@dawn-ai/langchain 0.1.8 → 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.
Files changed (51) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +16 -2
  3. package/dist/agent-adapter.d.ts +60 -4
  4. package/dist/agent-adapter.d.ts.map +1 -1
  5. package/dist/agent-adapter.js +396 -77
  6. package/dist/chat-model-factory.d.ts +11 -0
  7. package/dist/chat-model-factory.d.ts.map +1 -0
  8. package/dist/chat-model-factory.js +55 -0
  9. package/dist/index.d.ts +19 -2
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +11 -1
  12. package/dist/model-provider-resolver.d.ts +8 -0
  13. package/dist/model-provider-resolver.d.ts.map +1 -0
  14. package/dist/model-provider-resolver.js +40 -0
  15. package/dist/offload/offload-store.d.ts +30 -0
  16. package/dist/offload/offload-store.d.ts.map +1 -0
  17. package/dist/offload/offload-store.js +105 -0
  18. package/dist/offload/offload-tool-output.d.ts +10 -0
  19. package/dist/offload/offload-tool-output.d.ts.map +1 -0
  20. package/dist/offload/offload-tool-output.js +18 -0
  21. package/dist/offload/stub.d.ts +8 -0
  22. package/dist/offload/stub.d.ts.map +1 -0
  23. package/dist/offload/stub.js +14 -0
  24. package/dist/subagent-dispatcher.d.ts +33 -0
  25. package/dist/subagent-dispatcher.d.ts.map +1 -0
  26. package/dist/subagent-dispatcher.js +182 -0
  27. package/dist/subagent-tool-bridge.d.ts +27 -0
  28. package/dist/subagent-tool-bridge.d.ts.map +1 -0
  29. package/dist/subagent-tool-bridge.js +32 -0
  30. package/dist/summarization/hook.d.ts +31 -0
  31. package/dist/summarization/hook.d.ts.map +1 -0
  32. package/dist/summarization/hook.js +44 -0
  33. package/dist/summarization/index.d.ts +5 -0
  34. package/dist/summarization/index.d.ts.map +1 -0
  35. package/dist/summarization/index.js +4 -0
  36. package/dist/summarization/split.d.ts +12 -0
  37. package/dist/summarization/split.d.ts.map +1 -0
  38. package/dist/summarization/split.js +27 -0
  39. package/dist/summarization/summarize.d.ts +10 -0
  40. package/dist/summarization/summarize.d.ts.map +1 -0
  41. package/dist/summarization/summarize.js +30 -0
  42. package/dist/summarization/token-counter.d.ts +10 -0
  43. package/dist/summarization/token-counter.d.ts.map +1 -0
  44. package/dist/summarization/token-counter.js +29 -0
  45. package/dist/tool-converter.d.ts +5 -1
  46. package/dist/tool-converter.d.ts.map +1 -1
  47. package/dist/tool-converter.js +74 -21
  48. package/dist/unwrap-tool-result.d.ts +35 -0
  49. package/dist/unwrap-tool-result.d.ts.map +1 -0
  50. package/dist/unwrap-tool-result.js +42 -0
  51. package/package.json +55 -10
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Dawn contributors
3
+ Copyright (c) Brian Love
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -4,9 +4,23 @@
4
4
 
5
5
  # @dawn-ai/langchain
6
6
 
7
- LangChain backend adapters Dawn uses to materialize `chain` and `agent` routes (tool conversion, streaming, retry).
7
+ LangChain backend adapters Dawn uses to materialize `chain` routes and provider-aware `agent` routes (tool conversion, streaming, retry).
8
8
 
9
- This is an internal Dawn workspace package. For Dawn documentation, see <https://dawn-ai.org>.
9
+ `agent()` materialization resolves a LangChain chat model from the route descriptor. Dawn includes `@langchain/openai` for the default/backcompat path and lazy-loads optional provider packages when an agent selects or infers another provider.
10
+
11
+ Install optional provider integrations in applications as needed:
12
+
13
+ ```bash
14
+ pnpm add @langchain/anthropic # anthropic
15
+ pnpm add @langchain/google-genai # google
16
+ pnpm add @langchain/mistralai # mistral
17
+ pnpm add @langchain/groq # groq
18
+ pnpm add @langchain/ollama # ollama
19
+ pnpm add @langchain/xai # xai
20
+ pnpm add @langchain/openrouter # openrouter
21
+ ```
22
+
23
+ This is an internal Dawn workspace package. For Dawn documentation, see <https://github.com/cacheplane/dawnai/tree/main/apps/web/content/docs>.
10
24
 
11
25
  ## License
12
26
 
@@ -1,6 +1,13 @@
1
- import type { RetryConfig } from "@dawn-ai/sdk";
1
+ import type { PromptFragment, StreamTransformer } from "@dawn-ai/core";
2
+ import type { DawnAgent, RetryConfig } from "@dawn-ai/sdk";
3
+ import { type BaseMessageLike } from "@langchain/core/messages";
4
+ import type { BaseCheckpointSaver } from "@langchain/langgraph-checkpoint";
2
5
  import { type ResolvedStateField } from "./state-adapter.js";
