@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.
- package/README.md +3 -1234
- package/README.zh.md +3 -1191
- package/dist/acp.js +1 -1
- package/dist/api.js +1 -404
- package/dist/benchmark/checkpoint-resume-cost-benchmark.js +1 -55
- package/dist/benchmark/deepagent-local-model-benchmark.js +2 -35
- package/dist/benchmark/upstream-runtime-ab-benchmark.js +1 -179
- package/dist/cli/chat-interactive.js +25 -244
- package/dist/cli/chat-rendering.js +6 -100
- package/dist/cli/chat-stream.js +23 -512
- package/dist/cli/chat-ui.js +21 -199
- package/dist/cli/chat-workspace.js +2 -210
- package/dist/cli/main.js +21 -428
- package/dist/cli/managed-service-commands.js +9 -63
- package/dist/cli/managed-service.js +2 -137
- package/dist/cli/options-init-chat.js +1 -108
- package/dist/cli/options-runtime.js +1 -158
- package/dist/cli/options-serve.js +1 -282
- package/dist/cli/options.js +2 -19
- package/dist/cli/process-guards.js +1 -139
- package/dist/cli/request-tree.js +7 -296
- package/dist/cli/runtime-commands.js +12 -258
- package/dist/cli/runtime-output.js +16 -155
- package/dist/cli/server-commands.js +16 -270
- package/dist/cli/workspace.js +1 -67
- package/dist/cli.js +1 -7
- package/dist/client/acp.js +1 -1
- package/dist/client/in-process.js +1 -67
- package/dist/client/index.js +1 -2
- package/dist/client/types.js +0 -1
- package/dist/client.js +1 -1
- package/dist/contracts/core.js +1 -1
- package/dist/contracts/runtime-evaluation.js +0 -1
- package/dist/contracts/runtime-memory.js +0 -1
- package/dist/contracts/runtime-observability.js +0 -1
- package/dist/contracts/runtime-requests.js +0 -1
- package/dist/contracts/runtime-scheduling.js +0 -1
- package/dist/contracts/runtime.js +1 -27
- package/dist/contracts/types.js +1 -3
- package/dist/contracts/workspace.js +0 -1
- package/dist/flow/build-flow-graph.js +1 -50
- package/dist/flow/export-mermaid.js +2 -464
- package/dist/flow/export-sequence-mermaid.js +2 -325
- package/dist/flow/flow-graph-normalization.js +1 -214
- package/dist/flow/flow-graph-runtime.js +1 -107
- package/dist/flow/flow-graph-upstream.js +1 -494
- package/dist/flow/index.js +1 -3
- package/dist/flow/types.js +0 -1
- package/dist/index.js +1 -5
- package/dist/init-project.js +1 -1
- package/dist/knowledge/config.js +1 -32
- package/dist/knowledge/contracts.js +0 -1
- package/dist/knowledge/index.js +1 -2
- package/dist/knowledge/module.js +12 -909
- package/dist/knowledge/procedural/config.js +1 -125
- package/dist/knowledge/procedural/index.js +1 -2
- package/dist/knowledge/procedural/manager.js +9 -345
- package/dist/mcp.js +1 -2
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -2
- package/dist/persistence/file-store.js +3 -758
- package/dist/persistence/sqlite-request-context-store.js +5 -54
- package/dist/persistence/sqlite-request-queue-store.js +10 -108
- package/dist/persistence/sqlite-runtime.js +1 -86
- package/dist/persistence/sqlite-store.js +62 -810
- package/dist/persistence/types.js +0 -1
- package/dist/projections/presentation.js +37 -206
- package/dist/projections/request-events.js +2 -502
- package/dist/projections/upstream-events.js +1 -201
- package/dist/protocol/a2a/http-discovery.js +1 -178
- package/dist/protocol/a2a/http-rpc.js +6 -622
- package/dist/protocol/a2a/http.js +1 -138
- package/dist/protocol/a2a/task-state.js +3 -317
- package/dist/protocol/acp/client.js +8 -294
- package/dist/protocol/acp/harness-client.js +1 -218
- package/dist/protocol/acp/http.js +5 -130
- package/dist/protocol/acp/server.js +1 -310
- package/dist/protocol/acp/stdio.js +2 -69
- package/dist/protocol/ag-ui/http.js +3 -378
- package/dist/protocol/mcp/server.js +1 -428
- package/dist/resource/backend/workspace-scoped-backend.js +1 -319
- package/dist/resource/isolation.js +1 -237
- package/dist/resource/mcp/tool-support.js +3 -296
- package/dist/resource/mcp-tool-support.js +1 -2
- package/dist/resource/providers/resource-provider.js +1 -215
- package/dist/resource/resource-impl.js +1 -3
- package/dist/resource/resource-types.js +0 -1
- package/dist/resource/resource.js +1 -1
- package/dist/resource/sources.js +1 -247
- package/dist/resource/tools/function-tool-resolver.js +2 -272
- package/dist/runtime/adapter/compat/deepagent-compat.js +1 -29
- package/dist/runtime/adapter/compat/openai-compatible.js +1 -55
- package/dist/runtime/adapter/direct-builtin-utility.js +2 -90
- package/dist/runtime/adapter/flow/execution-context.js +1 -71
- package/dist/runtime/adapter/flow/invocation-flow.js +8 -425
- package/dist/runtime/adapter/flow/invoke-runtime.js +1 -20
- package/dist/runtime/adapter/flow/stream-runtime.js +11 -1395
- package/dist/runtime/adapter/invocation-result.js +2 -473
- package/dist/runtime/adapter/local-tool-invocation.js +6 -638
- package/dist/runtime/adapter/middleware/context-hygiene.js +1 -83
- package/dist/runtime/adapter/middleware-assembly.js +5 -477
- package/dist/runtime/adapter/model/invocation-request.js +3 -183
- package/dist/runtime/adapter/model/message-assembly.js +1 -28
- package/dist/runtime/adapter/model/model-providers.js +23 -1115
- package/dist/runtime/adapter/model/prompted-json-tool-call-capture.js +1 -40
- package/dist/runtime/adapter/model/prompted-json-tool-policy.js +1 -22
- package/dist/runtime/adapter/resilience.js +1 -104
- package/dist/runtime/adapter/runtime-adapter-support.js +3 -141
- package/dist/runtime/adapter/runtime-shell.js +5 -166
- package/dist/runtime/adapter/stream-event-projection.js +2 -622
- package/dist/runtime/adapter/stream-text-consumption.js +1 -18
- package/dist/runtime/adapter/terminal-status.js +2 -67
- package/dist/runtime/adapter/tool/builtin-middleware-tools.js +6 -627
- package/dist/runtime/adapter/tool/declared-middleware.js +1 -154
- package/dist/runtime/adapter/tool/interrupt-policy.js +1 -34
- package/dist/runtime/adapter/tool/provider-tool.js +1 -25
- package/dist/runtime/adapter/tool/resolved-tool.js +1 -225
- package/dist/runtime/adapter/tool/tool-arguments.js +3 -486
- package/dist/runtime/adapter/tool/tool-hitl.js +1 -346
- package/dist/runtime/adapter/tool/tool-name-mapping.js +1 -128
- package/dist/runtime/adapter/tool/tool-output-artifacts.js +2 -88
- package/dist/runtime/adapter/tool/tool-replay.js +1 -37
- package/dist/runtime/adapter/tool-resolution.js +1 -86
- package/dist/runtime/adapter/upstream-configurable-keys.js +1 -2
- package/dist/runtime/agent-runtime-adapter.js +60 -2338
- package/dist/runtime/agent-runtime-assembly.js +7 -249
- package/dist/runtime/env/runtime-env.js +1 -62
- package/dist/runtime/harness/background-runtime.js +1 -8
- package/dist/runtime/harness/bindings.js +1 -58
- package/dist/runtime/harness/events/event-bus.js +1 -16
- package/dist/runtime/harness/events/event-sink.js +1 -61
- package/dist/runtime/harness/events/events.js +1 -80
- package/dist/runtime/harness/events/listener-runtime.js +1 -13
- package/dist/runtime/harness/events/runtime-event-operations.js +1 -9
- package/dist/runtime/harness/events/streaming.js +1 -100
- package/dist/runtime/harness/events/timeline.js +1 -52
- package/dist/runtime/harness/public-shapes.js +1 -186
- package/dist/runtime/harness/run/artifact-paths.js +1 -15
- package/dist/runtime/harness/run/governance.js +1 -295
- package/dist/runtime/harness/run/helpers.js +1 -71
- package/dist/runtime/harness/run/inspection.js +1 -409
- package/dist/runtime/harness/run/operator-overview.js +1 -80
- package/dist/runtime/harness/run/queue-diagnostics.js +1 -15
- package/dist/runtime/harness/run/recovery.js +1 -162
- package/dist/runtime/harness/run/resources.js +1 -60
- package/dist/runtime/harness/run/resume.js +1 -56
- package/dist/runtime/harness/run/routing.js +1 -48
- package/dist/runtime/harness/run/run-lifecycle.js +1 -66
- package/dist/runtime/harness/run/run-operations.js +1 -217
- package/dist/runtime/harness/run/run-queue.js +1 -43
- package/dist/runtime/harness/run/run-slot-acquisition.js +1 -157
- package/dist/runtime/harness/run/session-records.js +1 -97
- package/dist/runtime/harness/run/start-run.js +1 -120
- package/dist/runtime/harness/run/startup-runtime.js +1 -69
- package/dist/runtime/harness/run/stream-run.js +8 -1418
- package/dist/runtime/harness/run/surface-semantics.js +1 -79
- package/dist/runtime/harness/runtime-defaults.js +1 -39
- package/dist/runtime/harness/system/boundary-analysis.js +1 -234
- package/dist/runtime/harness/system/health-monitor.js +1 -258
- package/dist/runtime/harness/system/inventory.js +1 -129
- package/dist/runtime/harness/system/mem0-ingestion-sync.js +5 -345
- package/dist/runtime/harness/system/policy-engine.js +1 -175
- package/dist/runtime/harness/system/runtime-memory-candidates.js +4 -110
- package/dist/runtime/harness/system/runtime-memory-consolidation.js +1 -51
- package/dist/runtime/harness/system/runtime-memory-manager.js +10 -693
- package/dist/runtime/harness/system/runtime-memory-policy.js +1 -155
- package/dist/runtime/harness/system/runtime-memory-records.js +11 -577
- package/dist/runtime/harness/system/runtime-memory-sync.js +5 -206
- package/dist/runtime/harness/system/session-memory-sync.js +3 -113
- package/dist/runtime/harness/system/skill-requirements.js +1 -112
- package/dist/runtime/harness/system/store.js +9 -365
- package/dist/runtime/harness/tool-gateway/index.js +1 -2
- package/dist/runtime/harness/tool-gateway/policy.js +1 -45
- package/dist/runtime/harness/tool-gateway/validation.js +1 -176
- package/dist/runtime/harness/tool-schema.js +1 -3
- package/dist/runtime/harness.js +3 -1490
- package/dist/runtime/index.js +1 -3
- package/dist/runtime/layout/runtime-layout.js +1 -31
- package/dist/runtime/maintenance/checkpoint-maintenance.js +2 -178
- package/dist/runtime/maintenance/file-checkpoint-saver.js +1 -106
- package/dist/runtime/maintenance/runtime-record-maintenance.js +2 -169
- package/dist/runtime/maintenance/sqlite-checkpoint-saver.js +4 -289
- package/dist/runtime/parsing/output-content.js +10 -550
- package/dist/runtime/parsing/output-parsing.js +1 -4
- package/dist/runtime/parsing/output-recovery.js +3 -213
- package/dist/runtime/parsing/output-tool-args.js +7 -663
- package/dist/runtime/parsing/stream-event-parsing.js +3 -362
- package/dist/runtime/prompts/runtime-prompts.js +4 -73
- package/dist/runtime/scheduling/system-schedule-manager.js +11 -532
- package/dist/runtime/skills/skill-metadata.js +1 -197
- package/dist/runtime/startup-tracing.js +2 -37
- package/dist/runtime/support/compiled-binding.js +1 -290
- package/dist/runtime/support/embedding-models.js +1 -118
- package/dist/runtime/support/harness-support.js +5 -137
- package/dist/runtime/support/llamaindex.js +1 -108
- package/dist/runtime/support/runtime-adapter-options.js +1 -29
- package/dist/runtime/support/runtime-factories.js +1 -51
- package/dist/runtime/support/vector-stores.js +9 -270
- package/dist/scaffold/init-project.js +54 -233
- package/dist/tooling/extensions.js +1 -311
- package/dist/tooling/module-loader.js +1 -55
- package/dist/tools.js +1 -176
- package/dist/utils/agent-display.js +1 -18
- package/dist/utils/bundled-text.js +4 -39
- package/dist/utils/compiled-binding.js +1 -33
- package/dist/utils/fs.js +2 -45
- package/dist/utils/id.js +1 -9
- package/dist/utils/message-content.js +1 -30
- package/dist/utils/object.js +1 -6
- package/dist/workspace/agent-binding-compiler.js +3 -613
- package/dist/workspace/compile.js +1 -472
- package/dist/workspace/framework-contract-validation.js +2 -322
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/object-loader-paths.js +1 -71
- package/dist/workspace/object-loader-readers.js +1 -187
- package/dist/workspace/object-loader.js +1 -754
- package/dist/workspace/resource-compilers.js +1 -374
- package/dist/workspace/support/agent-capabilities.js +1 -37
- package/dist/workspace/support/agent-execution-config.js +1 -44
- package/dist/workspace/support/discovery.js +1 -147
- package/dist/workspace/support/source-collectors.js +1 -30
- package/dist/workspace/support/source-protocols.js +2 -192
- package/dist/workspace/support/workspace-ref-utils.js +1 -362
- package/dist/workspace/tool-hydration.js +1 -280
- package/dist/workspace/validate.js +1 -99
- package/dist/workspace/yaml-object-reader.js +1 -285
- package/package.json +7 -3
|
@@ -1,311 +1 @@
|
|
|
1
|
-
import path from "
|
|
2
|
-
import { defaultResourceSkillsRoot } from "../resource/resource.js";
|
|
3
|
-
import { isExternalSourceLocator, resolveExternalResourcePath } from "../resource/sources.js";
|
|
4
|
-
import { hasAgentSystemPrompt } from "../workspace/support/agent-capabilities.js";
|
|
5
|
-
const toolKindAdapters = new Map();
|
|
6
|
-
const skillSourceResolvers = new Map();
|
|
7
|
-
const skillInheritancePolicies = new Map();
|
|
8
|
-
const skillPackagingConventions = new Map();
|
|
9
|
-
const policyEvaluators = new Map();
|
|
10
|
-
const eventSubscribers = new Map();
|
|
11
|
-
function resolveToolRefId(ref) {
|
|
12
|
-
if (isExternalSourceLocator(ref)) {
|
|
13
|
-
return ref;
|
|
14
|
-
}
|
|
15
|
-
if (ref.startsWith("builtin/")) {
|
|
16
|
-
return ref;
|
|
17
|
-
}
|
|
18
|
-
return ref.includes("/") ? ref.split("/").slice(1).join("/") : ref;
|
|
19
|
-
}
|
|
20
|
-
export function resolveToolTargets(tools, ref) {
|
|
21
|
-
const resolved = resolveToolRefId(ref);
|
|
22
|
-
if (resolved === "builtin/*") {
|
|
23
|
-
return Array.from(tools.entries())
|
|
24
|
-
.filter(([id]) => id.startsWith("builtin/"))
|
|
25
|
-
.map(([, tool]) => tool);
|
|
26
|
-
}
|
|
27
|
-
const exact = tools.get(resolved);
|
|
28
|
-
if (exact) {
|
|
29
|
-
return [exact];
|
|
30
|
-
}
|
|
31
|
-
const byName = Array.from(tools.values()).filter((tool) => tool.name === resolved);
|
|
32
|
-
if (byName.length > 0) {
|
|
33
|
-
return byName;
|
|
34
|
-
}
|
|
35
|
-
if (!resolved.startsWith("builtin/")) {
|
|
36
|
-
return [];
|
|
37
|
-
}
|
|
38
|
-
const prefix = `${resolved}/`;
|
|
39
|
-
return Array.from(tools.entries())
|
|
40
|
-
.filter(([id]) => id.startsWith(prefix))
|
|
41
|
-
.map(([, tool]) => tool);
|
|
42
|
-
}
|
|
43
|
-
export function registerToolKind(adapter) {
|
|
44
|
-
toolKindAdapters.set(adapter.type, adapter);
|
|
45
|
-
}
|
|
46
|
-
export function getToolKindAdapter(type) {
|
|
47
|
-
return toolKindAdapters.get(type);
|
|
48
|
-
}
|
|
49
|
-
export function registerSkillSourceResolver(resolver) {
|
|
50
|
-
skillSourceResolvers.set(resolver.kind, resolver);
|
|
51
|
-
}
|
|
52
|
-
export function getSkillSourceResolver(kind) {
|
|
53
|
-
return skillSourceResolvers.get(kind);
|
|
54
|
-
}
|
|
55
|
-
export function registerSkillInheritancePolicy(policy) {
|
|
56
|
-
skillInheritancePolicies.set(policy.kind, policy);
|
|
57
|
-
}
|
|
58
|
-
export function getSkillInheritancePolicy(kind) {
|
|
59
|
-
return skillInheritancePolicies.get(kind);
|
|
60
|
-
}
|
|
61
|
-
export function registerSkillPackagingConvention(convention) {
|
|
62
|
-
skillPackagingConventions.set(convention.kind, convention);
|
|
63
|
-
}
|
|
64
|
-
export function getSkillPackagingConvention(kind) {
|
|
65
|
-
return skillPackagingConventions.get(kind);
|
|
66
|
-
}
|
|
67
|
-
export function registerPolicyEvaluator(evaluator) {
|
|
68
|
-
policyEvaluators.set(evaluator.kind, evaluator);
|
|
69
|
-
}
|
|
70
|
-
export function getPolicyEvaluators() {
|
|
71
|
-
return Array.from(policyEvaluators.values());
|
|
72
|
-
}
|
|
73
|
-
export function registerEventSubscriber(subscriber) {
|
|
74
|
-
eventSubscribers.set(subscriber.kind, subscriber);
|
|
75
|
-
}
|
|
76
|
-
export function getEventSubscribers() {
|
|
77
|
-
return Array.from(eventSubscribers.values());
|
|
78
|
-
}
|
|
79
|
-
function compileBundleTool(tool, tools) {
|
|
80
|
-
const compiled = tool.bundleRefs.flatMap((ref) => {
|
|
81
|
-
const nested = resolveToolTargets(tools, ref);
|
|
82
|
-
if (nested.length === 0) {
|
|
83
|
-
throw new Error(`Tool bundle target ${ref} not found`);
|
|
84
|
-
}
|
|
85
|
-
return nested.flatMap((item) => compileToolWithRegistry(item, tools));
|
|
86
|
-
});
|
|
87
|
-
const deduped = new Map();
|
|
88
|
-
for (const item of compiled) {
|
|
89
|
-
deduped.set(item.name, item);
|
|
90
|
-
}
|
|
91
|
-
return Array.from(deduped.values());
|
|
92
|
-
}
|
|
93
|
-
export function compileToolWithRegistry(tool, tools) {
|
|
94
|
-
const adapter = getToolKindAdapter(tool.type);
|
|
95
|
-
if (!adapter) {
|
|
96
|
-
throw new Error(`No tool kind adapter registered for ${tool.type}`);
|
|
97
|
-
}
|
|
98
|
-
return adapter.compile(tool, tools);
|
|
99
|
-
}
|
|
100
|
-
export function validateToolWithRegistry(tool, tools) {
|
|
101
|
-
const adapter = getToolKindAdapter(tool.type);
|
|
102
|
-
if (!adapter) {
|
|
103
|
-
throw new Error(`No tool kind adapter registered for ${tool.type}`);
|
|
104
|
-
}
|
|
105
|
-
adapter.validate(tool, tools);
|
|
106
|
-
}
|
|
107
|
-
registerToolKind({
|
|
108
|
-
type: "function",
|
|
109
|
-
validate(tool) {
|
|
110
|
-
if (!tool.name) {
|
|
111
|
-
throw new Error(`Tool ${tool.id} name must not be empty`);
|
|
112
|
-
}
|
|
113
|
-
if (!tool.description) {
|
|
114
|
-
throw new Error(`Tool ${tool.id} description must not be empty`);
|
|
115
|
-
}
|
|
116
|
-
},
|
|
117
|
-
compile(tool) {
|
|
118
|
-
return [
|
|
119
|
-
{
|
|
120
|
-
id: tool.id,
|
|
121
|
-
type: "function",
|
|
122
|
-
name: tool.name,
|
|
123
|
-
description: tool.description,
|
|
124
|
-
config: tool.config,
|
|
125
|
-
subprocess: tool.subprocess,
|
|
126
|
-
inputSchemaRef: tool.inputSchemaRef,
|
|
127
|
-
hasModuleSchema: tool.hasModuleSchema,
|
|
128
|
-
modelSchema: tool.modelSchema,
|
|
129
|
-
embeddingModelRef: tool.embeddingModelRef,
|
|
130
|
-
bundleRefs: [],
|
|
131
|
-
hitl: tool.hitl
|
|
132
|
-
? {
|
|
133
|
-
enabled: tool.hitl.enabled,
|
|
134
|
-
allow: tool.hitl.allow ?? ["approve", "edit", "reject"],
|
|
135
|
-
}
|
|
136
|
-
: undefined,
|
|
137
|
-
retryable: tool.retryable,
|
|
138
|
-
runtimeValue: { name: tool.name, description: tool.description, type: "function" },
|
|
139
|
-
},
|
|
140
|
-
];
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
registerToolKind({
|
|
144
|
-
type: "backend",
|
|
145
|
-
validate(tool) {
|
|
146
|
-
if (!tool.name || !tool.description) {
|
|
147
|
-
throw new Error(`Tool ${tool.id} backend tool requires name and description`);
|
|
148
|
-
}
|
|
149
|
-
if (!tool.backendOperation) {
|
|
150
|
-
throw new Error(`Tool ${tool.id} backend tool must define operation`);
|
|
151
|
-
}
|
|
152
|
-
},
|
|
153
|
-
compile(tool) {
|
|
154
|
-
return [
|
|
155
|
-
{
|
|
156
|
-
id: tool.id,
|
|
157
|
-
type: "backend",
|
|
158
|
-
name: tool.name,
|
|
159
|
-
description: tool.description,
|
|
160
|
-
config: tool.config,
|
|
161
|
-
subprocess: tool.subprocess,
|
|
162
|
-
inputSchemaRef: tool.inputSchemaRef,
|
|
163
|
-
hasModuleSchema: tool.hasModuleSchema,
|
|
164
|
-
modelSchema: tool.modelSchema,
|
|
165
|
-
embeddingModelRef: tool.embeddingModelRef,
|
|
166
|
-
backendOperation: tool.backendOperation,
|
|
167
|
-
bundleRefs: [],
|
|
168
|
-
hitl: tool.hitl
|
|
169
|
-
? {
|
|
170
|
-
enabled: tool.hitl.enabled,
|
|
171
|
-
allow: tool.hitl.allow ?? ["approve", "edit", "reject"],
|
|
172
|
-
}
|
|
173
|
-
: undefined,
|
|
174
|
-
retryable: tool.retryable,
|
|
175
|
-
runtimeValue: { name: tool.name, description: tool.description, type: "backend" },
|
|
176
|
-
},
|
|
177
|
-
];
|
|
178
|
-
},
|
|
179
|
-
});
|
|
180
|
-
registerToolKind({
|
|
181
|
-
type: "mcp",
|
|
182
|
-
validate(tool) {
|
|
183
|
-
if (!tool.name || !tool.description) {
|
|
184
|
-
throw new Error(`Tool ${tool.id} mcp tool requires name and description`);
|
|
185
|
-
}
|
|
186
|
-
if (!tool.mcpRef) {
|
|
187
|
-
throw new Error(`Tool ${tool.id} mcp tool must define mcp.ref`);
|
|
188
|
-
}
|
|
189
|
-
},
|
|
190
|
-
compile(tool) {
|
|
191
|
-
return [
|
|
192
|
-
{
|
|
193
|
-
id: tool.id,
|
|
194
|
-
type: "mcp",
|
|
195
|
-
name: tool.name,
|
|
196
|
-
description: tool.description,
|
|
197
|
-
config: tool.config,
|
|
198
|
-
subprocess: tool.subprocess,
|
|
199
|
-
inputSchemaRef: tool.inputSchemaRef,
|
|
200
|
-
hasModuleSchema: tool.hasModuleSchema,
|
|
201
|
-
modelSchema: tool.modelSchema,
|
|
202
|
-
embeddingModelRef: tool.embeddingModelRef,
|
|
203
|
-
mcpRef: tool.mcpRef,
|
|
204
|
-
bundleRefs: [],
|
|
205
|
-
hitl: tool.hitl
|
|
206
|
-
? {
|
|
207
|
-
enabled: tool.hitl.enabled,
|
|
208
|
-
allow: tool.hitl.allow ?? ["approve", "edit", "reject"],
|
|
209
|
-
}
|
|
210
|
-
: undefined,
|
|
211
|
-
retryable: tool.retryable,
|
|
212
|
-
runtimeValue: { name: tool.name, description: tool.description, type: "mcp" },
|
|
213
|
-
},
|
|
214
|
-
];
|
|
215
|
-
},
|
|
216
|
-
});
|
|
217
|
-
registerToolKind({
|
|
218
|
-
type: "provider",
|
|
219
|
-
validate(tool) {
|
|
220
|
-
if (!tool.name || !tool.description) {
|
|
221
|
-
throw new Error(`Tool ${tool.id} provider tool requires name and description`);
|
|
222
|
-
}
|
|
223
|
-
const providerTool = typeof tool.config?.providerTool === "object" && tool.config.providerTool
|
|
224
|
-
? tool.config.providerTool
|
|
225
|
-
: undefined;
|
|
226
|
-
if (typeof providerTool?.provider !== "string" || !providerTool.provider.trim()) {
|
|
227
|
-
throw new Error(`Tool ${tool.id} provider tool must define providerTool.provider`);
|
|
228
|
-
}
|
|
229
|
-
if (typeof providerTool?.tool !== "string" || !providerTool.tool.trim()) {
|
|
230
|
-
throw new Error(`Tool ${tool.id} provider tool must define providerTool.tool`);
|
|
231
|
-
}
|
|
232
|
-
},
|
|
233
|
-
compile(tool) {
|
|
234
|
-
return [
|
|
235
|
-
{
|
|
236
|
-
id: tool.id,
|
|
237
|
-
type: "provider",
|
|
238
|
-
name: tool.name,
|
|
239
|
-
description: tool.description,
|
|
240
|
-
config: tool.config,
|
|
241
|
-
subprocess: tool.subprocess,
|
|
242
|
-
inputSchemaRef: tool.inputSchemaRef,
|
|
243
|
-
hasModuleSchema: tool.hasModuleSchema,
|
|
244
|
-
modelSchema: tool.modelSchema,
|
|
245
|
-
embeddingModelRef: tool.embeddingModelRef,
|
|
246
|
-
bundleRefs: [],
|
|
247
|
-
hitl: tool.hitl
|
|
248
|
-
? {
|
|
249
|
-
enabled: tool.hitl.enabled,
|
|
250
|
-
allow: tool.hitl.allow ?? ["approve", "edit", "reject"],
|
|
251
|
-
}
|
|
252
|
-
: undefined,
|
|
253
|
-
retryable: tool.retryable,
|
|
254
|
-
runtimeValue: { name: tool.name, description: tool.description, type: "provider" },
|
|
255
|
-
},
|
|
256
|
-
];
|
|
257
|
-
},
|
|
258
|
-
});
|
|
259
|
-
registerToolKind({
|
|
260
|
-
type: "bundle",
|
|
261
|
-
validate(tool, tools) {
|
|
262
|
-
if (tool.bundleRefs.length === 0) {
|
|
263
|
-
throw new Error(`Tool ${tool.id} bundle must contain nested refs`);
|
|
264
|
-
}
|
|
265
|
-
for (const ref of tool.bundleRefs) {
|
|
266
|
-
const target = resolveToolTargets(tools, ref);
|
|
267
|
-
if (target.length === 0) {
|
|
268
|
-
throw new Error(`Tool ${tool.id} bundle ref ${ref} does not exist`);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
},
|
|
272
|
-
compile: compileBundleTool,
|
|
273
|
-
});
|
|
274
|
-
registerSkillSourceResolver({
|
|
275
|
-
kind: "path",
|
|
276
|
-
resolve({ workspaceRoot, skill, packagingRoots }) {
|
|
277
|
-
if (packagingRoots.length > 0) {
|
|
278
|
-
return packagingRoots;
|
|
279
|
-
}
|
|
280
|
-
const candidate = String(skill.sourcePathRef);
|
|
281
|
-
if (isExternalSourceLocator(candidate)) {
|
|
282
|
-
return [resolveExternalResourcePath(candidate, workspaceRoot)];
|
|
283
|
-
}
|
|
284
|
-
return [candidate.startsWith("/") ? candidate : `${workspaceRoot}/${candidate}`];
|
|
285
|
-
},
|
|
286
|
-
});
|
|
287
|
-
registerSkillSourceResolver({
|
|
288
|
-
kind: "builtin",
|
|
289
|
-
resolve({ skill }) {
|
|
290
|
-
return [path.join(defaultResourceSkillsRoot(), skill.sourcePathRef)];
|
|
291
|
-
},
|
|
292
|
-
});
|
|
293
|
-
registerSkillInheritancePolicy({
|
|
294
|
-
kind: "default",
|
|
295
|
-
apply({ agent, ownSkills, parentSkills }) {
|
|
296
|
-
if (hasAgentSystemPrompt(agent) && agent.id.includes(".")) {
|
|
297
|
-
return ownSkills;
|
|
298
|
-
}
|
|
299
|
-
return Array.from(new Set([...parentSkills, ...ownSkills]));
|
|
300
|
-
},
|
|
301
|
-
});
|
|
302
|
-
registerSkillPackagingConvention({
|
|
303
|
-
kind: "path",
|
|
304
|
-
resolve({ workspaceRoot, skill }) {
|
|
305
|
-
const candidate = String(skill.sourcePathRef);
|
|
306
|
-
if (isExternalSourceLocator(candidate)) {
|
|
307
|
-
return [resolveExternalResourcePath(candidate, workspaceRoot)];
|
|
308
|
-
}
|
|
309
|
-
return [candidate.startsWith("/") ? candidate : `${workspaceRoot}/${candidate}`];
|
|
310
|
-
},
|
|
311
|
-
});
|
|
1
|
+
import v from"node:path";import{defaultResourceSkillsRoot as w}from"../resource/resource.js";import{isExternalSourceLocator as s,resolveExternalResourcePath as o}from"../resource/sources.js";import{hasAgentSystemPrompt as S}from"../workspace/support/agent-capabilities.js";const p=new Map,u=new Map,f=new Map,m=new Map,l=new Map,h=new Map;function R(e){return s(e)||e.startsWith("builtin/")?e:e.includes("/")?e.split("/").slice(1).join("/"):e}function b(e,n){const r=R(n);if(r==="builtin/*")return Array.from(e.entries()).filter(([t])=>t.startsWith("builtin/")).map(([,t])=>t);const i=e.get(r);if(i)return[i];const d=Array.from(e.values()).filter(t=>t.name===r);if(d.length>0)return d;if(!r.startsWith("builtin/"))return[];const c=`${r}/`;return Array.from(e.entries()).filter(([t])=>t.startsWith(c)).map(([,t])=>t)}function a(e){p.set(e.type,e)}function g(e){return p.get(e)}function y(e){u.set(e.kind,e)}function W(e){return u.get(e)}function k(e){f.set(e.kind,e)}function j(e){return f.get(e)}function T(e){m.set(e.kind,e)}function I(e){return m.get(e)}function V(e){l.set(e.kind,e)}function q(){return Array.from(l.values())}function C(e){h.set(e.kind,e)}function K(){return Array.from(h.values())}function M(e,n){const r=e.bundleRefs.flatMap(d=>{const c=b(n,d);if(c.length===0)throw new Error(`Tool bundle target ${d} not found`);return c.flatMap(t=>E(t,n))}),i=new Map;for(const d of r)i.set(d.name,d);return Array.from(i.values())}function E(e,n){const r=g(e.type);if(!r)throw new Error(`No tool kind adapter registered for ${e.type}`);return r.compile(e,n)}function N(e,n){const r=g(e.type);if(!r)throw new Error(`No tool kind adapter registered for ${e.type}`);r.validate(e,n)}a({type:"function",validate(e){if(!e.name)throw new Error(`Tool ${e.id} name must not be empty`);if(!e.description)throw new Error(`Tool ${e.id} description must not be empty`)},compile(e){return[{id:e.id,type:"function",name:e.name,description:e.description,config:e.config,subprocess:e.subprocess,inputSchemaRef:e.inputSchemaRef,hasModuleSchema:e.hasModuleSchema,modelSchema:e.modelSchema,embeddingModelRef:e.embeddingModelRef,bundleRefs:[],hitl:e.hitl?{enabled:e.hitl.enabled,allow:e.hitl.allow??["approve","edit","reject"]}:void 0,retryable:e.retryable,runtimeValue:{name:e.name,description:e.description,type:"function"}}]}}),a({type:"backend",validate(e){if(!e.name||!e.description)throw new Error(`Tool ${e.id} backend tool requires name and description`);if(!e.backendOperation)throw new Error(`Tool ${e.id} backend tool must define operation`)},compile(e){return[{id:e.id,type:"backend",name:e.name,description:e.description,config:e.config,subprocess:e.subprocess,inputSchemaRef:e.inputSchemaRef,hasModuleSchema:e.hasModuleSchema,modelSchema:e.modelSchema,embeddingModelRef:e.embeddingModelRef,backendOperation:e.backendOperation,bundleRefs:[],hitl:e.hitl?{enabled:e.hitl.enabled,allow:e.hitl.allow??["approve","edit","reject"]}:void 0,retryable:e.retryable,runtimeValue:{name:e.name,description:e.description,type:"backend"}}]}}),a({type:"mcp",validate(e){if(!e.name||!e.description)throw new Error(`Tool ${e.id} mcp tool requires name and description`);if(!e.mcpRef)throw new Error(`Tool ${e.id} mcp tool must define mcp.ref`)},compile(e){return[{id:e.id,type:"mcp",name:e.name,description:e.description,config:e.config,subprocess:e.subprocess,inputSchemaRef:e.inputSchemaRef,hasModuleSchema:e.hasModuleSchema,modelSchema:e.modelSchema,embeddingModelRef:e.embeddingModelRef,mcpRef:e.mcpRef,bundleRefs:[],hitl:e.hitl?{enabled:e.hitl.enabled,allow:e.hitl.allow??["approve","edit","reject"]}:void 0,retryable:e.retryable,runtimeValue:{name:e.name,description:e.description,type:"mcp"}}]}}),a({type:"provider",validate(e){if(!e.name||!e.description)throw new Error(`Tool ${e.id} provider tool requires name and description`);const n=typeof e.config?.providerTool=="object"&&e.config.providerTool?e.config.providerTool:void 0;if(typeof n?.provider!="string"||!n.provider.trim())throw new Error(`Tool ${e.id} provider tool must define providerTool.provider`);if(typeof n?.tool!="string"||!n.tool.trim())throw new Error(`Tool ${e.id} provider tool must define providerTool.tool`)},compile(e){return[{id:e.id,type:"provider",name:e.name,description:e.description,config:e.config,subprocess:e.subprocess,inputSchemaRef:e.inputSchemaRef,hasModuleSchema:e.hasModuleSchema,modelSchema:e.modelSchema,embeddingModelRef:e.embeddingModelRef,bundleRefs:[],hitl:e.hitl?{enabled:e.hitl.enabled,allow:e.hitl.allow??["approve","edit","reject"]}:void 0,retryable:e.retryable,runtimeValue:{name:e.name,description:e.description,type:"provider"}}]}}),a({type:"bundle",validate(e,n){if(e.bundleRefs.length===0)throw new Error(`Tool ${e.id} bundle must contain nested refs`);for(const r of e.bundleRefs)if(b(n,r).length===0)throw new Error(`Tool ${e.id} bundle ref ${r} does not exist`)},compile:M}),y({kind:"path",resolve({workspaceRoot:e,skill:n,packagingRoots:r}){if(r.length>0)return r;const i=String(n.sourcePathRef);return s(i)?[o(i,e)]:[i.startsWith("/")?i:`${e}/${i}`]}}),y({kind:"builtin",resolve({skill:e}){return[v.join(w(),e.sourcePathRef)]}}),k({kind:"default",apply({agent:e,ownSkills:n,parentSkills:r}){return S(e)&&e.id.includes(".")?n:Array.from(new Set([...r,...n]))}}),T({kind:"path",resolve({workspaceRoot:e,skill:n}){const r=String(n.sourcePathRef);return s(r)?[o(r,e)]:[r.startsWith("/")?r:`${e}/${r}`]}});export{E as compileToolWithRegistry,K as getEventSubscribers,q as getPolicyEvaluators,j as getSkillInheritancePolicy,I as getSkillPackagingConvention,W as getSkillSourceResolver,g as getToolKindAdapter,C as registerEventSubscriber,V as registerPolicyEvaluator,k as registerSkillInheritancePolicy,T as registerSkillPackagingConvention,y as registerSkillSourceResolver,a as registerToolKind,b as resolveToolTargets,N as validateToolWithRegistry};
|
|
@@ -1,55 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { readSkillMetadata } from "../runtime/skills/skill-metadata.js";
|
|
3
|
-
import { TOOL_DEFINITION_MARKER, buildToolJsonSchema, normalizeToolSchema } from "../tools.js";
|
|
4
|
-
const TOOL_MODULE_EXTENSIONS = new Set([".mjs", ".js", ".cjs"]);
|
|
5
|
-
function isToolDefinitionObject(value) {
|
|
6
|
-
return typeof value === "object" && value !== null && value[TOOL_DEFINITION_MARKER] === true;
|
|
7
|
-
}
|
|
8
|
-
function discoverExportedToolObjectNames(imported) {
|
|
9
|
-
return Object.entries(imported)
|
|
10
|
-
.filter(([name, value]) => name !== "default" && isToolDefinitionObject(value))
|
|
11
|
-
.map(([name]) => name)
|
|
12
|
-
.sort();
|
|
13
|
-
}
|
|
14
|
-
function loadToolObjectDefinition(imported, exportName) {
|
|
15
|
-
const definition = imported[exportName];
|
|
16
|
-
if (!isToolDefinitionObject(definition)) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
return {
|
|
20
|
-
implementationName: definition.name?.trim() || exportName,
|
|
21
|
-
invoke: definition.invoke,
|
|
22
|
-
schema: normalizeToolSchema(definition.schema),
|
|
23
|
-
modelSchema: buildToolJsonSchema(definition.schema),
|
|
24
|
-
hasModuleSchema: true,
|
|
25
|
-
description: definition.description.trim(),
|
|
26
|
-
retryable: definition.retryable === true,
|
|
27
|
-
...(definition.memory ? { memory: { ...definition.memory } } : {}),
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
export function isSupportedToolModulePath(filePath) {
|
|
31
|
-
return TOOL_MODULE_EXTENSIONS.has(path.extname(filePath));
|
|
32
|
-
}
|
|
33
|
-
export function discoverToolModuleDefinitions(_sourceText, imported) {
|
|
34
|
-
return discoverExportedToolObjectNames(imported)
|
|
35
|
-
.map((exportName) => loadToolObjectDefinition(imported, exportName))
|
|
36
|
-
.filter((definition) => Boolean(definition));
|
|
37
|
-
}
|
|
38
|
-
export function loadToolModuleDefinition(imported, implementationName) {
|
|
39
|
-
for (const exportName of discoverExportedToolObjectNames(imported)) {
|
|
40
|
-
const loaded = loadToolObjectDefinition(imported, exportName);
|
|
41
|
-
if (loaded && loaded.implementationName === implementationName) {
|
|
42
|
-
return loaded;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
throw new Error(`Tool module must export a tool({...}) definition named ${implementationName}.`);
|
|
46
|
-
}
|
|
47
|
-
export function discoverSkillDefinitions(skillRoots) {
|
|
48
|
-
return skillRoots.map((skillRoot) => {
|
|
49
|
-
const metadata = readSkillMetadata(skillRoot);
|
|
50
|
-
return {
|
|
51
|
-
name: metadata.name || path.basename(skillRoot),
|
|
52
|
-
description: metadata.description,
|
|
53
|
-
};
|
|
54
|
-
});
|
|
55
|
-
}
|
|
1
|
+
import r from"node:path";import{readSkillMetadata as c}from"../runtime/skills/skill-metadata.js";import{TOOL_DEFINITION_MARKER as l,buildToolJsonSchema as s,normalizeToolSchema as u}from"../tools.js";const d=new Set([".mjs",".js",".cjs"]);function i(o){return typeof o=="object"&&o!==null&&o[l]===!0}function a(o){return Object.entries(o).filter(([t,e])=>t!=="default"&&i(e)).map(([t])=>t).sort()}function m(o,t){const e=o[t];return i(e)?{implementationName:e.name?.trim()||t,invoke:e.invoke,schema:u(e.schema),modelSchema:s(e.schema),hasModuleSchema:!0,description:e.description.trim(),retryable:e.retryable===!0,...e.memory?{memory:{...e.memory}}:{}}:null}function h(o){return d.has(r.extname(o))}function O(o,t){return a(t).map(e=>m(t,e)).filter(e=>!!e)}function S(o,t){for(const e of a(o)){const n=m(o,e);if(n&&n.implementationName===t)return n}throw new Error(`Tool module must export a tool({...}) definition named ${t}.`)}function b(o){return o.map(t=>{const e=c(t);return{name:e.name||r.basename(t),description:e.description}})}export{b as discoverSkillDefinitions,O as discoverToolModuleDefinitions,h as isSupportedToolModulePath,S as loadToolModuleDefinition};
|
package/dist/tools.js
CHANGED
|
@@ -1,176 +1 @@
|
|
|
1
|
-
|
|
2
|
-
function isZodSchema(value) {
|
|
3
|
-
return typeof value === "object" && value !== null && typeof value.parse === "function";
|
|
4
|
-
}
|
|
5
|
-
function isParseableSchema(value) {
|
|
6
|
-
return typeof value === "object" && value !== null && typeof value.parse === "function";
|
|
7
|
-
}
|
|
8
|
-
function getZodLikeTypeName(value) {
|
|
9
|
-
if (typeof value !== "object" || value === null) {
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
|
-
const typed = value;
|
|
13
|
-
if (typeof typed.def?.type === "string") {
|
|
14
|
-
return typed.def.type;
|
|
15
|
-
}
|
|
16
|
-
if (typeof typed._zod?.def?.type === "string") {
|
|
17
|
-
return typed._zod.def.type;
|
|
18
|
-
}
|
|
19
|
-
if (typeof typed._def?.typeName === "string") {
|
|
20
|
-
return typed._def.typeName.replace(/^Zod/, "").toLowerCase();
|
|
21
|
-
}
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
function getZodLikeObjectShape(value) {
|
|
25
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
const typed = value;
|
|
29
|
-
const directShape = typeof typed.shape === "function"
|
|
30
|
-
? typed.shape()
|
|
31
|
-
: typeof typed._def?.shape === "function"
|
|
32
|
-
? typed._def.shape()
|
|
33
|
-
: typed.shape;
|
|
34
|
-
if (typeof directShape === "object" && directShape !== null && !Array.isArray(directShape)) {
|
|
35
|
-
return directShape;
|
|
36
|
-
}
|
|
37
|
-
const zod4Shape = typeof typed._zod?.def?.shape === "function" ? typed._zod.def.shape() : typed._zod?.def?.shape;
|
|
38
|
-
if (typeof zod4Shape === "object" && zod4Shape !== null && !Array.isArray(zod4Shape)) {
|
|
39
|
-
return zod4Shape;
|
|
40
|
-
}
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
function getZodLikeInnerSchema(value) {
|
|
44
|
-
if (typeof value !== "object" || value === null) {
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
const typed = value;
|
|
48
|
-
return typed.def?.innerType
|
|
49
|
-
?? typed.def?.element
|
|
50
|
-
?? typed.def?.valueType
|
|
51
|
-
?? typed.def?.schema
|
|
52
|
-
?? typed.def?.out
|
|
53
|
-
?? typed.def?.in
|
|
54
|
-
?? typed._zod?.def?.innerType
|
|
55
|
-
?? typed._zod?.def?.element
|
|
56
|
-
?? typed._zod?.def?.valueType
|
|
57
|
-
?? typed._def?.innerType
|
|
58
|
-
?? typed._def?.schema
|
|
59
|
-
?? typed._def?.type
|
|
60
|
-
?? typed._def?.valueType
|
|
61
|
-
?? typed._def?.in
|
|
62
|
-
?? typed._def?.out;
|
|
63
|
-
}
|
|
64
|
-
function isEffectWrappedOptional(value) {
|
|
65
|
-
const typeName = getZodLikeTypeName(value);
|
|
66
|
-
if (typeName !== "effects" && typeName !== "pipeline" && typeName !== "pipe" && typeName !== "transform") {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
const inner = getZodLikeInnerSchema(value);
|
|
70
|
-
const innerTypeName = getZodLikeTypeName(inner);
|
|
71
|
-
return innerTypeName === "optional" || innerTypeName === "default" || innerTypeName === "catch";
|
|
72
|
-
}
|
|
73
|
-
function buildJsonSchemaFromZodLike(value) {
|
|
74
|
-
const shape = getZodLikeObjectShape(value);
|
|
75
|
-
if (shape) {
|
|
76
|
-
const properties = Object.fromEntries(Object.entries(shape).map(([key, entry]) => [key, buildJsonSchemaFromZodLike(getZodLikeInnerSchema(entry) ?? entry) ?? {}]));
|
|
77
|
-
const required = Object.entries(shape)
|
|
78
|
-
.filter(([, entry]) => {
|
|
79
|
-
const typeName = getZodLikeTypeName(entry);
|
|
80
|
-
return typeName !== "optional" && typeName !== "default" && typeName !== "catch" && !isEffectWrappedOptional(entry);
|
|
81
|
-
})
|
|
82
|
-
.map(([key]) => key);
|
|
83
|
-
return {
|
|
84
|
-
type: "object",
|
|
85
|
-
properties,
|
|
86
|
-
required,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
const typeName = getZodLikeTypeName(value);
|
|
90
|
-
switch (typeName) {
|
|
91
|
-
case "string":
|
|
92
|
-
return { type: "string" };
|
|
93
|
-
case "number":
|
|
94
|
-
return { type: "number" };
|
|
95
|
-
case "int":
|
|
96
|
-
case "integer":
|
|
97
|
-
return { type: "integer" };
|
|
98
|
-
case "boolean":
|
|
99
|
-
return { type: "boolean" };
|
|
100
|
-
case "unknown":
|
|
101
|
-
case "any":
|
|
102
|
-
return {};
|
|
103
|
-
case "array":
|
|
104
|
-
return {
|
|
105
|
-
type: "array",
|
|
106
|
-
items: buildJsonSchemaFromZodLike(getZodLikeInnerSchema(value)) ?? {},
|
|
107
|
-
};
|
|
108
|
-
case "record":
|
|
109
|
-
return {
|
|
110
|
-
type: "object",
|
|
111
|
-
additionalProperties: buildJsonSchemaFromZodLike(getZodLikeInnerSchema(value)) ?? {},
|
|
112
|
-
};
|
|
113
|
-
case "optional":
|
|
114
|
-
case "nullable":
|
|
115
|
-
case "default":
|
|
116
|
-
case "catch":
|
|
117
|
-
case "effects":
|
|
118
|
-
case "pipeline":
|
|
119
|
-
case "pipe":
|
|
120
|
-
case "transform":
|
|
121
|
-
return buildJsonSchemaFromZodLike(getZodLikeInnerSchema(value)) ?? {};
|
|
122
|
-
default:
|
|
123
|
-
return undefined;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
export function buildToolJsonSchema(schema) {
|
|
127
|
-
if (!schema) {
|
|
128
|
-
return undefined;
|
|
129
|
-
}
|
|
130
|
-
if (isZodSchema(schema)) {
|
|
131
|
-
return buildJsonSchemaFromZodLike(schema);
|
|
132
|
-
}
|
|
133
|
-
return {
|
|
134
|
-
type: "object",
|
|
135
|
-
properties: Object.fromEntries(Object.entries(schema).map(([key, value]) => [key, buildJsonSchemaFromZodLike(value) ?? {}])),
|
|
136
|
-
required: Object.entries(schema)
|
|
137
|
-
.filter(([, value]) => {
|
|
138
|
-
const typeName = getZodLikeTypeName(value);
|
|
139
|
-
return typeName !== "optional" && typeName !== "default" && typeName !== "catch" && !isEffectWrappedOptional(value);
|
|
140
|
-
})
|
|
141
|
-
.map(([key]) => key),
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
export function normalizeToolSchema(schema) {
|
|
145
|
-
if (isZodSchema(schema)) {
|
|
146
|
-
return schema;
|
|
147
|
-
}
|
|
148
|
-
const rawShape = schema;
|
|
149
|
-
return {
|
|
150
|
-
shape: rawShape,
|
|
151
|
-
parse(input) {
|
|
152
|
-
const source = typeof input === "object" && input !== null && !Array.isArray(input)
|
|
153
|
-
? input
|
|
154
|
-
: {};
|
|
155
|
-
const parsed = {};
|
|
156
|
-
for (const [key, validator] of Object.entries(rawShape)) {
|
|
157
|
-
if (!isParseableSchema(validator)) {
|
|
158
|
-
throw new TypeError(`Tool schema field '${key}' is not parseable.`);
|
|
159
|
-
}
|
|
160
|
-
const hasValue = Object.prototype.hasOwnProperty.call(source, key);
|
|
161
|
-
const value = hasValue ? source[key] : undefined;
|
|
162
|
-
const parsedValue = validator.parse(value);
|
|
163
|
-
if (parsedValue !== undefined) {
|
|
164
|
-
parsed[key] = parsedValue;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return parsed;
|
|
168
|
-
},
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
export function tool(definition) {
|
|
172
|
-
return {
|
|
173
|
-
...definition,
|
|
174
|
-
[TOOL_DEFINITION_MARKER]: true,
|
|
175
|
-
};
|
|
176
|
-
}
|
|
1
|
+
const l="__agent_harness_tool_definition__";function d(t){return typeof t=="object"&&t!==null&&typeof t.parse=="function"}function b(t){return typeof t=="object"&&t!==null&&typeof t.parse=="function"}function p(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 h(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 a(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 u(t){const e=p(t);if(e!=="effects"&&e!=="pipeline"&&e!=="pipe"&&e!=="transform")return!1;const n=a(t),r=p(n);return r==="optional"||r==="default"||r==="catch"}function i(t){const e=h(t);if(e){const r=Object.fromEntries(Object.entries(e).map(([o,f])=>[o,i(a(f)??f)??{}])),c=Object.entries(e).filter(([,o])=>{const f=p(o);return f!=="optional"&&f!=="default"&&f!=="catch"&&!u(o)}).map(([o])=>o);return{type:"object",properties:r,required:c}}switch(p(t)){case"string":return{type:"string"};case"number":return{type:"number"};case"int":case"integer":return{type:"integer"};case"boolean":return{type:"boolean"};case"unknown":case"any":return{};case"array":return{type:"array",items:i(a(t))??{}};case"record":return{type:"object",additionalProperties:i(a(t))??{}};case"optional":case"nullable":case"default":case"catch":case"effects":case"pipeline":case"pipe":case"transform":return i(a(t))??{};default:return}}function _(t){if(t)return d(t)?i(t):{type:"object",properties:Object.fromEntries(Object.entries(t).map(([e,n])=>[e,i(n)??{}])),required:Object.entries(t).filter(([,e])=>{const n=p(e);return n!=="optional"&&n!=="default"&&n!=="catch"&&!u(e)}).map(([e])=>e)}}function j(t){if(d(t))return t;const e=t;return{shape:e,parse(n){const r=typeof n=="object"&&n!==null&&!Array.isArray(n)?n:{},c={};for(const[o,f]of Object.entries(e)){if(!b(f))throw new TypeError(`Tool schema field '${o}' is not parseable.`);const y=Object.prototype.hasOwnProperty.call(r,o)?r[o]:void 0,s=f.parse(y);s!==void 0&&(c[o]=s)}return c}}}function O(t){return{...t,[l]:!0}}export{l as TOOL_DEFINITION_MARKER,_ as buildToolJsonSchema,j as normalizeToolSchema,O as tool};
|
|
@@ -1,18 +1 @@
|
|
|
1
|
-
function
|
|
2
|
-
return value
|
|
3
|
-
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
4
|
-
.replace(/[_-]+/g, " ")
|
|
5
|
-
.replace(/\s+/g, " ")
|
|
6
|
-
.trim();
|
|
7
|
-
}
|
|
8
|
-
export function formatAgentName(agentId) {
|
|
9
|
-
const normalized = normalizeSegment(agentId);
|
|
10
|
-
if (!normalized) {
|
|
11
|
-
return "Agent";
|
|
12
|
-
}
|
|
13
|
-
return normalized
|
|
14
|
-
.split(" ")
|
|
15
|
-
.filter(Boolean)
|
|
16
|
-
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
17
|
-
.join(" ");
|
|
18
|
-
}
|
|
1
|
+
function t(e){return e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").replace(/\s+/g," ").trim()}function a(e){const r=t(e);return r?r.split(" ").filter(Boolean).map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" "):"Agent"}export{a as formatAgentName};
|
|
@@ -1,39 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const normalized = relativePath.replace(/^\.?\//, "");
|
|
6
|
-
const cached = bundledTextCache.get(normalized);
|
|
7
|
-
if (cached !== undefined) {
|
|
8
|
-
return cached;
|
|
9
|
-
}
|
|
10
|
-
const resourceUrl = resolveBundledResourceUrl(normalized);
|
|
11
|
-
const value = readFileSync(resourceUrl, "utf8");
|
|
12
|
-
bundledTextCache.set(normalized, value);
|
|
13
|
-
return value;
|
|
14
|
-
}
|
|
15
|
-
function resolveBundledResourceUrl(relativePath) {
|
|
16
|
-
const candidates = [
|
|
17
|
-
new URL(`../resources/${relativePath}`, import.meta.url),
|
|
18
|
-
new URL(`../../resources/${relativePath}`, import.meta.url),
|
|
19
|
-
];
|
|
20
|
-
for (const candidate of candidates) {
|
|
21
|
-
if (existsSync(fileURLToPath(candidate))) {
|
|
22
|
-
return candidate;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return candidates[0];
|
|
26
|
-
}
|
|
27
|
-
export function renderTemplateText(template, values) {
|
|
28
|
-
return template
|
|
29
|
-
.replace(/\{\{([a-zA-Z0-9_]+)\}\}/g, (_match, key) => {
|
|
30
|
-
const value = values[key];
|
|
31
|
-
return value === undefined ? "" : String(value);
|
|
32
|
-
})
|
|
33
|
-
.replace(/[ \t]+\n/g, "\n")
|
|
34
|
-
.replace(/\n{3,}/g, "\n\n")
|
|
35
|
-
.trim();
|
|
36
|
-
}
|
|
37
|
-
export function renderBundledTemplate(relativePath, values) {
|
|
38
|
-
return renderTemplateText(readBundledText(relativePath), values);
|
|
39
|
-
}
|
|
1
|
+
import{existsSync as u,readFileSync as d}from"node:fs";import{fileURLToPath as a}from"node:url";const c=new Map;function i(r){const e=r.replace(/^\.?\//,""),n=c.get(e);if(n!==void 0)return n;const o=l(e),t=d(o,"utf8");return c.set(e,t),t}function l(r){const e=[new URL(`../resources/${r}`,import.meta.url),new URL(`../../resources/${r}`,import.meta.url)];for(const n of e)if(u(a(n)))return n;return e[0]}function s(r,e){return r.replace(/\{\{([a-zA-Z0-9_]+)\}\}/g,(n,o)=>{const t=e[o];return t===void 0?"":String(t)}).replace(/[ \t]+\n/g,`
|
|
2
|
+
`).replace(/\n{3,}/g,`
|
|
3
|
+
|
|
4
|
+
`).trim()}function m(r,e){return s(i(r),e)}export{i as readBundledText,m as renderBundledTemplate,s as renderTemplateText};
|
|
@@ -1,33 +1 @@
|
|
|
1
|
-
function
|
|
2
|
-
if (Object.prototype.hasOwnProperty.call(binding, property)) {
|
|
3
|
-
return;
|
|
4
|
-
}
|
|
5
|
-
Object.defineProperty(binding, property, {
|
|
6
|
-
configurable: true,
|
|
7
|
-
enumerable: false,
|
|
8
|
-
get() {
|
|
9
|
-
return binding.execution?.kind === kind ? binding.execution.params : undefined;
|
|
10
|
-
},
|
|
11
|
-
set(value) {
|
|
12
|
-
if (value === undefined) {
|
|
13
|
-
if (binding.execution?.kind === kind) {
|
|
14
|
-
delete binding.execution;
|
|
15
|
-
}
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
binding.execution = {
|
|
19
|
-
kind,
|
|
20
|
-
params: value,
|
|
21
|
-
};
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
export function attachLegacyExecutionAliases(binding) {
|
|
26
|
-
defineExecutionAlias(binding, "langchainAgentParams", "langchain-v1");
|
|
27
|
-
defineExecutionAlias(binding, "deepAgentParams", "deepagent");
|
|
28
|
-
return binding;
|
|
29
|
-
}
|
|
30
|
-
export function stripLegacyExecutionAliases(binding) {
|
|
31
|
-
const { langchainAgentParams: _langchainAgentParams, deepAgentParams: _deepAgentParams, ...rest } = binding;
|
|
32
|
-
return rest;
|
|
33
|
-
}
|
|
1
|
+
function r(e,n,t){Object.prototype.hasOwnProperty.call(e,n)||Object.defineProperty(e,n,{configurable:!0,enumerable:!1,get(){return e.execution?.kind===t?e.execution.params:void 0},set(a){if(a===void 0){e.execution?.kind===t&&delete e.execution;return}e.execution={kind:t,params:a}}})}function c(e){return r(e,"langchainAgentParams","langchain-v1"),r(e,"deepAgentParams","deepagent"),e}function u(e){const{langchainAgentParams:n,deepAgentParams:t,...a}=e;return a}export{c as attachLegacyExecutionAliases,u as stripLegacyExecutionAliases};
|