@bobannomi/app-host 0.1.1 → 0.2.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/README.md +16 -11
- package/dist/index.d.ts +281 -166
- package/dist/index.js +317 -152
- package/dist/index.js.map +3 -3
- package/dist/protocol.d.ts +264 -317
- package/dist/protocol.js +201 -276
- package/dist/protocol.js.map +3 -3
- package/package.json +4 -9
- package/dist/node/service-host.d.ts +0 -1447
- package/dist/node/service-host.js +0 -1408
- package/dist/node/service-host.js.map +0 -6
package/dist/index.js
CHANGED
|
@@ -19,7 +19,9 @@ var APP_HOST_ERROR_RETRY = {
|
|
|
19
19
|
root_changed: "never",
|
|
20
20
|
resource_revision_conflict: "query",
|
|
21
21
|
request_conflict: "never",
|
|
22
|
-
cursor_stale: "query"
|
|
22
|
+
cursor_stale: "query",
|
|
23
|
+
model_provider_not_configured: "never",
|
|
24
|
+
model_not_configured: "never"
|
|
23
25
|
};
|
|
24
26
|
var HOST_REQUEST_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
25
27
|
function isSafeErrorDetails(value, depth = 0) {
|
|
@@ -45,6 +47,8 @@ function isAppHostErrorInfo(value) {
|
|
|
45
47
|
}
|
|
46
48
|
function appHostErrorMessage(code, details) {
|
|
47
49
|
const reason = details && typeof details === "object" && !Array.isArray(details) ? details.reason : void 0;
|
|
50
|
+
if (code === "model_provider_not_configured") return "\u8BF7\u5148\u914D\u7F6E\u6240\u9009\u4F9B\u5E94\u5546\u7684\u8FDE\u63A5\u3002";
|
|
51
|
+
if (code === "model_not_configured") return "\u8BF7\u5728\u4F9B\u5E94\u5546\u914D\u7F6E\u4E2D\u4FDD\u5B58\u6240\u9009\u6A21\u578B\u3002";
|
|
48
52
|
if (code === "host_unavailable") {
|
|
49
53
|
switch (reason) {
|
|
50
54
|
case "host_port_timeout":
|
|
@@ -114,7 +118,7 @@ var AppHostError = class extends Error {
|
|
|
114
118
|
};
|
|
115
119
|
|
|
116
120
|
// ../domain-contracts/src/app-host/wire-validation.ts
|
|
117
|
-
var text = (max = 1024,
|
|
121
|
+
var text = (max = 1024, empty3 = false) => (v) => typeof v === "string" && (empty3 || v.length > 0) && new TextEncoder().encode(v).byteLength <= max;
|
|
118
122
|
var id = (v) => typeof v === "string" && HOST_REQUEST_ID.test(v);
|
|
119
123
|
var count = (v) => typeof v === "number" && Number.isSafeInteger(v) && v >= 0;
|
|
120
124
|
var bool = (v) => typeof v === "boolean";
|
|
@@ -183,87 +187,6 @@ function validConnection(v) {
|
|
|
183
187
|
return wireConnection(v) && /^[A-Za-z0-9-]+$/.test(v.connectionId) && v.baseUrl === `https://app-host.invalid/connections/${v.connectionId}`;
|
|
184
188
|
}
|
|
185
189
|
|
|
186
|
-
// ../domain-contracts/src/app-host/service.ts
|
|
187
|
-
function fields(value, required, optional = []) {
|
|
188
|
-
if (!value || typeof value !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(value)))
|
|
189
|
-
return false;
|
|
190
|
-
return required.every((k) => Object.hasOwn(value, k)) && Reflect.ownKeys(value).every((k) => {
|
|
191
|
-
const d = Object.getOwnPropertyDescriptor(value, k);
|
|
192
|
-
return typeof k === "string" && [...required, ...optional].includes(k) && d.enumerable && Object.hasOwn(d, "value");
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
var version = (v) => typeof v === "string" && /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*)?(?:\+[\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*)?$/.test(
|
|
196
|
-
v
|
|
197
|
-
);
|
|
198
|
-
function json2(value, ancestors = /* @__PURE__ */ new Set(), depth = 0) {
|
|
199
|
-
if (depth > 100) return false;
|
|
200
|
-
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
201
|
-
return true;
|
|
202
|
-
if (typeof value === "number") return Number.isFinite(value);
|
|
203
|
-
if (typeof value !== "object" || ancestors.has(value)) return false;
|
|
204
|
-
const array2 = Array.isArray(value);
|
|
205
|
-
if (array2 ? Object.getPrototypeOf(value) !== Array.prototype || Reflect.ownKeys(value).length !== value.length + 1 : ![Object.prototype, null].includes(Object.getPrototypeOf(value)))
|
|
206
|
-
return false;
|
|
207
|
-
ancestors.add(value);
|
|
208
|
-
const result = Reflect.ownKeys(value).every((k) => {
|
|
209
|
-
if (array2 && k === "length") return true;
|
|
210
|
-
const d = Object.getOwnPropertyDescriptor(value, k);
|
|
211
|
-
return typeof k === "string" && (!array2 || /^(0|[1-9]\d*)$/.test(k) && Number(k) < value.length) && d.enumerable && Object.hasOwn(d, "value") && json2(d.value, ancestors, depth + 1);
|
|
212
|
-
});
|
|
213
|
-
ancestors.delete(value);
|
|
214
|
-
return result;
|
|
215
|
-
}
|
|
216
|
-
function validServiceStatus(value) {
|
|
217
|
-
return fields(value, ["state"], ["reason", "instanceId", "apiVersion"]) && [
|
|
218
|
-
"absent",
|
|
219
|
-
"unauthorized",
|
|
220
|
-
"stopped",
|
|
221
|
-
"starting",
|
|
222
|
-
"recovering",
|
|
223
|
-
"ready",
|
|
224
|
-
"failed"
|
|
225
|
-
].includes(value.state) && (!Object.hasOwn(value, "reason") || [
|
|
226
|
-
"dependency_missing",
|
|
227
|
-
"service_start_failed",
|
|
228
|
-
"service_unavailable",
|
|
229
|
-
"result_unknown",
|
|
230
|
-
"incompatible",
|
|
231
|
-
"revoked"
|
|
232
|
-
].includes(value.reason)) && (!Object.hasOwn(value, "instanceId") || typeof value.instanceId === "string" && HOST_REQUEST_ID.test(value.instanceId)) && (!Object.hasOwn(value, "apiVersion") || version(value.apiVersion)) && (value.state !== "ready" || Object.hasOwn(value, "instanceId") && Object.hasOwn(value, "apiVersion"));
|
|
233
|
-
}
|
|
234
|
-
function validWork(value) {
|
|
235
|
-
return fields(value, ["requestId", "state", "updatedAt"], ["result", "error"]) && typeof value.requestId === "string" && HOST_REQUEST_ID.test(value.requestId) && [
|
|
236
|
-
"not_accepted",
|
|
237
|
-
"accepted",
|
|
238
|
-
"running",
|
|
239
|
-
"completed",
|
|
240
|
-
"failed",
|
|
241
|
-
"interrupted",
|
|
242
|
-
"unknown"
|
|
243
|
-
].includes(value.state) && typeof value.updatedAt === "string" && /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?(?:Z|[+-]\d\d:\d\d)$/.test(
|
|
244
|
-
value.updatedAt
|
|
245
|
-
) && Number.isFinite(Date.parse(value.updatedAt)) && ["result", "error"].every(
|
|
246
|
-
(k) => !Object.hasOwn(value, k) || json2(value[k]) && new TextEncoder().encode(JSON.stringify(value[k])).length <= 16384
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
function validServiceResult(method, value) {
|
|
250
|
-
switch (method) {
|
|
251
|
-
case "service.getStatus":
|
|
252
|
-
return validServiceStatus(value);
|
|
253
|
-
case "service.getConnection":
|
|
254
|
-
return fields(value, ["connectionId", "baseUrl", "apiVersion"]) && typeof value.connectionId === "string" && /^[A-Za-z0-9-]+$/.test(value.connectionId) && value.baseUrl === `https://app-host.invalid/connections/${value.connectionId}` && version(value.apiVersion);
|
|
255
|
-
case "service.getWork":
|
|
256
|
-
return validWork(value);
|
|
257
|
-
case "service.listWork":
|
|
258
|
-
return Array.isArray(value) && value.length <= 5120 && value.every(validWork) && new Set(value.map((w) => w.requestId)).size === value.length;
|
|
259
|
-
case "service.interruptWork":
|
|
260
|
-
return fields(value, ["requested"]) && typeof value.requested === "boolean";
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
function validServiceConnectionInput(value) {
|
|
264
|
-
return fields(value, ["apiRange"]) && typeof value.apiRange === "string" && !!value.apiRange.trim() && value.apiRange.length <= 256;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
190
|
// ../domain-contracts/src/app-host/fetch.ts
|
|
268
191
|
var APP_HOST_FEATURES = [
|
|
269
192
|
"fetch-v1",
|
|
@@ -379,17 +302,12 @@ function pageFetchPath(baseUrl, input) {
|
|
|
379
302
|
const rawPath = input.replace(/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^/]+/, "").split("?")[0];
|
|
380
303
|
if (rawPath.includes("//") || /%(?:2e|2f|5c|25)/i.test(rawPath) || rawPath.split("/").some((p) => p === "." || p === "..") || /[\u0000-\u001f\u007f]/.test(decodeURIComponent(rawPath)))
|
|
381
304
|
throw new TypeError("Ambiguous fetch path");
|
|
382
|
-
const base = new URL(baseUrl),
|
|
383
|
-
if (base.protocol !== "https:" || base.hostname !== "app-host.invalid" || base.username || base.password || base.search || base.hash ||
|
|
305
|
+
const base = new URL(baseUrl), url2 = new URL(input);
|
|
306
|
+
if (base.protocol !== "https:" || base.hostname !== "app-host.invalid" || base.username || base.password || base.search || base.hash || url2.origin !== base.origin || url2.username || url2.password || url2.hash || url2.pathname !== base.pathname && !url2.pathname.startsWith(base.pathname + "/"))
|
|
384
307
|
throw new TypeError("Fetch target mismatch");
|
|
385
|
-
return (
|
|
308
|
+
return (url2.pathname.slice(base.pathname.length) || "/") + url2.search;
|
|
386
309
|
}
|
|
387
310
|
|
|
388
|
-
// ../domain-contracts/src/app-host/service-host-protocol.ts
|
|
389
|
-
var SERVICE_HOST_MAX_FRAME_BYTES = 512 * 1024;
|
|
390
|
-
var worktreeBody = { workspaceId: id, expectedHead: text(256), branch: text(1024) };
|
|
391
|
-
var worktreeReceipt = object({ requestId: id, state: enumeration("accepted", "completed", "failed", "unknown") }, { result: object({ executionRoot: id, workspaceId: id, branch: text(1024), sourceHead: text(256) }) });
|
|
392
|
-
|
|
393
311
|
// ../domain-contracts/src/app-host/workspace-conversations.ts
|
|
394
312
|
var validWorkspaceConversation = (value) => {
|
|
395
313
|
if (!object(
|
|
@@ -428,7 +346,6 @@ var workspaceConversationResult = object({
|
|
|
428
346
|
revision: count,
|
|
429
347
|
session: sessionRecord,
|
|
430
348
|
operationState: enumeration("prepared", "running", "completed", "failed", "unknown"),
|
|
431
|
-
indexBindingPending: (v) => v === true,
|
|
432
349
|
workspaceId: id,
|
|
433
350
|
executionRoot: id,
|
|
434
351
|
privateSessionId: id,
|
|
@@ -459,7 +376,6 @@ function validSessionControlInput(method, value) {
|
|
|
459
376
|
const target2 = value;
|
|
460
377
|
return target2.workspaceId !== void 0 ? target2.outsideProject !== true : target2.outsideProject === true;
|
|
461
378
|
}
|
|
462
|
-
if (method === "sessions.bindConversationIndex") return object({ original: validWorkspaceConversation, dataScopeId: text() })(value);
|
|
463
379
|
if (method === "sessions.createConversation" || method === "sessions.getConversationCreationResult") return validWorkspaceConversation(value);
|
|
464
380
|
if (method === "sessions.getControls") return object({ connectionId: text(), sessionId: text() })(value);
|
|
465
381
|
if (!object({ requestId: id, sessionId: text(), original: validSessionControlOriginal }, { connectionId: text() })(value)) return false;
|
|
@@ -469,15 +385,95 @@ function validSessionControlInput(method, value) {
|
|
|
469
385
|
function validSessionControlResult(method, value) {
|
|
470
386
|
if (!json(value)) return false;
|
|
471
387
|
if (method === "sessions.getDraftComposerOptions") return object({ source: enumeration("instance"), optionsRevision: text(), skills: array(object({ id: text(), name: text(), path: text(4096, true) }, { source: enumeration("bundled", "user", "project", "plugin") }), 128), plugins: array(object({ id: text(), name: text(), agents: array(option, 128) }), 128) })(value);
|
|
472
|
-
if (method === "sessions.bindConversationIndex") return validWorkspaceConversationResult(value);
|
|
473
388
|
if (method === "sessions.createConversation" || method === "sessions.getConversationCreationResult")
|
|
474
389
|
return method === "sessions.getConversationCreationResult" && value === null || validWorkspaceConversationResult(value);
|
|
475
|
-
if (method === "sessions.getControls") return object({ dataScopeId: text(), sessionId: text(), source: enumeration("instance", "auxiliary", "im"), revision: count, optionsRevision: text(), actions: object(Object.fromEntries(["readContext", "configure", "compact", "edit", "fork", "resume", "goalRead", "goalWrite", "goalStop"].map((k) => [k, bool]))), models: choices, roles: choices, efforts: effortChoices, workModes: choices, skills: array(object({ id: text(), name: text(), path: text(4096, true) }, { source: enumeration("bundled", "user", "project", "plugin") })), commands: choices, contexts: choices }, { permissionModes: array(option, 128),
|
|
390
|
+
if (method === "sessions.getControls") return object({ dataScopeId: text(), sessionId: text(), source: enumeration("instance", "auxiliary", "im"), revision: count, optionsRevision: text(), actions: object(Object.fromEntries(["readContext", "configure", "compact", "edit", "fork", "resume", "goalRead", "goalWrite", "goalStop"].map((k) => [k, bool]))), models: choices, roles: choices, efforts: effortChoices, workModes: choices, skills: array(object({ id: text(), name: text(), path: text(4096, true) }, { source: enumeration("bundled", "user", "project", "plugin") })), commands: choices, contexts: choices }, { permissionModes: array(option, 128), plugins: array(object({ id: text(), name: text(), agents: choices })) })(value);
|
|
476
391
|
if (method === "sessions.getControlResult") return value === null || receipt(value);
|
|
477
392
|
if (!receipt(value)) return false;
|
|
478
393
|
return false;
|
|
479
394
|
}
|
|
480
395
|
|
|
396
|
+
// ../domain-contracts/src/app-host/service.ts
|
|
397
|
+
function fields(value, required, optional = []) {
|
|
398
|
+
if (!value || typeof value !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(value)))
|
|
399
|
+
return false;
|
|
400
|
+
return required.every((k) => Object.hasOwn(value, k)) && Reflect.ownKeys(value).every((k) => {
|
|
401
|
+
const d = Object.getOwnPropertyDescriptor(value, k);
|
|
402
|
+
return typeof k === "string" && [...required, ...optional].includes(k) && d.enumerable && Object.hasOwn(d, "value");
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
var version = (v) => typeof v === "string" && /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*)?(?:\+[\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*)?$/.test(
|
|
406
|
+
v
|
|
407
|
+
);
|
|
408
|
+
function json2(value, ancestors = /* @__PURE__ */ new Set(), depth = 0) {
|
|
409
|
+
if (depth > 100) return false;
|
|
410
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
411
|
+
return true;
|
|
412
|
+
if (typeof value === "number") return Number.isFinite(value);
|
|
413
|
+
if (typeof value !== "object" || ancestors.has(value)) return false;
|
|
414
|
+
const array2 = Array.isArray(value);
|
|
415
|
+
if (array2 ? Object.getPrototypeOf(value) !== Array.prototype || Reflect.ownKeys(value).length !== value.length + 1 : ![Object.prototype, null].includes(Object.getPrototypeOf(value)))
|
|
416
|
+
return false;
|
|
417
|
+
ancestors.add(value);
|
|
418
|
+
const result = Reflect.ownKeys(value).every((k) => {
|
|
419
|
+
if (array2 && k === "length") return true;
|
|
420
|
+
const d = Object.getOwnPropertyDescriptor(value, k);
|
|
421
|
+
return typeof k === "string" && (!array2 || /^(0|[1-9]\d*)$/.test(k) && Number(k) < value.length) && d.enumerable && Object.hasOwn(d, "value") && json2(d.value, ancestors, depth + 1);
|
|
422
|
+
});
|
|
423
|
+
ancestors.delete(value);
|
|
424
|
+
return result;
|
|
425
|
+
}
|
|
426
|
+
function validServiceStatus(value) {
|
|
427
|
+
return fields(value, ["state"], ["reason", "instanceId", "apiVersion"]) && [
|
|
428
|
+
"absent",
|
|
429
|
+
"unauthorized",
|
|
430
|
+
"stopped",
|
|
431
|
+
"starting",
|
|
432
|
+
"recovering",
|
|
433
|
+
"ready",
|
|
434
|
+
"failed"
|
|
435
|
+
].includes(value.state) && (!Object.hasOwn(value, "reason") || [
|
|
436
|
+
"dependency_missing",
|
|
437
|
+
"service_start_failed",
|
|
438
|
+
"service_unavailable",
|
|
439
|
+
"result_unknown",
|
|
440
|
+
"incompatible",
|
|
441
|
+
"revoked"
|
|
442
|
+
].includes(value.reason)) && (!Object.hasOwn(value, "instanceId") || typeof value.instanceId === "string" && HOST_REQUEST_ID.test(value.instanceId)) && (!Object.hasOwn(value, "apiVersion") || version(value.apiVersion)) && (value.state !== "ready" || Object.hasOwn(value, "instanceId") && Object.hasOwn(value, "apiVersion"));
|
|
443
|
+
}
|
|
444
|
+
function validWork(value) {
|
|
445
|
+
return fields(value, ["requestId", "state", "updatedAt"], ["result", "error"]) && typeof value.requestId === "string" && HOST_REQUEST_ID.test(value.requestId) && [
|
|
446
|
+
"not_accepted",
|
|
447
|
+
"accepted",
|
|
448
|
+
"running",
|
|
449
|
+
"completed",
|
|
450
|
+
"failed",
|
|
451
|
+
"interrupted",
|
|
452
|
+
"unknown"
|
|
453
|
+
].includes(value.state) && typeof value.updatedAt === "string" && /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?(?:Z|[+-]\d\d:\d\d)$/.test(
|
|
454
|
+
value.updatedAt
|
|
455
|
+
) && Number.isFinite(Date.parse(value.updatedAt)) && ["result", "error"].every(
|
|
456
|
+
(k) => !Object.hasOwn(value, k) || json2(value[k]) && new TextEncoder().encode(JSON.stringify(value[k])).length <= 16384
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
function validServiceResult(method, value) {
|
|
460
|
+
switch (method) {
|
|
461
|
+
case "service.getStatus":
|
|
462
|
+
return validServiceStatus(value);
|
|
463
|
+
case "service.getConnection":
|
|
464
|
+
return fields(value, ["connectionId", "baseUrl", "apiVersion"]) && typeof value.connectionId === "string" && /^[A-Za-z0-9-]+$/.test(value.connectionId) && value.baseUrl === `https://app-host.invalid/connections/${value.connectionId}` && version(value.apiVersion);
|
|
465
|
+
case "service.getWork":
|
|
466
|
+
return validWork(value);
|
|
467
|
+
case "service.listWork":
|
|
468
|
+
return Array.isArray(value) && value.length <= 5120 && value.every(validWork) && new Set(value.map((w) => w.requestId)).size === value.length;
|
|
469
|
+
case "service.interruptWork":
|
|
470
|
+
return fields(value, ["requested"]) && typeof value.requested === "boolean";
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
function validServiceConnectionInput(value) {
|
|
474
|
+
return fields(value, ["apiRange"]) && typeof value.apiRange === "string" && !!value.apiRange.trim() && value.apiRange.length <= 256;
|
|
475
|
+
}
|
|
476
|
+
|
|
481
477
|
// ../domain-contracts/src/app-host/workspace.ts
|
|
482
478
|
function fields2(v, required, optional = []) {
|
|
483
479
|
if (!v || typeof v !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(v))) return false;
|
|
@@ -750,8 +746,7 @@ function createResourceCatalogApi(rpc) {
|
|
|
750
746
|
// src/session-controls.ts
|
|
751
747
|
var CONVERSATION_PREPARATION_METHODS = [
|
|
752
748
|
"sessions.createConversation",
|
|
753
|
-
"sessions.getConversationCreationResult"
|
|
754
|
-
"sessions.bindConversationIndex"
|
|
749
|
+
"sessions.getConversationCreationResult"
|
|
755
750
|
];
|
|
756
751
|
function isConversationPreparationMethod(method) {
|
|
757
752
|
return CONVERSATION_PREPARATION_METHODS.includes(method);
|
|
@@ -766,13 +761,8 @@ function createConversationPreparationApi(rpc) {
|
|
|
766
761
|
return rpc.request(method, input);
|
|
767
762
|
};
|
|
768
763
|
return {
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
async bindConversationIndex(input) {
|
|
772
|
-
const result = await call("sessions.bindConversationIndex", input);
|
|
773
|
-
if (result.dataScopeId !== input.dataScopeId || result.sessionId !== input.original.sessionId || result.requestId !== input.original.requestId || result.state !== "completed") throw new AppHostError("host_unavailable");
|
|
774
|
-
return result;
|
|
775
|
-
}
|
|
764
|
+
create: (input) => call("sessions.createConversation", input),
|
|
765
|
+
getResult: (input) => call("sessions.getConversationCreationResult", input)
|
|
776
766
|
};
|
|
777
767
|
}
|
|
778
768
|
|
|
@@ -799,10 +789,23 @@ function resolveClientConnection(connection, owner) {
|
|
|
799
789
|
|
|
800
790
|
// src/desktop.ts
|
|
801
791
|
var BROWSER_CAPTURE_PREVIEW_MAX_BYTES = 8 * 1024 * 1024;
|
|
792
|
+
var DESKTOP_ADAPTED_METHODS = ["desktop.files.openRead", "desktop.files.getOperation"];
|
|
802
793
|
var target = { targetId: text(256) };
|
|
803
794
|
var mount = { ...target, mountId: text(256) };
|
|
804
795
|
var source = object({ sessionId: text(), appId: text() });
|
|
805
796
|
var action = { ...mount, source, requestId: id, expectedRevision: count };
|
|
797
|
+
var fileWriteBody = { path: text(32768), expectedSha256: digest, text: text(8 * 1024 * 1024, true) };
|
|
798
|
+
var gitBranchBody = { expectedHead: text(), branch: text() };
|
|
799
|
+
var validFileOperationQuery = object({
|
|
800
|
+
...target,
|
|
801
|
+
requestId: id,
|
|
802
|
+
original: object({ kind: enumeration("files.writeText"), body: object(fileWriteBody) })
|
|
803
|
+
});
|
|
804
|
+
var validGitOperationQuery = object({
|
|
805
|
+
...target,
|
|
806
|
+
requestId: id,
|
|
807
|
+
original: object({ kind: enumeration("git.switchBranch", "git.createBranch"), body: object(gitBranchBody) })
|
|
808
|
+
});
|
|
806
809
|
var page = { ...target, tabId: text(256), pageRevision: count };
|
|
807
810
|
var mode = enumeration("off", "pick", "review");
|
|
808
811
|
var voidResult = (v) => v === void 0;
|
|
@@ -812,7 +815,7 @@ var annotationFields = { target: text(8192), selector: text(8192), locatorKind:
|
|
|
812
815
|
var validBrowserSnapshot = object({ pageUrl: text(16384, true), pageRevision: count, ready: bool, mode, interactionVersion: count, eventSequence: count, selection: nullable(object({ selectionId: text(), target: object(annotationFields), rect })), focusedAnnotationId: nullable(text()), viewport: nullable(object({ width: finite, height: finite })), annotations: array(object({ record: object({ ...annotationFields, id: text(), pageUrl: text(16384, true), comment: text(65536, true) }), status: enumeration("visible", "offscreen", "missing"), rect: nullable(rect) }), 4096) });
|
|
813
816
|
var root = object({ path: text(32768), identity: object({ dev: text(), ino: text() }) }, { workspaceId: text() });
|
|
814
817
|
var validDesktopTarget = object({ id: text(), dataScopeId: text(), draftId: text(), draftRevision: count }, { root, sessionId: text() });
|
|
815
|
-
var kind = enumeration("files.writeText", "git.switchBranch", "git.createBranch"
|
|
818
|
+
var kind = enumeration("files.writeText", "git.switchBranch", "git.createBranch");
|
|
816
819
|
var validWorkspaceOperation = object({ requestId: id, kind, state: enumeration("prepared", "running", "completed", "failed", "unknown"), createdAt: count, updatedAt: count }, { result: json, error: object({ code: text(128) }) });
|
|
817
820
|
var origin = (v) => object({ kind: enumeration("surface"), surfaceId: text() })(v) || object({ kind: enumeration("tool-result"), sourcePartId: text() })(v);
|
|
818
821
|
var appRecord = object({ id: text(), sessionId: text(), pluginId: text(), pluginVersion: text(), pluginDigest: text(), definitionDigest: text(), backendId: text(), backendKind: enumeration("native-tools", "mcp-server"), resourceUri: text(8192), origin, logicalKey: text(8192), status: enumeration("open", "closed", "revoked"), controlRevision: count, createdAt: count, updatedAt: count }, { activeActionRunId: text(), lastActionRunId: text() });
|
|
@@ -835,7 +838,7 @@ var rules = {
|
|
|
835
838
|
"desktop.files.search": { input: object({ ...target, query: text(4096, true) }, { directory: text(32768, true), limit: positive }), result: object({ matches: array(object({ path: text(32768), line: count, text: text(65536, true) }), 1e4), truncated: bool }) },
|
|
836
839
|
"desktop.files.openRead": { input: object({ ...target, path: text(32768) }), result: validConnection },
|
|
837
840
|
"desktop.files.readText": { input: object({ ...target, path: text(32768) }), result: object({ path: text(32768), text: text(8 * 1024 * 1024, true), sha256: digest, byteLength: count, encoding: enumeration("utf-8"), truncated: bool }) },
|
|
838
|
-
"desktop.files.writeText": { input: object({ ...target, requestId: id,
|
|
841
|
+
"desktop.files.writeText": { input: object({ ...target, requestId: id, ...fileWriteBody }), result: validWorkspaceOperation },
|
|
839
842
|
"desktop.files.getOperation": { input: object({ ...target, requestId: id, original: object({ kind, body: json }) }), result: nullable(validWorkspaceOperation) },
|
|
840
843
|
"desktop.files.revealPath": { input: object({ ...target, path: text(32768) }), result: voidResult },
|
|
841
844
|
"desktop.files.listOpeners": { input: object(target), result: array(object({ id: text(256), label: text(1024), kind: enumeration("editor", "folder", "terminal"), iconDataUrl: nullable(text(1024 * 1024)) }, { isDefault: bool }), 256) },
|
|
@@ -851,9 +854,8 @@ var rules = {
|
|
|
851
854
|
"desktop.git.listBranches": { input: object(target), result: object({ branches: array(text(1024), 1e4) }) },
|
|
852
855
|
"desktop.git.changes": { input: object(target, { range: enumeration("uncommitted", "working", "staged"), ignoreWhitespace: bool }), result: object({ files: array(object({ path: text(32768), status: enumeration("added", "modified", "deleted", "renamed", "copied", "untracked"), additions: nullable(count), deletions: nullable(count), binary: bool }, { oldPath: text(32768) }), 1e4), totalAdditions: count, totalDeletions: count }) },
|
|
853
856
|
"desktop.git.diff": { input: object(target, { path: text(32768), base: text(), head: text(), range: enumeration("uncommitted", "working", "staged"), ignoreWhitespace: bool }), result: object({ text: text(8 * 1024 * 1024, true), truncated: bool }) },
|
|
854
|
-
"desktop.git.switchBranch": { input: object({ ...target, requestId: id,
|
|
855
|
-
"desktop.git.createBranch": { input: object({ ...target, requestId: id,
|
|
856
|
-
"desktop.git.createTaskWorktree": { input: object({ ...target, requestId: id, expectedHead: text(), branch: text() }), result: validWorkspaceOperation },
|
|
857
|
+
"desktop.git.switchBranch": { input: object({ ...target, requestId: id, ...gitBranchBody }), result: validWorkspaceOperation },
|
|
858
|
+
"desktop.git.createBranch": { input: object({ ...target, requestId: id, ...gitBranchBody }), result: validWorkspaceOperation },
|
|
857
859
|
"desktop.terminals.create": { input: object({ ...target, requestId: id, cols: positive, rows: positive }, { name: text(256) }), result: object({ resourceId: text(), terminalId: text(), cwd: text(32768), status: enumeration("running", "exited") }) },
|
|
858
860
|
"desktop.terminals.list": { input: object(target), result: array(object({ id: text(), name: text(1024, true), scope: (v) => object({ kind: enumeration("session"), sessionId: text() })(v) || object({ kind: enumeration("project"), projectId: text() })(v), runtime: enumeration("local", "environment"), source: enumeration("user", "agent"), status: enumeration("running", "stopping", "completed", "killed", "failed"), cwd: text(32768), shell: text(32768, true), cols: positive, rows: positive, createdAt: text() }, { projectId: text(), sessionId: text(), environmentKind: enumeration("native", "wsl"), distribution: text(), command: text(65536, true), exitedAt: text(), exitCode: nullable(finite) }), 1e4) },
|
|
859
861
|
"desktop.terminals.restart": { input: object({ ...target, terminalId: text(), requestId: id }), result: object({ resourceId: text(), terminalId: text(), cwd: text(32768), status: enumeration("running", "exited") }) },
|
|
@@ -946,24 +948,48 @@ function createAppDesktopApi(rpc, owner, filesFeature = () => {
|
|
|
946
948
|
if (!validDesktopResultForInput(method, params, value)) throw new AppHostError("host_unavailable");
|
|
947
949
|
return value;
|
|
948
950
|
};
|
|
949
|
-
const group = (name2) => Object.fromEntries(DESKTOP_METHODS.filter((
|
|
950
|
-
|
|
951
|
-
if (!
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
951
|
+
const group = (name2) => Object.fromEntries(DESKTOP_METHODS.filter((method) => !DESKTOP_ADAPTED_METHODS.includes(method) && method.startsWith(`desktop.${name2}.`)).map((method) => [method.split(".")[2], (params) => call(method, params)]));
|
|
952
|
+
const getOperation = async (input, validate2) => {
|
|
953
|
+
if (!validate2(input)) throw new AppHostError("invalid_request");
|
|
954
|
+
return call("desktop.files.getOperation", input);
|
|
955
|
+
};
|
|
956
|
+
return {
|
|
957
|
+
bindTarget(input) {
|
|
958
|
+
if (!object({ draftId: text(), draftRevision: count }, { directory: text(32768), workspaceId: text(), connection: (v) => !!v && typeof v === "object", sessionId: text() })(input)) throw new AppHostError("invalid_request");
|
|
959
|
+
const { connection, ...rest } = input;
|
|
960
|
+
return call("desktop.bindTarget", { ...rest, ...connection === void 0 ? {} : { connectionId: resolveClientConnection(connection, owner) } });
|
|
961
|
+
},
|
|
962
|
+
releaseTarget: (input) => call("desktop.releaseTarget", input),
|
|
963
|
+
files: {
|
|
964
|
+
...group("files"),
|
|
965
|
+
getOperation: (input) => getOperation(input, validFileOperationQuery),
|
|
966
|
+
async readFile(input, options = {}) {
|
|
967
|
+
if (!object({ ...target, path: text(32768) }, { range: object({ start: count }, { end: count }) })(input) || input.range?.end !== void 0 && input.range.end < input.range.start) throw new AppHostError("invalid_request");
|
|
968
|
+
filesFeature();
|
|
969
|
+
const { range: range2, ...params } = input;
|
|
970
|
+
const wire = await call("desktop.files.openRead", params);
|
|
971
|
+
const fetchFile = owner.fetchFor(wire.connectionId, wire.baseUrl);
|
|
972
|
+
try {
|
|
973
|
+
return await fetchFile(wire.baseUrl + "/", {
|
|
974
|
+
...options.signal ? { signal: options.signal } : {},
|
|
975
|
+
...range2 ? { headers: { Range: `bytes=${range2.start}-${range2.end ?? ""}` } } : {}
|
|
976
|
+
});
|
|
977
|
+
} catch (error) {
|
|
978
|
+
owner.close(wire.connectionId);
|
|
979
|
+
throw error;
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
},
|
|
983
|
+
clipboard: group("clipboard"),
|
|
984
|
+
git: {
|
|
985
|
+
...group("git"),
|
|
986
|
+
getOperation: (input) => getOperation(input, validGitOperationQuery)
|
|
987
|
+
},
|
|
988
|
+
terminals: group("terminals"),
|
|
989
|
+
windows: group("windows"),
|
|
990
|
+
browser: group("browser"),
|
|
991
|
+
pluginApps: group("pluginApps")
|
|
992
|
+
};
|
|
967
993
|
}
|
|
968
994
|
function canonicalDesktopRequest(value) {
|
|
969
995
|
if (!json(value)) throw new AppHostError("invalid_request");
|
|
@@ -1051,12 +1077,94 @@ function validProjectRequest(value) {
|
|
|
1051
1077
|
case "archive":
|
|
1052
1078
|
return object({ action: (v) => v === "archive", ...project })(value);
|
|
1053
1079
|
case "rebind":
|
|
1054
|
-
return object({ action: (v) => v === "rebind", ...
|
|
1080
|
+
return object({ action: (v) => v === "rebind", ...project, previousWorkspaceId: id2, expectedPath: text(32768) })(value);
|
|
1055
1081
|
default:
|
|
1056
1082
|
return false;
|
|
1057
1083
|
}
|
|
1058
1084
|
}
|
|
1059
|
-
var validProjectSnapshot = (value) => object({
|
|
1085
|
+
var validProjectSnapshot = (value) => object({
|
|
1086
|
+
dataScopeId: id2,
|
|
1087
|
+
projects: array(object({ workspaceId: id2, projectId: id2, name: text(1024), path: text(32768), available: bool, lastOpenedAt: count }, {
|
|
1088
|
+
defaultShell: text(4096),
|
|
1089
|
+
rootIdentity: object({ dev: text(32), ino: text(32) })
|
|
1090
|
+
}), 1e4)
|
|
1091
|
+
}, { selectedWorkspaceId: id2 })(value);
|
|
1092
|
+
|
|
1093
|
+
// src/local-workspace.ts
|
|
1094
|
+
var root2 = { rootPath: text(32768) };
|
|
1095
|
+
var identity = { identity: object({ dev: text(32), ino: text(32) }) };
|
|
1096
|
+
var file = { ...root2, path: text(32768) };
|
|
1097
|
+
var write = { ...file, requestId: id, content: text(125e4, true), originalContent: text(125e4, true) };
|
|
1098
|
+
var actionOf = (value) => value && typeof value === "object" ? Object.getOwnPropertyDescriptor(value, "action")?.value : void 0;
|
|
1099
|
+
function validLocalWorkspaceRequest(value) {
|
|
1100
|
+
const action2 = actionOf(value);
|
|
1101
|
+
const field = { action: enumeration(action2) };
|
|
1102
|
+
switch (action2) {
|
|
1103
|
+
case "pick":
|
|
1104
|
+
case "listOpeners":
|
|
1105
|
+
return object(field)(value);
|
|
1106
|
+
case "list":
|
|
1107
|
+
return object({ ...field, ...root2 }, { ...identity, path: text(32768, true) })(value);
|
|
1108
|
+
case "find":
|
|
1109
|
+
return object({ ...field, ...root2, query: text(1024) }, identity)(value);
|
|
1110
|
+
case "write":
|
|
1111
|
+
case "getWrite":
|
|
1112
|
+
return object({ ...field, ...write }, identity)(value);
|
|
1113
|
+
case "openWith":
|
|
1114
|
+
return object({ ...field, ...file, openerId: text(256) }, identity)(value);
|
|
1115
|
+
case "copyPath":
|
|
1116
|
+
return object({ ...field, ...file }, { ...identity, absolute: bool })(value);
|
|
1117
|
+
case "read":
|
|
1118
|
+
case "reveal":
|
|
1119
|
+
case "webPreview":
|
|
1120
|
+
return object({ ...field, ...file }, identity)(value);
|
|
1121
|
+
default:
|
|
1122
|
+
return false;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
var bytes = (limit) => (value) => value instanceof ArrayBuffer && value.byteLength <= limit;
|
|
1126
|
+
var preview = object({
|
|
1127
|
+
path: text(32768),
|
|
1128
|
+
name: text(32768),
|
|
1129
|
+
language: text(4096),
|
|
1130
|
+
size: count,
|
|
1131
|
+
binary: bool,
|
|
1132
|
+
content: nullable(text(125e4, true)),
|
|
1133
|
+
scope: enumeration("project", "extra-root"),
|
|
1134
|
+
relativePath: text(32768),
|
|
1135
|
+
rootLabel: text(32768),
|
|
1136
|
+
previewBytes: nullable(bytes(50 * 1024 * 1024)),
|
|
1137
|
+
mediaType: enumeration(null, "image/avif", "image/bmp", "image/gif", "image/jpeg", "image/png", "image/webp"),
|
|
1138
|
+
imagePreviewError: enumeration(null, "image_too_large", "image_unsupported")
|
|
1139
|
+
}, {
|
|
1140
|
+
rootIdentity: identity.identity,
|
|
1141
|
+
documentPreview: object({ format: enumeration("pdf", "epub", "docx", "xlsx", "pptx"), bytes: bytes(64 * 1024 * 1024) })
|
|
1142
|
+
});
|
|
1143
|
+
var tree = object({
|
|
1144
|
+
...root2,
|
|
1145
|
+
entries: array(object({ path: text(32768), type: enumeration("file", "directory") }, { size: count }), 1e4)
|
|
1146
|
+
}, { truncated: bool });
|
|
1147
|
+
var found = object({ files: array(text(32768), 1e3), truncated: bool });
|
|
1148
|
+
var picked = object({ ...root2, ...identity, workspaceId: id });
|
|
1149
|
+
var url = object({ url: text(131072) });
|
|
1150
|
+
var openers = (value) => validDesktopResult("desktop.files.listOpeners", value);
|
|
1151
|
+
var empty2 = (value) => value === void 0;
|
|
1152
|
+
var checks = {
|
|
1153
|
+
pick: nullable(picked),
|
|
1154
|
+
list: tree,
|
|
1155
|
+
find: found,
|
|
1156
|
+
read: preview,
|
|
1157
|
+
write: preview,
|
|
1158
|
+
getWrite: nullable(preview),
|
|
1159
|
+
reveal: empty2,
|
|
1160
|
+
openWith: empty2,
|
|
1161
|
+
copyPath: empty2,
|
|
1162
|
+
listOpeners: openers,
|
|
1163
|
+
webPreview: url
|
|
1164
|
+
};
|
|
1165
|
+
function validLocalWorkspaceResult(value, action2) {
|
|
1166
|
+
return action2 ? checks[action2](value) : Object.values(checks).some((check) => check(value));
|
|
1167
|
+
}
|
|
1060
1168
|
|
|
1061
1169
|
// ../domain-contracts/src/app-host/model-providers.ts
|
|
1062
1170
|
var provider = text(256);
|
|
@@ -1096,8 +1204,9 @@ function validModelProviderConnections(value) {
|
|
|
1096
1204
|
var modelId = text(1024);
|
|
1097
1205
|
var effort = nullable(text(256));
|
|
1098
1206
|
var revision = text(8192);
|
|
1207
|
+
var accountGatewayProof = (value) => typeof value === "string" && /^[a-f0-9]{64}$/.test(value);
|
|
1099
1208
|
function validProviderDefaultsRequest(value) {
|
|
1100
|
-
return object({ action: enumeration("snapshot") })(value) || object({ action: enumeration("updateModel"), model: modelId }, { provider, effort, expectedRevision: revision })(value) || object({ action: enumeration("updateEffort"), effort, expectedRevision: revision })(value) || object({ action: enumeration("test"), provider, model: modelId })(value);
|
|
1209
|
+
return object({ action: enumeration("snapshot") }, { accountGatewayProof })(value) || object({ action: enumeration("updateModel"), model: modelId }, { provider, effort, expectedRevision: revision })(value) || object({ action: enumeration("updateEffort"), effort, expectedRevision: revision })(value) || object({ action: enumeration("test"), provider, model: modelId })(value);
|
|
1101
1210
|
}
|
|
1102
1211
|
var verifiedProvider = object({ model: modelId, checkedAt: count });
|
|
1103
1212
|
var verified = (value) => {
|
|
@@ -1121,7 +1230,7 @@ var validProviderDefaultsSnapshot = object({
|
|
|
1121
1230
|
verified,
|
|
1122
1231
|
fastModeAvailable: enumeration(false),
|
|
1123
1232
|
fastModeReason: text(1024)
|
|
1124
|
-
});
|
|
1233
|
+
}, { accountGatewayMatches: bool });
|
|
1125
1234
|
var validProviderConnectionTestResult = object({
|
|
1126
1235
|
status: enumeration("verified", "failed"),
|
|
1127
1236
|
detail: text(8192),
|
|
@@ -1168,6 +1277,7 @@ var SYSTEM_SHORTCUT_IDS = [
|
|
|
1168
1277
|
];
|
|
1169
1278
|
var SYSTEM_METHODS = [
|
|
1170
1279
|
"system.projects",
|
|
1280
|
+
"system.workspace",
|
|
1171
1281
|
"system.extensions",
|
|
1172
1282
|
"system.modelProviders",
|
|
1173
1283
|
"system.providerDefaults",
|
|
@@ -1265,6 +1375,8 @@ function validSystemInput(method, value) {
|
|
|
1265
1375
|
switch (method) {
|
|
1266
1376
|
case "system.projects":
|
|
1267
1377
|
return validProjectRequest(value);
|
|
1378
|
+
case "system.workspace":
|
|
1379
|
+
return validLocalWorkspaceRequest(value);
|
|
1268
1380
|
case "system.extensions":
|
|
1269
1381
|
return validExtensionRequest(value);
|
|
1270
1382
|
case "system.modelProviders":
|
|
@@ -1314,6 +1426,8 @@ function validSystemResult(method, value) {
|
|
|
1314
1426
|
switch (method) {
|
|
1315
1427
|
case "system.projects":
|
|
1316
1428
|
return validProjectSnapshot(value);
|
|
1429
|
+
case "system.workspace":
|
|
1430
|
+
return validLocalWorkspaceResult(value);
|
|
1317
1431
|
case "system.extensions":
|
|
1318
1432
|
return validExtensionResult(value);
|
|
1319
1433
|
case "system.modelProviders":
|
|
@@ -1354,6 +1468,11 @@ function createAppSystemApi(requester, connectionOwner) {
|
|
|
1354
1468
|
}
|
|
1355
1469
|
return {
|
|
1356
1470
|
projects: (input) => send("system.projects", input),
|
|
1471
|
+
workspace: (async (input) => {
|
|
1472
|
+
const result = await send("system.workspace", input);
|
|
1473
|
+
if (!validLocalWorkspaceResult(result, input.action)) throw new AppHostError("host_unavailable");
|
|
1474
|
+
return result;
|
|
1475
|
+
}),
|
|
1357
1476
|
extensions: (input) => send("system.extensions", input),
|
|
1358
1477
|
modelProviders: (input) => send("system.modelProviders", input),
|
|
1359
1478
|
providerDefaults: (async (input) => {
|
|
@@ -1381,7 +1500,7 @@ function createAppSystemApi(requester, connectionOwner) {
|
|
|
1381
1500
|
setTheme: (theme) => send("system.setTheme", { theme }),
|
|
1382
1501
|
setWindowMaterial: (preference) => send("system.setWindowMaterial", { preference }),
|
|
1383
1502
|
copyText: (text2) => send("system.copyText", { text: text2 }),
|
|
1384
|
-
openExternal: (
|
|
1503
|
+
openExternal: (url2) => send("system.openExternal", { url: url2 }),
|
|
1385
1504
|
navigationReady: () => send("system.navigationReady", {}),
|
|
1386
1505
|
completeNavigation: (input) => send("system.completeNavigation", input)
|
|
1387
1506
|
};
|
|
@@ -1544,20 +1663,51 @@ function createAppAuxiliarySessionsApi(rpc, streams) {
|
|
|
1544
1663
|
const { connection, ...rest } = input;
|
|
1545
1664
|
return { ...rest, connectionId: resolveClientConnection(connection, streams) };
|
|
1546
1665
|
};
|
|
1547
|
-
return {
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1666
|
+
return {
|
|
1667
|
+
getOptions: (input) => request("sessions.getAuxiliaryOptions", {
|
|
1668
|
+
sessionId: input.sessionId,
|
|
1669
|
+
connectionId: resolveClientConnection(input.connection, streams)
|
|
1670
|
+
}),
|
|
1671
|
+
async open(input) {
|
|
1672
|
+
const wire = await request("sessions.openAuxiliary", resolve(input));
|
|
1673
|
+
return { leaseId: wire.receipt.leaseId, sessionId: wire.receipt.sessionId, connection: createClientConnection(wire, streams) };
|
|
1674
|
+
},
|
|
1675
|
+
get: (input) => request("sessions.getAuxiliary", resolve(input)),
|
|
1676
|
+
close: (input) => request("sessions.closeAuxiliary", resolve(input))
|
|
1677
|
+
};
|
|
1551
1678
|
}
|
|
1552
1679
|
|
|
1553
1680
|
// src/workspace.ts
|
|
1681
|
+
var validPickOptions = object({}, { requestId: (value) => value === void 0 || id(value) });
|
|
1554
1682
|
function createAppWorkspaceApi(input) {
|
|
1555
1683
|
async function call(method, params) {
|
|
1556
1684
|
if (!validWorkspaceInput(method, params)) throw new AppHostError("invalid_request");
|
|
1557
1685
|
input.requireFeature();
|
|
1558
1686
|
return input.request(method, params);
|
|
1559
1687
|
}
|
|
1560
|
-
|
|
1688
|
+
function bindDirectory({ id: id3, displayName }) {
|
|
1689
|
+
return {
|
|
1690
|
+
id: id3,
|
|
1691
|
+
displayName,
|
|
1692
|
+
listFiles: ({ directory = "", cursor: cursor2 } = {}) => call("workspace.listFiles", {
|
|
1693
|
+
workspaceId: id3,
|
|
1694
|
+
directory,
|
|
1695
|
+
...cursor2 === void 0 ? {} : { cursor: cursor2 }
|
|
1696
|
+
}),
|
|
1697
|
+
readText: (path) => call("workspace.readText", { workspaceId: id3, path })
|
|
1698
|
+
};
|
|
1699
|
+
}
|
|
1700
|
+
return {
|
|
1701
|
+
async pick(options = {}) {
|
|
1702
|
+
if (!validPickOptions(options)) throw new AppHostError("invalid_request");
|
|
1703
|
+
const selected = await call("workspace.select", { requestId: options.requestId ?? crypto.randomUUID() });
|
|
1704
|
+
return selected === null ? null : bindDirectory(selected);
|
|
1705
|
+
},
|
|
1706
|
+
async open(id3) {
|
|
1707
|
+
return bindDirectory(await call("workspace.get", { workspaceId: id3 }));
|
|
1708
|
+
},
|
|
1709
|
+
getSelection: (x) => call("workspace.getSelection", x)
|
|
1710
|
+
};
|
|
1561
1711
|
}
|
|
1562
1712
|
|
|
1563
1713
|
// src/session-resources.ts
|
|
@@ -1833,10 +1983,10 @@ function createPageFetchClient(options) {
|
|
|
1833
1983
|
s.wake = void 0;
|
|
1834
1984
|
if (s.stopped) return;
|
|
1835
1985
|
}
|
|
1836
|
-
const
|
|
1986
|
+
const bytes2 = new Uint8Array(item.value.subarray(offset, offset + FETCH_CHUNK_BYTES));
|
|
1837
1987
|
s.credit--;
|
|
1838
|
-
offset +=
|
|
1839
|
-
send({ protocol: 2, type: "fetch-chunk", id: s.id, direction: "upload", sequence: s.uploadSequence++, bytes });
|
|
1988
|
+
offset += bytes2.byteLength;
|
|
1989
|
+
send({ protocol: 2, type: "fetch-chunk", id: s.id, direction: "upload", sequence: s.uploadSequence++, bytes: bytes2 });
|
|
1840
1990
|
if (s.stopped || closed) return;
|
|
1841
1991
|
touch(s);
|
|
1842
1992
|
}
|
|
@@ -2081,12 +2231,27 @@ function json3(value, ancestors = /* @__PURE__ */ new Set()) {
|
|
|
2081
2231
|
function payloadSize(value) {
|
|
2082
2232
|
if (value instanceof Uint8Array) return value.byteLength;
|
|
2083
2233
|
if (record(value) && value.bytes instanceof Uint8Array) {
|
|
2084
|
-
const { bytes, ...metadata } = value;
|
|
2085
|
-
return
|
|
2234
|
+
const { bytes: bytes2, ...metadata } = value;
|
|
2235
|
+
return bytes2.byteLength + new TextEncoder().encode(JSON.stringify(metadata)).byteLength;
|
|
2086
2236
|
}
|
|
2087
2237
|
if (!json3(value)) throw failure("invalid_request");
|
|
2088
2238
|
return new TextEncoder().encode(JSON.stringify(value)).byteLength;
|
|
2089
2239
|
}
|
|
2240
|
+
function responsePayloadFits(method, value) {
|
|
2241
|
+
if (value === void 0) return true;
|
|
2242
|
+
if (method === "system.workspace" && record(value)) {
|
|
2243
|
+
const { previewBytes, documentPreview, ...metadata } = value;
|
|
2244
|
+
const image = previewBytes instanceof ArrayBuffer;
|
|
2245
|
+
const document = record(documentPreview) && documentPreview.bytes instanceof ArrayBuffer;
|
|
2246
|
+
if (image || document) {
|
|
2247
|
+
return !(image && document) && payloadSize({
|
|
2248
|
+
...metadata,
|
|
2249
|
+
...document ? { documentPreview: { format: documentPreview.format } } : {}
|
|
2250
|
+
}) <= APP_HOST_MAX_PAYLOAD_BYTES;
|
|
2251
|
+
}
|
|
2252
|
+
}
|
|
2253
|
+
return payloadSize(value) <= APP_HOST_MAX_PAYLOAD_BYTES;
|
|
2254
|
+
}
|
|
2090
2255
|
function validContext(value) {
|
|
2091
2256
|
return keys(value, [
|
|
2092
2257
|
"appId",
|
|
@@ -2324,7 +2489,7 @@ var DocumentConnection = class {
|
|
|
2324
2489
|
const p = this.pending.get(data.id);
|
|
2325
2490
|
if (!p) return;
|
|
2326
2491
|
if (data.ok === true) {
|
|
2327
|
-
if (!keys(data, ["protocol", "type", "id", "ok"], ["value"]) || !validResult(p.method, data.value) ||
|
|
2492
|
+
if (!keys(data, ["protocol", "type", "id", "ok"], ["value"]) || !validResult(p.method, data.value) || !responsePayloadFits(p.method, data.value))
|
|
2328
2493
|
throw failure("host_unavailable");
|
|
2329
2494
|
clearTimeout(p.timer);
|
|
2330
2495
|
this.pending.delete(data.id);
|
|
@@ -2444,9 +2609,9 @@ var DocumentConnection = class {
|
|
|
2444
2609
|
},
|
|
2445
2610
|
this.fetchClient
|
|
2446
2611
|
),
|
|
2447
|
-
sessions:
|
|
2448
|
-
conversationPreparation,
|
|
2449
|
-
createAppSessionsApi(
|
|
2612
|
+
sessions: {
|
|
2613
|
+
preparation: conversationPreparation,
|
|
2614
|
+
...createAppSessionsApi(
|
|
2450
2615
|
{
|
|
2451
2616
|
requireFeature: () => this.requireFeature("session-resources-v1"),
|
|
2452
2617
|
request: (method, params2) => this.request(
|
|
@@ -2456,14 +2621,14 @@ var DocumentConnection = class {
|
|
|
2456
2621
|
},
|
|
2457
2622
|
this.fetchClient
|
|
2458
2623
|
),
|
|
2459
|
-
createAppAuxiliarySessionsApi(
|
|
2624
|
+
auxiliary: createAppAuxiliarySessionsApi(
|
|
2460
2625
|
{
|
|
2461
2626
|
requireFeature: () => this.requireFeature("auxiliary-sessions-v1"),
|
|
2462
2627
|
request: (method, params2) => this.request(method, params2)
|
|
2463
2628
|
},
|
|
2464
2629
|
this.fetchClient
|
|
2465
2630
|
)
|
|
2466
|
-
|
|
2631
|
+
},
|
|
2467
2632
|
workspace: Object.assign(
|
|
2468
2633
|
{ list: catalog.list },
|
|
2469
2634
|
createAppWorkspaceApi({
|
|
@@ -2503,8 +2668,8 @@ var DocumentConnection = class {
|
|
|
2503
2668
|
});
|
|
2504
2669
|
},
|
|
2505
2670
|
readFile: async (id3) => {
|
|
2506
|
-
const
|
|
2507
|
-
return new Response(new Uint8Array(
|
|
2671
|
+
const bytes2 = await this.request("storage.readFile", { id: id3 });
|
|
2672
|
+
return new Response(new Uint8Array(bytes2), {
|
|
2508
2673
|
headers: { "content-type": "application/octet-stream" }
|
|
2509
2674
|
});
|
|
2510
2675
|
},
|
|
@@ -2530,10 +2695,10 @@ var DocumentConnection = class {
|
|
|
2530
2695
|
([key, value]) => ["key", "id", "name"].includes(key) && !nonempty(value)
|
|
2531
2696
|
) || this.pending.size >= APP_HOST_MAX_PENDING || payloadSize(params) > APP_HOST_MAX_PAYLOAD_BYTES)
|
|
2532
2697
|
throw failure("invalid_request");
|
|
2533
|
-
const mutationRequestId = (isDesktopMethod(method) || isAuxiliaryMethod(method)) && "requestId" in params && typeof params.requestId === "string" && HOST_REQUEST_ID.test(params.requestId) ? params.requestId : void 0;
|
|
2698
|
+
const mutationRequestId = (isDesktopMethod(method) || isAuxiliaryMethod(method) || method === "sessions.createConversation" || method === "system.workspace" && "action" in params && params.action === "write") && "requestId" in params && typeof params.requestId === "string" && HOST_REQUEST_ID.test(params.requestId) ? params.requestId : void 0;
|
|
2534
2699
|
const selectionRequestId = method === "workspace.select" ? params.requestId : void 0;
|
|
2535
2700
|
let timeout = APP_HOST_REQUEST_TIMEOUT_MS;
|
|
2536
|
-
if (method === "auth.openLogin" || method === "workspace.select")
|
|
2701
|
+
if (method === "auth.openLogin" || method === "workspace.select" || method === "system.workspace" && "action" in params && params.action === "pick")
|
|
2537
2702
|
timeout = APP_HOST_LOGIN_TRANSPORT_TIMEOUT_MS;
|
|
2538
2703
|
if (method === "system.extensions") {
|
|
2539
2704
|
const { operation } = params;
|