@ai-sdk/langchain 3.0.0-beta.86 → 3.0.0-beta.88

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/index.d.mts DELETED
@@ -1,159 +0,0 @@
1
- import { BaseMessage, AIMessageChunk } from '@langchain/core/messages';
2
- import { UIMessage, UIMessageChunk, ModelMessage, ChatTransport, ChatRequestOptions } from 'ai';
3
- import { RemoteGraph, RemoteGraphParams } from '@langchain/langgraph/remote';
4
-
5
- /**
6
- * Callback options for stream lifecycle events.
7
- */
8
- interface StreamCallbacks<TState = unknown> {
9
- /** Called once when the stream is initialized. */
10
- onStart?: () => Promise<void> | void;
11
- /** Called for each tokenized message. */
12
- onToken?: (token: string) => Promise<void> | void;
13
- /** Called for each text chunk. */
14
- onText?: (text: string) => Promise<void> | void;
15
- /** Called with aggregated text when stream ends (success, error, or abort). */
16
- onFinal?: (completion: string) => Promise<void> | void;
17
- /**
18
- * Called on successful completion. Receives final graph state for LangGraph
19
- * streams (from last "values" event), undefined for other stream types.
20
- */
21
- onFinish?: (finalState: TState | undefined) => Promise<void> | void;
22
- /** Called when the stream encounters an error. */
23
- onError?: (error: Error) => Promise<void> | void;
24
- /** Called when the stream is aborted. */
25
- onAbort?: () => Promise<void> | void;
26
- }
27
-
28
- /**
29
- * Converts AI SDK UIMessages to LangChain BaseMessage objects.
30
- *
31
- * This function transforms the AI SDK's message format into LangChain's message
32
- * format, enabling seamless integration between the two frameworks.
33
- *
34
- * @param messages - Array of AI SDK UIMessage objects to convert.
35
- * @returns Promise resolving to an array of LangChain BaseMessage objects.
36
- *
37
- * @example
38
- * ```ts
39
- * import { toBaseMessages } from '@ai-sdk/langchain';
40
- *
41
- * const langchainMessages = await toBaseMessages(uiMessages);
42
- *
43
- * // Use with LangChain
44
- * const response = await model.invoke(langchainMessages);
45
- * ```
46
- */
47
- declare function toBaseMessages(messages: UIMessage[]): Promise<BaseMessage[]>;
48
- /**
49
- * Converts ModelMessages to LangChain BaseMessage objects.
50
- *
51
- * @param modelMessages - Array of ModelMessage objects from convertToModelMessages.
52
- * @returns Array of LangChain BaseMessage objects.
53
- */
54
- declare function convertModelMessages(modelMessages: ModelMessage[]): BaseMessage[];
55
- /**
56
- * Converts a LangChain stream to an AI SDK UIMessageStream.
57
- *
58
- * This function automatically detects the stream type and handles:
59
- * - Direct model streams (AsyncIterable from `model.stream()`)
60
- * - LangGraph streams (ReadableStream with `streamMode: ['values', 'messages']`)
61
- * - streamEvents streams (from `agent.streamEvents()` or `model.streamEvents()`)
62
- *
63
- * @param stream - A stream from LangChain model.stream(), graph.stream(), or streamEvents().
64
- * @param callbacks - Optional callbacks for stream lifecycle events.
65
- * @returns A ReadableStream of UIMessageChunk objects.
66
- *
67
- * @example
68
- * ```ts
69
- * // With a direct model stream
70
- * const model = new ChatOpenAI({ model: 'gpt-4o-mini' });
71
- * const stream = await model.stream(messages);
72
- * return createUIMessageStreamResponse({
73
- * stream: toUIMessageStream(stream),
74
- * });
75
- *
76
- * // With a LangGraph stream
77
- * const graphStream = await graph.stream(
78
- * { messages },
79
- * { streamMode: ['values', 'messages'] }
80
- * );
81
- * return createUIMessageStreamResponse({
82
- * stream: toUIMessageStream(graphStream),
83
- * });
84
- *
85
- * // With streamEvents
86
- * const streamEvents = agent.streamEvents(
87
- * { messages },
88
- * { version: "v2" }
89
- * );
90
- * return createUIMessageStreamResponse({
91
- * stream: toUIMessageStream(streamEvents),
92
- * });
93
- *
94
- * // With callbacks for LangGraph state
95
- * const graphStream = await graph.stream(
96
- * { messages },
97
- * { streamMode: ['values', 'messages'] }
98
- * );
99
- * return createUIMessageStreamResponse({
100
- * stream: toUIMessageStream<MyStateType>(graphStream, {
101
- * onFinish: async (finalState) => {
102
- * if (finalState) {
103
- * await saveToDatabase(finalState);
104
- * }
105
- * },
106
- * onError: (error) => console.error('Stream failed:', error),
107
- * onAbort: () => console.log('Stream aborted'),
108
- * }),
109
- * });
110
- * ```
111
- */
112
- declare function toUIMessageStream<TState = unknown>(stream: AsyncIterable<AIMessageChunk> | ReadableStream, callbacks?: StreamCallbacks<TState>): ReadableStream<UIMessageChunk>;
113
-
114
- /**
115
- * Options for configuring a LangSmith deployment transport.
116
- * Extends RemoteGraphParams but makes graphId optional (defaults to 'agent').
117
- */
118
- type LangSmithDeploymentTransportOptions = Omit<RemoteGraphParams, 'graphId'> & {
119
- /**
120
- * The ID of the graph to connect to.
121
- * @default 'agent'
122
- */
123
- graphId?: string;
124
- };
125
- /**
126
- * A ChatTransport implementation for LangSmith/LangGraph deployments.
127
- *
128
- * This transport enables seamless integration between the AI SDK's useChat hook
129
- * and LangSmith deployed LangGraph agents.
130
- *
131
- * @example
132
- * ```ts
133
- * import { LangSmithDeploymentTransport } from '@ai-sdk/langchain';
134
- *
135
- * // Use with useChat
136
- * const { messages, input, handleSubmit } = useChat({
137
- * transport: new LangSmithDeploymentTransport({
138
- * url: 'https://your-deployment.us.langgraph.app',
139
- * apiKey: 'my-api-key',
140
- * }),
141
- * });
142
- * ```
143
- */
144
- declare class LangSmithDeploymentTransport<UI_MESSAGE extends UIMessage> implements ChatTransport<UI_MESSAGE> {
145
- protected graph: RemoteGraph;
146
- constructor(options: LangSmithDeploymentTransportOptions);
147
- sendMessages(options: {
148
- trigger: 'submit-message' | 'regenerate-message';
149
- chatId: string;
150
- messageId: string | undefined;
151
- messages: UI_MESSAGE[];
152
- abortSignal: AbortSignal | undefined;
153
- } & ChatRequestOptions): Promise<ReadableStream<UIMessageChunk>>;
154
- reconnectToStream(_options: {
155
- chatId: string;
156
- } & ChatRequestOptions): Promise<ReadableStream<UIMessageChunk> | null>;
157
- }
158
-
159
- export { LangSmithDeploymentTransport, type LangSmithDeploymentTransportOptions, type StreamCallbacks, convertModelMessages, toBaseMessages, toUIMessageStream };