@nylorun/core 0.21.0-beta → 0.23.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 (74) hide show
  1. package/CHANGELOG.md +124 -0
  2. package/README.md +1 -1
  3. package/dist/compatibility.d.ts +37 -20
  4. package/dist/compatibility.js +38 -21
  5. package/dist/contracts.d.ts +531 -88
  6. package/dist/contracts.js +315 -204
  7. package/dist/define.d.ts +8 -12
  8. package/dist/define.js +7 -11
  9. package/dist/definition/assemble.d.ts +1 -3
  10. package/dist/definition/assemble.js +4 -8
  11. package/dist/definition/bound.d.ts +1 -1
  12. package/dist/definition/delegate.d.ts +5 -0
  13. package/dist/definition/delegate.js +6 -1
  14. package/dist/definition/from.d.ts +4 -2
  15. package/dist/definition/from.js +11 -29
  16. package/dist/definition/http-tool.d.ts +54 -8
  17. package/dist/definition/http-tool.js +175 -10
  18. package/dist/definition/manifest.d.ts +7 -6
  19. package/dist/definition/manifest.js +7 -6
  20. package/dist/definition/mcp.d.ts +1 -1
  21. package/dist/definition/media-reference.d.ts +2 -11
  22. package/dist/definition/media-reference.js +0 -12
  23. package/dist/definition/model-failure.js +1 -0
  24. package/dist/definition/removed.js +1 -0
  25. package/dist/definition/trace.d.ts +0 -7
  26. package/dist/definition/trace.js +0 -34
  27. package/dist/definition/variant.d.ts +1 -1
  28. package/dist/definition/variant.js +1 -3
  29. package/dist/harness-api/artifacts.d.ts +84 -0
  30. package/dist/harness-api/artifacts.js +128 -0
  31. package/dist/harness-api/gates.d.ts +0 -4
  32. package/dist/harness-api/gates.js +0 -4
  33. package/dist/harness-api/harness-api.schema.json +2422 -924
  34. package/dist/harness-api/index.d.ts +9 -6
  35. package/dist/harness-api/index.js +9 -6
  36. package/dist/harness-api/json-schema.js +5 -2
  37. package/dist/harness-api/mcp.d.ts +77 -30
  38. package/dist/harness-api/mcp.js +42 -25
  39. package/dist/harness-api/messages.d.ts +45 -17
  40. package/dist/harness-api/messages.js +20 -5
  41. package/dist/harness-api/schema.d.ts +538 -198
  42. package/dist/harness-api/schema.js +298 -59
  43. package/dist/harness-api/transcript.d.ts +8 -10
  44. package/dist/harness-api/transcript.js +27 -11
  45. package/dist/harness-api/transport.d.ts +7 -1
  46. package/dist/harness-api/transport.js +10 -7
  47. package/dist/manifest-schemas.js +14 -2
  48. package/dist/schemas/agent-manifest.schema.json +14 -147
  49. package/dist/schemas/environment-manifest.schema.json +76 -16
  50. package/dist/types/manifest.d.ts +17 -18
  51. package/dist/types/model.d.ts +10 -5
  52. package/dist/utils/definition-files.d.ts +20 -6
  53. package/dist/utils/definition-files.js +31 -17
  54. package/dist/utils/file-systems.d.ts +20 -0
  55. package/dist/utils/file-systems.js +20 -0
  56. package/dist/utils/harness-id.d.ts +4 -1
  57. package/dist/utils/harness-id.js +4 -1
  58. package/dist/utils/media-types.d.ts +30 -0
  59. package/dist/utils/media-types.js +128 -0
  60. package/dist/utils/runtime-limits.d.ts +229 -0
  61. package/dist/utils/runtime-limits.js +482 -0
  62. package/dist/utils/runtime-tools.d.ts +8 -16
  63. package/dist/utils/runtime-tools.js +8 -27
  64. package/dist/utils/sandbox.d.ts +4 -1
  65. package/dist/utils/sandbox.js +4 -1
  66. package/package.json +1 -1
  67. package/dist/definition/deferred-tools.d.ts +0 -27
  68. package/dist/definition/deferred-tools.js +0 -82
  69. package/dist/definition/runtime-manifest.d.ts +0 -30
  70. package/dist/definition/runtime-manifest.js +0 -132
  71. package/dist/definition/sandbox-tools.d.ts +0 -5
  72. package/dist/definition/sandbox-tools.js +0 -109
  73. package/dist/definition/skill-tools.d.ts +0 -23
  74. package/dist/definition/skill-tools.js +0 -76
package/dist/define.d.ts CHANGED
@@ -3,17 +3,15 @@ export type { AgentOptions } from "./definition/builder.js";
3
3
  export { HarnessError, isHarnessError } from "./errors.js";
4
4
  export type { HarnessErrorCode, HarnessErrorDetails, HarnessErrorOptions, } from "./errors.js";
5
5
  export type { AgentTool, BuiltAgent } from "./types/agent.js";
