@langchain/vue 0.1.3 → 0.3.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 +122 -19
- package/dist/context.cjs +112 -0
- package/dist/context.cjs.map +1 -0
- package/dist/context.d.cts +112 -0
- package/dist/context.d.cts.map +1 -0
- package/dist/context.d.ts +112 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +109 -0
- package/dist/context.js.map +1 -0
- package/dist/index.cjs +129 -421
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -16
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +7 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +128 -424
- package/dist/index.js.map +1 -1
- package/dist/stream.custom.cjs +46 -133
- package/dist/stream.custom.cjs.map +1 -1
- package/dist/stream.custom.js +48 -135
- package/dist/stream.custom.js.map +1 -1
- package/dist/types.d.cts +28 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +28 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +6 -8
package/dist/context.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { useStream } from "./index.js";
|
|
2
|
+
import { inject, provide } from "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 = useStream(options);
|
|
66
|
+
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 = 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
|
+
export { LANGCHAIN_OPTIONS, LangChainPlugin, provideStream, useStreamContext };
|
|
108
|
+
|
|
109
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","names":[],"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,SAAS,UAAkB,QAAe;AAChD,SAAQ,oBAAoB,OAAO;AACnC,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCT,SAAgB,mBAG0B;CACxC,MAAM,UAAU,OAAO,mBAAmB;AAC1C,KAAI,WAAW,KACb,OAAM,IAAI,MACR,8IAED;AAEH,QAAO"}
|