@bobannomi/app-host 0.1.0-next.1 → 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
  }
@@ -171,94 +183,6 @@ function validConnection(v) {
171
183
  return wireConnection(v) && /^[A-Za-z0-9-]+$/.test(v.connectionId) && v.baseUrl === `https://app-host.invalid/connections/${v.connectionId}`;
172
184
  }
173
185
 
174
- // ../domain-contracts/src/app-host/workspace-conversations.ts
175
- var validWorkspaceConversation = (value) => {
176
- if (!object(
177
- { dataScopeId: text(), requestId: id, sessionId: id, taskLocation: enumeration("current", "worktree"), configuration: json },
178
- { workspaceId: id, outsideProject: (v) => v === true, preparationRevision: text() }
179
- )(value)) return false;
180
- const input = value;
181
- return input.workspaceId !== void 0 ? input.outsideProject !== true : input.outsideProject === true && input.taskLocation === "current";
182
- };
183
- var sessionText = (value) => typeof value === "string";
184
- var sessionRecord = object({
185
- id,
186
- cwd: sessionText,
187
- title: sessionText,
188
- model: sessionText,
189
- status: enumeration("idle", "running", "closing", "archived", "error"),
190
- metadata: jsonObject,
191
- createdAt: count,
192
- updatedAt: count
193
- }, {
194
- storage: enumeration("sqlite", "memory"),
195
- parentId: sessionText,
196
- projectId: sessionText,
197
- cwdRelative: sessionText,
198
- agent: sessionText,
199
- archivedAt: count
200
- });
201
- var workspaceConversationResult = object({
202
- dataScopeId: text(),
203
- sessionId: id,
204
- requestId: id,
205
- action: (v) => v === "create-session",
206
- state: enumeration("prepared", "completed", "unknown")
207
- }, {
208
- configuration: json,
209
- revision: count,
210
- session: sessionRecord,
211
- operationState: enumeration("prepared", "running", "completed", "failed", "unknown"),
212
- indexBindingPending: (v) => v === true,
213
- workspaceId: id,
214
- executionRoot: id,
215
- privateSessionId: id,
216
- worktree: json
217
- });
218
- var validWorkspaceConversationResult = (value) => {
219
- if (!workspaceConversationResult(value)) return false;
220
- const result = value;
221
- return !result.session || result.state === "completed" && result.session.id === result.sessionId;
222
- };
223
-
224
- // ../domain-contracts/src/app-host/session-controls.ts
225
- var option = object({ id: text(), name: text() });
226
- var choices = array(option);
227
- var effortChoices = array(object({ id: text(1024, true), name: text() }));
228
- var receiptShape = object({ dataScopeId: text(), sessionId: text(), requestId: id, action: enumeration("fork", "configure", "compact"), state: enumeration("prepared", "created", "completed", "unknown") }, { revision: count, targetSessionId: text() });
229
- var receipt = receiptShape;
230
- function validSessionControlOriginal(value) {
231
- if (!object({ action: text(), body: json })(value)) return false;
232
- const v = value;
233
- if (v.action === "compact") return object({ requestId: id, expectedRevision: count })(v.body);
234
- return v.action === "fork" && object({ requestId: id, id: text() }, { copyHistory: bool, beforeMessageId: text(), afterMessageId: text(), storage: enumeration("sqlite") })(v.body);
235
- }
236
- function validSessionControlInput(method, value) {
237
- if (!json(value)) return false;
238
- if (method === "sessions.getDraftComposerOptions") {
239
- if (!object({ source: enumeration("instance") }, { workspaceId: id, outsideProject: bool, roleId: (v2) => v2 === null || text(256)(v2) })(value)) return false;
240
- const target2 = value;
241
- return target2.workspaceId !== void 0 ? target2.outsideProject !== true : target2.outsideProject === true;
242
- }
243
- if (method === "sessions.bindConversationIndex") return object({ original: validWorkspaceConversation, dataScopeId: text() })(value);
244
- if (method === "sessions.createConversation" || method === "sessions.getConversationCreationResult") return validWorkspaceConversation(value);
245
- if (method === "sessions.getControls") return object({ connectionId: text(), sessionId: text() })(value);
246
- if (!object({ requestId: id, sessionId: text(), original: validSessionControlOriginal }, { connectionId: text() })(value)) return false;
247
- const v = value;
248
- return v.original.body.requestId === v.requestId && !!v.connectionId;
249
- }
250
- function validSessionControlResult(method, value) {
251
- if (!json(value)) return false;
252
- if (method === "sessions.getDraftComposerOptions") return object({ source: enumeration("instance"), optionsRevision: text(), skills: array(object({ id: text(), name: text(), path: text(4096, true) }, { source: enumeration("bundled", "user", "project", "plugin") }), 128), plugins: array(object({ id: text(), name: text(), agents: array(option, 128) }), 128) })(value);
253
- if (method === "sessions.bindConversationIndex") return validWorkspaceConversationResult(value);
254
- if (method === "sessions.createConversation" || method === "sessions.getConversationCreationResult")
255
- return method === "sessions.getConversationCreationResult" && value === null || validWorkspaceConversationResult(value);
256
- if (method === "sessions.getControls") return object({ dataScopeId: text(), sessionId: text(), source: enumeration("instance", "auxiliary", "im"), revision: count, optionsRevision: text(), actions: object(Object.fromEntries(["readContext", "configure", "compact", "edit", "fork", "resume", "goalRead", "goalWrite", "goalStop"].map((k) => [k, bool]))), models: choices, roles: choices, efforts: effortChoices, workModes: choices, skills: array(object({ id: text(), name: text(), path: text(4096, true) }, { source: enumeration("bundled", "user", "project", "plugin") })), commands: choices, contexts: choices }, { permissionModes: array(option, 128), appServiceBindings: array(option, 128), plugins: array(object({ id: text(), name: text(), agents: choices })) })(value);
257
- if (method === "sessions.getControlResult") return value === null || receipt(value);
258
- if (!receipt(value)) return false;
259
- return false;
260
- }
261
-
262
186
  // ../domain-contracts/src/app-host/service.ts
