@indexnetwork/protocol 6.6.0-rc.386.1 → 6.6.2-rc.388.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/chat/chat.agent.d.ts +6 -0
- package/dist/chat/chat.agent.d.ts.map +1 -1
- package/dist/chat/chat.agent.js +119 -0
- package/dist/chat/chat.agent.js.map +1 -1
- package/dist/chat/chat.persona.d.ts +5 -0
- package/dist/chat/chat.persona.d.ts.map +1 -1
- package/dist/chat/chat.persona.js.map +1 -1
- package/dist/chat/chat.prompt.modules.d.ts +2 -0
- package/dist/chat/chat.prompt.modules.d.ts.map +1 -1
- package/dist/chat/chat.prompt.modules.js.map +1 -1
- package/dist/chat/reporter.persona.d.ts.map +1 -1
- package/dist/chat/reporter.persona.js +2 -1
- package/dist/chat/reporter.persona.js.map +1 -1
- package/dist/chat/reporter.prompt.d.ts +4 -0
- package/dist/chat/reporter.prompt.d.ts.map +1 -1
- package/dist/chat/reporter.prompt.js +39 -5
- package/dist/chat/reporter.prompt.js.map +1 -1
- package/dist/opportunity/discriminator/discriminator.adjustments.js +1 -1
- package/dist/opportunity/discriminator/discriminator.adjustments.js.map +1 -1
- package/dist/opportunity/opportunity.safe-presentation.d.ts +1 -1
- package/dist/opportunity/opportunity.safe-presentation.js +1 -1
- package/dist/opportunity/opportunity.safe-presentation.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -13,6 +13,7 @@ See [STABILITY.md](./STABILITY.md) for the public-contract and tier definitions.
|
|
|
13
13
|
## [Unreleased]
|
|
14
14
|
|
|
15
15
|
### Added
|
|
16
|
+
- Harden reporter turn handling so only the exact kickoff produces the detailed briefing, focused follow-ups stay narrow, and one-turn-local contextual natural-language confirmation deterministically bypasses the model and tools in favor of the visible confirmation card (IND-493).
|
|
16
17
|
- Dark-gated reporter cleanup-action proposals for retracting owner premises, narrowing owned signals, and pausing owned signals (IND-490 PR1). `propose_cleanup_actions` is conditionally registered only when `WEB_AGENT_ACTIONS_ENABLED` is enabled alongside the reporter surface; it validates full owner UUIDs, requires pause evidence, persists a confirmation request, and never mutates data in chat.
|
|
17
18
|
- Read-only `reporter` chat persona for Agent-surface activity reporting (IND-476 PR1), with an exact positive allowlist, self-only narrowing, aggregate-only opportunity reporting, grounded `report_agent_activity` metrics, and a public briefing kickoff marker. Mutation, discovery, negotiation, memory, question-answering, scraping, and counterparty identity surfaces remain unavailable.
|
|
18
19
|
- Restricted `signal` chat persona for the main-web cutover (IND-449), built on the existing persona-neutral runtime with a custom signals/profile prompt, an exact positive allowlist, proposal hallucination recovery, and the discovery-coupled create-intent callback disabled. Signal-specific wrappers clamp focused intent/network reads to owned active intents and current memberships, prohibit other-user membership enumeration, and validate live membership before forwarding network-scoped proposals. Shared orchestrator, MCP, and direct-tool registries are unchanged.
|
|
@@ -235,6 +235,12 @@ export declare class ChatAgent {
|
|
|
235
235
|
* Extracts the text content of the most recent HumanMessage.
|
|
236
236
|
*/
|
|
237
237
|
private static getCurrentUserMessage;
|
|
238
|
+
/**
|
|
239
|
+
* Detects a prior visible action proposal without considering current-turn
|
|
240
|
+
* tool calls. The reporter uses this only to make typed confirmation
|
|
241
|
+
* language contextual rather than executable on its own.
|
|
242
|
+
*/
|
|
243
|
+
static hasPriorAgentActionProposal(messages: BaseMessage[]): boolean;
|
|
238
244
|
/**
|
|
239
245
|
* Async factory: creates a ChatAgent with resolved user/index context.
|
|
240
246
|
* Resolves user/network identity from DB during tool initialization.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.agent.d.ts","sourceRoot":"/","sources":["chat/chat.agent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,WAAW,EAA8C,MAAM,0BAA0B,CAAC;AAC9G,OAAO,KAAK,EAAa,WAAW,EAAuB,MAAM,iCAAiC,CAAC;AAInG,OAAO,EAAwB,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAMj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AAE,YAAY,CAAC;YAAC,wBAAwB,CAAC,EAAE,iCAAiC,CAAC;YAAC,kBAAkB,CAAC,EAAE,2BAA2B,CAAA;SAAE,CAAC;KACjN,CAAC;CA6lBH"}
|
package/dist/chat/chat.agent.js
CHANGED
|
@@ -20,6 +20,55 @@ import { sanitizeForDebugMeta } from "../shared/observability/debug-meta.sanitiz
|
|
|
20
20
|
import { Timed } from "../shared/observability/performance.js";
|
|
21
21
|
import { requestContext } from "../shared/observability/request-context.js";
|
|
22
22
|
import { deduplicateQuestions } from "./chat.question-dedup.js";
|
|
23
|
+
const AGENT_ACTION_PROPOSAL_FENCE_PATTERN = /```agent_action_proposal\s*\n([\s\S]*?)\n```/g;
|
|
24
|
+
const AGENT_ACTION_PROPOSAL_KEYS = new Set(["proposalId", "actions"]);
|
|
25
|
+
const AGENT_ACTION_KEYS = new Set([
|
|
26
|
+
"type",
|
|
27
|
+
"entityId",
|
|
28
|
+
"currentState",
|
|
29
|
+
"proposedOperation",
|
|
30
|
+
"skipped",
|
|
31
|
+
"reason",
|
|
32
|
+
"description",
|
|
33
|
+
"evidence",
|
|
34
|
+
]);
|
|
35
|
+
const AGENT_ACTION_OPERATIONS = {
|
|
36
|
+
retract_premise: "RETRACT_PREMISE",
|
|
37
|
+
narrow_signal: "NARROW_SIGNAL",
|
|
38
|
+
pause_signal: "PAUSE_SIGNAL",
|
|
39
|
+
};
|
|
40
|
+
function isVisibleAgentActionProposal(payload) {
|
|
41
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
42
|
+
return false;
|
|
43
|
+
const proposal = payload;
|
|
44
|
+
if (Object.keys(proposal).some((key) => !AGENT_ACTION_PROPOSAL_KEYS.has(key)))
|
|
45
|
+
return false;
|
|
46
|
+
if (typeof proposal.proposalId !== "string"
|
|
47
|
+
|| !/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(proposal.proposalId)
|
|
48
|
+
|| !Array.isArray(proposal.actions)
|
|
49
|
+
|| proposal.actions.length < 1
|
|
50
|
+
|| proposal.actions.length > 5)
|
|
51
|
+
return false;
|
|
52
|
+
return proposal.actions.every((rawAction) => {
|
|
53
|
+
if (!rawAction || typeof rawAction !== "object" || Array.isArray(rawAction))
|
|
54
|
+
return false;
|
|
55
|
+
const action = rawAction;
|
|
56
|
+
if (Object.keys(action).some((key) => !AGENT_ACTION_KEYS.has(key)))
|
|
57
|
+
return false;
|
|
58
|
+
if (typeof action.type !== "string" || !(action.type in AGENT_ACTION_OPERATIONS))
|
|
59
|
+
return false;
|
|
60
|
+
const type = action.type;
|
|
61
|
+
if (action.proposedOperation !== AGENT_ACTION_OPERATIONS[type])
|
|
62
|
+
return false;
|
|
63
|
+
if (typeof action.entityId !== "string" || !action.entityId.trim())
|
|
64
|
+
return false;
|
|
65
|
+
if (typeof action.currentState !== "string" || !action.currentState.trim())
|
|
66
|
+
return false;
|
|
67
|
+
if (action.skipped !== undefined && typeof action.skipped !== "boolean")
|
|
68
|
+
return false;
|
|
69
|
+
return ["reason", "description", "evidence"].every((key) => action[key] === undefined || typeof action[key] === "string");
|
|
70
|
+
});
|
|
71
|
+
}
|
|
23
72
|
const logger = protocolLogger("ChatAgent");
|
|
24
73
|
// Re-export for external consumers
|
|
25
74
|
export { ITERATION_NUDGE } from "./chat.prompt.js";
|
|
@@ -95,6 +144,48 @@ export class ChatAgent {
|
|
|
95
144
|
}
|
|
96
145
|
return undefined;
|
|
97
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Detects a prior visible action proposal without considering current-turn
|
|
149
|
+
* tool calls. The reporter uses this only to make typed confirmation
|
|
150
|
+
* language contextual rather than executable on its own.
|
|
151
|
+
*/
|
|
152
|
+
static hasPriorAgentActionProposal(messages) {
|
|
153
|
+
let currentHumanIndex = -1;
|
|
154
|
+
let previousHumanIndex = -1;
|
|
155
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
156
|
+
if (messages[index]._getType() !== "human")
|
|
157
|
+
continue;
|
|
158
|
+
if (currentHumanIndex < 0) {
|
|
159
|
+
currentHumanIndex = index;
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
previousHumanIndex = index;
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (currentHumanIndex < 0 || previousHumanIndex < 0)
|
|
167
|
+
return false;
|
|
168
|
+
let latestAssistant;
|
|
169
|
+
for (let index = currentHumanIndex - 1; index > previousHumanIndex; index -= 1) {
|
|
170
|
+
if (messages[index]._getType() === "ai") {
|
|
171
|
+
latestAssistant = messages[index];
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (!latestAssistant || typeof latestAssistant.content !== "string")
|
|
176
|
+
return false;
|
|
177
|
+
AGENT_ACTION_PROPOSAL_FENCE_PATTERN.lastIndex = 0;
|
|
178
|
+
for (const match of latestAssistant.content.matchAll(AGENT_ACTION_PROPOSAL_FENCE_PATTERN)) {
|
|
179
|
+
try {
|
|
180
|
+
if (isVisibleAgentActionProposal(JSON.parse(match[1])))
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
// An invalid prior fence is not visible proposal context.
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
98
189
|
/**
|
|
99
190
|
* Async factory: creates a ChatAgent with resolved user/index context.
|
|
100
191
|
* Resolves user/network identity from DB during tool initialization.
|
|
@@ -135,8 +226,18 @@ export class ChatAgent {
|
|
|
135
226
|
const iterCtx = {
|
|
136
227
|
recentTools: extractRecentToolCalls(messages),
|
|
137
228
|
currentMessage: ChatAgent.getCurrentUserMessage(messages),
|
|
229
|
+
hasPriorAgentActionProposal: ChatAgent.hasPriorAgentActionProposal(messages),
|
|
138
230
|
ctx: this.resolvedContext,
|
|
139
231
|
};
|
|
232
|
+
const deterministicResponse = this.persona.resolveDeterministicResponse?.(this.resolvedContext, iterCtx);
|
|
233
|
+
if (deterministicResponse !== undefined && deterministicResponse !== null) {
|
|
234
|
+
const response = new AIMessage(deterministicResponse);
|
|
235
|
+
return {
|
|
236
|
+
shouldContinue: false,
|
|
237
|
+
responseText: deterministicResponse,
|
|
238
|
+
messages: [...messages, response],
|
|
239
|
+
};
|
|
240
|
+
}
|
|
140
241
|
const systemContent = this.persona.buildSystemContent(this.resolvedContext, iterCtx);
|
|
141
242
|
const fullMessages = [
|
|
142
243
|
new SystemMessage(systemContent),
|
|
@@ -579,8 +680,26 @@ export class ChatAgent {
|
|
|
579
680
|
const iterCtx = {
|
|
580
681
|
recentTools: extractRecentToolCalls(messages),
|
|
581
682
|
currentMessage: ChatAgent.getCurrentUserMessage(messages),
|
|
683
|
+
hasPriorAgentActionProposal: ChatAgent.hasPriorAgentActionProposal(messages),
|
|
582
684
|
ctx: this.resolvedContext,
|
|
583
685
|
};
|
|
686
|
+
const deterministicResponse = this.persona.resolveDeterministicResponse?.(this.resolvedContext, iterCtx);
|
|
687
|
+
if (deterministicResponse !== undefined && deterministicResponse !== null) {
|
|
688
|
+
emit({ type: "text_chunk", content: deterministicResponse });
|
|
689
|
+
messages = [...messages, new AIMessage(deterministicResponse)];
|
|
690
|
+
iterationCount++;
|
|
691
|
+
return {
|
|
692
|
+
responseText: deterministicResponse,
|
|
693
|
+
messages,
|
|
694
|
+
iterationCount,
|
|
695
|
+
debugMeta: {
|
|
696
|
+
graph: "agent_loop",
|
|
697
|
+
iterations: iterationCount,
|
|
698
|
+
tools: toolsDebug,
|
|
699
|
+
llm,
|
|
700
|
+
},
|
|
701
|
+
};
|
|
702
|
+
}
|
|
584
703
|
const systemContent = this.persona.buildSystemContent(this.resolvedContext, iterCtx);
|
|
585
704
|
const fullMessages = [
|
|
586
705
|
new SystemMessage(systemContent),
|