@sema-agent/server 7.43.0 → 7.44.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/USAGE.md +18 -0
- package/dist/adoption/plan.js +31 -192
- package/dist/adoption/quiesce.js +3 -86
- package/dist/adoption/runner.js +3 -140
- package/dist/adoption/sql.js +0 -74
- package/dist/adoption/wire.js +0 -80
- package/dist/approval-ask-machine.js +0 -75
- package/dist/approval-card.js +0 -323
- package/dist/approval-deny-reasons.js +0 -42
- package/dist/approval-hmac.js +0 -35
- package/dist/approval-reconciler.js +8 -166
- package/dist/approval.js +4 -67
- package/dist/audit.js +1 -44
- package/dist/auth-bridge.js +4 -47
- package/dist/auth-keys.js +0 -23
- package/dist/bake-runner/main.js +4 -65
- package/dist/bake-runner/protocol.js +3 -58
- package/dist/bake-runner/runner.js +5 -91
- package/dist/bench/l8/artifact.js +2 -61
- package/dist/bench/l8/escape.js +0 -25
- package/dist/bench/l8/index.js +0 -14
- package/dist/bench/l8/probes.js +0 -60
- package/dist/bench/l8/run-probes.js +2 -45
- package/dist/bench/s1/arms.js +14 -189
- package/dist/bench/s1/live-deps.js +11 -253
- package/dist/bench/s1/oracle.js +1 -36
- package/dist/bench/s1/repair-oracle-adapter.js +0 -30
- package/dist/bench/s1/reviewer.js +0 -34
- package/dist/bench/s1/row.js +0 -62
- package/dist/bench/s1/run-firm.js +4 -70
- package/dist/bench/s1/runner-ctx.js +0 -40
- package/dist/bench/s1/tasks.js +0 -115
- package/dist/boot/adoption.js +0 -20
- package/dist/boot/budget-tracing.js +3 -55
- package/dist/boot/config-center.js +43 -551
- package/dist/boot/coordinators.js +1 -69
- package/dist/boot/crash-last.js +0 -18
- package/dist/boot/deferred-sandbox-path-env.js +3 -119
- package/dist/boot/execution-env.js +5 -171
- package/dist/boot/governance-seams.js +0 -92
- package/dist/boot/leader.js +0 -69
- package/dist/boot/limit-sync.js +0 -2
- package/dist/boot/memory-boundary.js +3 -91
- package/dist/boot/org-memory.js +1 -25
- package/dist/boot/parked-revive-gate.js +0 -150
- package/dist/boot/permission-rules-audit.js +1 -56
- package/dist/boot/reapers.js +15 -273
- package/dist/boot/resolve-spec.js +9 -768
- package/dist/boot/retention-lane.js +4 -87
- package/dist/boot/runner-deps.js +3 -297
- package/dist/boot/runtime-caps.js +0 -40
- package/dist/boot/session-faces.js +2 -133
- package/dist/boot/shutdown.js +9 -83
- package/dist/boot/side-query-lane.js +2 -137
- package/dist/boot/stores.js +15 -215
- package/dist/boot/task-list-lane.js +0 -18
- package/dist/boot/webfetch-summarize-lane.js +0 -47
- package/dist/boot/workflow-orchestration.js +3 -99
- package/dist/boot-reclaim.js +0 -20
- package/dist/bounded-session-map.js +0 -19
- package/dist/brain.js +2 -139
- package/dist/budget.js +9 -244
- package/dist/capabilities/builtin-tools.js +0 -3
- package/dist/capabilities/center-plugins.js +6 -51
- package/dist/capabilities/center-prompts.js +6 -71
- package/dist/capabilities/code-review-council.js +7 -40
- package/dist/capabilities/collab-workflows.js +1 -44
- package/dist/capabilities/hands-lane.js +0 -65
- package/dist/capabilities/memory-notice.js +0 -70
- package/dist/capabilities/prompt.js +0 -14
- package/dist/capabilities/prompts/code-review.js +0 -14
- package/dist/capabilities/prompts/identity.js +0 -6
- package/dist/capabilities/prompts/team.js +0 -4
- package/dist/capabilities/repo-tools.js +0 -34
- package/dist/capabilities/sandbox-file-send.js +3 -92
- package/dist/capabilities/scenarios.d.ts +0 -1
- package/dist/capabilities/scenarios.js +18 -279
- package/dist/capabilities/select-environment-tool.js +0 -32
- package/dist/capabilities/send-user-file-tool.js +2 -66
- package/dist/capabilities/skills.d.ts +1 -2
- package/dist/capabilities/skills.js +3 -21
- package/dist/capabilities/team.d.ts +3 -11
- package/dist/capabilities/team.js +3 -51
- package/dist/capabilities/tool-defer.js +0 -3
- package/dist/config-center/apply-effective.js +15 -330
- package/dist/config-center/apply-ledger.js +5 -38
- package/dist/config-center/facade.js +0 -41
- package/dist/config-center/hot-keys-registry.js +0 -20
- package/dist/config-center/http-client.js +2 -125
- package/dist/config-center/mcp-revocation.js +2 -34
- package/dist/config-center/read-face.js +0 -59
- package/dist/config-center/restart-signal.js +1 -85
- package/dist/config-center/skills-mcp.d.ts +1 -1
- package/dist/config-center/skills-mcp.js +9 -76
- package/dist/config-center/stage-limits.js +8 -35
- package/dist/config-invariants.js +0 -16
- package/dist/config-lkg.js +0 -42
- package/dist/config-provider.js +3 -186
- package/dist/config-types.js +0 -5
- package/dist/config.js +107 -1145
- package/dist/degenerate-instrument.js +3 -67
- package/dist/deployment-governance.js +0 -124
- package/dist/digest-form.js +0 -12
- package/dist/elicitation.js +3 -86
- package/dist/env-facts.js +7 -75
- package/dist/fleet/fleet-bus.js +34 -507
- package/dist/fleet/fleet-reconciler.js +9 -149
- package/dist/fleet/fleet-terminal-window.js +10 -178
- package/dist/fleet/subagent-tail-bus.js +3 -72
- package/dist/fleet-client.js +10 -70
- package/dist/fleet-lease.js +5 -79
- package/dist/git-api-kind.js +0 -3
- package/dist/governance-ask-marks.js +2 -78
- package/dist/hooks/branch-transcript.js +0 -74
- package/dist/hooks/cc-agent-hook-prompt.js +0 -29
- package/dist/hooks/cc-stop-prompt.js +1 -46
- package/dist/hooks/hook-llm.js +1 -53
- package/dist/hooks/hook-runner.js +20 -414
- package/dist/http/active-run-conflict.js +4 -129
- package/dist/http/cursor-fingerprint.d.ts +5 -0
- package/dist/http/cursor-fingerprint.js +5 -0
- package/dist/http/idempotency.js +0 -37
- package/dist/http/principal-gate.js +3 -40
- package/dist/http/route-ctx.js +0 -9
- package/dist/http/routes/a2a-serve.js +7 -319
- package/dist/http/routes/admin-config-refresh.js +0 -4
- package/dist/http/routes/admin-drain.js +0 -10
- package/dist/http/routes/adoption.js +1 -29
- package/dist/http/routes/agents-roster.js +1 -47
- package/dist/http/routes/approvals-assistant.js +32 -395
- package/dist/http/routes/attachments.js +4 -22
- package/dist/http/routes/capabilities.js +3 -420
- package/dist/http/routes/diagnostics.js +1 -81
- package/dist/http/routes/fleet.js +9 -185
- package/dist/http/routes/images.js +14 -239
- package/dist/http/routes/leader.js +0 -13
- package/dist/http/routes/memory-bundle.js +1 -61
- package/dist/http/routes/memory-policy.js +9 -99
- package/dist/http/routes/notify-wake.js +3 -37
- package/dist/http/routes/observability.js +2 -19
- package/dist/http/routes/retention-ops.js +2 -34
- package/dist/http/routes/rules.js +1 -93
- package/dist/http/routes/runs.js +64 -873
- package/dist/http/routes/session-sync.js +19 -258
- package/dist/http/routes/sessions-list.js +17 -43
- package/dist/http/routes/sessions.js +34 -226
- package/dist/http/routes/shared-memory.js +5 -36
- package/dist/http/routes/side-query.js +1 -87
- package/dist/http/routes/tasks.js +52 -722
- package/dist/http/routes/trace-usage.js +32 -195
- package/dist/http/routes/workflows.js +19 -195
- package/dist/http/run-meta.js +0 -6
- package/dist/http/send.js +0 -32
- package/dist/http/server.js +92 -1597
- package/dist/http/sse-lifecycle.js +2 -13
- package/dist/http/sse-log.js +3 -48
- package/dist/http/tar.js +5 -21
- package/dist/http/verify-rounds.js +0 -5
- package/dist/http/wire-gate.js +0 -9
- package/dist/http/workspace-content.js +0 -10
- package/dist/images/bake-validate.js +1 -70
- package/dist/images/manifest.js +1 -6
- package/dist/index.js +0 -21
- package/dist/key-resolver.js +2 -17
- package/dist/leader/diffout.js +1 -20
- package/dist/leader/diffup.js +0 -47
- package/dist/leader/endpoint.js +2 -57
- package/dist/leader/fanout.js +3 -45
- package/dist/leader/grader-env-factory.js +3 -72
- package/dist/leader/leader.js +5 -156
- package/dist/leader/merge.js +8 -115
- package/dist/leader/planner.js +3 -54
- package/dist/leader/repair-oracle.js +1 -60
- package/dist/leader/repair-wire.js +2 -79
- package/dist/leader/wire.js +8 -307
- package/dist/lsp/e2b-bridge.js +4 -64
- package/dist/lsp/e2b-manager.js +6 -94
- package/dist/lsp/lsp-frames.js +0 -12
- package/dist/lsp/manager.js +4 -96
- package/dist/lsp/ws-transport.js +5 -55
- package/dist/lsp-evict.js +1 -15
- package/dist/main.js +57 -765
- package/dist/memory-bundle-engine.js +0 -55
- package/dist/memory-export.js +0 -4
- package/dist/memory-posture.js +1 -15
- package/dist/memory-scope.js +11 -148
- package/dist/memory-sync-client.js +2 -44
- package/dist/memory-sync.js +1 -80
- package/dist/model-select.js +3 -80
- package/dist/observability/cost-quota.js +1 -17
- package/dist/observability/cost-taxonomy.js +0 -34
- package/dist/observability/fail-open.js +7 -86
- package/dist/observability/logger.js +0 -6
- package/dist/observability/metrics.js +0 -94
- package/dist/observability/otel-exporter.js +3 -13
- package/dist/observability/principal-context.js +0 -9
- package/dist/observability/prompt-manifest.js +1 -37
- package/dist/observability/rate-limit.js +0 -4
- package/dist/observability/secret-env-scrub.js +2 -56
- package/dist/observability/tool-trace.js +1 -70
- package/dist/orchestration/hardened-vm-runner.js +4 -118
- package/dist/orchestration/hardened-vm-worker-runner.js +1 -26
- package/dist/orchestration/hardened-vm-worker.js +0 -27
- package/dist/orchestration/subagent-steer.js +1 -45
- package/dist/orchestration/workflow-agent-steer.js +1 -80
- package/dist/orchestration/workflow-completion-inbox.js +32 -285
- package/dist/orchestration/workflow-notify-journal.js +16 -259
- package/dist/org-memory-admission.js +3 -47
- package/dist/parent-watch.js +2 -48
- package/dist/parked-decide.js +1 -109
- package/dist/per-task-image.js +0 -57
- package/dist/plan-cache-probe.js +3 -27
- package/dist/plugins/adoption-log-sql.js +2 -119
- package/dist/plugins/approval-ask-store-memory.js +3 -38
- package/dist/plugins/approval-ask-store-sql.js +6 -188
- package/dist/plugins/approval-exemption-store.js +2 -28
- package/dist/plugins/background-agent-store-sql.js +4 -105
- package/dist/plugins/background-shell-support.js +14 -122
- package/dist/plugins/blob-backend.js +6 -169
- package/dist/plugins/breaker-state-sql.js +8 -46
- package/dist/plugins/caching-session-store.js +4 -106
- package/dist/plugins/checkpoint-store-sql.js +18 -505
- package/dist/plugins/e2b-orphan-reclaim.js +0 -45
- package/dist/plugins/file-outcome-sink.js +0 -9
- package/dist/plugins/file-resume-anchor-store.js +4 -43
- package/dist/plugins/file-run-store.js +26 -364
- package/dist/plugins/file-snapshot-store-sql.js +10 -181
- package/dist/plugins/fork-routing-session-store.js +8 -111
- package/dist/plugins/host-platform.js +2 -91
- package/dist/plugins/image-bake-store-sql.js +7 -250
- package/dist/plugins/image-index-sql.js +4 -123
- package/dist/plugins/k8s-bg-scripts.js +4 -88
- package/dist/plugins/k8s-exec-protocol.js +0 -41
- package/dist/plugins/leader-run-store-sql.js +0 -101
- package/dist/plugins/local-checkpoint-store.js +8 -128
- package/dist/plugins/local-session-store.js +34 -296
- package/dist/plugins/local-task-attachment-store.js +2 -16
- package/dist/plugins/mailbox-store-sql.js +8 -65
- package/dist/plugins/memory-embedder-fingerprint.js +5 -166
- package/dist/plugins/memory-embedder.js +4 -70
- package/dist/plugins/memory-engine-pg.js +6 -170
- package/dist/plugins/memory-engine-tidb.js +7 -155
- package/dist/plugins/memory-engine-vector-util.js +0 -10
- package/dist/plugins/memory-key-guards.js +0 -34
- package/dist/plugins/memory-origin-law.js +0 -187
- package/dist/plugins/memory-resume-anchor-store.js +0 -17
- package/dist/plugins/memory-run-store.js +12 -89
- package/dist/plugins/memory-session-policy-store.js +0 -17
- package/dist/plugins/memory-sync-store-pg.js +4 -49
- package/dist/plugins/memory-sync-store-tidb.js +3 -35
- package/dist/plugins/outcome-ledger-sql.js +3 -97
- package/dist/plugins/permission-rule-store-file.js +5 -133
- package/dist/plugins/permission-rule-store-sql.d.ts +3 -0
- package/dist/plugins/permission-rule-store-sql.js +50 -307
- package/dist/plugins/pg-cost-quota.js +0 -7
- package/dist/plugins/pg-pool.js +0 -92
- package/dist/plugins/pg-rate-limiter.js +2 -13
- package/dist/plugins/pg-safe-json.js +4 -40
- package/dist/plugins/pg-session-storage.js +25 -189
- package/dist/plugins/posix-shell-fs.js +1 -31
- package/dist/plugins/remote-env-adb.js +12 -101
- package/dist/plugins/remote-env-e2b.js +40 -371
- package/dist/plugins/remote-env-file-error.js +0 -37
- package/dist/plugins/remote-env-host.js +63 -483
- package/dist/plugins/remote-env-k8s.js +32 -326
- package/dist/plugins/remote-env-local-docker.js +24 -157
- package/dist/plugins/remote-env-ssh.js +20 -128
- package/dist/plugins/remote-scratchpad.js +2 -32
- package/dist/plugins/remote-shell.js +1 -32
- package/dist/plugins/resume-anchor-store-sql.js +0 -11
- package/dist/plugins/retention-lane-store-sql.js +0 -108
- package/dist/plugins/retention-store-sql.js +4 -383
- package/dist/plugins/roster-store-sql.js +0 -55
- package/dist/plugins/run-store-sql.js +14 -251
- package/dist/plugins/s3-presign.js +2 -49
- package/dist/plugins/scheduler-support.js +3 -80
- package/dist/plugins/send-file-ledger.js +4 -53
- package/dist/plugins/send-user-file.js +4 -94
- package/dist/plugins/session-placement.js +1 -89
- package/dist/plugins/session-policy-store-sql.js +3 -81
- package/dist/plugins/session-store.js +0 -57
- package/dist/plugins/shared-memory-store-sql.js +4 -167
- package/dist/plugins/sql-driver.js +0 -17
- package/dist/plugins/sql-errors.js +0 -7
- package/dist/plugins/sql-escape.js +0 -8
- package/dist/plugins/sql-row-helpers.js +0 -25
- package/dist/plugins/store-backend.js +42 -222
- package/dist/plugins/store-contracts.js +2 -46
- package/dist/plugins/task-attachment-store.js +3 -49
- package/dist/plugins/task-list-store-sql.js +0 -79
- package/dist/plugins/tidb-cost-quota.js +1 -4
- package/dist/plugins/tidb-pool.js +1 -207
- package/dist/plugins/tidb-rate-limiter.js +3 -9
- package/dist/plugins/tidb-session-storage.js +4 -70
- package/dist/plugins/tidb-session-store.js +19 -341
- package/dist/plugins/tool-result-store-sql.js +4 -179
- package/dist/plugins/usage-window-store-sql.js +0 -8
- package/dist/plugins/web-search.js +10 -132
- package/dist/plugins/workflow-journal-store-sql.js +2 -58
- package/dist/plugins/workflow-run-store-sql.js +6 -91
- package/dist/plugins/worktree-isolation.js +6 -126
- package/dist/plugins/write-behind-counter.js +16 -75
- package/dist/principal-jwt.js +5 -60
- package/dist/project-memory.js +15 -146
- package/dist/prompts-domain-validate.js +1 -51
- package/dist/question.js +2 -111
- package/dist/resource-suspend.js +0 -18
- package/dist/router/route-orchestration.js +0 -77
- package/dist/rules-consent.d.ts +44 -5
- package/dist/rules-consent.js +75 -215
- package/dist/run-local.js +14 -381
- package/dist/runs.js +29 -617
- package/dist/runtime-caps-resolver.js +6 -132
- package/dist/runtime-governance.js +1 -232
- package/dist/sandbox-pkg-source.js +0 -37
- package/dist/sealed-key.js +3 -68
- package/dist/security.js +6 -291
- package/dist/session-leaf-bus.js +0 -32
- package/dist/session-sync-content.js +1 -69
- package/dist/session-sync-kernel.js +3 -60
- package/dist/session-sync.js +3 -66
- package/dist/session-titler.js +7 -41
- package/dist/session-watch.js +9 -73
- package/dist/shared-memory-scope-authorizer.js +0 -18
- package/dist/sighup-idle.js +1 -12
- package/dist/spec-fields.js +4 -143
- package/dist/store-live-probe.js +3 -49
- package/dist/task-a2a.js +1 -126
- package/dist/task-cwd.js +1 -103
- package/dist/task-mcp.js +1 -89
- package/dist/task-settings.js +10 -300
- package/dist/task-workflow.js +8 -75
- package/dist/tool-approval.d.ts +28 -1
- package/dist/tool-approval.js +70 -1430
- package/dist/trace/artifacts.js +5 -20
- package/dist/trace/engine-notice-wire.js +6 -138
- package/dist/trace/ledger-sink.js +7 -96
- package/dist/trace/project.js +4 -448
- package/dist/trace/redact.js +9 -77
- package/dist/turn-activity.js +1 -27
- package/dist/usage-analytics.js +4 -34
- package/dist/wall-clock-jump-guard.js +1 -68
- package/package.json +3 -3
- package/dist/capabilities/scenario-alias.d.ts +0 -27
- package/dist/capabilities/scenario-alias.js +0 -61
|
@@ -2,11 +2,8 @@ import { SHARED_MEMORY_READ_CAP_BYTES, SharedMemoryStoreError } from "@sema-agen
|
|
|
2
2
|
import { sendJson, sendError } from "../send.js";
|
|
3
3
|
import { gatedPrincipal } from "../principal-gate.js";
|
|
4
4
|
const PREFIX = "/v1/shared-memory/";
|
|
5
|
-
/** `unavailable` 时给客户端的重试间隔。目录退避窗与库导入都在秒级,10s 是"别打穿"与"别显得死了"之间。 */
|
|
6
5
|
const RETRY_AFTER_SEC = 10;
|
|
7
|
-
/** 一次 documents 列举的窗口。core 的模型面用 50;HTTP 面给同一个数量级,靠 cursor 续窗。 */
|
|
8
6
|
const HTTP_LIST_LIMIT = 100;
|
|
9
|
-
/** core 的文档路径规则,HTTP 参数面复述:绝对、无控制字符/反斜杠、段非空且不以 `.` 开头、文件名带后缀。 */
|
|
10
7
|
const FORBIDDEN_PATH_CHARS = /[\p{Cc}\p{Cf}\p{Co}\p{Cn}\p{Default_Ignorable_Code_Point}\u2028\u2029\\]/u;
|
|
11
8
|
const DOCUMENT_SUFFIXES = [".md", ".txt", ".json", ".jsonl"];
|
|
12
9
|
function isDocumentPath(path) {
|
|
@@ -18,13 +15,9 @@ function isDocumentPath(path) {
|
|
|
18
15
|
return false;
|
|
19
16
|
return DOCUMENT_SUFFIXES.some((s) => last.endsWith(s));
|
|
20
17
|
}
|
|
21
|
-
/** 零存在性 oracle 的那**一句**拒绝。三种成因(库不存在 / 不是成员 / 是别的 org 的库)共用它,因此
|
|
22
|
-
* 调用方无法用响应差异枚举别人的库。改这里的字面量时三条腿一起改——它们同形是**被测断言**。 */
|
|
23
18
|
function refuseStore(res) {
|
|
24
19
|
sendError(res, 404, "not_found.shared_memory_store", "not found");
|
|
25
20
|
}
|
|
26
|
-
/** 供给面自述不可用 ⇒ 503 + Retry-After。**绝不**塌成「200 空库」:后者对调用方是终局的
|
|
27
|
-
* 「你们团队没有共享库」,而真相是「暂时读不到,一会儿再来」——两句话是相反的指令。 */
|
|
28
21
|
function refuseUnavailable(res, message) {
|
|
29
22
|
res.setHeader("retry-after", String(RETRY_AFTER_SEC));
|
|
30
23
|
sendError(res, 503, "memory.shared_unavailable", "shared memory stores are unavailable", {
|
|
@@ -32,18 +25,15 @@ function refuseUnavailable(res, message) {
|
|
|
32
25
|
...(message !== undefined ? { detail: message } : {}),
|
|
33
26
|
});
|
|
34
27
|
}
|
|
35
|
-
/** 取本次请求的绑定快照。返回 `undefined` = 已经应答(401/503),调用方直接 return。 */
|
|
36
28
|
async function bindSnapshot(req, res, ctx) {
|
|
37
29
|
const { deps } = ctx;
|
|
38
|
-
|
|
39
|
-
const principal = gatedPrincipal(req, deps.config); // direct-door safe: verified identity, never the spoofable header
|
|
30
|
+
const principal = gatedPrincipal(req, deps.config);
|
|
40
31
|
if (!principal && deps.config.requirePrincipal === true) {
|
|
41
32
|
sendError(res, 401, "auth.unauthorized", "unauthorized");
|
|
42
33
|
return undefined;
|
|
43
34
|
}
|
|
44
35
|
const provider = deps.sharedMemoryStore;
|
|
45
36
|
if (!provider) {
|
|
46
|
-
// 到不了:域头的合取式已经保证它在场。写出来是为了让类型收窄不靠断言。
|
|
47
37
|
refuseStore(res);
|
|
48
38
|
return undefined;
|
|
49
39
|
}
|
|
@@ -54,30 +44,18 @@ async function bindSnapshot(req, res, ctx) {
|
|
|
54
44
|
}
|
|
55
45
|
return snapshot;
|
|
56
46
|
}
|
|
57
|
-
/**
|
|
58
|
-
* reader 抛出的 **typed** 失败 → HTTP 的逐格映射。返回 `true` = 已应答。
|
|
59
|
-
*
|
|
60
|
-
* 🔴 codex 复审轮2 F2(真缺陷):不折叠的话这些全落进外层兜底的 500 `internal.error`。而它们**不是**
|
|
61
|
-
* 服务器缺陷:`store_not_found` 是治理面在绑定之后回收了库(正常竞态),`refused/document_too_large`
|
|
62
|
-
* 是一行旧数据(可恢复状况)。更要命的是——真 SQL 供给面对超帽行是**抛**而不是返回内容,所以本文件
|
|
63
|
-
* 那条 413 分支对它根本不可达,除非在这里折。
|
|
64
|
-
*
|
|
65
|
-
* `kind` 是 core 的闭集,用穷举 `switch` 消费:core 加员时这里当场编译红,而不是悄悄落进某个 default。
|
|
66
|
-
*/
|
|
67
47
|
function foldReaderError(res, err) {
|
|
68
48
|
if (!(err instanceof SharedMemoryStoreError))
|
|
69
49
|
return false;
|
|
70
50
|
switch (err.kind) {
|
|
71
51
|
case "store_not_found":
|
|
72
|
-
refuseStore(res);
|
|
52
|
+
refuseStore(res);
|
|
73
53
|
return true;
|
|
74
54
|
case "refused":
|
|
75
55
|
if (err.reason === "document_too_large") {
|
|
76
|
-
// 与模型面同一条规则:拒绝,不截断(一份被截断的共享文档读起来和完整的一模一样)。
|
|
77
56
|
sendError(res, 413, "request.payload_too_large", `document exceeds the ${SHARED_MEMORY_READ_CAP_BYTES}-byte shared-store read cap`, { capBytes: SHARED_MEMORY_READ_CAP_BYTES });
|
|
78
57
|
return true;
|
|
79
58
|
}
|
|
80
|
-
// host 自述的其它拒绝(配额等):按"现在读不到,带着机器原因重试"回,原因原样进 detail。
|
|
81
59
|
refuseUnavailable(res, err.reason);
|
|
82
60
|
return true;
|
|
83
61
|
case "transient":
|
|
@@ -85,10 +63,9 @@ function foldReaderError(res, err) {
|
|
|
85
63
|
return true;
|
|
86
64
|
}
|
|
87
65
|
}
|
|
88
|
-
/** 快照里解析一个 store,越界返回 `undefined` 并已应答 404(同形拒)。 */
|
|
89
66
|
function resolveStore(res, snapshot, storeId) {
|
|
90
67
|
if (snapshot.state !== "connected") {
|
|
91
|
-
refuseStore(res);
|
|
68
|
+
refuseStore(res);
|
|
92
69
|
return undefined;
|
|
93
70
|
}
|
|
94
71
|
const found = snapshot.stores.find((s) => s.info.id === storeId);
|
|
@@ -104,15 +81,11 @@ export async function handleSharedMemory(req, res, url, ctx) {
|
|
|
104
81
|
return !miss.fell;
|
|
105
82
|
}
|
|
106
83
|
async function handleSharedMemoryBody(req, res, url, ctx, miss) {
|
|
107
|
-
// GET /v1/shared-memory/stores —— 本会话可见的库清单(= 模型面 memory_list 无参形的同一份)。
|
|
108
84
|
if (url === "/v1/shared-memory/stores" && req.method === "GET") {
|
|
109
85
|
const snapshot = await bindSnapshot(req, res, ctx);
|
|
110
86
|
if (!snapshot)
|
|
111
87
|
return;
|
|
112
88
|
if (snapshot.state !== "connected") {
|
|
113
|
-
// 诚实的「还没好」:既不是错误(没坏)也不是空(不是终局)。与 core 模型面的 CONNECTING 同义。
|
|
114
|
-
// (`unavailable` 已在 bindSnapshot 里 503 掉,走不到这里;判 `!== "connected"` 是为了让类型
|
|
115
|
-
// 收窄不靠断言 —— 联合加员时这里当场编译红,而不是悄悄落进某个 else。)
|
|
116
89
|
sendJson(res, 200, { state: "connecting", stores: [] });
|
|
117
90
|
return;
|
|
118
91
|
}
|
|
@@ -121,10 +94,9 @@ async function handleSharedMemoryBody(req, res, url, ctx, miss) {
|
|
|
121
94
|
}
|
|
122
95
|
const rest = url.startsWith(PREFIX) ? url.slice(PREFIX.length) : undefined;
|
|
123
96
|
const segments = rest === undefined ? [] : rest.split("/");
|
|
124
|
-
// stores/:store/documents | stores/:store/document
|
|
125
97
|
if (segments.length === 3 && segments[0] === "stores" && req.method === "GET" && (segments[2] === "documents" || segments[2] === "document")) {
|
|
126
98
|
const storeId = decodeURIComponent(segments[1]);
|
|
127
|
-
const query = new URL(req.url ?? "", "http://x").searchParams;
|
|
99
|
+
const query = new URL(req.url ?? "", "http://x").searchParams;
|
|
128
100
|
const snapshot = await bindSnapshot(req, res, ctx);
|
|
129
101
|
if (!snapshot)
|
|
130
102
|
return;
|
|
@@ -137,7 +109,7 @@ async function handleSharedMemoryBody(req, res, url, ctx, miss) {
|
|
|
137
109
|
const page = await reader.list(prefix, { ...(cursor !== undefined ? { cursor } : {}), limit: HTTP_LIST_LIMIT }).catch((err) => {
|
|
138
110
|
if (foldReaderError(res, err))
|
|
139
111
|
return undefined;
|
|
140
|
-
throw err;
|
|
112
|
+
throw err;
|
|
141
113
|
});
|
|
142
114
|
if (page === undefined)
|
|
143
115
|
return;
|
|
@@ -162,14 +134,11 @@ async function handleSharedMemoryBody(req, res, url, ctx, miss) {
|
|
|
162
134
|
if (folded)
|
|
163
135
|
return;
|
|
164
136
|
if (doc === null) {
|
|
165
|
-
// 成员本人有权区分「打错了路径」与「无权」——见文件头注。
|
|
166
137
|
sendError(res, 404, "not_found.shared_memory_document", "not found");
|
|
167
138
|
return;
|
|
168
139
|
}
|
|
169
140
|
const bytes = Buffer.byteLength(doc.content, "utf8");
|
|
170
141
|
if (bytes > SHARED_MEMORY_READ_CAP_BYTES) {
|
|
171
|
-
// core 的模型面对超帽文档是**拒绝并报出真实大小**,从不截断(一份被截断的共享文档读起来和完整的
|
|
172
|
-
// 一模一样,而那正是这个帽存在的理由)。HTTP 面用同一条规则,两个面因此对「什么读得到」永不分歧。
|
|
173
142
|
sendError(res, 413, "request.payload_too_large", `document is ${bytes} bytes, over the ${SHARED_MEMORY_READ_CAP_BYTES}-byte shared-store read cap`, { bytes, capBytes: SHARED_MEMORY_READ_CAP_BYTES });
|
|
174
143
|
return;
|
|
175
144
|
}
|
|
@@ -4,56 +4,11 @@ import { isModelAllowlisted } from "../../model-select.js";
|
|
|
4
4
|
import { redactSecrets } from "../../trace/redact.js";
|
|
5
5
|
import { sendJson, sendError, httpErrorCode, msg } from "../send.js";
|
|
6
6
|
import { gatedPrincipal } from "../principal-gate.js";
|
|
7
|
-
/**
|
|
8
|
-
* A-002.2 —— core 前置校验异常的分类词表(400 客户端可改 / 500 我方缺陷)。
|
|
9
|
-
*
|
|
10
|
-
* 🔴 **亲验记账(core 5.x dist,本批复核)**:core 在这条路径上抛的是**裸 `Error`**,异常对象上
|
|
11
|
-
* 没有 `code`/`name`/`status` 任何结构化判别位 ——
|
|
12
|
-
* · `core/roles.js:8` `throw new Error(\`Unknown model ref "\${ref}". …\`)`
|
|
13
|
-
* · `core/roles.js:179` `throw new Error(\`No model for role "\${start}": …\`)`
|
|
14
|
-
* 所以「优先消费结构化位、正则降兜底」在当前 core 上**无位可消费**:这里如实停在文案匹配,并把跨仓
|
|
15
|
-
* 耦合交给一道机器门看着 —— test/side-query-http.test.ts 的「A-002.2 跨仓锚」**调装机 core 的两个导出
|
|
16
|
-
* 解析器把异常真抛出来**,拿真 message 过本谓词。
|
|
17
|
-
* 🔴 为什么不是「扫 core 源码里有没有这两句字面」:那种锚有一个致命假绿形(codex 复审 medium,已采纳)
|
|
18
|
-
* ——core 完全可以保留字面却在抛出时加前缀/包一层,源码锚照绿而 `startsWith` 当场失效,客户端错误静默
|
|
19
|
-
* 变成 500。真抛出预言机没有这个缝(它当场就揪出了下面 `modelRole` 那条连带缺陷)。
|
|
20
|
-
* core 哪天给这两处加了 code,本函数就该改成读那个 code、文案匹配退成兜底 —— 那道门会先红,提醒动这里。
|
|
21
|
-
*
|
|
22
|
-
* 🪦 **第三臂已删(死支确认)**:原表还有 `requires a non-empty messages array`(core
|
|
23
|
-
* `core/side-query.js:10`)。它**不可达** —— 本路由在调 core 之前就有
|
|
24
|
-
* `!Array.isArray(body.messages) || body.messages.length === 0 ⇒ 400 request.body_shape` 的前拦
|
|
25
|
-
* (见下方路由体),两个条件与 core 那条判据逐字同集,所以 core 那句永远轮不到抛。留着=养一条永假的
|
|
26
|
-
* 分支,删了并立此墓碑;前拦一旦被摘,side-query-http 的「空/非数组 messages → 400 request.body_shape」
|
|
27
|
-
* 两格先红。
|
|
28
|
-
*
|
|
29
|
-
* 失败方向:表外一律 500(响亮、可告警、可重试),绝不把不认识的异常猜成客户端错误。
|
|
30
|
-
*/
|
|
31
7
|
const CORE_PREFLIGHT_VALIDATION_PREFIXES = ["Unknown model ref ", "No model for role "];
|
|
32
|
-
/** 表内=core 的前置校验形(客户端可改请求)⇒ 400;表外一律 500。 */
|
|
33
8
|
export function isCorePreflightValidationError(message) {
|
|
34
9
|
return CORE_PREFLIGHT_VALIDATION_PREFIXES.some((prefix) => message.startsWith(prefix));
|
|
35
10
|
}
|
|
36
|
-
/** 供跨仓锚门读:门要拿这张表去装机的 core 里逐条对账(见上方 doc)。 */
|
|
37
11
|
export const CORE_PREFLIGHT_VALIDATION_ANCHORS = CORE_PREFLIGHT_VALIDATION_PREFIXES;
|
|
38
|
-
/**
|
|
39
|
-
* A-002.2 连带 —— `modelRole` 的**选路可达性**门。
|
|
40
|
-
*
|
|
41
|
-
* 🔴 由来(A-002.2 的真抛出预言机当场揪出来的,源码扫描锚与 mock 都照不到):core 的 `ModelRole` 是
|
|
42
|
-
* 闭集(8 值),而 core 的 `resolveTaskModel` 在**无显式 model** 时要走 `FALLBACK[start]` —— 表外角色
|
|
43
|
-
* 在那张表里是 `undefined`,于是真抛 `TypeError: FALLBACK[start] is not iterable`。一条**客户端可改**的
|
|
44
|
-
* 输入错误,以「服务器内部错误 + 可重试」的面目回给客户端;而且这一条连 400/500 分类都救不了(那句
|
|
45
|
-
* TypeError 文案里没有任何可分类的痕迹)。所以拒在本层。
|
|
46
|
-
*
|
|
47
|
-
* ⚠️ **只在这个字段真参与选路时才拒**(codex 复审 R2 medium,已采纳并收窄):`spec.model` 在场时
|
|
48
|
-
* `resolveTaskModel` 走**短路分支**,压根不碰 `FALLBACK` —— `{model:"<有效 ref>", modelRole:"cheap"}`
|
|
49
|
-
* 是一条**今天就能跑通**的既有形,而 SDK 的 `SideQueryRequest.modelRole` 又逐字声明为开放 `string`
|
|
50
|
-
* (spec/openapi.yaml)。对它一并拒 = 无版本协商地收窄已发布契约。首版正是这么写的,复审逮到。
|
|
51
|
-
* 同理也不能「有 model 时把表外角色丢掉」:core 会拿 `merged[start]` 取该角色上的 thinking/systemPrompt
|
|
52
|
-
* (`runSideQuery` 里 `spec.systemPrompt ?? resolved.systemPrompt`),丢掉它会让配置好的 `default` 角色的
|
|
53
|
-
* systemPrompt 意外生效 —— 那也是行为改动。⇒ 有 model 时**原样透传**,行为逐字不变。
|
|
54
|
-
*
|
|
55
|
-
* 表是 `Record<ModelRole, true>` 穷举:core 增删一个角色词,本表编译期先红(闭集词表的成文纪律)。
|
|
56
|
-
*/
|
|
57
12
|
const MODEL_ROLE_TABLE = {
|
|
58
13
|
default: true,
|
|
59
14
|
summarize: true,
|
|
@@ -64,16 +19,9 @@ const MODEL_ROLE_TABLE = {
|
|
|
64
19
|
verifier: true,
|
|
65
20
|
classifier: true,
|
|
66
21
|
};
|
|
67
|
-
/** 表内 ⇒ 收窄成 `ModelRole`(类型守卫)。门用它判「这个角色能不能自己选出模型」。 */
|
|
68
22
|
function isModelRole(value) {
|
|
69
23
|
return typeof value === "string" && Object.hasOwn(MODEL_ROLE_TABLE, value);
|
|
70
24
|
}
|
|
71
|
-
/**
|
|
72
|
-
* 线上契约(SDK `SideQueryRequest.modelRole: string`)比 core 的 `ModelRole` 闭集**宽**,而 core 对该字段的
|
|
73
|
-
* 实际用法是**开放键查表**(`mergeRoles(...)[start]`,查不到即空)——所以表外值在有显式 model 时是合法且
|
|
74
|
-
* 惰性的。这处窄化断言是那道宽窄差的**唯一**落点(其余路径已由上面的门挡住),集中在此并说明缘由,
|
|
75
|
-
* 而不是散在装配字面量里当作无声的裸 cast。
|
|
76
|
-
*/
|
|
77
25
|
function passthroughModelRole(value) {
|
|
78
26
|
return value;
|
|
79
27
|
}
|
|
@@ -82,21 +30,10 @@ export async function handleSideQuery(req, res, url, ctx) {
|
|
|
82
30
|
await handleSideQueryBody(req, res, url, ctx, miss);
|
|
83
31
|
return !miss.fell;
|
|
84
32
|
}
|
|
85
|
-
/** 路由体 = 从 `server.ts` 的 `handle()` 里**整段剪切**过来的原文(唯一改动:统一去缩进两格)。 */
|
|
86
33
|
async function handleSideQueryBody(req, res, url, ctx, miss) {
|
|
87
34
|
const { deps } = ctx;
|
|
88
35
|
const { readJson, rateLimited, quotaExceeded, leaseDenied } = ctx.helpers;
|
|
89
|
-
// Synchronous task endpoints.
|
|
90
|
-
// [1469] sideQuery verb(core 1.361 提货单):一次性 brain 路由问答——无 session/无工具执行/无 policy
|
|
91
|
-
// gate/无引擎侧记账/无流式(v1 刻意面=core 规格,side-query.d.ts)。cli 壳侧 15+ utility(标题/摘要/
|
|
92
|
-
// 权限解释…)的传输层正解([1463]①/[1467] P0 提升 P1)。鉴权同任务面:全局 service-credential 门
|
|
93
|
-
// (本路由在门后)+ isBillableSubmitPath 已含(no-token 503 fail-closed/draining/model-ready 三闸)+
|
|
94
|
-
// rate/quota 双闸 + requirePrincipal 缺 principal=401。断连即弃(anti token-burn,交互 Esc 契约同款)。
|
|
95
|
-
// 字段白名单透传(signal 为 server 属地;未知键丢弃=前向兼容);messages 逐条形不在这拆——core
|
|
96
|
-
// runSideQuery 是唯一语义源,server 只把明显垃圾(非数组/空)挡在 brain 调用前。
|
|
97
36
|
if (req.method === "POST" && url === "/v1/side-query") {
|
|
98
|
-
// 断连即弃:listener 必须在**任何 await 之前**挂上(codex 复审 medium:close 事件不回放——body 读取
|
|
99
|
-
// 期间断连若错过监听,brain 调用就带着活 signal 白烧 token)。
|
|
100
37
|
const ac = new AbortController();
|
|
101
38
|
const onClose = () => ac.abort();
|
|
102
39
|
res.on("close", onClose);
|
|
@@ -128,18 +65,10 @@ async function handleSideQueryBody(req, res, url, ctx, miss) {
|
|
|
128
65
|
sendError(res, 400, "request.field_invalid", "invalid thinking level");
|
|
129
66
|
return;
|
|
130
67
|
}
|
|
131
|
-
// 选路可达性门(见 MODEL_ROLE_TABLE 顶注):**仅当该字段真参与选路**(无显式 model)时,表外角色
|
|
132
|
-
// 才 fail-closed 在这里 —— 那条路上 core 抛的是无从分类的 TypeError,400/500 分类救不回来。
|
|
133
|
-
// 有显式 model ⇒ core 走短路分支,该值惰性,原样透传(既有可用形,不许无版本协商地收窄)。
|
|
134
68
|
if (typeof body.model !== "string" && body.modelRole !== undefined && !isModelRole(body.modelRole)) {
|
|
135
69
|
sendError(res, 400, "request.field_invalid", `invalid modelRole (expected one of: ${Object.keys(MODEL_ROLE_TABLE).join(", ")}) — a role only resolves a model when 'model' is absent`);
|
|
136
70
|
return;
|
|
137
71
|
}
|
|
138
|
-
// #233 / A-002.8 第三执法点 —— side-query 的 `body.model` 是**计费提交面**上的用户逐 turn 选择
|
|
139
|
-
// 通道(直透传给 core 的路由),与任务面 `body.model` 同名单同拒形。归一走同一只
|
|
140
|
-
// `isModelAllowlisted`(增广目录:档位词/CC 别名/id 与 name 指同一只模型时不许绕门)。
|
|
141
|
-
// 不受限的是 `modelRole`(operator 的角色表选路,不是用户点的模型)——两者的辖域线与任务面一致。
|
|
142
|
-
// 本路由无 resume 腿(一次性问答),故只有 fresh 拒这一支。
|
|
143
72
|
if (typeof body.model === "string" && body.model.length > 0) {
|
|
144
73
|
const bare = deps.config.models ?? {};
|
|
145
74
|
const catalog = expandTiers(bare, deps.config.tiers ?? {}) ?? bare;
|
|
@@ -149,7 +78,7 @@ async function handleSideQueryBody(req, res, url, ctx, miss) {
|
|
|
149
78
|
}
|
|
150
79
|
}
|
|
151
80
|
if (ac.signal.aborted)
|
|
152
|
-
return;
|
|
81
|
+
return;
|
|
153
82
|
const spec = {
|
|
154
83
|
messages: body.messages,
|
|
155
84
|
...(typeof body.model === "string" ? { model: body.model } : {}),
|
|
@@ -161,18 +90,7 @@ async function handleSideQueryBody(req, res, url, ctx, miss) {
|
|
|
161
90
|
signal: ac.signal,
|
|
162
91
|
};
|
|
163
92
|
try {
|
|
164
|
-
// #303:**不走** `deps.runner.sideQuery` —— core 的 SideQuerySpec 没有 key 座位,那条路恒把
|
|
165
|
-
// brain 构造时的网关 key 发到模型自己的 baseUrl(上游 401 + 凭据外泄形)。`deps.sideQuery` =
|
|
166
|
-
// boot/side-query-lane.ts 装配的执行席(真 runSideQuery + per-model key 注入 brain wrapper),
|
|
167
|
-
// 结果形逐字同 core 规格。poison(sealed key 不可解)在这里以异常上抛 ⇒ 落下面 500 臂(响亮),
|
|
168
|
-
// 绝不静默用网关 key 顶上。
|
|
169
93
|
const result = await deps.sideQuery(spec);
|
|
170
|
-
// 记账(codex R2 high→R3 收敛):走与 createTracer 同源装配的四路 sink seam(costQuota+指标+
|
|
171
|
-
// fleetUsage 批报+fleetLease 本地扣减)——sideQuery 不发 brain.call,tracer 链不经过这里。
|
|
172
|
-
// usageMissing/无 cost 面=0 记账,诚实缺席。
|
|
173
|
-
// #257:曾经这里在请求前拍 catalog 快照、按 Model 判 cache family 传给记账口(codex R4-R6 三轮
|
|
174
|
-
// 打磨的判定链)——整链随 #257 退役:core 在 side-query 出口已把 `usage.input` 归一为 uncached 量
|
|
175
|
-
// (每个 provider 族,side-query.d.ts 成文),折算恒 input+cacheRead+cacheWrite,family 不再是记账输入。
|
|
176
94
|
const rr = result;
|
|
177
95
|
const modelId = typeof rr.model === "string" ? rr.model : "unknown";
|
|
178
96
|
deps.sideQueryAccounting?.(principal, { model: modelId, usage: rr.usage });
|
|
@@ -181,14 +99,10 @@ async function handleSideQueryBody(req, res, url, ctx, miss) {
|
|
|
181
99
|
sendJson(res, 200, result);
|
|
182
100
|
}
|
|
183
101
|
catch (e) {
|
|
184
|
-
// 400 仅限 core 前置校验的**已知形**;其余异常=server/adapter/config 缺陷,走 500(可告警、可重试
|
|
185
|
-
// 语义)。stream 后错误按契约进 result.errorMessage 不 throw;断连 abort 的抛出无人收,
|
|
186
|
-
// writableEnded/aborted 双判后静默。
|
|
187
102
|
deps.metrics?.inc?.("side_query_total", { result: "error" });
|
|
188
103
|
if (!res.writableEnded && !ac.signal.aborted) {
|
|
189
104
|
const m = msg(e);
|
|
190
105
|
const isValidation = isCorePreflightValidationError(m);
|
|
191
|
-
// B7:机器码随状态码同分——已知前置校验形=`request.field_invalid`(客户端可改请求),其余=`internal.error`。
|
|
192
106
|
sendError(res, isValidation ? 400 : 500, isValidation ? "request.field_invalid" : "internal.error", redactSecrets(m));
|
|
193
107
|
}
|
|
194
108
|
}
|