@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/index.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
  }
@@ -253,7 +265,31 @@ function validServiceConnectionInput(value) {
253
265
  }
254
266
 
255
267
  // ../domain-contracts/src/app-host/fetch.ts
256
- 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"];
268
+ var APP_HOST_FEATURES = [
269
+ "fetch-v1",
270
+ "fetch-inline-body-v1",
271
+ "fetch-target-close-v1",
272
+ "service-v1",
273
+ "extended-errors-v1",
274
+ "workspace-v1",
275
+ "session-resources-v1",
276
+ "session-controls-v1",
277
+ "conversation-creation-session-v1",
278
+ "trusted-desktop-v1",
279
+ "attachments-v1",
280
+ "auxiliary-sessions-v1",
281
+ "system-ui-v1",
282
+ "lifecycle-v1",
283
+ "commands-v1",
284
+ "resource-catalog-v1",
285
+ "file-content-v1",
286
+ "window-chrome-v1",
287
+ "window-updates-v1",
288
+ "window-update-check-v1",
289
+ "embedded-browser-v1",
290
+ "browser-binding-invalidation-v1",
291
+ "browser-capture-preview-v1"
292
+ ];
257
293
  var FETCH_CHUNK_BYTES = 64 * 1024;
258
294
  var FETCH_INLINE_BODY_BYTES = 8 * 1024;
259
295
  var FETCH_WINDOW_CHUNKS = 4;
