@bobannomi/app-host 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -40,8 +40,8 @@ function isSafeErrorDetails(value, depth = 0) {
40
40
  }
41
41
  function isAppHostErrorInfo(value) {
42
42
  if (!value || typeof value !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(value))) return false;
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
+ 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;
45
45
  const error = value;
46
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));
47
47
  }
@@ -166,9 +166,9 @@ var json = (value) => {
166
166
  if (list ? Object.getPrototypeOf(v) !== Array.prototype : ![Object.prototype, null].includes(Object.getPrototypeOf(v))) return false;
167
167
  seen.add(v);
168
168
  try {
169
- const keys2 = Reflect.ownKeys(v);
170
- if (list && keys2.length !== v.length + 1) return false;
171
- return keys2.every((k) => {
169
+ const keys3 = Reflect.ownKeys(v);
170
+ if (list && keys3.length !== v.length + 1) return false;
171
+ return keys3.every((k) => {
172
172
  if (list && k === "length") return true;
173
173
  const d = Object.getOwnPropertyDescriptor(v, k);
174
174
  size += typeof k === "string" ? k.length + 3 : 0;
@@ -211,7 +211,8 @@ var APP_HOST_FEATURES = [
211
211
  "window-update-check-v1",
212
212
  "embedded-browser-v1",
213
213
  "browser-binding-invalidation-v1",
214
- "browser-capture-preview-v1"
214
+ "browser-capture-preview-v1",
215
+ "workbench-computer-v1"
215
216
  ];
216
217
  var FETCH_CHUNK_BYTES = 64 * 1024;
217
218
  var FETCH_INLINE_BODY_BYTES = 8 * 1024;
@@ -244,10 +245,10 @@ function isPageFetchFrame(value) {
244
245
  const array2 = Array.isArray(entry);
245
246
  if (array2 ? Object.getPrototypeOf(entry) !== Array.prototype : ![Object.prototype, null].includes(Object.getPrototypeOf(entry)))
246
247
  return false;
247
- const keys2 = Reflect.ownKeys(entry);
248
- if (keys2.length > FETCH_METADATA_BYTES || array2 && keys2.length !== entry.length + 1)
248
+ const keys3 = Reflect.ownKeys(entry);
249
+ if (keys3.length > FETCH_METADATA_BYTES || array2 && keys3.length !== entry.length + 1)
249
250
  return false;
250
- return keys2.every((key) => {
251
+ return keys3.every((key) => {
251
252
  if (array2 && key === "length") return true;
252
253
  const d = Object.getOwnPropertyDescriptor(entry, key);
253
254
  size += typeof key === "string" ? key.length + 3 : 0;
@@ -580,7 +581,7 @@ function validAppCommandSnapshot(value) {
580
581
  (m) => m.items.some((i) => "command" in i && !ids.has(i.command))
581
582
  ) || Object.values(v.toolbar ?? {}).some((x) => !ids.has(x)))
582
583
  return false;
583
- const keys2 = /* @__PURE__ */ new Set();
584
+ const keys3 = /* @__PURE__ */ new Set();
584
585
  for (const command of v.commands)
585
586
  for (const key of command.shortcuts ?? []) {
586
587
  const mods = new Set(key.modifiers);
@@ -589,8 +590,8 @@ function validAppCommandSnapshot(value) {
589
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")
590
591
  return false;
591
592
  const signature = `${[...mods].map((m) => m === "Control" || m === "Meta" ? "Primary" : m).sort().join("+")}:${key.code}`;
592
- if (keys2.has(signature)) return false;
593
- keys2.add(signature);
593
+ if (keys3.has(signature)) return false;
594
+ keys3.add(signature);
594
595
  }
595
596
  return true;
596
597
  }
@@ -719,6 +720,65 @@ function createAppCommandsApi(rpc) {
719
720
  };
720
721
  }
721
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
+
722
782
  // src/resource-catalog.ts
723
783
  var RESOURCE_CATALOG_METHODS = ["workspace.list"];
724
784
  var isResourceCatalogMethod = (m) => RESOURCE_CATALOG_METHODS.includes(m);
@@ -769,22 +829,22 @@ function createConversationPreparationApi(rpc) {
769
829
  // src/client-connections.ts
770
830
  var connections = /* @__PURE__ */ new WeakMap();
771
831
  function createClientConnection(wire, streams) {
772
- const record3 = { owner: streams, id: wire.connectionId, closed: false };
832
+ const record4 = { owner: streams, id: wire.connectionId, closed: false };
773
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() {
774
- return record3.closed || streams.isClosed?.(wire.connectionId) === true;
834
+ return record4.closed || streams.isClosed?.(wire.connectionId) === true;
775
835
  }, close() {
776
- if (!record3.closed) {
777
- record3.closed = true;
836
+ if (!record4.closed) {
837
+ record4.closed = true;
778
838
  streams.close(wire.connectionId);
779
839
  }
780
840
  } };
781
- connections.set(connection, record3);
841
+ connections.set(connection, record4);
782
842
  return connection;
783
843
  }
784
844
  function resolveClientConnection(connection, owner) {
785
- const record3 = connections.get(connection);
786
- if (!record3 || record3.owner !== owner || record3.closed || owner.isClosed?.(record3.id)) throw new AppHostError("connection_revoked");
787
- return record3.id;
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;
788
848
  }
789
849
 
790
850
  // src/desktop.ts
@@ -1173,8 +1233,8 @@ var limits = { contextWindow: count, maxOutputTokens: count };
1173
1233
  function headerValues(check) {
1174
1234
  return (value) => {
1175
1235
  if (!value || typeof value !== "object" || Array.isArray(value)) return false;
1176
- const keys2 = Object.keys(value);
1177
- return keys2.length <= 128 && keys2.every((key) => /^[!#$%&'*+.^_`|~0-9A-Za-z-]{1,256}$/.test(key)) && object(Object.fromEntries(keys2.map((key) => [key, check])))(value);
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);
1178
1238
  };
1179
1239
  }
1180
1240
  var headers = headerValues(text(8192, true));
@@ -1211,8 +1271,8 @@ function validProviderDefaultsRequest(value) {
1211
1271
  var verifiedProvider = object({ model: modelId, checkedAt: count });
1212
1272
  var verified = (value) => {
1213
1273
  if (!value || typeof value !== "object" || Array.isArray(value)) return false;
1214
- const keys2 = Object.keys(value);
1215
- return keys2.length <= 4096 && keys2.every(provider) && object(Object.fromEntries(keys2.map((key) => [key, verifiedProvider])))(value);
1274
+ const keys3 = Object.keys(value);
1275
+ return keys3.length <= 4096 && keys3.every(provider) && object(Object.fromEntries(keys3.map((key) => [key, verifiedProvider])))(value);
1216
1276
  };
1217
1277
  var defaultsModel = object({ id: modelId, label: text(1024), provider: text(1024), providerName: provider }, {
1218
1278
  reasoningEfforts: array(text(256, true)),
@@ -1248,7 +1308,6 @@ var SYSTEM_SETTINGS_SECTIONS = [
1248
1308
  "permissions",
1249
1309
  "personalization",
1250
1310
  "billing",
1251
- "connections",
1252
1311
  "terminal",
1253
1312
  "git",
1254
1313
  "runtime",
@@ -1275,11 +1334,28 @@ var SYSTEM_SHORTCUT_IDS = [
1275
1334
  "resetZoom",
1276
1335
  "showShortcuts"
1277
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);
1278
1353
  var SYSTEM_METHODS = [
1279
1354
  "system.projects",
1280
1355
  "system.workspace",
1281
1356
  "system.extensions",
1282
1357
  "system.modelProviders",
1358
+ "system.channelSettings",
1283
1359
  "system.providerDefaults",
1284
1360
  "system.open",
1285
1361
  "system.getPresentationPreferences",
@@ -1381,6 +1457,15 @@ function validSystemInput(method, value) {
1381
1457
  return validExtensionRequest(value);
1382
1458
  case "system.modelProviders":
1383
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
+ }
1384
1469
  case "system.providerDefaults":
1385
1470
  return validProviderDefaultsRequest(value);
1386
1471
  case "system.setTheme":
@@ -1432,6 +1517,8 @@ function validSystemResult(method, value) {
1432
1517
  return validExtensionResult(value);
1433
1518
  case "system.modelProviders":
1434
1519
  return validModelProviderConnections(value);
1520
+ case "system.channelSettings":
1521
+ return object({ value: channelSettingsValue })(value) || object({ error: enumeration("invalid_configuration", "conflict") })(value);
1435
1522
  case "system.providerDefaults":
1436
1523
  return validProviderDefaultsSnapshot(value) || validProviderConnectionTestResult(value);
1437
1524
  case "system.open":
@@ -1466,7 +1553,7 @@ function createAppSystemApi(requester, connectionOwner) {
1466
1553
  throw new AppHostError("invalid_request");
1467
1554
  return requester.request(method, params);
1468
1555
  }
1469
- return {
1556
+ const system = {
1470
1557
  projects: (input) => send("system.projects", input),
1471
1558
  workspace: (async (input) => {
1472
1559
  const result = await send("system.workspace", input);
@@ -1499,11 +1586,15 @@ function createAppSystemApi(requester, connectionOwner) {
1499
1586
  getPresentationPreferences: () => send("system.getPresentationPreferences", {}),
1500
1587
  setTheme: (theme) => send("system.setTheme", { theme }),
1501
1588
  setWindowMaterial: (preference) => send("system.setWindowMaterial", { preference }),
1502
- copyText: (text2) => send("system.copyText", { text: text2 }),
1589
+ copyText: (text3) => send("system.copyText", { text: text3 }),
1503
1590
  openExternal: (url2) => send("system.openExternal", { url: url2 }),
1504
1591
  navigationReady: () => send("system.navigationReady", {}),
1505
1592
  completeNavigation: (input) => send("system.completeNavigation", input)
1506
1593
  };
1594
+ Object.defineProperty(system, channelSettingsKey, {
1595
+ value: (input) => send("system.channelSettings", input)
1596
+ });
1597
+ return system;
1507
1598
  }
1508
1599
 
1509
1600
  // src/window.ts
@@ -1873,7 +1964,8 @@ var APP_HOST_METHODS = [
1873
1964
  ...ATTACHMENTS_METHODS,
1874
1965
  ...AUXILIARY_METHODS,
1875
1966
  ...SYSTEM_METHODS,
1876
- ...WINDOW_METHODS
1967
+ ...WINDOW_METHODS,
1968
+ ...WORKBENCH_COMPUTER_METHODS
1877
1969
  ];
1878
1970
 
1879
1971
  // src/transport/fetch-client.ts
@@ -2187,11 +2279,11 @@ var hostFailure = (reason, requestId) => {
2187
2279
  }
2188
2280
  );
2189
2281
  };
2190
- function record(value) {
2282
+ function record2(value) {
2191
2283
  return value !== null && typeof value === "object" && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
2192
2284
  }
2193
- function keys(value, required, optional = []) {
2194
- if (!record(value)) return false;
2285
+ function keys2(value, required, optional = []) {
2286
+ if (!record2(value)) return false;
2195
2287
  const own = Reflect.ownKeys(value);
2196
2288
  return required.every((k) => Object.hasOwn(value, k)) && own.every(
2197
2289
  (k) => typeof k === "string" && (required.includes(k) || optional.includes(k)) && Object.getOwnPropertyDescriptor(value, k)?.enumerable && Object.hasOwn(Object.getOwnPropertyDescriptor(value, k), "value")
@@ -2213,7 +2305,7 @@ function json3(value, ancestors = /* @__PURE__ */ new Set()) {
2213
2305
  if (value === null || typeof value === "string" || typeof value === "boolean")
2214
2306
  return true;
2215
2307
  if (typeof value === "number") return Number.isFinite(value);
2216
- if (typeof value !== "object" || !record(value) && !Array.isArray(value) || ancestors.has(value))
2308
+ if (typeof value !== "object" || !record2(value) && !Array.isArray(value) || ancestors.has(value))
2217
2309
  return false;
2218
2310
  if (Array.isArray(value) && (Object.getPrototypeOf(value) !== Array.prototype || Reflect.ownKeys(value).length !== value.length + 1))
2219
2311
  return false;
@@ -2230,7 +2322,7 @@ function json3(value, ancestors = /* @__PURE__ */ new Set()) {
2230
2322
  }
2231
2323
  function payloadSize(value) {
2232
2324
  if (value instanceof Uint8Array) return value.byteLength;
2233
- if (record(value) && value.bytes instanceof Uint8Array) {
2325
+ if (record2(value) && value.bytes instanceof Uint8Array) {
2234
2326
  const { bytes: bytes2, ...metadata } = value;
2235
2327
  return bytes2.byteLength + new TextEncoder().encode(JSON.stringify(metadata)).byteLength;
2236
2328
  }
@@ -2239,10 +2331,10 @@ function payloadSize(value) {
2239
2331
  }
2240
2332
  function responsePayloadFits(method, value) {
2241
2333
  if (value === void 0) return true;
2242
- if (method === "system.workspace" && record(value)) {
2334
+ if (method === "system.workspace" && record2(value)) {
2243
2335
  const { previewBytes, documentPreview, ...metadata } = value;
2244
2336
  const image = previewBytes instanceof ArrayBuffer;
2245
- const document = record(documentPreview) && documentPreview.bytes instanceof ArrayBuffer;
2337
+ const document = record2(documentPreview) && documentPreview.bytes instanceof ArrayBuffer;
2246
2338
  if (image || document) {
2247
2339
  return !(image && document) && payloadSize({
2248
2340
  ...metadata,
@@ -2253,7 +2345,7 @@ function responsePayloadFits(method, value) {
2253
2345
  return payloadSize(value) <= APP_HOST_MAX_PAYLOAD_BYTES;
2254
2346
  }
2255
2347
  function validContext(value) {
2256
- return keys(value, [
2348
+ return keys2(value, [
2257
2349
  "appId",
2258
2350
  "appVersion",
2259
2351
  "installationId",
@@ -2271,32 +2363,34 @@ function validContext(value) {
2271
2363
  "hostVersion",
2272
2364
  "hostApiVersion",
2273
2365
  "locale"
2274
- ].every((k) => nonempty(value[k])) && ["bundled", "remote"].includes(value.uiType) && ["light", "dark"].includes(value.theme) && Number.isSafeInteger(value.storageQuotaBytes) && value.storageQuotaBytes > 0 && record(value.capabilities) && Object.values(value.capabilities).every(
2275
- (c) => keys(c, ["granted"], ["reason"]) && typeof c.granted === "boolean" && (!Object.hasOwn(c, "reason") || typeof c.reason === "string")
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")
2276
2368
  );
2277
2369
  }
2278
2370
  function validEvent(value) {
2279
- if (!record(value)) return false;
2371
+ if (!record2(value)) return false;
2280
2372
  if (validCommandInvocation(value) || validResourceChanged(value)) return true;
2281
2373
  if (validSystemEvent(value)) return true;
2282
2374
  if (validWindowEvent(value)) return true;
2283
2375
  if (validDesktopEvent(value)) return true;
2376
+ if (validWorkbenchComputerEvent(value)) return true;
2284
2377
  switch (value.type) {
2285
2378
  case "service-changed":
2286
- return keys(value, ["type", "service"]) && validServiceStatus(value.service);
2379
+ return keys2(value, ["type", "service"]) && validServiceStatus(value.service);
2287
2380
  case "visibility":
2288
- return keys(value, ["type", "visible"]) && typeof value.visible === "boolean";
2381
+ return keys2(value, ["type", "visible"]) && typeof value.visible === "boolean";
2289
2382
  case "context-changed":
2290
- return keys(value, ["type", "context"]) && validContext(value.context);
2383
+ return keys2(value, ["type", "context"]) && validContext(value.context);
2291
2384
  case "connection-revoked":
2292
- return keys(value, ["type", "reason"]) && typeof value.reason === "string";
2385
+ return keys2(value, ["type", "reason"]) && typeof value.reason === "string";
2293
2386
  case "before-unload":
2294
- return keys(value, ["type", "reason"]) && ["switch", "reload", "disable", "quit"].includes(value.reason);
2387
+ return keys2(value, ["type", "reason"]) && ["switch", "reload", "disable", "quit"].includes(value.reason);
2295
2388
  default:
2296
2389
  return false;
2297
2390
  }
2298
2391
  }
2299
2392
  function validResult(method, value) {
2393
+ if (isWorkbenchComputerMethod(method)) return validWorkbenchComputerResult(method, value);
2300
2394
  if (isCommandsMethod(method)) return validCommandReceipt(value);
2301
2395
  if (isResourceCatalogMethod(method))
2302
2396
  return validResourceCatalogResult(method, value);
@@ -2316,20 +2410,20 @@ function validResult(method, value) {
2316
2410
  return validServiceResult(method, value);
2317
2411
  switch (method) {
2318
2412
  case "negotiate":
2319
- return keys(value, ["features"]) && dataArray(value.features) && value.features.length <= APP_HOST_FEATURES.length && new Set(value.features).size === value.features.length && value.features.every(
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(
2320
2414
  (f) => APP_HOST_FEATURES.includes(f)
2321
2415
  );
2322
2416
  case "connect":
2323
2417
  case "getContext":
2324
2418
  return validContext(value);
2325
2419
  case "storage.get":
2326
- return keys(value, ["found"], ["value"]) && (value.found === false && !Object.hasOwn(value, "value") || value.found === true && Object.hasOwn(value, "value") && json3(value.value));
2420
+ return keys2(value, ["found"], ["value"]) && (value.found === false && !Object.hasOwn(value, "value") || value.found === true && Object.hasOwn(value, "value") && json3(value.value));
2327
2421
  case "storage.putFile":
2328
- return keys(value, ["id", "name", "size"]) && nonempty(value.id) && nonempty(value.name) && Number.isSafeInteger(value.size) && value.size >= 0;
2422
+ return keys2(value, ["id", "name", "size"]) && nonempty(value.id) && nonempty(value.name) && Number.isSafeInteger(value.size) && value.size >= 0;
2329
2423
  case "storage.readFile":
2330
2424
  return value instanceof Uint8Array;
2331
2425
  case "auth.openLogin":
2332
- return keys(value, ["status"], ["callbackUrl"]) && (value.status === "cancelled" && !Object.hasOwn(value, "callbackUrl") || value.status === "completed" && nonempty(value.callbackUrl));
2426
+ return keys2(value, ["status"], ["callbackUrl"]) && (value.status === "cancelled" && !Object.hasOwn(value, "callbackUrl") || value.status === "completed" && nonempty(value.callbackUrl));
2333
2427
  default:
2334
2428
  return value === void 0;
2335
2429
  }
@@ -2393,7 +2487,7 @@ var DocumentConnection = class {
2393
2487
  }
2394
2488
  pagehide = () => this.close(failure("connection_revoked"));
2395
2489
  receivePort = (event) => {
2396
- if (event.source !== this.page || !keys(event.data, ["type", "protocol"]) || event.data.type !== APP_HOST_PORT || event.data.protocol !== APP_HOST_PROTOCOL || event.ports.length !== 1)
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)
2397
2491
  return;
2398
2492
  const port = event.ports[0];
2399
2493
  if (this.port || this.closed) {
@@ -2435,7 +2529,7 @@ var DocumentConnection = class {
2435
2529
  receive = (event) => {
2436
2530
  const data = event.data;
2437
2531
  try {
2438
- if (!record(data)) throw failure("host_unavailable");
2532
+ if (!record2(data)) throw failure("host_unavailable");
2439
2533
  const frameType = Object.getOwnPropertyDescriptor(data, "type")?.value;
2440
2534
  if (typeof frameType === "string" && frameType.startsWith("fetch-")) {
2441
2535
  if (!isPageFetchFrame(data)) throw failure("host_unavailable");
@@ -2453,7 +2547,7 @@ var DocumentConnection = class {
2453
2547
  return;
2454
2548
  }
2455
2549
  if (data.type === "event") {
2456
- if (!keys(data, ["protocol", "type", "sequence", "event"]) || !Number.isSafeInteger(data.sequence) || data.sequence <= 0 || !validEvent(data.event) || payloadSize(data.event) > APP_HOST_MAX_PAYLOAD_BYTES)
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)
2457
2551
  throw failure("host_unavailable");
2458
2552
  if (data.sequence <= this.sequence) return;
2459
2553
  if (data.sequence !== this.sequence + 1)
@@ -2473,6 +2567,7 @@ var DocumentConnection = class {
2473
2567
  }
2474
2568
  if (validSystemEvent(appEvent)) this.requireFeature("system-ui-v1");
2475
2569
  if (validWindowEvent(appEvent)) this.requireFeature("window-chrome-v1");
2570
+ if (validWorkbenchComputerEvent(appEvent)) this.requireFeature(WORKBENCH_COMPUTER_FEATURE);
2476
2571
  const observers = [...this.listeners];
2477
2572
  if (appEvent.type === "connection-revoked")
2478
2573
  this.close(failure("connection_revoked"));
@@ -2489,13 +2584,13 @@ var DocumentConnection = class {
2489
2584
  const p = this.pending.get(data.id);
2490
2585
  if (!p) return;
2491
2586
  if (data.ok === true) {
2492
- if (!keys(data, ["protocol", "type", "id", "ok"], ["value"]) || !validResult(p.method, data.value) || !responsePayloadFits(p.method, data.value))
2587
+ if (!keys2(data, ["protocol", "type", "id", "ok"], ["value"]) || !validResult(p.method, data.value) || !responsePayloadFits(p.method, data.value))
2493
2588
  throw failure("host_unavailable");
2494
2589
  clearTimeout(p.timer);
2495
2590
  this.pending.delete(data.id);
2496
2591
  p.resolve(data.value);
2497
2592
  } else {
2498
- if (!keys(data, ["protocol", "type", "id", "ok", "error"]) || data.ok !== false || !isAppHostErrorInfo(data.error) || payloadSize(data.error) > APP_HOST_MAX_PAYLOAD_BYTES)
2593
+ if (!keys2(data, ["protocol", "type", "id", "ok", "error"]) || data.ok !== false || !isAppHostErrorInfo(data.error) || payloadSize(data.error) > APP_HOST_MAX_PAYLOAD_BYTES)
2499
2594
  throw failure("host_unavailable");
2500
2595
  const error = new AppHostError(
2501
2596
  data.error.code,
@@ -2551,7 +2646,7 @@ var DocumentConnection = class {
2551
2646
  requireFeature: () => this.requireFeature("session-controls-v1"),
2552
2647
  request: (method, params2) => this.request(method, params2)
2553
2648
  });
2554
- return {
2649
+ const host = {
2555
2650
  hasFeature: (feature) => this.features.has(feature),
2556
2651
  commands: createAppCommandsApi({
2557
2652
  requireFeature: () => this.requireFeature("commands-v1"),
@@ -2677,9 +2772,29 @@ var DocumentConnection = class {
2677
2772
  },
2678
2773
  auth: { openLogin: (input) => this.login(input) }
2679
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;
2680
2795
  }
2681
2796
  async login(input) {
2682
- if (!keys(input, ["url"]) || !nonempty(input.url))
2797
+ if (!keys2(input, ["url"]) || !nonempty(input.url))
2683
2798
  throw failure("invalid_request");
2684
2799
  try {
2685
2800
  if (new URL(input.url).protocol !== "https:")
@@ -2698,7 +2813,8 @@ var DocumentConnection = class {
2698
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;
2699
2814
  const selectionRequestId = method === "workspace.select" ? params.requestId : void 0;
2700
2815
  let timeout = APP_HOST_REQUEST_TIMEOUT_MS;
2701
- if (method === "auth.openLogin" || method === "workspace.select" || method === "system.workspace" && "action" in params && params.action === "pick")
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")
2702
2818
  timeout = APP_HOST_LOGIN_TRANSPORT_TIMEOUT_MS;
2703
2819
  if (method === "system.extensions") {
2704
2820
  const { operation } = params;
@@ -2738,7 +2854,7 @@ var DocumentConnection = class {
2738
2854
  };
2739
2855
  var documents = /* @__PURE__ */ new WeakMap();
2740
2856
  async function connectAppHost(options) {
2741
- if (!keys(options, ["hostApi"]) || !nonempty(options.hostApi))
2857
+ if (!keys2(options, ["hostApi"]) || !nonempty(options.hostApi))
2742
2858
  throw failure("invalid_request");
2743
2859
  if (typeof window === "undefined") throw failure("host_unavailable");
2744
2860
  let connection = documents.get(window);
@@ -2762,8 +2878,8 @@ function copyBoundedJson(value, options) {
2762
2878
  const { maxBytes, maxDepth } = options;
2763
2879
  const ancestors = /* @__PURE__ */ new Set();
2764
2880
  let budget = maxBytes;
2765
- const spend = (text2) => {
2766
- budget -= new TextEncoder().encode(text2).byteLength;
2881
+ const spend = (text3) => {
2882
+ budget -= new TextEncoder().encode(text3).byteLength;
2767
2883
  if (budget < 0) throw new JsonCopyError("too_large");
2768
2884
  };
2769
2885
  const copy = (item, depth) => {
@@ -2878,9 +2994,9 @@ function validatePluginAppComposerContexts(value) {
2878
2994
  return validate(parsePluginAppComposerContexts, value);
2879
2995
  }
2880
2996
  function parsePluginAppConversationInput(value) {
2881
- const input = record2(copyPluginAppJson(value, PLUGIN_APP_INPUT_LIMITS.handoffBytes + 32 * 1024));
2997
+ const input = record3(copyPluginAppJson(value, PLUGIN_APP_INPUT_LIMITS.handoffBytes + 32 * 1024));
2882
2998
  fields3(input, ["source", "lease", "requestId", "expectedRevision", "text", "data"]);
2883
- const lease = record2(input.lease);
2999
+ const lease = record3(input.lease);
2884
3000
  fields3(lease, ["token", "backendGeneration"]);
2885
3001
  if (typeof input.text !== "string" || [...input.text].length > PLUGIN_APP_INPUT_LIMITS.messageCharacters || !input.text.trim())
2886
3002
  throw new InputError("plugin_app_invalid_message");
@@ -2893,7 +3009,7 @@ function parsePluginAppConversationInput(value) {
2893
3009
  data: copyPluginAppJson(input.data, PLUGIN_APP_INPUT_LIMITS.handoffBytes)
2894
3010
  };
2895
3011
  }
2896
- function record2(value) {
3012
+ function record3(value) {
2897
3013
  if (!value || typeof value !== "object" || Array.isArray(value)) throw new InputError("plugin_app_invalid_request");
2898
3014
  return value;
2899
3015
  }
@@ -2909,7 +3025,7 @@ function revision2(value) {
2909
3025
  return value;
2910
3026
  }
2911
3027
  function parsePluginAppSource(value) {
2912
- const input = record2(copyPluginAppJson(value, 4096));
3028
+ const input = record3(copyPluginAppJson(value, 4096));
2913
3029
  fields3(input, ["sessionId", "appId"]);
2914
3030
  return { sessionId: identifier2(input.sessionId), appId: identifier2(input.appId) };
2915
3031
  }