@aid-framework/runtime 0.0.0-stage → 0.1.39

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 (188) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +52 -2
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/agents/deep_agents.d.ts +78 -0
  5. package/dist/agents/deep_agents.d.ts.map +1 -0
  6. package/dist/agents/deep_agents.js +477 -0
  7. package/dist/agents/deep_agents.js.map +1 -0
  8. package/dist/agents/engine.d.ts +85 -0
  9. package/dist/agents/engine.d.ts.map +1 -0
  10. package/dist/agents/engine.js +129 -0
  11. package/dist/agents/engine.js.map +1 -0
  12. package/dist/agents/gateway_chat_model.d.ts +151 -0
  13. package/dist/agents/gateway_chat_model.d.ts.map +1 -0
  14. package/dist/agents/gateway_chat_model.js +350 -0
  15. package/dist/agents/gateway_chat_model.js.map +1 -0
  16. package/dist/agents/guardrail_middleware.d.ts +57 -0
  17. package/dist/agents/guardrail_middleware.d.ts.map +1 -0
  18. package/dist/agents/guardrail_middleware.js +85 -0
  19. package/dist/agents/guardrail_middleware.js.map +1 -0
  20. package/dist/agents/guardrails.d.ts +124 -0
  21. package/dist/agents/guardrails.d.ts.map +1 -0
  22. package/dist/agents/guardrails.js +336 -0
  23. package/dist/agents/guardrails.js.map +1 -0
  24. package/dist/agents/index.d.ts +15 -0
  25. package/dist/agents/index.d.ts.map +1 -0
  26. package/dist/agents/index.js +15 -0
  27. package/dist/agents/index.js.map +1 -0
  28. package/dist/agents/ir.d.ts +144 -0
  29. package/dist/agents/ir.d.ts.map +1 -0
  30. package/dist/agents/ir.js +513 -0
  31. package/dist/agents/ir.js.map +1 -0
  32. package/dist/agents/loop.d.ts +145 -0
  33. package/dist/agents/loop.d.ts.map +1 -0
  34. package/dist/agents/loop.js +1025 -0
  35. package/dist/agents/loop.js.map +1 -0
  36. package/dist/agents/memory.d.ts +115 -0
  37. package/dist/agents/memory.d.ts.map +1 -0
  38. package/dist/agents/memory.js +258 -0
  39. package/dist/agents/memory.js.map +1 -0
  40. package/dist/agents/state.d.ts +137 -0
  41. package/dist/agents/state.d.ts.map +1 -0
  42. package/dist/agents/state.js +255 -0
  43. package/dist/agents/state.js.map +1 -0
  44. package/dist/concurrency.d.ts +36 -0
  45. package/dist/concurrency.d.ts.map +1 -0
  46. package/dist/concurrency.js +86 -0
  47. package/dist/concurrency.js.map +1 -0
  48. package/dist/control.d.ts +116 -0
  49. package/dist/control.d.ts.map +1 -0
  50. package/dist/control.js +281 -0
  51. package/dist/control.js.map +1 -0
  52. package/dist/cost.d.ts +95 -0
  53. package/dist/cost.d.ts.map +1 -0
  54. package/dist/cost.js +161 -0
  55. package/dist/cost.js.map +1 -0
  56. package/dist/errors.d.ts +213 -0
  57. package/dist/errors.d.ts.map +1 -0
  58. package/dist/errors.js +316 -0
  59. package/dist/errors.js.map +1 -0
  60. package/dist/evals/dataset.d.ts +45 -0
  61. package/dist/evals/dataset.d.ts.map +1 -0
  62. package/dist/evals/dataset.js +147 -0
  63. package/dist/evals/dataset.js.map +1 -0
  64. package/dist/evals/gate.d.ts +236 -0
  65. package/dist/evals/gate.d.ts.map +1 -0
  66. package/dist/evals/gate.js +572 -0
  67. package/dist/evals/gate.js.map +1 -0
  68. package/dist/evals/metrics.d.ts +141 -0
  69. package/dist/evals/metrics.d.ts.map +1 -0
  70. package/dist/evals/metrics.js +364 -0
  71. package/dist/evals/metrics.js.map +1 -0
  72. package/dist/evals/predicate.d.ts +79 -0
  73. package/dist/evals/predicate.d.ts.map +1 -0
  74. package/dist/evals/predicate.js +178 -0
  75. package/dist/evals/predicate.js.map +1 -0
  76. package/dist/evals/runner.d.ts +94 -0
  77. package/dist/evals/runner.d.ts.map +1 -0
  78. package/dist/evals/runner.js +202 -0
  79. package/dist/evals/runner.js.map +1 -0
  80. package/dist/gateway.d.ts +118 -0
  81. package/dist/gateway.d.ts.map +1 -0
  82. package/dist/gateway.js +250 -0
  83. package/dist/gateway.js.map +1 -0
  84. package/dist/index.d.ts +83 -0
  85. package/dist/index.d.ts.map +1 -0
  86. package/dist/index.js +59 -0
  87. package/dist/index.js.map +1 -0
  88. package/dist/internal/json.d.ts +44 -0
  89. package/dist/internal/json.d.ts.map +1 -0
  90. package/dist/internal/json.js +90 -0
  91. package/dist/internal/json.js.map +1 -0
  92. package/dist/internal/text.d.ts +17 -0
  93. package/dist/internal/text.d.ts.map +1 -0
  94. package/dist/internal/text.js +22 -0
  95. package/dist/internal/text.js.map +1 -0
  96. package/dist/pipeline.d.ts +80 -0
  97. package/dist/pipeline.d.ts.map +1 -0
  98. package/dist/pipeline.js +159 -0
  99. package/dist/pipeline.js.map +1 -0
  100. package/dist/policy.d.ts +52 -0
  101. package/dist/policy.d.ts.map +1 -0
  102. package/dist/policy.js +199 -0
  103. package/dist/policy.js.map +1 -0
  104. package/dist/prompts.d.ts +86 -0
  105. package/dist/prompts.d.ts.map +1 -0
  106. package/dist/prompts.js +337 -0
  107. package/dist/prompts.js.map +1 -0
  108. package/dist/providers/base.d.ts +19 -0
  109. package/dist/providers/base.d.ts.map +1 -0
  110. package/dist/providers/base.js +13 -0
  111. package/dist/providers/base.js.map +1 -0
  112. package/dist/providers/fake.d.ts +98 -0
  113. package/dist/providers/fake.d.ts.map +1 -0
  114. package/dist/providers/fake.js +181 -0
  115. package/dist/providers/fake.js.map +1 -0
  116. package/dist/providers/http.d.ts +62 -0
  117. package/dist/providers/http.d.ts.map +1 -0
  118. package/dist/providers/http.js +245 -0
  119. package/dist/providers/http.js.map +1 -0
  120. package/dist/retrieval/chunking.d.ts +88 -0
  121. package/dist/retrieval/chunking.d.ts.map +1 -0
  122. package/dist/retrieval/chunking.js +188 -0
  123. package/dist/retrieval/chunking.js.map +1 -0
  124. package/dist/retrieval/citations.d.ts +98 -0
  125. package/dist/retrieval/citations.d.ts.map +1 -0
  126. package/dist/retrieval/citations.js +134 -0
  127. package/dist/retrieval/citations.js.map +1 -0
  128. package/dist/retrieval/connectors.d.ts +74 -0
  129. package/dist/retrieval/connectors.d.ts.map +1 -0
  130. package/dist/retrieval/connectors.js +218 -0
  131. package/dist/retrieval/connectors.js.map +1 -0
  132. package/dist/retrieval/embedding.d.ts +116 -0
  133. package/dist/retrieval/embedding.d.ts.map +1 -0
  134. package/dist/retrieval/embedding.js +282 -0
  135. package/dist/retrieval/embedding.js.map +1 -0
  136. package/dist/retrieval/gate.d.ts +52 -0
  137. package/dist/retrieval/gate.d.ts.map +1 -0
  138. package/dist/retrieval/gate.js +91 -0
  139. package/dist/retrieval/gate.js.map +1 -0
  140. package/dist/retrieval/hybrid.d.ts +76 -0
  141. package/dist/retrieval/hybrid.d.ts.map +1 -0
  142. package/dist/retrieval/hybrid.js +150 -0
  143. package/dist/retrieval/hybrid.js.map +1 -0
  144. package/dist/retrieval/metrics.d.ts +126 -0
  145. package/dist/retrieval/metrics.d.ts.map +1 -0
  146. package/dist/retrieval/metrics.js +200 -0
  147. package/dist/retrieval/metrics.js.map +1 -0
  148. package/dist/retrieval/pgvector.d.ts +62 -0
  149. package/dist/retrieval/pgvector.d.ts.map +1 -0
  150. package/dist/retrieval/pgvector.js +262 -0
  151. package/dist/retrieval/pgvector.js.map +1 -0
  152. package/dist/retrieval/rerank.d.ts +61 -0
  153. package/dist/retrieval/rerank.d.ts.map +1 -0
  154. package/dist/retrieval/rerank.js +105 -0
  155. package/dist/retrieval/rerank.js.map +1 -0
  156. package/dist/retrieval/retriever.d.ts +125 -0
  157. package/dist/retrieval/retriever.d.ts.map +1 -0
  158. package/dist/retrieval/retriever.js +281 -0
  159. package/dist/retrieval/retriever.js.map +1 -0
  160. package/dist/retrieval/stores.d.ts +106 -0
  161. package/dist/retrieval/stores.d.ts.map +1 -0
  162. package/dist/retrieval/stores.js +142 -0
  163. package/dist/retrieval/stores.js.map +1 -0
  164. package/dist/retrieval/types.d.ts +314 -0
  165. package/dist/retrieval/types.d.ts.map +1 -0
  166. package/dist/retrieval/types.js +388 -0
  167. package/dist/retrieval/types.js.map +1 -0
  168. package/dist/steps.d.ts +156 -0
  169. package/dist/steps.d.ts.map +1 -0
  170. package/dist/steps.js +199 -0
  171. package/dist/steps.js.map +1 -0
  172. package/dist/structured.d.ts +91 -0
  173. package/dist/structured.d.ts.map +1 -0
  174. package/dist/structured.js +155 -0
  175. package/dist/structured.js.map +1 -0
  176. package/dist/tools.d.ts +100 -0
  177. package/dist/tools.d.ts.map +1 -0
  178. package/dist/tools.js +201 -0
  179. package/dist/tools.js.map +1 -0
  180. package/dist/tracing.d.ts +104 -0
  181. package/dist/tracing.d.ts.map +1 -0
  182. package/dist/tracing.js +155 -0
  183. package/dist/tracing.js.map +1 -0
  184. package/dist/types.d.ts +240 -0
  185. package/dist/types.d.ts.map +1 -0
  186. package/dist/types.js +357 -0
  187. package/dist/types.js.map +1 -0
  188. package/package.json +77 -3
