@axlsdk/axl 0.7.5 → 0.8.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 +29 -6
- package/dist/index.cjs +267 -92
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +48 -3
- package/dist/index.d.ts +48 -3
- package/dist/index.js +266 -92
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -108,6 +108,8 @@ type StreamChunk = {
|
|
|
108
108
|
reasoning_tokens?: number;
|
|
109
109
|
cached_tokens?: number;
|
|
110
110
|
};
|
|
111
|
+
/** Estimated cost in USD for this call, computed the same way as ProviderResponse.cost. */
|
|
112
|
+
cost?: number;
|
|
111
113
|
/** Provider-specific opaque metadata (e.g. raw Gemini parts with thought signatures). */
|
|
112
114
|
providerMetadata?: Record<string, unknown>;
|
|
113
115
|
};
|
|
@@ -194,10 +196,22 @@ type VoteOptions<T> = {
|
|
|
194
196
|
scorer?: (value: T) => number | Promise<number>;
|
|
195
197
|
reducer?: (values: T[]) => T | Promise<T>;
|
|
196
198
|
};
|
|
199
|
+
/** Context passed to the verify function on retry (undefined on first call). */
|
|
200
|
+
type VerifyRetry<T> = {
|
|
201
|
+
/** Error message from the failed attempt (schema or validate). */
|
|
202
|
+
error: string;
|
|
203
|
+
/** Raw return value from the previous fn call. */
|
|
204
|
+
output: unknown;
|
|
205
|
+
/** Schema-parsed object — only present when schema passed but validate failed.
|
|
206
|
+
* Safe to modify and return as the next attempt. */
|
|
207
|
+
parsed?: T;
|
|
208
|
+
};
|
|
197
209
|
/** Verify options */
|
|
198
210
|
type VerifyOptions<T> = {
|
|
199
211
|
retries?: number;
|
|
200
212
|
fallback?: T;
|
|
213
|
+
/** Post-schema business rule validation on the parsed object. */
|
|
214
|
+
validate?: OutputValidator<T>;
|
|
201
215
|
};
|
|
202
216
|
/** AwaitHuman options */
|
|
203
217
|
type AwaitHumanOptions = {
|
|
@@ -209,6 +223,12 @@ type AwaitHumanOptions = {
|
|
|
209
223
|
type AskOptions<T = unknown> = {
|
|
210
224
|
schema?: z.ZodType<T>;
|
|
211
225
|
retries?: number;
|
|
226
|
+
/** Post-schema business rule validation. Receives the parsed typed object after schema
|
|
227
|
+
* validation succeeds. Only runs when `schema` is set. Retries with accumulating context
|
|
228
|
+
* on failure (LLM sees all previous failed attempts). Throws `ValidationError` on exhaustion. */
|
|
229
|
+
validate?: OutputValidator<T>;
|
|
230
|
+
/** Maximum retries for validate failures (default: 2). */
|
|
231
|
+
validateRetries?: number;
|
|
212
232
|
/** Per-call metadata passed to dynamic model/system selector functions. */
|
|
213
233
|
metadata?: Record<string, unknown>;
|
|
214
234
|
/** Override temperature for this call. */
|
|
@@ -238,11 +258,17 @@ type DelegateOptions<T = unknown> = {
|
|
|
238
258
|
metadata?: Record<string, unknown>;
|
|
239
259
|
/** Number of retries for structured output validation (passed to the final ask). */
|
|
240
260
|
retries?: number;
|
|
261
|
+
/** Post-schema business rule validation. Passed through to the final `ctx.ask()` call. */
|
|
262
|
+
validate?: OutputValidator<T>;
|
|
263
|
+
/** Maximum retries for validate failures (default: 2). Passed through to the final `ctx.ask()` call. */
|
|
264
|
+
validateRetries?: number;
|
|
241
265
|
};
|
|
242
266
|
/** Race options */
|
|
243
267
|
type RaceOptions<T = unknown> = {
|
|
244
268
|
/** Schema to validate each result. Invalid results are discarded and the race continues. */
|
|
245
269
|
schema?: z.ZodType<T>;
|
|
270
|
+
/** Post-schema business rule validation. Results that fail are discarded (same as schema failures). */
|
|
271
|
+
validate?: OutputValidator<T>;
|
|
246
272
|
};
|
|
247
273
|
/** Execution status */
|
|
248
274
|
type ExecutionStatus = 'running' | 'completed' | 'failed' | 'waiting';
|
|
@@ -250,7 +276,7 @@ type ExecutionStatus = 'running' | 'completed' | 'failed' | 'waiting';
|
|
|
250
276
|
type TraceEvent = {
|
|
251
277
|
executionId: string;
|
|
252
278
|
step: number;
|
|
253
|
-
type: 'agent_call' | 'tool_call' | 'verify' | 'handoff' | 'delegate' | 'tool_denied' | 'log' | 'workflow_start' | 'workflow_end' | 'guardrail';
|
|
279
|
+
type: 'agent_call' | 'tool_call' | 'verify' | 'handoff' | 'delegate' | 'tool_denied' | 'log' | 'workflow_start' | 'workflow_end' | 'guardrail' | 'validate';
|
|
254
280
|
workflow?: string;
|
|
255
281
|
agent?: string;
|
|
256
282
|
tool?: string;
|
|
@@ -285,6 +311,18 @@ type GuardrailsConfig = {
|
|
|
285
311
|
onBlock?: GuardrailBlockHandler;
|
|
286
312
|
maxRetries?: number;
|
|
287
313
|
};
|
|
314
|
+
/** Result of a validate check (post-schema business rule validation).
|
|
315
|
+
* Note: uses `valid: true` = pass, unlike `GuardrailResult` which uses `block: true` = fail. */
|
|
316
|
+
type ValidateResult = {
|
|
317
|
+
valid: boolean;
|
|
318
|
+
reason?: string;
|
|
319
|
+
};
|
|
320
|
+
/** Output validator function. Runs after schema parsing on the typed object.
|
|
321
|
+
* Only invoked when a schema is provided on the `ctx.ask()` call — without a schema,
|
|
322
|
+
* use output guardrails for raw text validation instead. */
|
|
323
|
+
type OutputValidator<T = unknown> = (output: T, ctx: {
|
|
324
|
+
metadata: Record<string, unknown>;
|
|
325
|
+
}) => ValidateResult | Promise<ValidateResult>;
|
|
288
326
|
/** Execution info */
|
|
289
327
|
type ExecutionInfo = {
|
|
290
328
|
executionId: string;
|
|
@@ -1000,7 +1038,7 @@ declare class WorkflowContext<TInput = unknown> {
|
|
|
1000
1038
|
private numericVote;
|
|
1001
1039
|
private meanVote;
|
|
1002
1040
|
private medianVote;
|
|
1003
|
-
verify<T>(fn: (
|
|
1041
|
+
verify<T>(fn: (retry?: VerifyRetry<T>) => Promise<unknown>, schema: z.ZodType<T>, options?: VerifyOptions<T>): Promise<T>;
|
|
1004
1042
|
budget<T>(options: BudgetOptions, fn: () => Promise<T>): Promise<BudgetResult<T>>;
|
|
1005
1043
|
/** Get the current budget status, or null if not inside a budget block. */
|
|
1006
1044
|
getBudgetStatus(): {
|
|
@@ -1406,6 +1444,13 @@ declare class GuardrailError extends AxlError {
|
|
|
1406
1444
|
readonly reason: string;
|
|
1407
1445
|
constructor(guardrailType: 'input' | 'output', reason: string);
|
|
1408
1446
|
}
|
|
1447
|
+
/** Thrown when post-schema business rule validation fails after all retries exhausted */
|
|
1448
|
+
declare class ValidationError extends AxlError {
|
|
1449
|
+
readonly lastOutput: unknown;
|
|
1450
|
+
readonly reason: string;
|
|
1451
|
+
readonly retries: number;
|
|
1452
|
+
constructor(lastOutput: unknown, reason: string, retries: number);
|
|
1453
|
+
}
|
|
1409
1454
|
/** Internal: thrown when an agent tries to call a tool not in its ACL */
|
|
1410
1455
|
declare class ToolDenied extends AxlError {
|
|
1411
1456
|
readonly toolName: string;
|
|
@@ -1798,4 +1843,4 @@ declare class NoopSpanManager implements SpanManager {
|
|
|
1798
1843
|
*/
|
|
1799
1844
|
declare function createSpanManager(config?: TelemetryConfig): Promise<SpanManager>;
|
|
1800
1845
|
|
|
1801
|
-
export { type Agent, type AgentCallInfo, type AgentConfig, AnthropicProvider, type AskOptions, type AwaitHumanOptions, type AxlConfig, AxlError, AxlRuntime, AxlStream, BudgetExceededError, type BudgetOptions, type BudgetResult, type ChatMessage, type ChatOptions, type DelegateOptions, type Effort, type Embedder, type ExecutionInfo, type ExecutionState, GeminiProvider, type GuardrailBlockHandler, GuardrailError, type GuardrailResult, type GuardrailsConfig, type HandoffDescriptor, type HandoffRecord, type HumanDecision, InMemoryVectorStore, type InputGuardrail, type MapOptions, MaxTurnsError, McpManager, type McpServer, type McpServerConfig, type McpToolDefinition, type McpToolResult, type MemoryConfig, MemoryManager, MemoryStore, NoConsensus, NoopSpanManager, OpenAIEmbedder, OpenAIProvider, OpenAIResponsesProvider, type OutputGuardrail, type PendingDecision, type Provider, type ProviderAdapter, ProviderRegistry, type ProviderResponse, QuorumNotMet, type RaceOptions, type RecallOptions, RedisStore, type RememberOptions, type ResolvedThinkingOptions, type Result, type RetryPolicy, SQLiteStore, Session, type SessionOptions, type SpanHandle, type SpanManager, type SpawnOptions, SqliteVectorStore, type StateStore, type StreamChunk, type StreamEvent, type TelemetryConfig, TimeoutError, type Tool, type ToolCallMessage, type ToolChoice, type ToolConfig, ToolDenied, type ToolHooks, type TraceEvent, type VectorEntry, type VectorResult, type VectorStore, VerifyError, type VerifyOptions, type VoteOptions, type Workflow, type WorkflowConfig, WorkflowContext, type WorkflowContextInit, agent, createSpanManager, defineConfig, resolveThinkingOptions, tool, workflow, zodToJsonSchema };
|
|
1846
|
+
export { type Agent, type AgentCallInfo, type AgentConfig, AnthropicProvider, type AskOptions, type AwaitHumanOptions, type AxlConfig, AxlError, AxlRuntime, AxlStream, BudgetExceededError, type BudgetOptions, type BudgetResult, type ChatMessage, type ChatOptions, type DelegateOptions, type Effort, type Embedder, type ExecutionInfo, type ExecutionState, GeminiProvider, type GuardrailBlockHandler, GuardrailError, type GuardrailResult, type GuardrailsConfig, type HandoffDescriptor, type HandoffRecord, type HumanDecision, InMemoryVectorStore, type InputGuardrail, type MapOptions, MaxTurnsError, McpManager, type McpServer, type McpServerConfig, type McpToolDefinition, type McpToolResult, type MemoryConfig, MemoryManager, MemoryStore, NoConsensus, NoopSpanManager, OpenAIEmbedder, OpenAIProvider, OpenAIResponsesProvider, type OutputGuardrail, type OutputValidator, type PendingDecision, type Provider, type ProviderAdapter, ProviderRegistry, type ProviderResponse, QuorumNotMet, type RaceOptions, type RecallOptions, RedisStore, type RememberOptions, type ResolvedThinkingOptions, type Result, type RetryPolicy, SQLiteStore, Session, type SessionOptions, type SpanHandle, type SpanManager, type SpawnOptions, SqliteVectorStore, type StateStore, type StreamChunk, type StreamEvent, type TelemetryConfig, TimeoutError, type Tool, type ToolCallMessage, type ToolChoice, type ToolConfig, ToolDenied, type ToolHooks, type TraceEvent, type ValidateResult, ValidationError, type VectorEntry, type VectorResult, type VectorStore, VerifyError, type VerifyOptions, type VerifyRetry, type VoteOptions, type Workflow, type WorkflowConfig, WorkflowContext, type WorkflowContextInit, agent, createSpanManager, defineConfig, resolveThinkingOptions, tool, workflow, zodToJsonSchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -108,6 +108,8 @@ type StreamChunk = {
|
|
|
108
108
|
reasoning_tokens?: number;
|
|
109
109
|
cached_tokens?: number;
|
|
110
110
|
};
|
|
111
|
+
/** Estimated cost in USD for this call, computed the same way as ProviderResponse.cost. */
|
|
112
|
+
cost?: number;
|
|
111
113
|
/** Provider-specific opaque metadata (e.g. raw Gemini parts with thought signatures). */
|
|
112
114
|
providerMetadata?: Record<string, unknown>;
|
|
113
115
|
};
|
|
@@ -194,10 +196,22 @@ type VoteOptions<T> = {
|
|
|
194
196
|
scorer?: (value: T) => number | Promise<number>;
|
|
195
197
|
reducer?: (values: T[]) => T | Promise<T>;
|
|
196
198
|
};
|
|
199
|
+
/** Context passed to the verify function on retry (undefined on first call). */
|
|
200
|
+
type VerifyRetry<T> = {
|
|
201
|
+
/** Error message from the failed attempt (schema or validate). */
|
|
202
|
+
error: string;
|
|
203
|
+
/** Raw return value from the previous fn call. */
|
|
204
|
+
output: unknown;
|
|
205
|
+
/** Schema-parsed object — only present when schema passed but validate failed.
|
|
206
|
+
* Safe to modify and return as the next attempt. */
|
|
207
|
+
parsed?: T;
|
|
208
|
+
};
|
|
197
209
|
/** Verify options */
|
|
198
210
|
type VerifyOptions<T> = {
|
|
199
211
|
retries?: number;
|
|
200
212
|
fallback?: T;
|
|
213
|
+
/** Post-schema business rule validation on the parsed object. */
|
|
214
|
+
validate?: OutputValidator<T>;
|
|
201
215
|
};
|
|
202
216
|
/** AwaitHuman options */
|
|
203
217
|
type AwaitHumanOptions = {
|
|
@@ -209,6 +223,12 @@ type AwaitHumanOptions = {
|
|
|
209
223
|
type AskOptions<T = unknown> = {
|
|
210
224
|
schema?: z.ZodType<T>;
|
|
211
225
|
retries?: number;
|
|
226
|
+
/** Post-schema business rule validation. Receives the parsed typed object after schema
|
|
227
|
+
* validation succeeds. Only runs when `schema` is set. Retries with accumulating context
|
|
228
|
+
* on failure (LLM sees all previous failed attempts). Throws `ValidationError` on exhaustion. */
|
|
229
|
+
validate?: OutputValidator<T>;
|
|
230
|
+
/** Maximum retries for validate failures (default: 2). */
|
|
231
|
+
validateRetries?: number;
|
|
212
232
|
/** Per-call metadata passed to dynamic model/system selector functions. */
|
|
213
233
|
metadata?: Record<string, unknown>;
|
|
214
234
|
/** Override temperature for this call. */
|
|
@@ -238,11 +258,17 @@ type DelegateOptions<T = unknown> = {
|
|
|
238
258
|
metadata?: Record<string, unknown>;
|
|
239
259
|
/** Number of retries for structured output validation (passed to the final ask). */
|
|
240
260
|
retries?: number;
|
|
261
|
+
/** Post-schema business rule validation. Passed through to the final `ctx.ask()` call. */
|
|
262
|
+
validate?: OutputValidator<T>;
|
|
263
|
+
/** Maximum retries for validate failures (default: 2). Passed through to the final `ctx.ask()` call. */
|
|
264
|
+
validateRetries?: number;
|
|
241
265
|
};
|
|
242
266
|
/** Race options */
|
|
243
267
|
type RaceOptions<T = unknown> = {
|
|
244
268
|
/** Schema to validate each result. Invalid results are discarded and the race continues. */
|
|
245
269
|
schema?: z.ZodType<T>;
|
|
270
|
+
/** Post-schema business rule validation. Results that fail are discarded (same as schema failures). */
|
|
271
|
+
validate?: OutputValidator<T>;
|
|
246
272
|
};
|
|
247
273
|
/** Execution status */
|
|
248
274
|
type ExecutionStatus = 'running' | 'completed' | 'failed' | 'waiting';
|
|
@@ -250,7 +276,7 @@ type ExecutionStatus = 'running' | 'completed' | 'failed' | 'waiting';
|
|
|
250
276
|
type TraceEvent = {
|
|
251
277
|
executionId: string;
|
|
252
278
|
step: number;
|
|
253
|
-
type: 'agent_call' | 'tool_call' | 'verify' | 'handoff' | 'delegate' | 'tool_denied' | 'log' | 'workflow_start' | 'workflow_end' | 'guardrail';
|
|
279
|
+
type: 'agent_call' | 'tool_call' | 'verify' | 'handoff' | 'delegate' | 'tool_denied' | 'log' | 'workflow_start' | 'workflow_end' | 'guardrail' | 'validate';
|
|
254
280
|
workflow?: string;
|
|
255
281
|
agent?: string;
|
|
256
282
|
tool?: string;
|
|
@@ -285,6 +311,18 @@ type GuardrailsConfig = {
|
|
|
285
311
|
onBlock?: GuardrailBlockHandler;
|
|
286
312
|
maxRetries?: number;
|
|
287
313
|
};
|
|
314
|
+
/** Result of a validate check (post-schema business rule validation).
|
|
315
|
+
* Note: uses `valid: true` = pass, unlike `GuardrailResult` which uses `block: true` = fail. */
|
|
316
|
+
type ValidateResult = {
|
|
317
|
+
valid: boolean;
|
|
318
|
+
reason?: string;
|
|
319
|
+
};
|
|
320
|
+
/** Output validator function. Runs after schema parsing on the typed object.
|
|
321
|
+
* Only invoked when a schema is provided on the `ctx.ask()` call — without a schema,
|
|
322
|
+
* use output guardrails for raw text validation instead. */
|
|
323
|
+
type OutputValidator<T = unknown> = (output: T, ctx: {
|
|
324
|
+
metadata: Record<string, unknown>;
|
|
325
|
+
}) => ValidateResult | Promise<ValidateResult>;
|
|
288
326
|
/** Execution info */
|
|
289
327
|
type ExecutionInfo = {
|
|
290
328
|
executionId: string;
|
|
@@ -1000,7 +1038,7 @@ declare class WorkflowContext<TInput = unknown> {
|
|
|
1000
1038
|
private numericVote;
|
|
1001
1039
|
private meanVote;
|
|
1002
1040
|
private medianVote;
|
|
1003
|
-
verify<T>(fn: (
|
|
1041
|
+
verify<T>(fn: (retry?: VerifyRetry<T>) => Promise<unknown>, schema: z.ZodType<T>, options?: VerifyOptions<T>): Promise<T>;
|
|
1004
1042
|
budget<T>(options: BudgetOptions, fn: () => Promise<T>): Promise<BudgetResult<T>>;
|
|
1005
1043
|
/** Get the current budget status, or null if not inside a budget block. */
|
|
1006
1044
|
getBudgetStatus(): {
|
|
@@ -1406,6 +1444,13 @@ declare class GuardrailError extends AxlError {
|
|
|
1406
1444
|
readonly reason: string;
|
|
1407
1445
|
constructor(guardrailType: 'input' | 'output', reason: string);
|
|
1408
1446
|
}
|
|
1447
|
+
/** Thrown when post-schema business rule validation fails after all retries exhausted */
|
|
1448
|
+
declare class ValidationError extends AxlError {
|
|
1449
|
+
readonly lastOutput: unknown;
|
|
1450
|
+
readonly reason: string;
|
|
1451
|
+
readonly retries: number;
|
|
1452
|
+
constructor(lastOutput: unknown, reason: string, retries: number);
|
|
1453
|
+
}
|
|
1409
1454
|
/** Internal: thrown when an agent tries to call a tool not in its ACL */
|
|
1410
1455
|
declare class ToolDenied extends AxlError {
|
|
1411
1456
|
readonly toolName: string;
|
|
@@ -1798,4 +1843,4 @@ declare class NoopSpanManager implements SpanManager {
|
|
|
1798
1843
|
*/
|
|
1799
1844
|
declare function createSpanManager(config?: TelemetryConfig): Promise<SpanManager>;
|
|
1800
1845
|
|
|
1801
|
-
export { type Agent, type AgentCallInfo, type AgentConfig, AnthropicProvider, type AskOptions, type AwaitHumanOptions, type AxlConfig, AxlError, AxlRuntime, AxlStream, BudgetExceededError, type BudgetOptions, type BudgetResult, type ChatMessage, type ChatOptions, type DelegateOptions, type Effort, type Embedder, type ExecutionInfo, type ExecutionState, GeminiProvider, type GuardrailBlockHandler, GuardrailError, type GuardrailResult, type GuardrailsConfig, type HandoffDescriptor, type HandoffRecord, type HumanDecision, InMemoryVectorStore, type InputGuardrail, type MapOptions, MaxTurnsError, McpManager, type McpServer, type McpServerConfig, type McpToolDefinition, type McpToolResult, type MemoryConfig, MemoryManager, MemoryStore, NoConsensus, NoopSpanManager, OpenAIEmbedder, OpenAIProvider, OpenAIResponsesProvider, type OutputGuardrail, type PendingDecision, type Provider, type ProviderAdapter, ProviderRegistry, type ProviderResponse, QuorumNotMet, type RaceOptions, type RecallOptions, RedisStore, type RememberOptions, type ResolvedThinkingOptions, type Result, type RetryPolicy, SQLiteStore, Session, type SessionOptions, type SpanHandle, type SpanManager, type SpawnOptions, SqliteVectorStore, type StateStore, type StreamChunk, type StreamEvent, type TelemetryConfig, TimeoutError, type Tool, type ToolCallMessage, type ToolChoice, type ToolConfig, ToolDenied, type ToolHooks, type TraceEvent, type VectorEntry, type VectorResult, type VectorStore, VerifyError, type VerifyOptions, type VoteOptions, type Workflow, type WorkflowConfig, WorkflowContext, type WorkflowContextInit, agent, createSpanManager, defineConfig, resolveThinkingOptions, tool, workflow, zodToJsonSchema };
|
|
1846
|
+
export { type Agent, type AgentCallInfo, type AgentConfig, AnthropicProvider, type AskOptions, type AwaitHumanOptions, type AxlConfig, AxlError, AxlRuntime, AxlStream, BudgetExceededError, type BudgetOptions, type BudgetResult, type ChatMessage, type ChatOptions, type DelegateOptions, type Effort, type Embedder, type ExecutionInfo, type ExecutionState, GeminiProvider, type GuardrailBlockHandler, GuardrailError, type GuardrailResult, type GuardrailsConfig, type HandoffDescriptor, type HandoffRecord, type HumanDecision, InMemoryVectorStore, type InputGuardrail, type MapOptions, MaxTurnsError, McpManager, type McpServer, type McpServerConfig, type McpToolDefinition, type McpToolResult, type MemoryConfig, MemoryManager, MemoryStore, NoConsensus, NoopSpanManager, OpenAIEmbedder, OpenAIProvider, OpenAIResponsesProvider, type OutputGuardrail, type OutputValidator, type PendingDecision, type Provider, type ProviderAdapter, ProviderRegistry, type ProviderResponse, QuorumNotMet, type RaceOptions, type RecallOptions, RedisStore, type RememberOptions, type ResolvedThinkingOptions, type Result, type RetryPolicy, SQLiteStore, Session, type SessionOptions, type SpanHandle, type SpanManager, type SpawnOptions, SqliteVectorStore, type StateStore, type StreamChunk, type StreamEvent, type TelemetryConfig, TimeoutError, type Tool, type ToolCallMessage, type ToolChoice, type ToolConfig, ToolDenied, type ToolHooks, type TraceEvent, type ValidateResult, ValidationError, type VectorEntry, type VectorResult, type VectorStore, VerifyError, type VerifyOptions, type VerifyRetry, type VoteOptions, type Workflow, type WorkflowConfig, WorkflowContext, type WorkflowContextInit, agent, createSpanManager, defineConfig, resolveThinkingOptions, tool, workflow, zodToJsonSchema };
|