@nylorun/core 0.21.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @nylorun/core
2
2
 
3
+ ## 0.22.0-beta
4
+
5
+ ### Minor Changes
6
+
7
+ - a0cf8b2: **HTTP tools take `GET` and `DELETE`, and URL path parameters.**
8
+
9
+ - `method` is `GET`, `POST` (default), `PUT`, `PATCH` or `DELETE`. `POST`, `PUT` and `PATCH` send the input as the JSON body, as before. `GET` and `DELETE` send no body: the input becomes the query string, after any query string written in the URL. An array repeats its name (`tag=a&tag=b`) and a `null` is left out.
10
+ - The URL's path may name input fields as `{field}`, as in `https://api.example.com/orders/{orderId}`. Each value is percent-encoded into the path and is not sent again in the body or query string. A value that is empty, `.` or `..`, or not a string, number or boolean is refused before the call is sent (`tool.invalid-input`).
11
+ - `http()` and the manifest contract check a tool against its input schema. Each `{field}` must be a required scalar property. For `GET` and `DELETE`, a property must not be an object and must not repeat a query parameter the URL already sets.
12
+ - An HTTP verifier still takes only `POST`, `PUT` or `PATCH` and a URL without `{field}` parameters, because it is sent `{ input, output, iteration }` as a body. A credential with `via` cannot serve a tool with `{field}` parameters (`http.credential`).
13
+ - core exports `httpToolRequest`, which maps a call's input to the request, and `httpPathParameters`. The Runtime's outbound `post()` is now `send()`, which can send a request without a body.
14
+
15
+ ### Patch Changes
16
+
17
+ - 620072d: **Docs and schemas match what the CLI and the Runtime do.**
18
+
19
+ - `@nylorun/core`: the environment manifest's JSON Schema (`@nylorun/core/schemas/environment-manifest.json`) takes the CLI's `{ path, from }` `files` entry, so an editor no longer flags a manifest that `nylorun environments manifests save` accepts. The Runtime's own schema is unchanged: the CLI turns the folder into `{ path, files }` before saving. `manifest_changed` says to save without `If-Match` (`--if-match`, `ifMatch`); no command takes `--force`.
20
+ - Tool names, skill names and MCP server names are each unique within their kind, as the builder and the Runtime check; a tool, a skill and a server may share a name. The docs said they were unique across kinds.
21
+ - `harness_mismatch` is described as what it is since protocol 14: an Environment's harness is fixed for its life (fork onto a manifest version to run another), and a session's turn is refused when its Environment id was deleted and made again with another harness, or an Environment changed in place before protocol 14 applies that change.
22
+ - `@nylorun/agents`: the README names `nylorun environments list | delete`, not `nylorun local sandbox ls | rm`.
23
+ - MIGRATION.md no longer offers a tool's `approval`, removed in protocol 11, as a replacement for step middleware.
24
+
3
25
  ## 0.21.0-beta
4
26
 
5
27
  ### Minor Changes
@@ -111,7 +111,7 @@ export type ProtocolFeature = (typeof PROTOCOL_FEATURES)[number];
111
111
  * (`nylorun local sandbox enable`), with `POST /v1/environments/{id}/stop` and `/reset`, lifecycle
112
112
  * events (`environment.running`, `.suspended`, `.relaunched`, `.lost`, `.reset`, `.failed`) and
113
113
  * the Tenant's `placement`.
114
- * `trusted-issuers`: the Tenant API accepts JWTs from the issuers of the Host's identity file
114
+ * `trusted-issuers`: the Runtime API accepts JWTs from the issuers of the Host's identity file
115
115
  * (`NYLORUN_IDENTITY_FILE`) as bearers, from servers and from browsers alike, with the
116
116
  * issuer's subject, scopes (and the issuer-only `studio`), agents and Environment grants; `GET
