@nylorun/core 0.19.0-beta → 0.21.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 (98) hide show
  1. package/CHANGELOG.md +191 -0
  2. package/README.md +2 -2
  3. package/dist/compatibility.d.ts +148 -32
  4. package/dist/compatibility.js +154 -33
  5. package/dist/contracts.d.ts +2714 -495
  6. package/dist/contracts.js +1395 -493
  7. package/dist/define.d.ts +15 -12
  8. package/dist/define.js +11 -7
  9. package/dist/definition/approval.d.ts +16 -0
  10. package/dist/definition/approval.js +33 -0
  11. package/dist/definition/assemble.d.ts +6 -10
  12. package/dist/definition/assemble.js +48 -105
  13. package/dist/definition/bind-agent.d.ts +3 -4
  14. package/dist/definition/bind-agent.js +12 -30
  15. package/dist/definition/binding.d.ts +2 -2
  16. package/dist/definition/bound.d.ts +10 -10
  17. package/dist/definition/builder.d.ts +16 -20
  18. package/dist/definition/builder.js +29 -81
  19. package/dist/definition/code-tools.d.ts +4 -4
  20. package/dist/definition/code-tools.js +7 -22
  21. package/dist/definition/declaration.d.ts +4 -7
  22. package/dist/definition/declaration.js +29 -99
  23. package/dist/definition/{tools-capability.d.ts → deferred-tools.d.ts} +3 -13
  24. package/dist/definition/{tools-capability.js → deferred-tools.js} +2 -18
  25. package/dist/definition/delegate.d.ts +2 -4
  26. package/dist/definition/delegate.js +8 -10
  27. package/dist/definition/flow/compile.js +0 -2
  28. package/dist/definition/from.d.ts +7 -4
  29. package/dist/definition/from.js +72 -117
  30. package/dist/definition/helpers.d.ts +0 -7
  31. package/dist/definition/helpers.js +0 -5
  32. package/dist/definition/http-tool.d.ts +7 -4
  33. package/dist/definition/http-tool.js +6 -10
  34. package/dist/definition/implementations.d.ts +6 -8
  35. package/dist/definition/manifest.d.ts +11 -5
  36. package/dist/definition/manifest.js +27 -26
  37. package/dist/definition/mcp.d.ts +1 -52
  38. package/dist/definition/mcp.js +11 -60
  39. package/dist/definition/media-reference.d.ts +23 -0
  40. package/dist/definition/media-reference.js +26 -0
  41. package/dist/definition/removed.d.ts +3 -10
  42. package/dist/definition/removed.js +10 -17
  43. package/dist/definition/runtime-manifest.d.ts +30 -0
  44. package/dist/definition/runtime-manifest.js +132 -0
  45. package/dist/definition/sandbox-tools.d.ts +1 -1
  46. package/dist/definition/sandbox-tools.js +1 -1
  47. package/dist/definition/skill-tools.d.ts +13 -7
  48. package/dist/definition/skill-tools.js +23 -10
  49. package/dist/definition/trace.d.ts +18 -0
  50. package/dist/definition/trace.js +42 -0
  51. package/dist/definition/variant.d.ts +5 -4
  52. package/dist/definition/variant.js +23 -55
  53. package/dist/definition/workflow/runnable.js +1 -1
  54. package/dist/errors.d.ts +1 -1
  55. package/dist/harness-api/entries.d.ts +242 -0
  56. package/dist/harness-api/entries.js +118 -0
  57. package/dist/harness-api/gates.d.ts +167 -0
  58. package/dist/harness-api/gates.js +117 -0
  59. package/dist/harness-api/harness-api.schema.json +4975 -0
  60. package/dist/harness-api/index.d.ts +19 -3
  61. package/dist/harness-api/index.js +16 -3
  62. package/dist/harness-api/json-schema.d.ts +12 -0
  63. package/dist/harness-api/json-schema.js +61 -0
  64. package/dist/harness-api/mcp.d.ts +57 -0
  65. package/dist/harness-api/mcp.js +39 -0
  66. package/dist/harness-api/messages.d.ts +11 -5
  67. package/dist/harness-api/messages.js +5 -3
  68. package/dist/harness-api/schema.d.ts +346 -36
  69. package/dist/harness-api/schema.js +143 -22
  70. package/dist/harness-api/transport.d.ts +55 -0
  71. package/dist/harness-api/transport.js +61 -0
  72. package/dist/index.d.ts +1 -1
  73. package/dist/manifest-schemas.d.ts +6 -0
  74. package/dist/manifest-schemas.js +34 -0
  75. package/dist/schemas/agent-manifest.schema.json +897 -0
  76. package/dist/schemas/environment-manifest.schema.json +329 -0
  77. package/dist/types/agent.d.ts +1 -1
  78. package/dist/types/manifest.d.ts +48 -28
  79. package/dist/types/model.d.ts +2 -2
  80. package/dist/types/observe.d.ts +8 -20
  81. package/dist/types/part.d.ts +25 -0
  82. package/dist/types/tool.d.ts +1 -1
  83. package/dist/types/transcript.d.ts +5 -0
  84. package/dist/utils/definition-files.d.ts +11 -6
  85. package/dist/utils/definition-files.js +19 -9
  86. package/dist/utils/harness-id.d.ts +9 -0
  87. package/dist/utils/harness-id.js +11 -0
  88. package/dist/utils/runtime-tools.d.ts +19 -0
  89. package/dist/utils/runtime-tools.js +30 -0
  90. package/dist/utils/sandbox.d.ts +1 -1
  91. package/dist/utils/sandbox.js +1 -1
  92. package/package.json +11 -4
  93. package/dist/definition/capability.d.ts +0 -43
  94. package/dist/definition/capability.js +0 -82
  95. package/dist/definition/sandbox-capability.d.ts +0 -44
  96. package/dist/definition/sandbox-capability.js +0 -139
  97. package/dist/types/middleware.d.ts +0 -94
  98. /package/dist/types/{middleware.js → part.js} +0 -0