6
- export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, flowDelegatesOf, flowDelegateManifest, isFlowDelegate, } from "./definition/delegate.js";
6
+ export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, flowDelegatesOf, flowDelegateManifest, isFlowDelegate, MODEL_TOOL_NAME_MAX, } 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";
10
- export { READ_ARTIFACT_MAX_BYTES, READ_ARTIFACT_TOOL, SAVE_ARTIFACT_TOOL, runtimeManifestFor, runtimeToolOf, type RuntimeManifestOptions, } from "./definition/runtime-manifest.js";
11
- export { RUNTIME_PART_ID } from "./definition/manifest.js";
12
- export { RUNTIME_TOOL_NAMES, isRuntimeToolName } from "./utils/runtime-tools.js";
9
+ export { APPROVAL_MODES, HTTP_TOOL_DEFAULT_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
+ export { SESSION_PART_ID } from "./definition/manifest.js";
11
+ export { READ_ARTIFACT_TOOL, SAVE_ARTIFACT_TOOL, } from "./utils/runtime-tools.js";
13
12
  export { MCP_TOOL_DEFAULTS, mcpToolSettings, McpError, normalizeMcpServers, stdioMcpRefusal, } from "./definition/mcp.js";
14
- export { SERVER_INSTRUCTIONS_MAX_CHARS, TOOL_CALL_TOOL, TOOL_SEARCH_DEFAULT_LIMIT, TOOL_SEARCH_MAX_LIMIT, TOOL_SEARCH_TOOL, deferredToolsInstructions, deferredToolsTools, type DeferredServerNote, } from "./definition/deferred-tools.js";
15
13
  export { codeToolRefusal, codeToolsOf } from "./definition/code-tools.js";
16
- export { pluginOf, skillOfToolCall, type ToolCallTrace } from "./definition/trace.js";
14
+ export { pluginOf, type ToolCallTrace } from "./definition/trace.js";
17
15
  export { approvalRefusal, approvalsOf } from "./definition/approval.js";
18
16
  export type { CodeTool } from "./definition/code-tools.js";
19
17
  export { flow, FlowBuilder, isFlowBuilder, ROOT_POSITION, childPosition, embeddedAgent, flowHttpTarget, forEachFlowNode, indexSuffix, isLeafNode, isWorkflowManifest, leafPart, leafPath, stageKey, stripIndices, } from "./definition/flow/index.js";
@@ -23,13 +21,11 @@ export { ToolError, isToolError } from "./definition/tool-error.js";
23
21
  export { defineSchema } from "./definition/schema.js";
24
22
  export { hashManifest } from "./utils/hash.js";
25
23
  export { MODEL_FAILURE_CODES, isModelFailureOutcome } from "./definition/model-failure.js";
26
- export { createSandboxTools, SANDBOX_INSTRUCTIONS, } from "./definition/sandbox-tools.js";
27
24
  export { SANDBOX_NETWORK_PRESETS, SANDBOX_TOOL_NAMES, SANDBOX_WORKSPACE, isSandboxHostPattern, isSandboxToolName, parseSandboxDuration, parseSandboxSize, } from "./utils/sandbox.js";
28
25
  export type { SandboxToolName } from "./utils/sandbox.js";
29
- export { LOAD_SKILL_TOOL, READ_SKILL_RESOURCE_TOOL, SKILL_TOOL_NAMES, isSkillTool, SKILLS_USAGE, formatSkillCatalog, } from "./definition/skill-tools.js";
30
- export { DEFINITION_FILE_MAX_BYTES, SKILL_ENTRY, SKILL_FILES_MAX, SKILL_FILE_PATH_MAX, SKILLS_MOUNT, definitionFilesOf, skillFolderOf, isDefinitionFileHash, skillFilePathIssue, skillFilesIssue, skillInstructions, } from "./utils/definition-files.js";
26
+ export { SKILL_ENTRY, SKILL_TOTAL_BYTES_DEFAULT, SKILL_FILE_PATH_MAX, SKILLS_MOUNT, definitionFilesOf, skillsOf, skillFolderOf, isDefinitionFileHash, skillFilePathIssue, skillFilesIssue, skillInstructions, } from "./utils/definition-files.js";
31
27
  export type { Implementations } from "./definition/implementations.js";
32
- export type { AgentManifest, ApprovalMode, HttpToolMethod, HttpToolTarget, McpServerManifest, McpToolSettings, PluginLabel, RuntimeManifest, SandboxManifest, SandboxNetworkPreset, SkillManifest, ToolManifest, ManifestSchemaVersion, } from "./types/manifest.js";
28
+ export type { AgentManifest, ApprovalMode, HttpToolMethod, HttpToolTarget, McpServerManifest, McpToolSettings, PluginLabel, SandboxManifest, SandboxNetworkPreset, SkillManifest, ToolManifest, ManifestSchemaVersion, } from "./types/manifest.js";
33
29
  export type { PartDeclaration, SkillFileSource, } from "./types/part.js";
34
30
  export type { ModelCandidate, ModelControls, ModelDirective, ModelEvidence, ModelFinishReason, ModelFailureCode, ModelFailureOutcome, ModelProducer, ModelAdapter, ModelAdapterContext, ModelPreparedCall, ContextContributor, ContextMutationOptions, ContextSnapshot, ModelCall, ModelCallTool, ModelOutputBlock, PromptContentPart, PromptItem, ModelConfigurationContributor, ModelConfigurationInstruction, ModelConfigurationMutationOptions, ModelConfigurationSnapshot, ModelConfigurationTool, ModelRequest, ModelToolCall, ModelUsage, } from "./types/model.js";
35
31
  export type { BuildDiagnostic, ContextItem, DeferredOutcome, JsonObject, JsonPrimitive, JsonValue, Tripwire, } from "./types/shared.js";
@@ -48,7 +44,7 @@ export { bindTool } from "./definition/bind-tool.js";
48
44
  export { bindOutputContract } from "./definition/output-contract.js";
49
45
  export type { TurnOutputContract } from "./definition/output-contract.js";
50
46
  export { agentFrom } from "./definition/from.js";
51
- export { mediaReferenceLine, mediaReferenceOf, type MediaReference, } from "./definition/media-reference.js";
47
+ export { mediaReferenceOf, type MediaReference } from "./definition/media-reference.js";
52
48
  export type { SessionToolRef } from "./definition/from.js";
53
49
  export { schemaFromJSON } from "./definition/schema-json.js";
54
50
  export { normalizeSchema } from "./definition/schema.js";
package/dist/define.js CHANGED
@@ -1,25 +1,21 @@
1
1
  export { Agent, AgentBuilder, AgentBuildError, AgentLifecycleError, } from "./definition/builder.js";
2
2
  export { HarnessError, isHarnessError } from "./errors.js";
3
- export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, flowDelegatesOf, flowDelegateManifest, isFlowDelegate, } from "./definition/delegate.js";
3
+ export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, flowDelegatesOf, flowDelegateManifest, isFlowDelegate, MODEL_TOOL_NAME_MAX, } 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";
6
- export { READ_ARTIFACT_MAX_BYTES, READ_ARTIFACT_TOOL, SAVE_ARTIFACT_TOOL, runtimeManifestFor, runtimeToolOf, } from "./definition/runtime-manifest.js";
7
- export { RUNTIME_PART_ID } from "./definition/manifest.js";
8
- export { RUNTIME_TOOL_NAMES, isRuntimeToolName } from "./utils/runtime-tools.js";
5
+ export { APPROVAL_MODES, HTTP_TOOL_DEFAULT_TIMEOUT_MS, HTTP_TOOL_METHODS, HTTP_BODY_METHODS, http, httpPathParameters, httpToolOf, httpToolRequest, isHttpTarget, withHttpTarget, } from "./definition/http-tool.js";
6
+ export { SESSION_PART_ID } from "./definition/manifest.js";
7
+ export { READ_ARTIFACT_TOOL, SAVE_ARTIFACT_TOOL, } from "./utils/runtime-tools.js";
9
8
  export { MCP_TOOL_DEFAULTS, mcpToolSettings, McpError, normalizeMcpServers, stdioMcpRefusal, } from "./definition/mcp.js";