@@ -266,7 +302,10 @@ function isPageFetchFrame(value) {
266
302
  const visit = (entry, depth, binary = false) => {
267
303
  if (depth > 10) return false;
268
304
  if (entry instanceof Uint8Array) {
269
- if (!binary || Object.getPrototypeOf(entry) !== Uint8Array.prototype || ["buffer", "byteLength", "byteOffset", "length"].some((key) => Object.hasOwn(entry, key))) return false;
305
+ if (!binary || Object.getPrototypeOf(entry) !== Uint8Array.prototype || ["buffer", "byteLength", "byteOffset", "length"].some(
306
+ (key) => Object.hasOwn(entry, key)
307
+ ))
308
+ return false;
270
309
  const buffer = entry.buffer;
271
310
  return buffer instanceof ArrayBuffer && !Object.hasOwn(buffer, "byteLength") && buffer.byteLength <= FETCH_CHUNK_BYTES && entry.byteLength > 0 && entry.byteLength <= FETCH_CHUNK_BYTES;
272
311
  }
@@ -280,9 +319,11 @@ function isPageFetchFrame(value) {
280
319
  }
281
320
  if (!entry || typeof entry !== "object") return false;
282
321
  const array2 = Array.isArray(entry);
283
- if (array2 ? Object.getPrototypeOf(entry) !== Array.prototype : ![Object.prototype, null].includes(Object.getPrototypeOf(entry))) return false;
322
+ if (array2 ? Object.getPrototypeOf(entry) !== Array.prototype : ![Object.prototype, null].includes(Object.getPrototypeOf(entry)))
323
+ return false;
284
324
  const keys2 = Reflect.ownKeys(entry);
285
- if (keys2.length > FETCH_METADATA_BYTES || array2 && keys2.length !== entry.length + 1) return false;
325
+ if (keys2.length > FETCH_METADATA_BYTES || array2 && keys2.length !== entry.length + 1)
326
+ return false;
286
327
  return keys2.every((key) => {
287
328
  if (array2 && key === "length") return true;
288
329
  const d = Object.getOwnPropertyDescriptor(entry, key);
@@ -290,7 +331,8 @@ function isPageFetchFrame(value) {
290
331
  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;
291
332
  });
292
333
  };
293
- if (!visit(value, 0) || !value || typeof value !== "object" || Array.isArray(value)) return false;
334
+ if (!visit(value, 0) || !value || typeof value !== "object" || Array.isArray(value))
335
+ return false;
294
336
  const v = value;
295
337
  if (v.protocol !== 2 || typeof v.type !== "string") return false;
296
338
  const fields4 = {
@@ -306,19 +348,28 @@ function isPageFetchFrame(value) {
306
348
  };
307
349
  const required = fields4[v.type];
308
350
  const inline = v.type === "fetch-open" && Object.hasOwn(v, "inlineBody");
309
- if (!required || Object.keys(v).length !== required.length + 2 + Number(inline) || !required.every((k) => Object.hasOwn(v, k))) return false;
310
- if (inline && (v.hasBody !== true || typeof v.inlineBody !== "string" || new TextEncoder().encode(v.inlineBody).byteLength > FETCH_INLINE_BODY_BYTES)) return false;
351
+ if (!required || Object.keys(v).length !== required.length + 2 + Number(inline) || !required.every((k) => Object.hasOwn(v, k)))
352
+ return false;
353
+ if (inline && (v.hasBody !== true || typeof v.inlineBody !== "string" || new TextEncoder().encode(v.inlineBody).byteLength > FETCH_INLINE_BODY_BYTES))
354
+ return false;
311
355
  const id3 = (x) => typeof x === "string" && x.length > 0 && x.length <= 128;
312
356
  if (v.type === "fetch-close") return id3(v.connectionId);
313
357
  if (!id3(v.id)) return false;
314
- if (v.type === "fetch-consumed") return v.direction === "download" && Number.isSafeInteger(v.sequence) && v.sequence >= 0;
315
- if (["fetch-chunk", "fetch-credit", "fetch-end"].includes(v.type) && (!["upload", "download"].includes(v.direction) || !Number.isSafeInteger(v.sequence) || v.sequence < 0)) return false;
316
- 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;
358
+ if (v.type === "fetch-consumed")
359
+ return v.direction === "download" && Number.isSafeInteger(v.sequence) && v.sequence >= 0;
360
+ if (["fetch-chunk", "fetch-credit", "fetch-end"].includes(v.type) && (!["upload", "download"].includes(v.direction) || !Number.isSafeInteger(v.sequence) || v.sequence < 0))
361
+ return false;
362
+ if (v.type === "fetch-credit")
363
+ return Number.isInteger(v.chunks) && v.chunks > 0 && v.chunks <= FETCH_WINDOW_CHUNKS && v.bytes === v.chunks * FETCH_CHUNK_BYTES;
317
364
  if (v.type === "fetch-chunk") return v.bytes instanceof Uint8Array;
318
365
  if (v.type === "fetch-error") return isAppHostErrorInfo(v.error);
319
366
  if (v.type === "fetch-open" || v.type === "fetch-headers") {
320
- 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;
321
- if (v.type === "fetch-open") return id3(v.connectionId) && typeof v.url === "string" && typeof v.method === "string" && /^[A-Za-z0-9!#$%&'*+.^_`|~-]+$/.test(v.method);
367
+ if (!Array.isArray(v.headers) || !v.headers.every(
368
+ (h) => Array.isArray(h) && h.length === 2 && h.every((x) => typeof x === "string")
369
+ ) || typeof v.hasBody !== "boolean")
370
+ return false;
371
+ if (v.type === "fetch-open")
372
+ return id3(v.connectionId) && typeof v.url === "string" && typeof v.method === "string" && /^[A-Za-z0-9!#$%&'*+.^_`|~-]+$/.test(v.method);
322
373
  return Number.isInteger(v.status) && v.status >= 200 && v.status <= 599 && typeof v.statusText === "string";
323
374
  }
324
375
  return true;
@@ -326,9 +377,11 @@ function isPageFetchFrame(value) {
326
377
  function pageFetchPath(baseUrl, input) {
327
378
  if (/[\\\s#]/.test(input)) throw new TypeError("Invalid fetch URL");
328
379
  const rawPath = input.replace(/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^/]+/, "").split("?")[0];
329
- 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");
380
+ if (rawPath.includes("//") || /%(?:2e|2f|5c|25)/i.test(rawPath) || rawPath.split("/").some((p) => p === "." || p === "..") || /[\u0000-\u001f\u007f]/.test(decodeURIComponent(rawPath)))
381
+ throw new TypeError("Ambiguous fetch path");
330
382
  const base = new URL(baseUrl), url = new URL(input);
331
- 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");
383
+ 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 + "/"))
384
+ throw new TypeError("Fetch target mismatch");
332
385
  return (url.pathname.slice(base.pathname.length) || "/") + url.search;
333
386
  }
334
387
 
@@ -710,9 +763,7 @@ function createConversationPreparationApi(rpc) {
710
763
  const call = async (method, input) => {
711
764
  if (!validSessionControlInput(method, input)) throw new AppHostError("invalid_request");
712
765
  rpc.requireFeature();
713
- const result = await rpc.request(method, input);
714
- if (!validSessionControlResult(method, result)) throw new AppHostError("host_unavailable");
715
- return result;
766
+ return rpc.request(method, input);
716
767
  };
717
768
  return {
718
769
  createConversation: (input) => call("sessions.createConversation", input),
@@ -932,6 +983,13 @@ var selection = object({ cwd: text(4096), selectionId: text(256) });
932
983
  var cancel = object({ selectionId: text(256) });
933
984
  var name = object({ name: text(256) });
934
985
  var login = object({ loginId: text(256) });
986
+ var skillSelection = { id: text(64), version: text(32), sha256: digest };
987
+ var personalSkillInstall = object({ ...skillSelection, scope: enumeration("personal") });
988
+ var projectSkillInstall = object({
989
+ ...skillSelection,
990
+ scope: enumeration("project"),
991
+ projectPath: (value) => typeof value === "string" && value.trim().length > 0 && text(4096)(value)
992
+ });
935
993
  var EXTENSION_INPUTS = {
936
994
  context: empty,
937
995
  "plugins.loadIcon": object({ src: text(8192) }),
@@ -956,6 +1014,8 @@ var EXTENSION_INPUTS = {
956
1014
  "plugins.marketplaceOperation": object({ cwd: text(4096), operationId: text(256) }),
957
1015
  "skills.snapshot": object({ projectPath: text(4096) }),
958
1016
  "skills.remove": object({ id: text(4096), expectedContent: text(8 * 1024 * 1024, true), projectPath: text(4096) }),
1017
+ "skills.marketplaceCatalog": empty,
1018
+ "skills.marketplaceInstall": (value) => personalSkillInstall(value) || projectSkillInstall(value),
959
1019
  "mcp.snapshot": empty,
960
1020
  "mcp.exportConfig": empty,
961
1021
  "mcp.getConfig": name,
@@ -1019,7 +1079,7 @@ var customProvider = object({
1019
1079
  models: array(object({ id: text(1024), displayName: text(1024) }, { imageInputSupport, ...limits }), 16384)
1020
1080
  }, { apiKey: text(8192), headers, secretHeaders });
1021
1081
  function validModelProviderRequest(value) {
1022
- 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);
1082
+ 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);
1023
1083
  }
1024
1084
  var validModel = object({ id: text(1024), label: text(1024) }, { imageInputSupport, declaredLimits: object({}, limits) });
1025
1085
  var validConnection2 = object({
@@ -1117,7 +1177,6 @@ var SYSTEM_METHODS = [
1117
1177
  "system.setWindowMaterial",
1118
1178
  "system.copyText",
1119
1179
  "system.openExternal",
1120
- "system.markSessionRead",
1121
1180
  "system.navigationReady",
1122
1181
  "system.completeNavigation"
1123
1182
  ];
@@ -1237,12 +1296,6 @@ function validSystemInput(method, value) {
1237
1296
  page: enumeration("session-settings"),
1238
1297
  target: validSessionSettingsTarget
1239
1298
  })(value);
1240
- case "system.markSessionRead":
1241
- return object({
1242
- connectionId: text(256),
1243
- sessionId: text(256),
1244
- throughSeq: count
1245
- })(value);
1246
1299
  case "system.completeNavigation":
1247
1300
  return object({
1248
1301
  id: text(256),
@@ -1329,39 +1382,62 @@ function createAppSystemApi(requester, connectionOwner) {
1329
1382
  setWindowMaterial: (preference) => send("system.setWindowMaterial", { preference }),
1330
1383
  copyText: (text2) => send("system.copyText", { text: text2 }),
1331
1384
  openExternal: (url) => send("system.openExternal", { url }),
1332
- markSessionRead: ({ connection, sessionId, throughSeq }) => send("system.markSessionRead", {
1333
- connectionId: resolveClientConnection(connection, connectionOwner),
1334
- sessionId,
1335
- throughSeq
1336
- }),
1337
1385
  navigationReady: () => send("system.navigationReady", {}),
1338
1386
  completeNavigation: (input) => send("system.completeNavigation", input)
1339
1387
  };
1340
1388
  }
1341
1389
 
1342
1390
  // src/window.ts
1343
- var WINDOW_METHODS = ["window.getState", "window.minimize", "window.toggleMaximize", "window.requestClose", "window.openHost", "window.reportStartup"];
1391
+ var WINDOW_METHODS = [
1392
+ "window.getState",
1393
+ "window.checkForUpdates",
1394
+ "window.minimize",
1395
+ "window.toggleMaximize",
1396
+ "window.requestClose",
1397
+ "window.openHost",
1398
+ "window.reportStartup"
1399
+ ];
1344
1400
  var finite2 = (value) => typeof value === "number" && Number.isFinite(value);
1345
1401
  var material = object({
1346
1402
  preference: enumeration("glass", "opaque"),
1347
1403
  active: enumeration("glass", "opaque"),
1348
1404
  shell: enumeration("solid", "translucent", "transparent"),
1349
- unavailableReason: nullable(enumeration("unsupported-platform", "unsupported-system", "reduced-transparency", "material-error"))
1405
+ unavailableReason: nullable(
1406
+ enumeration(
1407
+ "unsupported-platform",
1408
+ "unsupported-system",
1409
+ "reduced-transparency",
1410
+ "material-error"
1411
+ )
1412
+ )
1350
1413
  });
1351
- var validAppWindowState = (value) => object({
1352
- platform: enumeration("win32", "darwin", "linux"),
1353
- maximized: bool,
1354
- titleBar: enumeration("host", "custom", "native"),
1355
- trafficLightInset: (value2) => finite2(value2) && value2 >= 0,
1356
- material
1414
+ var validUpdateState = (value) => object({ status: enumeration("idle", "checking", "error") })(value) || object({
1415
+ status: enumeration("available", "downloaded"),
1416
+ version: text(128)
1417
+ })(value) || object({
1418
+ status: enumeration("downloading"),
1419
+ version: text(128),
1420
+ percent: (value2) => finite2(value2) && value2 >= 0 && value2 <= 100
1357
1421
  })(value);
1422
+ var validAppWindowState = (value) => object(
1423
+ {
1424
+ platform: enumeration("win32", "darwin", "linux"),
1425
+ maximized: bool,
1426
+ titleBar: enumeration("host", "custom", "native"),
1427
+ trafficLightInset: (value2) => finite2(value2) && value2 >= 0,
1428
+ material
1429
+ },
1430
+ { update: validUpdateState }
1431
+ )(value);
1358
1432
  function isWindowMethod(value) {
1359
1433
  return WINDOW_METHODS.includes(value);
1360
1434
  }
1361
1435
  function validWindowInput(method, value) {
1362
1436
  switch (method) {
1363
1437
  case "window.openHost":
1364
- return object({ page: enumeration("manage", "settings", "about", "recovery") })(value);
1438
+ return object({
1439
+ page: enumeration("manage", "settings", "about", "recovery")
1440
+ })(value);
1365
1441
  case "window.reportStartup":
1366
1442
  return object({ status: enumeration("ready") })(value) || object({ status: enumeration("failed"), message: text(2048) })(value);
1367
1443
  default:
@@ -1372,20 +1448,29 @@ function validWindowResult(method, value) {
1372
1448
  switch (method) {
1373
1449
  case "window.getState":
1374
1450
  return validAppWindowState(value);
1451
+ case "window.checkForUpdates":
1452
+ return validUpdateState(value) || object({ status: enumeration("unsupported") })(value);
1375
1453
  default:
1376
1454
  return value === void 0;
1377
1455
  }
1378
1456
  }
1379
1457
  function validWindowEvent(value) {
1380
- return object({ type: enumeration("window-state-changed"), state: validAppWindowState })(value);
1458
+ return object({
1459
+ type: enumeration("window-state-changed"),
1460
+ state: validAppWindowState
1461
+ })(value);
1381
1462
  }
1382
1463
  function createAppWindowApi(requester) {
1383
1464
  async function send(method, params) {
1384
1465
  requester.requireFeature();
1385
- if (!validWindowInput(method, params)) throw new AppHostError("invalid_request");
1466
+ if (method === "window.checkForUpdates")
1467
+ requester.requireFeature("window-update-check-v1");
1468
+ if (!validWindowInput(method, params))
1469
+ throw new AppHostError("invalid_request");
1386
1470
  return requester.request(method, params);
1387
1471
  }
1388
1472
  return {
1473
+ checkForUpdates: () => send("window.checkForUpdates", {}),
1389
1474
  getState: () => send("window.getState", {}),
1390
1475
  minimize: () => send("window.minimize", {}),
1391
1476
  toggleMaximize: () => send("window.toggleMaximize", {}),
@@ -1394,7 +1479,8 @@ function createAppWindowApi(requester) {
1394
1479
  reportStartup: (input) => send("window.reportStartup", input),
1395
1480
  onStateChanged: (listener) => {
1396
1481
  requester.requireFeature();
1397
- if (typeof listener !== "function") throw new AppHostError("invalid_request");
1482
+ if (typeof listener !== "function")
1483
+ throw new AppHostError("invalid_request");
1398
1484
  return requester.onEvent((event) => {
1399
1485
  if (event.type === "window-state-changed") listener(event.state);
1400
1486
  });
@@ -1469,9 +1555,7 @@ function createAppWorkspaceApi(input) {
1469
1555
  async function call(method, params) {
1470
1556
  if (!validWorkspaceInput(method, params)) throw new AppHostError("invalid_request");
1471
1557
  input.requireFeature();
1472
- const value = await input.request(method, params);
1473
- if (!validWorkspaceResult(method, value)) throw new AppHostError("host_unavailable");
1474
- return value;
1558
+ return input.request(method, params);
1475
1559
  }
1476
1560
  return { select: (x) => call("workspace.select", x), getSelection: (x) => call("workspace.getSelection", x), get: (id3) => call("workspace.get", { workspaceId: id3 }), listFiles: (x) => call("workspace.listFiles", x), readText: (x) => call("workspace.readText", x) };
1477
1561
  }
@@ -1494,7 +1578,6 @@ function createAppSessionsApi(input, streams) {
1494
1578
  if (args.length !== 0) throw new AppHostError("invalid_request");
1495
1579
  input.requireFeature();
1496
1580
  const wire = await input.request("sessions.getConnection", {});
1497
- if (!validSessionResourceResult("sessions.getConnection", wire)) throw new AppHostError("host_unavailable");
1498
1581
  return createClientConnection(wire, streams);
1499
1582
  }
1500
1583
  };
@@ -1502,12 +1585,7 @@ function createAppSessionsApi(input, streams) {
1502
1585
 
1503
1586
  // src/service.ts
1504
1587
  function createAppServiceApi(rpc, streams) {
1505
- const request = async (method, params) => {
1506
- const value = await rpc.request(method, params);
1507
- if (!validServiceResult(method, value))
1508
- throw new AppHostError("host_unavailable");
1509
- return value;
1510
- };
1588
+ const request = async (method, params) => rpc.request(method, params);
1511
1589
  const work = (method, requestId) => {
1512
1590
  if (typeof requestId !== "string" || !HOST_REQUEST_ID.test(requestId))
1513
1591
  return Promise.reject(new AppHostError("invalid_request"));
@@ -1946,13 +2024,18 @@ function createPageFetchClient(options) {
1946
2024
  }
1947
2025
 
1948
2026
  // src/connection.ts
2027
+ var SKILL_MARKETPLACE_TIMEOUT_MS = 3e5;
1949
2028
  var failure = (code) => new AppHostError(code);
1950
2029
  var hostFailure = (reason, requestId) => {
1951
2030
  const details = { reason };
1952
- return new AppHostError("host_unavailable", appHostErrorMessage("host_unavailable", details), {
1953
- details,
1954
- ...requestId === void 0 ? {} : { requestId }
1955
- });
2031
+ return new AppHostError(
2032
+ "host_unavailable",
2033
+ appHostErrorMessage("host_unavailable", details),
2034
+ {
2035
+ details,
2036
+ ...requestId === void 0 ? {} : { requestId }
2037
+ }
2038
+ );
1956
2039
  };
1957
2040
  function record(value) {
1958
2041
  return value !== null && typeof value === "object" && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
@@ -1960,10 +2043,13 @@ function record(value) {
1960
2043
  function keys(value, required, optional = []) {
1961
2044
  if (!record(value)) return false;
1962
2045
  const own = Reflect.ownKeys(value);
1963
- return required.every((k) => Object.hasOwn(value, k)) && own.every((k) => typeof k === "string" && (required.includes(k) || optional.includes(k)) && Object.getOwnPropertyDescriptor(value, k)?.enumerable && Object.hasOwn(Object.getOwnPropertyDescriptor(value, k), "value"));
2046
+ return required.every((k) => Object.hasOwn(value, k)) && own.every(
2047
+ (k) => typeof k === "string" && (required.includes(k) || optional.includes(k)) && Object.getOwnPropertyDescriptor(value, k)?.enumerable && Object.hasOwn(Object.getOwnPropertyDescriptor(value, k), "value")
2048
+ );
1964
2049
  }
1965
2050
  function dataArray(value) {
1966
- if (!Array.isArray(value) || Object.getPrototypeOf(value) !== Array.prototype || Reflect.ownKeys(value).length !== value.length + 1) return false;
2051
+ if (!Array.isArray(value) || Object.getPrototypeOf(value) !== Array.prototype || Reflect.ownKeys(value).length !== value.length + 1)
2052
+ return false;
1967
2053
  for (let i = 0; i < value.length; i++) {
1968
2054
  const d = Object.getOwnPropertyDescriptor(value, String(i));
1969
2055
  if (!d?.enumerable || !Object.hasOwn(d, "value")) return false;
@@ -1974,10 +2060,13 @@ function nonempty(value) {
1974
2060
  return typeof value === "string" && value.length > 0;
1975
2061
  }
1976
2062
  function json3(value, ancestors = /* @__PURE__ */ new Set()) {
1977
- if (value === null || typeof value === "string" || typeof value === "boolean") return true;
2063
+ if (value === null || typeof value === "string" || typeof value === "boolean")
2064
+ return true;
1978
2065
  if (typeof value === "number") return Number.isFinite(value);
1979
- if (typeof value !== "object" || !record(value) && !Array.isArray(value) || ancestors.has(value)) return false;
1980
- if (Array.isArray(value) && (Object.getPrototypeOf(value) !== Array.prototype || Reflect.ownKeys(value).length !== value.length + 1)) return false;
2066
+ if (typeof value !== "object" || !record(value) && !Array.isArray(value) || ancestors.has(value))
2067
+ return false;
2068
+ if (Array.isArray(value) && (Object.getPrototypeOf(value) !== Array.prototype || Reflect.ownKeys(value).length !== value.length + 1))
2069
+ return false;
1981
2070
  ancestors.add(value);
1982
2071
  try {
1983
2072
  return Reflect.ownKeys(value).every((k) => {
@@ -1999,7 +2088,27 @@ function payloadSize(value) {
1999
2088
  return new TextEncoder().encode(JSON.stringify(value)).byteLength;
2000
2089
  }
2001
2090
  function validContext(value) {
2002
- return keys(value, ["appId", "appVersion", "installationId", "hostVersion", "hostApiVersion", "uiType", "theme", "locale", "capabilities", "storageQuotaBytes"]) && ["appId", "appVersion", "installationId", "hostVersion", "hostApiVersion", "locale"].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((c) => keys(c, ["granted"], ["reason"]) && typeof c.granted === "boolean" && (!Object.hasOwn(c, "reason") || typeof c.reason === "string"));
2091
+ return keys(value, [
2092
+ "appId",
2093
+ "appVersion",
2094
+ "installationId",
2095
+ "hostVersion",
2096
+ "hostApiVersion",
2097
+ "uiType",
2098
+ "theme",
2099
+ "locale",
2100
+ "capabilities",
2101
+ "storageQuotaBytes"
2102
+ ]) && [
2103
+ "appId",
2104
+ "appVersion",
2105
+ "installationId",
2106
+ "hostVersion",
2107
+ "hostApiVersion",
2108
+ "locale"
2109
+ ].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(
2110
+ (c) => keys(c, ["granted"], ["reason"]) && typeof c.granted === "boolean" && (!Object.hasOwn(c, "reason") || typeof c.reason === "string")
2111
+ );
2003
2112
  }
2004
2113
  function validEvent(value) {
2005
2114
  if (!record(value)) return false;
@@ -2024,19 +2133,27 @@ function validEvent(value) {
2024
2133
  }
2025
2134
  function validResult(method, value) {
2026
2135
  if (isCommandsMethod(method)) return validCommandReceipt(value);
2027
- if (isResourceCatalogMethod(method)) return validResourceCatalogResult(method, value);
2136
+ if (isResourceCatalogMethod(method))
2137
+ return validResourceCatalogResult(method, value);
2028
2138
  if (isSystemMethod(method)) return validSystemResult(method, value);
2029
2139
  if (isWindowMethod(method)) return validWindowResult(method, value);
2030
2140
  if (isDesktopMethod(method)) return validDesktopResult(method, value);
2031
- if (method === "attachments.getConnection") return validAttachmentsResult(value);
2141
+ if (method === "attachments.getConnection")
2142
+ return validAttachmentsResult(value);
2032
2143
  if (isAuxiliaryMethod(method)) return validAuxiliaryResult(method, value);
2033
- if (isConversationPreparationMethod(method)) return validConversationPreparationResult(method, value);
2034
- if (method.startsWith("sessions.")) return validSessionResourceResult(method, value);
2035
- if (method.startsWith("workspace.")) return validWorkspaceResult(method, value);
2036
- if (method.startsWith("service.")) return validServiceResult(method, value);
2144
+ if (isConversationPreparationMethod(method))
2145
+ return validConversationPreparationResult(method, value);
2146
+ if (method.startsWith("sessions."))
2147
+ return validSessionResourceResult(method, value);
2148
+ if (method.startsWith("workspace."))
2149
+ return validWorkspaceResult(method, value);
2150
+ if (method.startsWith("service."))
2151
+ return validServiceResult(method, value);
2037
2152
  switch (method) {
2038
2153
  case "negotiate":
2039
- 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((f) => APP_HOST_FEATURES.includes(f));
2154
+ 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(
2155
+ (f) => APP_HOST_FEATURES.includes(f)
2156
+ );
2040
2157
  case "connect":
2041
2158
  case "getContext":
2042
2159
  return validContext(value);
@@ -2057,7 +2174,10 @@ var DocumentConnection = class {
2057
2174
  this.page = page2;
2058
2175
  page2.addEventListener("message", this.receivePort);
2059
2176
  page2.addEventListener("pagehide", this.pagehide, { once: true });
2060
- page2.postMessage({ type: APP_HOST_READY, protocol: APP_HOST_PROTOCOL }, "*");
2177
+ page2.postMessage(
2178
+ { type: APP_HOST_READY, protocol: APP_HOST_PROTOCOL },
2179
+ "*"
2180
+ );
2061
2181
  }
2062
2182
  page;
2063
2183
  port;
@@ -2086,7 +2206,7 @@ var DocumentConnection = class {
2086
2206
  allowsInlineBody: () => this.features.has("fetch-inline-body-v1"),
2087
2207
  allowsTargetClose: () => this.features.has("fetch-target-close-v1"),
2088
2208
  send: (frame) => {
2089
- this.requireFeature("fetch-v2");
2209
+ this.requireFeature("fetch-v1");
2090
2210
  this.port.postMessage(frame);
2091
2211
  },
2092
2212
  onMessage: (listener) => {
@@ -2108,7 +2228,8 @@ var DocumentConnection = class {
2108
2228
  }
2109
2229
  pagehide = () => this.close(failure("connection_revoked"));
2110
2230
  receivePort = (event) => {
2111
- 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) return;
2231
+ 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)
2232
+ return;
2112
2233
  const port = event.ports[0];
2113
2234
  if (this.port || this.closed) {
2114
2235
  if (port !== this.port) port.close();
@@ -2153,26 +2274,33 @@ var DocumentConnection = class {
2153
2274
  const frameType = Object.getOwnPropertyDescriptor(data, "type")?.value;
2154
2275
  if (typeof frameType === "string" && frameType.startsWith("fetch-")) {
2155
2276
  if (!isPageFetchFrame(data)) throw failure("host_unavailable");
2156
- this.requireFeature("fetch-v2");
2277
+ this.requireFeature("fetch-v1");
2157
2278
  for (const listener of this.fetchListeners) listener(data);
2158
2279
  return;
2159
2280
  }
2160
- if (data.protocol !== APP_HOST_PROTOCOL) throw failure("host_unavailable");
2281
+ if (data.protocol !== APP_HOST_PROTOCOL)
2282
+ throw failure("host_unavailable");
2161
2283
  if (typeof data.type === "string" && data.type.startsWith("lifecycle-")) {
2162
2284
  this.requireFeature("lifecycle-v1");
2163
- if (!isAppLifecycleFrame(data) || data.type === "lifecycle-result") throw failure("host_unavailable");
2285
+ if (!isAppLifecycleFrame(data) || data.type === "lifecycle-result")
2286
+ throw failure("host_unavailable");
2164
2287
  this.lifecycle.receive(data);
2165
2288
  return;
2166
2289
  }
2167
2290
  if (data.type === "event") {
2168
- 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) throw failure("host_unavailable");
2291
+ 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)
2292
+ throw failure("host_unavailable");
2169
2293
  if (data.sequence <= this.sequence) return;
2170
- if (data.sequence !== this.sequence + 1) throw failure("host_unavailable");
2294
+ if (data.sequence !== this.sequence + 1)
2295
+ throw failure("host_unavailable");
2171
2296
  this.sequence = data.sequence;
2172
2297
  const appEvent = data.event;
2173
- if (appEvent.type === "command-invoked") this.requireFeature("commands-v1");
2174
- if (appEvent.type === "resources-changed") this.requireFeature("resource-catalog-v1");
2175
- if (appEvent.type === "service-changed") this.requireFeature("service-v1");
2298
+ if (appEvent.type === "command-invoked")
2299
+ this.requireFeature("commands-v1");
2300
+ if (appEvent.type === "resources-changed")
2301
+ this.requireFeature("resource-catalog-v1");
2302
+ if (appEvent.type === "service-changed")
2303
+ this.requireFeature("service-v1");
2176
2304
  if (validDesktopEvent(appEvent)) {
2177
2305
  this.requireFeature("trusted-desktop-v1");
2178
2306
  if (appEvent.type === "browser-changed" && appEvent.invalidated)
@@ -2181,7 +2309,8 @@ var DocumentConnection = class {
2181
2309
  if (validSystemEvent(appEvent)) this.requireFeature("system-ui-v1");
2182
2310
  if (validWindowEvent(appEvent)) this.requireFeature("window-chrome-v1");
2183
2311
  const observers = [...this.listeners];
2184
- if (appEvent.type === "connection-revoked") this.close(failure("connection_revoked"));
2312
+ if (appEvent.type === "connection-revoked")
2313
+ this.close(failure("connection_revoked"));
2185
2314
  for (const listener of observers) {
2186
2315
  try {
2187
2316
  listener(appEvent);
@@ -2190,17 +2319,27 @@ var DocumentConnection = class {
2190
2319
  }
2191
2320
  return;
2192
2321
  }
2193
- if (data.type !== "response" || typeof data.id !== "string") throw failure("host_unavailable");
2322
+ if (data.type !== "response" || typeof data.id !== "string")
2323
+ throw failure("host_unavailable");
2194
2324
  const p = this.pending.get(data.id);
2195
2325
  if (!p) return;
2196
2326
  if (data.ok === true) {
2197
- if (!keys(data, ["protocol", "type", "id", "ok"], ["value"]) || !validResult(p.method, data.value) || data.value !== void 0 && payloadSize(data.value) > APP_HOST_MAX_PAYLOAD_BYTES) throw failure("host_unavailable");
2327
+ if (!keys(data, ["protocol", "type", "id", "ok"], ["value"]) || !validResult(p.method, data.value) || data.value !== void 0 && payloadSize(data.value) > APP_HOST_MAX_PAYLOAD_BYTES)
2328
+ throw failure("host_unavailable");
2198
2329
  clearTimeout(p.timer);
2199
2330
  this.pending.delete(data.id);
2200
2331
  p.resolve(data.value);
2201
2332
  } else {
2202
- if (!keys(data, ["protocol", "type", "id", "ok", "error"]) || data.ok !== false || !isAppHostErrorInfo(data.error) || payloadSize(data.error) > APP_HOST_MAX_PAYLOAD_BYTES) throw failure("host_unavailable");
2203
- const error = new AppHostError(data.error.code, appHostErrorMessage(data.error.code, data.error.details), { ...data.error.requestId === void 0 ? {} : { requestId: data.error.requestId }, ...data.error.details === void 0 ? {} : { details: data.error.details } });
2333
+ if (!keys(data, ["protocol", "type", "id", "ok", "error"]) || data.ok !== false || !isAppHostErrorInfo(data.error) || payloadSize(data.error) > APP_HOST_MAX_PAYLOAD_BYTES)
2334
+ throw failure("host_unavailable");
2335
+ const error = new AppHostError(
2336
+ data.error.code,
2337
+ appHostErrorMessage(data.error.code, data.error.details),
2338
+ {
2339
+ ...data.error.requestId === void 0 ? {} : { requestId: data.error.requestId },
2340
+ ...data.error.details === void 0 ? {} : { details: data.error.details }
2341
+ }
2342
+ );
2204
2343
  clearTimeout(p.timer);
2205
2344
  this.pending.delete(data.id);
2206
2345
  p.reject(error);
@@ -2213,13 +2352,16 @@ var DocumentConnection = class {
2213
2352
  if (this.closed) return Promise.reject(this.closed);
2214
2353
  if (this.port) return Promise.resolve();
2215
2354
  return new Promise((resolve, reject) => {
2216
- const waiter = { resolve: () => {
2217
- clearTimeout(timer);
2218
- resolve();
2219
- }, reject: (error) => {
2220
- clearTimeout(timer);
2221
- reject(error);
2222
- } };
2355
+ const waiter = {
2356
+ resolve: () => {
2357
+ clearTimeout(timer);
2358
+ resolve();
2359
+ },
2360
+ reject: (error) => {
2361
+ clearTimeout(timer);
2362
+ reject(error);
2363
+ }
2364
+ };
2223
2365
  const timer = setTimeout(() => {
2224
2366
  this.waiting.delete(waiter);
2225
2367
  reject(hostFailure("host_port_timeout"));
@@ -2230,53 +2372,117 @@ var DocumentConnection = class {
2230
2372
  async connect(params) {
2231
2373
  await this.waitForPort();
2232
2374
  await this.request("connect", params);
2233
- this.negotiation ??= this.request("negotiate", { features: [...APP_HOST_FEATURES] }).then((result) => {
2375
+ this.negotiation ??= this.request("negotiate", {
2376
+ features: [...APP_HOST_FEATURES]
2377
+ }).then((result) => {
2234
2378
  this.features = new Set(result.features);
2235
2379
  });
2236
2380
  await this.negotiation;
2237
- const catalog = createResourceCatalogApi({ requireFeature: () => this.requireFeature("resource-catalog-v1"), request: (method, params2) => this.request(method, params2) });
2381
+ const catalog = createResourceCatalogApi({
2382
+ requireFeature: () => this.requireFeature("resource-catalog-v1"),
2383
+ request: (method, params2) => this.request(method, params2)
2384
+ });
2238
2385
  const conversationPreparation = createConversationPreparationApi({
2239
2386
  requireFeature: () => this.requireFeature("session-controls-v1"),
2240
2387
  request: (method, params2) => this.request(method, params2)
2241
2388
  });
2242
2389
  return {
2243
2390
  hasFeature: (feature) => this.features.has(feature),
2244
- commands: createAppCommandsApi({ requireFeature: () => this.requireFeature("commands-v1"), request: (method, params2) => this.request(method, params2), onInvoke: (listener) => {
2245
- const handler = (event) => {
2246
- if (event.type === "command-invoked") listener(event);
2247
- };
2248
- this.listeners.add(handler);
2249
- return () => {
2250
- this.listeners.delete(handler);
2251
- };
2252
- }, onClose: (listener) => {
2253
- this.closeListeners.add(listener);
2254
- return () => {
2255
- this.closeListeners.delete(listener);
2256
- };
2257
- } }),
2391
+ commands: createAppCommandsApi({
2392
+ requireFeature: () => this.requireFeature("commands-v1"),
2393
+ request: (method, params2) => this.request(method, params2),
2394
+ onInvoke: (listener) => {
2395
+ const handler = (event) => {
2396
+ if (event.type === "command-invoked") listener(event);
2397
+ };
2398
+ this.listeners.add(handler);
2399
+ return () => {
2400
+ this.listeners.delete(handler);
2401
+ };
2402
+ },
2403
+ onClose: (listener) => {
2404
+ this.closeListeners.add(listener);
2405
+ return () => {
2406
+ this.closeListeners.delete(listener);
2407
+ };
2408
+ }
2409
+ }),
2258
2410
  lifecycle: this.lifecycle.api,
2259
- system: createAppSystemApi({ requireFeature: () => this.requireFeature("system-ui-v1"), request: (method, params2) => this.request(method, params2) }, this.fetchClient),
2260
- window: createAppWindowApi({ requireFeature: () => this.requireFeature("window-chrome-v1"), request: (method, params2) => this.request(method, params2), onEvent: (listener) => {
2261
- this.listeners.add(listener);
2262
- return () => {
2263
- this.listeners.delete(listener);
2264
- };
2265
- } }),
2266
- desktop: createAppDesktopApi({
2267
- requireFeature: (method) => {
2268
- this.requireFeature("trusted-desktop-v1");
2269
- if (method === "desktop.browser.capturePreview") this.requireFeature("browser-capture-preview-v1");
2411
+ system: createAppSystemApi(
2412
+ {
2413
+ requireFeature: () => this.requireFeature("system-ui-v1"),
2414
+ request: (method, params2) => this.request(method, params2)
2415
+ },
2416
+ this.fetchClient
2417
+ ),
2418
+ window: createAppWindowApi({
2419
+ requireFeature: (feature) => this.requireFeature(feature ?? "window-chrome-v1"),
2420
+ request: (method, params2) => this.request(method, params2),
2421
+ onEvent: (listener) => {
2422
+ this.listeners.add(listener);
2423
+ return () => {
2424
+ this.listeners.delete(listener);
2425
+ };
2426
+ }
2427
+ }),
2428
+ desktop: createAppDesktopApi(
2429
+ {
2430
+ requireFeature: (method) => {
2431
+ this.requireFeature("trusted-desktop-v1");
2432
+ if (method === "desktop.browser.capturePreview")
2433
+ this.requireFeature("browser-capture-preview-v1");
2434
+ },
2435
+ request: (method, params2) => this.request(method, params2)
2436
+ },
2437
+ this.fetchClient,
2438
+ () => this.requireFeature("file-content-v1")
2439
+ ),
2440
+ attachments: createAppAttachmentsApi(
2441
+ {
2442
+ requireFeature: () => this.requireFeature("attachments-v1"),
2443
+ request: (method, params2) => this.request(method, params2)
2270
2444
  },
2271
- request: (method, params2) => this.request(method, params2)
2272
- }, this.fetchClient, () => this.requireFeature("file-content-v1")),
2273
- attachments: createAppAttachmentsApi({ requireFeature: () => this.requireFeature("attachments-v1"), request: (method, params2) => this.request(method, params2) }, this.fetchClient),
2274
- sessions: Object.assign(conversationPreparation, createAppSessionsApi({ requireFeature: () => this.requireFeature("session-resources-v1"), request: (method, params2) => this.request(method, params2) }, this.fetchClient), createAppAuxiliarySessionsApi({ requireFeature: () => this.requireFeature("auxiliary-sessions-v1"), request: (method, params2) => this.request(method, params2) }, this.fetchClient)),
2275
- workspace: Object.assign({ list: catalog.list }, createAppWorkspaceApi({ requireFeature: () => this.requireFeature("workspace-v1"), request: (method, params2) => this.request(method, params2) })),
2276
- service: createAppServiceApi({ request: (method, params2) => {
2277
- this.requireFeature("service-v1");
2278
- return this.request(method, params2);
2279
- } }, this.fetchClient),
2445
+ this.fetchClient
2446
+ ),
2447
+ sessions: Object.assign(
2448
+ conversationPreparation,
2449
+ createAppSessionsApi(
2450
+ {
2451
+ requireFeature: () => this.requireFeature("session-resources-v1"),
2452
+ request: (method, params2) => this.request(
2453
+ method,
2454
+ params2
2455
+ )
2456
+ },
2457
+ this.fetchClient
2458
+ ),
2459
+ createAppAuxiliarySessionsApi(
2460
+ {
2461
+ requireFeature: () => this.requireFeature("auxiliary-sessions-v1"),
2462
+ request: (method, params2) => this.request(method, params2)
2463
+ },
2464
+ this.fetchClient
2465
+ )
2466
+ ),
2467
+ workspace: Object.assign(
2468
+ { list: catalog.list },
2469
+ createAppWorkspaceApi({
2470
+ requireFeature: () => this.requireFeature("workspace-v1"),
2471
+ request: (method, params2) => this.request(method, params2)
2472
+ })
2473
+ ),
2474
+ service: createAppServiceApi(
2475
+ {
2476
+ request: (method, params2) => {
2477
+ this.requireFeature("service-v1");
2478
+ return this.request(
2479
+ method,
2480
+ params2
2481
+ );
2482
+ }
2483
+ },
2484
+ this.fetchClient
2485
+ ),
2280
2486
  getContext: () => this.request("getContext", {}),
2281
2487
  onEvent: (listener) => {
2282
2488
  if (!this.closed) this.listeners.add(listener);
@@ -2289,12 +2495,18 @@ var DocumentConnection = class {
2289
2495
  set: (key, value) => this.request("storage.set", { key, value }),
2290
2496
  delete: (key) => this.request("storage.delete", { key }),
2291
2497
  putFile: async (name2, data) => {
2292
- if (!(data instanceof Blob) || !nonempty(name2) || data.size + new TextEncoder().encode(JSON.stringify({ name: name2 })).byteLength > APP_HOST_MAX_PAYLOAD_BYTES) throw failure("invalid_request");
2293
- return this.request("storage.putFile", { name: name2, bytes: new Uint8Array(await data.arrayBuffer()) });
2498
+ if (!(data instanceof Blob) || !nonempty(name2) || data.size + new TextEncoder().encode(JSON.stringify({ name: name2 })).byteLength > APP_HOST_MAX_PAYLOAD_BYTES)
2499
+ throw failure("invalid_request");
2500
+ return this.request("storage.putFile", {
2501
+ name: name2,
2502
+ bytes: new Uint8Array(await data.arrayBuffer())
2503
+ });
2294
2504
  },
2295
2505
  readFile: async (id3) => {
2296
2506
  const bytes = await this.request("storage.readFile", { id: id3 });
2297
- return new Response(new Uint8Array(bytes), { headers: { "content-type": "application/octet-stream" } });
2507
+ return new Response(new Uint8Array(bytes), {
2508
+ headers: { "content-type": "application/octet-stream" }
2509
+ });
2298
2510
  },
2299
2511
  deleteFile: (id3) => this.request("storage.deleteFile", { id: id3 })
2300
2512
  },
@@ -2302,9 +2514,11 @@ var DocumentConnection = class {
2302
2514
  };
2303
2515
  }
2304
2516
  async login(input) {
2305
- if (!keys(input, ["url"]) || !nonempty(input.url)) throw failure("invalid_request");
2517
+ if (!keys(input, ["url"]) || !nonempty(input.url))
2518
+ throw failure("invalid_request");
2306
2519
  try {
2307
- if (new URL(input.url).protocol !== "https:") throw failure("invalid_request");
2520
+ if (new URL(input.url).protocol !== "https:")
2521
+ throw failure("invalid_request");
2308
2522
  } catch {
2309
2523
  throw failure("invalid_request");
2310
2524
  }
@@ -2312,18 +2526,45 @@ var DocumentConnection = class {
2312
2526
  }
2313
2527
  async request(method, params) {
2314
2528
  if (this.closed) throw this.closed;
2315
- if (Object.entries(params).some(([key, value]) => ["key", "id", "name"].includes(key) && !nonempty(value)) || this.pending.size >= APP_HOST_MAX_PENDING || payloadSize(params) > APP_HOST_MAX_PAYLOAD_BYTES) throw failure("invalid_request");
2529
+ if (Object.entries(params).some(
2530
+ ([key, value]) => ["key", "id", "name"].includes(key) && !nonempty(value)
2531
+ ) || this.pending.size >= APP_HOST_MAX_PENDING || payloadSize(params) > APP_HOST_MAX_PAYLOAD_BYTES)
2532
+ throw failure("invalid_request");
2316
2533
  const mutationRequestId = (isDesktopMethod(method) || isAuxiliaryMethod(method)) && "requestId" in params && typeof params.requestId === "string" && HOST_REQUEST_ID.test(params.requestId) ? params.requestId : void 0;
2317
2534
  const selectionRequestId = method === "workspace.select" ? params.requestId : void 0;
2535
+ let timeout = APP_HOST_REQUEST_TIMEOUT_MS;
2536
+ if (method === "auth.openLogin" || method === "workspace.select")
2537
+ timeout = APP_HOST_LOGIN_TRANSPORT_TIMEOUT_MS;
2538
+ if (method === "system.extensions") {
2539
+ const { operation } = params;
2540
+ if (operation === "skills.marketplaceCatalog" || operation === "skills.marketplaceInstall") {
2541
+ timeout = SKILL_MARKETPLACE_TIMEOUT_MS;
2542
+ }
2543
+ }
2318
2544
  return new Promise((resolve, reject) => {
2319
2545
  const id3 = String(++this.nextId);
2320
2546
  const timer = setTimeout(() => {
2321
2547
  this.pending.delete(id3);
2322
- reject(mutationRequestId ? new AppHostError("result_unknown", "result_unknown", { requestId: mutationRequestId }) : hostFailure("host_response_timeout", selectionRequestId));
2323
- }, method === "auth.openLogin" || method === "workspace.select" ? APP_HOST_LOGIN_TRANSPORT_TIMEOUT_MS : APP_HOST_REQUEST_TIMEOUT_MS);
2324
- this.pending.set(id3, { method, resolve: (value) => resolve(value), reject, timer });
2548
+ reject(
2549
+ mutationRequestId ? new AppHostError("result_unknown", "result_unknown", {
2550
+ requestId: mutationRequestId
2551
+ }) : hostFailure("host_response_timeout", selectionRequestId)
2552
+ );
2553
+ }, timeout);
2554
+ this.pending.set(id3, {
2555
+ method,
2556
+ resolve: (value) => resolve(value),
2557
+ reject,
2558
+ timer
2559
+ });
2325
2560
  try {
2326
- this.port.postMessage({ protocol: APP_HOST_PROTOCOL, type: "request", id: id3, method, params });
2561
+ this.port.postMessage({
2562
+ protocol: APP_HOST_PROTOCOL,
2563
+ type: "request",
2564
+ id: id3,
2565
+ method,
2566
+ params
2567
+ });
2327
2568
  } catch {
2328
2569
  this.close(hostFailure("host_send_failed"));
2329
2570
  }
@@ -2332,7 +2573,8 @@ var DocumentConnection = class {
2332
2573
  };
2333
2574
  var documents = /* @__PURE__ */ new WeakMap();
2334
2575
  async function connectAppHost(options) {
2335
- if (!keys(options, ["hostApi"]) || !nonempty(options.hostApi)) throw failure("invalid_request");
2576
+ if (!keys(options, ["hostApi"]) || !nonempty(options.hostApi))
2577
+ throw failure("invalid_request");
2336
2578
  if (typeof window === "undefined") throw failure("host_unavailable");
2337
2579
  let connection = documents.get(window);
2338
2580
  if (!connection) {