weifuwu 0.82.4 → 0.82.5

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.
@@ -37,8 +37,15 @@ export interface AgentConfig {
37
37
  tools: AgentTool[];
38
38
  /** 默认 10 */
39
39
  maxSteps?: number;
40
- /** 每个工具执行前要求人工审批(协议 §4.5) */
41
- humanInTheLoop?: boolean;
40
+ /**
41
+ * 每个工具执行前要求人工审批(协议 §4.5)。
42
+ * 支持函数:按工具调用动态判定(C2 条件审批——风险分级)——
43
+ * 返回 true 需审批,false 自动执行。
44
+ */
45
+ humanInTheLoop?: boolean | ((call: {
46
+ name: string;
47
+ args: unknown;
48
+ }) => boolean);
42
49
  /** 审批超时(默认 5 分钟),到期按拒绝处理 */
43
50
  approvalTimeoutMs?: number;
44
51
  }
package/dist/index.js CHANGED
@@ -3231,7 +3231,8 @@ function createAgent(client, config) {
3231
3231
  const args = safeParseArgs(tc.function?.arguments ?? "");
3232
3232
  emit("wf:step", { type: "tool", toolCallId: tc.id, name });
3233
3233
  let execArgs = args;
3234
- if (config.humanInTheLoop) {
3234
+ const needApproval = typeof config.humanInTheLoop === "function" ? config.humanInTheLoop({ name, args }) : !!config.humanInTheLoop;
3235
+ if (needApproval) {
3235
3236
  const decision = await client.waitApproval(
3236
3237
  { id: randomUUID4(), toolCallId: tc.id, name, args },
3237
3238
  emit,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "weifuwu",
3
3
  "type": "module",
4
- "version": "0.82.4",
4
+ "version": "0.82.5",
5
5
  "description": "AI SaaS framework — (req, ctx) => Response",
6
6
  "exports": {
7
7
  ".": {