@space3-npm/cybersoul-client 1.0.0 → 1.0.2

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # cybersoul-client
1
+ # @space3-npm/cybersoul-client
2
2
 
3
- `cybersoul-client` is the official TypeScript client SDK for interacting with the Cyber-Soul backend service. It acts as the "Brain" orchestrator on the client side, converting your local text inputs into rich, multi-modal outputs (text, voice, and image) driven by an LLM architecture.
3
+ `@space3-npm/cybersoul-client` is the official TypeScript client SDK for interacting with the Cyber-Soul backend service. It acts as the "Brain" orchestrator on the client side, converting your local text inputs into rich, multi-modal outputs (text, voice, and image) driven by an LLM architecture.
4
4
 
5
5
  ## Overview
6
6
 
@@ -19,10 +19,10 @@ Cyber-Soul Service transforms static text-based virtual companions into fully re
19
19
 
20
20
  ## Installation
21
21
 
22
- You can install the SDK locally or via npm (when published):
22
+ You can install the SDK locally or via npm:
23
23
 
24
24
  ```bash
25
- npm install cybersoul-client
25
+ npm install @space3-npm/cybersoul-client
26
26
  ```
27
27
 
28
28
  ## Quick Start
@@ -30,7 +30,7 @@ npm install cybersoul-client
30
30
  Initialize the client with your Character Key (provided by your Cyber-Soul Dashboard) and your local LLM configuration:
31
31
 
