@indexnetwork/protocol 6.8.0-rc.395.1 → 6.10.0-rc.397.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 +1 -0
- package/dist/index.d.ts +8 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.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.consultation-policy.d.ts +40 -0
- package/dist/negotiation/negotiation.consultation-policy.d.ts.map +1 -0
- package/dist/negotiation/negotiation.consultation-policy.js +69 -0
- package/dist/negotiation/negotiation.consultation-policy.js.map +1 -0
- package/dist/negotiation/negotiation.graph.d.ts +86 -28
- package/dist/negotiation/negotiation.graph.d.ts.map +1 -1
- package/dist/negotiation/negotiation.graph.js +311 -81
- 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 +25 -2
- package/dist/negotiation/negotiation.state.d.ts.map +1 -1
- package/dist/negotiation/negotiation.state.js +35 -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 +5 -0
- package/dist/questioner/questioner.agent.js.map +1 -1
- package/dist/questioner/questioner.presets.d.ts.map +1 -1
- package/dist/questioner/questioner.presets.js +9 -13
- package/dist/questioner/questioner.presets.js.map +1 -1
- package/dist/questioner/questioner.types.d.ts +47 -10
- package/dist/questioner/questioner.types.d.ts.map +1 -1
- package/dist/questioner/questioner.types.js +61 -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 +81 -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 +347 -28
- package/dist/shared/schemas/question.schema.d.ts.map +1 -1
- package/dist/shared/schemas/question.schema.js +132 -2
- package/dist/shared/schemas/question.schema.js.map +1 -1
- package/package.json +1 -1
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { DiscoveryQuestionInput } from "../shared/schemas/discovery-question.schema.js";
|
|
9
9
|
import type { ToolScopeType } from "../shared/agent/tool.scope.js";
|
|
10
|
-
import type { QuestionMode, QuestionPoolDiscriminator } from "../shared/schemas/question.schema.js";
|
|
10
|
+
import type { NegotiationQuestionCandidate, QuestionMode, QuestionPoolDiscriminator } from "../shared/schemas/question.schema.js";
|
|
11
|
+
import type { NegotiationConsultationReason } from "../negotiation/negotiation.consultation-policy.js";
|
|
11
12
|
/**
|
|
12
13
|
* Discovery context — wraps the existing DiscoveryQuestionInput wholesale.
|
|
13
14
|
* The discovery preset's buildPrompt delegates to `questioner.discovery.prompt.ts`.
|
|
@@ -38,7 +39,9 @@ export interface ProfileContext {
|
|
|
38
39
|
/** Shared context fields for negotiation-mode questions. */
|
|
39
40
|
interface NegotiationContextBase {
|
|
40
41
|
negotiationId: string;
|
|
42
|
+
/** Privacy-reviewed generic description; never raw counterparty identity/profile. */
|
|
41
43
|
counterpartyHint: string;
|
|
44
|
+
/** Source-safe network label, never an internal prompt or identifier. */
|
|
42
45
|
indexContext: string;
|
|
43
46
|
/** The user's global user_context paragraph (profile-replacing identity text). */
|
|
44
47
|
userContext?: string;
|
|
@@ -47,15 +50,14 @@ interface NegotiationContextBase {
|
|
|
47
50
|
export interface PostStallNegotiationContext extends NegotiationContextBase {
|
|
48
51
|
purpose?: undefined;
|
|
49
52
|
outcomeReason: "turn_cap" | "timeout" | "stalled";
|
|
50
|
-
|
|
53
|
+
/** The recipient's own exact opportunity-bound signal, never evaluator reasoning. */
|
|
54
|
+
recipientIntent: string;
|
|
51
55
|
}
|
|
52
56
|
/** Pre-accept uptake context targeting a counterparty's preparatory conditions. */
|
|
53
57
|
export interface UptakeNegotiationContext extends NegotiationContextBase {
|
|
54
58
|
purpose: "uptake";
|
|
55
59
|
/** Plain-language activity or commitment whose feasibility needs clarification. */
|
|
56
60
|
proposedActivity: string;
|
|
57
|
-
/** Public evidence already available about capability, resources, or authority. */
|
|
58
|
-
preparatoryEvidence?: string;
|
|
59
61
|
}
|
|
60
62
|
/** Negotiation context discriminated by internal question purpose. */
|
|
61
63
|
export type NegotiationContext = PostStallNegotiationContext | UptakeNegotiationContext;
|
|
@@ -76,6 +78,8 @@ export interface NegotiationInflightContext {
|
|
|
76
78
|
draftQuestion?: string;
|
|
77
79
|
/** Community / index context the negotiation runs in. */
|
|
78
80
|
indexContext: string;
|
|
81
|
+
/** Server-only IND-508 reason; never copied into generated or persisted payloads. */
|
|
82
|
+
consultationPolicyReason?: NegotiationConsultationReason;
|
|
79
83
|
/** The user's global user_context paragraph (profile-replacing identity text). */
|
|
80
84
|
userContext?: string;
|
|
81
85
|
}
|
|
@@ -156,17 +160,47 @@ interface QuestionerInputBase {
|
|
|
156
160
|
conversationId?: string;
|
|
157
161
|
/** Assistant message ID — set when we know which message triggered the question. Stored in detection.messageId for inline anchoring. */
|
|
158
162
|
messageId?: string;
|
|
163
|
+
/**
|
|
164
|
+
* Candidate exact binding for negotiation-family jobs. The API/DB must
|
|
165
|
+
* authoritatively re-resolve it before generation and again before insert.
|
|
166
|
+
*/
|
|
167
|
+
negotiation?: NegotiationQuestionCandidate;
|
|
159
168
|
}
|
|
160
|
-
/**
|
|
169
|
+
/** Non-negotiation modes cannot smuggle negotiation purpose/provenance. */
|
|
161
170
|
interface StandardQuestionerInput extends QuestionerInputBase {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
171
|
+
mode: Exclude<QuestionMode, "negotiation" | "negotiation_inflight">;
|
|
172
|
+
purpose?: never;
|
|
173
|
+
negotiation?: never;
|
|
174
|
+
context: Exclude<QuestionerContext, NegotiationContext | NegotiationInflightContext | RecoveryIntentContext>;
|
|
175
|
+
}
|
|
176
|
+
/** Ordinary post-stall generation is task-backed and uses only the ordinary preset. */
|
|
177
|
+
export interface PostStallQuestionerInput extends QuestionerInputBase {
|
|
178
|
+
mode: "negotiation";
|
|
179
|
+
purpose: "stalled_followup";
|
|
180
|
+
negotiation: NegotiationQuestionCandidate & {
|
|
181
|
+
purpose: "stalled_followup";
|
|
182
|
+
taskId: string;
|
|
183
|
+
};
|
|
184
|
+
context: PostStallNegotiationContext;
|
|
185
|
+
}
|
|
186
|
+
/** Mid-negotiation consultation is task-backed and uses only structured ask_user fields. */
|
|
187
|
+
export interface InflightQuestionerInput extends QuestionerInputBase {
|
|
188
|
+
mode: "negotiation_inflight";
|
|
189
|
+
purpose: "inflight_consultation";
|
|
190
|
+
negotiation: NegotiationQuestionCandidate & {
|
|
191
|
+
purpose: "inflight_consultation";
|
|
192
|
+
taskId: string;
|
|
193
|
+
};
|
|
194
|
+
context: NegotiationInflightContext;
|
|
165
195
|
}
|
|
166
196
|
/** Negotiation-mode uptake generation input. */
|
|
167
197
|
export interface UptakeQuestionerInput extends QuestionerInputBase {
|
|
168
198
|
mode: "negotiation";
|
|
169
199
|
purpose: "uptake";
|
|
200
|
+
negotiation: NegotiationQuestionCandidate & {
|
|
201
|
+
purpose: "uptake";
|
|
202
|
+
taskId?: undefined;
|
|
203
|
+
};
|
|
170
204
|
context: UptakeNegotiationContext;
|
|
171
205
|
}
|
|
172
206
|
/** Intent-mode post-discovery recovery generation input. */
|
|
@@ -175,9 +209,12 @@ export interface RecoveryQuestionerInput extends QuestionerInputBase {
|
|
|
175
209
|
purpose: "recovery";
|
|
176
210
|
sourceType: "intent";
|
|
177
211
|
triggeredByIntentId: string;
|
|
212
|
+
negotiation?: never;
|
|
178
213
|
context: RecoveryIntentContext;
|
|
179
214
|
}
|
|
180
|
-
/** Top-level input discriminated by
|
|
181
|
-
export type QuestionerInput = StandardQuestionerInput | UptakeQuestionerInput | RecoveryQuestionerInput;
|
|
215
|
+
/** Top-level input discriminated by both mode and internal purpose. */
|
|
216
|
+
export type QuestionerInput = StandardQuestionerInput | PostStallQuestionerInput | InflightQuestionerInput | UptakeQuestionerInput | RecoveryQuestionerInput;
|
|
217
|
+
/** Runtime mirror of the mode/purpose/context discriminant used at queue boundaries. */
|
|
218
|
+
export declare function isValidQuestionerInputContract(input: QuestionerInput): boolean;
|
|
182
219
|
export {};
|
|
183
220
|
//# sourceMappingURL=questioner.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"questioner.types.d.ts","sourceRoot":"/","sources":["questioner/questioner.types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,sBAAs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AAE,QAAQ,CAAC;IACf,OAAO,EAAE,UAAU,CAAC;IACpB,UAAU,EAAE,QAAQ,CAAC;IACrB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,WAAW,CAAC,EAAE,KAAK,CAAC;IACpB,OAAO,EAAE,qBAAqB,CAAC;CAChC;AAED,uEAAuE;AACvE,MAAM,MAAM,eAAe,GACvB,uBAAuB,GACvB,wBAAwB,GACxB,uBAAuB,GACvB,qBAAqB,GACrB,uBAAuB,CAAC;AAE5B,wFAAwF;AACxF,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CA8D9E"}
|
|
@@ -1,2 +1,62 @@
|
|
|
1
|
-
|
|
1
|
+
import { NEGOTIATION_QUESTION_GENERIC_COUNTERPARTY, NEGOTIATION_QUESTION_GENERIC_NETWORK, NEGOTIATION_QUESTION_GENERIC_UPTAKE_ACTIVITY, isSafeNegotiationQuestionText } from "../negotiation/negotiation.question-safety.js";
|
|
2
|
+
/** Runtime mirror of the mode/purpose/context discriminant used at queue boundaries. */
|
|
3
|
+
export function isValidQuestionerInputContract(input) {
|
|
4
|
+
if (input.purpose === 'recovery') {
|
|
5
|
+
const context = input.context;
|
|
6
|
+
return input.mode === 'intent'
|
|
7
|
+
&& input.sourceType === 'intent'
|
|
8
|
+
&& input.triggeredByIntentId === input.sourceId
|
|
9
|
+
&& input.negotiation === undefined
|
|
10
|
+
&& context.purpose === 'recovery'
|
|
11
|
+
&& context.intentId === input.sourceId;
|
|
12
|
+
}
|
|
13
|
+
if (input.mode !== 'negotiation' && input.mode !== 'negotiation_inflight') {
|
|
14
|
+
return input.purpose === undefined && input.negotiation === undefined;
|
|
15
|
+
}
|
|
16
|
+
if (input.sourceType !== 'opportunity'
|
|
17
|
+
|| !input.negotiation
|
|
18
|
+
|| input.negotiation.opportunityId !== input.sourceId
|
|
19
|
+
|| input.negotiation.recipientUserId !== input.userId
|
|
20
|
+
|| input.negotiation.purpose !== input.purpose)
|
|
21
|
+
return false;
|
|
22
|
+
const context = input.context;
|
|
23
|
+
if (context.counterpartyHint !== NEGOTIATION_QUESTION_GENERIC_COUNTERPARTY
|
|
24
|
+
|| context.indexContext !== NEGOTIATION_QUESTION_GENERIC_NETWORK)
|
|
25
|
+
return false;
|
|
26
|
+
if (input.mode === 'negotiation_inflight') {
|
|
27
|
+
return input.purpose === 'inflight_consultation'
|
|
28
|
+
&& typeof input.negotiation.taskId === 'string'
|
|
29
|
+
&& input.negotiation.taskId.length > 0
|
|
30
|
+
&& context.negotiationId === input.negotiation.taskId
|
|
31
|
+
&& typeof context.disclosureSubject === 'string'
|
|
32
|
+
&& isSafeNegotiationQuestionText(context.disclosureSubject)
|
|
33
|
+
&& (context.consultationPolicyReason === undefined
|
|
34
|
+
|| context.consultationPolicyReason === 'unresolved_owner_constraint'
|
|
35
|
+
|| context.consultationPolicyReason === 'consequential_disclosure_permission'
|
|
36
|
+
|| context.consultationPolicyReason === 'repeated_non_convergence'
|
|
37
|
+
|| context.consultationPolicyReason === 'insufficient_commitment_authority')
|
|
38
|
+
&& (context.draftQuestion === undefined
|
|
39
|
+
|| (typeof context.draftQuestion === 'string' && isSafeNegotiationQuestionText(context.draftQuestion)));
|
|
40
|
+
}
|
|
41
|
+
if (input.purpose === 'uptake') {
|
|
42
|
+
return input.negotiation.taskId === undefined
|
|
43
|
+
&& typeof input.negotiation.counterpartyUserId === 'string'
|
|
44
|
+
&& input.negotiation.counterpartyUserId.length > 0
|
|
45
|
+
&& typeof input.negotiation.counterpartyIntentId === 'string'
|
|
46
|
+
&& input.negotiation.counterpartyIntentId.length > 0
|
|
47
|
+
&& typeof input.negotiation.counterpartyFelicityAuthority === 'number'
|
|
48
|
+
&& Number.isFinite(input.negotiation.counterpartyFelicityAuthority)
|
|
49
|
+
&& context.negotiationId === input.sourceId
|
|
50
|
+
&& context.purpose === 'uptake'
|
|
51
|
+
&& context.proposedActivity === NEGOTIATION_QUESTION_GENERIC_UPTAKE_ACTIVITY;
|
|
52
|
+
}
|
|
53
|
+
return input.purpose === 'stalled_followup'
|
|
54
|
+
&& typeof input.negotiation.taskId === 'string'
|
|
55
|
+
&& input.negotiation.taskId.length > 0
|
|
56
|
+
&& context.negotiationId === input.negotiation.taskId
|
|
57
|
+
&& context.purpose === undefined
|
|
58
|
+
&& (context.outcomeReason === 'turn_cap' || context.outcomeReason === 'timeout' || context.outcomeReason === 'stalled')
|
|
59
|
+
&& typeof context.recipientIntent === 'string'
|
|
60
|
+
&& context.recipientIntent.trim().length > 0;
|
|
61
|
+
}
|
|
2
62
|
//# sourceMappingURL=questioner.types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"questioner.types.js","sourceRoot":"/","sources":["questioner/questioner.types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * QuestionerAgent input types. The `QuestionerInput` envelope carries a `mode`\n * field that selects a preset, plus a polymorphic `context` that varies per mode.\n *\n * Slice 1 defines all four context shapes but only `DiscoveryContext` has a\n * working preset implementation. The others are type stubs for future slices.\n */\nimport type { DiscoveryQuestionInput } from \"../shared/schemas/discovery-question.schema.js\";\nimport type { ToolScopeType } from \"../shared/agent/tool.scope.js\";\nimport type { QuestionMode, QuestionPoolDiscriminator } from \"../shared/schemas/question.schema.js\";\n\n// ─── Per-mode context types ─────────────────────────────────────────────────\n\n/**\n * Discovery context — wraps the existing DiscoveryQuestionInput wholesale.\n * The discovery preset's buildPrompt delegates to `questioner.discovery.prompt.ts`.\n */\nexport type DiscoveryContext = DiscoveryQuestionInput;\n\n/** Intent context — data needed to generate questions about an intent. */\nexport interface IntentContext {\n intentId: string;\n payload: string;\n summary?: string;\n /** The user's global user_context paragraph (profile-replacing identity text). */\n userContext?: string;\n}\n\n/** Recovery-only intent context after a successful discovery completion. */\nexport interface RecoveryIntentContext extends IntentContext {\n purpose: \"recovery\";\n /** Privacy-safe aggregate signal; raw negotiation evidence is never provided. */\n rejectedNegotiationCount?: number;\n}\n\n/** Profile context — data needed to generate questions to fill profile gaps. */\nexport interface ProfileContext {\n /** The user's global user_context paragraph (profile-replacing identity text). */\n userContext?: string;\n gaps: string[];\n /** Existing premise texts the user has already stated (e.g. \"I live in Berlin\"). */\n existingPremises?: string[];\n}\n\n/** Shared context fields for negotiation-mode questions. */\ninterface NegotiationContextBase {\n negotiationId: string;\n counterpartyHint: string;\n indexContext: string;\n /** The user's global user_context paragraph (profile-replacing identity text). */\n userContext?: string;\n}\n\n/** Post-stall negotiation context. Preserves the existing source shape. */\nexport interface PostStallNegotiationContext extends NegotiationContextBase {\n purpose?: undefined;\n outcomeReason: \"turn_cap\" | \"timeout\" | \"stalled\";\n keyTake: string;\n}\n\n/** Pre-accept uptake context targeting a counterparty's preparatory conditions. */\nexport interface UptakeNegotiationContext extends NegotiationContextBase {\n purpose: \"uptake\";\n /** Plain-language activity or commitment whose feasibility needs clarification. */\n proposedActivity: string;\n /** Public evidence already available about capability, resources, or authority. */\n preparatoryEvidence?: string;\n}\n\n/** Negotiation context discriminated by internal question purpose. */\nexport type NegotiationContext = PostStallNegotiationContext | UptakeNegotiationContext;\n\n/**\n * Negotiation-inflight context — a negotiator mid-negotiation wants to ask its\n * OWN client a question before continuing (the `ask_user` action, P3.2). The\n * negotiator states the disclosure subject and optionally drafts the question;\n * the QuestionerAgent refines it into polished disclosure-gating questions.\n * Distinct from {@link NegotiationContext}, which covers post-stall questions.\n */\nexport interface NegotiationInflightContext {\n negotiationId: string;\n /** Anonymized counterparty description (attributes, never identity). */\n counterpartyHint: string;\n /** What the negotiator wants permission to share or needs to know (e.g. \"budget range\", \"availability in Q3\"). */\n disclosureSubject: string;\n /** Draft question authored by the negotiator. The agent refines it. */\n draftQuestion?: string;\n /** Community / index context the negotiation runs in. */\n indexContext: string;\n /** The user's global user_context paragraph (profile-replacing identity text). */\n userContext?: string;\n}\n\n/**\n * Chat context — data for orchestrator-initiated mid-conversation questions\n * (the `ask_user_question` tool). The orchestrator states what it needs to\n * learn; the QuestionerAgent turns that into polished structured questions,\n * grounded in the recent conversation and the user's identity context.\n */\nexport interface ChatContext {\n /** What the orchestrator needs to learn and why (authored by the chat model). */\n purpose: string;\n /** Draft questions proposed by the orchestrator. The agent refines these. */\n draftQuestions?: Array<{\n prompt: string;\n options?: string[];\n multiSelect?: boolean;\n }>;\n /** Recent conversation excerpt for grounding (most recent messages last). */\n conversationExcerpt?: string;\n /** The user's global user_context paragraph (profile-replacing identity text). */\n userContext?: string;\n}\n\n/**\n * Pool-discovery context — mined discriminators from a discovery-run pool\n * (IND-418). No generator LLM runs for this mode: the QuestionerQueue\n * synthesizes the question deterministically from the top discriminator and\n * stashes the rest as interview-mode alternates.\n */\nexport interface PoolDiscoveryContext {\n intentId: string;\n /** Truncated intent payload (+ summary) display snippet. */\n intentText: string;\n /** Stable hash of the full normalized payload + summary used for freshness. */\n intentFingerprint?: string;\n poolSize: number;\n /** Exact bounded candidate opportunity IDs supplied to synthesis. */\n opportunityIds: string[];\n /** Discovery run that produced the pool. */\n runId?: string;\n /** Eligible discriminators, VoI-descending (asked + chain alternates). */\n discriminators: QuestionPoolDiscriminator[];\n /** ISO-8601 timestamp of the mining pass. */\n minedAt: string;\n}\n\n/** Discriminated union: mode selects the context shape. */\nexport type QuestionerContext =\n | DiscoveryContext\n | IntentContext\n | RecoveryIntentContext\n | ProfileContext\n | NegotiationContext\n | NegotiationInflightContext\n | ChatContext\n | PoolDiscoveryContext;\n\n/**\n * Payload shape accepted by the questionerEnqueue callback. Covers all\n * question modes — the composition root bridges this to the concrete\n * QuestionerQueue.\n */\nexport type QuestionerEnqueuePayload = QuestionerInput;\n\n/** Callback signature for async question generation enqueue. */\nexport type QuestionerEnqueueFn = (input: QuestionerEnqueuePayload) => Promise<void>;\n\n/** Top-level input envelope for QuestionerAgent.invoke(). */\ninterface QuestionerInputBase {\n /** Selects the preset (system prompt + builder). */\n mode: QuestionMode;\n /** User the questions are generated for. */\n userId: string;\n /** Entity type that triggered this (e.g. \"opportunity\", \"intent\", \"profile\"). */\n sourceType: string;\n /** ID of the triggering entity. */\n sourceId: string;\n /** Scoped question context. Network scopes persist as QuestionActor.networkId. */\n scopeType?: ToolScopeType;\n /** Scoped question id. When scopeType is `network`, this is the actor networkId. */\n scopeId?: string;\n /**\n * Intent that triggered the run that generated these questions. Persisted as\n * `detection.triggeredBy` so intent-scoped surfaces (e.g. the intent page)\n * can find them. Independent of `scopeType`/`scopeId`, which may carry a\n * network scope at the same time.\n */\n triggeredByIntentId?: string;\n /** Conversation ID — set when the question originates from a chat session. Persisted on the question row for frontend filtering. */\n conversationId?: string;\n /** Assistant message ID — set when we know which message triggered the question. Stored in detection.messageId for inline anchoring. */\n messageId?: string;\n}\n\n/** Existing question inputs, including post-stall negotiation source compatibility. */\ninterface StandardQuestionerInput extends QuestionerInputBase {\n purpose?: undefined;\n /** Mode-specific context. Must align with the selected mode. */\n context: Exclude<QuestionerContext, UptakeNegotiationContext | RecoveryIntentContext>;\n}\n\n/** Negotiation-mode uptake generation input. */\nexport interface UptakeQuestionerInput extends QuestionerInputBase {\n mode: \"negotiation\";\n purpose: \"uptake\";\n context: UptakeNegotiationContext;\n}\n\n/** Intent-mode post-discovery recovery generation input. */\nexport interface RecoveryQuestionerInput extends QuestionerInputBase {\n mode: \"intent\";\n purpose: \"recovery\";\n sourceType: \"intent\";\n triggeredByIntentId: string;\n context: RecoveryIntentContext;\n}\n\n/** Top-level input discriminated by the internal purpose. */\nexport type QuestionerInput = StandardQuestionerInput | UptakeQuestionerInput | RecoveryQuestionerInput;\n"]}
|
|
1
|
+
{"version":3,"file":"questioner.types.js","sourceRoot":"/","sources":["questioner/questioner.types.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,yCAAyC,EAAE,oCAAoC,EAAE,4CAA4C,EAAE,6BAA6B,EAAE,MAAM,+CAA+C,CAAC;AA2O7N,wFAAwF;AACxF,MAAM,UAAU,8BAA8B,CAAC,KAAsB;IACnE,IAAI,KAAK,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;QACjC,MAAM,OAAO,GAAG,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MAAM,GAAG,CAAC;WACnC,OAAO,CAAC,aAAa,KAAK,KAAK,CAAC,WAAW,CAAC,MAAM;WAClD,OAAO,CAAC,OAAO,KAAK,SAAS;WAC7B,CAAC,OAAO,CAAC,aAAa,KAAK,UAAU,IAAI,OAAO,CAAC,aAAa,KAAK,SAAS,IAAI,OAAO,CAAC,aAAa,KAAK,SAAS,CAAC;WACpH,OAAO,OAAO,CAAC,eAAe,KAAK,QAAQ;WAC3C,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;AACjD,CAAC","sourcesContent":["/**\n * QuestionerAgent input types. The `QuestionerInput` envelope carries a `mode`\n * field that selects a preset, plus a polymorphic `context` that varies per mode.\n *\n * Slice 1 defines all four context shapes but only `DiscoveryContext` has a\n * working preset implementation. The others are type stubs for future slices.\n */\nimport type { DiscoveryQuestionInput } from \"../shared/schemas/discovery-question.schema.js\";\nimport type { ToolScopeType } from \"../shared/agent/tool.scope.js\";\nimport type { NegotiationQuestionCandidate, QuestionMode, QuestionPoolDiscriminator } from \"../shared/schemas/question.schema.js\";\nimport { NEGOTIATION_QUESTION_GENERIC_COUNTERPARTY, NEGOTIATION_QUESTION_GENERIC_NETWORK, NEGOTIATION_QUESTION_GENERIC_UPTAKE_ACTIVITY, isSafeNegotiationQuestionText } from \"../negotiation/negotiation.question-safety.js\";\nimport type { NegotiationConsultationReason } from \"../negotiation/negotiation.consultation-policy.js\";\n\n// ─── Per-mode context types ─────────────────────────────────────────────────\n\n/**\n * Discovery context — wraps the existing DiscoveryQuestionInput wholesale.\n * The discovery preset's buildPrompt delegates to `questioner.discovery.prompt.ts`.\n */\nexport type DiscoveryContext = DiscoveryQuestionInput;\n\n/** Intent context — data needed to generate questions about an intent. */\nexport interface IntentContext {\n intentId: string;\n payload: string;\n summary?: string;\n /** The user's global user_context paragraph (profile-replacing identity text). */\n userContext?: string;\n}\n\n/** Recovery-only intent context after a successful discovery completion. */\nexport interface RecoveryIntentContext extends IntentContext {\n purpose: \"recovery\";\n /** Privacy-safe aggregate signal; raw negotiation evidence is never provided. */\n rejectedNegotiationCount?: number;\n}\n\n/** Profile context — data needed to generate questions to fill profile gaps. */\nexport interface ProfileContext {\n /** The user's global user_context paragraph (profile-replacing identity text). */\n userContext?: string;\n gaps: string[];\n /** Existing premise texts the user has already stated (e.g. \"I live in Berlin\"). */\n existingPremises?: string[];\n}\n\n/** Shared context fields for negotiation-mode questions. */\ninterface NegotiationContextBase {\n negotiationId: string;\n /** Privacy-reviewed generic description; never raw counterparty identity/profile. */\n counterpartyHint: string;\n /** Source-safe network label, never an internal prompt or identifier. */\n indexContext: string;\n /** The user's global user_context paragraph (profile-replacing identity text). */\n userContext?: string;\n}\n\n/** Post-stall negotiation context. Preserves the existing source shape. */\nexport interface PostStallNegotiationContext extends NegotiationContextBase {\n purpose?: undefined;\n outcomeReason: \"turn_cap\" | \"timeout\" | \"stalled\";\n /** The recipient's own exact opportunity-bound signal, never evaluator reasoning. */\n recipientIntent: string;\n}\n\n/** Pre-accept uptake context targeting a counterparty's preparatory conditions. */\nexport interface UptakeNegotiationContext extends NegotiationContextBase {\n purpose: \"uptake\";\n /** Plain-language activity or commitment whose feasibility needs clarification. */\n proposedActivity: string;\n}\n\n/** Negotiation context discriminated by internal question purpose. */\nexport type NegotiationContext = PostStallNegotiationContext | UptakeNegotiationContext;\n\n/**\n * Negotiation-inflight context — a negotiator mid-negotiation wants to ask its\n * OWN client a question before continuing (the `ask_user` action, P3.2). The\n * negotiator states the disclosure subject and optionally drafts the question;\n * the QuestionerAgent refines it into polished disclosure-gating questions.\n * Distinct from {@link NegotiationContext}, which covers post-stall questions.\n */\nexport interface NegotiationInflightContext {\n negotiationId: string;\n /** Anonymized counterparty description (attributes, never identity). */\n counterpartyHint: string;\n /** What the negotiator wants permission to share or needs to know (e.g. \"budget range\", \"availability in Q3\"). */\n disclosureSubject: string;\n /** Draft question authored by the negotiator. The agent refines it. */\n draftQuestion?: string;\n /** Community / index context the negotiation runs in. */\n indexContext: string;\n /** Server-only IND-508 reason; never copied into generated or persisted payloads. */\n consultationPolicyReason?: NegotiationConsultationReason;\n /** The user's global user_context paragraph (profile-replacing identity text). */\n userContext?: string;\n}\n\n/**\n * Chat context — data for orchestrator-initiated mid-conversation questions\n * (the `ask_user_question` tool). The orchestrator states what it needs to\n * learn; the QuestionerAgent turns that into polished structured questions,\n * grounded in the recent conversation and the user's identity context.\n */\nexport interface ChatContext {\n /** What the orchestrator needs to learn and why (authored by the chat model). */\n purpose: string;\n /** Draft questions proposed by the orchestrator. The agent refines these. */\n draftQuestions?: Array<{\n prompt: string;\n options?: string[];\n multiSelect?: boolean;\n }>;\n /** Recent conversation excerpt for grounding (most recent messages last). */\n conversationExcerpt?: string;\n /** The user's global user_context paragraph (profile-replacing identity text). */\n userContext?: string;\n}\n\n/**\n * Pool-discovery context — mined discriminators from a discovery-run pool\n * (IND-418). No generator LLM runs for this mode: the QuestionerQueue\n * synthesizes the question deterministically from the top discriminator and\n * stashes the rest as interview-mode alternates.\n */\nexport interface PoolDiscoveryContext {\n intentId: string;\n /** Truncated intent payload (+ summary) display snippet. */\n intentText: string;\n /** Stable hash of the full normalized payload + summary used for freshness. */\n intentFingerprint?: string;\n poolSize: number;\n /** Exact bounded candidate opportunity IDs supplied to synthesis. */\n opportunityIds: string[];\n /** Discovery run that produced the pool. */\n runId?: string;\n /** Eligible discriminators, VoI-descending (asked + chain alternates). */\n discriminators: QuestionPoolDiscriminator[];\n /** ISO-8601 timestamp of the mining pass. */\n minedAt: string;\n}\n\n/** Discriminated union: mode selects the context shape. */\nexport type QuestionerContext =\n | DiscoveryContext\n | IntentContext\n | RecoveryIntentContext\n | ProfileContext\n | NegotiationContext\n | NegotiationInflightContext\n | ChatContext\n | PoolDiscoveryContext;\n\n/**\n * Payload shape accepted by the questionerEnqueue callback. Covers all\n * question modes — the composition root bridges this to the concrete\n * QuestionerQueue.\n */\nexport type QuestionerEnqueuePayload = QuestionerInput;\n\n/** Callback signature for async question generation enqueue. */\nexport type QuestionerEnqueueFn = (input: QuestionerEnqueuePayload) => Promise<void>;\n\n/** Top-level input envelope for QuestionerAgent.invoke(). */\ninterface QuestionerInputBase {\n /** Selects the preset (system prompt + builder). */\n mode: QuestionMode;\n /** User the questions are generated for. */\n userId: string;\n /** Entity type that triggered this (e.g. \"opportunity\", \"intent\", \"profile\"). */\n sourceType: string;\n /** ID of the triggering entity. */\n sourceId: string;\n /** Scoped question context. Network scopes persist as QuestionActor.networkId. */\n scopeType?: ToolScopeType;\n /** Scoped question id. When scopeType is `network`, this is the actor networkId. */\n scopeId?: string;\n /**\n * Intent that triggered the run that generated these questions. Persisted as\n * `detection.triggeredBy` so intent-scoped surfaces (e.g. the intent page)\n * can find them. Independent of `scopeType`/`scopeId`, which may carry a\n * network scope at the same time.\n */\n triggeredByIntentId?: string;\n /** Conversation ID — set when the question originates from a chat session. Persisted on the question row for frontend filtering. */\n conversationId?: string;\n /** Assistant message ID — set when we know which message triggered the question. Stored in detection.messageId for inline anchoring. */\n messageId?: string;\n /**\n * Candidate exact binding for negotiation-family jobs. The API/DB must\n * authoritatively re-resolve it before generation and again before insert.\n */\n negotiation?: NegotiationQuestionCandidate;\n}\n\n/** Non-negotiation modes cannot smuggle negotiation purpose/provenance. */\ninterface StandardQuestionerInput extends QuestionerInputBase {\n mode: Exclude<QuestionMode, \"negotiation\" | \"negotiation_inflight\">;\n purpose?: never;\n negotiation?: never;\n context: Exclude<QuestionerContext, NegotiationContext | NegotiationInflightContext | RecoveryIntentContext>;\n}\n\n/** Ordinary post-stall generation is task-backed and uses only the ordinary preset. */\nexport interface PostStallQuestionerInput extends QuestionerInputBase {\n mode: \"negotiation\";\n purpose: \"stalled_followup\";\n negotiation: NegotiationQuestionCandidate & { purpose: \"stalled_followup\"; taskId: string };\n context: PostStallNegotiationContext;\n}\n\n/** Mid-negotiation consultation is task-backed and uses only structured ask_user fields. */\nexport interface InflightQuestionerInput extends QuestionerInputBase {\n mode: \"negotiation_inflight\";\n purpose: \"inflight_consultation\";\n negotiation: NegotiationQuestionCandidate & { purpose: \"inflight_consultation\"; taskId: string };\n context: NegotiationInflightContext;\n}\n\n/** Negotiation-mode uptake generation input. */\nexport interface UptakeQuestionerInput extends QuestionerInputBase {\n mode: \"negotiation\";\n purpose: \"uptake\";\n negotiation: NegotiationQuestionCandidate & { purpose: \"uptake\"; taskId?: undefined };\n context: UptakeNegotiationContext;\n}\n\n/** Intent-mode post-discovery recovery generation input. */\nexport interface RecoveryQuestionerInput extends QuestionerInputBase {\n mode: \"intent\";\n purpose: \"recovery\";\n sourceType: \"intent\";\n triggeredByIntentId: string;\n negotiation?: never;\n context: RecoveryIntentContext;\n}\n\n/** Top-level input discriminated by both mode and internal purpose. */\nexport type QuestionerInput =\n | StandardQuestionerInput\n | PostStallQuestionerInput\n | InflightQuestionerInput\n | UptakeQuestionerInput\n | RecoveryQuestionerInput;\n\n/** Runtime mirror of the mode/purpose/context discriminant used at queue boundaries. */\nexport function isValidQuestionerInputContract(input: QuestionerInput): boolean {\n if (input.purpose === 'recovery') {\n const context = input.context as RecoveryIntentContext;\n return input.mode === 'intent'\n && input.sourceType === 'intent'\n && input.triggeredByIntentId === input.sourceId\n && input.negotiation === undefined\n && context.purpose === 'recovery'\n && context.intentId === input.sourceId;\n }\n if (input.mode !== 'negotiation' && input.mode !== 'negotiation_inflight') {\n return input.purpose === undefined && input.negotiation === undefined;\n }\n if (\n input.sourceType !== 'opportunity'\n || !input.negotiation\n || input.negotiation.opportunityId !== input.sourceId\n || input.negotiation.recipientUserId !== input.userId\n || input.negotiation.purpose !== input.purpose\n ) return false;\n\n const context = input.context as unknown as Record<string, unknown>;\n if (\n context.counterpartyHint !== NEGOTIATION_QUESTION_GENERIC_COUNTERPARTY\n || context.indexContext !== NEGOTIATION_QUESTION_GENERIC_NETWORK\n ) return false;\n\n if (input.mode === 'negotiation_inflight') {\n return input.purpose === 'inflight_consultation'\n && typeof input.negotiation.taskId === 'string'\n && input.negotiation.taskId.length > 0\n && context.negotiationId === input.negotiation.taskId\n && typeof context.disclosureSubject === 'string'\n && isSafeNegotiationQuestionText(context.disclosureSubject)\n && (context.consultationPolicyReason === undefined\n || context.consultationPolicyReason === 'unresolved_owner_constraint'\n || context.consultationPolicyReason === 'consequential_disclosure_permission'\n || context.consultationPolicyReason === 'repeated_non_convergence'\n || context.consultationPolicyReason === 'insufficient_commitment_authority')\n && (context.draftQuestion === undefined\n || (typeof context.draftQuestion === 'string' && isSafeNegotiationQuestionText(context.draftQuestion)));\n }\n if (input.purpose === 'uptake') {\n return input.negotiation.taskId === undefined\n && typeof input.negotiation.counterpartyUserId === 'string'\n && input.negotiation.counterpartyUserId.length > 0\n && typeof input.negotiation.counterpartyIntentId === 'string'\n && input.negotiation.counterpartyIntentId.length > 0\n && typeof input.negotiation.counterpartyFelicityAuthority === 'number'\n && Number.isFinite(input.negotiation.counterpartyFelicityAuthority)\n && context.negotiationId === input.sourceId\n && context.purpose === 'uptake'\n && context.proposedActivity === NEGOTIATION_QUESTION_GENERIC_UPTAKE_ACTIVITY;\n }\n return input.purpose === 'stalled_followup'\n && typeof input.negotiation.taskId === 'string'\n && input.negotiation.taskId.length > 0\n && context.negotiationId === input.negotiation.taskId\n && context.purpose === undefined\n && (context.outcomeReason === 'turn_cap' || context.outcomeReason === 'timeout' || context.outcomeReason === 'stalled')\n && typeof context.recipientIntent === 'string'\n && context.recipientIntent.trim().length > 0;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.factory.d.ts","sourceRoot":"/","sources":["shared/agent/tool.factory.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,mBAAmB,EAAmE,MAAM,mBAAmB,CAAC;AAiBhJ,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACxF,YAAY,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAQlD;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,WAAW,EACjB,kBAAkB,CAAC,EAAE,mBAAmB,
|
|
1
|
+
{"version":3,"file":"tool.factory.d.ts","sourceRoot":"/","sources":["shared/agent/tool.factory.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,mBAAmB,EAAmE,MAAM,mBAAmB,CAAC;AAiBhJ,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACxF,YAAY,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAQlD;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,WAAW,EACjB,kBAAkB,CAAC,EAAE,mBAAmB,kBAmOzC;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC,CAAC"}
|
|
@@ -170,6 +170,7 @@ export async function createChatTools(deps, preResolvedContext) {
|
|
|
170
170
|
...(deps.questionGenerator && { questionGenerator: deps.questionGenerator }),
|
|
171
171
|
...(sessionAwareEnqueue && { questionerEnqueue: sessionAwareEnqueue }),
|
|
172
172
|
...(deps.findPendingQuestions && { findPendingQuestions: deps.findPendingQuestions }),
|
|
173
|
+
...(deps.answerPendingQuestion && { answerPendingQuestion: deps.answerPendingQuestion }),
|
|
173
174
|
...(deps.negotiationSummary && { negotiationSummary: deps.negotiationSummary }),
|
|
174
175
|
...(deps.chatQuestions && { chatQuestions: deps.chatQuestions }),
|
|
175
176
|
...(deps.chatSession && { chatSession: deps.chatSession }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.factory.js","sourceRoot":"/","sources":["shared/agent/tool.factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAG7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AA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CAAsB,CAAC,IAAI,CAAC,CACxE,CAAC;IAEF,OAAO;QACL,GAAG,YAAY;QACf,GAAG,WAAW;QACd,GAAG,YAAY;QACf,GAAG,uBAAuB;QAC1B,GAAG,YAAY;QACf,GAAG,gBAAgB;QACnB,GAAG,YAAY;QACf,GAAG,UAAU;QACb,GAAG,gBAAgB;QACnB,GAAG,YAAY;QACf,GAAG,eAAe;QAClB,GAAG,oBAAoB;KACxB,CAAC;AACJ,CAAC","sourcesContent":["import { tool } from \"@langchain/core/tools\";\nimport { z } from \"zod\";\nimport type { HydeGraphDatabase } from \"../interfaces/database.interface.js\";\nimport { IntentGraphFactory } from \"../../intent/intent.graph.js\";\nimport { EnrichmentGraphFactory } from \"../../enrichment/enrichment.graph.js\";\nimport { OpportunityGraphFactory } from \"../../opportunity/opportunity.graph.js\";\nimport { HydeGraphFactory } from \"../hyde/hyde.graph.js\";\nimport { HydeGenerator } from \"../hyde/hyde.generator.js\";\nimport { LensInferrer } from \"../hyde/lens.inferrer.js\";\nimport { NetworkGraphFactory } from \"../../network/network.graph.js\";\nimport { NetworkMembershipGraphFactory } from \"../../network/membership/membership.graph.js\";\nimport { IntentNetworkGraphFactory } from \"../../network/indexer/indexer.graph.js\";\nimport { IntentIndexer } from \"../../intent/intent.indexer.js\";\nimport { NegotiationGraphFactory } from \"../../negotiation/negotiation.graph.js\";\nimport { PremiseGraphFactory } from \"../../premise/premise.graph.js\";\nimport { protocolLogger } from \"../observability/protocol.logger.js\";\n\nimport type { QuestionerEnqueueFn } from \"../../questioner/questioner.types.js\";\n\nimport { type ToolContext, type ResolvedToolContext, type ToolDeps, resolveChatContext, error, redactSensitiveFields } from \"./tool.helpers.js\";\nimport { deriveAllowedNetworkIds, scopeFromNetworkId } from \"./tool.scope.js\";\nimport { invokeToolRuntime, toolRuntimeErrorToResult } from \"./tool.runtime.js\";\nimport { createEnrichmentTools } from \"../../enrichment/enrichment.tools.js\";\nimport { createIntentTools } from \"../../intent/intent.tools.js\";\nimport { createNetworkTools } from \"../../network/network.tools.js\";\nimport { createOpportunityTools } from \"../../opportunity/opportunity.tools.js\";\nimport { createUtilityTools } from \"./utility.tools.js\";\nimport { createIntegrationTools } from \"../../integration/integration.tools.js\";\nimport { createContactTools } from \"../../contact/contact.tools.js\";\nimport { createAgentTools } from \"../../agent/agent.tools.js\";\nimport { createNegotiationTools } from \"../../negotiation/negotiation.tools.js\";\nimport { createPremiseTools } from \"../../premise/premise.tools.js\";\nimport { createQuestionerTools } from \"../../questioner/questioner.tools.js\";\nimport { createAskUserQuestionTools } from \"../../questioner/questioner.ask.tool.js\";\n\n// Re-export types for consumers\nexport type { ToolContext, ResolvedToolContext, ProtocolDeps } from \"./tool.helpers.js\";\nexport type { ToolDeps } from \"./tool.helpers.js\";\n\nconst logger = protocolLogger(\"ChatTools\");\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// TOOL FACTORY\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/**\n * Creates all chat tools bound to a specific user context.\n * Resolves user/network identity from DB at init time.\n * Tools are created fresh for each user session to ensure proper isolation.\n *\n * All external dependencies (cache, integration, queue, etc.) are provided\n * via the `deps` parameter — the protocol lib never imports concrete adapters.\n */\nexport async function createChatTools(\n deps: ToolContext,\n preResolvedContext?: ResolvedToolContext\n) {\n const { database, embedder, scraper } = deps;\n\n const explicitScope = deps.scopeType && deps.scopeId\n ? { scopeType: deps.scopeType, scopeId: deps.scopeId }\n : scopeFromNetworkId(deps.networkId);\n\n // ─── Resolve context from DB ───────────────────────────────────────────────\n // resolveChatContext still accepts a networkId because it loads scoped index\n // presentation metadata; the canonical request scope is explicitScope.\n const resolvedContext =\n preResolvedContext ??\n (await resolveChatContext({\n database,\n userId: deps.userId,\n networkId: explicitScope.scopeType === 'network' ? explicitScope.scopeId : deps.networkId,\n sessionId: deps.sessionId,\n contactsEnabled: deps.contactsEnabled,\n actionToolsEnabled: deps.actionToolsEnabled,\n }));\n\n if (!preResolvedContext && explicitScope.scopeType && explicitScope.scopeId) {\n resolvedContext.scopeType = explicitScope.scopeType;\n resolvedContext.scopeId = explicitScope.scopeId;\n }\n\n const allowedNetworkIds = deriveAllowedNetworkIds({\n memberships: resolvedContext.userNetworks,\n ...(resolvedContext.scopeType && resolvedContext.scopeId\n ? { scopeType: resolvedContext.scopeType, scopeId: resolvedContext.scopeId }\n : {}),\n });\n\n // ─── Tool wrapper ──────────────────────────────────────────────────────────\n /**\n * Standardized tool factory. Auto-injects resolved context and\n * provides uniform logging / error handling for every tool.\n */\n function defineTool<T extends z.ZodType>(opts: {\n name: string;\n description: string;\n querySchema: T;\n handler: (input: { context: ResolvedToolContext; query: z.infer<T> }) => Promise<string>;\n }) {\n return tool(\n async (query: z.infer<T>) => {\n logger.info('Tool invoked', {\n toolName: opts.name,\n context: { userId: resolvedContext.userId, scopeType: resolvedContext.scopeType, scopeId: resolvedContext.scopeId },\n query: redactSensitiveFields(query),\n });\n try {\n return await invokeToolRuntime({\n toolName: opts.name,\n tool: { handler: async ({ context, query }) => opts.handler({ context, query: query as z.infer<T> }) },\n context: resolvedContext,\n query,\n });\n } catch (err) {\n logger.error('Tool failed', {\n toolName: opts.name,\n error: err instanceof Error ? err.message : String(err),\n });\n const runtimeResult = toolRuntimeErrorToResult(err);\n if (runtimeResult) return runtimeResult;\n const reason = err instanceof Error ? err.message : String(err);\n return error(`Failed to execute ${opts.name}: ${reason}`);\n }\n },\n { name: opts.name, description: opts.description, schema: opts.querySchema }\n );\n }\n\n // ─── Compile subgraphs ─────────────────────────────────────────────────────\n\n // Wrap questionerEnqueue to include scoped/session context when available.\n const sessionAwareEnqueue: QuestionerEnqueueFn | undefined = deps.questionerEnqueue\n ? (input) => deps.questionerEnqueue!({\n ...input,\n ...(resolvedContext.scopeType && resolvedContext.scopeId && !input.scopeId\n ? { scopeType: resolvedContext.scopeType, scopeId: resolvedContext.scopeId }\n : {}),\n ...(resolvedContext.sessionId && !input.conversationId ? { conversationId: resolvedContext.sessionId } : {}),\n })\n : undefined;\n\n const intentGraph = new IntentGraphFactory(database, embedder, deps.intentQueue, sessionAwareEnqueue).createGraph();\n const premiseGraph = new PremiseGraphFactory(database, embedder).createGraph();\n const profileGraph = new EnrichmentGraphFactory(database, scraper, deps.enricher, sessionAwareEnqueue, premiseGraph).createGraph();\n const hydeCache = deps.hydeCache;\n const lensInferrer = new LensInferrer();\n const hydeGenerator = new HydeGenerator();\n const compiledHydeGraph = new HydeGraphFactory(\n database as unknown as HydeGraphDatabase,\n embedder,\n hydeCache,\n lensInferrer,\n hydeGenerator\n ).createGraph();\n const negotiationGraph = deps.agentDispatcher\n ? new NegotiationGraphFactory(\n deps.negotiationDatabase,\n deps.agentDispatcher,\n deps.negotiationTimeoutQueue,\n sessionAwareEnqueue,\n ).createGraph()\n : undefined;\n const opportunityGraph = new OpportunityGraphFactory(\n database,\n embedder,\n compiledHydeGraph,\n undefined, // evaluator (default)\n undefined, // queueNotification\n negotiationGraph,\n deps.agentDispatcher,\n deps.queueNegotiateExisting,\n deps.stampNewbornOpportunities,\n ).createGraph();\n const networkGraph = new NetworkGraphFactory(database).createGraph();\n const networkMembershipGraph = new NetworkMembershipGraphFactory(database).createGraph();\n const intentNetworkGraph = new IntentNetworkGraphFactory(database, new IntentIndexer()).createGraph();\n\n // ─── Create context-bound databases ────────────────────────────────────────\n // Use injected instances when provided (e.g. tests). Otherwise create from the same\n // database used for graphs so that scope checks (e.g. ensureScopedMembership, opportunity\n // update) use the same adapter as the rest of the tool pipeline.\n //\n // The systemDb's DB-level clamp derives concrete allowed network IDs from the\n // focused scope envelope plus memberships, rather than consuming a transported\n // legacy indexScope array.\n const userDb = deps.userDb ?? deps.createUserDatabase(database, resolvedContext.userId);\n const systemDb = deps.systemDb ?? deps.createSystemDatabase(database, resolvedContext.userId, allowedNetworkIds, embedder);\n\n // ─── Assemble dependencies ─────────────────────────────────────────────────\n const cache = deps.cache;\n const integration = deps.integration;\n const toolDeps: ToolDeps = {\n database,\n userDb,\n systemDb,\n scraper,\n embedder,\n cache,\n integration,\n contactService: deps.contactService,\n contactsEnabled: deps.contactsEnabled,\n integrationImporter: deps.integrationImporter,\n enricher: deps.enricher,\n negotiationDatabase: deps.negotiationDatabase,\n negotiationTimeoutQueue: deps.negotiationTimeoutQueue,\n agentDatabase: deps.agentDatabase,\n grantDefaultSystemPermissions: deps.grantDefaultSystemPermissions,\n agentDispatcher: deps.agentDispatcher,\n stampNewbornOpportunities: deps.stampNewbornOpportunities,\n deliveryLedger: deps.deliveryLedger,\n discoveryRuns: deps.discoveryRuns,\n discoveryRunQueue: deps.discoveryRunQueue,\n enrichmentRuns: deps.enrichmentRuns,\n enrichmentRunQueue: deps.enrichmentRunQueue,\n mintConnectToken: deps.mintConnectToken,\n mintConnectLink: deps.mintConnectLink,\n frontendUrl: deps.frontendUrl,\n apiBaseUrl: deps.apiBaseUrl,\n ...(deps.chatSummary && { chatSummary: deps.chatSummary }),\n ...(deps.questionGenerator && { questionGenerator: deps.questionGenerator }),\n ...(sessionAwareEnqueue && { questionerEnqueue: sessionAwareEnqueue }),\n ...(deps.findPendingQuestions && { findPendingQuestions: deps.findPendingQuestions }),\n ...(deps.negotiationSummary && { negotiationSummary: deps.negotiationSummary }),\n ...(deps.chatQuestions && { chatQuestions: deps.chatQuestions }),\n ...(deps.chatSession && { chatSession: deps.chatSession }),\n ...(deps.getUserContextText && { getUserContextText: deps.getUserContextText }),\n graphs: {\n profile: profileGraph,\n intent: intentGraph,\n index: networkGraph,\n networkMembership: networkMembershipGraph,\n intentIndex: intentNetworkGraph,\n opportunity: opportunityGraph,\n premise: premiseGraph,\n },\n };\n\n // ─── Create domain tools ──────────────────────────────────────────────────\n const profileTools = createEnrichmentTools(defineTool, toolDeps);\n const intentTools = createIntentTools(defineTool, toolDeps);\n const networkTools = createNetworkTools(defineTool, toolDeps);\n const opportunityTools = createOpportunityTools(defineTool, toolDeps);\n const utilityTools = createUtilityTools(defineTool, toolDeps);\n const contactTools = createContactTools(defineTool, toolDeps);\n const agentTools = createAgentTools(defineTool, toolDeps);\n const integrationTools = createIntegrationTools(defineTool, toolDeps);\n const negotiationTools = deps.agentDispatcher\n ? createNegotiationTools(defineTool, toolDeps)\n : [];\n const premiseTools = createPremiseTools(defineTool, toolDeps);\n const questionerTools = createQuestionerTools(defineTool, toolDeps);\n // Blocking mid-conversation questions — chat-only (never in the MCP registry),\n // and only when the host provides the ChatQuestionsHost bridge.\n const askUserQuestionTools = deps.chatQuestions\n ? createAskUserQuestionTools(defineTool, toolDeps)\n : [];\n\n // confirm_opportunity_delivery is an OpenClaw-delivery ledger write and must not be\n // callable from regular chat sessions.\n const chatOpportunityToolExclusions = new Set([\n \"confirm_opportunity_delivery\",\n ]);\n const opportunityToolsForChat = opportunityTools.filter(\n (t) => !chatOpportunityToolExclusions.has((t as { name: string }).name)\n );\n\n return [\n ...profileTools,\n ...intentTools,\n ...networkTools,\n ...opportunityToolsForChat,\n ...utilityTools,\n ...integrationTools,\n ...contactTools,\n ...agentTools,\n ...negotiationTools,\n ...premiseTools,\n ...questionerTools,\n ...askUserQuestionTools,\n ];\n}\n\n/**\n * Type for the tools array returned by createChatTools.\n */\nexport type ChatTools = Awaited<ReturnType<typeof createChatTools>>;\n"]}
|
|
1
|
+
{"version":3,"file":"tool.factory.js","sourceRoot":"/","sources":["shared/agent/tool.factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAG7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCA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BAAgB;QACnB,GAAG,YAAY;QACf,GAAG,eAAe;QAClB,GAAG,oBAAoB;KACxB,CAAC;AACJ,CAAC","sourcesContent":["import { tool } from \"@langchain/core/tools\";\nimport { z } from \"zod\";\nimport type { HydeGraphDatabase } from \"../interfaces/database.interface.js\";\nimport { IntentGraphFactory } from \"../../intent/intent.graph.js\";\nimport { EnrichmentGraphFactory } from \"../../enrichment/enrichment.graph.js\";\nimport { OpportunityGraphFactory } from \"../../opportunity/opportunity.graph.js\";\nimport { HydeGraphFactory } from \"../hyde/hyde.graph.js\";\nimport { HydeGenerator } from \"../hyde/hyde.generator.js\";\nimport { LensInferrer } from \"../hyde/lens.inferrer.js\";\nimport { NetworkGraphFactory } from \"../../network/network.graph.js\";\nimport { NetworkMembershipGraphFactory } from \"../../network/membership/membership.graph.js\";\nimport { IntentNetworkGraphFactory } from \"../../network/indexer/indexer.graph.js\";\nimport { IntentIndexer } from \"../../intent/intent.indexer.js\";\nimport { NegotiationGraphFactory } from \"../../negotiation/negotiation.graph.js\";\nimport { PremiseGraphFactory } from \"../../premise/premise.graph.js\";\nimport { protocolLogger } from \"../observability/protocol.logger.js\";\n\nimport type { QuestionerEnqueueFn } from \"../../questioner/questioner.types.js\";\n\nimport { type ToolContext, type ResolvedToolContext, type ToolDeps, resolveChatContext, error, redactSensitiveFields } from \"./tool.helpers.js\";\nimport { deriveAllowedNetworkIds, scopeFromNetworkId } from \"./tool.scope.js\";\nimport { invokeToolRuntime, toolRuntimeErrorToResult } from \"./tool.runtime.js\";\nimport { createEnrichmentTools } from \"../../enrichment/enrichment.tools.js\";\nimport { createIntentTools } from \"../../intent/intent.tools.js\";\nimport { createNetworkTools } from \"../../network/network.tools.js\";\nimport { createOpportunityTools } from \"../../opportunity/opportunity.tools.js\";\nimport { createUtilityTools } from \"./utility.tools.js\";\nimport { createIntegrationTools } from \"../../integration/integration.tools.js\";\nimport { createContactTools } from \"../../contact/contact.tools.js\";\nimport { createAgentTools } from \"../../agent/agent.tools.js\";\nimport { createNegotiationTools } from \"../../negotiation/negotiation.tools.js\";\nimport { createPremiseTools } from \"../../premise/premise.tools.js\";\nimport { createQuestionerTools } from \"../../questioner/questioner.tools.js\";\nimport { createAskUserQuestionTools } from \"../../questioner/questioner.ask.tool.js\";\n\n// Re-export types for consumers\nexport type { ToolContext, ResolvedToolContext, ProtocolDeps } from \"./tool.helpers.js\";\nexport type { ToolDeps } from \"./tool.helpers.js\";\n\nconst logger = protocolLogger(\"ChatTools\");\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// TOOL FACTORY\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/**\n * Creates all chat tools bound to a specific user context.\n * Resolves user/network identity from DB at init time.\n * Tools are created fresh for each user session to ensure proper isolation.\n *\n * All external dependencies (cache, integration, queue, etc.) are provided\n * via the `deps` parameter — the protocol lib never imports concrete adapters.\n */\nexport async function createChatTools(\n deps: ToolContext,\n preResolvedContext?: ResolvedToolContext\n) {\n const { database, embedder, scraper } = deps;\n\n const explicitScope = deps.scopeType && deps.scopeId\n ? { scopeType: deps.scopeType, scopeId: deps.scopeId }\n : scopeFromNetworkId(deps.networkId);\n\n // ─── Resolve context from DB ───────────────────────────────────────────────\n // resolveChatContext still accepts a networkId because it loads scoped index\n // presentation metadata; the canonical request scope is explicitScope.\n const resolvedContext =\n preResolvedContext ??\n (await resolveChatContext({\n database,\n userId: deps.userId,\n networkId: explicitScope.scopeType === 'network' ? explicitScope.scopeId : deps.networkId,\n sessionId: deps.sessionId,\n contactsEnabled: deps.contactsEnabled,\n actionToolsEnabled: deps.actionToolsEnabled,\n }));\n\n if (!preResolvedContext && explicitScope.scopeType && explicitScope.scopeId) {\n resolvedContext.scopeType = explicitScope.scopeType;\n resolvedContext.scopeId = explicitScope.scopeId;\n }\n\n const allowedNetworkIds = deriveAllowedNetworkIds({\n memberships: resolvedContext.userNetworks,\n ...(resolvedContext.scopeType && resolvedContext.scopeId\n ? { scopeType: resolvedContext.scopeType, scopeId: resolvedContext.scopeId }\n : {}),\n });\n\n // ─── Tool wrapper ──────────────────────────────────────────────────────────\n /**\n * Standardized tool factory. Auto-injects resolved context and\n * provides uniform logging / error handling for every tool.\n */\n function defineTool<T extends z.ZodType>(opts: {\n name: string;\n description: string;\n querySchema: T;\n handler: (input: { context: ResolvedToolContext; query: z.infer<T> }) => Promise<string>;\n }) {\n return tool(\n async (query: z.infer<T>) => {\n logger.info('Tool invoked', {\n toolName: opts.name,\n context: { userId: resolvedContext.userId, scopeType: resolvedContext.scopeType, scopeId: resolvedContext.scopeId },\n query: redactSensitiveFields(query),\n });\n try {\n return await invokeToolRuntime({\n toolName: opts.name,\n tool: { handler: async ({ context, query }) => opts.handler({ context, query: query as z.infer<T> }) },\n context: resolvedContext,\n query,\n });\n } catch (err) {\n logger.error('Tool failed', {\n toolName: opts.name,\n error: err instanceof Error ? err.message : String(err),\n });\n const runtimeResult = toolRuntimeErrorToResult(err);\n if (runtimeResult) return runtimeResult;\n const reason = err instanceof Error ? err.message : String(err);\n return error(`Failed to execute ${opts.name}: ${reason}`);\n }\n },\n { name: opts.name, description: opts.description, schema: opts.querySchema }\n );\n }\n\n // ─── Compile subgraphs ─────────────────────────────────────────────────────\n\n // Wrap questionerEnqueue to include scoped/session context when available.\n const sessionAwareEnqueue: QuestionerEnqueueFn | undefined = deps.questionerEnqueue\n ? (input) => deps.questionerEnqueue!({\n ...input,\n ...(resolvedContext.scopeType && resolvedContext.scopeId && !input.scopeId\n ? { scopeType: resolvedContext.scopeType, scopeId: resolvedContext.scopeId }\n : {}),\n ...(resolvedContext.sessionId && !input.conversationId ? { conversationId: resolvedContext.sessionId } : {}),\n })\n : undefined;\n\n const intentGraph = new IntentGraphFactory(database, embedder, deps.intentQueue, sessionAwareEnqueue).createGraph();\n const premiseGraph = new PremiseGraphFactory(database, embedder).createGraph();\n const profileGraph = new EnrichmentGraphFactory(database, scraper, deps.enricher, sessionAwareEnqueue, premiseGraph).createGraph();\n const hydeCache = deps.hydeCache;\n const lensInferrer = new LensInferrer();\n const hydeGenerator = new HydeGenerator();\n const compiledHydeGraph = new HydeGraphFactory(\n database as unknown as HydeGraphDatabase,\n embedder,\n hydeCache,\n lensInferrer,\n hydeGenerator\n ).createGraph();\n const negotiationGraph = deps.agentDispatcher\n ? new NegotiationGraphFactory(\n deps.negotiationDatabase,\n deps.agentDispatcher,\n deps.negotiationTimeoutQueue,\n sessionAwareEnqueue,\n ).createGraph()\n : undefined;\n const opportunityGraph = new OpportunityGraphFactory(\n database,\n embedder,\n compiledHydeGraph,\n undefined, // evaluator (default)\n undefined, // queueNotification\n negotiationGraph,\n deps.agentDispatcher,\n deps.queueNegotiateExisting,\n deps.stampNewbornOpportunities,\n ).createGraph();\n const networkGraph = new NetworkGraphFactory(database).createGraph();\n const networkMembershipGraph = new NetworkMembershipGraphFactory(database).createGraph();\n const intentNetworkGraph = new IntentNetworkGraphFactory(database, new IntentIndexer()).createGraph();\n\n // ─── Create context-bound databases ────────────────────────────────────────\n // Use injected instances when provided (e.g. tests). Otherwise create from the same\n // database used for graphs so that scope checks (e.g. ensureScopedMembership, opportunity\n // update) use the same adapter as the rest of the tool pipeline.\n //\n // The systemDb's DB-level clamp derives concrete allowed network IDs from the\n // focused scope envelope plus memberships, rather than consuming a transported\n // legacy indexScope array.\n const userDb = deps.userDb ?? deps.createUserDatabase(database, resolvedContext.userId);\n const systemDb = deps.systemDb ?? deps.createSystemDatabase(database, resolvedContext.userId, allowedNetworkIds, embedder);\n\n // ─── Assemble dependencies ─────────────────────────────────────────────────\n const cache = deps.cache;\n const integration = deps.integration;\n const toolDeps: ToolDeps = {\n database,\n userDb,\n systemDb,\n scraper,\n embedder,\n cache,\n integration,\n contactService: deps.contactService,\n contactsEnabled: deps.contactsEnabled,\n integrationImporter: deps.integrationImporter,\n enricher: deps.enricher,\n negotiationDatabase: deps.negotiationDatabase,\n negotiationTimeoutQueue: deps.negotiationTimeoutQueue,\n agentDatabase: deps.agentDatabase,\n grantDefaultSystemPermissions: deps.grantDefaultSystemPermissions,\n agentDispatcher: deps.agentDispatcher,\n stampNewbornOpportunities: deps.stampNewbornOpportunities,\n deliveryLedger: deps.deliveryLedger,\n discoveryRuns: deps.discoveryRuns,\n discoveryRunQueue: deps.discoveryRunQueue,\n enrichmentRuns: deps.enrichmentRuns,\n enrichmentRunQueue: deps.enrichmentRunQueue,\n mintConnectToken: deps.mintConnectToken,\n mintConnectLink: deps.mintConnectLink,\n frontendUrl: deps.frontendUrl,\n apiBaseUrl: deps.apiBaseUrl,\n ...(deps.chatSummary && { chatSummary: deps.chatSummary }),\n ...(deps.questionGenerator && { questionGenerator: deps.questionGenerator }),\n ...(sessionAwareEnqueue && { questionerEnqueue: sessionAwareEnqueue }),\n ...(deps.findPendingQuestions && { findPendingQuestions: deps.findPendingQuestions }),\n ...(deps.answerPendingQuestion && { answerPendingQuestion: deps.answerPendingQuestion }),\n ...(deps.negotiationSummary && { negotiationSummary: deps.negotiationSummary }),\n ...(deps.chatQuestions && { chatQuestions: deps.chatQuestions }),\n ...(deps.chatSession && { chatSession: deps.chatSession }),\n ...(deps.getUserContextText && { getUserContextText: deps.getUserContextText }),\n graphs: {\n profile: profileGraph,\n intent: intentGraph,\n index: networkGraph,\n networkMembership: networkMembershipGraph,\n intentIndex: intentNetworkGraph,\n opportunity: opportunityGraph,\n premise: premiseGraph,\n },\n };\n\n // ─── Create domain tools ──────────────────────────────────────────────────\n const profileTools = createEnrichmentTools(defineTool, toolDeps);\n const intentTools = createIntentTools(defineTool, toolDeps);\n const networkTools = createNetworkTools(defineTool, toolDeps);\n const opportunityTools = createOpportunityTools(defineTool, toolDeps);\n const utilityTools = createUtilityTools(defineTool, toolDeps);\n const contactTools = createContactTools(defineTool, toolDeps);\n const agentTools = createAgentTools(defineTool, toolDeps);\n const integrationTools = createIntegrationTools(defineTool, toolDeps);\n const negotiationTools = deps.agentDispatcher\n ? createNegotiationTools(defineTool, toolDeps)\n : [];\n const premiseTools = createPremiseTools(defineTool, toolDeps);\n const questionerTools = createQuestionerTools(defineTool, toolDeps);\n // Blocking mid-conversation questions — chat-only (never in the MCP registry),\n // and only when the host provides the ChatQuestionsHost bridge.\n const askUserQuestionTools = deps.chatQuestions\n ? createAskUserQuestionTools(defineTool, toolDeps)\n : [];\n\n // confirm_opportunity_delivery is an OpenClaw-delivery ledger write and must not be\n // callable from regular chat sessions.\n const chatOpportunityToolExclusions = new Set([\n \"confirm_opportunity_delivery\",\n ]);\n const opportunityToolsForChat = opportunityTools.filter(\n (t) => !chatOpportunityToolExclusions.has((t as { name: string }).name)\n );\n\n return [\n ...profileTools,\n ...intentTools,\n ...networkTools,\n ...opportunityToolsForChat,\n ...utilityTools,\n ...integrationTools,\n ...contactTools,\n ...agentTools,\n ...negotiationTools,\n ...premiseTools,\n ...questionerTools,\n ...askUserQuestionTools,\n ];\n}\n\n/**\n * Type for the tools array returned by createChatTools.\n */\nexport type ChatTools = Awaited<ReturnType<typeof createChatTools>>;\n"]}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { NegotiationTurn, UserNegotiationContext, SeedAssessment } from '../schemas/negotiation-state.schema.js';
|
|
9
9
|
import type { NegotiatorMemoryEntry } from '../../negotiation/negotiation.memory.js';
|
|
10
|
+
import type { NegotiationPrivateConsultation } from './database.interface.js';
|
|
10
11
|
/** Payload sent to the dispatcher for each negotiation turn. */
|
|
11
12
|
export interface NegotiationTurnPayload {
|
|
12
13
|
negotiationId: string;
|
|
@@ -36,6 +37,8 @@ export interface NegotiationTurnPayload {
|
|
|
36
37
|
* retrieved.
|
|
37
38
|
*/
|
|
38
39
|
negotiatorMemory?: NegotiatorMemoryEntry[];
|
|
40
|
+
/** Recipient-private ask-user consultation, present only for that recipient's turn. */
|
|
41
|
+
privateConsultation?: NegotiationPrivateConsultation;
|
|
39
42
|
}
|
|
40
43
|
/** Result of a dispatch attempt. */
|
|
41
44
|
export type AgentDispatchResult = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-dispatcher.interface.d.ts","sourceRoot":"/","sources":["shared/interfaces/agent-dispatcher.interface.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AACtH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"agent-dispatcher.interface.d.ts","sourceRoot":"/","sources":["shared/interfaces/agent-dispatcher.interface.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AACtH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yCAAyC,CAAC;AACrF,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,yBAAyB,CAAC;AAE9E,gEAAgE;AAChE,MAAM,WAAW,sBAAsB;IACrC,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,sBAAsB,CAAC;IAChC,SAAS,EAAE,sBAAsB,CAAC;IAClC,YAAY,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACrD,cAAc,EAAE,cAAc,CAAC;IAC/B,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,WAAW,EAAE,OAAO,CAAC;IACrB,iEAAiE;IACjE,YAAY,EAAE,OAAO,CAAC;IACtB,gHAAgH;IAChH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,mGAAmG;IACnG,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,4FAA4F;IAC5F,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,qBAAqB,EAAE,CAAC;IAC3C,uFAAuF;IACvF,mBAAmB,CAAC,EAAE,8BAA8B,CAAC;CACtD;AAED,oCAAoC;AACpC,MAAM,MAAM,mBAAmB,GAC3B;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,eAAe,CAAA;CAAE,GACxC;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,UAAU,GAAG,SAAS,CAAA;CAAE,GAClD;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,SAAS,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/D;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;;;OAOG;IACH,QAAQ,CACN,MAAM,EAAE,MAAM,EACd,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,EAC9D,OAAO,EAAE,sBAAsB,EAC/B,OAAO,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,GAC7B,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAEhC;;;;OAIG;IACH,gBAAgB,CACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAC7D,OAAO,CAAC,OAAO,CAAC,CAAC;CACrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-dispatcher.interface.js","sourceRoot":"/","sources":["shared/interfaces/agent-dispatcher.interface.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG","sourcesContent":["/**\n * AgentDispatcher interface for the negotiation graph.\n *\n * The graph calls dispatch() per turn and receives a result.\n * It never knows about webhooks, MCP, transports, or agent resolution.\n * The concrete implementation lives in the host application.\n */\n\nimport type { NegotiationTurn, UserNegotiationContext, SeedAssessment } from '../schemas/negotiation-state.schema.js';\nimport type { NegotiatorMemoryEntry } from '../../negotiation/negotiation.memory.js';\n\n/** Payload sent to the dispatcher for each negotiation turn. */\nexport interface NegotiationTurnPayload {\n negotiationId: string;\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. */\n isDiscoverer: boolean;\n /** The explicit search query that triggered this discovery (if any). Takes priority over background intents. */\n discoveryQuery?: string;\n /** The acting user's seat under the v2 client-advocate protocol (`initiator` | `counterparty`). */\n seat?: string;\n /** Negotiation protocol version for this task (`v1` | `v2`). */\n protocolVersion?: string;\n /** Actions the acting seat may submit on this turn (seat + version + final-turn scoped). */\n allowedActions?: string[];\n /**\n * The acting user's OWN negotiator memories (P5.3 read path) — private\n * context for the dispatched agent. Never contains the counterparty's\n * memory; absent when `NEGOTIATOR_MEMORY_INJECT` is off or nothing was\n * retrieved.\n */\n negotiatorMemory?: NegotiatorMemoryEntry[];\n}\n\n/** Result of a dispatch attempt. */\nexport type AgentDispatchResult =\n | { handled: true; turn: NegotiationTurn }\n | { handled: false; reason: 'no_agent' | 'timeout' }\n | { handled: false; reason: 'waiting'; resumeToken: string };\n\n/**\n * Dispatches a negotiation turn to the appropriate agent.\n * Tries external (poller) agents first, falls back to system agent.\n */\nexport interface AgentDispatcher {\n /**\n * Attempt to dispatch a negotiation turn to an external (poller) agent.\n * @param userId - The user whose agent should handle this turn\n * @param scope - Permission scope for agent resolution\n * @param payload - Turn context (users, history, seed assessment)\n * @param options - Timeout configuration\n * @returns Handled result with turn, or unhandled result with reason\n */\n dispatch(\n userId: string,\n scope: { action: string; scopeType: string; scopeId?: string },\n payload: NegotiationTurnPayload,\n options: { timeoutMs: number },\n ): Promise<AgentDispatchResult>;\n\n /**\n * Check whether a user has an authorized external (poller) agent for the given\n * scope. Used at init to determine scenario-based turn caps. Type-only by design\n * (no heartbeat freshness) — see IND-410.\n */\n hasExternalAgent(\n userId: string,\n scope: { action: string; scopeType: string; scopeId?: string },\n ): Promise<boolean>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"agent-dispatcher.interface.js","sourceRoot":"/","sources":["shared/interfaces/agent-dispatcher.interface.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG","sourcesContent":["/**\n * AgentDispatcher interface for the negotiation graph.\n *\n * The graph calls dispatch() per turn and receives a result.\n * It never knows about webhooks, MCP, transports, or agent resolution.\n * The concrete implementation lives in the host application.\n */\n\nimport type { NegotiationTurn, UserNegotiationContext, SeedAssessment } from '../schemas/negotiation-state.schema.js';\nimport type { NegotiatorMemoryEntry } from '../../negotiation/negotiation.memory.js';\nimport type { NegotiationPrivateConsultation } from './database.interface.js';\n\n/** Payload sent to the dispatcher for each negotiation turn. */\nexport interface NegotiationTurnPayload {\n negotiationId: string;\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. */\n isDiscoverer: boolean;\n /** The explicit search query that triggered this discovery (if any). Takes priority over background intents. */\n discoveryQuery?: string;\n /** The acting user's seat under the v2 client-advocate protocol (`initiator` | `counterparty`). */\n seat?: string;\n /** Negotiation protocol version for this task (`v1` | `v2`). */\n protocolVersion?: string;\n /** Actions the acting seat may submit on this turn (seat + version + final-turn scoped). */\n allowedActions?: string[];\n /**\n * The acting user's OWN negotiator memories (P5.3 read path) — private\n * context for the dispatched agent. Never contains the counterparty's\n * memory; absent when `NEGOTIATOR_MEMORY_INJECT` is off or nothing was\n * retrieved.\n */\n negotiatorMemory?: NegotiatorMemoryEntry[];\n /** Recipient-private ask-user consultation, present only for that recipient's turn. */\n privateConsultation?: NegotiationPrivateConsultation;\n}\n\n/** Result of a dispatch attempt. */\nexport type AgentDispatchResult =\n | { handled: true; turn: NegotiationTurn }\n | { handled: false; reason: 'no_agent' | 'timeout' }\n | { handled: false; reason: 'waiting'; resumeToken: string };\n\n/**\n * Dispatches a negotiation turn to the appropriate agent.\n * Tries external (poller) agents first, falls back to system agent.\n */\nexport interface AgentDispatcher {\n /**\n * Attempt to dispatch a negotiation turn to an external (poller) agent.\n * @param userId - The user whose agent should handle this turn\n * @param scope - Permission scope for agent resolution\n * @param payload - Turn context (users, history, seed assessment)\n * @param options - Timeout configuration\n * @returns Handled result with turn, or unhandled result with reason\n */\n dispatch(\n userId: string,\n scope: { action: string; scopeType: string; scopeId?: string },\n payload: NegotiationTurnPayload,\n options: { timeoutMs: number },\n ): Promise<AgentDispatchResult>;\n\n /**\n * Check whether a user has an authorized external (poller) agent for the given\n * scope. Used at init to determine scenario-based turn caps. Type-only by design\n * (no heartbeat freshness) — see IND-410.\n */\n hasExternalAgent(\n userId: string,\n scope: { action: string; scopeType: string; scopeId?: string },\n ): Promise<boolean>;\n}\n"]}
|
|
@@ -1900,14 +1900,70 @@ export type OpportunityGraphDatabase = Pick<Database, 'getProfile' | 'createOppo
|
|
|
1900
1900
|
* Negotiation-specific query operations not covered by generic
|
|
1901
1901
|
* conversation/task primitives.
|
|
1902
1902
|
*/
|
|
1903
|
-
/** A user's
|
|
1903
|
+
/** A user's ordinary follow-up answer stored on established shared opportunity metadata. */
|
|
1904
1904
|
export interface NegotiationUserAnswer {
|
|
1905
1905
|
questionId: string;
|
|
1906
1906
|
selectedOptions: string[];
|
|
1907
1907
|
freeText?: string;
|
|
1908
1908
|
answeredAt: string;
|
|
1909
1909
|
}
|
|
1910
|
+
export interface NegotiationPrivateConsultation {
|
|
1911
|
+
recipientUserId: string;
|
|
1912
|
+
recipientIntentId: string;
|
|
1913
|
+
kind: 'answer' | 'dismiss' | 'timeout';
|
|
1914
|
+
selectedOptions: string[];
|
|
1915
|
+
freeText?: string;
|
|
1916
|
+
}
|
|
1917
|
+
export interface NegotiationContinuationExecution {
|
|
1918
|
+
taskId: string;
|
|
1919
|
+
settlementId: string;
|
|
1920
|
+
opportunityId: string;
|
|
1921
|
+
userId: string;
|
|
1922
|
+
recipientIntentId: string;
|
|
1923
|
+
networkId: string;
|
|
1924
|
+
intentFingerprint: string;
|
|
1925
|
+
opportunityStatus: string;
|
|
1926
|
+
opportunityUpdatedAt: string;
|
|
1927
|
+
counterpartyUserId: string;
|
|
1928
|
+
counterpartyIntentId: string;
|
|
1929
|
+
successorTaskId: string;
|
|
1930
|
+
conversationId: string;
|
|
1931
|
+
token: string;
|
|
1932
|
+
fence: number;
|
|
1933
|
+
leaseExpiresAt: string;
|
|
1934
|
+
consultation: NegotiationPrivateConsultation;
|
|
1935
|
+
}
|
|
1936
|
+
export interface NegotiationContinuationReceipt {
|
|
1937
|
+
priorTaskId: string;
|
|
1938
|
+
settlementId: string;
|
|
1939
|
+
successorTaskId: string;
|
|
1940
|
+
fence: number;
|
|
1941
|
+
outcome: 'accepted' | 'rejected' | 'stalled' | 'waiting_for_agent' | 'input_required';
|
|
1942
|
+
}
|
|
1910
1943
|
export interface NegotiationQueries {
|
|
1944
|
+
/** Capture canonical material binding before arming an ask-user timeout. */
|
|
1945
|
+
captureNegotiationAskUserBinding(input: {
|
|
1946
|
+
taskId: string;
|
|
1947
|
+
turnContext: Record<string, unknown>;
|
|
1948
|
+
settlementId: string;
|
|
1949
|
+
recipientUserId: string;
|
|
1950
|
+
recipientIntentId: string;
|
|
1951
|
+
opportunityId: string;
|
|
1952
|
+
networkId: string;
|
|
1953
|
+
continuationExecution?: NegotiationContinuationExecution;
|
|
1954
|
+
}): Promise<{
|
|
1955
|
+
version: 2;
|
|
1956
|
+
settlementId: string;
|
|
1957
|
+
recipientUserId: string;
|
|
1958
|
+
recipientIntentId: string;
|
|
1959
|
+
opportunityId: string;
|
|
1960
|
+
networkId: string;
|
|
1961
|
+
intentFingerprint: string;
|
|
1962
|
+
opportunityStatus: string;
|
|
1963
|
+
opportunityUpdatedAt: string;
|
|
1964
|
+
counterpartyUserId: string;
|
|
1965
|
+
counterpartyIntentId: string;
|
|
1966
|
+
}>;
|
|
1911
1967
|
/**
|
|
1912
1968
|
* Persists the full negotiation turn context (source/candidate user contexts,
|
|
1913
1969
|
* seed assessment, index context, discovery query) onto the task metadata so
|
|
@@ -1916,7 +1972,7 @@ export interface NegotiationQueries {
|
|
|
1916
1972
|
* @param taskId - Task whose metadata to enrich
|
|
1917
1973
|
* @param turnContext - Absolute (source/candidate) view of the negotiation context
|
|
1918
1974
|
*/
|
|
1919
|
-
setTaskTurnContext(taskId: string, turnContext: Record<string, unknown
|
|
1975
|
+
setTaskTurnContext(taskId: string, turnContext: Record<string, unknown>, continuationExecution?: NegotiationContinuationExecution): Promise<void>;
|
|
1920
1976
|
/**
|
|
1921
1977
|
* Merges a screen-gate decision (P2.1 shadow mode) into
|
|
1922
1978
|
* `metadata.screenDecision`, leaving other metadata keys intact. Optional so
|
|
@@ -1925,7 +1981,7 @@ export interface NegotiationQueries {
|
|
|
1925
1981
|
* @param taskId - Task whose metadata to enrich
|
|
1926
1982
|
* @param screenDecision - ScreenDecisionRecord (decision, evidence, mode, timing)
|
|
1927
1983
|
*/
|
|
1928
|
-
setTaskScreenDecision?(taskId: string, screenDecision: Record<string, unknown
|
|
1984
|
+
setTaskScreenDecision?(taskId: string, screenDecision: Record<string, unknown>, continuationExecution?: NegotiationContinuationExecution): Promise<void>;
|
|
1929
1985
|
/**
|
|
1930
1986
|
* Merges an applied deadlock→bargaining shift record (IND-428) into
|
|
1931
1987
|
* `metadata.deadlockShift`, leaving other metadata keys intact. Internal
|
|
@@ -1935,7 +1991,7 @@ export interface NegotiationQueries {
|
|
|
1935
1991
|
* @param taskId - Task whose metadata to enrich
|
|
1936
1992
|
* @param deadlockShift - DeadlockShiftRecord (run length, threshold, turn, seat, timing)
|
|
1937
1993
|
*/
|
|
1938
|
-
setTaskDeadlockShift?(taskId: string, deadlockShift: Record<string, unknown
|
|
1994
|
+
setTaskDeadlockShift?(taskId: string, deadlockShift: Record<string, unknown>, continuationExecution?: NegotiationContinuationExecution): Promise<void>;
|
|
1939
1995
|
/**
|
|
1940
1996
|
* Returns the most-recently-created task whose metadata carries
|
|
1941
1997
|
* `type: 'negotiation'` and `opportunityId: <id>`. Returns null if no
|
|
@@ -1986,7 +2042,7 @@ export type NegotiationGraphDatabase = Pick<Database, 'getOrCreateDM' | 'getUser
|
|
|
1986
2042
|
* advance the opportunity lifecycle (negotiating -> pending/rejected/stalled).
|
|
1987
2043
|
* Returns only the narrow { id, status } needed by the graph, not the full Opportunity.
|
|
1988
2044
|
*/
|
|
1989
|
-
updateOpportunityStatus(id: string, status: OpportunityStatus): Promise<{
|
|
2045
|
+
updateOpportunityStatus(id: string, status: OpportunityStatus, acceptedBy?: string, continuationExecution?: NegotiationContinuationExecution): Promise<{
|
|
1990
2046
|
id: string;
|
|
1991
2047
|
status: OpportunityStatus;
|
|
1992
2048
|
} | null>;
|
|
@@ -1998,6 +2054,7 @@ export type NegotiationGraphDatabase = Pick<Database, 'getOrCreateDM' | 'getUser
|
|
|
1998
2054
|
parts: unknown[];
|
|
1999
2055
|
taskId?: string;
|
|
2000
2056
|
metadata?: Record<string, unknown> | null;
|
|
2057
|
+
continuationExecution?: NegotiationContinuationExecution;
|
|
2001
2058
|
}): Promise<{
|
|
2002
2059
|
id: string;
|
|
2003
2060
|
senderId: string;
|
|
@@ -2027,8 +2084,25 @@ export type NegotiationGraphDatabase = Pick<Database, 'getOrCreateDM' | 'getUser
|
|
|
2027
2084
|
conversationId: string;
|
|
2028
2085
|
state: string;
|
|
2029
2086
|
}>;
|
|
2087
|
+
/**
|
|
2088
|
+
* Under a deterministic settlement lock, validate the exact canceled ask_user
|
|
2089
|
+
* task and return its existing successor or create one. Never consults a
|
|
2090
|
+
* latest-task lookup.
|
|
2091
|
+
*/
|
|
2092
|
+
getOrCreateNegotiationContinuationTask(input: {
|
|
2093
|
+
priorTaskId: string;
|
|
2094
|
+
settlementId: string;
|
|
2095
|
+
conversationId: string;
|
|
2096
|
+
opportunityId: string;
|
|
2097
|
+
metadata: Record<string, unknown>;
|
|
2098
|
+
}): Promise<{
|
|
2099
|
+
id: string;
|
|
2100
|
+
conversationId: string;
|
|
2101
|
+
state: string;
|
|
2102
|
+
created: boolean;
|
|
2103
|
+
} | null>;
|
|
2030
2104
|
/** Transitions a task to a new state (e.g. working, completed, failed). */
|
|
2031
|
-
updateTaskState(taskId: string, state: string, statusMessage?: unknown): Promise<{
|
|
2105
|
+
updateTaskState(taskId: string, state: string, statusMessage?: unknown, continuationExecution?: NegotiationContinuationExecution): Promise<{
|
|
2032
2106
|
id: string;
|
|
2033
2107
|
conversationId: string;
|
|
2034
2108
|
state: string;
|
|
@@ -2039,6 +2113,7 @@ export type NegotiationGraphDatabase = Pick<Database, 'getOrCreateDM' | 'getUser
|
|
|
2039
2113
|
name?: string;
|
|
2040
2114
|
parts: unknown[];
|
|
2041
2115
|
metadata?: Record<string, unknown> | null;
|
|
2116
|
+
continuationExecution?: NegotiationContinuationExecution;
|
|
2042
2117
|
}): Promise<{
|
|
2043
2118
|
id: string;
|
|
2044
2119
|
}>;
|