@forbocai/core 0.5.8 → 0.6.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/chunk-63XJCSA3.mjs +339 -0
- package/dist/chunk-7WQWFGMJ.mjs +86 -0
- package/dist/chunk-EBFSO6HV.mjs +405 -0
- package/dist/chunk-ZO4M6UZR.mjs +86 -0
- package/dist/index.d.mts +2591 -205
- package/dist/index.d.ts +2591 -205
- package/dist/index.js +986 -443
- package/dist/index.mjs +923 -336
- package/dist/soul-7QZCL5UQ.mjs +20 -0
- package/dist/soul-EZ63WTVO.mjs +20 -0
- package/dist/soul-M4EWGY27.mjs +20 -0
- package/dist/soul-VFSUQDAD.mjs +20 -0
- package/package.json +5 -2
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
// src/store.ts
|
|
2
|
+
import { configureStore } from "@reduxjs/toolkit";
|
|
3
|
+
|
|
4
|
+
// src/apiSlice.ts
|
|
5
|
+
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query";
|
|
6
|
+
var sdkApi = createApi({
|
|
7
|
+
reducerPath: "forbocApi",
|
|
8
|
+
baseQuery: fetchBaseQuery({
|
|
9
|
+
baseUrl: "/",
|
|
10
|
+
prepareHeaders: (headers, { getState }) => {
|
|
11
|
+
return headers;
|
|
12
|
+
}
|
|
13
|
+
}),
|
|
14
|
+
tagTypes: ["NPC", "Memory", "Cortex", "Ghost", "Soul", "Bridge"],
|
|
15
|
+
endpoints: (builder) => ({
|
|
16
|
+
// NPC Endpoints
|
|
17
|
+
postDirective: builder.mutation({
|
|
18
|
+
query: ({ npcId, request, apiUrl, apiKey }) => ({
|
|
19
|
+
url: `${apiUrl}/npcs/${npcId}/directive`,
|
|
20
|
+
method: "POST",
|
|
21
|
+
headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {},
|
|
22
|
+
body: request
|
|
23
|
+
}),
|
|
24
|
+
invalidatesTags: ["NPC"]
|
|
25
|
+
}),
|
|
26
|
+
postContext: builder.mutation({
|
|
27
|
+
query: ({ npcId, request, apiUrl, apiKey }) => ({
|
|
28
|
+
url: `${apiUrl}/npcs/${npcId}/context`,
|
|
29
|
+
method: "POST",
|
|
30
|
+
headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {},
|
|
31
|
+
body: request
|
|
32
|
+
})
|
|
33
|
+
}),
|
|
34
|
+
postVerdict: builder.mutation({
|
|
35
|
+
query: ({ npcId, request, apiUrl, apiKey }) => ({
|
|
36
|
+
url: `${apiUrl}/npcs/${npcId}/verdict`,
|
|
37
|
+
method: "POST",
|
|
38
|
+
headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {},
|
|
39
|
+
body: request
|
|
40
|
+
}),
|
|
41
|
+
invalidatesTags: ["NPC"]
|
|
42
|
+
}),
|
|
43
|
+
postSpeak: builder.mutation({
|
|
44
|
+
query: ({ npcId, request, apiUrl, apiKey }) => ({
|
|
45
|
+
url: `${apiUrl}/npcs/${npcId}/speak`,
|
|
46
|
+
method: "POST",
|
|
47
|
+
headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {},
|
|
48
|
+
body: request
|
|
49
|
+
}),
|
|
50
|
+
invalidatesTags: ["NPC"]
|
|
51
|
+
}),
|
|
52
|
+
postDialogue: builder.mutation({
|
|
53
|
+
query: ({ npcId, request, apiUrl, apiKey }) => ({
|
|
54
|
+
url: `${apiUrl}/npcs/${npcId}/dialogue`,
|
|
55
|
+
method: "POST",
|
|
56
|
+
headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {},
|
|
57
|
+
body: request
|
|
58
|
+
})
|
|
59
|
+
}),
|
|
60
|
+
// Ghost Endpoints
|
|
61
|
+
postGhostRun: builder.mutation({
|
|
62
|
+
query: ({ request, apiUrl }) => ({ url: `${apiUrl}/ghost/run`, method: "POST", body: request }),
|
|
63
|
+
invalidatesTags: ["Ghost"]
|
|
64
|
+
}),
|
|
65
|
+
getGhostStatus: builder.query({
|
|
66
|
+
query: ({ sessionId, apiUrl }) => ({ url: `${apiUrl}/ghost/${sessionId}/status`, method: "GET" }),
|
|
67
|
+
providesTags: ["Ghost"]
|
|
68
|
+
}),
|
|
69
|
+
getGhostResults: builder.query({
|
|
70
|
+
query: ({ sessionId, apiUrl }) => ({ url: `${apiUrl}/ghost/${sessionId}/results`, method: "GET" })
|
|
71
|
+
}),
|
|
72
|
+
postGhostStop: builder.mutation({
|
|
73
|
+
query: ({ sessionId, apiUrl }) => ({ url: `${apiUrl}/ghost/${sessionId}/stop`, method: "POST" }),
|
|
74
|
+
invalidatesTags: ["Ghost"]
|
|
75
|
+
}),
|
|
76
|
+
getGhostHistory: builder.query({
|
|
77
|
+
query: ({ limit, apiUrl }) => ({ url: `${apiUrl}/ghost/history?limit=${limit}`, method: "GET" }),
|
|
78
|
+
providesTags: ["Ghost"]
|
|
79
|
+
}),
|
|
80
|
+
// Soul Endpoints
|
|
81
|
+
postSoulExport: builder.mutation({
|
|
82
|
+
query: ({ npcId, request, apiUrl }) => ({ url: `${apiUrl}/npcs/${npcId}/soul/export`, method: "POST", body: request }),
|
|
83
|
+
invalidatesTags: ["Soul"]
|
|
84
|
+
}),
|
|
85
|
+
getSoulImport: builder.query({
|
|
86
|
+
query: ({ txId, apiUrl }) => ({ url: `${apiUrl}/souls/${txId}`, method: "GET" })
|
|
87
|
+
}),
|
|
88
|
+
getSouls: builder.query({
|
|
89
|
+
query: ({ limit, apiUrl }) => ({ url: `${apiUrl}/souls?limit=${limit}`, method: "GET" }),
|
|
90
|
+
providesTags: ["Soul"]
|
|
91
|
+
}),
|
|
92
|
+
// Bridge Endpoints
|
|
93
|
+
postBridgeValidate: builder.mutation({
|
|
94
|
+
query: ({ request, npcId, apiUrl }) => ({
|
|
95
|
+
url: npcId ? `${apiUrl}/bridge/validate/${npcId}` : `${apiUrl}/bridge/validate`,
|
|
96
|
+
method: "POST",
|
|
97
|
+
body: request
|
|
98
|
+
})
|
|
99
|
+
}),
|
|
100
|
+
getBridgeRules: builder.query({
|
|
101
|
+
query: ({ apiUrl }) => ({ url: `${apiUrl}/rules`, method: "GET" }),
|
|
102
|
+
providesTags: ["Bridge"]
|
|
103
|
+
}),
|
|
104
|
+
postBridgePreset: builder.mutation({
|
|
105
|
+
query: ({ presetName, apiUrl }) => ({ url: `${apiUrl}/rules/presets/${presetName}`, method: "POST" }),
|
|
106
|
+
invalidatesTags: ["Bridge"]
|
|
107
|
+
}),
|
|
108
|
+
// Cortex Remote Endpoint
|
|
109
|
+
postCortexComplete: builder.mutation({
|
|
110
|
+
query: ({ cortexId, prompt, options, apiUrl, apiKey }) => ({
|
|
111
|
+
url: `${apiUrl}/cortex/${cortexId}/complete`,
|
|
112
|
+
method: "POST",
|
|
113
|
+
headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {},
|
|
114
|
+
body: { prompt, ...options }
|
|
115
|
+
})
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// src/npcSlice.ts
|
|
121
|
+
import { createSlice } from "@reduxjs/toolkit";
|
|
122
|
+
var initialState = {
|
|
123
|
+
id: "",
|
|
124
|
+
persona: "",
|
|
125
|
+
state: {},
|
|
126
|
+
history: [],
|
|
127
|
+
isBlocked: false
|
|
128
|
+
};
|
|
129
|
+
var npcSlice = createSlice({
|
|
130
|
+
name: "npc",
|
|
131
|
+
initialState,
|
|
132
|
+
reducers: {
|
|
133
|
+
setNPCInfo: (state, action) => {
|
|
134
|
+
state.id = action.payload.id;
|
|
135
|
+
state.persona = action.payload.persona;
|
|
136
|
+
if (action.payload.initialState) {
|
|
137
|
+
state.state = action.payload.initialState;
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
setNPCState: (state, action) => {
|
|
141
|
+
state.state = action.payload;
|
|
142
|
+
},
|
|
143
|
+
updateNPCState: (state, action) => {
|
|
144
|
+
state.state = { ...state.state, ...action.payload };
|
|
145
|
+
},
|
|
146
|
+
addToHistory: (state, action) => {
|
|
147
|
+
state.history.push(action.payload);
|
|
148
|
+
},
|
|
149
|
+
setHistory: (state, action) => {
|
|
150
|
+
state.history = action.payload;
|
|
151
|
+
},
|
|
152
|
+
setLastAction: (state, action) => {
|
|
153
|
+
state.lastAction = action.payload;
|
|
154
|
+
},
|
|
155
|
+
blockAction: (state, action) => {
|
|
156
|
+
state.isBlocked = true;
|
|
157
|
+
state.blockReason = action.payload;
|
|
158
|
+
},
|
|
159
|
+
clearBlock: (state) => {
|
|
160
|
+
state.isBlocked = false;
|
|
161
|
+
state.blockReason = void 0;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
var {
|
|
166
|
+
setNPCInfo,
|
|
167
|
+
setNPCState,
|
|
168
|
+
updateNPCState,
|
|
169
|
+
addToHistory,
|
|
170
|
+
setHistory,
|
|
171
|
+
setLastAction,
|
|
172
|
+
blockAction,
|
|
173
|
+
clearBlock
|
|
174
|
+
} = npcSlice.actions;
|
|
175
|
+
var npcSlice_default = npcSlice.reducer;
|
|
176
|
+
|
|
177
|
+
// src/cortexSlice.ts
|
|
178
|
+
import { createSlice as createSlice2 } from "@reduxjs/toolkit";
|
|
179
|
+
var initialState2 = {
|
|
180
|
+
status: {
|
|
181
|
+
id: "init",
|
|
182
|
+
model: "none",
|
|
183
|
+
ready: false,
|
|
184
|
+
engine: "mock"
|
|
185
|
+
},
|
|
186
|
+
isInitializing: false
|
|
187
|
+
};
|
|
188
|
+
var cortexSlice = createSlice2({
|
|
189
|
+
name: "cortex",
|
|
190
|
+
initialState: initialState2,
|
|
191
|
+
reducers: {
|
|
192
|
+
cortexInitStart: (state) => {
|
|
193
|
+
state.isInitializing = true;
|
|
194
|
+
state.error = void 0;
|
|
195
|
+
},
|
|
196
|
+
cortexInitSuccess: (state, action) => {
|
|
197
|
+
state.status = action.payload;
|
|
198
|
+
state.isInitializing = false;
|
|
199
|
+
state.error = void 0;
|
|
200
|
+
},
|
|
201
|
+
cortexInitFailed: (state, action) => {
|
|
202
|
+
state.isInitializing = false;
|
|
203
|
+
state.error = action.payload;
|
|
204
|
+
},
|
|
205
|
+
setCortexStatus: (state, action) => {
|
|
206
|
+
state.status = action.payload;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
var {
|
|
211
|
+
cortexInitStart,
|
|
212
|
+
cortexInitSuccess,
|
|
213
|
+
cortexInitFailed,
|
|
214
|
+
setCortexStatus
|
|
215
|
+
} = cortexSlice.actions;
|
|
216
|
+
var cortexSlice_default = cortexSlice.reducer;
|
|
217
|
+
|
|
218
|
+
// src/memorySlice.ts
|
|
219
|
+
import { createSlice as createSlice3 } from "@reduxjs/toolkit";
|
|
220
|
+
var initialState3 = {
|
|
221
|
+
trackedItemsCount: 0,
|
|
222
|
+
lastStoredItem: null,
|
|
223
|
+
lastRecalledItems: [],
|
|
224
|
+
storageStatus: "idle",
|
|
225
|
+
recallStatus: "idle",
|
|
226
|
+
error: null
|
|
227
|
+
};
|
|
228
|
+
var memorySlice = createSlice3({
|
|
229
|
+
name: "memory",
|
|
230
|
+
initialState: initialState3,
|
|
231
|
+
reducers: {
|
|
232
|
+
memoryStoreStart: (state) => {
|
|
233
|
+
state.storageStatus = "storing";
|
|
234
|
+
state.error = null;
|
|
235
|
+
},
|
|
236
|
+
memoryStoreSuccess: (state, action) => {
|
|
237
|
+
state.storageStatus = "idle";
|
|
238
|
+
state.lastStoredItem = action.payload;
|
|
239
|
+
state.trackedItemsCount += 1;
|
|
240
|
+
},
|
|
241
|
+
memoryStoreFailed: (state, action) => {
|
|
242
|
+
state.storageStatus = "error";
|
|
243
|
+
state.error = action.payload;
|
|
244
|
+
},
|
|
245
|
+
memoryRecallStart: (state) => {
|
|
246
|
+
state.recallStatus = "recalling";
|
|
247
|
+
state.error = null;
|
|
248
|
+
},
|
|
249
|
+
memoryRecallSuccess: (state, action) => {
|
|
250
|
+
state.recallStatus = "idle";
|
|
251
|
+
state.lastRecalledItems = action.payload;
|
|
252
|
+
},
|
|
253
|
+
memoryRecallFailed: (state, action) => {
|
|
254
|
+
state.recallStatus = "error";
|
|
255
|
+
state.error = action.payload;
|
|
256
|
+
},
|
|
257
|
+
memoryClear: (state) => {
|
|
258
|
+
state.trackedItemsCount = 0;
|
|
259
|
+
state.lastStoredItem = null;
|
|
260
|
+
state.lastRecalledItems = [];
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
var {
|
|
265
|
+
memoryStoreStart,
|
|
266
|
+
memoryStoreSuccess,
|
|
267
|
+
memoryStoreFailed,
|
|
268
|
+
memoryRecallStart,
|
|
269
|
+
memoryRecallSuccess,
|
|
270
|
+
memoryRecallFailed,
|
|
271
|
+
memoryClear
|
|
272
|
+
} = memorySlice.actions;
|
|
273
|
+
var memorySlice_default = memorySlice.reducer;
|
|
274
|
+
|
|
275
|
+
// src/store.ts
|
|
276
|
+
var createSDKStore = () => {
|
|
277
|
+
return configureStore({
|
|
278
|
+
reducer: {
|
|
279
|
+
[sdkApi.reducerPath]: sdkApi.reducer,
|
|
280
|
+
npc: npcSlice_default,
|
|
281
|
+
cortex: cortexSlice_default,
|
|
282
|
+
memory: memorySlice_default
|
|
283
|
+
},
|
|
284
|
+
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(sdkApi.middleware)
|
|
285
|
+
});
|
|
286
|
+
};
|
|
287
|
+
var store = createSDKStore();
|
|
288
|
+
var dispatch = store.dispatch;
|
|
289
|
+
|
|
290
|
+
// src/soul.ts
|
|
291
|
+
var createSoul = (id, name, persona, state, memories = []) => ({
|
|
292
|
+
id,
|
|
293
|
+
version: "1.0.0",
|
|
294
|
+
name,
|
|
295
|
+
persona,
|
|
296
|
+
state: { ...state },
|
|
297
|
+
memories: [...memories]
|
|
298
|
+
});
|
|
299
|
+
var serializeSoul = (soul) => JSON.stringify(soul, null, 2);
|
|
300
|
+
var deserializeSoul = (json) => {
|
|
301
|
+
const parsed = JSON.parse(json);
|
|
302
|
+
if (!parsed.id || !parsed.persona || !parsed.state) {
|
|
303
|
+
throw new Error("Invalid Soul format: missing required fields");
|
|
304
|
+
}
|
|
305
|
+
return {
|
|
306
|
+
id: parsed.id,
|
|
307
|
+
version: parsed.version || "1.0.0",
|
|
308
|
+
name: parsed.name || "Unknown",
|
|
309
|
+
persona: parsed.persona,
|
|
310
|
+
state: parsed.state,
|
|
311
|
+
memories: parsed.memories || [],
|
|
312
|
+
signature: parsed.signature
|
|
313
|
+
};
|
|
314
|
+
};
|
|
315
|
+
var exportSoul = async (npcId, _soul, config = {}) => {
|
|
316
|
+
const apiUrl = config.apiUrl || "https://api.forboc.ai";
|
|
317
|
+
try {
|
|
318
|
+
const data = await dispatch(sdkApi.endpoints.postSoulExport.initiate({
|
|
319
|
+
npcId,
|
|
320
|
+
request: {
|
|
321
|
+
agentIdRef: npcId,
|
|
322
|
+
persona: _soul.persona,
|
|
323
|
+
npcState: _soul.state
|
|
324
|
+
},
|
|
325
|
+
apiUrl
|
|
326
|
+
})).unwrap();
|
|
327
|
+
return {
|
|
328
|
+
txId: data.txId,
|
|
329
|
+
url: data.url,
|
|
330
|
+
soul: _soul
|
|
331
|
+
// Return the local soul data as context
|
|
332
|
+
};
|
|
333
|
+
} catch (e) {
|
|
334
|
+
throw new Error(`Soul export failed: ${e.message || "Network error"}`);
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
var importSoulFromArweave = async (txId, config = {}) => {
|
|
338
|
+
const apiUrl = config.apiUrl || "https://api.forboc.ai";
|
|
339
|
+
try {
|
|
340
|
+
const data = await dispatch(sdkApi.endpoints.getSoulImport.initiate({ txId, apiUrl })).unwrap();
|
|
341
|
+
return data;
|
|
342
|
+
} catch (e) {
|
|
343
|
+
throw new Error(`Import failed: ${e.message || "Network error"}`);
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
var getSoulList = async (limit = 50, apiUrl = "https://api.forboc.ai") => {
|
|
347
|
+
try {
|
|
348
|
+
const data = await dispatch(sdkApi.endpoints.getSouls.initiate({ limit, apiUrl })).unwrap();
|
|
349
|
+
return data.souls || [];
|
|
350
|
+
} catch {
|
|
351
|
+
return [];
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
var createSoulInstance = (id, name, persona, state, memories = []) => {
|
|
355
|
+
const soulData = createSoul(id, name, persona, state, memories);
|
|
356
|
+
return {
|
|
357
|
+
export: (config) => exportSoul(id, soulData, config),
|
|
358
|
+
toJSON: () => ({ ...soulData })
|
|
359
|
+
};
|
|
360
|
+
};
|
|
361
|
+
var validateSoul = (soul) => {
|
|
362
|
+
const errors = [
|
|
363
|
+
!soul.id && "Missing id",
|
|
364
|
+
!soul.persona && "Missing persona",
|
|
365
|
+
!soul.state && "Missing state"
|
|
366
|
+
].filter((e) => !!e);
|
|
367
|
+
return { valid: errors.length === 0, errors };
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
export {
|
|
371
|
+
sdkApi,
|
|
372
|
+
npcSlice,
|
|
373
|
+
setNPCInfo,
|
|
374
|
+
setNPCState,
|
|
375
|
+
updateNPCState,
|
|
376
|
+
addToHistory,
|
|
377
|
+
setHistory,
|
|
378
|
+
setLastAction,
|
|
379
|
+
blockAction,
|
|
380
|
+
clearBlock,
|
|
381
|
+
cortexSlice,
|
|
382
|
+
cortexInitStart,
|
|
383
|
+
cortexInitSuccess,
|
|
384
|
+
cortexInitFailed,
|
|
385
|
+
setCortexStatus,
|
|
386
|
+
memorySlice,
|
|
387
|
+
memoryStoreStart,
|
|
388
|
+
memoryStoreSuccess,
|
|
389
|
+
memoryStoreFailed,
|
|
390
|
+
memoryRecallStart,
|
|
391
|
+
memoryRecallSuccess,
|
|
392
|
+
memoryRecallFailed,
|
|
393
|
+
memoryClear,
|
|
394
|
+
createSDKStore,
|
|
395
|
+
store,
|
|
396
|
+
dispatch,
|
|
397
|
+
createSoul,
|
|
398
|
+
serializeSoul,
|
|
399
|
+
deserializeSoul,
|
|
400
|
+
exportSoul,
|
|
401
|
+
importSoulFromArweave,
|
|
402
|
+
getSoulList,
|
|
403
|
+
createSoulInstance,
|
|
404
|
+
validateSoul
|
|
405
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// src/soul.ts
|
|
2
|
+
var createSoul = (id, name, persona, state, memories = []) => ({
|
|
3
|
+
id,
|
|
4
|
+
version: "1.0.0",
|
|
5
|
+
name,
|
|
6
|
+
persona,
|
|
7
|
+
state: { ...state },
|
|
8
|
+
memories: [...memories]
|
|
9
|
+
});
|
|
10
|
+
var serializeSoul = (soul) => JSON.stringify(soul, null, 2);
|
|
11
|
+
var deserializeSoul = (json) => {
|
|
12
|
+
const parsed = JSON.parse(json);
|
|
13
|
+
if (!parsed.id || !parsed.persona || !parsed.state) {
|
|
14
|
+
throw new Error("Invalid Soul format: missing required fields");
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
id: parsed.id,
|
|
18
|
+
version: parsed.version || "1.0.0",
|
|
19
|
+
name: parsed.name || "Unknown",
|
|
20
|
+
persona: parsed.persona,
|
|
21
|
+
state: parsed.state,
|
|
22
|
+
memories: parsed.memories || [],
|
|
23
|
+
signature: parsed.signature
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
var exportSoul = async (npcId, _soul, config = {}) => {
|
|
27
|
+
const apiUrl = config.apiUrl || "https://api.forboc.ai";
|
|
28
|
+
const response = await fetch(`${apiUrl}/npcs/${npcId}/soul/export`, {
|
|
29
|
+
method: "POST",
|
|
30
|
+
headers: { "Content-Type": "application/json" },
|
|
31
|
+
body: JSON.stringify({
|
|
32
|
+
agentIdRef: npcId,
|
|
33
|
+
persona: _soul.persona,
|
|
34
|
+
npcState: _soul.state
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
throw new Error(`Soul export failed: ${response.statusText}`);
|
|
39
|
+
}
|
|
40
|
+
const data = await response.json();
|
|
41
|
+
return {
|
|
42
|
+
txId: data.txId,
|
|
43
|
+
url: data.url,
|
|
44
|
+
soul: _soul
|
|
45
|
+
// Return the local soul data as context
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
var importSoulFromArweave = async (txId, config = {}) => {
|
|
49
|
+
const apiUrl = config.apiUrl || "https://api.forboc.ai";
|
|
50
|
+
const response = await fetch(`${apiUrl}/souls/${txId}`);
|
|
51
|
+
if (!response.ok) throw new Error(`Import failed: ${response.statusText}`);
|
|
52
|
+
const data = await response.json();
|
|
53
|
+
return data;
|
|
54
|
+
};
|
|
55
|
+
var getSoulList = async (limit = 50, apiUrl = "https://api.forboc.ai") => {
|
|
56
|
+
const response = await fetch(`${apiUrl}/souls?limit=${limit}`);
|
|
57
|
+
if (!response.ok) return [];
|
|
58
|
+
const data = await response.json();
|
|
59
|
+
return data.souls || [];
|
|
60
|
+
};
|
|
61
|
+
var createSoulInstance = (id, name, persona, state, memories = []) => {
|
|
62
|
+
const soulData = createSoul(id, name, persona, state, memories);
|
|
63
|
+
return {
|
|
64
|
+
export: (config) => exportSoul(id, soulData, config),
|
|
65
|
+
toJSON: () => ({ ...soulData })
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
var validateSoul = (soul) => {
|
|
69
|
+
const errors = [
|
|
70
|
+
!soul.id && "Missing id",
|
|
71
|
+
!soul.persona && "Missing persona",
|
|
72
|
+
!soul.state && "Missing state"
|
|
73
|
+
].filter((e) => !!e);
|
|
74
|
+
return { valid: errors.length === 0, errors };
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
createSoul,
|
|
79
|
+
serializeSoul,
|
|
80
|
+
deserializeSoul,
|
|
81
|
+
exportSoul,
|
|
82
|
+
importSoulFromArweave,
|
|
83
|
+
getSoulList,
|
|
84
|
+
createSoulInstance,
|
|
85
|
+
validateSoul
|
|
86
|
+
};
|