32
32
  ```typescript
33
- import { CyberSoulClient } from 'cybersoul-client';
33
+ import { CyberSoulClient } from '@space3-npm/cybersoul-client';
34
34
 
35
35
  const client = new CyberSoulClient({
36
36
  characterKey: 'YOUR_CHARACTER_KEY_HASH', // Ties requests to your specific Cyber-Soul persona
@@ -91,4 +91,17 @@ flowchart TD
91
91
 
92
92
  When plugging this SDK into an existing bot framework like OpenClaw, you will generally bootstrap the system once with your config files, then call `.interact()` on every new message event.
93
93
 
94
- Because `interact` acts as an all-in-one state-machine adapter, it isolates multi-modal state tracking—you simply provide the raw user string and the array of recent history, and the SDK takes care of API generation, prompt construction, and relationship temperature updates implicitly.
94
+ Because `interact` acts as an all-in-one state-machine adapter, it isolates multi-modal state tracking—you simply provide the raw user string and the array of recent history, and the SDK takes care of API generation, prompt construction, and relationship temperature updates implicitly.
95
+
96
+ ## API Reference
97
+
98
+ The SDK perfectly mirrors the underlying Cyber-Soul backend capabilities via typed TypeScript primitives:
99
+
100
+ - `getState()`: Fetches the current dynamic context, relationship stage, next events, and wardrobe metadata.
101
+ - `updateDynamicContext(stateUpdate)`: Manually patches the character's relationship temperature or mood delta.
102
+ - `generateImage(params)`: Synthesizes a new explicit image of the character outside of standard chat flow logic.
103
+ - `generateVoice(params)`: Synthesizes explicit character audio (ElevenLabs/TTS) returning the URL and duration.
104
+ - `giftOutfit(descriptionText)`: Provisions a new explicit outfit descriptor to the character's backend inventory.
105
+ - `bootstrapCharacter(workspaceFiles)`: Automates character profile and prompt setup directly from local markdown configuration files.
106
+ - `generateDailyScript()`: Cron-job helper instructing the AI scheduling system to compute the next block of dynamic events and plans.
107
+ - `interact(params)`: The primary orchestrated multi-modal dialogue endpoint processing standard human <-> agent chat requests.
package/dist/client.d.ts CHANGED
@@ -1,10 +1,48 @@
1
- import { CyberSoulClientConfig, InteractParams, InteractResponse } from "./types";
1
+ import { CyberSoulClientConfig, InteractParams, DispatcherIntent, InteractResponse, CharacterState, ImageGenerationParams, VoiceGenerationParams } from "./types";
2
2
  export declare class CyberSoulClient {
3
3
  private config;
4
4
  private llm;
5
5
  constructor(config: CyberSoulClientConfig);
6
+ /**
7
+ * Internal wrapper for fetch that automatically injects the backend URL and Character Auth token.
8
+ */
9
+ private apiFetch;
10
+ /**
11
+ * Fetches the current dynamic context and daily state.
12
+ */
13
+ getState(): Promise<CharacterState>;
14
+ /**
15
+ * Updates the character's relationship temperature or mood.
16
+ */
17
+ updateDynamicContext(stateUpdate: DispatcherIntent["stateUpdate"]): Promise<void>;
18
+ /**
19
+ * Manually generate an image of the character outside of chat flow.
20
+ */
21
+ generateImage(params: ImageGenerationParams): Promise<{
22
+ imageUrl: string;
23
+ }>;
24
+ /**
25
+ * Manually synthesize voice audio outside of chat flow.
26
+ */
27
+ generateVoice(params: VoiceGenerationParams): Promise<{
28
+ audioUrl: string;
29
+ durationSec?: number;
30
+ }>;
31
+ /**
32
+ * Gift a new outfit to the character's wardrobe inventory.
33
+ */
34
+ giftOutfit(descriptionText: string): Promise<void>;
35
+ /**
36
+ * Bootstrap character profile from OpenClaw workspace files.
37
+ */
38
+ bootstrapCharacter(workspaceFiles: Record<string, string>): Promise<void>;
39
+ /**
40
+ * Instructs the backend to generate the daily script/plan for the character.
41
+ * Can be triggered by local Cron systems like OpenClaw.
42
+ */
43
+ generateDailyScript(): Promise<void>;
6
44
  private fetchRemoteState;
7
- private updateDynamicContext;
45
+ private _updateDynamicContextInternal;
8
46
  private generatePrimitive;
9
47
  interact(params: InteractParams): Promise<InteractResponse>;
10
48
  }
package/dist/client.js CHANGED
@@ -13,17 +13,94 @@ export class CyberSoulClient {
13
13
  throw new Error(`Unsupported LLM provider: ${config.llmConfig.provider}`);
14
14
  }
15
15
  }
16
- async fetchRemoteState() {
17
- const url = `${this.config.backendUrl}/api/v1/cyber-soul/state`;
18
- const res = await fetch(url, {
19
- headers: { Authorization: `Bearer ${this.config.characterKey}` },
16
+ /**
17
+ * Internal wrapper for fetch that automatically injects the backend URL and Character Auth token.
18
+ */
19
+ async apiFetch(endpoint, options = {}) {
20
+ const url = `${this.config.backendUrl}${endpoint}`;
21
+ const headers = {
22
+ Authorization: `Bearer ${this.config.characterKey}`,
23
+ "Content-Type": "application/json",
24
+ ...(options.headers || {}),
25
+ };
26
+ return fetch(url, { ...options, headers });
27
+ }
28
+ /**
29
+ * Fetches the current dynamic context and daily state.
30
+ */
31
+ async getState() {
32
+ return this.fetchRemoteState();
33
+ }
34
+ /**
35
+ * Updates the character's relationship temperature or mood.
36
+ */
37
+ async updateDynamicContext(stateUpdate) {
38
+ if (!stateUpdate)
39
+ return;
40
+ // Map TS schema intent (temperatureDelta) to match Backend payload schema (temperature)
41
+ const payload = { ...stateUpdate };
42
+ if (payload.temperatureDelta !== undefined) {
43
+ payload.temperature = payload.temperatureDelta;
44
+ delete payload.temperatureDelta;
45
+ }
46
+ await this.apiFetch("/api/v1/cyber-soul/characters/dynamic-context", {
47
+ method: "PATCH",
48
+ body: JSON.stringify(payload),
49
+ }).catch((e) => console.error("Failed to update dynamic context", e)); // non-blocking error handler
50
+ }
51
+ /**
52
+ * Manually generate an image of the character outside of chat flow.
53
+ */
54
+ async generateImage(params) {
55
+ return this.generatePrimitive("image", params);
56
+ }
57
+ /**
58
+ * Manually synthesize voice audio outside of chat flow.
59
+ */
60
+ async generateVoice(params) {
61
+ return this.generatePrimitive("voice", params);
62
+ }
63
+ /**
64
+ * Gift a new outfit to the character's wardrobe inventory.
65
+ */
66
+ async giftOutfit(descriptionText) {
67
+ const res = await this.apiFetch("/api/v1/cyber-soul/characters/gift-outfit", {
68
+ method: "POST",
69
+ body: JSON.stringify({ text: descriptionText }),
70
+ });
71
+ if (!res.ok)
72
+ throw new Error("Failed to gift outfit");
73
+ }
74
+ /**
75
+ * Bootstrap character profile from OpenClaw workspace files.
76
+ */
77
+ async bootstrapCharacter(workspaceFiles) {
78
+ const res = await this.apiFetch("/api/v1/cyber-soul/characters/bootstrap", {
79
+ method: "POST",
80
+ body: JSON.stringify({ workspace_files: workspaceFiles }),
20
81
  });
82
+ if (!res.ok)
83
+ throw new Error("Failed to bootstrap character");
84
+ }
85
+ /**
86
+ * Instructs the backend to generate the daily script/plan for the character.
87
+ * Can be triggered by local Cron systems like OpenClaw.
88
+ */
89
+ async generateDailyScript() {
90
+ const res = await this.apiFetch("/api/v1/cyber-soul/daily-script/generate", {
91
+ method: "POST",
92
+ });
93
+ if (!res.ok)
94
+ throw new Error("Failed to generate daily script");
95
+ }
96
+ async fetchRemoteState() {
97
+ const res = await this.apiFetch("/api/v1/cyber-soul/state");
21
98
  if (!res.ok)
22
99
  throw new Error("Failed to fetch character state");
23
100
  const json = await res.json();
24
101
  return json.data;
25
102
  }
26
- async updateDynamicContext(stateUpdate) {
103
+ async _updateDynamicContextInternal(stateUpdate) {
27
104
  if (!stateUpdate)
28
105
  return;
29
106
  // Map TS schema intent (temperatureDelta) to match Backend payload schema (temperature)
@@ -32,24 +109,14 @@ export class CyberSoulClient {
32
109
  payload.temperature = payload.temperatureDelta;
33
110
  delete payload.temperatureDelta;
34
111
  }
35
- const url = `${this.config.backendUrl}/api/v1/cyber-soul/characters/dynamic-context`;
36
- await fetch(url, {
112
+ await this.apiFetch("/api/v1/cyber-soul/characters/dynamic-context", {
37
113
  method: "PATCH",
38
- headers: {
39
- Authorization: `Bearer ${this.config.characterKey}`,
40
- "Content-Type": "application/json",
41
- },
42
114
  body: JSON.stringify(payload),
43
115
  }).catch((e) => console.error("Failed to update dynamic context", e)); // non-blocking error handler
44
116
  }
45
117
  async generatePrimitive(type, payload) {
46
- const url = `${this.config.backendUrl}/api/v1/cyber-soul/${type}/generate`;
47
- const res = await fetch(url, {
118
+ const res = await this.apiFetch(`/api/v1/cyber-soul/${type}/generate`, {
48
119
  method: "POST",
49
- headers: {
50
- Authorization: `Bearer ${this.config.characterKey}`,
51
- "Content-Type": "application/json",
52
- },
53
120
  body: JSON.stringify(payload),
54
121
  });
55
122
  if (!res.ok)
@@ -150,8 +217,8 @@ Note: If "imageParams", "voiceArgs", or "stateUpdate" are not needed, set their
150
217
  }
151
218
  console.log("[CyberSoulClient] Parsed Intent:", parsedIntent);
152
219
  // 4. Update Backend State async
153
- if (parsedIntent.stateUpdate) {
154
- this.updateDynamicContext(parsedIntent.stateUpdate);
220
+ if (parsedIntent && parsedIntent.stateUpdate) {
221
+ this._updateDynamicContextInternal(parsedIntent.stateUpdate);
155
222
  }
156
223
  // Fire text ready callback if provided
157
224
  if (params.onTextReady && parsedIntent.textResponse) {
package/dist/types.d.ts CHANGED
@@ -39,9 +39,48 @@ export interface DispatcherIntent {
39
39
  talkingStyle?: string;
40
40
  };
41
41
  }
42
+ export interface CharacterState {
43
+ current_time: string;
44
+ active_event?: any;
45
+ next_event?: any;
46
+ active_wardrobe?: any;
47
+ active_story_arcs?: string[];
48
+ dynamic_context?: any;
49
+ relationship_stage?: string;
50
+ name?: string;
51
+ age?: number;
52
+ gender?: string;
53
+ occupation?: string;
54
+ personality_traits?: string;
55
+ interaction_boundaries?: string;
56
+ communication_style?: string;
57
+ }
42
58
  export interface BaseLLMProvider {
43
59
  generate(messages: {
44
60
  role: string;
45
61
  content: string;
46
62
  }[], maxTokens?: number, temperature?: number): Promise<string>;
47
63
  }
64
+ export interface ImageGenerationParams {
65
+ mode: 'structured' | 'full-prompt';
66
+ full_prompt?: string;
67
+ expression?: string;
68
+ condition?: string;
69
+ pose?: string;
70
+ view_angle?: string;
71
+ exposure?: string;
72
+ outfit?: string;
73
+ scene?: string;
74
+ ondemandOutfit?: string;
75
+ style?: string;
76
+ triggerWord?: string;
77
+ appearanceBody?: string;
78
+ appearanceFace?: string;
79
+ }
80
+ export interface VoiceGenerationParams {
81
+ text: string;
82
+ dynamicArgs: {
83
+ style_instruction?: string;
84
+ emotion?: string;
85
+ };
86
+ }
package/package.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "@space3-npm/cybersoul-client",
3
- "version": "1.0.0",
4
- "type": "module", "main": "dist/index.js", "module": "dist/index.js",
3
+ "version": "1.0.2",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.js",
5
7
  "types": "dist/index.d.ts",
6
8
  "files": [
7
9
  "dist"