tavi-interaction-chain 0.3.0 → 0.4.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 +14 -0
- package/dist/panel-controller.d.ts +11 -0
- package/dist/panel-controller.js +35 -19
- package/dist/panel.d.ts +1 -1
- package/dist/panel.js +8 -1
- package/dist/tavi-workflow-model.d.ts +1 -1
- package/dist/tavi-workflow-model.js +2 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,3 +20,17 @@ onBeforeUnmount(() => panel?.dispose())
|
|
|
20
20
|
面板自带主题、交互画布、折叠摘要和缩放控件。样式封装在 Shadow DOM 中。默认展示工作流定义,可通过第二个参数传入 `issue` 或 `boardUrl` 接入真实台账。`run` 选择台账中的运行,`theme` 指定 light 或 dark,`showChildCards` 默认为 true。挂载后可调用 `panel.setShowChildCards(false)` 隐藏字段分叉。
|
|
21
21
|
|
|
22
22
|
只需要通用画布时,从主入口导入 `renderWorkflowCanvas`,并按需加载 `tavi-interaction-chain/style.css` 和 `tavi-interaction-chain/theme.css`。
|
|
23
|
+
|
|
24
|
+
## 自定义阶段
|
|
25
|
+
|
|
26
|
+
`stages` 按执行顺序排列。省略时使用 Tavi 的默认四阶段。每个阶段有唯一的 `key` 和显示标题 `title`,可以提供 `mark`、悬停说明 `summary` 和 0–3 张 `children` 子卡。子卡可写标题字符串或 `{label, value}`;值随 `onStage` 回调返回。整张图最多 40 张卡片。运行位置使用从 0 开始的阶段索引,耗时取自 `issue.stageTimings[key]`。
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
renderWorkflowPanel(host, {
|
|
30
|
+
stages: [
|
|
31
|
+
{key: 'scope', title: '需求确认', children: ['验收条件']},
|
|
32
|
+
{key: 'build', title: '开发实现', children: ['项目', '开发分支']},
|
|
33
|
+
{key: 'ship', title: '发布上线', children: ['发布记录']},
|
|
34
|
+
],
|
|
35
|
+
})
|
|
36
|
+
```
|
|
@@ -6,7 +6,18 @@ export interface StagePreview {
|
|
|
6
6
|
timing: string;
|
|
7
7
|
rows: [string, string | undefined][];
|
|
8
8
|
}
|
|
9
|
+
export interface PanelStage {
|
|
10
|
+
key: string;
|
|
11
|
+
title: string;
|
|
12
|
+
summary?: string;
|
|
13
|
+
mark?: string;
|
|
14
|
+
children?: readonly (string | {
|
|
15
|
+
label: string;
|
|
16
|
+
value?: string;
|
|
17
|
+
})[];
|
|
18
|
+
}
|
|
9
19
|
export interface WorkflowPanelOptions {
|
|
20
|
+
stages?: readonly PanelStage[];
|
|
10
21
|
theme?: 'light' | 'dark';
|
|
11
22
|
showChildCards?: boolean;
|
|
12
23
|
issue?: AutomationIssue;
|
package/dist/panel-controller.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { renderWorkflowCanvas, toTopology } from './index.js';
|
|
2
2
|
import { WORKFLOW_STAGES, stageStateLabel, stageElapsedMs, formatStageDuration } from './tavi-workflow-model.js';
|
|
3
3
|
export function mountWorkflow(panel, root, options = {}) {
|
|
4
|
+
const stages = options.stages ?? WORKFLOW_STAGES;
|
|
5
|
+
if (!stages.length || new Set(stages.map(stage => stage.key)).size !== stages.length)
|
|
6
|
+
throw new TypeError('stages must contain at least one stage and unique keys');
|
|
7
|
+
if (stages.some(stage => (stage.children?.length ?? 0) > 3))
|
|
8
|
+
throw new RangeError('Each stage supports up to three child cards');
|
|
9
|
+
if (stages.reduce((total, stage) => total + 1 + (stage.children?.length ?? 0), 0) > 40)
|
|
10
|
+
throw new RangeError('A workflow supports up to 40 cards');
|
|
4
11
|
const controller = new AbortController();
|
|
5
12
|
let release;
|
|
6
13
|
let selected;
|
|
@@ -21,30 +28,30 @@ export function mountWorkflow(panel, root, options = {}) {
|
|
|
21
28
|
};
|
|
22
29
|
function show(issue) {
|
|
23
30
|
selected = issue;
|
|
24
|
-
const labels =
|
|
25
|
-
const durations =
|
|
26
|
-
const current = issue && (
|
|
27
|
-
el('summary-stage').textContent = current !== undefined ?
|
|
31
|
+
const labels = stages.map((_, i) => !issue ? '等待运行数据' : options.stages && i < issue.completed ? '已完成' : stageStateLabel(issue, i));
|
|
32
|
+
const durations = stages.map((stage, i) => issue ? formatStageDuration(stageElapsedMs(issue, i, Date.now(), stage.key)) : '—');
|
|
33
|
+
const current = issue && (stages[issue.current] ? issue.current : issue.stage);
|
|
34
|
+
el('summary-stage').textContent = current !== undefined ? stages[current]?.title ?? '未知' : '未知';
|
|
28
35
|
el('summary-state').textContent = issue?.stateLabel || '未知';
|
|
29
36
|
el('summary-state').dataset.state = issue?.state ?? 'unknown';
|
|
30
37
|
el('summary-duration').textContent = current !== undefined ? durations[current] ?? '—' : '—';
|
|
31
|
-
const steps =
|
|
38
|
+
const steps = stages.map((stage, i) => ({
|
|
32
39
|
id: stage.key, label: stage.title, description: stage.summary,
|
|
33
|
-
kind: i === 0 ? 'plan' : i ===
|
|
40
|
+
kind: i === 0 ? 'plan' : i === stages.length - 1 ? 'output' : 'tool',
|
|
34
41
|
status: !issue ? 'unknown' : i < issue.completed ? 'completed' : i !== issue.current ? 'queued' :
|
|
35
42
|
{ waiting: 'waiting', failed: 'failed', canceled: 'cancelled', queued: 'queued' }[issue.state] ?? 'running',
|
|
36
43
|
}));
|
|
37
44
|
const graph = toTopology({ version: 1, steps });
|
|
38
|
-
const timingDetails =
|
|
45
|
+
const timingDetails = stages.map((stage, i) => {
|
|
39
46
|
const since = issue?.stageTimings?.[stage.key]?.runningSince;
|
|
40
47
|
const start = since ? Date.parse(since) : NaN;
|
|
41
48
|
const clock = Number.isFinite(start) ? new Date(start).toLocaleTimeString('zh-CN', { hour12: false }) : '';
|
|
42
|
-
return ['阶段 ' + (i + 1) + '/' +
|
|
49
|
+
return ['阶段 ' + (i + 1) + '/' + stages.length, clock && ('开始 ' + clock), '耗时 ' + durations[i]].filter(Boolean).join(' · ');
|
|
43
50
|
});
|
|
44
51
|
graph.nodes = graph.nodes.map((node, i) => ({ ...node, channel: timingDetails[i] }));
|
|
45
52
|
const confirmation = issue?.prdConfirmation;
|
|
46
53
|
const receipts = issue?.mrs?.map(mr => [mr.repo, mr.label, mr.state].filter(Boolean).join(' · ')).join('\n');
|
|
47
|
-
const
|
|
54
|
+
const defaultFields = {
|
|
48
55
|
prd: [['需求目标', issue?.goal], ['验收标准', issue?.criteria?.join('\n')],
|
|
49
56
|
['PRD 确认', confirmation ? { pending: '待确认', rejected: '已拒绝', confirmed: '已确认' }[confirmation] : undefined]],
|
|
50
57
|
coding: [['项目', issue?.project], ['开发分支', issue?.branch], ['基线', issue?.base]],
|
|
@@ -53,10 +60,17 @@ export function mountWorkflow(panel, root, options = {}) {
|
|
|
53
60
|
mr: [['源分支', issue?.branch], ['合并请求', receipts || issue?.mr], ['MR 状态', issue?.mrState]],
|
|
54
61
|
};
|
|
55
62
|
const briefs = { prd: '生成需求文档并确认范围', coding: '按已确认的需求修改代码', verify: '检查变更并运行验证', mr: '创建并提交合并请求' };
|
|
63
|
+
const fields = stages.map(stage => options.stages
|
|
64
|
+
? (stage.children ?? []).map((child) => typeof child === 'string' ? [child, undefined] : [child.label, child.value])
|
|
65
|
+
: defaultFields[stage.key]);
|
|
66
|
+
const ids = new Set(stages.map(stage => stage.key));
|
|
56
67
|
const owners = new Map();
|
|
57
68
|
for (const [column, step] of steps.entries()) {
|
|
58
|
-
for (const [slot, [label]] of fields[
|
|
59
|
-
|
|
69
|
+
for (const [slot, [label]] of fields[column].entries()) {
|
|
70
|
+
let id = step.id + '-' + slot;
|
|
71
|
+
while (ids.has(id))
|
|
72
|
+
id += '-';
|
|
73
|
+
ids.add(id);
|
|
60
74
|
owners.set(id, column);
|
|
61
75
|
graph.nodes = [...graph.nodes, { id, column, slot: slot, lane: 'input', label, kind: 'notice', status: 'unknown' }];
|
|
62
76
|
graph.links = [...graph.links, { from: id, to: step.id, kind: 'control' }];
|
|
@@ -65,12 +79,12 @@ export function mountWorkflow(panel, root, options = {}) {
|
|
|
65
79
|
}
|
|
66
80
|
const host = el('chain');
|
|
67
81
|
const copy = Object.fromEntries(graph.nodes.map(node => [
|
|
68
|
-
node.id, { tooltip: briefs[steps[owners.get(node.id)].id] }
|
|
82
|
+
node.id, { tooltip: options.stages ? stages[owners.get(node.id)].summary ?? stages[owners.get(node.id)].title : briefs[steps[owners.get(node.id)].id] }
|
|
69
83
|
]));
|
|
70
84
|
const preview = (column) => options.onStage?.({
|
|
71
|
-
column, issue, status: labels[column], timing: timingDetails[column], rows: fields[
|
|
85
|
+
column, issue, status: labels[column], timing: timingDetails[column], rows: fields[column],
|
|
72
86
|
});
|
|
73
|
-
preview(current !== undefined &&
|
|
87
|
+
preview(current !== undefined && stages[current] ? current : 0);
|
|
74
88
|
release = renderWorkflowCanvas(host, {
|
|
75
89
|
showChildCards: options.showChildCards ?? true,
|
|
76
90
|
onDetail: node => { if (node.lane !== 'input')
|
|
@@ -82,12 +96,13 @@ export function mountWorkflow(panel, root, options = {}) {
|
|
|
82
96
|
const badge = document.createElement('span');
|
|
83
97
|
badge.className = 'workflow-stage-mark';
|
|
84
98
|
badge.setAttribute('aria-hidden', 'true');
|
|
85
|
-
|
|
99
|
+
const index = owners.get(card.dataset.chainId);
|
|
100
|
+
badge.textContent = options.stages ? stages[index].mark ?? String(index + 1) : marks[card.dataset.chainId];
|
|
86
101
|
card.prepend(badge);
|
|
87
102
|
}
|
|
88
103
|
if (!issue)
|
|
89
104
|
return;
|
|
90
|
-
el('progress').textContent = '来源:Tavi Web 自动化运行台账';
|
|
105
|
+
el('progress').textContent = options.issue ? '' : '来源:Tavi Web 自动化运行台账';
|
|
91
106
|
}
|
|
92
107
|
async function loadRuns() {
|
|
93
108
|
el('progress').textContent = '正在读取运行台账…';
|
|
@@ -112,9 +127,10 @@ export function mountWorkflow(panel, root, options = {}) {
|
|
|
112
127
|
picker.value = issue.run;
|
|
113
128
|
show(issue);
|
|
114
129
|
}
|
|
115
|
-
show();
|
|
116
|
-
|
|
117
|
-
|
|
130
|
+
show(options.issue);
|
|
131
|
+
if (options.boardUrl && !options.issue)
|
|
132
|
+
loadRuns().catch(() => { if (!controller.signal.aborted)
|
|
133
|
+
el('progress').textContent = ''; });
|
|
118
134
|
function theme(light) {
|
|
119
135
|
root.dataset.theme = light ? 'light' : 'dark';
|
|
120
136
|
el('chain').dataset.workflowTheme = root.dataset.theme;
|
package/dist/panel.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type WorkflowPanelOptions } from './panel-controller.js';
|
|
2
|
-
export type { WorkflowPanelOptions, StagePreview } from './panel-controller.js';
|
|
2
|
+
export type { WorkflowPanelOptions, StagePreview, PanelStage } from './panel-controller.js';
|
|
3
3
|
export type { AutomationIssue } from './tavi-workflow-model.js';
|
|
4
4
|
/** Mount the complete workflow view, with isolated canvas styles. */
|
|
5
5
|
export declare function renderWorkflowPanel(host: HTMLElement, options?: WorkflowPanelOptions): {
|
package/dist/panel.js
CHANGED
|
@@ -14,7 +14,14 @@ export function renderWorkflowPanel(host, options = {}) {
|
|
|
14
14
|
root.append(page);
|
|
15
15
|
shadow.append(style, root);
|
|
16
16
|
host.append(surface);
|
|
17
|
-
|
|
17
|
+
let panel;
|
|
18
|
+
try {
|
|
19
|
+
panel = mountWorkflow(page, root, options);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
surface.remove();
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
18
25
|
return {
|
|
19
26
|
setShowChildCards: panel.setShowChildCards,
|
|
20
27
|
dispose() { panel.dispose(); surface.remove(); },
|
|
@@ -184,7 +184,7 @@ export declare function acceptsHuman(issue: AutomationIssue): boolean;
|
|
|
184
184
|
export declare function nextViewedArtifact(viewed: number, previousLatest: number | undefined, latest: number | undefined): number;
|
|
185
185
|
export declare function stageTone(issue: AutomationIssue, index: number): 'complete' | 'current' | 'blocked' | 'error' | '';
|
|
186
186
|
export declare function stageStateLabel(issue: AutomationIssue, index: number): string;
|
|
187
|
-
export declare function stageElapsedMs(issue: AutomationIssue, index: number, now: number): number | null;
|
|
187
|
+
export declare function stageElapsedMs(issue: AutomationIssue, index: number, now: number, key?: string): number | null;
|
|
188
188
|
export declare function formatStageDuration(elapsedMs: number | null): string;
|
|
189
189
|
/** 阶段说明描述目标,只有服务端事件才是执行证据。 */
|
|
190
190
|
/** 产物行能下载时,返回文件名和正文。没有登记正文就不给空文件。 */
|
|
@@ -176,9 +176,8 @@ export function stageStateLabel(issue, index) {
|
|
|
176
176
|
return issue.stateLabel;
|
|
177
177
|
return '待执行';
|
|
178
178
|
}
|
|
179
|
-
export function stageElapsedMs(issue, index, now) {
|
|
180
|
-
const
|
|
181
|
-
const timing = stage ? issue.stageTimings?.[stage.key] : undefined;
|
|
179
|
+
export function stageElapsedMs(issue, index, now, key = WORKFLOW_STAGES[index]?.key) {
|
|
180
|
+
const timing = key ? issue.stageTimings?.[key] : undefined;
|
|
182
181
|
if (!timing)
|
|
183
182
|
return null;
|
|
184
183
|
const started = timing.runningSince ? Date.parse(timing.runningSince) : NaN;
|