@meshagent/meshagent 0.44.10 → 0.44.12

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.
Files changed (68) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/browser/agent-client.js +1 -1
  3. package/dist/browser/containers-client.js +1 -1
  4. package/dist/browser/datasets-client.d.ts +1 -1
  5. package/dist/browser/datasets-client.js +15 -15
  6. package/dist/browser/developer-client.js +1 -1
  7. package/dist/browser/entrypoint.js +5 -1
  8. package/dist/browser/memory-client.js +1 -1
  9. package/dist/browser/meshagent-client.d.ts +123 -7
  10. package/dist/browser/meshagent-client.js +357 -10
  11. package/dist/browser/messaging-client.js +1 -1
  12. package/dist/browser/queues-client.js +1 -1
  13. package/dist/browser/requirement.d.ts +21 -0
  14. package/dist/browser/requirement.js +87 -1
  15. package/dist/browser/room-client.d.ts +12 -1
  16. package/dist/browser/room-client.js +91 -31
  17. package/dist/browser/secrets-client.js +1 -1
  18. package/dist/browser/services-client.js +2 -2
  19. package/dist/browser/storage-client.d.ts +1 -1
  20. package/dist/browser/storage-client.js +1 -1
  21. package/dist/browser/stream-controller.d.ts +1 -0
  22. package/dist/browser/stream-controller.js +27 -7
  23. package/dist/browser/sync-client.js +1 -1
  24. package/dist/esm/agent-client.js +1 -1
  25. package/dist/esm/containers-client.js +1 -1
  26. package/dist/esm/datasets-client.d.ts +1 -1
  27. package/dist/esm/datasets-client.js +15 -15
  28. package/dist/esm/developer-client.js +1 -1
  29. package/dist/esm/entrypoint.js +6 -1
  30. package/dist/esm/memory-client.js +1 -1
  31. package/dist/esm/meshagent-client.d.ts +123 -7
  32. package/dist/esm/meshagent-client.js +353 -10
  33. package/dist/esm/messaging-client.js +1 -1
  34. package/dist/esm/queues-client.js +1 -1
  35. package/dist/esm/requirement.d.ts +21 -0
  36. package/dist/esm/requirement.js +84 -0
  37. package/dist/esm/room-client.d.ts +12 -1
  38. package/dist/esm/room-client.js +92 -32
  39. package/dist/esm/secrets-client.js +1 -1
  40. package/dist/esm/services-client.js +2 -2
  41. package/dist/esm/storage-client.d.ts +1 -1
  42. package/dist/esm/storage-client.js +1 -1
  43. package/dist/esm/stream-controller.d.ts +1 -0
  44. package/dist/esm/stream-controller.js +27 -7
  45. package/dist/esm/sync-client.js +1 -1
  46. package/dist/node/agent-client.js +1 -1
  47. package/dist/node/containers-client.js +1 -1
  48. package/dist/node/datasets-client.d.ts +1 -1
  49. package/dist/node/datasets-client.js +15 -15
  50. package/dist/node/developer-client.js +1 -1
  51. package/dist/node/entrypoint.js +6 -1
  52. package/dist/node/memory-client.js +1 -1
  53. package/dist/node/meshagent-client.d.ts +123 -7
  54. package/dist/node/meshagent-client.js +357 -10
  55. package/dist/node/messaging-client.js +1 -1
  56. package/dist/node/queues-client.js +1 -1
  57. package/dist/node/requirement.d.ts +21 -0
  58. package/dist/node/requirement.js +87 -1
  59. package/dist/node/room-client.d.ts +12 -1
  60. package/dist/node/room-client.js +91 -31
  61. package/dist/node/secrets-client.js +1 -1
  62. package/dist/node/services-client.js +2 -2
  63. package/dist/node/storage-client.d.ts +1 -1
  64. package/dist/node/storage-client.js +1 -1
  65. package/dist/node/stream-controller.d.ts +1 -0
  66. package/dist/node/stream-controller.js +27 -7
  67. package/dist/node/sync-client.js +1 -1
  68. package/package.json +1 -1
