@threadplane/langgraph 0.0.46 → 0.0.49
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 +163 -42
- package/fesm2022/threadplane-langgraph.mjs +214 -45
- package/fesm2022/threadplane-langgraph.mjs.map +1 -1
- package/package.json +10 -1
- package/types/threadplane-langgraph.d.ts +115 -53
package/package.json
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threadplane/langgraph",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.49",
|
|
4
|
+
"description": "LangGraph adapter for @threadplane/chat — Angular bindings for LangGraph Platform.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"angular",
|
|
7
|
+
"langgraph",
|
|
8
|
+
"langchain",
|
|
9
|
+
"agent",
|
|
10
|
+
"adapter",
|
|
11
|
+
"threadplane"
|
|
12
|
+
],
|
|
4
13
|
"peerDependencies": {
|
|
5
14
|
"@threadplane/chat": "*",
|
|
6
15
|
"@angular/core": "^20.0.0 || ^21.0.0",
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import * as _langchain_langgraph_sdk from '@langchain/langgraph-sdk';
|
|
2
|
-
import { Config, Checkpoint, Command, Metadata, StreamMode, ThreadState, BagTemplate, Interrupt, ToolCallWithResult, ToolProgress, InferBag, Client } from '@langchain/langgraph-sdk';
|
|
3
|
-
export { BagTemplate, InferBag, Interrupt, ThreadState } from '@langchain/langgraph-sdk';
|
|
4
1
|
import * as i0 from '@angular/core';
|
|
5
2
|
import { InjectionToken, Signal, ResourceStatus as ResourceStatus$1, Provider, WritableSignal } from '@angular/core';
|
|
3
|
+
import { BaseMessage, AIMessage } from '@langchain/core/messages';
|
|
4
|
+
import * as _langchain_langgraph_sdk from '@langchain/langgraph-sdk';
|
|
5
|
+
import { ThreadState, Config, Checkpoint, Command, Metadata, StreamMode, BagTemplate, Interrupt, ToolCallWithResult, ToolProgress, Client } from '@langchain/langgraph-sdk';
|
|
6
|
+
export { BagTemplate, InferBag, Interrupt, ThreadState } from '@langchain/langgraph-sdk';
|
|
7
|
+
import { AgentRuntimeTelemetrySink, AgentWithHistory, AgentSubmitInput, AgentSubmitOptions, Message, AgentStatus, ToolCall, AgentInterrupt, Subagent, AgentCheckpoint, MockAgent, MockAgentOptions, Citation, Thread } from '@threadplane/chat';
|
|
6
8
|
import { MessageMetadata } from '@langchain/langgraph-sdk/ui';
|
|
7
9
|
export { SubmitOptions } from '@langchain/langgraph-sdk/ui';
|
|
8
|
-
import {
|
|
9
|
-
import { AgentRuntimeTelemetrySink, AgentWithHistory, AgentSubmitInput, AgentSubmitOptions, Message, AgentStatus, AgentInterrupt, ToolCall, AgentCheckpoint, Subagent, Citation, Thread } from '@threadplane/chat';
|
|
10
|
+
import { FakeAgentConfig } from '@threadplane/chat/testing';
|
|
10
11
|
|
|
11
12
|
interface AgentLifecycle {
|
|
12
13
|
/** Epoch ms of the first stream chunk arrival. Resets on switchThread(). */
|
|
@@ -203,7 +204,7 @@ interface SubagentStreamRef {
|
|
|
203
204
|
messages: Signal<BaseMessage[]>;
|
|
204
205
|
}
|
|
205
206
|
/**
|
|
206
|
-
* Unified LangGraph agent surface returned by `
|
|
207
|
+
* Unified LangGraph agent surface returned by `injectAgent()`.
|
|
207
208
|
*
|
|
208
209
|
* Extends the runtime-neutral `AgentWithHistory` contract (chat-consumable)
|
|
209
210
|
* with the full LangGraph-specific API. One object drives both `<chat>` and
|
|
@@ -278,51 +279,73 @@ interface LangGraphAgent<T = unknown, ResolvedBag extends BagTemplate = BagTempl
|
|
|
278
279
|
}
|
|
279
280
|
|
|
280
281
|
/**
|
|
281
|
-
*
|
|
282
|
+
* Configuration for an agent instance.
|
|
283
|
+
* Combines connection defaults with per-component options so the
|
|
284
|
+
* agent can be constructed once at provider time and injected
|
|
285
|
+
* everywhere it is needed.
|
|
286
|
+
*/
|
|
287
|
+
interface AgentConfig<T = Record<string, unknown>, _Bag extends BagTemplate = BagTemplate> {
|
|
288
|
+
/** Base URL of the LangGraph Platform API (e.g., `'http://localhost:2024'`). */
|
|
289
|
+
apiUrl?: string;
|
|
290
|
+
/** Agent or graph identifier on the LangGraph platform. */
|
|
291
|
+
assistantId?: string;
|
|
292
|
+
/** Thread ID to connect to. Pass a Signal for reactive thread switching. */
|
|
293
|
+
threadId?: Signal<string | null> | string | null;
|
|
294
|
+
/** Called when a new thread is auto-created by the transport. */
|
|
295
|
+
onThreadId?: (id: string) => void;
|
|
296
|
+
/** Initial state values before the first stream response arrives. */
|
|
297
|
+
initialValues?: Partial<T>;
|
|
298
|
+
/** Throttle signal updates in milliseconds. `false` to disable. */
|
|
299
|
+
throttle?: number | false;
|
|
300
|
+
/** Custom message deserializer for non-standard message formats. */
|
|
301
|
+
toMessage?: (msg: unknown) => BaseMessage;
|
|
302
|
+
/** Custom transport. Defaults to {@link FetchStreamTransport}. */
|
|
303
|
+
transport?: AgentTransport;
|
|
304
|
+
/** Optional app-owned telemetry sink. No telemetry is emitted unless this is provided. */
|
|
305
|
+
telemetry?: AgentRuntimeTelemetrySink | false;
|
|
306
|
+
/** When true, subagent messages are filtered from the main messages signal. */
|
|
307
|
+
filterSubagentMessages?: boolean;
|
|
308
|
+
/** Tool names that indicate a subagent invocation. */
|
|
309
|
+
subagentToolNames?: string[];
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Wire the LangGraph adapter into Angular's dependency injection.
|
|
282
313
|
*
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
* in real time as LangGraph streams messages, values, tool calls, interrupts,
|
|
287
|
-
* subagent state, and checkpoint history.
|
|
314
|
+
* Registers a singleton `LangGraphAgent` constructed from `config`. Retrieve it
|
|
315
|
+
* in any component with `injectAgent()`. Provide this at the application root
|
|
316
|
+
* (`app.config.ts`) for an app-wide agent.
|
|
288
317
|
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
* @returns A {@link LangGraphAgent} with reactive signals and action methods
|
|
318
|
+
* To use a different agent in a component subtree, re-provide
|
|
319
|
+
* `provideAgent({...})` in that component's `providers: []` array —
|
|
320
|
+
* Angular's hierarchical DI scopes the singleton accordingly.
|
|
293
321
|
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
* apiUrl: 'http://localhost:2024',
|
|
300
|
-
* threadId: signal(this.savedThreadId),
|
|
301
|
-
* onThreadId: (id) => localStorage.setItem('threadId', id),
|
|
302
|
-
* });
|
|
322
|
+
* **Static vs factory config.** Pass a plain `AgentConfig` object when the
|
|
323
|
+
* config is known up front. Pass a `() => AgentConfig` factory when the config
|
|
324
|
+
* depends on runtime/DI state — the factory runs inside an Angular injection
|
|
325
|
+
* context, so it may call `inject()` to read services, route params, or
|
|
326
|
+
* component-scoped signals:
|
|
303
327
|
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
328
|
+
* ```ts
|
|
329
|
+
* providers: [
|
|
330
|
+
* provideAgent(() => {
|
|
331
|
+
* const route = inject(ActivatedRoute);
|
|
332
|
+
* return { assistantId: 'chat', threadId: toSignal(route.paramMap) };
|
|
333
|
+
* }),
|
|
334
|
+
* ];
|
|
306
335
|
* ```
|
|
307
336
|
*/
|
|
308
|
-
declare function
|
|
337
|
+
declare function provideAgent<T = Record<string, unknown>>(configOrFactory: AgentConfig<T> | (() => AgentConfig<T>)): Provider[];
|
|
309
338
|
|
|
310
339
|
/**
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
transport?: AgentTransport;
|
|
319
|
-
}
|
|
320
|
-
declare const AGENT_CONFIG: InjectionToken<AgentConfig>;
|
|
321
|
-
/**
|
|
322
|
-
* Angular provider factory that registers global defaults for all
|
|
323
|
-
* agent instances in the application.
|
|
340
|
+
* Retrieve the LangGraph-backed Agent from the current Angular injection context.
|
|
341
|
+
*
|
|
342
|
+
* Mirrors `@threadplane/ag-ui`'s `injectAgent()` so consumer code is identical
|
|
343
|
+
* regardless of which adapter is wired in `app.config.ts`. The agent is a
|
|
344
|
+
* singleton scoped to the injector that called `provideAgent()` — re-provide
|
|
345
|
+
* in a child component's `providers: []` to scope a different agent to that
|
|
346
|
+
* subtree (Angular's hierarchical DI handles the rest).
|
|
324
347
|
*/
|
|
325
|
-
declare function
|
|
348
|
+
declare function injectAgent<T = Record<string, unknown>, ResolvedBag extends BagTemplate = BagTemplate>(): LangGraphAgent<T, ResolvedBag>;
|
|
326
349
|
|
|
327
350
|
/**
|
|
328
351
|
* Optional registry that collects per-instance agent lifecycles within
|
|
@@ -440,46 +463,85 @@ declare class FetchStreamTransport implements AgentTransport {
|
|
|
440
463
|
/**
|
|
441
464
|
* A LangGraphAgent mock with writable signals for easy test control.
|
|
442
465
|
*
|
|
466
|
+
* Builds on the runtime-neutral {@link MockAgent} from `@threadplane/chat`
|
|
467
|
+
* (which supplies the neutral `Agent`-contract writable signals plus
|
|
468
|
+
* `submit`/`stop`/`regenerate` call tracking) and layers the LangGraph-specific
|
|
469
|
+
* writable signals on top.
|
|
470
|
+
*
|
|
443
471
|
* Cast the result of `mockLangGraphAgent()` to this type to access
|
|
444
472
|
* writable signals without unsafe casts in test files.
|
|
445
473
|
*/
|
|
446
474
|
interface MockLangGraphAgent extends LangGraphAgent<any, any> {
|
|
447
475
|
messages: WritableSignal<Message[]>;
|
|
448
|
-
langGraphMessages: WritableSignal<BaseMessage[]>;
|
|
449
476
|
status: WritableSignal<AgentStatus>;
|
|
450
477
|
isLoading: WritableSignal<boolean>;
|
|
451
478
|
error: WritableSignal<unknown>;
|
|
479
|
+
toolCalls: WritableSignal<ToolCall[]>;
|
|
480
|
+
interrupt: WritableSignal<AgentInterrupt | undefined>;
|
|
481
|
+
subagents: WritableSignal<Map<string, Subagent>>;
|
|
482
|
+
history: WritableSignal<AgentCheckpoint[]>;
|
|
483
|
+
submitCalls: MockAgent['submitCalls'];
|
|
484
|
+
stopCount: MockAgent['stopCount'];
|
|
485
|
+
_internal: MockAgent['_internal'];
|
|
486
|
+
langGraphMessages: WritableSignal<BaseMessage[]>;
|
|
452
487
|
hasValue: WritableSignal<boolean>;
|
|
453
488
|
value: WritableSignal<any>;
|
|
454
|
-
interrupt: WritableSignal<AgentInterrupt | undefined>;
|
|
455
489
|
langGraphInterrupts: WritableSignal<Interrupt<any>[]>;
|
|
456
|
-
toolCalls: WritableSignal<ToolCall[]>;
|
|
457
490
|
langGraphToolCalls: WritableSignal<ToolCallWithResult[]>;
|
|
458
491
|
toolProgress: WritableSignal<ToolProgress[]>;
|
|
459
492
|
queue: WritableSignal<AgentQueue>;
|
|
460
493
|
branch: WritableSignal<string>;
|
|
461
|
-
history: WritableSignal<AgentCheckpoint[]>;
|
|
462
494
|
langGraphHistory: WritableSignal<ThreadState<any>[]>;
|
|
463
495
|
experimentalBranchTree: WritableSignal<AgentBranchTree<any>>;
|
|
464
496
|
isThreadLoading: WritableSignal<boolean>;
|
|
465
|
-
subagents: WritableSignal<Map<string, Subagent>>;
|
|
466
497
|
activeSubagents: WritableSignal<SubagentStreamRef[]>;
|
|
467
498
|
customEvents: WritableSignal<CustomStreamEvent[]>;
|
|
468
499
|
}
|
|
469
500
|
/**
|
|
470
501
|
* Creates a mock LangGraphAgent with writable signals for testing.
|
|
471
502
|
* Control state by writing to the returned writable signals directly.
|
|
503
|
+
*
|
|
504
|
+
* Neutral `Agent`-contract signals come from {@link mockAgent}; LangGraph-specific
|
|
505
|
+
* signals are declared here and layered on top.
|
|
472
506
|
*/
|
|
473
|
-
declare function mockLangGraphAgent(initial?: {
|
|
474
|
-
messages?: Message[];
|
|
507
|
+
declare function mockLangGraphAgent(initial?: MockAgentOptions & {
|
|
475
508
|
langGraphMessages?: BaseMessage[];
|
|
476
|
-
status?: AgentStatus;
|
|
477
|
-
isLoading?: boolean;
|
|
478
|
-
error?: unknown;
|
|
479
509
|
hasValue?: boolean;
|
|
480
510
|
isThreadLoading?: boolean;
|
|
481
511
|
}): MockLangGraphAgent;
|
|
482
512
|
|
|
513
|
+
/**
|
|
514
|
+
* Wire an in-process fake LangGraph agent into Angular DI.
|
|
515
|
+
*
|
|
516
|
+
* Streams a canned assistant reply (see FakeAgentConfig) with no backend —
|
|
517
|
+
* the symmetric counterpart to @threadplane/ag-ui's provideFakeAgent(). For
|
|
518
|
+
* advanced manual scripting (tool calls, interrupts, multi-batch), provide
|
|
519
|
+
* the agent yourself with
|
|
520
|
+
* `provideAgent({ assistantId, transport: new MockAgentTransport(...) })`.
|
|
521
|
+
*/
|
|
522
|
+
declare function provideFakeAgent(config?: FakeAgentConfig): Provider[];
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* In-process AgentTransport that auto-streams a canned assistant reply.
|
|
526
|
+
*
|
|
527
|
+
* Backs `provideFakeAgent()`. Unlike `MockAgentTransport` (passive, driven
|
|
528
|
+
* manually from specs), this transport emits its tokens automatically on
|
|
529
|
+
* `stream()`, then completes — suitable for offline demos and integration tests.
|
|
530
|
+
*
|
|
531
|
+
* NOT for production use.
|
|
532
|
+
*/
|
|
533
|
+
declare class FakeStreamTransport implements AgentTransport {
|
|
534
|
+
private readonly tokens;
|
|
535
|
+
private readonly reasoningTokens;
|
|
536
|
+
private readonly delayMs;
|
|
537
|
+
constructor(config?: FakeAgentConfig);
|
|
538
|
+
stream(_assistantId: string, _threadId: string | null, _payload: unknown, signal: AbortSignal, _options?: LangGraphSubmitOptions): AsyncIterable<StreamEvent>;
|
|
539
|
+
createQueuedRun(_assistantId: string, threadId: string, payload: unknown, _signal: AbortSignal, options?: LangGraphSubmitOptions): Promise<AgentQueueEntry>;
|
|
540
|
+
cancelRun(_threadId: string, _runId: string, _signal: AbortSignal): Promise<void>;
|
|
541
|
+
getHistory(_threadId: string, _signal: AbortSignal): Promise<ThreadState[]>;
|
|
542
|
+
joinStream(): AsyncIterable<StreamEvent>;
|
|
543
|
+
}
|
|
544
|
+
|
|
483
545
|
interface KwargsLike {
|
|
484
546
|
additional_kwargs?: Record<string, unknown> | undefined;
|
|
485
547
|
}
|
|
@@ -625,5 +687,5 @@ declare function refreshOnRunEnd(agent: LangGraphAgent, fn: () => void | Promise
|
|
|
625
687
|
*/
|
|
626
688
|
declare function refreshOnTransition<T>(watch: Signal<T>, isActive: (v: T) => boolean, fn: () => void | Promise<void>): void;
|
|
627
689
|
|
|
628
|
-
export {
|
|
690
|
+
export { AGENT_LIFECYCLE, AgentLifecycleRegistry, FakeStreamTransport, FetchStreamTransport, LANGGRAPH_CLIENT, LANGGRAPH_THREADS_CONFIG, LangGraphThreadsAdapter, MockAgentTransport, ResourceStatus, createLangGraphClient, extractCitations, injectAgent, mockLangGraphAgent, provideAgent, provideFakeAgent, refreshOnRunEnd, refreshOnTransition, toAbsoluteApiUrl };
|
|
629
691
|
export type { AgentBranchTree, AgentBranchTreeFork, AgentBranchTreeNode, AgentConfig, AgentLifecycle, AgentOptions, AgentQueue, AgentQueueEntry, AgentTransport, CustomStreamEvent, LangGraphAgent, LangGraphMultitaskStrategy, LangGraphSubmitOptions, LangGraphThreadsConfig, MockLangGraphAgent, StreamEvent, SubagentStreamRef };
|