@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,453 @@
|
|
|
1
|
+
import { n as ClaimStatusSchema, r as ConfidenceSchema } from "./claim-DOAGe8ZK.js";
|
|
2
|
+
import { t as KnowledgeError } from "./errors-Bp_2WXBr.js";
|
|
3
|
+
import { _ as JobError, c as readYamlOr, d as removeFile, f as writeTextAtomic, n as withFileLock, w as hasCode } from "./lock-DbmlKOoX.js";
|
|
4
|
+
import { n as VersionedDocumentSchema, t as SessionStateStore } from "./session-state-CYqUhC95.js";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import fs from "node:fs/promises";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
//#region src/formation/schema.ts
|
|
9
|
+
const draft = {
|
|
10
|
+
id: z.string(),
|
|
11
|
+
name: z.string(),
|
|
12
|
+
statement: z.string(),
|
|
13
|
+
scope: z.string(),
|
|
14
|
+
confidence: ConfidenceSchema,
|
|
15
|
+
evidence_summary: z.string(),
|
|
16
|
+
source_claim_ids: z.array(z.string())
|
|
17
|
+
};
|
|
18
|
+
const RecapOutputSchema = z.strictObject({
|
|
19
|
+
new_claims: z.array(z.strictObject(draft)),
|
|
20
|
+
updated_claims: z.array(z.strictObject({
|
|
21
|
+
...draft,
|
|
22
|
+
status: ClaimStatusSchema
|
|
23
|
+
})),
|
|
24
|
+
used_claim_ids: z.array(z.string()),
|
|
25
|
+
new_disputes: z.array(z.strictObject({
|
|
26
|
+
id: z.string(),
|
|
27
|
+
name: z.string(),
|
|
28
|
+
claims: z.array(z.string()).min(2),
|
|
29
|
+
summary: z.string()
|
|
30
|
+
}))
|
|
31
|
+
});
|
|
32
|
+
var FormationValidationError = class extends Error {
|
|
33
|
+
kind = "formation_validation";
|
|
34
|
+
};
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/formation/transcript.ts
|
|
37
|
+
const RouteSchema = z.strictObject({
|
|
38
|
+
provider: z.string().min(1),
|
|
39
|
+
model: z.string().min(1)
|
|
40
|
+
});
|
|
41
|
+
const seq = z.number().int().min(-1).max(Number.MAX_SAFE_INTEGER);
|
|
42
|
+
const FormationStateSchema = z.object({
|
|
43
|
+
lastSeenSeq: seq.default(-1),
|
|
44
|
+
recappedThroughSeq: seq.default(-1),
|
|
45
|
+
finalizedThroughSeq: seq.default(-1),
|
|
46
|
+
lastRoute: RouteSchema.optional(),
|
|
47
|
+
seenSourceIds: z.array(z.string()).default([]),
|
|
48
|
+
privateToolCalls: z.array(z.string()).default([]),
|
|
49
|
+
activityAt: z.number().int().nonnegative().default(0),
|
|
50
|
+
activitySeq: seq.default(-1),
|
|
51
|
+
humanTurn: z.boolean().default(false),
|
|
52
|
+
completedTurns: z.array(seq).default([]),
|
|
53
|
+
autoPaused: z.boolean().default(false),
|
|
54
|
+
archivedThroughSeq: seq.nullable().default(null),
|
|
55
|
+
archiveIntent: seq.nullable().default(null),
|
|
56
|
+
archivePending: z.boolean().default(false)
|
|
57
|
+
});
|
|
58
|
+
const TranscriptEntrySchema = z.strictObject({
|
|
59
|
+
seq: seq.refine((value) => value >= 0),
|
|
60
|
+
type: z.enum([
|
|
61
|
+
"user",
|
|
62
|
+
"assistant",
|
|
63
|
+
"tool_call",
|
|
64
|
+
"tool_result"
|
|
65
|
+
]),
|
|
66
|
+
text: z.string(),
|
|
67
|
+
projection: z.strictObject({
|
|
68
|
+
truncated: z.boolean(),
|
|
69
|
+
original_chars: z.number().int().nonnegative(),
|
|
70
|
+
retained_chars: z.number().int().nonnegative()
|
|
71
|
+
}).optional()
|
|
72
|
+
});
|
|
73
|
+
const processedThrough = (state) => Math.max(state.recappedThroughSeq, state.finalizedThroughSeq);
|
|
74
|
+
var TranscriptStore = class {
|
|
75
|
+
context;
|
|
76
|
+
maxBytes;
|
|
77
|
+
states;
|
|
78
|
+
constructor(context, maxBytes = 50 * 1024 * 1024) {
|
|
79
|
+
this.context = context;
|
|
80
|
+
this.maxBytes = maxBytes;
|
|
81
|
+
this.states = new SessionStateStore(context);
|
|
82
|
+
}
|
|
83
|
+
async state(id) {
|
|
84
|
+
return FormationStateSchema.parse(await this.states.read(id) ?? {});
|
|
85
|
+
}
|
|
86
|
+
async read(id, repair = false) {
|
|
87
|
+
let text = "";
|
|
88
|
+
try {
|
|
89
|
+
text = await fs.readFile(this.context.paths.transcript(id), "utf8");
|
|
90
|
+
} catch (error) {
|
|
91
|
+
if (!hasCode(error, "ENOENT")) throw error;
|
|
92
|
+
}
|
|
93
|
+
const complete = text.slice(0, text.lastIndexOf("\n") + 1);
|
|
94
|
+
const entries = complete.split("\n").filter(Boolean).map((line) => {
|
|
95
|
+
try {
|
|
96
|
+
return TranscriptEntrySchema.parse(JSON.parse(line));
|
|
97
|
+
} catch {
|
|
98
|
+
throw new JobError("transcript", "会话投影存在损坏的完整行;请检查本地 transcript 文件后重试。");
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
for (let index = 1; index < entries.length; index += 1) {
|
|
102
|
+
const previous = entries[index - 1];
|
|
103
|
+
const current = entries[index];
|
|
104
|
+
if (previous !== void 0 && current !== void 0 && current.seq <= previous.seq) throw new JobError("transcript", "会话投影的 seq 顺序损坏;请检查本地 transcript 后重试。");
|
|
105
|
+
}
|
|
106
|
+
if (repair && complete !== text) {
|
|
107
|
+
await writeTextAtomic(this.context.paths.transcript(id), complete, this.context.logger);
|
|
108
|
+
this.context.logger.warn("Repaired incomplete transcript tail.");
|
|
109
|
+
}
|
|
110
|
+
for (const file of await this.pendingFiles(id)) {
|
|
111
|
+
const body = await fs.readFile(join(this.context.paths.transcriptPending(id), file), "utf8");
|
|
112
|
+
let entry;
|
|
113
|
+
try {
|
|
114
|
+
entry = TranscriptEntrySchema.parse(JSON.parse(body));
|
|
115
|
+
} catch {
|
|
116
|
+
throw new JobError("transcript", "会话投影分片损坏;请检查本地 transcript-pending 后重试。");
|
|
117
|
+
}
|
|
118
|
+
if (`${entry.seq}.json` !== file) throw new JobError("transcript", "会话投影分片 seq 与文件名不一致。");
|
|
119
|
+
entries.push(entry);
|
|
120
|
+
}
|
|
121
|
+
const unique = /* @__PURE__ */ new Map();
|
|
122
|
+
for (const entry of entries) {
|
|
123
|
+
const previous = unique.get(entry.seq);
|
|
124
|
+
if (previous !== void 0 && JSON.stringify(previous) !== JSON.stringify(entry)) throw new JobError("transcript", "同一 seq 的会话投影内容冲突。");
|
|
125
|
+
unique.set(entry.seq, entry);
|
|
126
|
+
}
|
|
127
|
+
return [...unique.values()].sort((a, b) => a.seq - b.seq);
|
|
128
|
+
}
|
|
129
|
+
async pendingFiles(id) {
|
|
130
|
+
try {
|
|
131
|
+
return (await fs.readdir(this.context.paths.transcriptPending(id))).filter((file) => /^(0|[1-9][0-9]*)\.json$/.test(file));
|
|
132
|
+
} catch (error) {
|
|
133
|
+
if (hasCode(error, "ENOENT")) return [];
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async materialize(id, entries) {
|
|
138
|
+
let main = "";
|
|
139
|
+
let bytes = 0;
|
|
140
|
+
const spill = /* @__PURE__ */ new Set();
|
|
141
|
+
for (const entry of entries) {
|
|
142
|
+
const line = `${JSON.stringify(entry)}\n`;
|
|
143
|
+
const size = Buffer.byteLength(line);
|
|
144
|
+
if (size > this.maxBytes) throw new JobError("transcript_limit", "单条会话投影超过 50MB;请缩小单次输入后重试。");
|
|
145
|
+
if (bytes + size <= this.maxBytes) {
|
|
146
|
+
main += line;
|
|
147
|
+
bytes += size;
|
|
148
|
+
} else {
|
|
149
|
+
const file = `${entry.seq}.json`;
|
|
150
|
+
spill.add(file);
|
|
151
|
+
await writeTextAtomic(join(this.context.paths.transcriptPending(id), file), line, this.context.logger);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
await writeTextAtomic(this.context.paths.transcript(id), main, this.context.logger);
|
|
155
|
+
for (const file of await this.pendingFiles(id)) if (!spill.has(file)) await removeFile(join(this.context.paths.transcriptPending(id), file), this.context.logger);
|
|
156
|
+
return bytes;
|
|
157
|
+
}
|
|
158
|
+
async record(id, projection) {
|
|
159
|
+
await this.states.update(id, async (current) => {
|
|
160
|
+
const state = FormationStateSchema.parse(current ?? {});
|
|
161
|
+
const entries = await this.read(id, true);
|
|
162
|
+
const tail = entries.at(-1)?.seq ?? -1;
|
|
163
|
+
state.lastSeenSeq = Math.max(state.lastSeenSeq, tail);
|
|
164
|
+
if (projection.route !== void 0) state.lastRoute = projection.route;
|
|
165
|
+
if (projection.privateCallId !== void 0 && !state.privateToolCalls.includes(projection.privateCallId)) state.privateToolCalls.push(projection.privateCallId);
|
|
166
|
+
const privateResult = projection.resultCallId !== void 0 && state.privateToolCalls.includes(projection.resultCallId);
|
|
167
|
+
if (!privateResult) state.seenSourceIds = [.../* @__PURE__ */ new Set([...state.seenSourceIds, ...projection.seenSourceIds ?? []])];
|
|
168
|
+
const entry = projection.entry;
|
|
169
|
+
if (!privateResult && entry !== void 0 && entry.seq > state.lastSeenSeq) {
|
|
170
|
+
const line = `${JSON.stringify(entry)}\n`;
|
|
171
|
+
if (Buffer.byteLength(line) > this.maxBytes) throw new JobError("transcript_limit", "单条会话投影超过 50MB;请缩小单次输入后重试。");
|
|
172
|
+
let bytes = 0;
|
|
173
|
+
try {
|
|
174
|
+
bytes = (await fs.stat(this.context.paths.transcript(id))).size;
|
|
175
|
+
} catch (error) {
|
|
176
|
+
if (!hasCode(error, "ENOENT")) throw error;
|
|
177
|
+
}
|
|
178
|
+
if (bytes + Buffer.byteLength(line) > this.maxBytes) bytes = await this.materialize(id, entries.filter((row) => row.seq > processedThrough(state)));
|
|
179
|
+
if (bytes + Buffer.byteLength(line) > this.maxBytes) await writeTextAtomic(join(this.context.paths.transcriptPending(id), `${entry.seq}.json`), line, this.context.logger);
|
|
180
|
+
else {
|
|
181
|
+
const file = await fs.open(this.context.paths.transcript(id), "a", 384);
|
|
182
|
+
try {
|
|
183
|
+
await file.writeFile(line);
|
|
184
|
+
await file.sync();
|
|
185
|
+
} finally {
|
|
186
|
+
await file.close();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
state.lastSeenSeq = entry.seq;
|
|
190
|
+
}
|
|
191
|
+
const activity = projection.activity;
|
|
192
|
+
if (!privateResult && activity !== void 0 && activity.seq > state.activitySeq) {
|
|
193
|
+
state.activitySeq = activity.seq;
|
|
194
|
+
if (activity.turn === "start") state.humanTurn = false;
|
|
195
|
+
if (activity.human) {
|
|
196
|
+
state.humanTurn = true;
|
|
197
|
+
if (state.archiveIntent === null) state.autoPaused = false;
|
|
198
|
+
}
|
|
199
|
+
if (!state.autoPaused && state.archiveIntent === null) state.activityAt = Math.max(state.activityAt, activity.at);
|
|
200
|
+
if (activity.turn === "completed" && state.humanTurn && state.lastSeenSeq > processedThrough(state)) state.completedTurns.push(state.lastSeenSeq);
|
|
201
|
+
if (activity.turn === "completed" || activity.turn === "ended") state.humanTurn = false;
|
|
202
|
+
}
|
|
203
|
+
if (state.activityAt === 0 && state.lastSeenSeq >= 0) state.activityAt = Date.now();
|
|
204
|
+
return VersionedDocumentSchema.parse({
|
|
205
|
+
...current,
|
|
206
|
+
schemaVersion: 1,
|
|
207
|
+
...state
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
async replay(id, projections) {
|
|
212
|
+
await this.states.update(id, async (current) => {
|
|
213
|
+
const state = FormationStateSchema.parse(current ?? {});
|
|
214
|
+
const entries = new Map((await this.read(id, true)).map((entry) => [entry.seq, entry]));
|
|
215
|
+
const coveredThrough = projections.reduce((upper, projection) => Math.max(upper, projection.sourceSeq ?? -1, projection.entry?.seq ?? -1, projection.activity?.seq ?? -1), -1);
|
|
216
|
+
const unarchived = projections.some((projection) => projection.sourceArchived === false);
|
|
217
|
+
let resumedAt;
|
|
218
|
+
if ([...entries.values()].some((entry) => entry.seq > processedThrough(state) && entry.seq > coveredThrough)) throw new JobError("transcript_source", "Original session log does not cover the retained projection.");
|
|
219
|
+
state.privateToolCalls = [.../* @__PURE__ */ new Set([...state.privateToolCalls, ...projections.flatMap((projection) => projection.privateCallId === void 0 ? [] : [projection.privateCallId])])];
|
|
220
|
+
for (const projection of projections) {
|
|
221
|
+
if (projection.route !== void 0) state.lastRoute = projection.route;
|
|
222
|
+
if (projection.resultCallId !== void 0 && state.privateToolCalls.includes(projection.resultCallId)) {
|
|
223
|
+
if (projection.entry !== void 0) entries.delete(projection.entry.seq);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
state.seenSourceIds = [.../* @__PURE__ */ new Set([...state.seenSourceIds, ...projection.seenSourceIds ?? []])];
|
|
227
|
+
const entry = projection.entry;
|
|
228
|
+
if (entry !== void 0 && entry.seq > processedThrough(state)) {
|
|
229
|
+
const previous = entries.get(entry.seq);
|
|
230
|
+
if (previous !== void 0 && JSON.stringify(previous) !== JSON.stringify(entry)) throw new JobError("transcript", "原会话与已有投影内容冲突;未覆盖已有数据。");
|
|
231
|
+
entries.set(entry.seq, entry);
|
|
232
|
+
state.lastSeenSeq = Math.max(state.lastSeenSeq, entry.seq);
|
|
233
|
+
}
|
|
234
|
+
const activity = projection.activity;
|
|
235
|
+
if (activity?.human && unarchived && state.autoPaused && state.archiveIntent === null && state.archivedThroughSeq !== null && activity.seq > state.archivedThroughSeq) {
|
|
236
|
+
state.autoPaused = false;
|
|
237
|
+
resumedAt = activity.seq;
|
|
238
|
+
}
|
|
239
|
+
if (activity !== void 0 && resumedAt !== void 0 && activity.seq >= resumedAt) state.activityAt = Math.max(state.activityAt, activity.at);
|
|
240
|
+
if (activity !== void 0 && activity.seq > state.activitySeq) {
|
|
241
|
+
state.activitySeq = activity.seq;
|
|
242
|
+
if (activity.turn === "start") state.humanTurn = false;
|
|
243
|
+
if (activity.human) state.humanTurn = true;
|
|
244
|
+
if (!state.autoPaused && state.archiveIntent === null) state.activityAt = Math.max(state.activityAt, activity.at);
|
|
245
|
+
if (activity.turn === "completed" && state.humanTurn && state.lastSeenSeq > processedThrough(state)) state.completedTurns.push(state.lastSeenSeq);
|
|
246
|
+
if (activity.turn === "completed" || activity.turn === "ended") state.humanTurn = false;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const sorted = [...entries.values()].sort((left, right) => left.seq - right.seq);
|
|
250
|
+
await this.materialize(id, sorted);
|
|
251
|
+
state.lastSeenSeq = Math.max(state.lastSeenSeq, sorted.at(-1)?.seq ?? -1);
|
|
252
|
+
return VersionedDocumentSchema.parse({
|
|
253
|
+
...current,
|
|
254
|
+
schemaVersion: 1,
|
|
255
|
+
...state
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
async advance(id, kind, untilSeq) {
|
|
260
|
+
await this.states.update(id, async (current) => {
|
|
261
|
+
const state = FormationStateSchema.parse(current ?? {});
|
|
262
|
+
state.recappedThroughSeq = Math.max(state.recappedThroughSeq, untilSeq);
|
|
263
|
+
state.lastSeenSeq = Math.max(state.lastSeenSeq, untilSeq);
|
|
264
|
+
if (kind === "finalize") state.finalizedThroughSeq = Math.max(state.finalizedThroughSeq, untilSeq);
|
|
265
|
+
state.completedTurns = state.completedTurns.filter((end) => end > processedThrough(state));
|
|
266
|
+
const remaining = (await this.read(id, true)).filter((entry) => entry.seq > processedThrough(state));
|
|
267
|
+
await this.materialize(id, remaining);
|
|
268
|
+
return VersionedDocumentSchema.parse({
|
|
269
|
+
...current,
|
|
270
|
+
schemaVersion: 1,
|
|
271
|
+
...state
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
async lifecycle(id, change) {
|
|
276
|
+
return FormationStateSchema.parse(await this.states.update(id, (current) => {
|
|
277
|
+
const state = FormationStateSchema.parse(current ?? {});
|
|
278
|
+
change(state);
|
|
279
|
+
return VersionedDocumentSchema.parse({
|
|
280
|
+
...current,
|
|
281
|
+
schemaVersion: 1,
|
|
282
|
+
...state
|
|
283
|
+
});
|
|
284
|
+
}));
|
|
285
|
+
}
|
|
286
|
+
async sessions(formationOnly = false) {
|
|
287
|
+
let entries;
|
|
288
|
+
try {
|
|
289
|
+
entries = await fs.readdir(this.context.paths.sessions, { withFileTypes: true });
|
|
290
|
+
} catch (error) {
|
|
291
|
+
if (hasCode(error, "ENOENT")) return [];
|
|
292
|
+
throw error;
|
|
293
|
+
}
|
|
294
|
+
const ids = [];
|
|
295
|
+
for (const entry of entries) {
|
|
296
|
+
if (!entry.isDirectory() || !/^[a-zA-Z0-9_-]+$/.test(entry.name)) continue;
|
|
297
|
+
if (!formationOnly) {
|
|
298
|
+
ids.push(entry.name);
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
try {
|
|
302
|
+
const files = await fs.readdir(this.context.paths.session(entry.name));
|
|
303
|
+
if (files.includes("transcript.jsonl") || files.includes("transcript-pending")) {
|
|
304
|
+
ids.push(entry.name);
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
const state = await this.states.read(entry.name);
|
|
308
|
+
if (state !== null && Object.hasOwn(state, "lastSeenSeq")) ids.push(entry.name);
|
|
309
|
+
} catch {
|
|
310
|
+
ids.push(entry.name);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return ids;
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
//#endregion
|
|
317
|
+
//#region src/llm/structured.ts
|
|
318
|
+
const invalidLabels = {
|
|
319
|
+
json_syntax: "JSON 语法",
|
|
320
|
+
schema: "字段结构",
|
|
321
|
+
reference: "引用或领域约束",
|
|
322
|
+
incomplete: "输出未完整结束",
|
|
323
|
+
output_limit: "输出 token 上限(MAX_TOKENS)",
|
|
324
|
+
non_text: "缺少 JSON 文本或返回了工具调用、附件"
|
|
325
|
+
};
|
|
326
|
+
function abortable(promise, signal) {
|
|
327
|
+
return new Promise((resolve, reject) => {
|
|
328
|
+
const abort = () => {
|
|
329
|
+
const reason = signal.reason;
|
|
330
|
+
reject(reason instanceof Error ? reason : new JobError("aborted", "后台调用已取消。"));
|
|
331
|
+
};
|
|
332
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
333
|
+
if (signal.aborted) abort();
|
|
334
|
+
promise.then(resolve, reject).finally(() => {
|
|
335
|
+
signal.removeEventListener("abort", abort);
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
async function resolveRoute(config, context, sessionRoute) {
|
|
340
|
+
if (config.provider && config.model) return {
|
|
341
|
+
provider: config.provider,
|
|
342
|
+
model: config.model
|
|
343
|
+
};
|
|
344
|
+
if (sessionRoute !== void 0) return sessionRoute;
|
|
345
|
+
const route = await readYamlOr(context.paths.lastRoute, RouteSchema, () => null);
|
|
346
|
+
if (route === null) throw new JobError("route", "没有可用的模型路由。请先完成一次会话请求,或配置 llm.provider 和 llm.model 后重试任务。");
|
|
347
|
+
return route;
|
|
348
|
+
}
|
|
349
|
+
function transportError(error) {
|
|
350
|
+
if (error instanceof JobError) return error;
|
|
351
|
+
const record = typeof error === "object" && error !== null ? error : {};
|
|
352
|
+
const code = "code" in record && typeof record.code === "string" ? record.code : "";
|
|
353
|
+
const status = "status" in record && typeof record.status === "number" ? record.status : 0;
|
|
354
|
+
const delay = "providerRetryAfterMs" in record ? record.providerRetryAfterMs : void 0;
|
|
355
|
+
const retryAfterMs = typeof delay === "number" && Number.isFinite(delay) && delay > 0 && delay <= 2147483647 ? Math.ceil(delay) : void 0;
|
|
356
|
+
const retry = (kind, message) => new JobError(kind, message + (retryAfterMs === void 0 ? "" : ` 提供商要求至少等待 ${Math.ceil(retryAfterMs / 1e3)} 秒。`), true, retryAfterMs);
|
|
357
|
+
if (code === "CONTEXT_WINDOW_EXCEEDED") return new JobError("context_limit", "后台模型输入超过上下文容量(CONTEXT_WINDOW_EXCEEDED);请配置更大上下文的模型后重试任务。");
|
|
358
|
+
if (/^(?:AUTH|AUTH_FAILED|INVALID_CREDENTIAL|MISSING_CREDENTIAL)$/.test(code) || status === 401 || status === 403) return new JobError("model_auth", "后台模型鉴权失败(AUTH);请在 DSH 模型设置中检查提供商的凭据配置后重试。");
|
|
359
|
+
if (code === "QUOTA" || code === "ACCOUNT_QUOTA" || status === 402) return new JobError("model_quota", "后台模型额度不足(QUOTA);请检查提供商额度或更换知识处理模型后重试。");
|
|
360
|
+
if (code === "MALFORMED_RESPONSE") return new JobError("model_response", "后台模型返回的响应格式无效(MALFORMED_RESPONSE);可稍后重试或更换知识处理模型。");
|
|
361
|
+
if (code === "NO_ADAPTER") return new JobError("route", "后台模型适配器不可用(NO_ADAPTER);请检查 DSH 中的提供商与知识处理模型配置。");
|
|
362
|
+
if (code === "INVALID_REQUEST" || status === 400 || status === 413) return new JobError("model_request", "后台模型拒绝请求(INVALID_REQUEST);请检查所选模型支持的参数和上下文、输出上限。");
|
|
363
|
+
if (code === "EMPTY_RESPONSE") return retry("model_empty", "后台模型返回空响应(EMPTY_RESPONSE);可稍后重试或更换知识处理模型。");
|
|
364
|
+
if (code === "RATE_LIMIT" || code === "RATE_LIMITED" || status === 429) return retry("model_rate_limit", "后台模型请求受限(RATE_LIMIT);请稍后重试或检查提供商并发限制。");
|
|
365
|
+
if (code === "TIMEOUT" || code === "ETIMEDOUT" || code === "HTTP_408" || status === 408) return retry("timeout", "后台模型调用超时(TIMEOUT);请检查网络和模型服务,或调整超时后重试。");
|
|
366
|
+
if (code === "SERVER" || code === "SERVER_ERROR" || status >= 500 && status <= 599) return retry("model_server", "后台模型服务暂时不可用(SERVER);请稍后重试或更换知识处理模型。");
|
|
367
|
+
if (/^(?:NETWORK|TRANSPORT|NETWORK_ERROR|CONNECTION_ERROR|ECONNRESET|ECONNREFUSED)$/.test(code)) return retry("transport", "后台模型网络连接失败(TRANSPORT);请检查网络和模型服务后重试。");
|
|
368
|
+
return new JobError("route", "后台模型调用不可用。请检查 llm.provider、llm.model、适配器及凭据配置后重试任务。");
|
|
369
|
+
}
|
|
370
|
+
async function structuredCall(options) {
|
|
371
|
+
const { backend, context, config, route, jobId, signal } = options;
|
|
372
|
+
let feedback = "";
|
|
373
|
+
let lastInvalid;
|
|
374
|
+
for (let attempt = 1; attempt <= config.structuredRetries; attempt += 1) {
|
|
375
|
+
signal.throwIfAborted();
|
|
376
|
+
for (let transport = 1; transport <= 3; transport += 1) {
|
|
377
|
+
signal.throwIfAborted();
|
|
378
|
+
let response;
|
|
379
|
+
const startedAt = Date.now();
|
|
380
|
+
const timeout = AbortSignal.timeout(config.timeoutMs);
|
|
381
|
+
const callSignal = AbortSignal.any([signal, timeout]);
|
|
382
|
+
let outcome = "transport_failed";
|
|
383
|
+
let invalid;
|
|
384
|
+
try {
|
|
385
|
+
const schema = JSON.stringify(z.toJSONSchema(options.schema));
|
|
386
|
+
try {
|
|
387
|
+
response = await abortable(backend(route, `${options.system}\n只输出一个 JSON 对象,不调用工具。必须符合此 JSON schema:\n${schema}${feedback}`, options.input, config.maxOutputTokens, callSignal), callSignal);
|
|
388
|
+
} catch (error) {
|
|
389
|
+
signal.throwIfAborted();
|
|
390
|
+
if (error instanceof JobError && [
|
|
391
|
+
"structured_output",
|
|
392
|
+
"structured_output_limit",
|
|
393
|
+
"structured_output_content"
|
|
394
|
+
].includes(error.kind)) {
|
|
395
|
+
outcome = "invalid";
|
|
396
|
+
lastInvalid = error.kind === "structured_output_limit" ? "output_limit" : error.kind === "structured_output_content" ? "non_text" : "incomplete";
|
|
397
|
+
invalid = { kind: lastInvalid };
|
|
398
|
+
feedback = `\n上次响应未通过校验:${error.message}\n请重新提交完整 JSON 对象。`;
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
const failure = timeout.aborted ? transportError({ code: "TIMEOUT" }) : transportError(error);
|
|
402
|
+
if (!failure.retryable || transport === 3 || failure.retryAfterMs !== void 0) throw failure;
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
try {
|
|
406
|
+
const text = response.text.trim().replace(/^```(?:json)?\s*\n?([\s\S]*?)\n?```$/i, "$1");
|
|
407
|
+
const value = JSON.parse(text);
|
|
408
|
+
const result = options.parse(options.schema.parse(value));
|
|
409
|
+
outcome = "succeeded";
|
|
410
|
+
return result;
|
|
411
|
+
} catch (error) {
|
|
412
|
+
if (!(error instanceof SyntaxError || error instanceof z.ZodError || error instanceof FormationValidationError || error instanceof KnowledgeError)) throw error;
|
|
413
|
+
const summary = error instanceof z.ZodError ? error.issues.slice(0, 8).map((issue) => `${issue.path.join(".") || "$"}: ${issue.code}${issue.code === "unrecognized_keys" ? `;删除多余字段 ${JSON.stringify(issue.keys.slice(0, 8)).slice(0, 400)}` : ""}`).join("; ") : error instanceof FormationValidationError || error instanceof KnowledgeError ? error.message : "JSON 解析失败:检查字段名后的冒号、逗号、引号和转义;不要输出注释或省略号。";
|
|
414
|
+
lastInvalid = error instanceof z.ZodError ? "schema" : error instanceof SyntaxError ? "json_syntax" : "reference";
|
|
415
|
+
invalid = {
|
|
416
|
+
kind: lastInvalid,
|
|
417
|
+
...error instanceof z.ZodError ? { issueCodes: [...new Set(error.issues.map((issue) => issue.code))] } : {}
|
|
418
|
+
};
|
|
419
|
+
outcome = "invalid";
|
|
420
|
+
feedback = `\n上次响应未通过校验:${summary}\n请重新提交完整 JSON 对象。`;
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
} finally {
|
|
424
|
+
const day = new Date(startedAt).toISOString().slice(0, 10);
|
|
425
|
+
const path = join(context.paths.llmCalls, `${day}.jsonl`);
|
|
426
|
+
await withFileLock(`${path}.lock`, async () => {
|
|
427
|
+
await fs.mkdir(context.paths.llmCalls, { recursive: true });
|
|
428
|
+
const file = await fs.open(path, "a", 384);
|
|
429
|
+
try {
|
|
430
|
+
await file.writeFile(`${JSON.stringify({
|
|
431
|
+
jobId,
|
|
432
|
+
route,
|
|
433
|
+
...options.phase === void 0 ? {} : { phase: options.phase },
|
|
434
|
+
attempt,
|
|
435
|
+
transport,
|
|
436
|
+
startedAt,
|
|
437
|
+
elapsedMs: Date.now() - startedAt,
|
|
438
|
+
outcome,
|
|
439
|
+
...invalid === void 0 ? {} : { invalid },
|
|
440
|
+
...response?.usage === void 0 ? {} : { usage: response.usage }
|
|
441
|
+
})}\n`);
|
|
442
|
+
await file.sync();
|
|
443
|
+
} finally {
|
|
444
|
+
await file.close();
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
throw new JobError("structured_output", `${options.phase === void 0 ? "" : `${options.phase} 阶段:`}连续 ${config.structuredRetries} 次响应未通过结构或引用校验${lastInvalid === void 0 ? "" : `(最后失败:${invalidLabels[lastInvalid]})`};请检查模型后使用 /acn-status retry 重试任务。`);
|
|
451
|
+
}
|
|
452
|
+
//#endregion
|
|
453
|
+
export { FormationStateSchema as a, TranscriptStore as c, RecapOutputSchema as d, transportError as i, processedThrough as l, resolveRoute as n, RouteSchema as o, structuredCall as r, TranscriptEntrySchema as s, abortable as t, FormationValidationError as u };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/tools/subagent.ts
|
|
2
|
+
function isSubagent(header) {
|
|
3
|
+
return header.origin === "subagent" || (header.delegationDepth ?? 0) > 0;
|
|
4
|
+
}
|
|
5
|
+
function isEvidenceAgent(header) {
|
|
6
|
+
return header.origin === "subagent" && (header.agentPreset === "acn-evidence" || header.agentPreset === "acn-dream");
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { isSubagent as n, isEvidenceAgent as t };
|
package/lib/team.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { t as TeamError } from "./errors-pPumDOGD.js";
|
|
2
|
+
import { a as bypassProxy, i as TeamHttp, n as MaintainerClient, o as teamUrl, r as RouterClient, t as TeamFacade } from "./service-BQaszW_v.js";
|
|
3
|
+
export { MaintainerClient, RouterClient, TeamError, TeamFacade, TeamHttp, bypassProxy, teamUrl };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/dsh-adapter/tool-schema.ts
|
|
3
|
+
const JsonObject = z.record(z.string(), z.json());
|
|
4
|
+
function toolParameters(schema) {
|
|
5
|
+
const root = JsonObject.parse(JSON.parse(JSON.stringify(z.toJSONSchema(schema))));
|
|
6
|
+
if (!Array.isArray(root.oneOf)) return root;
|
|
7
|
+
const variants = root.oneOf.map((value) => JsonObject.parse(value));
|
|
8
|
+
const fields = variants.map((variant) => JsonObject.parse(variant.properties));
|
|
9
|
+
const keys = [...new Set(fields.flatMap((field) => Object.keys(field)))];
|
|
10
|
+
const properties = Object.fromEntries(keys.map((key) => {
|
|
11
|
+
const distinct = [...new Map(fields.filter((field) => field[key] !== void 0).map((field) => [JSON.stringify(field[key]), JsonObject.parse(field[key])])).values()];
|
|
12
|
+
const values = distinct.map((field) => field.const);
|
|
13
|
+
return [key, distinct.length === 1 ? distinct[0] : values.every((value) => typeof value === "string") ? {
|
|
14
|
+
type: "string",
|
|
15
|
+
enum: values
|
|
16
|
+
} : { anyOf: distinct }];
|
|
17
|
+
}));
|
|
18
|
+
const requiredSets = variants.map((variant) => z.array(z.string()).parse(variant.required ?? []));
|
|
19
|
+
const required = (requiredSets[0] ?? []).filter((key) => requiredSets.every((set) => set.includes(key)));
|
|
20
|
+
return JsonObject.parse({
|
|
21
|
+
...root,
|
|
22
|
+
type: "object",
|
|
23
|
+
properties,
|
|
24
|
+
required
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { toolParameters as t };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { a as TextSchema, c as AgentIdSchema, h as TraceIdSchema, l as ClaimIdSchema, m as SourceIdSchema, y as TimestampSchema } from "./claim-DOAGe8ZK.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region src/protocol/trace.ts
|
|
4
|
+
const TraceSchema = z.object({
|
|
5
|
+
id: TraceIdSchema,
|
|
6
|
+
name: TextSchema,
|
|
7
|
+
task: TextSchema,
|
|
8
|
+
agent: AgentIdSchema,
|
|
9
|
+
input_claims: z.array(SourceIdSchema).default([]),
|
|
10
|
+
output_claims: z.array(ClaimIdSchema).default([]),
|
|
11
|
+
created_at: TimestampSchema
|
|
12
|
+
});
|
|
13
|
+
//#endregion
|
|
14
|
+
export { TraceSchema as t };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { h as TraceIdSchema } from "./claim-DOAGe8ZK.js";
|
|
2
|
+
import { a as EntityStore } from "./reported-sets-DdEKdeVb.js";
|
|
3
|
+
import { t as TraceSchema } from "./trace-Da0RnL5R.js";
|
|
4
|
+
//#region src/store/traces.ts
|
|
5
|
+
var TraceStore = class extends EntityStore {
|
|
6
|
+
constructor(context) {
|
|
7
|
+
super(context, context.paths.traces, TraceSchema, TraceIdSchema);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { TraceStore as t };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { AcnKnowledge } from './knowledge/service.js';
|
|
2
|
+
import type { JobKind } from './worker/types.js';
|
|
3
|
+
import type { Activity } from './interaction.js';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
export declare function activityDetails(result: unknown): {
|
|
6
|
+
counts: {
|
|
7
|
+
[k: string]: number;
|
|
8
|
+
};
|
|
9
|
+
entityIds: ((string & z.core.$brand<"ClaimId">) | (string & z.core.$brand<"TraceId">) | (string & z.core.$brand<"DisputeId">))[];
|
|
10
|
+
summary: string;
|
|
11
|
+
warnings: string[];
|
|
12
|
+
incompleteCandidates: {
|
|
13
|
+
groupId: string;
|
|
14
|
+
claimIds: (string & z.core.$brand<"ClaimId">)[];
|
|
15
|
+
reason: string;
|
|
16
|
+
}[];
|
|
17
|
+
budgetLimited: boolean;
|
|
18
|
+
};
|
|
19
|
+
export declare function emptyInbox(result: unknown): boolean;
|
|
20
|
+
export declare function allActivities(knowledge: AcnKnowledge, supports?: (kind: JobKind) => boolean): Promise<Activity[]>;
|
|
21
|
+
export interface ActivityPage {
|
|
22
|
+
attentionOnly?: boolean;
|
|
23
|
+
sourceSession?: string;
|
|
24
|
+
kind?: string;
|
|
25
|
+
state?: string;
|
|
26
|
+
offset?: number;
|
|
27
|
+
}
|
|
28
|
+
export declare function activityPage(rows: Activity[], options?: ActivityPage): {
|
|
29
|
+
activities: {
|
|
30
|
+
id: string;
|
|
31
|
+
kind: string;
|
|
32
|
+
state: string;
|
|
33
|
+
attempts: number;
|
|
34
|
+
updatedAt: number;
|
|
35
|
+
unseen: boolean;
|
|
36
|
+
summary: string;
|
|
37
|
+
sessionId?: string | undefined;
|
|
38
|
+
source?: {
|
|
39
|
+
id: string;
|
|
40
|
+
available: boolean;
|
|
41
|
+
title?: string | undefined;
|
|
42
|
+
} | undefined;
|
|
43
|
+
error?: string | undefined;
|
|
44
|
+
summaryInfo?: {
|
|
45
|
+
code: string;
|
|
46
|
+
count?: number | undefined;
|
|
47
|
+
entityId?: string | undefined;
|
|
48
|
+
status?: number | undefined;
|
|
49
|
+
} | undefined;
|
|
50
|
+
errorInfo?: {
|
|
51
|
+
code: string;
|
|
52
|
+
count?: number | undefined;
|
|
53
|
+
entityId?: string | undefined;
|
|
54
|
+
status?: number | undefined;
|
|
55
|
+
} | undefined;
|
|
56
|
+
counts?: Record<string, number> | undefined;
|
|
57
|
+
warnings?: string[] | undefined;
|
|
58
|
+
budgetLimited?: boolean | undefined;
|
|
59
|
+
requiresAttention?: boolean | undefined;
|
|
60
|
+
incompleteCandidates?: {
|
|
61
|
+
groupId: string;
|
|
62
|
+
claimIds: (string & z.core.$brand<"ClaimId">)[];
|
|
63
|
+
reason: string;
|
|
64
|
+
}[] | undefined;
|
|
65
|
+
entityIds?: ((string & z.core.$brand<"ClaimId">) | (string & z.core.$brand<"TraceId">) | (string & z.core.$brand<"DisputeId">))[] | undefined;
|
|
66
|
+
entityId?: string | undefined;
|
|
67
|
+
retryable?: boolean | undefined;
|
|
68
|
+
acknowledged?: boolean | undefined;
|
|
69
|
+
reportPath?: string | undefined;
|
|
70
|
+
phase?: "finished" | "wrap_up" | "exploration" | undefined;
|
|
71
|
+
}[];
|
|
72
|
+
activitiesOmitted: number;
|
|
73
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const AdvancedConfigurationSchema: z.ZodObject<{
|
|
3
|
+
inboxProcessingStaleAfterSecs: z.ZodNumber;
|
|
4
|
+
routerQueryTimeoutSecs: z.ZodNumber;
|
|
5
|
+
httpTimeoutSecs: z.ZodNumber;
|
|
6
|
+
httpRetryCount: z.ZodNumber;
|
|
7
|
+
httpRetryBaseDelayMs: z.ZodNumber;
|
|
8
|
+
httpRetryMaxDelayMs: z.ZodNumber;
|
|
9
|
+
}, z.core.$strict>;
|
|
10
|
+
export type AdvancedConfiguration = z.infer<typeof AdvancedConfigurationSchema>;
|
|
11
|
+
export declare function advancedConfiguration(raw: unknown): AdvancedConfiguration;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Activity, InteractionRequest } from '../interaction.js';
|
|
2
|
+
import type { InteractionApi } from './TeamSettingsPage.js';
|
|
3
|
+
import type { Copy } from './interaction-ui.js';
|
|
4
|
+
export declare function ActivityCard(props: {
|
|
5
|
+
item: Activity;
|
|
6
|
+
runtimeKey: string;
|
|
7
|
+
busy: boolean;
|
|
8
|
+
c: Copy;
|
|
9
|
+
api: InteractionApi;
|
|
10
|
+
action: (request: InteractionRequest) => void;
|
|
11
|
+
openSource?: ((id: string) => void) | undefined;
|
|
12
|
+
openClaim: (id: string, from: string) => void;
|
|
13
|
+
openComponents?: (() => void) | undefined;
|
|
14
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { InteractionApi } from './TeamSettingsPage.js';
|
|
2
|
+
import type { Activity, InteractionRequest } from '../interaction.js';
|
|
3
|
+
import type { Copy } from './interaction-ui.js';
|
|
4
|
+
export declare function activityKind(kind: string, c: Copy): string;
|
|
5
|
+
export declare function activityState(item: Activity, c: Copy): string;
|
|
6
|
+
export declare function activitySummary(item: Activity, c: Copy): string;
|
|
7
|
+
export declare function ActivityDetails({ item, runtimeKey, busy, c, showSummary, action, openClaim, openComponents }: {
|
|
8
|
+
item: Activity;
|
|
9
|
+
runtimeKey: string;
|
|
10
|
+
busy: boolean;
|
|
11
|
+
c: Copy;
|
|
12
|
+
api: InteractionApi;
|
|
13
|
+
showSummary?: boolean;
|
|
14
|
+
action: (request: InteractionRequest) => void;
|
|
15
|
+
openSource?: ((id: string) => void) | undefined;
|
|
16
|
+
openClaim: (id: string, from: string) => void;
|
|
17
|
+
openComponents?: (() => void) | undefined;
|
|
18
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AdvancedConfiguration } from '../advanced-configuration.js';
|
|
2
|
+
import type { Copy } from './interaction-ui.js';
|
|
3
|
+
export declare function AdvancedPreferences({ value, busy, c, save }: {
|
|
4
|
+
value: AdvancedConfiguration;
|
|
5
|
+
busy: boolean;
|
|
6
|
+
c: Copy;
|
|
7
|
+
save: (value: AdvancedConfiguration) => Promise<boolean>;
|
|
8
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CommandResult } from '@deepseek-ai/dsh-commands';
|
|
2
|
+
import type { Copy } from './interaction-ui.js';
|
|
3
|
+
type Listener = (sessionId: string, name: string, result: CommandResult) => void;
|
|
4
|
+
export declare function BlankCommandFeedback({ sessionId, blank, subscribe, c }: {
|
|
5
|
+
sessionId: string;
|
|
6
|
+
blank: boolean;
|
|
7
|
+
subscribe: (listener: Listener) => () => void;
|
|
8
|
+
c: Copy;
|
|
9
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
10
|
+
export {};
|