@nylorun/harness 0.12.0-beta → 0.15.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 (137) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/HOST_CONTRACT.md +27 -0
  3. package/README.md +86 -5
  4. package/dist/compatibility.d.ts +3 -0
  5. package/dist/compatibility.js +3 -0
  6. package/dist/definition/agent-definition.d.ts +19 -0
  7. package/dist/definition/agent-definition.js +20 -0
  8. package/dist/definition/compatibility.d.ts +11 -0
  9. package/dist/definition/compatibility.js +30 -0
  10. package/dist/definition/registry.d.ts +10 -0
  11. package/dist/definition/registry.js +49 -0
  12. package/dist/index.d.ts +4 -15
  13. package/dist/index.js +1 -6
  14. package/dist/loop/dispatch.d.ts +2 -0
  15. package/dist/loop/dispatch.js +327 -0
  16. package/dist/loop/host-suspension.d.ts +6 -0
  17. package/dist/loop/host-suspension.js +10 -0
  18. package/dist/loop/initial-state.d.ts +13 -0
  19. package/dist/loop/initial-state.js +30 -0
  20. package/dist/loop/invocation.d.ts +24 -0
  21. package/dist/loop/invocation.js +37 -0
  22. package/dist/{model → loop/model}/adapters.d.ts +4 -2
  23. package/dist/{model → loop/model}/adapters.js +3 -2
  24. package/dist/{model → loop/model}/normalize.d.ts +2 -2
  25. package/dist/{model → loop/model}/normalize.js +2 -2
  26. package/dist/{model → loop/model}/prepared.d.ts +3 -3
  27. package/dist/{step → loop/model}/project.d.ts +1 -1
  28. package/dist/{step → loop/model}/project.js +2 -10
  29. package/dist/loop/observe.d.ts +17 -0
  30. package/dist/loop/observe.js +53 -0
  31. package/dist/loop/options.d.ts +11 -0
  32. package/dist/loop/options.js +69 -0
  33. package/dist/loop/resume.d.ts +4 -0
  34. package/dist/loop/resume.js +52 -0
  35. package/dist/loop/run.d.ts +5 -0
  36. package/dist/loop/run.js +264 -0
  37. package/dist/loop/state.d.ts +8 -0
  38. package/dist/loop/state.js +218 -0
  39. package/dist/{step → loop/step}/canonicalize.d.ts +2 -2
  40. package/dist/{step → loop/step}/canonicalize.js +2 -2
  41. package/dist/{step → loop/step}/compose.d.ts +3 -2
  42. package/dist/{step → loop/step}/compose.js +8 -5
  43. package/dist/loop/step/context-draft.d.ts +8 -0
  44. package/dist/{step → loop/step}/context-draft.js +5 -22
  45. package/dist/loop/step/describe.d.ts +9 -0
  46. package/dist/loop/step/describe.js +22 -0
  47. package/dist/loop/step/dynamics.d.ts +29 -0
  48. package/dist/loop/step/dynamics.js +147 -0
  49. package/dist/{step → loop/step}/model-configuration.d.ts +4 -3
  50. package/dist/{step → loop/step}/model-configuration.js +3 -3
  51. package/dist/loop/step/resolve.d.ts +11 -0
  52. package/dist/{step → loop/step}/resolve.js +5 -3
  53. package/dist/loop/step/run.d.ts +30 -0
  54. package/dist/{step → loop/step}/run.js +104 -53
  55. package/dist/loop/step/runtime.d.ts +40 -0
  56. package/dist/{step → loop/step}/seal.d.ts +13 -8
  57. package/dist/{step → loop/step}/seal.js +8 -6
  58. package/dist/{step → loop/step}/slot-assembly.d.ts +4 -4
  59. package/dist/{step → loop/step}/slot-assembly.js +4 -4
  60. package/dist/{step → loop/step}/step-context.d.ts +11 -12
  61. package/dist/{step → loop/step}/step-context.js +5 -27
  62. package/dist/loop/tool-result.d.ts +4 -0
  63. package/dist/loop/tool-result.js +30 -0
  64. package/dist/loop/transcript.d.ts +2 -0
  65. package/dist/{session/seed.js → loop/transcript.js} +11 -41
  66. package/dist/loop/waits.d.ts +50 -0
  67. package/dist/loop/waits.js +11 -0
  68. package/dist/run/durable.d.ts +71 -0
  69. package/dist/run/durable.js +164 -0
  70. package/dist/run/index.d.ts +33 -0
  71. package/dist/run/index.js +38 -0
  72. package/dist/types/client.d.ts +88 -0
  73. package/dist/types/execution.d.ts +114 -0
  74. package/dist/utils/ids.d.ts +1 -0
  75. package/dist/utils/ids.js +11 -1
  76. package/package.json +18 -6
  77. package/dist/build/agent.d.ts +0 -17
  78. package/dist/build/agent.js +0 -32
  79. package/dist/build/assemble.d.ts +0 -7
  80. package/dist/build/assemble.js +0 -41
  81. package/dist/build/bind-tool.d.ts +0 -3
  82. package/dist/build/bind-tool.js +0 -18
  83. package/dist/build/builder.d.ts +0 -38
  84. package/dist/build/builder.js +0 -136
  85. package/dist/build/helpers.d.ts +0 -6
  86. package/dist/build/helpers.js +0 -4
  87. package/dist/build/manifest.d.ts +0 -7
  88. package/dist/build/manifest.js +0 -20
  89. package/dist/build/schema.d.ts +0 -14
  90. package/dist/build/schema.js +0 -205
  91. package/dist/errors.d.ts +0 -17
  92. package/dist/errors.js +0 -17
  93. package/dist/session/capability-state.d.ts +0 -14
  94. package/dist/session/capability-state.js +0 -67
  95. package/dist/session/event-log.d.ts +0 -12
  96. package/dist/session/event-log.js +0 -63
  97. package/dist/session/input-queue.d.ts +0 -41
  98. package/dist/session/input-queue.js +0 -94
  99. package/dist/session/output-contract.d.ts +0 -6
  100. package/dist/session/output-contract.js +0 -12
  101. package/dist/session/record.d.ts +0 -11
  102. package/dist/session/record.js +0 -26
  103. package/dist/session/scheduler.d.ts +0 -62
  104. package/dist/session/scheduler.js +0 -475
  105. package/dist/session/seed.d.ts +0 -10
  106. package/dist/session/session.d.ts +0 -17
  107. package/dist/session/session.js +0 -101
  108. package/dist/session/state.d.ts +0 -15
  109. package/dist/session/state.js +0 -48
  110. package/dist/session/submission-stream.d.ts +0 -16
  111. package/dist/session/submission-stream.js +0 -46
  112. package/dist/step/context-draft.d.ts +0 -10
  113. package/dist/step/resolve.d.ts +0 -10
  114. package/dist/step/run.d.ts +0 -33
  115. package/dist/turn/plan-runner.d.ts +0 -72
  116. package/dist/turn/plan-runner.js +0 -389
  117. package/dist/turn/runner.d.ts +0 -69
  118. package/dist/turn/runner.js +0 -159
  119. package/dist/types/manifest.d.ts +0 -19
  120. package/dist/types/middleware.d.ts +0 -95
  121. package/dist/types/model.d.ts +0 -184
  122. package/dist/types/session.d.ts +0 -230
  123. package/dist/types/session.js +0 -1
  124. package/dist/types/shared.d.ts +0 -249
  125. package/dist/types/shared.js +0 -1
  126. package/dist/types/tool.d.ts +0 -139
  127. package/dist/types/tool.js +0 -1
  128. package/dist/utils/immutable.d.ts +0 -5
  129. package/dist/utils/immutable.js +0 -68
  130. package/dist/utils/maps.d.ts +0 -1
  131. package/dist/utils/maps.js +0 -37
  132. package/dist/utils/observe.d.ts +0 -3
  133. package/dist/utils/observe.js +0 -13
  134. /package/dist/{model → loop/model}/prepared.js +0 -0
  135. /package/dist/{types/manifest.js → loop/step/runtime.js} +0 -0
  136. /package/dist/types/{middleware.js → client.js} +0 -0
  137. /package/dist/types/{model.js → execution.js} +0 -0