10
- export { SERVER_INSTRUCTIONS_MAX_CHARS, TOOL_CALL_TOOL, TOOL_SEARCH_DEFAULT_LIMIT, TOOL_SEARCH_MAX_LIMIT, TOOL_SEARCH_TOOL, deferredToolsInstructions, deferredToolsTools, } from "./definition/deferred-tools.js";
11
9
  export { codeToolRefusal, codeToolsOf } from "./definition/code-tools.js";
12
- export { pluginOf, skillOfToolCall } from "./definition/trace.js";
10
+ export { pluginOf } from "./definition/trace.js";
13
11
  export { approvalRefusal, approvalsOf } from "./definition/approval.js";
14
12
  export { flow, FlowBuilder, isFlowBuilder, ROOT_POSITION, childPosition, embeddedAgent, flowHttpTarget, forEachFlowNode, indexSuffix, isLeafNode, isWorkflowManifest, leafPart, leafPath, stageKey, stripIndices, } from "./definition/flow/index.js";
15
13
  export { ToolError, isToolError } from "./definition/tool-error.js";
16
14
  export { defineSchema } from "./definition/schema.js";
17
15
  export { hashManifest } from "./utils/hash.js";
18
16
  export { MODEL_FAILURE_CODES, isModelFailureOutcome } from "./definition/model-failure.js";
19
- export { createSandboxTools, SANDBOX_INSTRUCTIONS, } from "./definition/sandbox-tools.js";
20
17
  export { SANDBOX_NETWORK_PRESETS, SANDBOX_TOOL_NAMES, SANDBOX_WORKSPACE, isSandboxHostPattern, isSandboxToolName, parseSandboxDuration, parseSandboxSize, } from "./utils/sandbox.js";
21
- export { LOAD_SKILL_TOOL, READ_SKILL_RESOURCE_TOOL, SKILL_TOOL_NAMES, isSkillTool, SKILLS_USAGE, formatSkillCatalog, } from "./definition/skill-tools.js";
22
- export { DEFINITION_FILE_MAX_BYTES, SKILL_ENTRY, SKILL_FILES_MAX, SKILL_FILE_PATH_MAX, SKILLS_MOUNT, definitionFilesOf, skillFolderOf, isDefinitionFileHash, skillFilePathIssue, skillFilesIssue, skillInstructions, } from "./utils/definition-files.js";
18
+ export { SKILL_ENTRY, SKILL_TOTAL_BYTES_DEFAULT, SKILL_FILE_PATH_MAX, SKILLS_MOUNT, definitionFilesOf, skillsOf, skillFolderOf, isDefinitionFileHash, skillFilePathIssue, skillFilesIssue, skillInstructions, } from "./utils/definition-files.js";
23
19
  export { normalizeToolDefinition, normalizedSchemasFor, } from "./definition/schema.js";
24
20
  export { implementationsFor, bindingFromAgent } from "./definition/binding.js";
25
21
  export { VerdictSchema, isVerdict, WorkflowBuildError, isBuiltWorkflow, } from "./definition/workflow/index.js";
@@ -27,7 +23,7 @@ export { isVariantOf } from "./definition/variant.js";
27
23
  export { bindTool } from "./definition/bind-tool.js";
28
24
  export { bindOutputContract } from "./definition/output-contract.js";
29
25
  export { agentFrom } from "./definition/from.js";
30
- export { mediaReferenceLine, mediaReferenceOf, } from "./definition/media-reference.js";
26
+ export { mediaReferenceOf } from "./definition/media-reference.js";
31
27
  export { schemaFromJSON } from "./definition/schema-json.js";
32
28
  export { normalizeSchema } from "./definition/schema.js";
33
29
  export * from "./utils/immutable.js";
