@langchain/macaw-components 1.7.19 → 1.7.21

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.
Files changed (47) hide show
  1. package/dist/catalog.json +798 -775
  2. package/dist/components/ChatComposer/ChatComposer.js +8 -1
  3. package/dist/components/ChatComposer/ChatComposer.js.map +1 -1
  4. package/dist/components/ChatThread/ChatThread.d.ts +59 -0
  5. package/dist/components/ChatThread/ChatThread.js +338 -0
  6. package/dist/components/ChatThread/ChatThread.js.map +1 -0
  7. package/dist/components/ChatThread/ChatThread.types.d.ts +284 -0
  8. package/dist/components/ChatThread/ChatThread.types.js +0 -0
  9. package/dist/components/ChatThread/ChatThreadContext.d.ts +34 -0
  10. package/dist/components/ChatThread/ChatThreadContext.js +53 -0
  11. package/dist/components/ChatThread/ChatThreadContext.js.map +1 -0
  12. package/dist/components/ChatThread/ChatThreadRequests.d.ts +1 -0
  13. package/dist/components/ChatThread/ChatThreadRequests.js +233 -0
  14. package/dist/components/ChatThread/ChatThreadRequests.js.map +1 -0
  15. package/dist/components/ChatThread/ChatThreadWork.d.ts +13 -0
  16. package/dist/components/ChatThread/ChatThreadWork.js +174 -0
  17. package/dist/components/ChatThread/ChatThreadWork.js.map +1 -0
  18. package/dist/components/ChatThread/deepAgentTools.d.ts +9 -0
  19. package/dist/components/ChatThread/deepAgentTools.js +215 -0
  20. package/dist/components/ChatThread/deepAgentTools.js.map +1 -0
  21. package/dist/components/ChatThread/index.d.ts +8 -0
  22. package/dist/components/ChatThread/index.js +6 -0
  23. package/dist/components/ChatThread/interrupts.d.ts +43 -0
  24. package/dist/components/ChatThread/interrupts.js +96 -0
  25. package/dist/components/ChatThread/interrupts.js.map +1 -0
  26. package/dist/components/ChatThread/messages.d.ts +29 -0
  27. package/dist/components/ChatThread/messages.js +137 -0
  28. package/dist/components/ChatThread/messages.js.map +1 -0
  29. package/dist/components/ChatThread/toChatThread.d.ts +12 -0
  30. package/dist/components/ChatThread/toChatThread.js +275 -0
  31. package/dist/components/ChatThread/toChatThread.js.map +1 -0
  32. package/dist/components/ChatThread/useLangGraphChatThread.d.ts +36 -0
  33. package/dist/components/ChatThread/useLangGraphChatThread.js +240 -0
  34. package/dist/components/ChatThread/useLangGraphChatThread.js.map +1 -0
  35. package/dist/components/ChatToolCall/ChatToolCallDetails.js +1 -1
  36. package/dist/components/MarkdownDisplay/MarkdownDisplay.js +1 -1
  37. package/dist/components/Tooltip/Tooltip.js +2 -10
  38. package/dist/components/Tooltip/Tooltip.js.map +1 -1
  39. package/dist/docs/phosphor-icon-catalog.js +2 -2
  40. package/dist/icons/LongTailPhosphorIcons.js +1 -1
  41. package/dist/utilities.css +1 -1
  42. package/dist/utils/inputModality.d.ts +3 -0
  43. package/dist/utils/inputModality.js +18 -0
  44. package/dist/utils/inputModality.js.map +1 -0
  45. package/docs/CHAT.md +109 -3
  46. package/docs/DESIGN.md +4 -1
  47. package/package.json +6 -2
