@cognipeer/agent-sdk 0.9.0 → 0.9.1
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 +31 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +39 -4
- package/dist/index.d.ts +39 -4
- package/dist/index.mjs +31 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -434,7 +434,7 @@ function createTool({
|
|
|
434
434
|
run: execute,
|
|
435
435
|
func: execute
|
|
436
436
|
};
|
|
437
|
-
if (typeof needsApproval === "boolean") {
|
|
437
|
+
if (typeof needsApproval === "function" || typeof needsApproval === "boolean") {
|
|
438
438
|
toolRecord.needsApproval = needsApproval;
|
|
439
439
|
}
|
|
440
440
|
if (approvalPrompt !== void 0) {
|
|
@@ -3483,6 +3483,29 @@ function selectPendingToolCalls(messages) {
|
|
|
3483
3483
|
}
|
|
3484
3484
|
|
|
3485
3485
|
// src/nodes/tools.ts
|
|
3486
|
+
function resolveNeedsApproval(tool, args) {
|
|
3487
|
+
const spec = tool?.needsApproval;
|
|
3488
|
+
if (typeof spec === "function") {
|
|
3489
|
+
try {
|
|
3490
|
+
return Boolean(spec(args));
|
|
3491
|
+
} catch {
|
|
3492
|
+
return true;
|
|
3493
|
+
}
|
|
3494
|
+
}
|
|
3495
|
+
return Boolean(spec);
|
|
3496
|
+
}
|
|
3497
|
+
function resolveApprovalPrompt(tool, args) {
|
|
3498
|
+
const prompt = tool?.approvalPrompt;
|
|
3499
|
+
if (typeof prompt === "function") {
|
|
3500
|
+
try {
|
|
3501
|
+
const resolved = prompt(args);
|
|
3502
|
+
return typeof resolved === "string" && resolved.length > 0 ? resolved : void 0;
|
|
3503
|
+
} catch {
|
|
3504
|
+
return void 0;
|
|
3505
|
+
}
|
|
3506
|
+
}
|
|
3507
|
+
return typeof prompt === "string" ? prompt : void 0;
|
|
3508
|
+
}
|
|
3486
3509
|
function normalizeMaxExecutionsPerRun(value) {
|
|
3487
3510
|
if (value === null || value === void 0 || value === "") return null;
|
|
3488
3511
|
const parsed = Number(value);
|
|
@@ -3529,10 +3552,13 @@ function buildToolDetails(tool, toolName) {
|
|
|
3529
3552
|
}
|
|
3530
3553
|
const inputSchema = normalizeToolSchema(tool, toolName);
|
|
3531
3554
|
if (inputSchema !== void 0) details.inputSchema = inputSchema;
|
|
3532
|
-
const
|
|
3533
|
-
|
|
3555
|
+
const approvalSpec = tool.needsApproval;
|
|
3556
|
+
const needsApproval = typeof approvalSpec === "boolean" ? approvalSpec : void 0;
|
|
3557
|
+
const conditionalApproval = typeof approvalSpec === "function" ? true : void 0;
|
|
3558
|
+
if (needsApproval !== void 0 || conditionalApproval !== void 0 || tool.approvalPrompt !== void 0 || tool.approvalDefaults !== void 0) {
|
|
3534
3559
|
details.approval = {
|
|
3535
3560
|
required: needsApproval,
|
|
3561
|
+
conditional: conditionalApproval,
|
|
3536
3562
|
prompt: typeof tool.approvalPrompt === "string" ? tool.approvalPrompt : void 0,
|
|
3537
3563
|
defaults: tool.approvalDefaults !== void 0 ? sanitizeTracePayload(tool.approvalDefaults) : void 0
|
|
3538
3564
|
};
|
|
@@ -3757,7 +3783,7 @@ function createToolsNode(initialTools, opts) {
|
|
|
3757
3783
|
}
|
|
3758
3784
|
}
|
|
3759
3785
|
let approvalEntry = pendingByCallId.get(toolCallId);
|
|
3760
|
-
const needsApproval =
|
|
3786
|
+
const needsApproval = resolveNeedsApproval(tool, args);
|
|
3761
3787
|
if (needsApproval) {
|
|
3762
3788
|
if (!approvalEntry) {
|
|
3763
3789
|
approvalEntry = {
|
|
@@ -3767,7 +3793,7 @@ function createToolsNode(initialTools, opts) {
|
|
|
3767
3793
|
args,
|
|
3768
3794
|
status: "pending",
|
|
3769
3795
|
requestedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3770
|
-
metadata: tool
|
|
3796
|
+
metadata: resolveApprovalPrompt(tool, args) !== void 0 || tool.approvalDefaults !== void 0 ? { prompt: resolveApprovalPrompt(tool, args), defaults: tool.approvalDefaults } : void 0
|
|
3771
3797
|
};
|
|
3772
3798
|
pendingApprovals.push(approvalEntry);
|
|
3773
3799
|
pendingByCallId.set(toolCallId, approvalEntry);
|