@bobannomi/app-host 0.1.1 → 0.3.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 +357 -170
- package/dist/index.js +492 -211
- package/dist/index.js.map +3 -3
- package/dist/protocol.d.ts +512 -321
- package/dist/protocol.js +358 -303
- 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) {
|
|
@@ -38,13 +40,15 @@ function isSafeErrorDetails(value, depth = 0) {
|
|
|
38
40
|
}
|
|
39
41
|
function isAppHostErrorInfo(value) {
|
|
40
42
|
if (!value || typeof value !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(value))) return false;
|
|
41
|
-
const
|
|
42
|
-
if (!
|
|
43
|
+
const keys3 = Reflect.ownKeys(value);
|
|
44
|
+
if (!keys3.every((key) => typeof key === "string" && ["code", "message", "retry", "requestId", "details"].includes(key) && Object.hasOwn(Object.getOwnPropertyDescriptor(value, key), "value"))) return false;
|
|
43
45
|
const error = value;
|
|
44
46
|
return Object.hasOwn(APP_HOST_ERROR_RETRY, error.code) && typeof error.message === "string" && (!Object.hasOwn(error, "retry") || error.retry === APP_HOST_ERROR_RETRY[error.code]) && (!Object.hasOwn(error, "requestId") || typeof error.requestId === "string" && HOST_REQUEST_ID.test(error.requestId)) && (!Object.hasOwn(error, "details") || isSafeErrorDetails(error.details));
|
|
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";
|
|
@@ -162,9 +166,9 @@ var json = (value) => {
|
|
|
162
166
|
if (list ? Object.getPrototypeOf(v) !== Array.prototype : ![Object.prototype, null].includes(Object.getPrototypeOf(v))) return false;
|
|
163
167
|
seen.add(v);
|
|
164
168
|
try {
|
|
165
|
-
const
|
|
166
|
-
if (list &&
|
|
167
|
-
return
|
|
169
|
+
const keys3 = Reflect.ownKeys(v);
|
|
170
|
+
if (list && keys3.length !== v.length + 1) return false;
|
|
171
|
+
return keys3.every((k) => {
|
|
168
172
|
if (list && k === "length") return true;
|
|
169
173
|
const d = Object.getOwnPropertyDescriptor(v, k);
|
|
170
174
|
size += typeof k === "string" ? k.length + 3 : 0;
|
|
@@ -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",
|
|
@@ -288,7 +211,8 @@ var APP_HOST_FEATURES = [
|
|
|
288
211
|
"window-update-check-v1",
|
|
289
212
|
"embedded-browser-v1",
|
|
290
213
|
"browser-binding-invalidation-v1",
|
|
291
|
-
"browser-capture-preview-v1"
|
|
214
|
+
"browser-capture-preview-v1",
|
|
215
|
+
"workbench-computer-v1"
|
|
292
216
|
];
|
|
293
217
|
var FETCH_CHUNK_BYTES = 64 * 1024;
|
|
294
218
|
var FETCH_INLINE_BODY_BYTES = 8 * 1024;
|
|
@@ -321,10 +245,10 @@ function isPageFetchFrame(value) {
|
|
|
321
245
|
const array2 = Array.isArray(entry);
|
|
322
246
|
if (array2 ? Object.getPrototypeOf(entry) !== Array.prototype : ![Object.prototype, null].includes(Object.getPrototypeOf(entry)))
|
|
323
247
|
return false;
|
|
324
|
-
const
|
|
325
|
-
if (
|
|
248
|
+
const keys3 = Reflect.ownKeys(entry);
|
|
249
|
+
if (keys3.length > FETCH_METADATA_BYTES || array2 && keys3.length !== entry.length + 1)
|
|
326
250
|
return false;
|
|
327
|
-
return
|
|
251
|
+
return keys3.every((key) => {
|
|
328
252
|
if (array2 && key === "length") return true;
|
|
329
253
|
const d = Object.getOwnPropertyDescriptor(entry, key);
|
|
330
254
|
size += typeof key === "string" ? key.length + 3 : 0;
|
|
@@ -379,17 +303,12 @@ function pageFetchPath(baseUrl, input) {
|
|
|
379
303
|
const rawPath = input.replace(/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^/]+/, "").split("?")[0];
|
|
380
304
|
if (rawPath.includes("//") || /%(?:2e|2f|5c|25)/i.test(rawPath) || rawPath.split("/").some((p) => p === "." || p === "..") || /[\u0000-\u001f\u007f]/.test(decodeURIComponent(rawPath)))
|
|
381
305
|
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 ||
|
|
306
|
+
const base = new URL(baseUrl), url2 = new URL(input);
|
|
307
|
+
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
308
|
throw new TypeError("Fetch target mismatch");
|
|
385
|
-
return (
|
|
309
|
+
return (url2.pathname.slice(base.pathname.length) || "/") + url2.search;
|
|
386
310
|
}
|
|
387
311
|
|
|
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
312
|
// ../domain-contracts/src/app-host/workspace-conversations.ts
|
|
394
313
|
var validWorkspaceConversation = (value) => {
|
|
395
314
|
if (!object(
|
|
@@ -428,7 +347,6 @@ var workspaceConversationResult = object({
|
|
|
428
347
|
revision: count,
|
|
429
348
|
session: sessionRecord,
|
|
430
349
|
operationState: enumeration("prepared", "running", "completed", "failed", "unknown"),
|
|
431
|
-
indexBindingPending: (v) => v === true,
|
|
432
350
|
workspaceId: id,
|
|
433
351
|
executionRoot: id,
|
|
434
352
|
privateSessionId: id,
|
|
@@ -459,7 +377,6 @@ function validSessionControlInput(method, value) {
|
|
|
459
377
|
const target2 = value;
|
|
460
378
|
return target2.workspaceId !== void 0 ? target2.outsideProject !== true : target2.outsideProject === true;
|
|
461
379
|
}
|
|
462
|
-
if (method === "sessions.bindConversationIndex") return object({ original: validWorkspaceConversation, dataScopeId: text() })(value);
|
|
463
380
|
if (method === "sessions.createConversation" || method === "sessions.getConversationCreationResult") return validWorkspaceConversation(value);
|
|
464
381
|
if (method === "sessions.getControls") return object({ connectionId: text(), sessionId: text() })(value);
|
|
465
382
|
if (!object({ requestId: id, sessionId: text(), original: validSessionControlOriginal }, { connectionId: text() })(value)) return false;
|
|
@@ -469,15 +386,95 @@ function validSessionControlInput(method, value) {
|
|
|
469
386
|
function validSessionControlResult(method, value) {
|
|
470
387
|
if (!json(value)) return false;
|
|
471
388
|
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
389
|
if (method === "sessions.createConversation" || method === "sessions.getConversationCreationResult")
|
|
474
390
|
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),
|
|
391
|
+
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
392
|
if (method === "sessions.getControlResult") return value === null || receipt(value);
|
|
477
393
|
if (!receipt(value)) return false;
|
|
478
394
|
return false;
|
|
479
395
|
}
|
|
480
396
|
|
|
397
|
+
// ../domain-contracts/src/app-host/service.ts
|
|
398
|
+
function fields(value, required, optional = []) {
|
|
399
|
+
if (!value || typeof value !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(value)))
|
|
400
|
+
return false;
|
|
401
|
+
return required.every((k) => Object.hasOwn(value, k)) && Reflect.ownKeys(value).every((k) => {
|
|
402
|
+
const d = Object.getOwnPropertyDescriptor(value, k);
|
|
403
|
+
return typeof k === "string" && [...required, ...optional].includes(k) && d.enumerable && Object.hasOwn(d, "value");
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
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(
|
|
407
|
+
v
|
|
408
|
+
);
|
|
409
|
+
function json2(value, ancestors = /* @__PURE__ */ new Set(), depth = 0) {
|
|
410
|
+
if (depth > 100) return false;
|
|
411
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
412
|
+
return true;
|
|
413
|
+
if (typeof value === "number") return Number.isFinite(value);
|
|
414
|
+
if (typeof value !== "object" || ancestors.has(value)) return false;
|
|
415
|
+
const array2 = Array.isArray(value);
|
|
416
|
+
if (array2 ? Object.getPrototypeOf(value) !== Array.prototype || Reflect.ownKeys(value).length !== value.length + 1 : ![Object.prototype, null].includes(Object.getPrototypeOf(value)))
|
|
417
|
+
return false;
|
|
418
|
+
ancestors.add(value);
|
|
419
|
+
const result = Reflect.ownKeys(value).every((k) => {
|
|
420
|
+
if (array2 && k === "length") return true;
|
|
421
|
+
const d = Object.getOwnPropertyDescriptor(value, k);
|
|
422
|
+
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);
|
|
423
|
+
});
|
|
424
|
+
ancestors.delete(value);
|
|
425
|
+
return result;
|
|
426
|
+
}
|
|
427
|
+
function validServiceStatus(value) {
|
|
428
|
+
return fields(value, ["state"], ["reason", "instanceId", "apiVersion"]) && [
|
|
429
|
+
"absent",
|
|
430
|
+
"unauthorized",
|
|
431
|
+
"stopped",
|
|
432
|
+
"starting",
|
|
433
|
+
"recovering",
|
|
434
|
+
"ready",
|
|
435
|
+
"failed"
|
|
436
|
+
].includes(value.state) && (!Object.hasOwn(value, "reason") || [
|
|
437
|
+
"dependency_missing",
|
|
438
|
+
"service_start_failed",
|
|
439
|
+
"service_unavailable",
|
|
440
|
+
"result_unknown",
|
|
441
|
+
"incompatible",
|
|
442
|
+
"revoked"
|
|
443
|
+
].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"));
|
|
444
|
+
}
|
|
445
|
+
function validWork(value) {
|
|
446
|
+
return fields(value, ["requestId", "state", "updatedAt"], ["result", "error"]) && typeof value.requestId === "string" && HOST_REQUEST_ID.test(value.requestId) && [
|
|
447
|
+
"not_accepted",
|
|
448
|
+
"accepted",
|
|
449
|
+
"running",
|
|
450
|
+
"completed",
|
|
451
|
+
"failed",
|
|
452
|
+
"interrupted",
|
|
453
|
+
"unknown"
|
|
454
|
+
].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(
|
|
455
|
+
value.updatedAt
|
|
456
|
+
) && Number.isFinite(Date.parse(value.updatedAt)) && ["result", "error"].every(
|
|
457
|
+
(k) => !Object.hasOwn(value, k) || json2(value[k]) && new TextEncoder().encode(JSON.stringify(value[k])).length <= 16384
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
function validServiceResult(method, value) {
|
|
461
|
+
switch (method) {
|
|
462
|
+
case "service.getStatus":
|
|
463
|
+
return validServiceStatus(value);
|
|
464
|
+
case "service.getConnection":
|
|
465
|
+
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);
|
|
466
|
+
case "service.getWork":
|
|
467
|
+
return validWork(value);
|
|
468
|
+
case "service.listWork":
|
|
469
|
+
return Array.isArray(value) && value.length <= 5120 && value.every(validWork) && new Set(value.map((w) => w.requestId)).size === value.length;
|
|
470
|
+
case "service.interruptWork":
|
|
471
|
+
return fields(value, ["requested"]) && typeof value.requested === "boolean";
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
function validServiceConnectionInput(value) {
|
|
475
|
+
return fields(value, ["apiRange"]) && typeof value.apiRange === "string" && !!value.apiRange.trim() && value.apiRange.length <= 256;
|
|
476
|
+
}
|
|
477
|
+
|
|
481
478
|
// ../domain-contracts/src/app-host/workspace.ts
|
|
482
479
|
function fields2(v, required, optional = []) {
|
|
483
480
|
if (!v || typeof v !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(v))) return false;
|
|
@@ -584,7 +581,7 @@ function validAppCommandSnapshot(value) {
|
|
|
584
581
|
(m) => m.items.some((i) => "command" in i && !ids.has(i.command))
|
|
585
582
|
) || Object.values(v.toolbar ?? {}).some((x) => !ids.has(x)))
|
|
586
583
|
return false;
|
|
587
|
-
const
|
|
584
|
+
const keys3 = /* @__PURE__ */ new Set();
|
|
588
585
|
for (const command of v.commands)
|
|
589
586
|
for (const key of command.shortcuts ?? []) {
|
|
590
587
|
const mods = new Set(key.modifiers);
|
|
@@ -593,8 +590,8 @@ function validAppCommandSnapshot(value) {
|
|
|
593
590
|
if ((mods.has("Primary") || mods.has("Meta") || mods.has("Control")) && ["KeyQ", "KeyR"].includes(key.code) || mods.has("Alt") && ["F4", "Tab", "Space"].includes(key.code) || mods.has("Meta") && ["Space", "Tab"].includes(key.code) || mods.has("Control") && mods.has("Alt") && key.code === "Delete" || key.code === "F5" || key.code === "F11" || key.code === "F12")
|
|
594
591
|
return false;
|
|
595
592
|
const signature = `${[...mods].map((m) => m === "Control" || m === "Meta" ? "Primary" : m).sort().join("+")}:${key.code}`;
|
|
596
|
-
if (
|
|
597
|
-
|
|
593
|
+
if (keys3.has(signature)) return false;
|
|
594
|
+
keys3.add(signature);
|
|
598
595
|
}
|
|
599
596
|
return true;
|
|
600
597
|
}
|
|
@@ -723,6 +720,65 @@ function createAppCommandsApi(rpc) {
|
|
|
723
720
|
};
|
|
724
721
|
}
|
|
725
722
|
|
|
723
|
+
// src/workbench-computer.ts
|
|
724
|
+
var WORKBENCH_COMPUTER_FEATURE = "workbench-computer-v1";
|
|
725
|
+
var workbenchComputerKey = /* @__PURE__ */ Symbol.for("nomi.workbench-computer");
|
|
726
|
+
var WORKBENCH_COMPUTER_METHODS = [
|
|
727
|
+
"workbench.computer.availability",
|
|
728
|
+
"workbench.computer.setConversation",
|
|
729
|
+
"workbench.computer.preparePrompt",
|
|
730
|
+
"workbench.computer.getActivity",
|
|
731
|
+
"workbench.computer.reply",
|
|
732
|
+
"workbench.computer.control",
|
|
733
|
+
"workbench.computer.shareWindow",
|
|
734
|
+
"workbench.computer.stopLocal"
|
|
735
|
+
];
|
|
736
|
+
var availability = ["unsupported", "disabled", "missing_driver", "ready"];
|
|
737
|
+
function record(value) {
|
|
738
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
739
|
+
}
|
|
740
|
+
function text2(value, limit = 256) {
|
|
741
|
+
return typeof value === "string" && value.length > 0 && value.length <= limit;
|
|
742
|
+
}
|
|
743
|
+
function keys(value, ...names) {
|
|
744
|
+
return Object.keys(value).length === names.length && names.every((name2) => Object.hasOwn(value, name2));
|
|
745
|
+
}
|
|
746
|
+
function isWorkbenchComputerMethod(method) {
|
|
747
|
+
return WORKBENCH_COMPUTER_METHODS.includes(method);
|
|
748
|
+
}
|
|
749
|
+
function validActivity(value) {
|
|
750
|
+
return record(value) && text2(value.sessionId) && text2(value.runId) && text2(value.phase) && ["ready", "observing", "foreground", "paused", "stopped"].includes(value.phase) && (value.preview === void 0 || record(value.preview) && text2(value.preview.dataUrl, 10 * 1024 * 1024) && /^data:image\/(png|jpeg);base64,/.test(value.preview.dataUrl) && typeof value.preview.width === "number" && typeof value.preview.height === "number");
|
|
751
|
+
}
|
|
752
|
+
function validWorkbenchComputerResult(method, value) {
|
|
753
|
+
switch (method) {
|
|
754
|
+
case "workbench.computer.availability":
|
|
755
|
+
return text2(value) && availability.includes(value);
|
|
756
|
+
case "workbench.computer.setConversation":
|
|
757
|
+
case "workbench.computer.stopLocal":
|
|
758
|
+
return value === void 0;
|
|
759
|
+
case "workbench.computer.preparePrompt":
|
|
760
|
+
case "workbench.computer.reply":
|
|
761
|
+
case "workbench.computer.control":
|
|
762
|
+
return typeof value === "boolean";
|
|
763
|
+
case "workbench.computer.getActivity":
|
|
764
|
+
return value === null || validActivity(value);
|
|
765
|
+
case "workbench.computer.shareWindow":
|
|
766
|
+
return value === null || record(value) && keys(value, "bytes") && value.bytes instanceof Uint8Array && value.bytes.byteLength > 0 && value.bytes.byteLength <= 8 * 1024 * 1024;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
function validWorkbenchComputerEvent(value) {
|
|
770
|
+
if (!record(value)) return false;
|
|
771
|
+
if (value.type === "workbench-computer-activity") {
|
|
772
|
+
const update = value.update;
|
|
773
|
+
return record(update) && text2(update.sessionId) && (update.activity === null || validActivity(update.activity) && record(update.activity) && update.activity.sessionId === update.sessionId);
|
|
774
|
+
}
|
|
775
|
+
const event = value.interaction;
|
|
776
|
+
if (value.type !== "workbench-computer-prompt" || !record(event)) return false;
|
|
777
|
+
if (event.type === "dismissed") return text2(event.id);
|
|
778
|
+
const prompt = event.prompt;
|
|
779
|
+
return event.type === "prompt" && record(prompt) && text2(prompt.id) && text2(prompt.sessionId) && (prompt.kind === "authorize" ? text2(prompt.appName, 512) : prompt.kind === "choose" && Array.isArray(prompt.candidates) && prompt.candidates.length <= 128 && prompt.candidates.every((candidate) => record(candidate) && text2(candidate.id) && text2(candidate.label, 512) && (candidate.detail === void 0 || text2(candidate.detail, 512))));
|
|
780
|
+
}
|
|
781
|
+
|
|
726
782
|
// src/resource-catalog.ts
|
|
727
783
|
var RESOURCE_CATALOG_METHODS = ["workspace.list"];
|
|
728
784
|
var isResourceCatalogMethod = (m) => RESOURCE_CATALOG_METHODS.includes(m);
|
|
@@ -750,8 +806,7 @@ function createResourceCatalogApi(rpc) {
|
|
|
750
806
|
// src/session-controls.ts
|
|
751
807
|
var CONVERSATION_PREPARATION_METHODS = [
|
|
752
808
|
"sessions.createConversation",
|
|
753
|
-
"sessions.getConversationCreationResult"
|
|
754
|
-
"sessions.bindConversationIndex"
|
|
809
|
+
"sessions.getConversationCreationResult"
|
|
755
810
|
];
|
|
756
811
|
function isConversationPreparationMethod(method) {
|
|
757
812
|
return CONVERSATION_PREPARATION_METHODS.includes(method);
|
|
@@ -766,43 +821,51 @@ function createConversationPreparationApi(rpc) {
|
|
|
766
821
|
return rpc.request(method, input);
|
|
767
822
|
};
|
|
768
823
|
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
|
-
}
|
|
824
|
+
create: (input) => call("sessions.createConversation", input),
|
|
825
|
+
getResult: (input) => call("sessions.getConversationCreationResult", input)
|
|
776
826
|
};
|
|
777
827
|
}
|
|
778
828
|
|
|
779
829
|
// src/client-connections.ts
|
|
780
830
|
var connections = /* @__PURE__ */ new WeakMap();
|
|
781
831
|
function createClientConnection(wire, streams) {
|
|
782
|
-
const
|
|
832
|
+
const record4 = { owner: streams, id: wire.connectionId, closed: false };
|
|
783
833
|
const connection = { ...wire.defaultTaskLocation === void 0 ? {} : { defaultTaskLocation: wire.defaultTaskLocation }, ...wire.cwd === void 0 ? {} : { cwd: wire.cwd }, clientOptions: { baseUrl: wire.baseUrl, fetch: streams.fetchFor(wire.connectionId, wire.baseUrl) }, isClosed() {
|
|
784
|
-
return
|
|
834
|
+
return record4.closed || streams.isClosed?.(wire.connectionId) === true;
|
|
785
835
|
}, close() {
|
|
786
|
-
if (!
|
|
787
|
-
|
|
836
|
+
if (!record4.closed) {
|
|
837
|
+
record4.closed = true;
|
|
788
838
|
streams.close(wire.connectionId);
|
|
789
839
|
}
|
|
790
840
|
} };
|
|
791
|
-
connections.set(connection,
|
|
841
|
+
connections.set(connection, record4);
|
|
792
842
|
return connection;
|
|
793
843
|
}
|
|
794
844
|
function resolveClientConnection(connection, owner) {
|
|
795
|
-
const
|
|
796
|
-
if (!
|
|
797
|
-
return
|
|
845
|
+
const record4 = connections.get(connection);
|
|
846
|
+
if (!record4 || record4.owner !== owner || record4.closed || owner.isClosed?.(record4.id)) throw new AppHostError("connection_revoked");
|
|
847
|
+
return record4.id;
|
|
798
848
|
}
|
|
799
849
|
|
|
800
850
|
// src/desktop.ts
|
|
801
851
|
var BROWSER_CAPTURE_PREVIEW_MAX_BYTES = 8 * 1024 * 1024;
|
|
852
|
+
var DESKTOP_ADAPTED_METHODS = ["desktop.files.openRead", "desktop.files.getOperation"];
|
|
802
853
|
var target = { targetId: text(256) };
|
|
803
854
|
var mount = { ...target, mountId: text(256) };
|
|
804
855
|
var source = object({ sessionId: text(), appId: text() });
|
|
805
856
|
var action = { ...mount, source, requestId: id, expectedRevision: count };
|
|
857
|
+
var fileWriteBody = { path: text(32768), expectedSha256: digest, text: text(8 * 1024 * 1024, true) };
|
|
858
|
+
var gitBranchBody = { expectedHead: text(), branch: text() };
|
|
859
|
+
var validFileOperationQuery = object({
|
|
860
|
+
...target,
|
|
861
|
+
requestId: id,
|
|
862
|
+
original: object({ kind: enumeration("files.writeText"), body: object(fileWriteBody) })
|
|
863
|
+
});
|
|
864
|
+
var validGitOperationQuery = object({
|
|
865
|
+
...target,
|
|
866
|
+
requestId: id,
|
|
867
|
+
original: object({ kind: enumeration("git.switchBranch", "git.createBranch"), body: object(gitBranchBody) })
|
|
868
|
+
});
|
|
806
869
|
var page = { ...target, tabId: text(256), pageRevision: count };
|
|
807
870
|
var mode = enumeration("off", "pick", "review");
|
|
808
871
|
var voidResult = (v) => v === void 0;
|
|
@@ -812,7 +875,7 @@ var annotationFields = { target: text(8192), selector: text(8192), locatorKind:
|
|
|
812
875
|
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
876
|
var root = object({ path: text(32768), identity: object({ dev: text(), ino: text() }) }, { workspaceId: text() });
|
|
814
877
|
var validDesktopTarget = object({ id: text(), dataScopeId: text(), draftId: text(), draftRevision: count }, { root, sessionId: text() });
|
|
815
|
-
var kind = enumeration("files.writeText", "git.switchBranch", "git.createBranch"
|
|
878
|
+
var kind = enumeration("files.writeText", "git.switchBranch", "git.createBranch");
|
|
816
879
|
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
880
|
var origin = (v) => object({ kind: enumeration("surface"), surfaceId: text() })(v) || object({ kind: enumeration("tool-result"), sourcePartId: text() })(v);
|
|
818
881
|
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 +898,7 @@ var rules = {
|
|
|
835
898
|
"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
899
|
"desktop.files.openRead": { input: object({ ...target, path: text(32768) }), result: validConnection },
|
|
837
900
|
"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,
|
|
901
|
+
"desktop.files.writeText": { input: object({ ...target, requestId: id, ...fileWriteBody }), result: validWorkspaceOperation },
|
|
839
902
|
"desktop.files.getOperation": { input: object({ ...target, requestId: id, original: object({ kind, body: json }) }), result: nullable(validWorkspaceOperation) },
|
|
840
903
|
"desktop.files.revealPath": { input: object({ ...target, path: text(32768) }), result: voidResult },
|
|
841
904
|
"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 +914,8 @@ var rules = {
|
|
|
851
914
|
"desktop.git.listBranches": { input: object(target), result: object({ branches: array(text(1024), 1e4) }) },
|
|
852
915
|
"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
916
|
"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 },
|
|
917
|
+
"desktop.git.switchBranch": { input: object({ ...target, requestId: id, ...gitBranchBody }), result: validWorkspaceOperation },
|
|
918
|
+
"desktop.git.createBranch": { input: object({ ...target, requestId: id, ...gitBranchBody }), result: validWorkspaceOperation },
|
|
857
919
|
"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
920
|
"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
921
|
"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 +1008,48 @@ function createAppDesktopApi(rpc, owner, filesFeature = () => {
|
|
|
946
1008
|
if (!validDesktopResultForInput(method, params, value)) throw new AppHostError("host_unavailable");
|
|
947
1009
|
return value;
|
|
948
1010
|
};
|
|
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
|
-
|
|
1011
|
+
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)]));
|
|
1012
|
+
const getOperation = async (input, validate2) => {
|
|
1013
|
+
if (!validate2(input)) throw new AppHostError("invalid_request");
|
|
1014
|
+
return call("desktop.files.getOperation", input);
|
|
1015
|
+
};
|
|
1016
|
+
return {
|
|
1017
|
+
bindTarget(input) {
|
|
1018
|
+
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");
|
|
1019
|
+
const { connection, ...rest } = input;
|
|
1020
|
+
return call("desktop.bindTarget", { ...rest, ...connection === void 0 ? {} : { connectionId: resolveClientConnection(connection, owner) } });
|
|
1021
|
+
},
|
|
1022
|
+
releaseTarget: (input) => call("desktop.releaseTarget", input),
|
|
1023
|
+
files: {
|
|
1024
|
+
...group("files"),
|
|
1025
|
+
getOperation: (input) => getOperation(input, validFileOperationQuery),
|
|
1026
|
+
async readFile(input, options = {}) {
|
|
1027
|
+
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");
|
|
1028
|
+
filesFeature();
|
|
1029
|
+
const { range: range2, ...params } = input;
|
|
1030
|
+
const wire = await call("desktop.files.openRead", params);
|
|
1031
|
+
const fetchFile = owner.fetchFor(wire.connectionId, wire.baseUrl);
|
|
1032
|
+
try {
|
|
1033
|
+
return await fetchFile(wire.baseUrl + "/", {
|
|
1034
|
+
...options.signal ? { signal: options.signal } : {},
|
|
1035
|
+
...range2 ? { headers: { Range: `bytes=${range2.start}-${range2.end ?? ""}` } } : {}
|
|
1036
|
+
});
|
|
1037
|
+
} catch (error) {
|
|
1038
|
+
owner.close(wire.connectionId);
|
|
1039
|
+
throw error;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
},
|
|
1043
|
+
clipboard: group("clipboard"),
|
|
1044
|
+
git: {
|
|
1045
|
+
...group("git"),
|
|
1046
|
+
getOperation: (input) => getOperation(input, validGitOperationQuery)
|
|
1047
|
+
},
|
|
1048
|
+
terminals: group("terminals"),
|
|
1049
|
+
windows: group("windows"),
|
|
1050
|
+
browser: group("browser"),
|
|
1051
|
+
pluginApps: group("pluginApps")
|
|
1052
|
+
};
|
|
967
1053
|
}
|
|
968
1054
|
function canonicalDesktopRequest(value) {
|
|
969
1055
|
if (!json(value)) throw new AppHostError("invalid_request");
|
|
@@ -1051,12 +1137,94 @@ function validProjectRequest(value) {
|
|
|
1051
1137
|
case "archive":
|
|
1052
1138
|
return object({ action: (v) => v === "archive", ...project })(value);
|
|
1053
1139
|
case "rebind":
|
|
1054
|
-
return object({ action: (v) => v === "rebind", ...
|
|
1140
|
+
return object({ action: (v) => v === "rebind", ...project, previousWorkspaceId: id2, expectedPath: text(32768) })(value);
|
|
1141
|
+
default:
|
|
1142
|
+
return false;
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
var validProjectSnapshot = (value) => object({
|
|
1146
|
+
dataScopeId: id2,
|
|
1147
|
+
projects: array(object({ workspaceId: id2, projectId: id2, name: text(1024), path: text(32768), available: bool, lastOpenedAt: count }, {
|
|
1148
|
+
defaultShell: text(4096),
|
|
1149
|
+
rootIdentity: object({ dev: text(32), ino: text(32) })
|
|
1150
|
+
}), 1e4)
|
|
1151
|
+
}, { selectedWorkspaceId: id2 })(value);
|
|
1152
|
+
|
|
1153
|
+
// src/local-workspace.ts
|
|
1154
|
+
var root2 = { rootPath: text(32768) };
|
|
1155
|
+
var identity = { identity: object({ dev: text(32), ino: text(32) }) };
|
|
1156
|
+
var file = { ...root2, path: text(32768) };
|
|
1157
|
+
var write = { ...file, requestId: id, content: text(125e4, true), originalContent: text(125e4, true) };
|
|
1158
|
+
var actionOf = (value) => value && typeof value === "object" ? Object.getOwnPropertyDescriptor(value, "action")?.value : void 0;
|
|
1159
|
+
function validLocalWorkspaceRequest(value) {
|
|
1160
|
+
const action2 = actionOf(value);
|
|
1161
|
+
const field = { action: enumeration(action2) };
|
|
1162
|
+
switch (action2) {
|
|
1163
|
+
case "pick":
|
|
1164
|
+
case "listOpeners":
|
|
1165
|
+
return object(field)(value);
|
|
1166
|
+
case "list":
|
|
1167
|
+
return object({ ...field, ...root2 }, { ...identity, path: text(32768, true) })(value);
|
|
1168
|
+
case "find":
|
|
1169
|
+
return object({ ...field, ...root2, query: text(1024) }, identity)(value);
|
|
1170
|
+
case "write":
|
|
1171
|
+
case "getWrite":
|
|
1172
|
+
return object({ ...field, ...write }, identity)(value);
|
|
1173
|
+
case "openWith":
|
|
1174
|
+
return object({ ...field, ...file, openerId: text(256) }, identity)(value);
|
|
1175
|
+
case "copyPath":
|
|
1176
|
+
return object({ ...field, ...file }, { ...identity, absolute: bool })(value);
|
|
1177
|
+
case "read":
|
|
1178
|
+
case "reveal":
|
|
1179
|
+
case "webPreview":
|
|
1180
|
+
return object({ ...field, ...file }, identity)(value);
|
|
1055
1181
|
default:
|
|
1056
1182
|
return false;
|
|
1057
1183
|
}
|
|
1058
1184
|
}
|
|
1059
|
-
var
|
|
1185
|
+
var bytes = (limit) => (value) => value instanceof ArrayBuffer && value.byteLength <= limit;
|
|
1186
|
+
var preview = object({
|
|
1187
|
+
path: text(32768),
|
|
1188
|
+
name: text(32768),
|
|
1189
|
+
language: text(4096),
|
|
1190
|
+
size: count,
|
|
1191
|
+
binary: bool,
|
|
1192
|
+
content: nullable(text(125e4, true)),
|
|
1193
|
+
scope: enumeration("project", "extra-root"),
|
|
1194
|
+
relativePath: text(32768),
|
|
1195
|
+
rootLabel: text(32768),
|
|
1196
|
+
previewBytes: nullable(bytes(50 * 1024 * 1024)),
|
|
1197
|
+
mediaType: enumeration(null, "image/avif", "image/bmp", "image/gif", "image/jpeg", "image/png", "image/webp"),
|
|
1198
|
+
imagePreviewError: enumeration(null, "image_too_large", "image_unsupported")
|
|
1199
|
+
}, {
|
|
1200
|
+
rootIdentity: identity.identity,
|
|
1201
|
+
documentPreview: object({ format: enumeration("pdf", "epub", "docx", "xlsx", "pptx"), bytes: bytes(64 * 1024 * 1024) })
|
|
1202
|
+
});
|
|
1203
|
+
var tree = object({
|
|
1204
|
+
...root2,
|
|
1205
|
+
entries: array(object({ path: text(32768), type: enumeration("file", "directory") }, { size: count }), 1e4)
|
|
1206
|
+
}, { truncated: bool });
|
|
1207
|
+
var found = object({ files: array(text(32768), 1e3), truncated: bool });
|
|
1208
|
+
var picked = object({ ...root2, ...identity, workspaceId: id });
|
|
1209
|
+
var url = object({ url: text(131072) });
|
|
1210
|
+
var openers = (value) => validDesktopResult("desktop.files.listOpeners", value);
|
|
1211
|
+
var empty2 = (value) => value === void 0;
|
|
1212
|
+
var checks = {
|
|
1213
|
+
pick: nullable(picked),
|
|
1214
|
+
list: tree,
|
|
1215
|
+
find: found,
|
|
1216
|
+
read: preview,
|
|
1217
|
+
write: preview,
|
|
1218
|
+
getWrite: nullable(preview),
|
|
1219
|
+
reveal: empty2,
|
|
1220
|
+
openWith: empty2,
|
|
1221
|
+
copyPath: empty2,
|
|
1222
|
+
listOpeners: openers,
|
|
1223
|
+
webPreview: url
|
|
1224
|
+
};
|
|
1225
|
+
function validLocalWorkspaceResult(value, action2) {
|
|
1226
|
+
return action2 ? checks[action2](value) : Object.values(checks).some((check) => check(value));
|
|
1227
|
+
}
|
|
1060
1228
|
|
|
1061
1229
|
// ../domain-contracts/src/app-host/model-providers.ts
|
|
1062
1230
|
var provider = text(256);
|
|
@@ -1065,8 +1233,8 @@ var limits = { contextWindow: count, maxOutputTokens: count };
|
|
|
1065
1233
|
function headerValues(check) {
|
|
1066
1234
|
return (value) => {
|
|
1067
1235
|
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1068
|
-
const
|
|
1069
|
-
return
|
|
1236
|
+
const keys3 = Object.keys(value);
|
|
1237
|
+
return keys3.length <= 128 && keys3.every((key) => /^[!#$%&'*+.^_`|~0-9A-Za-z-]{1,256}$/.test(key)) && object(Object.fromEntries(keys3.map((key) => [key, check])))(value);
|
|
1070
1238
|
};
|
|
1071
1239
|
}
|
|
1072
1240
|
var headers = headerValues(text(8192, true));
|
|
@@ -1096,14 +1264,15 @@ function validModelProviderConnections(value) {
|
|
|
1096
1264
|
var modelId = text(1024);
|
|
1097
1265
|
var effort = nullable(text(256));
|
|
1098
1266
|
var revision = text(8192);
|
|
1267
|
+
var accountGatewayProof = (value) => typeof value === "string" && /^[a-f0-9]{64}$/.test(value);
|
|
1099
1268
|
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);
|
|
1269
|
+
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
1270
|
}
|
|
1102
1271
|
var verifiedProvider = object({ model: modelId, checkedAt: count });
|
|
1103
1272
|
var verified = (value) => {
|
|
1104
1273
|
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1105
|
-
const
|
|
1106
|
-
return
|
|
1274
|
+
const keys3 = Object.keys(value);
|
|
1275
|
+
return keys3.length <= 4096 && keys3.every(provider) && object(Object.fromEntries(keys3.map((key) => [key, verifiedProvider])))(value);
|
|
1107
1276
|
};
|
|
1108
1277
|
var defaultsModel = object({ id: modelId, label: text(1024), provider: text(1024), providerName: provider }, {
|
|
1109
1278
|
reasoningEfforts: array(text(256, true)),
|
|
@@ -1121,7 +1290,7 @@ var validProviderDefaultsSnapshot = object({
|
|
|
1121
1290
|
verified,
|
|
1122
1291
|
fastModeAvailable: enumeration(false),
|
|
1123
1292
|
fastModeReason: text(1024)
|
|
1124
|
-
});
|
|
1293
|
+
}, { accountGatewayMatches: bool });
|
|
1125
1294
|
var validProviderConnectionTestResult = object({
|
|
1126
1295
|
status: enumeration("verified", "failed"),
|
|
1127
1296
|
detail: text(8192),
|
|
@@ -1139,7 +1308,6 @@ var SYSTEM_SETTINGS_SECTIONS = [
|
|
|
1139
1308
|
"permissions",
|
|
1140
1309
|
"personalization",
|
|
1141
1310
|
"billing",
|
|
1142
|
-
"connections",
|
|
1143
1311
|
"terminal",
|
|
1144
1312
|
"git",
|
|
1145
1313
|
"runtime",
|
|
@@ -1166,10 +1334,28 @@ var SYSTEM_SHORTCUT_IDS = [
|
|
|
1166
1334
|
"resetZoom",
|
|
1167
1335
|
"showShortcuts"
|
|
1168
1336
|
];
|
|
1337
|
+
var CHANNEL_SETTINGS_ACTIONS = [
|
|
1338
|
+
"snapshot",
|
|
1339
|
+
"runtimeStatus",
|
|
1340
|
+
"connect",
|
|
1341
|
+
"patch",
|
|
1342
|
+
"remove",
|
|
1343
|
+
"allowAdd",
|
|
1344
|
+
"allowRemove",
|
|
1345
|
+
"startRegistration",
|
|
1346
|
+
"registrationStatus",
|
|
1347
|
+
"cancelRegistration",
|
|
1348
|
+
"startRuntime",
|
|
1349
|
+
"stopRuntime"
|
|
1350
|
+
];
|
|
1351
|
+
var channelSettingsKey = /* @__PURE__ */ Symbol.for("nomi.workbench-channel-settings");
|
|
1352
|
+
var channelSettingsValue = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
1169
1353
|
var SYSTEM_METHODS = [
|
|
1170
1354
|
"system.projects",
|
|
1355
|
+
"system.workspace",
|
|
1171
1356
|
"system.extensions",
|
|
1172
1357
|
"system.modelProviders",
|
|
1358
|
+
"system.channelSettings",
|
|
1173
1359
|
"system.providerDefaults",
|
|
1174
1360
|
"system.open",
|
|
1175
1361
|
"system.getPresentationPreferences",
|
|
@@ -1265,10 +1451,21 @@ function validSystemInput(method, value) {
|
|
|
1265
1451
|
switch (method) {
|
|
1266
1452
|
case "system.projects":
|
|
1267
1453
|
return validProjectRequest(value);
|
|
1454
|
+
case "system.workspace":
|
|
1455
|
+
return validLocalWorkspaceRequest(value);
|
|
1268
1456
|
case "system.extensions":
|
|
1269
1457
|
return validExtensionRequest(value);
|
|
1270
1458
|
case "system.modelProviders":
|
|
1271
1459
|
return validModelProviderRequest(value);
|
|
1460
|
+
case "system.channelSettings": {
|
|
1461
|
+
const action2 = enumeration(...CHANNEL_SETTINGS_ACTIONS);
|
|
1462
|
+
if (object({ action: enumeration("allowRemove"), input: text() })(value)) return true;
|
|
1463
|
+
if (object({
|
|
1464
|
+
action: enumeration("connect", "patch", "allowAdd", "startRegistration"),
|
|
1465
|
+
input: channelSettingsValue
|
|
1466
|
+
})(value)) return true;
|
|
1467
|
+
return object({ action: (entry) => action2(entry) && !["allowRemove", "connect", "patch", "allowAdd", "startRegistration"].includes(entry) })(value);
|
|
1468
|
+
}
|
|
1272
1469
|
case "system.providerDefaults":
|
|
1273
1470
|
return validProviderDefaultsRequest(value);
|
|
1274
1471
|
case "system.setTheme":
|
|
@@ -1314,10 +1511,14 @@ function validSystemResult(method, value) {
|
|
|
1314
1511
|
switch (method) {
|
|
1315
1512
|
case "system.projects":
|
|
1316
1513
|
return validProjectSnapshot(value);
|
|
1514
|
+
case "system.workspace":
|
|
1515
|
+
return validLocalWorkspaceResult(value);
|
|
1317
1516
|
case "system.extensions":
|
|
1318
1517
|
return validExtensionResult(value);
|
|
1319
1518
|
case "system.modelProviders":
|
|
1320
1519
|
return validModelProviderConnections(value);
|
|
1520
|
+
case "system.channelSettings":
|
|
1521
|
+
return object({ value: channelSettingsValue })(value) || object({ error: enumeration("invalid_configuration", "conflict") })(value);
|
|
1321
1522
|
case "system.providerDefaults":
|
|
1322
1523
|
return validProviderDefaultsSnapshot(value) || validProviderConnectionTestResult(value);
|
|
1323
1524
|
case "system.open":
|
|
@@ -1352,8 +1553,13 @@ function createAppSystemApi(requester, connectionOwner) {
|
|
|
1352
1553
|
throw new AppHostError("invalid_request");
|
|
1353
1554
|
return requester.request(method, params);
|
|
1354
1555
|
}
|
|
1355
|
-
|
|
1556
|
+
const system = {
|
|
1356
1557
|
projects: (input) => send("system.projects", input),
|
|
1558
|
+
workspace: (async (input) => {
|
|
1559
|
+
const result = await send("system.workspace", input);
|
|
1560
|
+
if (!validLocalWorkspaceResult(result, input.action)) throw new AppHostError("host_unavailable");
|
|
1561
|
+
return result;
|
|
1562
|
+
}),
|
|
1357
1563
|
extensions: (input) => send("system.extensions", input),
|
|
1358
1564
|
modelProviders: (input) => send("system.modelProviders", input),
|
|
1359
1565
|
providerDefaults: (async (input) => {
|
|
@@ -1380,11 +1586,15 @@ function createAppSystemApi(requester, connectionOwner) {
|
|
|
1380
1586
|
getPresentationPreferences: () => send("system.getPresentationPreferences", {}),
|
|
1381
1587
|
setTheme: (theme) => send("system.setTheme", { theme }),
|
|
1382
1588
|
setWindowMaterial: (preference) => send("system.setWindowMaterial", { preference }),
|
|
1383
|
-
copyText: (
|
|
1384
|
-
openExternal: (
|
|
1589
|
+
copyText: (text3) => send("system.copyText", { text: text3 }),
|
|
1590
|
+
openExternal: (url2) => send("system.openExternal", { url: url2 }),
|
|
1385
1591
|
navigationReady: () => send("system.navigationReady", {}),
|
|
1386
1592
|
completeNavigation: (input) => send("system.completeNavigation", input)
|
|
1387
1593
|
};
|
|
1594
|
+
Object.defineProperty(system, channelSettingsKey, {
|
|
1595
|
+
value: (input) => send("system.channelSettings", input)
|
|
1596
|
+
});
|
|
1597
|
+
return system;
|
|
1388
1598
|
}
|
|
1389
1599
|
|
|
1390
1600
|
// src/window.ts
|
|
@@ -1544,20 +1754,51 @@ function createAppAuxiliarySessionsApi(rpc, streams) {
|
|
|
1544
1754
|
const { connection, ...rest } = input;
|
|
1545
1755
|
return { ...rest, connectionId: resolveClientConnection(connection, streams) };
|
|
1546
1756
|
};
|
|
1547
|
-
return {
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1757
|
+
return {
|
|
1758
|
+
getOptions: (input) => request("sessions.getAuxiliaryOptions", {
|
|
1759
|
+
sessionId: input.sessionId,
|
|
1760
|
+
connectionId: resolveClientConnection(input.connection, streams)
|
|
1761
|
+
}),
|
|
1762
|
+
async open(input) {
|
|
1763
|
+
const wire = await request("sessions.openAuxiliary", resolve(input));
|
|
1764
|
+
return { leaseId: wire.receipt.leaseId, sessionId: wire.receipt.sessionId, connection: createClientConnection(wire, streams) };
|
|
1765
|
+
},
|
|
1766
|
+
get: (input) => request("sessions.getAuxiliary", resolve(input)),
|
|
1767
|
+
close: (input) => request("sessions.closeAuxiliary", resolve(input))
|
|
1768
|
+
};
|
|
1551
1769
|
}
|
|
1552
1770
|
|
|
1553
1771
|
// src/workspace.ts
|
|
1772
|
+
var validPickOptions = object({}, { requestId: (value) => value === void 0 || id(value) });
|
|
1554
1773
|
function createAppWorkspaceApi(input) {
|
|
1555
1774
|
async function call(method, params) {
|
|
1556
1775
|
if (!validWorkspaceInput(method, params)) throw new AppHostError("invalid_request");
|
|
1557
1776
|
input.requireFeature();
|
|
1558
1777
|
return input.request(method, params);
|
|
1559
1778
|
}
|
|
1560
|
-
|
|
1779
|
+
function bindDirectory({ id: id3, displayName }) {
|
|
1780
|
+
return {
|
|
1781
|
+
id: id3,
|
|
1782
|
+
displayName,
|
|
1783
|
+
listFiles: ({ directory = "", cursor: cursor2 } = {}) => call("workspace.listFiles", {
|
|
1784
|
+
workspaceId: id3,
|
|
1785
|
+
directory,
|
|
1786
|
+
...cursor2 === void 0 ? {} : { cursor: cursor2 }
|
|
1787
|
+
}),
|
|
1788
|
+
readText: (path) => call("workspace.readText", { workspaceId: id3, path })
|
|
1789
|
+
};
|
|
1790
|
+
}
|
|
1791
|
+
return {
|
|
1792
|
+
async pick(options = {}) {
|
|
1793
|
+
if (!validPickOptions(options)) throw new AppHostError("invalid_request");
|
|
1794
|
+
const selected = await call("workspace.select", { requestId: options.requestId ?? crypto.randomUUID() });
|
|
1795
|
+
return selected === null ? null : bindDirectory(selected);
|
|
1796
|
+
},
|
|
1797
|
+
async open(id3) {
|
|
1798
|
+
return bindDirectory(await call("workspace.get", { workspaceId: id3 }));
|
|
1799
|
+
},
|
|
1800
|
+
getSelection: (x) => call("workspace.getSelection", x)
|
|
1801
|
+
};
|
|
1561
1802
|
}
|
|
1562
1803
|
|
|
1563
1804
|
// src/session-resources.ts
|
|
@@ -1723,7 +1964,8 @@ var APP_HOST_METHODS = [
|
|
|
1723
1964
|
...ATTACHMENTS_METHODS,
|
|
1724
1965
|
...AUXILIARY_METHODS,
|
|
1725
1966
|
...SYSTEM_METHODS,
|
|
1726
|
-
...WINDOW_METHODS
|
|
1967
|
+
...WINDOW_METHODS,
|
|
1968
|
+
...WORKBENCH_COMPUTER_METHODS
|
|
1727
1969
|
];
|
|
1728
1970
|
|
|
1729
1971
|
// src/transport/fetch-client.ts
|
|
@@ -1833,10 +2075,10 @@ function createPageFetchClient(options) {
|
|
|
1833
2075
|
s.wake = void 0;
|
|
1834
2076
|
if (s.stopped) return;
|
|
1835
2077
|
}
|
|
1836
|
-
const
|
|
2078
|
+
const bytes2 = new Uint8Array(item.value.subarray(offset, offset + FETCH_CHUNK_BYTES));
|
|
1837
2079
|
s.credit--;
|
|
1838
|
-
offset +=
|
|
1839
|
-
send({ protocol: 2, type: "fetch-chunk", id: s.id, direction: "upload", sequence: s.uploadSequence++, bytes });
|
|
2080
|
+
offset += bytes2.byteLength;
|
|
2081
|
+
send({ protocol: 2, type: "fetch-chunk", id: s.id, direction: "upload", sequence: s.uploadSequence++, bytes: bytes2 });
|
|
1840
2082
|
if (s.stopped || closed) return;
|
|
1841
2083
|
touch(s);
|
|
1842
2084
|
}
|
|
@@ -2037,11 +2279,11 @@ var hostFailure = (reason, requestId) => {
|
|
|
2037
2279
|
}
|
|
2038
2280
|
);
|
|
2039
2281
|
};
|
|
2040
|
-
function
|
|
2282
|
+
function record2(value) {
|
|
2041
2283
|
return value !== null && typeof value === "object" && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
2042
2284
|
}
|
|
2043
|
-
function
|
|
2044
|
-
if (!
|
|
2285
|
+
function keys2(value, required, optional = []) {
|
|
2286
|
+
if (!record2(value)) return false;
|
|
2045
2287
|
const own = Reflect.ownKeys(value);
|
|
2046
2288
|
return required.every((k) => Object.hasOwn(value, k)) && own.every(
|
|
2047
2289
|
(k) => typeof k === "string" && (required.includes(k) || optional.includes(k)) && Object.getOwnPropertyDescriptor(value, k)?.enumerable && Object.hasOwn(Object.getOwnPropertyDescriptor(value, k), "value")
|
|
@@ -2063,7 +2305,7 @@ function json3(value, ancestors = /* @__PURE__ */ new Set()) {
|
|
|
2063
2305
|
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
2064
2306
|
return true;
|
|
2065
2307
|
if (typeof value === "number") return Number.isFinite(value);
|
|
2066
|
-
if (typeof value !== "object" || !
|
|
2308
|
+
if (typeof value !== "object" || !record2(value) && !Array.isArray(value) || ancestors.has(value))
|
|
2067
2309
|
return false;
|
|
2068
2310
|
if (Array.isArray(value) && (Object.getPrototypeOf(value) !== Array.prototype || Reflect.ownKeys(value).length !== value.length + 1))
|
|
2069
2311
|
return false;
|
|
@@ -2080,15 +2322,30 @@ function json3(value, ancestors = /* @__PURE__ */ new Set()) {
|
|
|
2080
2322
|
}
|
|
2081
2323
|
function payloadSize(value) {
|
|
2082
2324
|
if (value instanceof Uint8Array) return value.byteLength;
|
|
2083
|
-
if (
|
|
2084
|
-
const { bytes, ...metadata } = value;
|
|
2085
|
-
return
|
|
2325
|
+
if (record2(value) && value.bytes instanceof Uint8Array) {
|
|
2326
|
+
const { bytes: bytes2, ...metadata } = value;
|
|
2327
|
+
return bytes2.byteLength + new TextEncoder().encode(JSON.stringify(metadata)).byteLength;
|
|
2086
2328
|
}
|
|
2087
2329
|
if (!json3(value)) throw failure("invalid_request");
|
|
2088
2330
|
return new TextEncoder().encode(JSON.stringify(value)).byteLength;
|
|
2089
2331
|
}
|
|
2332
|
+
function responsePayloadFits(method, value) {
|
|
2333
|
+
if (value === void 0) return true;
|
|
2334
|
+
if (method === "system.workspace" && record2(value)) {
|
|
2335
|
+
const { previewBytes, documentPreview, ...metadata } = value;
|
|
2336
|
+
const image = previewBytes instanceof ArrayBuffer;
|
|
2337
|
+
const document = record2(documentPreview) && documentPreview.bytes instanceof ArrayBuffer;
|
|
2338
|
+
if (image || document) {
|
|
2339
|
+
return !(image && document) && payloadSize({
|
|
2340
|
+
...metadata,
|
|
2341
|
+
...document ? { documentPreview: { format: documentPreview.format } } : {}
|
|
2342
|
+
}) <= APP_HOST_MAX_PAYLOAD_BYTES;
|
|
2343
|
+
}
|
|
2344
|
+
}
|
|
2345
|
+
return payloadSize(value) <= APP_HOST_MAX_PAYLOAD_BYTES;
|
|
2346
|
+
}
|
|
2090
2347
|
function validContext(value) {
|
|
2091
|
-
return
|
|
2348
|
+
return keys2(value, [
|
|
2092
2349
|
"appId",
|
|
2093
2350
|
"appVersion",
|
|
2094
2351
|
"installationId",
|
|
@@ -2106,32 +2363,34 @@ function validContext(value) {
|
|
|
2106
2363
|
"hostVersion",
|
|
2107
2364
|
"hostApiVersion",
|
|
2108
2365
|
"locale"
|
|
2109
|
-
].every((k) => nonempty(value[k])) && ["bundled", "remote"].includes(value.uiType) && ["light", "dark"].includes(value.theme) && Number.isSafeInteger(value.storageQuotaBytes) && value.storageQuotaBytes > 0 &&
|
|
2110
|
-
(c) =>
|
|
2366
|
+
].every((k) => nonempty(value[k])) && ["bundled", "remote"].includes(value.uiType) && ["light", "dark"].includes(value.theme) && Number.isSafeInteger(value.storageQuotaBytes) && value.storageQuotaBytes > 0 && record2(value.capabilities) && Object.values(value.capabilities).every(
|
|
2367
|
+
(c) => keys2(c, ["granted"], ["reason"]) && typeof c.granted === "boolean" && (!Object.hasOwn(c, "reason") || typeof c.reason === "string")
|
|
2111
2368
|
);
|
|
2112
2369
|
}
|
|
2113
2370
|
function validEvent(value) {
|
|
2114
|
-
if (!
|
|
2371
|
+
if (!record2(value)) return false;
|
|
2115
2372
|
if (validCommandInvocation(value) || validResourceChanged(value)) return true;
|
|
2116
2373
|
if (validSystemEvent(value)) return true;
|
|
2117
2374
|
if (validWindowEvent(value)) return true;
|
|
2118
2375
|
if (validDesktopEvent(value)) return true;
|
|
2376
|
+
if (validWorkbenchComputerEvent(value)) return true;
|
|
2119
2377
|
switch (value.type) {
|
|
2120
2378
|
case "service-changed":
|
|
2121
|
-
return
|
|
2379
|
+
return keys2(value, ["type", "service"]) && validServiceStatus(value.service);
|
|
2122
2380
|
case "visibility":
|
|
2123
|
-
return
|
|
2381
|
+
return keys2(value, ["type", "visible"]) && typeof value.visible === "boolean";
|
|
2124
2382
|
case "context-changed":
|
|
2125
|
-
return
|
|
2383
|
+
return keys2(value, ["type", "context"]) && validContext(value.context);
|
|
2126
2384
|
case "connection-revoked":
|
|
2127
|
-
return
|
|
2385
|
+
return keys2(value, ["type", "reason"]) && typeof value.reason === "string";
|
|
2128
2386
|
case "before-unload":
|
|
2129
|
-
return
|
|
2387
|
+
return keys2(value, ["type", "reason"]) && ["switch", "reload", "disable", "quit"].includes(value.reason);
|
|
2130
2388
|
default:
|
|
2131
2389
|
return false;
|
|
2132
2390
|
}
|
|
2133
2391
|
}
|
|
2134
2392
|
function validResult(method, value) {
|
|
2393
|
+
if (isWorkbenchComputerMethod(method)) return validWorkbenchComputerResult(method, value);
|
|
2135
2394
|
if (isCommandsMethod(method)) return validCommandReceipt(value);
|
|
2136
2395
|
if (isResourceCatalogMethod(method))
|
|
2137
2396
|
return validResourceCatalogResult(method, value);
|
|
@@ -2151,20 +2410,20 @@ function validResult(method, value) {
|
|
|
2151
2410
|
return validServiceResult(method, value);
|
|
2152
2411
|
switch (method) {
|
|
2153
2412
|
case "negotiate":
|
|
2154
|
-
return
|
|
2413
|
+
return keys2(value, ["features"]) && dataArray(value.features) && value.features.length <= APP_HOST_FEATURES.length && new Set(value.features).size === value.features.length && value.features.every(
|
|
2155
2414
|
(f) => APP_HOST_FEATURES.includes(f)
|
|
2156
2415
|
);
|
|
2157
2416
|
case "connect":
|
|
2158
2417
|
case "getContext":
|
|
2159
2418
|
return validContext(value);
|
|
2160
2419
|
case "storage.get":
|
|
2161
|
-
return
|
|
2420
|
+
return keys2(value, ["found"], ["value"]) && (value.found === false && !Object.hasOwn(value, "value") || value.found === true && Object.hasOwn(value, "value") && json3(value.value));
|
|
2162
2421
|
case "storage.putFile":
|
|
2163
|
-
return
|
|
2422
|
+
return keys2(value, ["id", "name", "size"]) && nonempty(value.id) && nonempty(value.name) && Number.isSafeInteger(value.size) && value.size >= 0;
|
|
2164
2423
|
case "storage.readFile":
|
|
2165
2424
|
return value instanceof Uint8Array;
|
|
2166
2425
|
case "auth.openLogin":
|
|
2167
|
-
return
|
|
2426
|
+
return keys2(value, ["status"], ["callbackUrl"]) && (value.status === "cancelled" && !Object.hasOwn(value, "callbackUrl") || value.status === "completed" && nonempty(value.callbackUrl));
|
|
2168
2427
|
default:
|
|
2169
2428
|
return value === void 0;
|
|
2170
2429
|
}
|
|
@@ -2228,7 +2487,7 @@ var DocumentConnection = class {
|
|
|
2228
2487
|
}
|
|
2229
2488
|
pagehide = () => this.close(failure("connection_revoked"));
|
|
2230
2489
|
receivePort = (event) => {
|
|
2231
|
-
if (event.source !== this.page || !
|
|
2490
|
+
if (event.source !== this.page || !keys2(event.data, ["type", "protocol"]) || event.data.type !== APP_HOST_PORT || event.data.protocol !== APP_HOST_PROTOCOL || event.ports.length !== 1)
|
|
2232
2491
|
return;
|
|
2233
2492
|
const port = event.ports[0];
|
|
2234
2493
|
if (this.port || this.closed) {
|
|
@@ -2270,7 +2529,7 @@ var DocumentConnection = class {
|
|
|
2270
2529
|
receive = (event) => {
|
|
2271
2530
|
const data = event.data;
|
|
2272
2531
|
try {
|
|
2273
|
-
if (!
|
|
2532
|
+
if (!record2(data)) throw failure("host_unavailable");
|
|
2274
2533
|
const frameType = Object.getOwnPropertyDescriptor(data, "type")?.value;
|
|
2275
2534
|
if (typeof frameType === "string" && frameType.startsWith("fetch-")) {
|
|
2276
2535
|
if (!isPageFetchFrame(data)) throw failure("host_unavailable");
|
|
@@ -2288,7 +2547,7 @@ var DocumentConnection = class {
|
|
|
2288
2547
|
return;
|
|
2289
2548
|
}
|
|
2290
2549
|
if (data.type === "event") {
|
|
2291
|
-
if (!
|
|
2550
|
+
if (!keys2(data, ["protocol", "type", "sequence", "event"]) || !Number.isSafeInteger(data.sequence) || data.sequence <= 0 || !validEvent(data.event) || payloadSize(data.event) > APP_HOST_MAX_PAYLOAD_BYTES)
|
|
2292
2551
|
throw failure("host_unavailable");
|
|
2293
2552
|
if (data.sequence <= this.sequence) return;
|
|
2294
2553
|
if (data.sequence !== this.sequence + 1)
|
|
@@ -2308,6 +2567,7 @@ var DocumentConnection = class {
|
|
|
2308
2567
|
}
|
|
2309
2568
|
if (validSystemEvent(appEvent)) this.requireFeature("system-ui-v1");
|
|
2310
2569
|
if (validWindowEvent(appEvent)) this.requireFeature("window-chrome-v1");
|
|
2570
|
+
if (validWorkbenchComputerEvent(appEvent)) this.requireFeature(WORKBENCH_COMPUTER_FEATURE);
|
|
2311
2571
|
const observers = [...this.listeners];
|
|
2312
2572
|
if (appEvent.type === "connection-revoked")
|
|
2313
2573
|
this.close(failure("connection_revoked"));
|
|
@@ -2324,13 +2584,13 @@ var DocumentConnection = class {
|
|
|
2324
2584
|
const p = this.pending.get(data.id);
|
|
2325
2585
|
if (!p) return;
|
|
2326
2586
|
if (data.ok === true) {
|
|
2327
|
-
if (!
|
|
2587
|
+
if (!keys2(data, ["protocol", "type", "id", "ok"], ["value"]) || !validResult(p.method, data.value) || !responsePayloadFits(p.method, data.value))
|
|
2328
2588
|
throw failure("host_unavailable");
|
|
2329
2589
|
clearTimeout(p.timer);
|
|
2330
2590
|
this.pending.delete(data.id);
|
|
2331
2591
|
p.resolve(data.value);
|
|
2332
2592
|
} else {
|
|
2333
|
-
if (!
|
|
2593
|
+
if (!keys2(data, ["protocol", "type", "id", "ok", "error"]) || data.ok !== false || !isAppHostErrorInfo(data.error) || payloadSize(data.error) > APP_HOST_MAX_PAYLOAD_BYTES)
|
|
2334
2594
|
throw failure("host_unavailable");
|
|
2335
2595
|
const error = new AppHostError(
|
|
2336
2596
|
data.error.code,
|
|
@@ -2386,7 +2646,7 @@ var DocumentConnection = class {
|
|
|
2386
2646
|
requireFeature: () => this.requireFeature("session-controls-v1"),
|
|
2387
2647
|
request: (method, params2) => this.request(method, params2)
|
|
2388
2648
|
});
|
|
2389
|
-
|
|
2649
|
+
const host = {
|
|
2390
2650
|
hasFeature: (feature) => this.features.has(feature),
|
|
2391
2651
|
commands: createAppCommandsApi({
|
|
2392
2652
|
requireFeature: () => this.requireFeature("commands-v1"),
|
|
@@ -2444,9 +2704,9 @@ var DocumentConnection = class {
|
|
|
2444
2704
|
},
|
|
2445
2705
|
this.fetchClient
|
|
2446
2706
|
),
|
|
2447
|
-
sessions:
|
|
2448
|
-
conversationPreparation,
|
|
2449
|
-
createAppSessionsApi(
|
|
2707
|
+
sessions: {
|
|
2708
|
+
preparation: conversationPreparation,
|
|
2709
|
+
...createAppSessionsApi(
|
|
2450
2710
|
{
|
|
2451
2711
|
requireFeature: () => this.requireFeature("session-resources-v1"),
|
|
2452
2712
|
request: (method, params2) => this.request(
|
|
@@ -2456,14 +2716,14 @@ var DocumentConnection = class {
|
|
|
2456
2716
|
},
|
|
2457
2717
|
this.fetchClient
|
|
2458
2718
|
),
|
|
2459
|
-
createAppAuxiliarySessionsApi(
|
|
2719
|
+
auxiliary: createAppAuxiliarySessionsApi(
|
|
2460
2720
|
{
|
|
2461
2721
|
requireFeature: () => this.requireFeature("auxiliary-sessions-v1"),
|
|
2462
2722
|
request: (method, params2) => this.request(method, params2)
|
|
2463
2723
|
},
|
|
2464
2724
|
this.fetchClient
|
|
2465
2725
|
)
|
|
2466
|
-
|
|
2726
|
+
},
|
|
2467
2727
|
workspace: Object.assign(
|
|
2468
2728
|
{ list: catalog.list },
|
|
2469
2729
|
createAppWorkspaceApi({
|
|
@@ -2503,8 +2763,8 @@ var DocumentConnection = class {
|
|
|
2503
2763
|
});
|
|
2504
2764
|
},
|
|
2505
2765
|
readFile: async (id3) => {
|
|
2506
|
-
const
|
|
2507
|
-
return new Response(new Uint8Array(
|
|
2766
|
+
const bytes2 = await this.request("storage.readFile", { id: id3 });
|
|
2767
|
+
return new Response(new Uint8Array(bytes2), {
|
|
2508
2768
|
headers: { "content-type": "application/octet-stream" }
|
|
2509
2769
|
});
|
|
2510
2770
|
},
|
|
@@ -2512,9 +2772,29 @@ var DocumentConnection = class {
|
|
|
2512
2772
|
},
|
|
2513
2773
|
auth: { openLogin: (input) => this.login(input) }
|
|
2514
2774
|
};
|
|
2775
|
+
if (host.hasFeature(WORKBENCH_COMPUTER_FEATURE)) {
|
|
2776
|
+
const computer = {
|
|
2777
|
+
availability: () => this.request("workbench.computer.availability", {}),
|
|
2778
|
+
setConversation: (sessionId) => this.request("workbench.computer.setConversation", { sessionId }),
|
|
2779
|
+
preparePrompt: (sessionId, inputId) => this.request("workbench.computer.preparePrompt", { sessionId, inputId }),
|
|
2780
|
+
stopLocal: (sessionId, runId) => this.request("workbench.computer.stopLocal", { sessionId, runId }),
|
|
2781
|
+
getActivity: (sessionId) => this.request("workbench.computer.getActivity", { sessionId }),
|
|
2782
|
+
reply: (input) => this.request("workbench.computer.reply", input),
|
|
2783
|
+
control: (input) => this.request("workbench.computer.control", input),
|
|
2784
|
+
shareWindow: () => this.request("workbench.computer.shareWindow", {}),
|
|
2785
|
+
onActivity: (listener) => host.onEvent((event) => {
|
|
2786
|
+
if (event.type === "workbench-computer-activity") listener(event.update);
|
|
2787
|
+
}),
|
|
2788
|
+
onPrompt: (listener) => host.onEvent((event) => {
|
|
2789
|
+
if (event.type === "workbench-computer-prompt") listener(event.interaction);
|
|
2790
|
+
})
|
|
2791
|
+
};
|
|
2792
|
+
Object.defineProperty(host, workbenchComputerKey, { value: computer });
|
|
2793
|
+
}
|
|
2794
|
+
return host;
|
|
2515
2795
|
}
|
|
2516
2796
|
async login(input) {
|
|
2517
|
-
if (!
|
|
2797
|
+
if (!keys2(input, ["url"]) || !nonempty(input.url))
|
|
2518
2798
|
throw failure("invalid_request");
|
|
2519
2799
|
try {
|
|
2520
2800
|
if (new URL(input.url).protocol !== "https:")
|
|
@@ -2530,10 +2810,11 @@ var DocumentConnection = class {
|
|
|
2530
2810
|
([key, value]) => ["key", "id", "name"].includes(key) && !nonempty(value)
|
|
2531
2811
|
) || this.pending.size >= APP_HOST_MAX_PENDING || payloadSize(params) > APP_HOST_MAX_PAYLOAD_BYTES)
|
|
2532
2812
|
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;
|
|
2813
|
+
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
2814
|
const selectionRequestId = method === "workspace.select" ? params.requestId : void 0;
|
|
2535
2815
|
let timeout = APP_HOST_REQUEST_TIMEOUT_MS;
|
|
2536
|
-
if (method === "
|
|
2816
|
+
if (method === "workbench.computer.stopLocal") timeout = 1e3;
|
|
2817
|
+
if (method === "auth.openLogin" || method === "workspace.select" || method === "workbench.computer.shareWindow" || method === "system.workspace" && "action" in params && params.action === "pick")
|
|
2537
2818
|
timeout = APP_HOST_LOGIN_TRANSPORT_TIMEOUT_MS;
|
|
2538
2819
|
if (method === "system.extensions") {
|
|
2539
2820
|
const { operation } = params;
|
|
@@ -2573,7 +2854,7 @@ var DocumentConnection = class {
|
|
|
2573
2854
|
};
|
|
2574
2855
|
var documents = /* @__PURE__ */ new WeakMap();
|
|
2575
2856
|
async function connectAppHost(options) {
|
|
2576
|
-
if (!
|
|
2857
|
+
if (!keys2(options, ["hostApi"]) || !nonempty(options.hostApi))
|
|
2577
2858
|
throw failure("invalid_request");
|
|
2578
2859
|
if (typeof window === "undefined") throw failure("host_unavailable");
|
|
2579
2860
|
let connection = documents.get(window);
|
|
@@ -2597,8 +2878,8 @@ function copyBoundedJson(value, options) {
|
|
|
2597
2878
|
const { maxBytes, maxDepth } = options;
|
|
2598
2879
|
const ancestors = /* @__PURE__ */ new Set();
|
|
2599
2880
|
let budget = maxBytes;
|
|
2600
|
-
const spend = (
|
|
2601
|
-
budget -= new TextEncoder().encode(
|
|
2881
|
+
const spend = (text3) => {
|
|
2882
|
+
budget -= new TextEncoder().encode(text3).byteLength;
|
|
2602
2883
|
if (budget < 0) throw new JsonCopyError("too_large");
|
|
2603
2884
|
};
|
|
2604
2885
|
const copy = (item, depth) => {
|
|
@@ -2713,9 +2994,9 @@ function validatePluginAppComposerContexts(value) {
|
|
|
2713
2994
|
return validate(parsePluginAppComposerContexts, value);
|
|
2714
2995
|
}
|
|
2715
2996
|
function parsePluginAppConversationInput(value) {
|
|
2716
|
-
const input =
|
|
2997
|
+
const input = record3(copyPluginAppJson(value, PLUGIN_APP_INPUT_LIMITS.handoffBytes + 32 * 1024));
|
|
2717
2998
|
fields3(input, ["source", "lease", "requestId", "expectedRevision", "text", "data"]);
|
|
2718
|
-
const lease =
|
|
2999
|
+
const lease = record3(input.lease);
|
|
2719
3000
|
fields3(lease, ["token", "backendGeneration"]);
|
|
2720
3001
|
if (typeof input.text !== "string" || [...input.text].length > PLUGIN_APP_INPUT_LIMITS.messageCharacters || !input.text.trim())
|
|
2721
3002
|
throw new InputError("plugin_app_invalid_message");
|
|
@@ -2728,7 +3009,7 @@ function parsePluginAppConversationInput(value) {
|
|
|
2728
3009
|
data: copyPluginAppJson(input.data, PLUGIN_APP_INPUT_LIMITS.handoffBytes)
|
|
2729
3010
|
};
|
|
2730
3011
|
}
|
|
2731
|
-
function
|
|
3012
|
+
function record3(value) {
|
|
2732
3013
|
if (!value || typeof value !== "object" || Array.isArray(value)) throw new InputError("plugin_app_invalid_request");
|
|
2733
3014
|
return value;
|
|
2734
3015
|
}
|
|
@@ -2744,7 +3025,7 @@ function revision2(value) {
|
|
|
2744
3025
|
return value;
|
|
2745
3026
|
}
|
|
2746
3027
|
function parsePluginAppSource(value) {
|
|
2747
|
-
const input =
|
|
3028
|
+
const input = record3(copyPluginAppJson(value, 4096));
|
|
2748
3029
|
fields3(input, ["sessionId", "appId"]);
|
|
2749
3030
|
return { sessionId: identifier2(input.sessionId), appId: identifier2(input.appId) };
|
|
2750
3031
|
}
|