@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/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# dsh-langgraph
|
|
2
2
|
|
|
3
|
-
A DSH bundle that registers LangGraph
|
|
3
|
+
A DSH bundle that registers LangGraph graphs and exposes them to the agent as the
|
|
4
4
|
`langgraph_run` and `langgraph_threads` tools. Graph nodes call the session's own DSH
|
|
5
5
|
tools through `helpers.callTool`; threads are checkpointed in a DSH storage domain, so a
|
|
6
6
|
run survives the turn — and the Host process — and an `interrupt()`ed graph resumes
|
|
@@ -9,13 +9,27 @@ where it stopped.
|
|
|
9
9
|
- `langgraph_run` (`graph`, `input`, `thread`, `resume`, `maxSteps`, `run_in_background`;
|
|
10
10
|
omit `graph` to list). A background run returns a DSH job id; read it with `job_output`
|
|
11
11
|
and stop it with `job_kill`.
|
|
12
|
-
- `langgraph_threads` (`action`: `list` | `state` | `delete`).
|
|
12
|
+
- `langgraph_threads` (`action`: `list` | `state` | `history` | `edit` | `topology` | `delete`).
|
|
13
|
+
`history` lists checkpoints, `state` reads one by `checkpoint`, and `edit` forks a
|
|
14
|
+
checkpoint with new values. Replay the fork with `langgraph_run({ graph, thread, checkpoint })`.
|
|
15
|
+
`topology` returns a graph's JSON-safe nodes and edges for a client view.
|
|
13
16
|
- Registry: `graphs/*.js` (and `graphs/*.ts` on Node 24.22+) in this package plus `config.graphs`.
|
|
14
|
-
- Node helpers: `helpers.callTool(name, args)` for DSH tools, `helpers.
|
|
15
|
-
for a
|
|
17
|
+
- Node helpers: `helpers.callTool(name, args)` for DSH tools, `helpers.askUser(questions)`
|
|
18
|
+
for a question in DSH's native question UI, `helpers.subagent(prompt, options)` for a
|
|
19
|
+
caller-delivered DSH child agent, `helpers.callModel(prompt, options)` for this
|
|
16
20
|
deployment's model, and `helpers.chatModel()` / `helpers.tools([...])` /
|
|
17
21
|
`helpers.createReactAgent({...})` when you want LangGraph's prebuilt agent to drive DSH
|
|
18
22
|
tools with the DSH model. Node-level calls keep the agent's sandbox and approval scope.
|
|
23
|
+
- **Long-term memory:** graphs get a real LangGraph `BaseStore` over the
|
|
24
|
+
`langgraph_store` storage domain. A node reads it with LangGraph's own
|
|
25
|
+
`getStore(config)`, `build(api)` sees `api.store`, and a helper is available as
|
|
26
|
+
`helpers.store()`. It supports get/put/delete, filtered pagination, and namespace
|
|
27
|
+
listing; vector `query` search is rejected rather than faked. Without a storage domain
|
|
28
|
+
it falls back to `InMemoryStore`; `config.store: false` passes no store at all.
|
|
29
|
+
- **Model-facing guidance:** while loaded, a system-prompt section lists the registered
|
|
30
|
+
graph ids and descriptions, distinguishes `langgraph_run` from the `workflow` tool, and
|
|
31
|
+
tells the model to use a matching graph rather than reimplement it. `config.prompt: false`
|
|
32
|
+
disables it.
|
|
19
33
|
- **Trajectory trace:** each run shows up as one `langgraph_run` row; its graph nodes, DSH
|
|
20
34
|
tool calls, and model calls appear as nested sub-calls in **Trajectory** — `langgraph:node`,
|
|
21
35
|
`langgraph:tool`, `langgraph:model`, `langgraph:subagent`. The trace uses DSH's log-only
|
|
@@ -24,8 +38,18 @@ where it stopped.
|
|
|
24
38
|
source, and DSH's existing session-event vocabulary is the sink. Background runs keep the
|
|
25
39
|
same trace under their `langgraph_run` row even though the events arrive after the tool result.
|
|
26
40
|
- Threads are owned by the session and graph that created them; another session cannot
|
|
27
|
-
resume or delete them.
|
|
41
|
+
resume or delete them. Each thread keeps at most `retention` checkpoints (default 200;
|
|
42
|
+
`0` keeps every checkpoint), with their writes pruned alongside.
|
|
43
|
+
- **Web panel:** in a Web profile the plugin contributes a **LangGraph** sidebar panel that
|
|
44
|
+
lists the registered graphs, their thread counts, and the selected graph's topology
|
|
45
|
+
(nodes, edges, conditional branches). It reads two owner-only `/api/plugins/langgraph/*`
|
|
46
|
+
routes; `config.ui: false` registers neither. Token-level streaming is not part of this
|
|
47
|
+
panel; runs stay visible in Trajectory.
|
|
28
48
|
- See `docs/DETAIL.md` for the graph module contract, trace mapping, thread semantics, and limits.
|
|
49
|
+
- See `docs/CONTEXT.md` for what is injected into the model context, the vocabulary, and
|
|
50
|
+
how it stays distinct from DSH's `workflow`, `subagent`, and question tools.
|
|
51
|
+
- See `docs/ECOSYSTEM.md` for adding LangChain packages, vector stores, prebuilt agents,
|
|
52
|
+
LangSmith tracing, and streaming.
|
|
29
53
|
|
|
30
54
|
From npm: `dsh plugin --profile <name> add @lzn1998/dsh-langgraph`, then restart that
|
|
31
55
|
profile's host. From a local checkout: `dsh plugin --profile <name> add <path-to-this-directory>`.
|
package/client/index.tsx
ADDED
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser half of the LangGraph panel.
|
|
3
|
+
*
|
|
4
|
+
* Two slot contributions that share one id:
|
|
5
|
+
* - `main` key `langgraph`: the panel listing registered graphs and drawing the
|
|
6
|
+
* selected graph's topology.
|
|
7
|
+
* - `sidebar.panellist` id `langgraph`: the launcher row that selects it.
|
|
8
|
+
*
|
|
9
|
+
* The panel reads the Host plugin's authenticated routes (registered through
|
|
10
|
+
* `ctx.connection.fetch.register`, owner-only): `GET /api/plugins/langgraph/ui` for
|
|
11
|
+
* the registry and thread counts, and `GET /api/plugins/langgraph/topology?graph=`
|
|
12
|
+
* for one drawable graph. Runtime dependencies are `react` and
|
|
13
|
+
* `react/jsx-runtime` only; the Web shell seeds both into the module table.
|
|
14
|
+
* @module @lzn1998/dsh-langgraph/client
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { useCallback, useEffect, useMemo, useState } from 'react'
|
|
18
|
+
|
|
19
|
+
/** The main-panel key and the sidebar-list id: one identity for both seats. */
|
|
20
|
+
const PANEL_ID = 'langgraph'
|
|
21
|
+
|
|
22
|
+
/** Host routes served by the plugin's owner-only fetch registrations. */
|
|
23
|
+
const UI_URL = '/api/plugins/langgraph/ui'
|
|
24
|
+
const TOPOLOGY_URL = '/api/plugins/langgraph/topology'
|
|
25
|
+
|
|
26
|
+
/** Refresh cadence for the registry and thread counts. */
|
|
27
|
+
const POLL_MS = 5000
|
|
28
|
+
|
|
29
|
+
/** The injected stylesheet's ownership id. */
|
|
30
|
+
const STYLE_ID = '@lzn1998/dsh-langgraph/client.css'
|
|
31
|
+
|
|
32
|
+
/** One registered graph as `GET /ui` reports it. */
|
|
33
|
+
interface GraphItem {
|
|
34
|
+
id: string
|
|
35
|
+
description?: string
|
|
36
|
+
input?: unknown
|
|
37
|
+
error?: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The registry plus durable-thread counts. */
|
|
41
|
+
interface UiPayload {
|
|
42
|
+
graphs: GraphItem[]
|
|
43
|
+
threads: { total: number; byGraph: Record<string, number>; durable: boolean }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** One drawable node. */
|
|
47
|
+
interface TopologyNode {
|
|
48
|
+
id: string
|
|
49
|
+
type?: string
|
|
50
|
+
name?: string
|
|
51
|
+
description?: string
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** One drawable edge; `conditional` marks a branch. */
|
|
55
|
+
interface TopologyEdge {
|
|
56
|
+
source: string
|
|
57
|
+
target: string
|
|
58
|
+
conditional?: boolean
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** One graph's drawable topology. */
|
|
62
|
+
interface TopologyPayload {
|
|
63
|
+
graph: string
|
|
64
|
+
description?: string
|
|
65
|
+
input?: unknown
|
|
66
|
+
nodes: TopologyNode[]
|
|
67
|
+
edges: TopologyEdge[]
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** The context slice this plugin uses, declared structurally. */
|
|
71
|
+
export interface PanelContext {
|
|
72
|
+
readonly slots: {
|
|
73
|
+
inject(key: string, factory: () => () => void): () => void
|
|
74
|
+
register(options: Readonly<Record<string, unknown>>, component: unknown): () => void
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Cordis services this browser plugin needs before it applies. */
|
|
79
|
+
export const inject = ['slots']
|
|
80
|
+
|
|
81
|
+
// ── host reads ───────────────────────────────────────────────────────────────
|
|
82
|
+
|
|
83
|
+
/** Read one JSON route, raising the Host's error message when it refuses. */
|
|
84
|
+
async function readJson<T>(url: string): Promise<T> {
|
|
85
|
+
const response = await fetch(url, { headers: { accept: 'application/json' } })
|
|
86
|
+
const payload = await response.json().catch(() => ({})) as { error?: unknown }
|
|
87
|
+
if (!response.ok) {
|
|
88
|
+
throw new Error(typeof payload?.error === 'string' ? payload.error : `HTTP ${response.status}`)
|
|
89
|
+
}
|
|
90
|
+
return payload as T
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** One-line message for an unknown thrown value. */
|
|
94
|
+
function messageOf(error: unknown): string {
|
|
95
|
+
return error instanceof Error ? error.message : String(error)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// ── topology layout ──────────────────────────────────────────────────────────
|
|
99
|
+
|
|
100
|
+
const NODE_WIDTH = 150
|
|
101
|
+
const NODE_HEIGHT = 44
|
|
102
|
+
const COLUMN_GAP = 82
|
|
103
|
+
const ROW_GAP = 34
|
|
104
|
+
const PADDING = 24
|
|
105
|
+
|
|
106
|
+
interface PlacedNode extends TopologyNode {
|
|
107
|
+
x: number
|
|
108
|
+
y: number
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
interface PlacedEdge {
|
|
112
|
+
path: string
|
|
113
|
+
conditional: boolean
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
interface Drawing {
|
|
117
|
+
width: number
|
|
118
|
+
height: number
|
|
119
|
+
nodes: PlacedNode[]
|
|
120
|
+
edges: PlacedEdge[]
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Assign every node the BFS depth from `__start__` (unreachable nodes stay at 0). */
|
|
124
|
+
function levelsOf(topology: TopologyPayload): Map<string, number> {
|
|
125
|
+
const levels = new Map<string, number>()
|
|
126
|
+
const bySource = new Map<string, string[]>()
|
|
127
|
+
for (const edge of topology.edges) {
|
|
128
|
+
const targets = bySource.get(edge.source) ?? []
|
|
129
|
+
targets.push(edge.target)
|
|
130
|
+
bySource.set(edge.source, targets)
|
|
131
|
+
}
|
|
132
|
+
const start = topology.nodes.some(node => node.id === '__start__') ? '__start__' : topology.nodes[0]?.id
|
|
133
|
+
if (start === undefined) return levels
|
|
134
|
+
levels.set(start, 0)
|
|
135
|
+
const queue = [start]
|
|
136
|
+
while (queue.length > 0) {
|
|
137
|
+
const id = queue.shift() as string
|
|
138
|
+
for (const target of bySource.get(id) ?? []) {
|
|
139
|
+
if (levels.has(target)) continue
|
|
140
|
+
levels.set(target, (levels.get(id) ?? 0) + 1)
|
|
141
|
+
queue.push(target)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return levels
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Place columns by depth and rows within a column, then route every edge. */
|
|
148
|
+
function drawTopology(topology: TopologyPayload): Drawing {
|
|
149
|
+
const levels = levelsOf(topology)
|
|
150
|
+
const columns = new Map<number, TopologyNode[]>()
|
|
151
|
+
for (const node of topology.nodes) {
|
|
152
|
+
const level = levels.get(node.id) ?? 0
|
|
153
|
+
const column = columns.get(level) ?? []
|
|
154
|
+
column.push(node)
|
|
155
|
+
columns.set(level, column)
|
|
156
|
+
}
|
|
157
|
+
for (const column of columns.values()) {
|
|
158
|
+
column.sort((left, right) => {
|
|
159
|
+
const leftEnd = left.id === '__end__' ? 1 : 0
|
|
160
|
+
const rightEnd = right.id === '__end__' ? 1 : 0
|
|
161
|
+
return leftEnd - rightEnd
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
const placed = new Map<string, PlacedNode>()
|
|
165
|
+
const depths = [...columns.keys()].sort((left, right) => left - right)
|
|
166
|
+
let maxRows = 0
|
|
167
|
+
for (const depth of depths) {
|
|
168
|
+
const column = columns.get(depth) ?? []
|
|
169
|
+
maxRows = Math.max(maxRows, column.length)
|
|
170
|
+
column.forEach((node, row) => {
|
|
171
|
+
placed.set(node.id, {
|
|
172
|
+
...node,
|
|
173
|
+
x: PADDING + depth * (NODE_WIDTH + COLUMN_GAP),
|
|
174
|
+
y: PADDING + row * (NODE_HEIGHT + ROW_GAP),
|
|
175
|
+
})
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
const nodes = [...placed.values()]
|
|
179
|
+
const edges: PlacedEdge[] = []
|
|
180
|
+
for (const edge of topology.edges) {
|
|
181
|
+
const source = placed.get(edge.source)
|
|
182
|
+
const target = placed.get(edge.target)
|
|
183
|
+
if (source === undefined || target === undefined) continue
|
|
184
|
+
const sx = source.x + NODE_WIDTH
|
|
185
|
+
const sy = source.y + NODE_HEIGHT / 2
|
|
186
|
+
const tx = target.x
|
|
187
|
+
const ty = target.y + NODE_HEIGHT / 2
|
|
188
|
+
const bend = Math.max(40, Math.abs(tx - sx) / 2)
|
|
189
|
+
let path
|
|
190
|
+
if (tx > sx) {
|
|
191
|
+
path = `M ${sx} ${sy} C ${sx + bend} ${sy}, ${tx - bend} ${ty}, ${tx} ${ty}`
|
|
192
|
+
} else if (tx === sx) {
|
|
193
|
+
// Same column: leave to the right and come into the target's top edge.
|
|
194
|
+
const center = target.x + NODE_WIDTH / 2
|
|
195
|
+
path = `M ${sx} ${sy} C ${sx + 70} ${sy}, ${center + 70} ${target.y - 28}, ${center} ${target.y}`
|
|
196
|
+
} else {
|
|
197
|
+
path = `M ${sx} ${sy} C ${sx + bend} ${sy + 40}, ${tx - bend} ${ty + 40}, ${tx} ${ty}`
|
|
198
|
+
}
|
|
199
|
+
edges.push({ path, conditional: edge.conditional === true })
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
width: PADDING * 2 + Math.max(1, depths.length) * (NODE_WIDTH + COLUMN_GAP) - COLUMN_GAP,
|
|
203
|
+
height: PADDING * 2 + Math.max(1, maxRows) * (NODE_HEIGHT + ROW_GAP) - ROW_GAP,
|
|
204
|
+
nodes,
|
|
205
|
+
edges,
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** Draw one topology as a small left-to-right diagram. */
|
|
210
|
+
function TopologyView({ topology }: { topology: TopologyPayload }) {
|
|
211
|
+
const drawing = useMemo(() => drawTopology(topology), [topology])
|
|
212
|
+
return (
|
|
213
|
+
<div className="lg-topology">
|
|
214
|
+
<svg viewBox={`0 0 ${drawing.width} ${drawing.height}`} role="img" aria-label={`${topology.graph} topology`}>
|
|
215
|
+
<defs>
|
|
216
|
+
<marker id="lg-arrow" viewBox="0 0 8 8" refX="7" refY="4" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
|
217
|
+
<path d="M 0 0 L 8 4 L 0 8 z" className="lg-arrow" />
|
|
218
|
+
</marker>
|
|
219
|
+
</defs>
|
|
220
|
+
{drawing.edges.map((edge, index) => (
|
|
221
|
+
<path
|
|
222
|
+
key={`edge-${index}`}
|
|
223
|
+
d={edge.path}
|
|
224
|
+
className={edge.conditional ? 'lg-edge lg-edge-conditional' : 'lg-edge'}
|
|
225
|
+
markerEnd="url(#lg-arrow)"
|
|
226
|
+
/>
|
|
227
|
+
))}
|
|
228
|
+
{drawing.nodes.map(node => (
|
|
229
|
+
<g key={node.id} transform={`translate(${node.x},${node.y})`}>
|
|
230
|
+
<rect
|
|
231
|
+
width={NODE_WIDTH}
|
|
232
|
+
height={NODE_HEIGHT}
|
|
233
|
+
rx={10}
|
|
234
|
+
className={node.id === '__start__' || node.id === '__end__' ? 'lg-node lg-node-terminal' : 'lg-node'}
|
|
235
|
+
/>
|
|
236
|
+
<text x={NODE_WIDTH / 2} y={NODE_HEIGHT / 2 + 4} textAnchor="middle" className="lg-node-label">
|
|
237
|
+
{node.id === '__start__' ? 'start' : node.id === '__end__' ? 'end' : node.name ?? node.id}
|
|
238
|
+
</text>
|
|
239
|
+
<title>{node.description ?? node.id}</title>
|
|
240
|
+
</g>
|
|
241
|
+
))}
|
|
242
|
+
</svg>
|
|
243
|
+
</div>
|
|
244
|
+
)
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// ── panel ────────────────────────────────────────────────────────────────────
|
|
248
|
+
|
|
249
|
+
/** The panel body: registry on the left, selected topology on the right. */
|
|
250
|
+
function LangGraphPanel() {
|
|
251
|
+
const [ui, setUi] = useState<UiPayload>()
|
|
252
|
+
const [uiError, setUiError] = useState<string>()
|
|
253
|
+
const [selected, setSelected] = useState<string>()
|
|
254
|
+
const [topology, setTopology] = useState<TopologyPayload>()
|
|
255
|
+
const [topologyError, setTopologyError] = useState<string>()
|
|
256
|
+
const [busy, setBusy] = useState(false)
|
|
257
|
+
|
|
258
|
+
const refresh = useCallback(async () => {
|
|
259
|
+
try {
|
|
260
|
+
const next = await readJson<UiPayload>(UI_URL)
|
|
261
|
+
setUi(next)
|
|
262
|
+
setUiError(undefined)
|
|
263
|
+
setSelected(current => current !== undefined && next.graphs.some(graph => graph.id === current)
|
|
264
|
+
? current
|
|
265
|
+
: next.graphs[0]?.id)
|
|
266
|
+
} catch (error) {
|
|
267
|
+
setUiError(messageOf(error))
|
|
268
|
+
}
|
|
269
|
+
}, [])
|
|
270
|
+
|
|
271
|
+
useEffect(() => {
|
|
272
|
+
void refresh()
|
|
273
|
+
const timer = window.setInterval(() => { void refresh() }, POLL_MS)
|
|
274
|
+
return () => { window.clearInterval(timer) }
|
|
275
|
+
}, [refresh])
|
|
276
|
+
|
|
277
|
+
useEffect(() => {
|
|
278
|
+
if (selected === undefined) {
|
|
279
|
+
setTopology(undefined)
|
|
280
|
+
return undefined
|
|
281
|
+
}
|
|
282
|
+
let live = true
|
|
283
|
+
setBusy(true)
|
|
284
|
+
setTopologyError(undefined)
|
|
285
|
+
readJson<TopologyPayload>(`${TOPOLOGY_URL}?graph=${encodeURIComponent(selected)}`)
|
|
286
|
+
.then(next => { if (live) setTopology(next) })
|
|
287
|
+
.catch(error => {
|
|
288
|
+
if (!live) return
|
|
289
|
+
setTopology(undefined)
|
|
290
|
+
setTopologyError(messageOf(error))
|
|
291
|
+
})
|
|
292
|
+
.finally(() => { if (live) setBusy(false) })
|
|
293
|
+
return () => { live = false }
|
|
294
|
+
}, [selected])
|
|
295
|
+
|
|
296
|
+
const selectedGraph = ui?.graphs.find(graph => graph.id === selected)
|
|
297
|
+
return (
|
|
298
|
+
<section className="lg-panel" aria-label="LangGraph graphs">
|
|
299
|
+
<header className="lg-header">
|
|
300
|
+
<div>
|
|
301
|
+
<h2 className="lg-title">LangGraph</h2>
|
|
302
|
+
<p className="lg-muted">
|
|
303
|
+
{ui === undefined
|
|
304
|
+
? 'Loading graphs…'
|
|
305
|
+
: `${ui.graphs.length} graph${ui.graphs.length === 1 ? '' : 's'} · ${ui.threads.total} durable thread${ui.threads.total === 1 ? '' : 's'}`}
|
|
306
|
+
</p>
|
|
307
|
+
</div>
|
|
308
|
+
<button type="button" className="lg-button" onClick={() => { void refresh() }}>Refresh</button>
|
|
309
|
+
</header>
|
|
310
|
+
|
|
311
|
+
{uiError !== undefined && <p className="lg-error">{uiError}</p>}
|
|
312
|
+
|
|
313
|
+
<div className="lg-grid">
|
|
314
|
+
<nav className="lg-list" aria-label="Registered graphs">
|
|
315
|
+
{(ui?.graphs ?? []).map(graph => (
|
|
316
|
+
<button
|
|
317
|
+
key={graph.id}
|
|
318
|
+
type="button"
|
|
319
|
+
className={graph.id === selected ? 'lg-item lg-item-active' : 'lg-item'}
|
|
320
|
+
onClick={() => setSelected(graph.id)}
|
|
321
|
+
>
|
|
322
|
+
<span className="lg-item-id">{graph.id}</span>
|
|
323
|
+
<span className="lg-item-meta">
|
|
324
|
+
{graph.error ?? `${ui?.threads.byGraph[graph.id] ?? 0} thread${(ui?.threads.byGraph[graph.id] ?? 0) === 1 ? '' : 's'}`}
|
|
325
|
+
</span>
|
|
326
|
+
{graph.error === undefined && graph.description !== undefined && (
|
|
327
|
+
<span className="lg-item-desc">{graph.description}</span>
|
|
328
|
+
)}
|
|
329
|
+
</button>
|
|
330
|
+
))}
|
|
331
|
+
{ui !== undefined && ui.graphs.length === 0 && <p className="lg-muted">No graphs registered.</p>}
|
|
332
|
+
</nav>
|
|
333
|
+
|
|
334
|
+
<div className="lg-canvas">
|
|
335
|
+
{topologyError !== undefined && <p className="lg-error">{topologyError}</p>}
|
|
336
|
+
{busy && <p className="lg-muted">Loading topology…</p>}
|
|
337
|
+
{!busy && topology !== undefined && <TopologyView topology={topology} />}
|
|
338
|
+
{!busy && topology === undefined && topologyError === undefined && (
|
|
339
|
+
<p className="lg-muted">Select a graph to see its nodes and edges.</p>
|
|
340
|
+
)}
|
|
341
|
+
</div>
|
|
342
|
+
</div>
|
|
343
|
+
|
|
344
|
+
<footer className="lg-footer">
|
|
345
|
+
{selectedGraph?.description ?? 'Runs appear as langgraph_run rows in Trajectory.'}
|
|
346
|
+
</footer>
|
|
347
|
+
</section>
|
|
348
|
+
)
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** Sidebar launcher icon: one node feeding two others. */
|
|
352
|
+
function LangGraphIcon() {
|
|
353
|
+
return (
|
|
354
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" aria-hidden="true">
|
|
355
|
+
<rect x="2" y="9" width="6" height="6" rx="2" stroke="currentColor" strokeWidth="1.6" />
|
|
356
|
+
<rect x="16" y="2" width="6" height="6" rx="2" stroke="currentColor" strokeWidth="1.6" />
|
|
357
|
+
<rect x="16" y="16" width="6" height="6" rx="2" stroke="currentColor" strokeWidth="1.6" />
|
|
358
|
+
<path d="M8 12h4v-7h4M12 12v7h4" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" />
|
|
359
|
+
</svg>
|
|
360
|
+
)
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// ── styles ───────────────────────────────────────────────────────────────────
|
|
364
|
+
|
|
365
|
+
const PANEL_CSS = `
|
|
366
|
+
.lg-panel { display: flex; flex-direction: column; height: 100%; min-height: 0; padding: 18px 20px; gap: 14px; color: inherit; font: inherit; }
|
|
367
|
+
.lg-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
|
|
368
|
+
.lg-title { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: .01em; }
|
|
369
|
+
.lg-muted { margin: 2px 0 0; opacity: .62; font-size: 12px; }
|
|
370
|
+
.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; }
|
|
371
|
+
.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; }
|
|
372
|
+
.lg-button:hover { background: color-mix(in srgb, currentColor 8%, transparent); }
|
|
373
|
+
.lg-grid { display: grid; grid-template-columns: minmax(190px, 250px) minmax(0, 1fr); gap: 14px; min-height: 0; flex: 1; }
|
|
374
|
+
.lg-list { display: flex; flex-direction: column; gap: 6px; overflow: auto; padding-right: 2px; }
|
|
375
|
+
.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; }
|
|
376
|
+
.lg-item:hover { background: color-mix(in srgb, currentColor 6%, transparent); }
|
|
377
|
+
.lg-item-active { border-color: color-mix(in srgb, currentColor 40%, transparent); background: color-mix(in srgb, currentColor 9%, transparent); }
|
|
378
|
+
.lg-item-id { font-size: 13px; font-weight: 600; }
|
|
379
|
+
.lg-item-meta { font-size: 11px; opacity: .58; }
|
|
380
|
+
.lg-item-desc { font-size: 11px; opacity: .72; line-height: 1.35; }
|
|
381
|
+
.lg-canvas { min-height: 0; overflow: auto; border: 1px solid color-mix(in srgb, currentColor 12%, transparent); border-radius: 12px; padding: 12px; }
|
|
382
|
+
.lg-topology { min-width: min-content; }
|
|
383
|
+
.lg-topology svg { display: block; max-width: 100%; height: auto; overflow: visible; }
|
|
384
|
+
.lg-node { fill: color-mix(in srgb, currentColor 7%, transparent); stroke: color-mix(in srgb, currentColor 38%, transparent); stroke-width: 1.2; }
|
|
385
|
+
.lg-node-terminal { fill: transparent; stroke-dasharray: 4 4; }
|
|
386
|
+
.lg-node-label { fill: currentColor; font-size: 12px; font-weight: 550; }
|
|
387
|
+
.lg-edge { fill: none; stroke: color-mix(in srgb, currentColor 42%, transparent); stroke-width: 1.4; }
|
|
388
|
+
.lg-edge-conditional { stroke-dasharray: 6 4; }
|
|
389
|
+
.lg-arrow { fill: color-mix(in srgb, currentColor 55%, transparent); }
|
|
390
|
+
.lg-footer { font-size: 11px; opacity: .55; border-top: 1px solid color-mix(in srgb, currentColor 10%, transparent); padding-top: 9px; }
|
|
391
|
+
`
|
|
392
|
+
|
|
393
|
+
/** Inject the panel stylesheet once per page. */
|
|
394
|
+
function installStyles(): void {
|
|
395
|
+
if (document.querySelector(`style[data-plugin-css="${STYLE_ID}"]`) !== null) return
|
|
396
|
+
const tag = document.createElement('style')
|
|
397
|
+
tag.dataset.plugin = '@lzn1998/dsh-langgraph'
|
|
398
|
+
tag.dataset.pluginCss = STYLE_ID
|
|
399
|
+
tag.textContent = PANEL_CSS
|
|
400
|
+
document.head.appendChild(tag)
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Contribute the panel and its sidebar launcher. `slots.inject` waits for each
|
|
405
|
+
* slot's declaration, so activation order does not matter; the disposers
|
|
406
|
+
* belong to this plugin's fiber.
|
|
407
|
+
* @param ctx - browser context carrying the slot registry.
|
|
408
|
+
*/
|
|
409
|
+
export function apply(ctx: PanelContext): void {
|
|
410
|
+
installStyles()
|
|
411
|
+
ctx.slots.inject('main', () => ctx.slots.register({ name: 'main', key: PANEL_ID }, LangGraphPanel))
|
|
412
|
+
ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
|
|
413
|
+
name: 'sidebar.panellist',
|
|
414
|
+
id: PANEL_ID,
|
|
415
|
+
order: 32,
|
|
416
|
+
label: 'LangGraph',
|
|
417
|
+
}, LangGraphIcon))
|
|
418
|
+
}
|
package/cordis.patch.yml
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
# Registers the LangGraph workflow tools. Graphs live in the package's `graphs/`
|
|
2
2
|
# directory; `config.graphs` adds more modules, `config.recursionLimit` bounds a run,
|
|
3
3
|
# `config.model` overrides the route graph nodes use for model calls, `config.trace:
|
|
4
|
-
# false` turns off the Trajectory sub-call trace, `config.
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
# `
|
|
4
|
+
# false` turns off the Trajectory sub-call trace, `config.prompt: false` turns off
|
|
5
|
+
# the model-facing system-prompt graph guidance, `config.background: false` hides
|
|
6
|
+
# background runs, `config.subagentProvider` selects the provider for
|
|
7
|
+
# `helpers.subagent` (default `spawn`), and `config.store: false` passes no
|
|
8
|
+
# long-term BaseStore to graphs. Threads are checkpointed in the
|
|
9
|
+
# `langgraph_checkpoints` storage domain and keep `config.retention` checkpoints
|
|
10
|
+
# each (default 200; 0 is unlimited); long-term memories live in
|
|
11
|
+
# `langgraph_store`. In a Web profile `config.ui: false` also turns off the
|
|
12
|
+
# panel's owner-only routes.
|
|
8
13
|
- insert:
|
|
9
14
|
- id: langgraph
|
|
10
15
|
name: '@lzn1998/dsh-langgraph'
|
package/docs/CONTEXT.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# Context and prompt design
|
|
2
|
+
|
|
3
|
+
This plugin adds one vocabulary and two tools to a DSH profile. This page records
|
|
4
|
+
exactly what it injects, what it deliberately does not inject, and how that layer stays
|
|
5
|
+
distinct from DSH's own prompt and tools.
|
|
6
|
+
|
|
7
|
+
## What is injected
|
|
8
|
+
|
|
9
|
+
| Layer | Contribution | Lifetime |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| Tool schemas | `langgraph_run`, `langgraph_threads` | While the plugin is loaded; `config.prompt: false` does not remove them. |
|
|
12
|
+
| System-prompt section | `tool:langgraph`, order `TOOL_SUBAGENT - 10` | Effect-owned by the plugin; `config.prompt: false` disables it. |
|
|
13
|
+
| Runtime context | **none** | — |
|
|
14
|
+
| Session events | none from the model's point of view | Traces are log-only DSH PTC events for Trajectory. |
|
|
15
|
+
|
|
16
|
+
The section is a text function, so the model sees a short "call it to list" hint until
|
|
17
|
+
the asynchronous registry scan finishes, then the graph list (up to 24 ids and one-line
|
|
18
|
+
descriptions; input schemas stay out of the prompt). `langgraph_run` with no `graph`
|
|
19
|
+
always returns the full list and schemas.
|
|
20
|
+
|
|
21
|
+
### Why no runtime context
|
|
22
|
+
|
|
23
|
+
`ctx.systemPrompt.context` materializes durable user-role snapshots. The plugin does not
|
|
24
|
+
use it because:
|
|
25
|
+
|
|
26
|
+
- The graph catalog is a profile-level fact, not a per-turn fact; a section is the right
|
|
27
|
+
layer and can be cached.
|
|
28
|
+
- The only genuinely dynamic facts are the calling session's threads and checkpoints.
|
|
29
|
+
Those are read on demand with `langgraph_threads`; injecting them every turn would
|
|
30
|
+
duplicate state, grow tokens, and go stale.
|
|
31
|
+
- `AssembleContext` carries no session identity, so a context contribution could not be
|
|
32
|
+
scoped to the calling session without a new DSH seam. The plugin does not invent one.
|
|
33
|
+
|
|
34
|
+
## Vocabulary
|
|
35
|
+
|
|
36
|
+
| Term | Meaning in this plugin | Not |
|
|
37
|
+
|---|---|---|
|
|
38
|
+
| **graph** | A module registered with the profile (`id`, `description`, `input`, `build`). | The `workflow` tool's ad-hoc JavaScript script. |
|
|
39
|
+
| **graph run** | One execution with an input, returning a state. | A DSH turn or Session. |
|
|
40
|
+
| **thread** | A durable LangGraph checkpoint chain for one graph run, owned by the session and graph that created it. | A DSH Session. |
|
|
41
|
+
| **checkpoint** | One snapshot in a thread; `history`, `edit`, and replay address it by id. | A DSH session checkpoint. |
|
|
42
|
+
| **background run** | A graph run started as a DSH job; read with `job_output`, stop with `job_kill`. | A detached process. |
|
|
43
|
+
| **Trajectory record** | The log-only `langgraph:node` / `langgraph:tool` / `langgraph:model` sub-calls under the `langgraph_run` row. | Model-visible conversation content. |
|
|
44
|
+
| **store** | An optional graph-owned `BaseStore`; not a model-facing facility by itself. | A reason to call `langgraph_run`. |
|
|
45
|
+
|
|
46
|
+
## Trigger policy
|
|
47
|
+
|
|
48
|
+
The section states one policy, in the same words the model sees:
|
|
49
|
+
|
|
50
|
+
1. **Name** — the user names one of the registered graph ids.
|
|
51
|
+
2. **Match** — a graph's description matches the **requested output**, not merely the
|
|
52
|
+
same files or tools. `scan-report` matches “is this a lot?”; an exact file count is a
|
|
53
|
+
glob/bash task, so the graph is not a match even though it also counts.
|
|
54
|
+
3. **Property** — the task needs a durable thread, a background run (DSH job),
|
|
55
|
+
checkpoint history or replay, a Trajectory sub-call record, or a graph that interrupts.
|
|
56
|
+
|
|
57
|
+
It also says what *not* to do: when no graph's output matches, use ordinary DSH tools;
|
|
58
|
+
do not wrap a single tool call in a graph for ceremony, and do not reimplement a matching
|
|
59
|
+
graph with `bash`, `subagent`, or ad-hoc steps. This keeps graph
|
|
60
|
+
use from becoming ceremony while still letting a matching graph win over a hand-rolled
|
|
61
|
+
sequence.
|
|
62
|
+
|
|
63
|
+
The tool description covers mechanics (arguments, thread/resume/checkpoint, background
|
|
64
|
+
job), not selection; the section covers selection, not mechanics. This split is the main
|
|
65
|
+
rule for future edits.
|
|
66
|
+
|
|
67
|
+
## Boundaries with DSH's own context
|
|
68
|
+
|
|
69
|
+
| DSH facility | Boundary |
|
|
70
|
+
|---|---|
|
|
71
|
+
| `workflow` tool | `workflow` writes an ad-hoc JavaScript fan-out script; `langgraph_run` runs a profile-registered, named graph with a durable thread. The section sits **after** the workflow tool's "only when the user asks" rule and **before** subagent guidance (`TOOL_SUBAGENT - 10`), so that rule cannot read as part of this section. |
|
|
72
|
+
| `subagent` | One-off delegation stays `subagent`; a graph may delegate internally, and `helpers.subagent` creates a normal DSH child. |
|
|
73
|
+
| `ask_user_question` | The native question tool is the default for one question; the `ask-user` graph only adds value when a graph or thread is wanted. |
|
|
74
|
+
| `job_output` / `job_kill` | A background graph run is a DSH job; use the stock job tools. |
|
|
75
|
+
| DSH Session | A LangGraph thread is not a Session; the prompt and tool schema say so explicitly. |
|
|
76
|
+
| Trajectory | Graph activity appears as nested log-only sub-calls; it is not injected into model context. |
|
|
77
|
+
| Goals, schedules | Out of scope; the plugin does not create either. |
|
|
78
|
+
|
|
79
|
+
## Placement
|
|
80
|
+
|
|
81
|
+
- Order: `ctx.systemPrompt.getSectionOrder('TOOL_SUBAGENT') - 10`, fallback `2790`.
|
|
82
|
+
The earlier `TOOL_WORKFLOW` (2600) placement put the section between two copies of the
|
|
83
|
+
workflow tool's "ONLY when..." guidance and made the two "workflow" instructions read
|
|
84
|
+
as one.
|
|
85
|
+
- The section is global to the profile while the plugin is active, including agents whose
|
|
86
|
+
tool policy hides `langgraph_run`; `config.prompt: false` is the escape hatch.
|
|
87
|
+
- Registry entries are sorted by id; broken modules are skipped from the list.
|
|
88
|
+
|
|
89
|
+
## Maintenance checklist
|
|
90
|
+
|
|
91
|
+
When changing this layer:
|
|
92
|
+
|
|
93
|
+
1. Keep the words **graph**, **thread**, **checkpoint**, and **DSH job** consistent in the
|
|
94
|
+
prompt, tool descriptions, error messages, UI, and docs.
|
|
95
|
+
2. Do not use "workflow" as a synonym for a graph; it belongs only in the explicit
|
|
96
|
+
distinction from the `workflow` tool.
|
|
97
|
+
3. Add a trigger only if it is a property the plugin actually provides; do not advertise
|
|
98
|
+
long-term memory unless a graph uses the store.
|
|
99
|
+
4. Keep the section about selection and the tool descriptions about mechanics.
|
|
100
|
+
5. Keep graph descriptions one line, unique, and specific about the graph's value; avoid
|
|
101
|
+
demo overlap.
|
|
102
|
+
6. Re-check section order when a DSH release adds or renames prompt sections.
|