117
117
  * /v1/me` reports who any credential is.
@@ -200,8 +200,9 @@ export declare const ERROR_CODES: readonly ["not_found",
200
200
  */
201
201
  "environment_owner_mismatch",
202
202
  /**
203
- * The session's Environment now runs another harness than the one the session pinned when it
204
- * opened (track R4): open a new session to run on it.
203
+ * The session's Environment runs another harness than the one the session pinned when it
204
+ * opened (track R4): its id was deleted and made again with another harness, or an
205
+ * Environment changed in place before protocol 14 applied that change. Open a new session.
205
206
  */
206
207
  "harness_mismatch",
207
208
  /**
@@ -265,7 +266,7 @@ export declare const ERROR_CODES: readonly ["not_found",
265
266
  "manifest_in_use",
266
267
  /**
267
268
  * `If-Match` named a version that is no longer the latest (D63): `412`. Read the manifest
268
- * again, or save with `--force` (no `If-Match`).
269
+ * again, or save without `If-Match` (the CLI's `--if-match`, the SDK's `ifMatch`).
269
270
  */
270
271
  "manifest_changed", "internal_error"];
271
272
  export type ErrorCode = (typeof ERROR_CODES)[number];
@@ -113,7 +113,7 @@ export const PROTOCOL_FEATURES = [
113
113
  * (`nylorun local sandbox enable`), with `POST /v1/environments/{id}/stop` and `/reset`, lifecycle
114
114
  * events (`environment.running`, `.suspended`, `.relaunched`, `.lost`, `.reset`, `.failed`) and
115
115
  * the Tenant's `placement`.
116
- * `trusted-issuers`: the Tenant API accepts JWTs from the issuers of the Host's identity file
116
+ * `trusted-issuers`: the Runtime API accepts JWTs from the issuers of the Host's identity file
117
117
  * (`NYLORUN_IDENTITY_FILE`) as bearers, from servers and from browsers alike, with the
118
118
  * issuer's subject, scopes (and the issuer-only `studio`), agents and Environment grants; `GET