@@ -0,0 +1,137 @@
1
+ //#region packages/components/src/components/ChatThread/messages.ts
2
+ function isRecord(value) {
3
+ return typeof value === "object" && value !== null;
4
+ }
5
+ function readString(value) {
6
+ return typeof value === "string" ? value : void 0;
7
+ }
8
+ function messageKind(message) {
9
+ let type = readString(message.type) ?? readString(message.role);
10
+ if (!type && typeof message._getType === "function") type = readString(message._getType());
11
+ switch (type) {
12
+ case "human":
13
+ case "user": return "human";
14
+ case "ai":
15
+ case "assistant": return "ai";
16
+ case "tool": return "tool";
17
+ case "system":
18
+ case "developer": return "system";
19
+ default: return "other";
20
+ }
21
+ }
22
+ function parseArgs(value) {
23
+ if (typeof value !== "string") return value;
24
+ try {
25
+ return JSON.parse(value);
26
+ } catch {
27
+ return value;
28
+ }
29
+ }
30
+ function imageUrl(block) {
31
+ const imageUrlField = block.image_url;
32
+ if (typeof imageUrlField === "string") return imageUrlField;
33
+ if (isRecord(imageUrlField)) return readString(imageUrlField.url);
34
+ const url = readString(block.url);
35
+ if (url) return url;
36
+ const data = readString(block.data) ?? readString(block.base64) ?? (isRecord(block.source) ? readString(block.source.data) : void 0);
37
+ const mimeType = readString(block.mimeType) ?? readString(block.mime_type) ?? (isRecord(block.source) ? readString(block.source.media_type) : void 0);
38
+ return data ? `data:${mimeType ?? "image/png"};base64,${data}` : void 0;
39
+ }
40
+ function reasoningFromKwargs(message) {
41
+ const kwargs = message.additional_kwargs;
42
+ if (!isRecord(kwargs)) return "";
43
+ const content = readString(kwargs.reasoning_content);
44
+ if (content) return content;
45
+ const reasoning = kwargs.reasoning;
46
+ if (isRecord(reasoning) && Array.isArray(reasoning.summary)) return reasoning.summary.map((part) => isRecord(part) ? readString(part.text) ?? "" : "").filter(Boolean).join("\n\n");
47
+ return "";
48
+ }
49
+ function contentBlocks(message) {
50
+ try {
51
+ const standard = message.contentBlocks;
52
+ if (Array.isArray(standard)) return standard;
53
+ } catch {}
54
+ return Array.isArray(message.content) ? message.content : void 0;
55
+ }
56
+ /**
57
+ * Normalizes one message. Tool calls without IDs get IDs derived from the
58
+ * message ID and position, so they stay stable across renders.
59
+ */
60
+ function normalizeMessage(value, index) {
61
+ const message = isRecord(value) ? value : {};
62
+ const id = readString(message.id) ?? `message-${index}`;
63
+ const kind = messageKind(message);
64
+ const textParts = [];
65
+ const reasoningParts = [];
66
+ const images = [];
67
+ const blockToolCalls = [];
68
+ if (typeof message.content === "string") textParts.push(message.content);
69
+ const blocks = contentBlocks(message);
70
+ for (const block of blocks ?? []) {
71
+ if (typeof block === "string") {
72
+ textParts.push(block);
73
+ continue;
74
+ }
75
+ if (!isRecord(block)) continue;
76
+ switch (block.type) {
77
+ case "text":
78
+ if (typeof message.content !== "string") textParts.push(readString(block.text) ?? "");
79
+ break;
80
+ case "reasoning":
81
+ reasoningParts.push(readString(block.reasoning) ?? "");
82
+ break;
83
+ case "thinking":
84
+ reasoningParts.push(readString(block.thinking) ?? "");
85
+ break;
86
+ case "image":
87
+ case "image_url": {
88
+ const url = imageUrl(block);
89
+ if (url) images.push(url);
90
+ break;
91
+ }
92
+ case "tool_use":
93
+ case "tool_call": {
94
+ const name = readString(block.name);
95
+ if (name) blockToolCalls.push({
96
+ id: readString(block.id) ?? "",
97
+ name,
98
+ args: parseArgs(block.input ?? block.args)
99
+ });
100
+ break;
101
+ }
102
+ }
103
+ }
104
+ let toolCalls = [];
105
+ const rawToolCalls = [message.tool_calls, message.tool_call_chunks].find((calls) => Array.isArray(calls) && calls.length > 0);
106
+ if (rawToolCalls) toolCalls = rawToolCalls.flatMap((call) => {
107
+ if (!isRecord(call)) return [];
108
+ const name = readString(call.name);
109
+ if (!name) return [];
110
+ return [{
111
+ id: readString(call.id) ?? "",
112
+ name,
113
+ args: parseArgs(call.args)
114
+ }];
115
+ });
116
+ else toolCalls = blockToolCalls;
117
+ toolCalls = toolCalls.map((call, position) => ({
118
+ ...call,
119
+ id: call.id || `${id}:tool:${position}`
120
+ }));
121
+ const status = readString(message.status);
122
+ return {
123
+ id,
124
+ kind,
125
+ text: textParts.join(""),
126
+ reasoning: reasoningParts.filter(Boolean).join("\n\n") || reasoningFromKwargs(message),
127
+ images,
128
+ toolCalls,
129
+ toolCallId: readString(message.tool_call_id),
130
+ toolStatus: status === "error" ? "error" : kind === "tool" ? "success" : void 0,
131
+ raw: value
132
+ };
133
+ }
134
+ //#endregion
135
+ export { isRecord, normalizeMessage };
136
+
137
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.js","names":[],"sources":["../../../src/components/ChatThread/messages.ts"],"sourcesContent":["/**\n * Reads LangChain messages structurally, whether they are `@langchain/core`\n * class instances (`@langchain/react` 1.x) or plain objects (0.3.x and\n * server payloads), without importing either package.\n */\n\nexport type MessageKind = 'human' | 'ai' | 'tool' | 'system' | 'other';\n\nexport interface MessageToolCall {\n id: string;\n name: string;\n args: unknown;\n}\n\nexport interface NormalizedMessage {\n id: string;\n kind: MessageKind;\n text: string;\n reasoning: string;\n images: string[];\n toolCalls: MessageToolCall[];\n /** Tool results only. */\n toolCallId?: string;\n toolStatus?: 'success' | 'error';\n raw: unknown;\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null;\n}\n\nfunction readString(value: unknown) {\n return typeof value === 'string' ? value : undefined;\n}\n\nfunction messageKind(message: Record<string, unknown>): MessageKind {\n let type = readString(message.type) ?? readString(message.role);\n if (!type && typeof message._getType === 'function') {\n type = readString((message._getType as () => unknown)());\n }\n switch (type) {\n case 'human':\n case 'user':\n return 'human';\n case 'ai':\n case 'assistant':\n return 'ai';\n case 'tool':\n return 'tool';\n case 'system':\n case 'developer':\n return 'system';\n default:\n return 'other';\n }\n}\n\nfunction parseArgs(value: unknown) {\n if (typeof value !== 'string') return value;\n try {\n return JSON.parse(value) as unknown;\n } catch {\n // Arguments still streaming in are not valid JSON yet.\n return value;\n }\n}\n\nfunction imageUrl(block: Record<string, unknown>) {\n const imageUrlField = block.image_url;\n if (typeof imageUrlField === 'string') return imageUrlField;\n if (isRecord(imageUrlField)) return readString(imageUrlField.url);\n const url = readString(block.url);\n if (url) return url;\n const data =\n readString(block.data) ??\n readString(block.base64) ??\n (isRecord(block.source) ? readString(block.source.data) : undefined);\n const mimeType =\n readString(block.mimeType) ??\n readString(block.mime_type) ??\n (isRecord(block.source) ? readString(block.source.media_type) : undefined);\n return data ? `data:${mimeType ?? 'image/png'};base64,${data}` : undefined;\n}\n\nfunction reasoningFromKwargs(message: Record<string, unknown>) {\n const kwargs = message.additional_kwargs;\n if (!isRecord(kwargs)) return '';\n const content = readString(kwargs.reasoning_content);\n if (content) return content;\n const reasoning = kwargs.reasoning;\n if (isRecord(reasoning) && Array.isArray(reasoning.summary)) {\n return reasoning.summary\n .map((part) => (isRecord(part) ? (readString(part.text) ?? '') : ''))\n .filter(Boolean)\n .join('\\n\\n');\n }\n return '';\n}\n\nfunction contentBlocks(\n message: Record<string, unknown>\n): unknown[] | undefined {\n // Prefer the standard blocks a core message instance derives across\n // providers; fall back to the raw content of plain objects.\n try {\n const standard = message.contentBlocks;\n if (Array.isArray(standard)) return standard;\n } catch {\n // A message that cannot derive standard blocks still has raw content.\n }\n return Array.isArray(message.content) ? message.content : undefined;\n}\n\n/**\n * Normalizes one message. Tool calls without IDs get IDs derived from the\n * message ID and position, so they stay stable across renders.\n */\nexport function normalizeMessage(\n value: unknown,\n index: number\n): NormalizedMessage {\n const message = isRecord(value) ? value : {};\n const id = readString(message.id) ?? `message-${index}`;\n const kind = messageKind(message);\n const textParts: string[] = [];\n const reasoningParts: string[] = [];\n const images: string[] = [];\n const blockToolCalls: MessageToolCall[] = [];\n\n if (typeof message.content === 'string') textParts.push(message.content);\n const blocks = contentBlocks(message);\n for (const block of blocks ?? []) {\n if (typeof block === 'string') {\n textParts.push(block);\n continue;\n }\n if (!isRecord(block)) continue;\n switch (block.type) {\n case 'text':\n if (typeof message.content !== 'string') {\n textParts.push(readString(block.text) ?? '');\n }\n break;\n case 'reasoning':\n reasoningParts.push(readString(block.reasoning) ?? '');\n break;\n case 'thinking':\n reasoningParts.push(readString(block.thinking) ?? '');\n break;\n case 'image':\n case 'image_url': {\n const url = imageUrl(block);\n if (url) images.push(url);\n break;\n }\n case 'tool_use':\n case 'tool_call': {\n const name = readString(block.name);\n if (name) {\n blockToolCalls.push({\n id: readString(block.id) ?? '',\n name,\n args: parseArgs(block.input ?? block.args),\n });\n }\n break;\n }\n default:\n break;\n }\n }\n\n let toolCalls: MessageToolCall[] = [];\n // A streaming chunk can carry an empty `tool_calls` beside its chunks.\n const rawToolCalls = [message.tool_calls, message.tool_call_chunks].find(\n (calls): calls is unknown[] => Array.isArray(calls) && calls.length > 0\n );\n if (rawToolCalls) {\n toolCalls = rawToolCalls.flatMap((call) => {\n if (!isRecord(call)) return [];\n const name = readString(call.name);\n if (!name) return [];\n return [\n { id: readString(call.id) ?? '', name, args: parseArgs(call.args) },\n ];\n });\n } else {\n toolCalls = blockToolCalls;\n }\n toolCalls = toolCalls.map((call, position) => ({\n ...call,\n id: call.id || `${id}:tool:${position}`,\n }));\n\n const status = readString(message.status);\n return {\n id,\n kind,\n text: textParts.join(''),\n reasoning:\n reasoningParts.filter(Boolean).join('\\n\\n') ||\n reasoningFromKwargs(message),\n images,\n toolCalls,\n toolCallId: readString(message.tool_call_id),\n toolStatus:\n status === 'error' ? 'error' : kind === 'tool' ? 'success' : undefined,\n raw: value,\n };\n}\n"],"mappings":";AA2BA,SAAgB,SAAS,OAAkD;CACzE,OAAO,OAAO,UAAU,YAAY,UAAU;AAChD;AAEA,SAAS,WAAW,OAAgB;CAClC,OAAO,OAAO,UAAU,WAAW,QAAQ,KAAA;AAC7C;AAEA,SAAS,YAAY,SAA+C;CAClE,IAAI,OAAO,WAAW,QAAQ,IAAI,KAAK,WAAW,QAAQ,IAAI;CAC9D,IAAI,CAAC,QAAQ,OAAO,QAAQ,aAAa,YACvC,OAAO,WAAY,QAAQ,SAA2B,CAAC;CAEzD,QAAQ,MAAR;EACE,KAAK;EACL,KAAK,QACH,OAAO;EACT,KAAK;EACL,KAAK,aACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,KAAK;EACL,KAAK,aACH,OAAO;EACT,SACE,OAAO;CACX;AACF;AAEA,SAAS,UAAU,OAAgB;CACjC,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI;EACF,OAAO,KAAK,MAAM,KAAK;CACzB,QAAQ;EAEN,OAAO;CACT;AACF;AAEA,SAAS,SAAS,OAAgC;CAChD,MAAM,gBAAgB,MAAM;CAC5B,IAAI,OAAO,kBAAkB,UAAU,OAAO;CAC9C,IAAI,SAAS,aAAa,GAAG,OAAO,WAAW,cAAc,GAAG;CAChE,MAAM,MAAM,WAAW,MAAM,GAAG;CAChC,IAAI,KAAK,OAAO;CAChB,MAAM,OACJ,WAAW,MAAM,IAAI,KACrB,WAAW,MAAM,MAAM,MACtB,SAAS,MAAM,MAAM,IAAI,WAAW,MAAM,OAAO,IAAI,IAAI,KAAA;CAC5D,MAAM,WACJ,WAAW,MAAM,QAAQ,KACzB,WAA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CAAC,KAAK,MAAM,KAC1C,oBAAoB,OAAO;EAC7B;EACA;EACA,YAAY,WAAW,QAAQ,YAAY;EAC3C,YACE,WAAW,UAAU,UAAU,SAAS,SAAS,YAAY,KAAA;EAC/D,KAAK;CACP;AACF"}
@@ -0,0 +1,12 @@
1
+ import type { ChatMessageStatus } from '../ChatMessage/index.js';
2
+ import type { ChatPlanItem } from '../ChatPlan/index.js';
3
+ import type { ChatThreadModel, ChatThreadSnapshot, ToChatThreadOptions } from './ChatThread.types.js';
4
+ /** Reads a deep agent's todos, from its state or a `write_todos` call. */
5
+ export declare function planItems(todos: unknown): ChatPlanItem[];
6
+ /**
7
+ * Turns LangGraph stream state into render-ready chat turns. Pure: it reads
8
+ * plain values, so it works with `@langchain/react` 1.x and 2.0, the 0.3.x
9
+ * hook, recorded fixtures, and tests alike.
10
+ */
11
+ export declare function toChatThread(snapshot: ChatThreadSnapshot, { hideMessage, messagesKey, subagentTools, }?: ToChatThreadOptions): ChatThreadModel;
12
+ export type { ChatMessageStatus };
@@ -0,0 +1,275 @@
1
+ import { isRecord, normalizeMessage } from "./messages.js";
2
+ import { parseInterrupt } from "./interrupts.js";
3
+ //#region packages/components/src/components/ChatThread/toChatThread.ts
4
+ var DEFAULT_SUBAGENT_TOOLS = ["task"];
5
+ function readString(value) {
6
+ return typeof value === "string" ? value : void 0;
7
+ }
8
+ function errorMessage(error) {
9
+ if (error == null) return void 0;
10
+ if (error instanceof Error) return error.message || "Something went wrong.";
11
+ if (typeof error === "string") return error;
12
+ if (isRecord(error) && typeof error.message === "string") return error.message;
13
+ return "Something went wrong.";
14
+ }
15
+ function toTime(value) {
16
+ if (value instanceof Date) return value.getTime();
17
+ if (typeof value === "number") return value;
18
+ if (typeof value === "string") {
19
+ const time = Date.parse(value);
20
+ return Number.isNaN(time) ? void 0 : time;
21
+ }
22
+ }
23
+ function liveToolCalls(toolCalls) {
24
+ const byId = /* @__PURE__ */ new Map();
25
+ for (const call of toolCalls ?? []) {
26
+ if (!isRecord(call)) continue;
27
+ const id = readString(call.callId) ?? readString(call.id);
28
+ if (id) byId.set(id, call);
29
+ }
30
+ return byId;
31
+ }
32
+ function textFromValue(value) {
33
+ if (typeof value === "string") return value;
34
+ if (Array.isArray(value)) return value.map((item) => typeof item === "string" ? item : isRecord(item) && typeof item.text === "string" ? item.text : "").join("") || void 0;
35
+ }
36
+ function resultValue(message, live) {
37
+ if (message) {
38
+ const content = isRecord(message.raw) ? message.raw.content : void 0;
39
+ return textFromValue(content) ?? content;
40
+ }
41
+ return live?.output ?? void 0;
42
+ }
43
+ /**
44
+ * Merges what the thread knows about a call: a tool result message settles
45
+ * it, then the live tool stream, then whether a pending interrupt or an
46
+ * active run is holding it. A call left without an outcome after the run
47
+ * ends was canceled.
48
+ */
49
+ function toolCallStatus({ result, live, gated, runActive, paused }) {
50
+ if (result) return result.toolStatus === "error" ? "failed" : "succeeded";
51
+ if (live?.status === "finished") return "succeeded";
52
+ if (live?.status === "error") return "failed";
53
+ if (gated) return "input-required";
54
+ if (live?.status === "running" || runActive) return "running";
55
+ return paused ? "pending" : "canceled";
56
+ }
57
+ /** Reads a deep agent's todos, from its state or a `write_todos` call. */
58
+ function planItems(todos) {
59
+ if (!Array.isArray(todos)) return [];
60
+ return todos.flatMap((todo, index) => {
61
+ if (!isRecord(todo) || typeof todo.content !== "string") return [];
62
+ const status = todo.status === "completed" ? "completed" : todo.status === "in_progress" || todo.status === "in-progress" ? "in-progress" : "pending";
63
+ return [{
64
+ id: `todo-${index}`,
65
+ label: todo.content,
66
+ status
67
+ }];
68
+ });
69
+ }
70
+ function planFromValues(values) {
71
+ const items = isRecord(values) ? planItems(values.todos) : [];
72
+ return items.length ? items : void 0;
73
+ }
74
+ function filesFromValues(values) {
75
+ if (!isRecord(values) || !isRecord(values.files)) return void 0;
76
+ const files = Object.entries(values.files).map(([path, data]) => ({
77
+ path,
78
+ modifiedAt: isRecord(data) ? readString(data.modified_at) : void 0
79
+ }));
80
+ return files.length ? files : void 0;
81
+ }
82
+ function queuedFromEntries(queue, messagesKey) {
83
+ return (queue ?? []).flatMap((entry) => {
84
+ if (!isRecord(entry) || typeof entry.id !== "string") return [];
85
+ const input = (isRecord(entry.values) ? entry.values : void 0)?.[messagesKey];
86
+ const last = (Array.isArray(input) ? input : []).at(-1);
87
+ const text = last === void 0 ? "" : normalizeMessage(last, 0).text;
88
+ return [{
89
+ id: entry.id,
90
+ text
91
+ }];
92
+ });
93
+ }
94
+ /** Matches each approval request, in order, to an open call it gates. */
95
+ function anchorInterrupts(interrupts, calls) {
96
+ const gates = /* @__PURE__ */ new Map();
97
+ for (const interrupt of interrupts) {
98
+ if (interrupt.kind !== "approval") continue;
99
+ for (const request of interrupt.requests) {
100
+ const open = calls.filter(({ call, settled }) => !settled && call.name === request.name && !gates.has(call.id));
101
+ const match = open.find(({ call }) => JSON.stringify(call.args) === JSON.stringify(request.args)) ?? open[0];
102
+ if (match) {
103
+ gates.set(match.call.id, interrupt.id);
104
+ request.toolCallId = match.call.id;
105
+ }
106
+ }
107
+ }
108
+ return gates;
109
+ }
110
+ function subagentModel({ call, status, handle }) {
111
+ const args = isRecord(call.args) ? call.args : {};
112
+ const snapshot = isRecord(handle) ? handle : {};
113
+ const startedAt = toTime(snapshot.startedAt);
114
+ const completedAt = toTime(snapshot.completedAt);
115
+ const subagentStatus = snapshot.status === "error" ? "failed" : snapshot.status === "complete" && status === "running" ? "succeeded" : status;
116
+ return {
117
+ id: call.id,
118
+ name: readString(args.subagent_type) ?? readString(args.subagentType) ?? readString(snapshot.name) ?? "subagent",
119
+ task: readString(args.description) ?? readString(snapshot.taskInput) ?? void 0,
120
+ status: subagentStatus,
121
+ startedAt,
122
+ elapsedMs: startedAt !== void 0 && completedAt !== void 0 ? completedAt - startedAt : void 0
123
+ };
124
+ }
125
+ /**
126
+ * Turns LangGraph stream state into render-ready chat turns. Pure: it reads
127
+ * plain values, so it works with `@langchain/react` 1.x and 2.0, the 0.3.x
128
+ * hook, recorded fixtures, and tests alike.
129
+ */
130
+ function toChatThread(snapshot, { hideMessage, messagesKey = "messages", subagentTools = DEFAULT_SUBAGENT_TOOLS } = {}) {
131
+ const runActive = snapshot.isLoading === true;
132
+ const messages = snapshot.messages.filter((message) => !hideMessage?.(message)).map(normalizeMessage);
133
+ const results = /* @__PURE__ */ new Map();
134
+ for (const message of messages) if (message.kind === "tool" && message.toolCallId) results.set(message.toolCallId, message);
135
+ const live = liveToolCalls(snapshot.toolCalls);
136
+ let lastAiIndex = -1;
137
+ let lastHumanIndex = -1;
138
+ messages.forEach((message, index) => {
139
+ if (message.kind === "ai") lastAiIndex = index;
140
+ if (message.kind === "human") lastHumanIndex = index;
141
+ });
142
+ const isCurrent = (index) => index > lastHumanIndex;
143
+ const interrupts = (snapshot.interrupts ?? []).map(parseInterrupt);
144
+ const gates = anchorInterrupts(interrupts, messages.flatMap((message, index) => isCurrent(index) ? message.toolCalls.map((call) => ({
145
+ call,
146
+ settled: results.has(call.id)
147
+ })) : []));
148
+ const subagentNames = new Set(subagentTools);
149
+ const error = errorMessage(snapshot.error);
150
+ const turns = [];
151
+ messages.forEach((message, index) => {
152
+ if (message.kind === "human") {
153
+ turns.push({
154
+ id: message.id,
155
+ user: {
156
+ message: {
157
+ id: message.id,
158
+ role: "user",
159
+ status: "completed",
160
+ content: [{
161
+ id: `${message.id}:text`,
162
+ type: "text",
163
+ text: message.text,
164
+ appearance: "bubble"
165
+ }]
166
+ },
167
+ text: message.text,
168
+ raw: message.raw
169
+ },
170
+ parts: [],
171
+ status: "completed",
172
+ actionCount: 0
173
+ });
174
+ return;
175
+ }
176
+ if (message.kind !== "ai") return;
177
+ if (turns.length === 0) turns.push({
178
+ id: message.id,
179
+ parts: [],
180
+ status: "completed",
181
+ actionCount: 0
182
+ });
183
+ const turn = turns[turns.length - 1];
184
+ const latest = runActive && index === lastAiIndex;
185
+ const source = { message: message.raw };
186
+ if (message.reasoning) turn.parts.push({
187
+ type: "reasoning",
188
+ id: `${message.id}:reasoning`,
189
+ text: message.reasoning,
190
+ streaming: latest && !message.text && message.toolCalls.length === 0,
191
+ source
192
+ });
193
+ if (message.text) turn.parts.push({
194
+ type: "text",
195
+ id: `${message.id}:text`,
196
+ text: message.text,
197
+ streaming: latest && message.toolCalls.length === 0,
198
+ source
199
+ });
200
+ for (const [imageIndex, url] of message.images.entries()) turn.parts.push({
201
+ type: "image",
202
+ id: `${message.id}:image:${imageIndex}`,
203
+ url,
204
+ source
205
+ });
206
+ for (const call of message.toolCalls) {
207
+ const result = results.get(call.id);
208
+ const liveCall = live.get(call.id);
209
+ const interruptId = gates.get(call.id);
210
+ const status = toolCallStatus({
211
+ result,
212
+ live: liveCall,
213
+ gated: interruptId !== void 0,
214
+ runActive: runActive && isCurrent(index),
215
+ paused: interrupts.length > 0 && isCurrent(index)
216
+ });
217
+ const value = resultValue(result, liveCall);
218
+ const callSource = {
219
+ message: message.raw,
220
+ result: result?.raw
221
+ };
222
+ turn.actionCount += 1;
223
+ if (subagentNames.has(call.name)) {
224
+ const handle = snapshot.subagents?.get(call.id);
225
+ turn.parts.push({
226
+ type: "subagent",
227
+ id: call.id,
228
+ subagent: subagentModel({
229
+ call,
230
+ status,
231
+ handle
232
+ }),
233
+ result: textFromValue(value),
234
+ handle,
235
+ interruptId,
236
+ source: callSource
237
+ });
238
+ continue;
239
+ }
240
+ turn.parts.push({
241
+ type: "tool-call",
242
+ id: call.id,
243
+ interruptId,
244
+ source: callSource,
245
+ toolCall: {
246
+ id: call.id,
247
+ name: call.name,
248
+ status,
249
+ args: call.args,
250
+ result: status === "failed" ? void 0 : value,
251
+ error: status === "failed" ? value ?? errorMessage(liveCall?.error) : void 0
252
+ }
253
+ });
254
+ }
255
+ });
256
+ const pendingInterrupts = interrupts.length > 0;
257
+ const lastTurn = turns.at(-1);
258
+ if (lastTurn) {
259
+ lastTurn.status = runActive ? "streaming" : pendingInterrupts ? "interrupted" : error ? "failed" : "completed";
260
+ if (!runActive && error) lastTurn.error = error;
261
+ }
262
+ return {
263
+ turns,
264
+ interrupts,
265
+ queued: queuedFromEntries(snapshot.queue, messagesKey),
266
+ plan: planFromValues(snapshot.values),
267
+ files: filesFromValues(snapshot.values),
268
+ status: runActive ? "running" : pendingInterrupts ? "interrupted" : error ? "failed" : "idle",
269
+ error
270
+ };
271
+ }
272
+ //#endregion
273
+ export { planItems, toChatThread };
274
+
275
+ //# sourceMappingURL=toChatThread.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toChatThread.js","names":[],"sources":["../../../src/components/ChatThread/toChatThread.ts"],"sourcesContent":["import type { ChatMessageStatus } from '../ChatMessage';\nimport type { ChatPlanItem, ChatPlanItemStatus } from '../ChatPlan';\nimport type { ChatToolCallStatus } from '../ChatToolCall';\nimport type {\n ChatThreadFile,\n ChatThreadInterrupt,\n ChatThreadModel,\n ChatThreadPart,\n ChatThreadQueuedMessage,\n ChatThreadSnapshot,\n ChatThreadSubagent,\n ChatThreadTurn,\n ToChatThreadOptions,\n} from './ChatThread.types';\nimport { parseInterrupt } from './interrupts';\nimport {\n isRecord,\n normalizeMessage,\n type MessageToolCall,\n type NormalizedMessage,\n} from './messages';\n\nconst DEFAULT_SUBAGENT_TOOLS = ['task'];\n\ninterface LiveToolCall {\n status?: string;\n output?: unknown;\n error?: unknown;\n}\n\nfunction readString(value: unknown) {\n return typeof value === 'string' ? value : undefined;\n}\n\nfunction errorMessage(error: unknown) {\n if (error == null) return undefined;\n if (error instanceof Error) return error.message || 'Something went wrong.';\n if (typeof error === 'string') return error;\n if (isRecord(error) && typeof error.message === 'string')\n return error.message;\n return 'Something went wrong.';\n}\n\nfunction toTime(value: unknown) {\n if (value instanceof Date) return value.getTime();\n if (typeof value === 'number') return value;\n if (typeof value === 'string') {\n const time = Date.parse(value);\n return Number.isNaN(time) ? undefined : time;\n }\n return undefined;\n}\n\nfunction liveToolCalls(toolCalls: readonly unknown[] | undefined) {\n const byId = new Map<string, LiveToolCall>();\n for (const call of toolCalls ?? []) {\n if (!isRecord(call)) continue;\n const id = readString(call.callId) ?? readString(call.id);\n if (id) byId.set(id, call);\n }\n return byId;\n}\n\nfunction textFromValue(value: unknown): string | undefined {\n if (typeof value === 'string') return value;\n if (Array.isArray(value)) {\n const text = value\n .map((item) =>\n typeof item === 'string'\n ? item\n : isRecord(item) && typeof item.text === 'string'\n ? item.text\n : ''\n )\n .join('');\n return text || undefined;\n }\n return undefined;\n}\n\nfunction resultValue(\n message: NormalizedMessage | undefined,\n live?: LiveToolCall\n) {\n if (message) {\n const content = isRecord(message.raw) ? message.raw.content : undefined;\n return textFromValue(content) ?? content;\n }\n return live?.output ?? undefined;\n}\n\n/**\n * Merges what the thread knows about a call: a tool result message settles\n * it, then the live tool stream, then whether a pending interrupt or an\n * active run is holding it. A call left without an outcome after the run\n * ends was canceled.\n */\nfunction toolCallStatus({\n result,\n live,\n gated,\n runActive,\n paused,\n}: {\n result?: NormalizedMessage;\n live?: LiveToolCall;\n gated: boolean;\n runActive: boolean;\n /** The run is waiting on an interrupt, so open calls haven't ended. */\n paused: boolean;\n}): ChatToolCallStatus {\n if (result) return result.toolStatus === 'error' ? 'failed' : 'succeeded';\n if (live?.status === 'finished') return 'succeeded';\n if (live?.status === 'error') return 'failed';\n if (gated) return 'input-required';\n if (live?.status === 'running' || runActive) return 'running';\n return paused ? 'pending' : 'canceled';\n}\n\n/** Reads a deep agent's todos, from its state or a `write_todos` call. */\nexport function planItems(todos: unknown): ChatPlanItem[] {\n if (!Array.isArray(todos)) return [];\n return todos.flatMap((todo, index): ChatPlanItem[] => {\n if (!isRecord(todo) || typeof todo.content !== 'string') return [];\n const status: ChatPlanItemStatus =\n todo.status === 'completed'\n ? 'completed'\n : todo.status === 'in_progress' || todo.status === 'in-progress'\n ? 'in-progress'\n : 'pending';\n // Deep agents rewrite the whole list, so position is the stable identity.\n return [{ id: `todo-${index}`, label: todo.content, status }];\n });\n}\n\nfunction planFromValues(values: unknown): ChatPlanItem[] | undefined {\n const items = isRecord(values) ? planItems(values.todos) : [];\n return items.length ? items : undefined;\n}\n\nfunction filesFromValues(values: unknown): ChatThreadFile[] | undefined {\n if (!isRecord(values) || !isRecord(values.files)) return undefined;\n const files = Object.entries(values.files).map(([path, data]) => ({\n path,\n modifiedAt: isRecord(data) ? readString(data.modified_at) : undefined,\n }));\n return files.length ? files : undefined;\n}\n\nfunction queuedFromEntries(\n queue: readonly unknown[] | undefined,\n messagesKey: string\n) {\n return (queue ?? []).flatMap((entry): ChatThreadQueuedMessage[] => {\n if (!isRecord(entry) || typeof entry.id !== 'string') return [];\n const values = isRecord(entry.values) ? entry.values : undefined;\n const input = values?.[messagesKey];\n const messages = Array.isArray(input) ? input : [];\n const last = messages.at(-1);\n const text = last === undefined ? '' : normalizeMessage(last, 0).text;\n return [{ id: entry.id, text }];\n });\n}\n\n/** Matches each approval request, in order, to an open call it gates. */\nfunction anchorInterrupts(\n interrupts: ChatThreadInterrupt[],\n calls: { call: MessageToolCall; settled: boolean }[]\n) {\n const gates = new Map<string, string>();\n for (const interrupt of interrupts) {\n if (interrupt.kind !== 'approval') continue;\n for (const request of interrupt.requests) {\n const open = calls.filter(\n ({ call, settled }) =>\n !settled && call.name === request.name && !gates.has(call.id)\n );\n const exact = open.find(\n ({ call }) => JSON.stringify(call.args) === JSON.stringify(request.args)\n );\n const match = exact ?? open[0];\n if (match) {\n gates.set(match.call.id, interrupt.id);\n request.toolCallId = match.call.id;\n }\n }\n }\n return gates;\n}\n\nfunction subagentModel({\n call,\n status,\n handle,\n}: {\n call: MessageToolCall;\n status: ChatToolCallStatus;\n handle: unknown;\n}): ChatThreadSubagent {\n const args = isRecord(call.args) ? call.args : {};\n const snapshot = isRecord(handle) ? handle : {};\n const startedAt = toTime(snapshot.startedAt);\n const completedAt = toTime(snapshot.completedAt);\n const subagentStatus =\n snapshot.status === 'error'\n ? 'failed'\n : snapshot.status === 'complete' && status === 'running'\n ? 'succeeded'\n : status;\n return {\n id: call.id,\n name:\n readString(args.subagent_type) ??\n readString(args.subagentType) ??\n readString(snapshot.name) ??\n 'subagent',\n task:\n readString(args.description) ??\n readString(snapshot.taskInput) ??\n undefined,\n status: subagentStatus,\n startedAt,\n elapsedMs:\n startedAt !== undefined && completedAt !== undefined\n ? completedAt - startedAt\n : undefined,\n };\n}\n\n/**\n * Turns LangGraph stream state into render-ready chat turns. Pure: it reads\n * plain values, so it works with `@langchain/react` 1.x and 2.0, the 0.3.x\n * hook, recorded fixtures, and tests alike.\n */\nexport function toChatThread(\n snapshot: ChatThreadSnapshot,\n {\n hideMessage,\n messagesKey = 'messages',\n subagentTools = DEFAULT_SUBAGENT_TOOLS,\n }: ToChatThreadOptions = {}\n): ChatThreadModel {\n const runActive = snapshot.isLoading === true;\n const messages = snapshot.messages\n .filter((message) => !hideMessage?.(message))\n .map(normalizeMessage);\n const results = new Map<string, NormalizedMessage>();\n for (const message of messages) {\n if (message.kind === 'tool' && message.toolCallId) {\n results.set(message.toolCallId, message);\n }\n }\n const live = liveToolCalls(snapshot.toolCalls);\n let lastAiIndex = -1;\n let lastHumanIndex = -1;\n messages.forEach((message, index) => {\n if (message.kind === 'ai') lastAiIndex = index;\n if (message.kind === 'human') lastHumanIndex = index;\n });\n // Only the newest turn's open calls can wait on the run or an interrupt;\n // calls left open in earlier turns were canceled.\n const isCurrent = (index: number) => index > lastHumanIndex;\n const interrupts = (snapshot.interrupts ?? []).map(parseInterrupt);\n const gates = anchorInterrupts(\n interrupts,\n messages.flatMap((message, index) =>\n isCurrent(index)\n ? message.toolCalls.map((call) => ({\n call,\n settled: results.has(call.id),\n }))\n : []\n )\n );\n const subagentNames = new Set(subagentTools);\n const error = errorMessage(snapshot.error);\n\n const turns: ChatThreadTurn[] = [];\n messages.forEach((message, index) => {\n if (message.kind === 'human') {\n turns.push({\n id: message.id,\n user: {\n message: {\n id: message.id,\n role: 'user',\n status: 'completed',\n content: [\n {\n id: `${message.id}:text`,\n type: 'text',\n text: message.text,\n appearance: 'bubble',\n },\n ],\n },\n text: message.text,\n raw: message.raw,\n },\n parts: [],\n status: 'completed',\n actionCount: 0,\n });\n return;\n }\n if (message.kind !== 'ai') return;\n if (turns.length === 0) {\n turns.push({\n id: message.id,\n parts: [],\n status: 'completed',\n actionCount: 0,\n });\n }\n const turn = turns[turns.length - 1];\n const latest = runActive && index === lastAiIndex;\n const source = { message: message.raw };\n if (message.reasoning) {\n turn.parts.push({\n type: 'reasoning',\n id: `${message.id}:reasoning`,\n text: message.reasoning,\n streaming: latest && !message.text && message.toolCalls.length === 0,\n source,\n });\n }\n if (message.text) {\n turn.parts.push({\n type: 'text',\n id: `${message.id}:text`,\n text: message.text,\n streaming: latest && message.toolCalls.length === 0,\n source,\n });\n }\n for (const [imageIndex, url] of message.images.entries()) {\n turn.parts.push({\n type: 'image',\n id: `${message.id}:image:${imageIndex}`,\n url,\n source,\n });\n }\n for (const call of message.toolCalls) {\n const result = results.get(call.id);\n const liveCall = live.get(call.id);\n const interruptId = gates.get(call.id);\n const status = toolCallStatus({\n result,\n live: liveCall,\n gated: interruptId !== undefined,\n runActive: runActive && isCurrent(index),\n paused: interrupts.length > 0 && isCurrent(index),\n });\n const value = resultValue(result, liveCall);\n const callSource = { message: message.raw, result: result?.raw };\n turn.actionCount += 1;\n if (subagentNames.has(call.name)) {\n const handle = snapshot.subagents?.get(call.id);\n turn.parts.push({\n type: 'subagent',\n id: call.id,\n subagent: subagentModel({ call, status, handle }),\n result: textFromValue(value),\n handle,\n interruptId,\n source: callSource,\n } satisfies ChatThreadPart);\n continue;\n }\n turn.parts.push({\n type: 'tool-call',\n id: call.id,\n interruptId,\n source: callSource,\n toolCall: {\n id: call.id,\n name: call.name,\n status,\n args: call.args,\n result: status === 'failed' ? undefined : value,\n error:\n status === 'failed'\n ? (value ?? errorMessage(liveCall?.error))\n : undefined,\n },\n });\n }\n });\n\n const pendingInterrupts = interrupts.length > 0;\n const lastTurn = turns.at(-1);\n if (lastTurn) {\n lastTurn.status = runActive\n ? 'streaming'\n : pendingInterrupts\n ? 'interrupted'\n : error\n ? 'failed'\n : 'completed';\n if (!runActive && error) lastTurn.error = error;\n }\n\n return {\n turns,\n interrupts,\n queued: queuedFromEntries(snapshot.queue, messagesKey),\n plan: planFromValues(snapshot.values),\n files: filesFromValues(snapshot.values),\n status: runActive\n ? 'running'\n : pendingInterrupts\n ? 'interrupted'\n : error\n ? 'failed'\n : 'idle',\n error,\n };\n}\n\nexport type { ChatMessageStatus };\n"],"mappings":";;;AAsBA,IAAM,yBAAyB,CAAC,MAAM;AAQtC,SAAS,WAAW,OAAgB;CAClC,OAAO,OAAO,UAAU,WAAW,QAAQ,KAAA;AAC7C;AAEA,SAAS,aAAa,OAAgB;CACpC,IAAI,SAAS,MAAM,OAAO,KAAA;CAC1B,IAAI,iBAAiB,OAAO,OAAO,MAAM,WAAW;CACpD,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,SAAS,KAAK,KAAK,OAAO,MAAM,YAAY,UAC9C,OAAO,MAAM;CACf,OAAO;AACT;AAEA,SAAS,OAAO,OAAgB;CAC9B,IAAI,iBAAiB,MAAM,OAAO,MAAM,QAAQ;CAChD,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,OAAO,UAAU,UAAU;EAC7B,MAAM,OAAO,KAAK,MAAM,KAAK;EAC7B,OAAO,OAAO,MAAM,IAAI,IAAI,KAAA,IAAY;CAC1C;AAEF;AAEA,SAAS,cAAc,WAA2C;CAChE,MAAM,uBAAO,IAAI,IAA0B;CAC3C,KAAK,MAAM,QAAQ,aAAa,CAAC,GAAG;EAClC,IAAI,CAAC,SAAS,IAAI,GAAG;EACrB,MAAM,KAAK,WAAW,KAAK,MAAM,KAAK,WAAW,KAAK,EAAE;EACxD,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI;CAC3B;CACA,OAAO;AACT;AAEA,SAAS,cAAc,OAAoC;CACzD,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,MAAM,QAAQ,KAAK,GAUrB,OATa,MACV,KAAK,SACJ,OAAO,SAAS,WACZ,OAC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AAS,MAAM;EACpC,OAAO,gBAAgB,SAAS,MAAM;EACtC,QAAQ,YACJ,YACA,oBACE,gBACA,QACE,WACA;EACR;CACF;AACF"}
@@ -0,0 +1,36 @@
1
+ import type { ChatThreadActions, ChatThreadController, ChatThreadModel, ChatThreadSelectors, ChatThreadStream, ChatThreadTiming, ChatThreadTurn, ToChatThreadOptions } from './ChatThread.types.js';
2
+ export interface UseLangGraphChatThreadOptions extends ToChatThreadOptions {
3
+ /**
4
+ * Selector hooks from the app's own `@langchain/react` import. Each one
5
+ * turns on a feature: queued messages, edit and retry, and subagent
6
+ * details. Pass a module-level object so it never changes.
7
+ */
8
+ selectors?: ChatThreadSelectors;
9
+ }
10
+ /** A `ChatThreadController` for a LangGraph stream, with every action. */
11
+ export interface LangGraphChatThreadState extends ChatThreadController {
12
+ model: ChatThreadModel;
13
+ actions: ChatThreadActions;
14
+ stream: ChatThreadStream;
15
+ selectors?: ChatThreadSelectors;
16
+ isThreadLoading: boolean;
17
+ stopping: boolean;
18
+ /** When each turn's work started and ended, measured on this client. */
19
+ timings: Readonly<Record<string, ChatThreadTiming>>;
20
+ useForkPoint: (turn: ChatThreadTurn) => unknown;
21
+ }
22
+ /**
23
+ * The default adapter behind `ChatThread`'s `stream` prop: connects a
24
+ * LangGraph `useStream` handle to Macaw chat. Reads the handle structurally, so it works with `@langchain/react` 1.x and 2.0 under any
25
+ * package alias, and with the 0.3.x hook (without selectors).
26
+ */
27
+ export declare function useLangGraphChatThread(stream: ChatThreadStream, { selectors, hideMessage, messagesKey, subagentTools, }?: UseLangGraphChatThreadOptions): LangGraphChatThreadState;
28
+ /**
29
+ * The checkpoint to fork from to edit or retry a message, or undefined when
30
+ * the stream can't fork. Uses `useMessageMetadata` when the app passes it
31
+ * (1.x and 2.0), or the 0.3.x stream's own metadata.
32
+ */
33
+ export declare function useLangGraphForkPoint(thread: Pick<LangGraphChatThreadState, 'stream' | 'selectors'>, message: {
34
+ id: string;
35
+ raw: unknown;
36
+ } | undefined): unknown;