@forbocai/core 0.4.10 → 0.5.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.d.mts +68 -14
- package/dist/index.d.ts +68 -14
- package/dist/index.js +83 -95
- package/dist/index.mjs +82 -94
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ForbocAI Core Types
|
|
3
|
-
* The foundational interfaces for the
|
|
3
|
+
* The foundational interfaces for the Multi-Round Protocol.
|
|
4
4
|
*/
|
|
5
5
|
interface CortexConfig {
|
|
6
6
|
/** The model to load (e.g., 'smollm2-135m', 'llama3-8b-q4') */
|
|
@@ -87,6 +87,67 @@ interface AgentAction {
|
|
|
87
87
|
confidence?: number;
|
|
88
88
|
signature?: string;
|
|
89
89
|
}
|
|
90
|
+
/** Step 2: SDK → API. SDK sends observation + agent state. */
|
|
91
|
+
interface DirectiveRequest {
|
|
92
|
+
observation: string;
|
|
93
|
+
agentState: AgentState;
|
|
94
|
+
context?: Record<string, unknown>;
|
|
95
|
+
}
|
|
96
|
+
/** Step 3: API → SDK. API returns memory recall instructions. */
|
|
97
|
+
interface DirectiveResponse {
|
|
98
|
+
memoryRecall: MemoryRecallInstruction;
|
|
99
|
+
}
|
|
100
|
+
/** API tells SDK exactly what to recall from local vector DB. */
|
|
101
|
+
interface MemoryRecallInstruction {
|
|
102
|
+
query: string;
|
|
103
|
+
limit: number;
|
|
104
|
+
threshold: number;
|
|
105
|
+
}
|
|
106
|
+
/** Step 4: SDK → API. SDK sends recalled memories. */
|
|
107
|
+
interface ContextRequest {
|
|
108
|
+
memories: RecalledMemory[];
|
|
109
|
+
observation: string;
|
|
110
|
+
agentState: AgentState;
|
|
111
|
+
}
|
|
112
|
+
/** A memory item as recalled by the SDK's local vector DB. */
|
|
113
|
+
interface RecalledMemory {
|
|
114
|
+
text: string;
|
|
115
|
+
type: string;
|
|
116
|
+
importance: number;
|
|
117
|
+
similarity?: number;
|
|
118
|
+
}
|
|
119
|
+
/** Step 5: API → SDK. API returns full SLM prompt + constraints. */
|
|
120
|
+
interface ContextResponse {
|
|
121
|
+
prompt: string;
|
|
122
|
+
constraints: PromptConstraints;
|
|
123
|
+
}
|
|
124
|
+
/** Constraints the API sends to control SLM generation. */
|
|
125
|
+
interface PromptConstraints {
|
|
126
|
+
maxTokens?: number;
|
|
127
|
+
temperature?: number;
|
|
128
|
+
stop?: string[];
|
|
129
|
+
jsonSchema?: object;
|
|
130
|
+
}
|
|
131
|
+
/** Step 7: SDK → API. SDK sends generated output. */
|
|
132
|
+
interface VerdictRequest {
|
|
133
|
+
generatedOutput: string;
|
|
134
|
+
observation: string;
|
|
135
|
+
agentState: AgentState;
|
|
136
|
+
}
|
|
137
|
+
/** Step 8: API → SDK. API returns verdict + storage/state instructions. */
|
|
138
|
+
interface VerdictResponse {
|
|
139
|
+
valid: boolean;
|
|
140
|
+
signature?: string;
|
|
141
|
+
memoryStore: MemoryStoreInstruction[];
|
|
142
|
+
stateDelta: Record<string, unknown>;
|
|
143
|
+
action?: AgentAction;
|
|
144
|
+
}
|
|
145
|
+
/** API tells SDK exactly what to store in local vector DB. */
|
|
146
|
+
interface MemoryStoreInstruction {
|
|
147
|
+
text: string;
|
|
148
|
+
type: string;
|
|
149
|
+
importance: number;
|
|
150
|
+
}
|
|
90
151
|
interface ValidationContext {
|
|
91
152
|
agentState?: Record<string, unknown>;
|
|
92
153
|
worldState?: Record<string, unknown>;
|
|
@@ -114,15 +175,13 @@ interface Soul {
|
|
|
114
175
|
signature?: string;
|
|
115
176
|
}
|
|
116
177
|
|
|
117
|
-
/**
|
|
118
|
-
* Interface for Agent operations
|
|
119
|
-
*/
|
|
120
178
|
/**
|
|
121
179
|
* Interface for Agent operations
|
|
122
180
|
*/
|
|
123
181
|
interface IAgent {
|
|
124
182
|
/**
|
|
125
183
|
* Processes an input string with optional context to generate a response.
|
|
184
|
+
* Follows the multi-round protocol: directive → context → verdict.
|
|
126
185
|
* @param input - The input string from the user or system.
|
|
127
186
|
* @param context - Optional context data to influence the agent's response.
|
|
128
187
|
* @returns A promise that resolves to the agent's response.
|
|
@@ -178,6 +237,7 @@ declare const processAgentInput: (currentState: AgentState, input: string, conte
|
|
|
178
237
|
declare const exportToSoul: (agentId: string, name: string, persona: string, state: AgentState, memories: MemoryItem[]) => Soul;
|
|
179
238
|
/**
|
|
180
239
|
* Factory function to create Agent (Functional/Closure based)
|
|
240
|
+
* Implements the multi-round protocol where the SDK is a dumb executor.
|
|
181
241
|
* @param config - The configuration object for creating the agent.
|
|
182
242
|
* @returns An instance of IAgent.
|
|
183
243
|
*/
|
|
@@ -532,16 +592,10 @@ declare const getGhostHistory: (limit?: number, apiUrl?: string) => Promise<Ghos
|
|
|
532
592
|
declare const createGhost: (config: GhostConfig) => IGhost;
|
|
533
593
|
|
|
534
594
|
/**
|
|
535
|
-
*
|
|
595
|
+
* Creates a remote Cortex instance that proxies inference to the ForbocAI API.
|
|
536
596
|
* This is environment-agnostic as it only uses the standard fetch API.
|
|
537
597
|
*/
|
|
538
|
-
declare
|
|
539
|
-
private apiUrl;
|
|
540
|
-
constructor(apiUrl: string);
|
|
541
|
-
init(): Promise<CortexStatus>;
|
|
542
|
-
complete(prompt: string, options?: CompletionOptions): Promise<string>;
|
|
543
|
-
completeStream(prompt: string, options?: CompletionOptions): AsyncGenerator<string>;
|
|
544
|
-
}
|
|
598
|
+
declare const createRemoteCortex: (apiUrl: string) => ICortex;
|
|
545
599
|
|
|
546
600
|
interface RPGAgentState extends AgentState {
|
|
547
601
|
inventory: string[];
|
|
@@ -592,6 +646,6 @@ declare namespace index {
|
|
|
592
646
|
export { type index_RPGAgentState as RPGAgentState, index_RPG_MEMORY_TYPES as RPG_MEMORY_TYPES, index_RPG_MOODS as RPG_MOODS, index_attackRule as attackRule, index_createRPGState as createRPGState, index_interactRule as interactRule, index_movementRule as movementRule, index_puzzleRules as puzzleRules, index_resourceRule as resourceRule, index_rpgRules as rpgRules, index_socialRules as socialRules, index_spatialRules as spatialRules, index_speakRule as speakRule };
|
|
593
647
|
}
|
|
594
648
|
|
|
595
|
-
declare const SDK_VERSION = "0.
|
|
649
|
+
declare const SDK_VERSION = "0.5.1";
|
|
596
650
|
|
|
597
|
-
export { type AgentAction, type AgentConfig, type AgentResponse, type AgentState, type BridgeConfig, type CompletionOptions, type CortexConfig, type CortexStatus, type Directive, type GhostConfig, type GhostHistoryEntry, type GhostResults, type GhostStatus, type GhostTestResult, type IAgent, type IBridge, type ICortex, type IGhost, type ISoul, type MemoryConfig, type MemoryItem, type MemoryType, type Mood, type Observation,
|
|
651
|
+
export { type AgentAction, type AgentConfig, type AgentResponse, type AgentState, type BridgeConfig, type CompletionOptions, type ContextRequest, type ContextResponse, type CortexConfig, type CortexStatus, type Directive, type DirectiveRequest, type DirectiveResponse, type GhostConfig, type GhostHistoryEntry, type GhostResults, type GhostStatus, type GhostTestResult, type IAgent, type IBridge, type ICortex, type IGhost, type ISoul, type MemoryConfig, type MemoryItem, type MemoryRecallInstruction, type MemoryStoreInstruction, type MemoryType, type Mood, type Observation, type PromptConstraints, type RecalledMemory, SDK_VERSION, type Soul, type SoulExportConfig, type SoulExportResult, type SoulImportConfig, type SoulListEntry, type ValidationContext, type ValidationResult, type ValidationRule, type VerdictRequest, type VerdictResponse, createAgent, createBridge, createGhost, createInitialState, createRemoteCortex, createSoul, createSoulInstance, deserializeSoul, exportSoul, exportToSoul, fromSoul, getGhostHistory, getGhostResults, getGhostStatus, getSoulList, importSoulFromArweave, index as presets, processAgentInput, serializeSoul, startGhostSession, stopGhostSession, updateAgentState, uploadToArweave, validateAction, validateSoul, waitForGhostCompletion };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ForbocAI Core Types
|
|
3
|
-
* The foundational interfaces for the
|
|
3
|
+
* The foundational interfaces for the Multi-Round Protocol.
|
|
4
4
|
*/
|
|
5
5
|
interface CortexConfig {
|
|
6
6
|
/** The model to load (e.g., 'smollm2-135m', 'llama3-8b-q4') */
|
|
@@ -87,6 +87,67 @@ interface AgentAction {
|
|
|
87
87
|
confidence?: number;
|
|
88
88
|
signature?: string;
|
|
89
89
|
}
|
|
90
|
+
/** Step 2: SDK → API. SDK sends observation + agent state. */
|
|
91
|
+
interface DirectiveRequest {
|
|
92
|
+
observation: string;
|
|
93
|
+
agentState: AgentState;
|
|
94
|
+
context?: Record<string, unknown>;
|
|
95
|
+
}
|
|
96
|
+
/** Step 3: API → SDK. API returns memory recall instructions. */
|
|
97
|
+
interface DirectiveResponse {
|
|
98
|
+
memoryRecall: MemoryRecallInstruction;
|
|
99
|
+
}
|
|
100
|
+
/** API tells SDK exactly what to recall from local vector DB. */
|
|
101
|
+
interface MemoryRecallInstruction {
|
|
102
|
+
query: string;
|
|
103
|
+
limit: number;
|
|
104
|
+
threshold: number;
|
|
105
|
+
}
|
|
106
|
+
/** Step 4: SDK → API. SDK sends recalled memories. */
|
|
107
|
+
interface ContextRequest {
|
|
108
|
+
memories: RecalledMemory[];
|
|
109
|
+
observation: string;
|
|
110
|
+
agentState: AgentState;
|
|
111
|
+
}
|
|
112
|
+
/** A memory item as recalled by the SDK's local vector DB. */
|
|
113
|
+
interface RecalledMemory {
|
|
114
|
+
text: string;
|
|
115
|
+
type: string;
|
|
116
|
+
importance: number;
|
|
117
|
+
similarity?: number;
|
|
118
|
+
}
|
|
119
|
+
/** Step 5: API → SDK. API returns full SLM prompt + constraints. */
|
|
120
|
+
interface ContextResponse {
|
|
121
|
+
prompt: string;
|
|
122
|
+
constraints: PromptConstraints;
|
|
123
|
+
}
|
|
124
|
+
/** Constraints the API sends to control SLM generation. */
|
|
125
|
+
interface PromptConstraints {
|
|
126
|
+
maxTokens?: number;
|
|
127
|
+
temperature?: number;
|
|
128
|
+
stop?: string[];
|
|
129
|
+
jsonSchema?: object;
|
|
130
|
+
}
|
|
131
|
+
/** Step 7: SDK → API. SDK sends generated output. */
|
|
132
|
+
interface VerdictRequest {
|
|
133
|
+
generatedOutput: string;
|
|
134
|
+
observation: string;
|
|
135
|
+
agentState: AgentState;
|
|
136
|
+
}
|
|
137
|
+
/** Step 8: API → SDK. API returns verdict + storage/state instructions. */
|
|
138
|
+
interface VerdictResponse {
|
|
139
|
+
valid: boolean;
|
|
140
|
+
signature?: string;
|
|
141
|
+
memoryStore: MemoryStoreInstruction[];
|
|
142
|
+
stateDelta: Record<string, unknown>;
|
|
143
|
+
action?: AgentAction;
|
|
144
|
+
}
|
|
145
|
+
/** API tells SDK exactly what to store in local vector DB. */
|
|
146
|
+
interface MemoryStoreInstruction {
|
|
147
|
+
text: string;
|
|
148
|
+
type: string;
|
|
149
|
+
importance: number;
|
|
150
|
+
}
|
|
90
151
|
interface ValidationContext {
|
|
91
152
|
agentState?: Record<string, unknown>;
|
|
92
153
|
worldState?: Record<string, unknown>;
|
|
@@ -114,15 +175,13 @@ interface Soul {
|
|
|
114
175
|
signature?: string;
|
|
115
176
|
}
|
|
116
177
|
|
|
117
|
-
/**
|
|
118
|
-
* Interface for Agent operations
|
|
119
|
-
*/
|
|
120
178
|
/**
|
|
121
179
|
* Interface for Agent operations
|
|
122
180
|
*/
|
|
123
181
|
interface IAgent {
|
|
124
182
|
/**
|
|
125
183
|
* Processes an input string with optional context to generate a response.
|
|
184
|
+
* Follows the multi-round protocol: directive → context → verdict.
|
|
126
185
|
* @param input - The input string from the user or system.
|
|
127
186
|
* @param context - Optional context data to influence the agent's response.
|
|
128
187
|
* @returns A promise that resolves to the agent's response.
|
|
@@ -178,6 +237,7 @@ declare const processAgentInput: (currentState: AgentState, input: string, conte
|
|
|
178
237
|
declare const exportToSoul: (agentId: string, name: string, persona: string, state: AgentState, memories: MemoryItem[]) => Soul;
|
|
179
238
|
/**
|
|
180
239
|
* Factory function to create Agent (Functional/Closure based)
|
|
240
|
+
* Implements the multi-round protocol where the SDK is a dumb executor.
|
|
181
241
|
* @param config - The configuration object for creating the agent.
|
|
182
242
|
* @returns An instance of IAgent.
|
|
183
243
|
*/
|
|
@@ -532,16 +592,10 @@ declare const getGhostHistory: (limit?: number, apiUrl?: string) => Promise<Ghos
|
|
|
532
592
|
declare const createGhost: (config: GhostConfig) => IGhost;
|
|
533
593
|
|
|
534
594
|
/**
|
|
535
|
-
*
|
|
595
|
+
* Creates a remote Cortex instance that proxies inference to the ForbocAI API.
|
|
536
596
|
* This is environment-agnostic as it only uses the standard fetch API.
|
|
537
597
|
*/
|
|
538
|
-
declare
|
|
539
|
-
private apiUrl;
|
|
540
|
-
constructor(apiUrl: string);
|
|
541
|
-
init(): Promise<CortexStatus>;
|
|
542
|
-
complete(prompt: string, options?: CompletionOptions): Promise<string>;
|
|
543
|
-
completeStream(prompt: string, options?: CompletionOptions): AsyncGenerator<string>;
|
|
544
|
-
}
|
|
598
|
+
declare const createRemoteCortex: (apiUrl: string) => ICortex;
|
|
545
599
|
|
|
546
600
|
interface RPGAgentState extends AgentState {
|
|
547
601
|
inventory: string[];
|
|
@@ -592,6 +646,6 @@ declare namespace index {
|
|
|
592
646
|
export { type index_RPGAgentState as RPGAgentState, index_RPG_MEMORY_TYPES as RPG_MEMORY_TYPES, index_RPG_MOODS as RPG_MOODS, index_attackRule as attackRule, index_createRPGState as createRPGState, index_interactRule as interactRule, index_movementRule as movementRule, index_puzzleRules as puzzleRules, index_resourceRule as resourceRule, index_rpgRules as rpgRules, index_socialRules as socialRules, index_spatialRules as spatialRules, index_speakRule as speakRule };
|
|
593
647
|
}
|
|
594
648
|
|
|
595
|
-
declare const SDK_VERSION = "0.
|
|
649
|
+
declare const SDK_VERSION = "0.5.1";
|
|
596
650
|
|
|
597
|
-
export { type AgentAction, type AgentConfig, type AgentResponse, type AgentState, type BridgeConfig, type CompletionOptions, type CortexConfig, type CortexStatus, type Directive, type GhostConfig, type GhostHistoryEntry, type GhostResults, type GhostStatus, type GhostTestResult, type IAgent, type IBridge, type ICortex, type IGhost, type ISoul, type MemoryConfig, type MemoryItem, type MemoryType, type Mood, type Observation,
|
|
651
|
+
export { type AgentAction, type AgentConfig, type AgentResponse, type AgentState, type BridgeConfig, type CompletionOptions, type ContextRequest, type ContextResponse, type CortexConfig, type CortexStatus, type Directive, type DirectiveRequest, type DirectiveResponse, type GhostConfig, type GhostHistoryEntry, type GhostResults, type GhostStatus, type GhostTestResult, type IAgent, type IBridge, type ICortex, type IGhost, type ISoul, type MemoryConfig, type MemoryItem, type MemoryRecallInstruction, type MemoryStoreInstruction, type MemoryType, type Mood, type Observation, type PromptConstraints, type RecalledMemory, SDK_VERSION, type Soul, type SoulExportConfig, type SoulExportResult, type SoulImportConfig, type SoulListEntry, type ValidationContext, type ValidationResult, type ValidationRule, type VerdictRequest, type VerdictResponse, createAgent, createBridge, createGhost, createInitialState, createRemoteCortex, createSoul, createSoulInstance, deserializeSoul, exportSoul, exportToSoul, fromSoul, getGhostHistory, getGhostResults, getGhostStatus, getSoulList, importSoulFromArweave, index as presets, processAgentInput, serializeSoul, startGhostSession, stopGhostSession, updateAgentState, uploadToArweave, validateAction, validateSoul, waitForGhostCompletion };
|
package/dist/index.js
CHANGED
|
@@ -30,12 +30,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
RemoteCortex: () => RemoteCortex,
|
|
34
33
|
SDK_VERSION: () => SDK_VERSION,
|
|
35
34
|
createAgent: () => createAgent,
|
|
36
35
|
createBridge: () => createBridge,
|
|
37
36
|
createGhost: () => createGhost,
|
|
38
37
|
createInitialState: () => createInitialState,
|
|
38
|
+
createRemoteCortex: () => createRemoteCortex,
|
|
39
39
|
createSoul: () => createSoul,
|
|
40
40
|
createSoulInstance: () => createSoulInstance,
|
|
41
41
|
deserializeSoul: () => deserializeSoul,
|
|
@@ -88,9 +88,7 @@ var exportToSoul = (agentId, name, persona, state, memories) => {
|
|
|
88
88
|
name,
|
|
89
89
|
persona,
|
|
90
90
|
memories: [...memories],
|
|
91
|
-
// Copy array for immutability
|
|
92
91
|
state: { ...state }
|
|
93
|
-
// Copy state for immutability
|
|
94
92
|
};
|
|
95
93
|
};
|
|
96
94
|
var createAgent = (config) => {
|
|
@@ -107,96 +105,91 @@ var createAgent = (config) => {
|
|
|
107
105
|
};
|
|
108
106
|
const process = async (input, context = {}) => {
|
|
109
107
|
const currentState = getAgentState();
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
108
|
+
const directiveBody = {
|
|
109
|
+
observation: input,
|
|
110
|
+
agentState: currentState,
|
|
111
|
+
context
|
|
112
|
+
};
|
|
113
|
+
const dirRes = await fetch(`${apiUrl}/agents/${agentId}/directive`, {
|
|
114
|
+
method: "POST",
|
|
115
|
+
headers: { "Content-Type": "application/json" },
|
|
116
|
+
body: JSON.stringify(directiveBody)
|
|
117
|
+
});
|
|
118
|
+
if (!dirRes.ok) {
|
|
119
|
+
throw new Error(`API Directive Error: ${dirRes.status}`);
|
|
120
|
+
}
|
|
121
|
+
const directiveData = await dirRes.json();
|
|
122
|
+
let recalledMemories = [];
|
|
114
123
|
if (config.memory && typeof config.memory.recall === "function") {
|
|
115
124
|
try {
|
|
116
|
-
|
|
125
|
+
const rawMemories = await config.memory.recall(
|
|
126
|
+
directiveData.memoryRecall.query,
|
|
127
|
+
directiveData.memoryRecall.limit
|
|
128
|
+
);
|
|
129
|
+
recalledMemories = rawMemories.map((m) => ({
|
|
130
|
+
text: m.text,
|
|
131
|
+
type: m.type,
|
|
132
|
+
importance: m.importance,
|
|
133
|
+
similarity: void 0
|
|
134
|
+
}));
|
|
117
135
|
} catch {
|
|
118
136
|
}
|
|
119
137
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
} catch (e) {
|
|
145
|
-
throw new Error(`API Directive Failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
146
|
-
}
|
|
147
|
-
const memoryContext = relevantMemories.length > 0 ? `
|
|
148
|
-
Memories:
|
|
149
|
-
${relevantMemories.map((m) => `- [${m.type}] ${m.text}`).join("\n")}
|
|
150
|
-
` : "";
|
|
151
|
-
const prompt = `System: You are ${config.persona}.
|
|
152
|
-
Directive: ${instruction} (${directive}).
|
|
153
|
-
Target: ${target || "None"}${memoryContext}
|
|
154
|
-
User: ${input}
|
|
155
|
-
Agent:`;
|
|
156
|
-
const generatedText = await cortex.complete(prompt);
|
|
138
|
+
const contextBody = {
|
|
139
|
+
memories: recalledMemories,
|
|
140
|
+
observation: input,
|
|
141
|
+
agentState: currentState
|
|
142
|
+
};
|
|
143
|
+
const ctxRes = await fetch(`${apiUrl}/agents/${agentId}/context`, {
|
|
144
|
+
method: "POST",
|
|
145
|
+
headers: { "Content-Type": "application/json" },
|
|
146
|
+
body: JSON.stringify(contextBody)
|
|
147
|
+
});
|
|
148
|
+
if (!ctxRes.ok) {
|
|
149
|
+
throw new Error(`API Context Error: ${ctxRes.status}`);
|
|
150
|
+
}
|
|
151
|
+
const contextData = await ctxRes.json();
|
|
152
|
+
const generatedText = await cortex.complete(contextData.prompt, {
|
|
153
|
+
maxTokens: contextData.constraints.maxTokens,
|
|
154
|
+
temperature: contextData.constraints.temperature,
|
|
155
|
+
stop: contextData.constraints.stop
|
|
156
|
+
});
|
|
157
|
+
const verdictBody = {
|
|
158
|
+
generatedOutput: generatedText,
|
|
159
|
+
observation: input,
|
|
160
|
+
agentState: currentState
|
|
161
|
+
};
|
|
157
162
|
const verRes = await fetch(`${apiUrl}/agents/${agentId}/verdict`, {
|
|
158
163
|
method: "POST",
|
|
159
164
|
headers: { "Content-Type": "application/json" },
|
|
160
|
-
body: JSON.stringify(
|
|
161
|
-
verDirective: {
|
|
162
|
-
dirInstruction: instruction,
|
|
163
|
-
dirTarget: target || "",
|
|
164
|
-
dirReason: directive
|
|
165
|
-
},
|
|
166
|
-
verAction: {
|
|
167
|
-
gaType: instruction,
|
|
168
|
-
// Map to generic action type
|
|
169
|
-
actionReason: directive,
|
|
170
|
-
actionTarget: target || ""
|
|
171
|
-
},
|
|
172
|
-
verThought: generatedText
|
|
173
|
-
})
|
|
165
|
+
body: JSON.stringify(verdictBody)
|
|
174
166
|
});
|
|
175
167
|
if (!verRes.ok) {
|
|
176
168
|
throw new Error(`API Verdict Error: ${verRes.status}`);
|
|
177
169
|
}
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
const signature = vData.verSignature;
|
|
181
|
-
if (!isValid) {
|
|
170
|
+
const verdictData = await verRes.json();
|
|
171
|
+
if (!verdictData.valid) {
|
|
182
172
|
return {
|
|
183
173
|
dialogue: "... [Action Blocked by Protocol]",
|
|
184
174
|
action: { type: "BLOCKED", reason: "API Validation Failed" }
|
|
185
175
|
};
|
|
186
176
|
}
|
|
187
|
-
if (config.memory && typeof config.memory.store === "function") {
|
|
188
|
-
|
|
189
|
-
|
|
177
|
+
if (config.memory && typeof config.memory.store === "function" && verdictData.memoryStore) {
|
|
178
|
+
for (const instruction of verdictData.memoryStore) {
|
|
179
|
+
config.memory.store(instruction.text, instruction.type, instruction.importance).catch(() => {
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (verdictData.stateDelta && Object.keys(verdictData.stateDelta).length > 0) {
|
|
184
|
+
state = updateAgentState(state, verdictData.stateDelta);
|
|
190
185
|
}
|
|
191
186
|
return {
|
|
192
187
|
dialogue: generatedText,
|
|
193
|
-
action: {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
},
|
|
199
|
-
thought: `Directive: ${directive}`
|
|
188
|
+
action: verdictData.action ? {
|
|
189
|
+
...verdictData.action,
|
|
190
|
+
signature: verdictData.signature
|
|
191
|
+
} : void 0,
|
|
192
|
+
thought: generatedText
|
|
200
193
|
};
|
|
201
194
|
};
|
|
202
195
|
const exportSoul2 = async () => {
|
|
@@ -227,8 +220,7 @@ var fromSoul = async (soul, cortex, memory) => {
|
|
|
227
220
|
if (memory && soul.memories && soul.memories.length > 0 && typeof memory.import === "function") {
|
|
228
221
|
try {
|
|
229
222
|
await memory.import(soul.memories);
|
|
230
|
-
} catch
|
|
231
|
-
console.warn("Failed to import memories into module:", e);
|
|
223
|
+
} catch {
|
|
232
224
|
}
|
|
233
225
|
}
|
|
234
226
|
return agent;
|
|
@@ -692,20 +684,15 @@ var createGhost = (config) => {
|
|
|
692
684
|
};
|
|
693
685
|
|
|
694
686
|
// src/cortex-remote.ts
|
|
695
|
-
var
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
engine: "remote"
|
|
705
|
-
};
|
|
706
|
-
}
|
|
707
|
-
async complete(prompt, options) {
|
|
708
|
-
const response = await fetch(`${this.apiUrl}/cortex/complete`, {
|
|
687
|
+
var createRemoteCortex = (apiUrl) => {
|
|
688
|
+
const init = async () => ({
|
|
689
|
+
id: `remote_${Date.now()}`,
|
|
690
|
+
model: "api-integrated",
|
|
691
|
+
ready: true,
|
|
692
|
+
engine: "remote"
|
|
693
|
+
});
|
|
694
|
+
const complete = async (prompt, options) => {
|
|
695
|
+
const response = await fetch(`${apiUrl}/cortex/complete`, {
|
|
709
696
|
method: "POST",
|
|
710
697
|
headers: { "Content-Type": "application/json" },
|
|
711
698
|
body: JSON.stringify({ prompt, ...options })
|
|
@@ -713,11 +700,12 @@ var RemoteCortex = class {
|
|
|
713
700
|
if (!response.ok) throw new Error(`Remote Cortex failed: ${response.statusText}`);
|
|
714
701
|
const data = await response.json();
|
|
715
702
|
return data.text;
|
|
716
|
-
}
|
|
717
|
-
async *
|
|
718
|
-
const result = await
|
|
703
|
+
};
|
|
704
|
+
const completeStream = async function* (prompt, options) {
|
|
705
|
+
const result = await complete(prompt, options);
|
|
719
706
|
yield result;
|
|
720
|
-
}
|
|
707
|
+
};
|
|
708
|
+
return { init, complete, completeStream };
|
|
721
709
|
};
|
|
722
710
|
|
|
723
711
|
// src/presets/index.ts
|
|
@@ -927,15 +915,15 @@ var socialRules = [speakRule, interactRule];
|
|
|
927
915
|
var puzzleRules = [movementRule, interactRule];
|
|
928
916
|
|
|
929
917
|
// src/index.ts
|
|
930
|
-
var SDK_VERSION = "0.
|
|
918
|
+
var SDK_VERSION = "0.5.1";
|
|
931
919
|
// Annotate the CommonJS export names for ESM import in node:
|
|
932
920
|
0 && (module.exports = {
|
|
933
|
-
RemoteCortex,
|
|
934
921
|
SDK_VERSION,
|
|
935
922
|
createAgent,
|
|
936
923
|
createBridge,
|
|
937
924
|
createGhost,
|
|
938
925
|
createInitialState,
|
|
926
|
+
createRemoteCortex,
|
|
939
927
|
createSoul,
|
|
940
928
|
createSoulInstance,
|
|
941
929
|
deserializeSoul,
|
package/dist/index.mjs
CHANGED
|
@@ -32,9 +32,7 @@ var exportToSoul = (agentId, name, persona, state, memories) => {
|
|
|
32
32
|
name,
|
|
33
33
|
persona,
|
|
34
34
|
memories: [...memories],
|
|
35
|
-
// Copy array for immutability
|
|
36
35
|
state: { ...state }
|
|
37
|
-
// Copy state for immutability
|
|
38
36
|
};
|
|
39
37
|
};
|
|
40
38
|
var createAgent = (config) => {
|
|
@@ -51,96 +49,91 @@ var createAgent = (config) => {
|
|
|
51
49
|
};
|
|
52
50
|
const process = async (input, context = {}) => {
|
|
53
51
|
const currentState = getAgentState();
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
const directiveBody = {
|
|
53
|
+
observation: input,
|
|
54
|
+
agentState: currentState,
|
|
55
|
+
context
|
|
56
|
+
};
|
|
57
|
+
const dirRes = await fetch(`${apiUrl}/agents/${agentId}/directive`, {
|
|
58
|
+
method: "POST",
|
|
59
|
+
headers: { "Content-Type": "application/json" },
|
|
60
|
+
body: JSON.stringify(directiveBody)
|
|
61
|
+
});
|
|
62
|
+
if (!dirRes.ok) {
|
|
63
|
+
throw new Error(`API Directive Error: ${dirRes.status}`);
|
|
64
|
+
}
|
|
65
|
+
const directiveData = await dirRes.json();
|
|
66
|
+
let recalledMemories = [];
|
|
58
67
|
if (config.memory && typeof config.memory.recall === "function") {
|
|
59
68
|
try {
|
|
60
|
-
|
|
69
|
+
const rawMemories = await config.memory.recall(
|
|
70
|
+
directiveData.memoryRecall.query,
|
|
71
|
+
directiveData.memoryRecall.limit
|
|
72
|
+
);
|
|
73
|
+
recalledMemories = rawMemories.map((m) => ({
|
|
74
|
+
text: m.text,
|
|
75
|
+
type: m.type,
|
|
76
|
+
importance: m.importance,
|
|
77
|
+
similarity: void 0
|
|
78
|
+
}));
|
|
61
79
|
} catch {
|
|
62
80
|
}
|
|
63
81
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
} catch (e) {
|
|
89
|
-
throw new Error(`API Directive Failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
90
|
-
}
|
|
91
|
-
const memoryContext = relevantMemories.length > 0 ? `
|
|
92
|
-
Memories:
|
|
93
|
-
${relevantMemories.map((m) => `- [${m.type}] ${m.text}`).join("\n")}
|
|
94
|
-
` : "";
|
|
95
|
-
const prompt = `System: You are ${config.persona}.
|
|
96
|
-
Directive: ${instruction} (${directive}).
|
|
97
|
-
Target: ${target || "None"}${memoryContext}
|
|
98
|
-
User: ${input}
|
|
99
|
-
Agent:`;
|
|
100
|
-
const generatedText = await cortex.complete(prompt);
|
|
82
|
+
const contextBody = {
|
|
83
|
+
memories: recalledMemories,
|
|
84
|
+
observation: input,
|
|
85
|
+
agentState: currentState
|
|
86
|
+
};
|
|
87
|
+
const ctxRes = await fetch(`${apiUrl}/agents/${agentId}/context`, {
|
|
88
|
+
method: "POST",
|
|
89
|
+
headers: { "Content-Type": "application/json" },
|
|
90
|
+
body: JSON.stringify(contextBody)
|
|
91
|
+
});
|
|
92
|
+
if (!ctxRes.ok) {
|
|
93
|
+
throw new Error(`API Context Error: ${ctxRes.status}`);
|
|
94
|
+
}
|
|
95
|
+
const contextData = await ctxRes.json();
|
|
96
|
+
const generatedText = await cortex.complete(contextData.prompt, {
|
|
97
|
+
maxTokens: contextData.constraints.maxTokens,
|
|
98
|
+
temperature: contextData.constraints.temperature,
|
|
99
|
+
stop: contextData.constraints.stop
|
|
100
|
+
});
|
|
101
|
+
const verdictBody = {
|
|
102
|
+
generatedOutput: generatedText,
|
|
103
|
+
observation: input,
|
|
104
|
+
agentState: currentState
|
|
105
|
+
};
|
|
101
106
|
const verRes = await fetch(`${apiUrl}/agents/${agentId}/verdict`, {
|
|
102
107
|
method: "POST",
|
|
103
108
|
headers: { "Content-Type": "application/json" },
|
|
104
|
-
body: JSON.stringify(
|
|
105
|
-
verDirective: {
|
|
106
|
-
dirInstruction: instruction,
|
|
107
|
-
dirTarget: target || "",
|
|
108
|
-
dirReason: directive
|
|
109
|
-
},
|
|
110
|
-
verAction: {
|
|
111
|
-
gaType: instruction,
|
|
112
|
-
// Map to generic action type
|
|
113
|
-
actionReason: directive,
|
|
114
|
-
actionTarget: target || ""
|
|
115
|
-
},
|
|
116
|
-
verThought: generatedText
|
|
117
|
-
})
|
|
109
|
+
body: JSON.stringify(verdictBody)
|
|
118
110
|
});
|
|
119
111
|
if (!verRes.ok) {
|
|
120
112
|
throw new Error(`API Verdict Error: ${verRes.status}`);
|
|
121
113
|
}
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
const signature = vData.verSignature;
|
|
125
|
-
if (!isValid) {
|
|
114
|
+
const verdictData = await verRes.json();
|
|
115
|
+
if (!verdictData.valid) {
|
|
126
116
|
return {
|
|
127
117
|
dialogue: "... [Action Blocked by Protocol]",
|
|
128
118
|
action: { type: "BLOCKED", reason: "API Validation Failed" }
|
|
129
119
|
};
|
|
130
120
|
}
|
|
131
|
-
if (config.memory && typeof config.memory.store === "function") {
|
|
132
|
-
|
|
133
|
-
|
|
121
|
+
if (config.memory && typeof config.memory.store === "function" && verdictData.memoryStore) {
|
|
122
|
+
for (const instruction of verdictData.memoryStore) {
|
|
123
|
+
config.memory.store(instruction.text, instruction.type, instruction.importance).catch(() => {
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (verdictData.stateDelta && Object.keys(verdictData.stateDelta).length > 0) {
|
|
128
|
+
state = updateAgentState(state, verdictData.stateDelta);
|
|
134
129
|
}
|
|
135
130
|
return {
|
|
136
131
|
dialogue: generatedText,
|
|
137
|
-
action: {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
},
|
|
143
|
-
thought: `Directive: ${directive}`
|
|
132
|
+
action: verdictData.action ? {
|
|
133
|
+
...verdictData.action,
|
|
134
|
+
signature: verdictData.signature
|
|
135
|
+
} : void 0,
|
|
136
|
+
thought: generatedText
|
|
144
137
|
};
|
|
145
138
|
};
|
|
146
139
|
const exportSoul2 = async () => {
|
|
@@ -171,8 +164,7 @@ var fromSoul = async (soul, cortex, memory) => {
|
|
|
171
164
|
if (memory && soul.memories && soul.memories.length > 0 && typeof memory.import === "function") {
|
|
172
165
|
try {
|
|
173
166
|
await memory.import(soul.memories);
|
|
174
|
-
} catch
|
|
175
|
-
console.warn("Failed to import memories into module:", e);
|
|
167
|
+
} catch {
|
|
176
168
|
}
|
|
177
169
|
}
|
|
178
170
|
return agent;
|
|
@@ -636,20 +628,15 @@ var createGhost = (config) => {
|
|
|
636
628
|
};
|
|
637
629
|
|
|
638
630
|
// src/cortex-remote.ts
|
|
639
|
-
var
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
engine: "remote"
|
|
649
|
-
};
|
|
650
|
-
}
|
|
651
|
-
async complete(prompt, options) {
|
|
652
|
-
const response = await fetch(`${this.apiUrl}/cortex/complete`, {
|
|
631
|
+
var createRemoteCortex = (apiUrl) => {
|
|
632
|
+
const init = async () => ({
|
|
633
|
+
id: `remote_${Date.now()}`,
|
|
634
|
+
model: "api-integrated",
|
|
635
|
+
ready: true,
|
|
636
|
+
engine: "remote"
|
|
637
|
+
});
|
|
638
|
+
const complete = async (prompt, options) => {
|
|
639
|
+
const response = await fetch(`${apiUrl}/cortex/complete`, {
|
|
653
640
|
method: "POST",
|
|
654
641
|
headers: { "Content-Type": "application/json" },
|
|
655
642
|
body: JSON.stringify({ prompt, ...options })
|
|
@@ -657,11 +644,12 @@ var RemoteCortex = class {
|
|
|
657
644
|
if (!response.ok) throw new Error(`Remote Cortex failed: ${response.statusText}`);
|
|
658
645
|
const data = await response.json();
|
|
659
646
|
return data.text;
|
|
660
|
-
}
|
|
661
|
-
async *
|
|
662
|
-
const result = await
|
|
647
|
+
};
|
|
648
|
+
const completeStream = async function* (prompt, options) {
|
|
649
|
+
const result = await complete(prompt, options);
|
|
663
650
|
yield result;
|
|
664
|
-
}
|
|
651
|
+
};
|
|
652
|
+
return { init, complete, completeStream };
|
|
665
653
|
};
|
|
666
654
|
|
|
667
655
|
// src/presets/index.ts
|
|
@@ -871,14 +859,14 @@ var socialRules = [speakRule, interactRule];
|
|
|
871
859
|
var puzzleRules = [movementRule, interactRule];
|
|
872
860
|
|
|
873
861
|
// src/index.ts
|
|
874
|
-
var SDK_VERSION = "0.
|
|
862
|
+
var SDK_VERSION = "0.5.1";
|
|
875
863
|
export {
|
|
876
|
-
RemoteCortex,
|
|
877
864
|
SDK_VERSION,
|
|
878
865
|
createAgent,
|
|
879
866
|
createBridge,
|
|
880
867
|
createGhost,
|
|
881
868
|
createInitialState,
|
|
869
|
+
createRemoteCortex,
|
|
882
870
|
createSoul,
|
|
883
871
|
createSoulInstance,
|
|
884
872
|
deserializeSoul,
|