@langchain/macaw-components 1.7.18 → 1.7.20
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/dist/catalog.json +798 -775
- package/dist/components/Banner/Banner.js +1 -1
- package/dist/components/Banner/Banner.js.map +1 -1
- package/dist/components/ChatPlan/ChatPlan.js +1 -1
- package/dist/components/ChatPlan/ChatPlan.js.map +1 -1
- package/dist/components/ChatThread/ChatThread.d.ts +59 -0
- package/dist/components/ChatThread/ChatThread.js +338 -0
- package/dist/components/ChatThread/ChatThread.js.map +1 -0
- package/dist/components/ChatThread/ChatThread.types.d.ts +284 -0
- package/dist/components/ChatThread/ChatThread.types.js +0 -0
- package/dist/components/ChatThread/ChatThreadContext.d.ts +34 -0
- package/dist/components/ChatThread/ChatThreadContext.js +53 -0
- package/dist/components/ChatThread/ChatThreadContext.js.map +1 -0
- package/dist/components/ChatThread/ChatThreadRequests.d.ts +1 -0
- package/dist/components/ChatThread/ChatThreadRequests.js +233 -0
- package/dist/components/ChatThread/ChatThreadRequests.js.map +1 -0
- package/dist/components/ChatThread/ChatThreadWork.d.ts +13 -0
- package/dist/components/ChatThread/ChatThreadWork.js +174 -0
- package/dist/components/ChatThread/ChatThreadWork.js.map +1 -0
- package/dist/components/ChatThread/deepAgentTools.d.ts +9 -0
- package/dist/components/ChatThread/deepAgentTools.js +215 -0
- package/dist/components/ChatThread/deepAgentTools.js.map +1 -0
- package/dist/components/ChatThread/index.d.ts +8 -0
- package/dist/components/ChatThread/index.js +6 -0
- package/dist/components/ChatThread/interrupts.d.ts +43 -0
- package/dist/components/ChatThread/interrupts.js +96 -0
- package/dist/components/ChatThread/interrupts.js.map +1 -0
- package/dist/components/ChatThread/messages.d.ts +29 -0
- package/dist/components/ChatThread/messages.js +137 -0
- package/dist/components/ChatThread/messages.js.map +1 -0
- package/dist/components/ChatThread/toChatThread.d.ts +12 -0
- package/dist/components/ChatThread/toChatThread.js +275 -0
- package/dist/components/ChatThread/toChatThread.js.map +1 -0
- package/dist/components/ChatThread/useLangGraphChatThread.d.ts +36 -0
- package/dist/components/ChatThread/useLangGraphChatThread.js +240 -0
- package/dist/components/ChatThread/useLangGraphChatThread.js.map +1 -0
- package/dist/components/ChatToolCall/ChatToolCallAccordion.js +1 -1
- package/dist/components/ChatToolCall/ChatToolCallAccordion.js.map +1 -1
- package/dist/components/ChatToolCall/ChatToolCallDetails.js +1 -1
- package/dist/components/ChatToolCall/ChatToolCallGroup.js +1 -1
- package/dist/components/ChatToolCall/ChatToolCallGroup.js.map +1 -1
- package/dist/components/MarkdownDisplay/MarkdownDisplay.js +1 -1
- package/dist/docs/phosphor-icon-catalog.js +2 -2
- package/dist/icons/LongTailPhosphorIcons.js +1 -1
- package/dist/utilities.css +1 -1
- package/docs/CHAT.md +109 -3
- package/docs/DESIGN.md +4 -1
- package/package.json +6 -2
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { Text } from "../Text/Text.js";
|
|
2
|
+
import { IconButton } from "../IconButton/IconButton.js";
|
|
3
|
+
import { formatChatDuration } from "../ChatState/formatChatDuration.js";
|
|
4
|
+
import { MarkdownDisplay } from "../MarkdownDisplay/MarkdownDisplay.js";
|
|
5
|
+
import { plainText, present, useThread } from "./ChatThreadContext.js";
|
|
6
|
+
import { ChatToolCall } from "../ChatToolCall/ChatToolCall.js";
|
|
7
|
+
import { ChatToolCallGroup } from "../ChatToolCall/ChatToolCallGroup.js";
|
|
8
|
+
import { ChatToolCallReasoning } from "../ChatToolCall/ChatToolCallReasoning.js";
|
|
9
|
+
import { describeToolCall } from "./deepAgentTools.js";
|
|
10
|
+
import { useState } from "react";
|
|
11
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
import { ArrowSquareOutIcon } from "@phosphor-icons/react/dist/ssr/ArrowSquareOut";
|
|
13
|
+
import { RobotIcon } from "@phosphor-icons/react/dist/ssr/Robot";
|
|
14
|
+
//#region packages/components/src/components/ChatThread/ChatThreadWork.tsx
|
|
15
|
+
function ToolCallPart({ toolCall, source }) {
|
|
16
|
+
const { tools } = useThread();
|
|
17
|
+
const presentation = present(tools, toolCall, source);
|
|
18
|
+
if (presentation.kind === "hidden") return null;
|
|
19
|
+
if (presentation.kind === "element") return presentation.element;
|
|
20
|
+
return /* @__PURE__ */ jsx(ChatToolCall, {
|
|
21
|
+
toolCall,
|
|
22
|
+
...presentation.props
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function SubagentTranscript({ handle, running }) {
|
|
26
|
+
const { thread, tools } = useThread();
|
|
27
|
+
const parts = thread.useSubagentTranscript ? thread.useSubagentTranscript(handle, running) : [];
|
|
28
|
+
if (parts.length === 0) return /* @__PURE__ */ jsx(Text, {
|
|
29
|
+
variant: "xs",
|
|
30
|
+
color: "tertiary",
|
|
31
|
+
children: running ? "Starting…" : "No activity recorded."
|
|
32
|
+
});
|
|
33
|
+
return /* @__PURE__ */ jsx("div", {
|
|
34
|
+
className: "flex min-w-0 flex-col gap-0.5",
|
|
35
|
+
children: parts.map((part) => part.type === "tool-call" ? /* @__PURE__ */ jsx(ToolCallPart, {
|
|
36
|
+
toolCall: part.toolCall,
|
|
37
|
+
source: part.source
|
|
38
|
+
}, part.id) : part.type === "text" ? /* @__PURE__ */ jsx(MarkdownDisplay, {
|
|
39
|
+
content: part.text,
|
|
40
|
+
isStreaming: part.streaming,
|
|
41
|
+
textColor: "secondary",
|
|
42
|
+
className: "py-space-1 text-xs"
|
|
43
|
+
}, part.id) : part.type === "subagent" ? /* @__PURE__ */ jsx(Text, {
|
|
44
|
+
variant: "xs",
|
|
45
|
+
color: "secondary",
|
|
46
|
+
children: describeToolCall("task", { description: part.subagent.task }, tools)
|
|
47
|
+
}, part.id) : null)
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
var SUBAGENT_ICON = /* @__PURE__ */ jsx(RobotIcon, {
|
|
51
|
+
size: 12,
|
|
52
|
+
weight: "regular"
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* A subagent run as a tool row named for the subagent. It shows the current
|
|
56
|
+
* step while it runs, and its own transcript in the details.
|
|
57
|
+
*/
|
|
58
|
+
function SubagentPart({ part }) {
|
|
59
|
+
const { thread, tools, onOpenSubagent } = useThread();
|
|
60
|
+
const { subagent } = part;
|
|
61
|
+
const running = subagent.status === "running";
|
|
62
|
+
const step = thread.useSubagentStep ? thread.useSubagentStep(running ? part.handle : void 0) : void 0;
|
|
63
|
+
const activity = running && step ? describeToolCall(step.name, step.args, tools) : void 0;
|
|
64
|
+
const result = part.result ? plainText(part.result) : void 0;
|
|
65
|
+
const canExpand = Boolean(thread.useSubagentTranscript && part.handle);
|
|
66
|
+
return /* @__PURE__ */ jsx(ChatToolCall, {
|
|
67
|
+
toolCall: {
|
|
68
|
+
id: subagent.id,
|
|
69
|
+
name: "task",
|
|
70
|
+
status: subagent.status,
|
|
71
|
+
args: subagent.task ? { description: subagent.task } : void 0,
|
|
72
|
+
result,
|
|
73
|
+
elapsedMs: subagent.elapsedMs
|
|
74
|
+
},
|
|
75
|
+
label: subagent.name,
|
|
76
|
+
icon: SUBAGENT_ICON,
|
|
77
|
+
summary: running && activity || subagent.task || null,
|
|
78
|
+
meta: onOpenSubagent ? /* @__PURE__ */ jsx(IconButton, {
|
|
79
|
+
type: "button",
|
|
80
|
+
icon: ArrowSquareOutIcon,
|
|
81
|
+
iconWeight: "regular",
|
|
82
|
+
size: "xs",
|
|
83
|
+
variant: "plain",
|
|
84
|
+
color: "secondary",
|
|
85
|
+
label: `Open ${subagent.name}`,
|
|
86
|
+
onClick: () => onOpenSubagent(subagent)
|
|
87
|
+
}) : void 0,
|
|
88
|
+
children: canExpand ? /* @__PURE__ */ jsxs("div", {
|
|
89
|
+
className: "flex min-w-0 flex-col gap-space-1",
|
|
90
|
+
children: [/* @__PURE__ */ jsx(SubagentTranscript, {
|
|
91
|
+
handle: part.handle,
|
|
92
|
+
running
|
|
93
|
+
}), result && /* @__PURE__ */ jsx(Text, {
|
|
94
|
+
variant: "xs",
|
|
95
|
+
color: "secondary",
|
|
96
|
+
className: "line-clamp-3",
|
|
97
|
+
children: result
|
|
98
|
+
})]
|
|
99
|
+
}) : void 0
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function WorkParts({ parts }) {
|
|
103
|
+
const nodes = [];
|
|
104
|
+
for (let index = 0; index < parts.length; index += 1) {
|
|
105
|
+
const part = parts[index];
|
|
106
|
+
if (part.type === "subagent") nodes.push(/* @__PURE__ */ jsx(SubagentPart, { part }, part.id));
|
|
107
|
+
else if (part.type === "tool-call") nodes.push(/* @__PURE__ */ jsx(ToolCallPart, {
|
|
108
|
+
toolCall: part.toolCall,
|
|
109
|
+
source: part.source
|
|
110
|
+
}, part.id));
|
|
111
|
+
else if (part.type === "reasoning") nodes.push(/* @__PURE__ */ jsx(ChatToolCallReasoning, {
|
|
112
|
+
status: part.streaming ? "streaming" : "completed",
|
|
113
|
+
label: part.streaming ? "Thinking" : "Thought process",
|
|
114
|
+
expandWhileStreaming: true,
|
|
115
|
+
children: /* @__PURE__ */ jsx(MarkdownDisplay, {
|
|
116
|
+
content: part.text,
|
|
117
|
+
isStreaming: part.streaming,
|
|
118
|
+
textColor: "tertiary",
|
|
119
|
+
className: "text-xs"
|
|
120
|
+
})
|
|
121
|
+
}, part.id));
|
|
122
|
+
else if (part.type === "text") nodes.push(/* @__PURE__ */ jsx(MarkdownDisplay, {
|
|
123
|
+
content: part.text,
|
|
124
|
+
isStreaming: part.streaming,
|
|
125
|
+
textColor: "secondary",
|
|
126
|
+
className: "px-space-1 py-space-1 text-xs"
|
|
127
|
+
}, part.id));
|
|
128
|
+
else if (part.type === "image") nodes.push(/* @__PURE__ */ jsx(ImagePart, { url: part.url }, part.id));
|
|
129
|
+
}
|
|
130
|
+
return /* @__PURE__ */ jsx(Fragment$1, { children: nodes });
|
|
131
|
+
}
|
|
132
|
+
function ImagePart({ url }) {
|
|
133
|
+
if (!url.startsWith("data:image/")) {
|
|
134
|
+
if (!/^https?:\/\//i.test(url)) return null;
|
|
135
|
+
return /* @__PURE__ */ jsx("a", {
|
|
136
|
+
href: url,
|
|
137
|
+
target: "_blank",
|
|
138
|
+
rel: "noreferrer",
|
|
139
|
+
className: "text-xs text-brand-primary underline",
|
|
140
|
+
children: "Open image"
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return /* @__PURE__ */ jsx("img", {
|
|
144
|
+
src: url,
|
|
145
|
+
alt: "Image from the agent",
|
|
146
|
+
className: "max-h-80 w-auto max-w-full rounded-lg border border-subtle"
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
function visibleActionCount(parts, tools) {
|
|
150
|
+
return parts.filter((part) => part.type === "subagent" || part.type === "tool-call" && present(tools, part.toolCall, part.source).kind !== "hidden").length;
|
|
151
|
+
}
|
|
152
|
+
function WorkSummary({ turn, parts, count }) {
|
|
153
|
+
const { thread } = useThread();
|
|
154
|
+
const timing = thread.timings?.[turn.id];
|
|
155
|
+
const working = turn.status === "streaming";
|
|
156
|
+
const waiting = turn.status === "interrupted";
|
|
157
|
+
const [readerChoice, setReaderChoice] = useState();
|
|
158
|
+
const actions = `${count} ${count === 1 ? "action" : "actions"}`;
|
|
159
|
+
const duration = timing?.endedAt !== void 0 ? formatChatDuration(timing.endedAt - timing.startedAt) : void 0;
|
|
160
|
+
const label = working ? "Working" : waiting ? `Waiting for you · ${actions}` : turn.status === "failed" ? `Stopped · ${actions}` : duration ? `Worked for ${duration} · ${actions}` : actions;
|
|
161
|
+
return /* @__PURE__ */ jsx(ChatToolCallGroup, {
|
|
162
|
+
label,
|
|
163
|
+
expanded: readerChoice ?? (working || waiting),
|
|
164
|
+
onExpandedChange: setReaderChoice,
|
|
165
|
+
running: working,
|
|
166
|
+
showElapsed: working,
|
|
167
|
+
startedAt: working ? timing?.startedAt : void 0,
|
|
168
|
+
children: /* @__PURE__ */ jsx(WorkParts, { parts })
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
//#endregion
|
|
172
|
+
export { ImagePart, WorkParts, WorkSummary, visibleActionCount };
|
|
173
|
+
|
|
174
|
+
//# sourceMappingURL=ChatThreadWork.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatThreadWork.js","names":[],"sources":["../../../src/components/ChatThread/ChatThreadWork.tsx"],"sourcesContent":["import { type ReactNode, useState } from 'react';\n\nimport { ArrowSquareOutIcon } from '@phosphor-icons/react/dist/ssr/ArrowSquareOut';\nimport { RobotIcon } from '@phosphor-icons/react/dist/ssr/Robot';\n\nimport { formatChatDuration } from '../ChatState';\nimport {\n ChatToolCall,\n ChatToolCallGroup,\n ChatToolCallReasoning,\n type ChatToolCallModel,\n} from '../ChatToolCall';\nimport { IconButton } from '../IconButton';\nimport { MarkdownDisplay } from '../MarkdownDisplay';\nimport { Text } from '../Text';\nimport type {\n ChatThreadPart,\n ChatThreadPartSource,\n ChatThreadToolRenderer,\n ChatThreadTurn,\n} from './ChatThread.types';\nimport { plainText, present, useThread } from './ChatThreadContext';\nimport { describeToolCall } from './deepAgentTools';\n\nfunction ToolCallPart({\n toolCall,\n source,\n}: {\n toolCall: ChatToolCallModel;\n source?: ChatThreadPartSource;\n}) {\n const { tools } = useThread();\n const presentation = present(tools, toolCall, source);\n if (presentation.kind === 'hidden') return null;\n if (presentation.kind === 'element') return presentation.element;\n return <ChatToolCall toolCall={toolCall} {...presentation.props} />;\n}\n\nfunction SubagentTranscript({\n handle,\n running,\n}: {\n handle: unknown;\n running: boolean;\n}) {\n const { thread, tools } = useThread();\n // Only rendered when the controller has the hook.\n const parts = thread.useSubagentTranscript\n ? thread.useSubagentTranscript(handle, running)\n : [];\n if (parts.length === 0) {\n return (\n <Text variant=\"xs\" color=\"tertiary\">\n {running ? 'Starting…' : 'No activity recorded.'}\n </Text>\n );\n }\n return (\n <div className=\"flex min-w-0 flex-col gap-0.5\">\n {parts.map((part) =>\n part.type === 'tool-call' ? (\n <ToolCallPart\n key={part.id}\n toolCall={part.toolCall}\n source={part.source}\n />\n ) : part.type === 'text' ? (\n <MarkdownDisplay\n key={part.id}\n content={part.text}\n isStreaming={part.streaming}\n textColor=\"secondary\"\n className=\"py-space-1 text-xs\"\n />\n ) : part.type === 'subagent' ? (\n <Text key={part.id} variant=\"xs\" color=\"secondary\">\n {describeToolCall(\n 'task',\n { description: part.subagent.task },\n tools\n )}\n </Text>\n ) : null\n )}\n </div>\n );\n}\n\nconst SUBAGENT_ICON = <RobotIcon size={12} weight=\"regular\" />;\n\n/**\n * A subagent run as a tool row named for the subagent. It shows the current\n * step while it runs, and its own transcript in the details.\n */\nfunction SubagentPart({\n part,\n}: {\n part: Extract<ChatThreadPart, { type: 'subagent' }>;\n}) {\n const { thread, tools, onOpenSubagent } = useThread();\n const { subagent } = part;\n const running = subagent.status === 'running';\n // While running, follow the subagent's own tool calls for its current step.\n const step = thread.useSubagentStep\n ? thread.useSubagentStep(running ? part.handle : undefined)\n : undefined;\n const activity =\n running && step ? describeToolCall(step.name, step.args, tools) : undefined;\n const result = part.result ? plainText(part.result) : undefined;\n const canExpand = Boolean(thread.useSubagentTranscript && part.handle);\n return (\n <ChatToolCall\n toolCall={{\n id: subagent.id,\n name: 'task',\n status: subagent.status,\n args: subagent.task ? { description: subagent.task } : undefined,\n result,\n elapsedMs: subagent.elapsedMs,\n }}\n label={subagent.name}\n icon={SUBAGENT_ICON}\n summary={(running && activity) || subagent.task || null}\n meta={\n onOpenSubagent ? (\n <IconButton\n type=\"button\"\n icon={ArrowSquareOutIcon}\n iconWeight=\"regular\"\n size=\"xs\"\n variant=\"plain\"\n color=\"secondary\"\n label={`Open ${subagent.name}`}\n onClick={() => onOpenSubagent(subagent)}\n />\n ) : undefined\n }\n >\n {canExpand ? (\n <div className=\"flex min-w-0 flex-col gap-space-1\">\n <SubagentTranscript handle={part.handle} running={running} />\n {result && (\n <Text variant=\"xs\" color=\"secondary\" className=\"line-clamp-3\">\n {result}\n </Text>\n )}\n </div>\n ) : undefined}\n </ChatToolCall>\n );\n}\n\nexport function WorkParts({ parts }: { parts: ChatThreadPart[] }) {\n const nodes: ReactNode[] = [];\n for (let index = 0; index < parts.length; index += 1) {\n const part = parts[index];\n if (part.type === 'subagent') {\n nodes.push(<SubagentPart key={part.id} part={part} />);\n } else if (part.type === 'tool-call') {\n nodes.push(\n <ToolCallPart\n key={part.id}\n toolCall={part.toolCall}\n source={part.source}\n />\n );\n } else if (part.type === 'reasoning') {\n nodes.push(\n <ChatToolCallReasoning\n key={part.id}\n status={part.streaming ? 'streaming' : 'completed'}\n label={part.streaming ? 'Thinking' : 'Thought process'}\n expandWhileStreaming\n >\n <MarkdownDisplay\n content={part.text}\n isStreaming={part.streaming}\n textColor=\"tertiary\"\n className=\"text-xs\"\n />\n </ChatToolCallReasoning>\n );\n } else if (part.type === 'text') {\n // Narration between steps, such as \"Checking the tests next.\"\n nodes.push(\n <MarkdownDisplay\n key={part.id}\n content={part.text}\n isStreaming={part.streaming}\n textColor=\"secondary\"\n className=\"px-space-1 py-space-1 text-xs\"\n />\n );\n } else if (part.type === 'image') {\n nodes.push(<ImagePart key={part.id} url={part.url} />);\n }\n }\n return <>{nodes}</>;\n}\n\nexport function ImagePart({ url }: { url: string }) {\n // Generated images arrive inline; remote URLs stay links so they aren't\n // fetched without the reader's action. Other schemes come from model\n // output and aren't safe to link.\n if (!url.startsWith('data:image/')) {\n if (!/^https?:\\/\\//i.test(url)) return null;\n return (\n <a\n href={url}\n target=\"_blank\"\n rel=\"noreferrer\"\n className=\"text-xs text-brand-primary underline\"\n >\n Open image\n </a>\n );\n }\n return (\n <img\n src={url}\n alt=\"Image from the agent\"\n className=\"max-h-80 w-auto max-w-full rounded-lg border border-subtle\"\n />\n );\n}\n\nexport function visibleActionCount(\n parts: ChatThreadPart[],\n tools: Record<string, ChatThreadToolRenderer>\n) {\n return parts.filter(\n (part) =>\n part.type === 'subagent' ||\n (part.type === 'tool-call' &&\n present(tools, part.toolCall, part.source).kind !== 'hidden')\n ).length;\n}\n\nexport function WorkSummary({\n turn,\n parts,\n count,\n}: {\n turn: ChatThreadTurn;\n parts: ChatThreadPart[];\n count: number;\n}) {\n const { thread } = useThread();\n const timing = thread.timings?.[turn.id];\n const working = turn.status === 'streaming';\n const waiting = turn.status === 'interrupted';\n const [readerChoice, setReaderChoice] = useState<boolean>();\n const actions = `${count} ${count === 1 ? 'action' : 'actions'}`;\n const duration =\n timing?.endedAt !== undefined\n ? formatChatDuration(timing.endedAt - timing.startedAt)\n : undefined;\n const label = working\n ? 'Working'\n : waiting\n ? `Waiting for you · ${actions}`\n : turn.status === 'failed'\n ? `Stopped · ${actions}`\n : duration\n ? `Worked for ${duration} · ${actions}`\n : actions;\n\n return (\n <ChatToolCallGroup\n label={label}\n // Open while the agent works or waits, so progress stays in view;\n // closed once it's done, unless the reader chose otherwise.\n expanded={readerChoice ?? (working || waiting)}\n onExpandedChange={setReaderChoice}\n // Keeps the header working while the agent decides its next call.\n running={working}\n showElapsed={working}\n startedAt={working ? timing?.startedAt : undefined}\n >\n <WorkParts parts={parts} />\n </ChatToolCallGroup>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAwBA,SAAS,aAAa,EACpB,UACA,UAIC;CACD,MAAM,EAAE,UAAU,UAAU;CAC5B,MAAM,eAAe,QAAQ,OAAO,UAAU,MAAM;CACpD,IAAI,aAAa,SAAS,UAAU,OAAO;CAC3C,IAAI,aAAa,SAAS,WAAW,OAAO,aAAa;CACzD,OAAO,oBAAC,cAAD;EAAwB;EAAU,GAAI,aAAa;CAAQ,CAAA;AACpE;AAEA,SAAS,mBAAmB,EAC1B,QACA,WAIC;CACD,MAAM,EAAE,QAAQ,UAAU,UAAU;CAEpC,MAAM,QAAQ,OAAO,wBACjB,OAAO,sBAAsB,QAAQ,OAAO,IAC5C,CAAC;CACL,IAAI,MAAM,WAAW,GACnB,OACE,oBAAC,MAAD;EAAM,SAAQ;EAAK,OAAM;EACtB,UAAA,UAAU,cAAc;CACrB,CAAA;CAGV,OACE,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
|
+
/**
|
|
3
|
+
* Presentations for the built-in tools of LangChain deep agents: the virtual
|
|
4
|
+
* filesystem, shell execution, and planning. `ChatThread` uses them by
|
|
5
|
+
* default; pass `tools` to add or override presentations.
|
|
6
|
+
*/
|
|
7
|
+
export declare const deepAgentTools: Record<string, ChatThreadToolRenderer>;
|
|
8
|
+
/** One line naming a tool call, such as "Search · retrieval", for live status. */
|
|
9
|
+
export declare function describeToolCall(name: string, input: unknown, tools: Record<string, ChatThreadToolRenderer>): string;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { Text } from "../Text/Text.js";
|
|
2
|
+
import { ChatPlan } from "../ChatPlan/ChatPlan.js";
|
|
3
|
+
import { CodeLite } from "../Code/CodeLite.js";
|
|
4
|
+
import { isRecord } from "./messages.js";
|
|
5
|
+
import { planItems } from "./toChatThread.js";
|
|
6
|
+
import { isValidElement } from "react";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { MagnifyingGlassIcon } from "@phosphor-icons/react/dist/ssr/MagnifyingGlass";
|
|
9
|
+
import { PencilSimpleIcon } from "@phosphor-icons/react/dist/ssr/PencilSimple";
|
|
10
|
+
import { FilePlusIcon } from "@phosphor-icons/react/dist/ssr/FilePlus";
|
|
11
|
+
import { FileTextIcon } from "@phosphor-icons/react/dist/ssr/FileText";
|
|
12
|
+
import { FolderOpenIcon } from "@phosphor-icons/react/dist/ssr/FolderOpen";
|
|
13
|
+
import { ListChecksIcon } from "@phosphor-icons/react/dist/ssr/ListChecks";
|
|
14
|
+
import { TerminalIcon } from "@phosphor-icons/react/dist/ssr/Terminal";
|
|
15
|
+
//#region packages/components/src/components/ChatThread/deepAgentTools.tsx
|
|
16
|
+
function args(value) {
|
|
17
|
+
return isRecord(value) ? value : {};
|
|
18
|
+
}
|
|
19
|
+
function text(value) {
|
|
20
|
+
return typeof value === "string" && value ? value : void 0;
|
|
21
|
+
}
|
|
22
|
+
function splitLines(value) {
|
|
23
|
+
const lines = value.split("\n");
|
|
24
|
+
if (lines.at(-1) === "") lines.pop();
|
|
25
|
+
return lines;
|
|
26
|
+
}
|
|
27
|
+
function lines(value) {
|
|
28
|
+
return value ? splitLines(value).length : 0;
|
|
29
|
+
}
|
|
30
|
+
/** Bounds the line diff so a huge edit can't stall rendering. */
|
|
31
|
+
var MAX_DIFF_LINES = 2e3;
|
|
32
|
+
/** Lines added and removed, from the longest common subsequence of lines. */
|
|
33
|
+
function lineChanges(before, after) {
|
|
34
|
+
const a = splitLines(before);
|
|
35
|
+
const b = splitLines(after);
|
|
36
|
+
if (a.length * b.length > MAX_DIFF_LINES * MAX_DIFF_LINES) return {
|
|
37
|
+
added: b.length,
|
|
38
|
+
removed: a.length
|
|
39
|
+
};
|
|
40
|
+
let previous = Array.from({ length: b.length + 1 }, () => 0);
|
|
41
|
+
for (let i = 1; i <= a.length; i += 1) {
|
|
42
|
+
const current = Array.from({ length: b.length + 1 }, () => 0);
|
|
43
|
+
for (let j = 1; j <= b.length; j += 1) current[j] = a[i - 1] === b[j - 1] ? previous[j - 1] + 1 : Math.max(previous[j], current[j - 1]);
|
|
44
|
+
previous = current;
|
|
45
|
+
}
|
|
46
|
+
const common = previous[b.length];
|
|
47
|
+
return {
|
|
48
|
+
added: b.length - common,
|
|
49
|
+
removed: a.length - common
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
var changesByArgs = /* @__PURE__ */ new WeakMap();
|
|
53
|
+
function cachedLineChanges(input, before, after) {
|
|
54
|
+
let changes = changesByArgs.get(input);
|
|
55
|
+
if (!changes) {
|
|
56
|
+
changes = lineChanges(before, after);
|
|
57
|
+
changesByArgs.set(input, changes);
|
|
58
|
+
}
|
|
59
|
+
return changes;
|
|
60
|
+
}
|
|
61
|
+
var EXTENSION_LANGUAGES = {
|
|
62
|
+
ts: "typescript",
|
|
63
|
+
tsx: "typescript",
|
|
64
|
+
js: "typescript",
|
|
65
|
+
jsx: "typescript",
|
|
66
|
+
mjs: "typescript",
|
|
67
|
+
cjs: "typescript",
|
|
68
|
+
py: "python",
|
|
69
|
+
sh: "shell",
|
|
70
|
+
bash: "shell",
|
|
71
|
+
zsh: "shell",
|
|
72
|
+
yml: "yaml",
|
|
73
|
+
yaml: "yaml",
|
|
74
|
+
json: "json"
|
|
75
|
+
};
|
|
76
|
+
function languageFor(path) {
|
|
77
|
+
const extension = path?.split(".").at(-1)?.toLowerCase();
|
|
78
|
+
return extension && EXTENSION_LANGUAGES[extension] || "plaintext";
|
|
79
|
+
}
|
|
80
|
+
function icon(Icon) {
|
|
81
|
+
return /* @__PURE__ */ jsx(Icon, {
|
|
82
|
+
size: 12,
|
|
83
|
+
weight: "regular"
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function DiffStat({ added, removed }) {
|
|
87
|
+
return /* @__PURE__ */ jsxs(Text, {
|
|
88
|
+
as: "span",
|
|
89
|
+
variant: "xs",
|
|
90
|
+
color: "tertiary",
|
|
91
|
+
className: "tabular-nums",
|
|
92
|
+
children: [
|
|
93
|
+
/* @__PURE__ */ jsxs("span", {
|
|
94
|
+
className: "text-success-secondary",
|
|
95
|
+
children: ["+", added]
|
|
96
|
+
}),
|
|
97
|
+
" ",
|
|
98
|
+
/* @__PURE__ */ jsxs("span", {
|
|
99
|
+
className: "text-error-secondary",
|
|
100
|
+
children: ["−", removed]
|
|
101
|
+
})
|
|
102
|
+
]
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Presentations for the built-in tools of LangChain deep agents: the virtual
|
|
107
|
+
* filesystem, shell execution, and planning. `ChatThread` uses them by
|
|
108
|
+
* default; pass `tools` to add or override presentations.
|
|
109
|
+
*/
|
|
110
|
+
var deepAgentTools = {
|
|
111
|
+
ls: ({ args: input }) => ({
|
|
112
|
+
label: "List files",
|
|
113
|
+
icon: icon(FolderOpenIcon),
|
|
114
|
+
summary: text(args(input).path) ?? "/"
|
|
115
|
+
}),
|
|
116
|
+
read_file: ({ args: input }) => ({
|
|
117
|
+
label: "Read",
|
|
118
|
+
icon: icon(FileTextIcon),
|
|
119
|
+
summary: text(args(input).file_path)
|
|
120
|
+
}),
|
|
121
|
+
write_file: ({ args: input }) => {
|
|
122
|
+
const path = text(args(input).file_path);
|
|
123
|
+
const content = text(args(input).content);
|
|
124
|
+
return {
|
|
125
|
+
label: "Write",
|
|
126
|
+
icon: icon(FilePlusIcon),
|
|
127
|
+
summary: path,
|
|
128
|
+
meta: content ? /* @__PURE__ */ jsx(DiffStat, {
|
|
129
|
+
added: lines(content),
|
|
130
|
+
removed: 0
|
|
131
|
+
}) : null,
|
|
132
|
+
children: content ? /* @__PURE__ */ jsx(CodeLite, {
|
|
133
|
+
value: content,
|
|
134
|
+
language: languageFor(path),
|
|
135
|
+
variant: "block",
|
|
136
|
+
label: path
|
|
137
|
+
}) : void 0
|
|
138
|
+
};
|
|
139
|
+
},
|
|
140
|
+
edit_file: ({ args: input }) => {
|
|
141
|
+
const fields = args(input);
|
|
142
|
+
const { file_path, old_string, new_string } = fields;
|
|
143
|
+
const path = text(file_path);
|
|
144
|
+
const before = typeof old_string === "string" ? old_string : void 0;
|
|
145
|
+
const after = typeof new_string === "string" ? new_string : void 0;
|
|
146
|
+
return {
|
|
147
|
+
label: "Edit",
|
|
148
|
+
icon: icon(PencilSimpleIcon),
|
|
149
|
+
summary: path,
|
|
150
|
+
meta: before !== void 0 && after !== void 0 ? /* @__PURE__ */ jsx(DiffStat, { ...cachedLineChanges(fields, before, after) }) : null,
|
|
151
|
+
children: before !== void 0 && after !== void 0 ? /* @__PURE__ */ jsx(CodeLite, {
|
|
152
|
+
variant: "diff",
|
|
153
|
+
oldString: before,
|
|
154
|
+
newString: after,
|
|
155
|
+
fileName: path
|
|
156
|
+
}) : void 0
|
|
157
|
+
};
|
|
158
|
+
},
|
|
159
|
+
glob: ({ args: input }) => ({
|
|
160
|
+
label: "Find files",
|
|
161
|
+
icon: icon(MagnifyingGlassIcon),
|
|
162
|
+
summary: text(args(input).pattern)
|
|
163
|
+
}),
|
|
164
|
+
grep: ({ args: input }) => ({
|
|
165
|
+
label: "Search",
|
|
166
|
+
icon: icon(MagnifyingGlassIcon),
|
|
167
|
+
summary: text(args(input).pattern)
|
|
168
|
+
}),
|
|
169
|
+
execute: ({ args: input, result, error }) => {
|
|
170
|
+
const output = text(result) ?? text(error);
|
|
171
|
+
return {
|
|
172
|
+
label: "Run",
|
|
173
|
+
icon: icon(TerminalIcon),
|
|
174
|
+
summary: text(args(input).command),
|
|
175
|
+
children: output ? /* @__PURE__ */ jsx(CodeLite, {
|
|
176
|
+
value: output,
|
|
177
|
+
language: "plaintext",
|
|
178
|
+
variant: "block",
|
|
179
|
+
label: "Output"
|
|
180
|
+
}) : void 0
|
|
181
|
+
};
|
|
182
|
+
},
|
|
183
|
+
write_todos: ({ args: input }) => {
|
|
184
|
+
const items = planItems(args(input).todos);
|
|
185
|
+
const done = items.filter((item) => item.status === "completed").length;
|
|
186
|
+
return {
|
|
187
|
+
label: "Update plan",
|
|
188
|
+
icon: icon(ListChecksIcon),
|
|
189
|
+
summary: items.length ? `${done} of ${items.length} done` : null,
|
|
190
|
+
children: items.length ? /* @__PURE__ */ jsx(ChatPlan, {
|
|
191
|
+
items,
|
|
192
|
+
defaultExpanded: true
|
|
193
|
+
}) : void 0
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
/** One line naming a tool call, such as "Search · retrieval", for live status. */
|
|
198
|
+
function describeToolCall(name, input, tools) {
|
|
199
|
+
const renderer = tools[name];
|
|
200
|
+
const presentation = renderer?.({
|
|
201
|
+
id: name,
|
|
202
|
+
name,
|
|
203
|
+
status: "running",
|
|
204
|
+
args: input
|
|
205
|
+
});
|
|
206
|
+
if (presentation && !isValidElement(presentation)) {
|
|
207
|
+
const label = presentation.label ?? name;
|
|
208
|
+
return typeof presentation.summary === "string" ? `${label} · ${presentation.summary}` : label;
|
|
209
|
+
}
|
|
210
|
+
return name;
|
|
211
|
+
}
|
|
212
|
+
//#endregion
|
|
213
|
+
export { deepAgentTools, describeToolCall };
|
|
214
|
+
|
|
215
|
+
//# sourceMappingURL=deepAgentTools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deepAgentTools.js","names":[],"sources":["../../../src/components/ChatThread/deepAgentTools.tsx"],"sourcesContent":["import { isValidElement } from 'react';\n\nimport { FilePlusIcon } from '@phosphor-icons/react/dist/ssr/FilePlus';\nimport { FileTextIcon } from '@phosphor-icons/react/dist/ssr/FileText';\nimport { FolderOpenIcon } from '@phosphor-icons/react/dist/ssr/FolderOpen';\nimport { ListChecksIcon } from '@phosphor-icons/react/dist/ssr/ListChecks';\nimport { MagnifyingGlassIcon } from '@phosphor-icons/react/dist/ssr/MagnifyingGlass';\nimport { PencilSimpleIcon } from '@phosphor-icons/react/dist/ssr/PencilSimple';\nimport { TerminalIcon } from '@phosphor-icons/react/dist/ssr/Terminal';\n\nimport { ChatPlan } from '../ChatPlan';\nimport { CodeLite, type CodeLiteCodeProps } from '../Code/CodeLite';\nimport { Text } from '../Text';\nimport type { ChatThreadToolRenderer } from './ChatThread.types';\nimport { isRecord } from './messages';\nimport { planItems } from './toChatThread';\n\nfunction args(value: unknown) {\n return isRecord(value) ? value : {};\n}\n\nfunction text(value: unknown) {\n return typeof value === 'string' && value ? value : undefined;\n}\n\nfunction splitLines(value: string) {\n const lines = value.split('\\n');\n // A trailing newline ends the last line rather than starting a new one.\n if (lines.at(-1) === '') lines.pop();\n return lines;\n}\n\nfunction lines(value: string | undefined) {\n return value ? splitLines(value).length : 0;\n}\n\n/** Bounds the line diff so a huge edit can't stall rendering. */\nconst MAX_DIFF_LINES = 2_000;\n\n/** Lines added and removed, from the longest common subsequence of lines. */\nfunction lineChanges(before: string, after: string) {\n const a = splitLines(before);\n const b = splitLines(after);\n if (a.length * b.length > MAX_DIFF_LINES * MAX_DIFF_LINES) {\n return { added: b.length, removed: a.length };\n }\n let previous = Array.from({ length: b.length + 1 }, () => 0);\n for (let i = 1; i <= a.length; i += 1) {\n const current = Array.from({ length: b.length + 1 }, () => 0);\n for (let j = 1; j <= b.length; j += 1) {\n current[j] =\n a[i - 1] === b[j - 1]\n ? previous[j - 1] + 1\n : Math.max(previous[j], current[j - 1]);\n }\n previous = current;\n }\n const common = previous[b.length];\n return { added: b.length - common, removed: a.length - common };\n}\n\n// Renderers run on every render, so keep each call's counts with its args.\nconst changesByArgs = new WeakMap<object, ReturnType<typeof lineChanges>>();\n\nfunction cachedLineChanges(input: object, before: string, after: string) {\n let changes = changesByArgs.get(input);\n if (!changes) {\n changes = lineChanges(before, after);\n changesByArgs.set(input, changes);\n }\n return changes;\n}\n\nconst EXTENSION_LANGUAGES: Record<string, CodeLiteCodeProps['language']> = {\n ts: 'typescript',\n tsx: 'typescript',\n js: 'typescript',\n jsx: 'typescript',\n mjs: 'typescript',\n cjs: 'typescript',\n py: 'python',\n sh: 'shell',\n bash: 'shell',\n zsh: 'shell',\n yml: 'yaml',\n yaml: 'yaml',\n json: 'json',\n};\n\nfunction languageFor(path: string | undefined): CodeLiteCodeProps['language'] {\n const extension = path?.split('.').at(-1)?.toLowerCase();\n return (extension && EXTENSION_LANGUAGES[extension]) || 'plaintext';\n}\n\nfunction icon(Icon: typeof TerminalIcon) {\n return <Icon size={12} weight=\"regular\" />;\n}\n\nfunction DiffStat({ added, removed }: { added: number; removed: number }) {\n return (\n <Text as=\"span\" variant=\"xs\" color=\"tertiary\" className=\"tabular-nums\">\n <span className=\"text-success-secondary\">+{added}</span>{' '}\n <span className=\"text-error-secondary\">−{removed}</span>\n </Text>\n );\n}\n\n/**\n * Presentations for the built-in tools of LangChain deep agents: the virtual\n * filesystem, shell execution, and planning. `ChatThread` uses them by\n * default; pass `tools` to add or override presentations.\n */\nexport const deepAgentTools: Record<string, ChatThreadToolRenderer> = {\n ls: ({ args: input }) => ({\n label: 'List files',\n icon: icon(FolderOpenIcon),\n summary: text(args(input).path) ?? '/',\n }),\n read_file: ({ args: input }) => ({\n label: 'Read',\n icon: icon(FileTextIcon),\n summary: text(args(input).file_path),\n }),\n write_file: ({ args: input }) => {\n const path = text(args(input).file_path);\n const content = text(args(input).content);\n return {\n label: 'Write',\n icon: icon(FilePlusIcon),\n summary: path,\n meta: content ? <DiffStat added={lines(content)} removed={0} /> : null,\n children: content ? (\n <CodeLite\n value={content}\n language={languageFor(path)}\n variant=\"block\"\n label={path}\n />\n ) : undefined,\n };\n },\n edit_file: ({ args: input }) => {\n const fields = args(input);\n const { file_path, old_string, new_string } = fields;\n const path = text(file_path);\n const before = typeof old_string === 'string' ? old_string : undefined;\n const after = typeof new_string === 'string' ? new_string : undefined;\n return {\n label: 'Edit',\n icon: icon(PencilSimpleIcon),\n summary: path,\n meta:\n before !== undefined && after !== undefined ? (\n <DiffStat {...cachedLineChanges(fields, before, after)} />\n ) : null,\n children:\n before !== undefined && after !== undefined ? (\n <CodeLite\n variant=\"diff\"\n oldString={before}\n newString={after}\n fileName={path}\n />\n ) : undefined,\n };\n },\n glob: ({ args: input }) => ({\n label: 'Find files',\n icon: icon(MagnifyingGlassIcon),\n summary: text(args(input).pattern),\n }),\n grep: ({ args: input }) => ({\n label: 'Search',\n icon: icon(MagnifyingGlassIcon),\n summary: text(args(input).pattern),\n }),\n execute: ({ args: input, result, error }) => {\n const output = text(result) ?? text(error);\n return {\n label: 'Run',\n icon: icon(TerminalIcon),\n summary: text(args(input).command),\n children: output ? (\n <CodeLite\n value={output}\n language=\"plaintext\"\n variant=\"block\"\n label=\"Output\"\n />\n ) : undefined,\n };\n },\n write_todos: ({ args: input }) => {\n const items = planItems(args(input).todos);\n const done = items.filter((item) => item.status === 'completed').length;\n return {\n label: 'Update plan',\n icon: icon(ListChecksIcon),\n summary: items.length ? `${done} of ${items.length} done` : null,\n // The plan as it stood after this update.\n children: items.length ? (\n <ChatPlan items={items} defaultExpanded />\n ) : undefined,\n };\n },\n};\n\n/** One line naming a tool call, such as \"Search · retrieval\", for live status. */\nexport function describeToolCall(\n name: string,\n input: unknown,\n tools: Record<string, ChatThreadToolRenderer>\n) {\n const renderer = tools[name];\n const presentation = renderer?.({\n id: name,\n name,\n status: 'running',\n args: input,\n });\n if (presentation && !isValidElement(presentation)) {\n const label = presentation.label ?? name;\n return typeof presentation.summary === 'string'\n ? `${label} · ${presentation.summary}`\n : label;\n }\n return name;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,SAAS,KAAK,OAAgB;CAC5B,OAAO,SAAS,KAAK,IAAI,QAAQ,CAAC;AACpC;AAEA,SAAS,KAAK,OAAgB;CAC5B,OAAO,OAAO,UAAU,YAAY,QAAQ,QAAQ,KAAA;AACtD;AAEA,SAAS,WAAW,OAAe;CACjC,MAAM,QAAQ,MAAM,MAAM,IAAI;CAE9B,IAAI,MAAM,GAAG,EAAE,MAAM,IAAI,MAAM,IAAI;CACnC,OAAO;AACT;AAEA,SAAS,MAAM,OAA2B;CACxC,OAAO,QAAQ,WAAW,KAAK,CAAC,CAAC,SAAS;AAC5C;;AAGA,IAAM,iBAAiB;;AAGvB,SAAS,YAAY,QAAgB,OAAe;CAClD,MAAM,IAAI,WAAW,MAAM;CAC3B,MAAM,IAAI,WAAW,KAAK;CAC1B,IAAI,EAAE,SAAS,EAAE,SAAS,iBAAiB,gBACzC,OAAO;EAAE,OAAO,EAAE;EAAQ,SAAS,EAAE;CAAO;CAE9C,IAAI,WAAW,MAAM,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,CAAC;CAC3D,KAAK,IAAI,IAAI,GAAG,KAAK,EAAE,QAAQ,KAAK,GAAG;EACrC,MAAM,UAAU,MAAM,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,CAAC;EAC5D,KAAK,IAAI,IAAI,GAAG,KAAK,EAAE,QAAQ,KAAK,GAClC,QAAQ,KACN,EAAE,IAAI,OAAO,EAAE,IAAI,KACf,SAAS,IAAI,KAAK,IAClB,KAAK,IAAI,SAAS,IAAI,QAAQ,IAAI,EAAE;EAE5C,WAAW;CACb;CAC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A,UAAU,EAAE,MAAM,OAAO,QAAQ,YAAY;EAC3C,MAAM,SAAS,KAAK,MAAM,KAAK,KAAK,KAAK;EACzC,OAAO;GACL,OAAO;GACP,MAAM,KAAK,YAAY;GACvB,SAAS,KAAK,KAAK,KAAK,CAAC,CAAC,OAAO;GACjC,UAAU,SACR,oBAAC,UAAD;IACE,OAAO;IACP,UAAS;IACT,SAAQ;IACR,OAAM;GACP,CAAA,IACC,KAAA;EACN;CACF;CACA,cAAc,EAAE,MAAM,YAAY;EAChC,MAAM,QAAQ,UAAU,KAAK,KAAK,CAAC,CAAC,KAAK;EACzC,MAAM,OAAO,MAAM,QAAQ,SAAS,KAAK,WAAW,WAAW,CAAC,CAAC;EACjE,OAAO;GACL,OAAO;GACP,MAAM,KAAK,cAAc;GACzB,SAAS,MAAM,SAAS,GAAG,KAAK,MAAM,MAAM,OAAO,SAAS;GAE5D,UAAU,MAAM,SACd,oBAAC,UAAD;IAAiB;IAAO,iBAAA;GAAiB,CAAA,IACvC,KAAA;EACN;CACF;AACF;;AAGA,SAAgB,iBACd,MACA,OACA,OACA;CACA,MAAM,WAAW,MAAM;CACvB,MAAM,eAAe,WAAW;EAC9B,IAAI;EACJ;EACA,QAAQ;EACR,MAAM;CACR,CAAC;CACD,IAAI,gBAAgB,CAAC,eAAe,YAAY,GAAG;EACjD,MAAM,QAAQ,aAAa,SAAS;EACpC,OAAO,OAAO,aAAa,YAAY,WACnC,GAAG,MAAM,KAAK,aAAa,YAC3B;CACN;CACA,OAAO;AACT"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { ChatThread } from './ChatThread.js';
|
|
2
|
+
export type { ChatThreadControllerProps, ChatThreadProps, ChatThreadStreamProps, } from './ChatThread.js';
|
|
3
|
+
export { useLangGraphChatThread, useLangGraphForkPoint, } from './useLangGraphChatThread.js';
|
|
4
|
+
export type { LangGraphChatThreadState, UseLangGraphChatThreadOptions, } from './useLangGraphChatThread.js';
|
|
5
|
+
export { toChatThread } from './toChatThread.js';
|
|
6
|
+
export { parseInterrupt, toHumanInTheLoopResponse } from './interrupts.js';
|
|
7
|
+
export { deepAgentTools } from './deepAgentTools.js';
|
|
8
|
+
export type { ChatThreadActionRequest, ChatThreadActions, ChatThreadController, ChatThreadDecision, ChatThreadDecisionType, ChatThreadFile, ChatThreadInterrupt, ChatThreadModel, ChatThreadPart, ChatThreadPartSource, ChatThreadQueuedMessage, ChatThreadSelectors, ChatThreadSnapshot, ChatThreadStream, ChatThreadSubagent, ChatThreadTiming, ChatThreadToolPresentation, ChatThreadToolRenderer, ChatThreadTurn, ToChatThreadOptions, } from './ChatThread.types.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { parseInterrupt, toHumanInTheLoopResponse } from "./interrupts.js";
|
|
2
|
+
import { toChatThread } from "./toChatThread.js";
|
|
3
|
+
import { deepAgentTools } from "./deepAgentTools.js";
|
|
4
|
+
import { useLangGraphChatThread, useLangGraphForkPoint } from "./useLangGraphChatThread.js";
|
|
5
|
+
import { ChatThread } from "./ChatThread.js";
|
|
6
|
+
export { ChatThread, deepAgentTools, parseInterrupt, toChatThread, toHumanInTheLoopResponse, useLangGraphChatThread, useLangGraphForkPoint };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ChatThreadDecision, ChatThreadInterrupt } from './ChatThread.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Reads one interrupt. Human-in-the-loop middleware requests become
|
|
4
|
+
* `approval` interrupts in either casing: Python graphs send
|
|
5
|
+
* `action_requests` and `review_configs`, JavaScript graphs `actionRequests`
|
|
6
|
+
* and `reviewConfigs`. Anything else is `other`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function parseInterrupt(raw: unknown, index: number): ChatThreadInterrupt;
|
|
9
|
+
/**
|
|
10
|
+
* Builds the resume payload for a human-in-the-loop request, one decision
|
|
11
|
+
* per action in order, in the casing the graph sent.
|
|
12
|
+
*/
|
|
13
|
+
export declare function toHumanInTheLoopResponse(interrupt: Extract<ChatThreadInterrupt, {
|
|
14
|
+
kind: 'approval';
|
|
15
|
+
}>, decisions: readonly ChatThreadDecision[]): {
|
|
16
|
+
decisions: ({
|
|
17
|
+
type: string;
|
|
18
|
+
edited_action: {
|
|
19
|
+
name: string;
|
|
20
|
+
args: Record<string, unknown>;
|
|
21
|
+
};
|
|
22
|
+
editedAction?: undefined;
|
|
23
|
+
message?: undefined;
|
|
24
|
+
} | {
|
|
25
|
+
type: string;
|
|
26
|
+
editedAction: {
|
|
27
|
+
name: string;
|
|
28
|
+
args: Record<string, unknown>;
|
|
29
|
+
};
|
|
30
|
+
edited_action?: undefined;
|
|
31
|
+
message?: undefined;
|
|
32
|
+
} | {
|
|
33
|
+
type: string;
|
|
34
|
+
message: string;
|
|
35
|
+
edited_action?: undefined;
|
|
36
|
+
editedAction?: undefined;
|
|
37
|
+
} | {
|
|
38
|
+
type: string;
|
|
39
|
+
edited_action?: undefined;
|
|
40
|
+
editedAction?: undefined;
|
|
41
|
+
message?: undefined;
|
|
42
|
+
})[];
|
|
43
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { isRecord } from "./messages.js";
|
|
2
|
+
//#region packages/components/src/components/ChatThread/interrupts.ts
|
|
3
|
+
var DECISIONS = /* @__PURE__ */ new Set([
|
|
4
|
+
"approve",
|
|
5
|
+
"edit",
|
|
6
|
+
"reject",
|
|
7
|
+
"respond"
|
|
8
|
+
]);
|
|
9
|
+
function decisionsFrom(value) {
|
|
10
|
+
if (!Array.isArray(value)) return void 0;
|
|
11
|
+
const decisions = value.filter((item) => DECISIONS.has(item));
|
|
12
|
+
return decisions.length ? decisions : void 0;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Reads one interrupt. Human-in-the-loop middleware requests become
|
|
16
|
+
* `approval` interrupts in either casing: Python graphs send
|
|
17
|
+
* `action_requests` and `review_configs`, JavaScript graphs `actionRequests`
|
|
18
|
+
* and `reviewConfigs`. Anything else is `other`.
|
|
19
|
+
*/
|
|
20
|
+
function parseInterrupt(raw, index) {
|
|
21
|
+
const record = isRecord(raw) ? raw : {};
|
|
22
|
+
const id = typeof record.id === "string" && record.id ? record.id : `interrupt-${index}`;
|
|
23
|
+
const value = "value" in record ? record.value : raw;
|
|
24
|
+
if (isRecord(value)) {
|
|
25
|
+
const snake = Array.isArray(value.action_requests);
|
|
26
|
+
const camel = Array.isArray(value.actionRequests);
|
|
27
|
+
if (snake || camel) {
|
|
28
|
+
const requests = snake ? value.action_requests : value.actionRequests;
|
|
29
|
+
const configs = snake ? value.review_configs : value.reviewConfigs;
|
|
30
|
+
const allowedByName = /* @__PURE__ */ new Map();
|
|
31
|
+
for (const config of configs ?? []) {
|
|
32
|
+
if (!isRecord(config)) continue;
|
|
33
|
+
const name = snake ? config.action_name : config.actionName;
|
|
34
|
+
const allowed = decisionsFrom(snake ? config.allowed_decisions : config.allowedDecisions);
|
|
35
|
+
if (typeof name === "string" && allowed) allowedByName.set(name, allowed);
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
kind: "approval",
|
|
39
|
+
id,
|
|
40
|
+
casing: snake ? "snake" : "camel",
|
|
41
|
+
raw,
|
|
42
|
+
requests: requests.flatMap((request) => {
|
|
43
|
+
if (!isRecord(request) || typeof request.name !== "string") return [];
|
|
44
|
+
return [{
|
|
45
|
+
name: request.name,
|
|
46
|
+
args: isRecord(request.args) ? request.args : {},
|
|
47
|
+
description: typeof request.description === "string" ? request.description : void 0,
|
|
48
|
+
allowedDecisions: allowedByName.get(request.name) ?? ["approve", "reject"]
|
|
49
|
+
}];
|
|
50
|
+
})
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
kind: "other",
|
|
56
|
+
id,
|
|
57
|
+
value,
|
|
58
|
+
raw
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Builds the resume payload for a human-in-the-loop request, one decision
|
|
63
|
+
* per action in order, in the casing the graph sent.
|
|
64
|
+
*/
|
|
65
|
+
function toHumanInTheLoopResponse(interrupt, decisions) {
|
|
66
|
+
return { decisions: decisions.map((decision, index) => {
|
|
67
|
+
switch (decision.type) {
|
|
68
|
+
case "edit": {
|
|
69
|
+
const action = {
|
|
70
|
+
name: interrupt.requests[index]?.name ?? "",
|
|
71
|
+
args: decision.args
|
|
72
|
+
};
|
|
73
|
+
return interrupt.casing === "snake" ? {
|
|
74
|
+
type: "edit",
|
|
75
|
+
edited_action: action
|
|
76
|
+
} : {
|
|
77
|
+
type: "edit",
|
|
78
|
+
editedAction: action
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
case "reject": return decision.message ? {
|
|
82
|
+
type: "reject",
|
|
83
|
+
message: decision.message
|
|
84
|
+
} : { type: "reject" };
|
|
85
|
+
case "respond": return {
|
|
86
|
+
type: "respond",
|
|
87
|
+
message: decision.message
|
|
88
|
+
};
|
|
89
|
+
default: return { type: "approve" };
|
|
90
|
+
}
|
|
91
|
+
}) };
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
export { parseInterrupt, toHumanInTheLoopResponse };
|
|
95
|
+
|
|
96
|
+
//# sourceMappingURL=interrupts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interrupts.js","names":[],"sources":["../../../src/components/ChatThread/interrupts.ts"],"sourcesContent":["import type {\n ChatThreadActionRequest,\n ChatThreadDecision,\n ChatThreadDecisionType,\n ChatThreadInterrupt,\n} from './ChatThread.types';\nimport { isRecord } from './messages';\n\nconst DECISIONS = new Set<ChatThreadDecisionType>([\n 'approve',\n 'edit',\n 'reject',\n 'respond',\n]);\n\nfunction decisionsFrom(value: unknown): ChatThreadDecisionType[] | undefined {\n if (!Array.isArray(value)) return undefined;\n const decisions = value.filter((item): item is ChatThreadDecisionType =>\n DECISIONS.has(item as ChatThreadDecisionType)\n );\n return decisions.length ? decisions : undefined;\n}\n\n/**\n * Reads one interrupt. Human-in-the-loop middleware requests become\n * `approval` interrupts in either casing: Python graphs send\n * `action_requests` and `review_configs`, JavaScript graphs `actionRequests`\n * and `reviewConfigs`. Anything else is `other`.\n */\nexport function parseInterrupt(\n raw: unknown,\n index: number\n): ChatThreadInterrupt {\n const record = isRecord(raw) ? raw : {};\n const id =\n typeof record.id === 'string' && record.id\n ? record.id\n : `interrupt-${index}`;\n const value = 'value' in record ? record.value : raw;\n if (isRecord(value)) {\n const snake = Array.isArray(value.action_requests);\n const camel = Array.isArray(value.actionRequests);\n if (snake || camel) {\n const requests = (\n snake ? value.action_requests : value.actionRequests\n ) as unknown[];\n const configs = (snake ? value.review_configs : value.reviewConfigs) as\n | unknown[]\n | undefined;\n const allowedByName = new Map<string, ChatThreadDecisionType[]>();\n for (const config of configs ?? []) {\n if (!isRecord(config)) continue;\n const name = snake ? config.action_name : config.actionName;\n const allowed = decisionsFrom(\n snake ? config.allowed_decisions : config.allowedDecisions\n );\n if (typeof name === 'string' && allowed)\n allowedByName.set(name, allowed);\n }\n return {\n kind: 'approval',\n id,\n casing: snake ? 'snake' : 'camel',\n raw,\n requests: requests.flatMap((request): ChatThreadActionRequest[] => {\n if (!isRecord(request) || typeof request.name !== 'string') return [];\n return [\n {\n name: request.name,\n args: isRecord(request.args) ? request.args : {},\n description:\n typeof request.description === 'string'\n ? request.description\n : undefined,\n // Without a config, offer the decisions every request accepts.\n allowedDecisions: allowedByName.get(request.name) ?? [\n 'approve',\n 'reject',\n ],\n },\n ];\n }),\n };\n }\n }\n return { kind: 'other', id, value, raw };\n}\n\n/**\n * Builds the resume payload for a human-in-the-loop request, one decision\n * per action in order, in the casing the graph sent.\n */\nexport function toHumanInTheLoopResponse(\n interrupt: Extract<ChatThreadInterrupt, { kind: 'approval' }>,\n decisions: readonly ChatThreadDecision[]\n) {\n return {\n decisions: decisions.map((decision, index) => {\n switch (decision.type) {\n case 'edit': {\n const action = {\n name: interrupt.requests[index]?.name ?? '',\n args: decision.args,\n };\n return interrupt.casing === 'snake'\n ? { type: 'edit', edited_action: action }\n : { type: 'edit', editedAction: action };\n }\n case 'reject':\n return decision.message\n ? { type: 'reject', message: decision.message }\n : { type: 'reject' };\n case 'respond':\n return { type: 'respond', message: decision.message };\n default:\n return { type: 'approve' };\n }\n }),\n };\n}\n"],"mappings":";;AAQA,IAAM,4BAAY,IAAI,IAA4B;CAChD;CACA;CACA;CACA;AACF,CAAC;AAED,SAAS,cAAc,OAAsD;CAC3E,IAAI,CAAC,MAAM,QAAQ,KAAK,GAAG,OAAO,KAAA;CAClC,MAAM,YAAY,MAAM,QAAQ,SAC9B,UAAU,IAAI,IAA8B,CAC9C;CACA,OAAO,UAAU,SAAS,YAAY,KAAA;AACxC;;;;;;;AAQA,SAAgB,eACd,KACA,OACqB;CACrB,MAAM,SAAS,SAAS,GAAG,IAAI,MAAM,CAAC;CACtC,MAAM,KACJ,OAAO,OAAO,OAAO,YAAY,OAAO,KACpC,OAAO,KACP,aAAa;CACnB,MAAM,QAAQ,WAAW,SAAS,OAAO,QAAQ;CACjD,IAAI,SAAS,KAAK,GAAG;EACnB,MAAM,QAAQ,MAAM,QAAQ,MAAM,eAAe;EACjD,MAAM,QAAQ,MAAM,QAAQ,MAAM,cAAc;EAChD,IAAI,SAAS,OAAO;GAClB,MAAM,WACJ,QAAQ,MAAM,kBAAkB,MAAM;GAExC,MAAM,UAAW,QAAQ,MAAM,iBAAiB,MAAM;GAGtD,MAAM,gCAAgB,IAAI,IAAsC;GAChE,KAAK,MAAM,UAAU,WAAW,CAAC,GAAG;IAClC,IAAI,CAAC,SAAS,MAAM,GAAG;IACvB,MAAM,OAAO,QAAQ,OAAO,cAAc,OAAO;IACjD,MAAM,UAAU,cACd,QAAQ,OAAO,oBAAoB,OAAO,gBAC5C;IACA,IAAI,OAAO,SAAS,YAAY,SAC9B,cAAc,IAAI,MAAM,OAAO;GACnC;GACA,OAAO;IACL,MAAM;IACN;IACA,QAAQ,QAAQ,UAAU;IAC1B;IACA,UAAU,SAAS,SAAS,YAAuC;KACjE,IAAI,CAAC,SAAS,OAAO,KAAK,OAAO,QAAQ,SAAS,UAAU,OAAO,CAAC;KACpE,OAAO,CACL;MACE,MAAM,QAAQ;MACd,MAAM,SAAS,QAAQ,IAAI,IAAI,QAAQ,OAAO,CAAC;MAC/C,aACE,OAAO,QAAQ,gBAAgB,WAC3B,QAAQ,cACR,KAAA;MAEN,kBAAkB,cAAc,IAAI,QAAQ,IAAI,KAAK,CACnD,WACA,QACF;KACF,CACF;IACF,CAAC;GACH;EACF;CACF;CACA,OAAO;EAAE,MAAM;EAAS;EAAI;EAAO;CAAI;AACzC;;;;;AAMA,SAAgB,yBACd,WACA,WACA;CACA,OAAO,EACL,WAAW,UAAU,KAAK,UAAU,UAAU;EAC5C,QAAQ,SAAS,MAAjB;GACE,KAAK,QAAQ;IACX,MAAM,SAAS;KACb,MAAM,UAAU,SAAS,MAAM,EAAE,QAAQ;KACzC,MAAM,SAAS;IACjB;IACA,OAAO,UAAU,WAAW,UACxB;KAAE,MAAM;KAAQ,eAAe;IAAO,IACtC;KAAE,MAAM;KAAQ,cAAc;IAAO;GAC3C;GACA,KAAK,UACH,OAAO,SAAS,UACZ;IAAE,MAAM;IAAU,SAAS,SAAS;GAAQ,IAC5C,EAAE,MAAM,SAAS;GACvB,KAAK,WACH,OAAO;IAAE,MAAM;IAAW,SAAS,SAAS;GAAQ;GACtD,SACE,OAAO,EAAE,MAAM,UAAU;EAC7B;CACF,CAAC,EACH;AACF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads LangChain messages structurally, whether they are `@langchain/core`
|
|
3
|
+
* class instances (`@langchain/react` 1.x) or plain objects (0.3.x and
|
|
4
|
+
* server payloads), without importing either package.
|
|
5
|
+
*/
|
|
6
|
+
export type MessageKind = 'human' | 'ai' | 'tool' | 'system' | 'other';
|
|
7
|
+
export interface MessageToolCall {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
args: unknown;
|
|
11
|
+
}
|
|
12
|
+
export interface NormalizedMessage {
|
|
13
|
+
id: string;
|
|
14
|
+
kind: MessageKind;
|
|
15
|
+
text: string;
|
|
16
|
+
reasoning: string;
|
|
17
|
+
images: string[];
|
|
18
|
+
toolCalls: MessageToolCall[];
|
|
19
|
+
/** Tool results only. */
|
|
20
|
+
toolCallId?: string;
|
|
21
|
+
toolStatus?: 'success' | 'error';
|
|
22
|
+
raw: unknown;
|
|
23
|
+
}
|
|
24
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
25
|
+
/**
|
|
26
|
+
* Normalizes one message. Tool calls without IDs get IDs derived from the
|
|
27
|
+
* message ID and position, so they stay stable across renders.
|
|
28
|
+
*/
|
|
29
|
+
export declare function normalizeMessage(value: unknown, index: number): NormalizedMessage;
|