@@ -1,6 +1,10 @@
1
+ import { Schema } from "apache-arrow";
1
2
  export declare class RoomException extends Error {
2
3
  constructor(message: string);
3
4
  }
5
+ export declare class ForbiddenException extends RoomException {
6
+ constructor(message: string);
7
+ }
4
8
  export declare abstract class Requirement {
5
9
  readonly name: string;
6
10
  constructor({ name }: {
@@ -25,3 +29,20 @@ export declare class RequiredSchema extends Requirement {
25
29
  });
26
30
  toJson(): Record<string, any>;
27
31
  }
32
+ export declare class RequiredTable extends Requirement {
33
+ readonly schema: Schema;
34
+ readonly namespace?: string[];
35
+ readonly scalarIndexes?: string[];
36
+ readonly fullTextSearchIndexes?: string[];
37
+ readonly vectorIndexes?: string[];
38
+ constructor({ name, schema, namespace, scalarIndexes, fullTextSearchIndexes, vectorIndexes, }: {
39
+ name: string;
40
+ schema: Schema;
41
+ namespace?: string[];
42
+ scalarIndexes?: string[];
43
+ fullTextSearchIndexes?: string[];
44
+ vectorIndexes?: string[];
45
+ });
46
+ static fromJson(r: Record<string, any>): RequiredTable;
47
+ toJson(): Record<string, any>;
48
+ }
@@ -1,9 +1,54 @@
1
+ import { Table, tableFromIPC, tableToIPC } from "apache-arrow";
1
2
  export class RoomException extends Error {
2
3
  constructor(message) {
3
4
  super(message);
4
5
  this.name = "RoomException";
5
6
  }
6
7
  }
8
+ export class ForbiddenException extends RoomException {
9
+ constructor(message) {
10
+ super(message);
11
+ this.name = "ForbiddenException";
12
+ }
13
+ }
14
+ const globalScope = globalThis;
15
+ function bytesToBase64(bytes) {
16
+ if (globalScope.Buffer) {
17
+ return globalScope.Buffer.from(bytes).toString("base64");
18
+ }
19
+ if (!globalScope.btoa) {
20
+ throw new Error("base64 encoding is not available in this runtime");
21
+ }
22
+ let binary = "";
23
+ for (const byte of bytes) {
24
+ binary += String.fromCharCode(byte);
25
+ }
26
+ return globalScope.btoa(binary);
27
+ }
28
+ function base64ToBytes(base64) {
29
+ if (globalScope.Buffer) {
30
+ return Uint8Array.from(globalScope.Buffer.from(base64, "base64"));
31
+ }
32
+ if (!globalScope.atob) {
33
+ throw new Error("base64 decoding is not available in this runtime");
34
+ }
35
+ const binary = globalScope.atob(base64);
36
+ const bytes = new Uint8Array(binary.length);
37
+ for (let index = 0; index < binary.length; index += 1) {
38
+ bytes[index] = binary.charCodeAt(index);
39
+ }
40
+ return bytes;
41
+ }
42
+ function schemaToIPC(schema) {
43
+ return tableToIPC(new Table(schema, []), "stream");
44
+ }
45
+ function schemaFromIPCBytes(data) {
46
+ const table = tableFromIPC(data);
47
+ if (table instanceof Promise) {
48
+ throw new RoomException("unexpected async Arrow IPC result");
49
+ }
50
+ return table.schema;
51
+ }
7
52
  export class Requirement {
8
53
  constructor({ name }) {
9
54
  this.name = name;
@@ -16,6 +61,9 @@ export class Requirement {
16
61
  participantName: r["participant_name"],
17
62
  });
18
63
  }
64
+ if ("table" in r) {
65
+ return RequiredTable.fromJson(r);
66
+ }
19
67
  if ("schema" in r) {
20
68
  return new RequiredSchema({ name: r["schema"] });
21
69
  }
@@ -46,3 +94,39 @@ export class RequiredSchema extends Requirement {
46
94
  };
47
95
  }
48
96
  }
