@signet-auth/vercel-ai 0.4.4

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/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # @signet-auth/vercel-ai
2
+
3
+ Signet signing callbacks for Vercel AI SDK. Signs every tool call with Ed25519 — 3 lines of code, no infrastructure.
4
+
5
+ [![npm](https://img.shields.io/npm/v/@signet-auth/vercel-ai?style=flat-square)](https://www.npmjs.com/package/@signet-auth/vercel-ai)
6
+ [![GitHub Stars](https://img.shields.io/github/stars/Prismer-AI/signet?style=flat-square&color=yellow)](https://github.com/Prismer-AI/signet)
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install @signet-auth/vercel-ai @signet-auth/core
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ```typescript
17
+ import { generateText } from "ai";
18
+ import { openai } from "@ai-sdk/openai";
19
+ import { createSignetCallbacks } from "@signet-auth/vercel-ai";
20
+ import { generateKeypair } from "@signet-auth/core";
21
+
22
+ const { secretKey } = generateKeypair();
23
+ const callbacks = createSignetCallbacks(secretKey, "my-agent");
24
+
25
+ const result = await generateText({
26
+ model: openai("gpt-4o"),
27
+ tools: { myTool },
28
+ ...callbacks,
29
+ prompt: "Use the tool to ...",
30
+ });
31
+
32
+ console.log(callbacks.receipts); // signed receipts for every tool call
33
+ ```
34
+
35
+ ## Links
36
+
37
+ - [Full documentation & all SDKs](https://github.com/Prismer-AI/signet)
38
+
39
+ If Signet is useful to you, [star us on GitHub](https://github.com/Prismer-AI/signet) — it helps others discover the project.
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Signet signing callbacks for Vercel AI SDK.
3
+ *
4
+ * Usage:
5
+ * import { generateText } from "ai";
6
+ * import { createSignetCallbacks } from "@signet-auth/vercel-ai";
7
+ * import { generateKeypair } from "@signet-auth/core";
8
+ *
9
+ * const { secretKey } = generateKeypair();
10
+ * const callbacks = createSignetCallbacks(secretKey, "my-agent");
11
+ *
12
+ * const result = await generateText({
13
+ * model: openai("gpt-4"),
14
+ * tools: { myTool },
15
+ * ...callbacks,
16
+ * prompt: "...",
17
+ * });
18
+ *
19
+ * console.log(callbacks.receipts); // all signed receipts
20
+ */
21
+ import { type SignetReceipt } from "@signet-auth/core";
22
+ /** A signed receipt from a tool call. */
23
+ export interface ToolCallReceipt {
24
+ toolName: string;
25
+ toolCallId: string;
26
+ receipt: SignetReceipt;
27
+ durationMs?: number;
28
+ }
29
+ /** Options for createSignetCallbacks. */
30
+ export interface SignetCallbackOptions {
31
+ /** Target URI for receipts (default: "vercel-ai://local"). */
32
+ target?: string;
33
+ /** Whether to include tool args hash in the receipt (default: true). */
34
+ hashArgs?: boolean;
35
+ }
36
+ /**
37
+ * Create Vercel AI SDK callbacks that sign every tool call with Signet.
38
+ *
39
+ * Returns an object with:
40
+ * - `experimental_onToolCallStart` — signs tool call before execution
41
+ * - `experimental_onToolCallFinish` — records completion with duration
42
+ * - `receipts` — array of all signed receipts
43
+ */
44
+ export declare function createSignetCallbacks(secretKey: string, signerName: string, options?: SignetCallbackOptions & {
45
+ signerOwner?: string;
46
+ }): {
47
+ receipts: ToolCallReceipt[];
48
+ experimental_onToolCallStart({ toolCallId, toolName, args, }: {
49
+ toolCallId: string;
50
+ toolName: string;
51
+ args: unknown;
52
+ }): void;
53
+ experimental_onToolCallFinish({ toolCallId, toolName, result, durationMs, }: {
54
+ toolCallId: string;
55
+ toolName: string;
56
+ result: unknown;
57
+ durationMs?: number;
58
+ }): void;
59
+ };
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Signet signing callbacks for Vercel AI SDK.
3
+ *
4
+ * Usage:
5
+ * import { generateText } from "ai";
6
+ * import { createSignetCallbacks } from "@signet-auth/vercel-ai";
7
+ * import { generateKeypair } from "@signet-auth/core";
8
+ *
9
+ * const { secretKey } = generateKeypair();
10
+ * const callbacks = createSignetCallbacks(secretKey, "my-agent");
11
+ *
12
+ * const result = await generateText({
13
+ * model: openai("gpt-4"),
14
+ * tools: { myTool },
15
+ * ...callbacks,
16
+ * prompt: "...",
17
+ * });
18
+ *
19
+ * console.log(callbacks.receipts); // all signed receipts
20
+ */
21
+ import { sign, contentHash } from "@signet-auth/core";
22
+ /**
23
+ * Create Vercel AI SDK callbacks that sign every tool call with Signet.
24
+ *
25
+ * Returns an object with:
26
+ * - `experimental_onToolCallStart` — signs tool call before execution
27
+ * - `experimental_onToolCallFinish` — records completion with duration
28
+ * - `receipts` — array of all signed receipts
29
+ */
30
+ export function createSignetCallbacks(secretKey, signerName, options = {}) {
31
+ const signerOwner = options.signerOwner ?? "";
32
+ const target = options.target ?? "vercel-ai://local";
33
+ const hashArgs = options.hashArgs ?? true;
34
+ const receipts = [];
35
+ return {
36
+ receipts,
37
+ experimental_onToolCallStart({ toolCallId, toolName, args, }) {
38
+ try {
39
+ const action = {
40
+ tool: toolName,
41
+ params: args,
42
+ params_hash: hashArgs && args != null ? contentHash(args) : contentHash({}),
43
+ target,
44
+ transport: "vercel-ai",
45
+ };
46
+ const receipt = sign(secretKey, action, signerName, signerOwner);
47
+ receipts.push({ toolName, toolCallId, receipt });
48
+ }
49
+ catch (err) {
50
+ // Never block tool execution, but log for debugging
51
+ console.warn("[signet] Failed to sign tool call:", err);
52
+ }
53
+ },
54
+ experimental_onToolCallFinish({ toolCallId, toolName, result, durationMs, }) {
55
+ // Update the matching receipt with duration
56
+ const entry = receipts.find((r) => r.toolCallId === toolCallId && r.toolName === toolName);
57
+ if (entry) {
58
+ entry.durationMs = durationMs;
59
+ }
60
+ },
61
+ };
62
+ }
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@signet-auth/vercel-ai",
3
+ "version": "0.4.4",
4
+ "description": "Signet signing middleware for Vercel AI SDK",
5
+ "type": "module",
6
+ "main": "dist/src/index.js",
7
+ "types": "dist/src/index.d.ts",
8
+ "files": ["dist/"],
9
+ "scripts": {
10
+ "build": "npx tsc",
11
+ "test": "npx tsc -p tsconfig.test.json && node --test dist-test/tests/vercel-ai.test.js"
12
+ },
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "dependencies": {
17
+ "@signet-auth/core": "^0.4.4"
18
+ },
19
+ "devDependencies": {
20
+ "@types/node": "^22",
21
+ "typescript": "^5"
22
+ },
23
+ "license": "Apache-2.0 OR MIT"
24
+ }