@forbocai/core 0.6.2 → 0.6.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.d.mts +2056 -1473
- package/dist/index.d.ts +2056 -1473
- package/dist/index.js +961 -560
- package/dist/index.mjs +927 -557
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -20,10 +20,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
|
|
23
|
+
DEFAULT_API_URL: () => DEFAULT_API_URL,
|
|
24
|
+
PRODUCTION_API_URL: () => PRODUCTION_API_URL,
|
|
25
|
+
VERSION: () => VERSION,
|
|
26
|
+
_: () => _,
|
|
24
27
|
addToHistory: () => addToHistory,
|
|
28
|
+
api: () => api,
|
|
25
29
|
blockAction: () => blockAction,
|
|
26
30
|
bridgeSlice: () => bridgeSlice,
|
|
31
|
+
checkApiConnectivity: () => checkApiConnectivity,
|
|
27
32
|
checkApiStatusThunk: () => checkApiStatusThunk,
|
|
28
33
|
clearBlock: () => clearBlock,
|
|
29
34
|
clearBridgeValidation: () => clearBridgeValidation,
|
|
@@ -32,13 +37,17 @@ __export(index_exports, {
|
|
|
32
37
|
clearMemoryRemoteThunk: () => clearMemoryRemoteThunk,
|
|
33
38
|
clearSoulState: () => clearSoulState,
|
|
34
39
|
completeRemoteThunk: () => completeRemoteThunk,
|
|
40
|
+
compose: () => compose,
|
|
35
41
|
contextComposed: () => contextComposed,
|
|
36
42
|
cortexInitFailed: () => cortexInitFailed,
|
|
37
43
|
cortexInitStart: () => cortexInitStart,
|
|
38
44
|
cortexInitSuccess: () => cortexInitSuccess,
|
|
39
45
|
cortexSlice: () => cortexSlice,
|
|
46
|
+
createDispatcher: () => createDispatcher,
|
|
40
47
|
createInitialState: () => createInitialState,
|
|
41
|
-
|
|
48
|
+
createRuntimeRegistry: () => createRuntimeRegistry,
|
|
49
|
+
createRuntimeStore: () => createRuntimeStore,
|
|
50
|
+
curry: () => curry,
|
|
42
51
|
delay: () => delay,
|
|
43
52
|
deleteRulesetThunk: () => deleteRulesetThunk,
|
|
44
53
|
directiveReceived: () => directiveReceived,
|
|
@@ -46,7 +55,12 @@ __export(index_exports, {
|
|
|
46
55
|
directiveRunStarted: () => directiveRunStarted,
|
|
47
56
|
directiveSlice: () => directiveSlice,
|
|
48
57
|
dispatch: () => dispatch,
|
|
58
|
+
ebind: () => ebind,
|
|
59
|
+
efmap: () => efmap,
|
|
60
|
+
ematch: () => ematch,
|
|
49
61
|
exportToSoul: () => exportToSoul,
|
|
62
|
+
fmap: () => fmap,
|
|
63
|
+
fromNullable: () => fromNullable,
|
|
50
64
|
generateNPCId: () => generateNPCId,
|
|
51
65
|
getBridgeRulesThunk: () => getBridgeRulesThunk,
|
|
52
66
|
getGhostHistoryThunk: () => getGhostHistoryThunk,
|
|
@@ -54,15 +68,25 @@ __export(index_exports, {
|
|
|
54
68
|
getGhostStatusThunk: () => getGhostStatusThunk,
|
|
55
69
|
getSoulListThunk: () => getSoulListThunk,
|
|
56
70
|
ghostSlice: () => ghostSlice,
|
|
71
|
+
handler_ArweaveDownload: () => handler_ArweaveDownload,
|
|
72
|
+
handler_ArweaveUpload: () => handler_ArweaveUpload,
|
|
57
73
|
importNpcFromSoulThunk: () => importNpcFromSoulThunk,
|
|
58
74
|
importSoulFromArweaveThunk: () => importSoulFromArweaveThunk,
|
|
59
75
|
initRemoteCortexThunk: () => initRemoteCortexThunk,
|
|
76
|
+
isJust: () => isJust,
|
|
77
|
+
isLeft: () => isLeft,
|
|
78
|
+
isNothing: () => isNothing,
|
|
79
|
+
isRight: () => isRight,
|
|
80
|
+
just: () => just,
|
|
81
|
+
left: () => left,
|
|
60
82
|
listCortexModelsThunk: () => listCortexModelsThunk,
|
|
61
83
|
listMemoryRemoteThunk: () => listMemoryRemoteThunk,
|
|
62
84
|
listRulePresetsThunk: () => listRulePresetsThunk,
|
|
63
85
|
listRulesetsThunk: () => listRulesetsThunk,
|
|
64
86
|
loadBridgePresetThunk: () => loadBridgePresetThunk,
|
|
65
87
|
localExportSoulThunk: () => localExportSoulThunk,
|
|
88
|
+
match: () => match,
|
|
89
|
+
mbind: () => mbind,
|
|
66
90
|
memoise: () => memoise,
|
|
67
91
|
memoiseAsync: () => memoiseAsync,
|
|
68
92
|
memoryClear: () => memoryClear,
|
|
@@ -73,14 +97,21 @@ __export(index_exports, {
|
|
|
73
97
|
memoryStoreFailed: () => memoryStoreFailed,
|
|
74
98
|
memoryStoreStart: () => memoryStoreStart,
|
|
75
99
|
memoryStoreSuccess: () => memoryStoreSuccess,
|
|
100
|
+
multiMatch: () => multiMatch,
|
|
101
|
+
nothing: () => nothing,
|
|
76
102
|
npcSlice: () => npcSlice,
|
|
103
|
+
orElse: () => orElse,
|
|
77
104
|
pipe: () => pipe,
|
|
78
105
|
processNPC: () => processNPC,
|
|
79
106
|
recallMemoryRemoteThunk: () => recallMemoryRemoteThunk,
|
|
80
107
|
registerRulesetThunk: () => registerRulesetThunk,
|
|
81
108
|
remoteExportSoulThunk: () => remoteExportSoulThunk,
|
|
82
109
|
removeNPC: () => removeNPC,
|
|
83
|
-
|
|
110
|
+
requireJust: () => requireJust,
|
|
111
|
+
resolveApiUrl: () => resolveApiUrl,
|
|
112
|
+
resolveApiUrlWithFallback: () => resolveApiUrlWithFallback,
|
|
113
|
+
resolveReachableApiUrl: () => resolveReachableApiUrl,
|
|
114
|
+
right: () => right,
|
|
84
115
|
selectActiveDirective: () => selectActiveDirective,
|
|
85
116
|
selectActiveDirectiveId: () => selectActiveDirectiveId,
|
|
86
117
|
selectActiveNPC: () => selectActiveNPC,
|
|
@@ -138,320 +169,461 @@ var import_toolkit = require("@reduxjs/toolkit");
|
|
|
138
169
|
|
|
139
170
|
// src/apiSlice.ts
|
|
140
171
|
var import_query = require("@reduxjs/toolkit/query");
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
172
|
+
|
|
173
|
+
// src/api/endpoints/arweave.ts
|
|
174
|
+
var buildArweaveEndpoints = (builder) => ({
|
|
175
|
+
postArweaveUpload: builder.mutation({
|
|
176
|
+
queryFn: async (instruction) => {
|
|
177
|
+
const maxRetries = instruction.maxRetries ?? 3;
|
|
178
|
+
const headers = {
|
|
179
|
+
"Content-Type": instruction.auiContentType || "application/json"
|
|
180
|
+
};
|
|
181
|
+
const walletToken = typeof globalThis !== "undefined" ? globalThis.process?.env?.ARWEAVE_WALLET_JWK ?? null : null;
|
|
182
|
+
const authToken = instruction.auiAuthHeader ?? (walletToken ? `Bearer ${walletToken}` : null);
|
|
183
|
+
if (authToken) headers.Authorization = authToken;
|
|
184
|
+
const attempt = async (n) => {
|
|
185
|
+
try {
|
|
186
|
+
const controller = new AbortController();
|
|
187
|
+
const timeout = setTimeout(() => controller.abort(), 6e4);
|
|
188
|
+
const response = await fetch(instruction.auiEndpoint, {
|
|
189
|
+
method: "POST",
|
|
190
|
+
headers,
|
|
191
|
+
body: JSON.stringify(instruction.auiPayload),
|
|
192
|
+
signal: controller.signal
|
|
193
|
+
});
|
|
194
|
+
clearTimeout(timeout);
|
|
195
|
+
const responseBody = await response.json().catch(() => null);
|
|
196
|
+
const txId = responseBody?.id ?? `ar_tx_sdk_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
|
197
|
+
const success = response.status >= 200 && response.status < 300;
|
|
198
|
+
return !success && n + 1 < maxRetries ? new Promise((resolve) => setTimeout(() => resolve(attempt(n + 1)), 250 * 2 ** n)) : {
|
|
199
|
+
data: {
|
|
200
|
+
aurTxId: txId,
|
|
201
|
+
aurStatus: response.status,
|
|
202
|
+
aurSuccess: success,
|
|
203
|
+
aurError: success ? null : `upload_failed_status_${response.status}`
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
} catch (error) {
|
|
207
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
208
|
+
return n + 1 < maxRetries ? new Promise((resolve) => setTimeout(() => resolve(attempt(n + 1)), 250 * 2 ** n)) : {
|
|
209
|
+
data: {
|
|
210
|
+
aurTxId: `ar_tx_failed_${Date.now()}`,
|
|
211
|
+
aurStatus: 0,
|
|
212
|
+
aurSuccess: false,
|
|
213
|
+
aurError: `upload_request_failed:${message}`
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
return attempt(0);
|
|
219
|
+
},
|
|
220
|
+
invalidatesTags: ["Soul"]
|
|
148
221
|
}),
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
|
|
222
|
+
postArweaveDownload: builder.mutation({
|
|
223
|
+
queryFn: async (instruction) => {
|
|
224
|
+
try {
|
|
225
|
+
const controller = new AbortController();
|
|
226
|
+
const timeout = setTimeout(() => controller.abort(), 6e4);
|
|
227
|
+
const response = await fetch(instruction.adiGatewayUrl, { method: "GET", signal: controller.signal });
|
|
228
|
+
clearTimeout(timeout);
|
|
229
|
+
return response.status < 200 || response.status >= 300 ? { data: { adrBody: null, adrStatus: response.status, adrSuccess: false, adrError: `download_failed_status_${response.status}` } } : response.json().then((body) => ({ data: { adrBody: body, adrStatus: response.status, adrSuccess: true, adrError: null } })).catch(() => ({ data: { adrBody: null, adrStatus: response.status, adrSuccess: false, adrError: "download_invalid_json" } }));
|
|
230
|
+
} catch (error) {
|
|
231
|
+
return {
|
|
232
|
+
data: {
|
|
233
|
+
adrBody: null,
|
|
234
|
+
adrStatus: 0,
|
|
235
|
+
adrSuccess: false,
|
|
236
|
+
adrError: error instanceof Error ? error.message : String(error)
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
invalidatesTags: ["Soul"]
|
|
242
|
+
})
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// src/api/endpoints/builder.ts
|
|
246
|
+
var authHeaders = (apiKey) => apiKey ? { Authorization: `Bearer ${apiKey}` } : {};
|
|
247
|
+
|
|
248
|
+
// src/api/endpoints/cortex.ts
|
|
249
|
+
var buildCortexEndpoints = (builder) => ({
|
|
250
|
+
getCortexModels: builder.query({
|
|
251
|
+
query: ({ apiUrl, apiKey }) => ({
|
|
252
|
+
url: `${apiUrl}/cortex/models`,
|
|
253
|
+
method: "GET",
|
|
254
|
+
headers: authHeaders(apiKey)
|
|
160
255
|
}),
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
256
|
+
providesTags: ["Cortex"],
|
|
257
|
+
transformResponse: (response) => response || []
|
|
258
|
+
}),
|
|
259
|
+
postCortexInit: builder.mutation({
|
|
260
|
+
query: ({ request, apiUrl, apiKey }) => ({
|
|
261
|
+
url: `${apiUrl}/cortex/init`,
|
|
262
|
+
method: "POST",
|
|
263
|
+
headers: authHeaders(apiKey),
|
|
264
|
+
body: request
|
|
170
265
|
}),
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
method: "POST",
|
|
181
|
-
headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {},
|
|
182
|
-
body: request
|
|
183
|
-
}),
|
|
184
|
-
invalidatesTags: (result, error, { npcId }) => [{ type: "NPC", id: npcId }],
|
|
185
|
-
transformResponse: (response) => response
|
|
266
|
+
invalidatesTags: ["Cortex"],
|
|
267
|
+
transformResponse: (response) => response
|
|
268
|
+
}),
|
|
269
|
+
postCortexComplete: builder.mutation({
|
|
270
|
+
query: ({ cortexId, prompt, options, apiUrl, apiKey }) => ({
|
|
271
|
+
url: `${apiUrl}/cortex/${cortexId}/complete`,
|
|
272
|
+
method: "POST",
|
|
273
|
+
headers: authHeaders(apiKey),
|
|
274
|
+
body: { prompt, ...options }
|
|
186
275
|
}),
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
276
|
+
invalidatesTags: ["Cortex"],
|
|
277
|
+
transformResponse: (response) => response
|
|
278
|
+
})
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
// src/api/endpoints/ghost.ts
|
|
282
|
+
var ghostTag = (sessionId) => [{ type: "Ghost", id: sessionId }];
|
|
283
|
+
var buildGhostEndpoints = (builder) => ({
|
|
284
|
+
postGhostRun: builder.mutation({
|
|
285
|
+
query: ({ request, apiUrl, apiKey }) => ({
|
|
286
|
+
url: `${apiUrl}/ghost/run`,
|
|
287
|
+
method: "POST",
|
|
288
|
+
headers: authHeaders(apiKey),
|
|
289
|
+
body: request
|
|
196
290
|
}),
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
transformResponse: (response) => response
|
|
291
|
+
invalidatesTags: ["Ghost"],
|
|
292
|
+
transformResponse: (response) => response
|
|
293
|
+
}),
|
|
294
|
+
getGhostStatus: builder.query({
|
|
295
|
+
query: ({ sessionId, apiUrl, apiKey }) => ({
|
|
296
|
+
url: `${apiUrl}/ghost/${sessionId}/status`,
|
|
297
|
+
method: "GET",
|
|
298
|
+
headers: authHeaders(apiKey)
|
|
206
299
|
}),
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
transformResponse: (response) => {
|
|
216
|
-
const action = response.action ? {
|
|
217
|
-
type: response.action.gaType || response.action.type,
|
|
218
|
-
reason: response.action.actionReason || response.action.reason,
|
|
219
|
-
target: response.action.actionTarget || response.action.target,
|
|
220
|
-
signature: response.action.signature
|
|
221
|
-
} : void 0;
|
|
222
|
-
return {
|
|
223
|
-
...response,
|
|
224
|
-
action
|
|
225
|
-
};
|
|
226
|
-
}
|
|
300
|
+
providesTags: (_result, _error, { sessionId }) => ghostTag(sessionId),
|
|
301
|
+
transformResponse: (response) => response
|
|
302
|
+
}),
|
|
303
|
+
getGhostResults: builder.query({
|
|
304
|
+
query: ({ sessionId, apiUrl, apiKey }) => ({
|
|
305
|
+
url: `${apiUrl}/ghost/${sessionId}/results`,
|
|
306
|
+
method: "GET",
|
|
307
|
+
headers: authHeaders(apiKey)
|
|
227
308
|
}),
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
transformResponse: (response) => response
|
|
309
|
+
providesTags: (_result, _error, { sessionId }) => ghostTag(sessionId),
|
|
310
|
+
transformResponse: (response) => response
|
|
311
|
+
}),
|
|
312
|
+
postGhostStop: builder.mutation({
|
|
313
|
+
query: ({ sessionId, apiUrl, apiKey }) => ({
|
|
314
|
+
url: `${apiUrl}/ghost/${sessionId}/stop`,
|
|
315
|
+
method: "POST",
|
|
316
|
+
headers: authHeaders(apiKey)
|
|
237
317
|
}),
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
318
|
+
invalidatesTags: (_result, _error, { sessionId }) => ghostTag(sessionId),
|
|
319
|
+
transformResponse: (response) => ({
|
|
320
|
+
stopped: response?.stopStatus === "stopped",
|
|
321
|
+
stopStatus: response?.stopStatus,
|
|
322
|
+
stopSessionId: response?.stopSessionId
|
|
323
|
+
})
|
|
324
|
+
}),
|
|
325
|
+
getGhostHistory: builder.query({
|
|
326
|
+
query: ({ limit, apiUrl, apiKey }) => ({
|
|
327
|
+
url: `${apiUrl}/ghost/history?limit=${limit}`,
|
|
328
|
+
method: "GET",
|
|
329
|
+
headers: authHeaders(apiKey)
|
|
246
330
|
}),
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
331
|
+
providesTags: ["Ghost"],
|
|
332
|
+
transformResponse: (response) => response
|
|
333
|
+
})
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
// src/api/endpoints/npc.ts
|
|
337
|
+
var memoryTag = (npcId) => [{ type: "Memory", id: npcId }];
|
|
338
|
+
var npcTag = (npcId) => [{ type: "NPC", id: npcId }];
|
|
339
|
+
var buildNpcEndpoints = (builder) => ({
|
|
340
|
+
postNpcProcess: builder.mutation({
|
|
341
|
+
query: ({ npcId, request, apiUrl, apiKey }) => ({
|
|
342
|
+
url: `${apiUrl}/npcs/${npcId}/process`,
|
|
343
|
+
method: "POST",
|
|
344
|
+
headers: authHeaders(apiKey),
|
|
345
|
+
body: request
|
|
256
346
|
}),
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
|
|
347
|
+
invalidatesTags: (_result, _error, { npcId }) => npcTag(npcId),
|
|
348
|
+
transformResponse: (response) => response
|
|
349
|
+
}),
|
|
350
|
+
postDirective: builder.mutation({
|
|
351
|
+
query: ({ npcId, request, apiUrl, apiKey }) => ({
|
|
352
|
+
url: `${apiUrl}/npcs/${npcId}/directive`,
|
|
353
|
+
method: "POST",
|
|
354
|
+
headers: authHeaders(apiKey),
|
|
355
|
+
body: request
|
|
265
356
|
}),
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
transformResponse: (response) => response
|
|
357
|
+
invalidatesTags: ["NPC"],
|
|
358
|
+
transformResponse: (response) => response
|
|
359
|
+
}),
|
|
360
|
+
postContext: builder.mutation({
|
|
361
|
+
query: ({ npcId, request, apiUrl, apiKey }) => ({
|
|
362
|
+
url: `${apiUrl}/npcs/${npcId}/context`,
|
|
363
|
+
method: "POST",
|
|
364
|
+
headers: authHeaders(apiKey),
|
|
365
|
+
body: request
|
|
276
366
|
}),
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
|
|
367
|
+
invalidatesTags: (_result, _error, { npcId }) => npcTag(npcId),
|
|
368
|
+
transformResponse: (response) => response
|
|
369
|
+
}),
|
|
370
|
+
postVerdict: builder.mutation({
|
|
371
|
+
query: ({ npcId, request, apiUrl, apiKey }) => ({
|
|
372
|
+
url: `${apiUrl}/npcs/${npcId}/verdict`,
|
|
373
|
+
method: "POST",
|
|
374
|
+
headers: authHeaders(apiKey),
|
|
375
|
+
body: request
|
|
285
376
|
}),
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
377
|
+
invalidatesTags: (_result, _error, { npcId }) => npcTag(npcId),
|
|
378
|
+
transformResponse: (response) => {
|
|
379
|
+
const action = response.action ? {
|
|
380
|
+
type: response.action.gaType || response.action.type,
|
|
381
|
+
reason: response.action.actionReason || response.action.reason,
|
|
382
|
+
target: response.action.actionTarget || response.action.target,
|
|
383
|
+
signature: response.action.signature
|
|
384
|
+
} : void 0;
|
|
385
|
+
return {
|
|
386
|
+
...response,
|
|
387
|
+
action
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
}),
|
|
391
|
+
postMemoryStore: builder.mutation({
|
|
392
|
+
query: ({ npcId, request, apiUrl, apiKey }) => ({
|
|
393
|
+
url: `${apiUrl}/npcs/${npcId}/memory`,
|
|
394
|
+
method: "POST",
|
|
395
|
+
headers: authHeaders(apiKey),
|
|
396
|
+
body: request
|
|
294
397
|
}),
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
stopped: response?.stopStatus === "stopped",
|
|
304
|
-
stopStatus: response?.stopStatus,
|
|
305
|
-
stopSessionId: response?.stopSessionId
|
|
306
|
-
})
|
|
398
|
+
invalidatesTags: (_result, _error, { npcId }) => memoryTag(npcId),
|
|
399
|
+
transformResponse: (response) => response
|
|
400
|
+
}),
|
|
401
|
+
getMemoryList: builder.query({
|
|
402
|
+
query: ({ npcId, apiUrl, apiKey }) => ({
|
|
403
|
+
url: `${apiUrl}/npcs/${npcId}/memory`,
|
|
404
|
+
method: "GET",
|
|
405
|
+
headers: authHeaders(apiKey)
|
|
307
406
|
}),
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
|
|
407
|
+
providesTags: (_result, _error, { npcId }) => memoryTag(npcId),
|
|
408
|
+
transformResponse: (response) => response || []
|
|
409
|
+
}),
|
|
410
|
+
postMemoryRecall: builder.mutation({
|
|
411
|
+
query: ({ npcId, request, apiUrl, apiKey }) => ({
|
|
412
|
+
url: `${apiUrl}/npcs/${npcId}/memory/recall`,
|
|
413
|
+
method: "POST",
|
|
414
|
+
headers: authHeaders(apiKey),
|
|
415
|
+
body: request
|
|
316
416
|
}),
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
invalidatesTags: ["Soul"],
|
|
326
|
-
transformResponse: (response) => response
|
|
417
|
+
invalidatesTags: (_result, _error, { npcId }) => memoryTag(npcId),
|
|
418
|
+
transformResponse: (response) => response || []
|
|
419
|
+
}),
|
|
420
|
+
deleteMemoryClear: builder.mutation({
|
|
421
|
+
query: ({ npcId, apiUrl, apiKey }) => ({
|
|
422
|
+
url: `${apiUrl}/npcs/${npcId}/memory/clear`,
|
|
423
|
+
method: "DELETE",
|
|
424
|
+
headers: authHeaders(apiKey)
|
|
327
425
|
}),
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
426
|
+
invalidatesTags: (_result, _error, { npcId }) => memoryTag(npcId),
|
|
427
|
+
transformResponse: (response) => response
|
|
428
|
+
})
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
// src/api/endpoints/rules.ts
|
|
432
|
+
var buildBridgeAndRuleEndpoints = (builder) => ({
|
|
433
|
+
postBridgeValidate: builder.mutation({
|
|
434
|
+
query: ({ request, npcId, apiUrl, apiKey }) => ({
|
|
435
|
+
url: npcId ? `${apiUrl}/bridge/validate/${npcId}` : `${apiUrl}/bridge/validate`,
|
|
436
|
+
method: "POST",
|
|
437
|
+
headers: authHeaders(apiKey),
|
|
438
|
+
body: request
|
|
336
439
|
}),
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
|
|
440
|
+
invalidatesTags: ["Bridge"],
|
|
441
|
+
transformResponse: (response) => response.brResult || response
|
|
442
|
+
}),
|
|
443
|
+
getBridgeRules: builder.query({
|
|
444
|
+
query: ({ apiUrl, apiKey }) => ({
|
|
445
|
+
url: `${apiUrl}/bridge/rules`,
|
|
446
|
+
method: "GET",
|
|
447
|
+
headers: authHeaders(apiKey)
|
|
345
448
|
}),
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
invalidatesTags: ["Bridge"],
|
|
355
|
-
transformResponse: (response) => response.brResult || response
|
|
449
|
+
providesTags: ["Bridge"],
|
|
450
|
+
transformResponse: (response) => response
|
|
451
|
+
}),
|
|
452
|
+
postBridgePreset: builder.mutation({
|
|
453
|
+
query: ({ presetName, apiUrl, apiKey }) => ({
|
|
454
|
+
url: `${apiUrl}/rules/presets/${presetName}`,
|
|
455
|
+
method: "POST",
|
|
456
|
+
headers: authHeaders(apiKey)
|
|
356
457
|
}),
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
|
|
458
|
+
invalidatesTags: ["Bridge"],
|
|
459
|
+
transformResponse: (response) => response
|
|
460
|
+
}),
|
|
461
|
+
getRulesets: builder.query({
|
|
462
|
+
query: ({ apiUrl, apiKey }) => ({
|
|
463
|
+
url: `${apiUrl}/rules`,
|
|
464
|
+
method: "GET",
|
|
465
|
+
headers: authHeaders(apiKey)
|
|
365
466
|
}),
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
|
|
467
|
+
providesTags: ["Rule"],
|
|
468
|
+
transformResponse: (response) => response || []
|
|
469
|
+
}),
|
|
470
|
+
getRulePresets: builder.query({
|
|
471
|
+
query: ({ apiUrl, apiKey }) => ({
|
|
472
|
+
url: `${apiUrl}/rules/presets`,
|
|
473
|
+
method: "GET",
|
|
474
|
+
headers: authHeaders(apiKey)
|
|
374
475
|
}),
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
476
|
+
providesTags: ["Rule"],
|
|
477
|
+
transformResponse: (response) => response || []
|
|
478
|
+
}),
|
|
479
|
+
postRuleRegister: builder.mutation({
|
|
480
|
+
query: ({ request, apiUrl, apiKey }) => ({
|
|
481
|
+
url: `${apiUrl}/rules`,
|
|
482
|
+
method: "POST",
|
|
483
|
+
headers: authHeaders(apiKey),
|
|
484
|
+
body: request
|
|
384
485
|
}),
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
|
|
486
|
+
invalidatesTags: ["Rule"],
|
|
487
|
+
transformResponse: (response) => response
|
|
488
|
+
}),
|
|
489
|
+
deleteRule: builder.mutation({
|
|
490
|
+
query: ({ rulesetId, apiUrl, apiKey }) => ({
|
|
491
|
+
url: `${apiUrl}/rules/${rulesetId}`,
|
|
492
|
+
method: "DELETE",
|
|
493
|
+
headers: authHeaders(apiKey)
|
|
393
494
|
}),
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
495
|
+
invalidatesTags: ["Rule"],
|
|
496
|
+
transformResponse: (_response) => ({ deleted: true })
|
|
497
|
+
})
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
// src/api/endpoints/soul.ts
|
|
501
|
+
var soulTag = (id) => [{ type: "Soul", id }];
|
|
502
|
+
var buildSoulEndpoints = (builder) => ({
|
|
503
|
+
postSoulExport: builder.mutation({
|
|
504
|
+
query: ({ npcId, request, apiUrl, apiKey }) => ({
|
|
505
|
+
url: `${apiUrl}/npcs/${npcId}/soul/export`,
|
|
506
|
+
method: "POST",
|
|
507
|
+
headers: authHeaders(apiKey),
|
|
508
|
+
body: request
|
|
403
509
|
}),
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
|
|
510
|
+
invalidatesTags: ["Soul"],
|
|
511
|
+
transformResponse: (response) => response
|
|
512
|
+
}),
|
|
513
|
+
postSoulExportConfirm: builder.mutation({
|
|
514
|
+
query: ({ npcId, request, apiUrl, apiKey }) => ({
|
|
515
|
+
url: `${apiUrl}/npcs/${npcId}/soul/confirm`,
|
|
516
|
+
method: "POST",
|
|
517
|
+
headers: authHeaders(apiKey),
|
|
518
|
+
body: request
|
|
412
519
|
}),
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
transformResponse: (response) => ({
|
|
422
|
-
valid: response.verifyValid ?? response.valid ?? false,
|
|
423
|
-
reason: response.verifyReason ?? response.reason
|
|
424
|
-
})
|
|
520
|
+
invalidatesTags: ["Soul"],
|
|
521
|
+
transformResponse: (response) => response
|
|
522
|
+
}),
|
|
523
|
+
getSoulImport: builder.query({
|
|
524
|
+
query: ({ txId, apiUrl, apiKey }) => ({
|
|
525
|
+
url: `${apiUrl}/souls/${txId}`,
|
|
526
|
+
method: "GET",
|
|
527
|
+
headers: authHeaders(apiKey)
|
|
425
528
|
}),
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
transformResponse: (response) => response
|
|
529
|
+
providesTags: (_result, _error, { txId }) => soulTag(txId),
|
|
530
|
+
transformResponse: (response) => response
|
|
531
|
+
}),
|
|
532
|
+
getSouls: builder.query({
|
|
533
|
+
query: ({ limit, apiUrl, apiKey }) => ({
|
|
534
|
+
url: `${apiUrl}/souls?limit=${limit}`,
|
|
535
|
+
method: "GET",
|
|
536
|
+
headers: authHeaders(apiKey)
|
|
435
537
|
}),
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
invalidatesTags: ["Cortex"],
|
|
445
|
-
transformResponse: (response) => response
|
|
538
|
+
providesTags: ["Soul"],
|
|
539
|
+
transformResponse: (response) => response
|
|
540
|
+
}),
|
|
541
|
+
postSoulVerify: builder.mutation({
|
|
542
|
+
query: ({ txId, apiUrl, apiKey }) => ({
|
|
543
|
+
url: `${apiUrl}/souls/${txId}/verify`,
|
|
544
|
+
method: "POST",
|
|
545
|
+
headers: authHeaders(apiKey)
|
|
446
546
|
}),
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
547
|
+
invalidatesTags: ["Soul"],
|
|
548
|
+
transformResponse: (response) => ({
|
|
549
|
+
valid: response.verifyValid ?? response.valid ?? false,
|
|
550
|
+
reason: response.verifyReason ?? response.reason
|
|
451
551
|
})
|
|
552
|
+
}),
|
|
553
|
+
postNpcImport: builder.mutation({
|
|
554
|
+
query: ({ request, apiUrl, apiKey }) => ({
|
|
555
|
+
url: `${apiUrl}/npcs/import`,
|
|
556
|
+
method: "POST",
|
|
557
|
+
headers: authHeaders(apiKey),
|
|
558
|
+
body: request
|
|
559
|
+
}),
|
|
560
|
+
invalidatesTags: ["NPC"],
|
|
561
|
+
transformResponse: (response) => response
|
|
562
|
+
}),
|
|
563
|
+
postNpcImportConfirm: builder.mutation({
|
|
564
|
+
query: ({ request, apiUrl, apiKey }) => ({
|
|
565
|
+
url: `${apiUrl}/npcs/import/confirm`,
|
|
566
|
+
method: "POST",
|
|
567
|
+
headers: authHeaders(apiKey),
|
|
568
|
+
body: request
|
|
569
|
+
}),
|
|
570
|
+
invalidatesTags: ["NPC"],
|
|
571
|
+
transformResponse: (response) => response
|
|
572
|
+
})
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
// src/api/endpoints/system.ts
|
|
576
|
+
var buildSystemEndpoints = (builder) => ({
|
|
577
|
+
getApiStatus: builder.query({
|
|
578
|
+
query: ({ apiUrl }) => ({ url: `${apiUrl}/status`, method: "GET" }),
|
|
579
|
+
providesTags: ["NPC"],
|
|
580
|
+
transformResponse: (response) => response
|
|
581
|
+
})
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
// src/apiSlice.ts
|
|
585
|
+
var api = (0, import_query.createApi)({
|
|
586
|
+
reducerPath: "api",
|
|
587
|
+
baseQuery: (0, import_query.fetchBaseQuery)({
|
|
588
|
+
baseUrl: "/",
|
|
589
|
+
prepareHeaders: (headers, { getState }) => {
|
|
590
|
+
return headers;
|
|
591
|
+
}
|
|
592
|
+
}),
|
|
593
|
+
tagTypes: ["NPC", "Memory", "Cortex", "Ghost", "Soul", "Bridge", "Rule"],
|
|
594
|
+
endpoints: (builder) => ({
|
|
595
|
+
...buildCortexEndpoints(builder),
|
|
596
|
+
...buildNpcEndpoints(builder),
|
|
597
|
+
...buildGhostEndpoints(builder),
|
|
598
|
+
...buildSoulEndpoints(builder),
|
|
599
|
+
...buildBridgeAndRuleEndpoints(builder),
|
|
600
|
+
...buildArweaveEndpoints(builder),
|
|
601
|
+
...buildSystemEndpoints(builder)
|
|
452
602
|
})
|
|
453
603
|
});
|
|
454
604
|
|
|
605
|
+
// src/errors.ts
|
|
606
|
+
var DEFAULT_API_URL = "http://localhost:8080";
|
|
607
|
+
var PRODUCTION_API_URL = "https://api.forboc.ai";
|
|
608
|
+
var resolveApiUrl = (apiUrl) => apiUrl || DEFAULT_API_URL;
|
|
609
|
+
var extractThunkErrorMessage = (error, fallback) => {
|
|
610
|
+
if (typeof error === "string") return error;
|
|
611
|
+
if (error && typeof error === "object") {
|
|
612
|
+
const e = error;
|
|
613
|
+
if (typeof e.data === "object" && e.data?.message) return String(e.data.message);
|
|
614
|
+
if (typeof e.data === "string") return e.data;
|
|
615
|
+
if (e.message) return e.message;
|
|
616
|
+
if (e.error) return e.error;
|
|
617
|
+
}
|
|
618
|
+
return fallback;
|
|
619
|
+
};
|
|
620
|
+
var requireApiKeyGuidance = (apiUrl, apiKey) => {
|
|
621
|
+
const normalized = apiUrl.toLowerCase();
|
|
622
|
+
if (normalized.includes("api.forboc.ai") && !apiKey) {
|
|
623
|
+
throw new Error("Missing API key. Set FORBOCAI_API_KEY (or run `forboc config set apiKey <key>`) for production API calls.");
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
|
|
455
627
|
// src/bridgeSlice.ts
|
|
456
628
|
var initialState = {
|
|
457
629
|
activePresets: [],
|
|
@@ -465,16 +637,17 @@ var validateBridgeThunk = (0, import_toolkit.createAsyncThunk)(
|
|
|
465
637
|
"bridge/validate",
|
|
466
638
|
async ({ action, context, npcId, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
|
|
467
639
|
try {
|
|
468
|
-
const url = apiUrl
|
|
469
|
-
|
|
640
|
+
const url = resolveApiUrl(apiUrl);
|
|
641
|
+
requireApiKeyGuidance(url, apiKey);
|
|
642
|
+
const data = await dispatch2(api.endpoints.postBridgeValidate.initiate({
|
|
470
643
|
request: { action, context },
|
|
471
644
|
npcId,
|
|
472
645
|
apiUrl: url,
|
|
473
646
|
apiKey
|
|
474
647
|
})).unwrap();
|
|
475
648
|
return data;
|
|
476
|
-
} catch (
|
|
477
|
-
return rejectWithValue(
|
|
649
|
+
} catch (error) {
|
|
650
|
+
return rejectWithValue(extractThunkErrorMessage(error, "Bridge validation failed"));
|
|
478
651
|
}
|
|
479
652
|
}
|
|
480
653
|
);
|
|
@@ -482,10 +655,11 @@ var loadBridgePresetThunk = (0, import_toolkit.createAsyncThunk)(
|
|
|
482
655
|
"bridge/loadPreset",
|
|
483
656
|
async ({ presetName, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
|
|
484
657
|
try {
|
|
485
|
-
const url = apiUrl
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
658
|
+
const url = resolveApiUrl(apiUrl);
|
|
659
|
+
requireApiKeyGuidance(url, apiKey);
|
|
660
|
+
return await dispatch2(api.endpoints.postBridgePreset.initiate({ presetName, apiUrl: url, apiKey })).unwrap();
|
|
661
|
+
} catch (error) {
|
|
662
|
+
return rejectWithValue(extractThunkErrorMessage(error, "Failed to load preset"));
|
|
489
663
|
}
|
|
490
664
|
}
|
|
491
665
|
);
|
|
@@ -493,10 +667,11 @@ var getBridgeRulesThunk = (0, import_toolkit.createAsyncThunk)(
|
|
|
493
667
|
"bridge/rules",
|
|
494
668
|
async ({ apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
|
|
495
669
|
try {
|
|
496
|
-
const url = apiUrl
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
670
|
+
const url = resolveApiUrl(apiUrl);
|
|
671
|
+
requireApiKeyGuidance(url, apiKey);
|
|
672
|
+
return await dispatch2(api.endpoints.getBridgeRules.initiate({ apiUrl: url, apiKey })).unwrap();
|
|
673
|
+
} catch (error) {
|
|
674
|
+
return rejectWithValue(extractThunkErrorMessage(error, "Failed to list bridge rules"));
|
|
500
675
|
}
|
|
501
676
|
}
|
|
502
677
|
);
|
|
@@ -504,10 +679,11 @@ var listRulesetsThunk = (0, import_toolkit.createAsyncThunk)(
|
|
|
504
679
|
"bridge/listRulesets",
|
|
505
680
|
async ({ apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
|
|
506
681
|
try {
|
|
507
|
-
const url = apiUrl
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
682
|
+
const url = resolveApiUrl(apiUrl);
|
|
683
|
+
requireApiKeyGuidance(url, apiKey);
|
|
684
|
+
return await dispatch2(api.endpoints.getRulesets.initiate({ apiUrl: url, apiKey })).unwrap();
|
|
685
|
+
} catch (error) {
|
|
686
|
+
return rejectWithValue(extractThunkErrorMessage(error, "Failed to list rulesets"));
|
|
511
687
|
}
|
|
512
688
|
}
|
|
513
689
|
);
|
|
@@ -515,10 +691,11 @@ var listRulePresetsThunk = (0, import_toolkit.createAsyncThunk)(
|
|
|
515
691
|
"bridge/listRulePresets",
|
|
516
692
|
async ({ apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
|
|
517
693
|
try {
|
|
518
|
-
const url = apiUrl
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
694
|
+
const url = resolveApiUrl(apiUrl);
|
|
695
|
+
requireApiKeyGuidance(url, apiKey);
|
|
696
|
+
return await dispatch2(api.endpoints.getRulePresets.initiate({ apiUrl: url, apiKey })).unwrap();
|
|
697
|
+
} catch (error) {
|
|
698
|
+
return rejectWithValue(extractThunkErrorMessage(error, "Failed to list rule presets"));
|
|
522
699
|
}
|
|
523
700
|
}
|
|
524
701
|
);
|
|
@@ -526,10 +703,11 @@ var registerRulesetThunk = (0, import_toolkit.createAsyncThunk)(
|
|
|
526
703
|
"bridge/registerRuleset",
|
|
527
704
|
async ({ ruleset, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
|
|
528
705
|
try {
|
|
529
|
-
const url = apiUrl
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
706
|
+
const url = resolveApiUrl(apiUrl);
|
|
707
|
+
requireApiKeyGuidance(url, apiKey);
|
|
708
|
+
return await dispatch2(api.endpoints.postRuleRegister.initiate({ request: ruleset, apiUrl: url, apiKey })).unwrap();
|
|
709
|
+
} catch (error) {
|
|
710
|
+
return rejectWithValue(extractThunkErrorMessage(error, "Failed to register ruleset"));
|
|
533
711
|
}
|
|
534
712
|
}
|
|
535
713
|
);
|
|
@@ -537,10 +715,11 @@ var deleteRulesetThunk = (0, import_toolkit.createAsyncThunk)(
|
|
|
537
715
|
"bridge/deleteRuleset",
|
|
538
716
|
async ({ rulesetId, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
|
|
539
717
|
try {
|
|
540
|
-
const url = apiUrl
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
718
|
+
const url = resolveApiUrl(apiUrl);
|
|
719
|
+
requireApiKeyGuidance(url, apiKey);
|
|
720
|
+
return await dispatch2(api.endpoints.deleteRule.initiate({ rulesetId, apiUrl: url, apiKey })).unwrap();
|
|
721
|
+
} catch (error) {
|
|
722
|
+
return rejectWithValue(extractThunkErrorMessage(error, "Failed to delete ruleset"));
|
|
544
723
|
}
|
|
545
724
|
}
|
|
546
725
|
);
|
|
@@ -589,6 +768,85 @@ var bridgeSlice_default = bridgeSlice.reducer;
|
|
|
589
768
|
|
|
590
769
|
// src/soulSlice.ts
|
|
591
770
|
var import_toolkit2 = require("@reduxjs/toolkit");
|
|
771
|
+
|
|
772
|
+
// src/functional_core.ts
|
|
773
|
+
var just = (value) => ({
|
|
774
|
+
_tag: "Just",
|
|
775
|
+
map: (f) => just(f(value)),
|
|
776
|
+
chain: (f) => f(value),
|
|
777
|
+
getOrElse: (_defaultValue) => value,
|
|
778
|
+
match: (cases) => cases.just(value)
|
|
779
|
+
});
|
|
780
|
+
var nothing = () => ({
|
|
781
|
+
_tag: "Nothing",
|
|
782
|
+
map: (_f) => nothing(),
|
|
783
|
+
chain: (_f) => nothing(),
|
|
784
|
+
getOrElse: (defaultValue) => defaultValue,
|
|
785
|
+
match: (cases) => cases.nothing()
|
|
786
|
+
});
|
|
787
|
+
var fmap = (m, f) => m.map(f);
|
|
788
|
+
var mbind = (m, f) => m.chain(f);
|
|
789
|
+
var orElse = (m, defaultValue) => m.getOrElse(defaultValue);
|
|
790
|
+
var match = (m, onJust, onNothing) => m.match({ just: onJust, nothing: onNothing });
|
|
791
|
+
var isJust = (m) => m._tag === "Just";
|
|
792
|
+
var isNothing = (m) => m._tag === "Nothing";
|
|
793
|
+
var fromNullable = (value) => value != null ? just(value) : nothing();
|
|
794
|
+
var requireJust = (m, errorMsg) => m.match({
|
|
795
|
+
just: (v) => v,
|
|
796
|
+
nothing: () => {
|
|
797
|
+
throw new Error(errorMsg);
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
var left = (error) => ({
|
|
801
|
+
_tag: "Left",
|
|
802
|
+
map: (_f) => left(error),
|
|
803
|
+
chain: (_f) => left(error),
|
|
804
|
+
getOrElse: (defaultValue) => defaultValue,
|
|
805
|
+
match: (cases) => cases.left(error)
|
|
806
|
+
});
|
|
807
|
+
var right = (value) => ({
|
|
808
|
+
_tag: "Right",
|
|
809
|
+
map: (f) => right(f(value)),
|
|
810
|
+
chain: (f) => f(value),
|
|
811
|
+
getOrElse: (_defaultValue) => value,
|
|
812
|
+
match: (cases) => cases.right(value)
|
|
813
|
+
});
|
|
814
|
+
var efmap = (e, f) => e.map(f);
|
|
815
|
+
var ebind = (e, f) => e.chain(f);
|
|
816
|
+
var ematch = (e, onLeft, onRight) => e.match({ left: onLeft, right: onRight });
|
|
817
|
+
var isLeft = (e) => e._tag === "Left";
|
|
818
|
+
var isRight = (e) => e._tag === "Right";
|
|
819
|
+
function compose(...fns) {
|
|
820
|
+
return (...args) => {
|
|
821
|
+
const last = fns[fns.length - 1];
|
|
822
|
+
const rest = fns.slice(0, -1);
|
|
823
|
+
return rest.reduceRight((acc, fn) => fn(acc), last(...args));
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
function curry(fn) {
|
|
827
|
+
const arity = fn.length;
|
|
828
|
+
const curried = (...args) => args.length >= arity ? fn(...args) : (...moreArgs) => curried(...args, ...moreArgs);
|
|
829
|
+
return curried;
|
|
830
|
+
}
|
|
831
|
+
var createDispatcher = (entries) => {
|
|
832
|
+
const table = new Map(entries);
|
|
833
|
+
return {
|
|
834
|
+
dispatch: (key, ...args) => {
|
|
835
|
+
const handler = table.get(key);
|
|
836
|
+
return handler ? just(handler(...args)) : nothing();
|
|
837
|
+
},
|
|
838
|
+
has: (key) => table.has(key),
|
|
839
|
+
keys: () => [...table.keys()]
|
|
840
|
+
};
|
|
841
|
+
};
|
|
842
|
+
var _ = /* @__PURE__ */ Symbol.for("forbocai_wildcard");
|
|
843
|
+
var testCase = (value, predicate, handler) => predicate === _ ? just(handler(value)) : typeof predicate === "function" ? predicate(value) ? just(handler(value)) : nothing() : predicate === value ? just(handler(value)) : nothing();
|
|
844
|
+
var multiMatch = (value, cases) => cases.length === 0 ? nothing() : testCase(value, cases[0][0], cases[0][1]).match({
|
|
845
|
+
just: (v) => just(v),
|
|
846
|
+
nothing: () => multiMatch(value, cases.slice(1))
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
// src/soulSlice.ts
|
|
592
850
|
var initialState2 = {
|
|
593
851
|
exportStatus: "idle",
|
|
594
852
|
importStatus: "idle",
|
|
@@ -599,26 +857,46 @@ var initialState2 = {
|
|
|
599
857
|
};
|
|
600
858
|
var remoteExportSoulThunk = (0, import_toolkit2.createAsyncThunk)(
|
|
601
859
|
"soul/export",
|
|
602
|
-
async ({ npcId: argNpcId, apiUrl, apiKey
|
|
860
|
+
async ({ npcId: argNpcId, apiUrl, apiKey }, { getState, dispatch: dispatch2, rejectWithValue }) => {
|
|
603
861
|
try {
|
|
604
862
|
const state = getState().npc;
|
|
605
863
|
const npcId = argNpcId || state.activeNpcId;
|
|
606
|
-
const npc = state.entities[npcId];
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
const
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
864
|
+
const npc = requireJust(fromNullable(state.entities[npcId]), `NPC ${npcId} not found`);
|
|
865
|
+
const url = resolveApiUrl(apiUrl);
|
|
866
|
+
requireApiKeyGuidance(url, apiKey);
|
|
867
|
+
const phase1 = await dispatch2(
|
|
868
|
+
api.endpoints.postSoulExport.initiate({
|
|
869
|
+
npcId,
|
|
870
|
+
request: { npcIdRef: npcId, persona: npc.persona || "NPC", npcState: npc.state },
|
|
871
|
+
apiUrl: url,
|
|
872
|
+
apiKey
|
|
873
|
+
})
|
|
874
|
+
).unwrap();
|
|
875
|
+
const uploadResult = await dispatch2(
|
|
876
|
+
api.endpoints.postArweaveUpload.initiate({
|
|
877
|
+
...phase1.se1Instruction,
|
|
878
|
+
auiAuthHeader: phase1.se1Instruction.auiAuthHeader ?? null
|
|
879
|
+
})
|
|
880
|
+
).unwrap();
|
|
881
|
+
const final = await dispatch2(
|
|
882
|
+
api.endpoints.postSoulExportConfirm.initiate({
|
|
883
|
+
npcId,
|
|
884
|
+
request: {
|
|
885
|
+
secUploadResult: uploadResult,
|
|
886
|
+
secSignedPayload: phase1.se1SignedPayload,
|
|
887
|
+
secSignature: phase1.se1Signature
|
|
888
|
+
},
|
|
889
|
+
apiUrl: url,
|
|
890
|
+
apiKey
|
|
891
|
+
})
|
|
892
|
+
).unwrap();
|
|
615
893
|
return {
|
|
616
|
-
txId:
|
|
617
|
-
url:
|
|
618
|
-
soul:
|
|
894
|
+
txId: final.txId,
|
|
895
|
+
url: final.arweaveUrl,
|
|
896
|
+
soul: final.soul
|
|
619
897
|
};
|
|
620
|
-
} catch (
|
|
621
|
-
return rejectWithValue(
|
|
898
|
+
} catch (error) {
|
|
899
|
+
return rejectWithValue(extractThunkErrorMessage(error, "Soul export failed"));
|
|
622
900
|
}
|
|
623
901
|
}
|
|
624
902
|
);
|
|
@@ -626,11 +904,34 @@ var importSoulFromArweaveThunk = (0, import_toolkit2.createAsyncThunk)(
|
|
|
626
904
|
"soul/import",
|
|
627
905
|
async ({ txId, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
|
|
628
906
|
try {
|
|
629
|
-
const url = apiUrl
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
907
|
+
const url = resolveApiUrl(apiUrl);
|
|
908
|
+
requireApiKeyGuidance(url, apiKey);
|
|
909
|
+
const phase1 = await dispatch2(
|
|
910
|
+
api.endpoints.postNpcImport.initiate({ request: { txIdRef: txId }, apiUrl: url, apiKey })
|
|
911
|
+
).unwrap();
|
|
912
|
+
const downloadResult = await dispatch2(
|
|
913
|
+
api.endpoints.postArweaveDownload.initiate(phase1.si1Instruction)
|
|
914
|
+
).unwrap();
|
|
915
|
+
const npc = await dispatch2(
|
|
916
|
+
api.endpoints.postNpcImportConfirm.initiate({
|
|
917
|
+
request: {
|
|
918
|
+
sicTxId: txId,
|
|
919
|
+
sicDownloadResult: downloadResult
|
|
920
|
+
},
|
|
921
|
+
apiUrl: url,
|
|
922
|
+
apiKey
|
|
923
|
+
})
|
|
924
|
+
).unwrap();
|
|
925
|
+
return {
|
|
926
|
+
id: txId,
|
|
927
|
+
version: "2.0.0",
|
|
928
|
+
name: npc.npcId,
|
|
929
|
+
persona: npc.persona,
|
|
930
|
+
memories: [],
|
|
931
|
+
state: npc.data || {}
|
|
932
|
+
};
|
|
933
|
+
} catch (error) {
|
|
934
|
+
return rejectWithValue(extractThunkErrorMessage(error, "Soul import failed"));
|
|
634
935
|
}
|
|
635
936
|
}
|
|
636
937
|
);
|
|
@@ -638,11 +939,12 @@ var getSoulListThunk = (0, import_toolkit2.createAsyncThunk)(
|
|
|
638
939
|
"soul/list",
|
|
639
940
|
async ({ limit = 50, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
|
|
640
941
|
try {
|
|
641
|
-
const url = apiUrl
|
|
642
|
-
|
|
942
|
+
const url = resolveApiUrl(apiUrl);
|
|
943
|
+
requireApiKeyGuidance(url, apiKey);
|
|
944
|
+
const data = await dispatch2(api.endpoints.getSouls.initiate({ limit, apiUrl: url, apiKey })).unwrap();
|
|
643
945
|
return data.souls || [];
|
|
644
|
-
} catch (
|
|
645
|
-
return rejectWithValue(
|
|
946
|
+
} catch (error) {
|
|
947
|
+
return rejectWithValue(extractThunkErrorMessage(error, "Failed to list souls"));
|
|
646
948
|
}
|
|
647
949
|
}
|
|
648
950
|
);
|
|
@@ -650,10 +952,11 @@ var verifySoulThunk = (0, import_toolkit2.createAsyncThunk)(
|
|
|
650
952
|
"soul/verify",
|
|
651
953
|
async ({ txId, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
|
|
652
954
|
try {
|
|
653
|
-
const url = apiUrl
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
955
|
+
const url = resolveApiUrl(apiUrl);
|
|
956
|
+
requireApiKeyGuidance(url, apiKey);
|
|
957
|
+
return await dispatch2(api.endpoints.postSoulVerify.initiate({ txId, apiUrl: url, apiKey })).unwrap();
|
|
958
|
+
} catch (error) {
|
|
959
|
+
return rejectWithValue(extractThunkErrorMessage(error, "Soul verify failed"));
|
|
657
960
|
}
|
|
658
961
|
}
|
|
659
962
|
);
|
|
@@ -661,14 +964,27 @@ var importNpcFromSoulThunk = (0, import_toolkit2.createAsyncThunk)(
|
|
|
661
964
|
"soul/importNpc",
|
|
662
965
|
async ({ txId, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
|
|
663
966
|
try {
|
|
664
|
-
const url = apiUrl
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
967
|
+
const url = resolveApiUrl(apiUrl);
|
|
968
|
+
requireApiKeyGuidance(url, apiKey);
|
|
969
|
+
const phase1 = await dispatch2(
|
|
970
|
+
api.endpoints.postNpcImport.initiate({
|
|
971
|
+
request: { txIdRef: txId },
|
|
972
|
+
apiUrl: url,
|
|
973
|
+
apiKey
|
|
974
|
+
})
|
|
975
|
+
).unwrap();
|
|
976
|
+
const downloadResult = await dispatch2(
|
|
977
|
+
api.endpoints.postArweaveDownload.initiate(phase1.si1Instruction)
|
|
978
|
+
).unwrap();
|
|
979
|
+
return await dispatch2(
|
|
980
|
+
api.endpoints.postNpcImportConfirm.initiate({
|
|
981
|
+
request: { sicTxId: txId, sicDownloadResult: downloadResult },
|
|
982
|
+
apiUrl: url,
|
|
983
|
+
apiKey
|
|
984
|
+
})
|
|
985
|
+
).unwrap();
|
|
986
|
+
} catch (error) {
|
|
987
|
+
return rejectWithValue(extractThunkErrorMessage(error, "NPC import from soul failed"));
|
|
672
988
|
}
|
|
673
989
|
}
|
|
674
990
|
);
|
|
@@ -726,8 +1042,9 @@ var startGhostThunk = (0, import_toolkit3.createAsyncThunk)(
|
|
|
726
1042
|
"ghost/start",
|
|
727
1043
|
async (config, { dispatch: dispatch2, rejectWithValue }) => {
|
|
728
1044
|
try {
|
|
729
|
-
const apiUrl = config.apiUrl
|
|
730
|
-
|
|
1045
|
+
const apiUrl = resolveApiUrl(config.apiUrl);
|
|
1046
|
+
requireApiKeyGuidance(apiUrl, config.apiKey);
|
|
1047
|
+
const data = await dispatch2(api.endpoints.postGhostRun.initiate({
|
|
731
1048
|
request: { testSuite: config.testSuite, duration: config.duration ?? 300 },
|
|
732
1049
|
apiUrl,
|
|
733
1050
|
apiKey: config.apiKey
|
|
@@ -736,8 +1053,8 @@ var startGhostThunk = (0, import_toolkit3.createAsyncThunk)(
|
|
|
736
1053
|
sessionId: data.sessionId,
|
|
737
1054
|
status: data.runStatus
|
|
738
1055
|
};
|
|
739
|
-
} catch (
|
|
740
|
-
return rejectWithValue(
|
|
1056
|
+
} catch (error) {
|
|
1057
|
+
return rejectWithValue(extractThunkErrorMessage(error, "Failed to start Ghost"));
|
|
741
1058
|
}
|
|
742
1059
|
}
|
|
743
1060
|
);
|
|
@@ -746,10 +1063,10 @@ var getGhostStatusThunk = (0, import_toolkit3.createAsyncThunk)(
|
|
|
746
1063
|
async ({ sessionId, apiUrl, apiKey }, { dispatch: dispatch2, getState, rejectWithValue }) => {
|
|
747
1064
|
try {
|
|
748
1065
|
const state = getState().ghost;
|
|
749
|
-
const targetSession = sessionId || state.activeSessionId;
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
const data = await dispatch2(
|
|
1066
|
+
const targetSession = requireJust(fromNullable(sessionId || state.activeSessionId), "No active Ghost session");
|
|
1067
|
+
const url = resolveApiUrl(apiUrl);
|
|
1068
|
+
requireApiKeyGuidance(url, apiKey);
|
|
1069
|
+
const data = await dispatch2(api.endpoints.getGhostStatus.initiate({ sessionId: targetSession, apiUrl: url, apiKey })).unwrap();
|
|
753
1070
|
return {
|
|
754
1071
|
sessionId: data.ghostSessionId,
|
|
755
1072
|
status: data.ghostStatus,
|
|
@@ -758,8 +1075,8 @@ var getGhostStatusThunk = (0, import_toolkit3.createAsyncThunk)(
|
|
|
758
1075
|
duration: data.ghostDuration || 0,
|
|
759
1076
|
errors: data.ghostErrors
|
|
760
1077
|
};
|
|
761
|
-
} catch (
|
|
762
|
-
return rejectWithValue(
|
|
1078
|
+
} catch (error) {
|
|
1079
|
+
return rejectWithValue(extractThunkErrorMessage(error, "Failed to get ghost status"));
|
|
763
1080
|
}
|
|
764
1081
|
}
|
|
765
1082
|
);
|
|
@@ -768,10 +1085,10 @@ var getGhostResultsThunk = (0, import_toolkit3.createAsyncThunk)(
|
|
|
768
1085
|
async ({ sessionId, apiUrl, apiKey }, { dispatch: dispatch2, getState, rejectWithValue }) => {
|
|
769
1086
|
try {
|
|
770
1087
|
const state = getState().ghost;
|
|
771
|
-
const targetSession = sessionId || state.activeSessionId;
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
const data = await dispatch2(
|
|
1088
|
+
const targetSession = requireJust(fromNullable(sessionId || state.activeSessionId), "No active Ghost session");
|
|
1089
|
+
const url = resolveApiUrl(apiUrl);
|
|
1090
|
+
requireApiKeyGuidance(url, apiKey);
|
|
1091
|
+
const data = await dispatch2(api.endpoints.getGhostResults.initiate({ sessionId: targetSession, apiUrl: url, apiKey })).unwrap();
|
|
775
1092
|
return {
|
|
776
1093
|
sessionId: data.resultsSessionId,
|
|
777
1094
|
totalTests: data.resultsTotalTests,
|
|
@@ -789,8 +1106,8 @@ var getGhostResultsThunk = (0, import_toolkit3.createAsyncThunk)(
|
|
|
789
1106
|
coverage: data.resultsCoverage,
|
|
790
1107
|
metrics: Object.fromEntries(data.resultsMetrics || [])
|
|
791
1108
|
};
|
|
792
|
-
} catch (
|
|
793
|
-
return rejectWithValue(
|
|
1109
|
+
} catch (error) {
|
|
1110
|
+
return rejectWithValue(extractThunkErrorMessage(error, "Failed to get ghost results"));
|
|
794
1111
|
}
|
|
795
1112
|
}
|
|
796
1113
|
);
|
|
@@ -799,17 +1116,17 @@ var stopGhostThunk = (0, import_toolkit3.createAsyncThunk)(
|
|
|
799
1116
|
async ({ sessionId, apiUrl, apiKey }, { dispatch: dispatch2, getState, rejectWithValue }) => {
|
|
800
1117
|
try {
|
|
801
1118
|
const state = getState().ghost;
|
|
802
|
-
const targetSession = sessionId || state.activeSessionId;
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
const data = await dispatch2(
|
|
1119
|
+
const targetSession = requireJust(fromNullable(sessionId || state.activeSessionId), "No active Ghost session");
|
|
1120
|
+
const url = resolveApiUrl(apiUrl);
|
|
1121
|
+
requireApiKeyGuidance(url, apiKey);
|
|
1122
|
+
const data = await dispatch2(api.endpoints.postGhostStop.initiate({ sessionId: targetSession, apiUrl: url, apiKey })).unwrap();
|
|
806
1123
|
return {
|
|
807
1124
|
stopped: data.stopped,
|
|
808
1125
|
status: data.stopStatus,
|
|
809
1126
|
sessionId: data.stopSessionId
|
|
810
1127
|
};
|
|
811
|
-
} catch (
|
|
812
|
-
return rejectWithValue(
|
|
1128
|
+
} catch (error) {
|
|
1129
|
+
return rejectWithValue(extractThunkErrorMessage(error, "Failed to stop ghost session"));
|
|
813
1130
|
}
|
|
814
1131
|
}
|
|
815
1132
|
);
|
|
@@ -817,8 +1134,9 @@ var getGhostHistoryThunk = (0, import_toolkit3.createAsyncThunk)(
|
|
|
817
1134
|
"ghost/history",
|
|
818
1135
|
async ({ limit = 10, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
|
|
819
1136
|
try {
|
|
820
|
-
const url = apiUrl
|
|
821
|
-
|
|
1137
|
+
const url = resolveApiUrl(apiUrl);
|
|
1138
|
+
requireApiKeyGuidance(url, apiKey);
|
|
1139
|
+
const data = await dispatch2(api.endpoints.getGhostHistory.initiate({ limit, apiUrl: url, apiKey })).unwrap();
|
|
822
1140
|
return (data.sessions || []).map((s) => ({
|
|
823
1141
|
sessionId: s.sessionId,
|
|
824
1142
|
testSuite: s.testSuite,
|
|
@@ -827,8 +1145,8 @@ var getGhostHistoryThunk = (0, import_toolkit3.createAsyncThunk)(
|
|
|
827
1145
|
status: s.status,
|
|
828
1146
|
passRate: s.passRate
|
|
829
1147
|
}));
|
|
830
|
-
} catch (
|
|
831
|
-
return rejectWithValue(
|
|
1148
|
+
} catch (error) {
|
|
1149
|
+
return rejectWithValue(extractThunkErrorMessage(error, "Failed to get ghost history"));
|
|
832
1150
|
}
|
|
833
1151
|
}
|
|
834
1152
|
);
|
|
@@ -863,7 +1181,7 @@ var ghostSlice = (0, import_toolkit3.createSlice)({
|
|
|
863
1181
|
state.status = "completed";
|
|
864
1182
|
}).addCase(stopGhostThunk.fulfilled, (state, action) => {
|
|
865
1183
|
if (action.payload.stopped) {
|
|
866
|
-
state.status = "
|
|
1184
|
+
state.status = "completed";
|
|
867
1185
|
} else {
|
|
868
1186
|
state.error = action.payload.status || "Ghost stop request did not stop a session";
|
|
869
1187
|
}
|
|
@@ -877,8 +1195,8 @@ var ghostSlice = (0, import_toolkit3.createSlice)({
|
|
|
877
1195
|
var { clearGhostSession } = ghostSlice.actions;
|
|
878
1196
|
var ghostSlice_default = ghostSlice.reducer;
|
|
879
1197
|
|
|
880
|
-
// src/utils/
|
|
881
|
-
var
|
|
1198
|
+
// src/utils/version.ts
|
|
1199
|
+
var VERSION = "0.6.4";
|
|
882
1200
|
|
|
883
1201
|
// src/utils/generateNPCId.ts
|
|
884
1202
|
var generateNPCId = () => `ag_${Date.now().toString(36)}`;
|
|
@@ -959,7 +1277,8 @@ var npcSlice = (0, import_toolkit4.createSlice)({
|
|
|
959
1277
|
persona,
|
|
960
1278
|
state: initialState5 || {},
|
|
961
1279
|
history: [],
|
|
962
|
-
isBlocked: false
|
|
1280
|
+
isBlocked: false,
|
|
1281
|
+
stateLog: [{ timestamp: Date.now(), delta: initialState5 || {}, state: initialState5 || {} }]
|
|
963
1282
|
});
|
|
964
1283
|
state.activeNpcId = id;
|
|
965
1284
|
},
|
|
@@ -974,7 +1293,9 @@ var npcSlice = (0, import_toolkit4.createSlice)({
|
|
|
974
1293
|
const { id, delta } = action.payload;
|
|
975
1294
|
const npc = state.entities[id];
|
|
976
1295
|
if (npc) {
|
|
977
|
-
|
|
1296
|
+
const newState = { ...npc.state, ...delta };
|
|
1297
|
+
npc.state = newState;
|
|
1298
|
+
npc.stateLog.push({ timestamp: Date.now(), delta, state: newState });
|
|
978
1299
|
}
|
|
979
1300
|
},
|
|
980
1301
|
addToHistory: (state, action) => {
|
|
@@ -1043,8 +1364,9 @@ var initRemoteCortexThunk = (0, import_toolkit5.createAsyncThunk)(
|
|
|
1043
1364
|
"cortex/initRemote",
|
|
1044
1365
|
async ({ model = "api-integrated", authKey, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
|
|
1045
1366
|
try {
|
|
1046
|
-
const url = apiUrl
|
|
1047
|
-
|
|
1367
|
+
const url = resolveApiUrl(apiUrl);
|
|
1368
|
+
requireApiKeyGuidance(url, apiKey);
|
|
1369
|
+
const data = await dispatch2(api.endpoints.postCortexInit.initiate({
|
|
1048
1370
|
request: { requestedModel: model, authKey },
|
|
1049
1371
|
apiUrl: url,
|
|
1050
1372
|
apiKey
|
|
@@ -1055,8 +1377,8 @@ var initRemoteCortexThunk = (0, import_toolkit5.createAsyncThunk)(
|
|
|
1055
1377
|
ready: data.state?.toLowerCase() === "ready",
|
|
1056
1378
|
engine: "remote"
|
|
1057
1379
|
};
|
|
1058
|
-
} catch (
|
|
1059
|
-
return rejectWithValue(
|
|
1380
|
+
} catch (error) {
|
|
1381
|
+
return rejectWithValue(extractThunkErrorMessage(error, "Remote cortex init failed"));
|
|
1060
1382
|
}
|
|
1061
1383
|
}
|
|
1062
1384
|
);
|
|
@@ -1064,10 +1386,11 @@ var listCortexModelsThunk = (0, import_toolkit5.createAsyncThunk)(
|
|
|
1064
1386
|
"cortex/listModels",
|
|
1065
1387
|
async ({ apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
|
|
1066
1388
|
try {
|
|
1067
|
-
const url = apiUrl
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1389
|
+
const url = resolveApiUrl(apiUrl);
|
|
1390
|
+
requireApiKeyGuidance(url, apiKey);
|
|
1391
|
+
return await dispatch2(api.endpoints.getCortexModels.initiate({ apiUrl: url, apiKey })).unwrap();
|
|
1392
|
+
} catch (error) {
|
|
1393
|
+
return rejectWithValue(extractThunkErrorMessage(error, "Failed to list cortex models"));
|
|
1071
1394
|
}
|
|
1072
1395
|
}
|
|
1073
1396
|
);
|
|
@@ -1075,7 +1398,8 @@ var completeRemoteThunk = (0, import_toolkit5.createAsyncThunk)(
|
|
|
1075
1398
|
"cortex/completeRemote",
|
|
1076
1399
|
async ({ cortexId, prompt, options, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
|
|
1077
1400
|
try {
|
|
1078
|
-
|
|
1401
|
+
requireApiKeyGuidance(apiUrl, apiKey);
|
|
1402
|
+
const data = await dispatch2(api.endpoints.postCortexComplete.initiate({
|
|
1079
1403
|
cortexId,
|
|
1080
1404
|
prompt,
|
|
1081
1405
|
options,
|
|
@@ -1083,8 +1407,8 @@ var completeRemoteThunk = (0, import_toolkit5.createAsyncThunk)(
|
|
|
1083
1407
|
apiKey
|
|
1084
1408
|
})).unwrap();
|
|
1085
1409
|
return data.text;
|
|
1086
|
-
} catch (
|
|
1087
|
-
return rejectWithValue(
|
|
1410
|
+
} catch (error) {
|
|
1411
|
+
return rejectWithValue(extractThunkErrorMessage(error, "Remote completing failed"));
|
|
1088
1412
|
}
|
|
1089
1413
|
}
|
|
1090
1414
|
);
|
|
@@ -1276,8 +1600,8 @@ var directiveSlice_default = directiveSlice.reducer;
|
|
|
1276
1600
|
|
|
1277
1601
|
// src/listeners.ts
|
|
1278
1602
|
var import_toolkit8 = require("@reduxjs/toolkit");
|
|
1279
|
-
var
|
|
1280
|
-
var startAppListening =
|
|
1603
|
+
var listenerMiddleware = (0, import_toolkit8.createListenerMiddleware)();
|
|
1604
|
+
var startAppListening = listenerMiddleware.startListening.withTypes();
|
|
1281
1605
|
startAppListening({
|
|
1282
1606
|
actionCreator: removeNPC,
|
|
1283
1607
|
effect: async (action, listenerApi) => {
|
|
@@ -1294,11 +1618,38 @@ startAppListening({
|
|
|
1294
1618
|
}
|
|
1295
1619
|
});
|
|
1296
1620
|
|
|
1621
|
+
// src/runtimeRegistry.ts
|
|
1622
|
+
var createRuntimeRegistry = () => {
|
|
1623
|
+
const _store = {};
|
|
1624
|
+
return {
|
|
1625
|
+
get: (ns, key) => _store[ns]?.[key],
|
|
1626
|
+
set: (ns, key, value) => {
|
|
1627
|
+
if (!_store[ns]) _store[ns] = {};
|
|
1628
|
+
_store[ns][key] = value;
|
|
1629
|
+
},
|
|
1630
|
+
delete: (ns, key) => {
|
|
1631
|
+
if (_store[ns]) {
|
|
1632
|
+
delete _store[ns][key];
|
|
1633
|
+
return true;
|
|
1634
|
+
}
|
|
1635
|
+
return false;
|
|
1636
|
+
},
|
|
1637
|
+
has: (ns, key) => !!(_store[ns]?.[key] !== void 0),
|
|
1638
|
+
clear: (ns) => {
|
|
1639
|
+
if (ns) {
|
|
1640
|
+
delete _store[ns];
|
|
1641
|
+
} else {
|
|
1642
|
+
Object.keys(_store).forEach((k) => delete _store[k]);
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
};
|
|
1646
|
+
};
|
|
1647
|
+
|
|
1297
1648
|
// src/store.ts
|
|
1298
|
-
var
|
|
1649
|
+
var createRuntimeStore = (extraReducers = {}, registry = createRuntimeRegistry()) => {
|
|
1299
1650
|
return (0, import_toolkit9.configureStore)({
|
|
1300
1651
|
reducer: {
|
|
1301
|
-
[
|
|
1652
|
+
[api.reducerPath]: api.reducer,
|
|
1302
1653
|
npc: npcSlice_default,
|
|
1303
1654
|
cortex: cortexSlice_default,
|
|
1304
1655
|
memory: memorySlice_default,
|
|
@@ -1309,46 +1660,120 @@ var createSDKStore = (extraReducers = {}) => {
|
|
|
1309
1660
|
...extraReducers
|
|
1310
1661
|
},
|
|
1311
1662
|
middleware: (getDefaultMiddleware) => getDefaultMiddleware({
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1663
|
+
thunk: { extraArgument: registry },
|
|
1664
|
+
serializableCheck: {
|
|
1665
|
+
ignoredActionPaths: [
|
|
1666
|
+
"meta.arg.cortex",
|
|
1667
|
+
"meta.arg.memory",
|
|
1668
|
+
"meta.arg.onProgress",
|
|
1669
|
+
"meta.baseQueryMeta.request",
|
|
1670
|
+
"meta.baseQueryMeta.response"
|
|
1671
|
+
]
|
|
1672
|
+
}
|
|
1673
|
+
}).prepend(listenerMiddleware.middleware).concat(api.middleware)
|
|
1315
1674
|
});
|
|
1316
1675
|
};
|
|
1317
|
-
var store =
|
|
1676
|
+
var store = createRuntimeStore();
|
|
1318
1677
|
var dispatch = store.dispatch;
|
|
1319
1678
|
|
|
1320
1679
|
// src/thunks.ts
|
|
1321
1680
|
var import_toolkit10 = require("@reduxjs/toolkit");
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1681
|
+
|
|
1682
|
+
// src/protocolHandlers.ts
|
|
1683
|
+
var persistMemoryRecursively = async (memory, instructions, index = 0) => !memory || index >= instructions.length ? void 0 : memory.store(instructions[index].text, instructions[index].type, instructions[index].importance).then(() => persistMemoryRecursively(memory, instructions, index + 1));
|
|
1684
|
+
var handleIdentifyActor = (ctx, nextTape, turn) => ctx.recurse(nextTape, {
|
|
1685
|
+
type: "IdentifyActorResult",
|
|
1686
|
+
actor: { npcId: ctx.npcId, persona: ctx.persona, data: nextTape.npcState }
|
|
1687
|
+
}, turn + 1);
|
|
1688
|
+
var handleQueryVector = async (ctx, instruction, nextTape, turn) => {
|
|
1689
|
+
ctx.dispatch(directiveReceived({
|
|
1690
|
+
id: ctx.directiveId,
|
|
1691
|
+
response: { memoryRecall: { query: instruction.query, limit: instruction.limit, threshold: instruction.threshold } }
|
|
1692
|
+
}));
|
|
1693
|
+
return ctx.memory ? ctx.memory.recall(instruction.query, instruction.limit, instruction.threshold).then((recalled) => ctx.recurse(nextTape, {
|
|
1694
|
+
type: "QueryVectorResult",
|
|
1695
|
+
memories: recalled.map((m) => ({ text: m.text, type: m.type, importance: m.importance, similarity: m.similarity }))
|
|
1696
|
+
}, turn + 1)) : ctx.rejectWithValue("API requested memory recall, but no memory engine is configured");
|
|
1697
|
+
};
|
|
1698
|
+
var handleExecuteInference = async (ctx, instruction, nextTape, turn) => {
|
|
1699
|
+
ctx.dispatch(contextComposed({ id: ctx.directiveId, prompt: instruction.prompt, constraints: instruction.constraints }));
|
|
1700
|
+
const generatedText = await ctx.cortex.complete(instruction.prompt, {
|
|
1701
|
+
maxTokens: instruction.constraints.maxTokens,
|
|
1702
|
+
temperature: instruction.constraints.temperature,
|
|
1703
|
+
stop: instruction.constraints.stop
|
|
1704
|
+
});
|
|
1705
|
+
return ctx.recurse(nextTape, {
|
|
1706
|
+
type: "ExecuteInferenceResult",
|
|
1707
|
+
generatedOutput: generatedText
|
|
1708
|
+
}, turn + 1);
|
|
1709
|
+
};
|
|
1710
|
+
var handleFinalize = async (ctx, finalize) => {
|
|
1711
|
+
ctx.dispatch(verdictValidated({
|
|
1712
|
+
id: ctx.directiveId,
|
|
1713
|
+
verdict: {
|
|
1714
|
+
valid: finalize.valid,
|
|
1715
|
+
signature: finalize.signature,
|
|
1716
|
+
memoryStore: finalize.memoryStore,
|
|
1717
|
+
stateDelta: finalize.stateTransform,
|
|
1718
|
+
action: finalize.action,
|
|
1719
|
+
dialogue: finalize.dialogue
|
|
1720
|
+
}
|
|
1721
|
+
}));
|
|
1722
|
+
return finalize.valid ? applyFinalizeSuccess(ctx, finalize) : applyFinalizeBlocked(ctx, finalize);
|
|
1328
1723
|
};
|
|
1724
|
+
var applyFinalizeBlocked = (ctx, finalize) => {
|
|
1725
|
+
ctx.dispatch(blockAction({ id: ctx.npcId, reason: finalize.dialogue || "Validation Failed" }));
|
|
1726
|
+
return { dialogue: finalize.dialogue, action: finalize.action, thought: finalize.dialogue };
|
|
1727
|
+
};
|
|
1728
|
+
var applyFinalizeSuccess = async (ctx, finalize) => {
|
|
1729
|
+
if (finalize.memoryStore?.length && !ctx.memory) {
|
|
1730
|
+
return ctx.rejectWithValue("API returned memoryStore instructions, but no memory engine is configured");
|
|
1731
|
+
}
|
|
1732
|
+
await persistMemoryRecursively(ctx.memory, finalize.memoryStore || []);
|
|
1733
|
+
if (finalize.stateTransform) {
|
|
1734
|
+
ctx.dispatch(updateNPCState({ id: ctx.npcId, delta: finalize.stateTransform }));
|
|
1735
|
+
}
|
|
1736
|
+
ctx.dispatch(setLastAction({ id: ctx.npcId, action: finalize.action }));
|
|
1737
|
+
ctx.dispatch(addToHistory({ id: ctx.npcId, role: "user", content: ctx.text }));
|
|
1738
|
+
ctx.dispatch(addToHistory({ id: ctx.npcId, role: "assistant", content: finalize.dialogue }));
|
|
1739
|
+
return { dialogue: finalize.dialogue, action: finalize.action, thought: finalize.dialogue };
|
|
1740
|
+
};
|
|
1741
|
+
var dispatchInstruction = (ctx, instruction, nextTape, turn) => {
|
|
1742
|
+
const handlers = {
|
|
1743
|
+
"IdentifyActor": () => handleIdentifyActor(ctx, nextTape, turn),
|
|
1744
|
+
"QueryVector": () => handleQueryVector(ctx, instruction, nextTape, turn),
|
|
1745
|
+
"ExecuteInference": () => handleExecuteInference(ctx, instruction, nextTape, turn),
|
|
1746
|
+
"Finalize": () => handleFinalize(ctx, instruction)
|
|
1747
|
+
};
|
|
1748
|
+
const handler = handlers[instruction.type];
|
|
1749
|
+
return handler ? handler() : Promise.resolve(ctx.rejectWithValue("API returned unknown instruction type"));
|
|
1750
|
+
};
|
|
1751
|
+
|
|
1752
|
+
// src/thunks.ts
|
|
1753
|
+
var extractThunkErrorMessage2 = (e) => multiMatch(e, [
|
|
1754
|
+
[(e2) => typeof e2 === "string", (e2) => e2],
|
|
1755
|
+
[(e2) => !!e2?.data?.message, (e2) => String(e2.data.message)],
|
|
1756
|
+
[(e2) => !!e2?.error, (e2) => String(e2.error)],
|
|
1757
|
+
[(e2) => !!e2?.message, (e2) => String(e2.message)],
|
|
1758
|
+
[_, () => "Protocol processing failed"]
|
|
1759
|
+
]).getOrElse("Protocol processing failed");
|
|
1760
|
+
var safeDispatch = async (promise) => promise.then((v) => right(v)).catch((e) => left(extractThunkErrorMessage2(e)));
|
|
1329
1761
|
var processNPC = (0, import_toolkit10.createAsyncThunk)(
|
|
1330
1762
|
"npc/process",
|
|
1331
1763
|
async ({ npcId: argNpcId, text, context = {}, apiUrl, apiKey, memory, cortex, persona: argPersona }, { getState, dispatch: dispatch2, rejectWithValue }) => {
|
|
1332
1764
|
const stateNpcId = selectActiveNpcId(getState());
|
|
1333
1765
|
const activeNpc = selectActiveNPC(getState());
|
|
1334
|
-
const npcId = argNpcId || stateNpcId;
|
|
1335
|
-
const persona = argPersona || activeNpc?.persona;
|
|
1336
1766
|
const currentState = activeNpc?.state || {};
|
|
1337
|
-
|
|
1338
|
-
return rejectWithValue("No npcId provided and no active NPC selected");
|
|
1339
|
-
}
|
|
1340
|
-
if (!persona) {
|
|
1341
|
-
return rejectWithValue("No persona provided and no active NPC persona available");
|
|
1342
|
-
}
|
|
1343
|
-
if (!cortex) {
|
|
1344
|
-
return rejectWithValue("No local cortex provided. SDK remote cortex fallback is disabled.");
|
|
1345
|
-
}
|
|
1346
|
-
if (argNpcId && argNpcId !== stateNpcId) {
|
|
1347
|
-
dispatch2(setNPCInfo({ id: argNpcId, persona }));
|
|
1348
|
-
}
|
|
1349
|
-
const directiveId = `${npcId}:${Date.now()}`;
|
|
1350
|
-
dispatch2(directiveRunStarted({ id: directiveId, npcId, observation: text }));
|
|
1767
|
+
let directiveId;
|
|
1351
1768
|
try {
|
|
1769
|
+
const npcId = requireJust(fromNullable(argNpcId || stateNpcId), "No npcId provided and no active NPC selected");
|
|
1770
|
+
const persona = requireJust(fromNullable(argPersona || activeNpc?.persona), "No persona provided and no active NPC persona available");
|
|
1771
|
+
requireJust(fromNullable(cortex), "No local cortex provided. SDK remote cortex fallback is disabled.");
|
|
1772
|
+
if (argNpcId && argNpcId !== stateNpcId) {
|
|
1773
|
+
dispatch2(setNPCInfo({ id: argNpcId, persona }));
|
|
1774
|
+
}
|
|
1775
|
+
directiveId = `${npcId}:${Date.now()}`;
|
|
1776
|
+
dispatch2(directiveRunStarted({ id: directiveId, npcId, observation: text }));
|
|
1352
1777
|
const initialTape = {
|
|
1353
1778
|
observation: text,
|
|
1354
1779
|
context,
|
|
@@ -1357,104 +1782,33 @@ var processNPC = (0, import_toolkit10.createAsyncThunk)(
|
|
|
1357
1782
|
memories: [],
|
|
1358
1783
|
vectorQueried: false
|
|
1359
1784
|
};
|
|
1360
|
-
const
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
return;
|
|
1364
|
-
}
|
|
1365
|
-
const inst = instructions[index];
|
|
1366
|
-
await memory.store(inst.text, inst.type, inst.importance);
|
|
1367
|
-
await persistMemoryInstructionsRecursively(instructions, index + 1);
|
|
1368
|
-
};
|
|
1369
|
-
const runProtocolRecursively = async (tape, lastResult, turn) => {
|
|
1370
|
-
if (turn >= maxTurns) {
|
|
1371
|
-
return rejectWithValue(`Protocol loop exceeded max turns (${maxTurns})`);
|
|
1785
|
+
const runProtocol = async (tape, lastResult, turn) => {
|
|
1786
|
+
if (turn >= 12) {
|
|
1787
|
+
return rejectWithValue("Protocol loop exceeded max turns (12)");
|
|
1372
1788
|
}
|
|
1373
1789
|
const request = { tape, lastResult };
|
|
1374
1790
|
const processResult = await dispatch2(
|
|
1375
|
-
|
|
1791
|
+
api.endpoints.postNpcProcess.initiate({ npcId, request, apiUrl, apiKey })
|
|
1376
1792
|
).unwrap();
|
|
1377
|
-
const
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
if (instruction.type === "QueryVector") {
|
|
1390
|
-
dispatch2(directiveReceived({
|
|
1391
|
-
id: directiveId,
|
|
1392
|
-
response: { memoryRecall: { query: instruction.query, limit: instruction.limit, threshold: instruction.threshold } }
|
|
1393
|
-
}));
|
|
1394
|
-
if (!memory) {
|
|
1395
|
-
return rejectWithValue("API requested memory recall, but no memory engine is configured");
|
|
1396
|
-
}
|
|
1397
|
-
const recalled = await memory.recall(instruction.query, instruction.limit, instruction.threshold);
|
|
1398
|
-
return runProtocolRecursively(nextTape, {
|
|
1399
|
-
type: "QueryVectorResult",
|
|
1400
|
-
memories: recalled.map((m) => ({ text: m.text, type: m.type, importance: m.importance, similarity: m.similarity }))
|
|
1401
|
-
}, turn + 1);
|
|
1402
|
-
}
|
|
1403
|
-
if (instruction.type === "ExecuteInference") {
|
|
1404
|
-
dispatch2(contextComposed({ id: directiveId, prompt: instruction.prompt, constraints: instruction.constraints }));
|
|
1405
|
-
const generatedText = await cortex.complete(instruction.prompt, {
|
|
1406
|
-
maxTokens: instruction.constraints.maxTokens,
|
|
1407
|
-
temperature: instruction.constraints.temperature,
|
|
1408
|
-
stop: instruction.constraints.stop
|
|
1409
|
-
});
|
|
1410
|
-
return runProtocolRecursively(nextTape, {
|
|
1411
|
-
type: "ExecuteInferenceResult",
|
|
1412
|
-
generatedOutput: generatedText
|
|
1413
|
-
}, turn + 1);
|
|
1414
|
-
}
|
|
1415
|
-
if (instruction.type === "Finalize") {
|
|
1416
|
-
const finalize = instruction;
|
|
1417
|
-
dispatch2(verdictValidated({
|
|
1418
|
-
id: directiveId,
|
|
1419
|
-
verdict: {
|
|
1420
|
-
valid: finalize.valid,
|
|
1421
|
-
signature: finalize.signature,
|
|
1422
|
-
memoryStore: finalize.memoryStore,
|
|
1423
|
-
stateDelta: finalize.stateTransform,
|
|
1424
|
-
action: finalize.action,
|
|
1425
|
-
dialogue: finalize.dialogue
|
|
1426
|
-
}
|
|
1427
|
-
}));
|
|
1428
|
-
if (!finalize.valid) {
|
|
1429
|
-
dispatch2(blockAction({ id: npcId, reason: finalize.dialogue || "Validation Failed" }));
|
|
1430
|
-
return {
|
|
1431
|
-
dialogue: finalize.dialogue,
|
|
1432
|
-
action: finalize.action,
|
|
1433
|
-
thought: finalize.dialogue
|
|
1434
|
-
};
|
|
1435
|
-
}
|
|
1436
|
-
if (finalize.memoryStore?.length && !memory) {
|
|
1437
|
-
return rejectWithValue("API returned memoryStore instructions, but no memory engine is configured");
|
|
1438
|
-
}
|
|
1439
|
-
await persistMemoryInstructionsRecursively(finalize.memoryStore || []);
|
|
1440
|
-
if (finalize.stateTransform) {
|
|
1441
|
-
dispatch2(updateNPCState({ id: npcId, delta: finalize.stateTransform }));
|
|
1442
|
-
}
|
|
1443
|
-
dispatch2(setLastAction({ id: npcId, action: finalize.action }));
|
|
1444
|
-
dispatch2(addToHistory({ id: npcId, role: "user", content: text }));
|
|
1445
|
-
dispatch2(addToHistory({ id: npcId, role: "assistant", content: finalize.dialogue }));
|
|
1446
|
-
return {
|
|
1447
|
-
dialogue: finalize.dialogue,
|
|
1448
|
-
action: finalize.action,
|
|
1449
|
-
thought: finalize.dialogue
|
|
1450
|
-
};
|
|
1451
|
-
}
|
|
1452
|
-
return rejectWithValue("API returned unknown instruction type");
|
|
1793
|
+
const ctx = {
|
|
1794
|
+
npcId,
|
|
1795
|
+
persona,
|
|
1796
|
+
text,
|
|
1797
|
+
directiveId,
|
|
1798
|
+
memory,
|
|
1799
|
+
cortex,
|
|
1800
|
+
dispatch: dispatch2,
|
|
1801
|
+
rejectWithValue,
|
|
1802
|
+
recurse: runProtocol
|
|
1803
|
+
};
|
|
1804
|
+
return dispatchInstruction(ctx, processResult.instruction, processResult.tape, turn);
|
|
1453
1805
|
};
|
|
1454
|
-
return
|
|
1806
|
+
return runProtocol(initialTape, void 0, 0);
|
|
1455
1807
|
} catch (e) {
|
|
1456
|
-
const message =
|
|
1457
|
-
|
|
1808
|
+
const message = extractThunkErrorMessage2(e);
|
|
1809
|
+
if (directiveId) {
|
|
1810
|
+
dispatch2(directiveRunFailed({ id: directiveId, error: String(message) }));
|
|
1811
|
+
}
|
|
1458
1812
|
return rejectWithValue(String(message));
|
|
1459
1813
|
}
|
|
1460
1814
|
}
|
|
@@ -1464,8 +1818,7 @@ var localExportSoulThunk = (0, import_toolkit10.createAsyncThunk)(
|
|
|
1464
1818
|
async ({ id, memory }, { getState }) => {
|
|
1465
1819
|
const state = getState().npc;
|
|
1466
1820
|
const npcId = id || state.activeNpcId;
|
|
1467
|
-
const npc = state.entities[npcId];
|
|
1468
|
-
if (!npc) throw new Error(`NPC ${npcId} not found`);
|
|
1821
|
+
const npc = requireJust(fromNullable(state.entities[npcId]), `NPC ${npcId} not found`);
|
|
1469
1822
|
const memories = memory ? await memory.export() : [];
|
|
1470
1823
|
return exportToSoul(npcId, "NPC", npc.persona, npc.state, memories);
|
|
1471
1824
|
}
|
|
@@ -1473,77 +1826,99 @@ var localExportSoulThunk = (0, import_toolkit10.createAsyncThunk)(
|
|
|
1473
1826
|
var checkApiStatusThunk = (0, import_toolkit10.createAsyncThunk)(
|
|
1474
1827
|
"system/checkApiStatus",
|
|
1475
1828
|
async ({ apiUrl }, { dispatch: dispatch2, rejectWithValue }) => {
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
}
|
|
1829
|
+
const result = await safeDispatch(dispatch2(api.endpoints.getApiStatus.initiate({ apiUrl })).unwrap());
|
|
1830
|
+
return result.match({
|
|
1831
|
+
left: (e) => rejectWithValue(e),
|
|
1832
|
+
right: (v) => v
|
|
1833
|
+
});
|
|
1481
1834
|
}
|
|
1482
1835
|
);
|
|
1483
1836
|
var listMemoryRemoteThunk = (0, import_toolkit10.createAsyncThunk)(
|
|
1484
1837
|
"memory/listRemote",
|
|
1485
1838
|
async ({ npcId, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
}
|
|
1839
|
+
const result = await safeDispatch(dispatch2(api.endpoints.getMemoryList.initiate({ npcId, apiUrl, apiKey })).unwrap());
|
|
1840
|
+
return result.match({
|
|
1841
|
+
left: (e) => rejectWithValue(e),
|
|
1842
|
+
right: (v) => v || []
|
|
1843
|
+
});
|
|
1492
1844
|
}
|
|
1493
1845
|
);
|
|
1494
1846
|
var recallMemoryRemoteThunk = (0, import_toolkit10.createAsyncThunk)(
|
|
1495
1847
|
"memory/recallRemote",
|
|
1496
1848
|
async ({ npcId, query, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
})
|
|
1505
|
-
).unwrap();
|
|
1506
|
-
return data || [];
|
|
1507
|
-
} catch (e) {
|
|
1508
|
-
return rejectWithValue(e?.message || "Failed to recall memories");
|
|
1509
|
-
}
|
|
1849
|
+
const result = await safeDispatch(dispatch2(
|
|
1850
|
+
api.endpoints.postMemoryRecall.initiate({ npcId, request: { query }, apiUrl, apiKey })
|
|
1851
|
+
).unwrap());
|
|
1852
|
+
return result.match({
|
|
1853
|
+
left: (e) => rejectWithValue(e),
|
|
1854
|
+
right: (v) => v || []
|
|
1855
|
+
});
|
|
1510
1856
|
}
|
|
1511
1857
|
);
|
|
1512
1858
|
var storeMemoryRemoteThunk = (0, import_toolkit10.createAsyncThunk)(
|
|
1513
1859
|
"memory/storeRemote",
|
|
1514
1860
|
async ({ npcId, observation, importance = 0.8, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
})
|
|
1523
|
-
).unwrap();
|
|
1524
|
-
} catch (e) {
|
|
1525
|
-
return rejectWithValue(e?.message || "Failed to store memory");
|
|
1526
|
-
}
|
|
1861
|
+
const result = await safeDispatch(dispatch2(
|
|
1862
|
+
api.endpoints.postMemoryStore.initiate({ npcId, request: { observation, importance }, apiUrl, apiKey })
|
|
1863
|
+
).unwrap());
|
|
1864
|
+
return result.match({
|
|
1865
|
+
left: (e) => rejectWithValue(e),
|
|
1866
|
+
right: (v) => v
|
|
1867
|
+
});
|
|
1527
1868
|
}
|
|
1528
1869
|
);
|
|
1529
1870
|
var clearMemoryRemoteThunk = (0, import_toolkit10.createAsyncThunk)(
|
|
1530
1871
|
"memory/clearRemote",
|
|
1531
1872
|
async ({ npcId, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
}
|
|
1873
|
+
const result = await safeDispatch(dispatch2(
|
|
1874
|
+
api.endpoints.deleteMemoryClear.initiate({ npcId, apiUrl, apiKey })
|
|
1875
|
+
).unwrap());
|
|
1876
|
+
return result.match({
|
|
1877
|
+
left: (e) => rejectWithValue(e),
|
|
1878
|
+
right: (v) => v
|
|
1879
|
+
});
|
|
1539
1880
|
}
|
|
1540
1881
|
);
|
|
1882
|
+
|
|
1883
|
+
// src/handlers/arweave.ts
|
|
1884
|
+
var handler_ArweaveUpload = async (instruction, maxRetries = 3) => store.dispatch(
|
|
1885
|
+
api.endpoints.postArweaveUpload.initiate({ ...instruction, maxRetries })
|
|
1886
|
+
).unwrap();
|
|
1887
|
+
var handler_ArweaveDownload = async (instruction) => store.dispatch(
|
|
1888
|
+
api.endpoints.postArweaveDownload.initiate(instruction)
|
|
1889
|
+
).unwrap();
|
|
1890
|
+
|
|
1891
|
+
// src/configOps.ts
|
|
1892
|
+
var normalizeStatusUrl = (apiUrl) => apiUrl.endsWith("/status") ? apiUrl : `${apiUrl.replace(/\/+$/, "")}/status`;
|
|
1893
|
+
var checkApiConnectivity = async (apiUrl = DEFAULT_API_URL) => {
|
|
1894
|
+
try {
|
|
1895
|
+
const res = await fetch(normalizeStatusUrl(apiUrl), { signal: AbortSignal.timeout(1500) });
|
|
1896
|
+
return res.ok;
|
|
1897
|
+
} catch {
|
|
1898
|
+
return false;
|
|
1899
|
+
}
|
|
1900
|
+
};
|
|
1901
|
+
var resolveReachableApiUrl = async (apiUrl) => {
|
|
1902
|
+
if (apiUrl) return await checkApiConnectivity(apiUrl) ? apiUrl : null;
|
|
1903
|
+
if (await checkApiConnectivity(DEFAULT_API_URL)) return DEFAULT_API_URL;
|
|
1904
|
+
if (await checkApiConnectivity(PRODUCTION_API_URL)) return PRODUCTION_API_URL;
|
|
1905
|
+
return null;
|
|
1906
|
+
};
|
|
1907
|
+
var resolveApiUrlWithFallback = async (apiUrl) => {
|
|
1908
|
+
if (apiUrl) return apiUrl;
|
|
1909
|
+
return await resolveReachableApiUrl() || PRODUCTION_API_URL;
|
|
1910
|
+
};
|
|
1541
1911
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1542
1912
|
0 && (module.exports = {
|
|
1543
|
-
|
|
1913
|
+
DEFAULT_API_URL,
|
|
1914
|
+
PRODUCTION_API_URL,
|
|
1915
|
+
VERSION,
|
|
1916
|
+
_,
|
|
1544
1917
|
addToHistory,
|
|
1918
|
+
api,
|
|
1545
1919
|
blockAction,
|
|
1546
1920
|
bridgeSlice,
|
|
1921
|
+
checkApiConnectivity,
|
|
1547
1922
|
checkApiStatusThunk,
|
|
1548
1923
|
clearBlock,
|
|
1549
1924
|
clearBridgeValidation,
|
|
@@ -1552,13 +1927,17 @@ var clearMemoryRemoteThunk = (0, import_toolkit10.createAsyncThunk)(
|
|
|
1552
1927
|
clearMemoryRemoteThunk,
|
|
1553
1928
|
clearSoulState,
|
|
1554
1929
|
completeRemoteThunk,
|
|
1930
|
+
compose,
|
|
1555
1931
|
contextComposed,
|
|
1556
1932
|
cortexInitFailed,
|
|
1557
1933
|
cortexInitStart,
|
|
1558
1934
|
cortexInitSuccess,
|
|
1559
1935
|
cortexSlice,
|
|
1936
|
+
createDispatcher,
|
|
1560
1937
|
createInitialState,
|
|
1561
|
-
|
|
1938
|
+
createRuntimeRegistry,
|
|
1939
|
+
createRuntimeStore,
|
|
1940
|
+
curry,
|
|
1562
1941
|
delay,
|
|
1563
1942
|
deleteRulesetThunk,
|
|
1564
1943
|
directiveReceived,
|
|
@@ -1566,7 +1945,12 @@ var clearMemoryRemoteThunk = (0, import_toolkit10.createAsyncThunk)(
|
|
|
1566
1945
|
directiveRunStarted,
|
|
1567
1946
|
directiveSlice,
|
|
1568
1947
|
dispatch,
|
|
1948
|
+
ebind,
|
|
1949
|
+
efmap,
|
|
1950
|
+
ematch,
|
|
1569
1951
|
exportToSoul,
|
|
1952
|
+
fmap,
|
|
1953
|
+
fromNullable,
|
|
1570
1954
|
generateNPCId,
|
|
1571
1955
|
getBridgeRulesThunk,
|
|
1572
1956
|
getGhostHistoryThunk,
|
|
@@ -1574,15 +1958,25 @@ var clearMemoryRemoteThunk = (0, import_toolkit10.createAsyncThunk)(
|
|
|
1574
1958
|
getGhostStatusThunk,
|
|
1575
1959
|
getSoulListThunk,
|
|
1576
1960
|
ghostSlice,
|
|
1961
|
+
handler_ArweaveDownload,
|
|
1962
|
+
handler_ArweaveUpload,
|
|
1577
1963
|
importNpcFromSoulThunk,
|
|
1578
1964
|
importSoulFromArweaveThunk,
|
|
1579
1965
|
initRemoteCortexThunk,
|
|
1966
|
+
isJust,
|
|
1967
|
+
isLeft,
|
|
1968
|
+
isNothing,
|
|
1969
|
+
isRight,
|
|
1970
|
+
just,
|
|
1971
|
+
left,
|
|
1580
1972
|
listCortexModelsThunk,
|
|
1581
1973
|
listMemoryRemoteThunk,
|
|
1582
1974
|
listRulePresetsThunk,
|
|
1583
1975
|
listRulesetsThunk,
|
|
1584
1976
|
loadBridgePresetThunk,
|
|
1585
1977
|
localExportSoulThunk,
|
|
1978
|
+
match,
|
|
1979
|
+
mbind,
|
|
1586
1980
|
memoise,
|
|
1587
1981
|
memoiseAsync,
|
|
1588
1982
|
memoryClear,
|
|
@@ -1593,14 +1987,21 @@ var clearMemoryRemoteThunk = (0, import_toolkit10.createAsyncThunk)(
|
|
|
1593
1987
|
memoryStoreFailed,
|
|
1594
1988
|
memoryStoreStart,
|
|
1595
1989
|
memoryStoreSuccess,
|
|
1990
|
+
multiMatch,
|
|
1991
|
+
nothing,
|
|
1596
1992
|
npcSlice,
|
|
1993
|
+
orElse,
|
|
1597
1994
|
pipe,
|
|
1598
1995
|
processNPC,
|
|
1599
1996
|
recallMemoryRemoteThunk,
|
|
1600
1997
|
registerRulesetThunk,
|
|
1601
1998
|
remoteExportSoulThunk,
|
|
1602
1999
|
removeNPC,
|
|
1603
|
-
|
|
2000
|
+
requireJust,
|
|
2001
|
+
resolveApiUrl,
|
|
2002
|
+
resolveApiUrlWithFallback,
|
|
2003
|
+
resolveReachableApiUrl,
|
|
2004
|
+
right,
|
|
1604
2005
|
selectActiveDirective,
|
|
1605
2006
|
selectActiveDirectiveId,
|
|
1606
2007
|
selectActiveNPC,
|