3
- interface DawnToolDefinition {
6
+ import { type SubagentResolverResult } from "./subagent-tool-bridge.js";
7
+ import { type ResolvedSummarizationConfig } from "./summarization/index.js";
8
+ import { type OffloadFn } from "./tool-converter.js";
9
+ export type SubagentResolver = (leafName: string) => SubagentResolverResult | undefined;
10
+ export interface DawnToolDefinition {
4
11
  readonly description?: string;
5
12
  readonly name: string;
6
13
  readonly run: (input: unknown, context: {
@@ -9,21 +16,70 @@ interface DawnToolDefinition {
9
16
  }) => Promise<unknown> | unknown;
10
17
  readonly schema?: unknown;
11
18
  }
19
+ /**
20
+ * Test-only escape hatch: reset the materialized-agents cache so the next
21
+ * harness run creates a fresh LLM instance (e.g. pointing at a new aimock
22
+ * port). Exported (and re-exported via `@dawn-ai/cli/runtime`) so the
23
+ * `@dawn-ai/testing` harness can clear the cache on teardown. Not for
24
+ * production use; the `__`/`ForTests` name marks it internal-by-convention.
25
+ */
26
+ export declare function __resetMaterializedAgentsForTests(): void;
27
+ export declare function composePromptMessages(systemPrompt: string, promptFragments: readonly PromptFragment[], state: Record<string, unknown>): BaseMessageLike[];
28
+ export declare function materializeAgentGraph(options: {
29
+ readonly checkpointer: BaseCheckpointSaver;
30
+ readonly descriptor: DawnAgent;
31
+ readonly tools?: readonly DawnToolDefinition[];
32
+ readonly stateFields?: readonly ResolvedStateField[];
33
+ readonly promptFragments?: readonly PromptFragment[];
34
+ readonly summarization?: ResolvedSummarizationConfig;
35
+ }): Promise<unknown>;
12
36
  export interface AgentStreamChunk {
13
- readonly type: "token" | "tool_call" | "tool_result" | "done";
37
+ readonly type: "token" | "tool_call" | "tool_result" | "interrupt" | "done" | (string & {});
14
38
  readonly data: unknown;
15
39
  }
16
40
  export interface AgentOptions {
41
+ /**
42
+ * Checkpointer used by LangGraph to park interrupted graph state and replay
43
+ * from it on resume. Required — the CLI runtime supplies a SQLite-backed
44
+ * instance by default. If you call agent-adapter directly (e.g. in tests),
45
+ * pass `new MemorySaver()` from `@langchain/langgraph`.
46
+ */
47
+ readonly checkpointer: BaseCheckpointSaver;
17
48
  readonly entry: unknown;
49
+ /**
50
+ * The agent input. For a normal invocation, this is a record like
51
+ * `{messages: [...]}`. For a resume invocation (after a parked interrupt),
52
+ * pass a `Command({resume: decision})` instance directly — the adapter will
53
+ * forward it verbatim to `streamEvents` instead of wrapping it in messages.
54
+ */
18
55
  readonly input: unknown;
19
56
  readonly middlewareContext?: Readonly<Record<string, unknown>>;
57
+ readonly offload?: OffloadFn;
20
58
  readonly retry?: RetryConfig;
21
59
  readonly routeParamNames: readonly string[];
22
60
  readonly signal: AbortSignal;
23
61
  readonly stateFields?: readonly ResolvedStateField[];
24
62
  readonly tools: readonly DawnToolDefinition[];
63
+ readonly promptFragments?: readonly PromptFragment[];
64
+ readonly streamTransformers?: readonly StreamTransformer[];
65
+ /**
66
+ * Resolves a subagent leaf name to a child graph + routeId. When set, the
67
+ * `task` tool contributed by the subagents capability marker is intercepted
68
+ * inside `streamFromRunnable` and replaced with a bridge that dispatches the
69
+ * call via `dispatchSubagent`. Emitted `subagent.*` events are queued and
70
+ * drained alongside normal stream chunks (no module-level mutable state).
71
+ */
72
+ readonly subagentResolver?: SubagentResolver;
73
+ /**
74
+ * Stable per-conversation identifier used as LangGraph's `thread_id`. When
75
+ * set, the agent-adapter wires it into `config.configurable.thread_id` so
76
+ * the checkpointer can park interrupted state. Required for resume to work
77
+ * — without a thread_id, an interrupt ends the stream with no way to
78
+ * replay.
79
+ */
80
+ readonly threadId?: string;
81
+ readonly summarization?: ResolvedSummarizationConfig;
25
82
  }
26
83
  export declare function executeAgent(options: AgentOptions): Promise<unknown>;
27
84
  export declare function streamAgent(options: AgentOptions): AsyncGenerator<AgentStreamChunk>;
28
- export {};
29
85
  //# sourceMappingURL=agent-adapter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent-adapter.d.ts","sourceRoot":"","sources":["../src/agent-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,WAAW,EAAE,MAAM,cAAc,CAAA;AAI1D,OAAO,EAA0B,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAGpF,UAAU,kBAAkB;IAC1B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,GAAG,EAAE,CACZ,KAAK,EAAE,OAAO,EACd,OAAO,EAAE;QACP,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;QACvD,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;KAC7B,KACE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAA;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAC1B;AAwDD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,WAAW,GAAG,aAAa,GAAG,MAAM,CAAA;IAC7D,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,iBAAiB,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IAC9D,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,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