@storvia/sdk 0.8.6 → 0.9.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.d.mts CHANGED
@@ -1,85 +1,3 @@
1
- /** 续读/重连共用的回调集合(与 stream() 的散参一一对应)。 */
2
- interface SSECallbacks {
3
- onChunk: (text: string) => void;
4
- onDone: (id: string) => void;
5
- onState?: (delta: unknown, full: unknown) => void;
6
- onThinking?: (status: 'start' | 'end') => void;
7
- onCreatedCharacters?: (names: string[]) => void;
8
- /** 每次发起重连前触发(attempt 从 1 递增),供 UI 提示「正在重新连接」。 */
9
- onReconnect?: (info: {
10
- attempt: number;
11
- }) => void;
12
- }
13
- declare class HttpClient {
14
- private baseUrl;
15
- private token;
16
- private debug;
17
- private devApiKey;
18
- constructor(baseUrl: string, token: string, debug?: boolean, devApiKey?: string);
19
- setToken(token: string): void;
20
- setDebug(enabled: boolean): void;
21
- private static readonly REQUEST_TIMEOUT;
22
- private static readonly MODEL_LOADING_TIMEOUT;
23
- private static readonly STREAM_INACTIVITY_TIMEOUT;
24
- /** 非 StorviaError(通常是 fetch 网络层抛错)统一弹 NETWORK_ERROR toast */
25
- private maybeShowNetworkToast;
26
- /** 将 AbortError 转换为 StorviaError('REQUEST_TIMEOUT') */
27
- private wrapAbortError;
28
- /** 创建带超时的 AbortController */
29
- private createTimeoutController;
30
- private buildHeaders;
31
- /**
32
- * Debug 日志:打印完整的请求与响应。
33
- * - 成功:请求体、HTTP 状态、完整原始响应体(后端返回的 `{success, data, ...}` 整体 JSON)、耗时
34
- * - 失败:请求体、HTTP 状态、完整原始响应体(含错误码/消息)、错误对象、耗时
35
- */
36
- private log;
37
- get<T>(path: string, params?: Record<string, string>): Promise<T>;
38
- post<T>(path: string, body?: unknown, meta?: {
39
- modelName?: string;
40
- }): Promise<T>;
41
- patch<T>(path: string, body?: unknown): Promise<T>;
42
- put<T>(path: string, body?: unknown): Promise<T>;
43
- delete<T>(path: string): Promise<T>;
44
- stream(path: string, body: unknown, onChunk: (text: string) => void, onDone: (id: string) => void, meta?: {
45
- modelName?: string;
46
- }, onState?: (delta: unknown, full: unknown) => void, onThinking?: (status: 'start' | 'end') => void, onCreatedCharacters?: (names: string[]) => void, resume?: {
47
- conversationId: string;
48
- topic?: string;
49
- }, onReconnect?: (info: {
50
- attempt: number;
51
- }) => void): Promise<void>;
52
- private static readonly RECONNECT_MAX_ATTEMPTS;
53
- private static readonly RECONNECT_BACKOFF_CAP;
54
- /**
55
- * 重连循环:退避 → GET 续读 → 直到拿到终止事件 / 服务端报无在途 / 次数耗尽。
56
- * 每次重连前回调 onReconnect 供 UI 提示「正在重新连接 n/10」。
57
- *
58
- * opts.finalize:发起方链路(send/generate/retry 的断线续读)传 true —— 即使
59
- * done 事件彻底丢失(messageId 为空)也必须触发 onDone 给调用方一个确定结局,
60
- * 否则上层等回调等不到(「send 未返回」)。resume() 接管链路保持旧语义
61
- * (无在途生成时静默返回)。
62
- */
63
- private resumeLoop;
64
- /**
65
- * 公开续读入口:接管某会话/ topic 的在途生成(刷新 / 换设备 / 多端接力时用)。
66
- * 无在途生成则静默返回。供 ChatModule.resume() 调用。
67
- */
68
- resumeStream(conversationId: string, topic: string | undefined, cb: SSECallbacks): Promise<void>;
69
- /** 续读读到终态 error 事件:toast + 构造抛给调用方的错误。 */
70
- private terminalError;
71
- /** 单次 GET 续读:拉一段 SSE 并分发。无在途生成(服务端回 JSON)返回 'inactive';HTTP/网络失败抛出供上层退避。 */
72
- private pumpGetStream;
73
- /** 共享 SSE 读循环:解析 id:/data:,分发 content/state/thinking/done,跟踪 lastId。带无活动超时(cancel 后返回 'eof' 供重连)。 */
74
- private pumpReader;
75
- /**
76
- * 读取完整响应文本,解析为 JSON 并返回 `{ raw, data }`:
77
- * - `raw` 是后端返回的整体(用于 debug 完整打印,含 success/code/message 等包装字段)
78
- * - `data` 是业务调用方期望的 T(解包 `{success, data}` 后)
79
- */
80
- private handleResponseWithRaw;
81
- }
82
-
83
1
  interface AISummary {
84
2
  /** 记忆内容 */
85
3
  content: string;
@@ -93,7 +11,7 @@ interface AssetItem {
93
11
  assetType: 'avatar' | 'icon';
94
12
  category: string;
95
13
  }
96
- type StorviaErrorCode = 'UNAUTHORIZED' | 'INSUFFICIENT_CREDITS' | 'VIOLATION_WORD_DETECTED' | 'CONTENT_FILTERED' | 'MODEL_REFUSAL' | 'STREAM_INTERRUPTED' | 'RATE_LIMITED' | 'MODEL_NOT_FOUND' | 'GAME_NOT_FOUND' | 'INVALID_REQUEST' | 'INTERNAL_ERROR' | 'NOT_INITIALIZED' | 'NOT_SUPPORTED_IN_PREVIEW' | 'NETWORK_ERROR' | 'REQUEST_TIMEOUT' | 'MODEL_LOADING_TIMEOUT' | 'STREAM_INACTIVITY' | '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';
14
+ type StorviaErrorCode = 'UNAUTHORIZED' | 'INSUFFICIENT_CREDITS' | 'VIOLATION_WORD_DETECTED' | 'CONTENT_FILTERED' | 'MODEL_REFUSAL' | 'STREAM_INTERRUPTED' | 'RATE_LIMITED' | 'MODEL_NOT_FOUND' | 'GAME_NOT_FOUND' | 'INVALID_REQUEST' | 'INTERNAL_ERROR' | 'NOT_INITIALIZED' | 'NOT_SUPPORTED_IN_PREVIEW' | 'NETWORK_ERROR' | 'REQUEST_TIMEOUT' | 'MODEL_LOADING_TIMEOUT' | 'STREAM_INACTIVITY' | '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';
97
15
  /** AI 本轮的属性变更(仅包含发生改变的字段) */
98
16
  interface StateChanges {
99
17
  /** 世界状态变更(扁平 KV) */
@@ -152,6 +70,37 @@ type ChatCreatedCharactersCallback = (names: string[]) => void;
152
70
  type ChatReconnectingCallback = (info: {
153
71
  attempt: number;
154
72
  }) => void;
73
+ /** 生成正常结束时的附加信息(done 事件) */
74
+ interface ChatDoneInfo {
75
+ /**
76
+ * 本条 AI 回复是否被模型截断(输出没写完就停了)。
77
+ * `true` 时可调 `chat.continue()` **免费**续写补完;`false` 调 continue 会正常扣费。
78
+ * 用户主动中断产生的消息恒为 `false`(中断 ≠ 截断,不给免费续写)。
79
+ */
80
+ truncated: boolean;
81
+ }
82
+ /**
83
+ * 生成结束回调。
84
+ * @param id AI 消息 uuid;断线且 done 事件丢失时可能为空串(内容已落库,可用 chat.messages() 取回)
85
+ * @param info 附加信息;仅在收到服务端 done 事件时提供,续读兜底收尾时为 undefined
86
+ */
87
+ type ChatDoneCallback = (id: string, info?: ChatDoneInfo) => void;
88
+ /** 生成被中断时的信息(aborted 事件) */
89
+ interface ChatAbortInfo {
90
+ /** AI 消息 uuid;`persisted:false` 时为空串 */
91
+ id: string;
92
+ /**
93
+ * 半截内容是否已入库。
94
+ * `false` = TTFT 前就停了、零内容、未入库 —— 调用方**必须把玩家刚发的输入放回输入框**,
95
+ * 否则玩家的话就丢了(服务端无法代为恢复)。
96
+ */
97
+ persisted: boolean;
98
+ }
99
+ /**
100
+ * 生成被用户主动中断时触发(`chat.cancel()` 后,或其他设备取消了同一条生成)。
101
+ * 提供此回调时**不再触发 `onDone`**;未提供时降级为 `onDone(id)` 保证总有终态回调。
102
+ */
103
+ type ChatAbortedCallback = (info: ChatAbortInfo) => void;
155
104
  /**
156
105
  * 流式 + 入库内容过滤规则。提供后,服务端只保留 AI 回复中
157
106
  * `start..end` 之间的内容(多段会自动拼接),其余被丢弃。
@@ -176,7 +125,7 @@ interface ChatSendOptions {
176
125
  extract?: ChatExtractRule;
177
126
  stream?: boolean;
178
127
  onChunk?: (text: string) => void;
179
- onDone?: (id: string) => void;
128
+ onDone?: ChatDoneCallback;
180
129
  /** AI 本轮有属性变更时触发;非流式调用通过 ChatResponse.delta/full 获取,无需此回调 */
181
130
  onState?: ChatStateCallback;
182
131
  /** 模型 reasoning 状态变更('start' = 开始思考,'end' = 开始输出正文);仅支持思考型模型 */
@@ -185,6 +134,8 @@ interface ChatSendOptions {
185
134
  onCreatedCharacters?: ChatCreatedCharactersCallback;
186
135
  /** 仅流式:生成中途断开后 SDK 自动续读,每次重连前触发,供 UI 提示「正在重新连接」 */
187
136
  onReconnecting?: ChatReconnectingCallback;
137
+ /** 仅流式:生成被 chat.cancel() 中断时触发;提供后不再触发 onDone */
138
+ onAborted?: ChatAbortedCallback;
188
139
  }
189
140
  interface ChatSaveOptions {
190
141
  role: 'user' | 'assistant';
@@ -198,7 +149,7 @@ interface ChatGenerateOptions {
198
149
  extract?: ChatExtractRule;
199
150
  stream?: boolean;
200
151
  onChunk?: (text: string) => void;
201
- onDone?: (id: string) => void;
152
+ onDone?: ChatDoneCallback;
202
153
  /** AI 本轮有属性变更时触发;非流式调用通过 ChatResponse.delta/full 获取,无需此回调 */
203
154
  onState?: ChatStateCallback;
204
155
  /** 模型 reasoning 状态变更('start' = 开始思考,'end' = 开始输出正文);仅支持思考型模型 */
@@ -207,6 +158,8 @@ interface ChatGenerateOptions {
207
158
  onCreatedCharacters?: ChatCreatedCharactersCallback;
208
159
  /** 仅流式:生成中途断开后 SDK 自动续读,每次重连前触发,供 UI 提示「正在重新连接」 */
209
160
  onReconnecting?: ChatReconnectingCallback;
161
+ /** 仅流式:生成被 chat.cancel() 中断时触发;提供后不再触发 onDone */
162
+ onAborted?: ChatAbortedCallback;
210
163
  }
211
164
  interface ChatRetryOptions {
212
165
  topic?: string;
@@ -215,7 +168,7 @@ interface ChatRetryOptions {
215
168
  extract?: ChatExtractRule;
216
169
  stream?: boolean;
217
170
  onChunk?: (text: string) => void;
218
- onDone?: (id: string) => void;
171
+ onDone?: ChatDoneCallback;
219
172
  /** AI 本轮有属性变更时触发;非流式调用通过 ChatResponse.delta/full 获取,无需此回调 */
220
173
  onState?: ChatStateCallback;
221
174
  /** 模型 reasoning 状态变更('start' = 开始思考,'end' = 开始输出正文);仅支持思考型模型 */
@@ -224,6 +177,8 @@ interface ChatRetryOptions {
224
177
  onCreatedCharacters?: ChatCreatedCharactersCallback;
225
178
  /** 仅流式:生成中途断开后 SDK 自动续读,每次重连前触发,供 UI 提示「正在重新连接」 */
226
179
  onReconnecting?: ChatReconnectingCallback;
180
+ /** 仅流式:生成被 chat.cancel() 中断时触发;提供后不再触发 onDone */
181
+ onAborted?: ChatAbortedCallback;
227
182
  }
228
183
  interface ChatResponse {
229
184
  id: string;
@@ -234,6 +189,52 @@ interface ChatResponse {
234
189
  full?: State;
235
190
  /** 本轮出现的「真·新角色」名字数组,仅在有新角色时出现 */
236
191
  createdNames?: string[];
192
+ /** 回复是否被模型截断;`true` 时可调 `chat.continue()` 免费续写补完 */
193
+ truncated: boolean;
194
+ /**
195
+ * 本轮生成被用户中断(半截内容已入库)。仅在中断时出现。
196
+ * 零内容中断不会走到这里 —— 那种情况直接抛 `StorviaError`(code: `GENERATION_ABORTED`)。
197
+ */
198
+ aborted?: boolean;
199
+ }
200
+ /**
201
+ * chat.continue() 选项:续写最后一条 AI 消息(把没写完的补完)。
202
+ * 续写目标由服务端自己定位(该 topic 下最后一条 AI 消息),无需也无法指定消息 id。
203
+ * **始终流式**,无非流式分支。
204
+ */
205
+ interface ChatContinueOptions {
206
+ /** 续写哪条支线的最后一条 AI 消息;缺省 = 主线 */
207
+ topic?: string;
208
+ /**
209
+ * 内容过滤规则;与 send/generate/retry 的 extract 语义一致,流式与入库都只保留 start..end 范围。
210
+ * 若被续写的消息是 extract 模式生成的,**必须传入原样的规则**,否则续写内容不会被抽取(标记外的
211
+ * 思考/旁白会流给玩家并入库)。续写是纯追加:已存内容不会被改写,只在其后接上新抽取的可见内容。
212
+ */
213
+ extract?: ChatExtractRule;
214
+ onChunk?: (text: string) => void;
215
+ onDone?: ChatDoneCallback;
216
+ onState?: ChatStateCallback;
217
+ onThinking?: ChatThinkingCallback;
218
+ onCreatedCharacters?: ChatCreatedCharactersCallback;
219
+ onReconnecting?: ChatReconnectingCallback;
220
+ onAborted?: ChatAbortedCallback;
221
+ }
222
+ /** chat.cancel() 选项 */
223
+ interface ChatCancelOptions {
224
+ /** 停哪条支线的在途生成;缺省 = 主线。锁是 topic 维度,与生成网关一致 */
225
+ topic?: string;
226
+ }
227
+ /** chat.cancel() 结果 */
228
+ interface ChatCancelResult {
229
+ /**
230
+ * 是否真的有在途生成被取消。
231
+ * `false` = 生成已经跑完了(竞态,取消信号来晚了)—— 此时**不会**再收到 `aborted` 事件,
232
+ * 正常的 `done` 已经在流里,调用方应立即复位「停止中」这类 UI 状态。
233
+ * `true` = 已发出取消信号,等 `onAborted` 统一收尾,别自己动本地流。
234
+ */
235
+ active: boolean;
236
+ /** 被取消的生成 id;`active:false` 时为 undefined */
237
+ generationId?: string;
237
238
  }
238
239
  /**
239
240
  * chat.resume() 选项:接管会话/ topic 的在途生成(刷新 / 换设备 / 多端接力)。
@@ -242,11 +243,13 @@ interface ChatResponse {
242
243
  interface ChatResumeOptions {
243
244
  topic?: string;
244
245
  onChunk?: (text: string) => void;
245
- onDone?: (id: string) => void;
246
+ onDone?: ChatDoneCallback;
246
247
  onState?: ChatStateCallback;
247
248
  onThinking?: ChatThinkingCallback;
248
249
  onCreatedCharacters?: ChatCreatedCharactersCallback;
249
250
  onReconnecting?: ChatReconnectingCallback;
251
+ /** 接管的在途生成被中断时触发(含其他设备按了停止);提供后不再触发 onDone */
252
+ onAborted?: ChatAbortedCallback;
250
253
  }
251
254
  interface ChatMessageCursor {
252
255
  uuid: string;
@@ -266,6 +269,11 @@ interface ChatMessage {
266
269
  status: string;
267
270
  model: string | null;
268
271
  createdAt: string;
272
+ /**
273
+ * AI 回复是否被模型截断(user 消息恒 false)。
274
+ * 刷新 / 重进游戏后据此决定要不要给这条消息显示「继续」按钮 —— `true` 时 `chat.continue()` 免费。
275
+ */
276
+ truncated: boolean;
269
277
  }
270
278
  interface ChatMessagesResponse {
271
279
  data: ChatMessage[];
@@ -452,6 +460,90 @@ interface State {
452
460
  dormant: DormantState;
453
461
  }
454
462
 
463
+ /** 续读/重连共用的回调集合(与 stream() 的散参一一对应)。 */
464
+ interface SSECallbacks {
465
+ onChunk: (text: string) => void;
466
+ onDone: (id: string, info?: ChatDoneInfo) => void;
467
+ onState?: (delta: unknown, full: unknown) => void;
468
+ onThinking?: (status: 'start' | 'end') => void;
469
+ onCreatedCharacters?: (names: string[]) => void;
470
+ /** 每次发起重连前触发(attempt 从 1 递增),供 UI 提示「正在重新连接」。 */
471
+ onReconnect?: (info: {
472
+ attempt: number;
473
+ }) => void;
474
+ /** 用户主动中断(aborted 终态事件)。未提供时降级为 onDone,保证总有终态回调。 */
475
+ onAborted?: (info: ChatAbortInfo) => void;
476
+ }
477
+ declare class HttpClient {
478
+ private baseUrl;
479
+ private token;
480
+ private debug;
481
+ private devApiKey;
482
+ constructor(baseUrl: string, token: string, debug?: boolean, devApiKey?: string);
483
+ setToken(token: string): void;
484
+ setDebug(enabled: boolean): void;
485
+ private static readonly REQUEST_TIMEOUT;
486
+ private static readonly MODEL_LOADING_TIMEOUT;
487
+ private static readonly STREAM_INACTIVITY_TIMEOUT;
488
+ /** 非 StorviaError(通常是 fetch 网络层抛错)统一弹 NETWORK_ERROR toast */
489
+ private maybeShowNetworkToast;
490
+ /** 将 AbortError 转换为 StorviaError('REQUEST_TIMEOUT') */
491
+ private wrapAbortError;
492
+ /** 创建带超时的 AbortController */
493
+ private createTimeoutController;
494
+ private buildHeaders;
495
+ /**
496
+ * Debug 日志:打印完整的请求与响应。
497
+ * - 成功:请求体、HTTP 状态、完整原始响应体(后端返回的 `{success, data, ...}` 整体 JSON)、耗时
498
+ * - 失败:请求体、HTTP 状态、完整原始响应体(含错误码/消息)、错误对象、耗时
499
+ */
500
+ private log;
501
+ get<T>(path: string, params?: Record<string, string>): Promise<T>;
502
+ post<T>(path: string, body?: unknown, meta?: {
503
+ modelName?: string;
504
+ }): Promise<T>;
505
+ patch<T>(path: string, body?: unknown): Promise<T>;
506
+ put<T>(path: string, body?: unknown): Promise<T>;
507
+ delete<T>(path: string): Promise<T>;
508
+ stream(path: string, body: unknown, onChunk: (text: string) => void, onDone: (id: string) => void, meta?: {
509
+ modelName?: string;
510
+ }, onState?: (delta: unknown, full: unknown) => void, onThinking?: (status: 'start' | 'end') => void, onCreatedCharacters?: (names: string[]) => void, resume?: {
511
+ conversationId: string;
512
+ topic?: string;
513
+ }, onReconnect?: (info: {
514
+ attempt: number;
515
+ }) => void, onAborted?: (info: ChatAbortInfo) => void): Promise<void>;
516
+ private static readonly RECONNECT_MAX_ATTEMPTS;
517
+ private static readonly RECONNECT_BACKOFF_CAP;
518
+ /**
519
+ * 重连循环:退避 → GET 续读 → 直到拿到终止事件 / 服务端报无在途 / 次数耗尽。
520
+ * 每次重连前回调 onReconnect 供 UI 提示「正在重新连接 n/10」。
521
+ *
522
+ * opts.finalize:发起方链路(send/generate/retry 的断线续读)传 true —— 即使
523
+ * done 事件彻底丢失(messageId 为空)也必须触发 onDone 给调用方一个确定结局,
524
+ * 否则上层等回调等不到(「send 未返回」)。resume() 接管链路保持旧语义
525
+ * (无在途生成时静默返回)。
526
+ */
527
+ private resumeLoop;
528
+ /**
529
+ * 公开续读入口:接管某会话/ topic 的在途生成(刷新 / 换设备 / 多端接力时用)。
530
+ * 无在途生成则静默返回。供 ChatModule.resume() 调用。
531
+ */
532
+ resumeStream(conversationId: string, topic: string | undefined, cb: SSECallbacks): Promise<void>;
533
+ /** 续读读到终态 error 事件:toast + 构造抛给调用方的错误。 */
534
+ private terminalError;
535
+ /** 单次 GET 续读:拉一段 SSE 并分发。无在途生成(服务端回 JSON)返回 'inactive';HTTP/网络失败抛出供上层退避。 */
536
+ private pumpGetStream;
537
+ /** 共享 SSE 读循环:解析 id:/data:,分发 content/state/thinking/done,跟踪 lastId。带无活动超时(cancel 后返回 'eof' 供重连)。 */
538
+ private pumpReader;
539
+ /**
540
+ * 读取完整响应文本,解析为 JSON 并返回 `{ raw, data }`:
541
+ * - `raw` 是后端返回的整体(用于 debug 完整打印,含 success/code/message 等包装字段)
542
+ * - `data` 是业务调用方期望的 T(解包 `{success, data}` 后)
543
+ */
544
+ private handleResponseWithRaw;
545
+ }
546
+
455
547
  declare class ChatModule {
456
548
  private http;
457
549
  private getGameId;
@@ -488,6 +580,25 @@ declare class ChatModule {
488
580
  * 适用于 AI 回复出错或不满意时重新生成
489
581
  */
490
582
  retry(options?: ChatRetryOptions): Promise<ChatResponse | void>;
583
+ /**
584
+ * 续写最后一条 AI 消息(把没写完的补完,覆盖式更新原消息、不新增消息)
585
+ * - 续写目标由服务端定位(该 topic 下最后一条 AI 消息),无需也无法指定消息 id
586
+ * - **原消息 `truncated:true`(模型自己截断)时免费**;否则按正常对话扣费
587
+ * - 始终流式;用固定的续写模型 + prefill 接续,不受当前选中模型影响
588
+ * 预览模式无持久消息,静默返回。
589
+ */
590
+ continue(options?: ChatContinueOptions): Promise<void>;
591
+ /**
592
+ * 中断当前会话/ topic 的在途生成(停止按钮)
593
+ * - 中断有内容 → 半截内容入库 + 按已生成部分扣费,随后流上发 `aborted` 事件
594
+ * - 中断时零内容 → 不入库不扣费,`aborted` 事件 `persisted:false`(调用方需把玩家输入放回输入框)
595
+ * - 中断的消息 `truncated` 恒 false(中断 ≠ 截断),**不给免费续写**
596
+ *
597
+ * 返回 `active:false` 表示生成已经跑完、取消来晚了(竞态):此时不会再有 `aborted` 事件,
598
+ * 正常的 `done` 已在流里,调用方应立即复位「停止中」UI;`active:true` 则等 `onAborted` 收尾。
599
+ * 预览模式无在途生成,恒返回 `{ active: false }`。
600
+ */
601
+ cancel(options?: ChatCancelOptions): Promise<ChatCancelResult>;
491
602
  /**
492
603
  * 获取当前会话的消息列表(支持 topic 过滤 + 游标分页)
493
604
  * order: 'asc' = 从旧到新(历史展示),'desc' = 从新到旧(游戏内聊天框)
@@ -1026,4 +1137,4 @@ interface ToastAction {
1026
1137
  */
1027
1138
  declare function showToast(message: string, type?: ToastType, duration?: number, action?: ToastAction): void;
1028
1139
 
1029
- export { type AISummary, type AckPayload, type AssetItem, type CharacterAddOptions, type CharacterDetail, type CharacterPersona, type CharacterUpdateOptions, 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 FieldValue, type Gender, type InitPayload, type InventoryAddOptions, type InventoryMoveOptions, type InventoryRemoveGroupOptions, type InventoryRemoveOptions, type InventoryState, type InventoryUpdateOptions, type ItemData, type OrientationPayload, PROTOCOL_VERSION, type PlayerPersona, 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, createStorviaSDK, envelope, extractFieldValue, isProtocolEnvelope, isRichFieldValue, setToastEnabled, showToast };
1140
+ 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 FieldValue, type Gender, type InitPayload, type InventoryAddOptions, type InventoryMoveOptions, type InventoryRemoveGroupOptions, type InventoryRemoveOptions, type InventoryState, type InventoryUpdateOptions, type ItemData, type OrientationPayload, PROTOCOL_VERSION, type PlayerPersona, 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, createStorviaSDK, envelope, extractFieldValue, isProtocolEnvelope, isRichFieldValue, setToastEnabled, showToast };