@threadplane/langgraph 0.0.49 → 0.0.51

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threadplane/langgraph",
3
- "version": "0.0.49",
3
+ "version": "0.0.51",
4
4
  "description": "LangGraph adapter for @threadplane/chat — Angular bindings for LangGraph Platform.",
5
5
  "keywords": [
6
6
  "angular",
@@ -4,7 +4,7 @@ import { BaseMessage, AIMessage } from '@langchain/core/messages';
4
4
  import * as _langchain_langgraph_sdk from '@langchain/langgraph-sdk';
5
5
  import { ThreadState, Config, Checkpoint, Command, Metadata, StreamMode, BagTemplate, Interrupt, ToolCallWithResult, ToolProgress, Client } from '@langchain/langgraph-sdk';
6
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';
7
+ import { AgentRuntimeTelemetrySink, AgentWithHistory, AgentSubmitInput, AgentSubmitOptions, ClientToolsCapability, AgentRef, Message, AgentStatus, AgentError, ToolCall, AgentInterrupt, Subagent, AgentCheckpoint, MockAgent, MockAgentOptions, Citation, Thread } from '@threadplane/chat';
8
8
  import { MessageMetadata } from '@langchain/langgraph-sdk/ui';
9
9
  export { SubmitOptions } from '@langchain/langgraph-sdk/ui';
10
10
  import { FakeAgentConfig } from '@threadplane/chat/testing';
@@ -166,6 +166,23 @@ interface AgentTransport {
166
166
  }): Promise<void>;
167
167
  }
168
168
  /** Options for creating a LangGraph-backed agent via {@link agent}. */