@@ -8,7 +8,7 @@ function toolsByName(tools) {
8
8
  map.set(tool.name, tool);
9
9
  return map;
10
10
  }
11
- /** Candidate tools/skills/agents-as-tools may only be removed, never added or changed. */
11
+ /** Candidate tools (agents used as tools included) may only be removed, never added or changed. */
12
12
  function removeOnlyTools(pinned, candidate) {
13
13
  const base = toolsByName(pinned);
14
14
  for (const tool of candidate ?? []) {
@@ -18,28 +18,20 @@ function removeOnlyTools(pinned, candidate) {
18
18
  }
19
19
  return true;
20
20
  }
21
- function removeOnlySkills(pinned, candidate) {
22
- const base = pinned ?? {};
23
- for (const [name, skill] of Object.entries(candidate ?? {})) {
24
- const prior = base[name];
25
- if (!prior || !same(prior, skill))
26
- return false;
27
- }
28
- return true;
29
- }
30
21
  /**
31
22
  * One tool setting, or the `"*"` entry, only tightened (R2b C9, Q18): `enabled` kept or set to
32
- * `false`, `approval` kept or set to `always`, `deferred` kept. Each level of a tool's resolution
33
- * (its entry, then `"*"`) either keeps its value or tightens it, so the tool does too.
23
+ * `false`, `approval` and `deferred` kept. Each level of a tool's resolution (its entry, then
24
+ * `"*"`) either keeps its value or tightens it, so the tool does too. A variant adds no
25
+ * approval: tool approvals are the Tenant's tool policy (R5 step 2).
34
26
  */
35
27
  function tightensSettings(prior, next) {
36
28
  return ((next.enabled === prior?.enabled || next.enabled === false) &&
37
- (next.approval === prior?.approval || next.approval === "always") &&
29
+ next.approval === prior?.approval &&
38
30
  next.deferred === prior?.deferred);
39
31
  }
40
32
  /**
41
33
  * The servers of a turn variant: the pinned ones, the same but for their `tools` maps, where a
42
- * variant may only disable a tool or require its approval (R2b C9, Q18). An entry the pin has
34
+ * variant may only disable a tool (R2b C9, Q18). An entry the pin has
43
35
  * stays, since dropping one could widen.
44
36
  */
45
37
  function tightensServers(pinned, candidate) {
@@ -62,51 +54,27 @@ function tightensServers(pinned, candidate) {
62
54
  });
63
55
  }
64
56
  /**
65
- * Whether `candidate` is a valid turn-manifest variant of the session's pinned
66
- * manifest (`loops.md` §3.4). Setup (MCP, sandbox) is fixed, but a variant may disable an MCP
67
- * server's tools or require their approval (R2b C9, Q18);
68
- * code-backed tools/skills/agents-as-tools are remove-only; plain data may change.
57
+ * Whether `candidate` is a valid turn-manifest variant of the session's pinned manifest
58
+ * (`loops.md` §3.4). A variant may remove tools (agents used as tools and HTTP tools included),
59
+ * tighten its MCP servers' tool settings (R2b C9, Q18), and change its instructions, name,
60
+ * description and metadata. Its skills and servers are setup: the sandbox holds the skills from
61
+ * the session's start. It never sets `runtime`; the turn runs with the pin's.
69
62
  */
70
63
  export function isVariantOf(candidate, pinned) {
71
64
  if (candidate.id !== pinned.id)
72
65
  return false;
73
- // A variant of a v5 pin may be v6, to set an MCP server's tools; never older than its pin.
74
- if (candidate.manifestSchemaVersion < pinned.manifestSchemaVersion)
66
+ if (candidate.manifestSchemaVersion !== pinned.manifestSchemaVersion)
75
67
  return false;
76
- if (!same(candidate.runtime ?? {}, pinned.runtime ?? {}))
68
+ if (candidate.runtime !== undefined)
77
69
  return false;
78
- const pinnedById = new Map(pinned.capabilities.map((capability) => [capability.id, capability]));
79
- const candidateById = new Map(candidate.capabilities.map((capability) => [capability.id, capability]));
80
- for (const [, prior] of pinnedById) {
81
- const next = candidateById.get(prior.id);
82
- // Setup — and any capability that declares it — must not change or be removed.
83
- if (prior.mcpServers !== undefined) {
84
- if (!next || !tightensServers(prior.mcpServers, next.mcpServers))
85
- return false;
86
- }
87
- if (prior.sandbox !== undefined) {
88
- if (!next || !same(next.sandbox, prior.sandbox))
89
- return false;
90
- }
91
- }
92
- for (const [id, next] of candidateById) {
93
- const prior = pinnedById.get(id);
94
- if (!prior)
95
- return false; // cannot add capabilities
96
- if (next.type !== prior.type)
97
- return false;
98
- if (!removeOnlyTools(prior.tools, next.tools))
99
- return false;
100
- if (!removeOnlySkills(prior.skills, next.skills))
101
- return false;
102
- // Free: name, description, metadata, instructions (and model once it exists).
103
- if (!tightensServers(prior.mcpServers, next.mcpServers))
104
- return false;
105
- if (!same(next.sandbox, prior.sandbox))
106
- return false;
107
- }
108
- // Dropping a capability is allowed only when it had no MCP / sandbox
109
- // (those are enforced above). Tools and skills on a dropped capability are
110
- // removals, which §3.4 permits.
111
- return true;
70
+ if (!same(candidate.outputSchema, pinned.outputSchema))
71
+ return false;
72
+ // What the agent needs of its Environment was checked when the session opened (D65).
73
+ if (!same(candidate.requires, pinned.requires))
74
+ return false;
75
+ if (!removeOnlyTools(pinned.tools, candidate.tools))
76
+ return false;
77
+ if (!same(candidate.skills, pinned.skills))
78
+ return false;
79
+ return tightensServers(pinned.mcpServers, candidate.mcpServers);
112
80
  }
