@meshagent/meshagent 0.44.13 → 0.45.1

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 (56) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/browser/index.d.ts +1 -1
  3. package/dist/browser/index.js +1 -1
  4. package/dist/browser/meshagent-client.d.ts +390 -372
  5. package/dist/browser/meshagent-client.js +841 -1040
  6. package/dist/browser/oauth-scopes.d.ts +1 -1
  7. package/dist/browser/oauth-scopes.js +64 -14
  8. package/dist/browser/participant-token.d.ts +68 -20
  9. package/dist/browser/participant-token.js +232 -61
  10. package/dist/browser/room-client.d.ts +4 -8
  11. package/dist/browser/room-client.js +4 -10
  12. package/dist/browser/services-client.d.ts +11 -0
  13. package/dist/browser/services-client.js +17 -0
  14. package/dist/browser/sqlite-client.d.ts +326 -0
  15. package/dist/browser/sqlite-client.js +630 -0
  16. package/dist/browser/toolkit-config.d.ts +7 -1
  17. package/dist/browser/toolkit-config.js +41 -22
  18. package/dist/esm/index.d.ts +1 -1
  19. package/dist/esm/index.js +1 -1
  20. package/dist/esm/meshagent-client.d.ts +390 -372
  21. package/dist/esm/meshagent-client.js +841 -1038
  22. package/dist/esm/oauth-scopes.d.ts +1 -1
  23. package/dist/esm/oauth-scopes.js +64 -14
  24. package/dist/esm/participant-token.d.ts +68 -20
  25. package/dist/esm/participant-token.js +228 -59
  26. package/dist/esm/room-client.d.ts +4 -8
  27. package/dist/esm/room-client.js +4 -10
  28. package/dist/esm/services-client.d.ts +11 -0
  29. package/dist/esm/services-client.js +17 -0
  30. package/dist/esm/sqlite-client.d.ts +326 -0
  31. package/dist/esm/sqlite-client.js +625 -0
  32. package/dist/esm/toolkit-config.d.ts +7 -1
  33. package/dist/esm/toolkit-config.js +41 -22
  34. package/dist/node/index.d.ts +1 -1
  35. package/dist/node/index.js +1 -1
  36. package/dist/node/meshagent-client.d.ts +390 -372
  37. package/dist/node/meshagent-client.js +841 -1040
  38. package/dist/node/oauth-scopes.d.ts +1 -1
  39. package/dist/node/oauth-scopes.js +64 -14
  40. package/dist/node/participant-token.d.ts +68 -20
  41. package/dist/node/participant-token.js +232 -61
  42. package/dist/node/room-client.d.ts +4 -8
  43. package/dist/node/room-client.js +4 -10
  44. package/dist/node/services-client.d.ts +11 -0
  45. package/dist/node/services-client.js +17 -0
  46. package/dist/node/sqlite-client.d.ts +326 -0
  47. package/dist/node/sqlite-client.js +630 -0
  48. package/dist/node/toolkit-config.d.ts +7 -1
  49. package/dist/node/toolkit-config.js +41 -22
  50. package/package.json +1 -1
  51. package/dist/browser/secrets-client.d.ts +0 -112
  52. package/dist/browser/secrets-client.js +0 -300
  53. package/dist/esm/secrets-client.d.ts +0 -112
  54. package/dist/esm/secrets-client.js +0 -296
  55. package/dist/node/secrets-client.d.ts +0 -112
  56. package/dist/node/secrets-client.js +0 -300
