@langchain/angular 0.2.0 → 0.3.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/README.md +17 -15
- package/dist/context.cjs +6 -52
- package/dist/context.cjs.map +1 -1
- package/dist/context.d.cts +55 -71
- package/dist/context.d.cts.map +1 -1
- package/dist/context.d.ts +51 -67
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +7 -52
- package/dist/context.js.map +1 -1
- package/dist/index.cjs +26 -462
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +255 -104
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +254 -103
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -463
- 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-service-instance.d.cts +70 -0
- package/dist/stream-service-instance.d.cts.map +1 -0
- package/dist/stream-service-instance.d.ts +70 -0
- package/dist/stream-service-instance.d.ts.map +1 -0
- package/dist/stream.custom.cjs +59 -161
- 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 +60 -163
- package/dist/stream.custom.js.map +1 -1
- package/dist/stream.lgp.cjs +163 -0
- package/dist/stream.lgp.cjs.map +1 -0
- package/dist/stream.lgp.d.cts +57 -0
- package/dist/stream.lgp.d.cts.map +1 -0
- package/dist/stream.lgp.d.ts +57 -0
- package/dist/stream.lgp.d.ts.map +1 -0
- package/dist/stream.lgp.js +163 -0
- package/dist/stream.lgp.js.map +1 -0
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,53 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { injectStreamCustom, useStreamCustom } from "./stream.custom.js";
|
|
2
|
+
import { STREAM_DEFAULTS, STREAM_INSTANCE, StreamDefaults, provideStream, provideStreamDefaults } from "./context.js";
|
|
3
|
+
import { useStreamLGP } from "./stream.lgp.js";
|
|
2
4
|
import { Signal, WritableSignal } from "@angular/core";
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import * as _langchain_langgraph_sdk0 from "@langchain/langgraph-sdk";
|
|
6
|
-
import { BagTemplate, Client, DefaultToolCall, DefaultToolCall as DefaultToolCall$1, Interrupt, Message, StreamEvent, StreamMode, ThreadState, ToolCallFromTool, ToolCallState, ToolCallWithResult as ToolCallWithResult$1, ToolCallsFromTools } from "@langchain/langgraph-sdk";
|
|
7
|
-
import * as _langchain_core_messages0 from "@langchain/core/messages";
|
|
5
|
+
import { AcceptBaseMessages, AgentTypeConfigLike, BaseStream, BaseSubagentState, ClassSubagentStreamInterface, CompiledSubAgentLike, DeepAgentTypeConfigLike, DefaultSubagentStates, ExtractAgentConfig, ExtractDeepAgentConfig, ExtractSubAgentMiddleware, FetchStreamTransport, GetConfigurableType, GetInterruptType, GetToolCallsType, InferAgentToolCalls, InferBag, InferBag as InferBag$1, InferDeepAgentSubagents, InferNodeNames, InferStateType, InferStateType as InferStateType$1, InferSubagentByName, InferSubagentNames, InferSubagentState, InferSubagentStates, InferToolCalls, IsAgentLike, IsDeepAgentLike, MessageMetadata, MessageMetadata as MessageMetadata$1, QueueEntry, QueueInterface, ResolveStreamInterface, ResolveStreamInterface as ResolveStreamInterface$1, ResolveStreamOptions, ResolveStreamOptions as ResolveStreamOptions$1, SubAgentLike, SubagentApi, SubagentManager, SubagentStateMap, SubagentStatus, SubagentStream, SubagentStreamInterface, SubagentStreamInterface as SubagentStreamInterface$1, SubagentToolCall, SubmitOptions, UseAgentStream, UseAgentStreamOptions, UseDeepAgentStream, UseDeepAgentStreamOptions, UseStreamCustomOptions, UseStreamCustomOptions as UseStreamCustomOptions$1, UseStreamOptions, UseStreamThread, UseStreamTransport, WithClassMessages, calculateDepthFromNamespace, extractParentIdFromNamespace, extractToolCallIdFromNamespace, isSubagentNamespace } from "@langchain/langgraph-sdk/ui";
|
|
6
|
+
import { BagTemplate, Client, DefaultToolCall, DefaultToolCall as DefaultToolCall$1, Interrupt, StreamEvent, StreamMode, ToolCallFromTool, ToolCallState, ToolCallWithResult as ToolCallWithResult$1, ToolCallsFromTools } from "@langchain/langgraph-sdk";
|
|
8
7
|
import { AIMessage, BaseMessage, ToolMessage } from "@langchain/core/messages";
|
|
9
8
|
|
|
10
9
|
//#region src/index.d.ts
|
|
11
|
-
type ClassToolCallWithResult<T> = T extends ToolCallWithResult$1<infer TC, unknown, unknown> ? ToolCallWithResult$1<TC, ToolMessage, AIMessage> : T;
|
|
12
|
-
type ClassSubagentStreamInterface<StateType = Record<string, unknown>, ToolCall = DefaultToolCall$1, SubagentName extends string = string> = Omit<SubagentStreamInterface$1<StateType, ToolCall, SubagentName>, "messages"> & {
|
|
13
|
-
messages: BaseMessage[];
|
|
14
|
-
};
|
|
15
|
-
type WithClassMessages<T> = Omit<T, "messages" | "history" | "getMessagesMetadata" | "toolCalls" | "getToolCalls" | "submit" | "subagents" | "activeSubagents" | "getSubagent" | "getSubagentsByType" | "getSubagentsByMessage"> & {
|
|
16
|
-
messages: BaseMessage[];
|
|
17
|
-
getMessagesMetadata: (message: BaseMessage, index?: number) => MessageMetadata$1<Record<string, unknown>> | undefined;
|
|
18
|
-
} & ("history" extends keyof T ? {
|
|
19
|
-
history: HistoryWithBaseMessages<T["history"]>;
|
|
20
|
-
} : unknown) & ("submit" extends keyof T ? {
|
|
21
|
-
submit: T extends {
|
|
22
|
-
submit: (values: infer V, options?: infer O) => infer Ret;
|
|
23
|
-
} ? (values: AcceptBaseMessages<Exclude<V, null | undefined>> | null | undefined, options?: O) => Ret : never;
|
|
24
|
-
} : unknown) & ("toolCalls" extends keyof T ? {
|
|
25
|
-
toolCalls: T extends {
|
|
26
|
-
toolCalls: (infer TC)[];
|
|
27
|
-
} ? ClassToolCallWithResult<TC>[] : never;
|
|
28
|
-
} : unknown) & ("getToolCalls" extends keyof T ? {
|
|
29
|
-
getToolCalls: T extends {
|
|
30
|
-
getToolCalls: (message: infer _M) => (infer TC)[];
|
|
31
|
-
} ? (message: AIMessage) => ClassToolCallWithResult<TC>[] : never;
|
|
32
|
-
} : unknown) & ("subagents" extends keyof T ? {
|
|
33
|
-
subagents: T extends {
|
|
34
|
-
subagents: Map<string, SubagentStreamInterface$1<infer S, infer TC, infer N>>;
|
|
35
|
-
} ? Map<string, ClassSubagentStreamInterface<S, TC, N>> : never;
|
|
36
|
-
activeSubagents: T extends {
|
|
37
|
-
activeSubagents: SubagentStreamInterface$1<infer S, infer TC, infer N>[];
|
|
38
|
-
} ? ClassSubagentStreamInterface<S, TC, N>[] : never;
|
|
39
|
-
getSubagent: T extends {
|
|
40
|
-
getSubagent: (id: string) => SubagentStreamInterface$1<infer S, infer TC, infer N> | undefined;
|
|
41
|
-
} ? (toolCallId: string) => ClassSubagentStreamInterface<S, TC, N> | undefined : never;
|
|
42
|
-
getSubagentsByType: T extends {
|
|
43
|
-
getSubagentsByType: (type: string) => SubagentStreamInterface$1<infer S, infer TC, infer N>[];
|
|
44
|
-
} ? (type: string) => ClassSubagentStreamInterface<S, TC, N>[] : never;
|
|
45
|
-
getSubagentsByMessage: T extends {
|
|
46
|
-
getSubagentsByMessage: (id: string) => SubagentStreamInterface$1<infer S, infer TC, infer N>[];
|
|
47
|
-
} ? (messageId: string) => ClassSubagentStreamInterface<S, TC, N>[] : never;
|
|
48
|
-
} : unknown);
|
|
49
10
|
type AngularWritableKeys = "isLoading" | "branch";
|
|
50
|
-
type AngularPlainKeys = "submit" | "stop" | "joinStream" | "switchThread" | "setBranch" | "getMessagesMetadata" | "getToolCalls" | "getSubagent" | "getSubagentsByType" | "getSubagentsByMessage" | "
|
|
11
|
+
type AngularPlainKeys = "submit" | "stop" | "joinStream" | "switchThread" | "setBranch" | "getMessagesMetadata" | "getToolCalls" | "getSubagent" | "getSubagentsByType" | "getSubagentsByMessage" | "client" | "assistantId";
|
|
51
12
|
type AngularQueueInterface<T> = T extends {
|
|
52
13
|
entries: infer E;
|
|
53
14
|
size: infer S;
|
|
@@ -60,55 +21,245 @@ type AngularQueueInterface<T> = T extends {
|
|
|
60
21
|
clear: Cl;
|
|
61
22
|
} : T;
|
|
62
23
|
type AngularSignalWrap<T> = { [K in keyof T]: K extends AngularPlainKeys ? T[K] : K extends AngularWritableKeys ? WritableSignal<T[K]> : K extends "queue" ? AngularQueueInterface<T[K]> : Signal<T[K]> };
|
|
63
|
-
declare function useStream<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(options: ResolveStreamOptions$1<T, InferBag$1<T, Bag>>): AngularSignalWrap<WithClassMessages<ResolveStreamInterface$1<T, InferBag$1<T, Bag>>>>;
|
|
64
|
-
declare function useStream<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(options: UseStreamCustomOptions$1<InferStateType$1<T>, InferBag$1<T, Bag>>): AngularSignalWrap<WithClassMessages<ResolveStreamInterface$1<T, InferBag$1<T, Bag>>>>;
|
|
65
|
-
declare function useStreamLGP<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {
|
|
66
|
-
ConfigurableType?: Record<string, unknown>;
|
|
67
|
-
InterruptType?: unknown;
|
|
68
|
-
CustomEventType?: unknown;
|
|
69
|
-
UpdateType?: unknown;
|
|
70
|
-
} = BagTemplate>(options: AnyStreamOptions<StateType, Bag>): {
|
|
71
|
-
assistantId: string;
|
|
72
|
-
client: Client<_langchain_langgraph_sdk0.DefaultValues, _langchain_langgraph_sdk0.DefaultValues, unknown>;
|
|
73
|
-
values: Signal<any>;
|
|
74
|
-
error: Signal<unknown>;
|
|
75
|
-
isLoading: WritableSignal<boolean>;
|
|
76
|
-
branch: WritableSignal<string>;
|
|
77
|
-
setBranch: (value: string) => void;
|
|
78
|
-
messages: Signal<(BaseMessage<_langchain_core_messages0.MessageStructure<_langchain_core_messages0.MessageToolSet>, _langchain_core_messages0.MessageType> | _langchain_core_messages0.BaseMessageChunk<_langchain_core_messages0.MessageStructure<_langchain_core_messages0.MessageToolSet>, _langchain_core_messages0.MessageType>)[]>;
|
|
79
|
-
toolCalls: Signal<ToolCallWithResult$1<DefaultToolCall$1>[]>;
|
|
80
|
-
getToolCalls: (message: Message) => ToolCallWithResult$1<DefaultToolCall$1>[];
|
|
81
|
-
interrupt: Signal<Interrupt<GetInterruptType<Bag>> | undefined>;
|
|
82
|
-
interrupts: Signal<Interrupt<GetInterruptType<Bag>>[]>;
|
|
83
|
-
history: Signal<ThreadState<any>[]>;
|
|
84
|
-
isThreadLoading: Signal<boolean>;
|
|
85
|
-
experimental_branchTree: Signal<_langchain_langgraph_sdk_ui0.Sequence<any>>;
|
|
86
|
-
getMessagesMetadata: (message: Message, index?: number | undefined) => MessageMetadata$1<StateType> | undefined;
|
|
87
|
-
submit: (values: StateType, submitOptions?: SubmitOptions<StateType, GetConfigurableType<Bag>> | undefined) => Promise<void>;
|
|
88
|
-
stop: () => Promise<void>;
|
|
89
|
-
joinStream: (runId: string, lastEventId?: string | undefined, joinOptions?: {
|
|
90
|
-
streamMode?: StreamMode[] | StreamMode | undefined;
|
|
91
|
-
filter?: ((event: {
|
|
92
|
-
id?: string | undefined;
|
|
93
|
-
event: StreamEvent;
|
|
94
|
-
data: unknown;
|
|
95
|
-
}) => boolean) | undefined;
|
|
96
|
-
} | undefined) => Promise<void>;
|
|
97
|
-
queue: {
|
|
98
|
-
entries: WritableSignal<readonly _langchain_langgraph_sdk_ui0.QueueEntry<StateType, SubmitOptions<StateType, GetConfigurableType<Bag>>>[]>;
|
|
99
|
-
size: WritableSignal<number>;
|
|
100
|
-
cancel(id: string): Promise<boolean>;
|
|
101
|
-
clear(): Promise<void>;
|
|
102
|
-
};
|
|
103
|
-
switchThread(newThreadId: string | null): void;
|
|
104
|
-
readonly subagents: Map<string, SubagentStreamInterface$1<Record<string, unknown>, DefaultToolCall$1, string>>;
|
|
105
|
-
readonly activeSubagents: SubagentStreamInterface$1<Record<string, unknown>, DefaultToolCall$1, string>[];
|
|
106
|
-
getSubagent(toolCallId: string): SubagentStreamInterface$1<Record<string, unknown>, DefaultToolCall$1, string> | undefined;
|
|
107
|
-
getSubagentsByType(type: string): SubagentStreamInterface$1<Record<string, unknown>, DefaultToolCall$1, string>[];
|
|
108
|
-
getSubagentsByMessage(messageId: string): SubagentStreamInterface$1<Record<string, unknown>, DefaultToolCall$1, string>[];
|
|
109
|
-
};
|
|
110
24
|
/**
|
|
111
|
-
*
|
|
25
|
+
* Injects the shared stream instance from the nearest ancestor that provided
|
|
26
|
+
* one via {@link provideStream}. Throws if no ancestor provides a stream
|
|
27
|
+
* instance.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { Component } from "@angular/core";
|
|
32
|
+
* import { injectStream } from "@langchain/angular";
|
|
33
|
+
*
|
|
34
|
+
* @Component({
|
|
35
|
+
* template: `
|
|
36
|
+
* @for (msg of stream.messages(); track msg.id) {
|
|
37
|
+
* <div>{{ msg.content }}</div>
|
|
38
|
+
* }
|
|
39
|
+
* <button
|
|
40
|
+
* [disabled]="stream.isLoading()"
|
|
41
|
+
* (click)="onSubmit()"
|
|
42
|
+
* >Send</button>
|
|
43
|
+
* `,
|
|
44
|
+
* })
|
|
45
|
+
* export class ChatComponent {
|
|
46
|
+
* stream = injectStream();
|
|
47
|
+
*
|
|
48
|
+
* onSubmit() {
|
|
49
|
+
* void this.stream.submit({
|
|
50
|
+
* messages: [{ type: "human", content: "Hello!" }],
|
|
51
|
+
* });
|
|
52
|
+
* }
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example With type parameters for full type safety:
|
|
57
|
+
* ```typescript
|
|
58
|
+
* import type { agent } from "./agent";
|
|
59
|
+
*
|
|
60
|
+
* export class ChatComponent {
|
|
61
|
+
* stream = injectStream<typeof agent>();
|
|
62
|
+
* // stream.messages() returns typed messages
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare function injectStream<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(): AngularSignalWrap<WithClassMessages<ResolveStreamInterface$1<T, InferBag$1<T, Bag>>>>;
|
|
67
|
+
/**
|
|
68
|
+
* Angular entry point for LangGraph streaming. Call from a component, directive,
|
|
69
|
+
* or service field initializer to get a **Signals-based** stream controller
|
|
70
|
+
* connected to the LangGraph Platform (HTTP + threads API).
|
|
71
|
+
*
|
|
72
|
+
* The returned object mirrors the shared `useStream` API from
|
|
73
|
+
* `@langchain/langgraph-sdk/ui`, but reactive fields are
|
|
74
|
+
* {@link https://angular.dev/guide/signals | Angular `Signal`s}:
|
|
75
|
+
* read state with calls like `stream.messages()`, `stream.values()`, and
|
|
76
|
+
* `stream.isLoading()`, and use `WritableSignal` setters where exposed (for
|
|
77
|
+
* example `stream.branch` for branch selection).
|
|
78
|
+
*
|
|
79
|
+
* ## Typing with `createDeepAgent`
|
|
80
|
+
*
|
|
81
|
+
* Expect `export const agent = createDeepAgent({ ... })` from `deepagents`. In
|
|
82
|
+
* UI code, `import { type agent } from "./agent"` (or `import type { agent }`)
|
|
83
|
+
* is a **type-only** import: it is erased when compiling, so the agent module
|
|
84
|
+
* does not run in the browser. You still pass **`typeof agent`** to
|
|
85
|
+
* `injectStream`, not `agent` alone — `agent` is a value; TypeScript only
|
|
86
|
+
* accepts it in a type position via `typeof` (otherwise: *refers to a value,
|
|
87
|
+
* but is being used as a type*). If you prefer a named type in generics, add
|
|
88
|
+
* `export type Agent = typeof agent` next to the const and use
|
|
89
|
+
* `injectStream<Agent>(...)`.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* // agent.ts
|
|
94
|
+
* import { createDeepAgent } from "deepagents";
|
|
95
|
+
* import { tool } from "langchain";
|
|
96
|
+
* import { z } from "zod";
|
|
97
|
+
*
|
|
98
|
+
* const getWeather = tool(
|
|
99
|
+
* async ({ location }) => `Weather in ${location}`,
|
|
100
|
+
* { name: "get_weather", schema: z.object({ location: z.string() }) },
|
|
101
|
+
* );
|
|
102
|
+
*
|
|
103
|
+
* export const agent = createDeepAgent({
|
|
104
|
+
* model: "openai:gpt-4o",
|
|
105
|
+
* tools: [getWeather],
|
|
106
|
+
* });
|
|
107
|
+
*
|
|
108
|
+
* // chat.component.ts — type-only import; no agent runtime in the frontend
|
|
109
|
+
* import { Component } from "@angular/core";
|
|
110
|
+
* import { injectStream } from "@langchain/angular";
|
|
111
|
+
* import { type agent } from "./agent";
|
|
112
|
+
*
|
|
113
|
+
* @Component({
|
|
114
|
+
* standalone: true,
|
|
115
|
+
* template: `
|
|
116
|
+
* @for (msg of stream.messages(); track msg.id ?? $index) {
|
|
117
|
+
* <p>{{ msg.content }}</p>
|
|
118
|
+
* }
|
|
119
|
+
* `,
|
|
120
|
+
* })
|
|
121
|
+
* export class ChatComponent {
|
|
122
|
+
* readonly stream = injectStream<typeof agent>({
|
|
123
|
+
* assistantId: "agent",
|
|
124
|
+
* apiUrl: "http://localhost:2024",
|
|
125
|
+
* });
|
|
126
|
+
* // stream.toolCalls()[0].call.name is typed as "get_weather"
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* ## Typing with `StateGraph` / custom graph state
|
|
131
|
+
*
|
|
132
|
+
* Use your graph state interface as `T` and embed tool call unions in
|
|
133
|
+
* `Message<...>[]` when you need discriminated tool types.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* import { Message } from "@langchain/langgraph-sdk";
|
|
138
|
+
* import { Component } from "@angular/core";
|
|
139
|
+
* import { injectStream } from "@langchain/angular";
|
|
140
|
+
*
|
|
141
|
+
* type MyToolCalls =
|
|
142
|
+
* | { name: "search"; args: { query: string }; id?: string }
|
|
143
|
+
* | { name: "calculate"; args: { expression: string }; id?: string };
|
|
144
|
+
*
|
|
145
|
+
* interface MyGraphState {
|
|
146
|
+
* messages: Message<MyToolCalls>[];
|
|
147
|
+
* context?: string;
|
|
148
|
+
* }
|
|
149
|
+
*
|
|
150
|
+
* @Component({ standalone: true, template: "" })
|
|
151
|
+
* export class ChatComponent {
|
|
152
|
+
* readonly stream = injectStream<MyGraphState>({
|
|
153
|
+
* assistantId: "my-graph",
|
|
154
|
+
* apiUrl: "http://localhost:2024",
|
|
155
|
+
* });
|
|
156
|
+
* // stream.values() is typed as MyGraphState | null
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* // Optional bag for interrupts, configurable, custom events, and updates
|
|
163
|
+
* import { Component } from "@angular/core";
|
|
164
|
+
* import { injectStream } from "@langchain/angular";
|
|
165
|
+
* import type { Message } from "@langchain/langgraph-sdk";
|
|
166
|
+
*
|
|
167
|
+
* interface MyGraphState {
|
|
168
|
+
* messages: Message[];
|
|
169
|
+
* }
|
|
170
|
+
*
|
|
171
|
+
* @Component({ standalone: true, template: "" })
|
|
172
|
+
* export class ChatComponent {
|
|
173
|
+
* readonly stream = injectStream<
|
|
174
|
+
* MyGraphState,
|
|
175
|
+
* {
|
|
176
|
+
* InterruptType: { question: string };
|
|
177
|
+
* ConfigurableType: { userId: string };
|
|
178
|
+
* }
|
|
179
|
+
* >({
|
|
180
|
+
* assistantId: "my-graph",
|
|
181
|
+
* apiUrl: "http://localhost:2024",
|
|
182
|
+
* });
|
|
183
|
+
* // stream.interrupt() is typed as { question: string } | undefined
|
|
184
|
+
* }
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* ## Subagent streaming
|
|
188
|
+
*
|
|
189
|
+
* For `createDeepAgent` agents with `subagents`, set `filterSubagentMessages`
|
|
190
|
+
* and use `streamSubgraphs` on `submit` to populate `stream.subagents` and
|
|
191
|
+
* related helpers.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* import { Component } from "@angular/core";
|
|
196
|
+
* import { injectStream } from "@langchain/angular";
|
|
197
|
+
* import { type agent } from "./agent";
|
|
198
|
+
*
|
|
199
|
+
* @Component({ standalone: true, template: "" })
|
|
200
|
+
* export class DeepAgentChatComponent {
|
|
201
|
+
* readonly stream = injectStream<typeof agent>({
|
|
202
|
+
* assistantId: "deepagent",
|
|
203
|
+
* apiUrl: "http://localhost:2024",
|
|
204
|
+
* filterSubagentMessages: true,
|
|
205
|
+
* });
|
|
206
|
+
*
|
|
207
|
+
* send(content: string) {
|
|
208
|
+
* void this.stream.submit(
|
|
209
|
+
* { messages: [{ content, type: "human" }] },
|
|
210
|
+
* { streamSubgraphs: true },
|
|
211
|
+
* );
|
|
212
|
+
* }
|
|
213
|
+
* }
|
|
214
|
+
* ```
|
|
215
|
+
*
|
|
216
|
+
* @param options - LangGraph Platform client options (`apiUrl` or `client`),
|
|
217
|
+
* `assistantId`, stream modes, history, reconnect, subagent settings, etc.
|
|
218
|
+
*
|
|
219
|
+
* @returns A stream controller backed by Signals: graph values, messages,
|
|
220
|
+
* loading and error state, interrupts, tool calls, branching, queue, and
|
|
221
|
+
* `submit` / `stop` / `switchThread` helpers (writable where the UI layer
|
|
222
|
+
* requires mutation).
|
|
223
|
+
*
|
|
224
|
+
* @template T Agent type (with `~agentTypes`) from `createDeepAgent` or
|
|
225
|
+
* `createAgent`, or a state shape extending `Record<string, unknown>`.
|
|
226
|
+
* @template Bag Optional configuration bag:
|
|
227
|
+
* - `ConfigurableType` — `config.configurable` typing
|
|
228
|
+
* - `InterruptType` — human-in-the-loop interrupt payloads
|
|
229
|
+
* - `CustomEventType` — custom stream events
|
|
230
|
+
* - `UpdateType` — payload typing for `submit`
|
|
231
|
+
*
|
|
232
|
+
* @see {@link https://docs.langchain.com/oss/javascript/langgraph/overview | LangGraph JavaScript overview}
|
|
233
|
+
* @see {@link https://docs.langchain.com/oss/javascript/langchain/overview | LangChain JavaScript overview}
|
|
234
|
+
* @see {@link https://docs.langchain.com/oss/javascript/deepagents/overview | Deep Agents JavaScript overview}
|
|
235
|
+
*/
|
|
236
|
+
declare function injectStream<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(options: ResolveStreamOptions$1<T, InferBag$1<T, Bag>>): AngularSignalWrap<WithClassMessages<ResolveStreamInterface$1<T, InferBag$1<T, Bag>>>>;
|
|
237
|
+
/**
|
|
238
|
+
* Overload for a **custom transport** (`options.transport`), for example
|
|
239
|
+
* {@link FetchStreamTransport} or any implementation compatible with
|
|
240
|
+
* {@link injectStreamCustom}. Prefer {@link injectStreamCustom} directly when
|
|
241
|
+
* you only use custom transports and want a narrower import.
|
|
242
|
+
*
|
|
243
|
+
* @param options - Custom transport and stream options (must include
|
|
244
|
+
* `transport`).
|
|
245
|
+
*
|
|
246
|
+
* @returns The same Signals-based controller shape as the LangGraph Platform
|
|
247
|
+
* overload.
|
|
248
|
+
*
|
|
249
|
+
* @template T Agent type or state shape, matching the custom transport.
|
|
250
|
+
* @template Bag Same optional bag as the platform overload.
|
|
251
|
+
*
|
|
252
|
+
* @see {@link injectStreamCustom}
|
|
253
|
+
*/
|
|
254
|
+
declare function injectStream<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(options: UseStreamCustomOptions$1<InferStateType$1<T>, InferBag$1<T, Bag>>): AngularSignalWrap<WithClassMessages<ResolveStreamInterface$1<T, InferBag$1<T, Bag>>>>;
|
|
255
|
+
/**
|
|
256
|
+
* @deprecated Use `injectStream` instead. `useStream` will be removed in a
|
|
257
|
+
* future major version. `injectStream` follows Angular's `inject*` naming
|
|
258
|
+
* convention for injection-based patterns.
|
|
259
|
+
*/
|
|
260
|
+
declare const useStream: typeof injectStream;
|
|
261
|
+
/**
|
|
262
|
+
* Injectable Angular service that wraps {@link injectStream}.
|
|
112
263
|
*
|
|
113
264
|
* Extend this class with your own `@Injectable()` service and call
|
|
114
265
|
* `super(options)` in the constructor:
|
|
@@ -122,7 +273,7 @@ declare function useStreamLGP<StateType extends Record<string, unknown> = Record
|
|
|
122
273
|
* }
|
|
123
274
|
* ```
|
|
124
275
|
*
|
|
125
|
-
* The service exposes the same signals and methods as `
|
|
276
|
+
* The service exposes the same signals and methods as `injectStream`
|
|
126
277
|
* (e.g. `values`, `messages`, `isLoading`, `submit`, `stop`).
|
|
127
278
|
*
|
|
128
279
|
* Must be created within an Angular injection context (via DI or
|
|
@@ -138,7 +289,7 @@ declare class StreamService<T = Record<string, unknown>, Bag extends BagTemplate
|
|
|
138
289
|
get branch(): WritableSignal<string>;
|
|
139
290
|
get interrupt(): Signal<Interrupt<GetInterruptType<Bag>> | undefined>;
|
|
140
291
|
get interrupts(): Signal<Interrupt<GetInterruptType<Bag>>[]>;
|
|
141
|
-
get toolCalls(): Signal<ToolCallWithResult$1<DefaultToolCall$1
|
|
292
|
+
get toolCalls(): Signal<ToolCallWithResult$1<DefaultToolCall$1>[]>;
|
|
142
293
|
get queue(): AngularQueueInterface<{
|
|
143
294
|
entries: readonly {
|
|
144
295
|
id: string;
|
|
@@ -148,15 +299,15 @@ declare class StreamService<T = Record<string, unknown>, Bag extends BagTemplate
|
|
|
148
299
|
cancel: (id: string) => Promise<boolean>;
|
|
149
300
|
clear: () => Promise<void>;
|
|
150
301
|
}>;
|
|
151
|
-
get subagents():
|
|
152
|
-
get activeSubagents():
|
|
302
|
+
get subagents(): Signal<ReadonlyMap<string, SubagentStreamInterface$1>>;
|
|
303
|
+
get activeSubagents(): Signal<readonly SubagentStreamInterface$1[]>;
|
|
153
304
|
get history(): Signal<unknown>;
|
|
154
305
|
get isThreadLoading(): Signal<boolean>;
|
|
155
306
|
get experimental_branchTree(): Signal<unknown>;
|
|
156
307
|
get client(): Client;
|
|
157
308
|
get assistantId(): string;
|
|
158
309
|
submit(values: AcceptBaseMessages<Exclude<T, null | undefined>> | null | undefined, options?: SubmitOptions<T extends Record<string, unknown> ? T : Record<string, unknown>, GetConfigurableType<Bag>>): ReturnType<typeof this._stream.submit>;
|
|
159
|
-
stop(): void
|
|
310
|
+
stop(): Promise<void>;
|
|
160
311
|
setBranch(value: string): void;
|
|
161
312
|
switchThread(newThreadId: string | null): void;
|
|
162
313
|
joinStream(runId: string, lastEventId?: string, options?: {
|
|
@@ -168,12 +319,12 @@ declare class StreamService<T = Record<string, unknown>, Bag extends BagTemplate
|
|
|
168
319
|
}) => boolean;
|
|
169
320
|
}): Promise<void>;
|
|
170
321
|
getMessagesMetadata(message: BaseMessage, index?: number): MessageMetadata$1<T extends Record<string, unknown> ? T : Record<string, unknown>> | undefined;
|
|
171
|
-
getToolCalls(message: BaseMessage): ToolCallWithResult$1<DefaultToolCall$1
|
|
172
|
-
getSubagent(toolCallId: string):
|
|
173
|
-
getSubagentsByType(type: string):
|
|
174
|
-
getSubagentsByMessage(messageId: string):
|
|
322
|
+
getToolCalls(message: BaseMessage): ToolCallWithResult$1<DefaultToolCall$1>[];
|
|
323
|
+
getSubagent(toolCallId: string): SubagentStreamInterface$1 | undefined;
|
|
324
|
+
getSubagentsByType(type: string): SubagentStreamInterface$1[];
|
|
325
|
+
getSubagentsByMessage(messageId: string): SubagentStreamInterface$1[];
|
|
175
326
|
}
|
|
176
327
|
type ToolCallWithResult<ToolCall = DefaultToolCall$1> = ToolCallWithResult$1<ToolCall, ToolMessage, AIMessage>;
|
|
177
328
|
//#endregion
|
|
178
|
-
export { type AgentTypeConfigLike, type BaseStream, type BaseSubagentState, ClassSubagentStreamInterface, type CompiledSubAgentLike, type DeepAgentTypeConfigLike, type DefaultSubagentStates, type DefaultToolCall, type ExtractAgentConfig, type ExtractDeepAgentConfig, type ExtractSubAgentMiddleware, FetchStreamTransport, type GetToolCallsType, type InferAgentToolCalls, type InferBag, type InferDeepAgentSubagents, type InferNodeNames, type InferStateType, type InferSubagentByName, type InferSubagentNames, type InferSubagentState, type InferSubagentStates, type InferToolCalls, type IsAgentLike, type IsDeepAgentLike, type MessageMetadata, type QueueEntry, type QueueInterface, type ResolveStreamInterface, type ResolveStreamOptions, STREAM_DEFAULTS, STREAM_INSTANCE, type StreamDefaults, StreamService, type SubAgentLike, type SubagentApi, SubagentManager, type SubagentStateMap, type SubagentStatus, type SubagentStream, type SubagentStreamInterface, type SubagentToolCall, type ToolCallFromTool, type ToolCallState, ToolCallWithResult, type ToolCallsFromTools, type UseAgentStream, type UseAgentStreamOptions, type UseDeepAgentStream, type UseDeepAgentStreamOptions, type UseStreamCustomOptions, type UseStreamOptions, type UseStreamThread, type UseStreamTransport, calculateDepthFromNamespace, extractParentIdFromNamespace, extractToolCallIdFromNamespace, injectStream, isSubagentNamespace, provideStream, provideStreamDefaults, useStream, useStreamLGP };
|
|
329
|
+
export { type AgentTypeConfigLike, type BaseStream, type BaseSubagentState, type ClassSubagentStreamInterface, type CompiledSubAgentLike, type DeepAgentTypeConfigLike, type DefaultSubagentStates, type DefaultToolCall, type ExtractAgentConfig, type ExtractDeepAgentConfig, type ExtractSubAgentMiddleware, FetchStreamTransport, type GetToolCallsType, type InferAgentToolCalls, type InferBag, type InferDeepAgentSubagents, type InferNodeNames, type InferStateType, type InferSubagentByName, type InferSubagentNames, type InferSubagentState, type InferSubagentStates, type InferToolCalls, type IsAgentLike, type IsDeepAgentLike, type MessageMetadata, type QueueEntry, type QueueInterface, type ResolveStreamInterface, type ResolveStreamOptions, STREAM_DEFAULTS, STREAM_INSTANCE, type StreamDefaults, StreamService, type SubAgentLike, type SubagentApi, SubagentManager, type SubagentStateMap, type SubagentStatus, type SubagentStream, type SubagentStreamInterface, type SubagentToolCall, type ToolCallFromTool, type ToolCallState, ToolCallWithResult, type ToolCallsFromTools, type UseAgentStream, type UseAgentStreamOptions, type UseDeepAgentStream, type UseDeepAgentStreamOptions, type UseStreamCustomOptions, type UseStreamOptions, type UseStreamThread, type UseStreamTransport, calculateDepthFromNamespace, extractParentIdFromNamespace, extractToolCallIdFromNamespace, injectStream, injectStreamCustom, isSubagentNamespace, provideStream, provideStreamDefaults, useStream, useStreamCustom, useStreamLGP };
|
|
179
330
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;KAgDK,mBAAA;AAAA,KAEA,gBAAA;AAAA,KAcA,qBAAA,MAA2B,CAAA;EAC9B,OAAA;EACA,IAAA;EACA,MAAA;EACA,KAAA;AAAA;EAGI,OAAA,EAAS,cAAA,CAAe,CAAA;EACxB,IAAA,EAAM,cAAA,CAAe,CAAA;EACrB,MAAA,EAAQ,CAAA;EACR,KAAA,EAAO,EAAA;AAAA,IAET,CAAA;AAAA,KAEC,iBAAA,oBACS,CAAA,GAAI,CAAA,SAAU,gBAAA,GACtB,CAAA,CAAE,CAAA,IACF,CAAA,SAAU,mBAAA,GACR,cAAA,CAAe,CAAA,CAAE,CAAA,KACjB,CAAA,mBACE,qBAAA,CAAsB,CAAA,CAAE,CAAA,KACxB,MAAA,CAAO,CAAA,CAAE,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AATd;;;;;;;;;;;;iBAsDI,YAAA,KACH,MAAA,+BACQ,WAAA,GAAc,WAAA,CAAA,CAAA,GACvB,iBAAA,CACH,iBAAA,CAAkB,wBAAA,CAAuB,CAAA,EAAG,UAAA,CAAS,CAAA,EAAG,GAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAjDtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDyC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkLA;;;;;;;;;;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