@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/protocol.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 keys2 = Reflect.ownKeys(value);
|
|
44
|
+
if (!keys2.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 keys2 = Reflect.ownKeys(v);
|
|
170
|
+
if (list && keys2.length !== v.length + 1) return false;
|
|
171
|
+
return keys2.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,124 +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/agent.ts
|
|
187
|
-
function fields(value, required, optional = []) {
|
|
188
|
-
if (!value || typeof value !== "object" || Array.isArray(value) || ![Object.prototype, null].includes(Object.getPrototypeOf(value)))
|
|
189
|
-
return false;
|
|
190
|
-
return required.every((key) => Object.hasOwn(value, key)) && Reflect.ownKeys(value).every((key) => {
|
|
191
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
192
|
-
return typeof key === "string" && [...required, ...optional].includes(key) && descriptor.enumerable && Object.hasOwn(descriptor, "value");
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
var text2 = (value) => typeof value === "string" && value.trim().length > 0;
|
|
196
|
-
var workspaceId = (value) => typeof value === "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value);
|
|
197
|
-
function rows(value, check) {
|
|
198
|
-
return Array.isArray(value) && value.length <= 1024 && value.every(check);
|
|
199
|
-
}
|
|
200
|
-
function validAgentInput(method, value) {
|
|
201
|
-
if (!json(value)) return false;
|
|
202
|
-
if (method === "agent.listModels") return fields(value, []);
|
|
203
|
-
if (method === "agent.resolveSkills") return fields(value, ["skillIds"]) && Array.isArray(value.skillIds) && value.skillIds.length <= 128 && value.skillIds.every((v) => text(256)(v)) && new Set(value.skillIds).size === value.skillIds.length;
|
|
204
|
-
if (method !== "agent.getConnection" || !fields(value, [], ["workspaceId", "executionRoot", "privateSessionId"])) return false;
|
|
205
|
-
return (!Object.hasOwn(value, "workspaceId") || workspaceId(value.workspaceId)) && (!Object.hasOwn(value, "privateSessionId") || workspaceId(value.privateSessionId) && !Object.hasOwn(value, "workspaceId") && !Object.hasOwn(value, "executionRoot")) && (!Object.hasOwn(value, "executionRoot") || workspaceId(value.executionRoot) && Object.hasOwn(value, "workspaceId"));
|
|
206
|
-
}
|
|
207
|
-
function validAgentResult(method, value) {
|
|
208
|
-
if (!json(value)) return false;
|
|
209
|
-
switch (method) {
|
|
210
|
-
case "agent.getConnection":
|
|
211
|
-
return fields(value, ["connectionId", "baseUrl"], ["cwd", "defaultTaskLocation"]) && (!Object.hasOwn(value, "defaultTaskLocation") || value.defaultTaskLocation === "current" || value.defaultTaskLocation === "worktree") && (!Object.hasOwn(value, "cwd") || text2(value.cwd)) && text2(value.connectionId) && value.baseUrl === `https://app-host.invalid/connections/${value.connectionId}` && /^[A-Za-z0-9-]+$/.test(value.connectionId);
|
|
212
|
-
case "agent.listModels":
|
|
213
|
-
return rows(
|
|
214
|
-
value,
|
|
215
|
-
(row) => fields(row, ["id", "name"], ["reasoning", "reasoningEfforts", "vision", "contextWindow", "outputLimit", "inputModalities", "toolCalling"]) && text2(row.id) && text2(row.name) && ["reasoning", "vision", "toolCalling"].every((key) => !Object.hasOwn(row, key) || typeof row[key] === "boolean") && ["contextWindow", "outputLimit"].every((key) => !Object.hasOwn(row, key) || Number.isSafeInteger(row[key]) && row[key] > 0) && ["reasoningEfforts", "inputModalities"].every((key) => !Object.hasOwn(row, key) || Array.isArray(row[key]) && row[key].length <= 32 && row[key].every((value2) => text(128)(value2)) && new Set(row[key]).size === row[key].length)
|
|
216
|
-
);
|
|
217
|
-
case "agent.resolveSkills":
|
|
218
|
-
return rows(
|
|
219
|
-
value,
|
|
220
|
-
(row) => fields(row, ["type", "name", "path"]) && row.type === "skill" && text2(row.name) && text2(row.path)
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
return false;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// ../domain-contracts/src/app-host/service.ts
|
|
227
|
-
function fields2(value, required, optional = []) {
|
|
228
|
-
if (!value || typeof value !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(value)))
|
|
229
|
-
return false;
|
|
230
|
-
return required.every((k) => Object.hasOwn(value, k)) && Reflect.ownKeys(value).every((k) => {
|
|
231
|
-
const d = Object.getOwnPropertyDescriptor(value, k);
|
|
232
|
-
return typeof k === "string" && [...required, ...optional].includes(k) && d.enumerable && Object.hasOwn(d, "value");
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
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(
|
|
236
|
-
v
|
|
237
|
-
);
|
|
238
|
-
function json2(value, ancestors = /* @__PURE__ */ new Set(), depth = 0) {
|
|
239
|
-
if (depth > 100) return false;
|
|
240
|
-
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
241
|
-
return true;
|
|
242
|
-
if (typeof value === "number") return Number.isFinite(value);
|
|
243
|
-
if (typeof value !== "object" || ancestors.has(value)) return false;
|
|
244
|
-
const array2 = Array.isArray(value);
|
|
245
|
-
if (array2 ? Object.getPrototypeOf(value) !== Array.prototype || Reflect.ownKeys(value).length !== value.length + 1 : ![Object.prototype, null].includes(Object.getPrototypeOf(value)))
|
|
246
|
-
return false;
|
|
247
|
-
ancestors.add(value);
|
|
248
|
-
const result = Reflect.ownKeys(value).every((k) => {
|
|
249
|
-
if (array2 && k === "length") return true;
|
|
250
|
-
const d = Object.getOwnPropertyDescriptor(value, k);
|
|
251
|
-
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);
|
|
252
|
-
});
|
|
253
|
-
ancestors.delete(value);
|
|
254
|
-
return result;
|
|
255
|
-
}
|
|
256
|
-
function validServiceStatus(value) {
|
|
257
|
-
return fields2(value, ["state"], ["reason", "instanceId", "apiVersion"]) && [
|
|
258
|
-
"absent",
|
|
259
|
-
"unauthorized",
|
|
260
|
-
"stopped",
|
|
261
|
-
"starting",
|
|
262
|
-
"recovering",
|
|
263
|
-
"ready",
|
|
264
|
-
"failed"
|
|
265
|
-
].includes(value.state) && (!Object.hasOwn(value, "reason") || [
|
|
266
|
-
"dependency_missing",
|
|
267
|
-
"service_start_failed",
|
|
268
|
-
"service_unavailable",
|
|
269
|
-
"result_unknown",
|
|
270
|
-
"incompatible",
|
|
271
|
-
"revoked"
|
|
272
|
-
].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"));
|
|
273
|
-
}
|
|
274
|
-
function validWork(value) {
|
|
275
|
-
return fields2(value, ["requestId", "state", "updatedAt"], ["result", "error"]) && typeof value.requestId === "string" && HOST_REQUEST_ID.test(value.requestId) && [
|
|
276
|
-
"not_accepted",
|
|
277
|
-
"accepted",
|
|
278
|
-
"running",
|
|
279
|
-
"completed",
|
|
280
|
-
"failed",
|
|
281
|
-
"interrupted",
|
|
282
|
-
"unknown"
|
|
283
|
-
].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(
|
|
284
|
-
value.updatedAt
|
|
285
|
-
) && Number.isFinite(Date.parse(value.updatedAt)) && ["result", "error"].every(
|
|
286
|
-
(k) => !Object.hasOwn(value, k) || json2(value[k]) && new TextEncoder().encode(JSON.stringify(value[k])).length <= 16384
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
function validServiceResult(method, value) {
|
|
290
|
-
switch (method) {
|
|
291
|
-
case "service.getStatus":
|
|
292
|
-
return validServiceStatus(value);
|
|
293
|
-
case "service.getConnection":
|
|
294
|
-
return fields2(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);
|
|
295
|
-
case "service.getWork":
|
|
296
|
-
return validWork(value);
|
|
297
|
-
case "service.listWork":
|
|
298
|
-
return Array.isArray(value) && value.length <= 5120 && value.every(validWork) && new Set(value.map((w) => w.requestId)).size === value.length;
|
|
299
|
-
case "service.interruptWork":
|
|
300
|
-
return fields2(value, ["requested"]) && typeof value.requested === "boolean";
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
190
|
// ../domain-contracts/src/app-host/fetch.ts
|
|
305
191
|
var APP_HOST_FEATURES = [
|
|
306
192
|
"fetch-v1",
|
|
@@ -325,7 +211,8 @@ var APP_HOST_FEATURES = [
|
|
|
325
211
|
"window-update-check-v1",
|
|
326
212
|
"embedded-browser-v1",
|
|
327
213
|
"browser-binding-invalidation-v1",
|
|
328
|
-
"browser-capture-preview-v1"
|
|
214
|
+
"browser-capture-preview-v1",
|
|
215
|
+
"workbench-computer-v1"
|
|
329
216
|
];
|
|
330
217
|
var FETCH_CHUNK_BYTES = 64 * 1024;
|
|
331
218
|
var FETCH_INLINE_BODY_BYTES = 8 * 1024;
|
|
@@ -358,10 +245,10 @@ function isPageFetchFrame(value) {
|
|
|
358
245
|
const array2 = Array.isArray(entry);
|
|
359
246
|
if (array2 ? Object.getPrototypeOf(entry) !== Array.prototype : ![Object.prototype, null].includes(Object.getPrototypeOf(entry)))
|
|
360
247
|
return false;
|
|
361
|
-
const
|
|
362
|
-
if (
|
|
248
|
+
const keys2 = Reflect.ownKeys(entry);
|
|
249
|
+
if (keys2.length > FETCH_METADATA_BYTES || array2 && keys2.length !== entry.length + 1)
|
|
363
250
|
return false;
|
|
364
|
-
return
|
|
251
|
+
return keys2.every((key) => {
|
|
365
252
|
if (array2 && key === "length") return true;
|
|
366
253
|
const d = Object.getOwnPropertyDescriptor(entry, key);
|
|
367
254
|
size += typeof key === "string" ? key.length + 3 : 0;
|
|
@@ -372,7 +259,7 @@ function isPageFetchFrame(value) {
|
|
|
372
259
|
return false;
|
|
373
260
|
const v = value;
|
|
374
261
|
if (v.protocol !== 2 || typeof v.type !== "string") return false;
|
|
375
|
-
const
|
|
262
|
+
const fields2 = {
|
|
376
263
|
"fetch-open": ["id", "connectionId", "url", "method", "headers", "hasBody"],
|
|
377
264
|
"fetch-headers": ["id", "status", "statusText", "headers", "hasBody"],
|
|
378
265
|
"fetch-credit": ["id", "direction", "sequence", "chunks", "bytes"],
|
|
@@ -383,7 +270,7 @@ function isPageFetchFrame(value) {
|
|
|
383
270
|
"fetch-error": ["id", "error"],
|
|
384
271
|
"fetch-close": ["connectionId"]
|
|
385
272
|
};
|
|
386
|
-
const required =
|
|
273
|
+
const required = fields2[v.type];
|
|
387
274
|
const inline = v.type === "fetch-open" && Object.hasOwn(v, "inlineBody");
|
|
388
275
|
if (!required || Object.keys(v).length !== required.length + 2 + Number(inline) || !required.every((k) => Object.hasOwn(v, k)))
|
|
389
276
|
return false;
|
|
@@ -416,101 +303,10 @@ function pageFetchPath(baseUrl, input) {
|
|
|
416
303
|
const rawPath = input.replace(/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^/]+/, "").split("?")[0];
|
|
417
304
|
if (rawPath.includes("//") || /%(?:2e|2f|5c|25)/i.test(rawPath) || rawPath.split("/").some((p) => p === "." || p === "..") || /[\u0000-\u001f\u007f]/.test(decodeURIComponent(rawPath)))
|
|
418
305
|
throw new TypeError("Ambiguous fetch path");
|
|
419
|
-
const base = new URL(baseUrl),
|
|
420
|
-
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 + "/"))
|
|
421
308
|
throw new TypeError("Fetch target mismatch");
|
|
422
|
-
return (
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
// ../domain-contracts/src/app-host/service-host-protocol.ts
|
|
426
|
-
var SERVICE_HOST_METHODS = ["secrets.get", "secrets.set", "secrets.delete", "context.get", "context.resolveInvocation", "agent.listModels", "agent.getConnection", "agent.resolveSkills", "sessions.getConnection", "workspace.gitStatus", "workspace.createTaskWorktree", "workspace.getWorktree", "workspace.releaseExecutionRoot", "work.list", "work.get"];
|
|
427
|
-
var SERVICE_HOST_MAX_FRAME_BYTES = 512 * 1024;
|
|
428
|
-
var SERVICE_HOST_MAX_PENDING = 64;
|
|
429
|
-
var validServiceContext = (v) => json(v) && object({ protocolVersion: enumeration(1), registrationId: id, instanceId: id, dataScopeId: text(256), scope: object({ appId: text(256), installationId: id, contentDigest: digest }), installationRevision: count, phase: enumeration("starting", "ready") })(v);
|
|
430
|
-
var worktreeBody = { workspaceId: id, expectedHead: text(256), branch: text(1024) };
|
|
431
|
-
var worktreeReceipt = object({ requestId: id, state: enumeration("accepted", "completed", "failed", "unknown") }, { result: object({ executionRoot: id, workspaceId: id, branch: text(1024), sourceHead: text(256) }) });
|
|
432
|
-
function validServiceHostInput(method, v) {
|
|
433
|
-
if (!json(v)) return false;
|
|
434
|
-
if (method.startsWith("agent.")) return validAgentInput(method, v);
|
|
435
|
-
switch (method) {
|
|
436
|
-
case "secrets.get":
|
|
437
|
-
case "secrets.delete":
|
|
438
|
-
return object({ key: (x) => typeof x === "string" && /^[a-zA-Z0-9._:-]{1,128}$/.test(x) })(v);
|
|
439
|
-
case "secrets.set":
|
|
440
|
-
return object({ key: (x) => typeof x === "string" && /^[a-zA-Z0-9._:-]{1,128}$/.test(x), value: text(16384) })(v);
|
|
441
|
-
case "context.get":
|
|
442
|
-
case "work.list":
|
|
443
|
-
return object({})(v);
|
|
444
|
-
case "context.resolveInvocation":
|
|
445
|
-
return object({ ticket: text(8192) })(v);
|
|
446
|
-
case "sessions.getConnection":
|
|
447
|
-
return object({ dataScopeId: text(256), sessionId: text(256) })(v);
|
|
448
|
-
case "workspace.gitStatus":
|
|
449
|
-
return object({ workspaceId: id })(v);
|
|
450
|
-
case "workspace.createTaskWorktree":
|
|
451
|
-
return object({ requestId: id, ...worktreeBody })(v);
|
|
452
|
-
case "workspace.getWorktree":
|
|
453
|
-
return object({ requestId: id, original: object(worktreeBody) })(v);
|
|
454
|
-
case "workspace.releaseExecutionRoot":
|
|
455
|
-
return object({ requestId: id, workspaceId: id, executionRoot: id })(v);
|
|
456
|
-
case "work.get":
|
|
457
|
-
return object({ requestId: id })(v);
|
|
458
|
-
default:
|
|
459
|
-
return false;
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
function validServiceHostResult(method, v) {
|
|
463
|
-
if (!json(v)) return false;
|
|
464
|
-
if (method.startsWith("agent.")) return validAgentResult(method, v);
|
|
465
|
-
switch (method) {
|
|
466
|
-
case "secrets.get":
|
|
467
|
-
return v === null || text(16384)(v);
|
|
468
|
-
case "secrets.set":
|
|
469
|
-
return object({ stored: enumeration(true) })(v);
|
|
470
|
-
case "secrets.delete":
|
|
471
|
-
return object({ deleted: enumeration(true) })(v);
|
|
472
|
-
case "context.get":
|
|
473
|
-
return validServiceContext(v);
|
|
474
|
-
case "context.resolveInvocation":
|
|
475
|
-
return object({ invocationId: id, dataScopeId: text(256), sessionId: text(256), runId: text(256) }, { inputId: text(256), workspaceId: id, executionRoot: id, privateSessionId: id })(v);
|
|
476
|
-
case "sessions.getConnection":
|
|
477
|
-
return validAgentResult("agent.getConnection", v);
|
|
478
|
-
case "workspace.gitStatus":
|
|
479
|
-
return object({ root: text(32768), commonDir: text(32768), head: text(256), branch: text(1024, true), changes: array(text(32768), 1e4) })(v);
|
|
480
|
-
case "workspace.createTaskWorktree":
|
|
481
|
-
return worktreeReceipt(v);
|
|
482
|
-
case "workspace.getWorktree":
|
|
483
|
-
return v === null || worktreeReceipt(v);
|
|
484
|
-
case "workspace.releaseExecutionRoot":
|
|
485
|
-
return object({ requestId: id, executionRoot: id, state: enumeration("released", "retained-dirty", "in-use", "unknown") })(v);
|
|
486
|
-
case "work.list":
|
|
487
|
-
return validServiceResult("service.listWork", v);
|
|
488
|
-
case "work.get":
|
|
489
|
-
return v === null || validServiceResult("service.getWork", v);
|
|
490
|
-
default:
|
|
491
|
-
return false;
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
function isServiceHostFrame(v) {
|
|
495
|
-
if (isPageFetchFrame(v)) return true;
|
|
496
|
-
if (!json(v) || new TextEncoder().encode(JSON.stringify(v)).byteLength > SERVICE_HOST_MAX_FRAME_BYTES || !object({ protocol: enumeration(1), type: text(64) }, { id, context: validServiceContext, method: enumeration(...SERVICE_HOST_METHODS), params: json, ok: enumeration(true, false), value: json, error: isAppHostErrorInfo })(v)) return false;
|
|
497
|
-
const frame = v;
|
|
498
|
-
switch (frame.type) {
|
|
499
|
-
case "service-host-connect":
|
|
500
|
-
return object({ protocol: enumeration(1), type: enumeration(frame.type), id })(v);
|
|
501
|
-
case "service-host-ready":
|
|
502
|
-
return object({ protocol: enumeration(1), type: enumeration(frame.type), id, context: validServiceContext })(v);
|
|
503
|
-
case "service-host-context":
|
|
504
|
-
return object({ protocol: enumeration(1), type: enumeration(frame.type), context: validServiceContext })(v);
|
|
505
|
-
case "service-host-close":
|
|
506
|
-
return object({ protocol: enumeration(1), type: enumeration(frame.type) })(v);
|
|
507
|
-
case "service-host-request":
|
|
508
|
-
return object({ protocol: enumeration(1), type: enumeration(frame.type), id, method: enumeration(...SERVICE_HOST_METHODS), params: (x) => validServiceHostInput(frame.method, x) })(v);
|
|
509
|
-
case "service-host-response":
|
|
510
|
-
return frame.ok ? object({ protocol: enumeration(1), type: enumeration(frame.type), id, ok: enumeration(true), value: json })(v) : object({ protocol: enumeration(1), type: enumeration(frame.type), id, ok: enumeration(false), error: isAppHostErrorInfo })(v);
|
|
511
|
-
default:
|
|
512
|
-
return false;
|
|
513
|
-
}
|
|
309
|
+
return (url2.pathname.slice(base.pathname.length) || "/") + url2.search;
|
|
514
310
|
}
|
|
515
311
|
|
|
516
312
|
// ../domain-contracts/src/app-host/agent-api-policy.ts
|
|
@@ -565,6 +361,7 @@ var routes = [
|
|
|
565
361
|
{ method: "POST", pattern: /^\/jobs\/[^/]+\/cancel$/, id: "jobs.cancel" }
|
|
566
362
|
];
|
|
567
363
|
function matchAgentApiRoute(method, path) {
|
|
364
|
+
if (path === "/attachments/storage") return void 0;
|
|
568
365
|
return routes.find((route) => route.method === method && route.pattern.test(path));
|
|
569
366
|
}
|
|
570
367
|
function normalizeAgentApiPath(raw) {
|
|
@@ -621,7 +418,6 @@ var workspaceConversationResult = object({
|
|
|
621
418
|
revision: count,
|
|
622
419
|
session: sessionRecord,
|
|
623
420
|
operationState: enumeration("prepared", "running", "completed", "failed", "unknown"),
|
|
624
|
-
indexBindingPending: (v) => v === true,
|
|
625
421
|
workspaceId: id,
|
|
626
422
|
executionRoot: id,
|
|
627
423
|
privateSessionId: id,
|
|
@@ -652,7 +448,6 @@ function validSessionControlInput(method, value) {
|
|
|
652
448
|
const target2 = value;
|
|
653
449
|
return target2.workspaceId !== void 0 ? target2.outsideProject !== true : target2.outsideProject === true;
|
|
654
450
|
}
|
|
655
|
-
if (method === "sessions.bindConversationIndex") return object({ original: validWorkspaceConversation, dataScopeId: text() })(value);
|
|
656
451
|
if (method === "sessions.createConversation" || method === "sessions.getConversationCreationResult") return validWorkspaceConversation(value);
|
|
657
452
|
if (method === "sessions.getControls") return object({ connectionId: text(), sessionId: text() })(value);
|
|
658
453
|
if (!object({ requestId: id, sessionId: text(), original: validSessionControlOriginal }, { connectionId: text() })(value)) return false;
|
|
@@ -662,17 +457,16 @@ function validSessionControlInput(method, value) {
|
|
|
662
457
|
function validSessionControlResult(method, value) {
|
|
663
458
|
if (!json(value)) return false;
|
|
664
459
|
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);
|
|
665
|
-
if (method === "sessions.bindConversationIndex") return validWorkspaceConversationResult(value);
|
|
666
460
|
if (method === "sessions.createConversation" || method === "sessions.getConversationCreationResult")
|
|
667
461
|
return method === "sessions.getConversationCreationResult" && value === null || validWorkspaceConversationResult(value);
|
|
668
|
-
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),
|
|
462
|
+
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);
|
|
669
463
|
if (method === "sessions.getControlResult") return value === null || receipt(value);
|
|
670
464
|
if (!receipt(value)) return false;
|
|
671
465
|
return false;
|
|
672
466
|
}
|
|
673
467
|
|
|
674
468
|
// ../domain-contracts/src/app-host/workspace.ts
|
|
675
|
-
function
|
|
469
|
+
function fields(v, required, optional = []) {
|
|
676
470
|
if (!v || typeof v !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(v))) return false;
|
|
677
471
|
return required.every((k) => Object.hasOwn(v, k)) && Reflect.ownKeys(v).every((k) => {
|
|
678
472
|
const d = Object.getOwnPropertyDescriptor(v, k);
|
|
@@ -681,7 +475,7 @@ function fields3(v, required, optional = []) {
|
|
|
681
475
|
}
|
|
682
476
|
var uuid = (v) => typeof v === "string" && HOST_REQUEST_ID.test(v);
|
|
683
477
|
var str = (v) => typeof v === "string";
|
|
684
|
-
function
|
|
478
|
+
function rows(v, check) {
|
|
685
479
|
if (!Array.isArray(v) || Object.getPrototypeOf(v) !== Array.prototype || v.length > 200 || Reflect.ownKeys(v).length !== v.length + 1) return false;
|
|
686
480
|
for (let i = 0; i < v.length; i++) {
|
|
687
481
|
const d = Object.getOwnPropertyDescriptor(v, String(i));
|
|
@@ -689,18 +483,18 @@ function rows2(v, check) {
|
|
|
689
483
|
}
|
|
690
484
|
return true;
|
|
691
485
|
}
|
|
692
|
-
var ref = (v) =>
|
|
486
|
+
var ref = (v) => fields(v, ["id", "displayName"]) && uuid(v.id) && str(v.displayName) && v.displayName.length > 0;
|
|
693
487
|
function validWorkspaceInput(method, v) {
|
|
694
488
|
switch (method) {
|
|
695
489
|
case "workspace.select":
|
|
696
490
|
case "workspace.getSelection":
|
|
697
|
-
return
|
|
491
|
+
return fields(v, ["requestId"]) && uuid(v.requestId);
|
|
698
492
|
case "workspace.get":
|
|
699
|
-
return
|
|
493
|
+
return fields(v, ["workspaceId"]) && uuid(v.workspaceId);
|
|
700
494
|
case "workspace.listFiles":
|
|
701
|
-
return
|
|
495
|
+
return fields(v, ["workspaceId", "directory"], ["cursor"]) && uuid(v.workspaceId) && str(v.directory) && (!Object.hasOwn(v, "cursor") || uuid(v.cursor));
|
|
702
496
|
case "workspace.readText":
|
|
703
|
-
return
|
|
497
|
+
return fields(v, ["workspaceId", "path"]) && uuid(v.workspaceId) && str(v.path) && v.path.length > 0;
|
|
704
498
|
}
|
|
705
499
|
}
|
|
706
500
|
function validWorkspaceResult(method, v) {
|
|
@@ -710,13 +504,13 @@ function validWorkspaceResult(method, v) {
|
|
|
710
504
|
case "workspace.get":
|
|
711
505
|
return ref(v);
|
|
712
506
|
case "workspace.getSelection":
|
|
713
|
-
if (!
|
|
714
|
-
if (v.status === "completed") return
|
|
715
|
-
return
|
|
507
|
+
if (!fields(v, ["requestId", "status"], ["workspace", "unavailable"]) || !uuid(v.requestId)) return false;
|
|
508
|
+
if (v.status === "completed") return fields(v, ["requestId", "status", "workspace"]) && ref(v.workspace) || fields(v, ["requestId", "status", "unavailable"]) && v.unavailable === true;
|
|
509
|
+
return fields(v, ["requestId", "status"]) && ["pending", "cancelled", "expired", "failed", "unknown"].includes(v.status);
|
|
716
510
|
case "workspace.listFiles":
|
|
717
|
-
return
|
|
511
|
+
return fields(v, ["entries"], ["nextCursor"]) && rows(v.entries, (e) => fields(e, ["path", "name", "kind"]) && str(e.path) && str(e.name) && (e.kind === "file" || e.kind === "directory")) && (!Object.hasOwn(v, "nextCursor") || uuid(v.nextCursor));
|
|
718
512
|
case "workspace.readText":
|
|
719
|
-
return
|
|
513
|
+
return fields(v, ["path", "text", "revision"]) && str(v.path) && v.path.length > 0 && str(v.text) && typeof v.revision === "string" && /^[a-f0-9]{64}$/.test(v.revision);
|
|
720
514
|
}
|
|
721
515
|
}
|
|
722
516
|
|
|
@@ -777,7 +571,7 @@ function validAppCommandSnapshot(value) {
|
|
|
777
571
|
(m) => m.items.some((i) => "command" in i && !ids.has(i.command))
|
|
778
572
|
) || Object.values(v.toolbar ?? {}).some((x) => !ids.has(x)))
|
|
779
573
|
return false;
|
|
780
|
-
const
|
|
574
|
+
const keys2 = /* @__PURE__ */ new Set();
|
|
781
575
|
for (const command of v.commands)
|
|
782
576
|
for (const key of command.shortcuts ?? []) {
|
|
783
577
|
const mods = new Set(key.modifiers);
|
|
@@ -786,8 +580,8 @@ function validAppCommandSnapshot(value) {
|
|
|
786
580
|
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")
|
|
787
581
|
return false;
|
|
788
582
|
const signature = `${[...mods].map((m) => m === "Control" || m === "Meta" ? "Primary" : m).sort().join("+")}:${key.code}`;
|
|
789
|
-
if (
|
|
790
|
-
|
|
583
|
+
if (keys2.has(signature)) return false;
|
|
584
|
+
keys2.add(signature);
|
|
791
585
|
}
|
|
792
586
|
return true;
|
|
793
587
|
}
|
|
@@ -1051,8 +845,7 @@ function createResourceCatalogApi(rpc) {
|
|
|
1051
845
|
// src/session-controls.ts
|
|
1052
846
|
var CONVERSATION_PREPARATION_METHODS = [
|
|
1053
847
|
"sessions.createConversation",
|
|
1054
|
-
"sessions.getConversationCreationResult"
|
|
1055
|
-
"sessions.bindConversationIndex"
|
|
848
|
+
"sessions.getConversationCreationResult"
|
|
1056
849
|
];
|
|
1057
850
|
function isConversationPreparationMethod(method) {
|
|
1058
851
|
return CONVERSATION_PREPARATION_METHODS.includes(method);
|
|
@@ -1067,30 +860,43 @@ function validConversationPreparationResult(method, result) {
|
|
|
1067
860
|
// src/client-connections.ts
|
|
1068
861
|
var connections = /* @__PURE__ */ new WeakMap();
|
|
1069
862
|
function createClientConnection(wire, streams) {
|
|
1070
|
-
const
|
|
863
|
+
const record2 = { owner: streams, id: wire.connectionId, closed: false };
|
|
1071
864
|
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() {
|
|
1072
|
-
return
|
|
865
|
+
return record2.closed || streams.isClosed?.(wire.connectionId) === true;
|
|
1073
866
|
}, close() {
|
|
1074
|
-
if (!
|
|
1075
|
-
|
|
867
|
+
if (!record2.closed) {
|
|
868
|
+
record2.closed = true;
|
|
1076
869
|
streams.close(wire.connectionId);
|
|
1077
870
|
}
|
|
1078
871
|
} };
|
|
1079
|
-
connections.set(connection,
|
|
872
|
+
connections.set(connection, record2);
|
|
1080
873
|
return connection;
|
|
1081
874
|
}
|
|
1082
875
|
function resolveClientConnection(connection, owner) {
|
|
1083
|
-
const
|
|
1084
|
-
if (!
|
|
1085
|
-
return
|
|
876
|
+
const record2 = connections.get(connection);
|
|
877
|
+
if (!record2 || record2.owner !== owner || record2.closed || owner.isClosed?.(record2.id)) throw new AppHostError("connection_revoked");
|
|
878
|
+
return record2.id;
|
|
1086
879
|
}
|
|
1087
880
|
|
|
1088
881
|
// src/desktop.ts
|
|
1089
882
|
var BROWSER_CAPTURE_PREVIEW_MAX_BYTES = 8 * 1024 * 1024;
|
|
883
|
+
var DESKTOP_ADAPTED_METHODS = ["desktop.files.openRead", "desktop.files.getOperation"];
|
|
1090
884
|
var target = { targetId: text(256) };
|
|
1091
885
|
var mount = { ...target, mountId: text(256) };
|
|
1092
886
|
var source = object({ sessionId: text(), appId: text() });
|
|
1093
887
|
var action = { ...mount, source, requestId: id, expectedRevision: count };
|
|
888
|
+
var fileWriteBody = { path: text(32768), expectedSha256: digest, text: text(8 * 1024 * 1024, true) };
|
|
889
|
+
var gitBranchBody = { expectedHead: text(), branch: text() };
|
|
890
|
+
var validFileOperationQuery = object({
|
|
891
|
+
...target,
|
|
892
|
+
requestId: id,
|
|
893
|
+
original: object({ kind: enumeration("files.writeText"), body: object(fileWriteBody) })
|
|
894
|
+
});
|
|
895
|
+
var validGitOperationQuery = object({
|
|
896
|
+
...target,
|
|
897
|
+
requestId: id,
|
|
898
|
+
original: object({ kind: enumeration("git.switchBranch", "git.createBranch"), body: object(gitBranchBody) })
|
|
899
|
+
});
|
|
1094
900
|
var page = { ...target, tabId: text(256), pageRevision: count };
|
|
1095
901
|
var mode = enumeration("off", "pick", "review");
|
|
1096
902
|
var voidResult = (v) => v === void 0;
|
|
@@ -1100,7 +906,7 @@ var annotationFields = { target: text(8192), selector: text(8192), locatorKind:
|
|
|
1100
906
|
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: finite2, height: finite2 })), 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) });
|
|
1101
907
|
var root = object({ path: text(32768), identity: object({ dev: text(), ino: text() }) }, { workspaceId: text() });
|
|
1102
908
|
var validDesktopTarget = object({ id: text(), dataScopeId: text(), draftId: text(), draftRevision: count }, { root, sessionId: text() });
|
|
1103
|
-
var kind = enumeration("files.writeText", "git.switchBranch", "git.createBranch"
|
|
909
|
+
var kind = enumeration("files.writeText", "git.switchBranch", "git.createBranch");
|
|
1104
910
|
var validWorkspaceOperation = object({ requestId: id, kind, state: enumeration("prepared", "running", "completed", "failed", "unknown"), createdAt: count, updatedAt: count }, { result: json, error: object({ code: text(128) }) });
|
|
1105
911
|
var origin = (v) => object({ kind: enumeration("surface"), surfaceId: text() })(v) || object({ kind: enumeration("tool-result"), sourcePartId: text() })(v);
|
|
1106
912
|
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() });
|
|
@@ -1123,7 +929,7 @@ var rules = {
|
|
|
1123
929
|
"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 }) },
|
|
1124
930
|
"desktop.files.openRead": { input: object({ ...target, path: text(32768) }), result: validConnection },
|
|
1125
931
|
"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 }) },
|
|
1126
|
-
"desktop.files.writeText": { input: object({ ...target, requestId: id,
|
|
932
|
+
"desktop.files.writeText": { input: object({ ...target, requestId: id, ...fileWriteBody }), result: validWorkspaceOperation },
|
|
1127
933
|
"desktop.files.getOperation": { input: object({ ...target, requestId: id, original: object({ kind, body: json }) }), result: nullable(validWorkspaceOperation) },
|
|
1128
934
|
"desktop.files.revealPath": { input: object({ ...target, path: text(32768) }), result: voidResult },
|
|
1129
935
|
"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) },
|
|
@@ -1139,9 +945,8 @@ var rules = {
|
|
|
1139
945
|
"desktop.git.listBranches": { input: object(target), result: object({ branches: array(text(1024), 1e4) }) },
|
|
1140
946
|
"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 }) },
|
|
1141
947
|
"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 }) },
|
|
1142
|
-
"desktop.git.switchBranch": { input: object({ ...target, requestId: id,
|
|
1143
|
-
"desktop.git.createBranch": { input: object({ ...target, requestId: id,
|
|
1144
|
-
"desktop.git.createTaskWorktree": { input: object({ ...target, requestId: id, expectedHead: text(), branch: text() }), result: validWorkspaceOperation },
|
|
948
|
+
"desktop.git.switchBranch": { input: object({ ...target, requestId: id, ...gitBranchBody }), result: validWorkspaceOperation },
|
|
949
|
+
"desktop.git.createBranch": { input: object({ ...target, requestId: id, ...gitBranchBody }), result: validWorkspaceOperation },
|
|
1145
950
|
"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") }) },
|
|
1146
951
|
"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(finite2) }), 1e4) },
|
|
1147
952
|
"desktop.terminals.restart": { input: object({ ...target, terminalId: text(), requestId: id }), result: object({ resourceId: text(), terminalId: text(), cwd: text(32768), status: enumeration("running", "exited") }) },
|
|
@@ -1234,24 +1039,48 @@ function createAppDesktopApi(rpc, owner, filesFeature = () => {
|
|
|
1234
1039
|
if (!validDesktopResultForInput(method, params, value)) throw new AppHostError("host_unavailable");
|
|
1235
1040
|
return value;
|
|
1236
1041
|
};
|
|
1237
|
-
const group = (name2) => Object.fromEntries(DESKTOP_METHODS.filter((
|
|
1238
|
-
|
|
1239
|
-
if (!
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1042
|
+
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)]));
|
|
1043
|
+
const getOperation = async (input, validate) => {
|
|
1044
|
+
if (!validate(input)) throw new AppHostError("invalid_request");
|
|
1045
|
+
return call("desktop.files.getOperation", input);
|
|
1046
|
+
};
|
|
1047
|
+
return {
|
|
1048
|
+
bindTarget(input) {
|
|
1049
|
+
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");
|
|
1050
|
+
const { connection, ...rest } = input;
|
|
1051
|
+
return call("desktop.bindTarget", { ...rest, ...connection === void 0 ? {} : { connectionId: resolveClientConnection(connection, owner) } });
|
|
1052
|
+
},
|
|
1053
|
+
releaseTarget: (input) => call("desktop.releaseTarget", input),
|
|
1054
|
+
files: {
|
|
1055
|
+
...group("files"),
|
|
1056
|
+
getOperation: (input) => getOperation(input, validFileOperationQuery),
|
|
1057
|
+
async readFile(input, options = {}) {
|
|
1058
|
+
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");
|
|
1059
|
+
filesFeature();
|
|
1060
|
+
const { range: range2, ...params } = input;
|
|
1061
|
+
const wire = await call("desktop.files.openRead", params);
|
|
1062
|
+
const fetchFile = owner.fetchFor(wire.connectionId, wire.baseUrl);
|
|
1063
|
+
try {
|
|
1064
|
+
return await fetchFile(wire.baseUrl + "/", {
|
|
1065
|
+
...options.signal ? { signal: options.signal } : {},
|
|
1066
|
+
...range2 ? { headers: { Range: `bytes=${range2.start}-${range2.end ?? ""}` } } : {}
|
|
1067
|
+
});
|
|
1068
|
+
} catch (error) {
|
|
1069
|
+
owner.close(wire.connectionId);
|
|
1070
|
+
throw error;
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
},
|
|
1074
|
+
clipboard: group("clipboard"),
|
|
1075
|
+
git: {
|
|
1076
|
+
...group("git"),
|
|
1077
|
+
getOperation: (input) => getOperation(input, validGitOperationQuery)
|
|
1078
|
+
},
|
|
1079
|
+
terminals: group("terminals"),
|
|
1080
|
+
windows: group("windows"),
|
|
1081
|
+
browser: group("browser"),
|
|
1082
|
+
pluginApps: group("pluginApps")
|
|
1083
|
+
};
|
|
1255
1084
|
}
|
|
1256
1085
|
function canonicalDesktopRequest(value) {
|
|
1257
1086
|
if (!json(value)) throw new AppHostError("invalid_request");
|
|
@@ -1319,10 +1148,18 @@ function createAppAuxiliarySessionsApi(rpc, streams) {
|
|
|
1319
1148
|
const { connection, ...rest } = input;
|
|
1320
1149
|
return { ...rest, connectionId: resolveClientConnection(connection, streams) };
|
|
1321
1150
|
};
|
|
1322
|
-
return {
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1151
|
+
return {
|
|
1152
|
+
getOptions: (input) => request("sessions.getAuxiliaryOptions", {
|
|
1153
|
+
sessionId: input.sessionId,
|
|
1154
|
+
connectionId: resolveClientConnection(input.connection, streams)
|
|
1155
|
+
}),
|
|
1156
|
+
async open(input) {
|
|
1157
|
+
const wire = await request("sessions.openAuxiliary", resolve(input));
|
|
1158
|
+
return { leaseId: wire.receipt.leaseId, sessionId: wire.receipt.sessionId, connection: createClientConnection(wire, streams) };
|
|
1159
|
+
},
|
|
1160
|
+
get: (input) => request("sessions.getAuxiliary", resolve(input)),
|
|
1161
|
+
close: (input) => request("sessions.closeAuxiliary", resolve(input))
|
|
1162
|
+
};
|
|
1326
1163
|
}
|
|
1327
1164
|
|
|
1328
1165
|
// src/extensions.ts
|
|
@@ -1401,12 +1238,94 @@ function validProjectRequest(value) {
|
|
|
1401
1238
|
case "archive":
|
|
1402
1239
|
return object({ action: (v) => v === "archive", ...project })(value);
|
|
1403
1240
|
case "rebind":
|
|
1404
|
-
return object({ action: (v) => v === "rebind", ...
|
|
1241
|
+
return object({ action: (v) => v === "rebind", ...project, previousWorkspaceId: id2, expectedPath: text(32768) })(value);
|
|
1405
1242
|
default:
|
|
1406
1243
|
return false;
|
|
1407
1244
|
}
|
|
1408
1245
|
}
|
|
1409
|
-
var validProjectSnapshot = (value) => object({
|
|
1246
|
+
var validProjectSnapshot = (value) => object({
|
|
1247
|
+
dataScopeId: id2,
|
|
1248
|
+
projects: array(object({ workspaceId: id2, projectId: id2, name: text(1024), path: text(32768), available: bool, lastOpenedAt: count }, {
|
|
1249
|
+
defaultShell: text(4096),
|
|
1250
|
+
rootIdentity: object({ dev: text(32), ino: text(32) })
|
|
1251
|
+
}), 1e4)
|
|
1252
|
+
}, { selectedWorkspaceId: id2 })(value);
|
|
1253
|
+
|
|
1254
|
+
// src/local-workspace.ts
|
|
1255
|
+
var root2 = { rootPath: text(32768) };
|
|
1256
|
+
var identity = { identity: object({ dev: text(32), ino: text(32) }) };
|
|
1257
|
+
var file = { ...root2, path: text(32768) };
|
|
1258
|
+
var write = { ...file, requestId: id, content: text(125e4, true), originalContent: text(125e4, true) };
|
|
1259
|
+
var actionOf = (value) => value && typeof value === "object" ? Object.getOwnPropertyDescriptor(value, "action")?.value : void 0;
|
|
1260
|
+
function validLocalWorkspaceRequest(value) {
|
|
1261
|
+
const action2 = actionOf(value);
|
|
1262
|
+
const field = { action: enumeration(action2) };
|
|
1263
|
+
switch (action2) {
|
|
1264
|
+
case "pick":
|
|
1265
|
+
case "listOpeners":
|
|
1266
|
+
return object(field)(value);
|
|
1267
|
+
case "list":
|
|
1268
|
+
return object({ ...field, ...root2 }, { ...identity, path: text(32768, true) })(value);
|
|
1269
|
+
case "find":
|
|
1270
|
+
return object({ ...field, ...root2, query: text(1024) }, identity)(value);
|
|
1271
|
+
case "write":
|
|
1272
|
+
case "getWrite":
|
|
1273
|
+
return object({ ...field, ...write }, identity)(value);
|
|
1274
|
+
case "openWith":
|
|
1275
|
+
return object({ ...field, ...file, openerId: text(256) }, identity)(value);
|
|
1276
|
+
case "copyPath":
|
|
1277
|
+
return object({ ...field, ...file }, { ...identity, absolute: bool })(value);
|
|
1278
|
+
case "read":
|
|
1279
|
+
case "reveal":
|
|
1280
|
+
case "webPreview":
|
|
1281
|
+
return object({ ...field, ...file }, identity)(value);
|
|
1282
|
+
default:
|
|
1283
|
+
return false;
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
var bytes = (limit) => (value) => value instanceof ArrayBuffer && value.byteLength <= limit;
|
|
1287
|
+
var preview = object({
|
|
1288
|
+
path: text(32768),
|
|
1289
|
+
name: text(32768),
|
|
1290
|
+
language: text(4096),
|
|
1291
|
+
size: count,
|
|
1292
|
+
binary: bool,
|
|
1293
|
+
content: nullable(text(125e4, true)),
|
|
1294
|
+
scope: enumeration("project", "extra-root"),
|
|
1295
|
+
relativePath: text(32768),
|
|
1296
|
+
rootLabel: text(32768),
|
|
1297
|
+
previewBytes: nullable(bytes(50 * 1024 * 1024)),
|
|
1298
|
+
mediaType: enumeration(null, "image/avif", "image/bmp", "image/gif", "image/jpeg", "image/png", "image/webp"),
|
|
1299
|
+
imagePreviewError: enumeration(null, "image_too_large", "image_unsupported")
|
|
1300
|
+
}, {
|
|
1301
|
+
rootIdentity: identity.identity,
|
|
1302
|
+
documentPreview: object({ format: enumeration("pdf", "epub", "docx", "xlsx", "pptx"), bytes: bytes(64 * 1024 * 1024) })
|
|
1303
|
+
});
|
|
1304
|
+
var tree = object({
|
|
1305
|
+
...root2,
|
|
1306
|
+
entries: array(object({ path: text(32768), type: enumeration("file", "directory") }, { size: count }), 1e4)
|
|
1307
|
+
}, { truncated: bool });
|
|
1308
|
+
var found = object({ files: array(text(32768), 1e3), truncated: bool });
|
|
1309
|
+
var picked = object({ ...root2, ...identity, workspaceId: id });
|
|
1310
|
+
var url = object({ url: text(131072) });
|
|
1311
|
+
var openers = (value) => validDesktopResult("desktop.files.listOpeners", value);
|
|
1312
|
+
var empty2 = (value) => value === void 0;
|
|
1313
|
+
var checks = {
|
|
1314
|
+
pick: nullable(picked),
|
|
1315
|
+
list: tree,
|
|
1316
|
+
find: found,
|
|
1317
|
+
read: preview,
|
|
1318
|
+
write: preview,
|
|
1319
|
+
getWrite: nullable(preview),
|
|
1320
|
+
reveal: empty2,
|
|
1321
|
+
openWith: empty2,
|
|
1322
|
+
copyPath: empty2,
|
|
1323
|
+
listOpeners: openers,
|
|
1324
|
+
webPreview: url
|
|
1325
|
+
};
|
|
1326
|
+
function validLocalWorkspaceResult(value, action2) {
|
|
1327
|
+
return action2 ? checks[action2](value) : Object.values(checks).some((check) => check(value));
|
|
1328
|
+
}
|
|
1410
1329
|
|
|
1411
1330
|
// ../domain-contracts/src/app-host/model-providers.ts
|
|
1412
1331
|
var provider = text(256);
|
|
@@ -1415,8 +1334,8 @@ var limits = { contextWindow: count, maxOutputTokens: count };
|
|
|
1415
1334
|
function headerValues(check) {
|
|
1416
1335
|
return (value) => {
|
|
1417
1336
|
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1418
|
-
const
|
|
1419
|
-
return
|
|
1337
|
+
const keys2 = Object.keys(value);
|
|
1338
|
+
return keys2.length <= 128 && keys2.every((key) => /^[!#$%&'*+.^_`|~0-9A-Za-z-]{1,256}$/.test(key)) && object(Object.fromEntries(keys2.map((key) => [key, check])))(value);
|
|
1420
1339
|
};
|
|
1421
1340
|
}
|
|
1422
1341
|
var headers = headerValues(text(8192, true));
|
|
@@ -1446,14 +1365,15 @@ function validModelProviderConnections(value) {
|
|
|
1446
1365
|
var modelId = text(1024);
|
|
1447
1366
|
var effort = nullable(text(256));
|
|
1448
1367
|
var revision = text(8192);
|
|
1368
|
+
var accountGatewayProof = (value) => typeof value === "string" && /^[a-f0-9]{64}$/.test(value);
|
|
1449
1369
|
function validProviderDefaultsRequest(value) {
|
|
1450
|
-
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);
|
|
1370
|
+
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);
|
|
1451
1371
|
}
|
|
1452
1372
|
var verifiedProvider = object({ model: modelId, checkedAt: count });
|
|
1453
1373
|
var verified = (value) => {
|
|
1454
1374
|
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1455
|
-
const
|
|
1456
|
-
return
|
|
1375
|
+
const keys2 = Object.keys(value);
|
|
1376
|
+
return keys2.length <= 4096 && keys2.every(provider) && object(Object.fromEntries(keys2.map((key) => [key, verifiedProvider])))(value);
|
|
1457
1377
|
};
|
|
1458
1378
|
var defaultsModel = object({ id: modelId, label: text(1024), provider: text(1024), providerName: provider }, {
|
|
1459
1379
|
reasoningEfforts: array(text(256, true)),
|
|
@@ -1471,7 +1391,7 @@ var validProviderDefaultsSnapshot = object({
|
|
|
1471
1391
|
verified,
|
|
1472
1392
|
fastModeAvailable: enumeration(false),
|
|
1473
1393
|
fastModeReason: text(1024)
|
|
1474
|
-
});
|
|
1394
|
+
}, { accountGatewayMatches: bool });
|
|
1475
1395
|
var validProviderConnectionTestResult = object({
|
|
1476
1396
|
status: enumeration("verified", "failed"),
|
|
1477
1397
|
detail: text(8192),
|
|
@@ -1489,7 +1409,6 @@ var SYSTEM_SETTINGS_SECTIONS = [
|
|
|
1489
1409
|
"permissions",
|
|
1490
1410
|
"personalization",
|
|
1491
1411
|
"billing",
|
|
1492
|
-
"connections",
|
|
1493
1412
|
"terminal",
|
|
1494
1413
|
"git",
|
|
1495
1414
|
"runtime",
|
|
@@ -1516,10 +1435,33 @@ var SYSTEM_SHORTCUT_IDS = [
|
|
|
1516
1435
|
"resetZoom",
|
|
1517
1436
|
"showShortcuts"
|
|
1518
1437
|
];
|
|
1438
|
+
var CHANNEL_SETTINGS_ACTIONS = [
|
|
1439
|
+
"snapshot",
|
|
1440
|
+
"runtimeStatus",
|
|
1441
|
+
"connect",
|
|
1442
|
+
"patch",
|
|
1443
|
+
"remove",
|
|
1444
|
+
"allowAdd",
|
|
1445
|
+
"allowRemove",
|
|
1446
|
+
"startRegistration",
|
|
1447
|
+
"registrationStatus",
|
|
1448
|
+
"cancelRegistration",
|
|
1449
|
+
"startRuntime",
|
|
1450
|
+
"stopRuntime"
|
|
1451
|
+
];
|
|
1452
|
+
var channelSettingsKey = /* @__PURE__ */ Symbol.for("nomi.workbench-channel-settings");
|
|
1453
|
+
var channelSettingsValue = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
1454
|
+
function workbenchChannelSettings(system) {
|
|
1455
|
+
const request = system[channelSettingsKey];
|
|
1456
|
+
if (!request) throw new AppHostError("incompatible");
|
|
1457
|
+
return request;
|
|
1458
|
+
}
|
|
1519
1459
|
var SYSTEM_METHODS = [
|
|
1520
1460
|
"system.projects",
|
|
1461
|
+
"system.workspace",
|
|
1521
1462
|
"system.extensions",
|
|
1522
1463
|
"system.modelProviders",
|
|
1464
|
+
"system.channelSettings",
|
|
1523
1465
|
"system.providerDefaults",
|
|
1524
1466
|
"system.open",
|
|
1525
1467
|
"system.getPresentationPreferences",
|
|
@@ -1615,10 +1557,21 @@ function validSystemInput(method, value) {
|
|
|
1615
1557
|
switch (method) {
|
|
1616
1558
|
case "system.projects":
|
|
1617
1559
|
return validProjectRequest(value);
|
|
1560
|
+
case "system.workspace":
|
|
1561
|
+
return validLocalWorkspaceRequest(value);
|
|
1618
1562
|
case "system.extensions":
|
|
1619
1563
|
return validExtensionRequest(value);
|
|
1620
1564
|
case "system.modelProviders":
|
|
1621
1565
|
return validModelProviderRequest(value);
|
|
1566
|
+
case "system.channelSettings": {
|
|
1567
|
+
const action2 = enumeration(...CHANNEL_SETTINGS_ACTIONS);
|
|
1568
|
+
if (object({ action: enumeration("allowRemove"), input: text() })(value)) return true;
|
|
1569
|
+
if (object({
|
|
1570
|
+
action: enumeration("connect", "patch", "allowAdd", "startRegistration"),
|
|
1571
|
+
input: channelSettingsValue
|
|
1572
|
+
})(value)) return true;
|
|
1573
|
+
return object({ action: (entry) => action2(entry) && !["allowRemove", "connect", "patch", "allowAdd", "startRegistration"].includes(entry) })(value);
|
|
1574
|
+
}
|
|
1622
1575
|
case "system.providerDefaults":
|
|
1623
1576
|
return validProviderDefaultsRequest(value);
|
|
1624
1577
|
case "system.setTheme":
|
|
@@ -1664,10 +1617,14 @@ function validSystemResult(method, value) {
|
|
|
1664
1617
|
switch (method) {
|
|
1665
1618
|
case "system.projects":
|
|
1666
1619
|
return validProjectSnapshot(value);
|
|
1620
|
+
case "system.workspace":
|
|
1621
|
+
return validLocalWorkspaceResult(value);
|
|
1667
1622
|
case "system.extensions":
|
|
1668
1623
|
return validExtensionResult(value);
|
|
1669
1624
|
case "system.modelProviders":
|
|
1670
1625
|
return validModelProviderConnections(value);
|
|
1626
|
+
case "system.channelSettings":
|
|
1627
|
+
return object({ value: channelSettingsValue })(value) || object({ error: enumeration("invalid_configuration", "conflict") })(value);
|
|
1671
1628
|
case "system.providerDefaults":
|
|
1672
1629
|
return validProviderDefaultsSnapshot(value) || validProviderConnectionTestResult(value);
|
|
1673
1630
|
case "system.open":
|
|
@@ -1702,8 +1659,13 @@ function createAppSystemApi(requester, connectionOwner) {
|
|
|
1702
1659
|
throw new AppHostError("invalid_request");
|
|
1703
1660
|
return requester.request(method, params);
|
|
1704
1661
|
}
|
|
1705
|
-
|
|
1662
|
+
const system = {
|
|
1706
1663
|
projects: (input) => send("system.projects", input),
|
|
1664
|
+
workspace: (async (input) => {
|
|
1665
|
+
const result = await send("system.workspace", input);
|
|
1666
|
+
if (!validLocalWorkspaceResult(result, input.action)) throw new AppHostError("host_unavailable");
|
|
1667
|
+
return result;
|
|
1668
|
+
}),
|
|
1707
1669
|
extensions: (input) => send("system.extensions", input),
|
|
1708
1670
|
modelProviders: (input) => send("system.modelProviders", input),
|
|
1709
1671
|
providerDefaults: (async (input) => {
|
|
@@ -1731,10 +1693,14 @@ function createAppSystemApi(requester, connectionOwner) {
|
|
|
1731
1693
|
setTheme: (theme) => send("system.setTheme", { theme }),
|
|
1732
1694
|
setWindowMaterial: (preference) => send("system.setWindowMaterial", { preference }),
|
|
1733
1695
|
copyText: (text3) => send("system.copyText", { text: text3 }),
|
|
1734
|
-
openExternal: (
|
|
1696
|
+
openExternal: (url2) => send("system.openExternal", { url: url2 }),
|
|
1735
1697
|
navigationReady: () => send("system.navigationReady", {}),
|
|
1736
1698
|
completeNavigation: (input) => send("system.completeNavigation", input)
|
|
1737
1699
|
};
|
|
1700
|
+
Object.defineProperty(system, channelSettingsKey, {
|
|
1701
|
+
value: (input) => send("system.channelSettings", input)
|
|
1702
|
+
});
|
|
1703
|
+
return system;
|
|
1738
1704
|
}
|
|
1739
1705
|
|
|
1740
1706
|
// src/session-resources.ts
|
|
@@ -1753,17 +1719,103 @@ function validSessionResourceResult(_method, v) {
|
|
|
1753
1719
|
return resourceFields(v, ["connectionId", "baseUrl"], ["defaultTaskLocation"]) && (!Object.hasOwn(v, "defaultTaskLocation") || v.defaultTaskLocation === "current" || v.defaultTaskLocation === "worktree") && str2(v.connectionId) && /^[A-Za-z0-9-]+$/.test(v.connectionId) && v.baseUrl === `https://app-host.invalid/connections/${v.connectionId}`;
|
|
1754
1720
|
}
|
|
1755
1721
|
|
|
1722
|
+
// src/workbench-computer.ts
|
|
1723
|
+
var WORKBENCH_COMPUTER_FEATURE = "workbench-computer-v1";
|
|
1724
|
+
var workbenchComputerKey = /* @__PURE__ */ Symbol.for("nomi.workbench-computer");
|
|
1725
|
+
function workbenchComputer(host) {
|
|
1726
|
+
return host[workbenchComputerKey];
|
|
1727
|
+
}
|
|
1728
|
+
var WORKBENCH_COMPUTER_METHODS = [
|
|
1729
|
+
"workbench.computer.availability",
|
|
1730
|
+
"workbench.computer.setConversation",
|
|
1731
|
+
"workbench.computer.preparePrompt",
|
|
1732
|
+
"workbench.computer.getActivity",
|
|
1733
|
+
"workbench.computer.reply",
|
|
1734
|
+
"workbench.computer.control",
|
|
1735
|
+
"workbench.computer.shareWindow",
|
|
1736
|
+
"workbench.computer.stopLocal"
|
|
1737
|
+
];
|
|
1738
|
+
var availability = ["unsupported", "disabled", "missing_driver", "ready"];
|
|
1739
|
+
var actions = ["pause", "resume", "disable_capture", "enable_capture"];
|
|
1740
|
+
function record(value) {
|
|
1741
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
1742
|
+
}
|
|
1743
|
+
function text2(value, limit = 256) {
|
|
1744
|
+
return typeof value === "string" && value.length > 0 && value.length <= limit;
|
|
1745
|
+
}
|
|
1746
|
+
function keys(value, ...names) {
|
|
1747
|
+
return Object.keys(value).length === names.length && names.every((name2) => Object.hasOwn(value, name2));
|
|
1748
|
+
}
|
|
1749
|
+
function isWorkbenchComputerMethod(method) {
|
|
1750
|
+
return WORKBENCH_COMPUTER_METHODS.includes(method);
|
|
1751
|
+
}
|
|
1752
|
+
function validWorkbenchComputerInput(method, value) {
|
|
1753
|
+
if (!record(value)) return false;
|
|
1754
|
+
switch (method) {
|
|
1755
|
+
case "workbench.computer.availability":
|
|
1756
|
+
case "workbench.computer.shareWindow":
|
|
1757
|
+
return keys(value);
|
|
1758
|
+
case "workbench.computer.setConversation":
|
|
1759
|
+
return keys(value, "sessionId") && (value.sessionId === null || text2(value.sessionId));
|
|
1760
|
+
case "workbench.computer.preparePrompt":
|
|
1761
|
+
return keys(value, "sessionId", "inputId") && text2(value.sessionId) && text2(value.inputId);
|
|
1762
|
+
case "workbench.computer.stopLocal":
|
|
1763
|
+
return keys(value, "sessionId", "runId") && text2(value.sessionId) && text2(value.runId);
|
|
1764
|
+
case "workbench.computer.getActivity":
|
|
1765
|
+
return keys(value, "sessionId") && text2(value.sessionId);
|
|
1766
|
+
case "workbench.computer.reply":
|
|
1767
|
+
return keys(value, "id", "choice") && text2(value.id) && (value.choice === null || text2(value.choice));
|
|
1768
|
+
case "workbench.computer.control":
|
|
1769
|
+
return keys(value, "sessionId", "runId", "action") && text2(value.sessionId) && text2(value.runId) && text2(value.action) && actions.includes(value.action);
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
function validActivity(value) {
|
|
1773
|
+
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");
|
|
1774
|
+
}
|
|
1775
|
+
function validWorkbenchComputerResult(method, value) {
|
|
1776
|
+
switch (method) {
|
|
1777
|
+
case "workbench.computer.availability":
|
|
1778
|
+
return text2(value) && availability.includes(value);
|
|
1779
|
+
case "workbench.computer.setConversation":
|
|
1780
|
+
case "workbench.computer.stopLocal":
|
|
1781
|
+
return value === void 0;
|
|
1782
|
+
case "workbench.computer.preparePrompt":
|
|
1783
|
+
case "workbench.computer.reply":
|
|
1784
|
+
case "workbench.computer.control":
|
|
1785
|
+
return typeof value === "boolean";
|
|
1786
|
+
case "workbench.computer.getActivity":
|
|
1787
|
+
return value === null || validActivity(value);
|
|
1788
|
+
case "workbench.computer.shareWindow":
|
|
1789
|
+
return value === null || record(value) && keys(value, "bytes") && value.bytes instanceof Uint8Array && value.bytes.byteLength > 0 && value.bytes.byteLength <= 8 * 1024 * 1024;
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
function validWorkbenchComputerEvent(value) {
|
|
1793
|
+
if (!record(value)) return false;
|
|
1794
|
+
if (value.type === "workbench-computer-activity") {
|
|
1795
|
+
const update = value.update;
|
|
1796
|
+
return record(update) && text2(update.sessionId) && (update.activity === null || validActivity(update.activity) && record(update.activity) && update.activity.sessionId === update.sessionId);
|
|
1797
|
+
}
|
|
1798
|
+
const event = value.interaction;
|
|
1799
|
+
if (value.type !== "workbench-computer-prompt" || !record(event)) return false;
|
|
1800
|
+
if (event.type === "dismissed") return text2(event.id);
|
|
1801
|
+
const prompt = event.prompt;
|
|
1802
|
+
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))));
|
|
1803
|
+
}
|
|
1804
|
+
|
|
1756
1805
|
// src/lifecycle.ts
|
|
1757
1806
|
function isAppLifecycleFrame(value) {
|
|
1758
1807
|
if (!value || typeof value !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(value))) return false;
|
|
1759
1808
|
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
1760
1809
|
if (Reflect.ownKeys(descriptors).some((key) => typeof key !== "string" || !descriptors[key].enumerable || !Object.hasOwn(descriptors[key], "value"))) return false;
|
|
1761
1810
|
const frame = value;
|
|
1762
|
-
const
|
|
1763
|
-
if (!
|
|
1811
|
+
const fields2 = frame.type === "lifecycle-prepare" ? ["protocol", "type", "id", "reason"] : frame.type === "lifecycle-cancel" ? ["protocol", "type", "id"] : frame.type === "lifecycle-result" ? ["protocol", "type", "id", "ready"] : void 0;
|
|
1812
|
+
if (!fields2 || Reflect.ownKeys(value).length !== fields2.length || !fields2.every((key) => Object.hasOwn(value, key)) || frame.protocol !== 1 || typeof frame.id !== "string" || !HOST_REQUEST_ID.test(frame.id)) return false;
|
|
1764
1813
|
return frame.type === "lifecycle-prepare" ? ["switch", "reload", "disable", "quit"].includes(frame.reason) : frame.type === "lifecycle-result" ? typeof frame.ready === "boolean" : true;
|
|
1765
1814
|
}
|
|
1766
1815
|
|
|
1816
|
+
// src/workspace.ts
|
|
1817
|
+
var validPickOptions = object({}, { requestId: (value) => value === void 0 || id(value) });
|
|
1818
|
+
|
|
1767
1819
|
// src/protocol.ts
|
|
1768
1820
|
var APP_HOST_PROTOCOL = 1;
|
|
1769
1821
|
var APP_HOST_READY = "nomi.app-host.ready";
|
|
@@ -1803,7 +1855,8 @@ var APP_HOST_METHODS = [
|
|
|
1803
1855
|
...ATTACHMENTS_METHODS,
|
|
1804
1856
|
...AUXILIARY_METHODS,
|
|
1805
1857
|
...SYSTEM_METHODS,
|
|
1806
|
-
...WINDOW_METHODS
|
|
1858
|
+
...WINDOW_METHODS,
|
|
1859
|
+
...WORKBENCH_COMPUTER_METHODS
|
|
1807
1860
|
];
|
|
1808
1861
|
export {
|
|
1809
1862
|
APP_HOST_ERROR_RETRY,
|
|
@@ -1834,13 +1887,12 @@ export {
|
|
|
1834
1887
|
FETCH_WINDOW_CHUNKS,
|
|
1835
1888
|
HOST_REQUEST_ID,
|
|
1836
1889
|
RESOURCE_CATALOG_METHODS,
|
|
1837
|
-
SERVICE_HOST_MAX_FRAME_BYTES,
|
|
1838
|
-
SERVICE_HOST_MAX_PENDING,
|
|
1839
|
-
SERVICE_HOST_METHODS,
|
|
1840
1890
|
SYSTEM_METHODS,
|
|
1841
1891
|
SYSTEM_SETTINGS_SECTIONS,
|
|
1842
1892
|
SYSTEM_SHORTCUT_IDS,
|
|
1843
1893
|
WINDOW_METHODS,
|
|
1894
|
+
WORKBENCH_COMPUTER_FEATURE,
|
|
1895
|
+
WORKBENCH_COMPUTER_METHODS,
|
|
1844
1896
|
appHostErrorMessage,
|
|
1845
1897
|
canonicalDesktopRequest,
|
|
1846
1898
|
createAppAttachmentsApi,
|
|
@@ -1859,9 +1911,9 @@ export {
|
|
|
1859
1911
|
isPageFetchFrame,
|
|
1860
1912
|
isResourceCatalogMethod,
|
|
1861
1913
|
isSafeErrorDetails,
|
|
1862
|
-
isServiceHostFrame,
|
|
1863
1914
|
isSystemMethod,
|
|
1864
1915
|
isWindowMethod,
|
|
1916
|
+
isWorkbenchComputerMethod,
|
|
1865
1917
|
matchAgentApiRoute,
|
|
1866
1918
|
normalizeAgentApiPath,
|
|
1867
1919
|
pageFetchPath,
|
|
@@ -1891,9 +1943,6 @@ export {
|
|
|
1891
1943
|
validResourceCatalogInput,
|
|
1892
1944
|
validResourceCatalogResult,
|
|
1893
1945
|
validResourceChanged,
|
|
1894
|
-
validServiceContext,
|
|
1895
|
-
validServiceHostInput,
|
|
1896
|
-
validServiceHostResult,
|
|
1897
1946
|
validSessionResourceInput,
|
|
1898
1947
|
validSessionResourceResult,
|
|
1899
1948
|
validSessionSettingsTarget,
|
|
@@ -1903,8 +1952,14 @@ export {
|
|
|
1903
1952
|
validWindowEvent,
|
|
1904
1953
|
validWindowInput,
|
|
1905
1954
|
validWindowResult,
|
|
1955
|
+
validWorkbenchComputerEvent,
|
|
1956
|
+
validWorkbenchComputerInput,
|
|
1957
|
+
validWorkbenchComputerResult,
|
|
1906
1958
|
validWorkspaceInput,
|
|
1907
1959
|
validWorkspaceOperation,
|
|
1908
|
-
validWorkspaceResult
|
|
1960
|
+
validWorkspaceResult,
|
|
1961
|
+
workbenchChannelSettings,
|
|
1962
|
+
workbenchComputer,
|
|
1963
|
+
workbenchComputerKey
|
|
1909
1964
|
};
|
|
1910
1965
|
//# sourceMappingURL=protocol.js.map
|