@nylorun/core 0.0.0-bootstrap → 0.2.0-beta
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/CHANGELOG.md +21 -0
- package/LICENSE +192 -0
- package/README.md +16 -0
- package/dist/compatibility.d.ts +3 -0
- package/dist/compatibility.js +3 -0
- package/dist/contracts.d.ts +330 -0
- package/dist/contracts.js +366 -0
- package/dist/define.d.ts +32 -0
- package/dist/define.js +15 -0
- package/dist/definition/assemble.d.ts +29 -0
- package/dist/definition/assemble.js +120 -0
- package/dist/definition/bind-agent.d.ts +8 -0
- package/dist/definition/bind-agent.js +62 -0
- package/dist/definition/bind-tool.d.ts +4 -0
- package/dist/definition/bind-tool.js +25 -0
- package/dist/definition/binding.d.ts +15 -0
- package/dist/definition/binding.js +9 -0
- package/dist/definition/bound.d.ts +34 -0
- package/dist/definition/bound.js +1 -0
- package/dist/definition/builder.d.ts +66 -0
- package/dist/definition/builder.js +218 -0
- package/dist/definition/declaration.d.ts +10 -0
- package/dist/definition/declaration.js +93 -0
- package/dist/definition/from.d.ts +13 -0
- package/dist/definition/from.js +294 -0
- package/dist/definition/helpers.d.ts +23 -0
- package/dist/definition/helpers.js +33 -0
- package/dist/definition/implementations.d.ts +16 -0
- package/dist/definition/implementations.js +3 -0
- package/dist/definition/manifest.d.ts +13 -0
- package/dist/definition/manifest.js +60 -0
- package/dist/definition/output-contract.d.ts +6 -0
- package/dist/definition/output-contract.js +12 -0
- package/dist/definition/schema-json.d.ts +3 -0
- package/dist/definition/schema-json.js +22 -0
- package/dist/definition/schema.d.ts +16 -0
- package/dist/definition/schema.js +284 -0
- package/dist/definition/skill-tools.d.ts +3 -0
- package/dist/definition/skill-tools.js +56 -0
- package/dist/definition/tool-error.d.ts +9 -0
- package/dist/definition/tool-error.js +20 -0
- package/dist/errors.d.ts +17 -0
- package/dist/errors.js +22 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +1 -0
- package/dist/types/agent.d.ts +10 -0
- package/dist/types/agent.js +1 -0
- package/dist/types/dynamics.d.ts +53 -0
- package/dist/types/dynamics.js +1 -0
- package/dist/types/manifest.d.ts +57 -0
- package/dist/types/manifest.js +1 -0
- package/dist/types/middleware.d.ts +92 -0
- package/dist/types/middleware.js +1 -0
- package/dist/types/model.d.ts +184 -0
- package/dist/types/model.js +1 -0
- package/dist/types/observe.d.ts +180 -0
- package/dist/types/observe.js +1 -0
- package/dist/types/shared.d.ts +25 -0
- package/dist/types/shared.js +1 -0
- package/dist/types/tool.d.ts +194 -0
- package/dist/types/tool.js +1 -0
- package/dist/types/transcript.d.ts +65 -0
- package/dist/types/transcript.js +1 -0
- package/dist/utils/canonical.d.ts +1 -0
- package/dist/utils/canonical.js +10 -0
- package/dist/utils/hash.d.ts +3 -0
- package/dist/utils/hash.js +7 -0
- package/dist/utils/immutable.d.ts +6 -0
- package/dist/utils/immutable.js +76 -0
- package/package.json +57 -7
- package/index.js +0 -1
- package/publish.out +0 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { HarnessError } from "../errors.js";
|
|
2
|
+
import { assembleAgent } from "./assemble.js";
|
|
3
|
+
import { schemaFromJSON } from "./schema-json.js";
|
|
4
|
+
import { copyJsonObject, deepFreeze } from "../utils/immutable.js";
|
|
5
|
+
/** Rebuild an agent from manifest JSON + in-process implementations (T28). */
|
|
6
|
+
export function agentFrom(json, implementations, options) {
|
|
7
|
+
const manifest = normalizeManifest(json);
|
|
8
|
+
const sessionTools = options?.sessionTools ?? [];
|
|
9
|
+
assertSessionTools(manifest, sessionTools);
|
|
10
|
+
const entries = [];
|
|
11
|
+
const dynamics = new Map();
|
|
12
|
+
for (const capability of manifest.capabilities) {
|
|
13
|
+
const impl = implementations[capability.id] ?? {};
|
|
14
|
+
const tools = resolveTools(capability, impl.tools);
|
|
15
|
+
const session = sessionTools
|
|
16
|
+
.filter((item) => item.capabilityId === capability.id)
|
|
17
|
+
.map((item) => {
|
|
18
|
+
const live = impl.tools?.[item.name];
|
|
19
|
+
if (!live)
|
|
20
|
+
throw new HarnessError("agent.build-failed", `Missing session tool implementation '${item.name}' for capability '${capability.id}'`);
|
|
21
|
+
return live;
|
|
22
|
+
});
|
|
23
|
+
if (capability.beforeModelCall && !impl.beforeModelCall)
|
|
24
|
+
throw new HarnessError("agent.build-failed", `Missing beforeModelCall implementation for capability '${capability.id}'`);
|
|
25
|
+
if (capability.afterModelCall && !impl.afterModelCall)
|
|
26
|
+
throw new HarnessError("agent.build-failed", `Missing afterModelCall implementation for capability '${capability.id}'`);
|
|
27
|
+
const handle = impl.middleware ??
|
|
28
|
+
(async (request, next) => {
|
|
29
|
+
const advertised = [...tools, ...session];
|
|
30
|
+
if (advertised.length)
|
|
31
|
+
request.configuration.tools.set(capability.id, advertised.map((tool) => implementations[capability.id]?.tools?.[tool.name] ?? tool));
|
|
32
|
+
if (capability.instructions)
|
|
33
|
+
request.configuration.instructions.set(capability.id, capability.instructions);
|
|
34
|
+
return next();
|
|
35
|
+
});
|
|
36
|
+
entries.push(Object.freeze({
|
|
37
|
+
id: capability.id,
|
|
38
|
+
...(capability.name === undefined ? {} : { name: capability.name }),
|
|
39
|
+
...(capability.description === undefined
|
|
40
|
+
? {}
|
|
41
|
+
: { description: capability.description }),
|
|
42
|
+
handle,
|
|
43
|
+
hasMiddleware: impl.middleware !== undefined,
|
|
44
|
+
tools: capability.tools !== undefined
|
|
45
|
+
? tools.map((tool) => {
|
|
46
|
+
const live = impl.tools?.[tool.name];
|
|
47
|
+
if (!live)
|
|
48
|
+
throw new HarnessError("agent.build-failed", `Missing tool implementation '${tool.name}' for capability '${capability.id}'`);
|
|
49
|
+
return live;
|
|
50
|
+
})
|
|
51
|
+
: undefined,
|
|
52
|
+
...(session.length === 0 ? {} : { sessionTools: session }),
|
|
53
|
+
contributions: Object.freeze({
|
|
54
|
+
...(capability.instructions
|
|
55
|
+
? { instructions: capability.instructions }
|
|
56
|
+
: {}),
|
|
57
|
+
...(capability.tools
|
|
58
|
+
? {
|
|
59
|
+
tools: capability.tools.map((tool) => Object.freeze({
|
|
60
|
+
name: tool.name,
|
|
61
|
+
...(tool.description === undefined
|
|
62
|
+
? {}
|
|
63
|
+
: { description: tool.description }),
|
|
64
|
+
})),
|
|
65
|
+
}
|
|
66
|
+
: {}),
|
|
67
|
+
}),
|
|
68
|
+
...(capability.beforeModelCall ? { beforeModelCall: true } : {}),
|
|
69
|
+
...(capability.afterModelCall ? { afterModelCall: true } : {}),
|
|
70
|
+
manifestType: capability.type,
|
|
71
|
+
...(capability.metadata === undefined
|
|
72
|
+
? {}
|
|
73
|
+
: { metadata: capability.metadata }),
|
|
74
|
+
...(capability.mcpServers === undefined
|
|
75
|
+
? {}
|
|
76
|
+
: { mcpServers: capability.mcpServers }),
|
|
77
|
+
...(capability.skills === undefined
|
|
78
|
+
? {}
|
|
79
|
+
: { skills: capability.skills }),
|
|
80
|
+
}));
|
|
81
|
+
dynamics.set(capability.id, {
|
|
82
|
+
...(impl.beforeModelCall
|
|
83
|
+
? { beforeModelCall: impl.beforeModelCall }
|
|
84
|
+
: {}),
|
|
85
|
+
...(impl.afterModelCall
|
|
86
|
+
? { afterModelCall: impl.afterModelCall }
|
|
87
|
+
: {}),
|
|
88
|
+
...(impl.middleware ? { middleware: impl.middleware } : {}),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
const outputSchema = manifest.outputSchema
|
|
92
|
+
? schemaFromJSON(manifest.outputSchema)
|
|
93
|
+
: undefined;
|
|
94
|
+
const result = assembleAgent(entries, {
|
|
95
|
+
id: manifest.id,
|
|
96
|
+
name: manifest.name,
|
|
97
|
+
description: manifest.description,
|
|
98
|
+
metadata: manifest.metadata,
|
|
99
|
+
outputSchema,
|
|
100
|
+
runtime: manifest.runtime,
|
|
101
|
+
}, dynamics);
|
|
102
|
+
if (!result.ok)
|
|
103
|
+
throw new HarnessError("agent.build-failed", result.diagnostics.map((item) => item.message).join("; "));
|
|
104
|
+
return result.agent;
|
|
105
|
+
}
|
|
106
|
+
function assertSessionTools(manifest, sessionTools) {
|
|
107
|
+
const seen = new Set();
|
|
108
|
+
for (const item of sessionTools) {
|
|
109
|
+
if (seen.has(item.name))
|
|
110
|
+
throw new HarnessError("agent.build-failed", `Duplicate session tool '${item.name}'`);
|
|
111
|
+
seen.add(item.name);
|
|
112
|
+
const capability = manifest.capabilities.find((entry) => entry.id === item.capabilityId);
|
|
113
|
+
if (!capability)
|
|
114
|
+
throw new HarnessError("agent.build-failed", `Session tool '${item.name}' references unknown capability '${item.capabilityId}'`);
|
|
115
|
+
if (capability.tools?.some((tool) => tool.name === item.name))
|
|
116
|
+
throw new HarnessError("agent.build-failed", `Session tool '${item.name}' collides with a declared tool`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function resolveTools(capability, tools) {
|
|
120
|
+
if (!capability.tools?.length)
|
|
121
|
+
return [];
|
|
122
|
+
return capability.tools.flatMap((declared) => {
|
|
123
|
+
const live = tools?.[declared.name];
|
|
124
|
+
if (live)
|
|
125
|
+
return [live];
|
|
126
|
+
if ((declared.name === "load_skill" || declared.name === "read_skill_resource") &&
|
|
127
|
+
capability.skills &&
|
|
128
|
+
Object.keys(capability.skills).length > 0)
|
|
129
|
+
return [];
|
|
130
|
+
throw new HarnessError("agent.build-failed", `Missing tool implementation '${declared.name}' for capability '${capability.id}'`);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function normalizeManifest(json) {
|
|
134
|
+
if (!json || typeof json !== "object" || Array.isArray(json))
|
|
135
|
+
throw new HarnessError("agent.build-failed", "Agent.from requires a manifest object");
|
|
136
|
+
const value = json;
|
|
137
|
+
if (typeof value.id !== "string" || !value.id)
|
|
138
|
+
throw new HarnessError("agent.build-failed", "Manifest id must be a non-empty string");
|
|
139
|
+
if ("name" in value && value.name !== undefined) {
|
|
140
|
+
if (typeof value.name !== "string" || !value.name)
|
|
141
|
+
throw new HarnessError("agent.build-failed", "Manifest name must be a non-empty string");
|
|
142
|
+
}
|
|
143
|
+
if (!Array.isArray(value.capabilities))
|
|
144
|
+
throw new HarnessError("agent.build-failed", "Manifest capabilities must be an array");
|
|
145
|
+
if ("schemaVersion" in value && value.schemaVersion !== undefined)
|
|
146
|
+
throw new HarnessError("agent.build-failed", "Manifest field schemaVersion was renamed to manifestSchemaVersion");
|
|
147
|
+
if (value.manifestSchemaVersion !== 3)
|
|
148
|
+
throw new HarnessError("agent.build-failed", `Unsupported manifestSchemaVersion ${String(value.manifestSchemaVersion)}`);
|
|
149
|
+
// Reject top-level model (Runtime-owned).
|
|
150
|
+
if ("model" in value && value.model !== undefined)
|
|
151
|
+
throw new HarnessError("agent.build-failed", "Manifest must not include top-level model; Runtime owns model resolution");
|
|
152
|
+
if ("description" in value && value.description !== undefined) {
|
|
153
|
+
if (typeof value.description !== "string")
|
|
154
|
+
throw new HarnessError("agent.build-failed", "Manifest description must be a string");
|
|
155
|
+
}
|
|
156
|
+
const metadata = "metadata" in value && value.metadata !== undefined
|
|
157
|
+
? copyJsonObject(value.metadata, "metadata")
|
|
158
|
+
: undefined;
|
|
159
|
+
const runtime = normalizeRuntime(value.runtime);
|
|
160
|
+
const capabilities = value.capabilities.map(normalizeCapability);
|
|
161
|
+
const servers = new Set();
|
|
162
|
+
for (const capability of capabilities)
|
|
163
|
+
for (const name of Object.keys(capability.mcpServers ?? {})) {
|
|
164
|
+
if (servers.has(name))
|
|
165
|
+
throw new HarnessError("agent.build-failed", `Duplicate MCP server '${name}'`);
|
|
166
|
+
servers.add(name);
|
|
167
|
+
}
|
|
168
|
+
return deepFreeze({
|
|
169
|
+
manifestSchemaVersion: 3,
|
|
170
|
+
id: value.id,
|
|
171
|
+
...(typeof value.name === "string" && value.name ? { name: value.name } : {}),
|
|
172
|
+
...(typeof value.description === "string"
|
|
173
|
+
? { description: value.description }
|
|
174
|
+
: {}),
|
|
175
|
+
...(metadata === undefined ? {} : { metadata }),
|
|
176
|
+
...(value.outputSchema && typeof value.outputSchema === "object"
|
|
177
|
+
? { outputSchema: value.outputSchema }
|
|
178
|
+
: {}),
|
|
179
|
+
capabilities,
|
|
180
|
+
...(runtime === undefined ? {} : { runtime }),
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
function normalizeRuntime(value) {
|
|
184
|
+
if (value === undefined)
|
|
185
|
+
return undefined;
|
|
186
|
+
if (!value ||
|
|
187
|
+
typeof value !== "object" ||
|
|
188
|
+
Array.isArray(value) ||
|
|
189
|
+
Object.keys(value).length > 0)
|
|
190
|
+
throw new HarnessError("agent.build-failed", "runtime must be an empty object when present");
|
|
191
|
+
return {};
|
|
192
|
+
}
|
|
193
|
+
function normalizeCapability(capability) {
|
|
194
|
+
const raw = capability;
|
|
195
|
+
if ("name" in raw && raw.name !== undefined) {
|
|
196
|
+
if (typeof raw.name !== "string" || !raw.name)
|
|
197
|
+
throw new HarnessError("agent.build-failed", `Capability '${capability.id}' name must be a non-empty string`);
|
|
198
|
+
}
|
|
199
|
+
if ("description" in raw && raw.description !== undefined) {
|
|
200
|
+
if (typeof raw.description !== "string")
|
|
201
|
+
throw new HarnessError("agent.build-failed", `Capability '${capability.id}' description must be a string`);
|
|
202
|
+
}
|
|
203
|
+
if ("model" in raw && raw.model !== undefined)
|
|
204
|
+
throw new HarnessError("agent.build-failed", `Capability '${capability.id}' must not include model; Runtime owns model resolution`);
|
|
205
|
+
if (capability.type !== "agent" && capability.type !== "agent-plugin")
|
|
206
|
+
throw new HarnessError("agent.build-failed", `Capability '${capability.id}' type must be agent or agent-plugin`);
|
|
207
|
+
const metadata = capability.metadata === undefined
|
|
208
|
+
? undefined
|
|
209
|
+
: copyJsonObject(capability.metadata, "metadata");
|
|
210
|
+
const mcpServers = normalizeMcpServers(capability.id, capability.mcpServers);
|
|
211
|
+
const skills = normalizeSkills(capability.id, capability.skills);
|
|
212
|
+
return Object.freeze({
|
|
213
|
+
id: capability.id,
|
|
214
|
+
type: capability.type,
|
|
215
|
+
...(typeof raw.name === "string" && raw.name ? { name: raw.name } : {}),
|
|
216
|
+
...(typeof raw.description === "string"
|
|
217
|
+
? { description: raw.description }
|
|
218
|
+
: {}),
|
|
219
|
+
...(metadata === undefined ? {} : { metadata }),
|
|
220
|
+
...(capability.instructions
|
|
221
|
+
? { instructions: Object.freeze([...capability.instructions]) }
|
|
222
|
+
: {}),
|
|
223
|
+
...(capability.tools
|
|
224
|
+
? { tools: Object.freeze(capability.tools.map(normalizeTool)) }
|
|
225
|
+
: {}),
|
|
226
|
+
...(skills === undefined ? {} : { skills }),
|
|
227
|
+
...(mcpServers === undefined ? {} : { mcpServers }),
|
|
228
|
+
...(capability.beforeModelCall ? { beforeModelCall: true } : {}),
|
|
229
|
+
...(capability.afterModelCall ? { afterModelCall: true } : {}),
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
function normalizeSkills(capabilityId, skills) {
|
|
233
|
+
if (skills === undefined)
|
|
234
|
+
return undefined;
|
|
235
|
+
if (!skills ||
|
|
236
|
+
typeof skills !== "object" ||
|
|
237
|
+
Array.isArray(skills) ||
|
|
238
|
+
Object.keys(skills).length === 0)
|
|
239
|
+
throw new HarnessError("agent.build-failed", `Capability '${capabilityId}' skills must be a non-empty map or omitted`);
|
|
240
|
+
const normalized = {};
|
|
241
|
+
for (const [key, skill] of Object.entries(skills)) {
|
|
242
|
+
if (!skill ||
|
|
243
|
+
typeof skill !== "object" ||
|
|
244
|
+
skill.name !== key ||
|
|
245
|
+
typeof skill.description !== "string" ||
|
|
246
|
+
skill.description.length === 0)
|
|
247
|
+
throw new HarnessError("agent.build-failed", `Capability '${capabilityId}' skills key '${key}' must equal the skill name`);
|
|
248
|
+
normalized[key] = Object.freeze({
|
|
249
|
+
name: skill.name,
|
|
250
|
+
description: skill.description,
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
return Object.freeze(normalized);
|
|
254
|
+
}
|
|
255
|
+
function normalizeMcpServers(capabilityId, servers) {
|
|
256
|
+
if (servers === undefined)
|
|
257
|
+
return undefined;
|
|
258
|
+
if (!servers ||
|
|
259
|
+
typeof servers !== "object" ||
|
|
260
|
+
Array.isArray(servers) ||
|
|
261
|
+
Object.keys(servers).length === 0)
|
|
262
|
+
throw new HarnessError("agent.build-failed", `Capability '${capabilityId}' mcpServers must be a non-empty map or omitted`);
|
|
263
|
+
const normalized = {};
|
|
264
|
+
for (const [key, server] of Object.entries(servers)) {
|
|
265
|
+
if (!isMcpServer(server) || server.name !== key)
|
|
266
|
+
throw new HarnessError("agent.build-failed", `Capability '${capabilityId}' mcpServers key '${key}' must equal the server name`);
|
|
267
|
+
normalized[key] = server;
|
|
268
|
+
}
|
|
269
|
+
return Object.freeze(normalized);
|
|
270
|
+
}
|
|
271
|
+
function isMcpServer(value) {
|
|
272
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
273
|
+
return false;
|
|
274
|
+
const server = value;
|
|
275
|
+
if (typeof server.name !== "string" || !server.name)
|
|
276
|
+
return false;
|
|
277
|
+
if (server.type === "stdio")
|
|
278
|
+
return typeof server.command === "string" && server.command.length > 0;
|
|
279
|
+
if (server.type === "streamable-http" || server.type === "sse")
|
|
280
|
+
return typeof server.url === "string" && server.url.length > 0;
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
function normalizeTool(tool) {
|
|
284
|
+
return Object.freeze({
|
|
285
|
+
name: tool.name,
|
|
286
|
+
...(tool.description === undefined
|
|
287
|
+
? {}
|
|
288
|
+
: { description: tool.description }),
|
|
289
|
+
inputSchema: tool.inputSchema,
|
|
290
|
+
...(tool.outputSchema === undefined
|
|
291
|
+
? {}
|
|
292
|
+
: { outputSchema: tool.outputSchema }),
|
|
293
|
+
});
|
|
294
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ModelAdapter } from "../types/model.js";
|
|
2
|
+
import type { StepMiddleware } from "../types/middleware.js";
|
|
3
|
+
import type { ToolDefinition, ToolInputSchema, ToolOutputSchema, ToolSchemaSource } from "../types/tool.js";
|
|
4
|
+
export declare const tool: <InputSchema extends ToolInputSchema, Info = unknown, OutputSchema extends ToolOutputSchema | undefined = undefined>(value: ToolDefinition<InputSchema, Info, OutputSchema>) => ToolDefinition<InputSchema, Info, OutputSchema>;
|
|
5
|
+
/** @deprecated Prefer Runtime model resolution. Capability-disguised `.use({ model })` is not the taught path. */
|
|
6
|
+
export declare const model: <T extends ModelAdapter>(value: T) => T;
|
|
7
|
+
/** @deprecated Prefer `beforeModelCall` / `afterModelCall`. Kept through 1.0. */
|
|
8
|
+
export declare const middleware: <T extends StepMiddleware>(value: T) => T;
|
|
9
|
+
/** Compose a reusable capability bundle (tools, instructions, optional dynamics). */
|
|
10
|
+
export declare function capability<Info = unknown>(declaration: {
|
|
11
|
+
readonly id: string;
|
|
12
|
+
readonly name?: string;
|
|
13
|
+
readonly description?: string;
|
|
14
|
+
readonly tools?: readonly ToolDefinition<any, Info, any>[];
|
|
15
|
+
readonly instructions?: string | readonly string[];
|
|
16
|
+
readonly beforeModelCall?: import("../types/dynamics.js").BeforeModelCallFn<Info>;
|
|
17
|
+
readonly afterModelCall?: import("../types/dynamics.js").AfterModelCallFn<Info>;
|
|
18
|
+
/** @deprecated Prefer beforeModelCall / afterModelCall. */
|
|
19
|
+
readonly middleware?: StepMiddleware<Info>;
|
|
20
|
+
/** @deprecated Model resolution is Runtime-owned; not projected into the manifest. */
|
|
21
|
+
readonly model?: import("../types/model.js").ModelDirective;
|
|
22
|
+
}): import("../types/middleware.js").CapabilityDeclaration<Info>;
|
|
23
|
+
export type { ToolSchemaSource };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { prepareTool } from "./schema.js";
|
|
2
|
+
export const tool = (value) => prepareTool(value);
|
|
3
|
+
/** @deprecated Prefer Runtime model resolution. Capability-disguised `.use({ model })` is not the taught path. */
|
|
4
|
+
export const model = (value) => value;
|
|
5
|
+
/** @deprecated Prefer `beforeModelCall` / `afterModelCall`. Kept through 1.0. */
|
|
6
|
+
export const middleware = (value) => value;
|
|
7
|
+
/** Compose a reusable capability bundle (tools, instructions, optional dynamics). */
|
|
8
|
+
export function capability(declaration) {
|
|
9
|
+
const instructions = declaration.instructions === undefined
|
|
10
|
+
? undefined
|
|
11
|
+
: typeof declaration.instructions === "string"
|
|
12
|
+
? [declaration.instructions]
|
|
13
|
+
: declaration.instructions;
|
|
14
|
+
return {
|
|
15
|
+
id: declaration.id,
|
|
16
|
+
...(declaration.name === undefined ? {} : { name: declaration.name }),
|
|
17
|
+
...(declaration.description === undefined
|
|
18
|
+
? {}
|
|
19
|
+
: { description: declaration.description }),
|
|
20
|
+
...(declaration.tools === undefined ? {} : { tools: declaration.tools }),
|
|
21
|
+
...(instructions === undefined ? {} : { instructions }),
|
|
22
|
+
...(declaration.beforeModelCall === undefined
|
|
23
|
+
? {}
|
|
24
|
+
: { beforeModelCall: declaration.beforeModelCall }),
|
|
25
|
+
...(declaration.afterModelCall === undefined
|
|
26
|
+
? {}
|
|
27
|
+
: { afterModelCall: declaration.afterModelCall }),
|
|
28
|
+
...(declaration.middleware === undefined
|
|
29
|
+
? {}
|
|
30
|
+
: { middleware: declaration.middleware }),
|
|
31
|
+
...(declaration.model === undefined ? {} : { model: declaration.model }),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AfterModelCallFn, BeforeModelCallFn } from "../types/dynamics.js";
|
|
2
|
+
import type { ToolDefinition } from "../types/tool.js";
|
|
3
|
+
import type { StepMiddleware } from "../types/middleware.js";
|
|
4
|
+
/** In-process implementations table keyed by capability id (never serialized). */
|
|
5
|
+
export interface Implementations<Info = unknown> {
|
|
6
|
+
readonly [capabilityId: string]: {
|
|
7
|
+
readonly tools?: {
|
|
8
|
+
readonly [toolName: string]: ToolDefinition<any, Info, any>;
|
|
9
|
+
};
|
|
10
|
+
readonly beforeModelCall?: BeforeModelCallFn<Info>;
|
|
11
|
+
readonly afterModelCall?: AfterModelCallFn<Info>;
|
|
12
|
+
/** @deprecated Local engine only through 1.0. */
|
|
13
|
+
readonly middleware?: StepMiddleware<Info>;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare function emptyImplementations(): Implementations;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { BoundMiddleware } from "./bound.js";
|
|
2
|
+
import type { AgentManifest, RuntimeManifest } from "../types/manifest.js";
|
|
3
|
+
import type { JsonObject } from "../types/shared.js";
|
|
4
|
+
import type { ToolSchemaSource } from "../types/tool.js";
|
|
5
|
+
export declare function createManifest(input: {
|
|
6
|
+
id: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
metadata?: JsonObject;
|
|
10
|
+
outputSchema?: ToolSchemaSource;
|
|
11
|
+
runtime?: RuntimeManifest;
|
|
12
|
+
middleware: readonly BoundMiddleware[];
|
|
13
|
+
}): AgentManifest;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { bindOutputContract } from "./output-contract.js";
|
|
2
|
+
import { normalizedSchemasFor } from "./schema.js";
|
|
3
|
+
import { copyJsonObject, deepFreeze } from "../utils/immutable.js";
|
|
4
|
+
export function createManifest(input) {
|
|
5
|
+
const capabilities = input.middleware.map((item) => projectCapability(item));
|
|
6
|
+
return deepFreeze({
|
|
7
|
+
manifestSchemaVersion: 3,
|
|
8
|
+
id: input.id,
|
|
9
|
+
...(input.name === undefined ? {} : { name: input.name }),
|
|
10
|
+
...(input.description === undefined
|
|
11
|
+
? {}
|
|
12
|
+
: { description: input.description }),
|
|
13
|
+
...(input.metadata === undefined
|
|
14
|
+
? {}
|
|
15
|
+
: { metadata: copyJsonObject(input.metadata, "metadata") }),
|
|
16
|
+
...(input.outputSchema === undefined
|
|
17
|
+
? {}
|
|
18
|
+
: {
|
|
19
|
+
outputSchema: bindOutputContract(input.outputSchema).schema
|
|
20
|
+
.jsonSchema,
|
|
21
|
+
}),
|
|
22
|
+
capabilities,
|
|
23
|
+
...(input.runtime === undefined ? {} : { runtime: input.runtime }),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function projectCapability(item) {
|
|
27
|
+
const contributions = item.contributions;
|
|
28
|
+
return {
|
|
29
|
+
id: item.id,
|
|
30
|
+
type: item.manifestType ?? "agent",
|
|
31
|
+
...(item.name === undefined ? {} : { name: item.name }),
|
|
32
|
+
...(item.description === undefined ? {} : { description: item.description }),
|
|
33
|
+
...(item.metadata === undefined
|
|
34
|
+
? {}
|
|
35
|
+
: { metadata: copyJsonObject(item.metadata, "metadata") }),
|
|
36
|
+
...(contributions?.instructions === undefined
|
|
37
|
+
? {}
|
|
38
|
+
: { instructions: contributions.instructions }),
|
|
39
|
+
...(item.tools === undefined
|
|
40
|
+
? {}
|
|
41
|
+
: { tools: item.tools.map((tool) => projectTool(tool)) }),
|
|
42
|
+
...(item.skills === undefined ? {} : { skills: item.skills }),
|
|
43
|
+
...(item.mcpServers === undefined ? {} : { mcpServers: item.mcpServers }),
|
|
44
|
+
...(item.beforeModelCall ? { beforeModelCall: true } : {}),
|
|
45
|
+
...(item.afterModelCall ? { afterModelCall: true } : {}),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function projectTool(tool) {
|
|
49
|
+
const schemas = normalizedSchemasFor(tool);
|
|
50
|
+
return {
|
|
51
|
+
name: tool.name,
|
|
52
|
+
...(tool.description === undefined
|
|
53
|
+
? {}
|
|
54
|
+
: { description: tool.description }),
|
|
55
|
+
inputSchema: schemas.inputSchema.jsonSchema,
|
|
56
|
+
...(schemas.outputSchema === undefined
|
|
57
|
+
? {}
|
|
58
|
+
: { outputSchema: schemas.outputSchema.jsonSchema }),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ToolSchema, ToolSchemaSource } from "../types/tool.js";
|
|
2
|
+
/** Runtime-only validator paired with the portable JSON Schema projected to models. */
|
|
3
|
+
export interface TurnOutputContract {
|
|
4
|
+
readonly schema: ToolSchema<unknown>;
|
|
5
|
+
}
|
|
6
|
+
export declare function bindOutputContract(source: ToolSchemaSource): TurnOutputContract;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { HarnessError, isHarnessError } from "../errors.js";
|
|
2
|
+
import { normalizeSchema } from "./schema.js";
|
|
3
|
+
export function bindOutputContract(source) {
|
|
4
|
+
try {
|
|
5
|
+
return Object.freeze({ schema: normalizeSchema(source, "output") });
|
|
6
|
+
}
|
|
7
|
+
catch (cause) {
|
|
8
|
+
if (isHarnessError(cause))
|
|
9
|
+
throw new HarnessError("output.invalid-schema", cause.message, { cause });
|
|
10
|
+
throw new HarnessError("output.invalid-schema", String(cause), { cause });
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { defineSchema } from "./schema.js";
|
|
3
|
+
/** Unsupported JSON Schema constructs fail closed during definition loading. */
|
|
4
|
+
export function schemaFromJSON(jsonSchema) {
|
|
5
|
+
const schema = z.fromJSONSchema(jsonSchema);
|
|
6
|
+
return defineSchema({
|
|
7
|
+
jsonSchema,
|
|
8
|
+
validate(value) {
|
|
9
|
+
const result = schema.safeParse(value);
|
|
10
|
+
return result.success
|
|
11
|
+
? { ok: true, value: result.data }
|
|
12
|
+
: {
|
|
13
|
+
ok: false,
|
|
14
|
+
issues: result.error.issues.map((issue) => ({
|
|
15
|
+
path: issue.path.filter((v) => typeof v === "string" || typeof v === "number"),
|
|
16
|
+
code: issue.code,
|
|
17
|
+
message: issue.message,
|
|
18
|
+
})),
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ToolDefinition, ToolSchema, ToolSchemaSource } from "../types/tool.js";
|
|
2
|
+
export type { SchemaValidation } from "../types/tool.js";
|
|
3
|
+
interface NormalizedToolSchemas {
|
|
4
|
+
readonly inputSchema: ToolSchema<unknown>;
|
|
5
|
+
readonly outputSchema?: ToolSchema<unknown>;
|
|
6
|
+
}
|
|
7
|
+
/** Creates a portable, explicitly validated schema source from raw JSON Schema. */
|
|
8
|
+
export declare function defineSchema<T>(value: ToolSchema<T>): ToolSchema<T>;
|
|
9
|
+
/** Eagerly prepares a definition authored through Harness's tool() helper. */
|
|
10
|
+
export declare function prepareTool<T extends ToolDefinition>(definition: T): T;
|
|
11
|
+
/** Resolves `input`/`output`/`run` aliases onto the legacy field names. */
|
|
12
|
+
export declare function normalizeToolDefinition(definition: ToolDefinition): ToolDefinition;
|
|
13
|
+
/** Returns cached normalized contracts, preparing raw definitions on first bind. */
|
|
14
|
+
export declare function normalizedSchemasFor(definition: ToolDefinition): NormalizedToolSchemas;
|
|
15
|
+
/** Converts an accepted tool schema source into Harness's immutable runtime representation. */
|
|
16
|
+
export declare function normalizeSchema<T>(source: ToolSchemaSource<T>, role: "input" | "output"): ToolSchema<T>;
|