@meshagent/meshagent-agents 0.47.1 → 0.48.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 +10 -0
- package/README.md +28 -5
- package/dist/browser/agent-messages.d.ts +1448 -107
- package/dist/browser/agent-messages.js +345 -193
- package/dist/browser/chat-client.d.ts +93 -33
- package/dist/browser/chat-client.js +483 -206
- package/dist/browser/images-dataset.d.ts +1 -1
- package/dist/browser/index.d.ts +2 -0
- package/dist/browser/index.js +8 -0
- package/dist/browser/thread-storage.d.ts +1 -1
- package/dist/esm/agent-messages.d.ts +1448 -107
- package/dist/esm/agent-messages.js +340 -189
- package/dist/esm/chat-client.d.ts +93 -33
- package/dist/esm/chat-client.js +478 -206
- package/dist/esm/images-dataset.d.ts +1 -1
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/thread-storage.d.ts +1 -1
- package/dist/node/agent-messages.d.ts +1448 -107
- package/dist/node/agent-messages.js +345 -193
- package/dist/node/chat-client.d.ts +93 -33
- package/dist/node/chat-client.js +483 -206
- package/dist/node/images-dataset.d.ts +1 -1
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.js +8 -0
- package/dist/node/thread-storage.d.ts +1 -1
- package/package.json +7 -3
|
@@ -13,6 +13,7 @@ export const agentThreadLoadedType = "meshagent.agent.thread.loaded";
|
|
|
13
13
|
export const agentThreadStartRejectedType = "meshagent.agent.thread.start.rejected";
|
|
14
14
|
export const agentThreadOpenType = "meshagent.agent.thread.open";
|
|
15
15
|
export const agentThreadCloseType = "meshagent.agent.thread.close";
|
|
16
|
+
export const agentMessagesInjectType = "meshagent.agent.messages.inject";
|
|
16
17
|
export const agentParticipantConnectType = "meshagent.agent.participant.connect";
|
|
17
18
|
export const agentParticipantDisconnectType = "meshagent.agent.participant.disconnect";
|
|
18
19
|
export const agentThreadDeleteType = "meshagent.agent.thread.delete";
|
|
@@ -82,6 +83,33 @@ export const agentToolApproveType = "meshagent.agent.tool_call.approve";
|
|
|
82
83
|
export const agentToolRejectType = "meshagent.agent.tool_call.reject";
|
|
83
84
|
export const agentSecretResponseType = "meshagent.agent.secret.response";
|
|
84
85
|
export const agentClientToolCallResponseType = "meshagent.agent.client_tool_call.response";
|
|
86
|
+
export class AgentFileContent {
|
|
87
|
+
constructor({ url, name }) {
|
|
88
|
+
this.type = "file";
|
|
89
|
+
this.url = url;
|
|
90
|
+
this.name = name;
|
|
91
|
+
}
|
|
92
|
+
static fromJson(json) {
|
|
93
|
+
return new AgentFileContent({
|
|
94
|
+
url: requiredString(json, "url"),
|
|
95
|
+
name: stringOrNull(json.name),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
toJson() {
|
|
99
|
+
return {
|
|
100
|
+
type: this.type,
|
|
101
|
+
url: this.url,
|
|
102
|
+
...(this.name != null ? { name: this.name } : {}),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
formatWith(values) {
|
|
106
|
+
const format = (value) => value.replace(/\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (token, key) => values[key] ?? token);
|
|
107
|
+
return new AgentFileContent({
|
|
108
|
+
url: format(this.url),
|
|
109
|
+
name: this.name == null ? undefined : format(this.name),
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
85
113
|
const globalScope = globalThis;
|
|
86
114
|
function hasOwn(value, key) {
|
|
87
115
|
return Object.prototype.hasOwnProperty.call(value, key);
|
|
@@ -129,13 +157,6 @@ function requiredString(json, key) {
|
|
|
129
157
|
}
|
|
130
158
|
throw new TypeError(`missing string field '${key}'`);
|
|
131
159
|
}
|
|
132
|
-
function requiredInt(json, key) {
|
|
133
|
-
const value = intOrNull(json[key]);
|
|
134
|
-
if (value !== undefined) {
|
|
135
|
-
return value;
|
|
136
|
-
}
|
|
137
|
-
throw new TypeError(`missing integer field '${key}'`);
|
|
138
|
-
}
|
|
139
160
|
function requiredMap(json, key) {
|
|
140
161
|
const value = dynamicMapOrNull(json[key]);
|
|
141
162
|
if (value != null) {
|
|
@@ -216,7 +237,7 @@ function inputContentFromJson(value) {
|
|
|
216
237
|
return { type: "text", text: requiredString(json, "text") };
|
|
217
238
|
}
|
|
218
239
|
if (json.type === "file") {
|
|
219
|
-
return
|
|
240
|
+
return AgentFileContent.fromJson(json);
|
|
220
241
|
}
|
|
221
242
|
throw new TypeError("unsupported agent input content type");
|
|
222
243
|
}
|
|
@@ -233,7 +254,17 @@ function objectList(value, fromJson) {
|
|
|
233
254
|
if (!Array.isArray(value)) {
|
|
234
255
|
return [];
|
|
235
256
|
}
|
|
236
|
-
return value.map((entry) =>
|
|
257
|
+
return value.map((entry) => (entry != null && typeof entry === "object" && typeof entry.toJson === "function"
|
|
258
|
+
? entry
|
|
259
|
+
: fromJson(requiredObjectValue(entry))));
|
|
260
|
+
}
|
|
261
|
+
function agentMessageList(value) {
|
|
262
|
+
if (!Array.isArray(value)) {
|
|
263
|
+
return [];
|
|
264
|
+
}
|
|
265
|
+
return value.map((entry) => (entry instanceof AgentMessage
|
|
266
|
+
? entry
|
|
267
|
+
: AgentMessage.fromJson(requiredObjectValue(entry))));
|
|
237
268
|
}
|
|
238
269
|
function mapListOrNull(value) {
|
|
239
270
|
if (!Array.isArray(value)) {
|
|
@@ -272,16 +303,19 @@ function maybeToJson(value) {
|
|
|
272
303
|
return value != null && typeof value.toJson === "function" ? value.toJson() : value;
|
|
273
304
|
}
|
|
274
305
|
function contentToJson(value) {
|
|
275
|
-
return { ...value };
|
|
306
|
+
return value instanceof AgentFileContent ? value.toJson() : { ...value };
|
|
276
307
|
}
|
|
277
308
|
function objectOrNull(value, fromJson) {
|
|
309
|
+
if (value != null && typeof value === "object" && typeof value.toJson === "function") {
|
|
310
|
+
return value;
|
|
311
|
+
}
|
|
278
312
|
const map = dynamicMapOrNull(value);
|
|
279
313
|
return map == null ? undefined : fromJson(map);
|
|
280
314
|
}
|
|
281
315
|
export class ToolChoice {
|
|
282
|
-
constructor({ toolkitName, toolName
|
|
283
|
-
this.toolkitName =
|
|
284
|
-
this.toolName =
|
|
316
|
+
constructor({ toolkitName, toolName }) {
|
|
317
|
+
this.toolkitName = toolkitName;
|
|
318
|
+
this.toolName = toolName;
|
|
285
319
|
}
|
|
286
320
|
static fromJson(json) {
|
|
287
321
|
return new ToolChoice({ toolkitName: requiredString(json, "toolkit_name"), toolName: requiredString(json, "tool_name") });
|
|
@@ -292,7 +326,7 @@ export class ToolChoice {
|
|
|
292
326
|
}
|
|
293
327
|
export class TurnMcpConfig {
|
|
294
328
|
constructor({ servers = [] } = {}) {
|
|
295
|
-
this.servers =
|
|
329
|
+
this.servers = servers;
|
|
296
330
|
}
|
|
297
331
|
static fromJson(json) {
|
|
298
332
|
return new TurnMcpConfig({ servers: mapListOrNull(json.servers) ?? [] });
|
|
@@ -302,18 +336,18 @@ export class TurnMcpConfig {
|
|
|
302
336
|
}
|
|
303
337
|
}
|
|
304
338
|
export class ClientToolkitDescription {
|
|
305
|
-
constructor({ name, title, description, inputSchema
|
|
306
|
-
this.name =
|
|
307
|
-
this.title =
|
|
308
|
-
this.description =
|
|
309
|
-
this.inputSchema =
|
|
339
|
+
constructor({ name, title, description, inputSchema }) {
|
|
340
|
+
this.name = name;
|
|
341
|
+
this.title = title;
|
|
342
|
+
this.description = description;
|
|
343
|
+
this.inputSchema = inputSchema;
|
|
310
344
|
}
|
|
311
345
|
static fromJson(json) {
|
|
312
346
|
return new ClientToolkitDescription({
|
|
313
347
|
name: requiredString(json, "name"),
|
|
314
348
|
title: stringOrNull(json.title),
|
|
315
349
|
description: stringOrNull(json.description),
|
|
316
|
-
inputSchema:
|
|
350
|
+
inputSchema: requiredMap(json, "input_schema"),
|
|
317
351
|
});
|
|
318
352
|
}
|
|
319
353
|
toJson() {
|
|
@@ -326,8 +360,8 @@ export class ClientToolkitDescription {
|
|
|
326
360
|
}
|
|
327
361
|
}
|
|
328
362
|
export class TurnToolkitConfig {
|
|
329
|
-
constructor({ clientOptions
|
|
330
|
-
this.clientOptions =
|
|
363
|
+
constructor({ clientOptions } = {}) {
|
|
364
|
+
this.clientOptions = clientOptions;
|
|
331
365
|
}
|
|
332
366
|
static fromJson(json) {
|
|
333
367
|
return new TurnToolkitConfig({ clientOptions: dynamicMapOrNull(json.client_options) });
|
|
@@ -350,15 +384,15 @@ function turnMcpConfigOrNull(value) {
|
|
|
350
384
|
return objectOrNull(value, TurnMcpConfig.fromJson);
|
|
351
385
|
}
|
|
352
386
|
export class AgentAudioFormat {
|
|
353
|
-
constructor({ type = "audio/pcm", sampleRate
|
|
354
|
-
this.type =
|
|
355
|
-
this.sampleRate =
|
|
356
|
-
this.bitrate =
|
|
387
|
+
constructor({ type = "audio/pcm", sampleRate = 24000, bitrate } = {}) {
|
|
388
|
+
this.type = type;
|
|
389
|
+
this.sampleRate = sampleRate ?? undefined;
|
|
390
|
+
this.bitrate = bitrate;
|
|
357
391
|
}
|
|
358
392
|
static fromJson(json) {
|
|
359
393
|
return new AgentAudioFormat({
|
|
360
394
|
type: stringOrNull(json.type) ?? "audio/pcm",
|
|
361
|
-
sampleRate: intOrNull(json.sample_rate),
|
|
395
|
+
sampleRate: intOrNull(json.sample_rate) ?? null,
|
|
362
396
|
bitrate: intOrNull(json.bitrate),
|
|
363
397
|
});
|
|
364
398
|
}
|
|
@@ -390,9 +424,9 @@ export class AgentError {
|
|
|
390
424
|
}
|
|
391
425
|
export class ToolkitToolCapabilities {
|
|
392
426
|
constructor({ name, title, description }) {
|
|
393
|
-
this.name =
|
|
394
|
-
this.title =
|
|
395
|
-
this.description =
|
|
427
|
+
this.name = name;
|
|
428
|
+
this.title = title;
|
|
429
|
+
this.description = description;
|
|
396
430
|
}
|
|
397
431
|
static fromJson(json) {
|
|
398
432
|
return new ToolkitToolCapabilities({
|
|
@@ -410,25 +444,31 @@ export class ToolkitToolCapabilities {
|
|
|
410
444
|
}
|
|
411
445
|
}
|
|
412
446
|
export class ToolkitCapabilities {
|
|
413
|
-
constructor(
|
|
414
|
-
this.name =
|
|
415
|
-
this.title =
|
|
416
|
-
this.description =
|
|
417
|
-
this.
|
|
418
|
-
this.
|
|
419
|
-
this.
|
|
420
|
-
this.
|
|
421
|
-
this.tools = Array.isArray(params.tools) ? params.tools.map((entry) => entry instanceof ToolkitToolCapabilities ? entry : ToolkitToolCapabilities.fromJson(requiredObjectValue(entry))) : [];
|
|
447
|
+
constructor({ name, title, description, rules = [], clientOptions, hidden = false, tools = [] }) {
|
|
448
|
+
this.name = name;
|
|
449
|
+
this.title = title;
|
|
450
|
+
this.description = description;
|
|
451
|
+
this.rules = rules;
|
|
452
|
+
this.clientOptions = clientOptions;
|
|
453
|
+
this.hidden = hidden;
|
|
454
|
+
this.tools = tools;
|
|
422
455
|
}
|
|
423
456
|
static fromJson(json) {
|
|
424
|
-
return new ToolkitCapabilities(
|
|
457
|
+
return new ToolkitCapabilities({
|
|
458
|
+
name: requiredString(json, "name"),
|
|
459
|
+
title: stringOrNull(json.title),
|
|
460
|
+
description: stringOrNull(json.description),
|
|
461
|
+
rules: stringList(json.rules),
|
|
462
|
+
clientOptions: dynamicMapOrNull(json.client_options),
|
|
463
|
+
hidden: json.hidden === true,
|
|
464
|
+
tools: objectList(json.tools, ToolkitToolCapabilities.fromJson),
|
|
465
|
+
});
|
|
425
466
|
}
|
|
426
467
|
toJson() {
|
|
427
468
|
return {
|
|
428
469
|
name: this.name,
|
|
429
470
|
...(this.title != null ? { title: this.title } : {}),
|
|
430
471
|
...(this.description != null ? { description: this.description } : {}),
|
|
431
|
-
...(this.thumbnailUrl != null ? { thumbnail_url: this.thumbnailUrl } : {}),
|
|
432
472
|
rules: this.rules,
|
|
433
473
|
...(this.clientOptions != null ? { client_options: this.clientOptions } : {}),
|
|
434
474
|
hidden: this.hidden,
|
|
@@ -437,23 +477,41 @@ export class ToolkitCapabilities {
|
|
|
437
477
|
}
|
|
438
478
|
}
|
|
439
479
|
export class AgentModelInfo {
|
|
440
|
-
constructor(
|
|
441
|
-
this.name =
|
|
442
|
-
this.friendlyName =
|
|
443
|
-
this.description =
|
|
444
|
-
this.contextWindow =
|
|
445
|
-
this.pricing =
|
|
446
|
-
this.modalities =
|
|
447
|
-
this.availableVoices =
|
|
448
|
-
this.defaultOutputVoice =
|
|
449
|
-
this.inputFormat =
|
|
450
|
-
this.outputFormat =
|
|
451
|
-
this.turnDetection =
|
|
452
|
-
this.realtimeProtocols =
|
|
453
|
-
this.
|
|
480
|
+
constructor({ name, friendlyName, description, contextWindow, pricing, modalities = ["text"], availableVoices = [], defaultOutputVoice, inputFormat, outputFormat, turnDetection, realtimeProtocols = [], supportsAttachments = false, accepts = [], active = false }) {
|
|
481
|
+
this.name = name;
|
|
482
|
+
this.friendlyName = friendlyName;
|
|
483
|
+
this.description = description;
|
|
484
|
+
this.contextWindow = contextWindow;
|
|
485
|
+
this.pricing = pricing;
|
|
486
|
+
this.modalities = modalities;
|
|
487
|
+
this.availableVoices = availableVoices;
|
|
488
|
+
this.defaultOutputVoice = defaultOutputVoice;
|
|
489
|
+
this.inputFormat = inputFormat;
|
|
490
|
+
this.outputFormat = outputFormat;
|
|
491
|
+
this.turnDetection = turnDetection;
|
|
492
|
+
this.realtimeProtocols = realtimeProtocols;
|
|
493
|
+
this.supportsAttachments = supportsAttachments;
|
|
494
|
+
this.accepts = accepts;
|
|
495
|
+
this.active = active;
|
|
454
496
|
}
|
|
455
497
|
static fromJson(json) {
|
|
456
|
-
return new AgentModelInfo(
|
|
498
|
+
return new AgentModelInfo({
|
|
499
|
+
name: requiredString(json, "name"),
|
|
500
|
+
friendlyName: stringOrNull(json.friendly_name),
|
|
501
|
+
description: stringOrNull(json.description),
|
|
502
|
+
contextWindow: intOrNull(json.context_window),
|
|
503
|
+
pricing: doubleMapOrNull(json.pricing),
|
|
504
|
+
modalities: stringList(json.modalities, ["text"]),
|
|
505
|
+
availableVoices: stringList(json.available_voices),
|
|
506
|
+
defaultOutputVoice: stringOrNull(json.default_output_voice),
|
|
507
|
+
inputFormat: audioFormatOrNull(json.input_format),
|
|
508
|
+
outputFormat: audioFormatOrNull(json.output_format),
|
|
509
|
+
turnDetection: stringOrNull(json.turn_detection),
|
|
510
|
+
realtimeProtocols: stringList(json.realtime_protocols),
|
|
511
|
+
supportsAttachments: json.supports_attachments === true,
|
|
512
|
+
accepts: stringList(json.accepts),
|
|
513
|
+
active: json.active === true,
|
|
514
|
+
});
|
|
457
515
|
}
|
|
458
516
|
toJson() {
|
|
459
517
|
return {
|
|
@@ -469,21 +527,30 @@ export class AgentModelInfo {
|
|
|
469
527
|
...(this.outputFormat != null ? { output_format: this.outputFormat.toJson() } : {}),
|
|
470
528
|
...(this.turnDetection != null ? { turn_detection: this.turnDetection } : {}),
|
|
471
529
|
realtime_protocols: this.realtimeProtocols,
|
|
530
|
+
supports_attachments: this.supportsAttachments,
|
|
531
|
+
accepts: this.accepts,
|
|
472
532
|
active: this.active,
|
|
473
533
|
};
|
|
474
534
|
}
|
|
475
535
|
}
|
|
476
536
|
export class AgentProviderInfo {
|
|
477
|
-
constructor(
|
|
478
|
-
this.name =
|
|
479
|
-
this.friendlyName =
|
|
480
|
-
this.description =
|
|
481
|
-
this.backend =
|
|
482
|
-
this.defaultModel =
|
|
483
|
-
this.models =
|
|
537
|
+
constructor({ name, friendlyName, description, backend, defaultModel, models = [] }) {
|
|
538
|
+
this.name = name;
|
|
539
|
+
this.friendlyName = friendlyName;
|
|
540
|
+
this.description = description;
|
|
541
|
+
this.backend = backend;
|
|
542
|
+
this.defaultModel = defaultModel;
|
|
543
|
+
this.models = models;
|
|
484
544
|
}
|
|
485
545
|
static fromJson(json) {
|
|
486
|
-
return new AgentProviderInfo(
|
|
546
|
+
return new AgentProviderInfo({
|
|
547
|
+
name: requiredString(json, "name"),
|
|
548
|
+
friendlyName: requiredString(json, "friendly_name"),
|
|
549
|
+
description: stringOrNull(json.description),
|
|
550
|
+
backend: stringOrNull(json.backend),
|
|
551
|
+
defaultModel: requiredString(json, "default_model"),
|
|
552
|
+
models: objectList(json.models, AgentModelInfo.fromJson),
|
|
553
|
+
});
|
|
487
554
|
}
|
|
488
555
|
toJson() {
|
|
489
556
|
return {
|
|
@@ -497,16 +564,16 @@ export class AgentProviderInfo {
|
|
|
497
564
|
}
|
|
498
565
|
}
|
|
499
566
|
export class AgentThreadListEntry {
|
|
500
|
-
constructor(
|
|
501
|
-
this.path =
|
|
502
|
-
this.name =
|
|
503
|
-
this.createdAt =
|
|
504
|
-
this.modifiedAt =
|
|
567
|
+
constructor({ path, name, createdAt, modifiedAt }) {
|
|
568
|
+
this.path = path;
|
|
569
|
+
this.name = name;
|
|
570
|
+
this.createdAt = createdAt;
|
|
571
|
+
this.modifiedAt = modifiedAt;
|
|
505
572
|
}
|
|
506
573
|
static fromJson(json) {
|
|
507
574
|
return new AgentThreadListEntry({
|
|
508
575
|
path: requiredString(json, "path"),
|
|
509
|
-
name:
|
|
576
|
+
name: requiredString(json, "name"),
|
|
510
577
|
createdAt: stringOrNull(json.created_at) ?? "",
|
|
511
578
|
modifiedAt: stringOrNull(json.modified_at) ?? "",
|
|
512
579
|
});
|
|
@@ -521,11 +588,11 @@ export class AgentThreadListEntry {
|
|
|
521
588
|
}
|
|
522
589
|
}
|
|
523
590
|
export class AgentRealtimeConnectionInfo {
|
|
524
|
-
constructor(
|
|
525
|
-
this.protocol =
|
|
526
|
-
this.url =
|
|
527
|
-
this.headers =
|
|
528
|
-
this.webOnlyProtocol =
|
|
591
|
+
constructor({ protocol, url, headers = {}, webOnlyProtocol }) {
|
|
592
|
+
this.protocol = protocol;
|
|
593
|
+
this.url = url;
|
|
594
|
+
this.headers = headers;
|
|
595
|
+
this.webOnlyProtocol = webOnlyProtocol;
|
|
529
596
|
}
|
|
530
597
|
static fromJson(json) {
|
|
531
598
|
return new AgentRealtimeConnectionInfo({
|
|
@@ -546,8 +613,8 @@ export class AgentRealtimeConnectionInfo {
|
|
|
546
613
|
}
|
|
547
614
|
export class AgentToolCallLogLine {
|
|
548
615
|
constructor({ source, text }) {
|
|
549
|
-
this.source =
|
|
550
|
-
this.text =
|
|
616
|
+
this.source = source;
|
|
617
|
+
this.text = text;
|
|
551
618
|
}
|
|
552
619
|
static fromJson(json) {
|
|
553
620
|
return new AgentToolCallLogLine({ source: requiredString(json, "source"), text: requiredString(json, "text") });
|
|
@@ -557,17 +624,25 @@ export class AgentToolCallLogLine {
|
|
|
557
624
|
}
|
|
558
625
|
}
|
|
559
626
|
export class AgentGeneratedImage {
|
|
560
|
-
constructor(
|
|
561
|
-
this.uri =
|
|
562
|
-
this.mimeType =
|
|
563
|
-
this.createdAt =
|
|
564
|
-
this.createdBy =
|
|
565
|
-
this.width =
|
|
566
|
-
this.height =
|
|
567
|
-
this.status =
|
|
627
|
+
constructor({ uri, mimeType, createdAt, createdBy, width, height, status } = {}) {
|
|
628
|
+
this.uri = uri;
|
|
629
|
+
this.mimeType = mimeType;
|
|
630
|
+
this.createdAt = createdAt;
|
|
631
|
+
this.createdBy = createdBy;
|
|
632
|
+
this.width = width;
|
|
633
|
+
this.height = height;
|
|
634
|
+
this.status = status;
|
|
568
635
|
}
|
|
569
636
|
static fromJson(json) {
|
|
570
|
-
return new AgentGeneratedImage(
|
|
637
|
+
return new AgentGeneratedImage({
|
|
638
|
+
uri: stringOrNull(json.uri),
|
|
639
|
+
mimeType: stringOrNull(json.mime_type),
|
|
640
|
+
createdAt: stringOrNull(json.created_at),
|
|
641
|
+
createdBy: stringOrNull(json.created_by),
|
|
642
|
+
width: numOrNull(json.width),
|
|
643
|
+
height: numOrNull(json.height),
|
|
644
|
+
status: stringOrNull(json.status),
|
|
645
|
+
});
|
|
571
646
|
}
|
|
572
647
|
toJson() {
|
|
573
648
|
return omitUndefined({
|
|
@@ -582,16 +657,23 @@ export class AgentGeneratedImage {
|
|
|
582
657
|
}
|
|
583
658
|
}
|
|
584
659
|
export class AgentGeneratedAudio {
|
|
585
|
-
constructor(
|
|
586
|
-
this.uri =
|
|
587
|
-
this.mimeType =
|
|
588
|
-
this.createdAt =
|
|
589
|
-
this.createdBy =
|
|
590
|
-
this.status =
|
|
591
|
-
this.transcript =
|
|
660
|
+
constructor({ uri, mimeType, createdAt, createdBy, status, transcript } = {}) {
|
|
661
|
+
this.uri = uri;
|
|
662
|
+
this.mimeType = mimeType;
|
|
663
|
+
this.createdAt = createdAt;
|
|
664
|
+
this.createdBy = createdBy;
|
|
665
|
+
this.status = status;
|
|
666
|
+
this.transcript = transcript;
|
|
592
667
|
}
|
|
593
668
|
static fromJson(json) {
|
|
594
|
-
return new AgentGeneratedAudio(
|
|
669
|
+
return new AgentGeneratedAudio({
|
|
670
|
+
uri: stringOrNull(json.uri),
|
|
671
|
+
mimeType: stringOrNull(json.mime_type),
|
|
672
|
+
createdAt: stringOrNull(json.created_at),
|
|
673
|
+
createdBy: stringOrNull(json.created_by),
|
|
674
|
+
status: stringOrNull(json.status),
|
|
675
|
+
transcript: stringOrNull(json.transcript),
|
|
676
|
+
});
|
|
595
677
|
}
|
|
596
678
|
toJson() {
|
|
597
679
|
return omitUndefined({
|
|
@@ -605,11 +687,11 @@ export class AgentGeneratedAudio {
|
|
|
605
687
|
}
|
|
606
688
|
}
|
|
607
689
|
export class AgentContextWindowUsage {
|
|
608
|
-
constructor(
|
|
609
|
-
this.usedTokens =
|
|
610
|
-
this.totalTokens =
|
|
611
|
-
this.compactionMode =
|
|
612
|
-
this.compactionThreshold =
|
|
690
|
+
constructor({ usedTokens, totalTokens, compactionMode, compactionThreshold }) {
|
|
691
|
+
this.usedTokens = usedTokens;
|
|
692
|
+
this.totalTokens = totalTokens;
|
|
693
|
+
this.compactionMode = compactionMode;
|
|
694
|
+
this.compactionThreshold = compactionThreshold;
|
|
613
695
|
}
|
|
614
696
|
static fromJson(json) {
|
|
615
697
|
const usedTokens = intOrNull(json.used_tokens ?? json.usedTokens) ?? 0;
|
|
@@ -638,19 +720,22 @@ export class AgentMessage {
|
|
|
638
720
|
const resolvedMessageId = stringOrNull(messageId ?? message_id)?.trim();
|
|
639
721
|
this.messageId = resolvedMessageId == null || resolvedMessageId.length === 0 ? uuidv4() : resolvedMessageId;
|
|
640
722
|
this.senderName = stringOrNull(senderName ?? sender_name);
|
|
641
|
-
|
|
723
|
+
const createdAtValue = createdAt ?? created_at;
|
|
724
|
+
const parsedCreatedAt = createdAtValue instanceof Date ? createdAtValue : new Date(String(createdAtValue ?? ""));
|
|
725
|
+
this.createdAtUtc = Number.isNaN(parsedCreatedAt.getTime()) ? new Date() : parsedCreatedAt;
|
|
642
726
|
this.metadata = dynamicMapOrNull(metadata) ?? {};
|
|
643
727
|
}
|
|
644
728
|
toJson() {
|
|
645
729
|
return {
|
|
646
730
|
type: this.type,
|
|
647
731
|
message_id: this.messageId,
|
|
648
|
-
created_at: this.
|
|
732
|
+
created_at: this.createdAtUtc.toISOString(),
|
|
649
733
|
...(Object.keys(this.metadata).length > 0 ? { metadata: this.metadata } : {}),
|
|
650
734
|
...(this.senderName != null ? { sender_name: this.senderName } : {}),
|
|
651
735
|
};
|
|
652
736
|
}
|
|
653
737
|
static fromJson(json) {
|
|
738
|
+
json = normalizeAgentMessageJson(json);
|
|
654
739
|
const type = json.type;
|
|
655
740
|
if (typeof type !== "string" || type.trim() === "") {
|
|
656
741
|
throw new TypeError("missing string field 'type'");
|
|
@@ -690,9 +775,55 @@ function register(type, ctor) {
|
|
|
690
775
|
messageConstructors[type] = ctor;
|
|
691
776
|
return ctor;
|
|
692
777
|
}
|
|
693
|
-
|
|
778
|
+
const agentMessageTypesWithRequiredItemId = new Set([
|
|
779
|
+
agentReasoningContentStartedType,
|
|
780
|
+
agentReasoningContentDeltaType,
|
|
781
|
+
agentReasoningContentEndedType,
|
|
782
|
+
agentTextContentStartedType,
|
|
783
|
+
agentTextContentDeltaType,
|
|
784
|
+
agentTextContentEndedType,
|
|
785
|
+
agentFileContentStartedType,
|
|
786
|
+
agentFileContentDeltaType,
|
|
787
|
+
agentFileContentEndedType,
|
|
788
|
+
agentToolCallPendingType,
|
|
789
|
+
agentToolCallInProgressType,
|
|
790
|
+
agentToolCallStartedType,
|
|
791
|
+
agentToolCallArgumentsDeltaType,
|
|
792
|
+
agentToolCallLogDeltaType,
|
|
793
|
+
agentToolCallEndedType,
|
|
794
|
+
agentToolCallApprovalRequestedType,
|
|
795
|
+
agentImageGenerationStartedType,
|
|
796
|
+
agentImageGenerationPartialType,
|
|
797
|
+
agentImageGenerationCompletedType,
|
|
798
|
+
agentImageGenerationFailedType,
|
|
799
|
+
]);
|
|
800
|
+
function normalizeAgentMessageJson(json) {
|
|
801
|
+
const type = stringOrNull(json.type);
|
|
802
|
+
if (type == null || !agentMessageTypesWithRequiredItemId.has(type) || normalizedString(json.item_id) != null) {
|
|
803
|
+
return json;
|
|
804
|
+
}
|
|
805
|
+
const itemId = fallbackItemId(json, type);
|
|
806
|
+
return itemId == null ? json : { ...json, item_id: itemId };
|
|
807
|
+
}
|
|
808
|
+
function fallbackItemId(json, type) {
|
|
809
|
+
const direct = normalizedString(json.itemId)
|
|
810
|
+
?? normalizedString(json.id)
|
|
811
|
+
?? normalizedString(json.call_id)
|
|
812
|
+
?? normalizedString(json.request_id)
|
|
813
|
+
?? normalizedString(json.message_id);
|
|
814
|
+
if (direct != null) {
|
|
815
|
+
return direct;
|
|
816
|
+
}
|
|
817
|
+
const turnId = normalizedString(json.turn_id) ?? normalizedString(json.turnId);
|
|
818
|
+
return turnId == null ? undefined : `${turnId}:${type}`;
|
|
819
|
+
}
|
|
820
|
+
function normalizedString(value) {
|
|
821
|
+
const normalized = stringOrNull(value)?.trim();
|
|
822
|
+
return normalized === "" ? undefined : normalized;
|
|
823
|
+
}
|
|
824
|
+
function makeMessageClass(className, { type, base = "message", fields = [], }) {
|
|
694
825
|
const Parent = base === "llm" ? AgentLLMMessage : base === "thread" ? AgentThreadMessage : AgentMessage;
|
|
695
|
-
|
|
826
|
+
const GeneratedMessage = class extends Parent {
|
|
696
827
|
constructor(params = {}) {
|
|
697
828
|
super({ ...params, type });
|
|
698
829
|
for (const field of fields) {
|
|
@@ -756,7 +887,9 @@ function makeMessageClass({ type, base = "message", fields = [], }) {
|
|
|
756
887
|
}
|
|
757
888
|
return json;
|
|
758
889
|
}
|
|
759
|
-
}
|
|
890
|
+
};
|
|
891
|
+
Object.defineProperty(GeneratedMessage, "name", { value: className });
|
|
892
|
+
return register(type, GeneratedMessage);
|
|
760
893
|
}
|
|
761
894
|
const s = (prop, json = snake(prop), required = false) => ({
|
|
762
895
|
prop,
|
|
@@ -881,7 +1014,7 @@ const imageGeneration = [
|
|
|
881
1014
|
{ prop: "tool", json: "tool", from: (value) => stringOrNull(value) ?? "image_generation", default: () => "image_generation", always: true },
|
|
882
1015
|
m("arguments"),
|
|
883
1016
|
];
|
|
884
|
-
export const StartThread = makeMessageClass({
|
|
1017
|
+
export const StartThread = makeMessageClass("StartThread", {
|
|
885
1018
|
type: agentThreadStartType,
|
|
886
1019
|
fields: [
|
|
887
1020
|
contentList("content", true),
|
|
@@ -899,96 +1032,114 @@ export const StartThread = makeMessageClass({
|
|
|
899
1032
|
obj("toolChoice", "tool_choice", ToolChoice.fromJson),
|
|
900
1033
|
],
|
|
901
1034
|
});
|
|
902
|
-
export const TurnStart = makeMessageClass({ type: agentTurnStartType, base: "thread", fields: turnOptions });
|
|
903
|
-
export const TurnSteer = makeMessageClass({ type: agentTurnSteerType, base: "thread", fields: [s("turnId", "turn_id", true), contentList("content")] });
|
|
904
|
-
export const TurnInterrupt = makeMessageClass({ type: agentTurnInterruptType, base: "thread", fields: [s("turnId", "turn_id", true)] });
|
|
905
|
-
export const AgentRealtimeAudioChunk = makeMessageClass({ type: agentRealtimeAudioChunkType, base: "thread", fields: [bytesField("data"), audioFormat("format", "format", true)] });
|
|
906
|
-
export const AgentRealtimeAudioCommit = makeMessageClass({ type: agentRealtimeAudioCommitType, base: "thread", fields: [s("turnId"), s("text"), s("status"), s("transcriptionItemId")] });
|
|
907
|
-
export const ClearThread = makeMessageClass({ type: agentThreadClearType, base: "thread" });
|
|
908
|
-
export const OpenThread = makeMessageClass({ type: agentThreadOpenType, base: "thread", fields: [{ prop: "load", json: "load", from: (value) => typeof value === "boolean" ? value : undefined }, s("sinceTurn")] });
|
|
909
|
-
export const CloseThread = makeMessageClass({ type: agentThreadCloseType, base: "thread" });
|
|
910
|
-
export const
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
export const
|
|
923
|
-
export const
|
|
924
|
-
export const
|
|
925
|
-
export const
|
|
926
|
-
export const
|
|
927
|
-
export const
|
|
928
|
-
export const
|
|
929
|
-
export const
|
|
930
|
-
export const
|
|
931
|
-
export const
|
|
932
|
-
export const
|
|
933
|
-
export const
|
|
934
|
-
export const
|
|
935
|
-
export const
|
|
936
|
-
export const
|
|
937
|
-
export const
|
|
938
|
-
export const
|
|
939
|
-
export const
|
|
940
|
-
export const
|
|
941
|
-
export const
|
|
942
|
-
export const
|
|
943
|
-
export const
|
|
944
|
-
export const
|
|
945
|
-
export const
|
|
946
|
-
export const
|
|
947
|
-
export const
|
|
948
|
-
export const
|
|
949
|
-
export const
|
|
950
|
-
export const
|
|
951
|
-
export const
|
|
952
|
-
export const
|
|
953
|
-
export const
|
|
954
|
-
export const
|
|
955
|
-
export const
|
|
956
|
-
export const
|
|
957
|
-
export const
|
|
958
|
-
export const
|
|
959
|
-
export const
|
|
960
|
-
export const
|
|
961
|
-
export const
|
|
962
|
-
export const
|
|
963
|
-
export const
|
|
964
|
-
export const
|
|
965
|
-
export const
|
|
966
|
-
export const
|
|
967
|
-
export const
|
|
968
|
-
export const
|
|
969
|
-
export const
|
|
970
|
-
export const
|
|
971
|
-
export const
|
|
972
|
-
export const
|
|
973
|
-
export const
|
|
974
|
-
export const
|
|
975
|
-
export const
|
|
976
|
-
export const
|
|
977
|
-
export const
|
|
978
|
-
export const
|
|
979
|
-
export const
|
|
980
|
-
export const
|
|
981
|
-
export const
|
|
982
|
-
export
|
|
1035
|
+
export const TurnStart = makeMessageClass("TurnStart", { type: agentTurnStartType, base: "thread", fields: turnOptions });
|
|
1036
|
+
export const TurnSteer = makeMessageClass("TurnSteer", { type: agentTurnSteerType, base: "thread", fields: [s("turnId", "turn_id", true), contentList("content")] });
|
|
1037
|
+
export const TurnInterrupt = makeMessageClass("TurnInterrupt", { type: agentTurnInterruptType, base: "thread", fields: [s("turnId", "turn_id", true)] });
|
|
1038
|
+
export const AgentRealtimeAudioChunk = makeMessageClass("AgentRealtimeAudioChunk", { type: agentRealtimeAudioChunkType, base: "thread", fields: [bytesField("data"), audioFormat("format", "format", true)] });
|
|
1039
|
+
export const AgentRealtimeAudioCommit = makeMessageClass("AgentRealtimeAudioCommit", { type: agentRealtimeAudioCommitType, base: "thread", fields: [s("turnId"), s("text"), s("status"), s("transcriptionItemId")] });
|
|
1040
|
+
export const ClearThread = makeMessageClass("ClearThread", { type: agentThreadClearType, base: "thread" });
|
|
1041
|
+
export const OpenThread = makeMessageClass("OpenThread", { type: agentThreadOpenType, base: "thread", fields: [s("backend"), { prop: "load", json: "load", from: (value) => typeof value === "boolean" ? value : undefined }, s("sinceTurn")] });
|
|
1042
|
+
export const CloseThread = makeMessageClass("CloseThread", { type: agentThreadCloseType, base: "thread" });
|
|
1043
|
+
export const InjectMessages = makeMessageClass("InjectMessages", {
|
|
1044
|
+
type: agentMessagesInjectType,
|
|
1045
|
+
base: "thread",
|
|
1046
|
+
fields: [{
|
|
1047
|
+
prop: "messages",
|
|
1048
|
+
json: "messages",
|
|
1049
|
+
from: agentMessageList,
|
|
1050
|
+
default: () => [],
|
|
1051
|
+
always: true,
|
|
1052
|
+
to: (messages) => messages.map((message) => message.toJson()),
|
|
1053
|
+
}],
|
|
1054
|
+
});
|
|
1055
|
+
export const ParticipantConnect = makeMessageClass("ParticipantConnect", { type: agentParticipantConnectType, fields: [s("participantId", "participant_id", true)] });
|
|
1056
|
+
export const ParticipantDisconnect = makeMessageClass("ParticipantDisconnect", { type: agentParticipantDisconnectType, fields: [s("participantId", "participant_id", true)] });
|
|
1057
|
+
export const DeleteThread = makeMessageClass("DeleteThread", { type: agentThreadDeleteType, base: "thread" });
|
|
1058
|
+
export const RenameThread = makeMessageClass("RenameThread", { type: agentThreadRenameType, base: "thread", fields: [s("name", "name", true)] });
|
|
1059
|
+
export const ListThreads = makeMessageClass("ListThreads", { 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 }] });
|
|
1060
|
+
export const WatchThreads = makeMessageClass("WatchThreads", { type: agentThreadWatchType });
|
|
1061
|
+
export const UnwatchThreads = makeMessageClass("UnwatchThreads", { type: agentThreadUnwatchType });
|
|
1062
|
+
export const ThreadsListed = makeMessageClass("ThreadsListed", { type: agentThreadListedType, fields: [s("sourceMessageId", "source_message_id", true), { prop: "threads", json: "threads", from: (value) => objectList(value, AgentThreadListEntry.fromJson), default: () => [], always: true, to: (value) => value.map(maybeToJson) }, { prop: "total", json: "total", from: intOrNull, default: (params) => Array.isArray(params.threads) ? params.threads.length : 0, always: true }, { prop: "offset", json: "offset", from: (value) => intOrNull(value) ?? 0, default: () => 0, always: true }, { prop: "limit", json: "limit", from: intOrNull, default: (params) => Array.isArray(params.threads) ? params.threads.length : 0, always: true }] });
|
|
1063
|
+
export const ThreadCreated = makeMessageClass("ThreadCreated", { type: agentThreadCreatedType, fields: [obj("thread", "thread", AgentThreadListEntry.fromJson, true)] });
|
|
1064
|
+
export const ThreadUpdated = makeMessageClass("ThreadUpdated", { type: agentThreadUpdatedType, fields: [obj("thread", "thread", AgentThreadListEntry.fromJson, true)] });
|
|
1065
|
+
export const ThreadDeleted = makeMessageClass("ThreadDeleted", { type: agentThreadDeletedType, fields: [s("path", "path", true)] });
|
|
1066
|
+
export const CapabilitiesRequest = makeMessageClass("CapabilitiesRequest", { type: agentCapabilitiesRequestType, base: "thread" });
|
|
1067
|
+
export const CapabilitiesResponse = makeMessageClass("CapabilitiesResponse", { type: agentCapabilitiesResponseType, base: "thread", fields: [s("sourceMessageId", "source_message_id", true), s("version", "version", true), { prop: "toolkits", json: "toolkits", from: (value) => objectList(value, ToolkitCapabilities.fromJson), default: () => [], always: true, to: (value) => value.map(maybeToJson) }] });
|
|
1068
|
+
export const ModelsRequest = makeMessageClass("ModelsRequest", { type: agentModelsRequestType });
|
|
1069
|
+
export const ModelsResponse = makeMessageClass("ModelsResponse", { type: agentModelsResponseType, fields: [s("sourceMessageId", "source_message_id", true), { prop: "providers", json: "providers", from: (value) => objectList(value, AgentProviderInfo.fromJson), default: () => [], always: true, to: (value) => value.map(maybeToJson) }] });
|
|
1070
|
+
export const ChangeModel = makeMessageClass("ChangeModel", { type: agentModelChangeType, base: "thread", fields: [s("backend"), s("provider"), s("model"), s("voice")] });
|
|
1071
|
+
export const AgentModelChanged = makeMessageClass("AgentModelChanged", { type: agentModelChangedType, base: "thread", fields: [s("sourceMessageId"), s("backend"), 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), { prop: "supportsAttachments", json: "supports_attachments", from: (value) => value === true, default: () => false }, sl("accepts", "accepts", [], true)] });
|
|
1072
|
+
export const ThreadCleared = makeMessageClass("ThreadCleared", { type: agentThreadClearedType, base: "thread", fields: [s("sourceMessageId", "source_message_id", true)] });
|
|
1073
|
+
export const TurnStartAccepted = makeMessageClass("TurnStartAccepted", { type: agentTurnStartAcceptedType, base: "thread", fields: [s("turnId"), s("sourceMessageId", "source_message_id", true), contentList("content")] });
|
|
1074
|
+
export const TurnStartRejected = makeMessageClass("TurnStartRejected", { type: agentTurnStartRejectedType, base: "thread", fields: [s("sourceMessageId", "source_message_id", true), obj("error", "error", AgentError.fromJson, true)] });
|
|
1075
|
+
export const TurnInterruptAccepted = makeMessageClass("TurnInterruptAccepted", { type: agentTurnInterruptAcceptedType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true)] });
|
|
1076
|
+
export const TurnInterrupted = makeMessageClass("TurnInterrupted", { type: agentTurnInterruptedType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true)] });
|
|
1077
|
+
export const TurnSteerAccepted = makeMessageClass("TurnSteerAccepted", { type: agentTurnSteerAcceptedType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true), contentList("content")] });
|
|
1078
|
+
export const TurnSteered = makeMessageClass("TurnSteered", { type: agentTurnSteeredType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true)] });
|
|
1079
|
+
export const TurnSteerRejected = makeMessageClass("TurnSteerRejected", { type: agentTurnSteerRejectedType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true), obj("error", "error", AgentError.fromJson, true)] });
|
|
1080
|
+
export const TurnStarted = makeMessageClass("TurnStarted", { type: agentTurnStartedType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true)] });
|
|
1081
|
+
export const TurnEnded = makeMessageClass("TurnEnded", { type: agentTurnEndedType, base: "thread", fields: [s("turnId", "turn_id", true), obj("error", "error", AgentError.fromJson)] });
|
|
1082
|
+
export const ThreadStarted = makeMessageClass("ThreadStarted", { type: agentThreadStartedType, fields: [s("sourceMessageId", "source_message_id", true), s("threadId", "thread_id", true), obj("realtimeConnection", "realtime_connection", AgentRealtimeConnectionInfo.fromJson)] });
|
|
1083
|
+
export const ThreadLoaded = makeMessageClass("ThreadLoaded", { type: agentThreadLoadedType, base: "thread", fields: [s("sourceMessageId"), s("sinceTurn")] });
|
|
1084
|
+
export const ThreadStartRejected = makeMessageClass("ThreadStartRejected", { type: agentThreadStartRejectedType, fields: [s("sourceMessageId", "source_message_id", true), obj("error", "error", AgentError.fromJson, true)] });
|
|
1085
|
+
export const AgentReasoningContentStarted = makeMessageClass("AgentReasoningContentStarted", { type: agentReasoningContentStartedType, base: "llm", fields: contentPart });
|
|
1086
|
+
export const AgentReasoningContentDelta = makeMessageClass("AgentReasoningContentDelta", { type: agentReasoningContentDeltaType, base: "llm", fields: [...contentPart, s("text", "text", true)] });
|
|
1087
|
+
export const AgentReasoningContentEnded = makeMessageClass("AgentReasoningContentEnded", { type: agentReasoningContentEndedType, base: "llm", fields: contentPart });
|
|
1088
|
+
export const AgentTextContentStarted = makeMessageClass("AgentTextContentStarted", { type: agentTextContentStartedType, base: "llm", fields: [...contentPart, s("phase")] });
|
|
1089
|
+
export const AgentTextContentDelta = makeMessageClass("AgentTextContentDelta", { type: agentTextContentDeltaType, base: "llm", fields: [...contentPart, s("phase"), s("text", "text", true)] });
|
|
1090
|
+
export const AgentTextContentEnded = makeMessageClass("AgentTextContentEnded", { type: agentTextContentEndedType, base: "llm", fields: [...contentPart, s("phase")] });
|
|
1091
|
+
export const AgentFileContentStarted = makeMessageClass("AgentFileContentStarted", { type: agentFileContentStartedType, base: "llm", fields: contentPart });
|
|
1092
|
+
export const AgentFileContentDelta = makeMessageClass("AgentFileContentDelta", { type: agentFileContentDeltaType, base: "llm", fields: [...contentPart, s("url", "url", true)] });
|
|
1093
|
+
export const AgentFileContentEnded = makeMessageClass("AgentFileContentEnded", { type: agentFileContentEndedType, base: "llm", fields: contentPart });
|
|
1094
|
+
export const AgentToolCallPending = makeMessageClass("AgentToolCallPending", { type: agentToolCallPendingType, base: "llm", fields: toolState });
|
|
1095
|
+
export const AgentToolCallInProgress = makeMessageClass("AgentToolCallInProgress", { type: agentToolCallInProgressType, base: "llm", fields: toolState });
|
|
1096
|
+
export const AgentToolCallStarted = makeMessageClass("AgentToolCallStarted", { type: agentToolCallStartedType, base: "llm", fields: toolState });
|
|
1097
|
+
export const AgentToolCallArgumentsDelta = makeMessageClass("AgentToolCallArgumentsDelta", { 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)] });
|
|
1098
|
+
export const AgentToolCallLogDelta = makeMessageClass("AgentToolCallLogDelta", { type: agentToolCallLogDeltaType, base: "llm", fields: [...contentPart, { prop: "namespace", json: "namespace", from: (value) => stringOrNull(value) ?? "meshagent", default: () => "meshagent", always: true }, s("callId"), { prop: "lines", json: "lines", from: (value) => objectList(value, AgentToolCallLogLine.fromJson), default: () => [], always: true, to: (value) => value.map(maybeToJson) }] });
|
|
1099
|
+
export const AgentToolCallEnded = makeMessageClass("AgentToolCallEnded", { 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)] });
|
|
1100
|
+
export const AgentToolCallApprovalRequested = makeMessageClass("AgentToolCallApprovalRequested", { type: agentToolCallApprovalRequestedType, base: "llm", fields: toolState.filter((field) => field.prop !== "argumentBytes") });
|
|
1101
|
+
export const AgentSecretRequested = makeMessageClass("AgentSecretRequested", { type: agentSecretRequestedType, base: "llm", fields: [s("turnId", "turn_id", true), s("requestId", "request_id", true), s("secretName", "secret_name", true), s("prompt"), m("oauth"), s("challenge")] });
|
|
1102
|
+
export const AgentClientToolCallRequested = makeMessageClass("AgentClientToolCallRequested", { type: agentClientToolCallRequestedType, base: "llm", fields: [s("turnId", "turn_id", true), s("requestId", "request_id", true), s("targetParticipantId"), s("toolkit", "toolkit", true), s("tool", "tool", true), { prop: "arguments", json: "arguments", from: (value) => dynamicMapOrNull(value) ?? {}, default: () => ({}), always: true }] });
|
|
1103
|
+
export const AgentClientToolCallCancelled = makeMessageClass("AgentClientToolCallCancelled", { type: agentClientToolCallCancelledType, base: "llm", fields: [s("turnId", "turn_id", true), s("requestId", "request_id", true), s("targetParticipantId"), s("toolkit", "toolkit", true), s("tool", "tool", true), s("reason")] });
|
|
1104
|
+
export const AgentThreadStatus = makeMessageClass("AgentThreadStatus", { type: agentThreadStatusType, base: "thread", fields: [s("status"), s("mode"), s("startedAt"), s("turnId"), s("pendingItemId"), i("totalBytes"), i("linesAdded"), i("linesRemoved")] });
|
|
1105
|
+
export const AgentConnectionStatus = makeMessageClass("AgentConnectionStatus", { type: agentConnectionStatusType, fields: [s("status", "status", true), s("message"), s("reason"), n("retryInSeconds"), s("participantId")] });
|
|
1106
|
+
export const AgentThreadEvent = makeMessageClass("AgentThreadEvent", { type: agentThreadEventType, base: "llm", fields: [m("event", "event", true)] });
|
|
1107
|
+
export const AgentImageGenerationStarted = makeMessageClass("AgentImageGenerationStarted", { type: agentImageGenerationStartedType, base: "llm", fields: imageGeneration });
|
|
1108
|
+
export const AgentImageGenerationPartial = makeMessageClass("AgentImageGenerationPartial", { type: agentImageGenerationPartialType, base: "llm", fields: [...imageGeneration, obj("image", "image", AgentGeneratedImage.fromJson), i("partialIndex")] });
|
|
1109
|
+
export const AgentImageGenerationCompleted = makeMessageClass("AgentImageGenerationCompleted", { type: agentImageGenerationCompletedType, base: "llm", fields: [...imageGeneration, objList("images", "images", AgentGeneratedImage.fromJson, true)] });
|
|
1110
|
+
export const AgentImageGenerationFailed = makeMessageClass("AgentImageGenerationFailed", { type: agentImageGenerationFailedType, base: "llm", fields: [...imageGeneration, obj("error", "error", AgentError.fromJson)] });
|
|
1111
|
+
export const AgentAudioGenerationStarted = makeMessageClass("AgentAudioGenerationStarted", { type: agentAudioGenerationStartedType, base: "llm", fields: responsePart });
|
|
1112
|
+
export const AgentAudioGenerationDelta = makeMessageClass("AgentAudioGenerationDelta", { type: agentAudioGenerationDeltaType, base: "llm", fields: [...responsePart, bytesField("data"), s("mimeType"), audioFormat("outputFormat")] });
|
|
1113
|
+
export const AgentAudioGenerationCompleted = makeMessageClass("AgentAudioGenerationCompleted", { type: agentAudioGenerationCompletedType, base: "llm", fields: [...responsePart, obj("audio", "audio", AgentGeneratedAudio.fromJson), audioFormat("outputFormat")] });
|
|
1114
|
+
export const AgentAudioGenerationFailed = makeMessageClass("AgentAudioGenerationFailed", { type: agentAudioGenerationFailedType, base: "llm", fields: [...responsePart, obj("error", "error", AgentError.fromJson)] });
|
|
1115
|
+
export const AgentAudioTranscriptionStarted = makeMessageClass("AgentAudioTranscriptionStarted", { type: agentAudioTranscriptionStartedType, base: "llm", fields: [...responsePart, s("role")] });
|
|
1116
|
+
export const AgentAudioTranscriptionDelta = makeMessageClass("AgentAudioTranscriptionDelta", { type: agentAudioTranscriptionDeltaType, base: "llm", fields: [...responsePart, s("role"), s("text", "text", true)] });
|
|
1117
|
+
export const AgentAudioTranscriptionCompleted = makeMessageClass("AgentAudioTranscriptionCompleted", { type: agentAudioTranscriptionCompletedType, base: "llm", fields: [...responsePart, s("role"), s("text")] });
|
|
1118
|
+
export const AgentAudioTranscriptionFailed = makeMessageClass("AgentAudioTranscriptionFailed", { type: agentAudioTranscriptionFailedType, base: "llm", fields: [...responsePart, s("role"), obj("error", "error", AgentError.fromJson)] });
|
|
1119
|
+
export const AgentAudioInputSpeechStarted = makeMessageClass("AgentAudioInputSpeechStarted", { type: agentAudioInputSpeechStartedType, base: "thread", fields: [s("turnId", "turn_id", true), s("itemId"), i("audioStartMs")] });
|
|
1120
|
+
export const AgentAudioInputSpeechEnded = makeMessageClass("AgentAudioInputSpeechEnded", { type: agentAudioInputSpeechEndedType, base: "thread", fields: [s("turnId", "turn_id", true), s("itemId"), i("audioEndMs")] });
|
|
1121
|
+
export const AgentContextCompacted = makeMessageClass("AgentContextCompacted", { 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 }] });
|
|
1122
|
+
export const AgentUsageUpdated = makeMessageClass("AgentUsageUpdated", { type: agentUsageUpdatedType, base: "thread", fields: [s("turnId"), { prop: "usage", json: "usage", from: doubleMap, default: () => ({}), always: true }, obj("contextWindow", "context_window", AgentContextWindowUsage.fromJson, true)] });
|
|
1123
|
+
export const ApproveAgentToolCall = makeMessageClass("ApproveAgentToolCall", { type: agentToolApproveType, base: "thread", fields: [s("turnId", "turn_id", true), s("itemId", "item_id", true)] });
|
|
1124
|
+
export const RejectAgentToolCall = makeMessageClass("RejectAgentToolCall", { type: agentToolRejectType, base: "thread", fields: [s("turnId", "turn_id", true), s("itemId", "item_id", true)] });
|
|
1125
|
+
export const AgentSecretResponse = makeMessageClass("AgentSecretResponse", { type: agentSecretResponseType, base: "thread", fields: [s("turnId", "turn_id", true), s("requestId", "request_id", true), s("value"), s("authorizationCode"), s("redirectUri"), s("error")] });
|
|
1126
|
+
export const AgentClientToolCallResponse = makeMessageClass("AgentClientToolCallResponse", { type: agentClientToolCallResponseType, base: "thread", fields: [s("turnId", "turn_id", true), s("requestId", "request_id", true), { prop: "response", json: "response", required: true, from: (value) => { const content = contentOrNull(value); if (content == null)
|
|
1127
|
+
throw new TypeError("missing content field 'response'"); return content; }, to: contentHeader }] });
|
|
1128
|
+
export function agentInputContent({ text, attachments, }) {
|
|
983
1129
|
const content = [];
|
|
984
1130
|
if (text.trim() !== "") {
|
|
985
1131
|
content.push({ type: "text", text });
|
|
986
1132
|
}
|
|
987
1133
|
for (const attachment of attachments) {
|
|
988
|
-
const
|
|
989
|
-
if (
|
|
990
|
-
|
|
1134
|
+
const url = attachment.url.trim();
|
|
1135
|
+
if (url === "") {
|
|
1136
|
+
continue;
|
|
991
1137
|
}
|
|
1138
|
+
const name = attachment.name?.trim();
|
|
1139
|
+
content.push(new AgentFileContent({
|
|
1140
|
+
url,
|
|
1141
|
+
name: name == null || name === "" ? undefined : name,
|
|
1142
|
+
}));
|
|
992
1143
|
}
|
|
993
1144
|
return content;
|
|
994
1145
|
}
|