@nylorun/core 0.13.0-beta → 0.16.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 +131 -0
  2. package/dist/compatibility.d.ts +68 -25
  3. package/dist/compatibility.js +67 -27
  4. package/dist/contracts.d.ts +325 -959
  5. package/dist/contracts.js +281 -516
  6. package/dist/define.d.ts +13 -10
  7. package/dist/define.js +7 -4
  8. package/dist/definition/assemble.d.ts +0 -3
  9. package/dist/definition/assemble.js +13 -19
  10. package/dist/definition/bind-agent.js +0 -2
  11. package/dist/definition/bind-tool.js +0 -1
  12. package/dist/definition/bound.d.ts +3 -10
  13. package/dist/definition/builder.d.ts +19 -55
  14. package/dist/definition/builder.js +19 -130
  15. package/dist/definition/capability.d.ts +3 -15
  16. package/dist/definition/capability.js +3 -25
  17. package/dist/definition/code-tools.d.ts +22 -0
  18. package/dist/definition/code-tools.js +46 -0
  19. package/dist/definition/declaration.d.ts +0 -3
  20. package/dist/definition/declaration.js +8 -11
  21. package/dist/definition/delegate.d.ts +7 -7
  22. package/dist/definition/flow/compile.d.ts +4 -5
  23. package/dist/definition/flow/compile.js +120 -72
  24. package/dist/definition/flow/from.d.ts +2 -2
  25. package/dist/definition/flow/from.js +14 -33
  26. package/dist/definition/flow/index.d.ts +2 -2
  27. package/dist/definition/flow/index.js +2 -2
  28. package/dist/definition/flow/paths.d.ts +32 -17
  29. package/dist/definition/flow/paths.js +35 -14
  30. package/dist/definition/flow/spec.d.ts +6 -9
  31. package/dist/definition/flow/spec.js +49 -31
  32. package/dist/definition/flow/types.d.ts +40 -116
  33. package/dist/definition/from.js +36 -41
  34. package/dist/definition/helpers.d.ts +1 -1
  35. package/dist/definition/helpers.js +1 -1
  36. package/dist/definition/http-tool.d.ts +66 -0
  37. package/dist/definition/http-tool.js +131 -0
  38. package/dist/definition/implementations.d.ts +0 -3
  39. package/dist/definition/manifest.js +5 -4
  40. package/dist/definition/mcp.d.ts +4 -2
  41. package/dist/definition/mcp.js +14 -18
  42. package/dist/definition/removed.d.ts +10 -0
  43. package/dist/definition/removed.js +26 -0
  44. package/dist/definition/sandbox-capability.d.ts +2 -0
  45. package/dist/definition/sandbox-capability.js +11 -1
  46. package/dist/definition/schema.js +0 -3
  47. package/dist/definition/skill-tools.d.ts +16 -2
  48. package/dist/definition/skill-tools.js +38 -31
  49. package/dist/definition/variant.d.ts +1 -1
  50. package/dist/definition/variant.js +3 -14
  51. package/dist/definition/workflow/diagnostics.d.ts +1 -7
  52. package/dist/definition/workflow/diagnostics.js +1 -24
  53. package/dist/definition/workflow/index.d.ts +3 -17
  54. package/dist/definition/workflow/index.js +2 -9
  55. package/dist/definition/workflow/runnable.d.ts +2 -34
  56. package/dist/definition/workflow/runnable.js +8 -142
  57. package/dist/definition/workflow/types.d.ts +1 -10
  58. package/dist/harness-api/messages.d.ts +24 -27
  59. package/dist/harness-api/messages.js +1 -1
  60. package/dist/harness-api/schema.d.ts +0 -16
  61. package/dist/harness-api/schema.js +5 -12
  62. package/dist/index.d.ts +1 -1
  63. package/dist/types/manifest.d.ts +41 -14
  64. package/dist/types/middleware.d.ts +11 -16
  65. package/dist/types/observe.d.ts +0 -6
  66. package/dist/types/tool.d.ts +0 -6
  67. package/dist/types/workflow.d.ts +54 -110
  68. package/dist/utils/definition-files.d.ts +31 -0
  69. package/dist/utils/definition-files.js +84 -0
  70. package/package.json +1 -1
  71. package/dist/definition/hooks.d.ts +0 -19
  72. package/dist/definition/hooks.js +0 -67
  73. package/dist/definition/workflow/build.d.ts +0 -28
  74. package/dist/definition/workflow/build.js +0 -40
  75. package/dist/definition/workflow/chain.d.ts +0 -49
  76. package/dist/definition/workflow/chain.js +0 -40
  77. package/dist/definition/workflow/loop.d.ts +0 -54
  78. package/dist/definition/workflow/loop.js +0 -100
  79. package/dist/definition/workflow/map.d.ts +0 -17
  80. package/dist/definition/workflow/map.js +0 -45
  81. package/dist/definition/workflow/parallel.d.ts +0 -19
  82. package/dist/definition/workflow/parallel.js +0 -36
  83. package/dist/definition/workflow/patch.d.ts +0 -11
  84. package/dist/definition/workflow/patch.js +0 -45
  85. package/dist/definition/workflow/slot.d.ts +0 -23
  86. package/dist/definition/workflow/slot.js +0 -16
  87. package/dist/definition/workflow/switch.d.ts +0 -26
  88. package/dist/definition/workflow/switch.js +0 -64
  89. package/dist/types/dynamics.d.ts +0 -101
  90. package/dist/types/dynamics.js +0 -1
@@ -1,20 +1,9 @@
1
1
  /**
2
- * Types for flow agents: each stage's output types the next stage's `input`, and
3
- * `results` gains an entry for every step whose id is known at compile time.
2
+ * Types for flow agents: each stage's output types the next stage's input, and the last
3
+ * stage's output is the flow agent's.
4
4
  */
