@ai.ntellect/core 0.3.3 → 0.4.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.
Files changed (85) hide show
  1. package/.nvmrc +1 -0
  2. package/README.FR.md +242 -247
  3. package/README.md +249 -246
  4. package/agent/index.ts +199 -215
  5. package/agent/tools/get-rss.ts +64 -0
  6. package/bull.ts +5 -0
  7. package/dist/agent/index.d.ts +29 -26
  8. package/dist/agent/index.js +123 -112
  9. package/dist/agent/tools/get-rss.d.ts +16 -0
  10. package/dist/agent/tools/get-rss.js +62 -0
  11. package/dist/bull.d.ts +1 -0
  12. package/dist/bull.js +9 -0
  13. package/dist/examples/index.d.ts +2 -0
  14. package/dist/examples/index.js +89 -0
  15. package/dist/llm/interpreter/context.d.ts +5 -22
  16. package/dist/llm/interpreter/context.js +8 -9
  17. package/dist/llm/interpreter/index.d.ts +9 -5
  18. package/dist/llm/interpreter/index.js +55 -48
  19. package/dist/llm/memory-manager/context.d.ts +2 -0
  20. package/dist/llm/memory-manager/context.js +22 -0
  21. package/dist/llm/memory-manager/index.d.ts +17 -0
  22. package/dist/llm/memory-manager/index.js +107 -0
  23. package/dist/llm/orchestrator/context.d.ts +2 -10
  24. package/dist/llm/orchestrator/context.js +19 -14
  25. package/dist/llm/orchestrator/index.d.ts +36 -21
  26. package/dist/llm/orchestrator/index.js +122 -88
  27. package/dist/llm/orchestrator/types.d.ts +12 -0
  28. package/dist/llm/orchestrator/types.js +2 -0
  29. package/dist/memory/cache.d.ts +6 -5
  30. package/dist/memory/cache.js +31 -21
  31. package/dist/memory/persistent.d.ts +5 -3
  32. package/dist/memory/persistent.js +89 -73
  33. package/dist/services/redis-cache.d.ts +37 -0
  34. package/dist/services/redis-cache.js +93 -0
  35. package/dist/services/scheduler.d.ts +39 -16
  36. package/dist/services/scheduler.js +81 -103
  37. package/dist/services/telegram-monitor.d.ts +0 -15
  38. package/dist/services/telegram-monitor.js +117 -101
  39. package/dist/test.js +106 -172
  40. package/dist/types.d.ts +38 -7
  41. package/dist/utils/generate-object.d.ts +12 -0
  42. package/dist/utils/generate-object.js +90 -0
  43. package/dist/utils/header-builder.d.ts +11 -0
  44. package/dist/utils/header-builder.js +34 -0
  45. package/dist/utils/inject-actions.js +2 -2
  46. package/dist/utils/queue-item-transformer.d.ts +2 -2
  47. package/dist/utils/schema-generator.d.ts +16 -0
  48. package/dist/utils/schema-generator.js +46 -0
  49. package/examples/index.ts +103 -0
  50. package/llm/interpreter/context.ts +20 -8
  51. package/llm/interpreter/index.ts +81 -54
  52. package/llm/memory-manager/context.ts +21 -0
  53. package/llm/memory-manager/index.ts +163 -0
  54. package/llm/orchestrator/context.ts +20 -13
  55. package/llm/orchestrator/index.ts +210 -130
  56. package/llm/orchestrator/types.ts +14 -0
  57. package/memory/cache.ts +37 -31
  58. package/memory/persistent.ts +121 -99
  59. package/package.json +11 -2
  60. package/services/redis-cache.ts +128 -0
  61. package/services/scheduler.ts +102 -141
  62. package/services/telegram-monitor.ts +138 -138
  63. package/t.py +79 -0
  64. package/t.spec +38 -0
  65. package/types.ts +40 -7
  66. package/utils/generate-object.ts +105 -0
  67. package/utils/header-builder.ts +40 -0
  68. package/utils/inject-actions.ts +4 -6
  69. package/utils/queue-item-transformer.ts +2 -1
  70. package/utils/schema-generator.ts +73 -0
  71. package/agent/handlers/ActionHandler.ts +0 -48
  72. package/agent/handlers/ConfirmationHandler.ts +0 -37
  73. package/agent/handlers/EventHandler.ts +0 -35
  74. package/dist/agent/handlers/ActionHandler.d.ts +0 -8
  75. package/dist/agent/handlers/ActionHandler.js +0 -36
  76. package/dist/agent/handlers/ConfirmationHandler.d.ts +0 -7
  77. package/dist/agent/handlers/ConfirmationHandler.js +0 -31
  78. package/dist/agent/handlers/EventHandler.d.ts +0 -10
  79. package/dist/agent/handlers/EventHandler.js +0 -34
  80. package/dist/llm/evaluator/context.d.ts +0 -10
  81. package/dist/llm/evaluator/context.js +0 -24
  82. package/dist/llm/evaluator/index.d.ts +0 -16
  83. package/dist/llm/evaluator/index.js +0 -150
  84. package/llm/evaluator/context.ts +0 -21
  85. package/llm/evaluator/index.ts +0 -193
