@ftai/dsh-plugin-acn 0.0.0-stage → 0.1.1
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/CHANGELOG.md +90 -0
- package/LICENSE-APACHE +201 -0
- package/LICENSE-MIT +19 -0
- package/README.md +82 -2
- package/README_EN.md +83 -0
- package/cordis.patch.yml +29 -0
- package/docs/acn-compat.md +33 -0
- package/docs/architecture.md +130 -0
- package/docs/assets/acn-claim-reuse.png +0 -0
- package/docs/assets/activity-view.png +0 -0
- package/docs/assets/install-package.png +0 -0
- package/docs/assets/knowledge-model.png +0 -0
- package/docs/assets/knowledge-view.png +0 -0
- package/docs/assets/personal-configuration.png +0 -0
- package/docs/assets/session-upstream.png +0 -0
- package/docs/assets/upstream-settings.png +0 -0
- package/docs/assets/upstream-team.png +0 -0
- package/docs/command-reference.md +201 -0
- package/docs/config.md +253 -0
- package/docs/development.md +197 -0
- package/docs/dsh-compat.md +59 -0
- package/docs/index.md +16 -0
- package/docs/outstanding-issues.md +61 -0
- package/docs/user_guide.md +185 -0
- package/icon.svg +8 -0
- package/lib/activities-B8U-iW4-.js +407 -0
- package/lib/alignment-CwH0nBf-.js +80 -0
- package/lib/auth-DFI9yowX.js +71 -0
- package/lib/checkpoint-CPFPOxBM.js +188 -0
- package/lib/checkpoint-c7aI4D-X.js +318 -0
- package/lib/claim-DOAGe8ZK.js +168 -0
- package/lib/client.js +18417 -0
- package/lib/deliver-C-dmhkfm.js +168 -0
- package/lib/delivery-status-M7-Rwoyj.js +89 -0
- package/lib/dispute-CtrInHzf.js +20 -0
- package/lib/disputes-ByEmi43j.js +51 -0
- package/lib/dream-agent-BVqxbKFc.js +249 -0
- package/lib/dream.js +4 -0
- package/lib/effects-DX1iy6FM.js +268 -0
- package/lib/errors-Bp_2WXBr.js +19 -0
- package/lib/errors-pPumDOGD.js +18 -0
- package/lib/evidence-store-DW7kj20i.js +1030 -0
- package/lib/formation-D4LO31WW.js +187 -0
- package/lib/formation-replay-Bf4TSBiz.js +87 -0
- package/lib/formation.js +9 -0
- package/lib/history-DPMHX3ZE.js +214 -0
- package/lib/inbox-2CugZZQm.js +188 -0
- package/lib/inbox-DFtE2fOp.js +71 -0
- package/lib/inbox.js +3 -0
- package/lib/index.js +1373 -0
- package/lib/lock-DbmlKOoX.js +332 -0
- package/lib/pages-BEWC3kmZ.js +51 -0
- package/lib/paths-B7NI9Ano.js +157 -0
- package/lib/plugins/commands.js +590 -0
- package/lib/plugins/dream.js +66 -0
- package/lib/plugins/formation.js +66 -0
- package/lib/plugins/inbox.js +53 -0
- package/lib/plugins/knowledge.js +1109 -0
- package/lib/plugins/prompt.js +102 -0
- package/lib/plugins/tools.js +280 -0
- package/lib/policy-DnyHh7Bl.js +16 -0
- package/lib/prepare-CGXwBEcu.js +134 -0
- package/lib/protocol.js +8 -0
- package/lib/queue-M917xHPS.js +153 -0
- package/lib/regular-file-BFpqMoub.js +136 -0
- package/lib/render-CJaVcKKC.js +48 -0
- package/lib/reported-sets-DdEKdeVb.js +122 -0
- package/lib/revision-DeoL_IUN.js +11 -0
- package/lib/scheduler-BfJSY1eq.js +64 -0
- package/lib/service-BPwaZzFF.js +1106 -0
- package/lib/service-BQaszW_v.js +344 -0
- package/lib/service-BhniAHLo.js +305 -0
- package/lib/service-C2lXoygJ.js +505 -0
- package/lib/session-binding-zCSuizHs.js +342 -0
- package/lib/session-state-CYqUhC95.js +38 -0
- package/lib/sessions-C2xuPFQv.js +218 -0
- package/lib/store.js +16 -0
- package/lib/structured-C9byFuzm.js +453 -0
- package/lib/subagent-yJsFxHmH.js +9 -0
- package/lib/team.js +3 -0
- package/lib/tool-schema-3b4gH1zf.js +28 -0
- package/lib/trace-Da0RnL5R.js +14 -0
- package/lib/traces-CHBo8y1z.js +11 -0
- package/lib/types/activities.d.ts +73 -0
- package/lib/types/advanced-configuration.d.ts +11 -0
- package/lib/types/client/ActivityCard.d.ts +14 -0
- package/lib/types/client/ActivityDetails.d.ts +18 -0
- package/lib/types/client/AdvancedPreferences.d.ts +8 -0
- package/lib/types/client/BlankCommandFeedback.d.ts +10 -0
- package/lib/types/client/ComposerMenu.d.ts +24 -0
- package/lib/types/client/ConfigurationPage.d.ts +11 -0
- package/lib/types/client/ConnectionCheckDialog.d.ts +12 -0
- package/lib/types/client/KnowledgeDetail.d.ts +6 -0
- package/lib/types/client/KnowledgeDirectoryField.d.ts +11 -0
- package/lib/types/client/KnowledgePanel.d.ts +12 -0
- package/lib/types/client/KnowledgeReference.d.ts +13 -0
- package/lib/types/client/SessionToolbar.d.ts +16 -0
- package/lib/types/client/SettingsToast.d.ts +3 -0
- package/lib/types/client/SourceSessionLink.d.ts +16 -0
- package/lib/types/client/TeamCredentialField.d.ts +16 -0
- package/lib/types/client/TeamSettingsPage.d.ts +28 -0
- package/lib/types/client/configuration-errors.d.ts +2 -0
- package/lib/types/client/interaction-styles.d.ts +1 -0
- package/lib/types/client/interaction-ui.d.ts +30 -0
- package/lib/types/client/knowledge-labels.d.ts +5 -0
- package/lib/types/client/locales.d.ts +51 -0
- package/lib/types/commands/claim.d.ts +4 -0
- package/lib/types/commands/import.d.ts +10 -0
- package/lib/types/commands/status.d.ts +5 -0
- package/lib/types/config.d.ts +111 -0
- package/lib/types/configuration.d.ts +235 -0
- package/lib/types/credentials.d.ts +59 -0
- package/lib/types/dream/audit.d.ts +4 -0
- package/lib/types/dream/autonomous.d.ts +185 -0
- package/lib/types/dream/candidates.d.ts +34 -0
- package/lib/types/dream/checkpoint.d.ts +35 -0
- package/lib/types/dream/evidence-files.d.ts +10 -0
- package/lib/types/dream/evidence-store.d.ts +103 -0
- package/lib/types/dream/evidence.d.ts +30 -0
- package/lib/types/dream/index.d.ts +10 -0
- package/lib/types/dream/plan.d.ts +18 -0
- package/lib/types/dream/preservation.d.ts +6 -0
- package/lib/types/dream/review.d.ts +10 -0
- package/lib/types/dream/schema.d.ts +1475 -0
- package/lib/types/dream/service.d.ts +56 -0
- package/lib/types/dream/sync.d.ts +147 -0
- package/lib/types/dsh-adapter/configuration-remote.d.ts +1 -0
- package/lib/types/dsh-adapter/configuration-service.d.ts +28 -0
- package/lib/types/dsh-adapter/dream-agent.d.ts +4 -0
- package/lib/types/dsh-adapter/dream-evidence.d.ts +3 -0
- package/lib/types/dsh-adapter/formation-archive.d.ts +3 -0
- package/lib/types/dsh-adapter/formation-replay.d.ts +5 -0
- package/lib/types/dsh-adapter/formation.d.ts +4 -0
- package/lib/types/dsh-adapter/interaction-service.d.ts +13 -0
- package/lib/types/dsh-adapter/knowledge-paths.d.ts +3 -0
- package/lib/types/dsh-adapter/llm.d.ts +10 -0
- package/lib/types/dsh-adapter/project-upstream.d.ts +4 -0
- package/lib/types/dsh-adapter/runtime-pool.d.ts +110 -0
- package/lib/types/dsh-adapter/session-binding.d.ts +43 -0
- package/lib/types/dsh-adapter/source-sessions.d.ts +3 -0
- package/lib/types/dsh-adapter/team-credentials.d.ts +5 -0
- package/lib/types/dsh-adapter/tool-schema.d.ts +4 -0
- package/lib/types/dsh-adapter/tools.d.ts +5 -0
- package/lib/types/formation/capture.d.ts +19 -0
- package/lib/types/formation/checkpoint.d.ts +136 -0
- package/lib/types/formation/index.d.ts +10 -0
- package/lib/types/formation/prepare.d.ts +16 -0
- package/lib/types/formation/schema.d.ts +45 -0
- package/lib/types/formation/service.d.ts +58 -0
- package/lib/types/formation/transcript.d.ts +75 -0
- package/lib/types/formation/triggers.d.ts +3 -0
- package/lib/types/inbox/cascade.d.ts +3 -0
- package/lib/types/inbox/effects.d.ts +275 -0
- package/lib/types/inbox/index.d.ts +5 -0
- package/lib/types/inbox/prepare.d.ts +380 -0
- package/lib/types/inbox/service.d.ts +26 -0
- package/lib/types/inbox/sync.d.ts +9 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/interaction-messages.d.ts +69 -0
- package/lib/types/interaction.d.ts +541 -0
- package/lib/types/knowledge/alignment.d.ts +49 -0
- package/lib/types/knowledge/catalog.d.ts +5 -0
- package/lib/types/knowledge/changes.d.ts +32 -0
- package/lib/types/knowledge/disputes.d.ts +3 -0
- package/lib/types/knowledge/errors.d.ts +9 -0
- package/lib/types/knowledge/ordering.d.ts +7 -0
- package/lib/types/knowledge/pages.d.ts +7 -0
- package/lib/types/knowledge/safety.d.ts +2 -0
- package/lib/types/knowledge/service.d.ts +52 -0
- package/lib/types/knowledge/sessions.d.ts +59 -0
- package/lib/types/knowledge/sources.d.ts +2 -0
- package/lib/types/knowledge/timestamps.d.ts +1 -0
- package/lib/types/knowledge/types.d.ts +84 -0
- package/lib/types/llm/response.d.ts +1 -0
- package/lib/types/llm/structured.d.ts +27 -0
- package/lib/types/local-name.d.ts +1 -0
- package/lib/types/plugins/client.d.ts +9 -0
- package/lib/types/plugins/commands.d.ts +11 -0
- package/lib/types/plugins/configuration.d.ts +8 -0
- package/lib/types/plugins/dream.d.ts +16 -0
- package/lib/types/plugins/formation.d.ts +16 -0
- package/lib/types/plugins/inbox.d.ts +16 -0
- package/lib/types/plugins/knowledge.d.ts +19 -0
- package/lib/types/plugins/prompt.d.ts +17 -0
- package/lib/types/plugins/tools.d.ts +10 -0
- package/lib/types/prompt/render.d.ts +2 -0
- package/lib/types/protocol/arbitration.d.ts +154 -0
- package/lib/types/protocol/auth.d.ts +31 -0
- package/lib/types/protocol/claim.d.ts +36 -0
- package/lib/types/protocol/dispute.d.ts +17 -0
- package/lib/types/protocol/ids.d.ts +20 -0
- package/lib/types/protocol/inbox.d.ts +141 -0
- package/lib/types/protocol/index.d.ts +11 -0
- package/lib/types/protocol/policy.d.ts +21 -0
- package/lib/types/protocol/revision.d.ts +2 -0
- package/lib/types/protocol/router.d.ts +114 -0
- package/lib/types/protocol/schema.d.ts +4 -0
- package/lib/types/protocol/time.d.ts +5 -0
- package/lib/types/protocol/trace.d.ts +11 -0
- package/lib/types/store/atomic.d.ts +8 -0
- package/lib/types/store/claim-edits.d.ts +33 -0
- package/lib/types/store/claims.d.ts +7 -0
- package/lib/types/store/context.d.ts +13 -0
- package/lib/types/store/delivery-status.d.ts +48 -0
- package/lib/types/store/disputes.d.ts +6 -0
- package/lib/types/store/entities.d.ts +16 -0
- package/lib/types/store/errors.d.ts +8 -0
- package/lib/types/store/history.d.ts +65 -0
- package/lib/types/store/inbox.d.ts +27 -0
- package/lib/types/store/index.d.ts +16 -0
- package/lib/types/store/jobs.d.ts +5 -0
- package/lib/types/store/library-directory.d.ts +4 -0
- package/lib/types/store/lock.d.ts +11 -0
- package/lib/types/store/path-names.d.ts +2 -0
- package/lib/types/store/paths.d.ts +45 -0
- package/lib/types/store/presentation.d.ts +13 -0
- package/lib/types/store/regular-file.d.ts +2 -0
- package/lib/types/store/rejected-disputes.d.ts +18 -0
- package/lib/types/store/rename.d.ts +1 -0
- package/lib/types/store/reported-sets.d.ts +24 -0
- package/lib/types/store/session-state.d.ts +17 -0
- package/lib/types/store/traces.d.ts +6 -0
- package/lib/types/store/uploads.d.ts +312 -0
- package/lib/types/store/yaml.d.ts +8 -0
- package/lib/types/team/errors.d.ts +10 -0
- package/lib/types/team/http.d.ts +20 -0
- package/lib/types/team/index.d.ts +5 -0
- package/lib/types/team/maintainer-client.d.ts +18 -0
- package/lib/types/team/router-client.d.ts +14 -0
- package/lib/types/team/service.d.ts +28 -0
- package/lib/types/team/system-proxy.d.ts +9 -0
- package/lib/types/tools/claim.d.ts +63 -0
- package/lib/types/tools/consult-router.d.ts +11 -0
- package/lib/types/tools/subagent.d.ts +8 -0
- package/lib/types/tools/validation.d.ts +2 -0
- package/lib/types/upload/consolidation.d.ts +63 -0
- package/lib/types/upload/deliver.d.ts +15 -0
- package/lib/types/upload/index.d.ts +2 -0
- package/lib/types/upload/scheduler.d.ts +19 -0
- package/lib/types/upstreams.d.ts +5 -0
- package/lib/types/worker/queue.d.ts +17 -0
- package/lib/types/worker/types.d.ts +51 -0
- package/lib/types/worker/worker.d.ts +39 -0
- package/lib/types-C2ST2Zdg.js +17 -0
- package/lib/upload.js +3 -0
- package/lib/uploads-BCA2p92b.js +210 -0
- package/lib/upstreams-DEi-56tD.js +495 -0
- package/lib/worker-HMGzJFWd.js +185 -0
- package/locale/commands/en.json +1 -0
- package/locale/commands/zh.json +1 -0
- package/locale/dream/en.json +1 -0
- package/locale/dream/zh.json +1 -0
- package/locale/en.json +7 -0
- package/locale/formation/en.json +1 -0
- package/locale/formation/zh.json +1 -0
- package/locale/inbox/en.json +1 -0
- package/locale/inbox/zh.json +1 -0
- package/locale/knowledge/en.json +1 -0
- package/locale/knowledge/zh.json +1 -0
- package/locale/prompt/en.json +1 -0
- package/locale/prompt/zh.json +1 -0
- package/locale/tools/en.json +1 -0
- package/locale/tools/zh.json +1 -0
- package/locale/zh.json +7 -0
- package/package.json +262 -3
- package/prompts/claim_dream.j2 +77 -0
- package/prompts/claim_dream_legacy.j2 +63 -0
- package/prompts/dream_compaction.j2 +11 -0
- package/prompts/dream_evidence.j2 +5 -0
- package/prompts/inbox_claim_attribute_update_internalize.j2 +112 -0
- package/prompts/inbox_policy_update_internalize.j2 +87 -0
- package/prompts/knowledge.j2 +38 -0
- package/prompts/session_recap.j2 +113 -0
- package/prompts/what_is_claim.j2 +51 -0
- package/prompts/what_is_dispute.j2 +21 -0
- package/prompts/what_is_policy.j2 +22 -0
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { c as AgentIdSchema } from "./claim-DOAGe8ZK.js";
|
|
2
|
+
import { n as agentHomePath } from "./paths-B7NI9Ano.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
import { appendPluginRecord, pluginRecordOf } from "@deepseek-ai/dsh-session";
|
|
6
|
+
//#region src/config.ts
|
|
7
|
+
const positive = () => z.number().int().positive().max(Number.MAX_SAFE_INTEGER);
|
|
8
|
+
const nonnegative = () => z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
|
|
9
|
+
const endpoint = z.string().refine((value) => {
|
|
10
|
+
if (value === "") return true;
|
|
11
|
+
try {
|
|
12
|
+
const url = new URL(value);
|
|
13
|
+
return ["http:", "https:"].includes(url.protocol) && !url.username && !url.password && !url.search && !url.hash;
|
|
14
|
+
} catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const UpstreamNameSchema = z.string().regex(/^[a-z0-9_-]+$/).refine((value) => ![
|
|
19
|
+
"data",
|
|
20
|
+
"skills",
|
|
21
|
+
"config.toml",
|
|
22
|
+
"acn.md",
|
|
23
|
+
"logs",
|
|
24
|
+
"tmp",
|
|
25
|
+
".git"
|
|
26
|
+
].includes(value));
|
|
27
|
+
const UpstreamSchema = z.strictObject({
|
|
28
|
+
name: z.string().trim().max(80).default(""),
|
|
29
|
+
agentId: AgentIdSchema,
|
|
30
|
+
enabled: z.boolean().default(true),
|
|
31
|
+
routerEndpoint: endpoint.default(""),
|
|
32
|
+
maintainerEndpoint: endpoint.default(""),
|
|
33
|
+
keyEnv: z.string().regex(/^(?:[A-Za-z_][A-Za-z0-9_]*)?$/).default(""),
|
|
34
|
+
timeoutMs: positive().default(15e3)
|
|
35
|
+
}).superRefine((value, ctx) => {
|
|
36
|
+
if (Boolean(value.routerEndpoint) !== Boolean(value.maintainerEndpoint)) ctx.addIssue({
|
|
37
|
+
code: "custom",
|
|
38
|
+
path: ["routerEndpoint"],
|
|
39
|
+
message: "Configure both team endpoints or neither."
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
const ConnectionSchema = z.strictObject({
|
|
43
|
+
id: z.string().regex(/^[a-zA-Z0-9_-]{1,80}$/).refine((id) => !["personal", "legacy"].includes(id)),
|
|
44
|
+
name: z.string().trim().min(1).max(80),
|
|
45
|
+
enabled: z.boolean().default(true),
|
|
46
|
+
agentId: AgentIdSchema,
|
|
47
|
+
routerEndpoint: endpoint.refine(Boolean),
|
|
48
|
+
maintainerEndpoint: endpoint.refine(Boolean),
|
|
49
|
+
keyEnv: z.string().regex(/^(?:[A-Za-z_][A-Za-z0-9_]*)?$/).default(""),
|
|
50
|
+
timeoutMs: positive().default(15e3)
|
|
51
|
+
});
|
|
52
|
+
const ConfigSchema = z.strictObject({
|
|
53
|
+
upstream: z.string().default(""),
|
|
54
|
+
upstreams: z.record(UpstreamNameSchema, UpstreamSchema).optional(),
|
|
55
|
+
agentId: z.union([z.literal(""), AgentIdSchema]).default(""),
|
|
56
|
+
home: z.string().trim().min(1).default("~/.acn-dsh"),
|
|
57
|
+
sessionEpoch: nonnegative().default(0),
|
|
58
|
+
connections: z.array(ConnectionSchema).max(50).default([]),
|
|
59
|
+
defaultConnection: z.string().default(""),
|
|
60
|
+
legacyEnabled: z.boolean().default(true),
|
|
61
|
+
showCompletion: z.boolean().default(true),
|
|
62
|
+
team: z.strictObject({
|
|
63
|
+
routerEndpoint: endpoint.default(""),
|
|
64
|
+
maintainerEndpoint: endpoint.default(""),
|
|
65
|
+
keyEnv: z.string().regex(/^(?:[A-Za-z_][A-Za-z0-9_]*)?$/).default(""),
|
|
66
|
+
timeoutMs: positive().default(15e3),
|
|
67
|
+
routerTimeoutMs: positive().default(5e4),
|
|
68
|
+
retryCount: nonnegative().default(3),
|
|
69
|
+
retryBaseDelayMs: positive().default(500),
|
|
70
|
+
retryMaxDelayMs: positive().default(8e3)
|
|
71
|
+
}).prefault({}),
|
|
72
|
+
llm: z.strictObject({
|
|
73
|
+
provider: z.string().default(""),
|
|
74
|
+
model: z.string().default(""),
|
|
75
|
+
maxOutputTokens: positive().default(32768),
|
|
76
|
+
timeoutMs: positive().default(6e5),
|
|
77
|
+
structuredRetries: positive().default(5)
|
|
78
|
+
}).prefault({}),
|
|
79
|
+
catalog: z.strictObject({
|
|
80
|
+
maxClaims: positive().default(20),
|
|
81
|
+
maxChars: positive().default(24e3)
|
|
82
|
+
}).prefault({}),
|
|
83
|
+
formation: z.strictObject({
|
|
84
|
+
recapOnCompaction: z.boolean().default(true),
|
|
85
|
+
idleRecap: z.boolean().default(true),
|
|
86
|
+
recapMinTurns: positive().default(10),
|
|
87
|
+
recapMinTokens: positive().default(1e5),
|
|
88
|
+
recapBatchIdleMinutes: positive().default(5),
|
|
89
|
+
recapTailIdleMinutes: positive().default(60),
|
|
90
|
+
recapScanSeconds: positive().default(30),
|
|
91
|
+
finalizeIdleMinutes: nonnegative().default(0),
|
|
92
|
+
finalizeOnDispose: z.boolean().default(false)
|
|
93
|
+
}).prefault({}),
|
|
94
|
+
inbox: z.strictObject({
|
|
95
|
+
pullOnSessionStart: z.boolean().default(true),
|
|
96
|
+
processingStaleAfterSecs: positive().default(600)
|
|
97
|
+
}).prefault({}),
|
|
98
|
+
dream: z.strictObject({
|
|
99
|
+
enabled: z.boolean().default(true),
|
|
100
|
+
minIntervalHours: positive().default(24),
|
|
101
|
+
minChangedClaims: positive().default(5),
|
|
102
|
+
checkIntervalHours: positive().default(4),
|
|
103
|
+
evidenceCalibration: z.boolean().default(false),
|
|
104
|
+
maxModelSteps: positive().max(128).default(24),
|
|
105
|
+
maxWrapUpSteps: positive().max(8).default(3),
|
|
106
|
+
evidenceMaxCalls: positive().max(256).default(32),
|
|
107
|
+
evidenceMaxSteps: positive().max(128).default(24),
|
|
108
|
+
evidenceMaxBytes: positive().max(16777216).default(1048576),
|
|
109
|
+
evidenceMaxChars: positive().max(64e3).default(16e3),
|
|
110
|
+
evidenceMaxFiles: positive().max(4096).default(256)
|
|
111
|
+
}).prefault({})
|
|
112
|
+
}).superRefine((config, ctx) => {
|
|
113
|
+
if (config.upstreams !== void 0) {
|
|
114
|
+
if (config.upstream !== "" && config.upstreams[config.upstream]?.enabled !== true) ctx.addIssue({
|
|
115
|
+
code: "custom",
|
|
116
|
+
path: ["upstream"],
|
|
117
|
+
message: "Select an enabled upstream."
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (new Set(config.connections.map((item) => item.id)).size !== config.connections.length) ctx.addIssue({
|
|
121
|
+
code: "custom",
|
|
122
|
+
path: ["connections"],
|
|
123
|
+
message: "Connection identifiers must be unique."
|
|
124
|
+
});
|
|
125
|
+
if (config.defaultConnection !== "" && config.defaultConnection !== "legacy" && !config.connections.some((item) => item.id === config.defaultConnection && item.enabled)) ctx.addIssue({
|
|
126
|
+
code: "custom",
|
|
127
|
+
path: ["defaultConnection"],
|
|
128
|
+
message: "Default connection must be enabled."
|
|
129
|
+
});
|
|
130
|
+
if (Boolean(config.team.routerEndpoint) !== Boolean(config.team.maintainerEndpoint)) ctx.addIssue({
|
|
131
|
+
code: "custom",
|
|
132
|
+
path: ["team"],
|
|
133
|
+
message: "Configure both team endpoints or neither."
|
|
134
|
+
});
|
|
135
|
+
if (Boolean(config.llm.provider.trim()) !== Boolean(config.llm.model.trim())) ctx.addIssue({
|
|
136
|
+
code: "custom",
|
|
137
|
+
path: ["llm"],
|
|
138
|
+
message: "Configure both provider and model or neither."
|
|
139
|
+
});
|
|
140
|
+
if (config.team.retryMaxDelayMs < config.team.retryBaseDelayMs) ctx.addIssue({
|
|
141
|
+
code: "custom",
|
|
142
|
+
path: ["team", "retryMaxDelayMs"],
|
|
143
|
+
message: "Maximum retry delay must not be smaller than the base delay."
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
var ConfigError = class extends Error {
|
|
147
|
+
fields;
|
|
148
|
+
kind = "config";
|
|
149
|
+
constructor(fields) {
|
|
150
|
+
super(`Invalid ACN configuration: ${fields.join(", ")}`);
|
|
151
|
+
this.fields = fields;
|
|
152
|
+
this.name = "ConfigError";
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
function resolveConfig(input) {
|
|
156
|
+
let value = input;
|
|
157
|
+
if (typeof input === "object" && input !== null && !Array.isArray(input)) {
|
|
158
|
+
const compatible = { ...input };
|
|
159
|
+
delete compatible["projectUpstreams"];
|
|
160
|
+
delete compatible["memory"];
|
|
161
|
+
value = compatible;
|
|
162
|
+
}
|
|
163
|
+
const parsed = ConfigSchema.safeParse(value);
|
|
164
|
+
if (!parsed.success) throw new ConfigError([...new Set(parsed.error.issues.map((issue) => issue.path.join(".") || "config"))]);
|
|
165
|
+
return parsed.data;
|
|
166
|
+
}
|
|
167
|
+
function upstreamsOf(config) {
|
|
168
|
+
if (config.upstreams !== void 0) return config.upstreams;
|
|
169
|
+
const items = {};
|
|
170
|
+
if (config.agentId !== "") items["personal"] = UpstreamSchema.parse({
|
|
171
|
+
name: config.team.routerEndpoint ? "团队" : "个人知识",
|
|
172
|
+
agentId: config.agentId,
|
|
173
|
+
enabled: config.legacyEnabled,
|
|
174
|
+
routerEndpoint: config.team.routerEndpoint,
|
|
175
|
+
maintainerEndpoint: config.team.maintainerEndpoint,
|
|
176
|
+
keyEnv: config.team.keyEnv,
|
|
177
|
+
timeoutMs: config.team.timeoutMs
|
|
178
|
+
});
|
|
179
|
+
for (const connection of config.connections) {
|
|
180
|
+
const { id, ...value } = connection;
|
|
181
|
+
let key = id.toLowerCase();
|
|
182
|
+
while (items[key] !== void 0 || [
|
|
183
|
+
"data",
|
|
184
|
+
"skills",
|
|
185
|
+
"logs",
|
|
186
|
+
"tmp"
|
|
187
|
+
].includes(key)) key = `${key}_copy`;
|
|
188
|
+
items[key] = UpstreamSchema.parse(value);
|
|
189
|
+
}
|
|
190
|
+
return items;
|
|
191
|
+
}
|
|
192
|
+
function activeUpstream(config) {
|
|
193
|
+
return config.upstream || "personal";
|
|
194
|
+
}
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/dsh-adapter/session-binding.ts
|
|
197
|
+
const BindingSchema = z.strictObject({
|
|
198
|
+
schemaVersion: z.literal(1),
|
|
199
|
+
identity: z.string().regex(/^[0-9a-f]{64}$/)
|
|
200
|
+
});
|
|
201
|
+
const EligibilitySchema = z.strictObject({ schemaVersion: z.literal(1) });
|
|
202
|
+
const emptyIdentity = createHash("sha256").update("").digest("hex");
|
|
203
|
+
const SelectionSchema = z.strictObject({
|
|
204
|
+
schemaVersion: z.literal(1),
|
|
205
|
+
key: z.string(),
|
|
206
|
+
identity: z.string().regex(/^[0-9a-f]{64}$/),
|
|
207
|
+
prepared: z.boolean().optional()
|
|
208
|
+
});
|
|
209
|
+
const bindings = /* @__PURE__ */ new WeakMap();
|
|
210
|
+
const identityOf = (config) => createHash("sha256").update(config.agentId === "" ? "" : agentHomePath(config.home, config.agentId, activeUpstream(config))).digest("hex");
|
|
211
|
+
const selections = /* @__PURE__ */ new WeakMap();
|
|
212
|
+
const runningConfigurations = /* @__PURE__ */ new WeakMap();
|
|
213
|
+
const activations = /* @__PURE__ */ new WeakMap();
|
|
214
|
+
let activationSequence = 0;
|
|
215
|
+
const configurationActivation = (header) => activations.get(header) ?? 0;
|
|
216
|
+
function runningConfiguration(header) {
|
|
217
|
+
return runningConfigurations.get(header);
|
|
218
|
+
}
|
|
219
|
+
function rememberConfiguration(header, config) {
|
|
220
|
+
runningConfigurations.set(header, config);
|
|
221
|
+
activations.set(header, ++activationSequence);
|
|
222
|
+
}
|
|
223
|
+
function forgetConfiguration(header) {
|
|
224
|
+
runningConfigurations.delete(header);
|
|
225
|
+
activations.delete(header);
|
|
226
|
+
}
|
|
227
|
+
function decodeSelection(value) {
|
|
228
|
+
const parsed = SelectionSchema.safeParse(value);
|
|
229
|
+
return parsed.success ? parsed.data : {
|
|
230
|
+
schemaVersion: 1,
|
|
231
|
+
key: "invalid",
|
|
232
|
+
identity: "0".repeat(64)
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
function observeSelection(header, event) {
|
|
236
|
+
const record = pluginRecordOf(event);
|
|
237
|
+
if (record?.type === "plugin:acn/team-selection") selections.set(header, decodeSelection(record.data));
|
|
238
|
+
}
|
|
239
|
+
function restoreSessionBinding(header, events) {
|
|
240
|
+
const records = events.map(pluginRecordOf);
|
|
241
|
+
const values = records.filter((record) => record?.type === "plugin:acn/session-binding").map((record) => BindingSchema.safeParse(record?.data));
|
|
242
|
+
const first = values[0];
|
|
243
|
+
bindings.set(header, first?.success && values.every((value) => value.success && value.data.identity === first.data.identity) ? first.data.identity : null);
|
|
244
|
+
const selected = records.filter((record) => record?.type === "plugin:acn/team-selection").at(-1);
|
|
245
|
+
selections.set(header, selected === void 0 ? void 0 : decodeSelection(selected.data));
|
|
246
|
+
}
|
|
247
|
+
function sessionSelection(ctx, header) {
|
|
248
|
+
if (selections.has(header)) return selections.get(header);
|
|
249
|
+
const last = (ctx.sessions.get(header.id)?.snapshotEvents().map(pluginRecordOf).filter((record) => record?.type === "plugin:acn/team-selection") ?? []).at(-1);
|
|
250
|
+
const value = last === void 0 ? void 0 : decodeSelection(last.data);
|
|
251
|
+
selections.set(header, value);
|
|
252
|
+
return value;
|
|
253
|
+
}
|
|
254
|
+
function sessionHasWork(events) {
|
|
255
|
+
return events.some((event) => event.type === "request/header" || event.type === "assistant/message" || event.type === "tool/result" || event.type === "turn/start" || event.type === "user/message" && event.data.source.kind === "user");
|
|
256
|
+
}
|
|
257
|
+
function sessionEligible(ctx, header, events = ctx.sessions.get(header.id)?.snapshotEvents()) {
|
|
258
|
+
return events?.some((event) => {
|
|
259
|
+
const record = pluginRecordOf(event);
|
|
260
|
+
return record?.type === "plugin:acn/session-eligibility" && EligibilitySchema.safeParse(record.data).success || record?.type === "plugin:acn/session-binding" && BindingSchema.safeParse(record.data).data?.identity === emptyIdentity;
|
|
261
|
+
}) ?? false;
|
|
262
|
+
}
|
|
263
|
+
function markSessionEligible(ctx, header) {
|
|
264
|
+
const session = ctx.sessions.get(header.id);
|
|
265
|
+
if (session === void 0 || session.firstLiveSeq > 0 || header.isSeeded || header.parentSession !== void 0 || sessionHasWork(session.snapshotEvents()) || sessionEligible(ctx, header)) return;
|
|
266
|
+
appendPluginRecord(session, "plugin:acn/session-eligibility", { schemaVersion: 1 });
|
|
267
|
+
}
|
|
268
|
+
function sessionUnbound(ctx, header, events) {
|
|
269
|
+
const seen = /* @__PURE__ */ new Set();
|
|
270
|
+
let current = header;
|
|
271
|
+
while (current !== void 0) {
|
|
272
|
+
if (seen.has(current.id)) return false;
|
|
273
|
+
seen.add(current.id);
|
|
274
|
+
const history = current === header && events !== void 0 ? events : ctx.sessions.get(current.id)?.snapshotEvents();
|
|
275
|
+
if (history === void 0) return current !== header;
|
|
276
|
+
for (const event of history) {
|
|
277
|
+
const record = pluginRecordOf(event);
|
|
278
|
+
if (record?.type === "plugin:acn/team-selection") return false;
|
|
279
|
+
if (record?.type === "plugin:acn/session-binding" && BindingSchema.safeParse(record.data).data?.identity !== emptyIdentity) return false;
|
|
280
|
+
}
|
|
281
|
+
current = current.parentSession === void 0 ? void 0 : ctx.sessions.get(current.parentSession)?.header;
|
|
282
|
+
}
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
function bindSession(ctx, config, header) {
|
|
286
|
+
if (config.agentId === "") return;
|
|
287
|
+
if (bindings.has(header)) return;
|
|
288
|
+
const session = ctx.sessions.get(header.id);
|
|
289
|
+
if (session === void 0) {
|
|
290
|
+
bindings.set(header, null);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
const records = session.snapshotEvents().map(pluginRecordOf).filter((record) => record?.type === "plugin:acn/session-binding");
|
|
294
|
+
if (records.length > 0) {
|
|
295
|
+
const values = records.map((record) => BindingSchema.safeParse(record?.data));
|
|
296
|
+
const first = values[0];
|
|
297
|
+
bindings.set(header, first?.success && values.every((value) => value.success && value.data.identity === first.data.identity) ? first.data.identity : null);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
const parent = header.parentSession === void 0 ? void 0 : ctx.sessions.get(header.parentSession);
|
|
301
|
+
const parentSelection = parent === void 0 ? void 0 : sessionSelection(ctx, parent.header);
|
|
302
|
+
if (session.firstLiveSeq === 0 && sessionSelection(ctx, header) === void 0 && parentSelection !== void 0) appendPluginRecord(session, "plugin:acn/team-selection", parentSelection);
|
|
303
|
+
const verifiedParent = parent !== void 0 && sessionAllowed(ctx, config, parent.header);
|
|
304
|
+
if (session.firstLiveSeq > 0 || !verifiedParent && (!sessionEligible(ctx, header) || sessionHasWork(session.snapshotEvents()) || header.parentSession !== void 0 || header.isSeeded)) {
|
|
305
|
+
bindings.set(header, null);
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
const identity = identityOf(config);
|
|
309
|
+
bindings.set(header, identity);
|
|
310
|
+
try {
|
|
311
|
+
appendPluginRecord(session, "plugin:acn/session-binding", {
|
|
312
|
+
schemaVersion: 1,
|
|
313
|
+
identity
|
|
314
|
+
});
|
|
315
|
+
} catch (error) {
|
|
316
|
+
bindings.set(header, null);
|
|
317
|
+
throw error;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
const sessionChanged = "ACN 会话身份与当前配置不一致,或缺少可验证的历史身份记录,请新建会话。旧会话不能访问当前身份的知识。";
|
|
321
|
+
const configurationBusy = "ACN 配置正在应用,请稍后重试。";
|
|
322
|
+
const unboundSession = "本会话未启用 ACN,聊天仍可继续。只有安装插件后新建且尚未发送消息的会话可选择工作配置;如需使用 ACN,请新建会话。";
|
|
323
|
+
function sessionAllowed(ctx, config, header) {
|
|
324
|
+
if (config.agentId === "") return true;
|
|
325
|
+
if (config.team.routerEndpoint && !config.legacyEnabled) return false;
|
|
326
|
+
const identity = identityOf(config);
|
|
327
|
+
const selected = sessionSelection(ctx, header);
|
|
328
|
+
if (selected !== void 0) return selected.identity === identity;
|
|
329
|
+
if (bindings.get(header) !== identity) return false;
|
|
330
|
+
if (config.sessionEpoch === 0) return true;
|
|
331
|
+
const seen = /* @__PURE__ */ new Set();
|
|
332
|
+
let current = header;
|
|
333
|
+
while (current !== void 0) {
|
|
334
|
+
if (current.createdAt <= config.sessionEpoch || seen.has(current.id)) return false;
|
|
335
|
+
seen.add(current.id);
|
|
336
|
+
if (current.parentSession === void 0) return true;
|
|
337
|
+
current = ctx.sessions.get(current.parentSession)?.header;
|
|
338
|
+
}
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
//#endregion
|
|
342
|
+
export { resolveConfig as C, activeUpstream as S, unboundSession as _, identityOf as a, UpstreamNameSchema as b, rememberConfiguration as c, sessionAllowed as d, sessionChanged as f, sessionUnbound as g, sessionSelection as h, forgetConfiguration as i, restoreSessionBinding as l, sessionHasWork as m, configurationActivation as n, markSessionEligible as o, sessionEligible as p, configurationBusy as r, observeSelection as s, bindSession as t, runningConfiguration as u, ConfigError as v, upstreamsOf as w, UpstreamSchema as x, ConnectionSchema as y };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { c as readYamlOr, l as writeYamlAtomic, n as withFileLock } from "./lock-DbmlKOoX.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region src/store/session-state.ts
|
|
4
|
+
const VersionedDocumentSchema = z.object({ schemaVersion: z.literal(1) }).catchall(z.json());
|
|
5
|
+
var VersionedFileStore = class {
|
|
6
|
+
context;
|
|
7
|
+
resolvePath;
|
|
8
|
+
constructor(context, resolvePath) {
|
|
9
|
+
this.context = context;
|
|
10
|
+
this.resolvePath = resolvePath;
|
|
11
|
+
}
|
|
12
|
+
read(id) {
|
|
13
|
+
return readYamlOr(this.resolvePath(id), VersionedDocumentSchema, () => null);
|
|
14
|
+
}
|
|
15
|
+
write(id, value) {
|
|
16
|
+
const path = this.resolvePath(id);
|
|
17
|
+
return withFileLock(`${path}.lock`, () => writeYamlAtomic(path, value, VersionedDocumentSchema, this.context.logger), { timeoutMs: this.context.lockTimeoutMs });
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var SessionStateStore = class extends VersionedFileStore {
|
|
21
|
+
constructor(context) {
|
|
22
|
+
super(context, (id) => context.paths.sessionState(id));
|
|
23
|
+
}
|
|
24
|
+
async update(id, change, signal) {
|
|
25
|
+
const path = this.context.paths.sessionState(id);
|
|
26
|
+
return withFileLock(`${path}.lock`, async () => {
|
|
27
|
+
const next = VersionedDocumentSchema.parse(await change(await this.read(id)));
|
|
28
|
+
signal?.throwIfAborted();
|
|
29
|
+
await writeYamlAtomic(path, next, VersionedDocumentSchema, this.context.logger);
|
|
30
|
+
return next;
|
|
31
|
+
}, {
|
|
32
|
+
timeoutMs: this.context.lockTimeoutMs,
|
|
33
|
+
signal
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
//#endregion
|
|
38
|
+
export { VersionedDocumentSchema as n, VersionedFileStore as r, SessionStateStore as t };
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { n as ClaimStatusSchema, x as nowSeconds } from "./claim-DOAGe8ZK.js";
|
|
2
|
+
import { n as claimRevision } from "./revision-DeoL_IUN.js";
|
|
3
|
+
import { S as LockTimeoutError } from "./lock-DbmlKOoX.js";
|
|
4
|
+
import { r as KnowledgeBusy } from "./alignment-CwH0nBf-.js";
|
|
5
|
+
import { n as VersionedDocumentSchema, t as SessionStateStore } from "./session-state-CYqUhC95.js";
|
|
6
|
+
import { i as sortClaims, t as boundedText } from "./pages-BEWC3kmZ.js";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
//#region src/knowledge/catalog.ts
|
|
9
|
+
function renderCatalog(claims, budget) {
|
|
10
|
+
const active = sortClaims(claims.filter((claim) => claim.status !== "deprecated"));
|
|
11
|
+
const lines = [];
|
|
12
|
+
for (const claim of active.slice(0, budget.maxClaims)) {
|
|
13
|
+
const line = `${claim.id} | ${JSON.stringify(boundedText(claim.name, 120).text)} | ${JSON.stringify(boundedText(claim.scope, 240).text)} | ${claim.confidence} | ${claim.status}`;
|
|
14
|
+
const omitted = active.length - lines.length - 1;
|
|
15
|
+
const candidate = [
|
|
16
|
+
...lines,
|
|
17
|
+
line,
|
|
18
|
+
...omitted > 0 ? [`另有 ${omitted} 条,用 claim 工具搜索。`] : []
|
|
19
|
+
].join("\n");
|
|
20
|
+
if (Array.from(candidate).length > budget.maxChars) break;
|
|
21
|
+
lines.push(line);
|
|
22
|
+
}
|
|
23
|
+
const omitted = active.length - lines.length;
|
|
24
|
+
if (omitted > 0) lines.push(`另有 ${omitted} 条,用 claim 工具搜索。`);
|
|
25
|
+
if (active.length === 0) lines.push("暂无 active/stale Claim。");
|
|
26
|
+
return boundedText(lines.join("\n"), budget.maxChars).text;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/knowledge/changes.ts
|
|
30
|
+
const ClaimIdentitySchema = z.object({
|
|
31
|
+
name: z.string(),
|
|
32
|
+
scope: z.string(),
|
|
33
|
+
status: ClaimStatusSchema,
|
|
34
|
+
revision: z.string()
|
|
35
|
+
});
|
|
36
|
+
const ClaimIndexSchema = z.record(z.string(), ClaimIdentitySchema);
|
|
37
|
+
function claimIndex(claims) {
|
|
38
|
+
return Object.fromEntries([...claims].sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0).map((claim) => [claim.id, {
|
|
39
|
+
name: claim.name,
|
|
40
|
+
scope: claim.scope,
|
|
41
|
+
status: claim.status,
|
|
42
|
+
revision: claimRevision(claim)
|
|
43
|
+
}]));
|
|
44
|
+
}
|
|
45
|
+
function claimChanges(baseline, current, known) {
|
|
46
|
+
const changes = [];
|
|
47
|
+
for (const [id, item] of Object.entries(current)) {
|
|
48
|
+
if (baseline[id]?.revision === item.revision) continue;
|
|
49
|
+
changes.push({
|
|
50
|
+
change: item.status === "deprecated" ? "deprecated" : baseline[id] === void 0 ? "created" : "updated",
|
|
51
|
+
id,
|
|
52
|
+
name: item.name,
|
|
53
|
+
scope: item.scope,
|
|
54
|
+
status: item.status
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
for (const [id, item] of Object.entries({
|
|
58
|
+
...baseline,
|
|
59
|
+
...known
|
|
60
|
+
})) if (current[id] === void 0) changes.push({
|
|
61
|
+
change: "removed",
|
|
62
|
+
id,
|
|
63
|
+
name: item.name,
|
|
64
|
+
scope: item.scope,
|
|
65
|
+
status: item.status
|
|
66
|
+
});
|
|
67
|
+
return changes.sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
68
|
+
}
|
|
69
|
+
function changeNotice(revision, baseline, current, known) {
|
|
70
|
+
const payload = {
|
|
71
|
+
revision,
|
|
72
|
+
refresh_all: false,
|
|
73
|
+
changes: claimChanges(baseline, current, known)
|
|
74
|
+
};
|
|
75
|
+
return `claim_changes_since_system_prompt: ${JSON.stringify(payload)}\nThis cumulative identity snapshot supersedes earlier claim notices. Assess relevance from name/scope; use claim action="read" for current content only when the current task needs to cite or rely on that Claim. Do not read every changed Claim merely because it is listed. Deprecated/removed entries must not be relied on; no content read is needed to stop using them.`;
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/knowledge/sessions.ts
|
|
79
|
+
const VersionSchema = z.object({ claimsDigest: z.string() });
|
|
80
|
+
const CatalogSchema = z.object({
|
|
81
|
+
text: z.string(),
|
|
82
|
+
knowledgeVersion: VersionSchema,
|
|
83
|
+
createdAt: z.string(),
|
|
84
|
+
baseline: ClaimIndexSchema
|
|
85
|
+
});
|
|
86
|
+
const KnowledgeSessionStateSchema = z.object({
|
|
87
|
+
schemaVersion: z.literal(1),
|
|
88
|
+
catalog: CatalogSchema.optional(),
|
|
89
|
+
lastNotifiedVersion: VersionSchema.optional(),
|
|
90
|
+
knownClaims: ClaimIndexSchema.optional(),
|
|
91
|
+
seenSourceIds: z.array(z.string()).optional()
|
|
92
|
+
});
|
|
93
|
+
var KnowledgeSessions = class {
|
|
94
|
+
knowledge;
|
|
95
|
+
store;
|
|
96
|
+
states = /* @__PURE__ */ new Map();
|
|
97
|
+
writes = /* @__PURE__ */ new Map();
|
|
98
|
+
constructor(knowledge) {
|
|
99
|
+
this.knowledge = knowledge;
|
|
100
|
+
this.store = new SessionStateStore(knowledge.context());
|
|
101
|
+
}
|
|
102
|
+
async freeze(id, source, parentId, fetchOverview = true, signal) {
|
|
103
|
+
signal?.throwIfAborted();
|
|
104
|
+
await this.flush(id);
|
|
105
|
+
const stored = await this.store.read(id);
|
|
106
|
+
let state = KnowledgeSessionStateSchema.parse(stored ?? { schemaVersion: 1 });
|
|
107
|
+
if (state.catalog === void 0 && parentId !== void 0 && source !== "clear") {
|
|
108
|
+
await this.flush(parentId);
|
|
109
|
+
const parent = KnowledgeSessionStateSchema.parse(await this.store.read(parentId) ?? { schemaVersion: 1 });
|
|
110
|
+
if (parent.catalog !== void 0) {
|
|
111
|
+
state = {
|
|
112
|
+
...state,
|
|
113
|
+
catalog: parent.catalog,
|
|
114
|
+
knownClaims: parent.knownClaims ?? parent.catalog.baseline,
|
|
115
|
+
seenSourceIds: parent.seenSourceIds ?? []
|
|
116
|
+
};
|
|
117
|
+
delete state.lastNotifiedVersion;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (state.catalog === void 0 || source === "clear" || source === "startup" && parentId === void 0) {
|
|
121
|
+
if (source === "resume" || source === "compact") this.knowledge.logger.warn("Missing session Claim catalog; creating a new baseline.");
|
|
122
|
+
const snapshot = await this.knowledge.snapshot(signal);
|
|
123
|
+
const baseline = claimIndex(snapshot.claims);
|
|
124
|
+
state = {
|
|
125
|
+
...state,
|
|
126
|
+
catalog: {
|
|
127
|
+
text: renderCatalog(snapshot.claims, this.knowledge.config.catalog),
|
|
128
|
+
knowledgeVersion: snapshot.version,
|
|
129
|
+
createdAt: nowSeconds(),
|
|
130
|
+
baseline
|
|
131
|
+
},
|
|
132
|
+
lastNotifiedVersion: snapshot.version,
|
|
133
|
+
knownClaims: baseline,
|
|
134
|
+
seenSourceIds: source === "clear" ? [] : state.seenSourceIds ?? []
|
|
135
|
+
};
|
|
136
|
+
const team = this.knowledge.team;
|
|
137
|
+
if (fetchOverview && team !== null && state.catalog !== void 0) try {
|
|
138
|
+
const overviewText = `\n\nTeam scope overview (discovery only):\n${(await team.request("router", () => team.router.overview(signal))).scopes.map((item) => `${JSON.stringify(item.scope)} | active=${item.active_claims} | stale=${item.stale_claims} | open_disputes=${item.open_disputes} | resolved_disputes=${item.resolved_disputes}`).join("\n") || "(empty)"}`;
|
|
139
|
+
const total = this.knowledge.config.catalog.maxChars;
|
|
140
|
+
const overviewBudget = Math.min(Math.floor(total / 2), Array.from(overviewText).length);
|
|
141
|
+
state.catalog.text = renderCatalog(snapshot.claims, {
|
|
142
|
+
...this.knowledge.config.catalog,
|
|
143
|
+
maxChars: Math.max(1, total - overviewBudget)
|
|
144
|
+
});
|
|
145
|
+
const remaining = Math.max(0, total - Array.from(state.catalog.text).length);
|
|
146
|
+
state.catalog.text += Array.from(overviewText).slice(0, remaining).join("");
|
|
147
|
+
} catch {
|
|
148
|
+
signal?.throwIfAborted();
|
|
149
|
+
state.catalog.text = Array.from(`${state.catalog.text}\n\n团队概览不可用。可调用 consult_router,参数为 {"mode":"overview"},重新获取概览。`).slice(0, this.knowledge.config.catalog.maxChars).join("");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
signal?.throwIfAborted();
|
|
153
|
+
const saved = await this.store.update(id, (current) => VersionedDocumentSchema.parse({
|
|
154
|
+
...current,
|
|
155
|
+
...state
|
|
156
|
+
}), signal);
|
|
157
|
+
this.states.set(id, KnowledgeSessionStateSchema.parse(saved));
|
|
158
|
+
}
|
|
159
|
+
catalog(id) {
|
|
160
|
+
return this.states.get(id)?.catalog?.text ?? "";
|
|
161
|
+
}
|
|
162
|
+
async prepare(id, signal) {
|
|
163
|
+
signal?.throwIfAborted();
|
|
164
|
+
await this.flush(id);
|
|
165
|
+
const state = this.states.get(id);
|
|
166
|
+
if (state?.catalog === void 0) return null;
|
|
167
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
168
|
+
signal?.throwIfAborted();
|
|
169
|
+
try {
|
|
170
|
+
const snapshot = await this.knowledge.snapshot(signal, 0);
|
|
171
|
+
signal?.throwIfAborted();
|
|
172
|
+
if (snapshot.version.claimsDigest === state.lastNotifiedVersion?.claimsDigest) return null;
|
|
173
|
+
const current = claimIndex(snapshot.claims);
|
|
174
|
+
return {
|
|
175
|
+
text: changeNotice(snapshot.version.claimsDigest, state.catalog.baseline, current, state.knownClaims ?? state.catalog.baseline),
|
|
176
|
+
version: snapshot.version,
|
|
177
|
+
knownClaims: {
|
|
178
|
+
...state.knownClaims,
|
|
179
|
+
...current
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
} catch (error) {
|
|
183
|
+
signal?.throwIfAborted();
|
|
184
|
+
if (!(error instanceof KnowledgeBusy || error instanceof LockTimeoutError)) throw error;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
this.knowledge.logger.debug("Knowledge refresh deferred while a local commit is busy.");
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
admitted(id, notice) {
|
|
191
|
+
const write = (this.writes.get(id) ?? Promise.resolve()).then(async () => {
|
|
192
|
+
const saved = await this.store.update(id, (current) => ({
|
|
193
|
+
...current,
|
|
194
|
+
schemaVersion: 1,
|
|
195
|
+
lastNotifiedVersion: notice.version,
|
|
196
|
+
knownClaims: notice.knownClaims
|
|
197
|
+
}));
|
|
198
|
+
this.states.set(id, KnowledgeSessionStateSchema.parse(saved));
|
|
199
|
+
}).catch(() => {
|
|
200
|
+
this.knowledge.logger.warn("Could not persist the session Claim notice cursor; it will be retried.");
|
|
201
|
+
});
|
|
202
|
+
this.writes.set(id, write);
|
|
203
|
+
}
|
|
204
|
+
async flush(id) {
|
|
205
|
+
if (id !== void 0) await this.writes.get(id);
|
|
206
|
+
else await Promise.all(this.writes.values());
|
|
207
|
+
}
|
|
208
|
+
clear(id) {
|
|
209
|
+
this.states.delete(id);
|
|
210
|
+
this.writes.delete(id);
|
|
211
|
+
}
|
|
212
|
+
async forget(id) {
|
|
213
|
+
await this.flush(id);
|
|
214
|
+
this.clear(id);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
//#endregion
|
|
218
|
+
export { KnowledgeSessions as t };
|
package/lib/store.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { C as StoreError, S as LockTimeoutError, a as encodeJson, c as readYamlOr, d as removeFile, f as writeTextAtomic, i as decodeYaml, l as writeYamlAtomic, n as withFileLock, o as encodeYaml, p as writeTextAtomicIfAbsent, r as withFileLocks, s as readYaml, t as acquireFileLease, u as cleanupAtomicTemps, w as hasCode } from "./lock-DbmlKOoX.js";
|
|
2
|
+
import { a as EntityStore, i as ClaimStore, n as ReportedSetsSchema, r as reportedClaimSetKey, t as ReportedSetStore } from "./reported-sets-DdEKdeVb.js";
|
|
3
|
+
import { t as TraceStore } from "./traces-CHBo8y1z.js";
|
|
4
|
+
import { n as PendingUploadsSchema, r as UploadStore, t as ConsolidationDeliverySchema } from "./uploads-BCA2p92b.js";
|
|
5
|
+
import { n as VersionedDocumentSchema, r as VersionedFileStore, t as SessionStateStore } from "./session-state-CYqUhC95.js";
|
|
6
|
+
import { i as safeKey, n as agentHomePath, r as expandHomePath, t as AgentPaths } from "./paths-B7NI9Ano.js";
|
|
7
|
+
import { n as ClaimEditStore, r as PendingClaimEditSchema, t as DisputeStore } from "./disputes-ByEmi43j.js";
|
|
8
|
+
import { t as InboxStore } from "./inbox-2CugZZQm.js";
|
|
9
|
+
//#region src/store/jobs.ts
|
|
10
|
+
var JobStore = class extends VersionedFileStore {
|
|
11
|
+
constructor(context) {
|
|
12
|
+
super(context, (id) => context.paths.job(id));
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { AgentPaths, ClaimEditStore, ClaimStore, ConsolidationDeliverySchema, DisputeStore, EntityStore, InboxStore, JobStore, LockTimeoutError, PendingClaimEditSchema, PendingUploadsSchema, ReportedSetStore, ReportedSetsSchema, SessionStateStore, StoreError, TraceStore, UploadStore, VersionedDocumentSchema, VersionedFileStore, acquireFileLease, agentHomePath, cleanupAtomicTemps, decodeYaml, encodeJson, encodeYaml, expandHomePath, hasCode, readYaml, readYamlOr, removeFile, reportedClaimSetKey, safeKey, withFileLock, withFileLocks, writeTextAtomic, writeTextAtomicIfAbsent, writeYamlAtomic };
|