@adonis-agora/authkit-poppy 1.0.0-rc.5 → 1.0.0-rc.7
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 +28 -0
- package/build/index.d.ts +4 -3
- package/build/index.js +3 -2
- package/build/src/config.d.ts +151 -2
- package/build/src/config.js +104 -5
- package/build/src/controllers/poppy_consent_controller.js +2 -2
- package/build/src/controllers/poppy_controller.d.ts +15 -0
- package/build/src/controllers/poppy_controller.js +76 -0
- package/build/src/extension.js +51 -11
- package/build/src/operations.d.ts +190 -0
- package/build/src/operations.js +607 -0
- package/build/src/replay.d.ts +12 -2
- package/build/src/replay.js +25 -8
- package/build/src/resource.d.ts +59 -21
- package/build/src/resource.js +145 -4
- package/build/src/service.d.ts +86 -6
- package/build/src/service.js +411 -38
- package/build/src/session_jwt.d.ts +4 -0
- package/build/src/session_jwt.js +4 -1
- package/build/src/store.d.ts +115 -0
- package/build/src/store.js +297 -0
- package/build/src/structured_fields.d.ts +12 -0
- package/build/src/structured_fields.js +133 -0
- package/build/src/tables.js +155 -2
- package/build/src/web_session.d.ts +30 -0
- package/build/src/web_session.js +30 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @adonis-agora/authkit-poppy
|
|
2
2
|
|
|
3
|
+
## 1.0.0-rc.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`0c4c958`](https://github.com/DavideCarvalho/adonis-agora-authkit/commit/0c4c95895572969cd6dc915a3a2b862a75c834fb) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Poppy's default in-memory rate limiter now has a hard cap (100 000 windows, oldest evicted first) and drops expired windows as it goes, so a stream of new identifiers on Mediated Sign-In can no longer grow it without bound.
|
|
8
|
+
|
|
9
|
+
The unauthenticated OAuth endpoints agents call server-to-server now sit behind a per-IP throttle by default (new `agentToken` bucket, 120/min, plain 429; off with the existing `rateLimit: { enabled: false }`): Poppy's `{prefix}/oauth/token`, `oauth/device`, `oauth/par` and `oauth/revoke`, and authkit-server's personal-agents `{personalAgents.prefix}/oauth/token` and `oauth/device_authorization`. Personal-agent extensions get the bucket as `kit.throttle.token(route)`.
|
|
10
|
+
|
|
11
|
+
The OIDC provider's own machine endpoints get the same treatment: inside the `${mountPath}/*` catch-all, only the POSTs to token, dynamic registration, device authorization, PAR, revocation, introspection and CIBA (paths read from the provider via `pathFor`, so custom `routes` and the issuer mount apply; disabled features are skipped) go through a new per-IP `oidcToken` bucket (120/min, plain 429). Authorize, userinfo, JWKS, discovery, end-session and the device code screen are never throttled. Poppy's `POST {prefix}/browser-session` now uses the login bucket, like its page. All of it is off with `rateLimit: { enabled: false }`.
|
|
12
|
+
|
|
13
|
+
## 1.0.0-rc.6
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- [#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:
|
|
18
|
+
|
|
19
|
+
- The consent page marks scopes the account already granted to the agent (still lists every scope).
|
|
20
|
+
- `signIn.limitToResource`: a sign-in whose first request names `resource` covers only those resources.
|
|
21
|
+
- A delegated key that already signed for another User ID gets `invalid_session` (`sessionJwt.oneUserPerKey`, default on).
|
|
22
|
+
- `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`.
|
|
23
|
+
- A Session keeps the `Poppy-Version` it started with (`session_ended` otherwise).
|
|
24
|
+
- `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`.
|
|
25
|
+
- `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.
|
|
26
|
+
- `browserControl`: lists Browser Control (version 1), with `poppyUserStep()` (also an Edge global) and `poppyUserStepAttrs()`.
|
|
27
|
+
- `links` / `disclosures`: list the Links and Disclosures extensions.
|
|
28
|
+
|
|
29
|
+
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()`).
|
|
30
|
+
|
|
3
31
|
## 1.0.0-rc.5
|
|
4
32
|
|
|
5
33
|
### Major Changes
|
package/build/index.d.ts
CHANGED
|
@@ -6,16 +6,17 @@
|
|
|
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
|
@@ -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';
|
package/build/src/config.d.ts
CHANGED
|
@@ -155,6 +155,26 @@ export interface PoppyTasksResponse {
|
|
|
155
155
|
endpoint: string;
|
|
156
156
|
};
|
|
157
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
|
+
}
|
|
158
178
|
/** Cobertura de tarefas (§9): o que sai no `tasks.endpoint`. */
|
|
159
179
|
export interface PoppyTasksConfigInput {
|
|
160
180
|
/**
|
|
@@ -166,10 +186,14 @@ export interface PoppyTasksConfigInput {
|
|
|
166
186
|
excludedTasks?: PoppyExcludedTask[];
|
|
167
187
|
/** Índice de skills (§9.4), no formato do Agent Skills discovery 0.2.0. */
|
|
168
188
|
skillIndex?: Record<string, unknown>;
|
|
169
|
-
/**
|
|
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
|
+
*/
|
|
170
194
|
feedback?: {
|
|
171
195
|
endpoint: string;
|
|
172
|
-
};
|
|
196
|
+
} | PoppyFeedbackConfigInput;
|
|
173
197
|
/**
|
|
174
198
|
* Resposta por Session (ex.: testar uma skill com parte dos usuários). Recebe a Session já
|
|
175
199
|
* verificada e a resposta montada dos campos acima; a resposta sai `Cache-Control: no-store`.
|
|
@@ -244,6 +268,12 @@ export interface PoppyConfigInput {
|
|
|
244
268
|
};
|
|
245
269
|
/** Desligado por default: o app precisa conferir as credenciais. */
|
|
246
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;
|
|
247
277
|
};
|
|
248
278
|
/** Company Agent (§8) — o endpoint de conversas é implementado pelo `@adonis-agora/agent`. */
|
|
249
279
|
agent?: {
|
|
@@ -316,6 +346,11 @@ export interface PoppyConfigInput {
|
|
|
316
346
|
sessionJwt?: {
|
|
317
347
|
/** Janela de aceitação do `iat`, em segundos. Default: 60. */
|
|
318
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;
|
|
319
354
|
};
|
|
320
355
|
/** DPoP (§4.5): prender os access tokens é escolha da empresa. */
|
|
321
356
|
dpop?: {
|
|
@@ -356,6 +391,27 @@ export interface PoppyConfigInput {
|
|
|
356
391
|
* global devolvem `actor`.
|
|
357
392
|
*/
|
|
358
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;
|
|
359
415
|
/**
|
|
360
416
|
* Offer the `agora:dev` scope: a personal agent the person grants it to may use the app's Agora
|
|
361
417
|
* developer tools over MCP (`@adonis-agora/agent`, `/mcp/agora`). It is never ticked for the
|
|
@@ -364,6 +420,66 @@ export interface PoppyConfigInput {
|
|
|
364
420
|
*/
|
|
365
421
|
devTools?: boolean;
|
|
366
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
|
+
}
|
|
367
483
|
/**
|
|
368
484
|
* O que uma request verificada autoriza — sem o `actor`.
|
|
369
485
|
*/
|
|
@@ -382,6 +498,11 @@ export interface PoppyPrincipalBase {
|
|
|
382
498
|
sessionId: string;
|
|
383
499
|
/** A versão do protocolo que a request declarou em `Poppy-Version` (`'1.0'`, `'1.1'`…). */
|
|
384
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;
|
|
385
506
|
/**
|
|
386
507
|
* As extensões que a request declarou em `Poppy-Extensions` e que este app lista, `nome → versão`
|
|
387
508
|
* (§3.3, §3.4).
|
|
@@ -419,6 +540,7 @@ export interface ResolvedPoppyConfig {
|
|
|
419
540
|
scopes: string[];
|
|
420
541
|
} | null;
|
|
421
542
|
mediated: ResolvedPoppyMediatedConfig | null;
|
|
543
|
+
limitToResource: boolean;
|
|
422
544
|
};
|
|
423
545
|
agent: {
|
|
424
546
|
protocols: PoppyAgentProtocolEntry[];
|
|
@@ -430,6 +552,8 @@ export interface ResolvedPoppyConfig {
|
|
|
430
552
|
endpoint: string | null;
|
|
431
553
|
response: PoppyTasksResponse;
|
|
432
554
|
resolve?: PoppyTasksConfigInput['resolve'];
|
|
555
|
+
/** O endpoint de feedback da lib (`{prefix}/feedback`); `null` = nenhum ou do app. */
|
|
556
|
+
feedback: PoppyFeedbackConfigInput | null;
|
|
433
557
|
} | null;
|
|
434
558
|
web: {
|
|
435
559
|
browserSession: boolean;
|
|
@@ -441,6 +565,18 @@ export interface ResolvedPoppyConfig {
|
|
|
441
565
|
extensions: Record<string, ({
|
|
442
566
|
version: string;
|
|
443
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;
|
|
444
580
|
/** `null` = sem PAR. */
|
|
445
581
|
par: {
|
|
446
582
|
required: boolean;
|
|
@@ -464,6 +600,7 @@ export interface ResolvedPoppyConfig {
|
|
|
464
600
|
assertionMaxLifetime: number;
|
|
465
601
|
sessionJwt: {
|
|
466
602
|
maxAge: number;
|
|
603
|
+
oneUserPerKey: boolean;
|
|
467
604
|
};
|
|
468
605
|
dpop: {
|
|
469
606
|
required: boolean;
|
|
@@ -493,6 +630,18 @@ export declare const BROWSER_SIGN_IN_SCOPED_DESCRIPTION = "Use the website signe
|
|
|
493
630
|
export declare const BROWSER_SIGN_IN_UNSCOPED_DESCRIPTION = "Browse the website, and see and do anything your account can do there";
|
|
494
631
|
/** O nome da extensão Mediated Sign-In em `extensions`. */
|
|
495
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;
|
|
496
645
|
/** The scope that lets a personal agent use the app's Agora developer tools over MCP. */
|
|
497
646
|
export declare const AGORA_DEV_SCOPE = "agora:dev";
|
|
498
647
|
/** The catalog description of {@link AGORA_DEV_SCOPE} (the consent screen shows a translated text). */
|
package/build/src/config.js
CHANGED
|
@@ -183,10 +183,19 @@ export function resolvePoppyConfig(input, fallbackScopes) {
|
|
|
183
183
|
};
|
|
184
184
|
}
|
|
185
185
|
const extensions = {};
|
|
186
|
+
const flagged = {
|
|
187
|
+
[OPERATIONS_EXTENSION]: !!input.operations,
|
|
188
|
+
[BROWSER_CONTROL_EXTENSION]: input.browserControl === true,
|
|
189
|
+
[LINKS_EXTENSION]: input.links === true,
|
|
190
|
+
[DISCLOSURES_EXTENSION]: input.disclosures === true,
|
|
191
|
+
};
|
|
186
192
|
for (const [name, entries] of Object.entries(input.extensions ?? {})) {
|
|
187
193
|
if (name === MEDIATED_SIGN_IN_EXTENSION) {
|
|
188
194
|
fail(`extensions.${name} é publicada por signIn.mediated.`);
|
|
189
195
|
}
|
|
196
|
+
if (flagged[name]) {
|
|
197
|
+
fail(`extensions.${name} é publicada pela opção do próprio poppy() — não liste as duas.`);
|
|
198
|
+
}
|
|
190
199
|
if (!Array.isArray(entries) || entries.length === 0) {
|
|
191
200
|
fail(`extensions.${name} precisa ser uma lista, uma entrada por versão (§3.3).`);
|
|
192
201
|
}
|
|
@@ -211,6 +220,26 @@ export function resolvePoppyConfig(input, fallbackScopes) {
|
|
|
211
220
|
const withBrowserScope = (type) => type && BROWSER_SIGN_IN_SCOPE in scopes && !type.scopes.includes(BROWSER_SIGN_IN_SCOPE)
|
|
212
221
|
? { scopes: [...type.scopes, BROWSER_SIGN_IN_SCOPE] }
|
|
213
222
|
: type;
|
|
223
|
+
const browserJoin = web?.browserSession === true;
|
|
224
|
+
let operations = null;
|
|
225
|
+
if (input.operations) {
|
|
226
|
+
const o = input.operations === true ? {} : input.operations;
|
|
227
|
+
if (o.website === true && !browserJoin) {
|
|
228
|
+
fail('operations.website exige o browser_session_endpoint (web.browserSession).');
|
|
229
|
+
}
|
|
230
|
+
if (o.decide !== undefined && typeof o.decide !== 'function') {
|
|
231
|
+
fail('operations.decide precisa ser uma função.');
|
|
232
|
+
}
|
|
233
|
+
operations = {
|
|
234
|
+
website: o.website ?? browserJoin,
|
|
235
|
+
decide: o.decide,
|
|
236
|
+
expiresIn: positive(o.expiresIn, 900, 'operations.expiresIn'),
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
if (input.browserControl === true && !browserJoin) {
|
|
240
|
+
fail('browserControl exige o browser_session_endpoint (web.browserSession).');
|
|
241
|
+
}
|
|
242
|
+
const { versions, preferredVersion } = resolveVersions(input.versions, input.preferredVersion);
|
|
214
243
|
const assertionMaxLifetime = positive(input.assertionMaxLifetime, 300, 'assertionMaxLifetime');
|
|
215
244
|
if (assertionMaxLifetime < 300) {
|
|
216
245
|
fail('assertionMaxLifetime precisa ser >= 300: a spec proíbe recusar assertions de até 5 min.');
|
|
@@ -243,12 +272,19 @@ export function resolvePoppyConfig(input, fallbackScopes) {
|
|
|
243
272
|
direct: withBrowserScope(typeScopes(signInInput.direct, catalog, 'direct')),
|
|
244
273
|
device: withBrowserScope(typeScopes(signInInput.device, catalog, 'device')),
|
|
245
274
|
mediated,
|
|
275
|
+
limitToResource: signInInput.limitToResource === true,
|
|
246
276
|
},
|
|
247
277
|
agent: input.agent?.protocols?.length ? { protocols: [...input.agent.protocols] } : null,
|
|
248
278
|
apis: [...(input.apis ?? [])],
|
|
249
279
|
tasks,
|
|
250
280
|
web,
|
|
251
281
|
extensions,
|
|
282
|
+
versions,
|
|
283
|
+
preferredVersion,
|
|
284
|
+
operations,
|
|
285
|
+
browserControl: input.browserControl === true,
|
|
286
|
+
links: input.links === true,
|
|
287
|
+
disclosures: input.disclosures === true,
|
|
252
288
|
par: input.par === false || signInInput.direct === false
|
|
253
289
|
? null
|
|
254
290
|
: { required: typeof input.par === 'object' && input.par.required === true },
|
|
@@ -267,7 +303,10 @@ export function resolvePoppyConfig(input, fallbackScopes) {
|
|
|
267
303
|
deviceCodeTtl: positive(input.deviceCodeTtl, 600, 'deviceCodeTtl'),
|
|
268
304
|
pollInterval: positive(input.pollInterval, 5, 'pollInterval'),
|
|
269
305
|
assertionMaxLifetime,
|
|
270
|
-
sessionJwt: {
|
|
306
|
+
sessionJwt: {
|
|
307
|
+
maxAge: positive(input.sessionJwt?.maxAge, 60, 'sessionJwt.maxAge'),
|
|
308
|
+
oneUserPerKey: input.sessionJwt?.oneUserPerKey !== false,
|
|
309
|
+
},
|
|
271
310
|
dpop: {
|
|
272
311
|
required: input.dpop?.required === true,
|
|
273
312
|
requireNonce: input.dpop?.requireNonce === true,
|
|
@@ -291,6 +330,54 @@ export const BROWSER_SIGN_IN_SCOPED_DESCRIPTION = 'Use the website signed in, wi
|
|
|
291
330
|
export const BROWSER_SIGN_IN_UNSCOPED_DESCRIPTION = 'Browse the website, and see and do anything your account can do there';
|
|
292
331
|
/** O nome da extensão Mediated Sign-In em `extensions`. */
|
|
293
332
|
export const MEDIATED_SIGN_IN_EXTENSION = 'mediated-sign-in';
|
|
333
|
+
/** Extensão Operations (versão 3). */
|
|
334
|
+
export const OPERATIONS_EXTENSION = 'operations';
|
|
335
|
+
export const OPERATIONS_VERSION = '3';
|
|
336
|
+
/** Extensão Browser Control (versão 1). */
|
|
337
|
+
export const BROWSER_CONTROL_EXTENSION = 'browser-control';
|
|
338
|
+
/** Extensões Links e Disclosures (versão 1). */
|
|
339
|
+
export const LINKS_EXTENSION = 'links';
|
|
340
|
+
export const DISCLOSURES_EXTENSION = 'disclosures';
|
|
341
|
+
/** A versão do protocolo que este pacote implementa (§3.4). */
|
|
342
|
+
export const POPPY_BASE_VERSION = '1.0';
|
|
343
|
+
const VERSION = /^(0|[1-9]\d{0,3})\.(0|[1-9]\d{0,3})$/;
|
|
344
|
+
function resolveVersions(input, preferred) {
|
|
345
|
+
const versions = { [POPPY_BASE_VERSION]: {} };
|
|
346
|
+
for (const [version, options] of Object.entries(input ?? {})) {
|
|
347
|
+
if (!VERSION.test(version))
|
|
348
|
+
fail(`versions — "${version}" precisa ser major.minor.`);
|
|
349
|
+
if (options?.document !== undefined && typeof options.document !== 'function') {
|
|
350
|
+
fail(`versions.${version}.document precisa ser uma função.`);
|
|
351
|
+
}
|
|
352
|
+
if (version === POPPY_BASE_VERSION && options?.document) {
|
|
353
|
+
fail(`versions.${POPPY_BASE_VERSION}.document — o documento da 1.0 é o poppy.json da lib.`);
|
|
354
|
+
}
|
|
355
|
+
const dep = options?.deprecated;
|
|
356
|
+
if (dep !== undefined) {
|
|
357
|
+
if (!(dep?.at instanceof Date) || Number.isNaN(dep.at.getTime())) {
|
|
358
|
+
fail(`versions.${version}.deprecated.at precisa ser uma Date.`);
|
|
359
|
+
}
|
|
360
|
+
if (dep.sunset !== undefined && !(dep.sunset instanceof Date)) {
|
|
361
|
+
fail(`versions.${version}.deprecated.sunset precisa ser uma Date.`);
|
|
362
|
+
}
|
|
363
|
+
if (dep.link !== undefined)
|
|
364
|
+
absoluteUrl(dep.link, `versions.${version}.deprecated.link`);
|
|
365
|
+
}
|
|
366
|
+
versions[version] = { ...(options ?? {}) };
|
|
367
|
+
}
|
|
368
|
+
const newest = Object.keys(versions).sort(compareVersions).at(-1);
|
|
369
|
+
const preferredVersion = preferred ?? newest;
|
|
370
|
+
if (!(preferredVersion in versions)) {
|
|
371
|
+
fail(`preferredVersion "${preferredVersion}" não está em versions.`);
|
|
372
|
+
}
|
|
373
|
+
return { versions, preferredVersion };
|
|
374
|
+
}
|
|
375
|
+
/** Ordena `major.minor` numericamente. */
|
|
376
|
+
export function compareVersions(a, b) {
|
|
377
|
+
const [am, an] = a.split('.').map(Number);
|
|
378
|
+
const [bm, bn] = b.split('.').map(Number);
|
|
379
|
+
return am - bm || an - bn;
|
|
380
|
+
}
|
|
294
381
|
const SKILL_DIGEST = /^sha256:[0-9a-f]{64}$/;
|
|
295
382
|
function resolveTasks(input, apis) {
|
|
296
383
|
if (!input)
|
|
@@ -300,7 +387,7 @@ function resolveTasks(input, apis) {
|
|
|
300
387
|
if (input.excludedTasks || input.skillIndex || input.feedback || input.resolve) {
|
|
301
388
|
fail('tasks.endpoint é um endpoint do app: os demais campos de tasks ficam nele.');
|
|
302
389
|
}
|
|
303
|
-
return { endpoint: input.endpoint, response: {} };
|
|
390
|
+
return { endpoint: input.endpoint, response: {}, feedback: null };
|
|
304
391
|
}
|
|
305
392
|
const response = {};
|
|
306
393
|
if (input.excludedTasks) {
|
|
@@ -330,14 +417,26 @@ function resolveTasks(input, apis) {
|
|
|
330
417
|
}
|
|
331
418
|
response.skill_index = index;
|
|
332
419
|
}
|
|
420
|
+
let feedback = null;
|
|
333
421
|
if (input.feedback) {
|
|
334
|
-
|
|
335
|
-
|
|
422
|
+
if ('endpoint' in input.feedback && input.feedback.endpoint !== undefined) {
|
|
423
|
+
absoluteUrl(input.feedback.endpoint, 'tasks.feedback.endpoint');
|
|
424
|
+
if (input.feedback.onReport !== undefined) {
|
|
425
|
+
fail('tasks.feedback.onReport é do endpoint da lib: sem `endpoint`.');
|
|
426
|
+
}
|
|
427
|
+
response.feedback = { endpoint: input.feedback.endpoint };
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
feedback = input.feedback;
|
|
431
|
+
if (feedback.onReport !== undefined && typeof feedback.onReport !== 'function') {
|
|
432
|
+
fail('tasks.feedback.onReport precisa ser uma função.');
|
|
433
|
+
}
|
|
434
|
+
}
|
|
336
435
|
}
|
|
337
436
|
if (input.resolve !== undefined && typeof input.resolve !== 'function') {
|
|
338
437
|
fail('tasks.resolve precisa ser uma função.');
|
|
339
438
|
}
|
|
340
|
-
return { endpoint: null, response, resolve: input.resolve };
|
|
439
|
+
return { endpoint: null, response, resolve: input.resolve, feedback };
|
|
341
440
|
}
|
|
342
441
|
function validateAlternative(alternative, apis) {
|
|
343
442
|
const refs = alternative.references ?? [];
|
|
@@ -126,14 +126,14 @@ export default class PoppyConsentController {
|
|
|
126
126
|
const input = ctx.request.input('user_code');
|
|
127
127
|
if (!input)
|
|
128
128
|
return render(ctx, 'agents/consent', base);
|
|
129
|
-
const
|
|
129
|
+
const accountId = ctx.session.get(ACCOUNT_SESSION_KEY);
|
|
130
|
+
const pending = await poppy.pendingDevice(input, accountId);
|
|
130
131
|
if (!pending) {
|
|
131
132
|
return render(ctx, 'agents/consent', {
|
|
132
133
|
...base,
|
|
133
134
|
error: 'agents.consent.invalid_code',
|
|
134
135
|
});
|
|
135
136
|
}
|
|
136
|
-
const accountId = ctx.session.get(ACCOUNT_SESSION_KEY);
|
|
137
137
|
const account = await service.config.accountStore.findById(accountId);
|
|
138
138
|
return render(ctx, 'agents/consent', {
|
|
139
139
|
...base,
|
|
@@ -8,6 +8,21 @@ import type { HttpContext } from '@adonisjs/core/http';
|
|
|
8
8
|
export default class PoppyController {
|
|
9
9
|
/** `GET /.well-known/poppy.json` — só no domínio da empresa; `www.` redireciona para ele. */
|
|
10
10
|
discovery(ctx: HttpContext): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* `GET {prefix}/versions/{versão}.json` (§3.4): o documento de outra versão servida, no mesmo host
|
|
13
|
+
* do poppy.json, sem `supported_versions`. Uma versão em retirada sai com `Deprecation`/`Sunset`.
|
|
14
|
+
*/
|
|
15
|
+
versionDocument(ctx: HttpContext): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* `POST feedback.endpoint` da lib (§9.3): com o header da Session. 202 sem corpo, 200 com uma
|
|
18
|
+
* alternativa, 400 `invalid_request` para um relato malformado.
|
|
19
|
+
*/
|
|
20
|
+
feedback(ctx: HttpContext): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* `POST endpoint` da extensão Operations (operações do site): `{ ref }`, com o header da Session,
|
|
23
|
+
* o access token quando logado e, para aprovar, `Poppy-Approval`.
|
|
24
|
+
*/
|
|
25
|
+
operations(ctx: HttpContext): Promise<void>;
|
|
11
26
|
/** `GET /.well-known/oauth-protected-resource` do domínio (§3.2, RFC 9728). */
|
|
12
27
|
protectedResource(ctx: HttpContext): Promise<void>;
|
|
13
28
|
/** `GET /.well-known/oauth-authorization-server{prefix}` (RFC 8414 + `protected_resources`). */
|
|
@@ -57,8 +57,82 @@ export default class PoppyController {
|
|
|
57
57
|
return ctx.response.notFound();
|
|
58
58
|
ctx.response.header('Access-Control-Allow-Origin', '*');
|
|
59
59
|
ctx.response.header('Cache-Control', 'public, max-age=300');
|
|
60
|
+
for (const [k, v] of Object.entries(poppy.versionHeaders(poppy.cfg.preferredVersion))) {
|
|
61
|
+
ctx.response.header(k, v);
|
|
62
|
+
}
|
|
60
63
|
return ctx.response.json(doc);
|
|
61
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* `GET {prefix}/versions/{versão}.json` (§3.4): o documento de outra versão servida, no mesmo host
|
|
67
|
+
* do poppy.json, sem `supported_versions`. Uma versão em retirada sai com `Deprecation`/`Sunset`.
|
|
68
|
+
*/
|
|
69
|
+
async versionDocument(ctx) {
|
|
70
|
+
const poppy = await poppyOr404(ctx);
|
|
71
|
+
if (!poppy)
|
|
72
|
+
return;
|
|
73
|
+
const match = /^(\d{1,4}\.\d{1,4})\.json$/.exec(String(ctx.request.param('file') ?? ''));
|
|
74
|
+
const host = ctx.request.host() ?? ctx.request.hostname() ?? '';
|
|
75
|
+
const doc = match ? poppy.versionDocument(host, match[1]) : null;
|
|
76
|
+
if (!doc)
|
|
77
|
+
return ctx.response.notFound();
|
|
78
|
+
ctx.response.header('Access-Control-Allow-Origin', '*');
|
|
79
|
+
ctx.response.header('Cache-Control', 'public, max-age=300');
|
|
80
|
+
for (const [k, v] of Object.entries(poppy.versionHeaders(match[1]))) {
|
|
81
|
+
ctx.response.header(k, v);
|
|
82
|
+
}
|
|
83
|
+
return ctx.response.json(doc);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* `POST feedback.endpoint` da lib (§9.3): com o header da Session. 202 sem corpo, 200 com uma
|
|
87
|
+
* alternativa, 400 `invalid_request` para um relato malformado.
|
|
88
|
+
*/
|
|
89
|
+
async feedback(ctx) {
|
|
90
|
+
const poppy = await poppyOr404(ctx);
|
|
91
|
+
if (!poppy)
|
|
92
|
+
return;
|
|
93
|
+
if (!poppy.cfg.tasks?.feedback)
|
|
94
|
+
return ctx.response.notFound();
|
|
95
|
+
noStore(ctx);
|
|
96
|
+
const result = await poppy.feedback({
|
|
97
|
+
method: ctx.request.method(),
|
|
98
|
+
url: publicRequestUrl(ctx, poppy),
|
|
99
|
+
headers: ctx.request.headers(),
|
|
100
|
+
}, ctx.request.body());
|
|
101
|
+
if (!result.ok) {
|
|
102
|
+
if ('wwwAuthenticate' in result)
|
|
103
|
+
return writePoppyAuthError(ctx, result);
|
|
104
|
+
return ctx.response.status(result.status).json(result.body);
|
|
105
|
+
}
|
|
106
|
+
for (const [k, v] of Object.entries(result.headers))
|
|
107
|
+
ctx.response.header(k, v);
|
|
108
|
+
if (result.body === null)
|
|
109
|
+
return ctx.response.status(202).send('');
|
|
110
|
+
return ctx.response.status(200).json(result.body);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* `POST endpoint` da extensão Operations (operações do site): `{ ref }`, com o header da Session,
|
|
114
|
+
* o access token quando logado e, para aprovar, `Poppy-Approval`.
|
|
115
|
+
*/
|
|
116
|
+
async operations(ctx) {
|
|
117
|
+
const poppy = await poppyOr404(ctx);
|
|
118
|
+
if (!poppy)
|
|
119
|
+
return;
|
|
120
|
+
if (!poppy.cfg.operations?.website)
|
|
121
|
+
return ctx.response.notFound();
|
|
122
|
+
noStore(ctx);
|
|
123
|
+
const result = await poppy.operationsEndpoint({
|
|
124
|
+
method: ctx.request.method(),
|
|
125
|
+
url: publicRequestUrl(ctx, poppy),
|
|
126
|
+
headers: ctx.request.headers(),
|
|
127
|
+
}, ctx.request.body());
|
|
128
|
+
if (!result.ok)
|
|
129
|
+
return writePoppyAuthError(ctx, result);
|
|
130
|
+
for (const [k, v] of Object.entries(result.headers))
|
|
131
|
+
ctx.response.header(k, v);
|
|
132
|
+
if (result.body === null)
|
|
133
|
+
return ctx.response.status(result.status).send('');
|
|
134
|
+
return ctx.response.status(result.status).json(result.body);
|
|
135
|
+
}
|
|
62
136
|
/** `GET /.well-known/oauth-protected-resource` do domínio (§3.2, RFC 9728). */
|
|
63
137
|
async protectedResource(ctx) {
|
|
64
138
|
const poppy = await poppyOr404(ctx);
|
|
@@ -130,6 +204,8 @@ export default class PoppyController {
|
|
|
130
204
|
});
|
|
131
205
|
if (!result.ok)
|
|
132
206
|
return writePoppyAuthError(ctx, result);
|
|
207
|
+
for (const [k, v] of Object.entries(result.headers))
|
|
208
|
+
ctx.response.header(k, v);
|
|
133
209
|
ctx.response.header('Cache-Control', result.perSession ? 'no-store' : 'private, max-age=300');
|
|
134
210
|
return ctx.response.status(200).json(result.body);
|
|
135
211
|
}
|