@langchain/vue 0.1.2 → 0.2.0

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @langchain/vue
2
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.
3
+ Vue SDK for building AI-powered applications with [Deep Agents](https://docs.langchain.com/oss/javascript/deepagents/overview), [LangChain](https://docs.langchain.com/oss/javascript/langchain/overview) and [LangGraph](https://docs.langchain.com/oss/javascript/langgraph/overview). It provides a `useStream` composable that manages streaming, state, branching, and interrupts using Vue's reactivity system.
4
4
 
5
5
  ## Installation
6
6
 
@@ -24,12 +24,12 @@ const { messages, submit, isLoading } = useStream({
24
24
 
25
25
  <template>
26
26
  <div>
27
- <div v-for="(msg, i) in messages.value" :key="msg.id ?? i">
27
+ <div v-for="(msg, i) in messages" :key="msg.id ?? i">
28
28
  {{ msg.content }}
29
29
  </div>
30
30
 
31
31
  <button
32
- :disabled="isLoading.value"
32
+ :disabled="isLoading"
33
33
  @click="submit({ messages: [{ type: 'human', content: 'Hello!' }] })"
34
34
  >
35
35
  Send
@@ -58,7 +58,7 @@ const { messages, submit, isLoading } = useStream({
58
58
 
59
59
  ## Return Values
60
60
 
61
- All reactive properties are Vue `computed` or `ref` values.
61
+ All reactive properties are Vue `computed` or `ref` values that [auto-unwrap](https://vuejs.org/guide/essentials/reactivity-fundamentals.html#ref-unwrapping-in-templates) in `<template>` blocks — use them directly (e.g. `messages`, not `messages.value`). The `queue` object is `reactive`, so its nested properties also auto-unwrap in templates.
62
62
 
63
63
  | Property | Type | Description |
64
64
  |---|---|---|
@@ -73,8 +73,8 @@ All reactive properties are Vue `computed` or `ref` values.
73
73
  | `setBranch(branch)` | `function` | Switch to a different conversation branch. |
74
74
  | `getMessagesMetadata(msg, index?)` | `function` | Get branching and checkpoint metadata for a message. |
75
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. |
76
+ | `queue.entries` | `ReadonlyArray<QueueEntry>` | Pending server-side runs. Each entry has `id` (server run ID), `values`, `options`, and `createdAt`. |
77
+ | `queue.size` | `number` | Number of pending runs on the server. |
78
78
  | `queue.cancel(id)` | `(id: string) => Promise<boolean>` | Cancel a pending run on the server by its run ID. |
79
79
  | `queue.clear()` | `() => Promise<void>` | Cancel all pending runs on the server. |
80
80
 
@@ -134,12 +134,12 @@ const { messages, interrupt, submit } = useStream<
134
134
 
135
135
  <template>
136
136
  <div>
137
- <div v-for="(msg, i) in messages.value" :key="msg.id ?? i">
137
+ <div v-for="(msg, i) in messages" :key="msg.id ?? i">
138
138
  {{ msg.content }}
139
139
  </div>
140
140
 
141
- <div v-if="interrupt.value">
142
- <p>{{ interrupt.value.value.question }}</p>
141
+ <div v-if="interrupt">
142
+ <p>{{ interrupt.value.question }}</p>
143
143
  <button @click="submit(null, { command: { resume: 'Approved' } })">
144
144
  Approve
145
145
  </button>
@@ -171,7 +171,7 @@ const { messages, submit, getMessagesMetadata, setBranch } = useStream({
171
171
 
172
172
  <template>
173
173
  <div>
174
- <div v-for="(msg, i) in messages.value" :key="msg.id ?? i">
174
+ <div v-for="(msg, i) in messages" :key="msg.id ?? i">
175
175
  <p>{{ msg.content }}</p>
176
176
 
177
177
  <template v-if="getMessagesMetadata(msg, i)?.branchOptions">
@@ -221,17 +221,17 @@ const { messages, submit, isLoading, queue, switchThread } = useStream({
221
221
 
222
222
  <template>
223
223
  <div>
224
- <div v-for="(msg, i) in messages.value" :key="msg.id ?? i">
224
+ <div v-for="(msg, i) in messages" :key="msg.id ?? i">
225
225
  {{ msg.content }}
226
226
  </div>
227
227
 
228
- <div v-if="queue.size.value > 0">
229
- <p>{{ queue.size.value }} message(s) queued</p>
228
+ <div v-if="queue.size > 0">
229
+ <p>{{ queue.size }} message(s) queued</p>
230
230
  <button @click="queue.clear()">Clear Queue</button>
231
231
  </div>
232
232
 
233
233
  <button
234
- :disabled="isLoading.value"
234
+ :disabled="isLoading"
235
235
  @click="submit({ messages: [{ type: 'human', content: 'Hello!' }] })"
236
236
  >
237
237
  Send
@@ -270,17 +270,17 @@ const {
270
270
 
271
271
  <template>
272
272
  <div>
273
- <div v-for="(msg, i) in messages.value" :key="msg.id ?? i">
273
+ <div v-for="(msg, i) in messages" :key="msg.id ?? i">
274
274
  <p>{{ msg.content }}</p>
275
275
  <span v-if="getMessagesMetadata(msg, i)?.streamMetadata">
276
276
  Node: {{ getMessagesMetadata(msg, i)?.streamMetadata?.langgraph_node }}
277
277
  </span>
278
278
  </div>
279
279
 
280
- <p>Current branch: {{ branch.value }}</p>
280
+ <p>Current branch: {{ branch }}</p>
281
281
 
282
282
  <button
283
- :disabled="isLoading.value"
283
+ :disabled="isLoading"
284
284
  @click="submit({ messages: [{ type: 'human', content: 'Hello!' }] })"
285
285
  >
286
286
  Send
@@ -289,11 +289,114 @@ const {
289
289
  </template>
290
290
  ```
291
291
 
292
- The custom transport interface returns the same properties as the standard `useStream` composable, including `getMessagesMetadata`, `branch`, `setBranch`, `switchThread`, and all message/interrupt/subagent helpers. When using a custom transport, `getMessagesMetadata` returns stream metadata sent alongside messages during streaming; `branch` and `setBranch` provide local branch state management.
292
+ The custom transport interface returns the same properties as the standard `useStream` composable, including `getMessagesMetadata`, `branch`, `setBranch`, `switchThread`, and all message/interrupt/subagent helpers. When using a custom transport, `getMessagesMetadata` returns stream metadata sent alongside messages during streaming; `branch` and `setBranch` provide local branch state management. `onFinish` is also supported and receives a synthetic `ThreadState` built from the final locally streamed values; the run metadata argument is `undefined`.
293
+
294
+ ## Sharing State with `provideStream`
295
+
296
+ When multiple components need access to the same stream (a message list, a header, an input bar), use `provideStream` and `useStreamContext` to share a single stream instance via Vue's `provide`/`inject`:
297
+
298
+ ```vue
299
+ <!-- ChatContainer.vue -->
300
+ <script setup lang="ts">
301
+ import { provideStream } from "@langchain/vue";
302
+
303
+ provideStream({
304
+ assistantId: "agent",
305
+ apiUrl: "http://localhost:2024",
306
+ });
307
+ </script>
308
+
309
+ <template>
310
+ <ChatHeader />
311
+ <MessageList />
312
+ <MessageInput />
313
+ </template>
314
+ ```
315
+
316
+ ```vue
317
+ <!-- MessageList.vue -->
318
+ <script setup lang="ts">
319
+ import { useStreamContext } from "@langchain/vue";
320
+
321
+ const { messages } = useStreamContext();
322
+ </script>
323
+
324
+ <template>
325
+ <div v-for="(msg, i) in messages.value" :key="msg.id ?? i">
326
+ {{ msg.content }}
327
+ </div>
328
+ </template>
329
+ ```
330
+
331
+ ```vue
332
+ <!-- MessageInput.vue -->
333
+ <script setup lang="ts">
334
+ import { useStreamContext } from "@langchain/vue";
335
+ import { ref } from "vue";
336
+
337
+ const { submit, isLoading } = useStreamContext();
338
+ const input = ref("");
339
+
340
+ function send() {
341
+ submit({ messages: [{ type: "human", content: input.value }] });
342
+ input.value = "";
343
+ }
344
+ </script>
345
+
346
+ <template>
347
+ <form @submit.prevent="send">
348
+ <textarea v-model="input" />
349
+ <button :disabled="isLoading.value" type="submit">Send</button>
350
+ </form>
351
+ </template>
352
+ ```
353
+
354
+ ### App-Level Configuration with `LangChainPlugin`
355
+
356
+ Use the Vue plugin to set default configuration for all `useStream` calls:
357
+
358
+ ```typescript
359
+ import { createApp } from "vue";
360
+ import { LangChainPlugin } from "@langchain/vue";
361
+ import App from "./App.vue";
362
+
363
+ const app = createApp(App);
364
+ app.use(LangChainPlugin, {
365
+ apiUrl: "http://localhost:2024",
366
+ });
367
+ app.mount("#app");
368
+ ```
369
+
370
+ Then in any component, `apiUrl` is inherited automatically:
371
+
372
+ ```vue
373
+ <script setup lang="ts">
374
+ import { useStream } from "@langchain/vue";
375
+
376
+ const stream = useStream({ assistantId: "agent" });
377
+ </script>
378
+ ```
379
+
380
+ ### Multiple Agents
381
+
382
+ Nest `provideStream` calls for multi-agent scenarios — Vue's `provide`/`inject` scoping ensures each subtree gets its own stream:
383
+
384
+ ```vue
385
+ <!-- ResearchPanel.vue -->
386
+ <script setup lang="ts">
387
+ import { provideStream } from "@langchain/vue";
388
+ provideStream({ assistantId: "researcher", apiUrl: "http://localhost:2024" });
389
+ </script>
390
+
391
+ <template>
392
+ <MessageList />
393
+ <MessageInput />
394
+ </template>
395
+ ```
293
396
 
294
397
  ## Playground
295
398
 
296
- For complete end-to-end examples with full agentic UIs, visit the [LangGraph Playground](https://github.com/langchain-ai/langgraphjs).
399
+ For complete end-to-end examples with full agentic UIs, visit the [LangChain UI Playground](https://docs.langchain.com/playground).
297
400
 
298
401
  ## License
299
402
 
@@ -0,0 +1,112 @@
1
+ const require_index = require("./index.cjs");
2
+ let vue = require("vue");
3
+ //#region src/context.ts
4
+ const STREAM_CONTEXT_KEY = Symbol("langchain-stream");
5
+ const LANGCHAIN_OPTIONS = Symbol("langchain-options");
6
+ /**
7
+ * Vue plugin that provides default LangGraph configuration to all components.
8
+ *
9
+ * When installed, `useStream` composables throughout the application will
10
+ * automatically use the configured `apiUrl` and `client` without requiring
11
+ * explicit options.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { createApp } from "vue";
16
+ * import { LangChainPlugin } from "@langchain/vue";
17
+ * import App from "./App.vue";
18
+ *
19
+ * const app = createApp(App);
20
+ * app.use(LangChainPlugin, {
21
+ * apiUrl: "http://localhost:2024",
22
+ * });
23
+ * app.mount("#app");
24
+ * ```
25
+ *
26
+ * Then in any component:
27
+ * ```vue
28
+ * <script setup lang="ts">
29
+ * import { useStream } from "@langchain/vue";
30
+ *
31
+ * // apiUrl is inherited from the plugin — no need to repeat it
32
+ * const stream = useStream({ assistantId: "agent" });
33
+ * <\/script>
34
+ * ```
35
+ */
36
+ const LangChainPlugin = { install(app, options = {}) {
37
+ app.provide(LANGCHAIN_OPTIONS, options);
38
+ } };
39
+ /**
40
+ * Creates a shared `useStream` instance and provides it to all descendant
41
+ * components via Vue's `provide`/`inject`.
42
+ *
43
+ * Call this in a parent component's `<script setup>` to make the stream
44
+ * available to children via `useStreamContext()`.
45
+ *
46
+ * @example
47
+ * ```vue
48
+ * <!-- ChatContainer.vue -->
49
+ * <script setup lang="ts">
50
+ * import { provideStream } from "@langchain/vue";
51
+ *
52
+ * provideStream({ assistantId: "agent", apiUrl: "http://localhost:2024" });
53
+ * <\/script>
54
+ *
55
+ * <template>
56
+ * <ChatHeader />
57
+ * <MessageList />
58
+ * <MessageInput />
59
+ * </template>
60
+ * ```
61
+ *
62
+ * @returns The stream instance (same as calling `useStream` directly).
63
+ */
64
+ function provideStream(options) {
65
+ const stream = require_index.useStream(options);
66
+ (0, vue.provide)(STREAM_CONTEXT_KEY, stream);
67
+ return stream;
68
+ }
69
+ /**
70
+ * Accesses the shared stream instance from the nearest ancestor that
71
+ * called `provideStream()`.
72
+ *
73
+ * Throws if no ancestor has provided a stream.
74
+ *
75
+ * @example
76
+ * ```vue
77
+ * <!-- MessageList.vue -->
78
+ * <script setup lang="ts">
79
+ * import { useStreamContext } from "@langchain/vue";
80
+ *
81
+ * const { messages } = useStreamContext();
82
+ * <\/script>
83
+ *
84
+ * <template>
85
+ * <div v-for="(msg, i) in messages.value" :key="msg.id ?? i">
86
+ * {{ msg.content }}
87
+ * </div>
88
+ * </template>
89
+ * ```
90
+ *
91
+ * @example With type parameters for full type safety:
92
+ * ```vue
93
+ * <script setup lang="ts">
94
+ * import { useStreamContext } from "@langchain/vue";
95
+ * import type { agent } from "./agent";
96
+ *
97
+ * const { toolCalls } = useStreamContext<typeof agent>();
98
+ * <\/script>
99
+ * ```
100
+ */
101
+ function useStreamContext() {
102
+ const context = (0, vue.inject)(STREAM_CONTEXT_KEY);
103
+ if (context == null) throw new Error("useStreamContext() requires a parent component to call provideStream(). Add provideStream({ assistantId: '...' }) in an ancestor component.");
104
+ return context;
105
+ }
106
+ //#endregion
107
+ exports.LANGCHAIN_OPTIONS = LANGCHAIN_OPTIONS;
108
+ exports.LangChainPlugin = LangChainPlugin;
109
+ exports.provideStream = provideStream;
110
+ exports.useStreamContext = useStreamContext;
111
+
112
+ //# sourceMappingURL=context.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.cjs","names":["useStream"],"sources":["../src/context.ts"],"sourcesContent":["import { provide, inject, type InjectionKey, type App, type Plugin } from \"vue\";\nimport type { BagTemplate } from \"@langchain/langgraph-sdk\";\nimport type {\n ResolveStreamOptions,\n InferBag,\n InferStateType,\n UseStreamCustomOptions,\n} from \"@langchain/langgraph-sdk/ui\";\nimport { Client } from \"@langchain/langgraph-sdk\";\nimport { useStream } from \"./index.js\";\n\n/**\n * Configuration options for the LangChain Vue plugin.\n * These provide default values that `useStream` will pick up automatically.\n */\nexport interface LangChainPluginOptions {\n /** Base URL of the LangGraph API. */\n apiUrl?: string;\n /** API key for authenticating with the LangGraph API. */\n apiKey?: string;\n /** Pre-configured Client instance. */\n client?: Client;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst STREAM_CONTEXT_KEY: InjectionKey<any> = Symbol(\"langchain-stream\");\n\nexport const LANGCHAIN_OPTIONS: InjectionKey<LangChainPluginOptions> =\n Symbol(\"langchain-options\");\n\n/**\n * Vue plugin that provides default LangGraph configuration to all components.\n *\n * When installed, `useStream` composables throughout the application will\n * automatically use the configured `apiUrl` and `client` without requiring\n * explicit options.\n *\n * @example\n * ```typescript\n * import { createApp } from \"vue\";\n * import { LangChainPlugin } from \"@langchain/vue\";\n * import App from \"./App.vue\";\n *\n * const app = createApp(App);\n * app.use(LangChainPlugin, {\n * apiUrl: \"http://localhost:2024\",\n * });\n * app.mount(\"#app\");\n * ```\n *\n * Then in any component:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useStream } from \"@langchain/vue\";\n *\n * // apiUrl is inherited from the plugin — no need to repeat it\n * const stream = useStream({ assistantId: \"agent\" });\n * </script>\n * ```\n */\nexport const LangChainPlugin: Plugin<[LangChainPluginOptions?]> = {\n install(app: App, options: LangChainPluginOptions = {}) {\n app.provide(LANGCHAIN_OPTIONS, options);\n },\n};\n\n/**\n * Creates a shared `useStream` instance and provides it to all descendant\n * components via Vue's `provide`/`inject`.\n *\n * Call this in a parent component's `<script setup>` to make the stream\n * available to children via `useStreamContext()`.\n *\n * @example\n * ```vue\n * <!-- ChatContainer.vue -->\n * <script setup lang=\"ts\">\n * import { provideStream } from \"@langchain/vue\";\n *\n * provideStream({ assistantId: \"agent\", apiUrl: \"http://localhost:2024\" });\n * </script>\n *\n * <template>\n * <ChatHeader />\n * <MessageList />\n * <MessageInput />\n * </template>\n * ```\n *\n * @returns The stream instance (same as calling `useStream` directly).\n */\nexport function provideStream<\n T = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate,\n>(\n options:\n | ResolveStreamOptions<T, InferBag<T, Bag>>\n | UseStreamCustomOptions<InferStateType<T>, InferBag<T, Bag>>,\n): ReturnType<typeof useStream<T, Bag>> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const stream = useStream<T, Bag>(options as any);\n provide(STREAM_CONTEXT_KEY, stream);\n return stream;\n}\n\n/**\n * Accesses the shared stream instance from the nearest ancestor that\n * called `provideStream()`.\n *\n * Throws if no ancestor has provided a stream.\n *\n * @example\n * ```vue\n * <!-- MessageList.vue -->\n * <script setup lang=\"ts\">\n * import { useStreamContext } from \"@langchain/vue\";\n *\n * const { messages } = useStreamContext();\n * </script>\n *\n * <template>\n * <div v-for=\"(msg, i) in messages.value\" :key=\"msg.id ?? i\">\n * {{ msg.content }}\n * </div>\n * </template>\n * ```\n *\n * @example With type parameters for full type safety:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useStreamContext } from \"@langchain/vue\";\n * import type { agent } from \"./agent\";\n *\n * const { toolCalls } = useStreamContext<typeof agent>();\n * </script>\n * ```\n */\nexport function useStreamContext<\n T = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate,\n>(): ReturnType<typeof useStream<T, Bag>> {\n const context = inject(STREAM_CONTEXT_KEY);\n if (context == null) {\n throw new Error(\n \"useStreamContext() requires a parent component to call provideStream(). \" +\n \"Add provideStream({ assistantId: '...' }) in an ancestor component.\",\n );\n }\n return context;\n}\n"],"mappings":";;;AAyBA,MAAM,qBAAwC,OAAO,mBAAmB;AAExE,MAAa,oBACX,OAAO,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgC7B,MAAa,kBAAqD,EAChE,QAAQ,KAAU,UAAkC,EAAE,EAAE;AACtD,KAAI,QAAQ,mBAAmB,QAAQ;GAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BD,SAAgB,cAId,SAGsC;CAEtC,MAAM,SAASA,cAAAA,UAAkB,QAAe;AAChD,EAAA,GAAA,IAAA,SAAQ,oBAAoB,OAAO;AACnC,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCT,SAAgB,mBAG0B;CACxC,MAAM,WAAA,GAAA,IAAA,QAAiB,mBAAmB;AAC1C,KAAI,WAAW,KACb,OAAM,IAAI,MACR,8IAED;AAEH,QAAO"}
@@ -0,0 +1,112 @@
1
+ import { useStream } from "./index.cjs";
2
+ import { InjectionKey, Plugin } from "vue";
3
+ import { InferBag, InferStateType, ResolveStreamOptions, UseStreamCustomOptions } from "@langchain/langgraph-sdk/ui";
4
+ import { BagTemplate, Client } from "@langchain/langgraph-sdk";
5
+
6
+ //#region src/context.d.ts
7
+ /**
8
+ * Configuration options for the LangChain Vue plugin.
9
+ * These provide default values that `useStream` will pick up automatically.
10
+ */
11
+ interface LangChainPluginOptions {
12
+ /** Base URL of the LangGraph API. */
13
+ apiUrl?: string;
14
+ /** API key for authenticating with the LangGraph API. */
15
+ apiKey?: string;
16
+ /** Pre-configured Client instance. */
17
+ client?: Client;
18
+ }
19
+ declare const LANGCHAIN_OPTIONS: InjectionKey<LangChainPluginOptions>;
20
+ /**
21
+ * Vue plugin that provides default LangGraph configuration to all components.
22
+ *
23
+ * When installed, `useStream` composables throughout the application will
24
+ * automatically use the configured `apiUrl` and `client` without requiring
25
+ * explicit options.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * import { createApp } from "vue";
30
+ * import { LangChainPlugin } from "@langchain/vue";
31
+ * import App from "./App.vue";
32
+ *
33
+ * const app = createApp(App);
34
+ * app.use(LangChainPlugin, {
35
+ * apiUrl: "http://localhost:2024",
36
+ * });
37
+ * app.mount("#app");
38
+ * ```
39
+ *
40
+ * Then in any component:
41
+ * ```vue
42
+ * <script setup lang="ts">
43
+ * import { useStream } from "@langchain/vue";
44
+ *
45
+ * // apiUrl is inherited from the plugin — no need to repeat it
46
+ * const stream = useStream({ assistantId: "agent" });
47
+ * </script>
48
+ * ```
49
+ */
50
+ declare const LangChainPlugin: Plugin<[LangChainPluginOptions?]>;
51
+ /**
52
+ * Creates a shared `useStream` instance and provides it to all descendant
53
+ * components via Vue's `provide`/`inject`.
54
+ *
55
+ * Call this in a parent component's `<script setup>` to make the stream
56
+ * available to children via `useStreamContext()`.
57
+ *
58
+ * @example
59
+ * ```vue
60
+ * <!-- ChatContainer.vue -->
61
+ * <script setup lang="ts">
62
+ * import { provideStream } from "@langchain/vue";
63
+ *
64
+ * provideStream({ assistantId: "agent", apiUrl: "http://localhost:2024" });
65
+ * </script>
66
+ *
67
+ * <template>
68
+ * <ChatHeader />
69
+ * <MessageList />
70
+ * <MessageInput />
71
+ * </template>
72
+ * ```
73
+ *
74
+ * @returns The stream instance (same as calling `useStream` directly).
75
+ */
76
+ declare function provideStream<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(options: ResolveStreamOptions<T, InferBag<T, Bag>> | UseStreamCustomOptions<InferStateType<T>, InferBag<T, Bag>>): ReturnType<typeof useStream<T, Bag>>;
77
+ /**
78
+ * Accesses the shared stream instance from the nearest ancestor that
79
+ * called `provideStream()`.
80
+ *
81
+ * Throws if no ancestor has provided a stream.
82
+ *
83
+ * @example
84
+ * ```vue
85
+ * <!-- MessageList.vue -->
86
+ * <script setup lang="ts">
87
+ * import { useStreamContext } from "@langchain/vue";
88
+ *
89
+ * const { messages } = useStreamContext();
90
+ * </script>
91
+ *
92
+ * <template>
93
+ * <div v-for="(msg, i) in messages.value" :key="msg.id ?? i">
94
+ * {{ msg.content }}
95
+ * </div>
96
+ * </template>
97
+ * ```
98
+ *
99
+ * @example With type parameters for full type safety:
100
+ * ```vue
101
+ * <script setup lang="ts">
102
+ * import { useStreamContext } from "@langchain/vue";
103
+ * import type { agent } from "./agent";
104
+ *
105
+ * const { toolCalls } = useStreamContext<typeof agent>();
106
+ * </script>
107
+ * ```
108
+ */
109
+ declare function useStreamContext<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(): ReturnType<typeof useStream<T, Bag>>;
110
+ //#endregion
111
+ export { LANGCHAIN_OPTIONS, LangChainPlugin, LangChainPluginOptions, provideStream, useStreamContext };
112
+ //# sourceMappingURL=context.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.cts","names":[],"sources":["../src/context.ts"],"mappings":";;;;;;;AAeA;;;UAAiB,sBAAA;EAEf;EAAA,MAAA;EAIA;EAFA,MAAA;EAEe;EAAf,MAAA,GAAS,MAAA;AAAA;AAAA,cAME,iBAAA,EAAmB,YAAA,CAAa,sBAAA;;;;AAiC7C;;;;;AA+BA;;;;;;;;;;;;;;;;;;;;;;cA/Ba,eAAA,EAAiB,MAAA,EAAQ,sBAAA;;;;;;;;;;;;;;;;;;;;;;;;AA6EtC;;iBA9CgB,aAAA,KACV,MAAA,+BACQ,WAAA,GAAc,WAAA,CAAA,CAE1B,OAAA,EACI,oBAAA,CAAqB,CAAA,EAAG,QAAA,CAAS,CAAA,EAAG,GAAA,KACpC,sBAAA,CAAuB,cAAA,CAAe,CAAA,GAAI,QAAA,CAAS,CAAA,EAAG,GAAA,KACzD,UAAA,QAAkB,SAAA,CAAU,CAAA,EAAG,GAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuClB,gBAAA,KACV,MAAA,+BACQ,WAAA,GAAc,WAAA,CAAA,CAAA,GACvB,UAAA,QAAkB,SAAA,CAAU,CAAA,EAAG,GAAA"}
@@ -0,0 +1,112 @@
1
+ import { useStream } from "./index.js";
2
+ import { InjectionKey, Plugin } from "vue";
3
+ import { InferBag, InferStateType, ResolveStreamOptions, UseStreamCustomOptions } from "@langchain/langgraph-sdk/ui";
4
+ import { BagTemplate, Client } from "@langchain/langgraph-sdk";
5
+
6
+ //#region src/context.d.ts
7
+ /**
8
+ * Configuration options for the LangChain Vue plugin.
9
+ * These provide default values that `useStream` will pick up automatically.
10
+ */
11
+ interface LangChainPluginOptions {
12
+ /** Base URL of the LangGraph API. */
13
+ apiUrl?: string;
14
+ /** API key for authenticating with the LangGraph API. */
15
+ apiKey?: string;
16
+ /** Pre-configured Client instance. */
17
+ client?: Client;
18
+ }
19
+ declare const LANGCHAIN_OPTIONS: InjectionKey<LangChainPluginOptions>;
20
+ /**
21
+ * Vue plugin that provides default LangGraph configuration to all components.
22
+ *
23
+ * When installed, `useStream` composables throughout the application will
24
+ * automatically use the configured `apiUrl` and `client` without requiring
25
+ * explicit options.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * import { createApp } from "vue";
30
+ * import { LangChainPlugin } from "@langchain/vue";
31
+ * import App from "./App.vue";
32
+ *
33
+ * const app = createApp(App);
34
+ * app.use(LangChainPlugin, {
35
+ * apiUrl: "http://localhost:2024",
36
+ * });
37
+ * app.mount("#app");
38
+ * ```
39
+ *
40
+ * Then in any component:
41
+ * ```vue
42
+ * <script setup lang="ts">
43
+ * import { useStream } from "@langchain/vue";
44
+ *
45
+ * // apiUrl is inherited from the plugin — no need to repeat it
46
+ * const stream = useStream({ assistantId: "agent" });
47
+ * </script>
48
+ * ```
49
+ */
50
+ declare const LangChainPlugin: Plugin<[LangChainPluginOptions?]>;
51
+ /**
52
+ * Creates a shared `useStream` instance and provides it to all descendant
53
+ * components via Vue's `provide`/`inject`.
54
+ *
55
+ * Call this in a parent component's `<script setup>` to make the stream
56
+ * available to children via `useStreamContext()`.
57
+ *
58
+ * @example
59
+ * ```vue
60
+ * <!-- ChatContainer.vue -->
61
+ * <script setup lang="ts">
62
+ * import { provideStream } from "@langchain/vue";
63
+ *
64
+ * provideStream({ assistantId: "agent", apiUrl: "http://localhost:2024" });
65
+ * </script>
66
+ *
67
+ * <template>
68
+ * <ChatHeader />
69
+ * <MessageList />
70
+ * <MessageInput />
71
+ * </template>
72
+ * ```
73
+ *
74
+ * @returns The stream instance (same as calling `useStream` directly).
75
+ */
76
+ declare function provideStream<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(options: ResolveStreamOptions<T, InferBag<T, Bag>> | UseStreamCustomOptions<InferStateType<T>, InferBag<T, Bag>>): ReturnType<typeof useStream<T, Bag>>;
77
+ /**
78
+ * Accesses the shared stream instance from the nearest ancestor that
79
+ * called `provideStream()`.
80
+ *
81
+ * Throws if no ancestor has provided a stream.
82
+ *
83
+ * @example
84
+ * ```vue
85
+ * <!-- MessageList.vue -->
86
+ * <script setup lang="ts">
87
+ * import { useStreamContext } from "@langchain/vue";
88
+ *
89
+ * const { messages } = useStreamContext();
90
+ * </script>
91
+ *
92
+ * <template>
93
+ * <div v-for="(msg, i) in messages.value" :key="msg.id ?? i">
94
+ * {{ msg.content }}
95
+ * </div>
96
+ * </template>
97
+ * ```
98
+ *
99
+ * @example With type parameters for full type safety:
100
+ * ```vue
101
+ * <script setup lang="ts">
102
+ * import { useStreamContext } from "@langchain/vue";
103
+ * import type { agent } from "./agent";
104
+ *
105
+ * const { toolCalls } = useStreamContext<typeof agent>();
106
+ * </script>
107
+ * ```
108
+ */
109
+ declare function useStreamContext<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(): ReturnType<typeof useStream<T, Bag>>;
110
+ //#endregion
111
+ export { LANGCHAIN_OPTIONS, LangChainPlugin, LangChainPluginOptions, provideStream, useStreamContext };
112
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","names":[],"sources":["../src/context.ts"],"mappings":";;;;;;;AAeA;;;UAAiB,sBAAA;EAEf;EAAA,MAAA;EAIA;EAFA,MAAA;EAEe;EAAf,MAAA,GAAS,MAAA;AAAA;AAAA,cAME,iBAAA,EAAmB,YAAA,CAAa,sBAAA;;;;AAiC7C;;;;;AA+BA;;;;;;;;;;;;;;;;;;;;;;cA/Ba,eAAA,EAAiB,MAAA,EAAQ,sBAAA;;;;;;;;;;;;;;;;;;;;;;;;AA6EtC;;iBA9CgB,aAAA,KACV,MAAA,+BACQ,WAAA,GAAc,WAAA,CAAA,CAE1B,OAAA,EACI,oBAAA,CAAqB,CAAA,EAAG,QAAA,CAAS,CAAA,EAAG,GAAA,KACpC,sBAAA,CAAuB,cAAA,CAAe,CAAA,GAAI,QAAA,CAAS,CAAA,EAAG,GAAA,KACzD,UAAA,QAAkB,SAAA,CAAU,CAAA,EAAG,GAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuClB,gBAAA,KACV,MAAA,+BACQ,WAAA,GAAc,WAAA,CAAA,CAAA,GACvB,UAAA,QAAkB,SAAA,CAAU,CAAA,EAAG,GAAA"}