@meshagent/meshagent-agents 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/LICENSE +1 -0
- package/README.md +206 -0
- package/dist/browser/agent-messages.d.ts +343 -0
- package/dist/browser/agent-messages.js +1015 -0
- package/dist/browser/change-emitter.d.ts +8 -0
- package/dist/browser/change-emitter.js +20 -0
- package/dist/browser/chat-client.d.ts +225 -0
- package/dist/browser/chat-client.js +642 -0
- package/dist/browser/images-dataset.d.ts +83 -0
- package/dist/browser/images-dataset.js +282 -0
- package/dist/browser/index.d.ts +6 -0
- package/dist/browser/index.js +22 -0
- package/dist/browser/package.json +1 -0
- package/dist/browser/room-shell-toolkit.d.ts +14 -0
- package/dist/browser/room-shell-toolkit.js +274 -0
- package/dist/browser/room-storage-toolkit.d.ts +11 -0
- package/dist/browser/room-storage-toolkit.js +513 -0
- package/dist/browser/thread-storage.d.ts +102 -0
- package/dist/browser/thread-storage.js +476 -0
- package/dist/esm/agent-messages.d.ts +343 -0
- package/dist/esm/agent-messages.js +989 -0
- package/dist/esm/change-emitter.d.ts +8 -0
- package/dist/esm/change-emitter.js +16 -0
- package/dist/esm/chat-client.d.ts +225 -0
- package/dist/esm/chat-client.js +632 -0
- package/dist/esm/images-dataset.d.ts +83 -0
- package/dist/esm/images-dataset.js +274 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/room-shell-toolkit.d.ts +14 -0
- package/dist/esm/room-shell-toolkit.js +270 -0
- package/dist/esm/room-storage-toolkit.d.ts +11 -0
- package/dist/esm/room-storage-toolkit.js +509 -0
- package/dist/esm/thread-storage.d.ts +102 -0
- package/dist/esm/thread-storage.js +465 -0
- package/dist/node/agent-messages.d.ts +343 -0
- package/dist/node/agent-messages.js +1015 -0
- package/dist/node/change-emitter.d.ts +8 -0
- package/dist/node/change-emitter.js +20 -0
- package/dist/node/chat-client.d.ts +225 -0
- package/dist/node/chat-client.js +642 -0
- package/dist/node/images-dataset.d.ts +83 -0
- package/dist/node/images-dataset.js +282 -0
- package/dist/node/index.d.ts +6 -0
- package/dist/node/index.js +22 -0
- package/dist/node/package.json +1 -0
- package/dist/node/room-shell-toolkit.d.ts +14 -0
- package/dist/node/room-shell-toolkit.js +274 -0
- package/dist/node/room-storage-toolkit.d.ts +11 -0
- package/dist/node/room-storage-toolkit.js +513 -0
- package/dist/node/thread-storage.d.ts +102 -0
- package/dist/node/thread-storage.js +476 -0
- package/package.json +57 -0
|
@@ -0,0 +1,989 @@
|
|
|
1
|
+
import { BinaryContent, ControlContent, EmptyContent, ErrorContent, FileContent, JsonContent, LinkContent, TextContent, packMessage, unpackContent, unpackMessage, } from "@meshagent/meshagent";
|
|
2
|
+
import { v4 as uuidv4 } from "uuid";
|
|
3
|
+
export const agentRoomMessageType = "agent-message";
|
|
4
|
+
export const agentTurnStartType = "meshagent.agent.turn.start";
|
|
5
|
+
export const agentTurnSteerType = "meshagent.agent.turn.steer";
|
|
6
|
+
export const agentTurnInterruptType = "meshagent.agent.turn.interrupt";
|
|
7
|
+
export const agentThreadClearType = "meshagent.agent.thread.clear";
|
|
8
|
+
export const agentRealtimeAudioChunkType = "meshagent.agent.realtime_audio.chunk";
|
|
9
|
+
export const agentRealtimeAudioCommitType = "meshagent.agent.realtime_audio.commit";
|
|
10
|
+
export const agentThreadStartType = "meshagent.agent.thread.start";
|
|
11
|
+
export const agentThreadStartedType = "meshagent.agent.thread.started";
|
|
12
|
+
export const agentThreadLoadedType = "meshagent.agent.thread.loaded";
|
|
13
|
+
export const agentThreadStartRejectedType = "meshagent.agent.thread.start.rejected";
|
|
14
|
+
export const agentThreadOpenType = "meshagent.agent.thread.open";
|
|
15
|
+
export const agentThreadCloseType = "meshagent.agent.thread.close";
|
|
16
|
+
export const agentParticipantConnectType = "meshagent.agent.participant.connect";
|
|
17
|
+
export const agentParticipantDisconnectType = "meshagent.agent.participant.disconnect";
|
|
18
|
+
export const agentThreadDeleteType = "meshagent.agent.thread.delete";
|
|
19
|
+
export const agentThreadRenameType = "meshagent.agent.thread.rename";
|
|
20
|
+
export const agentThreadListType = "meshagent.agent.thread.list";
|
|
21
|
+
export const agentThreadListedType = "meshagent.agent.thread.listed";
|
|
22
|
+
export const agentThreadCreatedType = "meshagent.agent.thread.created";
|
|
23
|
+
export const agentThreadUpdatedType = "meshagent.agent.thread.updated";
|
|
24
|
+
export const agentThreadDeletedType = "meshagent.agent.thread.deleted";
|
|
25
|
+
export const agentCapabilitiesRequestType = "meshagent.agent.capabilities_request";
|
|
26
|
+
export const agentCapabilitiesResponseType = "meshagent.agent.capabilities_response";
|
|
27
|
+
export const agentModelsRequestType = "meshagent.agent.models.request";
|
|
28
|
+
export const agentModelsResponseType = "meshagent.agent.models.response";
|
|
29
|
+
export const agentModelChangeType = "meshagent.agent.model.change";
|
|
30
|
+
export const agentModelChangedType = "meshagent.agent.model.changed";
|
|
31
|
+
export const agentThreadClearedType = "meshagent.agent.thread.cleared";
|
|
32
|
+
export const agentTurnStartAcceptedType = "meshagent.agent.turn.start.accepted";
|
|
33
|
+
export const agentTurnStartRejectedType = "meshagent.agent.turn.start.rejected";
|
|
34
|
+
export const agentTurnInterruptAcceptedType = "meshagent.agent.turn.interrupt.accepted";
|
|
35
|
+
export const agentTurnInterruptedType = "meshagent.agent.turn.interrupted";
|
|
36
|
+
export const agentTurnSteerAcceptedType = "meshagent.agent.turn.steer.accepted";
|
|
37
|
+
export const agentTurnSteeredType = "meshagent.agent.turn.steered";
|
|
38
|
+
export const agentTurnSteerRejectedType = "meshagent.agent.turn.steer.rejected";
|
|
39
|
+
export const agentTurnStartedType = "meshagent.agent.turn.started";
|
|
40
|
+
export const agentTurnEndedType = "meshagent.agent.turn.ended";
|
|
41
|
+
export const agentReasoningContentStartedType = "meshagent.agent.reasoning_content.started";
|
|
42
|
+
export const agentReasoningContentDeltaType = "meshagent.agent.reasoning_content.delta";
|
|
43
|
+
export const agentReasoningContentEndedType = "meshagent.agent.reasoning_content.ended";
|
|
44
|
+
export const agentTextContentStartedType = "meshagent.agent.text_content.started";
|
|
45
|
+
export const agentTextContentDeltaType = "meshagent.agent.text_content.delta";
|
|
46
|
+
export const agentTextContentEndedType = "meshagent.agent.text_content.ended";
|
|
47
|
+
export const agentFileContentStartedType = "meshagent.agent.file_content.started";
|
|
48
|
+
export const agentFileContentDeltaType = "meshagent.agent.file_content.delta";
|
|
49
|
+
export const agentFileContentEndedType = "meshagent.agent.file_content.ended";
|
|
50
|
+
export const agentToolCallPendingType = "meshagent.agent.tool_call.pending";
|
|
51
|
+
export const agentToolCallInProgressType = "meshagent.agent.tool_call.in_progress";
|
|
52
|
+
export const agentToolCallStartedType = "meshagent.agent.tool_call.started";
|
|
53
|
+
export const agentToolCallArgumentsDeltaType = "meshagent.agent.tool_call.arguments_delta";
|
|
54
|
+
export const agentToolCallLogDeltaType = "meshagent.agent.tool_call.log_delta";
|
|
55
|
+
export const agentToolCallEndedType = "meshagent.agent.tool_call.ended";
|
|
56
|
+
export const agentToolCallApprovalRequestedType = "meshagent.agent.tool_call.approval_requested";
|
|
57
|
+
export const agentClientToolCallRequestedType = "meshagent.agent.client_tool_call.requested";
|
|
58
|
+
export const agentClientToolCallCancelledType = "meshagent.agent.client_tool_call.cancelled";
|
|
59
|
+
export const agentSecretRequestedType = "meshagent.agent.secret.requested";
|
|
60
|
+
export const agentThreadStatusType = "meshagent.agent.thread.status";
|
|
61
|
+
export const agentConnectionStatusType = "meshagent.agent.connection.status";
|
|
62
|
+
export const agentThreadEventType = "meshagent.agent.thread.event";
|
|
63
|
+
export const agentImageGenerationStartedType = "meshagent.agent.image_generation.started";
|
|
64
|
+
export const agentImageGenerationPartialType = "meshagent.agent.image_generation.partial";
|
|
65
|
+
export const agentImageGenerationCompletedType = "meshagent.agent.image_generation.completed";
|
|
66
|
+
export const agentImageGenerationFailedType = "meshagent.agent.image_generation.failed";
|
|
67
|
+
export const agentAudioGenerationStartedType = "meshagent.agent.audio_generation.started";
|
|
68
|
+
export const agentAudioGenerationDeltaType = "meshagent.agent.audio_generation.delta";
|
|
69
|
+
export const agentAudioGenerationCompletedType = "meshagent.agent.audio_generation.completed";
|
|
70
|
+
export const agentAudioGenerationFailedType = "meshagent.agent.audio_generation.failed";
|
|
71
|
+
export const agentAudioTranscriptionStartedType = "meshagent.agent.audio_transcription.started";
|
|
72
|
+
export const agentAudioTranscriptionDeltaType = "meshagent.agent.audio_transcription.delta";
|
|
73
|
+
export const agentAudioTranscriptionCompletedType = "meshagent.agent.audio_transcription.completed";
|
|
74
|
+
export const agentAudioTranscriptionFailedType = "meshagent.agent.audio_transcription.failed";
|
|
75
|
+
export const agentAudioInputSpeechStartedType = "meshagent.agent.audio_input.speech_started";
|
|
76
|
+
export const agentAudioInputSpeechEndedType = "meshagent.agent.audio_input.speech_ended";
|
|
77
|
+
export const agentContextCompactedType = "meshagent.agent.context.compacted";
|
|
78
|
+
export const agentUsageUpdatedType = "meshagent.agent.usage.updated";
|
|
79
|
+
export const agentToolApproveType = "meshagent.agent.tool_call.approve";
|
|
80
|
+
export const agentToolRejectType = "meshagent.agent.tool_call.reject";
|
|
81
|
+
export const agentSecretResponseType = "meshagent.agent.secret.response";
|
|
82
|
+
export const agentClientToolCallResponseType = "meshagent.agent.client_tool_call.response";
|
|
83
|
+
const globalScope = globalThis;
|
|
84
|
+
function hasOwn(value, key) {
|
|
85
|
+
return Object.prototype.hasOwnProperty.call(value, key);
|
|
86
|
+
}
|
|
87
|
+
function paramValue(params, prop, jsonKey = prop) {
|
|
88
|
+
if (hasOwn(params, prop)) {
|
|
89
|
+
return params[prop];
|
|
90
|
+
}
|
|
91
|
+
return params[jsonKey];
|
|
92
|
+
}
|
|
93
|
+
function bytesToBase64(bytes) {
|
|
94
|
+
if (globalScope.Buffer != null) {
|
|
95
|
+
return globalScope.Buffer.from(bytes).toString("base64");
|
|
96
|
+
}
|
|
97
|
+
if (globalScope.btoa == null) {
|
|
98
|
+
throw new Error("base64 encoding is not available in this runtime");
|
|
99
|
+
}
|
|
100
|
+
let binary = "";
|
|
101
|
+
for (const byte of bytes) {
|
|
102
|
+
binary += String.fromCharCode(byte);
|
|
103
|
+
}
|
|
104
|
+
return globalScope.btoa(binary);
|
|
105
|
+
}
|
|
106
|
+
function base64ToBytes(value) {
|
|
107
|
+
if (globalScope.Buffer != null) {
|
|
108
|
+
return Uint8Array.from(globalScope.Buffer.from(value, "base64"));
|
|
109
|
+
}
|
|
110
|
+
if (globalScope.atob == null) {
|
|
111
|
+
throw new Error("base64 decoding is not available in this runtime");
|
|
112
|
+
}
|
|
113
|
+
const binary = globalScope.atob(value);
|
|
114
|
+
const bytes = new Uint8Array(binary.length);
|
|
115
|
+
for (let index = 0; index < binary.length; index += 1) {
|
|
116
|
+
bytes[index] = binary.charCodeAt(index);
|
|
117
|
+
}
|
|
118
|
+
return bytes;
|
|
119
|
+
}
|
|
120
|
+
function isRecord(value) {
|
|
121
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
122
|
+
}
|
|
123
|
+
function requiredString(json, key) {
|
|
124
|
+
const value = json[key];
|
|
125
|
+
if (typeof value === "string") {
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
throw new TypeError(`missing string field '${key}'`);
|
|
129
|
+
}
|
|
130
|
+
function requiredInt(json, key) {
|
|
131
|
+
const value = intOrNull(json[key]);
|
|
132
|
+
if (value !== undefined) {
|
|
133
|
+
return value;
|
|
134
|
+
}
|
|
135
|
+
throw new TypeError(`missing integer field '${key}'`);
|
|
136
|
+
}
|
|
137
|
+
function requiredMap(json, key) {
|
|
138
|
+
const value = dynamicMapOrNull(json[key]);
|
|
139
|
+
if (value != null) {
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
142
|
+
throw new TypeError(`missing object field '${key}'`);
|
|
143
|
+
}
|
|
144
|
+
function stringOrNull(value) {
|
|
145
|
+
return typeof value === "string" ? value : undefined;
|
|
146
|
+
}
|
|
147
|
+
function intOrNull(value) {
|
|
148
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
149
|
+
return Math.trunc(value);
|
|
150
|
+
}
|
|
151
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
152
|
+
const parsed = Number.parseInt(value, 10);
|
|
153
|
+
return Number.isNaN(parsed) ? undefined : parsed;
|
|
154
|
+
}
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
function numOrNull(value) {
|
|
158
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
159
|
+
return value;
|
|
160
|
+
}
|
|
161
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
162
|
+
const parsed = Number(value);
|
|
163
|
+
return Number.isNaN(parsed) ? undefined : parsed;
|
|
164
|
+
}
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
function bytesOrEmpty(value) {
|
|
168
|
+
if (value instanceof Uint8Array) {
|
|
169
|
+
return value;
|
|
170
|
+
}
|
|
171
|
+
if (Array.isArray(value) && value.every((entry) => typeof entry === "number")) {
|
|
172
|
+
return Uint8Array.from(value);
|
|
173
|
+
}
|
|
174
|
+
if (typeof value === "string" && value.length > 0) {
|
|
175
|
+
return base64ToBytes(value);
|
|
176
|
+
}
|
|
177
|
+
return new Uint8Array();
|
|
178
|
+
}
|
|
179
|
+
function dynamicMapOrNull(value) {
|
|
180
|
+
return isRecord(value) ? { ...value } : undefined;
|
|
181
|
+
}
|
|
182
|
+
function stringMap(value) {
|
|
183
|
+
const map = dynamicMapOrNull(value);
|
|
184
|
+
if (map == null) {
|
|
185
|
+
return {};
|
|
186
|
+
}
|
|
187
|
+
return Object.fromEntries(Object.entries(map).map(([key, entry]) => [key, String(entry)]));
|
|
188
|
+
}
|
|
189
|
+
function doubleMap(value) {
|
|
190
|
+
return doubleMapOrNull(value) ?? {};
|
|
191
|
+
}
|
|
192
|
+
function doubleMapOrNull(value) {
|
|
193
|
+
const map = dynamicMapOrNull(value);
|
|
194
|
+
if (map == null) {
|
|
195
|
+
return undefined;
|
|
196
|
+
}
|
|
197
|
+
return Object.fromEntries(Object.entries(map).map(([key, entry]) => [key, Number(entry)]));
|
|
198
|
+
}
|
|
199
|
+
function stringList(value, fallback = []) {
|
|
200
|
+
return stringListOrNull(value) ?? [...fallback];
|
|
201
|
+
}
|
|
202
|
+
function stringListOrNull(value) {
|
|
203
|
+
if (!Array.isArray(value)) {
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
return value.map((entry) => String(entry));
|
|
207
|
+
}
|
|
208
|
+
function inputContentFromJson(value) {
|
|
209
|
+
const json = dynamicMapOrNull(value);
|
|
210
|
+
if (json == null) {
|
|
211
|
+
throw new TypeError("agent input content must be an object");
|
|
212
|
+
}
|
|
213
|
+
if (json.type === "text") {
|
|
214
|
+
return { type: "text", text: requiredString(json, "text") };
|
|
215
|
+
}
|
|
216
|
+
if (json.type === "file") {
|
|
217
|
+
return { type: "file", url: requiredString(json, "url") };
|
|
218
|
+
}
|
|
219
|
+
throw new TypeError("unsupported agent input content type");
|
|
220
|
+
}
|
|
221
|
+
function inputContentList(value) {
|
|
222
|
+
return inputContentListOrNull(value) ?? [];
|
|
223
|
+
}
|
|
224
|
+
function inputContentListOrNull(value) {
|
|
225
|
+
if (!Array.isArray(value)) {
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
return value.map(inputContentFromJson);
|
|
229
|
+
}
|
|
230
|
+
function objectList(value, fromJson) {
|
|
231
|
+
if (!Array.isArray(value)) {
|
|
232
|
+
return [];
|
|
233
|
+
}
|
|
234
|
+
return value.map((entry) => fromJson(requiredObjectValue(entry)));
|
|
235
|
+
}
|
|
236
|
+
function mapListOrNull(value) {
|
|
237
|
+
if (!Array.isArray(value)) {
|
|
238
|
+
return undefined;
|
|
239
|
+
}
|
|
240
|
+
return value.map(requiredObjectValue);
|
|
241
|
+
}
|
|
242
|
+
function requiredObjectValue(value) {
|
|
243
|
+
const map = dynamicMapOrNull(value);
|
|
244
|
+
if (map == null) {
|
|
245
|
+
throw new TypeError("expected object");
|
|
246
|
+
}
|
|
247
|
+
return map;
|
|
248
|
+
}
|
|
249
|
+
function contentOrNull(value) {
|
|
250
|
+
if (isContent(value)) {
|
|
251
|
+
return value;
|
|
252
|
+
}
|
|
253
|
+
const map = dynamicMapOrNull(value);
|
|
254
|
+
return map == null ? undefined : unpackContent(packMessage(map));
|
|
255
|
+
}
|
|
256
|
+
function isContent(value) {
|
|
257
|
+
return value instanceof BinaryContent ||
|
|
258
|
+
value instanceof ControlContent ||
|
|
259
|
+
value instanceof EmptyContent ||
|
|
260
|
+
value instanceof ErrorContent ||
|
|
261
|
+
value instanceof FileContent ||
|
|
262
|
+
value instanceof JsonContent ||
|
|
263
|
+
value instanceof LinkContent ||
|
|
264
|
+
value instanceof TextContent;
|
|
265
|
+
}
|
|
266
|
+
function contentHeader(content) {
|
|
267
|
+
return unpackMessage(content.pack())[0];
|
|
268
|
+
}
|
|
269
|
+
function maybeToJson(value) {
|
|
270
|
+
return value != null && typeof value.toJson === "function" ? value.toJson() : value;
|
|
271
|
+
}
|
|
272
|
+
function contentToJson(value) {
|
|
273
|
+
return { ...value };
|
|
274
|
+
}
|
|
275
|
+
function objectOrNull(value, fromJson) {
|
|
276
|
+
const map = dynamicMapOrNull(value);
|
|
277
|
+
return map == null ? undefined : fromJson(map);
|
|
278
|
+
}
|
|
279
|
+
export class ToolChoice {
|
|
280
|
+
constructor({ toolkitName, toolName, toolkit_name, tool_name }) {
|
|
281
|
+
this.toolkitName = String(toolkitName ?? toolkit_name);
|
|
282
|
+
this.toolName = String(toolName ?? tool_name);
|
|
283
|
+
}
|
|
284
|
+
static fromJson(json) {
|
|
285
|
+
return new ToolChoice({ toolkitName: requiredString(json, "toolkit_name"), toolName: requiredString(json, "tool_name") });
|
|
286
|
+
}
|
|
287
|
+
toJson() {
|
|
288
|
+
return { toolkit_name: this.toolkitName, tool_name: this.toolName };
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
export class TurnMcpConfig {
|
|
292
|
+
constructor({ servers = [] } = {}) {
|
|
293
|
+
this.servers = mapListOrNull(servers) ?? [];
|
|
294
|
+
}
|
|
295
|
+
static fromJson(json) {
|
|
296
|
+
return new TurnMcpConfig({ servers: mapListOrNull(json.servers) ?? [] });
|
|
297
|
+
}
|
|
298
|
+
toJson() {
|
|
299
|
+
return { servers: this.servers };
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
export class ClientToolkitDescription {
|
|
303
|
+
constructor({ name, title, description, inputSchema, input_schema }) {
|
|
304
|
+
this.name = String(name);
|
|
305
|
+
this.title = stringOrNull(title);
|
|
306
|
+
this.description = stringOrNull(description);
|
|
307
|
+
this.inputSchema = dynamicMapOrNull(inputSchema ?? input_schema) ?? {};
|
|
308
|
+
}
|
|
309
|
+
static fromJson(json) {
|
|
310
|
+
return new ClientToolkitDescription({
|
|
311
|
+
name: requiredString(json, "name"),
|
|
312
|
+
title: stringOrNull(json.title),
|
|
313
|
+
description: stringOrNull(json.description),
|
|
314
|
+
inputSchema: dynamicMapOrNull(json.input_schema ?? json.inputSchema) ?? requiredMap(json, "input_schema"),
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
toJson() {
|
|
318
|
+
return {
|
|
319
|
+
name: this.name,
|
|
320
|
+
...(this.title != null ? { title: this.title } : {}),
|
|
321
|
+
...(this.description != null ? { description: this.description } : {}),
|
|
322
|
+
input_schema: this.inputSchema,
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
export class TurnToolkitConfig {
|
|
327
|
+
constructor({ clientOptions, client_options } = {}) {
|
|
328
|
+
this.clientOptions = dynamicMapOrNull(clientOptions ?? client_options);
|
|
329
|
+
}
|
|
330
|
+
static fromJson(json) {
|
|
331
|
+
return new TurnToolkitConfig({ clientOptions: dynamicMapOrNull(json.client_options) });
|
|
332
|
+
}
|
|
333
|
+
toJson() {
|
|
334
|
+
return this.clientOptions == null ? {} : { client_options: this.clientOptions };
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
function toolkitsOrNull(value) {
|
|
338
|
+
const map = dynamicMapOrNull(value);
|
|
339
|
+
if (map == null) {
|
|
340
|
+
return undefined;
|
|
341
|
+
}
|
|
342
|
+
return Object.fromEntries(Object.entries(map).map(([key, entry]) => [key, TurnToolkitConfig.fromJson(requiredObjectValue(entry))]));
|
|
343
|
+
}
|
|
344
|
+
function toolkitsToJson(value) {
|
|
345
|
+
return value == null ? undefined : Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, entry.toJson()]));
|
|
346
|
+
}
|
|
347
|
+
function turnMcpConfigOrNull(value) {
|
|
348
|
+
return objectOrNull(value, TurnMcpConfig.fromJson);
|
|
349
|
+
}
|
|
350
|
+
export class AgentAudioFormat {
|
|
351
|
+
constructor({ type = "audio/pcm", sampleRate, sample_rate, bitrate } = {}) {
|
|
352
|
+
this.type = String(type);
|
|
353
|
+
this.sampleRate = intOrNull(sampleRate ?? sample_rate);
|
|
354
|
+
this.bitrate = intOrNull(bitrate);
|
|
355
|
+
}
|
|
356
|
+
static fromJson(json) {
|
|
357
|
+
return new AgentAudioFormat({
|
|
358
|
+
type: stringOrNull(json.type) ?? "audio/pcm",
|
|
359
|
+
sampleRate: intOrNull(json.sample_rate),
|
|
360
|
+
bitrate: intOrNull(json.bitrate),
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
toJson() {
|
|
364
|
+
return {
|
|
365
|
+
type: this.type,
|
|
366
|
+
...(this.sampleRate !== undefined ? { sample_rate: this.sampleRate } : {}),
|
|
367
|
+
...(this.bitrate !== undefined ? { bitrate: this.bitrate } : {}),
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
function audioFormatOrNull(value) {
|
|
372
|
+
return objectOrNull(value, AgentAudioFormat.fromJson);
|
|
373
|
+
}
|
|
374
|
+
function audioFormatOrDefault(value) {
|
|
375
|
+
return audioFormatOrNull(value) ?? new AgentAudioFormat();
|
|
376
|
+
}
|
|
377
|
+
export class AgentError {
|
|
378
|
+
constructor({ message, code }) {
|
|
379
|
+
this.message = message;
|
|
380
|
+
this.code = code;
|
|
381
|
+
}
|
|
382
|
+
static fromJson(json) {
|
|
383
|
+
return new AgentError({ message: requiredString(json, "message"), code: stringOrNull(json.code) });
|
|
384
|
+
}
|
|
385
|
+
toJson() {
|
|
386
|
+
return { message: this.message, ...(this.code != null ? { code: this.code } : {}) };
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
export class ToolkitToolCapabilities {
|
|
390
|
+
constructor({ name, title, description }) {
|
|
391
|
+
this.name = String(name);
|
|
392
|
+
this.title = stringOrNull(title);
|
|
393
|
+
this.description = stringOrNull(description);
|
|
394
|
+
}
|
|
395
|
+
static fromJson(json) {
|
|
396
|
+
return new ToolkitToolCapabilities({
|
|
397
|
+
name: requiredString(json, "name"),
|
|
398
|
+
title: stringOrNull(json.title),
|
|
399
|
+
description: stringOrNull(json.description),
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
toJson() {
|
|
403
|
+
return {
|
|
404
|
+
name: this.name,
|
|
405
|
+
...(this.title != null ? { title: this.title } : {}),
|
|
406
|
+
...(this.description != null ? { description: this.description } : {}),
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
export class ToolkitCapabilities {
|
|
411
|
+
constructor(params) {
|
|
412
|
+
this.name = String(params.name);
|
|
413
|
+
this.title = stringOrNull(params.title);
|
|
414
|
+
this.description = stringOrNull(params.description);
|
|
415
|
+
this.thumbnailUrl = stringOrNull(params.thumbnailUrl ?? params.thumbnail_url);
|
|
416
|
+
this.rules = stringList(params.rules);
|
|
417
|
+
this.clientOptions = dynamicMapOrNull(params.clientOptions ?? params.client_options);
|
|
418
|
+
this.hidden = params.hidden === true;
|
|
419
|
+
this.tools = Array.isArray(params.tools) ? params.tools.map((entry) => entry instanceof ToolkitToolCapabilities ? entry : ToolkitToolCapabilities.fromJson(requiredObjectValue(entry))) : [];
|
|
420
|
+
}
|
|
421
|
+
static fromJson(json) {
|
|
422
|
+
return new ToolkitCapabilities(json);
|
|
423
|
+
}
|
|
424
|
+
toJson() {
|
|
425
|
+
return {
|
|
426
|
+
name: this.name,
|
|
427
|
+
...(this.title != null ? { title: this.title } : {}),
|
|
428
|
+
...(this.description != null ? { description: this.description } : {}),
|
|
429
|
+
...(this.thumbnailUrl != null ? { thumbnail_url: this.thumbnailUrl } : {}),
|
|
430
|
+
rules: this.rules,
|
|
431
|
+
...(this.clientOptions != null ? { client_options: this.clientOptions } : {}),
|
|
432
|
+
hidden: this.hidden,
|
|
433
|
+
tools: this.tools.map((entry) => entry.toJson()),
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
export class AgentModelInfo {
|
|
438
|
+
constructor(params) {
|
|
439
|
+
this.name = String(params.name);
|
|
440
|
+
this.friendlyName = stringOrNull(params.friendlyName ?? params.friendly_name);
|
|
441
|
+
this.description = stringOrNull(params.description);
|
|
442
|
+
this.contextWindow = intOrNull(params.contextWindow ?? params.context_window);
|
|
443
|
+
this.pricing = doubleMapOrNull(params.pricing);
|
|
444
|
+
this.modalities = stringList(params.modalities, ["text"]);
|
|
445
|
+
this.availableVoices = stringList(params.availableVoices ?? params.available_voices);
|
|
446
|
+
this.defaultOutputVoice = stringOrNull(params.defaultOutputVoice ?? params.default_output_voice);
|
|
447
|
+
this.inputFormat = params.inputFormat instanceof AgentAudioFormat ? params.inputFormat : audioFormatOrNull(params.inputFormat ?? params.input_format);
|
|
448
|
+
this.outputFormat = params.outputFormat instanceof AgentAudioFormat ? params.outputFormat : audioFormatOrNull(params.outputFormat ?? params.output_format);
|
|
449
|
+
this.turnDetection = stringOrNull(params.turnDetection ?? params.turn_detection);
|
|
450
|
+
this.realtimeProtocols = stringList(params.realtimeProtocols ?? params.realtime_protocols);
|
|
451
|
+
this.active = params.active === true;
|
|
452
|
+
}
|
|
453
|
+
static fromJson(json) {
|
|
454
|
+
return new AgentModelInfo(json);
|
|
455
|
+
}
|
|
456
|
+
toJson() {
|
|
457
|
+
return {
|
|
458
|
+
name: this.name,
|
|
459
|
+
...(this.friendlyName != null ? { friendly_name: this.friendlyName } : {}),
|
|
460
|
+
...(this.description != null ? { description: this.description } : {}),
|
|
461
|
+
...(this.contextWindow != null ? { context_window: this.contextWindow } : {}),
|
|
462
|
+
...(this.pricing != null ? { pricing: this.pricing } : {}),
|
|
463
|
+
modalities: this.modalities,
|
|
464
|
+
available_voices: this.availableVoices,
|
|
465
|
+
...(this.defaultOutputVoice != null ? { default_output_voice: this.defaultOutputVoice } : {}),
|
|
466
|
+
...(this.inputFormat != null ? { input_format: this.inputFormat.toJson() } : {}),
|
|
467
|
+
...(this.outputFormat != null ? { output_format: this.outputFormat.toJson() } : {}),
|
|
468
|
+
...(this.turnDetection != null ? { turn_detection: this.turnDetection } : {}),
|
|
469
|
+
realtime_protocols: this.realtimeProtocols,
|
|
470
|
+
active: this.active,
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
export class AgentProviderInfo {
|
|
475
|
+
constructor(params) {
|
|
476
|
+
this.name = String(params.name);
|
|
477
|
+
this.friendlyName = String(params.friendlyName ?? params.friendly_name);
|
|
478
|
+
this.description = stringOrNull(params.description);
|
|
479
|
+
this.defaultModel = String(params.defaultModel ?? params.default_model);
|
|
480
|
+
this.models = Array.isArray(params.models) ? params.models.map((entry) => entry instanceof AgentModelInfo ? entry : AgentModelInfo.fromJson(requiredObjectValue(entry))) : [];
|
|
481
|
+
}
|
|
482
|
+
static fromJson(json) {
|
|
483
|
+
return new AgentProviderInfo(json);
|
|
484
|
+
}
|
|
485
|
+
toJson() {
|
|
486
|
+
return {
|
|
487
|
+
name: this.name,
|
|
488
|
+
friendly_name: this.friendlyName,
|
|
489
|
+
...(this.description != null ? { description: this.description } : {}),
|
|
490
|
+
default_model: this.defaultModel,
|
|
491
|
+
models: this.models.map((entry) => entry.toJson()),
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
export class AgentThreadListEntry {
|
|
496
|
+
constructor(params) {
|
|
497
|
+
this.path = String(params.path);
|
|
498
|
+
this.name = String(params.name ?? "");
|
|
499
|
+
this.createdAt = String(params.createdAt ?? params.created_at ?? "");
|
|
500
|
+
this.modifiedAt = String(params.modifiedAt ?? params.modified_at ?? "");
|
|
501
|
+
}
|
|
502
|
+
static fromJson(json) {
|
|
503
|
+
return new AgentThreadListEntry({
|
|
504
|
+
path: requiredString(json, "path"),
|
|
505
|
+
name: stringOrNull(json.name) ?? "",
|
|
506
|
+
createdAt: stringOrNull(json.created_at) ?? "",
|
|
507
|
+
modifiedAt: stringOrNull(json.modified_at) ?? "",
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
toJson() {
|
|
511
|
+
return {
|
|
512
|
+
path: this.path,
|
|
513
|
+
name: this.name,
|
|
514
|
+
created_at: this.createdAt,
|
|
515
|
+
modified_at: this.modifiedAt,
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
export class AgentRealtimeConnectionInfo {
|
|
520
|
+
constructor(params) {
|
|
521
|
+
this.protocol = String(params.protocol);
|
|
522
|
+
this.url = String(params.url);
|
|
523
|
+
this.headers = stringMap(params.headers);
|
|
524
|
+
this.webOnlyProtocol = stringOrNull(params.webOnlyProtocol ?? params.web_only_protocol);
|
|
525
|
+
}
|
|
526
|
+
static fromJson(json) {
|
|
527
|
+
return new AgentRealtimeConnectionInfo({
|
|
528
|
+
protocol: requiredString(json, "protocol"),
|
|
529
|
+
url: requiredString(json, "url"),
|
|
530
|
+
headers: stringMap(json.headers),
|
|
531
|
+
webOnlyProtocol: stringOrNull(json.web_only_protocol),
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
toJson() {
|
|
535
|
+
return {
|
|
536
|
+
protocol: this.protocol,
|
|
537
|
+
url: this.url,
|
|
538
|
+
headers: this.headers,
|
|
539
|
+
...(this.webOnlyProtocol != null ? { web_only_protocol: this.webOnlyProtocol } : {}),
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
export class AgentToolCallLogLine {
|
|
544
|
+
constructor({ source, text }) {
|
|
545
|
+
this.source = String(source);
|
|
546
|
+
this.text = String(text);
|
|
547
|
+
}
|
|
548
|
+
static fromJson(json) {
|
|
549
|
+
return new AgentToolCallLogLine({ source: requiredString(json, "source"), text: requiredString(json, "text") });
|
|
550
|
+
}
|
|
551
|
+
toJson() {
|
|
552
|
+
return { source: this.source, text: this.text };
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
export class AgentGeneratedImage {
|
|
556
|
+
constructor(params = {}) {
|
|
557
|
+
this.uri = stringOrNull(params.uri);
|
|
558
|
+
this.mimeType = stringOrNull(params.mimeType ?? params.mime_type);
|
|
559
|
+
this.createdAt = stringOrNull(params.createdAt ?? params.created_at);
|
|
560
|
+
this.createdBy = stringOrNull(params.createdBy ?? params.created_by);
|
|
561
|
+
this.width = numOrNull(params.width);
|
|
562
|
+
this.height = numOrNull(params.height);
|
|
563
|
+
this.status = stringOrNull(params.status);
|
|
564
|
+
}
|
|
565
|
+
static fromJson(json) {
|
|
566
|
+
return new AgentGeneratedImage(json);
|
|
567
|
+
}
|
|
568
|
+
toJson() {
|
|
569
|
+
return omitUndefined({
|
|
570
|
+
uri: this.uri,
|
|
571
|
+
mime_type: this.mimeType,
|
|
572
|
+
created_at: this.createdAt,
|
|
573
|
+
created_by: this.createdBy,
|
|
574
|
+
width: this.width,
|
|
575
|
+
height: this.height,
|
|
576
|
+
status: this.status,
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
export class AgentGeneratedAudio {
|
|
581
|
+
constructor(params = {}) {
|
|
582
|
+
this.uri = stringOrNull(params.uri);
|
|
583
|
+
this.mimeType = stringOrNull(params.mimeType ?? params.mime_type);
|
|
584
|
+
this.createdAt = stringOrNull(params.createdAt ?? params.created_at);
|
|
585
|
+
this.createdBy = stringOrNull(params.createdBy ?? params.created_by);
|
|
586
|
+
this.status = stringOrNull(params.status);
|
|
587
|
+
this.transcript = stringOrNull(params.transcript);
|
|
588
|
+
}
|
|
589
|
+
static fromJson(json) {
|
|
590
|
+
return new AgentGeneratedAudio(json);
|
|
591
|
+
}
|
|
592
|
+
toJson() {
|
|
593
|
+
return omitUndefined({
|
|
594
|
+
uri: this.uri,
|
|
595
|
+
mime_type: this.mimeType,
|
|
596
|
+
created_at: this.createdAt,
|
|
597
|
+
created_by: this.createdBy,
|
|
598
|
+
status: this.status,
|
|
599
|
+
transcript: this.transcript,
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
export class AgentContextWindowUsage {
|
|
604
|
+
constructor(params) {
|
|
605
|
+
this.usedTokens = Number(params.usedTokens ?? params.used_tokens);
|
|
606
|
+
this.totalTokens = intOrNull(params.totalTokens ?? params.total_tokens);
|
|
607
|
+
this.compactionMode = stringOrNull(params.compactionMode ?? params.compaction_mode);
|
|
608
|
+
this.compactionThreshold = intOrNull(params.compactionThreshold ?? params.compaction_threshold);
|
|
609
|
+
}
|
|
610
|
+
static fromJson(json) {
|
|
611
|
+
return new AgentContextWindowUsage({
|
|
612
|
+
usedTokens: requiredInt(json, "used_tokens"),
|
|
613
|
+
totalTokens: intOrNull(json.total_tokens),
|
|
614
|
+
compactionMode: stringOrNull(json.compaction_mode),
|
|
615
|
+
compactionThreshold: intOrNull(json.compaction_threshold),
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
toJson() {
|
|
619
|
+
return omitUndefined({
|
|
620
|
+
used_tokens: this.usedTokens,
|
|
621
|
+
total_tokens: this.totalTokens,
|
|
622
|
+
compaction_mode: this.compactionMode,
|
|
623
|
+
compaction_threshold: this.compactionThreshold,
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
function omitUndefined(value) {
|
|
628
|
+
return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== undefined));
|
|
629
|
+
}
|
|
630
|
+
export class AgentMessage {
|
|
631
|
+
constructor({ type, messageId, message_id, senderName, sender_name }) {
|
|
632
|
+
this.type = String(type);
|
|
633
|
+
const resolvedMessageId = stringOrNull(messageId ?? message_id)?.trim();
|
|
634
|
+
this.messageId = resolvedMessageId == null || resolvedMessageId.length === 0 ? uuidv4() : resolvedMessageId;
|
|
635
|
+
this.senderName = stringOrNull(senderName ?? sender_name);
|
|
636
|
+
}
|
|
637
|
+
toJson() {
|
|
638
|
+
return {
|
|
639
|
+
type: this.type,
|
|
640
|
+
message_id: this.messageId,
|
|
641
|
+
...(this.senderName != null ? { sender_name: this.senderName } : {}),
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
static fromJson(json) {
|
|
645
|
+
const type = json.type;
|
|
646
|
+
if (typeof type !== "string" || type.trim() === "") {
|
|
647
|
+
throw new TypeError("missing string field 'type'");
|
|
648
|
+
}
|
|
649
|
+
const ctor = messageConstructors[type];
|
|
650
|
+
if (ctor == null) {
|
|
651
|
+
throw new TypeError(`unsupported agent message type '${type}'`);
|
|
652
|
+
}
|
|
653
|
+
return ctor.fromJson(json);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
export class AgentThreadMessage extends AgentMessage {
|
|
657
|
+
constructor(params) {
|
|
658
|
+
super(params);
|
|
659
|
+
this.threadId = String(paramValue(params, "threadId", "thread_id"));
|
|
660
|
+
}
|
|
661
|
+
toJson() {
|
|
662
|
+
return { ...super.toJson(), thread_id: this.threadId };
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
export class AgentLLMMessage extends AgentThreadMessage {
|
|
666
|
+
constructor(params) {
|
|
667
|
+
super(params);
|
|
668
|
+
this.provider = stringOrNull(params.provider);
|
|
669
|
+
this.model = stringOrNull(params.model);
|
|
670
|
+
}
|
|
671
|
+
toJson() {
|
|
672
|
+
return {
|
|
673
|
+
...super.toJson(),
|
|
674
|
+
...(this.provider != null ? { provider: this.provider } : {}),
|
|
675
|
+
...(this.model != null ? { model: this.model } : {}),
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
const messageConstructors = {};
|
|
680
|
+
function register(type, ctor) {
|
|
681
|
+
messageConstructors[type] = ctor;
|
|
682
|
+
return ctor;
|
|
683
|
+
}
|
|
684
|
+
function makeMessageClass({ type, base = "message", fields = [], }) {
|
|
685
|
+
const Parent = base === "llm" ? AgentLLMMessage : base === "thread" ? AgentThreadMessage : AgentMessage;
|
|
686
|
+
return register(type, class extends Parent {
|
|
687
|
+
constructor(params = {}) {
|
|
688
|
+
super({ ...params, type });
|
|
689
|
+
for (const field of fields) {
|
|
690
|
+
let value = paramValue(params, field.prop, field.json);
|
|
691
|
+
if (value === undefined && field.default != null) {
|
|
692
|
+
value = field.default(params);
|
|
693
|
+
}
|
|
694
|
+
if (value !== undefined && field.from != null) {
|
|
695
|
+
value = field.from(value, params);
|
|
696
|
+
}
|
|
697
|
+
this[field.prop] = value;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
static fromJson(json) {
|
|
701
|
+
const params = {
|
|
702
|
+
messageId: stringOrNull(json.message_id),
|
|
703
|
+
senderName: stringOrNull(json.sender_name),
|
|
704
|
+
};
|
|
705
|
+
if (base !== "message") {
|
|
706
|
+
params.threadId = requiredString(json, "thread_id");
|
|
707
|
+
}
|
|
708
|
+
if (base === "llm") {
|
|
709
|
+
params.provider = stringOrNull(json.provider);
|
|
710
|
+
params.model = stringOrNull(json.model);
|
|
711
|
+
}
|
|
712
|
+
for (const field of fields) {
|
|
713
|
+
if (field.required) {
|
|
714
|
+
if (field.from != null) {
|
|
715
|
+
params[field.prop] = field.from(json[field.json], json);
|
|
716
|
+
}
|
|
717
|
+
else if (typeof json[field.json] === "string") {
|
|
718
|
+
params[field.prop] = requiredString(json, field.json);
|
|
719
|
+
}
|
|
720
|
+
else if (typeof json[field.json] === "number") {
|
|
721
|
+
params[field.prop] = json[field.json];
|
|
722
|
+
}
|
|
723
|
+
else {
|
|
724
|
+
params[field.prop] = requiredMap(json, field.json);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
else if (hasOwn(json, field.json)) {
|
|
728
|
+
params[field.prop] = field.from != null ? field.from(json[field.json], json) : json[field.json];
|
|
729
|
+
}
|
|
730
|
+
else if (field.default != null) {
|
|
731
|
+
params[field.prop] = field.default(json);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
return new this(params);
|
|
735
|
+
}
|
|
736
|
+
toJson() {
|
|
737
|
+
const json = super.toJson();
|
|
738
|
+
for (const field of fields) {
|
|
739
|
+
const value = this[field.prop];
|
|
740
|
+
if (value === undefined && !field.always) {
|
|
741
|
+
continue;
|
|
742
|
+
}
|
|
743
|
+
if (value === undefined) {
|
|
744
|
+
json[field.json] = value;
|
|
745
|
+
}
|
|
746
|
+
else if (field.to != null) {
|
|
747
|
+
const encoded = field.to(value);
|
|
748
|
+
if (encoded !== undefined || field.always) {
|
|
749
|
+
json[field.json] = encoded;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
else {
|
|
753
|
+
json[field.json] = maybeToJson(value);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
return json;
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
const s = (prop, json = snake(prop), required = false) => ({
|
|
761
|
+
prop,
|
|
762
|
+
json,
|
|
763
|
+
required,
|
|
764
|
+
from: (value) => {
|
|
765
|
+
const parsed = stringOrNull(value);
|
|
766
|
+
if (required && parsed == null) {
|
|
767
|
+
throw new TypeError(`missing string field '${json}'`);
|
|
768
|
+
}
|
|
769
|
+
return parsed;
|
|
770
|
+
},
|
|
771
|
+
});
|
|
772
|
+
const i = (prop, json = snake(prop), required = false) => ({
|
|
773
|
+
prop,
|
|
774
|
+
json,
|
|
775
|
+
required,
|
|
776
|
+
from: (value) => {
|
|
777
|
+
const parsed = intOrNull(value);
|
|
778
|
+
if (required && parsed == null) {
|
|
779
|
+
throw new TypeError(`missing integer field '${json}'`);
|
|
780
|
+
}
|
|
781
|
+
return parsed;
|
|
782
|
+
},
|
|
783
|
+
});
|
|
784
|
+
const n = (prop, json = snake(prop)) => ({ prop, json, from: numOrNull });
|
|
785
|
+
const m = (prop, json = snake(prop), required = false) => ({
|
|
786
|
+
prop,
|
|
787
|
+
json,
|
|
788
|
+
required,
|
|
789
|
+
from: (value) => {
|
|
790
|
+
const parsed = dynamicMapOrNull(value);
|
|
791
|
+
if (required && parsed == null) {
|
|
792
|
+
throw new TypeError(`missing object field '${json}'`);
|
|
793
|
+
}
|
|
794
|
+
return parsed;
|
|
795
|
+
},
|
|
796
|
+
});
|
|
797
|
+
const sl = (prop, json = snake(prop), fallback, always = false) => ({
|
|
798
|
+
prop,
|
|
799
|
+
json,
|
|
800
|
+
from: (value) => fallback == null ? stringListOrNull(value) : stringList(value, fallback),
|
|
801
|
+
default: fallback == null ? undefined : () => [...fallback],
|
|
802
|
+
always,
|
|
803
|
+
});
|
|
804
|
+
const obj = (prop, json, fromJson, required = false) => ({
|
|
805
|
+
prop,
|
|
806
|
+
json,
|
|
807
|
+
required,
|
|
808
|
+
from: (value) => {
|
|
809
|
+
const parsed = objectOrNull(value, fromJson);
|
|
810
|
+
if (required && parsed == null) {
|
|
811
|
+
throw new TypeError(`missing object field '${json}'`);
|
|
812
|
+
}
|
|
813
|
+
return parsed;
|
|
814
|
+
},
|
|
815
|
+
to: maybeToJson,
|
|
816
|
+
});
|
|
817
|
+
const objList = (prop, json, fromJson, always = false) => ({
|
|
818
|
+
prop,
|
|
819
|
+
json,
|
|
820
|
+
from: (value) => objectList(value, fromJson),
|
|
821
|
+
default: always ? () => [] : undefined,
|
|
822
|
+
always,
|
|
823
|
+
to: (value) => value.map(maybeToJson),
|
|
824
|
+
});
|
|
825
|
+
const contentList = (prop = "content", optional = false) => ({
|
|
826
|
+
prop,
|
|
827
|
+
json: "content",
|
|
828
|
+
from: optional ? inputContentListOrNull : inputContentList,
|
|
829
|
+
default: optional ? undefined : () => [],
|
|
830
|
+
always: !optional,
|
|
831
|
+
to: (value) => value.map(contentToJson),
|
|
832
|
+
});
|
|
833
|
+
const bytesField = (prop = "data") => ({
|
|
834
|
+
prop,
|
|
835
|
+
json: prop,
|
|
836
|
+
from: bytesOrEmpty,
|
|
837
|
+
default: () => new Uint8Array(),
|
|
838
|
+
to: (value) => value.length > 0 ? bytesToBase64(value) : undefined,
|
|
839
|
+
});
|
|
840
|
+
const audioFormat = (prop, json = snake(prop), requiredDefault = false) => ({
|
|
841
|
+
prop,
|
|
842
|
+
json,
|
|
843
|
+
from: requiredDefault ? audioFormatOrDefault : audioFormatOrNull,
|
|
844
|
+
default: requiredDefault ? () => new AgentAudioFormat() : undefined,
|
|
845
|
+
always: requiredDefault,
|
|
846
|
+
to: maybeToJson,
|
|
847
|
+
});
|
|
848
|
+
function snake(value) {
|
|
849
|
+
return value.replace(/[A-Z]/g, (match) => `_${match.toLowerCase()}`);
|
|
850
|
+
}
|
|
851
|
+
const turnOptions = [
|
|
852
|
+
s("turnId"),
|
|
853
|
+
contentList("content"),
|
|
854
|
+
s("provider"),
|
|
855
|
+
s("model"),
|
|
856
|
+
s("voice"),
|
|
857
|
+
sl("outputModalities"),
|
|
858
|
+
s("instructions"),
|
|
859
|
+
{ prop: "mcp", json: "mcp", from: turnMcpConfigOrNull, to: maybeToJson },
|
|
860
|
+
objList("clientToolkits", "client_toolkits", ClientToolkitDescription.fromJson),
|
|
861
|
+
{ prop: "toolkits", json: "toolkits", from: toolkitsOrNull, to: toolkitsToJson },
|
|
862
|
+
obj("toolChoice", "tool_choice", ToolChoice.fromJson),
|
|
863
|
+
];
|
|
864
|
+
const contentPart = [s("turnId", "turn_id", true), s("itemId", "item_id", true)];
|
|
865
|
+
const responsePart = [...contentPart, s("responseId"), i("contentIndex")];
|
|
866
|
+
const toolState = [
|
|
867
|
+
...contentPart,
|
|
868
|
+
{ prop: "namespace", json: "namespace", from: (value) => stringOrNull(value) ?? "meshagent", default: () => "meshagent", always: true },
|
|
869
|
+
s("callId"),
|
|
870
|
+
s("toolkit", "toolkit", true),
|
|
871
|
+
s("tool", "tool", true),
|
|
872
|
+
m("arguments"),
|
|
873
|
+
i("argumentBytes"),
|
|
874
|
+
];
|
|
875
|
+
const imageGeneration = [
|
|
876
|
+
...contentPart,
|
|
877
|
+
s("callId"),
|
|
878
|
+
{ prop: "toolkit", json: "toolkit", from: (value) => stringOrNull(value) ?? "image_generation", default: () => "image_generation", always: true },
|
|
879
|
+
{ prop: "tool", json: "tool", from: (value) => stringOrNull(value) ?? "image_generation", default: () => "image_generation", always: true },
|
|
880
|
+
m("arguments"),
|
|
881
|
+
];
|
|
882
|
+
export const StartThread = makeMessageClass({
|
|
883
|
+
type: agentThreadStartType,
|
|
884
|
+
fields: [
|
|
885
|
+
contentList("content", true),
|
|
886
|
+
s("name"),
|
|
887
|
+
s("realtimeProtocol"),
|
|
888
|
+
s("provider"),
|
|
889
|
+
s("model"),
|
|
890
|
+
s("voice"),
|
|
891
|
+
sl("outputModalities"),
|
|
892
|
+
s("instructions"),
|
|
893
|
+
{ prop: "mcp", json: "mcp", from: turnMcpConfigOrNull, to: maybeToJson },
|
|
894
|
+
objList("clientToolkits", "client_toolkits", ClientToolkitDescription.fromJson),
|
|
895
|
+
{ prop: "toolkits", json: "toolkits", from: toolkitsOrNull, to: toolkitsToJson },
|
|
896
|
+
obj("toolChoice", "tool_choice", ToolChoice.fromJson),
|
|
897
|
+
],
|
|
898
|
+
});
|
|
899
|
+
export const TurnStart = makeMessageClass({ type: agentTurnStartType, base: "thread", fields: turnOptions });
|
|
900
|
+
export const TurnSteer = makeMessageClass({ type: agentTurnSteerType, base: "thread", fields: [s("turnId", "turn_id", true), contentList("content")] });
|
|
901
|
+
export const TurnInterrupt = makeMessageClass({ type: agentTurnInterruptType, base: "thread", fields: [s("turnId", "turn_id", true)] });
|
|
902
|
+
export const AgentRealtimeAudioChunk = makeMessageClass({ type: agentRealtimeAudioChunkType, base: "thread", fields: [bytesField("data"), audioFormat("format", "format", true)] });
|
|
903
|
+
export const AgentRealtimeAudioCommit = makeMessageClass({ type: agentRealtimeAudioCommitType, base: "thread", fields: [s("turnId"), s("text"), s("status"), s("transcriptionItemId")] });
|
|
904
|
+
export const ClearThread = makeMessageClass({ type: agentThreadClearType, base: "thread" });
|
|
905
|
+
export const OpenThread = makeMessageClass({ type: agentThreadOpenType, base: "thread", fields: [{ prop: "load", json: "load", from: (value) => typeof value === "boolean" ? value : undefined }, s("sinceTurn")] });
|
|
906
|
+
export const CloseThread = makeMessageClass({ type: agentThreadCloseType, base: "thread" });
|
|
907
|
+
export const ParticipantConnect = makeMessageClass({ type: agentParticipantConnectType, fields: [s("participantId"), s("participantName"), m("attributes")] });
|
|
908
|
+
export const ParticipantDisconnect = makeMessageClass({ type: agentParticipantDisconnectType, fields: [s("participantId"), s("participantName"), s("reason")] });
|
|
909
|
+
export const DeleteThread = makeMessageClass({ type: agentThreadDeleteType, base: "thread" });
|
|
910
|
+
export const RenameThread = makeMessageClass({ type: agentThreadRenameType, base: "thread", fields: [s("name", "name", true)] });
|
|
911
|
+
export const ListThreads = makeMessageClass({ type: agentThreadListType, fields: [{ prop: "limit", json: "limit", from: (value) => intOrNull(value) ?? 200, default: () => 200, always: true }, { prop: "offset", json: "offset", from: (value) => intOrNull(value) ?? 0, default: () => 0, always: true }] });
|
|
912
|
+
export const ThreadsListed = makeMessageClass({ type: agentThreadListedType, fields: [s("sourceMessageId", "source_message_id", true), objList("threads", "threads", AgentThreadListEntry.fromJson, true), i("total"), i("offset"), i("limit")] });
|
|
913
|
+
export const ThreadCreated = makeMessageClass({ type: agentThreadCreatedType, fields: [obj("thread", "thread", AgentThreadListEntry.fromJson, true)] });
|
|
914
|
+
export const ThreadUpdated = makeMessageClass({ type: agentThreadUpdatedType, fields: [obj("thread", "thread", AgentThreadListEntry.fromJson, true)] });
|
|
915
|
+
export const ThreadDeleted = makeMessageClass({ type: agentThreadDeletedType, fields: [s("path", "path", true)] });
|
|
916
|
+
export const CapabilitiesRequest = makeMessageClass({ type: agentCapabilitiesRequestType, base: "thread" });
|
|
917
|
+
export const CapabilitiesResponse = makeMessageClass({ type: agentCapabilitiesResponseType, base: "thread", fields: [s("sourceMessageId", "source_message_id", true), s("version", "version", true), objList("toolkits", "toolkits", ToolkitCapabilities.fromJson, true)] });
|
|
918
|
+
export const ModelsRequest = makeMessageClass({ type: agentModelsRequestType });
|
|
919
|
+
export const ModelsResponse = makeMessageClass({ type: agentModelsResponseType, fields: [s("sourceMessageId", "source_message_id", true), objList("providers", "providers", AgentProviderInfo.fromJson, true)] });
|
|
920
|
+
export const ChangeModel = makeMessageClass({ type: agentModelChangeType, base: "thread", fields: [s("provider"), s("model"), s("voice")] });
|
|
921
|
+
export const AgentModelChanged = makeMessageClass({ type: agentModelChangedType, base: "thread", fields: [s("sourceMessageId"), s("provider", "provider", true), s("model", "model", true), s("voice"), audioFormat("inputFormat"), audioFormat("outputFormat"), s("turnDetection"), sl("outputModalities", "output_modalities", ["text"], true), sl("realtimeProtocols", "realtime_protocols", [], true)] });
|
|
922
|
+
export const ThreadCleared = makeMessageClass({ type: agentThreadClearedType, base: "thread", fields: [s("sourceMessageId", "source_message_id", true)] });
|
|
923
|
+
export const TurnStartAccepted = makeMessageClass({ type: agentTurnStartAcceptedType, base: "thread", fields: [s("turnId"), s("sourceMessageId", "source_message_id", true), contentList("content")] });
|
|
924
|
+
export const TurnStartRejected = makeMessageClass({ type: agentTurnStartRejectedType, base: "thread", fields: [s("sourceMessageId", "source_message_id", true), obj("error", "error", AgentError.fromJson, true)] });
|
|
925
|
+
export const TurnInterruptAccepted = makeMessageClass({ type: agentTurnInterruptAcceptedType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true)] });
|
|
926
|
+
export const TurnInterrupted = makeMessageClass({ type: agentTurnInterruptedType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true)] });
|
|
927
|
+
export const TurnSteerAccepted = makeMessageClass({ type: agentTurnSteerAcceptedType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true), contentList("content")] });
|
|
928
|
+
export const TurnSteered = makeMessageClass({ type: agentTurnSteeredType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true)] });
|
|
929
|
+
export const TurnSteerRejected = makeMessageClass({ type: agentTurnSteerRejectedType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true), obj("error", "error", AgentError.fromJson, true)] });
|
|
930
|
+
export const TurnStarted = makeMessageClass({ type: agentTurnStartedType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true)] });
|
|
931
|
+
export const TurnEnded = makeMessageClass({ type: agentTurnEndedType, base: "thread", fields: [s("turnId", "turn_id", true), obj("error", "error", AgentError.fromJson)] });
|
|
932
|
+
export const ThreadStarted = makeMessageClass({ type: agentThreadStartedType, fields: [s("sourceMessageId", "source_message_id", true), s("threadId", "thread_id", true), obj("realtimeConnection", "realtime_connection", AgentRealtimeConnectionInfo.fromJson)] });
|
|
933
|
+
export const ThreadLoaded = makeMessageClass({ type: agentThreadLoadedType, base: "thread", fields: [s("sourceMessageId"), s("sinceTurn")] });
|
|
934
|
+
export const ThreadStartRejected = makeMessageClass({ type: agentThreadStartRejectedType, fields: [s("sourceMessageId", "source_message_id", true), obj("error", "error", AgentError.fromJson, true)] });
|
|
935
|
+
export const AgentReasoningContentStarted = makeMessageClass({ type: agentReasoningContentStartedType, base: "llm", fields: contentPart });
|
|
936
|
+
export const AgentReasoningContentDelta = makeMessageClass({ type: agentReasoningContentDeltaType, base: "llm", fields: [...contentPart, s("text", "text", true)] });
|
|
937
|
+
export const AgentReasoningContentEnded = makeMessageClass({ type: agentReasoningContentEndedType, base: "llm", fields: contentPart });
|
|
938
|
+
export const AgentTextContentStarted = makeMessageClass({ type: agentTextContentStartedType, base: "llm", fields: [...contentPart, s("phase")] });
|
|
939
|
+
export const AgentTextContentDelta = makeMessageClass({ type: agentTextContentDeltaType, base: "llm", fields: [...contentPart, s("phase"), s("text", "text", true)] });
|
|
940
|
+
export const AgentTextContentEnded = makeMessageClass({ type: agentTextContentEndedType, base: "llm", fields: [...contentPart, s("phase")] });
|
|
941
|
+
export const AgentFileContentStarted = makeMessageClass({ type: agentFileContentStartedType, base: "llm", fields: contentPart });
|
|
942
|
+
export const AgentFileContentDelta = makeMessageClass({ type: agentFileContentDeltaType, base: "llm", fields: [...contentPart, s("url", "url", true)] });
|
|
943
|
+
export const AgentFileContentEnded = makeMessageClass({ type: agentFileContentEndedType, base: "llm", fields: contentPart });
|
|
944
|
+
export const AgentToolCallPending = makeMessageClass({ type: agentToolCallPendingType, base: "llm", fields: toolState });
|
|
945
|
+
export const AgentToolCallInProgress = makeMessageClass({ type: agentToolCallInProgressType, base: "llm", fields: toolState });
|
|
946
|
+
export const AgentToolCallStarted = makeMessageClass({ type: agentToolCallStartedType, base: "llm", fields: toolState });
|
|
947
|
+
export const AgentToolCallArgumentsDelta = makeMessageClass({ type: agentToolCallArgumentsDeltaType, base: "llm", fields: [...contentPart, { prop: "namespace", json: "namespace", from: (value) => stringOrNull(value) ?? "meshagent", default: () => "meshagent", always: true }, s("callId"), s("delta", "delta", true)] });
|
|
948
|
+
export const AgentToolCallLogDelta = makeMessageClass({ type: agentToolCallLogDeltaType, base: "llm", fields: [...contentPart, { prop: "namespace", json: "namespace", from: (value) => stringOrNull(value) ?? "meshagent", default: () => "meshagent", always: true }, s("callId"), objList("lines", "lines", AgentToolCallLogLine.fromJson, true)] });
|
|
949
|
+
export const AgentToolCallEnded = makeMessageClass({ type: agentToolCallEndedType, base: "llm", fields: [...contentPart, { prop: "namespace", json: "namespace", from: (value) => stringOrNull(value) ?? "meshagent", default: () => "meshagent", always: true }, s("callId"), s("toolkit"), s("tool"), { prop: "result", json: "result", from: contentOrNull, to: contentHeader }, obj("error", "error", AgentError.fromJson)] });
|
|
950
|
+
export const AgentToolCallApprovalRequested = makeMessageClass({ type: agentToolCallApprovalRequestedType, base: "llm", fields: toolState.filter((field) => field.prop !== "argumentBytes") });
|
|
951
|
+
export const AgentSecretRequested = makeMessageClass({ type: agentSecretRequestedType, base: "llm", fields: [...contentPart, s("requestId", "request_id", true), s("name", "name", true), s("scope")] });
|
|
952
|
+
export const AgentClientToolCallRequested = makeMessageClass({ type: agentClientToolCallRequestedType, base: "llm", fields: [...contentPart, s("requestId", "request_id", true), s("toolkit", "toolkit", true), s("tool", "tool", true), m("arguments", "arguments", true)] });
|
|
953
|
+
export const AgentClientToolCallCancelled = makeMessageClass({ type: agentClientToolCallCancelledType, base: "llm", fields: [...contentPart, s("requestId", "request_id", true), s("reason")] });
|
|
954
|
+
export const AgentThreadStatus = makeMessageClass({ type: agentThreadStatusType, base: "thread", fields: [s("status"), s("mode"), s("startedAt"), s("turnId"), s("pendingItemId"), i("totalBytes"), i("linesAdded"), i("linesRemoved")] });
|
|
955
|
+
export const AgentConnectionStatus = makeMessageClass({ type: agentConnectionStatusType, fields: [s("status", "status", true), s("message"), s("reason"), n("retryInSeconds")] });
|
|
956
|
+
export const AgentThreadEvent = makeMessageClass({ type: agentThreadEventType, base: "llm", fields: [m("event", "event", true)] });
|
|
957
|
+
export const AgentImageGenerationStarted = makeMessageClass({ type: agentImageGenerationStartedType, base: "llm", fields: imageGeneration });
|
|
958
|
+
export const AgentImageGenerationPartial = makeMessageClass({ type: agentImageGenerationPartialType, base: "llm", fields: [...imageGeneration, obj("image", "image", AgentGeneratedImage.fromJson), i("partialIndex")] });
|
|
959
|
+
export const AgentImageGenerationCompleted = makeMessageClass({ type: agentImageGenerationCompletedType, base: "llm", fields: [...imageGeneration, objList("images", "images", AgentGeneratedImage.fromJson, true)] });
|
|
960
|
+
export const AgentImageGenerationFailed = makeMessageClass({ type: agentImageGenerationFailedType, base: "llm", fields: [...imageGeneration, obj("error", "error", AgentError.fromJson)] });
|
|
961
|
+
export const AgentAudioGenerationStarted = makeMessageClass({ type: agentAudioGenerationStartedType, base: "llm", fields: responsePart });
|
|
962
|
+
export const AgentAudioGenerationDelta = makeMessageClass({ type: agentAudioGenerationDeltaType, base: "llm", fields: [...responsePart, bytesField("data"), s("mimeType"), audioFormat("outputFormat")] });
|
|
963
|
+
export const AgentAudioGenerationCompleted = makeMessageClass({ type: agentAudioGenerationCompletedType, base: "llm", fields: [...responsePart, obj("audio", "audio", AgentGeneratedAudio.fromJson), audioFormat("outputFormat")] });
|
|
964
|
+
export const AgentAudioGenerationFailed = makeMessageClass({ type: agentAudioGenerationFailedType, base: "llm", fields: [...responsePart, obj("error", "error", AgentError.fromJson)] });
|
|
965
|
+
export const AgentAudioTranscriptionStarted = makeMessageClass({ type: agentAudioTranscriptionStartedType, base: "llm", fields: [...responsePart, s("role")] });
|
|
966
|
+
export const AgentAudioTranscriptionDelta = makeMessageClass({ type: agentAudioTranscriptionDeltaType, base: "llm", fields: [...responsePart, s("role"), s("text", "text", true)] });
|
|
967
|
+
export const AgentAudioTranscriptionCompleted = makeMessageClass({ type: agentAudioTranscriptionCompletedType, base: "llm", fields: [...responsePart, s("role"), s("text")] });
|
|
968
|
+
export const AgentAudioTranscriptionFailed = makeMessageClass({ type: agentAudioTranscriptionFailedType, base: "llm", fields: [...responsePart, s("role"), obj("error", "error", AgentError.fromJson)] });
|
|
969
|
+
export const AgentAudioInputSpeechStarted = makeMessageClass({ type: agentAudioInputSpeechStartedType, base: "thread", fields: [s("turnId", "turn_id", true), s("itemId"), i("audioStartMs")] });
|
|
970
|
+
export const AgentAudioInputSpeechEnded = makeMessageClass({ type: agentAudioInputSpeechEndedType, base: "thread", fields: [s("turnId", "turn_id", true), s("itemId"), i("audioEndMs")] });
|
|
971
|
+
export const AgentContextCompacted = makeMessageClass({ type: agentContextCompactedType, base: "thread", fields: [s("checkpointId", "checkpoint_id", true), s("path", "path", true), i("throughSequence", "through_sequence", true), s("createdAt"), { prop: "messages", json: "messages", from: mapListOrNull }] });
|
|
972
|
+
export const AgentUsageUpdated = makeMessageClass({ type: agentUsageUpdatedType, base: "thread", fields: [s("turnId"), { prop: "usage", json: "usage", from: doubleMap, default: () => ({}), always: true }, obj("contextWindow", "context_window", AgentContextWindowUsage.fromJson, true)] });
|
|
973
|
+
export const ApproveAgentToolCall = makeMessageClass({ type: agentToolApproveType, base: "thread", fields: [s("turnId", "turn_id", true), s("itemId", "item_id", true)] });
|
|
974
|
+
export const RejectAgentToolCall = makeMessageClass({ type: agentToolRejectType, base: "thread", fields: [s("turnId", "turn_id", true), s("itemId", "item_id", true)] });
|
|
975
|
+
export const AgentSecretResponse = makeMessageClass({ type: agentSecretResponseType, base: "thread", fields: [s("turnId", "turn_id", true), s("requestId", "request_id", true), s("value"), obj("error", "error", AgentError.fromJson)] });
|
|
976
|
+
export const AgentClientToolCallResponse = makeMessageClass({ type: agentClientToolCallResponseType, base: "thread", fields: [s("turnId", "turn_id", true), s("requestId", "request_id", true), { prop: "response", json: "response", from: contentOrNull, to: contentHeader }] });
|
|
977
|
+
export function agentInputContent({ text, attachments }) {
|
|
978
|
+
const content = [];
|
|
979
|
+
if (text.trim() !== "") {
|
|
980
|
+
content.push({ type: "text", text });
|
|
981
|
+
}
|
|
982
|
+
for (const attachment of attachments) {
|
|
983
|
+
const normalized = attachment.trim();
|
|
984
|
+
if (normalized !== "") {
|
|
985
|
+
content.push({ type: "file", url: normalized });
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
return content;
|
|
989
|
+
}
|