package/dist/test.js CHANGED
@@ -1,21 +1,11 @@
1
1
  "use strict";
2
2
  // import ccxt from "ccxt";
3
+ // import { configDotenv } from "dotenv";
3
4
  // import { parseEther } from "ethers";
4
5
  // import Parser from "rss-parser";
5
6
  // import { z } from "zod";
6
- // import { Agent } from "./agent";
7
- // import { Interpreter } from "./llm/interpreter";
8
- // import {
9
- // generalInterpreterContext,
10
- // marketInterpreterContext,
11
- // securityInterpreterContext,
12
- // } from "./llm/interpreter/context";
13
- // import { Orchestrator } from "./llm/orchestrator";
14
- // import { CacheMemory } from "./memory/cache";
15
- // import { PersistentMemory } from "./memory/persistent";
16
- // import { ActionQueueManager } from "./services/queue";
17
- // import { ActionScheduler } from "./services/scheduler";
18
- // import { ScheduledAction } from "./types";
7
+ // // import { Orchestrator } from "./llm/orchestrator";
8
+ // configDotenv();
19
9
  // interface HoneypotParams {
20
10
  // address: string;
21
11
  // chainName?: string;
@@ -329,100 +319,44 @@
329
319
  // }
330
320
  // },
331
321
  // };
332
- // const RSS_FEEDS = [
333
- // "https://www.investing.com/rss/news_301.rss",
334
- // "https://cointelegraph.com/rss/category/analysis",
335
- // "https://cointelegraph.com/rss/category/top-10-cryptocurrencies",
336
- // ];
337
- // const parser = new Parser();
338
- // function stripHtmlTags(content: string): string {
339
- // if (!content) return "";
340
- // return content
341
- // .replace(/<[^>]*>/g, "")
342
- // .replace(/\n/g, "")
343
- // .replace(" ", "");
344
- // }
345
- // export const getRssNews = {
346
- // name: "get-news-rss",
347
- // description: "Get latest news about on website",
348
- // parameters: z.object({}),
349
- // execute: async () => {
350
- // const itemsPerSource = 5;
351
- // try {
352
- // const feedPromises = RSS_FEEDS.map((url) => parser.parseURL(url));
353
- // const results = await Promise.allSettled(feedPromises);
354
- // const successfulFeeds = results
355
- // .filter(
356
- // (result): result is PromiseFulfilledResult<Parser.Output<any>> => {
357
- // return (
358
- // result.status === "fulfilled" && result.value?.items?.length > 0
359
- // );
360
- // }
361
- // )
362
- // .map((result) => result.value);
363
- // const allItems = successfulFeeds
364
- // .flatMap((feed) => feed.items.slice(0, itemsPerSource))
365
- // .sort((a, b) => {
366
- // const dateA = a.pubDate ? new Date(a.pubDate).getTime() : 0;
367
- // const dateB = b.pubDate ? new Date(b.pubDate).getTime() : 0;
368
- // return dateB - dateA;
369
- // })
370
- // .slice(0, 5)
371
- // .map((item) => ({
372
- // title: item.title,
373
- // content: stripHtmlTags(item.content),
374
- // link: item.link,
375
- // date: item.pubDate,
376
- // source: item.creator || new URL(item.link).hostname,
377
- // }));
378
- // const result = {
379
- // status: "success",
380
- // items: allItems,
381
- // };
382
- // return result;
383
- // } catch (error: any) {
384
- // throw error;
385
- // }
386
- // },
387
- // };
388
322
  // (async () => {