@@ -0,0 +1,630 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SqliteClient = exports.SqliteDatabaseClient = void 0;
4
+ const apache_arrow_1 = require("apache-arrow");
5
+ const room_server_client_js_1 = require("./room-server-client.js");
6
+ const response_js_1 = require("./response.js");
7
+ const datasets_client_js_1 = require("./datasets-client.js");
8
+ const ARROW_IPC_STREAM_MIME_TYPE = "application/vnd.apache.arrow.stream";
9
+ const globalScope = globalThis;
10
+ async function* toAsyncArrowIterable(chunks) {
11
+ if (Symbol.asyncIterator in chunks) {
12
+ for await (const chunk of chunks) {
13
+ yield chunk;
14
+ }
15
+ return;
16
+ }
17
+ for (const chunk of chunks) {
18
+ yield chunk;
19
+ }
20
+ }
21
+ function isRecord(value) {
22
+ return typeof value === "object" && value !== null && !Array.isArray(value);
23
+ }
24
+ function bytesToBase64(bytes) {
25
+ if (globalScope.Buffer) {
26
+ return globalScope.Buffer.from(bytes).toString("base64");
27
+ }
28
+ if (!globalScope.btoa) {
29
+ throw new Error("base64 encoding is not available in this runtime");
30
+ }
31
+ let binary = "";
32
+ for (const byte of bytes) {
33
+ binary += String.fromCharCode(byte);
34
+ }
35
+ return globalScope.btoa(binary);
36
+ }
37
+ function encodeRecordValue(value) {
38
+ if (value instanceof datasets_client_js_1.DatasetValueEncoder) {
39
+ return value.encodeDatasetValue();
40
+ }
41
+ if (value instanceof Uint8Array) {
42
+ return {
43
+ binary: bytesToBase64(value),
44
+ };
45
+ }
46
+ if (value instanceof Date) {
47
+ return {
48
+ timestamp: value.toISOString().replace("+00:00", "Z"),
49
+ };
50
+ }
51
+ if (Array.isArray(value)) {
52
+ return {
53
+ list: value.map((item) => encodeRecordValue(item)),
54
+ };
55
+ }
56
+ if (isRecord(value)) {
57
+ throw new room_server_client_js_1.RoomServerException("sqlite object values must use DatasetStruct or DatasetJson");
58
+ }
59
+ return value;
60
+ }
61
+ function buildWhereClause(where) {
62
+ if (where != null && typeof where === "object" && !Array.isArray(where)) {
63
+ return Object.fromEntries(Object.entries(where).map(([key, value]) => [key, encodeRecordValue(value)]));
64
+ }
65
+ if (typeof where === "string") {
66
+ return where;
67
+ }
68
+ return null;
69
+ }
70
+ function schemaToIPC(schema) {
71
+ return (0, apache_arrow_1.tableToIPC)(new apache_arrow_1.Table(schema, []), "stream");
72
+ }
73
+ function tableFromIPCBytes(data) {
74
+ const table = (0, apache_arrow_1.tableFromIPC)(data);
75
+ if (table instanceof Promise) {
76
+ throw new room_server_client_js_1.RoomServerException("unexpected async Arrow IPC result");
77
+ }
78
+ return table;
79
+ }
80
+ function tableFromChunks(chunks) {
81
+ if (chunks.length === 0) {
82
+ return new apache_arrow_1.Table(new apache_arrow_1.Schema([]), []);
83
+ }
84
+ const [first, ...rest] = chunks;
85
+ return first.concat(...rest);
86
+ }
87
+ function schemaFromIPCBytes(data) {
88
+ return tableFromIPCBytes(data).schema;
89
+ }
90
+ class SqliteArrowWriteInputStream {
91
+ constructor(start, chunks, schema) {
92
+ this.start = start;
93
+ this.schema = schema;
94
+ this.pulls = [];
95
+ this.closed = false;
96
+ this.source = toAsyncArrowIterable(chunks)[Symbol.asyncIterator]();
97
+ }
98
+ requestNext() {
99
+ if (this.closed) {
100
+ return;
101
+ }
102
+ const waiter = this.pulls.shift();
103
+ if (waiter) {
104
+ waiter();
105
+ return;
106
+ }
107
+ this.pulls.push(() => undefined);
108
+ }
109
+ close() {
110
+ if (this.closed) {
111
+ return;
112
+ }
113
+ this.closed = true;
114
+ while (this.pulls.length > 0) {
115
+ const waiter = this.pulls.shift();
116
+ waiter?.();
117
+ }
118
+ void this.source.return?.();
119
+ }
120
+ async waitForPull() {
121
+ if (this.closed) {
122
+ return;
123
+ }
124
+ const waiter = this.pulls.shift();
125
+ if (waiter) {
126
+ waiter();
127
+ return;
128
+ }
129
+ await new Promise((resolve) => {
130
+ this.pulls.push(resolve);
131
+ });
132
+ }
133
+ async *stream() {
134
+ yield new response_js_1.BinaryContent({
135
+ data: this.schema == null ? new Uint8Array() : schemaToIPC(this.schema),
136
+ headers: this.start,
137
+ });
138
+ while (!this.closed) {
139
+ await this.waitForPull();
140
+ if (this.closed) {
141
+ return;
142
+ }
143
+ const nextChunk = await this.source.next();
144
+ if (nextChunk.done) {
145
+ return;
146
+ }
147
+ if (nextChunk.value.numRows === 0) {
148
+ continue;
149
+ }
150
+ yield new response_js_1.BinaryContent({
151
+ data: (0, apache_arrow_1.tableToIPC)(nextChunk.value, "stream"),
152
+ headers: { kind: "data", content_type: ARROW_IPC_STREAM_MIME_TYPE },
153
+ });
154
+ }
155
+ }
156
+ }
157
+ class SqliteArrowReadInputStream {
158
+ constructor(start) {
159
+ this.start = start;
160
+ this.pulls = [];
161
+ this.closed = false;
162
+ }
163
+ requestNext() {
164
+ if (this.closed) {
165
+ return;
166
+ }
167
+ const waiter = this.pulls.shift();
168
+ if (waiter) {
169
+ waiter();
170
+ return;
171
+ }
172
+ this.pulls.push(() => undefined);
173
+ }
174
+ close() {
175
+ if (this.closed) {
176
+ return;
177
+ }
178
+ this.closed = true;
179
+ while (this.pulls.length > 0) {
180
+ const waiter = this.pulls.shift();
181
+ waiter?.();
182
+ }
183
+ }
184
+ async waitForPull() {
185
+ if (this.closed) {
186
+ return;
187
+ }
188
+ const waiter = this.pulls.shift();
189
+ if (waiter) {
190
+ waiter();
191
+ return;
192
+ }
193
+ await new Promise((resolve) => {
194
+ this.pulls.push(resolve);
195
+ });
196
+ }
197
+ async *stream() {
198
+ yield new response_js_1.BinaryContent({ data: new Uint8Array(), headers: this.start });
199
+ while (!this.closed) {
200
+ await this.waitForPull();
201
+ if (this.closed) {
202
+ return;
203
+ }
204
+ yield new response_js_1.BinaryContent({ data: new Uint8Array(), headers: { kind: "pull" } });
205
+ }
206
+ }
207
+ }
208
+ class SqliteDatabaseClient {
209
+ constructor(client, database, namespace) {
210
+ this.client = client;
211
+ this.database = database;
212
+ this.namespace = namespace;
213
+ }
214
+ async createDatabase({ mode = "create" } = {}) {
215
+ return this.client.createDatabase({ name: this.database, namespace: this.namespace, mode });
216
+ }
217
+ async dropDatabase({ ignoreMissing = false } = {}) {
218
+ return this.client.dropDatabase({ name: this.database, namespace: this.namespace, ignoreMissing });
219
+ }
220
+ async inspectDatabase() {
221
+ return this.client.inspectDatabase({ name: this.database, namespace: this.namespace });
222
+ }
223
+ async listTables() {
224
+ return this.client.listTables({ database: this.database, namespace: this.namespace });
225
+ }
226
+ async createTableWithSchema(params) {
227
+ return this.client.createTableWithSchema({ ...params, database: this.database, namespace: this.namespace });
228
+ }
229
+ async createTableFromData(params) {
230
+ return this.client.createTableFromData({ ...params, database: this.database, namespace: this.namespace });
231
+ }
232
+ async dropTable(params) {
233
+ return this.client.dropTable({ ...params, database: this.database, namespace: this.namespace });
234
+ }
235
+ async renameTable(params) {
236
+ return this.client.renameTable({ ...params, database: this.database, namespace: this.namespace });
237
+ }
238
+ async inspect(params) {
239
+ return this.client.inspect({ ...params, database: this.database, namespace: this.namespace });
240
+ }
241
+ async addColumns(params) {
242
+ return this.client.addColumns({ ...params, database: this.database, namespace: this.namespace });
243
+ }
244
+ async dropColumns(params) {
245
+ return this.client.dropColumns({ ...params, database: this.database, namespace: this.namespace });
246
+ }
247
+ async insert(params) {
248
+ return this.client.insert({ ...params, database: this.database, namespace: this.namespace });
249
+ }
250
+ async update(params) {
251
+ return this.client.update({ ...params, database: this.database, namespace: this.namespace });
252
+ }
253
+ async delete(params) {
254
+ return this.client.delete({ ...params, database: this.database, namespace: this.namespace });
255
+ }
256
+ async search(params) {
257
+ return this.client.search({ ...params, database: this.database, namespace: this.namespace });
258
+ }
259
+ async searchTable(params) {
260
+ return this.client.searchTable({ ...params, database: this.database, namespace: this.namespace });
261
+ }
262
+ async searchStream(params) {
263
+ return this.client.searchStream({ ...params, database: this.database, namespace: this.namespace });
264
+ }
265
+ async count(params) {
266
+ return this.client.count({ ...params, database: this.database, namespace: this.namespace });
267
+ }
268
+ async sql(params) {
269
+ return this.client.sql({ ...params, database: this.database, namespace: this.namespace });
270
+ }
271
+ async sqlTable(params) {
272
+ return this.client.sqlTable({ ...params, database: this.database, namespace: this.namespace });
273
+ }
274
+ async *sqlStream(params) {
275
+ yield* this.client.sqlStream({ ...params, database: this.database, namespace: this.namespace });
276
+ }
277
+ async executeSql(params) {
278
+ return this.client.executeSql({ ...params, database: this.database, namespace: this.namespace });
279
+ }
280
+ async executeSqlStatement(params) {
281
+ return this.client.executeSqlStatement({ ...params, database: this.database, namespace: this.namespace });
282
+ }
283
+ }
284
+ exports.SqliteDatabaseClient = SqliteDatabaseClient;
285
+ class SqliteClient {
286
+ constructor({ room }) {
287
+ this.room = room;
288
+ }
289
+ unexpectedResponseError(operation) {
290
+ return new room_server_client_js_1.RoomServerException(`unexpected return type from sqlite.${operation}`);
291
+ }
292
+ database(name, { namespace } = {}) {
293
+ return new SqliteDatabaseClient(this, name, namespace);
294
+ }
295
+ async invoke(operation, input) {
296
+ return await this.room.invokeContent({ toolkit: "sqlite", tool: operation, input });
297
+ }
298
+ async invokeContent(operation, input) {
299
+ return await this.room.invokeContent({ toolkit: "sqlite", tool: operation, input });
300
+ }
301
+ async invokeStream(operation, input) {
302
+ return await this.room.invokeStream({ toolkit: "sqlite", tool: operation, input });
303
+ }
304
+ async drainWriteStream(operation, input) {
305
+ const response = await this.invokeStream(operation, input.stream());
306
+ try {
307
+ for await (const chunk of response) {
308
+ if (chunk instanceof response_js_1.ErrorContent) {
309
+ throw new room_server_client_js_1.RoomServerException(chunk.text, chunk.code);
310
+ }
311
+ if (chunk instanceof response_js_1.ControlContent) {
312
+ if (chunk.method === "close") {
313
+ return;
314
+ }
315
+ throw this.unexpectedResponseError(operation);
316
+ }
317
+ if (!(chunk instanceof response_js_1.BinaryContent) || chunk.headers.kind !== "pull") {
318
+ throw this.unexpectedResponseError(operation);
319
+ }
320
+ input.requestNext();
321
+ }
322
+ }
323
+ finally {
324
+ input.close();
325
+ }
326
+ }
327
+ async *streamArrow(operation, start) {
328
+ const input = new SqliteArrowReadInputStream(start);
329
+ const response = await this.invokeStream(operation, input.stream());
330
+ input.requestNext();
331
+ try {
332
+ for await (const chunk of response) {
333
+ if (chunk instanceof response_js_1.ErrorContent) {
334
+ throw new room_server_client_js_1.RoomServerException(chunk.text, chunk.code);
335
+ }
336
+ if (chunk instanceof response_js_1.ControlContent) {
337
+ if (chunk.method === "close") {
338
+ return;
339
+ }
340
+ throw this.unexpectedResponseError(operation);
341
+ }
342
+ if (!(chunk instanceof response_js_1.BinaryContent) || chunk.headers.kind !== "data") {
343
+ throw this.unexpectedResponseError(operation);
344
+ }
345
+ yield tableFromIPCBytes(chunk.data);
346
+ input.requestNext();
347
+ }
348
+ }
349
+ finally {
350
+ input.close();
351
+ }
352
+ }
353
+ async listDatabases({ namespace } = {}) {
354
+ const response = await this.invoke("list_databases", { namespace: namespace ?? null });
355
+ if (!(response instanceof response_js_1.JsonContent) || !Array.isArray(response.json.databases)) {
356
+ throw this.unexpectedResponseError("list_databases");
357
+ }
358
+ return response.json.databases;
359
+ }
360
+ async createDatabase({ name, namespace, mode = "create" }) {
361
+ const response = await this.invoke("create_database", { name, namespace: namespace ?? null, mode });
362
+ if (!(response instanceof response_js_1.EmptyContent)) {
363
+ throw this.unexpectedResponseError("create_database");
364
+ }
365
+ }
366
+ async dropDatabase({ name, namespace, ignoreMissing = false }) {
367
+ const response = await this.invoke("drop_database", { name, namespace: namespace ?? null, ignore_missing: ignoreMissing });
368
+ if (!(response instanceof response_js_1.EmptyContent)) {
369
+ throw this.unexpectedResponseError("drop_database");
370
+ }
371
+ }
372
+ async inspectDatabase({ name, namespace }) {
373
+ const response = await this.invoke("inspect_database", { name, namespace: namespace ?? null });
374
+ if (!(response instanceof response_js_1.JsonContent) || typeof response.json.name !== "string" || typeof response.json.tables !== "number") {
375
+ throw this.unexpectedResponseError("inspect_database");
376
+ }
377
+ return {
378
+ name: response.json.name,
379
+ namespace: Array.isArray(response.json.namespace) ? response.json.namespace : null,
380
+ tables: response.json.tables,
381
+ sizeBytes: typeof response.json.size_bytes === "number" ? response.json.size_bytes : 0,
382
+ };
383
+ }
384
+ async listTables({ database, namespace }) {
385
+ const response = await this.invoke("list_tables", { database, namespace: namespace ?? null });
386
+ if (!(response instanceof response_js_1.JsonContent) || !Array.isArray(response.json.tables)) {
387
+ throw this.unexpectedResponseError("list_tables");
388
+ }
389
+ return response.json.tables;
390
+ }
391
+ async createTable({ database, name, data, schema, mode = "create", namespace, }) {
392
+ const input = new SqliteArrowWriteInputStream({
393
+ kind: "start",
394
+ database,
395
+ name,
396
+ mode,
397
+ namespace: namespace ?? null,
398
+ }, data ?? [], schema);
399
+ await this.drainWriteStream("create_table", input);
400
+ }
401
+ async createTableWithSchema({ database, name, schema, data, mode = "create", namespace }) {
402
+ return this.createTable({
403
+ database,
404
+ name,
405
+ schema,
406
+ data: data == null ? undefined : data instanceof apache_arrow_1.Table ? [data] : data,
407
+ mode,
408
+ namespace,
409
+ });
410
+ }
411
+ async createTableFromData({ database, name, data, mode = "create", namespace }) {
412
+ return this.createTable({
413
+ database,
414
+ name,
415
+ data: data == null ? undefined : data instanceof apache_arrow_1.Table ? [data] : data,
416
+ mode,
417
+ namespace,
418
+ });
419
+ }
420
+ async dropTable({ database, name, ignoreMissing = false, namespace }) {
421
+ const response = await this.invoke("drop_table", { database, name, ignore_missing: ignoreMissing, namespace: namespace ?? null });
422
+ if (!(response instanceof response_js_1.EmptyContent)) {
423
+ throw this.unexpectedResponseError("drop_table");
424
+ }
425
+ }
426
+ async renameTable({ database, name, newName, namespace }) {
427
+ const response = await this.invoke("rename_table", { database, name, new_name: newName, namespace: namespace ?? null });
428
+ if (!(response instanceof response_js_1.EmptyContent)) {
429
+ throw this.unexpectedResponseError("rename_table");
430
+ }
431
+ }
432
+ async inspect({ database, table, namespace }) {
433
+ const response = await this.invoke("inspect", { database, table, namespace: namespace ?? null });
434
+ if (!(response instanceof response_js_1.BinaryContent)) {
435
+ throw this.unexpectedResponseError("inspect");
436
+ }
437
+ return schemaFromIPCBytes(response.data);
438
+ }
439
+ async addColumns({ database, table, newColumns, namespace }) {
440
+ const response = await this.invokeContent("add_columns", new response_js_1.BinaryContent({
441
+ data: schemaToIPC(newColumns),
442
+ headers: {
443
+ database,
444
+ table,
445
+ namespace: namespace ?? null,
446
+ content_type: ARROW_IPC_STREAM_MIME_TYPE,
447
+ },
448
+ }));
449
+ if (!(response instanceof response_js_1.EmptyContent)) {
450
+ throw this.unexpectedResponseError("add_columns");
451
+ }
452
+ }
453
+ async dropColumns({ database, table, columns, namespace }) {
454
+ const response = await this.invoke("drop_columns", { database, table, columns, namespace: namespace ?? null });
455
+ if (!(response instanceof response_js_1.EmptyContent)) {
456
+ throw this.unexpectedResponseError("drop_columns");
457
+ }
458
+ }
459
+ async insert({ database, table, records, namespace }) {
460
+ await this.insertStream({ database, table, chunks: [records], namespace });
461
+ }
462
+ async insertStream({ database, table, chunks, namespace }) {
463
+ const input = new SqliteArrowWriteInputStream({
464
+ kind: "start",
465
+ database,
466
+ table,
467
+ namespace: namespace ?? null,
468
+ }, chunks);
469
+ await this.drainWriteStream("insert", input);
470
+ }
471
+ async update({ database, table, where, values, params, namespace }) {
472
+ const response = await this.invoke("update", {
473
+ database,
474
+ table,
475
+ where,
476
+ values: Object.entries(values).map(([column, value]) => ({ column, value_json: JSON.stringify(encodeRecordValue(value)) })),
477
+ params: params ?? null,
478
+ namespace: namespace ?? null,
479
+ });
480
+ if (!(response instanceof response_js_1.JsonContent) || typeof response.json.rows_affected !== "number") {
481
+ throw this.unexpectedResponseError("update");
482
+ }
483
+ return response.json.rows_affected;
484
+ }
485
+ async delete({ database, table, where, params, namespace }) {
486
+ const response = await this.invoke("delete", { database, table, where, params: params ?? null, namespace: namespace ?? null });
487
+ if (!(response instanceof response_js_1.JsonContent) || typeof response.json.rows_affected !== "number") {
488
+ throw this.unexpectedResponseError("delete");
489
+ }
490
+ return response.json.rows_affected;
491
+ }
492
+ async search({ database, table, where, params, offset, limit, select, namespace }) {
493
+ const results = [];
494
+ for await (const chunk of this.searchStream({ database, table, where, params, offset, limit, select, namespace })) {
495
+ results.push(chunk);
496
+ }
497
+ return results;
498
+ }
499
+ async searchTable({ database, table, where, params, offset, limit, select, namespace }) {
500
+ return tableFromChunks(await this.search({ database, table, where, params, offset, limit, select, namespace }));
501
+ }
502
+ async *searchStream({ database, table, where, params, offset, limit, select, namespace }) {
503
+ yield* this.streamArrow("search", {
504
+ kind: "start",
505
+ database,
506
+ table,
507
+ where: buildWhereClause(where),
508
+ params: params ?? null,
509
+ offset: offset ?? null,
510
+ limit: limit ?? null,
511
+ select: select ?? null,
512
+ namespace: namespace ?? null,
513
+ });
514
+ }
515
+ async count({ database, table, where, params, namespace }) {
516
+ const response = await this.invoke("count", {
517
+ database,
518
+ table,
519
+ where: buildWhereClause(where),
520
+ params: params ?? null,
521
+ namespace: namespace ?? null,
522
+ });
523
+ if (!(response instanceof response_js_1.JsonContent) || typeof response.json.count !== "number" || !Number.isInteger(response.json.count)) {
524
+ throw this.unexpectedResponseError("count");
525
+ }
526
+ return response.json.count;
527
+ }
528
+ async sql({ database, query, params, namespace }) {
529
+ const results = [];
530
+ for await (const chunk of this.sqlStream({ database, query, params, namespace })) {
531
+ results.push(chunk);
532
+ }
533
+ return results;
534
+ }
535
+ async sqlTable({ database, query, params, namespace }) {
536
+ return tableFromChunks(await this.sql({ database, query, params, namespace }));
537
+ }
538
+ async openSqlQuery({ database, query, params, namespace }) {
539
+ const response = await this.invokeContent("open_sql_query", new response_js_1.BinaryContent({
540
+ data: new Uint8Array(),
541
+ headers: { database, query, params: params ?? null, namespace: namespace ?? null },
542
+ }));
543
+ if (!(response instanceof response_js_1.BinaryContent)) {
544
+ throw this.unexpectedResponseError("open_sql_query");
545
+ }
546
+ const queryId = response.headers.query_id;
547
+ if (typeof queryId !== "string" || queryId === "") {
548
+ throw this.unexpectedResponseError("open_sql_query");
549
+ }
550
+ return {
551
+ schema: schemaFromIPCBytes(response.data),
552
+ kind: "query",
553
+ queryId,
554
+ };
555
+ }
556
+ async executeSql({ database, query, params, namespace }) {
557
+ const response = await this.invokeContent("execute_sql", new response_js_1.BinaryContent({
558
+ data: new Uint8Array(),
559
+ headers: { database, query, params: params ?? null, namespace: namespace ?? null },
560
+ }));
561
+ if (response instanceof response_js_1.BinaryContent) {
562
+ if (response.headers.kind !== "query") {
563
+ throw this.unexpectedResponseError("execute_sql");
564
+ }
565
+ const queryId = response.headers.query_id;
566
+ if (typeof queryId !== "string" || queryId === "") {
567
+ throw this.unexpectedResponseError("execute_sql");
568
+ }
569
+ return {
570
+ kind: "query",
571
+ schema: schemaFromIPCBytes(response.data),
572
+ queryId,
573
+ };
574
+ }
575
+ if (response instanceof response_js_1.JsonContent) {
576
+ if (response.json.kind !== "statement"
577
+ || typeof response.json.rows_affected !== "number"
578
+ || !Number.isInteger(response.json.rows_affected)) {
579
+ throw this.unexpectedResponseError("execute_sql");
580
+ }
581
+ return {
582
+ kind: "statement",
583
+ rowsAffected: response.json.rows_affected,
584
+ };
585
+ }
586
+ throw this.unexpectedResponseError("execute_sql");
587
+ }
588
+ async *sqlStream({ database, query, params, namespace }) {
589
+ const result = await this.executeSql({ database, query, params, namespace });
590
+ if (result.kind === "statement") {
591
+ throw new room_server_client_js_1.RoomServerException(`SQL statement did not return rows; rows_affected=${result.rowsAffected}`);
592
+ }
593
+ try {
594
+ yield* this.readSqlQuery({ queryId: result.queryId });
595
+ }
596
+ finally {
597
+ await this.closeSqlQuery({ queryId: result.queryId });
598
+ }
599
+ }
600
+ async *readSqlQuery({ queryId }) {
601
+ yield* this.streamArrow("read_sql_query", { kind: "start", query_id: queryId });
602
+ }
603
+ async closeSqlQuery({ queryId }) {
604
+ const response = await this.invoke("close_sql_query", { query_id: queryId });
605
+ if (!(response instanceof response_js_1.EmptyContent)) {
606
+ throw this.unexpectedResponseError("close_sql_query");
607
+ }
608
+ }
609
+ async cancelSqlQuery({ queryId }) {
610
+ const response = await this.invoke("cancel_sql_query", { query_id: queryId });
611
+ if (!(response instanceof response_js_1.JsonContent)
612
+ || !["cancelled", "cancelling", "not_cancellable"].includes(response.json.status)) {
613
+ throw this.unexpectedResponseError("cancel_sql_query");
614
+ }
615
+ return { status: response.json.status };
616
+ }
617
+ async executeSqlStatement({ database, query, params, namespace }) {
618
+ const response = await this.invokeContent("execute_sql_statement", new response_js_1.BinaryContent({
619
+ data: new Uint8Array(),
620
+ headers: { database, query, params: params ?? null, namespace: namespace ?? null },
621
+ }));
622
+ if (!(response instanceof response_js_1.JsonContent)
623
+ || typeof response.json.rows_affected !== "number"
624
+ || !Number.isInteger(response.json.rows_affected)) {
625
+ throw this.unexpectedResponseError("execute_sql_statement");
626
+ }
627
+ return response.json.rows_affected;
628
+ }
629
+ }
630
+ exports.SqliteClient = SqliteClient;
@@ -12,6 +12,11 @@ export declare class MCPHeader {
12
12
  toJson(): Record<string, string>;
13
13
  }
14
14
  export type MCPRequireApproval = "always" | "never";
15
+ export interface MeshagentProxyConfig {
16
+ apiUrl: string;
17
+ apiKey: string;
18
+ user?: string | null;
19
+ }
15
20
  export declare class MCPServer {
16
21
  readonly serverLabel: string;
17
22
  readonly authorization?: string;
@@ -67,9 +72,10 @@ export declare class Connector {
67
72
  isConnected(room: RoomClient, agentName: string): Promise<boolean>;
68
73
  authenticate(client: RoomClient, agent: RemoteParticipant, redirectUri: string | URL): Promise<string | null>;
69
74
  }
70
- export declare function mcpConnectorsFromRoomServices({ services, agentName, }: {
75
+ export declare function mcpConnectorsFromRoomServices({ services, agentName, meshagentProxyConfig, }: {
71
76
  services: Iterable<ServiceSpec>;
72
77
  agentName?: string | null;
78
+ meshagentProxyConfig?: MeshagentProxyConfig | null;
73
79
  }): Connector[];
74
80
  export declare class OpenAIConnectors {
75
81
  static readonly dropbox: Connector;