@bobannomi/app-host 0.2.0 → 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/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;
@@ -570,7 +571,7 @@ function validAppCommandSnapshot(value) {
570
571
  (m) => m.items.some((i) => "command" in i && !ids.has(i.command))
571
572
  ) || Object.values(v.toolbar ?? {}).some((x) => !ids.has(x)))
572
573
  return false;
573
- const keys = /* @__PURE__ */ new Set();
574
+ const keys2 = /* @__PURE__ */ new Set();
574
575
  for (const command of v.commands)
575
576
  for (const key of command.shortcuts ?? []) {
576
577
  const mods = new Set(key.modifiers);
@@ -579,8 +580,8 @@ function validAppCommandSnapshot(value) {
579
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")
580
581
  return false;
581
582
  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);
583
+ if (keys2.has(signature)) return false;
584
+ keys2.add(signature);
584
585
  }
585
586
  return true;
586
587
  }
@@ -859,22 +860,22 @@ function validConversationPreparationResult(method, result) {
859
860
  // src/client-connections.ts
860
861
  var connections = /* @__PURE__ */ new WeakMap();
861
862
  function createClientConnection(wire, streams) {
862
- const record = { owner: streams, id: wire.connectionId, closed: false };
863
+ const record2 = { owner: streams, id: wire.connectionId, closed: false };
863
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() {
864
- return record.closed || streams.isClosed?.(wire.connectionId) === true;
865
+ return record2.closed || streams.isClosed?.(wire.connectionId) === true;
865
866
  }, close() {
866
- if (!record.closed) {
867
- record.closed = true;
867
+ if (!record2.closed) {
868
+ record2.closed = true;
868
869
  streams.close(wire.connectionId);
869
870
  }
870
871
  } };
871
- connections.set(connection, record);
872
+ connections.set(connection, record2);
872
873
  return connection;
873
874
  }
874
875
  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;
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;
878
879
  }
879
880
 
880
881
  // src/desktop.ts
@@ -1333,8 +1334,8 @@ var limits = { contextWindow: count, maxOutputTokens: count };
1333
1334
  function headerValues(check) {
1334
1335
  return (value) => {
1335
1336
  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);
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);
1338
1339
  };
1339
1340
  }
1340
1341
  var headers = headerValues(text(8192, true));
@@ -1371,8 +1372,8 @@ function validProviderDefaultsRequest(value) {
1371
1372
  var verifiedProvider = object({ model: modelId, checkedAt: count });
1372
1373
  var verified = (value) => {
1373
1374
  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);
1375
+ const keys2 = Object.keys(value);
1376
+ return keys2.length <= 4096 && keys2.every(provider) && object(Object.fromEntries(keys2.map((key) => [key, verifiedProvider])))(value);
1376
1377
  };
