@forbocai/core 0.5.2 → 0.5.6
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/ans104-GLQVFKBA.mjs +224 -0
- package/dist/chunk-7P6ASYW6.mjs +9 -0
- package/dist/index.d.mts +29 -70
- package/dist/index.d.ts +29 -70
- package/dist/index.js +306 -85
- package/dist/index.mjs +76 -89
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-7P6ASYW6.mjs";
|
|
6
4
|
|
|
7
5
|
// src/agent.ts
|
|
8
6
|
var createInitialState = (partial) => {
|
|
@@ -14,17 +12,6 @@ var updateAgentState = (currentState, updates) => {
|
|
|
14
12
|
...updates
|
|
15
13
|
};
|
|
16
14
|
};
|
|
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
15
|
var exportToSoul = (agentId, name, persona, state, memories) => {
|
|
29
16
|
return {
|
|
30
17
|
id: agentId,
|
|
@@ -37,9 +24,8 @@ var exportToSoul = (agentId, name, persona, state, memories) => {
|
|
|
37
24
|
};
|
|
38
25
|
var createAgent = (config) => {
|
|
39
26
|
let state = createInitialState(config.initialState);
|
|
40
|
-
let memories = [];
|
|
41
27
|
const cortex = config.cortex;
|
|
42
|
-
const apiUrl = config.apiUrl || "
|
|
28
|
+
const apiUrl = config.apiUrl || "https://api.forboc.ai";
|
|
43
29
|
const agentId = config.id || "agent-" + Math.random().toString(36).substring(7);
|
|
44
30
|
const getAgentState = () => {
|
|
45
31
|
return { ...state };
|
|
@@ -68,7 +54,8 @@ var createAgent = (config) => {
|
|
|
68
54
|
try {
|
|
69
55
|
const rawMemories = await config.memory.recall(
|
|
70
56
|
directiveData.memoryRecall.query,
|
|
71
|
-
directiveData.memoryRecall.limit
|
|
57
|
+
directiveData.memoryRecall.limit,
|
|
58
|
+
directiveData.memoryRecall.threshold
|
|
72
59
|
);
|
|
73
60
|
recalledMemories = rawMemories.map((m) => ({
|
|
74
61
|
text: m.text,
|
|
@@ -76,7 +63,8 @@ var createAgent = (config) => {
|
|
|
76
63
|
importance: m.importance,
|
|
77
64
|
similarity: void 0
|
|
78
65
|
}));
|
|
79
|
-
} catch {
|
|
66
|
+
} catch (e) {
|
|
67
|
+
console.warn("Memory recall failed, continuing with empty memories:", e);
|
|
80
68
|
}
|
|
81
69
|
}
|
|
82
70
|
const contextBody = {
|
|
@@ -120,8 +108,7 @@ var createAgent = (config) => {
|
|
|
120
108
|
}
|
|
121
109
|
if (config.memory && typeof config.memory.store === "function" && verdictData.memoryStore) {
|
|
122
110
|
for (const instruction of verdictData.memoryStore) {
|
|
123
|
-
config.memory.store(instruction.text, instruction.type, instruction.importance).catch(() =>
|
|
124
|
-
});
|
|
111
|
+
config.memory.store(instruction.text, instruction.type, instruction.importance).catch((e) => console.warn("Memory store failed:", e));
|
|
125
112
|
}
|
|
126
113
|
}
|
|
127
114
|
if (verdictData.stateDelta && Object.keys(verdictData.stateDelta).length > 0) {
|
|
@@ -137,11 +124,12 @@ var createAgent = (config) => {
|
|
|
137
124
|
};
|
|
138
125
|
};
|
|
139
126
|
const exportSoul2 = async () => {
|
|
140
|
-
let exportedMemories = [
|
|
127
|
+
let exportedMemories = [];
|
|
141
128
|
if (config.memory && typeof config.memory.export === "function") {
|
|
142
129
|
try {
|
|
143
130
|
exportedMemories = await config.memory.export();
|
|
144
|
-
} catch {
|
|
131
|
+
} catch (e) {
|
|
132
|
+
console.warn("Memory export failed, exporting with empty memories:", e);
|
|
145
133
|
}
|
|
146
134
|
}
|
|
147
135
|
return exportToSoul(agentId, "Agent", config.persona, state, exportedMemories);
|
|
@@ -164,7 +152,8 @@ var fromSoul = async (soul, cortex, memory) => {
|
|
|
164
152
|
if (memory && soul.memories && soul.memories.length > 0 && typeof memory.import === "function") {
|
|
165
153
|
try {
|
|
166
154
|
await memory.import(soul.memories);
|
|
167
|
-
} catch {
|
|
155
|
+
} catch (e) {
|
|
156
|
+
console.warn("Memory hydration failed, continuing without memories:", e);
|
|
168
157
|
}
|
|
169
158
|
}
|
|
170
159
|
return agent;
|
|
@@ -218,10 +207,6 @@ var createBridge = (config = {}) => {
|
|
|
218
207
|
for (const rule of applicableRules) {
|
|
219
208
|
const result = rule.validate(currentAction, context);
|
|
220
209
|
if (!result.valid) {
|
|
221
|
-
if (effectiveConfig.apiUrl) {
|
|
222
|
-
const apiResult = await validateRemote(action);
|
|
223
|
-
console.debug("API validation result:", apiResult);
|
|
224
|
-
}
|
|
225
210
|
return result;
|
|
226
211
|
}
|
|
227
212
|
if (result.correctedAction) {
|
|
@@ -235,8 +220,6 @@ var createBridge = (config = {}) => {
|
|
|
235
220
|
};
|
|
236
221
|
const registerRule = (rule) => {
|
|
237
222
|
rules.set(rule.id, rule);
|
|
238
|
-
if (effectiveConfig.apiUrl) {
|
|
239
|
-
}
|
|
240
223
|
};
|
|
241
224
|
const listRules = () => {
|
|
242
225
|
return Array.from(rules.values());
|
|
@@ -264,7 +247,6 @@ var validateAction = (action, rules, context = {}) => {
|
|
|
264
247
|
};
|
|
265
248
|
|
|
266
249
|
// src/soul.ts
|
|
267
|
-
import Irys from "@irys/sdk";
|
|
268
250
|
var createSoul = (id, name, persona, state, memories = []) => {
|
|
269
251
|
return {
|
|
270
252
|
id,
|
|
@@ -294,63 +276,69 @@ var deserializeSoul = (json) => {
|
|
|
294
276
|
};
|
|
295
277
|
};
|
|
296
278
|
var uploadToArweave = async (soul, config) => {
|
|
297
|
-
|
|
298
|
-
|
|
279
|
+
const wallet = config.walletJwk || config.privateKey;
|
|
280
|
+
if (!wallet) {
|
|
281
|
+
throw new Error("Arweave wallet JWK required for direct upload");
|
|
299
282
|
}
|
|
300
|
-
|
|
301
|
-
url: config.irysUrl || "https://node1.irys.xyz",
|
|
302
|
-
token: config.token || "solana",
|
|
303
|
-
key: config.privateKey
|
|
304
|
-
});
|
|
305
|
-
const dataToUpload = serializeSoul(soul);
|
|
283
|
+
let createArweaveDataItem;
|
|
306
284
|
try {
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
txId: receipt.id,
|
|
310
|
-
url: `https://gateway.irys.xyz/${receipt.id}`,
|
|
311
|
-
soul
|
|
312
|
-
};
|
|
285
|
+
const imported = await import("./ans104-GLQVFKBA.mjs");
|
|
286
|
+
createArweaveDataItem = imported.createArweaveDataItem;
|
|
313
287
|
} catch (e) {
|
|
314
|
-
throw new Error(
|
|
288
|
+
throw new Error("Missing ANS-104 Arweave module. Rebuild the SDK to enable direct uploads.");
|
|
315
289
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
290
|
+
const jwk = typeof wallet === "string" ? JSON.parse(wallet) : wallet;
|
|
291
|
+
const dataToUpload = serializeSoul(soul);
|
|
292
|
+
const tags = [
|
|
293
|
+
{ name: "Content-Type", value: "application/json" },
|
|
294
|
+
{ name: "App-Name", value: "ForbocAI" },
|
|
295
|
+
{ name: "App-Version", value: "soul-1" }
|
|
296
|
+
];
|
|
297
|
+
const dataItem = await createArweaveDataItem(dataToUpload, jwk, { tags });
|
|
298
|
+
const rawData = dataItem.raw;
|
|
299
|
+
if (!rawData) {
|
|
300
|
+
throw new Error("Failed to build ANS-104 data item");
|
|
324
301
|
}
|
|
325
|
-
const
|
|
302
|
+
const bundlerUrl = config.bundlerUrl || "https://upload.ardrive.io/v1/tx";
|
|
303
|
+
const gatewayUrl = config.gatewayUrl || "https://arweave.net";
|
|
326
304
|
try {
|
|
327
|
-
const response = await fetch(
|
|
305
|
+
const response = await fetch(bundlerUrl, {
|
|
328
306
|
method: "POST",
|
|
329
|
-
headers: { "Content-Type": "application/
|
|
330
|
-
body:
|
|
331
|
-
// Sending full soul for server to sign/upload
|
|
307
|
+
headers: { "Content-Type": "application/octet-stream" },
|
|
308
|
+
body: rawData
|
|
332
309
|
});
|
|
333
310
|
if (!response.ok) {
|
|
334
|
-
|
|
311
|
+
const message = await response.text().catch(() => response.statusText);
|
|
312
|
+
throw new Error(message || response.statusText);
|
|
313
|
+
}
|
|
314
|
+
const responseText = await response.text();
|
|
315
|
+
let responseJson = null;
|
|
316
|
+
try {
|
|
317
|
+
responseJson = JSON.parse(responseText);
|
|
318
|
+
} catch {
|
|
319
|
+
responseJson = null;
|
|
320
|
+
}
|
|
321
|
+
const txId = responseJson?.id || responseJson?.dataItemId || responseJson?.txId || (typeof responseText === "string" && responseText.trim().length > 0 ? responseText.trim() : null) || dataItem.id;
|
|
322
|
+
if (!txId) {
|
|
323
|
+
throw new Error("Bundler response did not include a data item id");
|
|
335
324
|
}
|
|
336
|
-
const data = await response.json();
|
|
337
325
|
return {
|
|
338
|
-
txId
|
|
339
|
-
url:
|
|
326
|
+
txId,
|
|
327
|
+
url: `${gatewayUrl}/${txId}`,
|
|
340
328
|
soul
|
|
341
329
|
};
|
|
342
330
|
} catch (e) {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
};
|
|
331
|
+
throw new Error(`Failed to upload to Arweave: ${e}`);
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
var exportSoul = async (_agentId, soul, config = {}) => {
|
|
335
|
+
if (!config.walletJwk && !config.privateKey) {
|
|
336
|
+
throw new Error("walletJwk required for Arweave ANS-104 export");
|
|
350
337
|
}
|
|
338
|
+
return uploadToArweave(soul, config);
|
|
351
339
|
};
|
|
352
340
|
var importSoulFromArweave = async (txId, config = {}) => {
|
|
353
|
-
const gateway = config.gatewayUrl || "https://
|
|
341
|
+
const gateway = config.gatewayUrl || "https://arweave.net";
|
|
354
342
|
try {
|
|
355
343
|
const response = await fetch(`${gateway}/${txId}`, {
|
|
356
344
|
method: "GET",
|
|
@@ -374,25 +362,22 @@ var getSoulList = async (limit = 50, apiUrl) => {
|
|
|
374
362
|
const response = await fetch(`${url}/souls?limit=${limit}`);
|
|
375
363
|
if (!response.ok) throw new Error(response.statusText);
|
|
376
364
|
const data = await response.json();
|
|
377
|
-
return data.souls.map((s) =>
|
|
378
|
-
txId
|
|
379
|
-
name
|
|
380
|
-
agentId
|
|
381
|
-
exportedAt
|
|
382
|
-
|
|
383
|
-
|
|
365
|
+
return data.souls.map((s) => {
|
|
366
|
+
const txId = s.txId || s.soulEntryTxId || s.cid;
|
|
367
|
+
const name = s.name || s.soulEntryName;
|
|
368
|
+
const agentId = s.agentId || s.soulEntryAgentId;
|
|
369
|
+
const exportedAt = s.exportedAt || s.soulEntryExportedAt;
|
|
370
|
+
const url2 = s.url || s.soulEntryArweaveUrl || `https://arweave.net/${txId}`;
|
|
371
|
+
return { txId, name, agentId, exportedAt, url: url2 };
|
|
372
|
+
});
|
|
384
373
|
} catch (e) {
|
|
385
374
|
return [];
|
|
386
375
|
}
|
|
387
376
|
};
|
|
388
|
-
var createSoulInstance = (id, name, persona, state, memories = []
|
|
377
|
+
var createSoulInstance = (id, name, persona, state, memories = []) => {
|
|
389
378
|
const soulData = createSoul(id, name, persona, state, memories);
|
|
390
|
-
const defaultApiUrl = initialApiUrl || "https://api.forboc.ai";
|
|
391
379
|
const performExport = async (config) => {
|
|
392
|
-
return exportSoul(soulData.id, soulData, {
|
|
393
|
-
...config,
|
|
394
|
-
apiUrl: config?.apiUrl || defaultApiUrl
|
|
395
|
-
});
|
|
380
|
+
return exportSoul(soulData.id, soulData, { ...config });
|
|
396
381
|
};
|
|
397
382
|
return {
|
|
398
383
|
export: performExport,
|
|
@@ -604,6 +589,9 @@ var createGhost = (config) => {
|
|
|
604
589
|
return getGhostResults(sessionId, apiUrl);
|
|
605
590
|
};
|
|
606
591
|
const stop = async () => {
|
|
592
|
+
if (sessionId) {
|
|
593
|
+
await stopGhostSession(sessionId, apiUrl);
|
|
594
|
+
}
|
|
607
595
|
sessionId = null;
|
|
608
596
|
};
|
|
609
597
|
const waitForCompletion = async (pollIntervalMs, timeoutMs, onProgress) => {
|
|
@@ -628,7 +616,7 @@ var createGhost = (config) => {
|
|
|
628
616
|
};
|
|
629
617
|
|
|
630
618
|
// src/cortex-remote.ts
|
|
631
|
-
var createRemoteCortex = (apiUrl) => {
|
|
619
|
+
var createRemoteCortex = (apiUrl, cortexId = "local") => {
|
|
632
620
|
const init = async () => ({
|
|
633
621
|
id: `remote_${Date.now()}`,
|
|
634
622
|
model: "api-integrated",
|
|
@@ -636,7 +624,7 @@ var createRemoteCortex = (apiUrl) => {
|
|
|
636
624
|
engine: "remote"
|
|
637
625
|
});
|
|
638
626
|
const complete = async (prompt, options) => {
|
|
639
|
-
const response = await fetch(`${apiUrl}/cortex/complete`, {
|
|
627
|
+
const response = await fetch(`${apiUrl}/cortex/${cortexId}/complete`, {
|
|
640
628
|
method: "POST",
|
|
641
629
|
headers: { "Content-Type": "application/json" },
|
|
642
630
|
body: JSON.stringify({ prompt, ...options })
|
|
@@ -859,7 +847,7 @@ var socialRules = [speakRule, interactRule];
|
|
|
859
847
|
var puzzleRules = [movementRule, interactRule];
|
|
860
848
|
|
|
861
849
|
// src/index.ts
|
|
862
|
-
var SDK_VERSION = "0.5.
|
|
850
|
+
var SDK_VERSION = "0.5.6";
|
|
863
851
|
export {
|
|
864
852
|
SDK_VERSION,
|
|
865
853
|
createAgent,
|
|
@@ -879,7 +867,6 @@ export {
|
|
|
879
867
|
getSoulList,
|
|
880
868
|
importSoulFromArweave,
|
|
881
869
|
presets_exports as presets,
|
|
882
|
-
processAgentInput,
|
|
883
870
|
serializeSoul,
|
|
884
871
|
startGhostSession,
|
|
885
872
|
stopGhostSession,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forbocai/core",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"description": "Core agnostic logic for ForbocAI SDK",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"test": "vitest"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"
|
|
15
|
+
"arweave": "^1.15.7",
|
|
16
|
+
"base64url": "^3.0.1",
|
|
16
17
|
"axios": "^1.6.2",
|
|
17
18
|
"zod": "^3.22.4"
|
|
18
19
|
},
|