ralphflow-dsh 2.1.1 → 2.2.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/README.md +2 -1
- package/lib/client/definition.d.ts +14 -0
- package/lib/client/definition.js +42 -0
- package/lib/client/index.d.ts +12 -0
- package/lib/client/index.js +16 -0
- package/lib/client/status-source.d.ts +13 -0
- package/lib/client/status-source.js +60 -0
- package/lib/client/status.d.ts +5 -0
- package/lib/client/status.js +122 -0
- package/lib/client.js +457 -0
- package/lib/engine.d.ts +10 -0
- package/lib/engine.js +78 -3
- package/lib/index.js +72 -14
- package/lib/message-source.d.ts +12 -3
- package/lib/status-contract.d.ts +46 -0
- package/lib/status-contract.js +58 -0
- package/lib/status-service.d.ts +18 -0
- package/lib/status-service.js +86 -0
- package/lib/typert.d.ts +3 -0
- package/lib/typert.js +6 -0
- package/package.json +119 -13
package/README.md
CHANGED
|
@@ -81,7 +81,7 @@ CHECK 不是同一个会话再问一遍"你做完了吗"。它是一个**全新
|
|
|
81
81
|
|
|
82
82
|
### 安装
|
|
83
83
|
|
|
84
|
-
前置:已安装 **dsh
|
|
84
|
+
前置:已安装 **dsh** 与 **pnpm**(`dsh plugin` 是 pnpm 的转发器)。已验证 npm 默认频道 `dsh@0.2.0-rc.2`(`cordis@4.0.4`)及原有 `dsh@0.2.1-alpha.1`;**不需要升级到 alpha**。宿主包由 dsh 提供,插件不会通过 peer 自动安装另一套宿主。
|
|
85
85
|
|
|
86
86
|
```bash
|
|
87
87
|
dsh plugin --profile web add ralphflow-dsh
|
|
@@ -239,6 +239,7 @@ flowchart LR
|
|
|
239
239
|
| 完整导航(阅读顺序、场景速查、设计档案索引) | [文档主页](https://github.com/534529531/ralph-flow-dsh/blob/main/docs/README.md) |
|
|
240
240
|
| 设计定稿与宪法(不可违反的十二条) | [设计文档](https://github.com/534529531/ralph-flow-dsh/blob/main/docs/v2/design.md) |
|
|
241
241
|
| 历史任务书与验收证据 | [docs/v2/](https://github.com/534529531/ralph-flow-dsh/tree/main/docs/v2) |
|
|
242
|
+
| 怎么发版(维护者) | [发版](https://github.com/534529531/ralph-flow-dsh/blob/main/docs/releasing.md) |
|
|
242
243
|
|
|
243
244
|
## 致谢
|
|
244
245
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ConversationNodeDefinition } from "@deepseek-ai/dsh-client-ui-conversation/client";
|
|
2
|
+
/** Private renderer key; never replace a shipped Chat renderer. */
|
|
3
|
+
export declare const RALPHFLOW_NOTICE_KIND: "ralphflow-notice";
|
|
4
|
+
export interface RalphflowNotice {
|
|
5
|
+
summary: string;
|
|
6
|
+
text: string;
|
|
7
|
+
}
|
|
8
|
+
declare module "@deepseek-ai/dsh-client-ui-chat/client" {
|
|
9
|
+
interface ChatNodeDataMap {
|
|
10
|
+
"ralphflow-notice": RalphflowNotice;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** The human transcript follows append origins, independently of model-surface replacements. */
|
|
14
|
+
export declare const noticeDefinition: ConversationNodeDefinition<RalphflowNotice>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { RALPHFLOW_SOURCE_KIND } from "../message-source.js";
|
|
2
|
+
/** Private renderer key; never replace a shipped Chat renderer. */
|
|
3
|
+
export const RALPHFLOW_NOTICE_KIND = "ralphflow-notice";
|
|
4
|
+
/** The human transcript follows append origins, independently of model-surface replacements. */
|
|
5
|
+
export const noticeDefinition = {
|
|
6
|
+
kind: RALPHFLOW_NOTICE_KIND,
|
|
7
|
+
target: "chat",
|
|
8
|
+
match(event) {
|
|
9
|
+
if (event.type !== "user/message" || event.surfaceOp !== "append")
|
|
10
|
+
return null;
|
|
11
|
+
const source = event.data.source;
|
|
12
|
+
if (source.kind !== RALPHFLOW_SOURCE_KIND || source.form !== "notice"
|
|
13
|
+
|| typeof source.summary !== "string" || !source.summary.trim())
|
|
14
|
+
return null;
|
|
15
|
+
return { id: String(event.seq), role: "start" };
|
|
16
|
+
},
|
|
17
|
+
start(_context, { event }) {
|
|
18
|
+
if (event.type !== "user/message" || event.data.source.kind !== RALPHFLOW_SOURCE_KIND
|
|
19
|
+
|| event.data.source.form !== "notice" || typeof event.data.source.summary !== "string")
|
|
20
|
+
throw new Error("ralphflow notice requires user/message notice");
|
|
21
|
+
return {
|
|
22
|
+
summary: event.data.source.summary,
|
|
23
|
+
text: event.data.content.filter((b) => b.type === "text").map((b) => b.text).join("\n"),
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
update: (context) => context.state,
|
|
27
|
+
buildViewNode(context) {
|
|
28
|
+
if (!context.start || !context.state)
|
|
29
|
+
return null;
|
|
30
|
+
return {
|
|
31
|
+
key: context.key,
|
|
32
|
+
kind: RALPHFLOW_NOTICE_KIND,
|
|
33
|
+
id: context.id,
|
|
34
|
+
target: "chat",
|
|
35
|
+
anchorSeq: context.start.event.seq,
|
|
36
|
+
// Notices can land before turn/end. Never let the turn-process disclosure swallow them.
|
|
37
|
+
location: { kind: "session" },
|
|
38
|
+
visibility: "visible",
|
|
39
|
+
data: context.state,
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { ChatNode } from "@deepseek-ai/dsh-client-ui-chat/client";
|
|
3
|
+
import { RALPHFLOW_NOTICE_KIND } from "./definition.js";
|
|
4
|
+
export declare const inject: string[];
|
|
5
|
+
/** Native disclosure keeps every summary readable and the full record keyboard accessible. */
|
|
6
|
+
export declare function NoticeRow({ node }: {
|
|
7
|
+
node: ChatNode<typeof RALPHFLOW_NOTICE_KIND>;
|
|
8
|
+
}): import("react").DetailedReactHTMLElement<{
|
|
9
|
+
"data-ralphflow-notice": string;
|
|
10
|
+
className: string;
|
|
11
|
+
}, HTMLElement>;
|
|
12
|
+
export declare function apply(ctx: Context): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createElement } from "react";
|
|
2
|
+
import { noticeDefinition, RALPHFLOW_NOTICE_KIND } from "./definition.js";
|
|
3
|
+
import { registerWorkflowStatus, injectStatusCss } from "./status.js";
|
|
4
|
+
export const inject = ["uiConversation", "slots"];
|
|
5
|
+
/** Native disclosure keeps every summary readable and the full record keyboard accessible. */
|
|
6
|
+
export function NoticeRow({ node }) {
|
|
7
|
+
injectStatusCss();
|
|
8
|
+
return createElement("details", { "data-ralphflow-notice": String(node.anchorSeq), className: "ralphflow-notice" }, createElement("summary", null, node.data.summary), createElement("div", { className: "ralphflow-notice-text" }, node.data.text));
|
|
9
|
+
}
|
|
10
|
+
export function apply(ctx) {
|
|
11
|
+
ctx.inject(["remote", "sessions"], (child) => registerWorkflowStatus(child));
|
|
12
|
+
ctx.uiConversation.events.register(noticeDefinition);
|
|
13
|
+
ctx.slots.inject("conversation.chat.node", () => ctx.slots.register({
|
|
14
|
+
name: "conversation.chat.node", key: RALPHFLOW_NOTICE_KIND,
|
|
15
|
+
}, NoticeRow));
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import { type WorkflowStatus } from "../status-contract.js";
|
|
3
|
+
export interface ClientStatus {
|
|
4
|
+
status: WorkflowStatus | null;
|
|
5
|
+
connection: "connecting" | "live" | "offline";
|
|
6
|
+
error: string | null;
|
|
7
|
+
}
|
|
8
|
+
/** One lazy stream per Session, shared by the header and dock. Last unsubscribe releases it. */
|
|
9
|
+
export declare function createStatusSource(ctx: Context, sessionId: string): {
|
|
10
|
+
getSnapshot: () => ClientStatus;
|
|
11
|
+
subscribe(listener: () => void): () => void;
|
|
12
|
+
dispose(): void;
|
|
13
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { RemoteSnapshotStream } from "@deepseek-ai/dsh-api-gateway/client";
|
|
2
|
+
import { parseStatusFrame } from "../status-contract.js";
|
|
3
|
+
/** One lazy stream per Session, shared by the header and dock. Last unsubscribe releases it. */
|
|
4
|
+
export function createStatusSource(ctx, sessionId) {
|
|
5
|
+
let snapshot = { status: null, connection: "connecting", error: null };
|
|
6
|
+
const listeners = new Set();
|
|
7
|
+
let stream;
|
|
8
|
+
let token = 0;
|
|
9
|
+
const publish = (next) => {
|
|
10
|
+
if (JSON.stringify(next) === JSON.stringify(snapshot))
|
|
11
|
+
return;
|
|
12
|
+
snapshot = next;
|
|
13
|
+
for (const listener of listeners)
|
|
14
|
+
listener();
|
|
15
|
+
};
|
|
16
|
+
const start = () => {
|
|
17
|
+
const incarnation = ++token;
|
|
18
|
+
publish({ ...snapshot, connection: "connecting" });
|
|
19
|
+
const failed = (_error) => {
|
|
20
|
+
if (incarnation === token)
|
|
21
|
+
publish({ ...snapshot, connection: "offline", error: "连接中断,显示最后状态;正在重新同步。" });
|
|
22
|
+
};
|
|
23
|
+
const accept = (raw) => {
|
|
24
|
+
if (incarnation !== token)
|
|
25
|
+
return;
|
|
26
|
+
const frame = parseStatusFrame(raw);
|
|
27
|
+
if (frame.sessionId !== sessionId)
|
|
28
|
+
throw new Error("status stream crossed Session binding");
|
|
29
|
+
publish({ status: frame.status, connection: "live", error: frame.error });
|
|
30
|
+
};
|
|
31
|
+
const carrier = ctx.remote.$stream({
|
|
32
|
+
name: `ralphflow status ${sessionId}`,
|
|
33
|
+
open: (signal) => ctx.remote.ralphflowStatus.watch(sessionId, signal),
|
|
34
|
+
ended: () => new Error("workflow status stream ended"),
|
|
35
|
+
carrierFailed: failed,
|
|
36
|
+
});
|
|
37
|
+
stream = new RemoteSnapshotStream(carrier, {
|
|
38
|
+
name: "ralphflow status", isSnapshot: (frame) => frame.kind === "snapshot",
|
|
39
|
+
replace: accept, update: accept, failed,
|
|
40
|
+
});
|
|
41
|
+
stream.start();
|
|
42
|
+
};
|
|
43
|
+
const stop = () => {
|
|
44
|
+
++token;
|
|
45
|
+
const current = stream;
|
|
46
|
+
stream = undefined;
|
|
47
|
+
void current?.dispose();
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
getSnapshot: () => snapshot,
|
|
51
|
+
subscribe(listener) {
|
|
52
|
+
listeners.add(listener);
|
|
53
|
+
if (listeners.size === 1)
|
|
54
|
+
start();
|
|
55
|
+
return () => { listeners.delete(listener); if (listeners.size === 0)
|
|
56
|
+
stop(); };
|
|
57
|
+
},
|
|
58
|
+
dispose() { stop(); listeners.clear(); },
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
/** One shared, idempotent stylesheet; no timers or per-instance style nodes. */
|
|
3
|
+
export declare function injectStatusCss(): void;
|
|
4
|
+
/** Additive entries, with a single reference-counted observable for each bound Session. */
|
|
5
|
+
export declare function registerWorkflowStatus(ctx: Context): Promise<void>;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId, useRef, useState } from "react";
|
|
3
|
+
import { StateDot, useDismissOnOutsidePointer } from "@deepseek-ai/dsh-client-ui-primitives";
|
|
4
|
+
import { statusRemote } from "../status-contract.js";
|
|
5
|
+
import { createStatusSource } from "./status-source.js";
|
|
6
|
+
const labels = {
|
|
7
|
+
executing: "待交卷", verifying: "独立验证中", gate: "等待你放行", paused: "已暂停",
|
|
8
|
+
switching: "切换步骤中", done: "已完成", cancelled: "已取消", unavailable: "状态不可用",
|
|
9
|
+
};
|
|
10
|
+
const votes = { pending: "等待验证", running: "验证中", passed: "通过", failed: "未通过", infra: "验证者故障" };
|
|
11
|
+
/** The only stages that need the user to act. The input-area prompt appears for these and only these. */
|
|
12
|
+
const actionStages = new Set(["gate", "paused"]);
|
|
13
|
+
const terminalStages = new Set(["done", "cancelled"]);
|
|
14
|
+
const whole = (s) => s;
|
|
15
|
+
/**
|
|
16
|
+
* Colors, radii, shadows, and typography use installed dsh theme tokens.
|
|
17
|
+
* Geometry follows the native jobs trigger and goal dock. The opaque layer token
|
|
18
|
+
* replaces dsh’s translucent menu material, as requested.
|
|
19
|
+
*/
|
|
20
|
+
const css = `
|
|
21
|
+
.ralphflow-status { position: relative; display: inline-flex; align-items: center; gap: 4px; max-width: min(320px, 38vw); min-height: 28px; padding: 3px 2px; border: 0; background: none; color: var(--dsw-alias-label-tertiary); font: inherit; font-size: var(--dsw-font-xxs-12-font-size); line-height: var(--dsw-font-xxs-12-line-height); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
|
|
22
|
+
.ralphflow-status:hover, .ralphflow-status:focus-visible { color: var(--dsw-alias-label-secondary); }
|
|
23
|
+
.ralphflow-status-dot { flex: none; }
|
|
24
|
+
.ralphflow-status-popover { position: absolute; right: 0; top: calc(100% + 8px); width: min(380px, calc(100vw - 32px)); max-height: min(480px, 100vh - 140px); z-index: 100; box-sizing: border-box; display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 12px; overflow: auto; --dsw-elevation-stroke-color: var(--dsw-alias-border-l1); border: 0; border-radius: var(--dsw-radius-lg); background: var(--dsw-alias-bg-layer-2); box-shadow: var(--dsw-elevation-prominent); color: var(--dsw-alias-label-primary); font-size: var(--dsh-content-font-size-secondary); line-height: var(--dsw-font-xs-13-line-height); }
|
|
25
|
+
.ralphflow-status-popover-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
|
|
26
|
+
.ralphflow-status-popover-title { min-width: 0; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
27
|
+
.ralphflow-status-popover-stage { flex: none; color: var(--dsw-alias-label-tertiary); white-space: nowrap; }
|
|
28
|
+
.ralphflow-status-banner { padding: 6px 8px; border-radius: var(--dsw-radius-sm); background: var(--dsw-alias-bg-module-platform); color: var(--dsw-alias-label-secondary); overflow-wrap: anywhere; }
|
|
29
|
+
.ralphflow-status-banner[data-kind="error"] { background: var(--dsw-alias-state-error-secondary); color: var(--dsw-alias-label-primary); }
|
|
30
|
+
.ralphflow-status-hint { color: var(--dsw-alias-label-secondary); overflow-wrap: anywhere; }
|
|
31
|
+
.ralphflow-status-task { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
32
|
+
.ralphflow-status-label { color: var(--dsw-alias-label-tertiary); }
|
|
33
|
+
.ralphflow-status-steps { margin: 4px 0; padding-left: 20px; }
|
|
34
|
+
.ralphflow-status-steps li { overflow-wrap: anywhere; }
|
|
35
|
+
.ralphflow-status-votes { margin: 4px 0; padding-left: 20px; }
|
|
36
|
+
.ralphflow-status-votes li { overflow-wrap: anywhere; }
|
|
37
|
+
.ralphflow-status-recent { margin: 4px 0; padding-left: 20px; }
|
|
38
|
+
.ralphflow-status-recent li { overflow-wrap: anywhere; }
|
|
39
|
+
.ralphflow-status-report { margin: 0; overflow-wrap: anywhere; }
|
|
40
|
+
.ralphflow-status-report code { font-family: var(--dsw-font-mono, monospace); }
|
|
41
|
+
.ralphflow-status-action-dock { width: calc(100% - 2 * var(--dsh-composer-side-clearance) - 4 * var(--dsh-composer-dock-inset)); margin: 0 auto; }
|
|
42
|
+
.ralphflow-status-action { box-sizing: border-box; width: 100%; max-width: calc(var(--dsh-composer-card-max-width) - 4 * var(--dsh-composer-dock-inset)); margin: 0 auto; display: flex; align-items: center; gap: 8px; padding: 4px 12px; border: 0; border-radius: var(--dsw-radius-md); background: var(--dsw-alias-bg-layer-2); box-shadow: var(--dsw-elevation-panel); color: var(--dsw-alias-label-primary); font-size: var(--dsh-content-font-size-secondary); line-height: var(--dsw-font-xs-13-line-height); min-height: 36px; --dsw-elevation-stroke-color: var(--dsw-alias-border-l1); }
|
|
43
|
+
.ralphflow-status-action-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
44
|
+
/* The timeline broadcast row keeps its record role; only its radius/font move to tokens. */
|
|
45
|
+
.ralphflow-notice { margin: 8px 0; padding: 8px 12px; border-radius: var(--dsw-radius-sm); background: var(--dsw-alias-bg-module-platform); color: inherit; font-size: var(--dsh-content-font-size-secondary); line-height: 1.6; overflow-wrap: anywhere; }
|
|
46
|
+
.ralphflow-notice > summary { cursor: pointer; }
|
|
47
|
+
.ralphflow-notice-text { padding-top: 8px; white-space: pre-wrap; }
|
|
48
|
+
`;
|
|
49
|
+
/** One shared, idempotent stylesheet; no timers or per-instance style nodes. */
|
|
50
|
+
export function injectStatusCss() {
|
|
51
|
+
if (typeof document === "undefined" || document.querySelector("style[data-ralphflow-status-css]") !== null)
|
|
52
|
+
return;
|
|
53
|
+
const style = document.createElement("style");
|
|
54
|
+
style.dataset.ralphflowStatusCss = "";
|
|
55
|
+
style.textContent = css;
|
|
56
|
+
document.head.appendChild(style);
|
|
57
|
+
}
|
|
58
|
+
injectStatusCss();
|
|
59
|
+
function StatusDot({ stage }) {
|
|
60
|
+
const state = stage === "done" ? "done" : stage === "gate" || stage === "paused" ? "warning"
|
|
61
|
+
: stage === "unavailable" ? "error" : stage === "cancelled" ? "idle" : "ongoing";
|
|
62
|
+
return _jsx(StateDot, { state: state, className: "ralphflow-status-dot" });
|
|
63
|
+
}
|
|
64
|
+
/** The single persistent location: bare text + dot, no container, dsh jobs-trigger style. */
|
|
65
|
+
function WorkflowStatusControl({ useWorkflowStatus }) {
|
|
66
|
+
const { status, connection } = useWorkflowStatus(whole);
|
|
67
|
+
const [opened, setOpened] = useState(false);
|
|
68
|
+
const id = useId();
|
|
69
|
+
const root = useRef(null);
|
|
70
|
+
const trigger = useRef(null);
|
|
71
|
+
useDismissOnOutsidePointer(root, opened, setOpened);
|
|
72
|
+
if (!status)
|
|
73
|
+
return null;
|
|
74
|
+
const terminal = terminalStages.has(status.stage);
|
|
75
|
+
const label = labels[status.stage];
|
|
76
|
+
return _jsxs("div", { ref: root, style: { position: "relative" }, onKeyDown: (e) => { if (e.key === "Escape") {
|
|
77
|
+
setOpened(false);
|
|
78
|
+
trigger.current?.focus();
|
|
79
|
+
} }, children: [_jsxs("button", { ref: trigger, type: "button", className: "ralphflow-status", "data-ralphflow-status": status.id, "data-stage": status.stage, "data-connection": connection, "aria-expanded": opened, "aria-controls": opened ? id : undefined, "aria-label": "\u67E5\u770B\u5DE5\u4F5C\u6D41\u72B6\u6001", onClick: () => setOpened((v) => !v), title: `${status.workflow} · ${status.step} · ${label}`, children: [_jsx(StatusDot, { stage: status.stage }), _jsxs("span", { children: [terminal ? `${label} · 报告` : `${status.step} · ${status.stage === "paused" ? `失败 ${status.failures} 次` : `第 ${status.failures + 1} 轮`} · ${label}`, connection === "live" ? "" : " · 同步中"] })] }), opened ? _jsx(WorkflowStatusPopover, { id: id, useWorkflowStatus: useWorkflowStatus }) : null] });
|
|
80
|
+
}
|
|
81
|
+
function WorkflowStatusPopover({ id, useWorkflowStatus }) {
|
|
82
|
+
const { status, connection, error } = useWorkflowStatus(whole);
|
|
83
|
+
if (!status)
|
|
84
|
+
return null;
|
|
85
|
+
const terminal = terminalStages.has(status.stage);
|
|
86
|
+
const returned = status.votes.filter((v) => v.status === "passed" || v.status === "failed" || v.status === "infra").length;
|
|
87
|
+
// The internal failure budget is noise until it is nearly spent; only then surface n/m.
|
|
88
|
+
const nearLimit = status.maxFailures > 0 && status.failures > 0 && status.failures >= status.maxFailures * 0.8;
|
|
89
|
+
return _jsxs("div", { id: id, className: "ralphflow-status-popover", "data-ralphflow-status-popover": true, role: "status", children: [_jsxs("div", { className: "ralphflow-status-popover-head", children: [_jsxs("span", { className: "ralphflow-status-popover-title", children: ["Ralph Flow \u00B7 ", status.workflow] }), _jsxs("span", { className: "ralphflow-status-popover-stage", children: [labels[status.stage], connection === "live" ? "" : " · 同步中"] })] }), error ? _jsxs("div", { className: "ralphflow-status-banner", "data-kind": "error", role: "status", children: ["Ralph Flow \u00B7 ", error] }) : null, connection !== "live" && !error ? _jsx("div", { className: "ralphflow-status-banner", role: "status", children: "\u6B63\u5728\u91CD\u65B0\u540C\u6B65\uFF0C\u663E\u793A\u6700\u540E\u72B6\u6001\u3002" }) : null, !terminal && nearLimit ? _jsxs("div", { className: "ralphflow-status-banner", role: "status", children: ["\u672C\u6B65\u5931\u8D25\u63A5\u8FD1\u4E0A\u9650 \u00B7 ", status.failures, "/", status.maxFailures] }) : null, !terminal && status.hint ? _jsx("div", { className: "ralphflow-status-hint", children: status.hint }) : null, !terminal ? _jsx("p", { className: "ralphflow-status-task", children: status.task }) : null, !terminal ? _jsxs("div", { className: "ralphflow-status-label", children: ["\u672C\u6B65\u5931\u8D25 ", status.failures, " \u6B21"] }) : null, !terminal && status.steps.length ? _jsxs("div", { children: [_jsx("div", { className: "ralphflow-status-label", children: "\u6B65\u9AA4" }), _jsx("ol", { className: "ralphflow-status-steps", "aria-label": "\u5DE5\u4F5C\u6D41\u6B65\u9AA4", children: status.steps.map((step) => _jsxs("li", { "aria-current": step.current ? "step" : undefined, children: [step.current ? "→ " : "", _jsx("strong", { children: step.id }), " \u00B7 ", step.description, step.failures ? ` · 失败 ${step.failures} 次` : ""] }, step.id)) })] }) : null, !terminal && status.votes.length ? _jsxs("div", { children: [_jsxs("div", { className: "ralphflow-status-label", children: ["\u672C\u8F6E\u9A8C\u8BC1 \u00B7 ", returned, "/", status.votes.length, " \u5DF2\u8FD4\u56DE"] }), _jsx("ul", { className: "ralphflow-status-votes", "aria-label": `本轮验证 · ${returned}/${status.votes.length} 已返回`, children: status.votes.map((vote) => _jsxs("li", { children: ["\u9A8C\u8BC1\u8005 ", vote.index, "/", status.votes.length, " \u00B7 ", votes[vote.status], vote.reason ? _jsx("div", { children: vote.reason }) : null] }, vote.index)) })] }) : null, !terminal && status.recent.length ? _jsxs("details", { children: [_jsx("summary", { className: "ralphflow-status-label", children: "\u6700\u8FD1\u8F68\u8FF9" }), _jsx("ul", { className: "ralphflow-status-recent", children: status.recent.map((event, index) => _jsxs("li", { children: [event.step, " \u00B7 ", event.event, event.detail ? `:${event.detail}` : ""] }, index)) })] }) : null, status.report ? _jsxs("p", { className: "ralphflow-status-report", children: ["\u62A5\u544A\uFF1A", _jsx("code", { children: status.report })] }) : null] });
|
|
90
|
+
}
|
|
91
|
+
/** Input-area prompt: present only while the user must act, and it removes itself once handled. */
|
|
92
|
+
function WorkflowStatusAction({ useWorkflowStatus }) {
|
|
93
|
+
const { status } = useWorkflowStatus(whole);
|
|
94
|
+
if (!status || !actionStages.has(status.stage))
|
|
95
|
+
return null;
|
|
96
|
+
const reason = status.stage === "gate" ? "等待你放行" : status.maxFailures > 0 && status.failures >= status.maxFailures ? "失败已到上限" : "已暂停";
|
|
97
|
+
return _jsx("div", { className: "ralphflow-status-action-dock", children: _jsxs("div", { className: "ralphflow-status-action", "data-ralphflow-status-action": status.id, "data-stage": status.stage, role: "status", children: [_jsx(StatusDot, { stage: status.stage }), _jsxs("span", { className: "ralphflow-status-action-text", children: [reason, " \u00B7 \u8F93\u5165 ", _jsx("code", { children: "/ralphflow-continue" }), " \u7EE7\u7EED"] })] }) });
|
|
98
|
+
}
|
|
99
|
+
/** Additive entries, with a single reference-counted observable for each bound Session. */
|
|
100
|
+
export async function registerWorkflowStatus(ctx) {
|
|
101
|
+
await ctx.remote.$mount(statusRemote);
|
|
102
|
+
await ctx.inject(["remote.ralphflowStatus"], registerUi);
|
|
103
|
+
}
|
|
104
|
+
function registerUi(ctx) {
|
|
105
|
+
const sources = new Map();
|
|
106
|
+
const sourceOf = (sessionId) => {
|
|
107
|
+
let source = sources.get(sessionId);
|
|
108
|
+
if (!source) {
|
|
109
|
+
source = createStatusSource(ctx, sessionId);
|
|
110
|
+
sources.set(sessionId, source);
|
|
111
|
+
}
|
|
112
|
+
return { hooks: { workflowStatus: source } };
|
|
113
|
+
};
|
|
114
|
+
ctx.effect(() => () => { for (const source of sources.values())
|
|
115
|
+
source.dispose(); sources.clear(); });
|
|
116
|
+
ctx.slots.inject("conversation.input.dock", () => ctx.slots.register({
|
|
117
|
+
name: "conversation.input.dock", id: "ralphflow-status", order: 5, inject: sourceOf,
|
|
118
|
+
}, WorkflowStatusAction));
|
|
119
|
+
ctx.slots.inject("conversation.session.header.actions", () => ctx.slots.register({
|
|
120
|
+
name: "conversation.session.header.actions", id: "ralphflow-status", order: 15, inject: sourceOf,
|
|
121
|
+
}, WorkflowStatusControl));
|
|
122
|
+
}
|