@ftai/dsh-plugin-acn 0.0.0-stage → 0.1.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/CHANGELOG.md +79 -0
- package/LICENSE-APACHE +201 -0
- package/LICENSE-MIT +19 -0
- package/README.md +55 -2
- package/README_EN.md +56 -0
- package/cordis.patch.yml +29 -0
- package/docs/acn-compat.md +33 -0
- package/docs/architecture.md +129 -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 +243 -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 +183 -0
- package/icon.svg +8 -0
- package/lib/activities-LRoCwpzw.js +327 -0
- package/lib/alignment-CwH0nBf-.js +80 -0
- package/lib/auth-DFI9yowX.js +71 -0
- package/lib/checkpoint-Bmt8q2vB.js +188 -0
- package/lib/checkpoint-RgcdqifN.js +318 -0
- package/lib/claim-DOAGe8ZK.js +168 -0
- package/lib/client.js +18420 -0
- package/lib/deliver-BuYQaPRW.js +168 -0
- package/lib/delivery-status-D5m3178s.js +87 -0
- package/lib/dispute-CtrInHzf.js +20 -0
- package/lib/disputes-ByEmi43j.js +51 -0
- package/lib/dream-agent-DBszTHXY.js +249 -0
- package/lib/dream.js +4 -0
- package/lib/effects-DJ4Xa7Tx.js +268 -0
- package/lib/errors-Bp_2WXBr.js +19 -0
- package/lib/errors-pPumDOGD.js +18 -0
- package/lib/evidence-store-DLFvSuNa.js +1030 -0
- package/lib/formation-D4LO31WW.js +187 -0
- package/lib/formation-replay-CEOy5FkI.js +87 -0
- package/lib/formation.js +9 -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 +1377 -0
- package/lib/lock-DbmlKOoX.js +332 -0
- package/lib/pages-BEWC3kmZ.js +51 -0
- package/lib/paths-CDYV5UH9.js +154 -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 +1111 -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-DwHZudbA.js +134 -0
- package/lib/presentation-BlLjgDjP.js +47 -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-MaUEbXr3.js +64 -0
- package/lib/service-B7AI5jds.js +344 -0
- package/lib/service-BcHV5mc7.js +305 -0
- package/lib/service-CNjqHCBR.js +505 -0
- package/lib/service-C_i3BzdP.js +1106 -0
- package/lib/session-binding-BQrOGhZI.js +151 -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-lyQCK-Zk.js +452 -0
- package/lib/subagent-yJsFxHmH.js +9 -0
- package/lib/team-credentials-C9xHrPIi.js +579 -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 +71 -0
- package/lib/types/advanced-configuration.d.ts +11 -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 +15 -0
- package/lib/types/client/TeamCredentialField.d.ts +16 -0
- package/lib/types/client/TeamSettingsPage.d.ts +30 -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 +122 -0
- package/lib/types/configuration.d.ts +259 -0
- package/lib/types/credentials.d.ts +65 -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 +550 -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 +47 -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/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/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/worker-BBTYP2RE.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,102 @@
|
|
|
1
|
+
import { d as sessionAllowed } from "../session-binding-BQrOGhZI.js";
|
|
2
|
+
import { t as loadPromptRenderer } from "../render-CJaVcKKC.js";
|
|
3
|
+
import { t as isEvidenceAgent } from "../subagent-yJsFxHmH.js";
|
|
4
|
+
import { t as KnowledgeSessions } from "../sessions-C2xuPFQv.js";
|
|
5
|
+
import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
6
|
+
//#region src/plugins/prompt.ts
|
|
7
|
+
const name = "acn-prompt";
|
|
8
|
+
const inject = [
|
|
9
|
+
"acnKnowledge",
|
|
10
|
+
"acnRuntime",
|
|
11
|
+
"systemPrompt",
|
|
12
|
+
"agents",
|
|
13
|
+
"sessions"
|
|
14
|
+
];
|
|
15
|
+
async function apply(ctx) {
|
|
16
|
+
const knowledge = ctx.acnKnowledge;
|
|
17
|
+
ctx.effect(() => ctx.acnRuntime.component("prompt"));
|
|
18
|
+
if (!knowledge.configured || knowledge.config.upstreams !== void 0) return;
|
|
19
|
+
if (!knowledge.active) return;
|
|
20
|
+
const render = await loadPromptRenderer();
|
|
21
|
+
const sessions = new KnowledgeSessions(knowledge);
|
|
22
|
+
const pending = /* @__PURE__ */ new Map();
|
|
23
|
+
ctx.systemPrompt.section({
|
|
24
|
+
name: "acn:knowledge",
|
|
25
|
+
order: 700,
|
|
26
|
+
interpolate: false,
|
|
27
|
+
text: ({ agent }) => agent !== void 0 && !sessionAllowed(ctx, knowledge.config, agent.session.header) ? "" : render("knowledge.j2", {
|
|
28
|
+
agent_id: knowledge.agentId,
|
|
29
|
+
team: knowledge.mode === "team"
|
|
30
|
+
})
|
|
31
|
+
});
|
|
32
|
+
ctx.systemPrompt.section({
|
|
33
|
+
name: "acn:claim-catalog",
|
|
34
|
+
order: 710,
|
|
35
|
+
interpolate: false,
|
|
36
|
+
text: ({ agent }) => agent === void 0 || !sessionAllowed(ctx, knowledge.config, agent.session.header) ? "" : sessions.catalog(agent.session.id)
|
|
37
|
+
});
|
|
38
|
+
ctx.effect(() => ctx.acnRuntime.registerBaseline((id, fetchOverview) => sessions.freeze(id, "clear", void 0, fetchOverview), (header) => sessionAllowed(ctx, knowledge.config, header) ? {
|
|
39
|
+
"acn:knowledge": render("knowledge.j2", {
|
|
40
|
+
agent_id: knowledge.agentId,
|
|
41
|
+
team: knowledge.mode === "team"
|
|
42
|
+
}),
|
|
43
|
+
"acn:claim-catalog": sessions.catalog(header.id)
|
|
44
|
+
} : {
|
|
45
|
+
"acn:knowledge": "",
|
|
46
|
+
"acn:claim-catalog": ""
|
|
47
|
+
}));
|
|
48
|
+
ctx.on("agent/created", async ({ agent, source, signal }) => {
|
|
49
|
+
if (!sessionAllowed(ctx, knowledge.config, agent.session.header) || isEvidenceAgent(agent.session.header)) return;
|
|
50
|
+
await sessions.freeze(agent.session.id, source, agent.session.header.parentSession, true, signal);
|
|
51
|
+
});
|
|
52
|
+
ctx.on("agent/pre-step", async ({ agent, signal }, next) => {
|
|
53
|
+
if (isEvidenceAgent(agent.session.header) || !sessionAllowed(ctx, knowledge.config, agent.session.header)) return next();
|
|
54
|
+
const decision = await next();
|
|
55
|
+
if (decision.kind === "reject") return decision;
|
|
56
|
+
signal.throwIfAborted();
|
|
57
|
+
const notice = await sessions.prepare(agent.session.id, signal);
|
|
58
|
+
signal.throwIfAborted();
|
|
59
|
+
if (notice === null) return decision;
|
|
60
|
+
const message = createUserMessage({
|
|
61
|
+
content: [{
|
|
62
|
+
type: "text",
|
|
63
|
+
text: notice.text
|
|
64
|
+
}],
|
|
65
|
+
source: { kind: "acn-claim-changes" }
|
|
66
|
+
});
|
|
67
|
+
pending.set(message.id, {
|
|
68
|
+
sessionId: agent.session.id,
|
|
69
|
+
notice
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
...decision,
|
|
73
|
+
messages: [...decision.messages, message]
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
ctx.on("session/event", (session, event) => {
|
|
77
|
+
if (event.type !== "user/message" || event.data.source.kind !== "acn-claim-changes") return;
|
|
78
|
+
const admission = pending.get(event.data.id);
|
|
79
|
+
if (admission?.sessionId !== session.id) return;
|
|
80
|
+
pending.delete(event.data.id);
|
|
81
|
+
sessions.admitted(session.id, admission.notice);
|
|
82
|
+
});
|
|
83
|
+
ctx.on("agent/status", ({ agent, status }) => {
|
|
84
|
+
if (status === "idle") {
|
|
85
|
+
for (const [id, admission] of pending) if (admission.sessionId === agent.session.id) pending.delete(id);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
ctx.on("agent/disposed", ({ agent }) => {
|
|
89
|
+
sessions.forget(agent.session.id).catch(() => {
|
|
90
|
+
knowledge.logger.warn("Could not finish session Claim state cleanup.");
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
for (const agent of ctx.agents.list()) if (sessionAllowed(ctx, knowledge.config, agent.session.header) && !isEvidenceAgent(agent.session.header)) await sessions.freeze(agent.session.id, "resume", agent.session.header.parentSession);
|
|
94
|
+
ctx.effect(() => () => sessions.flush());
|
|
95
|
+
}
|
|
96
|
+
var prompt_default = {
|
|
97
|
+
name,
|
|
98
|
+
inject,
|
|
99
|
+
apply
|
|
100
|
+
};
|
|
101
|
+
//#endregion
|
|
102
|
+
export { apply, prompt_default as default, inject, name };
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { h as TraceIdSchema, l as ClaimIdSchema, n as ClaimStatusSchema, r as ConfidenceSchema } from "../claim-DOAGe8ZK.js";
|
|
2
|
+
import { n as RevisionConflict, t as KnowledgeError } from "../errors-Bp_2WXBr.js";
|
|
3
|
+
import { S as LockTimeoutError } from "../lock-DbmlKOoX.js";
|
|
4
|
+
import { r as KnowledgeBusy } from "../alignment-CwH0nBf-.js";
|
|
5
|
+
import { t as SessionStateStore } from "../session-state-CYqUhC95.js";
|
|
6
|
+
import { t as TeamError } from "../errors-pPumDOGD.js";
|
|
7
|
+
import { u as runningConfiguration } from "../session-binding-BQrOGhZI.js";
|
|
8
|
+
import { t as toolParameters } from "../tool-schema-3b4gH1zf.js";
|
|
9
|
+
import { n as isSubagent } from "../subagent-yJsFxHmH.js";
|
|
10
|
+
import { t as ClaimUpdateSchema } from "../types-C2ST2Zdg.js";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
13
|
+
//#region src/tools/validation.ts
|
|
14
|
+
function validationMessage(error) {
|
|
15
|
+
return error.issues.slice(0, 8).map((issue) => {
|
|
16
|
+
return `${issue.path.map(String).filter((part) => /^[a-zA-Z_][a-zA-Z0-9_]{0,63}$|^[0-9]+$/.test(part)).join(".") || "$"}: ${issue.code === "invalid_type" ? `expected ${issue.expected}` : issue.code === "too_small" ? `minimum ${String(issue.minimum)}` : issue.code === "too_big" ? `maximum ${String(issue.maximum)}` : issue.code === "invalid_value" ? `expected ${issue.values.map(String).join(" | ")}` : issue.code === "unrecognized_keys" ? "unexpected fields; use only fields for the selected action" : issue.code === "invalid_format" ? `invalid ${issue.format} format` : "does not match the required action or field rule"}`;
|
|
17
|
+
}).join("; ");
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/tools/claim.ts
|
|
21
|
+
const text = z.string();
|
|
22
|
+
const id = text.describe("claim id for read/update, or trace id for read_trace");
|
|
23
|
+
const offset = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER).optional().describe("list/traces result offset");
|
|
24
|
+
const limit = z.number().int().min(1).max(100).optional().describe("list/traces maximum results").meta({ default: 20 });
|
|
25
|
+
const editableText = text.optional().describe("update only");
|
|
26
|
+
const ClaimToolArgsSchema = z.discriminatedUnion("action", [
|
|
27
|
+
z.strictObject({
|
|
28
|
+
action: z.literal("list"),
|
|
29
|
+
query: text.optional().describe("list only: case-insensitive substring search across name, scope, and statement"),
|
|
30
|
+
include_deprecated: z.boolean().optional().describe("list only: include deprecated claims so they can be inspected or restored").meta({ default: false }),
|
|
31
|
+
offset,
|
|
32
|
+
limit
|
|
33
|
+
}),
|
|
34
|
+
z.strictObject({
|
|
35
|
+
action: z.literal("read"),
|
|
36
|
+
id
|
|
37
|
+
}),
|
|
38
|
+
z.strictObject({
|
|
39
|
+
action: z.literal("update"),
|
|
40
|
+
id,
|
|
41
|
+
expected_revision: text.describe("Required for update; use the exact revision returned by read"),
|
|
42
|
+
name: editableText,
|
|
43
|
+
statement: editableText,
|
|
44
|
+
scope: editableText,
|
|
45
|
+
evidence_summary: editableText,
|
|
46
|
+
confidence: ConfidenceSchema.optional().describe("update only"),
|
|
47
|
+
status: ClaimStatusSchema.optional().describe("update only")
|
|
48
|
+
}),
|
|
49
|
+
z.strictObject({
|
|
50
|
+
action: z.literal("traces"),
|
|
51
|
+
claim_id: text.optional().describe("traces only: return traces whose inputs or outputs reference this claim"),
|
|
52
|
+
offset,
|
|
53
|
+
limit
|
|
54
|
+
}),
|
|
55
|
+
z.strictObject({
|
|
56
|
+
action: z.literal("read_trace"),
|
|
57
|
+
id,
|
|
58
|
+
task_offset: offset.describe("read_trace only: character offset into task text"),
|
|
59
|
+
task_limit: z.number().int().min(1).max(16e3).optional().describe("read_trace only: maximum task characters").meta({ default: 4e3 })
|
|
60
|
+
})
|
|
61
|
+
]);
|
|
62
|
+
const CLAIM_DESCRIPTION = "List, search, read, or CAS-update this agent's own claims, and inspect the original task traces connected to them. Updates require the revision returned by read and preserve claim identity, holder, creation time, and sources.";
|
|
63
|
+
const optionalFields = /* @__PURE__ */ new Set([
|
|
64
|
+
"query",
|
|
65
|
+
"include_deprecated",
|
|
66
|
+
"offset",
|
|
67
|
+
"limit",
|
|
68
|
+
"name",
|
|
69
|
+
"statement",
|
|
70
|
+
"scope",
|
|
71
|
+
"evidence_summary",
|
|
72
|
+
"confidence",
|
|
73
|
+
"status",
|
|
74
|
+
"claim_id",
|
|
75
|
+
"task_offset",
|
|
76
|
+
"task_limit"
|
|
77
|
+
]);
|
|
78
|
+
async function executeClaim(knowledge, input, signal) {
|
|
79
|
+
try {
|
|
80
|
+
signal?.throwIfAborted();
|
|
81
|
+
const normalized = typeof input === "object" && input !== null && !Array.isArray(input) ? Object.fromEntries(Object.entries(input).map(([key, value]) => [key, value === null && optionalFields.has(key) ? void 0 : value])) : input;
|
|
82
|
+
const args = ClaimToolArgsSchema.parse(normalized);
|
|
83
|
+
switch (args.action) {
|
|
84
|
+
case "list": return await knowledge.listClaims({
|
|
85
|
+
...args.query === void 0 ? {} : { query: args.query },
|
|
86
|
+
...args.include_deprecated === void 0 ? {} : { includeDeprecated: args.include_deprecated },
|
|
87
|
+
...args.offset === void 0 ? {} : { offset: args.offset },
|
|
88
|
+
...args.limit === void 0 ? {} : { limit: args.limit }
|
|
89
|
+
}, signal);
|
|
90
|
+
case "read": return await knowledge.readClaim(z.object({ id: ClaimIdSchema }).parse({ id: args.id }).id, signal);
|
|
91
|
+
case "update": {
|
|
92
|
+
const update = ClaimUpdateSchema.parse(Object.fromEntries(Object.entries(args).filter(([key]) => key !== "action")));
|
|
93
|
+
return await knowledge.updateClaim(update, signal);
|
|
94
|
+
}
|
|
95
|
+
case "traces": return await knowledge.listTraces({
|
|
96
|
+
...args.claim_id === void 0 ? {} : { claimId: ClaimIdSchema.parse(args.claim_id) },
|
|
97
|
+
...args.offset === void 0 ? {} : { offset: args.offset },
|
|
98
|
+
...args.limit === void 0 ? {} : { limit: args.limit }
|
|
99
|
+
}, signal);
|
|
100
|
+
case "read_trace": return await knowledge.readTrace(z.object({ id: TraceIdSchema }).parse({ id: args.id }).id, {
|
|
101
|
+
...args.task_offset === void 0 ? {} : { taskOffset: args.task_offset },
|
|
102
|
+
...args.task_limit === void 0 ? {} : { taskLimit: args.task_limit }
|
|
103
|
+
}, signal);
|
|
104
|
+
}
|
|
105
|
+
} catch (error) {
|
|
106
|
+
signal?.throwIfAborted();
|
|
107
|
+
if (error instanceof KnowledgeBusy || error instanceof LockTimeoutError) return { error: {
|
|
108
|
+
kind: "knowledge_busy",
|
|
109
|
+
message: "知识库暂时忙碌,请稍后重试当前知识操作。",
|
|
110
|
+
retryable: true
|
|
111
|
+
} };
|
|
112
|
+
if (error instanceof RevisionConflict) return {
|
|
113
|
+
conflict: true,
|
|
114
|
+
current_revision: error.currentRevision
|
|
115
|
+
};
|
|
116
|
+
if (error instanceof KnowledgeError) return { error: {
|
|
117
|
+
kind: error.kind,
|
|
118
|
+
message: error.message
|
|
119
|
+
} };
|
|
120
|
+
if (error instanceof z.ZodError) return { error: {
|
|
121
|
+
kind: "validation",
|
|
122
|
+
message: validationMessage(error)
|
|
123
|
+
} };
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/tools/consult-router.ts
|
|
129
|
+
const CONSULT_ROUTER_DESCRIPTION = "Consult the team router. Use mode='overview' to list available team claim scopes before choosing a query boundary. Use mode='query' with a non-empty scope to retrieve candidate claims and related disputes. Overview is only a map of available scopes; query returns concrete claim content.";
|
|
130
|
+
const ConsultRouterArgsSchema = z.discriminatedUnion("mode", [z.strictObject({ mode: z.literal("overview") }), z.strictObject({
|
|
131
|
+
mode: z.literal("query"),
|
|
132
|
+
scope: z.string().trim().min(1),
|
|
133
|
+
semantic_query: z.string().trim().nullish()
|
|
134
|
+
})]);
|
|
135
|
+
async function executeConsultRouter(knowledge, args, sessionId, signal) {
|
|
136
|
+
const parsed = ConsultRouterArgsSchema.safeParse(args);
|
|
137
|
+
if (!parsed.success) return { error: {
|
|
138
|
+
kind: "validation",
|
|
139
|
+
message: validationMessage(parsed.error)
|
|
140
|
+
} };
|
|
141
|
+
const team = knowledge.team;
|
|
142
|
+
if (team === null) return { error: {
|
|
143
|
+
kind: "unconfigured",
|
|
144
|
+
message: "Team router is not configured."
|
|
145
|
+
} };
|
|
146
|
+
try {
|
|
147
|
+
if (parsed.data.mode === "overview") return {
|
|
148
|
+
mode: "overview",
|
|
149
|
+
available: true,
|
|
150
|
+
scopes: (await team.request("router", () => team.router.overview(signal))).scopes
|
|
151
|
+
};
|
|
152
|
+
const { scope, semantic_query } = parsed.data;
|
|
153
|
+
const result = await team.request("router", () => team.router.query({
|
|
154
|
+
scope,
|
|
155
|
+
semantic_query: semantic_query || null
|
|
156
|
+
}, signal));
|
|
157
|
+
signal?.throwIfAborted();
|
|
158
|
+
const ids = result.candidate_claims.map((claim) => claim.id);
|
|
159
|
+
await new SessionStateStore(knowledge.context()).update(sessionId, (current) => {
|
|
160
|
+
const seen = z.array(z.string()).parse(current?.["seenSourceIds"] ?? []);
|
|
161
|
+
return {
|
|
162
|
+
...current,
|
|
163
|
+
schemaVersion: 1,
|
|
164
|
+
seenSourceIds: [.../* @__PURE__ */ new Set([...seen, ...ids])]
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
return {
|
|
168
|
+
mode: "query",
|
|
169
|
+
available: true,
|
|
170
|
+
candidate_claims: result.candidate_claims,
|
|
171
|
+
disputes: result.disputes
|
|
172
|
+
};
|
|
173
|
+
} catch (error) {
|
|
174
|
+
if (!(error instanceof TeamError)) throw error;
|
|
175
|
+
return {
|
|
176
|
+
mode: parsed.data.mode,
|
|
177
|
+
available: false,
|
|
178
|
+
error: {
|
|
179
|
+
kind: error.kind,
|
|
180
|
+
message: error.message
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region src/dsh-adapter/tools.ts
|
|
187
|
+
function claimTool(knowledge, resolve) {
|
|
188
|
+
return {
|
|
189
|
+
...defineTool({
|
|
190
|
+
name: "claim",
|
|
191
|
+
description: CLAIM_DESCRIPTION,
|
|
192
|
+
parameters: { action: {
|
|
193
|
+
type: "string",
|
|
194
|
+
required: true,
|
|
195
|
+
enum: [
|
|
196
|
+
"list",
|
|
197
|
+
"read",
|
|
198
|
+
"update",
|
|
199
|
+
"traces",
|
|
200
|
+
"read_trace"
|
|
201
|
+
]
|
|
202
|
+
} },
|
|
203
|
+
output: {
|
|
204
|
+
schema: { type: "json" },
|
|
205
|
+
render: (_args, value) => [{
|
|
206
|
+
type: "text",
|
|
207
|
+
text: JSON.stringify(value, null, 2)
|
|
208
|
+
}]
|
|
209
|
+
},
|
|
210
|
+
async execute(args, exec) {
|
|
211
|
+
if (resolve !== void 0 && exec.agent === void 0) return { error: {
|
|
212
|
+
kind: "ownership",
|
|
213
|
+
message: "Claim requires an agent session."
|
|
214
|
+
} };
|
|
215
|
+
const result = await executeClaim(resolve === void 0 || exec.agent === void 0 ? knowledge : await resolve(exec.agent.session.header), args, exec.signal);
|
|
216
|
+
const json = JSON.parse(JSON.stringify(result));
|
|
217
|
+
return z.json().parse(json);
|
|
218
|
+
}
|
|
219
|
+
}),
|
|
220
|
+
parameters: toolParameters(ClaimToolArgsSchema)
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function consultRouterTool(knowledge, resolve) {
|
|
224
|
+
return {
|
|
225
|
+
...defineTool({
|
|
226
|
+
name: "consult_router",
|
|
227
|
+
description: CONSULT_ROUTER_DESCRIPTION,
|
|
228
|
+
parameters: { mode: {
|
|
229
|
+
type: "string",
|
|
230
|
+
enum: ["overview", "query"],
|
|
231
|
+
required: true
|
|
232
|
+
} },
|
|
233
|
+
output: {
|
|
234
|
+
schema: { type: "json" },
|
|
235
|
+
render: (_args, value) => [{
|
|
236
|
+
type: "text",
|
|
237
|
+
text: JSON.stringify(value, null, 2)
|
|
238
|
+
}]
|
|
239
|
+
},
|
|
240
|
+
async execute(args, exec) {
|
|
241
|
+
if (exec.agent === void 0) throw new Error("consult_router requires an agent session.");
|
|
242
|
+
const result = await executeConsultRouter(resolve === void 0 ? knowledge : await resolve(exec.agent.session.header), args, exec.agent.session.id, exec.signal);
|
|
243
|
+
return z.json().parse(JSON.parse(JSON.stringify(result)));
|
|
244
|
+
}
|
|
245
|
+
}),
|
|
246
|
+
parameters: toolParameters(ConsultRouterArgsSchema)
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
//#endregion
|
|
250
|
+
//#region src/plugins/tools.ts
|
|
251
|
+
const name = "acn-tools";
|
|
252
|
+
const inject = [
|
|
253
|
+
"acnKnowledge",
|
|
254
|
+
"acnRuntime",
|
|
255
|
+
"tools"
|
|
256
|
+
];
|
|
257
|
+
function apply(ctx) {
|
|
258
|
+
if (!ctx.acnKnowledge.configured && ctx.acnKnowledge.config.upstreams === void 0) return;
|
|
259
|
+
const denied = (exec) => {
|
|
260
|
+
const args = exec.arguments;
|
|
261
|
+
return exec.name === "claim" && typeof args === "object" && args !== null && "action" in args && args.action === "update" && exec.agent !== void 0 && isSubagent(exec.agent.session.header) ? "Subagents cannot modify ACN knowledge." : void 0;
|
|
262
|
+
};
|
|
263
|
+
ctx.on("tools/pre-execute", (exec, next) => {
|
|
264
|
+
const reason = denied(exec);
|
|
265
|
+
return reason === void 0 ? next() : Promise.resolve({
|
|
266
|
+
kind: "deny",
|
|
267
|
+
reason
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
ctx.tools.guard(denied);
|
|
271
|
+
ctx.tools.register(claimTool(ctx.acnKnowledge, (header) => ctx.acnRuntime.knowledge(header)));
|
|
272
|
+
if ((ctx.get("agents")?.list().some((agent) => Boolean(runningConfiguration(agent.session.header)?.team.routerEndpoint)) ?? false) || Object.values(ctx.acnKnowledge.config.upstreams ?? {}).some((item) => item.enabled && item.routerEndpoint) || ctx.acnKnowledge.team !== null || ctx.acnKnowledge.config.connections.some((connection) => connection.enabled)) ctx.tools.register(consultRouterTool(ctx.acnKnowledge, (header) => ctx.acnRuntime.knowledge(header)));
|
|
273
|
+
}
|
|
274
|
+
var tools_default = {
|
|
275
|
+
name,
|
|
276
|
+
inject,
|
|
277
|
+
apply
|
|
278
|
+
};
|
|
279
|
+
//#endregion
|
|
280
|
+
export { apply, tools_default as default, inject, name };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { a as TextSchema, c as AgentIdSchema, f as PolicyIdSchema, o as optional, y as TimestampSchema } from "./claim-DOAGe8ZK.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region src/protocol/policy.ts
|
|
4
|
+
const PolicySchema = z.object({
|
|
5
|
+
id: PolicyIdSchema,
|
|
6
|
+
message_type: z.enum(["policy_update", "claim_attribute_update"]).default("policy_update"),
|
|
7
|
+
name: TextSchema,
|
|
8
|
+
statement: TextSchema,
|
|
9
|
+
scope: TextSchema,
|
|
10
|
+
status: z.enum(["active", "deprecated"]),
|
|
11
|
+
created_at: TimestampSchema,
|
|
12
|
+
updated_at: optional(TimestampSchema),
|
|
13
|
+
target_agents: optional(z.array(AgentIdSchema))
|
|
14
|
+
});
|
|
15
|
+
//#endregion
|
|
16
|
+
export { PolicySchema as t };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { _ as deriveDisputeId, g as deriveClaimId, i as effectiveUpdatedAt, l as ClaimIdSchema, m as SourceIdSchema, u as DisputeIdSchema, x as nowSeconds } from "./claim-DOAGe8ZK.js";
|
|
2
|
+
import { d as RecapOutputSchema, u as FormationValidationError } from "./structured-lyQCK-Zk.js";
|
|
3
|
+
import { R as nextClaimUpdateAt } from "./evidence-store-DLFvSuNa.js";
|
|
4
|
+
import { n as validateClaimText } from "./regular-file-BFpqMoub.js";
|
|
5
|
+
//#region src/formation/prepare.ts
|
|
6
|
+
function requireValid(condition, message) {
|
|
7
|
+
if (!condition) throw new FormationValidationError(message);
|
|
8
|
+
}
|
|
9
|
+
function recapClaimIds(texts) {
|
|
10
|
+
return [...new Set(texts.flatMap((text) => [...text.matchAll(/(?<![A-Za-z0-9_])claim_[0-9a-f]{8}(?![A-Za-z0-9_])/g)].map((match) => ClaimIdSchema.parse(match[0]))))];
|
|
11
|
+
}
|
|
12
|
+
function prepareFormation(raw, agentId, local, seenSourceIds, now = nowSeconds(), visibility = {}) {
|
|
13
|
+
const output = RecapOutputSchema.parse(raw);
|
|
14
|
+
const placeholders = /* @__PURE__ */ new Map();
|
|
15
|
+
const occupied = new Set([...local, ...visibility.directClaims ?? []].map((claim) => String(claim.id)));
|
|
16
|
+
function reserve(make) {
|
|
17
|
+
for (let attempt = 0; attempt < 8; attempt += 1) {
|
|
18
|
+
const id = make();
|
|
19
|
+
if (!occupied.has(id)) {
|
|
20
|
+
occupied.add(id);
|
|
21
|
+
return id;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
throw new FormationValidationError("生成 ID 冲突,请重试本批复盘。");
|
|
25
|
+
}
|
|
26
|
+
output.new_claims.forEach((draft, index) => {
|
|
27
|
+
requireValid(draft.id === `$new_claim_${index}$`, "new_claims.id 必须是按数组位置递增的占位符。");
|
|
28
|
+
placeholders.set(draft.id, reserve(() => deriveClaimId(now, draft.name, draft.scope)));
|
|
29
|
+
});
|
|
30
|
+
output.new_disputes.forEach((draft, index) => {
|
|
31
|
+
requireValid(draft.id === `$new_dispute_${index}$`, "new_disputes.id 必须是按数组位置递增的占位符。");
|
|
32
|
+
placeholders.set(draft.id, reserve(() => deriveDisputeId(now, draft.name, draft.claims, draft.summary)));
|
|
33
|
+
});
|
|
34
|
+
const replace = (value) => value.replace(/\$new_(?:claim|dispute)_\d+\$/g, (token) => {
|
|
35
|
+
const id = placeholders.get(token);
|
|
36
|
+
requireValid(id !== void 0, "输出含未声明的占位符。");
|
|
37
|
+
return id;
|
|
38
|
+
});
|
|
39
|
+
const resolved = RecapOutputSchema.parse(JSON.parse(JSON.stringify(output), (_key, value) => typeof value === "string" ? replace(value) : value));
|
|
40
|
+
const visibleClaims = new Set(local.filter((claim) => claim.status !== "deprecated").map((claim) => claim.id));
|
|
41
|
+
for (const claim of visibility.directClaims ?? []) visibleClaims.add(claim.id);
|
|
42
|
+
for (const id of visibility.editableDeprecatedIds ?? []) visibleClaims.add(id);
|
|
43
|
+
const policies = /* @__PURE__ */ new Set();
|
|
44
|
+
for (const source of seenSourceIds) if (ClaimIdSchema.safeParse(source).success) visibleClaims.add(source);
|
|
45
|
+
else if (SourceIdSchema.safeParse(source).success) policies.add(source);
|
|
46
|
+
const sourceClaims = new Set(visibleClaims);
|
|
47
|
+
for (const claim of [...local.filter((claim) => visibleClaims.has(claim.id)), ...visibility.directClaims ?? []]) for (const source of claim.source_claim_ids) if (source.startsWith("policy_")) policies.add(source);
|
|
48
|
+
else sourceClaims.add(source);
|
|
49
|
+
const disputeClaims = new Set(visibleClaims);
|
|
50
|
+
for (const claim of resolved.new_claims) {
|
|
51
|
+
sourceClaims.add(claim.id);
|
|
52
|
+
disputeClaims.add(claim.id);
|
|
53
|
+
}
|
|
54
|
+
const warnings = [];
|
|
55
|
+
const usedClaimIds = [];
|
|
56
|
+
for (const raw of resolved.used_claim_ids) {
|
|
57
|
+
const id = ClaimIdSchema.safeParse(raw);
|
|
58
|
+
requireValid(id.success && visibleClaims.has(id.data), "used_claim_ids 包含不在本次上下文中的合法 Claim ID;请核对来源后重试整批。");
|
|
59
|
+
if (!usedClaimIds.includes(id.data)) usedClaimIds.push(id.data);
|
|
60
|
+
}
|
|
61
|
+
function sources(values, self) {
|
|
62
|
+
return [...new Set(values.map((value) => {
|
|
63
|
+
const parsed = SourceIdSchema.safeParse(value);
|
|
64
|
+
requireValid(parsed.success, "source_claim_ids 必须是合法 Claim 或 Policy ID。");
|
|
65
|
+
requireValid(value !== self, "source_claim_ids 不得引用自身。");
|
|
66
|
+
requireValid(value.startsWith("policy_") ? policies.has(value) : sourceClaims.has(value), "source_claim_ids 引用了本轮不可见的来源。");
|
|
67
|
+
return parsed.data;
|
|
68
|
+
}))];
|
|
69
|
+
}
|
|
70
|
+
const claims = resolved.new_claims.map(({ id: rawId, source_claim_ids, ...draft }) => {
|
|
71
|
+
validateClaimText({
|
|
72
|
+
name: draft.name,
|
|
73
|
+
statement: draft.statement,
|
|
74
|
+
scope: draft.scope,
|
|
75
|
+
evidence_summary: draft.evidence_summary
|
|
76
|
+
});
|
|
77
|
+
const id = ClaimIdSchema.parse(rawId);
|
|
78
|
+
return {
|
|
79
|
+
...draft,
|
|
80
|
+
id,
|
|
81
|
+
holder: agentId,
|
|
82
|
+
status: "active",
|
|
83
|
+
created_at: now,
|
|
84
|
+
source_claim_ids: sources(source_claim_ids, id)
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
const updated = /* @__PURE__ */ new Set();
|
|
88
|
+
for (const { id: rawId, source_claim_ids, ...draft } of resolved.updated_claims) {
|
|
89
|
+
const existing = local.find((claim) => claim.id === rawId);
|
|
90
|
+
requireValid(existing !== void 0 && existing.holder === agentId && (existing.status !== "deprecated" || visibility.editableDeprecatedIds?.has(existing.id) === true), "updated_claims 只能更新本轮可见且由当前 agent 持有的 Claim。");
|
|
91
|
+
requireValid(!updated.has(rawId), "updated_claims 含重复 ID。");
|
|
92
|
+
updated.add(rawId);
|
|
93
|
+
validateClaimText({
|
|
94
|
+
name: draft.name,
|
|
95
|
+
statement: draft.statement,
|
|
96
|
+
scope: draft.scope,
|
|
97
|
+
evidence_summary: draft.evidence_summary
|
|
98
|
+
});
|
|
99
|
+
claims.push({
|
|
100
|
+
...existing,
|
|
101
|
+
...draft,
|
|
102
|
+
source_claim_ids: sources(source_claim_ids, rawId),
|
|
103
|
+
updated_at: nextClaimUpdateAt(now, effectiveUpdatedAt(existing))
|
|
104
|
+
});
|
|
105
|
+
if (!usedClaimIds.includes(existing.id)) usedClaimIds.push(existing.id);
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
claims,
|
|
109
|
+
disputes: resolved.new_disputes.map((draft) => {
|
|
110
|
+
validateClaimText({
|
|
111
|
+
name: draft.name,
|
|
112
|
+
summary: draft.summary
|
|
113
|
+
});
|
|
114
|
+
const ids = draft.claims.map((raw) => {
|
|
115
|
+
const id = ClaimIdSchema.safeParse(raw);
|
|
116
|
+
requireValid(id.success && disputeClaims.has(raw), "Dispute 引用了本轮不可见的 Claim。");
|
|
117
|
+
return id.data;
|
|
118
|
+
});
|
|
119
|
+
requireValid(new Set(ids).size === ids.length, "Dispute 至少引用两条不同的 Claim。");
|
|
120
|
+
return {
|
|
121
|
+
...draft,
|
|
122
|
+
id: DisputeIdSchema.parse(draft.id),
|
|
123
|
+
claims: ids,
|
|
124
|
+
reporter_agent_id: agentId,
|
|
125
|
+
status: "open",
|
|
126
|
+
created_at: now
|
|
127
|
+
};
|
|
128
|
+
}),
|
|
129
|
+
usedClaimIds,
|
|
130
|
+
warnings
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
//#endregion
|
|
134
|
+
export { recapClaimIds as n, prepareFormation as t };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { c as readYamlOr, l as writeYamlAtomic, n as withFileLock } from "./lock-DbmlKOoX.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
//#region src/store/presentation.ts
|
|
5
|
+
const Schema = z.object({
|
|
6
|
+
schemaVersion: z.literal(1),
|
|
7
|
+
baselineAt: z.number(),
|
|
8
|
+
seen: z.record(z.string(), z.number())
|
|
9
|
+
});
|
|
10
|
+
var PresentationStore = class {
|
|
11
|
+
context;
|
|
12
|
+
path;
|
|
13
|
+
constructor(context) {
|
|
14
|
+
this.context = context;
|
|
15
|
+
this.path = join(context.paths.root, "presentation.yaml");
|
|
16
|
+
}
|
|
17
|
+
read() {
|
|
18
|
+
return readYamlOr(this.path, Schema, () => null);
|
|
19
|
+
}
|
|
20
|
+
async initialize() {
|
|
21
|
+
await withFileLock(`${this.path}.lock`, async () => {
|
|
22
|
+
if (await this.read() === null) await writeYamlAtomic(this.path, {
|
|
23
|
+
schemaVersion: 1,
|
|
24
|
+
baselineAt: Date.now(),
|
|
25
|
+
seen: {}
|
|
26
|
+
}, Schema, this.context.logger);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async acknowledge(id, version) {
|
|
30
|
+
await withFileLock(`${this.path}.lock`, async () => {
|
|
31
|
+
const current = await this.read() ?? {
|
|
32
|
+
schemaVersion: 1,
|
|
33
|
+
baselineAt: Date.now(),
|
|
34
|
+
seen: {}
|
|
35
|
+
};
|
|
36
|
+
await writeYamlAtomic(this.path, {
|
|
37
|
+
...current,
|
|
38
|
+
seen: {
|
|
39
|
+
...current.seen,
|
|
40
|
+
[id]: Math.max(version, current.seen[id] ?? 0)
|
|
41
|
+
}
|
|
42
|
+
}, Schema, this.context.logger);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
//#endregion
|
|
47
|
+
export { PresentationStore as t };
|
package/lib/protocol.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { S as timestampNanos, _ as deriveDisputeId, b as normalizeTimestamp, c as AgentIdSchema, d as InboxIdSchema, f as PolicyIdSchema, g as deriveClaimId, h as TraceIdSchema, i as effectiveUpdatedAt, l as ClaimIdSchema, m as SourceIdSchema, n as ClaimStatusSchema, p as ResolutionIdSchema, r as ConfidenceSchema, t as ClaimSchema, u as DisputeIdSchema, v as deriveTraceId, x as nowSeconds, y as TimestampSchema } from "./claim-DOAGe8ZK.js";
|
|
2
|
+
import { n as claimRevision, t as canonicalJson } from "./revision-DeoL_IUN.js";
|
|
3
|
+
import { t as TraceSchema } from "./trace-Da0RnL5R.js";
|
|
4
|
+
import { n as validateAgentReport, t as DisputeSchema } from "./dispute-CtrInHzf.js";
|
|
5
|
+
import { t as PolicySchema } from "./policy-DnyHh7Bl.js";
|
|
6
|
+
import { a as ArbitrationResolutionContextSchema, i as inboxEventAt, n as InboxMessageSchema, o as ClaimAssessmentSchema, r as InboxPullRequestSchema, s as DisputeResolutionSchema, t as InboxAckRequestSchema } from "./inbox-DFtE2fOp.js";
|
|
7
|
+
import { a as AgentQuerySchema, c as RouterQueryResultSchema, i as authRequestSchema, l as ScopeOverviewItemSchema, n as HealthRequestSchema, o as CandidateClaimSchema, r as HealthResponseSchema, s as DisputeRefSchema, t as AuthEnvelopeSchema, u as ScopesOverviewSnapshotSchema } from "./auth-DFI9yowX.js";
|
|
8
|
+
export { AgentIdSchema, AgentQuerySchema, ArbitrationResolutionContextSchema, AuthEnvelopeSchema, CandidateClaimSchema, ClaimAssessmentSchema, ClaimIdSchema, ClaimSchema, ClaimStatusSchema, ConfidenceSchema, DisputeIdSchema, DisputeRefSchema, DisputeResolutionSchema, DisputeSchema, HealthRequestSchema, HealthResponseSchema, InboxAckRequestSchema, InboxIdSchema, InboxMessageSchema, InboxPullRequestSchema, PolicyIdSchema, PolicySchema, ResolutionIdSchema, RouterQueryResultSchema, ScopeOverviewItemSchema, ScopesOverviewSnapshotSchema, SourceIdSchema, TimestampSchema, TraceIdSchema, TraceSchema, authRequestSchema, canonicalJson, claimRevision, deriveClaimId, deriveDisputeId, deriveTraceId, effectiveUpdatedAt, inboxEventAt, normalizeTimestamp, nowSeconds, timestampNanos, validateAgentReport };
|