@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,197 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { parse } from "yaml";
|
|
4
|
-
import { isRecord } from "../../utils/object.js";
|
|
5
|
-
const skillMetadataCache = new Map();
|
|
6
|
-
const skillValidationCache = new Map();
|
|
7
|
-
const SKILL_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
8
|
-
function parseFrontmatterSource(document) {
|
|
9
|
-
const match = document.match(/^---\s*\n([\s\S]*?)\n---\s*(?:\n|$)/);
|
|
10
|
-
return match?.[1];
|
|
11
|
-
}
|
|
12
|
-
function isJsonLikeValue(value) {
|
|
13
|
-
if (value === null ||
|
|
14
|
-
typeof value === "string" ||
|
|
15
|
-
typeof value === "number" ||
|
|
16
|
-
typeof value === "boolean") {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
if (Array.isArray(value)) {
|
|
20
|
-
return value.every((item) => isJsonLikeValue(item));
|
|
21
|
-
}
|
|
22
|
-
if (isRecord(value)) {
|
|
23
|
-
return Object.values(value).every((item) => isJsonLikeValue(item));
|
|
24
|
-
}
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
function normalizeMetadata(value, strict) {
|
|
28
|
-
if (value === undefined) {
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
if (!isRecord(value)) {
|
|
32
|
-
if (strict) {
|
|
33
|
-
throw new Error("metadata must be a JSON-like key-value map");
|
|
34
|
-
}
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
const normalized = Object.entries(value).reduce((acc, [key, item]) => {
|
|
38
|
-
if (isJsonLikeValue(item)) {
|
|
39
|
-
acc[key] = item;
|
|
40
|
-
}
|
|
41
|
-
return acc;
|
|
42
|
-
}, {});
|
|
43
|
-
if (strict && Object.keys(normalized).length !== Object.keys(value).length) {
|
|
44
|
-
throw new Error("metadata values must be JSON-like");
|
|
45
|
-
}
|
|
46
|
-
return Object.keys(normalized).length > 0 ? normalized : undefined;
|
|
47
|
-
}
|
|
48
|
-
function normalizeStringArray(value) {
|
|
49
|
-
if (typeof value === "string") {
|
|
50
|
-
const tokens = value.split(/\s+/).filter(Boolean);
|
|
51
|
-
return tokens.length > 0 ? tokens : undefined;
|
|
52
|
-
}
|
|
53
|
-
if (!Array.isArray(value)) {
|
|
54
|
-
return undefined;
|
|
55
|
-
}
|
|
56
|
-
const tokens = value
|
|
57
|
-
.filter((item) => typeof item === "string")
|
|
58
|
-
.map((item) => item.trim())
|
|
59
|
-
.filter(Boolean);
|
|
60
|
-
return tokens.length > 0 ? tokens : undefined;
|
|
61
|
-
}
|
|
62
|
-
function toAllowedTools(value) {
|
|
63
|
-
const tools = normalizeStringArray(value);
|
|
64
|
-
return tools && tools.length > 0 ? tools : undefined;
|
|
65
|
-
}
|
|
66
|
-
function parseOpenClawMetadata(value) {
|
|
67
|
-
if (!isRecord(value)) {
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
const requires = isRecord(value.requires) ? value.requires : undefined;
|
|
71
|
-
const normalizedRequires = {
|
|
72
|
-
...(normalizeStringArray(requires?.bins) ? { bins: normalizeStringArray(requires?.bins) } : {}),
|
|
73
|
-
...(normalizeStringArray(requires?.anyBins) ? { anyBins: normalizeStringArray(requires?.anyBins) } : {}),
|
|
74
|
-
...(normalizeStringArray(requires?.env) ? { env: normalizeStringArray(requires?.env) } : {}),
|
|
75
|
-
...(normalizeStringArray(requires?.config) ? { config: normalizeStringArray(requires?.config) } : {}),
|
|
76
|
-
...(typeof value.primaryEnv === "string" && value.primaryEnv.trim()
|
|
77
|
-
? { primaryEnv: value.primaryEnv.trim() }
|
|
78
|
-
: typeof requires?.primaryEnv === "string" && requires.primaryEnv.trim()
|
|
79
|
-
? { primaryEnv: requires.primaryEnv.trim() }
|
|
80
|
-
: {}),
|
|
81
|
-
};
|
|
82
|
-
const normalized = {
|
|
83
|
-
...(typeof value.emoji === "string" && value.emoji.trim() ? { emoji: value.emoji } : {}),
|
|
84
|
-
...(Object.keys(normalizedRequires).length > 0 ? { requires: normalizedRequires } : {}),
|
|
85
|
-
};
|
|
86
|
-
return Object.keys(normalized).length > 0 ? normalized : undefined;
|
|
87
|
-
}
|
|
88
|
-
function parseFrontmatter(document, strict = false) {
|
|
89
|
-
const source = parseFrontmatterSource(document);
|
|
90
|
-
if (!source) {
|
|
91
|
-
return undefined;
|
|
92
|
-
}
|
|
93
|
-
const parsed = parse(source);
|
|
94
|
-
if (!isRecord(parsed)) {
|
|
95
|
-
return undefined;
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
name: typeof parsed.name === "string" ? parsed.name : "",
|
|
99
|
-
description: typeof parsed.description === "string" ? parsed.description : undefined,
|
|
100
|
-
license: typeof parsed.license === "string" ? parsed.license : undefined,
|
|
101
|
-
compatibility: typeof parsed.compatibility === "string" ? parsed.compatibility : undefined,
|
|
102
|
-
metadata: normalizeMetadata(parsed.metadata, strict),
|
|
103
|
-
allowedTools: toAllowedTools(parsed["allowed-tools"]),
|
|
104
|
-
userInvocable: typeof parsed["user-invocable"] === "boolean" ? parsed["user-invocable"] : undefined,
|
|
105
|
-
openclaw: parseOpenClawMetadata(isRecord(parsed.metadata) ? parsed.metadata.openclaw : undefined),
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
function isLegacyBuiltinSkillName(name) {
|
|
109
|
-
return /^builtin\.[a-z0-9-]+$/.test(name);
|
|
110
|
-
}
|
|
111
|
-
function validateSkillName(name, skillPath) {
|
|
112
|
-
if (!name || name.length > 64) {
|
|
113
|
-
throw new Error(`Skill ${skillPath} must define a name between 1 and 64 characters`);
|
|
114
|
-
}
|
|
115
|
-
if (!SKILL_NAME_PATTERN.test(name) && !isLegacyBuiltinSkillName(name)) {
|
|
116
|
-
throw new Error(`Skill ${skillPath} has invalid name ${name}. Standard skill names must use lowercase letters, numbers, and single hyphens`);
|
|
117
|
-
}
|
|
118
|
-
if (SKILL_NAME_PATTERN.test(name) && path.basename(skillPath) !== name) {
|
|
119
|
-
throw new Error(`Skill ${skillPath} must use a directory name that matches its frontmatter name ${name}`);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
function validateSkillDescription(description, skillPath) {
|
|
123
|
-
if (!description || !description.trim() || description.length > 1024) {
|
|
124
|
-
throw new Error(`Skill ${skillPath} must define a description between 1 and 1024 characters`);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
function validateCompatibility(value, skillPath) {
|
|
128
|
-
if (value !== undefined && (!value.trim() || value.length > 500)) {
|
|
129
|
-
throw new Error(`Skill ${skillPath} compatibility must be between 1 and 500 characters when provided`);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
function validateMetadata(metadata, skillPath) {
|
|
133
|
-
if (!metadata) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
if (Object.keys(metadata).length === 0) {
|
|
137
|
-
throw new Error(`Skill ${skillPath} metadata must contain JSON-like key-value pairs when provided`);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
function parseSkillMetadataFromDocument(document, skillPath, strict) {
|
|
141
|
-
const parsed = parseFrontmatter(document, strict);
|
|
142
|
-
if (!parsed) {
|
|
143
|
-
if (strict) {
|
|
144
|
-
throw new Error(`Skill ${skillPath} must contain YAML frontmatter in SKILL.md`);
|
|
145
|
-
}
|
|
146
|
-
return { name: path.basename(skillPath) };
|
|
147
|
-
}
|
|
148
|
-
const metadata = {
|
|
149
|
-
name: strict ? parsed.name : parsed.name || path.basename(skillPath),
|
|
150
|
-
description: parsed.description,
|
|
151
|
-
license: parsed.license,
|
|
152
|
-
compatibility: parsed.compatibility,
|
|
153
|
-
metadata: parsed.metadata,
|
|
154
|
-
allowedTools: parsed.allowedTools,
|
|
155
|
-
userInvocable: parsed.userInvocable,
|
|
156
|
-
openclaw: parsed.openclaw,
|
|
157
|
-
};
|
|
158
|
-
if (strict) {
|
|
159
|
-
validateSkillName(metadata.name, skillPath);
|
|
160
|
-
validateSkillDescription(metadata.description, skillPath);
|
|
161
|
-
validateCompatibility(metadata.compatibility, skillPath);
|
|
162
|
-
validateMetadata(metadata.metadata, skillPath);
|
|
163
|
-
}
|
|
164
|
-
return metadata;
|
|
165
|
-
}
|
|
166
|
-
export function readSkillMetadata(skillPath) {
|
|
167
|
-
const cached = skillMetadataCache.get(skillPath);
|
|
168
|
-
if (cached) {
|
|
169
|
-
return cached;
|
|
170
|
-
}
|
|
171
|
-
const metadata = {
|
|
172
|
-
name: path.basename(skillPath),
|
|
173
|
-
};
|
|
174
|
-
try {
|
|
175
|
-
const document = readFileSync(path.join(skillPath, "SKILL.md"), "utf8");
|
|
176
|
-
Object.assign(metadata, parseSkillMetadataFromDocument(document, skillPath, false));
|
|
177
|
-
}
|
|
178
|
-
catch {
|
|
179
|
-
// Fall back to the directory name when the skill doc cannot be read.
|
|
180
|
-
}
|
|
181
|
-
skillMetadataCache.set(skillPath, metadata);
|
|
182
|
-
return metadata;
|
|
183
|
-
}
|
|
184
|
-
export function validateSkillMetadata(skillPath) {
|
|
185
|
-
const cached = skillValidationCache.get(skillPath);
|
|
186
|
-
if (cached) {
|
|
187
|
-
return cached;
|
|
188
|
-
}
|
|
189
|
-
const document = readFileSync(path.join(skillPath, "SKILL.md"), "utf8");
|
|
190
|
-
const metadata = parseSkillMetadataFromDocument(document, skillPath, true);
|
|
191
|
-
skillValidationCache.set(skillPath, metadata);
|
|
192
|
-
skillMetadataCache.set(skillPath, metadata);
|
|
193
|
-
return metadata;
|
|
194
|
-
}
|
|
195
|
-
export function readSkillName(skillPath) {
|
|
196
|
-
return readSkillMetadata(skillPath).name;
|
|
197
|
-
}
|
|
1
|
+
import{readFileSync as f}from"node:fs";import a from"node:path";import{parse as y}from"yaml";import{isRecord as s}from"../../utils/object.js";const d=new Map,u=new Map,l=/^[a-z0-9]+(?:-[a-z0-9]+)*$/;function b(e){return e.match(/^---\s*\n([\s\S]*?)\n---\s*(?:\n|$)/)?.[1]}function c(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"?!0:Array.isArray(e)?e.every(n=>c(n)):s(e)?Object.values(e).every(n=>c(n)):!1}function w(e,n){if(e===void 0)return;if(!s(e)){if(n)throw new Error("metadata must be a JSON-like key-value map");return}const r=Object.entries(e).reduce((t,[o,m])=>(c(m)&&(t[o]=m),t),{});if(n&&Object.keys(r).length!==Object.keys(e).length)throw new Error("metadata values must be JSON-like");return Object.keys(r).length>0?r:void 0}function i(e){if(typeof e=="string"){const r=e.split(/\s+/).filter(Boolean);return r.length>0?r:void 0}if(!Array.isArray(e))return;const n=e.filter(r=>typeof r=="string").map(r=>r.trim()).filter(Boolean);return n.length>0?n:void 0}function g(e){const n=i(e);return n&&n.length>0?n:void 0}function S(e){if(!s(e))return;const n=s(e.requires)?e.requires:void 0,r={...i(n?.bins)?{bins:i(n?.bins)}:{},...i(n?.anyBins)?{anyBins:i(n?.anyBins)}:{},...i(n?.env)?{env:i(n?.env)}:{},...i(n?.config)?{config:i(n?.config)}:{},...typeof e.primaryEnv=="string"&&e.primaryEnv.trim()?{primaryEnv:e.primaryEnv.trim()}:typeof n?.primaryEnv=="string"&&n.primaryEnv.trim()?{primaryEnv:n.primaryEnv.trim()}:{}},t={...typeof e.emoji=="string"&&e.emoji.trim()?{emoji:e.emoji}:{},...Object.keys(r).length>0?{requires:r}:{}};return Object.keys(t).length>0?t:void 0}function h(e,n=!1){const r=b(e);if(!r)return;const t=y(r);if(s(t))return{name:typeof t.name=="string"?t.name:"",description:typeof t.description=="string"?t.description:void 0,license:typeof t.license=="string"?t.license:void 0,compatibility:typeof t.compatibility=="string"?t.compatibility:void 0,metadata:w(t.metadata,n),allowedTools:g(t["allowed-tools"]),userInvocable:typeof t["user-invocable"]=="boolean"?t["user-invocable"]:void 0,openclaw:S(s(t.metadata)?t.metadata.openclaw:void 0)}}function E(e){return/^builtin\.[a-z0-9-]+$/.test(e)}function j(e,n){if(!e||e.length>64)throw new Error(`Skill ${n} must define a name between 1 and 64 characters`);if(!l.test(e)&&!E(e))throw new Error(`Skill ${n} has invalid name ${e}. Standard skill names must use lowercase letters, numbers, and single hyphens`);if(l.test(e)&&a.basename(n)!==e)throw new Error(`Skill ${n} must use a directory name that matches its frontmatter name ${e}`)}function k(e,n){if(!e||!e.trim()||e.length>1024)throw new Error(`Skill ${n} must define a description between 1 and 1024 characters`)}function O(e,n){if(e!==void 0&&(!e.trim()||e.length>500))throw new Error(`Skill ${n} compatibility must be between 1 and 500 characters when provided`)}function $(e,n){if(e&&Object.keys(e).length===0)throw new Error(`Skill ${n} metadata must contain JSON-like key-value pairs when provided`)}function p(e,n,r){const t=h(e,r);if(!t){if(r)throw new Error(`Skill ${n} must contain YAML frontmatter in SKILL.md`);return{name:a.basename(n)}}const o={name:r?t.name:t.name||a.basename(n),description:t.description,license:t.license,compatibility:t.compatibility,metadata:t.metadata,allowedTools:t.allowedTools,userInvocable:t.userInvocable,openclaw:t.openclaw};return r&&(j(o.name,n),k(o.description,n),O(o.compatibility,n),$(o.metadata,n)),o}function L(e){const n=d.get(e);if(n)return n;const r={name:a.basename(e)};try{const t=f(a.join(e,"SKILL.md"),"utf8");Object.assign(r,p(t,e,!1))}catch{}return d.set(e,r),r}function v(e){const n=u.get(e);if(n)return n;const r=f(a.join(e,"SKILL.md"),"utf8"),t=p(r,e,!0);return u.set(e,t),d.set(e,t),t}function I(e){return L(e).name}export{L as readSkillMetadata,I as readSkillName,v as validateSkillMetadata};
|
|
@@ -1,37 +1,2 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
function formatDurationMs(startedAt) {
|
|
5
|
-
return (Date.now() - startedAt).toString();
|
|
6
|
-
}
|
|
7
|
-
function writeStartupTrace(stage, phase, durationMs, detail) {
|
|
8
|
-
if (!startupTimingEnabled()) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
const fields = [
|
|
12
|
-
"[agent-harness.startup]",
|
|
13
|
-
`stage=${stage}`,
|
|
14
|
-
`phase=${phase}`,
|
|
15
|
-
...(durationMs ? [`durationMs=${durationMs}`] : []),
|
|
16
|
-
...Object.entries(detail ?? {})
|
|
17
|
-
.filter(([, value]) => value !== undefined && value !== null && `${value}`.length > 0)
|
|
18
|
-
.map(([key, value]) => `${key}=${JSON.stringify(value)}`),
|
|
19
|
-
];
|
|
20
|
-
process.stderr.write(`${fields.join(" ")}\n`);
|
|
21
|
-
}
|
|
22
|
-
export async function traceStartupStage(stage, operation, detail) {
|
|
23
|
-
const startedAt = Date.now();
|
|
24
|
-
writeStartupTrace(stage, "start", undefined, detail);
|
|
25
|
-
try {
|
|
26
|
-
const result = await operation();
|
|
27
|
-
writeStartupTrace(stage, "success", formatDurationMs(startedAt), detail);
|
|
28
|
-
return result;
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
writeStartupTrace(stage, "failure", formatDurationMs(startedAt), {
|
|
32
|
-
...detail,
|
|
33
|
-
error: error instanceof Error ? error.message : String(error),
|
|
34
|
-
});
|
|
35
|
-
throw error;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
1
|
+
function u(){return process.env.AGENT_HARNESS_STARTUP_TIMING==="1"}function a(r){return(Date.now()-r).toString()}function o(r,i,n,s){if(!u())return;const t=["[agent-harness.startup]",`stage=${r}`,`phase=${i}`,...n?[`durationMs=${n}`]:[],...Object.entries(s??{}).filter(([,e])=>e!=null&&`${e}`.length>0).map(([e,c])=>`${e}=${JSON.stringify(c)}`)];process.stderr.write(`${t.join(" ")}
|
|
2
|
+
`)}async function f(r,i,n){const s=Date.now();o(r,"start",void 0,n);try{const t=await i();return o(r,"success",a(s),n),t}catch(t){throw o(r,"failure",a(s),{...n,error:t instanceof Error?t.message:String(t)}),t}}export{f as traceStartupStage};
|
|
@@ -1,290 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { asRecord } from "../../utils/object.js";
|
|
3
|
-
const bindingExecutionViewCache = new WeakMap();
|
|
4
|
-
function getLegacyAdapterParams(binding) {
|
|
5
|
-
return asRecord(binding.adapter?.config?.params);
|
|
6
|
-
}
|
|
7
|
-
function inferBindingAdapterKind(binding) {
|
|
8
|
-
if (binding.adapter?.kind) {
|
|
9
|
-
return binding.adapter.kind;
|
|
10
|
-
}
|
|
11
|
-
if (binding.execution?.kind === "langchain-v1" || binding.execution?.kind === "deepagent") {
|
|
12
|
-
return binding.execution.kind;
|
|
13
|
-
}
|
|
14
|
-
if (binding.langchainAgentParams) {
|
|
15
|
-
return "langchain-v1";
|
|
16
|
-
}
|
|
17
|
-
if (binding.deepAgentParams) {
|
|
18
|
-
return "deepagent";
|
|
19
|
-
}
|
|
20
|
-
return binding.agent.executionMode;
|
|
21
|
-
}
|
|
22
|
-
function normalizeBindingExecution(binding) {
|
|
23
|
-
const adapterKind = inferBindingAdapterKind(binding);
|
|
24
|
-
if (binding.execution?.kind === "langchain-v1") {
|
|
25
|
-
attachLegacyExecutionAliases(binding);
|
|
26
|
-
return { adapterKind, execution: binding.execution };
|
|
27
|
-
}
|
|
28
|
-
if (binding.execution?.kind === "deepagent") {
|
|
29
|
-
attachLegacyExecutionAliases(binding);
|
|
30
|
-
return { adapterKind, execution: binding.execution };
|
|
31
|
-
}
|
|
32
|
-
if (adapterKind !== "langchain-v1" && adapterKind !== "deepagent") {
|
|
33
|
-
return { adapterKind };
|
|
34
|
-
}
|
|
35
|
-
if (binding.langchainAgentParams) {
|
|
36
|
-
const execution = {
|
|
37
|
-
kind: "langchain-v1",
|
|
38
|
-
params: binding.langchainAgentParams,
|
|
39
|
-
};
|
|
40
|
-
binding.execution = execution;
|
|
41
|
-
attachLegacyExecutionAliases(binding);
|
|
42
|
-
return { adapterKind, execution };
|
|
43
|
-
}
|
|
44
|
-
if (binding.deepAgentParams) {
|
|
45
|
-
const execution = {
|
|
46
|
-
kind: "deepagent",
|
|
47
|
-
params: binding.deepAgentParams,
|
|
48
|
-
};
|
|
49
|
-
binding.execution = execution;
|
|
50
|
-
attachLegacyExecutionAliases(binding);
|
|
51
|
-
return { adapterKind, execution };
|
|
52
|
-
}
|
|
53
|
-
const legacyAdapterParams = getLegacyAdapterParams(binding);
|
|
54
|
-
if (adapterKind === "langchain-v1" && legacyAdapterParams) {
|
|
55
|
-
const params = legacyAdapterParams;
|
|
56
|
-
binding.execution = {
|
|
57
|
-
kind: "langchain-v1",
|
|
58
|
-
params,
|
|
59
|
-
};
|
|
60
|
-
attachLegacyExecutionAliases(binding);
|
|
61
|
-
return { adapterKind, execution: binding.execution };
|
|
62
|
-
}
|
|
63
|
-
if (adapterKind === "deepagent" && legacyAdapterParams) {
|
|
64
|
-
const params = legacyAdapterParams;
|
|
65
|
-
binding.execution = {
|
|
66
|
-
kind: "deepagent",
|
|
67
|
-
params,
|
|
68
|
-
};
|
|
69
|
-
attachLegacyExecutionAliases(binding);
|
|
70
|
-
return { adapterKind, execution: binding.execution };
|
|
71
|
-
}
|
|
72
|
-
return { adapterKind };
|
|
73
|
-
}
|
|
74
|
-
function deriveBindingExecutionView(binding) {
|
|
75
|
-
const cached = bindingExecutionViewCache.get(binding);
|
|
76
|
-
if (cached) {
|
|
77
|
-
return cached;
|
|
78
|
-
}
|
|
79
|
-
const normalized = normalizeBindingExecution(binding);
|
|
80
|
-
const adapterKind = normalized.adapterKind;
|
|
81
|
-
const langchainParams = normalized.execution?.kind === "langchain-v1" ? binding.langchainAgentParams : undefined;
|
|
82
|
-
const deepAgentParams = normalized.execution?.kind === "deepagent" ? binding.deepAgentParams : undefined;
|
|
83
|
-
const canonicalLangchainParams = normalized.execution?.kind === "langchain-v1" ? normalized.execution.params : undefined;
|
|
84
|
-
const canonicalDeepAgentParams = normalized.execution?.kind === "deepagent" ? normalized.execution.params : undefined;
|
|
85
|
-
const primaryTools = langchainParams?.tools ?? deepAgentParams?.tools ?? [];
|
|
86
|
-
const middlewareConfigs = langchainParams?.middleware ?? deepAgentParams?.middleware;
|
|
87
|
-
const middlewareKinds = new Set((middlewareConfigs ?? [])
|
|
88
|
-
.map((entry) => typeof entry.kind === "string" ? entry.kind : "")
|
|
89
|
-
.filter(Boolean));
|
|
90
|
-
const langchainRuntimeConfig = binding.harnessRuntime?.langchain;
|
|
91
|
-
const view = {
|
|
92
|
-
adapterKind,
|
|
93
|
-
langchainParams,
|
|
94
|
-
deepAgentParams,
|
|
95
|
-
executionParams: langchainParams ?? deepAgentParams,
|
|
96
|
-
primaryTools,
|
|
97
|
-
toolCount: primaryTools.length,
|
|
98
|
-
primaryModel: langchainParams?.model ?? deepAgentParams?.model,
|
|
99
|
-
systemPrompt: langchainParams?.systemPrompt ?? deepAgentParams?.systemPrompt,
|
|
100
|
-
middlewareConfigs,
|
|
101
|
-
middlewareKinds,
|
|
102
|
-
interruptCompatibilityRules: langchainRuntimeConfig?.interruptOn ??
|
|
103
|
-
langchainParams?.interruptOn ??
|
|
104
|
-
deepAgentParams?.interruptOn,
|
|
105
|
-
storeConfig: canonicalDeepAgentParams?.store ?? binding.harnessRuntime?.store,
|
|
106
|
-
langChainSubagentSupport: (langchainRuntimeConfig?.subagents?.length ?? 0) > 0 ||
|
|
107
|
-
(langchainRuntimeConfig?.generalPurposeAgent ?? langchainParams?.generalPurposeAgent) === true ||
|
|
108
|
-
Boolean((langchainRuntimeConfig?.taskDescription ?? langchainParams?.taskDescription)?.trim()),
|
|
109
|
-
deepAgentSubagentCount: canonicalDeepAgentParams?.subagents?.length ?? 0,
|
|
110
|
-
};
|
|
111
|
-
bindingExecutionViewCache.set(binding, view);
|
|
112
|
-
return view;
|
|
113
|
-
}
|
|
114
|
-
export function getBindingExecutionView(binding) {
|
|
115
|
-
return deriveBindingExecutionView(binding);
|
|
116
|
-
}
|
|
117
|
-
export function getBindingAdapterKind(binding) {
|
|
118
|
-
return getBindingExecutionView(binding).adapterKind;
|
|
119
|
-
}
|
|
120
|
-
export function getBindingCanonicalExecution(binding) {
|
|
121
|
-
return normalizeBindingExecution(binding).execution;
|
|
122
|
-
}
|
|
123
|
-
export function getBindingRuntimeExecutionMode(binding) {
|
|
124
|
-
return getBindingExecutionKind(binding) ?? getBindingAdapterKind(binding);
|
|
125
|
-
}
|
|
126
|
-
export function getBindingLangChainParams(binding) {
|
|
127
|
-
return getBindingExecutionView(binding).langchainParams;
|
|
128
|
-
}
|
|
129
|
-
export function getBindingDeepAgentParams(binding) {
|
|
130
|
-
return getBindingExecutionView(binding).deepAgentParams;
|
|
131
|
-
}
|
|
132
|
-
export function getBindingExecutionParams(binding) {
|
|
133
|
-
return getBindingExecutionView(binding).executionParams;
|
|
134
|
-
}
|
|
135
|
-
export function getBindingExecutionKind(binding) {
|
|
136
|
-
const execution = getBindingCanonicalExecution(binding);
|
|
137
|
-
return execution?.kind;
|
|
138
|
-
}
|
|
139
|
-
export function withUpdatedBindingExecutionParams(binding, updater) {
|
|
140
|
-
const kind = getBindingExecutionKind(binding);
|
|
141
|
-
const params = getBindingExecutionParams(binding);
|
|
142
|
-
if (!kind || !params) {
|
|
143
|
-
return binding;
|
|
144
|
-
}
|
|
145
|
-
const updatedParams = updater(params);
|
|
146
|
-
if (kind === "langchain-v1") {
|
|
147
|
-
return attachLegacyExecutionAliases({
|
|
148
|
-
...stripLegacyExecutionAliases(binding),
|
|
149
|
-
execution: {
|
|
150
|
-
kind,
|
|
151
|
-
params: updatedParams,
|
|
152
|
-
},
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
return attachLegacyExecutionAliases({
|
|
156
|
-
...stripLegacyExecutionAliases(binding),
|
|
157
|
-
execution: {
|
|
158
|
-
kind,
|
|
159
|
-
params: updatedParams,
|
|
160
|
-
},
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
export function getBindingSkills(binding) {
|
|
164
|
-
const langchainSkills = binding.harnessRuntime?.langchain?.skills;
|
|
165
|
-
if (Array.isArray(langchainSkills)) {
|
|
166
|
-
return langchainSkills;
|
|
167
|
-
}
|
|
168
|
-
const legacyLangchainSkills = binding.langchainAgentParams?.skills;
|
|
169
|
-
if (Array.isArray(legacyLangchainSkills)) {
|
|
170
|
-
return legacyLangchainSkills;
|
|
171
|
-
}
|
|
172
|
-
const execution = getBindingExecutionParams(binding);
|
|
173
|
-
return Array.isArray(execution?.skills)
|
|
174
|
-
? (execution.skills)
|
|
175
|
-
: [];
|
|
176
|
-
}
|
|
177
|
-
export function getBindingMemorySources(binding) {
|
|
178
|
-
const langchainMemory = binding.harnessRuntime?.langchain?.memory;
|
|
179
|
-
if (Array.isArray(langchainMemory)) {
|
|
180
|
-
return langchainMemory;
|
|
181
|
-
}
|
|
182
|
-
const legacyLangchainMemory = binding.langchainAgentParams?.memory;
|
|
183
|
-
if (Array.isArray(legacyLangchainMemory)) {
|
|
184
|
-
return legacyLangchainMemory;
|
|
185
|
-
}
|
|
186
|
-
const execution = getBindingExecutionParams(binding);
|
|
187
|
-
return Array.isArray(execution?.memory)
|
|
188
|
-
? (execution.memory)
|
|
189
|
-
: [];
|
|
190
|
-
}
|
|
191
|
-
export function getBindingSubagents(binding) {
|
|
192
|
-
const langchainSubagents = binding.harnessRuntime?.langchain?.subagents;
|
|
193
|
-
if (Array.isArray(langchainSubagents)) {
|
|
194
|
-
return langchainSubagents;
|
|
195
|
-
}
|
|
196
|
-
const legacyLangchainSubagents = binding.langchainAgentParams?.subagents;
|
|
197
|
-
if (Array.isArray(legacyLangchainSubagents)) {
|
|
198
|
-
return legacyLangchainSubagents;
|
|
199
|
-
}
|
|
200
|
-
const execution = getBindingExecutionParams(binding);
|
|
201
|
-
return Array.isArray(execution?.subagents)
|
|
202
|
-
? (execution.subagents)
|
|
203
|
-
: [];
|
|
204
|
-
}
|
|
205
|
-
export function getBindingDeepAgentSubagents(binding) {
|
|
206
|
-
const execution = getBindingExecutionParams(binding);
|
|
207
|
-
return Array.isArray(execution?.subagents)
|
|
208
|
-
? (execution.subagents)
|
|
209
|
-
: [];
|
|
210
|
-
}
|
|
211
|
-
export function getBindingGeneralPurposeAgent(binding) {
|
|
212
|
-
const langchainGeneralPurposeAgent = binding.harnessRuntime?.langchain?.generalPurposeAgent;
|
|
213
|
-
if (typeof langchainGeneralPurposeAgent === "boolean") {
|
|
214
|
-
return langchainGeneralPurposeAgent;
|
|
215
|
-
}
|
|
216
|
-
const value = binding.langchainAgentParams?.generalPurposeAgent;
|
|
217
|
-
return typeof value === "boolean" ? value : undefined;
|
|
218
|
-
}
|
|
219
|
-
export function getBindingTaskDescription(binding) {
|
|
220
|
-
const langchainTaskDescription = binding.harnessRuntime?.langchain?.taskDescription;
|
|
221
|
-
if (typeof langchainTaskDescription === "string" && langchainTaskDescription.trim().length > 0) {
|
|
222
|
-
return langchainTaskDescription;
|
|
223
|
-
}
|
|
224
|
-
const value = binding.langchainAgentParams?.taskDescription;
|
|
225
|
-
return typeof value === "string" && value.trim().length > 0 ? value : undefined;
|
|
226
|
-
}
|
|
227
|
-
export function getBindingBackendConfig(binding) {
|
|
228
|
-
const execution = getBindingExecutionParams(binding);
|
|
229
|
-
const backend = execution?.backend;
|
|
230
|
-
return typeof backend === "object" && backend ? backend : undefined;
|
|
231
|
-
}
|
|
232
|
-
export function getBindingInteractionMode(binding) {
|
|
233
|
-
const execution = getBindingExecutionParams(binding);
|
|
234
|
-
const mode = execution?.interactionMode;
|
|
235
|
-
return mode === "invoke" || mode === "stream" ? mode : undefined;
|
|
236
|
-
}
|
|
237
|
-
export function getBindingBuiltinToolsConfig(binding) {
|
|
238
|
-
const execution = getBindingExecutionParams(binding);
|
|
239
|
-
const builtinTools = execution?.builtinTools;
|
|
240
|
-
return typeof builtinTools === "object" && builtinTools
|
|
241
|
-
? builtinTools
|
|
242
|
-
: undefined;
|
|
243
|
-
}
|
|
244
|
-
export function getBindingFilesystemConfig(binding) {
|
|
245
|
-
const langchainFilesystem = binding.harnessRuntime?.langchain?.filesystem;
|
|
246
|
-
if (typeof langchainFilesystem === "object" && langchainFilesystem) {
|
|
247
|
-
return langchainFilesystem;
|
|
248
|
-
}
|
|
249
|
-
const filesystem = binding.langchainAgentParams?.filesystem;
|
|
250
|
-
return typeof filesystem === "object" && filesystem ? filesystem : undefined;
|
|
251
|
-
}
|
|
252
|
-
export function isLangChainBinding(binding) {
|
|
253
|
-
return getBindingExecutionKind(binding) === "langchain-v1";
|
|
254
|
-
}
|
|
255
|
-
export function isDeepAgentBinding(binding) {
|
|
256
|
-
return getBindingExecutionKind(binding) === "deepagent";
|
|
257
|
-
}
|
|
258
|
-
export function getBindingPrimaryTools(binding) {
|
|
259
|
-
return getBindingExecutionView(binding).primaryTools;
|
|
260
|
-
}
|
|
261
|
-
export function getBindingPrimaryModel(binding) {
|
|
262
|
-
return getBindingExecutionView(binding).primaryModel;
|
|
263
|
-
}
|
|
264
|
-
export function getBindingSystemPrompt(binding) {
|
|
265
|
-
return getBindingExecutionView(binding).systemPrompt;
|
|
266
|
-
}
|
|
267
|
-
export function getBindingMiddlewareConfigs(binding) {
|
|
268
|
-
return getBindingExecutionView(binding).middlewareConfigs;
|
|
269
|
-
}
|
|
270
|
-
export function getBindingToolCount(binding) {
|
|
271
|
-
return getBindingExecutionView(binding).toolCount;
|
|
272
|
-
}
|
|
273
|
-
export function bindingHasMiddlewareKind(binding, kind) {
|
|
274
|
-
return getBindingExecutionView(binding).middlewareKinds.has(kind);
|
|
275
|
-
}
|
|
276
|
-
export function bindingHasLangChainSubagentSupport(binding) {
|
|
277
|
-
return getBindingExecutionView(binding).langChainSubagentSupport;
|
|
278
|
-
}
|
|
279
|
-
export function getBindingInterruptCompatibilityRules(binding) {
|
|
280
|
-
return getBindingExecutionView(binding).interruptCompatibilityRules;
|
|
281
|
-
}
|
|
282
|
-
export function getBindingModelInit(binding) {
|
|
283
|
-
return getBindingPrimaryModel(binding)?.init;
|
|
284
|
-
}
|
|
285
|
-
export function getBindingStoreConfig(binding) {
|
|
286
|
-
return getBindingExecutionView(binding).storeConfig;
|
|
287
|
-
}
|
|
288
|
-
export function bindingHasSubagents(binding) {
|
|
289
|
-
return getBindingExecutionView(binding).deepAgentSubagentCount > 0;
|
|
290
|
-
}
|
|
1
|
+
import{attachLegacyExecutionAliases as o,stripLegacyExecutionAliases as x}from"../../utils/compiled-binding.js";import{asRecord as P}from"../../utils/object.js";const h=new WeakMap;function k(e){return P(e.adapter?.config?.params)}function B(e){return e.adapter?.kind?e.adapter.kind:e.execution?.kind==="langchain-v1"||e.execution?.kind==="deepagent"?e.execution.kind:e.langchainAgentParams?"langchain-v1":e.deepAgentParams?"deepagent":e.agent.executionMode}function y(e){const t=B(e);if(e.execution?.kind==="langchain-v1")return o(e),{adapterKind:t,execution:e.execution};if(e.execution?.kind==="deepagent")return o(e),{adapterKind:t,execution:e.execution};if(t!=="langchain-v1"&&t!=="deepagent")return{adapterKind:t};if(e.langchainAgentParams){const r={kind:"langchain-v1",params:e.langchainAgentParams};return e.execution=r,o(e),{adapterKind:t,execution:r}}if(e.deepAgentParams){const r={kind:"deepagent",params:e.deepAgentParams};return e.execution=r,o(e),{adapterKind:t,execution:r}}const n=k(e);if(t==="langchain-v1"&&n){const r=n;return e.execution={kind:"langchain-v1",params:r},o(e),{adapterKind:t,execution:e.execution}}if(t==="deepagent"&&n){const r=n;return e.execution={kind:"deepagent",params:r},o(e),{adapterKind:t,execution:e.execution}}return{adapterKind:t}}function C(e){const t=h.get(e);if(t)return t;const n=y(e),r=n.adapterKind,i=n.execution?.kind==="langchain-v1"?e.langchainAgentParams:void 0,s=n.execution?.kind==="deepagent"?e.deepAgentParams:void 0,M=n.execution?.kind==="langchain-v1"?n.execution.params:void 0,p=n.execution?.kind==="deepagent"?n.execution.params:void 0,l=i?.tools??s?.tools??[],d=i?.middleware??s?.middleware,A=new Set((d??[]).map(f=>typeof f.kind=="string"?f.kind:"").filter(Boolean)),c=e.harnessRuntime?.langchain,m={adapterKind:r,langchainParams:i,deepAgentParams:s,executionParams:i??s,primaryTools:l,toolCount:l.length,primaryModel:i?.model??s?.model,systemPrompt:i?.systemPrompt??s?.systemPrompt,middlewareConfigs:d,middlewareKinds:A,interruptCompatibilityRules:c?.interruptOn??i?.interruptOn??s?.interruptOn,storeConfig:p?.store??e.harnessRuntime?.store,langChainSubagentSupport:(c?.subagents?.length??0)>0||(c?.generalPurposeAgent??i?.generalPurposeAgent)===!0||!!(c?.taskDescription??i?.taskDescription)?.trim(),deepAgentSubagentCount:p?.subagents?.length??0};return h.set(e,m),m}function a(e){return C(e)}function S(e){return a(e).adapterKind}function v(e){return y(e).execution}function D(e){return g(e)??S(e)}function K(e){return a(e).langchainParams}function L(e){return a(e).deepAgentParams}function u(e){return a(e).executionParams}function g(e){return v(e)?.kind}function T(e,t){const n=g(e),r=u(e);if(!n||!r)return e;const i=t(r);return n==="langchain-v1"?o({...x(e),execution:{kind:n,params:i}}):o({...x(e),execution:{kind:n,params:i}})}function j(e){const t=e.harnessRuntime?.langchain?.skills;if(Array.isArray(t))return t;const n=e.langchainAgentParams?.skills;if(Array.isArray(n))return n;const r=u(e);return Array.isArray(r?.skills)?r.skills:[]}function H(e){const t=e.harnessRuntime?.langchain?.memory;if(Array.isArray(t))return t;const n=e.langchainAgentParams?.memory;if(Array.isArray(n))return n;const r=u(e);return Array.isArray(r?.memory)?r.memory:[]}function I(e){const t=e.harnessRuntime?.langchain?.subagents;if(Array.isArray(t))return t;const n=e.langchainAgentParams?.subagents;if(Array.isArray(n))return n;const r=u(e);return Array.isArray(r?.subagents)?r.subagents:[]}function O(e){const t=u(e);return Array.isArray(t?.subagents)?t.subagents:[]}function V(e){const t=e.harnessRuntime?.langchain?.generalPurposeAgent;if(typeof t=="boolean")return t;const n=e.langchainAgentParams?.generalPurposeAgent;return typeof n=="boolean"?n:void 0}function z(e){const t=e.harnessRuntime?.langchain?.taskDescription;if(typeof t=="string"&&t.trim().length>0)return t;const n=e.langchainAgentParams?.taskDescription;return typeof n=="string"&&n.trim().length>0?n:void 0}function F(e){const n=u(e)?.backend;return typeof n=="object"&&n?n:void 0}function G(e){const n=u(e)?.interactionMode;return n==="invoke"||n==="stream"?n:void 0}function U(e){const n=u(e)?.builtinTools;return typeof n=="object"&&n?n:void 0}function W(e){const t=e.harnessRuntime?.langchain?.filesystem;if(typeof t=="object"&&t)return t;const n=e.langchainAgentParams?.filesystem;return typeof n=="object"&&n?n:void 0}function q(e){return g(e)==="langchain-v1"}function J(e){return g(e)==="deepagent"}function N(e){return a(e).primaryTools}function w(e){return a(e).primaryModel}function Q(e){return a(e).systemPrompt}function X(e){return a(e).middlewareConfigs}function Y(e){return a(e).toolCount}function Z(e,t){return a(e).middlewareKinds.has(t)}function _(e){return a(e).langChainSubagentSupport}function $(e){return a(e).interruptCompatibilityRules}function b(e){return w(e)?.init}function ee(e){return a(e).storeConfig}function ne(e){return a(e).deepAgentSubagentCount>0}export{_ as bindingHasLangChainSubagentSupport,Z as bindingHasMiddlewareKind,ne as bindingHasSubagents,S as getBindingAdapterKind,F as getBindingBackendConfig,U as getBindingBuiltinToolsConfig,v as getBindingCanonicalExecution,L as getBindingDeepAgentParams,O as getBindingDeepAgentSubagents,g as getBindingExecutionKind,u as getBindingExecutionParams,a as getBindingExecutionView,W as getBindingFilesystemConfig,V as getBindingGeneralPurposeAgent,G as getBindingInteractionMode,$ as getBindingInterruptCompatibilityRules,K as getBindingLangChainParams,H as getBindingMemorySources,X as getBindingMiddlewareConfigs,b as getBindingModelInit,w as getBindingPrimaryModel,N as getBindingPrimaryTools,D as getBindingRuntimeExecutionMode,j as getBindingSkills,ee as getBindingStoreConfig,I as getBindingSubagents,Q as getBindingSystemPrompt,z as getBindingTaskDescription,Y as getBindingToolCount,J as isDeepAgentBinding,q as isLangChainBinding,T as withUpdatedBindingExecutionParams};
|
|
@@ -1,118 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { OpenAIEmbeddings } from "@langchain/openai";
|
|
3
|
-
import { compileEmbeddingModel } from "../../workspace/resource-compilers.js";
|
|
4
|
-
import { resolveRefId } from "../../workspace/support/workspace-ref-utils.js";
|
|
5
|
-
function asObject(value) {
|
|
6
|
-
return typeof value === "object" && value ? value : undefined;
|
|
7
|
-
}
|
|
8
|
-
function isPlaceholderApiKey(value) {
|
|
9
|
-
return typeof value === "string" && value.trim().toLowerCase() === "dummy";
|
|
10
|
-
}
|
|
11
|
-
function buildAuthOmittingFetch(baseFetch = fetch) {
|
|
12
|
-
return async (input, init) => {
|
|
13
|
-
const sanitizedHeaders = new Headers(input instanceof Request ? input.headers : undefined);
|
|
14
|
-
const initHeaders = new Headers(init?.headers);
|
|
15
|
-
initHeaders.forEach((value, key) => {
|
|
16
|
-
sanitizedHeaders.set(key, value);
|
|
17
|
-
});
|
|
18
|
-
sanitizedHeaders.delete("authorization");
|
|
19
|
-
if (input instanceof Request) {
|
|
20
|
-
return baseFetch(new Request(input, {
|
|
21
|
-
...init,
|
|
22
|
-
headers: sanitizedHeaders,
|
|
23
|
-
}));
|
|
24
|
-
}
|
|
25
|
-
return baseFetch(input, {
|
|
26
|
-
...init,
|
|
27
|
-
headers: sanitizedHeaders,
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function normalizeOpenAICompatibleInit(init) {
|
|
32
|
-
const normalized = { ...init };
|
|
33
|
-
const configuration = asObject(init.configuration) ?? {};
|
|
34
|
-
const baseUrl = typeof init.baseUrl === "string" && init.baseUrl.trim() ? init.baseUrl.trim() : undefined;
|
|
35
|
-
const omitAuthHeader = init.omitAuthHeader === true || isPlaceholderApiKey(init.apiKey);
|
|
36
|
-
const nextConfiguration = { ...configuration };
|
|
37
|
-
if (baseUrl && typeof nextConfiguration.baseURL !== "string") {
|
|
38
|
-
nextConfiguration.baseURL = baseUrl;
|
|
39
|
-
}
|
|
40
|
-
if (omitAuthHeader) {
|
|
41
|
-
nextConfiguration.fetch = buildAuthOmittingFetch(typeof configuration.fetch === "function" ? configuration.fetch : fetch);
|
|
42
|
-
}
|
|
43
|
-
normalized.configuration = nextConfiguration;
|
|
44
|
-
delete normalized.baseUrl;
|
|
45
|
-
delete normalized.omitAuthHeader;
|
|
46
|
-
return normalized;
|
|
47
|
-
}
|
|
48
|
-
function inferNodeLlamaCppModelPath(embeddingModel) {
|
|
49
|
-
const modelPath = typeof embeddingModel.init?.modelPath === "string" ? embeddingModel.init.modelPath.trim() : "";
|
|
50
|
-
if (modelPath) {
|
|
51
|
-
return modelPath;
|
|
52
|
-
}
|
|
53
|
-
return embeddingModel.model.includes("/") || embeddingModel.model.endsWith(".gguf") ? embeddingModel.model : undefined;
|
|
54
|
-
}
|
|
55
|
-
async function createNodeLlamaCppEmbeddings(embeddingModel) {
|
|
56
|
-
const modelPath = inferNodeLlamaCppModelPath(embeddingModel);
|
|
57
|
-
if (!modelPath) {
|
|
58
|
-
throw new Error(`Embedding model ${embeddingModel.id} with provider ${embeddingModel.provider} must define a GGUF path via top-level modelPath or use model as the GGUF path.`);
|
|
59
|
-
}
|
|
60
|
-
try {
|
|
61
|
-
const { LlamaCppEmbeddings } = await import("@langchain/community/embeddings/llama_cpp");
|
|
62
|
-
return await LlamaCppEmbeddings.initialize({
|
|
63
|
-
...embeddingModel.init,
|
|
64
|
-
modelPath,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
throw new Error(`Failed to initialize ${embeddingModel.provider} embedding model ${embeddingModel.id}. Install @langchain/community and node-llama-cpp in the application workspace and ensure the GGUF file exists at ${modelPath}.`, { cause: error });
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
async function createLazyLlamaIndexEmbeddingModel(embeddingModel) {
|
|
72
|
-
const { createLlamaIndexEmbeddingModel } = await import("./llamaindex.js");
|
|
73
|
-
return createLlamaIndexEmbeddingModel(embeddingModel);
|
|
74
|
-
}
|
|
75
|
-
export function resolveCompiledEmbeddingModelRef(workspace, embeddingModelRef) {
|
|
76
|
-
const resolvedId = embeddingModelRef ? resolveRefId(embeddingModelRef) : "default";
|
|
77
|
-
const embeddingModel = workspace.embeddings.get(resolvedId);
|
|
78
|
-
if (embeddingModel) {
|
|
79
|
-
return compileEmbeddingModel(embeddingModel);
|
|
80
|
-
}
|
|
81
|
-
if (!embeddingModelRef && workspace.embeddings.size === 1) {
|
|
82
|
-
const soleModel = workspace.embeddings.values().next().value;
|
|
83
|
-
if (soleModel) {
|
|
84
|
-
return compileEmbeddingModel(soleModel);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
throw new Error(`Missing embedding model ${embeddingModelRef ?? "embedding-model/default"}`);
|
|
88
|
-
}
|
|
89
|
-
export async function resolveCompiledEmbeddingModel(embeddingModel, resolver) {
|
|
90
|
-
if (resolver) {
|
|
91
|
-
return resolver(embeddingModel.id);
|
|
92
|
-
}
|
|
93
|
-
if (embeddingModel.provider === "ollama") {
|
|
94
|
-
return new OllamaEmbeddings({
|
|
95
|
-
model: embeddingModel.model,
|
|
96
|
-
...(embeddingModel.init ?? {}),
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
if (embeddingModel.provider === "openai-compatible") {
|
|
100
|
-
return new OpenAIEmbeddings({
|
|
101
|
-
model: embeddingModel.model,
|
|
102
|
-
...normalizeOpenAICompatibleInit(embeddingModel.init ?? {}),
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
if (embeddingModel.provider === "openai") {
|
|
106
|
-
return new OpenAIEmbeddings({
|
|
107
|
-
model: embeddingModel.model,
|
|
108
|
-
...(embeddingModel.init ?? {}),
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
if (embeddingModel.provider === "llamaindex-ollama") {
|
|
112
|
-
return createLazyLlamaIndexEmbeddingModel(embeddingModel);
|
|
113
|
-
}
|
|
114
|
-
if (embeddingModel.provider === "node-llama-cpp" || embeddingModel.provider === "llama-cpp") {
|
|
115
|
-
return createNodeLlamaCppEmbeddings(embeddingModel);
|
|
116
|
-
}
|
|
117
|
-
throw new Error(`Embedding model provider ${embeddingModel.provider} is not supported by the built-in runtime. Configure embeddingModelResolver or use openai-compatible/openai/ollama/llamaindex-ollama/node-llama-cpp.`);
|
|
118
|
-
}
|
|
1
|
+
import{OllamaEmbeddings as m}from"@langchain/ollama";import{OpenAIEmbeddings as a}from"@langchain/openai";import{compileEmbeddingModel as s}from"../../workspace/resource-compilers.js";import{resolveRefId as c}from"../../workspace/support/workspace-ref-utils.js";function f(e){return typeof e=="object"&&e?e:void 0}function u(e){return typeof e=="string"&&e.trim().toLowerCase()==="dummy"}function p(e=fetch){return async(t,r)=>{const n=new Headers(t instanceof Request?t.headers:void 0);return new Headers(r?.headers).forEach((o,l)=>{n.set(l,o)}),n.delete("authorization"),t instanceof Request?e(new Request(t,{...r,headers:n})):e(t,{...r,headers:n})}}function d(e){const t={...e},r=f(e.configuration)??{},n=typeof e.baseUrl=="string"&&e.baseUrl.trim()?e.baseUrl.trim():void 0,i=e.omitAuthHeader===!0||u(e.apiKey),o={...r};return n&&typeof o.baseURL!="string"&&(o.baseURL=n),i&&(o.fetch=p(typeof r.fetch=="function"?r.fetch:fetch)),t.configuration=o,delete t.baseUrl,delete t.omitAuthHeader,t}function h(e){const t=typeof e.init?.modelPath=="string"?e.init.modelPath.trim():"";return t||(e.model.includes("/")||e.model.endsWith(".gguf")?e.model:void 0)}async function w(e){const t=h(e);if(!t)throw new Error(`Embedding model ${e.id} with provider ${e.provider} must define a GGUF path via top-level modelPath or use model as the GGUF path.`);try{const{LlamaCppEmbeddings:r}=await import("@langchain/community/embeddings/llama_cpp");return await r.initialize({...e.init,modelPath:t})}catch(r){throw new Error(`Failed to initialize ${e.provider} embedding model ${e.id}. Install @langchain/community and node-llama-cpp in the application workspace and ensure the GGUF file exists at ${t}.`,{cause:r})}}async function y(e){const{createLlamaIndexEmbeddingModel:t}=await import("./llamaindex.js");return t(e)}function C(e,t){const r=t?c(t):"default",n=e.embeddings.get(r);if(n)return s(n);if(!t&&e.embeddings.size===1){const i=e.embeddings.values().next().value;if(i)return s(i)}throw new Error(`Missing embedding model ${t??"embedding-model/default"}`)}async function L(e,t){if(t)return t(e.id);if(e.provider==="ollama")return new m({model:e.model,...e.init??{}});if(e.provider==="openai-compatible")return new a({model:e.model,...d(e.init??{})});if(e.provider==="openai")return new a({model:e.model,...e.init??{}});if(e.provider==="llamaindex-ollama")return y(e);if(e.provider==="node-llama-cpp"||e.provider==="llama-cpp")return w(e);throw new Error(`Embedding model provider ${e.provider} is not supported by the built-in runtime. Configure embeddingModelResolver or use openai-compatible/openai/ollama/llamaindex-ollama/node-llama-cpp.`)}export{L as resolveCompiledEmbeddingModel,C as resolveCompiledEmbeddingModelRef};
|