@webskill/chatbot 0.10.0 → 0.11.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/chatbot.css +5 -6
- package/dist/index.d.ts +630 -489
- package/dist/index.js +196 -94
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AgentLoopConfig, ApprovalScope, BridgeCapabilities, DocxTextExtractor, ExternalSkillProvider, ExternalToolSource, FileSystemProvider, HookRunner, InteractionRequest, InteractionResponse, LifecycleEventInit, LinkedDocumentReader, LlmClient, NetworkPolicy, Page, PageQuery, PdfTextExtractor, RenderBlock, RenderResultRequest, RunSnapshot, RunSnapshotListEntry, RuntimePhase, RuntimeRun, ScriptExecutor, SessionStore, SkillCandidateMarker, SkillCatalogEntry, SkillIntegrityGuard, SkillOutcomeReporter, SkillStateGuard, UiBridge, UiSpecDrafts, UiSpecEvent, UiSpecSnapshot, UiSurfaceActionRequest, UiSurfaceActionResponse, UserProfile, UserProfileExport, WebSkillErrorCode, XlsxTextExtractor, diffUserProfile } from "@webskill/sdk";
|
|
1
|
+
import { AgentLoopConfig, ApprovalScope, BridgeCapabilities, DataSourceInfo, DocxTextExtractor, ExternalSkillProvider, ExternalToolSource, FileSystemProvider, HookRunner, InteractionRequest, InteractionResponse, LifecycleEventInit, LinkedDocumentReader, LlmClient, NetworkPolicy, Page, PageQuery, PdfTextExtractor, RenderBlock, RenderResultRequest, RunSnapshot, RunSnapshotListEntry, RuntimePhase, RuntimeRun, ScriptExecutor, SessionStore, SkillCandidateMarker, SkillCatalogEntry, SkillIntegrityGuard, SkillOutcomeReporter, SkillStateGuard, UiBridge, UiSpecDrafts, UiSpecEvent, UiSpecSnapshot, UiSurfaceActionRequest, UiSurfaceActionResponse, UserProfile, UserProfileExport, WebSkillErrorCode, XlsxTextExtractor, diffUserProfile } from "@webskill/sdk";
|
|
2
2
|
import { SandboxMode, TypeScriptSupportOptions } from "@webskill/sdk/browser";
|
|
3
3
|
import { CustomSurfaceActionEvent, ReactBridgeState, SpecInteractionChannel, SurfaceRegistry, UiSurfaceActionEvent } from "@webskill/sdk/ui-react";
|
|
4
|
-
import { PageActionPolicy, PagePerceptionPolicy, PerceptionRecord, SkillCandidateSink, TodoItem } from "@webskill/sdk/agent";
|
|
4
|
+
import { DownloadedFileConsent, DownloadedFileReader, PageActionPolicy, PagePerceptionPolicy, PerceptionPagingBudget, PerceptionRecord, SkillCandidateSink, TodoItem } from "@webskill/sdk/agent";
|
|
5
5
|
import "react";
|
|
6
6
|
import "react/jsx-runtime";
|
|
7
7
|
//#region ../ui-kit/src/i18n/types.d.ts
|
|
@@ -26,6 +26,37 @@ type InterpolationParams = Record<string, string | number>;
|
|
|
26
26
|
/** t(key, params?):查当前 locale 词条并做 {name} 插值 */
|
|
27
27
|
type TranslateFn<D extends Dictionary = Dictionary> = (key: DictionaryKey<D>, params?: InterpolationParams) => string;
|
|
28
28
|
//#endregion
|
|
29
|
+
//#region ../core/src/attachment/kind.d.ts
|
|
30
|
+
/**
|
|
31
|
+
* 附件类型判据与文本形态。0.14.0 分册 20 从 `@webskill/chatbot` 迁入:
|
|
32
|
+
* 「用户上传」与「读取下载目录」两条入口必须给出同一结论(AC-20.17)、
|
|
33
|
+
* 产出同一份文本(AC-20.6),而后者住在 `@webskill/agent`,chatbot 依赖 agent,
|
|
34
|
+
* 判据只能落在两者共同的下游。纯字符串运算,无环境依赖。
|
|
35
|
+
*/
|
|
36
|
+
/** 附件在模型侧的内容形态(0.6.0 FR-11.2) @experimental */
|
|
37
|
+
type ChatAttachmentKind = 'text' | 'image' | 'file' | 'document-text';
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region ../runtime/src/tools/types.d.ts
|
|
40
|
+
/**
|
|
41
|
+
* 宿主声明的一个数据源的**可公开部分**(0.14.0 分册 19)。
|
|
42
|
+
*
|
|
43
|
+
* `target` 不在这里,且不得被加进来:这条通路的终点是模型上下文,
|
|
44
|
+
* 而「地址不由脚本提供」正是 0.11.0 分册 16 §2.2 授权面的全部依据。
|
|
45
|
+
* @experimental
|
|
46
|
+
*/
|
|
47
|
+
interface DataSourceInfo$1 {
|
|
48
|
+
id: string;
|
|
49
|
+
description: string;
|
|
50
|
+
/**
|
|
51
|
+
* 非宿主声明时的出处(0.14.0 分册 21)。缺省即宿主声明,不带标注。
|
|
52
|
+
*
|
|
53
|
+
* 有值意味着 `description` **来自页面**,模型看到的清单里必须随之出现「可能不准确」的标注,
|
|
54
|
+
* 否则一段由站点控制的文本会以宿主口吻进上下文。
|
|
55
|
+
* @experimental
|
|
56
|
+
*/
|
|
57
|
+
provenance?: 'page-declared' | 'tool-projection';
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
29
60
|
//#region ../runtime/src/sandbox/bridgeProtocol.d.ts
|
|
30
61
|
/**
|
|
31
62
|
* 能力模式:true 直通 / false 关闭(TOOL_UNSUPPORTED)/ 'require-approval' 调用前强制授权
|
|
@@ -117,6 +148,19 @@ interface RuntimeHooksConfig {
|
|
|
117
148
|
}
|
|
118
149
|
/** 浏览器宿主执行器档位;Node 宿主的 in-process/worker/process 由宿主侧扩展展示 */
|
|
119
150
|
type RuntimeSandboxExecutor = 'auto' | 'blob-worker' | 'iframe-sandbox';
|
|
151
|
+
/**
|
|
152
|
+
* 用户自己声明的取数源(0.14.0 分册 19)。
|
|
153
|
+
*
|
|
154
|
+
* 存在的理由:从别的宿主导出的技能会声明本宿主没有的源 id,没有这一段就永远跑不起来。
|
|
155
|
+
* 它不放宽任何闸门——`url` 照过 `sandbox.remoteUrl` 判定,取数照受 `capabilities.fetchData` 管,
|
|
156
|
+
* 变的只是「谁来写这个地址」:宿主开发者,还是宿主的使用者。
|
|
157
|
+
*/
|
|
158
|
+
interface RuntimeDataSourceEntry {
|
|
159
|
+
id: string;
|
|
160
|
+
/** 绝对 http(s) 地址 */
|
|
161
|
+
url: string;
|
|
162
|
+
description: string;
|
|
163
|
+
}
|
|
120
164
|
interface RuntimeSandboxConfig {
|
|
121
165
|
executor: RuntimeSandboxExecutor;
|
|
122
166
|
networkPolicy: NetworkPolicy$1;
|
|
@@ -138,6 +182,11 @@ interface RuntimeSandboxConfig {
|
|
|
138
182
|
* 所以不受 `toolResultMaxBytes` 约束。
|
|
139
183
|
*/
|
|
140
184
|
maxDataSourceBytes: number;
|
|
185
|
+
/**
|
|
186
|
+
* 用户声明的取数源(0.14.0 分册 19);缺省空数组 = 只有宿主代码写死的那些。
|
|
187
|
+
* 与宿主源撞 id 时宿主的那条胜出——否则用户配置就能改写宿主的授权面。
|
|
188
|
+
*/
|
|
189
|
+
dataSources: RuntimeDataSourceEntry[];
|
|
141
190
|
/**
|
|
142
191
|
* 出站 URL 准入策略(`RemoteUrlPolicy` 的可配置部分):技能安装、MCP 端点连接
|
|
143
192
|
* 这类由宿主发起的取数都按它判定。两项都默认关,即 https-only 且拒绝内网/环回。
|
|
@@ -145,6 +194,13 @@ interface RuntimeSandboxConfig {
|
|
|
145
194
|
remoteUrl: RuntimeRemoteUrlConfig;
|
|
146
195
|
/** 浏览器沙箱的 TypeScript 支持;关闭时 `.ts` 脚本按 `TOOL_UNSUPPORTED` 拒绝 */
|
|
147
196
|
typescript: RuntimeTypeScriptConfig;
|
|
197
|
+
/**
|
|
198
|
+
* 读取用户下载的文件(0.14.0 分册 20)。缺省 `false`。
|
|
199
|
+
*
|
|
200
|
+
* **不放进 `capabilities`**:那张表的语义是三态 `CapabilityMode`(关 / 需批准 / 开),
|
|
201
|
+
* 而本能力的「需批准」是恒定的,放进去会凭空多出一个「开且不批准」的非法组合。
|
|
202
|
+
*/
|
|
203
|
+
downloadedFiles: boolean;
|
|
148
204
|
}
|
|
149
205
|
/**
|
|
150
206
|
* 只做类型擦除,不做类型检查。`esbuildUrl` 为绝对 http(s) 地址时按 `remoteUrl` 判定;
|
|
@@ -378,269 +434,582 @@ declare function createLocalStorageRuntimeConfigStore(options?: LocalStorageRunt
|
|
|
378
434
|
/** 内存实现:测试、SSR、以及宿主明确不想持久化时使用。 @experimental */
|
|
379
435
|
declare function createMemoryRuntimeConfigStore(initial?: Partial<RuntimeConfig>): RuntimeConfigStore;
|
|
380
436
|
//#endregion
|
|
381
|
-
//#region src/core/
|
|
382
|
-
/** 附件在模型侧的内容形态(0.6.0 FR-11.2) @experimental */
|
|
383
|
-
type ChatAttachmentKind = 'text' | 'image' | 'file' | 'document-text';
|
|
384
|
-
//#endregion
|
|
385
|
-
//#region src/core/types.d.ts
|
|
437
|
+
//#region src/core/hostAdapter.d.ts
|
|
386
438
|
/**
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
* @
|
|
439
|
+
* 宿主装配口:chatbot 不感知环境(浏览器/Node),全部能力经此注入。
|
|
440
|
+
* 页面动态技能来源同时是外部工具来源与外部技能提供者(同一对象两个 port)。
|
|
441
|
+
* LLM 配置不在这里——它统一由 `RuntimeConfigStore` 承载(0.5.0 起)。
|
|
442
|
+
* @stable
|
|
391
443
|
*/
|
|
392
|
-
interface
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
444
|
+
interface ChatbotHostAdapter {
|
|
445
|
+
storage: FileSystemProvider;
|
|
446
|
+
skillRoots: string[];
|
|
447
|
+
pageSkillSource?: ExternalToolSource & ExternalSkillProvider;
|
|
448
|
+
navigation: {
|
|
449
|
+
openConsole(): void;
|
|
450
|
+
/** 跳 console Traces 面板并定位该 run(v1.1;缺省时消息不渲染 View trace 入口) */
|
|
451
|
+
openConsoleTrace?(runId: string): void;
|
|
452
|
+
/** 打开治理面的审批队列并定位该候选(FR-24.2);宿主未接治理面时不提供,入口随之不渲染 */
|
|
453
|
+
openConsoleCandidate?(candidateId: string): void;
|
|
454
|
+
};
|
|
455
|
+
/** 缺省 BrowserWorkerScriptExecutor(@webskill/browser);Node 宿主可注入自己的执行器 */
|
|
456
|
+
executor?: ScriptExecutor;
|
|
401
457
|
/**
|
|
402
|
-
*
|
|
458
|
+
* 页面只读感知策略(需求 10)。**只能在这里注入**:启用与否是宿主侧配置,
|
|
459
|
+
* 设置抽屉里没有也不会有开关(FR-10.1)——风险由部署方承担,
|
|
460
|
+
* 不应交给终端用户随手勾选。
|
|
461
|
+
* @experimental
|
|
462
|
+
*/
|
|
463
|
+
pagePerception?: PagePerceptionPolicy;
|
|
464
|
+
/**
|
|
465
|
+
* 感知结果的分段预算(0.14.0 分册 22 FR-22.4 / FR-22.8)。
|
|
403
466
|
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
*
|
|
407
|
-
*
|
|
467
|
+
* 与 `pagePerception` 同一条装配规矩:只能在这里给,设置抽屉里没有开关。
|
|
468
|
+
* **不给即不分段,但地板照样生效**——不开启不等于允许引擎盲切,
|
|
469
|
+
* 超预算时仍然是「读到预算为止 + 一条原位说明」,只是没有续读的入口。
|
|
470
|
+
* @experimental
|
|
408
471
|
*/
|
|
409
|
-
|
|
410
|
-
prompt: string;
|
|
411
|
-
run: RuntimeRun;
|
|
412
|
-
}) => Promise<void>;
|
|
413
|
-
}
|
|
414
|
-
/** 分配式交叉:直接写 `信封 & LifecycleEventInit` 会把联合压成一个对象,`phase` 的判别性就没了 */
|
|
415
|
-
type WithChatMeta<T> = T extends unknown ? {
|
|
416
|
-
type: 'lifecycle';
|
|
417
|
-
runId: string;
|
|
418
|
-
at: number;
|
|
419
|
-
} & T : never;
|
|
420
|
-
/**
|
|
421
|
-
* 生命周期步进事件:`data` 随 `phase` 判别,与 runtime 的 `LifecycleEvent` 同一套契约。
|
|
422
|
-
* 旧的 `Record<string, unknown>` 等于没有契约:消费方只能硬编码键名。
|
|
423
|
-
*/
|
|
424
|
-
type LifecycleChatEvent = WithChatMeta<LifecycleEventInit>;
|
|
425
|
-
/**
|
|
426
|
-
* 交互渲染框架档位:native(React InteractionCard)/ a2ui(@a2ui/lit Lit 渲染)/
|
|
427
|
-
* openui(@openuidev/react-lang Renderer,ui-kit Library)/ vercel(@json-render/react
|
|
428
|
-
* Registry 渲染 catalog 声明树)
|
|
429
|
-
* @experimental
|
|
430
|
-
*/
|
|
431
|
-
type RendererKind = 'native' | 'a2ui' | 'openui' | 'vercel';
|
|
432
|
-
/** assistant 消息所属 run 的一次工具调用(终态:completed/failed) @stable */
|
|
433
|
-
interface ChatToolCall {
|
|
434
|
-
callId: string;
|
|
435
|
-
name: string;
|
|
436
|
-
status: 'completed' | 'failed';
|
|
437
|
-
/** 参数摘要(JSON 截断 100 字符;trace 重放无 args 时留空,卡片展开详情有则显示) */
|
|
438
|
-
args?: string;
|
|
439
|
-
/** 执行耗时(trace completed/failed 回填;live 由 started→终态计时) */
|
|
440
|
-
durationMs?: number;
|
|
472
|
+
pagePerceptionPaging?: PerceptionPagingBudget;
|
|
441
473
|
/**
|
|
442
|
-
*
|
|
443
|
-
*
|
|
474
|
+
* 页面操作能力(需求 23)。**不注入即完全关闭**,与 `pagePerception` 分开:
|
|
475
|
+
* 可读不等于可操作。同样只能在这里注入——给终端用户一个「打开代操作」的开关
|
|
476
|
+
* 等于把安全边界交给最不了解它的人。
|
|
477
|
+
* @experimental
|
|
444
478
|
*/
|
|
445
|
-
|
|
479
|
+
pageActions?: PageActionPolicy;
|
|
446
480
|
/**
|
|
447
|
-
*
|
|
448
|
-
*
|
|
481
|
+
* 读页面链接指向的文档(分册 22)。实现住在 `@webskill/browser`,
|
|
482
|
+
* 而 chatbot 不依赖它 —— 与 `pagePerception` 同一条装配规矩:宿主注入。
|
|
483
|
+
* 不注入即 `read_linked_document` 不注册。
|
|
449
484
|
*/
|
|
450
|
-
|
|
451
|
-
/**
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
485
|
+
linkedDocuments?: LinkedDocumentReader;
|
|
486
|
+
/** docx → 文本(`extractDocxText`);不注入即 Word 文档明确报「本环境不支持」 */
|
|
487
|
+
docxExtractor?: DocxTextExtractor;
|
|
488
|
+
/** xlsx → 文本(`extractXlsxText`);不注入即 Excel 工作簿明确报「本环境不支持」 */
|
|
489
|
+
xlsxExtractor?: XlsxTextExtractor;
|
|
490
|
+
/**
|
|
491
|
+
* PDF → 文本;**只用于直传被端点拒后的回退**(0.13.0 FR-22.1)。
|
|
492
|
+
* PDF 仍然默认直传,能读的端点拿到的还是原件;不注入即没有回退能力。
|
|
493
|
+
*/
|
|
494
|
+
pdfExtractor?: PdfTextExtractor;
|
|
495
|
+
/** 文档读取留痕出口(FR-22.6) */
|
|
496
|
+
documentAudit?: {
|
|
497
|
+
append(event: {
|
|
498
|
+
type: string;
|
|
499
|
+
target: string;
|
|
500
|
+
data?: Record<string, unknown>;
|
|
501
|
+
}): Promise<unknown>;
|
|
502
|
+
};
|
|
503
|
+
/**
|
|
504
|
+
* 读用户本机下载的文件(0.14.0 分册 20)。**不注入即两个工具都不注册**,
|
|
505
|
+
* 与 `sandbox.downloadedFiles` 开关是「与」的关系:宿主没接通路,用户开了也没用。
|
|
506
|
+
*
|
|
507
|
+
* 只收端口,不收策略:授权卡出口、能力开关、模型读图能力、docx/xlsx 抽取器
|
|
508
|
+
* 全在引擎这一侧,宿主自己拼一个策略必然要重复这四项判断。
|
|
509
|
+
* @experimental
|
|
510
|
+
*/
|
|
511
|
+
downloads?: {
|
|
512
|
+
reader: DownloadedFileReader;
|
|
513
|
+
/** 「不再询问」的记忆端口;不注入即每次都问 */
|
|
514
|
+
consent?: DownloadedFileConsent;
|
|
515
|
+
};
|
|
466
516
|
}
|
|
467
|
-
|
|
468
|
-
|
|
517
|
+
//#endregion
|
|
518
|
+
//#region src/core/chatEngine.d.ts
|
|
469
519
|
/**
|
|
470
|
-
*
|
|
471
|
-
*
|
|
520
|
+
* 条目能否真的发请求:云端要有端点或密钥,浏览器内置两者都不需要。
|
|
521
|
+
*
|
|
522
|
+
* 导出给 UI:选择器不用同一份判据的话,用户能选中一个空配置条目,
|
|
523
|
+
* 而引擎静默回退到另一条——界面说在用 A、实际跑的是 B(UI-UX8 D1)。
|
|
472
524
|
* @experimental
|
|
473
525
|
*/
|
|
474
|
-
|
|
475
|
-
phase: RuntimePhase;
|
|
476
|
-
at: number;
|
|
477
|
-
/** 下一个步进到达时回填 */
|
|
478
|
-
endedAt?: number;
|
|
479
|
-
/** 由结构化 `LifecycleEvent.data` 派生的一句摘要 */
|
|
480
|
-
note?: string;
|
|
481
|
-
/** fail 相位的具体说明:`reason` 只有七种取值,说不出「哪个上限、哪个模型」 */
|
|
482
|
-
detail?: string;
|
|
483
|
-
}
|
|
484
|
-
/** 本轮发生的一次已提交交互(FR-17.8:提交后表单保留所填值) @experimental */
|
|
485
|
-
interface ChatInteractionRecord {
|
|
486
|
-
id: string;
|
|
487
|
-
request: InteractionRequest;
|
|
488
|
-
/** 提交时的表单值;文件类字段已在引擎侧脱敏 */
|
|
489
|
-
submittedValues?: unknown;
|
|
490
|
-
}
|
|
526
|
+
declare const isLlmEntryUsable: (entry: RuntimeLlmEntry) => boolean;
|
|
491
527
|
/**
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
*
|
|
528
|
+
* 选中条目 → 默认条目 → 首条;命中不可用条目时**回退到下一个可用条目**
|
|
529
|
+
* (0.10.0 复核:选中项失效时宁可静默换用可用模型,也不能把 UI 锁死成
|
|
530
|
+
* 「未配置」死胡同——引擎与 UI 共用同一判据,两边必须同进退)。
|
|
531
|
+
* 全部不可用才 undefined(引擎走内置演示)。
|
|
532
|
+
*
|
|
533
|
+
* 导出给 UI 复用同一判据:composer 的「未配置模型」引导判定必须与引擎的
|
|
534
|
+
* 实际挑选结果一致,否则会出现「UI 说有模型、引擎却走演示档」的错位(0.10.0 UI-UX5 #49-1)。
|
|
495
535
|
* @experimental
|
|
496
536
|
*/
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
537
|
+
declare function pickUsableLlmEntry(entries: readonly RuntimeLlmEntry[], defaultId: string | undefined, selectedId: string | undefined): RuntimeLlmEntry | undefined;
|
|
538
|
+
/** 默认沙箱执行器的构造参数(adapter.executor 未注入时;executorFactory 替换点可见同一形状) @stable */
|
|
539
|
+
interface SandboxExecutorDeps {
|
|
540
|
+
fs: FileSystemProvider;
|
|
541
|
+
sandbox?: SandboxMode;
|
|
542
|
+
networkPolicy?: NetworkPolicy;
|
|
543
|
+
capabilities?: BridgeCapabilities;
|
|
544
|
+
approvalScope?: ApprovalScope;
|
|
545
|
+
uiBridge?: UiBridge;
|
|
546
|
+
/** 缺省时 `.ts` 脚本按 `TOOL_UNSUPPORTED` 拒绝 */
|
|
547
|
+
typescript?: TypeScriptSupportOptions;
|
|
501
548
|
}
|
|
502
549
|
/**
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
* @experimental
|
|
550
|
+
* 装配时(而非执行时)把 `sandbox.typescript` 转成执行器参数,让配置错误早暴露。
|
|
551
|
+
* 只对绝对 URL 走 `RemoteUrlPolicy`:同源相对路径与打包器 specifier 不是出站请求。
|
|
506
552
|
*/
|
|
507
|
-
interface ChatTokenUsage {
|
|
508
|
-
inputTokens: number;
|
|
509
|
-
outputTokens: number;
|
|
510
|
-
/** 本 run 向大模型发送请求的次数(模型调用轮数) */
|
|
511
|
-
llmCalls: number;
|
|
512
|
-
}
|
|
513
553
|
/**
|
|
514
|
-
*
|
|
515
|
-
*
|
|
554
|
+
* 由 `RuntimeConfig` 装出沙箱执行器依赖。
|
|
555
|
+
*
|
|
556
|
+
* 主链路与**评估链路**共用这一处(T-17-H):此前评估侧只传 `fs`,
|
|
557
|
+
* 于是评估里跑的技能不受沙箱、网络策略、能力与授权范围约束——
|
|
558
|
+
* 那比「.ts 跑不了」严重得多(设计 17 §1.1a)。
|
|
559
|
+
*
|
|
516
560
|
* @experimental
|
|
517
561
|
*/
|
|
518
|
-
|
|
519
|
-
type: 'text';
|
|
520
|
-
text: string;
|
|
521
|
-
at: number;
|
|
522
|
-
} | {
|
|
523
|
-
type: 'surface';
|
|
524
|
-
surfaceId: string;
|
|
525
|
-
at: number;
|
|
526
|
-
} | {
|
|
527
|
-
type: 'blocks';
|
|
528
|
-
at: number;
|
|
529
|
-
};
|
|
562
|
+
declare function sandboxExecutorDeps(fs: FileSystemProvider, rc?: RuntimeConfig, uiBridge?: SandboxExecutorDeps['uiBridge']): SandboxExecutorDeps;
|
|
530
563
|
/** @stable */
|
|
531
|
-
interface
|
|
532
|
-
|
|
533
|
-
|
|
564
|
+
interface ChatEngineOptions {
|
|
565
|
+
llm?: LlmClient;
|
|
566
|
+
loopConfig?: AgentLoopConfig;
|
|
567
|
+
chatRoot?: string;
|
|
568
|
+
/** 运行环境配置存储(P2):#ensureReady 装配时 load()(默认值兜底)并按映射应用 */
|
|
569
|
+
runtimeConfig?: RuntimeConfigStore;
|
|
570
|
+
/** 初始渲染框架档(默认 'native';运行中可 setRenderer 热切换) */
|
|
571
|
+
renderer?: RendererKind;
|
|
534
572
|
/**
|
|
535
|
-
*
|
|
536
|
-
*
|
|
573
|
+
* 注入 `render_ui` 工具,让模型面向 AI Component Catalog 生成声明式 UI。
|
|
574
|
+
*
|
|
575
|
+
* 注入了 `runtimeConfig` 时**以 `RuntimeConfig.agentCapabilities.generativeUi` 为准**,
|
|
576
|
+
* 本字段只在未接配置存储的宿主上生效(否则设置面板里的开关点了不算数)。
|
|
537
577
|
*/
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
attachments?: ChatAttachmentMeta[];
|
|
578
|
+
generativeUi?: boolean;
|
|
579
|
+
/** 沙箱执行器替换点(测试注入 spy 断言构造参数;缺省 BrowserWorkerScriptExecutor) */
|
|
580
|
+
executorFactory?: (deps: SandboxExecutorDeps) => ScriptExecutor;
|
|
542
581
|
/**
|
|
543
|
-
*
|
|
544
|
-
*
|
|
545
|
-
*
|
|
582
|
+
* 宿主声明的数据源取数入口(分册 16)。不注入即脚本上下文没有 `fetchData` 这个键。
|
|
583
|
+
*
|
|
584
|
+
* 装配点必须在宿主:策略本体 `DataSourcePolicy` 住在 `@webskill/agent`,
|
|
585
|
+
* 而数据源的目标地址是宿主自己的业务知识,chatbot 无从代为声明。
|
|
586
|
+
* 能力开关 `sandbox.capabilities.fetchData` 缺省关,注入了也还要宿主在配置里打开。
|
|
546
587
|
*/
|
|
547
|
-
|
|
548
|
-
/** assistant 消息所属 run */
|
|
549
|
-
runId?: string;
|
|
550
|
-
/** 该 run 激活的技能(消息底部 badges) */
|
|
551
|
-
activeSkillNames?: string[];
|
|
552
|
-
/** 该 run 的工具调用序列(思维链工具行;按 trace 顺序) */
|
|
553
|
-
toolCalls?: ChatToolCall[];
|
|
588
|
+
fetchData?: (sourceId: string, params?: Record<string, unknown>) => Promise<unknown>;
|
|
554
589
|
/**
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
* @experimental
|
|
590
|
+
* 宿主声明的数据源清单(0.14.0 分册 19),取自 `DataSourcePolicy.publicSources`。
|
|
591
|
+
* 技能声明了本宿主没有的源时,引擎在激活回执里说明缺什么;不注入即不说。
|
|
558
592
|
*/
|
|
559
|
-
|
|
593
|
+
dataSources?: readonly DataSourceInfo$1[] | (() => readonly DataSourceInfo$1[]);
|
|
560
594
|
/**
|
|
561
|
-
*
|
|
562
|
-
*
|
|
595
|
+
* 会话落盘替换点(缺省 `FsSessionStore`,落在 `<chatRoot>/sessions`)。
|
|
596
|
+
* 宕主换自己的实现(如 IndexedDB)与测试统计端口读写量都走这里。
|
|
563
597
|
*/
|
|
564
|
-
|
|
565
|
-
/** The completed generative UI surfaces emitted by this run, retained for history replay. */
|
|
566
|
-
surfaces?: UiSpecSnapshot[];
|
|
567
|
-
/** 该 run 的待办清单终态(历史消息重放;未产生清单时缺省) */
|
|
568
|
-
todos?: TodoItem[];
|
|
598
|
+
sessionStore?: SessionStore<ChatMessage>;
|
|
569
599
|
/**
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
* @experimental
|
|
600
|
+
* 宿主已注册好钩子的执行器;装配时把 `RuntimeConfig.hooks` 应用到它再交给 runtime。
|
|
601
|
+
* 不注入即不挂钩子(与 0.0.2 行为一致)。
|
|
573
602
|
*/
|
|
574
|
-
|
|
603
|
+
hooks?: HookRunner;
|
|
575
604
|
/**
|
|
576
|
-
*
|
|
577
|
-
*
|
|
578
|
-
*
|
|
605
|
+
* 治理 port 注入(F1):把 `SkillStatePolicy` 的三个适配器接到本引擎装配的 runtime 上。
|
|
606
|
+
*
|
|
607
|
+
* 不注入即完全关闭,行为与 0.0.2 一致。装配点必须在宿主:chatbot 不能依赖
|
|
608
|
+
* `@webskill/governance`(它是可选治理层,且要求宿主提供治理根与审计存储)。
|
|
609
|
+
*
|
|
610
|
+
* 三个一起给才形成闭环——只给 `skillOutcomeReporter` 会把技能标成 `quarantined`
|
|
611
|
+
* 却仍旧照常路由和执行,降级形同虚设。
|
|
579
612
|
*/
|
|
580
|
-
|
|
613
|
+
governance?: ChatbotGovernancePorts;
|
|
581
614
|
/**
|
|
582
|
-
*
|
|
583
|
-
*
|
|
615
|
+
* 技能自动生成的候选收货端(需求 12 号)。与 `governance` 同理,装配点在宿主:
|
|
616
|
+
* `@webskill/governance` 的 `createCandidateSink()` 是现成实现。
|
|
617
|
+
*
|
|
618
|
+
* 开关另在 `RuntimeConfig.agentCapabilities.skillGeneration`(默认关);
|
|
619
|
+
* 开关开但未注入本端口时,工具会把 `SKILL_GENERATION_DISABLED` 回给模型。
|
|
584
620
|
*/
|
|
585
|
-
|
|
621
|
+
skillCandidates?: SkillCandidateSink;
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* 对话框引擎:装配 WebSkillRuntime + 会话持久化 + 事件分发。
|
|
625
|
+
* RuntimeConfig 的 load() 是异步的,runtime 在首次 send 前懒装配(#ensureReady)。
|
|
626
|
+
* @stable
|
|
627
|
+
*/
|
|
628
|
+
declare class ChatEngine {
|
|
629
|
+
#private;
|
|
630
|
+
readonly bridge: ReactBridgeState;
|
|
631
|
+
constructor(adapter: ChatbotHostAdapter, options?: ChatEngineOptions);
|
|
632
|
+
/** 当前待办清单快照(宿主可直读;实时更新订阅 `todo-changed` 事件) */
|
|
633
|
+
get todos(): readonly TodoItem[];
|
|
634
|
+
/** 当前渲染框架档 */
|
|
635
|
+
get renderer(): RendererKind;
|
|
636
|
+
/** 当前会话选中的模型条目 id;未显式切换过时为 undefined(走 `RuntimeConfig.llm.defaultId`) */
|
|
637
|
+
get modelId(): string | undefined;
|
|
586
638
|
/**
|
|
587
|
-
*
|
|
588
|
-
*
|
|
589
|
-
* @experimental
|
|
639
|
+
* 切换本会话后续消息使用的模型条目(需求 4)。传 `undefined` 回到配置里的默认项。
|
|
640
|
+
* 重装配 runtime 以换掉客户端;已落盘的消息不受影响。
|
|
590
641
|
*/
|
|
591
|
-
|
|
642
|
+
setModel(entryId: string | undefined): void;
|
|
643
|
+
/** 会话文件所在目录:「存储未初始化」提示要把路径写给用户看 @experimental */
|
|
644
|
+
get sessionsRoot(): string;
|
|
645
|
+
/** 渲染框架热切换:复合桥按档分发,无需重装配 runtime(会话句柄保留) */
|
|
646
|
+
setRenderer(renderer: RendererKind): void;
|
|
647
|
+
/** 非 native 三档共用的交互通道(Chatbot 的 SpecInteraction 订阅/attach;core 只产出 catalog 节点树) */
|
|
648
|
+
get interactionChannel(): SpecInteractionChannel;
|
|
649
|
+
/** 探测 @a2ui/lit 是否安装(Appearance/设置区 A2UI 档置灰判定) */
|
|
650
|
+
probeA2uiAvailability(): Promise<boolean>;
|
|
651
|
+
onEvent(listener: (event: ChatEvent) => void): () => void;
|
|
592
652
|
/**
|
|
593
|
-
*
|
|
594
|
-
*
|
|
653
|
+
* 配置源变更后调用(LLM 设置 / RuntimeConfigStore 内容变化):丢弃缓存的
|
|
654
|
+
* runtime/llm/会话句柄,下次 send 重新装配(RuntimeConfig 重新 load() 应用)
|
|
655
|
+
*/
|
|
656
|
+
reloadConfig(): void;
|
|
657
|
+
/**
|
|
658
|
+
* 技能仓变更后调用(安装/卸载/发布):作废 runtime 缓存的技能目录,下次 send 重新扫描。
|
|
659
|
+
*
|
|
660
|
+
* 比 `reloadConfig()` 轻,因为它不清 `#handles`——那会连带丢掉每个会话的模型上下文。
|
|
661
|
+
* 装技能的界面与对话不在同一个页面时(如扩展的 options 页 vs side panel),
|
|
662
|
+
* 宿主必须自己把变更通知过来,否则新技能要等页面重载才出现在 catalog 里。
|
|
595
663
|
* @experimental
|
|
596
664
|
*/
|
|
597
|
-
|
|
665
|
+
invalidateSkills(): void;
|
|
598
666
|
/**
|
|
599
|
-
*
|
|
600
|
-
*
|
|
667
|
+
* 会话列表页。归档会话也返回:UI 自己分区展示。
|
|
668
|
+
* `limit` 不给默认值——缺省属于 `SessionStore` 实现,在这里兜底就等于只下推了一半。
|
|
669
|
+
*/
|
|
670
|
+
listSessions(options?: PageQuery): Promise<ChatSessionListResult>;
|
|
671
|
+
/** `title` 缺省时会话先无标题,首条消息发出时再按内容补(FR-21.8) */
|
|
672
|
+
createSession(options?: {
|
|
673
|
+
title?: string;
|
|
674
|
+
}): Promise<ChatSessionMeta>;
|
|
675
|
+
/**
|
|
676
|
+
* 选中会话并取**最新**一页历史(页内时间升序)。
|
|
677
|
+
* 返回全量 `ChatMessage[]` 的旧签名已移除:长会话下它强迫每个调用方拿全量。
|
|
678
|
+
*/
|
|
679
|
+
selectSession(id: string, options?: PageQuery): Promise<Page<ChatMessage>>;
|
|
680
|
+
/** 向历史方向再取一页;`cursor` 只能来自上一页的 `nextCursor` */
|
|
681
|
+
loadMoreMessages(cursor: string, options?: {
|
|
682
|
+
limit?: number;
|
|
683
|
+
}): Promise<Page<ChatMessage>>;
|
|
684
|
+
deleteSession(id: string): Promise<void>;
|
|
685
|
+
/** 重命名会话:写入 title 并锁定(后续 send 不再用首条消息覆盖) */
|
|
686
|
+
renameSession(id: string, title: string): Promise<void>;
|
|
687
|
+
/** 归档会话(仅标记,消息与 trace 不动) */
|
|
688
|
+
archiveSession(id: string): Promise<void>;
|
|
689
|
+
/** 取消归档 */
|
|
690
|
+
unarchiveSession(id: string): Promise<void>;
|
|
691
|
+
/** 重发语义:取该 user 消息文本重新 send(assistant 应答新起一轮;不重写历史) */
|
|
692
|
+
retry(messageId: string): Promise<void>;
|
|
693
|
+
/**
|
|
694
|
+
* 编辑重发:截断该 user 消息(含自身)之后的持久化历史,再用新文本重跑一轮。
|
|
695
|
+
* runtime session 句柄自带的对话历史不受影响(与 retry 同口径)。
|
|
696
|
+
*/
|
|
697
|
+
editAndResend(messageId: string, text: string): Promise<void>;
|
|
698
|
+
/** 从当前会话消息列表删除指定消息并持久化(消息不存在/无当前会话时静默跳过) */
|
|
699
|
+
deleteMessage(messageId: string): Promise<void>;
|
|
700
|
+
/**
|
|
701
|
+
* 驱动当前 session 的一轮 run。同 session 并发由 runtime session handle 内部
|
|
702
|
+
* 队列串行化(此处直接 await);UI 层应在 send 期间禁用输入。
|
|
703
|
+
* 附件按 `attachmentsRoot` 内的路径读回并构造 `LlmContentPart[]`(FR-11.2)。
|
|
704
|
+
*/
|
|
705
|
+
send(text: string, attachments?: readonly ChatAttachmentInput[]): Promise<void>;
|
|
706
|
+
/** 附件落盘根目录(composer 附件适配器写入,send 时读回) */
|
|
707
|
+
get attachmentsRoot(): string;
|
|
708
|
+
/** 取消进行中的 run(Composer Stop 按钮);run 未找到/已结束返回 false */
|
|
709
|
+
cancel(runId: string): boolean;
|
|
710
|
+
/**
|
|
711
|
+
* 释放引擎:取消进行中的 run、退订全部事件、丢弃装配缓存。
|
|
712
|
+
* 宿主重挂组件时用它收尾;只是换配置的话用 `reloadConfig()`,不要 dispose。
|
|
713
|
+
*/
|
|
714
|
+
dispose(): Promise<void>;
|
|
715
|
+
/** 列出 interrupted run(InterruptedBanner 数据源);版本不受支持的项带 unsupported 标记 */
|
|
716
|
+
listInterrupted(): Promise<RunSnapshotListEntry[]>;
|
|
717
|
+
/**
|
|
718
|
+
* 恢复 interrupted run:等待中的交互重新进入 bridge.pending(UI 复用 InteractionForm),
|
|
719
|
+
* 完成后与 send 同路径(assistant 消息持久化 + run-completed + trace 落盘)。
|
|
720
|
+
*/
|
|
721
|
+
resume(runId: string): Promise<void>;
|
|
722
|
+
/** 读取当前画像(FR-19.3:可见) @experimental */
|
|
723
|
+
readUserProfile(): Promise<UserProfile>;
|
|
724
|
+
/** 已记录的行为条数;设置面板用它告诉用户「清除」会删掉什么 @experimental */
|
|
725
|
+
countBehaviorRecords(): Promise<number>;
|
|
726
|
+
/** 删除单条画像结论(FR-19.3:可编辑可删除) @experimental */
|
|
727
|
+
deleteUserProfileEntry(id: string): Promise<UserProfile>;
|
|
728
|
+
/** 清除全部行为记录(FR-19.8)。与清除画像是两个独立操作 @experimental */
|
|
729
|
+
clearBehaviorRecords(): Promise<void>;
|
|
730
|
+
/** 清除提炼出的画像(FR-19.8) @experimental */
|
|
731
|
+
clearUserProfile(): Promise<void>;
|
|
732
|
+
/**
|
|
733
|
+
* 一并清除记录与画像,并销毁加密密钥(FR-19.8:关闭总开关时的「一并清除」)。
|
|
734
|
+
* 密钥留着就等于给残留密文留了一把能解开的钥匙。
|
|
601
735
|
* @experimental
|
|
602
736
|
*/
|
|
603
|
-
|
|
737
|
+
clearUserProfileData(): Promise<void>;
|
|
604
738
|
/**
|
|
605
|
-
*
|
|
739
|
+
* 手动提炼(FR-19.3)。与会话结束后的自动提炼同一条路径,
|
|
740
|
+
* 区别只在于这里的失败会抛给调用方——用户点了按钮就该看到结果。
|
|
606
741
|
* @experimental
|
|
607
742
|
*/
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
/**
|
|
616
|
-
|
|
617
|
-
/** 用户已手动重命名:后续 send 不再用首条消息覆盖标题 */
|
|
618
|
-
titleLocked?: boolean;
|
|
743
|
+
refineUserProfile(): Promise<UserProfile>;
|
|
744
|
+
/** 导出画像(FR-19.7)。`excludeIds` 来自导出前的审阅界面 @experimental */
|
|
745
|
+
exportUserProfile(excludeIds?: readonly string[]): Promise<UserProfileExport>;
|
|
746
|
+
/** 导入前的差异(FR-19.7):由 UI 展示并确认后才调用 `applyUserProfileImport` @experimental */
|
|
747
|
+
diffUserProfileImport(incoming: UserProfileExport): Promise<ReturnType<typeof diffUserProfile> & {
|
|
748
|
+
origin: string;
|
|
749
|
+
}>;
|
|
750
|
+
/** 确认后落库(FR-19.7) @experimental */
|
|
751
|
+
applyUserProfileImport(incoming: UserProfileExport): Promise<UserProfile>;
|
|
619
752
|
}
|
|
753
|
+
//#endregion
|
|
754
|
+
//#region src/core/types.d.ts
|
|
620
755
|
/**
|
|
621
|
-
*
|
|
756
|
+
* 治理 port 集合(F1):宿主把 `SkillStatePolicy` 的适配器交给 chatbot,
|
|
757
|
+
* 由它接到内部装配的 `WebSkillRuntime` 上。字段名与 `WebSkillRuntimeDeps` 逐个对齐,
|
|
758
|
+
* 不做重命名:中间多一层映射只会让宿主多记一套名字。
|
|
759
|
+
* @experimental
|
|
622
760
|
*/
|
|
623
|
-
interface
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
/** `
|
|
627
|
-
|
|
628
|
-
/**
|
|
629
|
-
|
|
761
|
+
interface ChatbotGovernancePorts {
|
|
762
|
+
/** `SkillStatePolicy.toSkillStateGuard()`:read/activate/execute 三入口拦截 */
|
|
763
|
+
skillStateGuard?: SkillStateGuard;
|
|
764
|
+
/** `SkillStatePolicy.toSkillIntegrityGuard(verify)`:激活期验签,失败即隔离 */
|
|
765
|
+
skillIntegrityGuard?: SkillIntegrityGuard;
|
|
766
|
+
/** `SkillStatePolicy.toSkillOutcomeReporter()`:执行失败计数,达阈值即隔离 */
|
|
767
|
+
skillOutcomeReporter?: SkillOutcomeReporter;
|
|
768
|
+
/** `SkillStatePolicy.catalogFilter()`:非 active 技能不进路由候选集 */
|
|
769
|
+
catalogFilter?: (entries: SkillCatalogEntry[]) => SkillCatalogEntry[] | Promise<SkillCatalogEntry[]>;
|
|
770
|
+
/**
|
|
771
|
+
* run 未激活任何技能时的钩子(如 `createMissHook`)。
|
|
772
|
+
*
|
|
773
|
+
* 开关存在 `GovernanceFacade.missHook`(属 console),chatbot 读不到也不该依赖它;
|
|
774
|
+
* 所以读开关是**宿主**的责任。宿主应传一个**每次触发时才读开关**的闭包,
|
|
775
|
+
* 而不是装配时把布尔值算好——`#assemble()` 不是每次 run 都跑,
|
|
776
|
+
* 算好了会导致「开着启动 → 中途关闭」不生效(AC-17.11)。
|
|
777
|
+
*/
|
|
778
|
+
onSkillMiss?: (input: {
|
|
779
|
+
prompt: string;
|
|
780
|
+
run: RuntimeRun;
|
|
781
|
+
}) => Promise<void>;
|
|
630
782
|
}
|
|
631
|
-
/**
|
|
632
|
-
type
|
|
633
|
-
type: '
|
|
634
|
-
runId: string;
|
|
635
|
-
} | {
|
|
636
|
-
type: 'message-delta';
|
|
783
|
+
/** 分配式交叉:直接写 `信封 & LifecycleEventInit` 会把联合压成一个对象,`phase` 的判别性就没了 */
|
|
784
|
+
type WithChatMeta<T> = T extends unknown ? {
|
|
785
|
+
type: 'lifecycle';
|
|
637
786
|
runId: string;
|
|
638
|
-
|
|
639
|
-
}
|
|
787
|
+
at: number;
|
|
788
|
+
} & T : never;
|
|
640
789
|
/**
|
|
641
|
-
*
|
|
642
|
-
*
|
|
643
|
-
*/
|
|
790
|
+
* 生命周期步进事件:`data` 随 `phase` 判别,与 runtime 的 `LifecycleEvent` 同一套契约。
|
|
791
|
+
* 旧的 `Record<string, unknown>` 等于没有契约:消费方只能硬编码键名。
|
|
792
|
+
*/
|
|
793
|
+
type LifecycleChatEvent = WithChatMeta<LifecycleEventInit>;
|
|
794
|
+
/**
|
|
795
|
+
* 交互渲染框架档位:native(React InteractionCard)/ a2ui(@a2ui/lit Lit 渲染)/
|
|
796
|
+
* openui(@openuidev/react-lang Renderer,ui-kit Library)/ vercel(@json-render/react
|
|
797
|
+
* Registry 渲染 catalog 声明树)
|
|
798
|
+
* @experimental
|
|
799
|
+
*/
|
|
800
|
+
type RendererKind = 'native' | 'a2ui' | 'openui' | 'vercel';
|
|
801
|
+
/** assistant 消息所属 run 的一次工具调用(终态:completed/failed) @stable */
|
|
802
|
+
interface ChatToolCall {
|
|
803
|
+
callId: string;
|
|
804
|
+
name: string;
|
|
805
|
+
status: 'completed' | 'failed';
|
|
806
|
+
/** 参数摘要(JSON 截断 100 字符;trace 重放无 args 时留空,卡片展开详情有则显示) */
|
|
807
|
+
args?: string;
|
|
808
|
+
/** 执行耗时(trace completed/failed 回填;live 由 started→终态计时) */
|
|
809
|
+
durationMs?: number;
|
|
810
|
+
/**
|
|
811
|
+
* 开始时刻(epoch ms,0.10.0 UI-UX5 #32)。与思考段按时间穿插需要共同时钟;
|
|
812
|
+
* 旧会话消息没有该字段时工具卡片保持原有相对顺序。
|
|
813
|
+
*/
|
|
814
|
+
at?: number;
|
|
815
|
+
/**
|
|
816
|
+
* failed 时的结构化错误码(如 `TOOL_NOT_ALLOWED`)。
|
|
817
|
+
* 「被策略拒绝」与「执行失败」在 UI 上是两回事,靠错误码区分而不是解析文案。
|
|
818
|
+
*/
|
|
819
|
+
errorCode?: string;
|
|
820
|
+
/** failed 时的错误说明(拒绝时即「被哪条策略拒绝」) */
|
|
821
|
+
errorMessage?: string;
|
|
822
|
+
}
|
|
823
|
+
/** 已落盘的待发送附件(composer 附件适配器产出) @experimental */
|
|
824
|
+
interface ChatAttachmentInput {
|
|
825
|
+
id: string;
|
|
826
|
+
name: string;
|
|
827
|
+
contentType: string;
|
|
828
|
+
/** 相对 `attachmentsRoot` 的路径 */
|
|
829
|
+
path: string;
|
|
830
|
+
size: number;
|
|
831
|
+
/** 注入模型的内容形态;决定 send 时读文本还是读二进制 */
|
|
832
|
+
kind: ChatAttachmentKind;
|
|
833
|
+
/** 图片经压缩时的原始字节数,供 UI 显示「3.2 MB → 1.8 MB」(FR-11.3) */
|
|
834
|
+
originalSize?: number;
|
|
835
|
+
}
|
|
836
|
+
/** 随消息持久化的附件元数据 @experimental */
|
|
837
|
+
type ChatAttachmentMeta = ChatAttachmentInput;
|
|
838
|
+
/**
|
|
839
|
+
* 归并后的显示相位。进行中通道与历史通道共用这一个结构:
|
|
840
|
+
* 各存一份正是「运行细节首轮后消失」的根因(需求 17 条目 10-6)。
|
|
841
|
+
* @experimental
|
|
842
|
+
*/
|
|
843
|
+
interface ChatRunPhase {
|
|
844
|
+
phase: RuntimePhase;
|
|
845
|
+
at: number;
|
|
846
|
+
/** 下一个步进到达时回填 */
|
|
847
|
+
endedAt?: number;
|
|
848
|
+
/** 由结构化 `LifecycleEvent.data` 派生的一句摘要 */
|
|
849
|
+
note?: string;
|
|
850
|
+
/** fail 相位的具体说明:`reason` 只有七种取值,说不出「哪个上限、哪个模型」 */
|
|
851
|
+
detail?: string;
|
|
852
|
+
}
|
|
853
|
+
/** 本轮发生的一次已提交交互(FR-17.8:提交后表单保留所填值) @experimental */
|
|
854
|
+
interface ChatInteractionRecord {
|
|
855
|
+
id: string;
|
|
856
|
+
request: InteractionRequest;
|
|
857
|
+
/** 提交时的表单值;文件类字段已在引擎侧脱敏 */
|
|
858
|
+
submittedValues?: unknown;
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* 该 run 内模型产出的一段思考正文(0.10.0 UI-UX5 #32)。
|
|
862
|
+
* 每次模型调用的思考算一段;随消息持久化,重开会话仍能看到。
|
|
863
|
+
* 模型不支持思考输出时整个数组缺省——不产空壳卡片。
|
|
864
|
+
* @experimental
|
|
865
|
+
*/
|
|
866
|
+
interface ChatThinking {
|
|
867
|
+
text: string;
|
|
868
|
+
/** 首个思考增量到达时刻(epoch ms;与工具卡片按时间穿插的排序依据) */
|
|
869
|
+
at: number;
|
|
870
|
+
}
|
|
871
|
+
/**
|
|
872
|
+
* 该 run 的大模型用量(0.10.0 UI-UX5 #47):随消息持久化,重开会话仍可见。
|
|
873
|
+
* 上游不回报 token 用量时整个字段缺省——不显示假数据。
|
|
874
|
+
* @experimental
|
|
875
|
+
*/
|
|
876
|
+
interface ChatTokenUsage {
|
|
877
|
+
inputTokens: number;
|
|
878
|
+
outputTokens: number;
|
|
879
|
+
/** 本 run 向大模型发送请求的次数(模型调用轮数) */
|
|
880
|
+
llmCalls: number;
|
|
881
|
+
}
|
|
882
|
+
/**
|
|
883
|
+
* 助手消息的有序内容段(分册 17 FR-17.1):文字与 surface / 结果块按生成顺序排列。
|
|
884
|
+
* 冗余记账——删掉本字段消息内容不缺失,只退化成「正文在上、扩展在下」(FR-17.11)。
|
|
885
|
+
* @experimental
|
|
886
|
+
*/
|
|
887
|
+
type ChatContentPart = {
|
|
888
|
+
type: 'text';
|
|
889
|
+
text: string;
|
|
890
|
+
at: number;
|
|
891
|
+
} | {
|
|
892
|
+
type: 'surface';
|
|
893
|
+
surfaceId: string;
|
|
894
|
+
at: number;
|
|
895
|
+
} | {
|
|
896
|
+
type: 'blocks';
|
|
897
|
+
at: number;
|
|
898
|
+
};
|
|
899
|
+
/** @stable */
|
|
900
|
+
interface ChatMessage {
|
|
901
|
+
id: string;
|
|
902
|
+
role: 'user' | 'assistant';
|
|
903
|
+
/**
|
|
904
|
+
* 消息正文。本 run 一个字也没产出时(例如模型开口前就被中止)**缺省**,
|
|
905
|
+
* 与「产出了空串」区分开——写空串会渲染出一个空白气泡(FR-20.4)。
|
|
906
|
+
*/
|
|
907
|
+
text?: string;
|
|
908
|
+
ts: string;
|
|
909
|
+
/** user 消息携带的附件(旧会话文件无该字段) */
|
|
910
|
+
attachments?: ChatAttachmentMeta[];
|
|
911
|
+
/**
|
|
912
|
+
* 随消息持久化的系统提示(例如「图片超出数量上限,未发送 X」,FR-11.3)。
|
|
913
|
+
* 放在消息里而不是 toast:toast 会消失,用户回头就查不到这次到底发了什么。
|
|
914
|
+
* @experimental
|
|
915
|
+
*/
|
|
916
|
+
notice?: string;
|
|
917
|
+
/** assistant 消息所属 run */
|
|
918
|
+
runId?: string;
|
|
919
|
+
/** 该 run 激活的技能(消息底部 badges) */
|
|
920
|
+
activeSkillNames?: string[];
|
|
921
|
+
/** 该 run 的工具调用序列(思维链工具行;按 trace 顺序) */
|
|
922
|
+
toolCalls?: ChatToolCall[];
|
|
923
|
+
/**
|
|
924
|
+
* 该 run 的思考段序列(0.10.0 UI-UX5 #32):渲染时与 `toolCalls` 按 `at` 归并,
|
|
925
|
+
* 多张思考卡片按时间穿插在工具卡片之间。
|
|
926
|
+
* @experimental
|
|
927
|
+
*/
|
|
928
|
+
thinkings?: ChatThinking[];
|
|
929
|
+
/**
|
|
930
|
+
* 该 run 的结果块(bridge.renderResult 的 blocks),随消息持久化。
|
|
931
|
+
* 当前 run 的块由 ResultBlocksPro 直读 bridge 渲染;历史消息按 blocks 逐条渲染(ResultBlockList)。
|
|
932
|
+
*/
|
|
933
|
+
blocks?: RenderBlock[];
|
|
934
|
+
/** The completed generative UI surfaces emitted by this run, retained for history replay. */
|
|
935
|
+
surfaces?: UiSpecSnapshot[];
|
|
936
|
+
/** 该 run 的待办清单终态(历史消息重放;未产生清单时缺省) */
|
|
937
|
+
todos?: TodoItem[];
|
|
938
|
+
/**
|
|
939
|
+
* 该 run 内发生的页面只读感知(需求 10 FR-10.5)。
|
|
940
|
+
* 随消息持久化而不只在运行中闪现——事后仍能查到「那一次它读了哪些区域」。
|
|
941
|
+
* @experimental
|
|
942
|
+
*/
|
|
943
|
+
perceptions?: PerceptionRecord[];
|
|
944
|
+
/**
|
|
945
|
+
* 该 run 的大模型用量(0.10.0 UI-UX5 #47):消息操作区图标右侧显示
|
|
946
|
+
* 输入输出合计 tokens(千分位)。上游不回报用量时缺省,不显示假数据。
|
|
947
|
+
* @experimental
|
|
948
|
+
*/
|
|
949
|
+
usage?: ChatTokenUsage;
|
|
950
|
+
/**
|
|
951
|
+
* 发出本轮请求的模型条目 id(`RuntimeConfig.llm.entries[].id`)。
|
|
952
|
+
* 写在消息上而不是会话上:切换模型只对后续消息生效,已有消息的归属不能被改写。
|
|
953
|
+
*/
|
|
954
|
+
model?: string;
|
|
955
|
+
/**
|
|
956
|
+
* 该轮的生命周期相位快照(FR-17.7)。不持久化它,live 状态一丢「运行细节」入口就消失,
|
|
957
|
+
* 表现为容器高度先减后增。
|
|
958
|
+
* @experimental
|
|
959
|
+
*/
|
|
960
|
+
phases?: ChatRunPhase[];
|
|
961
|
+
/**
|
|
962
|
+
* 该轮发生的交互及其终态(FR-17.8)。交互卡归属发起它的那条消息,
|
|
963
|
+
* 后续结果另开新消息,而不是就地改写原表单。
|
|
964
|
+
* @experimental
|
|
965
|
+
*/
|
|
966
|
+
interactions?: ChatInteractionRecord[];
|
|
967
|
+
/**
|
|
968
|
+
* 该轮提交的技能候选(FR-24.1)。数据来自 `$skillCandidate` 载荷,
|
|
969
|
+
* 不从模型复述的自然语言里解析。
|
|
970
|
+
* @experimental
|
|
971
|
+
*/
|
|
972
|
+
candidates?: SkillCandidateMarker[];
|
|
973
|
+
/**
|
|
974
|
+
* 文字与 surface / blocks 的生成顺序(分册 17)。缺省时按 0.11.0 的两段式渲染。
|
|
975
|
+
* @experimental
|
|
976
|
+
*/
|
|
977
|
+
contentParts?: ChatContentPart[];
|
|
978
|
+
}
|
|
979
|
+
/** @stable */
|
|
980
|
+
interface ChatSessionMeta {
|
|
981
|
+
id: string;
|
|
982
|
+
createdAt: string;
|
|
983
|
+
title?: string;
|
|
984
|
+
/** 归档会话:列表分区展示,不参与默认选中 */
|
|
985
|
+
archived?: boolean;
|
|
986
|
+
/** 用户已手动重命名:后续 send 不再用首条消息覆盖标题 */
|
|
987
|
+
titleLocked?: boolean;
|
|
988
|
+
}
|
|
989
|
+
/**
|
|
990
|
+
* 会话列表页:除了数据,还得告诉 UI「为什么是空的」(FR-21.4 / FR-21.11)。 @experimental
|
|
991
|
+
*/
|
|
992
|
+
interface ChatSessionListResult {
|
|
993
|
+
items: ChatSessionMeta[];
|
|
994
|
+
nextCursor?: string;
|
|
995
|
+
/** `'ok'` = 正常列举;`'missing-root'` = 会话目录不存在(多半是 chatRoot 配错) */
|
|
996
|
+
source: 'ok' | 'missing-root';
|
|
997
|
+
/** 读不动而被跳过的会话文件名 */
|
|
998
|
+
skipped: readonly string[];
|
|
999
|
+
}
|
|
1000
|
+
/** @stable */
|
|
1001
|
+
type ChatEvent = {
|
|
1002
|
+
type: 'run-started';
|
|
1003
|
+
runId: string;
|
|
1004
|
+
} | {
|
|
1005
|
+
type: 'message-delta';
|
|
1006
|
+
runId: string;
|
|
1007
|
+
delta: string;
|
|
1008
|
+
} |
|
|
1009
|
+
/**
|
|
1010
|
+
* 思考增量(0.10.0 UI-UX5 #32):runtime 的 thinking-delta 原样转发。
|
|
1011
|
+
* 模型不产出思考时一个事件也没有;UI 据事件有无决定渲不渲染思考卡片。
|
|
1012
|
+
*/
|
|
644
1013
|
{
|
|
645
1014
|
type: 'thinking-delta';
|
|
646
1015
|
runId: string;
|
|
@@ -803,287 +1172,27 @@ interface ChatbotConfig {
|
|
|
803
1172
|
* 依赖表,每次渲染新建一个箭头函数会把整个引擎重建掉。
|
|
804
1173
|
*/
|
|
805
1174
|
fetchData?: (sourceId: string, params?: Record<string, unknown>) => Promise<unknown>;
|
|
806
|
-
}
|
|
807
|
-
//#endregion
|
|
808
|
-
//#region src/core/hostAdapter.d.ts
|
|
809
|
-
/**
|
|
810
|
-
* 宿主装配口:chatbot 不感知环境(浏览器/Node),全部能力经此注入。
|
|
811
|
-
* 页面动态技能来源同时是外部工具来源与外部技能提供者(同一对象两个 port)。
|
|
812
|
-
* LLM 配置不在这里——它统一由 `RuntimeConfigStore` 承载(0.5.0 起)。
|
|
813
|
-
* @stable
|
|
814
|
-
*/
|
|
815
|
-
interface ChatbotHostAdapter {
|
|
816
|
-
storage: FileSystemProvider;
|
|
817
|
-
skillRoots: string[];
|
|
818
|
-
pageSkillSource?: ExternalToolSource & ExternalSkillProvider;
|
|
819
|
-
navigation: {
|
|
820
|
-
openConsole(): void;
|
|
821
|
-
/** 跳 console Traces 面板并定位该 run(v1.1;缺省时消息不渲染 View trace 入口) */
|
|
822
|
-
openConsoleTrace?(runId: string): void;
|
|
823
|
-
/** 打开治理面的审批队列并定位该候选(FR-24.2);宿主未接治理面时不提供,入口随之不渲染 */
|
|
824
|
-
openConsoleCandidate?(candidateId: string): void;
|
|
825
|
-
};
|
|
826
|
-
/** 缺省 BrowserWorkerScriptExecutor(@webskill/browser);Node 宿主可注入自己的执行器 */
|
|
827
|
-
executor?: ScriptExecutor;
|
|
828
1175
|
/**
|
|
829
|
-
*
|
|
830
|
-
*
|
|
831
|
-
*
|
|
832
|
-
* @experimental
|
|
833
|
-
*/
|
|
834
|
-
pagePerception?: PagePerceptionPolicy;
|
|
835
|
-
/**
|
|
836
|
-
* 页面操作能力(需求 23)。**不注入即完全关闭**,与 `pagePerception` 分开:
|
|
837
|
-
* 可读不等于可操作。同样只能在这里注入——给终端用户一个「打开代操作」的开关
|
|
838
|
-
* 等于把安全边界交给最不了解它的人。
|
|
839
|
-
* @experimental
|
|
840
|
-
*/
|
|
841
|
-
pageActions?: PageActionPolicy;
|
|
842
|
-
/**
|
|
843
|
-
* 读页面链接指向的文档(分册 22)。实现住在 `@webskill/browser`,
|
|
844
|
-
* 而 chatbot 不依赖它 —— 与 `pagePerception` 同一条装配规矩:宿主注入。
|
|
845
|
-
* 不注入即 `read_linked_document` 不注册。
|
|
846
|
-
*/
|
|
847
|
-
linkedDocuments?: LinkedDocumentReader;
|
|
848
|
-
/** docx → 文本(`extractDocxText`);不注入即 Word 文档明确报「本环境不支持」 */
|
|
849
|
-
docxExtractor?: DocxTextExtractor;
|
|
850
|
-
/** xlsx → 文本(`extractXlsxText`);不注入即 Excel 工作簿明确报「本环境不支持」 */
|
|
851
|
-
xlsxExtractor?: XlsxTextExtractor;
|
|
852
|
-
/**
|
|
853
|
-
* PDF → 文本;**只用于直传被端点拒后的回退**(0.13.0 FR-22.1)。
|
|
854
|
-
* PDF 仍然默认直传,能读的端点拿到的还是原件;不注入即没有回退能力。
|
|
855
|
-
*/
|
|
856
|
-
pdfExtractor?: PdfTextExtractor;
|
|
857
|
-
/** 文档读取留痕出口(FR-22.6) */
|
|
858
|
-
documentAudit?: {
|
|
859
|
-
append(event: {
|
|
860
|
-
type: string;
|
|
861
|
-
target: string;
|
|
862
|
-
data?: Record<string, unknown>;
|
|
863
|
-
}): Promise<unknown>;
|
|
864
|
-
};
|
|
865
|
-
}
|
|
866
|
-
//#endregion
|
|
867
|
-
//#region src/core/chatEngine.d.ts
|
|
868
|
-
/**
|
|
869
|
-
* 条目能否真的发请求:云端要有端点或密钥,浏览器内置两者都不需要。
|
|
870
|
-
*
|
|
871
|
-
* 导出给 UI:选择器不用同一份判据的话,用户能选中一个空配置条目,
|
|
872
|
-
* 而引擎静默回退到另一条——界面说在用 A、实际跑的是 B(UI-UX8 D1)。
|
|
873
|
-
* @experimental
|
|
874
|
-
*/
|
|
875
|
-
declare const isLlmEntryUsable: (entry: RuntimeLlmEntry) => boolean;
|
|
876
|
-
/**
|
|
877
|
-
* 选中条目 → 默认条目 → 首条;命中不可用条目时**回退到下一个可用条目**
|
|
878
|
-
* (0.10.0 复核:选中项失效时宁可静默换用可用模型,也不能把 UI 锁死成
|
|
879
|
-
* 「未配置」死胡同——引擎与 UI 共用同一判据,两边必须同进退)。
|
|
880
|
-
* 全部不可用才 undefined(引擎走内置演示)。
|
|
881
|
-
*
|
|
882
|
-
* 导出给 UI 复用同一判据:composer 的「未配置模型」引导判定必须与引擎的
|
|
883
|
-
* 实际挑选结果一致,否则会出现「UI 说有模型、引擎却走演示档」的错位(0.10.0 UI-UX5 #49-1)。
|
|
884
|
-
* @experimental
|
|
885
|
-
*/
|
|
886
|
-
declare function pickUsableLlmEntry(entries: readonly RuntimeLlmEntry[], defaultId: string | undefined, selectedId: string | undefined): RuntimeLlmEntry | undefined;
|
|
887
|
-
/** 默认沙箱执行器的构造参数(adapter.executor 未注入时;executorFactory 替换点可见同一形状) @stable */
|
|
888
|
-
interface SandboxExecutorDeps {
|
|
889
|
-
fs: FileSystemProvider;
|
|
890
|
-
sandbox?: SandboxMode;
|
|
891
|
-
networkPolicy?: NetworkPolicy;
|
|
892
|
-
capabilities?: BridgeCapabilities;
|
|
893
|
-
approvalScope?: ApprovalScope;
|
|
894
|
-
uiBridge?: UiBridge;
|
|
895
|
-
/** 缺省时 `.ts` 脚本按 `TOOL_UNSUPPORTED` 拒绝 */
|
|
896
|
-
typescript?: TypeScriptSupportOptions;
|
|
897
|
-
}
|
|
898
|
-
/**
|
|
899
|
-
* 装配时(而非执行时)把 `sandbox.typescript` 转成执行器参数,让配置错误早暴露。
|
|
900
|
-
* 只对绝对 URL 走 `RemoteUrlPolicy`:同源相对路径与打包器 specifier 不是出站请求。
|
|
901
|
-
*/
|
|
902
|
-
/**
|
|
903
|
-
* 由 `RuntimeConfig` 装出沙箱执行器依赖。
|
|
904
|
-
*
|
|
905
|
-
* 主链路与**评估链路**共用这一处(T-17-H):此前评估侧只传 `fs`,
|
|
906
|
-
* 于是评估里跑的技能不受沙箱、网络策略、能力与授权范围约束——
|
|
907
|
-
* 那比「.ts 跑不了」严重得多(设计 17 §1.1a)。
|
|
908
|
-
*
|
|
909
|
-
* @experimental
|
|
910
|
-
*/
|
|
911
|
-
declare function sandboxExecutorDeps(fs: FileSystemProvider, rc?: RuntimeConfig, uiBridge?: SandboxExecutorDeps['uiBridge']): SandboxExecutorDeps;
|
|
912
|
-
/** @stable */
|
|
913
|
-
interface ChatEngineOptions {
|
|
914
|
-
llm?: LlmClient;
|
|
915
|
-
loopConfig?: AgentLoopConfig;
|
|
916
|
-
chatRoot?: string;
|
|
917
|
-
/** 运行环境配置存储(P2):#ensureReady 装配时 load()(默认值兜底)并按映射应用 */
|
|
918
|
-
runtimeConfig?: RuntimeConfigStore;
|
|
919
|
-
/** 初始渲染框架档(默认 'native';运行中可 setRenderer 热切换) */
|
|
920
|
-
renderer?: RendererKind;
|
|
921
|
-
/**
|
|
922
|
-
* 注入 `render_ui` 工具,让模型面向 AI Component Catalog 生成声明式 UI。
|
|
923
|
-
*
|
|
924
|
-
* 注入了 `runtimeConfig` 时**以 `RuntimeConfig.agentCapabilities.generativeUi` 为准**,
|
|
925
|
-
* 本字段只在未接配置存储的宿主上生效(否则设置面板里的开关点了不算数)。
|
|
926
|
-
*/
|
|
927
|
-
generativeUi?: boolean;
|
|
928
|
-
/** 沙箱执行器替换点(测试注入 spy 断言构造参数;缺省 BrowserWorkerScriptExecutor) */
|
|
929
|
-
executorFactory?: (deps: SandboxExecutorDeps) => ScriptExecutor;
|
|
930
|
-
/**
|
|
931
|
-
* 宿主声明的数据源取数入口(分册 16)。不注入即脚本上下文没有 `fetchData` 这个键。
|
|
1176
|
+
* 宿主声明的数据源清单(0.14.0 分册 19):透传给 `ChatEngineOptions.dataSources`。
|
|
1177
|
+
* 用 `DataSourcePolicy.publicSources` 取,不要改传 `sources`——后者带 `target`,
|
|
1178
|
+
* 结构子类型让这个赋值的类型检查能过,接口地址就静默进了模型上下文。
|
|
932
1179
|
*
|
|
933
|
-
*
|
|
934
|
-
*
|
|
935
|
-
* 能力开关 `sandbox.capabilities.fetchData` 缺省关,注入了也还要宿主在配置里打开。
|
|
936
|
-
*/
|
|
937
|
-
fetchData?: (sourceId: string, params?: Record<string, unknown>) => Promise<unknown>;
|
|
938
|
-
/**
|
|
939
|
-
* 会话落盘替换点(缺省 `FsSessionStore`,落在 `<chatRoot>/sessions`)。
|
|
940
|
-
* 宕主换自己的实现(如 IndexedDB)与测试统计端口读写量都走这里。
|
|
1180
|
+
* **必须是稳定引用**(模块级或 `useMemo`):同 `fetchData`,它进 `ChatEngine` 的依赖表。
|
|
1181
|
+
* 源清单随用户配置变动的宿主传函数形式,引擎在每次激活时求值,改配置无须重建引擎。
|
|
941
1182
|
*/
|
|
942
|
-
|
|
1183
|
+
dataSources?: readonly DataSourceInfo[] | (() => readonly DataSourceInfo[]);
|
|
943
1184
|
/**
|
|
944
|
-
*
|
|
945
|
-
* 不注入即不挂钩子(与 0.0.2 行为一致)。
|
|
946
|
-
*/
|
|
947
|
-
hooks?: HookRunner;
|
|
948
|
-
/**
|
|
949
|
-
* 治理 port 注入(F1):把 `SkillStatePolicy` 的三个适配器接到本引擎装配的 runtime 上。
|
|
950
|
-
*
|
|
951
|
-
* 不注入即完全关闭,行为与 0.0.2 一致。装配点必须在宿主:chatbot 不能依赖
|
|
952
|
-
* `@webskill/governance`(它是可选治理层,且要求宿主提供治理根与审计存储)。
|
|
1185
|
+
* 沙箱执行器替换点(分册 12):透传给 `ChatEngineOptions.executorFactory`。
|
|
953
1186
|
*
|
|
954
|
-
*
|
|
955
|
-
*
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
/**
|
|
959
|
-
* 技能自动生成的候选收货端(需求 12 号)。与 `governance` 同理,装配点在宿主:
|
|
960
|
-
* `@webskill/governance` 的 `createCandidateSink()` 是现成实现。
|
|
1187
|
+
* 需要自定义执行器的宿主**必须走这里,而不是 `ChatbotHostAdapter.executor`**:
|
|
1188
|
+
* 后者是一个构造期就定死的实例,装配时会整个跳过 `RuntimeConfig.sandbox` 映射,
|
|
1189
|
+
* 于是设置面板里的能力开关、网络策略、TypeScript 与授权范围全部点了不算数。
|
|
1190
|
+
* 本替换点拿到的 `deps` 已由引擎按当前配置算好,宿主只需覆盖自己要换的那几项。
|
|
961
1191
|
*
|
|
962
|
-
*
|
|
963
|
-
* 开关开但未注入本端口时,工具会把 `SKILL_GENERATION_DISABLED` 回给模型。
|
|
964
|
-
*/
|
|
965
|
-
skillCandidates?: SkillCandidateSink;
|
|
966
|
-
}
|
|
967
|
-
/**
|
|
968
|
-
* 对话框引擎:装配 WebSkillRuntime + 会话持久化 + 事件分发。
|
|
969
|
-
* RuntimeConfig 的 load() 是异步的,runtime 在首次 send 前懒装配(#ensureReady)。
|
|
970
|
-
* @stable
|
|
971
|
-
*/
|
|
972
|
-
declare class ChatEngine {
|
|
973
|
-
#private;
|
|
974
|
-
readonly bridge: ReactBridgeState;
|
|
975
|
-
constructor(adapter: ChatbotHostAdapter, options?: ChatEngineOptions);
|
|
976
|
-
/** 当前待办清单快照(宿主可直读;实时更新订阅 `todo-changed` 事件) */
|
|
977
|
-
get todos(): readonly TodoItem[];
|
|
978
|
-
/** 当前渲染框架档 */
|
|
979
|
-
get renderer(): RendererKind;
|
|
980
|
-
/** 当前会话选中的模型条目 id;未显式切换过时为 undefined(走 `RuntimeConfig.llm.defaultId`) */
|
|
981
|
-
get modelId(): string | undefined;
|
|
982
|
-
/**
|
|
983
|
-
* 切换本会话后续消息使用的模型条目(需求 4)。传 `undefined` 回到配置里的默认项。
|
|
984
|
-
* 重装配 runtime 以换掉客户端;已落盘的消息不受影响。
|
|
985
|
-
*/
|
|
986
|
-
setModel(entryId: string | undefined): void;
|
|
987
|
-
/** 会话文件所在目录:「存储未初始化」提示要把路径写给用户看 @experimental */
|
|
988
|
-
get sessionsRoot(): string;
|
|
989
|
-
/** 渲染框架热切换:复合桥按档分发,无需重装配 runtime(会话句柄保留) */
|
|
990
|
-
setRenderer(renderer: RendererKind): void;
|
|
991
|
-
/** 非 native 三档共用的交互通道(Chatbot 的 SpecInteraction 订阅/attach;core 只产出 catalog 节点树) */
|
|
992
|
-
get interactionChannel(): SpecInteractionChannel;
|
|
993
|
-
/** 探测 @a2ui/lit 是否安装(Appearance/设置区 A2UI 档置灰判定) */
|
|
994
|
-
probeA2uiAvailability(): Promise<boolean>;
|
|
995
|
-
onEvent(listener: (event: ChatEvent) => void): () => void;
|
|
996
|
-
/**
|
|
997
|
-
* 配置源变更后调用(LLM 设置 / RuntimeConfigStore 内容变化):丢弃缓存的
|
|
998
|
-
* runtime/llm/会话句柄,下次 send 重新装配(RuntimeConfig 重新 load() 应用)
|
|
999
|
-
*/
|
|
1000
|
-
reloadConfig(): void;
|
|
1001
|
-
/**
|
|
1002
|
-
* 会话列表页。归档会话也返回:UI 自己分区展示。
|
|
1003
|
-
* `limit` 不给默认值——缺省属于 `SessionStore` 实现,在这里兜底就等于只下推了一半。
|
|
1004
|
-
*/
|
|
1005
|
-
listSessions(options?: PageQuery): Promise<ChatSessionListResult>;
|
|
1006
|
-
/** `title` 缺省时会话先无标题,首条消息发出时再按内容补(FR-21.8) */
|
|
1007
|
-
createSession(options?: {
|
|
1008
|
-
title?: string;
|
|
1009
|
-
}): Promise<ChatSessionMeta>;
|
|
1010
|
-
/**
|
|
1011
|
-
* 选中会话并取**最新**一页历史(页内时间升序)。
|
|
1012
|
-
* 返回全量 `ChatMessage[]` 的旧签名已移除:长会话下它强迫每个调用方拿全量。
|
|
1013
|
-
*/
|
|
1014
|
-
selectSession(id: string, options?: PageQuery): Promise<Page<ChatMessage>>;
|
|
1015
|
-
/** 向历史方向再取一页;`cursor` 只能来自上一页的 `nextCursor` */
|
|
1016
|
-
loadMoreMessages(cursor: string, options?: {
|
|
1017
|
-
limit?: number;
|
|
1018
|
-
}): Promise<Page<ChatMessage>>;
|
|
1019
|
-
deleteSession(id: string): Promise<void>;
|
|
1020
|
-
/** 重命名会话:写入 title 并锁定(后续 send 不再用首条消息覆盖) */
|
|
1021
|
-
renameSession(id: string, title: string): Promise<void>;
|
|
1022
|
-
/** 归档会话(仅标记,消息与 trace 不动) */
|
|
1023
|
-
archiveSession(id: string): Promise<void>;
|
|
1024
|
-
/** 取消归档 */
|
|
1025
|
-
unarchiveSession(id: string): Promise<void>;
|
|
1026
|
-
/** 重发语义:取该 user 消息文本重新 send(assistant 应答新起一轮;不重写历史) */
|
|
1027
|
-
retry(messageId: string): Promise<void>;
|
|
1028
|
-
/**
|
|
1029
|
-
* 编辑重发:截断该 user 消息(含自身)之后的持久化历史,再用新文本重跑一轮。
|
|
1030
|
-
* runtime session 句柄自带的对话历史不受影响(与 retry 同口径)。
|
|
1031
|
-
*/
|
|
1032
|
-
editAndResend(messageId: string, text: string): Promise<void>;
|
|
1033
|
-
/** 从当前会话消息列表删除指定消息并持久化(消息不存在/无当前会话时静默跳过) */
|
|
1034
|
-
deleteMessage(messageId: string): Promise<void>;
|
|
1035
|
-
/**
|
|
1036
|
-
* 驱动当前 session 的一轮 run。同 session 并发由 runtime session handle 内部
|
|
1037
|
-
* 队列串行化(此处直接 await);UI 层应在 send 期间禁用输入。
|
|
1038
|
-
* 附件按 `attachmentsRoot` 内的路径读回并构造 `LlmContentPart[]`(FR-11.2)。
|
|
1039
|
-
*/
|
|
1040
|
-
send(text: string, attachments?: readonly ChatAttachmentInput[]): Promise<void>;
|
|
1041
|
-
/** 附件落盘根目录(composer 附件适配器写入,send 时读回) */
|
|
1042
|
-
get attachmentsRoot(): string;
|
|
1043
|
-
/** 取消进行中的 run(Composer Stop 按钮);run 未找到/已结束返回 false */
|
|
1044
|
-
cancel(runId: string): boolean;
|
|
1045
|
-
/**
|
|
1046
|
-
* 释放引擎:取消进行中的 run、退订全部事件、丢弃装配缓存。
|
|
1047
|
-
* 宿主重挂组件时用它收尾;只是换配置的话用 `reloadConfig()`,不要 dispose。
|
|
1048
|
-
*/
|
|
1049
|
-
dispose(): Promise<void>;
|
|
1050
|
-
/** 列出 interrupted run(InterruptedBanner 数据源);版本不受支持的项带 unsupported 标记 */
|
|
1051
|
-
listInterrupted(): Promise<RunSnapshotListEntry[]>;
|
|
1052
|
-
/**
|
|
1053
|
-
* 恢复 interrupted run:等待中的交互重新进入 bridge.pending(UI 复用 InteractionForm),
|
|
1054
|
-
* 完成后与 send 同路径(assistant 消息持久化 + run-completed + trace 落盘)。
|
|
1055
|
-
*/
|
|
1056
|
-
resume(runId: string): Promise<void>;
|
|
1057
|
-
/** 读取当前画像(FR-19.3:可见) @experimental */
|
|
1058
|
-
readUserProfile(): Promise<UserProfile>;
|
|
1059
|
-
/** 已记录的行为条数;设置面板用它告诉用户「清除」会删掉什么 @experimental */
|
|
1060
|
-
countBehaviorRecords(): Promise<number>;
|
|
1061
|
-
/** 删除单条画像结论(FR-19.3:可编辑可删除) @experimental */
|
|
1062
|
-
deleteUserProfileEntry(id: string): Promise<UserProfile>;
|
|
1063
|
-
/** 清除全部行为记录(FR-19.8)。与清除画像是两个独立操作 @experimental */
|
|
1064
|
-
clearBehaviorRecords(): Promise<void>;
|
|
1065
|
-
/** 清除提炼出的画像(FR-19.8) @experimental */
|
|
1066
|
-
clearUserProfile(): Promise<void>;
|
|
1067
|
-
/**
|
|
1068
|
-
* 一并清除记录与画像,并销毁加密密钥(FR-19.8:关闭总开关时的「一并清除」)。
|
|
1069
|
-
* 密钥留着就等于给残留密文留了一把能解开的钥匙。
|
|
1192
|
+
* **必须是稳定引用**(模块级或 `useMemo`):同 `fetchData`,它进 `ChatEngine` 的依赖表。
|
|
1070
1193
|
* @experimental
|
|
1071
1194
|
*/
|
|
1072
|
-
|
|
1073
|
-
/**
|
|
1074
|
-
* 手动提炼(FR-19.3)。与会话结束后的自动提炼同一条路径,
|
|
1075
|
-
* 区别只在于这里的失败会抛给调用方——用户点了按钮就该看到结果。
|
|
1076
|
-
* @experimental
|
|
1077
|
-
*/
|
|
1078
|
-
refineUserProfile(): Promise<UserProfile>;
|
|
1079
|
-
/** 导出画像(FR-19.7)。`excludeIds` 来自导出前的审阅界面 @experimental */
|
|
1080
|
-
exportUserProfile(excludeIds?: readonly string[]): Promise<UserProfileExport>;
|
|
1081
|
-
/** 导入前的差异(FR-19.7):由 UI 展示并确认后才调用 `applyUserProfileImport` @experimental */
|
|
1082
|
-
diffUserProfileImport(incoming: UserProfileExport): Promise<ReturnType<typeof diffUserProfile> & {
|
|
1083
|
-
origin: string;
|
|
1084
|
-
}>;
|
|
1085
|
-
/** 确认后落库(FR-19.7) @experimental */
|
|
1086
|
-
applyUserProfileImport(incoming: UserProfileExport): Promise<UserProfile>;
|
|
1195
|
+
executorFactory?: (deps: SandboxExecutorDeps) => ScriptExecutor;
|
|
1087
1196
|
}
|
|
1088
1197
|
//#endregion
|
|
1089
1198
|
//#region src/core/interactionBridge.d.ts
|
|
@@ -1238,7 +1347,6 @@ declare const chatbotDictionary: {
|
|
|
1238
1347
|
'welcome.capability.transparency.title': string;
|
|
1239
1348
|
'welcome.capability.transparency.description': string;
|
|
1240
1349
|
'welcome.quickPrompts': string;
|
|
1241
|
-
'welcome.dynamicPrompts': string;
|
|
1242
1350
|
'message.copy': string;
|
|
1243
1351
|
'message.copied': string;
|
|
1244
1352
|
'message.retry': string;
|
|
@@ -1324,11 +1432,20 @@ declare const chatbotDictionary: {
|
|
|
1324
1432
|
'interaction.pageAction.click': string;
|
|
1325
1433
|
'interaction.pageAction.fill': string;
|
|
1326
1434
|
'interaction.pageAction.submit': string;
|
|
1435
|
+
'interaction.pageAction.select': string;
|
|
1436
|
+
'interaction.pageAction.set': string;
|
|
1437
|
+
'interaction.pageAction.attach': string;
|
|
1327
1438
|
'interaction.pageAction.role.click': string;
|
|
1328
1439
|
'interaction.pageAction.role.fill': string;
|
|
1329
1440
|
'interaction.pageAction.role.submit': string;
|
|
1441
|
+
'interaction.pageAction.role.select': string;
|
|
1442
|
+
'interaction.pageAction.role.set': string;
|
|
1443
|
+
'interaction.pageAction.role.attach': string;
|
|
1444
|
+
'interaction.pageAction.remember': string;
|
|
1330
1445
|
'interaction.pageAction.frame': string;
|
|
1331
1446
|
'interaction.pageAction.elevated': string;
|
|
1447
|
+
'interaction.downloadedFile.file': string;
|
|
1448
|
+
'interaction.downloadedFile.remember': string;
|
|
1332
1449
|
'interaction.traceEvidence.title': string;
|
|
1333
1450
|
'interaction.traceEvidence.columnDraft': string;
|
|
1334
1451
|
'interaction.traceEvidence.columnTrace': string;
|
|
@@ -1591,7 +1708,6 @@ declare const chatbotDictionary: {
|
|
|
1591
1708
|
'welcome.capability.transparency.title': string;
|
|
1592
1709
|
'welcome.capability.transparency.description': string;
|
|
1593
1710
|
'welcome.quickPrompts': string;
|
|
1594
|
-
'welcome.dynamicPrompts': string;
|
|
1595
1711
|
'message.copy': string;
|
|
1596
1712
|
'message.copied': string;
|
|
1597
1713
|
'message.edit': string;
|
|
@@ -1677,11 +1793,20 @@ declare const chatbotDictionary: {
|
|
|
1677
1793
|
'interaction.pageAction.click': string;
|
|
1678
1794
|
'interaction.pageAction.fill': string;
|
|
1679
1795
|
'interaction.pageAction.submit': string;
|
|
1796
|
+
'interaction.pageAction.select': string;
|
|
1797
|
+
'interaction.pageAction.set': string;
|
|
1798
|
+
'interaction.pageAction.attach': string;
|
|
1680
1799
|
'interaction.pageAction.role.click': string;
|
|
1681
1800
|
'interaction.pageAction.role.fill': string;
|
|
1682
1801
|
'interaction.pageAction.role.submit': string;
|
|
1802
|
+
'interaction.pageAction.role.select': string;
|
|
1803
|
+
'interaction.pageAction.role.set': string;
|
|
1804
|
+
'interaction.pageAction.role.attach': string;
|
|
1805
|
+
'interaction.pageAction.remember': string;
|
|
1683
1806
|
'interaction.pageAction.frame': string;
|
|
1684
1807
|
'interaction.pageAction.elevated': string;
|
|
1808
|
+
'interaction.downloadedFile.file': string;
|
|
1809
|
+
'interaction.downloadedFile.remember': string;
|
|
1685
1810
|
'interaction.traceEvidence.title': string;
|
|
1686
1811
|
'interaction.traceEvidence.columnDraft': string;
|
|
1687
1812
|
'interaction.traceEvidence.columnTrace': string;
|
|
@@ -1947,7 +2072,6 @@ declare const useT: () => TranslateFn<{
|
|
|
1947
2072
|
'welcome.capability.transparency.title': string;
|
|
1948
2073
|
'welcome.capability.transparency.description': string;
|
|
1949
2074
|
'welcome.quickPrompts': string;
|
|
1950
|
-
'welcome.dynamicPrompts': string;
|
|
1951
2075
|
'message.copy': string;
|
|
1952
2076
|
'message.copied': string;
|
|
1953
2077
|
'message.retry': string;
|
|
@@ -2033,11 +2157,20 @@ declare const useT: () => TranslateFn<{
|
|
|
2033
2157
|
'interaction.pageAction.click': string;
|
|
2034
2158
|
'interaction.pageAction.fill': string;
|
|
2035
2159
|
'interaction.pageAction.submit': string;
|
|
2160
|
+
'interaction.pageAction.select': string;
|
|
2161
|
+
'interaction.pageAction.set': string;
|
|
2162
|
+
'interaction.pageAction.attach': string;
|
|
2036
2163
|
'interaction.pageAction.role.click': string;
|
|
2037
2164
|
'interaction.pageAction.role.fill': string;
|
|
2038
2165
|
'interaction.pageAction.role.submit': string;
|
|
2166
|
+
'interaction.pageAction.role.select': string;
|
|
2167
|
+
'interaction.pageAction.role.set': string;
|
|
2168
|
+
'interaction.pageAction.role.attach': string;
|
|
2169
|
+
'interaction.pageAction.remember': string;
|
|
2039
2170
|
'interaction.pageAction.frame': string;
|
|
2040
2171
|
'interaction.pageAction.elevated': string;
|
|
2172
|
+
'interaction.downloadedFile.file': string;
|
|
2173
|
+
'interaction.downloadedFile.remember': string;
|
|
2041
2174
|
'interaction.traceEvidence.title': string;
|
|
2042
2175
|
'interaction.traceEvidence.columnDraft': string;
|
|
2043
2176
|
'interaction.traceEvidence.columnTrace': string;
|
|
@@ -2300,7 +2433,6 @@ declare const useT: () => TranslateFn<{
|
|
|
2300
2433
|
'welcome.capability.transparency.title': string;
|
|
2301
2434
|
'welcome.capability.transparency.description': string;
|
|
2302
2435
|
'welcome.quickPrompts': string;
|
|
2303
|
-
'welcome.dynamicPrompts': string;
|
|
2304
2436
|
'message.copy': string;
|
|
2305
2437
|
'message.copied': string;
|
|
2306
2438
|
'message.edit': string;
|
|
@@ -2386,11 +2518,20 @@ declare const useT: () => TranslateFn<{
|
|
|
2386
2518
|
'interaction.pageAction.click': string;
|
|
2387
2519
|
'interaction.pageAction.fill': string;
|
|
2388
2520
|
'interaction.pageAction.submit': string;
|
|
2521
|
+
'interaction.pageAction.select': string;
|
|
2522
|
+
'interaction.pageAction.set': string;
|
|
2523
|
+
'interaction.pageAction.attach': string;
|
|
2389
2524
|
'interaction.pageAction.role.click': string;
|
|
2390
2525
|
'interaction.pageAction.role.fill': string;
|
|
2391
2526
|
'interaction.pageAction.role.submit': string;
|
|
2527
|
+
'interaction.pageAction.role.select': string;
|
|
2528
|
+
'interaction.pageAction.role.set': string;
|
|
2529
|
+
'interaction.pageAction.role.attach': string;
|
|
2530
|
+
'interaction.pageAction.remember': string;
|
|
2392
2531
|
'interaction.pageAction.frame': string;
|
|
2393
2532
|
'interaction.pageAction.elevated': string;
|
|
2533
|
+
'interaction.downloadedFile.file': string;
|
|
2534
|
+
'interaction.downloadedFile.remember': string;
|
|
2394
2535
|
'interaction.traceEvidence.title': string;
|
|
2395
2536
|
'interaction.traceEvidence.columnDraft': string;
|
|
2396
2537
|
'interaction.traceEvidence.columnTrace': string;
|
|
@@ -2878,6 +3019,6 @@ declare function ErrorCard({ code, message, loopLimits, onOpenSettings, onDismis
|
|
|
2878
3019
|
* Version of the published `@webskill/chatbot` package, injected at build time.
|
|
2879
3020
|
* @stable
|
|
2880
3021
|
*/
|
|
2881
|
-
declare const CHATBOT_VERSION = "0.
|
|
3022
|
+
declare const CHATBOT_VERSION = "0.11.0";
|
|
2882
3023
|
//#endregion
|
|
2883
3024
|
export { A2uiSurfaceHost, type A2uiSurfaceHostProps, A2uiSurfaceSnapshotHost, type A2uiSurfaceSnapshotHostProps, type AppearanceChange, CHATBOT_VERSION, type ChatAttachmentInput, type ChatAttachmentMeta, type ChatContentPart, ChatEngine, type ChatEngineOptions, type ChatEvent, type ChatInteractionRecord, type ChatLayout, type ChatMessage, type ChatRunPhase, type ChatSessionListResult, type ChatSessionMeta, type ChatTheme, type ChatThinking, type ChatTokenUsage, type ChatToolCall, Chatbot, type ChatbotConfig, type ChatbotGovernancePorts, type ChatbotHostAdapter, type ChatbotProps, CompositeUiBridge, type CompositeUiBridgeDeps, DEFAULT_RENDERER_CAPABILITIES, DEFAULT_RUNTIME_CONFIG_STORAGE_KEY, type DownloadableFile, ErrorCard, type ErrorCardProps, InteractionCard, type InteractionCardProps, InterruptedBanner, type InterruptedBannerProps, type Locale, type LocalizedText, OpenUiSurfaceHost, type OpenUiSurfaceHostProps, OpenUiSurfaceSnapshotHost, type OpenUiSurfaceSnapshotHostProps, type QuickPrompt, type QuickPromptIconName, type RendererCapability, type RendererKind, type ResolvedChatLayout, ResultBlockList, type ResultBlockListProps, ResultBlocksPro, type ResultBlocksProProps, type RunSnapshot, type RuntimeAppearanceConfig, type RuntimeConfig, type RuntimeConfigStore, type RuntimeQuickPrompt, type RuntimeRendererId, type SandboxExecutorDeps, type SettingsSectionId, SkillBadges, SpecInteraction, type SpecInteractionProps, VercelPayloadPreview, type VercelPayloadPreviewProps, VercelSurfaceHost, type VercelSurfaceHostProps, VercelSurfaceSnapshotHost, type VercelSurfaceSnapshotHostProps, chatbotDictionary, configureA2uiMarkdown, createLocalStorageRuntimeConfigStore, createMemoryRuntimeConfigStore, isLlmEntryUsable, pickUsableLlmEntry, probeA2uiAvailability, probeOpenUiAvailability, sandboxExecutorDeps, useT };
|