@forbocai/core 0.5.6 → 0.5.7
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 +70 -3
- package/dist/index.d.ts +70 -3
- package/dist/index.js +79 -6
- package/dist/index.mjs +75 -6
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -49,6 +49,7 @@ interface AgentConfig {
|
|
|
49
49
|
persona: string;
|
|
50
50
|
initialState?: Partial<AgentState>;
|
|
51
51
|
apiUrl?: string;
|
|
52
|
+
apiKey?: string;
|
|
52
53
|
}
|
|
53
54
|
interface AgentResponse {
|
|
54
55
|
dialogue: string;
|
|
@@ -100,6 +101,20 @@ interface RecalledMemory {
|
|
|
100
101
|
importance: number;
|
|
101
102
|
similarity?: number;
|
|
102
103
|
}
|
|
104
|
+
/** Speak Request (Simple Dialogue) */
|
|
105
|
+
interface SpeakRequest {
|
|
106
|
+
speakMessage: string;
|
|
107
|
+
speakContext?: Record<string, unknown>;
|
|
108
|
+
speakAgentState: Record<string, unknown>;
|
|
109
|
+
}
|
|
110
|
+
/** Speak Response (Simple Dialogue) */
|
|
111
|
+
interface SpeakResponse {
|
|
112
|
+
speakReply: string;
|
|
113
|
+
speakHistory: Array<{
|
|
114
|
+
role: string;
|
|
115
|
+
content: string;
|
|
116
|
+
}>;
|
|
117
|
+
}
|
|
103
118
|
/** Step 5: API → SDK. API returns full SLM prompt + constraints. */
|
|
104
119
|
interface ContextResponse {
|
|
105
120
|
prompt: string;
|
|
@@ -171,6 +186,17 @@ interface IAgent {
|
|
|
171
186
|
* @returns A promise that resolves to the agent's response.
|
|
172
187
|
*/
|
|
173
188
|
process(input: string, context?: Record<string, unknown>): Promise<AgentResponse>;
|
|
189
|
+
/**
|
|
190
|
+
* Generates a conversational response (bypassing the multi-round ruleset evaluation).
|
|
191
|
+
* @param message - The input message.
|
|
192
|
+
* @param context - Optional context overrides.
|
|
193
|
+
* @returns A promise resolving to the agent's textual reply.
|
|
194
|
+
*/
|
|
195
|
+
speak(message: string, context?: Record<string, unknown>): Promise<string>;
|
|
196
|
+
/**
|
|
197
|
+
* Alias for `speak()`.
|
|
198
|
+
*/
|
|
199
|
+
reply(message: string, context?: Record<string, unknown>): Promise<string>;
|
|
174
200
|
/**
|
|
175
201
|
* Retrieves the current state of the agent.
|
|
176
202
|
* @returns The current AgentState.
|
|
@@ -554,7 +580,48 @@ declare const createGhost: (config: GhostConfig) => IGhost;
|
|
|
554
580
|
* Creates a remote Cortex instance that proxies inference to the ForbocAI API.
|
|
555
581
|
* This is environment-agnostic as it only uses the standard fetch API.
|
|
556
582
|
*/
|
|
557
|
-
declare const createRemoteCortex: (apiUrl: string, cortexId?: string) => ICortex;
|
|
583
|
+
declare const createRemoteCortex: (apiUrl: string, cortexId?: string, apiKey?: string) => ICortex;
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Consume an async token stream, calling `onChunk` for each token.
|
|
587
|
+
* Useful for rendering typewriter effects in UI.
|
|
588
|
+
*/
|
|
589
|
+
declare function streamToCallback(stream: AsyncGenerator<string, void, unknown>, onChunk: (chunk: string) => void): Promise<void>;
|
|
590
|
+
/**
|
|
591
|
+
* Consume an async token stream and return the full accumulated string.
|
|
592
|
+
*/
|
|
593
|
+
declare function streamToString(stream: AsyncGenerator<string, void, unknown>): Promise<string>;
|
|
594
|
+
/**
|
|
595
|
+
* Stream tokens from a cortex directly to a callback.
|
|
596
|
+
* Convenience wrapper combining cortex.completeStream + streamToCallback.
|
|
597
|
+
*
|
|
598
|
+
* @example
|
|
599
|
+
* // Typewriter effect in a React component:
|
|
600
|
+
* await streamFromCortex(cortex, prompt, (token) => {
|
|
601
|
+
* setDisplayText(prev => prev + token);
|
|
602
|
+
* });
|
|
603
|
+
*/
|
|
604
|
+
declare function streamFromCortex(cortex: ICortex, prompt: string, onChunk: (chunk: string) => void, options?: {
|
|
605
|
+
temperature?: number;
|
|
606
|
+
maxTokens?: number;
|
|
607
|
+
stop?: string[];
|
|
608
|
+
}): Promise<string>;
|
|
609
|
+
/**
|
|
610
|
+
* Stream tokens from a cortex with a delay between tokens (for typewriter pacing).
|
|
611
|
+
*
|
|
612
|
+
* @param delayMs - Milliseconds to wait between tokens (default: 30ms)
|
|
613
|
+
*
|
|
614
|
+
* @example
|
|
615
|
+
* await streamFromCortexWithDelay(cortex, prompt, (token) => {
|
|
616
|
+
* setDisplayText(prev => prev + token);
|
|
617
|
+
* }, { delayMs: 25 });
|
|
618
|
+
*/
|
|
619
|
+
declare function streamFromCortexWithDelay(cortex: ICortex, prompt: string, onChunk: (chunk: string) => void, options?: {
|
|
620
|
+
temperature?: number;
|
|
621
|
+
maxTokens?: number;
|
|
622
|
+
stop?: string[];
|
|
623
|
+
delayMs?: number;
|
|
624
|
+
}): Promise<string>;
|
|
558
625
|
|
|
559
626
|
interface RPGAgentState extends AgentState {
|
|
560
627
|
inventory: string[];
|
|
@@ -605,6 +672,6 @@ declare namespace index {
|
|
|
605
672
|
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 };
|
|
606
673
|
}
|
|
607
674
|
|
|
608
|
-
declare const SDK_VERSION = "0.5.
|
|
675
|
+
declare const SDK_VERSION = "0.5.7";
|
|
609
676
|
|
|
610
|
-
export { type AgentAction, type AgentConfig, type AgentResponse, type AgentState, type BridgeConfig, type CompletionOptions, type ContextRequest, type ContextResponse, type CortexConfig, type CortexStatus, type DirectiveRequest, type DirectiveResponse, type GhostConfig, type GhostHistoryEntry, type GhostResults, type GhostStatus, type GhostTestResult, type IAgent, type IBridge, type ICortex, type IGhost, type IMemory, type ISoul, type MemoryItem, type MemoryRecallInstruction, type MemoryStoreInstruction, 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, serializeSoul, startGhostSession, stopGhostSession, updateAgentState, uploadToArweave, validateAction, validateSoul, waitForGhostCompletion };
|
|
677
|
+
export { type AgentAction, type AgentConfig, type AgentResponse, type AgentState, type BridgeConfig, type CompletionOptions, type ContextRequest, type ContextResponse, type CortexConfig, type CortexStatus, type DirectiveRequest, type DirectiveResponse, type GhostConfig, type GhostHistoryEntry, type GhostResults, type GhostStatus, type GhostTestResult, type IAgent, type IBridge, type ICortex, type IGhost, type IMemory, type ISoul, type MemoryItem, type MemoryRecallInstruction, type MemoryStoreInstruction, type PromptConstraints, type RecalledMemory, SDK_VERSION, type Soul, type SoulExportConfig, type SoulExportResult, type SoulImportConfig, type SoulListEntry, type SpeakRequest, type SpeakResponse, 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, serializeSoul, startGhostSession, stopGhostSession, streamFromCortex, streamFromCortexWithDelay, streamToCallback, streamToString, updateAgentState, uploadToArweave, validateAction, validateSoul, waitForGhostCompletion };
|
package/dist/index.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ interface AgentConfig {
|
|
|
49
49
|
persona: string;
|
|
50
50
|
initialState?: Partial<AgentState>;
|
|
51
51
|
apiUrl?: string;
|
|
52
|
+
apiKey?: string;
|
|
52
53
|
}
|
|
53
54
|
interface AgentResponse {
|
|
54
55
|
dialogue: string;
|
|
@@ -100,6 +101,20 @@ interface RecalledMemory {
|
|
|
100
101
|
importance: number;
|
|
101
102
|
similarity?: number;
|
|
102
103
|
}
|
|
104
|
+
/** Speak Request (Simple Dialogue) */
|
|
105
|
+
interface SpeakRequest {
|
|
106
|
+
speakMessage: string;
|
|
107
|
+
speakContext?: Record<string, unknown>;
|
|
108
|
+
speakAgentState: Record<string, unknown>;
|
|
109
|
+
}
|
|
110
|
+
/** Speak Response (Simple Dialogue) */
|
|
111
|
+
interface SpeakResponse {
|
|
112
|
+
speakReply: string;
|
|
113
|
+
speakHistory: Array<{
|
|
114
|
+
role: string;
|
|
115
|
+
content: string;
|
|
116
|
+
}>;
|
|
117
|
+
}
|
|
103
118
|
/** Step 5: API → SDK. API returns full SLM prompt + constraints. */
|
|
104
119
|
interface ContextResponse {
|
|
105
120
|
prompt: string;
|
|
@@ -171,6 +186,17 @@ interface IAgent {
|
|
|
171
186
|
* @returns A promise that resolves to the agent's response.
|
|
172
187
|
*/
|
|
173
188
|
process(input: string, context?: Record<string, unknown>): Promise<AgentResponse>;
|
|
189
|
+
/**
|
|
190
|
+
* Generates a conversational response (bypassing the multi-round ruleset evaluation).
|
|
191
|
+
* @param message - The input message.
|
|
192
|
+
* @param context - Optional context overrides.
|
|
193
|
+
* @returns A promise resolving to the agent's textual reply.
|
|
194
|
+
*/
|
|
195
|
+
speak(message: string, context?: Record<string, unknown>): Promise<string>;
|
|
196
|
+
/**
|
|
197
|
+
* Alias for `speak()`.
|
|
198
|
+
*/
|
|
199
|
+
reply(message: string, context?: Record<string, unknown>): Promise<string>;
|
|
174
200
|
/**
|
|
175
201
|
* Retrieves the current state of the agent.
|
|
176
202
|
* @returns The current AgentState.
|
|
@@ -554,7 +580,48 @@ declare const createGhost: (config: GhostConfig) => IGhost;
|
|
|
554
580
|
* Creates a remote Cortex instance that proxies inference to the ForbocAI API.
|
|
555
581
|
* This is environment-agnostic as it only uses the standard fetch API.
|
|
556
582
|
*/
|
|
557
|
-
declare const createRemoteCortex: (apiUrl: string, cortexId?: string) => ICortex;
|
|
583
|
+
declare const createRemoteCortex: (apiUrl: string, cortexId?: string, apiKey?: string) => ICortex;
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Consume an async token stream, calling `onChunk` for each token.
|
|
587
|
+
* Useful for rendering typewriter effects in UI.
|
|
588
|
+
*/
|
|
589
|
+
declare function streamToCallback(stream: AsyncGenerator<string, void, unknown>, onChunk: (chunk: string) => void): Promise<void>;
|
|
590
|
+
/**
|
|
591
|
+
* Consume an async token stream and return the full accumulated string.
|
|
592
|
+
*/
|
|
593
|
+
declare function streamToString(stream: AsyncGenerator<string, void, unknown>): Promise<string>;
|
|
594
|
+
/**
|
|
595
|
+
* Stream tokens from a cortex directly to a callback.
|
|
596
|
+
* Convenience wrapper combining cortex.completeStream + streamToCallback.
|
|
597
|
+
*
|
|
598
|
+
* @example
|
|
599
|
+
* // Typewriter effect in a React component:
|
|
600
|
+
* await streamFromCortex(cortex, prompt, (token) => {
|
|
601
|
+
* setDisplayText(prev => prev + token);
|
|
602
|
+
* });
|
|
603
|
+
*/
|
|
604
|
+
declare function streamFromCortex(cortex: ICortex, prompt: string, onChunk: (chunk: string) => void, options?: {
|
|
605
|
+
temperature?: number;
|
|
606
|
+
maxTokens?: number;
|
|
607
|
+
stop?: string[];
|
|
608
|
+
}): Promise<string>;
|
|
609
|
+
/**
|
|
610
|
+
* Stream tokens from a cortex with a delay between tokens (for typewriter pacing).
|
|
611
|
+
*
|
|
612
|
+
* @param delayMs - Milliseconds to wait between tokens (default: 30ms)
|
|
613
|
+
*
|
|
614
|
+
* @example
|
|
615
|
+
* await streamFromCortexWithDelay(cortex, prompt, (token) => {
|
|
616
|
+
* setDisplayText(prev => prev + token);
|
|
617
|
+
* }, { delayMs: 25 });
|
|
618
|
+
*/
|
|
619
|
+
declare function streamFromCortexWithDelay(cortex: ICortex, prompt: string, onChunk: (chunk: string) => void, options?: {
|
|
620
|
+
temperature?: number;
|
|
621
|
+
maxTokens?: number;
|
|
622
|
+
stop?: string[];
|
|
623
|
+
delayMs?: number;
|
|
624
|
+
}): Promise<string>;
|
|
558
625
|
|
|
559
626
|
interface RPGAgentState extends AgentState {
|
|
560
627
|
inventory: string[];
|
|
@@ -605,6 +672,6 @@ declare namespace index {
|
|
|
605
672
|
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 };
|
|
606
673
|
}
|
|
607
674
|
|
|
608
|
-
declare const SDK_VERSION = "0.5.
|
|
675
|
+
declare const SDK_VERSION = "0.5.7";
|
|
609
676
|
|
|
610
|
-
export { type AgentAction, type AgentConfig, type AgentResponse, type AgentState, type BridgeConfig, type CompletionOptions, type ContextRequest, type ContextResponse, type CortexConfig, type CortexStatus, type DirectiveRequest, type DirectiveResponse, type GhostConfig, type GhostHistoryEntry, type GhostResults, type GhostStatus, type GhostTestResult, type IAgent, type IBridge, type ICortex, type IGhost, type IMemory, type ISoul, type MemoryItem, type MemoryRecallInstruction, type MemoryStoreInstruction, 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, serializeSoul, startGhostSession, stopGhostSession, updateAgentState, uploadToArweave, validateAction, validateSoul, waitForGhostCompletion };
|
|
677
|
+
export { type AgentAction, type AgentConfig, type AgentResponse, type AgentState, type BridgeConfig, type CompletionOptions, type ContextRequest, type ContextResponse, type CortexConfig, type CortexStatus, type DirectiveRequest, type DirectiveResponse, type GhostConfig, type GhostHistoryEntry, type GhostResults, type GhostStatus, type GhostTestResult, type IAgent, type IBridge, type ICortex, type IGhost, type IMemory, type ISoul, type MemoryItem, type MemoryRecallInstruction, type MemoryStoreInstruction, type PromptConstraints, type RecalledMemory, SDK_VERSION, type Soul, type SoulExportConfig, type SoulExportResult, type SoulImportConfig, type SoulListEntry, type SpeakRequest, type SpeakResponse, 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, serializeSoul, startGhostSession, stopGhostSession, streamFromCortex, streamFromCortexWithDelay, streamToCallback, streamToString, updateAgentState, uploadToArweave, validateAction, validateSoul, waitForGhostCompletion };
|
package/dist/index.js
CHANGED
|
@@ -284,6 +284,10 @@ __export(index_exports, {
|
|
|
284
284
|
serializeSoul: () => serializeSoul,
|
|
285
285
|
startGhostSession: () => startGhostSession,
|
|
286
286
|
stopGhostSession: () => stopGhostSession,
|
|
287
|
+
streamFromCortex: () => streamFromCortex,
|
|
288
|
+
streamFromCortexWithDelay: () => streamFromCortexWithDelay,
|
|
289
|
+
streamToCallback: () => streamToCallback,
|
|
290
|
+
streamToString: () => streamToString,
|
|
287
291
|
updateAgentState: () => updateAgentState,
|
|
288
292
|
uploadToArweave: () => uploadToArweave,
|
|
289
293
|
validateAction: () => validateAction,
|
|
@@ -317,6 +321,7 @@ var createAgent = (config) => {
|
|
|
317
321
|
const cortex = config.cortex;
|
|
318
322
|
const apiUrl = config.apiUrl || "https://api.forboc.ai";
|
|
319
323
|
const agentId = config.id || "agent-" + Math.random().toString(36).substring(7);
|
|
324
|
+
const authHeaders = config.apiKey ? { "Content-Type": "application/json", "Authorization": `Bearer ${config.apiKey}` } : { "Content-Type": "application/json" };
|
|
320
325
|
const getAgentState = () => {
|
|
321
326
|
return { ...state };
|
|
322
327
|
};
|
|
@@ -332,7 +337,7 @@ var createAgent = (config) => {
|
|
|
332
337
|
};
|
|
333
338
|
const dirRes = await fetch(`${apiUrl}/agents/${agentId}/directive`, {
|
|
334
339
|
method: "POST",
|
|
335
|
-
headers:
|
|
340
|
+
headers: authHeaders,
|
|
336
341
|
body: JSON.stringify(directiveBody)
|
|
337
342
|
});
|
|
338
343
|
if (!dirRes.ok) {
|
|
@@ -364,7 +369,7 @@ var createAgent = (config) => {
|
|
|
364
369
|
};
|
|
365
370
|
const ctxRes = await fetch(`${apiUrl}/agents/${agentId}/context`, {
|
|
366
371
|
method: "POST",
|
|
367
|
-
headers:
|
|
372
|
+
headers: authHeaders,
|
|
368
373
|
body: JSON.stringify(contextBody)
|
|
369
374
|
});
|
|
370
375
|
if (!ctxRes.ok) {
|
|
@@ -383,7 +388,7 @@ var createAgent = (config) => {
|
|
|
383
388
|
};
|
|
384
389
|
const verRes = await fetch(`${apiUrl}/agents/${agentId}/verdict`, {
|
|
385
390
|
method: "POST",
|
|
386
|
-
headers:
|
|
391
|
+
headers: authHeaders,
|
|
387
392
|
body: JSON.stringify(verdictBody)
|
|
388
393
|
});
|
|
389
394
|
if (!verRes.ok) {
|
|
@@ -413,6 +418,28 @@ var createAgent = (config) => {
|
|
|
413
418
|
thought: generatedText
|
|
414
419
|
};
|
|
415
420
|
};
|
|
421
|
+
const speak = async (message, context = {}) => {
|
|
422
|
+
const currentState = getAgentState();
|
|
423
|
+
const speakBody = {
|
|
424
|
+
speakMessage: message,
|
|
425
|
+
speakContext: Object.keys(context).length > 0 ? context : void 0,
|
|
426
|
+
speakAgentState: currentState
|
|
427
|
+
};
|
|
428
|
+
const res = await fetch(`${apiUrl}/agents/${agentId}/speak`, {
|
|
429
|
+
method: "POST",
|
|
430
|
+
headers: authHeaders,
|
|
431
|
+
body: JSON.stringify(speakBody)
|
|
432
|
+
});
|
|
433
|
+
if (!res.ok) {
|
|
434
|
+
throw new Error(`API Speak Error: ${res.status}`);
|
|
435
|
+
}
|
|
436
|
+
const data = await res.json();
|
|
437
|
+
if (data.speakHistory) {
|
|
438
|
+
state = updateAgentState(state, { conversationHistory: data.speakHistory });
|
|
439
|
+
}
|
|
440
|
+
return data.speakReply;
|
|
441
|
+
};
|
|
442
|
+
const reply = speak;
|
|
416
443
|
const exportSoul2 = async () => {
|
|
417
444
|
let exportedMemories = [];
|
|
418
445
|
if (config.memory && typeof config.memory.export === "function") {
|
|
@@ -426,6 +453,8 @@ var createAgent = (config) => {
|
|
|
426
453
|
};
|
|
427
454
|
return {
|
|
428
455
|
process,
|
|
456
|
+
speak,
|
|
457
|
+
reply,
|
|
429
458
|
getState: getAgentState,
|
|
430
459
|
setState: setAgentState,
|
|
431
460
|
export: exportSoul2
|
|
@@ -906,7 +935,11 @@ var createGhost = (config) => {
|
|
|
906
935
|
};
|
|
907
936
|
|
|
908
937
|
// src/cortex-remote.ts
|
|
909
|
-
var createRemoteCortex = (apiUrl, cortexId = "local") => {
|
|
938
|
+
var createRemoteCortex = (apiUrl, cortexId = "local", apiKey) => {
|
|
939
|
+
const authHeaders = {
|
|
940
|
+
"Content-Type": "application/json",
|
|
941
|
+
...apiKey ? { "Authorization": `Bearer ${apiKey}` } : {}
|
|
942
|
+
};
|
|
910
943
|
const init = async () => ({
|
|
911
944
|
id: `remote_${Date.now()}`,
|
|
912
945
|
model: "api-integrated",
|
|
@@ -916,7 +949,7 @@ var createRemoteCortex = (apiUrl, cortexId = "local") => {
|
|
|
916
949
|
const complete = async (prompt, options) => {
|
|
917
950
|
const response = await fetch(`${apiUrl}/cortex/${cortexId}/complete`, {
|
|
918
951
|
method: "POST",
|
|
919
|
-
headers:
|
|
952
|
+
headers: authHeaders,
|
|
920
953
|
body: JSON.stringify({ prompt, ...options })
|
|
921
954
|
});
|
|
922
955
|
if (!response.ok) throw new Error(`Remote Cortex failed: ${response.statusText}`);
|
|
@@ -930,6 +963,42 @@ var createRemoteCortex = (apiUrl, cortexId = "local") => {
|
|
|
930
963
|
return { init, complete, completeStream };
|
|
931
964
|
};
|
|
932
965
|
|
|
966
|
+
// src/stream.ts
|
|
967
|
+
async function streamToCallback(stream, onChunk) {
|
|
968
|
+
for await (const chunk of stream) {
|
|
969
|
+
onChunk(chunk);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
async function streamToString(stream) {
|
|
973
|
+
let fullText = "";
|
|
974
|
+
for await (const chunk of stream) {
|
|
975
|
+
fullText += chunk;
|
|
976
|
+
}
|
|
977
|
+
return fullText;
|
|
978
|
+
}
|
|
979
|
+
async function streamFromCortex(cortex, prompt, onChunk, options) {
|
|
980
|
+
const stream = cortex.completeStream(prompt, options);
|
|
981
|
+
let fullText = "";
|
|
982
|
+
for await (const chunk of stream) {
|
|
983
|
+
fullText += chunk;
|
|
984
|
+
onChunk(chunk);
|
|
985
|
+
}
|
|
986
|
+
return fullText;
|
|
987
|
+
}
|
|
988
|
+
async function streamFromCortexWithDelay(cortex, prompt, onChunk, options) {
|
|
989
|
+
const { delayMs = 30, ...completionOptions } = options ?? {};
|
|
990
|
+
const stream = cortex.completeStream(prompt, completionOptions);
|
|
991
|
+
let fullText = "";
|
|
992
|
+
for await (const chunk of stream) {
|
|
993
|
+
fullText += chunk;
|
|
994
|
+
onChunk(chunk);
|
|
995
|
+
if (delayMs > 0) {
|
|
996
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
return fullText;
|
|
1000
|
+
}
|
|
1001
|
+
|
|
933
1002
|
// src/presets/index.ts
|
|
934
1003
|
var presets_exports = {};
|
|
935
1004
|
__export(presets_exports, {
|
|
@@ -1137,7 +1206,7 @@ var socialRules = [speakRule, interactRule];
|
|
|
1137
1206
|
var puzzleRules = [movementRule, interactRule];
|
|
1138
1207
|
|
|
1139
1208
|
// src/index.ts
|
|
1140
|
-
var SDK_VERSION = "0.5.
|
|
1209
|
+
var SDK_VERSION = "0.5.7";
|
|
1141
1210
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1142
1211
|
0 && (module.exports = {
|
|
1143
1212
|
SDK_VERSION,
|
|
@@ -1161,6 +1230,10 @@ var SDK_VERSION = "0.5.6";
|
|
|
1161
1230
|
serializeSoul,
|
|
1162
1231
|
startGhostSession,
|
|
1163
1232
|
stopGhostSession,
|
|
1233
|
+
streamFromCortex,
|
|
1234
|
+
streamFromCortexWithDelay,
|
|
1235
|
+
streamToCallback,
|
|
1236
|
+
streamToString,
|
|
1164
1237
|
updateAgentState,
|
|
1165
1238
|
uploadToArweave,
|
|
1166
1239
|
validateAction,
|
package/dist/index.mjs
CHANGED
|
@@ -27,6 +27,7 @@ var createAgent = (config) => {
|
|
|
27
27
|
const cortex = config.cortex;
|
|
28
28
|
const apiUrl = config.apiUrl || "https://api.forboc.ai";
|
|
29
29
|
const agentId = config.id || "agent-" + Math.random().toString(36).substring(7);
|
|
30
|
+
const authHeaders = config.apiKey ? { "Content-Type": "application/json", "Authorization": `Bearer ${config.apiKey}` } : { "Content-Type": "application/json" };
|
|
30
31
|
const getAgentState = () => {
|
|
31
32
|
return { ...state };
|
|
32
33
|
};
|
|
@@ -42,7 +43,7 @@ var createAgent = (config) => {
|
|
|
42
43
|
};
|
|
43
44
|
const dirRes = await fetch(`${apiUrl}/agents/${agentId}/directive`, {
|
|
44
45
|
method: "POST",
|
|
45
|
-
headers:
|
|
46
|
+
headers: authHeaders,
|
|
46
47
|
body: JSON.stringify(directiveBody)
|
|
47
48
|
});
|
|
48
49
|
if (!dirRes.ok) {
|
|
@@ -74,7 +75,7 @@ var createAgent = (config) => {
|
|
|
74
75
|
};
|
|
75
76
|
const ctxRes = await fetch(`${apiUrl}/agents/${agentId}/context`, {
|
|
76
77
|
method: "POST",
|
|
77
|
-
headers:
|
|
78
|
+
headers: authHeaders,
|
|
78
79
|
body: JSON.stringify(contextBody)
|
|
79
80
|
});
|
|
80
81
|
if (!ctxRes.ok) {
|
|
@@ -93,7 +94,7 @@ var createAgent = (config) => {
|
|
|
93
94
|
};
|
|
94
95
|
const verRes = await fetch(`${apiUrl}/agents/${agentId}/verdict`, {
|
|
95
96
|
method: "POST",
|
|
96
|
-
headers:
|
|
97
|
+
headers: authHeaders,
|
|
97
98
|
body: JSON.stringify(verdictBody)
|
|
98
99
|
});
|
|
99
100
|
if (!verRes.ok) {
|
|
@@ -123,6 +124,28 @@ var createAgent = (config) => {
|
|
|
123
124
|
thought: generatedText
|
|
124
125
|
};
|
|
125
126
|
};
|
|
127
|
+
const speak = async (message, context = {}) => {
|
|
128
|
+
const currentState = getAgentState();
|
|
129
|
+
const speakBody = {
|
|
130
|
+
speakMessage: message,
|
|
131
|
+
speakContext: Object.keys(context).length > 0 ? context : void 0,
|
|
132
|
+
speakAgentState: currentState
|
|
133
|
+
};
|
|
134
|
+
const res = await fetch(`${apiUrl}/agents/${agentId}/speak`, {
|
|
135
|
+
method: "POST",
|
|
136
|
+
headers: authHeaders,
|
|
137
|
+
body: JSON.stringify(speakBody)
|
|
138
|
+
});
|
|
139
|
+
if (!res.ok) {
|
|
140
|
+
throw new Error(`API Speak Error: ${res.status}`);
|
|
141
|
+
}
|
|
142
|
+
const data = await res.json();
|
|
143
|
+
if (data.speakHistory) {
|
|
144
|
+
state = updateAgentState(state, { conversationHistory: data.speakHistory });
|
|
145
|
+
}
|
|
146
|
+
return data.speakReply;
|
|
147
|
+
};
|
|
148
|
+
const reply = speak;
|
|
126
149
|
const exportSoul2 = async () => {
|
|
127
150
|
let exportedMemories = [];
|
|
128
151
|
if (config.memory && typeof config.memory.export === "function") {
|
|
@@ -136,6 +159,8 @@ var createAgent = (config) => {
|
|
|
136
159
|
};
|
|
137
160
|
return {
|
|
138
161
|
process,
|
|
162
|
+
speak,
|
|
163
|
+
reply,
|
|
139
164
|
getState: getAgentState,
|
|
140
165
|
setState: setAgentState,
|
|
141
166
|
export: exportSoul2
|
|
@@ -616,7 +641,11 @@ var createGhost = (config) => {
|
|
|
616
641
|
};
|
|
617
642
|
|
|
618
643
|
// src/cortex-remote.ts
|
|
619
|
-
var createRemoteCortex = (apiUrl, cortexId = "local") => {
|
|
644
|
+
var createRemoteCortex = (apiUrl, cortexId = "local", apiKey) => {
|
|
645
|
+
const authHeaders = {
|
|
646
|
+
"Content-Type": "application/json",
|
|
647
|
+
...apiKey ? { "Authorization": `Bearer ${apiKey}` } : {}
|
|
648
|
+
};
|
|
620
649
|
const init = async () => ({
|
|
621
650
|
id: `remote_${Date.now()}`,
|
|
622
651
|
model: "api-integrated",
|
|
@@ -626,7 +655,7 @@ var createRemoteCortex = (apiUrl, cortexId = "local") => {
|
|
|
626
655
|
const complete = async (prompt, options) => {
|
|
627
656
|
const response = await fetch(`${apiUrl}/cortex/${cortexId}/complete`, {
|
|
628
657
|
method: "POST",
|
|
629
|
-
headers:
|
|
658
|
+
headers: authHeaders,
|
|
630
659
|
body: JSON.stringify({ prompt, ...options })
|
|
631
660
|
});
|
|
632
661
|
if (!response.ok) throw new Error(`Remote Cortex failed: ${response.statusText}`);
|
|
@@ -640,6 +669,42 @@ var createRemoteCortex = (apiUrl, cortexId = "local") => {
|
|
|
640
669
|
return { init, complete, completeStream };
|
|
641
670
|
};
|
|
642
671
|
|
|
672
|
+
// src/stream.ts
|
|
673
|
+
async function streamToCallback(stream, onChunk) {
|
|
674
|
+
for await (const chunk of stream) {
|
|
675
|
+
onChunk(chunk);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
async function streamToString(stream) {
|
|
679
|
+
let fullText = "";
|
|
680
|
+
for await (const chunk of stream) {
|
|
681
|
+
fullText += chunk;
|
|
682
|
+
}
|
|
683
|
+
return fullText;
|
|
684
|
+
}
|
|
685
|
+
async function streamFromCortex(cortex, prompt, onChunk, options) {
|
|
686
|
+
const stream = cortex.completeStream(prompt, options);
|
|
687
|
+
let fullText = "";
|
|
688
|
+
for await (const chunk of stream) {
|
|
689
|
+
fullText += chunk;
|
|
690
|
+
onChunk(chunk);
|
|
691
|
+
}
|
|
692
|
+
return fullText;
|
|
693
|
+
}
|
|
694
|
+
async function streamFromCortexWithDelay(cortex, prompt, onChunk, options) {
|
|
695
|
+
const { delayMs = 30, ...completionOptions } = options ?? {};
|
|
696
|
+
const stream = cortex.completeStream(prompt, completionOptions);
|
|
697
|
+
let fullText = "";
|
|
698
|
+
for await (const chunk of stream) {
|
|
699
|
+
fullText += chunk;
|
|
700
|
+
onChunk(chunk);
|
|
701
|
+
if (delayMs > 0) {
|
|
702
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
return fullText;
|
|
706
|
+
}
|
|
707
|
+
|
|
643
708
|
// src/presets/index.ts
|
|
644
709
|
var presets_exports = {};
|
|
645
710
|
__export(presets_exports, {
|
|
@@ -847,7 +912,7 @@ var socialRules = [speakRule, interactRule];
|
|
|
847
912
|
var puzzleRules = [movementRule, interactRule];
|
|
848
913
|
|
|
849
914
|
// src/index.ts
|
|
850
|
-
var SDK_VERSION = "0.5.
|
|
915
|
+
var SDK_VERSION = "0.5.7";
|
|
851
916
|
export {
|
|
852
917
|
SDK_VERSION,
|
|
853
918
|
createAgent,
|
|
@@ -870,6 +935,10 @@ export {
|
|
|
870
935
|
serializeSoul,
|
|
871
936
|
startGhostSession,
|
|
872
937
|
stopGhostSession,
|
|
938
|
+
streamFromCortex,
|
|
939
|
+
streamFromCortexWithDelay,
|
|
940
|
+
streamToCallback,
|
|
941
|
+
streamToString,
|
|
873
942
|
updateAgentState,
|
|
874
943
|
uploadToArweave,
|
|
875
944
|
validateAction,
|