@forbocai/core 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -24,11 +24,15 @@ __export(index_exports, {
24
24
  addToHistory: () => addToHistory,
25
25
  blockAction: () => blockAction,
26
26
  bridgeSlice: () => bridgeSlice,
27
+ checkApiStatusThunk: () => checkApiStatusThunk,
27
28
  clearBlock: () => clearBlock,
28
29
  clearBridgeValidation: () => clearBridgeValidation,
30
+ clearDirectivesForNpc: () => clearDirectivesForNpc,
29
31
  clearGhostSession: () => clearGhostSession,
32
+ clearMemoryRemoteThunk: () => clearMemoryRemoteThunk,
30
33
  clearSoulState: () => clearSoulState,
31
34
  completeRemoteThunk: () => completeRemoteThunk,
35
+ contextComposed: () => contextComposed,
32
36
  cortexInitFailed: () => cortexInitFailed,
33
37
  cortexInitStart: () => cortexInitStart,
34
38
  cortexInitSuccess: () => cortexInitSuccess,
@@ -36,7 +40,11 @@ __export(index_exports, {
36
40
  createInitialState: () => createInitialState,
37
41
  createSDKStore: () => createSDKStore,
38
42
  delay: () => delay,
39
- dialogueNPC: () => dialogueNPC,
43
+ deleteRulesetThunk: () => deleteRulesetThunk,
44
+ directiveReceived: () => directiveReceived,
45
+ directiveRunFailed: () => directiveRunFailed,
46
+ directiveRunStarted: () => directiveRunStarted,
47
+ directiveSlice: () => directiveSlice,
40
48
  dispatch: () => dispatch,
41
49
  exportToSoul: () => exportToSoul,
42
50
  generateNPCId: () => generateNPCId,
@@ -46,8 +54,13 @@ __export(index_exports, {
46
54
  getGhostStatusThunk: () => getGhostStatusThunk,
47
55
  getSoulListThunk: () => getSoulListThunk,
48
56
  ghostSlice: () => ghostSlice,
57
+ importNpcFromSoulThunk: () => importNpcFromSoulThunk,
49
58
  importSoulFromArweaveThunk: () => importSoulFromArweaveThunk,
50
59
  initRemoteCortexThunk: () => initRemoteCortexThunk,
60
+ listCortexModelsThunk: () => listCortexModelsThunk,
61
+ listMemoryRemoteThunk: () => listMemoryRemoteThunk,
62
+ listRulePresetsThunk: () => listRulePresetsThunk,
63
+ listRulesetsThunk: () => listRulesetsThunk,
51
64
  loadBridgePresetThunk: () => loadBridgePresetThunk,
52
65
  localExportSoulThunk: () => localExportSoulThunk,
53
66
  memoise: () => memoise,
@@ -63,13 +76,19 @@ __export(index_exports, {
63
76
  npcSlice: () => npcSlice,
64
77
  pipe: () => pipe,
65
78
  processNPC: () => processNPC,
79
+ recallMemoryRemoteThunk: () => recallMemoryRemoteThunk,
80
+ registerRulesetThunk: () => registerRulesetThunk,
66
81
  remoteExportSoulThunk: () => remoteExportSoulThunk,
67
82
  removeNPC: () => removeNPC,
68
83
  sdkApi: () => sdkApi,
84
+ selectActiveDirective: () => selectActiveDirective,
85
+ selectActiveDirectiveId: () => selectActiveDirectiveId,
69
86
  selectActiveNPC: () => selectActiveNPC,
70
87
  selectActiveNpcId: () => selectActiveNpcId,
88
+ selectAllDirectives: () => selectAllDirectives,
71
89
  selectAllMemories: () => selectAllMemories,
72
90
  selectAllNPCs: () => selectAllNPCs,
91
+ selectDirectiveById: () => selectDirectiveById,
73
92
  selectLastRecalledMemories: () => selectLastRecalledMemories,
74
93
  selectMemoryById: () => selectMemoryById,
75
94
  selectNPCById: () => selectNPCById,
@@ -83,17 +102,19 @@ __export(index_exports, {
83
102
  setNPCInfo: () => setNPCInfo,
84
103
  setNPCState: () => setNPCState,
85
104
  soulSlice: () => soulSlice,
86
- speakNPC: () => speakNPC,
87
105
  startGhostThunk: () => startGhostThunk,
88
106
  stopGhostThunk: () => stopGhostThunk,
89
107
  store: () => store,
108
+ storeMemoryRemoteThunk: () => storeMemoryRemoteThunk,
90
109
  streamFromCortex: () => streamFromCortex,
91
110
  streamFromCortexWithDelay: () => streamFromCortexWithDelay,
92
111
  streamToCallback: () => streamToCallback,
93
112
  streamToString: () => streamToString,
94
113
  updateNPCState: () => updateNPCState,
95
114
  updateNPCStateLocally: () => updateNPCStateLocally,
96
- validateBridgeThunk: () => validateBridgeThunk
115
+ validateBridgeThunk: () => validateBridgeThunk,
116
+ verdictValidated: () => verdictValidated,
117
+ verifySoulThunk: () => verifySoulThunk
97
118
  });
98
119
  module.exports = __toCommonJS(index_exports);
99
120
 
@@ -125,8 +146,28 @@ var sdkApi = (0, import_query.createApi)({
125
146
  return headers;
126
147
  }
127
148
  }),
128
- tagTypes: ["NPC", "Memory", "Cortex", "Ghost", "Soul", "Bridge"],
149
+ tagTypes: ["NPC", "Memory", "Cortex", "Ghost", "Soul", "Bridge", "Rule"],
129
150
  endpoints: (builder) => ({
151
+ // Cortex Endpoints
152
+ getCortexModels: builder.query({
153
+ query: ({ apiUrl, apiKey }) => ({
154
+ url: `${apiUrl}/cortex/models`,
155
+ method: "GET",
156
+ headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {}
157
+ }),
158
+ providesTags: ["Cortex"],
159
+ transformResponse: (response) => response || []
160
+ }),
161
+ postCortexInit: builder.mutation({
162
+ query: ({ request, apiUrl, apiKey }) => ({
163
+ url: `${apiUrl}/cortex/init`,
164
+ method: "POST",
165
+ headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {},
166
+ body: request
167
+ }),
168
+ invalidatesTags: ["Cortex"],
169
+ transformResponse: (response) => response
170
+ }),
130
171
  // NPC Endpoints
131
172
  postDirective: builder.mutation({
132
173
  query: ({ npcId, request, apiUrl, apiKey }) => ({
@@ -169,88 +210,214 @@ var sdkApi = (0, import_query.createApi)({
169
210
  };
170
211
  }
171
212
  }),
172
- postSpeak: builder.mutation({
213
+ postMemoryStore: builder.mutation({
173
214
  query: ({ npcId, request, apiUrl, apiKey }) => ({
174
- url: `${apiUrl}/npcs/${npcId}/speak`,
215
+ url: `${apiUrl}/npcs/${npcId}/memory`,
175
216
  method: "POST",
176
217
  headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {},
177
218
  body: request
178
219
  }),
179
- invalidatesTags: (result, error, { npcId }) => [{ type: "NPC", id: npcId }],
220
+ invalidatesTags: (result, error, { npcId }) => [{ type: "Memory", id: npcId }],
180
221
  transformResponse: (response) => response
181
222
  }),
182
- postDialogue: builder.mutation({
223
+ getMemoryList: builder.query({
224
+ query: ({ npcId, apiUrl, apiKey }) => ({
225
+ url: `${apiUrl}/npcs/${npcId}/memory`,
226
+ method: "GET",
227
+ headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {}
228
+ }),
229
+ providesTags: (result, error, { npcId }) => [{ type: "Memory", id: npcId }],
230
+ transformResponse: (response) => response || []
231
+ }),
232
+ postMemoryRecall: builder.mutation({
183
233
  query: ({ npcId, request, apiUrl, apiKey }) => ({
184
- url: `${apiUrl}/npcs/${npcId}/dialogue`,
234
+ url: `${apiUrl}/npcs/${npcId}/memory/recall`,
185
235
  method: "POST",
186
236
  headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {},
187
237
  body: request
188
238
  }),
189
- invalidatesTags: (result, error, { npcId }) => [{ type: "NPC", id: npcId }],
239
+ invalidatesTags: (result, error, { npcId }) => [{ type: "Memory", id: npcId }],
240
+ transformResponse: (response) => response || []
241
+ }),
242
+ deleteMemoryClear: builder.mutation({
243
+ query: ({ npcId, apiUrl, apiKey }) => ({
244
+ url: `${apiUrl}/npcs/${npcId}/memory/clear`,
245
+ method: "DELETE",
246
+ headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {}
247
+ }),
248
+ invalidatesTags: (result, error, { npcId }) => [{ type: "Memory", id: npcId }],
190
249
  transformResponse: (response) => response
191
250
  }),
192
251
  // Ghost Endpoints
193
252
  postGhostRun: builder.mutation({
194
- query: ({ request, apiUrl }) => ({ url: `${apiUrl}/ghost/run`, method: "POST", body: request }),
253
+ query: ({ request, apiUrl, apiKey }) => ({
254
+ url: `${apiUrl}/ghost/run`,
255
+ method: "POST",
256
+ headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {},
257
+ body: request
258
+ }),
195
259
  invalidatesTags: ["Ghost"],
196
260
  transformResponse: (response) => response
197
261
  }),
198
262
  getGhostStatus: builder.query({
199
- query: ({ sessionId, apiUrl }) => ({ url: `${apiUrl}/ghost/${sessionId}/status`, method: "GET" }),
263
+ query: ({ sessionId, apiUrl, apiKey }) => ({
264
+ url: `${apiUrl}/ghost/${sessionId}/status`,
265
+ method: "GET",
266
+ headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {}
267
+ }),
200
268
  providesTags: (result, error, { sessionId }) => [{ type: "Ghost", id: sessionId }],
201
269
  transformResponse: (response) => response
202
270
  }),
203
271
  getGhostResults: builder.query({
204
- query: ({ sessionId, apiUrl }) => ({ url: `${apiUrl}/ghost/${sessionId}/results`, method: "GET" }),
272
+ query: ({ sessionId, apiUrl, apiKey }) => ({
273
+ url: `${apiUrl}/ghost/${sessionId}/results`,
274
+ method: "GET",
275
+ headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {}
276
+ }),
205
277
  providesTags: (result, error, { sessionId }) => [{ type: "Ghost", id: sessionId }],
206
278
  transformResponse: (response) => response
207
279
  }),
208
280
  postGhostStop: builder.mutation({
209
- query: ({ sessionId, apiUrl }) => ({ url: `${apiUrl}/ghost/${sessionId}/stop`, method: "POST" }),
281
+ query: ({ sessionId, apiUrl, apiKey }) => ({
282
+ url: `${apiUrl}/ghost/${sessionId}/stop`,
283
+ method: "POST",
284
+ headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {}
285
+ }),
210
286
  invalidatesTags: (result, error, { sessionId }) => [{ type: "Ghost", id: sessionId }],
211
- transformResponse: (response) => ({ stopped: true })
287
+ transformResponse: (response) => ({
288
+ stopped: response?.stopStatus === "stopped",
289
+ stopStatus: response?.stopStatus,
290
+ stopSessionId: response?.stopSessionId
291
+ })
212
292
  }),
213
293
  getGhostHistory: builder.query({
214
- query: ({ limit, apiUrl }) => ({ url: `${apiUrl}/ghost/history?limit=${limit}`, method: "GET" }),
294
+ query: ({ limit, apiUrl, apiKey }) => ({
295
+ url: `${apiUrl}/ghost/history?limit=${limit}`,
296
+ method: "GET",
297
+ headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {}
298
+ }),
215
299
  providesTags: ["Ghost"],
216
300
  transformResponse: (response) => response
217
301
  }),
218
302
  // Soul Endpoints
219
303
  postSoulExport: builder.mutation({
220
- query: ({ npcId, request, apiUrl }) => ({ url: `${apiUrl}/npcs/${npcId}/soul/export`, method: "POST", body: request }),
304
+ query: ({ npcId, request, apiUrl, apiKey }) => ({
305
+ url: `${apiUrl}/npcs/${npcId}/soul/export`,
306
+ method: "POST",
307
+ headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {},
308
+ body: request
309
+ }),
221
310
  invalidatesTags: ["Soul"],
222
311
  transformResponse: (response) => response
223
312
  }),
224
313
  getSoulImport: builder.query({
225
- query: ({ txId, apiUrl }) => ({ url: `${apiUrl}/souls/${txId}`, method: "GET" }),
314
+ query: ({ txId, apiUrl, apiKey }) => ({
315
+ url: `${apiUrl}/souls/${txId}`,
316
+ method: "GET",
317
+ headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {}
318
+ }),
226
319
  providesTags: (result, error, { txId }) => [{ type: "Soul", id: txId }],
227
320
  transformResponse: (response) => response
228
321
  }),
229
322
  getSouls: builder.query({
230
- query: ({ limit, apiUrl }) => ({ url: `${apiUrl}/souls?limit=${limit}`, method: "GET" }),
323
+ query: ({ limit, apiUrl, apiKey }) => ({
324
+ url: `${apiUrl}/souls?limit=${limit}`,
325
+ method: "GET",
326
+ headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {}
327
+ }),
231
328
  providesTags: ["Soul"],
232
329
  transformResponse: (response) => response
233
330
  }),
234
331
  // Bridge Endpoints
235
332
  postBridgeValidate: builder.mutation({
236
- query: ({ request, npcId, apiUrl }) => ({
333
+ query: ({ request, npcId, apiUrl, apiKey }) => ({
237
334
  url: npcId ? `${apiUrl}/bridge/validate/${npcId}` : `${apiUrl}/bridge/validate`,
238
335
  method: "POST",
336
+ headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {},
239
337
  body: request
240
338
  }),
241
339
  invalidatesTags: ["Bridge"],
242
340
  transformResponse: (response) => response.brResult || response
243
341
  }),
244
342
  getBridgeRules: builder.query({
245
- query: ({ apiUrl }) => ({ url: `${apiUrl}/rules`, method: "GET" }),
343
+ query: ({ apiUrl, apiKey }) => ({
344
+ url: `${apiUrl}/bridge/rules`,
345
+ method: "GET",
346
+ headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {}
347
+ }),
246
348
  providesTags: ["Bridge"],
247
349
  transformResponse: (response) => response
248
350
  }),
249
351
  postBridgePreset: builder.mutation({
250
- query: ({ presetName, apiUrl }) => ({ url: `${apiUrl}/rules/presets/${presetName}`, method: "POST" }),
352
+ query: ({ presetName, apiUrl, apiKey }) => ({
353
+ url: `${apiUrl}/rules/presets/${presetName}`,
354
+ method: "POST",
355
+ headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {}
356
+ }),
251
357
  invalidatesTags: ["Bridge"],
252
358
  transformResponse: (response) => response
253
359
  }),
360
+ // Rules Endpoints
361
+ getRulesets: builder.query({
362
+ query: ({ apiUrl, apiKey }) => ({
363
+ url: `${apiUrl}/rules`,
364
+ method: "GET",
365
+ headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {}
366
+ }),
367
+ providesTags: ["Rule"],
368
+ transformResponse: (response) => response || []
369
+ }),
370
+ getRulePresets: builder.query({
371
+ query: ({ apiUrl, apiKey }) => ({
372
+ url: `${apiUrl}/rules/presets`,
373
+ method: "GET",
374
+ headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {}
375
+ }),
376
+ providesTags: ["Rule"],
377
+ transformResponse: (response) => response || []
378
+ }),
379
+ postRuleRegister: builder.mutation({
380
+ query: ({ request, apiUrl, apiKey }) => ({
381
+ url: `${apiUrl}/rules`,
382
+ method: "POST",
383
+ headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {},
384
+ body: request
385
+ }),
386
+ invalidatesTags: ["Rule"],
387
+ transformResponse: (response) => response
388
+ }),
389
+ deleteRule: builder.mutation({
390
+ query: ({ rulesetId, apiUrl, apiKey }) => ({
391
+ url: `${apiUrl}/rules/${rulesetId}`,
392
+ method: "DELETE",
393
+ headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {}
394
+ }),
395
+ invalidatesTags: ["Rule"],
396
+ transformResponse: (_response) => ({ deleted: true })
397
+ }),
398
+ // Additional Soul/NPC Endpoints
399
+ postSoulVerify: builder.mutation({
400
+ query: ({ txId, apiUrl, apiKey }) => ({
401
+ url: `${apiUrl}/souls/${txId}/verify`,
402
+ method: "POST",
403
+ headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {}
404
+ }),
405
+ invalidatesTags: ["Soul"],
406
+ transformResponse: (response) => ({
407
+ valid: response.verifyValid ?? response.valid ?? false,
408
+ reason: response.verifyReason ?? response.reason
409
+ })
410
+ }),
411
+ postNpcImport: builder.mutation({
412
+ query: ({ request, apiUrl, apiKey }) => ({
413
+ url: `${apiUrl}/npcs/import`,
414
+ method: "POST",
415
+ headers: apiKey ? { "Authorization": `Bearer ${apiKey}` } : {},
416
+ body: request
417
+ }),
418
+ invalidatesTags: ["NPC"],
419
+ transformResponse: (response) => response
420
+ }),
254
421
  // Cortex Remote Endpoint
255
422
  postCortexComplete: builder.mutation({
256
423
  query: ({ cortexId, prompt, options, apiUrl, apiKey }) => ({
@@ -273,19 +440,22 @@ var sdkApi = (0, import_query.createApi)({
273
440
  // src/bridgeSlice.ts
274
441
  var initialState = {
275
442
  activePresets: [],
443
+ availableRulesets: [],
444
+ availablePresetIds: [],
276
445
  lastValidation: null,
277
446
  status: "idle",
278
447
  error: null
279
448
  };
280
449
  var validateBridgeThunk = (0, import_toolkit.createAsyncThunk)(
281
450
  "bridge/validate",
282
- async ({ action, context, npcId, apiUrl }, { dispatch: dispatch2, rejectWithValue }) => {
451
+ async ({ action, context, npcId, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
283
452
  try {
284
453
  const url = apiUrl || "https://api.forboc.ai";
285
454
  const data = await dispatch2(sdkApi.endpoints.postBridgeValidate.initiate({
286
455
  request: { action, context },
287
456
  npcId,
288
- apiUrl: url
457
+ apiUrl: url,
458
+ apiKey
289
459
  })).unwrap();
290
460
  return data;
291
461
  } catch (e) {
@@ -295,10 +465,10 @@ var validateBridgeThunk = (0, import_toolkit.createAsyncThunk)(
295
465
  );
296
466
  var loadBridgePresetThunk = (0, import_toolkit.createAsyncThunk)(
297
467
  "bridge/loadPreset",
298
- async ({ presetName, apiUrl }, { dispatch: dispatch2, rejectWithValue }) => {
468
+ async ({ presetName, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
299
469
  try {
300
470
  const url = apiUrl || "https://api.forboc.ai";
301
- return await dispatch2(sdkApi.endpoints.postBridgePreset.initiate({ presetName, apiUrl: url })).unwrap();
471
+ return await dispatch2(sdkApi.endpoints.postBridgePreset.initiate({ presetName, apiUrl: url, apiKey })).unwrap();
302
472
  } catch (e) {
303
473
  return rejectWithValue(e.message || "Failed to load preset");
304
474
  }
@@ -306,15 +476,59 @@ var loadBridgePresetThunk = (0, import_toolkit.createAsyncThunk)(
306
476
  );
307
477
  var getBridgeRulesThunk = (0, import_toolkit.createAsyncThunk)(
308
478
  "bridge/rules",
309
- async ({ apiUrl }, { dispatch: dispatch2, rejectWithValue }) => {
479
+ async ({ apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
310
480
  try {
311
481
  const url = apiUrl || "https://api.forboc.ai";
312
- return await dispatch2(sdkApi.endpoints.getBridgeRules.initiate({ apiUrl: url })).unwrap();
482
+ return await dispatch2(sdkApi.endpoints.getBridgeRules.initiate({ apiUrl: url, apiKey })).unwrap();
483
+ } catch (e) {
484
+ return rejectWithValue(e.message || "Failed to list bridge rules");
485
+ }
486
+ }
487
+ );
488
+ var listRulesetsThunk = (0, import_toolkit.createAsyncThunk)(
489
+ "bridge/listRulesets",
490
+ async ({ apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
491
+ try {
492
+ const url = apiUrl || "https://api.forboc.ai";
493
+ return await dispatch2(sdkApi.endpoints.getRulesets.initiate({ apiUrl: url, apiKey })).unwrap();
313
494
  } catch (e) {
314
495
  return rejectWithValue(e.message || "Failed to list rulesets");
315
496
  }
316
497
  }
317
498
  );
499
+ var listRulePresetsThunk = (0, import_toolkit.createAsyncThunk)(
500
+ "bridge/listRulePresets",
501
+ async ({ apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
502
+ try {
503
+ const url = apiUrl || "https://api.forboc.ai";
504
+ return await dispatch2(sdkApi.endpoints.getRulePresets.initiate({ apiUrl: url, apiKey })).unwrap();
505
+ } catch (e) {
506
+ return rejectWithValue(e.message || "Failed to list rule presets");
507
+ }
508
+ }
509
+ );
510
+ var registerRulesetThunk = (0, import_toolkit.createAsyncThunk)(
511
+ "bridge/registerRuleset",
512
+ async ({ ruleset, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
513
+ try {
514
+ const url = apiUrl || "https://api.forboc.ai";
515
+ return await dispatch2(sdkApi.endpoints.postRuleRegister.initiate({ request: ruleset, apiUrl: url, apiKey })).unwrap();
516
+ } catch (e) {
517
+ return rejectWithValue(e.message || "Failed to register ruleset");
518
+ }
519
+ }
520
+ );
521
+ var deleteRulesetThunk = (0, import_toolkit.createAsyncThunk)(
522
+ "bridge/deleteRuleset",
523
+ async ({ rulesetId, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
524
+ try {
525
+ const url = apiUrl || "https://api.forboc.ai";
526
+ return await dispatch2(sdkApi.endpoints.deleteRule.initiate({ rulesetId, apiUrl: url, apiKey })).unwrap();
527
+ } catch (e) {
528
+ return rejectWithValue(e.message || "Failed to delete ruleset");
529
+ }
530
+ }
531
+ );
318
532
  var bridgeSlice = (0, import_toolkit.createSlice)({
319
533
  name: "bridge",
320
534
  initialState,
@@ -348,6 +562,10 @@ var bridgeSlice = (0, import_toolkit.createSlice)({
348
562
  state.status = "error";
349
563
  state.error = action.payload;
350
564
  }).addCase(getBridgeRulesThunk.fulfilled, (state, action) => {
565
+ }).addCase(listRulesetsThunk.fulfilled, (state, action) => {
566
+ state.availableRulesets = action.payload;
567
+ }).addCase(listRulePresetsThunk.fulfilled, (state, action) => {
568
+ state.availablePresetIds = action.payload;
351
569
  });
352
570
  }
353
571
  });
@@ -366,7 +584,7 @@ var initialState2 = {
366
584
  };
367
585
  var remoteExportSoulThunk = (0, import_toolkit2.createAsyncThunk)(
368
586
  "soul/export",
369
- async ({ npcId: argNpcId, apiUrl, memories = [] }, { getState, dispatch: dispatch2, rejectWithValue }) => {
587
+ async ({ npcId: argNpcId, apiUrl, apiKey, memories = [] }, { getState, dispatch: dispatch2, rejectWithValue }) => {
370
588
  try {
371
589
  const state = getState().npc;
372
590
  const npcId = argNpcId || state.activeNpcId;
@@ -376,7 +594,8 @@ var remoteExportSoulThunk = (0, import_toolkit2.createAsyncThunk)(
376
594
  const result = await dispatch2(sdkApi.endpoints.postSoulExport.initiate({
377
595
  npcId,
378
596
  request: { npcIdRef: npcId, persona: npc.persona || "NPC", npcState: npc.state },
379
- apiUrl: url
597
+ apiUrl: url,
598
+ apiKey
380
599
  })).unwrap();
381
600
  return {
382
601
  txId: result.txId,
@@ -390,10 +609,10 @@ var remoteExportSoulThunk = (0, import_toolkit2.createAsyncThunk)(
390
609
  );
391
610
  var importSoulFromArweaveThunk = (0, import_toolkit2.createAsyncThunk)(
392
611
  "soul/import",
393
- async ({ txId, apiUrl }, { dispatch: dispatch2, rejectWithValue }) => {
612
+ async ({ txId, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
394
613
  try {
395
614
  const url = apiUrl || "https://api.forboc.ai";
396
- const data = await dispatch2(sdkApi.endpoints.getSoulImport.initiate({ txId, apiUrl: url })).unwrap();
615
+ const data = await dispatch2(sdkApi.endpoints.getSoulImport.initiate({ txId, apiUrl: url, apiKey })).unwrap();
397
616
  return data;
398
617
  } catch (e) {
399
618
  return rejectWithValue(e.message || "Soul import failed");
@@ -402,16 +621,42 @@ var importSoulFromArweaveThunk = (0, import_toolkit2.createAsyncThunk)(
402
621
  );
403
622
  var getSoulListThunk = (0, import_toolkit2.createAsyncThunk)(
404
623
  "soul/list",
405
- async ({ limit = 50, apiUrl }, { dispatch: dispatch2, rejectWithValue }) => {
624
+ async ({ limit = 50, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
406
625
  try {
407
626
  const url = apiUrl || "https://api.forboc.ai";
408
- const data = await dispatch2(sdkApi.endpoints.getSouls.initiate({ limit, apiUrl: url })).unwrap();
627
+ const data = await dispatch2(sdkApi.endpoints.getSouls.initiate({ limit, apiUrl: url, apiKey })).unwrap();
409
628
  return data.souls || [];
410
629
  } catch (e) {
411
630
  return rejectWithValue(e.message || "Failed to list souls");
412
631
  }
413
632
  }
414
633
  );
634
+ var verifySoulThunk = (0, import_toolkit2.createAsyncThunk)(
635
+ "soul/verify",
636
+ async ({ txId, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
637
+ try {
638
+ const url = apiUrl || "https://api.forboc.ai";
639
+ return await dispatch2(sdkApi.endpoints.postSoulVerify.initiate({ txId, apiUrl: url, apiKey })).unwrap();
640
+ } catch (e) {
641
+ return rejectWithValue(e.message || "Soul verify failed");
642
+ }
643
+ }
644
+ );
645
+ var importNpcFromSoulThunk = (0, import_toolkit2.createAsyncThunk)(
646
+ "soul/importNpc",
647
+ async ({ txId, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
648
+ try {
649
+ const url = apiUrl || "https://api.forboc.ai";
650
+ return await dispatch2(sdkApi.endpoints.postNpcImport.initiate({
651
+ request: { txIdRef: txId },
652
+ apiUrl: url,
653
+ apiKey
654
+ })).unwrap();
655
+ } catch (e) {
656
+ return rejectWithValue(e.message || "NPC import from soul failed");
657
+ }
658
+ }
659
+ );
415
660
  var soulSlice = (0, import_toolkit2.createSlice)({
416
661
  name: "soul",
417
662
  initialState: initialState2,
@@ -469,7 +714,8 @@ var startGhostThunk = (0, import_toolkit3.createAsyncThunk)(
469
714
  const apiUrl = config.apiUrl || "https://api.forboc.ai";
470
715
  const data = await dispatch2(sdkApi.endpoints.postGhostRun.initiate({
471
716
  request: { testSuite: config.testSuite, duration: config.duration ?? 300 },
472
- apiUrl
717
+ apiUrl,
718
+ apiKey: config.apiKey
473
719
  })).unwrap();
474
720
  return {
475
721
  sessionId: data.sessionId,
@@ -482,13 +728,13 @@ var startGhostThunk = (0, import_toolkit3.createAsyncThunk)(
482
728
  );
483
729
  var getGhostStatusThunk = (0, import_toolkit3.createAsyncThunk)(
484
730
  "ghost/status",
485
- async ({ sessionId, apiUrl }, { dispatch: dispatch2, getState, rejectWithValue }) => {
731
+ async ({ sessionId, apiUrl, apiKey }, { dispatch: dispatch2, getState, rejectWithValue }) => {
486
732
  try {
487
733
  const state = getState().ghost;
488
734
  const targetSession = sessionId || state.activeSessionId;
489
735
  if (!targetSession) throw new Error("No active Ghost session");
490
736
  const url = apiUrl || "https://api.forboc.ai";
491
- const data = await dispatch2(sdkApi.endpoints.getGhostStatus.initiate({ sessionId: targetSession, apiUrl: url })).unwrap();
737
+ const data = await dispatch2(sdkApi.endpoints.getGhostStatus.initiate({ sessionId: targetSession, apiUrl: url, apiKey })).unwrap();
492
738
  return {
493
739
  sessionId: data.ghostSessionId,
494
740
  status: data.ghostStatus,
@@ -504,13 +750,13 @@ var getGhostStatusThunk = (0, import_toolkit3.createAsyncThunk)(
504
750
  );
505
751
  var getGhostResultsThunk = (0, import_toolkit3.createAsyncThunk)(
506
752
  "ghost/results",
507
- async ({ sessionId, apiUrl }, { dispatch: dispatch2, getState, rejectWithValue }) => {
753
+ async ({ sessionId, apiUrl, apiKey }, { dispatch: dispatch2, getState, rejectWithValue }) => {
508
754
  try {
509
755
  const state = getState().ghost;
510
756
  const targetSession = sessionId || state.activeSessionId;
511
757
  if (!targetSession) throw new Error("No active Ghost session");
512
758
  const url = apiUrl || "https://api.forboc.ai";
513
- const data = await dispatch2(sdkApi.endpoints.getGhostResults.initiate({ sessionId: targetSession, apiUrl: url })).unwrap();
759
+ const data = await dispatch2(sdkApi.endpoints.getGhostResults.initiate({ sessionId: targetSession, apiUrl: url, apiKey })).unwrap();
514
760
  return {
515
761
  sessionId: data.resultsSessionId,
516
762
  totalTests: data.resultsTotalTests,
@@ -535,25 +781,29 @@ var getGhostResultsThunk = (0, import_toolkit3.createAsyncThunk)(
535
781
  );
536
782
  var stopGhostThunk = (0, import_toolkit3.createAsyncThunk)(
537
783
  "ghost/stop",
538
- async ({ sessionId, apiUrl }, { dispatch: dispatch2, getState, rejectWithValue }) => {
784
+ async ({ sessionId, apiUrl, apiKey }, { dispatch: dispatch2, getState, rejectWithValue }) => {
539
785
  try {
540
786
  const state = getState().ghost;
541
787
  const targetSession = sessionId || state.activeSessionId;
542
788
  if (!targetSession) throw new Error("No active Ghost session");
543
789
  const url = apiUrl || "https://api.forboc.ai";
544
- await dispatch2(sdkApi.endpoints.postGhostStop.initiate({ sessionId: targetSession, apiUrl: url })).unwrap();
545
- return { stopped: true };
790
+ const data = await dispatch2(sdkApi.endpoints.postGhostStop.initiate({ sessionId: targetSession, apiUrl: url, apiKey })).unwrap();
791
+ return {
792
+ stopped: data.stopped,
793
+ status: data.stopStatus,
794
+ sessionId: data.stopSessionId
795
+ };
546
796
  } catch (e) {
547
- return { stopped: true };
797
+ return rejectWithValue(e.message || "Failed to stop ghost session");
548
798
  }
549
799
  }
550
800
  );
551
801
  var getGhostHistoryThunk = (0, import_toolkit3.createAsyncThunk)(
552
802
  "ghost/history",
553
- async ({ limit = 10, apiUrl }, { dispatch: dispatch2, rejectWithValue }) => {
803
+ async ({ limit = 10, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
554
804
  try {
555
805
  const url = apiUrl || "https://api.forboc.ai";
556
- const data = await dispatch2(sdkApi.endpoints.getGhostHistory.initiate({ limit, apiUrl: url })).unwrap();
806
+ const data = await dispatch2(sdkApi.endpoints.getGhostHistory.initiate({ limit, apiUrl: url, apiKey })).unwrap();
557
807
  return (data.sessions || []).map((s) => ({
558
808
  sessionId: s.sessionId,
559
809
  testSuite: s.testSuite,
@@ -596,8 +846,14 @@ var ghostSlice = (0, import_toolkit3.createSlice)({
596
846
  }).addCase(getGhostResultsThunk.fulfilled, (state, action) => {
597
847
  state.results = action.payload;
598
848
  state.status = "completed";
599
- }).addCase(stopGhostThunk.fulfilled, (state) => {
600
- state.status = "failed";
849
+ }).addCase(stopGhostThunk.fulfilled, (state, action) => {
850
+ if (action.payload.stopped) {
851
+ state.status = "failed";
852
+ } else {
853
+ state.error = action.payload.status || "Ghost stop request did not stop a session";
854
+ }
855
+ }).addCase(stopGhostThunk.rejected, (state, action) => {
856
+ state.error = action.payload;
601
857
  }).addCase(getGhostHistoryThunk.fulfilled, (state, action) => {
602
858
  state.history = action.payload;
603
859
  });
@@ -606,11 +862,19 @@ var ghostSlice = (0, import_toolkit3.createSlice)({
606
862
  var { clearGhostSession } = ghostSlice.actions;
607
863
  var ghostSlice_default = ghostSlice.reducer;
608
864
 
609
- // src/utils.ts
610
- var SDK_VERSION = "0.5.9";
865
+ // src/utils/sdkVersion.ts
866
+ var SDK_VERSION = "0.6.0";
867
+
868
+ // src/utils/generateNPCId.ts
611
869
  var generateNPCId = () => `ag_${Date.now().toString(36)}`;
870
+
871
+ // src/utils/delay.ts
612
872
  var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
873
+
874
+ // src/utils/pipe.ts
613
875
  var pipe = (...fns) => (initialValue) => fns.reduce((acc, fn) => fn(acc), initialValue);
876
+
877
+ // src/utils/memoiseAsync.ts
614
878
  var memoiseAsync = (fn) => {
615
879
  let cached = null;
616
880
  let promise = null;
@@ -624,6 +888,8 @@ var memoiseAsync = (fn) => {
624
888
  return promise;
625
889
  };
626
890
  };
891
+
892
+ // src/utils/memoise.ts
627
893
  var memoise = (fn) => {
628
894
  let cached = null;
629
895
  let initialized = false;
@@ -660,7 +926,7 @@ var streamFromCortexWithDelay = async (cortex, prompt, onChunk, options) => {
660
926
  };
661
927
 
662
928
  // src/store.ts
663
- var import_toolkit8 = require("@reduxjs/toolkit");
929
+ var import_toolkit9 = require("@reduxjs/toolkit");
664
930
 
665
931
  // src/npcSlice.ts
666
932
  var import_toolkit4 = require("@reduxjs/toolkit");
@@ -760,13 +1026,34 @@ var initialState4 = {
760
1026
  };
761
1027
  var initRemoteCortexThunk = (0, import_toolkit5.createAsyncThunk)(
762
1028
  "cortex/initRemote",
763
- async ({ model = "api-integrated" }) => {
764
- return {
765
- id: `remote_${Date.now()}`,
766
- model,
767
- ready: true,
768
- engine: "remote"
769
- };
1029
+ async ({ model = "api-integrated", authKey, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
1030
+ try {
1031
+ const url = apiUrl || "https://api.forboc.ai";
1032
+ const data = await dispatch2(sdkApi.endpoints.postCortexInit.initiate({
1033
+ request: { requestedModel: model, authKey },
1034
+ apiUrl: url,
1035
+ apiKey
1036
+ })).unwrap();
1037
+ return {
1038
+ id: data.cortexId,
1039
+ model,
1040
+ ready: data.state?.toLowerCase() === "ready",
1041
+ engine: "remote"
1042
+ };
1043
+ } catch (e) {
1044
+ return rejectWithValue(e.message || "Remote cortex init failed");
1045
+ }
1046
+ }
1047
+ );
1048
+ var listCortexModelsThunk = (0, import_toolkit5.createAsyncThunk)(
1049
+ "cortex/listModels",
1050
+ async ({ apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
1051
+ try {
1052
+ const url = apiUrl || "https://api.forboc.ai";
1053
+ return await dispatch2(sdkApi.endpoints.getCortexModels.initiate({ apiUrl: url, apiKey })).unwrap();
1054
+ } catch (e) {
1055
+ return rejectWithValue(e.message || "Failed to list cortex models");
1056
+ }
770
1057
  }
771
1058
  );
772
1059
  var completeRemoteThunk = (0, import_toolkit5.createAsyncThunk)(
@@ -885,15 +1172,108 @@ var selectLastRecalledMemories = (state) => {
885
1172
  };
886
1173
  var memorySlice_default = memorySlice.reducer;
887
1174
 
888
- // src/listeners.ts
1175
+ // src/directiveSlice.ts
889
1176
  var import_toolkit7 = require("@reduxjs/toolkit");
890
- var sdkListenerMiddleware = (0, import_toolkit7.createListenerMiddleware)();
1177
+ var directiveAdapter = (0, import_toolkit7.createEntityAdapter)();
1178
+ var directiveSlice = (0, import_toolkit7.createSlice)({
1179
+ name: "directive",
1180
+ initialState: directiveAdapter.getInitialState({
1181
+ activeDirectiveId: ""
1182
+ }),
1183
+ reducers: {
1184
+ directiveRunStarted: (state, action) => {
1185
+ const { id, npcId, observation } = action.payload;
1186
+ directiveAdapter.upsertOne(state, {
1187
+ id,
1188
+ npcId,
1189
+ observation,
1190
+ status: "running",
1191
+ startedAt: Date.now()
1192
+ });
1193
+ state.activeDirectiveId = id;
1194
+ },
1195
+ directiveReceived: (state, action) => {
1196
+ const { id, response } = action.payload;
1197
+ directiveAdapter.updateOne(state, {
1198
+ id,
1199
+ changes: { memoryRecall: response.memoryRecall }
1200
+ });
1201
+ },
1202
+ contextComposed: (state, action) => {
1203
+ const { id, prompt, constraints } = action.payload;
1204
+ directiveAdapter.updateOne(state, {
1205
+ id,
1206
+ changes: { contextPrompt: prompt, contextConstraints: constraints }
1207
+ });
1208
+ },
1209
+ verdictValidated: (state, action) => {
1210
+ const { id, verdict } = action.payload;
1211
+ directiveAdapter.updateOne(state, {
1212
+ id,
1213
+ changes: {
1214
+ status: "completed",
1215
+ completedAt: Date.now(),
1216
+ verdictValid: verdict.valid,
1217
+ verdictDialogue: verdict.dialogue,
1218
+ verdictActionType: verdict.action?.type
1219
+ }
1220
+ });
1221
+ },
1222
+ directiveRunFailed: (state, action) => {
1223
+ const { id, error } = action.payload;
1224
+ directiveAdapter.updateOne(state, {
1225
+ id,
1226
+ changes: {
1227
+ status: "failed",
1228
+ completedAt: Date.now(),
1229
+ error
1230
+ }
1231
+ });
1232
+ },
1233
+ clearDirectivesForNpc: (state, action) => {
1234
+ const npcId = action.payload;
1235
+ const idsToRemove = Object.values(state.entities).filter((item) => Boolean(item)).filter((item) => item.npcId === npcId).map((item) => item.id);
1236
+ directiveAdapter.removeMany(state, idsToRemove);
1237
+ if (idsToRemove.includes(state.activeDirectiveId)) {
1238
+ state.activeDirectiveId = "";
1239
+ }
1240
+ }
1241
+ }
1242
+ });
1243
+ var {
1244
+ directiveRunStarted,
1245
+ directiveReceived,
1246
+ contextComposed,
1247
+ verdictValidated,
1248
+ directiveRunFailed,
1249
+ clearDirectivesForNpc
1250
+ } = directiveSlice.actions;
1251
+ var {
1252
+ selectById: selectDirectiveById,
1253
+ selectAll: selectAllDirectives
1254
+ } = directiveAdapter.getSelectors((state) => state.directive);
1255
+ var selectActiveDirectiveId = (state) => state.directive.activeDirectiveId;
1256
+ var selectActiveDirective = (state) => {
1257
+ const id = selectActiveDirectiveId(state);
1258
+ return state.directive.entities[id];
1259
+ };
1260
+ var directiveSlice_default = directiveSlice.reducer;
1261
+
1262
+ // src/listeners.ts
1263
+ var import_toolkit8 = require("@reduxjs/toolkit");
1264
+ var sdkListenerMiddleware = (0, import_toolkit8.createListenerMiddleware)();
891
1265
  var startAppListening = sdkListenerMiddleware.startListening.withTypes();
892
1266
  startAppListening({
893
1267
  actionCreator: removeNPC,
894
1268
  effect: async (action, listenerApi) => {
1269
+ const removedNpcId = action.payload;
895
1270
  const state = listenerApi.getState();
896
- if (action.payload === state.npc.activeNpcId) {
1271
+ listenerApi.dispatch(clearDirectivesForNpc(removedNpcId));
1272
+ listenerApi.dispatch(clearBridgeValidation());
1273
+ listenerApi.dispatch(clearGhostSession());
1274
+ listenerApi.dispatch(clearSoulState());
1275
+ listenerApi.dispatch(clearBlock(removedNpcId));
1276
+ if (removedNpcId === state.npc.activeNpcId) {
897
1277
  listenerApi.dispatch(memoryClear());
898
1278
  }
899
1279
  }
@@ -901,12 +1281,13 @@ startAppListening({
901
1281
 
902
1282
  // src/store.ts
903
1283
  var createSDKStore = (extraReducers = {}) => {
904
- return (0, import_toolkit8.configureStore)({
1284
+ return (0, import_toolkit9.configureStore)({
905
1285
  reducer: {
906
1286
  [sdkApi.reducerPath]: sdkApi.reducer,
907
1287
  npc: npcSlice_default,
908
1288
  cortex: cortexSlice_default,
909
1289
  memory: memorySlice_default,
1290
+ directive: directiveSlice_default,
910
1291
  ghost: ghostSlice_default,
911
1292
  soul: soulSlice_default,
912
1293
  bridge: bridgeSlice_default,
@@ -922,128 +1303,184 @@ var store = createSDKStore();
922
1303
  var dispatch = store.dispatch;
923
1304
 
924
1305
  // src/thunks.ts
925
- var import_toolkit9 = require("@reduxjs/toolkit");
926
- var processNPC = (0, import_toolkit9.createAsyncThunk)(
1306
+ var import_toolkit10 = require("@reduxjs/toolkit");
1307
+ var processNPC = (0, import_toolkit10.createAsyncThunk)(
927
1308
  "npc/process",
928
- async ({ npcId: argNpcId, text, context = {}, apiUrl, apiKey, memory, cortex, persona: argPersona }, { getState, dispatch: dispatch2 }) => {
1309
+ async ({ npcId: argNpcId, text, context = {}, apiUrl, apiKey, memory, cortex, persona: argPersona }, { getState, dispatch: dispatch2, rejectWithValue }) => {
929
1310
  const stateNpcId = selectActiveNpcId(getState());
930
1311
  const activeNpc = selectActiveNPC(getState());
931
1312
  const npcId = argNpcId || stateNpcId;
932
1313
  const persona = argPersona || activeNpc?.persona;
933
1314
  const currentState = activeNpc?.state || {};
1315
+ if (!npcId) {
1316
+ return rejectWithValue("No npcId provided and no active NPC selected");
1317
+ }
1318
+ if (!persona) {
1319
+ return rejectWithValue("No persona provided and no active NPC persona available");
1320
+ }
1321
+ if (!cortex) {
1322
+ return rejectWithValue("No local cortex provided. SDK remote cortex fallback is disabled.");
1323
+ }
934
1324
  if (argNpcId && argNpcId !== stateNpcId) {
935
- dispatch2(setNPCInfo({ id: argNpcId, persona: persona || "Default" }));
1325
+ dispatch2(setNPCInfo({ id: argNpcId, persona }));
936
1326
  }
937
- const directiveResult = await dispatch2(
938
- sdkApi.endpoints.postDirective.initiate({ npcId, request: { observation: text, npcState: currentState, context }, apiUrl, apiKey })
939
- ).unwrap();
940
- const recalledMemories = memory && directiveResult.memoryRecall ? await memory.recall(
941
- directiveResult.memoryRecall.query,
942
- directiveResult.memoryRecall.limit,
943
- directiveResult.memoryRecall.threshold
944
- ).then((mems) => mems.map((m) => ({ text: m.text, type: m.type, importance: m.importance }))).catch(() => []) : [];
945
- const contextResult = await dispatch2(
946
- sdkApi.endpoints.postContext.initiate({ npcId, request: { memories: recalledMemories, observation: text, npcState: currentState, persona: persona || "Default" }, apiUrl, apiKey })
947
- ).unwrap();
948
- let generatedText = "";
949
- if (cortex) {
950
- generatedText = await cortex.complete(contextResult.prompt, {
1327
+ const directiveId = `${npcId}:${Date.now()}`;
1328
+ dispatch2(directiveRunStarted({ id: directiveId, npcId, observation: text }));
1329
+ try {
1330
+ const directiveResult = await dispatch2(
1331
+ sdkApi.endpoints.postDirective.initiate({ npcId, request: { observation: text, npcState: currentState, context }, apiUrl, apiKey })
1332
+ ).unwrap();
1333
+ dispatch2(directiveReceived({ id: directiveId, response: directiveResult }));
1334
+ if (directiveResult.memoryRecall && !memory) {
1335
+ return rejectWithValue("API requested memory recall, but no memory engine is configured");
1336
+ }
1337
+ const recalledMemories = memory && directiveResult.memoryRecall ? (await memory.recall(
1338
+ directiveResult.memoryRecall.query,
1339
+ directiveResult.memoryRecall.limit,
1340
+ directiveResult.memoryRecall.threshold
1341
+ )).map((m) => ({ text: m.text, type: m.type, importance: m.importance })) : [];
1342
+ const contextResult = await dispatch2(
1343
+ sdkApi.endpoints.postContext.initiate({ npcId, request: { memories: recalledMemories, observation: text, npcState: currentState, persona }, apiUrl, apiKey })
1344
+ ).unwrap();
1345
+ dispatch2(contextComposed({ id: directiveId, prompt: contextResult.prompt, constraints: contextResult.constraints }));
1346
+ const generatedText = await cortex.complete(contextResult.prompt, {
951
1347
  maxTokens: contextResult.constraints.maxTokens,
952
1348
  temperature: contextResult.constraints.temperature,
953
1349
  stop: contextResult.constraints.stop
954
1350
  });
955
- } else {
956
- const remoteResult = await dispatch2(sdkApi.endpoints.postCortexComplete.initiate({
957
- cortexId: "remote",
958
- // Or generic
959
- prompt: contextResult.prompt,
960
- options: contextResult.constraints,
961
- apiUrl,
962
- apiKey
963
- })).unwrap();
964
- generatedText = remoteResult.text || "";
965
- }
966
- const verdictResult = await dispatch2(
967
- sdkApi.endpoints.postVerdict.initiate({ npcId, request: { generatedOutput: generatedText, observation: text, npcState: currentState }, apiUrl, apiKey })
968
- ).unwrap();
969
- if (!verdictResult.valid) {
970
- dispatch2(blockAction({ id: npcId, reason: "Validation Failed" }));
971
- return { dialogue: "... [Blocked]", action: { type: "BLOCKED", reason: "Validation Failed" } };
972
- }
973
- if (memory && verdictResult.memoryStore) {
974
- for (const inst of verdictResult.memoryStore) {
975
- await memory.store(inst.text, inst.type, inst.importance).catch((e) => console.warn("Memory store failed:", e));
1351
+ const verdictResult = await dispatch2(
1352
+ sdkApi.endpoints.postVerdict.initiate({ npcId, request: { generatedOutput: generatedText, observation: text, npcState: currentState }, apiUrl, apiKey })
1353
+ ).unwrap();
1354
+ dispatch2(verdictValidated({ id: directiveId, verdict: verdictResult }));
1355
+ if (!verdictResult.valid) {
1356
+ dispatch2(blockAction({ id: npcId, reason: verdictResult.dialogue || "Validation Failed" }));
1357
+ return {
1358
+ dialogue: verdictResult.dialogue,
1359
+ action: verdictResult.action,
1360
+ thought: verdictResult.dialogue
1361
+ };
976
1362
  }
1363
+ if (verdictResult.memoryStore?.length && !memory) {
1364
+ return rejectWithValue("API returned memoryStore instructions, but no memory engine is configured");
1365
+ }
1366
+ if (memory && verdictResult.memoryStore) {
1367
+ for (const inst of verdictResult.memoryStore) {
1368
+ await memory.store(inst.text, inst.type, inst.importance);
1369
+ }
1370
+ }
1371
+ if (verdictResult.stateDelta) {
1372
+ dispatch2(updateNPCState({ id: npcId, delta: verdictResult.stateDelta }));
1373
+ }
1374
+ const action = verdictResult.action;
1375
+ dispatch2(setLastAction({ id: npcId, action }));
1376
+ dispatch2(addToHistory({ id: npcId, role: "user", content: text }));
1377
+ dispatch2(addToHistory({ id: npcId, role: "assistant", content: verdictResult.dialogue }));
1378
+ return {
1379
+ dialogue: verdictResult.dialogue,
1380
+ action,
1381
+ thought: verdictResult.dialogue
1382
+ };
1383
+ } catch (e) {
1384
+ const message = e?.message || e?.data?.message || "Protocol processing failed";
1385
+ dispatch2(directiveRunFailed({ id: directiveId, error: String(message) }));
1386
+ return rejectWithValue(String(message));
977
1387
  }
978
- if (verdictResult.stateDelta) {
979
- dispatch2(updateNPCState({ id: npcId, delta: verdictResult.stateDelta }));
980
- }
981
- const action = verdictResult.action ? { ...verdictResult.action, signature: verdictResult.signature } : void 0;
982
- dispatch2(setLastAction({ id: npcId, action }));
983
- dispatch2(addToHistory({ id: npcId, role: "user", content: text }));
984
- dispatch2(addToHistory({ id: npcId, role: "assistant", content: verdictResult.dialogue }));
985
- return {
986
- dialogue: verdictResult.dialogue,
987
- action,
988
- thought: verdictResult.dialogue
989
- };
990
- }
991
- );
992
- var speakNPC = (0, import_toolkit9.createAsyncThunk)(
993
- "npc/speak",
994
- async ({ npcId: argNpcId, text, context = {}, apiUrl, apiKey }, { getState, dispatch: dispatch2 }) => {
995
- const stateNpcId = selectActiveNpcId(getState());
996
- const activeNpc = selectActiveNPC(getState());
997
- const npcId = argNpcId || stateNpcId;
998
- const currentState = activeNpc?.state || {};
999
- const data = await dispatch2(sdkApi.endpoints.postSpeak.initiate({
1000
- npcId,
1001
- request: { speakMessage: text, speakContext: context, speakNPCState: currentState },
1002
- apiUrl,
1003
- apiKey
1004
- })).unwrap();
1005
- if (data.speakHistory) {
1006
- dispatch2(setHistory({ id: npcId, history: data.speakHistory }));
1007
- }
1008
- return data.speakReply;
1009
- }
1010
- );
1011
- var dialogueNPC = (0, import_toolkit9.createAsyncThunk)(
1012
- "npc/dialogue",
1013
- async ({ npcId: argNpcId, text, context = [], apiUrl, apiKey }, { getState, dispatch: dispatch2 }) => {
1014
- const stateNpcId = selectActiveNpcId(getState());
1015
- const npcId = argNpcId || stateNpcId;
1016
- const data = await dispatch2(sdkApi.endpoints.postDialogue.initiate({
1017
- npcId,
1018
- request: { diagMessage: text, diagContext: context },
1019
- apiUrl,
1020
- apiKey
1021
- })).unwrap();
1022
- return data.diagReply;
1023
1388
  }
1024
1389
  );
1025
- var localExportSoulThunk = (0, import_toolkit9.createAsyncThunk)(
1390
+ var localExportSoulThunk = (0, import_toolkit10.createAsyncThunk)(
1026
1391
  "npc/localExportSoul",
1027
1392
  async ({ id, memory }, { getState }) => {
1028
1393
  const state = getState().npc;
1029
1394
  const npcId = id || state.activeNpcId;
1030
1395
  const npc = state.entities[npcId];
1031
1396
  if (!npc) throw new Error(`NPC ${npcId} not found`);
1032
- const memories = memory ? await memory.export().catch(() => []) : [];
1397
+ const memories = memory ? await memory.export() : [];
1033
1398
  return exportToSoul(npcId, "NPC", npc.persona, npc.state, memories);
1034
1399
  }
1035
1400
  );
1401
+ var checkApiStatusThunk = (0, import_toolkit10.createAsyncThunk)(
1402
+ "system/checkApiStatus",
1403
+ async ({ apiUrl }, { dispatch: dispatch2, rejectWithValue }) => {
1404
+ try {
1405
+ return await dispatch2(sdkApi.endpoints.getApiStatus.initiate({ apiUrl })).unwrap();
1406
+ } catch (e) {
1407
+ return rejectWithValue(e?.message || "Connection failed");
1408
+ }
1409
+ }
1410
+ );
1411
+ var listMemoryRemoteThunk = (0, import_toolkit10.createAsyncThunk)(
1412
+ "memory/listRemote",
1413
+ async ({ npcId, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
1414
+ try {
1415
+ const data = await dispatch2(sdkApi.endpoints.getMemoryList.initiate({ npcId, apiUrl, apiKey })).unwrap();
1416
+ return data || [];
1417
+ } catch (e) {
1418
+ return rejectWithValue(e?.message || "Failed to list memories");
1419
+ }
1420
+ }
1421
+ );
1422
+ var recallMemoryRemoteThunk = (0, import_toolkit10.createAsyncThunk)(
1423
+ "memory/recallRemote",
1424
+ async ({ npcId, query, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
1425
+ try {
1426
+ const data = await dispatch2(
1427
+ sdkApi.endpoints.postMemoryRecall.initiate({
1428
+ npcId,
1429
+ request: { query },
1430
+ apiUrl,
1431
+ apiKey
1432
+ })
1433
+ ).unwrap();
1434
+ return data || [];
1435
+ } catch (e) {
1436
+ return rejectWithValue(e?.message || "Failed to recall memories");
1437
+ }
1438
+ }
1439
+ );
1440
+ var storeMemoryRemoteThunk = (0, import_toolkit10.createAsyncThunk)(
1441
+ "memory/storeRemote",
1442
+ async ({ npcId, observation, importance = 0.8, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
1443
+ try {
1444
+ return await dispatch2(
1445
+ sdkApi.endpoints.postMemoryStore.initiate({
1446
+ npcId,
1447
+ request: { observation, importance },
1448
+ apiUrl,
1449
+ apiKey
1450
+ })
1451
+ ).unwrap();
1452
+ } catch (e) {
1453
+ return rejectWithValue(e?.message || "Failed to store memory");
1454
+ }
1455
+ }
1456
+ );
1457
+ var clearMemoryRemoteThunk = (0, import_toolkit10.createAsyncThunk)(
1458
+ "memory/clearRemote",
1459
+ async ({ npcId, apiUrl, apiKey }, { dispatch: dispatch2, rejectWithValue }) => {
1460
+ try {
1461
+ return await dispatch2(
1462
+ sdkApi.endpoints.deleteMemoryClear.initiate({ npcId, apiUrl, apiKey })
1463
+ ).unwrap();
1464
+ } catch (e) {
1465
+ return rejectWithValue(e?.message || "Failed to clear memories");
1466
+ }
1467
+ }
1468
+ );
1036
1469
  // Annotate the CommonJS export names for ESM import in node:
1037
1470
  0 && (module.exports = {
1038
1471
  SDK_VERSION,
1039
1472
  addToHistory,
1040
1473
  blockAction,
1041
1474
  bridgeSlice,
1475
+ checkApiStatusThunk,
1042
1476
  clearBlock,
1043
1477
  clearBridgeValidation,
1478
+ clearDirectivesForNpc,
1044
1479
  clearGhostSession,
1480
+ clearMemoryRemoteThunk,
1045
1481
  clearSoulState,
1046
1482
  completeRemoteThunk,
1483
+ contextComposed,
1047
1484
  cortexInitFailed,
1048
1485
  cortexInitStart,
1049
1486
  cortexInitSuccess,
@@ -1051,7 +1488,11 @@ var localExportSoulThunk = (0, import_toolkit9.createAsyncThunk)(
1051
1488
  createInitialState,
1052
1489
  createSDKStore,
1053
1490
  delay,
1054
- dialogueNPC,
1491
+ deleteRulesetThunk,
1492
+ directiveReceived,
1493
+ directiveRunFailed,
1494
+ directiveRunStarted,
1495
+ directiveSlice,
1055
1496
  dispatch,
1056
1497
  exportToSoul,
1057
1498
  generateNPCId,
@@ -1061,8 +1502,13 @@ var localExportSoulThunk = (0, import_toolkit9.createAsyncThunk)(
1061
1502
  getGhostStatusThunk,
1062
1503
  getSoulListThunk,
1063
1504
  ghostSlice,
1505
+ importNpcFromSoulThunk,
1064
1506
  importSoulFromArweaveThunk,
1065
1507
  initRemoteCortexThunk,
1508
+ listCortexModelsThunk,
1509
+ listMemoryRemoteThunk,
1510
+ listRulePresetsThunk,
1511
+ listRulesetsThunk,
1066
1512
  loadBridgePresetThunk,
1067
1513
  localExportSoulThunk,
1068
1514
  memoise,
@@ -1078,13 +1524,19 @@ var localExportSoulThunk = (0, import_toolkit9.createAsyncThunk)(
1078
1524
  npcSlice,
1079
1525
  pipe,
1080
1526
  processNPC,
1527
+ recallMemoryRemoteThunk,
1528
+ registerRulesetThunk,
1081
1529
  remoteExportSoulThunk,
1082
1530
  removeNPC,
1083
1531
  sdkApi,
1532
+ selectActiveDirective,
1533
+ selectActiveDirectiveId,
1084
1534
  selectActiveNPC,
1085
1535
  selectActiveNpcId,
1536
+ selectAllDirectives,
1086
1537
  selectAllMemories,
1087
1538
  selectAllNPCs,
1539
+ selectDirectiveById,
1088
1540
  selectLastRecalledMemories,
1089
1541
  selectMemoryById,
1090
1542
  selectNPCById,
@@ -1098,15 +1550,17 @@ var localExportSoulThunk = (0, import_toolkit9.createAsyncThunk)(
1098
1550
  setNPCInfo,
1099
1551
  setNPCState,
1100
1552
  soulSlice,
1101
- speakNPC,
1102
1553
  startGhostThunk,
1103
1554
  stopGhostThunk,
1104
1555
  store,
1556
+ storeMemoryRemoteThunk,
1105
1557
  streamFromCortex,
1106
1558
  streamFromCortexWithDelay,
1107
1559
  streamToCallback,
1108
1560
  streamToString,
1109
1561
  updateNPCState,
1110
1562
  updateNPCStateLocally,
1111
- validateBridgeThunk
1563
+ validateBridgeThunk,
1564
+ verdictValidated,
1565
+ verifySoulThunk
1112
1566
  });