@langchain/angular 0.2.0 → 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 +17 -15
- package/dist/context.cjs +0 -49
- package/dist/context.cjs.map +1 -1
- package/dist/context.d.cts +1 -46
- package/dist/context.d.cts.map +1 -1
- package/dist/context.d.ts +1 -46
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -49
- package/dist/context.js.map +1 -1
- package/dist/index.cjs +118 -401
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +261 -27
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +261 -27
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +119 -404
- package/dist/index.js.map +1 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_@opentelemetry_api@1.9.0_openai@6.27.0_ws@8.19._0520fb05d9e85da5f9e061dfe28cdbc8/node_modules/langchain/dist/index.d.cts +2 -2
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_@opentelemetry_api@1.9.0_openai@6.27.0_ws@8.19._0520fb05d9e85da5f9e061dfe28cdbc8/node_modules/langchain/dist/index.d.ts +2 -2
- package/dist/stream.custom.cjs +54 -158
- package/dist/stream.custom.cjs.map +1 -1
- package/dist/stream.custom.d.cts +45 -0
- package/dist/stream.custom.d.cts.map +1 -0
- package/dist/stream.custom.d.ts +45 -0
- package/dist/stream.custom.d.ts.map +1 -0
- package/dist/stream.custom.js +55 -160
- package/dist/stream.custom.js.map +1 -1
- package/dist/subagent-types.d.cts +15 -0
- package/dist/subagent-types.d.cts.map +1 -0
- package/dist/subagent-types.d.ts +15 -0
- package/dist/subagent-types.d.ts.map +1 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @langchain/angular
|
|
2
2
|
|
|
3
|
-
Angular 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
|
|
3
|
+
Angular 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 an `injectStream` function that manages streaming, state, branching, and interrupts using Angular's Signals API.
|
|
4
|
+
|
|
5
|
+
> **Migration note:** `useStream` has been renamed to `injectStream` to follow Angular's `inject*` naming convention. `useStream` is still available as a deprecated alias for backwards compatibility.
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
@@ -14,7 +16,7 @@ npm install @langchain/angular @langchain/core
|
|
|
14
16
|
|
|
15
17
|
```typescript
|
|
16
18
|
import { Component } from "@angular/core";
|
|
17
|
-
import {
|
|
19
|
+
import { injectStream } from "@langchain/angular";
|
|
18
20
|
|
|
19
21
|
@Component({
|
|
20
22
|
standalone: true,
|
|
@@ -34,7 +36,7 @@ import { useStream } from "@langchain/angular";
|
|
|
34
36
|
`,
|
|
35
37
|
})
|
|
36
38
|
export class ChatComponent {
|
|
37
|
-
stream =
|
|
39
|
+
stream = injectStream({
|
|
38
40
|
assistantId: "agent",
|
|
39
41
|
apiUrl: "http://localhost:2024",
|
|
40
42
|
});
|
|
@@ -51,7 +53,7 @@ export class ChatComponent {
|
|
|
51
53
|
}
|
|
52
54
|
```
|
|
53
55
|
|
|
54
|
-
## `
|
|
56
|
+
## `injectStream` Options
|
|
55
57
|
|
|
56
58
|
| Option | Type | Description |
|
|
57
59
|
|---|---|---|
|
|
@@ -105,7 +107,7 @@ interface MyState {
|
|
|
105
107
|
|
|
106
108
|
@Component({ /* ... */ })
|
|
107
109
|
export class ChatComponent {
|
|
108
|
-
stream =
|
|
110
|
+
stream = injectStream<MyState>({
|
|
109
111
|
assistantId: "my-graph",
|
|
110
112
|
apiUrl: "http://localhost:2024",
|
|
111
113
|
});
|
|
@@ -119,7 +121,7 @@ import type { BaseMessage } from "langchain";
|
|
|
119
121
|
|
|
120
122
|
@Component({ /* ... */ })
|
|
121
123
|
export class ChatComponent {
|
|
122
|
-
stream =
|
|
124
|
+
stream = injectStream<
|
|
123
125
|
{ messages: BaseMessage[] },
|
|
124
126
|
{ InterruptType: { question: string } }
|
|
125
127
|
>({
|
|
@@ -136,7 +138,7 @@ export class ChatComponent {
|
|
|
136
138
|
```typescript
|
|
137
139
|
import { Component } from "@angular/core";
|
|
138
140
|
import type { BaseMessage } from "langchain";
|
|
139
|
-
import {
|
|
141
|
+
import { injectStream } from "@langchain/angular";
|
|
140
142
|
|
|
141
143
|
@Component({
|
|
142
144
|
standalone: true,
|
|
@@ -158,7 +160,7 @@ import { useStream } from "@langchain/angular";
|
|
|
158
160
|
`,
|
|
159
161
|
})
|
|
160
162
|
export class ChatComponent {
|
|
161
|
-
stream =
|
|
163
|
+
stream = injectStream<
|
|
162
164
|
{ messages: BaseMessage[] },
|
|
163
165
|
{ InterruptType: { question: string } }
|
|
164
166
|
>({
|
|
@@ -188,7 +190,7 @@ Enable conversation branching with `fetchStateHistory: true`:
|
|
|
188
190
|
|
|
189
191
|
```typescript
|
|
190
192
|
import { Component } from "@angular/core";
|
|
191
|
-
import {
|
|
193
|
+
import { injectStream } from "@langchain/angular";
|
|
192
194
|
|
|
193
195
|
@Component({
|
|
194
196
|
standalone: true,
|
|
@@ -211,7 +213,7 @@ import { useStream } from "@langchain/angular";
|
|
|
211
213
|
`,
|
|
212
214
|
})
|
|
213
215
|
export class ChatComponent {
|
|
214
|
-
stream =
|
|
216
|
+
stream = injectStream({
|
|
215
217
|
assistantId: "agent",
|
|
216
218
|
apiUrl: "http://localhost:2024",
|
|
217
219
|
fetchStateHistory: true,
|
|
@@ -257,7 +259,7 @@ When `submit()` is called while a stream is already active, the SDK automaticall
|
|
|
257
259
|
|
|
258
260
|
```typescript
|
|
259
261
|
import { Component } from "@angular/core";
|
|
260
|
-
import {
|
|
262
|
+
import { injectStream } from "@langchain/angular";
|
|
261
263
|
|
|
262
264
|
@Component({
|
|
263
265
|
standalone: true,
|
|
@@ -285,7 +287,7 @@ import { useStream } from "@langchain/angular";
|
|
|
285
287
|
`,
|
|
286
288
|
})
|
|
287
289
|
export class ChatComponent {
|
|
288
|
-
stream =
|
|
290
|
+
stream = injectStream({
|
|
289
291
|
assistantId: "agent",
|
|
290
292
|
apiUrl: "http://localhost:2024",
|
|
291
293
|
});
|
|
@@ -454,7 +456,7 @@ Instead of connecting to a LangGraph API, you can provide your own streaming tra
|
|
|
454
456
|
|
|
455
457
|
```typescript
|
|
456
458
|
import { Component } from "@angular/core";
|
|
457
|
-
import {
|
|
459
|
+
import { injectStream, FetchStreamTransport } from "@langchain/angular";
|
|
458
460
|
import type { BaseMessage } from "langchain";
|
|
459
461
|
|
|
460
462
|
@Component({
|
|
@@ -482,7 +484,7 @@ import type { BaseMessage } from "langchain";
|
|
|
482
484
|
`,
|
|
483
485
|
})
|
|
484
486
|
export class ChatComponent {
|
|
485
|
-
stream =
|
|
487
|
+
stream = injectStream<{ messages: BaseMessage[] }>({
|
|
486
488
|
transport: new FetchStreamTransport({
|
|
487
489
|
url: "https://my-api.example.com/stream",
|
|
488
490
|
}),
|
|
@@ -507,7 +509,7 @@ export class ChatComponent {
|
|
|
507
509
|
}
|
|
508
510
|
```
|
|
509
511
|
|
|
510
|
-
The custom transport interface returns the same properties as the standard `
|
|
512
|
+
The custom transport interface returns the same properties as the standard `injectStream` function, 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`.
|
|
511
513
|
|
|
512
514
|
## Sharing State with `provideStream`
|
|
513
515
|
|
package/dist/context.cjs
CHANGED
|
@@ -85,58 +85,9 @@ function provideStream(options) {
|
|
|
85
85
|
}
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
|
-
/**
|
|
89
|
-
* Injects the shared stream instance from the nearest ancestor that
|
|
90
|
-
* provided one via `provideStream()`.
|
|
91
|
-
*
|
|
92
|
-
* Throws if no ancestor provides a stream instance.
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```typescript
|
|
96
|
-
* import { Component } from "@angular/core";
|
|
97
|
-
* import { injectStream } from "@langchain/angular";
|
|
98
|
-
*
|
|
99
|
-
* @Component({
|
|
100
|
-
* template: `
|
|
101
|
-
* @for (msg of stream.messages(); track msg.id) {
|
|
102
|
-
* <div>{{ msg.content }}</div>
|
|
103
|
-
* }
|
|
104
|
-
* <button
|
|
105
|
-
* [disabled]="stream.isLoading()"
|
|
106
|
-
* (click)="onSubmit()"
|
|
107
|
-
* >Send</button>
|
|
108
|
-
* `,
|
|
109
|
-
* })
|
|
110
|
-
* export class ChatComponent {
|
|
111
|
-
* stream = injectStream();
|
|
112
|
-
*
|
|
113
|
-
* onSubmit() {
|
|
114
|
-
* void this.stream.submit({
|
|
115
|
-
* messages: [{ type: "human", content: "Hello!" }],
|
|
116
|
-
* });
|
|
117
|
-
* }
|
|
118
|
-
* }
|
|
119
|
-
* ```
|
|
120
|
-
*
|
|
121
|
-
* @example With type parameters for full type safety:
|
|
122
|
-
* ```typescript
|
|
123
|
-
* import type { agent } from "./agent";
|
|
124
|
-
*
|
|
125
|
-
* export class ChatComponent {
|
|
126
|
-
* stream = injectStream<typeof agent>();
|
|
127
|
-
* // stream.messages() returns typed messages
|
|
128
|
-
* }
|
|
129
|
-
* ```
|
|
130
|
-
*/
|
|
131
|
-
function injectStream() {
|
|
132
|
-
const instance = (0, _angular_core.inject)(STREAM_INSTANCE, { optional: true });
|
|
133
|
-
if (instance == null) throw new Error("injectStream() requires an ancestor component to provide a stream via provideStream(). Add provideStream({ assistantId: '...' }) to the providers array of a parent component, or use useStream() directly.");
|
|
134
|
-
return instance;
|
|
135
|
-
}
|
|
136
88
|
//#endregion
|
|
137
89
|
exports.STREAM_DEFAULTS = STREAM_DEFAULTS;
|
|
138
90
|
exports.STREAM_INSTANCE = STREAM_INSTANCE;
|
|
139
|
-
exports.injectStream = injectStream;
|
|
140
91
|
exports.provideStream = provideStream;
|
|
141
92
|
exports.provideStreamDefaults = provideStreamDefaults;
|
|
142
93
|
|
package/dist/context.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.cjs","names":["InjectionToken","useStream"],"sources":["../src/context.ts"],"sourcesContent":["import {\n InjectionToken,\n inject as angularInject,\n type EnvironmentProviders,\n makeEnvironmentProviders,\n} from \"@angular/core\";\nimport type { BagTemplate } from \"@langchain/langgraph-sdk\";\nimport { Client } from \"@langchain/langgraph-sdk\";\nimport type {\n ResolveStreamOptions,\n InferBag,\n InferStateType,\n UseStreamCustomOptions,\n} from \"@langchain/langgraph-sdk/ui\";\nimport { useStream } from \"./index.js\";\n\n/**\n * Configuration defaults for `useStream` and `injectStream` calls.\n */\nexport interface StreamDefaults {\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/**\n * Injection token for stream default configuration.\n * Provide via `provideStreamDefaults()` in your application config.\n */\nexport const STREAM_DEFAULTS = new InjectionToken<StreamDefaults>(\n \"LANGCHAIN_STREAM_DEFAULTS\",\n);\n\n/**\n * Injection token for a shared stream instance.\n * Provide via `provideStream()` at the component level.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const STREAM_INSTANCE = new InjectionToken<any>(\n \"LANGCHAIN_STREAM_INSTANCE\",\n);\n\n/**\n * Provides default LangGraph configuration at the application level.\n *\n * Use this in your application's `providers` array to set defaults like\n * `apiUrl` that will be used by all `useStream` and `injectStream` calls.\n *\n * @example\n * ```typescript\n * // app.config.ts\n * import { ApplicationConfig } from \"@angular/core\";\n * import { provideStreamDefaults } from \"@langchain/angular\";\n *\n * export const appConfig: ApplicationConfig = {\n * providers: [\n * provideStreamDefaults({\n * apiUrl: \"http://localhost:2024\",\n * }),\n * ],\n * };\n * ```\n */\nexport function provideStreamDefaults(\n defaults: StreamDefaults,\n): EnvironmentProviders {\n return makeEnvironmentProviders([\n { provide: STREAM_DEFAULTS, useValue: defaults },\n ]);\n}\n\n/**\n * Creates a provider for a shared `useStream` instance at the component level.\n *\n * Add the returned provider to a component's `providers` array so that all\n * child components can access the same stream via `injectStream()`.\n *\n * @example\n * ```typescript\n * import { Component } from \"@angular/core\";\n * import { provideStream, injectStream } from \"@langchain/angular\";\n *\n * @Component({\n * providers: [provideStream({ assistantId: \"agent\" })],\n * template: `\n * <app-message-list />\n * <app-message-input />\n * `,\n * })\n * export class ChatContainer {}\n *\n * // In child components:\n * @Component({\n * template: `\n * @for (msg of stream.messages(); track msg.id) {\n * <div>{{ msg.content }}</div>\n * }\n * `,\n * })\n * export class MessageListComponent {\n * stream = injectStream();\n * }\n * ```\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) {\n return {\n provide: STREAM_INSTANCE,\n useFactory: () => {\n const defaults = angularInject(STREAM_DEFAULTS, { optional: true });\n const merged = {\n ...(defaults ?? {}),\n ...options,\n apiUrl: (options as Record<string, unknown>).apiUrl ?? defaults?.apiUrl,\n client: (options as Record<string, unknown>).client ?? defaults?.client,\n };\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return useStream(merged as any);\n },\n };\n}\n
|
|
1
|
+
{"version":3,"file":"context.cjs","names":["InjectionToken","useStream"],"sources":["../src/context.ts"],"sourcesContent":["import {\n InjectionToken,\n inject as angularInject,\n type EnvironmentProviders,\n makeEnvironmentProviders,\n} from \"@angular/core\";\nimport type { BagTemplate } from \"@langchain/langgraph-sdk\";\nimport { Client } from \"@langchain/langgraph-sdk\";\nimport type {\n ResolveStreamOptions,\n InferBag,\n InferStateType,\n UseStreamCustomOptions,\n} from \"@langchain/langgraph-sdk/ui\";\nimport { useStream } from \"./index.js\";\n\n/**\n * Configuration defaults for `useStream` and `injectStream` calls.\n */\nexport interface StreamDefaults {\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/**\n * Injection token for stream default configuration.\n * Provide via `provideStreamDefaults()` in your application config.\n */\nexport const STREAM_DEFAULTS = new InjectionToken<StreamDefaults>(\n \"LANGCHAIN_STREAM_DEFAULTS\",\n);\n\n/**\n * Injection token for a shared stream instance.\n * Provide via `provideStream()` at the component level.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const STREAM_INSTANCE = new InjectionToken<any>(\n \"LANGCHAIN_STREAM_INSTANCE\",\n);\n\n/**\n * Provides default LangGraph configuration at the application level.\n *\n * Use this in your application's `providers` array to set defaults like\n * `apiUrl` that will be used by all `useStream` and `injectStream` calls.\n *\n * @example\n * ```typescript\n * // app.config.ts\n * import { ApplicationConfig } from \"@angular/core\";\n * import { provideStreamDefaults } from \"@langchain/angular\";\n *\n * export const appConfig: ApplicationConfig = {\n * providers: [\n * provideStreamDefaults({\n * apiUrl: \"http://localhost:2024\",\n * }),\n * ],\n * };\n * ```\n */\nexport function provideStreamDefaults(\n defaults: StreamDefaults,\n): EnvironmentProviders {\n return makeEnvironmentProviders([\n { provide: STREAM_DEFAULTS, useValue: defaults },\n ]);\n}\n\n/**\n * Creates a provider for a shared `useStream` instance at the component level.\n *\n * Add the returned provider to a component's `providers` array so that all\n * child components can access the same stream via `injectStream()`.\n *\n * @example\n * ```typescript\n * import { Component } from \"@angular/core\";\n * import { provideStream, injectStream } from \"@langchain/angular\";\n *\n * @Component({\n * providers: [provideStream({ assistantId: \"agent\" })],\n * template: `\n * <app-message-list />\n * <app-message-input />\n * `,\n * })\n * export class ChatContainer {}\n *\n * // In child components:\n * @Component({\n * template: `\n * @for (msg of stream.messages(); track msg.id) {\n * <div>{{ msg.content }}</div>\n * }\n * `,\n * })\n * export class MessageListComponent {\n * stream = injectStream();\n * }\n * ```\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) {\n return {\n provide: STREAM_INSTANCE,\n useFactory: () => {\n const defaults = angularInject(STREAM_DEFAULTS, { optional: true });\n const merged = {\n ...(defaults ?? {}),\n ...options,\n apiUrl: (options as Record<string, unknown>).apiUrl ?? defaults?.apiUrl,\n client: (options as Record<string, unknown>).client ?? defaults?.client,\n };\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return useStream(merged as any);\n },\n };\n}\n"],"mappings":";;;;;;;AAgCA,MAAa,kBAAkB,IAAIA,cAAAA,eACjC,4BACD;;;;;AAOD,MAAa,kBAAkB,IAAIA,cAAAA,eACjC,4BACD;;;;;;;;;;;;;;;;;;;;;;AAuBD,SAAgB,sBACd,UACsB;AACtB,SAAA,GAAA,cAAA,0BAAgC,CAC9B;EAAE,SAAS;EAAiB,UAAU;EAAU,CACjD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCJ,SAAgB,cAId,SAGA;AACA,QAAO;EACL,SAAS;EACT,kBAAkB;GAChB,MAAM,YAAA,GAAA,cAAA,QAAyB,iBAAiB,EAAE,UAAU,MAAM,CAAC;AAQnE,UAAOC,cAAAA,UAPQ;IACb,GAAI,YAAY,EAAE;IAClB,GAAG;IACH,QAAS,QAAoC,UAAU,UAAU;IACjE,QAAS,QAAoC,UAAU,UAAU;IAClE,CAE8B;;EAElC"}
|
package/dist/context.d.cts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BaseMessage as BaseMessage$1 } from "./node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_@opentelemetry_api@1.9.0_openai@6.27.0_ws@8.19._0520fb05d9e85da5f9e061dfe28cdbc8/node_modules/langchain/dist/index.cjs";
|
|
2
|
-
import { useStream } from "./index.cjs";
|
|
3
2
|
import * as _langchain_langgraph_sdk0 from "@langchain/langgraph-sdk";
|
|
4
3
|
import { BagTemplate, Client } from "@langchain/langgraph-sdk";
|
|
5
4
|
import * as _langchain_core_messages0 from "@langchain/core/messages";
|
|
@@ -126,50 +125,6 @@ declare function provideStream<T = Record<string, unknown>, Bag extends BagTempl
|
|
|
126
125
|
} | null | undefined, options?: _langchain_langgraph_sdk_ui0.SubmitOptions<Record<string, unknown>, Record<string, unknown>> | undefined) => Promise<void>;
|
|
127
126
|
};
|
|
128
127
|
};
|
|
129
|
-
/**
|
|
130
|
-
* Injects the shared stream instance from the nearest ancestor that
|
|
131
|
-
* provided one via `provideStream()`.
|
|
132
|
-
*
|
|
133
|
-
* Throws if no ancestor provides a stream instance.
|
|
134
|
-
*
|
|
135
|
-
* @example
|
|
136
|
-
* ```typescript
|
|
137
|
-
* import { Component } from "@angular/core";
|
|
138
|
-
* import { injectStream } from "@langchain/angular";
|
|
139
|
-
*
|
|
140
|
-
* @Component({
|
|
141
|
-
* template: `
|
|
142
|
-
* @for (msg of stream.messages(); track msg.id) {
|
|
143
|
-
* <div>{{ msg.content }}</div>
|
|
144
|
-
* }
|
|
145
|
-
* <button
|
|
146
|
-
* [disabled]="stream.isLoading()"
|
|
147
|
-
* (click)="onSubmit()"
|
|
148
|
-
* >Send</button>
|
|
149
|
-
* `,
|
|
150
|
-
* })
|
|
151
|
-
* export class ChatComponent {
|
|
152
|
-
* stream = injectStream();
|
|
153
|
-
*
|
|
154
|
-
* onSubmit() {
|
|
155
|
-
* void this.stream.submit({
|
|
156
|
-
* messages: [{ type: "human", content: "Hello!" }],
|
|
157
|
-
* });
|
|
158
|
-
* }
|
|
159
|
-
* }
|
|
160
|
-
* ```
|
|
161
|
-
*
|
|
162
|
-
* @example With type parameters for full type safety:
|
|
163
|
-
* ```typescript
|
|
164
|
-
* import type { agent } from "./agent";
|
|
165
|
-
*
|
|
166
|
-
* export class ChatComponent {
|
|
167
|
-
* stream = injectStream<typeof agent>();
|
|
168
|
-
* // stream.messages() returns typed messages
|
|
169
|
-
* }
|
|
170
|
-
* ```
|
|
171
|
-
*/
|
|
172
|
-
declare function injectStream<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(): ReturnType<typeof useStream<T, Bag>>;
|
|
173
128
|
//#endregion
|
|
174
|
-
export { STREAM_DEFAULTS, STREAM_INSTANCE, StreamDefaults,
|
|
129
|
+
export { STREAM_DEFAULTS, STREAM_INSTANCE, StreamDefaults, provideStream, provideStreamDefaults };
|
|
175
130
|
//# sourceMappingURL=context.d.cts.map
|
package/dist/context.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.cts","names":[],"sources":["../src/context.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"context.d.cts","names":[],"sources":["../src/context.ts"],"mappings":";;;;;;;;;;;;;UAmBiB,cAAA;;EAEf,MAAA;EAFe;EAIf,MAAA;;EAEA,MAAA,GAAS,MAAA;AAAA;;;;;cAOE,eAAA,EAAe,cAAA,CAAA,cAAA;AAA5B;;;;AAAA,cASa,eAAA,EAAe,cAAA;AAA5B;;;;;AAyBA;;;;;;;;;AAyCA;;;;;;;AAlEA,iBAyBgB,qBAAA,CACd,QAAA,EAAU,cAAA,GACT,oBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuCa,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"}
|
package/dist/context.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BaseMessage as BaseMessage$1 } from "./node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_@opentelemetry_api@1.9.0_openai@6.27.0_ws@8.19._0520fb05d9e85da5f9e061dfe28cdbc8/node_modules/langchain/dist/index.js";
|
|
2
|
-
import { useStream } from "./index.js";
|
|
3
2
|
import * as _angular_core0 from "@angular/core";
|
|
4
3
|
import { EnvironmentProviders, InjectionToken } from "@angular/core";
|
|
5
4
|
import * as _langchain_langgraph_sdk_ui0 from "@langchain/langgraph-sdk/ui";
|
|
@@ -126,50 +125,6 @@ declare function provideStream<T = Record<string, unknown>, Bag extends BagTempl
|
|
|
126
125
|
} | null | undefined, options?: _langchain_langgraph_sdk_ui0.SubmitOptions<Record<string, unknown>, Record<string, unknown>> | undefined) => Promise<void>;
|
|
127
126
|
};
|
|
128
127
|
};
|
|
129
|
-
/**
|
|
130
|
-
* Injects the shared stream instance from the nearest ancestor that
|
|
131
|
-
* provided one via `provideStream()`.
|
|
132
|
-
*
|
|
133
|
-
* Throws if no ancestor provides a stream instance.
|
|
134
|
-
*
|
|
135
|
-
* @example
|
|
136
|
-
* ```typescript
|
|
137
|
-
* import { Component } from "@angular/core";
|
|
138
|
-
* import { injectStream } from "@langchain/angular";
|
|
139
|
-
*
|
|
140
|
-
* @Component({
|
|
141
|
-
* template: `
|
|
142
|
-
* @for (msg of stream.messages(); track msg.id) {
|
|
143
|
-
* <div>{{ msg.content }}</div>
|
|
144
|
-
* }
|
|
145
|
-
* <button
|
|
146
|
-
* [disabled]="stream.isLoading()"
|
|
147
|
-
* (click)="onSubmit()"
|
|
148
|
-
* >Send</button>
|
|
149
|
-
* `,
|
|
150
|
-
* })
|
|
151
|
-
* export class ChatComponent {
|
|
152
|
-
* stream = injectStream();
|
|
153
|
-
*
|
|
154
|
-
* onSubmit() {
|
|
155
|
-
* void this.stream.submit({
|
|
156
|
-
* messages: [{ type: "human", content: "Hello!" }],
|
|
157
|
-
* });
|
|
158
|
-
* }
|
|
159
|
-
* }
|
|
160
|
-
* ```
|
|
161
|
-
*
|
|
162
|
-
* @example With type parameters for full type safety:
|
|
163
|
-
* ```typescript
|
|
164
|
-
* import type { agent } from "./agent";
|
|
165
|
-
*
|
|
166
|
-
* export class ChatComponent {
|
|
167
|
-
* stream = injectStream<typeof agent>();
|
|
168
|
-
* // stream.messages() returns typed messages
|
|
169
|
-
* }
|
|
170
|
-
* ```
|
|
171
|
-
*/
|
|
172
|
-
declare function injectStream<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(): ReturnType<typeof useStream<T, Bag>>;
|
|
173
128
|
//#endregion
|
|
174
|
-
export { STREAM_DEFAULTS, STREAM_INSTANCE, StreamDefaults,
|
|
129
|
+
export { STREAM_DEFAULTS, STREAM_INSTANCE, StreamDefaults, provideStream, provideStreamDefaults };
|
|
175
130
|
//# sourceMappingURL=context.d.ts.map
|
package/dist/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","names":[],"sources":["../src/context.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"context.d.ts","names":[],"sources":["../src/context.ts"],"mappings":";;;;;;;;;;;;;UAmBiB,cAAA;;EAEf,MAAA;EAFe;EAIf,MAAA;;EAEA,MAAA,GAAS,MAAA;AAAA;;;;;cAOE,eAAA,EAAe,cAAA,CAAA,cAAA;AAA5B;;;;AAAA,cASa,eAAA,EAAe,cAAA;AAA5B;;;;;AAyBA;;;;;;;;;AAyCA;;;;;;;AAlEA,iBAyBgB,qBAAA,CACd,QAAA,EAAU,cAAA,GACT,oBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuCa,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"}
|
package/dist/context.js
CHANGED
|
@@ -85,55 +85,7 @@ function provideStream(options) {
|
|
|
85
85
|
}
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
|
-
/**
|
|
89
|
-
* Injects the shared stream instance from the nearest ancestor that
|
|
90
|
-
* provided one via `provideStream()`.
|
|
91
|
-
*
|
|
92
|
-
* Throws if no ancestor provides a stream instance.
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```typescript
|
|
96
|
-
* import { Component } from "@angular/core";
|
|
97
|
-
* import { injectStream } from "@langchain/angular";
|
|
98
|
-
*
|
|
99
|
-
* @Component({
|
|
100
|
-
* template: `
|
|
101
|
-
* @for (msg of stream.messages(); track msg.id) {
|
|
102
|
-
* <div>{{ msg.content }}</div>
|
|
103
|
-
* }
|
|
104
|
-
* <button
|
|
105
|
-
* [disabled]="stream.isLoading()"
|
|
106
|
-
* (click)="onSubmit()"
|
|
107
|
-
* >Send</button>
|
|
108
|
-
* `,
|
|
109
|
-
* })
|
|
110
|
-
* export class ChatComponent {
|
|
111
|
-
* stream = injectStream();
|
|
112
|
-
*
|
|
113
|
-
* onSubmit() {
|
|
114
|
-
* void this.stream.submit({
|
|
115
|
-
* messages: [{ type: "human", content: "Hello!" }],
|
|
116
|
-
* });
|
|
117
|
-
* }
|
|
118
|
-
* }
|
|
119
|
-
* ```
|
|
120
|
-
*
|
|
121
|
-
* @example With type parameters for full type safety:
|
|
122
|
-
* ```typescript
|
|
123
|
-
* import type { agent } from "./agent";
|
|
124
|
-
*
|
|
125
|
-
* export class ChatComponent {
|
|
126
|
-
* stream = injectStream<typeof agent>();
|
|
127
|
-
* // stream.messages() returns typed messages
|
|
128
|
-
* }
|
|
129
|
-
* ```
|
|
130
|
-
*/
|
|
131
|
-
function injectStream() {
|
|
132
|
-
const instance = inject(STREAM_INSTANCE, { optional: true });
|
|
133
|
-
if (instance == null) throw new Error("injectStream() requires an ancestor component to provide a stream via provideStream(). Add provideStream({ assistantId: '...' }) to the providers array of a parent component, or use useStream() directly.");
|
|
134
|
-
return instance;
|
|
135
|
-
}
|
|
136
88
|
//#endregion
|
|
137
|
-
export { STREAM_DEFAULTS, STREAM_INSTANCE,
|
|
89
|
+
export { STREAM_DEFAULTS, STREAM_INSTANCE, provideStream, provideStreamDefaults };
|
|
138
90
|
|
|
139
91
|
//# sourceMappingURL=context.js.map
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","names":["angularInject"],"sources":["../src/context.ts"],"sourcesContent":["import {\n InjectionToken,\n inject as angularInject,\n type EnvironmentProviders,\n makeEnvironmentProviders,\n} from \"@angular/core\";\nimport type { BagTemplate } from \"@langchain/langgraph-sdk\";\nimport { Client } from \"@langchain/langgraph-sdk\";\nimport type {\n ResolveStreamOptions,\n InferBag,\n InferStateType,\n UseStreamCustomOptions,\n} from \"@langchain/langgraph-sdk/ui\";\nimport { useStream } from \"./index.js\";\n\n/**\n * Configuration defaults for `useStream` and `injectStream` calls.\n */\nexport interface StreamDefaults {\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/**\n * Injection token for stream default configuration.\n * Provide via `provideStreamDefaults()` in your application config.\n */\nexport const STREAM_DEFAULTS = new InjectionToken<StreamDefaults>(\n \"LANGCHAIN_STREAM_DEFAULTS\",\n);\n\n/**\n * Injection token for a shared stream instance.\n * Provide via `provideStream()` at the component level.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const STREAM_INSTANCE = new InjectionToken<any>(\n \"LANGCHAIN_STREAM_INSTANCE\",\n);\n\n/**\n * Provides default LangGraph configuration at the application level.\n *\n * Use this in your application's `providers` array to set defaults like\n * `apiUrl` that will be used by all `useStream` and `injectStream` calls.\n *\n * @example\n * ```typescript\n * // app.config.ts\n * import { ApplicationConfig } from \"@angular/core\";\n * import { provideStreamDefaults } from \"@langchain/angular\";\n *\n * export const appConfig: ApplicationConfig = {\n * providers: [\n * provideStreamDefaults({\n * apiUrl: \"http://localhost:2024\",\n * }),\n * ],\n * };\n * ```\n */\nexport function provideStreamDefaults(\n defaults: StreamDefaults,\n): EnvironmentProviders {\n return makeEnvironmentProviders([\n { provide: STREAM_DEFAULTS, useValue: defaults },\n ]);\n}\n\n/**\n * Creates a provider for a shared `useStream` instance at the component level.\n *\n * Add the returned provider to a component's `providers` array so that all\n * child components can access the same stream via `injectStream()`.\n *\n * @example\n * ```typescript\n * import { Component } from \"@angular/core\";\n * import { provideStream, injectStream } from \"@langchain/angular\";\n *\n * @Component({\n * providers: [provideStream({ assistantId: \"agent\" })],\n * template: `\n * <app-message-list />\n * <app-message-input />\n * `,\n * })\n * export class ChatContainer {}\n *\n * // In child components:\n * @Component({\n * template: `\n * @for (msg of stream.messages(); track msg.id) {\n * <div>{{ msg.content }}</div>\n * }\n * `,\n * })\n * export class MessageListComponent {\n * stream = injectStream();\n * }\n * ```\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) {\n return {\n provide: STREAM_INSTANCE,\n useFactory: () => {\n const defaults = angularInject(STREAM_DEFAULTS, { optional: true });\n const merged = {\n ...(defaults ?? {}),\n ...options,\n apiUrl: (options as Record<string, unknown>).apiUrl ?? defaults?.apiUrl,\n client: (options as Record<string, unknown>).client ?? defaults?.client,\n };\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return useStream(merged as any);\n },\n };\n}\n
|
|
1
|
+
{"version":3,"file":"context.js","names":["angularInject"],"sources":["../src/context.ts"],"sourcesContent":["import {\n InjectionToken,\n inject as angularInject,\n type EnvironmentProviders,\n makeEnvironmentProviders,\n} from \"@angular/core\";\nimport type { BagTemplate } from \"@langchain/langgraph-sdk\";\nimport { Client } from \"@langchain/langgraph-sdk\";\nimport type {\n ResolveStreamOptions,\n InferBag,\n InferStateType,\n UseStreamCustomOptions,\n} from \"@langchain/langgraph-sdk/ui\";\nimport { useStream } from \"./index.js\";\n\n/**\n * Configuration defaults for `useStream` and `injectStream` calls.\n */\nexport interface StreamDefaults {\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/**\n * Injection token for stream default configuration.\n * Provide via `provideStreamDefaults()` in your application config.\n */\nexport const STREAM_DEFAULTS = new InjectionToken<StreamDefaults>(\n \"LANGCHAIN_STREAM_DEFAULTS\",\n);\n\n/**\n * Injection token for a shared stream instance.\n * Provide via `provideStream()` at the component level.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const STREAM_INSTANCE = new InjectionToken<any>(\n \"LANGCHAIN_STREAM_INSTANCE\",\n);\n\n/**\n * Provides default LangGraph configuration at the application level.\n *\n * Use this in your application's `providers` array to set defaults like\n * `apiUrl` that will be used by all `useStream` and `injectStream` calls.\n *\n * @example\n * ```typescript\n * // app.config.ts\n * import { ApplicationConfig } from \"@angular/core\";\n * import { provideStreamDefaults } from \"@langchain/angular\";\n *\n * export const appConfig: ApplicationConfig = {\n * providers: [\n * provideStreamDefaults({\n * apiUrl: \"http://localhost:2024\",\n * }),\n * ],\n * };\n * ```\n */\nexport function provideStreamDefaults(\n defaults: StreamDefaults,\n): EnvironmentProviders {\n return makeEnvironmentProviders([\n { provide: STREAM_DEFAULTS, useValue: defaults },\n ]);\n}\n\n/**\n * Creates a provider for a shared `useStream` instance at the component level.\n *\n * Add the returned provider to a component's `providers` array so that all\n * child components can access the same stream via `injectStream()`.\n *\n * @example\n * ```typescript\n * import { Component } from \"@angular/core\";\n * import { provideStream, injectStream } from \"@langchain/angular\";\n *\n * @Component({\n * providers: [provideStream({ assistantId: \"agent\" })],\n * template: `\n * <app-message-list />\n * <app-message-input />\n * `,\n * })\n * export class ChatContainer {}\n *\n * // In child components:\n * @Component({\n * template: `\n * @for (msg of stream.messages(); track msg.id) {\n * <div>{{ msg.content }}</div>\n * }\n * `,\n * })\n * export class MessageListComponent {\n * stream = injectStream();\n * }\n * ```\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) {\n return {\n provide: STREAM_INSTANCE,\n useFactory: () => {\n const defaults = angularInject(STREAM_DEFAULTS, { optional: true });\n const merged = {\n ...(defaults ?? {}),\n ...options,\n apiUrl: (options as Record<string, unknown>).apiUrl ?? defaults?.apiUrl,\n client: (options as Record<string, unknown>).client ?? defaults?.client,\n };\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return useStream(merged as any);\n },\n };\n}\n"],"mappings":";;;;;;;AAgCA,MAAa,kBAAkB,IAAI,eACjC,4BACD;;;;;AAOD,MAAa,kBAAkB,IAAI,eACjC,4BACD;;;;;;;;;;;;;;;;;;;;;;AAuBD,SAAgB,sBACd,UACsB;AACtB,QAAO,yBAAyB,CAC9B;EAAE,SAAS;EAAiB,UAAU;EAAU,CACjD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCJ,SAAgB,cAId,SAGA;AACA,QAAO;EACL,SAAS;EACT,kBAAkB;GAChB,MAAM,WAAWA,OAAc,iBAAiB,EAAE,UAAU,MAAM,CAAC;AAQnE,UAAO,UAPQ;IACb,GAAI,YAAY,EAAE;IAClB,GAAG;IACH,QAAS,QAAoC,UAAU,UAAU;IACjE,QAAS,QAAoC,UAAU,UAAU;IAClE,CAE8B;;EAElC"}
|