@@ -1,6 +1,6 @@
1
1
  import type { DefinitionPart } from "./bound.js";
2
2
  import type { BuiltAgent } from "../types/agent.js";
3
- import type { AgentManifest, AgentRequirements, RuntimeManifest } from "../types/manifest.js";
3
+ import type { AgentManifest, AgentRequirements } from "../types/manifest.js";
4
4
  import type { BuildDiagnostic, JsonObject } from "../types/shared.js";
5
5
  import type { ToolSchemaSource } from "../types/tool.js";
6
6
  type BuildResult<Agent> = {
@@ -18,7 +18,5 @@ export declare function assembleAgent(parts: readonly DefinitionPart[], identity
18
18
  metadata?: JsonObject;
19
19
  outputSchema?: ToolSchemaSource;
20
20
  requires?: AgentRequirements;
21
- /** A pinned manifest's `runtime` block, kept as it was (`agentFrom`). */
22
- runtime?: RuntimeManifest;
23
21
  }>): BuildResult<BuiltAgent>;
24
22
  export {};
@@ -1,7 +1,6 @@
1
1
  import { bindAgent } from "./bind-agent.js";
2
- import { createManifest, RUNTIME_PART_ID } from "./manifest.js";
2
+ import { createManifest, SESSION_PART_ID } from "./manifest.js";
3
3
  import { DELEGATE_NAME_PATTERN, delegateOf, delegatesOf } from "./delegate.js";
4
- import { isRuntimeToolName } from "../utils/runtime-tools.js";
5
4
  const diagnostic = (code, message, extra = {}) => Object.freeze({ code, message, ...extra });
6
5
  export function assembleAgent(parts, identity) {
7
6
  const diagnostics = [];
@@ -33,9 +32,7 @@ export function assembleAgent(parts, identity) {
33
32
  toolName: entry.name,
34
33
  }));
35
34
  toolNames.add(entry.name);
36
- if (item.id !== RUNTIME_PART_ID && isRuntimeToolName(entry.name))
37
- diagnostics.push(diagnostic("tool.reserved-name", `Tool '${entry.name}' takes the name of a tool the Runtime serves; rename it`, { toolName: entry.name }));
38
- if (item.id !== RUNTIME_PART_ID && entry.name.includes("__"))
35
+ if (item.id !== SESSION_PART_ID && entry.name.includes("__"))
39
36
  diagnostics.push(diagnostic("tool.invalid-name", `Tool '${entry.name}' must not contain '__', which names an MCP server's tools`, { toolName: entry.name }));
40
37
  }
41
38
  diagnostics.push(...nameDiagnostics(frozen, "skills", "skill.duplicate-name", "skill"));
@@ -55,7 +52,6 @@ export function assembleAgent(parts, identity) {
55
52
  metadata: identity.metadata,
56
53
  outputSchema: identity.outputSchema,
57
54
  requires: identity.requires,
58
- runtime: identity.runtime,
59
55
  parts: frozenParts,
60
56
  });
61
57
  const agent = bindAgent(frozenParts, manifest, identity);
@@ -101,8 +97,8 @@ function delegationDiagnostics(items) {
101
97
  }
102
98
  /**
103
99
  * Definitions declare no sandbox: a session gets one when it is opened (Sandboxes v3), and the
104
- * Runtime pins it in the manifest's `runtime` block. A part that still carries `sandbox` fails the
105
- * build instead of being silently dropped.
100
+ * Runtime keeps its spec on the session. A part that still carries `sandbox` fails the build
101
+ * instead of being silently dropped.
106
102
  */
107
103
  function sandboxDiagnostics(items) {
108
104
  return items
@@ -15,7 +15,7 @@ export interface BoundToolDefinition<Info = unknown> extends Omit<ToolDefinition
15
15
  }
16
16
  /**
17
17
  * One part of an agent definition: what one builder call, skills folder or plugin added, or (in
18
- * an agent rebuilt from a pinned manifest) the `runtime` block. The engine offers each part's
18
+ * an agent rebuilt from its manifest) what one run adds, its session part. The engine offers each part's
19
19
  * tools and instructions to the model in part order; the manifest holds the parts merged.
20
20
  */