@@ -1,159 +0,0 @@
1
- import { beginTurn, commitCandidate, commitFinal, commitToolResults, withStatus, } from "../session/state.js";
2
- import { runStep } from "../step/run.js";
3
- import { createId } from "../utils/ids.js";
4
- import { copyJson } from "../utils/immutable.js";
5
- import { ToolPlanRunner } from "./plan-runner.js";
6
- /** Advances one Turn until it finalizes, trips policy, or reaches a waiting barrier. */
7
- export class TurnRunner {
8
- agent;
9
- sessionId;
10
- session;
11
- constructor(agent, sessionId, session) {
12
- this.agent = agent;
13
- this.sessionId = sessionId;
14
- this.session = session;
15
- }
16
- async start(state, event, context, output) {
17
- const turnId = createId("turn");
18
- state = await context.commit(beginTurn(state, turnId, event), "input");
19
- context.onConversation({ type: "input", event, turnId });
20
- return this.advance(state, turnId, 1, [event], [], context, output);
21
- }
22
- async continue(state, context) {
23
- const turnId = createId("turn");
24
- return this.advance(beginTurn(state, turnId), turnId, 1, [], [], context);
25
- }
26
- async resume(state, pending, event, context) {
27
- const resume = pending.plan.interactionResume(event);
28
- const active = pending.plan.activeInteractionRecord(pending.turnId, pending.stepId, resume);
29
- state = await context.commit(withStatus(state, "running", undefined, active), "input", active);
30
- context.onConversation({ type: "input", event, turnId: pending.turnId });
31
- const progress = await this.runPlan(pending, context, event);
32
- if (progress.kind === "interaction-required")
33
- return this.waitForInteraction(state, pending, progress.interaction, context);
34
- if (progress.kind === "deferred")
35
- return this.waitForDeferred(state, pending, pending.plan.activeToolsRecord(pending.turnId, pending.stepId), context);
36
- state = await context.commit(commitToolResults(state, pending.turnId, pending.stepId, progress.results), "tool-results");
37
- pending.plan.publishSettlements(context.observe);
38
- const claimed = await context.claimInterrupts(state, pending.turnId);
39
- return this.advance(claimed.state, pending.turnId, pending.stepNumber + 1, claimed.arrivals, progress.results, context, pending.output);
40
- }
41
- async advance(initialState, turnId, firstStep, arrivals, initialResults, context, output) {
42
- let state = initialState;
43
- let stepArrivals = arrivals;
44
- let toolResults = initialResults;
45
- for (let stepNumber = firstStep;; stepNumber += 1) {
46
- const stepId = createId("step");
47
- const run = await runStep({
48
- agent: this.agent,
49
- observe: context.observe,
50
- state,
51
- sessionId: this.sessionId,
52
- turnId,
53
- stepId,
54
- turnNumber: state.turnCount,
55
- stepNumber,
56
- arrivals: stepArrivals,
57
- toolResults,
58
- signal: context.signal,
59
- session: this.session,
60
- states: context.states,
61
- output,
62
- recordModelRequested: (next, active) => context.commit(next, "model-requested", active),
63
- });
64
- context.assertCurrent();
65
- state = run.state;
66
- const pending = run.output.kind === "tools"
67
- ? {
68
- plan: new ToolPlanRunner(run.output.plan),
69
- turnId,
70
- stepId,
71
- stepNumber,
72
- ...(output === undefined ? {} : { output }),
73
- }
74
- : undefined;
75
- if (run.candidate) {
76
- const active = pending?.plan.activeToolsRecord(turnId, stepId);
77
- state = await context.commit(commitCandidate(state, turnId, stepId, run.candidate), "candidate", active);
78
- context.observe({
79
- type: "model.completed",
80
- turnId,
81
- stepId,
82
- ...(run.requestedModelId === undefined ? {} : { requestedModelId: run.requestedModelId }),
83
- attributes: run.candidate,
84
- });
85
- context.onConversation({ type: "candidate", turnId, stepId, candidate: run.candidate });
86
- }
87
- if (run.output.kind === "tripwire")
88
- return { kind: "tripwire", state, turnId, stepId, tripwire: run.output.tripwire };
89
- if (run.output.kind === "deferred-model") {
90
- state = await context.commit(withStatus(state, "waiting", undefined, run.output.active), "waiting", run.output.active);
91
- return { kind: "deferred", state, turnId, stepId, active: run.output.active };
92
- }
93
- if (run.output.kind === "final") {
94
- state = await context.commit(withStatus(commitFinal(state, turnId, stepId, run.output.output), "idle"), "final");
95
- return { kind: "final", state, turnId, stepId, output: run.output.output };
96
- }
97
- const toolPlan = run.output.plan;
98
- context.observe(() => ({
99
- type: "tool.sealed",
100
- turnId,
101
- stepId,
102
- attributes: {
103
- executable: Object.freeze(toolPlan.executable.map((entry) => Object.freeze({
104
- callId: entry.call.callId,
105
- toolName: entry.call.toolName,
106
- args: copyJson(entry.call.args),
107
- invocationId: entry.invocationId,
108
- owner: entry.owner,
109
- ...(entry.interaction === undefined
110
- ? {}
111
- : { interaction: copyJson(entry.interaction) }),
112
- }))),
113
- immediate: copyJson(toolPlan.immediateResults),
114
- },
115
- }));
116
- const progress = await this.runPlan(pending, context);
117
- if (progress.kind === "interaction-required")
118
- return this.waitForInteraction(state, pending, progress.interaction, context);
119
- if (progress.kind === "deferred")
120
- return this.waitForDeferred(state, pending, pending.plan.activeToolsRecord(turnId, stepId), context);
121
- state = await context.commit(commitToolResults(state, turnId, stepId, progress.results), "tool-results");
122
- pending.plan.publishSettlements(context.observe);
123
- const claimed = await context.claimInterrupts(state, turnId);
124
- state = claimed.state;
125
- stepArrivals = claimed.arrivals;
126
- toolResults = progress.results;
127
- }
128
- }
129
- async waitForInteraction(state, pending, interaction, context) {
130
- const active = pending.plan.activeInteractionRecord(pending.turnId, pending.stepId);
131
- state = await context.commit(withStatus(state, "waiting", interaction, active), "waiting", active);
132
- pending.plan.publishSettlements(context.observe);
133
- return { kind: "interaction-required", state, pending, interaction };
134
- }
135
- async waitForDeferred(state, pending, active, context) {
136
- state = await context.commit(withStatus(state, "waiting", undefined, active), "waiting", active);
137
- pending.plan.publishSettlements(context.observe);
138
- return {
139
- kind: "deferred",
140
- state,
141
- turnId: pending.turnId,
142
- stepId: pending.stepId,
143
- active,
144
- };
145
- }
146
- async runPlan(pending, context, resume) {
147
- context.onPlanActive(pending);
148
- const progress = await pending.plan.run({
149
- signal: context.signal,
150
- observe: context.observe,
151
- ids: { sessionId: this.sessionId, turnId: pending.turnId, stepId: pending.stepId },
152
- states: context.states,
153
- onModelCall: this.agent.invoke,
154
- }, resume);
155
- context.assertCurrent();
156
- context.onPlanActive(undefined);
157
- return progress;
158
- }
159
- }
@@ -1,19 +0,0 @@
1
- import type { BoundMiddleware, MiddlewareContributions } from "./middleware.js";
2
- import type { BuildDiagnostic } from "./shared.js";
3
- export interface MiddlewareManifest extends MiddlewareContributions {
4
- readonly id: string;
5
- }
6
- export interface AgentManifest {
7
- readonly id: string;
8
- readonly name: string;
9
- readonly middleware: readonly MiddlewareManifest[];
10
- }
11
- export type BuildResult<Agent> = {
12
- readonly ok: true;
13
- readonly agent: Agent;
14
- readonly manifest: AgentManifest;
15
- } | {
16
- readonly ok: false;
17
- readonly diagnostics: readonly BuildDiagnostic[];
18
- };
19
- export type { BoundMiddleware };
@@ -1,95 +0,0 @@
1
- import type { ContextMutationOptions, ModelCandidate, ModelDirective, ModelToolCall, ModelConfigurationMutationOptions } from "./model.js";
2
- import type { InputEvent, SessionIdentity, TranscriptEntry } from "./session.js";
3
- import type { ContextItem, JsonObject, Tripwire } from "./shared.js";
4
- import type { Interaction, ToolDefinition, ToolResult } from "./tool.js";
5
- export interface StepInput {
6
- readonly sessionId: string;
7
- readonly turnId: string;
8
- readonly stepId: string;
9
- /** One-based position of this turn within the Session. */
10
- readonly turnNumber: number;
11
- /** One-based position of this Model Step within the Turn. */
12
- readonly stepNumber: number;
13
- readonly session: Readonly<{
14
- readonly userId?: string;
15
- readonly context?: JsonObject;
16
- }>;
17
- readonly arrivals: readonly InputEvent[];
18
- readonly toolResults: readonly ToolResult[];
19
- readonly transcript: readonly TranscriptEntry[];
20
- }
21
- interface StepRequestBase {
22
- /** Opaque identity of the Session that owns this Step. */
23
- readonly sessionId: string;
24
- /** Opaque identity of the Turn that owns this Step. */
25
- readonly turnId: string;
26
- /** Opaque identity of this Model Step. */
27
- readonly stepId: string;
28
- readonly session: StepInput["session"];
29
- readonly turnNumber: number;
30
- readonly stepNumber: number;
31
- readonly arrivals: readonly InputEvent[];
32
- readonly toolResults: readonly ToolResult[];
33
- readonly transcript: readonly TranscriptEntry[];
34
- readonly context: {
35
- set(slot: string, items: readonly ContextItem[], options?: ContextMutationOptions): void;
36
- };
37
- readonly configuration: {
38
- readonly instructions: {
39
- set(slot: string, items: readonly string[], options?: ModelConfigurationMutationOptions): void;
40
- };
41
- readonly tools: {
42
- set(slot: string, tools: readonly ToolDefinition[], options?: ModelConfigurationMutationOptions): void;
43
- };
44
- readonly model: {
45
- select(directive: ModelDirective, options?: Omit<ModelConfigurationMutationOptions, "order">): void;
46
- replace(directive: ModelDirective, options?: Omit<ModelConfigurationMutationOptions, "order">): void;
47
- clear(options?: Omit<ModelConfigurationMutationOptions, "order">): void;
48
- };
49
- };
50
- tripwire(error: Tripwire): StepResponse;
51
- }
52
- export type StepRequest<State = never> = StepRequestBase & ([State] extends [never] ? object : {
53
- readonly state: Promise<State>;
54
- });
55
- export interface StepResponse {
56
- candidate(): Readonly<ModelCandidate> | undefined;
57
- toolCalls(): readonly ModelToolCall[];
58
- replace(candidate: ModelCandidate): void;
59
- deny(callId: string, reason: string): void;
60
- requireInteraction(callId: string, interaction: Interaction): void;
61
- tripwire(error: Tripwire): StepResponse;
62
- }
63
- export type StepMiddleware<State = never> = (request: StepRequest<State>, next: () => Promise<StepResponse>) => Promise<StepResponse>;
64
- export interface CapabilityState<State> {
65
- create(session: SessionIdentity, signal: AbortSignal): State | Promise<State>;
66
- dispose?(value: State): void | Promise<void>;
67
- }
68
- export type CapabilityItems<Item> = readonly Item[] | Readonly<{
69
- readonly slot: string;
70
- readonly items: readonly Item[];
71
- }>;
72
- /** A named capability that may supply static model surface and one typed middleware handler. */
73
- export interface CapabilityDeclaration<State = never> {
74
- readonly id: string;
75
- readonly tools?: CapabilityItems<ToolDefinition<ToolDefinition["inputSchema"], State>>;
76
- readonly instructions?: CapabilityItems<string>;
77
- readonly model?: ModelDirective;
78
- readonly state?: CapabilityState<State>;
79
- readonly middleware?: StepMiddleware<State>;
80
- }
81
- export interface MiddlewareContributions {
82
- readonly instructions?: readonly string[];
83
- readonly tools?: readonly {
84
- readonly name: string;
85
- readonly description?: string;
86
- }[];
87
- readonly model?: Pick<ModelDirective, "id" | "controls">;
88
- }
89
- export interface BoundMiddleware {
90
- readonly id: string;
91
- readonly handle: StepMiddleware;
92
- readonly state?: CapabilityState<unknown>;
93
- readonly contributions?: MiddlewareContributions;
94
- }
95
- export {};
@@ -1,184 +0,0 @@
1
- import type { ContextItem, DeferredOutcome, JsonObject, JsonValue } from "./shared.js";
2
- import type { InputEvent, TranscriptEntry } from "./session.js";
3
- import type { BoundToolDefinition, 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
- /** Bound tools are retained for execution. */
85
- readonly tools: readonly BoundToolDefinition[];
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 sessionId: 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
- /** Tools are normalized and immutable by the time a Model sees them. */
118
- readonly tools: readonly BoundToolDefinition[];
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 sessionId: 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 | DeferredOutcome>;
@@ -1,230 +0,0 @@
1
- import type { ModelAdapter, ModelCall, ModelCandidate } from "./model.js";
2
- import type { JsonObject, JsonValue, Observer, Tripwire } from "./shared.js";
3
- import type { RequiredInteraction, SchemaOutput, ToolExecutionResume, ToolOwner, ToolResult, ToolSchemaSource } 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
- export type SessionEvent<Output = string> = {
24
- readonly type: "input";
25
- readonly event: InputEvent;
26
- readonly turnId: string;
27
- } | {
28
- readonly type: "candidate";
29
- readonly turnId: string;
30
- readonly stepId: string;
31
- readonly candidate: ModelCandidate;
32
- } | {
33
- readonly type: "final";
34
- readonly output: Output;
35
- readonly turnId: string;
36
- } | {
37
- readonly type: "interaction.required";
38
- readonly interaction: RequiredInteraction;
39
- readonly turnId: string;
40
- } | {
41
- readonly type: "tripwire";
42
- readonly tripwire: Tripwire;
43
- readonly turnId: string;
44
- } | {
45
- readonly type: "execution.deferred";
46
- readonly active: ActiveExecutionRecord;
47
- readonly turnId: string;
48
- } | {
49
- readonly type: "input.queued";
50
- readonly inputId: string;
51
- } | {
52
- readonly type: "input.rejected";
53
- readonly inputId: string;
54
- readonly reason: string;
55
- } | {
56
- readonly type: "input.cancelled";
57
- readonly inputId: string;
58
- readonly reason: string;
59
- } | {
60
- readonly type: "session.stopped";
61
- readonly sessionId: string;
62
- };
63
- export interface InputCompletion<Output = string> {
64
- readonly inputId: string;
65
- readonly status: "completed" | "waiting" | "rejected" | "cancelled" | "stopped";
66
- readonly events: readonly SessionEvent<Output>[];
67
- }
68
- export interface InputHandle<Output = string> {
69
- readonly inputId: string;
70
- readonly completed: Promise<InputCompletion<Output>>;
71
- }
72
- export interface SessionOptions {
73
- readonly onModelCall: ModelAdapter;
74
- readonly id?: string;
75
- readonly userId?: string;
76
- readonly context?: JsonObject;
77
- readonly seed?: never;
78
- readonly recorder?: SessionRecorder;
79
- readonly observer?: Observer;
80
- }
81
- /** Stable host-owned facts available while a capability creates session-local state. */
82
- export interface SessionIdentity {
83
- readonly id: string;
84
- readonly userId?: string;
85
- readonly context?: JsonObject;
86
- }
87
- export interface SeededSessionOptions {
88
- readonly onModelCall: ModelAdapter;
89
- readonly seed: SessionSeed;
90
- readonly recorder?: SessionRecorder;
91
- readonly observer?: Observer;
92
- readonly id?: never;
93
- readonly userId?: never;
94
- readonly context?: never;
95
- }
96
- export type SessionRunOptions = SessionOptions | SeededSessionOptions;
97
- export interface InputOptions {
98
- readonly signal?: AbortSignal;
99
- }
100
- /** Per-turn, locally-enforced terminal JSON contract. */
101
- export interface OutputInputOptions<Schema extends ToolSchemaSource = ToolSchemaSource> extends InputOptions {
102
- readonly outputSchema?: Schema;
103
- }
104
- /** Ordered, model-visible user content. Media references stay host-owned JSON values. */
105
- export type UserContentPart = {
106
- readonly type: "text";
107
- readonly text: string;
108
- } | {
109
- readonly type: "media";
110
- readonly mediaType: string;
111
- readonly reference: JsonValue;
112
- };
113
- export type MessageInput = string | {
114
- readonly text: string;
115
- readonly metadata?: JsonObject;
116
- } | {
117
- readonly content: readonly UserContentPart[];
118
- readonly metadata?: JsonObject;
119
- };
120
- export type InteractionReply = Extract<InputEvent, {
121
- kind: "approve" | "respond";
122
- }>;
123
- /** Ordinary user text or an interaction reply. Use `Session.interrupt()` for barge-in text. */
124
- export type SessionInput = MessageInput | InteractionReply;
125
- export interface TranscriptInputEntry {
126
- readonly kind: "input";
127
- readonly turnId: string;
128
- readonly event: InputEvent;
129
- }
130
- export interface TranscriptCandidateEntry {
131
- readonly kind: "candidate";
132
- readonly turnId: string;
133
- readonly stepId: string;
134
- readonly candidate: ModelCandidate;
135
- }
136
- export interface TranscriptToolsEntry {
137
- readonly kind: "tool-results";
138
- readonly turnId: string;
139
- readonly stepId: string;
140
- readonly results: readonly ToolResult[];
141
- }
142
- export interface TranscriptFinalEntry {
143
- readonly kind: "final";
144
- readonly turnId: string;
145
- readonly stepId: string;
146
- readonly output: JsonValue;
147
- }
148
- export type TranscriptEntry = TranscriptInputEntry | TranscriptCandidateEntry | TranscriptToolsEntry | TranscriptFinalEntry;
149
- export interface SessionSnapshot {
150
- readonly id: string;
151
- readonly status: "idle" | "running" | "waiting" | "stopped";
152
- readonly turnCount: number;
153
- readonly revision: number;
154
- readonly transcript: readonly TranscriptEntry[];
155
- readonly pendingInteraction?: RequiredInteraction;
156
- readonly active?: ActiveExecutionRecord;
157
- }
158
- export interface SessionSeed {
159
- readonly id?: string;
160
- readonly userId?: string;
161
- readonly context?: JsonObject;
162
- readonly turnCount?: number;
163
- readonly revision?: number;
164
- readonly transcript: readonly TranscriptEntry[];
165
- }
166
- export interface ActiveModelExecutionRecord {
167
- readonly kind: "model";
168
- readonly turnId: string;
169
- readonly stepId: string;
170
- readonly invocationId: string;
171
- readonly call: ModelCall;
172
- readonly token?: JsonValue;
173
- }
174
- export interface ActiveToolCallRecord {
175
- readonly callId: string;
176
- readonly toolName: string;
177
- readonly args: JsonValue;
178
- readonly invocationId: string;
179
- readonly owner: ToolOwner;
180
- readonly status: "pending" | "settled" | "deferred";
181
- readonly result?: ToolResult;
182
- readonly token?: JsonValue;
183
- }
184
- export interface ActiveToolsExecutionRecord {
185
- readonly kind: "tools";
186
- readonly turnId: string;
187
- readonly stepId: string;
188
- readonly calls: readonly ActiveToolCallRecord[];
189
- }
190
- export interface ActiveInteractionExecutionRecord {
191
- readonly kind: "interaction";
192
- readonly turnId: string;
193
- readonly stepId: string;
194
- readonly callId: string;
195
- readonly toolName: string;
196
- readonly interaction: RequiredInteraction;
197
- readonly token?: JsonValue;
198
- readonly resume?: ToolExecutionResume;
199
- readonly tools: ActiveToolsExecutionRecord;
200
- }
201
- export type ActiveExecutionRecord = ActiveModelExecutionRecord | ActiveToolsExecutionRecord | ActiveInteractionExecutionRecord;
202
- export interface SessionRecord {
203
- readonly version: 1;
204
- readonly revision: number;
205
- readonly transition: "input" | "model-requested" | "candidate" | "tool-results" | "waiting" | "final" | "stopped";
206
- readonly session: {
207
- readonly id: string;
208
- readonly userId?: string;
209
- readonly context?: JsonObject;
210
- readonly turnCount: number;
211
- readonly status: SessionSnapshot["status"];
212
- };
213
- readonly transcript: readonly TranscriptEntry[];
214
- readonly active?: ActiveExecutionRecord;
215
- }
216
- export interface SessionRecorder {
217
- record(value: SessionRecord): Promise<void>;
218
- }
219
- export interface Session {
220
- readonly id: string;
221
- readonly state: SessionSnapshot;
222
- input<Schema extends ToolSchemaSource>(event: MessageInput, options: OutputInputOptions<Schema> & {
223
- readonly outputSchema: Schema;
224
- }): InputHandle<SchemaOutput<Schema>>;
225
- input(event: SessionInput, options?: InputOptions): InputHandle<string>;
226
- interrupt(event: MessageInput, options?: InputOptions): InputHandle;
227
- continue(options?: InputOptions): InputHandle;
228
- stream(): AsyncIterable<SessionEvent<JsonValue>>;
229
- stop(reason?: string): Promise<void>;
230
- }
@@ -1 +0,0 @@
1
- export {};