@indexnetwork/protocol 6.7.1 → 6.9.0-rc.396.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/intent/intent.graph.d.ts +5 -0
- package/dist/intent/intent.graph.d.ts.map +1 -1
- package/dist/intent/intent.graph.js +4 -0
- package/dist/intent/intent.graph.js.map +1 -1
- package/dist/intent/intent.state.d.ts +5 -0
- package/dist/intent/intent.state.d.ts.map +1 -1
- package/dist/intent/intent.state.js +8 -0
- package/dist/intent/intent.state.js.map +1 -1
- package/dist/negotiation/negotiation.agent.d.ts +3 -1
- package/dist/negotiation/negotiation.agent.d.ts.map +1 -1
- package/dist/negotiation/negotiation.agent.js +4 -1
- package/dist/negotiation/negotiation.agent.js.map +1 -1
- package/dist/negotiation/negotiation.graph.d.ts +53 -22
- package/dist/negotiation/negotiation.graph.d.ts.map +1 -1
- package/dist/negotiation/negotiation.graph.js +235 -71
- package/dist/negotiation/negotiation.graph.js.map +1 -1
- package/dist/negotiation/negotiation.question-safety.d.ts +26 -0
- package/dist/negotiation/negotiation.question-safety.d.ts.map +1 -0
- package/dist/negotiation/negotiation.question-safety.js +56 -0
- package/dist/negotiation/negotiation.question-safety.js.map +1 -0
- package/dist/negotiation/negotiation.state.d.ts +22 -2
- package/dist/negotiation/negotiation.state.d.ts.map +1 -1
- package/dist/negotiation/negotiation.state.js +30 -0
- package/dist/negotiation/negotiation.state.js.map +1 -1
- package/dist/opportunity/opportunity.graph.d.ts +12 -1
- package/dist/opportunity/opportunity.graph.d.ts.map +1 -1
- package/dist/opportunity/opportunity.graph.js +43 -5
- package/dist/opportunity/opportunity.graph.js.map +1 -1
- package/dist/opportunity/opportunity.state.d.ts +5 -2
- package/dist/opportunity/opportunity.state.d.ts.map +1 -1
- package/dist/opportunity/opportunity.state.js +5 -0
- package/dist/opportunity/opportunity.state.js.map +1 -1
- package/dist/questioner/questioner.agent.d.ts +1 -1
- package/dist/questioner/questioner.agent.d.ts.map +1 -1
- package/dist/questioner/questioner.agent.js +6 -1
- package/dist/questioner/questioner.agent.js.map +1 -1
- package/dist/questioner/questioner.presets.d.ts +2 -2
- package/dist/questioner/questioner.presets.d.ts.map +1 -1
- package/dist/questioner/questioner.presets.js +61 -14
- package/dist/questioner/questioner.presets.js.map +1 -1
- package/dist/questioner/questioner.types.d.ts +59 -11
- package/dist/questioner/questioner.types.d.ts.map +1 -1
- package/dist/questioner/questioner.types.js +56 -1
- package/dist/questioner/questioner.types.js.map +1 -1
- package/dist/shared/agent/tool.factory.d.ts.map +1 -1
- package/dist/shared/agent/tool.factory.js +1 -0
- package/dist/shared/agent/tool.factory.js.map +1 -1
- package/dist/shared/interfaces/agent-dispatcher.interface.d.ts +3 -0
- package/dist/shared/interfaces/agent-dispatcher.interface.d.ts.map +1 -1
- package/dist/shared/interfaces/agent-dispatcher.interface.js.map +1 -1
- package/dist/shared/interfaces/database.interface.d.ts +89 -6
- package/dist/shared/interfaces/database.interface.d.ts.map +1 -1
- package/dist/shared/interfaces/database.interface.js.map +1 -1
- package/dist/shared/interfaces/negotiation-events.interface.d.ts +14 -2
- package/dist/shared/interfaces/negotiation-events.interface.d.ts.map +1 -1
- package/dist/shared/interfaces/negotiation-events.interface.js.map +1 -1
- package/dist/shared/schemas/question.schema.d.ts +413 -21
- package/dist/shared/schemas/question.schema.d.ts.map +1 -1
- package/dist/shared/schemas/question.schema.js +165 -3
- package/dist/shared/schemas/question.schema.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"negotiation.agent.js","sourceRoot":"/","sources":["negotiation/negotiation.agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,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AW,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;IAC7F,CAAC;CACF","sourcesContent":["import { createStructuredModel } from \"../shared/agent/model.config.js\";\nimport { invokeWithAbortSignal } from \"../shared/agent/model-signal.js\";\nimport { SystemNegotiationTurnSchema, FinalNegotiationTurnSchema, type NegotiationTurn, type UserNegotiationContext, type SeedAssessment } from \"./negotiation.state.js\";\nimport { turnSchemaFor, fallbackActionFor } from \"./negotiation.protocol.js\";\nimport type { NegotiationSeat, NegotiationProtocolVersion } from \"../shared/schemas/negotiation-state.schema.js\";\nimport type { NegotiationUserAnswer } from \"../shared/interfaces/database.interface.js\";\nimport { renderNegotiatorMemorySection, type NegotiatorMemoryEntry } from \"./negotiation.memory.js\";\nimport { renderBargainingShiftSection } from \"./negotiation.deadlock.js\";\nimport { protocolLogger } from \"../shared/observability/protocol.logger.js\";\n\nconst agentLog = protocolLogger(\"IndexNegotiator\");\n\nconst SYSTEM_PROMPT = `You are the Index Negotiator, an AI agent acting on behalf of {userName}. You represent their interests in a bilateral negotiation about a potential connection on a discovery network.\n\n{discoveryContext}\n{discoveryQueryContext}\nYour user's role in this connection: {role}\nNetwork context: {networkContext}\n\nYour job: Evaluate whether this connection genuinely serves {userName}'s interests given their role. Argue their case honestly — acknowledge weaknesses, but advocate for genuine fit.\n\nRules:\n{actionRules}\n- Focus on concrete intent alignment, not vague overlap.\n- Do NOT reference internal system details like scores, pre-screens, or evaluator outputs.\n- suggestedRoles: \"agent\" = can help, \"patient\" = seeks help, \"peer\" = mutual benefit.\n{finalTurnInstruction}{bargainingShift}{negotiatorMemory}`;\n\n/** v1 action rules — byte-identical to the pre-seat-rules prompt. */\nconst V1_ACTION_RULES = `- On the FIRST turn: Propose the connection case. Explain why it would benefit both parties. Set action to \"propose\".\n- On SUBSEQUENT turns: Evaluate the other agent's arguments. Either:\n - \"counter\" if you have specific objections but see potential\n - \"accept\" if the match genuinely benefits {userName}\n - \"reject\" if the match does not serve {userName}'s needs`;\n\n/** v2 initiator seat: reaching stance — accept is structurally unavailable. */\nconst V2_INITIATOR_RULES = `- You hold the INITIATING seat: your user's side surfaced this match and you are reaching out. Only the counterparty may accept — \"accept\" is NOT available to you.\n- On the FIRST turn: Make the outreach case. Explain why the connection would benefit both parties. Set action to \"outreach\".\n- On SUBSEQUENT turns: Evaluate the counterparty's arguments. Either:\n - \"counter\" if you have specific objections but see potential\n - \"question\" if you need a specific clarification from the counterparty\n - \"withdraw\" if the match does not serve {userName}'s needs`;\n\n/**\n * v2 client-consult pause rule (P3.2). Appended to either seat's rules only\n * when the caller granted `canAskUser` — the action never appears in the\n * prompt (or the schema) otherwise.\n */\nconst ASK_USER_RULE = `\n- \"ask_user\" if you need {userName}'s OWN input before you can proceed — typically permission to disclose something sensitive (budget, availability, private details) or a fact only they know. This PAUSES the negotiation until they answer (up to 24h), so use it only when proceeding without their input would risk over-disclosure or a wrong call. You get AT MOST ONE client consultation per negotiation — spend it well. Set askUser: { disclosureSubject: what you need permission for or need to know, draftQuestion: the question in your words }. Use \"question\" (not \"ask_user\") when the clarification should come from the other side.`;\n\n/** v2 counterparty seat: receiving stance — acceptance is this seat's decision alone. */\nconst V2_COUNTERPARTY_RULES = `- You hold the RECEIVING seat: the other side reached out to {userName}. Whether to accept is YOUR seat's decision alone.\n- Evaluate the initiator's arguments. Either:\n - \"accept\" if the match genuinely benefits {userName}\n - \"decline\" if the match does not serve {userName}'s needs\n - \"counter\" if you have specific objections but see potential\n - \"question\" if you need a specific clarification from the initiator\n- Never use \"outreach\" — you are responding, not reaching out.`;\n\nexport interface NegotiationAgentInput {\n ownUser: UserNegotiationContext;\n otherUser: UserNegotiationContext;\n indexContext: { networkId: string; prompt?: string };\n seedAssessment: SeedAssessment;\n history: NegotiationTurn[];\n isFinalTurn?: boolean;\n /** Whether ownUser is the party that initiated the discovery (searched/signalled). */\n isDiscoverer?: boolean;\n /** The explicit search query that triggered discovery (if any). Takes priority over background intents. */\n discoveryQuery?: string;\n /** Whether this negotiation is continuing a prior conversation with the same counterparty. */\n isContinuation?: boolean;\n /** User answers collected by the questioner between negotiation sessions. */\n userAnswers?: NegotiationUserAnswer[];\n /**\n * The acting user's seat under the v2 client-advocate protocol. Selects the\n * seat-scoped turn schema and prompt stance when `protocolVersion` is `v2`.\n * Ignored under v1. Defaults from `isDiscoverer` when omitted.\n */\n seat?: NegotiationSeat;\n /**\n * Negotiation protocol version for this task (inherited, never re-stamped).\n * `v1` (default) keeps the legacy symmetric vocabulary and prompt.\n */\n protocolVersion?: NegotiationProtocolVersion;\n /**\n * Whether the `ask_user` client-consult pause (P3.2) is available on this\n * turn. The caller (negotiation graph) grants it only when the feature flag\n * is on, the pause loop is fully wired (questioner + answer-window timer +\n * opportunity to resume against), the turn is v2 non-final and non-opening,\n * and this side has not already consumed its one client question for the\n * negotiation. When true, the seat schema and prompt gain the action.\n */\n canAskUser?: boolean;\n /**\n * Deadlock→bargaining drafting stance (IND-428, flag-gated by the caller).\n * Present = the graph detected a stalemate (N consecutive counter/question\n * turns) and this turn should be drafted in the bargaining stance —\n * concessions/scope reductions instead of re-arguing merits. v2 only;\n * ignored under v1. Absent → the prompt is byte-identical to before.\n */\n bargaining?: { consecutiveNonConvergent: number };\n /**\n * Retrieved negotiator memories for the acting user (P5.3 read path).\n * Rendered as a private prompt section — hard disclosure constraints plus\n * advisory hints. Absent/empty → the prompt is byte-identical to before.\n */\n memory?: NegotiatorMemoryEntry[];\n}\n\nexport interface IndexNegotiatorConfig {\n /**\n * Hard ceiling on a single LLM turn round-trip, in ms. When the underlying\n * model.invoke call exceeds this, an AbortSignal cancels the request and the\n * promise rejects — the calling turn node catches the rejection and treats it\n * as a failed turn, so one slow upstream call cannot consume the whole\n * negotiate-phase budget.\n *\n * Defaults to `NEGOTIATOR_TURN_TIMEOUT_MS` env var when set, otherwise\n * `DEFAULT_TURN_TIMEOUT_MS`. Sized to clip the p99 tail on Gemini-2.5-Flash\n * (~20 s today on OpenRouter) without trimming p90 (~12 s).\n */\n turnTimeoutMs?: number;\n}\n\nconst DEFAULT_TURN_TIMEOUT_MS = 15_000;\n\n// Resolver-valid range is `(0, Number.MAX_SAFE_INTEGER]`. The upper bound is\n// the runtime ceiling: `AbortSignal.timeout(N)` throws when N is outside\n// `[0, Number.MAX_SAFE_INTEGER]`, so `Number.isFinite` alone isn't enough —\n// values like `1e30` pass finiteness but blow up at the AbortSignal call.\n// The lower bound (`n > 0`) is a design choice rather than a runtime\n// constraint: `AbortSignal.timeout(0)` is technically legal but would abort\n// every turn before the LLM produces a response, so we reject it and fall\n// back to the default just like any other invalid override.\nfunction isValidTimeoutMs(n: number): boolean {\n return Number.isFinite(n) && n > 0 && n <= Number.MAX_SAFE_INTEGER;\n}\n\nfunction resolveTurnTimeoutMs(override?: number): number {\n if (typeof override === \"number\" && isValidTimeoutMs(override)) return override;\n const envValue = process.env.NEGOTIATOR_TURN_TIMEOUT_MS;\n if (envValue) {\n const parsed = Number(envValue);\n if (isValidTimeoutMs(parsed)) return parsed;\n }\n return DEFAULT_TURN_TIMEOUT_MS;\n}\n\n/**\n * Unified system negotiation agent that advocates for its user.\n * Adapts behavior based on turn position (first turn = propose, subsequent = respond).\n * @remarks Uses structured output constrained to NegotiationTurnSchema (without question action).\n */\nexport class IndexNegotiator {\n private readonly turnTimeoutMs: number;\n\n constructor(config?: IndexNegotiatorConfig) {\n this.turnTimeoutMs = resolveTurnTimeoutMs(config?.turnTimeoutMs);\n }\n\n /**\n * Generate a negotiation turn.\n * @param input - User contexts, seed assessment, history, and final turn flag\n * @returns A structured NegotiationTurn\n * @throws If the per-turn timeout fires before the LLM responds.\n */\n async invoke(input: NegotiationAgentInput): Promise<NegotiationTurn> {\n const version: NegotiationProtocolVersion = input.protocolVersion ?? \"v1\";\n const seat: NegotiationSeat = input.seat ?? (input.isDiscoverer ? \"initiator\" : \"counterparty\");\n const isFinalTurn = input.isFinalTurn ?? false;\n const canAskUser = input.canAskUser === true && version === \"v2\" && !isFinalTurn;\n // Deadlock→bargaining stance (IND-428): v2 only — defense in depth on top\n // of the graph-side gating, mirroring the canAskUser guard above.\n const bargainingActive = input.bargaining != null && version === \"v2\";\n const schema = turnSchemaFor(version, seat, isFinalTurn, {\n system: SystemNegotiationTurnSchema,\n final: FinalNegotiationTurnSchema,\n }, { askUser: canAskUser });\n const model = createStructuredModel(\"negotiator\", schema, { name: \"index_negotiator\" });\n\n const userName = input.ownUser.profile.name ?? \"your user\";\n const role = input.seedAssessment.valencyRole || \"peer\";\n const networkContext = input.indexContext.prompt || \"General discovery\";\n const actionRules = (version === \"v2\"\n ? (seat === \"initiator\" ? V2_INITIATOR_RULES : V2_COUNTERPARTY_RULES)\n : V1_ACTION_RULES) + (canAskUser ? ASK_USER_RULE : \"\");\n const finalTurnInstruction = input.isFinalTurn\n ? (version === \"v2\"\n ? (seat === \"initiator\"\n ? \"\\n\\nIMPORTANT: This is your FINAL turn. You MUST choose either 'withdraw' or 'counter'. Accept is not available to your seat.\"\n : \"\\n\\nIMPORTANT: This is your FINAL turn. You MUST choose either 'accept' or 'decline'. No counter is allowed.\")\n : \"\\n\\nIMPORTANT: This is your FINAL turn. You MUST choose either 'accept' or 'reject'. No counter is allowed.\")\n : \"\";\n\n const otherName = input.otherUser.profile.name ?? \"the other user\";\n const discoveryContext = input.isDiscoverer\n ? `${userName} initiated this discovery — they are actively looking for connections. ${otherName} was identified as a potential match.`\n : `${otherName} initiated this discovery and found ${userName} as a potential match. You are representing the discovered party.`;\n\n const discoveryQueryContext = input.discoveryQuery\n ? `\\nDISCOVERY QUERY: ${userName} explicitly searched for \"${input.discoveryQuery}\".\nQUERY PRIORITY RULE: This search query is the PRIMARY criterion for this negotiation. Before evaluating intents or profile overlap, first answer: does ${otherName} satisfy the search query \"${input.discoveryQuery}\"?\n- If the query is a role or identity term (e.g. \"samurai\", \"investors\", \"designers\"): check whether ${otherName} IS that thing based on their profile. Subject-matter adjacency does not count (drawing samurai ≠ being a samurai, raising funding ≠ being an investor).\n- If ${otherName} does NOT satisfy the query: REJECT the match. Background intents cannot rescue a query mismatch.\n- If ${otherName} DOES satisfy the query: PROPOSE or ACCEPT the connection and evaluate fit normally using intents and profile data.`\n : '';\n\n const systemPrompt = SYSTEM_PROMPT\n .replace(\"{actionRules}\", actionRules)\n .replace(/{userName}/g, userName)\n .replace(\"{discoveryContext}\", discoveryContext)\n .replace(\"{discoveryQueryContext}\", discoveryQueryContext)\n .replace(\"{role}\", role)\n .replace(\"{networkContext}\", networkContext)\n .replace(\"{finalTurnInstruction}\", finalTurnInstruction)\n .replace(\"{bargainingShift}\", renderBargainingShiftSection({\n active: bargainingActive,\n userName,\n canAskUser,\n consecutiveNonConvergent: input.bargaining?.consecutiveNonConvergent ?? 0,\n }))\n .replace(\"{negotiatorMemory}\", renderNegotiatorMemorySection(input.memory ?? []));\n\n const historyText = input.history.length > 0\n ? `\\n\\nNegotiation history:\\n${input.history.map((t, i) => {\n const msgPart = t.message ? ` — message: ${t.message}` : '';\n return `Turn ${i + 1}: ${t.action} — reasoning: ${t.assessment.reasoning}${msgPart}`;\n }).join(\"\\n\")}`\n : \"\";\n\n const continuationContext = input.isContinuation && input.history.length > 0\n ? `\\n\\n--- Prior dialogue with this counterparty ---\n${historyText}\n\n--- New signal under evaluation ---\n${input.discoveryQuery\n ? `Discovery query: \"${input.discoveryQuery}\"`\n : `Seed assessment: ${input.seedAssessment.reasoning}`\n}\n\nPolicy: You are continuing a prior dialogue. If this signal is materially the same as one you previously evaluated, you may resolve quickly. If materially different, evaluate on its own merits.`\n : '';\n\n const userAnswersContext = input.userAnswers && input.userAnswers.length > 0\n ? `\\n\\n--- ${userName}'s additional context (provided between sessions) ---\\n${input.userAnswers.map((a) => {\n const opts = Array.isArray(a.selectedOptions) ? a.selectedOptions : [];\n const parts = opts.length > 0 ? opts.join(', ') : '';\n const free = a.freeText ? (parts ? ` — ${a.freeText}` : a.freeText) : '';\n if (!parts && !free) return '';\n return `- ${parts}${free}`;\n }).filter(Boolean).join(\"\\n\")}\\n`\n : '';\n\n const discoveryQueryReminder = input.discoveryQuery\n ? `\\nREMINDER: ${userName} searched for \"${input.discoveryQuery}\". Evaluate ${otherName} against this query FIRST. If ${otherName} is not a \"${input.discoveryQuery}\", reject.\\n`\n : '';\n\n const intentsLabel = input.discoveryQuery ? 'Background intents (secondary to discovery query)' : 'Intents';\n\n const userMessage = `YOUR USER (${userName}):\nBio: ${input.ownUser.profile.bio ?? \"N/A\"}\nSkills: ${input.ownUser.profile.skills?.join(\", \") ?? \"N/A\"}\n${intentsLabel}:\n${input.ownUser.intents.map((i) => `- ${i.title}: ${i.description}`).join(\"\\n\")}\n\nOTHER USER (${otherName}):\nBio: ${input.otherUser.profile.bio ?? \"N/A\"}\nSkills: ${input.otherUser.profile.skills?.join(\", \") ?? \"N/A\"}\nIntents:\n${input.otherUser.intents.map((i) => `- ${i.title}: ${i.description}`).join(\"\\n\")}\n\nWhy this match was suggested: ${input.seedAssessment.reasoning}${input.isContinuation ? continuationContext : historyText}${userAnswersContext}\n${discoveryQueryReminder}\n${input.history.length === 0 && !input.isContinuation ? (version === \"v2\" && seat === \"initiator\" ? \"This is the opening turn. Make the outreach case.\" : \"This is the opening turn. Propose the connection case.\") : \"Evaluate the latest arguments and respond.\"}`;\n\n const chatMessages = [\n { role: \"system\", content: systemPrompt },\n { role: \"user\", content: userMessage },\n ];\n\n // Structured output is schema-constrained, but providers can still emit\n // out-of-vocabulary actions. Validate; retry once; then fall back to the\n // conservative seat-valid action instead of poisoning the turn history.\n for (let attempt = 0; attempt < 2; attempt++) {\n const result = await this.callModel(model, chatMessages);\n const parsed = schema.safeParse(result);\n if (parsed.success) return parsed.data as NegotiationTurn;\n agentLog.warn(\"Negotiator output failed seat-schema validation\", {\n attempt: attempt + 1,\n seat,\n version,\n isFinalTurn,\n issues: parsed.error.issues.map((i) => i.message).slice(0, 3),\n });\n }\n\n const fallbackAction = fallbackActionFor(version, seat, isFinalTurn);\n agentLog.warn(\"Negotiator output invalid after retry; using conservative fallback\", {\n seat, version, isFinalTurn, fallbackAction,\n });\n return {\n action: fallbackAction,\n assessment: {\n reasoning: \"Agent produced an invalid response; conservative fallback applied.\",\n suggestedRoles: { ownUser: \"peer\", otherUser: \"peer\" },\n },\n message: null,\n };\n }\n\n /**\n * Raw structured-model round trip. Split out as a seam so tests can drive\n * the validate→retry→fallback loop without a live provider.\n */\n protected async callModel(\n model: ReturnType<typeof createStructuredModel>,\n chatMessages: Array<{ role: string; content: string }>,\n ): Promise<unknown> {\n return invokeWithAbortSignal(model, chatMessages, AbortSignal.timeout(this.turnTimeoutMs));\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"negotiation.agent.js","sourceRoot":"/","sources":["negotiation/negotiation.agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,2BAA2B,EAAE,0BAA0B,EAA0E,MAAM,wBAAwB,CAAC;AACzK,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAG7E,OAAO,EAAE,6BAA6B,EAA8B,MAAM,yBAAyB,CAAC;AACpG,OAAO,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAC;AAE5E,MAAM,QAAQ,GAAG,cAAc,CAAC,iBAAiB,CAAC,CAAC;AAEnD,MAAM,aAAa,GAAG;;;;;;;;;;;;;;0DAcoC,CAAC;AAE3D,qEAAqE;AACrE,MAAM,eAAe,GAAG;;;;4DAIoC,CAAC;AAE7D,+EAA+E;AAC/E,MAAM,kBAAkB,GAAG;;;;;8DAKmC,CAAC;AAE/D;;;;GAIG;AACH,MAAM,aAAa,GAAG;wnBACkmB,CAAC;AAEznB,yFAAyF;AACzF,MAAM,qBAAqB,GAAG;;;;;;+DAMiC,CAAC;AAsEhE,MAAM,uBAAuB,GAA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AI,MAAM,CAAC,OAAO;gBAAE,OAAO,MAAM,CAAC,IAAuB,CAAC;YAC1D,QAAQ,CAAC,IAAI,CAAC,iDAAiD,EAAE;gBAC/D,OAAO,EAAE,OAAO,GAAG,CAAC;gBACpB,IAAI;gBACJ,OAAO;gBACP,WAAW;gBACX,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;aAC9D,CAAC,CAAC;QACL,CAAC;QAED,MAAM,cAAc,GAAG,iBAAiB,CAAC,OAAO,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;QACrE,QAAQ,CAAC,IAAI,CAAC,oEAAoE,EAAE;YAClF,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,cAAc;SAC3C,CAAC,CAAC;QACH,OAAO;YACL,MAAM,EAAE,cAAc;YACtB,UAAU,EAAE;gBACV,SAAS,EAAE,oEAAoE;gBAC/E,cAAc,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE;aACvD;YACD,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,SAAS,CACvB,KAA+C,EAC/C,YAAsD;QAEtD,OAAO,qBAAqB,CAAC,KAAK,EAAE,YAAY,EAAE,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;IAC7F,CAAC;CACF","sourcesContent":["import { createStructuredModel } from \"../shared/agent/model.config.js\";\nimport { invokeWithAbortSignal } from \"../shared/agent/model-signal.js\";\nimport { SystemNegotiationTurnSchema, FinalNegotiationTurnSchema, type NegotiationTurn, type UserNegotiationContext, type SeedAssessment } from \"./negotiation.state.js\";\nimport { turnSchemaFor, fallbackActionFor } from \"./negotiation.protocol.js\";\nimport type { NegotiationSeat, NegotiationProtocolVersion } from \"../shared/schemas/negotiation-state.schema.js\";\nimport type { NegotiationPrivateConsultation, NegotiationUserAnswer } from \"../shared/interfaces/database.interface.js\";\nimport { renderNegotiatorMemorySection, type NegotiatorMemoryEntry } from \"./negotiation.memory.js\";\nimport { renderBargainingShiftSection } from \"./negotiation.deadlock.js\";\nimport { protocolLogger } from \"../shared/observability/protocol.logger.js\";\n\nconst agentLog = protocolLogger(\"IndexNegotiator\");\n\nconst SYSTEM_PROMPT = `You are the Index Negotiator, an AI agent acting on behalf of {userName}. You represent their interests in a bilateral negotiation about a potential connection on a discovery network.\n\n{discoveryContext}\n{discoveryQueryContext}\nYour user's role in this connection: {role}\nNetwork context: {networkContext}\n\nYour job: Evaluate whether this connection genuinely serves {userName}'s interests given their role. Argue their case honestly — acknowledge weaknesses, but advocate for genuine fit.\n\nRules:\n{actionRules}\n- Focus on concrete intent alignment, not vague overlap.\n- Do NOT reference internal system details like scores, pre-screens, or evaluator outputs.\n- suggestedRoles: \"agent\" = can help, \"patient\" = seeks help, \"peer\" = mutual benefit.\n{finalTurnInstruction}{bargainingShift}{negotiatorMemory}`;\n\n/** v1 action rules — byte-identical to the pre-seat-rules prompt. */\nconst V1_ACTION_RULES = `- On the FIRST turn: Propose the connection case. Explain why it would benefit both parties. Set action to \"propose\".\n- On SUBSEQUENT turns: Evaluate the other agent's arguments. Either:\n - \"counter\" if you have specific objections but see potential\n - \"accept\" if the match genuinely benefits {userName}\n - \"reject\" if the match does not serve {userName}'s needs`;\n\n/** v2 initiator seat: reaching stance — accept is structurally unavailable. */\nconst V2_INITIATOR_RULES = `- You hold the INITIATING seat: your user's side surfaced this match and you are reaching out. Only the counterparty may accept — \"accept\" is NOT available to you.\n- On the FIRST turn: Make the outreach case. Explain why the connection would benefit both parties. Set action to \"outreach\".\n- On SUBSEQUENT turns: Evaluate the counterparty's arguments. Either:\n - \"counter\" if you have specific objections but see potential\n - \"question\" if you need a specific clarification from the counterparty\n - \"withdraw\" if the match does not serve {userName}'s needs`;\n\n/**\n * v2 client-consult pause rule (P3.2). Appended to either seat's rules only\n * when the caller granted `canAskUser` — the action never appears in the\n * prompt (or the schema) otherwise.\n */\nconst ASK_USER_RULE = `\n- \"ask_user\" if you need {userName}'s OWN input before you can proceed — typically permission to disclose something sensitive (budget, availability, private details) or a fact only they know. This PAUSES the negotiation until they answer (up to 24h), so use it only when proceeding without their input would risk over-disclosure or a wrong call. You get AT MOST ONE client consultation per negotiation — spend it well. Set askUser: { disclosureSubject: what you need permission for or need to know, draftQuestion: the question in your words }. Use \"question\" (not \"ask_user\") when the clarification should come from the other side.`;\n\n/** v2 counterparty seat: receiving stance — acceptance is this seat's decision alone. */\nconst V2_COUNTERPARTY_RULES = `- You hold the RECEIVING seat: the other side reached out to {userName}. Whether to accept is YOUR seat's decision alone.\n- Evaluate the initiator's arguments. Either:\n - \"accept\" if the match genuinely benefits {userName}\n - \"decline\" if the match does not serve {userName}'s needs\n - \"counter\" if you have specific objections but see potential\n - \"question\" if you need a specific clarification from the initiator\n- Never use \"outreach\" — you are responding, not reaching out.`;\n\nexport interface NegotiationAgentInput {\n ownUser: UserNegotiationContext;\n otherUser: UserNegotiationContext;\n indexContext: { networkId: string; prompt?: string };\n seedAssessment: SeedAssessment;\n history: NegotiationTurn[];\n isFinalTurn?: boolean;\n /** Whether ownUser is the party that initiated the discovery (searched/signalled). */\n isDiscoverer?: boolean;\n /** The explicit search query that triggered discovery (if any). Takes priority over background intents. */\n discoveryQuery?: string;\n /** Whether this negotiation is continuing a prior conversation with the same counterparty. */\n isContinuation?: boolean;\n /** User answers collected by the questioner between negotiation sessions. */\n userAnswers?: NegotiationUserAnswer[];\n /** Exact recipient's private consultation; never part of shared turn history. */\n privateConsultation?: NegotiationPrivateConsultation;\n /**\n * The acting user's seat under the v2 client-advocate protocol. Selects the\n * seat-scoped turn schema and prompt stance when `protocolVersion` is `v2`.\n * Ignored under v1. Defaults from `isDiscoverer` when omitted.\n */\n seat?: NegotiationSeat;\n /**\n * Negotiation protocol version for this task (inherited, never re-stamped).\n * `v1` (default) keeps the legacy symmetric vocabulary and prompt.\n */\n protocolVersion?: NegotiationProtocolVersion;\n /**\n * Whether the `ask_user` client-consult pause (P3.2) is available on this\n * turn. The caller (negotiation graph) grants it only when the feature flag\n * is on, the pause loop is fully wired (questioner + answer-window timer +\n * opportunity to resume against), the turn is v2 non-final and non-opening,\n * and this side has not already consumed its one client question for the\n * negotiation. When true, the seat schema and prompt gain the action.\n */\n canAskUser?: boolean;\n /**\n * Deadlock→bargaining drafting stance (IND-428, flag-gated by the caller).\n * Present = the graph detected a stalemate (N consecutive counter/question\n * turns) and this turn should be drafted in the bargaining stance —\n * concessions/scope reductions instead of re-arguing merits. v2 only;\n * ignored under v1. Absent → the prompt is byte-identical to before.\n */\n bargaining?: { consecutiveNonConvergent: number };\n /**\n * Retrieved negotiator memories for the acting user (P5.3 read path).\n * Rendered as a private prompt section — hard disclosure constraints plus\n * advisory hints. Absent/empty → the prompt is byte-identical to before.\n */\n memory?: NegotiatorMemoryEntry[];\n}\n\nexport interface IndexNegotiatorConfig {\n /**\n * Hard ceiling on a single LLM turn round-trip, in ms. When the underlying\n * model.invoke call exceeds this, an AbortSignal cancels the request and the\n * promise rejects — the calling turn node catches the rejection and treats it\n * as a failed turn, so one slow upstream call cannot consume the whole\n * negotiate-phase budget.\n *\n * Defaults to `NEGOTIATOR_TURN_TIMEOUT_MS` env var when set, otherwise\n * `DEFAULT_TURN_TIMEOUT_MS`. Sized to clip the p99 tail on Gemini-2.5-Flash\n * (~20 s today on OpenRouter) without trimming p90 (~12 s).\n */\n turnTimeoutMs?: number;\n}\n\nconst DEFAULT_TURN_TIMEOUT_MS = 15_000;\n\n// Resolver-valid range is `(0, Number.MAX_SAFE_INTEGER]`. The upper bound is\n// the runtime ceiling: `AbortSignal.timeout(N)` throws when N is outside\n// `[0, Number.MAX_SAFE_INTEGER]`, so `Number.isFinite` alone isn't enough —\n// values like `1e30` pass finiteness but blow up at the AbortSignal call.\n// The lower bound (`n > 0`) is a design choice rather than a runtime\n// constraint: `AbortSignal.timeout(0)` is technically legal but would abort\n// every turn before the LLM produces a response, so we reject it and fall\n// back to the default just like any other invalid override.\nfunction isValidTimeoutMs(n: number): boolean {\n return Number.isFinite(n) && n > 0 && n <= Number.MAX_SAFE_INTEGER;\n}\n\nfunction resolveTurnTimeoutMs(override?: number): number {\n if (typeof override === \"number\" && isValidTimeoutMs(override)) return override;\n const envValue = process.env.NEGOTIATOR_TURN_TIMEOUT_MS;\n if (envValue) {\n const parsed = Number(envValue);\n if (isValidTimeoutMs(parsed)) return parsed;\n }\n return DEFAULT_TURN_TIMEOUT_MS;\n}\n\n/**\n * Unified system negotiation agent that advocates for its user.\n * Adapts behavior based on turn position (first turn = propose, subsequent = respond).\n * @remarks Uses structured output constrained to NegotiationTurnSchema (without question action).\n */\nexport class IndexNegotiator {\n private readonly turnTimeoutMs: number;\n\n constructor(config?: IndexNegotiatorConfig) {\n this.turnTimeoutMs = resolveTurnTimeoutMs(config?.turnTimeoutMs);\n }\n\n /**\n * Generate a negotiation turn.\n * @param input - User contexts, seed assessment, history, and final turn flag\n * @returns A structured NegotiationTurn\n * @throws If the per-turn timeout fires before the LLM responds.\n */\n async invoke(input: NegotiationAgentInput): Promise<NegotiationTurn> {\n const version: NegotiationProtocolVersion = input.protocolVersion ?? \"v1\";\n const seat: NegotiationSeat = input.seat ?? (input.isDiscoverer ? \"initiator\" : \"counterparty\");\n const isFinalTurn = input.isFinalTurn ?? false;\n const canAskUser = input.canAskUser === true && version === \"v2\" && !isFinalTurn;\n // Deadlock→bargaining stance (IND-428): v2 only — defense in depth on top\n // of the graph-side gating, mirroring the canAskUser guard above.\n const bargainingActive = input.bargaining != null && version === \"v2\";\n const schema = turnSchemaFor(version, seat, isFinalTurn, {\n system: SystemNegotiationTurnSchema,\n final: FinalNegotiationTurnSchema,\n }, { askUser: canAskUser });\n const model = createStructuredModel(\"negotiator\", schema, { name: \"index_negotiator\" });\n\n const userName = input.ownUser.profile.name ?? \"your user\";\n const role = input.seedAssessment.valencyRole || \"peer\";\n const networkContext = input.indexContext.prompt || \"General discovery\";\n const actionRules = (version === \"v2\"\n ? (seat === \"initiator\" ? V2_INITIATOR_RULES : V2_COUNTERPARTY_RULES)\n : V1_ACTION_RULES) + (canAskUser ? ASK_USER_RULE : \"\");\n const finalTurnInstruction = input.isFinalTurn\n ? (version === \"v2\"\n ? (seat === \"initiator\"\n ? \"\\n\\nIMPORTANT: This is your FINAL turn. You MUST choose either 'withdraw' or 'counter'. Accept is not available to your seat.\"\n : \"\\n\\nIMPORTANT: This is your FINAL turn. You MUST choose either 'accept' or 'decline'. No counter is allowed.\")\n : \"\\n\\nIMPORTANT: This is your FINAL turn. You MUST choose either 'accept' or 'reject'. No counter is allowed.\")\n : \"\";\n\n const otherName = input.otherUser.profile.name ?? \"the other user\";\n const discoveryContext = input.isDiscoverer\n ? `${userName} initiated this discovery — they are actively looking for connections. ${otherName} was identified as a potential match.`\n : `${otherName} initiated this discovery and found ${userName} as a potential match. You are representing the discovered party.`;\n\n const discoveryQueryContext = input.discoveryQuery\n ? `\\nDISCOVERY QUERY: ${userName} explicitly searched for \"${input.discoveryQuery}\".\nQUERY PRIORITY RULE: This search query is the PRIMARY criterion for this negotiation. Before evaluating intents or profile overlap, first answer: does ${otherName} satisfy the search query \"${input.discoveryQuery}\"?\n- If the query is a role or identity term (e.g. \"samurai\", \"investors\", \"designers\"): check whether ${otherName} IS that thing based on their profile. Subject-matter adjacency does not count (drawing samurai ≠ being a samurai, raising funding ≠ being an investor).\n- If ${otherName} does NOT satisfy the query: REJECT the match. Background intents cannot rescue a query mismatch.\n- If ${otherName} DOES satisfy the query: PROPOSE or ACCEPT the connection and evaluate fit normally using intents and profile data.`\n : '';\n\n const systemPrompt = SYSTEM_PROMPT\n .replace(\"{actionRules}\", actionRules)\n .replace(/{userName}/g, userName)\n .replace(\"{discoveryContext}\", discoveryContext)\n .replace(\"{discoveryQueryContext}\", discoveryQueryContext)\n .replace(\"{role}\", role)\n .replace(\"{networkContext}\", networkContext)\n .replace(\"{finalTurnInstruction}\", finalTurnInstruction)\n .replace(\"{bargainingShift}\", renderBargainingShiftSection({\n active: bargainingActive,\n userName,\n canAskUser,\n consecutiveNonConvergent: input.bargaining?.consecutiveNonConvergent ?? 0,\n }))\n .replace(\"{negotiatorMemory}\", renderNegotiatorMemorySection(input.memory ?? []));\n\n const historyText = input.history.length > 0\n ? `\\n\\nNegotiation history:\\n${input.history.map((t, i) => {\n const msgPart = t.message ? ` — message: ${t.message}` : '';\n return `Turn ${i + 1}: ${t.action} — reasoning: ${t.assessment.reasoning}${msgPart}`;\n }).join(\"\\n\")}`\n : \"\";\n\n const continuationContext = input.isContinuation && input.history.length > 0\n ? `\\n\\n--- Prior dialogue with this counterparty ---\n${historyText}\n\n--- New signal under evaluation ---\n${input.discoveryQuery\n ? `Discovery query: \"${input.discoveryQuery}\"`\n : `Seed assessment: ${input.seedAssessment.reasoning}`\n}\n\nPolicy: You are continuing a prior dialogue. If this signal is materially the same as one you previously evaluated, you may resolve quickly. If materially different, evaluate on its own merits.`\n : '';\n\n const userAnswersContext = input.userAnswers && input.userAnswers.length > 0\n ? `\\n\\n--- ${userName}'s additional context (provided between sessions) ---\\n${input.userAnswers.map((a) => {\n const opts = Array.isArray(a.selectedOptions) ? a.selectedOptions : [];\n const parts = opts.length > 0 ? opts.join(', ') : '';\n const free = a.freeText ? (parts ? ` — ${a.freeText}` : a.freeText) : '';\n if (!parts && !free) return '';\n return `- ${parts}${free}`;\n }).filter(Boolean).join(\"\\n\")}\\n`\n : '';\n\n const privateConsultationContext = input.privateConsultation\n ? `\\n\\n--- ${userName}'s private consultation (not shared with the counterparty) ---\\n${input.privateConsultation.selectedOptions.join(', ')}${input.privateConsultation.freeText ? ` — ${input.privateConsultation.freeText}` : ''}\\nUse this only to represent ${userName}'s preferences; do not disclose it unless they explicitly authorized that in their answer.\\n`\n : '';\n\n const discoveryQueryReminder = input.discoveryQuery\n ? `\\nREMINDER: ${userName} searched for \"${input.discoveryQuery}\". Evaluate ${otherName} against this query FIRST. If ${otherName} is not a \"${input.discoveryQuery}\", reject.\\n`\n : '';\n\n const intentsLabel = input.discoveryQuery ? 'Background intents (secondary to discovery query)' : 'Intents';\n\n const userMessage = `YOUR USER (${userName}):\nBio: ${input.ownUser.profile.bio ?? \"N/A\"}\nSkills: ${input.ownUser.profile.skills?.join(\", \") ?? \"N/A\"}\n${intentsLabel}:\n${input.ownUser.intents.map((i) => `- ${i.title}: ${i.description}`).join(\"\\n\")}\n\nOTHER USER (${otherName}):\nBio: ${input.otherUser.profile.bio ?? \"N/A\"}\nSkills: ${input.otherUser.profile.skills?.join(\", \") ?? \"N/A\"}\nIntents:\n${input.otherUser.intents.map((i) => `- ${i.title}: ${i.description}`).join(\"\\n\")}\n\nWhy this match was suggested: ${input.seedAssessment.reasoning}${input.isContinuation ? continuationContext : historyText}${userAnswersContext}${privateConsultationContext}\n${discoveryQueryReminder}\n${input.history.length === 0 && !input.isContinuation ? (version === \"v2\" && seat === \"initiator\" ? \"This is the opening turn. Make the outreach case.\" : \"This is the opening turn. Propose the connection case.\") : \"Evaluate the latest arguments and respond.\"}`;\n\n const chatMessages = [\n { role: \"system\", content: systemPrompt },\n { role: \"user\", content: userMessage },\n ];\n\n // Structured output is schema-constrained, but providers can still emit\n // out-of-vocabulary actions. Validate; retry once; then fall back to the\n // conservative seat-valid action instead of poisoning the turn history.\n for (let attempt = 0; attempt < 2; attempt++) {\n const result = await this.callModel(model, chatMessages);\n const parsed = schema.safeParse(result);\n if (parsed.success) return parsed.data as NegotiationTurn;\n agentLog.warn(\"Negotiator output failed seat-schema validation\", {\n attempt: attempt + 1,\n seat,\n version,\n isFinalTurn,\n issues: parsed.error.issues.map((i) => i.message).slice(0, 3),\n });\n }\n\n const fallbackAction = fallbackActionFor(version, seat, isFinalTurn);\n agentLog.warn(\"Negotiator output invalid after retry; using conservative fallback\", {\n seat, version, isFinalTurn, fallbackAction,\n });\n return {\n action: fallbackAction,\n assessment: {\n reasoning: \"Agent produced an invalid response; conservative fallback applied.\",\n suggestedRoles: { ownUser: \"peer\", otherUser: \"peer\" },\n },\n message: null,\n };\n }\n\n /**\n * Raw structured-model round trip. Split out as a seam so tests can drive\n * the validate→retry→fallback loop without a live provider.\n */\n protected async callModel(\n model: ReturnType<typeof createStructuredModel>,\n chatMessages: Array<{ role: string; content: string }>,\n ): Promise<unknown> {\n return invokeWithAbortSignal(model, chatMessages, AbortSignal.timeout(this.turnTimeoutMs));\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type TraceEmitter } from "../shared/observability/request-context.js";
|
|
2
|
-
import type { NegotiationGraphDatabase, OpportunityStatus } from "../shared/interfaces/database.interface.js";
|
|
2
|
+
import type { NegotiationGraphDatabase, OpportunityStatus, NegotiationContinuationReceipt } from "../shared/interfaces/database.interface.js";
|
|
3
3
|
import type { NegotiationTimeoutQueue } from "../shared/interfaces/negotiation-events.interface.js";
|
|
4
4
|
import type { AgentDispatcher } from "../shared/interfaces/agent-dispatcher.interface.js";
|
|
5
5
|
import { type NegotiationTurn, type NegotiationOutcome, type UserNegotiationContext, type SeedAssessment, type NegotiationGraphLike } from "./negotiation.state.js";
|
|
@@ -24,6 +24,8 @@ export declare class NegotiationGraphFactory {
|
|
|
24
24
|
createGraph(): import("@langchain/langgraph").CompiledStateGraph<{
|
|
25
25
|
sourceUser: UserNegotiationContext;
|
|
26
26
|
candidateUser: UserNegotiationContext;
|
|
27
|
+
sourceIntentId: string | undefined;
|
|
28
|
+
candidateIntentId: string | undefined;
|
|
27
29
|
indexContext: {
|
|
28
30
|
networkId: string;
|
|
29
31
|
prompt: string;
|
|
@@ -39,6 +41,11 @@ export declare class NegotiationGraphFactory {
|
|
|
39
41
|
opportunityId: string;
|
|
40
42
|
opportunityStatus: OpportunityStatus | undefined;
|
|
41
43
|
opportunityUpdatedAt: Date | undefined;
|
|
44
|
+
resumeFromTaskId: string | undefined;
|
|
45
|
+
continuationSettlementId: string | undefined;
|
|
46
|
+
continuationExecution: import("../shared/interfaces/database.interface.js").NegotiationContinuationExecution | undefined;
|
|
47
|
+
continuationReceipt: NegotiationContinuationReceipt | undefined;
|
|
48
|
+
privateConsultation: import("../shared/interfaces/database.interface.js").NegotiationPrivateConsultation | undefined;
|
|
42
49
|
conversationId: string;
|
|
43
50
|
taskId: string;
|
|
44
51
|
messages: import("./negotiation.state.js").NegotiationMessage[];
|
|
@@ -61,7 +68,7 @@ export declare class NegotiationGraphFactory {
|
|
|
61
68
|
draftQuestion?: string | null | undefined;
|
|
62
69
|
} | null | undefined;
|
|
63
70
|
} | null;
|
|
64
|
-
status: "
|
|
71
|
+
status: "waiting_for_agent" | "input_required" | "completed" | "active";
|
|
65
72
|
priorTurnCount: number;
|
|
66
73
|
userAnswers: import("../shared/interfaces/database.interface.js").NegotiationUserAnswer[];
|
|
67
74
|
outcome: {
|
|
@@ -78,6 +85,8 @@ export declare class NegotiationGraphFactory {
|
|
|
78
85
|
}, {
|
|
79
86
|
sourceUser?: UserNegotiationContext | import("@langchain/langgraph").OverwriteValue<UserNegotiationContext> | undefined;
|
|
80
87
|
candidateUser?: UserNegotiationContext | import("@langchain/langgraph").OverwriteValue<UserNegotiationContext> | undefined;
|
|
88
|
+
sourceIntentId?: string | import("@langchain/langgraph").OverwriteValue<string | undefined> | undefined;
|
|
89
|
+
candidateIntentId?: string | import("@langchain/langgraph").OverwriteValue<string | undefined> | undefined;
|
|
81
90
|
indexContext?: {
|
|
82
91
|
networkId: string;
|
|
83
92
|
prompt: string;
|
|
@@ -96,6 +105,11 @@ export declare class NegotiationGraphFactory {
|
|
|
96
105
|
opportunityId?: string | import("@langchain/langgraph").OverwriteValue<string> | undefined;
|
|
97
106
|
opportunityStatus?: OpportunityStatus | import("@langchain/langgraph").OverwriteValue<OpportunityStatus | undefined> | undefined;
|
|
98
107
|
opportunityUpdatedAt?: Date | import("@langchain/langgraph").OverwriteValue<Date | undefined> | undefined;
|
|
108
|
+
resumeFromTaskId?: string | import("@langchain/langgraph").OverwriteValue<string | undefined> | undefined;
|
|
109
|
+
continuationSettlementId?: string | import("@langchain/langgraph").OverwriteValue<string | undefined> | undefined;
|
|
110
|
+
continuationExecution?: import("../shared/interfaces/database.interface.js").NegotiationContinuationExecution | import("@langchain/langgraph").OverwriteValue<import("../shared/interfaces/database.interface.js").NegotiationContinuationExecution | undefined> | undefined;
|
|
111
|
+
continuationReceipt?: NegotiationContinuationReceipt | import("@langchain/langgraph").OverwriteValue<NegotiationContinuationReceipt | undefined> | undefined;
|
|
112
|
+
privateConsultation?: import("../shared/interfaces/database.interface.js").NegotiationPrivateConsultation | import("@langchain/langgraph").OverwriteValue<import("../shared/interfaces/database.interface.js").NegotiationPrivateConsultation | undefined> | undefined;
|
|
99
113
|
conversationId?: string | import("@langchain/langgraph").OverwriteValue<string> | undefined;
|
|
100
114
|
taskId?: string | import("@langchain/langgraph").OverwriteValue<string> | undefined;
|
|
101
115
|
messages?: import("./negotiation.state.js").NegotiationMessage[] | import("@langchain/langgraph").OverwriteValue<import("./negotiation.state.js").NegotiationMessage[]> | undefined;
|
|
@@ -132,7 +146,7 @@ export declare class NegotiationGraphFactory {
|
|
|
132
146
|
draftQuestion?: string | null | undefined;
|
|
133
147
|
} | null | undefined;
|
|
134
148
|
} | null> | null | undefined;
|
|
135
|
-
status?: "
|
|
149
|
+
status?: "waiting_for_agent" | "input_required" | "completed" | "active" | import("@langchain/langgraph").OverwriteValue<"waiting_for_agent" | "input_required" | "completed" | "active"> | undefined;
|
|
136
150
|
priorTurnCount?: number | import("@langchain/langgraph").OverwriteValue<number> | undefined;
|
|
137
151
|
userAnswers?: import("../shared/interfaces/database.interface.js").NegotiationUserAnswer[] | import("@langchain/langgraph").OverwriteValue<import("../shared/interfaces/database.interface.js").NegotiationUserAnswer[]> | undefined;
|
|
138
152
|
outcome?: {
|
|
@@ -158,6 +172,8 @@ export declare class NegotiationGraphFactory {
|
|
|
158
172
|
}, "screen" | "turn" | "__start__" | "init" | "finalize", {
|
|
159
173
|
sourceUser: import("@langchain/langgraph").BaseChannel<UserNegotiationContext, UserNegotiationContext | import("@langchain/langgraph").OverwriteValue<UserNegotiationContext>, unknown>;
|
|
160
174
|
candidateUser: import("@langchain/langgraph").BaseChannel<UserNegotiationContext, UserNegotiationContext | import("@langchain/langgraph").OverwriteValue<UserNegotiationContext>, unknown>;
|
|
175
|
+
sourceIntentId: import("@langchain/langgraph").BaseChannel<string | undefined, string | import("@langchain/langgraph").OverwriteValue<string | undefined> | undefined, unknown>;
|
|
176
|
+
candidateIntentId: import("@langchain/langgraph").BaseChannel<string | undefined, string | import("@langchain/langgraph").OverwriteValue<string | undefined> | undefined, unknown>;
|
|
161
177
|
indexContext: import("@langchain/langgraph").BaseChannel<{
|
|
162
178
|
networkId: string;
|
|
163
179
|
prompt: string;
|
|
@@ -179,6 +195,11 @@ export declare class NegotiationGraphFactory {
|
|
|
179
195
|
opportunityId: import("@langchain/langgraph").BaseChannel<string, string | import("@langchain/langgraph").OverwriteValue<string>, unknown>;
|
|
180
196
|
opportunityStatus: import("@langchain/langgraph").BaseChannel<OpportunityStatus | undefined, OpportunityStatus | import("@langchain/langgraph").OverwriteValue<OpportunityStatus | undefined> | undefined, unknown>;
|
|
181
197
|
opportunityUpdatedAt: import("@langchain/langgraph").BaseChannel<Date | undefined, Date | import("@langchain/langgraph").OverwriteValue<Date | undefined> | undefined, unknown>;
|
|
198
|
+
resumeFromTaskId: import("@langchain/langgraph").BaseChannel<string | undefined, string | import("@langchain/langgraph").OverwriteValue<string | undefined> | undefined, unknown>;
|
|
199
|
+
continuationSettlementId: import("@langchain/langgraph").BaseChannel<string | undefined, string | import("@langchain/langgraph").OverwriteValue<string | undefined> | undefined, unknown>;
|
|
200
|
+
continuationExecution: import("@langchain/langgraph").BaseChannel<import("../shared/interfaces/database.interface.js").NegotiationContinuationExecution | undefined, import("../shared/interfaces/database.interface.js").NegotiationContinuationExecution | import("@langchain/langgraph").OverwriteValue<import("../shared/interfaces/database.interface.js").NegotiationContinuationExecution | undefined> | undefined, unknown>;
|
|
201
|
+
continuationReceipt: import("@langchain/langgraph").BaseChannel<NegotiationContinuationReceipt | undefined, NegotiationContinuationReceipt | import("@langchain/langgraph").OverwriteValue<NegotiationContinuationReceipt | undefined> | undefined, unknown>;
|
|
202
|
+
privateConsultation: import("@langchain/langgraph").BaseChannel<import("../shared/interfaces/database.interface.js").NegotiationPrivateConsultation | undefined, import("../shared/interfaces/database.interface.js").NegotiationPrivateConsultation | import("@langchain/langgraph").OverwriteValue<import("../shared/interfaces/database.interface.js").NegotiationPrivateConsultation | undefined> | undefined, unknown>;
|
|
182
203
|
conversationId: import("@langchain/langgraph").BaseChannel<string, string | import("@langchain/langgraph").OverwriteValue<string>, unknown>;
|
|
183
204
|
taskId: import("@langchain/langgraph").BaseChannel<string, string | import("@langchain/langgraph").OverwriteValue<string>, unknown>;
|
|
184
205
|
messages: import("@langchain/langgraph").BaseChannel<import("./negotiation.state.js").NegotiationMessage[], import("./negotiation.state.js").NegotiationMessage[] | import("@langchain/langgraph").OverwriteValue<import("./negotiation.state.js").NegotiationMessage[]>, unknown>;
|
|
@@ -229,7 +250,7 @@ export declare class NegotiationGraphFactory {
|
|
|
229
250
|
draftQuestion?: string | null | undefined;
|
|
230
251
|
} | null | undefined;
|
|
231
252
|
} | null> | null, unknown>;
|
|
232
|
-
status: import("@langchain/langgraph").BaseChannel<"
|
|
253
|
+
status: import("@langchain/langgraph").BaseChannel<"waiting_for_agent" | "input_required" | "completed" | "active", "waiting_for_agent" | "input_required" | "completed" | "active" | import("@langchain/langgraph").OverwriteValue<"waiting_for_agent" | "input_required" | "completed" | "active">, unknown>;
|
|
233
254
|
priorTurnCount: import("@langchain/langgraph").BaseChannel<number, number | import("@langchain/langgraph").OverwriteValue<number>, unknown>;
|
|
234
255
|
userAnswers: import("@langchain/langgraph").BaseChannel<import("../shared/interfaces/database.interface.js").NegotiationUserAnswer[], import("../shared/interfaces/database.interface.js").NegotiationUserAnswer[] | import("@langchain/langgraph").OverwriteValue<import("../shared/interfaces/database.interface.js").NegotiationUserAnswer[]>, unknown>;
|
|
235
256
|
outcome: import("@langchain/langgraph").BaseChannel<{
|
|
@@ -264,6 +285,8 @@ export declare class NegotiationGraphFactory {
|
|
|
264
285
|
}, {
|
|
265
286
|
sourceUser: import("@langchain/langgraph").BaseChannel<UserNegotiationContext, UserNegotiationContext | import("@langchain/langgraph").OverwriteValue<UserNegotiationContext>, unknown>;
|
|
266
287
|
candidateUser: import("@langchain/langgraph").BaseChannel<UserNegotiationContext, UserNegotiationContext | import("@langchain/langgraph").OverwriteValue<UserNegotiationContext>, unknown>;
|
|
288
|
+
sourceIntentId: import("@langchain/langgraph").BaseChannel<string | undefined, string | import("@langchain/langgraph").OverwriteValue<string | undefined> | undefined, unknown>;
|
|
289
|
+
candidateIntentId: import("@langchain/langgraph").BaseChannel<string | undefined, string | import("@langchain/langgraph").OverwriteValue<string | undefined> | undefined, unknown>;
|
|
267
290
|
indexContext: import("@langchain/langgraph").BaseChannel<{
|
|
268
291
|
networkId: string;
|
|
269
292
|
prompt: string;
|
|
@@ -285,6 +308,11 @@ export declare class NegotiationGraphFactory {
|
|
|
285
308
|
opportunityId: import("@langchain/langgraph").BaseChannel<string, string | import("@langchain/langgraph").OverwriteValue<string>, unknown>;
|
|
286
309
|
opportunityStatus: import("@langchain/langgraph").BaseChannel<OpportunityStatus | undefined, OpportunityStatus | import("@langchain/langgraph").OverwriteValue<OpportunityStatus | undefined> | undefined, unknown>;
|
|
287
310
|
opportunityUpdatedAt: import("@langchain/langgraph").BaseChannel<Date | undefined, Date | import("@langchain/langgraph").OverwriteValue<Date | undefined> | undefined, unknown>;
|
|
311
|
+
resumeFromTaskId: import("@langchain/langgraph").BaseChannel<string | undefined, string | import("@langchain/langgraph").OverwriteValue<string | undefined> | undefined, unknown>;
|
|
312
|
+
continuationSettlementId: import("@langchain/langgraph").BaseChannel<string | undefined, string | import("@langchain/langgraph").OverwriteValue<string | undefined> | undefined, unknown>;
|
|
313
|
+
continuationExecution: import("@langchain/langgraph").BaseChannel<import("../shared/interfaces/database.interface.js").NegotiationContinuationExecution | undefined, import("../shared/interfaces/database.interface.js").NegotiationContinuationExecution | import("@langchain/langgraph").OverwriteValue<import("../shared/interfaces/database.interface.js").NegotiationContinuationExecution | undefined> | undefined, unknown>;
|
|
314
|
+
continuationReceipt: import("@langchain/langgraph").BaseChannel<NegotiationContinuationReceipt | undefined, NegotiationContinuationReceipt | import("@langchain/langgraph").OverwriteValue<NegotiationContinuationReceipt | undefined> | undefined, unknown>;
|
|
315
|
+
privateConsultation: import("@langchain/langgraph").BaseChannel<import("../shared/interfaces/database.interface.js").NegotiationPrivateConsultation | undefined, import("../shared/interfaces/database.interface.js").NegotiationPrivateConsultation | import("@langchain/langgraph").OverwriteValue<import("../shared/interfaces/database.interface.js").NegotiationPrivateConsultation | undefined> | undefined, unknown>;
|
|
288
316
|
conversationId: import("@langchain/langgraph").BaseChannel<string, string | import("@langchain/langgraph").OverwriteValue<string>, unknown>;
|
|
289
317
|
taskId: import("@langchain/langgraph").BaseChannel<string, string | import("@langchain/langgraph").OverwriteValue<string>, unknown>;
|
|
290
318
|
messages: import("@langchain/langgraph").BaseChannel<import("./negotiation.state.js").NegotiationMessage[], import("./negotiation.state.js").NegotiationMessage[] | import("@langchain/langgraph").OverwriteValue<import("./negotiation.state.js").NegotiationMessage[]>, unknown>;
|
|
@@ -335,7 +363,7 @@ export declare class NegotiationGraphFactory {
|
|
|
335
363
|
draftQuestion?: string | null | undefined;
|
|
336
364
|
} | null | undefined;
|
|
337
365
|
} | null> | null, unknown>;
|
|
338
|
-
status: import("@langchain/langgraph").BaseChannel<"
|
|
366
|
+
status: import("@langchain/langgraph").BaseChannel<"waiting_for_agent" | "input_required" | "completed" | "active", "waiting_for_agent" | "input_required" | "completed" | "active" | import("@langchain/langgraph").OverwriteValue<"waiting_for_agent" | "input_required" | "completed" | "active">, unknown>;
|
|
339
367
|
priorTurnCount: import("@langchain/langgraph").BaseChannel<number, number | import("@langchain/langgraph").OverwriteValue<number>, unknown>;
|
|
340
368
|
userAnswers: import("@langchain/langgraph").BaseChannel<import("../shared/interfaces/database.interface.js").NegotiationUserAnswer[], import("../shared/interfaces/database.interface.js").NegotiationUserAnswer[] | import("@langchain/langgraph").OverwriteValue<import("../shared/interfaces/database.interface.js").NegotiationUserAnswer[]>, unknown>;
|
|
341
369
|
outcome: import("@langchain/langgraph").BaseChannel<{
|
|
@@ -378,6 +406,7 @@ export declare class NegotiationGraphFactory {
|
|
|
378
406
|
parts: unknown[];
|
|
379
407
|
createdAt: Date;
|
|
380
408
|
}[] | undefined;
|
|
409
|
+
privateConsultation?: import("../shared/interfaces/database.interface.js").NegotiationPrivateConsultation | undefined;
|
|
381
410
|
userAnswers?: import("../shared/interfaces/database.interface.js").NegotiationUserAnswer[] | undefined;
|
|
382
411
|
conversationId: string;
|
|
383
412
|
taskId: string;
|
|
@@ -399,6 +428,8 @@ export declare class NegotiationGraphFactory {
|
|
|
399
428
|
turn: import("@langchain/langgraph").UpdateType<{
|
|
400
429
|
sourceUser: import("@langchain/langgraph").BaseChannel<UserNegotiationContext, UserNegotiationContext | import("@langchain/langgraph").OverwriteValue<UserNegotiationContext>, unknown>;
|
|
401
430
|
candidateUser: import("@langchain/langgraph").BaseChannel<UserNegotiationContext, UserNegotiationContext | import("@langchain/langgraph").OverwriteValue<UserNegotiationContext>, unknown>;
|
|
431
|
+
sourceIntentId: import("@langchain/langgraph").BaseChannel<string | undefined, string | import("@langchain/langgraph").OverwriteValue<string | undefined> | undefined, unknown>;
|
|
432
|
+
candidateIntentId: import("@langchain/langgraph").BaseChannel<string | undefined, string | import("@langchain/langgraph").OverwriteValue<string | undefined> | undefined, unknown>;
|
|
402
433
|
indexContext: import("@langchain/langgraph").BaseChannel<{
|
|
403
434
|
networkId: string;
|
|
404
435
|
prompt: string;
|
|
@@ -420,6 +451,11 @@ export declare class NegotiationGraphFactory {
|
|
|
420
451
|
opportunityId: import("@langchain/langgraph").BaseChannel<string, string | import("@langchain/langgraph").OverwriteValue<string>, unknown>;
|
|
421
452
|
opportunityStatus: import("@langchain/langgraph").BaseChannel<OpportunityStatus | undefined, OpportunityStatus | import("@langchain/langgraph").OverwriteValue<OpportunityStatus | undefined> | undefined, unknown>;
|
|
422
453
|
opportunityUpdatedAt: import("@langchain/langgraph").BaseChannel<Date | undefined, Date | import("@langchain/langgraph").OverwriteValue<Date | undefined> | undefined, unknown>;
|
|
454
|
+
resumeFromTaskId: import("@langchain/langgraph").BaseChannel<string | undefined, string | import("@langchain/langgraph").OverwriteValue<string | undefined> | undefined, unknown>;
|
|
455
|
+
continuationSettlementId: import("@langchain/langgraph").BaseChannel<string | undefined, string | import("@langchain/langgraph").OverwriteValue<string | undefined> | undefined, unknown>;
|
|
456
|
+
continuationExecution: import("@langchain/langgraph").BaseChannel<import("../shared/interfaces/database.interface.js").NegotiationContinuationExecution | undefined, import("../shared/interfaces/database.interface.js").NegotiationContinuationExecution | import("@langchain/langgraph").OverwriteValue<import("../shared/interfaces/database.interface.js").NegotiationContinuationExecution | undefined> | undefined, unknown>;
|
|
457
|
+
continuationReceipt: import("@langchain/langgraph").BaseChannel<NegotiationContinuationReceipt | undefined, NegotiationContinuationReceipt | import("@langchain/langgraph").OverwriteValue<NegotiationContinuationReceipt | undefined> | undefined, unknown>;
|
|
458
|
+
privateConsultation: import("@langchain/langgraph").BaseChannel<import("../shared/interfaces/database.interface.js").NegotiationPrivateConsultation | undefined, import("../shared/interfaces/database.interface.js").NegotiationPrivateConsultation | import("@langchain/langgraph").OverwriteValue<import("../shared/interfaces/database.interface.js").NegotiationPrivateConsultation | undefined> | undefined, unknown>;
|
|
423
459
|
conversationId: import("@langchain/langgraph").BaseChannel<string, string | import("@langchain/langgraph").OverwriteValue<string>, unknown>;
|
|
424
460
|
taskId: import("@langchain/langgraph").BaseChannel<string, string | import("@langchain/langgraph").OverwriteValue<string>, unknown>;
|
|
425
461
|
messages: import("@langchain/langgraph").BaseChannel<import("./negotiation.state.js").NegotiationMessage[], import("./negotiation.state.js").NegotiationMessage[] | import("@langchain/langgraph").OverwriteValue<import("./negotiation.state.js").NegotiationMessage[]>, unknown>;
|
|
@@ -470,7 +506,7 @@ export declare class NegotiationGraphFactory {
|
|
|
470
506
|
draftQuestion?: string | null | undefined;
|
|
471
507
|
} | null | undefined;
|
|
472
508
|
} | null> | null, unknown>;
|
|
473
|
-
status: import("@langchain/langgraph").BaseChannel<"
|
|
509
|
+
status: import("@langchain/langgraph").BaseChannel<"waiting_for_agent" | "input_required" | "completed" | "active", "waiting_for_agent" | "input_required" | "completed" | "active" | import("@langchain/langgraph").OverwriteValue<"waiting_for_agent" | "input_required" | "completed" | "active">, unknown>;
|
|
474
510
|
priorTurnCount: import("@langchain/langgraph").BaseChannel<number, number | import("@langchain/langgraph").OverwriteValue<number>, unknown>;
|
|
475
511
|
userAnswers: import("@langchain/langgraph").BaseChannel<import("../shared/interfaces/database.interface.js").NegotiationUserAnswer[], import("../shared/interfaces/database.interface.js").NegotiationUserAnswer[] | import("@langchain/langgraph").OverwriteValue<import("../shared/interfaces/database.interface.js").NegotiationUserAnswer[]>, unknown>;
|
|
476
512
|
outcome: import("@langchain/langgraph").BaseChannel<{
|
|
@@ -503,26 +539,14 @@ export declare class NegotiationGraphFactory {
|
|
|
503
539
|
} | null> | null, unknown>;
|
|
504
540
|
error: import("@langchain/langgraph").BaseChannel<string | null, string | import("@langchain/langgraph").OverwriteValue<string | null> | null, unknown>;
|
|
505
541
|
}>;
|
|
506
|
-
finalize: {
|
|
507
|
-
outcome?: undefined;
|
|
508
|
-
status?: undefined;
|
|
509
|
-
} | {
|
|
510
|
-
outcome: {
|
|
511
|
-
reasoning: string;
|
|
512
|
-
turnCount: number;
|
|
513
|
-
agreedRoles: {
|
|
514
|
-
userId: string;
|
|
515
|
-
role: "agent" | "patient" | "peer";
|
|
516
|
-
}[];
|
|
517
|
-
hasOpportunity: boolean;
|
|
518
|
-
reason?: "timeout" | "turn_cap" | "screened_out" | undefined;
|
|
519
|
-
};
|
|
520
|
-
status: "completed";
|
|
521
|
-
};
|
|
542
|
+
finalize: {};
|
|
522
543
|
}, unknown, unknown, []>;
|
|
523
544
|
}
|
|
524
545
|
export interface NegotiationCandidate {
|
|
525
546
|
userId: string;
|
|
547
|
+
/** Exact opportunity-bound source and candidate intent IDs. */
|
|
548
|
+
sourceIntentId?: string;
|
|
549
|
+
candidateIntentId?: string;
|
|
526
550
|
reasoning: string;
|
|
527
551
|
valencyRole: string;
|
|
528
552
|
networkId?: string;
|
|
@@ -563,6 +587,7 @@ export type OnNegotiationResolved = (entry: {
|
|
|
563
587
|
accepted: NegotiationResult | null;
|
|
564
588
|
turns: NegotiationTurn[];
|
|
565
589
|
outcome: NegotiationOutcome;
|
|
590
|
+
continuationReceipt?: import('../shared/interfaces/database.interface.js').NegotiationContinuationReceipt;
|
|
566
591
|
}) => Promise<void>;
|
|
567
592
|
/**
|
|
568
593
|
* Runs bilateral negotiation for each candidate in parallel.
|
|
@@ -584,5 +609,11 @@ export declare function negotiateCandidates(negotiationGraph: NegotiationGraphLi
|
|
|
584
609
|
* inheriting from a prior task on the same opportunity/conversation.
|
|
585
610
|
*/
|
|
586
611
|
initiatorUserId?: string;
|
|
612
|
+
/** Exact settled task to resume; only the durable run-existing path sets this. */
|
|
613
|
+
resumeFromTaskId?: string;
|
|
614
|
+
/** Deterministic settlement key paired with resumeFromTaskId. */
|
|
615
|
+
continuationSettlementId?: string;
|
|
616
|
+
/** Current durable lease/fence for this exact continuation successor. */
|
|
617
|
+
continuationExecution?: import('../shared/interfaces/database.interface.js').NegotiationContinuationExecution;
|
|
587
618
|
}): Promise<NegotiationResult[]>;
|
|
588
619
|
//# sourceMappingURL=negotiation.graph.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"negotiation.graph.d.ts","sourceRoot":"/","sources":["negotiation/negotiation.graph.ts"],"names":[],"mappings":"AAGA,OAAO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