@botbotgo/agent-harness 0.0.475 → 0.0.476

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 (227) hide show
  1. package/README.md +3 -1234
  2. package/README.zh.md +3 -1191
  3. package/dist/acp.js +1 -1
  4. package/dist/api.js +1 -404
  5. package/dist/benchmark/checkpoint-resume-cost-benchmark.js +1 -55
  6. package/dist/benchmark/deepagent-local-model-benchmark.js +2 -35
  7. package/dist/benchmark/upstream-runtime-ab-benchmark.js +1 -179
  8. package/dist/cli/chat-interactive.js +25 -244
  9. package/dist/cli/chat-rendering.js +6 -100
  10. package/dist/cli/chat-stream.js +23 -512
  11. package/dist/cli/chat-ui.js +21 -199
  12. package/dist/cli/chat-workspace.js +2 -210
  13. package/dist/cli/main.js +21 -428
  14. package/dist/cli/managed-service-commands.js +9 -63
  15. package/dist/cli/managed-service.js +2 -137
  16. package/dist/cli/options-init-chat.js +1 -108
  17. package/dist/cli/options-runtime.js +1 -158
  18. package/dist/cli/options-serve.js +1 -282
  19. package/dist/cli/options.js +2 -19
  20. package/dist/cli/process-guards.js +1 -139
  21. package/dist/cli/request-tree.js +7 -296
  22. package/dist/cli/runtime-commands.js +12 -258
  23. package/dist/cli/runtime-output.js +16 -155
  24. package/dist/cli/server-commands.js +16 -270
  25. package/dist/cli/workspace.js +1 -67
  26. package/dist/cli.js +1 -7
  27. package/dist/client/acp.js +1 -1
  28. package/dist/client/in-process.js +1 -67
  29. package/dist/client/index.js +1 -2
  30. package/dist/client/types.js +0 -1
  31. package/dist/client.js +1 -1
  32. package/dist/contracts/core.js +1 -1
  33. package/dist/contracts/runtime-evaluation.js +0 -1
  34. package/dist/contracts/runtime-memory.js +0 -1
  35. package/dist/contracts/runtime-observability.js +0 -1
  36. package/dist/contracts/runtime-requests.js +0 -1
  37. package/dist/contracts/runtime-scheduling.js +0 -1
  38. package/dist/contracts/runtime.js +1 -27
  39. package/dist/contracts/types.js +1 -3
  40. package/dist/contracts/workspace.js +0 -1
  41. package/dist/flow/build-flow-graph.js +1 -50
  42. package/dist/flow/export-mermaid.js +2 -464
  43. package/dist/flow/export-sequence-mermaid.js +2 -325
  44. package/dist/flow/flow-graph-normalization.js +1 -214
  45. package/dist/flow/flow-graph-runtime.js +1 -107
  46. package/dist/flow/flow-graph-upstream.js +1 -494
  47. package/dist/flow/index.js +1 -3
  48. package/dist/flow/types.js +0 -1
  49. package/dist/index.js +1 -5
  50. package/dist/init-project.js +1 -1
  51. package/dist/knowledge/config.js +1 -32
  52. package/dist/knowledge/contracts.js +0 -1
  53. package/dist/knowledge/index.js +1 -2
  54. package/dist/knowledge/module.js +12 -909
  55. package/dist/knowledge/procedural/config.js +1 -125
  56. package/dist/knowledge/procedural/index.js +1 -2
  57. package/dist/knowledge/procedural/manager.js +9 -345
  58. package/dist/mcp.js +1 -2
  59. package/dist/package-version.d.ts +1 -1
  60. package/dist/package-version.js +1 -2
  61. package/dist/persistence/file-store.js +3 -758
  62. package/dist/persistence/sqlite-request-context-store.js +5 -54
  63. package/dist/persistence/sqlite-request-queue-store.js +10 -108
  64. package/dist/persistence/sqlite-runtime.js +1 -86
  65. package/dist/persistence/sqlite-store.js +62 -810
  66. package/dist/persistence/types.js +0 -1
  67. package/dist/projections/presentation.js +37 -206
  68. package/dist/projections/request-events.js +2 -502
  69. package/dist/projections/upstream-events.js +1 -201
  70. package/dist/protocol/a2a/http-discovery.js +1 -178
  71. package/dist/protocol/a2a/http-rpc.js +6 -622
  72. package/dist/protocol/a2a/http.js +1 -138
  73. package/dist/protocol/a2a/task-state.js +3 -317
  74. package/dist/protocol/acp/client.js +8 -294
  75. package/dist/protocol/acp/harness-client.js +1 -218
  76. package/dist/protocol/acp/http.js +5 -130
  77. package/dist/protocol/acp/server.js +1 -310
  78. package/dist/protocol/acp/stdio.js +2 -69
  79. package/dist/protocol/ag-ui/http.js +3 -378
  80. package/dist/protocol/mcp/server.js +1 -428
  81. package/dist/resource/backend/workspace-scoped-backend.js +1 -319
  82. package/dist/resource/isolation.js +1 -237
  83. package/dist/resource/mcp/tool-support.js +3 -296
  84. package/dist/resource/mcp-tool-support.js +1 -2
  85. package/dist/resource/providers/resource-provider.js +1 -215
  86. package/dist/resource/resource-impl.js +1 -3
  87. package/dist/resource/resource-types.js +0 -1
  88. package/dist/resource/resource.js +1 -1
  89. package/dist/resource/sources.js +1 -247
  90. package/dist/resource/tools/function-tool-resolver.js +2 -272
  91. package/dist/runtime/adapter/compat/deepagent-compat.js +1 -29
  92. package/dist/runtime/adapter/compat/openai-compatible.js +1 -55
  93. package/dist/runtime/adapter/direct-builtin-utility.js +2 -90
  94. package/dist/runtime/adapter/flow/execution-context.js +1 -71
  95. package/dist/runtime/adapter/flow/invocation-flow.js +8 -425
  96. package/dist/runtime/adapter/flow/invoke-runtime.js +1 -20
  97. package/dist/runtime/adapter/flow/stream-runtime.js +11 -1395
  98. package/dist/runtime/adapter/invocation-result.js +2 -473
  99. package/dist/runtime/adapter/local-tool-invocation.js +6 -638
  100. package/dist/runtime/adapter/middleware/context-hygiene.js +1 -83
  101. package/dist/runtime/adapter/middleware-assembly.js +5 -477
  102. package/dist/runtime/adapter/model/invocation-request.js +3 -183
  103. package/dist/runtime/adapter/model/message-assembly.js +1 -28
  104. package/dist/runtime/adapter/model/model-providers.js +23 -1115
  105. package/dist/runtime/adapter/model/prompted-json-tool-call-capture.js +1 -40
  106. package/dist/runtime/adapter/model/prompted-json-tool-policy.js +1 -22
  107. package/dist/runtime/adapter/resilience.js +1 -104
  108. package/dist/runtime/adapter/runtime-adapter-support.js +3 -141
  109. package/dist/runtime/adapter/runtime-shell.js +5 -166
  110. package/dist/runtime/adapter/stream-event-projection.js +2 -622
  111. package/dist/runtime/adapter/stream-text-consumption.js +1 -18
  112. package/dist/runtime/adapter/terminal-status.js +2 -67
  113. package/dist/runtime/adapter/tool/builtin-middleware-tools.js +6 -627
  114. package/dist/runtime/adapter/tool/declared-middleware.js +1 -154
  115. package/dist/runtime/adapter/tool/interrupt-policy.js +1 -34
  116. package/dist/runtime/adapter/tool/provider-tool.js +1 -25
  117. package/dist/runtime/adapter/tool/resolved-tool.js +1 -225
  118. package/dist/runtime/adapter/tool/tool-arguments.js +3 -486
  119. package/dist/runtime/adapter/tool/tool-hitl.js +1 -346
  120. package/dist/runtime/adapter/tool/tool-name-mapping.js +1 -128
  121. package/dist/runtime/adapter/tool/tool-output-artifacts.js +2 -88
  122. package/dist/runtime/adapter/tool/tool-replay.js +1 -37
  123. package/dist/runtime/adapter/tool-resolution.js +1 -86
  124. package/dist/runtime/adapter/upstream-configurable-keys.js +1 -2
  125. package/dist/runtime/agent-runtime-adapter.js +60 -2338
  126. package/dist/runtime/agent-runtime-assembly.js +7 -249
  127. package/dist/runtime/env/runtime-env.js +1 -62
  128. package/dist/runtime/harness/background-runtime.js +1 -8
  129. package/dist/runtime/harness/bindings.js +1 -58
  130. package/dist/runtime/harness/events/event-bus.js +1 -16
  131. package/dist/runtime/harness/events/event-sink.js +1 -61
  132. package/dist/runtime/harness/events/events.js +1 -80
  133. package/dist/runtime/harness/events/listener-runtime.js +1 -13
  134. package/dist/runtime/harness/events/runtime-event-operations.js +1 -9
  135. package/dist/runtime/harness/events/streaming.js +1 -100
  136. package/dist/runtime/harness/events/timeline.js +1 -52
  137. package/dist/runtime/harness/public-shapes.js +1 -186
  138. package/dist/runtime/harness/run/artifact-paths.js +1 -15
  139. package/dist/runtime/harness/run/governance.js +1 -295
  140. package/dist/runtime/harness/run/helpers.js +1 -71
  141. package/dist/runtime/harness/run/inspection.js +1 -409
  142. package/dist/runtime/harness/run/operator-overview.js +1 -80
  143. package/dist/runtime/harness/run/queue-diagnostics.js +1 -15
  144. package/dist/runtime/harness/run/recovery.js +1 -162
  145. package/dist/runtime/harness/run/resources.js +1 -60
  146. package/dist/runtime/harness/run/resume.js +1 -56
  147. package/dist/runtime/harness/run/routing.js +1 -48
  148. package/dist/runtime/harness/run/run-lifecycle.js +1 -66
  149. package/dist/runtime/harness/run/run-operations.js +1 -217
  150. package/dist/runtime/harness/run/run-queue.js +1 -43
  151. package/dist/runtime/harness/run/run-slot-acquisition.js +1 -157
  152. package/dist/runtime/harness/run/session-records.js +1 -97
  153. package/dist/runtime/harness/run/start-run.js +1 -120
  154. package/dist/runtime/harness/run/startup-runtime.js +1 -69
  155. package/dist/runtime/harness/run/stream-run.js +8 -1418
  156. package/dist/runtime/harness/run/surface-semantics.js +1 -79
  157. package/dist/runtime/harness/runtime-defaults.js +1 -39
  158. package/dist/runtime/harness/system/boundary-analysis.js +1 -234
  159. package/dist/runtime/harness/system/health-monitor.js +1 -258
  160. package/dist/runtime/harness/system/inventory.js +1 -129
  161. package/dist/runtime/harness/system/mem0-ingestion-sync.js +5 -345
  162. package/dist/runtime/harness/system/policy-engine.js +1 -175
  163. package/dist/runtime/harness/system/runtime-memory-candidates.js +4 -110
  164. package/dist/runtime/harness/system/runtime-memory-consolidation.js +1 -51
  165. package/dist/runtime/harness/system/runtime-memory-manager.js +10 -693
  166. package/dist/runtime/harness/system/runtime-memory-policy.js +1 -155
  167. package/dist/runtime/harness/system/runtime-memory-records.js +11 -577
  168. package/dist/runtime/harness/system/runtime-memory-sync.js +5 -206
  169. package/dist/runtime/harness/system/session-memory-sync.js +3 -113
  170. package/dist/runtime/harness/system/skill-requirements.js +1 -112
  171. package/dist/runtime/harness/system/store.js +9 -365
  172. package/dist/runtime/harness/tool-gateway/index.js +1 -2
  173. package/dist/runtime/harness/tool-gateway/policy.js +1 -45
  174. package/dist/runtime/harness/tool-gateway/validation.js +1 -176
  175. package/dist/runtime/harness/tool-schema.js +1 -3
  176. package/dist/runtime/harness.js +3 -1490
  177. package/dist/runtime/index.js +1 -3
  178. package/dist/runtime/layout/runtime-layout.js +1 -31
  179. package/dist/runtime/maintenance/checkpoint-maintenance.js +2 -178
  180. package/dist/runtime/maintenance/file-checkpoint-saver.js +1 -106
  181. package/dist/runtime/maintenance/runtime-record-maintenance.js +2 -169
  182. package/dist/runtime/maintenance/sqlite-checkpoint-saver.js +4 -289
  183. package/dist/runtime/parsing/output-content.js +10 -550
  184. package/dist/runtime/parsing/output-parsing.js +1 -4
  185. package/dist/runtime/parsing/output-recovery.js +3 -213
  186. package/dist/runtime/parsing/output-tool-args.js +7 -663
  187. package/dist/runtime/parsing/stream-event-parsing.js +3 -362
  188. package/dist/runtime/prompts/runtime-prompts.js +4 -73
  189. package/dist/runtime/scheduling/system-schedule-manager.js +11 -532
  190. package/dist/runtime/skills/skill-metadata.js +1 -197
  191. package/dist/runtime/startup-tracing.js +2 -37
  192. package/dist/runtime/support/compiled-binding.js +1 -290
  193. package/dist/runtime/support/embedding-models.js +1 -118
  194. package/dist/runtime/support/harness-support.js +5 -137
  195. package/dist/runtime/support/llamaindex.js +1 -108
  196. package/dist/runtime/support/runtime-adapter-options.js +1 -29
  197. package/dist/runtime/support/runtime-factories.js +1 -51
  198. package/dist/runtime/support/vector-stores.js +9 -270
  199. package/dist/scaffold/init-project.js +54 -233
  200. package/dist/tooling/extensions.js +1 -311
  201. package/dist/tooling/module-loader.js +1 -55
  202. package/dist/tools.js +1 -176
  203. package/dist/utils/agent-display.js +1 -18
  204. package/dist/utils/bundled-text.js +4 -39
  205. package/dist/utils/compiled-binding.js +1 -33
  206. package/dist/utils/fs.js +2 -45
  207. package/dist/utils/id.js +1 -9
  208. package/dist/utils/message-content.js +1 -30
  209. package/dist/utils/object.js +1 -6
  210. package/dist/workspace/agent-binding-compiler.js +3 -613
  211. package/dist/workspace/compile.js +1 -472
  212. package/dist/workspace/framework-contract-validation.js +2 -322
  213. package/dist/workspace/index.js +1 -1
  214. package/dist/workspace/object-loader-paths.js +1 -71
  215. package/dist/workspace/object-loader-readers.js +1 -187
  216. package/dist/workspace/object-loader.js +1 -754
  217. package/dist/workspace/resource-compilers.js +1 -374
  218. package/dist/workspace/support/agent-capabilities.js +1 -37
  219. package/dist/workspace/support/agent-execution-config.js +1 -44
  220. package/dist/workspace/support/discovery.js +1 -147
  221. package/dist/workspace/support/source-collectors.js +1 -30
  222. package/dist/workspace/support/source-protocols.js +2 -192
  223. package/dist/workspace/support/workspace-ref-utils.js +1 -362
  224. package/dist/workspace/tool-hydration.js +1 -280
  225. package/dist/workspace/validate.js +1 -99
  226. package/dist/workspace/yaml-object-reader.js +1 -285
  227. package/package.json +7 -3
