/** * Negotiation context loader: given an opportunity, fetches the attached * negotiation task's transcript and outcome so the card presenter can * explain *why* the opportunity surfaced. * * For `draft`, `latent`, and `expired` opportunities, no negotiation has * happened (or no longer matters) so the loader returns null. * * For `negotiating` opportunities, only `turnCount` / `turnCap` are returned * — the presenter renders a templated chip without invoking the LLM. * * For `pending`, `stalled`, `accepted`, and `rejected` opportunities, the * full transcript and outcome are included so the prompt can ground its * explanation in concrete turn content. * * Screened-out negotiations (P2.2 — the client's own outreach gate declined * before any turn was exchanged) return null: presentation treats them as * never-happened, so no card, feed, or digest surface can frame the client's * private gate decision as a "counterparty declined" event. */ import type { NegotiationGraphDatabase, OpportunityStatus } from '../../shared/interfaces/database.interface.js'; import type { NegotiationOutcome, NegotiationTurn } from '../../capabilities/negotiation.state.facade.js'; /** * Narrow slice of {@link NegotiationGraphDatabase} required by the loader. Kept * minimal so call sites can opt into a smaller surface. */ export type NegotiationContextDatabase = Pick; /** * Snapshot of a negotiation surfaced to the presenter. `turns` and `outcome` * are only populated for post-negotiation statuses (pending/stalled/ * accepted/rejected); `negotiating` gets only the counters. */ export interface NegotiationContext { status: OpportunityStatus; /** * Conversation/task id of the A2A negotiation that produced this opportunity. * Lets callers deep-link to the negotiation trace (e.g. `/chat/:conversationId`). * Present whenever a negotiation task exists (i.e. context is non-null). */ conversationId: string; turnCount: number; /** Max turns allowed for this negotiation (0 = unlimited). */ turnCap: number; /** Only present when status is not `negotiating`. */ outcome?: NegotiationOutcome; /** Only present when status is not `negotiating`. */ turns?: NegotiationTurn[]; } /** * Loads the negotiation context for an opportunity. * * @param db - Narrow slice of NegotiationGraphDatabase. * @param opportunityId - Opportunity to load negotiation context for. * @param opportunityStatus - Current opportunity status. Used to gate loading * and to decide which fields to populate. * @returns NegotiationContext, or null when no meaningful negotiation exists * (draft/latent/expired) or when the task lookup fails. */ export declare function loadNegotiationContext(db: NegotiationContextDatabase, opportunityId: string, opportunityStatus: OpportunityStatus): Promise;