@ton-agent-kit/core 1.0.1 → 1.0.2

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/agent.ts +3 -38
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ton-agent-kit/core",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Core SDK for TON Agent Kit — plugin system, wallet abstraction, agent class",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
package/src/agent.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { readFileSync } from "fs";
2
+ import { toJSONSchema } from "zod";
2
3
  import { TonClient4 } from "@ton/ton";
3
4
  import { PluginRegistry } from "./plugin";
4
5
  import type {
@@ -208,42 +209,7 @@ export class TonAgentKit {
208
209
  */
209
210
  toAITools(): Array<{ type: "function"; function: { name: string; description: string; parameters: any } }> {
210
211
  return this.getAvailableActions().map((action) => {
211
- let parameters: any = { type: "object", properties: {} };
212
-
213
- // Try Zod v4 native toJSONSchema first
214
- try {
215
- const { toJSONSchema } = require("zod");
216
- const schema = toJSONSchema(action.schema);
217
- const { $schema, ...rest } = schema;
218
- parameters = { type: "object", properties: {}, ...rest };
219
- } catch {
220
- // Fallback: extract property names from Zod schema shape
221
- try {
222
- const shape = (action.schema as any)?._def?.shape || (action.schema as any)?.shape;
223
- if (shape && typeof shape === "object") {
224
- const props: Record<string, any> = {};
225
- for (const [key, val] of Object.entries(shape)) {
226
- const def = (val as any)?._def || (val as any)?.def || {};
227
- const zodType = def.type || def.typeName || "string";
228
- let jsonType = "string";
229
- if (zodType === "number" || zodType === "ZodNumber" || zodType === "float64") jsonType = "number";
230
- if (zodType === "boolean" || zodType === "ZodBoolean") jsonType = "boolean";
231
-
232
- const isOptional = zodType === "optional" || zodType === "ZodOptional" || def.type === "optional";
233
- const innerDef = isOptional ? (def.innerType?.def || def.innerType?._def || {}) : def;
234
- const innerType = innerDef.type || innerDef.typeName || "string";
235
- let finalType = "string";
236
- if (innerType === "number" || innerType === "ZodNumber" || innerType === "float64") finalType = "number";
237
- if (innerType === "boolean" || innerType === "ZodBoolean") finalType = "boolean";
238
-
239
- const description = (val as any)?._def?.description || (val as any)?.description || "";
240
- props[key] = { type: finalType, ...(description ? { description } : {}) };
241
- }
242
- parameters = { type: "object", properties: props };
243
- }
244
- } catch {}
245
- }
246
-
212
+ const { $schema, ...parameters } = toJSONSchema(action.schema);
247
213
  return {
248
214
  type: "function" as const,
249
215
  function: {
@@ -275,9 +241,8 @@ export class TonAgentKit {
275
241
  );
276
242
  }
277
243
 
278
- // Dynamic imports so the SDK works without these deps installed
244
+ // Dynamic import so the SDK works without openai installed
279
245
  const { default: OpenAI } = await import("openai");
280
- const { toJSONSchema } = await import("zod");
281
246
  const client = new OpenAI({ apiKey, baseURL });
282
247
 
283
248
  // Ensure plugins are initialized