@assistant-ui/react-langchain 0.0.32 → 0.0.33
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 +13 -14
- package/dist/attachSubagentTranscripts.d.ts.map +1 -1
- package/dist/convertMessages.d.ts +6 -9
- package/dist/convertMessages.d.ts.map +1 -1
- package/dist/convertMessages.js +53 -15
- package/dist/convertMessages.js.map +1 -1
- package/dist/converter.d.ts +128 -128
- package/dist/converter.d.ts.map +1 -1
- package/dist/converter.js +2 -1
- package/dist/converter.js.map +1 -1
- package/dist/findForkCheckpointInHistory.d.ts +15 -16
- package/dist/findForkCheckpointInHistory.d.ts.map +1 -1
- package/dist/hooks.d.ts +5 -7
- package/dist/hooks.d.ts.map +1 -1
- package/dist/index.d.ts +7 -8
- package/dist/index.d.ts.map +1 -0
- package/dist/resolveForkCheckpoint.d.ts +4 -5
- package/dist/resolveForkCheckpoint.d.ts.map +1 -1
- package/dist/runtimeExtras.d.ts +1 -3
- package/dist/runtimeExtras.d.ts.map +1 -1
- package/dist/sdkIdentity.d.ts +1 -3
- package/dist/sdkIdentity.d.ts.map +1 -1
- package/dist/sdkIdentity.js +1 -1
- package/dist/streamingTiming.d.ts +2 -4
- package/dist/streamingTiming.d.ts.map +1 -1
- package/dist/subagentMessagesProjection.d.ts +17 -0
- package/dist/subagentMessagesProjection.d.ts.map +1 -0
- package/dist/subagentMessagesProjection.js +40 -0
- package/dist/subagentMessagesProjection.js.map +1 -0
- package/dist/types.d.ts +100 -103
- package/dist/types.d.ts.map +1 -1
- package/dist/uiMessages.d.ts +18 -6
- package/dist/uiMessages.d.ts.map +1 -1
- package/dist/uiMessages.js +33 -1
- package/dist/uiMessages.js.map +1 -1
- package/dist/useStreamRuntime.d.ts +7 -10
- package/dist/useStreamRuntime.d.ts.map +1 -1
- package/dist/useStreamRuntime.js +99 -25
- package/dist/useStreamRuntime.js.map +1 -1
- package/dist/useSubagentTranscripts.d.ts +3 -5
- package/dist/useSubagentTranscripts.d.ts.map +1 -1
- package/dist/useSubagentTranscripts.js +3 -2
- package/dist/useSubagentTranscripts.js.map +1 -1
- package/package.json +9 -5
- package/src/convertMessages.test.ts +69 -0
- package/src/convertMessages.ts +46 -8
- package/src/converter.ts +6 -0
- package/src/subagentMessagesProjection.test.ts +175 -0
- package/src/subagentMessagesProjection.ts +50 -0
- package/src/uiMessages.test.ts +106 -0
- package/src/uiMessages.ts +43 -0
- package/src/useStreamRuntime.test.tsx +100 -0
- package/src/useStreamRuntime.ts +193 -44
- package/src/useStreamRuntime.voice.test.tsx +712 -0
- package/src/useSubagentTranscripts.ts +3 -6
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import { LangChainBaseMessage } from "./types.js";
|
|
2
|
-
//#region src/findForkCheckpointInHistory.d.ts
|
|
1
|
+
import type { LangChainBaseMessage } from "./types.js";
|
|
3
2
|
type ForkCheckpointHistoryState = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
values?: Record<string, unknown> | undefined;
|
|
4
|
+
checkpoint?: {
|
|
5
|
+
checkpoint_id?: string | null | undefined;
|
|
6
|
+
} | undefined;
|
|
8
7
|
};
|
|
9
8
|
type ForkHistoryCursor = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
configurable: {
|
|
10
|
+
checkpoint_id: string;
|
|
11
|
+
};
|
|
13
12
|
};
|
|
14
13
|
export type ForkCheckpointClient = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
threads: {
|
|
15
|
+
getHistory: (threadId: string, options?: {
|
|
16
|
+
limit?: number;
|
|
17
|
+
before?: ForkHistoryCursor;
|
|
18
|
+
}) => Promise<readonly ForkCheckpointHistoryState[]>;
|
|
19
|
+
};
|
|
21
20
|
};
|
|
22
21
|
export declare const findForkCheckpointInHistory: (client: ForkCheckpointClient, threadId: string, messagesUpToParent: readonly LangChainBaseMessage[], messagesKey: string, pageSize?: number) => Promise<string | null>;
|
|
23
|
-
|
|
22
|
+
export {};
|
|
24
23
|
//# sourceMappingURL=findForkCheckpointInHistory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findForkCheckpointInHistory.d.ts","
|
|
1
|
+
{"version":3,"file":"findForkCheckpointInHistory.d.ts","sourceRoot":"","sources":["../src/findForkCheckpointInHistory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAgB;AAEpD,KAAK,0BAA0B,GAAG;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAC7C,UAAU,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;KAAE,GAAG,SAAS,CAAC;CACxE,CAAC;AAEF,KAAK,iBAAiB,GAAG;IAAE,YAAY,EAAE;QAAE,aAAa,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC;AAErE,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE;QACP,UAAU,EAAE,CACV,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;YAAE,KAAK,CAAC,EAAE,MAAM,CAAC;YAAC,MAAM,CAAC,EAAE,iBAAiB,CAAA;SAAE,KACrD,OAAO,CAAC,SAAS,0BAA0B,EAAE,CAAC,CAAC;KACrD,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,2BAA2B,GACtC,QAAQ,oBAAoB,EAC5B,UAAU,MAAM,EAChB,oBAAoB,SAAS,oBAAoB,EAAE,EACnD,aAAa,MAAM,EACnB,iBAAc,KACb,OAAO,CAAC,MAAM,GAAG,IAAI,CA2CvB,CAAC"}
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
//#region src/hooks.d.ts
|
|
1
|
+
import type { AssembledToolCall, SubagentDiscoverySnapshot, SubgraphDiscoverySnapshot } from "@langchain/react";
|
|
2
|
+
import type { LangChainBaseMessage } from "./types.js";
|
|
4
3
|
/**
|
|
5
4
|
* Read the current LangGraph interrupt state from the runtime extras.
|
|
6
5
|
*/
|
|
7
6
|
export declare const useLangChainInterruptState: () => {
|
|
8
|
-
|
|
7
|
+
value?: unknown;
|
|
9
8
|
} | undefined;
|
|
10
9
|
/**
|
|
11
10
|
* Read every interrupt pending at the current checkpoint, each with `id`
|
|
@@ -13,8 +12,8 @@ export declare const useLangChainInterruptState: () => {
|
|
|
13
12
|
* (keyed by interrupt id) to resolve several at once.
|
|
14
13
|
*/
|
|
15
14
|
export declare const useLangChainInterrupts: () => readonly {
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
id?: string;
|
|
16
|
+
value?: unknown;
|
|
18
17
|
}[];
|
|
19
18
|
/** Read the last run/hydration error from the runtime extras. */
|
|
20
19
|
export declare const useLangChainError: () => unknown;
|
|
@@ -82,5 +81,4 @@ export declare const useLangChainSendCommand: () => (command: Record<string, unk
|
|
|
82
81
|
*/
|
|
83
82
|
export declare function useLangChainState<T>(key: string): T | undefined;
|
|
84
83
|
export declare function useLangChainState<T>(key: string, defaultValue: T): T;
|
|
85
|
-
//#endregion
|
|
86
84
|
//# sourceMappingURL=hooks.d.ts.map
|
package/dist/hooks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,iBAAiB,EACjB,yBAAyB,EACzB,yBAAyB,EAC1B,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAgB;AAYpD;;GAEG;AACH,eAAO,MAAM,0BAA0B;;aACa,CAAC;AAErD;;;;GAI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AC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export { type LangChainBaseMessage, type LangChainContentBlock, type LangChainToolCall, type RemoveUIMessage, type SubagentDiscoverySnapshot, type SubgraphDiscoverySnapshot, type UIMessage, type UseStreamRuntimeOptions, convertLangChainBaseMessage, useLangChainError, useLangChainInterruptState, useLangChainInterrupts, useLangChainRespond, useLangChainRespondAll, useLangChainSend, useLangChainSendCommand, useLangChainState, useLangChainStream, useLangChainStreamingTiming, useLangChainSubagents, useLangChainSubgraphs, useLangChainSubmit, useLangChainToolCalls, useStreamRuntime };
|
|
1
|
+
export { useStreamRuntime } from "./useStreamRuntime.js";
|
|
2
|
+
export { useLangChainError, useLangChainInterrupts, useLangChainInterruptState, useLangChainRespond, useLangChainRespondAll, useLangChainSend, useLangChainSendCommand, useLangChainState, useLangChainStream, useLangChainSubagents, useLangChainSubgraphs, useLangChainSubmit, useLangChainToolCalls, } from "./hooks.js";
|
|
3
|
+
export { convertLangChainBaseMessage } from "./convertMessages.js";
|
|
4
|
+
export { useLangChainStreamingTiming } from "./streamingTiming.js";
|
|
5
|
+
export type { SubagentDiscoverySnapshot, SubgraphDiscoverySnapshot, } from "@langchain/react";
|
|
6
|
+
export type { LangChainBaseMessage, LangChainContentBlock, LangChainToolCall, RemoveUIMessage, UIMessage, UseStreamRuntimeOptions, } from "./types.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,8BAA2B;AAEtD,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,0BAA0B,EAC1B,mBAAmB,EACnB,sBAAsB,EACtB,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,qBAAqB,GACtB,mBAAgB;AAEjB,OAAO,EAAE,2BAA2B,EAAE,6BAA0B;AAChE,OAAO,EAAE,2BAA2B,EAAE,6BAA0B;AAEhE,YAAY,EACV,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EACV,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,SAAS,EACT,uBAAuB,GACxB,mBAAgB"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { LangChainBaseMessage } from "./types.js";
|
|
2
|
-
import { ForkCheckpointClient } from "./findForkCheckpointInHistory.js";
|
|
3
|
-
//#region src/resolveForkCheckpoint.d.ts
|
|
1
|
+
import type { LangChainBaseMessage } from "./types.js";
|
|
2
|
+
import { type ForkCheckpointClient } from "./findForkCheckpointInHistory.js";
|
|
4
3
|
type MessageMetadataSnapshot = ReadonlyMap<string, {
|
|
5
|
-
|
|
4
|
+
readonly parentCheckpointId: string | undefined;
|
|
6
5
|
}> | undefined;
|
|
7
6
|
/**
|
|
8
7
|
* Hydration seeds every message with the head's parent checkpoint, so only the
|
|
@@ -11,5 +10,5 @@ type MessageMetadataSnapshot = ReadonlyMap<string, {
|
|
|
11
10
|
* message and forks from the thread's initial (empty-message) checkpoint.
|
|
12
11
|
*/
|
|
13
12
|
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
|
-
|
|
13
|
+
export {};
|
|
15
14
|
//# sourceMappingURL=resolveForkCheckpoint.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveForkCheckpoint.d.ts","
|
|
1
|
+
{"version":3,"file":"resolveForkCheckpoint.d.ts","sourceRoot":"","sources":["../src/resolveForkCheckpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAgB;AACpD,OAAO,EAEL,KAAK,oBAAoB,EAC1B,yCAAsC;AAEvC,KAAK,uBAAuB,GACxB,WAAW,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC,GACxE,SAAS,CAAC;AAEd;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAChC,QAAQ,oBAAoB,EAC5B,UAAU,MAAM,EAChB,UAAU,SAAS,oBAAoB,EAAE,EACzC,UAAU,MAAM,GAAG,IAAI,EACvB,UAAU,MAAM,GAAG,IAAI,GAAG,SAAS,EACnC,UAAU,uBAAuB,EACjC,aAAa,MAAM,KAClB,OAAO,CAAC,MAAM,GAAG,IAAI,CAwBvB,CAAC"}
|
package/dist/runtimeExtras.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { LangChainRuntimeExtras } from "./types.js";
|
|
2
|
-
//#region src/runtimeExtras.d.ts
|
|
1
|
+
import type { LangChainRuntimeExtras } from "./types.js";
|
|
3
2
|
export declare const langChainExtras: import("@assistant-ui/core/react").RuntimeExtras<LangChainRuntimeExtras>;
|
|
4
|
-
//#endregion
|
|
5
3
|
//# sourceMappingURL=runtimeExtras.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtimeExtras.d.ts","
|
|
1
|
+
{"version":3,"file":"runtimeExtras.d.ts","sourceRoot":"","sources":["../src/runtimeExtras.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,mBAAgB;AAEtD,eAAO,MAAM,eAAe,0EACqC,CAAC"}
|
package/dist/sdkIdentity.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdkIdentity.d.ts","
|
|
1
|
+
{"version":3,"file":"sdkIdentity.d.ts","sourceRoot":"","sources":["../src/sdkIdentity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,eAAO,MAAM,aAAa,EAAE,WAM3B,CAAC"}
|
package/dist/sdkIdentity.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
//#region src/streamingTiming.d.ts
|
|
1
|
+
import type { MessageTiming } from "@assistant-ui/core";
|
|
2
|
+
import type { LangChainBaseMessage } from "./types.js";
|
|
4
3
|
export declare const langChainStreamingTimingAccessors: import("@assistant-ui/core").StreamingTimingAccessors<LangChainBaseMessage>;
|
|
5
4
|
/**
|
|
6
5
|
* Tracks per-message streaming timing for LangChain messages. Delegates to
|
|
@@ -9,5 +8,4 @@ export declare const langChainStreamingTimingAccessors: import("@assistant-ui/co
|
|
|
9
8
|
* blocks including text/thinking/reasoning, `tool_calls`).
|
|
10
9
|
*/
|
|
11
10
|
export declare const useLangChainStreamingTiming: (messages: readonly LangChainBaseMessage[], isRunning: boolean) => Record<string, MessageTiming>;
|
|
12
|
-
//#endregion
|
|
13
11
|
//# sourceMappingURL=streamingTiming.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streamingTiming.d.ts","
|
|
1
|
+
{"version":3,"file":"streamingTiming.d.ts","sourceRoot":"","sources":["../src/streamingTiming.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAIxD,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAgB;AAEpD,eAAO,MAAM,iCAAiC,6EACiC,CAAC;AAEhF;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,GACtC,UAAU,SAAS,oBAAoB,EAAE,EACzC,WAAW,OAAO,KACjB,MAAM,CAAC,MAAM,EAAE,aAAa,CAC6C,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { BaseMessage } from "@langchain/core/messages";
|
|
2
|
+
import { type ProjectionSpec } from "@langchain/langgraph-sdk/stream";
|
|
3
|
+
type MessagesProjection = ProjectionSpec<BaseMessage[]>;
|
|
4
|
+
/**
|
|
5
|
+
* The SDK's messages projection subscribes at the protocol's default depth
|
|
6
|
+
* of 1 and applies every delivered event, so a nested subagent's `values`
|
|
7
|
+
* snapshots rebuild its parent's store from the child's state while the child
|
|
8
|
+
* runs. The projection exposes no depth option, so this spec opens it against
|
|
9
|
+
* a thread whose subscription is pinned to depth 0: the namespace the SDK
|
|
10
|
+
* sets stays and only events at exactly that namespace are delivered, the
|
|
11
|
+
* rule the SDK's root projection already applies. The client unions every
|
|
12
|
+
* subscription's depth into the server filter, so a depth 0 subscription
|
|
13
|
+
* narrows nothing for other consumers.
|
|
14
|
+
*/
|
|
15
|
+
export declare const subagentMessagesProjection: (namespace: readonly string[]) => MessagesProjection;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=subagentMessagesProjection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subagentMessagesProjection.d.ts","sourceRoot":"","sources":["../src/subagentMessagesProjection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,iCAAiC,CAAC;AAEzC,KAAK,kBAAkB,GAAG,cAAc,CAAC,WAAW,EAAE,CAAC,CAAC;AAgBxD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,0BAA0B,GACrC,WAAW,SAAS,MAAM,EAAE,KAC3B,kBAcF,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { messagesProjection } from "@langchain/langgraph-sdk/stream";
|
|
2
|
+
//#region src/subagentMessagesProjection.ts
|
|
3
|
+
const exactDepthThread = (thread) => new Proxy(thread, { get(target, property) {
|
|
4
|
+
if (property === "subscribe") return (...[params]) => target.subscribe({
|
|
5
|
+
...params,
|
|
6
|
+
depth: 0
|
|
7
|
+
});
|
|
8
|
+
const value = Reflect.get(target, property, target);
|
|
9
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
10
|
+
} });
|
|
11
|
+
/**
|
|
12
|
+
* The SDK's messages projection subscribes at the protocol's default depth
|
|
13
|
+
* of 1 and applies every delivered event, so a nested subagent's `values`
|
|
14
|
+
* snapshots rebuild its parent's store from the child's state while the child
|
|
15
|
+
* runs. The projection exposes no depth option, so this spec opens it against
|
|
16
|
+
* a thread whose subscription is pinned to depth 0: the namespace the SDK
|
|
17
|
+
* sets stays and only events at exactly that namespace are delivered, the
|
|
18
|
+
* rule the SDK's root projection already applies. The client unions every
|
|
19
|
+
* subscription's depth into the server filter, so a depth 0 subscription
|
|
20
|
+
* narrows nothing for other consumers.
|
|
21
|
+
*/
|
|
22
|
+
const subagentMessagesProjection = (namespace) => {
|
|
23
|
+
const projection = messagesProjection(namespace);
|
|
24
|
+
return {
|
|
25
|
+
key: `exact|${projection.key}`,
|
|
26
|
+
namespace: projection.namespace,
|
|
27
|
+
initial: projection.initial,
|
|
28
|
+
open({ thread, store, rootBus }) {
|
|
29
|
+
return projection.open({
|
|
30
|
+
thread: exactDepthThread(thread),
|
|
31
|
+
store,
|
|
32
|
+
rootBus
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
//#endregion
|
|
38
|
+
export { subagentMessagesProjection };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=subagentMessagesProjection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subagentMessagesProjection.js","names":[],"sources":["../src/subagentMessagesProjection.ts"],"sourcesContent":["import type { BaseMessage } from \"@langchain/core/messages\";\nimport {\n messagesProjection,\n type ProjectionSpec,\n} from \"@langchain/langgraph-sdk/stream\";\n\ntype MessagesProjection = ProjectionSpec<BaseMessage[]>;\n\ntype ProjectionThread = Parameters<MessagesProjection[\"open\"]>[0][\"thread\"];\n\nconst exactDepthThread = (thread: ProjectionThread): ProjectionThread =>\n new Proxy(thread, {\n get(target, property) {\n if (property === \"subscribe\") {\n return (...[params]: Parameters<ProjectionThread[\"subscribe\"]>) =>\n target.subscribe({ ...params, depth: 0 });\n }\n const value = Reflect.get(target, property, target);\n return typeof value === \"function\" ? value.bind(target) : value;\n },\n });\n\n/**\n * The SDK's messages projection subscribes at the protocol's default depth\n * of 1 and applies every delivered event, so a nested subagent's `values`\n * snapshots rebuild its parent's store from the child's state while the child\n * runs. The projection exposes no depth option, so this spec opens it against\n * a thread whose subscription is pinned to depth 0: the namespace the SDK\n * sets stays and only events at exactly that namespace are delivered, the\n * rule the SDK's root projection already applies. The client unions every\n * subscription's depth into the server filter, so a depth 0 subscription\n * narrows nothing for other consumers.\n */\nexport const subagentMessagesProjection = (\n namespace: readonly string[],\n): MessagesProjection => {\n const projection = messagesProjection(namespace);\n return {\n key: `exact|${projection.key}`,\n namespace: projection.namespace,\n initial: projection.initial,\n open({ thread, store, rootBus }) {\n return projection.open({\n thread: exactDepthThread(thread),\n store,\n rootBus,\n });\n },\n };\n};\n"],"mappings":";;AAUA,MAAM,oBAAoB,WACxB,IAAI,MAAM,QAAQ,EAChB,IAAI,QAAQ,UAAU;CACpB,IAAI,aAAa,aACf,QAAQ,GAAG,CAAC,YACV,OAAO,UAAU;EAAE,GAAG;EAAQ,OAAO;CAAE,CAAC;CAE5C,MAAM,QAAQ,QAAQ,IAAI,QAAQ,UAAU,MAAM;CAClD,OAAO,OAAO,UAAU,aAAa,MAAM,KAAK,MAAM,IAAI;AAC5D,EACF,CAAC;;;;;;;;;;;;AAaH,MAAa,8BACX,cACuB;CACvB,MAAM,aAAa,mBAAmB,SAAS;CAC/C,OAAO;EACL,KAAK,SAAS,WAAW;EACzB,WAAW,WAAW;EACtB,SAAS,WAAW;EACpB,KAAK,EAAE,QAAQ,OAAO,WAAW;GAC/B,OAAO,WAAW,KAAK;IACrB,QAAQ,iBAAiB,MAAM;IAC/B;IACA;GACF,CAAC;EACH;CACF;AACF"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
//#region src/types.d.ts
|
|
1
|
+
import type { AttachmentAdapter, DictationAdapter, ExternalStoreSharedOptions, FeedbackAdapter, MessageStatus, RealtimeVoiceAdapter, RemoteThreadListAdapter, SpeechSynthesisAdapter } from "@assistant-ui/core";
|
|
2
|
+
import type { AssistantCloud } from "assistant-cloud";
|
|
3
|
+
import type { UseStreamOptions, AssembledToolCall, AnyStream, SubagentDiscoverySnapshot, SubgraphDiscoverySnapshot } from "@langchain/react";
|
|
4
|
+
export type { LangChainContentBlock } from "./converter.js";
|
|
6
5
|
export type LangChainToolCall = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
args: Record<string, unknown>;
|
|
10
9
|
};
|
|
11
10
|
/**
|
|
12
11
|
* A generative UI component the graph accumulates in its state. Read from
|
|
@@ -16,27 +15,27 @@ export type LangChainToolCall = {
|
|
|
16
15
|
* Python SDK and in `metadata.id` by the JS SDK; the runtime reads either.
|
|
17
16
|
*/
|
|
18
17
|
export type UIMessage<TName extends string = string, TProps extends Record<string, unknown> = Record<string, unknown>> = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
18
|
+
type: "ui";
|
|
19
|
+
id: string;
|
|
20
|
+
name: TName;
|
|
21
|
+
props: TProps;
|
|
22
|
+
metadata?: {
|
|
23
|
+
merge?: boolean;
|
|
24
|
+
run_id?: string;
|
|
25
|
+
name?: string;
|
|
26
|
+
tags?: string[];
|
|
27
|
+
message_id?: string;
|
|
28
|
+
id?: string;
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
};
|
|
32
31
|
};
|
|
33
32
|
/**
|
|
34
33
|
* Emitted on the live `custom` channel by the graph's `remove_ui_message`
|
|
35
34
|
* helper to drop a pushed `UIMessage` by id.
|
|
36
35
|
*/
|
|
37
36
|
export type RemoveUIMessage = {
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
type: "remove-ui";
|
|
38
|
+
id: string;
|
|
40
39
|
};
|
|
41
40
|
/**
|
|
42
41
|
* Minimal duck-typed interface for BaseMessage class instances returned by
|
|
@@ -46,89 +45,87 @@ export type RemoveUIMessage = {
|
|
|
46
45
|
* `@langchain/core`'s `MessageContent` union.
|
|
47
46
|
*/
|
|
48
47
|
export type LangChainBaseMessage = {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
48
|
+
_getType: () => string;
|
|
49
|
+
content: unknown;
|
|
50
|
+
id?: string | undefined;
|
|
51
|
+
name?: string | undefined;
|
|
52
|
+
additional_kwargs?: Record<string, unknown> | undefined;
|
|
53
|
+
/** Present on AIMessage */
|
|
54
|
+
tool_calls?: readonly LangChainToolCall[] | undefined;
|
|
55
|
+
/** Present on ToolMessage */
|
|
56
|
+
tool_call_id?: string | undefined;
|
|
57
|
+
/** Completion status (AIMessage) or outcome status (ToolMessage) */
|
|
58
|
+
status?: MessageStatus | "success" | "error" | undefined;
|
|
59
|
+
/** Present on ToolMessage */
|
|
60
|
+
artifact?: unknown;
|
|
62
61
|
};
|
|
63
62
|
export type LangChainRuntimeExtras = {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
63
|
+
interrupt: {
|
|
64
|
+
value?: unknown;
|
|
65
|
+
} | undefined;
|
|
66
|
+
interrupts: readonly {
|
|
67
|
+
id?: string;
|
|
68
|
+
value?: unknown;
|
|
69
|
+
}[];
|
|
70
|
+
toolCalls: readonly AssembledToolCall[];
|
|
71
|
+
subagents: ReadonlyMap<string, SubagentDiscoverySnapshot>;
|
|
72
|
+
subgraphs: ReadonlyMap<string, SubgraphDiscoverySnapshot>;
|
|
73
|
+
stream: AnyStream;
|
|
74
|
+
error: unknown;
|
|
75
|
+
submit: (values: Record<string, unknown> | null | undefined, options?: Record<string, unknown>) => Promise<void>;
|
|
76
|
+
respond: (response: unknown, options?: Record<string, unknown>) => Promise<void>;
|
|
77
|
+
respondAll: (responsesById: Record<string, unknown>, options?: Record<string, unknown>) => Promise<void>;
|
|
78
|
+
values: Record<string, unknown>;
|
|
79
|
+
messagesKey: string;
|
|
81
80
|
};
|
|
82
81
|
export type LangChainRuntimeExtraOptions = ExternalStoreSharedOptions & {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Called whenever the active thread's canonical (remote) ID changes, so the
|
|
84
|
+
* value can be treated as a managed/controlled variable (e.g. synced to a URL
|
|
85
|
+
* query param). Only the settled remote ID is emitted: while a freshly created
|
|
86
|
+
* thread is still optimistic the value is `undefined`, and the real ID is
|
|
87
|
+
* emitted once the thread is initialized; the transient local ID is never
|
|
88
|
+
* surfaced.
|
|
89
|
+
*/
|
|
90
|
+
onThreadIdChange?: ((threadId: string | undefined) => void) | undefined;
|
|
91
|
+
cloud?: AssistantCloud | undefined;
|
|
92
|
+
adapters?: {
|
|
93
|
+
attachments?: AttachmentAdapter | undefined;
|
|
94
|
+
speech?: SpeechSynthesisAdapter | undefined;
|
|
95
|
+
dictation?: DictationAdapter | undefined;
|
|
96
|
+
voice?: RealtimeVoiceAdapter | undefined;
|
|
97
|
+
feedback?: FeedbackAdapter | undefined;
|
|
98
|
+
} | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* When the user sends a new message while previous tool calls are
|
|
101
|
+
* still pending, automatically submit `tool` messages that cancel
|
|
102
|
+
* them so the agent's tool-call accounting stays consistent.
|
|
103
|
+
* Defaults to `true`.
|
|
104
|
+
*/
|
|
105
|
+
autoCancelPendingToolCalls?: boolean | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* Routes the Cancel button's click to `useStream().stop()`. On by
|
|
108
|
+
* default. Pass `false` to disable the Cancel button.
|
|
109
|
+
*/
|
|
110
|
+
unstable_allowCancellation?: boolean | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* Custom `RemoteThreadListAdapter`. When provided, replaces the
|
|
113
|
+
* cloud-backed thread list adapter.
|
|
114
|
+
*/
|
|
115
|
+
unstable_threadListAdapter?: RemoteThreadListAdapter | undefined;
|
|
116
|
+
/** Custom thread-creation hook, forwarded to the cloud adapter. */
|
|
117
|
+
create?: (() => Promise<{
|
|
118
|
+
externalId: string | undefined;
|
|
119
|
+
}>) | undefined;
|
|
120
|
+
/** Custom thread-deletion hook, forwarded to the cloud adapter. */
|
|
121
|
+
delete?: ((threadId: string) => Promise<void>) | undefined;
|
|
122
|
+
/**
|
|
123
|
+
* State key the graph accumulates generative `UIMessage`s under. Each UI
|
|
124
|
+
* is attached to the assistant message identified by its `metadata.message_id`
|
|
125
|
+
* (Python SDK) or `metadata.id` (JS SDK) and emitted as a `data` part.
|
|
126
|
+
* Defaults to `"ui"`.
|
|
127
|
+
*/
|
|
128
|
+
uiStateKey?: string | undefined;
|
|
130
129
|
};
|
|
131
|
-
export type UseStreamRuntimeOptions = UseStreamOptions extends
|
|
132
|
-
//#endregion
|
|
133
|
-
export type { LangChainContentBlock };
|
|
130
|
+
export type UseStreamRuntimeOptions = UseStreamOptions extends infer O ? O extends UseStreamOptions ? O & LangChainRuntimeExtraOptions : never : never;
|
|
134
131
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,0BAA0B,EAC1B,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,EACT,yBAAyB,EACzB,yBAAyB,EAC1B,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EAAE,qBAAqB,EAAE,uBAAoB;AAEzD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B,CAAC;AAEF;;;;;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{ Channel } from "@langchain/react";
|
|
2
|
+
import type { RemoveUIMessage, UIMessage } from "./types.js";
|
|
4
3
|
/** Channels the generative-UI fold reads, at the root and per subagent. */
|
|
5
4
|
export declare const UI_CUSTOM_CHANNELS: readonly Channel[];
|
|
6
5
|
export type UIUpdate = UIMessage | RemoveUIMessage;
|
|
@@ -13,8 +12,8 @@ export declare const applyUIUpdate: (list: readonly UIMessage[], update: UIUpdat
|
|
|
13
12
|
*/
|
|
14
13
|
export declare const extractUIUpdate: (event: unknown) => UIUpdate | readonly UIUpdate[] | undefined;
|
|
15
14
|
export type UIFoldMemo = {
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
events: readonly unknown[];
|
|
16
|
+
messages: UIMessage[];
|
|
18
17
|
};
|
|
19
18
|
export declare const createUIFoldMemo: () => UIFoldMemo;
|
|
20
19
|
/**
|
|
@@ -26,6 +25,20 @@ export declare const createUIFoldMemo: () => UIFoldMemo;
|
|
|
26
25
|
* and is folded from scratch.
|
|
27
26
|
*/
|
|
28
27
|
export declare const foldUIUpdates: (events: readonly unknown[], memo?: UIFoldMemo) => UIMessage[];
|
|
28
|
+
export type UISnapshotMemo = {
|
|
29
|
+
snapshot: unknown;
|
|
30
|
+
entries: readonly UIMessage[];
|
|
31
|
+
};
|
|
32
|
+
export declare const createUISnapshotMemo: () => UISnapshotMemo;
|
|
33
|
+
/**
|
|
34
|
+
* Recovers entry identity across `values` events. The SDK rebuilds the
|
|
35
|
+
* `values` object from every snapshot and reconciles only the messages slot by
|
|
36
|
+
* id, so an unchanged UI list arrives as a new array of new objects on every
|
|
37
|
+
* superstep. An entry structurally equal to the previous entry with its id is
|
|
38
|
+
* replaced by that previous object, and a list whose entries all survive in
|
|
39
|
+
* place is replaced by the previous list.
|
|
40
|
+
*/
|
|
41
|
+
export declare const reconcileUISnapshot: (snapshot: unknown, memo: UISnapshotMemo) => readonly UIMessage[];
|
|
29
42
|
/**
|
|
30
43
|
* Merges live-streamed UI with the state snapshot. The snapshot is
|
|
31
44
|
* authoritative by id: once a UI lands in graph state it supersedes its live
|
|
@@ -34,5 +47,4 @@ export declare const foldUIUpdates: (events: readonly unknown[], memo?: UIFoldMe
|
|
|
34
47
|
* the snapshot catches up.
|
|
35
48
|
*/
|
|
36
49
|
export declare const mergeUIMessages: (live: readonly UIMessage[], snapshot: unknown) => UIMessage[];
|
|
37
|
-
//#endregion
|
|
38
50
|
//# sourceMappingURL=uiMessages.d.ts.map
|
package/dist/uiMessages.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uiMessages.d.ts","
|
|
1
|
+
{"version":3,"file":"uiMessages.d.ts","sourceRoot":"","sources":["../src/uiMessages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,mBAAgB;AAE1D,2EAA2E;AAC3E,eAAO,MAAM,kBAAkB,EAAE,SAAS,OAAO,EAAe,CAAC;AAEjE,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,eAAe,CAAC;AAEnD,eAAO,MAAM,UAAU,GACrB,OAAO,OAAO,KACb,KAAK,IAAI,QAAQ,GAAG,SAAS,QAAQ,EAiBvC,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,MAAM,SAAS,SAAS,EAAE,EAC1B,QAAQ,QAAQ,GAAG,SAAS,QAAQ,EAAE,KACrC,SAAS,EAmBX,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAC1B,OAAO,OAAO,KACb,QAAQ,GAAG,SAAS,QAAQ,EAAE,GAAG,SAMnC,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC;IAC3B,QAAQ,EAAE,SAAS,EAAE,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,gBAAgB,QAAO,UAGlC,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,GACxB,QAAQ,SAAS,OAAO,EAAE,EAC1B,OAAM,UAA+B,KACpC,SAAS,EAcX,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,SAAS,SAAS,EAAE,CAAC;CAC/B,CAAC;AAEF,eAAO,MAAM,oBAAoB,QAAO,cAGtC,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,GAC9B,UAAU,OAAO,EACjB,MAAM,cAAc,KACnB,SAAS,SAAS,EAmBpB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAC1B,MAAM,SAAS,SAAS,EAAE,EAC1B,UAAU,OAAO,KAChB,SAAS,EAOX,CAAC"}
|
package/dist/uiMessages.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isJSONValueEqual } from "@assistant-ui/core/internal";
|
|
1
2
|
//#region src/uiMessages.ts
|
|
2
3
|
/** Channels the generative-UI fold reads, at the root and per subagent. */
|
|
3
4
|
const UI_CUSTOM_CHANNELS = ["custom"];
|
|
@@ -67,6 +68,37 @@ const foldUIUpdates = (events, memo = createUIFoldMemo()) => {
|
|
|
67
68
|
memo.messages = acc;
|
|
68
69
|
return acc;
|
|
69
70
|
};
|
|
71
|
+
const createUISnapshotMemo = () => ({
|
|
72
|
+
snapshot: void 0,
|
|
73
|
+
entries: []
|
|
74
|
+
});
|
|
75
|
+
/**
|
|
76
|
+
* Recovers entry identity across `values` events. The SDK rebuilds the
|
|
77
|
+
* `values` object from every snapshot and reconciles only the messages slot by
|
|
78
|
+
* id, so an unchanged UI list arrives as a new array of new objects on every
|
|
79
|
+
* superstep. An entry structurally equal to the previous entry with its id is
|
|
80
|
+
* replaced by that previous object, and a list whose entries all survive in
|
|
81
|
+
* place is replaced by the previous list.
|
|
82
|
+
*/
|
|
83
|
+
const reconcileUISnapshot = (snapshot, memo) => {
|
|
84
|
+
if (snapshot === memo.snapshot) return memo.entries;
|
|
85
|
+
memo.snapshot = snapshot;
|
|
86
|
+
if (!Array.isArray(snapshot)) {
|
|
87
|
+
if (memo.entries.length > 0) memo.entries = [];
|
|
88
|
+
return memo.entries;
|
|
89
|
+
}
|
|
90
|
+
const previous = memo.entries;
|
|
91
|
+
const previousById = new Map(previous.map((ui) => [ui.id, ui]));
|
|
92
|
+
let same = snapshot.length === previous.length;
|
|
93
|
+
const entries = snapshot.map((ui, index) => {
|
|
94
|
+
const before = previousById.get(ui.id);
|
|
95
|
+
const entry = before !== void 0 && isJSONValueEqual(before, ui) ? before : ui;
|
|
96
|
+
if (entry !== previous[index]) same = false;
|
|
97
|
+
return entry;
|
|
98
|
+
});
|
|
99
|
+
if (!same) memo.entries = entries;
|
|
100
|
+
return memo.entries;
|
|
101
|
+
};
|
|
70
102
|
/**
|
|
71
103
|
* Merges live-streamed UI with the state snapshot. The snapshot is
|
|
72
104
|
* authoritative by id: once a UI lands in graph state it supersedes its live
|
|
@@ -81,6 +113,6 @@ const mergeUIMessages = (live, snapshot) => {
|
|
|
81
113
|
return [...byId.values()];
|
|
82
114
|
};
|
|
83
115
|
//#endregion
|
|
84
|
-
export { UI_CUSTOM_CHANNELS, applyUIUpdate, createUIFoldMemo, extractUIUpdate, foldUIUpdates, isUIUpdate, mergeUIMessages };
|
|
116
|
+
export { UI_CUSTOM_CHANNELS, applyUIUpdate, createUIFoldMemo, createUISnapshotMemo, extractUIUpdate, foldUIUpdates, isUIUpdate, mergeUIMessages, reconcileUISnapshot };
|
|
85
117
|
|
|
86
118
|
//# sourceMappingURL=uiMessages.js.map
|