@@ -0,0 +1,85 @@
1
+ /**
2
+ * The agent-engine seam: which backend runs an agent, and on exactly which release.
3
+ *
4
+ * Deep Agents is an *orchestration backend* selected per agent, never the IR, never the
5
+ * gateway, and never the only implementation. `native` stays the default.
6
+ *
7
+ * **The pin.** {@link DEEPAGENTS_PIN} is the single authoritative record of the Deep
8
+ * Agents release this runtime was built and measured against. It is a bare constant rather
9
+ * than a range because a range is the thing pinning exists to prevent: the harness's
10
+ * middleware stack, its recursion accounting and its interrupt payload all move between
11
+ * releases, so an unpinned backend would change behaviour under a stored eval baseline.
12
+ * {@link checkEngine} compares the IR's `engineVersion` against *this* constant, not
13
+ * against whatever package happens to be importable.
14
+ *
15
+ * **Per-runtime pins.** The npm harness and the Python harness do not share version
16
+ * numbers: this runtime pins `deepagents@1.16.0`, the Python runtime pins
17
+ * `deepagents==0.7.32`. One `engineVersion` therefore cannot satisfy both, and it is not
18
+ * asked to. Each runtime compares the declaration against its own pin, so a spec versioned
19
+ * for Python is refused here with {@link DeepAgentsVersionMismatchError} -- honestly, at
20
+ * the seam that would have to run it -- rather than being waved through on a major-version
21
+ * match. Accepting any installed release would recreate exactly the silent-drift hole the
22
+ * pin exists to close.
23
+ *
24
+ * **Fail closed, in one place.** Every reason a `deepagents` agent cannot run -- unknown
25
+ * engine, transfer declared, mismatched pin, missing package -- is raised from
26
+ * {@link checkEngine}. Putting them together means there is one function to read to know
27
+ * whether an engine is supported, and no second path that could grow a silent fallback to
28
+ * the native loop. A runtime that quietly ran a `deepagents` agent on the native engine
29
+ * would leave `engine` in the IR meaning nothing at all.
30
+ *
31
+ * **The backend.** This runtime runs `deepagents` agents through the real npm harness; see
32
+ * `./deep_agents.ts`. The harness is an optional peer dependency, because an application
33
+ * that never names `engine: deepagents` should not install a LangChain tree. That makes
34
+ * {@link installedDeepagentsVersion} load-bearing: it is what turns "the package is absent"
35
+ * into {@link DeepAgentsUnavailableError} instead of an unresolvable import.
36
+ */
37
+ import type { AgentDefinition } from './ir.js';
38
+ /** The default engine, and the one every agent that names none keeps using. */
39
+ export declare const NATIVE = "native";
40
+ /** The Deep Agents backend. */
41
+ export declare const DEEPAGENTS = "deepagents";
42
+ /** The closed set of engines the IR may name. */
43
+ export declare const ENGINES: ReadonlySet<string>;
44
+ /**
45
+ * The one authoritative pin. Measured from the npm registry and mirrored in this
46
+ * package's `peerDependenciesMeta`; compared against the IR's `engineVersion` at run time.
47
+ */
48
+ export declare const DEEPAGENTS_PIN = "1.16.0";
49
+ /**
50
+ * The harness and every required peer, at the exact releases this runtime was measured
51
+ * against. `deepagents@1.16.0` declares each of these as a peer, so an application that
52
+ * opts into the backend has to satisfy all of them; spelling them out means the install
53
+ * instruction in the error message is the one that was actually tested.
54
+ */
55
+ export declare const DEEPAGENTS_PEERS: readonly string[];
56
+ /** The optional peer set that installs the harness, as one `npm install` argument list. */
57
+ export declare const DEEPAGENTS_EXTRA: string;
58
+ /** The distribution the peers install. */
59
+ export declare const DEEPAGENTS_DISTRIBUTION = "deepagents";
60
+ /**
61
+ * How {@link installedDeepagentsVersion} finds the harness.
62
+ *
63
+ * A seam rather than a bare import so the absent-harness branch is reachable in a test that
64
+ * has the package installed -- the alternative is uninstalling it, which no hermetic test
65
+ * can do. It is also what the native-default test observes to prove the runtime never goes
66
+ * looking for the harness at all when the engine is `native`.
67
+ */
68
+ export type VersionDetector = () => string | undefined;
69
+ /**
70
+ * The installed `deepagents` version, or `undefined` when the package is absent.
71
+ *
72
+ * `detect` exists so a test can exercise the absent branch without uninstalling anything;
73
+ * production callers pass nothing.
74
+ */
75
+ export declare function installedDeepagentsVersion(detect?: VersionDetector): string | undefined;
76
+ /**
77
+ * Validate this agent's engine, or raise the reason it cannot run.
78
+ *
79
+ * Returns the validated engine name. `native` always passes, and passes *before* any
80
+ * version detection: an agent that does not opt in must never pay for, or even look for,
81
+ * the harness. `deepagents` passes only when it declares no handoffs, pins
82
+ * `engineVersion` to the version this runtime is built for, and the package is installed.
83
+ */
84
+ export declare function checkEngine(agent: AgentDefinition, detect?: VersionDetector): string;
85
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/agents/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAWH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,+EAA+E;AAC/E,eAAO,MAAM,MAAM,WAAW,CAAC;AAE/B,+BAA+B;AAC/B,eAAO,MAAM,UAAU,eAAe,CAAC;AAEvC,iDAAiD;AACjD,eAAO,MAAM,OAAO,EAAE,WAAW,CAAC,MAAM,CAAiC,CAAC;AAE1E;;;GAGG;AACH,eAAO,MAAM,cAAc,WAAW,CAAC;AAEvC;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,SAAS,MAAM,EAQ7C,CAAC;AAEF,2FAA2F;AAC3F,eAAO,MAAM,gBAAgB,QAA6B,CAAC;AAE3D,0CAA0C;AAC1C,eAAO,MAAM,uBAAuB,eAAe,CAAC;AAEpD;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,MAAM,GAAG,SAAS,CAAC;AAuBvD;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,MAAM,GAAE,eAAsC,GAC7C,MAAM,GAAG,SAAS,CAEpB;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,eAAe,EACtB,MAAM,GAAE,eAAsC,GAC7C,MAAM,CAqBR"}
@@ -0,0 +1,129 @@
1
+ /**
2
+ * The agent-engine seam: which backend runs an agent, and on exactly which release.
3
+ *
4
+ * Deep Agents is an *orchestration backend* selected per agent, never the IR, never the
5
+ * gateway, and never the only implementation. `native` stays the default.
6
+ *
7
+ * **The pin.** {@link DEEPAGENTS_PIN} is the single authoritative record of the Deep
8
+ * Agents release this runtime was built and measured against. It is a bare constant rather
9
+ * than a range because a range is the thing pinning exists to prevent: the harness's
10
+ * middleware stack, its recursion accounting and its interrupt payload all move between
11
+ * releases, so an unpinned backend would change behaviour under a stored eval baseline.
12
+ * {@link checkEngine} compares the IR's `engineVersion` against *this* constant, not
13
+ * against whatever package happens to be importable.
14
+ *
15
+ * **Per-runtime pins.** The npm harness and the Python harness do not share version
16
+ * numbers: this runtime pins `deepagents@1.16.0`, the Python runtime pins
17
+ * `deepagents==0.7.32`. One `engineVersion` therefore cannot satisfy both, and it is not
18
+ * asked to. Each runtime compares the declaration against its own pin, so a spec versioned
19
+ * for Python is refused here with {@link DeepAgentsVersionMismatchError} -- honestly, at
20
+ * the seam that would have to run it -- rather than being waved through on a major-version
21
+ * match. Accepting any installed release would recreate exactly the silent-drift hole the
22
+ * pin exists to close.
23
+ *
24
+ * **Fail closed, in one place.** Every reason a `deepagents` agent cannot run -- unknown
25
+ * engine, transfer declared, mismatched pin, missing package -- is raised from
26
+ * {@link checkEngine}. Putting them together means there is one function to read to know
27
+ * whether an engine is supported, and no second path that could grow a silent fallback to
28
+ * the native loop. A runtime that quietly ran a `deepagents` agent on the native engine
29
+ * would leave `engine` in the IR meaning nothing at all.
30
+ *
31
+ * **The backend.** This runtime runs `deepagents` agents through the real npm harness; see
32
+ * `./deep_agents.ts`. The harness is an optional peer dependency, because an application
33
+ * that never names `engine: deepagents` should not install a LangChain tree. That makes
34
+ * {@link installedDeepagentsVersion} load-bearing: it is what turns "the package is absent"
35
+ * into {@link DeepAgentsUnavailableError} instead of an unresolvable import.
36
+ */
37
+ import { createRequire } from 'node:module';
38
+ import { AgentHandoffUnsupportedError, ConfigurationError, DeepAgentsUnavailableError, DeepAgentsVersionMismatchError, } from '../errors.js';
39
+ import { repr } from '../internal/json.js';
40
+ /** The default engine, and the one every agent that names none keeps using. */
41
+ export const NATIVE = 'native';
42
+ /** The Deep Agents backend. */
43
+ export const DEEPAGENTS = 'deepagents';
44
+ /** The closed set of engines the IR may name. */
45
+ export const ENGINES = new Set([NATIVE, DEEPAGENTS]);
46
+ /**
47
+ * The one authoritative pin. Measured from the npm registry and mirrored in this
48
+ * package's `peerDependenciesMeta`; compared against the IR's `engineVersion` at run time.
49
+ */
50
+ export const DEEPAGENTS_PIN = '1.16.0';
51
+ /**
52
+ * The harness and every required peer, at the exact releases this runtime was measured
53
+ * against. `deepagents@1.16.0` declares each of these as a peer, so an application that
54
+ * opts into the backend has to satisfy all of them; spelling them out means the install
55
+ * instruction in the error message is the one that was actually tested.
56
+ */
57
+ export const DEEPAGENTS_PEERS = [
58
+ 'deepagents@1.16.0',
59
+ 'langchain@1.5.10',
60
+ '@langchain/core@1.2.14',
61
+ '@langchain/langgraph@1.5.3',
62
+ '@langchain/langgraph-sdk@1.12.8',
63
+ '@langchain/langgraph-checkpoint@1.2.1',
64
+ 'langsmith@0.9.0',
65
+ ];
66
+ /** The optional peer set that installs the harness, as one `npm install` argument list. */
67
+ export const DEEPAGENTS_EXTRA = DEEPAGENTS_PEERS.join(' ');
68
+ /** The distribution the peers install. */
69
+ export const DEEPAGENTS_DISTRIBUTION = 'deepagents';
70
+ const requireFromHere = createRequire(import.meta.url);
71
+ /**
72
+ * Read the installed harness version from its own manifest.
73
+ *
74
+ * `deepagents/package.json` rather than the module entry point: the manifest is not behind
75
+ * an `exports` guard, and reading it means detection never loads 3 MB of LangChain just to
76
+ * answer a version question.
77
+ */
78
+ function readInstalledVersion() {
79
+ let manifest;
80
+ try {
81
+ manifest = requireFromHere('deepagents/package.json');
82
+ }
83
+ catch {
84
+ return undefined;
85
+ }
86
+ if (typeof manifest !== 'object' || manifest === null)
87
+ return undefined;
88
+ const version = manifest.version;
89
+ return typeof version === 'string' ? version : undefined;
90
+ }
91
+ /**
92
+ * The installed `deepagents` version, or `undefined` when the package is absent.
93
+ *
94
+ * `detect` exists so a test can exercise the absent branch without uninstalling anything;
95
+ * production callers pass nothing.
96
+ */
97
+ export function installedDeepagentsVersion(detect = readInstalledVersion) {
98
+ return detect();
99
+ }
100
+ /**
101
+ * Validate this agent's engine, or raise the reason it cannot run.
102
+ *
103
+ * Returns the validated engine name. `native` always passes, and passes *before* any
104
+ * version detection: an agent that does not opt in must never pay for, or even look for,
105
+ * the harness. `deepagents` passes only when it declares no handoffs, pins
106
+ * `engineVersion` to the version this runtime is built for, and the package is installed.
107
+ */
108
+ export function checkEngine(agent, detect = readInstalledVersion) {
109
+ if (agent.engine === NATIVE)
110
+ return NATIVE;
111
+ if (agent.engine !== DEEPAGENTS) {
112
+ throw new ConfigurationError(`agent ${repr(agent.id)} declares engine ${repr(agent.engine)}; the IR admits ` +
113
+ `[${[...ENGINES]
114
+ .sort()
115
+ .map((engine) => repr(engine))
116
+ .join(', ')}]`);
117
+ }
118
+ if (agent.handoffs.length > 0) {
119
+ throw new AgentHandoffUnsupportedError(agent.id, agent.handoffs, DEEPAGENTS);
120
+ }
121
+ if (agent.engineVersion !== DEEPAGENTS_PIN) {
122
+ throw new DeepAgentsVersionMismatchError(agent.id, agent.engineVersion, DEEPAGENTS_PIN);
123
+ }
124
+ if (detect() === undefined) {
125
+ throw new DeepAgentsUnavailableError(DEEPAGENTS_EXTRA, DEEPAGENTS_DISTRIBUTION);
126
+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,CAAC,EAAE,EAAE,KAAK,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;IAC1F,CAAC;IACD,IAAI,MAAM,EAAE,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,IAAI,0BAA0B,CAAC,gBAAgB,EAAE,uBAAuB,CAAC,CAAC;IAClF,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Expose {@link ModelGateway} as a LangChain chat model.
3
+ *
4
+ * This module is the load-bearing part of the Deep Agents backend. A harness handed a
5
+ * provider would keep working while silently dropping every guarantee the gateway exists
6
+ * to provide: the fallback chain, the budget preflight, the cost ledger and the
7
+ * per-attempt LLM span. The agent would look fine and the budget would stop applying. So
8
+ * the harness is never handed a provider -- it is handed *this adapter*, and every model
9
+ * call inside the graph goes back out through our gateway.
10
+ *
11
+ * What the adapter is responsible for:
12
+ *
13
+ * - **Translation, both directions.** LangChain messages to our {@link Message}, and our
14
+ * {@link CompletionResponse} back to an `AIMessage` carrying tool calls, `usage_metadata`
15
+ * and the alias/cost the gateway actually charged. The alias matters: a fallback means
16
+ * the answer did not come from the pinned model, and the response says so rather than
17
+ * letting the harness believe otherwise.
18
+ * - **Tool filtering.** `bindTools` is the single funnel every tool reaches the model
19
+ * through, which makes it the one place to enforce what the agent may call. Deep Agents
20
+ * bundles `ls`/`read_file`/`write_file`/`edit_file`/`delete`/`glob`/`grep`/`execute` and
21
+ * binds all of them; the allow-list drops everything the agent did not declare, so the
22
+ * filesystem and shell tools are unreachable rather than merely undocumented.
23
+ * - **Budget continuity.** The agent's ceiling travels with every call, so a breach
24
+ * surfaces as the gateway's own {@link BudgetExceededError} from inside the harness.
25
+ * There is no second accounting path here to disagree with it.
26
+ *
27
+ * Everything in here statically imports `@langchain/*`. That is deliberate and safe: the
28
+ * harness is optional for consumers, `agents/deep_agents.ts` is the only module that
29
+ * reaches this one, and it does so with a dynamic `import()` after {@link checkEngine} has
30
+ * proved the packages are installed.
31
+ */
32
+ import type { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
33
+ import type { BaseChatModelCallOptions, BindToolsInput } from '@langchain/core/language_models/chat_models';
34
+ import { BaseChatModel } from '@langchain/core/language_models/chat_models';
35
+ import type { BaseMessage } from '@langchain/core/messages';
36
+ import type { ChatGenerationChunk, ChatResult } from '@langchain/core/outputs';
37
+ import { z } from 'zod';
38
+ import type { Budget } from '../cost.js';
39
+ import type { ModelGateway } from '../gateway.js';
40
+ import type { GenerationResult } from '../types.js';
41
+ import { Message, ToolDefinition } from '../types.js';
42
+ /** What {@link harnessTool} needs to build one harness tool around our executor. */
43
+ export interface HarnessToolSpec {
44
+ readonly name: string;
45
+ readonly description: string;
46
+ readonly parameters: Record<string, unknown>;
47
+ /** Run the call through the native loop's executor and return the observation. */
48
+ readonly call: (args: Record<string, unknown>) => Promise<string>;
49
+ }
50
+ /**
51
+ * A LangChain chat model whose every generation is a gateway call.
52
+ *
53
+ * Construct it with the alias the IR pinned, the gateway that owns fallback and
54
+ * accounting, and the ceiling this agent may spend. `allowedTools` is the tool allow-list:
55
+ * `undefined` admits everything the harness binds, which is only appropriate for an agent
56
+ * that declares no tools.
57
+ */
58
+ export declare class GatewayChatModel extends BaseChatModel {
59
+ readonly gateway: ModelGateway;
60
+ readonly alias: string;
61
+ readonly fallbacks: readonly string[];
62
+ readonly budget: Budget | undefined;
63
+ readonly allowedTools: ReadonlySet<string> | undefined;
64
+ /**
65
+ * The agent's `maxSteps`, counted in model calls. Enforced here because this adapter is
66
+ * the only place that sees every model call -- and because the harness's own limiter
67
+ * *completes* the run with a synthetic answer instead of failing.
68
+ */
69
+ readonly maxCalls: number | undefined;
70
+ /** What `bindTools` last admitted. Read by tests, never by the harness. */
71
+ readonly boundTools: readonly ToolDefinition[];
72
+ /** Every generation this model produced, in order: proof the harness went through us. */
73
+ readonly calls: GenerationResult[];
74
+ constructor(init: {
75
+ readonly gateway: ModelGateway;
76
+ readonly alias: string;
77
+ readonly fallbacks?: readonly string[];
78
+ readonly budget?: Budget;
79
+ readonly allowedTools?: ReadonlySet<string>;
80
+ readonly maxCalls?: number;
81
+ readonly boundTools?: readonly ToolDefinition[];
82
+ readonly calls?: GenerationResult[];
83
+ });
84
+ /**
85
+ * Admit only the tools this agent declared.
86
+ *
87
+ * Every tool the harness offers -- bundled ones included -- arrives here, so an
88
+ * allow-list applied at this point is the difference between "we do not document a
89
+ * shell" and "there is no shell the model can reach". The filtered set is kept on a copy
90
+ * rather than on `this` so two agents sharing one adapter cannot widen each other's
91
+ * grant; the copy shares `calls`, because the accumulator is the run's spend record and a
92
+ * per-copy one would silently lose the generations of every bound model.
93
+ */
94
+ bindTools(tools: BindToolsInput[]): GatewayChatModel;
95
+ _llmType(): string;
96
+ _identifyingParams(): Record<string, unknown>;
97
+ /**
98
+ * One harness model call, routed through the gateway.
99
+ *
100
+ * LangChain 1.x exposes a single async generation hook: `generate` and `invoke` both
101
+ * return promises and there is no synchronous entry point at all, so unlike the Python
102
+ * adapter there is no second path to refuse here.
103
+ *
104
+ * `fallbacks` and `budget` travel with the call, so the harness gets the same fallback
105
+ * behaviour and the same hard ceiling as the native loop. A breach is raised, not
106
+ * returned: the harness must not be able to continue past a budget the ledger refused.
107
+ */
108
+ _generate(messages: BaseMessage[], _options: BaseChatModelCallOptions, _runManager?: CallbackManagerForLLMRun): Promise<ChatResult>;
109
+ _streamResponseChunks(_messages: BaseMessage[], _options: BaseChatModelCallOptions, _runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
110
+ }
111
+ /**
112
+ * Translate the harness transcript into ours.
113
+ *
114
+ * Tool calls and their ids are preserved verbatim: the harness pairs a result with its
115
+ * call by id, and renaming or renumbering them here would break the pairing in a way that
116
+ * only shows up as a tool result attached to the wrong call.
117
+ */
118
+ export declare function toAidMessages(messages: readonly BaseMessage[]): Message[];
119
+ /**
120
+ * Normalise the harness's tool specs and drop everything outside the grant.
121
+ *
122
+ * The harness offers OpenAI-shaped objects, bare `{name, parameters}` records, and
123
+ * `BaseTool` instances carrying a Zod schema. All are accepted so the allow-list cannot be
124
+ * bypassed by a shape the filter did not recognise: anything unparseable has no name, and
125
+ * a tool with no name is refused rather than passed through.
126
+ */
127
+ export declare function toToolDefinitions(tools: readonly BindToolsInput[], options?: {
128
+ readonly allowed?: ReadonlySet<string> | undefined;
129
+ }): ToolDefinition[];
130
+ /**
131
+ * Translate our transcript back out, for seeding the harness with prior turns.
132
+ *
133
+ * This exists so a resumed run hands the harness the same transcript the native loop would
134
+ * have, rather than a summary of it. Tool calls are re-emitted as `AIMessage.tool_calls` so
135
+ * the harness sees them as calls it can pair, which is what keeps a resumed run's
136
+ * transcript comparable to an uninterrupted one.
137
+ */
138
+ export declare function toLangchainMessages(messages: readonly Message[]): BaseMessage[];
139
+ /**
140
+ * Wrap one declared tool as a harness tool whose body is our executor.
141
+ *
142
+ * The body is deliberately thin: authorization and the tool-call guardrail run in the
143
+ * guardrail middleware of whichever agent is calling, and execution goes through the same
144
+ * `ToolExecutor` the native loop uses. That is what makes a tool call under this engine the
145
+ * same event as one under the native engine.
146
+ *
147
+ * The call id is derived, not random: the harness pairs a result with its call by id, and a
148
+ * random one would make two identical runs differ.
149
+ */
150
+ export declare function harnessTool(spec: HarnessToolSpec): import("@langchain/core/tools").DynamicStructuredTool<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, Record<string, unknown>, unknown, string, unknown, string> | import("@langchain/core/tools").DynamicTool<string, unknown>;
151
+ //# sourceMappingURL=gateway_chat_model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gateway_chat_model.d.ts","sourceRoot":"","sources":["../../src/agents/gateway_chat_model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAClF,OAAO,KAAK,EACV,wBAAwB,EACxB,cAAc,EACf,MAAM,6CAA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