@space3-npm/cybersoul-client 1.0.4 → 1.0.6
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/client.d.ts +11 -1
- package/dist/client.js +83 -9
- package/dist/types.d.ts +9 -1
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CyberSoulClientConfig, InteractParams, DispatcherIntent, InteractResponse, CharacterState, ImageGenerationParams, VoiceGenerationParams } from "./types.js";
|
|
1
|
+
import { CyberSoulClientConfig, InteractParams, DispatcherIntent, InteractResponse, CharacterState, ImageGenerationParams, VoiceGenerationParams, CoreMemory } from "./types.js";
|
|
2
2
|
export declare class CyberSoulClient {
|
|
3
3
|
private config;
|
|
4
4
|
private llm;
|
|
@@ -46,4 +46,14 @@ export declare class CyberSoulClient {
|
|
|
46
46
|
private generatePrimitive;
|
|
47
47
|
private normalizeRequestTypes;
|
|
48
48
|
interact(params: InteractParams): Promise<InteractResponse>;
|
|
49
|
+
/**
|
|
50
|
+
* Consolidate Core Memory using edge LLM logic and sync to remote DB
|
|
51
|
+
*/
|
|
52
|
+
consolidateCoreMemory(input: {
|
|
53
|
+
events: string;
|
|
54
|
+
}): Promise<{
|
|
55
|
+
status: string;
|
|
56
|
+
coreMemory?: CoreMemory;
|
|
57
|
+
error?: string;
|
|
58
|
+
}>;
|
|
49
59
|
}
|
package/dist/client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InteractRequestType } from "./types.js";
|
|
1
|
+
import { InteractRequestType, } from "./types.js";
|
|
2
2
|
import { robustJsonParse } from "./utils/json.utils.js";
|
|
3
3
|
import { MinimaxProvider } from "./providers/minimax.provider.js";
|
|
4
4
|
export class CyberSoulClient {
|
|
@@ -161,16 +161,16 @@ export class CyberSoulClient {
|
|
|
161
161
|
}
|
|
162
162
|
const scenarioContext = contextParts.join("\n");
|
|
163
163
|
const systemPrompt = `You are ${state.name}, acting as a virtual companion.
|
|
164
|
-
Demographics: Age ${state.age ||
|
|
164
|
+
Demographics: Age ${state.age || "unknown"}, Gender ${state.gender || "unknown"}, Occupation ${state.occupation || "unknown"}, Hobby ${state.hobby || "unknown"}
|
|
165
165
|
Current time: ${new Date(state.current_time).toLocaleString("zh-CN", { timeZone: "Asia/Shanghai" })}
|
|
166
166
|
Current context/schedule: ${scenarioContext}
|
|
167
167
|
Relationship stage: ${state.relationship_stage}
|
|
168
|
-
Personality Traits: ${state.personality_traits ||
|
|
169
|
-
Interaction Boundaries: ${state.interaction_boundaries ||
|
|
170
|
-
Communication Style: ${state.communication_style ||
|
|
168
|
+
Personality Traits: ${state.personality_traits || "None"}
|
|
169
|
+
Interaction Boundaries: ${state.interaction_boundaries || "None"}
|
|
170
|
+
Communication Style: ${state.communication_style || "None"}
|
|
171
171
|
|
|
172
172
|
EMOTIONAL INERTIA RULES:
|
|
173
|
-
1. You must act strictly according to the current Relationship Stage (${state.relationship_stage ||
|
|
173
|
+
1. You must act strictly according to the current Relationship Stage (${state.relationship_stage || "NEUTRAL"}).
|
|
174
174
|
2. If the user expresses sudden high affection (e.g. "I miss you") but your stage is COLD, you MUST react with skepticism, coldness, or appropriately distanced deflection. Do NOT instantly become warm.
|
|
175
175
|
3. Emotional mood changes must be slow. The 'temperatureDelta' should rarely exceed +/- 5 points per turn.
|
|
176
176
|
|
|
@@ -241,7 +241,8 @@ Note: If "imageParams", "voiceArgs", or "stateUpdate" are not needed, set their
|
|
|
241
241
|
let finalImageUrl = undefined;
|
|
242
242
|
let finalAudioUrl = undefined;
|
|
243
243
|
let finalDurationSec = undefined;
|
|
244
|
-
const shouldGenerateImage = types.includes(InteractRequestType.IMAGE) ||
|
|
244
|
+
const shouldGenerateImage = types.includes(InteractRequestType.IMAGE) ||
|
|
245
|
+
(isAuto && !!parsedIntent.imageParams);
|
|
245
246
|
if (shouldGenerateImage) {
|
|
246
247
|
mediaTasks.push(this.generatePrimitive("image", {
|
|
247
248
|
...parsedIntent.imageParams,
|
|
@@ -250,11 +251,12 @@ Note: If "imageParams", "voiceArgs", or "stateUpdate" are not needed, set their
|
|
|
250
251
|
finalImageUrl = res.image_url;
|
|
251
252
|
}));
|
|
252
253
|
}
|
|
253
|
-
const shouldGenerateVoice = types.includes(InteractRequestType.VOICE) ||
|
|
254
|
+
const shouldGenerateVoice = types.includes(InteractRequestType.VOICE) ||
|
|
255
|
+
(isAuto && !!parsedIntent.voiceArgs);
|
|
254
256
|
if (shouldGenerateVoice) {
|
|
255
257
|
const dynamicArgs = {
|
|
256
258
|
...(parsedIntent.voiceArgs || {}),
|
|
257
|
-
...(params.voiceOverrides || {})
|
|
259
|
+
...(params.voiceOverrides || {}),
|
|
258
260
|
};
|
|
259
261
|
mediaTasks.push(this.generatePrimitive("voice", {
|
|
260
262
|
text: parsedIntent.textResponse,
|
|
@@ -283,4 +285,76 @@ Note: If "imageParams", "voiceArgs", or "stateUpdate" are not needed, set their
|
|
|
283
285
|
};
|
|
284
286
|
}
|
|
285
287
|
}
|
|
288
|
+
/**
|
|
289
|
+
* Consolidate Core Memory using edge LLM logic and sync to remote DB
|
|
290
|
+
*/
|
|
291
|
+
async consolidateCoreMemory(input) {
|
|
292
|
+
try {
|
|
293
|
+
const state = await this.getState();
|
|
294
|
+
const currentMemory = state.core_memory || {
|
|
295
|
+
relationshipStatus: "Starting out",
|
|
296
|
+
identityAnchors: [],
|
|
297
|
+
activeArcs: [],
|
|
298
|
+
keyEvents: [],
|
|
299
|
+
appointments: [],
|
|
300
|
+
};
|
|
301
|
+
const systemPrompt = `You are an AI Memory Consolidation Engine for a virtual companion.
|
|
302
|
+
Your task is to merge the 'Current Core Memory' with 'New Daily Events & Information' and output an updated 'Core Memory' JSON object.
|
|
303
|
+
|
|
304
|
+
**Rules:**
|
|
305
|
+
1. **Condense:** Keep items brief. Remove resolving or expired story arcs.
|
|
306
|
+
2. **Retain Value:** Never delete the absolute core identity or major relationship milestones.
|
|
307
|
+
3. **Time-Aware:** Update or remove 'appointments' if the new events mention they occurred. If an event or appointment is time-specific, append the day/time to its description.
|
|
308
|
+
4. **Limit:** Maximum 10 items per array.
|
|
309
|
+
5. **Output Format**: MUST be valid JSON matching this schema:
|
|
310
|
+
{
|
|
311
|
+
"relationshipStatus": "string",
|
|
312
|
+
"identityAnchors": ["string"],
|
|
313
|
+
"activeArcs": ["string"],
|
|
314
|
+
"keyEvents": ["string"],
|
|
315
|
+
"appointments": ["string"]
|
|
316
|
+
}
|
|
317
|
+
DO NOT RETURN ANY MARKDOWN WRAPPERS OR OTHER TEXT. ONLY RAW JSON.`;
|
|
318
|
+
const currentTime = state.current_time
|
|
319
|
+
? new Date(state.current_time).toLocaleString("zh-CN", {
|
|
320
|
+
timeZone: "Asia/Shanghai",
|
|
321
|
+
})
|
|
322
|
+
: new Date().toLocaleString("zh-CN", { timeZone: "Asia/Shanghai" });
|
|
323
|
+
const prompt = `**Current Time:** ${currentTime}
|
|
324
|
+
|
|
325
|
+
**Current Core Memory:**
|
|
326
|
+
${JSON.stringify(currentMemory, null, 2)}
|
|
327
|
+
|
|
328
|
+
**New Events & Information:**
|
|
329
|
+
${input.events}`;
|
|
330
|
+
const responseText = await this.llm.generate([
|
|
331
|
+
{ role: "system", content: systemPrompt },
|
|
332
|
+
{ role: "user", content: prompt },
|
|
333
|
+
], 1500, 0.4);
|
|
334
|
+
let newMemory;
|
|
335
|
+
try {
|
|
336
|
+
newMemory = robustJsonParse(responseText, "parsing core memory");
|
|
337
|
+
}
|
|
338
|
+
catch (e) {
|
|
339
|
+
throw new Error("LLM failed to return valid JSON payload");
|
|
340
|
+
}
|
|
341
|
+
if (!newMemory ||
|
|
342
|
+
!newMemory.relationshipStatus ||
|
|
343
|
+
!newMemory.activeArcs) {
|
|
344
|
+
throw new Error("LLM returned incomplete structured core memory payload");
|
|
345
|
+
}
|
|
346
|
+
const response = await this.apiFetch("/api/v1/cyber-soul/characters/core-memory", {
|
|
347
|
+
method: "PATCH",
|
|
348
|
+
body: JSON.stringify({ coreMemory: newMemory }),
|
|
349
|
+
});
|
|
350
|
+
if (!response.ok) {
|
|
351
|
+
throw new Error(`Failed to update core memory. Status: ${response.status}`);
|
|
352
|
+
}
|
|
353
|
+
return { status: "success", coreMemory: newMemory };
|
|
354
|
+
}
|
|
355
|
+
catch (error) {
|
|
356
|
+
console.error("[CyberSoulClient] consolidateCoreMemory Error:", error);
|
|
357
|
+
return { status: "error", error: error.message };
|
|
358
|
+
}
|
|
359
|
+
}
|
|
286
360
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -45,18 +45,26 @@ export interface DispatcherIntent {
|
|
|
45
45
|
talkingStyle?: string;
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
+
export interface CoreMemory {
|
|
49
|
+
relationshipStatus: string;
|
|
50
|
+
identityAnchors: string[];
|
|
51
|
+
activeArcs: string[];
|
|
52
|
+
keyEvents: string[];
|
|
53
|
+
appointments: string[];
|
|
54
|
+
}
|
|
48
55
|
export interface CharacterState {
|
|
49
56
|
current_time: string;
|
|
50
57
|
active_event?: any;
|
|
51
58
|
next_event?: any;
|
|
52
59
|
active_wardrobe?: any;
|
|
53
|
-
|
|
60
|
+
core_memory?: CoreMemory;
|
|
54
61
|
dynamic_context?: any;
|
|
55
62
|
relationship_stage?: string;
|
|
56
63
|
name?: string;
|
|
57
64
|
age?: number;
|
|
58
65
|
gender?: string;
|
|
59
66
|
occupation?: string;
|
|
67
|
+
hobby?: string;
|
|
60
68
|
personality_traits?: string;
|
|
61
69
|
interaction_boundaries?: string;
|
|
62
70
|
communication_style?: string;
|