@@ -60,7 +60,7 @@ export function bindToolNode(tool) {
60
60
  execute: execute.bind(normalized),
61
61
  ...(normalized.approval === undefined ? {} : { approval: normalized.approval }),
62
62
  ...(normalized.effects === undefined ? {} : { effects: normalized.effects }),
63
- owner: Object.freeze({ middlewareId: "workflow", slot: "tool-node" }),
63
+ owner: Object.freeze({ partId: "workflow", slot: "tool-node" }),
64
64
  });
65
65
  }
66
66
  /** Normalize a schema for a workflow tool node (any JSON Schema root type allowed). */
package/dist/errors.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /** Machine-readable error raised by Harness-owned code. */
2
- export type HarnessErrorCode = "execution.invalid-state" | "execution.invalid-input" | "execution.incompatible" | "execution.record-failed" | "tool.unregistered" | "tool.invalid-binding" | "agent.build-failed" | "agent.lifecycle-sealed" | "context.invalid-item" | "context.invalid-item-type" | "context.invalid-order" | "context.invalid-reason" | "context.invalid-slot" | "interaction.invalid" | "interaction.missing-resume" | "interaction.uncorrelated-resume" | "input.invalid-content" | "output.invalid" | "output.invalid-schema" | "json.invalid-data" | "json.invalid-object" | "middleware.next-after-return" | "middleware.next-called-twice" | "middleware.request-mutators-revoked" | "model.candidate-missing" | "model.adapter-invalid-options" | "model.adapter-invalid-response" | "model.invalid-candidate" | "model.invalid-directive" | "model.unsupported-content" | "model.unsupported-output-schema"
2
+ export type HarnessErrorCode = "execution.invalid-state" | "execution.invalid-input" | "execution.incompatible" | "execution.record-failed" | "tool.unregistered" | "tool.invalid-binding" | "agent.build-failed" | "agent.lifecycle-sealed" | "context.invalid-item" | "context.invalid-item-type" | "context.invalid-order" | "context.invalid-reason" | "context.invalid-slot" | "interaction.invalid" | "interaction.missing-resume" | "interaction.uncorrelated-resume" | "input.invalid-content" | "output.invalid" | "output.invalid-schema" | "json.invalid-data" | "json.invalid-object" | "model.candidate-missing" | "model.adapter-invalid-options" | "model.adapter-invalid-response" | "model.invalid-candidate" | "model.invalid-directive" | "model.unsupported-content" | "model.unsupported-output-schema"
3
3
  /** A provider failure the model adapter classified (Model Calls §6.1). */
4
4
  | `model.${import("./types/model.js").ModelFailureCode}` | "configuration.duplicate-tool-name" | "configuration.invalid" | "configuration.invalid-instructions" | "configuration.invalid-order" | "configuration.invalid-reason" | "configuration.invalid-slot" | "configuration.invalid-tools" | "configuration.model-selection-conflict" | "response.invalid-replacement" | "tool.invalid" | "tool.invalid-arguments" | "tool.invalid-output" | "tool.invalid-name" | "tool.invalid-schema" | "tool.invalid-tool-result";
5
5
  export type HarnessErrorDetails = Readonly<Record<string, string | number | boolean>>;
