@tangle-network/agent-app 0.46.28 → 0.46.30
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/dist/assistant/index.js +1 -1
- package/dist/chat-routes/index.js +1 -1
- package/dist/chat-store/index.js +1 -1
- package/dist/{chunk-XF7ZKISQ.js → chunk-4SGGSXI7.js} +27 -7
- package/dist/chunk-4SGGSXI7.js.map +1 -0
- package/dist/stream/index.js +1 -1
- package/dist/web-react/index.js +1 -1
- package/dist/work-product/index.js +33 -27
- package/dist/work-product/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-XF7ZKISQ.js.map +0 -1
package/dist/assistant/index.js
CHANGED
|
@@ -24,7 +24,7 @@ import "../chunk-YNMPMW3G.js";
|
|
|
24
24
|
import "../chunk-5ZTFZBS6.js";
|
|
25
25
|
import "../chunk-ZVEEWGDK.js";
|
|
26
26
|
import "../chunk-KWXUBMXU.js";
|
|
27
|
-
import "../chunk-
|
|
27
|
+
import "../chunk-4SGGSXI7.js";
|
|
28
28
|
import "../chunk-M3K2HVQD.js";
|
|
29
29
|
import "../chunk-YJMCRXQQ.js";
|
|
30
30
|
import "../chunk-TH7L265V.js";
|
package/dist/chat-store/index.js
CHANGED
|
@@ -35,6 +35,22 @@ function normalizeTime(value) {
|
|
|
35
35
|
end: Number.isFinite(end) ? end : void 0
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
+
var TOOL_EXIT_KEYS = ["exitCode", "exit"];
|
|
39
|
+
function toolExitCode(...values) {
|
|
40
|
+
for (const value of values) {
|
|
41
|
+
const record = asRecord(value);
|
|
42
|
+
if (!record) continue;
|
|
43
|
+
for (const key of TOOL_EXIT_KEYS) {
|
|
44
|
+
const exitCode = record[key];
|
|
45
|
+
if (typeof exitCode === "number" && Number.isInteger(exitCode)) return exitCode;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return void 0;
|
|
49
|
+
}
|
|
50
|
+
function toolExitError(output, exitCode) {
|
|
51
|
+
if (exitCode === void 0 || exitCode === 0) return void 0;
|
|
52
|
+
return asString(asRecord(output)?.stderr) ?? `Command exited with code ${exitCode}.`;
|
|
53
|
+
}
|
|
38
54
|
function normalizeToolEvent(event) {
|
|
39
55
|
if (event.type === "tool_call" || event.type === "tool.call") {
|
|
40
56
|
const data = event.data ?? {};
|
|
@@ -53,7 +69,10 @@ function normalizeToolEvent(event) {
|
|
|
53
69
|
}
|
|
54
70
|
if (event.type === "tool_result" || event.type === "tool.result") {
|
|
55
71
|
const data = event.data ?? {};
|
|
56
|
-
const
|
|
72
|
+
const output = data.output;
|
|
73
|
+
const exitCode = toolExitCode(output, data);
|
|
74
|
+
const error = asString(data.error) ?? toolExitError(output, exitCode);
|
|
75
|
+
const terminalError = data.status === "error" || data.status === "failed" || Boolean(error) || exitCode !== void 0 && exitCode !== 0;
|
|
57
76
|
return {
|
|
58
77
|
type: "message.part.updated",
|
|
59
78
|
data: {
|
|
@@ -61,9 +80,9 @@ function normalizeToolEvent(event) {
|
|
|
61
80
|
type: "tool",
|
|
62
81
|
id: data.id ?? data.callId ?? data.callID ?? data.name,
|
|
63
82
|
tool: data.name ?? data.tool ?? "tool",
|
|
64
|
-
output
|
|
83
|
+
output,
|
|
65
84
|
error,
|
|
66
|
-
status:
|
|
85
|
+
status: terminalError ? "error" : "completed"
|
|
67
86
|
}
|
|
68
87
|
}
|
|
69
88
|
};
|
|
@@ -144,9 +163,10 @@ function normalizePersistedPart(rawPart) {
|
|
|
144
163
|
if (type === "tool") {
|
|
145
164
|
const state = asRecord(rawPart.state);
|
|
146
165
|
const output = state?.output ?? rawPart.output;
|
|
147
|
-
const
|
|
148
|
-
const
|
|
149
|
-
const
|
|
166
|
+
const exitCode = toolExitCode(output, state, rawPart);
|
|
167
|
+
const error = asString(state?.error ?? rawPart.error) ?? toolExitError(output, exitCode);
|
|
168
|
+
const terminalError = state?.status === "error" || state?.status === "failed" || rawPart.status === "error" || rawPart.status === "failed" || Boolean(error) || exitCode !== void 0 && exitCode !== 0;
|
|
169
|
+
const status = terminalError ? "error" : state?.status === "completed" || rawPart.status === "completed" ? "completed" : output !== void 0 ? "completed" : "running";
|
|
150
170
|
return {
|
|
151
171
|
type: "tool",
|
|
152
172
|
id: resolveToolId(rawPart),
|
|
@@ -385,4 +405,4 @@ export {
|
|
|
385
405
|
terminalizeDanglingAssistantToolUpdates,
|
|
386
406
|
encodeEvent
|
|
387
407
|
};
|
|
388
|
-
//# sourceMappingURL=chunk-
|
|
408
|
+
//# sourceMappingURL=chunk-4SGGSXI7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/stream/stream-normalizer.ts"],"sourcesContent":["import {\n canTransitionInteractionStatus,\n persistedPartToInteraction,\n type ChatInteractionStatus,\n} from '../interactions/contract'\nimport {\n canTransitionPlanStatus,\n persistedPartToPlan,\n planPartKey,\n planToPersistedPart,\n type ChatPlanStatus,\n} from '../plans/index'\n\n/** Represent a JSON-compatible object with string keys and values of any type */\nexport type JsonRecord = Record<string, unknown>\n\n/** Define an event object carrying a type and optional JSON data payload */\nexport interface StreamEvent {\n type: string\n data?: JsonRecord\n}\n\n/** Resolve an unknown value to a JsonRecord if it is a non-array object or return undefined */\nexport function asRecord(value: unknown): JsonRecord | undefined {\n return value && typeof value === 'object' && !Array.isArray(value)\n ? value as JsonRecord\n : undefined\n}\n\n/** Resolve a non-empty string from a value or return undefined */\nexport function asString(value: unknown): string | undefined {\n return typeof value === 'string' && value.length > 0 ? value : undefined\n}\n\n/** Resolve a unique tool identifier from various possible properties or generate a fallback ID */\nexport function resolveToolId(part: JsonRecord): string {\n return String(\n part.id ??\n part.callID ??\n part.callId ??\n part.toolUseId ??\n part.toolCallId ??\n part.tool ??\n part.name ??\n `tool-${Date.now()}`,\n )\n}\n\n/** Resolve the tool name from a JSON record using tool, name, or a default value */\nexport function resolveToolName(part: JsonRecord): string {\n return String(part.tool ?? part.name ?? 'tool')\n}\n\n/** Resolve time properties from various keys into a normalized record with numeric start and end fields */\nexport function normalizeTime(value: unknown): JsonRecord | undefined {\n const record = asRecord(value)\n if (!record) return undefined\n\n const start = Number(record.start ?? record.startedAt ?? record.started_at)\n const end = Number(record.end ?? record.completedAt ?? record.completed_at)\n if (!Number.isFinite(start) && !Number.isFinite(end)) return undefined\n\n return {\n start: Number.isFinite(start) ? start : undefined,\n end: Number.isFinite(end) ? end : undefined,\n }\n}\n\n// Sandbox uses `exitCode`; OpenCode's structured shell output uses `exit`.\n// Keep this explicit so stderr alone never turns a successful command into an error.\nconst TOOL_EXIT_KEYS = ['exitCode', 'exit'] as const\n\nfunction toolExitCode(...values: unknown[]): number | undefined {\n for (const value of values) {\n const record = asRecord(value)\n if (!record) continue\n for (const key of TOOL_EXIT_KEYS) {\n const exitCode = record[key]\n if (typeof exitCode === 'number' && Number.isInteger(exitCode)) return exitCode\n }\n }\n return undefined\n}\n\nfunction toolExitError(output: unknown, exitCode: number | undefined): string | undefined {\n if (exitCode === undefined || exitCode === 0) return undefined\n return asString(asRecord(output)?.stderr) ?? `Command exited with code ${exitCode}.`\n}\n\n/** Normalize tool-related events into a standardized message.part.updated format */\nexport function normalizeToolEvent(event: StreamEvent): StreamEvent {\n if (event.type === 'tool_call' || event.type === 'tool.call') {\n const data = event.data ?? {}\n return {\n type: 'message.part.updated',\n data: {\n part: {\n type: 'tool',\n id: data.id ?? data.callId ?? data.callID ?? data.name,\n tool: data.name ?? data.tool ?? 'tool',\n input: data.arguments ?? data.input,\n status: 'running',\n },\n },\n }\n }\n\n if (event.type === 'tool_result' || event.type === 'tool.result') {\n const data = event.data ?? {}\n const output = data.output\n const exitCode = toolExitCode(output, data)\n const error = asString(data.error) ?? toolExitError(output, exitCode)\n const terminalError =\n data.status === 'error' ||\n data.status === 'failed' ||\n Boolean(error) ||\n (exitCode !== undefined && exitCode !== 0)\n return {\n type: 'message.part.updated',\n data: {\n part: {\n type: 'tool',\n id: data.id ?? data.callId ?? data.callID ?? data.name,\n tool: data.name ?? data.tool ?? 'tool',\n output,\n error,\n status: terminalError ? 'error' : 'completed',\n },\n },\n }\n }\n\n return event\n}\n\n/** Normalize a persisted part object by standardizing its structure and fields */\nexport function normalizePersistedPart(rawPart: JsonRecord): JsonRecord | null {\n const type = String(rawPart.type ?? '')\n\n if (type === 'text') {\n const id = asString(rawPart.id) ?? asString(rawPart.partId)\n return {\n type: 'text',\n text: asString(rawPart.text) ?? asString(rawPart.content) ?? '',\n // id: per-segment identity from the harness; absent on legacy parts,\n // which collapse to a single keyed segment. Never invented here.\n ...(id ? { id } : {}),\n }\n }\n\n if (type === 'reasoning') {\n const id = asString(rawPart.id) ?? asString(rawPart.partId)\n return {\n type: 'reasoning',\n text: asString(rawPart.text) ?? asString(rawPart.content) ?? '',\n time: normalizeTime(rawPart.time),\n ...(id ? { id } : {}),\n }\n }\n\n if (type === 'file' || type === 'image') {\n const id = asString(rawPart.id) ?? asString(rawPart.partId)\n return {\n type,\n ...(id ? { id } : {}),\n ...(asString(rawPart.filename) ? { filename: asString(rawPart.filename) } : {}),\n // `name`: the durable attachment display name `promoteAgentFilePart`\n // writes. Coexists with `filename` (legacy raw-harness shape) — kept\n // separate rather than unified so neither producer's shape is lossy.\n ...(asString(rawPart.name) ? { name: asString(rawPart.name) } : {}),\n ...(asString(rawPart.mediaType) ? { mediaType: asString(rawPart.mediaType) } : {}),\n ...(asString(rawPart.url) ? { url: asString(rawPart.url) } : {}),\n ...(asString(rawPart.path) ? { path: asString(rawPart.path) } : {}),\n ...(type === 'file' && asString(rawPart.content) ? { content: asString(rawPart.content) } : {}),\n ...(typeof rawPart.size === 'number' && Number.isFinite(rawPart.size) ? { size: rawPart.size } : {}),\n }\n }\n\n if (type === 'step-start') {\n return { type: 'step-start' }\n }\n\n // The harness's per-step usage receipt. Dropping it here silently loses the\n // turn's token/cost accounting from the persisted transcript.\n if (type === 'step-finish') {\n const tokens = asRecord(rawPart.tokens)\n const cost = Number(rawPart.cost)\n return {\n type: 'step-finish',\n ...(asString(rawPart.reason) ? { reason: asString(rawPart.reason) } : {}),\n ...(tokens ? { tokens } : {}),\n ...(Number.isFinite(cost) ? { cost } : {}),\n }\n }\n\n if (type === 'subtask') {\n const id = asString(rawPart.id) ?? asString(rawPart.partId)\n return {\n type: 'subtask',\n prompt: asString(rawPart.prompt) ?? '',\n description: asString(rawPart.description) ?? '',\n agent: asString(rawPart.agent) ?? '',\n ...(id ? { id } : {}),\n }\n }\n\n if (type === 'interaction') {\n return persistedPartToInteraction(rawPart) ? rawPart : null\n }\n\n if (type === 'plan') {\n const plan = persistedPartToPlan(rawPart)\n return plan ? { ...rawPart, ...planToPersistedPart(plan) } : null\n }\n\n // System-authored notices pass through verbatim; `/chat-store` owns their\n // final typed validation before persistence.\n if (type === 'notice') {\n return rawPart\n }\n\n if (type === 'tool') {\n const state = asRecord(rawPart.state)\n const output = state?.output ?? rawPart.output\n const exitCode = toolExitCode(output, state, rawPart)\n const error = asString(state?.error ?? rawPart.error) ?? toolExitError(output, exitCode)\n const terminalError =\n state?.status === 'error' ||\n state?.status === 'failed' ||\n rawPart.status === 'error' ||\n rawPart.status === 'failed' ||\n Boolean(error) ||\n (exitCode !== undefined && exitCode !== 0)\n const status =\n terminalError\n ? 'error'\n : state?.status === 'completed' || rawPart.status === 'completed'\n ? 'completed'\n : output !== undefined\n ? 'completed'\n : 'running'\n\n return {\n type: 'tool',\n id: resolveToolId(rawPart),\n tool: resolveToolName(rawPart),\n callID:\n rawPart.callID != null || rawPart.callId != null\n ? String(rawPart.callID ?? rawPart.callId)\n : undefined,\n state: {\n status,\n input: state?.input ?? rawPart.input,\n output,\n error,\n metadata: asRecord(state?.metadata) ?? asRecord(rawPart.metadata),\n time: normalizeTime(state?.time ?? rawPart.time),\n },\n }\n }\n\n return null\n}\n\n/** Stream/transcript part key for a promoted (path-bearing) attachment,\n * keyed on its storage path — re-emitting the same path folds into the same\n * segment instead of duplicating it. */\nexport function attachmentPartKey(path: string): string {\n return `attachment:${path}`\n}\n\n/** Resolve a unique key string for a part based on its type and identifying properties */\nexport function getPartKey(part: JsonRecord): string {\n const type = String(part.type ?? 'unknown')\n if (type === 'tool') {\n return `tool:${resolveToolId(part)}`\n }\n if (type === 'plan') return planPartKey(String(part.planId ?? ''))\n if ((type === 'file' || type === 'image') && asString(part.path)) {\n return attachmentPartKey(String(part.path))\n }\n\n // Keyed by the part's OWN type so distinct kinds never merge into each\n // other. Untyped parts fall back to the text lane (legacy shape).\n const lane = type && type !== 'unknown' ? type : 'text'\n return `${lane}:${String(part.id ?? part.partId ?? part.index ?? 'current')}`\n}\n\n/** Shallow overlay that skips `undefined` incoming values, so a later partial\n * update never erases a field an earlier one captured. */\nfunction overlayDefined(base: JsonRecord, patch: JsonRecord): JsonRecord {\n const out: JsonRecord = { ...base }\n for (const [key, value] of Object.entries(patch)) {\n if (value !== undefined) out[key] = value\n }\n return out\n}\n\n/** Merge incoming JSON with existing persisted data, applying delta for text types when provided */\nexport function mergePersistedPart(existing: JsonRecord | undefined, incoming: JsonRecord, delta?: string): JsonRecord {\n const type = String(incoming.type ?? '')\n if (!existing) {\n if (type === 'text' && delta) {\n return { type: 'text', text: delta }\n }\n return incoming\n }\n\n if (type === 'text' && String(existing.type ?? '') === 'text') {\n const existingText = String(existing.text ?? '')\n const incomingText = String(incoming.text ?? '')\n return {\n ...existing,\n ...incoming,\n // An empty snapshot never erases accumulated text (matches reasoning).\n text: delta ? `${existingText}${delta}` : incomingText || existingText,\n }\n }\n\n if (type === 'reasoning' && String(existing.type ?? '') === 'reasoning') {\n const existingText = String(existing.text ?? '')\n const incomingText = String(incoming.text ?? '')\n return {\n ...existing,\n ...incoming,\n text: delta && incomingText === existingText ? `${existingText}${delta}` : incomingText || existingText,\n time: incoming.time ?? existing.time,\n }\n }\n\n if (type === 'tool' && String(existing.type ?? '') === 'tool') {\n const existingState = asRecord(existing.state) ?? {}\n const incomingState = asRecord(incoming.state) ?? {}\n // Overlay only DEFINED incoming fields: a normalized tool part always\n // carries `output`/`error` keys (undefined when not captured), so a plain\n // spread would clobber a completed tool's output with a later empty update.\n const mergedState = overlayDefined(existingState, incomingState)\n // A partial update with no captured status/output/error normalizes to\n // `running`; never let it downgrade a tool that already settled.\n const existingStatus = String(existingState.status ?? '')\n if (\n (existingStatus === 'completed' || existingStatus === 'error') &&\n String(incomingState.status ?? '') === 'running'\n ) {\n mergedState.status = existingStatus\n }\n return {\n ...overlayDefined(existing, incoming),\n state: mergedState,\n }\n }\n\n if (type === 'interaction' && String(existing.type ?? '') === 'interaction') {\n const merged = overlayDefined(existing, incoming)\n const existingStatus = existing.status as ChatInteractionStatus | undefined\n const incomingStatus = incoming.status as ChatInteractionStatus | undefined\n if (\n existingStatus &&\n incomingStatus &&\n existingStatus !== incomingStatus &&\n !canTransitionInteractionStatus(existingStatus, incomingStatus)\n ) {\n merged.status = existingStatus\n }\n if (incoming.answers === undefined && existing.answers !== undefined) {\n merged.answers = existing.answers\n }\n return merged\n }\n\n if (type === 'plan' && String(existing.type ?? '') === 'plan') {\n const existingRevision = Number(existing.revision)\n const incomingRevision = Number(incoming.revision)\n if (Number.isInteger(existingRevision) && Number.isInteger(incomingRevision)) {\n if (incomingRevision < existingRevision) return existing\n if (incomingRevision > existingRevision) return incoming\n }\n const merged = overlayDefined(existing, incoming)\n const existingStatus = existing.status as ChatPlanStatus | undefined\n const incomingStatus = incoming.status as ChatPlanStatus | undefined\n if (\n existingStatus &&\n incomingStatus &&\n existingStatus !== incomingStatus &&\n !canTransitionPlanStatus(existingStatus, incomingStatus)\n ) {\n merged.status = existingStatus\n }\n return merged\n }\n\n return incoming\n}\n\n/** Resolve errors when a tool fails to report a terminal result before the assistant turn ends */\nexport const MISSING_TOOL_TERMINAL_ERROR = 'Tool did not report a terminal result before the assistant turn completed.'\n/** Provide the reason identifier for a missing tool in the terminal environment */\nexport const MISSING_TOOL_TERMINAL_REASON = 'missing-tool-terminal'\n\n/** Closes a tool part left `running` when a stream ended abnormally: settles\n * it as a terminal `error` and stamps `state.metadata.terminalized` so the\n * synthetic settlement is distinguishable from a real tool failure. Parts\n * that already settled (and non-tool parts) pass through untouched. */\nexport function terminalizeDanglingToolPart(part: JsonRecord): JsonRecord {\n if (String(part.type ?? '') !== 'tool') return part\n\n const state = asRecord(part.state) ?? {}\n if (String(state.status ?? part.status ?? '') !== 'running') return part\n\n const metadata = asRecord(state.metadata) ?? {}\n return {\n ...part,\n state: {\n ...state,\n status: 'error',\n error: asString(state.error ?? part.error) ?? MISSING_TOOL_TERMINAL_ERROR,\n metadata: {\n ...metadata,\n terminalized: true,\n terminalReason: MISSING_TOOL_TERMINAL_REASON,\n },\n },\n }\n}\n\n/** Resolve dangling tool parts into terminal forms within the given JSON records array */\nexport function terminalizeDanglingToolParts(parts: JsonRecord[]): JsonRecord[] {\n return parts.map(terminalizeDanglingToolPart)\n}\n\n/** Settles still-pending interaction parts at persist time. The broker\n * guarantees a resolved question either answered (run unblocked, no cancel\n * event) or cancelled/timed out (cancel event already updated the part), so\n * the success path finalizes remaining pendings as `answered` and the\n * failure/terminalize paths as `expired`. */\nexport function finalizePendingInteractionParts(\n parts: JsonRecord[],\n outcome: Extract<ChatInteractionStatus, 'answered' | 'expired'>,\n): JsonRecord[] {\n return parts.map((part) => {\n if (String(part.type ?? '') !== 'interaction') return part\n if (String(part.status ?? '') !== 'pending') return part\n return { ...part, status: outcome }\n })\n}\n\n/** Collapses text-part artifacts of unstable upstream segment identity: the\n * same text arriving under two keys (id-less delta stream, then an\n * id-bearing snapshot) folds into two segments, and interleaved empty\n * segments survive as blank parts. Consecutive identical text parts merge\n * into one; empty text parts drop when any non-empty text part exists. */\nexport function collapseRedundantTextParts(parts: JsonRecord[]): JsonRecord[] {\n const hasNonEmptyText = parts.some(\n (part) => String(part.type ?? '') === 'text' && String(part.text ?? '').trim().length > 0,\n )\n const collapsed: JsonRecord[] = []\n for (const part of parts) {\n if (String(part.type ?? '') !== 'text') {\n collapsed.push(part)\n continue\n }\n const text = String(part.text ?? '')\n if (hasNonEmptyText && text.trim().length === 0) continue\n const previous = collapsed[collapsed.length - 1]\n if (previous && String(previous.type ?? '') === 'text' && String(previous.text ?? '') === text) continue\n collapsed.push(part)\n }\n return collapsed\n}\n\nfunction assembleAssistantParts(\n partOrder: string[],\n partMap: Map<string, JsonRecord>,\n finalText: string,\n): JsonRecord[] {\n const parts = partOrder\n .map((key) => partMap.get(key))\n .filter((part): part is JsonRecord => Boolean(part))\n\n const textParts = parts.filter((part) => String(part.type ?? '') === 'text')\n\n if (textParts.length === 0) {\n if (finalText.trim()) {\n parts.push({ type: 'text', text: finalText })\n }\n return parts\n }\n\n // Id-less text parts form a single logical stream — the final text is\n // authoritative for it.\n if (!textParts.some((part) => asString(part.id))) {\n return parts.map((part) => {\n if (String(part.type ?? '') !== 'text') return part\n return {\n ...part,\n text: finalText || String(part.text ?? ''),\n }\n })\n }\n\n // Per-id text segments: invariant is concat(text parts) === persisted final\n // text, so segment boundaries survive without duplicating the answer into\n // every segment.\n const joined = textParts.map((part) => String(part.text ?? '')).join('')\n if (finalText === joined || finalText.trimEnd() === joined.trimEnd()) {\n return parts\n }\n\n if (finalText.startsWith(joined)) {\n // Final text extends the streamed segments (e.g. a failure diagnostic\n // appended after the stream) — persist the remainder as a trailing\n // id-less segment.\n return [...parts, { type: 'text', text: finalText.slice(joined.length) }]\n }\n\n // Final text replaced the streamed text outright. Keep non-text chronology;\n // collapse text to one authoritative segment at the last text position.\n const lastTextPart = textParts[textParts.length - 1]\n return parts\n .filter((part) => String(part.type ?? '') !== 'text' || part === lastTextPart)\n .map((part) => (part === lastTextPart ? { ...part, text: finalText } : part))\n}\n\n/** Resolve and clean up assistant parts by terminalizing and collapsing redundant segments */\nexport function finalizeAssistantParts(\n partOrder: string[],\n partMap: Map<string, JsonRecord>,\n finalText: string,\n): JsonRecord[] {\n // A stream that ended abnormally can leave tool parts `running` — never\n // persist one; collapsing then removes the duplicate/blank text segments an\n // unstable upstream segment identity produced.\n return collapseRedundantTextParts(terminalizeDanglingToolParts(\n assembleAssistantParts(partOrder, partMap, finalText),\n ))\n}\n\n/** The MID-STREAM twin of {@link finalizeAssistantParts}: the same assembled,\n * collapsed projection MINUS the dangling-tool terminalizer.\n *\n * Incremental persistence snapshots the assistant body while the turn is\n * still running, and mid-stream a tool part sitting at `state.status:\n * 'running'` is the NORMAL in-flight state — not the abnormal end\n * {@link terminalizeDanglingToolPart} exists to settle. Running a live\n * snapshot through `finalizeAssistantParts` would persist every in-flight\n * tool call as a failure (`state.status:'error'`, `metadata.terminalized`),\n * so a reader of the durable row would see phantom tool errors that the final\n * write then silently un-does. Terminalization stays a completion-time\n * decision: the final write is the only writer allowed to settle a tool part.\n *\n * Pending `interaction` parts are likewise left `pending` here (the caller\n * skips {@link finalizePendingInteractionParts}) — an ask is genuinely\n * unanswered until the turn settles. */\nexport function draftAssistantParts(\n partOrder: string[],\n partMap: Map<string, JsonRecord>,\n finalText: string,\n): JsonRecord[] {\n return collapseRedundantTextParts(assembleAssistantParts(partOrder, partMap, finalText))\n}\n\nfunction partStatus(part: JsonRecord | undefined): string {\n const state = asRecord(part?.state)\n return String(state?.status ?? part?.status ?? '')\n}\n\n/** Finalizes, then folds each synthetic tool settlement back into `partMap`\n * and returns just those updates — the shape a streaming loop needs to emit\n * closing `message.part.updated` frames for tools the stream never settled. */\nexport function terminalizeDanglingAssistantToolUpdates(\n partOrder: string[],\n partMap: Map<string, JsonRecord>,\n finalText: string,\n): JsonRecord[] {\n const finalizedParts = finalizeAssistantParts(partOrder, partMap, finalText)\n const updates: JsonRecord[] = []\n\n for (const part of finalizedParts) {\n if (String(part.type ?? '') !== 'tool') continue\n\n const key = getPartKey(part)\n const existing = partMap.get(key)\n if (partStatus(existing) !== 'running' || partStatus(part) === 'running') continue\n\n partMap.set(key, mergePersistedPart(existing, part))\n updates.push(part)\n }\n\n return updates\n}\n\n/** Encode a StreamEvent object into a Uint8Array using the provided TextEncoder */\nexport function encodeEvent(encoder: TextEncoder, event: StreamEvent): Uint8Array {\n return encoder.enc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|
terminalizeDanglingToolParts
|
|
28
|
-
} from "../chunk-
|
|
28
|
+
} from "../chunk-4SGGSXI7.js";
|
|
29
29
|
import "../chunk-M3K2HVQD.js";
|
|
30
30
|
import "../chunk-YJMCRXQQ.js";
|
|
31
31
|
import {
|
package/dist/web-react/index.js
CHANGED
|
@@ -892,9 +892,39 @@ function buildWorkProductTools(config) {
|
|
|
892
892
|
...config.now ? { now: config.now } : {},
|
|
893
893
|
...config.generateId ? { generateId: config.generateId } : {}
|
|
894
894
|
});
|
|
895
|
+
const canResolveTextLocators = config.readSourceText !== void 0;
|
|
896
|
+
const locatorProperties = {
|
|
897
|
+
page: { type: "number" },
|
|
898
|
+
range: { type: "string", description: "Free-form location: 'L120-L134' | 'B7' | '\xB64'." },
|
|
899
|
+
...canResolveTextLocators ? {
|
|
900
|
+
find: {
|
|
901
|
+
type: "string",
|
|
902
|
+
description: 'PREFERRED \u2014 use this whenever the value was READ from a document. The value exactly as it appears in the source (for example "128,450.00"), or a short distinctive phrase from the supporting line. The platform LOCATES it, cites the whole line it sits on, and returns that line to you. You do not retype the quote and you do not compute character offsets \u2014 so the citation can neither be invented nor land on the wrong line. If the value is not in the document, the entry is refused.'
|
|
903
|
+
},
|
|
904
|
+
findOccurrence: {
|
|
905
|
+
type: "integer",
|
|
906
|
+
minimum: 1,
|
|
907
|
+
description: "Which occurrence of `find` to cite when the value appears more than once. Defaults to the first."
|
|
908
|
+
},
|
|
909
|
+
span: {
|
|
910
|
+
type: "object",
|
|
911
|
+
description: "Only when you have exact character offsets from a tool that computed them. Absolute offsets into the whole document: start is the first character, end is one past the last. Prefer `find` \u2014 offsets computed by hand land on the wrong line.",
|
|
912
|
+
properties: {
|
|
913
|
+
start: { type: "integer", minimum: 0 },
|
|
914
|
+
end: { type: "integer", minimum: 1 }
|
|
915
|
+
},
|
|
916
|
+
required: ["start", "end"],
|
|
917
|
+
additionalProperties: false
|
|
918
|
+
}
|
|
919
|
+
} : {},
|
|
920
|
+
quote: {
|
|
921
|
+
type: "string",
|
|
922
|
+
description: canResolveTextLocators ? "Fallback for sources that cannot give you character offsets: the supporting text copied character-for-character. The platform checks it occurs in the document and REFUSES the entry if it does not. Prefer span. For a value you COMPUTED rather than read, omit both and state the computation in claim." : "Supporting text copied character-for-character from the source. This deployment cannot locate values or resolve character spans. For a value you COMPUTED rather than read, omit the locator and state the computation in claim."
|
|
923
|
+
}
|
|
924
|
+
};
|
|
895
925
|
const upsertEvidence = defineAppTool({
|
|
896
926
|
name: "upsert_evidence",
|
|
897
|
-
description: "Record source\u2192field lineage for the current work product, incrementally as you find it. Each entry links a source document (sourceRef + locator) to one artifact target and states the claim it supports. Cite by locator.find \u2014 the value exactly as it appears in the document \u2014 and the platform locates it and writes the supporting quote for you. Re-emitting an entry id replaces that entry. Address the work product by scopeKey; the first call creates the draft.",
|
|
927
|
+
description: canResolveTextLocators ? "Record source\u2192field lineage for the current work product, incrementally as you find it. Each entry links a source document (sourceRef + locator) to one artifact target and states the claim it supports. Cite by locator.find \u2014 the value exactly as it appears in the document \u2014 and the platform locates it and writes the supporting quote for you. Re-emitting an entry id replaces that entry. Address the work product by scopeKey; the first call creates the draft." : "Record source\u2192field lineage for the current work product, incrementally as you find it. Each entry links a source document (sourceRef + locator) to one artifact target and states the claim it supports. Cite with locator.quote when the source states the claim. This deployment cannot locate values or resolve character spans. Re-emitting an entry id replaces that entry. Address the work product by scopeKey; the first call creates the draft.",
|
|
898
928
|
parameters: {
|
|
899
929
|
type: "object",
|
|
900
930
|
properties: {
|
|
@@ -910,32 +940,8 @@ function buildWorkProductTools(config) {
|
|
|
910
940
|
sourceRef: { type: "string", description: "Vault path / attachment id of the SOURCE document." },
|
|
911
941
|
locator: {
|
|
912
942
|
type: "object",
|
|
913
|
-
properties:
|
|
914
|
-
|
|
915
|
-
range: { type: "string", description: "Free-form location: 'L120-L134' | 'B7' | '\xB64'." },
|
|
916
|
-
find: {
|
|
917
|
-
type: "string",
|
|
918
|
-
description: 'PREFERRED \u2014 use this whenever the value was READ from a document. The value exactly as it appears in the source (for example "128,450.00"), or a short distinctive phrase from the supporting line. The platform LOCATES it, cites the whole line it sits on, and returns that line to you. You do not retype the quote and you do not compute character offsets \u2014 so the citation can neither be invented nor land on the wrong line. If the value is not in the document, the entry is refused.'
|
|
919
|
-
},
|
|
920
|
-
findOccurrence: {
|
|
921
|
-
type: "integer",
|
|
922
|
-
minimum: 1,
|
|
923
|
-
description: "Which occurrence of `find` to cite when the value appears more than once. Defaults to the first."
|
|
924
|
-
},
|
|
925
|
-
span: {
|
|
926
|
-
type: "object",
|
|
927
|
-
description: "Only when you have exact character offsets from a tool that computed them. Absolute offsets into the whole document: start is the first character, end is one past the last. Prefer `find` \u2014 offsets computed by hand land on the wrong line.",
|
|
928
|
-
properties: {
|
|
929
|
-
start: { type: "integer", minimum: 0 },
|
|
930
|
-
end: { type: "integer", minimum: 1 }
|
|
931
|
-
},
|
|
932
|
-
required: ["start", "end"]
|
|
933
|
-
},
|
|
934
|
-
quote: {
|
|
935
|
-
type: "string",
|
|
936
|
-
description: "Fallback for sources that cannot give you character offsets: the supporting text copied character-for-character. The platform checks it occurs in the document and REFUSES the entry if it does not. Prefer span. For a value you COMPUTED rather than read, omit both and state the computation in claim."
|
|
937
|
-
}
|
|
938
|
-
}
|
|
943
|
+
properties: locatorProperties,
|
|
944
|
+
additionalProperties: false
|
|
939
945
|
},
|
|
940
946
|
target: { type: "string", description: "Artifact field/claim this evidence supports." },
|
|
941
947
|
claim: { type: "string", description: "The value/assertion at the target." },
|