@assistant-ui/react-langchain 0.0.31 → 0.0.32
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/attachSubagentTranscripts.d.ts +14 -6
- package/dist/attachSubagentTranscripts.d.ts.map +1 -1
- package/dist/attachSubagentTranscripts.js +8 -4
- package/dist/attachSubagentTranscripts.js.map +1 -1
- package/dist/convertMessages.d.ts +3 -3
- package/dist/convertMessages.d.ts.map +1 -1
- package/dist/converter.d.ts +9 -10
- package/dist/converter.d.ts.map +1 -1
- package/dist/findForkCheckpointInHistory.d.ts +2 -3
- package/dist/findForkCheckpointInHistory.d.ts.map +1 -1
- package/dist/hooks.d.ts +14 -15
- package/dist/hooks.d.ts.map +1 -1
- package/dist/resolveForkCheckpoint.d.ts +1 -2
- package/dist/resolveForkCheckpoint.d.ts.map +1 -1
- package/dist/runtimeExtras.d.ts +1 -2
- package/dist/runtimeExtras.d.ts.map +1 -1
- package/dist/sdkIdentity.d.ts +1 -2
- package/dist/sdkIdentity.d.ts.map +1 -1
- package/dist/sdkIdentity.js +1 -1
- package/dist/streamingTiming.d.ts +2 -3
- package/dist/streamingTiming.d.ts.map +1 -1
- package/dist/types.d.ts +8 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/uiMessages.d.ts +22 -7
- package/dist/uiMessages.d.ts.map +1 -1
- package/dist/uiMessages.js +23 -5
- package/dist/uiMessages.js.map +1 -1
- package/dist/useStreamRuntime.d.ts +3 -3
- package/dist/useStreamRuntime.d.ts.map +1 -1
- package/dist/useStreamRuntime.js +4 -4
- package/dist/useStreamRuntime.js.map +1 -1
- package/dist/useSubagentTranscripts.d.ts +3 -4
- package/dist/useSubagentTranscripts.d.ts.map +1 -1
- package/dist/useSubagentTranscripts.js +127 -33
- package/dist/useSubagentTranscripts.js.map +1 -1
- package/package.json +12 -11
- package/src/attachSubagentTranscripts.test.ts +13 -5
- package/src/attachSubagentTranscripts.ts +26 -7
- package/src/uiMessages.test.ts +43 -0
- package/src/uiMessages.ts +36 -4
- package/src/useStreamRuntime.test.tsx +112 -0
- package/src/useStreamRuntime.ts +9 -6
- package/src/useSubagentTranscripts.test.tsx +795 -52
- package/src/useSubagentTranscripts.ts +271 -49
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
import { ThreadMessage } from "@assistant-ui/core";
|
|
1
|
+
import { ThreadMessage, ToolCallTiming } from "@assistant-ui/core";
|
|
2
2
|
//#region src/attachSubagentTranscripts.d.ts
|
|
3
|
-
type
|
|
3
|
+
export type SubagentTranscript = {
|
|
4
|
+
readonly messages: readonly ThreadMessage[];
|
|
5
|
+
/**
|
|
6
|
+
* Only present when the client watched the task run: the discovery
|
|
7
|
+
* timestamps are stamped when the task call is first seen, so a thread
|
|
8
|
+
* seeded from a checkpoint would report a duration of zero.
|
|
9
|
+
*/
|
|
10
|
+
readonly timing?: ToolCallTiming;
|
|
11
|
+
};
|
|
12
|
+
type AttachedTranscript = readonly [string, SubagentTranscript];
|
|
4
13
|
type AttachedMessage = {
|
|
5
14
|
transcripts: readonly AttachedTranscript[];
|
|
6
15
|
attached: ThreadMessage;
|
|
7
16
|
};
|
|
8
|
-
type AttachMemo = {
|
|
17
|
+
export type AttachMemo = {
|
|
9
18
|
messages: WeakMap<ThreadMessage, AttachedMessage>;
|
|
10
19
|
results: WeakMap<readonly ThreadMessage[], readonly ThreadMessage[]>;
|
|
11
20
|
};
|
|
12
|
-
declare const createAttachMemo: () => AttachMemo;
|
|
13
|
-
declare const attachSubagentTranscripts: (messages: readonly ThreadMessage[], transcripts: ReadonlyMap<string,
|
|
21
|
+
export declare const createAttachMemo: () => AttachMemo;
|
|
22
|
+
export declare const attachSubagentTranscripts: (messages: readonly ThreadMessage[], transcripts: ReadonlyMap<string, SubagentTranscript>, memo: AttachMemo) => readonly ThreadMessage[];
|
|
14
23
|
//#endregion
|
|
15
|
-
export { AttachMemo, attachSubagentTranscripts, createAttachMemo };
|
|
16
24
|
//# sourceMappingURL=attachSubagentTranscripts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachSubagentTranscripts.d.ts","names":[],"sources":["../src/attachSubagentTranscripts.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"attachSubagentTranscripts.d.ts","names":[],"sources":["../src/attachSubagentTranscripts.ts"],"mappings":";;YAOY;WACD,mBAAmB;;;;;;WAMnB,SAAS;;KAGf,uCAAuC;KAEvC;EACH,sBAAsB;EACtB,UAAU;;YAGA;EACV,UAAU,QAAQ,eAAe;EACjC,SAAS,iBAAiB,0BAA0B;;qBAGzC,wBAAuB;qBAevB,4BACX,mBAAmB,iBACnB,aAAa,oBAAoB,qBACjC,MAAM,wBACI"}
|
|
@@ -15,10 +15,14 @@ const attachSubagentTranscripts = (messages, transcripts, memo) => {
|
|
|
15
15
|
if (cached && sameTranscripts(cached.transcripts, attachedTranscripts)) return cached.attached;
|
|
16
16
|
const attached = {
|
|
17
17
|
...message,
|
|
18
|
-
content: message.content.map((part) =>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
content: message.content.map((part) => {
|
|
19
|
+
const transcript = part.type === "tool-call" ? transcripts.get(part.toolCallId) : void 0;
|
|
20
|
+
return transcript ? {
|
|
21
|
+
...part,
|
|
22
|
+
messages: transcript.messages,
|
|
23
|
+
...transcript.timing && { timing: transcript.timing }
|
|
24
|
+
} : part;
|
|
25
|
+
})
|
|
22
26
|
};
|
|
23
27
|
memo.messages.set(message, {
|
|
24
28
|
transcripts: attachedTranscripts,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachSubagentTranscripts.js","names":[],"sources":["../src/attachSubagentTranscripts.ts"],"sourcesContent":["import {\n bindExternalStoreMessage,\n getExternalStoreMessages,\n type ThreadMessage,\n} from \"@assistant-ui/core\";\n\ntype AttachedTranscript = readonly [string,
|
|
1
|
+
{"version":3,"file":"attachSubagentTranscripts.js","names":[],"sources":["../src/attachSubagentTranscripts.ts"],"sourcesContent":["import {\n bindExternalStoreMessage,\n getExternalStoreMessages,\n type ThreadMessage,\n type ToolCallTiming,\n} from \"@assistant-ui/core\";\n\nexport type SubagentTranscript = {\n readonly messages: readonly ThreadMessage[];\n /**\n * Only present when the client watched the task run: the discovery\n * timestamps are stamped when the task call is first seen, so a thread\n * seeded from a checkpoint would report a duration of zero.\n */\n readonly timing?: ToolCallTiming;\n};\n\ntype AttachedTranscript = readonly [string, SubagentTranscript];\n\ntype AttachedMessage = {\n transcripts: readonly AttachedTranscript[];\n attached: ThreadMessage;\n};\n\nexport type AttachMemo = {\n messages: WeakMap<ThreadMessage, AttachedMessage>;\n results: WeakMap<readonly ThreadMessage[], readonly ThreadMessage[]>;\n};\n\nexport const createAttachMemo = (): AttachMemo => ({\n messages: new WeakMap(),\n results: new WeakMap(),\n});\n\nconst sameTranscripts = (\n a: readonly AttachedTranscript[],\n b: readonly AttachedTranscript[],\n) =>\n a.length === b.length &&\n a.every(\n ([toolCallId, transcript], index) =>\n toolCallId === b[index]![0] && transcript === b[index]![1],\n );\n\nexport const attachSubagentTranscripts = (\n messages: readonly ThreadMessage[],\n transcripts: ReadonlyMap<string, SubagentTranscript>,\n memo: AttachMemo,\n): readonly ThreadMessage[] => {\n let attachedAny = false;\n const next = messages.map((message) => {\n const attachedTranscripts = message.content.flatMap((part) =>\n part.type === \"tool-call\" && transcripts.has(part.toolCallId)\n ? [[part.toolCallId, transcripts.get(part.toolCallId)!] as const]\n : [],\n );\n if (attachedTranscripts.length === 0) return message;\n attachedAny = true;\n\n const cached = memo.messages.get(message);\n if (cached && sameTranscripts(cached.transcripts, attachedTranscripts))\n return cached.attached;\n\n const attached = {\n ...message,\n content: message.content.map((part) => {\n const transcript =\n part.type === \"tool-call\"\n ? transcripts.get(part.toolCallId)\n : undefined;\n return transcript\n ? {\n ...part,\n messages: transcript.messages,\n ...(transcript.timing && { timing: transcript.timing }),\n }\n : part;\n }),\n } as ThreadMessage;\n memo.messages.set(message, { transcripts: attachedTranscripts, attached });\n return attached;\n });\n\n if (!attachedAny) return messages;\n const previous = memo.results.get(messages);\n if (previous && previous.every((message, index) => message === next[index]))\n return previous;\n bindExternalStoreMessage(next, getExternalStoreMessages({ messages }));\n memo.results.set(messages, next);\n return next;\n};\n"],"mappings":";;AA6BA,MAAa,0BAAsC;CACjD,0BAAU,IAAI,QAAQ;CACtB,yBAAS,IAAI,QAAQ;AACvB;AAEA,MAAM,mBACJ,GACA,MAEA,EAAE,WAAW,EAAE,UACf,EAAE,OACC,CAAC,YAAY,aAAa,UACzB,eAAe,EAAE,MAAM,CAAE,MAAM,eAAe,EAAE,MAAM,CAAE,EAC5D;AAEF,MAAa,6BACX,UACA,aACA,SAC6B;CAC7B,IAAI,cAAc;CAClB,MAAM,OAAO,SAAS,KAAK,YAAY;EACrC,MAAM,sBAAsB,QAAQ,QAAQ,SAAS,SACnD,KAAK,SAAS,eAAe,YAAY,IAAI,KAAK,UAAU,IACxD,CAAC,CAAC,KAAK,YAAY,YAAY,IAAI,KAAK,UAAU,CAAE,CAAU,IAC9D,CAAC,CACP;EACA,IAAI,oBAAoB,WAAW,GAAG,OAAO;EAC7C,cAAc;EAEd,MAAM,SAAS,KAAK,SAAS,IAAI,OAAO;EACxC,IAAI,UAAU,gBAAgB,OAAO,aAAa,mBAAmB,GACnE,OAAO,OAAO;EAEhB,MAAM,WAAW;GACf,GAAG;GACH,SAAS,QAAQ,QAAQ,KAAK,SAAS;IACrC,MAAM,aACJ,KAAK,SAAS,cACV,YAAY,IAAI,KAAK,UAAU,IAC/B,KAAA;IACN,OAAO,aACH;KACE,GAAG;KACH,UAAU,WAAW;KACrB,GAAI,WAAW,UAAU,EAAE,QAAQ,WAAW,OAAO;IACvD,IACA;GACN,CAAC;EACH;EACA,KAAK,SAAS,IAAI,SAAS;GAAE,aAAa;GAAqB;EAAS,CAAC;EACzE,OAAO;CACT,CAAC;CAED,IAAI,CAAC,aAAa,OAAO;CACzB,MAAM,WAAW,KAAK,QAAQ,IAAI,QAAQ;CAC1C,IAAI,YAAY,SAAS,OAAO,SAAS,UAAU,YAAY,KAAK,MAAM,GACxE,OAAO;CACT,yBAAyB,MAAM,yBAAyB,EAAE,SAAS,CAAC,CAAC;CACrE,KAAK,QAAQ,IAAI,UAAU,IAAI;CAC/B,OAAO;AACT"}
|
|
@@ -7,8 +7,8 @@ type LangChainMessageConverterMetadata = useExternalMessageConverter.Metadata &
|
|
|
7
7
|
uiMessagesByParent?: Map<string, UIMessage[]>;
|
|
8
8
|
messageTiming?: Record<string, MessageTiming>;
|
|
9
9
|
};
|
|
10
|
-
declare const getMessageType: (message: LangChainBaseMessage) => string;
|
|
11
|
-
declare const convertLangChainBaseMessage: (message: LangChainBaseMessage, metadata?: LangChainMessageConverterMetadata) => useExternalMessageConverter.Message;
|
|
10
|
+
export declare const getMessageType: (message: LangChainBaseMessage) => string;
|
|
11
|
+
export declare const convertLangChainBaseMessage: (message: LangChainBaseMessage, metadata?: LangChainMessageConverterMetadata) => useExternalMessageConverter.Message;
|
|
12
12
|
//#endregion
|
|
13
|
-
export {
|
|
13
|
+
export { getMessageContent };
|
|
14
14
|
//# sourceMappingURL=convertMessages.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertMessages.d.ts","names":[],"sources":["../src/convertMessages.ts"],"mappings":";;;;;KAiBK,oCACH,4BAA4B;EAC1B,qBAAqB,YAAY;EACjC,gBAAgB,eAAe;;
|
|
1
|
+
{"version":3,"file":"convertMessages.d.ts","names":[],"sources":["../src/convertMessages.ts"],"mappings":";;;;;KAiBK,oCACH,4BAA4B;EAC1B,qBAAqB,YAAY;EACjC,gBAAgB,eAAe;;qBAetB,iBAAkB,SAAS;qBAuC3B,8BACX,SAAS,sBACT,WAAU,sCACT,4BAA4B"}
|
package/dist/converter.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { AppendMessage, DataMessagePart, ThreadAssistantMessage, ThreadUserMessa
|
|
|
2
2
|
import { StreamingTimingAccessors } from "@assistant-ui/core/react";
|
|
3
3
|
//#region src/converter.d.ts
|
|
4
4
|
/** Known content block types from @langchain/core messages. */
|
|
5
|
-
type LangChainContentBlock = {
|
|
5
|
+
export type LangChainContentBlock = {
|
|
6
6
|
type: "text";
|
|
7
7
|
text: string;
|
|
8
8
|
} | {
|
|
@@ -56,26 +56,26 @@ type LangChainContentBlock = {
|
|
|
56
56
|
type: "tool_use" | "input_json_delta";
|
|
57
57
|
};
|
|
58
58
|
type ConvertedContentPart = ThreadUserMessage["content"][number] | ThreadAssistantMessage["content"][number];
|
|
59
|
-
declare const convertLangChainContentBlock: (part: LangChainContentBlock) => ConvertedContentPart | null | undefined;
|
|
59
|
+
export declare const convertLangChainContentBlock: (part: LangChainContentBlock) => ConvertedContentPart | null | undefined;
|
|
60
60
|
/**
|
|
61
61
|
* Audio output arrives outside the content array: providers leave `content`
|
|
62
62
|
* empty and put the spoken text in `additional_kwargs.audio.transcript`. The
|
|
63
63
|
* audio bytes stay behind because no provider reports their media type, and a
|
|
64
64
|
* streamed response carries raw PCM rather than a playable file.
|
|
65
65
|
*/
|
|
66
|
-
declare const withAudioTranscript: <T extends {
|
|
66
|
+
export declare const withAudioTranscript: <T extends {
|
|
67
67
|
type: string;
|
|
68
68
|
text?: unknown;
|
|
69
69
|
}>(parts: readonly T[], additionalKwargs: Record<string, unknown> | undefined) => readonly (T | {
|
|
70
70
|
type: "text";
|
|
71
71
|
text: string;
|
|
72
72
|
})[];
|
|
73
|
-
declare const getCustomMetadata: (additionalKwargs: Record<string, unknown> | undefined) => Record<string, unknown>;
|
|
74
|
-
declare const uiMessageToDataPart: <TUIMessage extends {
|
|
73
|
+
export declare const getCustomMetadata: (additionalKwargs: Record<string, unknown> | undefined) => Record<string, unknown>;
|
|
74
|
+
export declare const uiMessageToDataPart: <TUIMessage extends {
|
|
75
75
|
name: string;
|
|
76
76
|
props: Record<string, unknown>;
|
|
77
77
|
}>(ui: TUIMessage) => DataMessagePart;
|
|
78
|
-
declare const getMessageContent: (msg: AppendMessage) => string | ({
|
|
78
|
+
export declare const getMessageContent: (msg: AppendMessage) => string | ({
|
|
79
79
|
type: "text";
|
|
80
80
|
text: string;
|
|
81
81
|
image_url?: never;
|
|
@@ -150,7 +150,7 @@ declare const getMessageContent: (msg: AppendMessage) => string | ({
|
|
|
150
150
|
metadata?: never;
|
|
151
151
|
url?: never;
|
|
152
152
|
})[];
|
|
153
|
-
declare const createLangChainStreamingTimingAccessors: <TMessage extends {
|
|
153
|
+
export declare const createLangChainStreamingTimingAccessors: <TMessage extends {
|
|
154
154
|
id?: string | undefined;
|
|
155
155
|
content?: unknown;
|
|
156
156
|
tool_calls?: readonly unknown[] | undefined;
|
|
@@ -159,7 +159,7 @@ declare const createLangChainStreamingTimingAccessors: <TMessage extends {
|
|
|
159
159
|
* Resolve the assistant message a `UIMessage` belongs to: the parent id comes
|
|
160
160
|
* from `metadata.message_id` (Python SDK) or `metadata.id` (JS SDK).
|
|
161
161
|
*/
|
|
162
|
-
declare const getUIMessageParentId: (ui: {
|
|
162
|
+
export declare const getUIMessageParentId: (ui: {
|
|
163
163
|
metadata?: {
|
|
164
164
|
message_id?: string;
|
|
165
165
|
id?: string;
|
|
@@ -169,12 +169,11 @@ declare const getUIMessageParentId: (ui: {
|
|
|
169
169
|
* Group the graph's accumulated `UIMessage`s by the assistant message they
|
|
170
170
|
* belong to. Non-array state and entries without a parent link are dropped.
|
|
171
171
|
*/
|
|
172
|
-
declare const groupUIMessagesByParent: <T extends {
|
|
172
|
+
export declare const groupUIMessagesByParent: <T extends {
|
|
173
173
|
metadata?: {
|
|
174
174
|
message_id?: string;
|
|
175
175
|
id?: string;
|
|
176
176
|
} | undefined;
|
|
177
177
|
}>(value: unknown) => Map<string, T[]>;
|
|
178
178
|
//#endregion
|
|
179
|
-
export { LangChainContentBlock, convertLangChainContentBlock, createLangChainStreamingTimingAccessors, getCustomMetadata, getMessageContent, getUIMessageParentId, groupUIMessagesByParent, uiMessageToDataPart, withAudioTranscript };
|
|
180
179
|
//# sourceMappingURL=converter.d.ts.map
|
package/dist/converter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"converter.d.ts","names":[],"sources":["../src/converter.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"converter.d.ts","names":[],"sources":["../src/converter.ts"],"mappings":";;;;YAaY;EACN;EAAc;;EACd;EAAoB;;EACpB;EAAmB;IAAsB;;;EACzC;EAAkB;;EAElB;EACA,UAAU;IAAQ;IAAsB;;EACxC;;EAGA;EACA;EACA;EACA;EACA;IAAa;;;EAGb;EACA;EACA;EACA;EACA;IAAa;;;EAGb;EACA;EACA;EACA;EACA;IAAa;;;EAGb;EACA;EACA;EACA;;EAEA;;KAED,uBACD,uCACA;qBAES,+BACX,MAAM,0BACL;;;;;;;qBAqEU,sBAAuB;EAAY;EAAc;GAC5D,gBAAgB,KAChB,kBAAkB,kDACP;EAAM;EAAc;;qBAapB,oBACX,kBAAkB,wCACjB;qBAGU,sBACX;EAAqB;EAAc,OAAO;GAE1C,IAAI,eACH;qBAoBU,oBAAqB,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAuG1B,0CACX;EACE;EACA;EACA;GAGF,UAAU,SAAS,wBAClB,yBAAyB;;;;;qBA+Df,uBAAwB;EACnC;IAAa;IAAqB;;;;;;;qBAOvB,0BACX;EACE;IAAa;IAAqB;;GAGpC,mBACC,YAAY"}
|
|
@@ -11,7 +11,7 @@ type ForkHistoryCursor = {
|
|
|
11
11
|
checkpoint_id: string;
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
|
-
type ForkCheckpointClient = {
|
|
14
|
+
export type ForkCheckpointClient = {
|
|
15
15
|
threads: {
|
|
16
16
|
getHistory: (threadId: string, options?: {
|
|
17
17
|
limit?: number;
|
|
@@ -19,7 +19,6 @@ type ForkCheckpointClient = {
|
|
|
19
19
|
}) => Promise<readonly ForkCheckpointHistoryState[]>;
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
|
-
declare const findForkCheckpointInHistory: (client: ForkCheckpointClient, threadId: string, messagesUpToParent: readonly LangChainBaseMessage[], messagesKey: string, pageSize?: number) => Promise<string | null>;
|
|
22
|
+
export declare const findForkCheckpointInHistory: (client: ForkCheckpointClient, threadId: string, messagesUpToParent: readonly LangChainBaseMessage[], messagesKey: string, pageSize?: number) => Promise<string | null>;
|
|
23
23
|
//#endregion
|
|
24
|
-
export { ForkCheckpointClient, findForkCheckpointInHistory };
|
|
25
24
|
//# sourceMappingURL=findForkCheckpointInHistory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findForkCheckpointInHistory.d.ts","names":[],"sources":["../src/findForkCheckpointInHistory.ts"],"mappings":";;KAEK;EACH,SAAS;EACT;IAAe;;;KAGZ;EAAsB;IAAgB;;;
|
|
1
|
+
{"version":3,"file":"findForkCheckpointInHistory.d.ts","names":[],"sources":["../src/findForkCheckpointInHistory.ts"],"mappings":";;KAEK;EACH,SAAS;EACT;IAAe;;;KAGZ;EAAsB;IAAgB;;;YAE/B;EACV;IACE,aACE,kBACA;MAAY;MAAgB,SAAS;UAClC,iBAAiB;;;qBAIb,8BACX,QAAQ,sBACR,kBACA,6BAA6B,wBAC7B,qBACA,sBACC"}
|
package/dist/hooks.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { AssembledToolCall, SubagentDiscoverySnapshot, SubgraphDiscoverySnapshot
|
|
|
4
4
|
/**
|
|
5
5
|
* Read the current LangGraph interrupt state from the runtime extras.
|
|
6
6
|
*/
|
|
7
|
-
declare const useLangChainInterruptState: () => {
|
|
7
|
+
export declare const useLangChainInterruptState: () => {
|
|
8
8
|
value?: unknown;
|
|
9
9
|
} | undefined;
|
|
10
10
|
/**
|
|
@@ -12,55 +12,55 @@ declare const useLangChainInterruptState: () => {
|
|
|
12
12
|
* and `value`. Defaults to an empty array. Pair with `useLangChainRespondAll`
|
|
13
13
|
* (keyed by interrupt id) to resolve several at once.
|
|
14
14
|
*/
|
|
15
|
-
declare const useLangChainInterrupts: () => readonly {
|
|
15
|
+
export declare const useLangChainInterrupts: () => readonly {
|
|
16
16
|
id?: string;
|
|
17
17
|
value?: unknown;
|
|
18
18
|
}[];
|
|
19
19
|
/** Read the last run/hydration error from the runtime extras. */
|
|
20
|
-
declare const useLangChainError: () => unknown;
|
|
20
|
+
export declare const useLangChainError: () => unknown;
|
|
21
21
|
/**
|
|
22
22
|
* Read the root tool calls assembled by `useStream` from the `tools`
|
|
23
23
|
* channel. Defaults to an empty array, so consumers can `.map` without
|
|
24
24
|
* a guard. Useful for rendering pending/streamed tool calls and
|
|
25
25
|
* approval UIs.
|
|
26
26
|
*/
|
|
27
|
-
declare const useLangChainToolCalls: () => readonly AssembledToolCall<string, unknown, unknown>[];
|
|
27
|
+
export declare const useLangChainToolCalls: () => readonly AssembledToolCall<string, unknown, unknown>[];
|
|
28
28
|
/** Subagents discovered on the current run (multi-agent graphs). */
|
|
29
|
-
declare const useLangChainSubagents: () => ReadonlyMap<string, SubagentDiscoverySnapshot>;
|
|
29
|
+
export declare const useLangChainSubagents: () => ReadonlyMap<string, SubagentDiscoverySnapshot>;
|
|
30
30
|
/** Subgraphs discovered on the current run. */
|
|
31
|
-
declare const useLangChainSubgraphs: () => ReadonlyMap<string, SubgraphDiscoverySnapshot>;
|
|
31
|
+
export declare const useLangChainSubgraphs: () => ReadonlyMap<string, SubgraphDiscoverySnapshot>;
|
|
32
32
|
/**
|
|
33
33
|
* The underlying `useStream` handle, for advanced views — pass it to v1's
|
|
34
34
|
* `useMessages(stream, target)` / `useToolCalls(stream, target)` with a
|
|
35
35
|
* subagent/subgraph from `useLangChainSubagents` / `useLangChainSubgraphs`.
|
|
36
36
|
* `undefined` outside the runtime provider.
|
|
37
37
|
*/
|
|
38
|
-
declare const useLangChainStream: () => import("@langchain/react").AnyStream | undefined;
|
|
38
|
+
export declare const useLangChainStream: () => import("@langchain/react").AnyStream | undefined;
|
|
39
39
|
/**
|
|
40
40
|
* Returns a function to submit raw state updates to the LangGraph agent,
|
|
41
41
|
* bypassing the normal message flow. Useful for sending interrupt resume
|
|
42
42
|
* commands.
|
|
43
43
|
*/
|
|
44
|
-
declare const useLangChainSubmit: () => (values: Record<string, unknown> | null | undefined, options?: Record<string, unknown>) => Promise<void>;
|
|
44
|
+
export declare const useLangChainSubmit: () => (values: Record<string, unknown> | null | undefined, options?: Record<string, unknown>) => Promise<void>;
|
|
45
45
|
/**
|
|
46
46
|
* Resume a LangGraph interrupt with a response payload via
|
|
47
47
|
* `useStream().respond`. Preferred over `useLangChainSendCommand`; it
|
|
48
48
|
* carries the response cleanly and handles interrupt namespaces.
|
|
49
49
|
*/
|
|
50
|
-
declare const useLangChainRespond: () => (response: unknown, options?: Record<string, unknown>) => Promise<void>;
|
|
50
|
+
export declare const useLangChainRespond: () => (response: unknown, options?: Record<string, unknown>) => Promise<void>;
|
|
51
51
|
/**
|
|
52
52
|
* Resume several LangGraph interrupts pending at the same checkpoint in
|
|
53
53
|
* one run via `useStream().respondAll`. Use when a run pauses on multiple
|
|
54
54
|
* interrupts at once; sequential `useLangChainRespond` calls can't service
|
|
55
55
|
* them (the first resume starts a run, stranding the rest).
|
|
56
56
|
*/
|
|
57
|
-
declare const useLangChainRespondAll: () => (responsesById: Record<string, unknown>, options?: Record<string, unknown>) => Promise<void>;
|
|
57
|
+
export declare const useLangChainRespondAll: () => (responsesById: Record<string, unknown>, options?: Record<string, unknown>) => Promise<void>;
|
|
58
58
|
/**
|
|
59
59
|
* Submit a list of LangChain-shaped messages on the current thread.
|
|
60
60
|
* Parity helper for migrating from `useLangGraphSend`. Routes to
|
|
61
61
|
* `useStream().submit({ [messagesKey]: messages }, options)`.
|
|
62
62
|
*/
|
|
63
|
-
declare const useLangChainSend: () => (messages: readonly LangChainBaseMessage[], options?: Record<string, unknown>) => Promise<void>;
|
|
63
|
+
export declare const useLangChainSend: () => (messages: readonly LangChainBaseMessage[], options?: Record<string, unknown>) => Promise<void>;
|
|
64
64
|
/**
|
|
65
65
|
* Submit a `useStream` command (e.g. interrupt resume). Parity helper
|
|
66
66
|
* for migrating from `useLangGraphSendCommand`. Note that v1's command
|
|
@@ -68,7 +68,7 @@ declare const useLangChainSend: () => (messages: readonly LangChainBaseMessage[]
|
|
|
68
68
|
* `{ resume: string }` form; to carry a payload, use the input or
|
|
69
69
|
* `stream.respond` instead.
|
|
70
70
|
*/
|
|
71
|
-
declare const useLangChainSendCommand: () => (command: Record<string, unknown>) => Promise<void>;
|
|
71
|
+
export declare const useLangChainSendCommand: () => (command: Record<string, unknown>) => Promise<void>;
|
|
72
72
|
/**
|
|
73
73
|
* Read a custom LangGraph state key from the current thread. Mirrors
|
|
74
74
|
* `useStream().values[key]` from `@langchain/react` and updates when the
|
|
@@ -80,8 +80,7 @@ declare const useLangChainSendCommand: () => (command: Record<string, unknown>)
|
|
|
80
80
|
* const files = useLangChainState<Record<string, string>>("files", {});
|
|
81
81
|
* ```
|
|
82
82
|
*/
|
|
83
|
-
declare function useLangChainState<T>(key: string): T | undefined;
|
|
84
|
-
declare function useLangChainState<T>(key: string, defaultValue: T): T;
|
|
83
|
+
export declare function useLangChainState<T>(key: string): T | undefined;
|
|
84
|
+
export declare function useLangChainState<T>(key: string, defaultValue: T): T;
|
|
85
85
|
//#endregion
|
|
86
|
-
export { useLangChainError, useLangChainInterruptState, useLangChainInterrupts, useLangChainRespond, useLangChainRespondAll, useLangChainSend, useLangChainSendCommand, useLangChainState, useLangChainStream, useLangChainSubagents, useLangChainSubgraphs, useLangChainSubmit, useLangChainToolCalls };
|
|
87
86
|
//# sourceMappingURL=hooks.d.ts.map
|
package/dist/hooks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","names":[],"sources":["../src/hooks.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","names":[],"sources":["../src/hooks.ts"],"mappings":";;;;;;qBAwBa;EAAA;;;;;;;qBAQA;EAAA;EAAA;;;qBAOA;;;;;;;qBASA,sCAAqB;;qBAIrB,6BAAqB,oBAAA;;qBAIrB,6BAAqB,oBAAA;;;;;;;qBASrB,qDAAkB;;;;;;qBAQlB,2BAGT,QAAQ,4CACR,UAAU,4BAAuB;;;;;;qBASxB,4BAEH,mBAAmB,UAAU,4BAAuB;;;;;;;qBAUjD,+BAGT,eAAe,yBACf,UAAU,4BAAuB;;;;;;qBASxB,yBAGT,mBAAmB,wBACnB,UAAU,4BAAuB;;;;;;;;qBAcxB,gCAEH,SAAS,4BAAuB;;;;;;;;;;;;wBAc1B,kBAAkB,GAAG,cAAc;wBACnC,kBAAkB,GAAG,aAAa,cAAc,IAAI"}
|
|
@@ -10,7 +10,6 @@ type MessageMetadataSnapshot = ReadonlyMap<string, {
|
|
|
10
10
|
* server history by message id. A `null` `parentId` edits the first human
|
|
11
11
|
* message and forks from the thread's initial (empty-message) checkpoint.
|
|
12
12
|
*/
|
|
13
|
-
declare const resolveForkCheckpoint: (client: ForkCheckpointClient, threadId: string, messages: readonly LangChainBaseMessage[], parentId: string | null, sourceId: string | null | undefined, metadata: MessageMetadataSnapshot, messagesKey: string) => Promise<string | null>;
|
|
13
|
+
export declare const resolveForkCheckpoint: (client: ForkCheckpointClient, threadId: string, messages: readonly LangChainBaseMessage[], parentId: string | null, sourceId: string | null | undefined, metadata: MessageMetadataSnapshot, messagesKey: string) => Promise<string | null>;
|
|
14
14
|
//#endregion
|
|
15
|
-
export { resolveForkCheckpoint };
|
|
16
15
|
//# sourceMappingURL=resolveForkCheckpoint.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveForkCheckpoint.d.ts","names":[],"sources":["../src/resolveForkCheckpoint.ts"],"mappings":";;;KAMK,0BACD;WAA+B;;;;;;;;
|
|
1
|
+
{"version":3,"file":"resolveForkCheckpoint.d.ts","names":[],"sources":["../src/resolveForkCheckpoint.ts"],"mappings":";;;KAMK,0BACD;WAA+B;;;;;;;;qBAStB,wBACX,QAAQ,sBACR,kBACA,mBAAmB,wBACnB,yBACA,qCACA,UAAU,yBACV,wBACC"}
|
package/dist/runtimeExtras.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { LangChainRuntimeExtras } from "./types.js";
|
|
2
2
|
//#region src/runtimeExtras.d.ts
|
|
3
|
-
declare const langChainExtras: import("@assistant-ui/core/react").RuntimeExtras<LangChainRuntimeExtras>;
|
|
3
|
+
export declare const langChainExtras: import("@assistant-ui/core/react").RuntimeExtras<LangChainRuntimeExtras>;
|
|
4
4
|
//#endregion
|
|
5
|
-
export { langChainExtras };
|
|
6
5
|
//# sourceMappingURL=runtimeExtras.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtimeExtras.d.ts","names":[],"sources":["../src/runtimeExtras.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"runtimeExtras.d.ts","names":[],"sources":["../src/runtimeExtras.ts"],"mappings":";;qBAGa,oDAAe,cAAA"}
|
package/dist/sdkIdentity.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdkIdentity.d.ts","names":[],"sources":["../src/sdkIdentity.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"sdkIdentity.d.ts","names":[],"sources":["../src/sdkIdentity.ts"],"mappings":";;qBAEa,eAAe"}
|
package/dist/sdkIdentity.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { LangChainBaseMessage } from "./types.js";
|
|
2
2
|
import { MessageTiming } from "@assistant-ui/core";
|
|
3
3
|
//#region src/streamingTiming.d.ts
|
|
4
|
-
declare const langChainStreamingTimingAccessors: import("@assistant-ui/core").StreamingTimingAccessors<LangChainBaseMessage>;
|
|
4
|
+
export declare const langChainStreamingTimingAccessors: import("@assistant-ui/core").StreamingTimingAccessors<LangChainBaseMessage>;
|
|
5
5
|
/**
|
|
6
6
|
* Tracks per-message streaming timing for LangChain messages. Delegates to
|
|
7
7
|
* the shared `useStreamingTiming` primitive in `@assistant-ui/core/react`,
|
|
8
8
|
* adapted to the `LangChainBaseMessage` shape (`_getType() -> "ai"`, content
|
|
9
9
|
* blocks including text/thinking/reasoning, `tool_calls`).
|
|
10
10
|
*/
|
|
11
|
-
declare const useLangChainStreamingTiming: (messages: readonly LangChainBaseMessage[], isRunning: boolean) => Record<string, MessageTiming>;
|
|
11
|
+
export declare const useLangChainStreamingTiming: (messages: readonly LangChainBaseMessage[], isRunning: boolean) => Record<string, MessageTiming>;
|
|
12
12
|
//#endregion
|
|
13
|
-
export { langChainStreamingTimingAccessors, useLangChainStreamingTiming };
|
|
14
13
|
//# sourceMappingURL=streamingTiming.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streamingTiming.d.ts","names":[],"sources":["../src/streamingTiming.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"streamingTiming.d.ts","names":[],"sources":["../src/streamingTiming.ts"],"mappings":";;;qBAQa,gEAAiC,yBAAA;;;;;;;qBASjC,8BACX,mBAAmB,wBACnB,uBACC,eAAe"}
|
package/dist/types.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { AttachmentAdapter, DictationAdapter, ExternalStoreSharedOptions, Feedba
|
|
|
3
3
|
import { AnyStream, AssembledToolCall, SubagentDiscoverySnapshot, SubgraphDiscoverySnapshot, UseStreamOptions } from "@langchain/react";
|
|
4
4
|
import { AssistantCloud } from "assistant-cloud";
|
|
5
5
|
//#region src/types.d.ts
|
|
6
|
-
type LangChainToolCall = {
|
|
6
|
+
export type LangChainToolCall = {
|
|
7
7
|
id: string;
|
|
8
8
|
name: string;
|
|
9
9
|
args: Record<string, unknown>;
|
|
@@ -15,7 +15,7 @@ type LangChainToolCall = {
|
|
|
15
15
|
* The parent assistant message is carried in `metadata.message_id` by the
|
|
16
16
|
* Python SDK and in `metadata.id` by the JS SDK; the runtime reads either.
|
|
17
17
|
*/
|
|
18
|
-
type UIMessage<TName extends string = string, TProps extends Record<string, unknown> = Record<string, unknown>> = {
|
|
18
|
+
export type UIMessage<TName extends string = string, TProps extends Record<string, unknown> = Record<string, unknown>> = {
|
|
19
19
|
type: "ui";
|
|
20
20
|
id: string;
|
|
21
21
|
name: TName;
|
|
@@ -34,7 +34,7 @@ type UIMessage<TName extends string = string, TProps extends Record<string, unkn
|
|
|
34
34
|
* Emitted on the live `custom` channel by the graph's `remove_ui_message`
|
|
35
35
|
* helper to drop a pushed `UIMessage` by id.
|
|
36
36
|
*/
|
|
37
|
-
type RemoveUIMessage = {
|
|
37
|
+
export type RemoveUIMessage = {
|
|
38
38
|
type: "remove-ui";
|
|
39
39
|
id: string;
|
|
40
40
|
};
|
|
@@ -45,7 +45,7 @@ type RemoveUIMessage = {
|
|
|
45
45
|
* Uses `unknown` for `content` to remain compatible with
|
|
46
46
|
* `@langchain/core`'s `MessageContent` union.
|
|
47
47
|
*/
|
|
48
|
-
type LangChainBaseMessage = {
|
|
48
|
+
export type LangChainBaseMessage = {
|
|
49
49
|
_getType: () => string;
|
|
50
50
|
content: unknown;
|
|
51
51
|
id?: string | undefined;
|
|
@@ -60,7 +60,7 @@ type LangChainBaseMessage = {
|
|
|
60
60
|
/** Present on ToolMessage */
|
|
61
61
|
artifact?: unknown;
|
|
62
62
|
};
|
|
63
|
-
type LangChainRuntimeExtras = {
|
|
63
|
+
export type LangChainRuntimeExtras = {
|
|
64
64
|
interrupt: {
|
|
65
65
|
value?: unknown;
|
|
66
66
|
} | undefined;
|
|
@@ -79,7 +79,7 @@ type LangChainRuntimeExtras = {
|
|
|
79
79
|
values: Record<string, unknown>;
|
|
80
80
|
messagesKey: string;
|
|
81
81
|
};
|
|
82
|
-
type LangChainRuntimeExtraOptions = ExternalStoreSharedOptions & {
|
|
82
|
+
export type LangChainRuntimeExtraOptions = ExternalStoreSharedOptions & {
|
|
83
83
|
/**
|
|
84
84
|
* Called whenever the active thread's canonical (remote) ID changes, so the
|
|
85
85
|
* value can be treated as a managed/controlled variable (e.g. synced to a URL
|
|
@@ -128,7 +128,7 @@ type LangChainRuntimeExtraOptions = ExternalStoreSharedOptions & {
|
|
|
128
128
|
*/
|
|
129
129
|
uiStateKey?: string | undefined;
|
|
130
130
|
};
|
|
131
|
-
type UseStreamRuntimeOptions = UseStreamOptions extends (infer O) ? O extends UseStreamOptions ? O & LangChainRuntimeExtraOptions : never : never;
|
|
131
|
+
export type UseStreamRuntimeOptions = UseStreamOptions extends (infer O) ? O extends UseStreamOptions ? O & LangChainRuntimeExtraOptions : never : never;
|
|
132
132
|
//#endregion
|
|
133
|
-
export {
|
|
133
|
+
export type { LangChainContentBlock };
|
|
134
134
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;YAqBY;EACV;EACA;EACA,MAAM;;;;;;;;;YAUI,UACV,+BACA,eAAe,0BAA0B;EAEzC;EACA;EACA,MAAM;EACN,OAAO;EACP;IACE;IACA;IACA;IACA;IACA;IACA;KACC;;;;;;;YAQO;EACV;EACA;;;;;;;;;YAUU;EACV;EACA;EACA;EACA;EACA,oBAAoB;;EAEpB,sBAAsB;;EAEtB;;EAEA,SAAS;;EAET;;YAGU;EACV;IAAa;;EACb;IAAuB;IAAa;;EACpC,oBAAoB;EACpB,WAAW,oBAAoB;EAC/B,WAAW,oBAAoB;EAC/B,QAAQ;EACR;EACA,SACE,QAAQ,4CACR,UAAU,4BACP;EACL,UACE,mBACA,UAAU,4BACP;EACL,aACE,eAAe,yBACf,UAAU,4BACP;EACL,QAAQ;EACR;;YAGU,+BAA+B;;;;;;;;;EASzC,qBAAqB;EACrB,QAAQ;EACR;IAEM,cAAc;IACd,SAAS;IACT,YAAY;IACZ,QAAQ;IACR,WAAW;;;;;;;;EASjB;;;;;EAKA;;;;;EAKA,6BAA6B;;EAE7B,gBAAgB;IAAU;;;EAE1B,WAAW,qBAAqB;;;;;;;EAOhC;;YAOU,0BAA0B,gCAA+B,KACjE,UAAU,mBACR,IAAI"}
|
package/dist/uiMessages.d.ts
CHANGED
|
@@ -1,15 +1,31 @@
|
|
|
1
1
|
import { RemoveUIMessage, UIMessage } from "./types.js";
|
|
2
|
+
import { Channel } from "@langchain/react";
|
|
2
3
|
//#region src/uiMessages.d.ts
|
|
3
|
-
|
|
4
|
-
declare const
|
|
5
|
-
|
|
4
|
+
/** Channels the generative-UI fold reads, at the root and per subagent. */
|
|
5
|
+
export declare const UI_CUSTOM_CHANNELS: readonly Channel[];
|
|
6
|
+
export type UIUpdate = UIMessage | RemoveUIMessage;
|
|
7
|
+
export declare const isUIUpdate: (value: unknown) => value is UIUpdate | readonly UIUpdate[];
|
|
8
|
+
export declare const applyUIUpdate: (list: readonly UIMessage[], update: UIUpdate | readonly UIUpdate[]) => UIMessage[];
|
|
6
9
|
/**
|
|
7
10
|
* Pulls a UI update out of a raw `custom`-channel event. The graph writes the
|
|
8
11
|
* `UIMessage` straight to the channel, so it lands at `params.data`; some
|
|
9
12
|
* transports wrap it one level deeper at `params.data.payload`.
|
|
10
13
|
*/
|
|
11
|
-
declare const extractUIUpdate: (event: unknown) => UIUpdate | readonly UIUpdate[] | undefined;
|
|
12
|
-
|
|
14
|
+
export declare const extractUIUpdate: (event: unknown) => UIUpdate | readonly UIUpdate[] | undefined;
|
|
15
|
+
export type UIFoldMemo = {
|
|
16
|
+
events: readonly unknown[];
|
|
17
|
+
messages: UIMessage[];
|
|
18
|
+
};
|
|
19
|
+
export declare const createUIFoldMemo: () => UIFoldMemo;
|
|
20
|
+
/**
|
|
21
|
+
* Folds `custom`-channel events into UI messages, continuing the fold held in
|
|
22
|
+
* `memo`. The channel buffer holds each event object once, appends new events
|
|
23
|
+
* and drops its oldest ones once full, so only events after the previously
|
|
24
|
+
* folded last event are applied, and entries no later event touches keep
|
|
25
|
+
* their identity. A buffer that no longer contains that event was replaced
|
|
26
|
+
* and is folded from scratch.
|
|
27
|
+
*/
|
|
28
|
+
export declare const foldUIUpdates: (events: readonly unknown[], memo?: UIFoldMemo) => UIMessage[];
|
|
13
29
|
/**
|
|
14
30
|
* Merges live-streamed UI with the state snapshot. The snapshot is
|
|
15
31
|
* authoritative by id: once a UI lands in graph state it supersedes its live
|
|
@@ -17,7 +33,6 @@ declare const foldUIUpdates: (events: readonly unknown[]) => UIMessage[];
|
|
|
17
33
|
* snapshot still contains that id; the removal only takes visible effect once
|
|
18
34
|
* the snapshot catches up.
|
|
19
35
|
*/
|
|
20
|
-
declare const mergeUIMessages: (live: readonly UIMessage[], snapshot: unknown) => UIMessage[];
|
|
36
|
+
export declare const mergeUIMessages: (live: readonly UIMessage[], snapshot: unknown) => UIMessage[];
|
|
21
37
|
//#endregion
|
|
22
|
-
export { UIUpdate, applyUIUpdate, extractUIUpdate, foldUIUpdates, isUIUpdate, mergeUIMessages };
|
|
23
38
|
//# sourceMappingURL=uiMessages.d.ts.map
|
package/dist/uiMessages.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uiMessages.d.ts","names":[],"sources":["../src/uiMessages.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"uiMessages.d.ts","names":[],"sources":["../src/uiMessages.ts"],"mappings":";;;;qBAIa,6BAA6B;YAE9B,WAAW,YAAY;qBAEtB,aACX,mBACC,SAAS,oBAAoB;qBAmBnB,gBACX,eAAe,aACf,QAAQ,oBAAoB,eAC3B;;;;;;qBA0BU,kBACX,mBACC,oBAAoB;YAQX;EACV;EACA,UAAU;;qBAGC,wBAAuB;;;;;;;;;qBAavB,gBACX,4BACA,OAAM,eACL;;;;;;;;qBAuBU,kBACX,eAAe,aACf,sBACC"}
|
package/dist/uiMessages.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
//#region src/uiMessages.ts
|
|
2
|
+
/** Channels the generative-UI fold reads, at the root and per subagent. */
|
|
3
|
+
const UI_CUSTOM_CHANNELS = ["custom"];
|
|
2
4
|
const isUIUpdate = (value) => {
|
|
3
5
|
if (Array.isArray(value)) return value.length > 0 && value.every(isUIUpdate);
|
|
4
6
|
if (value == null || typeof value !== "object") return false;
|
|
@@ -41,12 +43,28 @@ const extractUIUpdate = (event) => {
|
|
|
41
43
|
const payload = data?.payload;
|
|
42
44
|
if (isUIUpdate(payload)) return payload;
|
|
43
45
|
};
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
const createUIFoldMemo = () => ({
|
|
47
|
+
events: [],
|
|
48
|
+
messages: []
|
|
49
|
+
});
|
|
50
|
+
/**
|
|
51
|
+
* Folds `custom`-channel events into UI messages, continuing the fold held in
|
|
52
|
+
* `memo`. The channel buffer holds each event object once, appends new events
|
|
53
|
+
* and drops its oldest ones once full, so only events after the previously
|
|
54
|
+
* folded last event are applied, and entries no later event touches keep
|
|
55
|
+
* their identity. A buffer that no longer contains that event was replaced
|
|
56
|
+
* and is folded from scratch.
|
|
57
|
+
*/
|
|
58
|
+
const foldUIUpdates = (events, memo = createUIFoldMemo()) => {
|
|
59
|
+
const previous = memo.events;
|
|
60
|
+
const resumeAt = previous.length === 0 ? 0 : events.lastIndexOf(previous.at(-1), previous.length - 1) + 1;
|
|
61
|
+
let acc = previous.length > 0 && resumeAt === 0 ? [] : memo.messages;
|
|
62
|
+
for (let i = resumeAt; i < events.length; i++) {
|
|
63
|
+
const update = extractUIUpdate(events[i]);
|
|
48
64
|
if (update) acc = applyUIUpdate(acc, update);
|
|
49
65
|
}
|
|
66
|
+
memo.events = events;
|
|
67
|
+
memo.messages = acc;
|
|
50
68
|
return acc;
|
|
51
69
|
};
|
|
52
70
|
/**
|
|
@@ -63,6 +81,6 @@ const mergeUIMessages = (live, snapshot) => {
|
|
|
63
81
|
return [...byId.values()];
|
|
64
82
|
};
|
|
65
83
|
//#endregion
|
|
66
|
-
export { applyUIUpdate, extractUIUpdate, foldUIUpdates, isUIUpdate, mergeUIMessages };
|
|
84
|
+
export { UI_CUSTOM_CHANNELS, applyUIUpdate, createUIFoldMemo, extractUIUpdate, foldUIUpdates, isUIUpdate, mergeUIMessages };
|
|
67
85
|
|
|
68
86
|
//# sourceMappingURL=uiMessages.js.map
|
package/dist/uiMessages.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uiMessages.js","names":[],"sources":["../src/uiMessages.ts"],"sourcesContent":["import type { RemoveUIMessage, UIMessage } from \"./types\";\n\nexport type UIUpdate = UIMessage | RemoveUIMessage;\n\nexport const isUIUpdate = (\n value: unknown,\n): value is UIUpdate | readonly UIUpdate[] => {\n if (Array.isArray(value)) return value.length > 0 && value.every(isUIUpdate);\n if (value == null || typeof value !== \"object\") return false;\n const v = value as {\n type?: unknown;\n id?: unknown;\n name?: unknown;\n props?: unknown;\n };\n if (typeof v.id !== \"string\") return false;\n if (v.type === \"remove-ui\") return true;\n return (\n v.type === \"ui\" &&\n typeof v.name === \"string\" &&\n typeof v.props === \"object\" &&\n v.props !== null\n );\n};\n\nexport const applyUIUpdate = (\n list: readonly UIMessage[],\n update: UIUpdate | readonly UIUpdate[],\n): UIMessage[] => {\n const events = Array.isArray(update) ? update : [update as UIUpdate];\n let next = list.slice();\n for (const event of events) {\n if (event.type === \"remove-ui\") {\n next = next.filter((ui) => ui.id !== event.id);\n continue;\n }\n const index = next.findIndex((ui) => ui.id === event.id);\n if (index === -1) {\n next.push(event);\n continue;\n }\n next[index] =\n event.metadata?.merge === true\n ? { ...event, props: { ...next[index]!.props, ...event.props } }\n : event;\n }\n return next;\n};\n\n/**\n * Pulls a UI update out of a raw `custom`-channel event. The graph writes the\n * `UIMessage` straight to the channel, so it lands at `params.data`; some\n * transports wrap it one level deeper at `params.data.payload`.\n */\nexport const extractUIUpdate = (\n event: unknown,\n): UIUpdate | readonly UIUpdate[] | undefined => {\n const data = (event as { params?: { data?: unknown } } | null)?.params?.data;\n if (isUIUpdate(data)) return data;\n const payload = (data as { payload?: unknown } | undefined)?.payload;\n if (isUIUpdate(payload)) return payload;\n return undefined;\n};\n\nexport const foldUIUpdates = (events: readonly unknown[]): UIMessage[] => {\n let acc
|
|
1
|
+
{"version":3,"file":"uiMessages.js","names":[],"sources":["../src/uiMessages.ts"],"sourcesContent":["import type { Channel } from \"@langchain/react\";\nimport type { RemoveUIMessage, UIMessage } from \"./types\";\n\n/** Channels the generative-UI fold reads, at the root and per subagent. */\nexport const UI_CUSTOM_CHANNELS: readonly Channel[] = [\"custom\"];\n\nexport type UIUpdate = UIMessage | RemoveUIMessage;\n\nexport const isUIUpdate = (\n value: unknown,\n): value is UIUpdate | readonly UIUpdate[] => {\n if (Array.isArray(value)) return value.length > 0 && value.every(isUIUpdate);\n if (value == null || typeof value !== \"object\") return false;\n const v = value as {\n type?: unknown;\n id?: unknown;\n name?: unknown;\n props?: unknown;\n };\n if (typeof v.id !== \"string\") return false;\n if (v.type === \"remove-ui\") return true;\n return (\n v.type === \"ui\" &&\n typeof v.name === \"string\" &&\n typeof v.props === \"object\" &&\n v.props !== null\n );\n};\n\nexport const applyUIUpdate = (\n list: readonly UIMessage[],\n update: UIUpdate | readonly UIUpdate[],\n): UIMessage[] => {\n const events = Array.isArray(update) ? update : [update as UIUpdate];\n let next = list.slice();\n for (const event of events) {\n if (event.type === \"remove-ui\") {\n next = next.filter((ui) => ui.id !== event.id);\n continue;\n }\n const index = next.findIndex((ui) => ui.id === event.id);\n if (index === -1) {\n next.push(event);\n continue;\n }\n next[index] =\n event.metadata?.merge === true\n ? { ...event, props: { ...next[index]!.props, ...event.props } }\n : event;\n }\n return next;\n};\n\n/**\n * Pulls a UI update out of a raw `custom`-channel event. The graph writes the\n * `UIMessage` straight to the channel, so it lands at `params.data`; some\n * transports wrap it one level deeper at `params.data.payload`.\n */\nexport const extractUIUpdate = (\n event: unknown,\n): UIUpdate | readonly UIUpdate[] | undefined => {\n const data = (event as { params?: { data?: unknown } } | null)?.params?.data;\n if (isUIUpdate(data)) return data;\n const payload = (data as { payload?: unknown } | undefined)?.payload;\n if (isUIUpdate(payload)) return payload;\n return undefined;\n};\n\nexport type UIFoldMemo = {\n events: readonly unknown[];\n messages: UIMessage[];\n};\n\nexport const createUIFoldMemo = (): UIFoldMemo => ({\n events: [],\n messages: [],\n});\n\n/**\n * Folds `custom`-channel events into UI messages, continuing the fold held in\n * `memo`. The channel buffer holds each event object once, appends new events\n * and drops its oldest ones once full, so only events after the previously\n * folded last event are applied, and entries no later event touches keep\n * their identity. A buffer that no longer contains that event was replaced\n * and is folded from scratch.\n */\nexport const foldUIUpdates = (\n events: readonly unknown[],\n memo: UIFoldMemo = createUIFoldMemo(),\n): UIMessage[] => {\n const previous = memo.events;\n const resumeAt =\n previous.length === 0\n ? 0\n : events.lastIndexOf(previous.at(-1), previous.length - 1) + 1;\n let acc = previous.length > 0 && resumeAt === 0 ? [] : memo.messages;\n for (let i = resumeAt; i < events.length; i++) {\n const update = extractUIUpdate(events[i]);\n if (update) acc = applyUIUpdate(acc, update);\n }\n memo.events = events;\n memo.messages = acc;\n return acc;\n};\n\n/**\n * Merges live-streamed UI with the state snapshot. The snapshot is\n * authoritative by id: once a UI lands in graph state it supersedes its live\n * copy. A consequence is that a live `remove-ui` is overridden while the\n * snapshot still contains that id; the removal only takes visible effect once\n * the snapshot catches up.\n */\nexport const mergeUIMessages = (\n live: readonly UIMessage[],\n snapshot: unknown,\n): UIMessage[] => {\n const byId = new Map<string, UIMessage>();\n for (const ui of live) byId.set(ui.id, ui);\n if (Array.isArray(snapshot)) {\n for (const ui of snapshot as UIMessage[]) byId.set(ui.id, ui);\n }\n return [...byId.values()];\n};\n"],"mappings":";;AAIA,MAAa,qBAAyC,CAAC,QAAQ;AAI/D,MAAa,cACX,UAC4C;CAC5C,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,MAAM,SAAS,KAAK,MAAM,MAAM,UAAU;CAC3E,IAAI,SAAS,QAAQ,OAAO,UAAU,UAAU,OAAO;CACvD,MAAM,IAAI;CAMV,IAAI,OAAO,EAAE,OAAO,UAAU,OAAO;CACrC,IAAI,EAAE,SAAS,aAAa,OAAO;CACnC,OACE,EAAE,SAAS,QACX,OAAO,EAAE,SAAS,YAClB,OAAO,EAAE,UAAU,YACnB,EAAE,UAAU;AAEhB;AAEA,MAAa,iBACX,MACA,WACgB;CAChB,MAAM,SAAS,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAkB;CACnE,IAAI,OAAO,KAAK,MAAM;CACtB,KAAK,MAAM,SAAS,QAAQ;EAC1B,IAAI,MAAM,SAAS,aAAa;GAC9B,OAAO,KAAK,QAAQ,OAAO,GAAG,OAAO,MAAM,EAAE;GAC7C;EACF;EACA,MAAM,QAAQ,KAAK,WAAW,OAAO,GAAG,OAAO,MAAM,EAAE;EACvD,IAAI,UAAU,IAAI;GAChB,KAAK,KAAK,KAAK;GACf;EACF;EACA,KAAK,SACH,MAAM,UAAU,UAAU,OACtB;GAAE,GAAG;GAAO,OAAO;IAAE,GAAG,KAAK,MAAM,CAAE;IAAO,GAAG,MAAM;GAAM;EAAE,IAC7D;CACR;CACA,OAAO;AACT;;;;;;AAOA,MAAa,mBACX,UAC+C;CAC/C,MAAM,OAAQ,OAAkD,QAAQ;CACxE,IAAI,WAAW,IAAI,GAAG,OAAO;CAC7B,MAAM,UAAW,MAA4C;CAC7D,IAAI,WAAW,OAAO,GAAG,OAAO;AAElC;AAOA,MAAa,0BAAsC;CACjD,QAAQ,CAAC;CACT,UAAU,CAAC;AACb;;;;;;;;;AAUA,MAAa,iBACX,QACA,OAAmB,iBAAiB,MACpB;CAChB,MAAM,WAAW,KAAK;CACtB,MAAM,WACJ,SAAS,WAAW,IAChB,IACA,OAAO,YAAY,SAAS,GAAG,EAAE,GAAG,SAAS,SAAS,CAAC,IAAI;CACjE,IAAI,MAAM,SAAS,SAAS,KAAK,aAAa,IAAI,CAAC,IAAI,KAAK;CAC5D,KAAK,IAAI,IAAI,UAAU,IAAI,OAAO,QAAQ,KAAK;EAC7C,MAAM,SAAS,gBAAgB,OAAO,EAAE;EACxC,IAAI,QAAQ,MAAM,cAAc,KAAK,MAAM;CAC7C;CACA,KAAK,SAAS;CACd,KAAK,WAAW;CAChB,OAAO;AACT;;;;;;;;AASA,MAAa,mBACX,MACA,aACgB;CAChB,MAAM,uBAAO,IAAI,IAAuB;CACxC,KAAK,MAAM,MAAM,MAAM,KAAK,IAAI,GAAG,IAAI,EAAE;CACzC,IAAI,MAAM,QAAQ,QAAQ,GACxB,KAAK,MAAM,MAAM,UAAyB,KAAK,IAAI,GAAG,IAAI,EAAE;CAE9D,OAAO,CAAC,GAAG,KAAK,OAAO,CAAC;AAC1B"}
|
|
@@ -3,7 +3,7 @@ import { groupUIMessagesByParent } from "./converter.js";
|
|
|
3
3
|
import { UseStreamRuntimeOptions } from "./types.js";
|
|
4
4
|
import { AppendMessage } from "@assistant-ui/core";
|
|
5
5
|
//#region src/useStreamRuntime.d.ts
|
|
6
|
-
declare const runConfigToSubmitOptions: (runConfig: AppendMessage["runConfig"]) => {
|
|
6
|
+
export declare const runConfigToSubmitOptions: (runConfig: AppendMessage["runConfig"]) => {
|
|
7
7
|
config: {
|
|
8
8
|
configurable: Record<string, unknown>;
|
|
9
9
|
};
|
|
@@ -32,7 +32,7 @@ declare const runConfigToSubmitOptions: (runConfig: AppendMessage["runConfig"])
|
|
|
32
32
|
* }
|
|
33
33
|
* ```
|
|
34
34
|
*/
|
|
35
|
-
declare const useStreamRuntime: (rawOptions: UseStreamRuntimeOptions) => import("@assistant-ui/core").AssistantRuntime;
|
|
35
|
+
export declare const useStreamRuntime: (rawOptions: UseStreamRuntimeOptions) => import("@assistant-ui/core").AssistantRuntime;
|
|
36
36
|
//#endregion
|
|
37
|
-
export { groupUIMessagesByParent
|
|
37
|
+
export { groupUIMessagesByParent };
|
|
38
38
|
//# sourceMappingURL=useStreamRuntime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStreamRuntime.d.ts","names":[],"sources":["../src/useStreamRuntime.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"useStreamRuntime.d.ts","names":[],"sources":["../src/useStreamRuntime.ts"],"mappings":";;;;qBA4Da,2BACX,WAAW;;kBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAukBA,mBAAoB,YAAY,yDAAuB"}
|