@kiturone/kapibala 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +530 -72
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +224 -8
- package/dist/index.d.ts +224 -8
- package/dist/index.js +529 -72
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -231,10 +231,20 @@ declare class KapibalaError extends Error {
|
|
|
231
231
|
readonly code: string;
|
|
232
232
|
readonly retryPolicy: 'never' | 'immediate' | 'backoff' | 'after_user_action';
|
|
233
233
|
readonly safeMessage: string;
|
|
234
|
+
readonly dispatchOutcome?: 'not_sent' | 'succeeded' | 'failed' | 'unknown';
|
|
234
235
|
constructor(message: string, options?: {
|
|
235
236
|
code?: string;
|
|
236
237
|
retryPolicy?: 'never' | 'immediate' | 'backoff' | 'after_user_action';
|
|
237
238
|
safeMessage?: string;
|
|
239
|
+
dispatchOutcome?: 'not_sent' | 'succeeded' | 'failed' | 'unknown';
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
/** 工具向外部发送前在微任务复核或状态检查中被撤销/拒绝;dispatchOutcome 固定 not_sent。 */
|
|
243
|
+
declare class PreDispatchError extends KapibalaError {
|
|
244
|
+
constructor(message: string, options?: {
|
|
245
|
+
code?: string;
|
|
246
|
+
retryPolicy?: 'never' | 'after_user_action';
|
|
247
|
+
safeMessage?: string;
|
|
238
248
|
});
|
|
239
249
|
}
|
|
240
250
|
/** 模型调用失败;message 已脱敏,对外诊断统一经 describeModelError 产出,retryPolicy 仅为处理建议。 */
|
|
@@ -336,11 +346,26 @@ interface ProviderStateBlock {
|
|
|
336
346
|
}
|
|
337
347
|
/** canonical 历史的内容块联合;provider_state 等私有块只在同 run、同模型与端点续答回传。 */
|
|
338
348
|
type ContentBlock = TextBlock | ToolUseBlock | ToolResultBlock | ThinkingBlock | RedactedThinkingBlock | ProviderStateBlock;
|
|
349
|
+
/**
|
|
350
|
+
* 宿主准备受控 Prompt 时的来源元数据(v1)。
|
|
351
|
+
* 用于追踪 Prompt 来源、版本与内容摘要;不保存认证值或重复保存原始参数,
|
|
352
|
+
* 不发送到 Provider wire,不从历史恢复授权。
|
|
353
|
+
*/
|
|
354
|
+
interface PromptContentSource {
|
|
355
|
+
version: 1;
|
|
356
|
+
server: string;
|
|
357
|
+
name: string;
|
|
358
|
+
scope?: string;
|
|
359
|
+
contentDigest?: string;
|
|
360
|
+
configIdentity?: string;
|
|
361
|
+
}
|
|
339
362
|
interface TextBlock {
|
|
340
363
|
type: 'text';
|
|
341
364
|
text: string;
|
|
342
365
|
/** 宿主注入技能的可选来源;只追踪正文,缺失或恢复不授予权限。 */
|
|
343
366
|
skillSource?: SkillContentSource;
|
|
367
|
+
/** 宿主注入受控 Prompt 的可选来源;只追踪正文与审计摘要,缺失或恢复不授予权限。 */
|
|
368
|
+
promptSource?: PromptContentSource;
|
|
344
369
|
/** 源 wire Item 元数据;正文被改写后由调用方清除,不作为业务身份。 */
|
|
345
370
|
protocolMeta?: ProtocolItemMetadata;
|
|
346
371
|
}
|
|
@@ -356,6 +381,19 @@ interface ToolUseBlock {
|
|
|
356
381
|
/** 源 wire Item 元数据;内容被改写后由调用方清除,不作为业务身份。 */
|
|
357
382
|
protocolMeta?: ProtocolItemMetadata;
|
|
358
383
|
}
|
|
384
|
+
/**
|
|
385
|
+
* canonical 工具结果的可选 v1 执行事实元数据。
|
|
386
|
+
* 适配器按发送证据先记录 dispatchOutcome,执行器在发生本地钩子、校验、转换或审计失败时附加 hostError。
|
|
387
|
+
* 随 canonical 结果持久化;不直接上 Provider wire,不从历史中推断不存在的事实。
|
|
388
|
+
*/
|
|
389
|
+
interface ToolResultExecution {
|
|
390
|
+
version: 1;
|
|
391
|
+
dispatchOutcome: 'not_sent' | 'succeeded' | 'failed' | 'unknown';
|
|
392
|
+
hostError?: {
|
|
393
|
+
phase: 'validation' | 'projection' | 'hook' | 'audit';
|
|
394
|
+
code: string;
|
|
395
|
+
};
|
|
396
|
+
}
|
|
359
397
|
interface ToolResultBlock {
|
|
360
398
|
type: 'tool_result';
|
|
361
399
|
/** 完整技能正文的宿主来源;不发送到Provider wire,不从历史恢复授权。 */
|
|
@@ -369,6 +407,12 @@ interface ToolResultBlock {
|
|
|
369
407
|
errorCode?: string;
|
|
370
408
|
/** 不代表自动重试,只描述调用方应如何处理该错误。 */
|
|
371
409
|
retryPolicy?: 'never' | 'immediate' | 'backoff' | 'after_user_action';
|
|
410
|
+
/**
|
|
411
|
+
* 可选 v1 执行事实元数据。
|
|
412
|
+
* 适配器按发送证据先记录 dispatchOutcome,执行器在发生本地钩子、校验、转换或审计失败时附加 hostError。
|
|
413
|
+
* 随 canonical 结果持久化;不直接上 Provider wire,不从历史中推断不存在的事实。
|
|
414
|
+
*/
|
|
415
|
+
execution?: ToolResultExecution;
|
|
372
416
|
}
|
|
373
417
|
interface ThinkingBlock {
|
|
374
418
|
type: 'thinking';
|
|
@@ -587,6 +631,13 @@ type SessionEvent = {
|
|
|
587
631
|
usage?: Usage;
|
|
588
632
|
ttftMs?: number;
|
|
589
633
|
durationMs?: number;
|
|
634
|
+
} | {
|
|
635
|
+
type: 'mcp_prompt_loaded';
|
|
636
|
+
server: string;
|
|
637
|
+
name: string;
|
|
638
|
+
persistence: 'disk' | 'memory';
|
|
639
|
+
promptSource: PromptContentSource;
|
|
640
|
+
runId?: string;
|
|
590
641
|
} | {
|
|
591
642
|
type: 'turn_finish';
|
|
592
643
|
turn: number;
|
|
@@ -1523,7 +1574,28 @@ declare class PermissionPolicy {
|
|
|
1523
1574
|
declare function visibleTools(tools: readonly Tool[], mode: SessionMode, rules?: readonly PermissionRule[]): Tool[];
|
|
1524
1575
|
|
|
1525
1576
|
/** 执行能力的最小分类;权限规则、模式裁决与工具元数据声明共用这一词汇表。 */
|
|
1526
|
-
type Capability = 'fs:read' | 'fs:write' | 'exec' | 'net:outbound' | 'env:read' | 'agent:spawn';
|
|
1577
|
+
type Capability = 'fs:read' | 'fs:write' | 'exec' | 'net:outbound' | 'env:read' | 'agent:spawn' | 'external:call';
|
|
1578
|
+
/**
|
|
1579
|
+
* 外部调用的精确执行身份;供审批缓存、发送前复核与审计消费。
|
|
1580
|
+
* 包含服务端物理身份、连接代次、目录 epoch 与定义摘要等不可伪造字段。
|
|
1581
|
+
*/
|
|
1582
|
+
interface ToolExecutionIdentity {
|
|
1583
|
+
serverIdentity?: string;
|
|
1584
|
+
connectionGeneration?: number;
|
|
1585
|
+
catalogEpoch?: number;
|
|
1586
|
+
toolDigest?: string;
|
|
1587
|
+
[key: string]: unknown;
|
|
1588
|
+
}
|
|
1589
|
+
/**
|
|
1590
|
+
* 显式 opt-in 规范化执行结果;普通对象返回值保持兼容不强制包装。
|
|
1591
|
+
*/
|
|
1592
|
+
interface ToolExecutionResult {
|
|
1593
|
+
content: string;
|
|
1594
|
+
isError?: boolean;
|
|
1595
|
+
errorCode?: string;
|
|
1596
|
+
retryPolicy?: 'never' | 'after_user_action';
|
|
1597
|
+
execution?: ToolResultExecution;
|
|
1598
|
+
}
|
|
1527
1599
|
interface ToolMetadata {
|
|
1528
1600
|
/** 注册来源标记(如 'builtin');注册表据此执行冲突策略并支持按源注销。 */
|
|
1529
1601
|
source?: string;
|
|
@@ -1533,6 +1605,8 @@ interface ToolMetadata {
|
|
|
1533
1605
|
permissions?: Capability[];
|
|
1534
1606
|
/** 工具自身等待进程资源回收,执行器不可再使用通用 Promise.race 超时。 */
|
|
1535
1607
|
managesTimeout?: boolean;
|
|
1608
|
+
/** 只读提示;工具声明自身无副作用,供 UI 展示与只读过滤参考。 */
|
|
1609
|
+
readOnlyHint?: boolean;
|
|
1536
1610
|
}
|
|
1537
1611
|
/** 工具执行期由宿主注入的运行环境;信号取消后工具应尽快清理在途资源再返回。 */
|
|
1538
1612
|
interface ToolContext {
|
|
@@ -1547,6 +1621,13 @@ interface ToolContext {
|
|
|
1547
1621
|
outputBytes: number;
|
|
1548
1622
|
}) => void;
|
|
1549
1623
|
}
|
|
1624
|
+
/**
|
|
1625
|
+
* 工具输入参数校验结果;valid 为 false 或抛出异常均阻止审批和发送。
|
|
1626
|
+
*/
|
|
1627
|
+
interface ToolInputValidation {
|
|
1628
|
+
valid: boolean;
|
|
1629
|
+
message?: string;
|
|
1630
|
+
}
|
|
1550
1631
|
/** 工具契约;parameters 是 JSON Schema,模型只能看到经 toToolDefinition 投影后的三个字段。 */
|
|
1551
1632
|
interface Tool<TInput = Record<string, unknown>, TOutput = unknown> {
|
|
1552
1633
|
readonly name: string;
|
|
@@ -1555,6 +1636,12 @@ interface Tool<TInput = Record<string, unknown>, TOutput = unknown> {
|
|
|
1555
1636
|
readonly metadata?: ToolMetadata;
|
|
1556
1637
|
/** 声明本次输入的精确执行目标,供审批展示与执行前指纹复核;无固定执行目标的工具不实现。 */
|
|
1557
1638
|
approvalScope?(input: TInput, rootDir: string): ShellScope;
|
|
1639
|
+
/** 本次执行身份;审批缓存与执行前复核消费,缺省保持旧工具规则。 */
|
|
1640
|
+
executionIdentity?(input: TInput, rootDir: string): ToolExecutionIdentity;
|
|
1641
|
+
/** 无副作用地校验最终参数,不修改参数、不访问远端;异常与拒绝均阻止审批和发送。 */
|
|
1642
|
+
validateInput?(input: TInput): ToolInputValidation | undefined;
|
|
1643
|
+
/** 显式 opt-in 转换为标准执行结果;未提供时普通返回值继续作为常规输出。 */
|
|
1644
|
+
toExecutionResult?(raw: TOutput): ToolExecutionResult;
|
|
1558
1645
|
execute(input: TInput, ctx: ToolContext): Promise<TOutput>;
|
|
1559
1646
|
}
|
|
1560
1647
|
/** 恒等构造器:只为工具实现提供类型推断与统一书写形式,不产生任何运行时包装。 */
|
|
@@ -1602,6 +1689,10 @@ interface ApprovalRequest {
|
|
|
1602
1689
|
input: Record<string, unknown>;
|
|
1603
1690
|
rootDir: string;
|
|
1604
1691
|
shell?: ShellScope;
|
|
1692
|
+
/**
|
|
1693
|
+
* 本次调用的外部执行身份;深度哈希纳入审批缓存键,断连重连或目录变更后旧会话批准自动失效。
|
|
1694
|
+
*/
|
|
1695
|
+
executionIdentity?: ToolExecutionIdentity;
|
|
1605
1696
|
/** 宿主是否允许本次请求写入会话级允许缓存;deny_session 的缓存不受此限制。 */
|
|
1606
1697
|
sessionAllowed: boolean;
|
|
1607
1698
|
}
|
|
@@ -1621,29 +1712,68 @@ declare class SessionApprovalCache {
|
|
|
1621
1712
|
|
|
1622
1713
|
/** 同名工具冲突策略:error 直接抛错;prefer-builtin 保留既有内置注册;prefer-last 后到者覆盖。 */
|
|
1623
1714
|
type ConflictPolicy = 'error' | 'prefer-builtin' | 'prefer-last';
|
|
1715
|
+
/**
|
|
1716
|
+
* 不可变工具注册表快照;捕获特定时刻的工具定义、执行引用与版本。
|
|
1717
|
+
* 外部注册表后续的增删改绝不改写已有快照视图。
|
|
1718
|
+
*/
|
|
1719
|
+
interface ToolRegistrySnapshot {
|
|
1720
|
+
readonly version: number;
|
|
1721
|
+
get(name: string): Tool | undefined;
|
|
1722
|
+
has(name: string): boolean;
|
|
1723
|
+
resolve(name: string): Tool;
|
|
1724
|
+
list(): Tool[];
|
|
1725
|
+
definitions(): ToolDefinition[];
|
|
1726
|
+
sourceOf(name: string): string | undefined;
|
|
1727
|
+
}
|
|
1624
1728
|
/**
|
|
1625
1729
|
* 按名称索引的工具注册表。冲突按构造时给定的策略处理,胜出条目的来源标签保持不变;
|
|
1626
|
-
*
|
|
1730
|
+
* 支持原子来源替换(replaceSource)、不可变运行快照(snapshot)与来源注销。
|
|
1627
1731
|
*/
|
|
1628
1732
|
declare class ToolRegistry {
|
|
1629
1733
|
private readonly tools;
|
|
1630
1734
|
private readonly toolSources;
|
|
1631
1735
|
private readonly conflictPolicy;
|
|
1736
|
+
private version;
|
|
1632
1737
|
constructor(options?: {
|
|
1633
1738
|
conflictPolicy?: ConflictPolicy;
|
|
1634
1739
|
});
|
|
1740
|
+
/** 获取当前注册表版本号;每次有效变更(注册、替换、注销)单调自增。 */
|
|
1741
|
+
get currentVersion(): number;
|
|
1635
1742
|
register(tool: Tool, opts?: {
|
|
1636
1743
|
source?: string;
|
|
1637
1744
|
}): void;
|
|
1745
|
+
/**
|
|
1746
|
+
* 原子替换指定来源的全部工具:
|
|
1747
|
+
* 1. 预检候选批内自身重名:若候选批次内包含同名工具,整批拒绝;
|
|
1748
|
+
* 2. 预检跨来源冲突:若候选工具被其它来源占用且策略不允许覆盖,整批拒绝;
|
|
1749
|
+
* 3. 同步原子提交:预检全部通过后一次性清理该来源旧工具并写入新工具;失败时完全保持旧状态不变。
|
|
1750
|
+
*/
|
|
1751
|
+
replaceSource(source: string, tools: Tool[]): void;
|
|
1752
|
+
/**
|
|
1753
|
+
* 注册指定来源的工具集。
|
|
1754
|
+
*
|
|
1755
|
+
* 语义与约束:
|
|
1756
|
+
* 1. 委托给 `replaceSource` 实现整源原子替换(新集合未包含的该来源旧工具将被注销移除,非增量累加);
|
|
1757
|
+
* 2. 默认禁止跨来源名称冲突(抛出 KapibalaError TOOL_CONFLICT);若 options 配置了 conflictPolicy: 'prefer-last' 则允许覆盖旧来源同名工具;
|
|
1758
|
+
* 3. 预检阶段发现批内同名重复时整批拒绝,绝不破坏注册表原子状态。
|
|
1759
|
+
*/
|
|
1638
1760
|
registerSource(source: string, tools: Tool[]): void;
|
|
1639
1761
|
unregisterSource(source: string): void;
|
|
1640
1762
|
get(name: string): Tool | undefined;
|
|
1763
|
+
has(name: string): boolean;
|
|
1764
|
+
/** 获取工具对应的来源标记。 */
|
|
1765
|
+
sourceOf(name: string): string | undefined;
|
|
1641
1766
|
/** 注销指定名称及来源记录;调用方须核对实例身份,不能移除同名替代工具。 */
|
|
1642
1767
|
unregister(name: string): void;
|
|
1643
1768
|
/** 未命中时抛 ToolNotFound,并携带当前全部可用名称辅助模型自纠。 */
|
|
1644
1769
|
resolve(name: string): Tool;
|
|
1645
1770
|
list(): Tool[];
|
|
1646
1771
|
definitions(): ToolDefinition[];
|
|
1772
|
+
/**
|
|
1773
|
+
* 捕获当前注册表的不可变只读快照。
|
|
1774
|
+
* 注册表后续的增删改绝不改变该快照的定义列表、工具执行实例与来源版本。
|
|
1775
|
+
*/
|
|
1776
|
+
snapshot(): ToolRegistrySnapshot;
|
|
1647
1777
|
}
|
|
1648
1778
|
|
|
1649
1779
|
/**
|
|
@@ -1724,7 +1854,7 @@ interface ExecutorOptions {
|
|
|
1724
1854
|
hardDenial?: (tool: Tool, input: Record<string, unknown>) => ToolHardDenial | undefined;
|
|
1725
1855
|
/** 结果钩子和执行审计完成后调用;用于在同批次下一调用前安装宿主收紧状态。 */
|
|
1726
1856
|
onToolResult?: (tool: Tool, input: Record<string, unknown>, result: ToolResultBlock) => void | Promise<void>;
|
|
1727
|
-
tools: ToolRegistry;
|
|
1857
|
+
tools: ToolRegistry | ToolRegistrySnapshot;
|
|
1728
1858
|
hooks: HookRegistry;
|
|
1729
1859
|
/** 工具执行的绝对根目录;路径解析与审批均以此为基准。 */
|
|
1730
1860
|
rootDir: string;
|
|
@@ -2024,12 +2154,55 @@ interface PluginContext {
|
|
|
2024
2154
|
readonly rootDir: string;
|
|
2025
2155
|
readonly logger?: (msg: string) => void;
|
|
2026
2156
|
}
|
|
2027
|
-
/**
|
|
2157
|
+
/**
|
|
2158
|
+
* 插件声明的命令贡献描述元数据。
|
|
2159
|
+
*
|
|
2160
|
+
* 约束、边界与为什么:
|
|
2161
|
+
* 1. 纯元数据定义:只包含名称、描述、用法与变更标记,禁止引入 ANSI 渲染、Readline 或 TTY 依赖,坚守 Core Headless 铁律;
|
|
2162
|
+
* 2. 供宿主(CLI/TUI/Web)按需消费并装配到人机交互界面;非交互或 Headless 宿主可安全忽略本字段;
|
|
2163
|
+
* 3. 别名与主名均遵循全小写规范,防止跨平台输入歧义。
|
|
2164
|
+
*/
|
|
2165
|
+
interface PluginCommandContribution {
|
|
2166
|
+
/** 命令主名称(不含前导斜杠,如 'mcp' 或 'prompts')。 */
|
|
2167
|
+
readonly name: string;
|
|
2168
|
+
/** 命令用途说明,供帮助菜单展示。 */
|
|
2169
|
+
readonly description: string;
|
|
2170
|
+
/** 格式化调用用法(如 '/mcp [tools <server>]')。 */
|
|
2171
|
+
readonly usage?: string;
|
|
2172
|
+
/** 可选别名列表(如 ['plugin'])。 */
|
|
2173
|
+
readonly aliases?: readonly string[];
|
|
2174
|
+
/** 命令是否产生状态变更;true 表示写操作(受忙碌状态门拦截),false 表示纯只读诊断。 */
|
|
2175
|
+
readonly mutates?: boolean;
|
|
2176
|
+
}
|
|
2177
|
+
/**
|
|
2178
|
+
* 插件声明的扩展贡献元数据聚合容器。
|
|
2179
|
+
*
|
|
2180
|
+
* 约束与边界:
|
|
2181
|
+
* 1. 声明式规范:允许外部扩展包一次性声明技能根目录、交互命令与扩展元数据;
|
|
2182
|
+
* 2. 宿主(CLI)在会话挂载插件时自动读取并完成装配,无需在宿主层硬编码插件内部命令。
|
|
2183
|
+
*/
|
|
2184
|
+
interface PluginContribution {
|
|
2185
|
+
/** 插件显式携带或依赖的技能根目录集合(绝对物理路径)。 */
|
|
2186
|
+
readonly skillsRoots?: readonly string[];
|
|
2187
|
+
/** 插件贡献给宿主交互终端的斜杠命令列表。 */
|
|
2188
|
+
readonly commands?: readonly PluginCommandContribution[];
|
|
2189
|
+
}
|
|
2190
|
+
/**
|
|
2191
|
+
* 插件生命周期契约:setup 在会话空闲时挂载执行一次,teardown 在会话销毁时逐个调用以回收资源。
|
|
2192
|
+
* 遵循「一 Session 一插件实例」约束,实现外部生态向 Agent Harness 的受控单向注入。
|
|
2193
|
+
*/
|
|
2028
2194
|
interface AgentPlugin {
|
|
2029
|
-
/**
|
|
2195
|
+
/** 插件唯一识别名称,用于诊断输出与依赖追踪。 */
|
|
2030
2196
|
readonly name: string;
|
|
2197
|
+
/** 插件语义版本号,默认遵循包版本。 */
|
|
2031
2198
|
readonly version?: string;
|
|
2199
|
+
/** 插件用途与功能描述。 */
|
|
2200
|
+
readonly description?: string;
|
|
2201
|
+
/** 插件声明的扩展贡献元数据(命令清单、技能目录等)。 */
|
|
2202
|
+
readonly contributes?: PluginContribution;
|
|
2203
|
+
/** 挂载执行入口;仅在空闲状态调用,可向 tools / hooks 注册能力。 */
|
|
2032
2204
|
setup(ctx: PluginContext): void | Promise<void>;
|
|
2205
|
+
/** 销毁回收入口;必须幂等执行,彻底清理进程、网络连接或定时器。 */
|
|
2033
2206
|
teardown?(): void | Promise<void>;
|
|
2034
2207
|
}
|
|
2035
2208
|
|
|
@@ -2176,7 +2349,7 @@ interface PromptAssemblerOptions {
|
|
|
2176
2349
|
contextWindow?: number;
|
|
2177
2350
|
skillBudgetTokens?: number;
|
|
2178
2351
|
/** 提供时才生成 L2 工具清单段;缺省表示本次运行不向模型展示任何工具。 */
|
|
2179
|
-
tools?: ToolRegistry;
|
|
2352
|
+
tools?: ToolRegistry | ToolRegistrySnapshot;
|
|
2180
2353
|
/** L3 环境段展示的工作区根目录;文件工具的沙箱边界与其保持一致。 */
|
|
2181
2354
|
rootDir: string;
|
|
2182
2355
|
agentName?: string;
|
|
@@ -2226,7 +2399,7 @@ interface AgentLoopOptions {
|
|
|
2226
2399
|
onToolBatchUpdate?: (messages: readonly CanonicalMessage[]) => void;
|
|
2227
2400
|
provider: ModelProvider;
|
|
2228
2401
|
executor: ToolExecutor;
|
|
2229
|
-
tools: ToolRegistry;
|
|
2402
|
+
tools: ToolRegistry | ToolRegistrySnapshot;
|
|
2230
2403
|
hooks: HookRegistry;
|
|
2231
2404
|
systemPrompt?: string;
|
|
2232
2405
|
/** 单次 run 的最大 turn 数,耗尽时以 error 事件收尾;缺省 20。 */
|
|
@@ -2279,6 +2452,28 @@ declare class AgentLoop {
|
|
|
2279
2452
|
run(history: CanonicalMessage[]): AsyncIterable<SessionEvent>;
|
|
2280
2453
|
}
|
|
2281
2454
|
|
|
2455
|
+
/**
|
|
2456
|
+
* 任务准备上下文;提供当前会话取消信号、runId 与不可变工具快照。
|
|
2457
|
+
*/
|
|
2458
|
+
interface PreparedTaskContext {
|
|
2459
|
+
signal?: AbortSignal;
|
|
2460
|
+
runId: string;
|
|
2461
|
+
tools: ToolRegistrySnapshot;
|
|
2462
|
+
}
|
|
2463
|
+
/**
|
|
2464
|
+
* 任务准备产物;包含要附加到 User 消息的内容块,以及提交前的身份复核回调。
|
|
2465
|
+
*/
|
|
2466
|
+
interface PreparedTaskResult {
|
|
2467
|
+
/** 任务附加内容块或纯文本(如 Prompt 内容或技能正文)。 */
|
|
2468
|
+
content: ContentBlock[] | string;
|
|
2469
|
+
/** 可选来源元数据;仅在 content 为 string 时由宿主自动包装为带来源的 TextBlock。 */
|
|
2470
|
+
promptSource?: PromptContentSource;
|
|
2471
|
+
/** 最终提交前核对准备身份;若在此期间目录变化或连接重置,返回 false 拒绝提交并零发送闭合。 */
|
|
2472
|
+
verifyIdentity?: () => boolean | Promise<boolean>;
|
|
2473
|
+
/** 可选技能名称;存在时按显式技能流程处理。 */
|
|
2474
|
+
skillName?: string;
|
|
2475
|
+
}
|
|
2476
|
+
|
|
2282
2477
|
/** AgentSession 的构造配置;除主任务绑定外均可缺省,缺省行为见各字段。 */
|
|
2283
2478
|
interface SessionConfig {
|
|
2284
2479
|
/** 宿主显式技能配置;缺省不扫描home,项目根需独立信任。 */
|
|
@@ -2392,6 +2587,12 @@ declare class AgentSession {
|
|
|
2392
2587
|
init(): Promise<void>;
|
|
2393
2588
|
/** 挂载插件并执行 setup;销毁后或运行中拒绝,setup 失败的插件不进入已装列表。 */
|
|
2394
2589
|
use(plugin: AgentPlugin): Promise<void>;
|
|
2590
|
+
/**
|
|
2591
|
+
* 获取当前会话已成功挂载的扩展插件只读列表。
|
|
2592
|
+
*
|
|
2593
|
+
* 保证返回当前状态的独立切片,外部修改不污染内部挂载表。
|
|
2594
|
+
*/
|
|
2595
|
+
getPlugins(): readonly AgentPlugin[];
|
|
2395
2596
|
/**
|
|
2396
2597
|
* 空闲时原子替换角色的模型绑定;本方法不改变当前角色或工具权限。
|
|
2397
2598
|
* @param profile 模型协议、请求目标和输出预算。
|
|
@@ -2412,6 +2613,8 @@ declare class AgentSession {
|
|
|
2412
2613
|
/** 只在空闲时切换本次会话模式;宿主负责 FullAccess 的显式选择交互。 */
|
|
2413
2614
|
switchMode(mode: SessionMode): void;
|
|
2414
2615
|
getMode(): SessionMode;
|
|
2616
|
+
/** 获取当前会话生效的权限规则列表。 */
|
|
2617
|
+
getPermissionRules(): readonly PermissionRule[];
|
|
2415
2618
|
/** 返回最近一次成功装载的来源路径,不暴露指令正文。 */
|
|
2416
2619
|
getInstructionSources(): string[];
|
|
2417
2620
|
/** 稳定会话身份,独立于当前进程日志实例和每次用户交互。 */
|
|
@@ -2464,6 +2667,19 @@ declare class AgentSession {
|
|
|
2464
2667
|
signal?: AbortSignal;
|
|
2465
2668
|
role?: PrimaryModelRole;
|
|
2466
2669
|
}): AsyncIterable<SessionEvent>;
|
|
2670
|
+
/**
|
|
2671
|
+
* 受控任务准备入口:在同一运行锁内异步准备文本块/来源,预算和存储成功后才进入模型。
|
|
2672
|
+
*
|
|
2673
|
+
* @param task 用户显式任务正文(或命令描述)。
|
|
2674
|
+
* @param prepare 异步任务准备函数;在锁内执行,若准备失败或取消则释放锁且零 append。
|
|
2675
|
+
* @param options 可选中止信号与显式主任务角色。
|
|
2676
|
+
* @returns 结构化事件的异步流。
|
|
2677
|
+
* @throws {SessionBusyError} 当前会话忙碌时抛出。
|
|
2678
|
+
*/
|
|
2679
|
+
runPreparedTask(task: string, prepare: (context: PreparedTaskContext) => Promise<PreparedTaskResult>, options?: {
|
|
2680
|
+
signal?: AbortSignal;
|
|
2681
|
+
role?: PrimaryModelRole;
|
|
2682
|
+
}): AsyncIterable<SessionEvent>;
|
|
2467
2683
|
/** 单次任务执行主体;调用方 return 的中止与 finally 清理由外层统一协调。 */
|
|
2468
2684
|
private runOperation;
|
|
2469
2685
|
/** 幂等销毁:卸载插件后发出 session:end;运行中拒绝,teardown 失败聚合抛出且不完成销毁。 */
|
|
@@ -2505,4 +2721,4 @@ declare class AgentSession {
|
|
|
2505
2721
|
private findClosedToolMessages;
|
|
2506
2722
|
}
|
|
2507
2723
|
|
|
2508
|
-
export { AbortError, AgentLoop, type AgentLoopOptions, type AgentPlugin, AgentSession, AnthropicProvider, type AnthropicProviderOptions, type ApprovalChannel, type ApprovalChoice, type ApprovalRequest, type CanonicalMessage, type Capability, type ChatCapabilities, type CommandResult, type ConflictPolicy, type ContentBlock, type ContextBudget, ContextBudgetError, ContextManager, type ContextManagerOptions, ContextOverflowError, type ContextSnapshot, ContextStorageError, type ContextSummary, type ContextUsage, type ContextWindowValue, DEFAULT_CONTEXT_WINDOW_TOKENS, type EventLogger, type ExecutorOptions, FatalError, type FileDetails, FileLogSink, type FileLogSinkOptions, type FileObservation, type HistoryRepair, type HookContext, type HookHandlers, type HookPoint, HookRegistry, type InstructionLoadOptions, type InstructionSnapshot, type InstructionSource, type InteractionBoundary, type InteractionTerminal, JSONLMessageStore, KapibalaError, type LogChannel, type LogEvent, type LogField, type LogInput, type LogLevel, type LogSink, type ManagedSession, type MessageRole, type MessageStore, ModelError, type ModelErrorCategory, type ModelErrorInfo, type ModelErrorOptions, type ModelEvent, type ModelProfile, type ModelProtocol, type ModelProvider, type ModelProviderBinding, type ModelRequest, type ModelRole, type ModelRouter, type NormalizedHistory, OpenAICompatibleProvider, type OpenAIProviderOptions, OpenAIResponsesProvider, type OpenAIResponsesProviderOptions, PathSandbox, type PermissionAction, type PermissionDecision, PermissionPolicy, type PermissionRequest, type PermissionRule, type PluginContext, type PreparedSkill, type PrimaryModelRole, type ProjectIdentity, PromptAssembler, type PromptAssemblerOptions, type ProtocolItemMetadata, type ProtocolOrigin, type ProviderStateBlock, type RedactedThinkingBlock, type RequestPreparation, type ResolvedContextWindow, type RunCommandInput, type RunMetrics, SESSION_SCHEMA_VERSION, SKILL_LIMITS, SUMMARY_OUTPUT_BUFFER_MULTIPLIER, type SandboxConfig, SessionApprovalCache, SessionBusyError, type SessionConfig, type SessionEvent, type SessionHeader, SessionLock, SessionManager, type SessionManagerOptions, type SessionMetadata, type SessionMode, type SessionRecord, type SessionRecordType, type SessionState, type SessionStats, SessionStore, type ShellDetectOptions, type ShellEnvironment, type ShellKind, type ShellPreference, type ShellScope, SimpleModelRouter, type SkillActivation, type SkillCatalog, type SkillContentSource, type SkillContextState, type SkillDefinition, type SkillDiagnostic, type SkillDocument, type SkillMetadata, type SkillOptions, type SkillQuery, type SkillQueryPage, SkillRegistry, type SkillResourceInput, type SkillResourcePage, type SkillRoot, SkillRuntime, type SkillScanResult, type SkillScope, type StatefulMessageStore, type StepLogEntry, type StepLogStage, StructuredLogger, type SummaryCandidate, SummaryService, type SummaryServiceOptions, type TextBlock, type ThinkingBlock, type TokenEstimate, type TokenEstimator, type Tool, type ToolContext, type ToolDecision, type ToolDefinition, ToolError, ToolExecutor, type ToolHardDenial, type ToolMetadata, ToolNotFound, ToolRegistry, type ToolResultBlock, type ToolUseBlock, TransportError, type TurnMetrics, UnicodeTokenEstimator, type Usage, assembleCanonicalToolResults, builtinTools, classifyBashOutput, cleanupCommandResults, commandAuditSummary, compareSkillPaths, createContextBudget, createDefaultLogSinks, createLogId, createMessageId, createRunCommandTool, defineTool, describeModelError, detectShell, editFileTool, escapeSkillXml, estimateSkillTokens, executionFingerprint, extractFileDetails, findSkillContent, formatSkillCatalog, globTool, grepTool, identifyHistory, indexInteractions, inspectSkillContent, intersectSkillTools, isSkillName, isTextBlock, isThinkingBlock, isToolResultBlock, isToolUseBlock, isWithinSkillRoot, listSkillResources, loadInstructions, normalizeHistory, normalizeSkillTools, parseSkillDocument, projectSafeFields, readBoundedSkillText, readFileTool, readSkillResource, recoverIncompleteAudit, renderFileDetails, renderSkillReloads, requestFingerprint, resolveContextWindow, resolveSessionProject, sanitizeModelErrorMessage, sanitizeSessionTitle, scanSkillRoot, skillDigest, skillFailure, skillPathKey, stableJsonStringify, stableSerialize, supportsSessionState, toToolDefinition, truncateToolOutput, validateModelBinding, validatePermissionRules, validateSummary, visibleTools, writeFileTool };
|
|
2724
|
+
export { AbortError, AgentLoop, type AgentLoopOptions, type AgentPlugin, AgentSession, AnthropicProvider, type AnthropicProviderOptions, type ApprovalChannel, type ApprovalChoice, type ApprovalRequest, type CanonicalMessage, type Capability, type ChatCapabilities, type CommandResult, type ConflictPolicy, type ContentBlock, type ContextBudget, ContextBudgetError, ContextManager, type ContextManagerOptions, ContextOverflowError, type ContextSnapshot, ContextStorageError, type ContextSummary, type ContextUsage, type ContextWindowValue, DEFAULT_CONTEXT_WINDOW_TOKENS, type EventLogger, type ExecutorOptions, FatalError, type FileDetails, FileLogSink, type FileLogSinkOptions, type FileObservation, type HistoryRepair, type HookContext, type HookHandlers, type HookPoint, HookRegistry, type InstructionLoadOptions, type InstructionSnapshot, type InstructionSource, type InteractionBoundary, type InteractionTerminal, JSONLMessageStore, KapibalaError, type LogChannel, type LogEvent, type LogField, type LogInput, type LogLevel, type LogSink, type ManagedSession, type MessageRole, type MessageStore, ModelError, type ModelErrorCategory, type ModelErrorInfo, type ModelErrorOptions, type ModelEvent, type ModelProfile, type ModelProtocol, type ModelProvider, type ModelProviderBinding, type ModelRequest, type ModelRole, type ModelRouter, type NormalizedHistory, OpenAICompatibleProvider, type OpenAIProviderOptions, OpenAIResponsesProvider, type OpenAIResponsesProviderOptions, PathSandbox, type PermissionAction, type PermissionDecision, PermissionPolicy, type PermissionRequest, type PermissionRule, type PluginCommandContribution, type PluginContext, type PluginContribution, PreDispatchError, type PreparedSkill, type PreparedTaskContext, type PreparedTaskResult, type PrimaryModelRole, type ProjectIdentity, PromptAssembler, type PromptAssemblerOptions, type PromptContentSource, type ProtocolItemMetadata, type ProtocolOrigin, type ProviderStateBlock, type RedactedThinkingBlock, type RequestPreparation, type ResolvedContextWindow, type RunCommandInput, type RunMetrics, SESSION_SCHEMA_VERSION, SKILL_LIMITS, SUMMARY_OUTPUT_BUFFER_MULTIPLIER, type SandboxConfig, SessionApprovalCache, SessionBusyError, type SessionConfig, type SessionEvent, type SessionHeader, SessionLock, SessionManager, type SessionManagerOptions, type SessionMetadata, type SessionMode, type SessionRecord, type SessionRecordType, type SessionState, type SessionStats, SessionStore, type ShellDetectOptions, type ShellEnvironment, type ShellKind, type ShellPreference, type ShellScope, SimpleModelRouter, type SkillActivation, type SkillCatalog, type SkillContentSource, type SkillContextState, type SkillDefinition, type SkillDiagnostic, type SkillDocument, type SkillMetadata, type SkillOptions, type SkillQuery, type SkillQueryPage, SkillRegistry, type SkillResourceInput, type SkillResourcePage, type SkillRoot, SkillRuntime, type SkillScanResult, type SkillScope, type StatefulMessageStore, type StepLogEntry, type StepLogStage, StructuredLogger, type SummaryCandidate, SummaryService, type SummaryServiceOptions, type TextBlock, type ThinkingBlock, type TokenEstimate, type TokenEstimator, type Tool, type ToolContext, type ToolDecision, type ToolDefinition, ToolError, type ToolExecutionIdentity, type ToolExecutionResult, ToolExecutor, type ToolHardDenial, type ToolInputValidation, type ToolMetadata, ToolNotFound, ToolRegistry, type ToolRegistrySnapshot, type ToolResultBlock, type ToolResultExecution, type ToolUseBlock, TransportError, type TurnMetrics, UnicodeTokenEstimator, type Usage, assembleCanonicalToolResults, builtinTools, classifyBashOutput, cleanupCommandResults, commandAuditSummary, compareSkillPaths, createContextBudget, createDefaultLogSinks, createLogId, createMessageId, createRunCommandTool, defineTool, describeModelError, detectShell, editFileTool, escapeSkillXml, estimateSkillTokens, executionFingerprint, extractFileDetails, findSkillContent, formatSkillCatalog, globTool, grepTool, identifyHistory, indexInteractions, inspectSkillContent, intersectSkillTools, isSkillName, isTextBlock, isThinkingBlock, isToolResultBlock, isToolUseBlock, isWithinSkillRoot, listSkillResources, loadInstructions, normalizeHistory, normalizeSkillTools, parseSkillDocument, projectSafeFields, readBoundedSkillText, readFileTool, readSkillResource, recoverIncompleteAudit, renderFileDetails, renderSkillReloads, requestFingerprint, resolveContextWindow, resolveSessionProject, sanitizeModelErrorMessage, sanitizeSessionTitle, scanSkillRoot, skillDigest, skillFailure, skillPathKey, stableJsonStringify, stableSerialize, supportsSessionState, toToolDefinition, truncateToolOutput, validateModelBinding, validatePermissionRules, validateSummary, visibleTools, writeFileTool };
|