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