@xopcai/xopc 0.0.395 → 0.0.397
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/browser-ext/manifest.json +1 -1
- package/dist/extensions/telegram/src/plugin.js +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-BRtkz-ZU.js → agent-avatar-dicebear-CIEGrioy.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-defaults-settings-panel-Dqg2NOn-.js → agent-defaults-settings-panel-CzKNVkRn.js} +1 -1
- package/dist/gateway/static/root/assets/agent-plugin-dialog-mpA9rwYd.js +1 -0
- package/dist/gateway/static/root/assets/{agents-0zgLsfVA.js → agents-7VMa7Rzo.js} +3 -3
- package/dist/gateway/static/root/assets/{app-management-settings-panel-BZS8FvoL.js → app-management-settings-panel-DIJ0ii-n.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-RxXMAxiB.js → appearance-settings-BGnyHS-p.js} +1 -1
- package/dist/gateway/static/root/assets/apps-page-CvqDUvof.js +1 -0
- package/dist/gateway/static/root/assets/{archive-plugin-DEnHq3OR.js → archive-plugin-CR8FcRAa.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-page-BwkugzB8.js → automations-page-BLInZo7N.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-workspace-K8aDhoYt.js → automations-workspace-DvTSHLt3.js} +1 -1
- package/dist/gateway/static/root/assets/{binary-plugins-NWeXhh1k.js → binary-plugins-DW9pu205.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-D_bKN3BN.js → block-editor-ClgTc5v8.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-automation-inputs-vtPkXfJ8.js → browser-automation-inputs-Bn7kDuUB.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-automations-page-DBPbwOG8.js → browser-automations-page-CJGBhDnv.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-settings-page-VBZDYoXD.js → browser-settings-page-tsi5W-cJ.js} +1 -1
- package/dist/gateway/static/root/assets/capabilities-page-CfbGk8q_.js +2 -0
- package/dist/gateway/static/root/assets/{capabilities-settings-panel-C_OMsW_8.js → capabilities-settings-panel-BkO7QEyA.js} +1 -1
- package/dist/gateway/static/root/assets/{capability-header-actions-CMJXWq8a.js → capability-header-actions-9ZG71-BO.js} +1 -1
- package/dist/gateway/static/root/assets/{channels-C_TVCc1N.js → channels-D0CwJktG.js} +1 -1
- package/dist/gateway/static/root/assets/{chat-terminal-dock-9YRAokOl.js → chat-terminal-dock-x1W2_hwc.js} +1 -1
- package/dist/gateway/static/root/assets/{computer-settings-page-BPYAZ4ks.js → computer-settings-page-D_b_bFVz.js} +1 -1
- package/dist/gateway/static/root/assets/{connector-service-page-B81cEAEX.js → connector-service-page-Kf8kaNm_.js} +1 -1
- package/dist/gateway/static/root/assets/{connectors-page-C0NvAP2V.js → connectors-page-DlpfL2Rc.js} +1 -1
- package/dist/gateway/static/root/assets/{date-picker-BvKP4P3n.js → date-picker-d5kiPUG0.js} +1 -1
- package/dist/gateway/static/root/assets/{dependency-picker-TvrNaf8y.js → dependency-picker-BcH76tQC.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-De-_QNSD.js → desktop-pet-B-925tPX.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-CRSRTIwT.js → desktop-pet-settings-3XJ4qR65.js} +1 -1
- package/dist/gateway/static/root/assets/device-pairing-wizard-12m5Z9-8.js +1 -0
- package/dist/gateway/static/root/assets/{directory-picker-path-field-DOPXwYNR.js → directory-picker-path-field-B-qZCjGR.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-DzXvpUwj.js → extension-debug-page-BlQu1u6X.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-C0S1zNeP.js → extension-page-CXxM1M62.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-C3Z7bFjy.js → extension-settings-page-AF5nvsPP.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-settings-Btc2wTQe.js → gateway-settings-ABXvW_yL.js} +1 -1
- package/dist/gateway/static/root/assets/{highlighted-body-KQOG7T2V-BFYBbh1P.js → highlighted-body-KQOG7T2V-Czdbbi0H.js} +1 -1
- package/dist/gateway/static/root/assets/{home-page-C5sLR47Q.js → home-page-LXGxGwVl.js} +1 -1
- package/dist/gateway/static/root/assets/{image-generation-api-Vqcyqnzb.js → image-generation-api-DPFPJ2ps.js} +1 -1
- package/dist/gateway/static/root/assets/{imports-page-BJGHrzhX.js → imports-page-Bwyotfbt.js} +1 -1
- package/dist/gateway/static/root/assets/index-BKHxJaGD.css +1 -0
- package/dist/gateway/static/root/assets/{index-BNRLzxpH.js → index-Dsp_gNdl.js} +116 -116
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-BQkQoPmm.js → keyboard-shortcuts-settings-C20gl-l7.js} +1 -1
- package/dist/gateway/static/root/assets/{local-app-workbench-page-DbxLz9Ms.js → local-app-workbench-page-o0M_OSjC.js} +1 -1
- package/dist/gateway/static/root/assets/{local-apps-page-CaatwSrK.js → local-apps-page-DoWJCmOq.js} +1 -1
- package/dist/gateway/static/root/assets/{logs-page-3Wo4Lmts.js → logs-page-BFTL93RX.js} +1 -1
- package/dist/gateway/static/root/assets/{management-settings-BHlbM8IM.js → management-settings-C52cuMg1.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-Cq1uLrd8.js → media-plugins-DLrTRF0a.js} +1 -1
- package/dist/gateway/static/root/assets/mermaid-MCJ5UELQ-CPYJsRUJ.js +1 -0
- package/dist/gateway/static/root/assets/{note-detail-panel-MjKND8HC.js → note-detail-panel-CNN41byS.js} +3 -3
- package/dist/gateway/static/root/assets/{notes-page-Cv040hVD.js → notes-page-BsfBp_8z.js} +1 -1
- package/dist/gateway/static/root/assets/{page-context-capture-button-Cp71nTq2.js → page-context-capture-button-YTVWZ02-.js} +1 -1
- package/dist/gateway/static/root/assets/{personal-page-CyEUWV2n.js → personal-page-N4KoCZYG.js} +1 -1
- package/dist/gateway/static/root/assets/plugin-details-page-DcrrzQI-.js +1 -0
- package/dist/gateway/static/root/assets/{preview-open-alternatives-gzCecXc4.js → preview-open-alternatives-DzA__S54.js} +1 -1
- package/dist/gateway/static/root/assets/{product-open-page-CWFT7VuQ.js → product-open-page-DvlMKj0T.js} +1 -1
- package/dist/gateway/static/root/assets/{product-preview-content-Dh111Kca.js → product-preview-content-qdFyo4NG.js} +1 -1
- package/dist/gateway/static/root/assets/{project-detail-page-CyhyZiTi.js → project-detail-page-y67s_fA8.js} +1 -1
- package/dist/gateway/static/root/assets/{projects-page-QUdyJino.js → projects-page-D5iYgi0O.js} +1 -1
- package/dist/gateway/static/root/assets/{remote-access-hub-Cd8P0Dxs.js → remote-access-hub-DeFF7Re-.js} +1 -1
- package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-bTjVfYm5.js → runtime-tools-settings-panel-BCHLh-KQ.js} +1 -1
- package/dist/gateway/static/root/assets/{schema-form-BGOzfVyj.js → schema-form-CJvaVHkx.js} +1 -1
- package/dist/gateway/static/root/assets/{sessions-page-BGMemJF6.js → sessions-page-DZ93_D5M.js} +1 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-F1WX7vxq.js +1 -0
- package/dist/gateway/static/root/assets/{settings-form-section-Bqm1IKvR.js → settings-form-section-B3eODxNv.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-CniJVL-o.js → settings-page-Dg86uCnr.js} +1 -1
- package/dist/gateway/static/root/assets/{setup-status-panel-JPs4-QRw.js → setup-status-panel-ruFzAArp.js} +1 -1
- package/dist/gateway/static/root/assets/{share-preview-page-BnDGFgBR.js → share-preview-page-DCy1f25V.js} +1 -1
- package/dist/gateway/static/root/assets/{shares-settings-Cgp5BuLt.js → shares-settings-DeIVZvpJ.js} +1 -1
- package/dist/gateway/static/root/assets/{skill-api-CFdrz6tl.js → skill-api-RisyPAMA.js} +1 -1
- package/dist/gateway/static/root/assets/{skill-reload-api-Cy5jVfms.js → skill-reload-api-Dwkm1Fof.js} +1 -1
- package/dist/gateway/static/root/assets/{skills-page-CxaA3P5E.js → skills-page-UiTLsrFc.js} +1 -1
- package/dist/gateway/static/root/assets/{style-C_MAnir7.js → style-CwMX73G7.js} +1 -1
- package/dist/gateway/static/root/assets/{system-settings-panel-BjnIlilP.js → system-settings-panel-Cma37Pfm.js} +1 -1
- package/dist/gateway/static/root/assets/{task-detail-page-Bg79rPnF.js → task-detail-page-BKOF_kxS.js} +1 -1
- package/dist/gateway/static/root/assets/{tracing-settings-page-BCI0tUbe.js → tracing-settings-page-DC-kLysq.js} +1 -1
- package/dist/gateway/static/root/assets/{tunnel-api-0knnta9z.js → tunnel-api-BgdhbR1L.js} +1 -1
- package/dist/gateway/static/root/assets/{usage-page-D5aT1eie.js → usage-page-BSlFg3Xj.js} +1 -1
- package/dist/gateway/static/root/assets/{use-autosave-Ds_mbAfe.js → use-autosave-iKvZ1pvC.js} +1 -1
- package/dist/gateway/static/root/assets/{user-model-page-D7L0-pDt.js → user-model-page-D4GB8QsM.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-api-key-field-CPoGdarN.js → voice-api-key-field-CESbtuwM.js} +1 -1
- package/dist/gateway/static/root/assets/{work-discovery-overlay-CWNguy2Z.js → work-discovery-overlay-dtPpmYyh.js} +1 -1
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-BcDMFfkT.js → workflow-run-setup-panel-DmFn3E_B.js} +1 -1
- package/dist/gateway/static/root/assets/{workflows-page-BwZB-s4N.js → workflows-page-DEtaRuxH.js} +1 -1
- package/dist/gateway/static/root/assets/{xopc-cloud-account-card-DlKr98VO.js → xopc-cloud-account-card-DTZnabfg.js} +1 -1
- package/dist/gateway/static/root/index.html +2 -2
- package/dist/package.js +1 -1
- package/dist/src/agent/embedded/codemode-extension.d.ts +1 -0
- package/dist/src/agent/embedded/codemode-extension.js +6 -1
- package/dist/src/agent/embedded/run-for-session.js +1 -1
- package/dist/src/agent/embedded/run-turn.js +34 -2
- package/dist/src/agent/embedded/session-runner.js +1 -1
- package/dist/src/agent/mcp/config.d.ts +2 -0
- package/dist/src/agent/mcp/config.js +2 -2
- package/dist/src/agent/mcp/connection-setup.js +13 -1
- package/dist/src/agent/mcp/effective-server.d.ts +3 -0
- package/dist/src/agent/mcp/effective-server.js +27 -0
- package/dist/src/agent/mcp/native-mcp.d.ts +1 -1
- package/dist/src/agent/mcp/native-mcp.js +13 -4
- package/dist/src/agent/mcp/tool-catalog.js +2 -1
- package/dist/src/agent/skills/index.d.ts +1 -0
- package/dist/src/agent/skills/index.js +6 -2
- package/dist/src/agent/skills/skill-manager.d.ts +1 -0
- package/dist/src/agent/skills/skill-manager.js +6 -1
- package/dist/src/agent/skills/skill-sources.d.ts +1 -0
- package/dist/src/agent/skills/skill-sources.js +4 -3
- package/dist/src/agent/skills/types.d.ts +1 -0
- package/dist/src/agent/workspace-runtime/registry.js +6 -2
- package/dist/src/browser/native-messaging-host.js +1 -1
- package/dist/src/browser/providers/browser-ext-install.js +2 -2
- package/dist/src/channels/index.js +1 -1
- package/dist/src/channels/manager.js +1 -1
- package/dist/src/cli/commands/channels.js +1 -1
- package/dist/src/cli/commands/connectors.js +1 -1
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/cli/commands/extension-agent-plugin.js +92 -7
- package/dist/src/cli/commands/extension-marketplace.js +2 -2
- package/dist/src/cli/commands/extension.js +1 -1
- package/dist/src/cli/commands/mcp.js +6 -4
- package/dist/src/cli/commands/models.js +1 -1
- package/dist/src/cli/commands/onboard/model.js +1 -1
- package/dist/src/cli/commands/onboard.js +1 -1
- package/dist/src/extensions/agent-plugins/auth.d.ts +7 -1
- package/dist/src/extensions/agent-plugins/auth.js +53 -12
- package/dist/src/extensions/agent-plugins/branding.d.ts +6 -0
- package/dist/src/extensions/agent-plugins/branding.js +44 -0
- package/dist/src/extensions/agent-plugins/cli-authorization.d.ts +22 -0
- package/dist/src/extensions/agent-plugins/cli-authorization.js +198 -0
- package/dist/src/extensions/agent-plugins/connection-reuse.d.ts +10 -0
- package/dist/src/extensions/agent-plugins/connection-reuse.js +23 -0
- package/dist/src/extensions/agent-plugins/credentials.js +24 -1
- package/dist/src/extensions/agent-plugins/formats.d.ts +27 -0
- package/dist/src/extensions/agent-plugins/formats.js +208 -0
- package/dist/src/extensions/agent-plugins/inventory.d.ts +142 -2
- package/dist/src/extensions/agent-plugins/inventory.js +39 -5
- package/dist/src/extensions/agent-plugins/mcp-adapter.d.ts +2 -1
- package/dist/src/extensions/agent-plugins/mcp-adapter.js +42 -8
- package/dist/src/extensions/agent-plugins/mcp-format.d.ts +2 -0
- package/dist/src/extensions/agent-plugins/mcp-format.js +82 -0
- package/dist/src/extensions/agent-plugins/resources.d.ts +14 -0
- package/dist/src/extensions/agent-plugins/resources.js +112 -0
- package/dist/src/extensions/agent-plugins/setup-contract.d.ts +54 -0
- package/dist/src/extensions/agent-plugins/setup-contract.js +58 -0
- package/dist/src/extensions/agent-plugins/setup.d.ts +119 -0
- package/dist/src/extensions/agent-plugins/setup.js +491 -0
- package/dist/src/extensions/agent-plugins/source-catalog.d.ts +21 -0
- package/dist/src/extensions/agent-plugins/source-catalog.js +175 -0
- package/dist/src/extensions/agent-plugins/sources.d.ts +1 -1
- package/dist/src/extensions/agent-plugins/sources.js +12 -3
- package/dist/src/extensions/agent-plugins/store.d.ts +33 -2
- package/dist/src/extensions/agent-plugins/store.js +175 -25
- package/dist/src/extensions/agent-plugins/user-config.d.ts +5 -0
- package/dist/src/extensions/agent-plugins/user-config.js +49 -0
- package/dist/src/extensions/agent-plugins/validation.d.ts +26 -1
- package/dist/src/extensions/agent-plugins/validation.js +142 -27
- package/dist/src/extensions/sdk/index.js +1 -1
- package/dist/src/gateway/hono/app.js +1 -1
- package/dist/src/gateway/hono/routes/agent-plugins.js +120 -9
- package/dist/src/gateway/hono/routes/browser-install.js +1 -1
- package/dist/src/gateway/hono/routes/composer-history.js +22 -4
- package/dist/src/gateway/hono/routes/mcp.js +6 -4
- package/dist/src/gateway/hono/routes/provider-setup.js +7 -0
- package/dist/src/gateway/service.js +11 -9
- package/dist/src/gateway/session-context-summary.js +1 -1
- package/dist/src/gateway/xopc-cloud-capability-setup.d.ts +4 -0
- package/dist/src/gateway/xopc-cloud-capability-setup.js +90 -26
- package/dist/src/home-intelligence/host.js +2 -2
- package/dist/src/providers/setup/engine.js +12 -10
- package/dist/src/providers/setup/voice.js +24 -6
- package/dist/src/storage/sqlite/composer-input-history-repository.d.ts +4 -3
- package/dist/src/storage/sqlite/composer-input-history-repository.js +10 -8
- package/dist/src/storage/sqlite/device-pairing-approval.js +1 -1
- package/dist/src/storage/sqlite/migrations/257_session_composer_history.sql +11 -0
- package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
- package/dist/src/storage/sqlite/migrations/runner.js +3 -3
- package/dist/src/storage/sqlite/schema.js +1 -1
- package/dist/src/tui/backends/embedded-backend.d.ts +2 -2
- package/dist/src/tui/backends/embedded-backend.js +4 -4
- package/dist/src/tui/backends/gateway-realtime-backend.d.ts +2 -2
- package/dist/src/tui/backends/gateway-realtime-backend.js +7 -4
- package/dist/src/tui/composer-history.d.ts +14 -0
- package/dist/src/tui/composer-history.js +85 -0
- package/dist/src/tui/tui-backend.d.ts +4 -3
- package/dist/src/tui/tui.js +19 -46
- package/package.json +12 -4
- package/dist/gateway/static/root/assets/agent-plugin-dialog-CKK95Jmr.js +0 -1
- package/dist/gateway/static/root/assets/apps-page-mGU9WLjP.js +0 -1
- package/dist/gateway/static/root/assets/capabilities-page-CQsGp9Sx.js +0 -2
- package/dist/gateway/static/root/assets/device-pairing-wizard-DnyJ8Bja.js +0 -1
- package/dist/gateway/static/root/assets/index-zIgp-ZTu.css +0 -1
- package/dist/gateway/static/root/assets/mermaid-MCJ5UELQ-XhlIBp5t.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-BiySFw1N.js +0 -1
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { createPluginSourceFetch } from "./source-http-fetch.js";
|
|
2
|
+
import { containedPath } from "./validation.js";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
//#region src/extensions/agent-plugins/resources.ts
|
|
8
|
+
const resourceVariant = z.strictObject({
|
|
9
|
+
url: z.string().url(),
|
|
10
|
+
sha256: z.string().regex(/^[a-f0-9]{64}$/),
|
|
11
|
+
maxBytes: z.number().int().positive().max(50 * 1024 * 1024).default(50 * 1024 * 1024),
|
|
12
|
+
executable: z.boolean().default(false),
|
|
13
|
+
platform: z.enum([
|
|
14
|
+
"darwin",
|
|
15
|
+
"linux",
|
|
16
|
+
"win32"
|
|
17
|
+
]).optional(),
|
|
18
|
+
arch: z.enum(["arm64", "x64"]).optional()
|
|
19
|
+
});
|
|
20
|
+
const resourceId = z.string().min(1).max(64).regex(/^[a-z][a-z0-9]*(?:[-.][a-z0-9]+)*$/);
|
|
21
|
+
const resourcesSchema = z.array(z.union([resourceVariant.extend({ id: resourceId }).strict(), z.strictObject({
|
|
22
|
+
id: resourceId,
|
|
23
|
+
variants: z.array(resourceVariant).min(1).max(6)
|
|
24
|
+
})])).max(20);
|
|
25
|
+
function pluginResources(plugin) {
|
|
26
|
+
const extension = plugin.manifest.extensions?.["ai.xopc"];
|
|
27
|
+
if (extension?.setup?.version !== void 0 && extension.setup.version !== 1) throw new Error("Unsupported plugin setup protocol version");
|
|
28
|
+
const ids = /* @__PURE__ */ new Set();
|
|
29
|
+
return resourcesSchema.parse(extension?.setup?.resources ?? []).map((resource) => {
|
|
30
|
+
if (ids.has(resource.id)) throw new Error("Duplicate plugin resource");
|
|
31
|
+
ids.add(resource.id);
|
|
32
|
+
if (!("variants" in resource)) return resource;
|
|
33
|
+
const matches = resource.variants.filter((value) => (!value.platform || value.platform === process.platform) && (!value.arch || value.arch === process.arch));
|
|
34
|
+
if (matches.length !== 1) throw new Error(`Expected one resource variant for this platform: ${resource.id}`);
|
|
35
|
+
return {
|
|
36
|
+
...matches[0],
|
|
37
|
+
id: resource.id
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function verified(path, sha256, maxBytes) {
|
|
42
|
+
if (!existsSync(path)) return;
|
|
43
|
+
const stat = statSync(path);
|
|
44
|
+
if (!stat.isFile() || stat.size > maxBytes) return;
|
|
45
|
+
const data = readFileSync(path);
|
|
46
|
+
return createHash("sha256").update(data).digest("hex") === sha256 ? data : void 0;
|
|
47
|
+
}
|
|
48
|
+
function atomicFile(path, data, mode) {
|
|
49
|
+
mkdirSync(dirname(path), {
|
|
50
|
+
recursive: true,
|
|
51
|
+
mode: 448
|
|
52
|
+
});
|
|
53
|
+
const pending = `${path}.${randomUUID()}.tmp`;
|
|
54
|
+
try {
|
|
55
|
+
writeFileSync(pending, data, {
|
|
56
|
+
mode,
|
|
57
|
+
flag: "wx"
|
|
58
|
+
});
|
|
59
|
+
renameSync(pending, path);
|
|
60
|
+
} finally {
|
|
61
|
+
rmSync(pending, { force: true });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** Download pinned files; execute them only later through an explicitly reviewed MCP process. */
|
|
65
|
+
async function preparePluginResources(store, plugin, signal) {
|
|
66
|
+
const dataRoot = store.dataDir(plugin.id), cacheRoot = join(store.stateDir, "plugin-resource-cache");
|
|
67
|
+
for (const resource of pluginResources(plugin)) {
|
|
68
|
+
signal.throwIfAborted();
|
|
69
|
+
if (resource.platform && resource.platform !== process.platform || resource.arch && resource.arch !== process.arch) throw new Error(`Resource is unavailable for this platform: ${resource.id}`);
|
|
70
|
+
const target = containedPath(dataRoot, join(dataRoot, "resources", plugin.receipt.revision, resource.id));
|
|
71
|
+
if (verified(target, resource.sha256, resource.maxBytes) && (!resource.executable || (statSync(target).mode & 73) !== 0)) continue;
|
|
72
|
+
const cached = containedPath(cacheRoot, join(cacheRoot, resource.sha256));
|
|
73
|
+
let data = verified(cached, resource.sha256, resource.maxBytes);
|
|
74
|
+
if (!data) {
|
|
75
|
+
const url = new URL(resource.url);
|
|
76
|
+
const response = await createPluginSourceFetch(url, {})(url, { signal: AbortSignal.any([signal, AbortSignal.timeout(6e4)]) });
|
|
77
|
+
if (!response.ok || !response.body) throw new Error(`Resource download failed: ${resource.id}`);
|
|
78
|
+
const chunks = [];
|
|
79
|
+
let bytes = 0;
|
|
80
|
+
const reader = response.body.getReader();
|
|
81
|
+
try {
|
|
82
|
+
for (;;) {
|
|
83
|
+
const part = await reader.read();
|
|
84
|
+
if (part.done) break;
|
|
85
|
+
bytes += part.value.length;
|
|
86
|
+
if (bytes > resource.maxBytes) throw new Error("Resource exceeds size limit");
|
|
87
|
+
chunks.push(part.value);
|
|
88
|
+
}
|
|
89
|
+
} finally {
|
|
90
|
+
await reader.cancel();
|
|
91
|
+
}
|
|
92
|
+
data = Buffer.concat(chunks);
|
|
93
|
+
if (createHash("sha256").update(data).digest("hex") !== resource.sha256) throw new Error(`Resource integrity failed: ${resource.id}`);
|
|
94
|
+
}
|
|
95
|
+
signal.throwIfAborted();
|
|
96
|
+
const content = data;
|
|
97
|
+
store.withRevision(plugin.id, plugin.receipt.revision, () => {
|
|
98
|
+
atomicFile(cached, content, 384);
|
|
99
|
+
atomicFile(containedPath(dataRoot, target), content, resource.executable ? 448 : 384);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** Derive ownership from retained revisions, including rollback and staged packages. */
|
|
104
|
+
function prunePluginResourceCache(store) {
|
|
105
|
+
const cacheRoot = join(store.stateDir, "plugin-resource-cache");
|
|
106
|
+
if (!existsSync(cacheRoot)) return;
|
|
107
|
+
const referenced = /* @__PURE__ */ new Set();
|
|
108
|
+
for (const plugin of store.list()) for (const revision of store.history(plugin.id)) if (existsSync(revision.rootDir)) for (const hash of revision.receipt.resourceHashes ?? []) referenced.add(hash);
|
|
109
|
+
for (const name of readdirSync(cacheRoot)) if (/^[a-f0-9]{64}$/.test(name) && !referenced.has(name)) rmSync(join(cacheRoot, name), { force: true });
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
112
|
+
export { pluginResources, preparePluginResources, prunePluginResourceCache };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const setupCommandSchema: z.ZodObject<{
|
|
3
|
+
command: z.ZodString;
|
|
4
|
+
args: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
5
|
+
env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
6
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
7
|
+
}, z.core.$strict>;
|
|
8
|
+
export declare const pluginAuthorizationSchema: z.ZodArray<z.ZodObject<{
|
|
9
|
+
id: z.ZodString;
|
|
10
|
+
title: z.ZodString;
|
|
11
|
+
description: z.ZodOptional<z.ZodString>;
|
|
12
|
+
servers: z.ZodArray<z.ZodString>;
|
|
13
|
+
methods: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
14
|
+
type: z.ZodLiteral<"oauth">;
|
|
15
|
+
server: z.ZodString;
|
|
16
|
+
id: z.ZodString;
|
|
17
|
+
title: z.ZodString;
|
|
18
|
+
instructions: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
19
|
+
helpUrl: z.ZodOptional<z.ZodString>;
|
|
20
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
21
|
+
type: z.ZodLiteral<"form">;
|
|
22
|
+
fields: z.ZodArray<z.ZodString>;
|
|
23
|
+
id: z.ZodString;
|
|
24
|
+
title: z.ZodString;
|
|
25
|
+
instructions: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
26
|
+
helpUrl: z.ZodOptional<z.ZodString>;
|
|
27
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
28
|
+
type: z.ZodLiteral<"cli">;
|
|
29
|
+
fields: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
30
|
+
login: z.ZodObject<{
|
|
31
|
+
command: z.ZodString;
|
|
32
|
+
args: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
33
|
+
env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
34
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
35
|
+
}, z.core.$strict>;
|
|
36
|
+
check: z.ZodObject<{
|
|
37
|
+
command: z.ZodString;
|
|
38
|
+
args: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
39
|
+
env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
40
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
41
|
+
}, z.core.$strict>;
|
|
42
|
+
timeoutSeconds: z.ZodDefault<z.ZodNumber>;
|
|
43
|
+
id: z.ZodString;
|
|
44
|
+
title: z.ZodString;
|
|
45
|
+
instructions: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
46
|
+
helpUrl: z.ZodOptional<z.ZodString>;
|
|
47
|
+
}, z.core.$strict>], "type">>;
|
|
48
|
+
}, z.core.$strict>>;
|
|
49
|
+
export type PluginAuthorization = z.infer<typeof pluginAuthorizationSchema>[number];
|
|
50
|
+
export type SetupCommand = z.infer<typeof setupCommandSchema>;
|
|
51
|
+
export declare function pluginAuthorizations(manifest: {
|
|
52
|
+
extensions?: Record<string, unknown>;
|
|
53
|
+
}): PluginAuthorization[];
|
|
54
|
+
export declare function safeAuthorizationUrl(value: string): string;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/extensions/agent-plugins/setup-contract.ts
|
|
3
|
+
const id = z.string().min(1).max(64).regex(/^[a-z][a-z0-9-]*$/);
|
|
4
|
+
const setupCommandSchema = z.strictObject({
|
|
5
|
+
command: z.string().min(1),
|
|
6
|
+
args: z.array(z.string()).max(100).default([]),
|
|
7
|
+
env: z.record(z.string(), z.string()).default({}),
|
|
8
|
+
cwd: z.string().optional()
|
|
9
|
+
});
|
|
10
|
+
const guidance = {
|
|
11
|
+
id,
|
|
12
|
+
title: z.string().min(1).max(100),
|
|
13
|
+
instructions: z.array(z.string().min(1).max(1e3)).max(12).default([]),
|
|
14
|
+
helpUrl: z.string().url().optional()
|
|
15
|
+
};
|
|
16
|
+
const pluginAuthorizationSchema = z.array(z.strictObject({
|
|
17
|
+
id,
|
|
18
|
+
title: z.string().min(1).max(100),
|
|
19
|
+
description: z.string().max(1e3).optional(),
|
|
20
|
+
servers: z.array(z.string().min(1)).min(1).max(20),
|
|
21
|
+
methods: z.array(z.discriminatedUnion("type", [
|
|
22
|
+
z.strictObject({
|
|
23
|
+
...guidance,
|
|
24
|
+
type: z.literal("oauth"),
|
|
25
|
+
server: z.string().min(1)
|
|
26
|
+
}),
|
|
27
|
+
z.strictObject({
|
|
28
|
+
...guidance,
|
|
29
|
+
type: z.literal("form"),
|
|
30
|
+
fields: z.array(z.string().min(1)).min(1).max(20)
|
|
31
|
+
}),
|
|
32
|
+
z.strictObject({
|
|
33
|
+
...guidance,
|
|
34
|
+
type: z.literal("cli"),
|
|
35
|
+
fields: z.array(z.string().min(1)).max(20).default([]),
|
|
36
|
+
login: setupCommandSchema,
|
|
37
|
+
check: setupCommandSchema,
|
|
38
|
+
timeoutSeconds: z.number().int().min(10).max(900).default(300)
|
|
39
|
+
})
|
|
40
|
+
])).min(1).max(6)
|
|
41
|
+
})).max(20);
|
|
42
|
+
function pluginAuthorizations(manifest) {
|
|
43
|
+
const extension = manifest.extensions?.["ai.xopc"];
|
|
44
|
+
const declarations = pluginAuthorizationSchema.parse(extension?.setup?.authorizations ?? []);
|
|
45
|
+
for (const account of declarations) for (const method of account.methods) if (method.helpUrl) safeAuthorizationUrl(method.helpUrl);
|
|
46
|
+
return declarations;
|
|
47
|
+
}
|
|
48
|
+
function safeAuthorizationUrl(value) {
|
|
49
|
+
const url = new URL(value);
|
|
50
|
+
if (url.username || url.password || !(url.protocol === "https:" || url.protocol === "http:" && [
|
|
51
|
+
"127.0.0.1",
|
|
52
|
+
"[::1]",
|
|
53
|
+
"localhost"
|
|
54
|
+
].includes(url.hostname))) throw new Error("Authorization requires an HTTPS or loopback URL");
|
|
55
|
+
return url.href;
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
export { pluginAuthorizationSchema, pluginAuthorizations, safeAuthorizationUrl, setupCommandSchema };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { Config } from '../../config/schema.js';
|
|
3
|
+
import { AgentPluginStore } from './store.js';
|
|
4
|
+
declare const schema: z.ZodObject<{
|
|
5
|
+
id: z.ZodString;
|
|
6
|
+
pluginId: z.ZodString;
|
|
7
|
+
owner: z.ZodString;
|
|
8
|
+
packageRevision: z.ZodString;
|
|
9
|
+
revision: z.ZodNumber;
|
|
10
|
+
state: z.ZodEnum<{
|
|
11
|
+
cancelled: "cancelled";
|
|
12
|
+
failed: "failed";
|
|
13
|
+
completed: "completed";
|
|
14
|
+
pending: "pending";
|
|
15
|
+
running: "running";
|
|
16
|
+
interrupted: "interrupted";
|
|
17
|
+
action_required: "action_required";
|
|
18
|
+
}>;
|
|
19
|
+
resources: z.ZodEnum<{
|
|
20
|
+
error: "error";
|
|
21
|
+
pending: "pending";
|
|
22
|
+
ready: "ready";
|
|
23
|
+
running: "running";
|
|
24
|
+
}>;
|
|
25
|
+
connections: z.ZodArray<z.ZodObject<{
|
|
26
|
+
name: z.ZodString;
|
|
27
|
+
state: z.ZodEnum<{
|
|
28
|
+
error: "error";
|
|
29
|
+
pending: "pending";
|
|
30
|
+
skipped: "skipped";
|
|
31
|
+
connected: "connected";
|
|
32
|
+
oauth_required: "oauth_required";
|
|
33
|
+
token_required: "token_required";
|
|
34
|
+
}>;
|
|
35
|
+
toolCount: z.ZodOptional<z.ZodNumber>;
|
|
36
|
+
authorizationId: z.ZodOptional<z.ZodString>;
|
|
37
|
+
}, z.core.$strip>>;
|
|
38
|
+
installed: z.ZodDefault<z.ZodBoolean>;
|
|
39
|
+
deferred: z.ZodDefault<z.ZodBoolean>;
|
|
40
|
+
authorizations: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
41
|
+
id: z.ZodString;
|
|
42
|
+
state: z.ZodEnum<{
|
|
43
|
+
error: "error";
|
|
44
|
+
pending: "pending";
|
|
45
|
+
skipped: "skipped";
|
|
46
|
+
connected: "connected";
|
|
47
|
+
}>;
|
|
48
|
+
method: z.ZodOptional<z.ZodString>;
|
|
49
|
+
attemptId: z.ZodOptional<z.ZodString>;
|
|
50
|
+
}, z.core.$strip>>>;
|
|
51
|
+
operations: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
52
|
+
key: z.ZodString;
|
|
53
|
+
action: z.ZodString;
|
|
54
|
+
}, z.core.$strip>>>;
|
|
55
|
+
missingConfig: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
56
|
+
partial: z.ZodBoolean;
|
|
57
|
+
updatedAt: z.ZodString;
|
|
58
|
+
error: z.ZodOptional<z.ZodString>;
|
|
59
|
+
}, z.core.$strip>;
|
|
60
|
+
export type PluginSetupJob = z.infer<typeof schema>;
|
|
61
|
+
export declare const setupActionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
62
|
+
expectedRevision: z.ZodNumber;
|
|
63
|
+
idempotencyKey: z.ZodOptional<z.ZodString>;
|
|
64
|
+
action: z.ZodLiteral<"prepare">;
|
|
65
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
66
|
+
server: z.ZodString;
|
|
67
|
+
sourceServerId: z.ZodString;
|
|
68
|
+
expectedRevision: z.ZodNumber;
|
|
69
|
+
idempotencyKey: z.ZodOptional<z.ZodString>;
|
|
70
|
+
action: z.ZodLiteral<"reuse">;
|
|
71
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
72
|
+
server: z.ZodString;
|
|
73
|
+
method: z.ZodOptional<z.ZodString>;
|
|
74
|
+
expectedRevision: z.ZodNumber;
|
|
75
|
+
idempotencyKey: z.ZodOptional<z.ZodString>;
|
|
76
|
+
action: z.ZodLiteral<"authorize">;
|
|
77
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
78
|
+
values: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
79
|
+
authorization: z.ZodOptional<z.ZodString>;
|
|
80
|
+
method: z.ZodOptional<z.ZodString>;
|
|
81
|
+
expectedRevision: z.ZodNumber;
|
|
82
|
+
idempotencyKey: z.ZodOptional<z.ZodString>;
|
|
83
|
+
action: z.ZodLiteral<"configure">;
|
|
84
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
85
|
+
workspacePaths: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
|
|
86
|
+
allowPartial: z.ZodDefault<z.ZodBoolean>;
|
|
87
|
+
expectedRevision: z.ZodNumber;
|
|
88
|
+
idempotencyKey: z.ZodOptional<z.ZodString>;
|
|
89
|
+
action: z.ZodLiteral<"complete">;
|
|
90
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
91
|
+
expectedRevision: z.ZodNumber;
|
|
92
|
+
idempotencyKey: z.ZodOptional<z.ZodString>;
|
|
93
|
+
action: z.ZodLiteral<"defer">;
|
|
94
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
95
|
+
expectedRevision: z.ZodNumber;
|
|
96
|
+
idempotencyKey: z.ZodOptional<z.ZodString>;
|
|
97
|
+
action: z.ZodLiteral<"cancel">;
|
|
98
|
+
}, z.core.$strict>], "action">;
|
|
99
|
+
export declare class PluginSetupService {
|
|
100
|
+
readonly store: AgentPluginStore;
|
|
101
|
+
constructor(store?: AgentPluginStore);
|
|
102
|
+
private path;
|
|
103
|
+
private key;
|
|
104
|
+
private write;
|
|
105
|
+
get(id: string, owner: string): PluginSetupJob | undefined;
|
|
106
|
+
create(id: string, owner: string): PluginSetupJob;
|
|
107
|
+
invalidateConnection(id: string, owner: string, name: string): void;
|
|
108
|
+
reusableConnections(id: string, owner: string, config: Config): Promise<Record<string, Array<{
|
|
109
|
+
id: string;
|
|
110
|
+
name: string;
|
|
111
|
+
}>>>;
|
|
112
|
+
authorization(id: string, owner: string, server: string, config: Config): Promise<import("../../agent/mcp/connection-setup.js").McpAuthorization | import("./cli-authorization.js").PluginCliAuthorization>;
|
|
113
|
+
redirect(id: string, owner: string, server: string, url: string, config: Config): boolean;
|
|
114
|
+
private config;
|
|
115
|
+
startPrepare(id: string, owner: string, revision: number, config: Config, workspace: string, idempotencyKey?: string): PluginSetupJob;
|
|
116
|
+
act(id: string, owner: string, input: z.infer<typeof setupActionSchema>, config: Config, workspace: string): Promise<PluginSetupJob>;
|
|
117
|
+
private perform;
|
|
118
|
+
}
|
|
119
|
+
export {};
|