@bobannomi/app-host 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -19,7 +19,9 @@ var APP_HOST_ERROR_RETRY = {
19
19
  root_changed: "never",
20
20
  resource_revision_conflict: "query",
21
21
  request_conflict: "never",
22
- cursor_stale: "query"
22
+ cursor_stale: "query",
23
+ model_provider_not_configured: "never",
24
+ model_not_configured: "never"
23
25
  };
24
26
  var HOST_REQUEST_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
25
27
  function isSafeErrorDetails(value, depth = 0) {
@@ -45,6 +47,8 @@ function isAppHostErrorInfo(value) {
45
47
  }
46
48
  function appHostErrorMessage(code, details) {
47
49
  const reason = details && typeof details === "object" && !Array.isArray(details) ? details.reason : void 0;
50
+ if (code === "model_provider_not_configured") return "\u8BF7\u5148\u914D\u7F6E\u6240\u9009\u4F9B\u5E94\u5546\u7684\u8FDE\u63A5\u3002";
51
+ if (code === "model_not_configured") return "\u8BF7\u5728\u4F9B\u5E94\u5546\u914D\u7F6E\u4E2D\u4FDD\u5B58\u6240\u9009\u6A21\u578B\u3002";
48
52
  if (code === "host_unavailable") {
49
53
  switch (reason) {
50
54
  case "host_port_timeout":
@@ -61,6 +65,18 @@ function appHostErrorMessage(code, details) {
61
65
  return "The desktop host could not reconnect services for this page.";
62
66
  case "host_access_check_failed":
63
67
  return "The desktop host could not verify access for this page.";
68
+ case "skill_marketplace_unavailable":
69
+ return "\u6682\u65F6\u65E0\u6CD5\u8BFB\u53D6\u5B98\u65B9\u6280\u80FD\u5E02\u573A\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002";
70
+ case "skill_marketplace_install_failed":
71
+ return "\u6280\u80FD\u5B89\u88C5\u6216\u66F4\u65B0\u672A\u5B8C\u6210\uFF0C\u8BF7\u5237\u65B0\u5DF2\u5B89\u88C5\u6280\u80FD\u540E\u91CD\u8BD5\u3002";
72
+ case "skill_marketplace_busy":
73
+ return "\u540E\u53F0\u6B63\u5728\u8FD0\u884C\u4EFB\u52A1\u6216\u5904\u7406\u6280\u80FD\u53D8\u66F4\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002";
74
+ case "skill_marketplace_local_conflict":
75
+ 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";
76
+ case "skill_marketplace_selection_changed":
77
+ return "\u6240\u9009\u6280\u80FD\u6216\u7248\u672C\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u6280\u80FD\u5E02\u573A\u540E\u91CD\u8BD5\u3002";
78
+ case "skill_marketplace_project_unavailable":
79
+ return "\u5F53\u524D\u9879\u76EE\u65E0\u6CD5\u5B89\u88C5\u6280\u80FD\uFF0C\u8BF7\u9009\u62E9\u5DF2\u767B\u8BB0\u7684\u9879\u76EE\u3002";
64
80
  default:
65
81
  return "The desktop host could not complete the operation.";
66
82
  }
@@ -102,7 +118,7 @@ var AppHostError = class extends Error {
102
118
  };
103
119
 
104
120
  // ../domain-contracts/src/app-host/wire-validation.ts
105
- var text = (max = 1024, empty2 = false) => (v) => typeof v === "string" && (empty2 || v.length > 0) && new TextEncoder().encode(v).byteLength <= max;
121
+ var text = (max = 1024, empty3 = false) => (v) => typeof v === "string" && (empty3 || v.length > 0) && new TextEncoder().encode(v).byteLength <= max;
106
122
  var id = (v) => typeof v === "string" && HOST_REQUEST_ID.test(v);
107
123
  var count = (v) => typeof v === "number" && Number.isSafeInteger(v) && v >= 0;
108
124
  var bool = (v) => typeof v === "boolean";
@@ -171,89 +187,32 @@ function validConnection(v) {
171
187
  return wireConnection(v) && /^[A-Za-z0-9-]+$/.test(v.connectionId) && v.baseUrl === `https://app-host.invalid/connections/${v.connectionId}`;
172
188
  }
173
189
 
174
- // ../domain-contracts/src/app-host/service.ts
175
- function fields(value, required, optional = []) {
176
- if (!value || typeof value !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(value)))
177
- return false;
178
- return required.every((k) => Object.hasOwn(value, k)) && Reflect.ownKeys(value).every((k) => {
179
- const d = Object.getOwnPropertyDescriptor(value, k);
180
- return typeof k === "string" && [...required, ...optional].includes(k) && d.enumerable && Object.hasOwn(d, "value");
181
- });
182
- }
183
- var version = (v) => typeof v === "string" && /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*)?(?:\+[\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*)?$/.test(
184
- v
185
- );
186
- function json2(value, ancestors = /* @__PURE__ */ new Set(), depth = 0) {
187
- if (depth > 100) return false;
188
- if (value === null || typeof value === "string" || typeof value === "boolean")
189
- return true;
190
- if (typeof value === "number") return Number.isFinite(value);
191
- if (typeof value !== "object" || ancestors.has(value)) return false;
192
- const array2 = Array.isArray(value);
193
- if (array2 ? Object.getPrototypeOf(value) !== Array.prototype || Reflect.ownKeys(value).length !== value.length + 1 : ![Object.prototype, null].includes(Object.getPrototypeOf(value)))
194
- return false;
195
- ancestors.add(value);
196
- const result = Reflect.ownKeys(value).every((k) => {
197
- if (array2 && k === "length") return true;
198
- const d = Object.getOwnPropertyDescriptor(value, k);
199
- return typeof k === "string" && (!array2 || /^(0|[1-9]\d*)$/.test(k) && Number(k) < value.length) && d.enumerable && Object.hasOwn(d, "value") && json2(d.value, ancestors, depth + 1);
200
- });
201
- ancestors.delete(value);
202
- return result;
203
- }
204
- function validServiceStatus(value) {
205
- return fields(value, ["state"], ["reason", "instanceId", "apiVersion"]) && [
206
- "absent",
207
- "unauthorized",
208
- "stopped",
209
- "starting",
210
- "recovering",
211
- "ready",
212
- "failed"
213
- ].includes(value.state) && (!Object.hasOwn(value, "reason") || [
214
- "dependency_missing",
215
- "service_start_failed",
216
- "service_unavailable",
217
- "result_unknown",
218
- "incompatible",
219
- "revoked"
220
- ].includes(value.reason)) && (!Object.hasOwn(value, "instanceId") || typeof value.instanceId === "string" && HOST_REQUEST_ID.test(value.instanceId)) && (!Object.hasOwn(value, "apiVersion") || version(value.apiVersion)) && (value.state !== "ready" || Object.hasOwn(value, "instanceId") && Object.hasOwn(value, "apiVersion"));
221
- }
222
- function validWork(value) {
223
- return fields(value, ["requestId", "state", "updatedAt"], ["result", "error"]) && typeof value.requestId === "string" && HOST_REQUEST_ID.test(value.requestId) && [
224
- "not_accepted",
225
- "accepted",
226
- "running",
227
- "completed",
228
- "failed",
229
- "interrupted",
230
- "unknown"
231
- ].includes(value.state) && typeof value.updatedAt === "string" && /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?(?:Z|[+-]\d\d:\d\d)$/.test(
232
- value.updatedAt
233
- ) && Number.isFinite(Date.parse(value.updatedAt)) && ["result", "error"].every(
234
- (k) => !Object.hasOwn(value, k) || json2(value[k]) && new TextEncoder().encode(JSON.stringify(value[k])).length <= 16384
235
- );
236
- }
237
- function validServiceResult(method, value) {
238
- switch (method) {
239
- case "service.getStatus":
240
- return validServiceStatus(value);
241
- case "service.getConnection":
242
- return fields(value, ["connectionId", "baseUrl", "apiVersion"]) && typeof value.connectionId === "string" && /^[A-Za-z0-9-]+$/.test(value.connectionId) && value.baseUrl === `https://app-host.invalid/connections/${value.connectionId}` && version(value.apiVersion);
243
- case "service.getWork":
244
- return validWork(value);
245
- case "service.listWork":
246
- return Array.isArray(value) && value.length <= 5120 && value.every(validWork) && new Set(value.map((w) => w.requestId)).size === value.length;
247
- case "service.interruptWork":
248
- return fields(value, ["requested"]) && typeof value.requested === "boolean";
249
- }
250
- }
251
- function validServiceConnectionInput(value) {
252
- return fields(value, ["apiRange"]) && typeof value.apiRange === "string" && !!value.apiRange.trim() && value.apiRange.length <= 256;
253
- }
254
-
255
190
  // ../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"];
191
+ var APP_HOST_FEATURES = [
192
+ "fetch-v1",
193
+ "fetch-inline-body-v1",
194
+ "fetch-target-close-v1",
195
+ "service-v1",
196
+ "extended-errors-v1",
197
+ "workspace-v1",
198
+ "session-resources-v1",
199
+ "session-controls-v1",
200
+ "conversation-creation-session-v1",
201
+ "trusted-desktop-v1",
202
+ "attachments-v1",
203
+ "auxiliary-sessions-v1",
204
+ "system-ui-v1",
205
+ "lifecycle-v1",
206
+ "commands-v1",
207
+ "resource-catalog-v1",
208
+ "file-content-v1",
209
+ "window-chrome-v1",
210
+ "window-updates-v1",
211
+ "window-update-check-v1",
212
+ "embedded-browser-v1",
213
+ "browser-binding-invalidation-v1",
214
+ "browser-capture-preview-v1"
215
+ ];
257
216
  var FETCH_CHUNK_BYTES = 64 * 1024;
258
217
  var FETCH_INLINE_BODY_BYTES = 8 * 1024;
259
218
  var FETCH_WINDOW_CHUNKS = 4;
@@ -266,7 +225,10 @@ function isPageFetchFrame(value) {
266
225
  const visit = (entry, depth, binary = false) => {
267
226
  if (depth > 10) return false;
268
227
  if (entry instanceof Uint8Array) {
269
- if (!binary || Object.getPrototypeOf(entry) !== Uint8Array.prototype || ["buffer", "byteLength", "byteOffset", "length"].some((key) => Object.hasOwn(entry, key))) return false;
228
+ if (!binary || Object.getPrototypeOf(entry) !== Uint8Array.prototype || ["buffer", "byteLength", "byteOffset", "length"].some(
229
+ (key) => Object.hasOwn(entry, key)
230
+ ))
231
+ return false;
270
232
  const buffer = entry.buffer;
271
233
  return buffer instanceof ArrayBuffer && !Object.hasOwn(buffer, "byteLength") && buffer.byteLength <= FETCH_CHUNK_BYTES && entry.byteLength > 0 && entry.byteLength <= FETCH_CHUNK_BYTES;
272
234
  }
@@ -280,9 +242,11 @@ function isPageFetchFrame(value) {
280
242
  }
281
243
  if (!entry || typeof entry !== "object") return false;
282
244
  const array2 = Array.isArray(entry);
283
- if (array2 ? Object.getPrototypeOf(entry) !== Array.prototype : ![Object.prototype, null].includes(Object.getPrototypeOf(entry))) return false;
245
+ if (array2 ? Object.getPrototypeOf(entry) !== Array.prototype : ![Object.prototype, null].includes(Object.getPrototypeOf(entry)))
246
+ return false;
284
247
  const keys2 = Reflect.ownKeys(entry);
285
- if (keys2.length > FETCH_METADATA_BYTES || array2 && keys2.length !== entry.length + 1) return false;
248
+ if (keys2.length > FETCH_METADATA_BYTES || array2 && keys2.length !== entry.length + 1)
249
+ return false;
286
250
  return keys2.every((key) => {
287
251
  if (array2 && key === "length") return true;
288
252
  const d = Object.getOwnPropertyDescriptor(entry, key);
@@ -290,7 +254,8 @@ function isPageFetchFrame(value) {
290
254
  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
255
  });
292
256
  };
293
- if (!visit(value, 0) || !value || typeof value !== "object" || Array.isArray(value)) return false;
257
+ if (!visit(value, 0) || !value || typeof value !== "object" || Array.isArray(value))
258
+ return false;
294
259
  const v = value;
295
260
  if (v.protocol !== 2 || typeof v.type !== "string") return false;
296
261
  const fields4 = {
@@ -306,19 +271,28 @@ function isPageFetchFrame(value) {
306
271
  };
307
272
  const required = fields4[v.type];
308
273
  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;
274
+ if (!required || Object.keys(v).length !== required.length + 2 + Number(inline) || !required.every((k) => Object.hasOwn(v, k)))
275
+ return false;
276
+ if (inline && (v.hasBody !== true || typeof v.inlineBody !== "string" || new TextEncoder().encode(v.inlineBody).byteLength > FETCH_INLINE_BODY_BYTES))
277
+ return false;
311
278
  const id3 = (x) => typeof x === "string" && x.length > 0 && x.length <= 128;
312
279
  if (v.type === "fetch-close") return id3(v.connectionId);
313
280
  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;
281
+ if (v.type === "fetch-consumed")
282
+ return v.direction === "download" && Number.isSafeInteger(v.sequence) && v.sequence >= 0;
283
+ if (["fetch-chunk", "fetch-credit", "fetch-end"].includes(v.type) && (!["upload", "download"].includes(v.direction) || !Number.isSafeInteger(v.sequence) || v.sequence < 0))
284
+ return false;
285
+ if (v.type === "fetch-credit")
286
+ return Number.isInteger(v.chunks) && v.chunks > 0 && v.chunks <= FETCH_WINDOW_CHUNKS && v.bytes === v.chunks * FETCH_CHUNK_BYTES;
317
287
  if (v.type === "fetch-chunk") return v.bytes instanceof Uint8Array;
318
288
  if (v.type === "fetch-error") return isAppHostErrorInfo(v.error);
319
289
  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);
290
+ if (!Array.isArray(v.headers) || !v.headers.every(
291
+ (h) => Array.isArray(h) && h.length === 2 && h.every((x) => typeof x === "string")
292
+ ) || typeof v.hasBody !== "boolean")
293
+ return false;
294
+ if (v.type === "fetch-open")
295
+ return id3(v.connectionId) && typeof v.url === "string" && typeof v.method === "string" && /^[A-Za-z0-9!#$%&'*+.^_`|~-]+$/.test(v.method);
322
296
  return Number.isInteger(v.status) && v.status >= 200 && v.status <= 599 && typeof v.statusText === "string";
323
297
  }
324
298
  return true;
@@ -326,17 +300,14 @@ function isPageFetchFrame(value) {
326
300
  function pageFetchPath(baseUrl, input) {
327
301
  if (/[\\\s#]/.test(input)) throw new TypeError("Invalid fetch URL");
328
302
  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");
330
- 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");
332
- return (url.pathname.slice(base.pathname.length) || "/") + url.search;
303
+ if (rawPath.includes("//") || /%(?:2e|2f|5c|25)/i.test(rawPath) || rawPath.split("/").some((p) => p === "." || p === "..") || /[\u0000-\u001f\u007f]/.test(decodeURIComponent(rawPath)))
304
+ throw new TypeError("Ambiguous fetch path");
305
+ const base = new URL(baseUrl), url2 = new URL(input);
306
+ if (base.protocol !== "https:" || base.hostname !== "app-host.invalid" || base.username || base.password || base.search || base.hash || url2.origin !== base.origin || url2.username || url2.password || url2.hash || url2.pathname !== base.pathname && !url2.pathname.startsWith(base.pathname + "/"))
307
+ throw new TypeError("Fetch target mismatch");
308
+ return (url2.pathname.slice(base.pathname.length) || "/") + url2.search;
333
309
  }
334
310
 
335
- // ../domain-contracts/src/app-host/service-host-protocol.ts
336
- var SERVICE_HOST_MAX_FRAME_BYTES = 512 * 1024;
337
- var worktreeBody = { workspaceId: id, expectedHead: text(256), branch: text(1024) };
338
- var worktreeReceipt = object({ requestId: id, state: enumeration("accepted", "completed", "failed", "unknown") }, { result: object({ executionRoot: id, workspaceId: id, branch: text(1024), sourceHead: text(256) }) });
339
-
340
311
  // ../domain-contracts/src/app-host/workspace-conversations.ts
341
312
  var validWorkspaceConversation = (value) => {
342
313
  if (!object(
@@ -375,7 +346,6 @@ var workspaceConversationResult = object({
375
346
  revision: count,
376
347
  session: sessionRecord,
377
348
  operationState: enumeration("prepared", "running", "completed", "failed", "unknown"),
378
- indexBindingPending: (v) => v === true,
379
349
  workspaceId: id,
380
350
  executionRoot: id,
381
351
  privateSessionId: id,
@@ -406,7 +376,6 @@ function validSessionControlInput(method, value) {
406
376
  const target2 = value;
407
377
  return target2.workspaceId !== void 0 ? target2.outsideProject !== true : target2.outsideProject === true;
408
378
  }
409
- if (method === "sessions.bindConversationIndex") return object({ original: validWorkspaceConversation, dataScopeId: text() })(value);
410
379
  if (method === "sessions.createConversation" || method === "sessions.getConversationCreationResult") return validWorkspaceConversation(value);
411
380
  if (method === "sessions.getControls") return object({ connectionId: text(), sessionId: text() })(value);
412
381
  if (!object({ requestId: id, sessionId: text(), original: validSessionControlOriginal }, { connectionId: text() })(value)) return false;
@@ -416,15 +385,95 @@ function validSessionControlInput(method, value) {
416
385
  function validSessionControlResult(method, value) {
417
386
  if (!json(value)) return false;
418
387
  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);
419
- if (method === "sessions.bindConversationIndex") return validWorkspaceConversationResult(value);
420
388
  if (method === "sessions.createConversation" || method === "sessions.getConversationCreationResult")
421
389
  return method === "sessions.getConversationCreationResult" && value === null || validWorkspaceConversationResult(value);
422
- 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);
390
+ 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), plugins: array(object({ id: text(), name: text(), agents: choices })) })(value);
423
391
  if (method === "sessions.getControlResult") return value === null || receipt(value);
424
392
  if (!receipt(value)) return false;
425
393
  return false;
426
394
  }
427
395
 
396
+ // ../domain-contracts/src/app-host/service.ts
397
+ function fields(value, required, optional = []) {
398
+ if (!value || typeof value !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(value)))
399
+ return false;
400
+ return required.every((k) => Object.hasOwn(value, k)) && Reflect.ownKeys(value).every((k) => {
401
+ const d = Object.getOwnPropertyDescriptor(value, k);
402
+ return typeof k === "string" && [...required, ...optional].includes(k) && d.enumerable && Object.hasOwn(d, "value");
403
+ });
404
+ }
405
+ var version = (v) => typeof v === "string" && /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*)?(?:\+[\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*)?$/.test(
406
+ v
407
+ );
408
+ function json2(value, ancestors = /* @__PURE__ */ new Set(), depth = 0) {
409
+ if (depth > 100) return false;
410
+ if (value === null || typeof value === "string" || typeof value === "boolean")
411
+ return true;
412
+ if (typeof value === "number") return Number.isFinite(value);
413
+ if (typeof value !== "object" || ancestors.has(value)) return false;
414
+ const array2 = Array.isArray(value);
415
+ if (array2 ? Object.getPrototypeOf(value) !== Array.prototype || Reflect.ownKeys(value).length !== value.length + 1 : ![Object.prototype, null].includes(Object.getPrototypeOf(value)))
416
+ return false;
417
+ ancestors.add(value);
418
+ const result = Reflect.ownKeys(value).every((k) => {
419
+ if (array2 && k === "length") return true;
420
+ const d = Object.getOwnPropertyDescriptor(value, k);
421
+ return typeof k === "string" && (!array2 || /^(0|[1-9]\d*)$/.test(k) && Number(k) < value.length) && d.enumerable && Object.hasOwn(d, "value") && json2(d.value, ancestors, depth + 1);
422
+ });
423
+ ancestors.delete(value);
424
+ return result;
425
+ }
426
+ function validServiceStatus(value) {
427
+ return fields(value, ["state"], ["reason", "instanceId", "apiVersion"]) && [
428
+ "absent",
429
+ "unauthorized",
430
+ "stopped",
431
+ "starting",
432
+ "recovering",
433
+ "ready",
434
+ "failed"
435
+ ].includes(value.state) && (!Object.hasOwn(value, "reason") || [
436
+ "dependency_missing",
437
+ "service_start_failed",
438
+ "service_unavailable",
439
+ "result_unknown",
440
+ "incompatible",
441
+ "revoked"
442
+ ].includes(value.reason)) && (!Object.hasOwn(value, "instanceId") || typeof value.instanceId === "string" && HOST_REQUEST_ID.test(value.instanceId)) && (!Object.hasOwn(value, "apiVersion") || version(value.apiVersion)) && (value.state !== "ready" || Object.hasOwn(value, "instanceId") && Object.hasOwn(value, "apiVersion"));
443
+ }
444
+ function validWork(value) {
445
+ return fields(value, ["requestId", "state", "updatedAt"], ["result", "error"]) && typeof value.requestId === "string" && HOST_REQUEST_ID.test(value.requestId) && [
446
+ "not_accepted",
447
+ "accepted",
448
+ "running",
449
+ "completed",
450
+ "failed",
451
+ "interrupted",
452
+ "unknown"
453
+ ].includes(value.state) && typeof value.updatedAt === "string" && /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?(?:Z|[+-]\d\d:\d\d)$/.test(
454
+ value.updatedAt
455
+ ) && Number.isFinite(Date.parse(value.updatedAt)) && ["result", "error"].every(
456
+ (k) => !Object.hasOwn(value, k) || json2(value[k]) && new TextEncoder().encode(JSON.stringify(value[k])).length <= 16384
457
+ );
458
+ }
459
+ function validServiceResult(method, value) {
460
+ switch (method) {
461
+ case "service.getStatus":
462
+ return validServiceStatus(value);
463
+ case "service.getConnection":
464
+ return fields(value, ["connectionId", "baseUrl", "apiVersion"]) && typeof value.connectionId === "string" && /^[A-Za-z0-9-]+$/.test(value.connectionId) && value.baseUrl === `https://app-host.invalid/connections/${value.connectionId}` && version(value.apiVersion);
465
+ case "service.getWork":
466
+ return validWork(value);
467
+ case "service.listWork":
468
+ return Array.isArray(value) && value.length <= 5120 && value.every(validWork) && new Set(value.map((w) => w.requestId)).size === value.length;
469
+ case "service.interruptWork":
470
+ return fields(value, ["requested"]) && typeof value.requested === "boolean";
471
+ }
472
+ }
473
+ function validServiceConnectionInput(value) {
474
+ return fields(value, ["apiRange"]) && typeof value.apiRange === "string" && !!value.apiRange.trim() && value.apiRange.length <= 256;
475
+ }
476
+
428
477
  // ../domain-contracts/src/app-host/workspace.ts
429
478
  function fields2(v, required, optional = []) {
430
479
  if (!v || typeof v !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(v))) return false;
@@ -697,8 +746,7 @@ function createResourceCatalogApi(rpc) {
697
746
  // src/session-controls.ts
698
747
  var CONVERSATION_PREPARATION_METHODS = [
699
748
  "sessions.createConversation",
700
- "sessions.getConversationCreationResult",
701
- "sessions.bindConversationIndex"
749
+ "sessions.getConversationCreationResult"
702
750
  ];
703
751
  function isConversationPreparationMethod(method) {
704
752
  return CONVERSATION_PREPARATION_METHODS.includes(method);
@@ -710,18 +758,11 @@ function createConversationPreparationApi(rpc) {
710
758
  const call = async (method, input) => {
711
759
  if (!validSessionControlInput(method, input)) throw new AppHostError("invalid_request");
712
760
  rpc.requireFeature();
713
- const result = await rpc.request(method, input);
714
- if (!validSessionControlResult(method, result)) throw new AppHostError("host_unavailable");
715
- return result;
761
+ return rpc.request(method, input);
716
762
  };
717
763
  return {
718
- createConversation: (input) => call("sessions.createConversation", input),
719
- getConversationCreationResult: (input) => call("sessions.getConversationCreationResult", input),
720
- async bindConversationIndex(input) {
721
- const result = await call("sessions.bindConversationIndex", input);
722
- if (result.dataScopeId !== input.dataScopeId || result.sessionId !== input.original.sessionId || result.requestId !== input.original.requestId || result.state !== "completed") throw new AppHostError("host_unavailable");
723
- return result;
724
- }
764
+ create: (input) => call("sessions.createConversation", input),
765
+ getResult: (input) => call("sessions.getConversationCreationResult", input)
725
766
  };
726
767
  }
727
768
 
@@ -748,10 +789,23 @@ function resolveClientConnection(connection, owner) {
748
789
 
749
790
  // src/desktop.ts
750
791
  var BROWSER_CAPTURE_PREVIEW_MAX_BYTES = 8 * 1024 * 1024;
792
+ var DESKTOP_ADAPTED_METHODS = ["desktop.files.openRead", "desktop.files.getOperation"];
751
793
  var target = { targetId: text(256) };
752
794
  var mount = { ...target, mountId: text(256) };
753
795
  var source = object({ sessionId: text(), appId: text() });
754
796
  var action = { ...mount, source, requestId: id, expectedRevision: count };
797
+ var fileWriteBody = { path: text(32768), expectedSha256: digest, text: text(8 * 1024 * 1024, true) };
798
+ var gitBranchBody = { expectedHead: text(), branch: text() };
799
+ var validFileOperationQuery = object({
800
+ ...target,
801
+ requestId: id,
802
+ original: object({ kind: enumeration("files.writeText"), body: object(fileWriteBody) })
803
+ });
804
+ var validGitOperationQuery = object({
805
+ ...target,
806
+ requestId: id,
807
+ original: object({ kind: enumeration("git.switchBranch", "git.createBranch"), body: object(gitBranchBody) })
808
+ });
755
809
  var page = { ...target, tabId: text(256), pageRevision: count };
756
810
  var mode = enumeration("off", "pick", "review");
757
811
  var voidResult = (v) => v === void 0;
@@ -761,7 +815,7 @@ var annotationFields = { target: text(8192), selector: text(8192), locatorKind:
761
815
  var validBrowserSnapshot = object({ pageUrl: text(16384, true), pageRevision: count, ready: bool, mode, interactionVersion: count, eventSequence: count, selection: nullable(object({ selectionId: text(), target: object(annotationFields), rect })), focusedAnnotationId: nullable(text()), viewport: nullable(object({ width: finite, height: finite })), annotations: array(object({ record: object({ ...annotationFields, id: text(), pageUrl: text(16384, true), comment: text(65536, true) }), status: enumeration("visible", "offscreen", "missing"), rect: nullable(rect) }), 4096) });
762
816
  var root = object({ path: text(32768), identity: object({ dev: text(), ino: text() }) }, { workspaceId: text() });
763
817
  var validDesktopTarget = object({ id: text(), dataScopeId: text(), draftId: text(), draftRevision: count }, { root, sessionId: text() });
764
- var kind = enumeration("files.writeText", "git.switchBranch", "git.createBranch", "git.createTaskWorktree");
818
+ var kind = enumeration("files.writeText", "git.switchBranch", "git.createBranch");
765
819
  var validWorkspaceOperation = object({ requestId: id, kind, state: enumeration("prepared", "running", "completed", "failed", "unknown"), createdAt: count, updatedAt: count }, { result: json, error: object({ code: text(128) }) });
766
820
  var origin = (v) => object({ kind: enumeration("surface"), surfaceId: text() })(v) || object({ kind: enumeration("tool-result"), sourcePartId: text() })(v);
767
821
  var appRecord = object({ id: text(), sessionId: text(), pluginId: text(), pluginVersion: text(), pluginDigest: text(), definitionDigest: text(), backendId: text(), backendKind: enumeration("native-tools", "mcp-server"), resourceUri: text(8192), origin, logicalKey: text(8192), status: enumeration("open", "closed", "revoked"), controlRevision: count, createdAt: count, updatedAt: count }, { activeActionRunId: text(), lastActionRunId: text() });
@@ -784,7 +838,7 @@ var rules = {
784
838
  "desktop.files.search": { input: object({ ...target, query: text(4096, true) }, { directory: text(32768, true), limit: positive }), result: object({ matches: array(object({ path: text(32768), line: count, text: text(65536, true) }), 1e4), truncated: bool }) },
785
839
  "desktop.files.openRead": { input: object({ ...target, path: text(32768) }), result: validConnection },
786
840
  "desktop.files.readText": { input: object({ ...target, path: text(32768) }), result: object({ path: text(32768), text: text(8 * 1024 * 1024, true), sha256: digest, byteLength: count, encoding: enumeration("utf-8"), truncated: bool }) },
787
- "desktop.files.writeText": { input: object({ ...target, requestId: id, path: text(32768), expectedSha256: digest, text: text(8 * 1024 * 1024, true) }), result: validWorkspaceOperation },
841
+ "desktop.files.writeText": { input: object({ ...target, requestId: id, ...fileWriteBody }), result: validWorkspaceOperation },
788
842
  "desktop.files.getOperation": { input: object({ ...target, requestId: id, original: object({ kind, body: json }) }), result: nullable(validWorkspaceOperation) },
789
843
  "desktop.files.revealPath": { input: object({ ...target, path: text(32768) }), result: voidResult },
790
844
  "desktop.files.listOpeners": { input: object(target), result: array(object({ id: text(256), label: text(1024), kind: enumeration("editor", "folder", "terminal"), iconDataUrl: nullable(text(1024 * 1024)) }, { isDefault: bool }), 256) },
@@ -800,9 +854,8 @@ var rules = {
800
854
  "desktop.git.listBranches": { input: object(target), result: object({ branches: array(text(1024), 1e4) }) },
801
855
  "desktop.git.changes": { input: object(target, { range: enumeration("uncommitted", "working", "staged"), ignoreWhitespace: bool }), result: object({ files: array(object({ path: text(32768), status: enumeration("added", "modified", "deleted", "renamed", "copied", "untracked"), additions: nullable(count), deletions: nullable(count), binary: bool }, { oldPath: text(32768) }), 1e4), totalAdditions: count, totalDeletions: count }) },
802
856
  "desktop.git.diff": { input: object(target, { path: text(32768), base: text(), head: text(), range: enumeration("uncommitted", "working", "staged"), ignoreWhitespace: bool }), result: object({ text: text(8 * 1024 * 1024, true), truncated: bool }) },
803
- "desktop.git.switchBranch": { input: object({ ...target, requestId: id, expectedHead: text(), branch: text() }), result: validWorkspaceOperation },
804
- "desktop.git.createBranch": { input: object({ ...target, requestId: id, expectedHead: text(), branch: text() }), result: validWorkspaceOperation },
805
- "desktop.git.createTaskWorktree": { input: object({ ...target, requestId: id, expectedHead: text(), branch: text() }), result: validWorkspaceOperation },
857
+ "desktop.git.switchBranch": { input: object({ ...target, requestId: id, ...gitBranchBody }), result: validWorkspaceOperation },
858
+ "desktop.git.createBranch": { input: object({ ...target, requestId: id, ...gitBranchBody }), result: validWorkspaceOperation },
806
859
  "desktop.terminals.create": { input: object({ ...target, requestId: id, cols: positive, rows: positive }, { name: text(256) }), result: object({ resourceId: text(), terminalId: text(), cwd: text(32768), status: enumeration("running", "exited") }) },
807
860
  "desktop.terminals.list": { input: object(target), result: array(object({ id: text(), name: text(1024, true), scope: (v) => object({ kind: enumeration("session"), sessionId: text() })(v) || object({ kind: enumeration("project"), projectId: text() })(v), runtime: enumeration("local", "environment"), source: enumeration("user", "agent"), status: enumeration("running", "stopping", "completed", "killed", "failed"), cwd: text(32768), shell: text(32768, true), cols: positive, rows: positive, createdAt: text() }, { projectId: text(), sessionId: text(), environmentKind: enumeration("native", "wsl"), distribution: text(), command: text(65536, true), exitedAt: text(), exitCode: nullable(finite) }), 1e4) },
808
861
  "desktop.terminals.restart": { input: object({ ...target, terminalId: text(), requestId: id }), result: object({ resourceId: text(), terminalId: text(), cwd: text(32768), status: enumeration("running", "exited") }) },
@@ -895,24 +948,48 @@ function createAppDesktopApi(rpc, owner, filesFeature = () => {
895
948
  if (!validDesktopResultForInput(method, params, value)) throw new AppHostError("host_unavailable");
896
949
  return value;
897
950
  };
898
- const group = (name2) => Object.fromEntries(DESKTOP_METHODS.filter((m) => m !== "desktop.files.openRead" && m.startsWith(`desktop.${name2}.`)).map((method) => [method.split(".")[2], (params) => call(method, params)]));
899
- return { bindTarget(input) {
900
- if (!object({ draftId: text(), draftRevision: count }, { directory: text(32768), workspaceId: text(), connection: (v) => !!v && typeof v === "object", sessionId: text() })(input)) throw new AppHostError("invalid_request");
901
- const { connection, ...rest } = input;
902
- return call("desktop.bindTarget", { ...rest, ...connection === void 0 ? {} : { connectionId: resolveClientConnection(connection, owner) } });
903
- }, releaseTarget: (input) => call("desktop.releaseTarget", input), files: Object.assign(group("files"), { async readFile(input, options = {}) {
904
- if (!object({ ...target, path: text(32768) }, { range: object({ start: count }, { end: count }) })(input) || input.range?.end !== void 0 && input.range.end < input.range.start) throw new AppHostError("invalid_request");
905
- filesFeature();
906
- const { range: range2, ...params } = input;
907
- const wire = await call("desktop.files.openRead", params);
908
- const fetchFile = owner.fetchFor(wire.connectionId, wire.baseUrl);
909
- try {
910
- return await fetchFile(wire.baseUrl + "/", { ...options.signal ? { signal: options.signal } : {}, ...range2 ? { headers: { Range: `bytes=${range2.start}-${range2.end ?? ""}` } } : {} });
911
- } catch (error) {
912
- owner.close(wire.connectionId);
913
- throw error;
914
- }
915
- } }), clipboard: group("clipboard"), git: group("git"), terminals: group("terminals"), windows: group("windows"), browser: group("browser"), pluginApps: group("pluginApps") };
951
+ const group = (name2) => Object.fromEntries(DESKTOP_METHODS.filter((method) => !DESKTOP_ADAPTED_METHODS.includes(method) && method.startsWith(`desktop.${name2}.`)).map((method) => [method.split(".")[2], (params) => call(method, params)]));
952
+ const getOperation = async (input, validate2) => {
953
+ if (!validate2(input)) throw new AppHostError("invalid_request");
954
+ return call("desktop.files.getOperation", input);
955
+ };
956
+ return {
957
+ bindTarget(input) {
958
+ if (!object({ draftId: text(), draftRevision: count }, { directory: text(32768), workspaceId: text(), connection: (v) => !!v && typeof v === "object", sessionId: text() })(input)) throw new AppHostError("invalid_request");
959
+ const { connection, ...rest } = input;
960
+ return call("desktop.bindTarget", { ...rest, ...connection === void 0 ? {} : { connectionId: resolveClientConnection(connection, owner) } });
961
+ },
962
+ releaseTarget: (input) => call("desktop.releaseTarget", input),
963
+ files: {
964
+ ...group("files"),
965
+ getOperation: (input) => getOperation(input, validFileOperationQuery),
966
+ async readFile(input, options = {}) {
967
+ if (!object({ ...target, path: text(32768) }, { range: object({ start: count }, { end: count }) })(input) || input.range?.end !== void 0 && input.range.end < input.range.start) throw new AppHostError("invalid_request");
968
+ filesFeature();
969
+ const { range: range2, ...params } = input;
970
+ const wire = await call("desktop.files.openRead", params);
971
+ const fetchFile = owner.fetchFor(wire.connectionId, wire.baseUrl);
972
+ try {
973
+ return await fetchFile(wire.baseUrl + "/", {
974
+ ...options.signal ? { signal: options.signal } : {},
975
+ ...range2 ? { headers: { Range: `bytes=${range2.start}-${range2.end ?? ""}` } } : {}
976
+ });
977
+ } catch (error) {
978
+ owner.close(wire.connectionId);
979
+ throw error;
980
+ }
981
+ }
982
+ },
983
+ clipboard: group("clipboard"),
984
+ git: {
985
+ ...group("git"),
986
+ getOperation: (input) => getOperation(input, validGitOperationQuery)
987
+ },
988
+ terminals: group("terminals"),
989
+ windows: group("windows"),
990
+ browser: group("browser"),
991
+ pluginApps: group("pluginApps")
992
+ };
916
993
  }
917
994
  function canonicalDesktopRequest(value) {
918
995
  if (!json(value)) throw new AppHostError("invalid_request");
@@ -932,6 +1009,13 @@ var selection = object({ cwd: text(4096), selectionId: text(256) });
932
1009
  var cancel = object({ selectionId: text(256) });
933
1010
  var name = object({ name: text(256) });
934
1011
  var login = object({ loginId: text(256) });
1012
+ var skillSelection = { id: text(64), version: text(32), sha256: digest };
1013
+ var personalSkillInstall = object({ ...skillSelection, scope: enumeration("personal") });
1014
+ var projectSkillInstall = object({
1015
+ ...skillSelection,
1016
+ scope: enumeration("project"),
1017
+ projectPath: (value) => typeof value === "string" && value.trim().length > 0 && text(4096)(value)
1018
+ });
935
1019
  var EXTENSION_INPUTS = {
936
1020
  context: empty,
937
1021
  "plugins.loadIcon": object({ src: text(8192) }),
@@ -956,6 +1040,8 @@ var EXTENSION_INPUTS = {
956
1040
  "plugins.marketplaceOperation": object({ cwd: text(4096), operationId: text(256) }),
957
1041
  "skills.snapshot": object({ projectPath: text(4096) }),
958
1042
  "skills.remove": object({ id: text(4096), expectedContent: text(8 * 1024 * 1024, true), projectPath: text(4096) }),
1043
+ "skills.marketplaceCatalog": empty,
1044
+ "skills.marketplaceInstall": (value) => personalSkillInstall(value) || projectSkillInstall(value),
959
1045
  "mcp.snapshot": empty,
960
1046
  "mcp.exportConfig": empty,
961
1047
  "mcp.getConfig": name,
@@ -991,12 +1077,94 @@ function validProjectRequest(value) {
991
1077
  case "archive":
992
1078
  return object({ action: (v) => v === "archive", ...project })(value);
993
1079
  case "rebind":
994
- return object({ action: (v) => v === "rebind", ...scope, workspaceId: id2, previousWorkspaceId: id2 }, { projectId: id2, previousPath: text(32768) })(value);
1080
+ return object({ action: (v) => v === "rebind", ...project, previousWorkspaceId: id2, expectedPath: text(32768) })(value);
995
1081
  default:
996
1082
  return false;
997
1083
  }
998
1084
  }
999
- var validProjectSnapshot = (value) => object({ dataScopeId: id2, projects: array(object({ workspaceId: id2, name: text(1024), path: text(32768), available: bool, lastOpenedAt: count }, { projectId: id2, defaultShell: text(4096) }), 1e4) })(value);
1085
+ var validProjectSnapshot = (value) => object({
1086
+ dataScopeId: id2,
1087
+ projects: array(object({ workspaceId: id2, projectId: id2, name: text(1024), path: text(32768), available: bool, lastOpenedAt: count }, {
1088
+ defaultShell: text(4096),
1089
+ rootIdentity: object({ dev: text(32), ino: text(32) })
1090
+ }), 1e4)
1091
+ }, { selectedWorkspaceId: id2 })(value);
1092
+
1093
+ // src/local-workspace.ts
1094
+ var root2 = { rootPath: text(32768) };
1095
+ var identity = { identity: object({ dev: text(32), ino: text(32) }) };
1096
+ var file = { ...root2, path: text(32768) };
1097
+ var write = { ...file, requestId: id, content: text(125e4, true), originalContent: text(125e4, true) };
1098
+ var actionOf = (value) => value && typeof value === "object" ? Object.getOwnPropertyDescriptor(value, "action")?.value : void 0;
1099
+ function validLocalWorkspaceRequest(value) {
1100
+ const action2 = actionOf(value);
1101
+ const field = { action: enumeration(action2) };
1102
+ switch (action2) {
1103
+ case "pick":
1104
+ case "listOpeners":
1105
+ return object(field)(value);
1106
+ case "list":
1107
+ return object({ ...field, ...root2 }, { ...identity, path: text(32768, true) })(value);
1108
+ case "find":
1109
+ return object({ ...field, ...root2, query: text(1024) }, identity)(value);
1110
+ case "write":
1111
+ case "getWrite":
1112
+ return object({ ...field, ...write }, identity)(value);
1113
+ case "openWith":
1114
+ return object({ ...field, ...file, openerId: text(256) }, identity)(value);
1115
+ case "copyPath":
1116
+ return object({ ...field, ...file }, { ...identity, absolute: bool })(value);
1117
+ case "read":
1118
+ case "reveal":
1119
+ case "webPreview":
1120
+ return object({ ...field, ...file }, identity)(value);
1121
+ default:
1122
+ return false;
1123
+ }
1124
+ }
1125
+ var bytes = (limit) => (value) => value instanceof ArrayBuffer && value.byteLength <= limit;
1126
+ var preview = object({
1127
+ path: text(32768),
1128
+ name: text(32768),
1129
+ language: text(4096),
1130
+ size: count,
1131
+ binary: bool,
1132
+ content: nullable(text(125e4, true)),
1133
+ scope: enumeration("project", "extra-root"),
1134
+ relativePath: text(32768),
1135
+ rootLabel: text(32768),
1136
+ previewBytes: nullable(bytes(50 * 1024 * 1024)),
1137
+ mediaType: enumeration(null, "image/avif", "image/bmp", "image/gif", "image/jpeg", "image/png", "image/webp"),
1138
+ imagePreviewError: enumeration(null, "image_too_large", "image_unsupported")
1139
+ }, {
1140
+ rootIdentity: identity.identity,
1141
+ documentPreview: object({ format: enumeration("pdf", "epub", "docx", "xlsx", "pptx"), bytes: bytes(64 * 1024 * 1024) })
1142
+ });
1143
+ var tree = object({
1144
+ ...root2,
1145
+ entries: array(object({ path: text(32768), type: enumeration("file", "directory") }, { size: count }), 1e4)
1146
+ }, { truncated: bool });
1147
+ var found = object({ files: array(text(32768), 1e3), truncated: bool });
1148
+ var picked = object({ ...root2, ...identity, workspaceId: id });
1149
+ var url = object({ url: text(131072) });
1150
+ var openers = (value) => validDesktopResult("desktop.files.listOpeners", value);
1151
+ var empty2 = (value) => value === void 0;
1152
+ var checks = {
1153
+ pick: nullable(picked),
1154
+ list: tree,
1155
+ find: found,
1156
+ read: preview,
1157
+ write: preview,
1158
+ getWrite: nullable(preview),
1159
+ reveal: empty2,
1160
+ openWith: empty2,
1161
+ copyPath: empty2,
1162
+ listOpeners: openers,
1163
+ webPreview: url
1164
+ };
1165
+ function validLocalWorkspaceResult(value, action2) {
1166
+ return action2 ? checks[action2](value) : Object.values(checks).some((check) => check(value));
1167
+ }
1000
1168
 
1001
1169
  // ../domain-contracts/src/app-host/model-providers.ts
1002
1170
  var provider = text(256);
@@ -1019,7 +1187,7 @@ var customProvider = object({
1019
1187
  models: array(object({ id: text(1024), displayName: text(1024) }, { imageInputSupport, ...limits }), 16384)
1020
1188
  }, { apiKey: text(8192), headers, secretHeaders });
1021
1189
  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);
1190
+ 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
1191
  }
1024
1192
  var validModel = object({ id: text(1024), label: text(1024) }, { imageInputSupport, declaredLimits: object({}, limits) });
1025
1193
  var validConnection2 = object({
@@ -1036,8 +1204,9 @@ function validModelProviderConnections(value) {
1036
1204
  var modelId = text(1024);
1037
1205
  var effort = nullable(text(256));
1038
1206
  var revision = text(8192);
1207
+ var accountGatewayProof = (value) => typeof value === "string" && /^[a-f0-9]{64}$/.test(value);
1039
1208
  function validProviderDefaultsRequest(value) {
1040
- return object({ action: enumeration("snapshot") })(value) || object({ action: enumeration("updateModel"), model: modelId }, { provider, effort, expectedRevision: revision })(value) || object({ action: enumeration("updateEffort"), effort, expectedRevision: revision })(value) || object({ action: enumeration("test"), provider, model: modelId })(value);
1209
+ return object({ action: enumeration("snapshot") }, { accountGatewayProof })(value) || object({ action: enumeration("updateModel"), model: modelId }, { provider, effort, expectedRevision: revision })(value) || object({ action: enumeration("updateEffort"), effort, expectedRevision: revision })(value) || object({ action: enumeration("test"), provider, model: modelId })(value);
1041
1210
  }
1042
1211
  var verifiedProvider = object({ model: modelId, checkedAt: count });
1043
1212
  var verified = (value) => {
@@ -1061,7 +1230,7 @@ var validProviderDefaultsSnapshot = object({
1061
1230
  verified,
1062
1231
  fastModeAvailable: enumeration(false),
1063
1232
  fastModeReason: text(1024)
1064
- });
1233
+ }, { accountGatewayMatches: bool });
1065
1234
  var validProviderConnectionTestResult = object({
1066
1235
  status: enumeration("verified", "failed"),
1067
1236
  detail: text(8192),
@@ -1108,6 +1277,7 @@ var SYSTEM_SHORTCUT_IDS = [
1108
1277
  ];
1109
1278
  var SYSTEM_METHODS = [
1110
1279
  "system.projects",
1280
+ "system.workspace",
1111
1281
  "system.extensions",
1112
1282
  "system.modelProviders",
1113
1283
  "system.providerDefaults",
@@ -1117,7 +1287,6 @@ var SYSTEM_METHODS = [
1117
1287
  "system.setWindowMaterial",
1118
1288
  "system.copyText",
1119
1289
  "system.openExternal",
1120
- "system.markSessionRead",
1121
1290
  "system.navigationReady",
1122
1291
  "system.completeNavigation"
1123
1292
  ];
@@ -1206,6 +1375,8 @@ function validSystemInput(method, value) {
1206
1375
  switch (method) {
1207
1376
  case "system.projects":
1208
1377
  return validProjectRequest(value);
1378
+ case "system.workspace":
1379
+ return validLocalWorkspaceRequest(value);
1209
1380
  case "system.extensions":
1210
1381
  return validExtensionRequest(value);
1211
1382
  case "system.modelProviders":
@@ -1237,12 +1408,6 @@ function validSystemInput(method, value) {
1237
1408
  page: enumeration("session-settings"),
1238
1409
  target: validSessionSettingsTarget
1239
1410
  })(value);
1240
- case "system.markSessionRead":
1241
- return object({
1242
- connectionId: text(256),
1243
- sessionId: text(256),
1244
- throughSeq: count
1245
- })(value);
1246
1411
  case "system.completeNavigation":
1247
1412
  return object({
1248
1413
  id: text(256),
@@ -1261,6 +1426,8 @@ function validSystemResult(method, value) {
1261
1426
  switch (method) {
1262
1427
  case "system.projects":
1263
1428
  return validProjectSnapshot(value);
1429
+ case "system.workspace":
1430
+ return validLocalWorkspaceResult(value);
1264
1431
  case "system.extensions":
1265
1432
  return validExtensionResult(value);
1266
1433
  case "system.modelProviders":
@@ -1301,6 +1468,11 @@ function createAppSystemApi(requester, connectionOwner) {
1301
1468
  }
1302
1469
  return {
1303
1470
  projects: (input) => send("system.projects", input),
1471
+ workspace: (async (input) => {
1472
+ const result = await send("system.workspace", input);
1473
+ if (!validLocalWorkspaceResult(result, input.action)) throw new AppHostError("host_unavailable");
1474
+ return result;
1475
+ }),
1304
1476
  extensions: (input) => send("system.extensions", input),
1305
1477
  modelProviders: (input) => send("system.modelProviders", input),
1306
1478
  providerDefaults: (async (input) => {
@@ -1328,40 +1500,63 @@ function createAppSystemApi(requester, connectionOwner) {
1328
1500
  setTheme: (theme) => send("system.setTheme", { theme }),
1329
1501
  setWindowMaterial: (preference) => send("system.setWindowMaterial", { preference }),
1330
1502
  copyText: (text2) => send("system.copyText", { text: text2 }),
1331
- openExternal: (url) => send("system.openExternal", { url }),
1332
- markSessionRead: ({ connection, sessionId, throughSeq }) => send("system.markSessionRead", {
1333
- connectionId: resolveClientConnection(connection, connectionOwner),
1334
- sessionId,
1335
- throughSeq
1336
- }),
1503
+ openExternal: (url2) => send("system.openExternal", { url: url2 }),
1337
1504
  navigationReady: () => send("system.navigationReady", {}),
1338
1505
  completeNavigation: (input) => send("system.completeNavigation", input)
1339
1506
  };
1340
1507
  }
1341
1508
 
1342
1509
  // src/window.ts
1343
- var WINDOW_METHODS = ["window.getState", "window.minimize", "window.toggleMaximize", "window.requestClose", "window.openHost", "window.reportStartup"];
1510
+ var WINDOW_METHODS = [
1511
+ "window.getState",
1512
+ "window.checkForUpdates",
1513
+ "window.minimize",
1514
+ "window.toggleMaximize",
1515
+ "window.requestClose",
1516
+ "window.openHost",
1517
+ "window.reportStartup"
1518
+ ];
1344
1519
  var finite2 = (value) => typeof value === "number" && Number.isFinite(value);
1345
1520
  var material = object({
1346
1521
  preference: enumeration("glass", "opaque"),
1347
1522
  active: enumeration("glass", "opaque"),
1348
1523
  shell: enumeration("solid", "translucent", "transparent"),
1349
- unavailableReason: nullable(enumeration("unsupported-platform", "unsupported-system", "reduced-transparency", "material-error"))
1524
+ unavailableReason: nullable(
1525
+ enumeration(
1526
+ "unsupported-platform",
1527
+ "unsupported-system",
1528
+ "reduced-transparency",
1529
+ "material-error"
1530
+ )
1531
+ )
1350
1532
  });
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
1533
+ var validUpdateState = (value) => object({ status: enumeration("idle", "checking", "error") })(value) || object({
1534
+ status: enumeration("available", "downloaded"),
1535
+ version: text(128)
1536
+ })(value) || object({
1537
+ status: enumeration("downloading"),
1538
+ version: text(128),
1539
+ percent: (value2) => finite2(value2) && value2 >= 0 && value2 <= 100
1357
1540
  })(value);
1541
+ var validAppWindowState = (value) => object(
1542
+ {
1543
+ platform: enumeration("win32", "darwin", "linux"),
1544
+ maximized: bool,
1545
+ titleBar: enumeration("host", "custom", "native"),
1546
+ trafficLightInset: (value2) => finite2(value2) && value2 >= 0,
1547
+ material
1548
+ },
1549
+ { update: validUpdateState }
1550
+ )(value);
1358
1551
  function isWindowMethod(value) {
1359
1552
  return WINDOW_METHODS.includes(value);
1360
1553
  }
1361
1554
  function validWindowInput(method, value) {
1362
1555
  switch (method) {
1363
1556
  case "window.openHost":
1364
- return object({ page: enumeration("manage", "settings", "about", "recovery") })(value);
1557
+ return object({
1558
+ page: enumeration("manage", "settings", "about", "recovery")
1559
+ })(value);
1365
1560
  case "window.reportStartup":
1366
1561
  return object({ status: enumeration("ready") })(value) || object({ status: enumeration("failed"), message: text(2048) })(value);
1367
1562
  default:
@@ -1372,20 +1567,29 @@ function validWindowResult(method, value) {
1372
1567
  switch (method) {
1373
1568
  case "window.getState":
1374
1569
  return validAppWindowState(value);
1570
+ case "window.checkForUpdates":
1571
+ return validUpdateState(value) || object({ status: enumeration("unsupported") })(value);
1375
1572
  default:
1376
1573
  return value === void 0;
1377
1574
  }
1378
1575
  }
1379
1576
  function validWindowEvent(value) {
1380
- return object({ type: enumeration("window-state-changed"), state: validAppWindowState })(value);
1577
+ return object({
1578
+ type: enumeration("window-state-changed"),
1579
+ state: validAppWindowState
1580
+ })(value);
1381
1581
  }
1382
1582
  function createAppWindowApi(requester) {
1383
1583
  async function send(method, params) {
1384
1584
  requester.requireFeature();
1385
- if (!validWindowInput(method, params)) throw new AppHostError("invalid_request");
1585
+ if (method === "window.checkForUpdates")
1586
+ requester.requireFeature("window-update-check-v1");
1587
+ if (!validWindowInput(method, params))
1588
+ throw new AppHostError("invalid_request");
1386
1589
  return requester.request(method, params);
1387
1590
  }
1388
1591
  return {
1592
+ checkForUpdates: () => send("window.checkForUpdates", {}),
1389
1593
  getState: () => send("window.getState", {}),
1390
1594
  minimize: () => send("window.minimize", {}),
1391
1595
  toggleMaximize: () => send("window.toggleMaximize", {}),
@@ -1394,7 +1598,8 @@ function createAppWindowApi(requester) {
1394
1598
  reportStartup: (input) => send("window.reportStartup", input),
1395
1599
  onStateChanged: (listener) => {
1396
1600
  requester.requireFeature();
1397
- if (typeof listener !== "function") throw new AppHostError("invalid_request");
1601
+ if (typeof listener !== "function")
1602
+ throw new AppHostError("invalid_request");
1398
1603
  return requester.onEvent((event) => {
1399
1604
  if (event.type === "window-state-changed") listener(event.state);
1400
1605
  });
@@ -1458,22 +1663,51 @@ function createAppAuxiliarySessionsApi(rpc, streams) {
1458
1663
  const { connection, ...rest } = input;
1459
1664
  return { ...rest, connectionId: resolveClientConnection(connection, streams) };
1460
1665
  };
1461
- return { getAuxiliaryOptions: (input) => request("sessions.getAuxiliaryOptions", { sessionId: input.sessionId, connectionId: resolveClientConnection(input.connection, streams) }), async openAuxiliary(input) {
1462
- const wire = await request("sessions.openAuxiliary", resolve(input));
1463
- return { leaseId: wire.receipt.leaseId, sessionId: wire.receipt.sessionId, connection: createClientConnection(wire, streams) };
1464
- }, getAuxiliary: (input) => request("sessions.getAuxiliary", resolve(input)), closeAuxiliary: (input) => request("sessions.closeAuxiliary", resolve(input)) };
1666
+ return {
1667
+ getOptions: (input) => request("sessions.getAuxiliaryOptions", {
1668
+ sessionId: input.sessionId,
1669
+ connectionId: resolveClientConnection(input.connection, streams)
1670
+ }),
1671
+ async open(input) {
1672
+ const wire = await request("sessions.openAuxiliary", resolve(input));
1673
+ return { leaseId: wire.receipt.leaseId, sessionId: wire.receipt.sessionId, connection: createClientConnection(wire, streams) };
1674
+ },
1675
+ get: (input) => request("sessions.getAuxiliary", resolve(input)),
1676
+ close: (input) => request("sessions.closeAuxiliary", resolve(input))
1677
+ };
1465
1678
  }
1466
1679
 
1467
1680
  // src/workspace.ts
1681
+ var validPickOptions = object({}, { requestId: (value) => value === void 0 || id(value) });
1468
1682
  function createAppWorkspaceApi(input) {
1469
1683
  async function call(method, params) {
1470
1684
  if (!validWorkspaceInput(method, params)) throw new AppHostError("invalid_request");
1471
1685
  input.requireFeature();
1472
- const value = await input.request(method, params);
1473
- if (!validWorkspaceResult(method, value)) throw new AppHostError("host_unavailable");
1474
- return value;
1686
+ return input.request(method, params);
1687
+ }
1688
+ function bindDirectory({ id: id3, displayName }) {
1689
+ return {
1690
+ id: id3,
1691
+ displayName,
1692
+ listFiles: ({ directory = "", cursor: cursor2 } = {}) => call("workspace.listFiles", {
1693
+ workspaceId: id3,
1694
+ directory,
1695
+ ...cursor2 === void 0 ? {} : { cursor: cursor2 }
1696
+ }),
1697
+ readText: (path) => call("workspace.readText", { workspaceId: id3, path })
1698
+ };
1475
1699
  }
1476
- 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) };
1700
+ return {
1701
+ async pick(options = {}) {
1702
+ if (!validPickOptions(options)) throw new AppHostError("invalid_request");
1703
+ const selected = await call("workspace.select", { requestId: options.requestId ?? crypto.randomUUID() });
1704
+ return selected === null ? null : bindDirectory(selected);
1705
+ },
1706
+ async open(id3) {
1707
+ return bindDirectory(await call("workspace.get", { workspaceId: id3 }));
1708
+ },
1709
+ getSelection: (x) => call("workspace.getSelection", x)
1710
+ };
1477
1711
  }
1478
1712
 
1479
1713
  // src/session-resources.ts
@@ -1494,7 +1728,6 @@ function createAppSessionsApi(input, streams) {
1494
1728
  if (args.length !== 0) throw new AppHostError("invalid_request");
1495
1729
  input.requireFeature();
1496
1730
  const wire = await input.request("sessions.getConnection", {});
1497
- if (!validSessionResourceResult("sessions.getConnection", wire)) throw new AppHostError("host_unavailable");
1498
1731
  return createClientConnection(wire, streams);
1499
1732
  }
1500
1733
  };
@@ -1502,12 +1735,7 @@ function createAppSessionsApi(input, streams) {
1502
1735
 
1503
1736
  // src/service.ts
1504
1737
  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
- };
1738
+ const request = async (method, params) => rpc.request(method, params);
1511
1739
  const work = (method, requestId) => {
1512
1740
  if (typeof requestId !== "string" || !HOST_REQUEST_ID.test(requestId))
1513
1741
  return Promise.reject(new AppHostError("invalid_request"));
@@ -1755,10 +1983,10 @@ function createPageFetchClient(options) {
1755
1983
  s.wake = void 0;
1756
1984
  if (s.stopped) return;
1757
1985
  }
1758
- const bytes = new Uint8Array(item.value.subarray(offset, offset + FETCH_CHUNK_BYTES));
1986
+ const bytes2 = new Uint8Array(item.value.subarray(offset, offset + FETCH_CHUNK_BYTES));
1759
1987
  s.credit--;
1760
- offset += bytes.byteLength;
1761
- send({ protocol: 2, type: "fetch-chunk", id: s.id, direction: "upload", sequence: s.uploadSequence++, bytes });
1988
+ offset += bytes2.byteLength;
1989
+ send({ protocol: 2, type: "fetch-chunk", id: s.id, direction: "upload", sequence: s.uploadSequence++, bytes: bytes2 });
1762
1990
  if (s.stopped || closed) return;
1763
1991
  touch(s);
1764
1992
  }
@@ -1946,13 +2174,18 @@ function createPageFetchClient(options) {
1946
2174
  }
1947
2175
 
1948
2176
  // src/connection.ts
2177
+ var SKILL_MARKETPLACE_TIMEOUT_MS = 3e5;
1949
2178
  var failure = (code) => new AppHostError(code);
1950
2179
  var hostFailure = (reason, requestId) => {
1951
2180
  const details = { reason };
1952
- return new AppHostError("host_unavailable", appHostErrorMessage("host_unavailable", details), {
1953
- details,
1954
- ...requestId === void 0 ? {} : { requestId }
1955
- });
2181
+ return new AppHostError(
2182
+ "host_unavailable",
2183
+ appHostErrorMessage("host_unavailable", details),
2184
+ {
2185
+ details,
2186
+ ...requestId === void 0 ? {} : { requestId }
2187
+ }
2188
+ );
1956
2189
  };
1957
2190
  function record(value) {
1958
2191
  return value !== null && typeof value === "object" && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
@@ -1960,10 +2193,13 @@ function record(value) {
1960
2193
  function keys(value, required, optional = []) {
1961
2194
  if (!record(value)) return false;
1962
2195
  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"));
2196
+ return required.every((k) => Object.hasOwn(value, k)) && own.every(
2197
+ (k) => typeof k === "string" && (required.includes(k) || optional.includes(k)) && Object.getOwnPropertyDescriptor(value, k)?.enumerable && Object.hasOwn(Object.getOwnPropertyDescriptor(value, k), "value")
2198
+ );
1964
2199
  }
1965
2200
  function dataArray(value) {
1966
- if (!Array.isArray(value) || Object.getPrototypeOf(value) !== Array.prototype || Reflect.ownKeys(value).length !== value.length + 1) return false;
2201
+ if (!Array.isArray(value) || Object.getPrototypeOf(value) !== Array.prototype || Reflect.ownKeys(value).length !== value.length + 1)
2202
+ return false;
1967
2203
  for (let i = 0; i < value.length; i++) {
1968
2204
  const d = Object.getOwnPropertyDescriptor(value, String(i));
1969
2205
  if (!d?.enumerable || !Object.hasOwn(d, "value")) return false;
@@ -1974,10 +2210,13 @@ function nonempty(value) {
1974
2210
  return typeof value === "string" && value.length > 0;
1975
2211
  }
1976
2212
  function json3(value, ancestors = /* @__PURE__ */ new Set()) {
1977
- if (value === null || typeof value === "string" || typeof value === "boolean") return true;
2213
+ if (value === null || typeof value === "string" || typeof value === "boolean")
2214
+ return true;
1978
2215
  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;
2216
+ if (typeof value !== "object" || !record(value) && !Array.isArray(value) || ancestors.has(value))
2217
+ return false;
2218
+ if (Array.isArray(value) && (Object.getPrototypeOf(value) !== Array.prototype || Reflect.ownKeys(value).length !== value.length + 1))
2219
+ return false;
1981
2220
  ancestors.add(value);
1982
2221
  try {
1983
2222
  return Reflect.ownKeys(value).every((k) => {
@@ -1992,14 +2231,49 @@ function json3(value, ancestors = /* @__PURE__ */ new Set()) {
1992
2231
  function payloadSize(value) {
1993
2232
  if (value instanceof Uint8Array) return value.byteLength;
1994
2233
  if (record(value) && value.bytes instanceof Uint8Array) {
1995
- const { bytes, ...metadata } = value;
1996
- return bytes.byteLength + new TextEncoder().encode(JSON.stringify(metadata)).byteLength;
2234
+ const { bytes: bytes2, ...metadata } = value;
2235
+ return bytes2.byteLength + new TextEncoder().encode(JSON.stringify(metadata)).byteLength;
1997
2236
  }
1998
2237
  if (!json3(value)) throw failure("invalid_request");
1999
2238
  return new TextEncoder().encode(JSON.stringify(value)).byteLength;
2000
2239
  }
2240
+ function responsePayloadFits(method, value) {
2241
+ if (value === void 0) return true;
2242
+ if (method === "system.workspace" && record(value)) {
2243
+ const { previewBytes, documentPreview, ...metadata } = value;
2244
+ const image = previewBytes instanceof ArrayBuffer;
2245
+ const document = record(documentPreview) && documentPreview.bytes instanceof ArrayBuffer;
2246
+ if (image || document) {
2247
+ return !(image && document) && payloadSize({
2248
+ ...metadata,
2249
+ ...document ? { documentPreview: { format: documentPreview.format } } : {}
2250
+ }) <= APP_HOST_MAX_PAYLOAD_BYTES;
2251
+ }
2252
+ }
2253
+ return payloadSize(value) <= APP_HOST_MAX_PAYLOAD_BYTES;
2254
+ }
2001
2255
  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"));
2256
+ return keys(value, [
2257
+ "appId",
2258
+ "appVersion",
2259
+ "installationId",
2260
+ "hostVersion",
2261
+ "hostApiVersion",
2262
+ "uiType",
2263
+ "theme",
2264
+ "locale",
2265
+ "capabilities",
2266
+ "storageQuotaBytes"
2267
+ ]) && [
2268
+ "appId",
2269
+ "appVersion",
2270
+ "installationId",
2271
+ "hostVersion",
2272
+ "hostApiVersion",
2273
+ "locale"
2274
+ ].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(
2275
+ (c) => keys(c, ["granted"], ["reason"]) && typeof c.granted === "boolean" && (!Object.hasOwn(c, "reason") || typeof c.reason === "string")
2276
+ );
2003
2277
  }
2004
2278
  function validEvent(value) {
2005
2279
  if (!record(value)) return false;
@@ -2024,19 +2298,27 @@ function validEvent(value) {
2024
2298
  }
2025
2299
  function validResult(method, value) {
2026
2300
  if (isCommandsMethod(method)) return validCommandReceipt(value);
2027
- if (isResourceCatalogMethod(method)) return validResourceCatalogResult(method, value);
2301
+ if (isResourceCatalogMethod(method))
2302
+ return validResourceCatalogResult(method, value);
2028
2303
  if (isSystemMethod(method)) return validSystemResult(method, value);
2029
2304
  if (isWindowMethod(method)) return validWindowResult(method, value);
2030
2305
  if (isDesktopMethod(method)) return validDesktopResult(method, value);
2031
- if (method === "attachments.getConnection") return validAttachmentsResult(value);
2306
+ if (method === "attachments.getConnection")
2307
+ return validAttachmentsResult(value);
2032
2308
  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);
2309
+ if (isConversationPreparationMethod(method))
2310
+ return validConversationPreparationResult(method, value);
2311
+ if (method.startsWith("sessions."))
2312
+ return validSessionResourceResult(method, value);
2313
+ if (method.startsWith("workspace."))
2314
+ return validWorkspaceResult(method, value);
2315
+ if (method.startsWith("service."))
2316
+ return validServiceResult(method, value);
2037
2317
  switch (method) {
2038
2318
  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));
2319
+ 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(
2320
+ (f) => APP_HOST_FEATURES.includes(f)
2321
+ );
2040
2322
  case "connect":
2041
2323
  case "getContext":
2042
2324
  return validContext(value);
@@ -2057,7 +2339,10 @@ var DocumentConnection = class {
2057
2339
  this.page = page2;
2058
2340
  page2.addEventListener("message", this.receivePort);
2059
2341
  page2.addEventListener("pagehide", this.pagehide, { once: true });
2060
- page2.postMessage({ type: APP_HOST_READY, protocol: APP_HOST_PROTOCOL }, "*");
2342
+ page2.postMessage(
2343
+ { type: APP_HOST_READY, protocol: APP_HOST_PROTOCOL },
2344
+ "*"
2345
+ );
2061
2346
  }
2062
2347
  page;
2063
2348
  port;
@@ -2086,7 +2371,7 @@ var DocumentConnection = class {
2086
2371
  allowsInlineBody: () => this.features.has("fetch-inline-body-v1"),
2087
2372
  allowsTargetClose: () => this.features.has("fetch-target-close-v1"),
2088
2373
  send: (frame) => {
2089
- this.requireFeature("fetch-v2");
2374
+ this.requireFeature("fetch-v1");
2090
2375
  this.port.postMessage(frame);
2091
2376
  },
2092
2377
  onMessage: (listener) => {
@@ -2108,7 +2393,8 @@ var DocumentConnection = class {
2108
2393
  }
2109
2394
  pagehide = () => this.close(failure("connection_revoked"));
2110
2395
  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;
2396
+ 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)
2397
+ return;
2112
2398
  const port = event.ports[0];
2113
2399
  if (this.port || this.closed) {
2114
2400
  if (port !== this.port) port.close();
@@ -2153,26 +2439,33 @@ var DocumentConnection = class {
2153
2439
  const frameType = Object.getOwnPropertyDescriptor(data, "type")?.value;
2154
2440
  if (typeof frameType === "string" && frameType.startsWith("fetch-")) {
2155
2441
  if (!isPageFetchFrame(data)) throw failure("host_unavailable");
2156
- this.requireFeature("fetch-v2");
2442
+ this.requireFeature("fetch-v1");
2157
2443
  for (const listener of this.fetchListeners) listener(data);
2158
2444
  return;
2159
2445
  }
2160
- if (data.protocol !== APP_HOST_PROTOCOL) throw failure("host_unavailable");
2446
+ if (data.protocol !== APP_HOST_PROTOCOL)
2447
+ throw failure("host_unavailable");
2161
2448
  if (typeof data.type === "string" && data.type.startsWith("lifecycle-")) {
2162
2449
  this.requireFeature("lifecycle-v1");
2163
- if (!isAppLifecycleFrame(data) || data.type === "lifecycle-result") throw failure("host_unavailable");
2450
+ if (!isAppLifecycleFrame(data) || data.type === "lifecycle-result")
2451
+ throw failure("host_unavailable");
2164
2452
  this.lifecycle.receive(data);
2165
2453
  return;
2166
2454
  }
2167
2455
  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");
2456
+ 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)
2457
+ throw failure("host_unavailable");
2169
2458
  if (data.sequence <= this.sequence) return;
2170
- if (data.sequence !== this.sequence + 1) throw failure("host_unavailable");
2459
+ if (data.sequence !== this.sequence + 1)
2460
+ throw failure("host_unavailable");
2171
2461
  this.sequence = data.sequence;
2172
2462
  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");
2463
+ if (appEvent.type === "command-invoked")
2464
+ this.requireFeature("commands-v1");
2465
+ if (appEvent.type === "resources-changed")
2466
+ this.requireFeature("resource-catalog-v1");
2467
+ if (appEvent.type === "service-changed")
2468
+ this.requireFeature("service-v1");
2176
2469
  if (validDesktopEvent(appEvent)) {
2177
2470
  this.requireFeature("trusted-desktop-v1");
2178
2471
  if (appEvent.type === "browser-changed" && appEvent.invalidated)
@@ -2181,7 +2474,8 @@ var DocumentConnection = class {
2181
2474
  if (validSystemEvent(appEvent)) this.requireFeature("system-ui-v1");
2182
2475
  if (validWindowEvent(appEvent)) this.requireFeature("window-chrome-v1");
2183
2476
  const observers = [...this.listeners];
2184
- if (appEvent.type === "connection-revoked") this.close(failure("connection_revoked"));
2477
+ if (appEvent.type === "connection-revoked")
2478
+ this.close(failure("connection_revoked"));
2185
2479
  for (const listener of observers) {
2186
2480
  try {
2187
2481
  listener(appEvent);
@@ -2190,17 +2484,27 @@ var DocumentConnection = class {
2190
2484
  }
2191
2485
  return;
2192
2486
  }
2193
- if (data.type !== "response" || typeof data.id !== "string") throw failure("host_unavailable");
2487
+ if (data.type !== "response" || typeof data.id !== "string")
2488
+ throw failure("host_unavailable");
2194
2489
  const p = this.pending.get(data.id);
2195
2490
  if (!p) return;
2196
2491
  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");
2492
+ if (!keys(data, ["protocol", "type", "id", "ok"], ["value"]) || !validResult(p.method, data.value) || !responsePayloadFits(p.method, data.value))
2493
+ throw failure("host_unavailable");
2198
2494
  clearTimeout(p.timer);
2199
2495
  this.pending.delete(data.id);
2200
2496
  p.resolve(data.value);
2201
2497
  } 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 } });
2498
+ if (!keys(data, ["protocol", "type", "id", "ok", "error"]) || data.ok !== false || !isAppHostErrorInfo(data.error) || payloadSize(data.error) > APP_HOST_MAX_PAYLOAD_BYTES)
2499
+ throw failure("host_unavailable");
2500
+ const error = new AppHostError(
2501
+ data.error.code,
2502
+ appHostErrorMessage(data.error.code, data.error.details),
2503
+ {
2504
+ ...data.error.requestId === void 0 ? {} : { requestId: data.error.requestId },
2505
+ ...data.error.details === void 0 ? {} : { details: data.error.details }
2506
+ }
2507
+ );
2204
2508
  clearTimeout(p.timer);
2205
2509
  this.pending.delete(data.id);
2206
2510
  p.reject(error);
@@ -2213,13 +2517,16 @@ var DocumentConnection = class {
2213
2517
  if (this.closed) return Promise.reject(this.closed);
2214
2518
  if (this.port) return Promise.resolve();
2215
2519
  return new Promise((resolve, reject) => {
2216
- const waiter = { resolve: () => {
2217
- clearTimeout(timer);
2218
- resolve();
2219
- }, reject: (error) => {
2220
- clearTimeout(timer);
2221
- reject(error);
2222
- } };
2520
+ const waiter = {
2521
+ resolve: () => {
2522
+ clearTimeout(timer);
2523
+ resolve();
2524
+ },
2525
+ reject: (error) => {
2526
+ clearTimeout(timer);
2527
+ reject(error);
2528
+ }
2529
+ };
2223
2530
  const timer = setTimeout(() => {
2224
2531
  this.waiting.delete(waiter);
2225
2532
  reject(hostFailure("host_port_timeout"));
@@ -2230,53 +2537,117 @@ var DocumentConnection = class {
2230
2537
  async connect(params) {
2231
2538
  await this.waitForPort();
2232
2539
  await this.request("connect", params);
2233
- this.negotiation ??= this.request("negotiate", { features: [...APP_HOST_FEATURES] }).then((result) => {
2540
+ this.negotiation ??= this.request("negotiate", {
2541
+ features: [...APP_HOST_FEATURES]
2542
+ }).then((result) => {
2234
2543
  this.features = new Set(result.features);
2235
2544
  });
2236
2545
  await this.negotiation;
2237
- const catalog = createResourceCatalogApi({ requireFeature: () => this.requireFeature("resource-catalog-v1"), request: (method, params2) => this.request(method, params2) });
2546
+ const catalog = createResourceCatalogApi({
2547
+ requireFeature: () => this.requireFeature("resource-catalog-v1"),
2548
+ request: (method, params2) => this.request(method, params2)
2549
+ });
2238
2550
  const conversationPreparation = createConversationPreparationApi({
2239
2551
  requireFeature: () => this.requireFeature("session-controls-v1"),
2240
2552
  request: (method, params2) => this.request(method, params2)
2241
2553
  });
2242
2554
  return {
2243
2555
  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
- } }),
2556
+ commands: createAppCommandsApi({
2557
+ requireFeature: () => this.requireFeature("commands-v1"),
2558
+ request: (method, params2) => this.request(method, params2),
2559
+ onInvoke: (listener) => {
2560
+ const handler = (event) => {
2561
+ if (event.type === "command-invoked") listener(event);
2562
+ };
2563
+ this.listeners.add(handler);
2564
+ return () => {
2565
+ this.listeners.delete(handler);
2566
+ };
2567
+ },
2568
+ onClose: (listener) => {
2569
+ this.closeListeners.add(listener);
2570
+ return () => {
2571
+ this.closeListeners.delete(listener);
2572
+ };
2573
+ }
2574
+ }),
2258
2575
  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");
2576
+ system: createAppSystemApi(
2577
+ {
2578
+ requireFeature: () => this.requireFeature("system-ui-v1"),
2579
+ request: (method, params2) => this.request(method, params2)
2270
2580
  },
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),
2581
+ this.fetchClient
2582
+ ),
2583
+ window: createAppWindowApi({
2584
+ requireFeature: (feature) => this.requireFeature(feature ?? "window-chrome-v1"),
2585
+ request: (method, params2) => this.request(method, params2),
2586
+ onEvent: (listener) => {
2587
+ this.listeners.add(listener);
2588
+ return () => {
2589
+ this.listeners.delete(listener);
2590
+ };
2591
+ }
2592
+ }),
2593
+ desktop: createAppDesktopApi(
2594
+ {
2595
+ requireFeature: (method) => {
2596
+ this.requireFeature("trusted-desktop-v1");
2597
+ if (method === "desktop.browser.capturePreview")
2598
+ this.requireFeature("browser-capture-preview-v1");
2599
+ },
2600
+ request: (method, params2) => this.request(method, params2)
2601
+ },
2602
+ this.fetchClient,
2603
+ () => this.requireFeature("file-content-v1")
2604
+ ),
2605
+ attachments: createAppAttachmentsApi(
2606
+ {
2607
+ requireFeature: () => this.requireFeature("attachments-v1"),
2608
+ request: (method, params2) => this.request(method, params2)
2609
+ },
2610
+ this.fetchClient
2611
+ ),
2612
+ sessions: {
2613
+ preparation: conversationPreparation,
2614
+ ...createAppSessionsApi(
2615
+ {
2616
+ requireFeature: () => this.requireFeature("session-resources-v1"),
2617
+ request: (method, params2) => this.request(
2618
+ method,
2619
+ params2
2620
+ )
2621
+ },
2622
+ this.fetchClient
2623
+ ),
2624
+ auxiliary: createAppAuxiliarySessionsApi(
2625
+ {
2626
+ requireFeature: () => this.requireFeature("auxiliary-sessions-v1"),
2627
+ request: (method, params2) => this.request(method, params2)
2628
+ },
2629
+ this.fetchClient
2630
+ )
2631
+ },
2632
+ workspace: Object.assign(
2633
+ { list: catalog.list },
2634
+ createAppWorkspaceApi({
2635
+ requireFeature: () => this.requireFeature("workspace-v1"),
2636
+ request: (method, params2) => this.request(method, params2)
2637
+ })
2638
+ ),
2639
+ service: createAppServiceApi(
2640
+ {
2641
+ request: (method, params2) => {
2642
+ this.requireFeature("service-v1");
2643
+ return this.request(
2644
+ method,
2645
+ params2
2646
+ );
2647
+ }
2648
+ },
2649
+ this.fetchClient
2650
+ ),
2280
2651
  getContext: () => this.request("getContext", {}),
2281
2652
  onEvent: (listener) => {
2282
2653
  if (!this.closed) this.listeners.add(listener);
@@ -2289,12 +2660,18 @@ var DocumentConnection = class {
2289
2660
  set: (key, value) => this.request("storage.set", { key, value }),
2290
2661
  delete: (key) => this.request("storage.delete", { key }),
2291
2662
  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()) });
2663
+ if (!(data instanceof Blob) || !nonempty(name2) || data.size + new TextEncoder().encode(JSON.stringify({ name: name2 })).byteLength > APP_HOST_MAX_PAYLOAD_BYTES)
2664
+ throw failure("invalid_request");
2665
+ return this.request("storage.putFile", {
2666
+ name: name2,
2667
+ bytes: new Uint8Array(await data.arrayBuffer())
2668
+ });
2294
2669
  },
2295
2670
  readFile: async (id3) => {
2296
- const bytes = await this.request("storage.readFile", { id: id3 });
2297
- return new Response(new Uint8Array(bytes), { headers: { "content-type": "application/octet-stream" } });
2671
+ const bytes2 = await this.request("storage.readFile", { id: id3 });
2672
+ return new Response(new Uint8Array(bytes2), {
2673
+ headers: { "content-type": "application/octet-stream" }
2674
+ });
2298
2675
  },
2299
2676
  deleteFile: (id3) => this.request("storage.deleteFile", { id: id3 })
2300
2677
  },
@@ -2302,9 +2679,11 @@ var DocumentConnection = class {
2302
2679
  };
2303
2680
  }
2304
2681
  async login(input) {
2305
- if (!keys(input, ["url"]) || !nonempty(input.url)) throw failure("invalid_request");
2682
+ if (!keys(input, ["url"]) || !nonempty(input.url))
2683
+ throw failure("invalid_request");
2306
2684
  try {
2307
- if (new URL(input.url).protocol !== "https:") throw failure("invalid_request");
2685
+ if (new URL(input.url).protocol !== "https:")
2686
+ throw failure("invalid_request");
2308
2687
  } catch {
2309
2688
  throw failure("invalid_request");
2310
2689
  }
@@ -2312,18 +2691,45 @@ var DocumentConnection = class {
2312
2691
  }
2313
2692
  async request(method, params) {
2314
2693
  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");
2316
- const mutationRequestId = (isDesktopMethod(method) || isAuxiliaryMethod(method)) && "requestId" in params && typeof params.requestId === "string" && HOST_REQUEST_ID.test(params.requestId) ? params.requestId : void 0;
2694
+ if (Object.entries(params).some(
2695
+ ([key, value]) => ["key", "id", "name"].includes(key) && !nonempty(value)
2696
+ ) || this.pending.size >= APP_HOST_MAX_PENDING || payloadSize(params) > APP_HOST_MAX_PAYLOAD_BYTES)
2697
+ throw failure("invalid_request");
2698
+ const mutationRequestId = (isDesktopMethod(method) || isAuxiliaryMethod(method) || method === "sessions.createConversation" || method === "system.workspace" && "action" in params && params.action === "write") && "requestId" in params && typeof params.requestId === "string" && HOST_REQUEST_ID.test(params.requestId) ? params.requestId : void 0;
2317
2699
  const selectionRequestId = method === "workspace.select" ? params.requestId : void 0;
2700
+ let timeout = APP_HOST_REQUEST_TIMEOUT_MS;
2701
+ if (method === "auth.openLogin" || method === "workspace.select" || method === "system.workspace" && "action" in params && params.action === "pick")
2702
+ timeout = APP_HOST_LOGIN_TRANSPORT_TIMEOUT_MS;
2703
+ if (method === "system.extensions") {
2704
+ const { operation } = params;
2705
+ if (operation === "skills.marketplaceCatalog" || operation === "skills.marketplaceInstall") {
2706
+ timeout = SKILL_MARKETPLACE_TIMEOUT_MS;
2707
+ }
2708
+ }
2318
2709
  return new Promise((resolve, reject) => {
2319
2710
  const id3 = String(++this.nextId);
2320
2711
  const timer = setTimeout(() => {
2321
2712
  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 });
2713
+ reject(
2714
+ mutationRequestId ? new AppHostError("result_unknown", "result_unknown", {
2715
+ requestId: mutationRequestId
2716
+ }) : hostFailure("host_response_timeout", selectionRequestId)
2717
+ );
2718
+ }, timeout);
2719
+ this.pending.set(id3, {
2720
+ method,
2721
+ resolve: (value) => resolve(value),
2722
+ reject,
2723
+ timer
2724
+ });
2325
2725
  try {
2326
- this.port.postMessage({ protocol: APP_HOST_PROTOCOL, type: "request", id: id3, method, params });
2726
+ this.port.postMessage({
2727
+ protocol: APP_HOST_PROTOCOL,
2728
+ type: "request",
2729
+ id: id3,
2730
+ method,
2731
+ params
2732
+ });
2327
2733
  } catch {
2328
2734
  this.close(hostFailure("host_send_failed"));
2329
2735
  }
@@ -2332,7 +2738,8 @@ var DocumentConnection = class {
2332
2738
  };
2333
2739
  var documents = /* @__PURE__ */ new WeakMap();
2334
2740
  async function connectAppHost(options) {
2335
- if (!keys(options, ["hostApi"]) || !nonempty(options.hostApi)) throw failure("invalid_request");
2741
+ if (!keys(options, ["hostApi"]) || !nonempty(options.hostApi))
2742
+ throw failure("invalid_request");
2336
2743
  if (typeof window === "undefined") throw failure("host_unavailable");
2337
2744
  let connection = documents.get(window);
2338
2745
  if (!connection) {