@nylorun/harness 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 (123) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/HOST_CONTRACT.md +27 -0
  3. package/README.md +62 -100
  4. package/dist/compatibility.d.ts +3 -0
  5. package/dist/compatibility.js +3 -0
  6. package/dist/definition/agent-definition.d.ts +11 -3
  7. package/dist/definition/agent-definition.js +18 -10
  8. package/dist/definition/compatibility.d.ts +11 -0
  9. package/dist/definition/compatibility.js +30 -0
  10. package/dist/definition/registry.d.ts +2 -2
  11. package/dist/definition/registry.js +8 -7
  12. package/dist/index.d.ts +4 -18
  13. package/dist/index.js +1 -6
  14. package/dist/loop/dispatch.js +327 -0
  15. package/dist/loop/host-suspension.d.ts +6 -0
  16. package/dist/loop/host-suspension.js +10 -0
  17. package/dist/loop/initial-state.d.ts +13 -0
  18. package/dist/loop/initial-state.js +30 -0
  19. package/dist/{execution → loop}/invocation.d.ts +5 -2
  20. package/dist/{execution → loop}/invocation.js +8 -3
  21. package/dist/{execution → loop}/model/adapters.d.ts +4 -2
  22. package/dist/{execution → loop}/model/adapters.js +3 -2
  23. package/dist/{execution → loop}/model/normalize.d.ts +2 -2
  24. package/dist/{execution → loop}/model/normalize.js +2 -2
  25. package/dist/{execution → loop}/model/prepared.d.ts +2 -2
  26. package/dist/{execution → loop}/model/project.d.ts +1 -1
  27. package/dist/{execution → loop}/model/project.js +1 -1
  28. package/dist/{execution → loop}/observe.d.ts +2 -2
  29. package/dist/{execution → loop}/observe.js +1 -1
  30. package/dist/{execution → loop}/options.d.ts +2 -1
  31. package/dist/{execution → loop}/options.js +28 -8
  32. package/dist/{execution → loop}/resume.d.ts +1 -1
  33. package/dist/{execution → loop}/resume.js +2 -2
  34. package/dist/{execution → loop}/run.d.ts +1 -1
  35. package/dist/{execution → loop}/run.js +9 -1
  36. package/dist/{execution → loop}/state.d.ts +2 -2
  37. package/dist/{execution → loop}/state.js +13 -3
  38. package/dist/{execution → loop}/step/canonicalize.d.ts +2 -2
  39. package/dist/{execution → loop}/step/canonicalize.js +1 -1
  40. package/dist/{execution → loop}/step/compose.d.ts +2 -2
  41. package/dist/{execution → loop}/step/compose.js +4 -1
  42. package/dist/{execution → loop}/step/context-draft.d.ts +2 -2
  43. package/dist/{execution → loop}/step/context-draft.js +2 -2
  44. package/dist/{execution → loop}/step/describe.d.ts +3 -3
  45. package/dist/{execution → loop}/step/describe.js +1 -1
  46. package/dist/loop/step/dynamics.d.ts +29 -0
  47. package/dist/loop/step/dynamics.js +149 -0
  48. package/dist/{execution → loop}/step/model-configuration.d.ts +2 -2
  49. package/dist/{execution → loop}/step/model-configuration.js +3 -3
  50. package/dist/{execution → loop}/step/resolve.d.ts +4 -4
  51. package/dist/{execution → loop}/step/run.d.ts +5 -4
  52. package/dist/{execution → loop}/step/run.js +87 -2
  53. package/dist/{execution → loop}/step/runtime.d.ts +12 -4
  54. package/dist/{execution → loop}/step/seal.d.ts +5 -5
  55. package/dist/{execution → loop}/step/seal.js +2 -2
  56. package/dist/{execution → loop}/step/slot-assembly.d.ts +1 -1
  57. package/dist/{execution → loop}/step/slot-assembly.js +1 -1
  58. package/dist/{execution → loop}/step/step-context.d.ts +5 -5
  59. package/dist/{execution → loop}/step/step-context.js +2 -2
  60. package/dist/{execution → loop}/tool-result.d.ts +2 -2
  61. package/dist/{execution → loop}/tool-result.js +2 -2
  62. package/dist/{execution → loop}/transcript.d.ts +1 -1
  63. package/dist/{execution → loop}/transcript.js +2 -2
  64. package/dist/loop/waits.d.ts +50 -0
  65. package/dist/loop/waits.js +11 -0
  66. package/dist/run/durable.d.ts +80 -0
  67. package/dist/run/durable.js +176 -0
  68. package/dist/run/index.d.ts +33 -0
  69. package/dist/run/index.js +38 -0
  70. package/dist/types/client.d.ts +88 -0
  71. package/dist/types/execution.d.ts +22 -5
  72. package/dist/utils/ids.d.ts +1 -0
  73. package/dist/utils/ids.js +11 -1
  74. package/package.json +21 -9
  75. package/dist/definition/assemble.d.ts +0 -22
  76. package/dist/definition/assemble.js +0 -43
  77. package/dist/definition/bind-agent.d.ts +0 -9
  78. package/dist/definition/bind-agent.js +0 -21
  79. package/dist/definition/bind-tool.d.ts +0 -4
  80. package/dist/definition/bind-tool.js +0 -19
  81. package/dist/definition/bound.d.ts +0 -16
  82. package/dist/definition/builder.d.ts +0 -30
  83. package/dist/definition/builder.js +0 -94
  84. package/dist/definition/declaration.d.ts +0 -3
  85. package/dist/definition/declaration.js +0 -53
  86. package/dist/definition/helpers.d.ts +0 -6
  87. package/dist/definition/helpers.js +0 -4
  88. package/dist/definition/manifest.d.ts +0 -9
  89. package/dist/definition/manifest.js +0 -45
  90. package/dist/definition/output-contract.d.ts +0 -6
  91. package/dist/definition/output-contract.js +0 -12
  92. package/dist/definition/schema.d.ts +0 -14
  93. package/dist/definition/schema.js +0 -205
  94. package/dist/errors.d.ts +0 -17
  95. package/dist/errors.js +0 -17
  96. package/dist/execution/dispatch.js +0 -164
  97. package/dist/execution/initial-state.d.ts +0 -3
  98. package/dist/execution/initial-state.js +0 -14
  99. package/dist/types/agent.d.ts +0 -9
  100. package/dist/types/agent.js +0 -1
  101. package/dist/types/manifest.d.ts +0 -22
  102. package/dist/types/manifest.js +0 -1
  103. package/dist/types/middleware.d.ts +0 -66
  104. package/dist/types/middleware.js +0 -1
  105. package/dist/types/model.d.ts +0 -184
  106. package/dist/types/model.js +0 -1
  107. package/dist/types/observe.d.ts +0 -165
  108. package/dist/types/observe.js +0 -1
  109. package/dist/types/shared.d.ts +0 -25
  110. package/dist/types/shared.js +0 -1
  111. package/dist/types/tool.d.ts +0 -138
  112. package/dist/types/tool.js +0 -1
  113. package/dist/types/transcript.d.ts +0 -65
  114. package/dist/types/transcript.js +0 -1
  115. package/dist/utils/canonical.d.ts +0 -1
  116. package/dist/utils/canonical.js +0 -10
  117. package/dist/utils/immutable.d.ts +0 -6
  118. package/dist/utils/immutable.js +0 -76
  119. /package/dist/{execution → loop}/dispatch.d.ts +0 -0
  120. /package/dist/{execution → loop}/model/prepared.js +0 -0
  121. /package/dist/{execution → loop}/step/resolve.js +0 -0
  122. /package/dist/{execution → loop}/step/runtime.js +0 -0
  123. /package/dist/{definition/bound.js → types/client.js} +0 -0
