page-agent-sdk 2.34.0 → 2.36.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/README.md +7 -6
- package/README.zh-CN.md +7 -6
- package/dist/page-agent-sdk.headless.js +9748 -0
- package/dist/page-agent-sdk.iife.js +168 -168
- package/dist/page-agent-sdk.js +18419 -18387
- package/dist/page-agent-sdk.umd.cjs +108 -108
- package/package.json +7 -2
- package/types/headless.d.ts +1349 -0
- package/types/index.d.ts +19 -0
|
@@ -0,0 +1,1349 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* page-agent-sdk/headless 类型声明 —— 纯核心子集(不含 UI 组件)。
|
|
3
|
+
*
|
|
4
|
+
* 与 index.d.ts 一致的核心 API/类型 + ChatSdkOptions/ChatSdk/DialogConfig + createChatContext/chatContextKey/useChatContext/useChat。
|
|
5
|
+
* 不含 13 个 .vue 组件声明(ChatDialog/MessageContent/CodePreview/SkillPanel/ChatHeader/ChatInput/MessageList/MessageRow/QueuedBar/ApprovalBar/ConflictBar/FocusBar/DebugDrawer)。
|
|
6
|
+
* 由 types/index.d.ts 派生(删组件 declare + 去 DefineComponent import),保持与主类型同步,防漂移。
|
|
7
|
+
*/
|
|
8
|
+
import { InjectionKey, Ref } from 'vue';
|
|
9
|
+
export { z } from 'zod';
|
|
10
|
+
|
|
11
|
+
// 代理连接模块(防 apiKey 泄露:proxy 代理模式 / direct 直连模式)
|
|
12
|
+
export type ProxyLlmMode = 'proxy' | 'direct';
|
|
13
|
+
export interface ProxyLlmOptions {
|
|
14
|
+
mode: ProxyLlmMode;
|
|
15
|
+
baseUrl?: string;
|
|
16
|
+
userToken?: string;
|
|
17
|
+
apiKey?: string;
|
|
18
|
+
model?: string;
|
|
19
|
+
temperature?: number;
|
|
20
|
+
maxTokens?: number;
|
|
21
|
+
refreshToken?: () => Promise<string>;
|
|
22
|
+
headers?: Record<string, string>;
|
|
23
|
+
}
|
|
24
|
+
export declare function createProxyLlm(opts: ProxyLlmOptions): import('@langchain/core/language_models/chat_models').BaseChatModel;
|
|
25
|
+
export interface ConstructOpts {
|
|
26
|
+
temperature?: number;
|
|
27
|
+
maxTokens?: number;
|
|
28
|
+
}
|
|
29
|
+
/** 同步构造 OpenAI 协议 LLM(仅 openai 分支;Anthropic 无同步构造,用 constructLlmFromConfig) */
|
|
30
|
+
export declare function constructOpenLlmSync(cfg: LLMConfig, opts?: ConstructOpts): import('@langchain/core/language_models/chat_models').BaseChatModel;
|
|
31
|
+
/** 按 provider 分支构造 LLM(openai 同步 / anthropic 动态 import @langchain/anthropic);缺省 provider → openai */
|
|
32
|
+
export declare function constructLlmFromConfig(cfg: LLMConfig, opts?: ConstructOpts): Promise<import('@langchain/core/language_models/chat_models').BaseChatModel>;
|
|
33
|
+
/** 从流式 chunk 提取文本 delta(兼容 OpenAI string content 与 Anthropic parts 数组) */
|
|
34
|
+
export declare function extractTextDelta(chunk: import('@langchain/core/messages').AIMessageChunk): string;
|
|
35
|
+
/** 从流式 chunk 提取推理 delta(DeepSeek additional_kwargs.reasoning_content + Anthropic thinking parts) */
|
|
36
|
+
export declare function extractReasoningDelta(chunk: import('@langchain/core/messages').AIMessageChunk): string;
|
|
37
|
+
/** 从响应消息提取 token usage(OpenAI additional_kwargs.usage + Anthropic response_metadata.usage) */
|
|
38
|
+
export declare function extractUsage(message: import('@langchain/core/messages').BaseMessage): any;
|
|
39
|
+
|
|
40
|
+
export interface ToolStep {
|
|
41
|
+
name: string;
|
|
42
|
+
args?: any;
|
|
43
|
+
result?: string;
|
|
44
|
+
status: 'running' | 'done' | 'error';
|
|
45
|
+
/** 工具执行耗时(毫秒,tool_result 时回填) */
|
|
46
|
+
durationMs?: number;
|
|
47
|
+
/** 子 agent 工具步骤(spawn 委派时展示子进度) */
|
|
48
|
+
children?: ToolStep[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface AgentMessage {
|
|
52
|
+
role: 'user' | 'assistant' | 'system';
|
|
53
|
+
content: string;
|
|
54
|
+
timestamp: number;
|
|
55
|
+
reasoning?: string;
|
|
56
|
+
steps?: ToolStep[];
|
|
57
|
+
/** user 消息发送时的焦点快照(multi-focus;MessageRow 渲染 🎯 chip 标注背景组件限制,持久化随 messages) */
|
|
58
|
+
focuses?: Focus[];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface AgentConfig {
|
|
62
|
+
model: string;
|
|
63
|
+
temperature?: number;
|
|
64
|
+
maxTokens?: number;
|
|
65
|
+
systemPrompt?: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface AgentState {
|
|
69
|
+
messages: AgentMessage[];
|
|
70
|
+
loading: boolean;
|
|
71
|
+
error: string | null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export type StreamEvent =
|
|
75
|
+
| { type: 'round_start'; round: number }
|
|
76
|
+
| { type: 'reasoning'; delta: string }
|
|
77
|
+
| { type: 'text'; delta: string }
|
|
78
|
+
| { type: 'tool_call'; name: string; args: any }
|
|
79
|
+
| { type: 'tool_result'; name: string; result: string; status: 'done' | 'error' }
|
|
80
|
+
| { type: 'subagent'; taskId: string; label: string; kind: 'tool_call' | 'tool_result'; name: string; args?: any; result?: string; status?: 'done' | 'error' }
|
|
81
|
+
| { type: 'done'; content: string };
|
|
82
|
+
|
|
83
|
+
export type StreamHandler = (event: StreamEvent) => void;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* SDK 事件(供 createChatSdk({ onEvent }) 订阅常用时机)。
|
|
87
|
+
* 复用 StreamEvent(round_start/reasoning/text/tool_call/tool_result/subagent/done;approval_request 不外发)
|
|
88
|
+
* + 额外时机:data_change / message_update / error。
|
|
89
|
+
*/
|
|
90
|
+
export type SdkEvent =
|
|
91
|
+
| { type: 'round_start'; round: number }
|
|
92
|
+
| { type: 'reasoning'; delta: string }
|
|
93
|
+
| { type: 'text'; delta: string }
|
|
94
|
+
| { type: 'tool_call'; name: string; args: any }
|
|
95
|
+
| { type: 'tool_result'; name: string; result: string; status: 'done' | 'error' }
|
|
96
|
+
| { type: 'subagent'; taskId: string; label: string; kind: 'tool_call' | 'tool_result'; name: string; args?: any; result?: string; status?: 'done' | 'error' }
|
|
97
|
+
| { type: 'done'; content: string }
|
|
98
|
+
| { type: 'data_change'; operation: 'set' | 'edit' | 'delete' | 'restore'; value?: unknown }
|
|
99
|
+
| { type: 'message_update'; count: number }
|
|
100
|
+
| { type: 'conflict'; conflict: PendingConflict }
|
|
101
|
+
| { type: 'session_restored'; sessionId: string; rounds: number }
|
|
102
|
+
| { type: 'usage'; round: number; usage: TokenUsage; cumulative: TokenUsage }
|
|
103
|
+
| { type: 'error'; message: string; severity?: 'recoverable' | 'fatal' | 'observable'; code?: string; context?: unknown }
|
|
104
|
+
| { type: 'trace'; spans: TraceSpan[]; metrics: TraceMetrics }
|
|
105
|
+
| { type: 'context_trimmed'; dropped: { round: number; user: unknown; assistant: unknown[]; steps: unknown[] }[]; vfsResults: Record<string, string>; summary: string; reason: string }
|
|
106
|
+
| { type: 'focus_chip_click'; path: string; label?: string };
|
|
107
|
+
|
|
108
|
+
/** token 用量(OpenAI 协议字段名) */
|
|
109
|
+
export interface TokenUsage {
|
|
110
|
+
prompt_tokens?: number;
|
|
111
|
+
completion_tokens?: number;
|
|
112
|
+
total_tokens?: number;
|
|
113
|
+
}
|
|
114
|
+
/** 批处理单任务结果(sdk.batch 返回;ok=true 含 reply,ok=false 含 error) */
|
|
115
|
+
export interface BatchResult {
|
|
116
|
+
/** 任务在入参数组中的下标 */
|
|
117
|
+
index: number;
|
|
118
|
+
/** 任务文本 */
|
|
119
|
+
task: string;
|
|
120
|
+
/** 成功时的 agent 回复 */
|
|
121
|
+
reply?: string;
|
|
122
|
+
/** 失败时的错误信息 */
|
|
123
|
+
error?: string;
|
|
124
|
+
/** 是否成功 */
|
|
125
|
+
ok: boolean;
|
|
126
|
+
}
|
|
127
|
+
/** 批处理进度回调 payload(sdk.batch 的 onProgress 每任务完成调一次) */
|
|
128
|
+
export interface BatchProgress {
|
|
129
|
+
done: number;
|
|
130
|
+
total: number;
|
|
131
|
+
task: string;
|
|
132
|
+
ok: boolean;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export type SdkEventHandler = (event: SdkEvent) => void;
|
|
136
|
+
|
|
137
|
+
/** 调试日志(与 harness/createAgent 的 DebugLog 一致) */
|
|
138
|
+
export interface DebugLog {
|
|
139
|
+
timestamp: number;
|
|
140
|
+
type: 'context' | 'llm_request' | 'llm_response' | 'tool_call' | 'tool_result' | 'error' | 'middleware';
|
|
141
|
+
data: any;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** ChatDialog 区块显隐控制(chatdialog-component-split):键=区块,false 关闭整块(含 slot);默认 undefined=全开 */
|
|
145
|
+
export interface ChatDialogSections {
|
|
146
|
+
header?: boolean;
|
|
147
|
+
focus?: boolean;
|
|
148
|
+
body?: boolean;
|
|
149
|
+
queued?: boolean;
|
|
150
|
+
approval?: boolean;
|
|
151
|
+
conflict?: boolean;
|
|
152
|
+
footer?: boolean;
|
|
153
|
+
debug?: boolean;
|
|
154
|
+
skill?: boolean;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface ChatDialogProps {
|
|
158
|
+
fetchResponse?: (messages: AgentMessage[], signal?: AbortSignal) => Promise<string>;
|
|
159
|
+
fetchStream?: (messages: AgentMessage[], onEvent: StreamHandler, signal?: AbortSignal) => Promise<string>;
|
|
160
|
+
title?: string;
|
|
161
|
+
placeholder?: string;
|
|
162
|
+
debugLogs?: DebugLog[];
|
|
163
|
+
initialMessages?: AgentMessage[];
|
|
164
|
+
onPersist?: (messages: AgentMessage[]) => void;
|
|
165
|
+
onClear?: () => void;
|
|
166
|
+
getInfo?: () => AgentInfo;
|
|
167
|
+
onUndo?: () => boolean;
|
|
168
|
+
canUndo?: () => boolean;
|
|
169
|
+
showAvatar?: boolean;
|
|
170
|
+
showTyping?: boolean;
|
|
171
|
+
pendingConflict?: PendingConflict | null;
|
|
172
|
+
onResolveConflict?: (action: ConflictResolution['action']) => void;
|
|
173
|
+
infoTick?: Ref<number>;
|
|
174
|
+
getSkillContent?: (name: string) => Promise<string | null>;
|
|
175
|
+
onAddSkill?: (skill: { name: string; description: string; getContent: () => string }) => void;
|
|
176
|
+
onRemoveSkill?: (name: string) => boolean;
|
|
177
|
+
getUserSkillNames?: () => string[];
|
|
178
|
+
onGetSkill?: (name: string) => { name: string; description: string; content: string } | undefined;
|
|
179
|
+
drawer?: boolean;
|
|
180
|
+
drawerWidth?: number | string;
|
|
181
|
+
drawerHidden?: boolean;
|
|
182
|
+
inputRows?: number;
|
|
183
|
+
sessions?: SessionMeta[];
|
|
184
|
+
currentSessionId?: string;
|
|
185
|
+
onNewSession?: () => void;
|
|
186
|
+
onOpenSession?: (sessionId: string) => void;
|
|
187
|
+
onRemoveSession?: (sessionId: string) => void;
|
|
188
|
+
getFocus?: () => Focus | undefined;
|
|
189
|
+
onSetFocus?: (focus: Focus) => { ok: boolean; error?: string };
|
|
190
|
+
onClearFocus?: () => void;
|
|
191
|
+
getFocuses?: () => Focus[];
|
|
192
|
+
onAddFocus?: (focus: Focus) => { ok: boolean; error?: string };
|
|
193
|
+
onRemoveFocus?: (path: string) => void;
|
|
194
|
+
onFocusChipClick?: (focus: Focus) => void;
|
|
195
|
+
/** 区块显隐(chatdialog-component-split);键=false 关闭整块(含 slot),默认全开 */
|
|
196
|
+
sections?: ChatDialogSections;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface ToolInfo { name: string; description: string; schema?: unknown; source?: string }
|
|
200
|
+
export interface SkillInfo { name: string; description: string }
|
|
201
|
+
export interface DataInfo { description?: string; schema?: unknown }
|
|
202
|
+
export interface SubagentInfo {
|
|
203
|
+
enabled: boolean;
|
|
204
|
+
maxDepth: number;
|
|
205
|
+
maxParallel: number;
|
|
206
|
+
allowedTools: string[];
|
|
207
|
+
/** 预声明子 agent 列表(动态:反映 setSubagents/addSubagent/removeSubagent 后的最新) */
|
|
208
|
+
subagents?: { id: string; description: string }[];
|
|
209
|
+
}
|
|
210
|
+
/** 预声明子 agent 配置(同主配置子集 + id/description;缺省继承主 agent) */
|
|
211
|
+
export interface SubagentConfig {
|
|
212
|
+
/** 唯一标识;生成委派工具名 use_<id>(须合法工具名) */
|
|
213
|
+
id: string;
|
|
214
|
+
/** 一句话说明(进主 systemPrompt 索引 + 作委派工具描述) */
|
|
215
|
+
description: string;
|
|
216
|
+
llm?: LLMConfig | ChatModelLike;
|
|
217
|
+
systemPrompt?: string;
|
|
218
|
+
tools?: any[];
|
|
219
|
+
skills?: SkillSpec[];
|
|
220
|
+
temperature?: number;
|
|
221
|
+
maxTokens?: number;
|
|
222
|
+
/** 子 agent 工具调用轮次上限(默认 10);大 JSON 子任务可调大 */
|
|
223
|
+
maxToolRounds?: number;
|
|
224
|
+
/** 子 agent 可写路径前缀白名单(给子 agent 写权限;写工具包 path guard,越界 PATH_OUT_OF_SCOPE;整体 set 禁)。subagent-writable Phase 2 */
|
|
225
|
+
writablePaths?: string[];
|
|
226
|
+
}
|
|
227
|
+
export interface AgentInfo {
|
|
228
|
+
id: string;
|
|
229
|
+
/** 当前会话 id(switchSession/onClear 后实时反映) */
|
|
230
|
+
sessionId: string;
|
|
231
|
+
model?: string;
|
|
232
|
+
/** 当前生效的 systemPrompt(默认或用户传入;仅 base 段,不含中间件 augmentPrompt,便于调试/验证默认提示词) */
|
|
233
|
+
systemPrompt: string;
|
|
234
|
+
tools: ToolInfo[];
|
|
235
|
+
skills: SkillInfo[];
|
|
236
|
+
data?: DataInfo;
|
|
237
|
+
/** 当前上下文压缩预设(默认 auto;complex 为多步复杂任务/大 JSON 场景) */
|
|
238
|
+
contextPreset: 'auto' | 'conservative' | 'aggressive' | 'complex';
|
|
239
|
+
memory: string;
|
|
240
|
+
middleware: string[];
|
|
241
|
+
todos: { id: string; content: string; status: string }[];
|
|
242
|
+
/** 规划阶段防死循环状态(maxPlanRevisions 预算;planning 关闭时 inPlanning 恒 false) */
|
|
243
|
+
planPhase?: { inPlanning: boolean; rounds: number; limit: number };
|
|
244
|
+
/** 当前任务目标锚点(mission 中间件;未开启/未 capture → undefined) */
|
|
245
|
+
mission?: Mission;
|
|
246
|
+
/** 宿主动作元信息(actions 注册;集成方 save_draft/publish 等) */
|
|
247
|
+
actions?: Record<string, { description: string; hasParams: boolean }>;
|
|
248
|
+
/** 跨压缩工作记忆(workingMemory 中间件;pin 最近 read/query/search 定位 path + read hash,≤10 LRU) */
|
|
249
|
+
workingMemory?: WorkingMemory;
|
|
250
|
+
/** 当前上下文聚焦焦点(focus 中间件;兼容:首个;未聚焦/未开启 → undefined) */
|
|
251
|
+
focus?: Focus;
|
|
252
|
+
/** 全部聚焦焦点(multi-focus;空数组=未聚焦) */
|
|
253
|
+
focuses?: Focus[];
|
|
254
|
+
subagent: SubagentInfo;
|
|
255
|
+
verify?: { enabled: boolean; maxAttempts: number; adversarial: boolean };
|
|
256
|
+
mcp?: { servers: { name: string; url: string; toolCount: number }[] };
|
|
257
|
+
/** 最近一次跨轮压缩统计(未触发过 → undefined) */
|
|
258
|
+
lastCompression?: {
|
|
259
|
+
triggered: boolean; roundsTotal: number; roundsSummarized: number; roundsRecalled: number;
|
|
260
|
+
originalMessages: number; compressedMessages: number; strategy: string;
|
|
261
|
+
decision?: CompressDecision;
|
|
262
|
+
};
|
|
263
|
+
/** 会话级 checkpoint 装载状态(未开启 → undefined) */
|
|
264
|
+
checkpoints?: { enabled: boolean; auto: boolean; list: CheckpointMeta[] };
|
|
265
|
+
/** 结构化追踪(revive-observability-tracing;capabilities.tracing 开时填充,否则 undefined) */
|
|
266
|
+
trace?: { spans: TraceSpan[]; metrics: TraceMetrics };
|
|
267
|
+
/** 上下文构成快照(context-inspector;每轮 wrapModelCall 覆盖;capabilities.contextInspector:false → undefined) */
|
|
268
|
+
context?: ContextSnapshot;
|
|
269
|
+
}
|
|
270
|
+
/** 上下文分类(context-inspector) */
|
|
271
|
+
export interface ContextCategory {
|
|
272
|
+
key: string;
|
|
273
|
+
label: string;
|
|
274
|
+
tokens: number;
|
|
275
|
+
pct: number;
|
|
276
|
+
msgCount: number;
|
|
277
|
+
}
|
|
278
|
+
/** 上下文构成快照(context-inspector;每轮 wrapModelCall 覆盖,不累积) */
|
|
279
|
+
export interface ContextSnapshot {
|
|
280
|
+
totalTokens: number;
|
|
281
|
+
contextWindow?: number;
|
|
282
|
+
/** totalTokens / contextWindow(无窗口为 0) */
|
|
283
|
+
occupancy: number;
|
|
284
|
+
/** 压缩触发阈值占比 */
|
|
285
|
+
thresholdRatio: number;
|
|
286
|
+
/** 分类明细(按 tokens 降序) */
|
|
287
|
+
categories: ContextCategory[];
|
|
288
|
+
/** 最近一次压缩统计(复用 state.lastCompression) */
|
|
289
|
+
compression?: { triggered: boolean; roundsTotal: number; roundsSummarized: number; roundsRecalled: number; originalMessages: number; compressedMessages: number; strategy: string };
|
|
290
|
+
}
|
|
291
|
+
/** analyzeContext 选项(context-inspector) */
|
|
292
|
+
export interface AnalyzeContextOptions {
|
|
293
|
+
contextWindow?: number;
|
|
294
|
+
thresholdRatio?: number;
|
|
295
|
+
}
|
|
296
|
+
/** 对「实际发给 LLM 的消息」分类切分 + token 估算(纯函数,零 LLM 成本) */
|
|
297
|
+
export declare function analyzeContext(messages: import('@langchain/core/messages').BaseMessage[], opts?: AnalyzeContextOptions): ContextSnapshot;
|
|
298
|
+
/** 上下文检查中间件选项(context-inspector) */
|
|
299
|
+
export interface ContextInspectorOptions {
|
|
300
|
+
contextWindow?: number;
|
|
301
|
+
thresholdRatio?: number;
|
|
302
|
+
}
|
|
303
|
+
/** 上下文检查中间件(context-inspector;getSnapshot 读最近快照) */
|
|
304
|
+
export interface ContextInspectorMiddleware {
|
|
305
|
+
name: string;
|
|
306
|
+
getSnapshot(): ContextSnapshot | undefined;
|
|
307
|
+
}
|
|
308
|
+
/** 创建上下文检查中间件(capabilities.contextInspector 默认开) */
|
|
309
|
+
export declare function createContextInspectorMiddleware(opts?: ContextInspectorOptions): ContextInspectorMiddleware;
|
|
310
|
+
export interface McpServerConfig { transport: 'http' | 'sse' | 'websocket'; url: string; name?: string; requestInit?: any; }
|
|
311
|
+
|
|
312
|
+
/** DebugDrawer props(纯 props 驱动,不耦合 ChatDialog;headless 自建对话框可复用) */
|
|
313
|
+
export interface DebugDrawerProps {
|
|
314
|
+
logs?: DebugLog[];
|
|
315
|
+
visible: boolean;
|
|
316
|
+
/** 取 agent 详情(「Agent 信息」tab) */
|
|
317
|
+
getInfo?: () => AgentInfo;
|
|
318
|
+
/** 刷新 tick(watch 后重拉 getInfo;setSkills/setData 后 ++ 实时反映) */
|
|
319
|
+
infoTick?: Ref<number>;
|
|
320
|
+
/** 读 skill 全文(展开 skill 时调;返回 null 表示无内容) */
|
|
321
|
+
getSkillContent?: (name: string) => Promise<string | null>;
|
|
322
|
+
}
|
|
323
|
+
/** 调试抽屉(7 类日志筛选 / Agent 信息 / 上下文构成 / 上轮压缩 / skill 展开);v-model:visible 显隐,emit clear 清日志 */
|
|
324
|
+
// chatContext 枢纽(L2 自建根组件调 createChatContext + provide(chatContextKey);原子组件 useChatContext inject)
|
|
325
|
+
export interface ChatContextOptions {
|
|
326
|
+
fetchResponse?: (messages: AgentMessage[], signal?: AbortSignal) => Promise<string>;
|
|
327
|
+
fetchStream?: (messages: AgentMessage[], onEvent: StreamHandler, signal?: AbortSignal) => Promise<string>;
|
|
328
|
+
messages?: AgentMessage[];
|
|
329
|
+
onPersist?: (messages: AgentMessage[]) => void;
|
|
330
|
+
onClear?: () => void;
|
|
331
|
+
getInfo?: () => AgentInfo;
|
|
332
|
+
canUndo?: () => boolean;
|
|
333
|
+
onUndo?: () => boolean;
|
|
334
|
+
}
|
|
335
|
+
export interface ChatContext {
|
|
336
|
+
/** 对话状态 + 操作(useChat 返回 14 项) */
|
|
337
|
+
readonly chat: any;
|
|
338
|
+
inputText: Ref<string>;
|
|
339
|
+
isExpanded: Ref<boolean>;
|
|
340
|
+
toggleCollapse: () => void;
|
|
341
|
+
debugVisible: Ref<boolean>;
|
|
342
|
+
openDebug: () => void;
|
|
343
|
+
closeDebug: () => void;
|
|
344
|
+
skillVisible: Ref<boolean>;
|
|
345
|
+
openSkill: () => void;
|
|
346
|
+
closeSkill: () => void;
|
|
347
|
+
reasoningExpanded: Ref<Record<number, boolean>>;
|
|
348
|
+
isReasoningExpanded: (idx: number) => boolean;
|
|
349
|
+
toggleReasoning: (idx: number) => void;
|
|
350
|
+
copiedMsg: Ref<boolean>;
|
|
351
|
+
copyMessage: (text: string) => void;
|
|
352
|
+
summary: Readonly<Ref<{ mcp: number; tools: number }>>;
|
|
353
|
+
canUndo: Readonly<Ref<boolean>>;
|
|
354
|
+
undo: () => void;
|
|
355
|
+
formatTime: (timestamp: number) => string;
|
|
356
|
+
send: () => void;
|
|
357
|
+
keydown: (e: KeyboardEvent) => void;
|
|
358
|
+
editQueued: (idx: number) => void;
|
|
359
|
+
isPendingAssistant: (idx: number) => boolean;
|
|
360
|
+
}
|
|
361
|
+
export declare const chatContextKey: InjectionKey<ChatContext>;
|
|
362
|
+
export declare function createChatContext(opts?: ChatContextOptions): ChatContext;
|
|
363
|
+
export declare function useChatContext(): ChatContext;
|
|
364
|
+
export declare function useChat(opts?: any): any;
|
|
365
|
+
|
|
366
|
+
// ===== 框架无关 SDK(页面内 Agent)=====
|
|
367
|
+
export interface LLMConfig {
|
|
368
|
+
apiKey: string;
|
|
369
|
+
/** provider 选择:缺省 'openai'(兼容 OpenAI/DeepSeek 协议,向后兼容);'anthropic' 动态加载 @langchain/anthropic 走 Claude */
|
|
370
|
+
provider?: 'openai' | 'anthropic';
|
|
371
|
+
baseUrl?: string;
|
|
372
|
+
model?: string;
|
|
373
|
+
temperature?: number;
|
|
374
|
+
maxTokens?: number;
|
|
375
|
+
/** 模型上下文窗口(token);缺省按 model 名查表。影响 offload 阈值与压缩触发(大模型自适应) */
|
|
376
|
+
contextWindow?: number;
|
|
377
|
+
/** 模型最大输出(token);缺省按 model 名查表。maxTokens 未传时作其缺省,避免设错被截断 */
|
|
378
|
+
maxOutputTokens?: number;
|
|
379
|
+
/** 透传 ChatOpenAI 的 modelKwargs:额外请求 body 参数(如 deepseek thinking: { thinking: { type: 'enabled' } }) */
|
|
380
|
+
extraBody?: Record<string, any>;
|
|
381
|
+
/** 透传 ChatOpenAI configuration 的额外字段(如 headers/timeout/customFetch),与 baseUrl 合并 */
|
|
382
|
+
extraConfig?: Record<string, any>;
|
|
383
|
+
}
|
|
384
|
+
/** LangChain BaseChatModel 的结构形状(provider 抽离:llm 可传任意 provider 实例) */
|
|
385
|
+
export type ChatModelLike = {
|
|
386
|
+
invoke: (input: any, options?: any) => Promise<any>;
|
|
387
|
+
stream: (input: any, options?: any) => Promise<any>;
|
|
388
|
+
bindTools: (tools: any[]) => any;
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
/** 受保护资源配置(精确值保护:占位符替换读写) */
|
|
392
|
+
export interface ResourceProtectSpec {
|
|
393
|
+
/** 相对主数据根的点号路径(如 id / components.0.verification) */
|
|
394
|
+
path: string;
|
|
395
|
+
/** freeze=只读不可改(精确值不入消息流);verbatim=原样保留(防压缩丢字,改须经 resource_update) */
|
|
396
|
+
mode: 'freeze' | 'verbatim';
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export interface DataConfig {
|
|
400
|
+
/** 值的 zod schema(写入时校验);字段的 .describe() 自动提取注入 systemPrompt「可操作数据」段 */
|
|
401
|
+
schema: any;
|
|
402
|
+
/** 数据源:reactive/普通对象,工具直接读写 bind(reactive 写后响应式刷新;不挂 window) */
|
|
403
|
+
bind: any;
|
|
404
|
+
/** 数据说明,供 Agent 理解用途;不传则自动生成 */
|
|
405
|
+
description?: string;
|
|
406
|
+
/** 受保护资源(精确值保护):声明需 freeze(只读)/verbatim(原样保留)的字段路径。
|
|
407
|
+
* 配置后 read 受保护路径返占位符(精确值不入 LLM 消息流),写侧强制(freeze 拒/verbatim 展开校验)。
|
|
408
|
+
* opt-in:未配(默认)全部行为零变化 */
|
|
409
|
+
resources?: ResourceProtectSpec[];
|
|
410
|
+
}
|
|
411
|
+
/** createDataOps 选项(审计回调 / 快照上限 / 乐观锁) */
|
|
412
|
+
export interface DataOpsOptions {
|
|
413
|
+
onAudit?: (entry: { op: string; value?: any; detail?: string; timestamp: number }) => void;
|
|
414
|
+
maxSnapshots?: number;
|
|
415
|
+
/** 乐观锁冲突人工介入回调(详见 ConflictInfo/ConflictResolution);不传则冲突时返回 VERSION_CONFLICT 错误 */
|
|
416
|
+
onConflict?: (conflict: ConflictInfo) => Promise<ConflictResolution>;
|
|
417
|
+
/**
|
|
418
|
+
* 自动乐观锁(默认 true):写入时若 LLM 未显式传 expectedHash,自动用「LLM 最后一次 read/get 读到的 hash」作基准比对。
|
|
419
|
+
* LLM 无需手动传 expectedHash 即可享受乐观锁保护;冲突走 onConflict(无 onConflict 则返回 VERSION_CONFLICT)。
|
|
420
|
+
* LLM 未读过直接写(无基准记录)时跳过锁(等同不校验)。设 false 回退「不传 expectedHash = 不校验」的旧行为。
|
|
421
|
+
*/
|
|
422
|
+
autoLock?: boolean;
|
|
423
|
+
/** 读写拦截器:read/write 透传给数据工具(脱敏/转换/审计/拒绝 LLM 读写) */
|
|
424
|
+
interceptors?: DataInterceptors;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/** 数据读写拦截器(集成方可脱敏/转换/审计/拒绝 LLM 的读写) */
|
|
428
|
+
export interface DataInterceptors {
|
|
429
|
+
/** LLM 读时拦截:原始值 → 改写后返回给 LLM(如脱敏/派生);抛错则返回 READ_INTERCEPT 错误 */
|
|
430
|
+
read?: (value: any) => any;
|
|
431
|
+
/** LLM 写时拦截:欲写值 + 当前值 → 改写后的值,或 { error } 拒绝;抛错则拒绝 */
|
|
432
|
+
write?: (payload: any, current: any) => any | { error: string };
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/** 工具呈现模式:simple=主推 read/write 但保留高级能力(默认)| advanced=全暴露| minimal=只 read/write */
|
|
436
|
+
export type ToolMode = 'simple' | 'advanced' | 'minimal';
|
|
437
|
+
|
|
438
|
+
/** 数据操作控制器(运行时替换配置;createDataOps 返回的工具数组上以不可枚举属性 `controller` 挂载) */
|
|
439
|
+
export interface DataOpsController {
|
|
440
|
+
/** 读取当前配置 */
|
|
441
|
+
get(): DataConfig;
|
|
442
|
+
/** 替换主数据配置(如页面切换、schema 变更);清空快照栈与乐观锁缓存 */
|
|
443
|
+
set(config: DataConfig): void;
|
|
444
|
+
/** 仅替换 bind 引用;清空快照栈与乐观锁缓存 */
|
|
445
|
+
update(bind: any): void;
|
|
446
|
+
/** 受保护资源清单快照(供跨压缩 pin 中间件注入「受保护资源」段;freeze 无 handle,verbatim 有) */
|
|
447
|
+
getResourcesSnapshot?(): { path: string; mode: 'freeze' | 'verbatim'; handle?: string }[];
|
|
448
|
+
/** 资源池操作(经 controller 同闭包;有 vfsStore 时可用) */
|
|
449
|
+
createResource?(path: string, value?: unknown): string;
|
|
450
|
+
getResource?(pathOrHandle: string): { path: string; mode: string; value: unknown; handle: string } | undefined;
|
|
451
|
+
updateResource?(path: string, value: unknown): void;
|
|
452
|
+
deleteResource?(pathOrHandle: string): boolean;
|
|
453
|
+
listResources?(): { path: string; mode: string; handle: string; bytes: number }[];
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
export interface SkillsController {
|
|
457
|
+
/** 运行时替换整个 skill 列表(同名 skill 覆盖更新;清缓存) */
|
|
458
|
+
set(skills: SkillSpec[]): void;
|
|
459
|
+
/** 读取当前 skill 列表(反映运行时 setSkills 替换) */
|
|
460
|
+
get(): SkillSpec[];
|
|
461
|
+
/** 清指定 skill 的全文缓存(不传清全部);下次 load_skill 重新取最新 */
|
|
462
|
+
invalidateCache(name?: string): void;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
export interface PermissionRule {
|
|
466
|
+
operations: ('read' | 'write')[];
|
|
467
|
+
scopes: string[];
|
|
468
|
+
mode: 'allow' | 'deny';
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
export interface SkillSpec {
|
|
472
|
+
name: string;
|
|
473
|
+
/** 一句话说明(进索引,兼顾「是什么」+「何时用」) */
|
|
474
|
+
description: string;
|
|
475
|
+
/** 文档源(http(s):// 远程 md,或 vfs://path / 裸路径;SDK 代劳 fetch+vfs);与 getContent 二选一,doc 优先 */
|
|
476
|
+
doc?: string;
|
|
477
|
+
getContent?: () => string | Promise<string>;
|
|
478
|
+
/** 加载时执行脚本,结果注入全文(skill-external-scripts);code/url 二选一,默认 sandbox,失败不缓存 */
|
|
479
|
+
exec?: SkillExecSpec;
|
|
480
|
+
/** 附带可调工具工厂;load_skill 后注入工具池(命名空间 <skill>__<tool>,走 dedupeTools);与 exec 正交 */
|
|
481
|
+
tools?: SkillToolFactory[];
|
|
482
|
+
}
|
|
483
|
+
/** skill 执行钩子:code(内联 JS)/url(远程,仅 sandbox)二选一;context 默认 sandbox,host 需 skillHostScript */
|
|
484
|
+
export interface SkillExecSpec {
|
|
485
|
+
code?: string;
|
|
486
|
+
url?: string;
|
|
487
|
+
context?: 'sandbox' | 'host';
|
|
488
|
+
inject?: 'append' | 'prepend';
|
|
489
|
+
}
|
|
490
|
+
/** skill 附带工具工厂(返回单个/数组工具,可异步;ctx.signal 运行时中止信号) */
|
|
491
|
+
export type SkillToolFactory = () => any | any[] | Promise<any | any[]>;
|
|
492
|
+
|
|
493
|
+
// ===== Verify 自检中间件 =====
|
|
494
|
+
/** verify check 上下文:与 beforeReturn 底层一致(messages 含 system 头 + agent 最新回复 + 历史 tool_result) */
|
|
495
|
+
export interface VerifyCheckContext {
|
|
496
|
+
messages: any[];
|
|
497
|
+
state: any;
|
|
498
|
+
}
|
|
499
|
+
export interface VerifyCheckResult {
|
|
500
|
+
ok: boolean;
|
|
501
|
+
/** ok=false 时的修正指引(回灌给 agent 触发自纠) */
|
|
502
|
+
feedback?: string;
|
|
503
|
+
}
|
|
504
|
+
/** 领域校验函数:ok=true 放行,ok=false 用 feedback 回灌自纠 */
|
|
505
|
+
export type VerifyCheck = (ctx: VerifyCheckContext) => Promise<VerifyCheckResult> | VerifyCheckResult;
|
|
506
|
+
export interface VerifyMiddlewareOptions {
|
|
507
|
+
check: VerifyCheck;
|
|
508
|
+
/** 对抗式验证:check 通过后 spawn 找茬子 agent 审查;verdict 无问题放行,否则回灌 */
|
|
509
|
+
adversarial?: { llm: any; tools?: any[] };
|
|
510
|
+
}
|
|
511
|
+
/** createWriteBackCheck 选项 */
|
|
512
|
+
export interface WriteBackCheckOptions {
|
|
513
|
+
/** name → zod schema(由 createChatSdk 从 data 构造注入,键 '' 代表主数据);省略则只校验「读回非空」 */
|
|
514
|
+
schemas?: Record<string, any>;
|
|
515
|
+
/**
|
|
516
|
+
* 读回的根对象。优先于 `window`。
|
|
517
|
+
* - 单对象 data 模式:传 bind 对象(或 getter `() => liveData()?.bind`,适配 sdk.setData 运行时替换)
|
|
518
|
+
* - 旧 windowProps 模式:省略则用 `window`(默认 globalThis.window)
|
|
519
|
+
*/
|
|
520
|
+
root?: unknown | (() => unknown);
|
|
521
|
+
/** 读 window 的根对象(旧 windowProps 模式;data 模式应传 root)。默认 globalThis.window */
|
|
522
|
+
window?: unknown;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
// ===== 人工确认(approval)=====
|
|
526
|
+
/** 人工确认中间件选项:工具调用前需用户「允许/拒绝」 */
|
|
527
|
+
export interface ApprovalOptions {
|
|
528
|
+
/** 需确认的工具名列表;不传 confirm 且不传 tools → 所有工具都确认 */
|
|
529
|
+
tools?: string[];
|
|
530
|
+
/** 自定义判定(优先于 tools);返回 true 需确认 */
|
|
531
|
+
confirm?: (name: string, args: any) => boolean;
|
|
532
|
+
/** 超时毫秒(用户未响应自动拒绝);0 = 不超时(默认) */
|
|
533
|
+
timeoutMs?: number;
|
|
534
|
+
/** 是否装载 request_human_confirmation 主动确认工具(传 approval 时默认 true;false 关闭) */
|
|
535
|
+
humanConfirmTool?: boolean;
|
|
536
|
+
}
|
|
537
|
+
export declare function createApprovalMiddleware(opts?: ApprovalOptions): any;
|
|
538
|
+
export declare function createHumanConfirmTool(): any;
|
|
539
|
+
export declare function createHumanConfirmMiddleware(): any;
|
|
540
|
+
export declare const HUMAN_CONFIRM_TOOL_NAME: string;
|
|
541
|
+
export interface CheckpointMeta {
|
|
542
|
+
id: number;
|
|
543
|
+
label?: string;
|
|
544
|
+
timestamp: number;
|
|
545
|
+
messageCount: number;
|
|
546
|
+
}
|
|
547
|
+
export interface Checkpoint extends CheckpointMeta {
|
|
548
|
+
messages: AgentMessage[];
|
|
549
|
+
windowVals: Record<string, unknown>;
|
|
550
|
+
vfs: Record<string, { content: string; mimeType?: string; updatedAt: number }>;
|
|
551
|
+
todos: { id: string; content: string; status: 'pending' | 'in_progress' | 'completed' }[];
|
|
552
|
+
}
|
|
553
|
+
export interface CheckpointManager {
|
|
554
|
+
save(label?: string): number;
|
|
555
|
+
list(): CheckpointMeta[];
|
|
556
|
+
restore(id?: number): boolean;
|
|
557
|
+
canRestore(): boolean;
|
|
558
|
+
/** 导出栈快照(深拷贝,可序列化;供 automation 断点续跑持久化,刷新/崩溃后恢复 restoreLastCheckpoint 能力) */
|
|
559
|
+
exportStack(): Checkpoint[];
|
|
560
|
+
/** 灌入栈快照(刷新/崩溃恢复时重建 checkpoint 栈;重置 nextId 防后续 save id 冲突) */
|
|
561
|
+
importStack(cps: unknown[]): void;
|
|
562
|
+
}
|
|
563
|
+
export declare function createCheckpointManager(deps: any): CheckpointManager;
|
|
564
|
+
export declare function createCheckpointMiddleware(mgr: CheckpointManager): any;
|
|
565
|
+
|
|
566
|
+
// ===== 持久化存储 =====
|
|
567
|
+
export type StorageBackendType = 'indexed' | 'session' | 'local' | 'memory';
|
|
568
|
+
export interface StorageConfig {
|
|
569
|
+
backend?: StorageBackendType;
|
|
570
|
+
enabled?: boolean;
|
|
571
|
+
dbName?: string;
|
|
572
|
+
maxBytes?: number;
|
|
573
|
+
maxBytesPerSession?: number;
|
|
574
|
+
evictionWatermark?: number;
|
|
575
|
+
debounceMs?: number;
|
|
576
|
+
}
|
|
577
|
+
/** Skill 独立持久化存储配置(与 storage 选项分离) */
|
|
578
|
+
export interface SkillStoreConfig {
|
|
579
|
+
/** 存储 id(命名空间)。手动指定同一 id 即可跨页面/跨 agent 复用同一套用户 skill;不传默认按 agentId 隔离 */
|
|
580
|
+
id?: string;
|
|
581
|
+
/** 后端类型,默认 'indexed'(大容量、跨刷新);'local' 跨页持久;'session' 刷新保留关页清;'memory' 纯内存降级 */
|
|
582
|
+
backend?: StorageBackendType;
|
|
583
|
+
/** DB 命名空间,默认 'chat-sdk'(与 SessionStore 同库,不同 key 前缀) */
|
|
584
|
+
dbName?: string;
|
|
585
|
+
}
|
|
586
|
+
export interface SessionMeta {
|
|
587
|
+
agentId: string;
|
|
588
|
+
sessionId: string;
|
|
589
|
+
createdAt: number;
|
|
590
|
+
lastAccessed: number;
|
|
591
|
+
bytes: number;
|
|
592
|
+
title?: string;
|
|
593
|
+
}
|
|
594
|
+
export interface SessionSnapshot {
|
|
595
|
+
messages: AgentMessage[];
|
|
596
|
+
vfs: Record<string, { content: string; mimeType?: string; updatedAt: number }>;
|
|
597
|
+
todos: { id: string; content: string; status: 'pending' | 'in_progress' | 'completed' }[];
|
|
598
|
+
memory: string;
|
|
599
|
+
/** automation 断点续跑:checkpoint 栈快照(刷新/崩溃后恢复 restoreLastCheckpoint 能力);仅 capabilities.automation 开启时写入 */
|
|
600
|
+
checkpoints?: unknown[];
|
|
601
|
+
/** automation 断点续跑:累计 token usage(刷新后续跑预算统计连续) */
|
|
602
|
+
usage?: TokenUsage;
|
|
603
|
+
/** 会话任务目标(context-persist-resilience:刷新后不丢;capabilities.missionAnchor 开启时写入) */
|
|
604
|
+
mission?: Mission;
|
|
605
|
+
/** 跨压缩工作记忆 path/hash 备忘(context-persist-resilience:刷新后少重复 read;capabilities.workingMemory 开启时写入) */
|
|
606
|
+
workingMemory?: WorkingMemory;
|
|
607
|
+
/** 上下文聚焦焦点(multi-focus:Focus[] 数组;null=清除标记;旧版本单个 applySnapshot 读时归一化) */
|
|
608
|
+
focus?: Focus[] | null;
|
|
609
|
+
}
|
|
610
|
+
export type StorageEvent =
|
|
611
|
+
| { type: 'degraded'; reason: string }
|
|
612
|
+
| { type: 'quota'; sessionBytes: number; limit: number }
|
|
613
|
+
| { type: 'evicted'; agentId: string; sessionId: string; bytes: number }
|
|
614
|
+
| { type: 'flush' };
|
|
615
|
+
export interface StorageBackend {
|
|
616
|
+
get(key: string): Promise<unknown | undefined>;
|
|
617
|
+
set(key: string, value: unknown): Promise<void>;
|
|
618
|
+
del(key: string): Promise<void>;
|
|
619
|
+
scan(prefix: string, cb: (key: string, value: unknown) => boolean | void): Promise<void>;
|
|
620
|
+
clearPrefix(prefix: string): Promise<void>;
|
|
621
|
+
}
|
|
622
|
+
export interface SessionStore {
|
|
623
|
+
ready: Promise<boolean>;
|
|
624
|
+
listSessions(agentId: string): Promise<SessionMeta[]>;
|
|
625
|
+
load(agentId: string, sessionId: string): Promise<SessionSnapshot | undefined>;
|
|
626
|
+
save(agentId: string, sessionId: string, snap: Partial<SessionSnapshot>): Promise<void>;
|
|
627
|
+
/** 更新会话标题(自动从首条 user 消息生成,供历史列表显示) */
|
|
628
|
+
updateTitle(agentId: string, sessionId: string, title: string): Promise<void>;
|
|
629
|
+
flush(): Promise<void>;
|
|
630
|
+
deleteSession(agentId: string, sessionId: string): Promise<void>;
|
|
631
|
+
createSession(agentId: string, title?: string, sessionId?: string): Promise<string>;
|
|
632
|
+
onEvent(cb: (e: StorageEvent) => void): void;
|
|
633
|
+
dispose(): void;
|
|
634
|
+
}
|
|
635
|
+
export interface SessionOptions {
|
|
636
|
+
id?: string;
|
|
637
|
+
autoResume?: boolean;
|
|
638
|
+
title?: string;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* augmentSystem 钩子上下文:集成方回调据此按运行时状态动态注入 system prompt 段。
|
|
643
|
+
* - `state`:harness 当前状态(messages/todos/files/skills/memory…);不含 data(data 是 createChatSdk 层概念)
|
|
644
|
+
* - `data`:当前主数据配置(每轮从 liveData() 取最新,setData 后自动同步;含 schema/bind/description)
|
|
645
|
+
*/
|
|
646
|
+
export interface SystemAugmentContext {
|
|
647
|
+
state: any;
|
|
648
|
+
data?: DataConfig;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/** 宿主动作定义:集成方注册的页面操作(保存/发布/预览/导出等),SDK 自动包成命名 tool */
|
|
652
|
+
export interface ActionDef {
|
|
653
|
+
/** 动作描述(给 LLM 看) */
|
|
654
|
+
description: string;
|
|
655
|
+
/** 执行函数;接收 params schema 解析的参数,返回值序列化回灌 LLM */
|
|
656
|
+
run: (args: Record<string, unknown>) => unknown | Promise<unknown>;
|
|
657
|
+
/** 可选参数 schema(ZodObject);不传 = 无参 tool */
|
|
658
|
+
params?: any;
|
|
659
|
+
}
|
|
660
|
+
/** actions 配置:动作名 → 定义(动作名即 tool 名,须合法标识符) */
|
|
661
|
+
export type ActionMap = Record<string, ActionDef>;
|
|
662
|
+
export interface ChatSdkOptions {
|
|
663
|
+
container?: string | HTMLElement;
|
|
664
|
+
/** UI:'default'(内置 ChatDialog)/ false(headless 不渲染,自建 UI) */
|
|
665
|
+
ui?: boolean | 'default';
|
|
666
|
+
llm: LLMConfig | ChatModelLike;
|
|
667
|
+
/** agent 实例 id(多 agent 共存隔离;不传则随机生成并告警,刷新后无法恢复) */
|
|
668
|
+
id?: string;
|
|
669
|
+
/** 持久化:默认关闭;赋值后端字符串('indexed'/'session'/'local'/'memory')或配置对象开启;false 关闭 */
|
|
670
|
+
storage?: StorageBackendType | StorageConfig | false;
|
|
671
|
+
/** 会话控制 */
|
|
672
|
+
session?: SessionOptions;
|
|
673
|
+
/** 共享上下文:默认 false;true 时同 id 复用同一核心(messages/agent/工作区) */
|
|
674
|
+
shareContext?: boolean;
|
|
675
|
+
/** 系统提示词(base + 可操作数据段,数据段随 data 动态;不含 todos/skills/memory/augmentSystem 等运行态 augmentPrompt 段) */
|
|
676
|
+
systemPrompt?: string;
|
|
677
|
+
/** 自定义 systemPrompt 时是否自动追加 reliableWriteRules(默认 true,用 '---' 分隔线区分;设 false 关闭;不传 systemPrompt 用默认 prompt 时已内置,此项无效) */
|
|
678
|
+
appendReliableWriteRules?: boolean;
|
|
679
|
+
/**
|
|
680
|
+
* 动态 system prompt 注入钩子:每轮 buildSystemPrompt 时调用,集成方按运行时状态(state/data)返回字符串 → 作为 system prompt 一段注入;返回 undefined → 跳过。
|
|
681
|
+
* - ctx.data 每轮从 liveData() 取最新(setData 后自动同步),可据此动态算组件说明 / 部分 schema 描述
|
|
682
|
+
* - 回调异常降级为跳过该段 + debug 日志(不崩 agent)
|
|
683
|
+
* - 段排在内置段之后、用户 middleware 之前;不配 = 完全现状行为
|
|
684
|
+
*/
|
|
685
|
+
augmentSystem?: (ctx: SystemAugmentContext) => string | undefined;
|
|
686
|
+
tools?: any[];
|
|
687
|
+
/** 宿主动作:集成方注册的页面操作(保存/发布/预览等),SDK 自动包成命名 tool;LLM 直接看到命名 tool */
|
|
688
|
+
actions?: ActionMap;
|
|
689
|
+
skills?: SkillSpec[];
|
|
690
|
+
/** 用户创建 skill 的独立持久化存储(与 storage 选项分离)。默认 `{ backend: 'indexed' }`(即使 storage:false 也持久化);`false` 关闭;`id` 手动指定同一 id 可跨页面/跨 agent 复用 */
|
|
691
|
+
skillStorage?: SkillStoreConfig | false;
|
|
692
|
+
/** AGENTS.md 风格持久指令。支持 string 与同步/异步函数(异步函数适合加载 RAG 文档) */
|
|
693
|
+
memory?: string | (() => string | Promise<string>);
|
|
694
|
+
data?: DataConfig;
|
|
695
|
+
/** 大 schema 分层披露阈值(默认 maxKeys=15/maxChars=4000;超则 systemPrompt 只注入顶层概览,深层约束查 schema_data) */
|
|
696
|
+
schemaHint?: SchemaHintOptions;
|
|
697
|
+
permissions?: PermissionRule[];
|
|
698
|
+
/** 自定义中间件(注入到内置中间件之后;可拦截/观察模型调用、工具、prompt) */
|
|
699
|
+
middleware?: any[];
|
|
700
|
+
vfs?: { initialFiles?: Record<string, string>; maxBytes?: number };
|
|
701
|
+
/** 每个数据对象最多保留快照数(默认 20) */
|
|
702
|
+
maxSnapshots?: number;
|
|
703
|
+
/** 自动乐观锁(默认 true):写入时若 LLM 未传 expectedHash,自动用其最后 get 读到的 hash 比对;设 false 回退「不传 = 不校验」 */
|
|
704
|
+
autoLock?: boolean;
|
|
705
|
+
/** 数据操作审计回调:每次 set/edit/delete/restore 经此回调外发结构化事件(独立于 debug,无需 debug:true);集成方做合规审计/操作追溯 */
|
|
706
|
+
onAudit?: (entry: { op: string; value?: unknown; detail?: string; timestamp: number }) => void;
|
|
707
|
+
/** 工具呈现模式:simple(默认,主推 read/write 但保留 query/search/eval/snapshot)| advanced(全暴露)| minimal(只 read/write) */
|
|
708
|
+
toolMode?: 'simple' | 'advanced' | 'minimal';
|
|
709
|
+
/** 读写拦截器:read/write 透传给数据工具(脱敏/转换/审计/拒绝 LLM 读写);input/output 在 agent IO 入口/出口预处理 */
|
|
710
|
+
interceptors?: {
|
|
711
|
+
read?: (value: any) => any;
|
|
712
|
+
write?: (payload: any, current: any) => any | { error: string };
|
|
713
|
+
/** agent 接收输入时拦截:send/stream 的 user message 预处理(可改写/审计) */
|
|
714
|
+
input?: (input: any) => any;
|
|
715
|
+
/** agent 产出输出时拦截:返回前 postprocess(可改写最终回复) */
|
|
716
|
+
output?: (json: any) => any;
|
|
717
|
+
};
|
|
718
|
+
/** 内存中保留的对话轮数上限(默认 50);超限把最旧轮次压缩为摘要 system 消息(防 OOM);0 关闭 */
|
|
719
|
+
maxMemoryRounds?: number;
|
|
720
|
+
debug?: boolean;
|
|
721
|
+
/** agent 工具调用轮次上限(默认 10);大 JSON 分块构建(draft_write×N + draft_commit + read 确认)是多轮场景,可能触顶被截断,建议调大到 20-30 */
|
|
722
|
+
maxToolRounds?: number;
|
|
723
|
+
/** 规划阶段总轮次预算(默认 5);planning 状态下超限 → write_todos/update_todo 回灌,防"光规划不执行"死循环。与 maxIterations 正交 */
|
|
724
|
+
maxPlanRevisions?: number;
|
|
725
|
+
/** 模型调用失败自动重试次数(默认 2;网络/429/5xx 重试,4xx 与 abort 不重试) */
|
|
726
|
+
maxRetries?: number;
|
|
727
|
+
/** token 预算上限(累计 total_tokens 超过 → 停止 agent + emit BUDGET_EXCEEDED;需 capabilities.automation:true) */
|
|
728
|
+
tokenBudget?: number;
|
|
729
|
+
/** 时间预算 ms(从 agent 开始计时,超过 → 停止;需 capabilities.automation:true) */
|
|
730
|
+
timeBudgetMs?: number;
|
|
731
|
+
/** 无人值守错误恢复:致命错误(invoke 抛错)自动 restore_last_checkpoint + 重试次数(默认 1;防单点错误永久中断批量/长任务)。需 capabilities.automation:true */
|
|
732
|
+
maxAutoRetries?: number;
|
|
733
|
+
/** 同轮工具并发上限(默认 1 串行) */
|
|
734
|
+
maxParallelTools?: number;
|
|
735
|
+
/** 模型上下文窗口(token);顶层声明对 llm 实例场景也生效,缺省按 model 名查表。影响 offload 阈值与压缩触发 */
|
|
736
|
+
contextWindow?: number;
|
|
737
|
+
/** 模型最大输出(token);顶层声明对 llm 实例场景也生效,缺省按 model 名查表 */
|
|
738
|
+
maxOutputTokens?: number;
|
|
739
|
+
/** 子 agent 委派(默认开启;{ enabled: false } 关闭) */
|
|
740
|
+
capabilities?: { dataOps?: boolean; fetch?: boolean; planning?: boolean; missionAnchor?: boolean; skills?: boolean; vfs?: boolean; summarization?: boolean; memory?: boolean; subagent?: boolean; verify?: boolean; domInspect?: boolean; inspectEnv?: boolean; draftWrite?: boolean; tracing?: boolean; todoDeps?: boolean; automation?: boolean; workingMemory?: boolean; focus?: boolean; skillHostScript?: boolean; contextInspector?: boolean };
|
|
741
|
+
subagent?: { enabled?: boolean; allowedTools?: string[]; systemPrompt?: string; temperature?: number; maxTokens?: number; skills?: SkillSpec[]; llm?: LLMConfig | ChatModelLike; maxDepth?: number; maxParallel?: number };
|
|
742
|
+
/** 预声明子 agent 列表:每个用同主配置方式声明,自动生成 use_<id> 委派工具(与 spawn_agent 共存) */
|
|
743
|
+
subagents?: SubagentConfig[];
|
|
744
|
+
/** 自检:agent 返回前跑 check,不通过则 feedback 回灌自纠(默认关闭;需 capabilities.verify:true)。check 省略时默认 createWriteBackCheck 写后读回验证 */
|
|
745
|
+
verify?: { enabled?: boolean; check?: VerifyCheck; maxAttempts?: number; adversarial?: boolean };
|
|
746
|
+
/** 人工确认:工具调用前弹确认框,用户「允许/拒绝」后才执行(默认关闭,不传 = 不装) */
|
|
747
|
+
approval?: ApprovalOptions;
|
|
748
|
+
/** 会话级 checkpoint 回滚(回到上次正常时)。默认关闭;传 true 或 { maxCheckpoints?, auto? } 开启 */
|
|
749
|
+
checkpoint?: boolean | { maxCheckpoints?: number; auto?: boolean };
|
|
750
|
+
/** MCP server 列表(连远程 server 动态注入其 tools;浏览器仅 http/sse/websocket) */
|
|
751
|
+
mcp?: McpServerConfig[];
|
|
752
|
+
/** 上下文压缩配置(false 关闭;默认 LLM 摘要,失败回退索引摘要) */
|
|
753
|
+
contextOptions?: any;
|
|
754
|
+
/** 上下文压缩预设档位(默认 'auto'):auto / conservative / aggressive / complex(多步复杂任务/大 JSON);提供合理默认,contextOptions 细参可覆盖 */
|
|
755
|
+
contextPreset?: 'auto' | 'conservative' | 'aggressive' | 'complex';
|
|
756
|
+
/** 摘要压缩专用 LLM(BaseChatModel 实例或 LLMConfig);不传则默认用主 agent 模型(llm) */
|
|
757
|
+
summaryLlm?: any;
|
|
758
|
+
/** 标题生成 LLM(BaseChatModel 实例或 LLMConfig);不传则用 summaryLlm → 主 llm。首轮后自动生成会话标题(主旨) */
|
|
759
|
+
titleLlm?: any;
|
|
760
|
+
/** 自动生成会话标题(默认 true:首轮后调 LLM 生成主旨标题;false 关闭,用规则 deriveTitle 截取) */
|
|
761
|
+
autoTitle?: boolean;
|
|
762
|
+
/** 摘要 LLM 温度(默认 0.3) */
|
|
763
|
+
summaryTemperature?: number;
|
|
764
|
+
/** 摘要 LLM 输出上限(默认 1024) */
|
|
765
|
+
summaryMaxTokens?: number;
|
|
766
|
+
/** 摘要 LLM 超时毫秒(默认 15000;超时回退索引摘要) */
|
|
767
|
+
summaryTimeoutMs?: number;
|
|
768
|
+
/**
|
|
769
|
+
* SDK 事件回调:订阅常用时机(数据槽变化 / 消息更新 / 工具调用 / 流式文本 / 轮次 / 错误)。
|
|
770
|
+
* UI 与 headless 模式均生效;用于外部联动(宿主页面响应式刷新、埋点、日志),替代轮询。
|
|
771
|
+
* approval_request 不外发(UI 已处理)。
|
|
772
|
+
*/
|
|
773
|
+
onEvent?: SdkEventHandler;
|
|
774
|
+
/** 流式输出(默认 true);false 时等整段回复再显示 */
|
|
775
|
+
streaming?: boolean;
|
|
776
|
+
/** Dialog UI config (title/placeholder/drawer/drawerWidth/drawerHidden/inputRows/onClose grouped) */
|
|
777
|
+
dialog?: DialogConfig;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
/** Dialog UI config (grouped form, recommended) */
|
|
781
|
+
export interface DialogConfig {
|
|
782
|
+
title?: string;
|
|
783
|
+
placeholder?: string;
|
|
784
|
+
drawer?: boolean;
|
|
785
|
+
drawerWidth?: number | string;
|
|
786
|
+
drawerHidden?: boolean;
|
|
787
|
+
/** Input box rows (visible height); default 2 (2-row initial height, auto-expands up to max-height:100px). 1 = single row; >2 = taller. */
|
|
788
|
+
inputRows?: number;
|
|
789
|
+
onClose?: () => void;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
/** 会话级任务目标锚点(mission 中间件;capture 或 setMission;revive-mission-anchor Phase 1) */
|
|
793
|
+
/** 跨压缩工作记忆(workingMemory 中间件;经 augmentPrompt 每轮注入 system,天然跨压缩保留) */
|
|
794
|
+
export interface WorkingMemory {
|
|
795
|
+
locatedPaths: string[];
|
|
796
|
+
lastHashes: Record<string, string>;
|
|
797
|
+
}
|
|
798
|
+
export interface Mission {
|
|
799
|
+
/** 一句话任务目标(必填) */
|
|
800
|
+
goal: string;
|
|
801
|
+
/** 完成标准(可选,集成方显式传入) */
|
|
802
|
+
acceptanceCriteria?: string[];
|
|
803
|
+
/** 来源 user 消息 index(自动 capture 时填) */
|
|
804
|
+
sourceMessageIdx: number;
|
|
805
|
+
/** capture/setMission 时间戳 */
|
|
806
|
+
capturedAt: number;
|
|
807
|
+
/** true=集成方显式 setMission;false=自动 capture */
|
|
808
|
+
explicit: boolean;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
/** 上下文聚焦焦点(focus 中间件;指定组件精修,path=jsonPath 锚点,聚焦后目标/视野/范围三层收敛) */
|
|
812
|
+
export interface Focus {
|
|
813
|
+
/** jsonPath 锚点,如 `components.3`(setFocus 时经 getSchemaAtPath 校验在 schema 内才可聚焦) */
|
|
814
|
+
path: string;
|
|
815
|
+
/** 人类可读标签,如「导航栏」(注入目标提示 + ChatDialog chip 显示;可选) */
|
|
816
|
+
label?: string;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
export interface ChatSdk {
|
|
820
|
+
/** 渲染对话框到 container(异步:含持久化恢复);ui:false 时仅 init agent(headless)。
|
|
821
|
+
* 可选传 overrideContainer(HTMLElement | 选择器字符串)覆盖创建时 options.container —— 异步绑定:创建时可省略 container,mount 时才指定 */
|
|
822
|
+
mount(overrideContainer?: HTMLElement | string): Promise<void>;
|
|
823
|
+
/** 响应式消息数组(headless 模式自建 UI 读) */
|
|
824
|
+
messages: AgentMessage[];
|
|
825
|
+
unmount(): void;
|
|
826
|
+
/** 抽屉模式隐藏:加 cs-hidden class,不卸载 vueApp/不 release agent —— 保留聊天历史与正在进行的生成进程;再 mount() 直接 show 恢复 */
|
|
827
|
+
hide(): void;
|
|
828
|
+
/** 抽屉模式显示:移除 cs-hidden class 恢复可见(配合 hide 使用;首次挂载用 mount) */
|
|
829
|
+
show(): void;
|
|
830
|
+
send(message: string, options?: { mission?: Partial<Mission> }): Promise<string>;
|
|
831
|
+
switchSession(sessionId?: string): Promise<string>;
|
|
832
|
+
/** 列出当前 agent 的所有历史会话(供「历史列表」UI;storage 未开启 → []) */
|
|
833
|
+
listSessions(): Promise<SessionMeta[]>;
|
|
834
|
+
/** 历史会话列表(响应式;switchSession/deleteSession/onClear/init 后自动 refresh;直接消费无需手动 listSessions/refresh/hook) */
|
|
835
|
+
readonly sessions: import('vue').Ref<SessionMeta[]>;
|
|
836
|
+
/** 删除指定历史会话;不可删除当前会话(删当前请先 switchSession 切走);storage 未开启 → no-op + warn */
|
|
837
|
+
deleteSession(sessionId: string): Promise<void>;
|
|
838
|
+
/** 当前会话 id(switchSession/onClear 后实时反映;供历史列表高亮当前项) */
|
|
839
|
+
readonly sessionId: string;
|
|
840
|
+
stream: (messages: AgentMessage[], onEvent: StreamHandler, signal?: AbortSignal) => Promise<string>;
|
|
841
|
+
/** 显式持久化当前轮(headless 用 sdk.stream 时需手动调:把 messages/vfs/todos 存 store;内置 useChat 经 onPersist 自动调。storage 未开启 → no-op) */
|
|
842
|
+
afterRound(): void;
|
|
843
|
+
/** 调试日志(LLM 请求/响应/工具调用/中间件/错误;switchSession/onClear 清空;供 DebugDrawer 或外部消费) */
|
|
844
|
+
readonly debugLogs: Ref<DebugLog[]>;
|
|
845
|
+
/** Agent 信息刷新 tick(setSkills/setData/setFocus 后 ++);传给 DebugDrawer watch 后重拉 inspect() 实时反映 */
|
|
846
|
+
readonly infoTick: Ref<number>;
|
|
847
|
+
/** 检视 agent 详细信息(tools/skills/data/middleware/todos) */
|
|
848
|
+
inspect(): AgentInfo;
|
|
849
|
+
/** 读取最近一次上下文构成快照(每轮 wrapModelCall 覆盖;capabilities.contextInspector:false → undefined) */
|
|
850
|
+
inspectContext(): ContextSnapshot | undefined;
|
|
851
|
+
/** 读取当前任务目标锚点 mission(自动 capture 或 setMission;capabilities.missionAnchor:false → undefined) */
|
|
852
|
+
getMission(): Mission | undefined;
|
|
853
|
+
/** 显式设置/覆盖 mission(传 {goal} 重设;传 {goal,criteria} 整体替换;传 {} 清空);capabilities 关时 warn 不抛 */
|
|
854
|
+
setMission(mission: Partial<Mission>): void;
|
|
855
|
+
/** 读取当前聚焦焦点(兼容:返回首个;未聚焦 / capabilities.focus:false → undefined) */
|
|
856
|
+
getFocus(): Focus | undefined;
|
|
857
|
+
/** 读取全部聚焦焦点(multi-focus;空数组=未聚焦;capabilities.focus:false → []) */
|
|
858
|
+
getFocuses(): Focus[];
|
|
859
|
+
/** 设置聚焦焦点(替换全部;path 经 getSchemaAtPath 校验);非法 path 返回 {ok:false,error};capabilities.focus:false 返回 {ok:false} 不抛 */
|
|
860
|
+
setFocus(focus: Focus): { ok: boolean; error?: string };
|
|
861
|
+
/** 追加聚焦焦点(multi-focus 累积,去重 by path;校验同 setFocus);capabilities.focus:false 返回 {ok:false} */
|
|
862
|
+
addFocus(focus: Focus): { ok: boolean; error?: string };
|
|
863
|
+
/** 移除单个聚焦焦点(by path);capabilities.focus:false → no-op */
|
|
864
|
+
removeFocus(path: string): void;
|
|
865
|
+
/** 清除全部聚焦焦点(退出精修模式,恢复全量可操作范围) */
|
|
866
|
+
clearFocus(): void;
|
|
867
|
+
/** 回退到最近一次正常 checkpoint(整体还原对话历史 + 主数据 + vfs + todos);需开启 checkpoint,无可用返回 false */
|
|
868
|
+
restoreLastCheckpoint(): boolean;
|
|
869
|
+
/** 列出可用 checkpoint(回退点);需开启 checkpoint,未开启返回空数组 */
|
|
870
|
+
listCheckpoints(): CheckpointMeta[];
|
|
871
|
+
/**
|
|
872
|
+
* 批处理(automation):逐任务跑 agent,每任务前自动 checkpoint,任务间错误隔离(单任务失败记 error 不中断整批)。
|
|
873
|
+
* 适合无人值守批量操作(批量生成/改一批页面)。不经 UI 排队(直接 invoke);返回每个任务结果(成功 reply / 失败 error)。
|
|
874
|
+
* 配合 capabilities.automation + checkpoint 使用。
|
|
875
|
+
*/
|
|
876
|
+
batch(tasks: string[], onProgress?: (p: BatchProgress) => void): Promise<BatchResult[]>;
|
|
877
|
+
/** 运行时订阅 SDK 事件(可多个监听器,返回取消函数);与构造时 onEvent 互补 */
|
|
878
|
+
hook(handler: SdkEventHandler): () => void;
|
|
879
|
+
/** 运行时替换主数据配置(如页面切换、schema 变更);立即对数据工具生效,无需重建 agent。需开启 dataOps */
|
|
880
|
+
setData(config: DataConfig): void;
|
|
881
|
+
/** 读取当前主数据配置;dataOps 关闭时返回 undefined */
|
|
882
|
+
getData(): DataConfig | undefined;
|
|
883
|
+
/**
|
|
884
|
+
* 运行时替换整个 skill 列表(同名 skill 覆盖更新)。立即生效:system prompt 的 skill 索引段下轮重渲染反映新 skill;
|
|
885
|
+
* 清空 skill 全文缓存与本轮已加载记录,下次 load_skill 重新取最新全文(含 vfs doc)。需开启 skills(默认开)
|
|
886
|
+
*/
|
|
887
|
+
setSkills(skills: SkillSpec[]): void;
|
|
888
|
+
/** 添加用户创建的 skill(持久化,跨刷新恢复;同名覆盖)。需开启 skills(默认开) */
|
|
889
|
+
addSkill(skill: SkillSpec): void;
|
|
890
|
+
/** 删除用户创建的 skill(仅删用户创建的,不删集成方 initialSkills)。返回是否删除成功 */
|
|
891
|
+
removeSkill(name: string): boolean;
|
|
892
|
+
/** 列出用户创建的 skill 名(仅用户创建的,不含集成方 initialSkills) */
|
|
893
|
+
listUserSkills(): string[];
|
|
894
|
+
/** 读取用户创建的 skill 详情(返回 {name, description, content};不存在返回 undefined) */
|
|
895
|
+
getUserSkill(name: string): { name: string; description: string; content: string } | undefined;
|
|
896
|
+
/**
|
|
897
|
+
* 清 skill 全文缓存(动态 skill 内容变化时主动失效)。不传 name 清全部;传 name 清指定。
|
|
898
|
+
* 下次 load_skill 重新 getContent/readSkillDoc 取最新。需开启 skills(默认开)
|
|
899
|
+
*/
|
|
900
|
+
invalidateSkillCache(name?: string): void;
|
|
901
|
+
/** 导出主数据 bind 的深拷贝(备份/迁移用);dataOps 关闭或无 data 返回 null */
|
|
902
|
+
exportData(): any;
|
|
903
|
+
/** 导入数据整体替换主数据 bind(就地还原,保留 reactive 引用);默认经 schema 校验,不合法返回 {ok:false,error};opts.validate:false 跳过校验,opts.emit:false 不发 data_change */
|
|
904
|
+
importData(json: any, opts?: { validate?: boolean; emit?: boolean }): { ok: boolean; error?: string };
|
|
905
|
+
/** 创建/注册受保护资源(返回 handle);需配 data.resources + vfsStore,否则抛错 */
|
|
906
|
+
createResource(path: string, value?: unknown): string;
|
|
907
|
+
/** 取受保护资源真值(by path 或 handle);不存在返 undefined */
|
|
908
|
+
getResource(pathOrHandle: string): { path: string; mode: string; value: unknown; handle: string } | undefined;
|
|
909
|
+
/** 更新 verbatim 受保护资源真值(同步 bind+标脏);freeze 抛错 */
|
|
910
|
+
updateResource(path: string, value: unknown): void;
|
|
911
|
+
/** 删除/释放单个受保护资源(by path 或 handle);返是否存在过 */
|
|
912
|
+
deleteResource(pathOrHandle: string): boolean;
|
|
913
|
+
/** 列出全部受保护资源(path/mode/handle/bytes) */
|
|
914
|
+
listResources(): { path: string; mode: string; handle: string; bytes: number }[];
|
|
915
|
+
/** 批量释放受保护资源;传 paths 释放指定,未传释放全部 */
|
|
916
|
+
releaseResources(paths?: string[]): void;
|
|
917
|
+
/** 累计 token 用量(每轮 LLM 调用累加;prompt/completion/total_tokens)。无调用时为 0 */
|
|
918
|
+
usage: TokenUsage;
|
|
919
|
+
/** 乐观锁冲突挂起状态(响应式 ref;无冲突为 null,有冲突时 UI 据此渲染冲突对话框)。headless 集成方可 watch 自建 UI */
|
|
920
|
+
pendingConflict: Ref<PendingConflict | null>;
|
|
921
|
+
/** 冲突解决:用户点「保留外部」(keep_external)/「强制覆盖」(overwrite)/「回退」(restore) → 收口挂起的 conflict,被挂起的工具调用继续 */
|
|
922
|
+
resolveConflict(action: ConflictResolution['action']): void;
|
|
923
|
+
/** 运行时替换用户工具集(内置工具不动);立即 rebind + infoTick 刷新 */
|
|
924
|
+
setTools(tools: any[]): void;
|
|
925
|
+
/** 运行时追加用户工具(去重 by name);立即生效 */
|
|
926
|
+
addTool(tool: any): void;
|
|
927
|
+
/** 运行时移除用户工具(by name;内置不动);返回是否移除成功 */
|
|
928
|
+
removeTool(name: string): boolean;
|
|
929
|
+
/** 运行时切换 LLM(BaseChatModel 或 LLMConfig);rebind + 重解析能力 + infoTick */
|
|
930
|
+
setLlm(llm: ChatModelLike | LLMConfig): void;
|
|
931
|
+
/** 运行时更新 memory;支持 string 与同步/异步函数(异步函数后台求值,下一轮 beforeAgent 前就绪) */
|
|
932
|
+
setMemory(source: string | (() => string | Promise<string>)): void;
|
|
933
|
+
/** 重新求值当前 memory 函数 source(RAG 文档更新后强制刷新);返回最新文本 */
|
|
934
|
+
refreshMemory(): Promise<string>;
|
|
935
|
+
/** 运行时替换预声明子 agent 列表(重新生成委派工具 + rebind);需创建时配 subagents:[] */
|
|
936
|
+
setSubagents(configs: SubagentConfig[]): void;
|
|
937
|
+
/** 运行时追加预声明子 agent(id 重复 warn 跳过);需创建时配 subagents:[] */
|
|
938
|
+
addSubagent(config: SubagentConfig): void;
|
|
939
|
+
/** 运行时移除预声明子 agent(by id);返回是否移除成功;需创建时配 subagents:[] */
|
|
940
|
+
removeSubagent(id: string): boolean;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
/** 乐观锁冲突挂起(dataOps 写入时 expectedHash 不匹配,挂起等用户决定) */
|
|
944
|
+
export interface PendingConflict {
|
|
945
|
+
id: number;
|
|
946
|
+
op: 'set' | 'edit' | 'delete';
|
|
947
|
+
agentValue?: unknown;
|
|
948
|
+
currentValue: unknown;
|
|
949
|
+
currentHash: string;
|
|
950
|
+
expectedHash: string;
|
|
951
|
+
snapshotId: number;
|
|
952
|
+
resolve: (r: ConflictResolution) => void;
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
/** 冲突解决决定:保留外部修改 / 强制覆盖 / 回退到写前快照 */
|
|
956
|
+
export type ConflictResolution =
|
|
957
|
+
| { action: 'keep_external' }
|
|
958
|
+
| { action: 'overwrite' }
|
|
959
|
+
| { action: 'restore' };
|
|
960
|
+
|
|
961
|
+
/** 乐观锁冲突信息(dataOps onConflict 回调参数) */
|
|
962
|
+
export interface ConflictInfo {
|
|
963
|
+
op: 'set' | 'edit' | 'delete';
|
|
964
|
+
agentValue?: unknown;
|
|
965
|
+
currentValue: unknown;
|
|
966
|
+
currentHash: string;
|
|
967
|
+
expectedHash: string;
|
|
968
|
+
snapshotId: number;
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
export declare function createChatSdk(options: ChatSdkOptions): ChatSdk;
|
|
972
|
+
// ============ system prompt 构建(promptBuilder,refactor-module-extraction 从 createChatSdk 抽离)============
|
|
973
|
+
/** 默认 systemPrompt(用户未传 systemPrompt 时用);含身份 + 能力概述 + 可靠写入规则 */
|
|
974
|
+
export declare const DEFAULT_SYSTEM_PROMPT: string;
|
|
975
|
+
/** 拼接「可操作数据」段(从 data schema .describe() 自动提取注入) */
|
|
976
|
+
export declare function buildDataPrompt(data: DataConfig | undefined): string;
|
|
977
|
+
/**
|
|
978
|
+
* 统一 systemPrompt base 段入口:处理 appendReliableWriteRules 分支 + '---' 分割线。
|
|
979
|
+
* 传 systemPrompt 默认追加 reliableWriteRules(设 appendReliableWriteRules:false 关闭);不传用 DEFAULT_SYSTEM_PROMPT(已内置)。纯函数。
|
|
980
|
+
*/
|
|
981
|
+
export declare function buildSystemPrompt(opts: { systemPrompt?: string; appendReliableWriteRules?: boolean }): string;
|
|
982
|
+
export declare function defineTool(opts: {
|
|
983
|
+
name: string;
|
|
984
|
+
description: string;
|
|
985
|
+
schema: any;
|
|
986
|
+
handler: (args: any) => unknown | Promise<unknown>;
|
|
987
|
+
}): any;
|
|
988
|
+
export declare function createDataOps(config: DataConfig, opts?: DataOpsOptions): any[];
|
|
989
|
+
export declare function filterByToolMode(tools: any[], mode?: 'simple' | 'advanced' | 'minimal'): any[];
|
|
990
|
+
/** 整体 set 写入纯函数:schema 校验 + 快照 + merge/替换 + audit。set_data / write(set) / draft_commit 共用。返回 {ok,hash,data} 或 {ok:false,error} */
|
|
991
|
+
export declare function commitSetToBind(args: { bindRef: unknown; value: unknown; schema: any; allowKeys: string[] | null; snapshots: any[]; maxSnapshots: number; audit: (e: any) => void; dryRun?: boolean; op?: 'set' | 'draft_commit' }): { ok: true; hash: string; data: unknown } | { ok: false; error: string };
|
|
992
|
+
/** 结构化追踪 span(revive-observability-tracing Phase 3) */
|
|
993
|
+
export type SpanType = 'round' | 'model' | 'tool' | 'compression';
|
|
994
|
+
export type SpanStatus = 'ok' | 'error' | 'timeout';
|
|
995
|
+
export interface TraceSpan {
|
|
996
|
+
id: string;
|
|
997
|
+
parentId?: string;
|
|
998
|
+
name: string;
|
|
999
|
+
type: SpanType;
|
|
1000
|
+
startTs: number;
|
|
1001
|
+
endTs?: number;
|
|
1002
|
+
durationMs?: number;
|
|
1003
|
+
status: SpanStatus;
|
|
1004
|
+
attributes: Record<string, unknown>;
|
|
1005
|
+
}
|
|
1006
|
+
export interface TraceMetrics {
|
|
1007
|
+
rounds: number;
|
|
1008
|
+
totalDurationMs: number;
|
|
1009
|
+
avgRoundMs: number;
|
|
1010
|
+
toolCalls: number;
|
|
1011
|
+
toolFailures: number;
|
|
1012
|
+
toolSuccessRate: number;
|
|
1013
|
+
modelCalls: number;
|
|
1014
|
+
retries: number;
|
|
1015
|
+
compressions: number;
|
|
1016
|
+
totalTokens?: { prompt: number; completion: number; total: number };
|
|
1017
|
+
}
|
|
1018
|
+
/** 从 TraceSpan[] 聚合 metrics(纯函数:轮次/延迟/工具成功率/重试/压缩/token) */
|
|
1019
|
+
export declare function getTraceMetrics(spans: TraceSpan[]): TraceMetrics;
|
|
1020
|
+
// ============ 通用 JSON 操作纯函数(jsonUtils,refactor-module-extraction 从 dataOps 抽离;零依赖,经 ./query subpath 按需引入)============
|
|
1021
|
+
export type EditOp = 'set' | 'remove' | 'merge' | 'append';
|
|
1022
|
+
export declare const UNSAFE_KEYS: Set<string>;
|
|
1023
|
+
export declare function isUnsafePath(path: string): boolean;
|
|
1024
|
+
export declare function safeMerge(target: Record<string, any>, src: unknown): void;
|
|
1025
|
+
export declare function getByPath(obj: unknown, path: string): unknown;
|
|
1026
|
+
export declare function setByPath(obj: unknown, path: string, value: unknown): void;
|
|
1027
|
+
export declare function deleteByPath(obj: unknown, path: string): boolean;
|
|
1028
|
+
export declare function deepClone<T>(v: T): T;
|
|
1029
|
+
export declare function maybeParseValue(v: unknown): { parsed?: unknown; parseError?: unknown };
|
|
1030
|
+
export declare function projectFields(obj: unknown, fields: string[]): unknown;
|
|
1031
|
+
export declare function limitDepth(obj: unknown, depth: number): unknown;
|
|
1032
|
+
export declare function safeStringify(value: unknown, maxLen?: number): string;
|
|
1033
|
+
export declare function hashValue(value: unknown): string;
|
|
1034
|
+
export declare function applyPatchToClone(clone: any, op: EditOp, jsonPath: string, value: unknown): string | null;
|
|
1035
|
+
export declare function applyPatchToLive(bind: any, op: EditOp, jsonPath: string, value: unknown): void;
|
|
1036
|
+
export declare function restoreLive(bind: any, snapshotVal: unknown): void;
|
|
1037
|
+
export declare function restoreInPlace(live: Record<string, unknown> | unknown[], snapshotVal: unknown): void;
|
|
1038
|
+
/** 深度差异对比(对象/数组递归,叶子差异),返回 {path, from, to}[];供 diff_data / verify 自纠 / 审计复用 */
|
|
1039
|
+
export declare function diffObjects(a: unknown, b: unknown, prefix?: string): { path: string; from: unknown; to: unknown }[];
|
|
1040
|
+
// ============ schema 白名单投影纯函数(schemaUtils,refactor-module-extraction 从 dataOps 抽离)============
|
|
1041
|
+
export declare function getSchemaTopKeys(schema: any): string[] | null;
|
|
1042
|
+
export declare function isPathAllowed(jsonPath: string, schema: any | null, allowKeys: string[] | null): boolean;
|
|
1043
|
+
export declare function unwrapSchema(schema: any): any;
|
|
1044
|
+
export declare function getSchemaAtPath(schema: any, jsonPath: string): any | null;
|
|
1045
|
+
export declare function projectBySchemaDeep(obj: unknown, schema: any | null): unknown;
|
|
1046
|
+
export declare function projectBySchema(obj: unknown, allowKeys: string[] | null): unknown;
|
|
1047
|
+
// ============ schema 约束结构化提取(expose-schema-constraints;供 systemPrompt「可操作数据」段 / read 概览 / schema_data 工具)============
|
|
1048
|
+
export interface SchemaNodeDesc {
|
|
1049
|
+
type: string;
|
|
1050
|
+
constraints?: {
|
|
1051
|
+
minLength?: number; maxLength?: number; length?: number;
|
|
1052
|
+
min?: number; max?: number; int?: boolean;
|
|
1053
|
+
format?: string | string[];
|
|
1054
|
+
values?: readonly (string | number)[];
|
|
1055
|
+
value?: unknown;
|
|
1056
|
+
item?: SchemaNodeDesc;
|
|
1057
|
+
shape?: Record<string, SchemaNodeDesc>;
|
|
1058
|
+
anyOf?: SchemaNodeDesc[];
|
|
1059
|
+
valueType?: SchemaNodeDesc;
|
|
1060
|
+
};
|
|
1061
|
+
optional?: boolean;
|
|
1062
|
+
nullable?: boolean;
|
|
1063
|
+
default?: unknown;
|
|
1064
|
+
description?: string;
|
|
1065
|
+
}
|
|
1066
|
+
/** 结构化提取单个 zod 节点的约束(type + 关键约束 + optional/default/nullable;zod 4 `_def`/`_zod.def` 读取) */
|
|
1067
|
+
export declare function describeSchemaNode(schema: any): SchemaNodeDesc;
|
|
1068
|
+
/** 把标量约束格式化为括号内短串(min/max/enum/format 等;shape/item/anyOf 不渲染) */
|
|
1069
|
+
export declare function formatConstraints(c: NonNullable<SchemaNodeDesc['constraints']>): string;
|
|
1070
|
+
/** 渲染单行字段标注 `- key (Type?)[约束]: description` */
|
|
1071
|
+
export declare function renderSchemaHint(key: string, desc: SchemaNodeDesc): string;
|
|
1072
|
+
/** 渲染 schema 顶层字段约束总览(非 object fallback 根节点;供 extractSchemaHint + read 概览复用) */
|
|
1073
|
+
export declare function renderSchemaOverview(schema: any): string;
|
|
1074
|
+
/** 渲染 schema 顶层字段浅概览(分层模式:只 key+type+desc,不带约束/不递归;大 schema 用,体积降) */
|
|
1075
|
+
export declare function renderSchemaShallow(schema: any): string;
|
|
1076
|
+
/** extractSchemaHint 分层阈值配置(默认 maxKeys=15/maxChars=4000;超则转顶层概览) */
|
|
1077
|
+
export interface SchemaHintOptions { maxKeys?: number; maxChars?: number }
|
|
1078
|
+
// ============ 上下文索引纯函数(contextIndex,refactor-module-extraction 期二 从 useContextManager 抽离)============
|
|
1079
|
+
export declare const STOP_WORDS: Set<string>;
|
|
1080
|
+
export declare function tokenize(text: string): string[];
|
|
1081
|
+
export declare function estimateMessageTokens(m: any): number;
|
|
1082
|
+
export declare function estimateRoundTokens(r: any): number;
|
|
1083
|
+
export declare function indexSummarize(older: any[], preserve?: Set<string>): string;
|
|
1084
|
+
export declare function recallRounds(older: any[], query: string, topK: number): any[];
|
|
1085
|
+
export declare function shouldTriggerCompression(rounds: any[], config: { contextWindow?: number; summaryThresholdRatio?: number; summaryThresholdRounds?: number }): boolean;
|
|
1086
|
+
// ============ LLM 解析(llmResolver,refactor-module-extraction 期二 从 createChatSdk 抽离)============
|
|
1087
|
+
export declare function isChatModel(v: unknown): boolean;
|
|
1088
|
+
export declare function resolveLlm(options: any): { modelCaps: any; summaryLlmInvoke: ((prompt: string) => Promise<string>) | undefined };
|
|
1089
|
+
export declare function deriveTitle(msgs: AgentMessage[]): string | undefined;
|
|
1090
|
+
// ============ 乐观锁冲突管理器(conflictManager,refactor-module-extraction 期二 从 createChatSdk 抽离)============
|
|
1091
|
+
export interface ConflictManager {
|
|
1092
|
+
pendingConflict: import('vue').Ref<any | null>;
|
|
1093
|
+
set(info: any): Promise<any>;
|
|
1094
|
+
resolve(action: any): void;
|
|
1095
|
+
}
|
|
1096
|
+
export declare function createConflictManager(getEmit?: () => (((e: any) => void) | undefined)): ConflictManager;
|
|
1097
|
+
// ============ 配置解析 + 事件系统(optionsResolver/events,refactor-module-extraction 期三)============
|
|
1098
|
+
// capabilities 能力开关注册表 + 单一解析(p2-refactor 子项 4:消除 11/17 开关 ===true/!==false 混)
|
|
1099
|
+
export interface Capability { name: string; defaultOn: boolean; requires?: readonly string[] }
|
|
1100
|
+
export type CapabilityFlags = Partial<Record<string, boolean>>;
|
|
1101
|
+
export type ResolvedCapabilities = Record<string, boolean>;
|
|
1102
|
+
export declare const CAPABILITIES: readonly Capability[];
|
|
1103
|
+
/** 单一解析:集成方原始 caps(Partial)→ 全量 boolean(opt-out 默认开 !==false / opt-in 默认关 ===true;requires 依赖未满足强制关)。参数宽松 Record<string,unknown>(兼容含 subagents 等非 boolean 字段的 caps 对象;只读已知 capability 的 boolean) */
|
|
1104
|
+
export declare function resolveCapabilities(caps?: Record<string, unknown>): ResolvedCapabilities;
|
|
1105
|
+
export declare function resolveStorage(storage: any): any | null;
|
|
1106
|
+
export declare function resolveDialogConfig(opts: any): any;
|
|
1107
|
+
export interface SdkEvents {
|
|
1108
|
+
listeners: Set<(e: any) => void>;
|
|
1109
|
+
emit: (e: any) => void;
|
|
1110
|
+
hook(handler: (e: any) => void): () => void;
|
|
1111
|
+
}
|
|
1112
|
+
export declare function createSdkEvents(onEvent?: (e: any) => void): SdkEvents;
|
|
1113
|
+
export declare function selectBuiltinTools(caps: { dataOps?: boolean; fetch?: boolean; domInspect?: boolean; inspectEnv?: boolean } | undefined, dataOps: any[], fetchDocs: any[], dom?: any[], inspect?: any[]): any[];
|
|
1114
|
+
export declare function createUsageHintsMiddleware(caps: { planning?: boolean; dataOps?: boolean; subagent?: boolean } | undefined, hasDataOps: boolean, toolMode?: 'simple' | 'advanced' | 'minimal'): any;
|
|
1115
|
+
export declare const fetchDocTools: any[];
|
|
1116
|
+
/** DOM 读取工具 get_dom(随 capabilities.domInspect 装配,opt-in) */
|
|
1117
|
+
export declare const domTools: any[];
|
|
1118
|
+
export declare const domToolsStatic: any[];
|
|
1119
|
+
/** 环境探查工具 inspect_env(随 capabilities.inspectEnv 默认装配,默认开;排查 window/location/调试变量) */
|
|
1120
|
+
export declare const inspectTools: any[];
|
|
1121
|
+
/** 单个 inspect_env 工具(inspectTools 数组的元素) */
|
|
1122
|
+
export declare const inspectEnvTool: any;
|
|
1123
|
+
/** 纯函数:安全序列化任意值(跳过 function/DOM,防循环引用,截断)—— inspect_env 读 window[key] 时用 */
|
|
1124
|
+
export declare function safeSerialize(value: unknown, depth?: number, maxLen?: number, seen?: WeakSet<object>): unknown;
|
|
1125
|
+
/** 环境摘要(location/navigator/viewport/document);inspect_env 无参时返回,可传 win 注入测试 */
|
|
1126
|
+
export declare function getEnvSummary(win?: Window & typeof globalThis): Record<string, unknown>;
|
|
1127
|
+
export declare const getDomTool: any;
|
|
1128
|
+
/** 纯函数:DOM Element → 结构化 DomNode(可单测,与浏览器解耦) */
|
|
1129
|
+
export declare function domToStructure(node: Element | null, opts: { depth: number; attrs?: string[]; includeText?: boolean }): DomNode | null;
|
|
1130
|
+
/** 把集成方注册的 actions 转成命名 tool 数组(每个 action 一个 tool) */
|
|
1131
|
+
export declare function actionsToTools(actions: ActionMap): any[];
|
|
1132
|
+
export declare function actionsToInspectInfo(actions: ActionMap): Record<string, { description: string; hasParams: boolean }>;
|
|
1133
|
+
export interface DomNode { tag: string; attrs: Record<string, string>; text?: string; children?: DomNode[]; childCount?: number }
|
|
1134
|
+
export interface DomReadOptions { depth: number; attrs?: string[]; includeText?: boolean }
|
|
1135
|
+
export declare const fetchTools: any[];
|
|
1136
|
+
export declare function defineDataToolset(config: DataConfig, opts?: DataOpsOptions): any[];
|
|
1137
|
+
export declare function defineSkill(spec: SkillSpec): SkillSpec;
|
|
1138
|
+
export declare function createAgent(options: any): any;
|
|
1139
|
+
/** 检测模型把工具调用写成文本(伪 XML/标签)而非标准 tool_calls 的异常格式;主循环据此回灌 feedback 自纠 */
|
|
1140
|
+
export declare function detectGarbledToolCall(content: string): boolean;
|
|
1141
|
+
export declare function createSubagentMiddleware(opts: any): any;
|
|
1142
|
+
export declare function createVerifyMiddleware(opts: VerifyMiddlewareOptions): any;
|
|
1143
|
+
export declare function createWriteBackCheck(opts?: WriteBackCheckOptions): VerifyCheck;
|
|
1144
|
+
export declare function createMemoryMiddleware(memory?: string | (() => string | Promise<string>)): any;
|
|
1145
|
+
export type MemorySource = string | (() => string | Promise<string>);
|
|
1146
|
+
export declare const presets: Record<string, any>;
|
|
1147
|
+
/** systemPrompt 辅助片段(标准化最佳实践,拼进 systemPrompt 降低写错门槛) */
|
|
1148
|
+
export declare const systemPromptHelpers: {
|
|
1149
|
+
/** 可靠写入规则:改前先读、动态先 list、字段以 describe 为准、写错看校验错误重试、优先增量 patch */
|
|
1150
|
+
readonly reliableWriteRules: string;
|
|
1151
|
+
};
|
|
1152
|
+
/** 从 zod schema 提取字段说明(io 契约注入 systemPrompt 用);非 object schema 用 description 兜底 */
|
|
1153
|
+
export declare function extractSchemaHint(schema: any): string;
|
|
1154
|
+
export declare function createSessionStore(config?: StorageConfig): SessionStore;
|
|
1155
|
+
export declare function createMemoryBackend(): StorageBackend;
|
|
1156
|
+
export declare function createWebStorageBackend(storage: Storage): StorageBackend;
|
|
1157
|
+
export declare function isQuotaError(err: unknown): boolean;
|
|
1158
|
+
/** 创建 Skill 独立持久化存储(与 storage 选项分离;默认 indexedDB,可手动指定 id 跨页复用) */
|
|
1159
|
+
export declare function createSkillStore(config?: SkillStoreConfig): SkillStore;
|
|
1160
|
+
export interface SkillStore {
|
|
1161
|
+
ready: Promise<boolean>;
|
|
1162
|
+
list(): Promise<PersistedSkill[]>;
|
|
1163
|
+
get(name: string): Promise<PersistedSkill | undefined>;
|
|
1164
|
+
put(skill: PersistedSkill): Promise<void>;
|
|
1165
|
+
remove(name: string): Promise<boolean>;
|
|
1166
|
+
clear(): Promise<void>;
|
|
1167
|
+
dispose(): void;
|
|
1168
|
+
}
|
|
1169
|
+
/** 持久化的用户创建 skill(getContent 函数不可序列化,故 content 直接存字符串) */
|
|
1170
|
+
export interface PersistedSkill {
|
|
1171
|
+
name: string;
|
|
1172
|
+
description: string;
|
|
1173
|
+
content: string;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
// ============ 大 JSON 查询/搜索/沙箱脚本(dataSlotQuery)============
|
|
1177
|
+
export interface JpNode {
|
|
1178
|
+
/** 相对属性根的点号路径(数组索引用数字,如 components.0.text) */
|
|
1179
|
+
path: string;
|
|
1180
|
+
/** 匹配元素值 */
|
|
1181
|
+
value: unknown;
|
|
1182
|
+
/** 父为数组时的索引(便于后续 edit_data_slot 的 jsonPath 定位) */
|
|
1183
|
+
index?: number;
|
|
1184
|
+
}
|
|
1185
|
+
export interface SearchHit {
|
|
1186
|
+
path: string;
|
|
1187
|
+
key?: string;
|
|
1188
|
+
value: string;
|
|
1189
|
+
score?: number;
|
|
1190
|
+
}
|
|
1191
|
+
export type SearchMode = 'substring' | 'regex' | 'fuzzy';
|
|
1192
|
+
export interface EvalResult {
|
|
1193
|
+
ok: boolean;
|
|
1194
|
+
result?: unknown;
|
|
1195
|
+
error?: string;
|
|
1196
|
+
elapsedMs: number;
|
|
1197
|
+
}
|
|
1198
|
+
/** JSONPath 查询(只读,无副作用);expr 子集:$ .key [n] ["key"] [*] [?(filter)] ..key ..* */
|
|
1199
|
+
export declare function jpEval(root: unknown, expr: string): JpNode[];
|
|
1200
|
+
/** 在 JSON 子树内搜索文本(substring/regex/fuzzy) */
|
|
1201
|
+
export declare function searchJson(
|
|
1202
|
+
root: unknown,
|
|
1203
|
+
query: string,
|
|
1204
|
+
opts?: { mode?: SearchMode; fuzzyThreshold?: number; matchKey?: boolean; limit?: number },
|
|
1205
|
+
): SearchHit[];
|
|
1206
|
+
/** Web Worker 沙箱执行自定义 JS(无 window/document,禁 fetch/XHR/WebSocket/importScripts,超时可终止) */
|
|
1207
|
+
export declare function runSandboxedScript(data: unknown, script: string, timeoutMs?: number): Promise<EvalResult>;
|
|
1208
|
+
/** 通用 Worker 沙箱结果(eval_script 与 skill exec 共用;EvalResult 的别名同构) */
|
|
1209
|
+
export interface SandboxResult {
|
|
1210
|
+
ok: boolean;
|
|
1211
|
+
result?: unknown;
|
|
1212
|
+
error?: string;
|
|
1213
|
+
elapsedMs: number;
|
|
1214
|
+
}
|
|
1215
|
+
/**
|
|
1216
|
+
* 创建沙箱执行器(柯里化:先绑 script+timeoutMs,再传可选 input)。三层防护:静态扫描禁用模式 +
|
|
1217
|
+
* lockSandboxGlobal defineProperty 锁网络/存储 API(防 delete self.fetch 逃逸)+ 超时 terminate。
|
|
1218
|
+
* 无 input 传 undefined(skill exec);有 input 作 data 入参(eval_script)。
|
|
1219
|
+
*/
|
|
1220
|
+
export declare function createSandboxRunner(script: string, timeoutMs?: number): (input?: unknown) => Promise<SandboxResult>;
|
|
1221
|
+
/** 宿主脚本执行(skill exec context:'host';AsyncFunction 主线程全权,不经静态扫描,需 capabilities.skillHostScript:true) */
|
|
1222
|
+
export declare function runHostScript(code: string, timeoutMs?: number): Promise<SandboxResult>;
|
|
1223
|
+
|
|
1224
|
+
// ============ 工具报错(结构化 ERROR:{json},供 LLM 排查)============
|
|
1225
|
+
export interface ToolErrorInput {
|
|
1226
|
+
/** 机器可读错误码(大写蛇形,如 NOT_REGISTERED / SCHEMA_INVALID / JSON_PARSE / PATH_UNSAFE / NOT_OBJECT / PATCH_FAILED / JSONPATH_SYNTAX / REGEX_INVALID / SCRIPT_TIMEOUT / SCRIPT_ERROR / NOT_FOUND / NO_MATCH / AMBIGUOUS_MATCH) */
|
|
1227
|
+
code: string;
|
|
1228
|
+
/** 人类可读:具体发生了什么 */
|
|
1229
|
+
message: string;
|
|
1230
|
+
/** 建议的修复动作(可操作) */
|
|
1231
|
+
hint?: string;
|
|
1232
|
+
/** 相关属性路径 */
|
|
1233
|
+
path?: string;
|
|
1234
|
+
/** 额外结构化细节(zod issues / 匹配位置 / 实际值等) */
|
|
1235
|
+
details?: unknown;
|
|
1236
|
+
}
|
|
1237
|
+
/** 格式化工具错误为 `ERROR: {json}` 字符串(单行 JSON,前缀 ERROR) */
|
|
1238
|
+
export declare function toolError(e: ToolErrorInput): string;
|
|
1239
|
+
/** zod 校验失败 → toolError(提取 issues 为 details) */
|
|
1240
|
+
export declare function zodError(path: string, issues: unknown[]): string;
|
|
1241
|
+
/** JSON 解析失败 → toolError(带原解析错误 + 预览) */
|
|
1242
|
+
export declare function jsonParseError(path: string | undefined, raw: string, err: unknown): string;
|
|
1243
|
+
/** 提取 zod issues 为结构化 details(每条 path/expected/received/message) */
|
|
1244
|
+
export declare function formatZodIssues(issues: unknown[]): unknown[];
|
|
1245
|
+
// ============ 统一错误模型(unify-error-model:三档 severity,各 catch 点按档路由)============
|
|
1246
|
+
/** 错误严重程度三档:recoverable(回灌)/ fatal(中断)/ observable(记录不中断) */
|
|
1247
|
+
export type ErrorSeverity = 'recoverable' | 'fatal' | 'observable';
|
|
1248
|
+
/** 统一错误对象(结构化,跨层传递;普通 Error 经 asAgentError 归一化) */
|
|
1249
|
+
export interface AgentError {
|
|
1250
|
+
severity: ErrorSeverity;
|
|
1251
|
+
message: string;
|
|
1252
|
+
code?: string;
|
|
1253
|
+
context?: unknown;
|
|
1254
|
+
}
|
|
1255
|
+
/** 错误路由:recoverable→feedback / fatal→abort / observable→log */
|
|
1256
|
+
export type ErrorRouting = 'feedback' | 'abort' | 'log';
|
|
1257
|
+
/** 路由纯函数:据 severity 决定错误如何被处理 */
|
|
1258
|
+
export declare function routeError(err: AgentError): ErrorRouting;
|
|
1259
|
+
/** 把任意错误归一化为 AgentError(已是 AgentError 不覆盖;普通 Error 用 defaultSeverity,默认 fatal) */
|
|
1260
|
+
export declare function asAgentError(err: unknown, defaultSeverity?: ErrorSeverity): AgentError;
|
|
1261
|
+
/** AgentError 便捷工厂 */
|
|
1262
|
+
export declare function agentError(severity: ErrorSeverity, message: string, code?: string, context?: unknown): AgentError;
|
|
1263
|
+
|
|
1264
|
+
// === 与 src/core/index.ts 导出对齐(消费者类型完整;复杂内部类型用宽松声明,消费者主要消费工厂返回值) ===
|
|
1265
|
+
// 上下文压缩预设
|
|
1266
|
+
export declare function resolveContextOptions(options: any, modelContextWindow: number): any;
|
|
1267
|
+
export type ContextPreset = 'auto' | 'conservative' | 'aggressive' | 'complex';
|
|
1268
|
+
export declare const CONTEXT_PRESETS: Record<string, any>;
|
|
1269
|
+
|
|
1270
|
+
// MCP
|
|
1271
|
+
export declare function connectMcp(config: any): Promise<any>;
|
|
1272
|
+
export declare function extractText(result: any): string;
|
|
1273
|
+
export type McpTransport = 'http' | 'sse' | 'websocket';
|
|
1274
|
+
export interface McpConnection { [k: string]: any }
|
|
1275
|
+
|
|
1276
|
+
// harness / 中间件
|
|
1277
|
+
export interface CreateAgentOptions { [k: string]: any }
|
|
1278
|
+
export interface Middleware { name: string; [k: string]: any }
|
|
1279
|
+
export interface ModelRequest { [k: string]: any }
|
|
1280
|
+
export interface ModelResponse { [k: string]: any }
|
|
1281
|
+
export interface ToolCallContext { [k: string]: any }
|
|
1282
|
+
export interface StateUpdate { [k: string]: any }
|
|
1283
|
+
|
|
1284
|
+
// 子 agent
|
|
1285
|
+
export declare function createSubagentsMiddleware(opts: any): any;
|
|
1286
|
+
export interface SubagentsController {
|
|
1287
|
+
set(configs: SubagentConfig[]): void;
|
|
1288
|
+
add(config: SubagentConfig): void;
|
|
1289
|
+
remove(id: string): boolean;
|
|
1290
|
+
get(): SubagentConfig[];
|
|
1291
|
+
}
|
|
1292
|
+
/** spawn_agent / spawn_agents 运行时选项(role/tools/writablePaths 等可运行时覆盖) */
|
|
1293
|
+
export interface SubagentOptions {
|
|
1294
|
+
role?: string;
|
|
1295
|
+
tools?: string[];
|
|
1296
|
+
/** 子 agent 可写路径前缀白名单(运行时覆盖;写工具包 path guard,越界 PATH_OUT_OF_SCOPE)。subagent-writable Phase 2 */
|
|
1297
|
+
writablePaths?: string[];
|
|
1298
|
+
model?: string;
|
|
1299
|
+
[k: string]: any;
|
|
1300
|
+
}
|
|
1301
|
+
export interface SubagentLlmConfig { [k: string]: any }
|
|
1302
|
+
|
|
1303
|
+
// checkpoint / dataOps / permissions
|
|
1304
|
+
export interface CheckpointDeps { [k: string]: any }
|
|
1305
|
+
export interface DataAuditEntry { [k: string]: any }
|
|
1306
|
+
export interface DataSnapshotEntry { [k: string]: any }
|
|
1307
|
+
export type PermissionOp = string;
|
|
1308
|
+
|
|
1309
|
+
// vfs
|
|
1310
|
+
export declare function createVfs(opts?: any): any;
|
|
1311
|
+
|
|
1312
|
+
// 上下文管理
|
|
1313
|
+
export interface ContextManagerOptions { [k: string]: any }
|
|
1314
|
+
export interface CompressionStats {
|
|
1315
|
+
triggered: boolean; roundsTotal: number; roundsSummarized: number; roundsRecalled: number;
|
|
1316
|
+
originalMessages: number; compressedMessages: number; strategy: string;
|
|
1317
|
+
decision?: CompressDecision;
|
|
1318
|
+
}
|
|
1319
|
+
// 压缩决策(agent-driven-compression;summaryLlm.decide 输出)
|
|
1320
|
+
export interface CompressDecision {
|
|
1321
|
+
keepRounds?: number;
|
|
1322
|
+
windowRatio?: number;
|
|
1323
|
+
summarize: { mode: 'index' | 'llm' };
|
|
1324
|
+
recallTopK?: number;
|
|
1325
|
+
preserveTools?: string[];
|
|
1326
|
+
reason?: string;
|
|
1327
|
+
}
|
|
1328
|
+
export declare const CompressDecisionSchema: {
|
|
1329
|
+
safeParse: (input: unknown) => { success: true; data: CompressDecision } | { success: false; error: unknown };
|
|
1330
|
+
};
|
|
1331
|
+
|
|
1332
|
+
// 模型能力 / token 估算 / offload 阈值
|
|
1333
|
+
export declare const MIN_CONTEXT_WINDOW: number;
|
|
1334
|
+
/** 判定错误是否为上下文超限(模型输入超 contextWindow);复用 langchain ContextOverflowError + 兜底正则。harden-context-resilience */
|
|
1335
|
+
export declare function isContextLengthError(err: unknown): boolean;
|
|
1336
|
+
export declare function resolveModelCaps(model: string): any;
|
|
1337
|
+
export declare function estimateTokens(text: string): number;
|
|
1338
|
+
export declare function offloadThresholdChars(contextWindow: number): number;
|
|
1339
|
+
export declare function offloadPassThroughChars(contextWindow: number): number;
|
|
1340
|
+
export interface ModelCaps { [k: string]: any }
|
|
1341
|
+
|
|
1342
|
+
// 剪贴板复制(clipboard API + execCommand 降级,兼容非 secure context / 旧浏览器)
|
|
1343
|
+
export declare function copyText(text: string): Promise<boolean>;
|
|
1344
|
+
/**
|
|
1345
|
+
* 串行化运行器(P1-2,arch-review):把并发异步操作排成串行链,一个跑完下一个才开始。
|
|
1346
|
+
* createChatSdk 的 send/switchSession/batch 经此串行化,防并发共享 state 竞态。
|
|
1347
|
+
* 返回的 runSerial(fn):fn 排队执行(前一个无论成败都继续),返回 fn 的 Promise(透传结果/错误)。
|
|
1348
|
+
*/
|
|
1349
|
+
export declare function createSerialRunner(): <T>(fn: () => Promise<T>) => Promise<T>;
|