@forbocai/core 0.4.4

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.mjs ADDED
@@ -0,0 +1,903 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/agent.ts
8
+ var createInitialState = (partial) => {
9
+ return { ...partial };
10
+ };
11
+ var updateAgentState = (currentState, updates) => {
12
+ return {
13
+ ...currentState,
14
+ ...updates
15
+ };
16
+ };
17
+ var processAgentInput = (currentState, input, context = {}) => {
18
+ const stateKeys = Object.keys(currentState);
19
+ const stateSummary = stateKeys.length > 0 ? stateKeys.map((k) => `${k}=${JSON.stringify(currentState[k])}`).join(", ") : "empty";
20
+ return {
21
+ dialogue: `Processing: "${input}" (State: ${stateSummary})`,
22
+ action: {
23
+ type: "respond",
24
+ reason: "Default processing"
25
+ }
26
+ };
27
+ };
28
+ var exportToSoul = (agentId, name, persona, state, memories) => {
29
+ return {
30
+ id: agentId,
31
+ version: "1.0.0",
32
+ name,
33
+ persona,
34
+ memories: [...memories],
35
+ // Copy array for immutability
36
+ state: { ...state }
37
+ // Copy state for immutability
38
+ };
39
+ };
40
+ var createAgent = (config) => {
41
+ let state = createInitialState(config.initialState);
42
+ let memories = [];
43
+ const cortex = config.cortex;
44
+ const apiUrl = config.apiUrl || "http://localhost:8080";
45
+ const agentId = config.id || "agent-" + Math.random().toString(36).substring(7);
46
+ const getAgentState = () => {
47
+ return { ...state };
48
+ };
49
+ const setAgentState = (newState) => {
50
+ state = newState;
51
+ };
52
+ const process = async (input, context = {}) => {
53
+ const currentState = getAgentState();
54
+ const apiContext = Object.entries(context).map(([k, v]) => [k, String(v)]);
55
+ const timestamp = Date.now();
56
+ apiContext.push(["timestamp", String(timestamp)]);
57
+ let relevantMemories = [];
58
+ if (config.memory && typeof config.memory.recall === "function") {
59
+ try {
60
+ relevantMemories = await config.memory.recall(input, 5);
61
+ } catch {
62
+ }
63
+ }
64
+ let directive = "Respond normally.";
65
+ let instruction = "IDLE";
66
+ let target;
67
+ try {
68
+ const dirRes = await fetch(`${apiUrl}/agents/${agentId}/directive`, {
69
+ method: "POST",
70
+ headers: {
71
+ "Content-Type": "application/json",
72
+ "X-Request-Timestamp": String(timestamp)
73
+ },
74
+ body: JSON.stringify({
75
+ dirContext: apiContext,
76
+ dirState: currentState,
77
+ dirMemories: relevantMemories.map((m) => ({ text: m.text, type: m.type, importance: m.importance }))
78
+ })
79
+ });
80
+ if (dirRes.ok) {
81
+ const data = await dirRes.json();
82
+ directive = data.dirReason;
83
+ instruction = data.dirInstruction;
84
+ target = data.dirTarget;
85
+ } else {
86
+ throw new Error(`API Error: ${dirRes.status}`);
87
+ }
88
+ } catch (e) {
89
+ throw new Error(`API Directive Failed: ${e instanceof Error ? e.message : String(e)}`);
90
+ }
91
+ const memoryContext = relevantMemories.length > 0 ? `
92
+ Memories:
93
+ ${relevantMemories.map((m) => `- [${m.type}] ${m.text}`).join("\n")}
94
+ ` : "";
95
+ const prompt = `System: You are ${config.persona}.
96
+ Directive: ${instruction} (${directive}).
97
+ Target: ${target || "None"}${memoryContext}
98
+ User: ${input}
99
+ Agent:`;
100
+ const generatedText = await cortex.complete(prompt);
101
+ const verRes = await fetch(`${apiUrl}/agents/${agentId}/verdict`, {
102
+ method: "POST",
103
+ headers: { "Content-Type": "application/json" },
104
+ body: JSON.stringify({
105
+ verDirective: {
106
+ dirInstruction: instruction,
107
+ dirTarget: target || "",
108
+ dirReason: directive
109
+ },
110
+ verAction: {
111
+ gaType: instruction,
112
+ // Map to generic action type
113
+ actionReason: directive,
114
+ actionTarget: target || ""
115
+ },
116
+ verThought: generatedText
117
+ })
118
+ });
119
+ if (!verRes.ok) {
120
+ throw new Error(`API Verdict Error: ${verRes.status}`);
121
+ }
122
+ const vData = await verRes.json();
123
+ const isValid = vData.verValid;
124
+ const signature = vData.verSignature;
125
+ if (!isValid) {
126
+ return {
127
+ dialogue: "... [Action Blocked by Protocol]",
128
+ action: { type: "BLOCKED", reason: "API Validation Failed" }
129
+ };
130
+ }
131
+ if (config.memory && typeof config.memory.store === "function") {
132
+ config.memory.store(`Input: "${input}" \u2192 Action: ${instruction}`, "experience", 0.5).catch(() => {
133
+ });
134
+ }
135
+ return {
136
+ dialogue: generatedText,
137
+ action: {
138
+ type: instruction,
139
+ reason: directive,
140
+ target,
141
+ signature
142
+ },
143
+ thought: `Directive: ${directive}`
144
+ };
145
+ };
146
+ const exportSoul2 = async () => {
147
+ let exportedMemories = [...memories];
148
+ if (config.memory && typeof config.memory.export === "function") {
149
+ try {
150
+ exportedMemories = await config.memory.export();
151
+ } catch {
152
+ }
153
+ }
154
+ return exportToSoul(agentId, "Agent", config.persona, state, exportedMemories);
155
+ };
156
+ return {
157
+ process,
158
+ getState: getAgentState,
159
+ setState: setAgentState,
160
+ export: exportSoul2
161
+ };
162
+ };
163
+ var fromSoul = async (soul, cortex, memory) => {
164
+ const agent = createAgent({
165
+ id: soul.id,
166
+ cortex,
167
+ memory: memory || null,
168
+ persona: soul.persona,
169
+ initialState: soul.state
170
+ });
171
+ if (memory && soul.memories && soul.memories.length > 0 && typeof memory.import === "function") {
172
+ try {
173
+ await memory.import(soul.memories);
174
+ } catch (e) {
175
+ console.warn("Failed to import memories into module:", e);
176
+ }
177
+ }
178
+ return agent;
179
+ };
180
+
181
+ // src/bridge.ts
182
+ var createBridge = (config = {}) => {
183
+ const effectiveConfig = {
184
+ strictMode: config.strictMode ?? false,
185
+ ...config
186
+ };
187
+ const rules = /* @__PURE__ */ new Map();
188
+ if (config.customRules) {
189
+ config.customRules.forEach((rule) => rules.set(rule.id, rule));
190
+ }
191
+ const validateRemote = async (action) => {
192
+ const response = await fetch(`${effectiveConfig.apiUrl}/bridge/validate`, {
193
+ method: "POST",
194
+ headers: { "Content-Type": "application/json" },
195
+ body: JSON.stringify({
196
+ actionType: action.type,
197
+ payload: JSON.stringify(action.payload || {})
198
+ })
199
+ });
200
+ if (!response.ok) {
201
+ throw new Error(`API validation failed: ${response.statusText}`);
202
+ }
203
+ const data = await response.json();
204
+ return {
205
+ valid: data.valid,
206
+ reason: data.reason
207
+ };
208
+ };
209
+ const validate = async (action, context = {}) => {
210
+ const applicableRules = Array.from(rules.values()).filter(
211
+ (rule) => rule.actionTypes.some(
212
+ (t) => t.toLowerCase() === action.type.toLowerCase()
213
+ )
214
+ );
215
+ if (effectiveConfig.strictMode && applicableRules.length === 0) {
216
+ const safeTypes = ["IDLE", "idle", "WAIT", "wait"];
217
+ if (!safeTypes.includes(action.type)) {
218
+ return {
219
+ valid: false,
220
+ reason: `Unknown action type '${action.type}' in strict mode`,
221
+ correctedAction: { ...action, type: "IDLE", reason: "Unknown action type" }
222
+ };
223
+ }
224
+ }
225
+ let currentAction = action;
226
+ for (const rule of applicableRules) {
227
+ const result = rule.validate(currentAction, context);
228
+ if (!result.valid) {
229
+ if (effectiveConfig.apiUrl) {
230
+ const apiResult = await validateRemote(action);
231
+ console.debug("API validation result:", apiResult);
232
+ }
233
+ return result;
234
+ }
235
+ if (result.correctedAction) {
236
+ currentAction = result.correctedAction;
237
+ }
238
+ }
239
+ return {
240
+ valid: true,
241
+ correctedAction: currentAction !== action ? currentAction : void 0
242
+ };
243
+ };
244
+ const registerRule = (rule) => {
245
+ rules.set(rule.id, rule);
246
+ if (effectiveConfig.apiUrl) {
247
+ }
248
+ };
249
+ const listRules = () => {
250
+ return Array.from(rules.values());
251
+ };
252
+ const removeRule = (ruleId) => {
253
+ return rules.delete(ruleId);
254
+ };
255
+ return {
256
+ validate,
257
+ registerRule,
258
+ listRules,
259
+ removeRule
260
+ };
261
+ };
262
+ var validateAction = (action, rules, context = {}) => {
263
+ for (const rule of rules) {
264
+ if (rule.actionTypes.some((t) => t.toLowerCase() === action.type.toLowerCase())) {
265
+ const result = rule.validate(action, context);
266
+ if (!result.valid) {
267
+ return result;
268
+ }
269
+ }
270
+ }
271
+ return { valid: true };
272
+ };
273
+
274
+ // src/soul.ts
275
+ import Irys from "@irys/sdk";
276
+ var createSoul = (id, name, persona, state, memories = []) => {
277
+ return {
278
+ id,
279
+ version: "1.0.0",
280
+ name,
281
+ persona,
282
+ state: { ...state },
283
+ memories: [...memories]
284
+ };
285
+ };
286
+ var serializeSoul = (soul) => {
287
+ return JSON.stringify(soul, null, 2);
288
+ };
289
+ var deserializeSoul = (json) => {
290
+ const parsed = JSON.parse(json);
291
+ if (!parsed.id || !parsed.persona || !parsed.state) {
292
+ throw new Error("Invalid Soul format: missing required fields");
293
+ }
294
+ return {
295
+ id: parsed.id,
296
+ version: parsed.version || "1.0.0",
297
+ name: parsed.name || "Unknown",
298
+ persona: parsed.persona,
299
+ state: parsed.state,
300
+ memories: parsed.memories || [],
301
+ signature: parsed.signature
302
+ };
303
+ };
304
+ var uploadToArweave = async (soul, config) => {
305
+ if (!config.privateKey) {
306
+ throw new Error("Private key required for direct Arweave upload");
307
+ }
308
+ const irys = new Irys({
309
+ url: config.irysUrl || "https://node1.irys.xyz",
310
+ token: config.token || "solana",
311
+ key: config.privateKey
312
+ });
313
+ const dataToUpload = serializeSoul(soul);
314
+ try {
315
+ const receipt = await irys.upload(dataToUpload);
316
+ return {
317
+ txId: receipt.id,
318
+ url: `https://gateway.irys.xyz/${receipt.id}`,
319
+ soul
320
+ };
321
+ } catch (e) {
322
+ throw new Error(`Failed to upload to Arweave: ${e}`);
323
+ }
324
+ };
325
+ var exportSoul = async (agentId, soul, config = {}) => {
326
+ if (config.privateKey) {
327
+ try {
328
+ return await uploadToArweave(soul, config);
329
+ } catch (e) {
330
+ console.warn("Direct Arweave upload failed, falling back to API", e);
331
+ }
332
+ }
333
+ const apiUrl = config.apiUrl || "https://api.forboc.ai";
334
+ try {
335
+ const response = await fetch(`${apiUrl}/agents/${agentId}/soul/export`, {
336
+ method: "POST",
337
+ headers: { "Content-Type": "application/json" },
338
+ body: JSON.stringify({ soul })
339
+ // Sending full soul for server to sign/upload
340
+ });
341
+ if (!response.ok) {
342
+ throw new Error(`Export failed: ${response.statusText}`);
343
+ }
344
+ const data = await response.json();
345
+ return {
346
+ txId: data.txId,
347
+ url: data.url,
348
+ soul
349
+ };
350
+ } catch (e) {
351
+ console.warn("API export failed, returning mock Arweave TXID used for dev");
352
+ const mockTxId = `mock_ar_${Date.now()}`;
353
+ return {
354
+ txId: mockTxId,
355
+ url: `https://arweave.net/${mockTxId}`,
356
+ soul
357
+ };
358
+ }
359
+ };
360
+ var importSoulFromArweave = async (txId, config = {}) => {
361
+ const gateway = config.gatewayUrl || "https://gateway.irys.xyz";
362
+ try {
363
+ const response = await fetch(`${gateway}/${txId}`, {
364
+ method: "GET",
365
+ headers: { "Content-Type": "application/json" }
366
+ });
367
+ if (!response.ok) {
368
+ throw new Error(`Import failed: ${response.statusText}`);
369
+ }
370
+ const data = await response.json();
371
+ if (!data.id || !data.persona) {
372
+ throw new Error("Invalid soul data from Arweave");
373
+ }
374
+ return data;
375
+ } catch (e) {
376
+ throw new Error(`Failed to import Soul from TXID ${txId}: ${e}`);
377
+ }
378
+ };
379
+ var getSoulList = async (limit = 50, apiUrl) => {
380
+ const url = apiUrl || "https://api.forboc.ai";
381
+ try {
382
+ const response = await fetch(`${url}/souls?limit=${limit}`);
383
+ if (!response.ok) throw new Error(response.statusText);
384
+ const data = await response.json();
385
+ return data.souls.map((s) => ({
386
+ txId: s.txId,
387
+ name: s.name,
388
+ agentId: s.agentId,
389
+ exportedAt: s.exportedAt,
390
+ url: s.url || `https://gateway.irys.xyz/${s.txId}`
391
+ }));
392
+ } catch (e) {
393
+ return [];
394
+ }
395
+ };
396
+ var createSoulInstance = (id, name, persona, state, memories = [], initialApiUrl) => {
397
+ const soulData = createSoul(id, name, persona, state, memories);
398
+ const defaultApiUrl = initialApiUrl || "https://api.forboc.ai";
399
+ const performExport = async (config) => {
400
+ return exportSoul(soulData.id, soulData, {
401
+ ...config,
402
+ apiUrl: config?.apiUrl || defaultApiUrl
403
+ });
404
+ };
405
+ return {
406
+ export: performExport,
407
+ toJSON: () => ({ ...soulData })
408
+ };
409
+ };
410
+ var validateSoul = (soul) => {
411
+ const errors = [];
412
+ if (!soul.id) errors.push("Missing id");
413
+ if (!soul.persona) errors.push("Missing persona");
414
+ if (!soul.state) errors.push("Missing state");
415
+ return {
416
+ valid: errors.length === 0,
417
+ errors
418
+ };
419
+ };
420
+
421
+ // src/ghost.ts
422
+ var startGhostSession = async (config) => {
423
+ const apiUrl = config.apiUrl || "https://api.forboc.ai";
424
+ try {
425
+ const response = await fetch(`${apiUrl}/ghost/run`, {
426
+ method: "POST",
427
+ headers: { "Content-Type": "application/json" },
428
+ body: JSON.stringify({
429
+ testSuite: config.testSuite,
430
+ duration: config.duration
431
+ })
432
+ });
433
+ if (!response.ok) {
434
+ throw new Error(`Failed to start Ghost session: ${response.statusText}`);
435
+ }
436
+ const data = await response.json();
437
+ return {
438
+ sessionId: data.sessionId,
439
+ status: data.runStatus
440
+ };
441
+ } catch (e) {
442
+ const mockId = `ghost_${Date.now()}_${Math.random().toString(36).substring(7)}`;
443
+ return {
444
+ sessionId: mockId,
445
+ status: "running"
446
+ };
447
+ }
448
+ };
449
+ var getGhostStatus = async (sessionId, apiUrl) => {
450
+ const url = apiUrl || "https://api.forboc.ai";
451
+ try {
452
+ const response = await fetch(`${url}/ghost/${sessionId}/status`, {
453
+ method: "GET",
454
+ headers: { "Content-Type": "application/json" }
455
+ });
456
+ if (!response.ok) {
457
+ throw new Error(`Failed to get Ghost status: ${response.statusText}`);
458
+ }
459
+ const data = await response.json();
460
+ return {
461
+ sessionId: data.ghostSessionId,
462
+ status: data.ghostStatus,
463
+ progress: data.ghostProgress,
464
+ startedAt: data.ghostStartedAt,
465
+ duration: data.ghostDuration,
466
+ errors: data.ghostErrors
467
+ };
468
+ } catch (e) {
469
+ return {
470
+ sessionId,
471
+ status: "running",
472
+ progress: Math.floor(Math.random() * 100),
473
+ startedAt: (/* @__PURE__ */ new Date()).toISOString(),
474
+ duration: 60,
475
+ errors: 0
476
+ };
477
+ }
478
+ };
479
+ var getGhostResults = async (sessionId, apiUrl) => {
480
+ const url = apiUrl || "https://api.forboc.ai";
481
+ try {
482
+ const response = await fetch(`${url}/ghost/${sessionId}/results`, {
483
+ method: "GET",
484
+ headers: { "Content-Type": "application/json" }
485
+ });
486
+ if (!response.ok) {
487
+ throw new Error(`Failed to get Ghost results: ${response.statusText}`);
488
+ }
489
+ const data = await response.json();
490
+ return {
491
+ sessionId: data.resultsSessionId,
492
+ totalTests: data.resultsTotalTests,
493
+ passed: data.resultsPassed,
494
+ failed: data.resultsFailed,
495
+ skipped: data.resultsSkipped,
496
+ duration: data.resultsDuration,
497
+ tests: data.resultsTests.map((t) => ({
498
+ name: t.testName,
499
+ passed: t.testPassed,
500
+ duration: t.testDuration,
501
+ error: t.testError,
502
+ screenshot: t.testScreenshot
503
+ })),
504
+ coverage: data.resultsCoverage,
505
+ metrics: Object.fromEntries(data.resultsMetrics)
506
+ };
507
+ } catch (e) {
508
+ return {
509
+ sessionId,
510
+ totalTests: 5,
511
+ passed: 4,
512
+ failed: 1,
513
+ skipped: 0,
514
+ duration: 1245,
515
+ tests: [
516
+ { name: "test.navigation", passed: true, duration: 150 },
517
+ { name: "test.combat", passed: true, duration: 230 },
518
+ { name: "test.dialogue", passed: false, duration: 450, error: "Timeout" }
519
+ ],
520
+ coverage: 0.75,
521
+ metrics: {
522
+ avgFrameRate: 58.5,
523
+ memoryUsageMB: 512.3,
524
+ aiDecisionsPerSec: 15.2
525
+ }
526
+ };
527
+ }
528
+ };
529
+ var waitForGhostCompletion = async (sessionId, pollIntervalMs = 5e3, timeoutMs = 3e5, apiUrl, onProgress) => {
530
+ const startTime = Date.now();
531
+ while (Date.now() - startTime < timeoutMs) {
532
+ try {
533
+ const status = await getGhostStatus(sessionId, apiUrl);
534
+ if (onProgress) {
535
+ onProgress(status);
536
+ }
537
+ if (status.status === "completed") {
538
+ return getGhostResults(sessionId, apiUrl);
539
+ }
540
+ if (status.status === "failed") {
541
+ throw new Error(`Ghost session failed with ${status.errors} errors`);
542
+ }
543
+ } catch (e) {
544
+ }
545
+ await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
546
+ }
547
+ throw new Error(`Ghost session timed out after ${timeoutMs}ms`);
548
+ };
549
+ var stopGhostSession = async (sessionId, apiUrl) => {
550
+ const url = apiUrl || "https://api.forboc.ai";
551
+ try {
552
+ const response = await fetch(`${url}/ghost/${sessionId}/stop`, {
553
+ method: "POST",
554
+ headers: { "Content-Type": "application/json" }
555
+ });
556
+ if (!response.ok) {
557
+ throw new Error(`Failed to stop Ghost session: ${response.statusText}`);
558
+ }
559
+ const data = await response.json();
560
+ return {
561
+ stopped: true,
562
+ status: data.status || "stopped"
563
+ };
564
+ } catch (e) {
565
+ return {
566
+ stopped: true,
567
+ status: "stopped"
568
+ };
569
+ }
570
+ };
571
+ var getGhostHistory = async (limit = 10, apiUrl) => {
572
+ const url = apiUrl || "https://api.forboc.ai";
573
+ try {
574
+ const response = await fetch(`${url}/ghost/history?limit=${limit}`, {
575
+ method: "GET",
576
+ headers: { "Content-Type": "application/json" }
577
+ });
578
+ if (!response.ok) {
579
+ throw new Error(`Failed to get Ghost history: ${response.statusText}`);
580
+ }
581
+ const data = await response.json();
582
+ return data.sessions.map((s) => ({
583
+ sessionId: s.sessionId,
584
+ testSuite: s.testSuite,
585
+ startedAt: s.startedAt,
586
+ completedAt: s.completedAt,
587
+ status: s.status,
588
+ passRate: s.passRate
589
+ }));
590
+ } catch (e) {
591
+ return [];
592
+ }
593
+ };
594
+ var createGhost = (config) => {
595
+ let sessionId = null;
596
+ const apiUrl = config.apiUrl || "https://api.forboc.ai";
597
+ const run = async () => {
598
+ const result = await startGhostSession(config);
599
+ sessionId = result.sessionId;
600
+ return sessionId;
601
+ };
602
+ const status = async () => {
603
+ if (!sessionId) {
604
+ throw new Error("Ghost session not started");
605
+ }
606
+ return getGhostStatus(sessionId, apiUrl);
607
+ };
608
+ const results = async () => {
609
+ if (!sessionId) {
610
+ throw new Error("Ghost session not started");
611
+ }
612
+ return getGhostResults(sessionId, apiUrl);
613
+ };
614
+ const stop = async () => {
615
+ sessionId = null;
616
+ };
617
+ const waitForCompletion = async (pollIntervalMs, timeoutMs, onProgress) => {
618
+ if (!sessionId) {
619
+ throw new Error("Ghost session not started");
620
+ }
621
+ return waitForGhostCompletion(
622
+ sessionId,
623
+ pollIntervalMs,
624
+ timeoutMs,
625
+ apiUrl,
626
+ onProgress
627
+ );
628
+ };
629
+ return {
630
+ run,
631
+ status,
632
+ results,
633
+ stop,
634
+ waitForCompletion
635
+ };
636
+ };
637
+
638
+ // src/cortex-remote.ts
639
+ var RemoteCortex = class {
640
+ constructor(apiUrl) {
641
+ this.apiUrl = apiUrl;
642
+ }
643
+ async init() {
644
+ return {
645
+ id: `remote_${Date.now()}`,
646
+ model: "api-integrated",
647
+ ready: true,
648
+ engine: "remote"
649
+ };
650
+ }
651
+ async complete(prompt, options) {
652
+ const response = await fetch(`${this.apiUrl}/cortex/complete`, {
653
+ method: "POST",
654
+ headers: { "Content-Type": "application/json" },
655
+ body: JSON.stringify({ prompt, ...options })
656
+ });
657
+ if (!response.ok) throw new Error(`Remote Cortex failed: ${response.statusText}`);
658
+ const data = await response.json();
659
+ return data.text;
660
+ }
661
+ async *completeStream(prompt, options) {
662
+ const result = await this.complete(prompt, options);
663
+ yield result;
664
+ }
665
+ };
666
+
667
+ // src/presets/index.ts
668
+ var presets_exports = {};
669
+ __export(presets_exports, {
670
+ RPG_MEMORY_TYPES: () => RPG_MEMORY_TYPES,
671
+ RPG_MOODS: () => RPG_MOODS,
672
+ attackRule: () => attackRule,
673
+ createRPGState: () => createRPGState,
674
+ interactRule: () => interactRule,
675
+ movementRule: () => movementRule,
676
+ puzzleRules: () => puzzleRules,
677
+ resourceRule: () => resourceRule,
678
+ rpgRules: () => rpgRules,
679
+ socialRules: () => socialRules,
680
+ spatialRules: () => spatialRules,
681
+ speakRule: () => speakRule
682
+ });
683
+
684
+ // src/presets/rpg.ts
685
+ var RPG_MOODS = {
686
+ hostile: "hostile",
687
+ suspicious: "suspicious",
688
+ neutral: "neutral",
689
+ friendly: "friendly",
690
+ loyal: "loyal"
691
+ };
692
+ var RPG_MEMORY_TYPES = {
693
+ observation: "observation",
694
+ experience: "experience",
695
+ knowledge: "knowledge",
696
+ emotion: "emotion"
697
+ };
698
+ var createRPGState = (partial) => {
699
+ return {
700
+ inventory: partial?.inventory ?? [],
701
+ hp: partial?.hp ?? 100,
702
+ mana: partial?.mana ?? 100,
703
+ skills: partial?.skills ?? {},
704
+ relationships: partial?.relationships ?? {},
705
+ mood: partial?.mood ?? "neutral",
706
+ ...partial
707
+ };
708
+ };
709
+ var movementRule = {
710
+ id: "core.movement",
711
+ name: "Movement Validation",
712
+ description: "Ensures MOVE actions have valid x,y coordinates",
713
+ actionTypes: ["MOVE", "move"],
714
+ validate: (action, context) => {
715
+ const payload = action.payload || {};
716
+ const target = payload.target;
717
+ if (!target || typeof target.x !== "number" || typeof target.y !== "number") {
718
+ return {
719
+ valid: false,
720
+ reason: "MOVE action must have target with numeric x,y coordinates",
721
+ correctedAction: {
722
+ ...action,
723
+ type: "IDLE",
724
+ reason: "Invalid MOVE target - defaulting to IDLE"
725
+ }
726
+ };
727
+ }
728
+ const world = context.worldState || {};
729
+ const maxX = world.maxX || Infinity;
730
+ const maxY = world.maxY || Infinity;
731
+ if (target.x < 0 || target.x > maxX || target.y < 0 || target.y > maxY) {
732
+ return {
733
+ valid: false,
734
+ reason: `MOVE target (${target.x}, ${target.y}) is out of bounds`,
735
+ correctedAction: {
736
+ ...action,
737
+ payload: {
738
+ ...payload,
739
+ target: {
740
+ x: Math.max(0, Math.min(maxX, target.x)),
741
+ y: Math.max(0, Math.min(maxY, target.y))
742
+ }
743
+ }
744
+ }
745
+ };
746
+ }
747
+ return { valid: true };
748
+ }
749
+ };
750
+ var attackRule = {
751
+ id: "core.attack",
752
+ name: "Attack Validation",
753
+ description: "Ensures ATTACK actions have valid targetId",
754
+ actionTypes: ["ATTACK", "attack"],
755
+ validate: (action, context) => {
756
+ if (!action.target && !action.payload?.targetId) {
757
+ return {
758
+ valid: false,
759
+ reason: "ATTACK action must have a target or targetId",
760
+ correctedAction: {
761
+ ...action,
762
+ type: "IDLE",
763
+ reason: "Invalid ATTACK - no target specified"
764
+ }
765
+ };
766
+ }
767
+ const world = context.worldState || {};
768
+ const entities = world.entities || [];
769
+ const targetId = action.target || action.payload?.targetId;
770
+ if (entities.length > 0 && !entities.includes(targetId)) {
771
+ return {
772
+ valid: false,
773
+ reason: `ATTACK target '${targetId}' does not exist in world`,
774
+ correctedAction: {
775
+ ...action,
776
+ type: "IDLE",
777
+ reason: "Target not found"
778
+ }
779
+ };
780
+ }
781
+ return { valid: true };
782
+ }
783
+ };
784
+ var interactRule = {
785
+ id: "core.interact",
786
+ name: "Interact Validation",
787
+ description: "Ensures INTERACT actions have valid objectId",
788
+ actionTypes: ["INTERACT", "interact"],
789
+ validate: (action, context) => {
790
+ if (!action.target && !action.payload?.objectId) {
791
+ return {
792
+ valid: false,
793
+ reason: "INTERACT action must have objectId",
794
+ correctedAction: {
795
+ ...action,
796
+ type: "IDLE",
797
+ reason: "Invalid INTERACT - no object specified"
798
+ }
799
+ };
800
+ }
801
+ return { valid: true };
802
+ }
803
+ };
804
+ var speakRule = {
805
+ id: "core.speak",
806
+ name: "Speak Validation",
807
+ description: "Ensures SPEAK actions have non-empty text",
808
+ actionTypes: ["SPEAK", "speak"],
809
+ validate: (action, context) => {
810
+ const text = action.payload?.text;
811
+ if (!text || text.trim().length === 0) {
812
+ return {
813
+ valid: false,
814
+ reason: "SPEAK action must have non-empty text",
815
+ correctedAction: {
816
+ ...action,
817
+ type: "IDLE",
818
+ reason: "Empty speech - defaulting to IDLE"
819
+ }
820
+ };
821
+ }
822
+ const maxLength = context.constraints?.maxSpeechLength || 1e3;
823
+ if (text.length > maxLength) {
824
+ return {
825
+ valid: true,
826
+ reason: `Speech truncated to ${maxLength} characters`,
827
+ correctedAction: {
828
+ ...action,
829
+ payload: {
830
+ ...action.payload,
831
+ text: text.substring(0, maxLength)
832
+ }
833
+ }
834
+ };
835
+ }
836
+ return { valid: true };
837
+ }
838
+ };
839
+ var resourceRule = {
840
+ id: "core.resources",
841
+ name: "Resource Validation",
842
+ description: "Ensures agent has required resources for action",
843
+ actionTypes: ["ATTACK", "CAST", "USE_ITEM"],
844
+ validate: (action, context) => {
845
+ const agent = context.agentState || {};
846
+ const hp = agent.hp ?? 100;
847
+ const mana = agent.mana ?? 100;
848
+ if (hp <= 0) {
849
+ return {
850
+ valid: false,
851
+ reason: "Agent is dead and cannot perform actions",
852
+ correctedAction: { ...action, type: "IDLE", reason: "Agent dead" }
853
+ };
854
+ }
855
+ if (action.type === "CAST" || action.type === "cast") {
856
+ const manaCost = action.payload?.manaCost || 10;
857
+ if (mana < manaCost) {
858
+ return {
859
+ valid: false,
860
+ reason: `Insufficient mana: need ${manaCost}, have ${mana}`,
861
+ correctedAction: { ...action, type: "IDLE", reason: "Not enough mana" }
862
+ };
863
+ }
864
+ }
865
+ return { valid: true };
866
+ }
867
+ };
868
+ var rpgRules = [movementRule, attackRule, interactRule, speakRule, resourceRule];
869
+ var spatialRules = [movementRule];
870
+ var socialRules = [speakRule, interactRule];
871
+ var puzzleRules = [movementRule, interactRule];
872
+
873
+ // src/index.ts
874
+ var SDK_VERSION = "0.4.4";
875
+ export {
876
+ RemoteCortex,
877
+ SDK_VERSION,
878
+ createAgent,
879
+ createBridge,
880
+ createGhost,
881
+ createInitialState,
882
+ createSoul,
883
+ createSoulInstance,
884
+ deserializeSoul,
885
+ exportSoul,
886
+ exportToSoul,
887
+ fromSoul,
888
+ getGhostHistory,
889
+ getGhostResults,
890
+ getGhostStatus,
891
+ getSoulList,
892
+ importSoulFromArweave,
893
+ presets_exports as presets,
894
+ processAgentInput,
895
+ serializeSoul,
896
+ startGhostSession,
897
+ stopGhostSession,
898
+ updateAgentState,
899
+ uploadToArweave,
900
+ validateAction,
901
+ validateSoul,
902
+ waitForGhostCompletion
903
+ };