agent-tool-chat 1.2.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.d.ts CHANGED
@@ -3,8 +3,14 @@ import { CoreMessage, ToolCall, StreamResult, ToolDefinition as CoreToolDefiniti
3
3
  export type { CoreMessage, ToolCall, StreamResult, LLMProviderConfig };
4
4
  export interface ToolDefinition {
5
5
  name: string;
6
+ alias?: string;
6
7
  description: string;
7
8
  parameters: Record<string, any>;
9
+ /**
10
+ * 执行前置条件。声明后会写进系统提示词;
11
+ * 带 check 的条件由宿主 onCheckToolRequirement 权威判定,未满足时不执行工具。
12
+ */
13
+ requires?: ToolRequirement | ToolRequirement[];
8
14
  displayHints?: {
9
15
  suggestComponent?: string;
10
16
  resultFormat?: 'table' | 'card' | 'list' | 'text' | 'map' | 'none' | 'auto';
@@ -81,10 +87,53 @@ export interface ChatMessage {
81
87
  export interface ToolResult {
82
88
  callId: string;
83
89
  name: string;
90
+ alias?: string;
84
91
  arguments: string;
85
92
  result: string;
86
93
  success: boolean;
87
- status: 'running' | 'success' | 'error';
94
+ status: 'running' | 'success' | 'error' | 'blocked';
95
+ /** 被前置条件阻断时的原因(status === 'blocked') */
96
+ hint?: string;
97
+ }
98
+ export type ToolRequirementAction = 'call-tool' | 'ask-user' | 'block';
99
+ export interface ToolRequirement {
100
+ /** 条件说明(必填,会写进系统提示词) */
101
+ description: string;
102
+ /** 建议先成功调用的工具名(仅提示词建议,不做硬拦截) */
103
+ tools?: string[];
104
+ /** 宿主校验项 id,由 onCheckToolRequirement 判定;未满足则不执行工具 */
105
+ check?: string;
106
+ /** 未满足时给模型/用户的指令 */
107
+ hint?: string;
108
+ /** 未满足时建议动作,默认:有 tools → call-tool,否则 ask-user */
109
+ action?: ToolRequirementAction;
110
+ }
111
+ export interface ToolRequirementContext {
112
+ sessionId: string;
113
+ packageId: string;
114
+ toolName: string;
115
+ args: Record<string, any>;
116
+ check: string;
117
+ description?: string;
118
+ }
119
+ export interface ToolRequirementResult {
120
+ ok: boolean;
121
+ /** 未满足原因(进 tool 结果与 UI) */
122
+ message?: string;
123
+ /** 覆盖声明里的 hint */
124
+ hint?: string;
125
+ /** 建议先调用的工具 */
126
+ suggestedTool?: string;
127
+ action?: ToolRequirementAction;
128
+ }
129
+ export interface SessionMeta {
130
+ id: string;
131
+ title: string;
132
+ /** 毫秒时间戳 */
133
+ createdAt: number;
134
+ /** 毫秒时间戳 */
135
+ updatedAt: number;
136
+ messageCount?: number;
88
137
  }
89
138
  export interface ProviderModelOption {
90
139
  label: string;
@@ -135,6 +184,7 @@ export interface ChatSettings {
135
184
  mdTableClick?: boolean;
136
185
  /** md 内容列表项点击执行,默认开启 */
137
186
  mdListClick?: boolean;
187
+ /** @deprecated 预留字段,当前未实现任何行为 */
138
188
  useTools?: boolean;
139
189
  /** @deprecated 兼容旧代码,始终镜像当前 provider 的值 */
140
190
  apiKey?: string;
@@ -158,6 +208,11 @@ export interface ChatCommand {
158
208
  export interface AgentChatOptions {
159
209
  toolPackages: ToolPackage[];
160
210
  onToolCall?: (call: ToolCallEvent) => Promise<any>;
211
+ /**
212
+ * 工具前置条件校验钩子:声明了 requires.check 的工具在执行前会调用它,
213
+ * 返回 ok:false 时不执行工具,并把结构化结果回给模型。
214
+ */
215
+ onCheckToolRequirement?: (ctx: ToolRequirementContext) => ToolRequirementResult | Promise<ToolRequirementResult>;
161
216
  provider?: any;
162
217
  providerConfig?: Partial<LLMProviderConfig>;
163
218
  /** 初始设置项:作为默认值,localStorage 中已保存的设置按字段覆盖 */
@@ -178,6 +233,14 @@ export interface AgentChatOptions {
178
233
  maxContextTokens?: number;
179
234
  /** 历史消息硬上限(条),超出仅保留最近 N 条;≤0 表示不限制。默认 60(见 useAgentChat) */
180
235
  maxHistoryMessages?: number;
236
+ /** 单次工具结果写入模型的字符上限;0 表示不限制。默认 30000(见 useAgentChat) */
237
+ maxToolResultChars?: number;
238
+ /**
239
+ * 承载 chat 实例的组件卸载时是否自动 dispose(停止业务事件引擎)。
240
+ * 默认 false:业务事件按应用级常驻,避免宿主缓存实例后路由往返导致事件失效;
241
+ * 需要旧的"卸载即清理"行为时显式传 true。
242
+ */
243
+ disposeOnUnmount?: boolean;
181
244
  }
182
245
  export interface BusinessEvent {
183
246
  type: string;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "agent-tool-chat",
3
3
  "description": "An agent-driven chat plugin with ToolPackage architecture and host-controlled execution",
4
4
  "author": "kangjinrui <1092014304@qq.com>",
5
- "version": "1.2.0",
5
+ "version": "1.6.0",
6
6
  "license": "MIT",
7
7
  "private": false,
8
8
  "type": "module",
@@ -26,6 +26,7 @@
26
26
  ],
27
27
  "scripts": {
28
28
  "build": "vite build && .\\copy-mp.bat",
29
+ "build:host": "vite build && node scripts/copy-to-host.mjs",
29
30
  "dev": "vite build --watch",
30
31
  "prepublishOnly": "npm run build"
31
32
  },