389
- // const cacheMemory = new CacheMemory();
390
- // const memory = new PersistentMemory({
391
- // host: "http://localhost:7700",
392
- // apiKey: "aSampleMasterKey",
393
- // });
394
- // const orchestrator = new Orchestrator({
395
- // id: "1",
396
- // tools: [
397
- // prepareEvmTransaction,
398
- // checkHoneypot,
399
- // getChainsTVL,
400
- // getRssNews,
401
- // {
402
- // name: "hello",
403
- // description: "hello",
404
- // parameters: z.object({
405
- // name: z.string(),
406
- // }),
407
- // execute: async () => {
408
- // console.log("hello");
409
- // },
410
- // },
411
- // ],
412
- // memory: {
413
- // persistent: memory,
414
- // cache: cacheMemory,
415
- // },
416
- // });
417
- // const securityInterpreter = new Interpreter(
418
- // "security",
419
- // securityInterpreterContext
420
- // );
421
- // const marketInterpreter = new Interpreter("market", marketInterpreterContext);
422
- // const generalInterpreter = new Interpreter(
423
- // "general",
424
- // generalInterpreterContext
425
- // );
323
+ // // const cacheMemory = new CacheMemory();
324
+ // // const memory = new PersistentMemory({
325
+ // // host: "http://localhost:7700",
326
+ // // apiKey: "aSampleMasterKey",
327
+ // // });
328
+ // // const orchestrator = new Orchestrator({
329
+ // // id: "1",
330
+ // // tools: [
331
+ // // prepareEvmTransaction,
332
+ // // checkHoneypot,
333
+ // // getChainsTVL,
334
+ // // getRssNews,
335
+ // // {
336
+ // // name: "hello",
337
+ // // description: "hello",
338
+ // // parameters: z.object({
339
+ // // name: z.string(),
340
+ // // }),
341
+ // // execute: async () => {
342
+ // // console.log("hello");
343
+ // // },
344
+ // // },
345
+ // // ],
346
+ // // memory: {
347
+ // // persistent: memory,
348
+ // // cache: cacheMemory,
349
+ // // },
350
+ // // });
351
+ // // const securityInterpreter = new Interpreter(
352
+ // // "security",
353
+ // // securityInterpreterContext
354
+ // // );
355
+ // // const marketInterpreter = new Interpreter("market", marketInterpreterContext);
356
+ // // const generalInterpreter = new Interpreter(
357
+ // // "general",
358
+ // // generalInterpreterContext
359
+ // // );
426
360
  // // const ccacheMemory = await cacheMemory.findSimilarActions(
427
361
  // // "le top 3 des chaines par TVL en DeFi",
428
362
  // // {
@@ -433,72 +367,72 @@
433
367
  // // }
434
368
  // // );
435
369
  // // console.log("✅ RECENT_ACTIONS: ", ccacheMemory);
436
- // const agent = new Agent({
437
- // interpreters: [securityInterpreter, marketInterpreter, generalInterpreter],
438
- // orchestrator,
439
- // memory: {
440
- // persistent: memory,
441
- // cache: cacheMemory,
442
- // },
443
- // stream: false,
444
- // maxEvaluatorIteration: 1,
445
- // });
446
- // const prompt = "tu pourrais analyser le bnb/usdt";
370
+ // // const agent = new Agent({
371
+ // // interpreters: [securityInterpreter, marketInterpreter, generalInterpreter],
372
+ // // orchestrator,
373
+ // // memory: {
374
+ // // persistent: memory,
375
+ // // cache: cacheMemory,
376
+ // // },
377
+ // // stream: false,
378
+ // // maxEvaluatorIteration: 1,
379
+ // // });
380
+ // // const prompt = "c quoi les news";
447
381
  // // const result = await agent.process(prompt, {});