97
+ export class RequiredTable extends Requirement {
98
+ constructor({ name, schema, namespace, scalarIndexes, fullTextSearchIndexes, vectorIndexes, }) {
99
+ super({ name });
100
+ this.schema = schema;
101
+ this.namespace = namespace;
102
+ this.scalarIndexes = scalarIndexes;
103
+ this.fullTextSearchIndexes = fullTextSearchIndexes;
104
+ this.vectorIndexes = vectorIndexes;
105
+ }
106
+ static fromJson(r) {
107
+ if (typeof r["table"] !== "string") {
108
+ throw new RoomException("required table name must be a string");
109
+ }
110
+ if (typeof r["schema"] !== "string") {
111
+ throw new RoomException("required table schema must be a base64 Arrow IPC schema");
112
+ }
113
+ return new RequiredTable({
114
+ name: r["table"],
115
+ schema: schemaFromIPCBytes(base64ToBytes(r["schema"])),
116
+ namespace: Array.isArray(r["namespace"]) ? r["namespace"].map(String) : undefined,
117
+ scalarIndexes: Array.isArray(r["scalar_indexes"]) ? r["scalar_indexes"].map(String) : undefined,
118
+ fullTextSearchIndexes: Array.isArray(r["full_text_search_indexes"]) ? r["full_text_search_indexes"].map(String) : undefined,
119
+ vectorIndexes: Array.isArray(r["vector_indexes"]) ? r["vector_indexes"].map(String) : undefined,
120
+ });
121
+ }
122
+ toJson() {
123
+ return {
124
+ table: this.name,
125
+ schema: bytesToBase64(schemaToIPC(this.schema)),
126
+ namespace: this.namespace,
127
+ scalar_indexes: this.scalarIndexes,
128
+ full_text_search_indexes: this.fullTextSearchIndexes,
129
+ vector_indexes: this.vectorIndexes,
130
+ };
131
+ }
132
+ }
@@ -18,6 +18,7 @@ import { ContainersClient } from "./containers-client.js";
18
18
  interface RequestHeader {
19
19
  [key: string]: unknown;
20
20
  }
