@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/protocol.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 keys = Reflect.ownKeys(value);
44
- if (!keys.every((key) => typeof key === "string" && ["code", "message", "retry", "requestId", "details"].includes(key) && Object.hasOwn(Object.getOwnPropertyDescriptor(value, key), "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;
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 keys = Reflect.ownKeys(v);
170
- if (list && keys.length !== v.length + 1) return false;
171
- return keys.every((k) => {
169
+ const keys2 = Reflect.ownKeys(v);
170
+ if (list && keys2.length !== v.length + 1) return false;
171
+ return keys2.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 keys = Reflect.ownKeys(entry);
248
- if (keys.length > FETCH_METADATA_BYTES || array2 && keys.length !== entry.length + 1)
248
+ const keys2 = Reflect.ownKeys(entry);
249
+ if (keys2.length > FETCH_METADATA_BYTES || array2 && keys2.length !== entry.length + 1)
249
250
  return false;
250
- return keys.every((key) => {
251
+ return keys2.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;
@@ -316,6 +317,7 @@ var routes = [
316
317
  { method: "DELETE", pattern: /^\/schedules\/tasks\/[^/]+$/, id: "schedules.delete" },
317
318
  { method: "GET", pattern: /^\/(health|capabilities)$/, id: "protocol.read" },
318
319
  { method: "GET", pattern: /^\/(models|agent-personas|skills)$/, id: "resources.read" },
320
+ { method: "POST", pattern: /^\/model-connections$/, id: "models.prepare" },
319
321
  { method: "GET", pattern: /^\/sessions\/[^/]+\/goal(?:\/requests\/[^/]+)?$/, id: "goals.read" },
320
322
  { method: "POST", pattern: /^\/sessions\/[^/]+\/goals$/, id: "goals.write" },
321
323
  { method: "POST", pattern: /^\/sessions\/[^/]+\/goals\/[^/]+\/actions$/, id: "goals.actions" },
@@ -570,7 +572,7 @@ function validAppCommandSnapshot(value) {
570
572
  (m) => m.items.some((i) => "command" in i && !ids.has(i.command))
571
573
  ) || Object.values(v.toolbar ?? {}).some((x) => !ids.has(x)))
572
574
  return false;
573
- const keys = /* @__PURE__ */ new Set();
575
+ const keys2 = /* @__PURE__ */ new Set();
574
576
  for (const command of v.commands)
575
577
  for (const key of command.shortcuts ?? []) {
576
578
  const mods = new Set(key.modifiers);
@@ -579,8 +581,8 @@ function validAppCommandSnapshot(value) {
579
581
  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")
580
582
  return false;
581
583
  const signature = `${[...mods].map((m) => m === "Control" || m === "Meta" ? "Primary" : m).sort().join("+")}:${key.code}`;
582
- if (keys.has(signature)) return false;
583
- keys.add(signature);
584
+ if (keys2.has(signature)) return false;
585
+ keys2.add(signature);
584
586
  }
585
587
  return true;
586
588
  }
@@ -859,22 +861,22 @@ function validConversationPreparationResult(method, result) {
859
861
  // src/client-connections.ts
860
862
  var connections = /* @__PURE__ */ new WeakMap();
861
863
  function createClientConnection(wire, streams) {
862
- const record = { owner: streams, id: wire.connectionId, closed: false };
864
+ const record2 = { owner: streams, id: wire.connectionId, closed: false };
863
865
  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() {
864
- return record.closed || streams.isClosed?.(wire.connectionId) === true;
866
+ return record2.closed || streams.isClosed?.(wire.connectionId) === true;
865
867
  }, close() {
866
- if (!record.closed) {
867
- record.closed = true;
868
+ if (!record2.closed) {
869
+ record2.closed = true;
868
870
  streams.close(wire.connectionId);
869
871
  }
870
872
  } };
871
- connections.set(connection, record);
873
+ connections.set(connection, record2);
872
874
  return connection;
873
875
  }
874
876
  function resolveClientConnection(connection, owner) {
875
- const record = connections.get(connection);
876
- if (!record || record.owner !== owner || record.closed || owner.isClosed?.(record.id)) throw new AppHostError("connection_revoked");
877
- return record.id;
877
+ const record2 = connections.get(connection);
878
+ if (!record2 || record2.owner !== owner || record2.closed || owner.isClosed?.(record2.id)) throw new AppHostError("connection_revoked");
879
+ return record2.id;
878
880
  }
879
881
 
880
882
  // src/desktop.ts
@@ -1333,8 +1335,8 @@ var limits = { contextWindow: count, maxOutputTokens: count };
1333
1335
  function headerValues(check) {
1334
1336
  return (value) => {
1335
1337
  if (!value || typeof value !== "object" || Array.isArray(value)) return false;
1336
- const keys = Object.keys(value);
1337
- return keys.length <= 128 && keys.every((key) => /^[!#$%&'*+.^_`|~0-9A-Za-z-]{1,256}$/.test(key)) && object(Object.fromEntries(keys.map((key) => [key, check])))(value);
1338
+ const keys2 = Object.keys(value);
1339
+ return keys2.length <= 128 && keys2.every((key) => /^[!#$%&'*+.^_`|~0-9A-Za-z-]{1,256}$/.test(key)) && object(Object.fromEntries(keys2.map((key) => [key, check])))(value);
1338
1340
  };
1339
1341
  }
1340
1342
  var headers = headerValues(text(8192, true));
@@ -1371,8 +1373,8 @@ function validProviderDefaultsRequest(value) {
1371
1373
  var verifiedProvider = object({ model: modelId, checkedAt: count });
1372
1374
  var verified = (value) => {
1373
1375
  if (!value || typeof value !== "object" || Array.isArray(value)) return false;
1374
- const keys = Object.keys(value);
1375
- return keys.length <= 4096 && keys.every(provider) && object(Object.fromEntries(keys.map((key) => [key, verifiedProvider])))(value);
1376
+ const keys2 = Object.keys(value);
1377
+ return keys2.length <= 4096 && keys2.every(provider) && object(Object.fromEntries(keys2.map((key) => [key, verifiedProvider])))(value);
1376
1378
  };
1377
1379
  var defaultsModel = object({ id: modelId, label: text(1024), provider: text(1024), providerName: provider }, {
1378
1380
  reasoningEfforts: array(text(256, true)),
@@ -1408,7 +1410,6 @@ var SYSTEM_SETTINGS_SECTIONS = [
1408
1410
  "permissions",
1409
1411
  "personalization",
1410
1412
  "billing",
1411
- "connections",
1412
1413
  "terminal",
1413
1414
  "git",
1414
1415
  "runtime",
@@ -1435,11 +1436,33 @@ var SYSTEM_SHORTCUT_IDS = [
1435
1436
  "resetZoom",
1436
1437
  "showShortcuts"
1437
1438
  ];
1439
+ var CHANNEL_SETTINGS_ACTIONS = [
1440
+ "snapshot",
1441
+ "runtimeStatus",
1442
+ "connect",
1443
+ "patch",
1444
+ "remove",
1445
+ "allowAdd",
1446
+ "allowRemove",
1447
+ "startRegistration",
1448
+ "registrationStatus",
1449
+ "cancelRegistration",
1450
+ "startRuntime",
1451
+ "stopRuntime"
1452
+ ];
1453
+ var channelSettingsKey = /* @__PURE__ */ Symbol.for("nomi.workbench-channel-settings");
1454
+ var channelSettingsValue = (value) => !!value && typeof value === "object" && !Array.isArray(value);
1455
+ function workbenchChannelSettings(system) {
1456
+ const request = system[channelSettingsKey];
1457
+ if (!request) throw new AppHostError("incompatible");
1458
+ return request;
1459
+ }
1438
1460
  var SYSTEM_METHODS = [
1439
1461
  "system.projects",
1440
1462
  "system.workspace",
1441
1463
  "system.extensions",
1442
1464
  "system.modelProviders",
1465
+ "system.channelSettings",
1443
1466
  "system.providerDefaults",
1444
1467
  "system.open",
1445
1468
  "system.getPresentationPreferences",
@@ -1541,6 +1564,15 @@ function validSystemInput(method, value) {
1541
1564
  return validExtensionRequest(value);
1542
1565
  case "system.modelProviders":
1543
1566
  return validModelProviderRequest(value);
1567
+ case "system.channelSettings": {
1568
+ const action2 = enumeration(...CHANNEL_SETTINGS_ACTIONS);
1569
+ if (object({ action: enumeration("allowRemove"), input: text() })(value)) return true;
1570
+ if (object({
1571
+ action: enumeration("connect", "patch", "allowAdd", "startRegistration"),
1572
+ input: channelSettingsValue
1573
+ })(value)) return true;
1574
+ return object({ action: (entry) => action2(entry) && !["allowRemove", "connect", "patch", "allowAdd", "startRegistration"].includes(entry) })(value);
1575
+ }
1544
1576
  case "system.providerDefaults":
1545
1577
  return validProviderDefaultsRequest(value);
1546
1578
  case "system.setTheme":
@@ -1592,6 +1624,8 @@ function validSystemResult(method, value) {
1592
1624
  return validExtensionResult(value);
1593
1625
  case "system.modelProviders":
1594
1626
  return validModelProviderConnections(value);
1627
+ case "system.channelSettings":
1628
+ return object({ value: channelSettingsValue })(value) || object({ error: enumeration("invalid_configuration", "conflict") })(value);
1595
1629
  case "system.providerDefaults":
1596
1630
  return validProviderDefaultsSnapshot(value) || validProviderConnectionTestResult(value);
1597
1631
  case "system.open":
@@ -1626,7 +1660,7 @@ function createAppSystemApi(requester, connectionOwner) {
1626
1660
  throw new AppHostError("invalid_request");
1627
1661
  return requester.request(method, params);
1628
1662
  }
1629
- return {
1663
+ const system = {
1630
1664
  projects: (input) => send("system.projects", input),
1631
1665
  workspace: (async (input) => {
1632
1666
  const result = await send("system.workspace", input);
@@ -1659,11 +1693,15 @@ function createAppSystemApi(requester, connectionOwner) {
1659
1693
  getPresentationPreferences: () => send("system.getPresentationPreferences", {}),
1660
1694
  setTheme: (theme) => send("system.setTheme", { theme }),
1661
1695
  setWindowMaterial: (preference) => send("system.setWindowMaterial", { preference }),
1662
- copyText: (text2) => send("system.copyText", { text: text2 }),
1696
+ copyText: (text3) => send("system.copyText", { text: text3 }),
1663
1697
  openExternal: (url2) => send("system.openExternal", { url: url2 }),
1664
1698
  navigationReady: () => send("system.navigationReady", {}),
1665
1699
  completeNavigation: (input) => send("system.completeNavigation", input)
1666
1700
  };
1701
+ Object.defineProperty(system, channelSettingsKey, {
1702
+ value: (input) => send("system.channelSettings", input)
1703
+ });
1704
+ return system;
1667
1705
  }
1668
1706
 
1669
1707
  // src/session-resources.ts
@@ -1682,6 +1720,89 @@ function validSessionResourceResult(_method, v) {
1682
1720
  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}`;
1683
1721
  }
1684
1722
 
1723
+ // src/workbench-computer.ts
1724
+ var WORKBENCH_COMPUTER_FEATURE = "workbench-computer-v1";
1725
+ var workbenchComputerKey = /* @__PURE__ */ Symbol.for("nomi.workbench-computer");
1726
+ function workbenchComputer(host) {
1727
+ return host[workbenchComputerKey];
1728
+ }
1729
+ var WORKBENCH_COMPUTER_METHODS = [
1730
+ "workbench.computer.availability",
1731
+ "workbench.computer.setConversation",
1732
+ "workbench.computer.preparePrompt",
1733
+ "workbench.computer.getActivity",
1734
+ "workbench.computer.reply",
1735
+ "workbench.computer.control",
1736
+ "workbench.computer.shareWindow",
1737
+ "workbench.computer.stopLocal"
1738
+ ];
1739
+ var availability = ["unsupported", "disabled", "missing_driver", "ready"];
1740
+ var actions = ["pause", "resume", "disable_capture", "enable_capture"];
1741
+ function record(value) {
1742
+ return !!value && typeof value === "object" && !Array.isArray(value);
1743
+ }
1744
+ function text2(value, limit = 256) {
1745
+ return typeof value === "string" && value.length > 0 && value.length <= limit;
1746
+ }
1747
+ function keys(value, ...names) {
1748
+ return Object.keys(value).length === names.length && names.every((name2) => Object.hasOwn(value, name2));
1749
+ }
1750
+ function isWorkbenchComputerMethod(method) {
1751
+ return WORKBENCH_COMPUTER_METHODS.includes(method);
1752
+ }
1753
+ function validWorkbenchComputerInput(method, value) {
1754
+ if (!record(value)) return false;
1755
+ switch (method) {
1756
+ case "workbench.computer.availability":
1757
+ case "workbench.computer.shareWindow":
1758
+ return keys(value);
1759
+ case "workbench.computer.setConversation":
1760
+ return keys(value, "sessionId") && (value.sessionId === null || text2(value.sessionId));
1761
+ case "workbench.computer.preparePrompt":
1762
+ return keys(value, "sessionId", "inputId") && text2(value.sessionId) && text2(value.inputId);
1763
+ case "workbench.computer.stopLocal":
1764
+ return keys(value, "sessionId", "runId") && text2(value.sessionId) && text2(value.runId);
1765
+ case "workbench.computer.getActivity":
1766
+ return keys(value, "sessionId") && text2(value.sessionId);
1767
+ case "workbench.computer.reply":
1768
+ return keys(value, "id", "choice") && text2(value.id) && (value.choice === null || text2(value.choice));
1769
+ case "workbench.computer.control":
1770
+ return keys(value, "sessionId", "runId", "action") && text2(value.sessionId) && text2(value.runId) && text2(value.action) && actions.includes(value.action);
1771
+ }
1772
+ }
1773
+ function validActivity(value) {
1774
+ 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");
1775
+ }
1776
+ function validWorkbenchComputerResult(method, value) {
1777
+ switch (method) {
1778
+ case "workbench.computer.availability":
1779
+ return text2(value) && availability.includes(value);
1780
+ case "workbench.computer.setConversation":
1781
+ case "workbench.computer.stopLocal":
1782
+ return value === void 0;
1783
+ case "workbench.computer.preparePrompt":
1784
+ case "workbench.computer.reply":
1785
+ case "workbench.computer.control":
1786
+ return typeof value === "boolean";
1787
+ case "workbench.computer.getActivity":
1788
+ return value === null || validActivity(value);
1789
+ case "workbench.computer.shareWindow":
1790
+ return value === null || record(value) && keys(value, "bytes") && value.bytes instanceof Uint8Array && value.bytes.byteLength > 0 && value.bytes.byteLength <= 8 * 1024 * 1024;
1791
+ }
1792
+ }
1793
+ function validWorkbenchComputerEvent(value) {
1794
+ if (!record(value)) return false;
1795
+ if (value.type === "workbench-computer-activity") {
1796
+ const update = value.update;
1797
+ return record(update) && text2(update.sessionId) && (update.activity === null || validActivity(update.activity) && record(update.activity) && update.activity.sessionId === update.sessionId);
1798
+ }
1799
+ const event = value.interaction;
1800
+ if (value.type !== "workbench-computer-prompt" || !record(event)) return false;
1801
+ if (event.type === "dismissed") return text2(event.id);
1802
+ const prompt = event.prompt;
1803
+ 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))));
1804
+ }
1805
+
1685
1806
  // src/lifecycle.ts
1686
1807
  function isAppLifecycleFrame(value) {
1687
1808
  if (!value || typeof value !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(value))) return false;
@@ -1735,7 +1856,8 @@ var APP_HOST_METHODS = [
1735
1856
  ...ATTACHMENTS_METHODS,
1736
1857
  ...AUXILIARY_METHODS,
1737
1858
  ...SYSTEM_METHODS,
1738
- ...WINDOW_METHODS
1859
+ ...WINDOW_METHODS,
1860
+ ...WORKBENCH_COMPUTER_METHODS
1739
1861
  ];
1740
1862
  export {
1741
1863
  APP_HOST_ERROR_RETRY,
@@ -1770,6 +1892,8 @@ export {
1770
1892
  SYSTEM_SETTINGS_SECTIONS,
1771
1893
  SYSTEM_SHORTCUT_IDS,
1772
1894
  WINDOW_METHODS,
1895
+ WORKBENCH_COMPUTER_FEATURE,
1896
+ WORKBENCH_COMPUTER_METHODS,
1773
1897
  appHostErrorMessage,
1774
1898
  canonicalDesktopRequest,
1775
1899
  createAppAttachmentsApi,
@@ -1790,6 +1914,7 @@ export {
1790
1914
  isSafeErrorDetails,
1791
1915
  isSystemMethod,
1792
1916
  isWindowMethod,
1917
+ isWorkbenchComputerMethod,
1793
1918
  matchAgentApiRoute,
1794
1919
  normalizeAgentApiPath,
1795
1920
  pageFetchPath,
@@ -1828,8 +1953,14 @@ export {
1828
1953
  validWindowEvent,
1829
1954
  validWindowInput,
1830
1955
  validWindowResult,
1956
+ validWorkbenchComputerEvent,
1957
+ validWorkbenchComputerInput,
1958
+ validWorkbenchComputerResult,
1831
1959
  validWorkspaceInput,
1832
1960
  validWorkspaceOperation,
1833
- validWorkspaceResult
1961
+ validWorkspaceResult,
1962
+ workbenchChannelSettings,
1963
+ workbenchComputer,
1964
+ workbenchComputerKey
1834
1965
  };
1835
1966
  //# sourceMappingURL=protocol.js.map