@storvia/sdk 0.2.2 → 0.3.1

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 CHANGED
@@ -20,7 +20,7 @@ type StorviaErrorCode = 'UNAUTHORIZED' | 'INSUFFICIENT_BALANCE' | 'RATE_LIMITED'
20
20
  interface ChatSendOptions {
21
21
  message: string;
22
22
  topic?: string;
23
- context?: string;
23
+ scene_key?: string;
24
24
  stream?: boolean;
25
25
  onChunk?: (text: string) => void;
26
26
  onDone?: (id: string) => void;
@@ -32,7 +32,7 @@ interface ChatSaveOptions {
32
32
  }
33
33
  interface ChatGenerateOptions {
34
34
  topic?: string;
35
- context?: string;
35
+ scene_key?: string;
36
36
  stream?: boolean;
37
37
  save?: boolean;
38
38
  onChunk?: (text: string) => void;
@@ -40,7 +40,7 @@ interface ChatGenerateOptions {
40
40
  }
41
41
  interface ChatRetryOptions {
42
42
  topic?: string;
43
- context?: string;
43
+ scene_key?: string;
44
44
  stream?: boolean;
45
45
  onChunk?: (text: string) => void;
46
46
  onDone?: (id: string) => void;
@@ -162,7 +162,7 @@ declare class ChatModule {
162
162
  id: string;
163
163
  }>;
164
164
  /**
165
- * 基于 topic 历史 + context 请求 AI 生成回复(无需当前轮用户输入)
165
+ * 基于 topic 历史 + scene_key 请求 AI 生成回复(无需当前轮用户输入)
166
166
  * 适用于群聊 NPC 回复、NPC 自动发言、弹幕生成等
167
167
  */
168
168
  generate(options: ChatGenerateOptions): Promise<ChatResponse | void>;
@@ -171,7 +171,10 @@ declare class ChatModule {
171
171
  * 适用于 AI 回复出错或不满意时重新生成
172
172
  */
173
173
  retry(options?: ChatRetryOptions): Promise<ChatResponse | void>;
174
- /** 预览模式:发到 /preview 端点 */
174
+ /** 预览模式:发到 /preview 端点
175
+ * - 创作台预览:父页面已注入 previewConfig,请求体塞 prompt_config,服务端不查库
176
+ * - 本地预览 / dev:无 previewConfig,请求体塞 game_id,服务端按 hash_id 查 prompts
177
+ */
175
178
  private sendPreview;
176
179
  }
177
180
 
@@ -179,8 +182,11 @@ declare class CharacterStateModule {
179
182
  private http;
180
183
  private getConversationId;
181
184
  private isPreview;
185
+ /** characterName → state(与正式模式 GET /characters/:name/state 同结构) */
182
186
  private mem;
183
- constructor(http: HttpClient, getConversationId: () => string, isPreview?: boolean);
187
+ constructor(http: HttpClient, getConversationId: () => string, isPreview?: boolean, initialStates?: Record<string, Record<string, FieldValue>>);
188
+ /** 预览模式下重新灌入初始数据(previewConfig 变更时调用) */
189
+ setInitial(initialStates: Record<string, Record<string, FieldValue>> | undefined): void;
184
190
  get(characterName: string): Promise<Record<string, FieldValue>>;
185
191
  update(characterName: string, values: Record<string, string | number | boolean>): Promise<void>;
186
192
  }
@@ -190,7 +196,9 @@ declare class CharactersModule {
190
196
  private isPreview;
191
197
  state: CharacterStateModule;
192
198
  private mem;
193
- constructor(http: HttpClient, getConversationId: () => string, isPreview?: boolean);
199
+ constructor(http: HttpClient, getConversationId: () => string, isPreview?: boolean, initialCharacters?: CharacterPersona[], initialStates?: Record<string, Record<string, FieldValue>>);
200
+ /** 预览模式下重新灌入初始数据(previewConfig 变更时调用) */
201
+ setInitial(initialCharacters: CharacterPersona[] | undefined, initialStates: Record<string, Record<string, FieldValue>> | undefined): void;
194
202
  list(): Promise<CharacterPersona[]>;
195
203
  get(name: string): Promise<CharacterPersona>;
196
204
  add(character: CharacterAddOptions): Promise<void>;
@@ -212,7 +220,9 @@ declare class RelationshipsModule {
212
220
  private getConversationId;
213
221
  private isPreview;
214
222
  private mem;
215
- constructor(http: HttpClient, getConversationId: () => string, isPreview?: boolean);
223
+ constructor(http: HttpClient, getConversationId: () => string, isPreview?: boolean, initialRelationships?: Relationship[]);
224
+ /** 预览模式下重新灌入初始数据(previewConfig 变更时调用) */
225
+ setInitial(initialRelationships: Relationship[] | undefined): void;
216
226
  list(): Promise<Relationship[]>;
217
227
  get(from: string, to: string): Promise<Relationship>;
218
228
  add(relationship: Relationship): Promise<void>;
@@ -230,7 +240,9 @@ declare class InventoryModule {
230
240
  private getConversationId;
231
241
  private isPreview;
232
242
  private mem;
233
- constructor(http: HttpClient, getConversationId: () => string, isPreview?: boolean);
243
+ constructor(http: HttpClient, getConversationId: () => string, isPreview?: boolean, initialInventory?: InventoryState);
244
+ /** 预览模式下重新灌入初始数据(previewConfig 变更时调用) */
245
+ setInitial(initialInventory: InventoryState | undefined): void;
234
246
  /** 返回整个物品栏(分组 → 物品名 → 数据) */
235
247
  list(): Promise<InventoryState>;
236
248
  /** 返回指定分组下的物品(物品名 → 数据) */
@@ -254,7 +266,9 @@ declare class WorldModule {
254
266
  private getConversationId;
255
267
  private isPreview;
256
268
  private mem;
257
- constructor(http: HttpClient, getConversationId: () => string, isPreview?: boolean);
269
+ constructor(http: HttpClient, getConversationId: () => string, isPreview?: boolean, initialWorld?: Record<string, unknown>);
270
+ /** 预览模式下重新灌入初始数据(previewConfig 变更时调用) */
271
+ setInitial(initialWorld: Record<string, unknown> | undefined): void;
258
272
  get(): Promise<Record<string, unknown>>;
259
273
  update(data: Record<string, unknown>): Promise<void>;
260
274
  }
@@ -264,7 +278,9 @@ declare class PlayerStateModule {
264
278
  private getConversationId;
265
279
  private isPreview;
266
280
  private mem;
267
- constructor(http: HttpClient, getConversationId: () => string, isPreview?: boolean);
281
+ constructor(http: HttpClient, getConversationId: () => string, isPreview?: boolean, initialState?: Record<string, Record<string, FieldValue>>);
282
+ /** 预览模式下重新灌入初始数据(previewConfig 变更时调用) */
283
+ setInitial(initialState: Record<string, Record<string, FieldValue>> | undefined): void;
268
284
  get(): Promise<Record<string, Record<string, FieldValue>>>;
269
285
  get(group: string): Promise<Record<string, FieldValue>>;
270
286
  update(group: string, values: Record<string, string | number | boolean>): Promise<void>;
@@ -275,7 +291,9 @@ declare class PlayerModule {
275
291
  private isPreview;
276
292
  state: PlayerStateModule;
277
293
  private memPersona;
278
- constructor(http: HttpClient, getConversationId: () => string, isPreview?: boolean);
294
+ constructor(http: HttpClient, getConversationId: () => string, isPreview?: boolean, initialPersona?: PlayerPersona, initialState?: Record<string, Record<string, FieldValue>>);
295
+ /** 预览模式下重新灌入初始数据(previewConfig 变更时调用) */
296
+ setInitial(initialPersona: PlayerPersona | undefined, initialState: Record<string, Record<string, FieldValue>> | undefined): void;
279
297
  get(): Promise<PlayerPersona>;
280
298
  update(data: Partial<PlayerPersona>): Promise<void>;
281
299
  }
@@ -285,7 +303,9 @@ declare class CustomModule {
285
303
  private getConversationId;
286
304
  private isPreview;
287
305
  private mem;
288
- constructor(http: HttpClient, getConversationId: () => string, isPreview?: boolean);
306
+ constructor(http: HttpClient, getConversationId: () => string, isPreview?: boolean, initialCustom?: Record<string, unknown>);
307
+ /** 预览模式下重新灌入初始数据(previewConfig 变更时调用) */
308
+ setInitial(initialCustom: Record<string, unknown> | undefined): void;
289
309
  get(): Promise<Record<string, unknown>>;
290
310
  get(key: string): Promise<unknown>;
291
311
  set(data: Record<string, unknown>): Promise<void>;
@@ -319,6 +339,15 @@ declare class StorviaSDK {
319
339
  init(): Promise<void>;
320
340
  /** 监听父页面 postMessage(预览模式) */
321
341
  private listenForPreviewMessages;
342
+ /**
343
+ * 调用 POST /preview/initial-snapshot 拉取与正式发布等价的初始数据
344
+ * - 预览模式:传 game_config + game_state_override(来自 previewConfig)
345
+ * - dev 模式:HttpClient 自动带 x-api-key,后端按 game_id 反查
346
+ * 失败时返回 null(不阻塞 init,list/get 仍能用空 mem 工作)
347
+ */
348
+ private fetchPreviewSnapshot;
349
+ /** 重新拉 snapshot 并把结果灌进每个 module 的 mem(用于 update-config 后同步) */
350
+ private refreshPreviewSnapshot;
322
351
  /** 保存设置到后端 */
323
352
  private saveSettings;
324
353
  /** 同步最新游戏设定到当前存档 */