@makaio/adapter-openai-node 1.0.0-dev-1779051654000
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/LICENSE +21 -0
- package/README.md +186 -0
- package/descriptor.json +21 -0
- package/dist/index.d.mts +2118 -0
- package/dist/index.mjs +1790 -0
- package/package.json +70 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,2118 @@
|
|
|
1
|
+
import { AIAdapter, AIAdapterConfig, AIReasoningLevel, BaseAgentConnectorConfig, ConformanceTestConfig, CreateConformanceTestConfigOptions, MessageHandle, MessageResult, NormalizedCallUsage, ProceduralConnectorTurn, ReasoningLevelMap, UserMessageQueue, WireSessionSubjects } from "@makaio/framework/adapters";
|
|
2
|
+
import OpenAI from "openai";
|
|
3
|
+
import { BaseStreamAgent, BaseStreamConnector, BaseStreamSession, StreamAdapterSubjectSpec, StreamSessionTurnState, ToolCall } from "@makaio/framework/adapters/stream-session";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import * as _$_makaio_core0 from "@makaio/framework/core";
|
|
6
|
+
import { ExtractSubjectPayload, ExtractSubjectResponse, ScopedSubjectDefinition } from "@makaio/framework/core";
|
|
7
|
+
import * as _$_makaio_bus_core0 from "@makaio/framework/bus";
|
|
8
|
+
import { ScopedBus } from "@makaio/framework/bus";
|
|
9
|
+
import { ChatCompletionChunk } from "openai/resources";
|
|
10
|
+
import { ChatCompletionTool } from "openai/resources/index.js";
|
|
11
|
+
import { DiscoveredAIModel, SessionMessageBlock, ToolListItem } from "@makaio/framework/contracts";
|
|
12
|
+
|
|
13
|
+
//#region src/schemas.d.ts
|
|
14
|
+
/**
|
|
15
|
+
* Zod schema for OpenAI Node provider-specific configuration.
|
|
16
|
+
*
|
|
17
|
+
* Used for:
|
|
18
|
+
* 1. Type-safe config resolution
|
|
19
|
+
* 2. Serialization to JSON Schema for web-ui form generation
|
|
20
|
+
* 3. Runtime validation
|
|
21
|
+
*/
|
|
22
|
+
declare const OpenAINodeProviderConfigSchema: z.ZodObject<{
|
|
23
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
/**
|
|
26
|
+
* Provider settings input type (pre-validation, fields optional).
|
|
27
|
+
*/
|
|
28
|
+
type OpenAINodeProviderSettings = z.input<typeof OpenAINodeProviderConfigSchema>;
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/namespaces/schemas/message.d.ts
|
|
31
|
+
/**
|
|
32
|
+
* Schema for message complete event.
|
|
33
|
+
* Emitted when a full assistant message has been assembled from streaming chunks.
|
|
34
|
+
* Extends the base schema with OpenAI-specific `finish_reason` values.
|
|
35
|
+
*/
|
|
36
|
+
declare const MessageCompleteEventSchema$1: z.ZodObject<{
|
|
37
|
+
eventType: z.ZodLiteral<"message_complete">;
|
|
38
|
+
content: z.ZodNullable<z.ZodString>;
|
|
39
|
+
reasoning: z.ZodOptional<z.ZodString>;
|
|
40
|
+
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
41
|
+
id: z.ZodString;
|
|
42
|
+
type: z.ZodLiteral<"function">;
|
|
43
|
+
function: z.ZodObject<{
|
|
44
|
+
name: z.ZodString;
|
|
45
|
+
arguments: z.ZodString;
|
|
46
|
+
}, z.core.$strip>;
|
|
47
|
+
}, z.core.$strip>>>;
|
|
48
|
+
finish_reason: z.ZodNullable<z.ZodEnum<{
|
|
49
|
+
tool_calls: "tool_calls";
|
|
50
|
+
stop: "stop";
|
|
51
|
+
length: "length";
|
|
52
|
+
content_filter: "content_filter";
|
|
53
|
+
function_call: "function_call";
|
|
54
|
+
}>>;
|
|
55
|
+
}, z.core.$strip>;
|
|
56
|
+
type MessageCompleteEvent = z.infer<typeof MessageCompleteEventSchema$1>;
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/namespaces/index.d.ts
|
|
59
|
+
/**
|
|
60
|
+
* Discriminated union of all SDK event types.
|
|
61
|
+
* Uses discriminatedUnion for type-safe event routing based on eventType.
|
|
62
|
+
*/
|
|
63
|
+
declare const SdkEventMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
64
|
+
eventType: z.ZodLiteral<"chunk">;
|
|
65
|
+
id: z.ZodString;
|
|
66
|
+
choices: z.ZodArray<z.ZodObject<{
|
|
67
|
+
delta: z.ZodObject<{
|
|
68
|
+
content: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
69
|
+
role: z.ZodOptional<z.ZodEnum<{
|
|
70
|
+
assistant: "assistant";
|
|
71
|
+
user: "user";
|
|
72
|
+
system: "system";
|
|
73
|
+
tool: "tool";
|
|
74
|
+
developer: "developer";
|
|
75
|
+
}>>;
|
|
76
|
+
refusal: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
77
|
+
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
78
|
+
index: z.ZodNumber;
|
|
79
|
+
id: z.ZodOptional<z.ZodString>;
|
|
80
|
+
type: z.ZodOptional<z.ZodLiteral<"function">>;
|
|
81
|
+
function: z.ZodOptional<z.ZodObject<{
|
|
82
|
+
name: z.ZodOptional<z.ZodString>;
|
|
83
|
+
arguments: z.ZodOptional<z.ZodString>;
|
|
84
|
+
}, z.core.$strip>>;
|
|
85
|
+
}, z.core.$strip>>>;
|
|
86
|
+
}, z.core.$strip>;
|
|
87
|
+
index: z.ZodNumber;
|
|
88
|
+
finish_reason: z.ZodNullable<z.ZodEnum<{
|
|
89
|
+
tool_calls: "tool_calls";
|
|
90
|
+
stop: "stop";
|
|
91
|
+
length: "length";
|
|
92
|
+
content_filter: "content_filter";
|
|
93
|
+
function_call: "function_call";
|
|
94
|
+
}>>;
|
|
95
|
+
logprobs: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
|
|
96
|
+
}, z.core.$strip>>;
|
|
97
|
+
created: z.ZodNumber;
|
|
98
|
+
model: z.ZodString;
|
|
99
|
+
object: z.ZodLiteral<"chat.completion.chunk">;
|
|
100
|
+
service_tier: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
101
|
+
default: "default";
|
|
102
|
+
auto: "auto";
|
|
103
|
+
flex: "flex";
|
|
104
|
+
scale: "scale";
|
|
105
|
+
priority: "priority";
|
|
106
|
+
}>>>;
|
|
107
|
+
system_fingerprint: z.ZodOptional<z.ZodString>;
|
|
108
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
109
|
+
eventType: z.ZodLiteral<"usage">;
|
|
110
|
+
prompt_tokens: z.ZodNumber;
|
|
111
|
+
completion_tokens: z.ZodNumber;
|
|
112
|
+
total_tokens: z.ZodNumber;
|
|
113
|
+
prompt_tokens_details: z.ZodOptional<z.ZodObject<{
|
|
114
|
+
audio_tokens: z.ZodOptional<z.ZodNumber>;
|
|
115
|
+
cached_tokens: z.ZodOptional<z.ZodNumber>;
|
|
116
|
+
}, z.core.$strip>>;
|
|
117
|
+
completion_tokens_details: z.ZodOptional<z.ZodObject<{
|
|
118
|
+
accepted_prediction_tokens: z.ZodOptional<z.ZodNumber>;
|
|
119
|
+
audio_tokens: z.ZodOptional<z.ZodNumber>;
|
|
120
|
+
reasoning_tokens: z.ZodOptional<z.ZodNumber>;
|
|
121
|
+
rejected_prediction_tokens: z.ZodOptional<z.ZodNumber>;
|
|
122
|
+
}, z.core.$strip>>;
|
|
123
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
124
|
+
eventType: z.ZodLiteral<"tool_calls">;
|
|
125
|
+
toolCalls: z.ZodArray<z.ZodObject<{
|
|
126
|
+
id: z.ZodString;
|
|
127
|
+
type: z.ZodLiteral<"function">;
|
|
128
|
+
function: z.ZodObject<{
|
|
129
|
+
name: z.ZodString;
|
|
130
|
+
arguments: z.ZodString;
|
|
131
|
+
}, z.core.$strip>;
|
|
132
|
+
}, z.core.$strip>>;
|
|
133
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
134
|
+
eventType: z.ZodLiteral<"message_complete">;
|
|
135
|
+
content: z.ZodNullable<z.ZodString>;
|
|
136
|
+
reasoning: z.ZodOptional<z.ZodString>;
|
|
137
|
+
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
138
|
+
id: z.ZodString;
|
|
139
|
+
type: z.ZodLiteral<"function">;
|
|
140
|
+
function: z.ZodObject<{
|
|
141
|
+
name: z.ZodString;
|
|
142
|
+
arguments: z.ZodString;
|
|
143
|
+
}, z.core.$strip>;
|
|
144
|
+
}, z.core.$strip>>>;
|
|
145
|
+
finish_reason: z.ZodNullable<z.ZodEnum<{
|
|
146
|
+
tool_calls: "tool_calls";
|
|
147
|
+
stop: "stop";
|
|
148
|
+
length: "length";
|
|
149
|
+
content_filter: "content_filter";
|
|
150
|
+
function_call: "function_call";
|
|
151
|
+
}>>;
|
|
152
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
153
|
+
eventType: z.ZodLiteral<"reasoning_delta">;
|
|
154
|
+
content: z.ZodString;
|
|
155
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
156
|
+
eventType: z.ZodLiteral<"reasoning_complete">;
|
|
157
|
+
content: z.ZodString;
|
|
158
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
159
|
+
eventType: z.ZodLiteral<"agent_started">;
|
|
160
|
+
model: z.ZodOptional<z.ZodString>;
|
|
161
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
162
|
+
eventType: z.ZodLiteral<"agent_complete">;
|
|
163
|
+
message: z.ZodOptional<z.ZodString>;
|
|
164
|
+
error: z.ZodOptional<z.ZodString>;
|
|
165
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
166
|
+
eventType: z.ZodLiteral<"error">;
|
|
167
|
+
message: z.ZodString;
|
|
168
|
+
code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
169
|
+
type: z.ZodOptional<z.ZodString>;
|
|
170
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
171
|
+
eventType: z.ZodLiteral<"tool_started">;
|
|
172
|
+
toolName: z.ZodString;
|
|
173
|
+
toolCallId: z.ZodString;
|
|
174
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
175
|
+
eventType: z.ZodLiteral<"tool_completed">;
|
|
176
|
+
toolName: z.ZodString;
|
|
177
|
+
toolCallId: z.ZodString;
|
|
178
|
+
result: z.ZodString;
|
|
179
|
+
success: z.ZodBoolean;
|
|
180
|
+
}, z.core.$strip>], "eventType">;
|
|
181
|
+
type SdkEventMessage = z.infer<typeof SdkEventMessageSchema>;
|
|
182
|
+
/**
|
|
183
|
+
* Envelope schema for sdk.event catch-all subject.
|
|
184
|
+
* Wraps the discriminated union in an envelope for proper TypeScript narrowing at emit time.
|
|
185
|
+
* Pattern matches codex-mcp's \{ id, msg \} envelope.
|
|
186
|
+
*/
|
|
187
|
+
declare const SdkEventSchema: z.ZodObject<{
|
|
188
|
+
event: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
189
|
+
eventType: z.ZodLiteral<"chunk">;
|
|
190
|
+
id: z.ZodString;
|
|
191
|
+
choices: z.ZodArray<z.ZodObject<{
|
|
192
|
+
delta: z.ZodObject<{
|
|
193
|
+
content: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
194
|
+
role: z.ZodOptional<z.ZodEnum<{
|
|
195
|
+
assistant: "assistant";
|
|
196
|
+
user: "user";
|
|
197
|
+
system: "system";
|
|
198
|
+
tool: "tool";
|
|
199
|
+
developer: "developer";
|
|
200
|
+
}>>;
|
|
201
|
+
refusal: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
202
|
+
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
203
|
+
index: z.ZodNumber;
|
|
204
|
+
id: z.ZodOptional<z.ZodString>;
|
|
205
|
+
type: z.ZodOptional<z.ZodLiteral<"function">>;
|
|
206
|
+
function: z.ZodOptional<z.ZodObject<{
|
|
207
|
+
name: z.ZodOptional<z.ZodString>;
|
|
208
|
+
arguments: z.ZodOptional<z.ZodString>;
|
|
209
|
+
}, z.core.$strip>>;
|
|
210
|
+
}, z.core.$strip>>>;
|
|
211
|
+
}, z.core.$strip>;
|
|
212
|
+
index: z.ZodNumber;
|
|
213
|
+
finish_reason: z.ZodNullable<z.ZodEnum<{
|
|
214
|
+
tool_calls: "tool_calls";
|
|
215
|
+
stop: "stop";
|
|
216
|
+
length: "length";
|
|
217
|
+
content_filter: "content_filter";
|
|
218
|
+
function_call: "function_call";
|
|
219
|
+
}>>;
|
|
220
|
+
logprobs: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
|
|
221
|
+
}, z.core.$strip>>;
|
|
222
|
+
created: z.ZodNumber;
|
|
223
|
+
model: z.ZodString;
|
|
224
|
+
object: z.ZodLiteral<"chat.completion.chunk">;
|
|
225
|
+
service_tier: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
226
|
+
default: "default";
|
|
227
|
+
auto: "auto";
|
|
228
|
+
flex: "flex";
|
|
229
|
+
scale: "scale";
|
|
230
|
+
priority: "priority";
|
|
231
|
+
}>>>;
|
|
232
|
+
system_fingerprint: z.ZodOptional<z.ZodString>;
|
|
233
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
234
|
+
eventType: z.ZodLiteral<"usage">;
|
|
235
|
+
prompt_tokens: z.ZodNumber;
|
|
236
|
+
completion_tokens: z.ZodNumber;
|
|
237
|
+
total_tokens: z.ZodNumber;
|
|
238
|
+
prompt_tokens_details: z.ZodOptional<z.ZodObject<{
|
|
239
|
+
audio_tokens: z.ZodOptional<z.ZodNumber>;
|
|
240
|
+
cached_tokens: z.ZodOptional<z.ZodNumber>;
|
|
241
|
+
}, z.core.$strip>>;
|
|
242
|
+
completion_tokens_details: z.ZodOptional<z.ZodObject<{
|
|
243
|
+
accepted_prediction_tokens: z.ZodOptional<z.ZodNumber>;
|
|
244
|
+
audio_tokens: z.ZodOptional<z.ZodNumber>;
|
|
245
|
+
reasoning_tokens: z.ZodOptional<z.ZodNumber>;
|
|
246
|
+
rejected_prediction_tokens: z.ZodOptional<z.ZodNumber>;
|
|
247
|
+
}, z.core.$strip>>;
|
|
248
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
249
|
+
eventType: z.ZodLiteral<"tool_calls">;
|
|
250
|
+
toolCalls: z.ZodArray<z.ZodObject<{
|
|
251
|
+
id: z.ZodString;
|
|
252
|
+
type: z.ZodLiteral<"function">;
|
|
253
|
+
function: z.ZodObject<{
|
|
254
|
+
name: z.ZodString;
|
|
255
|
+
arguments: z.ZodString;
|
|
256
|
+
}, z.core.$strip>;
|
|
257
|
+
}, z.core.$strip>>;
|
|
258
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
259
|
+
eventType: z.ZodLiteral<"message_complete">;
|
|
260
|
+
content: z.ZodNullable<z.ZodString>;
|
|
261
|
+
reasoning: z.ZodOptional<z.ZodString>;
|
|
262
|
+
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
263
|
+
id: z.ZodString;
|
|
264
|
+
type: z.ZodLiteral<"function">;
|
|
265
|
+
function: z.ZodObject<{
|
|
266
|
+
name: z.ZodString;
|
|
267
|
+
arguments: z.ZodString;
|
|
268
|
+
}, z.core.$strip>;
|
|
269
|
+
}, z.core.$strip>>>;
|
|
270
|
+
finish_reason: z.ZodNullable<z.ZodEnum<{
|
|
271
|
+
tool_calls: "tool_calls";
|
|
272
|
+
stop: "stop";
|
|
273
|
+
length: "length";
|
|
274
|
+
content_filter: "content_filter";
|
|
275
|
+
function_call: "function_call";
|
|
276
|
+
}>>;
|
|
277
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
278
|
+
eventType: z.ZodLiteral<"reasoning_delta">;
|
|
279
|
+
content: z.ZodString;
|
|
280
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
281
|
+
eventType: z.ZodLiteral<"reasoning_complete">;
|
|
282
|
+
content: z.ZodString;
|
|
283
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
284
|
+
eventType: z.ZodLiteral<"agent_started">;
|
|
285
|
+
model: z.ZodOptional<z.ZodString>;
|
|
286
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
287
|
+
eventType: z.ZodLiteral<"agent_complete">;
|
|
288
|
+
message: z.ZodOptional<z.ZodString>;
|
|
289
|
+
error: z.ZodOptional<z.ZodString>;
|
|
290
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
291
|
+
eventType: z.ZodLiteral<"error">;
|
|
292
|
+
message: z.ZodString;
|
|
293
|
+
code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
294
|
+
type: z.ZodOptional<z.ZodString>;
|
|
295
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
296
|
+
eventType: z.ZodLiteral<"tool_started">;
|
|
297
|
+
toolName: z.ZodString;
|
|
298
|
+
toolCallId: z.ZodString;
|
|
299
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
300
|
+
eventType: z.ZodLiteral<"tool_completed">;
|
|
301
|
+
toolName: z.ZodString;
|
|
302
|
+
toolCallId: z.ZodString;
|
|
303
|
+
result: z.ZodString;
|
|
304
|
+
success: z.ZodBoolean;
|
|
305
|
+
}, z.core.$strip>], "eventType">;
|
|
306
|
+
adapterName: z.ZodOptional<z.ZodString>;
|
|
307
|
+
agentId: z.ZodOptional<z.ZodString>;
|
|
308
|
+
adapterId: z.ZodOptional<z.ZodString>;
|
|
309
|
+
adapterSessionId: z.ZodOptional<z.ZodString>;
|
|
310
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
311
|
+
}, z.core.$strip>;
|
|
312
|
+
type SdkEvent = z.infer<typeof SdkEventSchema>;
|
|
313
|
+
/**
|
|
314
|
+
* OpenAI Node Adapter Namespace with semantic subjects.
|
|
315
|
+
*
|
|
316
|
+
* Provides typed subjects for:
|
|
317
|
+
* - sdk.event: Catch-all for raw SDK events (for observability/debugging)
|
|
318
|
+
* - tool_approval: RPC for tool execution approval
|
|
319
|
+
* - Semantic subjects: Individual typed events for agent layer processing
|
|
320
|
+
*/
|
|
321
|
+
declare const OpenAINodeConnectorNamespace: _$_makaio_bus_core0.BusNamespace<"adapter:openai-node", _$_makaio_core0.SubjectRecordFromSchemaRecord<{
|
|
322
|
+
'sdk.raw': z.ZodCustom<ChatCompletionChunk, ChatCompletionChunk>;
|
|
323
|
+
'sdk.event': z.ZodObject<{
|
|
324
|
+
event: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
325
|
+
eventType: z.ZodLiteral<"chunk">;
|
|
326
|
+
id: z.ZodString;
|
|
327
|
+
choices: z.ZodArray<z.ZodObject<{
|
|
328
|
+
delta: z.ZodObject<{
|
|
329
|
+
content: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
330
|
+
role: z.ZodOptional<z.ZodEnum<{
|
|
331
|
+
assistant: "assistant";
|
|
332
|
+
user: "user";
|
|
333
|
+
system: "system";
|
|
334
|
+
tool: "tool";
|
|
335
|
+
developer: "developer";
|
|
336
|
+
}>>;
|
|
337
|
+
refusal: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
338
|
+
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
339
|
+
index: z.ZodNumber;
|
|
340
|
+
id: z.ZodOptional<z.ZodString>;
|
|
341
|
+
type: z.ZodOptional<z.ZodLiteral<"function">>;
|
|
342
|
+
function: z.ZodOptional<z.ZodObject<{
|
|
343
|
+
name: z.ZodOptional<z.ZodString>;
|
|
344
|
+
arguments: z.ZodOptional<z.ZodString>;
|
|
345
|
+
}, z.core.$strip>>;
|
|
346
|
+
}, z.core.$strip>>>;
|
|
347
|
+
}, z.core.$strip>;
|
|
348
|
+
index: z.ZodNumber;
|
|
349
|
+
finish_reason: z.ZodNullable<z.ZodEnum<{
|
|
350
|
+
tool_calls: "tool_calls";
|
|
351
|
+
stop: "stop";
|
|
352
|
+
length: "length";
|
|
353
|
+
content_filter: "content_filter";
|
|
354
|
+
function_call: "function_call";
|
|
355
|
+
}>>;
|
|
356
|
+
logprobs: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
|
|
357
|
+
}, z.core.$strip>>;
|
|
358
|
+
created: z.ZodNumber;
|
|
359
|
+
model: z.ZodString;
|
|
360
|
+
object: z.ZodLiteral<"chat.completion.chunk">;
|
|
361
|
+
service_tier: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
362
|
+
default: "default";
|
|
363
|
+
auto: "auto";
|
|
364
|
+
flex: "flex";
|
|
365
|
+
scale: "scale";
|
|
366
|
+
priority: "priority";
|
|
367
|
+
}>>>;
|
|
368
|
+
system_fingerprint: z.ZodOptional<z.ZodString>;
|
|
369
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
370
|
+
eventType: z.ZodLiteral<"usage">;
|
|
371
|
+
prompt_tokens: z.ZodNumber;
|
|
372
|
+
completion_tokens: z.ZodNumber;
|
|
373
|
+
total_tokens: z.ZodNumber;
|
|
374
|
+
prompt_tokens_details: z.ZodOptional<z.ZodObject<{
|
|
375
|
+
audio_tokens: z.ZodOptional<z.ZodNumber>;
|
|
376
|
+
cached_tokens: z.ZodOptional<z.ZodNumber>;
|
|
377
|
+
}, z.core.$strip>>;
|
|
378
|
+
completion_tokens_details: z.ZodOptional<z.ZodObject<{
|
|
379
|
+
accepted_prediction_tokens: z.ZodOptional<z.ZodNumber>;
|
|
380
|
+
audio_tokens: z.ZodOptional<z.ZodNumber>;
|
|
381
|
+
reasoning_tokens: z.ZodOptional<z.ZodNumber>;
|
|
382
|
+
rejected_prediction_tokens: z.ZodOptional<z.ZodNumber>;
|
|
383
|
+
}, z.core.$strip>>;
|
|
384
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
385
|
+
eventType: z.ZodLiteral<"tool_calls">;
|
|
386
|
+
toolCalls: z.ZodArray<z.ZodObject<{
|
|
387
|
+
id: z.ZodString;
|
|
388
|
+
type: z.ZodLiteral<"function">;
|
|
389
|
+
function: z.ZodObject<{
|
|
390
|
+
name: z.ZodString;
|
|
391
|
+
arguments: z.ZodString;
|
|
392
|
+
}, z.core.$strip>;
|
|
393
|
+
}, z.core.$strip>>;
|
|
394
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
395
|
+
eventType: z.ZodLiteral<"message_complete">;
|
|
396
|
+
content: z.ZodNullable<z.ZodString>;
|
|
397
|
+
reasoning: z.ZodOptional<z.ZodString>;
|
|
398
|
+
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
399
|
+
id: z.ZodString;
|
|
400
|
+
type: z.ZodLiteral<"function">;
|
|
401
|
+
function: z.ZodObject<{
|
|
402
|
+
name: z.ZodString;
|
|
403
|
+
arguments: z.ZodString;
|
|
404
|
+
}, z.core.$strip>;
|
|
405
|
+
}, z.core.$strip>>>;
|
|
406
|
+
finish_reason: z.ZodNullable<z.ZodEnum<{
|
|
407
|
+
tool_calls: "tool_calls";
|
|
408
|
+
stop: "stop";
|
|
409
|
+
length: "length";
|
|
410
|
+
content_filter: "content_filter";
|
|
411
|
+
function_call: "function_call";
|
|
412
|
+
}>>;
|
|
413
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
414
|
+
eventType: z.ZodLiteral<"reasoning_delta">;
|
|
415
|
+
content: z.ZodString;
|
|
416
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
417
|
+
eventType: z.ZodLiteral<"reasoning_complete">;
|
|
418
|
+
content: z.ZodString;
|
|
419
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
420
|
+
eventType: z.ZodLiteral<"agent_started">;
|
|
421
|
+
model: z.ZodOptional<z.ZodString>;
|
|
422
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
423
|
+
eventType: z.ZodLiteral<"agent_complete">;
|
|
424
|
+
message: z.ZodOptional<z.ZodString>;
|
|
425
|
+
error: z.ZodOptional<z.ZodString>;
|
|
426
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
427
|
+
eventType: z.ZodLiteral<"error">;
|
|
428
|
+
message: z.ZodString;
|
|
429
|
+
code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
430
|
+
type: z.ZodOptional<z.ZodString>;
|
|
431
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
432
|
+
eventType: z.ZodLiteral<"tool_started">;
|
|
433
|
+
toolName: z.ZodString;
|
|
434
|
+
toolCallId: z.ZodString;
|
|
435
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
436
|
+
eventType: z.ZodLiteral<"tool_completed">;
|
|
437
|
+
toolName: z.ZodString;
|
|
438
|
+
toolCallId: z.ZodString;
|
|
439
|
+
result: z.ZodString;
|
|
440
|
+
success: z.ZodBoolean;
|
|
441
|
+
}, z.core.$strip>], "eventType">;
|
|
442
|
+
adapterName: z.ZodOptional<z.ZodString>;
|
|
443
|
+
agentId: z.ZodOptional<z.ZodString>;
|
|
444
|
+
adapterId: z.ZodOptional<z.ZodString>;
|
|
445
|
+
adapterSessionId: z.ZodOptional<z.ZodString>;
|
|
446
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
447
|
+
}, z.core.$strip>;
|
|
448
|
+
tool_approval: {
|
|
449
|
+
request: z.ZodObject<{
|
|
450
|
+
agentId: z.ZodString;
|
|
451
|
+
adapterId: z.ZodString;
|
|
452
|
+
adapterName: z.ZodString;
|
|
453
|
+
adapterSessionId: z.ZodString;
|
|
454
|
+
messageId: z.ZodOptional<z.ZodString>;
|
|
455
|
+
turnId: z.ZodOptional<z.ZodString>;
|
|
456
|
+
clientId: z.ZodOptional<z.ZodString>;
|
|
457
|
+
providerConfigId: z.ZodOptional<z.ZodString>;
|
|
458
|
+
occurredAt: z.ZodOptional<z.ZodNumber>;
|
|
459
|
+
toolName: z.ZodOptional<z.ZodString>;
|
|
460
|
+
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
461
|
+
toolCallId: z.ZodString;
|
|
462
|
+
reasoning: z.ZodOptional<z.ZodString>;
|
|
463
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
464
|
+
}, z.core.$strip>;
|
|
465
|
+
response: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
466
|
+
action: z.ZodLiteral<"allow">;
|
|
467
|
+
updatedInput: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
468
|
+
updatedPermissions: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
|
|
469
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
470
|
+
action: z.ZodLiteral<"deny">;
|
|
471
|
+
message: z.ZodString;
|
|
472
|
+
shouldAbort: z.ZodOptional<z.ZodBoolean>;
|
|
473
|
+
}, z.core.$strip>], "action">;
|
|
474
|
+
};
|
|
475
|
+
chunk: z.ZodObject<{
|
|
476
|
+
eventType: z.ZodLiteral<"chunk">;
|
|
477
|
+
id: z.ZodString;
|
|
478
|
+
choices: z.ZodArray<z.ZodObject<{
|
|
479
|
+
delta: z.ZodObject<{
|
|
480
|
+
content: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
481
|
+
role: z.ZodOptional<z.ZodEnum<{
|
|
482
|
+
assistant: "assistant";
|
|
483
|
+
user: "user";
|
|
484
|
+
system: "system";
|
|
485
|
+
tool: "tool";
|
|
486
|
+
developer: "developer";
|
|
487
|
+
}>>;
|
|
488
|
+
refusal: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
489
|
+
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
490
|
+
index: z.ZodNumber;
|
|
491
|
+
id: z.ZodOptional<z.ZodString>;
|
|
492
|
+
type: z.ZodOptional<z.ZodLiteral<"function">>;
|
|
493
|
+
function: z.ZodOptional<z.ZodObject<{
|
|
494
|
+
name: z.ZodOptional<z.ZodString>;
|
|
495
|
+
arguments: z.ZodOptional<z.ZodString>;
|
|
496
|
+
}, z.core.$strip>>;
|
|
497
|
+
}, z.core.$strip>>>;
|
|
498
|
+
}, z.core.$strip>;
|
|
499
|
+
index: z.ZodNumber;
|
|
500
|
+
finish_reason: z.ZodNullable<z.ZodEnum<{
|
|
501
|
+
tool_calls: "tool_calls";
|
|
502
|
+
stop: "stop";
|
|
503
|
+
length: "length";
|
|
504
|
+
content_filter: "content_filter";
|
|
505
|
+
function_call: "function_call";
|
|
506
|
+
}>>;
|
|
507
|
+
logprobs: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
|
|
508
|
+
}, z.core.$strip>>;
|
|
509
|
+
created: z.ZodNumber;
|
|
510
|
+
model: z.ZodString;
|
|
511
|
+
object: z.ZodLiteral<"chat.completion.chunk">;
|
|
512
|
+
service_tier: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
513
|
+
default: "default";
|
|
514
|
+
auto: "auto";
|
|
515
|
+
flex: "flex";
|
|
516
|
+
scale: "scale";
|
|
517
|
+
priority: "priority";
|
|
518
|
+
}>>>;
|
|
519
|
+
system_fingerprint: z.ZodOptional<z.ZodString>;
|
|
520
|
+
}, z.core.$strip>;
|
|
521
|
+
usage: z.ZodObject<{
|
|
522
|
+
eventType: z.ZodLiteral<"usage">;
|
|
523
|
+
prompt_tokens: z.ZodNumber;
|
|
524
|
+
completion_tokens: z.ZodNumber;
|
|
525
|
+
total_tokens: z.ZodNumber;
|
|
526
|
+
prompt_tokens_details: z.ZodOptional<z.ZodObject<{
|
|
527
|
+
audio_tokens: z.ZodOptional<z.ZodNumber>;
|
|
528
|
+
cached_tokens: z.ZodOptional<z.ZodNumber>;
|
|
529
|
+
}, z.core.$strip>>;
|
|
530
|
+
completion_tokens_details: z.ZodOptional<z.ZodObject<{
|
|
531
|
+
accepted_prediction_tokens: z.ZodOptional<z.ZodNumber>;
|
|
532
|
+
audio_tokens: z.ZodOptional<z.ZodNumber>;
|
|
533
|
+
reasoning_tokens: z.ZodOptional<z.ZodNumber>;
|
|
534
|
+
rejected_prediction_tokens: z.ZodOptional<z.ZodNumber>;
|
|
535
|
+
}, z.core.$strip>>;
|
|
536
|
+
}, z.core.$strip>;
|
|
537
|
+
message_complete: z.ZodObject<{
|
|
538
|
+
eventType: z.ZodLiteral<"message_complete">;
|
|
539
|
+
content: z.ZodNullable<z.ZodString>;
|
|
540
|
+
reasoning: z.ZodOptional<z.ZodString>;
|
|
541
|
+
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
542
|
+
id: z.ZodString;
|
|
543
|
+
type: z.ZodLiteral<"function">;
|
|
544
|
+
function: z.ZodObject<{
|
|
545
|
+
name: z.ZodString;
|
|
546
|
+
arguments: z.ZodString;
|
|
547
|
+
}, z.core.$strip>;
|
|
548
|
+
}, z.core.$strip>>>;
|
|
549
|
+
finish_reason: z.ZodNullable<z.ZodEnum<{
|
|
550
|
+
tool_calls: "tool_calls";
|
|
551
|
+
stop: "stop";
|
|
552
|
+
length: "length";
|
|
553
|
+
content_filter: "content_filter";
|
|
554
|
+
function_call: "function_call";
|
|
555
|
+
}>>;
|
|
556
|
+
}, z.core.$strip>;
|
|
557
|
+
reasoning_delta: z.ZodObject<{
|
|
558
|
+
eventType: z.ZodLiteral<"reasoning_delta">;
|
|
559
|
+
content: z.ZodString;
|
|
560
|
+
}, z.core.$strip>;
|
|
561
|
+
reasoning_complete: z.ZodObject<{
|
|
562
|
+
eventType: z.ZodLiteral<"reasoning_complete">;
|
|
563
|
+
content: z.ZodString;
|
|
564
|
+
}, z.core.$strip>;
|
|
565
|
+
tool_calls: z.ZodObject<{
|
|
566
|
+
eventType: z.ZodLiteral<"tool_calls">;
|
|
567
|
+
toolCalls: z.ZodArray<z.ZodObject<{
|
|
568
|
+
id: z.ZodString;
|
|
569
|
+
type: z.ZodLiteral<"function">;
|
|
570
|
+
function: z.ZodObject<{
|
|
571
|
+
name: z.ZodString;
|
|
572
|
+
arguments: z.ZodString;
|
|
573
|
+
}, z.core.$strip>;
|
|
574
|
+
}, z.core.$strip>>;
|
|
575
|
+
}, z.core.$strip>;
|
|
576
|
+
tool_started: z.ZodObject<{
|
|
577
|
+
eventType: z.ZodLiteral<"tool_started">;
|
|
578
|
+
toolName: z.ZodString;
|
|
579
|
+
toolCallId: z.ZodString;
|
|
580
|
+
}, z.core.$strip>;
|
|
581
|
+
tool_completed: z.ZodObject<{
|
|
582
|
+
eventType: z.ZodLiteral<"tool_completed">;
|
|
583
|
+
toolName: z.ZodString;
|
|
584
|
+
toolCallId: z.ZodString;
|
|
585
|
+
result: z.ZodString;
|
|
586
|
+
success: z.ZodBoolean;
|
|
587
|
+
}, z.core.$strip>;
|
|
588
|
+
agent_started: z.ZodObject<{
|
|
589
|
+
eventType: z.ZodLiteral<"agent_started">;
|
|
590
|
+
model: z.ZodOptional<z.ZodString>;
|
|
591
|
+
}, z.core.$strip>;
|
|
592
|
+
agent_complete: z.ZodObject<{
|
|
593
|
+
eventType: z.ZodLiteral<"agent_complete">;
|
|
594
|
+
message: z.ZodOptional<z.ZodString>;
|
|
595
|
+
error: z.ZodOptional<z.ZodString>;
|
|
596
|
+
}, z.core.$strip>;
|
|
597
|
+
error: z.ZodObject<{
|
|
598
|
+
eventType: z.ZodLiteral<"error">;
|
|
599
|
+
message: z.ZodString;
|
|
600
|
+
code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
601
|
+
type: z.ZodOptional<z.ZodString>;
|
|
602
|
+
}, z.core.$strip>;
|
|
603
|
+
'turn.state_changed': z.ZodObject<{
|
|
604
|
+
adapterId: z.ZodString;
|
|
605
|
+
agentId: z.ZodString;
|
|
606
|
+
oldState: z.ZodEnum<{
|
|
607
|
+
idle: "idle";
|
|
608
|
+
turn_started: "turn_started";
|
|
609
|
+
step_started: "step_started";
|
|
610
|
+
step_finished: "step_finished";
|
|
611
|
+
turn_finished: "turn_finished";
|
|
612
|
+
}>;
|
|
613
|
+
newState: z.ZodEnum<{
|
|
614
|
+
idle: "idle";
|
|
615
|
+
turn_started: "turn_started";
|
|
616
|
+
step_started: "step_started";
|
|
617
|
+
step_finished: "step_finished";
|
|
618
|
+
turn_finished: "turn_finished";
|
|
619
|
+
}>;
|
|
620
|
+
timestamp: z.ZodNumber;
|
|
621
|
+
}, z.core.$strip>;
|
|
622
|
+
'turn.turn_started': z.ZodObject<{
|
|
623
|
+
adapterId: z.ZodString;
|
|
624
|
+
agentId: z.ZodString;
|
|
625
|
+
oldState: z.ZodEnum<{
|
|
626
|
+
idle: "idle";
|
|
627
|
+
turn_started: "turn_started";
|
|
628
|
+
step_started: "step_started";
|
|
629
|
+
step_finished: "step_finished";
|
|
630
|
+
turn_finished: "turn_finished";
|
|
631
|
+
}>;
|
|
632
|
+
newState: z.ZodEnum<{
|
|
633
|
+
idle: "idle";
|
|
634
|
+
turn_started: "turn_started";
|
|
635
|
+
step_started: "step_started";
|
|
636
|
+
step_finished: "step_finished";
|
|
637
|
+
turn_finished: "turn_finished";
|
|
638
|
+
}>;
|
|
639
|
+
timestamp: z.ZodNumber;
|
|
640
|
+
}, z.core.$strip>;
|
|
641
|
+
'turn.step_started': z.ZodObject<{
|
|
642
|
+
adapterId: z.ZodString;
|
|
643
|
+
agentId: z.ZodString;
|
|
644
|
+
oldState: z.ZodEnum<{
|
|
645
|
+
idle: "idle";
|
|
646
|
+
turn_started: "turn_started";
|
|
647
|
+
step_started: "step_started";
|
|
648
|
+
step_finished: "step_finished";
|
|
649
|
+
turn_finished: "turn_finished";
|
|
650
|
+
}>;
|
|
651
|
+
newState: z.ZodEnum<{
|
|
652
|
+
idle: "idle";
|
|
653
|
+
turn_started: "turn_started";
|
|
654
|
+
step_started: "step_started";
|
|
655
|
+
step_finished: "step_finished";
|
|
656
|
+
turn_finished: "turn_finished";
|
|
657
|
+
}>;
|
|
658
|
+
timestamp: z.ZodNumber;
|
|
659
|
+
}, z.core.$strip>;
|
|
660
|
+
'turn.step_finished': z.ZodObject<{
|
|
661
|
+
adapterId: z.ZodString;
|
|
662
|
+
agentId: z.ZodString;
|
|
663
|
+
oldState: z.ZodEnum<{
|
|
664
|
+
idle: "idle";
|
|
665
|
+
turn_started: "turn_started";
|
|
666
|
+
step_started: "step_started";
|
|
667
|
+
step_finished: "step_finished";
|
|
668
|
+
turn_finished: "turn_finished";
|
|
669
|
+
}>;
|
|
670
|
+
newState: z.ZodEnum<{
|
|
671
|
+
idle: "idle";
|
|
672
|
+
turn_started: "turn_started";
|
|
673
|
+
step_started: "step_started";
|
|
674
|
+
step_finished: "step_finished";
|
|
675
|
+
turn_finished: "turn_finished";
|
|
676
|
+
}>;
|
|
677
|
+
timestamp: z.ZodNumber;
|
|
678
|
+
}, z.core.$strip>;
|
|
679
|
+
'turn.turn_finished': z.ZodObject<{
|
|
680
|
+
adapterId: z.ZodString;
|
|
681
|
+
agentId: z.ZodString;
|
|
682
|
+
oldState: z.ZodEnum<{
|
|
683
|
+
idle: "idle";
|
|
684
|
+
turn_started: "turn_started";
|
|
685
|
+
step_started: "step_started";
|
|
686
|
+
step_finished: "step_finished";
|
|
687
|
+
turn_finished: "turn_finished";
|
|
688
|
+
}>;
|
|
689
|
+
newState: z.ZodEnum<{
|
|
690
|
+
idle: "idle";
|
|
691
|
+
turn_started: "turn_started";
|
|
692
|
+
step_started: "step_started";
|
|
693
|
+
step_finished: "step_finished";
|
|
694
|
+
turn_finished: "turn_finished";
|
|
695
|
+
}>;
|
|
696
|
+
timestamp: z.ZodNumber;
|
|
697
|
+
}, z.core.$strip>;
|
|
698
|
+
}>, {
|
|
699
|
+
object: "chat.completion.chunk";
|
|
700
|
+
eventType: "chunk" | "tool_calls" | "usage" | "error" | "message_complete" | "reasoning_delta" | "reasoning_complete" | "agent_started" | "agent_complete" | "tool_started" | "tool_completed";
|
|
701
|
+
id: string;
|
|
702
|
+
choices: {
|
|
703
|
+
delta: {
|
|
704
|
+
content?: string | null | undefined;
|
|
705
|
+
role?: "assistant" | "user" | "system" | "tool" | "developer" | undefined;
|
|
706
|
+
refusal?: string | null | undefined;
|
|
707
|
+
tool_calls?: {
|
|
708
|
+
index: number;
|
|
709
|
+
id?: string | undefined;
|
|
710
|
+
type?: "function" | undefined;
|
|
711
|
+
function?: {
|
|
712
|
+
name?: string | undefined;
|
|
713
|
+
arguments?: string | undefined;
|
|
714
|
+
} | undefined;
|
|
715
|
+
}[] | undefined;
|
|
716
|
+
};
|
|
717
|
+
index: number;
|
|
718
|
+
finish_reason: "tool_calls" | "stop" | "length" | "content_filter" | "function_call" | null;
|
|
719
|
+
logprobs?: unknown;
|
|
720
|
+
}[] | ChatCompletionChunk.Choice[];
|
|
721
|
+
content: string | null;
|
|
722
|
+
type: never;
|
|
723
|
+
success: boolean;
|
|
724
|
+
tool_calls: never;
|
|
725
|
+
finish_reason: "tool_calls" | "stop" | "length" | "content_filter" | "function_call" | null;
|
|
726
|
+
created: number;
|
|
727
|
+
model: string;
|
|
728
|
+
service_tier: never;
|
|
729
|
+
system_fingerprint: never;
|
|
730
|
+
usage: never;
|
|
731
|
+
prompt_tokens: number;
|
|
732
|
+
completion_tokens: number;
|
|
733
|
+
total_tokens: number;
|
|
734
|
+
prompt_tokens_details: never;
|
|
735
|
+
completion_tokens_details: never;
|
|
736
|
+
message: string;
|
|
737
|
+
code: never;
|
|
738
|
+
error: never;
|
|
739
|
+
toolCalls: {
|
|
740
|
+
id: string;
|
|
741
|
+
type: "function";
|
|
742
|
+
function: {
|
|
743
|
+
name: string;
|
|
744
|
+
arguments: string;
|
|
745
|
+
};
|
|
746
|
+
}[];
|
|
747
|
+
reasoning: never;
|
|
748
|
+
toolName: string;
|
|
749
|
+
toolCallId: string;
|
|
750
|
+
result: string;
|
|
751
|
+
event: {
|
|
752
|
+
eventType: "tool_calls";
|
|
753
|
+
toolCalls: {
|
|
754
|
+
id: string;
|
|
755
|
+
type: "function";
|
|
756
|
+
function: {
|
|
757
|
+
name: string;
|
|
758
|
+
arguments: string;
|
|
759
|
+
};
|
|
760
|
+
}[];
|
|
761
|
+
} | {
|
|
762
|
+
eventType: "chunk";
|
|
763
|
+
id: string;
|
|
764
|
+
choices: {
|
|
765
|
+
delta: {
|
|
766
|
+
content?: string | null | undefined;
|
|
767
|
+
role?: "assistant" | "user" | "system" | "tool" | "developer" | undefined;
|
|
768
|
+
refusal?: string | null | undefined;
|
|
769
|
+
tool_calls?: {
|
|
770
|
+
index: number;
|
|
771
|
+
id?: string | undefined;
|
|
772
|
+
type?: "function" | undefined;
|
|
773
|
+
function?: {
|
|
774
|
+
name?: string | undefined;
|
|
775
|
+
arguments?: string | undefined;
|
|
776
|
+
} | undefined;
|
|
777
|
+
}[] | undefined;
|
|
778
|
+
};
|
|
779
|
+
index: number;
|
|
780
|
+
finish_reason: "tool_calls" | "stop" | "length" | "content_filter" | "function_call" | null;
|
|
781
|
+
logprobs?: unknown;
|
|
782
|
+
}[];
|
|
783
|
+
created: number;
|
|
784
|
+
model: string;
|
|
785
|
+
object: "chat.completion.chunk";
|
|
786
|
+
service_tier?: "default" | "auto" | "flex" | "scale" | "priority" | null | undefined;
|
|
787
|
+
system_fingerprint?: string | undefined;
|
|
788
|
+
} | {
|
|
789
|
+
eventType: "usage";
|
|
790
|
+
prompt_tokens: number;
|
|
791
|
+
completion_tokens: number;
|
|
792
|
+
total_tokens: number;
|
|
793
|
+
prompt_tokens_details?: {
|
|
794
|
+
audio_tokens?: number | undefined;
|
|
795
|
+
cached_tokens?: number | undefined;
|
|
796
|
+
} | undefined;
|
|
797
|
+
completion_tokens_details?: {
|
|
798
|
+
accepted_prediction_tokens?: number | undefined;
|
|
799
|
+
audio_tokens?: number | undefined;
|
|
800
|
+
reasoning_tokens?: number | undefined;
|
|
801
|
+
rejected_prediction_tokens?: number | undefined;
|
|
802
|
+
} | undefined;
|
|
803
|
+
} | {
|
|
804
|
+
eventType: "message_complete";
|
|
805
|
+
content: string | null;
|
|
806
|
+
finish_reason: "tool_calls" | "stop" | "length" | "content_filter" | "function_call" | null;
|
|
807
|
+
reasoning?: string | undefined;
|
|
808
|
+
tool_calls?: {
|
|
809
|
+
id: string;
|
|
810
|
+
type: "function";
|
|
811
|
+
function: {
|
|
812
|
+
name: string;
|
|
813
|
+
arguments: string;
|
|
814
|
+
};
|
|
815
|
+
}[] | undefined;
|
|
816
|
+
} | {
|
|
817
|
+
eventType: "reasoning_delta";
|
|
818
|
+
content: string;
|
|
819
|
+
} | {
|
|
820
|
+
eventType: "reasoning_complete";
|
|
821
|
+
content: string;
|
|
822
|
+
} | {
|
|
823
|
+
eventType: "agent_started";
|
|
824
|
+
model?: string | undefined;
|
|
825
|
+
} | {
|
|
826
|
+
eventType: "agent_complete";
|
|
827
|
+
message?: string | undefined;
|
|
828
|
+
error?: string | undefined;
|
|
829
|
+
} | {
|
|
830
|
+
eventType: "error";
|
|
831
|
+
message: string;
|
|
832
|
+
code?: string | number | undefined;
|
|
833
|
+
type?: string | undefined;
|
|
834
|
+
} | {
|
|
835
|
+
eventType: "tool_started";
|
|
836
|
+
toolName: string;
|
|
837
|
+
toolCallId: string;
|
|
838
|
+
} | {
|
|
839
|
+
eventType: "tool_completed";
|
|
840
|
+
toolName: string;
|
|
841
|
+
toolCallId: string;
|
|
842
|
+
result: string;
|
|
843
|
+
success: boolean;
|
|
844
|
+
};
|
|
845
|
+
adapterName: string;
|
|
846
|
+
agentId: string;
|
|
847
|
+
adapterId: string;
|
|
848
|
+
adapterSessionId: string;
|
|
849
|
+
sessionId: never;
|
|
850
|
+
messageId: never;
|
|
851
|
+
turnId: never;
|
|
852
|
+
clientId: never;
|
|
853
|
+
providerConfigId: never;
|
|
854
|
+
occurredAt: never;
|
|
855
|
+
args: never;
|
|
856
|
+
oldState: "idle" | "turn_started" | "step_started" | "step_finished" | "turn_finished";
|
|
857
|
+
newState: "idle" | "turn_started" | "step_started" | "step_finished" | "turn_finished";
|
|
858
|
+
timestamp: number;
|
|
859
|
+
}, {
|
|
860
|
+
'sdk.raw': z.ZodCustom<ChatCompletionChunk, ChatCompletionChunk>;
|
|
861
|
+
'sdk.event': z.ZodObject<{
|
|
862
|
+
event: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
863
|
+
eventType: z.ZodLiteral<"chunk">;
|
|
864
|
+
id: z.ZodString;
|
|
865
|
+
choices: z.ZodArray<z.ZodObject<{
|
|
866
|
+
delta: z.ZodObject<{
|
|
867
|
+
content: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
868
|
+
role: z.ZodOptional<z.ZodEnum<{
|
|
869
|
+
assistant: "assistant";
|
|
870
|
+
user: "user";
|
|
871
|
+
system: "system";
|
|
872
|
+
tool: "tool";
|
|
873
|
+
developer: "developer";
|
|
874
|
+
}>>;
|
|
875
|
+
refusal: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
876
|
+
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
877
|
+
index: z.ZodNumber;
|
|
878
|
+
id: z.ZodOptional<z.ZodString>;
|
|
879
|
+
type: z.ZodOptional<z.ZodLiteral<"function">>;
|
|
880
|
+
function: z.ZodOptional<z.ZodObject<{
|
|
881
|
+
name: z.ZodOptional<z.ZodString>;
|
|
882
|
+
arguments: z.ZodOptional<z.ZodString>;
|
|
883
|
+
}, z.core.$strip>>;
|
|
884
|
+
}, z.core.$strip>>>;
|
|
885
|
+
}, z.core.$strip>;
|
|
886
|
+
index: z.ZodNumber;
|
|
887
|
+
finish_reason: z.ZodNullable<z.ZodEnum<{
|
|
888
|
+
tool_calls: "tool_calls";
|
|
889
|
+
stop: "stop";
|
|
890
|
+
length: "length";
|
|
891
|
+
content_filter: "content_filter";
|
|
892
|
+
function_call: "function_call";
|
|
893
|
+
}>>;
|
|
894
|
+
logprobs: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
|
|
895
|
+
}, z.core.$strip>>;
|
|
896
|
+
created: z.ZodNumber;
|
|
897
|
+
model: z.ZodString;
|
|
898
|
+
object: z.ZodLiteral<"chat.completion.chunk">;
|
|
899
|
+
service_tier: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
900
|
+
default: "default";
|
|
901
|
+
auto: "auto";
|
|
902
|
+
flex: "flex";
|
|
903
|
+
scale: "scale";
|
|
904
|
+
priority: "priority";
|
|
905
|
+
}>>>;
|
|
906
|
+
system_fingerprint: z.ZodOptional<z.ZodString>;
|
|
907
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
908
|
+
eventType: z.ZodLiteral<"usage">;
|
|
909
|
+
prompt_tokens: z.ZodNumber;
|
|
910
|
+
completion_tokens: z.ZodNumber;
|
|
911
|
+
total_tokens: z.ZodNumber;
|
|
912
|
+
prompt_tokens_details: z.ZodOptional<z.ZodObject<{
|
|
913
|
+
audio_tokens: z.ZodOptional<z.ZodNumber>;
|
|
914
|
+
cached_tokens: z.ZodOptional<z.ZodNumber>;
|
|
915
|
+
}, z.core.$strip>>;
|
|
916
|
+
completion_tokens_details: z.ZodOptional<z.ZodObject<{
|
|
917
|
+
accepted_prediction_tokens: z.ZodOptional<z.ZodNumber>;
|
|
918
|
+
audio_tokens: z.ZodOptional<z.ZodNumber>;
|
|
919
|
+
reasoning_tokens: z.ZodOptional<z.ZodNumber>;
|
|
920
|
+
rejected_prediction_tokens: z.ZodOptional<z.ZodNumber>;
|
|
921
|
+
}, z.core.$strip>>;
|
|
922
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
923
|
+
eventType: z.ZodLiteral<"tool_calls">;
|
|
924
|
+
toolCalls: z.ZodArray<z.ZodObject<{
|
|
925
|
+
id: z.ZodString;
|
|
926
|
+
type: z.ZodLiteral<"function">;
|
|
927
|
+
function: z.ZodObject<{
|
|
928
|
+
name: z.ZodString;
|
|
929
|
+
arguments: z.ZodString;
|
|
930
|
+
}, z.core.$strip>;
|
|
931
|
+
}, z.core.$strip>>;
|
|
932
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
933
|
+
eventType: z.ZodLiteral<"message_complete">;
|
|
934
|
+
content: z.ZodNullable<z.ZodString>;
|
|
935
|
+
reasoning: z.ZodOptional<z.ZodString>;
|
|
936
|
+
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
937
|
+
id: z.ZodString;
|
|
938
|
+
type: z.ZodLiteral<"function">;
|
|
939
|
+
function: z.ZodObject<{
|
|
940
|
+
name: z.ZodString;
|
|
941
|
+
arguments: z.ZodString;
|
|
942
|
+
}, z.core.$strip>;
|
|
943
|
+
}, z.core.$strip>>>;
|
|
944
|
+
finish_reason: z.ZodNullable<z.ZodEnum<{
|
|
945
|
+
tool_calls: "tool_calls";
|
|
946
|
+
stop: "stop";
|
|
947
|
+
length: "length";
|
|
948
|
+
content_filter: "content_filter";
|
|
949
|
+
function_call: "function_call";
|
|
950
|
+
}>>;
|
|
951
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
952
|
+
eventType: z.ZodLiteral<"reasoning_delta">;
|
|
953
|
+
content: z.ZodString;
|
|
954
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
955
|
+
eventType: z.ZodLiteral<"reasoning_complete">;
|
|
956
|
+
content: z.ZodString;
|
|
957
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
958
|
+
eventType: z.ZodLiteral<"agent_started">;
|
|
959
|
+
model: z.ZodOptional<z.ZodString>;
|
|
960
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
961
|
+
eventType: z.ZodLiteral<"agent_complete">;
|
|
962
|
+
message: z.ZodOptional<z.ZodString>;
|
|
963
|
+
error: z.ZodOptional<z.ZodString>;
|
|
964
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
965
|
+
eventType: z.ZodLiteral<"error">;
|
|
966
|
+
message: z.ZodString;
|
|
967
|
+
code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
968
|
+
type: z.ZodOptional<z.ZodString>;
|
|
969
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
970
|
+
eventType: z.ZodLiteral<"tool_started">;
|
|
971
|
+
toolName: z.ZodString;
|
|
972
|
+
toolCallId: z.ZodString;
|
|
973
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
974
|
+
eventType: z.ZodLiteral<"tool_completed">;
|
|
975
|
+
toolName: z.ZodString;
|
|
976
|
+
toolCallId: z.ZodString;
|
|
977
|
+
result: z.ZodString;
|
|
978
|
+
success: z.ZodBoolean;
|
|
979
|
+
}, z.core.$strip>], "eventType">;
|
|
980
|
+
adapterName: z.ZodOptional<z.ZodString>;
|
|
981
|
+
agentId: z.ZodOptional<z.ZodString>;
|
|
982
|
+
adapterId: z.ZodOptional<z.ZodString>;
|
|
983
|
+
adapterSessionId: z.ZodOptional<z.ZodString>;
|
|
984
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
985
|
+
}, z.core.$strip>;
|
|
986
|
+
tool_approval: {
|
|
987
|
+
request: z.ZodObject<{
|
|
988
|
+
agentId: z.ZodString;
|
|
989
|
+
adapterId: z.ZodString;
|
|
990
|
+
adapterName: z.ZodString;
|
|
991
|
+
adapterSessionId: z.ZodString;
|
|
992
|
+
messageId: z.ZodOptional<z.ZodString>;
|
|
993
|
+
turnId: z.ZodOptional<z.ZodString>;
|
|
994
|
+
clientId: z.ZodOptional<z.ZodString>;
|
|
995
|
+
providerConfigId: z.ZodOptional<z.ZodString>;
|
|
996
|
+
occurredAt: z.ZodOptional<z.ZodNumber>;
|
|
997
|
+
toolName: z.ZodOptional<z.ZodString>;
|
|
998
|
+
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
999
|
+
toolCallId: z.ZodString;
|
|
1000
|
+
reasoning: z.ZodOptional<z.ZodString>;
|
|
1001
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
1002
|
+
}, z.core.$strip>;
|
|
1003
|
+
response: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
1004
|
+
action: z.ZodLiteral<"allow">;
|
|
1005
|
+
updatedInput: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
1006
|
+
updatedPermissions: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
|
|
1007
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1008
|
+
action: z.ZodLiteral<"deny">;
|
|
1009
|
+
message: z.ZodString;
|
|
1010
|
+
shouldAbort: z.ZodOptional<z.ZodBoolean>;
|
|
1011
|
+
}, z.core.$strip>], "action">;
|
|
1012
|
+
};
|
|
1013
|
+
chunk: z.ZodObject<{
|
|
1014
|
+
eventType: z.ZodLiteral<"chunk">;
|
|
1015
|
+
id: z.ZodString;
|
|
1016
|
+
choices: z.ZodArray<z.ZodObject<{
|
|
1017
|
+
delta: z.ZodObject<{
|
|
1018
|
+
content: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1019
|
+
role: z.ZodOptional<z.ZodEnum<{
|
|
1020
|
+
assistant: "assistant";
|
|
1021
|
+
user: "user";
|
|
1022
|
+
system: "system";
|
|
1023
|
+
tool: "tool";
|
|
1024
|
+
developer: "developer";
|
|
1025
|
+
}>>;
|
|
1026
|
+
refusal: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1027
|
+
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1028
|
+
index: z.ZodNumber;
|
|
1029
|
+
id: z.ZodOptional<z.ZodString>;
|
|
1030
|
+
type: z.ZodOptional<z.ZodLiteral<"function">>;
|
|
1031
|
+
function: z.ZodOptional<z.ZodObject<{
|
|
1032
|
+
name: z.ZodOptional<z.ZodString>;
|
|
1033
|
+
arguments: z.ZodOptional<z.ZodString>;
|
|
1034
|
+
}, z.core.$strip>>;
|
|
1035
|
+
}, z.core.$strip>>>;
|
|
1036
|
+
}, z.core.$strip>;
|
|
1037
|
+
index: z.ZodNumber;
|
|
1038
|
+
finish_reason: z.ZodNullable<z.ZodEnum<{
|
|
1039
|
+
tool_calls: "tool_calls";
|
|
1040
|
+
stop: "stop";
|
|
1041
|
+
length: "length";
|
|
1042
|
+
content_filter: "content_filter";
|
|
1043
|
+
function_call: "function_call";
|
|
1044
|
+
}>>;
|
|
1045
|
+
logprobs: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
|
|
1046
|
+
}, z.core.$strip>>;
|
|
1047
|
+
created: z.ZodNumber;
|
|
1048
|
+
model: z.ZodString;
|
|
1049
|
+
object: z.ZodLiteral<"chat.completion.chunk">;
|
|
1050
|
+
service_tier: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
1051
|
+
default: "default";
|
|
1052
|
+
auto: "auto";
|
|
1053
|
+
flex: "flex";
|
|
1054
|
+
scale: "scale";
|
|
1055
|
+
priority: "priority";
|
|
1056
|
+
}>>>;
|
|
1057
|
+
system_fingerprint: z.ZodOptional<z.ZodString>;
|
|
1058
|
+
}, z.core.$strip>;
|
|
1059
|
+
usage: z.ZodObject<{
|
|
1060
|
+
eventType: z.ZodLiteral<"usage">;
|
|
1061
|
+
prompt_tokens: z.ZodNumber;
|
|
1062
|
+
completion_tokens: z.ZodNumber;
|
|
1063
|
+
total_tokens: z.ZodNumber;
|
|
1064
|
+
prompt_tokens_details: z.ZodOptional<z.ZodObject<{
|
|
1065
|
+
audio_tokens: z.ZodOptional<z.ZodNumber>;
|
|
1066
|
+
cached_tokens: z.ZodOptional<z.ZodNumber>;
|
|
1067
|
+
}, z.core.$strip>>;
|
|
1068
|
+
completion_tokens_details: z.ZodOptional<z.ZodObject<{
|
|
1069
|
+
accepted_prediction_tokens: z.ZodOptional<z.ZodNumber>;
|
|
1070
|
+
audio_tokens: z.ZodOptional<z.ZodNumber>;
|
|
1071
|
+
reasoning_tokens: z.ZodOptional<z.ZodNumber>;
|
|
1072
|
+
rejected_prediction_tokens: z.ZodOptional<z.ZodNumber>;
|
|
1073
|
+
}, z.core.$strip>>;
|
|
1074
|
+
}, z.core.$strip>;
|
|
1075
|
+
message_complete: z.ZodObject<{
|
|
1076
|
+
eventType: z.ZodLiteral<"message_complete">;
|
|
1077
|
+
content: z.ZodNullable<z.ZodString>;
|
|
1078
|
+
reasoning: z.ZodOptional<z.ZodString>;
|
|
1079
|
+
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1080
|
+
id: z.ZodString;
|
|
1081
|
+
type: z.ZodLiteral<"function">;
|
|
1082
|
+
function: z.ZodObject<{
|
|
1083
|
+
name: z.ZodString;
|
|
1084
|
+
arguments: z.ZodString;
|
|
1085
|
+
}, z.core.$strip>;
|
|
1086
|
+
}, z.core.$strip>>>;
|
|
1087
|
+
finish_reason: z.ZodNullable<z.ZodEnum<{
|
|
1088
|
+
tool_calls: "tool_calls";
|
|
1089
|
+
stop: "stop";
|
|
1090
|
+
length: "length";
|
|
1091
|
+
content_filter: "content_filter";
|
|
1092
|
+
function_call: "function_call";
|
|
1093
|
+
}>>;
|
|
1094
|
+
}, z.core.$strip>;
|
|
1095
|
+
reasoning_delta: z.ZodObject<{
|
|
1096
|
+
eventType: z.ZodLiteral<"reasoning_delta">;
|
|
1097
|
+
content: z.ZodString;
|
|
1098
|
+
}, z.core.$strip>;
|
|
1099
|
+
reasoning_complete: z.ZodObject<{
|
|
1100
|
+
eventType: z.ZodLiteral<"reasoning_complete">;
|
|
1101
|
+
content: z.ZodString;
|
|
1102
|
+
}, z.core.$strip>;
|
|
1103
|
+
tool_calls: z.ZodObject<{
|
|
1104
|
+
eventType: z.ZodLiteral<"tool_calls">;
|
|
1105
|
+
toolCalls: z.ZodArray<z.ZodObject<{
|
|
1106
|
+
id: z.ZodString;
|
|
1107
|
+
type: z.ZodLiteral<"function">;
|
|
1108
|
+
function: z.ZodObject<{
|
|
1109
|
+
name: z.ZodString;
|
|
1110
|
+
arguments: z.ZodString;
|
|
1111
|
+
}, z.core.$strip>;
|
|
1112
|
+
}, z.core.$strip>>;
|
|
1113
|
+
}, z.core.$strip>;
|
|
1114
|
+
tool_started: z.ZodObject<{
|
|
1115
|
+
eventType: z.ZodLiteral<"tool_started">;
|
|
1116
|
+
toolName: z.ZodString;
|
|
1117
|
+
toolCallId: z.ZodString;
|
|
1118
|
+
}, z.core.$strip>;
|
|
1119
|
+
tool_completed: z.ZodObject<{
|
|
1120
|
+
eventType: z.ZodLiteral<"tool_completed">;
|
|
1121
|
+
toolName: z.ZodString;
|
|
1122
|
+
toolCallId: z.ZodString;
|
|
1123
|
+
result: z.ZodString;
|
|
1124
|
+
success: z.ZodBoolean;
|
|
1125
|
+
}, z.core.$strip>;
|
|
1126
|
+
agent_started: z.ZodObject<{
|
|
1127
|
+
eventType: z.ZodLiteral<"agent_started">;
|
|
1128
|
+
model: z.ZodOptional<z.ZodString>;
|
|
1129
|
+
}, z.core.$strip>;
|
|
1130
|
+
agent_complete: z.ZodObject<{
|
|
1131
|
+
eventType: z.ZodLiteral<"agent_complete">;
|
|
1132
|
+
message: z.ZodOptional<z.ZodString>;
|
|
1133
|
+
error: z.ZodOptional<z.ZodString>;
|
|
1134
|
+
}, z.core.$strip>;
|
|
1135
|
+
error: z.ZodObject<{
|
|
1136
|
+
eventType: z.ZodLiteral<"error">;
|
|
1137
|
+
message: z.ZodString;
|
|
1138
|
+
code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
1139
|
+
type: z.ZodOptional<z.ZodString>;
|
|
1140
|
+
}, z.core.$strip>;
|
|
1141
|
+
'turn.state_changed': z.ZodObject<{
|
|
1142
|
+
adapterId: z.ZodString;
|
|
1143
|
+
agentId: z.ZodString;
|
|
1144
|
+
oldState: z.ZodEnum<{
|
|
1145
|
+
idle: "idle";
|
|
1146
|
+
turn_started: "turn_started";
|
|
1147
|
+
step_started: "step_started";
|
|
1148
|
+
step_finished: "step_finished";
|
|
1149
|
+
turn_finished: "turn_finished";
|
|
1150
|
+
}>;
|
|
1151
|
+
newState: z.ZodEnum<{
|
|
1152
|
+
idle: "idle";
|
|
1153
|
+
turn_started: "turn_started";
|
|
1154
|
+
step_started: "step_started";
|
|
1155
|
+
step_finished: "step_finished";
|
|
1156
|
+
turn_finished: "turn_finished";
|
|
1157
|
+
}>;
|
|
1158
|
+
timestamp: z.ZodNumber;
|
|
1159
|
+
}, z.core.$strip>;
|
|
1160
|
+
'turn.turn_started': z.ZodObject<{
|
|
1161
|
+
adapterId: z.ZodString;
|
|
1162
|
+
agentId: z.ZodString;
|
|
1163
|
+
oldState: z.ZodEnum<{
|
|
1164
|
+
idle: "idle";
|
|
1165
|
+
turn_started: "turn_started";
|
|
1166
|
+
step_started: "step_started";
|
|
1167
|
+
step_finished: "step_finished";
|
|
1168
|
+
turn_finished: "turn_finished";
|
|
1169
|
+
}>;
|
|
1170
|
+
newState: z.ZodEnum<{
|
|
1171
|
+
idle: "idle";
|
|
1172
|
+
turn_started: "turn_started";
|
|
1173
|
+
step_started: "step_started";
|
|
1174
|
+
step_finished: "step_finished";
|
|
1175
|
+
turn_finished: "turn_finished";
|
|
1176
|
+
}>;
|
|
1177
|
+
timestamp: z.ZodNumber;
|
|
1178
|
+
}, z.core.$strip>;
|
|
1179
|
+
'turn.step_started': z.ZodObject<{
|
|
1180
|
+
adapterId: z.ZodString;
|
|
1181
|
+
agentId: z.ZodString;
|
|
1182
|
+
oldState: z.ZodEnum<{
|
|
1183
|
+
idle: "idle";
|
|
1184
|
+
turn_started: "turn_started";
|
|
1185
|
+
step_started: "step_started";
|
|
1186
|
+
step_finished: "step_finished";
|
|
1187
|
+
turn_finished: "turn_finished";
|
|
1188
|
+
}>;
|
|
1189
|
+
newState: z.ZodEnum<{
|
|
1190
|
+
idle: "idle";
|
|
1191
|
+
turn_started: "turn_started";
|
|
1192
|
+
step_started: "step_started";
|
|
1193
|
+
step_finished: "step_finished";
|
|
1194
|
+
turn_finished: "turn_finished";
|
|
1195
|
+
}>;
|
|
1196
|
+
timestamp: z.ZodNumber;
|
|
1197
|
+
}, z.core.$strip>;
|
|
1198
|
+
'turn.step_finished': z.ZodObject<{
|
|
1199
|
+
adapterId: z.ZodString;
|
|
1200
|
+
agentId: z.ZodString;
|
|
1201
|
+
oldState: z.ZodEnum<{
|
|
1202
|
+
idle: "idle";
|
|
1203
|
+
turn_started: "turn_started";
|
|
1204
|
+
step_started: "step_started";
|
|
1205
|
+
step_finished: "step_finished";
|
|
1206
|
+
turn_finished: "turn_finished";
|
|
1207
|
+
}>;
|
|
1208
|
+
newState: z.ZodEnum<{
|
|
1209
|
+
idle: "idle";
|
|
1210
|
+
turn_started: "turn_started";
|
|
1211
|
+
step_started: "step_started";
|
|
1212
|
+
step_finished: "step_finished";
|
|
1213
|
+
turn_finished: "turn_finished";
|
|
1214
|
+
}>;
|
|
1215
|
+
timestamp: z.ZodNumber;
|
|
1216
|
+
}, z.core.$strip>;
|
|
1217
|
+
'turn.turn_finished': z.ZodObject<{
|
|
1218
|
+
adapterId: z.ZodString;
|
|
1219
|
+
agentId: z.ZodString;
|
|
1220
|
+
oldState: z.ZodEnum<{
|
|
1221
|
+
idle: "idle";
|
|
1222
|
+
turn_started: "turn_started";
|
|
1223
|
+
step_started: "step_started";
|
|
1224
|
+
step_finished: "step_finished";
|
|
1225
|
+
turn_finished: "turn_finished";
|
|
1226
|
+
}>;
|
|
1227
|
+
newState: z.ZodEnum<{
|
|
1228
|
+
idle: "idle";
|
|
1229
|
+
turn_started: "turn_started";
|
|
1230
|
+
step_started: "step_started";
|
|
1231
|
+
step_finished: "step_finished";
|
|
1232
|
+
turn_finished: "turn_finished";
|
|
1233
|
+
}>;
|
|
1234
|
+
timestamp: z.ZodNumber;
|
|
1235
|
+
}, z.core.$strip>;
|
|
1236
|
+
}>;
|
|
1237
|
+
/**
|
|
1238
|
+
* Typed subject literals for OpenAI Node adapter.
|
|
1239
|
+
* Use these constants to subscribe to specific message types with full type safety.
|
|
1240
|
+
* @example
|
|
1241
|
+
* ```typescript
|
|
1242
|
+
* connector.on(OpenAINodeSubjects.chunk, (ctx) => {
|
|
1243
|
+
* // ctx.payload is typed as ChunkEvent
|
|
1244
|
+
* console.debug(ctx.payload.choices[0].delta.content);
|
|
1245
|
+
* });
|
|
1246
|
+
* ```
|
|
1247
|
+
*/
|
|
1248
|
+
declare const OpenAINodeConnectorSubjects: _$_makaio_core0.BusSubjects<_$_makaio_core0.FlatSubjectDefinitions<"adapter:openai-node", {
|
|
1249
|
+
'sdk.raw': z.ZodCustom<ChatCompletionChunk, ChatCompletionChunk>;
|
|
1250
|
+
'sdk.event': z.ZodObject<{
|
|
1251
|
+
event: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
1252
|
+
eventType: z.ZodLiteral<"chunk">;
|
|
1253
|
+
id: z.ZodString;
|
|
1254
|
+
choices: z.ZodArray<z.ZodObject<{
|
|
1255
|
+
delta: z.ZodObject<{
|
|
1256
|
+
content: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1257
|
+
role: z.ZodOptional<z.ZodEnum<{
|
|
1258
|
+
assistant: "assistant";
|
|
1259
|
+
user: "user";
|
|
1260
|
+
system: "system";
|
|
1261
|
+
tool: "tool";
|
|
1262
|
+
developer: "developer";
|
|
1263
|
+
}>>;
|
|
1264
|
+
refusal: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1265
|
+
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1266
|
+
index: z.ZodNumber;
|
|
1267
|
+
id: z.ZodOptional<z.ZodString>;
|
|
1268
|
+
type: z.ZodOptional<z.ZodLiteral<"function">>;
|
|
1269
|
+
function: z.ZodOptional<z.ZodObject<{
|
|
1270
|
+
name: z.ZodOptional<z.ZodString>;
|
|
1271
|
+
arguments: z.ZodOptional<z.ZodString>;
|
|
1272
|
+
}, z.core.$strip>>;
|
|
1273
|
+
}, z.core.$strip>>>;
|
|
1274
|
+
}, z.core.$strip>;
|
|
1275
|
+
index: z.ZodNumber;
|
|
1276
|
+
finish_reason: z.ZodNullable<z.ZodEnum<{
|
|
1277
|
+
tool_calls: "tool_calls";
|
|
1278
|
+
stop: "stop";
|
|
1279
|
+
length: "length";
|
|
1280
|
+
content_filter: "content_filter";
|
|
1281
|
+
function_call: "function_call";
|
|
1282
|
+
}>>;
|
|
1283
|
+
logprobs: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
|
|
1284
|
+
}, z.core.$strip>>;
|
|
1285
|
+
created: z.ZodNumber;
|
|
1286
|
+
model: z.ZodString;
|
|
1287
|
+
object: z.ZodLiteral<"chat.completion.chunk">;
|
|
1288
|
+
service_tier: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
1289
|
+
default: "default";
|
|
1290
|
+
auto: "auto";
|
|
1291
|
+
flex: "flex";
|
|
1292
|
+
scale: "scale";
|
|
1293
|
+
priority: "priority";
|
|
1294
|
+
}>>>;
|
|
1295
|
+
system_fingerprint: z.ZodOptional<z.ZodString>;
|
|
1296
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1297
|
+
eventType: z.ZodLiteral<"usage">;
|
|
1298
|
+
prompt_tokens: z.ZodNumber;
|
|
1299
|
+
completion_tokens: z.ZodNumber;
|
|
1300
|
+
total_tokens: z.ZodNumber;
|
|
1301
|
+
prompt_tokens_details: z.ZodOptional<z.ZodObject<{
|
|
1302
|
+
audio_tokens: z.ZodOptional<z.ZodNumber>;
|
|
1303
|
+
cached_tokens: z.ZodOptional<z.ZodNumber>;
|
|
1304
|
+
}, z.core.$strip>>;
|
|
1305
|
+
completion_tokens_details: z.ZodOptional<z.ZodObject<{
|
|
1306
|
+
accepted_prediction_tokens: z.ZodOptional<z.ZodNumber>;
|
|
1307
|
+
audio_tokens: z.ZodOptional<z.ZodNumber>;
|
|
1308
|
+
reasoning_tokens: z.ZodOptional<z.ZodNumber>;
|
|
1309
|
+
rejected_prediction_tokens: z.ZodOptional<z.ZodNumber>;
|
|
1310
|
+
}, z.core.$strip>>;
|
|
1311
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1312
|
+
eventType: z.ZodLiteral<"tool_calls">;
|
|
1313
|
+
toolCalls: z.ZodArray<z.ZodObject<{
|
|
1314
|
+
id: z.ZodString;
|
|
1315
|
+
type: z.ZodLiteral<"function">;
|
|
1316
|
+
function: z.ZodObject<{
|
|
1317
|
+
name: z.ZodString;
|
|
1318
|
+
arguments: z.ZodString;
|
|
1319
|
+
}, z.core.$strip>;
|
|
1320
|
+
}, z.core.$strip>>;
|
|
1321
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1322
|
+
eventType: z.ZodLiteral<"message_complete">;
|
|
1323
|
+
content: z.ZodNullable<z.ZodString>;
|
|
1324
|
+
reasoning: z.ZodOptional<z.ZodString>;
|
|
1325
|
+
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1326
|
+
id: z.ZodString;
|
|
1327
|
+
type: z.ZodLiteral<"function">;
|
|
1328
|
+
function: z.ZodObject<{
|
|
1329
|
+
name: z.ZodString;
|
|
1330
|
+
arguments: z.ZodString;
|
|
1331
|
+
}, z.core.$strip>;
|
|
1332
|
+
}, z.core.$strip>>>;
|
|
1333
|
+
finish_reason: z.ZodNullable<z.ZodEnum<{
|
|
1334
|
+
tool_calls: "tool_calls";
|
|
1335
|
+
stop: "stop";
|
|
1336
|
+
length: "length";
|
|
1337
|
+
content_filter: "content_filter";
|
|
1338
|
+
function_call: "function_call";
|
|
1339
|
+
}>>;
|
|
1340
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1341
|
+
eventType: z.ZodLiteral<"reasoning_delta">;
|
|
1342
|
+
content: z.ZodString;
|
|
1343
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1344
|
+
eventType: z.ZodLiteral<"reasoning_complete">;
|
|
1345
|
+
content: z.ZodString;
|
|
1346
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1347
|
+
eventType: z.ZodLiteral<"agent_started">;
|
|
1348
|
+
model: z.ZodOptional<z.ZodString>;
|
|
1349
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1350
|
+
eventType: z.ZodLiteral<"agent_complete">;
|
|
1351
|
+
message: z.ZodOptional<z.ZodString>;
|
|
1352
|
+
error: z.ZodOptional<z.ZodString>;
|
|
1353
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1354
|
+
eventType: z.ZodLiteral<"error">;
|
|
1355
|
+
message: z.ZodString;
|
|
1356
|
+
code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
1357
|
+
type: z.ZodOptional<z.ZodString>;
|
|
1358
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1359
|
+
eventType: z.ZodLiteral<"tool_started">;
|
|
1360
|
+
toolName: z.ZodString;
|
|
1361
|
+
toolCallId: z.ZodString;
|
|
1362
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1363
|
+
eventType: z.ZodLiteral<"tool_completed">;
|
|
1364
|
+
toolName: z.ZodString;
|
|
1365
|
+
toolCallId: z.ZodString;
|
|
1366
|
+
result: z.ZodString;
|
|
1367
|
+
success: z.ZodBoolean;
|
|
1368
|
+
}, z.core.$strip>], "eventType">;
|
|
1369
|
+
adapterName: z.ZodOptional<z.ZodString>;
|
|
1370
|
+
agentId: z.ZodOptional<z.ZodString>;
|
|
1371
|
+
adapterId: z.ZodOptional<z.ZodString>;
|
|
1372
|
+
adapterSessionId: z.ZodOptional<z.ZodString>;
|
|
1373
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
1374
|
+
}, z.core.$strip>;
|
|
1375
|
+
tool_approval: {
|
|
1376
|
+
request: z.ZodObject<{
|
|
1377
|
+
agentId: z.ZodString;
|
|
1378
|
+
adapterId: z.ZodString;
|
|
1379
|
+
adapterName: z.ZodString;
|
|
1380
|
+
adapterSessionId: z.ZodString;
|
|
1381
|
+
messageId: z.ZodOptional<z.ZodString>;
|
|
1382
|
+
turnId: z.ZodOptional<z.ZodString>;
|
|
1383
|
+
clientId: z.ZodOptional<z.ZodString>;
|
|
1384
|
+
providerConfigId: z.ZodOptional<z.ZodString>;
|
|
1385
|
+
occurredAt: z.ZodOptional<z.ZodNumber>;
|
|
1386
|
+
toolName: z.ZodOptional<z.ZodString>;
|
|
1387
|
+
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
1388
|
+
toolCallId: z.ZodString;
|
|
1389
|
+
reasoning: z.ZodOptional<z.ZodString>;
|
|
1390
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
1391
|
+
}, z.core.$strip>;
|
|
1392
|
+
response: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
1393
|
+
action: z.ZodLiteral<"allow">;
|
|
1394
|
+
updatedInput: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
1395
|
+
updatedPermissions: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
|
|
1396
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1397
|
+
action: z.ZodLiteral<"deny">;
|
|
1398
|
+
message: z.ZodString;
|
|
1399
|
+
shouldAbort: z.ZodOptional<z.ZodBoolean>;
|
|
1400
|
+
}, z.core.$strip>], "action">;
|
|
1401
|
+
};
|
|
1402
|
+
chunk: z.ZodObject<{
|
|
1403
|
+
eventType: z.ZodLiteral<"chunk">;
|
|
1404
|
+
id: z.ZodString;
|
|
1405
|
+
choices: z.ZodArray<z.ZodObject<{
|
|
1406
|
+
delta: z.ZodObject<{
|
|
1407
|
+
content: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1408
|
+
role: z.ZodOptional<z.ZodEnum<{
|
|
1409
|
+
assistant: "assistant";
|
|
1410
|
+
user: "user";
|
|
1411
|
+
system: "system";
|
|
1412
|
+
tool: "tool";
|
|
1413
|
+
developer: "developer";
|
|
1414
|
+
}>>;
|
|
1415
|
+
refusal: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1416
|
+
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1417
|
+
index: z.ZodNumber;
|
|
1418
|
+
id: z.ZodOptional<z.ZodString>;
|
|
1419
|
+
type: z.ZodOptional<z.ZodLiteral<"function">>;
|
|
1420
|
+
function: z.ZodOptional<z.ZodObject<{
|
|
1421
|
+
name: z.ZodOptional<z.ZodString>;
|
|
1422
|
+
arguments: z.ZodOptional<z.ZodString>;
|
|
1423
|
+
}, z.core.$strip>>;
|
|
1424
|
+
}, z.core.$strip>>>;
|
|
1425
|
+
}, z.core.$strip>;
|
|
1426
|
+
index: z.ZodNumber;
|
|
1427
|
+
finish_reason: z.ZodNullable<z.ZodEnum<{
|
|
1428
|
+
tool_calls: "tool_calls";
|
|
1429
|
+
stop: "stop";
|
|
1430
|
+
length: "length";
|
|
1431
|
+
content_filter: "content_filter";
|
|
1432
|
+
function_call: "function_call";
|
|
1433
|
+
}>>;
|
|
1434
|
+
logprobs: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
|
|
1435
|
+
}, z.core.$strip>>;
|
|
1436
|
+
created: z.ZodNumber;
|
|
1437
|
+
model: z.ZodString;
|
|
1438
|
+
object: z.ZodLiteral<"chat.completion.chunk">;
|
|
1439
|
+
service_tier: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
1440
|
+
default: "default";
|
|
1441
|
+
auto: "auto";
|
|
1442
|
+
flex: "flex";
|
|
1443
|
+
scale: "scale";
|
|
1444
|
+
priority: "priority";
|
|
1445
|
+
}>>>;
|
|
1446
|
+
system_fingerprint: z.ZodOptional<z.ZodString>;
|
|
1447
|
+
}, z.core.$strip>;
|
|
1448
|
+
usage: z.ZodObject<{
|
|
1449
|
+
eventType: z.ZodLiteral<"usage">;
|
|
1450
|
+
prompt_tokens: z.ZodNumber;
|
|
1451
|
+
completion_tokens: z.ZodNumber;
|
|
1452
|
+
total_tokens: z.ZodNumber;
|
|
1453
|
+
prompt_tokens_details: z.ZodOptional<z.ZodObject<{
|
|
1454
|
+
audio_tokens: z.ZodOptional<z.ZodNumber>;
|
|
1455
|
+
cached_tokens: z.ZodOptional<z.ZodNumber>;
|
|
1456
|
+
}, z.core.$strip>>;
|
|
1457
|
+
completion_tokens_details: z.ZodOptional<z.ZodObject<{
|
|
1458
|
+
accepted_prediction_tokens: z.ZodOptional<z.ZodNumber>;
|
|
1459
|
+
audio_tokens: z.ZodOptional<z.ZodNumber>;
|
|
1460
|
+
reasoning_tokens: z.ZodOptional<z.ZodNumber>;
|
|
1461
|
+
rejected_prediction_tokens: z.ZodOptional<z.ZodNumber>;
|
|
1462
|
+
}, z.core.$strip>>;
|
|
1463
|
+
}, z.core.$strip>;
|
|
1464
|
+
message_complete: z.ZodObject<{
|
|
1465
|
+
eventType: z.ZodLiteral<"message_complete">;
|
|
1466
|
+
content: z.ZodNullable<z.ZodString>;
|
|
1467
|
+
reasoning: z.ZodOptional<z.ZodString>;
|
|
1468
|
+
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1469
|
+
id: z.ZodString;
|
|
1470
|
+
type: z.ZodLiteral<"function">;
|
|
1471
|
+
function: z.ZodObject<{
|
|
1472
|
+
name: z.ZodString;
|
|
1473
|
+
arguments: z.ZodString;
|
|
1474
|
+
}, z.core.$strip>;
|
|
1475
|
+
}, z.core.$strip>>>;
|
|
1476
|
+
finish_reason: z.ZodNullable<z.ZodEnum<{
|
|
1477
|
+
tool_calls: "tool_calls";
|
|
1478
|
+
stop: "stop";
|
|
1479
|
+
length: "length";
|
|
1480
|
+
content_filter: "content_filter";
|
|
1481
|
+
function_call: "function_call";
|
|
1482
|
+
}>>;
|
|
1483
|
+
}, z.core.$strip>;
|
|
1484
|
+
reasoning_delta: z.ZodObject<{
|
|
1485
|
+
eventType: z.ZodLiteral<"reasoning_delta">;
|
|
1486
|
+
content: z.ZodString;
|
|
1487
|
+
}, z.core.$strip>;
|
|
1488
|
+
reasoning_complete: z.ZodObject<{
|
|
1489
|
+
eventType: z.ZodLiteral<"reasoning_complete">;
|
|
1490
|
+
content: z.ZodString;
|
|
1491
|
+
}, z.core.$strip>;
|
|
1492
|
+
tool_calls: z.ZodObject<{
|
|
1493
|
+
eventType: z.ZodLiteral<"tool_calls">;
|
|
1494
|
+
toolCalls: z.ZodArray<z.ZodObject<{
|
|
1495
|
+
id: z.ZodString;
|
|
1496
|
+
type: z.ZodLiteral<"function">;
|
|
1497
|
+
function: z.ZodObject<{
|
|
1498
|
+
name: z.ZodString;
|
|
1499
|
+
arguments: z.ZodString;
|
|
1500
|
+
}, z.core.$strip>;
|
|
1501
|
+
}, z.core.$strip>>;
|
|
1502
|
+
}, z.core.$strip>;
|
|
1503
|
+
tool_started: z.ZodObject<{
|
|
1504
|
+
eventType: z.ZodLiteral<"tool_started">;
|
|
1505
|
+
toolName: z.ZodString;
|
|
1506
|
+
toolCallId: z.ZodString;
|
|
1507
|
+
}, z.core.$strip>;
|
|
1508
|
+
tool_completed: z.ZodObject<{
|
|
1509
|
+
eventType: z.ZodLiteral<"tool_completed">;
|
|
1510
|
+
toolName: z.ZodString;
|
|
1511
|
+
toolCallId: z.ZodString;
|
|
1512
|
+
result: z.ZodString;
|
|
1513
|
+
success: z.ZodBoolean;
|
|
1514
|
+
}, z.core.$strip>;
|
|
1515
|
+
agent_started: z.ZodObject<{
|
|
1516
|
+
eventType: z.ZodLiteral<"agent_started">;
|
|
1517
|
+
model: z.ZodOptional<z.ZodString>;
|
|
1518
|
+
}, z.core.$strip>;
|
|
1519
|
+
agent_complete: z.ZodObject<{
|
|
1520
|
+
eventType: z.ZodLiteral<"agent_complete">;
|
|
1521
|
+
message: z.ZodOptional<z.ZodString>;
|
|
1522
|
+
error: z.ZodOptional<z.ZodString>;
|
|
1523
|
+
}, z.core.$strip>;
|
|
1524
|
+
error: z.ZodObject<{
|
|
1525
|
+
eventType: z.ZodLiteral<"error">;
|
|
1526
|
+
message: z.ZodString;
|
|
1527
|
+
code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
1528
|
+
type: z.ZodOptional<z.ZodString>;
|
|
1529
|
+
}, z.core.$strip>;
|
|
1530
|
+
'turn.state_changed': z.ZodObject<{
|
|
1531
|
+
adapterId: z.ZodString;
|
|
1532
|
+
agentId: z.ZodString;
|
|
1533
|
+
oldState: z.ZodEnum<{
|
|
1534
|
+
idle: "idle";
|
|
1535
|
+
turn_started: "turn_started";
|
|
1536
|
+
step_started: "step_started";
|
|
1537
|
+
step_finished: "step_finished";
|
|
1538
|
+
turn_finished: "turn_finished";
|
|
1539
|
+
}>;
|
|
1540
|
+
newState: z.ZodEnum<{
|
|
1541
|
+
idle: "idle";
|
|
1542
|
+
turn_started: "turn_started";
|
|
1543
|
+
step_started: "step_started";
|
|
1544
|
+
step_finished: "step_finished";
|
|
1545
|
+
turn_finished: "turn_finished";
|
|
1546
|
+
}>;
|
|
1547
|
+
timestamp: z.ZodNumber;
|
|
1548
|
+
}, z.core.$strip>;
|
|
1549
|
+
'turn.turn_started': z.ZodObject<{
|
|
1550
|
+
adapterId: z.ZodString;
|
|
1551
|
+
agentId: z.ZodString;
|
|
1552
|
+
oldState: z.ZodEnum<{
|
|
1553
|
+
idle: "idle";
|
|
1554
|
+
turn_started: "turn_started";
|
|
1555
|
+
step_started: "step_started";
|
|
1556
|
+
step_finished: "step_finished";
|
|
1557
|
+
turn_finished: "turn_finished";
|
|
1558
|
+
}>;
|
|
1559
|
+
newState: z.ZodEnum<{
|
|
1560
|
+
idle: "idle";
|
|
1561
|
+
turn_started: "turn_started";
|
|
1562
|
+
step_started: "step_started";
|
|
1563
|
+
step_finished: "step_finished";
|
|
1564
|
+
turn_finished: "turn_finished";
|
|
1565
|
+
}>;
|
|
1566
|
+
timestamp: z.ZodNumber;
|
|
1567
|
+
}, z.core.$strip>;
|
|
1568
|
+
'turn.step_started': z.ZodObject<{
|
|
1569
|
+
adapterId: z.ZodString;
|
|
1570
|
+
agentId: z.ZodString;
|
|
1571
|
+
oldState: z.ZodEnum<{
|
|
1572
|
+
idle: "idle";
|
|
1573
|
+
turn_started: "turn_started";
|
|
1574
|
+
step_started: "step_started";
|
|
1575
|
+
step_finished: "step_finished";
|
|
1576
|
+
turn_finished: "turn_finished";
|
|
1577
|
+
}>;
|
|
1578
|
+
newState: z.ZodEnum<{
|
|
1579
|
+
idle: "idle";
|
|
1580
|
+
turn_started: "turn_started";
|
|
1581
|
+
step_started: "step_started";
|
|
1582
|
+
step_finished: "step_finished";
|
|
1583
|
+
turn_finished: "turn_finished";
|
|
1584
|
+
}>;
|
|
1585
|
+
timestamp: z.ZodNumber;
|
|
1586
|
+
}, z.core.$strip>;
|
|
1587
|
+
'turn.step_finished': z.ZodObject<{
|
|
1588
|
+
adapterId: z.ZodString;
|
|
1589
|
+
agentId: z.ZodString;
|
|
1590
|
+
oldState: z.ZodEnum<{
|
|
1591
|
+
idle: "idle";
|
|
1592
|
+
turn_started: "turn_started";
|
|
1593
|
+
step_started: "step_started";
|
|
1594
|
+
step_finished: "step_finished";
|
|
1595
|
+
turn_finished: "turn_finished";
|
|
1596
|
+
}>;
|
|
1597
|
+
newState: z.ZodEnum<{
|
|
1598
|
+
idle: "idle";
|
|
1599
|
+
turn_started: "turn_started";
|
|
1600
|
+
step_started: "step_started";
|
|
1601
|
+
step_finished: "step_finished";
|
|
1602
|
+
turn_finished: "turn_finished";
|
|
1603
|
+
}>;
|
|
1604
|
+
timestamp: z.ZodNumber;
|
|
1605
|
+
}, z.core.$strip>;
|
|
1606
|
+
'turn.turn_finished': z.ZodObject<{
|
|
1607
|
+
adapterId: z.ZodString;
|
|
1608
|
+
agentId: z.ZodString;
|
|
1609
|
+
oldState: z.ZodEnum<{
|
|
1610
|
+
idle: "idle";
|
|
1611
|
+
turn_started: "turn_started";
|
|
1612
|
+
step_started: "step_started";
|
|
1613
|
+
step_finished: "step_finished";
|
|
1614
|
+
turn_finished: "turn_finished";
|
|
1615
|
+
}>;
|
|
1616
|
+
newState: z.ZodEnum<{
|
|
1617
|
+
idle: "idle";
|
|
1618
|
+
turn_started: "turn_started";
|
|
1619
|
+
step_started: "step_started";
|
|
1620
|
+
step_finished: "step_finished";
|
|
1621
|
+
turn_finished: "turn_finished";
|
|
1622
|
+
}>;
|
|
1623
|
+
timestamp: z.ZodNumber;
|
|
1624
|
+
}, z.core.$strip>;
|
|
1625
|
+
}>, "adapter:openai-node">;
|
|
1626
|
+
/**
|
|
1627
|
+
* Scoped bus type for OpenAI Node adapter
|
|
1628
|
+
*/
|
|
1629
|
+
type OpenAINodeConnectorBus = ScopedBus<typeof OPENAI_NODE_NAMESPACE>;
|
|
1630
|
+
//#endregion
|
|
1631
|
+
//#region src/types/index.d.ts
|
|
1632
|
+
/**
|
|
1633
|
+
* OpenAI Node adapter namespace identifier
|
|
1634
|
+
*/
|
|
1635
|
+
declare const OPENAI_NODE_NAMESPACE: "adapter:openai-node";
|
|
1636
|
+
/**
|
|
1637
|
+
* Scoped bus type for OpenAI Node adapter
|
|
1638
|
+
*/
|
|
1639
|
+
type OpenAIBus = ScopedBus<typeof OPENAI_NODE_NAMESPACE>;
|
|
1640
|
+
/**
|
|
1641
|
+
* Provider-specific configuration for the OpenAI Node connector.
|
|
1642
|
+
*
|
|
1643
|
+
* Contains only non-credential settings. Credentials (e.g., `apiKey`) are
|
|
1644
|
+
* resolved at runtime from `providerContext.credentialRefs` via
|
|
1645
|
+
* `resolveConnectorCredentials()` and never appear in this type.
|
|
1646
|
+
*/
|
|
1647
|
+
type OpenAINodeProviderConfig = OpenAINodeProviderSettings;
|
|
1648
|
+
/**
|
|
1649
|
+
* Configuration for an OpenAI Node agent session.
|
|
1650
|
+
*/
|
|
1651
|
+
type OpenAINodeAgentConfig = BaseAgentConnectorConfig<OpenAIBus, OpenAINodeProviderConfig>;
|
|
1652
|
+
/** Tool approval request payload type (extracted from namespace subject) */
|
|
1653
|
+
type ToolApprovalPayload = Omit<ExtractSubjectPayload<typeof OpenAINodeConnectorSubjects.tool_approval>, 'adapterName' | 'adapterId' | 'agentId' | 'adapterSessionId' | 'sessionId'>;
|
|
1654
|
+
/** Tool approval response type (extracted from namespace subject) */
|
|
1655
|
+
type ToolApprovalResponse = ExtractSubjectResponse<typeof OpenAINodeConnectorSubjects.tool_approval>;
|
|
1656
|
+
/** Configuration for OpenAI session lifecycle management */
|
|
1657
|
+
interface OpenAISessionConfig {
|
|
1658
|
+
bus: OpenAINodeConnectorBus;
|
|
1659
|
+
adapterId: string;
|
|
1660
|
+
adapterName: string;
|
|
1661
|
+
/** Agent ID for tool execution attribution */
|
|
1662
|
+
agentId: string;
|
|
1663
|
+
/** Makaio session ID for tool execution context */
|
|
1664
|
+
sessionId?: string;
|
|
1665
|
+
cwd: string;
|
|
1666
|
+
model: string;
|
|
1667
|
+
reasoningEffort?: AIReasoningLevel;
|
|
1668
|
+
/** Timeout for obtaining a stream from chat.completions.create (ms) */
|
|
1669
|
+
streamStartTimeoutMs?: number;
|
|
1670
|
+
env: Record<string, string>;
|
|
1671
|
+
client: OpenAI;
|
|
1672
|
+
openAITools: ChatCompletionTool[];
|
|
1673
|
+
/** Resolved system prompt string to prepend to messages */
|
|
1674
|
+
systemPrompt?: string;
|
|
1675
|
+
/**
|
|
1676
|
+
* Reasoning levels supported by the active model.
|
|
1677
|
+
* Populated by the config factory from the resolved ProviderRecord's model catalog.
|
|
1678
|
+
* Absent when the model does not declare reasoning support.
|
|
1679
|
+
*/
|
|
1680
|
+
supportedReasoningLevels?: ReasoningLevelMap;
|
|
1681
|
+
/**
|
|
1682
|
+
* Directory restrictions for file-system tool execution.
|
|
1683
|
+
* Forwarded as `constraints.allowedDirectories` in every tool call.
|
|
1684
|
+
*/
|
|
1685
|
+
allowedDirectories?: string[];
|
|
1686
|
+
emitSdkEvent: (event: SdkEventMessage) => Promise<void>;
|
|
1687
|
+
handleError: (error: Error, rethrow: boolean) => void;
|
|
1688
|
+
requestToolApproval: (payload: ToolApprovalPayload) => Promise<ToolApprovalResponse>;
|
|
1689
|
+
logLowLevelEvent?: (event: unknown) => void;
|
|
1690
|
+
onTurnStart?: (handle: MessageHandle) => void;
|
|
1691
|
+
onTurnComplete?: (handle: MessageHandle, result: MessageResult) => void;
|
|
1692
|
+
/**
|
|
1693
|
+
* Record one mcp_call invocation in the session tool ledger.
|
|
1694
|
+
* Bound by the connector as a closure over its ledger and current turn number.
|
|
1695
|
+
* @param toolFullName - Namespaced target tool name from the mcp_call args
|
|
1696
|
+
*/
|
|
1697
|
+
recordMcpCall?: (toolFullName: string) => void;
|
|
1698
|
+
}
|
|
1699
|
+
//#endregion
|
|
1700
|
+
//#region src/turn.d.ts
|
|
1701
|
+
/**
|
|
1702
|
+
* Turn state machine for OpenAI SDK.
|
|
1703
|
+
*
|
|
1704
|
+
* Tracks state transitions for a single user message.
|
|
1705
|
+
* Unlike Claude, OpenAI has no true pause/resume - we abort and restart.
|
|
1706
|
+
*
|
|
1707
|
+
* State flow:
|
|
1708
|
+
* idle to turn_started to step_started to step_finished to turn_finished
|
|
1709
|
+
*
|
|
1710
|
+
* On immediate: abort current turn, merge content, start new turn.
|
|
1711
|
+
*/
|
|
1712
|
+
declare class OpenAIConnectorTurn extends ProceduralConnectorTurn<StreamSessionTurnState, OpenAINodeConnectorBus> {
|
|
1713
|
+
private abortController;
|
|
1714
|
+
constructor(bus: OpenAINodeConnectorBus, adapterId: string, adapterName: string, agentId: string, messageHandle: MessageHandle);
|
|
1715
|
+
/**
|
|
1716
|
+
* Get the AbortSignal for this turn.
|
|
1717
|
+
* Pass to OpenAI client for cancellation.
|
|
1718
|
+
* @returns The abort signal for this turn
|
|
1719
|
+
*/
|
|
1720
|
+
getAbortSignal(): AbortSignal;
|
|
1721
|
+
/**
|
|
1722
|
+
* Pause (abort) at next opportunity.
|
|
1723
|
+
* OpenAI doesn't support true pause - we abort and caller restarts with
|
|
1724
|
+
* merged content.
|
|
1725
|
+
* @returns Pause result indicating turn state
|
|
1726
|
+
*/
|
|
1727
|
+
pause(): ReturnType<ProceduralConnectorTurn['pause']>;
|
|
1728
|
+
}
|
|
1729
|
+
//#endregion
|
|
1730
|
+
//#region src/session.d.ts
|
|
1731
|
+
/**
|
|
1732
|
+
* Session for OpenAI SDK lifecycle management.
|
|
1733
|
+
*
|
|
1734
|
+
* Manages OpenAI client calls across multiple user messages:
|
|
1735
|
+
* - Creates Turn instances for each user message
|
|
1736
|
+
* - Handles immediate mode via abort+restart (no true pause)
|
|
1737
|
+
* - Processes message queue with merge support
|
|
1738
|
+
*
|
|
1739
|
+
* Key difference from Claude: OpenAI has no server-side session.
|
|
1740
|
+
* Each turn rebuilds the messages[] array with full history.
|
|
1741
|
+
*/
|
|
1742
|
+
declare class OpenAIConnectorSession extends BaseStreamSession<OpenAISessionConfig, OpenAIConnectorTurn, MessageCompleteEvent> {
|
|
1743
|
+
private messages;
|
|
1744
|
+
/**
|
|
1745
|
+
* Mutable tool list for this session.
|
|
1746
|
+
* Rebuilt whenever either `nativeTools` or `mcpTools` changes.
|
|
1747
|
+
*/
|
|
1748
|
+
private currentTools;
|
|
1749
|
+
/** Latest native registry tools for this live session. */
|
|
1750
|
+
private nativeTools;
|
|
1751
|
+
/**
|
|
1752
|
+
* Latest MCP direct-inject tools converted to OpenAI format.
|
|
1753
|
+
* Stored separately so that `replaceNativeTools` can rebuild `currentTools`
|
|
1754
|
+
* without losing the MCP tool set.
|
|
1755
|
+
*/
|
|
1756
|
+
private mcpTools;
|
|
1757
|
+
/**
|
|
1758
|
+
* Runtime reasoning effort level; updated by `updateReasoning()`.
|
|
1759
|
+
* Initialized from `config.reasoningEffort` at session construction.
|
|
1760
|
+
*/
|
|
1761
|
+
private currentReasoningEffort;
|
|
1762
|
+
/**
|
|
1763
|
+
* Create an OpenAI connector session.
|
|
1764
|
+
* @param config - OpenAI session configuration (bus identity, model/cwd, SDK client, and lifecycle hooks).
|
|
1765
|
+
*/
|
|
1766
|
+
constructor(config: OpenAISessionConfig);
|
|
1767
|
+
/**
|
|
1768
|
+
* Replace the native registry tool set used for subsequent turns.
|
|
1769
|
+
*
|
|
1770
|
+
* Rebuilds `currentTools` so that MCP tools registered via `updateTools`
|
|
1771
|
+
* are preserved alongside the new native tools.
|
|
1772
|
+
* @param tools - Fresh OpenAI-formatted native tools
|
|
1773
|
+
*/
|
|
1774
|
+
replaceNativeTools(tools: ChatCompletionTool[]): void;
|
|
1775
|
+
/**
|
|
1776
|
+
* Update the session's tool set for the next API call.
|
|
1777
|
+
*
|
|
1778
|
+
* Converts generic `ToolListItem[]` (MCP direct-inject tools) to
|
|
1779
|
+
* OpenAI `ChatCompletionTool[]` format and merges them with the existing native tools.
|
|
1780
|
+
* @param tools - New MCP direct-inject tools in generic format
|
|
1781
|
+
*/
|
|
1782
|
+
updateTools(tools: ToolListItem[]): void;
|
|
1783
|
+
/**
|
|
1784
|
+
* Update the reasoning effort level used for subsequent API calls.
|
|
1785
|
+
*
|
|
1786
|
+
* Called by the connector's `changeReasoningInPlace()` to sync the session
|
|
1787
|
+
* with the connector-level reasoning effort without requiring a full session
|
|
1788
|
+
* swap. The updated value is picked up by `executeApiCall` on the next turn.
|
|
1789
|
+
* @internal Direct calls bypass capability validation — only the mutation
|
|
1790
|
+
* manager should call this (via the connector's `changeReasoningInPlace`).
|
|
1791
|
+
* @param level - New reasoning effort level
|
|
1792
|
+
*/
|
|
1793
|
+
updateReasoning(level: AIReasoningLevel): void;
|
|
1794
|
+
/**
|
|
1795
|
+
* Return the names of all tools that would be sent in the next API call.
|
|
1796
|
+
*
|
|
1797
|
+
* Reflects the merged set of native and MCP tools after any `replaceNativeTools`
|
|
1798
|
+
* or `updateTools` calls.
|
|
1799
|
+
* @returns Ordered list of tool names matching the next API request
|
|
1800
|
+
*/
|
|
1801
|
+
protected getEffectiveToolNames(): string[];
|
|
1802
|
+
/**
|
|
1803
|
+
* Create an OpenAI connector turn for the given message handle.
|
|
1804
|
+
* @param handle - The message handle this turn will process
|
|
1805
|
+
* @returns A new `OpenAIConnectorTurn` instance
|
|
1806
|
+
*/
|
|
1807
|
+
protected createTurn(handle: MessageHandle): OpenAIConnectorTurn;
|
|
1808
|
+
/**
|
|
1809
|
+
* Validate that content is non-empty after trim.
|
|
1810
|
+
* Throws an Error with a descriptive message if content is empty.
|
|
1811
|
+
* @param content - Content string to validate
|
|
1812
|
+
* @param messageId - Message ID for error context
|
|
1813
|
+
* @param context - Additional context for the error message
|
|
1814
|
+
*/
|
|
1815
|
+
private throwIfEmptyContent;
|
|
1816
|
+
/**
|
|
1817
|
+
* Build the messages array from handle history and optional merged content.
|
|
1818
|
+
*
|
|
1819
|
+
* Ensures the configured system prompt is always at index 0 without
|
|
1820
|
+
* duplicating existing history system entries.
|
|
1821
|
+
* @param handle - The message handle containing history
|
|
1822
|
+
* @param mergedContent - Optional content from superseded/merged messages
|
|
1823
|
+
*/
|
|
1824
|
+
protected buildMessages(handle: MessageHandle, mergedContent?: string[]): void;
|
|
1825
|
+
/**
|
|
1826
|
+
* Execute the OpenAI streaming API call.
|
|
1827
|
+
*
|
|
1828
|
+
* Calls `client.chat.completions.create` with the current messages array
|
|
1829
|
+
* and pipes the resulting stream through the stream-bridge event emitter.
|
|
1830
|
+
* @param turn - Captured turn instance for this run loop
|
|
1831
|
+
* @param abortSignal - Combined abort signal (turn abort + stream timeout)
|
|
1832
|
+
* @param adapterSessionId - Turn-scoped adapter session ID for event correlation
|
|
1833
|
+
*/
|
|
1834
|
+
protected executeApiCall(turn: OpenAIConnectorTurn, abortSignal: AbortSignal, adapterSessionId: string): Promise<void>;
|
|
1835
|
+
/**
|
|
1836
|
+
* Return the OpenAI Node event bus subject for `message_complete` waiting.
|
|
1837
|
+
* @returns The `sdk.event` subject for the OpenAI adapter namespace
|
|
1838
|
+
*/
|
|
1839
|
+
protected getSdkEventSubject(): ScopedSubjectDefinition<string>;
|
|
1840
|
+
/**
|
|
1841
|
+
* Apply a `message_complete` event to the OpenAI messages array and recurse
|
|
1842
|
+
* for tool calls.
|
|
1843
|
+
*
|
|
1844
|
+
* Appends the assistant response as a `ChatCompletionMessageParam`. When
|
|
1845
|
+
* `finish_reason` is `'tool_calls'`, executes tools and continues the loop.
|
|
1846
|
+
* @param result - The parsed OpenAI `message_complete` event
|
|
1847
|
+
* @param currentHandle - The active message handle
|
|
1848
|
+
* @param toolCallIteration - Current tool recursion depth
|
|
1849
|
+
* @param turn - Captured turn instance for this run loop
|
|
1850
|
+
*/
|
|
1851
|
+
protected applyMessageComplete(result: MessageCompleteEvent, currentHandle: MessageHandle, toolCallIteration: number, turn: OpenAIConnectorTurn): Promise<void>;
|
|
1852
|
+
/**
|
|
1853
|
+
* Classify an OpenAI SDK error into the appropriate Makaio error type.
|
|
1854
|
+
* @param error - The raw error from the OpenAI SDK
|
|
1855
|
+
* @returns A classified `Error` instance
|
|
1856
|
+
*/
|
|
1857
|
+
protected classifyError(error: unknown): Error;
|
|
1858
|
+
}
|
|
1859
|
+
//#endregion
|
|
1860
|
+
//#region src/connector.d.ts
|
|
1861
|
+
/**
|
|
1862
|
+
* OpenAI Node Agent - Wraps the OpenAI SDK for agentic chat completions.
|
|
1863
|
+
*
|
|
1864
|
+
* Implements the agentic loop pattern:
|
|
1865
|
+
* 1. Send user message to OpenAI
|
|
1866
|
+
* 2. Process streaming response
|
|
1867
|
+
* 3. If tool_calls present, execute tools via Bus RPC and recurse
|
|
1868
|
+
* 4. When no tool_calls, mark turn complete
|
|
1869
|
+
*
|
|
1870
|
+
* Tools are fetched from ToolRegistry via MakaioBus.request(ToolSubjects.list)
|
|
1871
|
+
* on the first turn. Tool execution routes through MakaioBus.request(ToolSubjects.execute)
|
|
1872
|
+
* to the ToolRegistry, which validates input and executes the tool handler.
|
|
1873
|
+
*
|
|
1874
|
+
* Credential resolution happens in `fetchTools()` (the first async lifecycle hook)
|
|
1875
|
+
* via `resolveConnectorCredentials()`. Plaintext credentials are stored in instance
|
|
1876
|
+
* fields and never leave the connector.
|
|
1877
|
+
*/
|
|
1878
|
+
declare class OpenAINodeConnector extends BaseStreamConnector<OpenAIBus, OpenAIConnectorSession, OpenAINodeAgentConfig> {
|
|
1879
|
+
/** Resolved API key (populated in fetchTools before createSession is called). */
|
|
1880
|
+
private resolvedApiKey;
|
|
1881
|
+
private client?;
|
|
1882
|
+
/** OpenAI-format tools for chat completions API (fetched from bus on first turn) */
|
|
1883
|
+
private openAITools;
|
|
1884
|
+
/**
|
|
1885
|
+
* Emit an SDK event wrapped in envelope for type-safe discriminated union handling.
|
|
1886
|
+
* Pattern matches codex-mcp's \{ id, msg \} envelope.
|
|
1887
|
+
* @param event - The typed SDK event message to emit
|
|
1888
|
+
*/
|
|
1889
|
+
private emitSdkEvent;
|
|
1890
|
+
constructor(config: OpenAINodeAgentConfig & {
|
|
1891
|
+
adapterId?: string;
|
|
1892
|
+
});
|
|
1893
|
+
/**
|
|
1894
|
+
* Resolve credentials and fetch available tools from the bus.
|
|
1895
|
+
*
|
|
1896
|
+
* Resolves `apiKey` from `providerContext.credentialRefs` via the encrypted
|
|
1897
|
+
* credential channel, then initializes the OpenAI SDK client. Called once
|
|
1898
|
+
* by `BaseStreamConnector.initializeSession()` before `createSession()`.
|
|
1899
|
+
*
|
|
1900
|
+
* Also converts fetched tools to OpenAI format and caches them in
|
|
1901
|
+
* `this.openAITools` for use in `createSession`.
|
|
1902
|
+
*/
|
|
1903
|
+
protected fetchTools(): Promise<void>;
|
|
1904
|
+
/**
|
|
1905
|
+
* Re-fetch native tools and re-resolve MCP direct-inject tools.
|
|
1906
|
+
*
|
|
1907
|
+
* Called at turn boundary when `hasPendingToolRefresh` is true.
|
|
1908
|
+
* Re-fetches OpenAI-format tools from the registry, re-prepares MCP
|
|
1909
|
+
* direct tools (and arms the ledger injection flag via `super.refreshTools()`),
|
|
1910
|
+
* then notifies the active session so the next API call uses the updated
|
|
1911
|
+
* merged tool list. The ledger `recordInjection` is deferred to
|
|
1912
|
+
* `onTurnStarted` so it uses the canonical turn number.
|
|
1913
|
+
*/
|
|
1914
|
+
protected refreshTools(): Promise<void>;
|
|
1915
|
+
/**
|
|
1916
|
+
* Construct the OpenAI connector session with all required config.
|
|
1917
|
+
*
|
|
1918
|
+
* Called by `BaseStreamConnector.initializeSession()` after `fetchTools()`
|
|
1919
|
+
* has resolved credentials and initialized `this.client`.
|
|
1920
|
+
* @returns A new `OpenAIConnectorSession` instance
|
|
1921
|
+
*/
|
|
1922
|
+
protected createSession(): OpenAIConnectorSession;
|
|
1923
|
+
/**
|
|
1924
|
+
* Get OpenAI namespace turn subjects.
|
|
1925
|
+
* @returns Turn subject definitions
|
|
1926
|
+
*/
|
|
1927
|
+
protected getTurnSubjects(): WireSessionSubjects<OpenAIBus['namespace']>;
|
|
1928
|
+
}
|
|
1929
|
+
//#endregion
|
|
1930
|
+
//#region src/agent.d.ts
|
|
1931
|
+
/**
|
|
1932
|
+
* Subject spec for the OpenAI Node adapter, satisfying `StreamAdapterSubjectSpec`.
|
|
1933
|
+
*
|
|
1934
|
+
* Scoped to the OpenAI Node connector namespace. Passed as the `TSpec` type parameter
|
|
1935
|
+
* to `BaseStreamAgent` so shared wire methods resolve handler types correctly.
|
|
1936
|
+
*/
|
|
1937
|
+
type OpenAISubjectSpec = StreamAdapterSubjectSpec<typeof OpenAINodeConnectorSubjects.chunk.$meta.namespace>;
|
|
1938
|
+
/**
|
|
1939
|
+
* OpenAI Agent - Middle layer between AIAdapter and OpenAINodeConnector.
|
|
1940
|
+
*
|
|
1941
|
+
* Responsibilities:
|
|
1942
|
+
* 1. Wire connector's scoped bus events to global agent.* subjects
|
|
1943
|
+
* 2. Auto-enrich payloads with AgentContext via emitGlobal()
|
|
1944
|
+
*
|
|
1945
|
+
* Event Flow:
|
|
1946
|
+
* - OpenAINodeConnector emits to semantic subjects (chunk, usage, etc.)
|
|
1947
|
+
* - OpenAIAgent subscribes to semantic subjects and emits to global bus (agent.*)
|
|
1948
|
+
* - Downstream consumers subscribe to normalized agent.* subjects
|
|
1949
|
+
*
|
|
1950
|
+
* Extends `BaseStreamAgent` which provides all shared wiring logic. This class only
|
|
1951
|
+
* implements the adapter-specific abstract hooks.
|
|
1952
|
+
*/
|
|
1953
|
+
declare class OpenAIAgent extends BaseStreamAgent<OpenAINodeConnectorBus, OpenAINodeConnector, OpenAISubjectSpec> {
|
|
1954
|
+
/**
|
|
1955
|
+
* Tier 1: Route sdk.event catch-all to typed semantic subjects.
|
|
1956
|
+
*
|
|
1957
|
+
* Uses `createConnectorEventMapping` for type-safe discriminated union routing.
|
|
1958
|
+
* Pattern matches codex-mcp: envelope `{ id, event }` with nestedMessageProp 'event'.
|
|
1959
|
+
*/
|
|
1960
|
+
protected wireSdkEvents(): void;
|
|
1961
|
+
/**
|
|
1962
|
+
* Return the OpenAI Node adapter's connector subject spec.
|
|
1963
|
+
*
|
|
1964
|
+
* Maps adapter subject constants to the `StreamAdapterSubjectSpec` interface used
|
|
1965
|
+
* by `BaseStreamAgent` to subscribe to semantic events.
|
|
1966
|
+
* @returns OpenAI-specific subject spec
|
|
1967
|
+
*/
|
|
1968
|
+
protected getConnectorSubjects(): OpenAISubjectSpec;
|
|
1969
|
+
/**
|
|
1970
|
+
* Extract plain text from an OpenAI chunk event payload.
|
|
1971
|
+
*
|
|
1972
|
+
* OpenAI chunk events use the ChatCompletionChunk structure where text content
|
|
1973
|
+
* is at `choices[0].delta.content`.
|
|
1974
|
+
* @param payload - OpenAI chunk event payload
|
|
1975
|
+
* @returns The text content, or empty string when no content is present
|
|
1976
|
+
*/
|
|
1977
|
+
protected extractChunkText(payload: Record<string, unknown>): string;
|
|
1978
|
+
/**
|
|
1979
|
+
* Map an OpenAI usage event payload to the shared `NormalizedCallUsage` format.
|
|
1980
|
+
*
|
|
1981
|
+
* Reads OpenAI-specific nested fields: `prompt_tokens_details.cached_tokens`
|
|
1982
|
+
* and `completion_tokens_details.reasoning_tokens`.
|
|
1983
|
+
* @param payload - OpenAI usage event payload
|
|
1984
|
+
* @returns Normalized usage metrics
|
|
1985
|
+
*/
|
|
1986
|
+
protected extractUsagePayload(payload: Record<string, unknown>): NormalizedCallUsage;
|
|
1987
|
+
/**
|
|
1988
|
+
* Emit context window update after OpenAI usage tracking.
|
|
1989
|
+
*
|
|
1990
|
+
* Uses `prompt_tokens_details.cached_tokens` for the cached token count and
|
|
1991
|
+
* defaults to 128,000 tokens (standard GPT-4o context window).
|
|
1992
|
+
* @param payload - OpenAI usage event payload
|
|
1993
|
+
*/
|
|
1994
|
+
protected emitUsageContextWindowUpdate(payload: Record<string, unknown>): Promise<void>;
|
|
1995
|
+
/**
|
|
1996
|
+
* Reserve a block index for a tool call using the local internal counter.
|
|
1997
|
+
*
|
|
1998
|
+
* OpenAI does not provide provider-native block indices on tool calls, so we
|
|
1999
|
+
* allocate the current counter value and increment to reserve the slot.
|
|
2000
|
+
* @param _tc - OpenAI tool call entry (blockIndex not used)
|
|
2001
|
+
* @returns Current block index (incremented after return by base class via `afterToolCallStepEmitted`)
|
|
2002
|
+
*/
|
|
2003
|
+
protected reserveToolCallBlockIndex(_tc: ToolCall): number;
|
|
2004
|
+
/**
|
|
2005
|
+
* Increment the block index after emitting a tool call step.
|
|
2006
|
+
*
|
|
2007
|
+
* OpenAI uses the local counter, so we must explicitly reserve the slot by
|
|
2008
|
+
* incrementing after the step has been emitted.
|
|
2009
|
+
* @param _blockIndex - The block index just emitted (unused; counter manages state)
|
|
2010
|
+
*/
|
|
2011
|
+
protected afterToolCallStepEmitted(_blockIndex: number): void;
|
|
2012
|
+
/**
|
|
2013
|
+
* Return `-1` as the fallback block index when no map entry exists for a toolCallId.
|
|
2014
|
+
*
|
|
2015
|
+
* OpenAI uses a sentinel value of `-1` to indicate an unknown index, which is
|
|
2016
|
+
* distinguishable from any valid (non-negative) provider block index.
|
|
2017
|
+
* @returns `-1` sentinel value
|
|
2018
|
+
*/
|
|
2019
|
+
protected getFallbackToolCompletedBlockIndex(): number;
|
|
2020
|
+
/**
|
|
2021
|
+
* No-op: OpenAI does not need post-step index reconciliation.
|
|
2022
|
+
*
|
|
2023
|
+
* The internal block index was already incremented inside `afterToolCallStepEmitted`,
|
|
2024
|
+
* so no reconciliation is needed after tool_completed.
|
|
2025
|
+
* @param _resolvedBlockIndex - Unused
|
|
2026
|
+
*/
|
|
2027
|
+
protected afterToolCompletedStepEmitted(_resolvedBlockIndex: number): void;
|
|
2028
|
+
/**
|
|
2029
|
+
* Build the reasoning `SessionMessageBlock` from an OpenAI reasoning_complete payload.
|
|
2030
|
+
*
|
|
2031
|
+
* OpenAI reasoning events do not carry a `signature` field, so the block
|
|
2032
|
+
* contains only `{ type, content }` without metadata.
|
|
2033
|
+
* @param payload - OpenAI reasoning complete event payload
|
|
2034
|
+
* @returns Plain reasoning block without signature metadata
|
|
2035
|
+
*/
|
|
2036
|
+
protected buildReasoningBlock(payload: Record<string, unknown>): SessionMessageBlock;
|
|
2037
|
+
/**
|
|
2038
|
+
* Wire tool approval RPC from connector's scoped bus to global AgentSubjects.toolApprove.
|
|
2039
|
+
*
|
|
2040
|
+
* Uses centralized tool-handling helper for consistent approval flow.
|
|
2041
|
+
* Uses lazy callback to resolve adapterSessionId at request time (not constructor time).
|
|
2042
|
+
* @param connector - The OpenAINodeConnector to wire RPC from
|
|
2043
|
+
*/
|
|
2044
|
+
protected wireToolApprovalRpc(connector: OpenAINodeConnector): void;
|
|
2045
|
+
}
|
|
2046
|
+
//#endregion
|
|
2047
|
+
//#region src/constants.d.ts
|
|
2048
|
+
/** Adapter name constant for consistent identification */
|
|
2049
|
+
declare const OpenAINodeAdapterName = "openai-node";
|
|
2050
|
+
//#endregion
|
|
2051
|
+
//#region src/adapter.d.ts
|
|
2052
|
+
/**
|
|
2053
|
+
* OpenAI Adapter - Domain-level adapter using the three-layer architecture.
|
|
2054
|
+
*
|
|
2055
|
+
* Architecture:
|
|
2056
|
+
* ```
|
|
2057
|
+
* OpenAIAdapter extends AIAdapter
|
|
2058
|
+
* -> creates via agentFactory()
|
|
2059
|
+
* OpenAIAgent extends AIAgent
|
|
2060
|
+
* -> creates via connectorFactory()
|
|
2061
|
+
* OpenAINodeConnector extends AIAgentConnector
|
|
2062
|
+
* ```
|
|
2063
|
+
*
|
|
2064
|
+
* Responsibilities:
|
|
2065
|
+
* - Handle adapter.startAgent RPC (inherited from AIAdapter)
|
|
2066
|
+
* - Create OpenAIAgent instances with proper configuration
|
|
2067
|
+
* - Emit adapter.initialized and adapter.session.created events
|
|
2068
|
+
* - Manage agent lifecycle (tracking, disposal)
|
|
2069
|
+
* @example
|
|
2070
|
+
* ```typescript
|
|
2071
|
+
* // Using the class directly
|
|
2072
|
+
* const adapter = new OpenAIAdapter();
|
|
2073
|
+
* await adapter.init();
|
|
2074
|
+
*
|
|
2075
|
+
* // Using the convenience factory
|
|
2076
|
+
* const adapter = await createOpenAINodeAdapter();
|
|
2077
|
+
* ```
|
|
2078
|
+
*/
|
|
2079
|
+
declare class OpenAIAdapter extends AIAdapter<OpenAINodeConnectorBus, OpenAINodeConnector, OpenAIAgent> {
|
|
2080
|
+
constructor(config?: Partial<AIAdapterConfig>);
|
|
2081
|
+
/**
|
|
2082
|
+
* Fetch available models from OpenAI-compatible /v1/models endpoint.
|
|
2083
|
+
*
|
|
2084
|
+
* Normalizes responses from various providers (OpenAI, NanoGPT, Z.AI, Kimi, etc.)
|
|
2085
|
+
* to a consistent AIModel[] format.
|
|
2086
|
+
* @param baseUrl - Optional base URL for the provider (defaults to OpenAI)
|
|
2087
|
+
* @param credentials - Optional credentials object with apiKey
|
|
2088
|
+
* @returns Array of normalized model objects
|
|
2089
|
+
* @throws Error if the API request fails
|
|
2090
|
+
*/
|
|
2091
|
+
fetchModels(baseUrl?: string, credentials?: Record<string, string>): Promise<DiscoveredAIModel[]>;
|
|
2092
|
+
}
|
|
2093
|
+
/**
|
|
2094
|
+
* Factory function to create and initialize an OpenAI adapter.
|
|
2095
|
+
*
|
|
2096
|
+
* Convenience wrapper that creates the adapter and calls init() for you.
|
|
2097
|
+
* @param config - Optional adapter configuration
|
|
2098
|
+
* @returns Initialized OpenAIAdapter instance
|
|
2099
|
+
* @example
|
|
2100
|
+
* ```typescript
|
|
2101
|
+
* const adapter = await createOpenAINodeAdapter();
|
|
2102
|
+
*
|
|
2103
|
+
* // Adapter is ready to handle requests via bus
|
|
2104
|
+
* // e.g., MakaioBus.request(AdapterSubjects.startAgent, { adapterId: adapter.adapterId, ... })
|
|
2105
|
+
* ```
|
|
2106
|
+
*/
|
|
2107
|
+
declare function createOpenAINodeAdapter(config?: Partial<AIAdapterConfig>): Promise<OpenAIAdapter>;
|
|
2108
|
+
//#endregion
|
|
2109
|
+
//#region src/index.d.ts
|
|
2110
|
+
/**
|
|
2111
|
+
* Creates test configuration for conformance test suite.
|
|
2112
|
+
* Sets up scoped bus and tool approval proxy.
|
|
2113
|
+
* @param options - Provider definitions supplied by the conformance harness
|
|
2114
|
+
* @returns Configuration for running conformance tests against this adapter
|
|
2115
|
+
*/
|
|
2116
|
+
declare const createTestConfig: (options?: CreateConformanceTestConfigOptions) => Promise<ConformanceTestConfig<OpenAINodeConnectorBus, OpenAINodeConnector, OpenAIAgent>>;
|
|
2117
|
+
//#endregion
|
|
2118
|
+
export { OPENAI_NODE_NAMESPACE, OpenAIAdapter, OpenAIAgent, OpenAIConnectorSession, OpenAIConnectorTurn, OpenAINodeAdapterName, OpenAINodeConnector, type OpenAINodeConnectorBus, OpenAINodeConnectorNamespace, OpenAINodeConnectorSubjects, type OpenAISessionConfig, type SdkEvent, UserMessageQueue, createOpenAINodeAdapter, createTestConfig };
|