21
21
  export interface DefinitionPart {
@@ -20,6 +20,11 @@ export interface Delegate {
20
20
  export declare function isFlowDelegate(delegate: Delegate): delegate is Delegate & {
21
21
  readonly manifest: WorkflowManifest;
22
22
  };
23
+ /**
24
+ * The longest tool name every model provider accepts (R2b C6, Q14): OpenAI's and Anthropic's
25
+ * `^[a-zA-Z0-9_-]{1,64}$`. A provider's ceiling, not a setting.
26
+ */
27
+ export declare const MODEL_TOOL_NAME_MAX = 64;
23
28
  /** Model-facing tool names: what every supported provider accepts. */
24
29
  export declare const DELEGATE_NAME_PATTERN: RegExp;
25
30
  /** The input every agent used as a tool accepts. Part of the hashed manifest; change deliberately. */
@@ -8,8 +8,13 @@ const DELEGATE = Symbol.for("@nylorun/core/delegate");
8
8
  export function isFlowDelegate(delegate) {
9
9
  return delegate.manifest.kind === "workflow";
10
10
  }
11
+ /**
12
+ * The longest tool name every model provider accepts (R2b C6, Q14): OpenAI's and Anthropic's
13
+ * `^[a-zA-Z0-9_-]{1,64}$`. A provider's ceiling, not a setting.
14
+ */
15
+ export const MODEL_TOOL_NAME_MAX = 64;
11
16
  /** Model-facing tool names: what every supported provider accepts. */
12
- export const DELEGATE_NAME_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;
17
+ export const DELEGATE_NAME_PATTERN = new RegExp(`^[A-Za-z0-9_-]{1,${MODEL_TOOL_NAME_MAX}}$`);
13
18
  const taskSchema = z
14
19
  .object({
15
20
  task: z
@@ -13,9 +13,11 @@ export interface SessionToolRef {
13
13
  }
14
14
  /**
15
15
  * Rebuild an agent from its manifest and the code of its tools, by name (T28). Agents used as
16
- * tools and HTTP tools need no code; neither do the tools in `runtime`, which the Runtime serves.
17
- * A session tool (`sessionTools`) is offered with the `runtime` part and needs its code.
16
+ * tools and HTTP tools need no code. A session tool (`sessionTools`) is offered in the session
17
+ * part, after the agent's own, with `sessionInstructions` (text not tied to one tool) before its
18
+ * tools' own; it needs its code, and its name may not be one of the agent's tools.
18
19
  */
19
20
  export declare function agentFrom<Info = unknown>(json: AgentManifest | JsonObject, implementations: Implementations<Info>, options?: {
20
21
  readonly sessionTools?: readonly SessionToolRef[];
22
+ readonly sessionInstructions?: readonly string[];
21
23
  }): BuiltAgent<Info>;
@@ -4,13 +4,13 @@ import { schemaFromJSON } from "./schema-json.js";
4
4
  import { assertJson, deepFreeze } from "../utils/immutable.js";
5
5
  import { delegateFromManifest, delegateOf } from "./delegate.js";
6
6
  import { httpToolFromManifest, httpToolOf } from "./http-tool.js";
7
- import { RUNTIME_PART_ID } from "./manifest.js";
8
- import { ToolError } from "./tool-error.js";
7
+ import { SESSION_PART_ID } from "./manifest.js";
9
8
  import { AgentManifestSchema } from "../contracts.js";
10
9
  /**
11
10
  * 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.
11
+ * tools and HTTP tools need no code. A session tool (`sessionTools`) is offered in the session
12
+ * part, after the agent's own, with `sessionInstructions` (text not tied to one tool) before its
13
+ * tools' own; it needs its code, and its name may not be one of the agent's tools.
14
14
  */
15
15
  export function agentFrom(json, implementations, options) {
16
16
  const manifest = normalizeManifest(json);
@@ -30,22 +30,20 @@ export function agentFrom(json, implementations, options) {
30
30
  ...(manifest.skills === undefined ? {} : { skills: manifest.skills }),
31
31
  ...(manifest.mcpServers === undefined ? {} : { mcpServers: manifest.mcpServers }),
32
32
  }));
33
- const runtime = manifest.runtime;
34
33
  const session = sessionTools.map((item) => {
35
34
  const live = code[item.name];
36
35
  if (!live)
37
36
  throw new HarnessError("agent.build-failed", `Missing session tool implementation '${item.name}'`);
38
37
  return live;
39
38
  });
40
- const sessionInstructions = sessionTools.flatMap((item) => item.instructions ?? []);
41
- if (runtime !== undefined || session.length > 0)
39
+ const sessionInstructions = [
40
+ ...(options?.sessionInstructions ?? []),
41
+ ...sessionTools.flatMap((item) => item.instructions ?? []),
42
+ ];
43
+ if (session.length > 0 || sessionInstructions.length > 0)
42
44
  parts.push(Object.freeze({
43
- id: RUNTIME_PART_ID,
44
- ...(runtime?.tools === undefined
45
- ? {}
46
- : { tools: runtime.tools.map((declared) => code[declared.name] ?? runtimeTool(declared)) }),
45
+ id: SESSION_PART_ID,
47
46
  ...(session.length === 0 ? {} : { sessionTools: session }),
48
- ...(runtime?.instructions === undefined ? {} : { instructions: runtime.instructions }),
49
47
  ...(sessionInstructions.length === 0 ? {} : { sessionInstructions }),
50
48
  }));
51
49
  const outputSchema = manifest.outputSchema
@@ -58,17 +56,13 @@ export function agentFrom(json, implementations, options) {
58
56
  metadata: manifest.metadata,
59
57
  outputSchema,
60
58
  ...(manifest.requires === undefined ? {} : { requires: manifest.requires }),
61
- runtime: manifest.runtime,
62
59
  });
63
60
  if (!result.ok)
64
61
  throw new HarnessError("agent.build-failed", result.diagnostics.map((item) => item.message).join("; "));
65
62
  return result.agent;
66
63
  }
67
64
  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
- ]);
65
+ const taken = new Set((manifest.tools ?? []).map((tool) => tool.name));
72
66
  const seen = new Set();
73
67
  for (const item of sessionTools) {
74
68
  if (seen.has(item.name))
@@ -94,18 +88,6 @@ function authoredTool(declared, live) {
94
88
  return live;
95
89
  throw new HarnessError("agent.build-failed", `Missing tool implementation '${declared.name}'`);
96
90
  }
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
- },
107
- });
108
- }
109
91
  /**
110
92
  * The manifest as `AgentManifestSchema` accepts it (the Runtime's own check), as a frozen copy.
111
93
  * A refusal is `agent.build-failed` with the schema's messages.
@@ -5,17 +5,26 @@
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
- /** How long a service may take to answer when the tool sets no `timeoutMs`. */
22
+ /**
23
+ * The default of a tool's `timeoutMs` setting: how long a service may take to answer when the
24
+ * tool sets none. The longest a tool may set is the Tenant's Runtime limit `httpToolTimeoutMs`,
25
+ * checked when the agent is deployed and when the tool is called.
26
+ */
16
27
  export declare const HTTP_TOOL_DEFAULT_TIMEOUT_MS = 60000;