169
+ /**
170
+ * Tuning options for the underlying LangGraph SDK `Client` constructed by the
171
+ * default {@link FetchStreamTransport}. Ignored when a custom `transport` is
172
+ * supplied (the transport owns its own client).
173
+ */
174
+ interface LangGraphClientOptions {
175
+ /**
176
+ * How many times a failed request — including the initial stream connect —
177
+ * is retried with exponential backoff before the error surfaces. Maps to the
178
+ * SDK's `callerOptions.maxRetries`. Omitted → the SDK default (currently 4).
179
+ *
180
+ * Set `0` to fail fast: useful for e2e tests that force a connection failure
181
+ * and assert the error surfaces promptly, rather than after the full
182
+ * multi-second backoff window.
183
+ */
184
+ maxRetries?: number;
185
+ }
169
186
  interface AgentOptions<T, _ResolvedBag extends BagTemplate> {
170
187
  /** Base URL of the LangGraph Platform API. Defaults to `provideAgent({ apiUrl })` when omitted. */
171
188
  apiUrl?: string;
@@ -183,6 +200,8 @@ interface AgentOptions<T, _ResolvedBag extends BagTemplate> {
183
200
  toMessage?: (msg: unknown) => BaseMessage;
184
201
  /** Custom transport. Defaults to FetchStreamTransport. */
185
202
  transport?: AgentTransport;
203
+ /** Tuning options for the default transport's LangGraph SDK client (e.g. retry budget). */
204
+ clientOptions?: LangGraphClientOptions;
186
205
  /** Optional app-owned telemetry sink. No telemetry is emitted unless this is provided. */
187
206
  telemetry?: AgentRuntimeTelemetrySink | false;
188
207
  /** When true, subagent messages are filtered from the main messages signal. */
@@ -211,7 +230,7 @@ interface SubagentStreamRef {
211
230
  * any LangGraph-specific demo. Raw LangGraph signals are prefixed with
212
231
  * `langGraph` to avoid collision with the runtime-neutral names.
213
232
  */
214
- interface LangGraphAgent<T = unknown, ResolvedBag extends BagTemplate = BagTemplate> extends AgentWithHistory {
233
+ interface LangGraphAgent<T = unknown, ResolvedBag extends BagTemplate = BagTemplate> extends AgentWithHistory<T> {
215
234
  /** Raw LangChain BaseMessage list. Use `messages` for chat rendering. */
216
235
  langGraphMessages: Signal<BaseMessage[]>;
217
236
  /** All interrupts received during the current run (raw LangGraph shape). */
@@ -224,6 +243,13 @@ interface LangGraphAgent<T = unknown, ResolvedBag extends BagTemplate = BagTempl
224
243
  experimentalBranchTree: Signal<AgentBranchTree<T>>;
225
244
  /** Submit input, resume commands, checkpoint forks, or other LangGraph run options. */
226
245
  submit: (input: AgentSubmitInput | null | undefined, opts?: AgentSubmitOptions & LangGraphSubmitOptions) => Promise<void>;
246
+ /**
247
+ * Client-declared, client-executed tools. Call setCatalog() to register
248
+ * tool specs; the catalog is automatically shipped with every run via
249
+ * `input.client_tools`. Pending tool calls appear in pending() after
250
+ * the run ends; resolve() returns a result and continues the run.
251
+ */
252
+ clientTools: ClientToolsCapability;
227
253
  /** Current agent state values (raw, typed per the type parameter T). */
228
254
  value: Signal<T>;
229
255
  /** True once at least one value or message has been received. */
@@ -301,6 +327,8 @@ interface AgentConfig<T = Record<string, unknown>, _Bag extends BagTemplate = Ba
301
327
  toMessage?: (msg: unknown) => BaseMessage;
302
328
  /** Custom transport. Defaults to {@link FetchStreamTransport}. */
303
329
  transport?: AgentTransport;
330
+ /** Tuning options for the default transport's LangGraph SDK client (e.g. retry budget). */
331
+ clientOptions?: LangGraphClientOptions;
304
332
  /** Optional app-owned telemetry sink. No telemetry is emitted unless this is provided. */
305
333
  telemetry?: AgentRuntimeTelemetrySink | false;
306
334
  /** When true, subagent messages are filtered from the main messages signal. */
@@ -333,7 +361,20 @@ interface AgentConfig<T = Record<string, unknown>, _Bag extends BagTemplate = Ba
333
361
  * }),
334
362
  * ];
335
363
  * ```
364
+ *
365
+ * **Typed state via AgentRef.** Pass a typed ref as the first argument to flow
366
+ * the state shape from `provideAgent` to `injectAgent` without repeating the
367
+ * generic at every call site:
368
+ *
369
+ * ```ts
370
+ * export const TRIP = createAgentRef<TripState>('trip');
371
+ * // app.config.ts:
372
+ * providers: [provideAgent(TRIP, { assistantId: 'trip-graph' })]
373
+ * // component:
374
+ * const agent = injectAgent(TRIP); // LangGraphAgent<TripState>
375
+ * ```
336
376
  */
377
+ declare function provideAgent<T = Record<string, unknown>>(ref: AgentRef<T>, configOrFactory: AgentConfig<T> | (() => AgentConfig<T>)): Provider[];
337
378
  declare function provideAgent<T = Record<string, unknown>>(configOrFactory: AgentConfig<T> | (() => AgentConfig<T>)): Provider[];
338
379
 
339
380
  /**
@@ -344,8 +385,19 @@ declare function provideAgent<T = Record<string, unknown>>(configOrFactory: Agen
344
385
  * singleton scoped to the injector that called `provideAgent()` — re-provide
345
386
  * in a child component's `providers: []` to scope a different agent to that
346
387
  * subtree (Angular's hierarchical DI handles the rest).
388
+ *
389
+ * **Typed state via AgentRef.** Pass the same ref that was supplied to
390
+ * `provideAgent(ref, …)` to carry the state type through DI without repeating
391
+ * the generic at every call site:
392
+ *
393
+ * ```ts
394
+ * const agent = injectAgent(TRIP); // LangGraphAgent<TripState>
395
+ * ```
396
+ *
397
+ * The no-arg form defaults to `LangGraphAgent<Record<string, unknown>>`.
347
398
  */
348
- declare function injectAgent<T = Record<string, unknown>, ResolvedBag extends BagTemplate = BagTemplate>(): LangGraphAgent<T, ResolvedBag>;
399
+ declare function injectAgent(): LangGraphAgent<Record<string, unknown>>;
400
+ declare function injectAgent<T, ResolvedBag extends BagTemplate = BagTemplate>(ref: AgentRef<T>): LangGraphAgent<T, ResolvedBag>;
349
401
 
350
402
  /**
351
403
  * Optional registry that collects per-instance agent lifecycles within
@@ -442,8 +494,9 @@ declare class FetchStreamTransport implements AgentTransport {
442
494
  /**
443
495
  * @param apiUrl - Base URL of the LangGraph Platform API
444
496
  * @param onThreadId - Optional callback invoked when a new thread is created
497
+ * @param clientOptions - Optional SDK client tuning (e.g. `maxRetries`)
445
498
  */
446
- constructor(apiUrl: string, onThreadId?: (id: string) => void);
499
+ constructor(apiUrl: string, onThreadId?: (id: string) => void, clientOptions?: LangGraphClientOptions);
447
500
  /** Open a streaming connection, creating a thread if needed. */
448
501
  stream(assistantId: string, threadId: string | null, payload: unknown, signal: AbortSignal, options?: LangGraphSubmitOptions): AsyncIterable<StreamEvent>;
449
502
  /** Join an already-started run without creating a new thread. */
@@ -475,7 +528,7 @@ interface MockLangGraphAgent extends LangGraphAgent<any, any> {
475
528
  messages: WritableSignal<Message[]>;
476
529
  status: WritableSignal<AgentStatus>;
477
530
  isLoading: WritableSignal<boolean>;
478
- error: WritableSignal<unknown>;
531
+ error: WritableSignal<AgentError | undefined>;
479
532
  toolCalls: WritableSignal<ToolCall[]>;
480
533
  interrupt: WritableSignal<AgentInterrupt | undefined>;
481
534
  subagents: WritableSignal<Map<string, Subagent>>;
@@ -558,17 +611,34 @@ declare function extractCitations(msg: KwargsLike): Citation[] | undefined;
558
611
  * transport (`fetch-stream.transport.ts`) and the threads adapter
559
612
  * (`LangGraphThreadsAdapter`) both go through here.
560
613
  *
614
+ * `clientOptions.maxRetries` maps to the SDK's `callerOptions.maxRetries`,
615
+ * which governs how many times a failed request (including the initial
616
+ * stream connect) is retried with exponential backoff before the error
617
+ * surfaces. Omitted → the SDK default (currently 4). Apps under test set
618
+ * `0` so a forced connection failure surfaces immediately instead of after
619
+ * the full backoff window.
620
+ *
561
621
  * @example
562
622
  * ```ts
563
623
  * const client = createLangGraphClient(environment.langGraphApiUrl);
564
624
  * const threads = await client.threads.search({ limit: 50 });
565
625
  * ```
566
626
  */
567
- declare function createLangGraphClient(apiUrl: string): Client;
627
+ declare function createLangGraphClient(apiUrl: string, clientOptions?: LangGraphClientOptions): Client;
568
628
  /** Exported separately so non-Client callers (e.g. raw fetch) can
569
629
  * share the same normalization logic. */
570
630
  declare function toAbsoluteApiUrl(apiUrl: string): string;
571
631
 
632
+ /**
633
+ * App-wide LangGraph SDK client tuning (e.g. `maxRetries`). Provide once at the
634
+ * app root; both the agent's default {@link FetchStreamTransport} and the
635
+ * {@link LangGraphThreadsAdapter} read it so the retry budget is configured in
636
+ * one place. A call-site `agent({ clientOptions })` or per-agent
637
+ * `provideAgent({ clientOptions })` overrides it for that agent.
638
+ * Absent → the SDK default.
639
+ */
640
+ declare const LANGGRAPH_CLIENT_OPTIONS: InjectionToken<LangGraphClientOptions>;
641
+
572
642
  /**
573
643
  * Configuration consumed by {@link LangGraphThreadsAdapter}. Provide
574
644
  * via {@link LANGGRAPH_THREADS_CONFIG} (typically in app.config.ts):
@@ -620,6 +690,7 @@ declare const LANGGRAPH_CLIENT: InjectionToken<Client<_langchain_langgraph_sdk.D
620
690
  */
621
691
  declare class LangGraphThreadsAdapter {
622
692
  private readonly config;
693
+ private readonly sharedClientOptions;
623
694
  private readonly client;
624
695
  private readonly fallback;
625
696
  private readonly _threads;
@@ -687,5 +758,5 @@ declare function refreshOnRunEnd(agent: LangGraphAgent, fn: () => void | Promise
687
758
  */
688
759
  declare function refreshOnTransition<T>(watch: Signal<T>, isActive: (v: T) => boolean, fn: () => void | Promise<void>): void;
689
760
 
690
- export { AGENT_LIFECYCLE, AgentLifecycleRegistry, FakeStreamTransport, FetchStreamTransport, LANGGRAPH_CLIENT, LANGGRAPH_THREADS_CONFIG, LangGraphThreadsAdapter, MockAgentTransport, ResourceStatus, createLangGraphClient, extractCitations, injectAgent, mockLangGraphAgent, provideAgent, provideFakeAgent, refreshOnRunEnd, refreshOnTransition, toAbsoluteApiUrl };
691
- export type { AgentBranchTree, AgentBranchTreeFork, AgentBranchTreeNode, AgentConfig, AgentLifecycle, AgentOptions, AgentQueue, AgentQueueEntry, AgentTransport, CustomStreamEvent, LangGraphAgent, LangGraphMultitaskStrategy, LangGraphSubmitOptions, LangGraphThreadsConfig, MockLangGraphAgent, StreamEvent, SubagentStreamRef };
761
+ export { AGENT_LIFECYCLE, AgentLifecycleRegistry, FakeStreamTransport, FetchStreamTransport, LANGGRAPH_CLIENT, LANGGRAPH_CLIENT_OPTIONS, LANGGRAPH_THREADS_CONFIG, LangGraphThreadsAdapter, MockAgentTransport, ResourceStatus, createLangGraphClient, extractCitations, injectAgent, mockLangGraphAgent, provideAgent, provideFakeAgent, refreshOnRunEnd, refreshOnTransition, toAbsoluteApiUrl };
762
+ export type { AgentBranchTree, AgentBranchTreeFork, AgentBranchTreeNode, AgentConfig, AgentLifecycle, AgentOptions, AgentQueue, AgentQueueEntry, AgentTransport, CustomStreamEvent, LangGraphAgent, LangGraphClientOptions, LangGraphMultitaskStrategy, LangGraphSubmitOptions, LangGraphThreadsConfig, MockLangGraphAgent, StreamEvent, SubagentStreamRef };