@linnlabs/linnkit 0.8.0
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 +84 -0
- package/LICENSE +21 -0
- package/README.md +178 -0
- package/README.zh-CN.md +182 -0
- package/dist/agent-invocation-BHcNfrBV.d.cts +30 -0
- package/dist/agent-invocation-BznDaXDs.d.ts +30 -0
- package/dist/agentEvents-DEB7Fy_J.d.cts +81 -0
- package/dist/agentEvents-DEB7Fy_J.d.ts +81 -0
- package/dist/agentSpec-EkmviZjy.d.cts +2621 -0
- package/dist/agentSpec-EkmviZjy.d.ts +2621 -0
- package/dist/ai-engine.types-BpeU_XQG.d.cts +158 -0
- package/dist/ai-engine.types-vZRnQcJa.d.ts +158 -0
- package/dist/audit-BaRUGaqv.d.cts +307 -0
- package/dist/audit-BaRUGaqv.d.ts +307 -0
- package/dist/audit-CtcfART1.d.ts +33 -0
- package/dist/audit-LeOrm2hX.d.cts +33 -0
- package/dist/checkpointMarker-DAI3wUQu.d.cts +8 -0
- package/dist/checkpointMarker-DAI3wUQu.d.ts +8 -0
- package/dist/cli.cjs +8028 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +4 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +8025 -0
- package/dist/cli.js.map +1 -0
- package/dist/context-manager.cjs +8704 -0
- package/dist/context-manager.cjs.map +1 -0
- package/dist/context-manager.d.cts +2190 -0
- package/dist/context-manager.d.ts +2190 -0
- package/dist/context-manager.js +8650 -0
- package/dist/context-manager.js.map +1 -0
- package/dist/context-trace-DRi5M4lX.d.ts +239 -0
- package/dist/context-trace-HE2qY5Q-.d.cts +239 -0
- package/dist/contracts.cjs +1333 -0
- package/dist/contracts.cjs.map +1 -0
- package/dist/contracts.d.cts +8 -0
- package/dist/contracts.d.ts +8 -0
- package/dist/contracts.js +1214 -0
- package/dist/contracts.js.map +1 -0
- package/dist/defaultGraphExecutor-BBswR8wn.d.ts +624 -0
- package/dist/defaultGraphExecutor-BIjJj7WF.d.cts +624 -0
- package/dist/execution-CAIypb41.d.cts +129 -0
- package/dist/execution-CAIypb41.d.ts +129 -0
- package/dist/index-CHqwkvGp.d.ts +149 -0
- package/dist/index-CJeWHopy.d.ts +584 -0
- package/dist/index-Cm-JbzTH.d.cts +1450 -0
- package/dist/index-Cvr23YCl.d.cts +23 -0
- package/dist/index-DDzuSb0n.d.ts +23 -0
- package/dist/index-DO4dQgf2.d.cts +584 -0
- package/dist/index-DRBWi1fy.d.ts +1450 -0
- package/dist/index-Dl5PLgAv.d.cts +149 -0
- package/dist/index.cjs +9577 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +89 -0
- package/dist/index.d.ts +89 -0
- package/dist/index.js +9563 -0
- package/dist/index.js.map +1 -0
- package/dist/messages-XthmnHZ3.d.cts +8007 -0
- package/dist/messages-XthmnHZ3.d.ts +8007 -0
- package/dist/ports-DaatKJXp.d.cts +90 -0
- package/dist/ports-DnLuKfpE.d.ts +90 -0
- package/dist/ports.cjs +4 -0
- package/dist/ports.cjs.map +1 -0
- package/dist/ports.d.cts +7 -0
- package/dist/ports.d.ts +7 -0
- package/dist/ports.js +3 -0
- package/dist/ports.js.map +1 -0
- package/dist/quickstart.cjs +7697 -0
- package/dist/quickstart.cjs.map +1 -0
- package/dist/quickstart.d.cts +24 -0
- package/dist/quickstart.d.ts +24 -0
- package/dist/quickstart.js +7691 -0
- package/dist/quickstart.js.map +1 -0
- package/dist/runAgent-CPj_9e58.d.ts +88 -0
- package/dist/runAgent-HYKlXbVr.d.cts +88 -0
- package/dist/runHandle-CyXvzgzk.d.ts +239 -0
- package/dist/runHandle-D3gPsD7B.d.cts +239 -0
- package/dist/runtime-kernel/events.cjs +1485 -0
- package/dist/runtime-kernel/events.cjs.map +1 -0
- package/dist/runtime-kernel/events.d.cts +8 -0
- package/dist/runtime-kernel/events.d.ts +8 -0
- package/dist/runtime-kernel/events.js +1475 -0
- package/dist/runtime-kernel/events.js.map +1 -0
- package/dist/runtime-kernel.cjs +8656 -0
- package/dist/runtime-kernel.cjs.map +1 -0
- package/dist/runtime-kernel.d.cts +19 -0
- package/dist/runtime-kernel.d.ts +19 -0
- package/dist/runtime-kernel.js +8568 -0
- package/dist/runtime-kernel.js.map +1 -0
- package/dist/sse-vPyrOPa0.d.cts +1687 -0
- package/dist/sse-vPyrOPa0.d.ts +1687 -0
- package/dist/testkit.cjs +10613 -0
- package/dist/testkit.cjs.map +1 -0
- package/dist/testkit.d.cts +284 -0
- package/dist/testkit.d.ts +284 -0
- package/dist/testkit.js +10593 -0
- package/dist/testkit.js.map +1 -0
- package/dist/todo-B1PmDlp3.d.cts +2253 -0
- package/dist/todo-B1PmDlp3.d.ts +2253 -0
- package/dist/tokenizer-DFL4I7-I.d.ts +28 -0
- package/dist/tokenizer-DH_JXv-H.d.cts +28 -0
- package/dist/toolContracts-Blll0241.d.ts +463 -0
- package/dist/toolContracts-CLkQmhTG.d.cts +463 -0
- package/docs/README.md +76 -0
- package/docs/integration/01-installation.md +94 -0
- package/docs/integration/02-quickstart.md +104 -0
- package/docs/integration/README.md +223 -0
- package/docs/integration/agent-registration-guide.md +330 -0
- package/docs/integration/audit.md +64 -0
- package/docs/integration/child-runs.md +87 -0
- package/docs/integration/constraints-and-pitfalls.md +87 -0
- package/docs/integration/context-engineering.md +650 -0
- package/docs/integration/context-fences.md +289 -0
- package/docs/integration/glossary.md +69 -0
- package/docs/integration/llm-provider.md +76 -0
- package/docs/integration/persistence.md +44 -0
- package/docs/integration/realtime.md +76 -0
- package/docs/integration/run-supervisor.md +69 -0
- package/docs/integration/telemetry.md +48 -0
- package/docs/integration/testing.md +95 -0
- package/docs/integration/tool-development-guide.md +362 -0
- package/docs/integration/tool-history.md +202 -0
- package/docs/integration/tools.md +188 -0
- package/package.json +115 -0
|
@@ -0,0 +1,1333 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var zod = require('zod');
|
|
4
|
+
|
|
5
|
+
// src/contracts/messages.ts
|
|
6
|
+
var ProviderReasoningDetails = zod.z.array(zod.z.unknown());
|
|
7
|
+
var ToolCallExtraContent = zod.z.object({
|
|
8
|
+
google: zod.z.object({
|
|
9
|
+
thought_signature: zod.z.string().optional()
|
|
10
|
+
}).passthrough().optional()
|
|
11
|
+
}).passthrough();
|
|
12
|
+
var ToolCallWire = zod.z.object({
|
|
13
|
+
id: zod.z.string(),
|
|
14
|
+
type: zod.z.literal("function"),
|
|
15
|
+
function: zod.z.object({
|
|
16
|
+
name: zod.z.string(),
|
|
17
|
+
arguments: zod.z.string()
|
|
18
|
+
}),
|
|
19
|
+
extra_content: ToolCallExtraContent.optional()
|
|
20
|
+
}).passthrough();
|
|
21
|
+
var HistorySummaryMeta = zod.z.object({
|
|
22
|
+
messageType: zod.z.literal("summary"),
|
|
23
|
+
originalMessageCount: zod.z.number().int().positive(),
|
|
24
|
+
compressionRatio: zod.z.number().min(0).max(1).optional(),
|
|
25
|
+
includedOldSummary: zod.z.boolean(),
|
|
26
|
+
replacedMessageIds: zod.z.array(zod.z.string()),
|
|
27
|
+
summarySeq: zod.z.number().int().nonnegative()
|
|
28
|
+
});
|
|
29
|
+
var ToolCallsMeta = zod.z.object({
|
|
30
|
+
tool_calls: zod.z.array(ToolCallWire),
|
|
31
|
+
reasoning_details: ProviderReasoningDetails.optional()
|
|
32
|
+
});
|
|
33
|
+
var ToolOutputMeta = zod.z.object({
|
|
34
|
+
tool_name: zod.z.string(),
|
|
35
|
+
args: zod.z.record(zod.z.unknown()).optional(),
|
|
36
|
+
tool_call_id: zod.z.string()
|
|
37
|
+
});
|
|
38
|
+
var ImageInfoMeta = zod.z.object({
|
|
39
|
+
url: zod.z.string().optional(),
|
|
40
|
+
width: zod.z.number().int().positive().optional(),
|
|
41
|
+
height: zod.z.number().int().positive().optional(),
|
|
42
|
+
format: zod.z.string().optional(),
|
|
43
|
+
size: zod.z.number().int().nonnegative().optional()
|
|
44
|
+
});
|
|
45
|
+
var TaskTrackingMeta = zod.z.object({
|
|
46
|
+
taskType: zod.z.string().optional(),
|
|
47
|
+
taskId: zod.z.string().optional(),
|
|
48
|
+
taskStatus: zod.z.enum(["requested", "in_progress", "completed", "failed"]).optional(),
|
|
49
|
+
taskTrackingInfo: zod.z.object({
|
|
50
|
+
startTime: zod.z.number().optional(),
|
|
51
|
+
endTime: zod.z.number().optional(),
|
|
52
|
+
duration: zod.z.number().optional(),
|
|
53
|
+
retryCount: zod.z.number().int().nonnegative().optional(),
|
|
54
|
+
lastError: zod.z.string().optional()
|
|
55
|
+
}).optional()
|
|
56
|
+
});
|
|
57
|
+
var PersistentMetadata = zod.z.object({
|
|
58
|
+
messageType: zod.z.literal("summary").optional(),
|
|
59
|
+
originalMessageCount: zod.z.number().int().positive().optional(),
|
|
60
|
+
compressionRatio: zod.z.number().min(0).max(1).optional(),
|
|
61
|
+
includedOldSummary: zod.z.boolean().optional(),
|
|
62
|
+
replacedMessageIds: zod.z.array(zod.z.string()).optional(),
|
|
63
|
+
summarySeq: zod.z.number().int().nonnegative().optional(),
|
|
64
|
+
tool_calls: zod.z.array(ToolCallWire).optional(),
|
|
65
|
+
reasoning_details: ProviderReasoningDetails.optional(),
|
|
66
|
+
tool_name: zod.z.string().optional(),
|
|
67
|
+
args: zod.z.record(zod.z.unknown()).optional(),
|
|
68
|
+
tool_call_id: zod.z.string().optional(),
|
|
69
|
+
raw_output: zod.z.string().optional(),
|
|
70
|
+
image_info: ImageInfoMeta.optional(),
|
|
71
|
+
taskType: zod.z.string().optional(),
|
|
72
|
+
taskId: zod.z.string().optional(),
|
|
73
|
+
taskStatus: zod.z.enum(["requested", "in_progress", "completed", "failed"]).optional(),
|
|
74
|
+
taskTrackingInfo: zod.z.object({
|
|
75
|
+
startTime: zod.z.number().optional(),
|
|
76
|
+
endTime: zod.z.number().optional(),
|
|
77
|
+
duration: zod.z.number().optional(),
|
|
78
|
+
retryCount: zod.z.number().int().nonnegative().optional(),
|
|
79
|
+
lastError: zod.z.string().optional()
|
|
80
|
+
}).optional(),
|
|
81
|
+
fenceKind: zod.z.string().optional(),
|
|
82
|
+
fenceAttrs: zod.z.record(zod.z.unknown()).optional(),
|
|
83
|
+
fencePlacement: zod.z.string().optional()
|
|
84
|
+
}).passthrough();
|
|
85
|
+
var BaseMessage = zod.z.object({
|
|
86
|
+
id: zod.z.string(),
|
|
87
|
+
content: zod.z.string(),
|
|
88
|
+
timestamp: zod.z.number().int().nonnegative(),
|
|
89
|
+
metadata: PersistentMetadata.optional()
|
|
90
|
+
});
|
|
91
|
+
var SystemMessage = BaseMessage.extend({
|
|
92
|
+
role: zod.z.literal("system"),
|
|
93
|
+
type: zod.z.enum(["system_prompt", "history_summary", "context_injection"])
|
|
94
|
+
});
|
|
95
|
+
var UserMessage = BaseMessage.extend({
|
|
96
|
+
role: zod.z.literal("user"),
|
|
97
|
+
type: zod.z.enum([
|
|
98
|
+
"user_input",
|
|
99
|
+
"context_injection",
|
|
100
|
+
"context_before",
|
|
101
|
+
"context_after",
|
|
102
|
+
"document_fragment",
|
|
103
|
+
"task_request",
|
|
104
|
+
"image"
|
|
105
|
+
])
|
|
106
|
+
});
|
|
107
|
+
var AssistantMessage = BaseMessage.extend({
|
|
108
|
+
role: zod.z.literal("assistant"),
|
|
109
|
+
type: zod.z.enum([
|
|
110
|
+
"thought",
|
|
111
|
+
"final_answer",
|
|
112
|
+
"tool_code",
|
|
113
|
+
"tool_calls",
|
|
114
|
+
"task_completion"
|
|
115
|
+
])
|
|
116
|
+
});
|
|
117
|
+
var ToolMessage = BaseMessage.extend({
|
|
118
|
+
role: zod.z.literal("tool"),
|
|
119
|
+
type: zod.z.literal("tool_output")
|
|
120
|
+
});
|
|
121
|
+
var AiMessage = zod.z.discriminatedUnion("role", [
|
|
122
|
+
SystemMessage,
|
|
123
|
+
UserMessage,
|
|
124
|
+
AssistantMessage,
|
|
125
|
+
ToolMessage
|
|
126
|
+
]);
|
|
127
|
+
function createSystemMessage(type, content, metadata) {
|
|
128
|
+
return {
|
|
129
|
+
id: crypto.randomUUID(),
|
|
130
|
+
role: "system",
|
|
131
|
+
type,
|
|
132
|
+
content,
|
|
133
|
+
timestamp: Date.now(),
|
|
134
|
+
metadata
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function createUserMessage(type, content, metadata) {
|
|
138
|
+
return {
|
|
139
|
+
id: crypto.randomUUID(),
|
|
140
|
+
role: "user",
|
|
141
|
+
type,
|
|
142
|
+
content,
|
|
143
|
+
timestamp: Date.now(),
|
|
144
|
+
metadata
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function createAssistantMessage(type, content, metadata) {
|
|
148
|
+
return {
|
|
149
|
+
id: crypto.randomUUID(),
|
|
150
|
+
role: "assistant",
|
|
151
|
+
type,
|
|
152
|
+
content,
|
|
153
|
+
timestamp: Date.now(),
|
|
154
|
+
metadata
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function createToolMessage(content, toolCallId, toolName, metadata) {
|
|
158
|
+
return {
|
|
159
|
+
id: crypto.randomUUID(),
|
|
160
|
+
role: "tool",
|
|
161
|
+
type: "tool_output",
|
|
162
|
+
content,
|
|
163
|
+
timestamp: Date.now(),
|
|
164
|
+
metadata: {
|
|
165
|
+
...metadata,
|
|
166
|
+
tool_call_id: toolCallId,
|
|
167
|
+
tool_name: toolName
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function createHistorySummaryMessage(content, summaryMeta) {
|
|
172
|
+
return {
|
|
173
|
+
id: crypto.randomUUID(),
|
|
174
|
+
role: "system",
|
|
175
|
+
type: "history_summary",
|
|
176
|
+
content,
|
|
177
|
+
timestamp: Date.now(),
|
|
178
|
+
metadata: summaryMeta
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
function validateAiMessage(data) {
|
|
182
|
+
return AiMessage.safeParse(data);
|
|
183
|
+
}
|
|
184
|
+
function validateHistorySummaryMeta(data) {
|
|
185
|
+
return HistorySummaryMeta.safeParse(data);
|
|
186
|
+
}
|
|
187
|
+
function isSystemMessage(message) {
|
|
188
|
+
return message.role === "system";
|
|
189
|
+
}
|
|
190
|
+
function isUserMessage(message) {
|
|
191
|
+
return message.role === "user";
|
|
192
|
+
}
|
|
193
|
+
function isAssistantMessage(message) {
|
|
194
|
+
return message.role === "assistant";
|
|
195
|
+
}
|
|
196
|
+
function isToolMessage(message) {
|
|
197
|
+
return message.role === "tool";
|
|
198
|
+
}
|
|
199
|
+
function isHistorySummaryMessage(message) {
|
|
200
|
+
return message.role === "system" && message.type === "history_summary" && message.metadata?.messageType === "summary";
|
|
201
|
+
}
|
|
202
|
+
function hasToolCalls(message) {
|
|
203
|
+
return message.role === "assistant" && Array.isArray(message.metadata?.tool_calls) && message.metadata.tool_calls.length > 0;
|
|
204
|
+
}
|
|
205
|
+
var SerializableJsonValueSchema = zod.z.lazy(
|
|
206
|
+
() => zod.z.union([
|
|
207
|
+
zod.z.string(),
|
|
208
|
+
zod.z.number(),
|
|
209
|
+
zod.z.boolean(),
|
|
210
|
+
zod.z.null(),
|
|
211
|
+
zod.z.array(SerializableJsonValueSchema),
|
|
212
|
+
zod.z.record(zod.z.string(), SerializableJsonValueSchema)
|
|
213
|
+
])
|
|
214
|
+
);
|
|
215
|
+
var SerializableJsonRecord = zod.z.record(zod.z.string(), SerializableJsonValueSchema);
|
|
216
|
+
var AgentSpecMessageType = zod.z.enum([
|
|
217
|
+
"system_prompt",
|
|
218
|
+
"history_summary",
|
|
219
|
+
"context_injection",
|
|
220
|
+
"user_input",
|
|
221
|
+
"context_before",
|
|
222
|
+
"context_after",
|
|
223
|
+
"document_fragment",
|
|
224
|
+
"task_request",
|
|
225
|
+
"image",
|
|
226
|
+
"thought",
|
|
227
|
+
"final_answer",
|
|
228
|
+
"tool_code",
|
|
229
|
+
"tool_calls",
|
|
230
|
+
"task_completion",
|
|
231
|
+
"tool_output"
|
|
232
|
+
]);
|
|
233
|
+
var AgentSpecBudgetPolicy = zod.z.object({
|
|
234
|
+
maxTokens: zod.z.number().int().positive().optional(),
|
|
235
|
+
reservedForResponse: zod.z.number().int().nonnegative().optional(),
|
|
236
|
+
workingMemoryBudgetPercentage: zod.z.number().min(0).max(1).optional()
|
|
237
|
+
});
|
|
238
|
+
var AgentSpecToolHistoryPolicy = zod.z.object({
|
|
239
|
+
strategy: zod.z.enum(["per-pair", "per-run", "none"]).optional(),
|
|
240
|
+
keepLatestToolPairs: zod.z.number().int().nonnegative().optional(),
|
|
241
|
+
keepLatestRuns: zod.z.number().int().nonnegative().optional(),
|
|
242
|
+
maxInteractionGroups: zod.z.number().int().nonnegative().optional(),
|
|
243
|
+
overflowStrategy: zod.z.enum(["keep-latest", "fail-fast"]).optional(),
|
|
244
|
+
maxPairTokens: zod.z.number().int().nonnegative().optional(),
|
|
245
|
+
maxOutputSummaryTokens: zod.z.number().int().nonnegative().optional()
|
|
246
|
+
});
|
|
247
|
+
var AgentSpecToolObservationGovernancePolicy = zod.z.object({
|
|
248
|
+
enabled: zod.z.boolean().optional(),
|
|
249
|
+
maxChars: zod.z.number().int().positive().optional(),
|
|
250
|
+
maxLines: zod.z.number().int().positive().optional()
|
|
251
|
+
});
|
|
252
|
+
var AgentSpecToolOutputPolicy = zod.z.object({
|
|
253
|
+
observationGovernance: AgentSpecToolObservationGovernancePolicy.optional()
|
|
254
|
+
});
|
|
255
|
+
var AgentSpecProviderReplayPolicy = zod.z.object({
|
|
256
|
+
provider: zod.z.string().min(1).optional(),
|
|
257
|
+
requiresReasoningDetailsForToolReplay: zod.z.boolean().optional(),
|
|
258
|
+
missingSidecarBehavior: zod.z.enum(["allow", "degrade_to_text", "provider_empty_replay_field"]).optional()
|
|
259
|
+
});
|
|
260
|
+
var AgentSpecSummarizationPolicy = zod.z.object({
|
|
261
|
+
triggerThreshold: zod.z.number().min(0).max(1).optional(),
|
|
262
|
+
budgetPercentage: zod.z.number().min(0).max(1).optional(),
|
|
263
|
+
oldestMessagesPercentage: zod.z.number().min(0).max(1).optional(),
|
|
264
|
+
agentId: zod.z.string().min(1).optional(),
|
|
265
|
+
failureBehavior: zod.z.enum(["fail-fast", "continue-if-within-budget"]).optional()
|
|
266
|
+
});
|
|
267
|
+
var AgentSpecMustKeepTruncationRule = zod.z.object({
|
|
268
|
+
fenceKind: zod.z.string().min(1),
|
|
269
|
+
maxBudgetFraction: zod.z.number().gt(0).max(1),
|
|
270
|
+
strategyName: zod.z.string().min(1)
|
|
271
|
+
});
|
|
272
|
+
var AgentSpecMustKeepPolicy = zod.z.object({
|
|
273
|
+
alwaysKeepTypes: zod.z.array(AgentSpecMessageType).optional(),
|
|
274
|
+
alwaysKeepFenceKinds: zod.z.array(zod.z.string().min(1)).optional(),
|
|
275
|
+
truncationRules: zod.z.array(AgentSpecMustKeepTruncationRule).optional()
|
|
276
|
+
});
|
|
277
|
+
var AgentSpecWorkingMemoryPolicy = zod.z.object({
|
|
278
|
+
maxRecentToolInteractions: zod.z.number().int().nonnegative().optional(),
|
|
279
|
+
minToolInteractionsToKeep: zod.z.number().int().nonnegative().optional(),
|
|
280
|
+
toolPairingSearchRange: zod.z.number().int().positive().optional()
|
|
281
|
+
});
|
|
282
|
+
var AgentSpecCheckpointPolicy = zod.z.object({
|
|
283
|
+
keepPairsBefore: zod.z.number().int().nonnegative().optional(),
|
|
284
|
+
triggerToolName: zod.z.string().min(1).optional()
|
|
285
|
+
});
|
|
286
|
+
var AgentSpecReasoningRetentionPolicy = zod.z.object({
|
|
287
|
+
keepLatestThoughts: zod.z.number().int().nonnegative().optional()
|
|
288
|
+
});
|
|
289
|
+
var AgentSpecTokenEstimationPolicy = zod.z.object({
|
|
290
|
+
encoding: zod.z.string().min(1).optional(),
|
|
291
|
+
avgCharsPerToken: zod.z.number().positive().optional(),
|
|
292
|
+
toolCallOverhead: zod.z.number().int().nonnegative().optional()
|
|
293
|
+
});
|
|
294
|
+
var SYSTEM_REMINDER_BUILTIN_TRIGGER_KINDS = [
|
|
295
|
+
"phase-equals",
|
|
296
|
+
"remaining-steps-leq",
|
|
297
|
+
"step-count-modulo",
|
|
298
|
+
"tool-call-streak",
|
|
299
|
+
"budget-warning",
|
|
300
|
+
"agent-has-tool"
|
|
301
|
+
];
|
|
302
|
+
var AgentSpecSystemReminderTrigger = zod.z.object({
|
|
303
|
+
kind: zod.z.string().min(1),
|
|
304
|
+
threshold: zod.z.number().nonnegative().optional(),
|
|
305
|
+
value: zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()]).optional(),
|
|
306
|
+
moduloStep: zod.z.boolean().optional(),
|
|
307
|
+
toolName: zod.z.string().min(1).optional(),
|
|
308
|
+
period: zod.z.number().int().positive().optional(),
|
|
309
|
+
minStep: zod.z.number().int().nonnegative().optional(),
|
|
310
|
+
ratio: zod.z.number().min(0).max(1).optional(),
|
|
311
|
+
config: SerializableJsonRecord.optional()
|
|
312
|
+
});
|
|
313
|
+
var AgentSpecSystemReminderExtraRule = zod.z.object({
|
|
314
|
+
id: zod.z.string().min(1),
|
|
315
|
+
trigger: AgentSpecSystemReminderTrigger,
|
|
316
|
+
contentTemplate: zod.z.string().min(1),
|
|
317
|
+
contentArgs: SerializableJsonRecord.optional()
|
|
318
|
+
});
|
|
319
|
+
var AgentSpecSystemReminderPolicy = zod.z.object({
|
|
320
|
+
enabledRuleIds: zod.z.array(zod.z.string().min(1)).nullable().optional(),
|
|
321
|
+
disabledRuleIds: zod.z.array(zod.z.string().min(1)).optional(),
|
|
322
|
+
thresholds: zod.z.object({
|
|
323
|
+
toolCallStreak: zod.z.number().int().nonnegative().optional(),
|
|
324
|
+
taskstateReflectionPeriod: zod.z.number().int().positive().optional(),
|
|
325
|
+
budgetWarningRatio: zod.z.number().min(0).max(1).optional(),
|
|
326
|
+
lastStepsHintThreshold: zod.z.number().int().nonnegative().optional()
|
|
327
|
+
}).optional(),
|
|
328
|
+
extraRules: zod.z.array(AgentSpecSystemReminderExtraRule).optional()
|
|
329
|
+
}).superRefine((value, ctx) => {
|
|
330
|
+
if (value.enabledRuleIds !== void 0 && value.enabledRuleIds !== null && value.disabledRuleIds?.length) {
|
|
331
|
+
ctx.addIssue({
|
|
332
|
+
code: zod.z.ZodIssueCode.custom,
|
|
333
|
+
path: ["disabledRuleIds"],
|
|
334
|
+
message: "enabledRuleIds and disabledRuleIds cannot be configured at the same time"
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
var AgentSpecContextTracePolicy = zod.z.object({
|
|
339
|
+
enabled: zod.z.boolean().optional(),
|
|
340
|
+
includeMessageIds: zod.z.boolean().optional(),
|
|
341
|
+
includeTokenBreakdown: zod.z.boolean().optional(),
|
|
342
|
+
maxTraceEvents: zod.z.number().int().positive().optional()
|
|
343
|
+
});
|
|
344
|
+
var AgentSpecContextPolicy = zod.z.object({
|
|
345
|
+
profileId: zod.z.string().min(1),
|
|
346
|
+
budget: AgentSpecBudgetPolicy.optional(),
|
|
347
|
+
toolHistory: AgentSpecToolHistoryPolicy.optional(),
|
|
348
|
+
toolOutput: AgentSpecToolOutputPolicy.optional(),
|
|
349
|
+
providerReplay: AgentSpecProviderReplayPolicy.optional(),
|
|
350
|
+
summarization: AgentSpecSummarizationPolicy.optional(),
|
|
351
|
+
mustKeep: AgentSpecMustKeepPolicy.optional(),
|
|
352
|
+
workingMemory: AgentSpecWorkingMemoryPolicy.optional(),
|
|
353
|
+
checkpoint: AgentSpecCheckpointPolicy.optional(),
|
|
354
|
+
reasoningRetention: AgentSpecReasoningRetentionPolicy.optional(),
|
|
355
|
+
tokenEstimation: AgentSpecTokenEstimationPolicy.optional(),
|
|
356
|
+
systemReminder: AgentSpecSystemReminderPolicy.optional(),
|
|
357
|
+
contextTrace: AgentSpecContextTracePolicy.optional()
|
|
358
|
+
});
|
|
359
|
+
var DEFAULT_CONTEXT_POLICY = {
|
|
360
|
+
profileId: "agent",
|
|
361
|
+
budget: {
|
|
362
|
+
maxTokens: 12e4,
|
|
363
|
+
reservedForResponse: 2400,
|
|
364
|
+
workingMemoryBudgetPercentage: 0.7
|
|
365
|
+
},
|
|
366
|
+
toolHistory: {
|
|
367
|
+
strategy: "per-run",
|
|
368
|
+
keepLatestToolPairs: 2,
|
|
369
|
+
keepLatestRuns: 1,
|
|
370
|
+
maxInteractionGroups: 12,
|
|
371
|
+
overflowStrategy: "keep-latest",
|
|
372
|
+
maxPairTokens: 6e3,
|
|
373
|
+
maxOutputSummaryTokens: 1e3
|
|
374
|
+
},
|
|
375
|
+
toolOutput: {
|
|
376
|
+
observationGovernance: {
|
|
377
|
+
enabled: true,
|
|
378
|
+
maxChars: 2e4,
|
|
379
|
+
maxLines: 1200
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
providerReplay: {},
|
|
383
|
+
summarization: {
|
|
384
|
+
triggerThreshold: 0.7,
|
|
385
|
+
budgetPercentage: 0.12,
|
|
386
|
+
oldestMessagesPercentage: 0.75,
|
|
387
|
+
failureBehavior: "fail-fast"
|
|
388
|
+
},
|
|
389
|
+
mustKeep: {
|
|
390
|
+
alwaysKeepTypes: ["system_prompt", "user_input"],
|
|
391
|
+
alwaysKeepFenceKinds: [],
|
|
392
|
+
truncationRules: []
|
|
393
|
+
},
|
|
394
|
+
workingMemory: {
|
|
395
|
+
maxRecentToolInteractions: 2,
|
|
396
|
+
minToolInteractionsToKeep: 2,
|
|
397
|
+
toolPairingSearchRange: 10
|
|
398
|
+
},
|
|
399
|
+
checkpoint: {
|
|
400
|
+
keepPairsBefore: 2,
|
|
401
|
+
triggerToolName: "context_checkpoint"
|
|
402
|
+
},
|
|
403
|
+
reasoningRetention: {
|
|
404
|
+
keepLatestThoughts: 1
|
|
405
|
+
},
|
|
406
|
+
tokenEstimation: {
|
|
407
|
+
encoding: "cl100k_base",
|
|
408
|
+
avgCharsPerToken: 2,
|
|
409
|
+
toolCallOverhead: 50
|
|
410
|
+
},
|
|
411
|
+
systemReminder: {
|
|
412
|
+
enabledRuleIds: null,
|
|
413
|
+
disabledRuleIds: [],
|
|
414
|
+
thresholds: {
|
|
415
|
+
toolCallStreak: 10,
|
|
416
|
+
taskstateReflectionPeriod: 30,
|
|
417
|
+
budgetWarningRatio: 0.9,
|
|
418
|
+
lastStepsHintThreshold: 0
|
|
419
|
+
},
|
|
420
|
+
extraRules: []
|
|
421
|
+
},
|
|
422
|
+
contextTrace: {
|
|
423
|
+
enabled: false,
|
|
424
|
+
includeMessageIds: true,
|
|
425
|
+
includeTokenBreakdown: true,
|
|
426
|
+
maxTraceEvents: 200
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
function defineContextPolicy(input = {}) {
|
|
430
|
+
const merged = {
|
|
431
|
+
profileId: input.profileId ?? DEFAULT_CONTEXT_POLICY.profileId,
|
|
432
|
+
budget: { ...DEFAULT_CONTEXT_POLICY.budget, ...input.budget },
|
|
433
|
+
toolHistory: { ...DEFAULT_CONTEXT_POLICY.toolHistory, ...input.toolHistory },
|
|
434
|
+
toolOutput: {
|
|
435
|
+
...DEFAULT_CONTEXT_POLICY.toolOutput,
|
|
436
|
+
...input.toolOutput,
|
|
437
|
+
observationGovernance: {
|
|
438
|
+
...DEFAULT_CONTEXT_POLICY.toolOutput.observationGovernance,
|
|
439
|
+
...input.toolOutput?.observationGovernance
|
|
440
|
+
}
|
|
441
|
+
},
|
|
442
|
+
providerReplay: { ...DEFAULT_CONTEXT_POLICY.providerReplay, ...input.providerReplay },
|
|
443
|
+
summarization: { ...DEFAULT_CONTEXT_POLICY.summarization, ...input.summarization },
|
|
444
|
+
mustKeep: { ...DEFAULT_CONTEXT_POLICY.mustKeep, ...input.mustKeep },
|
|
445
|
+
workingMemory: { ...DEFAULT_CONTEXT_POLICY.workingMemory, ...input.workingMemory },
|
|
446
|
+
checkpoint: { ...DEFAULT_CONTEXT_POLICY.checkpoint, ...input.checkpoint },
|
|
447
|
+
reasoningRetention: { ...DEFAULT_CONTEXT_POLICY.reasoningRetention, ...input.reasoningRetention },
|
|
448
|
+
tokenEstimation: { ...DEFAULT_CONTEXT_POLICY.tokenEstimation, ...input.tokenEstimation },
|
|
449
|
+
systemReminder: {
|
|
450
|
+
...DEFAULT_CONTEXT_POLICY.systemReminder,
|
|
451
|
+
...input.systemReminder,
|
|
452
|
+
thresholds: {
|
|
453
|
+
...DEFAULT_CONTEXT_POLICY.systemReminder.thresholds,
|
|
454
|
+
...input.systemReminder?.thresholds
|
|
455
|
+
},
|
|
456
|
+
extraRules: input.systemReminder?.extraRules ?? DEFAULT_CONTEXT_POLICY.systemReminder.extraRules
|
|
457
|
+
},
|
|
458
|
+
contextTrace: { ...DEFAULT_CONTEXT_POLICY.contextTrace, ...input.contextTrace }
|
|
459
|
+
};
|
|
460
|
+
return AgentSpecContextPolicy.parse(merged);
|
|
461
|
+
}
|
|
462
|
+
var JsonRecord = zod.z.record(zod.z.string(), zod.z.unknown());
|
|
463
|
+
var ToolArgsSchemaSpec = JsonRecord.superRefine((value, ctx) => {
|
|
464
|
+
const parse = value["parse"];
|
|
465
|
+
const safeParse = value["safeParse"];
|
|
466
|
+
const definition = value["_def"];
|
|
467
|
+
if (typeof parse === "function" && typeof safeParse === "function" && definition !== void 0) {
|
|
468
|
+
ctx.addIssue({
|
|
469
|
+
code: zod.z.ZodIssueCode.custom,
|
|
470
|
+
message: "argsSchema must be a serializable record, not a runtime zod schema"
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
var AgentCapability = zod.z.string().min(1);
|
|
475
|
+
var ToolBindingSpec = zod.z.object({
|
|
476
|
+
toolId: zod.z.string().min(1),
|
|
477
|
+
bindingId: zod.z.string().min(1).optional(),
|
|
478
|
+
argsSchema: ToolArgsSchemaSpec.optional(),
|
|
479
|
+
config: JsonRecord.optional(),
|
|
480
|
+
metadata: JsonRecord.optional()
|
|
481
|
+
});
|
|
482
|
+
var AgentSpecModelHints = zod.z.object({
|
|
483
|
+
preferredProviders: zod.z.array(zod.z.string().min(1)).optional(),
|
|
484
|
+
preferredModels: zod.z.array(zod.z.string().min(1)).optional(),
|
|
485
|
+
fallbackChain: zod.z.array(zod.z.string().min(1)).optional()
|
|
486
|
+
});
|
|
487
|
+
var AgentSpecAuditConfig = zod.z.object({
|
|
488
|
+
redactionLevel: zod.z.enum(["none", "standard", "strict"]).optional(),
|
|
489
|
+
pii: zod.z.boolean().optional()
|
|
490
|
+
});
|
|
491
|
+
var AgentSpec = zod.z.object({
|
|
492
|
+
id: zod.z.string().min(1),
|
|
493
|
+
version: zod.z.string().min(1),
|
|
494
|
+
role: zod.z.string().optional(),
|
|
495
|
+
description: zod.z.string().optional(),
|
|
496
|
+
capabilities: zod.z.array(AgentCapability),
|
|
497
|
+
tools: zod.z.array(ToolBindingSpec),
|
|
498
|
+
contextPolicy: AgentSpecContextPolicy,
|
|
499
|
+
modelHints: AgentSpecModelHints.optional(),
|
|
500
|
+
audit: AgentSpecAuditConfig.optional(),
|
|
501
|
+
metadata: JsonRecord.optional()
|
|
502
|
+
});
|
|
503
|
+
var JsonRecord2 = zod.z.record(zod.z.string(), zod.z.unknown());
|
|
504
|
+
var AUDIT_ACTIONS = [
|
|
505
|
+
"model.select",
|
|
506
|
+
"model.fallback",
|
|
507
|
+
"tool.allow",
|
|
508
|
+
"tool.deny",
|
|
509
|
+
"wait_user.request",
|
|
510
|
+
"sandbox.decide",
|
|
511
|
+
"run.cancel",
|
|
512
|
+
"run.pause",
|
|
513
|
+
"run.resume",
|
|
514
|
+
"memory.write"
|
|
515
|
+
];
|
|
516
|
+
var AUDIT_DECISION_OUTCOMES = [
|
|
517
|
+
"allowed",
|
|
518
|
+
"denied",
|
|
519
|
+
"fallback",
|
|
520
|
+
"retry",
|
|
521
|
+
"cancelled",
|
|
522
|
+
"paused",
|
|
523
|
+
"resumed",
|
|
524
|
+
"requested",
|
|
525
|
+
"recorded"
|
|
526
|
+
];
|
|
527
|
+
var AuditActor = zod.z.object({
|
|
528
|
+
kind: zod.z.enum(["system", "host", "agent", "model", "tool", "user"]),
|
|
529
|
+
id: zod.z.string().min(1).optional(),
|
|
530
|
+
name: zod.z.string().min(1).optional()
|
|
531
|
+
});
|
|
532
|
+
var AuditDecision = zod.z.object({
|
|
533
|
+
outcome: zod.z.enum(AUDIT_DECISION_OUTCOMES),
|
|
534
|
+
reason: zod.z.string().optional(),
|
|
535
|
+
policy: zod.z.string().optional(),
|
|
536
|
+
metadata: JsonRecord2.optional()
|
|
537
|
+
});
|
|
538
|
+
var AuditEvidence = zod.z.object({
|
|
539
|
+
kind: zod.z.string().min(1),
|
|
540
|
+
ref: zod.z.string().min(1).optional(),
|
|
541
|
+
summary: zod.z.string().optional(),
|
|
542
|
+
metadata: JsonRecord2.optional()
|
|
543
|
+
});
|
|
544
|
+
var AuditCostDelta = zod.z.object({
|
|
545
|
+
tokensInput: zod.z.number().int().nonnegative().optional(),
|
|
546
|
+
tokensOutput: zod.z.number().int().nonnegative().optional(),
|
|
547
|
+
totalCostUsd: zod.z.number().nonnegative().optional(),
|
|
548
|
+
latencyMs: zod.z.number().nonnegative().optional()
|
|
549
|
+
});
|
|
550
|
+
var AuditScope = zod.z.object({
|
|
551
|
+
conversationId: zod.z.string().min(1).optional(),
|
|
552
|
+
runId: zod.z.string().min(1).optional(),
|
|
553
|
+
parentRunId: zod.z.string().min(1).optional(),
|
|
554
|
+
turnId: zod.z.string().min(1).optional(),
|
|
555
|
+
traceId: zod.z.string().min(1).optional(),
|
|
556
|
+
agentSpecId: zod.z.string().min(1).optional(),
|
|
557
|
+
toolCallId: zod.z.string().min(1).optional(),
|
|
558
|
+
toolName: zod.z.string().min(1).optional(),
|
|
559
|
+
modelId: zod.z.string().min(1).optional(),
|
|
560
|
+
nodeId: zod.z.string().min(1).optional(),
|
|
561
|
+
metadata: JsonRecord2.optional()
|
|
562
|
+
});
|
|
563
|
+
var AuditEnvelope = zod.z.object({
|
|
564
|
+
envelopeId: zod.z.string().min(1),
|
|
565
|
+
runId: zod.z.string().min(1),
|
|
566
|
+
parentRunId: zod.z.string().min(1).optional(),
|
|
567
|
+
ts: zod.z.number().int().nonnegative(),
|
|
568
|
+
actor: AuditActor,
|
|
569
|
+
action: zod.z.string().min(1),
|
|
570
|
+
decision: AuditDecision.optional(),
|
|
571
|
+
evidence: zod.z.array(AuditEvidence).optional(),
|
|
572
|
+
costDelta: AuditCostDelta.optional(),
|
|
573
|
+
scope: AuditScope.optional()
|
|
574
|
+
});
|
|
575
|
+
var BaseEvent = zod.z.object({
|
|
576
|
+
id: zod.z.string(),
|
|
577
|
+
conversation_id: zod.z.string(),
|
|
578
|
+
timestamp: zod.z.number(),
|
|
579
|
+
metadata: zod.z.record(zod.z.unknown()).optional(),
|
|
580
|
+
version: zod.z.literal(1).default(1),
|
|
581
|
+
turn_id: zod.z.string(),
|
|
582
|
+
ephemeral: zod.z.boolean().optional()
|
|
583
|
+
});
|
|
584
|
+
var ToolCallPhase = zod.z.enum(["start", "update", "complete", "error"]);
|
|
585
|
+
var Status = zod.z.enum(["loading", "success", "error"]);
|
|
586
|
+
var AgentTodoStatus = zod.z.enum(["pending", "in_progress", "completed", "cancelled"]);
|
|
587
|
+
var AgentTodoItem = zod.z.object({
|
|
588
|
+
id: zod.z.string(),
|
|
589
|
+
content: zod.z.string(),
|
|
590
|
+
status: AgentTodoStatus
|
|
591
|
+
});
|
|
592
|
+
var ProviderReasoningDetailsPayload = zod.z.array(zod.z.unknown());
|
|
593
|
+
var ToolCallDecisionPayload = zod.z.object({
|
|
594
|
+
args: zod.z.record(zod.z.any()).optional(),
|
|
595
|
+
tool_calls: zod.z.array(zod.z.unknown()).optional(),
|
|
596
|
+
/**
|
|
597
|
+
* 不透明 provider reasoning replay blocks。
|
|
598
|
+
*
|
|
599
|
+
* RuntimeEvent 层的标准位置是 assistant 产出事件携带 reasoning_details;
|
|
600
|
+
* context-manager 会把它回放到 AiMessage.metadata.reasoning_details。
|
|
601
|
+
*/
|
|
602
|
+
reasoning_details: ProviderReasoningDetailsPayload.optional()
|
|
603
|
+
}).passthrough();
|
|
604
|
+
var RuntimeEvent = zod.z.discriminatedUnion("type", [
|
|
605
|
+
BaseEvent.extend({
|
|
606
|
+
type: zod.z.literal("user_input"),
|
|
607
|
+
content: zod.z.string(),
|
|
608
|
+
raw_content: zod.z.string().optional(),
|
|
609
|
+
source: zod.z.enum(["user", "editor", "system"]).default("user")
|
|
610
|
+
}),
|
|
611
|
+
BaseEvent.extend({
|
|
612
|
+
type: zod.z.literal("thought"),
|
|
613
|
+
content: zod.z.string(),
|
|
614
|
+
thought_message_id: zod.z.string().optional(),
|
|
615
|
+
delta: zod.z.string().optional(),
|
|
616
|
+
is_complete: zod.z.boolean().default(false)
|
|
617
|
+
}),
|
|
618
|
+
BaseEvent.extend({
|
|
619
|
+
type: zod.z.literal("tool_call_decision"),
|
|
620
|
+
tool_name: zod.z.string(),
|
|
621
|
+
tool_call_id: zod.z.string(),
|
|
622
|
+
phase: ToolCallPhase,
|
|
623
|
+
status: Status,
|
|
624
|
+
args: zod.z.record(zod.z.any()).optional(),
|
|
625
|
+
payload: ToolCallDecisionPayload.optional(),
|
|
626
|
+
parent_tool_call_id: zod.z.string().optional(),
|
|
627
|
+
meta: zod.z.record(zod.z.any()).optional()
|
|
628
|
+
}),
|
|
629
|
+
BaseEvent.extend({
|
|
630
|
+
type: zod.z.literal("tool_process"),
|
|
631
|
+
tool_name: zod.z.string(),
|
|
632
|
+
tool_call_id: zod.z.string(),
|
|
633
|
+
phase: ToolCallPhase,
|
|
634
|
+
status: Status,
|
|
635
|
+
args: zod.z.record(zod.z.any()).optional(),
|
|
636
|
+
payload: zod.z.record(zod.z.any()).optional(),
|
|
637
|
+
parent_tool_call_id: zod.z.string().optional(),
|
|
638
|
+
meta: zod.z.record(zod.z.any()).optional()
|
|
639
|
+
}),
|
|
640
|
+
BaseEvent.extend({
|
|
641
|
+
type: zod.z.literal("tool_output"),
|
|
642
|
+
tool_name: zod.z.string(),
|
|
643
|
+
tool_call_id: zod.z.string(),
|
|
644
|
+
status: zod.z.enum(["success", "error"]),
|
|
645
|
+
output: zod.z.any().optional(),
|
|
646
|
+
payload: zod.z.record(zod.z.any()).optional(),
|
|
647
|
+
error: zod.z.string().optional(),
|
|
648
|
+
duration_ms: zod.z.number().optional()
|
|
649
|
+
}),
|
|
650
|
+
BaseEvent.extend({
|
|
651
|
+
type: zod.z.literal("todo_updated"),
|
|
652
|
+
todo_list_id: zod.z.string(),
|
|
653
|
+
todo_list_version: zod.z.number().int().nonnegative(),
|
|
654
|
+
items: zod.z.array(AgentTodoItem)
|
|
655
|
+
}),
|
|
656
|
+
BaseEvent.extend({
|
|
657
|
+
type: zod.z.literal("subrun_trace"),
|
|
658
|
+
parent_tool_call_id: zod.z.string(),
|
|
659
|
+
subrun_id: zod.z.string(),
|
|
660
|
+
subrun_parent_id: zod.z.string().optional(),
|
|
661
|
+
kind: zod.z.enum([
|
|
662
|
+
"thought_delta",
|
|
663
|
+
"thought_complete",
|
|
664
|
+
"tool_call_decision",
|
|
665
|
+
"tool_process",
|
|
666
|
+
"tool_output",
|
|
667
|
+
"final_answer_chunk",
|
|
668
|
+
"final_answer"
|
|
669
|
+
]),
|
|
670
|
+
delta: zod.z.string().optional(),
|
|
671
|
+
content: zod.z.string().optional(),
|
|
672
|
+
tool_name: zod.z.string().optional(),
|
|
673
|
+
tool_call_id: zod.z.string().optional(),
|
|
674
|
+
phase: ToolCallPhase.optional(),
|
|
675
|
+
status: Status.optional(),
|
|
676
|
+
args: zod.z.unknown().optional(),
|
|
677
|
+
output: zod.z.unknown().optional(),
|
|
678
|
+
duration_ms: zod.z.number().optional(),
|
|
679
|
+
meta: zod.z.record(zod.z.unknown()).optional()
|
|
680
|
+
}),
|
|
681
|
+
BaseEvent.extend({
|
|
682
|
+
type: zod.z.literal("requires_user_interaction"),
|
|
683
|
+
form: zod.z.any().optional(),
|
|
684
|
+
interaction_type: zod.z.string().optional(),
|
|
685
|
+
prompt: zod.z.string().optional()
|
|
686
|
+
}),
|
|
687
|
+
BaseEvent.extend({
|
|
688
|
+
type: zod.z.literal("audit_envelope"),
|
|
689
|
+
envelope: AuditEnvelope
|
|
690
|
+
}),
|
|
691
|
+
BaseEvent.extend({
|
|
692
|
+
type: zod.z.literal("final_answer"),
|
|
693
|
+
answer_id: zod.z.string(),
|
|
694
|
+
content: zod.z.string(),
|
|
695
|
+
is_complete: zod.z.boolean().default(true),
|
|
696
|
+
reasoning_details: ProviderReasoningDetailsPayload.optional(),
|
|
697
|
+
meta: zod.z.record(zod.z.any()).optional()
|
|
698
|
+
}),
|
|
699
|
+
BaseEvent.extend({
|
|
700
|
+
type: zod.z.literal("final_answer_chunk"),
|
|
701
|
+
answer_id: zod.z.string(),
|
|
702
|
+
seq: zod.z.number().int().nonnegative(),
|
|
703
|
+
content: zod.z.string(),
|
|
704
|
+
is_last: zod.z.boolean().optional()
|
|
705
|
+
}),
|
|
706
|
+
BaseEvent.extend({
|
|
707
|
+
type: zod.z.literal("history_summary"),
|
|
708
|
+
content: zod.z.string(),
|
|
709
|
+
replaced_message_ids: zod.z.array(zod.z.string()),
|
|
710
|
+
summary_seq: zod.z.number().int().nonnegative(),
|
|
711
|
+
original_message_count: zod.z.number().int().nonnegative().optional(),
|
|
712
|
+
compression_ratio: zod.z.number().min(0).max(1).optional(),
|
|
713
|
+
included_old_summary: zod.z.boolean().optional()
|
|
714
|
+
}),
|
|
715
|
+
BaseEvent.extend({
|
|
716
|
+
type: zod.z.literal("error"),
|
|
717
|
+
error: zod.z.string(),
|
|
718
|
+
details: zod.z.any().optional(),
|
|
719
|
+
error_code: zod.z.string().optional(),
|
|
720
|
+
retryable: zod.z.boolean().optional()
|
|
721
|
+
}),
|
|
722
|
+
BaseEvent.extend({
|
|
723
|
+
type: zod.z.literal("control"),
|
|
724
|
+
op: zod.z.enum(["truncate_after", "replace", "redo", "branch"]),
|
|
725
|
+
target_id: zod.z.string().optional(),
|
|
726
|
+
reason: zod.z.string().optional(),
|
|
727
|
+
meta: zod.z.any().optional()
|
|
728
|
+
}),
|
|
729
|
+
BaseEvent.extend({
|
|
730
|
+
type: zod.z.literal("stream_end"),
|
|
731
|
+
reason: zod.z.enum(["complete", "error", "interrupted", "timeout"]).optional(),
|
|
732
|
+
reason_message: zod.z.string().optional(),
|
|
733
|
+
stats: zod.z.object({
|
|
734
|
+
total_events: zod.z.number().optional(),
|
|
735
|
+
duration_ms: zod.z.number().optional(),
|
|
736
|
+
error_count: zod.z.number().optional()
|
|
737
|
+
}).optional()
|
|
738
|
+
})
|
|
739
|
+
]);
|
|
740
|
+
var validateRuntimeEvent = (event) => RuntimeEvent.safeParse(event);
|
|
741
|
+
var validateRuntimeEvents = (events) => zod.z.array(RuntimeEvent).safeParse(events);
|
|
742
|
+
var createUserInputEvent = (id, conversationId, turnId, content, options = {}) => ({
|
|
743
|
+
type: "user_input",
|
|
744
|
+
id,
|
|
745
|
+
conversation_id: conversationId,
|
|
746
|
+
turn_id: turnId,
|
|
747
|
+
timestamp: Date.now(),
|
|
748
|
+
version: 1,
|
|
749
|
+
content,
|
|
750
|
+
source: "user",
|
|
751
|
+
...options
|
|
752
|
+
});
|
|
753
|
+
var createThoughtEvent = (id, conversationId, turnId, content, options = {}) => ({
|
|
754
|
+
type: "thought",
|
|
755
|
+
id,
|
|
756
|
+
conversation_id: conversationId,
|
|
757
|
+
turn_id: turnId,
|
|
758
|
+
timestamp: Date.now(),
|
|
759
|
+
version: 1,
|
|
760
|
+
content,
|
|
761
|
+
is_complete: false,
|
|
762
|
+
...options
|
|
763
|
+
});
|
|
764
|
+
var createToolCallDecisionEvent = (id, conversationId, turnId, toolName, toolCallId, options = {}) => ({
|
|
765
|
+
type: "tool_call_decision",
|
|
766
|
+
id,
|
|
767
|
+
conversation_id: conversationId,
|
|
768
|
+
turn_id: turnId,
|
|
769
|
+
timestamp: Date.now(),
|
|
770
|
+
version: 1,
|
|
771
|
+
tool_name: toolName,
|
|
772
|
+
tool_call_id: toolCallId,
|
|
773
|
+
phase: "start",
|
|
774
|
+
status: "loading",
|
|
775
|
+
...options
|
|
776
|
+
});
|
|
777
|
+
var createToolProcessEvent = (id, conversationId, turnId, toolName, toolCallId, options = {}) => ({
|
|
778
|
+
type: "tool_process",
|
|
779
|
+
id,
|
|
780
|
+
conversation_id: conversationId,
|
|
781
|
+
turn_id: turnId,
|
|
782
|
+
timestamp: Date.now(),
|
|
783
|
+
version: 1,
|
|
784
|
+
tool_name: toolName,
|
|
785
|
+
tool_call_id: toolCallId,
|
|
786
|
+
phase: "start",
|
|
787
|
+
status: "loading",
|
|
788
|
+
...options
|
|
789
|
+
});
|
|
790
|
+
var createSubRunTraceEvent = (id, conversationId, turnId, parentToolCallId, subrunId, kind, options = {}) => ({
|
|
791
|
+
type: "subrun_trace",
|
|
792
|
+
id,
|
|
793
|
+
conversation_id: conversationId,
|
|
794
|
+
turn_id: turnId,
|
|
795
|
+
timestamp: Date.now(),
|
|
796
|
+
version: 1,
|
|
797
|
+
ephemeral: true,
|
|
798
|
+
parent_tool_call_id: parentToolCallId,
|
|
799
|
+
subrun_id: subrunId,
|
|
800
|
+
kind,
|
|
801
|
+
...options
|
|
802
|
+
});
|
|
803
|
+
var createToolOutputEvent = (id, conversationId, turnId, toolName, toolCallId, output, status = "success", options = {}) => ({
|
|
804
|
+
type: "tool_output",
|
|
805
|
+
id,
|
|
806
|
+
conversation_id: conversationId,
|
|
807
|
+
turn_id: turnId,
|
|
808
|
+
timestamp: Date.now(),
|
|
809
|
+
version: 1,
|
|
810
|
+
tool_name: toolName,
|
|
811
|
+
tool_call_id: toolCallId,
|
|
812
|
+
status,
|
|
813
|
+
output,
|
|
814
|
+
...options
|
|
815
|
+
});
|
|
816
|
+
var createTodoUpdatedEvent = (id, conversationId, turnId, todoListId, todoListVersion, items, options = {}) => ({
|
|
817
|
+
type: "todo_updated",
|
|
818
|
+
id,
|
|
819
|
+
conversation_id: conversationId,
|
|
820
|
+
turn_id: turnId,
|
|
821
|
+
timestamp: Date.now(),
|
|
822
|
+
version: 1,
|
|
823
|
+
todo_list_id: todoListId,
|
|
824
|
+
todo_list_version: todoListVersion,
|
|
825
|
+
items,
|
|
826
|
+
...options
|
|
827
|
+
});
|
|
828
|
+
var createFinalAnswerEvent = (id, conversationId, turnId, answerId, content, options = {}) => ({
|
|
829
|
+
type: "final_answer",
|
|
830
|
+
id,
|
|
831
|
+
conversation_id: conversationId,
|
|
832
|
+
turn_id: turnId,
|
|
833
|
+
timestamp: Date.now(),
|
|
834
|
+
version: 1,
|
|
835
|
+
answer_id: answerId,
|
|
836
|
+
content,
|
|
837
|
+
is_complete: true,
|
|
838
|
+
...options
|
|
839
|
+
});
|
|
840
|
+
var createAuditEnvelopeEvent = (id, conversationId, turnId, envelope, options = {}) => ({
|
|
841
|
+
type: "audit_envelope",
|
|
842
|
+
id,
|
|
843
|
+
conversation_id: conversationId,
|
|
844
|
+
turn_id: turnId,
|
|
845
|
+
timestamp: envelope.ts,
|
|
846
|
+
version: 1,
|
|
847
|
+
envelope,
|
|
848
|
+
metadata: {
|
|
849
|
+
audit_action: envelope.action,
|
|
850
|
+
run_context: {
|
|
851
|
+
runId: envelope.runId,
|
|
852
|
+
parentId: envelope.parentRunId,
|
|
853
|
+
traceId: envelope.scope?.traceId
|
|
854
|
+
}
|
|
855
|
+
},
|
|
856
|
+
...options
|
|
857
|
+
});
|
|
858
|
+
var createFinalAnswerChunkEvent = (id, conversationId, turnId, answerId, seq, content, options = {}) => ({
|
|
859
|
+
type: "final_answer_chunk",
|
|
860
|
+
id,
|
|
861
|
+
conversation_id: conversationId,
|
|
862
|
+
turn_id: turnId,
|
|
863
|
+
timestamp: Date.now(),
|
|
864
|
+
version: 1,
|
|
865
|
+
answer_id: answerId,
|
|
866
|
+
seq,
|
|
867
|
+
content,
|
|
868
|
+
...options
|
|
869
|
+
});
|
|
870
|
+
var createHistorySummaryEvent = (id, conversationId, turnId, content, replacedMessageIds, summarySeq, options = {}) => ({
|
|
871
|
+
type: "history_summary",
|
|
872
|
+
id,
|
|
873
|
+
conversation_id: conversationId,
|
|
874
|
+
turn_id: turnId,
|
|
875
|
+
timestamp: Date.now(),
|
|
876
|
+
version: 1,
|
|
877
|
+
content,
|
|
878
|
+
replaced_message_ids: replacedMessageIds,
|
|
879
|
+
summary_seq: summarySeq,
|
|
880
|
+
...options
|
|
881
|
+
});
|
|
882
|
+
var createErrorEvent = (id, conversationId, turnId, error, options = {}) => ({
|
|
883
|
+
type: "error",
|
|
884
|
+
id,
|
|
885
|
+
conversation_id: conversationId,
|
|
886
|
+
turn_id: turnId,
|
|
887
|
+
timestamp: Date.now(),
|
|
888
|
+
version: 1,
|
|
889
|
+
error,
|
|
890
|
+
...options
|
|
891
|
+
});
|
|
892
|
+
var createStreamEndEvent = (id, conversationId, turnId, options = {}) => ({
|
|
893
|
+
type: "stream_end",
|
|
894
|
+
id,
|
|
895
|
+
conversation_id: conversationId,
|
|
896
|
+
turn_id: turnId,
|
|
897
|
+
timestamp: Date.now(),
|
|
898
|
+
version: 1,
|
|
899
|
+
...options
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
// src/contracts/constants.ts
|
|
903
|
+
var DEFAULT_MAX_STEPS = 80;
|
|
904
|
+
var ExecutionTraceContext = zod.z.object({
|
|
905
|
+
execution_id: zod.z.string().describe("The unique identifier for a single, complete execution flow."),
|
|
906
|
+
trace_id: zod.z.string().optional().describe("An optional trace ID for correlating logs in an APM system.")
|
|
907
|
+
});
|
|
908
|
+
var EventEnvelopeSchema = zod.z.object({
|
|
909
|
+
seq: zod.z.number().int().nonnegative().describe("A monotonically increasing sequence number within a single execution."),
|
|
910
|
+
timestamp: zod.z.number().describe("The high-precision timestamp of when the event occurred."),
|
|
911
|
+
trace: ExecutionTraceContext,
|
|
912
|
+
source: zod.z.string().describe("The origin of the event, e.g., 'ai', 'tool:file_reader', 'system:summary'."),
|
|
913
|
+
payload: zod.z.unknown(),
|
|
914
|
+
render_hint: zod.z.object({
|
|
915
|
+
card: zod.z.enum(["normal", "collapsible", "none", "image", "interactive"]).optional().describe("Hint for how the UI card should be rendered."),
|
|
916
|
+
content: zod.z.enum(["markdown", "text", "json", "image_url", "code"]).default("text").describe("Hint for how the content itself should be interpreted.")
|
|
917
|
+
}).optional(),
|
|
918
|
+
run_location: zod.z.enum(["frontend", "backend"]).optional().describe("Specifies where a tool action should be or was executed.")
|
|
919
|
+
});
|
|
920
|
+
var EventEnvelope = EventEnvelopeSchema;
|
|
921
|
+
var BaseSSEEvent = zod.z.object({
|
|
922
|
+
id: zod.z.string(),
|
|
923
|
+
timestamp: zod.z.number(),
|
|
924
|
+
conversation_id: zod.z.string(),
|
|
925
|
+
turn_id: zod.z.string(),
|
|
926
|
+
metadata: zod.z.record(zod.z.unknown()).optional()
|
|
927
|
+
});
|
|
928
|
+
var SSEThoughtEvent = BaseSSEEvent.extend({
|
|
929
|
+
type: zod.z.literal("thought"),
|
|
930
|
+
thought_message_id: zod.z.string().optional(),
|
|
931
|
+
delta: zod.z.string().optional(),
|
|
932
|
+
content: zod.z.string().optional(),
|
|
933
|
+
is_complete: zod.z.boolean().default(false)
|
|
934
|
+
});
|
|
935
|
+
var SSEFinalAnswerChunkEvent = BaseSSEEvent.extend({
|
|
936
|
+
type: zod.z.literal("final_answer_chunk"),
|
|
937
|
+
answer_id: zod.z.string(),
|
|
938
|
+
seq: zod.z.number().int().nonnegative(),
|
|
939
|
+
chunk: zod.z.string(),
|
|
940
|
+
is_last: zod.z.boolean().optional()
|
|
941
|
+
});
|
|
942
|
+
var SSEFinalAnswerEvent = BaseSSEEvent.extend({
|
|
943
|
+
type: zod.z.literal("final_answer"),
|
|
944
|
+
answer_id: zod.z.string(),
|
|
945
|
+
content: zod.z.string(),
|
|
946
|
+
meta: zod.z.record(zod.z.any()).optional()
|
|
947
|
+
});
|
|
948
|
+
var SSEMarkdownChunkEvent = BaseSSEEvent.extend({
|
|
949
|
+
type: zod.z.literal("markdown_chunk"),
|
|
950
|
+
content_type: zod.z.enum(["text", "code", "table", "image"]).default("text"),
|
|
951
|
+
text: zod.z.string(),
|
|
952
|
+
seq: zod.z.number().optional()
|
|
953
|
+
});
|
|
954
|
+
var BaseSSEToolLifecycleEvent = BaseSSEEvent.extend({
|
|
955
|
+
tool_name: zod.z.string(),
|
|
956
|
+
tool_call_id: zod.z.string(),
|
|
957
|
+
phase: zod.z.enum(["start", "update", "complete", "error"]),
|
|
958
|
+
status: zod.z.enum(["loading", "success", "error"]),
|
|
959
|
+
args: zod.z.any().optional(),
|
|
960
|
+
payload: zod.z.any().optional(),
|
|
961
|
+
meta: zod.z.record(zod.z.any()).optional()
|
|
962
|
+
});
|
|
963
|
+
var SSEToolCallDecisionEvent = BaseSSEToolLifecycleEvent.extend({
|
|
964
|
+
type: zod.z.literal("tool_call_decision")
|
|
965
|
+
});
|
|
966
|
+
var SSEToolProcessEvent = BaseSSEToolLifecycleEvent.extend({
|
|
967
|
+
type: zod.z.literal("tool_process")
|
|
968
|
+
});
|
|
969
|
+
var SSEToolOutputEvent = BaseSSEEvent.extend({
|
|
970
|
+
type: zod.z.literal("tool_output"),
|
|
971
|
+
tool_name: zod.z.string(),
|
|
972
|
+
tool_call_id: zod.z.string(),
|
|
973
|
+
status: zod.z.enum(["success", "error"]),
|
|
974
|
+
output: zod.z.any().optional(),
|
|
975
|
+
payload: zod.z.record(zod.z.any()).optional(),
|
|
976
|
+
duration_ms: zod.z.number().optional()
|
|
977
|
+
});
|
|
978
|
+
var SSETodoUpdatedEvent = BaseSSEEvent.extend({
|
|
979
|
+
type: zod.z.literal("todo_updated"),
|
|
980
|
+
todo_list_id: zod.z.string(),
|
|
981
|
+
todo_list_version: zod.z.number().int().nonnegative(),
|
|
982
|
+
items: zod.z.array(zod.z.object({
|
|
983
|
+
id: zod.z.string(),
|
|
984
|
+
content: zod.z.string(),
|
|
985
|
+
status: zod.z.enum(["pending", "in_progress", "completed", "cancelled"])
|
|
986
|
+
}))
|
|
987
|
+
});
|
|
988
|
+
var SSESubRunTraceEvent = BaseSSEEvent.extend({
|
|
989
|
+
type: zod.z.literal("subrun_trace"),
|
|
990
|
+
parent_tool_call_id: zod.z.string(),
|
|
991
|
+
subrun_id: zod.z.string(),
|
|
992
|
+
subrun_parent_id: zod.z.string().optional(),
|
|
993
|
+
kind: zod.z.enum([
|
|
994
|
+
"thought_delta",
|
|
995
|
+
"thought_complete",
|
|
996
|
+
"tool_call_decision",
|
|
997
|
+
"tool_process",
|
|
998
|
+
"tool_output",
|
|
999
|
+
"final_answer_chunk",
|
|
1000
|
+
"final_answer"
|
|
1001
|
+
]),
|
|
1002
|
+
delta: zod.z.string().optional(),
|
|
1003
|
+
content: zod.z.string().optional(),
|
|
1004
|
+
tool_name: zod.z.string().optional(),
|
|
1005
|
+
tool_call_id: zod.z.string().optional(),
|
|
1006
|
+
phase: zod.z.enum(["start", "update", "complete", "error"]).optional(),
|
|
1007
|
+
status: zod.z.enum(["loading", "success", "error"]).optional(),
|
|
1008
|
+
args: zod.z.unknown().optional(),
|
|
1009
|
+
output: zod.z.unknown().optional(),
|
|
1010
|
+
duration_ms: zod.z.number().optional(),
|
|
1011
|
+
meta: zod.z.record(zod.z.unknown()).optional()
|
|
1012
|
+
});
|
|
1013
|
+
var SSERequiresUserInteractionEvent = BaseSSEEvent.extend({
|
|
1014
|
+
type: zod.z.literal("requires_user_interaction"),
|
|
1015
|
+
form: zod.z.any().optional(),
|
|
1016
|
+
interaction_type: zod.z.string().optional(),
|
|
1017
|
+
prompt: zod.z.string().optional()
|
|
1018
|
+
});
|
|
1019
|
+
var SSEErrorEvent = BaseSSEEvent.extend({
|
|
1020
|
+
type: zod.z.literal("error"),
|
|
1021
|
+
error: zod.z.string(),
|
|
1022
|
+
details: zod.z.any().optional(),
|
|
1023
|
+
error_code: zod.z.string().optional(),
|
|
1024
|
+
retryable: zod.z.boolean().optional()
|
|
1025
|
+
});
|
|
1026
|
+
var SSEStreamEndEvent = BaseSSEEvent.extend({
|
|
1027
|
+
type: zod.z.literal("stream_end"),
|
|
1028
|
+
reason: zod.z.enum(["complete", "error", "interrupted", "timeout"]).optional(),
|
|
1029
|
+
reason_message: zod.z.string().optional(),
|
|
1030
|
+
stats: zod.z.object({
|
|
1031
|
+
total_events: zod.z.number().optional(),
|
|
1032
|
+
duration_ms: zod.z.number().optional(),
|
|
1033
|
+
error_count: zod.z.number().optional(),
|
|
1034
|
+
benchmark: zod.z.record(zod.z.unknown()).optional()
|
|
1035
|
+
}).optional()
|
|
1036
|
+
});
|
|
1037
|
+
var SSEHistorySummaryEvent = BaseSSEEvent.extend({
|
|
1038
|
+
type: zod.z.literal("history_summary"),
|
|
1039
|
+
summary_id: zod.z.string(),
|
|
1040
|
+
content: zod.z.string(),
|
|
1041
|
+
original_message_count: zod.z.number().int().nonnegative(),
|
|
1042
|
+
summary_seq: zod.z.number().int().nonnegative()
|
|
1043
|
+
});
|
|
1044
|
+
var SSESummarizationStartEvent = BaseSSEEvent.extend({
|
|
1045
|
+
type: zod.z.literal("summarization_start"),
|
|
1046
|
+
originalMessages: zod.z.number().optional()
|
|
1047
|
+
});
|
|
1048
|
+
var SSESummarizationEndEvent = BaseSSEEvent.extend({
|
|
1049
|
+
type: zod.z.literal("summarization_end"),
|
|
1050
|
+
originalMessages: zod.z.number().optional(),
|
|
1051
|
+
compressedMessages: zod.z.number().optional(),
|
|
1052
|
+
compressionRatio: zod.z.string().optional(),
|
|
1053
|
+
timeSaved: zod.z.string().optional()
|
|
1054
|
+
});
|
|
1055
|
+
var SSESummarizationErrorEvent = BaseSSEEvent.extend({
|
|
1056
|
+
type: zod.z.literal("summarization_error"),
|
|
1057
|
+
error: zod.z.string()
|
|
1058
|
+
});
|
|
1059
|
+
var SSEEvent = zod.z.discriminatedUnion("type", [
|
|
1060
|
+
SSEThoughtEvent,
|
|
1061
|
+
SSEFinalAnswerChunkEvent,
|
|
1062
|
+
SSEFinalAnswerEvent,
|
|
1063
|
+
SSEMarkdownChunkEvent,
|
|
1064
|
+
SSEToolCallDecisionEvent,
|
|
1065
|
+
SSEToolProcessEvent,
|
|
1066
|
+
SSEToolOutputEvent,
|
|
1067
|
+
SSETodoUpdatedEvent,
|
|
1068
|
+
SSESubRunTraceEvent,
|
|
1069
|
+
SSERequiresUserInteractionEvent,
|
|
1070
|
+
SSEErrorEvent,
|
|
1071
|
+
SSEStreamEndEvent,
|
|
1072
|
+
SSEHistorySummaryEvent,
|
|
1073
|
+
SSESummarizationStartEvent,
|
|
1074
|
+
SSESummarizationEndEvent,
|
|
1075
|
+
SSESummarizationErrorEvent
|
|
1076
|
+
]);
|
|
1077
|
+
var validateSSEEvent = (event) => SSEEvent.safeParse(event);
|
|
1078
|
+
var createSSEThoughtEvent = (id, conversationId, turnId, options = {}) => ({
|
|
1079
|
+
type: "thought",
|
|
1080
|
+
id,
|
|
1081
|
+
timestamp: Date.now(),
|
|
1082
|
+
conversation_id: conversationId,
|
|
1083
|
+
turn_id: turnId,
|
|
1084
|
+
is_complete: false,
|
|
1085
|
+
...options
|
|
1086
|
+
});
|
|
1087
|
+
var createSSEFinalAnswerChunkEvent = (id, conversationId, turnId, answerId, seq, chunk, options = {}) => ({
|
|
1088
|
+
type: "final_answer_chunk",
|
|
1089
|
+
id,
|
|
1090
|
+
timestamp: Date.now(),
|
|
1091
|
+
conversation_id: conversationId,
|
|
1092
|
+
turn_id: turnId,
|
|
1093
|
+
answer_id: answerId,
|
|
1094
|
+
seq,
|
|
1095
|
+
chunk,
|
|
1096
|
+
...options
|
|
1097
|
+
});
|
|
1098
|
+
var createSSEFinalAnswerEvent = (id, conversationId, turnId, answerId, content, options = {}) => ({
|
|
1099
|
+
type: "final_answer",
|
|
1100
|
+
id,
|
|
1101
|
+
timestamp: Date.now(),
|
|
1102
|
+
conversation_id: conversationId,
|
|
1103
|
+
turn_id: turnId,
|
|
1104
|
+
answer_id: answerId,
|
|
1105
|
+
content,
|
|
1106
|
+
...options
|
|
1107
|
+
});
|
|
1108
|
+
var createSSEMarkdownChunkEvent = (id, conversationId, turnId, text, options = {}) => ({
|
|
1109
|
+
type: "markdown_chunk",
|
|
1110
|
+
id,
|
|
1111
|
+
timestamp: Date.now(),
|
|
1112
|
+
conversation_id: conversationId,
|
|
1113
|
+
turn_id: turnId,
|
|
1114
|
+
text,
|
|
1115
|
+
content_type: "text",
|
|
1116
|
+
...options
|
|
1117
|
+
});
|
|
1118
|
+
var createSSEToolCallDecisionEvent = (id, conversationId, turnId, toolName, toolCallId, phase, status, options = {}) => ({
|
|
1119
|
+
type: "tool_call_decision",
|
|
1120
|
+
id,
|
|
1121
|
+
timestamp: Date.now(),
|
|
1122
|
+
conversation_id: conversationId,
|
|
1123
|
+
turn_id: turnId,
|
|
1124
|
+
tool_name: toolName,
|
|
1125
|
+
tool_call_id: toolCallId,
|
|
1126
|
+
phase,
|
|
1127
|
+
status,
|
|
1128
|
+
...options
|
|
1129
|
+
});
|
|
1130
|
+
var createSSEToolProcessEvent = (id, conversationId, turnId, toolName, toolCallId, phase, status, options = {}) => ({
|
|
1131
|
+
type: "tool_process",
|
|
1132
|
+
id,
|
|
1133
|
+
timestamp: Date.now(),
|
|
1134
|
+
conversation_id: conversationId,
|
|
1135
|
+
turn_id: turnId,
|
|
1136
|
+
tool_name: toolName,
|
|
1137
|
+
tool_call_id: toolCallId,
|
|
1138
|
+
phase,
|
|
1139
|
+
status,
|
|
1140
|
+
...options
|
|
1141
|
+
});
|
|
1142
|
+
var createSSEToolOutputEvent = (id, conversationId, turnId, toolName, toolCallId, status, output, options = {}) => ({
|
|
1143
|
+
type: "tool_output",
|
|
1144
|
+
id,
|
|
1145
|
+
timestamp: Date.now(),
|
|
1146
|
+
conversation_id: conversationId,
|
|
1147
|
+
turn_id: turnId,
|
|
1148
|
+
tool_name: toolName,
|
|
1149
|
+
tool_call_id: toolCallId,
|
|
1150
|
+
status,
|
|
1151
|
+
output,
|
|
1152
|
+
...options
|
|
1153
|
+
});
|
|
1154
|
+
var createSSETodoUpdatedEvent = (id, conversationId, turnId, todoListId, todoListVersion, items, options = {}) => ({
|
|
1155
|
+
type: "todo_updated",
|
|
1156
|
+
id,
|
|
1157
|
+
timestamp: Date.now(),
|
|
1158
|
+
conversation_id: conversationId,
|
|
1159
|
+
turn_id: turnId,
|
|
1160
|
+
todo_list_id: todoListId,
|
|
1161
|
+
todo_list_version: todoListVersion,
|
|
1162
|
+
items,
|
|
1163
|
+
...options
|
|
1164
|
+
});
|
|
1165
|
+
var createSSESubRunTraceEvent = (id, conversationId, turnId, parentToolCallId, subrunId, kind, options = {}) => ({
|
|
1166
|
+
type: "subrun_trace",
|
|
1167
|
+
id,
|
|
1168
|
+
timestamp: Date.now(),
|
|
1169
|
+
conversation_id: conversationId,
|
|
1170
|
+
turn_id: turnId,
|
|
1171
|
+
parent_tool_call_id: parentToolCallId,
|
|
1172
|
+
subrun_id: subrunId,
|
|
1173
|
+
kind,
|
|
1174
|
+
...options
|
|
1175
|
+
});
|
|
1176
|
+
var createSSERequiresUserInteractionEvent = (id, conversationId, turnId, options = {}) => ({
|
|
1177
|
+
type: "requires_user_interaction",
|
|
1178
|
+
id,
|
|
1179
|
+
timestamp: Date.now(),
|
|
1180
|
+
conversation_id: conversationId,
|
|
1181
|
+
turn_id: turnId,
|
|
1182
|
+
...options
|
|
1183
|
+
});
|
|
1184
|
+
var createSSEErrorEvent = (id, conversationId, turnId, error, options = {}) => ({
|
|
1185
|
+
type: "error",
|
|
1186
|
+
id,
|
|
1187
|
+
timestamp: Date.now(),
|
|
1188
|
+
conversation_id: conversationId,
|
|
1189
|
+
turn_id: turnId,
|
|
1190
|
+
error,
|
|
1191
|
+
...options
|
|
1192
|
+
});
|
|
1193
|
+
var createSSEStreamEndEvent = (id, conversationId, turnId, options = {}) => ({
|
|
1194
|
+
type: "stream_end",
|
|
1195
|
+
id,
|
|
1196
|
+
timestamp: Date.now(),
|
|
1197
|
+
conversation_id: conversationId,
|
|
1198
|
+
turn_id: turnId,
|
|
1199
|
+
...options
|
|
1200
|
+
});
|
|
1201
|
+
var createSSEHistorySummaryEvent = (id, conversationId, turnId, summaryId, content, originalMessageCount, summarySeq, options = {}) => ({
|
|
1202
|
+
type: "history_summary",
|
|
1203
|
+
id,
|
|
1204
|
+
timestamp: Date.now(),
|
|
1205
|
+
conversation_id: conversationId,
|
|
1206
|
+
turn_id: turnId,
|
|
1207
|
+
summary_id: summaryId,
|
|
1208
|
+
content,
|
|
1209
|
+
original_message_count: originalMessageCount,
|
|
1210
|
+
summary_seq: summarySeq,
|
|
1211
|
+
...options
|
|
1212
|
+
});
|
|
1213
|
+
|
|
1214
|
+
exports.AUDIT_ACTIONS = AUDIT_ACTIONS;
|
|
1215
|
+
exports.AUDIT_DECISION_OUTCOMES = AUDIT_DECISION_OUTCOMES;
|
|
1216
|
+
exports.AgentCapability = AgentCapability;
|
|
1217
|
+
exports.AgentSpec = AgentSpec;
|
|
1218
|
+
exports.AgentSpecAuditConfig = AgentSpecAuditConfig;
|
|
1219
|
+
exports.AgentSpecBudgetPolicy = AgentSpecBudgetPolicy;
|
|
1220
|
+
exports.AgentSpecCheckpointPolicy = AgentSpecCheckpointPolicy;
|
|
1221
|
+
exports.AgentSpecContextPolicy = AgentSpecContextPolicy;
|
|
1222
|
+
exports.AgentSpecContextTracePolicy = AgentSpecContextTracePolicy;
|
|
1223
|
+
exports.AgentSpecMessageType = AgentSpecMessageType;
|
|
1224
|
+
exports.AgentSpecModelHints = AgentSpecModelHints;
|
|
1225
|
+
exports.AgentSpecMustKeepPolicy = AgentSpecMustKeepPolicy;
|
|
1226
|
+
exports.AgentSpecMustKeepTruncationRule = AgentSpecMustKeepTruncationRule;
|
|
1227
|
+
exports.AgentSpecProviderReplayPolicy = AgentSpecProviderReplayPolicy;
|
|
1228
|
+
exports.AgentSpecReasoningRetentionPolicy = AgentSpecReasoningRetentionPolicy;
|
|
1229
|
+
exports.AgentSpecSummarizationPolicy = AgentSpecSummarizationPolicy;
|
|
1230
|
+
exports.AgentSpecSystemReminderExtraRule = AgentSpecSystemReminderExtraRule;
|
|
1231
|
+
exports.AgentSpecSystemReminderPolicy = AgentSpecSystemReminderPolicy;
|
|
1232
|
+
exports.AgentSpecSystemReminderTrigger = AgentSpecSystemReminderTrigger;
|
|
1233
|
+
exports.AgentSpecTokenEstimationPolicy = AgentSpecTokenEstimationPolicy;
|
|
1234
|
+
exports.AgentSpecToolHistoryPolicy = AgentSpecToolHistoryPolicy;
|
|
1235
|
+
exports.AgentSpecToolObservationGovernancePolicy = AgentSpecToolObservationGovernancePolicy;
|
|
1236
|
+
exports.AgentSpecToolOutputPolicy = AgentSpecToolOutputPolicy;
|
|
1237
|
+
exports.AgentSpecWorkingMemoryPolicy = AgentSpecWorkingMemoryPolicy;
|
|
1238
|
+
exports.AgentTodoItem = AgentTodoItem;
|
|
1239
|
+
exports.AgentTodoStatus = AgentTodoStatus;
|
|
1240
|
+
exports.AiMessage = AiMessage;
|
|
1241
|
+
exports.AssistantMessage = AssistantMessage;
|
|
1242
|
+
exports.AuditActor = AuditActor;
|
|
1243
|
+
exports.AuditCostDelta = AuditCostDelta;
|
|
1244
|
+
exports.AuditDecision = AuditDecision;
|
|
1245
|
+
exports.AuditEnvelope = AuditEnvelope;
|
|
1246
|
+
exports.AuditEvidence = AuditEvidence;
|
|
1247
|
+
exports.AuditScope = AuditScope;
|
|
1248
|
+
exports.BaseEvent = BaseEvent;
|
|
1249
|
+
exports.BaseSSEEvent = BaseSSEEvent;
|
|
1250
|
+
exports.DEFAULT_MAX_STEPS = DEFAULT_MAX_STEPS;
|
|
1251
|
+
exports.EventEnvelope = EventEnvelope;
|
|
1252
|
+
exports.ExecutionTraceContext = ExecutionTraceContext;
|
|
1253
|
+
exports.HistorySummaryMeta = HistorySummaryMeta;
|
|
1254
|
+
exports.ImageInfoMeta = ImageInfoMeta;
|
|
1255
|
+
exports.PersistentMetadata = PersistentMetadata;
|
|
1256
|
+
exports.ProviderReasoningDetails = ProviderReasoningDetails;
|
|
1257
|
+
exports.ProviderReasoningDetailsPayload = ProviderReasoningDetailsPayload;
|
|
1258
|
+
exports.RuntimeEvent = RuntimeEvent;
|
|
1259
|
+
exports.SSEErrorEvent = SSEErrorEvent;
|
|
1260
|
+
exports.SSEEvent = SSEEvent;
|
|
1261
|
+
exports.SSEFinalAnswerChunkEvent = SSEFinalAnswerChunkEvent;
|
|
1262
|
+
exports.SSEFinalAnswerEvent = SSEFinalAnswerEvent;
|
|
1263
|
+
exports.SSEHistorySummaryEvent = SSEHistorySummaryEvent;
|
|
1264
|
+
exports.SSEMarkdownChunkEvent = SSEMarkdownChunkEvent;
|
|
1265
|
+
exports.SSERequiresUserInteractionEvent = SSERequiresUserInteractionEvent;
|
|
1266
|
+
exports.SSEStreamEndEvent = SSEStreamEndEvent;
|
|
1267
|
+
exports.SSESubRunTraceEvent = SSESubRunTraceEvent;
|
|
1268
|
+
exports.SSESummarizationEndEvent = SSESummarizationEndEvent;
|
|
1269
|
+
exports.SSESummarizationErrorEvent = SSESummarizationErrorEvent;
|
|
1270
|
+
exports.SSESummarizationStartEvent = SSESummarizationStartEvent;
|
|
1271
|
+
exports.SSEThoughtEvent = SSEThoughtEvent;
|
|
1272
|
+
exports.SSETodoUpdatedEvent = SSETodoUpdatedEvent;
|
|
1273
|
+
exports.SSEToolCallDecisionEvent = SSEToolCallDecisionEvent;
|
|
1274
|
+
exports.SSEToolOutputEvent = SSEToolOutputEvent;
|
|
1275
|
+
exports.SSEToolProcessEvent = SSEToolProcessEvent;
|
|
1276
|
+
exports.SYSTEM_REMINDER_BUILTIN_TRIGGER_KINDS = SYSTEM_REMINDER_BUILTIN_TRIGGER_KINDS;
|
|
1277
|
+
exports.Status = Status;
|
|
1278
|
+
exports.SystemMessage = SystemMessage;
|
|
1279
|
+
exports.TaskTrackingMeta = TaskTrackingMeta;
|
|
1280
|
+
exports.ToolBindingSpec = ToolBindingSpec;
|
|
1281
|
+
exports.ToolCallDecisionPayload = ToolCallDecisionPayload;
|
|
1282
|
+
exports.ToolCallExtraContent = ToolCallExtraContent;
|
|
1283
|
+
exports.ToolCallPhase = ToolCallPhase;
|
|
1284
|
+
exports.ToolCallWire = ToolCallWire;
|
|
1285
|
+
exports.ToolCallsMeta = ToolCallsMeta;
|
|
1286
|
+
exports.ToolMessage = ToolMessage;
|
|
1287
|
+
exports.ToolOutputMeta = ToolOutputMeta;
|
|
1288
|
+
exports.UserMessage = UserMessage;
|
|
1289
|
+
exports.createAssistantMessage = createAssistantMessage;
|
|
1290
|
+
exports.createAuditEnvelopeEvent = createAuditEnvelopeEvent;
|
|
1291
|
+
exports.createErrorEvent = createErrorEvent;
|
|
1292
|
+
exports.createFinalAnswerChunkEvent = createFinalAnswerChunkEvent;
|
|
1293
|
+
exports.createFinalAnswerEvent = createFinalAnswerEvent;
|
|
1294
|
+
exports.createHistorySummaryEvent = createHistorySummaryEvent;
|
|
1295
|
+
exports.createHistorySummaryMessage = createHistorySummaryMessage;
|
|
1296
|
+
exports.createSSEErrorEvent = createSSEErrorEvent;
|
|
1297
|
+
exports.createSSEFinalAnswerChunkEvent = createSSEFinalAnswerChunkEvent;
|
|
1298
|
+
exports.createSSEFinalAnswerEvent = createSSEFinalAnswerEvent;
|
|
1299
|
+
exports.createSSEHistorySummaryEvent = createSSEHistorySummaryEvent;
|
|
1300
|
+
exports.createSSEMarkdownChunkEvent = createSSEMarkdownChunkEvent;
|
|
1301
|
+
exports.createSSERequiresUserInteractionEvent = createSSERequiresUserInteractionEvent;
|
|
1302
|
+
exports.createSSEStreamEndEvent = createSSEStreamEndEvent;
|
|
1303
|
+
exports.createSSESubRunTraceEvent = createSSESubRunTraceEvent;
|
|
1304
|
+
exports.createSSEThoughtEvent = createSSEThoughtEvent;
|
|
1305
|
+
exports.createSSETodoUpdatedEvent = createSSETodoUpdatedEvent;
|
|
1306
|
+
exports.createSSEToolCallDecisionEvent = createSSEToolCallDecisionEvent;
|
|
1307
|
+
exports.createSSEToolOutputEvent = createSSEToolOutputEvent;
|
|
1308
|
+
exports.createSSEToolProcessEvent = createSSEToolProcessEvent;
|
|
1309
|
+
exports.createStreamEndEvent = createStreamEndEvent;
|
|
1310
|
+
exports.createSubRunTraceEvent = createSubRunTraceEvent;
|
|
1311
|
+
exports.createSystemMessage = createSystemMessage;
|
|
1312
|
+
exports.createThoughtEvent = createThoughtEvent;
|
|
1313
|
+
exports.createTodoUpdatedEvent = createTodoUpdatedEvent;
|
|
1314
|
+
exports.createToolCallDecisionEvent = createToolCallDecisionEvent;
|
|
1315
|
+
exports.createToolMessage = createToolMessage;
|
|
1316
|
+
exports.createToolOutputEvent = createToolOutputEvent;
|
|
1317
|
+
exports.createToolProcessEvent = createToolProcessEvent;
|
|
1318
|
+
exports.createUserInputEvent = createUserInputEvent;
|
|
1319
|
+
exports.createUserMessage = createUserMessage;
|
|
1320
|
+
exports.defineContextPolicy = defineContextPolicy;
|
|
1321
|
+
exports.hasToolCalls = hasToolCalls;
|
|
1322
|
+
exports.isAssistantMessage = isAssistantMessage;
|
|
1323
|
+
exports.isHistorySummaryMessage = isHistorySummaryMessage;
|
|
1324
|
+
exports.isSystemMessage = isSystemMessage;
|
|
1325
|
+
exports.isToolMessage = isToolMessage;
|
|
1326
|
+
exports.isUserMessage = isUserMessage;
|
|
1327
|
+
exports.validateAiMessage = validateAiMessage;
|
|
1328
|
+
exports.validateHistorySummaryMeta = validateHistorySummaryMeta;
|
|
1329
|
+
exports.validateRuntimeEvent = validateRuntimeEvent;
|
|
1330
|
+
exports.validateRuntimeEvents = validateRuntimeEvents;
|
|
1331
|
+
exports.validateSSEEvent = validateSSEEvent;
|
|
1332
|
+
//# sourceMappingURL=contracts.cjs.map
|
|
1333
|
+
//# sourceMappingURL=contracts.cjs.map
|