1377
1378
  var defaultsModel = object({ id: modelId, label: text(1024), provider: text(1024), providerName: provider }, {
1378
1379
  reasoningEfforts: array(text(256, true)),
@@ -1408,7 +1409,6 @@ var SYSTEM_SETTINGS_SECTIONS = [
1408
1409
  "permissions",
1409
1410
  "personalization",
1410
1411
  "billing",
1411
- "connections",
1412
1412
  "terminal",
1413
1413
  "git",
1414
1414
  "runtime",
@@ -1435,11 +1435,33 @@ var SYSTEM_SHORTCUT_IDS = [
1435
1435
  "resetZoom",
1436
1436
  "showShortcuts"
1437
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
+ }
1438
1459
  var SYSTEM_METHODS = [
1439
1460
  "system.projects",
1440
1461
  "system.workspace",
1441
1462
  "system.extensions",
1442
1463
  "system.modelProviders",
1464
+ "system.channelSettings",
1443
1465
  "system.providerDefaults",
1444
1466
  "system.open",
1445
1467
  "system.getPresentationPreferences",
@@ -1541,6 +1563,15 @@ function validSystemInput(method, value) {
1541
1563
  return validExtensionRequest(value);
1542
1564
  case "system.modelProviders":
1543
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
+ }
1544
1575
  case "system.providerDefaults":
1545
1576
  return validProviderDefaultsRequest(value);
1546
1577
  case "system.setTheme":
@@ -1592,6 +1623,8 @@ function validSystemResult(method, value) {
1592
1623
  return validExtensionResult(value);
1593
1624
  case "system.modelProviders":
1594
1625
  return validModelProviderConnections(value);
1626
+ case "system.channelSettings":
1627
+ return object({ value: channelSettingsValue })(value) || object({ error: enumeration("invalid_configuration", "conflict") })(value);
1595
1628
  case "system.providerDefaults":
1596
1629
  return validProviderDefaultsSnapshot(value) || validProviderConnectionTestResult(value);
1597
1630
  case "system.open":
@@ -1626,7 +1659,7 @@ function createAppSystemApi(requester, connectionOwner) {
1626
1659
  throw new AppHostError("invalid_request");
1627
1660
  return requester.request(method, params);
1628
1661
  }
1629
- return {
1662
+ const system = {
1630
1663
  projects: (input) => send("system.projects", input),
1631
1664
  workspace: (async (input) => {
1632
1665
  const result = await send("system.workspace", input);
@@ -1659,11 +1692,15 @@ function createAppSystemApi(requester, connectionOwner) {
1659
1692
  getPresentationPreferences: () => send("system.getPresentationPreferences", {}),
1660
1693
  setTheme: (theme) => send("system.setTheme", { theme }),
1661
1694
  setWindowMaterial: (preference) => send("system.setWindowMaterial", { preference }),
1662
- copyText: (text2) => send("system.copyText", { text: text2 }),
1695
+ copyText: (text3) => send("system.copyText", { text: text3 }),
1663
1696
  openExternal: (url2) => send("system.openExternal", { url: url2 }),
1664
1697
  navigationReady: () => send("system.navigationReady", {}),
1665
1698
  completeNavigation: (input) => send("system.completeNavigation", input)
1666
1699
  };
1700
+ Object.defineProperty(system, channelSettingsKey, {
1701
+ value: (input) => send("system.channelSettings", input)
1702
+ });
1703
+ return system;
1667
1704
  }
1668
1705
 
1669
1706
  // src/session-resources.ts
@@ -1682,6 +1719,89 @@ function validSessionResourceResult(_method, v) {
1682
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}`;
1683
1720
  }
1684
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
+
1685
1805
  // src/lifecycle.ts
1686
1806
  function isAppLifecycleFrame(value) {
1687
1807
  if (!value || typeof value !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(value))) return false;
@@ -1735,7 +1855,8 @@ var APP_HOST_METHODS = [
1735
1855
  ...ATTACHMENTS_METHODS,
1736
1856
  ...AUXILIARY_METHODS,
1737
1857
  ...SYSTEM_METHODS,
1738
- ...WINDOW_METHODS
1858
+ ...WINDOW_METHODS,
1859
+ ...WORKBENCH_COMPUTER_METHODS
1739
1860
  ];
1740
1861
  export {
1741
1862
  APP_HOST_ERROR_RETRY,
@@ -1770,6 +1891,8 @@ export {
1770
1891
  SYSTEM_SETTINGS_SECTIONS,
1771
1892
  SYSTEM_SHORTCUT_IDS,
1772
1893
  WINDOW_METHODS,
1894
+ WORKBENCH_COMPUTER_FEATURE,
1895
+ WORKBENCH_COMPUTER_METHODS,
1773
1896
  appHostErrorMessage,
1774
1897
  canonicalDesktopRequest,
1775
1898
  createAppAttachmentsApi,
@@ -1790,6 +1913,7 @@ export {
1790
1913
  isSafeErrorDetails,
1791
1914
  isSystemMethod,
1792
1915
  isWindowMethod,
1916
+ isWorkbenchComputerMethod,
1793
1917
  matchAgentApiRoute,
1794
1918
  normalizeAgentApiPath,
1795
1919
  pageFetchPath,
@@ -1828,8 +1952,14 @@ export {
1828
1952
  validWindowEvent,
1829
1953
  validWindowInput,
1830
1954
  validWindowResult,
1955
+ validWorkbenchComputerEvent,
1956
+ validWorkbenchComputerInput,
1957
+ validWorkbenchComputerResult,
1831
1958
  validWorkspaceInput,
1832
1959
  validWorkspaceOperation,
1833
- validWorkspaceResult
1960
+ validWorkspaceResult,
1961
+ workbenchChannelSettings,
1962
+ workbenchComputer,
1963
+ workbenchComputerKey
1834
1964
  };
1835
1965
  //# sourceMappingURL=protocol.js.map