@ai.ntellect/core 0.5.0 → 0.6.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/.mocharc.json +1 -1
- package/README.md +311 -272
- package/create-llm-to-select-multiple-graph copy.ts +243 -0
- package/create-llm-to-select-multiple-graph.ts +148 -0
- package/dist/graph/controller.js +63 -0
- package/dist/graph/engine.js +563 -0
- package/dist/index.js +6 -6
- package/dist/memory/adapters/meilisearch/index.js +249 -0
- package/dist/memory/adapters/redis/index.js +96 -0
- package/dist/memory/index.js +9 -0
- package/dist/services/agenda.js +115 -0
- package/dist/services/embedding.js +40 -0
- package/dist/services/queue.js +99 -103
- package/dist/test/graph/controller.test.js +170 -0
- package/dist/test/graph/engine.test.js +465 -0
- package/dist/test/memory/adapters/meilisearch.test.js +250 -0
- package/dist/test/memory/adapters/redis.test.js +143 -0
- package/dist/test/memory/base.test.js +209 -0
- package/dist/test/services/agenda.test.js +230 -0
- package/dist/test/services/queue.test.js +258 -0
- package/dist/types/index.js +2 -0
- package/dist/utils/generate-object.js +32 -11
- package/dist/utils/inject-actions.js +2 -2
- package/dist/utils/queue-item-transformer.js +2 -2
- package/dist/utils/state-manager.js +20 -0
- package/graph/controller.ts +64 -0
- package/graph/engine.ts +790 -0
- package/index copy.ts +81 -0
- package/index.ts +7 -7
- package/interfaces/index.ts +119 -0
- package/memory/adapters/meilisearch/index.ts +286 -0
- package/memory/adapters/redis/index.ts +103 -0
- package/memory/index.ts +22 -0
- package/package.json +7 -2
- package/services/agenda.ts +48 -43
- package/services/embedding.ts +26 -0
- package/services/queue.ts +2 -29
- package/test/.env.test +4 -0
- package/test/graph/controller.test.ts +186 -0
- package/test/graph/engine.test.ts +546 -0
- package/test/memory/adapters/meilisearch.test.ts +297 -0
- package/test/memory/adapters/redis.test.ts +160 -0
- package/test/memory/base.test.ts +229 -0
- package/test/services/agenda.test.ts +280 -0
- package/test/services/queue.test.ts +286 -44
- package/tsconfig.json +10 -10
- package/types/index.ts +278 -0
- package/utils/queue-item-transformer.ts +8 -11
- package/utils/setup-graphs.ts +45 -0
- package/utils/stringifiy-zod-schema.ts +45 -0
- package/.nvmrc +0 -1
- package/README.FR.md +0 -916
- package/agent/index.ts +0 -151
- package/agent/workflow/conditions.ts +0 -16
- package/agent/workflow/handlers/interpreter.handler.ts +0 -48
- package/agent/workflow/handlers/memory.handler.ts +0 -106
- package/agent/workflow/handlers/orchestrator.handler.ts +0 -23
- package/agent/workflow/handlers/queue.handler.ts +0 -34
- package/agent/workflow/handlers/scheduler.handler.ts +0 -61
- package/agent/workflow/index.ts +0 -62
- package/dist/agent/index.d.ts +0 -38
- package/dist/agent/index.js +0 -143
- package/dist/agent/tools/get-rss.d.ts +0 -16
- package/dist/agent/tools/get-rss.js +0 -62
- package/dist/bull.d.ts +0 -1
- package/dist/bull.js +0 -9
- package/dist/examples/index.d.ts +0 -2
- package/dist/examples/index.js +0 -89
- package/dist/index.d.ts +0 -7
- package/dist/llm/interpreter/context.d.ts +0 -15
- package/dist/llm/interpreter/context.js +0 -89
- package/dist/llm/interpreter/index.d.ts +0 -21
- package/dist/llm/interpreter/index.js +0 -87
- package/dist/llm/memory-manager/context.d.ts +0 -2
- package/dist/llm/memory-manager/context.js +0 -22
- package/dist/llm/memory-manager/index.d.ts +0 -17
- package/dist/llm/memory-manager/index.js +0 -107
- package/dist/llm/orchestrator/context.d.ts +0 -2
- package/dist/llm/orchestrator/context.js +0 -23
- package/dist/llm/orchestrator/index.d.ts +0 -44
- package/dist/llm/orchestrator/index.js +0 -139
- package/dist/llm/orchestrator/types.d.ts +0 -12
- package/dist/memory/cache.d.ts +0 -22
- package/dist/memory/cache.js +0 -165
- package/dist/memory/persistent.d.ts +0 -57
- package/dist/memory/persistent.js +0 -189
- package/dist/services/queue.d.ts +0 -13
- package/dist/services/redis-cache.d.ts +0 -37
- package/dist/services/redis-cache.js +0 -93
- package/dist/services/scheduler.d.ts +0 -40
- package/dist/services/scheduler.js +0 -99
- package/dist/services/telegram-monitor.d.ts +0 -0
- package/dist/services/telegram-monitor.js +0 -118
- package/dist/t.d.ts +0 -46
- package/dist/t.js +0 -102
- package/dist/test.d.ts +0 -0
- package/dist/test.js +0 -438
- package/dist/types.d.ts +0 -258
- package/dist/types.js +0 -22
- package/dist/utils/generate-object.d.ts +0 -12
- package/dist/utils/header-builder.d.ts +0 -11
- package/dist/utils/inject-actions.d.ts +0 -2
- package/dist/utils/queue-item-transformer.d.ts +0 -7
- package/dist/utils/sanitize-results.d.ts +0 -17
- package/dist/utils/schema-generator.d.ts +0 -16
- package/examples/actions/get-rss.ts +0 -71
- package/examples/index.ts +0 -98
- package/index.html +0 -42
- package/llm/dynamic-condition/example.ts +0 -36
- package/llm/dynamic-condition/index.ts +0 -108
- package/llm/interpreter/context.ts +0 -94
- package/llm/interpreter/index.ts +0 -140
- package/llm/memory-manager/context.ts +0 -19
- package/llm/memory-manager/index.ts +0 -115
- package/llm/orchestrator/context.ts +0 -19
- package/llm/orchestrator/index.ts +0 -192
- package/llm/orchestrator/types.ts +0 -14
- package/memory/cache.ts +0 -221
- package/memory/persistent.ts +0 -265
- package/script.js +0 -167
- package/services/cache.ts +0 -298
- package/services/telegram-monitor.ts +0 -138
- package/services/workflow.ts +0 -491
- package/t.py +0 -79
- package/t.ts +0 -25
- package/test/llm/orchestrator.test.ts +0 -47
- package/test/llm/synthesizer.test.ts +0 -31
- package/types.ts +0 -367
- package/utils/schema-generator.ts +0 -73
- package/utils/state-manager.ts +0 -25
- /package/dist/{llm/orchestrator/types.js → interfaces/index.js} +0 -0
package/types/index.ts
ADDED
@@ -0,0 +1,278 @@
|
|
1
|
+
import { z } from "zod";
|
2
|
+
|
3
|
+
/* ======================== MEMORY ======================== */
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Represents the input structure for creating a memory entry.
|
7
|
+
* @typedef {Object} CreateMemoryInput
|
8
|
+
* @property {string} query - The query associated with the memory.
|
9
|
+
* @property {any} data - The data to be stored.
|
10
|
+
* @property {string} roomId - The room identifier.
|
11
|
+
* @property {number} [ttl] - Time-to-live in seconds (optional).
|
12
|
+
*/
|
13
|
+
export type CreateMemoryInput = {
|
14
|
+
query: string;
|
15
|
+
data: any;
|
16
|
+
roomId: string;
|
17
|
+
ttl?: number;
|
18
|
+
};
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Represents a stored memory entry.
|
22
|
+
* @typedef {Object} BaseMemoryType
|
23
|
+
* @property {string} id - Unique identifier of the memory entry.
|
24
|
+
* @property {string} data - Stored data as a string.
|
25
|
+
* @property {string} query - The associated query.
|
26
|
+
* @property {number[] | null} embedding - Vector representation of the data.
|
27
|
+
* @property {string} roomId - The associated room ID.
|
28
|
+
* @property {Date} createdAt - Creation date.
|
29
|
+
*/
|
30
|
+
export type BaseMemoryType = {
|
31
|
+
id: string;
|
32
|
+
data: string;
|
33
|
+
query: string;
|
34
|
+
embedding: number[] | null;
|
35
|
+
roomId: string;
|
36
|
+
createdAt: Date;
|
37
|
+
};
|
38
|
+
|
39
|
+
/* ======================== QUEUE ======================== */
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Represents a single parameter for a queued action.
|
43
|
+
* @typedef {Object} QueueItemParameter
|
44
|
+
* @property {string} name - Parameter name.
|
45
|
+
* @property {string} value - Parameter value.
|
46
|
+
*/
|
47
|
+
export type QueueItemParameter = {
|
48
|
+
name: string;
|
49
|
+
value: string;
|
50
|
+
};
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Represents an action in the queue.
|
54
|
+
* @typedef {Object} QueueItem
|
55
|
+
* @property {string} name - Name of the action.
|
56
|
+
* @property {QueueItemParameter[]} parameters - List of parameters.
|
57
|
+
*/
|
58
|
+
export type QueueItem = {
|
59
|
+
name: string;
|
60
|
+
parameters: QueueItemParameter[];
|
61
|
+
};
|
62
|
+
|
63
|
+
/**
|
64
|
+
* Represents the result of a processed queue action.
|
65
|
+
* @typedef {Object} QueueResult
|
66
|
+
* @property {string} name - Action name.
|
67
|
+
* @property {Record<string, string>} parameters - Executed parameters.
|
68
|
+
* @property {any} result - The execution result.
|
69
|
+
* @property {string | null} error - Error message if any.
|
70
|
+
* @property {boolean} [cancelled] - Indicates if the action was cancelled.
|
71
|
+
*/
|
72
|
+
export type QueueResult = {
|
73
|
+
name: string;
|
74
|
+
parameters: Record<string, string>;
|
75
|
+
result: any;
|
76
|
+
error: string | null;
|
77
|
+
cancelled?: boolean;
|
78
|
+
};
|
79
|
+
|
80
|
+
/**
|
81
|
+
* Defines callback functions for queue execution events.
|
82
|
+
* @typedef {Object} QueueCallbacks
|
83
|
+
* @property {(action: QueueItem) => void} [onActionStart] - Triggered when an action starts.
|
84
|
+
* @property {(result: QueueResult) => void} [onActionComplete] - Triggered when an action completes.
|
85
|
+
* @property {(results: QueueResult[]) => void} [onQueueComplete] - Triggered when the queue is fully processed.
|
86
|
+
* @property {(message: string) => Promise<boolean>} [onConfirmationRequired] - Triggered when confirmation is needed.
|
87
|
+
*/
|
88
|
+
export type QueueCallbacks = {
|
89
|
+
onActionStart?: (action: QueueItem) => void;
|
90
|
+
onActionComplete?: (result: QueueResult) => void;
|
91
|
+
onQueueComplete?: (results: QueueResult[]) => void;
|
92
|
+
onConfirmationRequired?: (message: string) => Promise<boolean>;
|
93
|
+
};
|
94
|
+
|
95
|
+
/* ======================== ACTION ======================== */
|
96
|
+
|
97
|
+
/**
|
98
|
+
* Represents an executable action schema.
|
99
|
+
* @typedef {Object} ActionSchema
|
100
|
+
* @property {string} name - Action name.
|
101
|
+
* @property {string} description - Action description.
|
102
|
+
* @property {z.ZodObject<Record<string, z.ZodType>>} parameters - Schema for input parameters.
|
103
|
+
* @property {(args: any) => Promise<any>} execute - Function to execute the action.
|
104
|
+
* @property {Object[]} [examples] - Example usages of the action.
|
105
|
+
* @property {Object} [confirmation] - Confirmation requirements.
|
106
|
+
* @property {boolean} confirmation.requireConfirmation - Whether confirmation is needed.
|
107
|
+
* @property {string} confirmation.message - The confirmation message.
|
108
|
+
*/
|
109
|
+
export type ActionSchema = {
|
110
|
+
name: string;
|
111
|
+
description: string;
|
112
|
+
parameters: z.ZodObject<{ [key: string]: z.ZodType }>;
|
113
|
+
execute: (args: any) => Promise<any>;
|
114
|
+
examples?: {
|
115
|
+
role: string;
|
116
|
+
content: string;
|
117
|
+
parameters?: Record<string, any>;
|
118
|
+
}[];
|
119
|
+
confirmation?: {
|
120
|
+
requireConfirmation: boolean;
|
121
|
+
message: string;
|
122
|
+
};
|
123
|
+
};
|
124
|
+
|
125
|
+
/* ======================== SCHEDULING ======================== */
|
126
|
+
|
127
|
+
/**
|
128
|
+
* Represents a scheduled action with optional recurrence.
|
129
|
+
* @typedef {Object} ScheduledAction
|
130
|
+
* @property {string} id - Unique identifier for the scheduled action.
|
131
|
+
* @property {Object} action - The action details.
|
132
|
+
* @property {string} action.name - The action name.
|
133
|
+
* @property {QueueItemParameter[]} action.parameters - Action parameters.
|
134
|
+
* @property {Date} scheduledTime - The scheduled execution time.
|
135
|
+
* @property {string} userId - Associated user identifier.
|
136
|
+
* @property {"pending" | "completed" | "failed"} status - The execution status.
|
137
|
+
* @property {Object} [recurrence] - Recurrence details (optional).
|
138
|
+
* @property {"daily" | "weekly" | "monthly"} recurrence.type - Recurrence type.
|
139
|
+
* @property {number} recurrence.interval - Recurrence interval.
|
140
|
+
*/
|
141
|
+
export type ScheduledAction = {
|
142
|
+
id: string;
|
143
|
+
action: {
|
144
|
+
name: string;
|
145
|
+
parameters: QueueItemParameter[];
|
146
|
+
};
|
147
|
+
scheduledTime: Date;
|
148
|
+
userId: string;
|
149
|
+
status: "pending" | "completed" | "failed";
|
150
|
+
recurrence?: {
|
151
|
+
type: "daily" | "weekly" | "monthly";
|
152
|
+
interval: number;
|
153
|
+
};
|
154
|
+
};
|
155
|
+
|
156
|
+
/**
|
157
|
+
* Represents a scheduled request.
|
158
|
+
* @typedef {Object} ScheduledRequest
|
159
|
+
* @property {string} id - Unique identifier for the scheduled request.
|
160
|
+
* @property {string} originalRequest - The original request string.
|
161
|
+
* @property {string} cronExpression - The cron expression for scheduling.
|
162
|
+
* @property {boolean} isRecurring - Whether the request is recurring.
|
163
|
+
* @property {Date} createdAt - The creation date.
|
164
|
+
*/
|
165
|
+
export type ScheduledRequest = {
|
166
|
+
id: string;
|
167
|
+
originalRequest: string;
|
168
|
+
cronExpression: string;
|
169
|
+
isRecurring: boolean;
|
170
|
+
createdAt: Date;
|
171
|
+
};
|
172
|
+
|
173
|
+
/* ======================== GRAPH ======================== */
|
174
|
+
|
175
|
+
/**
|
176
|
+
* Defines a graph definition.
|
177
|
+
* @typedef {Object} GraphDefinition
|
178
|
+
* @property {string} name - The graph name.
|
179
|
+
* @property {string} entryNode - The entry node name.
|
180
|
+
* @property {Record<string, Node<T>>} nodes - The nodes in the graph.
|
181
|
+
* @property {z.ZodSchema<T>} [schema] - Optional schema for input validation.
|
182
|
+
*/
|
183
|
+
export type GraphDefinition<T> = {
|
184
|
+
name: string;
|
185
|
+
entryNode: string;
|
186
|
+
nodes: Record<string, Node<T>>;
|
187
|
+
schema?: z.ZodSchema<T>;
|
188
|
+
};
|
189
|
+
|
190
|
+
/**
|
191
|
+
* Defines a shared state context for execution graphs.
|
192
|
+
* @typedef {Object} SharedState
|
193
|
+
* @property {Partial<T>} context - The execution context.
|
194
|
+
*/
|
195
|
+
export type SharedState<T> = T;
|
196
|
+
|
197
|
+
/**
|
198
|
+
* Defines a graph node within a graph execution structure.
|
199
|
+
* @typedef {Object} Node
|
200
|
+
* @property {string} name - The node name.
|
201
|
+
* @property {string} [description] - Optional description.
|
202
|
+
* @property {(params: P, state: SharedState<T>) => Promise<SharedState<T> | void>} execute - Execution function.
|
203
|
+
* @property {(state: SharedState<T>) => boolean} [condition] - Optional condition for execution.
|
204
|
+
* @property {NodeRelationship[]} [relationships] - Possible node transitions.
|
205
|
+
* @property {z.ZodSchema<P>} [schema] - Optional schema for input validation.
|
206
|
+
* @property {any} [state] - Internal node state.
|
207
|
+
* @property {string[]} [events] - Events triggered by the node.
|
208
|
+
*/
|
209
|
+
export type Node<T, P = any> = {
|
210
|
+
name: string;
|
211
|
+
description?: string;
|
212
|
+
execute: (params: P, state: SharedState<T>) => Promise<SharedState<T> | void>;
|
213
|
+
condition?: (state: SharedState<T>) => boolean;
|
214
|
+
relationships?: NodeRelationship[];
|
215
|
+
schema?: z.ZodSchema<P>;
|
216
|
+
state?: any;
|
217
|
+
events?: string[];
|
218
|
+
};
|
219
|
+
|
220
|
+
/**
|
221
|
+
* Defines a node relationship in an execution graph.
|
222
|
+
* @typedef {Object} NodeRelationship
|
223
|
+
* @property {string} name - Relationship name.
|
224
|
+
* @property {string} [description] - Optional description.
|
225
|
+
*/
|
226
|
+
export type NodeRelationship = {
|
227
|
+
name: string;
|
228
|
+
description?: string;
|
229
|
+
};
|
230
|
+
|
231
|
+
/* ======================== SEARCH ======================== */
|
232
|
+
|
233
|
+
/**
|
234
|
+
* Represents a document that can be indexed and searched.
|
235
|
+
* @typedef {Object} SearchDocument
|
236
|
+
* @property {string} [id] - Optional unique identifier of the document.
|
237
|
+
* @property {string} content - The searchable text content.
|
238
|
+
* @property {Record<string, any>} [metadata] - Additional metadata for context.
|
239
|
+
*/
|
240
|
+
export type SearchDocument = {
|
241
|
+
id?: string;
|
242
|
+
content: string;
|
243
|
+
metadata?: Record<string, any>;
|
244
|
+
};
|
245
|
+
|
246
|
+
/**
|
247
|
+
* Represents a search result with a similarity score.
|
248
|
+
* @typedef {Object} SearchResult
|
249
|
+
* @property {SearchDocument} document - The matched document.
|
250
|
+
* @property {number} score - The similarity score.
|
251
|
+
*/
|
252
|
+
export type SearchResult = {
|
253
|
+
document: SearchDocument;
|
254
|
+
score: number;
|
255
|
+
};
|
256
|
+
|
257
|
+
/* ======================== MEILISEARCH ======================== */
|
258
|
+
export type MeilisearchConfig = {
|
259
|
+
host: string;
|
260
|
+
apiKey: string;
|
261
|
+
searchableAttributes?: string[];
|
262
|
+
sortableAttributes?: string[];
|
263
|
+
};
|
264
|
+
|
265
|
+
export type MeilisearchSettings = {
|
266
|
+
searchableAttributes?: string[];
|
267
|
+
sortableAttributes?: string[];
|
268
|
+
};
|
269
|
+
|
270
|
+
/* ======================== ACTIONS ======================== */
|
271
|
+
|
272
|
+
export type Action = {
|
273
|
+
name: string;
|
274
|
+
parameters: {
|
275
|
+
name: string;
|
276
|
+
value: string;
|
277
|
+
}[];
|
278
|
+
};
|
@@ -1,13 +1,10 @@
|
|
1
|
-
import {
|
2
|
-
ActionData,
|
3
|
-
QueueItem,
|
4
|
-
QueueItemParameter,
|
5
|
-
QueueResult,
|
6
|
-
TransformedQueueItem,
|
7
|
-
} from "../types";
|
1
|
+
import { QueueItem, QueueItemParameter, QueueResult } from "@/types";
|
8
2
|
|
9
3
|
export class QueueItemTransformer {
|
10
|
-
static transformActionToQueueItem(action:
|
4
|
+
static transformActionToQueueItem(action: {
|
5
|
+
name: string;
|
6
|
+
parameters: Record<string, any>;
|
7
|
+
}): QueueItem {
|
11
8
|
return {
|
12
9
|
name: action.name || "",
|
13
10
|
parameters: QueueItemTransformer.transformParameters(
|
@@ -18,8 +15,8 @@ export class QueueItemTransformer {
|
|
18
15
|
|
19
16
|
static transformFromSimilarActions(
|
20
17
|
similarActions: QueueResult[]
|
21
|
-
):
|
22
|
-
return similarActions?.map((action:
|
18
|
+
): QueueItem[] | undefined {
|
19
|
+
return similarActions?.map((action: QueueResult) =>
|
23
20
|
QueueItemTransformer.transformActionToQueueItem(action)
|
24
21
|
);
|
25
22
|
}
|
@@ -34,7 +31,7 @@ export class QueueItemTransformer {
|
|
34
31
|
}
|
35
32
|
|
36
33
|
static transformActionsToQueueItems(
|
37
|
-
actions:
|
34
|
+
actions: { name: string; parameters: Record<string, any> }[] | undefined
|
38
35
|
): QueueItem[] | undefined {
|
39
36
|
return actions?.map((action) => this.transformActionToQueueItem(action));
|
40
37
|
}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import { GraphEngine } from "../graph/engine";
|
2
|
+
import { Action, GraphDefinition, SharedState } from "../types";
|
3
|
+
|
4
|
+
export function setupGraphsWithActions<T>(
|
5
|
+
actions: Action[],
|
6
|
+
baseStateMapping: Record<string, SharedState<T>>,
|
7
|
+
graphMaps: GraphDefinition<T>[]
|
8
|
+
): {
|
9
|
+
initialStates: SharedState<T>[];
|
10
|
+
graphs: GraphEngine<T>[];
|
11
|
+
startNodes: string[];
|
12
|
+
} {
|
13
|
+
const initialStates = actions.map((action) => {
|
14
|
+
const parametersObject = Object.fromEntries(
|
15
|
+
action.parameters.map((param) => [
|
16
|
+
param.name,
|
17
|
+
param.value !== undefined ? param.value : null,
|
18
|
+
]) // Handle optional values
|
19
|
+
);
|
20
|
+
|
21
|
+
const baseState = baseStateMapping[action.name] || {};
|
22
|
+
|
23
|
+
return {
|
24
|
+
...baseState,
|
25
|
+
...parametersObject,
|
26
|
+
};
|
27
|
+
});
|
28
|
+
|
29
|
+
const selectedGraphs = actions
|
30
|
+
.map((action) => graphMaps.find((graph) => graph.name === action.name))
|
31
|
+
.filter((graph): graph is GraphDefinition<T> => graph !== undefined);
|
32
|
+
|
33
|
+
if (selectedGraphs.length !== actions.length) {
|
34
|
+
throw new Error("Graph not found");
|
35
|
+
}
|
36
|
+
|
37
|
+
const startNodes = selectedGraphs.map((graph) => graph.entryNode);
|
38
|
+
const graphEngines = selectedGraphs.map((graph) => new GraphEngine(graph));
|
39
|
+
|
40
|
+
return {
|
41
|
+
initialStates: initialStates as SharedState<T>[],
|
42
|
+
graphs: graphEngines,
|
43
|
+
startNodes,
|
44
|
+
};
|
45
|
+
}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import { Node } from "@/types";
|
2
|
+
import { z } from "zod";
|
3
|
+
|
4
|
+
export const stringifyZodSchema = <T>(nodes: Node<T>[]) => {
|
5
|
+
return nodes
|
6
|
+
.map((node) => {
|
7
|
+
const schemaStr = node.schema
|
8
|
+
? getSchemaString(node.schema)
|
9
|
+
: "No parameters";
|
10
|
+
return `Workflow: ${node.name}\nDescription: ${node.description}\nParameters: ${schemaStr}`;
|
11
|
+
})
|
12
|
+
.join("\n\n");
|
13
|
+
};
|
14
|
+
|
15
|
+
const getSchemaString = (schema: z.ZodType): string => {
|
16
|
+
if (schema instanceof z.ZodObject) {
|
17
|
+
const entries = Object.entries(schema.shape);
|
18
|
+
const fields = entries.map(([key, value]) => {
|
19
|
+
const description = (value as any)._def.description;
|
20
|
+
const schemaStr = getSchemaString(value as z.ZodType);
|
21
|
+
return description
|
22
|
+
? `${key}: ${schemaStr} // ${description}`
|
23
|
+
: `${key}: ${schemaStr}`;
|
24
|
+
});
|
25
|
+
return `z.object({${fields.join(", ")}})`;
|
26
|
+
}
|
27
|
+
|
28
|
+
if (schema instanceof z.ZodArray) {
|
29
|
+
return `z.array(${getSchemaString(schema.element)})`;
|
30
|
+
}
|
31
|
+
|
32
|
+
if (schema instanceof z.ZodString) {
|
33
|
+
return "z.string()";
|
34
|
+
}
|
35
|
+
|
36
|
+
if (schema instanceof z.ZodNumber) {
|
37
|
+
return "z.number()";
|
38
|
+
}
|
39
|
+
|
40
|
+
if (schema instanceof z.ZodBoolean) {
|
41
|
+
return "z.boolean()";
|
42
|
+
}
|
43
|
+
|
44
|
+
return `z.unknown()`;
|
45
|
+
};
|
package/.nvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
v22.0.0
|