bailinghub 0.9.4 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +6 -6
- package/README.md +6 -6
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/docker-compose.images.yml +2 -2
- package/docs/AGENT_CLIENT_QUICKSTART.en.md +1 -3
- package/docs/AGENT_CLIENT_QUICKSTART.md +1 -1
- package/docs/AGENT_CLIENT_RUNTIME_API.en.md +87 -2
- package/docs/AGENT_CLIENT_RUNTIME_API.md +36 -2
- package/docs/AGENT_KNOWLEDGE_API.en.md +77 -0
- package/docs/AGENT_KNOWLEDGE_API.md +86 -0
- package/docs/AGENT_TASK_CONTROL.md +4 -4
- package/docs/AGENT_TASK_CONTROL_FOUNDATION.md +1 -1
- package/docs/ARCHITECTURE.md +4 -0
- package/docs/CHANGELOG.en.md +12 -0
- package/docs/CHANGELOG.md +12 -0
- package/docs/COMPATIBILITY.en.md +27 -1
- package/docs/CONTRACT.en.md +1 -1
- package/docs/CONTRACT.md +1 -1
- package/docs/IMPLEMENTATION_STATUS.en.md +19 -15
- package/docs/IMPLEMENTATION_STATUS.md +19 -15
- package/docs/INDEPENDENT_VALIDATION.en.md +6 -4
- package/docs/INDEPENDENT_VALIDATION.md +6 -4
- package/docs/INTEGRATION_WALKTHROUGH.md +65 -0
- package/docs/MODEL_BILLING.en.md +2 -0
- package/docs/MODEL_BILLING.md +6 -2
- package/docs/MODEL_CONTINUATION.en.md +54 -0
- package/docs/MODEL_CONTINUATION.md +54 -0
- package/docs/MODEL_OUTPUT_BUDGET.en.md +69 -0
- package/docs/MODEL_OUTPUT_BUDGET.md +69 -0
- package/docs/OPERATIONS.en.md +16 -4
- package/docs/OPERATIONS.md +16 -4
- package/docs/QUICKSTART.md +1 -1
- package/docs/README.en.md +5 -0
- package/docs/README.md +5 -0
- package/docs/RELEASE_NOTES_NEXT.en.md +3 -3
- package/docs/RELEASE_NOTES_NEXT.md +3 -3
- package/docs/RELEASE_NOTES_v0.10.0.en.md +58 -0
- package/docs/RELEASE_NOTES_v0.10.0.md +58 -0
- package/docs/UPGRADE_PLAN.en.md +118 -0
- package/docs/UPGRADE_PLAN.md +124 -0
- package/docs/UPGRADE_v0.10.0.en.md +47 -0
- package/docs/UPGRADE_v0.10.0.md +47 -0
- package/docs//345/205/274/345/256/271/346/200/247/344/270/216/345/215/207/347/272/247.md +38 -22
- package/package.json +8 -5
- package/schemas/tool-definition.schema.json +13 -0
- package/scripts/check-doc-links.mjs +4 -0
- package/scripts/check-image-tags.sh +1 -1
- package/scripts/check-release-consistency.test.mjs +2 -2
- package/scripts/doctor-upgrade-plan.test.ts +205 -0
- package/scripts/doctor-upgrade-plan.ts +276 -0
- package/scripts/doctor.ts +4 -1
- package/scripts/e2e-console-approval-details.mjs +134 -0
- package/scripts/e2e-console-config-races.mjs +180 -0
- package/scripts/e2e-console-kb-audit.mjs +170 -0
- package/scripts/e2e-console-operations-audit.mjs +152 -0
- package/scripts/e2e-console-runtime-audit.mjs +179 -0
- package/scripts/e2e-console-settings-audit.mjs +125 -0
- package/scripts/e2e-console-troubleshooting-extra.mjs +267 -0
- package/scripts/e2e-console.mjs +476 -7
- package/scripts/install.sh +1 -1
- package/scripts/publish-images.sh +1 -1
- package/scripts/release-audit.mjs +4 -0
- package/scripts/verify-github-repo.mjs +4 -0
- package/src/app/agent-client-runtime.test.ts +115 -2
- package/src/app/agent-client-runtime.ts +40 -11
- package/src/app/agent-knowledge.test.ts +171 -0
- package/src/app/agent-knowledge.ts +233 -0
- package/src/app/agent-tool-catalog-revision.test.ts +31 -0
- package/src/app/agent-tool-invocations.test.ts +7 -2
- package/src/app/agent-tool-invocations.ts +67 -7
- package/src/app/approval-continuations.test.ts +49 -1
- package/src/app/http.test.ts +16 -1
- package/src/app/http.ts +3 -3
- package/src/app/kernel-boot-recovery.mysql.test.ts +132 -0
- package/src/app/kernel-boot-recovery.test.ts +157 -0
- package/src/app/kernel.ts +12 -8
- package/src/app/readiness.mysql.test.ts +120 -0
- package/src/app/readiness.test.ts +111 -26
- package/src/app/readiness.ts +26 -22
- package/src/app/runtime-lifecycle.ts +34 -3
- package/src/app/tool-approvals.test.ts +83 -0
- package/src/app/tool-approvals.ts +25 -7
- package/src/app/tool-proxy-payload.test.ts +81 -0
- package/src/app/tool-proxy.ts +24 -2
- package/src/core/config/console-diagnostic-location.test.ts +36 -0
- package/src/core/config/console-form-guard.test.ts +69 -0
- package/src/core/config/console-task-location.test.ts +64 -0
- package/src/core/contracts/openapi-tools.ts +16 -5
- package/src/core/contracts/schema-readiness.ts +11 -0
- package/src/core/contracts/tool-definition.ts +26 -0
- package/src/core/contracts/tool-guidance.test.ts +77 -0
- package/src/core/contracts/tool-guidance.ts +31 -0
- package/src/core/contracts/tool-input-limits.ts +15 -0
- package/src/core/contracts/tools-idempotency.test.ts +90 -0
- package/src/core/contracts/tools.ts +52 -9
- package/src/core/runtime/agent-execution-memory.test.ts +64 -0
- package/src/core/runtime/agent-execution-memory.ts +63 -0
- package/src/core/state/state-contracts.ts +3 -0
- package/src/infrastructure/config/config-observability-ledger.ts +2 -0
- package/src/infrastructure/schema/schema-readiness.ts +29 -0
- package/src/infrastructure/state/state-mysql.ts +3 -0
- package/src/modules/usage/contracts.ts +7 -0
- package/src/modules/usage/http.ts +2 -0
- package/src/modules/usage/model-continuation.test.ts +109 -0
- package/src/modules/usage/model-gateway.ts +5 -1
- package/src/modules/usage/output-budget.mysql.test.ts +84 -0
- package/src/modules/usage/output-budget.test.ts +167 -0
- package/src/modules/usage/output-budget.ts +73 -0
- package/src/modules/usage/provider-stream.test.ts +22 -0
- package/src/modules/usage/provider.ts +2 -3
- package/src/modules/usage/repository.ts +6 -0
- package/src/modules/usage/test-harness.ts +4 -2
- package/src/routes/admin-approval-view.test.ts +109 -0
- package/src/routes/admin-approval-view.ts +36 -0
- package/src/routes/admin-readiness.test.ts +52 -0
- package/src/routes/admin-runtime-ux.test.ts +51 -0
- package/src/routes/admin-runtime-ux.ts +25 -0
- package/src/routes/admin-runtime.ts +36 -8
- package/src/routes/admin.ts +9 -0
- package/src/routes/agent-api.test.ts +80 -1
- package/src/routes/agent-api.ts +63 -4
- package/src/routes/agent-tool-detail.test.ts +140 -0
- package/src/routes/public-default.ts +1 -1
- package/src/services/kb-agent.test.ts +84 -0
- package/src/services/kb.ts +73 -0
- package/web/console/assets/Accounts-CjIBO3sU.css +1 -0
- package/web/console/assets/Accounts-Dhyw-7wF.js +3 -0
- package/web/console/assets/AgentClients-BA0M26-I.css +1 -0
- package/web/console/assets/AgentClients-DWxb8-ko.js +1 -0
- package/web/console/assets/AgentTasks-DOyxANnx.css +1 -0
- package/web/console/assets/AgentTasks-DUHD4dzr.js +2 -0
- package/web/console/assets/Approvals-Brl-2uJq.css +1 -0
- package/web/console/assets/Approvals-CQx1YWxW.js +1 -0
- package/web/console/assets/Audit--QcdVlMh.js +1 -0
- package/web/console/assets/Audit-DAdmOnIs.css +1 -0
- package/web/console/assets/{BrandLockup-CffORQse.js → BrandLockup-DQcaW4Nt.js} +1 -1
- package/web/console/assets/Channels-DJJU3ksE.css +1 -0
- package/web/console/assets/Channels-cGS5WfQ-.js +105 -0
- package/web/console/assets/ChatEntries-BYpji27B.css +1 -0
- package/web/console/assets/ChatEntries-nh23Iz5O.js +7 -0
- package/web/console/assets/Clients-CX5EeYio.js +3 -0
- package/web/console/assets/Clients-CbZAou8E.css +1 -0
- package/web/console/assets/Cost-C6oQvz9P.css +1 -0
- package/web/console/assets/Cost-DOZfdNS9.js +1 -0
- package/web/console/assets/Credentials--aHs57yV.css +1 -0
- package/web/console/assets/Credentials-sy6W9Sac.js +1 -0
- package/web/console/assets/Diagnostics-CKs27Dnv.css +1 -0
- package/web/console/assets/Diagnostics-CyoM1XrZ.js +1 -0
- package/web/console/assets/Executors-2Upi6bOS.css +1 -0
- package/web/console/assets/Executors-BQqqiFwt.js +1 -0
- package/web/console/assets/HelpTip-DLlhaGQp.js +1 -0
- package/web/console/assets/HelpTip-bbDEyuqV.css +1 -0
- package/web/console/assets/Kb-5R3ce4UU.js +5 -0
- package/web/console/assets/Kb-BM_PYi11.css +1 -0
- package/web/console/assets/{Login-CGgLGTE1.js → Login-YKeUwdgo.js} +1 -1
- package/web/console/assets/Projects-DHwHrPT9.css +1 -0
- package/web/console/assets/Projects-Grgb6fOv.js +1 -0
- package/web/console/assets/Routes-DR_Yf02e.css +1 -0
- package/web/console/assets/Routes-DYgrXlRJ.js +138 -0
- package/web/console/assets/Runs-CwTddJJj.js +3 -0
- package/web/console/assets/Runs-D4FOvNfu.css +1 -0
- package/web/console/assets/Setup-Ca0b1d1-.css +1 -0
- package/web/console/assets/Setup-D_xUPNDq.js +1 -0
- package/web/console/assets/Shell-BTg8Vw_L.css +1 -0
- package/web/console/assets/Shell-Dfam2Uoj.js +1 -0
- package/web/console/assets/StorageBuckets-7QLBpV4a.css +1 -0
- package/web/console/assets/StorageBuckets-CP6e50wI.js +1 -0
- package/web/console/assets/SystemSettings-BRYKyJNa.js +1 -0
- package/web/console/assets/SystemSettings-HsXGx0aH.css +1 -0
- package/web/console/assets/SystemStatus-B-VfRsQd.css +1 -0
- package/web/console/assets/SystemStatus-CbPsDsGt.js +1 -0
- package/web/console/assets/Targets-1j4-g6rC.css +1 -0
- package/web/console/assets/Targets-C2LkR2AF.js +1 -0
- package/web/console/assets/Tools-C9HPJqJb.css +1 -0
- package/web/console/assets/Tools-C9JNJUS0.js +2 -0
- package/web/console/assets/Usage-D1Mv6vGY.js +1 -0
- package/web/console/assets/Usage-DMOzUsqh.css +1 -0
- package/web/console/assets/UsageAccess-77LmGCm6.js +1 -0
- package/web/console/assets/UsageAccess-C6ZGxEgJ.css +1 -0
- package/web/console/assets/{UsageHelp-CzS2gI40.js → UsageHelp-BmuiE1Ew.js} +1 -1
- package/web/console/assets/client-route-draft-DxZRxKPT.js +1 -0
- package/web/console/assets/console-location-Csv-xsnl.js +1 -0
- package/web/console/assets/form-guard-8GrFpry0.js +1 -0
- package/web/console/assets/{index-65JiiUr4.js → index-B_5UfiTw.js} +1 -1
- package/web/console/assets/index-MjZJEFIN.js +2 -0
- package/web/console/assets/{request-DKycpD7z.js → request-rqm6MT0s.js} +1 -1
- package/web/console/assets/runtime-feedback-gPfZVNvY.js +1 -0
- package/web/console/assets/{schema-SCiNxBlR.js → schema-o3mK4mid.js} +1 -1
- package/web/console/assets/task-page-location-DWiGtAln.js +1 -0
- package/web/console/assets/use-list-location-FvLFt0Tq.css +1 -0
- package/web/console/assets/use-list-location-cIPy2cKM.js +1 -0
- package/web/console/assets/use-unsaved-form-DScKD0h9.js +1 -0
- package/web/console/assets/{util-DZYfJ5Zo.js → util-B40VqOwl.js} +1 -1
- package/web/console/assets/{vendor-element-8cVcdt5T.js → vendor-element-BT8tHCFk.js} +1 -1
- package/web/console/assets/{vendor-mammoth-CnDA23N0.js → vendor-mammoth-CVIXVxTN.js} +1 -1
- package/web/console/assets/{vendor-vue-Co7x2FW6.js → vendor-vue-DhbG0vd4.js} +7 -7
- package/web/console/index.html +3 -3
- package/web-admin/package-lock.json +4 -4
- package/web-admin/package.json +1 -1
- package/web-admin/src/client-route-draft.ts +25 -0
- package/web-admin/src/components/AgentSetupPanel.vue +54 -41
- package/web-admin/src/components/HelpTip.vue +4 -1
- package/web-admin/src/components/ListLocationBar.vue +22 -0
- package/web-admin/src/components/NotificationOutboxPanel.vue +35 -7
- package/web-admin/src/console-entry.test.ts +26 -0
- package/web-admin/src/console-entry.ts +20 -0
- package/web-admin/src/console-location.ts +35 -0
- package/web-admin/src/form-guard.ts +35 -0
- package/web-admin/src/layout/Shell.vue +18 -65
- package/web-admin/src/onboarding-state.test.ts +174 -0
- package/web-admin/src/onboarding-state.ts +122 -0
- package/web-admin/src/pages/Accounts.vue +44 -24
- package/web-admin/src/pages/AgentClients.vue +47 -29
- package/web-admin/src/pages/AgentTasks.vue +57 -12
- package/web-admin/src/pages/Approvals.vue +105 -25
- package/web-admin/src/pages/Audit.vue +15 -6
- package/web-admin/src/pages/Channels.vue +136 -43
- package/web-admin/src/pages/ChatEntries.vue +96 -41
- package/web-admin/src/pages/Clients.vue +87 -26
- package/web-admin/src/pages/Cost.vue +15 -4
- package/web-admin/src/pages/Credentials.vue +63 -32
- package/web-admin/src/pages/Diagnostics.vue +103 -54
- package/web-admin/src/pages/Executors.vue +103 -40
- package/web-admin/src/pages/Kb.vue +278 -128
- package/web-admin/src/pages/Projects.vue +44 -16
- package/web-admin/src/pages/Routes.vue +168 -247
- package/web-admin/src/pages/Runs.vue +163 -91
- package/web-admin/src/pages/Setup.vue +182 -291
- package/web-admin/src/pages/StorageBuckets.vue +61 -25
- package/web-admin/src/pages/SystemSettings.vue +76 -51
- package/web-admin/src/pages/SystemStatus.vue +54 -30
- package/web-admin/src/pages/Targets.vue +45 -17
- package/web-admin/src/pages/Tools.vue +133 -68
- package/web-admin/src/pages/Usage.vue +64 -25
- package/web-admin/src/pages/UsageAccess.vue +11 -8
- package/web-admin/src/route-call-snippets.test.ts +82 -0
- package/web-admin/src/route-call-snippets.ts +178 -0
- package/web-admin/src/router.ts +11 -29
- package/web-admin/src/runtime-feedback.ts +43 -0
- package/web-admin/src/task-page-location.ts +66 -0
- package/web-admin/src/usage-output-budget.test.ts +26 -0
- package/web-admin/src/usage-output-budget.ts +46 -0
- package/web-admin/src/use-list-location.ts +24 -0
- package/web-admin/src/use-unsaved-form.ts +38 -0
- package/web-admin/tests/model-output-budget.browser.mjs +69 -0
- package/web/console/assets/Accounts-Bervi5JU.css +0 -1
- package/web/console/assets/Accounts-Dhj6PjXP.js +0 -3
- package/web/console/assets/AgentClients-CMy8StAH.js +0 -1
- package/web/console/assets/AgentClients-i52AI6YV.css +0 -1
- package/web/console/assets/AgentTasks-BsG850Il.css +0 -1
- package/web/console/assets/AgentTasks-DA1xZdmP.js +0 -2
- package/web/console/assets/Approvals-DIsd7R8N.js +0 -1
- package/web/console/assets/Approvals-DlTSHl_7.css +0 -1
- package/web/console/assets/Audit-AUDABLTX.js +0 -1
- package/web/console/assets/Audit-CSu6_3oD.css +0 -1
- package/web/console/assets/Channels-B8rjsM0S.js +0 -105
- package/web/console/assets/Channels-CCn0L1jg.css +0 -1
- package/web/console/assets/ChatEntries-DsYtcXN6.css +0 -1
- package/web/console/assets/ChatEntries-iZjJMEUZ.js +0 -7
- package/web/console/assets/Clients-CSHIsaWU.css +0 -1
- package/web/console/assets/Clients-CwgpGCSD.js +0 -3
- package/web/console/assets/Cost-B2tNxu71.js +0 -1
- package/web/console/assets/Cost-CjT39DSZ.css +0 -1
- package/web/console/assets/Credentials-BuwFB-fV.js +0 -1
- package/web/console/assets/Credentials-ioLP0qYN.css +0 -1
- package/web/console/assets/Diagnostics-Ya05PTDp.css +0 -1
- package/web/console/assets/Diagnostics-z5glms11.js +0 -1
- package/web/console/assets/Executors-Bc4SvjeH.js +0 -1
- package/web/console/assets/Executors-CjhEM54c.css +0 -1
- package/web/console/assets/HelpTip-CA6Bm7Nx.css +0 -1
- package/web/console/assets/HelpTip-Dtdt2tKR.js +0 -1
- package/web/console/assets/Kb-BRbRHxLy.js +0 -5
- package/web/console/assets/Kb-CzIzd9xr.css +0 -1
- package/web/console/assets/Projects-Bm8AjsNx.css +0 -1
- package/web/console/assets/Projects-CPWw3con.js +0 -1
- package/web/console/assets/Routes-CMIaE0Bx.js +0 -124
- package/web/console/assets/Routes-CyXV4Pba.css +0 -1
- package/web/console/assets/Runs-B8HuE700.js +0 -3
- package/web/console/assets/Runs-Bv6CV_Hk.css +0 -1
- package/web/console/assets/Setup-D7nxgn-9.css +0 -1
- package/web/console/assets/Setup-G8RKzliR.js +0 -1
- package/web/console/assets/Shell-DimHgraJ.js +0 -1
- package/web/console/assets/Shell-ykb-tUfo.css +0 -1
- package/web/console/assets/StorageBuckets-CVgpZRWY.css +0 -1
- package/web/console/assets/StorageBuckets-CiVYXIE2.js +0 -1
- package/web/console/assets/SystemSettings-BjiHyrXO.css +0 -1
- package/web/console/assets/SystemSettings-DF8sZNen.js +0 -1
- package/web/console/assets/SystemStatus-BlHywK13.js +0 -1
- package/web/console/assets/SystemStatus-I11I67rw.css +0 -1
- package/web/console/assets/Targets-BXaoPoAJ.js +0 -1
- package/web/console/assets/Targets-DTb5tn6z.css +0 -1
- package/web/console/assets/Tools-B22lNHXq.js +0 -2
- package/web/console/assets/Tools-DU8ei6sd.css +0 -1
- package/web/console/assets/Usage-C02EzoI2.js +0 -1
- package/web/console/assets/Usage-CAeDGjrb.css +0 -1
- package/web/console/assets/UsageAccess-CGGaWTuj.css +0 -1
- package/web/console/assets/UsageAccess-DOb-cyPE.js +0 -1
- package/web/console/assets/index-CK0ZCTZv.js +0 -2
package/src/app/readiness.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { AppConfig } from '../core/config/config';
|
|
2
|
-
import { sqlMigrationFiles } from '../core/platform/version';
|
|
3
2
|
import type { ConfigStoreContract } from '../infrastructure/config/configstore';
|
|
3
|
+
import type { RuntimeStateStore } from '../core/state/state-contracts';
|
|
4
|
+
import type { SchemaReadinessDatabase } from '../core/contracts/schema-readiness';
|
|
5
|
+
import { inspectCoreSchemaReadiness } from '../infrastructure/schema/schema-readiness';
|
|
4
6
|
|
|
5
7
|
export interface ReadinessReport {
|
|
6
8
|
ready: boolean;
|
|
@@ -11,29 +13,31 @@ export interface ReadinessReport {
|
|
|
11
13
|
};
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (cfg.state.backend !== 'mysql') {
|
|
19
|
-
return { ready: true, checks: { state_backend: 'ok', database: 'skipped', migrations: { status: 'skipped', pending: 0 } } };
|
|
20
|
-
}
|
|
21
|
-
if (!configStore) {
|
|
22
|
-
return { ready: false, checks: { state_backend: 'ok', database: 'failed', migrations: { status: 'failed', pending: 0 } } };
|
|
23
|
-
}
|
|
16
|
+
/** Shared storage only: external model, tool and channel failures belong to business diagnostics. */
|
|
17
|
+
export async function checkReadinessFor(
|
|
18
|
+
cfg: AppConfig, configStore: ConfigStoreContract | null, stateStore?: Pick<RuntimeStateStore, 'schemaReadinessDb'>,
|
|
19
|
+
): Promise<ReadinessReport> {
|
|
24
20
|
try {
|
|
25
|
-
|
|
21
|
+
// A custom MySQL state store must expose its actual resource. Guessing from
|
|
22
|
+
// config or checking only the configuration DB can admit a broken instance.
|
|
23
|
+
if (cfg.state.backend === 'mysql' && (!configStore || !stateStore?.schemaReadinessDb)) {
|
|
24
|
+
return { ready: false, checks: { state_backend: 'ok', database: 'failed', migrations: { status: 'failed', pending: 0 } } };
|
|
25
|
+
}
|
|
26
|
+
const resources = new Set<SchemaReadinessDatabase>();
|
|
27
|
+
if (stateStore?.schemaReadinessDb) resources.add(stateStore.schemaReadinessDb);
|
|
28
|
+
if (configStore) resources.add(configStore.db);
|
|
29
|
+
if (!resources.size) {
|
|
30
|
+
return { ready: true, checks: { state_backend: 'ok', database: 'skipped', migrations: { status: 'skipped', pending: 0 } } };
|
|
31
|
+
}
|
|
32
|
+
const checks = await Promise.all([...resources].map(inspectCoreSchemaReadiness));
|
|
33
|
+
const database = checks.some(check => check.database === 'failed') ? 'failed' : 'ok';
|
|
34
|
+
// Count distinct missing migration files, even when separate pool objects
|
|
35
|
+
// refer to one schema. Never merge resources by guessed connection settings.
|
|
36
|
+
const pending = new Set(checks.flatMap(check => check.pendingFilenames)).size;
|
|
37
|
+
const status = checks.some(check => check.migrations.status === 'failed') ? 'failed' : pending ? 'pending' : 'ok';
|
|
38
|
+
return { ready: database === 'ok' && status === 'ok', checks: { state_backend: 'ok', database, migrations: { status, pending } } };
|
|
26
39
|
} catch {
|
|
40
|
+
// Getter/adapter errors must not disclose connection strings or SQL details.
|
|
27
41
|
return { ready: false, checks: { state_backend: 'ok', database: 'failed', migrations: { status: 'failed', pending: 0 } } };
|
|
28
42
|
}
|
|
29
|
-
try {
|
|
30
|
-
const applied = new Set(await configStore.observability.listSchemaMigrations());
|
|
31
|
-
const pending = sqlMigrationFiles(cfg.root).filter((file) => !applied.has(file));
|
|
32
|
-
return {
|
|
33
|
-
ready: pending.length === 0,
|
|
34
|
-
checks: { state_backend: 'ok', database: 'ok', migrations: { status: pending.length ? 'pending' : 'ok', pending: pending.length } },
|
|
35
|
-
};
|
|
36
|
-
} catch {
|
|
37
|
-
return { ready: false, checks: { state_backend: 'ok', database: 'ok', migrations: { status: 'failed', pending: 0 } } };
|
|
38
|
-
}
|
|
39
43
|
}
|
|
@@ -478,12 +478,43 @@ export function startRuntimeSchedulersFor(deps: RuntimeLifecycleDeps): RuntimeSc
|
|
|
478
478
|
};
|
|
479
479
|
}
|
|
480
480
|
|
|
481
|
-
export
|
|
481
|
+
export interface RuntimeBootRecovery {
|
|
482
|
+
readonly timer: ReturnType<typeof setTimeout>;
|
|
483
|
+
stop(): void;
|
|
484
|
+
/** A fired timer still owns its recovery query, audits and requeues until settled. */
|
|
485
|
+
drain(drainMs?: number): Promise<boolean>;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
export function startBootRecoveryFor(deps: RuntimeLifecycleDeps): RuntimeBootRecovery {
|
|
482
489
|
const actions = runtimeMaintenanceActionsFor(deps);
|
|
490
|
+
let stopped = false;
|
|
491
|
+
let work: Promise<void> | null = null;
|
|
483
492
|
// 崩溃恢复:boot 时把上一进程遗留的 inhub running 任务放回 DB 队列;queued 任务由 inhub 调度器继续认领。
|
|
484
493
|
// 延后到 listen 之后再跑(不阻塞开始收流量,也避开冷启动抢资源)。
|
|
485
494
|
const timer = setTimeout(() => {
|
|
486
|
-
|
|
495
|
+
if (stopped) return;
|
|
496
|
+
// Own the entire action, including engine target refresh before recoverJobs.
|
|
497
|
+
// Clearing a fired timer alone cannot prevent its later database writes.
|
|
498
|
+
work = Promise.resolve().then(actions.recoverBoot);
|
|
487
499
|
}, 2000).unref();
|
|
488
|
-
return
|
|
500
|
+
return {
|
|
501
|
+
timer,
|
|
502
|
+
stop() { stopped = true; clearTimeout(timer); },
|
|
503
|
+
async drain(drainMs = 30_000) {
|
|
504
|
+
if (!work) return true;
|
|
505
|
+
const bounded = Number.isFinite(drainMs) ? Math.max(0, Math.floor(drainMs)) : 0;
|
|
506
|
+
let timeout: ReturnType<typeof setTimeout> | undefined;
|
|
507
|
+
try {
|
|
508
|
+
return await Promise.race([
|
|
509
|
+
work.then(() => true),
|
|
510
|
+
new Promise<boolean>(resolve => { timeout = setTimeout(() => resolve(false), bounded); }),
|
|
511
|
+
]);
|
|
512
|
+
} finally { if (timeout) clearTimeout(timeout); }
|
|
513
|
+
},
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/** Preserve the timer-only extension helper; Kernel owns the drainable handle. */
|
|
518
|
+
export function scheduleBootRecoveryFor(deps: RuntimeLifecycleDeps): ReturnType<typeof setTimeout> {
|
|
519
|
+
return startBootRecoveryFor(deps).timer;
|
|
489
520
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import type { Job } from '../core/contracts/types';
|
|
4
|
+
import type { AppConfig } from '../core/config/config';
|
|
5
|
+
import type { ConfigStoreContract } from '../infrastructure/config/configstore';
|
|
6
|
+
import type { RuntimeStateStore } from '../core/state/state-contracts';
|
|
7
|
+
import type { ApprovalIntentSnap } from '../core/contracts/tools';
|
|
8
|
+
import { argsHash, approvalNotificationSnapshot } from '../core/contracts/tools';
|
|
9
|
+
import { approvalDepsForStores, approvedNoteForJobFor, notifyApprovalPayloadFor } from './tool-approvals';
|
|
10
|
+
import { defaultTargetRegistry } from '../core/targets/registry';
|
|
11
|
+
|
|
12
|
+
const now = () => new Date().toISOString();
|
|
13
|
+
const cfg = { server: { token: 'synthetic-only' }, brand: { name: 'Synthetic' }, alerts: null } as AppConfig;
|
|
14
|
+
const state = { appendAudit: async () => {} } as unknown as RuntimeStateStore;
|
|
15
|
+
const job = (): Job => ({ job_id: 'synthetic-job', request_id: 'synthetic-request', status: 'running', source: 'test',
|
|
16
|
+
profile: 'test', project: '', input_preview: '', created_at: now(), updated_at: now(),
|
|
17
|
+
metadata: { subject: 'synthetic-user', agent_frozen_arguments: 'private-encrypted-recovery-marker' } });
|
|
18
|
+
function snapshot(large = true): ApprovalIntentSnap {
|
|
19
|
+
const args = { source: { html: large ? `中😀"\\${'x'.repeat(200_000)}DO_NOT_COPY_FULL_DESIGN_END` : 'small', css: '' } };
|
|
20
|
+
return { tool: 'synthetic_save', scope: 'synthetic.write', risk: 'high', policy: 'always', reason: 'synthetic',
|
|
21
|
+
method: 'POST', path: '/synthetic', args_json: JSON.stringify(args), args_hash: argsHash(args) };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
test('atomic approval retains full execution arguments but persists only a bounded notification projection', async () => {
|
|
25
|
+
const original = job(), snap = snapshot(); let saved: any, draft: any;
|
|
26
|
+
const config = { approvals: { createWithNotification: async (approval: unknown, notification: unknown) => {
|
|
27
|
+
saved = structuredClone(approval); draft = structuredClone(notification); return 7;
|
|
28
|
+
} } } as unknown as ConfigStoreContract;
|
|
29
|
+
const approvals = approvalDepsForStores(config, state, original, { name: 'synthetic' } as any, {},
|
|
30
|
+
{ provider: 'synthetic', allow: ['*'], subject_field: 'subject' }, cfg, now, async () => {});
|
|
31
|
+
assert.equal(await approvals!.create(snap), 7);
|
|
32
|
+
assert.equal(saved.args_json, snap.args_json); assert.equal(argsHash(JSON.parse(saved.args_json)), snap.args_hash);
|
|
33
|
+
assert.deepEqual(saved.intent.args, JSON.parse(snap.args_json));
|
|
34
|
+
assert.equal(saved.intent.metadata.subject, 'synthetic-user');
|
|
35
|
+
assert.equal(saved.intent.metadata.agent_frozen_arguments, undefined);
|
|
36
|
+
assert.equal(draft.job.metadata.agent_frozen_arguments, undefined);
|
|
37
|
+
assert.equal(original.metadata.agent_frozen_arguments, 'private-encrypted-recovery-marker');
|
|
38
|
+
assert.equal(draft.snap.args_truncated, true); assert.equal(draft.snap.args_hash, snap.args_hash);
|
|
39
|
+
assert.equal(draft.snap.args_bytes, Buffer.byteLength(snap.args_json, 'utf8'));
|
|
40
|
+
assert.equal(JSON.parse(draft.snap.args_json).truncated, true);
|
|
41
|
+
assert.ok(Buffer.byteLength(JSON.stringify(draft), 'utf8') < 5000);
|
|
42
|
+
assert.equal(JSON.stringify(draft).includes('DO_NOT_COPY_FULL_DESIGN_END'), false);
|
|
43
|
+
assert.equal(JSON.stringify(draft).includes('private-encrypted-recovery-marker'), false);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('small notifications preserve original JSON object and large previews remain bounded and idempotent', () => {
|
|
47
|
+
const small = snapshot(false);
|
|
48
|
+
assert.equal(approvalNotificationSnapshot(small).args_json, small.args_json);
|
|
49
|
+
assert.equal(approvalNotificationSnapshot(small).args_truncated, undefined);
|
|
50
|
+
const large = snapshot(); large.summary = '中'.repeat(1000);
|
|
51
|
+
const preview = approvalNotificationSnapshot(large);
|
|
52
|
+
assert.equal(preview.args_bytes, Buffer.byteLength(large.args_json, 'utf8'));
|
|
53
|
+
assert.ok(Buffer.byteLength(preview.args_json, 'utf8') <= 1000);
|
|
54
|
+
assert.ok(Buffer.byteLength(preview.summary!, 'utf8') <= 512);
|
|
55
|
+
assert.deepEqual(approvalNotificationSnapshot(preview), preview);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('historical full notification drafts are projected again before any signed webhook dispatch', async () => {
|
|
59
|
+
const original = job(), snap = snapshot(); let sent: any;
|
|
60
|
+
const config = { approvals: { get: async () => ({ job_id: original.job_id, request_id: original.request_id, status: 'pending' }) } } as unknown as ConfigStoreContract;
|
|
61
|
+
const originalFetch = globalThis.fetch;
|
|
62
|
+
globalThis.fetch = async (_url, init) => { sent = JSON.parse(String(init?.body)); return new Response('', { status: 200 }); };
|
|
63
|
+
try {
|
|
64
|
+
const out = await notifyApprovalPayloadFor(config, state, { approval_id: 7, job: original, snap,
|
|
65
|
+
provider_name: 'synthetic', subject: 'synthetic-user', destination: { type: 'business_webhook', url: 'https://synthetic.invalid/approval' } },
|
|
66
|
+
cfg, now, async () => {}, defaultTargetRegistry, 'approval:7');
|
|
67
|
+
assert.equal(out.status, 'completed'); assert.equal(sent.args_truncated, true);
|
|
68
|
+
assert.equal(sent.args_hash, snap.args_hash); assert.equal(sent.intent.args_hash, snap.args_hash);
|
|
69
|
+
assert.equal(sent.args_bytes, Buffer.byteLength(snap.args_json, 'utf8'));
|
|
70
|
+
assert.equal(sent.metadata.agent_frozen_arguments, undefined);
|
|
71
|
+
assert.equal(sent.intent.metadata.agent_frozen_arguments, undefined);
|
|
72
|
+
assert.equal(JSON.stringify(sent).includes('DO_NOT_COPY_FULL_DESIGN_END'), false);
|
|
73
|
+
assert.equal(JSON.stringify(sent).includes('private-encrypted-recovery-marker'), false);
|
|
74
|
+
assert.ok(Buffer.byteLength(JSON.stringify(sent), 'utf8') < 7000);
|
|
75
|
+
} finally { globalThis.fetch = originalFetch; }
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('legacy approved note retains complete approved parameters rather than silently cropping the action', async () => {
|
|
79
|
+
const snap = snapshot();
|
|
80
|
+
const config = { approvals: { approvedUnusedForJob: async () => [{ id: 7, tool: snap.tool, args_json: snap.args_json }] } } as unknown as ConfigStoreContract;
|
|
81
|
+
const note = await approvedNoteForJobFor(config, 'synthetic-job');
|
|
82
|
+
assert.ok(note?.includes(snap.args_json)); assert.ok(note?.includes('DO_NOT_COPY_FULL_DESIGN_END'));
|
|
83
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { outboundRuntimeDepsFor, postSignedWithDeps, postSignedNotificationWithDeps, secretForJobWithDeps, type NotificationSendOutcome } from './outbound';
|
|
3
3
|
import type { ApprovalDeps, ApprovalIntentSnap } from '../core/contracts/tools';
|
|
4
|
+
import { approvalNotificationSnapshot } from '../core/contracts/tools';
|
|
4
5
|
import { approvalConfig, type RouteToolsConfig, type ToolSourceConfig, type ToolApprovalConfig } from '../core/config/tools-config';
|
|
5
6
|
import type { Job, ToolProvider } from '../core/contracts/types';
|
|
6
7
|
import { defaultTargetRegistry, type TargetRegistry } from '../core/targets/registry';
|
|
@@ -14,6 +15,13 @@ import { wakeNotificationOutboxFor } from '../core/runtime/notification-outbox-w
|
|
|
14
15
|
import type { ApprovalNotificationPayload } from '../core/contracts/notification-outbox';
|
|
15
16
|
import { createNotificationChildOnce } from './delivery';
|
|
16
17
|
|
|
18
|
+
/** Private encrypted recovery material is not approval intent or notification metadata. */
|
|
19
|
+
function approvalVisibleJob(job: Job): Job {
|
|
20
|
+
const metadata = { ...job.metadata };
|
|
21
|
+
delete metadata.agent_frozen_arguments;
|
|
22
|
+
return { ...job, metadata };
|
|
23
|
+
}
|
|
24
|
+
|
|
17
25
|
function notificationDestination(tools: RouteToolsConfig, config: AppConfig): ToolApprovalConfig | undefined {
|
|
18
26
|
const value = approvalConfig(tools) ?? config.alerts;
|
|
19
27
|
if (!value?.type) return undefined;
|
|
@@ -78,8 +86,8 @@ export function approvalDepsForStores(
|
|
|
78
86
|
};
|
|
79
87
|
if (cs.approvals.createWithNotification) {
|
|
80
88
|
const id = await cs.approvals.createWithNotification(approval, {
|
|
81
|
-
job, provider_name: provider.name, subject: onBehalfOf, subject_field: sourceCfg.subject_field,
|
|
82
|
-
snap, brand_name: appConfig.brand.name,
|
|
89
|
+
job: approvalVisibleJob(job), provider_name: provider.name, subject: onBehalfOf, subject_field: sourceCfg.subject_field,
|
|
90
|
+
snap: approvalNotificationSnapshot(snap), brand_name: appConfig.brand.name,
|
|
83
91
|
destination: notificationDestination(toolsCfg, appConfig),
|
|
84
92
|
});
|
|
85
93
|
wakeNotificationOutboxFor(state);
|
|
@@ -92,7 +100,7 @@ export function approvalDepsForStores(
|
|
|
92
100
|
// Compatibility for external ledgers without the durable creation port.
|
|
93
101
|
await notificationBackgroundWorkFor(state).track('approval-notification', async () => {
|
|
94
102
|
await notifyApprovalPayloadFor(config, state, { approval_id: id, job, provider_name: provider.name,
|
|
95
|
-
subject: subjectOf(job, sourceCfg), subject_field: sourceCfg.subject_field, snap, brand_name: appConfig.brand.name,
|
|
103
|
+
subject: subjectOf(job, sourceCfg), subject_field: sourceCfg.subject_field, snap: approvalNotificationSnapshot(snap), brand_name: appConfig.brand.name,
|
|
96
104
|
destination: notificationDestination(toolsCfg, appConfig),
|
|
97
105
|
}, appConfig, nowFn, sleepFn, targetRegistry);
|
|
98
106
|
});
|
|
@@ -123,9 +131,11 @@ function approvalIntentFor(job: Job, provider: ToolProvider, sourceCfg: ToolSour
|
|
|
123
131
|
path: snap.path,
|
|
124
132
|
args,
|
|
125
133
|
args_hash: snap.args_hash,
|
|
134
|
+
...(snap.args_bytes !== undefined ? { args_bytes: snap.args_bytes } : {}),
|
|
135
|
+
...(snap.args_truncated ? { args_truncated: true } : {}),
|
|
126
136
|
summary: snap.summary,
|
|
127
137
|
confirm_when: snap.confirm_when,
|
|
128
|
-
metadata: job.metadata
|
|
138
|
+
metadata: approvalVisibleJob(job).metadata,
|
|
129
139
|
};
|
|
130
140
|
}
|
|
131
141
|
|
|
@@ -139,7 +149,10 @@ export async function notifyApprovalPayloadFor(
|
|
|
139
149
|
targetRegistry: TargetRegistry,
|
|
140
150
|
eventId?: string,
|
|
141
151
|
): Promise<NotificationSendOutcome> {
|
|
142
|
-
const {
|
|
152
|
+
const { approval_id: approvalId } = payload;
|
|
153
|
+
// Also bound historical durable drafts before sending; new producers already store this view.
|
|
154
|
+
const job = approvalVisibleJob(payload.job);
|
|
155
|
+
const snap = approvalNotificationSnapshot(payload.snap);
|
|
143
156
|
const provider = { name: payload.provider_name } as ToolProvider;
|
|
144
157
|
const sourceCfg = { provider: payload.provider_name, allow: [], subject_field: payload.subject_field };
|
|
145
158
|
const subject = payload.subject;
|
|
@@ -165,7 +178,7 @@ export async function notifyApprovalPayloadFor(
|
|
|
165
178
|
`触发原因:${snap.reason}`,
|
|
166
179
|
`任务:${job.dispatch?.route_name || job.request_id}(job ${job.job_id})`,
|
|
167
180
|
`工具:${snap.tool}(scope ${snap.scope},风险 ${snap.risk})`,
|
|
168
|
-
|
|
181
|
+
`${snap.args_truncated ? '参数预览(已截断,完整参数请到授权控制台查看)' : '参数'}:${snap.args_json}`,
|
|
169
182
|
isAgentToolInvocationJob(job)
|
|
170
183
|
? '请到控制台「工具审批」页处理;批准后由原本地 Agent 用 invocation_id 续执行,中枢不启动模型重跑。'
|
|
171
184
|
: '请到控制台「工具审批」页处理;批准后任务将自动重跑完成该操作。',
|
|
@@ -204,6 +217,8 @@ export async function notifyApprovalPayloadFor(
|
|
|
204
217
|
path: snap.path,
|
|
205
218
|
args,
|
|
206
219
|
args_hash: snap.args_hash,
|
|
220
|
+
...(snap.args_bytes !== undefined ? { args_bytes: snap.args_bytes } : {}),
|
|
221
|
+
...(snap.args_truncated ? { args_truncated: true } : {}),
|
|
207
222
|
summary: snap.summary,
|
|
208
223
|
intent: { approval_id: approvalId, ...intent },
|
|
209
224
|
decision_path: `/approvals/${approvalId}/decision`,
|
|
@@ -238,7 +253,10 @@ export async function notifyApprovalPayloadFor(
|
|
|
238
253
|
if (type === 'webhook' && ap['url']) {
|
|
239
254
|
return post(String(ap['url']), {
|
|
240
255
|
kind: 'tool_approval', approval_id: approvalId, job_id: job.job_id, request_id: job.request_id,
|
|
241
|
-
tool: snap.tool, scope: snap.scope, risk: snap.risk, policy: snap.policy, reason: snap.reason, args: snap.args_json,
|
|
256
|
+
tool: snap.tool, scope: snap.scope, risk: snap.risk, policy: snap.policy, reason: snap.reason, args: snap.args_json,
|
|
257
|
+
...(snap.args_bytes !== undefined ? { args_bytes: snap.args_bytes } : {}),
|
|
258
|
+
...(snap.args_truncated ? { args_truncated: true } : {}),
|
|
259
|
+
intent: { approval_id: approvalId, ...intent }, message: content,
|
|
242
260
|
}, 'approval_notify');
|
|
243
261
|
}
|
|
244
262
|
const targetName = `${type}-notify`;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { createHmac } from 'node:crypto';
|
|
3
|
+
import { Readable } from 'node:stream';
|
|
4
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
5
|
+
import test from 'node:test';
|
|
6
|
+
import type { AppConfig } from '../core/config/config';
|
|
7
|
+
import type { Job } from '../core/contracts/types';
|
|
8
|
+
import type { RuntimeStateStore } from '../core/state/state-contracts';
|
|
9
|
+
import { TOOL_ARGUMENTS_MAX_BYTES, TOOL_INVOCATION_BODY_MAX_BYTES } from '../core/contracts/tool-input-limits';
|
|
10
|
+
import { handleToolInvokeFor, type ToolProxyDeps } from './tool-proxy';
|
|
11
|
+
|
|
12
|
+
class Response {
|
|
13
|
+
statusCode = 0;
|
|
14
|
+
body: Record<string, unknown> = {};
|
|
15
|
+
writeHead(status: number): void { this.statusCode = status; }
|
|
16
|
+
end(value: string): void { this.body = JSON.parse(value) as Record<string, unknown>; }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function fixture() {
|
|
20
|
+
const serverToken = 'demo-server-token';
|
|
21
|
+
const job = { job_id: 'demo-job', request_id: 'demo-request', status: 'dispatched',
|
|
22
|
+
claim_token: 'demo-claim', metadata: {}, dispatch: {} } as Job;
|
|
23
|
+
const deps: ToolProxyDeps = {
|
|
24
|
+
cfg: { server: { token: serverToken } } as AppConfig, configStore: null,
|
|
25
|
+
stateStore: { getJob: async () => job } as unknown as RuntimeStateStore,
|
|
26
|
+
toolIndex: null, now: () => '2026-01-01T00:00:00.000Z', sleep: async () => undefined,
|
|
27
|
+
};
|
|
28
|
+
const token = createHmac('sha256', serverToken).update(`${job.job_id}.${job.claim_token}`).digest('hex');
|
|
29
|
+
return { deps, job, token };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function invoke(body: unknown, presented?: string) {
|
|
33
|
+
const fx = fixture(), res = new Response();
|
|
34
|
+
const req = Readable.from([Buffer.from(JSON.stringify(body))]) as unknown as IncomingMessage;
|
|
35
|
+
await handleToolInvokeFor(fx.deps, req, res as unknown as ServerResponse, fx.job.job_id, presented ?? fx.token);
|
|
36
|
+
return res;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function argsOfBytes(bytes: number): Record<string, unknown> {
|
|
40
|
+
const base = { source: { html: '中文😀"\\', css: '' }, padding: '' };
|
|
41
|
+
base.padding = 'x'.repeat(bytes - Buffer.byteLength(JSON.stringify(base), 'utf8'));
|
|
42
|
+
assert.equal(Buffer.byteLength(JSON.stringify(base), 'utf8'), bytes);
|
|
43
|
+
return base;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
test('Executor tool proxy: 1 MiB arguments reach normal governance without the old envelope rejection', async () => {
|
|
47
|
+
for (const bytes of [4395, 5183, 16 * 1024, 64 * 1024, 256 * 1024, TOOL_ARGUMENTS_MAX_BYTES]) {
|
|
48
|
+
const response = await invoke({ tool: 'validate_page', arguments: argsOfBytes(bytes) });
|
|
49
|
+
// This fixture deliberately has no provider. The size gate must not replace normal governance.
|
|
50
|
+
assert.equal(response.statusCode, 400);
|
|
51
|
+
assert.equal(response.body.error, '该任务未配置工具');
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('Executor tool proxy: exact serialized arguments budget rejects +1 with no payload echo', async () => {
|
|
56
|
+
const response = await invoke({ tool: 'validate_page', arguments: argsOfBytes(TOOL_ARGUMENTS_MAX_BYTES + 1) });
|
|
57
|
+
assert.equal(response.statusCode, 413);
|
|
58
|
+
assert.deepEqual(response.body, {
|
|
59
|
+
error: 'arguments_too_large', origin: 'core', dispatch: 'not_dispatched',
|
|
60
|
+
limit_scope: 'arguments', actual_bytes: 1048577, max_bytes: 1048576,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('Executor tool proxy: oversized HTTP body keeps 413 instead of becoming tool-required 400', async () => {
|
|
65
|
+
const response = await invoke({ tool: 'validate_page', arguments: {}, padding: 'x'.repeat(TOOL_INVOCATION_BODY_MAX_BYTES) });
|
|
66
|
+
assert.equal(response.statusCode, 413);
|
|
67
|
+
assert.equal(response.body.error, 'arguments_too_large');
|
|
68
|
+
assert.equal(response.body.limit_scope, 'request_body');
|
|
69
|
+
assert.equal(response.body.max_bytes, 2097152);
|
|
70
|
+
assert.equal(response.body.dispatch, 'not_dispatched');
|
|
71
|
+
assert.ok(Number(response.body.observed_bytes) > TOOL_INVOCATION_BODY_MAX_BYTES);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('Executor tool proxy: authentication still precedes size reads and invalid bodies stay invalid', async () => {
|
|
75
|
+
assert.equal((await invoke({ arguments: argsOfBytes(TOOL_ARGUMENTS_MAX_BYTES + 1) }, 'demo-invalid-token')).statusCode, 401);
|
|
76
|
+
for (const body of [null, [], 'text']) {
|
|
77
|
+
const response = await invoke(body);
|
|
78
|
+
assert.equal(response.statusCode, 400);
|
|
79
|
+
assert.equal(response.body.error, 'invalid_request');
|
|
80
|
+
}
|
|
81
|
+
});
|
package/src/app/tool-proxy.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
2
2
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
3
|
-
import { errMsg, readBody, send } from './http';
|
|
3
|
+
import { errMsg, PayloadTooLargeError, readBody, send } from './http';
|
|
4
|
+
import { TOOL_ARGUMENTS_MAX_BYTES, TOOL_INVOCATION_BODY_MAX_BYTES } from '../core/contracts/tool-input-limits';
|
|
4
5
|
import { TOOL_INLINE_MAX, type ToolRuntime } from '../core/contracts/tools';
|
|
5
6
|
import type { ToolDefinition } from '../core/contracts/tool-definition';
|
|
6
7
|
import { toolSummary } from '../core/contracts/tool-definition';
|
|
@@ -134,10 +135,31 @@ export async function handleToolInvokeFor(deps: ToolProxyDeps, req: IncomingMess
|
|
|
134
135
|
return;
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
|
-
|
|
138
|
+
let body: Record<string, unknown>;
|
|
139
|
+
try { body = await readBody(req, TOOL_INVOCATION_BODY_MAX_BYTES); }
|
|
140
|
+
catch (error) {
|
|
141
|
+
if (error instanceof PayloadTooLargeError) {
|
|
142
|
+
send(res, 413, {
|
|
143
|
+
error: 'arguments_too_large', origin: 'core', dispatch: 'not_dispatched',
|
|
144
|
+
limit_scope: 'request_body', max_bytes: TOOL_INVOCATION_BODY_MAX_BYTES,
|
|
145
|
+
...(error.observedBytes !== undefined ? { observed_bytes: error.observedBytes } : {}),
|
|
146
|
+
});
|
|
147
|
+
} else send(res, 400, { error: 'invalid_request', message: 'The tool request body must be valid JSON.' });
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)) {
|
|
151
|
+
send(res, 400, { error: 'invalid_request', message: 'The tool request body must be a JSON object.' });
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
138
154
|
const tool = String(body['tool'] ?? '');
|
|
139
155
|
if (!tool) { send(res, 400, { error: 'tool 必填' }); return; }
|
|
140
156
|
const args = (body['arguments'] as Record<string, unknown>) ?? {};
|
|
157
|
+
const argumentsBytes = Buffer.byteLength(JSON.stringify(args), 'utf8');
|
|
158
|
+
if (argumentsBytes > TOOL_ARGUMENTS_MAX_BYTES) {
|
|
159
|
+
send(res, 413, { error: 'arguments_too_large', origin: 'core', dispatch: 'not_dispatched',
|
|
160
|
+
limit_scope: 'arguments', actual_bytes: argumentsBytes, max_bytes: TOOL_ARGUMENTS_MAX_BYTES });
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
141
163
|
if (tool === SEND_TOOL_NAME) {
|
|
142
164
|
const sendChannels = await resolveSendChannelsFor(deps.configStore, job.dispatch?.tools as Record<string, unknown> | undefined).catch(() => [] as string[]);
|
|
143
165
|
if (!sendChannels.length) { send(res, 400, { error: '本路由未开放主动发送渠道' }); return; }
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { diagnosticDestination, filterLocatedRows, readListLocation } from '../../../web-admin/src/console-location';
|
|
4
|
+
|
|
5
|
+
test('diagnostics distinguish configuration objects from runtime aggregates and preserve return context', () => {
|
|
6
|
+
const origin = '/diagnostics?severity=error&q=demo';
|
|
7
|
+
assert.deepEqual(diagnosticDestination({ area: 'tool_provider', id: 'demo' }, origin), { path: '/tools', query: { q: 'demo', focus: 'demo', return_to: origin } });
|
|
8
|
+
assert.equal(diagnosticDestination({ area: 'alert_rule', id: '12' }, origin)?.query.alert_focus, '12');
|
|
9
|
+
assert.equal(diagnosticDestination({ area: 'runtime_jobs', id: 'error_burst' }, origin)?.query.tab, 'jobs');
|
|
10
|
+
assert.equal(diagnosticDestination({ area: 'runtime_delivery', id: 'delivery_dlq' }, origin)?.query.outbox_kind, 'delivery-dlq');
|
|
11
|
+
assert.equal(diagnosticDestination({ area: 'runtime_executor', id: 'offline' }, origin)?.query.state, 'offline');
|
|
12
|
+
assert.equal(diagnosticDestination({ area: 'runtime_executor', id: 'worker-a' }, origin)?.query.target, 'worker-a');
|
|
13
|
+
assert.equal(diagnosticDestination({ area: 'new-unknown-area', id: 'something' }, origin), undefined);
|
|
14
|
+
});
|
|
15
|
+
test('exact diagnostic focus cannot silently select a similar object or match secrets', () => {
|
|
16
|
+
const rows = [{ id: 'a', name: 'Alpha', secret: 'token-value' }, { id: 'aa', name: 'Beta', secret: '' }];
|
|
17
|
+
const filter = (q: string, focus = '') => filterLocatedRows(rows, q, focus, r => r.id, r => `${r.id} ${r.name}`);
|
|
18
|
+
assert.deepEqual(filter('a', 'a'), [rows[0]]);
|
|
19
|
+
assert.deepEqual(filter('', 'deleted'), []);
|
|
20
|
+
assert.deepEqual(filter('TOKEN-VALUE'), []);
|
|
21
|
+
assert.deepEqual(filter('alpha'), [rows[0]]);
|
|
22
|
+
assert.deepEqual(readListLocation({ q: ['bad'], focus: null }), { keyword: '', focus: '' });
|
|
23
|
+
assert.deepEqual(readListLocation({ alert_q: '12', alert_focus: '12' }, 'alert_'), { keyword: '12', focus: '12' });
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('auto-routing diagnostics locate a client or both ambiguous routes rather than treating aggregate IDs as route keys', () => {
|
|
27
|
+
const origin = '/diagnostics?tab=auto';
|
|
28
|
+
const noCandidates = diagnosticDestination({ area: 'route_auto', id: 'client-a' }, origin);
|
|
29
|
+
assert.equal(noCandidates?.path, '/clients');
|
|
30
|
+
assert.equal(noCandidates?.query.focus, 'client-a');
|
|
31
|
+
const ambiguous = diagnosticDestination({ area: 'route_auto', id: 'route-a<->route-b' }, origin);
|
|
32
|
+
assert.deepEqual(ambiguous, { path: '/routes', query: { return_to: origin, q: 'route-a', focus: 'route-a', related: 'route-b' } });
|
|
33
|
+
assert.deepEqual(filterLocatedRows(['route-a', 'route-b', 'route-aa'], 'route-a', 'route-a', r => r, r => r, 'route-b'), ['route-a', 'route-b']);
|
|
34
|
+
assert.equal(diagnosticDestination({ area: 'route_auto', id: 'a<->b<->c' }, origin), undefined);
|
|
35
|
+
assert.equal(diagnosticDestination({ area: 'credential', id: 'model-key' }, origin)?.path, '/credentials');
|
|
36
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { createFormExitGuard, formSnapshot, needsUnloadWarning } from '../../../web-admin/src/form-guard';
|
|
4
|
+
import { hasClientRouteDraft, rememberClientRouteDraft, takeClientRouteDraft, type ClientRouteDraft } from '../../../web-admin/src/client-route-draft';
|
|
5
|
+
|
|
6
|
+
test('unchanged forms leave quietly; edits, reverted edits and in-flight saves have distinct unload behavior', async () => {
|
|
7
|
+
const form = { name: 'existing', routes: ['one'], settings: { window: 'day', enabled: true } };
|
|
8
|
+
const baseline = formSnapshot(form);
|
|
9
|
+
let active = true, saving = false, prompts = 0, blocked = 0;
|
|
10
|
+
const state = { active: () => active, saving: () => saving, dirty: () => formSnapshot(form) !== baseline };
|
|
11
|
+
const guard = createFormExitGuard(state, async () => { prompts++; return false; }, () => { blocked++; });
|
|
12
|
+
assert.equal(await guard.confirmLeave(), true);
|
|
13
|
+
assert.equal(needsUnloadWarning(state), false);
|
|
14
|
+
form.routes.push('two');
|
|
15
|
+
assert.equal(needsUnloadWarning(state), true);
|
|
16
|
+
assert.equal(await guard.confirmLeave(), false);
|
|
17
|
+
assert.deepEqual(form.routes, ['one', 'two'], 'cancel retains the exact input');
|
|
18
|
+
form.routes.pop();
|
|
19
|
+
assert.equal(needsUnloadWarning(state), false, 'reverting the edit restores a clean form');
|
|
20
|
+
saving = true;
|
|
21
|
+
assert.equal(needsUnloadWarning(state), true, 'an unchanged form can still have a pending save');
|
|
22
|
+
assert.equal(await guard.confirmLeave(), false);
|
|
23
|
+
assert.equal(prompts, 1); assert.equal(blocked, 1);
|
|
24
|
+
active = false;
|
|
25
|
+
assert.equal(needsUnloadWarning(state), false);
|
|
26
|
+
assert.equal(await guard.confirmLeave(), true);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('overlapping close and navigation share one confirmation; starting a save prevents a late discard', async () => {
|
|
30
|
+
let saving = false, prompts = 0;
|
|
31
|
+
let answer!: (value: boolean) => void;
|
|
32
|
+
const guard = createFormExitGuard({ active: () => true, dirty: () => true, saving: () => saving },
|
|
33
|
+
() => { prompts++; return new Promise<boolean>((resolve) => { answer = resolve; }); }, () => undefined);
|
|
34
|
+
const close = guard.confirmLeave(), navigation = guard.confirmLeave();
|
|
35
|
+
assert.equal(prompts, 1);
|
|
36
|
+
saving = true; answer(true);
|
|
37
|
+
assert.equal(await close, false); assert.equal(await navigation, false);
|
|
38
|
+
saving = false;
|
|
39
|
+
const retry = guard.confirmLeave(); answer(true);
|
|
40
|
+
assert.equal(await retry, true); assert.equal(prompts, 2);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('a dismissed or rejected confirmation never permits navigation', async () => {
|
|
44
|
+
const guard = createFormExitGuard({ active: () => true, dirty: () => true, saving: () => false },
|
|
45
|
+
async () => { throw new Error('modal dismissed'); }, () => undefined);
|
|
46
|
+
assert.equal(await guard.confirmLeave(), false);
|
|
47
|
+
assert.equal(formSnapshot({ a: 1, nested: { b: 2, a: 3 } }), formSnapshot({ nested: { a: 3, b: 2 }, a: 1 }),
|
|
48
|
+
'hydrating an equivalent object with a different key order does not invent edits');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('the client dependency detour restores only its owner, once, without adding a wildcard or retaining token fields', () => {
|
|
52
|
+
const input = { form: { app_id: 'draft', name: 'Unfinished client', agent_authorize_url: '', allowed_routes: [], allowed_channels: [],
|
|
53
|
+
rate_limit_per_min: 60, description: 'keep this input', enabled: true, token: 'must-not-be-retained', secret: 'also-not-retained' },
|
|
54
|
+
budget: { enabled: true, window: 'day', hard_tokens: 1234 }, budgetRest: { legacy_budget_flag: true }, editing: false, baseline: 'original-baseline' } as ClientRouteDraft;
|
|
55
|
+
rememberClientRouteDraft('user-a', input);
|
|
56
|
+
input.form.name = 'changed after leaving';
|
|
57
|
+
assert.equal(hasClientRouteDraft('user-a'), true);
|
|
58
|
+
assert.equal(hasClientRouteDraft('user-b'), false);
|
|
59
|
+
const restored = takeClientRouteDraft('user-a')!;
|
|
60
|
+
assert.equal(restored.form.name, 'Unfinished client');
|
|
61
|
+
assert.deepEqual(restored.form.allowed_routes, []);
|
|
62
|
+
assert.equal(restored.budget.hard_tokens, 1234);
|
|
63
|
+
assert.equal(restored.baseline, 'original-baseline');
|
|
64
|
+
assert.equal('token' in restored.form, false); assert.equal('secret' in restored.form, false);
|
|
65
|
+
assert.equal(takeClientRouteDraft('user-a'), undefined);
|
|
66
|
+
rememberClientRouteDraft('user-a', input);
|
|
67
|
+
assert.equal(takeClientRouteDraft('user-b'), undefined);
|
|
68
|
+
assert.equal(takeClientRouteDraft('user-a'), undefined, 'changing account discards the previous draft');
|
|
69
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { filterLoadedRuns, patchTaskQuery, readOutboxLocation, readRunFilters, readRunsLocation, RUN_FILTER_STATUSES, runsTabQuery, safeTaskReturnPath } from '../../../web-admin/src/task-page-location';
|
|
4
|
+
|
|
5
|
+
test('task tabs restore canonical and legacy links without a job stealing an explicit delivery tab', () => {
|
|
6
|
+
assert.equal(readRunsLocation({ tab: 'outbox', job: 'original' }).tab, 'notifications');
|
|
7
|
+
assert.equal(readRunsLocation({ tab: 'notifications' }).tab, 'notifications');
|
|
8
|
+
assert.equal(readRunsLocation({ job: 'original' }).detail, 'original');
|
|
9
|
+
assert.equal(readRunsLocation({ tab: 'jobs', job: 'original' }).detail, '');
|
|
10
|
+
assert.equal(runsTabQuery('threads'), 'conversations');
|
|
11
|
+
const restored = readRunsLocation({ tab: 'conversations', view: 'legacy', thread: '42', thread_q: 'customer', detail: 'job-detail' });
|
|
12
|
+
assert.deepEqual([restored.tab, restored.view, restored.thread, restored.threadQ, restored.detail], ['threads', 'legacy', 42, 'customer', 'job-detail']);
|
|
13
|
+
});
|
|
14
|
+
test('changing a task selection preserves unrelated filters and the diagnostic return context', () => {
|
|
15
|
+
const original = { task: 'old', invocation: 'old-call', return_to: '/diagnostics?section=delivery', future: ['one', 'two'], outbox_status: 'uncertain' };
|
|
16
|
+
const next = patchTaskQuery(original, { task: 'new', invocation: undefined });
|
|
17
|
+
assert.equal(next.task, 'new'); assert.equal(next.invocation, undefined);
|
|
18
|
+
assert.equal(next.return_to, original.return_to); assert.deepEqual(next.future, ['one', 'two']);
|
|
19
|
+
assert.equal(original.invocation, 'old-call');
|
|
20
|
+
});
|
|
21
|
+
test('outbox filter restoration validates enums and pagination without coercing malformed query arrays', () => {
|
|
22
|
+
assert.deepEqual(readOutboxLocation({ outbox_kind: 'delivery-dlq', outbox_status: 'uncertain', outbox_page: '3' }), { kind: 'delivery-dlq', status: 'uncertain', page: 3 });
|
|
23
|
+
assert.deepEqual(readOutboxLocation({ outbox_kind: ['delivery'], outbox_status: 'new-state', outbox_page: '-4' }), { kind: 'callback', status: '', page: 1 });
|
|
24
|
+
assert.equal(readOutboxLocation({ outbox_page: '9007199254740992' }).page, 1);
|
|
25
|
+
});
|
|
26
|
+
test('return context only navigates to known pages inside this console', () => {
|
|
27
|
+
assert.equal(safeTaskReturnPath('/diagnostics?section=delivery#results'), '/diagnostics?section=delivery#results');
|
|
28
|
+
assert.equal(safeTaskReturnPath('/agent-tasks?task=original'), '/agent-tasks?task=original');
|
|
29
|
+
assert.equal(safeTaskReturnPath('/executors?focus=worker-1&q=orders'), '/executors?focus=worker-1&q=orders');
|
|
30
|
+
for (const value of ['https://evil.example/runs', '//evil.example/runs', '/\\evil.example/runs', 'javascript:alert(1)', '/admin/api/runs', '/runs/../../login', '/%2f%2fevil.example', '/runs\n', ['/runs']]) assert.equal(safeTaskReturnPath(value), undefined);
|
|
31
|
+
});
|
|
32
|
+
test('job filters accept the actual job status contract and keep diagnostic and selection context', () => {
|
|
33
|
+
assert.deepEqual([...RUN_FILTER_STATUSES], ['queued', 'running', 'dispatched', 'done', 'error', 'rejected']);
|
|
34
|
+
assert.deepEqual(readRunFilters({ run_status: 'error', run_route: 'orders', run_period: '24h' }), { status: 'error', route: 'orders', period: '24h' });
|
|
35
|
+
assert.deepEqual(readRunFilters({ run_status: 'failed', run_route: ['orders'], run_period: '2d' }), { status: '', route: '', period: 'all' });
|
|
36
|
+
const query = patchTaskQuery({ detail: 'original-job', return_to: '/diagnostics', future: 'kept', run_status: 'queued' }, { tab: 'jobs', run_status: undefined, run_route: 'orders', run_period: '7d' });
|
|
37
|
+
assert.deepEqual(readRunFilters(query), { status: '', route: 'orders', period: '7d' });
|
|
38
|
+
assert.equal(query.detail, 'original-job'); assert.equal(query.return_to, '/diagnostics'); assert.equal(query.future, 'kept');
|
|
39
|
+
});
|
|
40
|
+
test('loaded job filtering composes exact status and route without searching body text', () => {
|
|
41
|
+
const rows = [
|
|
42
|
+
{ id: 'match', status: 'error', route_key: 'orders', created_at: '2026-10-21T00:00:00Z' },
|
|
43
|
+
{ id: 'prefix', status: 'error', route_key: 'orders-next', input_preview: 'orders', created_at: '2026-10-21T00:00:00Z' },
|
|
44
|
+
{ id: 'body-only', status: 'error', input_preview: 'orders', created_at: '2026-10-21T00:00:00Z' },
|
|
45
|
+
{ id: 'wrong-status', status: 'done', route_key: 'orders', created_at: '2026-10-21T00:00:00Z' },
|
|
46
|
+
{ id: 'old', status: 'error', route_key: 'orders', created_at: '2026-10-10T00:00:00Z' },
|
|
47
|
+
];
|
|
48
|
+
const found = filterLoadedRuns(rows, { status: 'error', route: 'orders', period: '24h' }, Date.parse('2026-10-21T10:00:00Z'));
|
|
49
|
+
assert.deepEqual(found.map(row => row.id), ['match']);
|
|
50
|
+
assert.equal(rows.length, 5, 'filtering does not mutate or replace the loaded snapshot');
|
|
51
|
+
assert.deepEqual(filterLoadedRuns(rows, { status: '', route: '', period: 'all' }, 0), rows);
|
|
52
|
+
});
|
|
53
|
+
test('time windows include their exact boundary and exclude invalid, future, and older timestamps', () => {
|
|
54
|
+
const now = Date.parse('2026-10-21T10:00:00Z');
|
|
55
|
+
const rows = [
|
|
56
|
+
{ id: '24h', created_at: new Date(now - 86400000).toISOString() },
|
|
57
|
+
{ id: '7d', created_at: new Date(now - 7 * 86400000).toISOString() },
|
|
58
|
+
{ id: 'older', created_at: new Date(now - 7 * 86400000 - 1).toISOString() },
|
|
59
|
+
{ id: 'future', created_at: new Date(now + 1).toISOString() },
|
|
60
|
+
{ id: 'invalid', created_at: 'unknown' },
|
|
61
|
+
];
|
|
62
|
+
assert.deepEqual(filterLoadedRuns(rows, { status: '', route: '', period: '24h' }, now).map(row => row.id), ['24h']);
|
|
63
|
+
assert.deepEqual(filterLoadedRuns(rows, { status: '', route: '', period: '7d' }, now).map(row => row.id), ['24h', '7d']);
|
|
64
|
+
});
|