263
187
  function fields(value, required, optional = []) {
264
188
  if (!value || typeof value !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(value)))
@@ -341,7 +265,31 @@ function validServiceConnectionInput(value) {
341
265
  }
342
266
 
343
267
  // ../domain-contracts/src/app-host/fetch.ts
344
- 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
+ ];
345
293
  var FETCH_CHUNK_BYTES = 64 * 1024;
346
294
  var FETCH_INLINE_BODY_BYTES = 8 * 1024;
347
295
  var FETCH_WINDOW_CHUNKS = 4;
@@ -354,7 +302,10 @@ function isPageFetchFrame(value) {
354
302
  const visit = (entry, depth, binary = false) => {
355
303
  if (depth > 10) return false;
356
304
  if (entry instanceof Uint8Array) {
357
- 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;
358
309
  const buffer = entry.buffer;
359
310
  return buffer instanceof ArrayBuffer && !Object.hasOwn(buffer, "byteLength") && buffer.byteLength <= FETCH_CHUNK_BYTES && entry.byteLength > 0 && entry.byteLength <= FETCH_CHUNK_BYTES;
360
311
  }
@@ -368,9 +319,11 @@ function isPageFetchFrame(value) {
368
319
  }
369
320
  if (!entry || typeof entry !== "object") return false;
370
321
  const array2 = Array.isArray(entry);
371
- 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;
372
324
  const keys2 = Reflect.ownKeys(entry);
373
- 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;
374
327
  return keys2.every((key) => {
375
328
  if (array2 && key === "length") return true;
376
329
  const d = Object.getOwnPropertyDescriptor(entry, key);
@@ -378,7 +331,8 @@ function isPageFetchFrame(value) {
378
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;
379
332
  });
380
333
  };
381
- 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;
382
336
  const v = value;
383
337
  if (v.protocol !== 2 || typeof v.type !== "string") return false;
384
338
  const fields4 = {
@@ -394,19 +348,28 @@ function isPageFetchFrame(value) {
394
348
  };
395
349
  const required = fields4[v.type];
396
350
  const inline = v.type === "fetch-open" && Object.hasOwn(v, "inlineBody");
397
- if (!required || Object.keys(v).length !== required.length + 2 + Number(inline) || !required.every((k) => Object.hasOwn(v, k))) return false;
398
- 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;
399
355
  const id3 = (x) => typeof x === "string" && x.length > 0 && x.length <= 128;
400
356
  if (v.type === "fetch-close") return id3(v.connectionId);
401
357
  if (!id3(v.id)) return false;
402
- if (v.type === "fetch-consumed") return v.direction === "download" && Number.isSafeInteger(v.sequence) && v.sequence >= 0;
403
- if (["fetch-chunk", "fetch-credit", "fetch-end"].includes(v.type) && (!["upload", "download"].includes(v.direction) || !Number.isSafeInteger(v.sequence) || v.sequence < 0)) return false;
404
- 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;
405
364
  if (v.type === "fetch-chunk") return v.bytes instanceof Uint8Array;
406
365
  if (v.type === "fetch-error") return isAppHostErrorInfo(v.error);
407
366
  if (v.type === "fetch-open" || v.type === "fetch-headers") {
408
- 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;
409
- 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);
410
373
  return Number.isInteger(v.status) && v.status >= 200 && v.status <= 599 && typeof v.statusText === "string";
411
374
  }
412
375
  return true;
@@ -414,9 +377,11 @@ function isPageFetchFrame(value) {
414
377
  function pageFetchPath(baseUrl, input) {
415
378
  if (/[\\\s#]/.test(input)) throw new TypeError("Invalid fetch URL");
416
379
  const rawPath = input.replace(/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^/]+/, "").split("?")[0];
417
- 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");
418
382
  const base = new URL(baseUrl), url = new URL(input);
419
- 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");
420
385
  return (url.pathname.slice(base.pathname.length) || "/") + url.search;
421
386
  }
422
387
 
@@ -425,6 +390,94 @@ var SERVICE_HOST_MAX_FRAME_BYTES = 512 * 1024;
425
390
  var worktreeBody = { workspaceId: id, expectedHead: text(256), branch: text(1024) };
426
391
  var worktreeReceipt = object({ requestId: id, state: enumeration("accepted", "completed", "failed", "unknown") }, { result: object({ executionRoot: id, workspaceId: id, branch: text(1024), sourceHead: text(256) }) });
427
392
 
393
+ // ../domain-contracts/src/app-host/workspace-conversations.ts
394
+ var validWorkspaceConversation = (value) => {
395
+ if (!object(
396
+ { dataScopeId: text(), requestId: id, sessionId: id, taskLocation: enumeration("current", "worktree"), configuration: json },
397
+ { workspaceId: id, outsideProject: (v) => v === true, preparationRevision: text() }
398
+ )(value)) return false;
399
+ const input = value;
400
+ return input.workspaceId !== void 0 ? input.outsideProject !== true : input.outsideProject === true && input.taskLocation === "current";
401
+ };
402
+ var sessionText = (value) => typeof value === "string";
403
+ var sessionRecord = object({
404
+ id,
405
+ cwd: sessionText,
406
+ title: sessionText,
407
+ model: sessionText,
408
+ status: enumeration("idle", "running", "closing", "archived", "error"),
409
+ metadata: jsonObject,
410
+ createdAt: count,
411
+ updatedAt: count
412
+ }, {
413
+ storage: enumeration("sqlite", "memory"),
414
+ parentId: sessionText,
415
+ projectId: sessionText,
416
+ cwdRelative: sessionText,
417
+ agent: sessionText,
418
+ archivedAt: count
419
+ });
420
+ var workspaceConversationResult = object({
421
+ dataScopeId: text(),
422
+ sessionId: id,
423
+ requestId: id,
424
+ action: (v) => v === "create-session",
425
+ state: enumeration("prepared", "completed", "unknown")
426
+ }, {
427
+ configuration: json,
428
+ revision: count,
429
+ session: sessionRecord,
430
+ operationState: enumeration("prepared", "running", "completed", "failed", "unknown"),
431
+ indexBindingPending: (v) => v === true,
432
+ workspaceId: id,
433
+ executionRoot: id,
434
+ privateSessionId: id,
435
+ worktree: json
436
+ });
437
+ var validWorkspaceConversationResult = (value) => {
438
+ if (!workspaceConversationResult(value)) return false;
439
+ const result = value;
440
+ return !result.session || result.state === "completed" && result.session.id === result.sessionId;
441
+ };
442
+
443
+ // ../domain-contracts/src/app-host/session-controls.ts
444
+ var option = object({ id: text(), name: text() });
445
+ var choices = array(option);
446
+ var effortChoices = array(object({ id: text(1024, true), name: text() }));
447
+ var receiptShape = object({ dataScopeId: text(), sessionId: text(), requestId: id, action: enumeration("fork", "configure", "compact"), state: enumeration("prepared", "created", "completed", "unknown") }, { revision: count, targetSessionId: text() });
448
+ var receipt = receiptShape;
449
+ function validSessionControlOriginal(value) {
450
+ if (!object({ action: text(), body: json })(value)) return false;
451
+ const v = value;
452
+ if (v.action === "compact") return object({ requestId: id, expectedRevision: count })(v.body);
453
+ return v.action === "fork" && object({ requestId: id, id: text() }, { copyHistory: bool, beforeMessageId: text(), afterMessageId: text(), storage: enumeration("sqlite") })(v.body);
454
+ }
455
+ function validSessionControlInput(method, value) {
456
+ if (!json(value)) return false;
457
+ if (method === "sessions.getDraftComposerOptions") {
458
+ if (!object({ source: enumeration("instance") }, { workspaceId: id, outsideProject: bool, roleId: (v2) => v2 === null || text(256)(v2) })(value)) return false;
459
+ const target2 = value;
460
+ return target2.workspaceId !== void 0 ? target2.outsideProject !== true : target2.outsideProject === true;
461
+ }
462
+ if (method === "sessions.bindConversationIndex") return object({ original: validWorkspaceConversation, dataScopeId: text() })(value);
463
+ if (method === "sessions.createConversation" || method === "sessions.getConversationCreationResult") return validWorkspaceConversation(value);
464
+ if (method === "sessions.getControls") return object({ connectionId: text(), sessionId: text() })(value);
465
+ if (!object({ requestId: id, sessionId: text(), original: validSessionControlOriginal }, { connectionId: text() })(value)) return false;
466
+ const v = value;
467
+ return v.original.body.requestId === v.requestId && !!v.connectionId;
468
+ }
469
+ function validSessionControlResult(method, value) {
470
+ if (!json(value)) return false;
471
+ if (method === "sessions.getDraftComposerOptions") return object({ source: enumeration("instance"), optionsRevision: text(), skills: array(object({ id: text(), name: text(), path: text(4096, true) }, { source: enumeration("bundled", "user", "project", "plugin") }), 128), plugins: array(object({ id: text(), name: text(), agents: array(option, 128) }), 128) })(value);
472
+ if (method === "sessions.bindConversationIndex") return validWorkspaceConversationResult(value);
473
+ if (method === "sessions.createConversation" || method === "sessions.getConversationCreationResult")
474
+ return method === "sessions.getConversationCreationResult" && value === null || validWorkspaceConversationResult(value);
475
+ if (method === "sessions.getControls") return object({ dataScopeId: text(), sessionId: text(), source: enumeration("instance", "auxiliary", "im"), revision: count, optionsRevision: text(), actions: object(Object.fromEntries(["readContext", "configure", "compact", "edit", "fork", "resume", "goalRead", "goalWrite", "goalStop"].map((k) => [k, bool]))), models: choices, roles: choices, efforts: effortChoices, workModes: choices, skills: array(object({ id: text(), name: text(), path: text(4096, true) }, { source: enumeration("bundled", "user", "project", "plugin") })), commands: choices, contexts: choices }, { permissionModes: array(option, 128), appServiceBindings: array(option, 128), plugins: array(object({ id: text(), name: text(), agents: choices })) })(value);
476
+ if (method === "sessions.getControlResult") return value === null || receipt(value);
477
+ if (!receipt(value)) return false;
478
+ return false;
479
+ }
480
+
428
481
  // ../domain-contracts/src/app-host/workspace.ts
429
482
  function fields2(v, required, optional = []) {
430
483
  if (!v || typeof v !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(v))) return false;
@@ -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),
@@ -827,7 +878,6 @@ var rules = {
827
878
  "desktop.browser.addAnnotation": { input: object({ ...page, selectionId: text(), comment: text(65536, true) }), result: validBrowserSnapshot },
828
879
  "desktop.browser.focusAnnotation": { input: object({ ...page, annotationId: text() }), result: validBrowserSnapshot },
829
880
  "desktop.browser.removeAnnotation": { input: object({ ...page, annotationId: text() }), result: validBrowserSnapshot },
830
- "desktop.browser.capture": { input: object(page), result: object({ assetId: text(), sha256: digest, mediaType: text(256), byteLength: count, width: positive, height: positive }) },
831
881
  "desktop.browser.capturePreview": { input: object(page), result: object({ bytes: capturePreviewBytes, width: positive, height: positive }) },
832
882
  "desktop.pluginApps.catalog": { input: object(target), result: object({ backends: array(object({ pluginId: text(), pluginVersion: text(), pluginDigest: text(), definitionDigest: text(), backendId: text(), backendKind: enumeration("native-tools", "mcp-server"), surfaces: array(object({ id: text(), title: text(), backend: text(), resourceUri: text(8192), availability: enumeration("session") })) })) }) },
833
883
  "desktop.pluginApps.composerContext": { input: object({ ...target, contextIds: array(id, 8) }), result: array(object({ source, lease: object({ token: text(), backendGeneration: text() }), requestId: id, expectedRevision: count, text: text(8 * 1024 * 1024, true), data: json }), 8) },
@@ -933,6 +983,13 @@ var selection = object({ cwd: text(4096), selectionId: text(256) });
933
983
  var cancel = object({ selectionId: text(256) });
934
984
  var name = object({ name: text(256) });
935
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
+ });
936
993
  var EXTENSION_INPUTS = {
937
994
  context: empty,
938
995
  "plugins.loadIcon": object({ src: text(8192) }),
@@ -957,6 +1014,8 @@ var EXTENSION_INPUTS = {
957
1014
  "plugins.marketplaceOperation": object({ cwd: text(4096), operationId: text(256) }),
958
1015
  "skills.snapshot": object({ projectPath: text(4096) }),
959
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),
960
1019
  "mcp.snapshot": empty,
961
1020
  "mcp.exportConfig": empty,
962
1021
  "mcp.getConfig": name,
@@ -1020,7 +1079,7 @@ var customProvider = object({
1020
1079
  models: array(object({ id: text(1024), displayName: text(1024) }, { imageInputSupport, ...limits }), 16384)
1021
1080
  }, { apiKey: text(8192), headers, secretHeaders });
1022
1081
  function validModelProviderRequest(value) {
1023
- 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);
1024
1083
  }
1025
1084
  var validModel = object({ id: text(1024), label: text(1024) }, { imageInputSupport, declaredLimits: object({}, limits) });
1026
1085
  var validConnection2 = object({
@@ -1118,7 +1177,6 @@ var SYSTEM_METHODS = [
1118
1177
  "system.setWindowMaterial",
1119
1178
  "system.copyText",
1120
1179
  "system.openExternal",
1121
- "system.markSessionRead",
1122
1180
  "system.navigationReady",
1123
1181
  "system.completeNavigation"
1124
1182
  ];
@@ -1238,12 +1296,6 @@ function validSystemInput(method, value) {
1238
1296
  page: enumeration("session-settings"),
1239
1297
  target: validSessionSettingsTarget
1240
1298
  })(value);
1241
- case "system.markSessionRead":
1242
- return object({
1243
- connectionId: text(256),
1244
- sessionId: text(256),
1245
- throughSeq: count
1246
- })(value);
1247
1299
  case "system.completeNavigation":
1248
1300
  return object({
1249
1301
  id: text(256),
@@ -1330,39 +1382,62 @@ function createAppSystemApi(requester, connectionOwner) {
1330
1382
  setWindowMaterial: (preference) => send("system.setWindowMaterial", { preference }),
1331
1383
  copyText: (text2) => send("system.copyText", { text: text2 }),
1332
1384
  openExternal: (url) => send("system.openExternal", { url }),
1333
- markSessionRead: ({ connection, sessionId, throughSeq }) => send("system.markSessionRead", {
1334
- connectionId: resolveClientConnection(connection, connectionOwner),
1335
- sessionId,
1336
- throughSeq
1337
- }),
1338
1385
  navigationReady: () => send("system.navigationReady", {}),
1339
1386
  completeNavigation: (input) => send("system.completeNavigation", input)
1340
1387
  };
1341
1388
  }
1342
1389
 
1343
1390
  // src/window.ts
1344
- 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
+ ];
1345
1400
  var finite2 = (value) => typeof value === "number" && Number.isFinite(value);
1346
1401
  var material = object({
1347
1402
  preference: enumeration("glass", "opaque"),
1348
1403
  active: enumeration("glass", "opaque"),
1349
1404
  shell: enumeration("solid", "translucent", "transparent"),
1350
- 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
+ )
1351
1413
  });
1352
- var validAppWindowState = (value) => object({
1353
- platform: enumeration("win32", "darwin", "linux"),
1354
- maximized: bool,
1355
- titleBar: enumeration("host", "custom", "native"),
1356
- trafficLightInset: (value2) => finite2(value2) && value2 >= 0,
1357
- 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
1358
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);
1359
1432
  function isWindowMethod(value) {
1360
1433
  return WINDOW_METHODS.includes(value);
1361
1434
  }
1362
1435
  function validWindowInput(method, value) {
1363
1436
  switch (method) {
1364
1437
  case "window.openHost":
1365
- return object({ page: enumeration("manage", "settings", "about", "recovery") })(value);
1438
+ return object({
1439
+ page: enumeration("manage", "settings", "about", "recovery")
1440
+ })(value);
1366
1441
  case "window.reportStartup":
1367
1442
  return object({ status: enumeration("ready") })(value) || object({ status: enumeration("failed"), message: text(2048) })(value);
1368
1443
  default:
@@ -1373,20 +1448,29 @@ function validWindowResult(method, value) {
1373
1448
  switch (method) {
1374
1449
  case "window.getState":
1375
1450
  return validAppWindowState(value);
1451
+ case "window.checkForUpdates":
1452
+ return validUpdateState(value) || object({ status: enumeration("unsupported") })(value);
1376
1453
  default:
1377
1454
  return value === void 0;
1378
1455
  }
1379
1456
  }
1380
1457
  function validWindowEvent(value) {
1381
- return object({ type: enumeration("window-state-changed"), state: validAppWindowState })(value);
1458
+ return object({
1459
+ type: enumeration("window-state-changed"),
1460
+ state: validAppWindowState
1461
+ })(value);
1382
1462
  }
1383
1463
  function createAppWindowApi(requester) {
1384
1464
  async function send(method, params) {
1385
1465
  requester.requireFeature();
1386
- 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");
1387
1470
  return requester.request(method, params);
1388
1471
  }
1389
1472
  return {
1473
+ checkForUpdates: () => send("window.checkForUpdates", {}),
1390
1474
  getState: () => send("window.getState", {}),
1391
1475
  minimize: () => send("window.minimize", {}),
1392
1476
  toggleMaximize: () => send("window.toggleMaximize", {}),
@@ -1395,7 +1479,8 @@ function createAppWindowApi(requester) {
1395
1479
  reportStartup: (input) => send("window.reportStartup", input),
1396
1480
  onStateChanged: (listener) => {
1397
1481
  requester.requireFeature();
1398
- if (typeof listener !== "function") throw new AppHostError("invalid_request");
1482
+ if (typeof listener !== "function")
1483
+ throw new AppHostError("invalid_request");
1399
1484
  return requester.onEvent((event) => {
1400
1485
  if (event.type === "window-state-changed") listener(event.state);
1401
1486
  });
@@ -1470,9 +1555,7 @@ function createAppWorkspaceApi(input) {
1470
1555
  async function call(method, params) {
1471
1556
  if (!validWorkspaceInput(method, params)) throw new AppHostError("invalid_request");
1472
1557
  input.requireFeature();
1473
- const value = await input.request(method, params);
1474
- if (!validWorkspaceResult(method, value)) throw new AppHostError("host_unavailable");
1475
- return value;
1558
+ return input.request(method, params);
1476
1559
  }
1477
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) };
1478
1561
  }
@@ -1486,35 +1569,23 @@ function resourceFields(v, required, optional = []) {
1486
1569
  });
1487
1570
  }
1488
1571
  var str2 = (v, max = 256) => typeof v === "string" && v.length > 0 && v.length <= max;
1489
- function validSessionResourceInput(method, v) {
1490
- if (method === "sessions.getConnection" && resourceFields(v, [])) return true;
1491
- return resourceFields(v, ["dataScopeId", "sessionId"]) && str2(v.dataScopeId) && str2(v.sessionId);
1492
- }
1493
- function validSessionResourceResult(method, v) {
1572
+ function validSessionResourceResult(_method, v) {
1494
1573
  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}`;
1495
1574
  }
1496
1575
  function createAppSessionsApi(input, streams) {
1497
- const call = async (method, params) => {
1498
- if (!validSessionResourceInput(method, params)) throw new AppHostError("invalid_request");
1499
- input.requireFeature();
1500
- const result = await input.request(method, params);
1501
- if (!validSessionResourceResult(method, result)) throw new AppHostError("host_unavailable");
1502
- return result;
1576
+ return {
1577
+ async getConnection(...args) {
1578
+ if (args.length !== 0) throw new AppHostError("invalid_request");
1579
+ input.requireFeature();
1580
+ const wire = await input.request("sessions.getConnection", {});
1581
+ return createClientConnection(wire, streams);
1582
+ }
1503
1583
  };
1504
- return { async getConnection(params = {}) {
1505
- const wire = await call("sessions.getConnection", params);
1506
- return createClientConnection(wire, streams);
1507
- } };
1508
1584
  }
1509
1585
 
1510
1586
  // src/service.ts
1511
1587
  function createAppServiceApi(rpc, streams) {
1512
- const request = async (method, params) => {
1513
- const value = await rpc.request(method, params);
1514
- if (!validServiceResult(method, value))
1515
- throw new AppHostError("host_unavailable");
1516
- return value;
1517
- };
1588
+ const request = async (method, params) => rpc.request(method, params);
1518
1589
  const work = (method, requestId) => {
1519
1590
  if (typeof requestId !== "string" || !HOST_REQUEST_ID.test(requestId))
1520
1591
  return Promise.reject(new AppHostError("invalid_request"));
@@ -1953,13 +2024,18 @@ function createPageFetchClient(options) {
1953
2024
  }
1954
2025
 
1955
2026
  // src/connection.ts
2027
+ var SKILL_MARKETPLACE_TIMEOUT_MS = 3e5;
1956
2028
  var failure = (code) => new AppHostError(code);
1957
2029
  var hostFailure = (reason, requestId) => {
1958
2030
  const details = { reason };
1959
- return new AppHostError("host_unavailable", appHostErrorMessage("host_unavailable", details), {
1960
- details,
1961
- ...requestId === void 0 ? {} : { requestId }
1962
- });
2031
+ return new AppHostError(
2032
+ "host_unavailable",
2033
+ appHostErrorMessage("host_unavailable", details),
2034
+ {
2035
+ details,
2036
+ ...requestId === void 0 ? {} : { requestId }
2037
+ }
2038
+ );
1963
2039
  };
1964
2040
  function record(value) {
1965
2041
  return value !== null && typeof value === "object" && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
@@ -1967,10 +2043,13 @@ function record(value) {
1967
2043
  function keys(value, required, optional = []) {
1968
2044
  if (!record(value)) return false;
1969
2045
  const own = Reflect.ownKeys(value);
1970
- 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
+ );
1971
2049
  }
1972
2050
  function dataArray(value) {
1973
- 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;
1974
2053
  for (let i = 0; i < value.length; i++) {
1975
2054
  const d = Object.getOwnPropertyDescriptor(value, String(i));
1976
2055
  if (!d?.enumerable || !Object.hasOwn(d, "value")) return false;
@@ -1981,10 +2060,13 @@ function nonempty(value) {
1981
2060
  return typeof value === "string" && value.length > 0;
1982
2061
  }
1983
2062
  function json3(value, ancestors = /* @__PURE__ */ new Set()) {
1984
- if (value === null || typeof value === "string" || typeof value === "boolean") return true;
2063
+ if (value === null || typeof value === "string" || typeof value === "boolean")
2064
+ return true;
1985
2065
  if (typeof value === "number") return Number.isFinite(value);
1986
- if (typeof value !== "object" || !record(value) && !Array.isArray(value) || ancestors.has(value)) return false;
1987
- 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;
1988
2070
  ancestors.add(value);
1989
2071
  try {
1990
2072
  return Reflect.ownKeys(value).every((k) => {
@@ -2006,7 +2088,27 @@ function payloadSize(value) {
2006
2088
  return new TextEncoder().encode(JSON.stringify(value)).byteLength;
2007
2089
  }
2008
2090
  function validContext(value) {
2009
- 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
+ );
2010
2112
  }
2011
2113
  function validEvent(value) {
2012
2114
  if (!record(value)) return false;
@@ -2031,19 +2133,27 @@ function validEvent(value) {
2031
2133
  }
2032
2134
  function validResult(method, value) {
2033
2135
  if (isCommandsMethod(method)) return validCommandReceipt(value);
2034
- if (isResourceCatalogMethod(method)) return validResourceCatalogResult(method, value);
2136
+ if (isResourceCatalogMethod(method))
2137
+ return validResourceCatalogResult(method, value);
2035
2138
  if (isSystemMethod(method)) return validSystemResult(method, value);
2036
2139
  if (isWindowMethod(method)) return validWindowResult(method, value);
2037
2140
  if (isDesktopMethod(method)) return validDesktopResult(method, value);
2038
- if (method === "attachments.getConnection") return validAttachmentsResult(value);
2141
+ if (method === "attachments.getConnection")
2142
+ return validAttachmentsResult(value);
2039
2143
  if (isAuxiliaryMethod(method)) return validAuxiliaryResult(method, value);
2040
- if (isConversationPreparationMethod(method)) return validConversationPreparationResult(method, value);
2041
- if (method.startsWith("sessions.")) return validSessionResourceResult(method, value);
2042
- if (method.startsWith("workspace.")) return validWorkspaceResult(method, value);
2043
- 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);
2044
2152
  switch (method) {
2045
2153
  case "negotiate":
2046
- 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
+ );
2047
2157
  case "connect":
2048
2158
  case "getContext":
2049
2159
  return validContext(value);
@@ -2064,7 +2174,10 @@ var DocumentConnection = class {
2064
2174
  this.page = page2;
2065
2175
  page2.addEventListener("message", this.receivePort);
2066
2176
  page2.addEventListener("pagehide", this.pagehide, { once: true });
2067
- page2.postMessage({ type: APP_HOST_READY, protocol: APP_HOST_PROTOCOL }, "*");
2177
+ page2.postMessage(
2178
+ { type: APP_HOST_READY, protocol: APP_HOST_PROTOCOL },
2179
+ "*"
2180
+ );
2068
2181
  }
2069
2182
  page;
2070
2183
  port;
@@ -2093,7 +2206,7 @@ var DocumentConnection = class {
2093
2206
  allowsInlineBody: () => this.features.has("fetch-inline-body-v1"),
2094
2207
  allowsTargetClose: () => this.features.has("fetch-target-close-v1"),
2095
2208
  send: (frame) => {
2096
- this.requireFeature("fetch-v2");
2209
+ this.requireFeature("fetch-v1");
2097
2210
  this.port.postMessage(frame);
2098
2211
  },
2099
2212
  onMessage: (listener) => {
@@ -2115,7 +2228,8 @@ var DocumentConnection = class {
2115
2228
  }
2116
2229
  pagehide = () => this.close(failure("connection_revoked"));
2117
2230
  receivePort = (event) => {
2118
- 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;
2119
2233
  const port = event.ports[0];
2120
2234
  if (this.port || this.closed) {
2121
2235
  if (port !== this.port) port.close();
@@ -2160,26 +2274,33 @@ var DocumentConnection = class {
2160
2274
  const frameType = Object.getOwnPropertyDescriptor(data, "type")?.value;
2161
2275
  if (typeof frameType === "string" && frameType.startsWith("fetch-")) {
2162
2276
  if (!isPageFetchFrame(data)) throw failure("host_unavailable");
2163
- this.requireFeature("fetch-v2");
2277
+ this.requireFeature("fetch-v1");
2164
2278
  for (const listener of this.fetchListeners) listener(data);
2165
2279
  return;
2166
2280
  }
2167
- if (data.protocol !== APP_HOST_PROTOCOL) throw failure("host_unavailable");
2281
+ if (data.protocol !== APP_HOST_PROTOCOL)
2282
+ throw failure("host_unavailable");
2168
2283
  if (typeof data.type === "string" && data.type.startsWith("lifecycle-")) {
2169
2284
  this.requireFeature("lifecycle-v1");
2170
- if (!isAppLifecycleFrame(data) || data.type === "lifecycle-result") throw failure("host_unavailable");
2285
+ if (!isAppLifecycleFrame(data) || data.type === "lifecycle-result")
2286
+ throw failure("host_unavailable");
2171
2287
  this.lifecycle.receive(data);
2172
2288
  return;
2173
2289
  }
2174
2290
  if (data.type === "event") {
2175
- 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");
2176
2293
  if (data.sequence <= this.sequence) return;
2177
- if (data.sequence !== this.sequence + 1) throw failure("host_unavailable");
2294
+ if (data.sequence !== this.sequence + 1)
2295
+ throw failure("host_unavailable");
2178
2296
  this.sequence = data.sequence;
2179
2297
  const appEvent = data.event;
2180
- if (appEvent.type === "command-invoked") this.requireFeature("commands-v1");
2181
- if (appEvent.type === "resources-changed") this.requireFeature("resource-catalog-v1");
2182
- 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");
2183
2304
  if (validDesktopEvent(appEvent)) {
2184
2305
  this.requireFeature("trusted-desktop-v1");
2185
2306
  if (appEvent.type === "browser-changed" && appEvent.invalidated)
@@ -2188,7 +2309,8 @@ var DocumentConnection = class {
2188
2309
  if (validSystemEvent(appEvent)) this.requireFeature("system-ui-v1");
2189
2310
  if (validWindowEvent(appEvent)) this.requireFeature("window-chrome-v1");
2190
2311
  const observers = [...this.listeners];
2191
- if (appEvent.type === "connection-revoked") this.close(failure("connection_revoked"));
2312
+ if (appEvent.type === "connection-revoked")
2313
+ this.close(failure("connection_revoked"));
2192
2314
  for (const listener of observers) {
2193
2315
  try {
2194
2316
  listener(appEvent);
@@ -2197,17 +2319,27 @@ var DocumentConnection = class {
2197
2319
  }
2198
2320
  return;
2199
2321
  }
2200
- 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");
2201
2324
  const p = this.pending.get(data.id);
2202
2325
  if (!p) return;
2203
2326
  if (data.ok === true) {
2204
- 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");
2205
2329
  clearTimeout(p.timer);
2206
2330
  this.pending.delete(data.id);
2207
2331
  p.resolve(data.value);
2208
2332
  } else {
2209
- 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");
2210
- 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
+ );
2211
2343
  clearTimeout(p.timer);
2212
2344
  this.pending.delete(data.id);
2213
2345
  p.reject(error);
@@ -2220,13 +2352,16 @@ var DocumentConnection = class {
2220
2352
  if (this.closed) return Promise.reject(this.closed);
2221
2353
  if (this.port) return Promise.resolve();
2222
2354
  return new Promise((resolve, reject) => {
2223
- const waiter = { resolve: () => {
2224
- clearTimeout(timer);
2225
- resolve();
2226
- }, reject: (error) => {
2227
- clearTimeout(timer);
2228
- reject(error);
2229
- } };
2355
+ const waiter = {
2356
+ resolve: () => {
2357
+ clearTimeout(timer);
2358
+ resolve();
2359
+ },
2360
+ reject: (error) => {
2361
+ clearTimeout(timer);
2362
+ reject(error);
2363
+ }
2364
+ };
2230
2365
  const timer = setTimeout(() => {
2231
2366
  this.waiting.delete(waiter);
2232
2367
  reject(hostFailure("host_port_timeout"));
@@ -2237,53 +2372,117 @@ var DocumentConnection = class {
2237
2372
  async connect(params) {
2238
2373
  await this.waitForPort();
2239
2374
  await this.request("connect", params);
2240
- 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) => {
2241
2378
  this.features = new Set(result.features);
2242
2379
  });
2243
2380
  await this.negotiation;
2244
- 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
+ });
2245
2385
  const conversationPreparation = createConversationPreparationApi({
2246
2386
  requireFeature: () => this.requireFeature("session-controls-v1"),
2247
2387
  request: (method, params2) => this.request(method, params2)
2248
2388
  });
2249
2389
  return {
2250
2390
  hasFeature: (feature) => this.features.has(feature),
2251
- commands: createAppCommandsApi({ requireFeature: () => this.requireFeature("commands-v1"), request: (method, params2) => this.request(method, params2), onInvoke: (listener) => {
2252
- const handler = (event) => {
2253
- if (event.type === "command-invoked") listener(event);
2254
- };
2255
- this.listeners.add(handler);
2256
- return () => {
2257
- this.listeners.delete(handler);
2258
- };
2259
- }, onClose: (listener) => {
2260
- this.closeListeners.add(listener);
2261
- return () => {
2262
- this.closeListeners.delete(listener);
2263
- };
2264
- } }),
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
+ }),
2265
2410
  lifecycle: this.lifecycle.api,
2266
- system: createAppSystemApi({ requireFeature: () => this.requireFeature("system-ui-v1"), request: (method, params2) => this.request(method, params2) }, this.fetchClient),
2267
- window: createAppWindowApi({ requireFeature: () => this.requireFeature("window-chrome-v1"), request: (method, params2) => this.request(method, params2), onEvent: (listener) => {
2268
- this.listeners.add(listener);
2269
- return () => {
2270
- this.listeners.delete(listener);
2271
- };
2272
- } }),
2273
- desktop: createAppDesktopApi({
2274
- requireFeature: (method) => {
2275
- this.requireFeature("trusted-desktop-v1");
2276
- 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)
2444
+ },
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
+ }
2277
2483
  },
2278
- request: (method, params2) => this.request(method, params2)
2279
- }, this.fetchClient, () => this.requireFeature("file-content-v1")),
2280
- attachments: createAppAttachmentsApi({ requireFeature: () => this.requireFeature("attachments-v1"), request: (method, params2) => this.request(method, params2) }, this.fetchClient),
2281
- 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)),
2282
- workspace: Object.assign({ list: catalog.list }, createAppWorkspaceApi({ requireFeature: () => this.requireFeature("workspace-v1"), request: (method, params2) => this.request(method, params2) })),
2283
- service: createAppServiceApi({ request: (method, params2) => {
2284
- this.requireFeature("service-v1");
2285
- return this.request(method, params2);
2286
- } }, this.fetchClient),
2484
+ this.fetchClient
2485
+ ),
2287
2486
  getContext: () => this.request("getContext", {}),
2288
2487
  onEvent: (listener) => {
2289
2488
  if (!this.closed) this.listeners.add(listener);
@@ -2296,12 +2495,18 @@ var DocumentConnection = class {
2296
2495
  set: (key, value) => this.request("storage.set", { key, value }),
2297
2496
  delete: (key) => this.request("storage.delete", { key }),
2298
2497
  putFile: async (name2, data) => {
2299
- 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");
2300
- 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
+ });
2301
2504
  },
2302
2505
  readFile: async (id3) => {
2303
2506
  const bytes = await this.request("storage.readFile", { id: id3 });
2304
- 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
+ });
2305
2510
  },
2306
2511
  deleteFile: (id3) => this.request("storage.deleteFile", { id: id3 })
2307
2512
  },
@@ -2309,9 +2514,11 @@ var DocumentConnection = class {
2309
2514
  };
2310
2515
  }
2311
2516
  async login(input) {
2312
- if (!keys(input, ["url"]) || !nonempty(input.url)) throw failure("invalid_request");
2517
+ if (!keys(input, ["url"]) || !nonempty(input.url))
2518
+ throw failure("invalid_request");
2313
2519
  try {
2314
- if (new URL(input.url).protocol !== "https:") throw failure("invalid_request");
2520
+ if (new URL(input.url).protocol !== "https:")
2521
+ throw failure("invalid_request");
2315
2522
  } catch {
2316
2523
  throw failure("invalid_request");
2317
2524
  }
@@ -2319,18 +2526,45 @@ var DocumentConnection = class {
2319
2526
  }
2320
2527
  async request(method, params) {
2321
2528
  if (this.closed) throw this.closed;
2322
- 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");
2323
2533
  const mutationRequestId = (isDesktopMethod(method) || isAuxiliaryMethod(method)) && "requestId" in params && typeof params.requestId === "string" && HOST_REQUEST_ID.test(params.requestId) ? params.requestId : void 0;
2324
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
+ }
2325
2544
  return new Promise((resolve, reject) => {
2326
2545
  const id3 = String(++this.nextId);
2327
2546
  const timer = setTimeout(() => {
2328
2547
  this.pending.delete(id3);
2329
- reject(mutationRequestId ? new AppHostError("result_unknown", "result_unknown", { requestId: mutationRequestId }) : hostFailure("host_response_timeout", selectionRequestId));
2330
- }, method === "auth.openLogin" || method === "workspace.select" ? APP_HOST_LOGIN_TRANSPORT_TIMEOUT_MS : APP_HOST_REQUEST_TIMEOUT_MS);
2331
- 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
+ });
2332
2560
  try {
2333
- 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
+ });
2334
2568
  } catch {
2335
2569
  this.close(hostFailure("host_send_failed"));
2336
2570
  }
@@ -2339,7 +2573,8 @@ var DocumentConnection = class {
2339
2573
  };
2340
2574
  var documents = /* @__PURE__ */ new WeakMap();
2341
2575
  async function connectAppHost(options) {
2342
- if (!keys(options, ["hostApi"]) || !nonempty(options.hostApi)) throw failure("invalid_request");
2576
+ if (!keys(options, ["hostApi"]) || !nonempty(options.hostApi))
2577
+ throw failure("invalid_request");
2343
2578
  if (typeof window === "undefined") throw failure("host_unavailable");
2344
2579
  let connection = documents.get(window);
2345
2580
  if (!connection) {