@alpacachen/dsh-kanban 1.11.2 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +78 -49
- package/README.zh.md +77 -48
- package/cordis.patch.yml +2 -0
- package/docs/guide.md +1 -1
- package/docs/guide.zh.md +1 -1
- package/docs/readme/workflow-en-mobile.svg +28 -0
- package/docs/readme/workflow-en.svg +28 -0
- package/docs/readme/workflow-zh-mobile.svg +28 -0
- package/docs/readme/workflow-zh.svg +28 -0
- package/docs/testing-images.md +12 -0
- package/docs/workflow-guide.en.md +87 -0
- package/docs/workflow-guide.md +85 -0
- package/docs/workflow-model.schema.sql +303 -0
- package/docs/workflow-validation.md +82 -0
- package/lib/client.js +989 -17
- package/package.json +39 -22
- package/workflow/dsh-adapter.js +206 -0
- package/workflow/index.js +334 -0
- package/workflow/locale/en.json +6 -0
- package/workflow/locale/zh.json +6 -0
- package/workflow/management-tools.js +160 -0
- package/workflow/recovery.js +75 -0
- package/workflow/review-api.js +296 -0
- package/workflow/runner.js +348 -0
- package/workflow/stage-trace.js +65 -0
- package/workflow/store.js +900 -0
- package/workflow/task-files.js +133 -0
- package/docs/readme/cover-en-mobile.png +0 -0
- package/docs/readme/cover-en.png +0 -0
- package/docs/readme/cover-zh-mobile.png +0 -0
- package/docs/readme/cover-zh.png +0 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const elapsed = (start, end) => Number.isFinite(start) && Number.isFinite(end) && end >= start ? end - start : null
|
|
2
|
+
const time = value => Number.isFinite(value) ? value : null
|
|
3
|
+
const stepKey = data => `${data.turn}:${data.step}`
|
|
4
|
+
const callKey = (data, id) => `${stepKey(data)}:${id}`
|
|
5
|
+
|
|
6
|
+
/** A stage Session may later be reopened for chat; only return this Attempt's own turn. */
|
|
7
|
+
export function stageEventWindow(events, attempt) {
|
|
8
|
+
const fail = () => { throw Object.assign(new Error('本次阶段执行尚无可核对的完整会话起点。'), { code: 'WF_TRACE_UNAVAILABLE' }) }
|
|
9
|
+
const input = events.find(event => event.type === 'user/message' && event.data?.source?.rpcId === attempt.requestId
|
|
10
|
+
&& (!attempt.messageId || event.data.id === attempt.messageId))
|
|
11
|
+
if (!input) fail()
|
|
12
|
+
const start = events.findLast(event => event.type === 'turn/start' && event.seq < input.seq)
|
|
13
|
+
if (!start || attempt.turnNumber != null && start.data.turn !== attempt.turnNumber) fail()
|
|
14
|
+
const end = events.find(event => event.type === 'turn/end' && event.seq > input.seq && event.data.turn === start.data.turn)
|
|
15
|
+
const nextTurn = events.find(event => event.type === 'turn/start' && event.seq > start.seq)
|
|
16
|
+
const last = end?.seq ?? (nextTurn ? nextTurn.seq - 1 : Infinity)
|
|
17
|
+
return events.filter(event => event.seq >= start.seq && event.seq <= last)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Read-only, task-owned projections. Transport headers/configuration are never returned. */
|
|
21
|
+
export function projectStageTrace(task, attempt, events, { fromSeq = 0, limit = 50, firstTokenTime = () => undefined } = {}) {
|
|
22
|
+
const starts = new Map(), calls = new Map(), tools = [], modelResponses = [], entries = []
|
|
23
|
+
for (const event of events) {
|
|
24
|
+
const data = event.data ?? {}, key = stepKey(data), at = time(event.time)
|
|
25
|
+
if (event.type === 'step/start') starts.set(key, at)
|
|
26
|
+
if (event.type === 'tool/call') {
|
|
27
|
+
const tool = { callId: data.callId, name: data.name, turn: data.turn, step: data.step, startedAt: at, finishedAt: null, elapsedMs: null, isError: null }
|
|
28
|
+
tools.push(tool); calls.set(callKey(data, data.callId), tool)
|
|
29
|
+
}
|
|
30
|
+
if (event.type === 'tool/result') {
|
|
31
|
+
const tool = calls.get(callKey(data, data.message?.toolCallId))
|
|
32
|
+
if (tool) { tool.finishedAt = at; tool.elapsedMs = elapsed(tool.startedAt, at); tool.isError = data.message?.isError === true }
|
|
33
|
+
}
|
|
34
|
+
if (event.type === 'assistant/message' || event.type === 'assistant/attempt') {
|
|
35
|
+
let first = null
|
|
36
|
+
try { first = time(firstTokenTime(data.stream ?? [])) } catch { /* Old logs may lack compatible stream timing. */ }
|
|
37
|
+
const startedAt = starts.get(key) ?? null
|
|
38
|
+
modelResponses.push({ seq: event.seq, turn: data.turn, step: data.step, stepStartedAt: startedAt, firstTokenAt: first, settledAt: at,
|
|
39
|
+
stepToResponseMs: elapsed(startedAt, at), firstOutputWaitMs: elapsed(startedAt, first), usage: data.usage ?? null, interrupted: data.interrupted === true, hasMessage: event.type === 'assistant/message' })
|
|
40
|
+
}
|
|
41
|
+
let detail
|
|
42
|
+
if (event.type === 'user/message') detail = { role: 'user', content: data.content, source: data.source?.kind ?? null }
|
|
43
|
+
else if (event.type === 'developer/message') detail = { role: 'context', content: data.message?.content }
|
|
44
|
+
else if (event.type === 'assistant/message') detail = { role: 'assistant', turn: data.turn, step: data.step, content: data.message?.content, usage: data.usage ?? null, interrupted: data.interrupted === true }
|
|
45
|
+
else if (event.type === 'assistant/attempt') detail = { turn: data.turn, step: data.step, stream: (data.stream ?? []).filter(record => ['text-chunks', 'reasoning-chunks', 'tool-call-chunks'].includes(record.type)) }
|
|
46
|
+
else if (event.type === 'tool/call') detail = { turn: data.turn, step: data.step, callId: data.callId, name: data.name, arguments: data.arguments }
|
|
47
|
+
else if (event.type === 'tool/result') detail = { turn: data.turn, step: data.step, callId: data.message?.toolCallId, content: data.message?.content, isError: data.message?.isError === true, error: data.error ?? null }
|
|
48
|
+
else if (['turn/start', 'turn/end', 'step/start', 'step/end'].includes(event.type)) detail = { turn: data.turn, step: data.step, reason: data.reason?.kind ?? null }
|
|
49
|
+
else if (/^(approval\/|compaction\/|llm\/retry$)/.test(event.type)) detail = Object.fromEntries(Object.entries(data).filter(([name, value]) => ['id', 'requestId', 'callId', 'toolCallId', 'decision', 'status', 'turn', 'step', 'delayMs', 'attempt', 'code'].includes(name) && (value === null || ['string', 'number', 'boolean'].includes(typeof value))))
|
|
50
|
+
if (detail) entries.push({ seq: event.seq, time: at, type: event.type, ...Object.fromEntries(Object.entries(detail).filter(([, value]) => value !== undefined)) })
|
|
51
|
+
}
|
|
52
|
+
const intervals = tools.filter(tool => tool.elapsedMs !== null).map(tool => [tool.startedAt, tool.finishedAt]).sort((a, b) => a[0] - b[0])
|
|
53
|
+
let toolWallMs = 0, end = -Infinity
|
|
54
|
+
for (const [start, finish] of intervals) { toolWallMs += Math.max(0, finish - Math.max(start, end)); end = Math.max(end, finish) }
|
|
55
|
+
const selected = entries.filter(entry => entry.seq >= fromSeq), page = selected.slice(0, limit)
|
|
56
|
+
const visit = task.visits.find(visit => visit.id === attempt.visitId)
|
|
57
|
+
return { taskId: task.id, workflowId: task.workflowId, workflowVersionId: task.workflowVersionId, versionNumber: task.versionNumber,
|
|
58
|
+
stageId: visit.stageId, attemptId: attempt.id, sessionId: attempt.sessionId, state: attempt.state, persistedOnly: true,
|
|
59
|
+
summary: { stageElapsedMs: elapsed(attempt.createdAt, attempt.settledAt), modelResponseCount: modelResponses.length, toolCallCount: tools.length,
|
|
60
|
+
toolFailureCount: tools.filter(tool => tool.isError).length, unfinishedToolCount: tools.filter(tool => tool.finishedAt === null).length,
|
|
61
|
+
observedToolWallMs: tools.length && !intervals.length ? null : toolWallMs, retryCount: events.filter(event => event.type === 'llm/retry').length,
|
|
62
|
+
compactionCount: events.filter(event => event.type === 'compaction/start').length, approvalRequestCount: events.filter(event => event.type === 'approval/requested').length },
|
|
63
|
+
timingNotes: 'Times come from persisted DSH wall-clock events. Tool call-to-result includes any queue/authorization waiting; observedToolWallMs merges overlapping intervals. stepToResponseMs and firstOutputWaitMs begin at step/start, so they may include preparation and retry backoff. Missing measurements are null. Model-server internal queue time and tool-internal substeps are not measured here. Live persistence can lag.',
|
|
64
|
+
tools, modelResponses, entries: page, nextFromSeq: selected.length > page.length ? page.at(-1).seq + 1 : null }
|
|
65
|
+
}
|