@nylorun/core 0.20.0-beta → 0.22.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.
Files changed (90) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/README.md +2 -2
  3. package/dist/compatibility.d.ts +88 -13
  4. package/dist/compatibility.js +88 -13
  5. package/dist/contracts.d.ts +1328 -110
  6. package/dist/contracts.js +563 -163
  7. package/dist/define.d.ts +15 -13
  8. package/dist/define.js +11 -8
  9. package/dist/definition/approval.js +12 -14
  10. package/dist/definition/assemble.d.ts +6 -10
  11. package/dist/definition/assemble.js +48 -105
  12. package/dist/definition/bind-agent.d.ts +3 -4
  13. package/dist/definition/bind-agent.js +12 -30
  14. package/dist/definition/binding.d.ts +2 -2
  15. package/dist/definition/bound.d.ts +10 -10
  16. package/dist/definition/builder.d.ts +16 -20
  17. package/dist/definition/builder.js +29 -81
  18. package/dist/definition/code-tools.d.ts +3 -3
  19. package/dist/definition/code-tools.js +6 -21
  20. package/dist/definition/declaration.d.ts +4 -7
  21. package/dist/definition/declaration.js +29 -99
  22. package/dist/definition/{tools-capability.d.ts → deferred-tools.d.ts} +3 -13
  23. package/dist/definition/{tools-capability.js → deferred-tools.js} +2 -18
  24. package/dist/definition/delegate.d.ts +2 -4
  25. package/dist/definition/delegate.js +8 -10
  26. package/dist/definition/from.d.ts +7 -4
  27. package/dist/definition/from.js +72 -117
  28. package/dist/definition/helpers.d.ts +0 -7
  29. package/dist/definition/helpers.js +0 -5
  30. package/dist/definition/http-tool.d.ts +49 -5
  31. package/dist/definition/http-tool.js +167 -5
  32. package/dist/definition/implementations.d.ts +6 -8
  33. package/dist/definition/manifest.d.ts +11 -5
  34. package/dist/definition/manifest.js +26 -26
  35. package/dist/definition/mcp.d.ts +1 -52
  36. package/dist/definition/mcp.js +0 -52
  37. package/dist/definition/media-reference.d.ts +23 -0
  38. package/dist/definition/media-reference.js +26 -0
  39. package/dist/definition/removed.d.ts +3 -10
  40. package/dist/definition/removed.js +10 -17
  41. package/dist/definition/runtime-manifest.d.ts +30 -0
  42. package/dist/definition/runtime-manifest.js +132 -0
  43. package/dist/definition/sandbox-tools.d.ts +1 -1
  44. package/dist/definition/sandbox-tools.js +1 -1
  45. package/dist/definition/skill-tools.d.ts +13 -7
  46. package/dist/definition/skill-tools.js +23 -10
  47. package/dist/definition/trace.d.ts +18 -0
  48. package/dist/definition/trace.js +42 -0
  49. package/dist/definition/variant.d.ts +5 -4
  50. package/dist/definition/variant.js +18 -51
  51. package/dist/definition/workflow/runnable.js +1 -1
  52. package/dist/errors.d.ts +1 -1
  53. package/dist/harness-api/entries.d.ts +1 -0
  54. package/dist/harness-api/entries.js +1 -0
  55. package/dist/harness-api/gates.d.ts +1 -6
  56. package/dist/harness-api/gates.js +1 -3
  57. package/dist/harness-api/harness-api.schema.json +11 -92
  58. package/dist/harness-api/index.d.ts +2 -2
  59. package/dist/harness-api/index.js +2 -2
  60. package/dist/harness-api/mcp.d.ts +0 -4
  61. package/dist/harness-api/mcp.js +0 -2
  62. package/dist/harness-api/messages.d.ts +1 -3
  63. package/dist/harness-api/messages.js +1 -3
  64. package/dist/harness-api/schema.d.ts +5 -17
  65. package/dist/harness-api/schema.js +9 -6
  66. package/dist/index.d.ts +1 -1
  67. package/dist/manifest-schemas.d.ts +6 -0
  68. package/dist/manifest-schemas.js +46 -0
  69. package/dist/schemas/agent-manifest.schema.json +905 -0
  70. package/dist/schemas/environment-manifest.schema.json +349 -0
  71. package/dist/types/agent.d.ts +1 -1
  72. package/dist/types/manifest.d.ts +47 -24
  73. package/dist/types/model.d.ts +2 -2
  74. package/dist/types/observe.d.ts +5 -18
  75. package/dist/types/part.d.ts +25 -0
  76. package/dist/types/tool.d.ts +1 -1
  77. package/dist/types/transcript.d.ts +5 -0
  78. package/dist/utils/definition-files.d.ts +11 -6
  79. package/dist/utils/definition-files.js +19 -9
  80. package/dist/utils/runtime-tools.d.ts +19 -0
  81. package/dist/utils/runtime-tools.js +30 -0
  82. package/dist/utils/sandbox.d.ts +1 -1
  83. package/dist/utils/sandbox.js +1 -1
  84. package/package.json +9 -3
  85. package/dist/definition/capability.d.ts +0 -43
  86. package/dist/definition/capability.js +0 -82
  87. package/dist/definition/sandbox-capability.d.ts +0 -44
  88. package/dist/definition/sandbox-capability.js +0 -139
  89. package/dist/types/middleware.d.ts +0 -94
  90. /package/dist/types/{middleware.js → part.js} +0 -0