119
119
  * /v1/me` reports who any credential is.
@@ -227,8 +227,9 @@ export const ERROR_CODES = [
227
227
  */
228
228
  "environment_owner_mismatch",
229
229
  /**
230
- * The session's Environment now runs another harness than the one the session pinned when it
231
- * opened (track R4): open a new session to run on it.
230
+ * The session's Environment runs another harness than the one the session pinned when it
231
+ * opened (track R4): its id was deleted and made again with another harness, or an
232
+ * Environment changed in place before protocol 14 applied that change. Open a new session.
232
233
  */
233
234
  "harness_mismatch",
234
235
  /**
@@ -292,7 +293,7 @@ export const ERROR_CODES = [
292
293
  "manifest_in_use",
293
294
  /**
294
295
  * `If-Match` named a version that is no longer the latest (D63): `412`. Read the manifest
295
- * again, or save with `--force` (no `If-Match`).
296
+ * again, or save without `If-Match` (the CLI's `--if-match`, the SDK's `ifMatch`).
296
297
  */
297
298
  "manifest_changed",
298
299
  "internal_error",
package/dist/contracts.js CHANGED
@@ -5,7 +5,7 @@ import { REMOVED_MANIFEST_FIELDS, manifestVersionIssue, workflowVersionIssue, }
5
5
  import { RUNTIME_TOOL_NAMES } from "./utils/runtime-tools.js";
6
6
  import { DELEGATE_INPUT_SCHEMA, DELEGATE_NAME_PATTERN } from "./definition/delegate.js";
7
7
  import { stdioMcpRefusal } from "./definition/mcp.js";
8
- import { APPROVAL_MODES, HTTP_TOOL_MAX_TIMEOUT_MS, HTTP_TOOL_METHODS, httpUrlIssue, } from "./definition/http-tool.js";
8
+ import { APPROVAL_MODES, HTTP_TOOL_MAX_TIMEOUT_MS, HTTP_TOOL_METHODS, httpInputIssue, httpUrlIssue, httpUrlTemplateIssue, httpVerifierIssue, } from "./definition/http-tool.js";
9
9
  import { canonical } from "./utils/canonical.js";
10
10
  import { DEFAULT_HARNESS, HARNESS_ID_PATTERN, isHarnessId } from "./utils/harness-id.js";
11
11
  export { DEFAULT_HARNESS, HARNESS_ID_PATTERN, isHarnessId };
@@ -143,7 +143,7 @@ const sandboxManifestSchema = z
143
143
  const httpToolTargetSchema = z
144
144
  .object({
145
145
  url: z.string().superRefine((url, ctx) => {
146
- const issue = httpUrlIssue(url);
146
+ const issue = httpUrlIssue(url) ?? httpUrlTemplateIssue(url);
147
147
  if (issue)
148
148
  ctx.addIssue({ code: "custom", message: issue });
149
149
  }),
@@ -188,6 +188,9 @@ const toolManifestSchema = z
188
188
  path: ["approval"],
189
189
  message: `Tool '${tool.name}' takes approval only as an HTTP tool`,
190
190
  });
191
+ const parameters = tool.http && httpInputIssue(tool.http, tool.inputSchema);
192
+ if (parameters)
193
+ ctx.addIssue({ code: "custom", path: ["http", "url"], message: `Tool '${tool.name}': ${parameters}` });
191
194
  });
192
195
  /** A manifest naming a removed field is refused with what replaces it. */
193
196
  const removedFieldError = (removedFields) => (issue) => {
@@ -350,6 +353,9 @@ const workflowLoopVerifySchema = z
350
353
  });
351
354
  else if (verify.http !== undefined && verify.id !== undefined)
352
355
  ctx.addIssue({ code: "custom", path: ["id"], message: "An HTTP verifier takes no id" });
356
+ const verifier = verify.http && httpVerifierIssue(verify.http);
357
+ if (verifier)
358
+ ctx.addIssue({ code: "custom", path: ["http"], message: verifier });
353
359
  })
354
360
  .meta({ id: "WorkflowLoopVerify" }); // the refinement picks one kind
355
361
  const workflowNodeKinds = z.lazy(() => z.union([
@@ -365,7 +371,12 @@ const workflowNodeKinds = z.lazy(() => z.union([
365
371
  /** An HTTP stage: the Runtime makes the request, as for an agent's HTTP tool. */
366
372
  http: httpToolTargetSchema.optional(),
367
373
  })
368
- .strict(),
374
+ .strict()
375
+ .superRefine((tool, ctx) => {
376
+ const parameters = tool.http && httpInputIssue(tool.http, tool.inputSchema);
377
+ if (parameters)
378
+ ctx.addIssue({ code: "custom", path: ["http", "url"], message: `Tool '${tool.name}': ${parameters}` });
379
+ }),
369
380
  ...workflowNodeOptions,
370
381
  })
371
382
  .strict(),
@@ -721,9 +732,11 @@ export const PutEnvironmentRequestSchema = z
721
732
  /**
722
733
  * The harness that runs the Environment's sessions (track R4): `nylorun` (ours, the default)
723
734
  * or the id of a custom harness. A pod Environment whose harness is not ours runs its
724
- * `image` as the harness: the image's own entrypoint, with nothing copied in. Each session
725
- * pins the harness when it opens; a session whose Environment's harness changed later fails
726
- * its next turn with `harness_mismatch`.
735
+ * `image` as the harness: the image's own entrypoint, with nothing copied in. It is fixed
736
+ * for the Environment's life (protocol 14): to run another harness, fork onto a manifest
737
+ * version that names it. Each session pins the harness when it opens; a session whose
738
+ * Environment id was deleted and made again with another harness fails its next turn with
739
+ * `harness_mismatch`.
727
740
  */
728
741
  harness: HarnessIdSchema.optional(),
729
742
  /**
package/dist/define.d.ts CHANGED
@@ -6,7 +6,7 @@ export type { AgentTool, BuiltAgent } from "./types/agent.js";
6
6
  export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, flowDelegatesOf, flowDelegateManifest, isFlowDelegate, } from "./definition/delegate.js";
7
7
  export type { Delegate } from "./definition/delegate.js";
8
8
  export { tool } from "./definition/helpers.js";
9
- export { APPROVAL_MODES, HTTP_TOOL_DEFAULT_TIMEOUT_MS, HTTP_TOOL_MAX_TIMEOUT_MS, HTTP_TOOL_METHODS, http, httpToolOf, isHttpTarget, withHttpTarget, type HttpTarget, type HttpTool, type HttpToolOptions, } from "./definition/http-tool.js";
9
+ export { APPROVAL_MODES, HTTP_TOOL_DEFAULT_TIMEOUT_MS, HTTP_TOOL_MAX_TIMEOUT_MS, HTTP_TOOL_METHODS, HTTP_BODY_METHODS, http, httpPathParameters, httpToolOf, httpToolRequest, isHttpTarget, withHttpTarget, type HttpTarget, type HttpTool, type HttpToolOptions, type HttpToolRequest, } from "./definition/http-tool.js";
10
10
  export { READ_ARTIFACT_MAX_BYTES, READ_ARTIFACT_TOOL, SAVE_ARTIFACT_TOOL, runtimeManifestFor, runtimeToolOf, type RuntimeManifestOptions, } from "./definition/runtime-manifest.js";
11
11
  export { RUNTIME_PART_ID } from "./definition/manifest.js";
12
12
  export { RUNTIME_TOOL_NAMES, isRuntimeToolName } from "./utils/runtime-tools.js";
package/dist/define.js CHANGED
@@ -2,7 +2,7 @@ export { Agent, AgentBuilder, AgentBuildError, AgentLifecycleError, } from "./de
2
2
  export { HarnessError, isHarnessError } from "./errors.js";
3
3
  export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, flowDelegatesOf, flowDelegateManifest, isFlowDelegate, } from "./definition/delegate.js";
4
4
  export { tool } from "./definition/helpers.js";
5
- export { APPROVAL_MODES, HTTP_TOOL_DEFAULT_TIMEOUT_MS, HTTP_TOOL_MAX_TIMEOUT_MS, HTTP_TOOL_METHODS, http, httpToolOf, isHttpTarget, withHttpTarget, } from "./definition/http-tool.js";
5
+ export { APPROVAL_MODES, HTTP_TOOL_DEFAULT_TIMEOUT_MS, HTTP_TOOL_MAX_TIMEOUT_MS, HTTP_TOOL_METHODS, HTTP_BODY_METHODS, http, httpPathParameters, httpToolOf, httpToolRequest, isHttpTarget, withHttpTarget, } from "./definition/http-tool.js";
6
6
  export { READ_ARTIFACT_MAX_BYTES, READ_ARTIFACT_TOOL, SAVE_ARTIFACT_TOOL, runtimeManifestFor, runtimeToolOf, } from "./definition/runtime-manifest.js";
7
7
  export { RUNTIME_PART_ID } from "./definition/manifest.js";
8
8
  export { RUNTIME_TOOL_NAMES, isRuntimeToolName } from "./utils/runtime-tools.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
  }
@@ -4,7 +4,9 @@
4
4
  * from its `$schema` and a client in another language validates what core enforces. The build
5
5
  * writes them to `dist/schemas/` (`@nylorun/core/schemas/agent-manifest.json` and
6
6
  * `@nylorun/core/schemas/environment-manifest.json`). Both allow a top-level `$schema`, which
7
- * the CLI and SDK drop before they save: the Runtime's own schemas stay strict.
7
+ * the CLI and SDK drop before they save: the Runtime's own schemas stay strict. The environment
8
+ * manifest's `files` also allow the CLI's `{ path, from }`, a folder beside the file that
9
+ * `nylorun environments manifests save` hashes into `{ path, files }`: the Runtime never sees it.
8
10
  */
9
11
  import { z } from "zod";
10
12
  import { AgentManifestSchema, ENVIRONMENT_MANIFEST_SCHEMA_VERSION, EnvironmentManifestSchema, } from "./contracts.js";
@@ -26,7 +28,17 @@ function document(schema, id, title) {
26
28
  }
27
29
  /** The environment manifest's JSON Schema document (draft 2020-12). */
28
30
  export function environmentManifestJsonSchema() {
29
- return document(EnvironmentManifestSchema, `environment-manifest/v${ENVIRONMENT_MANIFEST_SCHEMA_VERSION}`, `Nylorun environment manifest ${ENVIRONMENT_MANIFEST_SCHEMA_VERSION}`);
31
+ const schema = document(EnvironmentManifestSchema, `environment-manifest/v${ENVIRONMENT_MANIFEST_SCHEMA_VERSION}`, `Nylorun environment manifest ${ENVIRONMENT_MANIFEST_SCHEMA_VERSION}`);
32
+ const shapes = schema.properties.files.items.anyOf;
33
+ const tree = shapes.find((shape) => "files" in shape.properties);
34
+ shapes.push({
35
+ type: "object",
36
+ description: "For the CLI only: a folder, relative to this file, that `nylorun environments manifests save` uploads by hash and saves as { path, files }",
37
+ properties: { path: tree?.properties.path, from: { type: "string", minLength: 1 } },
38
+ required: ["path", "from"],
39
+ additionalProperties: false,
40
+ });
41
+ return schema;
30
42
  }
31
43
  /** The agent manifest's JSON Schema document (draft 2020-12). */
32
44
  export function agentManifestJsonSchema() {
@@ -81,9 +81,11 @@
81
81
  "method": {
82
82
  "type": "string",
83
83
  "enum": [
84
+ "GET",
84
85
  "POST",
85
86
  "PUT",
86
- "PATCH"
87
+ "PATCH",
88
+ "DELETE"
87
89
  ]
88
90
  },
89
91
  "credential": {
@@ -389,9 +391,11 @@
389
391
  "method": {
390
392
  "type": "string",
391
393
  "enum": [
394
+ "GET",
392
395
  "POST",
393
396
  "PUT",
394
- "PATCH"
397
+ "PATCH",
398
+ "DELETE"
395
399
  ]
396
400
  },
397
401
  "credential": {
@@ -634,9 +638,11 @@
634
638
  "method": {
635
639
  "type": "string",
636
640
  "enum": [
641
+ "GET",
637
642
  "POST",
638
643
  "PUT",
639
- "PATCH"
644
+ "PATCH",
645
+ "DELETE"
640
646
  ]
641
647
  },
642
648
  "credential": {
@@ -824,9 +830,11 @@
824
830
  "method": {
825
831
  "type": "string",
826
832
  "enum": [
833
+ "GET",
827
834
  "POST",
828
835
  "PUT",
829
- "PATCH"
836
+ "PATCH",
837
+ "DELETE"
830
838
  ]
831
839
  },
832
840
  "credential": {
@@ -157,6 +157,26 @@
157
157
  "files"
158
158
  ],
159
159
  "additionalProperties": false
160
+ },
161
+ {
162
+ "type": "object",
163
+ "description": "For the CLI only: a folder, relative to this file, that `nylorun environments manifests save` uploads by hash and saves as { path, files }",
164
+ "properties": {
165
+ "path": {
166
+ "type": "string",
167
+ "minLength": 1,
168
+ "maxLength": 1024
169
+ },
170
+ "from": {
171
+ "type": "string",
172
+ "minLength": 1
173
+ }
174
+ },
175
+ "required": [
176
+ "path",
177
+ "from"
178
+ ],
179
+ "additionalProperties": false
160
180
  }
161
181
  ]
162
182
  }
@@ -15,14 +15,23 @@ export interface PluginLabel {
15
15
  * Tool Gate holds such a call). New definitions use the Tenant's tool policy instead.
16
16
  */
17
17
  export type ApprovalMode = "never" | "always";
18
- /** The methods an HTTP tool may use: each sends the tool input as a JSON body. */
19
- export type HttpToolMethod = "POST" | "PUT" | "PATCH";
20
18
  /**
21
- * A tool the Runtime runs as one HTTP request through its Tool Gate: the input as a JSON body,
22
- * the answer as the output. A sibling of `agent`; `fn` and `command` are reserved for later kinds.
19
+ * The methods an HTTP tool may use. `POST`, `PUT` and `PATCH` send the tool input as a JSON body;
20
+ * `GET` and `DELETE` send no body and put it in the query string.
21
+ */
22
+ export type HttpToolMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
23
+ /**
24
+ * A tool the Runtime runs as one HTTP request through its Tool Gate: the input's path parameters
25
+ * in the URL, the rest as a JSON body (or, for `GET` and `DELETE`, as the query string), the
26
+ * answer as the output. A sibling of `agent`; `fn` and `command` are reserved for later kinds.
23
27
  */
24
28
  export interface HttpToolTarget {
25
- /** Absolute `http` or `https` URL. */
29
+ /**
30
+ * Absolute `http` or `https` URL. Its path may name input fields as `{field}`, such as
31
+ * `https://api.example.com/orders/{orderId}`: each is a required field of the input schema,
32
+ * sent percent-encoded in its place and not again in the query string or body. A query string
33
+ * in the URL is kept, and the input's fields are added after it.
34
+ */
26
35
  readonly url: string;
27
36
  /** Default `POST`. */
28
37
  readonly method?: HttpToolMethod;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nylorun/core",
3
- "version": "0.21.0-beta",
3
+ "version": "0.22.0-beta",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "description": "Shared agent definitions and wire contracts",