@axlsdk/axl 0.8.0 → 0.9.1
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 +3 -1
- package/dist/index.cjs +12 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -10
- package/dist/index.d.ts +14 -10
- package/dist/index.js +13 -44
- package/dist/index.js.map +1 -1
- package/package.json +3 -4
package/dist/index.d.cts
CHANGED
|
@@ -200,10 +200,12 @@ type VoteOptions<T> = {
|
|
|
200
200
|
type VerifyRetry<T> = {
|
|
201
201
|
/** Error message from the failed attempt (schema or validate). */
|
|
202
202
|
error: string;
|
|
203
|
-
/** Raw return value from the previous fn call.
|
|
203
|
+
/** Raw return value from the previous fn call. When fn() throws a ValidationError
|
|
204
|
+
* or VerifyError, falls back to err.lastOutput so the retry has data to repair. */
|
|
204
205
|
output: unknown;
|
|
205
206
|
/** Schema-parsed object — only present when schema passed but validate failed.
|
|
206
|
-
*
|
|
207
|
+
* Also populated from ValidationError.lastOutput when fn() throws (e.g., inner
|
|
208
|
+
* ctx.ask() exhausted its validate retries). Safe to modify and return. */
|
|
207
209
|
parsed?: T;
|
|
208
210
|
};
|
|
209
211
|
/** Verify options */
|
|
@@ -912,8 +914,10 @@ declare class MemoryManager {
|
|
|
912
914
|
close(): Promise<void>;
|
|
913
915
|
}
|
|
914
916
|
|
|
915
|
-
/** Convert a Zod schema to JSON Schema
|
|
916
|
-
|
|
917
|
+
/** Convert a Zod schema to JSON Schema. Exported for Studio tool introspection.
|
|
918
|
+
* Wraps Zod v4's built-in `z.toJSONSchema()`, stripping the `$schema` key
|
|
919
|
+
* since tool parameter schemas are embedded objects, not standalone documents. */
|
|
920
|
+
declare function zodToJsonSchema(schema: z.ZodType): Record<string, unknown>;
|
|
917
921
|
type WorkflowContextInit = {
|
|
918
922
|
input: unknown;
|
|
919
923
|
executionId: string;
|
|
@@ -1100,7 +1104,7 @@ type ToolHooks<TInput = unknown, TOutput = unknown> = {
|
|
|
1100
1104
|
after?(output: TOutput, ctx: WorkflowContext): TOutput | Promise<TOutput>;
|
|
1101
1105
|
};
|
|
1102
1106
|
/** Tool configuration */
|
|
1103
|
-
type ToolConfig<TInput extends z.
|
|
1107
|
+
type ToolConfig<TInput extends z.ZodType, TOutput = unknown> = {
|
|
1104
1108
|
name: string;
|
|
1105
1109
|
description: string;
|
|
1106
1110
|
input: TInput;
|
|
@@ -1115,7 +1119,7 @@ type ToolConfig<TInput extends z.ZodTypeAny, TOutput = unknown> = {
|
|
|
1115
1119
|
hooks?: ToolHooks<z.infer<TInput>, TOutput>;
|
|
1116
1120
|
};
|
|
1117
1121
|
/** A defined tool instance */
|
|
1118
|
-
type Tool<TInput extends z.
|
|
1122
|
+
type Tool<TInput extends z.ZodType = z.ZodType, TOutput = unknown> = {
|
|
1119
1123
|
readonly name: string;
|
|
1120
1124
|
readonly description: string;
|
|
1121
1125
|
readonly inputSchema: TInput;
|
|
@@ -1133,17 +1137,17 @@ type Tool<TInput extends z.ZodTypeAny = z.ZodTypeAny, TOutput = unknown> = {
|
|
|
1133
1137
|
* @param config - Tool configuration: name, description, input schema, handler, retry, and sensitivity options.
|
|
1134
1138
|
* @returns A Tool instance that can be attached to agents and invoked via `tool.run()` or agent tool calling.
|
|
1135
1139
|
*/
|
|
1136
|
-
declare function tool<TInput extends z.
|
|
1140
|
+
declare function tool<TInput extends z.ZodType, TOutput = unknown>(config: ToolConfig<TInput, TOutput>): Tool<TInput, TOutput>;
|
|
1137
1141
|
|
|
1138
1142
|
/** Workflow configuration */
|
|
1139
|
-
type WorkflowConfig<TInput extends z.
|
|
1143
|
+
type WorkflowConfig<TInput extends z.ZodType = z.ZodType, TOutput extends z.ZodType = z.ZodType> = {
|
|
1140
1144
|
name: string;
|
|
1141
1145
|
input: TInput;
|
|
1142
1146
|
output?: TOutput;
|
|
1143
1147
|
handler: (ctx: WorkflowContext<z.infer<TInput>>) => Promise<z.infer<TOutput>>;
|
|
1144
1148
|
};
|
|
1145
1149
|
/** A defined workflow instance */
|
|
1146
|
-
type Workflow<TInput extends z.
|
|
1150
|
+
type Workflow<TInput extends z.ZodType = z.ZodType, TOutput extends z.ZodType = z.ZodType> = {
|
|
1147
1151
|
readonly name: string;
|
|
1148
1152
|
readonly inputSchema: TInput;
|
|
1149
1153
|
readonly outputSchema: TOutput | undefined;
|
|
@@ -1155,7 +1159,7 @@ type Workflow<TInput extends z.ZodTypeAny = z.ZodTypeAny, TOutput extends z.ZodT
|
|
|
1155
1159
|
* @param config - Workflow configuration: name, input schema, optional output schema, and async handler receiving a WorkflowContext.
|
|
1156
1160
|
* @returns A Workflow instance ready to be registered with an AxlRuntime.
|
|
1157
1161
|
*/
|
|
1158
|
-
declare function workflow<TInput extends z.
|
|
1162
|
+
declare function workflow<TInput extends z.ZodType, TOutput extends z.ZodType = z.ZodType>(config: WorkflowConfig<TInput, TOutput>): Workflow<TInput, TOutput>;
|
|
1159
1163
|
|
|
1160
1164
|
/**
|
|
1161
1165
|
* A streamable workflow execution.
|
package/dist/index.d.ts
CHANGED
|
@@ -200,10 +200,12 @@ type VoteOptions<T> = {
|
|
|
200
200
|
type VerifyRetry<T> = {
|
|
201
201
|
/** Error message from the failed attempt (schema or validate). */
|
|
202
202
|
error: string;
|
|
203
|
-
/** Raw return value from the previous fn call.
|
|
203
|
+
/** Raw return value from the previous fn call. When fn() throws a ValidationError
|
|
204
|
+
* or VerifyError, falls back to err.lastOutput so the retry has data to repair. */
|
|
204
205
|
output: unknown;
|
|
205
206
|
/** Schema-parsed object — only present when schema passed but validate failed.
|
|
206
|
-
*
|
|
207
|
+
* Also populated from ValidationError.lastOutput when fn() throws (e.g., inner
|
|
208
|
+
* ctx.ask() exhausted its validate retries). Safe to modify and return. */
|
|
207
209
|
parsed?: T;
|
|
208
210
|
};
|
|
209
211
|
/** Verify options */
|
|
@@ -912,8 +914,10 @@ declare class MemoryManager {
|
|
|
912
914
|
close(): Promise<void>;
|
|
913
915
|
}
|
|
914
916
|
|
|
915
|
-
/** Convert a Zod schema to JSON Schema
|
|
916
|
-
|
|
917
|
+
/** Convert a Zod schema to JSON Schema. Exported for Studio tool introspection.
|
|
918
|
+
* Wraps Zod v4's built-in `z.toJSONSchema()`, stripping the `$schema` key
|
|
919
|
+
* since tool parameter schemas are embedded objects, not standalone documents. */
|
|
920
|
+
declare function zodToJsonSchema(schema: z.ZodType): Record<string, unknown>;
|
|
917
921
|
type WorkflowContextInit = {
|
|
918
922
|
input: unknown;
|
|
919
923
|
executionId: string;
|
|
@@ -1100,7 +1104,7 @@ type ToolHooks<TInput = unknown, TOutput = unknown> = {
|
|
|
1100
1104
|
after?(output: TOutput, ctx: WorkflowContext): TOutput | Promise<TOutput>;
|
|
1101
1105
|
};
|
|
1102
1106
|
/** Tool configuration */
|
|
1103
|
-
type ToolConfig<TInput extends z.
|
|
1107
|
+
type ToolConfig<TInput extends z.ZodType, TOutput = unknown> = {
|
|
1104
1108
|
name: string;
|
|
1105
1109
|
description: string;
|
|
1106
1110
|
input: TInput;
|
|
@@ -1115,7 +1119,7 @@ type ToolConfig<TInput extends z.ZodTypeAny, TOutput = unknown> = {
|
|
|
1115
1119
|
hooks?: ToolHooks<z.infer<TInput>, TOutput>;
|
|
1116
1120
|
};
|
|
1117
1121
|
/** A defined tool instance */
|
|
1118
|
-
type Tool<TInput extends z.
|
|
1122
|
+
type Tool<TInput extends z.ZodType = z.ZodType, TOutput = unknown> = {
|
|
1119
1123
|
readonly name: string;
|
|
1120
1124
|
readonly description: string;
|
|
1121
1125
|
readonly inputSchema: TInput;
|
|
@@ -1133,17 +1137,17 @@ type Tool<TInput extends z.ZodTypeAny = z.ZodTypeAny, TOutput = unknown> = {
|
|
|
1133
1137
|
* @param config - Tool configuration: name, description, input schema, handler, retry, and sensitivity options.
|
|
1134
1138
|
* @returns A Tool instance that can be attached to agents and invoked via `tool.run()` or agent tool calling.
|
|
1135
1139
|
*/
|
|
1136
|
-
declare function tool<TInput extends z.
|
|
1140
|
+
declare function tool<TInput extends z.ZodType, TOutput = unknown>(config: ToolConfig<TInput, TOutput>): Tool<TInput, TOutput>;
|
|
1137
1141
|
|
|
1138
1142
|
/** Workflow configuration */
|
|
1139
|
-
type WorkflowConfig<TInput extends z.
|
|
1143
|
+
type WorkflowConfig<TInput extends z.ZodType = z.ZodType, TOutput extends z.ZodType = z.ZodType> = {
|
|
1140
1144
|
name: string;
|
|
1141
1145
|
input: TInput;
|
|
1142
1146
|
output?: TOutput;
|
|
1143
1147
|
handler: (ctx: WorkflowContext<z.infer<TInput>>) => Promise<z.infer<TOutput>>;
|
|
1144
1148
|
};
|
|
1145
1149
|
/** A defined workflow instance */
|
|
1146
|
-
type Workflow<TInput extends z.
|
|
1150
|
+
type Workflow<TInput extends z.ZodType = z.ZodType, TOutput extends z.ZodType = z.ZodType> = {
|
|
1147
1151
|
readonly name: string;
|
|
1148
1152
|
readonly inputSchema: TInput;
|
|
1149
1153
|
readonly outputSchema: TOutput | undefined;
|
|
@@ -1155,7 +1159,7 @@ type Workflow<TInput extends z.ZodTypeAny = z.ZodTypeAny, TOutput extends z.ZodT
|
|
|
1155
1159
|
* @param config - Workflow configuration: name, input schema, optional output schema, and async handler receiving a WorkflowContext.
|
|
1156
1160
|
* @returns A Workflow instance ready to be registered with an AxlRuntime.
|
|
1157
1161
|
*/
|
|
1158
|
-
declare function workflow<TInput extends z.
|
|
1162
|
+
declare function workflow<TInput extends z.ZodType, TOutput extends z.ZodType = z.ZodType>(config: WorkflowConfig<TInput, TOutput>): Workflow<TInput, TOutput>;
|
|
1159
1163
|
|
|
1160
1164
|
/**
|
|
1161
1165
|
* A streamable workflow execution.
|
package/dist/index.js
CHANGED
|
@@ -1922,7 +1922,7 @@ var defaultRegistry = new ProviderRegistry();
|
|
|
1922
1922
|
|
|
1923
1923
|
// src/context.ts
|
|
1924
1924
|
import { AsyncLocalStorage } from "async_hooks";
|
|
1925
|
-
import { ZodError } from "zod";
|
|
1925
|
+
import { z, ZodError } from "zod";
|
|
1926
1926
|
|
|
1927
1927
|
// src/errors.ts
|
|
1928
1928
|
var AxlError = class extends Error {
|
|
@@ -2102,48 +2102,9 @@ function resolveConfig(config) {
|
|
|
2102
2102
|
// src/context.ts
|
|
2103
2103
|
var signalStorage = new AsyncLocalStorage();
|
|
2104
2104
|
function zodToJsonSchema(schema) {
|
|
2105
|
-
const
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
case "ZodString":
|
|
2109
|
-
return { type: "string" };
|
|
2110
|
-
case "ZodNumber":
|
|
2111
|
-
return { type: "number" };
|
|
2112
|
-
case "ZodBoolean":
|
|
2113
|
-
return { type: "boolean" };
|
|
2114
|
-
case "ZodArray":
|
|
2115
|
-
return { type: "array", items: zodToJsonSchema(def.type) };
|
|
2116
|
-
case "ZodObject": {
|
|
2117
|
-
const shape = def.shape?.() ?? {};
|
|
2118
|
-
const properties = {};
|
|
2119
|
-
const required = [];
|
|
2120
|
-
for (const [key, value] of Object.entries(shape)) {
|
|
2121
|
-
properties[key] = zodToJsonSchema(value);
|
|
2122
|
-
const innerDef = value._def;
|
|
2123
|
-
if (innerDef?.typeName !== "ZodOptional" && innerDef?.typeName !== "ZodDefault") {
|
|
2124
|
-
required.push(key);
|
|
2125
|
-
}
|
|
2126
|
-
}
|
|
2127
|
-
return { type: "object", properties, required: required.length > 0 ? required : void 0 };
|
|
2128
|
-
}
|
|
2129
|
-
case "ZodOptional":
|
|
2130
|
-
return zodToJsonSchema(def.innerType);
|
|
2131
|
-
case "ZodDefault":
|
|
2132
|
-
return zodToJsonSchema(def.innerType);
|
|
2133
|
-
case "ZodEnum":
|
|
2134
|
-
return { type: "string", enum: def.values };
|
|
2135
|
-
case "ZodLiteral": {
|
|
2136
|
-
const v = def.value;
|
|
2137
|
-
const t = v === null ? "null" : typeof v;
|
|
2138
|
-
return { type: t, const: v };
|
|
2139
|
-
}
|
|
2140
|
-
case "ZodUnion":
|
|
2141
|
-
return { oneOf: def.options.map((o) => zodToJsonSchema(o)) };
|
|
2142
|
-
case "ZodNullable":
|
|
2143
|
-
return { ...zodToJsonSchema(def.innerType), nullable: true };
|
|
2144
|
-
default:
|
|
2145
|
-
return {};
|
|
2146
|
-
}
|
|
2105
|
+
const result = z.toJSONSchema(schema, { unrepresentable: "any" });
|
|
2106
|
+
delete result.$schema;
|
|
2107
|
+
return result;
|
|
2147
2108
|
}
|
|
2148
2109
|
function estimateTokens(text) {
|
|
2149
2110
|
return Math.ceil(text.length / 4);
|
|
@@ -3384,7 +3345,7 @@ ${summaryResponse.content}`
|
|
|
3384
3345
|
if (err instanceof ValidationError) {
|
|
3385
3346
|
lastRetry = {
|
|
3386
3347
|
error: err.reason,
|
|
3387
|
-
output: rawOutput,
|
|
3348
|
+
output: rawOutput ?? err.lastOutput,
|
|
3388
3349
|
parsed: err.lastOutput
|
|
3389
3350
|
};
|
|
3390
3351
|
if (attempt === maxRetries) {
|
|
@@ -3393,6 +3354,14 @@ ${summaryResponse.content}`
|
|
|
3393
3354
|
}
|
|
3394
3355
|
continue;
|
|
3395
3356
|
}
|
|
3357
|
+
if (err instanceof VerifyError) {
|
|
3358
|
+
lastRetry = { error: err.message, output: rawOutput ?? err.lastOutput };
|
|
3359
|
+
if (attempt === maxRetries) {
|
|
3360
|
+
if (options?.fallback !== void 0) return options.fallback;
|
|
3361
|
+
throw err;
|
|
3362
|
+
}
|
|
3363
|
+
continue;
|
|
3364
|
+
}
|
|
3396
3365
|
const errorMsg = err instanceof ZodError ? err.message : err instanceof Error ? err.message : String(err);
|
|
3397
3366
|
lastRetry = { error: errorMsg, output: rawOutput };
|
|
3398
3367
|
if (attempt === maxRetries) {
|