@@ -1,164 +0,0 @@
1
- import { HarnessError, isHarnessError } from "../errors.js";
2
- import { createId } from "../utils/ids.js";
3
- import { copyJson } from "../utils/immutable.js";
4
- import { toolResult } from "./tool-result.js";
5
- export async function dispatchPlan(invocation) {
6
- const { signal, definitions, options, observe, record } = invocation;
7
- let plan = invocation.state.plan;
8
- if (plan.calls.some((call) => call.status === "interaction" && call.interactionPhase === "before")) {
9
- for (const call of plan.calls)
10
- if (call.status === "interaction")
11
- observe({
12
- type: "interaction.required",
13
- turnId: plan.turnId,
14
- stepId: plan.stepId,
15
- interactionId: call.interaction.id,
16
- kind: call.interaction.kind,
17
- callId: call.callId,
18
- toolName: call.toolName,
19
- phase: "interaction",
20
- attributes: {
21
- prompt: call.interaction.prompt,
22
- ...(call.interaction.metadata ? { metadata: call.interaction.metadata } : {}),
23
- },
24
- });
25
- return "paused";
26
- }
27
- signal.throwIfAborted();
28
- const pending = plan.calls.filter((call) => call.status === "pending");
29
- if (pending.length) {
30
- invocation.state = {
31
- ...invocation.state,
32
- plan: {
33
- ...plan,
34
- calls: plan.calls.map((call) => call.status === "pending" ? { ...call, status: "active" } : call),
35
- },
36
- };
37
- await record();
38
- signal.throwIfAborted();
39
- const settled = await Promise.all(pending.map(async (call) => {
40
- const definition = definitions.get(call.invocationId);
41
- const eventIds = {
42
- executionId: invocation.state.executionId,
43
- turnId: plan.turnId,
44
- stepId: plan.stepId,
45
- callId: call.callId,
46
- invocationId: call.invocationId,
47
- toolName: call.toolName,
48
- middlewareId: call.reference.capabilityId,
49
- slot: definition.owner.slot,
50
- };
51
- observe({ type: "tool.started", ...eventIds, attributes: { args: call.args } });
52
- let outcome;
53
- try {
54
- signal.throwIfAborted();
55
- outcome = await definition.execute(call.args, {
56
- executionId: invocation.state.executionId,
57
- turnId: plan.turnId,
58
- stepId: plan.stepId,
59
- callId: call.callId,
60
- invocationId: call.invocationId,
61
- signal,
62
- info: options.info,
63
- onModelCall: options.onModelCall,
64
- ...(call.resume ? { resume: call.resume } : {}),
65
- });
66
- if (!outcome || typeof outcome !== "object")
67
- throw new HarnessError("tool.invalid-tool-result", "Tool returned an invalid outcome");
68
- if (outcome.kind === "interaction-required") {
69
- if (!["approval", "response"].includes(outcome.interaction.kind) ||
70
- typeof outcome.interaction.prompt !== "string")
71
- throw new HarnessError("tool.invalid-tool-result", "Tool returned an invalid interaction");
72
- return copyJson({
73
- ...call,
74
- status: "interaction",
75
- interaction: {
76
- ...outcome.interaction,
77
- id: outcome.interaction.id ?? createId("interaction"),
78
- },
79
- interactionPhase: "execute",
80
- ...(outcome.token === undefined ? {} : { token: outcome.token }),
81
- });
82
- }
83
- if (outcome.kind === "deferred") {
84
- observe({
85
- type: "tool.deferred",
86
- ...eventIds,
87
- attributes: outcome.token === undefined ? {} : { token: outcome.token },
88
- });
89
- return copyJson({
90
- ...call,
91
- status: "deferred",
92
- ...(outcome.token === undefined ? {} : { token: outcome.token }),
93
- });
94
- }
95
- const result = toolResult(call, definition, outcome);
96
- observe({
97
- type: "tool.completed",
98
- ...eventIds,
99
- outcome: result.kind,
100
- attributes: result,
101
- });
102
- return copyJson({ ...call, status: "settled", result });
103
- }
104
- catch (cause) {
105
- const result = {
106
- callId: call.callId,
107
- toolName: call.toolName,
108
- kind: "failed",
109
- code: signal.aborted
110
- ? "tool.cancelled"
111
- : isHarnessError(cause)
112
- ? cause.code
113
- : "tool.execution-failed",
114
- message: cause instanceof Error ? cause.message : String(cause),
115
- };
116
- observe({
117
- type: "tool.completed",
118
- ...eventIds,
119
- outcome: result.kind,
120
- attributes: result,
121
- });
122
- return copyJson({ ...call, status: "settled", result });
123
- }
124
- }));
125
- const byId = new Map(settled.map((call) => [call.invocationId, call]));
126
- plan = { ...plan, calls: plan.calls.map((call) => byId.get(call.invocationId) ?? call) };
127
- invocation.state = { ...invocation.state, plan };
128
- await record();
129
- }
130
- signal.throwIfAborted();
131
- if (plan.calls.some((call) => call.status === "interaction" || call.status === "deferred")) {
132
- for (const call of plan.calls)
133
- if (call.status === "interaction")
134
- observe({
135
- type: "interaction.required",
136
- turnId: plan.turnId,
137
- stepId: plan.stepId,
138
- interactionId: call.interaction.id,
139
- kind: call.interaction.kind,
140
- callId: call.callId,
141
- toolName: call.toolName,
142
- phase: call.interactionPhase === "before" ? "interaction" : "execute",
143
- attributes: {
144
- prompt: call.interaction.prompt,
145
- ...(call.interaction.metadata ? { metadata: call.interaction.metadata } : {}),
146
- },
147
- });
148
- return "paused";
149
- }
150
- const results = [
151
- ...plan.immediate,
152
- ...plan.calls.flatMap((call) => (call.result ? [call.result] : [])),
153
- ];
154
- const ordered = plan.order.map((item) => results.find((result) => result.callId === item.callId && result.toolName === item.toolName));
155
- const { plan: _, ...rest } = invocation.state;
156
- invocation.state = {
157
- ...rest,
158
- transcript: [
159
- ...invocation.state.transcript,
160
- { kind: "tool-results", turnId: plan.turnId, stepId: plan.stepId, results: ordered },
161
- ],
162
- };
163
- await record();
164
- }
@@ -1,3 +0,0 @@
1
- import type { AgentDefinition } from "../definition/agent-definition.js";
2
- import type { ExecutionState } from "../types/execution.js";
3
- export declare function initializeExecutionState(agent: AgentDefinition): ExecutionState;
@@ -1,14 +0,0 @@
1
- import { copyJson } from "../utils/immutable.js";
2
- import { createId } from "../utils/ids.js";
3
- export function initializeExecutionState(agent) {
4
- return copyJson({
5
- version: 1,
6
- agentId: agent.id,
7
- executionId: createId("execution"),
8
- revision: 0,
9
- turnCount: 0,
10
- transcript: [],
11
- status: "ready",
12
- ...(agent.output ? { outputContract: agent.output.schema.jsonSchema } : {}),
13
- });
14
- }
@@ -1,9 +0,0 @@
1
- import type { AgentManifest } from "./manifest.js";
2
- import type { RunOptions, RunResult } from "./execution.js";
3
- /** An agent definition built with Agent(...).use(...).build(). */
4
- export interface BuiltAgent<Info = unknown, Output = string> {
5
- readonly id: string;
6
- readonly name: string;
7
- readonly manifest: AgentManifest;
8
- run(options: RunOptions<Info>): Promise<RunResult<Output>>;
9
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,22 +0,0 @@
1
- import type { ModelDirective } from "./model.js";
2
- import type { JsonObject } from "./shared.js";
3
- export interface ManifestTool {
4
- readonly name: string;
5
- readonly description?: string;
6
- readonly inputSchema: JsonObject;
7
- readonly outputSchema?: JsonObject;
8
- }
9
- export interface CapabilityManifest {
10
- readonly id: string;
11
- readonly kind: "agent" | "capability" | "middleware";
12
- readonly hasMiddleware: boolean;
13
- readonly instructions?: readonly string[];
14
- readonly tools?: readonly ManifestTool[];
15
- readonly model?: Pick<ModelDirective, "id" | "controls">;
16
- }
17
- export interface AgentManifest {
18
- readonly id: string;
19
- readonly name: string;
20
- readonly outputSchema?: JsonObject;
21
- readonly capabilities: readonly CapabilityManifest[];
22
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,66 +0,0 @@
1
- import type { ContextMutationOptions, ModelCandidate, ModelDirective, ModelToolCall, ModelConfigurationMutationOptions } from "./model.js";
2
- import type { InputEvent, TranscriptEntry } from "./transcript.js";
3
- import type { ContextItem, Tripwire } from "./shared.js";
4
- import type { Interaction, ToolDefinition, ToolResult } from "./tool.js";
5
- interface StepRequestBase {
6
- /** Opaque identity of the execution that owns this Step. */
7
- readonly executionId: string;
8
- /** Opaque identity of the Turn that owns this Step. */
9
- readonly turnId: string;
10
- /** Opaque identity of this Model Step. */
11
- readonly stepId: string;
12
- readonly turnNumber: number;
13
- readonly stepNumber: number;
14
- readonly arrivals: readonly InputEvent[];
15
- readonly toolResults: readonly ToolResult[];
16
- readonly transcript: readonly TranscriptEntry[];
17
- readonly context: {
18
- set(slot: string, items: readonly ContextItem[], options?: ContextMutationOptions): void;
19
- };
20
- readonly configuration: {
21
- readonly instructions: {
22
- set(slot: string, items: readonly string[], options?: ModelConfigurationMutationOptions): void;
23
- };
24
- readonly tools: {
25
- set(slot: string, tools: readonly ToolDefinition[], options?: ModelConfigurationMutationOptions): void;
26
- };
27
- readonly model: {
28
- select(directive: ModelDirective, options?: Omit<ModelConfigurationMutationOptions, "order">): void;
29
- replace(directive: ModelDirective, options?: Omit<ModelConfigurationMutationOptions, "order">): void;
30
- clear(options?: Omit<ModelConfigurationMutationOptions, "order">): void;
31
- };
32
- };
33
- tripwire(error: Tripwire): StepResponse;
34
- }
35
- export type StepRequest<Info = unknown> = StepRequestBase & {
36
- readonly info?: Info;
37
- };
38
- export interface StepResponse {
39
- candidate(): Readonly<ModelCandidate> | undefined;
40
- toolCalls(): readonly ModelToolCall[];
41
- replace(candidate: ModelCandidate): void;
42
- deny(callId: string, reason: string): void;
43
- requireInteraction(callId: string, interaction: Interaction): void;
44
- tripwire(error: Tripwire): StepResponse;
45
- }
46
- export type StepMiddleware<Info = unknown> = (request: StepRequest<Info>, next: () => Promise<StepResponse>) => Promise<StepResponse>;
47
- export type CapabilityItems<Item> = readonly Item[] | Readonly<{
48
- readonly slot: string;
49
- readonly items: readonly Item[];
50
- }>;
51
- export interface CapabilityDeclaration<Info = unknown> {
52
- readonly id: string;
53
- readonly tools?: CapabilityItems<ToolDefinition<any, Info, any>>;
54
- readonly instructions?: CapabilityItems<string>;
55
- readonly model?: ModelDirective;
56
- readonly middleware?: StepMiddleware<Info>;
57
- }
58
- export interface MiddlewareContributions {
59
- readonly instructions?: readonly string[];
60
- readonly tools?: readonly {
61
- readonly name: string;
62
- readonly description?: string;
63
- }[];
64
- readonly model?: Pick<ModelDirective, "id" | "controls">;
65
- }
66
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,184 +0,0 @@
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>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,165 +0,0 @@
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.completed";
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 outcome: string;
116
- readonly code?: string;
117
- readonly attributes?: ToolResult;
118
- } | {
119
- readonly type: "tool.deferred";
120
- readonly executionId: string;
121
- readonly turnId: string;
122
- readonly stepId: string;
123
- readonly inputId?: string;
124
- readonly toolName: string;
125
- readonly callId: string;
126
- readonly invocationId: string;
127
- readonly middlewareId: string;
128
- readonly slot: string;
129
- readonly attributes: {
130
- readonly token?: JsonValue;
131
- };
132
- } | {
133
- readonly type: "turn.completed";
134
- readonly turnId: string;
135
- readonly stepId: string;
136
- readonly inputId?: string;
137
- readonly attributes: {
138
- readonly output: JsonValue;
139
- };
140
- } | {
141
- readonly type: "interaction.required";
142
- readonly turnId: string;
143
- readonly stepId: string;
144
- readonly inputId?: string;
145
- readonly interactionId: string;
146
- readonly kind: string;
147
- readonly callId?: string;
148
- readonly toolName?: string;
149
- readonly phase?: "interaction" | "execute";
150
- readonly attributes: {
151
- readonly prompt: string;
152
- readonly metadata?: JsonObject;
153
- };
154
- } | {
155
- readonly type: "tripwire";
156
- readonly turnId: string;
157
- readonly stepId?: string;
158
- readonly inputId?: string;
159
- readonly code: string;
160
- readonly scope: string;
161
- readonly attributes: {
162
- readonly message: string;
163
- };
164
- };
165
- export type Observer = (event: ObserveEvent) => void | Promise<void>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,25 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- export {};