@nylorun/core 0.0.0-bootstrap → 0.2.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 (72) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/LICENSE +192 -0
  3. package/README.md +16 -0
  4. package/dist/compatibility.d.ts +3 -0
  5. package/dist/compatibility.js +3 -0
  6. package/dist/contracts.d.ts +330 -0
  7. package/dist/contracts.js +366 -0
  8. package/dist/define.d.ts +32 -0
  9. package/dist/define.js +15 -0
  10. package/dist/definition/assemble.d.ts +29 -0
  11. package/dist/definition/assemble.js +120 -0
  12. package/dist/definition/bind-agent.d.ts +8 -0
  13. package/dist/definition/bind-agent.js +62 -0
  14. package/dist/definition/bind-tool.d.ts +4 -0
  15. package/dist/definition/bind-tool.js +25 -0
  16. package/dist/definition/binding.d.ts +15 -0
  17. package/dist/definition/binding.js +9 -0
  18. package/dist/definition/bound.d.ts +34 -0
  19. package/dist/definition/bound.js +1 -0
  20. package/dist/definition/builder.d.ts +66 -0
  21. package/dist/definition/builder.js +218 -0
  22. package/dist/definition/declaration.d.ts +10 -0
  23. package/dist/definition/declaration.js +93 -0
  24. package/dist/definition/from.d.ts +13 -0
  25. package/dist/definition/from.js +294 -0
  26. package/dist/definition/helpers.d.ts +23 -0
  27. package/dist/definition/helpers.js +33 -0
  28. package/dist/definition/implementations.d.ts +16 -0
  29. package/dist/definition/implementations.js +3 -0
  30. package/dist/definition/manifest.d.ts +13 -0
  31. package/dist/definition/manifest.js +60 -0
  32. package/dist/definition/output-contract.d.ts +6 -0
  33. package/dist/definition/output-contract.js +12 -0
  34. package/dist/definition/schema-json.d.ts +3 -0
  35. package/dist/definition/schema-json.js +22 -0
  36. package/dist/definition/schema.d.ts +16 -0
  37. package/dist/definition/schema.js +284 -0
  38. package/dist/definition/skill-tools.d.ts +3 -0
  39. package/dist/definition/skill-tools.js +56 -0
  40. package/dist/definition/tool-error.d.ts +9 -0
  41. package/dist/definition/tool-error.js +20 -0
  42. package/dist/errors.d.ts +17 -0
  43. package/dist/errors.js +22 -0
  44. package/dist/index.d.ts +10 -0
  45. package/dist/index.js +1 -0
  46. package/dist/types/agent.d.ts +10 -0
  47. package/dist/types/agent.js +1 -0
  48. package/dist/types/dynamics.d.ts +53 -0
  49. package/dist/types/dynamics.js +1 -0
  50. package/dist/types/manifest.d.ts +57 -0
  51. package/dist/types/manifest.js +1 -0
  52. package/dist/types/middleware.d.ts +92 -0
  53. package/dist/types/middleware.js +1 -0
  54. package/dist/types/model.d.ts +184 -0
  55. package/dist/types/model.js +1 -0
  56. package/dist/types/observe.d.ts +180 -0
  57. package/dist/types/observe.js +1 -0
  58. package/dist/types/shared.d.ts +25 -0
  59. package/dist/types/shared.js +1 -0
  60. package/dist/types/tool.d.ts +194 -0
  61. package/dist/types/tool.js +1 -0
  62. package/dist/types/transcript.d.ts +65 -0
  63. package/dist/types/transcript.js +1 -0
  64. package/dist/utils/canonical.d.ts +1 -0
  65. package/dist/utils/canonical.js +10 -0
  66. package/dist/utils/hash.d.ts +3 -0
  67. package/dist/utils/hash.js +7 -0
  68. package/dist/utils/immutable.d.ts +6 -0
  69. package/dist/utils/immutable.js +76 -0
  70. package/package.json +57 -7
  71. package/index.js +0 -1
  72. package/publish.out +0 -0
