@xopcai/xopc 0.0.222 → 0.0.224
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/feishu/src/outbound/media-load.js +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{activity-store-NItGQmvR.js → activity-store--GBciH10.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-DsR_2U9-.js → agent-avatar-dicebear-K7V4XXt7.js} +1 -1
- package/dist/gateway/static/root/assets/agents-BsxTpXyq.js +68 -0
- package/dist/gateway/static/root/assets/{api-53ZXsuyr.js → api-HoIz_ija.js} +1 -1
- package/dist/gateway/static/root/assets/{app-management-settings-panel-BCzVX09V.js → app-management-settings-panel-xQCmkAHh.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-DgSpwqQI.js → appearance-settings-BRoeA4kU.js} +1 -1
- package/dist/gateway/static/root/assets/apps-page-BXgpBA8w.js +1 -0
- package/dist/gateway/static/root/assets/{archive-plugin-D8o8CP9Y.js → archive-plugin-CteCVsBP.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-BQHcAR6J.js → attachment-load-D7xNA2jB.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-page-CswK3HFb.js → automations-page-BD1vK7r5.js} +1 -1
- package/dist/gateway/static/root/assets/automations-workspace-wrgf-z7D.js +6 -0
- package/dist/gateway/static/root/assets/{binary-plugins-BlpyTJ1b.js → binary-plugins-C3DaJa0W.js} +1 -1
- package/dist/gateway/static/root/assets/block-editor-lTkcHTve.js +184 -0
- package/dist/gateway/static/root/assets/browser-settings-page-zhzNkeVG.js +8 -0
- package/dist/gateway/static/root/assets/{browser-workflow-inputs-Bi6RSSpD.js → browser-workflow-inputs-1UZ0vnIy.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-workflows-page-CZNOOQY4.js → browser-workflows-page-BHuJOF4M.js} +2 -2
- package/dist/gateway/static/root/assets/capabilities-settings-panel-DuCmg2Ej.js +7 -0
- package/dist/gateway/static/root/assets/{capability-presets-api-pC2fno7r.js → capability-presets-api-yNqTIuyd.js} +1 -1
- package/dist/gateway/static/root/assets/capability-presets-settings-panel-DjiP3mQQ.js +3 -0
- package/dist/gateway/static/root/assets/{channel-recipient-api-B5Szgu_z.js → channel-recipient-api-krezGsKc.js} +1 -1
- package/dist/gateway/static/root/assets/channels-settings-B4AtvQHk.js +1 -0
- package/dist/gateway/static/root/assets/channels-status-swr-DMxB7slL.js +1 -0
- package/dist/gateway/static/root/assets/{chat-terminal-dock-2fpzufzt.js → chat-terminal-dock-BRrL2iHA.js} +2 -2
- package/dist/gateway/static/root/assets/connectors-page-fmda2NEP.js +2 -0
- package/dist/gateway/static/root/assets/{cron-expression-VePLfPUR.js → cron-expression-Bl-2DzBQ.js} +1 -1
- package/dist/gateway/static/root/assets/{date-picker-CJegmPTJ.js → date-picker-CxTl6Wlz.js} +1 -1
- package/dist/gateway/static/root/assets/{dependency-picker-B2o9unBk.js → dependency-picker-DSl0mOPa.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-BH4Np-ay.js → desktop-pet-DTeCmCdb.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-Duu3ctxD.js → desktop-pet-settings-BNebxg0V.js} +1 -1
- package/dist/gateway/static/root/assets/{directory-picker-path-field-BBCUZOg2.js → directory-picker-path-field-Dn9XpmXY.js} +1 -1
- package/dist/gateway/static/root/assets/dist-DaxPZj9e.js +1 -0
- package/dist/gateway/static/root/assets/{dist-DY4Af0fY.js → dist-J_ySZvz0.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-DS_o3F97.js → extension-debug-page-D-J-eOTb.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-BTLBZdCq.js → extension-page-CpST24nU.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-KTGrYbgk.js → extension-settings-page-4nQXFnFq.js} +1 -1
- package/dist/gateway/static/root/assets/floating-ui.dom-B7uQOZZW.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-config-api-D3YJVfzY.js → gateway-config-api-BHWHduDi.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-config-swr-BzTbnu4O.js → gateway-config-swr-yUxMMVjK.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-settings-B8--s3yC.js → gateway-settings-BimMKmkM.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-startup-retry-B2zpkNvi.js → gateway-startup-retry-9mrsL84j.js} +1 -1
- package/dist/gateway/static/root/assets/heartbeat-settings-MUJ3mEC9.js +1 -0
- package/dist/gateway/static/root/assets/home-page-DSM6aPHF.js +1 -0
- package/dist/gateway/static/root/assets/{image-generation-api-BXRjz-iY.js → image-generation-api-CgFAGDi8.js} +1 -1
- package/dist/gateway/static/root/assets/index-B3zYJBhK.js +74 -0
- package/dist/gateway/static/root/assets/index-D3_xSYKd.css +2 -0
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-D-Ib-suu.js → keyboard-shortcuts-settings-6Ar5rfX4.js} +1 -1
- package/dist/gateway/static/root/assets/local-app-workbench-page-tzM0wTL8.js +2 -0
- package/dist/gateway/static/root/assets/{local-apps-page-Bsy1lvAc.js → local-apps-page-B5n-x544.js} +1 -1
- package/dist/gateway/static/root/assets/{locale-store-iKjqemWG.js → locale-store-CPylQjH9.js} +1 -1
- package/dist/gateway/static/root/assets/logs-page-CgoQlera.js +2 -0
- package/dist/gateway/static/root/assets/{management-settings-D-akydG4.js → management-settings-CXBLyU-0.js} +1 -1
- package/dist/gateway/static/root/assets/{markdown-split-DHH4Cu2i.js → markdown-split-CtmQemJi.js} +1 -1
- package/dist/gateway/static/root/assets/markdown-view-CUsob4Pz.js +69 -0
- package/dist/gateway/static/root/assets/{media-plugins-BwHtUXkj.js → media-plugins-Dsd-IEOW.js} +1 -1
- package/dist/gateway/static/root/assets/messages-B82nsi9k.js +3 -0
- package/dist/gateway/static/root/assets/notes-api-CfKZYrBC.js +1 -0
- package/dist/gateway/static/root/assets/{notes-page-BxM1p6hz.js → notes-page-BKbOTE2n.js} +1 -1
- package/dist/gateway/static/root/assets/notes-workbench-BScELo01.js +4 -0
- package/dist/gateway/static/root/assets/oauth-authorization-window-Cdolr2wE.js +1 -0
- package/dist/gateway/static/root/assets/{popover-select-BzdnTy3h.js → popover-select-CccGri5Y.js} +1 -1
- package/dist/gateway/static/root/assets/{product-open-page-DrfWH1ir.js → product-open-page-DqB9bsDB.js} +1 -1
- package/dist/gateway/static/root/assets/project-detail-page-DUoyty8X.js +1 -0
- package/dist/gateway/static/root/assets/projects-page-PeXUdGdO.js +1 -0
- package/dist/gateway/static/root/assets/{registry-api-Cx3JxXSL.js → registry-api-B_5D8epF.js} +1 -1
- package/dist/gateway/static/root/assets/remote-access-hub-sHho-uXP.js +1 -0
- package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-DF7syQRd.js → runtime-tools-settings-panel-DBTH_t0O.js} +1 -1
- package/dist/gateway/static/root/assets/{schema-form-BQ_qRIsM.js → schema-form-CqMKAwV0.js} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-DyvNgaP9.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-CnYf1R7z.js +1 -0
- package/dist/gateway/static/root/assets/{settings-form-section-BBHGOQHU.js → settings-form-section-dPriuuYq.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-loading-skeleton-CiwjP2-b.js → settings-loading-skeleton-B-Mbm8Va.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-Rl9waapk.js → settings-page-Dyj3w-Ml.js} +1 -1
- package/dist/gateway/static/root/assets/setup-status-panel-C4FxY5J3.js +1 -0
- package/dist/gateway/static/root/assets/share-preview-page-emEdx7YL.js +2 -0
- package/dist/gateway/static/root/assets/shares-settings-BQBVq-sN.js +1 -0
- package/dist/gateway/static/root/assets/skill-reload-api-BFoEpQ4I.js +1 -0
- package/dist/gateway/static/root/assets/{skills-page-YbtR_zEU.js → skills-page-BNtYnrRT.js} +1 -1
- package/dist/gateway/static/root/assets/{skills-page.utils-DTmx2Zza.js → skills-page.utils-DjnbNFs5.js} +1 -1
- package/dist/gateway/static/root/assets/{system-settings-panel-BZDJcKdS.js → system-settings-panel-DDStf-jZ.js} +1 -1
- package/dist/gateway/static/root/assets/task-detail-page-ZVwr8KbS.js +1 -0
- package/dist/gateway/static/root/assets/{theme-store-BOD2D0dJ.js → theme-store-BN-32Fz5.js} +1 -1
- package/dist/gateway/static/root/assets/{use-autosave-Be9aR9qA.js → use-autosave-C2mKZ-ua.js} +1 -1
- package/dist/gateway/static/root/assets/user-context-page-CHjIinCW.js +1 -0
- package/dist/gateway/static/root/assets/{voice-api-key-field-IMc3Ua6C.js → voice-api-key-field-D7OHeQby.js} +1 -1
- package/dist/gateway/static/root/assets/{work-discovery-overlay-TC-xQenr.js → work-discovery-overlay-CIiXie7F.js} +1 -1
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-B2auxcRv.js → workflow-run-setup-panel-9_dAGW3_.js} +2 -2
- package/dist/gateway/static/root/assets/workflows-page-DXpYJxao.js +5 -0
- package/dist/gateway/static/root/index.html +15 -14
- package/dist/package.js +1 -1
- package/dist/src/agent/agent-instance-gateway.d.ts +3 -0
- package/dist/src/agent/agent-manager.d.ts +3 -0
- package/dist/src/agent/agent-manager.js +30 -24
- package/dist/src/agent/embedded/index.d.ts +1 -1
- package/dist/src/agent/embedded/index.js +2 -2
- package/dist/src/agent/embedded/run-for-session.js +101 -62
- package/dist/src/agent/embedded/run-turn.js +56 -28
- package/dist/src/agent/embedded/runs.d.ts +16 -29
- package/dist/src/agent/embedded/runs.js +44 -65
- package/dist/src/agent/embedded/types.d.ts +4 -0
- package/dist/src/agent/orchestration/agent-run-supervisor.d.ts +28 -0
- package/dist/src/agent/orchestration/agent-run-supervisor.js +49 -0
- package/dist/src/agent/orchestration/agent-turn-policy.d.ts +18 -0
- package/dist/src/agent/orchestration/agent-turn-policy.js +36 -0
- package/dist/src/agent/orchestration/llm-turn-retry.d.ts +5 -0
- package/dist/src/agent/orchestration/llm-turn-retry.js +34 -4
- package/dist/src/agent/orchestration/run-agent-turn-with-timeout.d.ts +10 -1
- package/dist/src/agent/orchestration/run-agent-turn-with-timeout.js +25 -4
- package/dist/src/agent/service/async-queue.d.ts +16 -3
- package/dist/src/agent/service/async-queue.js +29 -11
- package/dist/src/agent/service/process-direct-streaming.js +27 -4
- package/dist/src/agent/service.js +1 -0
- package/dist/src/agent/tools/exec-command.d.ts +2 -0
- package/dist/src/agent/tools/exec-command.js +70 -7
- package/dist/src/auth/oauth/index.js +3 -3
- package/dist/src/auth/oauth/registry.d.ts +2 -0
- package/dist/src/auth/oauth/registry.js +20 -12
- package/dist/src/auth/oauth/xopc-cloud.d.ts +1 -0
- package/dist/src/auth/oauth/xopc-cloud.js +32 -16
- package/dist/src/cli/commands/channels.js +1 -1
- package/dist/src/cli/commands/connectors.js +1 -1
- package/dist/src/cli/commands/extension-marketplace.js +1 -1
- package/dist/src/cli/commands/models.js +1 -1
- package/dist/src/cli/commands/onboard.js +1 -1
- package/dist/src/cli/commands/tunnel.js +4 -5
- package/dist/src/config/agent-profile.js +1 -1
- package/dist/src/config/schema.d.ts +18 -0
- package/dist/src/config/schema.js +19 -1
- package/dist/src/extensions/sdk/index.js +1 -1
- package/dist/src/gateway/agents-admin.js +1 -1
- package/dist/src/gateway/hono/app.js +2 -1
- package/dist/src/gateway/hono/oauth-async.d.ts +1 -0
- package/dist/src/gateway/hono/oauth-async.js +11 -4
- package/dist/src/gateway/hono/routes/config.js +10 -0
- package/dist/src/gateway/hono/routes/host-fs.js +40 -1
- package/dist/src/gateway/hono/routes/media.js +33 -1
- package/dist/src/gateway/hono/routes/notes.js +162 -7
- package/dist/src/gateway/hono/routes/shares.js +141 -6
- package/dist/src/gateway/hono/routes/tunnel.js +47 -10
- package/dist/src/gateway/hono/routes/voice.d.ts +2 -6
- package/dist/src/gateway/hono/routes/voice.js +20 -4
- package/dist/src/gateway/hono/routes/workflows.js +2 -2
- package/dist/src/gateway/run-loop.js +3 -0
- package/dist/src/gateway/server.d.ts +3 -0
- package/dist/src/gateway/server.js +30 -5
- package/dist/src/gateway/service.js +4 -4
- package/dist/src/notes/service.d.ts +6 -2
- package/dist/src/notes/service.js +36 -4
- package/dist/src/providers/index.js +2 -2
- package/dist/src/share/note-share-service.d.ts +67 -0
- package/dist/src/share/note-share-service.js +283 -0
- package/dist/src/share/share-config.js +32 -3
- package/dist/src/share/share-landing.d.ts +5 -1
- package/dist/src/share/share-landing.js +28 -1
- package/dist/src/share/share-store.d.ts +34 -5
- package/dist/src/share/share-store.js +125 -19
- package/dist/src/share/share-thumbnail.js +4 -2
- package/dist/src/share/share-types.d.ts +52 -14
- package/dist/src/share/share-types.js +9 -0
- package/dist/src/share/share-zip.d.ts +2 -2
- package/dist/src/tui/backends/embedded-backend.js +1 -1
- package/dist/src/tunnel/env.d.ts +12 -6
- package/dist/src/tunnel/env.js +34 -26
- package/dist/src/tunnel/gateway-lifecycle.js +2 -13
- package/dist/src/tunnel/index.d.ts +1 -1
- package/dist/src/tunnel/index.js +2 -2
- package/dist/src/tunnel/tunnel-audit.d.ts +1 -1
- package/dist/src/tunnel/tunnel-config.d.ts +1 -1
- package/dist/src/tunnel/tunnel-config.js +9 -4
- package/dist/src/tunnel/tunnel-service.d.ts +1 -1
- package/dist/src/tunnel/tunnel-service.js +3 -0
- package/dist/src/tunnel/well-known.d.ts +1 -1
- package/dist/src/tunnel/well-known.js +1 -1
- package/dist/src/tunnel/xopc-cloud-registration.d.ts +9 -0
- package/dist/src/tunnel/xopc-cloud-registration.js +42 -0
- package/dist/src/voice/stt/transcribe-core.js +17 -1
- package/dist/src/voice/stt/types.d.ts +1 -1
- package/package.json +2 -2
- package/dist/gateway/static/root/assets/agents-DijFbC4G.js +0 -68
- package/dist/gateway/static/root/assets/apps-page-BFAmf9hq.js +0 -1
- package/dist/gateway/static/root/assets/automations-workspace-B8us5JBf.js +0 -6
- package/dist/gateway/static/root/assets/block-editor-C3mwGsms.js +0 -184
- package/dist/gateway/static/root/assets/browser-settings-page-BeBd17-3.js +0 -8
- package/dist/gateway/static/root/assets/capabilities-settings-panel-Bv0z3KRq.js +0 -7
- package/dist/gateway/static/root/assets/capability-presets-settings-panel-BczD-pWE.js +0 -3
- package/dist/gateway/static/root/assets/channels-settings-2KQYq6xl.js +0 -1
- package/dist/gateway/static/root/assets/channels-status-swr-ByRbxC6z.js +0 -1
- package/dist/gateway/static/root/assets/connectors-page-PB1boaNy.js +0 -2
- package/dist/gateway/static/root/assets/dist-C230izr8.js +0 -1
- package/dist/gateway/static/root/assets/heartbeat-settings-5YQ5BUwp.js +0 -1
- package/dist/gateway/static/root/assets/home-page-DfIVWJl3.js +0 -1
- package/dist/gateway/static/root/assets/index-BXGC3VFm.css +0 -2
- package/dist/gateway/static/root/assets/index-jqDCfet4.js +0 -74
- package/dist/gateway/static/root/assets/local-app-workbench-page-CAb0odzu.js +0 -2
- package/dist/gateway/static/root/assets/logs-page-CFxKbDZl.js +0 -2
- package/dist/gateway/static/root/assets/markdown-view-DYkxMtJA.js +0 -69
- package/dist/gateway/static/root/assets/messages-kx5W39dO.js +0 -3
- package/dist/gateway/static/root/assets/notes-api-DJizatxh.js +0 -1
- package/dist/gateway/static/root/assets/notes-workbench-BGjEC89c.js +0 -4
- package/dist/gateway/static/root/assets/project-detail-page-Dj9kEQwg.js +0 -1
- package/dist/gateway/static/root/assets/projects-page-CBRy5Ezz.js +0 -1
- package/dist/gateway/static/root/assets/remote-access-hub-DSwz9RBh.js +0 -1
- package/dist/gateway/static/root/assets/sessions-page-WtattyVX.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-CNAz_q1F.js +0 -1
- package/dist/gateway/static/root/assets/setup-status-panel-CNo4Ajhn.js +0 -1
- package/dist/gateway/static/root/assets/share-preview-page-B7PI3yZ6.js +0 -2
- package/dist/gateway/static/root/assets/shares-settings-DpOH0zWB.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-BOf4xCat.js +0 -1
- package/dist/gateway/static/root/assets/task-detail-page-DrMX5Yhj.js +0 -1
- package/dist/gateway/static/root/assets/user-context-page-ewIK2ddC.js +0 -1
- package/dist/gateway/static/root/assets/workflows-page-Bdn82kFQ.js +0 -5
|
@@ -7,10 +7,10 @@ import { messagesToClientHistory } from "../../../session/client-history.js";
|
|
|
7
7
|
import "../../../workflows/domain/index.js";
|
|
8
8
|
import { resolveWorkflowRunArtifactsDir } from "../../../workflows/store/paths.js";
|
|
9
9
|
import { WorkflowDraftService } from "../../../workflows/draft/workflow-draft-service.js";
|
|
10
|
-
import "../../../workflows/draft/index.js";
|
|
11
|
-
import { ProjectWorkflowPresetRepository } from "../../../workflows/project-presets/project-workflow-preset-repository.js";
|
|
12
10
|
import { WorkflowDraftConflictError, WorkflowDraftStore } from "../../../workflows/authoring/workflow-draft-store.js";
|
|
13
11
|
import "../../../workflows/authoring/index.js";
|
|
12
|
+
import "../../../workflows/draft/index.js";
|
|
13
|
+
import { ProjectWorkflowPresetRepository } from "../../../workflows/project-presets/project-workflow-preset-repository.js";
|
|
14
14
|
import { basename, join } from "node:path";
|
|
15
15
|
import { readFile, stat } from "node:fs/promises";
|
|
16
16
|
//#region src/gateway/hono/routes/workflows.ts
|
|
@@ -67,6 +67,9 @@ async function runGatewayLoop(opts) {
|
|
|
67
67
|
forceCloseRequested = true;
|
|
68
68
|
console.warn(`[GatewayRunLoop] Received ${signal} again; force closing connections`);
|
|
69
69
|
server?.forceCloseConnections();
|
|
70
|
+
} else if (signal === "SIGINT" || signal === "SIGTERM") {
|
|
71
|
+
console.warn(`[GatewayRunLoop] Received ${signal} again; force exiting`);
|
|
72
|
+
exitProcess(0);
|
|
70
73
|
}
|
|
71
74
|
return;
|
|
72
75
|
}
|
|
@@ -14,6 +14,8 @@ export interface GatewayServerConfig {
|
|
|
14
14
|
export declare class GatewayServer {
|
|
15
15
|
private server?;
|
|
16
16
|
private extraServers;
|
|
17
|
+
private readonly serverSockets;
|
|
18
|
+
private stopPromise;
|
|
17
19
|
private config;
|
|
18
20
|
private service;
|
|
19
21
|
constructor(config: GatewayServerConfig);
|
|
@@ -23,6 +25,7 @@ export declare class GatewayServer {
|
|
|
23
25
|
restartExpectedMs?: number | null;
|
|
24
26
|
}): Promise<void>;
|
|
25
27
|
stop(): Promise<void>;
|
|
28
|
+
private stopInternal;
|
|
26
29
|
forceCloseConnections(): void;
|
|
27
30
|
get isRunning(): boolean;
|
|
28
31
|
get serviceInstance(): GatewayService;
|
|
@@ -10,6 +10,8 @@ ensureXopcCliOnPath();
|
|
|
10
10
|
var GatewayServer = class {
|
|
11
11
|
server;
|
|
12
12
|
extraServers = [];
|
|
13
|
+
serverSockets = /* @__PURE__ */ new Map();
|
|
14
|
+
stopPromise = null;
|
|
13
15
|
config;
|
|
14
16
|
service;
|
|
15
17
|
constructor(config) {
|
|
@@ -57,7 +59,14 @@ var GatewayServer = class {
|
|
|
57
59
|
});
|
|
58
60
|
const primaryHost = listenHosts[0] ?? bindHost;
|
|
59
61
|
const attachUpgrade = (server) => {
|
|
60
|
-
|
|
62
|
+
const inner = server;
|
|
63
|
+
const sockets = /* @__PURE__ */ new Set();
|
|
64
|
+
this.serverSockets.set(server, sockets);
|
|
65
|
+
inner.on("connection", (socket) => {
|
|
66
|
+
sockets.add(socket);
|
|
67
|
+
socket.once("close", () => sockets.delete(socket));
|
|
68
|
+
});
|
|
69
|
+
inner.on("upgrade", (req, socket, head) => {
|
|
61
70
|
try {
|
|
62
71
|
if (this.service.realtime.handleUpgrade(req, socket, head)) return;
|
|
63
72
|
if (handleSiteShareUpgrade(this.service, req, socket, head)) return;
|
|
@@ -98,11 +107,20 @@ var GatewayServer = class {
|
|
|
98
107
|
await this.stop();
|
|
99
108
|
}
|
|
100
109
|
async stop() {
|
|
110
|
+
if (this.stopPromise) return this.stopPromise;
|
|
111
|
+
this.stopPromise = this.stopInternal();
|
|
112
|
+
return this.stopPromise;
|
|
113
|
+
}
|
|
114
|
+
async stopInternal() {
|
|
101
115
|
console.log("[GatewayServer] Stopping gateway server...");
|
|
116
|
+
const forceCloseServer = (server) => {
|
|
117
|
+
server.closeAllConnections?.();
|
|
118
|
+
for (const socket of this.serverSockets.get(server) ?? []) socket.destroy();
|
|
119
|
+
};
|
|
102
120
|
const closeServer = async (server) => {
|
|
103
121
|
if (!server) return;
|
|
104
122
|
const forceClose = setTimeout(() => {
|
|
105
|
-
server
|
|
123
|
+
forceCloseServer(server);
|
|
106
124
|
}, 2e3);
|
|
107
125
|
await new Promise((resolve) => {
|
|
108
126
|
server.close(() => {
|
|
@@ -111,16 +129,23 @@ var GatewayServer = class {
|
|
|
111
129
|
});
|
|
112
130
|
});
|
|
113
131
|
};
|
|
114
|
-
|
|
132
|
+
const primaryServer = this.server;
|
|
133
|
+
const extraServers = this.extraServers;
|
|
134
|
+
const closePromises = [closeServer(primaryServer), ...extraServers.map(closeServer)];
|
|
135
|
+
const activeServers = [primaryServer, ...extraServers].filter((server) => server !== void 0);
|
|
136
|
+
await this.service.stop();
|
|
137
|
+
for (const server of activeServers) forceCloseServer(server);
|
|
138
|
+
await Promise.all(closePromises);
|
|
139
|
+
for (const server of activeServers) this.serverSockets.delete(server);
|
|
115
140
|
this.server = void 0;
|
|
116
|
-
for (const extra of this.extraServers) await closeServer(extra);
|
|
117
141
|
this.extraServers = [];
|
|
118
|
-
await this.service.stop();
|
|
119
142
|
console.log("[GatewayServer] Gateway server stopped");
|
|
120
143
|
}
|
|
121
144
|
forceCloseConnections() {
|
|
122
145
|
const close = (server) => {
|
|
146
|
+
if (!server) return;
|
|
123
147
|
server?.closeAllConnections?.();
|
|
148
|
+
for (const socket of this.serverSockets.get(server) ?? []) socket.destroy();
|
|
124
149
|
};
|
|
125
150
|
close(this.server);
|
|
126
151
|
for (const extra of this.extraServers) close(extra);
|
|
@@ -45,25 +45,25 @@ import { MessageBus, MessageBusShutdownError } from "../infra/bus/queue.js";
|
|
|
45
45
|
import "../infra/bus/index.js";
|
|
46
46
|
import { AgentService } from "../agent/service.js";
|
|
47
47
|
import { ensureStarterAgentsInitialized } from "../agent/starter-agents.js";
|
|
48
|
+
import { getWorkspacePath } from "../config/workspace-path-helpers.js";
|
|
49
|
+
import "../config/index.js";
|
|
48
50
|
import { setPairingBroadcastSink } from "../channels/pairing/pairing-events.js";
|
|
49
51
|
import { registerClarifyBridge } from "./clarify-runtime.js";
|
|
50
52
|
import { ChannelManager } from "../channels/manager.js";
|
|
51
|
-
import { getWorkspacePath } from "../config/workspace-path-helpers.js";
|
|
52
|
-
import "../config/index.js";
|
|
53
53
|
import { DiscussionService } from "../discussions/service.js";
|
|
54
54
|
import { DiscussionOrganizer } from "../discussions/organizer.js";
|
|
55
55
|
import { DiscussionLiveWorker } from "../discussions/live-worker.js";
|
|
56
56
|
import { DiscussionOrganizerWorker } from "../discussions/organizer-worker.js";
|
|
57
57
|
import { DiscussionSealer } from "../discussions/sealer.js";
|
|
58
58
|
import "../discussions/index.js";
|
|
59
|
+
import { EndpointToolRuntime } from "../endpoint-tools/runtime.js";
|
|
60
|
+
import "../endpoint-tools/index.js";
|
|
59
61
|
import { ManagedComposioEventPoller } from "../connectors/composio-managed-events.js";
|
|
60
62
|
import { startConnectedKnowledgeCoordinator } from "../knowledge/coordinator.js";
|
|
61
63
|
import "../knowledge/index.js";
|
|
62
64
|
import { startConnectorLearningCoordinator } from "../connectors/learning-coordinator.js";
|
|
63
65
|
import { ConnectedSourceChangePublisher } from "../connectors/source-change-publisher.js";
|
|
64
66
|
import { startConnectorSupervisor } from "../connectors/supervisor.js";
|
|
65
|
-
import { EndpointToolRuntime } from "../endpoint-tools/runtime.js";
|
|
66
|
-
import "../endpoint-tools/index.js";
|
|
67
67
|
import { assertGatewayAuthConfigured, extractToken, resolveGatewayAuth, validateToken } from "./auth.js";
|
|
68
68
|
import { prepareAutomationAgentSession } from "./automation-agent-session.js";
|
|
69
69
|
import { reconcileDreamingAutomations } from "./dreaming-automation-reconciler.js";
|
|
@@ -6,11 +6,14 @@ export declare class NotesService {
|
|
|
6
6
|
private readonly store;
|
|
7
7
|
private lastSnapshotAt;
|
|
8
8
|
private quickCapturesInFlight;
|
|
9
|
+
private noteCapturesInFlight;
|
|
10
|
+
private noteAttachmentsInFlight;
|
|
9
11
|
constructor(store?: NotesStore);
|
|
10
12
|
initialize(): Promise<void>;
|
|
11
13
|
quickCapture(markdown: string, source: CaptureSource, idempotencyKey?: string): Promise<Note>;
|
|
12
14
|
private createQuickCapture;
|
|
13
|
-
createNote(params: CreateNoteParams): Promise<Note>;
|
|
15
|
+
createNote(params: CreateNoteParams, idempotencyKey?: string): Promise<Note>;
|
|
16
|
+
private createNoteWithId;
|
|
14
17
|
getNote(id: string): Promise<Note | null>;
|
|
15
18
|
updateNote(id: string, patch: Partial<Note>, trigger?: SnapshotTrigger): Promise<Note | null>;
|
|
16
19
|
private reconcileAttachments;
|
|
@@ -49,7 +52,8 @@ export declare class NotesService {
|
|
|
49
52
|
mimeType: string;
|
|
50
53
|
duration?: number;
|
|
51
54
|
retainWithoutReference?: boolean;
|
|
52
|
-
}): Promise<NoteAttachment | null>;
|
|
55
|
+
}, idempotencyKey?: string): Promise<NoteAttachment | null>;
|
|
56
|
+
private addAttachmentWithId;
|
|
53
57
|
removeAttachment(noteId: string, attachmentId: string): Promise<boolean>;
|
|
54
58
|
getAttachmentPath(noteId: string, attachmentId: string): Promise<{
|
|
55
59
|
filePath: string;
|
|
@@ -19,6 +19,12 @@ const SNAPSHOT_THROTTLE_MS = 6e4;
|
|
|
19
19
|
function quickCaptureId(idempotencyKey) {
|
|
20
20
|
return `capture_${createHash("sha256").update(`xopc:quick-capture:${idempotencyKey}`).digest("hex").slice(0, 32)}`;
|
|
21
21
|
}
|
|
22
|
+
function noteCaptureId(idempotencyKey) {
|
|
23
|
+
return `note_capture_${createHash("sha256").update(`xopc:note-capture:${idempotencyKey}`).digest("hex").slice(0, 32)}`;
|
|
24
|
+
}
|
|
25
|
+
function noteAttachmentId(noteId, idempotencyKey) {
|
|
26
|
+
return `attachment_${createHash("sha256").update(`xopc:note-attachment:${noteId}:${idempotencyKey}`).digest("hex").slice(0, 32)}`;
|
|
27
|
+
}
|
|
22
28
|
function inferKind(markdown, hasAttachments, attachments) {
|
|
23
29
|
if (hasAttachments && attachments?.length && attachments.every((item) => item.type === "audio")) return "voice";
|
|
24
30
|
if (hasAttachments) return "media";
|
|
@@ -146,6 +152,8 @@ async function buildAiCatalysisReport(note, config) {
|
|
|
146
152
|
var NotesService = class {
|
|
147
153
|
lastSnapshotAt = /* @__PURE__ */ new Map();
|
|
148
154
|
quickCapturesInFlight = /* @__PURE__ */ new Map();
|
|
155
|
+
noteCapturesInFlight = /* @__PURE__ */ new Map();
|
|
156
|
+
noteAttachmentsInFlight = /* @__PURE__ */ new Map();
|
|
149
157
|
constructor(store = new NotesStore()) {
|
|
150
158
|
this.store = store;
|
|
151
159
|
}
|
|
@@ -204,8 +212,20 @@ var NotesService = class {
|
|
|
204
212
|
}, "Quick capture");
|
|
205
213
|
return note;
|
|
206
214
|
}
|
|
207
|
-
async createNote(params) {
|
|
208
|
-
const id = randomUUID();
|
|
215
|
+
async createNote(params, idempotencyKey) {
|
|
216
|
+
const id = idempotencyKey ? noteCaptureId(idempotencyKey) : randomUUID();
|
|
217
|
+
if (idempotencyKey) {
|
|
218
|
+
const existing = await this.store.getNote(id);
|
|
219
|
+
if (existing) return existing;
|
|
220
|
+
const inFlight = this.noteCapturesInFlight.get(id);
|
|
221
|
+
if (inFlight) return inFlight;
|
|
222
|
+
const capture = this.createNoteWithId(id, params).finally(() => this.noteCapturesInFlight.delete(id));
|
|
223
|
+
this.noteCapturesInFlight.set(id, capture);
|
|
224
|
+
return capture;
|
|
225
|
+
}
|
|
226
|
+
return this.createNoteWithId(id, params);
|
|
227
|
+
}
|
|
228
|
+
async createNoteWithId(id, params) {
|
|
209
229
|
const now = Date.now();
|
|
210
230
|
const markdown = params.markdown ?? "";
|
|
211
231
|
const note = {
|
|
@@ -463,12 +483,24 @@ var NotesService = class {
|
|
|
463
483
|
async listNotes(query = {}) {
|
|
464
484
|
return this.store.listNotes(query);
|
|
465
485
|
}
|
|
466
|
-
async addAttachment(noteId, file) {
|
|
486
|
+
async addAttachment(noteId, file, idempotencyKey) {
|
|
487
|
+
if (!idempotencyKey) return this.addAttachmentWithId(noteId, file, randomUUID());
|
|
488
|
+
const attachmentId = noteAttachmentId(noteId, idempotencyKey);
|
|
489
|
+
const existing = (await this.store.getNote(noteId))?.attachments?.find((attachment) => attachment.id === attachmentId);
|
|
490
|
+
if (existing) return existing;
|
|
491
|
+
const inFlightKey = `${noteId}:${attachmentId}`;
|
|
492
|
+
const inFlight = this.noteAttachmentsInFlight.get(inFlightKey);
|
|
493
|
+
if (inFlight) return inFlight;
|
|
494
|
+
const capture = this.addAttachmentWithId(noteId, file, attachmentId).finally(() => this.noteAttachmentsInFlight.delete(inFlightKey));
|
|
495
|
+
this.noteAttachmentsInFlight.set(inFlightKey, capture);
|
|
496
|
+
return capture;
|
|
497
|
+
}
|
|
498
|
+
async addAttachmentWithId(noteId, file, attachmentId) {
|
|
467
499
|
const note = await this.store.getNote(noteId);
|
|
468
500
|
if (!note) return null;
|
|
469
501
|
const { relativePath, size } = await this.store.saveAttachment(noteId, file.name, file.buffer);
|
|
470
502
|
const attachment = {
|
|
471
|
-
id:
|
|
503
|
+
id: attachmentId,
|
|
472
504
|
type: file.mimeType.startsWith("image/") ? "image" : file.mimeType.startsWith("audio/") ? "audio" : file.mimeType.startsWith("video/") ? "video" : "file",
|
|
473
505
|
mimeType: file.mimeType,
|
|
474
506
|
fileName: file.name,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __esmMin, __exportAll } from "../../_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { getAgentDefaultModelRef, init_schema } from "../config/schema.js";
|
|
3
|
-
import {
|
|
3
|
+
import { getModelOAuthProviderIds, init_registry } from "../auth/oauth/registry.js";
|
|
4
4
|
import { hasProviderAuthOnDiskSync, init_sync_provider_auth } from "../auth/sync-provider-auth.js";
|
|
5
5
|
import { PROVIDER_ENV_MAP, getApiKeyFromEnv, init_env_keys } from "./env-keys.js";
|
|
6
6
|
import { init_model_ref, splitProviderModelRef } from "./model-ref.js";
|
|
@@ -141,7 +141,7 @@ function getAllProviders() {
|
|
|
141
141
|
for (const p of getProviders()) providers.add(p);
|
|
142
142
|
for (const m of registry.getAll()) providers.add(m.provider);
|
|
143
143
|
for (const plugin of getProviderRegistry().listAll()) providers.add(plugin.id);
|
|
144
|
-
for (const provider of
|
|
144
|
+
for (const provider of getModelOAuthProviderIds()) providers.add(provider);
|
|
145
145
|
return Array.from(providers);
|
|
146
146
|
}
|
|
147
147
|
async function getApiKey(provider, credentialOptions) {
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Note, NoteAttachment } from '../notes/types.js';
|
|
2
|
+
import type { NoteShareRecord } from './share-types.js';
|
|
3
|
+
import type { ShareStore } from './share-store.js';
|
|
4
|
+
export interface NoteShareManifestAttachment {
|
|
5
|
+
id: string;
|
|
6
|
+
type: NoteAttachment['type'];
|
|
7
|
+
mimeType: string;
|
|
8
|
+
fileName: string;
|
|
9
|
+
size: number;
|
|
10
|
+
artifactFileName: string;
|
|
11
|
+
checksum: string;
|
|
12
|
+
duration?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface NoteShareManifest {
|
|
15
|
+
schemaVersion: 1;
|
|
16
|
+
shareId: string;
|
|
17
|
+
source: {
|
|
18
|
+
noteId: string;
|
|
19
|
+
noteVersion: number;
|
|
20
|
+
};
|
|
21
|
+
title: string;
|
|
22
|
+
markdown: string;
|
|
23
|
+
snapshotAt: string;
|
|
24
|
+
attachments: NoteShareManifestAttachment[];
|
|
25
|
+
}
|
|
26
|
+
export interface NoteShareSource {
|
|
27
|
+
getNote(id: string): Promise<Note | null>;
|
|
28
|
+
getAttachmentPath(noteId: string, attachmentId: string): Promise<{
|
|
29
|
+
filePath: string;
|
|
30
|
+
mimeType: string;
|
|
31
|
+
fileName: string;
|
|
32
|
+
} | null>;
|
|
33
|
+
}
|
|
34
|
+
export interface CreateNoteShareInput {
|
|
35
|
+
expectedNoteVersion?: number;
|
|
36
|
+
attachmentIds?: string[];
|
|
37
|
+
ttlMs?: number;
|
|
38
|
+
maxViews?: number | null;
|
|
39
|
+
description?: string;
|
|
40
|
+
gatewayTokenHash: string;
|
|
41
|
+
}
|
|
42
|
+
export declare class NoteShareVersionConflictError extends Error {
|
|
43
|
+
readonly currentVersion: number;
|
|
44
|
+
constructor(currentVersion: number);
|
|
45
|
+
}
|
|
46
|
+
export declare class NoteShareService {
|
|
47
|
+
private readonly store;
|
|
48
|
+
private readonly notes;
|
|
49
|
+
constructor(store: ShareStore, notes: NoteShareSource);
|
|
50
|
+
create(noteId: string, input: CreateNoteShareInput): Promise<NoteShareRecord>;
|
|
51
|
+
refresh(noteId: string, shareId: string, input: Pick<CreateNoteShareInput, 'expectedNoteVersion' | 'attachmentIds'>): Promise<NoteShareRecord>;
|
|
52
|
+
list(noteId: string): NoteShareRecord[];
|
|
53
|
+
revokeForNote(noteId: string): Promise<number>;
|
|
54
|
+
removeArtifact(shareId: string): Promise<void>;
|
|
55
|
+
readManifest(record: NoteShareRecord): Promise<NoteShareManifest>;
|
|
56
|
+
issueAssetTicket(record: NoteShareRecord): string;
|
|
57
|
+
verifyAssetTicket(record: NoteShareRecord, ticket: string): boolean;
|
|
58
|
+
resolveAsset(record: NoteShareRecord, attachmentId: string): Promise<{
|
|
59
|
+
path: string;
|
|
60
|
+
attachment: NoteShareManifestAttachment;
|
|
61
|
+
} | null>;
|
|
62
|
+
publicMarkdown(record: NoteShareRecord, manifest: NoteShareManifest, ticket: string): string;
|
|
63
|
+
private requireNote;
|
|
64
|
+
private buildArtifact;
|
|
65
|
+
private artifactRelativePath;
|
|
66
|
+
private artifactDir;
|
|
67
|
+
}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { resolveStateDir } from "../config/paths-state.js";
|
|
2
|
+
import { createLogger } from "../utils/logger/index.js";
|
|
3
|
+
import { init_logger } from "../utils/logger.js";
|
|
4
|
+
import { init_paths } from "../config/paths.js";
|
|
5
|
+
import { collectReferencedAttachmentIds } from "../notes/note-attachment-sync.js";
|
|
6
|
+
import { dirname, join } from "node:path";
|
|
7
|
+
import { createHash, createHmac, randomUUID, timingSafeEqual } from "node:crypto";
|
|
8
|
+
import { copyFile, mkdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
9
|
+
//#region src/share/note-share-service.ts
|
|
10
|
+
init_paths();
|
|
11
|
+
init_logger();
|
|
12
|
+
const log = createLogger("NoteShareService");
|
|
13
|
+
const MANIFEST_SCHEMA_VERSION = 1;
|
|
14
|
+
var NoteShareVersionConflictError = class extends Error {
|
|
15
|
+
constructor(currentVersion) {
|
|
16
|
+
super("Note changed after the share preview was reviewed");
|
|
17
|
+
this.currentVersion = currentVersion;
|
|
18
|
+
this.name = "NoteShareVersionConflictError";
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var NoteShareService = class {
|
|
22
|
+
constructor(store, notes) {
|
|
23
|
+
this.store = store;
|
|
24
|
+
this.notes = notes;
|
|
25
|
+
}
|
|
26
|
+
async create(noteId, input) {
|
|
27
|
+
const note = await this.requireNote(noteId, input.expectedNoteVersion);
|
|
28
|
+
const id = randomUUID();
|
|
29
|
+
const staged = await this.buildArtifact(id, note, input.attachmentIds);
|
|
30
|
+
try {
|
|
31
|
+
return this.store.createNoteShare({
|
|
32
|
+
id,
|
|
33
|
+
sourceNoteId: note.id,
|
|
34
|
+
sourceVersion: note.updatedAt,
|
|
35
|
+
artifactRelativePath: this.artifactRelativePath(id),
|
|
36
|
+
artifactSize: staged.totalSize,
|
|
37
|
+
attachmentCount: staged.manifest.attachments.length,
|
|
38
|
+
fileName: staged.manifest.title,
|
|
39
|
+
ttlMs: input.ttlMs,
|
|
40
|
+
maxViews: input.maxViews,
|
|
41
|
+
description: input.description,
|
|
42
|
+
gatewayTokenHash: input.gatewayTokenHash
|
|
43
|
+
});
|
|
44
|
+
} catch (error) {
|
|
45
|
+
await this.removeArtifact(id);
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async refresh(noteId, shareId, input) {
|
|
50
|
+
const record = this.store.getById(shareId);
|
|
51
|
+
if (!record || record.kind !== "note" || record.sourceNoteId !== noteId) throw new Error("Note share not found");
|
|
52
|
+
const note = await this.requireNote(noteId, input.expectedNoteVersion);
|
|
53
|
+
const finalDir = this.artifactDir(shareId);
|
|
54
|
+
const stagedDir = `${finalDir}.refresh-${randomUUID()}`;
|
|
55
|
+
const backupDir = `${finalDir}.backup-${randomUUID()}`;
|
|
56
|
+
const staged = await this.buildArtifact(shareId, note, input.attachmentIds, stagedDir);
|
|
57
|
+
let movedOld = false;
|
|
58
|
+
try {
|
|
59
|
+
await rename(finalDir, backupDir);
|
|
60
|
+
movedOld = true;
|
|
61
|
+
await rename(stagedDir, finalDir);
|
|
62
|
+
const updated = this.store.updateNoteSnapshot(shareId, {
|
|
63
|
+
sourceVersion: note.updatedAt,
|
|
64
|
+
artifactSize: staged.totalSize,
|
|
65
|
+
attachmentCount: staged.manifest.attachments.length,
|
|
66
|
+
fileName: staged.manifest.title
|
|
67
|
+
});
|
|
68
|
+
if (!updated) throw new Error("Note share not found");
|
|
69
|
+
await rm(backupDir, {
|
|
70
|
+
recursive: true,
|
|
71
|
+
force: true
|
|
72
|
+
});
|
|
73
|
+
return updated;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
await rm(stagedDir, {
|
|
76
|
+
recursive: true,
|
|
77
|
+
force: true
|
|
78
|
+
});
|
|
79
|
+
if (movedOld) {
|
|
80
|
+
await rm(finalDir, {
|
|
81
|
+
recursive: true,
|
|
82
|
+
force: true
|
|
83
|
+
});
|
|
84
|
+
await rename(backupDir, finalDir).catch(() => void 0);
|
|
85
|
+
}
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
list(noteId) {
|
|
90
|
+
return this.store.getNoteShares(noteId);
|
|
91
|
+
}
|
|
92
|
+
async revokeForNote(noteId) {
|
|
93
|
+
const active = this.store.getNoteShares(noteId).filter((record) => !record.revoked);
|
|
94
|
+
const count = this.store.revokeMany(active.map((record) => record.id));
|
|
95
|
+
await Promise.all(active.map((record) => this.removeArtifact(record.id)));
|
|
96
|
+
return count;
|
|
97
|
+
}
|
|
98
|
+
async removeArtifact(shareId) {
|
|
99
|
+
await rm(this.artifactDir(shareId), {
|
|
100
|
+
recursive: true,
|
|
101
|
+
force: true
|
|
102
|
+
}).catch((err) => {
|
|
103
|
+
log.warn({
|
|
104
|
+
err,
|
|
105
|
+
shareId
|
|
106
|
+
}, "Failed to remove Note share artifact");
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
async readManifest(record) {
|
|
110
|
+
const raw = await readFile(join(resolveStateDir(), record.artifactRelativePath, "manifest.json"), "utf8");
|
|
111
|
+
const manifest = JSON.parse(raw);
|
|
112
|
+
if (manifest.schemaVersion !== MANIFEST_SCHEMA_VERSION || manifest.shareId !== record.id) throw new Error("Invalid Note share artifact");
|
|
113
|
+
return manifest;
|
|
114
|
+
}
|
|
115
|
+
issueAssetTicket(record) {
|
|
116
|
+
const expiresAt = Date.now() + this.store.getConfig().note.assetTicketTtlMs;
|
|
117
|
+
const payload = Buffer.from(JSON.stringify({
|
|
118
|
+
shareId: record.id,
|
|
119
|
+
revision: record.snapshotRevision,
|
|
120
|
+
expiresAt
|
|
121
|
+
})).toString("base64url");
|
|
122
|
+
return `${payload}.${createHmac("sha256", record.assetTicketSecret).update(payload).digest("base64url")}`;
|
|
123
|
+
}
|
|
124
|
+
verifyAssetTicket(record, ticket) {
|
|
125
|
+
const [payload, signature] = ticket.split(".");
|
|
126
|
+
if (!payload || !signature) return false;
|
|
127
|
+
const expected = createHmac("sha256", record.assetTicketSecret).update(payload).digest();
|
|
128
|
+
let actual;
|
|
129
|
+
try {
|
|
130
|
+
actual = Buffer.from(signature, "base64url");
|
|
131
|
+
} catch {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
if (actual.length !== expected.length || !timingSafeEqual(actual, expected)) return false;
|
|
135
|
+
try {
|
|
136
|
+
const value = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
137
|
+
return value.shareId === record.id && value.revision === record.snapshotRevision && typeof value.expiresAt === "number" && Date.now() < value.expiresAt;
|
|
138
|
+
} catch {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async resolveAsset(record, attachmentId) {
|
|
143
|
+
const attachment = (await this.readManifest(record)).attachments.find((item) => item.id === attachmentId);
|
|
144
|
+
if (!attachment || attachment.artifactFileName !== attachment.id) return null;
|
|
145
|
+
return {
|
|
146
|
+
path: join(resolveStateDir(), record.artifactRelativePath, "assets", attachment.artifactFileName),
|
|
147
|
+
attachment
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
publicMarkdown(record, manifest, ticket) {
|
|
151
|
+
return manifest.markdown.replace(/xopc-attachment:\/\/notes\/([^/]+)\/([^\s)]+)/gi, (_match, noteId, attachmentId) => {
|
|
152
|
+
let decodedNoteId = noteId;
|
|
153
|
+
let decodedAttachmentId = attachmentId;
|
|
154
|
+
try {
|
|
155
|
+
decodedNoteId = decodeURIComponent(noteId);
|
|
156
|
+
decodedAttachmentId = decodeURIComponent(attachmentId);
|
|
157
|
+
} catch {
|
|
158
|
+
return "#invalid-attachment";
|
|
159
|
+
}
|
|
160
|
+
if (decodedNoteId !== record.sourceNoteId || !manifest.attachments.some((item) => item.id === decodedAttachmentId)) return "#attachment-not-shared";
|
|
161
|
+
return `/s/${encodeURIComponent(record.token)}/assets/${encodeURIComponent(decodedAttachmentId)}?ticket=${encodeURIComponent(ticket)}`;
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
async requireNote(noteId, expectedVersion) {
|
|
165
|
+
const note = await this.notes.getNote(noteId);
|
|
166
|
+
if (!note) throw new Error("Note not found");
|
|
167
|
+
if (expectedVersion !== void 0 && note.updatedAt !== expectedVersion) throw new NoteShareVersionConflictError(note.updatedAt);
|
|
168
|
+
return note;
|
|
169
|
+
}
|
|
170
|
+
async buildArtifact(shareId, note, requestedAttachmentIds, targetDir = this.artifactDir(shareId)) {
|
|
171
|
+
const cfg = this.store.getConfig().note;
|
|
172
|
+
if (!cfg.enabled) throw new Error("Note sharing is disabled");
|
|
173
|
+
const referenced = collectReferencedAttachmentIds(note);
|
|
174
|
+
const known = new Map((note.attachments ?? []).map((attachment) => [attachment.id, attachment]));
|
|
175
|
+
for (const id of referenced) if (!known.has(id)) throw new Error(`Referenced attachment is missing: ${id}`);
|
|
176
|
+
const selected = requestedAttachmentIds === void 0 ? [...referenced] : Array.from(new Set(requestedAttachmentIds));
|
|
177
|
+
for (const id of selected) if (!referenced.has(id)) throw new Error(`Attachment is not referenced by this Note: ${id}`);
|
|
178
|
+
const projectedMarkdown = projectPublicMarkdown(note, new Set(selected));
|
|
179
|
+
const markdownBytes = Buffer.byteLength(projectedMarkdown, "utf8");
|
|
180
|
+
if (markdownBytes > cfg.maxMarkdownBytes) throw new Error("Note Markdown exceeds sharing limit");
|
|
181
|
+
if (selected.length > cfg.maxAttachmentCount) throw new Error("Note has too many attachments to share");
|
|
182
|
+
const tempDir = targetDir === this.artifactDir(shareId) ? `${targetDir}.tmp-${randomUUID()}` : targetDir;
|
|
183
|
+
const assetsDir = join(tempDir, "assets");
|
|
184
|
+
await rm(tempDir, {
|
|
185
|
+
recursive: true,
|
|
186
|
+
force: true
|
|
187
|
+
});
|
|
188
|
+
await mkdir(assetsDir, {
|
|
189
|
+
recursive: true,
|
|
190
|
+
mode: 448
|
|
191
|
+
});
|
|
192
|
+
let totalSize = markdownBytes;
|
|
193
|
+
const attachments = [];
|
|
194
|
+
try {
|
|
195
|
+
for (const id of selected) {
|
|
196
|
+
const source = known.get(id);
|
|
197
|
+
if (source.size > cfg.maxAttachmentSize) throw new Error(`Attachment exceeds sharing limit: ${source.fileName}`);
|
|
198
|
+
totalSize += source.size;
|
|
199
|
+
if (totalSize > cfg.maxTotalSize) throw new Error("Note share exceeds total size limit");
|
|
200
|
+
const resolved = await this.notes.getAttachmentPath(note.id, id);
|
|
201
|
+
if (!resolved) throw new Error(`Attachment is missing: ${source.fileName}`);
|
|
202
|
+
const fileStat = await stat(resolved.filePath);
|
|
203
|
+
if (!fileStat.isFile() || fileStat.size !== source.size) throw new Error(`Attachment changed or is missing: ${source.fileName}`);
|
|
204
|
+
const bytes = await readFile(resolved.filePath);
|
|
205
|
+
const checksum = createHash("sha256").update(bytes).digest("hex");
|
|
206
|
+
await copyFile(resolved.filePath, join(assetsDir, id));
|
|
207
|
+
attachments.push({
|
|
208
|
+
id,
|
|
209
|
+
type: source.type,
|
|
210
|
+
mimeType: source.mimeType,
|
|
211
|
+
fileName: source.fileName,
|
|
212
|
+
size: source.size,
|
|
213
|
+
artifactFileName: id,
|
|
214
|
+
checksum,
|
|
215
|
+
duration: source.duration
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
const title = note.title?.trim() || "Untitled Note";
|
|
219
|
+
const manifest = {
|
|
220
|
+
schemaVersion: MANIFEST_SCHEMA_VERSION,
|
|
221
|
+
shareId,
|
|
222
|
+
source: {
|
|
223
|
+
noteId: note.id,
|
|
224
|
+
noteVersion: note.updatedAt
|
|
225
|
+
},
|
|
226
|
+
title,
|
|
227
|
+
markdown: projectedMarkdown,
|
|
228
|
+
snapshotAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
229
|
+
attachments
|
|
230
|
+
};
|
|
231
|
+
await writeFile(join(tempDir, "manifest.json"), `${JSON.stringify(manifest, null, 2)}\n`, { mode: 384 });
|
|
232
|
+
if (tempDir !== targetDir) {
|
|
233
|
+
await mkdir(dirname(targetDir), {
|
|
234
|
+
recursive: true,
|
|
235
|
+
mode: 448
|
|
236
|
+
});
|
|
237
|
+
await rename(tempDir, targetDir);
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
manifest,
|
|
241
|
+
totalSize
|
|
242
|
+
};
|
|
243
|
+
} catch (error) {
|
|
244
|
+
await rm(tempDir, {
|
|
245
|
+
recursive: true,
|
|
246
|
+
force: true
|
|
247
|
+
});
|
|
248
|
+
throw error;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
artifactRelativePath(shareId) {
|
|
252
|
+
return join("share-artifacts", shareId);
|
|
253
|
+
}
|
|
254
|
+
artifactDir(shareId) {
|
|
255
|
+
return join(resolveStateDir(), this.artifactRelativePath(shareId));
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
function projectPublicMarkdown(note, selected) {
|
|
259
|
+
const canonicalTarget = "xopc-attachment://notes/([^/\\s)]+)/([^\\s)]+)";
|
|
260
|
+
const assertOwned = new RegExp(canonicalTarget, "gi");
|
|
261
|
+
note.markdown.replace(assertOwned, (_match, rawNoteId) => {
|
|
262
|
+
let noteId;
|
|
263
|
+
try {
|
|
264
|
+
noteId = decodeURIComponent(rawNoteId);
|
|
265
|
+
} catch {
|
|
266
|
+
throw new Error("Invalid Note attachment reference");
|
|
267
|
+
}
|
|
268
|
+
if (noteId !== note.id) throw new Error("Cross-Note attachment references cannot be shared");
|
|
269
|
+
return _match;
|
|
270
|
+
});
|
|
271
|
+
const projectTarget = (rawNoteId, rawAttachmentId) => {
|
|
272
|
+
try {
|
|
273
|
+
return decodeURIComponent(rawNoteId) === note.id && selected.has(decodeURIComponent(rawAttachmentId));
|
|
274
|
+
} catch {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
let markdown = note.markdown.replace(new RegExp(`!\\[([^\\]]*)\\]\\(${canonicalTarget}\\)`, "gi"), (_match, alt, rawNoteId, rawAttachmentId) => projectTarget(rawNoteId, rawAttachmentId) ? _match : `_[Attachment not shared${alt ? `: ${alt}` : ""}]_`);
|
|
279
|
+
markdown = markdown.replace(new RegExp(`\\[([^\\]]+)\\]\\(${canonicalTarget}\\)`, "gi"), (_match, label, rawNoteId, rawAttachmentId) => projectTarget(rawNoteId, rawAttachmentId) ? _match : label);
|
|
280
|
+
return markdown;
|
|
281
|
+
}
|
|
282
|
+
//#endregion
|
|
283
|
+
export { NoteShareService, NoteShareVersionConflictError };
|