@telnyx/agent-harness 0.1.0-beta.0
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.
- package/README.md +179 -0
- package/dist/approvals.d.ts +140 -0
- package/dist/approvals.js +699 -0
- package/dist/channel.d.ts +178 -0
- package/dist/channel.js +184 -0
- package/dist/contract.d.ts +50 -0
- package/dist/contract.js +278 -0
- package/dist/durable.d.ts +81 -0
- package/dist/durable.js +650 -0
- package/dist/harness.d.ts +199 -0
- package/dist/harness.js +1223 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +19 -0
- package/dist/lifecycle.d.ts +9 -0
- package/dist/lifecycle.js +25 -0
- package/dist/node-adapter.d.ts +71 -0
- package/dist/node-adapter.js +736 -0
- package/dist/ports.d.ts +99 -0
- package/dist/ports.js +3 -0
- package/dist/runtime-adapter.d.ts +15 -0
- package/dist/runtime-adapter.js +70 -0
- package/dist/runtime-config.d.ts +38 -0
- package/dist/runtime-config.js +104 -0
- package/dist/scheduling.d.ts +46 -0
- package/dist/scheduling.js +425 -0
- package/dist/steps.d.ts +52 -0
- package/dist/steps.js +310 -0
- package/dist/tool-context.d.ts +8 -0
- package/dist/tool-context.js +9 -0
- package/dist/workspace.d.ts +151 -0
- package/dist/workspace.js +404 -0
- package/package.json +58 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { type FinishReason, type GenerateTextOnFinishCallback, type GenerateTextOnStartCallback, type GenerateTextOnStepFinishCallback, type GenerateTextOnStepStartCallback, type GenerateTextOnToolCallFinishCallback, type GenerateTextOnToolCallStartCallback, type LanguageModel, type ToolSet } from "ai";
|
|
2
|
+
import type { AgentHarnessPorts } from "./ports.js";
|
|
3
|
+
import { type HarnessApprovalLedger } from "./approvals.js";
|
|
4
|
+
import { type HarnessCheckpoint, type HarnessRunLedger } from "./durable.js";
|
|
5
|
+
import { type HarnessMiddleware } from "./lifecycle.js";
|
|
6
|
+
import { type HarnessRuntimeConfig } from "./runtime-config.js";
|
|
7
|
+
import type { HarnessStepContext } from "./steps.js";
|
|
8
|
+
/** Structural subset of an AI SDK output definition used for parsed-result inference. */
|
|
9
|
+
interface HarnessOutputDefinition<Parsed = unknown> {
|
|
10
|
+
parseCompleteOutput(options: {
|
|
11
|
+
text: string;
|
|
12
|
+
}, context: unknown): Promise<Parsed>;
|
|
13
|
+
}
|
|
14
|
+
/** Complete parsed value associated with an AI SDK output definition. */
|
|
15
|
+
type HarnessParsedOutput<Definition> = Definition extends HarnessOutputDefinition<infer Parsed> ? Parsed : never;
|
|
16
|
+
/** Raised after the final allowed model step still requests executable tools. */
|
|
17
|
+
export declare class HarnessStepLimitError extends Error {
|
|
18
|
+
readonly maxSteps: number;
|
|
19
|
+
readonly completedSteps: number;
|
|
20
|
+
readonly lastToolCalls: ReadonlyArray<Readonly<{
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
}>>;
|
|
24
|
+
readonly code: "HARNESS_STEP_LIMIT";
|
|
25
|
+
constructor(maxSteps: number, completedSteps: number, lastToolCalls: ReadonlyArray<Readonly<{
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
}>>);
|
|
29
|
+
}
|
|
30
|
+
/** Safe provider failure fields. Raw causes, URLs, headers, and bodies are never retained. */
|
|
31
|
+
export interface HarnessProviderDiagnostics {
|
|
32
|
+
readonly provider: string;
|
|
33
|
+
readonly modelId: string;
|
|
34
|
+
readonly causeName: string;
|
|
35
|
+
readonly statusCode?: number;
|
|
36
|
+
readonly retryable?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** Stable provider-boundary error containing only allowlisted diagnostics. */
|
|
39
|
+
export declare class HarnessProviderError extends Error {
|
|
40
|
+
readonly diagnostics: HarnessProviderDiagnostics;
|
|
41
|
+
readonly code: "HARNESS_PROVIDER_ERROR";
|
|
42
|
+
constructor(diagnostics: HarnessProviderDiagnostics);
|
|
43
|
+
}
|
|
44
|
+
/** Local tool failure used when a successful execution returns an unsafe output. */
|
|
45
|
+
export declare class HarnessToolOutputError extends Error {
|
|
46
|
+
readonly toolName: string;
|
|
47
|
+
readonly code: "HARNESS_TOOL_OUTPUT_ERROR";
|
|
48
|
+
constructor(toolName: string);
|
|
49
|
+
}
|
|
50
|
+
/** Stable cancellation classification for an aborted caller-owned turn signal. */
|
|
51
|
+
export declare class HarnessCancellationError extends Error {
|
|
52
|
+
readonly code: "HARNESS_CANCELLED";
|
|
53
|
+
constructor();
|
|
54
|
+
}
|
|
55
|
+
/** Stable aggregate retaining a primary turn failure when its observer also fails. */
|
|
56
|
+
export declare class HarnessObserverError extends Error {
|
|
57
|
+
readonly primary: unknown;
|
|
58
|
+
readonly observer: unknown;
|
|
59
|
+
readonly phase: "cancel" | "error";
|
|
60
|
+
readonly code: "HARNESS_OBSERVER_ERROR";
|
|
61
|
+
constructor(primary: unknown, observer: unknown, phase: "cancel" | "error");
|
|
62
|
+
}
|
|
63
|
+
/** Construction input for one portable model/tool turn engine. */
|
|
64
|
+
export interface HarnessSpec<State extends Record<string, unknown>, TOOLS extends ToolSet, OutputDefinition extends HarnessOutputDefinition | undefined = undefined> {
|
|
65
|
+
/** Durable host capabilities supplied through the versioned ports seam. */
|
|
66
|
+
ports: AgentHarnessPorts<State>;
|
|
67
|
+
/** AI SDK v6 language model. */
|
|
68
|
+
model: LanguageModel;
|
|
69
|
+
/** Host-owned models selectable only by a named runtime configuration key. */
|
|
70
|
+
models?: Readonly<Record<string, LanguageModel>>;
|
|
71
|
+
/** The one explicit, flat tool set available to the model. */
|
|
72
|
+
tools: TOOLS;
|
|
73
|
+
/**
|
|
74
|
+
* Private, host-owned Service Account action mapping. Every supplied tool is
|
|
75
|
+
* mapped exactly once when approval-capable tools are present; model/tool
|
|
76
|
+
* metadata is never treated as an authorization authority.
|
|
77
|
+
*/
|
|
78
|
+
authorization?: Readonly<{
|
|
79
|
+
toolActions: Readonly<Record<string, string>>;
|
|
80
|
+
/** Required host-owned lifetime for durable approval decisions. */
|
|
81
|
+
approvalTtlMs?: number;
|
|
82
|
+
}>;
|
|
83
|
+
/** Optional static subset of the injected tool set. */
|
|
84
|
+
activeTools?: readonly (keyof TOOLS & string)[];
|
|
85
|
+
/** Optional static instructions supplied to every model step. */
|
|
86
|
+
instructions?: string;
|
|
87
|
+
/** Optional host-owned structured output mode. */
|
|
88
|
+
output?: OutputDefinition;
|
|
89
|
+
/** Host-owned output modes selectable only by a named runtime configuration key. */
|
|
90
|
+
outputs?: Readonly<Record<string, OutputDefinition>>;
|
|
91
|
+
/** Required bounded turn limits. */
|
|
92
|
+
limits: Readonly<{
|
|
93
|
+
steps: number;
|
|
94
|
+
}>;
|
|
95
|
+
/** Ordered transport-neutral lifecycle middleware. */
|
|
96
|
+
middleware?: Readonly<{
|
|
97
|
+
turn?: readonly HarnessMiddleware<HarnessTurnMiddlewareContext<TOOLS, OutputDefinition>, HarnessTurnResult<HarnessParsedOutput<OutputDefinition>>>[];
|
|
98
|
+
modelStep?: readonly HarnessMiddleware<HarnessModelStepMiddlewareContext<TOOLS>, unknown>[];
|
|
99
|
+
tool?: readonly HarnessMiddleware<HarnessToolMiddlewareContext<TOOLS>, unknown>[];
|
|
100
|
+
}>;
|
|
101
|
+
/** Deterministic durability seams used by recovery tests. */
|
|
102
|
+
durability?: Readonly<{
|
|
103
|
+
checkpoints?: HarnessCheckpoint;
|
|
104
|
+
/** Deterministic test seam for delaying one durable tool call before execution. */
|
|
105
|
+
onToolCallStart?: GenerateTextOnToolCallStartCallback<TOOLS>;
|
|
106
|
+
/** Explicit version for the built-in durable tool-effect contract. */
|
|
107
|
+
toolStepVersion?: string;
|
|
108
|
+
}>;
|
|
109
|
+
}
|
|
110
|
+
/** Transport-safe aggregate token usage for a completed turn. */
|
|
111
|
+
export interface HarnessUsage {
|
|
112
|
+
readonly inputTokens: number | undefined;
|
|
113
|
+
readonly outputTokens: number | undefined;
|
|
114
|
+
readonly totalTokens: number | undefined;
|
|
115
|
+
}
|
|
116
|
+
/** Transport-neutral result of a completed turn. */
|
|
117
|
+
export interface HarnessTurnResult<Output = unknown> {
|
|
118
|
+
readonly text: string;
|
|
119
|
+
readonly stepCount: number;
|
|
120
|
+
readonly finishReason: FinishReason;
|
|
121
|
+
readonly journalThrough: number;
|
|
122
|
+
readonly usage: HarnessUsage;
|
|
123
|
+
/** Parsed AI SDK output when a structured output mode is configured. */
|
|
124
|
+
readonly output?: Output;
|
|
125
|
+
}
|
|
126
|
+
/** Immutable turn-local context passed to turn middleware. */
|
|
127
|
+
export interface HarnessTurnMiddlewareContext<TOOLS extends ToolSet = ToolSet, OutputDefinition extends HarnessOutputDefinition | undefined = undefined> {
|
|
128
|
+
readonly phase: "turn";
|
|
129
|
+
readonly input: string;
|
|
130
|
+
readonly config: HarnessRuntimeConfig<LanguageModel, TOOLS, OutputDefinition>;
|
|
131
|
+
readonly signal: AbortSignal | undefined;
|
|
132
|
+
}
|
|
133
|
+
/** Immutable context passed around an actual model invocation. */
|
|
134
|
+
export interface HarnessModelStepMiddlewareContext<TOOLS extends ToolSet = ToolSet> {
|
|
135
|
+
readonly phase: "modelStep";
|
|
136
|
+
readonly config: HarnessRuntimeConfig<LanguageModel, TOOLS>;
|
|
137
|
+
readonly stepNumber: number;
|
|
138
|
+
readonly signal: AbortSignal | undefined;
|
|
139
|
+
}
|
|
140
|
+
/** Immutable context passed around an actual server-tool invocation. */
|
|
141
|
+
export interface HarnessToolMiddlewareContext<TOOLS extends ToolSet = ToolSet> {
|
|
142
|
+
readonly phase: "tool";
|
|
143
|
+
readonly config: HarnessRuntimeConfig<LanguageModel, TOOLS>;
|
|
144
|
+
readonly toolName: string;
|
|
145
|
+
readonly toolCallId: string | undefined;
|
|
146
|
+
readonly signal: AbortSignal | undefined;
|
|
147
|
+
}
|
|
148
|
+
/** One completed model step, excluding provider request/response bodies and metadata. */
|
|
149
|
+
export interface HarnessStep {
|
|
150
|
+
number: number;
|
|
151
|
+
text: string;
|
|
152
|
+
finishReason: FinishReason;
|
|
153
|
+
toolCalls: ReadonlyArray<Readonly<{
|
|
154
|
+
id: string;
|
|
155
|
+
name: string;
|
|
156
|
+
input: unknown;
|
|
157
|
+
}>>;
|
|
158
|
+
journalThrough: number;
|
|
159
|
+
toolResults: ReadonlyArray<Readonly<{
|
|
160
|
+
id: string;
|
|
161
|
+
name: string;
|
|
162
|
+
output: unknown;
|
|
163
|
+
isError: boolean;
|
|
164
|
+
}>>;
|
|
165
|
+
}
|
|
166
|
+
/** Per-turn transport-neutral observation callbacks. */
|
|
167
|
+
export interface HarnessTurnOptions<TOOLS extends ToolSet = ToolSet, OutputDefinition extends HarnessOutputDefinition | undefined = undefined> {
|
|
168
|
+
/** Caller-owned cancellation signal passed to AI SDK without transport coupling. */
|
|
169
|
+
signal?: AbortSignal;
|
|
170
|
+
/** Durable context supplied only by the harness run ledger. */
|
|
171
|
+
steps?: HarnessStepContext;
|
|
172
|
+
/** Runs after the completed step has been durably journaled. */
|
|
173
|
+
onStepCommitted?: (step: HarnessStep) => void | Promise<void>;
|
|
174
|
+
/** Runs once after the complete successful output has been durably journaled. */
|
|
175
|
+
onOutput?: (output: HarnessTurnResult<HarnessParsedOutput<OutputDefinition>>) => void | Promise<void>;
|
|
176
|
+
/** AI SDK lifecycle callbacks, chained after harness durability work. */
|
|
177
|
+
callbacks?: Readonly<{
|
|
178
|
+
onStart?: GenerateTextOnStartCallback;
|
|
179
|
+
onStepStart?: GenerateTextOnStepStartCallback<TOOLS>;
|
|
180
|
+
onToolCallStart?: GenerateTextOnToolCallStartCallback<TOOLS>;
|
|
181
|
+
onToolCallFinish?: GenerateTextOnToolCallFinishCallback<TOOLS>;
|
|
182
|
+
onStepFinish?: GenerateTextOnStepFinishCallback<TOOLS>;
|
|
183
|
+
onFinish?: GenerateTextOnFinishCallback<TOOLS>;
|
|
184
|
+
}>;
|
|
185
|
+
/** Runs once after cleanup when the caller-owned signal cancels a turn. */
|
|
186
|
+
onCancel?: (error: HarnessCancellationError) => void | Promise<void>;
|
|
187
|
+
/** Runs once after cleanup for non-cancellation failures. */
|
|
188
|
+
onError?: (error: unknown) => void | Promise<void>;
|
|
189
|
+
}
|
|
190
|
+
/** Portable harness constructed by {@link createHarness}. */
|
|
191
|
+
export interface Harness<TOOLS extends ToolSet = ToolSet, OutputDefinition extends HarnessOutputDefinition | undefined = undefined> extends HarnessRunLedger {
|
|
192
|
+
turn(input: string, options?: HarnessTurnOptions<TOOLS, OutputDefinition>): Promise<HarnessTurnResult<HarnessParsedOutput<OutputDefinition>>>;
|
|
193
|
+
/** Durable, authorization-gated approval inspection and decisions. */
|
|
194
|
+
readonly approvals: HarnessApprovalLedger;
|
|
195
|
+
}
|
|
196
|
+
/** Construct a portable AI SDK v6 turn engine over an explicit ports object. */
|
|
197
|
+
export declare function createHarness<State extends Record<string, unknown>, TOOLS extends ToolSet, OutputDefinition extends HarnessOutputDefinition | undefined = undefined>(spec: HarnessSpec<State, TOOLS, OutputDefinition>): Harness<TOOLS, OutputDefinition>;
|
|
198
|
+
export {};
|
|
199
|
+
//# sourceMappingURL=harness.d.ts.map
|