@pidgeon-ai/sdk 1.68.0 → 2.0.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 CHANGED
@@ -1,21 +1,55 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 PCN Labs OÜ
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.
1
+ Apache License
2
+
3
+ Version 2.0, January 2004
4
+
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
16
+
17
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
18
+
19
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
20
+
21
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
22
+
23
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
24
+
25
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
26
+
27
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
28
+
29
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
30
+
31
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
32
+
33
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
34
+
35
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
36
+
37
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and
38
+
39
+ You must cause any modified files to carry prominent notices stating that You changed the files; and
40
+
41
+ You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
42
+
43
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
44
+
45
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
46
+
47
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
48
+
49
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
50
+
51
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
52
+
53
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
54
+
55
+ END OF TERMS AND CONDITIONS
package/README.md CHANGED
@@ -1,238 +1,138 @@
1
1
  # @pidgeon-ai/sdk
2
2
 
3
- Pidgeon is the email inbox API for AI agents. It gives agents their own inboxes
4
- so they can work with emails just like a human. This is its TypeScript client:
5
- one typed function per operation, plus a webhook verifier.
3
+ Pidgeon's TypeScript SDK for its four products: Passport (your agents' keys
4
+ and reputation), Bouncer (verify agents at your site), Email (inboxes for
5
+ agents) and Auth (Sign in with Pidgeon). https://pidgeon.ai
6
6
 
7
- ```bash
7
+ ```sh
8
8
  npm install @pidgeon-ai/sdk
9
9
  ```
10
10
 
11
- Or `pnpm add @pidgeon-ai/sdk`. **Zero dependencies.** Needs `fetch` and
12
- `crypto.subtle`, so it runs on Node 18+, Bun, Deno, Cloudflare Workers and
13
- Vercel functions. ESM and CommonJS.
11
+ Version 2 is for the new Pidgeon. Code written for 1.x (the old email API at
12
+ `/api/v1`) keeps working on 1.68.0 until that API is retired.
14
13
 
15
- ## Create an address, send, receive, reply
14
+ ## Set an agent up
16
15
 
17
16
  ```ts
18
- import {
19
- client,
20
- identitiesCreate,
21
- messagesAwait,
22
- messagesReply,
23
- messagesSend,
24
- } from '@pidgeon-ai/sdk';
25
-
26
- client.setConfig({ auth: () => process.env.PIDGEON_API_KEY! });
27
-
28
- // 1. An address of its own. Any free name on pidgeon.email works with no DNS.
29
- const { data: address } = await identitiesCreate({
30
- body: { address: 'scout@pidgeon.email', type: 'agent' },
31
- throwOnError: true,
32
- });
17
+ import { Pidgeon } from '@pidgeon-ai/sdk';
33
18
 
34
- // 2. Send from it.
35
- await messagesSend({
36
- body: {
37
- from: address.data.email,
38
- to: 'ops@example.com',
39
- subject: 'Staging access',
40
- text: 'Could you send me the access code?',
41
- },
42
- throwOnError: true,
43
- });
19
+ const pidgeon = new Pidgeon({ apiKey: process.env.PIDGEON_API_KEY! });
44
20
 
