@bobannomi/app-host 0.1.0 → 0.1.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
@@ -61,6 +61,18 @@ function appHostErrorMessage(code, details) {
61
61
  return "The desktop host could not reconnect services for this page.";
62
62
  case "host_access_check_failed":
63
63
  return "The desktop host could not verify access for this page.";
64
+ case "skill_marketplace_unavailable":
65
+ return "\u6682\u65F6\u65E0\u6CD5\u8BFB\u53D6\u5B98\u65B9\u6280\u80FD\u5E02\u573A\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002";
66
+ case "skill_marketplace_install_failed":
67
+ return "\u6280\u80FD\u5B89\u88C5\u6216\u66F4\u65B0\u672A\u5B8C\u6210\uFF0C\u8BF7\u5237\u65B0\u5DF2\u5B89\u88C5\u6280\u80FD\u540E\u91CD\u8BD5\u3002";
68
+ case "skill_marketplace_busy":
69
+ return "\u540E\u53F0\u6B63\u5728\u8FD0\u884C\u4EFB\u52A1\u6216\u5904\u7406\u6280\u80FD\u53D8\u66F4\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002";
70
+ case "skill_marketplace_local_conflict":
71
+ return "\u6240\u9009\u8303\u56F4\u5185\u5DF2\u6709\u540C\u540D\u6280\u80FD\u6216\u672C\u5730\u6539\u52A8\uFF0C\u8BF7\u68C0\u67E5\u5DF2\u5B89\u88C5\u7684\u6280\u80FD\u3002";
72
+ case "skill_marketplace_selection_changed":
73
+ return "\u6240\u9009\u6280\u80FD\u6216\u7248\u672C\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u6280\u80FD\u5E02\u573A\u540E\u91CD\u8BD5\u3002";
74
+ case "skill_marketplace_project_unavailable":
75
+ return "\u5F53\u524D\u9879\u76EE\u65E0\u6CD5\u5B89\u88C5\u6280\u80FD\uFF0C\u8BF7\u9009\u62E9\u5DF2\u767B\u8BB0\u7684\u9879\u76EE\u3002";
64
76
  default:
65
77
  return "The desktop host could not complete the operation.";
66
78
  }
@@ -290,7 +302,31 @@ function validServiceResult(method, value) {
290
302
  }
291
303
 
292
304
  // ../domain-contracts/src/app-host/fetch.ts
293
- var APP_HOST_FEATURES = ["fetch-v2", "fetch-inline-body-v1", "fetch-target-close-v1", "service-v1", "extended-errors-v1", "workspace-v1", "session-resources-v1", "session-controls-v1", "conversation-creation-session-v1", "trusted-desktop-v1", "attachments-v1", "auxiliary-sessions-v1", "system-ui-v1", "lifecycle-v1", "commands-v1", "resource-catalog-v1", "file-content-v1", "window-chrome-v1", "embedded-browser-v1", "browser-binding-invalidation-v1", "browser-capture-preview-v1"];
305
+ var APP_HOST_FEATURES = [
306
+ "fetch-v1",
307
+ "fetch-inline-body-v1",
308
+ "fetch-target-close-v1",
309
+ "service-v1",
310
+ "extended-errors-v1",
311
+ "workspace-v1",
312
+ "session-resources-v1",
313
+ "session-controls-v1",
314
+ "conversation-creation-session-v1",
315
+ "trusted-desktop-v1",
316
+ "attachments-v1",
317
+ "auxiliary-sessions-v1",
318
+ "system-ui-v1",
319
+ "lifecycle-v1",
320
+ "commands-v1",
321
+ "resource-catalog-v1",
322
+ "file-content-v1",
323
+ "window-chrome-v1",
324
+ "window-updates-v1",
325
+ "window-update-check-v1",
326
+ "embedded-browser-v1",
327
+ "browser-binding-invalidation-v1",
328
+ "browser-capture-preview-v1"
329
+ ];
294
330
  var FETCH_CHUNK_BYTES = 64 * 1024;
