@space3-npm/cybersoul-client 1.3.5 → 1.3.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.
Files changed (2) hide show
  1. package/dist/client.js +16 -16
  2. package/package.json +1 -1
package/dist/client.js CHANGED
@@ -154,7 +154,7 @@ export class CyberSoulClient {
154
154
  }
155
155
  return normalized;
156
156
  }
157
- buildStateContextPrompt(state, localContext, isProactive = false) {
157
+ buildStateContextPrompt(state, isProactive = false) {
158
158
  const dyn = state.dynamic_context || {};
159
159
  const stage = state.relationship_stage || "NEUTRAL";
160
160
  const temperature = dyn.temperature ?? 50;
@@ -210,9 +210,6 @@ Current time: ${new Date(currentTimeMs).toLocaleString("zh-CN", { timeZone: "Asi
210
210
  if (state.active_event) {
211
211
  contextParts.push(`Active Event: ${state.active_event.title} (${state.active_event.narrative_context})`);
212
212
  }
213
- if (localContext) {
214
- contextParts.push(`Additional Context: ${localContext}`);
215
- }
216
213
  if (state.next_event) {
217
214
  contextParts.push(`Next Event: ${state.next_event.title} at ${state.next_event.start_time} (in ${state.next_event.time_until_mins} mins)`);
218
215
  }
@@ -411,7 +408,7 @@ ${isProactive
411
408
  const mapped = recentHistory.map((msg) => {
412
409
  const speaker = msg.role === 'user' ? userName : (msg.role === 'assistant' || msg.role === 'agent' ? agentName : msg.role);
413
410
  const content = typeof msg.content === 'string' ? msg.content : JSON.stringify(msg.content);
414
- const action = msg.actionText ? ` ${msg.actionText}` : "";
411
+ const action = msg.actionText ? ` (${msg.actionText})` : "";
415
412
  const media = msg.mediaHint ? ` [${msg.mediaHint}]` : "";
416
413
  return `${speaker}:${action} ${content}${media}`;
417
414
  });
@@ -471,7 +468,7 @@ ${isProactive
471
468
  modalitiesInstruction += `\n ${this.getTriggerEventPolicyPrompt()}
472
469
  ${this.getOutfitAcquisitionPolicyPrompt()}`;
473
470
  // Combine state info into a clean descriptive context
474
- const systemPrompt = `${this.buildStateContextPrompt(state, params.localContext)}
471
+ const systemPrompt = `${this.buildStateContextPrompt(state)}
475
472
  Available Wardrobe Outfits (For event triggers):
476
473
  ${availableOutfits}
477
474
 
@@ -516,13 +513,15 @@ Output JSON Schema:
516
513
  ${this.getVoiceSchemaFromState(state, requestedOthers.includes(InteractRequestType.VOICE))}
517
514
  }
518
515
  Note: Always include "isEndTurn". If "imageParams", "voiceArgs", "triggerEvent", "giftOutfit", or "userAnalysis" are not needed, set them to null. "stateUpdate" cannot be null. Return valid raw JSON only.`;
519
- const transcript = this.buildHistoryTranscript(params.history, state);
516
+ const transcript = params.history && params.history.length > 0 ? this.buildHistoryTranscript(params.history, state) : "";
517
+ const harnessContext = params.localContext ? `[ADDITIONAL SCENE CONTEXT]\n${params.localContext}\n\n` : "";
520
518
  const userName = state.dynamic_context?.userNickname || "User";
521
519
  const promptMessages = [
522
520
  { role: "system", content: systemPrompt },
523
521
  {
524
522
  role: "user",
525
- content: transcript +
523
+ content: harnessContext +
524
+ transcript +
526
525
  `[VERY LAST USER MESSAGE]\n${userName}: ${params.userMessage}\n\n` +
527
526
  "\n\nReturn only valid JSON matching the schema. Escape newlines inside JSON strings with \\n. Keep imageParams values in ENGLISH and use the provided enums.",
528
527
  },
@@ -668,7 +667,7 @@ Note: Always include "isEndTurn". If "imageParams", "voiceArgs", "triggerEvent",
668
667
  this.getWardrobePromptStr()
669
668
  ]);
670
669
  // 2. Build local Prompt
671
- const systemPrompt = `${this.buildStateContextPrompt(state, params.interactParams?.localContext)}
670
+ const systemPrompt = `${this.buildStateContextPrompt(state)}
672
671
 
673
672
  The user proposes a new event for you to participate in: "${params.eventDescription}".
674
673
  Evaluate this based on your current state and relationship stage.
@@ -686,7 +685,8 @@ You MUST output ONLY a valid JSON object matching this exact structure:
686
685
  }
687
686
 
688
687
  CRITICAL: Output MUST be ONLY valid JSON with no markdown block wrappers. Do NOT wrap the JSON in \`\`\`json or add conversational text.`;
689
- const transcript = this.buildHistoryTranscript(params.interactParams?.history, state);
688
+ const transcript = params.interactParams?.history && params.interactParams.history.length > 0 ? this.buildHistoryTranscript(params.interactParams.history, state) : "";
689
+ const harnessContext = params.interactParams?.localContext ? `[ADDITIONAL SCENE CONTEXT]\n${params.interactParams.localContext}\n\n` : "";
690
690
  const userMessage = params.interactParams?.userMessage ?
691
691
  `${state.dynamic_context?.userNickname || "User"}: ${params.interactParams.userMessage}` :
692
692
  `Event Proposal: ${params.eventDescription}`;
@@ -794,9 +794,8 @@ CRITICAL: Output MUST be ONLY valid JSON with no markdown block wrappers. Do NOT
794
794
  // History/Context awareness prompt
795
795
  const historyAwarenessPrompt = `CRITICAL CONTEXT AWARENESS: Read the CHAT HISTORY above carefully. Remember that YOU sent the last message. Your new message MUST feel organically connected to the flow of what you two were previously talking about, or naturally bring up a known event/topic from your [CORE MEMORY]. Do not sound like a robot reading a log.`;
796
796
  // 4. Build a Proactive-specific System Prompt
797
- const baseContext = this.buildStateContextPrompt(state, params.localContext, true);
797
+ const baseContext = this.buildStateContextPrompt(state, true);
798
798
  const types = this.normalizeRequestTypes(params.requestTypes);
799
- const isAuto = types.includes(InteractRequestType.AUTO);
800
799
  const requestedOthers = types.filter((t) => t !== InteractRequestType.AUTO && t !== InteractRequestType.TEXT);
801
800
  // Determine modalities (reusing logic from interact)
802
801
  let modalitiesInstruction = "You are initiating conversation without a preceding user message.\\n";
@@ -826,12 +825,13 @@ You MUST output ONLY a valid JSON object matching exactly this structure:
826
825
  ${this.getImageSchemaParams(requestedOthers.includes(InteractRequestType.IMAGE))},
827
826
  "voiceArgs": null
828
827
  }`;
829
- const transcript = this.buildHistoryTranscript(params.history, state);
828
+ const transcript = params.history && params.history.length > 0 ? this.buildHistoryTranscript(params.history, state) : "";
829
+ const harnessContext = params.localContext ? `[ADDITIONAL SCENE CONTEXT]\n${params.localContext}\n\n` : "";
830
830
  const promptMessages = [
831
831
  { role: "system", content: systemPrompt },
832
832
  {
833
833
  role: "user",
834
- content: `${transcript}\n[TRIGGER PROACTIVE MESSAGE]\nBased on your active event and environment, send a new message to the user.\n\nCRITICAL: Output ONLY valid JSON matching the schema. DO NOT wrap the JSON in \`\`\`json.`
834
+ content: `${harnessContext}${transcript}\n[TRIGGER PROACTIVE MESSAGE]\nBased on your active event and environment, send a new message to the user.\n\nCRITICAL: Output ONLY valid JSON matching the schema. DO NOT wrap the JSON in \`\`\`json.`
835
835
  }
836
836
  ];
837
837
  // 5. Generate with LLM using a confident temperature
@@ -892,7 +892,7 @@ You MUST output ONLY a valid JSON object matching exactly this structure:
892
892
  async generateImage(params) {
893
893
  let imageParams = {};
894
894
  const state = await this.fetchRemoteState();
895
- const prompt = `${this.buildStateContextPrompt(state, params.interactParams?.localContext)}
895
+ const prompt = `${this.buildStateContextPrompt(state)}
896
896
 
897
897
  You are an AI image prompt director. Analyze the scene description according to the character's relationship stage and emotional inertia to determine the best image generation parameters.
898
898
  Output strictly valid JSON ONLY. No markdown, no conversational filler. Return exactly matching this schema:
@@ -927,7 +927,7 @@ Output strictly valid JSON ONLY. No markdown, no conversational filler. Return e
927
927
  async generateVoice(params) {
928
928
  let dynamicArgs = {};
929
929
  const state = await this.fetchRemoteState();
930
- const prompt = `${this.buildStateContextPrompt(state, params.interactParams?.localContext)}
930
+ const prompt = `${this.buildStateContextPrompt(state)}
931
931
 
932
932
  You are a voice acting director. ${this.getVoiceDirectorInstruction(state)}
933
933
  Output strictly valid JSON ONLY. No markdown, no conversational filler. Return exactly matching this schema:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@space3-npm/cybersoul-client",
3
- "version": "1.3.5",
3
+ "version": "1.3.6",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",