@lzn1998/dsh-langgraph 0.0.0-stage → 0.13.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/LICENSE +21 -0
- package/README.md +51 -2
- package/client/index.tsx +418 -0
- package/cordis.patch.yml +16 -0
- package/docs/DETAIL.md +422 -0
- package/docs/ECOSYSTEM.md +134 -0
- package/docs/architecture.svg +117 -0
- package/dsh-chat-model.js +157 -0
- package/dsh-checkpointer.js +585 -0
- package/dsh-store.js +262 -0
- package/dsh-tools.js +56 -0
- package/dsh-trace.js +313 -0
- package/graphs/approval-gate.js +52 -0
- package/graphs/ask-subagent.js +48 -0
- package/graphs/ask-tools.js +57 -0
- package/graphs/ask-user.js +51 -0
- package/graphs/ask-workspace.js +48 -0
- package/graphs/scan-report.js +51 -0
- package/graphs/typed-report.ts +58 -0
- package/icon.svg +11 -0
- package/index.d.ts +155 -0
- package/index.js +1315 -0
- package/lib/client.js +273 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +71 -4
- package/scripts/build-client.mjs +126 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example graph that delegates one task to a DSH subagent.
|
|
3
|
+
*
|
|
4
|
+
* `helpers.subagent(prompt, options)` starts a caller-delivered child through
|
|
5
|
+
* `ctx.subagents`, awaits its final output, and disposes the exact activation.
|
|
6
|
+
* The child has its own Session and tool scope; the parent graph only sees the
|
|
7
|
+
* returned text/structured result. In Trajectory the delegation appears as a
|
|
8
|
+
* `langgraph:subagent` sub-call under the enclosing node.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Graph id used by the `langgraph_run` tool. */
|
|
12
|
+
export const id = 'ask-subagent'
|
|
13
|
+
|
|
14
|
+
/** One-line description shown when the agent lists graphs. */
|
|
15
|
+
export const description = 'Delegate a question to a DSH subagent from inside a graph node.'
|
|
16
|
+
|
|
17
|
+
/** JSON Schema of the initial state, shown to the agent when it lists graphs. */
|
|
18
|
+
export const input = {
|
|
19
|
+
type: 'object',
|
|
20
|
+
properties: {
|
|
21
|
+
question: { type: 'string', description: 'Task sent to the child agent.' },
|
|
22
|
+
},
|
|
23
|
+
additionalProperties: false,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Build the graph.
|
|
28
|
+
* @param {object} api - LangGraph API plus `helpers` bound to one run.
|
|
29
|
+
* @returns {object} an uncompiled StateGraph.
|
|
30
|
+
*/
|
|
31
|
+
export function build({ StateGraph, Annotation, START, END, helpers }) {
|
|
32
|
+
const State = Annotation.Root({
|
|
33
|
+
question: Annotation({ reducer: (_, next) => next, default: () => 'What is this workspace?' }),
|
|
34
|
+
answer: Annotation({ reducer: (_, next) => next, default: () => '' }),
|
|
35
|
+
stopReason: Annotation({ reducer: (_, next) => next, default: () => '' }),
|
|
36
|
+
child: Annotation({ reducer: (_, next) => next, default: () => '' }),
|
|
37
|
+
})
|
|
38
|
+
return new StateGraph(State)
|
|
39
|
+
.addNode('delegate', async state => {
|
|
40
|
+
const result = await helpers.subagent(
|
|
41
|
+
`${state.question}\n\nUse this workspace's tools when you need evidence, and answer in at most three sentences.`,
|
|
42
|
+
{ label: 'langgraph delegation' },
|
|
43
|
+
)
|
|
44
|
+
return { answer: result.text, stopReason: result.stopReason, child: result.name }
|
|
45
|
+
})
|
|
46
|
+
.addEdge(START, 'delegate')
|
|
47
|
+
.addEdge('delegate', END)
|
|
48
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example ReAct workflow: LangGraph's prebuilt agent driving DSH tools with this
|
|
3
|
+
* deployment's model.
|
|
4
|
+
*
|
|
5
|
+
* This is the "LangGraph in DSH" case end to end: the graph is LangGraph's own
|
|
6
|
+
* prebuilt agent, its chat model is the DSH model route (`helpers.chatModel()`), and
|
|
7
|
+
* every tool it calls is a DSH tool ran in this session's scope (`helpers.tools`).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Graph id used by the `langgraph_run` tool. */
|
|
11
|
+
export const id = 'ask-tools'
|
|
12
|
+
|
|
13
|
+
/** One-line description shown when the agent lists graphs. */
|
|
14
|
+
export const description = 'Answer a question about this workspace with a ReAct agent over the glob/read tools.'
|
|
15
|
+
|
|
16
|
+
/** JSON Schema of the initial state, shown to the agent when it lists graphs. */
|
|
17
|
+
export const input = {
|
|
18
|
+
type: 'object',
|
|
19
|
+
properties: {
|
|
20
|
+
question: { type: 'string', description: 'Question about this workspace.' },
|
|
21
|
+
},
|
|
22
|
+
additionalProperties: false,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Build the graph.
|
|
27
|
+
* @param {object} api - LangGraph API plus `helpers` bound to one run.
|
|
28
|
+
* @returns {Promise<object>} a compiled LangGraph.
|
|
29
|
+
*/
|
|
30
|
+
export async function build({ StateGraph, Annotation, START, END, helpers }) {
|
|
31
|
+
const State = Annotation.Root({
|
|
32
|
+
question: Annotation({ reducer: (_, next) => next, default: () => 'What kind of project is this workspace?' }),
|
|
33
|
+
answer: Annotation({ reducer: (_, next) => next, default: () => '' }),
|
|
34
|
+
toolCalls: Annotation({ reducer: (_, next) => next, default: () => 0 }),
|
|
35
|
+
})
|
|
36
|
+
const agent = await helpers.createReactAgent({
|
|
37
|
+
llm: helpers.chatModel({ temperature: 0 }),
|
|
38
|
+
tools: helpers.tools(['glob', 'read']),
|
|
39
|
+
prompt: 'You inspect a workspace with two tools and answer in at most three sentences.',
|
|
40
|
+
})
|
|
41
|
+
return new StateGraph(State)
|
|
42
|
+
.addNode('react', async state => {
|
|
43
|
+
const result = await agent.invoke({ messages: [['human', state.question]] })
|
|
44
|
+
const messages = result.messages ?? []
|
|
45
|
+
const last = messages[messages.length - 1]
|
|
46
|
+
const text = typeof last?.content === 'string'
|
|
47
|
+
? last.content
|
|
48
|
+
: Array.isArray(last?.content)
|
|
49
|
+
? last.content.map(part => (part?.type === 'text' ? part.text : '')).join('')
|
|
50
|
+
: String(last?.content ?? '')
|
|
51
|
+
const toolCalls = messages.filter(message => (message.getType?.() ?? '') === 'ai')
|
|
52
|
+
.reduce((total, message) => total + (message.tool_calls?.length ?? 0), 0)
|
|
53
|
+
return { answer: text.trim(), toolCalls }
|
|
54
|
+
})
|
|
55
|
+
.addEdge(START, 'react')
|
|
56
|
+
.addEdge('react', END)
|
|
57
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ask one question through DSH's native question UI, then report the answer.
|
|
3
|
+
*
|
|
4
|
+
* This is the human-in-the-loop path that needs no custom client: the node calls
|
|
5
|
+
* `helpers.askUser`, which runs the stock `ask_user_question` tool in this
|
|
6
|
+
* session, so the user sees the same question card as a model-asked question.
|
|
7
|
+
*/
|
|
8
|
+
export const id = 'ask-user'
|
|
9
|
+
export const description = 'Ask the user one question in the native question UI and return the answer.'
|
|
10
|
+
export const input = {
|
|
11
|
+
type: 'object',
|
|
12
|
+
properties: {
|
|
13
|
+
question: { type: 'string', description: 'The question to put to the user.' },
|
|
14
|
+
options: {
|
|
15
|
+
type: 'array',
|
|
16
|
+
items: { type: 'string' },
|
|
17
|
+
description: 'Optional answer labels; omit for a free-text answer.',
|
|
18
|
+
},
|
|
19
|
+
multiSelect: { type: 'boolean', description: 'Allow more than one option (default false).' },
|
|
20
|
+
},
|
|
21
|
+
required: ['question'],
|
|
22
|
+
additionalProperties: false,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function build({ StateGraph, Annotation, START, END, helpers }) {
|
|
26
|
+
const State = Annotation.Root({
|
|
27
|
+
question: Annotation({ reducer: (_left, right) => right, default: () => '' }),
|
|
28
|
+
options: Annotation({ reducer: (_left, right) => right, default: () => [] }),
|
|
29
|
+
multiSelect: Annotation({ reducer: (_left, right) => right, default: () => false }),
|
|
30
|
+
answer: Annotation({ reducer: (_left, right) => right, default: () => '' }),
|
|
31
|
+
selected: Annotation({ reducer: (_left, right) => right, default: () => [] }),
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
return new StateGraph(State)
|
|
35
|
+
.addNode('ask', async state => {
|
|
36
|
+
const options = Array.isArray(state.options) ? state.options.filter(option => typeof option === 'string') : []
|
|
37
|
+
const { answers } = await helpers.askUser([{
|
|
38
|
+
id: 'answer',
|
|
39
|
+
question: state.question,
|
|
40
|
+
...(options.length === 0 ? {} : { options }),
|
|
41
|
+
multi_select: state.multiSelect === true,
|
|
42
|
+
}])
|
|
43
|
+
const reply = answers.find(answer => answer.id === 'answer')
|
|
44
|
+
return {
|
|
45
|
+
answer: reply?.custom ?? reply?.selected?.join(', ') ?? '',
|
|
46
|
+
selected: reply?.selected ?? [],
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
.addEdge(START, 'ask')
|
|
50
|
+
.addEdge('ask', END)
|
|
51
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example workflow that mixes DSH tool calls with a model call inside one graph.
|
|
3
|
+
*
|
|
4
|
+
* `scan` reads the workspace through the DSH `glob` tool; `answer` asks the
|
|
5
|
+
* deployment's model to explain the result. The graph owns the control flow, DSH
|
|
6
|
+
* owns the tools and the model route.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** Graph id used by the `langgraph_run` tool. */
|
|
10
|
+
export const id = 'ask-workspace'
|
|
11
|
+
|
|
12
|
+
/** One-line description shown when the agent lists graphs. */
|
|
13
|
+
export const description = 'List files matching a glob, then have the model explain the result in one sentence.'
|
|
14
|
+
|
|
15
|
+
/** JSON Schema of the initial state, shown to the agent when it lists graphs. */
|
|
16
|
+
export const input = {
|
|
17
|
+
type: 'object',
|
|
18
|
+
properties: {
|
|
19
|
+
pattern: { type: 'string', description: 'Glob pattern to list; defaults to **/*.md.' },
|
|
20
|
+
},
|
|
21
|
+
additionalProperties: false,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Build the graph.
|
|
26
|
+
* @param {object} api - LangGraph API plus `helpers` bound to one run.
|
|
27
|
+
* @returns {object} a compiled LangGraph.
|
|
28
|
+
*/
|
|
29
|
+
export function build({ StateGraph, Annotation, START, END, helpers }) {
|
|
30
|
+
const State = Annotation.Root({
|
|
31
|
+
pattern: Annotation({ reducer: (_, next) => next, default: () => '**/*.md' }),
|
|
32
|
+
files: Annotation({ reducer: (_, next) => next, default: () => '' }),
|
|
33
|
+
explanation: Annotation({ reducer: (_, next) => next, default: () => '' }),
|
|
34
|
+
})
|
|
35
|
+
return new StateGraph(State)
|
|
36
|
+
.addNode('scan', async state => ({ files: await helpers.callTool('glob', { pattern: state.pattern }) }))
|
|
37
|
+
.addNode('answer', async state => {
|
|
38
|
+
const { text } = await helpers.callModel(
|
|
39
|
+
`Files matching ${state.pattern}:\n${state.files || '(none)'}\n\n`
|
|
40
|
+
+ 'In one sentence, say what this says about the project layout.',
|
|
41
|
+
{ system: 'You are explaining a repository layout to its owner. Be concrete and brief.' },
|
|
42
|
+
)
|
|
43
|
+
return { explanation: text }
|
|
44
|
+
})
|
|
45
|
+
.addEdge(START, 'scan')
|
|
46
|
+
.addEdge('scan', 'answer')
|
|
47
|
+
.addEdge('answer', END)
|
|
48
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example LangGraph workflow shipped with the plugin.
|
|
3
|
+
*
|
|
4
|
+
* It demonstrates the two things this plugin adds to LangGraph inside DSH:
|
|
5
|
+
* - a graph is registered by id and run from the agent's `langgraph_run` tool;
|
|
6
|
+
* - nodes call real DSH tools through `helpers.callTool`, in the calling agent's
|
|
7
|
+
* scope (same sandbox, same approvals, same session), so the graph is a
|
|
8
|
+
* coordinator of DSH work rather than a separate runtime.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Graph id used by the `langgraph_run` tool. */
|
|
12
|
+
export const id = 'scan-report'
|
|
13
|
+
|
|
14
|
+
/** One-line description shown when the agent lists graphs. */
|
|
15
|
+
export const description = 'Glob a pattern in the workspace, then report whether the match set is large.'
|
|
16
|
+
|
|
17
|
+
/** JSON Schema of the initial state, shown to the agent when it lists graphs. */
|
|
18
|
+
export const input = {
|
|
19
|
+
type: 'object',
|
|
20
|
+
properties: {
|
|
21
|
+
pattern: { type: 'string', description: 'Glob pattern to scan; defaults to **/*.js.' },
|
|
22
|
+
},
|
|
23
|
+
additionalProperties: false,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Build the graph.
|
|
28
|
+
* @param {object} api - LangGraph API plus `helpers` bound to one run.
|
|
29
|
+
* @returns {object} a compiled LangGraph.
|
|
30
|
+
*/
|
|
31
|
+
export function build({ StateGraph, Annotation, START, END, helpers }) {
|
|
32
|
+
const State = Annotation.Root({
|
|
33
|
+
pattern: Annotation({ reducer: (_, next) => next, default: () => '**/*.js' }),
|
|
34
|
+
matches: Annotation({ reducer: (_, next) => next, default: () => '' }),
|
|
35
|
+
count: Annotation({ reducer: (_, next) => next, default: () => 0 }),
|
|
36
|
+
verdict: Annotation({ reducer: (_, next) => next, default: () => '' }),
|
|
37
|
+
report: Annotation({ reducer: (_, next) => next, default: () => '' }),
|
|
38
|
+
})
|
|
39
|
+
return new StateGraph(State)
|
|
40
|
+
.addNode('scan', async state => {
|
|
41
|
+
const listing = await helpers.callTool('glob', { pattern: state.pattern })
|
|
42
|
+
const count = listing.split('\n').map(line => line.trim()).filter(Boolean).length
|
|
43
|
+
return { matches: listing, count }
|
|
44
|
+
})
|
|
45
|
+
.addNode('large', async state => ({ verdict: 'large', report: `${state.count} files match ${state.pattern}` }))
|
|
46
|
+
.addNode('small', async state => ({ verdict: 'small', report: `${state.count} files match ${state.pattern}` }))
|
|
47
|
+
.addEdge(START, 'scan')
|
|
48
|
+
.addConditionalEdges('scan', state => (state.count > 5 ? 'large' : 'small'))
|
|
49
|
+
.addEdge('large', END)
|
|
50
|
+
.addEdge('small', END)
|
|
51
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A TypeScript example graph.
|
|
3
|
+
*
|
|
4
|
+
* The plugin loads `.ts` graph modules directly on Node 24.22+ (type stripping),
|
|
5
|
+
* so this file needs no build step. Keep the syntax erasable: no enums,
|
|
6
|
+
* namespaces, parameter properties, or decorators.
|
|
7
|
+
*
|
|
8
|
+
* It is also the smallest end-to-end proof that a typed graph module can use
|
|
9
|
+
* `GraphApi` without importing the plugin at runtime: `import type` is erased.
|
|
10
|
+
*/
|
|
11
|
+
import type { GraphApi, GraphModule } from '../index.js'
|
|
12
|
+
|
|
13
|
+
/** Graph id used by the `langgraph_run` tool. */
|
|
14
|
+
export const id: string = 'typed-report'
|
|
15
|
+
|
|
16
|
+
/** One-line description shown when the agent lists graphs. */
|
|
17
|
+
export const description: string = 'TypeScript example: glob a pattern, then classify the match set.'
|
|
18
|
+
|
|
19
|
+
/** JSON Schema of the initial state, shown to the agent when it lists graphs. */
|
|
20
|
+
export const input = {
|
|
21
|
+
type: 'object',
|
|
22
|
+
properties: {
|
|
23
|
+
pattern: { type: 'string', description: 'Glob pattern to scan; defaults to **/*.js.' },
|
|
24
|
+
},
|
|
25
|
+
additionalProperties: false,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Build a small typed graph over `helpers.callTool`. */
|
|
29
|
+
export function build({ StateGraph, Annotation, START, END, helpers }: GraphApi): unknown {
|
|
30
|
+
const State = Annotation.Root({
|
|
31
|
+
pattern: Annotation({ reducer: (_previous: string, next: string) => next, default: () => '**/*.js' }),
|
|
32
|
+
files: Annotation({ reducer: (_previous: string, next: string) => next, default: () => '' }),
|
|
33
|
+
count: Annotation({ reducer: (_previous: number, next: number) => next, default: () => 0 }),
|
|
34
|
+
verdict: Annotation({ reducer: (_previous: string, next: string) => next, default: () => '' }),
|
|
35
|
+
})
|
|
36
|
+
return new StateGraph(State)
|
|
37
|
+
.addNode('scan', async (state: { pattern: string }) => {
|
|
38
|
+
const listing = await helpers.callTool('glob', { pattern: state.pattern })
|
|
39
|
+
const count = listing.split('\n').map(line => line.trim()).filter(Boolean).length
|
|
40
|
+
return { files: listing, count }
|
|
41
|
+
})
|
|
42
|
+
.addNode('large', async (state: { count: number; pattern: string }) => ({
|
|
43
|
+
verdict: 'large',
|
|
44
|
+
files: `${state.count} files match ${state.pattern}`,
|
|
45
|
+
}))
|
|
46
|
+
.addNode('small', async (state: { count: number; pattern: string }) => ({
|
|
47
|
+
verdict: 'small',
|
|
48
|
+
files: `${state.count} files match ${state.pattern}`,
|
|
49
|
+
}))
|
|
50
|
+
.addEdge(START, 'scan')
|
|
51
|
+
.addConditionalEdges('scan', (state: { count: number }) => (state.count > 5 ? 'large' : 'small'))
|
|
52
|
+
.addEdge('large', END)
|
|
53
|
+
.addEdge('small', END)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The module shape the plugin checks at load time. */
|
|
57
|
+
const module: GraphModule = { id, description, input, build }
|
|
58
|
+
export default module
|
package/icon.svg
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128" role="img" aria-label="LangGraph workflow">
|
|
2
|
+
<rect width="128" height="128" rx="28" fill="#0f172a"/>
|
|
3
|
+
<g stroke="#38bdf8" stroke-width="4" stroke-linecap="round" fill="none">
|
|
4
|
+
<path d="M34 40 L64 64 L34 88"/>
|
|
5
|
+
<path d="M64 64 L96 64"/>
|
|
6
|
+
</g>
|
|
7
|
+
<circle cx="34" cy="40" r="9" fill="#38bdf8"/>
|
|
8
|
+
<circle cx="34" cy="88" r="9" fill="#38bdf8"/>
|
|
9
|
+
<circle cx="64" cy="64" r="10" fill="#e2e8f0"/>
|
|
10
|
+
<circle cx="98" cy="64" r="9" fill="#38bdf8"/>
|
|
11
|
+
</svg>
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type declarations for `dsh-langgraph` graph modules.
|
|
3
|
+
*
|
|
4
|
+
* A graph module can be written in TypeScript and type-checked without importing
|
|
5
|
+
* the plugin at runtime:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import type { GraphApi, GraphModule } from '@lzn1998/dsh-langgraph'
|
|
9
|
+
* export const id = 'report'
|
|
10
|
+
* export const input = { type: 'object' }
|
|
11
|
+
* export function build({ StateGraph, Annotation, START, END, helpers }: GraphApi) { ... }
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
import { Annotation, END, START, StateGraph, getStore, interrupt } from '@langchain/langgraph'
|
|
15
|
+
import type { BaseCheckpointSaver, BaseStore } from '@langchain/langgraph-checkpoint'
|
|
16
|
+
import type { BaseChatModel } from '@langchain/core/language_models/chat_models'
|
|
17
|
+
|
|
18
|
+
/** Route options accepted by the model bridges. */
|
|
19
|
+
export interface ModelRouteOptions {
|
|
20
|
+
provider?: string
|
|
21
|
+
model?: string
|
|
22
|
+
reasoningEffort?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Options for one text-only model call. */
|
|
26
|
+
export interface CallModelOptions extends ModelRouteOptions {
|
|
27
|
+
system?: string
|
|
28
|
+
temperature?: number
|
|
29
|
+
maxTokens?: number
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Options for one DSH subagent delegation. */
|
|
33
|
+
export interface SubagentOptions {
|
|
34
|
+
/** Registered subagent provider; defaults to `spawn`. */
|
|
35
|
+
provider?: string
|
|
36
|
+
/** Display label for the child. */
|
|
37
|
+
label?: string
|
|
38
|
+
/** Unique child name; omitted assigns `agent-N`. */
|
|
39
|
+
name?: string
|
|
40
|
+
/** Initial child directory; relative paths resolve against the parent's cwd. */
|
|
41
|
+
cwd?: string
|
|
42
|
+
/** Independent agent preset; only local providers support this. */
|
|
43
|
+
agentPreset?: string
|
|
44
|
+
/** Child model/provider overrides. */
|
|
45
|
+
agentOptions?: Record<string, unknown>
|
|
46
|
+
/** Object-rooted JSON Schema for the child's structured result. */
|
|
47
|
+
schema?: Record<string, unknown>
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** One selectable answer offered to the user. */
|
|
51
|
+
export interface AskUserOption {
|
|
52
|
+
label: string
|
|
53
|
+
description?: string
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** One question for the native DSH question UI. */
|
|
57
|
+
export interface AskUserQuestion {
|
|
58
|
+
/** Stable id, echoed in the answer; defaults to `q1`, `q2`, … */
|
|
59
|
+
id?: string
|
|
60
|
+
question: string
|
|
61
|
+
header?: string
|
|
62
|
+
options?: Array<string | AskUserOption>
|
|
63
|
+
multi_select?: boolean
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The user's answer to one question; empty `selected` with no `custom` means skip. */
|
|
67
|
+
export interface AskUserAnswer {
|
|
68
|
+
id: string
|
|
69
|
+
selected: string[]
|
|
70
|
+
custom?: string
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The result of one `askUser` call. */
|
|
74
|
+
export interface AskUserResult {
|
|
75
|
+
answers: AskUserAnswer[]
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The result of one DSH subagent delegation. */
|
|
79
|
+
export interface SubagentResult {
|
|
80
|
+
/** Concatenated text blocks of the child's final output. */
|
|
81
|
+
text: string
|
|
82
|
+
/** The child's final content blocks, including any images. */
|
|
83
|
+
output: unknown[]
|
|
84
|
+
/** The validated structured result when `schema` was supplied. */
|
|
85
|
+
structured?: unknown
|
|
86
|
+
/** `completed` or the provider's failure stop reason. */
|
|
87
|
+
stopReason: string
|
|
88
|
+
/** The child's model-facing name. */
|
|
89
|
+
name: string
|
|
90
|
+
/** The child's Session id. */
|
|
91
|
+
childId: string
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The helpers bound to one run. */
|
|
95
|
+
export interface GraphHelpers {
|
|
96
|
+
/** The calling DSH agent, when the tool was invoked by an agent. */
|
|
97
|
+
readonly agent: unknown
|
|
98
|
+
/** The calling session id, when known. */
|
|
99
|
+
readonly sessionId: string | undefined
|
|
100
|
+
/** LangChain message classes, re-exported so a graph needs no LangChain dependency. */
|
|
101
|
+
readonly messages: {
|
|
102
|
+
AIMessage: unknown
|
|
103
|
+
HumanMessage: unknown
|
|
104
|
+
SystemMessage: unknown
|
|
105
|
+
ToolMessage: unknown
|
|
106
|
+
}
|
|
107
|
+
/** A LangChain chat model over this deployment's model route. */
|
|
108
|
+
chatModel(options?: ModelRouteOptions): BaseChatModel
|
|
109
|
+
/** Wrap visible DSH tools as LangChain tools. */
|
|
110
|
+
tools(names: string[]): unknown[]
|
|
111
|
+
/** LangGraph's prebuilt ReAct agent over DSH tools and the DSH model. */
|
|
112
|
+
createReactAgent(options?: Record<string, unknown>): Promise<unknown>
|
|
113
|
+
/** One text completion on this deployment's model route. */
|
|
114
|
+
callModel(prompt: string, options?: CallModelOptions): Promise<{ text: string; usage?: unknown }>
|
|
115
|
+
/** Run one DSH tool in the calling agent's scope and return its text content. */
|
|
116
|
+
callTool(name: string, args?: Record<string, unknown>): Promise<string>
|
|
117
|
+
/** Ask the user through DSH's native question UI and wait for the answers. */
|
|
118
|
+
askUser(questions: AskUserQuestion[]): Promise<AskUserResult>
|
|
119
|
+
/** Delegate one task to a DSH subagent and await its final output. */
|
|
120
|
+
subagent(prompt: string, options?: SubagentOptions): Promise<SubagentResult>
|
|
121
|
+
/** The run's LangGraph long-term store; undefined when `config.store` is false. */
|
|
122
|
+
store(): BaseStore | undefined
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** The API object passed to a graph module's `build(api)`. */
|
|
126
|
+
export interface GraphApi {
|
|
127
|
+
readonly StateGraph: typeof StateGraph
|
|
128
|
+
readonly Annotation: typeof Annotation
|
|
129
|
+
readonly START: typeof START
|
|
130
|
+
readonly END: typeof END
|
|
131
|
+
readonly interrupt: typeof interrupt
|
|
132
|
+
/** LangGraph's config-scoped store accessor; nodes use `getStore(config)`. */
|
|
133
|
+
readonly getStore: typeof getStore
|
|
134
|
+
readonly helpers: GraphHelpers
|
|
135
|
+
/** The durable checkpointer the plugin compiles the graph with. */
|
|
136
|
+
readonly checkpointer: BaseCheckpointSaver
|
|
137
|
+
/** The run's long-term store; undefined when `config.store` is false. */
|
|
138
|
+
readonly store: BaseStore | undefined
|
|
139
|
+
readonly [key: string]: unknown
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** The module shape the plugin discovers. */
|
|
143
|
+
export interface GraphModule {
|
|
144
|
+
/** Stable graph id used by the `langgraph_run` tool. */
|
|
145
|
+
readonly id: string
|
|
146
|
+
/** One-line description shown when the agent lists graphs. */
|
|
147
|
+
readonly description?: string
|
|
148
|
+
/** JSON Schema of the initial state, shown to the agent. */
|
|
149
|
+
readonly input?: Record<string, unknown>
|
|
150
|
+
/** Return an uncompiled StateGraph (preferred) or a compiled graph. */
|
|
151
|
+
build(api: GraphApi): unknown | Promise<unknown>
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Identity helper for a typed graph module. */
|
|
155
|
+
export function defineGraph<T extends GraphModule>(module: T): T
|