@@ -1,154 +1 @@
1
- import { anthropicPromptCachingMiddleware, contextEditingMiddleware, dynamicSystemPromptMiddleware, humanInTheLoopMiddleware, llmToolSelectorMiddleware, modelCallLimitMiddleware, modelFallbackMiddleware, modelRetryMiddleware, openAIModerationMiddleware, piiMiddleware, piiRedactionMiddleware, summarizationMiddleware, todoListMiddleware, toolCallLimitMiddleware, toolEmulatorMiddleware, toolRetryMiddleware, } from "langchain";
2
- import { createCompletionCallbackMiddleware, createFilesystemMiddleware, createPatchToolCallsMiddleware, createSummarizationMiddleware as createDeepAgentSummarizationMiddleware, } from "deepagents";
3
- function asMiddlewareConfig(value) {
4
- return typeof value === "object" && value !== null && !Array.isArray(value) ? { ...value } : null;
5
- }
6
- function requireKind(config) {
7
- const kind = typeof config.kind === "string" ? config.kind.trim() : "";
8
- if (!kind) {
9
- throw new Error("Declarative middleware entries must include a non-empty kind");
10
- }
11
- return kind;
12
- }
13
- function omitKind(config) {
14
- const { kind: _kind, ...rest } = config;
15
- return rest;
16
- }
17
- async function resolveReferencedModel(value, options) {
18
- if (value && typeof value === "object" && "id" in value) {
19
- return options.resolveModel(value);
20
- }
21
- return value;
22
- }
23
- async function resolveReferencedModelList(values, options) {
24
- if (!Array.isArray(values)) {
25
- return undefined;
26
- }
27
- return Promise.all(values.map((value) => resolveReferencedModel(value, options)));
28
- }
29
- async function createSummarizationMiddleware({ config, resolveModel }) {
30
- if (config.provider === "deepagents") {
31
- const runtimeConfig = { ...config };
32
- runtimeConfig.model = await resolveReferencedModel(runtimeConfig.model, { resolveModel });
33
- if (runtimeConfig.model === undefined) {
34
- throw new Error("deepagents summarization middleware requires model or modelRef");
35
- }
36
- if (runtimeConfig.backend === undefined) {
37
- throw new Error("deepagents summarization middleware requires backend");
38
- }
39
- delete runtimeConfig.provider;
40
- return createDeepAgentSummarizationMiddleware(runtimeConfig);
41
- }
42
- const runtimeConfig = { ...config };
43
- runtimeConfig.model = await resolveReferencedModel(runtimeConfig.model, { resolveModel });
44
- if (runtimeConfig.model === undefined) {
45
- throw new Error("summarization middleware requires model or modelRef");
46
- }
47
- return summarizationMiddleware(runtimeConfig);
48
- }
49
- async function createBindingAwareSummarizationMiddleware(context) {
50
- const runtimeConfig = { ...context.config };
51
- if (context.binding?.agent.executionMode === "deepagent") {
52
- runtimeConfig.provider = "deepagents";
53
- runtimeConfig.backend ??= context.resolveBackend?.() ?? context.resolveFilesystemBackend?.();
54
- }
55
- return createSummarizationMiddleware({
56
- ...context,
57
- config: runtimeConfig,
58
- });
59
- }
60
- async function createLlmToolSelectorMiddleware({ config, resolveModel }) {
61
- const runtimeConfig = { ...config };
62
- runtimeConfig.model = await resolveReferencedModel(runtimeConfig.model, { resolveModel });
63
- return llmToolSelectorMiddleware(runtimeConfig);
64
- }
65
- async function createModelFallbackDeclarativeMiddleware({ config, resolveModel }) {
66
- const fallbackModels = (await resolveReferencedModelList(config.fallbackModels, { resolveModel })) ??
67
- (await resolveReferencedModelList(config.models, { resolveModel }));
68
- if (!fallbackModels || fallbackModels.length === 0) {
69
- throw new Error("modelFallback middleware requires fallbackModels or models");
70
- }
71
- return modelFallbackMiddleware(...fallbackModels);
72
- }
73
- async function createPiiDeclarativeMiddleware({ config }) {
74
- const piiType = typeof config.piiType === "string" ? config.piiType : undefined;
75
- if (!piiType) {
76
- throw new Error("pii middleware requires piiType");
77
- }
78
- const { piiType: _piiType, ...piiOptions } = config;
79
- return piiMiddleware(piiType, piiOptions);
80
- }
81
- async function createFilesystemDeclarativeMiddleware({ config, resolveFilesystemBackend }) {
82
- const runtimeConfig = { ...config };
83
- runtimeConfig.backend ??= resolveFilesystemBackend?.();
84
- return createFilesystemMiddleware(runtimeConfig);
85
- }
86
- export const DECLARATIVE_MIDDLEWARE_REGISTRY = {
87
- completionCallback: async ({ config }) => createCompletionCallbackMiddleware(config),
88
- filesystem: createFilesystemDeclarativeMiddleware,
89
- patchToolCalls: async () => createPatchToolCallsMiddleware(),
90
- summarization: createBindingAwareSummarizationMiddleware,
91
- llmToolSelector: createLlmToolSelectorMiddleware,
92
- modelRetry: async ({ config }) => modelRetryMiddleware(config),
93
- modelFallback: createModelFallbackDeclarativeMiddleware,
94
- toolRetry: async ({ config }) => toolRetryMiddleware(config),
95
- toolCallLimit: async ({ config }) => toolCallLimitMiddleware(config),
96
- modelCallLimit: async ({ config }) => modelCallLimitMiddleware(config),
97
- todoList: async ({ config }) => todoListMiddleware(config),
98
- contextEditing: async ({ config }) => contextEditingMiddleware(config),
99
- dynamicSystemPrompt: async ({ config }) => dynamicSystemPromptMiddleware(config),
100
- toolEmulator: async ({ config }) => toolEmulatorMiddleware(config),
101
- humanInTheLoop: async ({ config }) => humanInTheLoopMiddleware(config),
102
- openAIModeration: async ({ config }) => openAIModerationMiddleware(config),
103
- pii: createPiiDeclarativeMiddleware,
104
- piiRedaction: async ({ config }) => piiRedactionMiddleware(config),
105
- anthropicPromptCaching: async ({ config }) => anthropicPromptCachingMiddleware(config),
106
- };
107
- export const SUPPORTED_DECLARATIVE_MIDDLEWARE_KINDS = Object.freeze(Object.keys(DECLARATIVE_MIDDLEWARE_REGISTRY).sort());
108
- export async function resolveDeclaredMiddleware(middlewareConfigs, options) {
109
- const resolved = [];
110
- for (const rawConfig of middlewareConfigs ?? []) {
111
- const config = asMiddlewareConfig(rawConfig);
112
- if (!config) {
113
- continue;
114
- }
115
- const kind = requireKind(config);
116
- const runtimeConfig = omitKind(config);
117
- const registeredFactory = DECLARATIVE_MIDDLEWARE_REGISTRY[kind];
118
- if (registeredFactory) {
119
- const resolvedBuiltin = await registeredFactory({
120
- config: runtimeConfig,
121
- resolveModel: options.resolveModel,
122
- resolveBackend: () => options.resolveBackend?.(options.binding),
123
- resolveFilesystemBackend: () => options.resolveFilesystemBackend?.(options.binding),
124
- binding: options.binding,
125
- });
126
- if (Array.isArray(resolvedBuiltin)) {
127
- resolved.push(...resolvedBuiltin);
128
- continue;
129
- }
130
- if (resolvedBuiltin) {
131
- resolved.push(resolvedBuiltin);
132
- continue;
133
- }
134
- }
135
- const customResolved = options.resolveCustom
136
- ? await options.resolveCustom({
137
- kind,
138
- config: runtimeConfig,
139
- binding: options.binding,
140
- resolveModel: options.resolveModel,
141
- })
142
- : undefined;
143
- if (Array.isArray(customResolved)) {
144
- resolved.push(...customResolved);
145
- continue;
146
- }
147
- if (customResolved) {
148
- resolved.push(customResolved);
149
- continue;
150
- }
151
- throw new Error(`Unsupported declarative middleware kind ${kind}`);
152
- }
153
- return resolved;
154
- }
1
+ import{anthropicPromptCachingMiddleware as w,contextEditingMiddleware as f,dynamicSystemPromptMiddleware as y,humanInTheLoopMiddleware as p,llmToolSelectorMiddleware as M,modelCallLimitMiddleware as g,modelFallbackMiddleware as k,modelRetryMiddleware as b,openAIModerationMiddleware as C,piiMiddleware as h,piiRedactionMiddleware as E,summarizationMiddleware as A,todoListMiddleware as R,toolCallLimitMiddleware as v,toolEmulatorMiddleware as T,toolRetryMiddleware as D}from"langchain";import{createCompletionCallbackMiddleware as L,createFilesystemMiddleware as S,createPatchToolCallsMiddleware as z,createSummarizationMiddleware as F}from"deepagents";function I(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?{...e}:null}function P(e){const i=typeof e.kind=="string"?e.kind.trim():"";if(!i)throw new Error("Declarative middleware entries must include a non-empty kind");return i}function B(e){const{kind:i,...r}=e;return r}async function d(e,i){return e&&typeof e=="object"&&"id"in e?i.resolveModel(e):e}async function m(e,i){if(Array.isArray(e))return Promise.all(e.map(r=>d(r,i)))}async function _({config:e,resolveModel:i}){if(e.provider==="deepagents"){const n={...e};if(n.model=await d(n.model,{resolveModel:i}),n.model===void 0)throw new Error("deepagents summarization middleware requires model or modelRef");if(n.backend===void 0)throw new Error("deepagents summarization middleware requires backend");return delete n.provider,F(n)}const r={...e};if(r.model=await d(r.model,{resolveModel:i}),r.model===void 0)throw new Error("summarization middleware requires model or modelRef");return A(r)}async function q(e){const i={...e.config};return e.binding?.agent.executionMode==="deepagent"&&(i.provider="deepagents",i.backend??=e.resolveBackend?.()??e.resolveFilesystemBackend?.()),_({...e,config:i})}async function j({config:e,resolveModel:i}){const r={...e};return r.model=await d(r.model,{resolveModel:i}),M(r)}async function O({config:e,resolveModel:i}){const r=await m(e.fallbackModels,{resolveModel:i})??await m(e.models,{resolveModel:i});if(!r||r.length===0)throw new Error("modelFallback middleware requires fallbackModels or models");return k(...r)}async function K({config:e}){const i=typeof e.piiType=="string"?e.piiType:void 0;if(!i)throw new Error("pii middleware requires piiType");const{piiType:r,...n}=e;return h(i,n)}async function x({config:e,resolveFilesystemBackend:i}){const r={...e};return r.backend??=i?.(),S(r)}const u={completionCallback:async({config:e})=>L(e),filesystem:x,patchToolCalls:async()=>z(),summarization:q,llmToolSelector:j,modelRetry:async({config:e})=>b(e),modelFallback:O,toolRetry:async({config:e})=>D(e),toolCallLimit:async({config:e})=>v(e),modelCallLimit:async({config:e})=>g(e),todoList:async({config:e})=>R(e),contextEditing:async({config:e})=>f(e),dynamicSystemPrompt:async({config:e})=>y(e),toolEmulator:async({config:e})=>T(e),humanInTheLoop:async({config:e})=>p(e),openAIModeration:async({config:e})=>C(e),pii:K,piiRedaction:async({config:e})=>E(e),anthropicPromptCaching:async({config:e})=>w(e)},W=Object.freeze(Object.keys(u).sort());async function G(e,i){const r=[];for(const n of e??[]){const t=I(n);if(!t)continue;const l=P(t),c=B(t),s=u[l];if(s){const a=await s({config:c,resolveModel:i.resolveModel,resolveBackend:()=>i.resolveBackend?.(i.binding),resolveFilesystemBackend:()=>i.resolveFilesystemBackend?.(i.binding),binding:i.binding});if(Array.isArray(a)){r.push(...a);continue}if(a){r.push(a);continue}}const o=i.resolveCustom?await i.resolveCustom({kind:l,config:c,binding:i.binding,resolveModel:i.resolveModel}):void 0;if(Array.isArray(o)){r.push(...o);continue}if(o){r.push(o);continue}throw new Error(`Unsupported declarative middleware kind ${l}`)}return r}export{u as DECLARATIVE_MIDDLEWARE_REGISTRY,W as SUPPORTED_DECLARATIVE_MIDDLEWARE_KINDS,G as resolveDeclaredMiddleware};
@@ -1,34 +1 @@
1
- import { buildToolNameMapping } from "./tool-name-mapping.js";
2
- export function normalizeInterruptPolicy(rule) {
3
- if (!rule)
4
- return null;
5
- if (rule === true)
6
- return ["approve", "edit", "reject"];
7
- const typed = rule;
8
- if (Array.isArray(typed.allowedDecisions)) {
9
- return typed.allowedDecisions.filter((item) => item === "approve" || item === "edit" || item === "reject");
10
- }
11
- const decisions = [];
12
- if (typed.allowAccept !== false)
13
- decisions.push("approve");
14
- if (typed.allowEdit !== false)
15
- decisions.push("edit");
16
- if (typed.allowReject !== false)
17
- decisions.push("reject");
18
- return decisions.length > 0 ? decisions : null;
19
- }
20
- export function compileInterruptOn(tools, compatibilityRules) {
21
- const toolNameMapping = buildToolNameMapping(tools);
22
- const compiled = new Map();
23
- for (const [toolName, rule] of Object.entries(compatibilityRules ?? {})) {
24
- const modelFacingName = toolNameMapping.originalToModelFacing.get(toolName) ?? toolName;
25
- const allowedDecisions = normalizeInterruptPolicy(rule);
26
- if (!allowedDecisions) {
27
- compiled.delete(modelFacingName);
28
- }
29
- else {
30
- compiled.set(modelFacingName, { allowedDecisions });
31
- }
32
- }
33
- return compiled.size > 0 ? Object.fromEntries(compiled.entries()) : undefined;
34
- }
1
+ import{buildToolNameMapping as c}from"./tool-name-mapping.js";function a(i){if(!i)return null;if(i===!0)return["approve","edit","reject"];const o=i;if(Array.isArray(o.allowedDecisions))return o.allowedDecisions.filter(e=>e==="approve"||e==="edit"||e==="reject");const t=[];return o.allowAccept!==!1&&t.push("approve"),o.allowEdit!==!1&&t.push("edit"),o.allowReject!==!1&&t.push("reject"),t.length>0?t:null}function f(i,o){const t=c(i),e=new Map;for(const[n,s]of Object.entries(o??{})){const r=t.originalToModelFacing.get(n)??n,l=a(s);l?e.set(r,{allowedDecisions:l}):e.delete(r)}return e.size>0?Object.fromEntries(e.entries()):void 0}export{f as compileInterruptOn,a as normalizeInterruptPolicy};
@@ -1,25 +1 @@
1
- import { tools as anthropicProviderTools } from "@langchain/anthropic";
2
- import { tools as openAIProviderTools } from "@langchain/openai";
3
- import { asRecord } from "./resolved-tool.js";
4
- export function instantiateProviderTool(compiledTool) {
5
- const providerTool = asRecord(compiledTool.config?.providerTool);
6
- const provider = typeof providerTool?.provider === "string" ? providerTool.provider.trim().toLowerCase() : "";
7
- const toolName = typeof providerTool?.tool === "string" ? providerTool.tool.trim() : "";
8
- const args = asRecord(providerTool?.args) ?? {};
9
- if (!provider || !toolName) {
10
- throw new Error(`Provider tool ${compiledTool.id} must define providerTool.provider and providerTool.tool`);
11
- }
12
- const registry = provider === "openai"
13
- ? openAIProviderTools
14
- : provider === "anthropic"
15
- ? anthropicProviderTools
16
- : undefined;
17
- if (!registry) {
18
- throw new Error(`Provider tool ${compiledTool.id} uses unsupported provider ${provider}`);
19
- }
20
- const factory = registry[toolName];
21
- if (typeof factory !== "function") {
22
- throw new Error(`Provider tool ${compiledTool.id} references unknown ${provider} tool ${toolName}`);
23
- }
24
- return factory(args);
25
- }
1
+ import{tools as p}from"@langchain/anthropic";import{tools as f}from"@langchain/openai";import{asRecord as s}from"./resolved-tool.js";function l(t){const o=s(t.config?.providerTool),r=typeof o?.provider=="string"?o.provider.trim().toLowerCase():"",e=typeof o?.tool=="string"?o.tool.trim():"",d=s(o?.args)??{};if(!r||!e)throw new Error(`Provider tool ${t.id} must define providerTool.provider and providerTool.tool`);const i=r==="openai"?f:r==="anthropic"?p:void 0;if(!i)throw new Error(`Provider tool ${t.id} uses unsupported provider ${r}`);const n=i[e];if(typeof n!="function")throw new Error(`Provider tool ${t.id} references unknown ${r} tool ${e}`);return n(d)}export{l as instantiateProviderTool};
@@ -1,225 +1 @@
1
- import { z } from "zod";
2
- import { tool as createLangChainTool } from "@langchain/core/tools";
3
- import { toJsonSchema } from "@langchain/core/utils/json_schema";
4
- function isZodSchemaLike(value) {
5
- return typeof value === "object" && value !== null && typeof value.parse === "function";
6
- }
7
- function isZodRawShape(value) {
8
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
9
- return false;
10
- }
11
- const entries = Object.values(value);
12
- return entries.length > 0 && entries.every((entry) => isZodSchemaLike(entry));
13
- }
14
- function isJsonSchemaObject(value) {
15
- return typeof value === "object" && value !== null && !Array.isArray(value);
16
- }
17
- function getZodLikeTypeName(value) {
18
- if (typeof value !== "object" || value === null) {
19
- return undefined;
20
- }
21
- const typed = value;
22
- if (typeof typed.def?.type === "string") {
23
- return typed.def.type;
24
- }
25
- if (typeof typed._zod?.def?.type === "string") {
26
- return typed._zod.def.type;
27
- }
28
- if (typeof typed._def?.typeName === "string") {
29
- return typed._def.typeName.replace(/^Zod/, "").toLowerCase();
30
- }
31
- return undefined;
32
- }
33
- function getZodLikeInnerSchema(value) {
34
- if (typeof value !== "object" || value === null) {
35
- return undefined;
36
- }
37
- const typed = value;
38
- return typed.def?.innerType
39
- ?? typed.def?.element
40
- ?? typed.def?.valueType
41
- ?? typed.def?.schema
42
- ?? typed.def?.out
43
- ?? typed.def?.in
44
- ?? typed._zod?.def?.innerType
45
- ?? typed._zod?.def?.element
46
- ?? typed._zod?.def?.valueType
47
- ?? typed._def?.innerType
48
- ?? typed._def?.schema
49
- ?? typed._def?.type
50
- ?? typed._def?.valueType
51
- ?? typed._def?.in
52
- ?? typed._def?.out;
53
- }
54
- function getZodLikeObjectShape(value) {
55
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
56
- return undefined;
57
- }
58
- const typed = value;
59
- const directShape = typeof typed.shape === "function"
60
- ? typed.shape()
61
- : typeof typed._def?.shape === "function"
62
- ? typed._def.shape()
63
- : typed.shape;
64
- if (typeof directShape === "object" && directShape !== null && !Array.isArray(directShape)) {
65
- return directShape;
66
- }
67
- const v4Shape = typeof typed._zod?.def?.shape === "function" ? typed._zod.def.shape() : typed._zod?.def?.shape;
68
- if (typeof v4Shape === "object" && v4Shape !== null && !Array.isArray(v4Shape)) {
69
- return v4Shape;
70
- }
71
- return undefined;
72
- }
73
- function isZodLikeOptional(value) {
74
- const typeName = getZodLikeTypeName(value);
75
- if (!typeName) {
76
- return false;
77
- }
78
- if (typeName === "optional" || typeName === "default" || typeName === "catch") {
79
- return true;
80
- }
81
- if (typeName === "effects" || typeName === "pipeline" || typeName === "pipe" || typeName === "transform") {
82
- return isZodLikeOptional(getZodLikeInnerSchema(value));
83
- }
84
- return false;
85
- }
86
- function buildBestEffortJsonSchema(value) {
87
- const shape = isZodRawShape(value) ? value : getZodLikeObjectShape(value);
88
- if (shape) {
89
- const properties = Object.fromEntries(Object.entries(shape).map(([key, entry]) => [key, buildBestEffortJsonSchema(getZodLikeInnerSchema(entry) ?? entry) ?? {}]));
90
- const required = Object.entries(shape)
91
- .filter(([, entry]) => !isZodLikeOptional(entry))
92
- .map(([key]) => key);
93
- return {
94
- type: "object",
95
- properties,
96
- required,
97
- };
98
- }
99
- const typeName = getZodLikeTypeName(value);
100
- if (!typeName) {
101
- return undefined;
102
- }
103
- if (typeName === "string") {
104
- return { type: "string" };
105
- }
106
- if (typeName === "number") {
107
- return { type: "number" };
108
- }
109
- if (typeName === "int" || typeName === "integer") {
110
- return { type: "integer" };
111
- }
112
- if (typeName === "boolean") {
113
- return { type: "boolean" };
114
- }
115
- if (typeName === "array") {
116
- return {
117
- type: "array",
118
- items: buildBestEffortJsonSchema(getZodLikeInnerSchema(value)) ?? {},
119
- };
120
- }
121
- if (typeName === "record") {
122
- return {
123
- type: "object",
124
- additionalProperties: buildBestEffortJsonSchema(getZodLikeInnerSchema(value)) ?? {},
125
- };
126
- }
127
- if (typeName === "effects" || typeName === "pipeline" || typeName === "pipe" || typeName === "transform") {
128
- return buildBestEffortJsonSchema(getZodLikeInnerSchema(value)) ?? {};
129
- }
130
- return {};
131
- }
132
- function jsonSchemaPreservesShape(schema, expectedKeys) {
133
- if (expectedKeys.length === 0 || !isJsonSchemaObject(schema)) {
134
- return true;
135
- }
136
- const properties = isJsonSchemaObject(schema.properties) ? Object.keys(schema.properties) : [];
137
- return expectedKeys.every((key) => properties.includes(key));
138
- }
139
- export function asRecord(value) {
140
- return typeof value === "object" && value !== null && !Array.isArray(value)
141
- ? { ...value }
142
- : undefined;
143
- }
144
- export function wrapResolvedToolWithModelFacingName(resolvedTool, modelFacingName) {
145
- if (typeof resolvedTool !== "object" || resolvedTool === null) {
146
- return resolvedTool;
147
- }
148
- return new Proxy(resolvedTool, {
149
- get(target, prop, receiver) {
150
- if (prop === "name") {
151
- return modelFacingName;
152
- }
153
- return Reflect.get(target, prop, receiver);
154
- },
155
- getOwnPropertyDescriptor(target, prop) {
156
- if (prop === "name") {
157
- return {
158
- configurable: true,
159
- enumerable: true,
160
- writable: false,
161
- value: modelFacingName,
162
- };
163
- }
164
- return Reflect.getOwnPropertyDescriptor(target, prop);
165
- },
166
- });
167
- }
168
- export function hasCallableToolHandler(value) {
169
- if (typeof value !== "object" || value === null) {
170
- return false;
171
- }
172
- const typed = value;
173
- return typeof typed.invoke === "function" || typeof typed.call === "function" || typeof typed.func === "function";
174
- }
175
- export function normalizeResolvedToolSchema(resolvedTool) {
176
- const schema = resolvedTool.schema;
177
- if (isZodSchemaLike(schema) && "_def" in schema) {
178
- return resolvedTool.schema;
179
- }
180
- if (isZodRawShape(schema)) {
181
- return z.object(schema);
182
- }
183
- if (schema && (schema.type === "object" || typeof schema.properties === "object")) {
184
- return schema;
185
- }
186
- return z.object({}).passthrough();
187
- }
188
- export function normalizeModelFacingToolSchema(resolvedTool) {
189
- if (isJsonSchemaObject(resolvedTool.modelSchema)) {
190
- return resolvedTool.modelSchema;
191
- }
192
- const normalizedSchema = normalizeResolvedToolSchema(resolvedTool);
193
- const normalizedJsonSchema = isJsonSchemaObject(normalizedSchema) ? normalizedSchema : undefined;
194
- if (normalizedJsonSchema && (normalizedJsonSchema.type === "object" || typeof normalizedJsonSchema.properties === "object")) {
195
- return normalizedJsonSchema;
196
- }
197
- const shape = isZodRawShape(resolvedTool.schema) ? resolvedTool.schema : getZodLikeObjectShape(normalizedSchema);
198
- const shapeKeys = shape ? Object.keys(shape) : [];
199
- if (shapeKeys.length === 0) {
200
- return normalizedSchema;
201
- }
202
- try {
203
- if (jsonSchemaPreservesShape(toJsonSchema(normalizedSchema), shapeKeys)) {
204
- return normalizedSchema;
205
- }
206
- }
207
- catch {
208
- // Fall through to the best-effort JSON schema below.
209
- }
210
- return buildBestEffortJsonSchema(resolvedTool.schema ?? normalizedSchema) ?? normalizedSchema;
211
- }
212
- export function asStructuredExecutableTool(resolvedTool, modelFacingName, description) {
213
- if (!hasCallableToolHandler(resolvedTool)) {
214
- return resolvedTool;
215
- }
216
- const handler = resolvedTool.invoke ?? resolvedTool.call ?? resolvedTool.func;
217
- if (typeof handler !== "function") {
218
- return resolvedTool;
219
- }
220
- return createLangChainTool(async (input, config) => handler.call(resolvedTool, input, config), {
221
- name: modelFacingName,
222
- description,
223
- schema: normalizeModelFacingToolSchema(resolvedTool),
224
- });
225
- }
1
+ import{z as s}from"zod";import{tool as b}from"@langchain/core/tools";import{toJsonSchema as j}from"@langchain/core/utils/json_schema";function y(t){return typeof t=="object"&&t!==null&&typeof t.parse=="function"}function u(t){if(typeof t!="object"||t===null||Array.isArray(t))return!1;const e=Object.values(t);return e.length>0&&e.every(n=>y(n))}function p(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function d(t){if(typeof t!="object"||t===null)return;const e=t;if(typeof e.def?.type=="string")return e.def.type;if(typeof e._zod?.def?.type=="string")return e._zod.def.type;if(typeof e._def?.typeName=="string")return e._def.typeName.replace(/^Zod/,"").toLowerCase()}function o(t){if(typeof t!="object"||t===null)return;const e=t;return e.def?.innerType??e.def?.element??e.def?.valueType??e.def?.schema??e.def?.out??e.def?.in??e._zod?.def?.innerType??e._zod?.def?.element??e._zod?.def?.valueType??e._def?.innerType??e._def?.schema??e._def?.type??e._def?.valueType??e._def?.in??e._def?.out}function m(t){if(typeof t!="object"||t===null||Array.isArray(t))return;const e=t,n=typeof e.shape=="function"?e.shape():typeof e._def?.shape=="function"?e._def.shape():e.shape;if(typeof n=="object"&&n!==null&&!Array.isArray(n))return n;const r=typeof e._zod?.def?.shape=="function"?e._zod.def.shape():e._zod?.def?.shape;if(typeof r=="object"&&r!==null&&!Array.isArray(r))return r}function h(t){const e=d(t);return e?e==="optional"||e==="default"||e==="catch"?!0:e==="effects"||e==="pipeline"||e==="pipe"||e==="transform"?h(o(t)):!1:!1}function c(t){const e=u(t)?t:m(t);if(e){const r=Object.fromEntries(Object.entries(e).map(([i,a])=>[i,c(o(a)??a)??{}])),f=Object.entries(e).filter(([,i])=>!h(i)).map(([i])=>i);return{type:"object",properties:r,required:f}}const n=d(t);if(n)return n==="string"?{type:"string"}:n==="number"?{type:"number"}:n==="int"||n==="integer"?{type:"integer"}:n==="boolean"?{type:"boolean"}:n==="array"?{type:"array",items:c(o(t))??{}}:n==="record"?{type:"object",additionalProperties:c(o(t))??{}}:n==="effects"||n==="pipeline"||n==="pipe"||n==="transform"?c(o(t))??{}:{}}function l(t,e){if(e.length===0||!p(t))return!0;const n=p(t.properties)?Object.keys(t.properties):[];return e.every(r=>n.includes(r))}function k(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)?{...t}:void 0}function w(t,e){return typeof t!="object"||t===null?t:new Proxy(t,{get(n,r,f){return r==="name"?e:Reflect.get(n,r,f)},getOwnPropertyDescriptor(n,r){return r==="name"?{configurable:!0,enumerable:!0,writable:!1,value:e}:Reflect.getOwnPropertyDescriptor(n,r)}})}function g(t){if(typeof t!="object"||t===null)return!1;const e=t;return typeof e.invoke=="function"||typeof e.call=="function"||typeof e.func=="function"}function _(t){const e=t.schema;return y(e)&&"_def"in e?t.schema:u(e)?s.object(e):e&&(e.type==="object"||typeof e.properties=="object")?e:s.object({}).passthrough()}function S(t){if(p(t.modelSchema))return t.modelSchema;const e=_(t),n=p(e)?e:void 0;if(n&&(n.type==="object"||typeof n.properties=="object"))return n;const r=u(t.schema)?t.schema:m(e),f=r?Object.keys(r):[];if(f.length===0)return e;try{if(l(j(e),f))return e}catch{}return c(t.schema??e)??e}function x(t,e,n){if(!g(t))return t;const r=t.invoke??t.call??t.func;return typeof r!="function"?t:b(async(f,i)=>r.call(t,f,i),{name:e,description:n,schema:S(t)})}export{k as asRecord,x as asStructuredExecutableTool,g as hasCallableToolHandler,S as normalizeModelFacingToolSchema,_ as normalizeResolvedToolSchema,w as wrapResolvedToolWithModelFacingName};