5
- import type { AgentManifest } from "../../types/manifest.js";
6
5
  import type { SchemaOutput, ToolSchemaSource } from "../../types/tool.js";
7
- import type { Verdict } from "../../types/workflow.js";
8
6
  import type { BuiltWorkflow } from "../workflow/types.js";
9
- /** What every flow function receives. */
10
- export type StageArgs<Cur = any, Results = Readonly<Record<string, any>>, In = any> = {
11
- readonly input: Cur;
12
- readonly results: Results;
13
- /** The input of the nearest Agent. */
14
- readonly flowInput: In;
15
- };
16
- /** What a function inside a nested `flow()` receives: the same as a top-level stage. */
17
- export type NestedStageArgs<Cur = any, Results = Readonly<Record<string, any>>> = StageArgs<Cur, Results, any>;
18
7
  /** A child renamed with `.withId()`. */
19
8
  export interface Named<R = unknown> {
20
9
  readonly run: R;
@@ -25,133 +14,68 @@ export interface Named<R = unknown> {
25
14
  export type FlowOut<C> = C extends {
26
15
  readonly __output?: infer O;
27
16
  } ? unknown extends O ? any : O : C extends BuiltWorkflow<any, infer O> ? O : any;
28
- /** A child's step id, when it is a string literal. */
29
- export type IdOf<C> = C extends {
30
- readonly __id?: infer I;
31
- } ? I extends string ? I : string : string;
32
- export type AddResult<Results, K extends string, V> = string extends K ? Results : Results & {
33
- readonly [P in K]: V;
34
- };
35
- /** Case names `on` may return: any string when there is a `default` case. */
36
- export type CaseKey<Cases> = "default" extends keyof Cases ? string : Extract<keyof Cases, string>;
17
+ /** The output of the last of `.pipe()`'s children. */
18
+ export type PipeOut<Children extends readonly unknown[], Cur> = Children extends readonly [
19
+ ...unknown[],
20
+ infer Last
21
+ ] ? FlowOut<Last> : Cur;
37
22
  export type CasesOut<Cases> = {
38
23
  [K in keyof Cases]: FlowOut<Cases[K]>;
39
24
  }[keyof Cases];
40
25
  export type BranchesOut<Branches> = {
41
26
  readonly [K in keyof Branches]: FlowOut<Branches[K]>;
42
27
  };
43
- export type LoopVerifyFn<Cur, Out> = (args: {
44
- readonly input: Cur;
45
- readonly output: Out;
46
- readonly iteration: number;
47
- readonly results: Readonly<Record<string, any>>;
48
- readonly flowInput: any;
49
- }) => Verdict | Promise<Verdict>;
50
- export type LoopDecideArgs<Cur, Out> = {
51
- readonly input: Cur;
52
- readonly output: Out;
53
- readonly verdict: Verdict;
54
- readonly iteration: number;
55
- readonly history: readonly {
56
- readonly iteration: number;
57
- readonly output: Out;
58
- readonly verdict: Verdict;
59
- }[];
60
- /** The body agent's manifest, when the body is an agent: pass a variant back in `agent`. */
61
- readonly agent?: AgentManifest;
62
- readonly results: Readonly<Record<string, any>>;
63
- readonly flowInput: any;
64
- };
65
- export type LoopChoice<Out> = {
66
- readonly output: Out;
67
- } | {
68
- readonly retry: unknown;
69
- readonly agent?: AgentManifest;
70
- };
28
+ /** `.loop()` options: a verifier judges each attempt, at most `max` times. */
29
+ export interface LoopOptions {
30
+ /**
31
+ * A verifier agent, which gets `{ task, response, iteration }`, or an HTTP verifier,
32
+ * `http({ url })`, which gets `{ input, output, iteration }` as JSON. Either returns a verdict.
33
+ */
34
+ readonly verify: object;
35
+ readonly max: number;
36
+ readonly id?: string;
37
+ }
38
+ /** Options every other stage takes. */
39
+ export interface StageOptions {
40
+ readonly id?: string;
41
+ }
71
42
  type Final<Cur, Out> = [Out] extends [never] ? Cur : Out;
72
43
  /**
73
44
  * A flow agent: an `Agent` whose body is a flow. Returned by `.input()` and by every
74
45
  * stage method, so ReAct methods such as `.instructions()` are not available on it.
75
46
  */
76
- export interface FlowAgentBuilder<Info = unknown, In = any, Cur = any, Results = {}, Out = never, Id extends string = string> extends BuiltWorkflow<In, Final<Cur, Out>> {
47
+ export interface FlowAgentBuilder<Info = unknown, In = any, Cur = any, Out = never, Id extends string = string> extends BuiltWorkflow<In, Final<Cur, Out>> {
77
48
  readonly id: Id;
78
49
  /** Phantom carrier for the agent's id. */
79
50
  readonly __id?: Id;
80
- /** Phantom carrier for the context type hooks see. */
51
+ /** Phantom carrier for the agent's context type. */
81
52
  readonly __info?: Info;
82
53
  build(): BuiltWorkflow<In, Final<Cur, Out>>;
83
54
  /** Give this flow agent a new step id where there is no options object. */
84
55
  withId(id: string): Named<this>;
85
- output<S extends ToolSchemaSource>(schema: S): FlowAgentBuilder<Info, In, Cur, Results, SchemaOutput<S>, Id>;
86
- step<C, const StepId extends string = IdOf<C>>(child: C, options?: {
87
- readonly id?: StepId;
88
- readonly input?: (args: StageArgs<Cur, Results, In>) => unknown;
89
- }): FlowAgentBuilder<Info, In, FlowOut<C>, AddResult<Results, StepId, FlowOut<C>>, Out, Id>;
90
- switch<const Cases extends Readonly<Record<string, unknown>>, T, const StageId extends string = string>(cases: Cases, options: {
91
- readonly input: (args: StageArgs<Cur, Results, In>) => T;
92
- readonly on: (args: StageArgs<T, Results, In>) => CaseKey<Cases>;
93
- readonly id?: StageId;
94
- }): FlowAgentBuilder<Info, In, CasesOut<Cases>, AddResult<Results, StageId, CasesOut<Cases>>, Out, Id>;
95
- switch<const Cases extends Readonly<Record<string, unknown>>, const StageId extends string = string>(cases: Cases, options: {
96
- readonly on: (args: StageArgs<Cur, Results, In>) => CaseKey<Cases>;
97
- readonly id?: StageId;
98
- }): FlowAgentBuilder<Info, In, CasesOut<Cases>, AddResult<Results, StageId, CasesOut<Cases>>, Out, Id>;
99
- parallel<const Branches extends Readonly<Record<string, unknown>>, const StageId extends string = string>(branches: Branches, options?: {
100
- readonly id?: StageId;
101
- readonly input?: (args: StageArgs<Cur, Results, In>) => unknown;
102
- }): FlowAgentBuilder<Info, In, BranchesOut<Branches>, AddResult<Results, StageId, BranchesOut<Branches>>, Out, Id>;
103
- map<E, const StageId extends string = string>(each: E, ...options: Cur extends readonly unknown[] ? [options?: {
104
- readonly id?: StageId;
105
- readonly input?: (args: StageArgs<Cur, Results, In>) => readonly unknown[];
106
- }] : [options: {
107
- readonly id?: StageId;
108
- readonly input: (args: StageArgs<Cur, Results, In>) => readonly unknown[];
109
- }]): FlowAgentBuilder<Info, In, FlowOut<E>[], AddResult<Results, StageId, FlowOut<E>[]>, Out, Id>;
110
- loop<B, const StageId extends string = string>(body: B, options: {
111
- readonly verify: LoopVerifyFn<Cur, FlowOut<B>> | object;
112
- readonly max?: number;
113
- readonly decide?: (args: LoopDecideArgs<Cur, FlowOut<B>>) => LoopChoice<FlowOut<B>>;
114
- readonly id?: StageId;
115
- readonly input?: (args: StageArgs<Cur, Results, In>) => unknown;
116
- }): FlowAgentBuilder<Info, In, FlowOut<B>, AddResult<Results, StageId, FlowOut<B>>, Out, Id>;
56
+ output<S extends ToolSchemaSource>(schema: S): FlowAgentBuilder<Info, In, Cur, SchemaOutput<S>, Id>;
57
+ /** Add stages in order: each gets the previous one's output. */
58
+ pipe<const Children extends readonly unknown[]>(...children: Children): FlowAgentBuilder<Info, In, PipeOut<Children, Cur>, Out, Id>;
59
+ /** @deprecated Use `.pipe()`, and `.withId()` to rename a child. */
60
+ step<C>(child: C, options?: StageOptions): FlowAgentBuilder<Info, In, FlowOut<C>, Out, Id>;
61
+ switch<const Cases extends Readonly<Record<string, unknown>>>(cases: Cases, options?: StageOptions): FlowAgentBuilder<Info, In, CasesOut<Cases>, Out, Id>;
62
+ parallel<const Branches extends Readonly<Record<string, unknown>>>(branches: Branches, options?: StageOptions): FlowAgentBuilder<Info, In, BranchesOut<Branches>, Out, Id>;
63
+ map<E>(each: E, options?: StageOptions): FlowAgentBuilder<Info, In, FlowOut<E>[], Out, Id>;
64
+ loop<B>(body: B, options: LoopOptions): FlowAgentBuilder<Info, In, FlowOut<B>, Out, Id>;
117
65
  }
118
66
  /**
119
67
  * A `flow()`: a sequence with no id, for a switch case, parallel branch, map item or
120
68
  * loop body that is more than one step.
121
69
  */
122
- export interface Flow<Cur = any, Results = {}> {
70
+ export interface Flow<Cur = any> {
123
71
  readonly __output?: Cur;
124
72
  withId(id: string): Named<this>;
125
- step<C, const StepId extends string = IdOf<C>>(child: C, options?: {
126
- readonly id?: StepId;
127
- readonly input?: (args: NestedStageArgs<Cur, Results>) => unknown;
128
- }): Flow<FlowOut<C>, AddResult<Results, StepId, FlowOut<C>>>;
129
- switch<const Cases extends Readonly<Record<string, unknown>>, T, const StageId extends string = string>(cases: Cases, options: {
130
- readonly input: (args: NestedStageArgs<Cur, Results>) => T;
131
- readonly on: (args: NestedStageArgs<T, Results>) => CaseKey<Cases>;
132
- readonly id?: StageId;
133
- }): Flow<CasesOut<Cases>, AddResult<Results, StageId, CasesOut<Cases>>>;
134
- switch<const Cases extends Readonly<Record<string, unknown>>, const StageId extends string = string>(cases: Cases, options: {
135
- readonly on: (args: NestedStageArgs<Cur, Results>) => CaseKey<Cases>;
136
- readonly id?: StageId;
137
- }): Flow<CasesOut<Cases>, AddResult<Results, StageId, CasesOut<Cases>>>;
138
- parallel<const Branches extends Readonly<Record<string, unknown>>, const StageId extends string = string>(branches: Branches, options?: {
139
- readonly id?: StageId;
140
- readonly input?: (args: NestedStageArgs<Cur, Results>) => unknown;
141
- }): Flow<BranchesOut<Branches>, AddResult<Results, StageId, BranchesOut<Branches>>>;
142
- map<E, const StageId extends string = string>(each: E, ...options: Cur extends readonly unknown[] ? [options?: {
143
- readonly id?: StageId;
144
- readonly input?: (args: NestedStageArgs<Cur, Results>) => readonly unknown[];
145
- }] : [options: {
146
- readonly id?: StageId;
147
- readonly input: (args: NestedStageArgs<Cur, Results>) => readonly unknown[];
148
- }]): Flow<FlowOut<E>[], AddResult<Results, StageId, FlowOut<E>[]>>;
149
- loop<B, const StageId extends string = string>(body: B, options: {
150
- readonly verify: LoopVerifyFn<Cur, FlowOut<B>> | object;
151
- readonly max?: number;
152
- readonly decide?: (args: LoopDecideArgs<Cur, FlowOut<B>>) => LoopChoice<FlowOut<B>>;
153
- readonly id?: StageId;
154
- readonly input?: (args: NestedStageArgs<Cur, Results>) => unknown;
155
- }): Flow<FlowOut<B>, AddResult<Results, StageId, FlowOut<B>>>;
73
+ pipe<const Children extends readonly unknown[]>(...children: Children): Flow<PipeOut<Children, Cur>>;
74
+ /** @deprecated Use `.pipe()`, and `.withId()` to rename a child. */
75
+ step<C>(child: C, options?: StageOptions): Flow<FlowOut<C>>;
76
+ switch<const Cases extends Readonly<Record<string, unknown>>>(cases: Cases, options?: StageOptions): Flow<CasesOut<Cases>>;
77
+ parallel<const Branches extends Readonly<Record<string, unknown>>>(branches: Branches, options?: StageOptions): Flow<BranchesOut<Branches>>;
78
+ map<E>(each: E, options?: StageOptions): Flow<FlowOut<E>[]>;
79
+ loop<B>(body: B, options: LoopOptions): Flow<FlowOut<B>>;
156
80
  }
157
81
  export {};
@@ -2,8 +2,14 @@ import { HarnessError } from "../errors.js";
2
2
  import { assembleAgent } from "./assemble.js";
3
3
  import { schemaFromJSON } from "./schema-json.js";
4
4
  import { copyJsonObject, deepFreeze } from "../utils/immutable.js";
5
- import { HOOK_POINTS, hasHook, hookListIssue } from "./hooks.js";
5
+ import { REMOVED_CAPABILITY_FIELDS, manifestVersionIssue } from "./removed.js";
6
6
  import { delegateFromManifest, delegateOf } from "./delegate.js";
7
+ import { stdioMcpRefusal } from "./mcp.js";
8
+ import { SKILL_TOOL_NAMES } from "./skill-tools.js";
9
+ import { skillFilesIssue } from "../utils/definition-files.js";
10
+ import { httpToolFromManifest, httpToolOf } from "./http-tool.js";
11
+ /** Tools the engine or the Runtime runs, which need no implementation: agents and HTTP tools. */
12
+ const declarative = (tool) => delegateOf(tool) !== undefined || httpToolOf(tool) !== undefined;
7
13
  /** Rebuild an agent from manifest JSON + in-process implementations (T28). */
8
14
  export function agentFrom(json, implementations, options) {
9
15
  const manifest = normalizeManifest(json);
@@ -22,12 +28,11 @@ export function agentFrom(json, implementations, options) {
22
28
  throw new HarnessError("agent.build-failed", `Missing session tool implementation '${item.name}' for capability '${capability.id}'`);
23
29
  return live;
24
30
  });
25
- assertHookImplementations(capability, impl);
26
31
  const handle = impl.middleware ??
27
32
  (async (request, next) => {
28
33
  const advertised = [...tools, ...session];
29
34
  if (advertised.length)
30
- request.configuration.tools.set(capability.id, advertised.map((tool) => (delegateOf(tool)
35
+ request.configuration.tools.set(capability.id, advertised.map((tool) => (declarative(tool)
31
36
  ? tool
32
37
  : implementations[capability.id]?.tools?.[tool.name]) ?? tool));
33
38
  if (capability.instructions)
@@ -44,7 +49,7 @@ export function agentFrom(json, implementations, options) {
44
49
  hasMiddleware: impl.middleware !== undefined,
45
50
  tools: capability.tools !== undefined
46
51
  ? tools.map((tool) => {
47
- const live = delegateOf(tool) ? tool : impl.tools?.[tool.name];
52
+ const live = declarative(tool) ? tool : impl.tools?.[tool.name];
48
53
  if (!live)
49
54
  throw new HarnessError("agent.build-failed", `Missing tool implementation '${tool.name}' for capability '${capability.id}'`);
50
55
  return live;
@@ -66,7 +71,6 @@ export function agentFrom(json, implementations, options) {
66
71
  }
67
72
  : {}),
68
73
  }),
69
- ...(capability.hooks === undefined ? {} : { hooks: capability.hooks }),
70
74
  manifestType: capability.type,
71
75
  ...(capability.metadata === undefined
72
76
  ? {}
@@ -81,11 +85,7 @@ export function agentFrom(json, implementations, options) {
81
85
  ? {}
82
86
  : { skills: capability.skills }),
83
87
  }));
84
- dynamics.set(capability.id, {
85
- ...(impl.before ? { before: impl.before } : {}),
86
- ...(impl.after ? { after: impl.after } : {}),
87
- ...(impl.middleware ? { middleware: impl.middleware } : {}),
88
- });
88
+ dynamics.set(capability.id, impl.middleware ? { middleware: impl.middleware } : {});
89
89
  }
90
90
  const outputSchema = manifest.outputSchema
91
91
  ? schemaFromJSON(manifest.outputSchema)
@@ -127,25 +127,23 @@ function resolveTools(capability, tools) {
127
127
  ? live
128
128
  : delegateFromManifest(declared.agent, declared),
129
129
  ];
130
+ // The Runtime runs HTTP tools; a host's own (its engine's routing) is kept.
131
+ if (declared.http)
132
+ return [
133
+ live && httpToolOf(live)
134
+ ? live
135
+ : httpToolFromManifest({ ...declared, http: declared.http }),
136
+ ];
130
137
  if (live)
131
138
  return [live];
132
- if ((declared.name === "load_skill" || declared.name === "read_skill_resource") &&
139
+ // The build attaches the skill tools again; the Runtime serves them.
140
+ if (SKILL_TOOL_NAMES.has(declared.name) &&
133
141
  capability.skills &&
134
142
  Object.keys(capability.skills).length > 0)
135
143
  return [];
136
144
  throw new HarnessError("agent.build-failed", `Missing tool implementation '${declared.name}' for capability '${capability.id}'`);
137
145
  });
138
146
  }
139
- function assertHookImplementations(capability, impl) {
140
- for (const point of HOOK_POINTS) {
141
- const declared = hasHook(capability.hooks, point.at, point.scope);
142
- const live = impl[point.at]?.[point.scope] !== undefined;
143
- if (declared && !live)
144
- throw new HarnessError("agent.build-failed", `Missing ${point.at}("${point.scope}") implementation for capability '${capability.id}'`);
145
- if (live && !declared)
146
- throw new HarnessError("agent.build-failed", `Capability '${capability.id}' implements ${point.at}("${point.scope}") but the manifest does not declare it`);
147
- }
148
- }
149
147
  function normalizeManifest(json) {
150
148
  if (!json || typeof json !== "object" || Array.isArray(json))
151
149
  throw new HarnessError("agent.build-failed", "Agent.from requires a manifest object");
@@ -160,10 +158,11 @@ function normalizeManifest(json) {
160
158
  throw new HarnessError("agent.build-failed", "Manifest capabilities must be an array");
161
159
  if ("schemaVersion" in value && value.schemaVersion !== undefined)
162
160
  throw new HarnessError("agent.build-failed", "Manifest field schemaVersion was renamed to manifestSchemaVersion");
163
- if (value.manifestSchemaVersion !== 4)
164
- throw new HarnessError("agent.build-failed", value.manifestSchemaVersion === 3
165
- ? "manifestSchemaVersion 3 is no longer supported; rebuild the agent with before/after hooks (see MIGRATION.md)"
166
- : `Unsupported manifestSchemaVersion ${String(value.manifestSchemaVersion)}`);
161
+ const versionIssue = manifestVersionIssue(value.manifestSchemaVersion);
162
+ if (versionIssue)
163
+ throw new HarnessError("agent.build-failed", versionIssue);
164
+ if ("functions" in value && value.functions !== undefined)
165
+ throw new HarnessError("agent.build-failed", "Functions are not available yet");
167
166
  // Reject top-level model (Runtime-owned).
168
167
  if ("model" in value && value.model !== undefined)
169
168
  throw new HarnessError("agent.build-failed", "Manifest must not include top-level model; Runtime owns model resolution");
@@ -184,7 +183,7 @@ function normalizeManifest(json) {
184
183
  servers.add(name);
185
184
  }
186
185
  return deepFreeze({
187
- manifestSchemaVersion: 4,
186
+ manifestSchemaVersion: 5,
188
187
  id: value.id,
189
188
  ...(typeof value.name === "string" && value.name ? { name: value.name } : {}),
190
189
  ...(typeof value.description === "string"
@@ -222,14 +221,9 @@ function normalizeCapability(capability) {
222
221
  throw new HarnessError("agent.build-failed", `Capability '${capability.id}' must not include model; Runtime owns model resolution`);
223
222
  if (capability.type !== "agent" && capability.type !== "agent-plugin")
224
223
  throw new HarnessError("agent.build-failed", `Capability '${capability.id}' type must be agent or agent-plugin`);
225
- for (const legacy of ["beforeModelCall", "afterModelCall"])
226
- if (legacy in raw)
227
- throw new HarnessError("agent.build-failed", `Capability '${capability.id}' field ${legacy} was replaced by hooks (see MIGRATION.md)`);
228
- if (capability.hooks !== undefined) {
229
- const issue = hookListIssue(capability.hooks);
230
- if (issue)
231
- throw new HarnessError("agent.build-failed", `Capability '${capability.id}' ${issue}`);
232
- }
224
+ for (const [field, message] of Object.entries(REMOVED_CAPABILITY_FIELDS))
225
+ if (field in raw)
226
+ throw new HarnessError("agent.build-failed", `Capability '${capability.id}': ${message}`);
233
227
  const metadata = capability.metadata === undefined
234
228
  ? undefined
235
229
  : copyJsonObject(capability.metadata, "metadata");
@@ -256,11 +250,6 @@ function normalizeCapability(capability) {
256
250
  : {
257
251
  sandbox: deepFreeze(copyJsonObject(capability.sandbox, "sandbox")),
258
252
  }),
259
- ...(capability.hooks === undefined
260
- ? {}
261
- : {
262
- hooks: Object.freeze(capability.hooks.map((hook) => Object.freeze({ at: hook.at, scope: hook.scope }))),
263
- }),
264
253
  });
265
254
  }
266
255
  function normalizeSkills(capabilityId, skills) {
@@ -279,9 +268,13 @@ function normalizeSkills(capabilityId, skills) {
279
268
  typeof skill.description !== "string" ||
280
269
  skill.description.length === 0)
281
270
  throw new HarnessError("agent.build-failed", `Capability '${capabilityId}' skills key '${key}' must equal the skill name`);
271
+ const issue = skillFilesIssue(skill.files);
272
+ if (issue)
273
+ throw new HarnessError("agent.build-failed", `Capability '${capabilityId}' skill '${key}' ${issue}`);
282
274
  normalized[key] = Object.freeze({
283
275
  name: skill.name,
284
276
  description: skill.description,
277
+ files: Object.freeze({ ...skill.files }),
285
278
  });
286
279
  }
287
280
  return Object.freeze(normalized);
@@ -296,6 +289,8 @@ function normalizeMcpServers(capabilityId, servers) {
296
289
  throw new HarnessError("agent.build-failed", `Capability '${capabilityId}' mcpServers must be a non-empty map or omitted`);
297
290
  const normalized = {};
298
291
  for (const [key, server] of Object.entries(servers)) {
292
+ if (server.type === "stdio")
293
+ throw new HarnessError("agent.build-failed", stdioMcpRefusal(key));
299
294
  if (!isMcpServer(server) || server.name !== key)
300
295
  throw new HarnessError("agent.build-failed", `Capability '${capabilityId}' mcpServers key '${key}' must equal the server name`);
301
296
  normalized[key] = server;
@@ -308,8 +303,6 @@ function isMcpServer(value) {
308
303
  const server = value;
309
304
  if (typeof server.name !== "string" || !server.name)
310
305
  return false;
311
- if (server.type === "stdio")
312
- return typeof server.command === "string" && server.command.length > 0;
313
306
  if (server.type === "streamable-http" || server.type === "sse")
314
307
  return typeof server.url === "string" && server.url.length > 0;
315
308
  return false;
@@ -331,5 +324,7 @@ function normalizeTool(tool) {
331
324
  ? deepFreeze(JSON.parse(JSON.stringify(tool.agent)))
332
325
  : normalizeManifest(tool.agent),
333
326
  }),
327
+ ...(tool.http === undefined ? {} : { http: Object.freeze({ ...tool.http }) }),
328
+ ...(tool.approval === undefined ? {} : { approval: tool.approval }),
334
329
  });
335
330
  }
@@ -4,7 +4,7 @@ import type { ToolDefinition, ToolInputSchema, ToolOutputSchema, ToolSchemaSourc
4
4
  export declare const tool: <InputSchema extends ToolInputSchema, Info = unknown, OutputSchema extends ToolOutputSchema | undefined = undefined>(value: ToolDefinition<InputSchema, Info, OutputSchema>) => ToolDefinition<InputSchema, Info, OutputSchema>;
5
5
  /** @deprecated Prefer Runtime model resolution. Capability-disguised `.use({ model })` is not the taught path. */
6
6
  export declare const model: <T extends ModelAdapter>(value: T) => T;
7
- /** @deprecated Prefer `before` / `after` hooks. Kept through 1.0. */
7
+ /** @deprecated Runs in the local engine only. Kept through 1.0. */
8
8
  export declare const middleware: <T extends StepMiddleware>(value: T) => T;
9
9
  export { capability } from "./capability.js";
10
10
  export type { ToolSchemaSource };
@@ -2,6 +2,6 @@ import { prepareTool } from "./schema.js";
2
2
  export const tool = (value) => prepareTool(value);
3
3
  /** @deprecated Prefer Runtime model resolution. Capability-disguised `.use({ model })` is not the taught path. */
4
4
  export const model = (value) => value;
5
- /** @deprecated Prefer `before` / `after` hooks. Kept through 1.0. */
5
+ /** @deprecated Runs in the local engine only. Kept through 1.0. */
6
6
  export const middleware = (value) => value;
7
7
  export { capability } from "./capability.js";
@@ -0,0 +1,66 @@
1
+ /**
2
+ * HTTP tools (R2 M3): a tool the manifest describes as one HTTP request, which the Runtime makes
3
+ * itself through its Tool Gate. No developer code runs for it: the tool value carries its target
4
+ * (`http`) and static approval into the manifest, and its `execute` only says where it runs.
5
+ * An HTTP tool is also a flow stage. `http({ url })` without a name and an input is a bare
6
+ * target, a Loop's HTTP verifier: its manifest form is itself, `{ http: { url, … } }`.
7
+ */
8
+ import type { ApprovalMode, HttpToolTarget, ToolManifest } from "../types/manifest.js";
9
+ import type { JsonObject } from "../types/shared.js";
10
+ import type { ToolDefinition, ToolInputSchema, ToolOutputSchema } from "../types/tool.js";
11
+ type AnyTool = ToolDefinition<any, any, any>;
12
+ export declare const HTTP_TOOL_METHODS: readonly ["POST", "PUT", "PATCH"];
13
+ export declare const APPROVAL_MODES: readonly ["never", "always"];
14
+ /** How long a service may take to answer when the tool sets no `timeoutMs`. */
15
+ export declare const HTTP_TOOL_DEFAULT_TIMEOUT_MS = 60000;
16
+ /** The longest `timeoutMs` a tool may set. */
17
+ export declare const HTTP_TOOL_MAX_TIMEOUT_MS = 300000;
18
+ /** What an HTTP tool puts in its manifest entry besides its name and schemas. */
19
+ export interface HttpTool {
20
+ readonly http: HttpToolTarget;
21
+ readonly approval?: ApprovalMode;
22
+ }
23
+ export interface HttpToolOptions<InputSchema extends ToolInputSchema | JsonObject = ToolInputSchema, OutputSchema extends ToolOutputSchema | JsonObject | undefined = undefined> extends HttpToolTarget {
24
+ readonly name: string;
25
+ readonly description?: string;
26
+ /** A Zod schema, a Standard Schema, a `defineSchema()` contract, or a JSON Schema object. */
27
+ readonly input: InputSchema;
28
+ /** Checked against the answer; a mismatch is a tool error the model sees. */
29
+ readonly output?: OutputSchema;
30
+ /** `always`: each call waits for approval. Default `never`. */
31
+ readonly approval?: ApprovalMode;
32
+ }
33
+ /** A bare HTTP target: a Loop's HTTP verifier, `.loop(body, { verify: http({ url }), max })`. */
34
+ export interface HttpTarget {
35
+ readonly http: HttpToolTarget;
36
+ }
37
+ /**
38
+ * A tool the Runtime runs as an HTTP request: it sends the input as JSON to `url` and gives
39
+ * the model the answer. Use it in `.tools(...)` like any tool, or as a flow stage; it has no
40
+ * implementation.
41
+ */
42
+ export declare function http<InputSchema extends ToolInputSchema | JsonObject, OutputSchema extends ToolOutputSchema | JsonObject | undefined = undefined>(options: HttpToolOptions<InputSchema, OutputSchema>): AnyTool;
43
+ /**
44
+ * A Loop's HTTP verifier: the Runtime POSTs `{ input, output, iteration }` to `url` and reads
45
+ * the answer as a verdict, `{ pass: boolean, feedback?: string }`.
46
+ */
47
+ export declare function http(target: HttpToolTarget): HttpTarget;
48
+ /** True for a bare HTTP target made by `http({ url })`. */
49
+ export declare function isHttpTarget(value: unknown): value is HttpTarget;
50
+ /** Rebuilds an HTTP tool from its manifest entry. */
51
+ export declare function httpToolFromManifest(declared: ToolManifest & {
52
+ readonly http: HttpToolTarget;
53
+ }): AnyTool;
54
+ /**
55
+ * Marks `tool` as an HTTP tool. A host gives its own `execute` (the Runtime's engine routes the
56
+ * call to its Tool Gate); without one, calling it explains that only the Runtime runs it.
57
+ * `approval: "always"` makes each call wait for approval.
58
+ */
59
+ export declare function withHttpTarget(tool: Omit<AnyTool, "execute"> & Pick<Partial<AnyTool>, "execute">, target: HttpTool): AnyTool;
60
+ /** The HTTP target behind a tool definition, or behind the bound snapshot of one. */
61
+ export declare function httpToolOf(tool: unknown): HttpTool | undefined;
62
+ /** Why `target` is not a valid HTTP tool target, or undefined. */
63
+ export declare function httpTargetIssue(target: HttpToolTarget): string | undefined;
64
+ /** Why `url` is not an HTTP tool's URL, or undefined. */
65
+ export declare function httpUrlIssue(url: unknown): string | undefined;
66
+ export {};
@@ -0,0 +1,131 @@
1
+ import { HarnessError } from "../errors.js";
2
+ import { ToolError } from "./tool-error.js";
3
+ import { prepareTool } from "./schema.js";
4
+ import { schemaFromJSON } from "./schema-json.js";
5
+ /** Survives duplicate installed copies of core, like the delegate brand. */
6
+ const HTTP = Symbol.for("@nylorun/core/http-tool");
7
+ const TARGET = Symbol.for("@nylorun/core/http-target");
8
+ export const HTTP_TOOL_METHODS = ["POST", "PUT", "PATCH"];
9
+ export const APPROVAL_MODES = ["never", "always"];
10
+ /** How long a service may take to answer when the tool sets no `timeoutMs`. */
11
+ export const HTTP_TOOL_DEFAULT_TIMEOUT_MS = 60_000;
12
+ /** The longest `timeoutMs` a tool may set. */
13
+ export const HTTP_TOOL_MAX_TIMEOUT_MS = 300_000;
14
+ export function http(options) {
15
+ if (!("name" in options) && !("input" in options))
16
+ return httpTarget(options);
17
+ const { name, description, input, output, approval } = options;
18
+ const target = targetOf(options);
19
+ const issue = (input === undefined ? "input is required" : undefined) ?? httpTargetIssue(target) ?? approvalIssue(approval);
20
+ if (issue)
21
+ throw new HarnessError("tool.invalid", `HTTP tool '${name}': ${issue}`);
22
+ return prepareTool(withHttpTarget({
23
+ name,
24
+ ...(description === undefined ? {} : { description }),
25
+ inputSchema: schemaSource(input),
26
+ ...(output === undefined ? {} : { outputSchema: schemaSource(output) }),
27
+ }, { http: target, ...(approval === undefined ? {} : { approval }) }));
28
+ }
29
+ function targetOf({ url, method, credential, timeoutMs }) {
30
+ return {
31
+ url,
32
+ ...(method === undefined ? {} : { method }),
33
+ ...(credential === undefined ? {} : { credential }),
34
+ ...(timeoutMs === undefined ? {} : { timeoutMs }),
35
+ };
36
+ }
37
+ function httpTarget(options) {
38
+ const fields = ["url", "method", "credential", "timeoutMs"];
39
+ const unknown = Object.keys(options).filter((key) => !fields.includes(key));
40
+ if (unknown.length > 0)
41
+ throw new HarnessError("configuration.invalid", `HTTP verifier: unknown option${unknown.length === 1 ? "" : "s"} ${unknown.join(", ")}; an HTTP tool needs a name and an input`);
42
+ const target = targetOf(options);
43
+ const issue = httpTargetIssue(target);
44
+ if (issue)
45
+ throw new HarnessError("configuration.invalid", `HTTP verifier: ${issue}`);
46
+ const value = { http: Object.freeze(target) };
47
+ Object.defineProperty(value, TARGET, { value: true, enumerable: false });
48
+ return Object.freeze(value);
49
+ }
50
+ /** True for a bare HTTP target made by `http({ url })`. */
51
+ export function isHttpTarget(value) {
52
+ return !!value && typeof value === "object" && value[TARGET] === true;
53
+ }
54
+ /** Rebuilds an HTTP tool from its manifest entry. */
55
+ export function httpToolFromManifest(declared) {
56
+ return withHttpTarget({
57
+ name: declared.name,
58
+ ...(declared.description === undefined ? {} : { description: declared.description }),
59
+ inputSchema: schemaFromJSON(declared.inputSchema),
60
+ ...(declared.outputSchema === undefined ? {} : { outputSchema: schemaFromJSON(declared.outputSchema) }),
61
+ }, { http: declared.http, ...(declared.approval === undefined ? {} : { approval: declared.approval }) });
62
+ }
63
+ /**
64
+ * Marks `tool` as an HTTP tool. A host gives its own `execute` (the Runtime's engine routes the
65
+ * call to its Tool Gate); without one, calling it explains that only the Runtime runs it.
66
+ * `approval: "always"` makes each call wait for approval.
67
+ */
68
+ export function withHttpTarget(tool, target) {
69
+ const definition = {
70
+ ...tool,
71
+ execute: tool.execute ?? runtimeOnly,
72
+ ...(target.approval === "always" ? { approval: () => true } : {}),
73
+ };
74
+ Object.defineProperty(definition, HTTP, {
75
+ value: Object.freeze({ http: Object.freeze({ ...target.http }), ...(target.approval ? { approval: target.approval } : {}) }),
76
+ enumerable: false,
77
+ });
78
+ return Object.freeze(definition);
79
+ }
80
+ /** The HTTP target behind a tool definition, or behind the bound snapshot of one. */
81
+ export function httpToolOf(tool) {
82
+ if (tool === null || typeof tool !== "object")
83
+ return undefined;
84
+ const value = tool;
85
+ return value[HTTP] ?? (value.source === tool ? undefined : httpToolOf(value.source));
86
+ }
87
+ /** Why `target` is not a valid HTTP tool target, or undefined. */
88
+ export function httpTargetIssue(target) {
89
+ const url = httpUrlIssue(target.url);
90
+ if (url)
91
+ return url;
92
+ if (target.method !== undefined && !HTTP_TOOL_METHODS.includes(target.method))
93
+ return `method must be one of ${HTTP_TOOL_METHODS.join(", ")}`;
94
+ if (target.credential !== undefined && (typeof target.credential !== "string" || target.credential === ""))
95
+ return "credential must be a non-empty name";
96
+ if (target.timeoutMs !== undefined &&
97
+ (!Number.isInteger(target.timeoutMs) || target.timeoutMs <= 0 || target.timeoutMs > HTTP_TOOL_MAX_TIMEOUT_MS))
98
+ return `timeoutMs must be a positive integer of at most ${HTTP_TOOL_MAX_TIMEOUT_MS}`;
99
+ return undefined;
100
+ }
101
+ /** Why `url` is not an HTTP tool's URL, or undefined. */
102
+ export function httpUrlIssue(url) {
103
+ let parsed;
104
+ try {
105
+ parsed = new URL(String(url));
106
+ }
107
+ catch {
108
+ return "url must be an absolute http or https URL";
109
+ }
110
+ if (typeof url !== "string" || (parsed.protocol !== "http:" && parsed.protocol !== "https:"))
111
+ return "url must be an absolute http or https URL";
112
+ if (parsed.username !== "" || parsed.password !== "")
113
+ return "url must not carry credentials; name a vault credential with `credential`";
114
+ if (parsed.hash !== "")
115
+ return "url must not have a fragment";
116
+ return undefined;
117
+ }
118
+ function approvalIssue(approval) {
119
+ return approval === undefined || APPROVAL_MODES.includes(approval)
120
+ ? undefined
121
+ : `approval must be one of ${APPROVAL_MODES.join(", ")}`;
122
+ }
123
+ async function runtimeOnly() {
124
+ throw new ToolError("http.runtime-only", "HTTP tools are run by the Nylorun Runtime, not in this process");
125
+ }
126
+ /** A schema source as `tool()` takes it, or a JSON Schema object. */
127
+ function schemaSource(value) {
128
+ const candidate = value;
129
+ const authored = typeof candidate.validate === "function" || "~standard" in candidate || "_zod" in candidate;
130
+ return authored ? value : schemaFromJSON(value);
131
+ }
@@ -1,4 +1,3 @@
1
- import type { AfterHooks, BeforeHooks } from "../types/dynamics.js";
2
1
  import type { ToolDefinition } from "../types/tool.js";
3
2
  import type { StepMiddleware } from "../types/middleware.js";
4
3
  /** In-process implementations table keyed by capability id (never serialized). */
@@ -7,8 +6,6 @@ export interface Implementations<Info = unknown> {
7
6
  readonly tools?: {
8
7
  readonly [toolName: string]: ToolDefinition<any, Info, any>;
9
8
  };
10
- readonly before?: BeforeHooks<Info>;
11
- readonly after?: AfterHooks<Info>;
12
9
  /** @deprecated Local engine only through 1.0. */
13
10
  readonly middleware?: StepMiddleware<Info>;
14
11
  };