@nuvin/agent-core 0.0.0-rc.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/dist/VERSION +4 -0
- package/dist/agent/index.d.ts +19 -0
- package/dist/agent/index.js +1 -0
- package/dist/chunk-C6OLKGP6.js +1 -0
- package/dist/chunk-EJTTW4JQ.js +1 -0
- package/dist/chunk-NYZR4XKO.js +1 -0
- package/dist/chunk-U2BLX7Y5.js +1 -0
- package/dist/chunk-X7VAACWY.js +1 -0
- package/dist/formats/index.d.ts +25 -0
- package/dist/formats/index.js +1 -0
- package/dist/models/index.d.ts +344 -0
- package/dist/models/index.js +1 -0
- package/dist/provider-adapters-BHDQNPHa.d.ts +5 -0
- package/dist/shared/index.d.ts +17 -0
- package/dist/shared/index.js +1 -0
- package/dist/tools/index.d.ts +309 -0
- package/dist/tools/index.js +1 -0
- package/dist/types-BueDJWnx.d.ts +675 -0
- package/package.json +63 -0
|
@@ -0,0 +1,675 @@
|
|
|
1
|
+
type JsonPrimitive = boolean | number | string | null;
|
|
2
|
+
interface JsonObject {
|
|
3
|
+
[key: string]: JsonValue;
|
|
4
|
+
}
|
|
5
|
+
type JsonValue = JsonObject | JsonPrimitive | JsonValue[];
|
|
6
|
+
type JsonSchemaType = "array" | "boolean" | "number" | "object" | "string";
|
|
7
|
+
interface JsonSchemaString {
|
|
8
|
+
type: "string";
|
|
9
|
+
}
|
|
10
|
+
interface JsonSchemaNumber {
|
|
11
|
+
type: "number";
|
|
12
|
+
}
|
|
13
|
+
interface JsonSchemaBoolean {
|
|
14
|
+
type: "boolean";
|
|
15
|
+
}
|
|
16
|
+
interface JsonSchemaArray<TItem extends JsonSchema = JsonSchema> {
|
|
17
|
+
type: "array";
|
|
18
|
+
items: TItem;
|
|
19
|
+
}
|
|
20
|
+
interface JsonSchemaObject<TProperties extends Record<string, JsonSchema> = Record<string, JsonSchema>, TRequired extends readonly string[] | undefined = readonly string[] | undefined> {
|
|
21
|
+
type: "object";
|
|
22
|
+
properties: TProperties;
|
|
23
|
+
required?: TRequired;
|
|
24
|
+
}
|
|
25
|
+
type JsonSchema = JsonSchemaArray | JsonSchemaBoolean | JsonSchemaNumber | JsonSchemaObject | JsonSchemaString;
|
|
26
|
+
interface TextBlock {
|
|
27
|
+
type: "text";
|
|
28
|
+
text: string;
|
|
29
|
+
}
|
|
30
|
+
interface AnthropicThinkingBlock {
|
|
31
|
+
type: "anthropic_thinking";
|
|
32
|
+
thinking: string;
|
|
33
|
+
signature: string;
|
|
34
|
+
}
|
|
35
|
+
interface AnthropicRedactedThinkingBlock {
|
|
36
|
+
type: "anthropic_redacted_thinking";
|
|
37
|
+
data: string;
|
|
38
|
+
}
|
|
39
|
+
interface OpenAiReasoningSummaryText {
|
|
40
|
+
type: "summary_text";
|
|
41
|
+
text: string;
|
|
42
|
+
}
|
|
43
|
+
interface OpenAiReasoningBlock {
|
|
44
|
+
type: "openai_reasoning";
|
|
45
|
+
encryptedContent?: string;
|
|
46
|
+
id?: string;
|
|
47
|
+
summary: OpenAiReasoningSummaryText[];
|
|
48
|
+
text?: string;
|
|
49
|
+
}
|
|
50
|
+
interface ToolUseBlock {
|
|
51
|
+
type: "tool_use";
|
|
52
|
+
id: string;
|
|
53
|
+
name: string;
|
|
54
|
+
input: JsonValue;
|
|
55
|
+
}
|
|
56
|
+
interface ToolResultBlock {
|
|
57
|
+
type: "tool_result";
|
|
58
|
+
tool_use_id: string;
|
|
59
|
+
content: JsonValue | string;
|
|
60
|
+
is_error: boolean;
|
|
61
|
+
}
|
|
62
|
+
interface AnthropicThinkingWireBlock {
|
|
63
|
+
type: "thinking";
|
|
64
|
+
thinking: string;
|
|
65
|
+
signature: string;
|
|
66
|
+
}
|
|
67
|
+
interface AnthropicRedactedThinkingWireBlock {
|
|
68
|
+
type: "redacted_thinking";
|
|
69
|
+
data: string;
|
|
70
|
+
}
|
|
71
|
+
type AnthropicAssistantContentBlock = AnthropicRedactedThinkingWireBlock | AnthropicThinkingWireBlock | TextBlock | ToolUseBlock;
|
|
72
|
+
type ReasoningVisibility = "continuity-only" | "user-visible";
|
|
73
|
+
type AutoReasoningEffort = "low" | "medium" | "high";
|
|
74
|
+
interface AutoReasoningConfig {
|
|
75
|
+
effort: AutoReasoningEffort;
|
|
76
|
+
}
|
|
77
|
+
type AnthropicThinkingDisplay = "omitted" | "summarized";
|
|
78
|
+
type AnthropicThinkingEffort = "low" | "medium" | "high";
|
|
79
|
+
interface AnthropicEnabledThinkingConfig {
|
|
80
|
+
type: "enabled";
|
|
81
|
+
budgetTokens: number;
|
|
82
|
+
display?: AnthropicThinkingDisplay;
|
|
83
|
+
interleaved?: boolean;
|
|
84
|
+
}
|
|
85
|
+
interface AnthropicAdaptiveThinkingConfig {
|
|
86
|
+
type: "adaptive";
|
|
87
|
+
display?: AnthropicThinkingDisplay;
|
|
88
|
+
effort?: AnthropicThinkingEffort;
|
|
89
|
+
interleaved?: boolean;
|
|
90
|
+
}
|
|
91
|
+
interface AnthropicDisabledThinkingConfig {
|
|
92
|
+
type: "disabled";
|
|
93
|
+
}
|
|
94
|
+
type AnthropicThinkingConfig = AnthropicAdaptiveThinkingConfig | AnthropicDisabledThinkingConfig | AnthropicEnabledThinkingConfig;
|
|
95
|
+
type OpenAiReasoningEffort = "high" | "low" | "medium" | "minimal" | "none" | "xhigh";
|
|
96
|
+
type OpenAiReasoningSummary = "auto" | "concise" | "detailed";
|
|
97
|
+
interface OpenAiReasoningConfig {
|
|
98
|
+
effort?: OpenAiReasoningEffort;
|
|
99
|
+
includeEncryptedContent?: boolean;
|
|
100
|
+
summary?: OpenAiReasoningSummary;
|
|
101
|
+
}
|
|
102
|
+
interface ReasoningConfig {
|
|
103
|
+
auto?: AutoReasoningConfig;
|
|
104
|
+
anthropic?: AnthropicThinkingConfig;
|
|
105
|
+
openai?: OpenAiReasoningConfig;
|
|
106
|
+
visibility?: ReasoningVisibility;
|
|
107
|
+
}
|
|
108
|
+
interface MessageProviderState {
|
|
109
|
+
anthropicAssistantContent?: AnthropicAssistantContentBlock[];
|
|
110
|
+
openaiResponsesOutput?: OpenAiResponsesOutputItem[];
|
|
111
|
+
openaiResponsesResponseId?: string;
|
|
112
|
+
}
|
|
113
|
+
type AssistantContentBlock = AnthropicRedactedThinkingBlock | AnthropicThinkingBlock | OpenAiReasoningBlock | TextBlock | ToolUseBlock;
|
|
114
|
+
type ContentBlock = AssistantContentBlock | ToolResultBlock;
|
|
115
|
+
type ContentInput = ContentBlock[] | string | null | undefined;
|
|
116
|
+
type MessageRole = "assistant" | "user";
|
|
117
|
+
type SystemInput = TextBlock[] | string | null | undefined;
|
|
118
|
+
interface Message {
|
|
119
|
+
id?: string;
|
|
120
|
+
role: MessageRole;
|
|
121
|
+
content: ContentBlock[];
|
|
122
|
+
providerState?: MessageProviderState;
|
|
123
|
+
}
|
|
124
|
+
interface IdentifiedMessage extends Message {
|
|
125
|
+
id: string;
|
|
126
|
+
}
|
|
127
|
+
interface MessageInput {
|
|
128
|
+
id?: string;
|
|
129
|
+
role: MessageRole;
|
|
130
|
+
content?: ContentInput;
|
|
131
|
+
providerState?: MessageProviderState;
|
|
132
|
+
}
|
|
133
|
+
interface ToolSchema {
|
|
134
|
+
name: string;
|
|
135
|
+
description: string;
|
|
136
|
+
input_schema: JsonSchemaObject;
|
|
137
|
+
}
|
|
138
|
+
interface Usage {
|
|
139
|
+
input_tokens: number;
|
|
140
|
+
output_tokens: number;
|
|
141
|
+
reasoning_tokens?: number;
|
|
142
|
+
}
|
|
143
|
+
interface ModelRequest {
|
|
144
|
+
model: string;
|
|
145
|
+
max_tokens: number;
|
|
146
|
+
reasoning?: ReasoningConfig;
|
|
147
|
+
system: TextBlock[];
|
|
148
|
+
messages: Message[];
|
|
149
|
+
tools: ToolSchema[];
|
|
150
|
+
metadata: {
|
|
151
|
+
session_id: string;
|
|
152
|
+
turn_id: string;
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
interface ModelResponse {
|
|
156
|
+
id: string;
|
|
157
|
+
type: "message";
|
|
158
|
+
role: "assistant";
|
|
159
|
+
content: AssistantContentBlock[];
|
|
160
|
+
stop_reason: "end_turn" | "tool_use";
|
|
161
|
+
stop_sequence: null | string;
|
|
162
|
+
usage: Usage;
|
|
163
|
+
providerState?: MessageProviderState;
|
|
164
|
+
}
|
|
165
|
+
interface ChatRequest {
|
|
166
|
+
model: string;
|
|
167
|
+
maxTokens: number;
|
|
168
|
+
reasoning?: ReasoningConfig;
|
|
169
|
+
system: TextBlock[];
|
|
170
|
+
messages: Message[];
|
|
171
|
+
tools: ToolSchema[];
|
|
172
|
+
metadata: {
|
|
173
|
+
sessionId: string;
|
|
174
|
+
turnId: string;
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
interface ChatResponse {
|
|
178
|
+
id: string;
|
|
179
|
+
content: AssistantContentBlock[];
|
|
180
|
+
stopReason: "end_turn" | "tool_use";
|
|
181
|
+
usage: {
|
|
182
|
+
inputTokens: number;
|
|
183
|
+
outputTokens: number;
|
|
184
|
+
reasoningTokens?: number;
|
|
185
|
+
};
|
|
186
|
+
providerState?: MessageProviderState;
|
|
187
|
+
}
|
|
188
|
+
interface ContentDeltaChunk {
|
|
189
|
+
type: "content_delta";
|
|
190
|
+
index?: number;
|
|
191
|
+
text?: string;
|
|
192
|
+
}
|
|
193
|
+
interface ToolUseDeltaChunk {
|
|
194
|
+
type: "tool_use_delta";
|
|
195
|
+
id: string;
|
|
196
|
+
index: number;
|
|
197
|
+
inputDelta?: string;
|
|
198
|
+
name?: string;
|
|
199
|
+
}
|
|
200
|
+
interface AnthropicThinkingDeltaChunk {
|
|
201
|
+
type: "anthropic_thinking_delta";
|
|
202
|
+
index: number;
|
|
203
|
+
thinking: string;
|
|
204
|
+
}
|
|
205
|
+
interface AnthropicSignatureDeltaChunk {
|
|
206
|
+
type: "anthropic_signature_delta";
|
|
207
|
+
index: number;
|
|
208
|
+
signature: string;
|
|
209
|
+
}
|
|
210
|
+
interface OpenAiReasoningDeltaChunk {
|
|
211
|
+
type: "openai_reasoning_delta";
|
|
212
|
+
contentIndex: number;
|
|
213
|
+
delta: string;
|
|
214
|
+
itemId: string;
|
|
215
|
+
outputIndex: number;
|
|
216
|
+
}
|
|
217
|
+
interface OpenAiReasoningSummaryDeltaChunk {
|
|
218
|
+
type: "openai_reasoning_summary_delta";
|
|
219
|
+
delta: string;
|
|
220
|
+
itemId: string;
|
|
221
|
+
outputIndex: number;
|
|
222
|
+
summaryIndex: number;
|
|
223
|
+
}
|
|
224
|
+
interface ChatResponseChunk {
|
|
225
|
+
type: "anthropic_signature_delta" | "anthropic_thinking_delta" | "content_delta" | "done" | "openai_reasoning_delta" | "openai_reasoning_summary_delta" | "tool_use_delta";
|
|
226
|
+
contentIndex?: number;
|
|
227
|
+
delta?: string;
|
|
228
|
+
index?: number;
|
|
229
|
+
itemId?: string;
|
|
230
|
+
outputIndex?: number;
|
|
231
|
+
signature?: string;
|
|
232
|
+
summaryIndex?: number;
|
|
233
|
+
text?: string;
|
|
234
|
+
thinking?: string;
|
|
235
|
+
inputDelta?: string;
|
|
236
|
+
name?: string;
|
|
237
|
+
id?: string;
|
|
238
|
+
response?: ChatResponse;
|
|
239
|
+
}
|
|
240
|
+
interface ModelLimits {
|
|
241
|
+
contextWindow?: number;
|
|
242
|
+
maxOutput?: number;
|
|
243
|
+
}
|
|
244
|
+
interface ModelInfo {
|
|
245
|
+
id: string;
|
|
246
|
+
name: string;
|
|
247
|
+
limits?: ModelLimits;
|
|
248
|
+
supportedEndpoints?: string[];
|
|
249
|
+
}
|
|
250
|
+
interface ToolResultMeta {
|
|
251
|
+
truncated?: boolean;
|
|
252
|
+
originalBytes?: number;
|
|
253
|
+
transforms: string[];
|
|
254
|
+
}
|
|
255
|
+
interface ToolResultChunk {
|
|
256
|
+
output: string;
|
|
257
|
+
structured: JsonObject;
|
|
258
|
+
}
|
|
259
|
+
interface ToolOutputEnvelope {
|
|
260
|
+
output: string;
|
|
261
|
+
structured?: JsonObject;
|
|
262
|
+
}
|
|
263
|
+
interface ToolResult {
|
|
264
|
+
callId: string;
|
|
265
|
+
toolName: string;
|
|
266
|
+
status: "error" | "ok";
|
|
267
|
+
output: string;
|
|
268
|
+
structured: JsonObject;
|
|
269
|
+
chunks: ToolResultChunk[];
|
|
270
|
+
meta: ToolResultMeta;
|
|
271
|
+
}
|
|
272
|
+
interface TurnInput {
|
|
273
|
+
sessionId: string;
|
|
274
|
+
turnId: string;
|
|
275
|
+
streaming?: boolean;
|
|
276
|
+
signal?: AbortSignal;
|
|
277
|
+
system?: SystemInput;
|
|
278
|
+
messages?: MessageInput[];
|
|
279
|
+
message: MessageInput;
|
|
280
|
+
}
|
|
281
|
+
interface TurnState {
|
|
282
|
+
sessionId: string;
|
|
283
|
+
turnId: string;
|
|
284
|
+
system: TextBlock[];
|
|
285
|
+
messages: Message[];
|
|
286
|
+
lastResponse?: ChatResponse;
|
|
287
|
+
toolResults: ToolResult[];
|
|
288
|
+
finalMessage?: IdentifiedMessage;
|
|
289
|
+
}
|
|
290
|
+
type TurnResultStatus = "completed" | "aborted";
|
|
291
|
+
interface TurnResult {
|
|
292
|
+
status: TurnResultStatus;
|
|
293
|
+
finalMessage?: IdentifiedMessage;
|
|
294
|
+
state: TurnState;
|
|
295
|
+
}
|
|
296
|
+
type ProviderCredentialKind = "api-key" | "oauth-token" | "session-token";
|
|
297
|
+
interface ProviderCredential {
|
|
298
|
+
kind: ProviderCredentialKind;
|
|
299
|
+
value: string;
|
|
300
|
+
}
|
|
301
|
+
interface ProviderEndpoints {
|
|
302
|
+
api?: string;
|
|
303
|
+
originTracker?: string;
|
|
304
|
+
proxy?: string;
|
|
305
|
+
telemetry?: string;
|
|
306
|
+
}
|
|
307
|
+
interface ResolvedProviderSession {
|
|
308
|
+
credential: ProviderCredential;
|
|
309
|
+
endpoints?: ProviderEndpoints;
|
|
310
|
+
metadata?: Record<string, string>;
|
|
311
|
+
}
|
|
312
|
+
interface ProviderSessionResolver {
|
|
313
|
+
resolve(signal?: AbortSignal): Promise<ResolvedProviderSession>;
|
|
314
|
+
}
|
|
315
|
+
interface PrepareRequestInput {
|
|
316
|
+
sessionId: string;
|
|
317
|
+
turnId: string;
|
|
318
|
+
reasoning?: ReasoningConfig;
|
|
319
|
+
system: TextBlock[];
|
|
320
|
+
messages: Message[];
|
|
321
|
+
tools: ToolSchema[];
|
|
322
|
+
maxTokens?: number;
|
|
323
|
+
}
|
|
324
|
+
interface PreparedRequest {
|
|
325
|
+
request: ModelRequest;
|
|
326
|
+
session?: ResolvedProviderSession;
|
|
327
|
+
}
|
|
328
|
+
type ProviderRequestMutator = (preparedRequest: PreparedRequest) => PreparedRequest | Promise<PreparedRequest>;
|
|
329
|
+
interface ChatModel {
|
|
330
|
+
prepareRequest(request: PrepareRequestInput): ModelRequest;
|
|
331
|
+
complete(request: ModelRequest): Promise<ModelResponse>;
|
|
332
|
+
}
|
|
333
|
+
interface ModelExecutionOptions {
|
|
334
|
+
signal?: AbortSignal;
|
|
335
|
+
}
|
|
336
|
+
interface EngineChatModel {
|
|
337
|
+
model: string;
|
|
338
|
+
maxTokens?: number;
|
|
339
|
+
complete(request: ChatRequest, options?: ModelExecutionOptions): Promise<ChatResponse>;
|
|
340
|
+
stream?(request: ChatRequest, options?: ModelExecutionOptions): AsyncIterable<ChatResponseChunk>;
|
|
341
|
+
getModels?(signal?: AbortSignal): Promise<ModelInfo[]>;
|
|
342
|
+
}
|
|
343
|
+
interface BaseChatModelOptions {
|
|
344
|
+
model: string;
|
|
345
|
+
maxTokens?: number;
|
|
346
|
+
reasoning?: ReasoningConfig;
|
|
347
|
+
providerSessionResolver?: ProviderSessionResolver;
|
|
348
|
+
requestMutators?: ProviderRequestMutator[];
|
|
349
|
+
}
|
|
350
|
+
interface AgentEventContext {
|
|
351
|
+
sessionId: string;
|
|
352
|
+
turnId: string;
|
|
353
|
+
state: TurnState;
|
|
354
|
+
}
|
|
355
|
+
interface ToolExecutionContext extends AgentEventContext {
|
|
356
|
+
signal: AbortSignal;
|
|
357
|
+
toolCallId?: string;
|
|
358
|
+
}
|
|
359
|
+
interface ToolRuntimeStartedEvent {
|
|
360
|
+
type: "tool_started";
|
|
361
|
+
toolCall: ToolUseBlock;
|
|
362
|
+
}
|
|
363
|
+
interface ToolRuntimeOutputChunkEvent {
|
|
364
|
+
type: "tool_output_chunk";
|
|
365
|
+
toolCall: ToolUseBlock;
|
|
366
|
+
chunk: ToolResultChunk;
|
|
367
|
+
}
|
|
368
|
+
interface ToolRuntimeCompletedEvent {
|
|
369
|
+
type: "tool_completed";
|
|
370
|
+
toolCall: ToolUseBlock;
|
|
371
|
+
result: ToolResult;
|
|
372
|
+
}
|
|
373
|
+
interface ToolRuntimeRejectedEvent {
|
|
374
|
+
type: "tool_rejected";
|
|
375
|
+
toolCall: ToolUseBlock;
|
|
376
|
+
result: ToolResult;
|
|
377
|
+
}
|
|
378
|
+
type ToolRuntimeEvent = ToolRuntimeOutputChunkEvent | ToolRuntimeCompletedEvent | ToolRuntimeRejectedEvent | ToolRuntimeStartedEvent;
|
|
379
|
+
interface AgentUserMessageEvent {
|
|
380
|
+
type: "user_message";
|
|
381
|
+
message: Message;
|
|
382
|
+
}
|
|
383
|
+
interface AgentModelRequestEvent {
|
|
384
|
+
type: "model_request";
|
|
385
|
+
request: ChatRequest;
|
|
386
|
+
}
|
|
387
|
+
interface AgentModelResponseEvent {
|
|
388
|
+
type: "model_response";
|
|
389
|
+
response: ChatResponse;
|
|
390
|
+
}
|
|
391
|
+
interface AgentAssistantMessageEvent {
|
|
392
|
+
type: "assistant_message";
|
|
393
|
+
message: IdentifiedMessage;
|
|
394
|
+
}
|
|
395
|
+
interface AgentAssistantChunkEvent {
|
|
396
|
+
type: "assistant_chunk";
|
|
397
|
+
index: number;
|
|
398
|
+
messageId: string;
|
|
399
|
+
chunk: ContentDeltaChunk;
|
|
400
|
+
}
|
|
401
|
+
interface AgentToolUseMessageEvent {
|
|
402
|
+
type: "tool_use_message";
|
|
403
|
+
message: IdentifiedMessage;
|
|
404
|
+
}
|
|
405
|
+
interface AgentToolUseChunkEvent {
|
|
406
|
+
type: "tool_use_chunk";
|
|
407
|
+
index: number;
|
|
408
|
+
messageId: string;
|
|
409
|
+
chunk: ToolUseDeltaChunk;
|
|
410
|
+
}
|
|
411
|
+
interface AgentReasoningMessageEvent {
|
|
412
|
+
type: "reasoning_message";
|
|
413
|
+
message: IdentifiedMessage;
|
|
414
|
+
}
|
|
415
|
+
interface AgentReasoningChunkEvent {
|
|
416
|
+
type: "reasoning_chunk";
|
|
417
|
+
index: number;
|
|
418
|
+
messageId: string;
|
|
419
|
+
chunk: AnthropicThinkingDeltaChunk | OpenAiReasoningDeltaChunk | OpenAiReasoningSummaryDeltaChunk;
|
|
420
|
+
text: string;
|
|
421
|
+
}
|
|
422
|
+
interface AgentToolCallEvent {
|
|
423
|
+
type: "tool_call";
|
|
424
|
+
toolCall: ToolUseBlock;
|
|
425
|
+
}
|
|
426
|
+
interface AgentToolResultEvent {
|
|
427
|
+
type: "tool_result";
|
|
428
|
+
result: ToolResult;
|
|
429
|
+
}
|
|
430
|
+
interface AgentToolResultMessageEvent {
|
|
431
|
+
type: "tool_result_message";
|
|
432
|
+
message: Message;
|
|
433
|
+
}
|
|
434
|
+
interface AgentFinalMessageEvent {
|
|
435
|
+
type: "final_message";
|
|
436
|
+
message: IdentifiedMessage;
|
|
437
|
+
}
|
|
438
|
+
interface AgentTurnCompleteEvent {
|
|
439
|
+
type: "turn_complete";
|
|
440
|
+
state: TurnState;
|
|
441
|
+
}
|
|
442
|
+
type AgentLifecycleEvent = AgentAssistantChunkEvent | AgentAssistantMessageEvent | AgentFinalMessageEvent | AgentModelRequestEvent | AgentModelResponseEvent | AgentReasoningChunkEvent | AgentReasoningMessageEvent | AgentToolCallEvent | AgentToolUseChunkEvent | AgentToolUseMessageEvent | AgentToolResultEvent | AgentToolResultMessageEvent | AgentTurnCompleteEvent | AgentUserMessageEvent;
|
|
443
|
+
type AgentEvent = AgentLifecycleEvent | ToolRuntimeEvent;
|
|
444
|
+
type ToolRuntimeDispatchDecision = {
|
|
445
|
+
action: "reject";
|
|
446
|
+
reason?: string;
|
|
447
|
+
} | {
|
|
448
|
+
action: "run";
|
|
449
|
+
};
|
|
450
|
+
type ToolRuntimeToolCallHandler = (toolCall: ToolUseBlock, ctx: ToolExecutionContext) => Promise<ToolRuntimeDispatchDecision | undefined> | ToolRuntimeDispatchDecision | undefined;
|
|
451
|
+
type ToolRuntimeEventHandler = (event: ToolRuntimeEvent, ctx: ToolExecutionContext) => Promise<void> | void;
|
|
452
|
+
type AgentEventHandler = (event: AgentEvent, ctx: AgentEventContext) => Promise<void> | void;
|
|
453
|
+
interface ToolRuntime {
|
|
454
|
+
listToolSchemas(): ToolSchema[];
|
|
455
|
+
executeCalls(toolCalls: ToolUseBlock[], ctx: ToolExecutionContext): Promise<ToolResult[]>;
|
|
456
|
+
execute(toolCall: ToolUseBlock, ctx: ToolExecutionContext): Promise<ToolResult>;
|
|
457
|
+
}
|
|
458
|
+
type InferJsonSchema<TSchema extends JsonSchema> = TSchema extends JsonSchemaString ? string : TSchema extends JsonSchemaNumber ? number : TSchema extends JsonSchemaBoolean ? boolean : TSchema extends JsonSchemaArray<infer TItem> ? InferJsonSchema<TItem>[] : TSchema extends JsonSchemaObject<infer TProperties, infer TRequired> ? Expand<RequiredProperties<TProperties, TRequired> & OptionalProperties<TProperties, TRequired>> : never;
|
|
459
|
+
type Expand<TValue> = TValue extends infer TObject ? {
|
|
460
|
+
[TKey in keyof TObject]: TObject[TKey];
|
|
461
|
+
} : never;
|
|
462
|
+
type RequiredKeyUnion<TRequired extends readonly string[] | undefined> = TRequired extends readonly string[] ? TRequired[number] : never;
|
|
463
|
+
type OptionalKeyUnion<TProperties extends Record<string, JsonSchema>, TRequired extends readonly string[] | undefined> = Exclude<keyof TProperties, RequiredKeyUnion<TRequired>>;
|
|
464
|
+
type RequiredProperties<TProperties extends Record<string, JsonSchema>, TRequired extends readonly string[] | undefined> = {
|
|
465
|
+
[TKey in Extract<keyof TProperties, RequiredKeyUnion<TRequired>>]: InferJsonSchema<TProperties[TKey]>;
|
|
466
|
+
};
|
|
467
|
+
type OptionalProperties<TProperties extends Record<string, JsonSchema>, TRequired extends readonly string[] | undefined> = {
|
|
468
|
+
[TKey in OptionalKeyUnion<TProperties, TRequired>]?: InferJsonSchema<TProperties[TKey]>;
|
|
469
|
+
};
|
|
470
|
+
type ToolOutputValue = JsonValue | ToolOutputEnvelope;
|
|
471
|
+
type ToolGenerator<TYield extends ToolOutputValue = ToolOutputValue, TReturn extends ToolOutputValue | undefined = ToolOutputValue | undefined> = AsyncGenerator<TYield, TReturn, void>;
|
|
472
|
+
interface ToolDefinition<TInput extends JsonObject = JsonObject, TYield extends ToolOutputValue = ToolOutputValue, TReturn extends ToolOutputValue | undefined = ToolOutputValue | undefined, TSchema extends JsonSchemaObject = JsonSchemaObject> {
|
|
473
|
+
name: string;
|
|
474
|
+
description: string;
|
|
475
|
+
inputSchema: TSchema;
|
|
476
|
+
execute(input: TInput, ctx: ToolExecutionContext): ToolGenerator<TYield, TReturn>;
|
|
477
|
+
}
|
|
478
|
+
type AnyToolDefinition = ToolDefinition<JsonObject, ToolOutputValue, ToolOutputValue | undefined, JsonSchemaObject>;
|
|
479
|
+
type Stage = "afterModelResponse" | "afterToolResult" | "afterTurnComplete" | "beforeAssistantAppend" | "beforeFinalOutput" | "beforeModelRequest" | "beforeToolExecution" | "beforeToolResultAppend" | "onUserMessage";
|
|
480
|
+
interface PayloadByStage {
|
|
481
|
+
onUserMessage: Message;
|
|
482
|
+
beforeModelRequest: ChatRequest;
|
|
483
|
+
afterModelResponse: ChatResponse;
|
|
484
|
+
beforeToolExecution: ToolUseBlock;
|
|
485
|
+
afterToolResult: ToolResult;
|
|
486
|
+
beforeAssistantAppend: Message;
|
|
487
|
+
beforeFinalOutput: Message;
|
|
488
|
+
beforeToolResultAppend: Message;
|
|
489
|
+
afterTurnComplete: TurnState;
|
|
490
|
+
}
|
|
491
|
+
interface ExtensionContext {
|
|
492
|
+
state: TurnState;
|
|
493
|
+
}
|
|
494
|
+
type Transformer<S extends Stage> = (payload: PayloadByStage[S], ctx: ExtensionContext) => PayloadByStage[S] | Promise<PayloadByStage[S]>;
|
|
495
|
+
type Observer<S extends Stage> = (payload: PayloadByStage[S], ctx: ExtensionContext) => Promise<void> | void;
|
|
496
|
+
interface TransformerExtensionRegistration<S extends Stage = Stage> {
|
|
497
|
+
id: string;
|
|
498
|
+
stage: S;
|
|
499
|
+
kind: "transformer";
|
|
500
|
+
order: number;
|
|
501
|
+
enabled: boolean;
|
|
502
|
+
run: Transformer<S>;
|
|
503
|
+
}
|
|
504
|
+
interface ObserverExtensionRegistration<S extends Stage = Stage> {
|
|
505
|
+
id: string;
|
|
506
|
+
stage: S;
|
|
507
|
+
kind: "observer";
|
|
508
|
+
order: number;
|
|
509
|
+
enabled: boolean;
|
|
510
|
+
run: Observer<S>;
|
|
511
|
+
}
|
|
512
|
+
type ExtensionRegistration<S extends Stage = Stage> = ObserverExtensionRegistration<S> | TransformerExtensionRegistration<S>;
|
|
513
|
+
type AnyExtensionRegistration = {
|
|
514
|
+
[S in Stage]: ExtensionRegistration<S>;
|
|
515
|
+
}[Stage];
|
|
516
|
+
interface ExtensionRegistry {
|
|
517
|
+
register(extension: AnyExtensionRegistration): void;
|
|
518
|
+
runTransformers<S extends Stage>(stage: S, payload: PayloadByStage[S], ctx: ExtensionContext): Promise<PayloadByStage[S]>;
|
|
519
|
+
runObservers<S extends Stage>(stage: S, payload: PayloadByStage[S], ctx: ExtensionContext): Promise<void>;
|
|
520
|
+
}
|
|
521
|
+
interface RunTurnDeps {
|
|
522
|
+
registry: ExtensionRegistry;
|
|
523
|
+
chatModel: EngineChatModel;
|
|
524
|
+
toolRuntime: ToolRuntime;
|
|
525
|
+
onEvent?: AgentEventHandler;
|
|
526
|
+
}
|
|
527
|
+
type AgentInput = MessageInput | string;
|
|
528
|
+
interface AgentSendOptions {
|
|
529
|
+
streaming?: boolean;
|
|
530
|
+
signal?: AbortSignal;
|
|
531
|
+
}
|
|
532
|
+
interface AgentOptions {
|
|
533
|
+
sessionId?: string;
|
|
534
|
+
systemPrompt?: string;
|
|
535
|
+
messages?: MessageInput[];
|
|
536
|
+
message?: AgentInput;
|
|
537
|
+
onEvent?: AgentEventHandler;
|
|
538
|
+
onToolCall?: ToolRuntimeToolCallHandler;
|
|
539
|
+
registry?: ExtensionRegistry;
|
|
540
|
+
extensions?: AnyExtensionRegistration[];
|
|
541
|
+
chatModel?: EngineChatModel;
|
|
542
|
+
tools?: AnyToolDefinition[];
|
|
543
|
+
}
|
|
544
|
+
interface AgentDefinitionFactoryContext {
|
|
545
|
+
agentId: string;
|
|
546
|
+
parentSessionId?: string;
|
|
547
|
+
runId?: string;
|
|
548
|
+
toolCallId?: string;
|
|
549
|
+
}
|
|
550
|
+
interface AgentDefinition {
|
|
551
|
+
id: string;
|
|
552
|
+
description?: string;
|
|
553
|
+
enabled?: boolean;
|
|
554
|
+
allowedChildAgentIds?: string[];
|
|
555
|
+
createOptions(ctx?: AgentDefinitionFactoryContext): AgentOptions;
|
|
556
|
+
}
|
|
557
|
+
type ManagedRunStatus = "aborted" | "completed" | "failed" | "idle" | "running";
|
|
558
|
+
interface ManagedRunError {
|
|
559
|
+
message: string;
|
|
560
|
+
}
|
|
561
|
+
interface ManagedAgentRun {
|
|
562
|
+
runId: string;
|
|
563
|
+
agentId: string;
|
|
564
|
+
sessionId: string;
|
|
565
|
+
status: ManagedRunStatus;
|
|
566
|
+
depth: number;
|
|
567
|
+
parentRunId?: string;
|
|
568
|
+
originToolCallId?: string;
|
|
569
|
+
result?: TurnResult;
|
|
570
|
+
error?: ManagedRunError;
|
|
571
|
+
}
|
|
572
|
+
interface ManagedAgentRunHandle {
|
|
573
|
+
readonly runId: string;
|
|
574
|
+
readonly agentId: string;
|
|
575
|
+
readonly sessionId: string;
|
|
576
|
+
send(input: AgentInput, options?: AgentSendOptions): Promise<TurnResult>;
|
|
577
|
+
snapshot(): ManagedAgentRun;
|
|
578
|
+
wait(signal?: AbortSignal): Promise<ManagedAgentRun>;
|
|
579
|
+
}
|
|
580
|
+
interface ManagedRunEvent {
|
|
581
|
+
runId: string;
|
|
582
|
+
agentId: string;
|
|
583
|
+
sessionId: string;
|
|
584
|
+
parentRunId?: string;
|
|
585
|
+
originToolCallId?: string;
|
|
586
|
+
event: AgentEvent;
|
|
587
|
+
}
|
|
588
|
+
type ManagedRunEventHandler = (event: ManagedRunEvent) => Promise<void> | void;
|
|
589
|
+
interface RuntimeManagerOptions {
|
|
590
|
+
onEvent?: ManagedRunEventHandler;
|
|
591
|
+
}
|
|
592
|
+
interface CreateManagedRunInput {
|
|
593
|
+
agentId: string;
|
|
594
|
+
parentRunId?: string;
|
|
595
|
+
originToolCallId?: string;
|
|
596
|
+
}
|
|
597
|
+
interface CompileRequestInput {
|
|
598
|
+
sessionId: string;
|
|
599
|
+
turnId: string;
|
|
600
|
+
reasoning?: ReasoningConfig;
|
|
601
|
+
system?: SystemInput;
|
|
602
|
+
messages: MessageInput[];
|
|
603
|
+
tools?: ToolSchema[];
|
|
604
|
+
model?: string;
|
|
605
|
+
max_tokens?: number;
|
|
606
|
+
}
|
|
607
|
+
interface OpenAiInputText {
|
|
608
|
+
type: "input_text";
|
|
609
|
+
text: string;
|
|
610
|
+
}
|
|
611
|
+
interface OpenAiInputMessage {
|
|
612
|
+
type: "message";
|
|
613
|
+
role: MessageRole;
|
|
614
|
+
content: OpenAiInputText[];
|
|
615
|
+
}
|
|
616
|
+
interface OpenAiFunctionCall {
|
|
617
|
+
type: "function_call";
|
|
618
|
+
call_id: string;
|
|
619
|
+
name: string;
|
|
620
|
+
arguments: string;
|
|
621
|
+
}
|
|
622
|
+
interface OpenAiFunctionCallOutput {
|
|
623
|
+
type: "function_call_output";
|
|
624
|
+
call_id: string;
|
|
625
|
+
output: string;
|
|
626
|
+
}
|
|
627
|
+
interface OpenAiOutputTextPart {
|
|
628
|
+
type: "output_text";
|
|
629
|
+
text: string;
|
|
630
|
+
}
|
|
631
|
+
interface OpenAiRefusalPart {
|
|
632
|
+
type: "refusal";
|
|
633
|
+
refusal: string;
|
|
634
|
+
}
|
|
635
|
+
interface OpenAiOutputMessage {
|
|
636
|
+
type: "message";
|
|
637
|
+
content?: Array<OpenAiOutputTextPart | OpenAiRefusalPart>;
|
|
638
|
+
role?: string;
|
|
639
|
+
status?: string;
|
|
640
|
+
}
|
|
641
|
+
interface OpenAiReasoningOutputItem {
|
|
642
|
+
type: "reasoning";
|
|
643
|
+
content?: Array<{
|
|
644
|
+
text?: string;
|
|
645
|
+
type?: string;
|
|
646
|
+
}>;
|
|
647
|
+
encrypted_content?: string;
|
|
648
|
+
id?: string;
|
|
649
|
+
status?: string;
|
|
650
|
+
summary?: OpenAiReasoningSummaryText[];
|
|
651
|
+
text?: string;
|
|
652
|
+
}
|
|
653
|
+
type OpenAiResponsesOutputItem = JsonObject | OpenAiFunctionCall | OpenAiOutputMessage | OpenAiReasoningOutputItem;
|
|
654
|
+
interface OpenAiResponsesReasoningParam {
|
|
655
|
+
effort?: OpenAiReasoningEffort;
|
|
656
|
+
generate_summary?: OpenAiReasoningSummary;
|
|
657
|
+
summary?: OpenAiReasoningSummary;
|
|
658
|
+
}
|
|
659
|
+
interface OpenAiFunctionTool {
|
|
660
|
+
type: "function";
|
|
661
|
+
name: string;
|
|
662
|
+
description: string;
|
|
663
|
+
parameters: JsonSchemaObject;
|
|
664
|
+
}
|
|
665
|
+
interface OpenAiResponsesRequest {
|
|
666
|
+
include?: string[];
|
|
667
|
+
model: string;
|
|
668
|
+
instructions: string;
|
|
669
|
+
input: Array<OpenAiFunctionCall | OpenAiFunctionCallOutput | OpenAiInputMessage | OpenAiResponsesOutputItem>;
|
|
670
|
+
max_output_tokens?: number;
|
|
671
|
+
reasoning?: OpenAiResponsesReasoningParam;
|
|
672
|
+
tools: OpenAiFunctionTool[];
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
export type { AnthropicThinkingWireBlock as $, AgentOptions as A, BaseChatModelOptions as B, ContentInput as C, AutoReasoningEffort as D, ExtensionRegistry as E, AnthropicThinkingConfig as F, OpenAiReasoningConfig as G, JsonObject as H, JsonValue as I, JsonPrimitive as J, JsonSchemaType as K, JsonSchemaString as L, Message as M, JsonSchemaNumber as N, OpenAiResponsesRequest as O, ProviderSessionResolver as P, JsonSchemaBoolean as Q, RunTurnDeps as R, SystemInput as S, TurnResult as T, JsonSchemaArray as U, JsonSchemaObject as V, JsonSchema as W, AnthropicThinkingBlock as X, AnthropicRedactedThinkingBlock as Y, OpenAiReasoningSummaryText as Z, OpenAiReasoningBlock as _, AgentInput as a, Stage as a$, AnthropicRedactedThinkingWireBlock as a0, AnthropicAssistantContentBlock as a1, ReasoningVisibility as a2, AutoReasoningConfig as a3, AnthropicThinkingDisplay as a4, AnthropicThinkingEffort as a5, AnthropicEnabledThinkingConfig as a6, AnthropicAdaptiveThinkingConfig as a7, AnthropicDisabledThinkingConfig as a8, OpenAiReasoningEffort as a9, ToolRuntimeEvent as aA, AgentUserMessageEvent as aB, AgentModelRequestEvent as aC, AgentModelResponseEvent as aD, AgentAssistantMessageEvent as aE, AgentAssistantChunkEvent as aF, AgentToolUseMessageEvent as aG, AgentToolUseChunkEvent as aH, AgentReasoningMessageEvent as aI, AgentReasoningChunkEvent as aJ, AgentToolCallEvent as aK, AgentToolResultEvent as aL, AgentToolResultMessageEvent as aM, AgentFinalMessageEvent as aN, AgentTurnCompleteEvent as aO, AgentLifecycleEvent as aP, AgentEvent as aQ, ToolRuntimeDispatchDecision as aR, ToolRuntimeToolCallHandler as aS, ToolRuntimeEventHandler as aT, AgentEventHandler as aU, ToolRuntime as aV, InferJsonSchema as aW, ToolOutputValue as aX, ToolGenerator as aY, ToolDefinition as aZ, AnyToolDefinition as a_, OpenAiReasoningSummary as aa, MessageProviderState as ab, AssistantContentBlock as ac, MessageRole as ad, IdentifiedMessage as ae, ToolSchema as af, Usage as ag, ContentDeltaChunk as ah, ToolUseDeltaChunk as ai, AnthropicThinkingDeltaChunk as aj, AnthropicSignatureDeltaChunk as ak, OpenAiReasoningDeltaChunk as al, OpenAiReasoningSummaryDeltaChunk as am, ModelLimits as an, ToolResultMeta as ao, ToolResultChunk as ap, ToolOutputEnvelope as aq, TurnResultStatus as ar, PrepareRequestInput as as, ChatModel as at, AgentEventContext as au, ToolExecutionContext as av, ToolRuntimeStartedEvent as aw, ToolRuntimeOutputChunkEvent as ax, ToolRuntimeCompletedEvent as ay, ToolRuntimeRejectedEvent as az, AgentSendOptions as b, PayloadByStage as b0, ExtensionContext as b1, Transformer as b2, Observer as b3, TransformerExtensionRegistration as b4, ObserverExtensionRegistration as b5, ExtensionRegistration as b6, AnyExtensionRegistration as b7, AgentDefinitionFactoryContext as b8, AgentDefinition as b9, ManagedRunStatus as ba, ManagedRunError as bb, ManagedAgentRun as bc, ManagedAgentRunHandle as bd, ManagedRunEvent as be, ManagedRunEventHandler as bf, RuntimeManagerOptions as bg, CreateManagedRunInput as bh, OpenAiInputText as bi, OpenAiInputMessage as bj, OpenAiFunctionCall as bk, OpenAiFunctionCallOutput as bl, OpenAiOutputTextPart as bm, OpenAiRefusalPart as bn, OpenAiOutputMessage as bo, OpenAiReasoningOutputItem as bp, OpenAiResponsesOutputItem as bq, OpenAiResponsesReasoningParam as br, OpenAiFunctionTool as bs, TurnInput as c, TurnState as d, TextBlock as e, ContentBlock as f, MessageInput as g, CompileRequestInput as h, ModelRequest as i, ChatRequest as j, ModelResponse as k, ChatResponse as l, ToolUseBlock as m, ToolResultBlock as n, ToolResult as o, ResolvedProviderSession as p, ProviderRequestMutator as q, PreparedRequest as r, ProviderCredential as s, EngineChatModel as t, ReasoningConfig as u, ChatResponseChunk as v, ModelExecutionOptions as w, ModelInfo as x, ProviderCredentialKind as y, ProviderEndpoints as z };
|