@@ -0,0 +1,242 @@
1
+ /**
2
+ * What a harness writes into the session's record besides its effects (R4.5): transcript
3
+ * entries, and the effect id rule replays depend on.
4
+ *
5
+ * Transcript. A session's transcript is shared by every turn: a run reads it once
6
+ * (`transcript.read`), and its output edits it (`TurnOutput.transcript`, a list of
7
+ * `TranscriptUpdate`s whose `entries` are `TranscriptEntry`s). History, `transcript.read` and the
8
+ * next turn's cursor fold these edits, so a harness writes the five published kinds only.
9
+ *
10
+ * Effect ids. Core hands a run the completed outcomes of its segment whose effect id starts with
11
+ * `<turnId>:<segment>:`, and a harness replays them instead of calling again. An id must be
12
+ * derived from stable names, never call order, so a run that starts over asks for the same ids.
13
+ */
14
+ import { z } from "zod";
15
+ /** One block of a model candidate's output. */
16
+ export declare const ModelOutputBlockSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
17
+ type: z.ZodLiteral<"text">;
18
+ text: z.ZodString;
19
+ providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
20
+ }, z.core.$strip>, z.ZodObject<{
21
+ type: z.ZodLiteral<"reasoning">;
22
+ text: z.ZodString;
23
+ providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
24
+ }, z.core.$strip>, z.ZodObject<{
25
+ type: z.ZodLiteral<"json">;
26
+ value: z.ZodUnknown;
27
+ }, z.core.$strip>, z.ZodObject<{
28
+ type: z.ZodLiteral<"tool-call">;
29
+ id: z.ZodString;
30
+ name: z.ZodString;
31
+ args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
32
+ raw: z.ZodOptional<z.ZodString>;
33
+ providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
34
+ }, z.core.$strip>], "type">;
35
+ /** A model's answer: what the Model Gate's `outcome` is when the call worked. */
36
+ export declare const ModelCandidateSchema: z.ZodObject<{
37
+ output: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
38
+ type: z.ZodLiteral<"text">;
39
+ text: z.ZodString;
40
+ providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
41
+ }, z.core.$strip>, z.ZodObject<{
42
+ type: z.ZodLiteral<"reasoning">;
43
+ text: z.ZodString;
44
+ providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
45
+ }, z.core.$strip>, z.ZodObject<{
46
+ type: z.ZodLiteral<"json">;
47
+ value: z.ZodUnknown;
48
+ }, z.core.$strip>, z.ZodObject<{
49
+ type: z.ZodLiteral<"tool-call">;
50
+ id: z.ZodString;
51
+ name: z.ZodString;
52
+ args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
53
+ raw: z.ZodOptional<z.ZodString>;
54
+ providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
55
+ }, z.core.$strip>], "type">>;
56
+ finishReason: z.ZodOptional<z.ZodEnum<{
57
+ "content-filter": "content-filter";
58
+ length: "length";
59
+ other: "other";
60
+ stop: "stop";
61
+ "tool-calls": "tool-calls";
62
+ }>>;
63
+ usage: z.ZodOptional<z.ZodObject<{
64
+ inputTokens: z.ZodOptional<z.ZodNumber>;
65
+ outputTokens: z.ZodOptional<z.ZodNumber>;
66
+ totalTokens: z.ZodOptional<z.ZodNumber>;
67
+ cachedTokens: z.ZodOptional<z.ZodNumber>;
68
+ cacheWriteTokens: z.ZodOptional<z.ZodNumber>;
69
+ reasoningTokens: z.ZodOptional<z.ZodNumber>;
70
+ costUsd: z.ZodOptional<z.ZodNumber>;
71
+ }, z.core.$strip>>;
72
+ evidence: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
73
+ }, z.core.$strip>;
74
+ /** One tool call's result, as the model sees it next. */
75
+ export declare const ToolResultSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
76
+ callId: z.ZodString;
77
+ toolName: z.ZodString;
78
+ kind: z.ZodLiteral<"completed">;
79
+ output: z.ZodUnknown;
80
+ files: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
81
+ }, z.core.$strip>, z.ZodObject<{
82
+ callId: z.ZodString;
83
+ toolName: z.ZodString;
84
+ kind: z.ZodLiteral<"denied">;
85
+ reason: z.ZodString;
86
+ }, z.core.$strip>, z.ZodObject<{
87
+ callId: z.ZodString;
88
+ toolName: z.ZodString;
89
+ kind: z.ZodLiteral<"failed">;
90
+ code: z.ZodString;
91
+ message: z.ZodString;
92
+ details: z.ZodOptional<z.ZodUnknown>;
93
+ retryable: z.ZodOptional<z.ZodBoolean>;
94
+ }, z.core.$strip>], "kind">;
95
+ /** What started a turn: a user message (text or content parts), or an answer to a question. */
96
+ export declare const InputEventSchema: z.ZodUnion<readonly [z.ZodObject<{
97
+ kind: z.ZodEnum<{
98
+ interrupt: "interrupt";
99
+ "user-message": "user-message";
100
+ }>;
101
+ text: z.ZodString;
102
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
103
+ }, z.core.$strip>, z.ZodObject<{
104
+ kind: z.ZodEnum<{
105
+ interrupt: "interrupt";
106
+ "user-message": "user-message";
107
+ }>;
108
+ content: z.ZodArray<z.ZodUnknown>;
109
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
110
+ }, z.core.$strip>, z.ZodObject<{
111
+ kind: z.ZodLiteral<"approve">;
112
+ interactionId: z.ZodString;
113
+ approved: z.ZodBoolean;
114
+ }, z.core.$strip>, z.ZodObject<{
115
+ kind: z.ZodLiteral<"respond">;
116
+ interactionId: z.ZodString;
117
+ value: z.ZodUnknown;
118
+ }, z.core.$strip>]>;
119
+ /**
120
+ * One transcript entry. Every entry names its turn; a step's entries share a `stepId` (the model
121
+ * candidate, then its tools' results). `compaction` is always first: a summary that replaced the
122
+ * older part, followed by the kept tail.
123
+ */
124
+ export declare const TranscriptEntrySchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
125
+ kind: z.ZodLiteral<"input">;
126
+ turnId: z.ZodString;
127
+ event: z.ZodUnion<readonly [z.ZodObject<{
128
+ kind: z.ZodEnum<{
129
+ interrupt: "interrupt";
130
+ "user-message": "user-message";
131
+ }>;
132
+ text: z.ZodString;
133
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
134
+ }, z.core.$strip>, z.ZodObject<{
135
+ kind: z.ZodEnum<{
136
+ interrupt: "interrupt";
137
+ "user-message": "user-message";
138
+ }>;
139
+ content: z.ZodArray<z.ZodUnknown>;
140
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
141
+ }, z.core.$strip>, z.ZodObject<{
142
+ kind: z.ZodLiteral<"approve">;
143
+ interactionId: z.ZodString;
144
+ approved: z.ZodBoolean;
145
+ }, z.core.$strip>, z.ZodObject<{
146
+ kind: z.ZodLiteral<"respond">;
147
+ interactionId: z.ZodString;
148
+ value: z.ZodUnknown;
149
+ }, z.core.$strip>]>;
150
+ }, z.core.$strip>, z.ZodObject<{
151
+ kind: z.ZodLiteral<"candidate">;
152
+ turnId: z.ZodString;
153
+ stepId: z.ZodString;
154
+ candidate: z.ZodObject<{
155
+ output: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
156
+ type: z.ZodLiteral<"text">;
157
+ text: z.ZodString;
158
+ providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
159
+ }, z.core.$strip>, z.ZodObject<{
160
+ type: z.ZodLiteral<"reasoning">;
161
+ text: z.ZodString;
162
+ providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
163
+ }, z.core.$strip>, z.ZodObject<{
164
+ type: z.ZodLiteral<"json">;
165
+ value: z.ZodUnknown;
166
+ }, z.core.$strip>, z.ZodObject<{
167
+ type: z.ZodLiteral<"tool-call">;
168
+ id: z.ZodString;
169
+ name: z.ZodString;
170
+ args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
171
+ raw: z.ZodOptional<z.ZodString>;
172
+ providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
173
+ }, z.core.$strip>], "type">>;
174
+ finishReason: z.ZodOptional<z.ZodEnum<{
175
+ "content-filter": "content-filter";
176
+ length: "length";
177
+ other: "other";
178
+ stop: "stop";
179
+ "tool-calls": "tool-calls";
180
+ }>>;
181
+ usage: z.ZodOptional<z.ZodObject<{
182
+ inputTokens: z.ZodOptional<z.ZodNumber>;
183
+ outputTokens: z.ZodOptional<z.ZodNumber>;
184
+ totalTokens: z.ZodOptional<z.ZodNumber>;
185
+ cachedTokens: z.ZodOptional<z.ZodNumber>;
186
+ cacheWriteTokens: z.ZodOptional<z.ZodNumber>;
187
+ reasoningTokens: z.ZodOptional<z.ZodNumber>;
188
+ costUsd: z.ZodOptional<z.ZodNumber>;
189
+ }, z.core.$strip>>;
190
+ evidence: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
191
+ }, z.core.$strip>;
192
+ }, z.core.$strip>, z.ZodObject<{
193
+ kind: z.ZodLiteral<"tool-results">;
194
+ turnId: z.ZodString;
195
+ stepId: z.ZodString;
196
+ results: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
197
+ callId: z.ZodString;
198
+ toolName: z.ZodString;
199
+ kind: z.ZodLiteral<"completed">;
200
+ output: z.ZodUnknown;
201
+ files: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
202
+ }, z.core.$strip>, z.ZodObject<{
203
+ callId: z.ZodString;
204
+ toolName: z.ZodString;
205
+ kind: z.ZodLiteral<"denied">;
206
+ reason: z.ZodString;
207
+ }, z.core.$strip>, z.ZodObject<{
208
+ callId: z.ZodString;
209
+ toolName: z.ZodString;
210
+ kind: z.ZodLiteral<"failed">;
211
+ code: z.ZodString;
212
+ message: z.ZodString;
213
+ details: z.ZodOptional<z.ZodUnknown>;
214
+ retryable: z.ZodOptional<z.ZodBoolean>;
215
+ }, z.core.$strip>], "kind">>;
216
+ }, z.core.$strip>, z.ZodObject<{
217
+ kind: z.ZodLiteral<"final">;
218
+ turnId: z.ZodString;
219
+ stepId: z.ZodString;
220
+ output: z.ZodUnknown;
221
+ }, z.core.$strip>, z.ZodObject<{
222
+ kind: z.ZodLiteral<"compaction">;
223
+ turnId: z.ZodString;
224
+ stepId: z.ZodString;
225
+ summary: z.ZodString;
226
+ trigger: z.ZodEnum<{
227
+ overflow: "overflow";
228
+ threshold: "threshold";
229
+ }>;
230
+ tokensBefore: z.ZodNumber;
231
+ tokensAfter: z.ZodNumber;
232
+ files: z.ZodOptional<z.ZodArray<z.ZodString>>;
233
+ }, z.core.$strip>], "kind">;
234
+ /** The prefix every effect id of a segment carries. */
235
+ export declare function effectIdPrefix(turnId: string, segment: number): string;
236
+ /**
237
+ * An effect's id: `<turnId>:<segment>:<kind>:<identity>`, where `identity` names the effect
238
+ * stably within the segment (the model step's invocation id, a tool call's id).
239
+ */
240
+ export declare function effectIdOf(turnId: string, segment: number, kind: string, identity: string): string;
241
+ /** True when `effectId` is one of the segment's, so core replays its outcome to the segment. */
242
+ export declare function isEffectIdOf(effectId: string, turnId: string, segment: number): boolean;
@@ -0,0 +1,118 @@
1
+ /**
2
+ * What a harness writes into the session's record besides its effects (R4.5): transcript
3
+ * entries, and the effect id rule replays depend on.
4
+ *
5
+ * Transcript. A session's transcript is shared by every turn: a run reads it once
6
+ * (`transcript.read`), and its output edits it (`TurnOutput.transcript`, a list of
7
+ * `TranscriptUpdate`s whose `entries` are `TranscriptEntry`s). History, `transcript.read` and the
8
+ * next turn's cursor fold these edits, so a harness writes the five published kinds only.
9
+ *
10
+ * Effect ids. Core hands a run the completed outcomes of its segment whose effect id starts with
11
+ * `<turnId>:<segment>:`, and a harness replays them instead of calling again. An id must be
12
+ * derived from stable names, never call order, so a run that starts over asks for the same ids.
13
+ */
14
+ import { z } from "zod";
15
+ const json = z.unknown();
16
+ const jsonObject = z.record(z.string(), z.unknown());
17
+ /** One block of a model candidate's output. */
18
+ export const ModelOutputBlockSchema = z.discriminatedUnion("type", [
19
+ z.object({ type: z.literal("text"), text: z.string(), providerMetadata: jsonObject.optional() }),
20
+ z.object({ type: z.literal("reasoning"), text: z.string(), providerMetadata: jsonObject.optional() }),
21
+ z.object({ type: z.literal("json"), value: json }),
22
+ z.object({
23
+ type: z.literal("tool-call"),
24
+ id: z.string(),
25
+ name: z.string(),
26
+ args: jsonObject,
27
+ raw: z.string().optional(),
28
+ providerMetadata: jsonObject.optional(),
29
+ }),
30
+ ]);
31
+ /** A model's answer: what the Model Gate's `outcome` is when the call worked. */
32
+ export const ModelCandidateSchema = z.object({
33
+ output: z.array(ModelOutputBlockSchema),
34
+ finishReason: z.enum(["stop", "length", "tool-calls", "content-filter", "other"]).optional(),
35
+ usage: z
36
+ .object({
37
+ inputTokens: z.number().optional(),
38
+ outputTokens: z.number().optional(),
39
+ totalTokens: z.number().optional(),
40
+ cachedTokens: z.number().optional(),
41
+ cacheWriteTokens: z.number().optional(),
42
+ reasoningTokens: z.number().optional(),
43
+ costUsd: z.number().optional(),
44
+ })
45
+ .optional(),
46
+ evidence: jsonObject.optional(),
47
+ });
48
+ /** One tool call's result, as the model sees it next. */
49
+ export const ToolResultSchema = z.discriminatedUnion("kind", [
50
+ z.object({
51
+ callId: z.string(),
52
+ toolName: z.string(),
53
+ kind: z.literal("completed"),
54
+ output: json,
55
+ files: z.array(json).optional(),
56
+ }),
57
+ z.object({ callId: z.string(), toolName: z.string(), kind: z.literal("denied"), reason: z.string() }),
58
+ z.object({
59
+ callId: z.string(),
60
+ toolName: z.string(),
61
+ kind: z.literal("failed"),
62
+ code: z.string(),
63
+ message: z.string(),
64
+ details: json.optional(),
65
+ retryable: z.boolean().optional(),
66
+ }),
67
+ ]);
68
+ /** What started a turn: a user message (text or content parts), or an answer to a question. */
69
+ export const InputEventSchema = z.union([
70
+ z.object({
71
+ kind: z.enum(["user-message", "interrupt"]),
72
+ text: z.string(),
73
+ metadata: jsonObject.optional(),
74
+ }),
75
+ z.object({
76
+ kind: z.enum(["user-message", "interrupt"]),
77
+ content: z.array(json),
78
+ metadata: jsonObject.optional(),
79
+ }),
80
+ z.object({ kind: z.literal("approve"), interactionId: z.string(), approved: z.boolean() }),
81
+ z.object({ kind: z.literal("respond"), interactionId: z.string(), value: json }),
82
+ ]);
83
+ /**
84
+ * One transcript entry. Every entry names its turn; a step's entries share a `stepId` (the model
85
+ * candidate, then its tools' results). `compaction` is always first: a summary that replaced the
86
+ * older part, followed by the kept tail.
87
+ */
88
+ export const TranscriptEntrySchema = z.discriminatedUnion("kind", [
89
+ z.object({ kind: z.literal("input"), turnId: z.string(), event: InputEventSchema }),
90
+ z.object({ kind: z.literal("candidate"), turnId: z.string(), stepId: z.string(), candidate: ModelCandidateSchema }),
91
+ z.object({ kind: z.literal("tool-results"), turnId: z.string(), stepId: z.string(), results: z.array(ToolResultSchema) }),
92
+ z.object({ kind: z.literal("final"), turnId: z.string(), stepId: z.string(), output: json }),
93
+ z.object({
94
+ kind: z.literal("compaction"),
95
+ turnId: z.string(),
96
+ stepId: z.string(),
97
+ summary: z.string(),
98
+ trigger: z.enum(["threshold", "overflow"]),
99
+ tokensBefore: z.number(),
100
+ tokensAfter: z.number(),
101
+ files: z.array(z.string()).optional(),
102
+ }),
103
+ ]);
104
+ /** The prefix every effect id of a segment carries. */
105
+ export function effectIdPrefix(turnId, segment) {
106
+ return `${turnId}:${segment}:`;
107
+ }
108
+ /**
109
+ * An effect's id: `<turnId>:<segment>:<kind>:<identity>`, where `identity` names the effect
110
+ * stably within the segment (the model step's invocation id, a tool call's id).
111
+ */
112
+ export function effectIdOf(turnId, segment, kind, identity) {
113
+ return `${effectIdPrefix(turnId, segment)}${kind}:${identity}`;
114
+ }
115
+ /** True when `effectId` is one of the segment's, so core replays its outcome to the segment. */
116
+ export function isEffectIdOf(effectId, turnId, segment) {
117
+ return effectId.startsWith(effectIdPrefix(turnId, segment));
118
+ }
@@ -0,0 +1,167 @@
1
+ /**
2
+ * The gates a harness calls (R4.5): the Model Gate and the Tool Gate, on the gateway's port. A
3
+ * harness never holds a model or tool credential: it presents the run token of the run it holds
4
+ * (`RunGrant.token`) as `Authorization: Bearer`, and the gate takes the session, turn and agent
5
+ * from the token. Every call is keyed by its effect id, sent as `Idempotency-Key`: a re-send
6
+ * with the same key and body joins the call or gets its outcome, so a harness that lost an
7
+ * answer sends the call again instead of guessing.
8
+ *
9
+ * Model Gate. `POST /nylorun/v1/model-calls` with a `ModelCallBody`: `200 {outcome}` once the
10
+ * call has finished, a model candidate or a failure outcome. `POST
11
+ * /nylorun/v1/model-calls/{key}/cancel` aborts a keyed call (`204`).
12
+ *
13
+ * Tool Gate. Remote MCP servers by name (`mcp/connect`, `mcp/list`, `tool-calls`, `mcp/close`)
14
+ * and HTTP tools by tool (`http-calls`); `tool-calls/{key}/cancel` aborts either. Each answers
15
+ * `200 {ok: true, result}` or `200 {ok: false, error}`: a tool's failure is an answer, not a
16
+ * gate error.
17
+ *
18
+ * A gate error is `{error: {code, message}}` with one of `GATE_ERROR_CODES`: `401
19
+ * gate_unauthorized` (missing, malformed, expired or foreign token), `403 gate_forbidden`
20
+ * (another session's call), `409 run_stale` (the token's lease is no longer the session's),
21
+ * `400 invalid_request`, `409 gate_conflict` (another request runs under the same key). A run's
22
+ * tool call must be journaled first (`effect.intent` answered `execute`) and keyed by its effect
23
+ * id: else `400 key_required` or `409 effect_not_journaled`.
24
+ */
25
+ import { z } from "zod";
26
+ import type { ModelCall, ModelCandidate, ModelFailureOutcome } from "../types/model.js";
27
+ export declare const MODEL_CALLS_PATH = "/nylorun/v1/model-calls";
28
+ export declare const MCP_CONNECT_PATH = "/nylorun/v1/mcp/connect";
29
+ export declare const MCP_LIST_PATH = "/nylorun/v1/mcp/list";
30
+ export declare const MCP_CLOSE_PATH = "/nylorun/v1/mcp/close";
31
+ export declare const TOOL_CALLS_PATH = "/nylorun/v1/tool-calls";
32
+ export declare const HTTP_CALLS_PATH = "/nylorun/v1/http-calls";
33
+ /** Largest model call body the gate reads: one `ModelCall` with its whole projected history. */
34
+ export declare const MAX_MODEL_CALL_BYTES: number;
35
+ /** Largest tool call body the gate reads. */
36
+ export declare const MAX_TOOL_BODY_BYTES: number;
37
+ /**
38
+ * One model call. It names no session, turn or agent: the gate takes them from the run token,
39
+ * and refuses a body that names them. `call` is the engine's `ModelCall`.
40
+ */
41
+ export declare const ModelCallBodySchema: z.ZodObject<{
42
+ effectId: z.ZodString;
43
+ invocationId: z.ZodString;
44
+ call: z.ZodObject<{
45
+ prompt: z.ZodArray<z.ZodUnknown>;
46
+ tools: z.ZodArray<z.ZodObject<{
47
+ name: z.ZodString;
48
+ }, z.core.$loose>>;
49
+ }, z.core.$loose>;
50
+ }, z.core.$strict>;
51
+ export type ModelCallBody = Omit<z.infer<typeof ModelCallBodySchema>, "call"> & {
52
+ readonly call: ModelCall;
53
+ };
54
+ /** What a model call answers: a candidate, or a failure the engine fails its step with. */
55
+ export interface ModelCallResponse {
56
+ readonly outcome: ModelCandidate | ModelFailureOutcome;
57
+ }
58
+ export declare const GATE_ERROR_CODES: readonly ["gate_unauthorized", "gate_forbidden", "run_stale", "invalid_request", "gate_conflict",
59
+ /** A run's tool call without its effect id as `Idempotency-Key`. */
60
+ "key_required",
61
+ /** A run's tool call the effect journal does not hold, running, as sent: journal it first. */
62
+ "effect_not_journaled"];
63
+ export type GateErrorCode = (typeof GATE_ERROR_CODES)[number];
64
+ /** An error answer: `{error: {code, message}}`. */
65
+ export declare const GateErrorBodySchema: z.ZodObject<{
66
+ error: z.ZodObject<{
67
+ code: z.ZodEnum<{
68
+ effect_not_journaled: "effect_not_journaled";
69
+ gate_conflict: "gate_conflict";
70
+ gate_forbidden: "gate_forbidden";
71
+ gate_unauthorized: "gate_unauthorized";
72
+ invalid_request: "invalid_request";
73
+ key_required: "key_required";
74
+ run_stale: "run_stale";
75
+ }>;
76
+ message: z.ZodString;
77
+ }, z.core.$strict>;
78
+ }, z.core.$strict>;
79
+ export type GateErrorBody = z.infer<typeof GateErrorBodySchema>;
80
+ /** A remote MCP server of the session's pinned manifest, by name. */
81
+ export declare const McpServerRefSchema: z.ZodObject<{
82
+ sessionId: z.ZodOptional<z.ZodString>;
83
+ agentId: z.ZodOptional<z.ZodString>;
84
+ serverName: z.ZodString;
85
+ }, z.core.$strip>;
86
+ export type McpServerRef = z.infer<typeof McpServerRefSchema>;
87
+ /** `mcp/connect` and `mcp/close`. */
88
+ export declare const McpServerBodySchema: z.ZodObject<{
89
+ server: z.ZodObject<{
90
+ sessionId: z.ZodOptional<z.ZodString>;
91
+ agentId: z.ZodOptional<z.ZodString>;
92
+ serverName: z.ZodString;
93
+ }, z.core.$strip>;
94
+ }, z.core.$strip>;
95
+ /** `mcp/list`: one page of `tools/list`. */
96
+ export declare const McpListBodySchema: z.ZodObject<{
97
+ server: z.ZodObject<{
98
+ sessionId: z.ZodOptional<z.ZodString>;
99
+ agentId: z.ZodOptional<z.ZodString>;
100
+ serverName: z.ZodString;
101
+ }, z.core.$strip>;
102
+ cursor: z.ZodOptional<z.ZodString>;
103
+ }, z.core.$strip>;
104
+ /** `tool-calls`: one `tools/call`, keyed by its effect id. */
105
+ export declare const ToolCallBodySchema: z.ZodObject<{
106
+ server: z.ZodObject<{
107
+ sessionId: z.ZodOptional<z.ZodString>;
108
+ agentId: z.ZodOptional<z.ZodString>;
109
+ serverName: z.ZodString;
110
+ }, z.core.$strip>;
111
+ effectId: z.ZodString;
112
+ name: z.ZodString;
113
+ arguments: z.ZodRecord<z.ZodString, z.ZodUnknown>;
114
+ }, z.core.$strip>;
115
+ export type ToolCallBody = z.infer<typeof ToolCallBodySchema>;
116
+ /**
117
+ * `http-calls`: one call of an HTTP tool, named by its agent and tool, or a flow's
118
+ * HTTP stage or verifier by its stage key. The gate finds its URL, method and credential in the
119
+ * session's pinned manifest. A run token's turn is the call's; `turnId` counts only under core's
120
+ * credential.
121
+ */
122
+ export declare const HttpCallBodySchema: z.ZodObject<{
123
+ tool: z.ZodUnion<readonly [z.ZodObject<{
124
+ sessionId: z.ZodOptional<z.ZodString>;
125
+ agentId: z.ZodOptional<z.ZodString>;
126
+ toolName: z.ZodString;
127
+ }, z.core.$strip>, z.ZodObject<{
128
+ sessionId: z.ZodOptional<z.ZodString>;
129
+ stage: z.ZodString;
130
+ }, z.core.$strip>]>;
131
+ effectId: z.ZodString;
132
+ turnId: z.ZodString;
133
+ input: z.ZodUnknown;
134
+ }, z.core.$strip>;
135
+ export type HttpCallBody = z.infer<typeof HttpCallBodySchema>;
136
+ /** How an MCP tool call failed, coded; the failed outcome the model sees carries the code. */
137
+ export declare const MCP_FAILURE_CODES: readonly ["mcp.unreachable", "credential_rejected", "mcp.forbidden", "mcp.error", "mcp.status", "mcp.lost", "mcp.too-large"];
138
+ export type McpFailureCode = (typeof MCP_FAILURE_CODES)[number];
139
+ /** Why an MCP request failed. Its message has no credential value in it. */
140
+ export interface McpGateError {
141
+ readonly message: string;
142
+ /** The MCP SDK's error code, or an HTTP status for transport errors (401 for a refused token). */
143
+ readonly code?: number;
144
+ /** The vault credentials a refused authorization names. */
145
+ readonly credentialIds?: readonly string[];
146
+ /** The call may have run: its earlier attempt was lost with the gateway. */
147
+ readonly uncertain?: boolean;
148
+ readonly failure?: {
149
+ readonly code: McpFailureCode;
150
+ readonly message: string;
151
+ /** The request reached the server, so it may have acted on it. */
152
+ readonly sent: boolean;
153
+ readonly retryable: boolean;
154
+ readonly server?: string;
155
+ readonly redacted?: number;
156
+ };
157
+ }
158
+ /** A Tool Gate answer. */
159
+ export type McpAnswer<T> = {
160
+ readonly ok: true;
161
+ readonly result: T;
162
+ /** A `tools/call`'s: how many credential values its result echoed, replaced. */
163
+ readonly redacted?: number;
164
+ } | {
165
+ readonly ok: false;
166
+ readonly error: McpGateError;
167
+ };