295
331
  var FETCH_INLINE_BODY_BYTES = 8 * 1024;
296
332
  var FETCH_WINDOW_CHUNKS = 4;
@@ -303,7 +339,10 @@ function isPageFetchFrame(value) {
303
339
  const visit = (entry, depth, binary = false) => {
304
340
  if (depth > 10) return false;
305
341
  if (entry instanceof Uint8Array) {
306
- if (!binary || Object.getPrototypeOf(entry) !== Uint8Array.prototype || ["buffer", "byteLength", "byteOffset", "length"].some((key) => Object.hasOwn(entry, key))) return false;
342
+ if (!binary || Object.getPrototypeOf(entry) !== Uint8Array.prototype || ["buffer", "byteLength", "byteOffset", "length"].some(
343
+ (key) => Object.hasOwn(entry, key)
344
+ ))
345
+ return false;
307
346
  const buffer = entry.buffer;
308
347
  return buffer instanceof ArrayBuffer && !Object.hasOwn(buffer, "byteLength") && buffer.byteLength <= FETCH_CHUNK_BYTES && entry.byteLength > 0 && entry.byteLength <= FETCH_CHUNK_BYTES;
309
348
  }
@@ -317,9 +356,11 @@ function isPageFetchFrame(value) {
317
356
  }
318
357
  if (!entry || typeof entry !== "object") return false;
319
358
  const array2 = Array.isArray(entry);
320
- if (array2 ? Object.getPrototypeOf(entry) !== Array.prototype : ![Object.prototype, null].includes(Object.getPrototypeOf(entry))) return false;
359
+ if (array2 ? Object.getPrototypeOf(entry) !== Array.prototype : ![Object.prototype, null].includes(Object.getPrototypeOf(entry)))
360
+ return false;
321
361
  const keys = Reflect.ownKeys(entry);
322
- if (keys.length > FETCH_METADATA_BYTES || array2 && keys.length !== entry.length + 1) return false;
362
+ if (keys.length > FETCH_METADATA_BYTES || array2 && keys.length !== entry.length + 1)
363
+ return false;
323
364
  return keys.every((key) => {
324
365
  if (array2 && key === "length") return true;
325
366
  const d = Object.getOwnPropertyDescriptor(entry, key);
@@ -327,7 +368,8 @@ function isPageFetchFrame(value) {
327
368
  return typeof key === "string" && d.enumerable && Object.hasOwn(d, "value") && (!array2 || /^(0|[1-9][0-9]*)$/.test(key) && Number(key) < entry.length) && visit(d.value, depth + 1, depth === 0 && key === "bytes") && size <= FETCH_METADATA_BYTES;
328
369
  });
329
370
  };
330
- if (!visit(value, 0) || !value || typeof value !== "object" || Array.isArray(value)) return false;
371
+ if (!visit(value, 0) || !value || typeof value !== "object" || Array.isArray(value))
372
+ return false;
331
373
  const v = value;
332
374
  if (v.protocol !== 2 || typeof v.type !== "string") return false;
333
375
  const fields4 = {
@@ -343,19 +385,28 @@ function isPageFetchFrame(value) {
343
385
  };
344
386
  const required = fields4[v.type];
345
387
  const inline = v.type === "fetch-open" && Object.hasOwn(v, "inlineBody");
346
- if (!required || Object.keys(v).length !== required.length + 2 + Number(inline) || !required.every((k) => Object.hasOwn(v, k))) return false;
347
- if (inline && (v.hasBody !== true || typeof v.inlineBody !== "string" || new TextEncoder().encode(v.inlineBody).byteLength > FETCH_INLINE_BODY_BYTES)) return false;
388
+ if (!required || Object.keys(v).length !== required.length + 2 + Number(inline) || !required.every((k) => Object.hasOwn(v, k)))
389
+ return false;
390
+ if (inline && (v.hasBody !== true || typeof v.inlineBody !== "string" || new TextEncoder().encode(v.inlineBody).byteLength > FETCH_INLINE_BODY_BYTES))
391
+ return false;
348
392
  const id3 = (x) => typeof x === "string" && x.length > 0 && x.length <= 128;
349
393
  if (v.type === "fetch-close") return id3(v.connectionId);
350
394
  if (!id3(v.id)) return false;
351
- if (v.type === "fetch-consumed") return v.direction === "download" && Number.isSafeInteger(v.sequence) && v.sequence >= 0;
352
- if (["fetch-chunk", "fetch-credit", "fetch-end"].includes(v.type) && (!["upload", "download"].includes(v.direction) || !Number.isSafeInteger(v.sequence) || v.sequence < 0)) return false;
353
- if (v.type === "fetch-credit") return Number.isInteger(v.chunks) && v.chunks > 0 && v.chunks <= FETCH_WINDOW_CHUNKS && v.bytes === v.chunks * FETCH_CHUNK_BYTES;
395
+ if (v.type === "fetch-consumed")
396
+ return v.direction === "download" && Number.isSafeInteger(v.sequence) && v.sequence >= 0;
397
+ if (["fetch-chunk", "fetch-credit", "fetch-end"].includes(v.type) && (!["upload", "download"].includes(v.direction) || !Number.isSafeInteger(v.sequence) || v.sequence < 0))
398
+ return false;
399
+ if (v.type === "fetch-credit")
400
+ return Number.isInteger(v.chunks) && v.chunks > 0 && v.chunks <= FETCH_WINDOW_CHUNKS && v.bytes === v.chunks * FETCH_CHUNK_BYTES;
354
401
  if (v.type === "fetch-chunk") return v.bytes instanceof Uint8Array;
355
402
  if (v.type === "fetch-error") return isAppHostErrorInfo(v.error);
356
403
  if (v.type === "fetch-open" || v.type === "fetch-headers") {
357
- if (!Array.isArray(v.headers) || !v.headers.every((h) => Array.isArray(h) && h.length === 2 && h.every((x) => typeof x === "string")) || typeof v.hasBody !== "boolean") return false;
358
- if (v.type === "fetch-open") return id3(v.connectionId) && typeof v.url === "string" && typeof v.method === "string" && /^[A-Za-z0-9!#$%&'*+.^_`|~-]+$/.test(v.method);
404
+ if (!Array.isArray(v.headers) || !v.headers.every(
405
+ (h) => Array.isArray(h) && h.length === 2 && h.every((x) => typeof x === "string")
406
+ ) || typeof v.hasBody !== "boolean")
407
+ return false;
408
+ if (v.type === "fetch-open")
409
+ return id3(v.connectionId) && typeof v.url === "string" && typeof v.method === "string" && /^[A-Za-z0-9!#$%&'*+.^_`|~-]+$/.test(v.method);
359
410
  return Number.isInteger(v.status) && v.status >= 200 && v.status <= 599 && typeof v.statusText === "string";
360
411
  }
361
412
  return true;
@@ -363,9 +414,11 @@ function isPageFetchFrame(value) {
363
414
  function pageFetchPath(baseUrl, input) {
364
415
  if (/[\\\s#]/.test(input)) throw new TypeError("Invalid fetch URL");
365
416
  const rawPath = input.replace(/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^/]+/, "").split("?")[0];
366
- if (rawPath.includes("//") || /%(?:2e|2f|5c|25)/i.test(rawPath) || rawPath.split("/").some((p) => p === "." || p === "..") || /[\u0000-\u001f\u007f]/.test(decodeURIComponent(rawPath))) throw new TypeError("Ambiguous fetch path");
417
+ if (rawPath.includes("//") || /%(?:2e|2f|5c|25)/i.test(rawPath) || rawPath.split("/").some((p) => p === "." || p === "..") || /[\u0000-\u001f\u007f]/.test(decodeURIComponent(rawPath)))
418
+ throw new TypeError("Ambiguous fetch path");
367
419
  const base = new URL(baseUrl), url = new URL(input);
368
- if (base.protocol !== "https:" || base.hostname !== "app-host.invalid" || base.username || base.password || base.search || base.hash || url.origin !== base.origin || url.username || url.password || url.hash || url.pathname !== base.pathname && !url.pathname.startsWith(base.pathname + "/")) throw new TypeError("Fetch target mismatch");
420
+ if (base.protocol !== "https:" || base.hostname !== "app-host.invalid" || base.username || base.password || base.search || base.hash || url.origin !== base.origin || url.username || url.password || url.hash || url.pathname !== base.pathname && !url.pathname.startsWith(base.pathname + "/"))
421
+ throw new TypeError("Fetch target mismatch");
369
422
  return (url.pathname.slice(base.pathname.length) || "/") + url.search;
370
423
  }
371
424
 
@@ -462,7 +515,7 @@ function isServiceHostFrame(v) {
462
515
 
463
516
  // ../domain-contracts/src/app-host/agent-api-policy.ts
464
517
  var routes = [
465
- { method: "GET", pattern: /^\/schedules\/(status|tasks(?:\/[^/]+)?|runs)$/, id: "schedules.read" },
518
+ { method: "GET", pattern: /^\/schedules\/(status|tasks(?:\/[^/]+(?:\/run|\/runs\/[^/]+)?)?|runs)$/, id: "schedules.read" },
466
519
  { method: "POST", pattern: /^\/schedules\/tasks(?:\/[^/]+\/run)?$/, id: "schedules.create" },
467
520
  { method: "PATCH", pattern: /^\/schedules\/(tasks\/[^/]+|runs\/[^/]+\/read)$/, id: "schedules.update" },
468
521
  { method: "DELETE", pattern: /^\/schedules\/tasks\/[^/]+$/, id: "schedules.delete" },
@@ -871,28 +924,56 @@ function createAppCommandsApi(rpc) {
871
924
  }
872
925
 
873
926
  // src/window.ts
874
- var WINDOW_METHODS = ["window.getState", "window.minimize", "window.toggleMaximize", "window.requestClose", "window.openHost", "window.reportStartup"];
927
+ var WINDOW_METHODS = [
928
+ "window.getState",
929
+ "window.checkForUpdates",
930
+ "window.minimize",
931
+ "window.toggleMaximize",
932
+ "window.requestClose",
933
+ "window.openHost",
934
+ "window.reportStartup"
935
+ ];
875
936
  var finite = (value) => typeof value === "number" && Number.isFinite(value);
876
937
  var material = object({
877
938
  preference: enumeration("glass", "opaque"),
878
939
  active: enumeration("glass", "opaque"),
879
940
  shell: enumeration("solid", "translucent", "transparent"),
880
- unavailableReason: nullable(enumeration("unsupported-platform", "unsupported-system", "reduced-transparency", "material-error"))
941
+ unavailableReason: nullable(
942
+ enumeration(
943
+ "unsupported-platform",
944
+ "unsupported-system",
945
+ "reduced-transparency",
946
+ "material-error"
947
+ )
948
+ )
881
949
  });
882
- var validAppWindowState = (value) => object({
883
- platform: enumeration("win32", "darwin", "linux"),
884
- maximized: bool,
885
- titleBar: enumeration("host", "custom", "native"),
886
- trafficLightInset: (value2) => finite(value2) && value2 >= 0,
887
- material
950
+ var validUpdateState = (value) => object({ status: enumeration("idle", "checking", "error") })(value) || object({
951
+ status: enumeration("available", "downloaded"),
952
+ version: text(128)
953
+ })(value) || object({
954
+ status: enumeration("downloading"),
955
+ version: text(128),
956
+ percent: (value2) => finite(value2) && value2 >= 0 && value2 <= 100
888
957
  })(value);
958
+ var validAppWindowState = (value) => object(
959
+ {
960
+ platform: enumeration("win32", "darwin", "linux"),
961
+ maximized: bool,
962
+ titleBar: enumeration("host", "custom", "native"),
963
+ trafficLightInset: (value2) => finite(value2) && value2 >= 0,
964
+ material
965
+ },
966
+ { update: validUpdateState }
967
+ )(value);
889
968
  function isWindowMethod(value) {
890
969
  return WINDOW_METHODS.includes(value);
891
970
  }
892
971
  function validWindowInput(method, value) {
893
972
  switch (method) {
894
973
  case "window.openHost":
895
- return object({ page: enumeration("manage", "settings", "about", "recovery") })(value);
974
+ return object({
975
+ page: enumeration("manage", "settings", "about", "recovery")
976
+ })(value);
896
977
  case "window.reportStartup":
897
978
  return object({ status: enumeration("ready") })(value) || object({ status: enumeration("failed"), message: text(2048) })(value);
898
979
  default:
@@ -903,20 +984,29 @@ function validWindowResult(method, value) {
903
984
  switch (method) {
904
985
  case "window.getState":
905
986
  return validAppWindowState(value);
987
+ case "window.checkForUpdates":
988
+ return validUpdateState(value) || object({ status: enumeration("unsupported") })(value);
906
989
  default:
907
990
  return value === void 0;
908
991
  }
909
992
  }
910
993
  function validWindowEvent(value) {
911
- return object({ type: enumeration("window-state-changed"), state: validAppWindowState })(value);
994
+ return object({
995
+ type: enumeration("window-state-changed"),
996
+ state: validAppWindowState
997
+ })(value);
912
998
  }
913
999
  function createAppWindowApi(requester) {
914
1000
  async function send(method, params) {
915
1001
  requester.requireFeature();
916
- if (!validWindowInput(method, params)) throw new AppHostError("invalid_request");
1002
+ if (method === "window.checkForUpdates")
1003
+ requester.requireFeature("window-update-check-v1");
1004
+ if (!validWindowInput(method, params))
1005
+ throw new AppHostError("invalid_request");
917
1006
  return requester.request(method, params);
918
1007
  }
919
1008
  return {
1009
+ checkForUpdates: () => send("window.checkForUpdates", {}),
920
1010
  getState: () => send("window.getState", {}),
921
1011
  minimize: () => send("window.minimize", {}),
922
1012
  toggleMaximize: () => send("window.toggleMaximize", {}),
@@ -925,7 +1015,8 @@ function createAppWindowApi(requester) {
925
1015
  reportStartup: (input) => send("window.reportStartup", input),
926
1016
  onStateChanged: (listener) => {
927
1017
  requester.requireFeature();
928
- if (typeof listener !== "function") throw new AppHostError("invalid_request");
1018
+ if (typeof listener !== "function")
1019
+ throw new AppHostError("invalid_request");
929
1020
  return requester.onEvent((event) => {
930
1021
  if (event.type === "window-state-changed") listener(event.state);
931
1022
  });
@@ -1242,6 +1333,13 @@ var selection2 = object({ cwd: text(4096), selectionId: text(256) });
1242
1333
  var cancel = object({ selectionId: text(256) });
1243
1334
  var name = object({ name: text(256) });
1244
1335
  var login = object({ loginId: text(256) });
1336
+ var skillSelection = { id: text(64), version: text(32), sha256: digest };
1337
+ var personalSkillInstall = object({ ...skillSelection, scope: enumeration("personal") });
1338
+ var projectSkillInstall = object({
1339
+ ...skillSelection,
1340
+ scope: enumeration("project"),
1341
+ projectPath: (value) => typeof value === "string" && value.trim().length > 0 && text(4096)(value)
1342
+ });
1245
1343
  var EXTENSION_INPUTS = {
1246
1344
  context: empty,
1247
1345
  "plugins.loadIcon": object({ src: text(8192) }),
@@ -1266,6 +1364,8 @@ var EXTENSION_INPUTS = {
1266
1364
  "plugins.marketplaceOperation": object({ cwd: text(4096), operationId: text(256) }),
1267
1365
  "skills.snapshot": object({ projectPath: text(4096) }),
1268
1366
  "skills.remove": object({ id: text(4096), expectedContent: text(8 * 1024 * 1024, true), projectPath: text(4096) }),
1367
+ "skills.marketplaceCatalog": empty,
1368
+ "skills.marketplaceInstall": (value) => personalSkillInstall(value) || projectSkillInstall(value),
1269
1369
  "mcp.snapshot": empty,
1270
1370
  "mcp.exportConfig": empty,
1271
1371
  "mcp.getConfig": name,
@@ -1329,7 +1429,7 @@ var customProvider = object({
1329
1429
  models: array(object({ id: text(1024), displayName: text(1024) }, { imageInputSupport, ...limits }), 16384)
1330
1430
  }, { apiKey: text(8192), headers, secretHeaders });
1331
1431
  function validModelProviderRequest(value) {
1332
- return object({ action: enumeration("list", "refresh") })(value) || object({ action: enumeration("connect"), provider, apiKey: text(8192) }, { headers, secretHeaders })(value) || object({ action: enumeration("updateHeaders"), provider, headers }, { secretHeaders })(value) || object({ action: enumeration("createCustom"), value: customProvider })(value) || object({ action: enumeration("updateCustom"), provider, value: customProvider })(value) || object({ action: enumeration("disconnect", "removeCustom"), provider }, { disableDefault: bool })(value) || object({ action: enumeration("disconnect", "removeCustom"), provider, replacement: object({ provider, model: text(1024) }) })(value);
1432
+ return object({ action: enumeration("list", "refresh") })(value) || object({ action: enumeration("connect"), provider, apiKey: text(8192) }, { headers, secretHeaders })(value) || object({ action: enumeration("updateHeaders"), provider, headers }, { secretHeaders })(value) || object({ action: enumeration("createCustom", "syncAccount"), value: customProvider })(value) || object({ action: enumeration("updateCustom"), provider, value: customProvider })(value) || object({ action: enumeration("disconnect", "removeCustom"), provider }, { disableDefault: bool })(value) || object({ action: enumeration("disconnect", "removeCustom"), provider, replacement: object({ provider, model: text(1024) }) })(value);
1333
1433
  }
1334
1434
  var validModel = object({ id: text(1024), label: text(1024) }, { imageInputSupport, declaredLimits: object({}, limits) });
1335
1435
  var validConnection2 = object({
@@ -1427,7 +1527,6 @@ var SYSTEM_METHODS = [
1427
1527
  "system.setWindowMaterial",
1428
1528
  "system.copyText",
1429
1529
  "system.openExternal",
1430
- "system.markSessionRead",
1431
1530
  "system.navigationReady",
1432
1531
  "system.completeNavigation"
1433
1532
  ];
@@ -1547,12 +1646,6 @@ function validSystemInput(method, value) {
1547
1646
  page: enumeration("session-settings"),
1548
1647
  target: validSessionSettingsTarget
1549
1648
  })(value);
1550
- case "system.markSessionRead":
1551
- return object({
1552
- connectionId: text(256),
1553
- sessionId: text(256),
1554
- throughSeq: count
1555
- })(value);
1556
1649
  case "system.completeNavigation":
1557
1650
  return object({
1558
1651
  id: text(256),
@@ -1639,11 +1732,6 @@ function createAppSystemApi(requester, connectionOwner) {
1639
1732
  setWindowMaterial: (preference) => send("system.setWindowMaterial", { preference }),
1640
1733
  copyText: (text3) => send("system.copyText", { text: text3 }),
1641
1734
  openExternal: (url) => send("system.openExternal", { url }),
1642
- markSessionRead: ({ connection, sessionId, throughSeq }) => send("system.markSessionRead", {
1643
- connectionId: resolveClientConnection(connection, connectionOwner),
1644
- sessionId,
1645
- throughSeq
1646
- }),
1647
1735
  navigationReady: () => send("system.navigationReady", {}),
1648
1736
  completeNavigation: (input) => send("system.completeNavigation", input)
1649
1737
  };