@@ -3,148 +3,107 @@ import { assembleAgent } from "./assemble.js";
3
3
  import { schemaFromJSON } from "./schema-json.js";
4
4
  import { assertJson, deepFreeze } from "../utils/immutable.js";
5
5
  import { delegateFromManifest, delegateOf } from "./delegate.js";
6
- import { SKILL_TOOL_NAMES } from "./skill-tools.js";
7
6
  import { httpToolFromManifest, httpToolOf } from "./http-tool.js";
7
+ import { RUNTIME_PART_ID } from "./manifest.js";
8
+ import { ToolError } from "./tool-error.js";
8
9
  import { AgentManifestSchema } from "../contracts.js";
9
- /** Tools the engine or the Runtime runs, which need no implementation: agents and HTTP tools. */
10
- const declarative = (tool) => delegateOf(tool) !== undefined || httpToolOf(tool) !== undefined;
11
- /** Rebuild an agent from manifest JSON + in-process implementations (T28). */
10
+ /**
11
+ * Rebuild an agent from its manifest and the code of its tools, by name (T28). Agents used as
12
+ * tools and HTTP tools need no code; neither do the tools in `runtime`, which the Runtime serves.
13
+ * A session tool (`sessionTools`) is offered with the `runtime` part and needs its code.
14
+ */
12
15
  export function agentFrom(json, implementations, options) {
13
16
  const manifest = normalizeManifest(json);
14
17
  const sessionTools = options?.sessionTools ?? [];
15
18
  assertSessionTools(manifest, sessionTools);
16
- const entries = [];
17
- const dynamics = new Map();
18
- for (const capability of manifest.capabilities) {
19
- const impl = implementations[capability.id] ?? {};
20
- const tools = resolveTools(capability, impl.tools);
21
- const owned = sessionTools.filter((item) => item.capabilityId === capability.id);
22
- const instructions = [
23
- ...(capability.instructions ?? []),
24
- ...owned.flatMap((item) => item.instructions ?? []),
25
- ];
26
- const session = owned
27
- .map((item) => {
28
- const live = impl.tools?.[item.name];
29
- if (!live)
30
- throw new HarnessError("agent.build-failed", `Missing session tool implementation '${item.name}' for capability '${capability.id}'`);
31
- return live;
32
- });
33
- const handle = impl.middleware ??
34
- (async (request, next) => {
35
- const advertised = [...tools, ...session];
36
- if (advertised.length)
37
- request.configuration.tools.set(capability.id, advertised.map((tool) => (declarative(tool)
38
- ? tool
39
- : implementations[capability.id]?.tools?.[tool.name]) ?? tool));
40
- if (instructions.length > 0)
41
- request.configuration.instructions.set(capability.id, instructions);
42
- return next();
43
- });
44
- entries.push(Object.freeze({
45
- id: capability.id,
46
- ...(capability.name === undefined ? {} : { name: capability.name }),
47
- ...(capability.description === undefined
19
+ const code = implementations.tools ?? {};
20
+ const parts = [];
21
+ const own = (manifest.tools ?? []).map((declared) => authoredTool(declared, code[declared.name]));
22
+ if (own.length > 0 ||
23
+ manifest.instructions !== undefined ||
24
+ manifest.skills !== undefined ||
25
+ manifest.mcpServers !== undefined)
26
+ parts.push(Object.freeze({
27
+ id: "agent",
28
+ ...(manifest.tools === undefined ? {} : { tools: own }),
29
+ ...(manifest.instructions === undefined ? {} : { instructions: manifest.instructions }),
30
+ ...(manifest.skills === undefined ? {} : { skills: manifest.skills }),
31
+ ...(manifest.mcpServers === undefined ? {} : { mcpServers: manifest.mcpServers }),
32
+ }));
33
+ const runtime = manifest.runtime;
34
+ const session = sessionTools.map((item) => {
35
+ const live = code[item.name];
36
+ if (!live)
37
+ throw new HarnessError("agent.build-failed", `Missing session tool implementation '${item.name}'`);
38
+ return live;
39
+ });
40
+ const sessionInstructions = sessionTools.flatMap((item) => item.instructions ?? []);
41
+ if (runtime !== undefined || session.length > 0)
42
+ parts.push(Object.freeze({
43
+ id: RUNTIME_PART_ID,
44
+ ...(runtime?.tools === undefined
48
45
  ? {}
49
- : { description: capability.description }),
50
- handle,
51
- hasMiddleware: impl.middleware !== undefined,
52
- tools: capability.tools !== undefined
53
- ? tools.map((tool) => {
54
- const live = declarative(tool) ? tool : impl.tools?.[tool.name];
55
- if (!live)
56
- throw new HarnessError("agent.build-failed", `Missing tool implementation '${tool.name}' for capability '${capability.id}'`);
57
- return live;
58
- })
59
- : undefined,
46
+ : { tools: runtime.tools.map((declared) => code[declared.name] ?? runtimeTool(declared)) }),
60
47
  ...(session.length === 0 ? {} : { sessionTools: session }),
61
- contributions: Object.freeze({
62
- ...(capability.instructions
63
- ? { instructions: capability.instructions }
64
- : {}),
65
- ...(capability.tools
66
- ? {
67
- tools: capability.tools.map((tool) => Object.freeze({
68
- name: tool.name,
69
- ...(tool.description === undefined
70
- ? {}
71
- : { description: tool.description }),
72
- })),
73
- }
74
- : {}),
75
- }),
76
- manifestType: capability.type,
77
- ...(capability.metadata === undefined
78
- ? {}
79
- : { metadata: capability.metadata }),
80
- ...(capability.mcpServers === undefined
81
- ? {}
82
- : { mcpServers: capability.mcpServers }),
83
- ...(capability.sandbox === undefined
84
- ? {}
85
- : { sandbox: capability.sandbox }),
86
- ...(capability.skills === undefined
87
- ? {}
88
- : { skills: capability.skills }),
48
+ ...(runtime?.instructions === undefined ? {} : { instructions: runtime.instructions }),
49
+ ...(sessionInstructions.length === 0 ? {} : { sessionInstructions }),
89
50
  }));
90
- dynamics.set(capability.id, impl.middleware ? { middleware: impl.middleware } : {});
91
- }
92
51
  const outputSchema = manifest.outputSchema
93
52
  ? schemaFromJSON(manifest.outputSchema)
94
53
  : undefined;
95
- const result = assembleAgent(entries, {
54
+ const result = assembleAgent(parts, {
96
55
  id: manifest.id,
97
56
  name: manifest.name,
98
57
  description: manifest.description,
99
58
  metadata: manifest.metadata,
100
59
  outputSchema,
60
+ ...(manifest.requires === undefined ? {} : { requires: manifest.requires }),
101
61
  runtime: manifest.runtime,
102
- manifestSchemaVersion: manifest.manifestSchemaVersion,
103
- }, dynamics);
62
+ });
104
63
  if (!result.ok)
105
64
  throw new HarnessError("agent.build-failed", result.diagnostics.map((item) => item.message).join("; "));
106
65
  return result.agent;
107
66
  }
108
67
  function assertSessionTools(manifest, sessionTools) {
68
+ const taken = new Set([
69
+ ...(manifest.tools ?? []).map((tool) => tool.name),
70
+ ...(manifest.runtime?.tools ?? []).map((tool) => tool.name),
71
+ ]);
109
72
  const seen = new Set();
110
73
  for (const item of sessionTools) {
111
74
  if (seen.has(item.name))
112
75
  throw new HarnessError("agent.build-failed", `Duplicate session tool '${item.name}'`);
113
76
  seen.add(item.name);
114
- const capability = manifest.capabilities.find((entry) => entry.id === item.capabilityId);
115
- if (!capability)
116
- throw new HarnessError("agent.build-failed", `Session tool '${item.name}' references unknown capability '${item.capabilityId}'`);
117
- if (capability.tools?.some((tool) => tool.name === item.name))
77
+ if (taken.has(item.name))
118
78
  throw new HarnessError("agent.build-failed", `Session tool '${item.name}' collides with a declared tool`);
119
79
  }
120
80
  }
121
- function resolveTools(capability, tools) {
122
- if (!capability.tools?.length)
123
- return [];
124
- return capability.tools.flatMap((declared) => {
125
- const live = tools?.[declared.name];
126
- // The engine runs agents used as tools; an authored delegate keeps its local child.
127
- if (declared.agent)
128
- return [
129
- live && delegateOf(live)?.manifest.id === declared.agent.id
130
- ? live
131
- : delegateFromManifest(declared.agent, declared),
132
- ];
133
- // The Runtime runs HTTP tools; a host's own (its engine's routing) is kept.
134
- if (declared.http)
135
- return [
136
- live && httpToolOf(live)
137
- ? live
138
- : httpToolFromManifest({ ...declared, http: declared.http }),
139
- ];
140
- if (live)
141
- return [live];
142
- // The build attaches the skill tools again; the Runtime serves them.
143
- if (SKILL_TOOL_NAMES.has(declared.name) &&
144
- capability.skills &&
145
- Object.keys(capability.skills).length > 0)
146
- return [];
147
- throw new HarnessError("agent.build-failed", `Missing tool implementation '${declared.name}' for capability '${capability.id}'`);
81
+ /**
82
+ * An authored tool: the engine runs agents used as tools (an authored delegate keeps its local
83
+ * child), the Runtime runs HTTP tools (a host's own keeps its routing), and any other tool is the
84
+ * caller's code.
85
+ */
86
+ function authoredTool(declared, live) {
87
+ if (declared.agent)
88
+ return live && delegateOf(live)?.manifest.id === declared.agent.id
89
+ ? live
90
+ : delegateFromManifest(declared.agent, declared);
91
+ if (declared.http)
92
+ return live && httpToolOf(live) ? live : httpToolFromManifest({ ...declared, http: declared.http });
93
+ if (live)
94
+ return live;
95
+ throw new HarnessError("agent.build-failed", `Missing tool implementation '${declared.name}'`);
96
+ }
97
+ /** A tool the Runtime serves, as a process without a Runtime sees it: calling it says so. */
98
+ function runtimeTool(declared) {
99
+ return Object.freeze({
100
+ name: declared.name,
101
+ ...(declared.description === undefined ? {} : { description: declared.description }),
102
+ inputSchema: schemaFromJSON(declared.inputSchema),
103
+ ...(declared.outputSchema === undefined ? {} : { outputSchema: schemaFromJSON(declared.outputSchema) }),
104
+ async execute() {
105
+ throw new ToolError("tool.runtime-only", `'${declared.name}' runs in the Nylorun Runtime. Connect the agent to a Runtime to use it.`);
106
+ },
148
107
  });
149
108
  }
150
109
  /**
@@ -163,11 +122,7 @@ function normalizeManifest(json) {
163
122
  .join("; "));
164
123
  // The schema checks no value of a JSON object; metadata must be JSON data, as before.
165
124
  const manifest = parsed.data;
166
- for (const metadata of [
167
- manifest.metadata,
168
- ...manifest.capabilities.map((capability) => capability.metadata),
169
- ])
170
- if (metadata !== undefined)
171
- assertJson(metadata, "metadata");
125
+ if (manifest.metadata !== undefined)
126
+ assertJson(manifest.metadata, "metadata");
172
127
  return deepFreeze(JSON.parse(JSON.stringify(manifest)));
173
128
  }
@@ -1,10 +1,3 @@
1
- import type { ModelAdapter } from "../types/model.js";
2
- import type { StepMiddleware } from "../types/middleware.js";
3
1
  import type { ToolDefinition, ToolInputSchema, ToolOutputSchema, ToolSchemaSource } from "../types/tool.js";
4
2
  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 Runs in the local engine only. Kept through 1.0. */
8
- export declare const middleware: <T extends StepMiddleware>(value: T) => T;
9
- export { capability } from "./capability.js";
10
3
  export type { ToolSchemaSource };
@@ -1,7 +1,2 @@
1
1
  import { prepareTool } from "./schema.js";
2
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 Runs in the local engine only. Kept through 1.0. */
6
- export const middleware = (value) => value;
7
- export { capability } from "./capability.js";
@@ -5,12 +5,19 @@
5
5
  * a person is the Tenant's tool policy, decided at the Tool Gate (R5 step 2), never the tool's.
6
6
  * An HTTP tool is also a flow stage. `http({ url })` without a name and an input is a bare
7
7
  * target, a Loop's HTTP verifier: its manifest form is itself, `{ http: { url, … } }`.
8
+ *
9
+ * How a call's input becomes the request (`httpToolRequest`) is decided here, so every Runtime
10
+ * and every check agree: the fields the URL's path names as `{field}` fill it, percent-encoded;
11
+ * the rest are the JSON body for `POST`, `PUT` and `PATCH`, and the query string for `GET` and
12
+ * `DELETE`, which send no body.
8
13
  */
9
- import type { ApprovalMode, HttpToolTarget, ToolManifest } from "../types/manifest.js";
14
+ import type { ApprovalMode, HttpToolMethod, HttpToolTarget, ToolManifest } from "../types/manifest.js";
10
15
  import type { JsonObject } from "../types/shared.js";
11
16
  import type { ToolDefinition, ToolInputSchema, ToolOutputSchema } from "../types/tool.js";
12
17
  type AnyTool = ToolDefinition<any, any, any>;
13
- export declare const HTTP_TOOL_METHODS: readonly ["POST", "PUT", "PATCH"];
18
+ export declare const HTTP_TOOL_METHODS: readonly ["GET", "POST", "PUT", "PATCH", "DELETE"];
19
+ /** The methods that send the input as a JSON body; the others send it as the query string. */
20
+ export declare const HTTP_BODY_METHODS: readonly ["POST", "PUT", "PATCH"];
14
21
  export declare const APPROVAL_MODES: readonly ["never", "always"];
15
22
  /** How long a service may take to answer when the tool sets no `timeoutMs`. */
16
23
  export declare const HTTP_TOOL_DEFAULT_TIMEOUT_MS = 60000;
@@ -39,9 +46,10 @@ export interface HttpTarget {
39
46
  readonly http: HttpToolTarget;
40
47
  }
41
48
  /**
42
- * A tool the Runtime runs as an HTTP request: it sends the input as JSON to `url` and gives
43
- * the model the answer. Use it in `.tools(...)` like any tool, or as a flow stage; it has no
44
- * implementation.
49
+ * A tool the Runtime runs as an HTTP request to `url` with `method` (default `POST`): the input
50
+ * fields the URL's path names as `{field}` fill it, and the rest are the JSON body (`POST`, `PUT`,
51
+ * `PATCH`) or the query string (`GET`, `DELETE`). The model gets the answer. Use it in
52
+ * `.tools(...)` like any tool, or as a flow stage; it has no implementation.
45
53
  */
46
54
  export declare function http<InputSchema extends ToolInputSchema | JsonObject, OutputSchema extends ToolOutputSchema | JsonObject | undefined = undefined>(options: HttpToolOptions<InputSchema, OutputSchema>): AnyTool;
47
55
  /**
@@ -66,4 +74,40 @@ export declare function httpToolOf(tool: unknown): HttpTool | undefined;
66
74
  export declare function httpTargetIssue(target: HttpToolTarget): string | undefined;
67
75
  /** Why `url` is not an HTTP tool's URL, or undefined. */
68
76
  export declare function httpUrlIssue(url: unknown): string | undefined;
77
+ /** The input fields an HTTP target's URL names in its path as `{field}`, in order. */
78
+ export declare function httpPathParameters(url: string): string[];
79
+ /**
80
+ * Why the `{field}` parameters of an absolute http(s) `url` are malformed, or undefined: each is
81
+ * a field name, named once, in the path (never the host or the query string).
82
+ */
83
+ export declare function httpUrlTemplateIssue(url: string): string | undefined;
84
+ /**
85
+ * Why `target` cannot be a Loop's HTTP verifier, or undefined: the Runtime sends a verifier
86
+ * `{ input, output, iteration }` as a JSON body, so it takes a body method and no URL parameters.
87
+ */
88
+ export declare function httpVerifierIssue(target: HttpToolTarget): string | undefined;
89
+ /**
90
+ * Why an HTTP tool's `inputSchema` does not fit its target, or undefined. Each `{field}` its URL
91
+ * names is a required property of the input, and not an object or an array, so the model always
92
+ * has one value to put there. For `GET` and `DELETE`, which send the other fields as the query
93
+ * string, no field is an object, and none is a query parameter the URL already fixes.
94
+ */
95
+ export declare function httpInputIssue(target: HttpToolTarget, inputSchema: JsonObject | undefined): string | undefined;
96
+ /** The request one call of an HTTP target makes, or why its input cannot make one. */
97
+ export type HttpToolRequest = {
98
+ readonly url: string;
99
+ readonly method: HttpToolMethod;
100
+ /** The JSON body, for `POST`, `PUT` and `PATCH`; `GET` and `DELETE` send none. */
101
+ readonly body?: string;
102
+ } | {
103
+ readonly issue: string;
104
+ };
105
+ /**
106
+ * The request a call of `target` with `input` makes. The fields the URL's path names fill it,
107
+ * each percent-encoded as one path segment; the other fields are the JSON body for a body
108
+ * method, and the query string, after the URL's own, for `GET` and `DELETE`. In the query
109
+ * string an array repeats its name (`tag=a&tag=b`), a `null` is left out, and an object is
110
+ * refused. A body-method target without URL parameters sends the input as it is.
111
+ */
112
+ export declare function httpToolRequest(target: HttpToolTarget, input: unknown): HttpToolRequest;
69
113
  export {};
@@ -1,12 +1,14 @@
1
1
  import { APPROVAL_REMOVED } from "./approval.js";
2
2
  import { HarnessError } from "../errors.js";
3
3
  import { ToolError } from "./tool-error.js";
4
- import { prepareTool } from "./schema.js";
4
+ import { normalizedSchemasFor, prepareTool } from "./schema.js";
5
5
  import { schemaFromJSON } from "./schema-json.js";
6
6
  /** Survives duplicate installed copies of core, like the delegate brand. */
7
7
  const HTTP = Symbol.for("@nylorun/core/http-tool");
8
8
  const TARGET = Symbol.for("@nylorun/core/http-target");
9
- export const HTTP_TOOL_METHODS = ["POST", "PUT", "PATCH"];
9
+ export const HTTP_TOOL_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"];
10
+ /** The methods that send the input as a JSON body; the others send it as the query string. */
11
+ export const HTTP_BODY_METHODS = ["POST", "PUT", "PATCH"];
10
12
  export const APPROVAL_MODES = ["never", "always"];
11
13
  /** How long a service may take to answer when the tool sets no `timeoutMs`. */
12
14
  export const HTTP_TOOL_DEFAULT_TIMEOUT_MS = 60_000;
@@ -22,12 +24,16 @@ export function http(options) {
22
24
  ("approval" in options ? APPROVAL_REMOVED : undefined);
23
25
  if (issue)
24
26
  throw new HarnessError("tool.invalid", `HTTP tool '${name}': ${issue}`);
25
- return prepareTool(withHttpTarget({
27
+ const tool = prepareTool(withHttpTarget({
26
28
  name,
27
29
  ...(description === undefined ? {} : { description }),
28
30
  inputSchema: schemaSource(input),
29
31
  ...(output === undefined ? {} : { outputSchema: schemaSource(output) }),
30
32
  }, { http: target }));
33
+ const parameters = httpInputIssue(target, normalizedSchemasFor(tool).inputSchema.jsonSchema);
34
+ if (parameters)
35
+ throw new HarnessError("tool.invalid", `HTTP tool '${name}': ${parameters}`);
36
+ return tool;
31
37
  }
32
38
  function targetOf({ url, method, credential, timeoutMs }) {
33
39
  return {
@@ -43,7 +49,7 @@ function httpTarget(options) {
43
49
  if (unknown.length > 0)
44
50
  throw new HarnessError("configuration.invalid", `HTTP verifier: unknown option${unknown.length === 1 ? "" : "s"} ${unknown.join(", ")}; an HTTP tool needs a name and an input`);
45
51
  const target = targetOf(options);
46
- const issue = httpTargetIssue(target);
52
+ const issue = httpTargetIssue(target) ?? httpVerifierIssue(target);
47
53
  if (issue)
48
54
  throw new HarnessError("configuration.invalid", `HTTP verifier: ${issue}`);
49
55
  const value = { http: Object.freeze(target) };
@@ -87,7 +93,7 @@ export function httpToolOf(tool) {
87
93
  }
88
94
  /** Why `target` is not a valid HTTP tool target, or undefined. */
89
95
  export function httpTargetIssue(target) {
90
- const url = httpUrlIssue(target.url);
96
+ const url = httpUrlIssue(target.url) ?? httpUrlTemplateIssue(target.url);
91
97
  if (url)
92
98
  return url;
93
99
  if (target.method !== undefined && !HTTP_TOOL_METHODS.includes(target.method))
@@ -116,6 +122,162 @@ export function httpUrlIssue(url) {
116
122
  return "url must not have a fragment";
117
123
  return undefined;
118
124
  }
125
+ const PLACEHOLDER = /\{([^{}]*)\}/g;
126
+ const FIELD_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
127
+ /** The input fields an HTTP target's URL names in its path as `{field}`, in order. */
128
+ export function httpPathParameters(url) {
129
+ return [...url.matchAll(PLACEHOLDER)].map((match) => match[1]);
130
+ }
131
+ /**
132
+ * Why the `{field}` parameters of an absolute http(s) `url` are malformed, or undefined: each is
133
+ * a field name, named once, in the path (never the host or the query string).
134
+ */
135
+ export function httpUrlTemplateIssue(url) {
136
+ if (!/[{}]/.test(url))
137
+ return undefined;
138
+ if (/[{}]/.test(url.replace(PLACEHOLDER, "")))
139
+ return "url has an unmatched { or }";
140
+ const scheme = url.indexOf("://");
141
+ if (scheme === -1)
142
+ return "url must be an absolute http or https URL";
143
+ const authority = scheme + 3;
144
+ const query = url.indexOf("?", authority);
145
+ const end = query === -1 ? url.length : query;
146
+ const path = url.indexOf("/", authority);
147
+ const seen = new Set();
148
+ for (const match of url.matchAll(PLACEHOLDER)) {
149
+ const name = match[1];
150
+ if (path === -1 || match.index < path || match.index >= end)
151
+ return "url may name input fields as {field} only in its path";
152
+ if (!FIELD_NAME.test(name))
153
+ return `url parameter {${name}} must be an input field name`;
154
+ if (seen.has(name))
155
+ return `url names {${name}} twice`;
156
+ seen.add(name);
157
+ }
158
+ return undefined;
159
+ }
160
+ /**
161
+ * Why `target` cannot be a Loop's HTTP verifier, or undefined: the Runtime sends a verifier
162
+ * `{ input, output, iteration }` as a JSON body, so it takes a body method and no URL parameters.
163
+ */
164
+ export function httpVerifierIssue(target) {
165
+ if (target.method !== undefined && !HTTP_BODY_METHODS.includes(target.method))
166
+ return `an HTTP verifier is sent a JSON body: method must be one of ${HTTP_BODY_METHODS.join(", ")}`;
167
+ if (httpPathParameters(target.url).length > 0)
168
+ return "an HTTP verifier's url takes no {field} parameters";
169
+ return undefined;
170
+ }
171
+ /**
172
+ * Why an HTTP tool's `inputSchema` does not fit its target, or undefined. Each `{field}` its URL
173
+ * names is a required property of the input, and not an object or an array, so the model always
174
+ * has one value to put there. For `GET` and `DELETE`, which send the other fields as the query
175
+ * string, no field is an object, and none is a query parameter the URL already fixes.
176
+ */
177
+ export function httpInputIssue(target, inputSchema) {
178
+ // A malformed URL reports its own issue.
179
+ if (inputSchema === undefined || httpUrlTemplateIssue(target.url))
180
+ return undefined;
181
+ const properties = (inputSchema.properties && typeof inputSchema.properties === "object" ? inputSchema.properties : {});
182
+ const required = Array.isArray(inputSchema.required) ? inputSchema.required : [];
183
+ const names = httpPathParameters(target.url);
184
+ for (const name of names) {
185
+ if (!Object.hasOwn(properties, name))
186
+ return `url names {${name}}, which is not a property of the input schema`;
187
+ if (!required.includes(name))
188
+ return `url names {${name}}, which the input schema must list as required`;
189
+ if (typesOf(properties[name]).some((type) => type === "object" || type === "array"))
190
+ return `url names {${name}}, which must be a string, a number or a boolean`;
191
+ }
192
+ if (HTTP_BODY_METHODS.includes(target.method ?? "POST"))
193
+ return undefined;
194
+ let fixed;
195
+ try {
196
+ fixed = new URL(target.url.replace(PLACEHOLDER, "x")).searchParams;
197
+ }
198
+ catch {
199
+ return undefined; // the URL's own issue is reported
200
+ }
201
+ for (const [name, property] of Object.entries(properties)) {
202
+ if (names.includes(name))
203
+ continue;
204
+ if (fixed.has(name))
205
+ return `'${name}' is both an input field and a query parameter the url fixes`;
206
+ const types = typesOf(property);
207
+ const items = types.includes("array") ? typesOf(property.items) : [];
208
+ if (types.includes("object") || items.includes("object") || items.includes("array"))
209
+ return `'${name}' is sent in the query string by ${target.method}, so it must not be an object or hold objects`;
210
+ }
211
+ return undefined;
212
+ }
213
+ /** The JSON Schema `type`s a property declares, if any. */
214
+ function typesOf(schema) {
215
+ const type = schema && typeof schema === "object" ? schema.type : undefined;
216
+ return typeof type === "string" ? [type] : Array.isArray(type) ? type.filter((t) => typeof t === "string") : [];
217
+ }
218
+ /**
219
+ * The request a call of `target` with `input` makes. The fields the URL's path names fill it,
220
+ * each percent-encoded as one path segment; the other fields are the JSON body for a body
221
+ * method, and the query string, after the URL's own, for `GET` and `DELETE`. In the query
222
+ * string an array repeats its name (`tag=a&tag=b`), a `null` is left out, and an object is
223
+ * refused. A body-method target without URL parameters sends the input as it is.
224
+ */
225
+ export function httpToolRequest(target, input) {
226
+ const method = target.method ?? "POST";
227
+ const hasBody = HTTP_BODY_METHODS.includes(method);
228
+ const names = httpPathParameters(target.url);
229
+ if (hasBody && names.length === 0)
230
+ return { url: target.url, method, body: JSON.stringify(input ?? {}) };
231
+ const fields = input ?? {};
232
+ if (typeof fields !== "object" || Array.isArray(fields))
233
+ return { issue: "The tool input must be an object" };
234
+ const rest = { ...fields };
235
+ let url = target.url;
236
+ for (const name of names) {
237
+ const segment = pathSegment(rest[name]);
238
+ if (segment === undefined)
239
+ return {
240
+ issue: `'${name}' must be a non-empty string, a number or a boolean, and not . or ..: it fills {${name}} in the URL`,
241
+ };
242
+ delete rest[name];
243
+ url = url.replace(`{${name}}`, () => segment);
244
+ }
245
+ if (hasBody)
246
+ return { url, method, body: JSON.stringify(rest) };
247
+ const query = queryString(rest);
248
+ if (typeof query !== "string")
249
+ return query;
250
+ if (query === "")
251
+ return { url, method };
252
+ const joiner = !url.includes("?") ? "?" : url.endsWith("?") || url.endsWith("&") ? "" : "&";
253
+ return { url: `${url}${joiner}${query}`, method };
254
+ }
255
+ /** `value` as one percent-encoded path segment, or undefined when it cannot be one. */
256
+ function pathSegment(value) {
257
+ if (typeof value === "number" && !Number.isFinite(value))
258
+ return undefined;
259
+ if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean")
260
+ return undefined;
261
+ const text = String(value);
262
+ // `.` and `..` are not encoded, and would move the request to another path. Side by side,
263
+ // `{a}{b}` or `.{a}`, a `..` segment needs one value to be `.`, so this check covers them too.
264
+ if (text === "" || text === "." || text === "..")
265
+ return undefined;
266
+ return encodeURIComponent(text);
267
+ }
268
+ /** `fields` as a query string, in their order, without a leading `?`; an object cannot be one. */
269
+ function queryString(fields) {
270
+ const pairs = [];
271
+ for (const [name, value] of Object.entries(fields))
272
+ for (const item of Array.isArray(value) ? value : [value]) {
273
+ if (item === null || item === undefined)
274
+ continue;
275
+ if (typeof item === "object")
276
+ return { issue: `'${name}' is sent in the query string, so it must not be an object or hold objects` };
277
+ pairs.push(`${encodeURIComponent(name)}=${encodeURIComponent(String(item))}`);
278
+ }
279
+ return pairs.join("&");
280
+ }
119
281
  async function runtimeOnly() {
120
282
  throw new ToolError("http.runtime-only", "HTTP tools are run by the Nylorun Runtime, not in this process");
121
283
  }
@@ -1,13 +1,11 @@
1
1
  import type { ToolDefinition } from "../types/tool.js";
2
- import type { StepMiddleware } from "../types/middleware.js";
3
- /** In-process implementations table keyed by capability id (never serialized). */
2
+ /**
3
+ * The code of an agent's tools, by tool name, for `Agent.from(manifest, implementations)` (never
4
+ * serialized). Agents used as tools, HTTP tools and the Runtime's tools need none.
5
+ */
4
6
  export interface Implementations<Info = unknown> {
5
- readonly [capabilityId: string]: {
6
- readonly tools?: {
7
- readonly [toolName: string]: ToolDefinition<any, Info, any>;
8
- };
9
- /** @deprecated Local engine only through 1.0. */
10
- readonly middleware?: StepMiddleware<Info>;
7
+ readonly tools?: {
8
+ readonly [toolName: string]: ToolDefinition<any, Info, any>;
11
9
  };
12
10
  }
13
11
  export declare function emptyImplementations(): Implementations;
@@ -1,15 +1,21 @@
1
- import type { BoundMiddleware } from "./bound.js";
2
- import type { AgentManifest, ManifestSchemaVersion, RuntimeManifest } from "../types/manifest.js";
1
+ import type { DefinitionPart } from "./bound.js";
2
+ import type { AgentManifest, AgentRequirements, RuntimeManifest } from "../types/manifest.js";
3
3
  import type { JsonObject } from "../types/shared.js";
4
4
  import type { ToolSchemaSource } from "../types/tool.js";
5
+ /** The id of the part an agent rebuilt from a pinned manifest gets for its `runtime` block. */
6
+ export declare const RUNTIME_PART_ID = "runtime";
7
+ /**
8
+ * The agent's manifest (v7): its parts merged in order, the instructions and tools concatenated,
9
+ * the skills and servers keyed by name. The `runtime` part is not projected: `runtime` comes as
10
+ * it was pinned.
11
+ */
5
12
  export declare function createManifest(input: {
6
13
  id: string;
7
14
  name?: string;
8
15
  description?: string;
9
16
  metadata?: JsonObject;
10
17
  outputSchema?: ToolSchemaSource;
18
+ requires?: AgentRequirements;
11
19
  runtime?: RuntimeManifest;
12
- middleware: readonly BoundMiddleware[];
13
- /** The version a manifest rebuilt from JSON had; it never goes below what the capabilities need. */
14
- manifestSchemaVersion?: ManifestSchemaVersion;
20
+ parts: readonly DefinitionPart[];
15
21
  }): AgentManifest;