45
- // 3. Receive: one held-open request until the answer arrives, up to 60 seconds.
46
- const { data: awaited } = await messagesAwait({
47
- query: { identity_id: address.data.id, timeout: 60 },
48
- throwOnError: true,
21
+ // Registers the agent, makes its key here, and publishes the public half
22
+ // signed with it. Keep key.privateJwk where the agent runs: Pidgeon never sees it.
23
+ const { agent, key } = await pidgeon.agents.setUp({
24
+ name: 'Booking agent',
25
+ purpose: 'Books tables.',
49
26
  });
50
27
 
51
- // 4. Reply into the same conversation. Recipients and subject come off the original.
52
- if (awaited.data.message) {
53
- console.log(awaited.data.message.extracted.codes);
54
- await messagesReply({
55
- path: { id: awaited.data.message.id },
56
- body: { text: 'Thanks, that worked.' },
57
- throwOnError: true,
58
- });
59
- }
28
+ const { reputation } = await pidgeon.agents.get(agent.id);
29
+ reputation.band; // unverified, new, good, flagged or suspended
60
30
  ```
61
31
 
62
- `PIDGEON_API_KEY` is a `pgn_live_…` key. Make one at
63
- [pidgeon.ai/app/developers/keys](https://pidgeon.ai/signup?utm_source=npm&utm_medium=readme&utm_campaign=sdk&next=/app/developers/keys), or
64
- let your agent sign itself up: [pidgeon.ai/skill.md](https://pidgeon.ai/skill.md)
65
- is two calls, and the only thing it needs from a person is a six-digit code.
32
+ From a terminal or a coding agent, `@pidgeon-ai/cli` and `@pidgeon-ai/mcp`
33
+ do the same, and keep the key in a file on your machine
34
+ (`@pidgeon-ai/sdk/node`: `setUpAgent`, `agentFromKeyFile`).
66
35
 
67
- In production, take a [signed webhook](#receiving-mail) rather than holding a
68
- request open. Documentation: [pidgeon.ai/docs](https://pidgeon.ai/docs) ·
69
- [API reference](https://pidgeon.ai/docs/reference) ·
70
- [OpenAPI](https://pidgeon.ai/openapi.json).
71
-
72
- ## The shape
73
-
74
- **There is no `Pidgeon` class.** Every operation is a function named for its
75
- tag — `messagesSend`, `messagesGet`, `threadsUpdate` — and they share one
76
- client you configure at startup. The Python package is generated from the same
77
- document, so an operation has the same name in both.
36
+ ## Sign your agent's requests
78
37
 
79
38
  ```ts
80
- import { client, messagesGet } from '@pidgeon-ai/sdk';
81
-
82
- client.setConfig({ auth: () => process.env.PIDGEON_API_KEY! });
39
+ import { agentFromEnv } from '@pidgeon-ai/sdk';
83
40
 
84
- const { data, error } = await messagesGet({ path: { id: messageId } });
41
+ // PIDGEON_AGENT_KEY is the private JWK, PIDGEON_DIRECTORY the agent's directory.
42
+ const agent = agentFromEnv();
43
+ await agent.fetch('https://shop.example/api/orders', { method: 'POST' });
85
44
  ```
86
45
 
87
- A call resolves to `{ data, error }` rather than throwing: `error` carries the
88
- API's own `code`, a `message` written for a person, and a `field` when one
89
- input was at fault. Pass `throwOnError: true` on a call to get the data
90
- directly and an exception instead.
91
-
92
- ## Receiving mail
93
-
94
- Mail arriving at an address your code owns becomes an event, and your
95
- endpoint is called with a signed payload.
46
+ ## Verify an agent at your site (Bouncer)
96
47
 
97
48
  ```ts
98
- import { client, messagesGet, messagesReply, verifyWebhook } from '@pidgeon-ai/sdk';
99
-
100
- client.setConfig({ auth: () => process.env.PIDGEON_API_KEY! });
101
-
102
- export async function POST(request: Request) {
103
- // Verify first. An unverified payload is an unauthenticated POST that
104
- // claims a message arrived.
105
- const event = await verifyWebhook({
106
- rawBody: await request.text(),
107
- headers: request.headers,
108
- secret: process.env.PIDGEON_WEBHOOK_SECRET!,
109
- });
110
-
111
- if (event.type !== 'message.received') return new Response(null, { status: 204 });
112
-
113
- // The event carries ids, never a body. Exchange one for the content.
114
- const { data: mail } = await messagesGet({
115
- path: { id: event.data.message_id as string },
116
- throwOnError: true,
117
- });
118
-
119
- // Into the same conversation, threaded in the recipient's client too.
120
- await messagesReply({
121
- path: { id: mail.data.id },
122
- body: { text: 'Got it — someone will be in touch.' },
123
- throwOnError: true,
124
- });
125
-
126
- return new Response(null, { status: 204 });
49
+ const answer = await pidgeon.verify(request);
50
+ if (answer.valid && answer.reputation.band !== 'suspended') {
51
+ // answer.agent, answer.operator
127
52
  }
53
+ await pidgeon.report({ verificationId: answer.verification_id, category: 'spam', evidence: '…' });
128
54
  ```
129
55
 
130
- `rawBody` must be the exact bytes we sent. Parse the JSON _after_
131
- verifying — re-serialising changes key order and the signature will not
132
- match.
133
-
134
- `verifyWebhook` throws rather than returning a boolean, because the failure
135
- mode of a boolean is a caller who forgets to check it. It rejects a
136
- timestamp outside tolerance (five minutes by default) before it looks at
137
- the signature, and compares in constant time.
138
-
139
- ## Handing a conversation to a person
56
+ ## Email
140
57
 
141
58
  ```ts
142
- import { threadsUpdate } from '@pidgeon-ai/sdk';
59
+ const inbox = await pidgeon.inboxes.create({ name: 'bookings', agentId: agent.id });
60
+ await pidgeon.messages.send(inbox.id, {
61
+ to: ['ana@example.com'],
62
+ subject: 'Table for two',
63
+ text: 'Friday at 8?',
64
+ });
143
65
 
144
- await threadsUpdate({
145
- path: { id: threadId },
146
- body: { owner_type: 'human' },
147
- throwOnError: true,
66
+ // A person looks first:
67
+ const draft = await pidgeon.drafts.create(inbox.id, {
68
+ to: ['ana@example.com'],
69
+ subject: '…',
70
+ text: '…',
148
71
  });
72
+ await pidgeon.drafts.requestApproval(draft.id);
149
73
  ```
150
74
 
151
- Hand it back by setting `owner_type` to `agent`.
152
-
153
- It appears in the web inbox, and `thread.updated` tells whatever was
154
- driving the conversation that it no longer is.
155
-
156
- ## Errors
75
+ Also `pidgeon.rules`, `pidgeon.suppressions`, `pidgeon.events`, `pidgeon.pods`,
76
+ and `pidgeon.request(method, path, …)` for any `/v1` call. A refusal throws
77
+ `PidgeonError` with the API's `status` and `code`.
157
78
 
158
- A failure comes back in `error`, carrying the API's own `code`, a `message`
159
- written for a person and safe to show one, and the offending `field` on a
160
- validation failure.
79
+ Webhooks: `verifyWebhook(secret, rawBody, request.headers.get('pidgeon-signature'))`.
161
80
 
162
- ```ts
163
- const { data, error } = await messagesSend({ body: { from, to, text } });
164
-
165
- if (error) {
166
- if (error.error.code === 'rate_limited') {
167
- // Back off. Deliberately not done for you — see below.
168
- }
169
- throw new Error(error.error.message);
170
- }
171
- ```
81
+ ## Sign in with Pidgeon (`@pidgeon-ai/sdk/auth`)
172
82
 
173
- `code` is one of `validation`, `unauthenticated`, `entitlement`,
174
- `forbidden`, `not_found`, `conflict`, `rate_limited`, `internal`.
83
+ Register your site with `pidgeon.sites.create({ name, redirectUris })`; ask a
84
+ person to let your agent act for them with `pidgeon.mandates.create(…)`.
175
85
 
176
- With `throwOnError: true` the same failure is thrown instead and `data` is no
177
- longer `undefined`, which is the shape most call sites want.
86
+ People sign in to your site with any OpenID Connect library: the issuer is
87
+ `https://pidgeon.ai`, with the client id and secret you registered. Check an
88
+ ID token with `verifyIdToken(idToken, { clientId })`.
178
89
 
179
- ## Pagination
180
-
181
- List endpoints return a page, not an iterator.
90
+ An agent signs in with no person present, and sends its ID token with every
91
+ request it signs:
182
92
 
183
93
  ```ts
184
- import { eventsList } from '@pidgeon-ai/sdk';
94
+ import { signedFetch } from '@pidgeon-ai/sdk';
95
+ import { signInAsAgent } from '@pidgeon-ai/sdk/auth';
96
+
97
+ const { idToken } = await signInAsAgent({ site: 'site_…', key, directory });
98
+ await signedFetch(
99
+ 'https://shop.example/api/orders',
100
+ {
101
+ method: 'POST',
102
+ headers: { authorization: `Bearer ${idToken}` },
103
+ },
104
+ { privateJwk: key.privateJwk, directory },
105
+ );
106
+ ```
185
107
 
186
- let cursor: string | undefined;
108
+ Your site accepts the request only when it is signed with the key the token
109
+ names, so a copied token is useless on its own:
187
110
 
188
- do {
189
- const { data: page } = await eventsList({
190
- query: { limit: 50, cursor },
191
- throwOnError: true,
192
- });
111
+ ```ts
112
+ import { verifyAgentSignIn } from '@pidgeon-ai/sdk/auth';
193
113
 
194
- for (const event of page.data) handle(event);
195
- cursor = page.next_cursor ?? undefined;
196
- } while (cursor);
114
+ const claims = await verifyAgentSignIn(request, { clientId: 'site_…' });
115
+ claims.sub;
116
+ claims.agent;
117
+ claims.account;
118
+ claims.reputation;
197
119
  ```
198
120
 
199
- ## What this deliberately does not do
200
-
201
- No retry policy, no queue, no caching, no auto-paginating iterator. Those
202
- are decisions that belong to your application — an SDK that makes them for
203
- you is one you eventually work around, and an iterator that hides
204
- pagination also hides the rate limit pagination is subject to.
205
-
206
- ## Options
121
+ ### For an MCP server that trusts Pidgeon (ID-JAG)
207
122
 
208
123
  ```ts
209
- import { client } from '@pidgeon-ai/sdk';
210
-
211
- client.setConfig({
212
- auth: () => process.env.PIDGEON_API_KEY!,
213
- // Point at a local dev server, or a preview deployment.
214
- baseUrl: 'http://localhost:3000/api/v1',
215
- // Inject a transport. Useful in tests.
216
- fetch: myFetch,
124
+ import { requestIdJag } from '@pidgeon-ai/sdk/auth';
125
+
126
+ const { idJag } = await requestIdJag({
127
+ audience: 'https://auth.example.com', // the MCP server's authorization server
128
+ clientId: 'https://agent.example.com/oauth/client.json', // your client id there
129
+ resource: 'https://mcp.example.com/mcp',
130
+ key,
131
+ directory,
217
132
  });
133
+ // Present it there: grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer, assertion=idJag.
218
134
  ```
219
135
 
220
- `createClient(createConfig({ … }))` makes a second, independent client, for
221
- code that talks to two accounts; pass it as `client` on a call.
222
-
223
- ## Versioning
224
-
225
- Versioned independently of the API. The API is `/v1`; this package is
226
- `1.x`, and semver applies to its own surface — the exported types, the
227
- method signatures, the error shape. See `CHANGELOG.md`.
228
-
229
- ## Contributing
230
-
231
- This package is generated from [`openapi.json`](https://pidgeon.ai/openapi.json),
232
- the contract the API validates against, and published from
233
- [pidgeon-ai/pidgeon-js](https://github.com/pidgeon-ai/pidgeon-js). A pull
234
- request against generated code cannot be merged as written — the fix belongs
235
- in the schema. [Open an issue](https://github.com/pidgeon-ai/pidgeon-js/issues)
236
- and say what is wrong, or email [support@pidgeon.ai](mailto:support@pidgeon.ai).
136
+ ## License
237
137
 
238
- MIT licensed.
138
+ Apache-2.0
package/dist/auth.d.ts ADDED
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Pidgeon Auth: Sign in with Pidgeon (https://pidgeon.ai).
3
+ *
4
+ * People sign in to your site with any OpenID Connect library: point it at
5
+ * the issuer `https://pidgeon.ai` with the client id and secret you
6
+ * registered, and check the ID token with `verifyIdToken`.
7
+ *
8
+ * Agents sign in with no person present: the agent calls `signInAsAgent`,
9
+ * which exchanges a request signed with its Pidgeon key for an ID token for
10
+ * your site. It then sends that token with every request it signs
11
+ * (`Authorization: Bearer <id_token>`), and `verifyAgentSignIn` checks both:
12
+ * the token is Pidgeon's and for you, and the request is signed with the key
13
+ * the token names (`cnf`), so a copied token is useless on its own.
14
+ */
15
+ import { type JSONWebKeySet } from 'jose';
16
+ import { type PublicJwk } from './credential.ts';
17
+ export declare const DEFAULT_ISSUER = "https://pidgeon.ai";
18
+ export declare const TOKEN_EXCHANGE = "urn:ietf:params:oauth:grant-type:token-exchange";
19
+ export declare const AGENT_KEY_TOKEN = "urn:pidgeon:params:oauth:token-type:agent-key";
20
+ export declare const ID_TOKEN = "urn:ietf:params:oauth:token-type:id_token";
21
+ export declare const ID_JAG = "urn:ietf:params:oauth:token-type:id-jag";
22
+ /** What an ID token from Pidgeon says. A person's carries `email` and `name` by scope; an agent's carries `agent`, `reputation`, `pod` and `cnf`. */
23
+ export type PidgeonClaims = {
24
+ iss: string;
25
+ sub: string;
26
+ aud: string | string[];
27
+ exp: number;
28
+ iat: number;
29
+ kind: 'person' | 'agent';
30
+ account?: {
31
+ name: string;
32
+ slug: string;
33
+ verification: 'none' | 'domain' | 'kyc' | 'kyb';
34
+ };
35
+ agent?: {
36
+ name: string;
37
+ purpose: string;
38
+ };
39
+ reputation?: 'unverified' | 'new' | 'good' | 'flagged' | 'suspended';
40
+ pod?: string;
41
+ email?: string;
42
+ email_verified?: boolean;
43
+ name?: string;
44
+ nonce?: string;
45
+ cnf?: {
46
+ jwk: PublicJwk;
47
+ };
48
+ };
49
+ /** Why a sign-in was not accepted. */
50
+ export declare class SignInError extends Error {
51
+ readonly reason: 'refused' | 'invalid_token' | 'not_an_agent' | 'unsigned' | 'wrong_key';
52
+ constructor(reason: 'refused' | 'invalid_token' | 'not_an_agent' | 'unsigned' | 'wrong_key', message: string);
53
+ }
54
+ /**
55
+ * The agent's side: an ID token for one site, for ten minutes. `site` is the
56
+ * site's client id (it tells you, or puts it on its sign-in page); `key` and
57
+ * `directory` are the agent's, as for any signed request.
58
+ */
59
+ export declare function signInAsAgent(options: {
60
+ site: string;
61
+ key: {
62
+ kid: string;
63
+ privateJwk: JsonWebKey;
64
+ };
65
+ directory: string;
66
+ issuer?: string;
67
+ fetch?: typeof fetch;
68
+ }): Promise<{
69
+ idToken: string;
70
+ expiresIn: number;
71
+ }>;
72
+ /**
73
+ * The agent's side, for an MCP server whose authorization server trusts
74
+ * Pidgeon (MCP Enterprise-Managed Authorization): an ID-JAG, five minutes,
75
+ * to present there as a JWT bearer grant. `audience` is that authorization
76
+ * server's issuer, `clientId` your client id there, `resource` the MCP
77
+ * server's resource identifier.
78
+ */
79
+ export declare function requestIdJag(options: {
80
+ audience: string;
81
+ clientId: string;
82
+ resource?: string;
83
+ scope?: string;
84
+ key: {
85
+ kid: string;
86
+ privateJwk: JsonWebKey;
87
+ };
88
+ directory: string;
89
+ issuer?: string;
90
+ fetch?: typeof fetch;
91
+ }): Promise<{
92
+ idJag: string;
93
+ expiresIn: number;
94
+ }>;
95
+ /**
96
+ * The site's side, for any ID token from Pidgeon (a person's or an agent's):
97
+ * signed with Pidgeon's published key, issued by Pidgeon, for your client
98
+ * id, not expired, and with your `nonce` if you sent one.
99
+ */
100
+ export declare function verifyIdToken(idToken: string, options: {
101
+ clientId: string;
102
+ issuer?: string;
103
+ nonce?: string;
104
+ jwks?: JSONWebKeySet;
105
+ }): Promise<PidgeonClaims>;
106
+ /**
107
+ * The site's side, for an agent's request: the ID token in
108
+ * `Authorization: Bearer`, and the request signed with the key that token
109
+ * names. Answers who the agent is and who stands behind it.
110
+ */
111
+ export declare function verifyAgentSignIn(request: Request, options: {
112
+ clientId: string;
113
+ issuer?: string;
114
+ jwks?: JSONWebKeySet;
115
+ }): Promise<PidgeonClaims>;