@deliverd/sdk 0.11.1 → 0.13.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.
@@ -1,59 +1,59 @@
1
- import { askAboutCall, type ToolApprovalOptions } from "./shared.js";
2
-
3
- /**
4
- * The Vercel AI SDK: a person approves tool calls, through Deliverd.
5
- *
6
- * ```ts
7
- * import { generateText } from "ai";
8
- * import { Deliverd } from "@deliverd/sdk";
9
- * import { deliverdToolApproval } from "@deliverd/sdk/adapters";
10
- *
11
- * const result = await generateText({
12
- * model,
13
- * tools: { refund, sendEmail, lookupOrder },
14
- * toolApproval: deliverdToolApproval({
15
- * deliverd: new Deliverd(),
16
- * approvers: ["finance"],
17
- * when: (tool) => tool === "refund" || tool === "sendEmail",
18
- * }),
19
- * prompt,
20
- * });
21
- * ```
22
- *
23
- * `toolApproval` is the AI SDK's own approval hook on `generateText`,
24
- * `streamText` and `ToolLoopAgent`; this function is one it accepts. A call
25
- * that needs no person is `not-applicable`. One that does waits for Deliverd:
26
- * `approved` runs it, `denied` hands the model the person's reason.
27
- *
28
- * Shapes follow `GenericToolApprovalFunction` and `ToolApprovalStatus` in
29
- * `ai`'s type definitions (v7).
30
- */
31
-
32
- /** The part of the AI SDK's approval call this adapter reads. */
33
- export interface AiSdkApprovalCall {
34
- toolCall: { toolName: string; toolCallId: string; input: unknown };
35
- }
36
-
37
- export type AiSdkApprovalStatus =
38
- | { type: "not-applicable" }
39
- | { type: "approved"; reason?: string }
40
- | { type: "denied"; reason?: string };
41
-
42
- export function deliverdToolApproval(
43
- options: ToolApprovalOptions
44
- ): (call: AiSdkApprovalCall) => Promise<AiSdkApprovalStatus> {
45
- return async ({ toolCall }) => {
46
- if (options.when && !(await options.when(toolCall.toolName, toolCall.input))) {
47
- return { type: "not-applicable" };
48
- }
49
- const outcome = await askAboutCall(
50
- toolCall.toolName,
51
- toolCall.input,
52
- `ai-sdk:${toolCall.toolCallId}`,
53
- options
54
- );
55
- return outcome.allowed
56
- ? { type: "approved", reason: outcome.decidedBy ? `Approved by ${outcome.decidedBy}` : undefined }
57
- : { type: "denied", reason: outcome.reason };
58
- };
59
- }
1
+ import { askAboutCall, type ToolApprovalOptions } from "./shared.js";
2
+
3
+ /**
4
+ * The Vercel AI SDK: a person approves tool calls, through Deliverd.
5
+ *
6
+ * ```ts
7
+ * import { generateText } from "ai";
8
+ * import { Deliverd } from "@deliverd/sdk";
9
+ * import { deliverdToolApproval } from "@deliverd/sdk/adapters";
10
+ *
11
+ * const result = await generateText({
12
+ * model,
13
+ * tools: { refund, sendEmail, lookupOrder },
14
+ * toolApproval: deliverdToolApproval({
15
+ * deliverd: new Deliverd(),
16
+ * approvers: ["finance"],
17
+ * when: (tool) => tool === "refund" || tool === "sendEmail",
18
+ * }),
19
+ * prompt,
20
+ * });
21
+ * ```
22
+ *
23
+ * `toolApproval` is the AI SDK's own approval hook on `generateText`,
24
+ * `streamText` and `ToolLoopAgent`; this function is one it accepts. A call
25
+ * that needs no person is `not-applicable`. One that does waits for Deliverd:
26
+ * `approved` runs it, `denied` hands the model the person's reason.
27
+ *
28
+ * Shapes follow `GenericToolApprovalFunction` and `ToolApprovalStatus` in
29
+ * `ai`'s type definitions (v7).
30
+ */
31
+
32
+ /** The part of the AI SDK's approval call this adapter reads. */
33
+ export interface AiSdkApprovalCall {
34
+ toolCall: { toolName: string; toolCallId: string; input: unknown };
35
+ }
36
+
37
+ export type AiSdkApprovalStatus =
38
+ | { type: "not-applicable" }
39
+ | { type: "approved"; reason?: string }
40
+ | { type: "denied"; reason?: string };
41
+
42
+ export function deliverdToolApproval(
43
+ options: ToolApprovalOptions
44
+ ): (call: AiSdkApprovalCall) => Promise<AiSdkApprovalStatus> {
45
+ return async ({ toolCall }) => {
46
+ if (options.when && !(await options.when(toolCall.toolName, toolCall.input))) {
47
+ return { type: "not-applicable" };
48
+ }
49
+ const outcome = await askAboutCall(
50
+ toolCall.toolName,
51
+ toolCall.input,
52
+ `ai-sdk:${toolCall.toolCallId}`,
53
+ options
54
+ );
55
+ return outcome.allowed
56
+ ? { type: "approved", reason: outcome.decidedBy ? `Approved by ${outcome.decidedBy}` : undefined }
57
+ : { type: "denied", reason: outcome.reason };
58
+ };
59
+ }
@@ -1,90 +1,90 @@
1
- import { askAboutCall, type ToolApprovalOptions } from "./shared.js";
2
-
3
- /**
4
- * The Claude Agent SDK: a person approves tool calls, through Deliverd.
5
- *
6
- * ```ts
7
- * import { query } from "@anthropic-ai/claude-agent-sdk";
8
- * import { Deliverd } from "@deliverd/sdk";
9
- * import { deliverdCanUseTool } from "@deliverd/sdk/adapters";
10
- *
11
- * const deliverd = new Deliverd();
12
- * for await (const message of query({
13
- * prompt: "Tidy the release notes and publish them",
14
- * options: {
15
- * canUseTool: deliverdCanUseTool({
16
- * deliverd,
17
- * approvers: ["release-managers"],
18
- * when: (tool) => tool === "Bash" || tool.startsWith("mcp__"),
19
- * }),
20
- * },
21
- * })) { … }
22
- * ```
23
- *
24
- * A call that needs no person is allowed with its input unchanged. One that
25
- * does waits for the decision, from the page, the email link, Slack or Teams:
26
- * allowed, it runs; declined, the model is told why and told not to retry.
27
- * The run's abort signal cancels the wait.
28
- *
29
- * Shapes follow `CanUseTool` and `PermissionResult` in
30
- * `@anthropic-ai/claude-agent-sdk`'s `sdk.d.ts`.
31
- */
32
-
33
- /** The options `canUseTool` receives that this adapter reads. */
34
- export interface ClaudeCanUseToolContext {
35
- signal: AbortSignal;
36
- /** The tool call's id, which keeps a retried call from asking twice. */
37
- toolUseID?: string;
38
- }
39
-
40
- export type ClaudePermissionResult =
41
- | { behavior: "allow"; updatedInput: Record<string, unknown> }
42
- | { behavior: "deny"; message: string };
43
-
44
- export type ClaudeCanUseTool = (
45
- toolName: string,
46
- input: Record<string, unknown>,
47
- context: ClaudeCanUseToolContext
48
- ) => Promise<ClaudePermissionResult>;
49
-
50
- export interface ClaudeToolApprovalOptions extends ToolApprovalOptions {
51
- /**
52
- * Fields of a tool's input the approver may correct before approving, per
53
- * tool: `editable: (tool) => tool === "refund" ? ["amount"] : []`. The call
54
- * then runs with what they approved — the Agent SDK's `updatedInput` —
55
- * rather than with what the model proposed.
56
- */
57
- editable?: (toolName: string, input: Record<string, unknown>) => string[];
58
- }
59
-
60
- export function deliverdCanUseTool(options: ClaudeToolApprovalOptions): ClaudeCanUseTool {
61
- return async (toolName, input, context) => {
62
- if (options.when && !(await options.when(toolName, input))) {
63
- return { behavior: "allow", updatedInput: input };
64
- }
65
- const id = context.toolUseID ?? `${toolName}:${stableHash(input)}`;
66
- const outcome = await askAboutCall(
67
- toolName,
68
- input,
69
- `claude-agent-sdk:${id}`,
70
- options,
71
- context.signal,
72
- options.editable?.(toolName, input)
73
- );
74
- // What was approved runs, which is the proposal unless a person corrected it.
75
- return outcome.allowed
76
- ? { behavior: "allow", updatedInput: outcome.input ?? input }
77
- : { behavior: "deny", message: outcome.reason };
78
- };
79
- }
80
-
81
- /** A short, stable fingerprint of an input, for when no call id is given. */
82
- function stableHash(value: unknown): string {
83
- const text = JSON.stringify(value) ?? "";
84
- let h = 0x811c9dc5;
85
- for (let i = 0; i < text.length; i++) {
86
- h ^= text.charCodeAt(i);
87
- h = Math.imul(h, 0x01000193);
88
- }
89
- return (h >>> 0).toString(16);
90
- }
1
+ import { askAboutCall, type ToolApprovalOptions } from "./shared.js";
2
+
3
+ /**
4
+ * The Claude Agent SDK: a person approves tool calls, through Deliverd.
5
+ *
6
+ * ```ts
7
+ * import { query } from "@anthropic-ai/claude-agent-sdk";
8
+ * import { Deliverd } from "@deliverd/sdk";
9
+ * import { deliverdCanUseTool } from "@deliverd/sdk/adapters";
10
+ *
11
+ * const deliverd = new Deliverd();
12
+ * for await (const message of query({
13
+ * prompt: "Tidy the release notes and publish them",
14
+ * options: {
15
+ * canUseTool: deliverdCanUseTool({
16
+ * deliverd,
17
+ * approvers: ["release-managers"],
18
+ * when: (tool) => tool === "Bash" || tool.startsWith("mcp__"),
19
+ * }),
20
+ * },
21
+ * })) { … }
22
+ * ```
23
+ *
24
+ * A call that needs no person is allowed with its input unchanged. One that
25
+ * does waits for the decision, from the page, the email link, Slack or Teams:
26
+ * allowed, it runs; declined, the model is told why and told not to retry.
27
+ * The run's abort signal cancels the wait.
28
+ *
29
+ * Shapes follow `CanUseTool` and `PermissionResult` in
30
+ * `@anthropic-ai/claude-agent-sdk`'s `sdk.d.ts`.
31
+ */
32
+
33
+ /** The options `canUseTool` receives that this adapter reads. */
34
+ export interface ClaudeCanUseToolContext {
35
+ signal: AbortSignal;
36
+ /** The tool call's id, which keeps a retried call from asking twice. */
37
+ toolUseID?: string;
38
+ }
39
+
40
+ export type ClaudePermissionResult =
41
+ | { behavior: "allow"; updatedInput: Record<string, unknown> }
42
+ | { behavior: "deny"; message: string };
43
+
44
+ export type ClaudeCanUseTool = (
45
+ toolName: string,
46
+ input: Record<string, unknown>,
47
+ context: ClaudeCanUseToolContext
48
+ ) => Promise<ClaudePermissionResult>;
49
+
50
+ export interface ClaudeToolApprovalOptions extends ToolApprovalOptions {
51
+ /**
52
+ * Fields of a tool's input the approver may correct before approving, per
53
+ * tool: `editable: (tool) => tool === "refund" ? ["amount"] : []`. The call
54
+ * then runs with what they approved — the Agent SDK's `updatedInput` —
55
+ * rather than with what the model proposed.
56
+ */
57
+ editable?: (toolName: string, input: Record<string, unknown>) => string[];
58
+ }
59
+
60
+ export function deliverdCanUseTool(options: ClaudeToolApprovalOptions): ClaudeCanUseTool {
61
+ return async (toolName, input, context) => {
62
+ if (options.when && !(await options.when(toolName, input))) {
63
+ return { behavior: "allow", updatedInput: input };
64
+ }
65
+ const id = context.toolUseID ?? `${toolName}:${stableHash(input)}`;
66
+ const outcome = await askAboutCall(
67
+ toolName,
68
+ input,
69
+ `claude-agent-sdk:${id}`,
70
+ options,
71
+ context.signal,
72
+ options.editable?.(toolName, input)
73
+ );
74
+ // What was approved runs, which is the proposal unless a person corrected it.
75
+ return outcome.allowed
76
+ ? { behavior: "allow", updatedInput: outcome.input ?? input }
77
+ : { behavior: "deny", message: outcome.reason };
78
+ };
79
+ }
80
+
81
+ /** A short, stable fingerprint of an input, for when no call id is given. */
82
+ function stableHash(value: unknown): string {
83
+ const text = JSON.stringify(value) ?? "";
84
+ let h = 0x811c9dc5;
85
+ for (let i = 0; i < text.length; i++) {
86
+ h ^= text.charCodeAt(i);
87
+ h = Math.imul(h, 0x01000193);
88
+ }
89
+ return (h >>> 0).toString(16);
90
+ }
@@ -1,23 +1,23 @@
1
- /**
2
- * Deliverd inside the agent frameworks people already use: a person approves
3
- * a tool call from their inbox, Slack or Teams, and the agent carries on.
4
- *
5
- * `@deliverd/sdk/adapters`, separate from the main entry so none of it is
6
- * loaded unless it is used. No dependencies: each adapter matches its
7
- * framework's hook by shape.
8
- */
9
- export { deliverdCanUseTool } from "./claude-agent-sdk.js";
10
- export type {
11
- ClaudeCanUseTool,
12
- ClaudeCanUseToolContext,
13
- ClaudePermissionResult,
14
- ClaudeToolApprovalOptions,
15
- } from "./claude-agent-sdk.js";
16
- export { deliverdToolApproval } from "./ai-sdk.js";
17
- export type { AiSdkApprovalCall, AiSdkApprovalStatus } from "./ai-sdk.js";
18
- export { resolveInterruptions, runWithDeliverdApprovals } from "./openai-agents.js";
19
- export type { OpenAiApprovalItem, OpenAiInterruptedResult } from "./openai-agents.js";
20
- export { approveInGraph, resumeFromCallback } from "./langgraph.js";
21
- export type { DeliverdInterruptValue, GraphApprovalRecord, GraphApprover, GraphDecision } from "./langgraph.js";
22
- export { defaultDescription, DEFAULT_TOOL_EXPIRY } from "./shared.js";
23
- export type { Approver, CallDescription, CallOutcome, ToolApprovalOptions } from "./shared.js";
1
+ /**
2
+ * Deliverd inside the agent frameworks people already use: a person approves
3
+ * a tool call from their inbox, Slack or Teams, and the agent carries on.
4
+ *
5
+ * `@deliverd/sdk/adapters`, separate from the main entry so none of it is
6
+ * loaded unless it is used. No dependencies: each adapter matches its
7
+ * framework's hook by shape.
8
+ */
9
+ export { deliverdCanUseTool } from "./claude-agent-sdk.js";
10
+ export type {
11
+ ClaudeCanUseTool,
12
+ ClaudeCanUseToolContext,
13
+ ClaudePermissionResult,
14
+ ClaudeToolApprovalOptions,
15
+ } from "./claude-agent-sdk.js";
16
+ export { deliverdToolApproval } from "./ai-sdk.js";
17
+ export type { AiSdkApprovalCall, AiSdkApprovalStatus } from "./ai-sdk.js";
18
+ export { resolveInterruptions, runWithDeliverdApprovals } from "./openai-agents.js";
19
+ export type { OpenAiApprovalItem, OpenAiInterruptedResult } from "./openai-agents.js";
20
+ export { approveInGraph, resumeFromCallback } from "./langgraph.js";
21
+ export type { DeliverdInterruptValue, GraphApprovalRecord, GraphApprover, GraphDecision } from "./langgraph.js";
22
+ export { defaultDescription, DEFAULT_TOOL_EXPIRY } from "./shared.js";
23
+ export type { Approver, CallDescription, CallOutcome, ToolApprovalOptions } from "./shared.js";