eny-ai 1.0.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.
package/dist/index.js ADDED
@@ -0,0 +1,495 @@
1
+ import {
2
+ SYMBOL_NAMES,
3
+ TokenType,
4
+ applyEvolve,
5
+ hasWASMTarget,
6
+ init_parser,
7
+ init_tokenize,
8
+ init_transpile,
9
+ parse,
10
+ parser_exports,
11
+ runENY,
12
+ tokenize,
13
+ transpileToDTS,
14
+ transpileToJS,
15
+ transpileToWAT,
16
+ transpile_exports,
17
+ validateSemantic,
18
+ validateSemanticFull
19
+ } from "./chunk-2WFUL4XJ.js";
20
+ import {
21
+ ALPHABET,
22
+ FALSE,
23
+ NIL,
24
+ SYMBOLS,
25
+ TRANSPILE_MAP,
26
+ TRUE,
27
+ VOID,
28
+ asyncFn,
29
+ component,
30
+ effect,
31
+ error,
32
+ filter,
33
+ find,
34
+ fn,
35
+ get,
36
+ log,
37
+ map,
38
+ navigate,
39
+ post,
40
+ reduce,
41
+ shape,
42
+ state,
43
+ storageGet,
44
+ storageSet,
45
+ toSymbolic,
46
+ transpileSymbols,
47
+ validate
48
+ } from "./chunk-E4KJZEXX.js";
49
+ import {
50
+ __toCommonJS
51
+ } from "./chunk-PNKVD2UK.js";
52
+
53
+ // src/index.ts
54
+ init_parser();
55
+ init_tokenize();
56
+ init_transpile();
57
+
58
+ // src/ia/index.ts
59
+ var LocalIA = class {
60
+ constructor() {
61
+ this.name = "LocalIA";
62
+ this.capabilities = /* @__PURE__ */ new Map();
63
+ this.capabilities.set("aprender", () => ({ learned: true }));
64
+ this.capabilities.set("sugerir", () => ({ suggestions: ["option1", "option2"] }));
65
+ this.capabilities.set("evoluir", () => ({ evolved: true }));
66
+ this.capabilities.set("analisar", () => ({ analysis: "completed" }));
67
+ this.capabilities.set("prever", () => ({ prediction: "success" }));
68
+ this.capabilities.set("otimizar", () => ({ optimized: true }));
69
+ }
70
+ async isAvailable() {
71
+ return true;
72
+ }
73
+ async process(ia, context) {
74
+ const log2 = context?.onLog;
75
+ if (log2) {
76
+ log2({
77
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
78
+ level: "info",
79
+ event: "ia.process.start",
80
+ detail: { name: ia.name, capabilities: ia.body }
81
+ });
82
+ }
83
+ const results = {};
84
+ const processedCapabilities = [];
85
+ for (const capability of ia.body) {
86
+ const capName = capability.split(/\s+/)[0].toLowerCase();
87
+ const handler = this.capabilities.get(capName);
88
+ if (handler) {
89
+ results[capName] = handler();
90
+ processedCapabilities.push(capName);
91
+ if (log2) {
92
+ log2({
93
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
94
+ level: "debug",
95
+ event: "ia.capability.executed",
96
+ detail: { capability: capName, result: results[capName] }
97
+ });
98
+ }
99
+ } else {
100
+ results[capName] = { status: "acknowledged", raw: capability };
101
+ processedCapabilities.push(capName);
102
+ if (log2) {
103
+ log2({
104
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
105
+ level: "warn",
106
+ event: "ia.capability.unknown",
107
+ detail: { capability: capName, raw: capability }
108
+ });
109
+ }
110
+ }
111
+ }
112
+ if (log2) {
113
+ log2({
114
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
115
+ level: "info",
116
+ event: "ia.process.complete",
117
+ detail: { name: ia.name, processedCount: processedCapabilities.length }
118
+ });
119
+ }
120
+ return {
121
+ success: true,
122
+ result: results,
123
+ capabilities: processedCapabilities
124
+ };
125
+ }
126
+ /**
127
+ * Register a custom capability handler
128
+ */
129
+ registerCapability(name, handler) {
130
+ this.capabilities.set(name.toLowerCase(), handler);
131
+ }
132
+ };
133
+ var RemoteIA = class {
134
+ constructor(endpoint, apiKey) {
135
+ this.name = "RemoteIA";
136
+ this.endpoint = endpoint;
137
+ this.apiKey = apiKey;
138
+ }
139
+ async isAvailable() {
140
+ return false;
141
+ }
142
+ async process(ia, context) {
143
+ const log2 = context?.onLog;
144
+ if (log2) {
145
+ log2({
146
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
147
+ level: "warn",
148
+ event: "ia.remote.notImplemented",
149
+ detail: { endpoint: this.endpoint }
150
+ });
151
+ }
152
+ return {
153
+ success: false,
154
+ error: "RemoteIA is not implemented yet. Use LocalIA for development."
155
+ };
156
+ }
157
+ };
158
+ var IAManager = class {
159
+ constructor(defaultProvider) {
160
+ this.providers = /* @__PURE__ */ new Map();
161
+ this.defaultProvider = defaultProvider || new LocalIA();
162
+ this.providers.set(this.defaultProvider.name, this.defaultProvider);
163
+ }
164
+ registerProvider(provider) {
165
+ this.providers.set(provider.name, provider);
166
+ }
167
+ getProvider(name) {
168
+ if (name && this.providers.has(name)) {
169
+ return this.providers.get(name);
170
+ }
171
+ return this.defaultProvider;
172
+ }
173
+ async processIA(ia, context, providerName) {
174
+ const provider = this.getProvider(providerName);
175
+ const available = await provider.isAvailable();
176
+ if (!available) {
177
+ if (provider.name !== "LocalIA") {
178
+ const localIA = this.providers.get("LocalIA") || new LocalIA();
179
+ return localIA.process(ia, context);
180
+ }
181
+ return {
182
+ success: false,
183
+ error: `Provider ${provider.name} is not available`
184
+ };
185
+ }
186
+ return provider.process(ia, context);
187
+ }
188
+ };
189
+ var defaultIAManager = new IAManager();
190
+ async function processIA(ia, context, provider) {
191
+ const p = provider || new LocalIA();
192
+ return p.process(ia, context);
193
+ }
194
+
195
+ // src/pillars.ts
196
+ function createSystem(config) {
197
+ const lines = [];
198
+ lines.push(`\u03A3 SYSTEM "${config.name}"`);
199
+ if (config.mode) lines.push(`\u03A3 MODE ${config.mode}`);
200
+ if (config.ui) lines.push(`\u03A3 UI ${config.ui}`);
201
+ if (config.evolve) lines.push(`\u03A3 EVOLVE true`);
202
+ if (config.targets?.length) {
203
+ lines.push(`\u03A3 TARGET ${config.targets.join(" + ")}`);
204
+ }
205
+ return lines.join("\n");
206
+ }
207
+ function getState(ast) {
208
+ return {
209
+ system: ast.system,
210
+ mode: ast.mode,
211
+ ui: ast.ui,
212
+ version: ast.version,
213
+ isEny: ast.isEny,
214
+ substates: ast.substates || []
215
+ };
216
+ }
217
+ function createFunction(name, args, steps) {
218
+ const argsStr = args.length ? `(${args.join(", ")})` : "";
219
+ const stepsStr = steps.map((s) => ` \u2192 ${s}`).join("\n");
220
+ return `\u0394 function ${name}${argsStr}
221
+ ${stepsStr}`;
222
+ }
223
+ function getFunctions(ast) {
224
+ return ast.functions || [];
225
+ }
226
+ function createObject(name, props) {
227
+ const propsStr = Object.entries(props).map(([k, v]) => ` ${k}: ${JSON.stringify(v)}`).join("\n");
228
+ return `\u03A9 ${name} {
229
+ ${propsStr}
230
+ }`;
231
+ }
232
+ function createClass(name, props, methods = [], extendsClass) {
233
+ const extendsStr = extendsClass ? ` \u2192 ${extendsClass}` : "";
234
+ const propsStr = Object.entries(props).map(([k, v]) => ` ${k}: ${typeof v}`).join("\n");
235
+ const methodsStr = methods.map((m) => ` ${m}()`).join("\n");
236
+ return `\u25CB ${name}${extendsStr} {
237
+ ${propsStr}
238
+ ${methodsStr}
239
+ }`;
240
+ }
241
+ function getStructures(ast) {
242
+ return {
243
+ objects: ast.objects || [],
244
+ classes: ast.classes || [],
245
+ modules: ast.modules || []
246
+ };
247
+ }
248
+ function createEvent(name, handlers) {
249
+ const handlersStr = handlers.map((h) => ` \u2192 ${h}`).join("\n");
250
+ return `\u25CC ${name}
251
+ ${handlersStr}`;
252
+ }
253
+ function createLoop(count, body) {
254
+ const bodyStr = body.map((b) => ` ${b}`).join("\n");
255
+ return `\u21BB ${count} {
256
+ ${bodyStr}
257
+ }`;
258
+ }
259
+ function getTemporals(ast) {
260
+ return {
261
+ events: ast.events || [],
262
+ loops: ast.loops || [],
263
+ causes: ast.causes || [],
264
+ timeouts: ast.timeouts || [],
265
+ delays: ast.delays || [],
266
+ syncs: ast.syncs || []
267
+ };
268
+ }
269
+ function createThrottle(target, limit) {
270
+ return `\u23EC ${target} ${limit}`;
271
+ }
272
+ function createBoost(target, factor) {
273
+ return `\u23EB ${target} ${factor}`;
274
+ }
275
+ function getEnergy(ast) {
276
+ return {
277
+ throttles: ast.throttles || [],
278
+ boosts: ast.boosts || [],
279
+ costs: ast.costs || []
280
+ };
281
+ }
282
+ function createMemory(name, size, persist = false) {
283
+ return `\u{1D4DC} ${name} ${size}${persist ? " persist" : ""}`;
284
+ }
285
+ function createPersist(target, storage = "db") {
286
+ return `\u267E ${target} ${storage}`;
287
+ }
288
+ function getMemory(ast) {
289
+ return {
290
+ database: ast.database,
291
+ memories: ast.memories || [],
292
+ persists: ast.persists || []
293
+ };
294
+ }
295
+ function createInput(name, type = "text") {
296
+ return `\u2328 ${name} ${type}`;
297
+ }
298
+ function createVisual(name, props) {
299
+ const propsStr = Object.entries(props).map(([k, v]) => ` ${k}: ${v}`).join("\n");
300
+ return `\u{1F441} ${name} {
301
+ ${propsStr}
302
+ }`;
303
+ }
304
+ function getInterface(ast) {
305
+ return {
306
+ forms: ast.forms || [],
307
+ inputs: ast.inputs || [],
308
+ visuals: ast.visuals || [],
309
+ interfaces: ast.interfaces || []
310
+ };
311
+ }
312
+ function createSecurity(level, rules) {
313
+ const rulesStr = rules.map((r) => ` ${r}`).join("\n");
314
+ return `\u{1F6E1} ${level} {
315
+ ${rulesStr}
316
+ }`;
317
+ }
318
+ function createKey(name, permissions) {
319
+ const permsStr = permissions.map((p) => ` ${p}`).join("\n");
320
+ return `\u{1F511} ${name} {
321
+ ${permsStr}
322
+ }`;
323
+ }
324
+ function getSecurity(ast) {
325
+ return {
326
+ securities: ast.securities || [],
327
+ keys: ast.keys || [],
328
+ sandboxes: ast.sandboxes || [],
329
+ locks: ast.locks || [],
330
+ unlocks: ast.unlocks || []
331
+ };
332
+ }
333
+ function createEvolve(steps) {
334
+ const stepsStr = steps.map((s) => ` ${s}`).join("\n");
335
+ return `\u27F3 {
336
+ ${stepsStr}
337
+ }`;
338
+ }
339
+ function getEvolve(ast) {
340
+ return {
341
+ evolve: ast.evolve,
342
+ verifies: ast.verifies || [],
343
+ logNodes: ast.logNodes || []
344
+ };
345
+ }
346
+ function generateENY(config) {
347
+ const parts = [];
348
+ parts.push(`\u03A3 SYSTEM "${config.system.name}"`);
349
+ if (config.system.mode) parts.push(`\u03A3 MODE ${config.system.mode}`);
350
+ if (config.system.ui) parts.push(`\u03A3 UI ${config.system.ui}`);
351
+ parts.push("");
352
+ for (const fn2 of config.functions || []) {
353
+ parts.push(createFunction(fn2.name, fn2.args || [], fn2.steps));
354
+ parts.push("");
355
+ }
356
+ for (const obj of config.objects || []) {
357
+ parts.push(createObject(obj.name, obj.props));
358
+ parts.push("");
359
+ }
360
+ for (const evt of config.events || []) {
361
+ parts.push(createEvent(evt.name, evt.handlers));
362
+ parts.push("");
363
+ }
364
+ if (config.security) {
365
+ parts.push(createSecurity(config.security.level, config.security.rules));
366
+ parts.push("");
367
+ }
368
+ if (config.evolve?.length) {
369
+ parts.push(createEvolve(config.evolve));
370
+ }
371
+ return parts.join("\n").trim();
372
+ }
373
+
374
+ // src/index.ts
375
+ var VERSION = "1.0.0";
376
+ var NAME = "eny-ai";
377
+ var STATE = /* @__PURE__ */ Symbol("STATE");
378
+ var SUBSTATE = /* @__PURE__ */ Symbol("SUBSTATE");
379
+ var VOID_VAL = null;
380
+ var TRUE_VAL = true;
381
+ var FALSE_VAL = false;
382
+ var OBJECT = /* @__PURE__ */ Symbol("OBJECT");
383
+ var FUNCTION = /* @__PURE__ */ Symbol("FUNCTION");
384
+ var INTERFACE = /* @__PURE__ */ Symbol("INTERFACE");
385
+ var SHIELD = /* @__PURE__ */ Symbol("SECURITY");
386
+ var EVOLVE = /* @__PURE__ */ Symbol("EVOLVE");
387
+ function quickSystem(name, config) {
388
+ return createSystem({
389
+ name,
390
+ mode: config?.mode || "development",
391
+ ui: config?.ui || "auto",
392
+ evolve: config?.evolve || false
393
+ });
394
+ }
395
+ function compile(enyCode) {
396
+ const { transpileToJS: transpileToJS2 } = (init_transpile(), __toCommonJS(transpile_exports));
397
+ const { parse: parse2 } = (init_parser(), __toCommonJS(parser_exports));
398
+ const ast = parse2(enyCode);
399
+ return transpileToJS2(ast);
400
+ }
401
+ function isValidENY(code) {
402
+ try {
403
+ const { parse: parse2 } = (init_parser(), __toCommonJS(parser_exports));
404
+ const ast = parse2(code);
405
+ return ast.isEny === true;
406
+ } catch {
407
+ return false;
408
+ }
409
+ }
410
+ export {
411
+ ALPHABET,
412
+ EVOLVE,
413
+ FALSE,
414
+ FALSE_VAL,
415
+ FUNCTION,
416
+ IAManager,
417
+ INTERFACE,
418
+ LocalIA,
419
+ NAME,
420
+ NIL,
421
+ OBJECT,
422
+ RemoteIA,
423
+ SHIELD,
424
+ STATE,
425
+ SUBSTATE,
426
+ SYMBOLS,
427
+ SYMBOL_NAMES,
428
+ TRANSPILE_MAP,
429
+ TRUE,
430
+ TRUE_VAL,
431
+ TokenType,
432
+ VERSION,
433
+ VOID,
434
+ VOID_VAL,
435
+ applyEvolve,
436
+ asyncFn,
437
+ compile,
438
+ component,
439
+ createBoost,
440
+ createClass,
441
+ createEvent,
442
+ createEvolve,
443
+ createFunction,
444
+ createInput,
445
+ createKey,
446
+ createLoop,
447
+ createMemory,
448
+ createObject,
449
+ createPersist,
450
+ createSecurity,
451
+ createSystem,
452
+ createThrottle,
453
+ createVisual,
454
+ defaultIAManager,
455
+ effect,
456
+ error,
457
+ filter,
458
+ find,
459
+ fn,
460
+ generateENY,
461
+ get,
462
+ getEnergy,
463
+ getEvolve,
464
+ getFunctions,
465
+ getInterface,
466
+ getMemory,
467
+ getSecurity,
468
+ getState,
469
+ getStructures,
470
+ getTemporals,
471
+ hasWASMTarget,
472
+ isValidENY,
473
+ log,
474
+ map,
475
+ navigate,
476
+ parse,
477
+ post,
478
+ processIA,
479
+ quickSystem,
480
+ reduce,
481
+ runENY,
482
+ shape,
483
+ state,
484
+ storageGet,
485
+ storageSet,
486
+ toSymbolic,
487
+ tokenize,
488
+ transpileSymbols,
489
+ transpileToDTS,
490
+ transpileToJS,
491
+ transpileToWAT,
492
+ validate,
493
+ validateSemantic,
494
+ validateSemanticFull
495
+ };