448
- // const scheduler = new ActionScheduler(
449
- // new ActionQueueManager(orchestrator.tools),
450
- // orchestrator,
451
- // {
452
- // onActionScheduled: (action: ScheduledAction) => {
453
- // console.log("🗓️ Action programmée:", {
454
- // id: action.id,
455
- // name: action.action.name,
456
- // scheduledTime: action.scheduledTime,
457
- // });
458
- // },
459
- // onActionStart: (action: ScheduledAction) => {
460
- // console.log("▶️ Action démarrée:", action.id);
461
- // },
462
- // onActionComplete: (action: ScheduledAction, result: any) => {
463
- // console.log("✅ Action terminée:", {
464
- // id: action.id,
465
- // result,
466
- // });
467
- // },
468
- // onActionFailed: (action: ScheduledAction, error: any) => {
469
- // console.error("❌ Action échouée:", {
470
- // id: action.id,
471
- // error: error.message,
472
- // });
473
- // },
474
- // onActionCancelled: (actionId: string) => {
475
- // console.log("🚫 Action annulée:", actionId);
476
- // },
477
- // }
478
- // );
382
+ // // const scheduler = new ActionScheduler(
383
+ // // new ActionQueueManager(orchestrator.tools),
384
+ // // orchestrator,
385
+ // // {
386
+ // // onActionScheduled: (action: ScheduledAction) => {
387
+ // // console.log("🗓️ Action programmée:", {
388
+ // // id: action.id,
389
+ // // name: action.action.name,
390
+ // // scheduledTime: action.scheduledTime,
391
+ // // });
392
+ // // },
393
+ // // onActionStart: (action: ScheduledAction) => {
394
+ // // console.log("▶️ Action démarrée:", action.id);
395
+ // // },
396
+ // // onActionComplete: (action: ScheduledAction, result: any) => {
397
+ // // console.log("✅ Action terminée:", {
398
+ // // id: action.id,
399
+ // // result,
400
+ // // });
401
+ // // },
402
+ // // onActionFailed: (action: ScheduledAction, error: any) => {
403
+ // // console.error("❌ Action échouée:", {
404
+ // // id: action.id,
405
+ // // error: error.message,
406
+ // // });
407
+ // // },
408
+ // // onActionCancelled: (actionId: string) => {
409
+ // // console.log("🚫 Action annulée:", actionId);
410
+ // // },
411
+ // // }
412
+ // // );
479
413
  // // Test du scheduler
480
- // console.log("🕒 Testing scheduler...");
481
- // const scheduledTime = new Date(Date.now() + 10000);
482
- // const actionId = await scheduler.scheduleAction(
483
- // {
484
- // name: "hello",
485
- // description: "hello",
486
- // parameters: z.object({
487
- // name: z.string(),
488
- // }),
489
- // execute: async () => {
490
- // console.log("hello");
491
- // return "Hello executed!";
492
- // },
493
- // },
494
- // scheduledTime,
495
- // "user123",
496
- // {
497
- // type: "daily",
498
- // interval: 1,
499
- // }
500
- // );
501
- // // Attendre 15 secondes
502
- // await new Promise((resolve) => setTimeout(resolve, 15000));
503
- // console.log("✅ Test terminé");
414
+ // // console.log("🕒 Testing scheduler...");
415
+ // // const scheduledTime = new Date(Date.now() + 10000);
416
+ // // const actionId = await scheduler.scheduleAction(
417
+ // // {
418
+ // // name: "hello",
419
+ // // description: "hello",
420
+ // // parameters: z.object({
421
+ // // name: z.string(),
422
+ // // }),
423
+ // // execute: async () => {
424
+ // // console.log("hello");
425
+ // // return "Hello executed!";
426
+ // // },
427
+ // // },
428
+ // // scheduledTime,
429
+ // // "user123",
430
+ // // {
431
+ // // type: "daily",
432
+ // // interval: 1,
433
+ // // }
434
+ // // );
435
+ // // // Attendre 15 secondes
436
+ // // await new Promise((resolve) => setTimeout(resolve, 15000));
437
+ // // console.log("✅ Test terminé");
504
438
  // })();
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Embedding, StreamTextResult } from "ai";
1
+ import { Embedding, EmbeddingModel, StreamTextResult } from "ai";
2
2
  import { z } from "zod";
