@lzn1998/dsh-langgraph 0.5.0 → 1.0.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 +29 -5
- package/client/index.tsx +418 -0
- package/cordis.patch.yml +9 -4
- package/docs/CONTEXT.md +102 -0
- package/docs/DETAIL.md +203 -11
- package/docs/ECOSYSTEM.md +134 -0
- package/docs/architecture.svg +1 -1
- package/dsh-checkpointer.js +68 -3
- package/dsh-store.js +262 -0
- package/graphs/approval-gate.js +1 -1
- package/graphs/ask-tools.js +1 -1
- package/graphs/ask-user.js +51 -0
- package/graphs/ask-workspace.js +1 -1
- package/graphs/scan-report.js +1 -1
- package/index.d.ts +38 -2
- package/index.js +481 -43
- package/lib/client.js +273 -0
- package/locale/en.json +2 -2
- package/locale/zh.json +2 -2
- package/package.json +18 -3
- package/scripts/build-client.mjs +126 -0
package/lib/client.js
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @lzn1998/dsh-langgraph — browser closure-factory bundle.
|
|
3
|
+
*
|
|
4
|
+
* Generated from client/index.tsx by scripts/build-client.mjs — do not edit by hand.
|
|
5
|
+
* The module loader registers this factory and materializes it on first import;
|
|
6
|
+
* every module-body side effect stays inside the factory closure.
|
|
7
|
+
*/
|
|
8
|
+
window.__ModuleLoader__.load({
|
|
9
|
+
id: "@lzn1998/dsh-langgraph",
|
|
10
|
+
factory: (require) => {
|
|
11
|
+
var module = { exports: {} };
|
|
12
|
+
var exports = module.exports;
|
|
13
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
14
|
+
"use strict";
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.inject = void 0;
|
|
17
|
+
exports.apply = apply;
|
|
18
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
19
|
+
/**
|
|
20
|
+
* Browser half of the LangGraph panel.
|
|
21
|
+
*
|
|
22
|
+
* Two slot contributions that share one id:
|
|
23
|
+
* - `main` key `langgraph`: the panel listing registered graphs and drawing the
|
|
24
|
+
* selected graph's topology.
|
|
25
|
+
* - `sidebar.panellist` id `langgraph`: the launcher row that selects it.
|
|
26
|
+
*
|
|
27
|
+
* The panel reads the Host plugin's authenticated routes (registered through
|
|
28
|
+
* `ctx.connection.fetch.register`, owner-only): `GET /api/plugins/langgraph/ui` for
|
|
29
|
+
* the registry and thread counts, and `GET /api/plugins/langgraph/topology?graph=`
|
|
30
|
+
* for one drawable graph. Runtime dependencies are `react` and
|
|
31
|
+
* `react/jsx-runtime` only; the Web shell seeds both into the module table.
|
|
32
|
+
* @module @lzn1998/dsh-langgraph/client
|
|
33
|
+
*/
|
|
34
|
+
const react_1 = require("react");
|
|
35
|
+
/** The main-panel key and the sidebar-list id: one identity for both seats. */
|
|
36
|
+
const PANEL_ID = 'langgraph';
|
|
37
|
+
/** Host routes served by the plugin's owner-only fetch registrations. */
|
|
38
|
+
const UI_URL = '/api/plugins/langgraph/ui';
|
|
39
|
+
const TOPOLOGY_URL = '/api/plugins/langgraph/topology';
|
|
40
|
+
/** Refresh cadence for the registry and thread counts. */
|
|
41
|
+
const POLL_MS = 5000;
|
|
42
|
+
/** The injected stylesheet's ownership id. */
|
|
43
|
+
const STYLE_ID = '@lzn1998/dsh-langgraph/client.css';
|
|
44
|
+
/** Cordis services this browser plugin needs before it applies. */
|
|
45
|
+
exports.inject = ['slots'];
|
|
46
|
+
// ── host reads ───────────────────────────────────────────────────────────────
|
|
47
|
+
/** Read one JSON route, raising the Host's error message when it refuses. */
|
|
48
|
+
async function readJson(url) {
|
|
49
|
+
const response = await fetch(url, { headers: { accept: 'application/json' } });
|
|
50
|
+
const payload = await response.json().catch(() => ({}));
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
throw new Error(typeof payload?.error === 'string' ? payload.error : `HTTP ${response.status}`);
|
|
53
|
+
}
|
|
54
|
+
return payload;
|
|
55
|
+
}
|
|
56
|
+
/** One-line message for an unknown thrown value. */
|
|
57
|
+
function messageOf(error) {
|
|
58
|
+
return error instanceof Error ? error.message : String(error);
|
|
59
|
+
}
|
|
60
|
+
// ── topology layout ──────────────────────────────────────────────────────────
|
|
61
|
+
const NODE_WIDTH = 150;
|
|
62
|
+
const NODE_HEIGHT = 44;
|
|
63
|
+
const COLUMN_GAP = 82;
|
|
64
|
+
const ROW_GAP = 34;
|
|
65
|
+
const PADDING = 24;
|
|
66
|
+
/** Assign every node the BFS depth from `__start__` (unreachable nodes stay at 0). */
|
|
67
|
+
function levelsOf(topology) {
|
|
68
|
+
const levels = new Map();
|
|
69
|
+
const bySource = new Map();
|
|
70
|
+
for (const edge of topology.edges) {
|
|
71
|
+
const targets = bySource.get(edge.source) ?? [];
|
|
72
|
+
targets.push(edge.target);
|
|
73
|
+
bySource.set(edge.source, targets);
|
|
74
|
+
}
|
|
75
|
+
const start = topology.nodes.some(node => node.id === '__start__') ? '__start__' : topology.nodes[0]?.id;
|
|
76
|
+
if (start === undefined)
|
|
77
|
+
return levels;
|
|
78
|
+
levels.set(start, 0);
|
|
79
|
+
const queue = [start];
|
|
80
|
+
while (queue.length > 0) {
|
|
81
|
+
const id = queue.shift();
|
|
82
|
+
for (const target of bySource.get(id) ?? []) {
|
|
83
|
+
if (levels.has(target))
|
|
84
|
+
continue;
|
|
85
|
+
levels.set(target, (levels.get(id) ?? 0) + 1);
|
|
86
|
+
queue.push(target);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return levels;
|
|
90
|
+
}
|
|
91
|
+
/** Place columns by depth and rows within a column, then route every edge. */
|
|
92
|
+
function drawTopology(topology) {
|
|
93
|
+
const levels = levelsOf(topology);
|
|
94
|
+
const columns = new Map();
|
|
95
|
+
for (const node of topology.nodes) {
|
|
96
|
+
const level = levels.get(node.id) ?? 0;
|
|
97
|
+
const column = columns.get(level) ?? [];
|
|
98
|
+
column.push(node);
|
|
99
|
+
columns.set(level, column);
|
|
100
|
+
}
|
|
101
|
+
for (const column of columns.values()) {
|
|
102
|
+
column.sort((left, right) => {
|
|
103
|
+
const leftEnd = left.id === '__end__' ? 1 : 0;
|
|
104
|
+
const rightEnd = right.id === '__end__' ? 1 : 0;
|
|
105
|
+
return leftEnd - rightEnd;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
const placed = new Map();
|
|
109
|
+
const depths = [...columns.keys()].sort((left, right) => left - right);
|
|
110
|
+
let maxRows = 0;
|
|
111
|
+
for (const depth of depths) {
|
|
112
|
+
const column = columns.get(depth) ?? [];
|
|
113
|
+
maxRows = Math.max(maxRows, column.length);
|
|
114
|
+
column.forEach((node, row) => {
|
|
115
|
+
placed.set(node.id, {
|
|
116
|
+
...node,
|
|
117
|
+
x: PADDING + depth * (NODE_WIDTH + COLUMN_GAP),
|
|
118
|
+
y: PADDING + row * (NODE_HEIGHT + ROW_GAP),
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
const nodes = [...placed.values()];
|
|
123
|
+
const edges = [];
|
|
124
|
+
for (const edge of topology.edges) {
|
|
125
|
+
const source = placed.get(edge.source);
|
|
126
|
+
const target = placed.get(edge.target);
|
|
127
|
+
if (source === undefined || target === undefined)
|
|
128
|
+
continue;
|
|
129
|
+
const sx = source.x + NODE_WIDTH;
|
|
130
|
+
const sy = source.y + NODE_HEIGHT / 2;
|
|
131
|
+
const tx = target.x;
|
|
132
|
+
const ty = target.y + NODE_HEIGHT / 2;
|
|
133
|
+
const bend = Math.max(40, Math.abs(tx - sx) / 2);
|
|
134
|
+
let path;
|
|
135
|
+
if (tx > sx) {
|
|
136
|
+
path = `M ${sx} ${sy} C ${sx + bend} ${sy}, ${tx - bend} ${ty}, ${tx} ${ty}`;
|
|
137
|
+
}
|
|
138
|
+
else if (tx === sx) {
|
|
139
|
+
// Same column: leave to the right and come into the target's top edge.
|
|
140
|
+
const center = target.x + NODE_WIDTH / 2;
|
|
141
|
+
path = `M ${sx} ${sy} C ${sx + 70} ${sy}, ${center + 70} ${target.y - 28}, ${center} ${target.y}`;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
path = `M ${sx} ${sy} C ${sx + bend} ${sy + 40}, ${tx - bend} ${ty + 40}, ${tx} ${ty}`;
|
|
145
|
+
}
|
|
146
|
+
edges.push({ path, conditional: edge.conditional === true });
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
width: PADDING * 2 + Math.max(1, depths.length) * (NODE_WIDTH + COLUMN_GAP) - COLUMN_GAP,
|
|
150
|
+
height: PADDING * 2 + Math.max(1, maxRows) * (NODE_HEIGHT + ROW_GAP) - ROW_GAP,
|
|
151
|
+
nodes,
|
|
152
|
+
edges,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
/** Draw one topology as a small left-to-right diagram. */
|
|
156
|
+
function TopologyView({ topology }) {
|
|
157
|
+
const drawing = (0, react_1.useMemo)(() => drawTopology(topology), [topology]);
|
|
158
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: "lg-topology", children: (0, jsx_runtime_1.jsxs)("svg", { viewBox: `0 0 ${drawing.width} ${drawing.height}`, role: "img", "aria-label": `${topology.graph} topology`, children: [(0, jsx_runtime_1.jsx)("defs", { children: (0, jsx_runtime_1.jsx)("marker", { id: "lg-arrow", viewBox: "0 0 8 8", refX: "7", refY: "4", markerWidth: "7", markerHeight: "7", orient: "auto-start-reverse", children: (0, jsx_runtime_1.jsx)("path", { d: "M 0 0 L 8 4 L 0 8 z", className: "lg-arrow" }) }) }), drawing.edges.map((edge, index) => ((0, jsx_runtime_1.jsx)("path", { d: edge.path, className: edge.conditional ? 'lg-edge lg-edge-conditional' : 'lg-edge', markerEnd: "url(#lg-arrow)" }, `edge-${index}`))), drawing.nodes.map(node => ((0, jsx_runtime_1.jsxs)("g", { transform: `translate(${node.x},${node.y})`, children: [(0, jsx_runtime_1.jsx)("rect", { width: NODE_WIDTH, height: NODE_HEIGHT, rx: 10, className: node.id === '__start__' || node.id === '__end__' ? 'lg-node lg-node-terminal' : 'lg-node' }), (0, jsx_runtime_1.jsx)("text", { x: NODE_WIDTH / 2, y: NODE_HEIGHT / 2 + 4, textAnchor: "middle", className: "lg-node-label", children: node.id === '__start__' ? 'start' : node.id === '__end__' ? 'end' : node.name ?? node.id }), (0, jsx_runtime_1.jsx)("title", { children: node.description ?? node.id })] }, node.id)))] }) }));
|
|
159
|
+
}
|
|
160
|
+
// ── panel ────────────────────────────────────────────────────────────────────
|
|
161
|
+
/** The panel body: registry on the left, selected topology on the right. */
|
|
162
|
+
function LangGraphPanel() {
|
|
163
|
+
const [ui, setUi] = (0, react_1.useState)();
|
|
164
|
+
const [uiError, setUiError] = (0, react_1.useState)();
|
|
165
|
+
const [selected, setSelected] = (0, react_1.useState)();
|
|
166
|
+
const [topology, setTopology] = (0, react_1.useState)();
|
|
167
|
+
const [topologyError, setTopologyError] = (0, react_1.useState)();
|
|
168
|
+
const [busy, setBusy] = (0, react_1.useState)(false);
|
|
169
|
+
const refresh = (0, react_1.useCallback)(async () => {
|
|
170
|
+
try {
|
|
171
|
+
const next = await readJson(UI_URL);
|
|
172
|
+
setUi(next);
|
|
173
|
+
setUiError(undefined);
|
|
174
|
+
setSelected(current => current !== undefined && next.graphs.some(graph => graph.id === current)
|
|
175
|
+
? current
|
|
176
|
+
: next.graphs[0]?.id);
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
setUiError(messageOf(error));
|
|
180
|
+
}
|
|
181
|
+
}, []);
|
|
182
|
+
(0, react_1.useEffect)(() => {
|
|
183
|
+
void refresh();
|
|
184
|
+
const timer = window.setInterval(() => { void refresh(); }, POLL_MS);
|
|
185
|
+
return () => { window.clearInterval(timer); };
|
|
186
|
+
}, [refresh]);
|
|
187
|
+
(0, react_1.useEffect)(() => {
|
|
188
|
+
if (selected === undefined) {
|
|
189
|
+
setTopology(undefined);
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
let live = true;
|
|
193
|
+
setBusy(true);
|
|
194
|
+
setTopologyError(undefined);
|
|
195
|
+
readJson(`${TOPOLOGY_URL}?graph=${encodeURIComponent(selected)}`)
|
|
196
|
+
.then(next => { if (live)
|
|
197
|
+
setTopology(next); })
|
|
198
|
+
.catch(error => {
|
|
199
|
+
if (!live)
|
|
200
|
+
return;
|
|
201
|
+
setTopology(undefined);
|
|
202
|
+
setTopologyError(messageOf(error));
|
|
203
|
+
})
|
|
204
|
+
.finally(() => { if (live)
|
|
205
|
+
setBusy(false); });
|
|
206
|
+
return () => { live = false; };
|
|
207
|
+
}, [selected]);
|
|
208
|
+
const selectedGraph = ui?.graphs.find(graph => graph.id === selected);
|
|
209
|
+
return ((0, jsx_runtime_1.jsxs)("section", { className: "lg-panel", "aria-label": "LangGraph graphs", children: [(0, jsx_runtime_1.jsxs)("header", { className: "lg-header", children: [(0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("h2", { className: "lg-title", children: "LangGraph" }), (0, jsx_runtime_1.jsx)("p", { className: "lg-muted", children: ui === undefined
|
|
210
|
+
? 'Loading graphs…'
|
|
211
|
+
: `${ui.graphs.length} graph${ui.graphs.length === 1 ? '' : 's'} · ${ui.threads.total} durable thread${ui.threads.total === 1 ? '' : 's'}` })] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "lg-button", onClick: () => { void refresh(); }, children: "Refresh" })] }), uiError !== undefined && (0, jsx_runtime_1.jsx)("p", { className: "lg-error", children: uiError }), (0, jsx_runtime_1.jsxs)("div", { className: "lg-grid", children: [(0, jsx_runtime_1.jsxs)("nav", { className: "lg-list", "aria-label": "Registered graphs", children: [(ui?.graphs ?? []).map(graph => ((0, jsx_runtime_1.jsxs)("button", { type: "button", className: graph.id === selected ? 'lg-item lg-item-active' : 'lg-item', onClick: () => setSelected(graph.id), children: [(0, jsx_runtime_1.jsx)("span", { className: "lg-item-id", children: graph.id }), (0, jsx_runtime_1.jsx)("span", { className: "lg-item-meta", children: graph.error ?? `${ui?.threads.byGraph[graph.id] ?? 0} thread${(ui?.threads.byGraph[graph.id] ?? 0) === 1 ? '' : 's'}` }), graph.error === undefined && graph.description !== undefined && ((0, jsx_runtime_1.jsx)("span", { className: "lg-item-desc", children: graph.description }))] }, graph.id))), ui !== undefined && ui.graphs.length === 0 && (0, jsx_runtime_1.jsx)("p", { className: "lg-muted", children: "No graphs registered." })] }), (0, jsx_runtime_1.jsxs)("div", { className: "lg-canvas", children: [topologyError !== undefined && (0, jsx_runtime_1.jsx)("p", { className: "lg-error", children: topologyError }), busy && (0, jsx_runtime_1.jsx)("p", { className: "lg-muted", children: "Loading topology\u2026" }), !busy && topology !== undefined && (0, jsx_runtime_1.jsx)(TopologyView, { topology: topology }), !busy && topology === undefined && topologyError === undefined && ((0, jsx_runtime_1.jsx)("p", { className: "lg-muted", children: "Select a graph to see its nodes and edges." }))] })] }), (0, jsx_runtime_1.jsx)("footer", { className: "lg-footer", children: selectedGraph?.description ?? 'Runs appear as langgraph_run rows in Trajectory.' })] }));
|
|
212
|
+
}
|
|
213
|
+
/** Sidebar launcher icon: one node feeding two others. */
|
|
214
|
+
function LangGraphIcon() {
|
|
215
|
+
return ((0, jsx_runtime_1.jsxs)("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: [(0, jsx_runtime_1.jsx)("rect", { x: "2", y: "9", width: "6", height: "6", rx: "2", stroke: "currentColor", strokeWidth: "1.6" }), (0, jsx_runtime_1.jsx)("rect", { x: "16", y: "2", width: "6", height: "6", rx: "2", stroke: "currentColor", strokeWidth: "1.6" }), (0, jsx_runtime_1.jsx)("rect", { x: "16", y: "16", width: "6", height: "6", rx: "2", stroke: "currentColor", strokeWidth: "1.6" }), (0, jsx_runtime_1.jsx)("path", { d: "M8 12h4v-7h4M12 12v7h4", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round" })] }));
|
|
216
|
+
}
|
|
217
|
+
// ── styles ───────────────────────────────────────────────────────────────────
|
|
218
|
+
const PANEL_CSS = `
|
|
219
|
+
.lg-panel { display: flex; flex-direction: column; height: 100%; min-height: 0; padding: 18px 20px; gap: 14px; color: inherit; font: inherit; }
|
|
220
|
+
.lg-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
|
|
221
|
+
.lg-title { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: .01em; }
|
|
222
|
+
.lg-muted { margin: 2px 0 0; opacity: .62; font-size: 12px; }
|
|
223
|
+
.lg-error { margin: 0; padding: 8px 10px; border-radius: 8px; font-size: 12px; color: #ffb4ab; background: rgba(255, 80, 70, .12); border: 1px solid rgba(255, 80, 70, .28); white-space: pre-wrap; }
|
|
224
|
+
.lg-button { border: 1px solid color-mix(in srgb, currentColor 22%, transparent); background: transparent; color: inherit; border-radius: 8px; padding: 6px 12px; font: inherit; font-size: 12px; cursor: pointer; }
|
|
225
|
+
.lg-button:hover { background: color-mix(in srgb, currentColor 8%, transparent); }
|
|
226
|
+
.lg-grid { display: grid; grid-template-columns: minmax(190px, 250px) minmax(0, 1fr); gap: 14px; min-height: 0; flex: 1; }
|
|
227
|
+
.lg-list { display: flex; flex-direction: column; gap: 6px; overflow: auto; padding-right: 2px; }
|
|
228
|
+
.lg-item { display: flex; flex-direction: column; gap: 2px; text-align: left; border: 1px solid color-mix(in srgb, currentColor 14%, transparent); background: transparent; color: inherit; border-radius: 10px; padding: 8px 10px; font: inherit; cursor: pointer; }
|
|
229
|
+
.lg-item:hover { background: color-mix(in srgb, currentColor 6%, transparent); }
|
|
230
|
+
.lg-item-active { border-color: color-mix(in srgb, currentColor 40%, transparent); background: color-mix(in srgb, currentColor 9%, transparent); }
|
|
231
|
+
.lg-item-id { font-size: 13px; font-weight: 600; }
|
|
232
|
+
.lg-item-meta { font-size: 11px; opacity: .58; }
|
|
233
|
+
.lg-item-desc { font-size: 11px; opacity: .72; line-height: 1.35; }
|
|
234
|
+
.lg-canvas { min-height: 0; overflow: auto; border: 1px solid color-mix(in srgb, currentColor 12%, transparent); border-radius: 12px; padding: 12px; }
|
|
235
|
+
.lg-topology { min-width: min-content; }
|
|
236
|
+
.lg-topology svg { display: block; max-width: 100%; height: auto; overflow: visible; }
|
|
237
|
+
.lg-node { fill: color-mix(in srgb, currentColor 7%, transparent); stroke: color-mix(in srgb, currentColor 38%, transparent); stroke-width: 1.2; }
|
|
238
|
+
.lg-node-terminal { fill: transparent; stroke-dasharray: 4 4; }
|
|
239
|
+
.lg-node-label { fill: currentColor; font-size: 12px; font-weight: 550; }
|
|
240
|
+
.lg-edge { fill: none; stroke: color-mix(in srgb, currentColor 42%, transparent); stroke-width: 1.4; }
|
|
241
|
+
.lg-edge-conditional { stroke-dasharray: 6 4; }
|
|
242
|
+
.lg-arrow { fill: color-mix(in srgb, currentColor 55%, transparent); }
|
|
243
|
+
.lg-footer { font-size: 11px; opacity: .55; border-top: 1px solid color-mix(in srgb, currentColor 10%, transparent); padding-top: 9px; }
|
|
244
|
+
`;
|
|
245
|
+
/** Inject the panel stylesheet once per page. */
|
|
246
|
+
function installStyles() {
|
|
247
|
+
if (document.querySelector(`style[data-plugin-css="${STYLE_ID}"]`) !== null)
|
|
248
|
+
return;
|
|
249
|
+
const tag = document.createElement('style');
|
|
250
|
+
tag.dataset.plugin = '@lzn1998/dsh-langgraph';
|
|
251
|
+
tag.dataset.pluginCss = STYLE_ID;
|
|
252
|
+
tag.textContent = PANEL_CSS;
|
|
253
|
+
document.head.appendChild(tag);
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Contribute the panel and its sidebar launcher. `slots.inject` waits for each
|
|
257
|
+
* slot's declaration, so activation order does not matter; the disposers
|
|
258
|
+
* belong to this plugin's fiber.
|
|
259
|
+
* @param ctx - browser context carrying the slot registry.
|
|
260
|
+
*/
|
|
261
|
+
function apply(ctx) {
|
|
262
|
+
installStyles();
|
|
263
|
+
ctx.slots.inject('main', () => ctx.slots.register({ name: 'main', key: PANEL_ID }, LangGraphPanel));
|
|
264
|
+
ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
|
|
265
|
+
name: 'sidebar.panellist',
|
|
266
|
+
id: PANEL_ID,
|
|
267
|
+
order: 32,
|
|
268
|
+
label: 'LangGraph',
|
|
269
|
+
}, LangGraphIcon));
|
|
270
|
+
}
|
|
271
|
+
return module.exports;
|
|
272
|
+
},
|
|
273
|
+
});
|
package/locale/en.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
|
-
"title": "LangGraph
|
|
4
|
-
"description": "Registers LangGraph graphs as durable
|
|
3
|
+
"title": "LangGraph graphs",
|
|
4
|
+
"description": "Registers LangGraph graphs as durable DSH tools an agent runs with the langgraph_run tool. Registered graphs are listed in the system prompt, nodes call this session's own tools in its sandbox, can ask the user through the native question UI, run as background jobs or delegate to DSH subagents, every node/tool/model call is traced in Trajectory, threads and long-term memory survive restarts, an interrupted graph resumes where it stopped, and a Web sidebar panel lists the graphs and draws their topology.",
|
|
5
5
|
"detail": "docs/DETAIL.md"
|
|
6
6
|
}
|
|
7
7
|
}
|
package/locale/zh.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
|
-
"title": "LangGraph
|
|
4
|
-
"description": "把 LangGraph
|
|
3
|
+
"title": "LangGraph 图",
|
|
4
|
+
"description": "把 LangGraph 图注册成可持久化的 DSH 工具,agent 通过 langgraph_run 工具运行。已注册的图会列在 system prompt 里,图里的节点调用本会话自己的工具、在同一个沙箱执行,可通过原生提问 UI 询问用户,可后台运行,也可派发 DSH 子 agent;节点/工具/模型动作在 Trajectory 里逐层可见;线程和长期记忆跨重启保留,被 interrupt 暂停的图可以从原处继续;Web 侧边栏面板会列出图并绘制拓扑。",
|
|
5
5
|
"detail": "docs/DETAIL.md"
|
|
6
6
|
}
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lzn1998/dsh-langgraph",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Durable LangGraph
|
|
5
|
+
"description": "Durable LangGraph graphs as DSH tools: register TS/JS graphs, advertise them in the system prompt, run, resume and time-travel them, give them durable long-term memory, ask the user in the native question UI, run them as background jobs, delegate to DSH subagents, trace every node/tool/model call in Trajectory, draw their topology in a Web panel, and let graph nodes call this session's own tools.",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/lznnnnn1998/DSH-LangGraph.git"
|
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
"types": "./index.d.ts",
|
|
20
20
|
"default": "./index.js"
|
|
21
21
|
},
|
|
22
|
+
"./client": {
|
|
23
|
+
"default": "./lib/client.js"
|
|
24
|
+
},
|
|
22
25
|
"./locale/*.json": "./locale/*.json",
|
|
23
26
|
"./icon": "./icon.svg"
|
|
24
27
|
},
|
|
@@ -27,11 +30,15 @@
|
|
|
27
30
|
"index.d.ts",
|
|
28
31
|
"dsh-checkpointer.js",
|
|
29
32
|
"dsh-chat-model.js",
|
|
33
|
+
"dsh-store.js",
|
|
30
34
|
"dsh-tools.js",
|
|
31
35
|
"dsh-trace.js",
|
|
32
36
|
"graphs",
|
|
33
37
|
"locale",
|
|
34
38
|
"docs",
|
|
39
|
+
"lib/client.js",
|
|
40
|
+
"client/index.tsx",
|
|
41
|
+
"scripts/build-client.mjs",
|
|
35
42
|
"icon.svg",
|
|
36
43
|
"cordis.patch.yml",
|
|
37
44
|
"README.md",
|
|
@@ -42,7 +49,8 @@
|
|
|
42
49
|
"node": ">=24.9.0"
|
|
43
50
|
},
|
|
44
51
|
"scripts": {
|
|
45
|
-
"test": "node --test test/*.test.js"
|
|
52
|
+
"test": "node --test test/*.test.js",
|
|
53
|
+
"build:client": "node scripts/build-client.mjs"
|
|
46
54
|
},
|
|
47
55
|
"dependencies": {
|
|
48
56
|
"@langchain/core": "^1.5.1",
|
|
@@ -53,6 +61,13 @@
|
|
|
53
61
|
"dsh": {
|
|
54
62
|
"bundle": {
|
|
55
63
|
"patch": "./cordis.patch.yml"
|
|
64
|
+
},
|
|
65
|
+
"client": {
|
|
66
|
+
"platform": "web",
|
|
67
|
+
"inject": [
|
|
68
|
+
"@deepseek-ai/dsh-client-ui-layout",
|
|
69
|
+
"@deepseek-ai/dsh-client-ui-sidebar"
|
|
70
|
+
]
|
|
56
71
|
}
|
|
57
72
|
}
|
|
58
73
|
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Build `lib/client.js`, the browser closure-factory bundle for this package's
|
|
4
|
+
* LangGraph panel.
|
|
5
|
+
*
|
|
6
|
+
* The DSH client module loader expects `window.__ModuleLoader__.load({ id,
|
|
7
|
+
* factory })`, where the factory receives the injected `require` and returns
|
|
8
|
+
* its CJS exports. The in-tree tsdown preset cannot build an out-of-tree
|
|
9
|
+
* package, so this script transpiles the one TSX entry with the TypeScript
|
|
10
|
+
* compiler and wraps the output in the same envelope. `react` and
|
|
11
|
+
* `react/jsx-runtime` stay runtime externals: the Web shell seeds both into
|
|
12
|
+
* the frozen module table.
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* node scripts/build-client.mjs
|
|
16
|
+
* DSH_TYPESCRIPT=/path/to/typescript node scripts/build-client.mjs
|
|
17
|
+
* @module @lzn1998/dsh-langgraph/scripts/build-client
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
21
|
+
import { createRequire } from 'node:module'
|
|
22
|
+
import { dirname, join, resolve } from 'node:path'
|
|
23
|
+
import { fileURLToPath } from 'node:url'
|
|
24
|
+
|
|
25
|
+
const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
|
26
|
+
const manifest = JSON.parse(readFileSync(join(packageRoot, 'package.json'), 'utf8'))
|
|
27
|
+
|
|
28
|
+
/** @param {string} message - failure text. @returns {never} */
|
|
29
|
+
function fail(message) {
|
|
30
|
+
console.error(`build-client: ${message}`)
|
|
31
|
+
process.exit(1)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Load a TypeScript package from one directory candidate. */
|
|
35
|
+
function loadTypeScript(directory) {
|
|
36
|
+
try {
|
|
37
|
+
const anchor = createRequire(join(directory, 'package.json'))
|
|
38
|
+
const ts = anchor(directory)
|
|
39
|
+
if (typeof ts?.transpileModule !== 'function') return undefined
|
|
40
|
+
return { ts, directory }
|
|
41
|
+
} catch {
|
|
42
|
+
return undefined
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const candidates = [
|
|
47
|
+
process.env.DSH_TYPESCRIPT,
|
|
48
|
+
process.env.DSH_HARNESS_ROOT === undefined ? undefined : join(process.env.DSH_HARNESS_ROOT, 'node_modules', 'typescript'),
|
|
49
|
+
join(packageRoot, 'node_modules', 'typescript'),
|
|
50
|
+
].filter(candidate => typeof candidate === 'string' && candidate.length > 0)
|
|
51
|
+
|
|
52
|
+
let toolchain
|
|
53
|
+
for (const candidate of candidates) {
|
|
54
|
+
toolchain = loadTypeScript(resolve(candidate))
|
|
55
|
+
if (toolchain !== undefined) break
|
|
56
|
+
}
|
|
57
|
+
if (toolchain === undefined) {
|
|
58
|
+
fail([
|
|
59
|
+
'cannot find the TypeScript compiler.',
|
|
60
|
+
'Set DSH_TYPESCRIPT to a typescript package directory, or DSH_HARNESS_ROOT to a',
|
|
61
|
+
'deepseek-harness checkout that carries one. Tried:',
|
|
62
|
+
...candidates.map(candidate => ` - ${resolve(candidate)}`),
|
|
63
|
+
'The committed lib/client.js is already built; this script is only for rebuilding it.',
|
|
64
|
+
].join('\n'))
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const { ts, directory } = toolchain
|
|
68
|
+
const sourceFile = join(packageRoot, 'client/index.tsx')
|
|
69
|
+
const result = ts.transpileModule(readFileSync(sourceFile, 'utf8'), {
|
|
70
|
+
fileName: 'client/index.tsx',
|
|
71
|
+
reportDiagnostics: true,
|
|
72
|
+
compilerOptions: {
|
|
73
|
+
module: ts.ModuleKind.CommonJS,
|
|
74
|
+
target: ts.ScriptTarget.ES2022,
|
|
75
|
+
jsx: ts.JsxEmit.ReactJSX,
|
|
76
|
+
newLine: ts.NewLineKind.LineFeed,
|
|
77
|
+
removeComments: false,
|
|
78
|
+
},
|
|
79
|
+
})
|
|
80
|
+
const errors = (result.diagnostics ?? []).filter(diagnostic => diagnostic.category === ts.DiagnosticCategory.Error)
|
|
81
|
+
if (errors.length > 0) {
|
|
82
|
+
fail(`${ts.formatDiagnosticsWithColorAndContext(errors, {
|
|
83
|
+
getCanonicalFileName: file => file,
|
|
84
|
+
getCurrentDirectory: () => packageRoot,
|
|
85
|
+
getNewLine: () => '\n',
|
|
86
|
+
})}`)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Indent every line so the wrapped body reads like a generated bundle. */
|
|
90
|
+
function indent(text, prefix) {
|
|
91
|
+
return text.replace(/\n$/u, '').split('\n').map(line => (line.length === 0 ? line : prefix + line)).join('\n')
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const bundle = [
|
|
95
|
+
'/**',
|
|
96
|
+
` * ${manifest.name} — browser closure-factory bundle.`,
|
|
97
|
+
' *',
|
|
98
|
+
' * Generated from client/index.tsx by scripts/build-client.mjs — do not edit by hand.',
|
|
99
|
+
' * The module loader registers this factory and materializes it on first import;',
|
|
100
|
+
' * every module-body side effect stays inside the factory closure.',
|
|
101
|
+
' */',
|
|
102
|
+
'window.__ModuleLoader__.load({',
|
|
103
|
+
`\tid: ${JSON.stringify(manifest.name)},`,
|
|
104
|
+
'\tfactory: (require) => {',
|
|
105
|
+
'\t\tvar module = { exports: {} };',
|
|
106
|
+
'\t\tvar exports = module.exports;',
|
|
107
|
+
'\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: "Module" });',
|
|
108
|
+
indent(result.outputText, '\t\t'),
|
|
109
|
+
'\t\treturn module.exports;',
|
|
110
|
+
'\t},',
|
|
111
|
+
'});',
|
|
112
|
+
'',
|
|
113
|
+
].join('\n')
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
// Compile once without executing: catches a broken emit before the browser.
|
|
117
|
+
// eslint-disable-next-line no-new-func
|
|
118
|
+
new Function(bundle)
|
|
119
|
+
} catch (error) {
|
|
120
|
+
fail(`lib/client.js is not valid JavaScript: ${String(error)}`)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
mkdirSync(join(packageRoot, 'lib'), { recursive: true })
|
|
124
|
+
writeFileSync(join(packageRoot, 'lib/client.js'), bundle)
|
|
125
|
+
console.log(`built lib/client.js (${Buffer.byteLength(bundle)} bytes)`)
|
|
126
|
+
console.log(`typescript: ${directory}`)
|