@adonis-agora/authkit-poppy 0.3.1-rc.4 → 1.0.0-rc.6

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/CHANGELOG.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # @adonis-agora/authkit-poppy
2
2
 
3
+ ## 1.0.0-rc.6
4
+
5
+ ### Minor Changes
6
+
7
+ - [#545](https://github.com/DavideCarvalho/adonis-agora-authkit/pull/545) [`1c1e74d`](https://github.com/DavideCarvalho/adonis-agora-authkit/commit/1c1e74dff54da413fee2501c4080c437f26cb241) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Poppy 1.0 optional parts:
8
+
9
+ - The consent page marks scopes the account already granted to the agent (still lists every scope).
10
+ - `signIn.limitToResource`: a sign-in whose first request names `resource` covers only those resources.
11
+ - A delegated key that already signed for another User ID gets `invalid_session` (`sessionJwt.oneUserPerKey`, default on).
12
+ - `versions` / `preferredVersion`: serve several protocol versions (`supported_versions`, a document per version on the same host, `Deprecation`/`Sunset` for a version being retired). The principal gains `documentVersion`; verified results carry `headers`.
13
+ - A Session keeps the `Poppy-Version` it started with (`session_ended` otherwise).
14
+ - `tasks.feedback` without `endpoint`: a built-in feedback endpoint (`POST /poppy/feedback`) that verifies the Session, stores reports in `auth_poppy_feedback` and calls `onReport`.
15
+ - `operations`: the Operations extension (version 3) — `requirePoppyOperation()`, website operations with `Poppy-Operation` and `POST /poppy/operations`, declines, at-most-once retries, and the `@adonis-agora/poppy:operations` global slot.
16
+ - `browserControl`: lists Browser Control (version 1), with `poppyUserStep()` (also an Edge global) and `poppyUserStepAttrs()`.
17
+ - `links` / `disclosures`: list the Links and Disclosures extensions.
18
+
19
+ New lib-owned tables (`auth_poppy_grant_resources`, `auth_poppy_delegated_keys`, `auth_poppy_feedback`, `auth_poppy_operations`, `auth_poppy_operation_revisions`) and `sid`/`protocol_version` columns on `auth_poppy_sessions`, created additively at boot (or with `ensurePoppySchema()`).
20
+
21
+ ## 1.0.0-rc.5
22
+
23
+ ### Major Changes
24
+
25
+ - [#544](https://github.com/DavideCarvalho/adonis-agora-authkit/pull/544) [`ccc5b61`](https://github.com/DavideCarvalho/adonis-agora-authkit/commit/ccc5b61ffc27bf38ada188b557eed0764bd1153c) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Poppy 1.0. The package now implements the published Personal Agent Protocol 1.0 and serves version `1.0` only; its version follows the spec version.
26
+
27
+ Breaking changes for apps:
28
+
29
+ - `agent.protocols[]` entries need a `description` (what the agent there can help with). An endpoint announced through the `@adonis-agora/poppy:endpoints` slot is published only with a `description` next to `conversations`.
30
+ - `feedback` and `excludedTasks` moved into `tasks` (`tasks.feedback`, `tasks.excludedTasks`, plus `tasks.skillIndex` and `tasks.resolve`); the package serves `GET /poppy/tasks` and lists it as `tasks.endpoint`. Pass `tasks: { endpoint }` to serve your own.
31
+ - `extensions` takes a list with one entry per version: `{ name: [{ version: '1', … }] }`.
32
+ - `poppy:browser-sign-in` is added to the scopes when browser join and sign-in are on; joining a browser with an access token needs it. `web.unscoped` (default `true`) and `web.disabled` are new.
33
+ - Requests verified with the Session header need `Poppy-Version: 1.x` (`version_unsupported` otherwise). Ended Sessions and account changes answer `session_ended`. Sessions are keyed by `client_id` + `sid` + User ID. Failures carry a `body` to send as JSON.
34
+ - Delegations are `poppy-delegation+jwt` in the `poppy_dlg` header.
35
+ - `assertionMaxLifetime` can't be lower than 300.
36
+
37
+ New: Pushed Authorization Requests (`POST /poppy/oauth/par`, `par: { required }`), refresh tokens bound to the sign-in's DPoP key (`dpop.bindRefreshTokens`), `auth.disabled` when no sign-in type is on, `organization.domain` with its port, `scopes_supported` in the protected resource metadata, `resource=https://{domain}` for the default token, `protocolVersion` and `extensions` on the principal, and `verifyPoppyRequest(…, { extension })`. A new table, `auth_poppy_grant_keys`, is created with the others.
38
+
3
39
  ## 0.3.1-rc.4
4
40
 
5
41
  ### Patch Changes
package/README.md CHANGED
@@ -1,12 +1,11 @@
1
1
  # @adonis-agora/authkit-poppy
2
2
 
3
- The [Personal Agent Protocol ("Poppy")](https://personalagentprotocol.org/docs/spec) for
3
+ The [Personal Agent Protocol ("Poppy") 1.0](https://personalagentprotocol.org/docs/1.0/spec) for
4
4
  [AuthKit](https://davidecarvalho.github.io/agora/docs/authkit): discovery (`poppy.json`), signed
5
5
  `Poppy-Session` agent sessions, Direct / Device / Mediated sign-in, DPoP, MCP tokens and browser
6
6
  sessions — as an extension of `@adonis-agora/authkit-server`.
7
7
 
8
- > **Experimental.** Poppy is a draft spec. The package version follows the draft it implements:
9
- > `0.3.x` is Draft 0.3, and the next draft ships as a new minor. Pin it with `~0.3.0`.
8
+ > The package version follows the spec version it implements: `1.x` is Poppy `1.x`.
10
9
 
11
10
  ```sh
12
11
  node ace add @adonis-agora/authkit-poppy
package/build/index.d.ts CHANGED
@@ -1,21 +1,22 @@
1
1
  /**
2
- * @adonis-agora/authkit-poppy — the Personal Agent Protocol ("Poppy", Draft 0.3) for AuthKit, as a
2
+ * @adonis-agora/authkit-poppy — the Personal Agent Protocol ("Poppy", version 1.0) for AuthKit, as a
3
3
  * `personalAgents.extensions` entry of `@adonis-agora/authkit-server`.
4
4
  *
5
- * Experimental: this package stays on 0.x and follows the draft spec, so any minor may break.
5
+ * The package version follows the spec version: 1.x implements Poppy 1.x.
6
6
  */
7
7
  export { isBlockedAddress, SafeFetchError, safeFetchJson } from '@adonis-agora/authkit-server';
8
8
  export { configure, POPPY_CONFIG_SNIPPET } from './configure.js';
9
- export type { PoppyAgentProtocolEntry, PoppyApiEntry, PoppyBrowserLogin, PoppyClientsConfigInput, PoppyConfigInput, PoppyLimiter, PoppyMediatedConfigInput, PoppyMediatedField, PoppyMediatedResult, PoppyMediatedVerifyInput, PoppyPrincipalBase, PoppyReplayStore, PoppyScopeHint, PoppySignInType, ResolvedPoppyConfig, } from './src/config.js';
9
+ export type { PoppyAgentProtocolEntry, PoppyAlternative, PoppyApiEntry, PoppyApproval, PoppyBrowserLogin, PoppyClientsConfigInput, PoppyConfigInput, PoppyDecline, PoppyFeedbackConfigInput, PoppyFeedbackReport, PoppyLimiter, PoppyMediatedConfigInput, PoppyMediatedField, PoppyMediatedResult, PoppyMediatedVerifyInput, PoppyOperationsConfigInput, PoppyPrincipalBase, PoppyReplayStore, PoppyScopeHint, PoppySignInType, PoppyVersionInput, ResolvedPoppyConfig, } from './src/config.js';
10
10
  export { AGORA_DEV_SCOPE } from './src/config.js';
11
11
  export { accessTokenHash, type DpopNonceSource, type DpopResult, hmacNonceSource, type VerifyDpopInput, verifyDpopProof, } from './src/dpop.js';
12
12
  export { maskEmail, type PoppyEmailCodeSignInOptions, type PoppySignInCodeEmail, poppyEmailCodeSignIn, } from './src/email_code_sign_in.js';
13
13
  export { PoppyError, type PoppyErrorCode } from './src/errors.js';
14
14
  export { POPPY_GRANT_PREFIX, type PoppyExtensionOptions, poppy, } from './src/extension.js';
15
15
  export { POPPY_MESSAGES } from './src/messages.js';
16
+ export { approvalFromMcpMeta, MCP_APPROVAL_META, normalizeApproval, POPPY_APPROVAL_HEADER, POPPY_OPERATION_HEADER, type PoppyDeclinedWire, type PoppyOperationInput, type PoppyOperationRecord, type PoppyOperationResult, type PoppyOperationWire, parseApprovalHeader, poppyOperationToolResult, } from './src/operations.js';
16
17
  export { databaseReplayStore, memoryReplayStore, redisReplayStore, } from './src/replay.js';
17
- export { installPoppySlots, POPPY_AUTHENTICATE_SLOT, type PoppyAuthenticate, type PoppyAuthResult, type PoppyPrincipal, type PoppySlotRequest, poppyAuth, poppyOf, verifyPoppyRequest, writePoppyAuthError, } from './src/resource.js';
18
+ export { getPoppyOperation, installPoppySlots, markPoppyOperationPerformed, POPPY_AUTHENTICATE_SLOT, POPPY_OPERATIONS_SLOT, type PoppyAuthenticate, type PoppyAuthResult, type PoppyOperationsSlot, type PoppyPrincipal, type PoppySlotRequest, poppyAuth, poppyOf, releasePoppyOperation, requirePoppyOperation, verifyPoppyRequest, writePoppyAuthError, writePoppyOperationResult, } from './src/resource.js';
18
19
  export { POPPY_PROTOCOL_ID, poppyFor, poppyFromApp } from './src/runtime.js';
19
20
  export type { PoppyAuthError, PoppyGrantSummary, PoppyScopeDescription, PoppyService, PoppySessionState, PoppyTokenResponse, PoppyVerifyOptions, } from './src/service.js';
20
21
  export { ensurePoppySchema, POPPY_TABLES } from './src/tables.js';
21
- export { isPoppyBrowser, POPPY_WEB_SESSION_KEY, type PoppyWebSessionMarker, poppyWebSession, poppyWebSessionOf, } from './src/web_session.js';
22
+ export { isPoppyBrowser, POPPY_WEB_SESSION_KEY, type PoppyUserStep, type PoppyWebSessionMarker, poppyBrowserControlOf, poppyControllerOf, poppyUserStep, poppyUserStepAttrs, poppyWebSession, poppyWebSessionOf, } from './src/web_session.js';
package/build/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * @adonis-agora/authkit-poppy — the Personal Agent Protocol ("Poppy", Draft 0.3) for AuthKit, as a
2
+ * @adonis-agora/authkit-poppy — the Personal Agent Protocol ("Poppy", version 1.0) for AuthKit, as a
3
3
  * `personalAgents.extensions` entry of `@adonis-agora/authkit-server`.
4
4
  *
5
- * Experimental: this package stays on 0.x and follows the draft spec, so any minor may break.
5
+ * The package version follows the spec version: 1.x implements Poppy 1.x.
6
6
  */
7
7
  // A busca à prova de SSRF mora no `@adonis-agora/authkit-server` (Client ID Metadata Documents).
8
8
  export { isBlockedAddress, SafeFetchError, safeFetchJson } from '@adonis-agora/authkit-server';
@@ -13,8 +13,9 @@ export { maskEmail, poppyEmailCodeSignIn, } from './src/email_code_sign_in.js';
13
13
  export { PoppyError } from './src/errors.js';
14
14
  export { POPPY_GRANT_PREFIX, poppy, } from './src/extension.js';
15
15
  export { POPPY_MESSAGES } from './src/messages.js';
16
+ export { approvalFromMcpMeta, MCP_APPROVAL_META, normalizeApproval, POPPY_APPROVAL_HEADER, POPPY_OPERATION_HEADER, parseApprovalHeader, poppyOperationToolResult, } from './src/operations.js';
16
17
  export { databaseReplayStore, memoryReplayStore, redisReplayStore, } from './src/replay.js';
17
- export { installPoppySlots, POPPY_AUTHENTICATE_SLOT, poppyAuth, poppyOf, verifyPoppyRequest, writePoppyAuthError, } from './src/resource.js';
18
+ export { getPoppyOperation, installPoppySlots, markPoppyOperationPerformed, POPPY_AUTHENTICATE_SLOT, POPPY_OPERATIONS_SLOT, poppyAuth, poppyOf, releasePoppyOperation, requirePoppyOperation, verifyPoppyRequest, writePoppyAuthError, writePoppyOperationResult, } from './src/resource.js';
18
19
  export { POPPY_PROTOCOL_ID, poppyFor, poppyFromApp } from './src/runtime.js';
19
20
  export { ensurePoppySchema, POPPY_TABLES } from './src/tables.js';
20
- export { isPoppyBrowser, POPPY_WEB_SESSION_KEY, poppyWebSession, poppyWebSessionOf, } from './src/web_session.js';
21
+ export { isPoppyBrowser, POPPY_WEB_SESSION_KEY, poppyBrowserControlOf, poppyControllerOf, poppyUserStep, poppyUserStepAttrs, poppyWebSession, poppyWebSessionOf, } from './src/web_session.js';
@@ -14,7 +14,6 @@ export interface PoppyClient {
14
14
  logoUri: string | null;
15
15
  jwksUri: string;
16
16
  redirectUris: string[];
17
- extensions: Record<string, unknown>;
18
17
  /** Chaves públicas do `jwks_uri`. */
19
18
  keys: JWTVerifyGetKey;
20
19
  }
@@ -76,16 +76,12 @@ export function validateClientMetadata(fetchedFrom, doc, options = {}) {
76
76
  if (d.jwks !== undefined)
77
77
  throw bad('keys are published at jwks_uri only');
78
78
  const name = typeof d.client_name === 'string' && d.client_name.trim() ? d.client_name : host;
79
- const extensions = d.extensions && typeof d.extensions === 'object' && !Array.isArray(d.extensions)
80
- ? d.extensions
81
- : {};
82
79
  return {
83
80
  clientId: fetchedFrom,
84
81
  name: name.slice(0, 200),
85
82
  logoUri: isHttpsUrl(d.logo_uri, allowHttp) ? d.logo_uri : null,
86
83
  jwksUri: d.jwks_uri,
87
84
  redirectUris: redirects,
88
- extensions,
89
85
  };
90
86
  }
91
87
  /** Só chaves públicas (§4.1) e pelo menos uma. */
@@ -118,8 +114,8 @@ export class PoppyClientRegistry {
118
114
  this.#cfg = cfg;
119
115
  const fetchJson = options.fetchJson ??
120
116
  (cfg.allowInsecureClientIds
121
- ? (url) => insecureDevFetchJson(url, { userAgent: 'authkit-poppy/0.3' })
122
- : (url) => safeFetchJson(url, { userAgent: 'authkit-poppy/0.3' }));
117
+ ? (url) => insecureDevFetchJson(url, { userAgent: 'authkit-poppy/1.0' })
118
+ : (url) => safeFetchJson(url, { userAgent: 'authkit-poppy/1.0' }));
123
119
  const common = { fetchJson, now: options.now, ttl: { min: 60, max: 86_400, fallback: 3600 } };
124
120
  this.#clients = new MetadataDocumentCache({
125
121
  ...common,
@@ -1,8 +1,6 @@
1
1
  /**
2
- * @experimental Draft 0.3 da spec (https://personalagentprotocol.org/docs/spec) — pode mudar de forma
3
- * incompatível fora de majors enquanto a spec for draft.
4
- *
5
- * Personal Agent Protocol ("Poppy", Draft 0.3 — https://personalagentprotocol.org) — config.
2
+ * Personal Agent Protocol ("Poppy", versão 1.0 — https://personalagentprotocol.org/docs/1.0/spec) —
3
+ * config.
6
4
  *
7
5
  * Poppy é o segundo protocolo de personal agents ao lado do PACT. O agente se identifica pelo
8
6
  * `client_id` (uma URL HTTPS com o documento de metadata dele) e declara a Session em cada request
@@ -71,9 +69,6 @@ export type PoppyMediatedResult = {
71
69
  } | {
72
70
  status: 'denied';
73
71
  };
74
- /**
75
- * @experimental Poppy (Personal Agent Protocol) Draft 0.3 — pode mudar de forma incompatível enquanto a spec for draft.
76
- */
77
72
  export interface PoppyMediatedConfigInput {
78
73
  /** Campos pedidos (extensão Mediated Sign-In). Ex.: `[{ name: 'email', … }, { name: 'password', secret: true, … }]`. */
79
74
  fields: PoppyMediatedField[];
@@ -102,6 +97,11 @@ export interface PoppyAgentProtocolEntry {
102
97
  type: string;
103
98
  /** URL HTTPS do endpoint de conversas. */
104
99
  endpoint: string;
100
+ /**
101
+ * O que o agente deste endpoint ajuda a fazer (§3.1, §8.1) — o personal agent usa para decidir se
102
+ * uma conversa serve à tarefa. Pode dizer que ajuda com qualquer coisa. Obrigatório.
103
+ */
104
+ description: string;
105
105
  /** A interface precisa da conta desde o início (§3.2). Default: `session`. */
106
106
  access?: 'session' | 'signed_in';
107
107
  /**
@@ -123,6 +123,86 @@ export interface PoppyApiEntry {
123
123
  /** Como em `agent.protocols`. MCP sempre exige o próprio `url` (§7). */
124
124
  resource?: string;
125
125
  }
126
+ /** Uma tarefa que a empresa escolheu não oferecer pelo protocolo (§9.1). */
127
+ export interface PoppyExcludedTask {
128
+ /** A tarefa, numa frase curta: "Send a wire transfer". */
129
+ task: string;
130
+ /** Outro jeito de fazer a tarefa (§9.2). */
131
+ alternative?: PoppyAlternative;
132
+ }
133
+ /** Outro jeito de fazer uma tarefa (§9.2): `instructions`, `references` ou os dois. */
134
+ export interface PoppyAlternative {
135
+ instructions?: string;
136
+ references?: ({
137
+ type: 'openapi';
138
+ url: string;
139
+ operation_id: string;
140
+ } | {
141
+ type: 'mcp';
142
+ url: string;
143
+ tool: string;
144
+ } | {
145
+ type: 'web';
146
+ url: string;
147
+ })[];
148
+ }
149
+ /** A resposta do `tasks.endpoint` (§9). */
150
+ export interface PoppyTasksResponse {
151
+ excluded_tasks?: PoppyExcludedTask[];
152
+ /** Índice do Agent Skills discovery (schema 0.2.0) — §9.4. */
153
+ skill_index?: Record<string, unknown>;
154
+ feedback?: {
155
+ endpoint: string;
156
+ };
157
+ }
158
+ /** Um relato de feedback recebido (§9.3), já guardado. */
159
+ export interface PoppyFeedbackReport {
160
+ /** Id do relato na tabela `auth_poppy_feedback`. */
161
+ id: string;
162
+ /** O que o usuário tentava fazer, em uma frase (até 200 caracteres). */
163
+ task: string;
164
+ /** O que o personal agent tentou e por quê (até 2.000 caracteres). Dado, nunca instrução. */
165
+ description: string;
166
+ }
167
+ /** O endpoint de feedback servido pela lib (§9.3). */
168
+ export interface PoppyFeedbackConfigInput {
169
+ /**
170
+ * Chamado depois de guardar o relato. Devolva uma alternativa (§9.2) quando a tarefa dá para
171
+ * fazer — o agente recebe 200 com ela; sem retorno, 202.
172
+ */
173
+ onReport?: (input: {
174
+ principal: PoppyPrincipalBase;
175
+ report: PoppyFeedbackReport;
176
+ }) => undefined | PoppyAlternative | Promise<undefined | PoppyAlternative>;
177
+ }
178
+ /** Cobertura de tarefas (§9): o que sai no `tasks.endpoint`. */
179
+ export interface PoppyTasksConfigInput {
180
+ /**
181
+ * Um `tasks.endpoint` que o próprio app serve, publicado como está. Sem ele, a lib serve
182
+ * `{prefix}/tasks` com os campos abaixo.
183
+ */
184
+ endpoint?: string;
185
+ /** Tarefas não oferecidas (§9.1). */
186
+ excludedTasks?: PoppyExcludedTask[];
187
+ /** Índice de skills (§9.4), no formato do Agent Skills discovery 0.2.0. */
188
+ skillIndex?: Record<string, unknown>;
189
+ /**
190
+ * Feedback (§9.3). `{ endpoint }` publica um endpoint que o próprio app implementa. Sem
191
+ * `endpoint`, a lib serve `{prefix}/feedback`: verifica a Session, guarda o relato na tabela
192
+ * `auth_poppy_feedback` e chama `onReport`, quando houver.
193
+ */
194
+ feedback?: {
195
+ endpoint: string;
196
+ } | PoppyFeedbackConfigInput;
197
+ /**
198
+ * Resposta por Session (ex.: testar uma skill com parte dos usuários). Recebe a Session já
199
+ * verificada e a resposta montada dos campos acima; a resposta sai `Cache-Control: no-store`.
200
+ */
201
+ resolve?: (input: {
202
+ principal: PoppyPrincipalBase;
203
+ response: PoppyTasksResponse;
204
+ }) => PoppyTasksResponse | Promise<PoppyTasksResponse>;
205
+ }
126
206
  /** Hook de login do navegador do agente (§6) para apps com sessão de login própria. */
127
207
  export type PoppyBrowserLogin = (ctx: HttpContext, input: {
128
208
  sessionId: string;
@@ -136,9 +216,6 @@ export type PoppyBrowserLogin = (ctx: HttpContext, input: {
136
216
  * Onde o protocolo guarda os `jti` já vistos (client assertions, Session JWTs,
137
217
  * provas DPoP) até expirarem. `claim` devolve `true` na
138
218
  * primeira vez que vê a chave e `false` num replay.
139
- *
140
- * @experimental Poppy (Personal Agent Protocol) Draft 0.3 — acompanha a spec em desenvolvimento e PODE MUDAR
141
- * de forma incompatível fora de majors enquanto ela for draft.
142
219
  */
143
220
  export interface PoppyReplayStore {
144
221
  claim(key: string, expiresAt: Date): Promise<boolean>;
@@ -160,9 +237,6 @@ export interface PoppyClientsConfigInput {
160
237
  /** `client_id`s bloqueados (revogados por mau uso). */
161
238
  blocked?: string[] | ((clientId: string) => boolean | Promise<boolean>);
162
239
  }
163
- /**
164
- * @experimental Poppy (Personal Agent Protocol) Draft 0.3 — pode mudar de forma incompatível enquanto a spec for draft.
165
- */
166
240
  export interface PoppyConfigInput {
167
241
  /** Nome exibido e domínio (`organization` do poppy.json). */
168
242
  organization: {
@@ -194,6 +268,12 @@ export interface PoppyConfigInput {
194
268
  };
195
269
  /** Desligado por default: o app precisa conferir as credenciais. */
196
270
  mediated?: PoppyMediatedConfigInput;
271
+ /**
272
+ * Um sign-in que nomeia `resource` vale só para esses resources (§4.5, RFC 8707 §2.2): o
273
+ * default token só sai se ele nomeou `https://{organization.domain}`. Sem `resource`, o sign-in
274
+ * continua cobrindo tudo. Default: false (o `resource` do início é ignorado).
275
+ */
276
+ limitToResource?: boolean;
197
277
  };
198
278
  /** Company Agent (§8) — o endpoint de conversas é implementado pelo `@adonis-agora/agent`. */
199
279
  agent?: {
@@ -201,28 +281,40 @@ export interface PoppyConfigInput {
201
281
  };
202
282
  /** APIs do app que aceitam o header da Session (§7). */
203
283
  apis?: PoppyApiEntry[];
204
- /** Endpoint de feedback que o app implementa (§9.3). */
205
- feedback?: {
206
- endpoint: string;
207
- };
208
- /** Documento público das tarefas que a empresa não oferece (§9.1). */
209
- excludedTasks?: {
210
- url: string;
211
- };
284
+ /** Cobertura de tarefas (§9): tarefas excluídas, skills e feedback, no `tasks.endpoint`. */
285
+ tasks?: PoppyTasksConfigInput;
212
286
  /**
213
- * Site (§6). Default: liga o `browser_session_endpoint`. `false` desliga. `login`
287
+ * Site (§6). Default: liga o `browser_session_endpoint`. `false` não publica `web`. `login`
214
288
  * substitui o login default (sessão de conta do authkit + `adonisAuth.guard`). `redirectTo` é
215
289
  * a página do site para onde o navegador vai depois de entrar (path). Default: `/`.
290
+ *
291
+ * - `disabled: true` pede aos personal agents que não naveguem o site num navegador
292
+ * (`web.disabled`); desliga o `browser_session_endpoint`. Liste `agent` ou `apis`.
293
+ * - `unscoped` (`web.unscoped`): o site não aplica os scopes do cookie, então
294
+ * `poppy:browser-sign-in` dá todo o acesso da conta no site. Default: `true` — o login default
295
+ * entra na conta inteira. Passe `false` só com um `login` que aplica os scopes.
216
296
  */
217
297
  web?: false | {
218
298
  browserSession?: boolean;
299
+ disabled?: boolean;
300
+ unscoped?: boolean;
219
301
  login?: PoppyBrowserLogin;
220
302
  redirectTo?: string;
221
303
  };
222
- /** Extensões suportadas (§3.3), publicadas como estão. */
223
- extensions?: Record<string, {
304
+ /**
305
+ * Extensões suportadas (§3.3), publicadas como estão: uma entrada por versão.
306
+ * Ex.: `{ 'example.com/gift-wrap': [{ version: '1', endpoint: 'https://…' }] }`.
307
+ */
308
+ extensions?: Record<string, ({
224
309
  version: string;
225
- } & Record<string, unknown>>;
310
+ } & Record<string, unknown>)[]>;
311
+ /**
312
+ * Pushed Authorization Requests (RFC 9126, §4.2) no Direct Sign-In. Default: oferecido.
313
+ * `{ required: true }` exige (`require_pushed_authorization_requests`). `false` não oferece.
314
+ */
315
+ par?: boolean | {
316
+ required?: boolean;
317
+ };
226
318
  /** Registro/allowlist/blocklist de agentes. */
227
319
  clients?: PoppyClientsConfigInput;
228
320
  /**
@@ -245,12 +337,20 @@ export interface PoppyConfigInput {
245
337
  deviceCodeTtl?: number;
246
338
  /** Intervalo mínimo de polling do device flow, em segundos. Default: 5. */
247
339
  pollInterval?: number;
248
- /** Vida máxima das client assertions (`exp - iat`), em segundos. Default: 300. */
340
+ /**
341
+ * Vida máxima das client assertions (`exp - iat`), em segundos. Default: 300. Nunca menos que 300:
342
+ * a spec proíbe recusar uma assertion de até 5 minutos (§4.1).
343
+ */
249
344
  assertionMaxLifetime?: number;
250
345
  /** Session JWT (§5.3). */
251
346
  sessionJwt?: {
252
347
  /** Janela de aceitação do `iat`, em segundos. Default: 60. */
253
348
  maxAge?: number;
349
+ /**
350
+ * Recusa (`invalid_session`) uma chave delegada que já assinou por outro User ID enquanto a
351
+ * delegação dela vale (§5.2): limita uma chave vazada a um usuário. Default: true.
352
+ */
353
+ oneUserPerKey?: boolean;
254
354
  };
255
355
  /** DPoP (§4.5): prender os access tokens é escolha da empresa. */
256
356
  dpop?: {
@@ -262,6 +362,11 @@ export interface PoppyConfigInput {
262
362
  maxAge?: number;
263
363
  /** Algoritmos aceitos na prova. Default: `['ES256']`. */
264
364
  algorithms?: string[];
365
+ /**
366
+ * Prende o refresh token à chave DPoP do sign-in (§4.4): um refresh sem prova ou com outra
367
+ * chave leva `invalid_grant`. Só vale para sign-ins feitos com prova. Default: true.
368
+ */
369
+ bindRefreshTokens?: boolean;
265
370
  };
266
371
  /**
267
372
  * Onde guardar os `jti` vistos. Default: `'database'` (tabela lib-owned
@@ -286,6 +391,27 @@ export interface PoppyConfigInput {
286
391
  * global devolvem `actor`.
287
392
  */
288
393
  toActor?: (principal: PoppyPrincipalBase) => unknown | Promise<unknown>;
394
+ /**
395
+ * Versões do protocolo servidas (§3.4), `'major.minor' → opções`. Default: só `'1.0'`, a que este
396
+ * pacote implementa — ela sempre entra. Cada outra versão vira um documento no mesmo host
397
+ * (`{prefix}/versions/{versão}.json`), listado em `supported_versions`; `document` ajusta o que
398
+ * ela publica. `deprecated` manda `Deprecation` (RFC 9745) e `Sunset` (RFC 8594) nas respostas a
399
+ * requests nela.
400
+ */
401
+ versions?: Record<string, PoppyVersionInput>;
402
+ /** A versão do `/.well-known/poppy.json` (§3.4). Default: a mais nova servida. */
403
+ preferredVersion?: string;
404
+ /** Extensão Operations, versão 3. Desligada por default. */
405
+ operations?: boolean | PoppyOperationsConfigInput;
406
+ /**
407
+ * Extensão Browser Control, versão 1: o site marca passos do usuário com
408
+ * `data-poppy-user-step`. Exige o `browser_session_endpoint`. Default: false.
409
+ */
410
+ browserControl?: boolean;
411
+ /** Extensão Links, versão 1: mensagens da empresa com links. Default: false. */
412
+ links?: boolean;
413
+ /** Extensão Disclosures, versão 1: avisos destacados nas mensagens. Default: false. */
414
+ disclosures?: boolean;
289
415
  /**
290
416
  * Offer the `agora:dev` scope: a personal agent the person grants it to may use the app's Agora
291
417
  * developer tools over MCP (`@adonis-agora/agent`, `/mcp/agora`). It is never ticked for the
@@ -294,11 +420,68 @@ export interface PoppyConfigInput {
294
420
  */
295
421
  devTools?: boolean;
296
422
  }
423
+ /** Uma versão do protocolo servida (§3.4). */
424
+ export interface PoppyVersionInput {
425
+ /**
426
+ * Ajusta o documento desta versão: recebe o da 1.0 (com `protocol_version` já trocado, sem
427
+ * `supported_versions`) e devolve o desta versão. Não troque `organization.domain` nem o issuer.
428
+ */
429
+ document?: (doc: Record<string, unknown>) => Record<string, unknown>;
430
+ /**
431
+ * A versão vai deixar de ser servida: as respostas a requests nela levam `Deprecation` (desde
432
+ * `at`), `Sunset` (quando houver) e um `Link` `rel="deprecation"` (quando houver).
433
+ */
434
+ deprecated?: {
435
+ at: Date;
436
+ sunset?: Date;
437
+ link?: string;
438
+ };
439
+ }
440
+ /** Uma aprovação recebida (Operations 3, §6). */
441
+ export interface PoppyApproval {
442
+ operation_id: string;
443
+ revision: string;
444
+ /** `user` (o usuário aprovou) ou `agent` (o agente aprovou por instrução do usuário). */
445
+ approver: 'user' | 'agent';
446
+ /** Unix seconds. */
447
+ approved_at?: number;
448
+ /** Só com `user`: `tap`, `typed`, `voice`… */
449
+ input_type?: string;
450
+ /** Id do registro do personal agent para esta aprovação. */
451
+ reference?: string;
452
+ }
453
+ /** A recusa de uma aprovação (Operations 3, §6), devolvida pelo `decide`. */
454
+ export interface PoppyDecline {
455
+ /** Por quê, curto, para o usuário. Nada que a Session não pudesse ver. */
456
+ reason?: string;
457
+ /** Outro jeito de fazer (§9.2). */
458
+ alternative?: PoppyAlternative;
459
+ }
460
+ export interface PoppyOperationsConfigInput {
461
+ /**
462
+ * Operações no site (§4 "Websites"): publica `endpoint` (`{prefix}/operations`), onde o agente
463
+ * busca e aprova as operações que o site devolveu. Exige o `browser_session_endpoint`. Default:
464
+ * ligado quando o site tem browser join.
465
+ */
466
+ website?: boolean;
467
+ /**
468
+ * Chamado com uma aprovação que passou nas checagens, antes de executar: devolva um
469
+ * {@link PoppyDecline} para recusá-la (`approval_declined`), ou nada para seguir.
470
+ */
471
+ decide?: (input: {
472
+ principal: PoppyPrincipalBase;
473
+ operation: {
474
+ operationId: string;
475
+ revision: string;
476
+ terms: Record<string, unknown>;
477
+ };
478
+ approval: PoppyApproval;
479
+ }) => undefined | PoppyDecline | Promise<undefined | PoppyDecline>;
480
+ /** Validade default de uma revisão, em segundos. Default: 900 (15 min, o mínimo dos guias). */
481
+ expiresIn?: number;
482
+ }
297
483
  /**
298
484
  * O que uma request verificada autoriza — sem o `actor`.
299
- *
300
- * @experimental Poppy (Personal Agent Protocol) Draft 0.3 — acompanha a spec em desenvolvimento e PODE MUDAR
301
- * de forma incompatível fora de majors enquanto ela for draft.
302
485
  */
303
486
  export interface PoppyPrincipalBase {
304
487
  /** User ID que o personal agent deu ao usuário NESTE app (opaco, estável). */
@@ -311,8 +494,20 @@ export interface PoppyPrincipalBase {
311
494
  clientId: string;
312
495
  /** Scopes do access token. Vazio deslogado. */
313
496
  scopes: string[];
314
- /** A Session, única por `client_id` + `sid`. */
497
+ /** A Session, única por `client_id` + `sid` + User ID (§5.3). */
315
498
  sessionId: string;
499
+ /** A versão do protocolo que a request declarou em `Poppy-Version` (`'1.0'`, `'1.1'`…). */
500
+ protocolVersion: string;
501
+ /**
502
+ * A versão servida (§3.4) com que a request é atendida: a de `versions` compatível com
503
+ * `protocolVersion` — a igual, senão a mais nova que não passa dela.
504
+ */
505
+ documentVersion: string;
506
+ /**
507
+ * As extensões que a request declarou em `Poppy-Extensions` e que este app lista, `nome → versão`
508
+ * (§3.3, §3.4).
509
+ */
510
+ extensions: Record<string, string>;
316
511
  signedIn: boolean;
317
512
  /** `resource` para o qual o token foi emitido (RFC 8707), ou `null`. */
318
513
  resource: string | null;
@@ -345,25 +540,47 @@ export interface ResolvedPoppyConfig {
345
540
  scopes: string[];
346
541
  } | null;
347
542
  mediated: ResolvedPoppyMediatedConfig | null;
543
+ limitToResource: boolean;
348
544
  };
349
545
  agent: {
350
546
  protocols: PoppyAgentProtocolEntry[];
351
547
  } | null;
352
548
  apis: PoppyApiEntry[];
353
- feedback: {
354
- endpoint: string;
355
- } | null;
356
- excludedTasks: {
357
- url: string;
549
+ /** `null` = sem `tasks` no poppy.json. */
550
+ tasks: {
551
+ /** Endpoint do próprio app; `null` = a lib serve `{prefix}/tasks`. */
552
+ endpoint: string | null;
553
+ response: PoppyTasksResponse;
554
+ resolve?: PoppyTasksConfigInput['resolve'];
555
+ /** O endpoint de feedback da lib (`{prefix}/feedback`); `null` = nenhum ou do app. */
556
+ feedback: PoppyFeedbackConfigInput | null;
358
557
  } | null;
359
558
  web: {
360
559
  browserSession: boolean;
560
+ disabled: boolean;
561
+ unscoped: boolean;
361
562
  login?: PoppyBrowserLogin;
362
563
  redirectTo: string;
363
564
  } | null;
364
- extensions: Record<string, {
565
+ extensions: Record<string, ({
365
566
  version: string;
366
- } & Record<string, unknown>>;
567
+ } & Record<string, unknown>)[]>;
568
+ /** Versões servidas (§3.4), com `'1.0'` sempre. */
569
+ versions: Record<string, PoppyVersionInput>;
570
+ preferredVersion: string;
571
+ /** Operations 3; `null` = desligada. */
572
+ operations: {
573
+ website: boolean;
574
+ decide?: PoppyOperationsConfigInput['decide'];
575
+ expiresIn: number;
576
+ } | null;
577
+ browserControl: boolean;
578
+ links: boolean;
579
+ disclosures: boolean;
580
+ /** `null` = sem PAR. */
581
+ par: {
582
+ required: boolean;
583
+ } | null;
367
584
  clients: {
368
585
  requireRegistration: boolean;
369
586
  isRegistered: (clientId: string) => Promise<boolean>;
@@ -383,12 +600,14 @@ export interface ResolvedPoppyConfig {
383
600
  assertionMaxLifetime: number;
384
601
  sessionJwt: {
385
602
  maxAge: number;
603
+ oneUserPerKey: boolean;
386
604
  };
387
605
  dpop: {
388
606
  required: boolean;
389
607
  requireNonce: boolean;
390
608
  maxAge: number;
391
609
  algorithms: string[];
610
+ bindRefreshTokens: boolean;
392
611
  };
393
612
  replay: 'database' | 'memory' | {
394
613
  redis: string;
@@ -403,6 +622,26 @@ export interface ResolvedPoppyConfig {
403
622
  }
404
623
  export declare function normalizePoppyPrefix(prefix: string | undefined): string;
405
624
  export declare function resolvePoppyConfig(input: PoppyConfigInput | undefined, fallbackScopes: Record<string, string> | undefined): ResolvedPoppyConfig | undefined;
625
+ /** O único scope que o protocolo define: o navegador do agente entra logado no site (§6). */
626
+ export declare const BROWSER_SIGN_IN_SCOPE = "poppy:browser-sign-in";
627
+ /** A descrição quando o site aplica os scopes do cookie. */
628
+ export declare const BROWSER_SIGN_IN_SCOPED_DESCRIPTION = "Use the website signed in, with the other access you approve";
629
+ /** A descrição quando o site dá a conta inteira (`web.unscoped`, §6). */
630
+ export declare const BROWSER_SIGN_IN_UNSCOPED_DESCRIPTION = "Browse the website, and see and do anything your account can do there";
631
+ /** O nome da extensão Mediated Sign-In em `extensions`. */
632
+ export declare const MEDIATED_SIGN_IN_EXTENSION = "mediated-sign-in";
633
+ /** Extensão Operations (versão 3). */
634
+ export declare const OPERATIONS_EXTENSION = "operations";
635
+ export declare const OPERATIONS_VERSION = "3";
636
+ /** Extensão Browser Control (versão 1). */
637
+ export declare const BROWSER_CONTROL_EXTENSION = "browser-control";
638
+ /** Extensões Links e Disclosures (versão 1). */
639
+ export declare const LINKS_EXTENSION = "links";
640
+ export declare const DISCLOSURES_EXTENSION = "disclosures";
641
+ /** A versão do protocolo que este pacote implementa (§3.4). */
642
+ export declare const POPPY_BASE_VERSION = "1.0";
643
+ /** Ordena `major.minor` numericamente. */
644
+ export declare function compareVersions(a: string, b: string): number;
406
645
  /** The scope that lets a personal agent use the app's Agora developer tools over MCP. */
407
646
  export declare const AGORA_DEV_SCOPE = "agora:dev";
408
647
  /** The catalog description of {@link AGORA_DEV_SCOPE} (the consent screen shows a translated text). */