3
3
  export interface BaseLLM {
4
4
  process: (prompt: string) => Promise<string | object>;
@@ -118,20 +118,41 @@ export interface SummarizerAgent {
118
118
  streamProcess: (results: object, onFinish?: (event: any) => void) => Promise<StreamTextResult<Record<string, any>>>;
119
119
  }
120
120
  export interface CacheMemoryOptions {
121
+ embeddingModel: EmbeddingModel<string>;
121
122
  cacheTTL?: number;
122
123
  redisUrl?: string;
123
124
  cachePrefix?: string;
124
125
  }
126
+ export type GenerateObjectResponse = {
127
+ shouldContinue: boolean;
128
+ actions: Array<{
129
+ name: string;
130
+ parameters: Array<{
131
+ name: string;
132
+ value: any;
133
+ }>;
134
+ scheduler?: {
135
+ isScheduled: boolean;
136
+ cronExpression: string;
137
+ reason?: string;
138
+ };
139
+ }>;
140
+ socialResponse?: {
141
+ shouldRespond: boolean;
142
+ response?: string;
143
+ isPartialResponse?: boolean;
144
+ };
145
+ interpreter?: string;
146
+ };
125
147
  export interface CreateMemoryInput {
126
- content: any;
127
- type: MemoryType;
128
- data: string[];
148
+ query: string;
149
+ data: any;
129
150
  userId?: string;
130
151
  scope?: MemoryScope;
152
+ ttl?: number;
131
153
  }
132
154
  export interface CacheMemoryType {
133
155
  id: string;
134
- type: MemoryType;
135
156
  data: any;
136
157
  query: string;
137
158
  embedding: Embedding;
@@ -149,14 +170,15 @@ export interface MemoryChunk {
149
170
  embedding: number[];
150
171
  }
151
172
  export type MemoryScopeType = (typeof MemoryScope)[keyof typeof MemoryScope];
152
- export interface Memory {
173
+ export interface LongTermMemory {
153
174
  id: string;
154
175
  query: string;
155
- purpose: string;
176
+ category: string;
156
177
  data: any;
157
178
  roomId: string;
158
179
  createdAt: Date;
159
180
  chunks?: MemoryChunk[];
181
+ tags: string[];
160
182
  }
161
183
  export declare const ActionSchema: z.ZodArray<z.ZodObject<{
162
184
  name: z.ZodString;
@@ -225,3 +247,12 @@ export interface ScheduledActionEvents {
225
247
  onActionScheduled?: (action: ScheduledAction) => void;
226
248
  onActionCancelled?: (actionId: string) => void;
227
249
  }
250
+ export interface WorkflowPattern {
251
+ query: string;
252
+ actions: Array<{
253
+ done: boolean;
254
+ name: string;
255
+ result: string;
256
+ }>;
257
+ success: boolean;
258
+ }
@@ -0,0 +1,12 @@
1
+ import { LanguageModelV1 } from "ai";
2
+ import { z } from "zod";
3
+ export declare const describeZodSchema: (schema: z.ZodType) => string;
4
+ export declare const generateObject: <T>(config: {
5
+ model: LanguageModelV1;
6
+ schema: z.ZodSchema;
7
+ prompt: string;
8
+ system: string;
9
+ temperature: number;
10
+ }) => Promise<{
11
+ object: T;
12
+ }>;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateObject = exports.describeZodSchema = void 0;
4
+ const ai_1 = require("ai");
5
+ const zod_1 = require("zod");
6
+ const describeZodSchema = (schema) => {
7
+ if (schema instanceof zod_1.z.ZodObject) {
8
+ const entries = Object.entries(schema.shape);
9
+ const fields = entries.map(([key, value]) => {
10
+ const description = value._def.description || "";
11
+ const fieldSchema = (0, exports.describeZodSchema)(value);
12
+ return description
13
+ ? `${key}: ${fieldSchema} // ${description}`
14
+ : `${key}: ${fieldSchema}`;
15
+ });
16
+ return `z.object({${fields.join(", ")}})`;
17
+ }
18
+ if (schema instanceof zod_1.z.ZodArray) {
19
+ return `z.array(${(0, exports.describeZodSchema)(schema.element)})`;
20
+ }
21
+ if (schema instanceof zod_1.z.ZodString) {
22
+ return "z.string()";
23
+ }
24
+ if (schema instanceof zod_1.z.ZodNumber) {
25
+ return "z.number()";
26
+ }
27
+ if (schema instanceof zod_1.z.ZodBoolean) {
28
+ return "z.boolean()";
29
+ }
30
+ if (schema instanceof zod_1.z.ZodOptional) {
31
+ return `z.optional(${(0, exports.describeZodSchema)(schema._def.innerType)})`;
32
+ }
33
+ if (schema instanceof zod_1.z.ZodUnion) {
34
+ return `z.union([${schema._def.options
35
+ .map((option) => (0, exports.describeZodSchema)(option))
36
+ .join(", ")}])`;
37
+ }
38
+ if (schema instanceof zod_1.z.ZodEnum) {
39
+ return `z.enum(${JSON.stringify(schema._def.values)})`;
40
+ }
41
+ if (schema instanceof zod_1.z.ZodLiteral) {
42
+ return `z.literal(${JSON.stringify(schema._def.value)})`;
43
+ }
44
+ return "z.unknown()"; // Fallback for unknown types
45
+ };
46
+ exports.describeZodSchema = describeZodSchema;
47
+ const generateObject = async (config) => {
48
+ // Generate a detailed description of the schema
49
+ const schemaDescription = (0, exports.describeZodSchema)(config.schema);
50
+ console.log("🔍 Schema Description:\n", schemaDescription);
51
+ const response = await (0, ai_1.generateText)({
52
+ model: config.model,
53
+ prompt: `${config.prompt}
54
+
55
+ EXPECTED SCHEMA:
56
+ ${schemaDescription}
57
+
58
+ BAD EXAMPLE:
59
+ \`\`\`json
60
+ {
61
+ "key": "value"
62
+ }
63
+ \`\`\`
64
+
65
+ GOOD EXAMPLE:
66
+ {
67
+ "key": "value"
68
+ }
69
+
70
+ Output only the JSON schema, no 'triple quotes'json or any other text. Only the JSON schema.
71
+ `,
72
+ system: config.system,
73
+ temperature: config.temperature,
74
+ });
75
+ try {
76
+ // Clean the response text from any markdown or code block markers
77
+ const cleanText = response.text
78
+ .replace(/```json\s*/g, "")
79
+ .replace(/```\s*$/g, "")
80
+ .trim();
81
+ const parsedResponse = JSON.parse(cleanText);
82
+ const validatedResponse = config.schema.parse(parsedResponse);
83
+ return { object: validatedResponse };
84
+ }
85
+ catch (error) {
86
+ console.error("Error parsing or validating JSON response:", error);
87
+ throw new Error("Failed to generate valid JSON response");
88
+ }
89
+ };
90
+ exports.generateObject = generateObject;
@@ -0,0 +1,11 @@
1
+ type HeaderValue = string | string[] | undefined;
2
+ export declare class LLMHeaderBuilder {
3
+ private headers;
4
+ private _result;
5
+ constructor();
6
+ addHeader(key: string, value: HeaderValue): LLMHeaderBuilder;
7
+ valueOf(): string;
8
+ toString(): string;
9
+ static create(): LLMHeaderBuilder;
10
+ }
11
+ export {};
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LLMHeaderBuilder = void 0;
4
+ class LLMHeaderBuilder {
5
+ constructor() {
6
+ this.headers = new Map();
7
+ this._result = "";
8
+ }
9
+ addHeader(key, value) {
10
+ if (Array.isArray(value)) {
11
+ this.headers.set(key, value.join("\n"));
12
+ }
13
+ else {
14
+ this.headers.set(key, value);
15
+ }
16
+ // Build result immediately
17
+ this._result = Array.from(this.headers.entries())
18
+ .filter(([_, value]) => value !== undefined)
19
+ .map(([key, value]) => `# ${key}: ${value}`)
20
+ .join("\n")
21
+ .trim();
22
+ return this;
23
+ }
24
+ valueOf() {
25
+ return this._result;
26
+ }
27
+ toString() {
28
+ return this._result;
29
+ }
30
+ static create() {
31
+ return new LLMHeaderBuilder();
32
+ }
33
+ }
34
+ exports.LLMHeaderBuilder = LLMHeaderBuilder;
@@ -5,8 +5,8 @@ const injectActions = (actions) => {
5
5
  return actions.map((action) => {
6
6
  const parameters = action.parameters;
7
7
  const schemaShape = Object.keys(parameters._def.shape()).join(", ");
8
- const actionString = `Name: ${action.name}, Description: ${action.description}, Arguments (STRICTLY REQUIRED): { ${schemaShape} } ${action.examples
9
- ? `Format examples (MUST RESPECT): ${action.examples.map((example) => {
8
+ const actionString = `Name: ${action.name}, Description: ${action.description}, Arguments: { ${schemaShape} } ${action.examples
9
+ ? `Format examples: ${action.examples.map((example) => {
10
10
  return JSON.stringify(example);
11
11
  })}`
12
12
  : ""}`;
@@ -1,7 +1,7 @@
1
- import { ActionData, QueueResult, TransformedQueueItem } from "../types";
1
+ import { ActionData, QueueItem, QueueResult, TransformedQueueItem } from "../types";
2
2
  export declare class QueueItemTransformer {
3
3
  static transformActionToQueueItem(action: ActionData): TransformedQueueItem;
4
4
  static transformFromSimilarActions(similarActions: QueueResult[]): TransformedQueueItem[] | undefined;
5
5
  private static transformParameters;
6
- static transformActionsToQueueItems(actions: ActionData[] | undefined): TransformedQueueItem[] | undefined;
6
+ static transformActionsToQueueItems(actions: ActionData[] | undefined): QueueItem[] | undefined;
7
7
  }
@@ -0,0 +1,16 @@
1
+ import { z } from "zod";
2
+ export interface SchemaConfig {
3
+ schema: z.ZodType;
4
+ instructions?: string;
5
+ outputExamples?: {
6
+ input: string;
7
+ output: string;
8
+ }[];
9
+ }
10
+ export declare class SchemaGenerator {
11
+ static generate(config: SchemaConfig): {
12
+ schema: string;
13
+ instructions: string;
14
+ outputExamples: string;
15
+ };
16
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SchemaGenerator = void 0;
4
+ const zod_1 = require("zod");
5
+ class SchemaGenerator {
6
+ static generate(config) {
7
+ const { schema, instructions = "Output only the JSON schema, no 'triple quotes'json or any other text. Only the JSON schema.", outputExamples = [], } = config;
8
+ const getSchemaString = (schema) => {
9
+ if (schema instanceof zod_1.z.ZodObject) {
10
+ const entries = Object.entries(schema.shape);
11
+ const fields = entries.map(([key, value]) => {
12
+ const description = value._def.description;
13
+ const schemaStr = getSchemaString(value);
14
+ return description
15
+ ? `${key}: ${schemaStr} // ${description}`
16
+ : `${key}: ${schemaStr}`;
17
+ });
18
+ return `z.object({${fields.join(", ")}})`;
19
+ }
20
+ if (schema instanceof zod_1.z.ZodArray) {
21
+ return `z.array(${getSchemaString(schema.element)})`;
22
+ }
23
+ if (schema instanceof zod_1.z.ZodString) {
24
+ return "z.string()";
25
+ }
26
+ if (schema instanceof zod_1.z.ZodNumber) {
27
+ return "z.number()";
28
+ }
29
+ if (schema instanceof zod_1.z.ZodBoolean) {
30
+ return "z.boolean()";
31
+ }
32
+ // Fallback for other Zod types
33
+ return `z.unknown()`;
34
+ };
35
+ const schemaString = getSchemaString(schema);
36
+ return {
37
+ schema: schemaString,
38
+ instructions,
39
+ outputExamples: outputExamples
40
+ .map((example) => `Input: ${JSON.stringify(example.input)}, Output: ${JSON.stringify(example.output)}`)
41
+ .join("\n")
42
+ .trim(),
43
+ };
44
+ }
45
+ }
46
+ exports.SchemaGenerator = SchemaGenerator;