@capyclaw/ppt-suite 2.5.69 → 2.5.71
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/composition.lock.json +27 -27
- package/contract/ppt-contract.json +27 -1
- package/dsh-suite.json +27 -17
- package/node_modules/@capyclaw/asset-service/dsh-suite.json +1 -1
- package/node_modules/@capyclaw/asset-service/package.json +1 -1
- package/node_modules/@capyclaw/asset-service/src/index.mjs +4 -3
- package/node_modules/@capyclaw/document-workbench/package.json +6 -3
- package/node_modules/@capyclaw/document-workbench/src/client/index.mjs +56 -3
- package/node_modules/@capyclaw/document-workbench/src/client/visibility.mjs +112 -0
- package/node_modules/@capyclaw/document-workbench/src/model/manifest.mjs +6 -4
- package/node_modules/@capyclaw/document-workbench/src/model/ops.mjs +7 -2
- package/node_modules/@capyclaw/document-workbench/src/session/index.mjs +8 -0
- package/node_modules/@capyclaw/document-workbench/src/store/file-backend.mjs +17 -10
- package/node_modules/@capyclaw/document-workbench/src/store/projection.mjs +39 -0
- package/node_modules/@capyclaw/document-workbench/src/testing/index.mjs +14 -11
- package/node_modules/@capyclaw/editor-host/dsh-suite.json +1 -1
- package/node_modules/@capyclaw/editor-host/package.json +1 -1
- package/node_modules/@capyclaw/editor-host/src/index.mjs +12 -21
- package/node_modules/@capyclaw/foundation/abi/assets.mjs +26 -0
- package/node_modules/@capyclaw/foundation/abi/bridge.mjs +3 -1
- package/node_modules/@capyclaw/foundation/abi/index.mjs +15 -0
- package/node_modules/@capyclaw/foundation/abi/visibility.mjs +90 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +21 -4
- package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +5 -1
- package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +5 -2
- package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +4 -0
- package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +29 -2
- package/node_modules/@capyclaw/foundation/lib/kernel.mjs +13 -3
- package/node_modules/@capyclaw/foundation/package.json +1 -1
- package/node_modules/@capyclaw/plugin-kit/package.json +3 -1
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +5 -2
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat.mjs +26 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +3 -1
- package/node_modules/@capyclaw/plugin-kit/src/service/static.mjs +79 -0
- package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +13 -5
- package/node_modules/@capyclaw/portal/package.json +1 -1
- package/node_modules/@capyclaw/ppt-editor/app.js +458 -10
- package/node_modules/@capyclaw/ppt-editor/contract/ppt-contract.json +27 -1
- package/node_modules/@capyclaw/ppt-editor/heartbeat-worker.js +5 -2
- package/node_modules/@capyclaw/ppt-editor/index.html +4 -0
- package/node_modules/@capyclaw/ppt-editor/package.json +2 -2
- package/node_modules/@capyclaw/ppt-skill-api/contract/ppt-contract.json +27 -1
- package/node_modules/@capyclaw/ppt-skill-api/package.json +1 -1
- package/node_modules/@capyclaw/ppt-skill-api/skills/pptist-api/references/tool-contract.md +1 -1
- package/node_modules/@capyclaw/ppt-skill-proposal/contract/ppt-contract.json +27 -1
- package/node_modules/@capyclaw/ppt-skill-proposal/package.json +1 -1
- package/node_modules/@capyclaw/ppt-workbench/contract/ppt-contract.json +27 -1
- package/node_modules/@capyclaw/ppt-workbench/core/deck-layout.js +3 -1
- package/node_modules/@capyclaw/ppt-workbench/core/ops/slide.js +9 -3
- package/node_modules/@capyclaw/ppt-workbench/core/text.js +14 -2
- package/node_modules/@capyclaw/ppt-workbench/package.json +10 -8
- package/node_modules/@capyclaw/ppt-workbench/plugin.mjs +13 -1
- package/node_modules/@capyclaw/ppt-workbench/server/contract.mjs +1 -1
- package/node_modules/@capyclaw/ppt-workbench/server/embedded-host.mjs +201 -20
- package/node_modules/@capyclaw/ppt-workbench/server/relay.mjs +10 -7
- package/node_modules/@capyclaw/ppt-workbench/server/shared/SHARED_MANIFEST.json +4 -4
- package/node_modules/@capyclaw/ppt-workbench/server/store/backends/file-backend.mjs +3 -0
- package/node_modules/@capyclaw/ppt-workbench/server/store/checkpoints.mjs +4 -1
- package/node_modules/@capyclaw/ppt-workbench/server/store/index.mjs +4 -0
- package/node_modules/@capyclaw/ppt-workbench/server/store/sessions.mjs +139 -4
- package/node_modules/@capyclaw/ppt-workbench/server/store/shape.mjs +37 -0
- package/node_modules/@capyclaw/ppt-workbench/server/workbench-framework.mjs +34 -0
- package/node_modules/@capyclaw/service-broker/README.md +1 -1
- package/node_modules/@capyclaw/service-broker/lib/control.mjs +23 -7
- package/node_modules/@capyclaw/service-broker/lib/engine.mjs +60 -6
- package/node_modules/@capyclaw/service-broker/lib/host.mjs +11 -6
- package/node_modules/@capyclaw/service-broker/lib/skills-client.mjs +30 -10
- package/node_modules/@capyclaw/service-broker/package.json +1 -1
- package/node_modules/@capyclaw/service-host/dsh-suite.json +1 -1
- package/node_modules/@capyclaw/service-host/package.json +1 -1
- package/node_modules/@capyclaw/service-host/src/index.mjs +13 -22
- package/node_modules/@capyclaw/skills-service/README.md +42 -10
- package/node_modules/@capyclaw/skills-service/package.json +6 -3
- package/node_modules/@capyclaw/skills-service/server.mjs +129 -51
- package/node_modules/@capyclaw/suite-kit/README.md +289 -0
- package/node_modules/@capyclaw/suite-kit/bin/dsh-domain.mjs +98 -0
- package/node_modules/@capyclaw/suite-kit/bin/dsh-suite.mjs +174 -0
- package/node_modules/@capyclaw/suite-kit/client/embed.js +35 -0
- package/node_modules/@capyclaw/suite-kit/domain.schema.json +129 -0
- package/node_modules/@capyclaw/suite-kit/package.json +58 -0
- package/node_modules/@capyclaw/suite-kit/src/activation-registry.mjs +184 -0
- package/node_modules/@capyclaw/suite-kit/src/artifacts.mjs +131 -0
- package/node_modules/@capyclaw/suite-kit/src/capability.mjs +181 -0
- package/node_modules/@capyclaw/suite-kit/src/compose.mjs +201 -0
- package/node_modules/@capyclaw/suite-kit/src/domain.mjs +138 -0
- package/node_modules/@capyclaw/suite-kit/src/embed.mjs +81 -0
- package/node_modules/@capyclaw/suite-kit/src/host.mjs +230 -0
- package/node_modules/@capyclaw/suite-kit/src/index.mjs +24 -0
- package/node_modules/@capyclaw/suite-kit/src/manifest.mjs +263 -0
- package/node_modules/@capyclaw/suite-kit/src/orchestration.mjs +100 -0
- package/node_modules/@capyclaw/suite-kit/src/profile.mjs +584 -0
- package/node_modules/@capyclaw/suite-kit/src/surface.mjs +28 -0
- package/node_modules/@capyclaw/suite-kit/suite.schema.json +128 -0
- package/node_modules/@capyclaw/tool-host/dsh-suite.json +2 -2
- package/node_modules/@capyclaw/tool-host/lib/host.mjs +34 -4
- package/node_modules/@capyclaw/tool-host/package.json +1 -1
- package/node_modules/@capyclaw/tool-host/src/admit-images.mjs +80 -0
- package/node_modules/@capyclaw/tool-host/src/caller-session.mjs +25 -0
- package/node_modules/@capyclaw/tool-host/src/index.mjs +59 -14
- package/node_modules/@capyclaw/tool-host/src/mode-gate.mjs +272 -0
- package/node_modules/@capyclaw/work-store/README.md +83 -0
- package/node_modules/@capyclaw/work-store/STANDARD.md +263 -0
- package/node_modules/@capyclaw/work-store/cordis.patch.yml +3 -0
- package/node_modules/@capyclaw/work-store/dsh-suite.json +33 -0
- package/node_modules/@capyclaw/work-store/icon.svg +7 -0
- package/node_modules/@capyclaw/work-store/lib/host.mjs +21 -0
- package/node_modules/@capyclaw/work-store/package.json +68 -0
- package/node_modules/@capyclaw/work-store/src/backend.mjs +90 -0
- package/node_modules/@capyclaw/work-store/src/db.mjs +199 -0
- package/node_modules/@capyclaw/work-store/src/envelope.mjs +132 -0
- package/node_modules/@capyclaw/work-store/src/index.mjs +571 -0
- package/node_modules/@capyclaw/work-store/src/interop.mjs +70 -0
- package/node_modules/@capyclaw/work-store/src/refs.mjs +99 -0
- package/node_modules/@capyclaw/work-store/src/routes.mjs +135 -0
- package/node_modules/playwright-core/LICENSE +202 -0
- package/node_modules/playwright-core/NOTICE +5 -0
- package/node_modules/playwright-core/README.md +3 -0
- package/node_modules/playwright-core/ThirdPartyNotices.txt +13 -0
- package/node_modules/playwright-core/bin/install_media_pack.ps1 +5 -0
- package/node_modules/playwright-core/bin/install_webkit_wsl.ps1 +33 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_beta_linux.sh +42 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_beta_mac.sh +13 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_beta_win.ps1 +24 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_stable_linux.sh +42 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_stable_mac.sh +12 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_stable_win.ps1 +24 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_beta_linux.sh +48 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_beta_mac.sh +11 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_beta_win.ps1 +23 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_dev_linux.sh +48 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_dev_mac.sh +11 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_dev_win.ps1 +23 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_stable_linux.sh +48 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_stable_mac.sh +11 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_stable_win.ps1 +24 -0
- package/node_modules/playwright-core/browsers.json +52 -0
- package/node_modules/playwright-core/cli.js +22 -0
- package/node_modules/playwright-core/index.d.ts +17 -0
- package/node_modules/playwright-core/index.js +17 -0
- package/node_modules/playwright-core/index.mjs +28 -0
- package/node_modules/playwright-core/lib/bootstrap.js +149 -0
- package/node_modules/playwright-core/lib/coreBundle.js +78041 -0
- package/node_modules/playwright-core/lib/entry/cliDaemon.js +5 -0
- package/node_modules/playwright-core/lib/entry/dashboardApp.js +3 -0
- package/node_modules/playwright-core/lib/entry/mcp.js +10 -0
- package/node_modules/playwright-core/lib/entry/oopBrowserDownload.js +3 -0
- package/node_modules/playwright-core/lib/package.js +50 -0
- package/node_modules/playwright-core/lib/server/chromium/appIcon.png +0 -0
- package/node_modules/playwright-core/lib/server/electron/loader.js +123 -0
- package/node_modules/playwright-core/lib/serverRegistry.js +1939 -0
- package/node_modules/playwright-core/lib/serverRegistry.js.LICENSE +65 -0
- package/node_modules/playwright-core/lib/tools/cli-client/channelSessions.js +141 -0
- package/node_modules/playwright-core/lib/tools/cli-client/cli.js +7 -0
- package/node_modules/playwright-core/lib/tools/cli-client/help.json +808 -0
- package/node_modules/playwright-core/lib/tools/cli-client/minimist.js +128 -0
- package/node_modules/playwright-core/lib/tools/cli-client/output.js +352 -0
- package/node_modules/playwright-core/lib/tools/cli-client/program.js +422 -0
- package/node_modules/playwright-core/lib/tools/cli-client/registry.js +180 -0
- package/node_modules/playwright-core/lib/tools/cli-client/session.js +261 -0
- package/node_modules/playwright-core/lib/tools/dashboard/appIcon.png +0 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/SKILL.md +493 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/element-attributes.md +23 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/playwright-tests.md +39 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/pr-attachments.md +60 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/request-mocking.md +87 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/running-code.md +245 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/session-management.md +227 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/storage-state.md +275 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/test-generation.md +433 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/tracing.md +139 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/video-recording.md +216 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/SKILL.md +136 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/gallery-spec.md +144 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/migration.md +89 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/react.md +69 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/typing.md +173 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/vue.md +77 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-trace/SKILL.md +174 -0
- package/node_modules/playwright-core/lib/tools/utils/extension.js +112 -0
- package/node_modules/playwright-core/lib/tools/utils/socketConnection.js +108 -0
- package/node_modules/playwright-core/lib/utilsBundle.js +86078 -0
- package/node_modules/playwright-core/lib/utilsBundle.js.LICENSE +1890 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/codeMirrorModule--QdMvsKi.css +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/codeMirrorModule-CQ8RZGBm.js +32 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/codicon-DCmgc-ay.ttf +0 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/firefox-1bWoP6pv.svg +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/firefox-beta-k3eOH_eK.svg +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/firefox-nightly-Cp5nfeDT.svg +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/index-AwgwcYie.css +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/index-hRvO4yU2.js +12 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/safari-na3_-uQk.svg +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/index.html +29 -0
- package/node_modules/playwright-core/lib/vite/dashboard/playwright-logo.svg +24 -0
- package/node_modules/playwright-core/lib/vite/htmlReport/index.html +16 -0
- package/node_modules/playwright-core/lib/vite/htmlReport/report.css +2 -0
- package/node_modules/playwright-core/lib/vite/htmlReport/report.js +32 -0
- package/node_modules/playwright-core/lib/vite/recorder/assets/codeMirrorModule--QdMvsKi.css +1 -0
- package/node_modules/playwright-core/lib/vite/recorder/assets/codeMirrorModule-DK72OMRi.js +32 -0
- package/node_modules/playwright-core/lib/vite/recorder/assets/codicon-DCmgc-ay.ttf +0 -0
- package/node_modules/playwright-core/lib/vite/recorder/assets/index-BZpYJZ-P.css +1 -0
- package/node_modules/playwright-core/lib/vite/recorder/assets/index-Cn0mmDuv.js +129 -0
- package/node_modules/playwright-core/lib/vite/recorder/index.html +29 -0
- package/node_modules/playwright-core/lib/vite/recorder/playwright-logo.svg +9 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/assets/codeMirrorModule-BEB2e8M3.js +32 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/assets/defaultSettingsView-D-g2vrvf.js +184 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/assets/urlMatch-L3liM589.js +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/assets/xtermModule-B794rD2Z.js +7 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/codeMirrorModule.-QdMvsKi.css +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/codicon.DCmgc-ay.ttf +0 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/defaultSettingsView.C8BeHuxd.css +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/index.B_TqY17P.css +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/index.html +44 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/index.oNry3Hjv.js +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/manifest.webmanifest +16 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/playwright-logo.svg +9 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/snapshot.B_Jk1wbt.js +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/snapshot.html +10 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/sw.bundle.js +4 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/uiMode.CYwC_gH1.js +5 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/uiMode.CyMfwkXJ.css +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/uiMode.html +18 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/xtermModule.kHJ-D0s7.css +1 -0
- package/node_modules/playwright-core/lib/webp_codec.LICENSE +173 -0
- package/node_modules/playwright-core/lib/webp_codec.wasm +0 -0
- package/node_modules/playwright-core/lib/xdg-open +1267 -0
- package/node_modules/playwright-core/package.json +34 -0
- package/node_modules/playwright-core/types/protocol.d.ts +24776 -0
- package/node_modules/playwright-core/types/structs.d.ts +52 -0
- package/node_modules/playwright-core/types/types.d.ts +27167 -0
- package/package.json +17 -15
|
@@ -4,28 +4,28 @@
|
|
|
4
4
|
"packages": {
|
|
5
5
|
"service-host": {
|
|
6
6
|
"package": "@capyclaw/service-host",
|
|
7
|
-
"version": "0.1.
|
|
7
|
+
"version": "0.1.7",
|
|
8
8
|
"apiVersion": "1.0.0",
|
|
9
9
|
"spec": "@capyclaw/service-host/src",
|
|
10
10
|
"sha256": "af0a57d779bfe6a66dc935320178d591ef799a7e037f7a5823cdfa1fe5878eeb"
|
|
11
11
|
},
|
|
12
12
|
"tool-host": {
|
|
13
13
|
"package": "@capyclaw/tool-host",
|
|
14
|
-
"version": "0.2
|
|
14
|
+
"version": "0.3.2",
|
|
15
15
|
"apiVersion": "1.1.0",
|
|
16
16
|
"spec": "@capyclaw/tool-host/src",
|
|
17
17
|
"sha256": "23256dbcd5cbee0b96b33c97e4eb4e74d0e169cbdde52f91d4526f2fc0f60d3e"
|
|
18
18
|
},
|
|
19
19
|
"asset-service": {
|
|
20
20
|
"package": "@capyclaw/asset-service",
|
|
21
|
-
"version": "0.1.
|
|
21
|
+
"version": "0.1.6",
|
|
22
22
|
"apiVersion": "1.0.0",
|
|
23
23
|
"spec": "@capyclaw/asset-service/src",
|
|
24
24
|
"sha256": "311a83e95d56dbb69b739d61aced0889b64e85eddd95b883e322e0fa5be8bd6f"
|
|
25
25
|
},
|
|
26
26
|
"editor-host": {
|
|
27
27
|
"package": "@capyclaw/editor-host",
|
|
28
|
-
"version": "0.1.
|
|
28
|
+
"version": "0.1.7",
|
|
29
29
|
"apiVersion": "1.0.0",
|
|
30
30
|
"spec": "@capyclaw/editor-host/src",
|
|
31
31
|
"sha256": "c8b80dbd4f1b2bee9ef9001423a013031a21ea9a3b8897b5536fe6e5687f01b3"
|
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
import { FileStateBackend } from '@capyclaw/document-workbench/store/file-backend'
|
|
3
3
|
import { getTuning } from '../../tuning.mjs'
|
|
4
4
|
import { EMPTY_DOC } from '../doc.mjs'
|
|
5
|
+
import { projectPptCheckpoint } from '../shape.mjs'
|
|
5
6
|
|
|
6
7
|
export class FileBridgeBackend extends FileStateBackend {
|
|
7
8
|
constructor(file) {
|
|
8
9
|
super(file, {
|
|
9
10
|
initialDoc: EMPTY_DOC(),
|
|
10
11
|
journalMaxBytes: getTuning().journalMaxBytes,
|
|
12
|
+
/* PPT 形状投影显式传入:内核默认只回通用信封,slides/title 由适配层声明。 */
|
|
13
|
+
project: projectPptCheckpoint,
|
|
11
14
|
})
|
|
12
15
|
}
|
|
13
16
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/** 兼容层:checkpoint 名称与载荷沿用 PPT 字段,底层由 DocumentSession 写入。 */
|
|
2
|
+
import { deckPages } from './shape.mjs'
|
|
3
|
+
|
|
2
4
|
export { checkpointName } from '@capyclaw/document-workbench/session'
|
|
3
5
|
|
|
4
6
|
export function buildCheckpoint(doc, name, meta = {}) {
|
|
@@ -10,7 +12,8 @@ export function buildCheckpoint(doc, name, meta = {}) {
|
|
|
10
12
|
appliedSeq: doc.applied_seq | 0,
|
|
11
13
|
pending,
|
|
12
14
|
title: doc.title || deck.title || '未命名',
|
|
13
|
-
|
|
15
|
+
/* 页解释走适配层形状声明(deckPages),不在这里硬编码 deck.slides。 */
|
|
16
|
+
slides: deckPages(doc).length,
|
|
14
17
|
deck,
|
|
15
18
|
meta: meta && typeof meta === 'object' ? meta : {},
|
|
16
19
|
createdAt: new Date().toISOString(),
|
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
import { DocumentSession, OWNER_TTL } from '@capyclaw/document-workbench/session'
|
|
6
6
|
import { FileBridgeBackend } from './backends/file-backend.mjs'
|
|
7
7
|
import { EMPTY_DOC } from './doc.mjs'
|
|
8
|
+
import { PPT_SHAPE } from './shape.mjs'
|
|
8
9
|
|
|
9
10
|
export * from './sanitize.mjs'
|
|
10
11
|
export { OWNER_TTL, FileBridgeBackend }
|
|
12
|
+
export { PPT_SHAPE, deckPages, projectPptCheckpoint } from './shape.mjs'
|
|
11
13
|
|
|
12
14
|
export class BridgeStore extends DocumentSession {
|
|
13
15
|
constructor(fileOrOptions) {
|
|
@@ -21,6 +23,8 @@ export class BridgeStore extends DocumentSession {
|
|
|
21
23
|
initialDoc: EMPTY_DOC(),
|
|
22
24
|
documentKey: 'deck',
|
|
23
25
|
stateCompact: true,
|
|
26
|
+
/* 形状标签随 checkpoint 写入;列表业务字段由 backend 的 project 声明叠加。 */
|
|
27
|
+
shape: PPT_SHAPE,
|
|
24
28
|
summary: (doc) => ({
|
|
25
29
|
title: doc.deck && doc.deck.title ? doc.deck.title : '未命名',
|
|
26
30
|
slides: doc.deck && Array.isArray(doc.deck.slides) ? doc.deck.slides.length : 0,
|
|
@@ -32,11 +32,20 @@ import fs from 'node:fs'
|
|
|
32
32
|
import os from 'node:os'
|
|
33
33
|
import path from 'node:path'
|
|
34
34
|
import { BridgeStore } from './index.mjs'
|
|
35
|
+
import { projectPptCheckpoint } from './shape.mjs'
|
|
35
36
|
import { currentSession, sessionContext } from '../session-context.mjs'
|
|
37
|
+
import { isOwnerLive, isShadowOwner } from '@capyclaw/document-workbench/session'
|
|
36
38
|
|
|
37
39
|
export const DEFAULT_SESSION = 'default'
|
|
38
40
|
export const DECK_FILE = 'deck.json'
|
|
39
41
|
|
|
42
|
+
/* 空闲 TTL 驱逐:store 常驻整份内存 deck(含 base64 图时可能很大),旧实现缓存只增不减,
|
|
43
|
+
* 内存随会话数无界。这里周期性驱逐「空闲足够久」的实例,但驱逐前排空写队列并 fsync 落盘,
|
|
44
|
+
* 驱逐后保留 metadata-only 快照,让 sessions() 列表与影子对账仍看得到该会话(不复活实例)。
|
|
45
|
+
* 活跃保护:有 pending 写或挂着长轮询 watcher 的实例永不驱逐;单实例由「flush 后才删」保证。 */
|
|
46
|
+
export const IDLE_TTL_MS = 5 * 60 * 1000
|
|
47
|
+
export const EVICT_INTERVAL_MS = 60 * 1000
|
|
48
|
+
|
|
40
49
|
/** 会话目录的根:DSH 里是 `$DSH_HOME/ppt-sessions`,独立运行是 `<hostDir>/sessions`。 */
|
|
41
50
|
export function sessionsHomeFor({ hostDir, embedded = false, env = process.env } = {}) {
|
|
42
51
|
const explicit = String(env.PPT_SESSIONS_HOME || '').trim()
|
|
@@ -78,7 +87,8 @@ export function scopedWorkspaceClient(client, prefix) {
|
|
|
78
87
|
}
|
|
79
88
|
|
|
80
89
|
export class SessionStores {
|
|
81
|
-
constructor({ hostDir, backend = null, sessionsHome = '', getWorkStore = null
|
|
90
|
+
constructor({ hostDir, backend = null, sessionsHome = '', getWorkStore = null,
|
|
91
|
+
idleTtlMs = IDLE_TTL_MS, evictIntervalMs = EVICT_INTERVAL_MS, autoEvict = true } = {}) {
|
|
82
92
|
if (!hostDir) throw new Error('SessionStores 需要 hostDir')
|
|
83
93
|
this.hostDir = hostDir
|
|
84
94
|
/* 真机形态下 DSH 会塞一个 workspace 后端进来。它现在只当「旧数据的来源」用:
|
|
@@ -98,6 +108,21 @@ export class SessionStores {
|
|
|
98
108
|
this.getWorkStore = getWorkStore
|
|
99
109
|
this._workStore = null
|
|
100
110
|
this.sanitizer = null
|
|
111
|
+
/* 空闲驱逐跟踪:_lastUsed 记每键最近一次 forSession 访问;_known 是 metadata-only 注册表
|
|
112
|
+
* (永不缩,sessions() 由它派生);_meta 存被驱逐会话的轻量快照(内容计数 + owner),
|
|
113
|
+
* 供影子对账在不复活实例的前提下仍能看到该会话。 */
|
|
114
|
+
this.idleTtlMs = Number.isFinite(idleTtlMs) ? idleTtlMs : IDLE_TTL_MS
|
|
115
|
+
this.evictIntervalMs = Number.isFinite(evictIntervalMs) ? evictIntervalMs : EVICT_INTERVAL_MS
|
|
116
|
+
this._lastUsed = new Map()
|
|
117
|
+
this._known = new Set()
|
|
118
|
+
this._meta = new Map()
|
|
119
|
+
this._evicting = false
|
|
120
|
+
this._disposed = false
|
|
121
|
+
this._evictTimer = null
|
|
122
|
+
if (autoEvict && this.idleTtlMs > 0 && this.evictIntervalMs > 0) {
|
|
123
|
+
this._evictTimer = setInterval(() => { this.evictIdleNow().catch(() => {}) }, this.evictIntervalMs)
|
|
124
|
+
this._evictTimer.unref?.()
|
|
125
|
+
}
|
|
101
126
|
}
|
|
102
127
|
|
|
103
128
|
/** relay prepare 钩子在 createStore 之后、首个请求之前塞入懒解析器。 */
|
|
@@ -105,7 +130,9 @@ export class SessionStores {
|
|
|
105
130
|
this.getWorkStore = getter || null
|
|
106
131
|
this._workStore = null
|
|
107
132
|
/* 解析器换了,旧句柄绑定的每会话 store 一律作废,下次访问重建。 */
|
|
133
|
+
this._snapshotAllToMeta()
|
|
108
134
|
this.cache.clear()
|
|
135
|
+
this._lastUsed.clear()
|
|
109
136
|
}
|
|
110
137
|
|
|
111
138
|
/** 落盘净化器(base64 闸):由 relay prepare 注入,绑定 assetStore + urlBase。 */
|
|
@@ -132,14 +159,17 @@ export class SessionStores {
|
|
|
132
159
|
} catch { /* 解析失败就当没有底座,降级文件 */ }
|
|
133
160
|
if (ws && ws !== this._workStore) {
|
|
134
161
|
this._workStore = ws
|
|
162
|
+
this._snapshotAllToMeta()
|
|
135
163
|
this.cache.clear()
|
|
164
|
+
this._lastUsed.clear()
|
|
136
165
|
}
|
|
137
166
|
return this._workStore || null
|
|
138
167
|
}
|
|
139
168
|
|
|
140
|
-
/** 已经出现过的会话(不含 fallback
|
|
169
|
+
/** 已经出现过的会话(不含 fallback)。由 _known 注册表派生:实例被空闲驱逐后
|
|
170
|
+
* 会话仍列得出(metadata-only),不会从列表里静默消失。 */
|
|
141
171
|
sessions() {
|
|
142
|
-
return [...this.
|
|
172
|
+
return [...this._known].filter((key) => key !== DEFAULT_SESSION)
|
|
143
173
|
}
|
|
144
174
|
|
|
145
175
|
/** 拆库前那份全局稿子归了哪个会话(没迁过就是空串)。 */
|
|
@@ -174,7 +204,11 @@ export class SessionStores {
|
|
|
174
204
|
if (!store) {
|
|
175
205
|
store = this.create(key)
|
|
176
206
|
this.cache.set(key, store)
|
|
207
|
+
/* 活实例接管:丢弃驱逐期的元数据快照,对账改读实时 doc。 */
|
|
208
|
+
this._meta.delete(key)
|
|
177
209
|
}
|
|
210
|
+
this._known.add(key)
|
|
211
|
+
this._lastUsed.set(key, Date.now())
|
|
178
212
|
return store
|
|
179
213
|
}
|
|
180
214
|
|
|
@@ -191,7 +225,7 @@ export class SessionStores {
|
|
|
191
225
|
/* 底座形态:deck 落 SQLite 作品库(自然键 ppt:deck:<会话id>)。
|
|
192
226
|
* 旧文件数据在首次访问时一次性导入(只读种子,不覆盖已有库数据),
|
|
193
227
|
* 旧 deck.json 保留作备份。文件专属的崩溃安全由 SQLite WAL 接管。 */
|
|
194
|
-
const backend = ws.backendFor({ suite: 'ppt', kind: 'deck', sessionId: key, transform: this.sanitizer })
|
|
228
|
+
const backend = ws.backendFor({ suite: 'ppt', kind: 'deck', sessionId: key, transform: this.sanitizer, project: projectPptCheckpoint })
|
|
195
229
|
this.seedIntoDb(key, file, backend)
|
|
196
230
|
return new BridgeStore({ backend })
|
|
197
231
|
}
|
|
@@ -257,6 +291,107 @@ export class SessionStores {
|
|
|
257
291
|
current() {
|
|
258
292
|
return this.forSession(this.currentKey())
|
|
259
293
|
}
|
|
294
|
+
|
|
295
|
+
/* ---- 空闲 TTL 驱逐 ---- */
|
|
296
|
+
|
|
297
|
+
/** 是否挂着长轮询 watcher(有则永不驱逐,避免 watcher 成孤儿/收到旧实例通知)。 */
|
|
298
|
+
_hasWaiters(store) {
|
|
299
|
+
return !!(store && store._waiters && store._waiters.size > 0)
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** 驱逐/清缓存时的轻量元数据快照:只留内容计数 + owner,释放整份内存 deck。 */
|
|
303
|
+
_metaOf(doc) {
|
|
304
|
+
return {
|
|
305
|
+
contentCount: (doc && doc.deck && Array.isArray(doc.deck.slides)) ? doc.deck.slides.length : 0,
|
|
306
|
+
owner: doc && doc.owner ? { ...doc.owner } : null,
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** 底座重载清缓存前,把活实例快照成元数据,保证对账在重建前仍看得到每个会话。 */
|
|
311
|
+
_snapshotAllToMeta() {
|
|
312
|
+
for (const [key, store] of this.cache) {
|
|
313
|
+
try { this._meta.set(key, this._metaOf(store.get())) } catch { /* ignore */ }
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** 影子对账投影:不复活实例、不刷新 idle 钟。活实例从实时 doc 算;被驱逐会话从
|
|
318
|
+
* 元数据快照算(owner 存活按时间现算,随 TTL 自然 stale)。无该会话则回 null。 */
|
|
319
|
+
reconcileInfo(sid) {
|
|
320
|
+
const key = normalizeSessionId(sid) || DEFAULT_SESSION
|
|
321
|
+
const store = this.cache.get(key)
|
|
322
|
+
if (store) {
|
|
323
|
+
const doc = store.get()
|
|
324
|
+
return {
|
|
325
|
+
hasContent: !!(doc && doc.deck && Array.isArray(doc.deck.slides) && doc.deck.slides.length),
|
|
326
|
+
ownerLive: isOwnerLive(doc),
|
|
327
|
+
ownerShadow: isShadowOwner(doc),
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
const meta = this._meta.get(key)
|
|
331
|
+
if (!meta) return null
|
|
332
|
+
const ownerDoc = { owner: meta.owner }
|
|
333
|
+
return {
|
|
334
|
+
hasContent: meta.contentCount > 0,
|
|
335
|
+
ownerLive: isOwnerLive(ownerDoc),
|
|
336
|
+
ownerShadow: isShadowOwner(ownerDoc),
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/** 驱逐单键:排空写队列 → 重验 → 快照元数据 → fsync 落盘 → 才从缓存移除。
|
|
341
|
+
* store 全程留在 cache,forSession 不会建第二实例 → 同一 id 任何时刻只有一个活实例。 */
|
|
342
|
+
async _evict(key) {
|
|
343
|
+
const store = this.cache.get(key)
|
|
344
|
+
if (!store) return false
|
|
345
|
+
if (this._hasWaiters(store)) return false
|
|
346
|
+
/* 排空串行写队列:基类 _tail 恒 resolve(错误被吞),循环等到链尾不再增长。
|
|
347
|
+
* 有界轮数:期间持续被写说明会话活跃,放弃本轮驱逐(下一轮再试)。 */
|
|
348
|
+
let drained = false
|
|
349
|
+
for (let pass = 0; pass < 8; pass += 1) {
|
|
350
|
+
const tail = store._tail
|
|
351
|
+
await tail
|
|
352
|
+
if (store._tail === tail) { drained = true; break }
|
|
353
|
+
}
|
|
354
|
+
if (!drained) return false
|
|
355
|
+
/* await 之后重新校验:实例没被换、没挂上 watch、确实空闲够久(期间被复用则放弃)。 */
|
|
356
|
+
if (this.cache.get(key) !== store) return false
|
|
357
|
+
if (this._hasWaiters(store)) return false
|
|
358
|
+
const last = this._lastUsed.get(key) || 0
|
|
359
|
+
if (Date.now() - last < this.idleTtlMs) return false
|
|
360
|
+
this._meta.set(key, this._metaOf(store.get()))
|
|
361
|
+
/* fsync 落盘(文件后端有 flush();SQLite 底座 WAL 已持久,无 flush 则跳过)。 */
|
|
362
|
+
try { if (typeof store.backend?.flush === 'function') store.backend.flush() } catch { /* fsync 失败不阻塞驱逐 */ }
|
|
363
|
+
this.cache.delete(key)
|
|
364
|
+
this._lastUsed.delete(key)
|
|
365
|
+
return true
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/** 一轮驱逐巡检(重入守卫)。定时器周期驱动;测试可手动调用。返回驱逐数量。 */
|
|
369
|
+
async evictIdleNow() {
|
|
370
|
+
if (this._evicting || this._disposed) return 0
|
|
371
|
+
this._evicting = true
|
|
372
|
+
let removed = 0
|
|
373
|
+
try {
|
|
374
|
+
const now = Date.now()
|
|
375
|
+
const candidates = []
|
|
376
|
+
for (const [key, store] of this.cache) {
|
|
377
|
+
if (this._hasWaiters(store)) continue
|
|
378
|
+
const last = this._lastUsed.get(key) || 0
|
|
379
|
+
if (now - last >= this.idleTtlMs) candidates.push(key)
|
|
380
|
+
}
|
|
381
|
+
for (const key of candidates) {
|
|
382
|
+
if (await this._evict(key)) removed += 1
|
|
383
|
+
}
|
|
384
|
+
} finally {
|
|
385
|
+
this._evicting = false
|
|
386
|
+
}
|
|
387
|
+
return removed
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/** 卸载:清驱逐定时器(relay beforeStop 调用)。不影响已落盘数据。 */
|
|
391
|
+
dispose() {
|
|
392
|
+
this._disposed = true
|
|
393
|
+
if (this._evictTimer) { clearInterval(this._evictTimer); this._evictTimer = null }
|
|
394
|
+
}
|
|
260
395
|
}
|
|
261
396
|
|
|
262
397
|
function readJson(file) {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PPT 存储适配层的形状声明(M5 / checkpoint 投影通用化)。
|
|
3
|
+
*
|
|
4
|
+
* 内核(document-workbench / work-store)不再硬编码 deck.slides:
|
|
5
|
+
* PPT 的页解释与 checkpoint 投影在这里显式声明,再传给内核——
|
|
6
|
+
* - PPT_SHAPE:写入 checkpoint payload 的形状标签(新格式);旧 payload 无标签,
|
|
7
|
+
* 投影按 deck 键兜底,保证旧 checkpoint 仍可读。
|
|
8
|
+
* - deckPages:PPT 页解释(模型侧 schema.pages 同语义,mcp 层 deck-schema.mjs 是模型入口)。
|
|
9
|
+
* - projectPptCheckpoint:checkpoint 列表投影 = 会话协议字段 + PPT 业务字段(title/slides),
|
|
10
|
+
* 兼容三种历史形状:
|
|
11
|
+
* 1) 新:payload.slides 为数字(summary 写入)+ payload.shape 标签;
|
|
12
|
+
* 2) 旧:仅 payload.deck.slides 数组(无顶层 slides);
|
|
13
|
+
* 3) 更旧:payload.slides 本身是数组。
|
|
14
|
+
*/
|
|
15
|
+
import { sessionCheckpointFields } from '@capyclaw/document-workbench/store/projection'
|
|
16
|
+
|
|
17
|
+
export const PPT_SHAPE = 'ppt.deck'
|
|
18
|
+
|
|
19
|
+
/** PPT 页解释:接受 deck 本体({slides})或会话信封({deck:{slides}})。 */
|
|
20
|
+
export function deckPages(doc) {
|
|
21
|
+
const deck = doc && Array.isArray(doc.slides) ? doc : (doc && doc.deck)
|
|
22
|
+
return deck && Array.isArray(deck.slides) ? deck.slides : []
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** checkpoint 列表投影:传给 backendFor / FileStateBackend 的 project(形状声明)。 */
|
|
26
|
+
export function projectPptCheckpoint(payload) {
|
|
27
|
+
const p = payload && typeof payload === 'object' ? payload : {}
|
|
28
|
+
const out = sessionCheckpointFields(p)
|
|
29
|
+
const deck = p.deck && typeof p.deck === 'object' ? p.deck : null
|
|
30
|
+
const title = p.title || (deck && deck.title) || ''
|
|
31
|
+
if (title) out.title = title
|
|
32
|
+
if (typeof p.slides === 'number') out.slides = p.slides | 0
|
|
33
|
+
else if (Array.isArray(p.slides)) out.slides = p.slides.length
|
|
34
|
+
else if (deck && Array.isArray(deck.slides)) out.slides = deck.slides.length
|
|
35
|
+
else out.slides = 0
|
|
36
|
+
return out
|
|
37
|
+
}
|
|
@@ -111,7 +111,13 @@ export function createWorkbench(spec) {
|
|
|
111
111
|
* 已创建的资源——否则引擎/仓库泄漏在仍存活的进程里(reused 分支的 stop 是
|
|
112
112
|
* no-op,不会有人替它清理)。外部传入的 assetStore 不归本框架关。 */
|
|
113
113
|
let app
|
|
114
|
+
/* 资产仓库周期 GC:默认只清孤儿临时文件(安全——内容寻址资产被稿件引用,
|
|
115
|
+
* 按龄/LRU 淘汰会毁掉旧稿渲染,必须经 tuning 显式 opt-in)。定时器 unref,
|
|
116
|
+
* 不拖住进程退出;所有关闭路径都要清掉它。 */
|
|
117
|
+
let assetGcTimer = null
|
|
118
|
+
const stopAssetGc = () => { if (assetGcTimer) { clearInterval(assetGcTimer); assetGcTimer = null } }
|
|
114
119
|
const closeCreatedResources = async (why) => {
|
|
120
|
+
stopAssetGc()
|
|
115
121
|
try { if (spec.beforeStop) await spec.beforeStop(ctx) } catch (error) { console.error(`[${spec.id}] ${why}:beforeStop 失败`, error?.message || error) }
|
|
116
122
|
try { if (!givenAssetStore) await assetStore?.close?.() } catch (error) { console.error(`[${spec.id}] ${why}:assetStore 关闭失败`, error?.message || error) }
|
|
117
123
|
try { await store?.close?.() } catch (error) { console.error(`[${spec.id}] ${why}:store 关闭失败`, error?.message || error) }
|
|
@@ -213,6 +219,32 @@ export function createWorkbench(spec) {
|
|
|
213
219
|
}
|
|
214
220
|
}
|
|
215
221
|
|
|
222
|
+
/* 只有真正提供服务的形态才起周期 GC(reused 形态已回收资源,不起定时器)。
|
|
223
|
+
* tuning.assetGcIntervalMs<=0 可整体关闭;maxAgeMs/maxBytes 缺省 0=不按龄/量淘汰。 */
|
|
224
|
+
if (assetStore && typeof assetStore.gc === 'function') {
|
|
225
|
+
const gcIntervalMs = Number(tuning.assetGcIntervalMs ?? 3600000)
|
|
226
|
+
if (gcIntervalMs > 0) {
|
|
227
|
+
const gcOptions = {
|
|
228
|
+
maxAgeMs: Number(tuning.assetGcMaxAgeMs) || 0,
|
|
229
|
+
maxBytes: Number(tuning.assetGcMaxBytes) || 0,
|
|
230
|
+
}
|
|
231
|
+
const runGc = async () => {
|
|
232
|
+
try {
|
|
233
|
+
const result = await assetStore.gc(gcOptions)
|
|
234
|
+
if (result?.removed || result?.orphanTmpRemoved) {
|
|
235
|
+
console.log(`[${spec.id}] 资产 GC:清理 ${result.removed || 0} 项、孤儿临时文件 ${result.orphanTmpRemoved || 0} 个,释放 ${result.freedBytes || 0} 字节`)
|
|
236
|
+
}
|
|
237
|
+
} catch (error) {
|
|
238
|
+
console.error(`[${spec.id}] 资产 GC 失败(下轮再试):`, error?.message || error)
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
assetGcTimer = setInterval(runGc, gcIntervalMs)
|
|
242
|
+
assetGcTimer.unref?.()
|
|
243
|
+
/* 启动即跑一轮:清掉上次进程崩溃留下的孤儿 tmp,不必等第一个周期。 */
|
|
244
|
+
runGc()
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
216
248
|
try {
|
|
217
249
|
/* 业务钩子:设置 URL 环境变量、崩溃恢复等(必须在工具装载之前)。 */
|
|
218
250
|
if (spec.onListening) await spec.onListening(ctx, info, url)
|
|
@@ -255,12 +287,14 @@ export function createWorkbench(spec) {
|
|
|
255
287
|
tools: ctx.toolsRegistry || null,
|
|
256
288
|
...(spec.resultExtras ? spec.resultExtras(ctx) : {}),
|
|
257
289
|
stop: async () => {
|
|
290
|
+
stopAssetGc()
|
|
258
291
|
if (!ctx.embedded) removeDiscovery(hostDir)
|
|
259
292
|
if (spec.beforeStop) await spec.beforeStop(ctx)
|
|
260
293
|
await info.stop()
|
|
261
294
|
},
|
|
262
295
|
}
|
|
263
296
|
} catch (error) {
|
|
297
|
+
stopAssetGc()
|
|
264
298
|
try { if (!ctx.embedded) removeDiscovery(hostDir) } catch { /* 忽略 */ }
|
|
265
299
|
try { if (spec.beforeStop) await spec.beforeStop(ctx) } catch { /* 忽略 */ }
|
|
266
300
|
try { await info.stop() } catch { /* 忽略 */ }
|
|
@@ -45,7 +45,7 @@ cordis insert 唯一一行(`cordis.patch.yml`),config:
|
|
|
45
45
|
controlPort: 0 # >0 时embedded 也开控制端点
|
|
46
46
|
stopOnUnload: false # true=插件卸载时全停(默认服务独立存活)
|
|
47
47
|
skills:
|
|
48
|
-
url: "http://127.0.0.1:<真实端口>" #
|
|
48
|
+
url: "http://127.0.0.1:<真实端口>" # 可选 standalone 模式:ctx.skillsHttp 瘦客户端数据源(默认不启用;技能标准路径是 skillProvider@1 进程内注册,不占用原生 ctx.skills)
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
## 服务规格 spec(与桌面后端 works_services 契约对齐)
|
|
@@ -61,21 +61,36 @@ function tokenMatches(expected, actual) {
|
|
|
61
61
|
|
|
62
62
|
const isLoopback = isLoopbackAddress
|
|
63
63
|
|
|
64
|
-
function jsonBody(req, limit = 8 * 1024 * 1024) {
|
|
64
|
+
function jsonBody(req, res, limit = 8 * 1024 * 1024) {
|
|
65
65
|
return new Promise((resolve, reject) => {
|
|
66
66
|
let size = 0
|
|
67
|
+
let aborted = false
|
|
67
68
|
const chunks = []
|
|
68
69
|
req.on('data', (chunk) => {
|
|
70
|
+
if (aborted) return
|
|
69
71
|
size += chunk.length
|
|
70
|
-
if (size > limit) {
|
|
72
|
+
if (size > limit) {
|
|
73
|
+
/* 先回 413 再处理连接:客户端要能区分「体太大」与「连接被莫名掐断」。
|
|
74
|
+
* 不能立刻 destroy——响应字节还没刷出去就断连,客户端只会看到 ECONNRESET。
|
|
75
|
+
* 这里回完 413 后把剩余请求体排空丢弃(有 8MB 上限兜底,量可控),
|
|
76
|
+
* 让响应干净送达;病态超长上传由服务器级请求超时兜底。 */
|
|
77
|
+
aborted = true
|
|
78
|
+
if (res && !res.headersSent && !res.writableEnded) {
|
|
79
|
+
send(res, 413, { ok: false, error: `请求体超过上限 ${limit} 字节` })
|
|
80
|
+
}
|
|
81
|
+
reject(new Error('body too large'))
|
|
82
|
+
req.resume()
|
|
83
|
+
return
|
|
84
|
+
}
|
|
71
85
|
chunks.push(chunk)
|
|
72
86
|
})
|
|
73
87
|
req.on('end', () => {
|
|
88
|
+
if (aborted) return
|
|
74
89
|
const raw = Buffer.concat(chunks).toString('utf8')
|
|
75
90
|
if (!raw) return resolve({})
|
|
76
91
|
try { resolve(JSON.parse(raw)) } catch { reject(new Error('bad json')) }
|
|
77
92
|
})
|
|
78
|
-
req.on('error', reject)
|
|
93
|
+
req.on('error', (err) => { if (!aborted) reject(err) })
|
|
79
94
|
})
|
|
80
95
|
}
|
|
81
96
|
|
|
@@ -132,13 +147,13 @@ export function createControlServer(engine, options = {}) {
|
|
|
132
147
|
}
|
|
133
148
|
|
|
134
149
|
if (route === 'POST /control/apply') {
|
|
135
|
-
const body = await jsonBody(req)
|
|
150
|
+
const body = await jsonBody(req, res)
|
|
136
151
|
const result = await engine.apply(body.commands || [], { waitMs: body.waitMs })
|
|
137
152
|
return send(res, result.ok ? 200 : 207, result)
|
|
138
153
|
}
|
|
139
154
|
|
|
140
155
|
if (route === 'POST /control/start') {
|
|
141
|
-
const body = await jsonBody(req)
|
|
156
|
+
const body = await jsonBody(req, res)
|
|
142
157
|
let spec = body.service
|
|
143
158
|
if (!spec && body.id && manifestPath && existsSync(manifestPath)) {
|
|
144
159
|
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'))
|
|
@@ -170,7 +185,7 @@ export function createControlServer(engine, options = {}) {
|
|
|
170
185
|
}
|
|
171
186
|
|
|
172
187
|
if (route === 'POST /control/stop') {
|
|
173
|
-
const body = await jsonBody(req)
|
|
188
|
+
const body = await jsonBody(req, res)
|
|
174
189
|
if (!body.id) return send(res, 400, { ok: false, error: '缺 id' })
|
|
175
190
|
return send(res, 200, await engine.stop(body.id))
|
|
176
191
|
}
|
|
@@ -183,7 +198,8 @@ export function createControlServer(engine, options = {}) {
|
|
|
183
198
|
|
|
184
199
|
send(res, 404, { ok: false, error: `未知端点 ${route}` })
|
|
185
200
|
} catch (err) {
|
|
186
|
-
|
|
201
|
+
/* jsonBody 超限时已回过 413 并断连,不能再往已结束的响应上写。 */
|
|
202
|
+
if (!res.headersSent && !res.writableEnded) send(res, 400, { ok: false, error: err.message })
|
|
187
203
|
}
|
|
188
204
|
})
|
|
189
205
|
// 供宿主打日志用:只暴露位置,不暴露 token 本身。
|
|
@@ -186,6 +186,10 @@ export class ServiceEngine {
|
|
|
186
186
|
this._unhealthy = new Map()
|
|
187
187
|
// 深探节流:id → 上次健康/工具探测时间。
|
|
188
188
|
this._lastProbe = new Map()
|
|
189
|
+
// 重启退避:id → 上次自动重启尝试时间(崩溃循环不再每 2s 硬拉一次)。
|
|
190
|
+
this._lastRestart = new Map()
|
|
191
|
+
// error 态恢复:id → { count, lastAt }(冷却指数翻倍,不再永久移出扫描)。
|
|
192
|
+
this._errorRetries = new Map()
|
|
189
193
|
// broker 自身的创建身份在本进程生命周期内不变;Windows 上 marker() 约 900ms,
|
|
190
194
|
// 每次 up 重算会白烧近 1 秒。null 时不缓存(瞬时查询失败可重试)。
|
|
191
195
|
this._brokerMarker = null
|
|
@@ -963,9 +967,10 @@ export class ServiceEngine {
|
|
|
963
967
|
maxUnhealthy = 3,
|
|
964
968
|
requireTools = true,
|
|
965
969
|
probeEveryMs = 15000,
|
|
970
|
+
errorRetryMs = 300000,
|
|
966
971
|
} = {}) {
|
|
967
972
|
if (this._guardTimer) return
|
|
968
|
-
this._guardConfig = { maxConsecutive, maxUnhealthy, requireTools, probeEveryMs }
|
|
973
|
+
this._guardConfig = { maxConsecutive, maxUnhealthy, requireTools, probeEveryMs, errorRetryMs }
|
|
969
974
|
this._guardTimer = setInterval(() => {
|
|
970
975
|
if (this._stopping || this._sweeping) return
|
|
971
976
|
this._sweeping = true
|
|
@@ -1048,6 +1053,13 @@ export class ServiceEngine {
|
|
|
1048
1053
|
cur[row.id] = { ...current, state: 'error', error: message }
|
|
1049
1054
|
await this._saveRegistry(cur)
|
|
1050
1055
|
})
|
|
1056
|
+
/* 冷却从「进入 error 态」起算,而不是从恢复尝试起算:否则 breaker 触发前的
|
|
1057
|
+
* 最后一次重启时间会被当成冷却起点,errorRetryMs 短于崩溃循环时长时,
|
|
1058
|
+
* 行刚变 error 就立刻被重试,冷却形同虚设。仅状态真的翻转时登记。 */
|
|
1059
|
+
const after = (await this._loadRegistry())[row.id]
|
|
1060
|
+
if (after?.state === 'error' && after.pid === row.pid && after.startedAt === row.startedAt) {
|
|
1061
|
+
this._errorRetries.set(row.id, { count: 0, lastAt: Date.now() })
|
|
1062
|
+
}
|
|
1051
1063
|
this.log(`✗ ${row.id} ${message}`)
|
|
1052
1064
|
}
|
|
1053
1065
|
|
|
@@ -1058,7 +1070,7 @@ export class ServiceEngine {
|
|
|
1058
1070
|
* 孤儿行)。只看 _owned 是历史故障的根因:服务被外部杀掉后行还在、_owned 里
|
|
1059
1071
|
* 没有它,于是 2s 一轮的守护永远跳过它,注册表一直写着 running 的假状态。 */
|
|
1060
1072
|
const rows = Object.values(services).filter((row) =>
|
|
1061
|
-
row.keepAlive && row.state === 'running'
|
|
1073
|
+
row.keepAlive && (row.state === 'running' || row.state === 'error')
|
|
1062
1074
|
&& (this._owned.has(row.id) || this._lastSpecs.has(row.id)))
|
|
1063
1075
|
/* 并行探测:一个服务探测慢/超时不能拖住其他服务的巡检。 */
|
|
1064
1076
|
await Promise.all(rows.map((row) => this._sweepOne(row, maxConsecutive).catch(() => {})))
|
|
@@ -1066,8 +1078,12 @@ export class ServiceEngine {
|
|
|
1066
1078
|
}
|
|
1067
1079
|
|
|
1068
1080
|
async _sweepOne(row, maxConsecutive) {
|
|
1081
|
+
/* error 态不是终点:带冷却地重试(见 _recoverError),不再永久移出扫描。 */
|
|
1082
|
+
if (row.state === 'error') return this._recoverError(row)
|
|
1069
1083
|
if (pidAlive(row.pid)) {
|
|
1070
|
-
|
|
1084
|
+
/* 注意:这里**不能**无条件清 _guardFailures——进程只要活过一个巡检间隔
|
|
1085
|
+
* 就把计数清零,「起-死-起」崩溃循环(活得比巡检间隔长)永远打不满熔断,
|
|
1086
|
+
* 变成无限重试。计数只在下方「稳定跑过一分钟」或手动 up 成功时翻篇。 */
|
|
1071
1087
|
/* 分两档节奏:
|
|
1072
1088
|
* - 存活检查每一轮都做(默认 2s 一轮)→ 进程一死,2s 内就重启;
|
|
1073
1089
|
* - 健康/工具深探按 probeEveryMs(默认 15s)做一次,避免频繁打 HTTP。
|
|
@@ -1082,7 +1098,11 @@ export class ServiceEngine {
|
|
|
1082
1098
|
/* "连续"重启次数:稳定跑过一分钟才算翻篇,避免“起-死-起”抖动
|
|
1083
1099
|
* 每次都把计数清零,最后无限重试。 */
|
|
1084
1100
|
const startedAt = Date.parse(row.startedAt || '') || 0
|
|
1085
|
-
if (startedAt && Date.now() - startedAt > 60_000)
|
|
1101
|
+
if (startedAt && Date.now() - startedAt > 60_000) {
|
|
1102
|
+
this._guardFailures.delete(row.id)
|
|
1103
|
+
this._errorRetries.delete(row.id)
|
|
1104
|
+
this._lastRestart.delete(row.id)
|
|
1105
|
+
}
|
|
1086
1106
|
return
|
|
1087
1107
|
}
|
|
1088
1108
|
const count = (this._unhealthy.get(row.id) || 0) + 1
|
|
@@ -1137,10 +1157,18 @@ export class ServiceEngine {
|
|
|
1137
1157
|
const failures = this._guardFailures.get(row.id) || 0
|
|
1138
1158
|
const spec = this._lastSpecs.get(row.id)
|
|
1139
1159
|
if (!spec) { await this._markError(row, '缺少重启规格,拒绝自动重启'); return }
|
|
1140
|
-
if (failures >= maxConsecutive) { await this._markError(row, '
|
|
1141
|
-
|
|
1160
|
+
if (failures >= maxConsecutive) { await this._markError(row, '连续重启次数超限,进入冷却(稍后自动重试)'); return }
|
|
1161
|
+
/* 重启退避:崩溃循环不能每 2s 硬拉一次,间隔随失败次数翻倍(2s→4s→8s…上限 60s)。 */
|
|
1162
|
+
const backoff = Math.min(2000 * 2 ** failures, 60_000)
|
|
1163
|
+
const lastRestart = this._lastRestart.get(row.id) || 0
|
|
1164
|
+
if (Date.now() - lastRestart < backoff) return
|
|
1165
|
+
this._lastRestart.set(row.id, Date.now())
|
|
1142
1166
|
try {
|
|
1143
1167
|
await this._upOnce(spec, {})
|
|
1168
|
+
/* 计数必须在重启**成功后**累加:_upOnce 的健康拉起路径会清 _guardFailures
|
|
1169
|
+
* (手动 up 语义=翻篇),守护重启若先加后清,崩溃循环永远打不满熔断。
|
|
1170
|
+
* 只有「稳定跑过 60s」或手动 up 才真正翻篇(见 _sweepOne)。 */
|
|
1171
|
+
this._guardFailures.set(row.id, failures + 1)
|
|
1144
1172
|
this.log(`↻ ${row.id} 已自动重启`)
|
|
1145
1173
|
} catch (err) {
|
|
1146
1174
|
await this._markError(row, `自动重启失败: ${err.message}`)
|
|
@@ -1148,6 +1176,32 @@ export class ServiceEngine {
|
|
|
1148
1176
|
})
|
|
1149
1177
|
}
|
|
1150
1178
|
|
|
1179
|
+
/** error 态恢复:冷却指数翻倍(默认 5min→10min→20min…上限 30min)后按规格重试。
|
|
1180
|
+
* _upOnce 自带仲裁——端口上已有健康实例就复用,不会双开;成功即回到 running,
|
|
1181
|
+
* 稳定跑过 60s 后冷却计数清零(见 _sweepOne)。没有重启规格的行无法自愈,留给手动 up。 */
|
|
1182
|
+
async _recoverError(row) {
|
|
1183
|
+
const cfg = this._guardConfig || {}
|
|
1184
|
+
const base = cfg.errorRetryMs ?? 300_000
|
|
1185
|
+
const retry = this._errorRetries.get(row.id) || { count: 0, lastAt: 0 }
|
|
1186
|
+
const cooldown = Math.min(base * 2 ** retry.count, 1_800_000)
|
|
1187
|
+
if (Date.now() - retry.lastAt < cooldown) return
|
|
1188
|
+
const spec = this._lastSpecs.get(row.id)
|
|
1189
|
+
if (!spec) return
|
|
1190
|
+
await this._withServiceLock(row.id, async () => {
|
|
1191
|
+
if (this._stopping) return
|
|
1192
|
+
this._errorRetries.set(row.id, { count: retry.count + 1, lastAt: Date.now() })
|
|
1193
|
+
/* error 恢复是新一轮:不背旧的连续重启计数。 */
|
|
1194
|
+
this._guardFailures.delete(row.id)
|
|
1195
|
+
this._unhealthy.delete(row.id)
|
|
1196
|
+
try {
|
|
1197
|
+
await this._upOnce(spec, {})
|
|
1198
|
+
this.log(`↻ ${row.id} 已从 error 态恢复(第 ${retry.count + 1} 次尝试)`)
|
|
1199
|
+
} catch (err) {
|
|
1200
|
+
this.log(`… ${row.id} error 恢复失败(第 ${retry.count + 1} 次尝试):${err.message},冷却后再试`)
|
|
1201
|
+
}
|
|
1202
|
+
})
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1151
1205
|
/** 与服务级启动锁串行,避免与并发的 up/stop 交叉执行。 */
|
|
1152
1206
|
_withServiceLock(id, fn) {
|
|
1153
1207
|
const prev = this._upLocks.get(id) || Promise.resolve()
|
|
@@ -5,8 +5,11 @@
|
|
|
5
5
|
* 只做三件事:
|
|
6
6
|
* 1. 按清单(config.manifest 指向 services.json)把各服务作为独立进程拉起;
|
|
7
7
|
* 2. 向同进程提供 ctx.serviceBroker(list/start/stop/apply 控制面);
|
|
8
|
-
* 3. 可选:config.skills.url 指向技能服务时,提供 ctx.
|
|
9
|
-
* (数据来自 HTTP
|
|
8
|
+
* 3. 可选:config.skills.url 指向技能服务时,提供 ctx.skillsHttp 瘦客户端
|
|
9
|
+
* (数据来自 HTTP)。技能的标准路径是 skillProvider@1 进程内注册 →
|
|
10
|
+
* DSH 原生 SkillRegistry(ctx.skills);此 HTTP 路是 standalone 可选模式,
|
|
11
|
+
* 默认不启用。服务名用 skillsHttp 而非 skills,避免遮蔽原生注册表
|
|
12
|
+
* (详见 lib/skills-client.mjs 头注释,P1-10 决策)。
|
|
10
13
|
*
|
|
11
14
|
* 生命周期:keepAlive 服务(默认)不随插件卸载停止——服务独立于 dsh;
|
|
12
15
|
* config.stopOnUnload === true 时才随卸载全停。
|
|
@@ -40,13 +43,15 @@ export const { name, inject, apply } = defineDriver({
|
|
|
40
43
|
}
|
|
41
44
|
const disposeService = ctx.provide('serviceBroker', api)
|
|
42
45
|
|
|
43
|
-
//
|
|
44
|
-
//
|
|
46
|
+
// 技能瘦客户端(可选 standalone 模式,默认不启用):list/get 形状与进程内
|
|
47
|
+
// 注册表一致,数据源改为 HTTP 技能服务。服务名 skillsHttp——'skills' 归 DSH
|
|
48
|
+
// 原生 SkillRegistry,provide('skills') 会遮蔽它并令 skillProvider@1 插件
|
|
49
|
+
// 因缺 registerProvider 挂载失败(P1-10 决策,见 lib/skills-client.mjs)。
|
|
45
50
|
let disposeSkills = null
|
|
46
51
|
if (config.skills?.url) {
|
|
47
52
|
const client = createSkillsClient(config.skills.url)
|
|
48
|
-
disposeSkills = ctx.provide('
|
|
49
|
-
console.log(`[service-broker]
|
|
53
|
+
disposeSkills = ctx.provide('skillsHttp', client)
|
|
54
|
+
console.log(`[service-broker] skillsHttp ← ${config.skills.url}`)
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
// 开机清单:有清单就按 up 命令投递给自己(幂等,复用优先)
|