17
- /** The longest `timeoutMs` a tool may set. */
18
- export declare const HTTP_TOOL_MAX_TIMEOUT_MS = 300000;
19
28
  /** What an HTTP tool puts in its manifest entry besides its name and schemas. */
20
29
  export interface HttpTool {
21
30
  readonly http: HttpToolTarget;
@@ -39,9 +48,10 @@ export interface HttpTarget {
39
48
  readonly http: HttpToolTarget;
40
49
  }
41
50
  /**
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.
51
+ * A tool the Runtime runs as an HTTP request to `url` with `method` (default `POST`): the input
52
+ * fields the URL's path names as `{field}` fill it, and the rest are the JSON body (`POST`, `PUT`,
53
+ * `PATCH`) or the query string (`GET`, `DELETE`). The model gets the answer. Use it in
54
+ * `.tools(...)` like any tool, or as a flow stage; it has no implementation.
45
55
  */
46
56
  export declare function http<InputSchema extends ToolInputSchema | JsonObject, OutputSchema extends ToolOutputSchema | JsonObject | undefined = undefined>(options: HttpToolOptions<InputSchema, OutputSchema>): AnyTool;
47
57
  /**
@@ -66,4 +76,40 @@ export declare function httpToolOf(tool: unknown): HttpTool | undefined;
66
76
  export declare function httpTargetIssue(target: HttpToolTarget): string | undefined;
67
77
  /** Why `url` is not an HTTP tool's URL, or undefined. */
68
78
  export declare function httpUrlIssue(url: unknown): string | undefined;
79
+ /** The input fields an HTTP target's URL names in its path as `{field}`, in order. */
80
+ export declare function httpPathParameters(url: string): string[];
81
+ /**
82
+ * Why the `{field}` parameters of an absolute http(s) `url` are malformed, or undefined: each is
83
+ * a field name, named once, in the path (never the host or the query string).
84
+ */
85
+ export declare function httpUrlTemplateIssue(url: string): string | undefined;
86
+ /**
87
+ * Why `target` cannot be a Loop's HTTP verifier, or undefined: the Runtime sends a verifier
88
+ * `{ input, output, iteration }` as a JSON body, so it takes a body method and no URL parameters.
89
+ */
90
+ export declare function httpVerifierIssue(target: HttpToolTarget): string | undefined;
91
+ /**
92
+ * Why an HTTP tool's `inputSchema` does not fit its target, or undefined. Each `{field}` its URL
93
+ * names is a required property of the input, and not an object or an array, so the model always
94
+ * has one value to put there. For `GET` and `DELETE`, which send the other fields as the query
95
+ * string, no field is an object, and none is a query parameter the URL already fixes.
96
+ */
97
+ export declare function httpInputIssue(target: HttpToolTarget, inputSchema: JsonObject | undefined): string | undefined;
98
+ /** The request one call of an HTTP target makes, or why its input cannot make one. */
99
+ export type HttpToolRequest = {
100
+ readonly url: string;
101
+ readonly method: HttpToolMethod;
102
+ /** The JSON body, for `POST`, `PUT` and `PATCH`; `GET` and `DELETE` send none. */
103
+ readonly body?: string;
104
+ } | {
105
+ readonly issue: string;
106
+ };
107
+ /**
108
+ * The request a call of `target` with `input` makes. The fields the URL's path names fill it,
109
+ * each percent-encoded as one path segment; the other fields are the JSON body for a body
110
+ * method, and the query string, after the URL's own, for `GET` and `DELETE`. In the query
111
+ * string an array repeats its name (`tag=a&tag=b`), a `null` is left out, and an object is
112
+ * refused. A body-method target without URL parameters sends the input as it is.
113
+ */
114
+ export declare function httpToolRequest(target: HttpToolTarget, input: unknown): HttpToolRequest;
69
115
  export {};
@@ -1,17 +1,22 @@
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
+ import { TIMER_MAX_MS } from "../utils/runtime-limits.js";
6
7
  /** Survives duplicate installed copies of core, like the delegate brand. */
7
8
  const HTTP = Symbol.for("@nylorun/core/http-tool");
8
9
  const TARGET = Symbol.for("@nylorun/core/http-target");
9
- export const HTTP_TOOL_METHODS = ["POST", "PUT", "PATCH"];
10
+ export const HTTP_TOOL_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"];
11
+ /** The methods that send the input as a JSON body; the others send it as the query string. */
12
+ export const HTTP_BODY_METHODS = ["POST", "PUT", "PATCH"];
10
13
  export const APPROVAL_MODES = ["never", "always"];
11
- /** How long a service may take to answer when the tool sets no `timeoutMs`. */
14
+ /**
15
+ * The default of a tool's `timeoutMs` setting: how long a service may take to answer when the
16
+ * tool sets none. The longest a tool may set is the Tenant's Runtime limit `httpToolTimeoutMs`,
17
+ * checked when the agent is deployed and when the tool is called.
18
+ */
12
19
  export const HTTP_TOOL_DEFAULT_TIMEOUT_MS = 60_000;
13
- /** The longest `timeoutMs` a tool may set. */
14
- export const HTTP_TOOL_MAX_TIMEOUT_MS = 300_000;
15
20
  export function http(options) {
16
21
  if (!("name" in options) && !("input" in options))
17
22
  return httpTarget(options);
@@ -22,12 +27,16 @@ export function http(options) {
22
27
  ("approval" in options ? APPROVAL_REMOVED : undefined);
23
28
  if (issue)
24
29
  throw new HarnessError("tool.invalid", `HTTP tool '${name}': ${issue}`);
25
- return prepareTool(withHttpTarget({
30
+ const tool = prepareTool(withHttpTarget({
26
31
  name,
27
32
  ...(description === undefined ? {} : { description }),
28
33
  inputSchema: schemaSource(input),
29
34
  ...(output === undefined ? {} : { outputSchema: schemaSource(output) }),
30
35
  }, { http: target }));
36
+ const parameters = httpInputIssue(target, normalizedSchemasFor(tool).inputSchema.jsonSchema);
37
+ if (parameters)
38
+ throw new HarnessError("tool.invalid", `HTTP tool '${name}': ${parameters}`);
39
+ return tool;
31
40
  }
32
41
  function targetOf({ url, method, credential, timeoutMs }) {
33
42
  return {
@@ -43,7 +52,7 @@ function httpTarget(options) {
43
52
  if (unknown.length > 0)
44
53
  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
54
  const target = targetOf(options);
46
- const issue = httpTargetIssue(target);
55
+ const issue = httpTargetIssue(target) ?? httpVerifierIssue(target);
47
56
  if (issue)
48
57
  throw new HarnessError("configuration.invalid", `HTTP verifier: ${issue}`);
49
58
  const value = { http: Object.freeze(target) };
@@ -87,7 +96,7 @@ export function httpToolOf(tool) {
87
96
  }
88
97
  /** Why `target` is not a valid HTTP tool target, or undefined. */
89
98
  export function httpTargetIssue(target) {
90
- const url = httpUrlIssue(target.url);
99
+ const url = httpUrlIssue(target.url) ?? httpUrlTemplateIssue(target.url);
91
100
  if (url)
92
101
  return url;
93
102
  if (target.method !== undefined && !HTTP_TOOL_METHODS.includes(target.method))
@@ -95,8 +104,8 @@ export function httpTargetIssue(target) {
95
104
  if (target.credential !== undefined && (typeof target.credential !== "string" || target.credential === ""))
96
105
  return "credential must be a non-empty name";
97
106
  if (target.timeoutMs !== undefined &&
98
- (!Number.isInteger(target.timeoutMs) || target.timeoutMs <= 0 || target.timeoutMs > HTTP_TOOL_MAX_TIMEOUT_MS))
99
- return `timeoutMs must be a positive integer of at most ${HTTP_TOOL_MAX_TIMEOUT_MS}`;
107
+ (!Number.isInteger(target.timeoutMs) || target.timeoutMs <= 0 || target.timeoutMs > TIMER_MAX_MS))
108
+ return `timeoutMs must be a positive integer of at most ${TIMER_MAX_MS}`;
100
109
  return undefined;
101
110
  }
102
111
  /** Why `url` is not an HTTP tool's URL, or undefined. */
@@ -116,6 +125,162 @@ export function httpUrlIssue(url) {
116
125
  return "url must not have a fragment";
117
126
  return undefined;
118
127
  }
128
+ const PLACEHOLDER = /\{([^{}]*)\}/g;
129
+ const FIELD_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
130
+ /** The input fields an HTTP target's URL names in its path as `{field}`, in order. */
131
+ export function httpPathParameters(url) {
132
+ return [...url.matchAll(PLACEHOLDER)].map((match) => match[1]);
133
+ }
134
+ /**
135
+ * Why the `{field}` parameters of an absolute http(s) `url` are malformed, or undefined: each is
136
+ * a field name, named once, in the path (never the host or the query string).
137
+ */
138
+ export function httpUrlTemplateIssue(url) {
139
+ if (!/[{}]/.test(url))
140
+ return undefined;
141
+ if (/[{}]/.test(url.replace(PLACEHOLDER, "")))
142
+ return "url has an unmatched { or }";
143
+ const scheme = url.indexOf("://");
144
+ if (scheme === -1)
145
+ return "url must be an absolute http or https URL";
146
+ const authority = scheme + 3;
147
+ const query = url.indexOf("?", authority);
148
+ const end = query === -1 ? url.length : query;
149
+ const path = url.indexOf("/", authority);
150
+ const seen = new Set();
151
+ for (const match of url.matchAll(PLACEHOLDER)) {
152
+ const name = match[1];
153
+ if (path === -1 || match.index < path || match.index >= end)
154
+ return "url may name input fields as {field} only in its path";
155
+ if (!FIELD_NAME.test(name))
156
+ return `url parameter {${name}} must be an input field name`;
157
+ if (seen.has(name))
158
+ return `url names {${name}} twice`;
159
+ seen.add(name);
160
+ }
161
+ return undefined;
162
+ }
163
+ /**
164
+ * Why `target` cannot be a Loop's HTTP verifier, or undefined: the Runtime sends a verifier
165
+ * `{ input, output, iteration }` as a JSON body, so it takes a body method and no URL parameters.
166
+ */
167
+ export function httpVerifierIssue(target) {
168
+ if (target.method !== undefined && !HTTP_BODY_METHODS.includes(target.method))
169
+ return `an HTTP verifier is sent a JSON body: method must be one of ${HTTP_BODY_METHODS.join(", ")}`;
170
+ if (httpPathParameters(target.url).length > 0)
171
+ return "an HTTP verifier's url takes no {field} parameters";
172
+ return undefined;
173
+ }
174
+ /**
175
+ * Why an HTTP tool's `inputSchema` does not fit its target, or undefined. Each `{field}` its URL
176
+ * names is a required property of the input, and not an object or an array, so the model always
177
+ * has one value to put there. For `GET` and `DELETE`, which send the other fields as the query
178
+ * string, no field is an object, and none is a query parameter the URL already fixes.
179
+ */
180
+ export function httpInputIssue(target, inputSchema) {
181
+ // A malformed URL reports its own issue.
182
+ if (inputSchema === undefined || httpUrlTemplateIssue(target.url))
183
+ return undefined;
184
+ const properties = (inputSchema.properties && typeof inputSchema.properties === "object" ? inputSchema.properties : {});
185
+ const required = Array.isArray(inputSchema.required) ? inputSchema.required : [];
186
+ const names = httpPathParameters(target.url);
187
+ for (const name of names) {
188
+ if (!Object.hasOwn(properties, name))
189
+ return `url names {${name}}, which is not a property of the input schema`;
190
+ if (!required.includes(name))
191
+ return `url names {${name}}, which the input schema must list as required`;
192
+ if (typesOf(properties[name]).some((type) => type === "object" || type === "array"))
193
+ return `url names {${name}}, which must be a string, a number or a boolean`;
194
+ }
195
+ if (HTTP_BODY_METHODS.includes(target.method ?? "POST"))
196
+ return undefined;
197
+ let fixed;
198
+ try {
199
+ fixed = new URL(target.url.replace(PLACEHOLDER, "x")).searchParams;
200
+ }
201
+ catch {
202
+ return undefined; // the URL's own issue is reported
203
+ }
204
+ for (const [name, property] of Object.entries(properties)) {
205
+ if (names.includes(name))
206
+ continue;
207
+ if (fixed.has(name))
208
+ return `'${name}' is both an input field and a query parameter the url fixes`;
209
+ const types = typesOf(property);
210
+ const items = types.includes("array") ? typesOf(property.items) : [];
211
+ if (types.includes("object") || items.includes("object") || items.includes("array"))
212
+ return `'${name}' is sent in the query string by ${target.method}, so it must not be an object or hold objects`;
213
+ }
214
+ return undefined;
215
+ }
216
+ /** The JSON Schema `type`s a property declares, if any. */
217
+ function typesOf(schema) {
218
+ const type = schema && typeof schema === "object" ? schema.type : undefined;
219
+ return typeof type === "string" ? [type] : Array.isArray(type) ? type.filter((t) => typeof t === "string") : [];
220
+ }
221
+ /**
222
+ * The request a call of `target` with `input` makes. The fields the URL's path names fill it,
223
+ * each percent-encoded as one path segment; the other fields are the JSON body for a body
224
+ * method, and the query string, after the URL's own, for `GET` and `DELETE`. In the query
225
+ * string an array repeats its name (`tag=a&tag=b`), a `null` is left out, and an object is
226
+ * refused. A body-method target without URL parameters sends the input as it is.
227
+ */
228
+ export function httpToolRequest(target, input) {
229
+ const method = target.method ?? "POST";
230
+ const hasBody = HTTP_BODY_METHODS.includes(method);
231
+ const names = httpPathParameters(target.url);
232
+ if (hasBody && names.length === 0)
233
+ return { url: target.url, method, body: JSON.stringify(input ?? {}) };
234
+ const fields = input ?? {};
235
+ if (typeof fields !== "object" || Array.isArray(fields))
236
+ return { issue: "The tool input must be an object" };
237
+ const rest = { ...fields };
238
+ let url = target.url;
239
+ for (const name of names) {
240
+ const segment = pathSegment(rest[name]);
241
+ if (segment === undefined)
242
+ return {
243
+ issue: `'${name}' must be a non-empty string, a number or a boolean, and not . or ..: it fills {${name}} in the URL`,
244
+ };
245
+ delete rest[name];
246
+ url = url.replace(`{${name}}`, () => segment);
247
+ }
248
+ if (hasBody)
249
+ return { url, method, body: JSON.stringify(rest) };
250
+ const query = queryString(rest);
251
+ if (typeof query !== "string")
252
+ return query;
253
+ if (query === "")
254
+ return { url, method };
255
+ const joiner = !url.includes("?") ? "?" : url.endsWith("?") || url.endsWith("&") ? "" : "&";
256
+ return { url: `${url}${joiner}${query}`, method };
257
+ }
258
+ /** `value` as one percent-encoded path segment, or undefined when it cannot be one. */
259
+ function pathSegment(value) {
260
+ if (typeof value === "number" && !Number.isFinite(value))
261
+ return undefined;
262
+ if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean")
263
+ return undefined;
264
+ const text = String(value);
265
+ // `.` and `..` are not encoded, and would move the request to another path. Side by side,
266
+ // `{a}{b}` or `.{a}`, a `..` segment needs one value to be `.`, so this check covers them too.
267
+ if (text === "" || text === "." || text === "..")
268
+ return undefined;
269
+ return encodeURIComponent(text);
270
+ }
271
+ /** `fields` as a query string, in their order, without a leading `?`; an object cannot be one. */
272
+ function queryString(fields) {
273
+ const pairs = [];
274
+ for (const [name, value] of Object.entries(fields))
275
+ for (const item of Array.isArray(value) ? value : [value]) {
276
+ if (item === null || item === undefined)
277
+ continue;
278
+ if (typeof item === "object")
279
+ return { issue: `'${name}' is sent in the query string, so it must not be an object or hold objects` };
280
+ pairs.push(`${encodeURIComponent(name)}=${encodeURIComponent(String(item))}`);
281
+ }
282
+ return pairs.join("&");
283
+ }
119
284
  async function runtimeOnly() {
120
285
  throw new ToolError("http.runtime-only", "HTTP tools are run by the Nylorun Runtime, not in this process");
121
286
  }