@space3-npm/cybersoul-client 1.0.3 → 1.0.5
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 +1 -0
- package/dist/client.js +22 -10
- package/dist/types.d.ts +10 -3
- package/dist/types.js +7 -1
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
package/dist/client.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { InteractRequestType } from "./types.js";
|
|
1
2
|
import { robustJsonParse } from "./utils/json.utils.js";
|
|
2
3
|
import { MinimaxProvider } from "./providers/minimax.provider.js";
|
|
3
4
|
export class CyberSoulClient {
|
|
@@ -123,13 +124,24 @@ export class CyberSoulClient {
|
|
|
123
124
|
throw new Error(`Failed to generate ${type}`);
|
|
124
125
|
return res.json();
|
|
125
126
|
}
|
|
127
|
+
normalizeRequestTypes(requestTypes) {
|
|
128
|
+
if (!requestTypes || requestTypes.length === 0) {
|
|
129
|
+
return [InteractRequestType.AUTO];
|
|
130
|
+
}
|
|
131
|
+
const validRequestTypes = new Set(Object.values(InteractRequestType));
|
|
132
|
+
const invalidRequestTypes = requestTypes.filter((type) => !validRequestTypes.has(type));
|
|
133
|
+
if (invalidRequestTypes.length > 0) {
|
|
134
|
+
throw new Error(`Invalid requestTypes: ${invalidRequestTypes.join(", ")}. Allowed values: ${Object.values(InteractRequestType).join(", ")}`);
|
|
135
|
+
}
|
|
136
|
+
return requestTypes;
|
|
137
|
+
}
|
|
126
138
|
async interact(params) {
|
|
127
139
|
try {
|
|
128
140
|
// 1. Sync remote context
|
|
129
141
|
const state = await this.fetchRemoteState();
|
|
130
142
|
// 2. Build local Prompt
|
|
131
|
-
const types =
|
|
132
|
-
const isAuto = types.includes(
|
|
143
|
+
const types = this.normalizeRequestTypes(params.requestTypes);
|
|
144
|
+
const isAuto = types.includes(InteractRequestType.AUTO);
|
|
133
145
|
// Combine state info into a clean descriptive context
|
|
134
146
|
const contextParts = [];
|
|
135
147
|
if (state.active_event) {
|
|
@@ -149,7 +161,7 @@ export class CyberSoulClient {
|
|
|
149
161
|
}
|
|
150
162
|
const scenarioContext = contextParts.join("\n");
|
|
151
163
|
const systemPrompt = `You are ${state.name}, acting as a virtual companion.
|
|
152
|
-
Demographics: Age ${state.age || 'unknown'}, Gender ${state.gender || 'unknown'}, Occupation ${state.occupation || 'unknown'}
|
|
164
|
+
Demographics: Age ${state.age || 'unknown'}, Gender ${state.gender || 'unknown'}, Occupation ${state.occupation || 'unknown'}, Hobby ${state.hobby || 'unknown'}
|
|
153
165
|
Current time: ${new Date(state.current_time).toLocaleString("zh-CN", { timeZone: "Asia/Shanghai" })}
|
|
154
166
|
Current context/schedule: ${scenarioContext}
|
|
155
167
|
Relationship stage: ${state.relationship_stage}
|
|
@@ -169,7 +181,7 @@ ${isAuto
|
|
|
169
181
|
- Always include 'textResponse'.
|
|
170
182
|
- If the user explicitly asks to see a photo, look at you, or describing an action that warrants a photo, include 'imageParams'.
|
|
171
183
|
- If the user wants to hear you, or if appropriate for a voice message, include 'voiceArgs'.`
|
|
172
|
-
: `Requested types to fulfill: ${
|
|
184
|
+
: `Requested types to fulfill: ${types.join(", ")}`}
|
|
173
185
|
If the user's message shifts the emotional mood, establishes new nicknames, or warrants a relationship temperature change, you MUST include a 'stateUpdate' block. Temperature goes from 0 (cold/angry) to 100 (obsessively in love).
|
|
174
186
|
|
|
175
187
|
Output JSON Schema:
|
|
@@ -229,7 +241,7 @@ Note: If "imageParams", "voiceArgs", or "stateUpdate" are not needed, set their
|
|
|
229
241
|
let finalImageUrl = undefined;
|
|
230
242
|
let finalAudioUrl = undefined;
|
|
231
243
|
let finalDurationSec = undefined;
|
|
232
|
-
const shouldGenerateImage = types.includes(
|
|
244
|
+
const shouldGenerateImage = types.includes(InteractRequestType.IMAGE) || (isAuto && !!parsedIntent.imageParams);
|
|
233
245
|
if (shouldGenerateImage) {
|
|
234
246
|
mediaTasks.push(this.generatePrimitive("image", {
|
|
235
247
|
...parsedIntent.imageParams,
|
|
@@ -238,12 +250,12 @@ Note: If "imageParams", "voiceArgs", or "stateUpdate" are not needed, set their
|
|
|
238
250
|
finalImageUrl = res.image_url;
|
|
239
251
|
}));
|
|
240
252
|
}
|
|
241
|
-
const shouldGenerateVoice = types.includes(
|
|
253
|
+
const shouldGenerateVoice = types.includes(InteractRequestType.VOICE) || (isAuto && !!parsedIntent.voiceArgs);
|
|
242
254
|
if (shouldGenerateVoice) {
|
|
243
|
-
const dynamicArgs = {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}
|
|
255
|
+
const dynamicArgs = {
|
|
256
|
+
...(parsedIntent.voiceArgs || {}),
|
|
257
|
+
...(params.voiceOverrides || {})
|
|
258
|
+
};
|
|
247
259
|
mediaTasks.push(this.generatePrimitive("voice", {
|
|
248
260
|
text: parsedIntent.textResponse,
|
|
249
261
|
dynamicArgs,
|
package/dist/types.d.ts
CHANGED
|
@@ -8,16 +8,22 @@ export interface CyberSoulClientConfig {
|
|
|
8
8
|
backendUrl: string;
|
|
9
9
|
llmConfig: LLMConfig;
|
|
10
10
|
}
|
|
11
|
+
export declare enum InteractRequestType {
|
|
12
|
+
AUTO = "auto",
|
|
13
|
+
TEXT = "text",
|
|
14
|
+
IMAGE = "image",
|
|
15
|
+
VOICE = "voice"
|
|
16
|
+
}
|
|
11
17
|
export interface InteractParams {
|
|
12
18
|
userMessage: string;
|
|
13
19
|
localContext?: string;
|
|
14
|
-
requestTypes?:
|
|
20
|
+
requestTypes?: InteractRequestType[];
|
|
15
21
|
history?: {
|
|
16
22
|
role: string;
|
|
17
23
|
content: string;
|
|
18
24
|
}[];
|
|
19
|
-
imageOverrides?:
|
|
20
|
-
|
|
25
|
+
imageOverrides?: Partial<ImageGenerationParams>;
|
|
26
|
+
voiceOverrides?: Partial<VoiceGenerationParams['dynamicArgs']>;
|
|
21
27
|
onTextReady?: (textResponse: string) => void;
|
|
22
28
|
}
|
|
23
29
|
export interface InteractResponse {
|
|
@@ -51,6 +57,7 @@ export interface CharacterState {
|
|
|
51
57
|
age?: number;
|
|
52
58
|
gender?: string;
|
|
53
59
|
occupation?: string;
|
|
60
|
+
hobby?: string;
|
|
54
61
|
personality_traits?: string;
|
|
55
62
|
interaction_boundaries?: string;
|
|
56
63
|
communication_style?: string;
|
package/dist/types.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
export
|
|
1
|
+
export var InteractRequestType;
|
|
2
|
+
(function (InteractRequestType) {
|
|
3
|
+
InteractRequestType["AUTO"] = "auto";
|
|
4
|
+
InteractRequestType["TEXT"] = "text";
|
|
5
|
+
InteractRequestType["IMAGE"] = "image";
|
|
6
|
+
InteractRequestType["VOICE"] = "voice";
|
|
7
|
+
})(InteractRequestType || (InteractRequestType = {}));
|