@@ -0,0 +1,184 @@
1
+ import type { ContextItem, JsonObject, JsonValue } from "./shared.js";
2
+ import type { InputEvent, TranscriptEntry } from "./transcript.js";
3
+ import type { ToolDescriptor, ToolResult } from "./tool.js";
4
+ export interface ModelToolCall {
5
+ readonly id: string;
6
+ readonly name: string;
7
+ readonly args: JsonObject;
8
+ }
9
+ export type ModelOutputBlock = {
10
+ readonly type: "text";
11
+ readonly text: string;
12
+ readonly providerMetadata?: JsonObject;
13
+ } | {
14
+ readonly type: "reasoning";
15
+ readonly text: string;
16
+ readonly providerMetadata?: JsonObject;
17
+ } | {
18
+ readonly type: "json";
19
+ readonly value: JsonValue;
20
+ } | {
21
+ readonly type: "tool-call";
22
+ readonly providerMetadata?: JsonObject;
23
+ readonly id: string;
24
+ readonly name: string;
25
+ readonly args: JsonObject;
26
+ readonly raw?: string;
27
+ };
28
+ export interface ModelUsage {
29
+ readonly inputTokens?: number;
30
+ readonly outputTokens?: number;
31
+ readonly totalTokens?: number;
32
+ readonly cachedTokens?: number;
33
+ readonly reasoningTokens?: number;
34
+ readonly costUsd?: number;
35
+ }
36
+ export type ModelFinishReason = "stop" | "length" | "tool-calls" | "content-filter" | "other";
37
+ export interface ModelEvidence {
38
+ readonly requestId?: string;
39
+ readonly resolvedModel?: string;
40
+ readonly warnings?: readonly string[];
41
+ readonly extras?: JsonObject;
42
+ }
43
+ export interface ModelCandidate {
44
+ readonly output: readonly ModelOutputBlock[];
45
+ readonly finishReason?: ModelFinishReason;
46
+ readonly usage?: ModelUsage;
47
+ readonly evidence?: ModelEvidence;
48
+ }
49
+ export interface ModelControls {
50
+ readonly temperature?: number;
51
+ readonly maxOutputTokens?: number;
52
+ }
53
+ export interface ModelDirective {
54
+ readonly id?: string;
55
+ readonly controls?: ModelControls;
56
+ readonly config?: JsonObject;
57
+ }
58
+ /** A middleware-owned declaration for the model-visible configuration. */
59
+ export interface ModelConfigurationMutationOptions {
60
+ readonly order?: number;
61
+ readonly reason?: string;
62
+ }
63
+ export interface ModelConfigurationContributor {
64
+ readonly middlewareId: string;
65
+ readonly slot: string;
66
+ readonly order: number;
67
+ readonly reason?: string;
68
+ }
69
+ export interface ModelConfigurationTool {
70
+ readonly name: string;
71
+ readonly description?: string;
72
+ readonly inputSchema: JsonObject;
73
+ readonly outputSchema?: JsonObject;
74
+ readonly contributor: ModelConfigurationContributor;
75
+ }
76
+ export interface ModelConfigurationInstruction {
77
+ readonly text: string;
78
+ readonly contributor: ModelConfigurationContributor;
79
+ }
80
+ export interface ModelConfigurationSnapshot {
81
+ readonly version: 1;
82
+ readonly model?: ModelDirective;
83
+ readonly instructions: readonly ModelConfigurationInstruction[];
84
+ /** Data-only descriptions of the selected tools. */
85
+ readonly tools: readonly ToolDescriptor[];
86
+ readonly toolContracts: readonly ModelConfigurationTool[];
87
+ readonly contributors: readonly ModelConfigurationContributor[];
88
+ }
89
+ /** A middleware-owned declaration for this model call's runtime context. */
90
+ export interface ContextMutationOptions {
91
+ readonly order?: number;
92
+ readonly reason?: string;
93
+ }
94
+ export interface ContextContributor {
95
+ readonly middlewareId: string;
96
+ readonly slot: string;
97
+ readonly order: number;
98
+ readonly reason?: string;
99
+ }
100
+ /** Canonical runtime context for one model call. */
101
+ export interface ContextSnapshot {
102
+ readonly items: readonly ContextItem[];
103
+ readonly contributors: readonly ContextContributor[];
104
+ }
105
+ export interface ModelRequest {
106
+ readonly executionId: string;
107
+ readonly turnId: string;
108
+ readonly stepId: string;
109
+ readonly model?: ModelDirective;
110
+ /** Canonical, immutable Harness-owned model configuration for this call. */
111
+ readonly configuration: ModelConfigurationSnapshot;
112
+ readonly instructions: readonly string[];
113
+ readonly context: ContextSnapshot;
114
+ readonly transcript: readonly TranscriptEntry[];
115
+ readonly arrivals: readonly InputEvent[];
116
+ readonly toolResults: readonly ToolResult[];
117
+ /** Immutable tool descriptions; executable definitions stay inside Harness. */
118
+ readonly tools: readonly ToolDescriptor[];
119
+ /** Optional portable contract for this turn's terminal JSON result. */
120
+ readonly outputSchema?: JsonObject;
121
+ }
122
+ export type PromptContentPart = {
123
+ readonly type: "reasoning";
124
+ readonly text: string;
125
+ readonly providerMetadata?: JsonObject;
126
+ } | {
127
+ readonly type: "text";
128
+ readonly text: string;
129
+ readonly providerMetadata?: JsonObject;
130
+ } | {
131
+ readonly type: "media";
132
+ readonly mediaType: string;
133
+ readonly reference: JsonValue;
134
+ } | {
135
+ readonly type: "tool-call";
136
+ readonly providerMetadata?: JsonObject;
137
+ readonly id: string;
138
+ readonly name: string;
139
+ readonly args: JsonObject;
140
+ };
141
+ export type PromptItem = {
142
+ readonly kind: "instructions";
143
+ readonly role: "system";
144
+ readonly content: readonly PromptContentPart[];
145
+ } | {
146
+ readonly kind: "message";
147
+ readonly role: "user" | "assistant";
148
+ readonly content: readonly PromptContentPart[];
149
+ } | {
150
+ readonly kind: "tool-result";
151
+ readonly toolCallId: string;
152
+ readonly toolName: string;
153
+ readonly status: "completed" | "denied" | "failed";
154
+ readonly content: readonly PromptContentPart[];
155
+ } | {
156
+ readonly kind: "context";
157
+ readonly role: "user";
158
+ readonly content: readonly PromptContentPart[];
159
+ };
160
+ export interface ModelCallTool {
161
+ readonly name: string;
162
+ readonly description?: string;
163
+ readonly inputSchema: JsonObject;
164
+ }
165
+ export interface ModelCall {
166
+ readonly model?: ModelDirective;
167
+ readonly prompt: readonly PromptItem[];
168
+ readonly tools: readonly ModelCallTool[];
169
+ /** Optional portable contract for this turn's terminal JSON result. */
170
+ readonly outputSchema?: JsonObject;
171
+ readonly executionId: string;
172
+ }
173
+ export interface ModelAdapterContext {
174
+ readonly request: ModelRequest;
175
+ readonly invocationId: string;
176
+ readonly signal: AbortSignal;
177
+ /** Publishes one JSON-safe provider request derived from the canonical ModelCall. */
178
+ reportPreparedCall(prepared: ModelPreparedCall): void;
179
+ }
180
+ export interface ModelPreparedCall {
181
+ readonly adapter: string;
182
+ readonly call: JsonValue;
183
+ }
184
+ export type ModelAdapter = (call: ModelCall, context: ModelAdapterContext) => Promise<ModelCandidate | string>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,180 @@
1
+ import type { ContextSnapshot, ModelCandidate, ModelCall, ModelConfigurationSnapshot } from "./model.js";
2
+ import type { JsonObject, JsonValue } from "./shared.js";
3
+ import type { InputEvent, TranscriptEntry } from "./transcript.js";
4
+ import type { RequiredInteraction, ToolDescriptor, ToolResult } from "./tool.js";
5
+ export type ObserveToolSnapshot = ToolDescriptor;
6
+ /** JSON-only model-configuration view suitable for an observation stream. */
7
+ export interface ObserveModelConfigurationSnapshot extends Omit<ModelConfigurationSnapshot, "tools"> {
8
+ readonly tools: readonly ObserveToolSnapshot[];
9
+ }
10
+ export interface ObserveSealedCall {
11
+ readonly callId: string;
12
+ readonly toolName: string;
13
+ readonly args: JsonValue;
14
+ readonly invocationId: string;
15
+ readonly owner: {
16
+ readonly middlewareId: string;
17
+ readonly slot: string;
18
+ };
19
+ readonly interaction?: RequiredInteraction;
20
+ }
21
+ export interface ObserveModelRequested {
22
+ /** The exact immutable logical input supplied to the ModelAdapter. */
23
+ readonly call: ModelCall;
24
+ /** Canonical configuration facts and attribution. */
25
+ readonly configuration: ObserveModelConfigurationSnapshot;
26
+ /** Current-step runtime context and attribution. */
27
+ readonly context: ContextSnapshot;
28
+ }
29
+ export type ObserveEvent = {
30
+ readonly type: "model.requested";
31
+ readonly invocationId: string;
32
+ readonly turnId: string;
33
+ readonly stepId: string;
34
+ readonly inputId?: string;
35
+ readonly requestedModelId?: string;
36
+ readonly attributes: ObserveModelRequested;
37
+ } | {
38
+ readonly type: "model.prepared";
39
+ readonly invocationId: string;
40
+ readonly turnId: string;
41
+ readonly stepId: string;
42
+ readonly inputId?: string;
43
+ readonly requestedModelId?: string;
44
+ readonly attributes: {
45
+ readonly adapter: string;
46
+ readonly call: JsonValue;
47
+ };
48
+ } | {
49
+ readonly type: "model.completed";
50
+ readonly invocationId?: string;
51
+ readonly turnId: string;
52
+ readonly stepId: string;
53
+ readonly inputId?: string;
54
+ readonly requestedModelId?: string;
55
+ readonly attributes: ModelCandidate;
56
+ } | {
57
+ readonly type: "step.started";
58
+ readonly turnId: string;
59
+ readonly stepId: string;
60
+ readonly inputId?: string;
61
+ readonly turnNumber: number;
62
+ readonly stepNumber: number;
63
+ readonly attributes: {
64
+ readonly arrivals: readonly InputEvent[];
65
+ readonly toolResults: readonly ToolResult[];
66
+ readonly transcript: readonly TranscriptEntry[];
67
+ };
68
+ } | {
69
+ readonly type: "middleware.entered" | "middleware.completed";
70
+ readonly turnId: string;
71
+ readonly stepId: string;
72
+ readonly inputId?: string;
73
+ readonly middlewareId: string;
74
+ } | {
75
+ readonly type: "middleware.lease-violation";
76
+ readonly turnId: string;
77
+ readonly stepId: string;
78
+ readonly inputId?: string;
79
+ readonly middlewareId: string;
80
+ readonly reason: string;
81
+ } | {
82
+ readonly type: "tool.sealed";
83
+ readonly turnId: string;
84
+ readonly stepId: string;
85
+ readonly inputId?: string;
86
+ readonly attributes: {
87
+ readonly executable: readonly ObserveSealedCall[];
88
+ readonly immediate: readonly ToolResult[];
89
+ };
90
+ } | {
91
+ readonly type: "tool.started";
92
+ readonly executionId: string;
93
+ readonly turnId: string;
94
+ readonly stepId: string;
95
+ readonly inputId?: string;
96
+ readonly toolName: string;
97
+ readonly callId: string;
98
+ readonly invocationId: string;
99
+ readonly middlewareId: string;
100
+ readonly slot: string;
101
+ readonly attributes: {
102
+ readonly args: JsonValue;
103
+ };
104
+ } | {
105
+ readonly type: "tool.progress";
106
+ readonly executionId: string;
107
+ readonly turnId: string;
108
+ readonly stepId: string;
109
+ readonly inputId?: string;
110
+ readonly toolName: string;
111
+ readonly callId: string;
112
+ readonly invocationId: string;
113
+ readonly middlewareId: string;
114
+ readonly slot: string;
115
+ readonly attributes: {
116
+ readonly message: string;
117
+ readonly data?: JsonObject;
118
+ };
119
+ } | {
120
+ readonly type: "tool.completed";
121
+ readonly executionId: string;
122
+ readonly turnId: string;
123
+ readonly stepId: string;
124
+ readonly inputId?: string;
125
+ readonly toolName: string;
126
+ readonly callId: string;
127
+ readonly invocationId: string;
128
+ readonly middlewareId: string;
129
+ readonly slot: string;
130
+ readonly outcome: string;
131
+ readonly code?: string;
132
+ readonly attributes?: ToolResult;
133
+ } | {
134
+ readonly type: "tool.deferred";
135
+ readonly executionId: string;
136
+ readonly turnId: string;
137
+ readonly stepId: string;
138
+ readonly inputId?: string;
139
+ readonly toolName: string;
140
+ readonly callId: string;
141
+ readonly invocationId: string;
142
+ readonly middlewareId: string;
143
+ readonly slot: string;
144
+ readonly attributes: {
145
+ readonly token?: JsonValue;
146
+ };
147
+ } | {
148
+ readonly type: "turn.completed";
149
+ readonly turnId: string;
150
+ readonly stepId: string;
151
+ readonly inputId?: string;
152
+ readonly attributes: {
153
+ readonly output: JsonValue;
154
+ };
155
+ } | {
156
+ readonly type: "interaction.required";
157
+ readonly turnId: string;
158
+ readonly stepId: string;
159
+ readonly inputId?: string;
160
+ readonly interactionId: string;
161
+ readonly kind: string;
162
+ readonly callId?: string;
163
+ readonly toolName?: string;
164
+ readonly phase?: "interaction" | "execute";
165
+ readonly attributes: {
166
+ readonly prompt: string;
167
+ readonly metadata?: JsonObject;
168
+ };
169
+ } | {
170
+ readonly type: "tripwire";
171
+ readonly turnId: string;
172
+ readonly stepId?: string;
173
+ readonly inputId?: string;
174
+ readonly code: string;
175
+ readonly scope: string;
176
+ readonly attributes: {
177
+ readonly message: string;
178
+ };
179
+ };
180
+ export type Observer = (event: ObserveEvent) => void | Promise<void>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ export type JsonPrimitive = string | number | boolean | null;
2
+ export type JsonValue = JsonPrimitive | JsonObject | readonly JsonValue[];
3
+ export type JsonObject = {
4
+ readonly [key: string]: JsonValue;
5
+ };
6
+ export interface DeferredOutcome {
7
+ readonly kind: "deferred";
8
+ readonly token?: JsonValue;
9
+ }
10
+ export interface BuildDiagnostic {
11
+ readonly code: string;
12
+ readonly message: string;
13
+ readonly toolName?: string;
14
+ readonly details?: Readonly<Record<string, string | number | boolean>>;
15
+ readonly cause?: unknown;
16
+ }
17
+ export interface ContextItem {
18
+ readonly type?: string;
19
+ readonly value: JsonValue;
20
+ }
21
+ export interface Tripwire {
22
+ readonly code: string;
23
+ readonly message: string;
24
+ readonly scope?: "step" | "execution";
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,194 @@
1
+ import type { z } from "zod";
2
+ import type { DeferredOutcome, JsonObject, JsonValue } from "./shared.js";
3
+ import type { ModelAdapter } from "./model.js";
4
+ /**
5
+ * Zod classic schemas accepted as tool contracts.
6
+ * Use core `$ZodType` so concrete schemas (e.g. ZodObject) stay assignable on
7
+ * zod 4.6+, where ZodType gained validate/validateAsync methods that break
8
+ * ZodObject → ZodType assignability in some TypeScript configurations.
9
+ */
10
+ type ZodToolSchema<T = unknown> = z.core.$ZodType<T, unknown>;
11
+ export interface SchemaIssue {
12
+ readonly path: readonly (string | number)[];
13
+ readonly code: string;
14
+ readonly message: string;
15
+ }
16
+ export type SchemaValidation<T> = {
17
+ readonly ok: true;
18
+ readonly value: T;
19
+ } | {
20
+ readonly ok: false;
21
+ readonly issues: readonly SchemaIssue[];
22
+ };
23
+ /** The portable, locally-enforced schema contract accepted by a Harness tool. */
24
+ export interface ToolSchema<T> {
25
+ readonly jsonSchema: JsonObject;
26
+ validate(value: unknown): SchemaValidation<T>;
27
+ }
28
+ /** The synchronous Standard Schema subset required to project and validate a tool contract. */
29
+ export interface StandardToolSchema<Input = unknown, Output = unknown> {
30
+ readonly "~standard": {
31
+ readonly validate: (value: Input) => {
32
+ readonly value: Output;
33
+ readonly issues?: undefined;
34
+ } | {
35
+ readonly issues: readonly StandardSchemaIssue[];
36
+ readonly value?: undefined;
37
+ } | Promise<unknown>;
38
+ readonly jsonSchema: {
39
+ readonly input: () => unknown;
40
+ readonly output: () => unknown;
41
+ };
42
+ };
43
+ }
44
+ export interface StandardSchemaIssue {
45
+ readonly message?: string;
46
+ readonly path?: readonly (string | number | symbol)[];
47
+ readonly code?: string;
48
+ }
49
+ export type ToolSchemaSource<T = unknown> = ZodToolSchema<T> | StandardToolSchema<any, T> | ToolSchema<T>;
50
+ export type SchemaOutput<Schema> = Schema extends z.core.$ZodType<infer Value, any> ? Value : Schema extends StandardToolSchema<any, infer Value> ? Value : Schema extends ToolSchema<infer Value> ? Value : never;
51
+ export type ToolInputSchema = ToolSchemaSource;
52
+ export type ToolOutputSchema = ToolSchemaSource;
53
+ type OutputFor<Schema> = Schema extends ToolSchemaSource ? SchemaOutput<Schema> : ToolContent;
54
+ /** Side-effect class for crash / redelivery semantics (code-only; never in the manifest). */
55
+ export type ToolEffects = "read" | "idempotent" | "write";
56
+ /**
57
+ * Declarative approval gate. Return a prompt string (or `true`) to pause;
58
+ * return `false` / `undefined` / empty string to proceed.
59
+ */
60
+ export type ToolApproval<InputSchema extends ToolInputSchema> = (args: SchemaOutput<InputSchema>) => string | boolean | undefined | Promise<string | boolean | undefined>;
61
+ export interface SessionStateBag {
62
+ get(key: string): JsonValue | undefined;
63
+ set(key: string, value: JsonValue): void;
64
+ entries(): Readonly<Record<string, JsonValue>>;
65
+ }
66
+ export interface ToolDefinition<InputSchema extends ToolInputSchema = ToolInputSchema, Info = unknown, OutputSchema extends ToolOutputSchema | undefined = undefined> {
67
+ readonly name: string;
68
+ readonly description?: string;
69
+ /** Preferred alias for `inputSchema`. */
70
+ readonly input?: InputSchema;
71
+ readonly inputSchema?: InputSchema;
72
+ /** Preferred alias for `outputSchema`. */
73
+ readonly output?: OutputSchema;
74
+ readonly outputSchema?: OutputSchema;
75
+ /** Preferred alias for `execute`. */
76
+ run?(args: SchemaOutput<InputSchema>, context: ToolExecutionContext<Info>): Promise<ToolRunResult<OutputFor<OutputSchema>>>;
77
+ execute?(args: SchemaOutput<InputSchema>, context: ToolExecutionContext<Info>): Promise<ToolRunResult<OutputFor<OutputSchema>>>;
78
+ /** Code-only metadata — never serialized into the manifest. */
79
+ readonly approval?: ToolApproval<InputSchema>;
80
+ /** Code-only metadata — never serialized into the manifest. */
81
+ readonly effects?: ToolEffects;
82
+ }
83
+ /** A plain return value is treated as `{ kind: "completed", output }`. Legacy tagged outcomes remain valid. */
84
+ export type ToolRunResult<Output = ToolContent> = Output | ToolOutcome<Output>;
85
+ export interface ToolOwner {
86
+ readonly middlewareId: string;
87
+ readonly slot: string;
88
+ }
89
+ export interface Interaction {
90
+ readonly id?: string;
91
+ readonly kind: "approval" | "response";
92
+ readonly prompt: string;
93
+ readonly metadata?: JsonObject;
94
+ }
95
+ export interface RequiredInteraction extends Interaction {
96
+ readonly id: string;
97
+ }
98
+ export interface ToolExecutionResume {
99
+ readonly interactionId: string;
100
+ readonly kind: "approval" | "response";
101
+ readonly approved?: boolean;
102
+ readonly value?: JsonValue;
103
+ readonly token?: JsonValue;
104
+ }
105
+ interface ToolExecutionContextBase {
106
+ readonly executionId: string;
107
+ readonly turnId: string;
108
+ readonly stepId: string;
109
+ readonly callId: string;
110
+ readonly invocationId: string;
111
+ readonly signal: AbortSignal;
112
+ /** The invocation's model callable, for tools that explicitly run a child agent. */
113
+ readonly onModelCall?: ModelAdapter;
114
+ readonly resume?: ToolExecutionResume;
115
+ /** Stable per invocation across crash and replay. */
116
+ readonly idempotencyKey: string;
117
+ /** True when this invocation is being offered again after an interrupted active call. */
118
+ readonly redelivery?: boolean;
119
+ /** Durable session memory (tools write; beforeModelCall reads). */
120
+ readonly state: SessionStateBag;
121
+ /** Session identity stub — Runtime fills this later. */
122
+ readonly session: {
123
+ readonly id: string;
124
+ };
125
+ /** Live progress stub — emits an observation when a listener is present. */
126
+ progress(message: string, data?: JsonObject): void;
127
+ /** Durable wait: park for a human/app response. */
128
+ ask(prompt: string, opts?: JsonObject): Promise<JsonValue>;
129
+ /** Durable wait: park for approval. */
130
+ approve(prompt: string): Promise<boolean>;
131
+ /** Durable wait: park until a timer fires (host settles). */
132
+ sleep(duration: string | number): Promise<void>;
133
+ /** Durable wait: park until a named event arrives. */
134
+ waitFor(event: string, opts?: {
135
+ readonly match?: JsonValue;
136
+ readonly timeout?: string | number;
137
+ }): Promise<JsonValue>;
138
+ /** Memoized sub-step so effects before a wait are not re-run on resume. */
139
+ step<T>(name: string, fn: () => Promise<T> | T): Promise<T>;
140
+ }
141
+ export type ToolExecutionContext<Info = unknown> = ToolExecutionContextBase & {
142
+ readonly info?: Info;
143
+ };
144
+ export type ToolContent = JsonValue;
145
+ export type ToolOutcome<Output = ToolContent> = {
146
+ readonly kind: "completed";
147
+ readonly output: Output;
148
+ } | {
149
+ readonly kind: "denied";
150
+ readonly reason: string;
151
+ } | {
152
+ readonly kind: "failed";
153
+ readonly code: string;
154
+ readonly message: string;
155
+ } | {
156
+ readonly kind: "interaction-required";
157
+ readonly interaction: Interaction;
158
+ readonly token?: JsonValue;
159
+ } | DeferredOutcome;
160
+ export interface ToolValidationFailureDetails {
161
+ readonly phase: "input" | "output";
162
+ readonly issues: readonly SchemaIssue[];
163
+ }
164
+ export type ToolResult = {
165
+ readonly callId: string;
166
+ readonly toolName: string;
167
+ readonly kind: "completed";
168
+ readonly output: ToolContent;
169
+ } | {
170
+ readonly callId: string;
171
+ readonly toolName: string;
172
+ readonly kind: "denied";
173
+ readonly reason: string;
174
+ } | {
175
+ readonly callId: string;
176
+ readonly toolName: string;
177
+ readonly kind: "failed";
178
+ readonly code: string;
179
+ readonly message: string;
180
+ readonly details?: ToolValidationFailureDetails;
181
+ };
182
+ /** Immutable tool metadata supplied to model adapters and observers. */
183
+ export interface ToolDescriptor {
184
+ readonly name: string;
185
+ readonly description?: string;
186
+ readonly owner: ToolOwner;
187
+ readonly inputSchema: {
188
+ readonly jsonSchema: JsonObject;
189
+ };
190
+ readonly outputSchema?: {
191
+ readonly jsonSchema: JsonObject;
192
+ };
193
+ }
194
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,65 @@
1
+ import type { ModelCandidate } from "./model.js";
2
+ import type { JsonObject, JsonValue } from "./shared.js";
3
+ import type { ToolResult } from "./tool.js";
4
+ export type InputEvent = {
5
+ readonly kind: "user-message" | "interrupt";
6
+ readonly text: string;
7
+ readonly metadata?: JsonObject;
8
+ } | {
9
+ readonly kind: "user-message" | "interrupt";
10
+ readonly content: readonly UserContentPart[];
11
+ /** Undefined for content-bearing events; retained for text-event narrowing compatibility. */
12
+ readonly text?: undefined;
13
+ readonly metadata?: JsonObject;
14
+ } | {
15
+ readonly kind: "approve";
16
+ readonly interactionId: string;
17
+ readonly approved: boolean;
18
+ } | {
19
+ readonly kind: "respond";
20
+ readonly interactionId: string;
21
+ readonly value: JsonValue;
22
+ };
23
+ /** Ordered, model-visible user content. Media references stay host-owned JSON values. */
24
+ export type UserContentPart = {
25
+ readonly type: "text";
26
+ readonly text: string;
27
+ } | {
28
+ readonly type: "media";
29
+ readonly mediaType: string;
30
+ readonly reference: JsonValue;
31
+ };
32
+ export type MessageInput = string | {
33
+ readonly text: string;
34
+ readonly metadata?: JsonObject;
35
+ } | {
36
+ readonly content: readonly UserContentPart[];
37
+ readonly metadata?: JsonObject;
38
+ };
39
+ export type InteractionReply = Extract<InputEvent, {
40
+ kind: "approve" | "respond";
41
+ }>;
42
+ export interface TranscriptInputEntry {
43
+ readonly kind: "input";
44
+ readonly turnId: string;
45
+ readonly event: InputEvent;
46
+ }
47
+ export interface TranscriptCandidateEntry {
48
+ readonly kind: "candidate";
49
+ readonly turnId: string;
50
+ readonly stepId: string;
51
+ readonly candidate: ModelCandidate;
52
+ }
53
+ export interface TranscriptToolsEntry {
54
+ readonly kind: "tool-results";
55
+ readonly turnId: string;
56
+ readonly stepId: string;
57
+ readonly results: readonly ToolResult[];
58
+ }
59
+ export interface TranscriptFinalEntry {
60
+ readonly kind: "final";
61
+ readonly turnId: string;
62
+ readonly stepId: string;
63
+ readonly output: JsonValue;
64
+ }
65
+ export type TranscriptEntry = TranscriptInputEntry | TranscriptCandidateEntry | TranscriptToolsEntry | TranscriptFinalEntry;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare function canonical(value: unknown): string;
@@ -0,0 +1,10 @@
1
+ export function canonical(value) {
2
+ if (Array.isArray(value))
3
+ return `[${value.map(canonical).join(",")}]`;
4
+ if (value && typeof value === "object")
5
+ return `{${Object.entries(value)
6
+ .sort(([a], [b]) => a.localeCompare(b))
7
+ .map(([key, item]) => `${JSON.stringify(key)}:${canonical(item)}`)
8
+ .join(",")}}`;
9
+ return JSON.stringify(value);
10
+ }
@@ -0,0 +1,3 @@
1
+ import type { AgentManifest } from "../types/manifest.js";
2
+ /** Canonical SHA-256 hex digest of a manifest (agent identity). */
3
+ export declare function hashManifest(manifest: AgentManifest): string;
@@ -0,0 +1,7 @@
1
+ import { sha256 } from "@noble/hashes/sha256";
2
+ import { bytesToHex } from "@noble/hashes/utils";
3
+ import { canonical } from "./canonical.js";
4
+ /** Canonical SHA-256 hex digest of a manifest (agent identity). */
5
+ export function hashManifest(manifest) {
6
+ return bytesToHex(sha256(canonical(manifest)));
7
+ }