@atlasauth/pca-anthropic 0.0.0-stage → 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Atlas Authorization
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,62 @@
1
- # Temporary Holding Version
1
+ # @atlasauth/pca-anthropic
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Anthropic (Claude) adapter for Proof-Carrying Authority (PCA). It sits between a Claude `tool_use` block and the `tool_result` you send back: it turns the block into a PCActn (a signed proof-carrying action) using a PCA `Agent`, runs your handler with the proof in hand, and returns the `tool_result` block, including the error-shaped result Claude expects when a tool is declined or throws.
4
+
5
+ It does not authorize anything itself: it attaches a proof, and the resource server's verifier decides. A handler that forgets to forward the proof just produces a downstream call without a valid PCActn, which fails server-side.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm i @atlasauth/pca-anthropic @atlasauth/pca
11
+ npm i @anthropic-ai/sdk
12
+ ```
13
+
14
+ `@anthropic-ai/sdk` is an optional peer dependency; the adapter models only the block shapes it touches and does not import the SDK at runtime.
15
+
16
+ ## Usage
17
+
18
+ ```ts
19
+ import { agent, generateKeyPair } from '@atlasauth/pca';
20
+ import { handleToolUses, extractToolUses } from '@atlasauth/pca-anthropic';
21
+
22
+ const pcaAgent = agent({
23
+ principal: generateKeyPair(),
24
+ goal: 'issue refunds',
25
+ permissions: { stripe: ['refund'] },
26
+ limits: { refund: '$500/day' },
27
+ aud: 'ins_acme', // the id your resource server verifies against
28
+ });
29
+
30
+ // After each assistant turn, answer every tool_use block:
31
+ const toolResults = await handleToolUses(
32
+ pcaAgent,
33
+ extractToolUses(message.content),
34
+ ({ name, input }) => // map tool -> { verb, resource }; return null to decline
35
+ name === 'refund' ? { verb: 'stripe.refund', resource: `charge:${input.chargeId}` } : null,
36
+ {
37
+ refund: async (input, pca) => { // pca.headers / pca.encoded carry the signed proof
38
+ return doRefund(input, pca.headers);
39
+ },
40
+ },
41
+ );
42
+ // -> [{ type: 'tool_result', tool_use_id, content }]; is_error: true when declined, unhandled or thrown
43
+ // Append them to your next user message's content.
44
+ ```
45
+
46
+ `handleToolUse` does the same for a single block. On success `content` is the JSON of your handler's return value (or `{ pca: <encoded> }` if it returns nothing).
47
+
48
+ ## API
49
+
50
+ - `handleToolUse(agent, block, map, handlers, opts?)`, `handleToolUses(agent, blocks, map, handlers, opts?)`, `extractToolUses(content)`.
51
+ - Types: `ToolUseBlock`, `ToolResultBlock`, `ToolMapping`, `ToolHandler`.
52
+ - Re-exports from `@atlasauth/pca`: `pcaHeaders`, `PcaCall`.
53
+
54
+ ## Status
55
+
56
+ Experimental. The underlying cryptography in `@atlasauth/pca` has not been independently audited.
57
+
58
+ Source and issues: https://github.com/Atlas-Authorization/pca
59
+
60
+ ## License
61
+
62
+ MIT - see LICENSE
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Anthropic (Claude) adapter for Proof-Carrying Authority.
3
+ *
4
+ * Claude's tool use is a conversation: an assistant message carries content blocks, and a
5
+ * `tool_use` block (`{ type, id, name, input }`) asks your app to run a tool. Your app runs it and
6
+ * replies with a user message containing a matching `tool_result` block (`{ tool_use_id, content }`).
7
+ * This adapter sits in that gap: it turns a `tool_use` block into a PCActn (via the core
8
+ * `bridgeToolCall`), runs your handler with the proof in hand, and hands back the `tool_result` to
9
+ * append to the next message — including the error-shaped result Claude expects when a tool refuses.
10
+ *
11
+ * Structurally compatible with the `@anthropic-ai/sdk` package (declared as an OPTIONAL peer
12
+ * dependency). We model only the block shapes we touch, so this works across SDK minor versions
13
+ * without importing its runtime — nothing here requires the SDK to be installed.
14
+ *
15
+ * HONEST: this does not authorize — it attaches a proof-carrying action; the resource server's
16
+ * verifier decides. A handler that forgets to forward the proof just means the downstream action
17
+ * lacks a valid PCActn and fails server-side.
18
+ */
19
+ import { type Agent, type PcaCall, pcaHeaders } from '@atlasauth/pca';
20
+ /** A Claude `tool_use` content block (what the model emits to call a tool). */
21
+ export interface ToolUseBlock {
22
+ type: 'tool_use';
23
+ id: string;
24
+ name: string;
25
+ input: Record<string, unknown>;
26
+ }
27
+ /** A Claude `tool_result` content block (what your app replies with). */
28
+ export interface ToolResultBlock {
29
+ type: 'tool_result';
30
+ tool_use_id: string;
31
+ content: string;
32
+ is_error?: boolean;
33
+ }
34
+ /** How a Claude tool name + input maps onto a PCA (verb, resource). Return null to decline the tool. */
35
+ export type ToolMapping = (block: {
36
+ name: string;
37
+ input: Record<string, unknown>;
38
+ }) => {
39
+ verb: string;
40
+ resource: string;
41
+ } | null;
42
+ /** Your tool implementation: gets the model's input and the PCActn so it can carry the proof downstream. */
43
+ export type ToolHandler = (input: Record<string, unknown>, pca: import('@atlasauth/pca').PcaCall) => Promise<unknown> | unknown;
44
+ /**
45
+ * Handle one `tool_use` block: build its PCActn, run the mapped handler, and return the `tool_result`.
46
+ *
47
+ * If the mapping declines the tool (returns null), we never run the handler — we return a
48
+ * `tool_result` with `is_error: true` so Claude sees the refusal. If the handler throws, we likewise
49
+ * return an error-shaped `tool_result`. On success, `content` is `JSON.stringify(result)`, falling
50
+ * back to `{ pca: <encoded> }` when the handler returns nothing.
51
+ */
52
+ export declare function handleToolUse(agent: Agent, block: ToolUseBlock, map: ToolMapping, handlers: Record<string, ToolHandler>, opts?: {
53
+ aud?: string;
54
+ counter?: number;
55
+ now?: number;
56
+ }): Promise<ToolResultBlock>;
57
+ /** Handle many `tool_use` blocks (e.g. all of them from one assistant turn), preserving order. */
58
+ export declare function handleToolUses(agent: Agent, blocks: ToolUseBlock[], map: ToolMapping, handlers: Record<string, ToolHandler>, opts?: {
59
+ aud?: string;
60
+ counter?: number;
61
+ now?: number;
62
+ }): Promise<ToolResultBlock[]>;
63
+ /** Pull the `tool_use` blocks out of an assistant message's `content` array (ignoring text/other blocks). */
64
+ export declare function extractToolUses(content: Array<{
65
+ type: string;
66
+ [k: string]: unknown;
67
+ }>): ToolUseBlock[];
68
+ export { pcaHeaders, type PcaCall };
package/dist/index.js ADDED
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ /**
3
+ * Anthropic (Claude) adapter for Proof-Carrying Authority.
4
+ *
5
+ * Claude's tool use is a conversation: an assistant message carries content blocks, and a
6
+ * `tool_use` block (`{ type, id, name, input }`) asks your app to run a tool. Your app runs it and
7
+ * replies with a user message containing a matching `tool_result` block (`{ tool_use_id, content }`).
8
+ * This adapter sits in that gap: it turns a `tool_use` block into a PCActn (via the core
9
+ * `bridgeToolCall`), runs your handler with the proof in hand, and hands back the `tool_result` to
10
+ * append to the next message — including the error-shaped result Claude expects when a tool refuses.
11
+ *
12
+ * Structurally compatible with the `@anthropic-ai/sdk` package (declared as an OPTIONAL peer
13
+ * dependency). We model only the block shapes we touch, so this works across SDK minor versions
14
+ * without importing its runtime — nothing here requires the SDK to be installed.
15
+ *
16
+ * HONEST: this does not authorize — it attaches a proof-carrying action; the resource server's
17
+ * verifier decides. A handler that forgets to forward the proof just means the downstream action
18
+ * lacks a valid PCActn and fails server-side.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.pcaHeaders = void 0;
22
+ exports.handleToolUse = handleToolUse;
23
+ exports.handleToolUses = handleToolUses;
24
+ exports.extractToolUses = extractToolUses;
25
+ const pca_1 = require("@atlasauth/pca");
26
+ Object.defineProperty(exports, "pcaHeaders", { enumerable: true, get: function () { return pca_1.pcaHeaders; } });
27
+ /**
28
+ * Handle one `tool_use` block: build its PCActn, run the mapped handler, and return the `tool_result`.
29
+ *
30
+ * If the mapping declines the tool (returns null), we never run the handler — we return a
31
+ * `tool_result` with `is_error: true` so Claude sees the refusal. If the handler throws, we likewise
32
+ * return an error-shaped `tool_result`. On success, `content` is `JSON.stringify(result)`, falling
33
+ * back to `{ pca: <encoded> }` when the handler returns nothing.
34
+ */
35
+ async function handleToolUse(agent, block, map, handlers, opts) {
36
+ const pca = (0, pca_1.bridgeToolCall)(agent, { name: block.name, arguments: block.input }, (b) => map({ name: b.name, input: b.arguments }), opts);
37
+ if (!pca) {
38
+ return {
39
+ type: 'tool_result',
40
+ tool_use_id: block.id,
41
+ content: `No proof-carrying authority is mapped for tool "${block.name}".`,
42
+ is_error: true,
43
+ };
44
+ }
45
+ const handler = handlers[block.name];
46
+ if (!handler) {
47
+ return {
48
+ type: 'tool_result',
49
+ tool_use_id: block.id,
50
+ content: `No handler registered for tool "${block.name}".`,
51
+ is_error: true,
52
+ };
53
+ }
54
+ try {
55
+ const result = await handler(block.input, pca);
56
+ return {
57
+ type: 'tool_result',
58
+ tool_use_id: block.id,
59
+ content: JSON.stringify(result ?? { pca: pca.encoded }),
60
+ };
61
+ }
62
+ catch (err) {
63
+ return {
64
+ type: 'tool_result',
65
+ tool_use_id: block.id,
66
+ content: err instanceof Error ? err.message : String(err),
67
+ is_error: true,
68
+ };
69
+ }
70
+ }
71
+ /** Handle many `tool_use` blocks (e.g. all of them from one assistant turn), preserving order. */
72
+ async function handleToolUses(agent, blocks, map, handlers, opts) {
73
+ const uses = blocks.filter((b) => b.type === 'tool_use');
74
+ return Promise.all(uses.map((b) => handleToolUse(agent, b, map, handlers, opts)));
75
+ }
76
+ /** Pull the `tool_use` blocks out of an assistant message's `content` array (ignoring text/other blocks). */
77
+ function extractToolUses(content) {
78
+ return content.filter((b) => b.type === 'tool_use');
79
+ }
80
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAwCH,sCA6CC;AAGD,wCASC;AAGD,0CAEC;AApGD,wCAAsF;AAsG7E,2FAtG0C,gBAAU,OAsG1C;AAxEnB;;;;;;;GAOG;AACI,KAAK,UAAU,aAAa,CACjC,KAAY,EACZ,KAAmB,EACnB,GAAgB,EAChB,QAAqC,EACrC,IAAuD;IAEvD,MAAM,GAAG,GAAG,IAAA,oBAAc,EACxB,KAAK,EACL,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,KAAK,EAAE,EAC5C,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC,EAChD,IAAI,CACL,CAAC;IACF,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO;YACL,IAAI,EAAE,aAAa;YACnB,WAAW,EAAE,KAAK,CAAC,EAAE;YACrB,OAAO,EAAE,mDAAmD,KAAK,CAAC,IAAI,IAAI;YAC1E,QAAQ,EAAE,IAAI;SACf,CAAC;IACJ,CAAC;IACD,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,CAAC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F,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAA+C,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;AACnG,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,64 @@
1
1
  {
2
2
  "name": "@atlasauth/pca-anthropic",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "Anthropic (Claude) adapter for Proof-Carrying Authority: turn a tool_use block into a PCActn and build the tool_result with the proof attached.",
5
+ "keywords": [
6
+ "anthropic",
7
+ "claude",
8
+ "tool use",
9
+ "agent authorization",
10
+ "proof-carrying authority",
11
+ "pca",
12
+ "ai agents"
13
+ ],
14
+ "license": "MIT",
15
+ "homepage": "https://github.com/Atlas-Authorization/pca#readme",
16
+ "bugs": {
17
+ "url": "https://github.com/Atlas-Authorization/pca/issues"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/Atlas-Authorization/pca.git",
22
+ "directory": "packages/pca-anthropic"
23
+ },
24
+ "main": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "default": "./dist/index.js"
30
+ },
31
+ "./package.json": "./package.json"
32
+ },
33
+ "dependencies": {
34
+ "@atlasauth/pca": "0.2.0"
35
+ },
36
+ "peerDependencies": {
37
+ "@anthropic-ai/sdk": "^0.30 || ^0.40 || ^0.50"
38
+ },
39
+ "peerDependenciesMeta": {
40
+ "@anthropic-ai/sdk": {
41
+ "optional": true
42
+ }
43
+ },
44
+ "devDependencies": {
45
+ "typescript": "^5.6.3",
46
+ "vitest": "^2.1.4"
47
+ },
48
+ "files": [
49
+ "dist",
50
+ "README.md",
51
+ "LICENSE"
52
+ ],
53
+ "engines": {
54
+ "node": ">=20"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public"
58
+ },
59
+ "scripts": {
60
+ "build": "tsc -p tsconfig.build.json",
61
+ "typecheck": "tsc -p tsconfig.json --noEmit",
62
+ "test": "vitest run"
63
+ }
6
64
  }