@bobannomi/app-host 0.7.0 → 0.8.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/README.md +5 -5
- package/dist/index.d.ts +19 -239
- package/dist/index.js +131 -297
- package/dist/index.js.map +3 -3
- package/dist/protocol.d.ts +19 -254
- package/dist/protocol.js +65 -261
- package/dist/protocol.js.map +3 -3
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -115,18 +115,6 @@ function appHostErrorMessage(code, details) {
|
|
|
115
115
|
return "The desktop host could not read the response stream.";
|
|
116
116
|
case "response_delivery_failed":
|
|
117
117
|
return "The desktop host could not deliver the response.";
|
|
118
|
-
case "skill_marketplace_unavailable":
|
|
119
|
-
return "\u6682\u65F6\u65E0\u6CD5\u8BFB\u53D6\u5B98\u65B9\u6280\u80FD\u5E02\u573A\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002";
|
|
120
|
-
case "skill_marketplace_install_failed":
|
|
121
|
-
return "\u6280\u80FD\u5B89\u88C5\u6216\u66F4\u65B0\u672A\u5B8C\u6210\uFF0C\u8BF7\u5237\u65B0\u5DF2\u5B89\u88C5\u6280\u80FD\u540E\u91CD\u8BD5\u3002";
|
|
122
|
-
case "skill_marketplace_busy":
|
|
123
|
-
return "\u540E\u53F0\u6B63\u5728\u8FD0\u884C\u4EFB\u52A1\u6216\u5904\u7406\u6280\u80FD\u53D8\u66F4\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002";
|
|
124
|
-
case "skill_marketplace_local_conflict":
|
|
125
|
-
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";
|
|
126
|
-
case "skill_marketplace_selection_changed":
|
|
127
|
-
return "\u6240\u9009\u6280\u80FD\u6216\u7248\u672C\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u6280\u80FD\u5E02\u573A\u540E\u91CD\u8BD5\u3002";
|
|
128
|
-
case "skill_marketplace_project_unavailable":
|
|
129
|
-
return "\u5F53\u524D\u9879\u76EE\u65E0\u6CD5\u5B89\u88C5\u6280\u80FD\uFF0C\u8BF7\u9009\u62E9\u5DF2\u767B\u8BB0\u7684\u9879\u76EE\u3002";
|
|
130
118
|
default:
|
|
131
119
|
return "The desktop host could not complete the operation.";
|
|
132
120
|
}
|
|
@@ -168,7 +156,7 @@ var AppHostError = class extends Error {
|
|
|
168
156
|
};
|
|
169
157
|
|
|
170
158
|
// ../domain-contracts/src/app-host/wire-validation.ts
|
|
171
|
-
var text = (max = 1024,
|
|
159
|
+
var text = (max = 1024, empty2 = false) => (v) => typeof v === "string" && (empty2 || v.length > 0) && new TextEncoder().encode(v).byteLength <= max;
|
|
172
160
|
var id = (v) => typeof v === "string" && HOST_REQUEST_ID.test(v);
|
|
173
161
|
var count = (v) => typeof v === "number" && Number.isSafeInteger(v) && v >= 0;
|
|
174
162
|
var bool = (v) => typeof v === "boolean";
|
|
@@ -245,7 +233,6 @@ var APP_HOST_FEATURES = [
|
|
|
245
233
|
"service-v1",
|
|
246
234
|
"extended-errors-v1",
|
|
247
235
|
"workspace-v1",
|
|
248
|
-
"session-resources-v1",
|
|
249
236
|
"session-controls-v1",
|
|
250
237
|
"conversation-creation-session-v1",
|
|
251
238
|
"trusted-desktop-v1",
|
|
@@ -271,6 +258,11 @@ var FETCH_MAX_STREAMS = 16;
|
|
|
271
258
|
var FETCH_METADATA_BYTES = 64 * 1024;
|
|
272
259
|
var FETCH_HEADERS_TIMEOUT_MS = 3e4;
|
|
273
260
|
var FETCH_IDLE_TIMEOUT_MS = 12e4;
|
|
261
|
+
function pageFetchHeadersTimeout(method, target2) {
|
|
262
|
+
const path = target2.split("?", 1)[0];
|
|
263
|
+
const preparesExtension = method === "GET" ? path === "/skills/marketplace" || path === "/plugins/marketplace/catalog" : method === "POST" && /^\/(?:skills\/marketplace\/install|plugins\/(?:archive|git|marketplace)\/(?:preview|install)|plugins\/archive\/uploads(?:\/install)?)$/.test(path ?? "");
|
|
264
|
+
return preparesExtension ? 33e4 : FETCH_HEADERS_TIMEOUT_MS;
|
|
265
|
+
}
|
|
274
266
|
function isPageFetchFrame(value) {
|
|
275
267
|
let size = 0;
|
|
276
268
|
const visit = (entry, depth, binary = false) => {
|
|
@@ -292,17 +284,17 @@ function isPageFetchFrame(value) {
|
|
|
292
284
|
return size <= FETCH_METADATA_BYTES;
|
|
293
285
|
}
|
|
294
286
|
if (!entry || typeof entry !== "object") return false;
|
|
295
|
-
const
|
|
296
|
-
if (
|
|
287
|
+
const array3 = Array.isArray(entry);
|
|
288
|
+
if (array3 ? Object.getPrototypeOf(entry) !== Array.prototype : ![Object.prototype, null].includes(Object.getPrototypeOf(entry)))
|
|
297
289
|
return false;
|
|
298
290
|
const keys3 = Reflect.ownKeys(entry);
|
|
299
|
-
if (keys3.length > FETCH_METADATA_BYTES ||
|
|
291
|
+
if (keys3.length > FETCH_METADATA_BYTES || array3 && keys3.length !== entry.length + 1)
|
|
300
292
|
return false;
|
|
301
293
|
return keys3.every((key) => {
|
|
302
|
-
if (
|
|
294
|
+
if (array3 && key === "length") return true;
|
|
303
295
|
const d = Object.getOwnPropertyDescriptor(entry, key);
|
|
304
296
|
size += typeof key === "string" ? key.length + 3 : 0;
|
|
305
|
-
return typeof key === "string" && d.enumerable && Object.hasOwn(d, "value") && (!
|
|
297
|
+
return typeof key === "string" && d.enumerable && Object.hasOwn(d, "value") && (!array3 || /^(0|[1-9][0-9]*)$/.test(key) && Number(key) < entry.length) && visit(d.value, depth + 1, depth === 0 && key === "bytes") && size <= FETCH_METADATA_BYTES;
|
|
306
298
|
});
|
|
307
299
|
};
|
|
308
300
|
if (!visit(value, 0) || !value || typeof value !== "object" || Array.isArray(value))
|
|
@@ -462,14 +454,14 @@ function json2(value, ancestors = /* @__PURE__ */ new Set(), depth = 0) {
|
|
|
462
454
|
return true;
|
|
463
455
|
if (typeof value === "number") return Number.isFinite(value);
|
|
464
456
|
if (typeof value !== "object" || ancestors.has(value)) return false;
|
|
465
|
-
const
|
|
466
|
-
if (
|
|
457
|
+
const array3 = Array.isArray(value);
|
|
458
|
+
if (array3 ? Object.getPrototypeOf(value) !== Array.prototype || Reflect.ownKeys(value).length !== value.length + 1 : ![Object.prototype, null].includes(Object.getPrototypeOf(value)))
|
|
467
459
|
return false;
|
|
468
460
|
ancestors.add(value);
|
|
469
461
|
const result = Reflect.ownKeys(value).every((k) => {
|
|
470
|
-
if (
|
|
462
|
+
if (array3 && k === "length") return true;
|
|
471
463
|
const d = Object.getOwnPropertyDescriptor(value, k);
|
|
472
|
-
return typeof k === "string" && (!
|
|
464
|
+
return typeof k === "string" && (!array3 || /^(0|[1-9]\d*)$/.test(k) && Number(k) < value.length) && d.enumerable && Object.hasOwn(d, "value") && json2(d.value, ancestors, depth + 1);
|
|
473
465
|
});
|
|
474
466
|
ancestors.delete(value);
|
|
475
467
|
return result;
|
|
@@ -663,7 +655,7 @@ function createAppCommandsApi(rpc) {
|
|
|
663
655
|
rpc.requireFeature();
|
|
664
656
|
snapshot = structuredClone(snapshot);
|
|
665
657
|
const registrationId = crypto.randomUUID();
|
|
666
|
-
let
|
|
658
|
+
let revision2 = 0;
|
|
667
659
|
let disposed = false;
|
|
668
660
|
let remoteValid = true;
|
|
669
661
|
let disposal;
|
|
@@ -671,11 +663,11 @@ function createAppCommandsApi(rpc) {
|
|
|
671
663
|
let conflicts = [];
|
|
672
664
|
let queue = Promise.resolve();
|
|
673
665
|
const off = rpc.onInvoke((event) => {
|
|
674
|
-
if (!disposed && event.registrationId === registrationId && event.revision ===
|
|
666
|
+
if (!disposed && event.registrationId === registrationId && event.revision === revision2 && current.commands.some(
|
|
675
667
|
(c) => c.id === event.commandId && c.enabled !== false
|
|
676
668
|
)) {
|
|
677
669
|
void Promise.resolve().then(() => {
|
|
678
|
-
if (!disposed && event.revision ===
|
|
670
|
+
if (!disposed && event.revision === revision2)
|
|
679
671
|
return invoke(event.commandId);
|
|
680
672
|
}).catch(() => {
|
|
681
673
|
});
|
|
@@ -695,14 +687,14 @@ function createAppCommandsApi(rpc) {
|
|
|
695
687
|
const call = async (method, next) => {
|
|
696
688
|
const params = {
|
|
697
689
|
registrationId,
|
|
698
|
-
revision:
|
|
690
|
+
revision: revision2,
|
|
699
691
|
...next === void 0 ? {} : { snapshot: next }
|
|
700
692
|
};
|
|
701
693
|
const result = await rpc.request(
|
|
702
694
|
method,
|
|
703
695
|
params
|
|
704
696
|
);
|
|
705
|
-
if (!validCommandReceipt(result) || result.registrationId !== registrationId || result.revision !==
|
|
697
|
+
if (!validCommandReceipt(result) || result.registrationId !== registrationId || result.revision !== revision2)
|
|
706
698
|
throw new AppHostError("host_unavailable");
|
|
707
699
|
conflicts = [...result.shortcutConflicts ?? []];
|
|
708
700
|
};
|
|
@@ -712,7 +704,7 @@ function createAppCommandsApi(rpc) {
|
|
|
712
704
|
try {
|
|
713
705
|
await rpc.request("commands.dispose", {
|
|
714
706
|
registrationId,
|
|
715
|
-
revision: ++
|
|
707
|
+
revision: ++revision2
|
|
716
708
|
});
|
|
717
709
|
} catch {
|
|
718
710
|
}
|
|
@@ -736,7 +728,7 @@ function createAppCommandsApi(rpc) {
|
|
|
736
728
|
const task = queue.then(async () => {
|
|
737
729
|
if (disposed) throw new AppHostError("connection_revoked");
|
|
738
730
|
rpc.requireFeature();
|
|
739
|
-
|
|
731
|
+
revision2++;
|
|
740
732
|
current = next;
|
|
741
733
|
try {
|
|
742
734
|
await call("commands.update", next);
|
|
@@ -754,7 +746,7 @@ function createAppCommandsApi(rpc) {
|
|
|
754
746
|
stop();
|
|
755
747
|
disposal = queue.then(async () => {
|
|
756
748
|
if (!remoteValid) return;
|
|
757
|
-
|
|
749
|
+
revision2++;
|
|
758
750
|
try {
|
|
759
751
|
await call("commands.dispose");
|
|
760
752
|
} finally {
|
|
@@ -791,7 +783,7 @@ function text2(value, limit = 256) {
|
|
|
791
783
|
return typeof value === "string" && value.length > 0 && value.length <= limit;
|
|
792
784
|
}
|
|
793
785
|
function keys(value, ...names) {
|
|
794
|
-
return Object.keys(value).length === names.length && names.every((
|
|
786
|
+
return Object.keys(value).length === names.length && names.every((name) => Object.hasOwn(value, name));
|
|
795
787
|
}
|
|
796
788
|
function isWorkbenchComputerMethod(method) {
|
|
797
789
|
return WORKBENCH_COMPUTER_METHODS.includes(method);
|
|
@@ -879,9 +871,9 @@ function createConversationPreparationApi(rpc) {
|
|
|
879
871
|
// src/client-connections.ts
|
|
880
872
|
var connections = /* @__PURE__ */ new WeakMap();
|
|
881
873
|
function createClientConnection(wire, streams) {
|
|
882
|
-
const { connectionId, baseUrl, cwd
|
|
874
|
+
const { connectionId, baseUrl, cwd, defaultTaskLocation } = wire;
|
|
883
875
|
const connection = {
|
|
884
|
-
...
|
|
876
|
+
...cwd === void 0 ? {} : { cwd },
|
|
885
877
|
...defaultTaskLocation === void 0 ? {} : { defaultTaskLocation },
|
|
886
878
|
clientOptions: { baseUrl, fetch: streams.fetchFor(connectionId, baseUrl) },
|
|
887
879
|
isClosed: () => streams.isClosed?.(connectionId) === true
|
|
@@ -889,9 +881,68 @@ function createClientConnection(wire, streams) {
|
|
|
889
881
|
connections.set(connection, { owner: streams, id: connectionId });
|
|
890
882
|
return connection;
|
|
891
883
|
}
|
|
884
|
+
async function connectAgent() {
|
|
885
|
+
const page2 = typeof window === "undefined" ? void 0 : window;
|
|
886
|
+
if (!page2?.nomiNative?.agentConnection) throw new AppHostError("host_unavailable");
|
|
887
|
+
const readDescriptor = page2.nomiNative.agentConnection.bind(page2.nomiNative);
|
|
888
|
+
const descriptor = await readDescriptor().catch(() => {
|
|
889
|
+
throw new AppHostError("host_unavailable");
|
|
890
|
+
});
|
|
891
|
+
if (!descriptor || typeof descriptor.baseUrl !== "string" || typeof descriptor.token !== "string" || !descriptor.token || typeof descriptor.connectionId !== "string" || !/^[a-z0-9-]+$/i.test(descriptor.connectionId) || descriptor.defaultTaskLocation !== void 0 && descriptor.defaultTaskLocation !== "current" && descriptor.defaultTaskLocation !== "worktree")
|
|
892
|
+
throw new AppHostError("host_unavailable");
|
|
893
|
+
const { baseUrl, token, connectionId, defaultTaskLocation } = descriptor;
|
|
894
|
+
const endpoint = URL.parse(baseUrl);
|
|
895
|
+
if (!endpoint || endpoint.protocol !== "http:" || !["127.0.0.1", "[::1]"].includes(endpoint.hostname) || endpoint.username || endpoint.password || endpoint.pathname !== "/" || endpoint.search || endpoint.hash)
|
|
896
|
+
throw new AppHostError("host_unavailable");
|
|
897
|
+
let closed = false;
|
|
898
|
+
const fetchDaemon = async (input, init) => {
|
|
899
|
+
if (closed) throw new AppHostError("connection_revoked");
|
|
900
|
+
const original = input instanceof Request ? input : void 0;
|
|
901
|
+
const target2 = URL.parse(original?.url ?? String(input), endpoint);
|
|
902
|
+
if (!target2 || target2.origin !== endpoint.origin || target2.username || target2.password)
|
|
903
|
+
throw new AppHostError("invalid_request");
|
|
904
|
+
const headers = new Headers(init?.headers ?? original?.headers);
|
|
905
|
+
headers.set("authorization", "Bearer " + token);
|
|
906
|
+
headers.set("x-nomi-connection-id", connectionId);
|
|
907
|
+
const signal = init?.signal ?? original?.signal;
|
|
908
|
+
signal?.throwIfAborted();
|
|
909
|
+
let response;
|
|
910
|
+
try {
|
|
911
|
+
response = await fetch(original ?? target2, {
|
|
912
|
+
...init,
|
|
913
|
+
headers,
|
|
914
|
+
signal,
|
|
915
|
+
redirect: "error",
|
|
916
|
+
credentials: "omit",
|
|
917
|
+
cache: "no-store"
|
|
918
|
+
});
|
|
919
|
+
} catch (error) {
|
|
920
|
+
if (signal?.aborted) throw error;
|
|
921
|
+
const current = await readDescriptor().catch(() => void 0);
|
|
922
|
+
signal?.throwIfAborted();
|
|
923
|
+
if (!current || current.baseUrl !== baseUrl || current.connectionId !== connectionId || current.token !== token) closed = true;
|
|
924
|
+
throw new AppHostError("host_unavailable");
|
|
925
|
+
}
|
|
926
|
+
if (response.status === 401 || response.status === 403 && (await response.clone().json().catch(() => void 0))?.error === "connection_revoked") {
|
|
927
|
+
closed = true;
|
|
928
|
+
await response.body?.cancel().catch(() => {
|
|
929
|
+
});
|
|
930
|
+
throw new AppHostError("connection_revoked");
|
|
931
|
+
}
|
|
932
|
+
return response;
|
|
933
|
+
};
|
|
934
|
+
const connection = {
|
|
935
|
+
clientOptions: { baseUrl: endpoint.origin, fetch: fetchDaemon },
|
|
936
|
+
...defaultTaskLocation ? { defaultTaskLocation } : {},
|
|
937
|
+
isClosed: () => closed
|
|
938
|
+
};
|
|
939
|
+
connections.set(connection, { owner: page2, id: connectionId });
|
|
940
|
+
return connection;
|
|
941
|
+
}
|
|
892
942
|
function resolveClientConnection(connection, owner) {
|
|
893
943
|
const record4 = connections.get(connection);
|
|
894
|
-
if (!record4 || record4.owner !== owner
|
|
944
|
+
if (!record4 || record4.owner !== owner && record4.owner !== globalThis.window || connection.isClosed?.())
|
|
945
|
+
throw new AppHostError("connection_revoked");
|
|
895
946
|
return record4.id;
|
|
896
947
|
}
|
|
897
948
|
|
|
@@ -1056,7 +1107,7 @@ function createAppDesktopApi(rpc, owner, filesFeature = () => {
|
|
|
1056
1107
|
if (!validDesktopResultForInput(method, params, value)) throw new AppHostError("host_unavailable");
|
|
1057
1108
|
return value;
|
|
1058
1109
|
};
|
|
1059
|
-
const group = (
|
|
1110
|
+
const group = (name) => Object.fromEntries(DESKTOP_METHODS.filter((method) => !DESKTOP_ADAPTED_METHODS.includes(method) && method.startsWith(`desktop.${name}.`)).map((method) => [method.split(".")[2], (params) => call(method, params)]));
|
|
1060
1111
|
const getOperation = async (input, validate2) => {
|
|
1061
1112
|
if (!validate2(input)) throw new AppHostError("invalid_request");
|
|
1062
1113
|
return call("desktop.files.getOperation", input);
|
|
@@ -1109,67 +1160,6 @@ function canonicalDesktopRequest(value) {
|
|
|
1109
1160
|
return JSON.stringify(normalize(value));
|
|
1110
1161
|
}
|
|
1111
1162
|
|
|
1112
|
-
// src/extensions.ts
|
|
1113
|
-
var empty = object({});
|
|
1114
|
-
var cwd = object({ cwd: text(4096) });
|
|
1115
|
-
var plugin = object({ cwd: text(4096), pluginId: text(256) });
|
|
1116
|
-
var selection = object({ cwd: text(4096), selectionId: text(256) });
|
|
1117
|
-
var cancel = object({ selectionId: text(256) });
|
|
1118
|
-
var name = object({ name: text(256) });
|
|
1119
|
-
var login = object({ loginId: text(256) });
|
|
1120
|
-
var skillSelection = { id: text(64), version: text(32), sha256: digest };
|
|
1121
|
-
var skillInstallOptions = { allowWhileRunning: bool };
|
|
1122
|
-
var personalSkillInstall = object({ ...skillSelection, scope: enumeration("personal") }, skillInstallOptions);
|
|
1123
|
-
var projectSkillInstall = object({
|
|
1124
|
-
...skillSelection,
|
|
1125
|
-
scope: enumeration("project"),
|
|
1126
|
-
projectPath: (value) => typeof value === "string" && value.trim().length > 0 && text(4096)(value)
|
|
1127
|
-
}, skillInstallOptions);
|
|
1128
|
-
var EXTENSION_INPUTS = {
|
|
1129
|
-
context: empty,
|
|
1130
|
-
"plugins.loadIcon": object({ src: text(8192) }),
|
|
1131
|
-
"plugins.snapshot": cwd,
|
|
1132
|
-
"plugins.enable": plugin,
|
|
1133
|
-
"plugins.disable": plugin,
|
|
1134
|
-
"plugins.uninstall": plugin,
|
|
1135
|
-
"plugins.reload": cwd,
|
|
1136
|
-
"plugins.importArchive": cwd,
|
|
1137
|
-
"plugins.confirmArchive": selection,
|
|
1138
|
-
"plugins.cancelArchive": cancel,
|
|
1139
|
-
"plugins.importGit": object({ cwd: text(4096), url: text(8192) }, { ref: text(1024) }),
|
|
1140
|
-
"plugins.confirmGit": selection,
|
|
1141
|
-
"plugins.cancelGit": cancel,
|
|
1142
|
-
"plugins.marketplaceCatalog": object({ cwd: text(4096) }, { refresh: bool }),
|
|
1143
|
-
"plugins.marketplaceAddSource": object({ url: text(8192) }),
|
|
1144
|
-
"plugins.marketplaceSetSourceEnabled": object({ sourceId: text(256), enabled: bool }),
|
|
1145
|
-
"plugins.marketplaceRemoveSource": object({ sourceId: text(256) }),
|
|
1146
|
-
"plugins.marketplacePreview": object({ cwd: text(4096), sourceId: text(256), pluginId: text(256) }, { version: text(256) }),
|
|
1147
|
-
"plugins.marketplaceConfirm": selection,
|
|
1148
|
-
"plugins.marketplaceCancel": cancel,
|
|
1149
|
-
"plugins.marketplaceOperation": object({ cwd: text(4096), operationId: text(256) }),
|
|
1150
|
-
"skills.snapshot": object({ projectPath: text(4096) }),
|
|
1151
|
-
"skills.remove": object({ id: text(4096), expectedContent: text(8 * 1024 * 1024, true), projectPath: text(4096) }),
|
|
1152
|
-
"skills.marketplaceCatalog": empty,
|
|
1153
|
-
"skills.marketplaceInstall": (value) => personalSkillInstall(value) || projectSkillInstall(value),
|
|
1154
|
-
"mcp.snapshot": empty,
|
|
1155
|
-
"mcp.exportConfig": empty,
|
|
1156
|
-
"mcp.getConfig": name,
|
|
1157
|
-
"mcp.add": object({ name: text(256), config: jsonObject }),
|
|
1158
|
-
"mcp.update": object({ name: text(256), config: jsonObject, expectedConfig: jsonObject }),
|
|
1159
|
-
"mcp.remove": name,
|
|
1160
|
-
"mcp.setEnabled": object({ name: text(256), enabled: bool }),
|
|
1161
|
-
"mcp.login": object({ name: text(256), scopes: array(text(2048), 128) }),
|
|
1162
|
-
"mcp.loginStatus": login,
|
|
1163
|
-
"mcp.cancelLogin": login,
|
|
1164
|
-
"mcp.logout": name
|
|
1165
|
-
};
|
|
1166
|
-
function validExtensionRequest(value) {
|
|
1167
|
-
if (!object({ operation: text(128), input: jsonObject })(value)) return false;
|
|
1168
|
-
const request = value;
|
|
1169
|
-
return Object.hasOwn(EXTENSION_INPUTS, request.operation) && EXTENSION_INPUTS[request.operation](request.input);
|
|
1170
|
-
}
|
|
1171
|
-
var validExtensionResult = (value) => value === void 0 || json(value);
|
|
1172
|
-
|
|
1173
1163
|
// src/projects.ts
|
|
1174
1164
|
var id2 = text(256);
|
|
1175
1165
|
var scope = { dataScopeId: id2 };
|
|
@@ -1177,14 +1167,8 @@ var project = { ...scope, projectId: id2, workspaceId: id2 };
|
|
|
1177
1167
|
function validProjectRequest(value) {
|
|
1178
1168
|
const action2 = value && typeof value === "object" ? Object.getOwnPropertyDescriptor(value, "action")?.value : void 0;
|
|
1179
1169
|
switch (action2) {
|
|
1180
|
-
case "list":
|
|
1181
|
-
return object({ action: (v) => v === "list" })(value);
|
|
1182
1170
|
case "register":
|
|
1183
1171
|
return object({ action: (v) => v === "register", ...scope, workspaceId: id2 })(value);
|
|
1184
|
-
case "setDefaultShell":
|
|
1185
|
-
return object({ action: (v) => v === "setDefaultShell", ...project, shell: (v) => v === null || text(4096)(v) })(value);
|
|
1186
|
-
case "archive":
|
|
1187
|
-
return object({ action: (v) => v === "archive", ...project })(value);
|
|
1188
1172
|
case "rebind":
|
|
1189
1173
|
return object({ action: (v) => v === "rebind", ...project, previousWorkspaceId: id2, expectedPath: text(32768) })(value);
|
|
1190
1174
|
default:
|
|
@@ -1204,6 +1188,7 @@ var root2 = { rootPath: text(32768) };
|
|
|
1204
1188
|
var identity = { identity: object({ dev: text(32), ino: text(32) }) };
|
|
1205
1189
|
var file = { ...root2, path: text(32768) };
|
|
1206
1190
|
var write = { ...file, requestId: id, content: text(125e4, true), originalContent: text(125e4, true) };
|
|
1191
|
+
var gitRead = { ...identity, range: enumeration("uncommitted", "working", "staged"), ignoreWhitespace: bool };
|
|
1207
1192
|
var actionOf = (value) => value && typeof value === "object" ? Object.getOwnPropertyDescriptor(value, "action")?.value : void 0;
|
|
1208
1193
|
function validLocalWorkspaceRequest(value) {
|
|
1209
1194
|
const action2 = actionOf(value);
|
|
@@ -1216,6 +1201,10 @@ function validLocalWorkspaceRequest(value) {
|
|
|
1216
1201
|
return object({ ...field, ...root2 }, { ...identity, path: text(32768, true) })(value);
|
|
1217
1202
|
case "find":
|
|
1218
1203
|
return object({ ...field, ...root2, query: text(1024) }, identity)(value);
|
|
1204
|
+
case "gitChanges":
|
|
1205
|
+
return object({ ...field, ...root2 }, gitRead)(value);
|
|
1206
|
+
case "gitDiff":
|
|
1207
|
+
return object({ ...field, ...root2 }, { ...gitRead, path: text(32768), base: text(512), head: text(512) })(value);
|
|
1219
1208
|
case "write":
|
|
1220
1209
|
case "getWrite":
|
|
1221
1210
|
return object({ ...field, ...write }, identity)(value);
|
|
@@ -1257,7 +1246,7 @@ var found = object({ files: array(text(32768), 1e3), truncated: bool });
|
|
|
1257
1246
|
var picked = object({ ...root2, ...identity, workspaceId: id });
|
|
1258
1247
|
var url = object({ url: text(131072) });
|
|
1259
1248
|
var openers = (value) => validDesktopResult("desktop.files.listOpeners", value);
|
|
1260
|
-
var
|
|
1249
|
+
var empty = (value) => value === void 0;
|
|
1261
1250
|
var checks = {
|
|
1262
1251
|
pick: nullable(picked),
|
|
1263
1252
|
list: tree,
|
|
@@ -1265,87 +1254,18 @@ var checks = {
|
|
|
1265
1254
|
read: preview,
|
|
1266
1255
|
write: preview,
|
|
1267
1256
|
getWrite: nullable(preview),
|
|
1268
|
-
reveal:
|
|
1269
|
-
openWith:
|
|
1270
|
-
copyPath:
|
|
1257
|
+
reveal: empty,
|
|
1258
|
+
openWith: empty,
|
|
1259
|
+
copyPath: empty,
|
|
1271
1260
|
listOpeners: openers,
|
|
1272
|
-
webPreview: url
|
|
1261
|
+
webPreview: url,
|
|
1262
|
+
gitChanges: (value) => validDesktopResult("desktop.git.changes", value),
|
|
1263
|
+
gitDiff: (value) => validDesktopResult("desktop.git.diff", value)
|
|
1273
1264
|
};
|
|
1274
1265
|
function validLocalWorkspaceResult(value, action2) {
|
|
1275
1266
|
return action2 ? checks[action2](value) : Object.values(checks).some((check) => check(value));
|
|
1276
1267
|
}
|
|
1277
1268
|
|
|
1278
|
-
// ../domain-contracts/src/app-host/model-providers.ts
|
|
1279
|
-
var provider = text(256);
|
|
1280
|
-
var imageInputSupport = enumeration("native", "unsupported", "unknown");
|
|
1281
|
-
var limits = { contextWindow: count, maxOutputTokens: count };
|
|
1282
|
-
function headerValues(check) {
|
|
1283
|
-
return (value) => {
|
|
1284
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1285
|
-
const keys3 = Object.keys(value);
|
|
1286
|
-
return keys3.length <= 128 && keys3.every((key) => /^[!#$%&'*+.^_`|~0-9A-Za-z-]{1,256}$/.test(key)) && object(Object.fromEntries(keys3.map((key) => [key, check])))(value);
|
|
1287
|
-
};
|
|
1288
|
-
}
|
|
1289
|
-
var headers = headerValues(text(8192, true));
|
|
1290
|
-
var secretHeaders = headerValues(nullable(text(8192)));
|
|
1291
|
-
var customProvider = object({
|
|
1292
|
-
id: provider,
|
|
1293
|
-
displayName: text(1024),
|
|
1294
|
-
baseUrl: text(4096),
|
|
1295
|
-
apiFormat: enumeration("openai"),
|
|
1296
|
-
models: array(object({ id: text(1024), displayName: text(1024) }, { imageInputSupport, ...limits }), 16384)
|
|
1297
|
-
}, { apiKey: text(8192), headers, secretHeaders });
|
|
1298
|
-
function validModelProviderRequest(value) {
|
|
1299
|
-
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);
|
|
1300
|
-
}
|
|
1301
|
-
var validModel = object({ id: text(1024), label: text(1024) }, { imageInputSupport, declaredLimits: object({}, limits) });
|
|
1302
|
-
var validConnection2 = object({
|
|
1303
|
-
name: provider,
|
|
1304
|
-
displayName: text(1024),
|
|
1305
|
-
connected: bool,
|
|
1306
|
-
active: bool,
|
|
1307
|
-
credentialSource: enumeration("credentials", "environment", "subscription", "local", "configured", "none"),
|
|
1308
|
-
models: array(validModel, 16384)
|
|
1309
|
-
}, { source: enumeration("builtin", "catalog", "custom", "subscription"), custom: bool, credentialLabel: text(1024), baseUrl: text(4096), headers, secretHeaderNames: array(text(256), 128) });
|
|
1310
|
-
function validModelProviderConnections(value) {
|
|
1311
|
-
return array(validConnection2, 4096)(value);
|
|
1312
|
-
}
|
|
1313
|
-
var modelId = text(1024);
|
|
1314
|
-
var effort = nullable(text(256));
|
|
1315
|
-
var revision = text(8192);
|
|
1316
|
-
var accountGatewayProof = (value) => typeof value === "string" && /^[a-f0-9]{64}$/.test(value);
|
|
1317
|
-
function validProviderDefaultsRequest(value) {
|
|
1318
|
-
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);
|
|
1319
|
-
}
|
|
1320
|
-
var verifiedProvider = object({ model: modelId, checkedAt: count });
|
|
1321
|
-
var verified = (value) => {
|
|
1322
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1323
|
-
const keys3 = Object.keys(value);
|
|
1324
|
-
return keys3.length <= 4096 && keys3.every(provider) && object(Object.fromEntries(keys3.map((key) => [key, verifiedProvider])))(value);
|
|
1325
|
-
};
|
|
1326
|
-
var defaultsModel = object({ id: modelId, label: text(1024), provider: text(1024), providerName: provider }, {
|
|
1327
|
-
reasoningEfforts: array(text(256, true)),
|
|
1328
|
-
contextWindow: count,
|
|
1329
|
-
inputModalities: array(text(256)),
|
|
1330
|
-
inputCapabilities: object({ image: imageInputSupport })
|
|
1331
|
-
});
|
|
1332
|
-
var validProviderDefaultsSnapshot = object({
|
|
1333
|
-
models: array(defaultsModel, 16384),
|
|
1334
|
-
provider: nullable(provider),
|
|
1335
|
-
model: nullable(modelId),
|
|
1336
|
-
effort,
|
|
1337
|
-
disabled: bool,
|
|
1338
|
-
revision,
|
|
1339
|
-
verified,
|
|
1340
|
-
fastModeAvailable: enumeration(false),
|
|
1341
|
-
fastModeReason: text(1024)
|
|
1342
|
-
}, { accountGatewayMatches: bool });
|
|
1343
|
-
var validProviderConnectionTestResult = object({
|
|
1344
|
-
status: enumeration("verified", "failed"),
|
|
1345
|
-
detail: text(8192),
|
|
1346
|
-
checkedAt: count
|
|
1347
|
-
}, { category: enumeration("authentication", "address", "network", "model", "unsupported", "service") });
|
|
1348
|
-
|
|
1349
1269
|
// src/system.ts
|
|
1350
1270
|
var SYSTEM_SETTINGS_SECTIONS = [
|
|
1351
1271
|
"general",
|
|
@@ -1383,29 +1303,9 @@ var SYSTEM_SHORTCUT_IDS = [
|
|
|
1383
1303
|
"resetZoom",
|
|
1384
1304
|
"showShortcuts"
|
|
1385
1305
|
];
|
|
1386
|
-
var CHANNEL_SETTINGS_ACTIONS = [
|
|
1387
|
-
"snapshot",
|
|
1388
|
-
"runtimeStatus",
|
|
1389
|
-
"connect",
|
|
1390
|
-
"patch",
|
|
1391
|
-
"remove",
|
|
1392
|
-
"allowAdd",
|
|
1393
|
-
"allowRemove",
|
|
1394
|
-
"startRegistration",
|
|
1395
|
-
"registrationStatus",
|
|
1396
|
-
"cancelRegistration",
|
|
1397
|
-
"startRuntime",
|
|
1398
|
-
"stopRuntime"
|
|
1399
|
-
];
|
|
1400
|
-
var channelSettingsKey = /* @__PURE__ */ Symbol.for("nomi.workbench-channel-settings");
|
|
1401
|
-
var channelSettingsValue = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
1402
1306
|
var SYSTEM_METHODS = [
|
|
1403
1307
|
"system.projects",
|
|
1404
1308
|
"system.workspace",
|
|
1405
|
-
"system.extensions",
|
|
1406
|
-
"system.modelProviders",
|
|
1407
|
-
"system.channelSettings",
|
|
1408
|
-
"system.providerDefaults",
|
|
1409
1309
|
"system.open",
|
|
1410
1310
|
"system.getPresentationPreferences",
|
|
1411
1311
|
"system.setTheme",
|
|
@@ -1480,7 +1380,11 @@ var validDesktopNavigationTarget = (v) => object(
|
|
|
1480
1380
|
scheduledRunId: text(256)
|
|
1481
1381
|
},
|
|
1482
1382
|
{ sessionId: text(256) }
|
|
1483
|
-
)(v)
|
|
1383
|
+
)(v) || object({
|
|
1384
|
+
id: text(256),
|
|
1385
|
+
dataScopeId: text(256),
|
|
1386
|
+
kind: enumeration("extensions")
|
|
1387
|
+
})(v);
|
|
1484
1388
|
function isSystemMethod(v) {
|
|
1485
1389
|
return SYSTEM_METHODS.includes(v);
|
|
1486
1390
|
}
|
|
@@ -1502,21 +1406,6 @@ function validSystemInput(method, value) {
|
|
|
1502
1406
|
return validProjectRequest(value);
|
|
1503
1407
|
case "system.workspace":
|
|
1504
1408
|
return validLocalWorkspaceRequest(value);
|
|
1505
|
-
case "system.extensions":
|
|
1506
|
-
return validExtensionRequest(value);
|
|
1507
|
-
case "system.modelProviders":
|
|
1508
|
-
return validModelProviderRequest(value);
|
|
1509
|
-
case "system.channelSettings": {
|
|
1510
|
-
const action2 = enumeration(...CHANNEL_SETTINGS_ACTIONS);
|
|
1511
|
-
if (object({ action: enumeration("allowRemove"), input: text() })(value)) return true;
|
|
1512
|
-
if (object({
|
|
1513
|
-
action: enumeration("connect", "patch", "allowAdd", "startRegistration"),
|
|
1514
|
-
input: channelSettingsValue
|
|
1515
|
-
})(value)) return true;
|
|
1516
|
-
return object({ action: (entry) => action2(entry) && !["allowRemove", "connect", "patch", "allowAdd", "startRegistration"].includes(entry) })(value);
|
|
1517
|
-
}
|
|
1518
|
-
case "system.providerDefaults":
|
|
1519
|
-
return validProviderDefaultsRequest(value);
|
|
1520
1409
|
case "system.setTheme":
|
|
1521
1410
|
return object({ theme: themeMode })(value);
|
|
1522
1411
|
case "system.setWindowMaterial":
|
|
@@ -1530,9 +1419,6 @@ function validSystemInput(method, value) {
|
|
|
1530
1419
|
{ page: enumeration("scheduled") },
|
|
1531
1420
|
{ taskId: text(256), scheduledRunId: text(256) }
|
|
1532
1421
|
)(value) && (!Object.hasOwn(value, "scheduledRunId") || Object.hasOwn(value, "taskId")) || object(
|
|
1533
|
-
{ page: enumeration("extensions") },
|
|
1534
|
-
{ tab: enumeration("plugins", "skills", "mcp") }
|
|
1535
|
-
)(value) || object(
|
|
1536
1422
|
{ page: enumeration("settings") },
|
|
1537
1423
|
{ section: enumeration(...SYSTEM_SETTINGS_SECTIONS) }
|
|
1538
1424
|
)(value) || object({ page: enumeration("pet") })(value) || object(
|
|
@@ -1562,14 +1448,6 @@ function validSystemResult(method, value) {
|
|
|
1562
1448
|
return validProjectSnapshot(value);
|
|
1563
1449
|
case "system.workspace":
|
|
1564
1450
|
return validLocalWorkspaceResult(value);
|
|
1565
|
-
case "system.extensions":
|
|
1566
|
-
return validExtensionResult(value);
|
|
1567
|
-
case "system.modelProviders":
|
|
1568
|
-
return validModelProviderConnections(value);
|
|
1569
|
-
case "system.channelSettings":
|
|
1570
|
-
return object({ value: channelSettingsValue })(value) || object({ error: enumeration("invalid_configuration", "conflict") })(value);
|
|
1571
|
-
case "system.providerDefaults":
|
|
1572
|
-
return validProviderDefaultsSnapshot(value) || validProviderConnectionTestResult(value);
|
|
1573
1451
|
case "system.open":
|
|
1574
1452
|
return object({ opened: enumeration(true) })(value);
|
|
1575
1453
|
case "system.getPresentationPreferences":
|
|
@@ -1609,14 +1487,6 @@ function createAppSystemApi(requester, connectionOwner) {
|
|
|
1609
1487
|
if (!validLocalWorkspaceResult(result, input.action)) throw new AppHostError("host_unavailable");
|
|
1610
1488
|
return result;
|
|
1611
1489
|
}),
|
|
1612
|
-
extensions: (input) => send("system.extensions", input),
|
|
1613
|
-
modelProviders: (input) => send("system.modelProviders", input),
|
|
1614
|
-
providerDefaults: (async (input) => {
|
|
1615
|
-
const result = await send("system.providerDefaults", input);
|
|
1616
|
-
if (!(input.action === "test" ? validProviderConnectionTestResult(result) : validProviderDefaultsSnapshot(result)))
|
|
1617
|
-
throw new AppHostError("invalid_request");
|
|
1618
|
-
return result;
|
|
1619
|
-
}),
|
|
1620
1490
|
open: (input) => {
|
|
1621
1491
|
if (input.page !== "session-settings") return send("system.open", input);
|
|
1622
1492
|
const { target: target2 } = input;
|
|
@@ -1640,9 +1510,6 @@ function createAppSystemApi(requester, connectionOwner) {
|
|
|
1640
1510
|
navigationReady: () => send("system.navigationReady", {}),
|
|
1641
1511
|
completeNavigation: (input) => send("system.completeNavigation", input)
|
|
1642
1512
|
};
|
|
1643
|
-
Object.defineProperty(system, channelSettingsKey, {
|
|
1644
|
-
value: (input) => send("system.channelSettings", input)
|
|
1645
|
-
});
|
|
1646
1513
|
return system;
|
|
1647
1514
|
}
|
|
1648
1515
|
|
|
@@ -1786,8 +1653,8 @@ function createAppAttachmentsApi(rpc, streams) {
|
|
|
1786
1653
|
|
|
1787
1654
|
// src/auxiliary.ts
|
|
1788
1655
|
var AUXILIARY_METHODS = ["sessions.getAuxiliaryOptions", "sessions.openAuxiliary", "sessions.getAuxiliary", "sessions.closeAuxiliary"];
|
|
1789
|
-
var
|
|
1790
|
-
var tuple = object({ connectionId: text(), sessionId: text(), requestId: id, id: text(), selection
|
|
1656
|
+
var selection = object({ optionsRevision: text(), model: text(), workMode: text(), effort: text(1024, true) });
|
|
1657
|
+
var tuple = object({ connectionId: text(), sessionId: text(), requestId: id, id: text(), selection });
|
|
1791
1658
|
var receipt2 = object({ requestId: id, id: text(), state: enumeration("opening", "open", "closing", "closed") }, { leaseId: text(), sessionId: text() });
|
|
1792
1659
|
function isAuxiliaryMethod(method) {
|
|
1793
1660
|
return AUXILIARY_METHODS.includes(method);
|
|
@@ -1871,27 +1738,6 @@ function createAppWorkspaceApi(input) {
|
|
|
1871
1738
|
};
|
|
1872
1739
|
}
|
|
1873
1740
|
|
|
1874
|
-
// src/session-resources.ts
|
|
1875
|
-
function resourceFields(v, required, optional = []) {
|
|
1876
|
-
if (!v || typeof v !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(v))) return false;
|
|
1877
|
-
return required.every((k) => Object.hasOwn(v, k)) && Reflect.ownKeys(v).every((k) => {
|
|
1878
|
-
const d = Object.getOwnPropertyDescriptor(v, k);
|
|
1879
|
-
return typeof k === "string" && [...required, ...optional].includes(k) && d.enumerable && Object.hasOwn(d, "value");
|
|
1880
|
-
});
|
|
1881
|
-
}
|
|
1882
|
-
var str2 = (v, max = 256) => typeof v === "string" && v.length > 0 && v.length <= max;
|
|
1883
|
-
function validSessionResourceResult(_method, v) {
|
|
1884
|
-
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}`;
|
|
1885
|
-
}
|
|
1886
|
-
function bindAuthorizedAgentConnection(input, streams) {
|
|
1887
|
-
return async (...args) => {
|
|
1888
|
-
if (args.length !== 0) throw new AppHostError("invalid_request");
|
|
1889
|
-
input.requireFeature();
|
|
1890
|
-
const wire = await input.request("getAuthorizedAgentConnection", {});
|
|
1891
|
-
return createClientConnection(wire, streams);
|
|
1892
|
-
};
|
|
1893
|
-
}
|
|
1894
|
-
|
|
1895
1741
|
// src/service.ts
|
|
1896
1742
|
function createAppServiceApi(rpc, streams) {
|
|
1897
1743
|
const request = async (method, params) => rpc.request(method, params);
|
|
@@ -1944,7 +1790,7 @@ function isAppLifecycleFrame(value) {
|
|
|
1944
1790
|
function createAppLifecycle(options) {
|
|
1945
1791
|
const handlers = /* @__PURE__ */ new Set();
|
|
1946
1792
|
let active;
|
|
1947
|
-
const
|
|
1793
|
+
const cancel = () => {
|
|
1948
1794
|
const old = active;
|
|
1949
1795
|
active = void 0;
|
|
1950
1796
|
old?.controller.abort();
|
|
@@ -1962,14 +1808,14 @@ function createAppLifecycle(options) {
|
|
|
1962
1808
|
};
|
|
1963
1809
|
const finish = (pending, ready) => {
|
|
1964
1810
|
if (active !== pending || pending.controller.signal.aborted) return;
|
|
1965
|
-
if (!ready)
|
|
1811
|
+
if (!ready) cancel();
|
|
1966
1812
|
options.send({ protocol: 1, type: "lifecycle-result", id: pending.id, ready });
|
|
1967
1813
|
};
|
|
1968
1814
|
return {
|
|
1969
1815
|
api,
|
|
1970
1816
|
receive(frame) {
|
|
1971
1817
|
if (frame.type === "lifecycle-cancel") {
|
|
1972
|
-
if (active?.id === frame.id)
|
|
1818
|
+
if (active?.id === frame.id) cancel();
|
|
1973
1819
|
return;
|
|
1974
1820
|
}
|
|
1975
1821
|
if (active) {
|
|
@@ -1987,7 +1833,7 @@ function createAppLifecycle(options) {
|
|
|
1987
1833
|
}))).then(() => finish(pending, true), () => finish(pending, false));
|
|
1988
1834
|
},
|
|
1989
1835
|
close() {
|
|
1990
|
-
|
|
1836
|
+
cancel();
|
|
1991
1837
|
handlers.clear();
|
|
1992
1838
|
}
|
|
1993
1839
|
};
|
|
@@ -2010,7 +1856,6 @@ var APP_HOST_METHODS = [
|
|
|
2010
1856
|
"storage.get",
|
|
2011
1857
|
"storage.set",
|
|
2012
1858
|
"storage.delete",
|
|
2013
|
-
"getAuthorizedAgentConnection",
|
|
2014
1859
|
"service.getStatus",
|
|
2015
1860
|
"service.getConnection",
|
|
2016
1861
|
"service.listWork",
|
|
@@ -2114,10 +1959,14 @@ function createDocumentPageFetchClient(options, getDocumentCloseError) {
|
|
|
2114
1959
|
const touch = (s) => {
|
|
2115
1960
|
if (s.stopped || closed) return;
|
|
2116
1961
|
clearTimeout(s.idleTimer);
|
|
2117
|
-
|
|
1962
|
+
const deadline = s.uploadDone && !s.headers ? Math.max(FETCH_IDLE_TIMEOUT_MS, s.headersTimeoutMs + 1e3) : FETCH_IDLE_TIMEOUT_MS;
|
|
1963
|
+
s.idleTimer = setTimeout(() => finish(s, timeout("idle_timeout"), true), deadline);
|
|
2118
1964
|
};
|
|
2119
1965
|
const waitForHeaders = (s) => {
|
|
2120
|
-
if (!s.headers)
|
|
1966
|
+
if (!s.headers) {
|
|
1967
|
+
s.headTimer = setTimeout(() => finish(s, timeout("headers_timeout"), true), s.headersTimeoutMs);
|
|
1968
|
+
touch(s);
|
|
1969
|
+
}
|
|
2121
1970
|
};
|
|
2122
1971
|
const shutdown = () => {
|
|
2123
1972
|
if (closed) return;
|
|
@@ -2197,6 +2046,7 @@ function createDocumentPageFetchClient(options, getDocumentCloseError) {
|
|
|
2197
2046
|
if (s.headers || message.hasBody && (s.request.method === "HEAD" || [204, 205, 304].includes(message.status))) throw error("invalid_request");
|
|
2198
2047
|
s.headers = true;
|
|
2199
2048
|
clearTimeout(s.headTimer);
|
|
2049
|
+
touch(s);
|
|
2200
2050
|
const body = message.hasBody ? new ReadableStream({
|
|
2201
2051
|
start(controller) {
|
|
2202
2052
|
s.controller = controller;
|
|
@@ -2277,9 +2127,10 @@ function createDocumentPageFetchClient(options, getDocumentCloseError) {
|
|
|
2277
2127
|
const request = new Request(input, init);
|
|
2278
2128
|
const id3 = String(nextId + 1);
|
|
2279
2129
|
let frame;
|
|
2130
|
+
let path;
|
|
2280
2131
|
try {
|
|
2281
2132
|
pageFetchPath(baseUrl, inputUrl);
|
|
2282
|
-
pageFetchPath(baseUrl, request.url);
|
|
2133
|
+
path = pageFetchPath(baseUrl, request.url);
|
|
2283
2134
|
if (request.signal.aborted) throw new DOMException("The operation was aborted", "AbortError");
|
|
2284
2135
|
if (streams.size >= FETCH_MAX_STREAMS) throw error("invalid_request");
|
|
2285
2136
|
frame = { protocol: 2, type: "fetch-open", id: id3, connectionId, url: request.url, method: request.method, headers: [...request.headers], hasBody: !!request.body };
|
|
@@ -2305,6 +2156,7 @@ function createDocumentPageFetchClient(options, getDocumentCloseError) {
|
|
|
2305
2156
|
reject,
|
|
2306
2157
|
headers: false,
|
|
2307
2158
|
stopped: false,
|
|
2159
|
+
headersTimeoutMs: pageFetchHeadersTimeout(request.method, path),
|
|
2308
2160
|
uploadDone: !request.body || frame.inlineBody !== void 0,
|
|
2309
2161
|
downloadEnded: false,
|
|
2310
2162
|
downloadDone: false,
|
|
@@ -2348,7 +2200,6 @@ function createDocumentPageFetchClient(options, getDocumentCloseError) {
|
|
|
2348
2200
|
}
|
|
2349
2201
|
|
|
2350
2202
|
// src/connection.ts
|
|
2351
|
-
var SKILL_MARKETPLACE_TIMEOUT_MS = 3e5;
|
|
2352
2203
|
var failure = (code) => new AppHostError(code);
|
|
2353
2204
|
function invalidHostResponse(reason, frameKind, stage, operation) {
|
|
2354
2205
|
const details = { reason, frameKind, stage, ...operation };
|
|
@@ -2488,8 +2339,6 @@ function validResult(method, value) {
|
|
|
2488
2339
|
if (isAuxiliaryMethod(method)) return validAuxiliaryResult(method, value);
|
|
2489
2340
|
if (isConversationPreparationMethod(method))
|
|
2490
2341
|
return validConversationPreparationResult(method, value);
|
|
2491
|
-
if (method === "getAuthorizedAgentConnection")
|
|
2492
|
-
return validSessionResourceResult(method, value);
|
|
2493
2342
|
if (method.startsWith("workspace."))
|
|
2494
2343
|
return validWorkspaceResult(method, value);
|
|
2495
2344
|
if (method.startsWith("service."))
|
|
@@ -2824,13 +2673,6 @@ var DocumentConnection = class {
|
|
|
2824
2673
|
},
|
|
2825
2674
|
this.fetchClient
|
|
2826
2675
|
),
|
|
2827
|
-
getAuthorizedAgentConnection: bindAuthorizedAgentConnection(
|
|
2828
|
-
{
|
|
2829
|
-
requireFeature: () => this.requireFeature("session-resources-v1"),
|
|
2830
|
-
request: (method, params2) => this.request(method, params2)
|
|
2831
|
-
},
|
|
2832
|
-
this.fetchClient
|
|
2833
|
-
),
|
|
2834
2676
|
sessions: {
|
|
2835
2677
|
preparation: conversationPreparation,
|
|
2836
2678
|
auxiliary: createAppAuxiliarySessionsApi(
|
|
@@ -2871,11 +2713,11 @@ var DocumentConnection = class {
|
|
|
2871
2713
|
get: (key) => this.request("storage.get", { key }),
|
|
2872
2714
|
set: (key, value) => this.request("storage.set", { key, value }),
|
|
2873
2715
|
delete: (key) => this.request("storage.delete", { key }),
|
|
2874
|
-
putFile: async (
|
|
2875
|
-
if (!(data instanceof Blob) || !nonempty(
|
|
2716
|
+
putFile: async (name, data) => {
|
|
2717
|
+
if (!(data instanceof Blob) || !nonempty(name) || data.size + new TextEncoder().encode(JSON.stringify({ name })).byteLength > APP_HOST_MAX_PAYLOAD_BYTES)
|
|
2876
2718
|
throw failure("invalid_request");
|
|
2877
2719
|
return this.request("storage.putFile", {
|
|
2878
|
-
name
|
|
2720
|
+
name,
|
|
2879
2721
|
bytes: new Uint8Array(await data.arrayBuffer())
|
|
2880
2722
|
});
|
|
2881
2723
|
},
|
|
@@ -2933,12 +2775,6 @@ var DocumentConnection = class {
|
|
|
2933
2775
|
if (method === "workbench.computer.stopLocal") timeout = 1e3;
|
|
2934
2776
|
if (method === "auth.openLogin" || method === "workspace.select" || method === "workbench.computer.shareWindow" || method === "system.workspace" && "action" in params && params.action === "pick")
|
|
2935
2777
|
timeout = APP_HOST_LOGIN_TRANSPORT_TIMEOUT_MS;
|
|
2936
|
-
if (method === "system.extensions") {
|
|
2937
|
-
const { operation } = params;
|
|
2938
|
-
if (operation === "skills.marketplaceCatalog" || operation === "skills.marketplaceInstall") {
|
|
2939
|
-
timeout = SKILL_MARKETPLACE_TIMEOUT_MS;
|
|
2940
|
-
}
|
|
2941
|
-
}
|
|
2942
2778
|
return new Promise((resolve, reject) => {
|
|
2943
2779
|
const id3 = String(++this.nextId);
|
|
2944
2780
|
const timer = setTimeout(() => {
|
|
@@ -3006,14 +2842,14 @@ function copyBoundedJson(value, options) {
|
|
|
3006
2842
|
return item;
|
|
3007
2843
|
}
|
|
3008
2844
|
if (typeof item !== "object" || item === null || depth >= maxDepth || ancestors.has(item)) throw new JsonCopyError("invalid_json");
|
|
3009
|
-
const
|
|
3010
|
-
if (!
|
|
2845
|
+
const array3 = Array.isArray(item);
|
|
2846
|
+
if (!array3 && Object.getPrototypeOf(item) !== Object.prototype && Object.getPrototypeOf(item) !== null) throw new JsonCopyError("invalid_json");
|
|
3011
2847
|
const descriptors = Object.getOwnPropertyDescriptors(item);
|
|
3012
2848
|
if (Object.getOwnPropertySymbols(item).length || Object.values(descriptors).some((descriptor) => descriptor.get || descriptor.set)) throw new JsonCopyError("invalid_json");
|
|
3013
2849
|
ancestors.add(item);
|
|
3014
|
-
spend(
|
|
2850
|
+
spend(array3 ? "[]" : "{}");
|
|
3015
2851
|
try {
|
|
3016
|
-
if (
|
|
2852
|
+
if (array3) {
|
|
3017
2853
|
const result2 = [];
|
|
3018
2854
|
if (Object.keys(item).length !== item.length) throw new JsonCopyError("invalid_json");
|
|
3019
2855
|
for (let index = 0; index < item.length; index++) {
|
|
@@ -3106,7 +2942,7 @@ function parsePluginAppConversationInput(value) {
|
|
|
3106
2942
|
source: parsePluginAppSource(input.source),
|
|
3107
2943
|
lease: { token: identifier2(lease.token), backendGeneration: identifier2(lease.backendGeneration) },
|
|
3108
2944
|
requestId: identifier2(input.requestId),
|
|
3109
|
-
expectedRevision:
|
|
2945
|
+
expectedRevision: revision(input.expectedRevision),
|
|
3110
2946
|
text: input.text,
|
|
3111
2947
|
data: copyPluginAppJson(input.data, PLUGIN_APP_INPUT_LIMITS.handoffBytes)
|
|
3112
2948
|
};
|
|
@@ -3116,13 +2952,13 @@ function record3(value) {
|
|
|
3116
2952
|
return value;
|
|
3117
2953
|
}
|
|
3118
2954
|
function fields3(value, names) {
|
|
3119
|
-
if (Object.keys(value).length !== names.length || names.some((
|
|
2955
|
+
if (Object.keys(value).length !== names.length || names.some((name) => !Object.hasOwn(value, name))) throw new InputError("plugin_app_invalid_request");
|
|
3120
2956
|
}
|
|
3121
2957
|
function identifier2(value) {
|
|
3122
2958
|
if (typeof value !== "string" || !value.trim() || value.length > 1024) throw new InputError("plugin_app_invalid_request");
|
|
3123
2959
|
return value;
|
|
3124
2960
|
}
|
|
3125
|
-
function
|
|
2961
|
+
function revision(value) {
|
|
3126
2962
|
if (!Number.isSafeInteger(value) || value < 0) throw new InputError("plugin_app_invalid_request");
|
|
3127
2963
|
return value;
|
|
3128
2964
|
}
|
|
@@ -3166,9 +3002,9 @@ function parsePluginAppComposerContexts2(value) {
|
|
|
3166
3002
|
}
|
|
3167
3003
|
export {
|
|
3168
3004
|
AppHostError,
|
|
3169
|
-
EXTENSION_INPUTS,
|
|
3170
3005
|
WINDOW_METHODS,
|
|
3171
3006
|
canonicalDesktopRequest,
|
|
3007
|
+
connectAgent,
|
|
3172
3008
|
connectAppHost,
|
|
3173
3009
|
createAppWindowApi,
|
|
3174
3010
|
createPageFetchClient,
|
|
@@ -3176,8 +3012,6 @@ export {
|
|
|
3176
3012
|
parsePluginAppComposerContexts2 as parsePluginAppComposerContexts,
|
|
3177
3013
|
validAppCommandSnapshot,
|
|
3178
3014
|
validAppWindowState,
|
|
3179
|
-
validExtensionRequest,
|
|
3180
|
-
validExtensionResult,
|
|
3181
3015
|
validWindowEvent,
|
|
3182
3016
|
validWindowInput,
|
|
3183
3017
|
validWindowResult
|