21
+ export type InvokeInput = Record<string, unknown> | Content;
21
22
  export declare class RoomProtocolProxy {
22
23
  private readonly _room;
23
24
  private readonly _handlers;
@@ -67,6 +68,7 @@ export declare class RoomClient {
67
68
  private readonly _eventEmitter;
68
69
  private readonly _pendingRequests;
69
70
  private readonly _toolCallStreams;
71
+ private readonly _toolCallPreOpenErrors;
70
72
  private readonly _ignoredResponseLabels;
71
73
  private readonly _ready;
72
74
  private readonly _roomClosed;
@@ -202,11 +204,20 @@ export declare class RoomClient {
202
204
  participantName?: string;
203
205
  timeout?: number;
204
206
  }): Promise<ToolkitDescription[]>;
207
+ private _normalizeInvokeInput;
205
208
  invoke(params: {
206
209
  toolkit: string;
207
210
  tool: string;
208
211
  arguments?: Record<string, unknown>;
209
- input?: Record<string, unknown> | Content;
212
+ input?: InvokeInput;
213
+ participantId?: string;
214
+ onBehalfOfId?: string;
215
+ }): AsyncIterable<Content>;
216
+ invokeContent(params: {
217
+ toolkit: string;
218
+ tool: string;
219
+ arguments?: Record<string, unknown>;
220
+ input?: InvokeInput;
210
221
  participantId?: string;
211
222
  onBehalfOfId?: string;
212
223
  }): Promise<Content>;
@@ -7,7 +7,7 @@ import { MemoryClient } from "./memory-client.js";
7
7
  import { LocalParticipant } from "./participant.js";
8
8
  import { ProtocolCloseException, ProtocolCloseKind, ProtocolHandshakeException, ProtocolReconnectUnsupportedException, WebSocketClientProtocol, } from "./protocol.js";
9
9
  import { QueuesClient } from "./queues-client.js";
10
- import { BinaryContent, ControlContent, EmptyContent, ErrorContent, FileContent, JsonContent, LinkContent, TextContent, unpackContent } from "./response.js";
10
+ import { BinaryContent, ControlCloseStatus, ControlContent, EmptyContent, ErrorContent, FileContent, JsonContent, LinkContent, TextContent, unpackContent } from "./response.js";
11
11
  import { RoomStatusEvent } from "./room-event.js";
12
12
  import { RoomServerException } from "./room-server-client.js";
13
13
  import { SecretsClient } from "./secrets-client.js";
@@ -212,6 +212,7 @@ export class RoomClient {
212
212
  this._eventEmitter = new EventEmitter();
213
213
  this._pendingRequests = new Map();
214
214
  this._toolCallStreams = new Map();
215
+ this._toolCallPreOpenErrors = new Map();
215
216
  this._ignoredResponseLabels = new Map();
216
217
  this._ready = new Completer();
217
218
  this._roomClosed = new Completer();
@@ -1195,13 +1196,10 @@ export class RoomClient {
1195
1196
  }
1196
1197
  return toolkits;
1197
1198
  }
1198
- async invoke(params) {
1199
- const input = params.input ?? params.arguments ?? new EmptyContent();
1200
- const request = {
1201
- toolkit: params.toolkit,
1202
- tool: params.tool,
1203
- };
1204
- let requestData;
1199
+ _normalizeInvokeInput(input) {
1200
+ if (input === undefined) {
1201
+ return new EmptyContent();
1202
+ }
1205
1203
  if (input instanceof BinaryContent ||
1206
1204
  input instanceof EmptyContent ||
1207
1205
  input instanceof ErrorContent ||
@@ -1209,35 +1207,53 @@ export class RoomClient {
1209
1207
  input instanceof JsonContent ||
1210
1208
  input instanceof LinkContent ||
1211
1209
  input instanceof TextContent) {
1212
- const packed = input.pack();
1213
- request["arguments"] = JSON.parse(splitMessageHeader(packed));
1214
- const payload = splitMessagePayload(packed);
1215
- if (payload.length > 0) {
1216
- requestData = payload;
1217
- }
1210
+ return input;
1218
1211
  }
1219
- else if (typeof input === "object" && input !== null && !Array.isArray(input)) {
1220
- request["arguments"] = {
1221
- type: "json",
1222
- json: input,
1223
- };
1212
+ if (typeof input === "object" && input !== null && !Array.isArray(input)) {
1213
+ return new JsonContent({ json: input });
1224
1214
  }
1225
- else {
1226
- throw new RoomServerException("invoke input must be a content value or JSON object");
1227
- }
1228
- if (params.participantId != null) {
1229
- request["participant_id"] = params.participantId;
1230
- }
1231
- if (params.onBehalfOfId != null) {
1232
- request["on_behalf_of_id"] = params.onBehalfOfId;
1215
+ throw new RoomServerException("invoke input must be a content value or JSON object");
1216
+ }
1217
+ invoke(params) {
1218
+ const outputPromise = this.invokeToolCall({
1219
+ toolkit: params.toolkit,
1220
+ tool: params.tool,
1221
+ input: this._normalizeInvokeInput(params.input ?? params.arguments),
1222
+ participantId: params.participantId,
1223
+ onBehalfOfId: params.onBehalfOfId,
1224
+ });
1225
+ void outputPromise.catch(() => undefined);
1226
+ return {
1227
+ async *[Symbol.asyncIterator]() {
1228
+ const output = await outputPromise;
1229
+ if (output.kind === "stream") {
1230
+ yield* output.stream;
1231
+ return;
1232
+ }
1233
+ yield output.content;
1234
+ },
1235
+ };
1236
+ }
1237
+ async invokeContent(params) {
1238
+ const output = await this.invokeToolCall({
1239
+ toolkit: params.toolkit,
1240
+ tool: params.tool,
1241
+ input: this._normalizeInvokeInput(params.input ?? params.arguments),
1242
+ participantId: params.participantId,
1243
+ onBehalfOfId: params.onBehalfOfId,
1244
+ });
1245
+ if (output.kind !== "content") {
1246
+ throw new RoomServerException("unexpected streamed output from " + params.toolkit + "." + params.tool);
1233
1247
  }
1234
- return await this.sendRequest("room.invoke_tool", request, requestData);
1248
+ return output.content;
1235
1249
  }
1236
1250
  async invokeToolCall(params) {
1237
1251
  const toolCallId = `${Date.now()}-${Math.random().toString(16).slice(2)}`;
1238
1252
  const controller = new StreamController();
1239
1253
  const responseIterator = controller.stream[Symbol.asyncIterator]();
1254
+ const preOpenError = new Completer();
1240
1255
  this._toolCallStreams.set(toolCallId, controller);
1256
+ this._toolCallPreOpenErrors.set(toolCallId, preOpenError);
1241
1257
  const request = {
1242
1258
  toolkit: params.toolkit,
1243
1259
  tool: params.tool,
@@ -1265,7 +1281,11 @@ export class RoomClient {
1265
1281
  request["on_behalf_of_id"] = params.onBehalfOfId;
1266
1282
  }
1267
1283
  try {
1268
- const response = await this.sendRequest("room.invoke_tool", request, requestData);
1284
+ const response = await Promise.race([
1285
+ this.sendRequest("room.invoke_tool", request, requestData),
1286
+ preOpenError.fut,
1287
+ ]);
1288
+ this._toolCallPreOpenErrors.delete(toolCallId);
1269
1289
  if (response instanceof ControlContent && response.method === "open") {
1270
1290
  if (requestTask != null) {
1271
1291
  void requestTask.catch((error) => {
@@ -1273,7 +1293,7 @@ export class RoomClient {
1273
1293
  if (stream == null) {
1274
1294
  return;
1275
1295
  }
1276
- stream.add(new ErrorContent({ text: `request stream failed: ${String(error)}` }));
1296
+ stream.addError(error);
1277
1297
  stream.close();
1278
1298
  this._toolCallStreams.delete(toolCallId);
1279
1299
  });
@@ -1297,6 +1317,7 @@ export class RoomClient {
1297
1317
  }
1298
1318
  catch (error) {
1299
1319
  await Promise.resolve(requestTask).catch(() => undefined);
1320
+ this._toolCallPreOpenErrors.delete(toolCallId);
1300
1321
  this._toolCallStreams.delete(toolCallId);
1301
1322
  controller.close();
1302
1323
  throw error;
@@ -1334,7 +1355,9 @@ export class RoomClient {
1334
1355
  const toolCallId = `${Date.now()}-${Math.random().toString(16).slice(2)}`;
1335
1356
  const controller = new StreamController();
1336
1357
  const responseIterator = controller.stream[Symbol.asyncIterator]();
1358
+ const preOpenError = new Completer();
1337
1359
  this._toolCallStreams.set(toolCallId, controller);
1360
+ this._toolCallPreOpenErrors.set(toolCallId, preOpenError);
1338
1361
  const request = {
1339
1362
  toolkit: params.toolkit,
1340
1363
  tool: params.tool,
@@ -1353,11 +1376,24 @@ export class RoomClient {
1353
1376
  if (stream == null) {
1354
1377
  return;
1355
1378
  }
1356
- stream.add(new ErrorContent({ text: `request stream failed: ${String(error)}` }));
1379
+ stream.addError(error);
1357
1380
  stream.close();
1358
1381
  this._toolCallStreams.delete(toolCallId);
1359
1382
  });
1360
- const response = await this.sendRequest("room.invoke_tool", request);
1383
+ let response;
1384
+ try {
1385
+ response = await Promise.race([
1386
+ this.sendRequest("room.invoke_tool", request),
1387
+ preOpenError.fut,
1388
+ ]);
1389
+ }
1390
+ catch (error) {
1391
+ this._toolCallPreOpenErrors.delete(toolCallId);
1392
+ this._toolCallStreams.delete(toolCallId);
1393
+ controller.close();
1394
+ throw error;
1395
+ }
1396
+ this._toolCallPreOpenErrors.delete(toolCallId);
1361
1397
  if (!(response instanceof ControlContent) || response.method !== "open") {
1362
1398
  this._toolCallStreams.delete(toolCallId);
1363
1399
  controller.close();
@@ -1414,10 +1450,34 @@ export class RoomClient {
1414
1450
  return;
1415
1451
  }
1416
1452
  const content = this._decodeToolCallContent({ header, payload });
1453
+ const preOpenError = this._toolCallPreOpenErrors.get(toolCallId);
1454
+ if (preOpenError != null && content instanceof ErrorContent) {
1455
+ const error = new RoomServerException(content.text, content.code);
1456
+ if (!preOpenError.completed) {
1457
+ preOpenError.completeError(error);
1458
+ }
1459
+ stream.addError(error);
1460
+ stream.close();
1461
+ this._toolCallStreams.delete(toolCallId);
1462
+ this._toolCallPreOpenErrors.delete(toolCallId);
1463
+ return;
1464
+ }
1465
+ if (content instanceof ControlContent &&
1466
+ content.method === "close" &&
1467
+ content.statusCode !== undefined &&
1468
+ content.statusCode !== ControlCloseStatus.NORMAL) {
1469
+ const error = new RoomServerException(content.message ?? `tool call stream closed with status ${content.statusCode}`, undefined, { statusCode: content.statusCode });
1470
+ stream.addError(error);
1471
+ stream.close();
1472
+ this._toolCallStreams.delete(toolCallId);
1473
+ this._toolCallPreOpenErrors.delete(toolCallId);
1474
+ return;
1475
+ }
1417
1476
  stream.add(content);
1418
1477
  if (content instanceof ControlContent && content.method === "close") {
1419
1478
  stream.close();
1420
1479
  this._toolCallStreams.delete(toolCallId);
1480
+ this._toolCallPreOpenErrors.delete(toolCallId);
1421
1481
  }
1422
1482
  }
1423
1483
  async _handleResponse(protocol, messageId, _type, data) {
@@ -18,7 +18,7 @@ export class SecretsClient {
18
18
  return new RoomServerException(`unexpected return type from secrets.${operation}`);
19
19
  }
20
20
  async invoke(operation, input) {
21
- return await this.client.invoke({
21
+ return await this.client.invokeContent({
22
22
  toolkit: "secrets",
23
23
  tool: operation,
24
24
  input,
@@ -50,7 +50,7 @@ export class ServicesClient {
50
50
  return (await this.listWithState()).services;
51
51
  }
52
52
  async listWithState() {
53
- const response = await this.room.invoke({
53
+ const response = await this.room.invokeContent({
54
54
  toolkit: "services",
55
55
  tool: "list",
56
56
  input: {},
@@ -74,7 +74,7 @@ export class ServicesClient {
74
74
  };
75
75
  }
76
76
  async restart(params) {
77
- const response = await this.room.invoke({
77
+ const response = await this.room.invokeContent({
78
78
  toolkit: "services",
79
79
  tool: "restart",
80
80
  input: {
@@ -3,7 +3,7 @@ import { Protocol } from "./protocol.js";
3
3
  import { RoomEvent } from "./room-event.js";
4
4
  import { BinaryContent, FileContent } from "./response.js";
5
5
  import { EventEmitter } from "./event-emitter.js";
6
- type StorageClientRoom = Pick<RoomClient, "invoke" | "invokeStream" | "emit"> & {
6
+ type StorageClientRoom = Pick<RoomClient, "invokeContent" | "invokeStream" | "emit"> & {
7
7
  isActiveProtocol(protocol: Protocol): boolean;
8
8
  protocol: Pick<Protocol, "addHandler">;
9
9
  };
@@ -132,7 +132,7 @@ export class StorageClient extends EventEmitter {
132
132
  });
133
133
  }
134
134
  async _invoke(operation, input) {
135
- return await this.client.invoke({
135
+ return await this.client.invokeContent({
136
136
  toolkit: "storage",
137
137
  tool: operation,
138
138
  input,
@@ -3,5 +3,6 @@ export declare class StreamController<T> {
3
3
  private subs;
4
4
  get stream(): AsyncIterable<T>;
5
5
  add(value: T): void;
6
+ addError(error: unknown): void;
6
7
  close(): void;
7
8
  }
@@ -16,21 +16,26 @@ export class StreamController {
16
16
  if (sub.waiter) {
17
17
  const w = sub.waiter;
18
18
  sub.waiter = null;
19
- w({ done: true, value: undefined });
19
+ w.resolve({ done: true, value: undefined });
20
20
  }
21
21
  self.subs.delete(sub);
22
22
  };
23
23
  return {
24
24
  async next() {
25
25
  if (sub.queue.length > 0) {
26
- return { done: false, value: sub.queue.shift() };
26
+ const item = sub.queue.shift();
27
+ if (item.kind === "error") {
28
+ cleanup();
29
+ return Promise.reject(item.error);
30
+ }
31
+ return { done: false, value: item.value };
27
32
  }
28
33
  if (self.closed) {
29
34
  cleanup();
30
35
  return { done: true, value: undefined };
31
36
  }
32
- return new Promise(resolve => {
33
- sub.waiter = resolve;
37
+ return new Promise((resolve, reject) => {
38
+ sub.waiter = { resolve, reject };
34
39
  });
35
40
  },
36
41
  async return() {
@@ -52,10 +57,25 @@ export class StreamController {
52
57
  if (sub.waiter) {
53
58
  const w = sub.waiter;
54
59
  sub.waiter = null;
55
- w({ done: false, value });
60
+ w.resolve({ done: false, value });
56
61
  }
57
62
  else {
58
- sub.queue.push(value);
63
+ sub.queue.push({ kind: "value", value });
64
+ }
65
+ }
66
+ }
67
+ addError(error) {
68
+ if (this.closed)
69
+ return;
70
+ for (const sub of [...this.subs]) {
71
+ if (sub.waiter) {
72
+ const w = sub.waiter;
73
+ sub.waiter = null;
74
+ w.reject(error);
75
+ this.subs.delete(sub);
76
+ }
77
+ else {
78
+ sub.queue.push({ kind: "error", error });
59
79
  }
60
80
  }
61
81
  }
@@ -67,7 +87,7 @@ export class StreamController {
67
87
  if (sub.waiter) {
68
88
  const w = sub.waiter;
69
89
  sub.waiter = null;
70
- w({ done: true, value: undefined });
90
+ w.resolve({ done: true, value: undefined });
71
91
  }
72
92
  }
73
93
  }
@@ -161,7 +161,7 @@ export class SyncClient extends EventEmitter {
161
161
  return new RoomServerException(`unexpected return type from sync.${operation}`);
162
162
  }
163
163
  async _invoke(operation, input) {
164
- return await this.room.invoke({
164
+ return await this.room.invokeContent({
165
165
  toolkit: "sync",
166
166
  tool: operation,
167
167
  input,
@@ -141,7 +141,7 @@ class AgentsClient {
141
141
  }
142
142
  async invokeTool(params) {
143
143
  if (params.input === undefined) {
144
- return await this.client.invoke({
144
+ return await this.client.invokeContent({
145
145
  toolkit: params.toolkit,
146
146
  tool: params.tool,
147
147
  arguments: params.arguments ?? {},
@@ -403,7 +403,7 @@ class ContainersClient {
403
403
  return new room_server_client_js_1.RoomServerException(`unexpected return type from containers.${operation}`);
404
404
  }
405
405
  async invoke(operation, input) {
406
- return await this.room.invoke({
406
+ return await this.room.invokeContent({
407
407
  toolkit: "containers",
408
408
  tool: operation,
409
409
  input,
@@ -173,7 +173,7 @@ export type DatasetRecord = Record<string, DatasetValue>;
173
173
  export type DatasetRows = DatasetRecord[];
174
174
  export type DatasetRowChunks = AsyncIterable<DatasetRows> | Iterable<DatasetRows>;
175
175
  export type DatasetWhere = string | Record<string, DatasetValue>;
176
- type DatasetRoomInvoker = Pick<RoomClient, "invoke" | "invokeStream">;
176
+ type DatasetRoomInvoker = Pick<RoomClient, "invokeContent" | "invokeStream">;
177
177
  export declare class DatasetUuid {
178
178
  readonly value: string;
179
179
  constructor(value: string);