@langchain/vue 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 LangChain, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,252 @@
1
+ # @langchain/vue
2
+
3
+ Vue SDK for building AI-powered applications with [LangChain](https://js.langchain.com/) and [LangGraph](https://langchain-ai.github.io/langgraphjs/). Provides a `useStream` composable that manages streaming, state, branching, and interrupts using Vue's reactivity system.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @langchain/vue @langchain/core
9
+ ```
10
+
11
+ **Peer dependencies:** `vue` (^3.0.0), `@langchain/core` (^1.0.1)
12
+
13
+ ## Quick Start
14
+
15
+ ```vue
16
+ <script setup lang="ts">
17
+ import { useStream } from "@langchain/vue";
18
+
19
+ const { messages, submit, isLoading } = useStream({
20
+ assistantId: "agent",
21
+ apiUrl: "http://localhost:2024",
22
+ });
23
+ </script>
24
+
25
+ <template>
26
+ <div>
27
+ <div v-for="(msg, i) in messages.value" :key="msg.id ?? i">
28
+ {{ msg.content }}
29
+ </div>
30
+
31
+ <button
32
+ :disabled="isLoading.value"
33
+ @click="submit({ messages: [{ type: 'human', content: 'Hello!' }] })"
34
+ >
35
+ Send
36
+ </button>
37
+ </div>
38
+ </template>
39
+ ```
40
+
41
+ ## `useStream` Options
42
+
43
+ | Option | Type | Description |
44
+ |---|---|---|
45
+ | `assistantId` | `string` | **Required.** The assistant/graph ID to stream from. |
46
+ | `apiUrl` | `string` | Base URL of the LangGraph API. |
47
+ | `client` | `Client` | Pre-configured `Client` instance (alternative to `apiUrl`). |
48
+ | `messagesKey` | `string` | State key containing messages. Defaults to `"messages"`. |
49
+ | `initialValues` | `StateType` | Initial state values before any stream data arrives. |
50
+ | `fetchStateHistory` | `boolean \| { limit: number }` | Fetch thread history on stream completion. Enables branching. |
51
+ | `throttle` | `boolean \| number` | Throttle state updates for performance. |
52
+ | `onFinish` | `(state, error?) => void` | Called when the stream completes. |
53
+ | `onError` | `(error, state?) => void` | Called on stream errors. |
54
+ | `onThreadId` | `(threadId) => void` | Called when a new thread is created. |
55
+ | `onUpdateEvent` | `(event) => void` | Receive update events from the stream. |
56
+ | `onCustomEvent` | `(event) => void` | Receive custom events from the stream. |
57
+ | `onStop` | `() => void` | Called when the stream is stopped by the user. |
58
+
59
+ ## Return Values
60
+
61
+ All reactive properties are Vue `computed` or `ref` values.
62
+
63
+ | Property | Type | Description |
64
+ |---|---|---|
65
+ | `values` | `ComputedRef<StateType>` | Current graph state. |
66
+ | `messages` | `ComputedRef<Message[]>` | Messages from the current state. |
67
+ | `isLoading` | `Ref<boolean>` | Whether a stream is currently active. |
68
+ | `error` | `ComputedRef<unknown>` | The most recent error, if any. |
69
+ | `interrupt` | `ComputedRef<Interrupt \| undefined>` | Current interrupt requiring user input. |
70
+ | `branch` | `Ref<string>` | Active branch identifier. |
71
+ | `submit(values, options?)` | `function` | Submit new input to the graph. When called while a stream is active, the run is created on the server with `multitaskStrategy: "enqueue"` and queued automatically. |
72
+ | `stop()` | `function` | Cancel the active stream. |
73
+ | `setBranch(branch)` | `function` | Switch to a different conversation branch. |
74
+ | `getMessagesMetadata(msg, index?)` | `function` | Get branching and checkpoint metadata for a message. |
75
+ | `switchThread(id)` | `(id: string \| null) => void` | Switch to a different thread. Pass `null` to start a new thread on next submit. |
76
+ | `queue.entries` | `Ref<ReadonlyArray<QueueEntry>>` | Pending server-side runs. Each entry has `id` (server run ID), `values`, `options`, and `createdAt`. |
77
+ | `queue.size` | `Ref<number>` | Number of pending runs on the server. |
78
+ | `queue.cancel(id)` | `(id: string) => Promise<boolean>` | Cancel a pending run on the server by its run ID. |
79
+ | `queue.clear()` | `() => Promise<void>` | Cancel all pending runs on the server. |
80
+
81
+ ## Type Safety
82
+
83
+ Provide your state type as a generic parameter:
84
+
85
+ ```vue
86
+ <script setup lang="ts">
87
+ import { useStream } from "@langchain/vue";
88
+ import type { Message } from "@langchain/langgraph-sdk";
89
+
90
+ interface MyState {
91
+ messages: Message[];
92
+ context?: string;
93
+ }
94
+
95
+ const { messages, submit } = useStream<MyState>({
96
+ assistantId: "my-graph",
97
+ apiUrl: "http://localhost:2024",
98
+ });
99
+ </script>
100
+ ```
101
+
102
+ ### Typed Interrupts
103
+
104
+ ```vue
105
+ <script setup lang="ts">
106
+ import { useStream } from "@langchain/vue";
107
+ import type { Message } from "@langchain/langgraph-sdk";
108
+
109
+ const { interrupt, submit } = useStream<
110
+ { messages: Message[] },
111
+ { InterruptType: { question: string } }
112
+ >({
113
+ assistantId: "my-graph",
114
+ apiUrl: "http://localhost:2024",
115
+ });
116
+ </script>
117
+ ```
118
+
119
+ ## Handling Interrupts
120
+
121
+ ```vue
122
+ <script setup lang="ts">
123
+ import { useStream } from "@langchain/vue";
124
+ import type { Message } from "@langchain/langgraph-sdk";
125
+
126
+ const { messages, interrupt, submit } = useStream<
127
+ { messages: Message[] },
128
+ { InterruptType: { question: string } }
129
+ >({
130
+ assistantId: "agent",
131
+ apiUrl: "http://localhost:2024",
132
+ });
133
+ </script>
134
+
135
+ <template>
136
+ <div>
137
+ <div v-for="(msg, i) in messages.value" :key="msg.id ?? i">
138
+ {{ msg.content }}
139
+ </div>
140
+
141
+ <div v-if="interrupt.value">
142
+ <p>{{ interrupt.value.value.question }}</p>
143
+ <button @click="submit(null, { command: { resume: 'Approved' } })">
144
+ Approve
145
+ </button>
146
+ </div>
147
+
148
+ <button
149
+ @click="submit({ messages: [{ type: 'human', content: 'Hello' }] })"
150
+ >
151
+ Send
152
+ </button>
153
+ </div>
154
+ </template>
155
+ ```
156
+
157
+ ## Branching
158
+
159
+ Enable conversation branching with `fetchStateHistory: true`:
160
+
161
+ ```vue
162
+ <script setup lang="ts">
163
+ import { useStream } from "@langchain/vue";
164
+
165
+ const { messages, submit, getMessagesMetadata, setBranch } = useStream({
166
+ assistantId: "agent",
167
+ apiUrl: "http://localhost:2024",
168
+ fetchStateHistory: true,
169
+ });
170
+ </script>
171
+
172
+ <template>
173
+ <div>
174
+ <div v-for="(msg, i) in messages.value" :key="msg.id ?? i">
175
+ <p>{{ msg.content }}</p>
176
+
177
+ <template v-if="getMessagesMetadata(msg, i)?.branchOptions">
178
+ <button
179
+ @click="() => {
180
+ const meta = getMessagesMetadata(msg, i);
181
+ const prev = meta.branchOptions[meta.branchOptions.indexOf(meta.branch) - 1];
182
+ if (prev) setBranch(prev);
183
+ }"
184
+ >
185
+ Previous
186
+ </button>
187
+ <button
188
+ @click="() => {
189
+ const meta = getMessagesMetadata(msg, i);
190
+ const next = meta.branchOptions[meta.branchOptions.indexOf(meta.branch) + 1];
191
+ if (next) setBranch(next);
192
+ }"
193
+ >
194
+ Next
195
+ </button>
196
+ </template>
197
+ </div>
198
+
199
+ <button
200
+ @click="submit({ messages: [{ type: 'human', content: 'Hello' }] })"
201
+ >
202
+ Send
203
+ </button>
204
+ </div>
205
+ </template>
206
+ ```
207
+
208
+ ## Server-Side Queuing
209
+
210
+ When `submit()` is called while a stream is already active, the SDK automatically creates the run on the server with `multitaskStrategy: "enqueue"`. The pending runs are tracked in `queue` and processed in order as each finishes:
211
+
212
+ ```vue
213
+ <script setup lang="ts">
214
+ import { useStream } from "@langchain/vue";
215
+
216
+ const { messages, submit, isLoading, queue, switchThread } = useStream({
217
+ assistantId: "agent",
218
+ apiUrl: "http://localhost:2024",
219
+ });
220
+ </script>
221
+
222
+ <template>
223
+ <div>
224
+ <div v-for="(msg, i) in messages.value" :key="msg.id ?? i">
225
+ {{ msg.content }}
226
+ </div>
227
+
228
+ <div v-if="queue.size.value > 0">
229
+ <p>{{ queue.size.value }} message(s) queued</p>
230
+ <button @click="queue.clear()">Clear Queue</button>
231
+ </div>
232
+
233
+ <button
234
+ :disabled="isLoading.value"
235
+ @click="submit({ messages: [{ type: 'human', content: 'Hello!' }] })"
236
+ >
237
+ Send
238
+ </button>
239
+ <button @click="switchThread(null)">New Thread</button>
240
+ </div>
241
+ </template>
242
+ ```
243
+
244
+ Switching threads via `switchThread()` cancels all pending runs and clears the queue.
245
+
246
+ ## Playground
247
+
248
+ For complete end-to-end examples with full agentic UIs, visit the [LangGraph Playground](https://github.com/langchain-ai/langgraphjs).
249
+
250
+ ## License
251
+
252
+ MIT