@cuylabs/agent-core 0.2.0 → 0.3.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.
@@ -206,6 +206,32 @@ interface ToolMetadata {
206
206
  * Following OpenCode's Tool.define pattern for consistent tool creation.
207
207
  */
208
208
 
209
+ /**
210
+ * A schema type compatible with both Zod 3 and Zod 4.
211
+ *
212
+ * Uses structural typing so that schemas from either Zod version satisfy
213
+ * the constraint. This avoids the problem where Zod 3's `ZodType` class
214
+ * and Zod 4's `ZodType` class have incompatible internal shapes, causing
215
+ * type errors when a library compiled against one version is consumed with
216
+ * the other.
217
+ *
218
+ * Both Zod 3 and Zod 4 (classic API) schemas have `parse()` and `_output`.
219
+ */
220
+ interface CompatibleSchema<T = any> {
221
+ /** Parse and validate input data. Present in both Zod 3 and Zod 4. */
222
+ parse(data: unknown): T;
223
+ /**
224
+ * Type-level output marker used by both Zod versions:
225
+ * - Zod 3: `readonly _output!: T` (definite assignment assertion)
226
+ * - Zod 4 classic: `get _output(): T` (getter)
227
+ */
228
+ readonly _output: T;
229
+ }
230
+ /**
231
+ * Infer the output type from a compatible schema.
232
+ * Equivalent to `z.infer<T>` but works with both Zod 3 and Zod 4 schemas.
233
+ */
234
+ type InferSchemaOutput<T extends CompatibleSchema> = T["_output"];
209
235
  /**
210
236
  * Tool namespace - OpenCode-style tool definition
211
237
  */
@@ -213,7 +239,7 @@ declare namespace Tool {
213
239
  /**
214
240
  * Tool info interface - the shape of a defined tool
215
241
  */
216
- interface Info<TParams extends z.ZodType = z.ZodType, TMeta extends ToolMetadata = ToolMetadata> {
242
+ interface Info<TParams extends CompatibleSchema = any, TMeta extends ToolMetadata = ToolMetadata> {
217
243
  /** Unique tool identifier */
218
244
  id: string;
219
245
  /** Initialize the tool (can be async for dynamic descriptions) */
@@ -235,13 +261,13 @@ declare namespace Tool {
235
261
  /**
236
262
  * Result of tool initialization
237
263
  */
238
- interface InitResult<TParams extends z.ZodType = z.ZodType, TMeta extends ToolMetadata = ToolMetadata> {
264
+ interface InitResult<TParams extends CompatibleSchema = any, TMeta extends ToolMetadata = ToolMetadata> {
239
265
  /** Tool description for the LLM */
240
266
  description: string;
241
267
  /** Zod schema for parameters */
242
268
  parameters: TParams;
243
269
  /** Execute the tool */
244
- execute: (params: z.infer<TParams>, ctx: ToolContext) => Promise<ExecuteResult<TMeta>>;
270
+ execute: (params: InferSchemaOutput<TParams>, ctx: ToolContext) => Promise<ExecuteResult<TMeta>>;
245
271
  /** Optional custom validation error formatter */
246
272
  formatValidationError?: (error: z.ZodError) => string;
247
273
  /**
@@ -289,14 +315,14 @@ declare namespace Tool {
289
315
  * });
290
316
  * ```
291
317
  */
292
- function define<TParams extends z.ZodType, TMeta extends ToolMetadata = ToolMetadata>(id: string, init: Info<TParams, TMeta>["init"] | Awaited<ReturnType<Info<TParams, TMeta>["init"]>>): Info<TParams, TMeta>;
318
+ function define<TParams extends CompatibleSchema, TMeta extends ToolMetadata = ToolMetadata>(id: string, init: Info<TParams, TMeta>["init"] | Awaited<ReturnType<Info<TParams, TMeta>["init"]>>): Info<TParams, TMeta>;
293
319
  /**
294
320
  * Simple define for static tools (no async init)
295
321
  */
296
- function defineSimple<TParams extends z.ZodType, TMeta extends ToolMetadata = ToolMetadata>(id: string, config: {
322
+ function defineSimple<TParams extends CompatibleSchema, TMeta extends ToolMetadata = ToolMetadata>(id: string, config: {
297
323
  description: string;
298
324
  parameters: TParams;
299
- execute: (params: z.infer<TParams>, ctx: ToolContext) => Promise<ExecuteResult<TMeta>>;
325
+ execute: (params: InferSchemaOutput<TParams>, ctx: ToolContext) => Promise<ExecuteResult<TMeta>>;
300
326
  }): Info<TParams, TMeta>;
301
327
  }
302
328
  /**
@@ -304,11 +330,11 @@ declare namespace Tool {
304
330
  *
305
331
  * @deprecated Use Tool.define instead
306
332
  */
307
- declare function defineTool<TParams extends z.ZodType>(definition: {
333
+ declare function defineTool<TParams extends CompatibleSchema>(definition: {
308
334
  id: string;
309
335
  description: string;
310
336
  parameters: TParams;
311
- execute: (params: z.infer<TParams>, ctx: ToolContext) => Promise<ToolResult>;
337
+ execute: (params: InferSchemaOutput<TParams>, ctx: ToolContext) => Promise<ToolResult>;
312
338
  }): Tool.Info<TParams>;
313
339
 
314
340
  /**
@@ -443,4 +469,4 @@ declare function truncateOutput(output: string, options?: {
443
469
  */
444
470
  declare function formatSize(bytes: number): string;
445
471
 
446
- export { type DirEntry as D, type ExecOptions as E, type FileOperationMeta as F, MAX_BYTES as M, type ToolHost as T, Tool as a, type TurnTrackerContext as b, type ExecResult as c, type FileStat as d, MAX_LINES as e, TRUNCATE_DIR as f, TRUNCATE_GLOB as g, type ToolContext as h, type ToolMetadata as i, ToolRegistry as j, type ToolResult as k, type ToolSpec as l, type TruncateResult as m, defaultRegistry as n, defineTool as o, formatSize as p, truncateOutput as t };
472
+ export { type CompatibleSchema as C, type DirEntry as D, type ExecOptions as E, type FileOperationMeta as F, type InferSchemaOutput as I, MAX_BYTES as M, type ToolHost as T, Tool as a, type TurnTrackerContext as b, type ExecResult as c, type FileStat as d, MAX_LINES as e, TRUNCATE_DIR as f, TRUNCATE_GLOB as g, type ToolContext as h, type ToolMetadata as i, ToolRegistry as j, type ToolResult as k, type ToolSpec as l, type TruncateResult as m, defaultRegistry as n, defineTool as o, formatSize as p, truncateOutput as t };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as ai from 'ai';
2
2
  import { LanguageModel, Tool, StreamTextResult, ToolSet, Output, ModelMessage } from 'ai';
3
- import { T as ToolHost, a as Tool$1, F as FileOperationMeta, b as TurnTrackerContext } from './index-eud06GDQ.js';
4
- export { D as DirEntry, E as ExecOptions, c as ExecResult, d as FileStat, M as MAX_BYTES, e as MAX_LINES, f as TRUNCATE_DIR, g as TRUNCATE_GLOB, h as ToolContext, i as ToolMetadata, j as ToolRegistry, k as ToolResult, l as ToolSpec, m as TruncateResult, n as defaultRegistry, o as defineTool, p as formatSize, t as truncateOutput } from './index-eud06GDQ.js';
3
+ import { T as ToolHost, a as Tool$1, F as FileOperationMeta, b as TurnTrackerContext } from './index-QR704uRr.js';
4
+ export { C as CompatibleSchema, D as DirEntry, E as ExecOptions, c as ExecResult, d as FileStat, I as InferSchemaOutput, M as MAX_BYTES, e as MAX_LINES, f as TRUNCATE_DIR, g as TRUNCATE_GLOB, h as ToolContext, i as ToolMetadata, j as ToolRegistry, k as ToolResult, l as ToolSpec, m as TruncateResult, n as defaultRegistry, o as defineTool, p as formatSize, t as truncateOutput } from './index-QR704uRr.js';
5
5
  import { ProviderOptions } from '@ai-sdk/provider-utils';
6
6
  import 'zod';
7
7
 
@@ -1,2 +1,2 @@
1
- export { M as MAX_BYTES, e as MAX_LINES, f as TRUNCATE_DIR, g as TRUNCATE_GLOB, a as Tool, j as ToolRegistry, l as ToolSpec, m as TruncateResult, n as defaultRegistry, o as defineTool, p as formatSize, t as truncateOutput } from '../index-eud06GDQ.js';
1
+ export { C as CompatibleSchema, I as InferSchemaOutput, M as MAX_BYTES, e as MAX_LINES, f as TRUNCATE_DIR, g as TRUNCATE_GLOB, a as Tool, j as ToolRegistry, l as ToolSpec, m as TruncateResult, n as defaultRegistry, o as defineTool, p as formatSize, t as truncateOutput } from '../index-QR704uRr.js';
2
2
  import 'zod';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuylabs/agent-core",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Embeddable AI agent infrastructure - streaming, sessions, resilience, capabilities",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -24,7 +24,7 @@
24
24
  "dependencies": {
25
25
  "@ai-sdk/provider": "^3.0.7",
26
26
  "ai": "^6.0.67",
27
- "zod": "^3.24.0"
27
+ "zod": "^3.25.76 || ^4.1.8"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "@ai-sdk/anthropic": "^3.0.0",