@storvia/sdk 0.6.0 → 0.7.0
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.cjs.js +8 -805
- package/dist/index.d.mts +32 -17
- package/dist/index.esm.js +8 -805
- package/dist/index.umd.js +8 -805
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -31,7 +31,7 @@ declare class HttpClient {
|
|
|
31
31
|
delete<T>(path: string): Promise<T>;
|
|
32
32
|
stream(path: string, body: unknown, onChunk: (text: string) => void, onDone: (id: string) => void, meta?: {
|
|
33
33
|
modelName?: string;
|
|
34
|
-
}, onState?: (delta: unknown, full: unknown) => void, onThinking?: (status: 'start' | 'end') => void): Promise<void>;
|
|
34
|
+
}, onState?: (delta: unknown, full: unknown) => void, onThinking?: (status: 'start' | 'end') => void, onCreatedCharacters?: (names: string[]) => void): Promise<void>;
|
|
35
35
|
/**
|
|
36
36
|
* 读取完整响应文本,解析为 JSON 并返回 `{ raw, data }`:
|
|
37
37
|
* - `raw` 是后端返回的整体(用于 debug 完整打印,含 success/code/message 等包装字段)
|
|
@@ -97,6 +97,13 @@ interface StateChanges {
|
|
|
97
97
|
type ChatStateCallback = (delta: StateChanges, full: State | null) => void;
|
|
98
98
|
/** 模型 reasoning 状态回调:'start' 表示开始思考,'end' 表示思考结束、开始输出正文 */
|
|
99
99
|
type ChatThinkingCallback = (status: 'start' | 'end') => void;
|
|
100
|
+
/**
|
|
101
|
+
* 新角色出场回调:本轮 AI 创造了之前从未出现过的「真·新角色」时触发。
|
|
102
|
+
* @param names 新角色名字数组(apply 后 current 里、apply 前 current∪dormant 都没有的);
|
|
103
|
+
* 不含休眠恢复 / 被限额挤进 dormant 的角色。作者可据此弹「新角色出现」提示卡片。
|
|
104
|
+
* 非流式调用通过 ChatResponse.createdNames 获取,无需此回调。
|
|
105
|
+
*/
|
|
106
|
+
type ChatCreatedCharactersCallback = (names: string[]) => void;
|
|
100
107
|
/**
|
|
101
108
|
* 流式 + 入库内容过滤规则。提供后,服务端只保留 AI 回复中
|
|
102
109
|
* `start..end` 之间的内容(多段会自动拼接),其余被丢弃。
|
|
@@ -126,6 +133,8 @@ interface ChatSendOptions {
|
|
|
126
133
|
onState?: ChatStateCallback;
|
|
127
134
|
/** 模型 reasoning 状态变更('start' = 开始思考,'end' = 开始输出正文);仅支持思考型模型 */
|
|
128
135
|
onThinking?: ChatThinkingCallback;
|
|
136
|
+
/** 本轮出现「真·新角色」时触发;非流式调用通过 ChatResponse.createdNames 获取,无需此回调 */
|
|
137
|
+
onCreatedCharacters?: ChatCreatedCharactersCallback;
|
|
129
138
|
}
|
|
130
139
|
interface ChatSaveOptions {
|
|
131
140
|
role: 'user' | 'assistant';
|
|
@@ -144,6 +153,8 @@ interface ChatGenerateOptions {
|
|
|
144
153
|
onState?: ChatStateCallback;
|
|
145
154
|
/** 模型 reasoning 状态变更('start' = 开始思考,'end' = 开始输出正文);仅支持思考型模型 */
|
|
146
155
|
onThinking?: ChatThinkingCallback;
|
|
156
|
+
/** 本轮出现「真·新角色」时触发;非流式调用通过 ChatResponse.createdNames 获取,无需此回调 */
|
|
157
|
+
onCreatedCharacters?: ChatCreatedCharactersCallback;
|
|
147
158
|
}
|
|
148
159
|
interface ChatRetryOptions {
|
|
149
160
|
topic?: string;
|
|
@@ -157,6 +168,8 @@ interface ChatRetryOptions {
|
|
|
157
168
|
onState?: ChatStateCallback;
|
|
158
169
|
/** 模型 reasoning 状态变更('start' = 开始思考,'end' = 开始输出正文);仅支持思考型模型 */
|
|
159
170
|
onThinking?: ChatThinkingCallback;
|
|
171
|
+
/** 本轮出现「真·新角色」时触发;非流式调用通过 ChatResponse.createdNames 获取,无需此回调 */
|
|
172
|
+
onCreatedCharacters?: ChatCreatedCharactersCallback;
|
|
160
173
|
}
|
|
161
174
|
interface ChatResponse {
|
|
162
175
|
id: string;
|
|
@@ -165,6 +178,8 @@ interface ChatResponse {
|
|
|
165
178
|
delta?: StateChanges;
|
|
166
179
|
/** 合并后的完整状态快照,仅在有变更时出现;结构同 storvia.state.get() */
|
|
167
180
|
full?: State;
|
|
181
|
+
/** 本轮出现的「真·新角色」名字数组,仅在有新角色时出现 */
|
|
182
|
+
createdNames?: string[];
|
|
168
183
|
}
|
|
169
184
|
interface ChatMessageCursor {
|
|
170
185
|
uuid: string;
|
|
@@ -370,13 +385,6 @@ interface State {
|
|
|
370
385
|
dormant: DormantState;
|
|
371
386
|
}
|
|
372
387
|
|
|
373
|
-
interface GameSettings {
|
|
374
|
-
temperature: number;
|
|
375
|
-
replyLength: string;
|
|
376
|
-
replyLanguage: string;
|
|
377
|
-
playerNote: string;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
388
|
declare class ChatModule {
|
|
381
389
|
private http;
|
|
382
390
|
private getGameId;
|
|
@@ -384,9 +392,8 @@ declare class ChatModule {
|
|
|
384
392
|
private getModelId;
|
|
385
393
|
private isPreview;
|
|
386
394
|
private previewConfig?;
|
|
387
|
-
private getSettings?;
|
|
388
395
|
private getModelName?;
|
|
389
|
-
constructor(http: HttpClient, getGameId: () => string, getConversationId: () => string, getModelId: () => string, isPreview?: boolean, previewConfig?: Record<string, unknown>,
|
|
396
|
+
constructor(http: HttpClient, getGameId: () => string, getConversationId: () => string, getModelId: () => string, isPreview?: boolean, previewConfig?: Record<string, unknown>, getModelName?: () => string | undefined);
|
|
390
397
|
/** 构造 http 层的元信息(用于 debug 日志标题显示) */
|
|
391
398
|
private reqMeta;
|
|
392
399
|
/** 更新预览配置(由父页面 postMessage 触发) */
|
|
@@ -676,10 +683,11 @@ declare class MemoryModule {
|
|
|
676
683
|
interface DevConfig {
|
|
677
684
|
apiKey: string;
|
|
678
685
|
gameId: string;
|
|
686
|
+
/** 本地预览/dev:指定初始模型的展示名(display name)。不传则用第一个可用模型。 */
|
|
687
|
+
model?: string;
|
|
679
688
|
}
|
|
680
689
|
declare class StorviaSDK {
|
|
681
690
|
private http;
|
|
682
|
-
private settingsSheet;
|
|
683
691
|
private baseUrl;
|
|
684
692
|
private gameId;
|
|
685
693
|
private conversationId;
|
|
@@ -701,6 +709,12 @@ declare class StorviaSDK {
|
|
|
701
709
|
state: StateModule;
|
|
702
710
|
memory: MemoryModule;
|
|
703
711
|
init(): Promise<void>;
|
|
712
|
+
/**
|
|
713
|
+
* 监听宿主运行时下发的模型切换(envelope 'set-model')。
|
|
714
|
+
* 正式模式用:宿主已接管模型选择,用户在宿主 FAB 改模型时实时同步到 SDK。
|
|
715
|
+
* (预览模式的 set-model 在 listenForPreviewMessages 内单独处理。)
|
|
716
|
+
*/
|
|
717
|
+
private listenForModelChange;
|
|
704
718
|
/**
|
|
705
719
|
* 监听父页面 token 刷新(envelope 'token-update')。
|
|
706
720
|
* Supabase JWT 默认 1h 过期,父页面 session 自动刷新后转发新 token 进来,
|
|
@@ -718,13 +732,8 @@ declare class StorviaSDK {
|
|
|
718
732
|
private fetchPreviewSnapshot;
|
|
719
733
|
/** 重新拉 snapshot 并把结果灌进每个 module 的 mem(用于 update-config 后同步) */
|
|
720
734
|
private refreshPreviewSnapshot;
|
|
721
|
-
/** 保存设置到后端 */
|
|
722
|
-
private saveSettings;
|
|
723
|
-
/** 同步最新游戏设定到当前存档 */
|
|
724
|
-
syncSettings(): Promise<void>;
|
|
725
735
|
private fetchModels;
|
|
726
736
|
private authenticate;
|
|
727
|
-
private getSavedModelId;
|
|
728
737
|
initDev(devConfig: DevConfig): Promise<void>;
|
|
729
738
|
getAssets(type: 'avatar' | 'icon', category?: string): Promise<AssetItem[]>;
|
|
730
739
|
}
|
|
@@ -772,6 +781,12 @@ interface InitPayload {
|
|
|
772
781
|
* 待主站 / App 全部升级后改为必填,以彻底消除 /auth 端选错存档的漂移。
|
|
773
782
|
*/
|
|
774
783
|
conversationId?: string;
|
|
784
|
+
/**
|
|
785
|
+
* 宿主(主站/App)已选中的模型 UUID。宿主已接管模型选择 → 正式模式优先用它,
|
|
786
|
+
* 盖过 SDK 自己的 localStorage / 列表首项。随 init 一起下发,避免「init 后单独发 set-model」
|
|
787
|
+
* 在 SDK 注册监听前到达而丢失的竞态。运行时切换仍走 envelope 'set-model'。
|
|
788
|
+
*/
|
|
789
|
+
selectedModelId?: string;
|
|
775
790
|
debug?: boolean;
|
|
776
791
|
}
|
|
777
792
|
interface PreviewConfig {
|
|
@@ -830,7 +845,7 @@ interface AckPayload {
|
|
|
830
845
|
error?: string;
|
|
831
846
|
}
|
|
832
847
|
type DownstreamMsg = ProtocolEnvelope<'init', InitPayload> | ProtocolEnvelope<'preview-init', PreviewInitPayload> | ProtocolEnvelope<'token-update', TokenUpdatePayload> | ProtocolEnvelope<'config-update', ConfigUpdatePayload> | ProtocolEnvelope<'set-model', SetModelPayload> | ProtocolEnvelope<'orientation', OrientationPayload> | ProtocolEnvelope<'ack', AckPayload>;
|
|
833
|
-
type UpstreamMsg = ProtocolEnvelope<'ready', ReadyPayload> | ProtocolEnvelope<'exit', Record<string, never>> | ProtocolEnvelope<'request-orientation', OrientationPayload> | ProtocolEnvelope<'error', SdkErrorPayload> | ProtocolEnvelope<'navigate', NavigatePayload> | ProtocolEnvelope<'ack', AckPayload>;
|
|
848
|
+
type UpstreamMsg = ProtocolEnvelope<'ready', ReadyPayload> | ProtocolEnvelope<'exit', Record<string, never>> | ProtocolEnvelope<'request-orientation', OrientationPayload> | ProtocolEnvelope<'error', SdkErrorPayload> | ProtocolEnvelope<'navigate', NavigatePayload> | ProtocolEnvelope<'model-change', SetModelPayload> | ProtocolEnvelope<'ack', AckPayload>;
|
|
834
849
|
declare function isProtocolEnvelope(data: unknown): data is ProtocolEnvelope<string, unknown>;
|
|
835
850
|
declare function envelope<T extends string, P>(type: T, payload: P, opts?: {
|
|
836
851
|
id?: string;
|