@meshagent/meshagent-ts-auth 0.44.11 → 0.44.13

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 CHANGED
@@ -1,3 +1,12 @@
1
+ ## [0.44.13]
2
+ - Stability
3
+
4
+ ## [0.44.12]
5
+ - Added generated project support flows across the SDK CLI, including visible-room selection, deploy-room updates, and expanded template creation coverage.
6
+ - Added `predev` dependency bootstrapping to generated JavaScript, TypeScript, and React templates, and restored room-workspace install/dev scripts.
7
+ - Expanded chat and voice UI support with realtime audio output, responsive meeting updates, and fixes for room-client invocation and voice-agent handoff behavior.
8
+ - Updated third-party packages: `ws` to `^8.21.0` and added `react-virtuoso` `^4.18.7`.
9
+
1
10
  ## [0.44.11]
2
11
  - Stability
3
12
 
@@ -11,11 +11,20 @@ meshagent.auth = (() => {
11
11
  throw TypeError(msg);
12
12
  };
13
13
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14
- var __esm = (fn, res) => function __init() {
15
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
14
+ var __esm = (fn, res, err) => function __init() {
15
+ if (err) throw err[0];
16
+ try {
17
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
18
+ } catch (e) {
19
+ throw err = [e], e;
20
+ }
16
21
  };
17
22
  var __commonJS = (cb, mod) => function __require() {
18
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
23
+ try {
24
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
25
+ } catch (e) {
26
+ throw mod = 0, e;
27
+ }
19
28
  };
20
29
  var __export = (target, all) => {
21
30
  for (var name in all)
@@ -4250,7 +4259,11 @@ meshagent.auth = (() => {
4250
4259
  var __getProtoOf2 = Object.getPrototypeOf;
4251
4260
  var __hasOwnProp2 = Object.prototype.hasOwnProperty;
4252
4261
  var __commonJS2 = (cb, mod) => function __require() {
4253
- return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4262
+ try {
4263
+ return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4264
+ } catch (e) {
4265
+ throw mod = 0, e;
4266
+ }
4254
4267
  };
4255
4268
  var __export2 = (target, all2) => {
4256
4269
  for (var name in all2)
@@ -14074,21 +14087,26 @@ ${err.toString()}`);
14074
14087
  if (sub.waiter) {
14075
14088
  const w = sub.waiter;
14076
14089
  sub.waiter = null;
14077
- w({ done: true, value: void 0 });
14090
+ w.resolve({ done: true, value: void 0 });
14078
14091
  }
14079
14092
  self2.subs.delete(sub);
14080
14093
  };
14081
14094
  return {
14082
14095
  async next() {
14083
14096
  if (sub.queue.length > 0) {
14084
- return { done: false, value: sub.queue.shift() };
14097
+ const item = sub.queue.shift();
14098
+ if (item.kind === "error") {
14099
+ cleanup();
14100
+ return Promise.reject(item.error);
14101
+ }
14102
+ return { done: false, value: item.value };
14085
14103
  }
14086
14104
  if (self2.closed) {
14087
14105
  cleanup();
14088
14106
  return { done: true, value: void 0 };
14089
14107
  }
14090
- return new Promise((resolve) => {
14091
- sub.waiter = resolve;
14108
+ return new Promise((resolve, reject) => {
14109
+ sub.waiter = { resolve, reject };
14092
14110
  });
14093
14111
  },
14094
14112
  async return() {
@@ -14110,9 +14128,23 @@ ${err.toString()}`);
14110
14128
  if (sub.waiter) {
14111
14129
  const w = sub.waiter;
14112
14130
  sub.waiter = null;
14113
- w({ done: false, value });
14131
+ w.resolve({ done: false, value });
14114
14132
  } else {
14115
- sub.queue.push(value);
14133
+ sub.queue.push({ kind: "value", value });
14134
+ }
14135
+ }
14136
+ }
14137
+ addError(error) {
14138
+ if (this.closed)
14139
+ return;
14140
+ for (const sub of [...this.subs]) {
14141
+ if (sub.waiter) {
14142
+ const w = sub.waiter;
14143
+ sub.waiter = null;
14144
+ w.reject(error);
14145
+ this.subs.delete(sub);
14146
+ } else {
14147
+ sub.queue.push({ kind: "error", error });
14116
14148
  }
14117
14149
  }
14118
14150
  }
@@ -14124,7 +14156,7 @@ ${err.toString()}`);
14124
14156
  if (sub.waiter) {
14125
14157
  const w = sub.waiter;
14126
14158
  sub.waiter = null;
14127
- w({ done: true, value: void 0 });
14159
+ w.resolve({ done: true, value: void 0 });
14128
14160
  }
14129
14161
  }
14130
14162
  }
@@ -14982,7 +15014,7 @@ ${err.toString()}`);
14982
15014
  }
14983
15015
  async invokeTool(params) {
14984
15016
  if (params.input === void 0) {
14985
- return await this.client.invoke({
15017
+ return await this.client.invokeContent({
14986
15018
  toolkit: params.toolkit,
14987
15019
  tool: params.tool,
14988
15020
  arguments: params.arguments ?? {},
@@ -15861,7 +15893,7 @@ ${err.toString()}`);
15861
15893
  return new room_server_client_js_1.RoomServerException(`unexpected return type from containers.${operation}`);
15862
15894
  }
15863
15895
  async invoke(operation, input) {
15864
- return await this.room.invoke({
15896
+ return await this.room.invokeContent({
15865
15897
  toolkit: "containers",
15866
15898
  tool: operation,
15867
15899
  input
@@ -33803,7 +33835,7 @@ return true;`);
33803
33835
  return new room_server_client_js_1.RoomServerException(`unexpected return type from datasets.${operation}`);
33804
33836
  }
33805
33837
  async invoke(operation, input) {
33806
- const response = await this.room.invoke({ toolkit: "dataset", tool: operation, input });
33838
+ const response = await this.room.invokeContent({ toolkit: "dataset", tool: operation, input });
33807
33839
  if (response instanceof response_js_1.JsonContent) {
33808
33840
  return response;
33809
33841
  }
@@ -33813,7 +33845,7 @@ return true;`);
33813
33845
  return null;
33814
33846
  }
33815
33847
  async invokeContent(operation, input) {
33816
- return await this.room.invoke({ toolkit: "dataset", tool: operation, input });
33848
+ return await this.room.invokeContent({ toolkit: "dataset", tool: operation, input });
33817
33849
  }
33818
33850
  async invokeStream(operation, input) {
33819
33851
  return await this.room.invokeStream({ toolkit: "dataset", tool: operation, input });
@@ -33986,7 +34018,7 @@ return true;`);
33986
34018
  await this.drainWriteStream("create_table", input);
33987
34019
  }
33988
34020
  async dropTable({ name, ignoreMissing = false, namespace, branch }) {
33989
- await this.room.invoke({
34021
+ await this.room.invokeContent({
33990
34022
  toolkit: "dataset",
33991
34023
  tool: "drop_table",
33992
34024
  input: {
@@ -34041,7 +34073,7 @@ return true;`);
34041
34073
  });
34042
34074
  }
34043
34075
  async dropIndex({ table, name, namespace, branch }) {
34044
- await this.room.invoke({
34076
+ await this.room.invokeContent({
34045
34077
  toolkit: "dataset",
34046
34078
  tool: "drop_index",
34047
34079
  input: { table, name, namespace: namespace ?? null, branch: branch ?? null }
@@ -34060,7 +34092,7 @@ return true;`);
34060
34092
  }));
34061
34093
  return;
34062
34094
  }
34063
- await this.room.invoke({
34095
+ await this.room.invokeContent({
34064
34096
  toolkit: "dataset",
34065
34097
  tool: "add_columns",
34066
34098
  input: {
@@ -34072,7 +34104,7 @@ return true;`);
34072
34104
  });
34073
34105
  }
34074
34106
  async dropColumns({ table, columns, namespace, branch }) {
34075
- await this.room.invoke({
34107
+ await this.room.invokeContent({
34076
34108
  toolkit: "dataset",
34077
34109
  tool: "drop_columns",
34078
34110
  input: { table, columns, namespace: namespace ?? null, branch: branch ?? null }
@@ -34094,7 +34126,7 @@ return true;`);
34094
34126
  await this.drainWriteStream("insert", input);
34095
34127
  }
34096
34128
  async update({ table, where, values, namespace, branch }) {
34097
- await this.room.invoke({
34129
+ await this.room.invokeContent({
34098
34130
  toolkit: "dataset",
34099
34131
  tool: "update",
34100
34132
  input: {
@@ -34107,7 +34139,7 @@ return true;`);
34107
34139
  });
34108
34140
  }
34109
34141
  async delete({ table, where, namespace, branch }) {
34110
- await this.room.invoke({
34142
+ await this.room.invokeContent({
34111
34143
  toolkit: "dataset",
34112
34144
  tool: "delete",
34113
34145
  input: { table, where, namespace: namespace ?? null, branch: branch ?? null }
@@ -34216,13 +34248,13 @@ return true;`);
34216
34248
  });
34217
34249
  }
34218
34250
  async closeSqlQuery({ queryId }) {
34219
- const response = await this.room.invoke({ toolkit: "dataset", tool: "close_sql_query", input: { query_id: queryId } });
34251
+ const response = await this.room.invokeContent({ toolkit: "dataset", tool: "close_sql_query", input: { query_id: queryId } });
34220
34252
  if (!(response instanceof response_js_1.EmptyContent)) {
34221
34253
  throw this._unexpectedResponseError("close_sql_query");
34222
34254
  }
34223
34255
  }
34224
34256
  async cancelSqlQuery({ queryId }) {
34225
- const response = await this.room.invoke({ toolkit: "dataset", tool: "cancel_sql_query", input: { query_id: queryId } });
34257
+ const response = await this.room.invokeContent({ toolkit: "dataset", tool: "cancel_sql_query", input: { query_id: queryId } });
34226
34258
  if (!(response instanceof response_js_1.JsonContent) || !["cancelled", "cancelling", "not_cancellable"].includes(response.json.status)) {
34227
34259
  throw this._unexpectedResponseError("cancel_sql_query");
34228
34260
  }
@@ -34372,7 +34404,7 @@ return true;`);
34372
34404
  return response.json.count;
34373
34405
  }
34374
34406
  async inspect({ table, namespace, branch, version: version2 }) {
34375
- const response = await this.room.invoke({
34407
+ const response = await this.room.invokeContent({
34376
34408
  toolkit: "dataset",
34377
34409
  tool: "inspect",
34378
34410
  input: {
@@ -34417,7 +34449,7 @@ return true;`);
34417
34449
  return tableStatsFromJson(response.json);
34418
34450
  }
34419
34451
  async restore({ table, version: version2, namespace, branch }) {
34420
- await this.room.invoke({
34452
+ await this.room.invokeContent({
34421
34453
  toolkit: "dataset",
34422
34454
  tool: "restore",
34423
34455
  input: { table, version: version2, namespace: namespace ?? null, branch: branch ?? null }
@@ -34435,7 +34467,7 @@ return true;`);
34435
34467
  return response.json.versions.map((version2) => tableVersionFromJson(version2));
34436
34468
  }
34437
34469
  async createIndex({ table, config, namespace, branch }) {
34438
- await this.room.invoke({
34470
+ await this.room.invokeContent({
34439
34471
  toolkit: "dataset",
34440
34472
  tool: "create_index",
34441
34473
  input: { table, config, namespace: namespace ?? null, branch: branch ?? null }
@@ -34463,7 +34495,7 @@ return true;`);
34463
34495
  return response.json.branches.map((branch) => tableBranchFromJson(branch));
34464
34496
  }
34465
34497
  async createBranch({ branch, fromBranch, namespace }) {
34466
- await this.room.invoke({
34498
+ await this.room.invokeContent({
34467
34499
  toolkit: "dataset",
34468
34500
  tool: "create_branch",
34469
34501
  input: {
@@ -34474,7 +34506,7 @@ return true;`);
34474
34506
  });
34475
34507
  }
34476
34508
  async deleteBranch({ branch, namespace }) {
34477
- await this.room.invoke({
34509
+ await this.room.invokeContent({
34478
34510
  toolkit: "dataset",
34479
34511
  tool: "delete_branch",
34480
34512
  input: { branch, namespace: namespace ?? null }
@@ -34514,7 +34546,7 @@ return true;`);
34514
34546
  this._emitDeveloperLog(rawJson["type"], rawJson["data"]);
34515
34547
  }
34516
34548
  async log(type, data) {
34517
- await this.client.invoke({
34549
+ await this.client.invokeContent({
34518
34550
  toolkit: "developer",
34519
34551
  tool: "log",
34520
34552
  input: { type, data }
@@ -41383,7 +41415,8 @@ ${newlined}
41383
41415
  "../meshagent-ts/dist/browser/requirement.js"(exports) {
41384
41416
  "use strict";
41385
41417
  Object.defineProperty(exports, "__esModule", { value: true });
41386
- exports.RequiredSchema = exports.RequiredToolkit = exports.Requirement = exports.RoomException = void 0;
41418
+ exports.RequiredTable = exports.RequiredSchema = exports.RequiredToolkit = exports.Requirement = exports.ForbiddenException = exports.RoomException = void 0;
41419
+ var apache_arrow_1 = require_Arrow_dom();
41387
41420
  var RoomException = class extends Error {
41388
41421
  constructor(message2) {
41389
41422
  super(message2);
@@ -41391,6 +41424,51 @@ ${newlined}
41391
41424
  }
41392
41425
  };
41393
41426
  exports.RoomException = RoomException;
41427
+ var ForbiddenException = class extends RoomException {
41428
+ constructor(message2) {
41429
+ super(message2);
41430
+ this.name = "ForbiddenException";
41431
+ }
41432
+ };
41433
+ exports.ForbiddenException = ForbiddenException;
41434
+ var globalScope = globalThis;
41435
+ function bytesToBase64(bytes) {
41436
+ if (globalScope.Buffer) {
41437
+ return globalScope.Buffer.from(bytes).toString("base64");
41438
+ }
41439
+ if (!globalScope.btoa) {
41440
+ throw new Error("base64 encoding is not available in this runtime");
41441
+ }
41442
+ let binary = "";
41443
+ for (const byte of bytes) {
41444
+ binary += String.fromCharCode(byte);
41445
+ }
41446
+ return globalScope.btoa(binary);
41447
+ }
41448
+ function base64ToBytes(base64) {
41449
+ if (globalScope.Buffer) {
41450
+ return Uint8Array.from(globalScope.Buffer.from(base64, "base64"));
41451
+ }
41452
+ if (!globalScope.atob) {
41453
+ throw new Error("base64 decoding is not available in this runtime");
41454
+ }
41455
+ const binary = globalScope.atob(base64);
41456
+ const bytes = new Uint8Array(binary.length);
41457
+ for (let index = 0; index < binary.length; index += 1) {
41458
+ bytes[index] = binary.charCodeAt(index);
41459
+ }
41460
+ return bytes;
41461
+ }
41462
+ function schemaToIPC(schema) {
41463
+ return (0, apache_arrow_1.tableToIPC)(new apache_arrow_1.Table(schema, []), "stream");
41464
+ }
41465
+ function schemaFromIPCBytes(data) {
41466
+ const table = (0, apache_arrow_1.tableFromIPC)(data);
41467
+ if (table instanceof Promise) {
41468
+ throw new RoomException("unexpected async Arrow IPC result");
41469
+ }
41470
+ return table.schema;
41471
+ }
41394
41472
  var Requirement = class {
41395
41473
  constructor({ name }) {
41396
41474
  this.name = name;
@@ -41403,6 +41481,9 @@ ${newlined}
41403
41481
  participantName: r["participant_name"]
41404
41482
  });
41405
41483
  }
41484
+ if ("table" in r) {
41485
+ return RequiredTable.fromJson(r);
41486
+ }
41406
41487
  if ("schema" in r) {
41407
41488
  return new RequiredSchema({ name: r["schema"] });
41408
41489
  }
@@ -41436,6 +41517,43 @@ ${newlined}
41436
41517
  }
41437
41518
  };
41438
41519
  exports.RequiredSchema = RequiredSchema;
41520
+ var RequiredTable = class _RequiredTable extends Requirement {
41521
+ constructor({ name, schema, namespace, scalarIndexes, fullTextSearchIndexes, vectorIndexes }) {
41522
+ super({ name });
41523
+ this.schema = schema;
41524
+ this.namespace = namespace;
41525
+ this.scalarIndexes = scalarIndexes;
41526
+ this.fullTextSearchIndexes = fullTextSearchIndexes;
41527
+ this.vectorIndexes = vectorIndexes;
41528
+ }
41529
+ static fromJson(r) {
41530
+ if (typeof r["table"] !== "string") {
41531
+ throw new RoomException("required table name must be a string");
41532
+ }
41533
+ if (typeof r["schema"] !== "string") {
41534
+ throw new RoomException("required table schema must be a base64 Arrow IPC schema");
41535
+ }
41536
+ return new _RequiredTable({
41537
+ name: r["table"],
41538
+ schema: schemaFromIPCBytes(base64ToBytes(r["schema"])),
41539
+ namespace: Array.isArray(r["namespace"]) ? r["namespace"].map(String) : void 0,
41540
+ scalarIndexes: Array.isArray(r["scalar_indexes"]) ? r["scalar_indexes"].map(String) : void 0,
41541
+ fullTextSearchIndexes: Array.isArray(r["full_text_search_indexes"]) ? r["full_text_search_indexes"].map(String) : void 0,
41542
+ vectorIndexes: Array.isArray(r["vector_indexes"]) ? r["vector_indexes"].map(String) : void 0
41543
+ });
41544
+ }
41545
+ toJson() {
41546
+ return {
41547
+ table: this.name,
41548
+ schema: bytesToBase64(schemaToIPC(this.schema)),
41549
+ namespace: this.namespace,
41550
+ scalar_indexes: this.scalarIndexes,
41551
+ full_text_search_indexes: this.fullTextSearchIndexes,
41552
+ vector_indexes: this.vectorIndexes
41553
+ };
41554
+ }
41555
+ };
41556
+ exports.RequiredTable = RequiredTable;
41439
41557
  }
41440
41558
  });
41441
41559
 
@@ -41444,11 +41562,251 @@ ${newlined}
41444
41562
  "../meshagent-ts/dist/browser/meshagent-client.js"(exports) {
41445
41563
  "use strict";
41446
41564
  Object.defineProperty(exports, "__esModule", { value: true });
41447
- exports.Meshagent = void 0;
41565
+ exports.Meshagent = exports.ManagedAgentGrant = exports.ServiceTemplateSpec = exports.RoomSession = void 0;
41566
+ exports.normalizeServiceSpec = normalizeServiceSpec;
41448
41567
  var helpers_js_1 = require_helpers();
41449
41568
  var requirement_js_1 = require_requirement();
41450
41569
  var participant_token_js_1 = require_participant_token();
41451
41570
  var utils_js_1 = require_utils();
41571
+ var RoomSession = class {
41572
+ constructor({ id, roomId, roomName, createdAt, isActive, participants, kind = "room", agentId, agentName }) {
41573
+ this.id = id;
41574
+ this.roomId = roomId;
41575
+ this.roomName = roomName;
41576
+ this.createdAt = createdAt;
41577
+ this.isActive = isActive;
41578
+ this.participants = participants;
41579
+ this.kind = kind;
41580
+ this.agentId = agentId;
41581
+ this.agentName = agentName;
41582
+ }
41583
+ toJson() {
41584
+ return {
41585
+ id: this.id,
41586
+ room_id: this.roomId ?? null,
41587
+ room_name: this.roomName,
41588
+ started_at: this.createdAt.toISOString(),
41589
+ is_active: this.isActive,
41590
+ kind: this.kind,
41591
+ ...this.agentId != null ? { agent_id: this.agentId } : {},
41592
+ ...this.agentName != null ? { agent_name: this.agentName } : {}
41593
+ };
41594
+ }
41595
+ };
41596
+ exports.RoomSession = RoomSession;
41597
+ function cloneJsonValue(value) {
41598
+ if (Array.isArray(value)) {
41599
+ return value.map((item) => cloneJsonValue(item));
41600
+ }
41601
+ if (value != null && typeof value === "object") {
41602
+ const result = {};
41603
+ for (const [key, item] of Object.entries(value)) {
41604
+ result[key] = cloneJsonValue(item);
41605
+ }
41606
+ return result;
41607
+ }
41608
+ return value;
41609
+ }
41610
+ function formatTemplateString(value, values) {
41611
+ return value.replace(/\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (token, key) => values[key] ?? token);
41612
+ }
41613
+ function formatJsonValue(value, values) {
41614
+ if (typeof value === "string") {
41615
+ return formatTemplateString(value, values);
41616
+ }
41617
+ if (Array.isArray(value)) {
41618
+ return value.map((item) => formatJsonValue(item, values));
41619
+ }
41620
+ if (value != null && typeof value === "object") {
41621
+ const result = {};
41622
+ for (const [key, item] of Object.entries(value)) {
41623
+ result[key] = formatJsonValue(item, values);
41624
+ }
41625
+ return result;
41626
+ }
41627
+ return value;
41628
+ }
41629
+ function objectOrUndefined(value) {
41630
+ return value != null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
41631
+ }
41632
+ function objectArray(value) {
41633
+ return Array.isArray(value) ? value.filter((item) => objectOrUndefined(item) !== void 0) : void 0;
41634
+ }
41635
+ function stringValue(value) {
41636
+ return typeof value === "string" ? value : void 0;
41637
+ }
41638
+ function booleanValue(value) {
41639
+ return typeof value === "boolean" ? value : void 0;
41640
+ }
41641
+ function normalizeRoomMount(value) {
41642
+ return {
41643
+ path: stringValue(value.path) ?? "",
41644
+ ...stringValue(value.subpath) !== void 0 ? { subpath: stringValue(value.subpath) } : {},
41645
+ ...booleanValue(value.read_only) !== void 0 ? { read_only: booleanValue(value.read_only) } : {}
41646
+ };
41647
+ }
41648
+ function normalizeProjectMount(value) {
41649
+ return {
41650
+ path: stringValue(value.path) ?? "",
41651
+ ...stringValue(value.subpath) !== void 0 ? { subpath: stringValue(value.subpath) } : {},
41652
+ read_only: booleanValue(value.read_only) ?? true
41653
+ };
41654
+ }
41655
+ function normalizeImageMount(value) {
41656
+ return {
41657
+ path: stringValue(value.path) ?? "",
41658
+ ...stringValue(value.subpath) !== void 0 ? { subpath: stringValue(value.subpath) } : {},
41659
+ read_only: booleanValue(value.read_only) ?? true,
41660
+ image: stringValue(value.image) ?? ""
41661
+ };
41662
+ }
41663
+ function normalizeFileMount(value) {
41664
+ return {
41665
+ path: stringValue(value.path) ?? "",
41666
+ ...stringValue(value.subpath) !== void 0 ? { subpath: stringValue(value.subpath) } : {},
41667
+ read_only: booleanValue(value.read_only) ?? true,
41668
+ text: stringValue(value.text) ?? ""
41669
+ };
41670
+ }
41671
+ function normalizeEmptyDirMount(value) {
41672
+ return {
41673
+ path: stringValue(value.path) ?? "",
41674
+ read_only: booleanValue(value.read_only) ?? false
41675
+ };
41676
+ }
41677
+ function normalizeConfigMount(value) {
41678
+ return {
41679
+ path: stringValue(value.path) ?? "/var/run/meshagent"
41680
+ };
41681
+ }
41682
+ function normalizeContainerMountSpec(value) {
41683
+ const source = objectOrUndefined(value) ?? {};
41684
+ const room = objectArray(source.room)?.map(normalizeRoomMount);
41685
+ const project = objectArray(source.project)?.map(normalizeProjectMount);
41686
+ const images = objectArray(source.images)?.map(normalizeImageMount);
41687
+ const files = objectArray(source.files)?.map(normalizeFileMount);
41688
+ const emptyDirs = objectArray(source.empty_dirs)?.map(normalizeEmptyDirMount);
41689
+ const configs = objectArray(source.configs)?.map(normalizeConfigMount);
41690
+ return {
41691
+ ...room !== void 0 ? { room } : {},
41692
+ ...project !== void 0 ? { project } : {},
41693
+ ...images !== void 0 ? { images } : {},
41694
+ ...files !== void 0 ? { files } : {},
41695
+ ...emptyDirs !== void 0 ? { empty_dirs: emptyDirs } : {},
41696
+ ...configs !== void 0 ? { configs } : {}
41697
+ };
41698
+ }
41699
+ function normalizeAgentSpec(agent, values) {
41700
+ const formatted = formatJsonValue(agent, values);
41701
+ const spec = cloneJsonValue(formatted);
41702
+ if (spec.email != null && spec.email.public == null) {
41703
+ spec.email = { ...spec.email, public: false };
41704
+ }
41705
+ if (spec.channels?.email) {
41706
+ spec.channels = {
41707
+ ...spec.channels,
41708
+ email: spec.channels.email.map((channel) => ({
41709
+ ...channel,
41710
+ private: channel.private ?? false
41711
+ }))
41712
+ };
41713
+ }
41714
+ if (spec.channels?.messaging) {
41715
+ spec.channels = {
41716
+ ...spec.channels,
41717
+ messaging: spec.channels.messaging.map((channel) => ({
41718
+ ...channel,
41719
+ protocol: channel.protocol ?? "meshagent.agent-message.v1"
41720
+ }))
41721
+ };
41722
+ }
41723
+ return spec;
41724
+ }
41725
+ function normalizeServiceSpec(service) {
41726
+ const normalized = cloneJsonValue(service);
41727
+ if (normalized.container?.storage != null) {
41728
+ normalized.container = {
41729
+ ...normalized.container,
41730
+ storage: normalizeContainerMountSpec(normalized.container.storage)
41731
+ };
41732
+ }
41733
+ return normalized;
41734
+ }
41735
+ var ServiceTemplateSpec = class _ServiceTemplateSpec {
41736
+ constructor({ version: version2 = "v1", kind = "ServiceTemplate", variables, metadata, ports = [], container, external, agents = [] }) {
41737
+ this.version = version2;
41738
+ this.kind = kind;
41739
+ this.variables = variables;
41740
+ this.metadata = metadata;
41741
+ this.ports = ports;
41742
+ this.container = container;
41743
+ this.external = external;
41744
+ this.agents = agents;
41745
+ }
41746
+ static fromJson(json) {
41747
+ const metadata = objectOrUndefined(json.metadata);
41748
+ if (metadata === void 0 || typeof metadata.name !== "string") {
41749
+ throw new requirement_js_1.RoomException("Invalid service template payload: missing metadata.name");
41750
+ }
41751
+ return new _ServiceTemplateSpec({
41752
+ version: stringValue(json.version) ?? "v1",
41753
+ kind: stringValue(json.kind) ?? "ServiceTemplate",
41754
+ variables: objectArray(json.variables),
41755
+ metadata: cloneJsonValue(metadata),
41756
+ ports: objectArray(json.ports) ?? [],
41757
+ container: objectOrUndefined(json.container),
41758
+ external: objectOrUndefined(json.external),
41759
+ agents: objectArray(json.agents) ?? []
41760
+ });
41761
+ }
41762
+ toJson() {
41763
+ return {
41764
+ version: this.version,
41765
+ kind: this.kind,
41766
+ ...this.variables != null ? { variables: cloneJsonValue(this.variables) } : {},
41767
+ metadata: cloneJsonValue(this.metadata),
41768
+ ...this.ports.length > 0 ? { ports: cloneJsonValue(this.ports) } : {},
41769
+ ...this.container != null ? { container: cloneJsonValue(this.container) } : {},
41770
+ ...this.external != null ? { external: cloneJsonValue(this.external) } : {},
41771
+ ...this.agents.length > 0 ? { agents: cloneJsonValue(this.agents) } : {}
41772
+ };
41773
+ }
41774
+ toServiceSpec({ values = {} } = {}) {
41775
+ const service = {
41776
+ version: "v1",
41777
+ kind: "Service",
41778
+ metadata: cloneJsonValue(this.metadata),
41779
+ agents: this.agents.map((agent) => normalizeAgentSpec(agent, values)),
41780
+ ports: cloneJsonValue(this.ports)
41781
+ };
41782
+ if (this.container != null) {
41783
+ const formattedContainer = formatJsonValue(this.container, values);
41784
+ const image = stringValue(formattedContainer.image);
41785
+ if (image === void 0 || image.length === 0) {
41786
+ throw new requirement_js_1.RoomException("ServiceTemplateSpec.image is required to build a ServiceSpec");
41787
+ }
41788
+ service.container = {
41789
+ ...booleanValue(formattedContainer.private) !== void 0 ? { private: booleanValue(formattedContainer.private) } : {},
41790
+ ...stringValue(formattedContainer.command) !== void 0 ? { command: stringValue(formattedContainer.command) } : {},
41791
+ ...stringValue(formattedContainer.working_dir) !== void 0 ? { working_dir: stringValue(formattedContainer.working_dir) } : {},
41792
+ image,
41793
+ ...Array.isArray(formattedContainer.environment) ? { environment: formattedContainer.environment } : {},
41794
+ ...objectOrUndefined(formattedContainer.storage) !== void 0 ? { storage: normalizeContainerMountSpec(formattedContainer.storage) } : {},
41795
+ ...booleanValue(formattedContainer.on_demand) !== void 0 ? { on_demand: booleanValue(formattedContainer.on_demand) } : {},
41796
+ ...booleanValue(formattedContainer.writable_root_fs) !== void 0 ? { writable_root_fs: booleanValue(formattedContainer.writable_root_fs) } : {}
41797
+ };
41798
+ }
41799
+ if (this.external != null) {
41800
+ const formattedExternal = formatJsonValue(this.external, values);
41801
+ const url = stringValue(formattedExternal.url);
41802
+ if (url !== void 0) {
41803
+ service.external = { url };
41804
+ }
41805
+ }
41806
+ return normalizeServiceSpec(service);
41807
+ }
41808
+ };
41809
+ exports.ServiceTemplateSpec = ServiceTemplateSpec;
41452
41810
  function pruneUndefinedValues(value) {
41453
41811
  if (Array.isArray(value)) {
41454
41812
  const prunedItems = value.map((item) => pruneUndefinedValues(item)).filter((item) => item !== void 0);
@@ -41469,6 +41827,25 @@ ${newlined}
41469
41827
  }
41470
41828
  return value;
41471
41829
  }
41830
+ function pruneNullishValues(value) {
41831
+ if (Array.isArray(value)) {
41832
+ return value.map((item) => pruneNullishValues(item)).filter((item) => item !== void 0);
41833
+ }
41834
+ if (value === null || value === void 0) {
41835
+ return void 0;
41836
+ }
41837
+ if (typeof value === "object") {
41838
+ const result = {};
41839
+ for (const [key, entryValue] of Object.entries(value)) {
41840
+ const normalized = pruneNullishValues(entryValue);
41841
+ if (normalized !== void 0) {
41842
+ result[key] = normalized;
41843
+ }
41844
+ }
41845
+ return result;
41846
+ }
41847
+ return value;
41848
+ }
41472
41849
  function serializeServiceSpec(service) {
41473
41850
  const agents = service.agents?.map((agent) => ({
41474
41851
  ...agent,
@@ -41490,6 +41867,18 @@ ${newlined}
41490
41867
  delete payload.id;
41491
41868
  return payload;
41492
41869
  }
41870
+ var ManagedAgentGrant = class _ManagedAgentGrant {
41871
+ constructor({ admin = false } = {}) {
41872
+ this.admin = admin;
41873
+ }
41874
+ static fromJson(json) {
41875
+ return new _ManagedAgentGrant({ admin: json["admin"] === true });
41876
+ }
41877
+ toJson() {
41878
+ return { admin: this.admin };
41879
+ }
41880
+ };
41881
+ exports.ManagedAgentGrant = ManagedAgentGrant;
41493
41882
  var globalScope = globalThis;
41494
41883
  function bytesToBase64(bytes) {
41495
41884
  if (globalScope.Buffer) {
@@ -41589,7 +41978,11 @@ ${newlined}
41589
41978
  } catch {
41590
41979
  message2 = "<unable to read body>";
41591
41980
  }
41592
- throw new requirement_js_1.RoomException(`Failed to ${action}. Status code: ${response.status}, body: ${message2}`);
41981
+ const errorMessage = `Failed to ${action}. Status code: ${response.status}, body: ${message2}`;
41982
+ if (response.status === 403) {
41983
+ throw new requirement_js_1.ForbiddenException(errorMessage);
41984
+ }
41985
+ throw new requirement_js_1.RoomException(errorMessage);
41593
41986
  }
41594
41987
  switch (responseType) {
41595
41988
  case "json":
@@ -41628,7 +42021,7 @@ ${newlined}
41628
42021
  if (!data || typeof data !== "object") {
41629
42022
  throw new requirement_js_1.RoomException("Invalid room session payload");
41630
42023
  }
41631
- const { id, room_id: roomIdRaw, roomId, room_name: roomNameRaw, roomName, created_at: createdRaw, createdAt, is_active: isActiveRaw, isActive, participants } = data;
42024
+ const { id, room_id: roomIdRaw, roomId, room_name: roomNameRaw, roomName, created_at: createdRaw, createdAt, is_active: isActiveRaw, isActive, participants, kind, agent_id: agentIdRaw, agentId, agent_name: agentNameRaw, agentName } = data;
41632
42025
  if (typeof id !== "string") {
41633
42026
  throw new requirement_js_1.RoomException("Invalid room session payload: missing id");
41634
42027
  }
@@ -41644,13 +42037,30 @@ ${newlined}
41644
42037
  if (typeof isActiveValue !== "boolean") {
41645
42038
  throw new requirement_js_1.RoomException("Invalid room session payload: missing is_active");
41646
42039
  }
41647
- return {
42040
+ return new RoomSession({
41648
42041
  id,
41649
42042
  roomId: typeof roomId === "string" ? roomId : typeof roomIdRaw === "string" ? roomIdRaw : void 0,
41650
42043
  roomName: roomNameValue,
41651
42044
  createdAt: new Date(created),
41652
42045
  isActive: isActiveValue,
41653
- participants: participants && typeof participants === "object" ? participants : void 0
42046
+ participants: participants && typeof participants === "object" ? participants : void 0,
42047
+ kind: typeof kind === "string" ? kind : "room",
42048
+ agentId: typeof agentId === "string" ? agentId : typeof agentIdRaw === "string" ? agentIdRaw : void 0,
42049
+ agentName: typeof agentName === "string" ? agentName : typeof agentNameRaw === "string" ? agentNameRaw : void 0
42050
+ });
42051
+ }
42052
+ parseManagedAgent(data) {
42053
+ if (!data || typeof data !== "object") {
42054
+ throw new requirement_js_1.RoomException("Invalid managed agent payload");
42055
+ }
42056
+ const { id, name, configuration } = data;
42057
+ if (typeof id !== "string" || typeof name !== "string") {
42058
+ throw new requirement_js_1.RoomException("Invalid managed agent payload: missing id or name");
42059
+ }
42060
+ return {
42061
+ id,
42062
+ name,
42063
+ configuration: configuration && typeof configuration === "object" && !Array.isArray(configuration) ? configuration : {}
41654
42064
  };
41655
42065
  }
41656
42066
  parseRoom(data) {
@@ -42154,7 +42564,7 @@ ${newlined}
42154
42564
  });
42155
42565
  }
42156
42566
  async addUserToProject(projectId, userId, options = {}) {
42157
- const { isAdmin, isDeveloper, canCreateRooms } = options;
42567
+ const { isAdmin, isDeveloper, canCreateRooms, inviteRedirectUrl } = options;
42158
42568
  return await this.request(`/accounts/projects/${projectId}/users`, {
42159
42569
  method: "POST",
42160
42570
  json: {
@@ -42162,7 +42572,23 @@ ${newlined}
42162
42572
  user_id: userId,
42163
42573
  ...isAdmin !== void 0 ? { is_admin: isAdmin } : {},
42164
42574
  ...isDeveloper !== void 0 ? { is_developer: isDeveloper } : {},
42165
- ...canCreateRooms !== void 0 ? { can_create_rooms: canCreateRooms } : {}
42575
+ ...canCreateRooms !== void 0 ? { can_create_rooms: canCreateRooms } : {},
42576
+ ...inviteRedirectUrl !== void 0 ? { invite_redirect_url: inviteRedirectUrl } : {}
42577
+ },
42578
+ action: "add user to project"
42579
+ });
42580
+ }
42581
+ async addUserToProjectByEmail(projectId, email, options = {}) {
42582
+ const { isAdmin, isDeveloper, canCreateRooms, inviteRedirectUrl } = options;
42583
+ return await this.request(`/accounts/projects/${projectId}/users`, {
42584
+ method: "POST",
42585
+ json: {
42586
+ project_id: projectId,
42587
+ email,
42588
+ ...isAdmin !== void 0 ? { is_admin: isAdmin } : {},
42589
+ ...isDeveloper !== void 0 ? { is_developer: isDeveloper } : {},
42590
+ ...canCreateRooms !== void 0 ? { can_create_rooms: canCreateRooms } : {},
42591
+ ...inviteRedirectUrl !== void 0 ? { invite_redirect_url: inviteRedirectUrl } : {}
42166
42592
  },
42167
42593
  action: "add user to project"
42168
42594
  });
@@ -42220,6 +42646,20 @@ ${newlined}
42220
42646
  action: "get project by key"
42221
42647
  });
42222
42648
  }
42649
+ async createAgent(params) {
42650
+ const { projectId, configuration, ifNotExists = false, permissions } = params;
42651
+ const permissionsJson = permissions == null ? void 0 : Object.fromEntries(Object.entries(permissions).map(([userId, grant]) => [userId, grant.toJson()]));
42652
+ const data = await this.request(`/accounts/projects/${this.encodePathComponent(projectId)}/agents`, {
42653
+ method: "POST",
42654
+ json: {
42655
+ configuration: pruneNullishValues(configuration),
42656
+ if_not_exists: ifNotExists,
42657
+ ...permissionsJson !== void 0 ? { permissions: permissionsJson } : {}
42658
+ },
42659
+ action: "create agent"
42660
+ });
42661
+ return this.parseManagedAgent(data);
42662
+ }
42223
42663
  async createApiKey(projectId, name, description) {
42224
42664
  return await this.request(`/accounts/projects/${projectId}/api-keys`, {
42225
42665
  method: "POST",
@@ -42711,14 +43151,14 @@ ${newlined}
42711
43151
  const data = await this.request(`/accounts/projects/${projectId}/rooms/${roomName}/services/${serviceId}`, {
42712
43152
  action: "fetch room service"
42713
43153
  });
42714
- return data;
43154
+ return normalizeServiceSpec(data);
42715
43155
  }
42716
43156
  async listRoomServices(projectId, roomName) {
42717
43157
  const data = await this.request(`/accounts/projects/${projectId}/rooms/${roomName}/services`, {
42718
43158
  action: "list room services"
42719
43159
  });
42720
43160
  const services = Array.isArray(data?.services) ? data.services : [];
42721
- return services;
43161
+ return services.map((service) => normalizeServiceSpec(service));
42722
43162
  }
42723
43163
  async deleteRoomService(projectId, roomName, serviceId) {
42724
43164
  await this.request(`/accounts/projects/${projectId}/rooms/${roomName}/services/${serviceId}`, {
@@ -42742,14 +43182,14 @@ ${newlined}
42742
43182
  const data = await this.request(`/accounts/projects/${projectId}/services/${serviceId}`, {
42743
43183
  action: "fetch service"
42744
43184
  });
42745
- return data;
43185
+ return normalizeServiceSpec(data);
42746
43186
  }
42747
43187
  async listServices(projectId) {
42748
43188
  const data = await this.request(`/accounts/projects/${projectId}/services`, {
42749
43189
  action: "list services"
42750
43190
  });
42751
43191
  const services = Array.isArray(data?.services) ? data.services : [];
42752
- return services;
43192
+ return services.map((service) => normalizeServiceSpec(service));
42753
43193
  }
42754
43194
  async deleteService(projectId, serviceId) {
42755
43195
  await this.request(`/accounts/projects/${projectId}/services/${serviceId}`, {
@@ -43088,13 +43528,14 @@ ${newlined}
43088
43528
  });
43089
43529
  }
43090
43530
  async createRoomGrantByEmail(params) {
43091
- const { projectId, roomId, email, permissions } = params;
43531
+ const { projectId, roomId, email, permissions, inviteRedirectUrl } = params;
43092
43532
  await this.request(`/accounts/projects/${projectId}/room-grants`, {
43093
43533
  method: "POST",
43094
43534
  json: {
43095
43535
  room_id: roomId,
43096
43536
  email,
43097
- permissions: permissions.toJSON()
43537
+ permissions: permissions.toJSON(),
43538
+ ...inviteRedirectUrl !== void 0 ? { invite_redirect_url: inviteRedirectUrl } : {}
43098
43539
  },
43099
43540
  action: "create room grant",
43100
43541
  responseType: "void"
@@ -43386,7 +43827,7 @@ ${newlined}
43386
43827
  return input;
43387
43828
  }
43388
43829
  async _invoke({ operation, input }) {
43389
- await this.client.invoke({
43830
+ await this.client.invokeContent({
43390
43831
  toolkit: "messaging",
43391
43832
  tool: operation,
43392
43833
  input: new response_js_1.JsonContent({ json: input })
@@ -44085,7 +44526,7 @@ ${newlined}
44085
44526
  return unexpectedResponse(operation);
44086
44527
  }
44087
44528
  async invoke(operation, input) {
44088
- const response = await this.room.invoke({
44529
+ const response = await this.room.invokeContent({
44089
44530
  toolkit: "memory",
44090
44531
  tool: operation,
44091
44532
  input
@@ -44332,7 +44773,7 @@ ${newlined}
44332
44773
  return new room_server_client_js_1.RoomServerException(`unexpected return type from queues.${operation}`);
44333
44774
  }
44334
44775
  async _invoke(operation, arguments_) {
44335
- return await this.client.invoke({
44776
+ return await this.client.invokeContent({
44336
44777
  toolkit: "queues",
44337
44778
  tool: operation,
44338
44779
  arguments: arguments_
@@ -44415,7 +44856,7 @@ ${newlined}
44415
44856
  return new room_server_client_js_1.RoomServerException(`unexpected return type from secrets.${operation}`);
44416
44857
  }
44417
44858
  async invoke(operation, input) {
44418
- return await this.client.invoke({
44859
+ return await this.client.invokeContent({
44419
44860
  toolkit: "secrets",
44420
44861
  tool: operation,
44421
44862
  input
@@ -44753,7 +45194,7 @@ ${newlined}
44753
45194
  return (await this.listWithState()).services;
44754
45195
  }
44755
45196
  async listWithState() {
44756
- const response = await this.room.invoke({
45197
+ const response = await this.room.invokeContent({
44757
45198
  toolkit: "services",
44758
45199
  tool: "list",
44759
45200
  input: {}
@@ -44777,7 +45218,7 @@ ${newlined}
44777
45218
  };
44778
45219
  }
44779
45220
  async restart(params) {
44780
- const response = await this.room.invoke({
45221
+ const response = await this.room.invokeContent({
44781
45222
  toolkit: "services",
44782
45223
  tool: "restart",
44783
45224
  input: {
@@ -44930,7 +45371,7 @@ ${newlined}
44930
45371
  });
44931
45372
  }
44932
45373
  async _invoke(operation, input) {
44933
- return await this.client.invoke({
45374
+ return await this.client.invokeContent({
44934
45375
  toolkit: "storage",
44935
45376
  tool: operation,
44936
45377
  input
@@ -45507,7 +45948,7 @@ ${newlined}
45507
45948
  return new room_server_client_js_1.RoomServerException(`unexpected return type from sync.${operation}`);
45508
45949
  }
45509
45950
  async _invoke(operation, input) {
45510
- return await this.room.invoke({
45951
+ return await this.room.invokeContent({
45511
45952
  toolkit: "sync",
45512
45953
  tool: operation,
45513
45954
  input
@@ -45975,6 +46416,7 @@ ${newlined}
45975
46416
  this._eventEmitter = new event_emitter_js_1.EventEmitter();
45976
46417
  this._pendingRequests = /* @__PURE__ */ new Map();
45977
46418
  this._toolCallStreams = /* @__PURE__ */ new Map();
46419
+ this._toolCallPreOpenErrors = /* @__PURE__ */ new Map();
45978
46420
  this._ignoredResponseLabels = /* @__PURE__ */ new Map();
45979
46421
  this._ready = new completer_js_1.Completer();
45980
46422
  this._roomClosed = new completer_js_1.Completer();
@@ -46928,41 +47370,58 @@ ${newlined}
46928
47370
  }
46929
47371
  return toolkits;
46930
47372
  }
46931
- async invoke(params) {
46932
- const input = params.input ?? params.arguments ?? new response_js_1.EmptyContent();
46933
- const request = {
46934
- toolkit: params.toolkit,
46935
- tool: params.tool
46936
- };
46937
- let requestData;
47373
+ _normalizeInvokeInput(input) {
47374
+ if (input === void 0) {
47375
+ return new response_js_1.EmptyContent();
47376
+ }
46938
47377
  if (input instanceof response_js_1.BinaryContent || input instanceof response_js_1.EmptyContent || input instanceof response_js_1.ErrorContent || input instanceof response_js_1.FileContent || input instanceof response_js_1.JsonContent || input instanceof response_js_1.LinkContent || input instanceof response_js_1.TextContent) {
46939
- const packed = input.pack();
46940
- request["arguments"] = JSON.parse((0, utils_js_1.splitMessageHeader)(packed));
46941
- const payload = (0, utils_js_1.splitMessagePayload)(packed);
46942
- if (payload.length > 0) {
46943
- requestData = payload;
46944
- }
46945
- } else if (typeof input === "object" && input !== null && !Array.isArray(input)) {
46946
- request["arguments"] = {
46947
- type: "json",
46948
- json: input
46949
- };
46950
- } else {
46951
- throw new room_server_client_js_1.RoomServerException("invoke input must be a content value or JSON object");
47378
+ return input;
46952
47379
  }
46953
- if (params.participantId != null) {
46954
- request["participant_id"] = params.participantId;
47380
+ if (typeof input === "object" && input !== null && !Array.isArray(input)) {
47381
+ return new response_js_1.JsonContent({ json: input });
46955
47382
  }
46956
- if (params.onBehalfOfId != null) {
46957
- request["on_behalf_of_id"] = params.onBehalfOfId;
47383
+ throw new room_server_client_js_1.RoomServerException("invoke input must be a content value or JSON object");
47384
+ }
47385
+ invoke(params) {
47386
+ const outputPromise = this.invokeToolCall({
47387
+ toolkit: params.toolkit,
47388
+ tool: params.tool,
47389
+ input: this._normalizeInvokeInput(params.input ?? params.arguments),
47390
+ participantId: params.participantId,
47391
+ onBehalfOfId: params.onBehalfOfId
47392
+ });
47393
+ void outputPromise.catch(() => void 0);
47394
+ return {
47395
+ async *[Symbol.asyncIterator]() {
47396
+ const output = await outputPromise;
47397
+ if (output.kind === "stream") {
47398
+ yield* output.stream;
47399
+ return;
47400
+ }
47401
+ yield output.content;
47402
+ }
47403
+ };
47404
+ }
47405
+ async invokeContent(params) {
47406
+ const output = await this.invokeToolCall({
47407
+ toolkit: params.toolkit,
47408
+ tool: params.tool,
47409
+ input: this._normalizeInvokeInput(params.input ?? params.arguments),
47410
+ participantId: params.participantId,
47411
+ onBehalfOfId: params.onBehalfOfId
47412
+ });
47413
+ if (output.kind !== "content") {
47414
+ throw new room_server_client_js_1.RoomServerException("unexpected streamed output from " + params.toolkit + "." + params.tool);
46958
47415
  }
46959
- return await this.sendRequest("room.invoke_tool", request, requestData);
47416
+ return output.content;
46960
47417
  }
46961
47418
  async invokeToolCall(params) {
46962
47419
  const toolCallId = `${Date.now()}-${Math.random().toString(16).slice(2)}`;
46963
47420
  const controller = new stream_controller_js_1.StreamController();
46964
47421
  const responseIterator = controller.stream[Symbol.asyncIterator]();
47422
+ const preOpenError = new completer_js_1.Completer();
46965
47423
  this._toolCallStreams.set(toolCallId, controller);
47424
+ this._toolCallPreOpenErrors.set(toolCallId, preOpenError);
46966
47425
  const request = {
46967
47426
  toolkit: params.toolkit,
46968
47427
  tool: params.tool,
@@ -46989,7 +47448,11 @@ ${newlined}
46989
47448
  request["on_behalf_of_id"] = params.onBehalfOfId;
46990
47449
  }
46991
47450
  try {
46992
- const response = await this.sendRequest("room.invoke_tool", request, requestData);
47451
+ const response = await Promise.race([
47452
+ this.sendRequest("room.invoke_tool", request, requestData),
47453
+ preOpenError.fut
47454
+ ]);
47455
+ this._toolCallPreOpenErrors.delete(toolCallId);
46993
47456
  if (response instanceof response_js_1.ControlContent && response.method === "open") {
46994
47457
  if (requestTask != null) {
46995
47458
  void requestTask.catch((error) => {
@@ -46997,7 +47460,7 @@ ${newlined}
46997
47460
  if (stream == null) {
46998
47461
  return;
46999
47462
  }
47000
- stream.add(new response_js_1.ErrorContent({ text: `request stream failed: ${String(error)}` }));
47463
+ stream.addError(error);
47001
47464
  stream.close();
47002
47465
  this._toolCallStreams.delete(toolCallId);
47003
47466
  });
@@ -47020,6 +47483,7 @@ ${newlined}
47020
47483
  return { kind: "content", content: response, inputClosed: requestTask };
47021
47484
  } catch (error) {
47022
47485
  await Promise.resolve(requestTask).catch(() => void 0);
47486
+ this._toolCallPreOpenErrors.delete(toolCallId);
47023
47487
  this._toolCallStreams.delete(toolCallId);
47024
47488
  controller.close();
47025
47489
  throw error;
@@ -47056,7 +47520,9 @@ ${newlined}
47056
47520
  const toolCallId = `${Date.now()}-${Math.random().toString(16).slice(2)}`;
47057
47521
  const controller = new stream_controller_js_1.StreamController();
47058
47522
  const responseIterator = controller.stream[Symbol.asyncIterator]();
47523
+ const preOpenError = new completer_js_1.Completer();
47059
47524
  this._toolCallStreams.set(toolCallId, controller);
47525
+ this._toolCallPreOpenErrors.set(toolCallId, preOpenError);
47060
47526
  const request = {
47061
47527
  toolkit: params.toolkit,
47062
47528
  tool: params.tool,
@@ -47075,11 +47541,23 @@ ${newlined}
47075
47541
  if (stream == null) {
47076
47542
  return;
47077
47543
  }
47078
- stream.add(new response_js_1.ErrorContent({ text: `request stream failed: ${String(error)}` }));
47544
+ stream.addError(error);
47079
47545
  stream.close();
47080
47546
  this._toolCallStreams.delete(toolCallId);
47081
47547
  });
47082
- const response = await this.sendRequest("room.invoke_tool", request);
47548
+ let response;
47549
+ try {
47550
+ response = await Promise.race([
47551
+ this.sendRequest("room.invoke_tool", request),
47552
+ preOpenError.fut
47553
+ ]);
47554
+ } catch (error) {
47555
+ this._toolCallPreOpenErrors.delete(toolCallId);
47556
+ this._toolCallStreams.delete(toolCallId);
47557
+ controller.close();
47558
+ throw error;
47559
+ }
47560
+ this._toolCallPreOpenErrors.delete(toolCallId);
47083
47561
  if (!(response instanceof response_js_1.ControlContent) || response.method !== "open") {
47084
47562
  this._toolCallStreams.delete(toolCallId);
47085
47563
  controller.close();
@@ -47135,10 +47613,31 @@ ${newlined}
47135
47613
  return;
47136
47614
  }
47137
47615
  const content = this._decodeToolCallContent({ header, payload });
47616
+ const preOpenError = this._toolCallPreOpenErrors.get(toolCallId);
47617
+ if (preOpenError != null && content instanceof response_js_1.ErrorContent) {
47618
+ const error = new room_server_client_js_1.RoomServerException(content.text, content.code);
47619
+ if (!preOpenError.completed) {
47620
+ preOpenError.completeError(error);
47621
+ }
47622
+ stream.addError(error);
47623
+ stream.close();
47624
+ this._toolCallStreams.delete(toolCallId);
47625
+ this._toolCallPreOpenErrors.delete(toolCallId);
47626
+ return;
47627
+ }
47628
+ if (content instanceof response_js_1.ControlContent && content.method === "close" && content.statusCode !== void 0 && content.statusCode !== response_js_1.ControlCloseStatus.NORMAL) {
47629
+ const error = new room_server_client_js_1.RoomServerException(content.message ?? `tool call stream closed with status ${content.statusCode}`, void 0, { statusCode: content.statusCode });
47630
+ stream.addError(error);
47631
+ stream.close();
47632
+ this._toolCallStreams.delete(toolCallId);
47633
+ this._toolCallPreOpenErrors.delete(toolCallId);
47634
+ return;
47635
+ }
47138
47636
  stream.add(content);
47139
47637
  if (content instanceof response_js_1.ControlContent && content.method === "close") {
47140
47638
  stream.close();
47141
47639
  this._toolCallStreams.delete(toolCallId);
47640
+ this._toolCallPreOpenErrors.delete(toolCallId);
47142
47641
  }
47143
47642
  }
47144
47643
  async _handleResponse(protocol, messageId, _type, data) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshagent/meshagent-ts-auth",
3
- "version": "0.44.11",
3
+ "version": "0.44.13",
4
4
  "description": "Meshagent Typescript Auth",
5
5
  "homepage": "https://github.com/meshagent/meshagent-ts-auth",
6
6
  "scripts": {
@@ -39,7 +39,7 @@
39
39
  "CHANGELOG.md"
40
40
  ],
41
41
  "dependencies": {
42
- "@meshagent/meshagent": "^0.44.11",
42
+ "@meshagent/meshagent": "^0.44.13",
43
43
  "typescript": "^5.8.3"
44
44
  },
45
45
  "devDependencies": {