@storvia/sdk 0.10.7 → 0.10.9

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
@@ -57,12 +57,23 @@ interface WorldbookPatch {
57
57
  }
58
58
  interface AssetItem {
59
59
  id: number;
60
+ /** 素材 UUID,原数字 id 与图片 url 继续可用。 */
61
+ assetId: string;
60
62
  name: string;
63
+ nameI18n?: Record<string, string>;
61
64
  url: string;
62
65
  assetType: 'avatar' | 'icon';
63
66
  category: string;
67
+ /** 分类展示译名;分类筛选仍使用 category 原文。 */
68
+ categoryI18n?: Record<string, string> | null;
69
+ tags: AssetTag[];
64
70
  }
65
- type StorviaErrorCode = 'UNAUTHORIZED' | 'INSUFFICIENT_CREDITS' | 'VIOLATION_WORD_DETECTED' | 'CONTENT_FILTERED' | 'MODEL_REFUSAL' | 'STREAM_INTERRUPTED' | 'RATE_LIMITED' | 'GENERATING_IN_PROGRESS' | 'CONCURRENT_GENERATION_LIMIT' | 'INVENTORY_LIMIT' | 'CUSTOM_FIELDS_LIMIT' | 'MODEL_NOT_FOUND' | 'GAME_NOT_FOUND' | 'INVALID_REQUEST' | 'INVALID_EXTRACT_RULE' | 'INTERNAL_ERROR' | 'NOT_INITIALIZED' | 'NOT_SUPPORTED_IN_PREVIEW' | 'NETWORK_ERROR' | 'REQUEST_TIMEOUT' | 'MODEL_LOADING_TIMEOUT' | 'DAISY_CARD_REQUIRED' | 'MESSAGE_NOT_FOUND' | 'MESSAGE_TOO_OLD' | 'NO_MESSAGES_TO_DELETE' | 'GENERATION_TIMEOUT' | 'GENERATION_LOST' | 'REPETITION_LOOP' | 'SAVE_FAILED' | 'FINALIZE_FAILED' | 'CONVERSATION_NOT_FOUND' | 'EMPTY_MESSAGE' | 'CONTINUE_MODEL_NOT_AVAILABLE' | 'CONTINUE_PROMPT_MISSING' | 'GENERATION_ABORTED';
71
+ interface AssetTag {
72
+ id: string;
73
+ label: string;
74
+ labelI18n?: Record<string, string> | null;
75
+ }
76
+ type StorviaErrorCode = 'UNAUTHORIZED' | 'INSUFFICIENT_CREDITS' | 'VIOLATION_WORD_DETECTED' | 'CONTENT_FILTERED' | 'MODEL_REFUSAL' | 'STREAM_INTERRUPTED' | 'RATE_LIMITED' | 'GENERATING_IN_PROGRESS' | 'CONCURRENT_GENERATION_LIMIT' | 'INVENTORY_LIMIT' | 'CUSTOM_FIELDS_LIMIT' | 'MODEL_NOT_FOUND' | 'GAME_NOT_FOUND' | 'INVALID_REQUEST' | 'INVALID_EXTRACT_RULE' | 'INTERNAL_ERROR' | 'ASR_BAD_AUDIO' | 'ASR_UPSTREAM_FAILED' | 'ASR_MODEL_UNAVAILABLE' | 'TTS_UNKNOWN_VOICE' | 'TTS_EMPTY_TEXT' | 'TTS_UPSTREAM_FAILED' | 'NOT_INITIALIZED' | 'NOT_SUPPORTED_IN_PREVIEW' | 'NETWORK_ERROR' | 'REQUEST_TIMEOUT' | 'MODEL_LOADING_TIMEOUT' | 'DAISY_CARD_REQUIRED' | 'MESSAGE_NOT_FOUND' | 'MESSAGE_TOO_OLD' | 'NO_MESSAGES_TO_DELETE' | 'GENERATION_TIMEOUT' | 'GENERATION_LOST' | 'REPETITION_LOOP' | 'SAVE_FAILED' | 'FINALIZE_FAILED' | 'CONVERSATION_NOT_FOUND' | 'EMPTY_MESSAGE' | 'CONTINUE_MODEL_NOT_AVAILABLE' | 'CONTINUE_PROMPT_MISSING' | 'GENERATION_ABORTED';
66
77
  /** AI 本轮的属性变更(仅包含发生改变的字段) */
67
78
  interface StateChanges {
68
79
  /** 世界状态变更(扁平 KV) */
@@ -420,12 +431,37 @@ declare function isRichFieldValue(v: unknown): v is RichFieldValue;
420
431
  /** 从 FieldValue 中提取原始值 */
421
432
  declare function extractFieldValue(v: FieldValue): string | number | boolean;
422
433
  type Gender = 'male' | 'female' | 'other';
434
+ interface TtsSpeakOptions {
435
+ text: string;
436
+ character: string;
437
+ }
438
+ interface TtsAudio {
439
+ audio: Blob;
440
+ cached: boolean;
441
+ }
442
+ type AsrAudioFormat = 'wav' | 'mp3' | 'm4a' | 'webm' | 'ogg' | 'opus' | 'flac' | 'aac';
443
+ interface AsrTranscribeOptions {
444
+ /** 文件或完整录音 Blob,最多 10MB;支持不超过 5 分钟的音频。 */
445
+ audio: Blob;
446
+ /** MIME 为空时显式指定文件格式。 */
447
+ format?: AsrAudioFormat;
448
+ /** 帮助识别专有名词的上下文,最多 400 字符。 */
449
+ context?: string;
450
+ /** 最多四个语言代码;留空自动识别。 */
451
+ languageHints?: string[];
452
+ /** 最多五十个专有名词,每项最多 64 字符。 */
453
+ hotwords?: string[];
454
+ }
455
+ interface AsrTranscription {
456
+ text: string;
457
+ }
423
458
  interface CharacterPersona {
424
459
  name: string;
425
460
  avatar?: string;
426
461
  description?: string;
427
462
  introduction?: string;
428
463
  visibleAtStart?: boolean;
464
+ hasVoice?: boolean;
429
465
  userDescription?: string;
430
466
  gender?: Gender;
431
467
  isPreset?: boolean;
@@ -436,6 +472,7 @@ interface CharacterDetail {
436
472
  description?: string;
437
473
  introduction?: string;
438
474
  visibleAtStart?: boolean;
475
+ hasVoice?: boolean;
439
476
  userDescription?: string;
440
477
  gender?: Gender;
441
478
  isPreset?: boolean;
@@ -573,6 +610,10 @@ declare class HttpClient {
573
610
  private devApiKey;
574
611
  constructor(baseUrl: string, token: string, debug?: boolean, devApiKey?: string);
575
612
  setToken(token: string): void;
613
+ ttsClient(): HttpClient;
614
+ asrClient(): HttpClient;
615
+ postForm<T>(path: string, form: FormData, timeoutMs?: number): Promise<T>;
616
+ postAudio(path: string, body: unknown): Promise<Blob>;
576
617
  setDebug(enabled: boolean): void;
577
618
  private static readonly REQUEST_TIMEOUT;
578
619
  private static readonly INITIAL_TIMEOUT;
@@ -799,6 +840,8 @@ declare class CharactersModule {
799
840
  state: CharacterStateModule;
800
841
  private mem;
801
842
  constructor(http: HttpClient, getConversationId: () => string, isPreview?: boolean, initialCharacters?: CharacterPersona[], initialStates?: Record<string, CharacterStateAttributes>);
843
+ /** 预览模式下当前角色名(关系模块判断别名是否被同名角色占用) */
844
+ previewNames(): string[];
802
845
  /** 预览模式下重新灌入初始数据(previewConfig 变更时调用) */
803
846
  setInitial(initialCharacters: CharacterPersona[] | undefined, initialStates: Record<string, CharacterStateAttributes> | undefined): void;
804
847
  list(): Promise<CharacterPersona[]>;
@@ -831,10 +874,13 @@ declare class RelationshipsModule {
831
874
  private http;
832
875
  private getConversationId;
833
876
  private isPreview;
877
+ private getCharacterNames;
834
878
  private mem;
835
- constructor(http: HttpClient, getConversationId: () => string, isPreview?: boolean, initialRelationships?: Relationship[]);
879
+ constructor(http: HttpClient, getConversationId: () => string, isPreview?: boolean, initialRelationships?: Relationship[], getCharacterNames?: () => string[]);
836
880
  /** 预览模式下重新灌入初始数据(previewConfig 变更时调用) */
837
881
  setInitial(initialRelationships: Relationship[] | undefined): void;
882
+ /** 玩家可传 "player" / "user" 等别名;线上由服务端归一,预览在内存里按同一规则归一 */
883
+ private entity;
838
884
  list(): Promise<Relationship[]>;
839
885
  get(from: string, to: string): Promise<Relationship>;
840
886
  add(relationship: Relationship): Promise<void>;
@@ -1321,10 +1367,29 @@ declare class HostModule {
1321
1367
  refreshMessages(): boolean;
1322
1368
  }
1323
1369
 
1370
+ /** 语音按需生成;studio/dev 预览也使用真实合成,按实际用量收费。 */
1371
+ declare class TtsModule {
1372
+ private getHttp;
1373
+ private getConversationId;
1374
+ private getGameId;
1375
+ private getVoice;
1376
+ private isPreview;
1377
+ private pending;
1378
+ constructor(getHttp: () => HttpClient, getConversationId: () => string, getGameId: () => string, getVoice: (name: string) => Promise<string | undefined>, isPreview?: boolean);
1379
+ speak(options: TtsSpeakOptions): Promise<TtsAudio>;
1380
+ }
1381
+
1382
+ /** 上传录音识别为文本。与 TTS 一致,studio/dev 预览也使用真实识别并按用量收费。 */
1383
+ declare class AsrModule {
1384
+ private getHttp;
1385
+ constructor(getHttp: () => HttpClient);
1386
+ transcribe(options: AsrTranscribeOptions): Promise<AsrTranscription>;
1387
+ }
1388
+
1324
1389
  interface DevConfig {
1325
1390
  apiKey: string;
1326
1391
  gameId: string;
1327
- /** 本地预览/dev:指定初始模型的展示名(display name)。不传则用第一个可用模型。 */
1392
+ /** 本地预览/dev:指定初始模型的展示名,任一语言都行(如 "DeepSeek V4 Flash · Direct")。不传或匹配不到则用第一个可用模型。 */
1328
1393
  model?: string;
1329
1394
  /** 本地预览/dev:指定生效的预设 id。不传则由服务端回退到该模型的第一个预设。 */
1330
1395
  preset?: string;
@@ -1342,6 +1407,7 @@ declare class StorviaSDK {
1342
1407
  private initialized;
1343
1408
  private isPreview;
1344
1409
  private previewConfig;
1410
+ private previewVoices;
1345
1411
  private bus;
1346
1412
  chat: ChatModule;
1347
1413
  characters: CharactersModule;
@@ -1354,6 +1420,8 @@ declare class StorviaSDK {
1354
1420
  state: StateModule;
1355
1421
  memory: MemoryModule;
1356
1422
  host: HostModule;
1423
+ tts: TtsModule;
1424
+ asr: AsrModule;
1357
1425
  init(): Promise<void>;
1358
1426
  /**
1359
1427
  * 监听宿主运行时下发的模型切换(envelope 'set-model')。
@@ -1369,11 +1437,12 @@ declare class StorviaSDK {
1369
1437
  private listenForTokenUpdate;
1370
1438
  /** 监听父页面发来的预览模式动态更新(envelope 'config-update' / 'set-model') */
1371
1439
  private listenForPreviewMessages;
1440
+ private getCharacterVoice;
1372
1441
  /**
1373
1442
  * 调用 POST /preview/initial-snapshot 拉取与正式发布等价的初始数据
1374
1443
  * - 预览模式:传 game_config + game_state_override(来自 previewConfig)
1375
1444
  * - dev 模式:HttpClient 自动带 x-api-key,后端按 game_id 反查
1376
- * 失败时返回 null(不阻塞 init,list/get 仍能用空 mem 工作)
1445
+ * 请求失败保留实际错误,初始化不会使用空数据冒充成功。
1377
1446
  */
1378
1447
  private fetchPreviewSnapshot;
1379
1448
  /** 重新拉 snapshot 并把结果灌进每个 module 的 mem(用于 update-config 后同步) */
@@ -1415,4 +1484,10 @@ interface ToastAction {
1415
1484
  */
1416
1485
  declare function showToast(message: string, type?: ToastType, duration?: number, action?: ToastAction): void;
1417
1486
 
1418
- export { type AISummary, type AckPayload, type AssetItem, type CharacterAddOptions, type CharacterDetail, type CharacterPersona, type CharacterUpdateOptions, type ChatAbortInfo, type ChatAbortedCallback, type ChatCancelOptions, type ChatCancelResult, type ChatContinueOptions, type ChatDoneCallback, type ChatDoneInfo, type ChatGenerateOptions, type ChatMessage, type ChatMessageCursor, type ChatMessagesOptions, type ChatMessagesResponse, type ChatReconnectingCallback, type ChatResponse, type ChatResumeOptions, type ChatRetryOptions, type ChatSaveOptions, type ChatSendOptions, type ChatStateCallback, type ConfigUpdatePayload, type CurrentState, type DormantState, type DownstreamMsg, type ExtendWorldRuleEntry, type FieldValue, type Gender, HOST_NOTIFY_MAX_LENGTH, HOST_NOTIFY_MIN_INTERVAL_MS, HOST_PANEL_SCOPES, HOST_REFRESH_MIN_INTERVAL_MS, type HostMessagesChangedPayload, HostModule, type HostNotifyPayload, type HostPanelScope, type HostStateChangedPayload, type InitPayload, type InventoryAddOptions, type InventoryMoveOptions, type InventoryRemoveGroupOptions, type InventoryRemoveOptions, type InventoryState, type InventoryUpdateOptions, type ItemData, MAIN_CHAT_TOPIC, type OrientationPayload, PROTOCOL_VERSION, type PlayerPersona, type PresetWorldbookView, type PreviewConfig, type PreviewInitPayload, type ProtocolEnvelope, type ReadyPayload, type Relationship, type RichFieldValue, type SdkErrorPayload, type SetModelPayload, type State, type StateChanges, StorviaBus, type StorviaBusOptions, StorviaError, type StorviaErrorCode, StorviaSDK, type TokenUpdatePayload, type UpstreamMsg, type Worldbook, type WorldbookPatch, createStorviaSDK, envelope, extractFieldValue, isProtocolEnvelope, isRichFieldValue, setToastEnabled, showToast };
1487
+ /**
1488
+ * 关系 from / to 里代表玩家本人的固定 id。与服务端 `_shared/game-state/constants.ts` 的 PLAYER_ENTITY_ID 同值。
1489
+ * 写代码时用这个常量比较(`r.from === PLAYER_ID`),不要手写字面量。
1490
+ */
1491
+ declare const PLAYER_ID = "\u73A9\u5BB6";
1492
+
1493
+ export { type AISummary, type AckPayload, type AsrAudioFormat, type AsrTranscribeOptions, type AsrTranscription, type AssetItem, type AssetTag, type CharacterAddOptions, type CharacterDetail, type CharacterPersona, type CharacterUpdateOptions, type ChatAbortInfo, type ChatAbortedCallback, type ChatCancelOptions, type ChatCancelResult, type ChatContinueOptions, type ChatDoneCallback, type ChatDoneInfo, type ChatGenerateOptions, type ChatMessage, type ChatMessageCursor, type ChatMessagesOptions, type ChatMessagesResponse, type ChatReconnectingCallback, type ChatResponse, type ChatResumeOptions, type ChatRetryOptions, type ChatSaveOptions, type ChatSendOptions, type ChatStateCallback, type ConfigUpdatePayload, type CurrentState, type DormantState, type DownstreamMsg, type ExtendWorldRuleEntry, type FieldValue, type Gender, HOST_NOTIFY_MAX_LENGTH, HOST_NOTIFY_MIN_INTERVAL_MS, HOST_PANEL_SCOPES, HOST_REFRESH_MIN_INTERVAL_MS, type HostMessagesChangedPayload, HostModule, type HostNotifyPayload, type HostPanelScope, type HostStateChangedPayload, type InitPayload, type InventoryAddOptions, type InventoryMoveOptions, type InventoryRemoveGroupOptions, type InventoryRemoveOptions, type InventoryState, type InventoryUpdateOptions, type ItemData, MAIN_CHAT_TOPIC, type OrientationPayload, PLAYER_ID, PROTOCOL_VERSION, type PlayerPersona, type PresetWorldbookView, type PreviewConfig, type PreviewInitPayload, type ProtocolEnvelope, type ReadyPayload, type Relationship, type RichFieldValue, type SdkErrorPayload, type SetModelPayload, type State, type StateChanges, StorviaBus, type StorviaBusOptions, StorviaError, type StorviaErrorCode, StorviaSDK, type TokenUpdatePayload, type TtsAudio, type TtsSpeakOptions, type UpstreamMsg, type Worldbook, type WorldbookPatch, createStorviaSDK, envelope, extractFieldValue, isProtocolEnvelope, isRichFieldValue, setToastEnabled, showToast };