@adonis-agora/authkit-server 0.74.0 → 0.76.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/README.md +3 -0
- package/build/host/views/account/apps.edge +30 -0
- package/build/host/views/agents/consent.edge +60 -0
- package/build/host/views/agents/done.edge +24 -0
- package/build/host/views/consent.edge +9 -1
- package/build/host/views/partials/styles.edge +1 -1
- package/build/index.d.ts +9 -0
- package/build/index.js +4 -0
- package/build/providers/authkit_server_provider.js +75 -50
- package/build/src/agents/agent_identity.d.ts +33 -0
- package/build/src/agents/agent_identity.js +156 -0
- package/build/src/agents/config.d.ts +99 -0
- package/build/src/agents/config.js +101 -0
- package/build/src/agents/delegation_service.d.ts +154 -0
- package/build/src/agents/delegation_service.js +394 -0
- package/build/src/agents/delegation_store.d.ts +93 -0
- package/build/src/agents/delegation_store.js +222 -0
- package/build/src/agents/middleware.d.ts +73 -0
- package/build/src/agents/middleware.js +113 -0
- package/build/src/agents/protocol.d.ts +62 -0
- package/build/src/agents/protocol.js +51 -0
- package/build/src/agents/runtime.d.ts +36 -0
- package/build/src/agents/runtime.js +65 -0
- package/build/src/agents/signer.d.ts +34 -0
- package/build/src/agents/signer.js +70 -0
- package/build/src/audit/audit_sink.d.ts +1 -1
- package/build/src/audit/audit_sink.js +5 -0
- package/build/src/controllers/authorization_server_metadata_controller.d.ts +10 -0
- package/build/src/controllers/authorization_server_metadata_controller.js +20 -0
- package/build/src/define_config.d.ts +34 -3
- package/build/src/define_config.js +35 -1
- package/build/src/host/access_token_verifier.d.ts +7 -0
- package/build/src/host/access_token_verifier.js +8 -0
- package/build/src/host/account_api/account_api_controller.d.ts +12 -0
- package/build/src/host/account_api/account_api_controller.js +40 -0
- package/build/src/host/admin_api/dto.d.ts +1 -1
- package/build/src/host/admin_sessions_service.d.ts +2 -0
- package/build/src/host/admin_sessions_service.js +18 -0
- package/build/src/host/auth_host_config.d.ts +4 -0
- package/build/src/host/bearer_account.d.ts +17 -0
- package/build/src/host/bearer_account.js +10 -0
- package/build/src/host/client_names.d.ts +11 -0
- package/build/src/host/client_names.js +12 -0
- package/build/src/host/console_session.js +3 -5
- package/build/src/host/controllers/account_apps_controller.d.ts +2 -0
- package/build/src/host/controllers/account_apps_controller.js +39 -3
- package/build/src/host/controllers/account_orgs_controller.js +2 -1
- package/build/src/host/controllers/account_session_controller.js +2 -1
- package/build/src/host/controllers/agent_consent_controller.d.ts +17 -0
- package/build/src/host/controllers/agent_consent_controller.js +138 -0
- package/build/src/host/controllers/agent_oauth_controller.d.ts +23 -0
- package/build/src/host/controllers/agent_oauth_controller.js +110 -0
- package/build/src/host/controllers/interaction_controller.js +28 -0
- package/build/src/host/csrf.d.ts +8 -18
- package/build/src/host/csrf.js +28 -2
- package/build/src/host/i18n.d.ts +54 -0
- package/build/src/host/i18n.js +54 -0
- package/build/src/host/impersonation_session.d.ts +5 -0
- package/build/src/host/impersonation_session.js +37 -4
- package/build/src/host/oidc_bearer_guard.js +10 -1
- package/build/src/host/redirect_exact.d.ts +12 -0
- package/build/src/host/redirect_exact.js +17 -0
- package/build/src/host/register_auth_host.js +48 -7
- package/build/src/host/request_url.d.ts +10 -0
- package/build/src/host/request_url.js +17 -0
- package/build/src/host/sudo/methods/magic_link.js +2 -1
- package/build/src/host/sudo/runtime.js +3 -2
- package/build/src/host/sudo_mode.js +4 -4
- package/build/src/mcp/mcp_oauth.d.ts +85 -0
- package/build/src/mcp/mcp_oauth.js +154 -0
- package/build/src/provider/build_provider.js +20 -1
- package/build/src/provider/oidc_service.d.ts +8 -0
- package/build/src/provider/oidc_service.js +11 -0
- package/build/src/provider/token_exchange.d.ts +26 -0
- package/build/src/provider/token_exchange.js +44 -3
- package/build/src/schema/ensure.js +92 -0
- package/build/stubs/ui/react/pages/consent.tsx +17 -1
- package/package.json +1 -1
- package/stubs/ui/react/pages/consent.tsx +17 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Personal agents — config.
|
|
3
|
+
*
|
|
4
|
+
* Um PERSONAL AGENT é uma plataforma de agente (ChatGPT, Meta AI, um assistente
|
|
5
|
+
* próprio…) que fala com este app EM NOME de um usuário. Ele se identifica com um
|
|
6
|
+
* JWT assinado pela própria chave (publicada num JWKS) — sem segredo
|
|
7
|
+
* compartilhado — e, opcionalmente, recebe do usuário uma DELEGAÇÃO: o usuário
|
|
8
|
+
* loga aqui, aprova scopes definidos pelo app, e o agente passa a agir na conta
|
|
9
|
+
* dele só dentro desses scopes.
|
|
10
|
+
*
|
|
11
|
+
* O núcleo (identidade do agente, device flow, grants, tokens de delegação,
|
|
12
|
+
* recibos) não depende de protocolo; o formato do fio vem do adapter em
|
|
13
|
+
* `protocol` (default: PACT — https://openpactprotocol.org). Ver `protocol.ts`.
|
|
14
|
+
*/
|
|
15
|
+
import { type BuiltinProtocolId, type PersonalAgentProtocol } from './protocol.js';
|
|
16
|
+
/** Registro de um personal agent conhecido (PACT §3.1). */
|
|
17
|
+
export interface PersonalAgentRegistration {
|
|
18
|
+
/** Valor exato que o agente põe no `iss` do JWT. Também é o `client_id` OAuth dele. */
|
|
19
|
+
issuer: string;
|
|
20
|
+
/** URL HTTPS do JWKS do agente. Estável — a rotação acontece dentro do JWKS. */
|
|
21
|
+
jwksUri: string;
|
|
22
|
+
/** Nome exibido na tela de consentimento. Default: o host do `issuer`. */
|
|
23
|
+
name?: string;
|
|
24
|
+
/** `false` desabilita o agente: as requests dele passam a receber 401. Default: true. */
|
|
25
|
+
enabled?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/** Resolve um agente pelo `iss`. `null` = desconhecido (401). */
|
|
28
|
+
export type PersonalAgentResolver = (issuer: string) => PersonalAgentRegistration | null | Promise<PersonalAgentRegistration | null>;
|
|
29
|
+
export interface PersonalAgentDelegationConfigInput {
|
|
30
|
+
/**
|
|
31
|
+
* URL do endpoint do agente DESTE app que os personal agents chamam (a
|
|
32
|
+
* "interface URL" do Agent Card). Vira o `aud` dos tokens de delegação — um
|
|
33
|
+
* token só vale para ela.
|
|
34
|
+
*/
|
|
35
|
+
interfaceUrl: string;
|
|
36
|
+
/**
|
|
37
|
+
* Scopes que o app oferece, `id → descrição`. A descrição aparece VERBATIM na
|
|
38
|
+
* tela de consentimento, então escreva para o usuário final
|
|
39
|
+
* (`{ 'orders:read': 'Ver seus pedidos e o status deles' }`).
|
|
40
|
+
*/
|
|
41
|
+
scopes: Record<string, string>;
|
|
42
|
+
/** TTL do token de delegação, em segundos. Default: 3600 (o PACT recomenda ≤ 1h). */
|
|
43
|
+
accessTokenTtl?: number;
|
|
44
|
+
/** Validade do grant (e dos refresh tokens dele), em segundos. Default: 30 dias. */
|
|
45
|
+
grantTtl?: number;
|
|
46
|
+
/** Validade do `device_code`/`user_code`, em segundos. Default: 600. */
|
|
47
|
+
deviceCodeTtl?: number;
|
|
48
|
+
/** Intervalo mínimo de polling do token endpoint, em segundos. Default: 5. */
|
|
49
|
+
pollInterval?: number;
|
|
50
|
+
}
|
|
51
|
+
export interface PersonalAgentsConfigInput {
|
|
52
|
+
/**
|
|
53
|
+
* Protocolo do fio: um embutido pelo id (`'pact'`) ou um adapter próprio
|
|
54
|
+
* (ver {@link PersonalAgentProtocol}). Default: `'pact'`.
|
|
55
|
+
*/
|
|
56
|
+
protocol?: BuiltinProtocolId | PersonalAgentProtocol;
|
|
57
|
+
/**
|
|
58
|
+
* Valor que os personal agents põem no `aud` do JWT deles. Opaco e atribuído
|
|
59
|
+
* por ESTE app no registro do agente — um valor por app, não derivado de URL.
|
|
60
|
+
*/
|
|
61
|
+
audience: string;
|
|
62
|
+
/**
|
|
63
|
+
* Agentes aceitos: uma lista estática, ou uma função que resolve pelo `iss`
|
|
64
|
+
* (para quem guarda o registro no banco). Default: nenhum.
|
|
65
|
+
*/
|
|
66
|
+
agents?: PersonalAgentRegistration[] | PersonalAgentResolver;
|
|
67
|
+
/**
|
|
68
|
+
* `true` aceita QUALQUER agente cujo `iss` publique um JWKS via OIDC discovery
|
|
69
|
+
* (`{iss}/.well-known/openid-configuration`), além dos registrados. A
|
|
70
|
+
* verificação do JWT continua completa; só a lista de permitidos some.
|
|
71
|
+
* Default: false.
|
|
72
|
+
*/
|
|
73
|
+
open?: boolean;
|
|
74
|
+
/** Delegação (PACT §5). Ausente = só identidade (o agente fala, mas não age na conta). */
|
|
75
|
+
delegation?: PersonalAgentDelegationConfigInput;
|
|
76
|
+
/** Prefixo das rotas (`{prefix}/oauth/*`, `{prefix}/consent`). Default: `/agents`. */
|
|
77
|
+
prefix?: string;
|
|
78
|
+
}
|
|
79
|
+
export interface ResolvedPersonalAgentDelegationConfig {
|
|
80
|
+
interfaceUrl: string;
|
|
81
|
+
scopes: Record<string, string>;
|
|
82
|
+
accessTokenTtl: number;
|
|
83
|
+
grantTtl: number;
|
|
84
|
+
deviceCodeTtl: number;
|
|
85
|
+
pollInterval: number;
|
|
86
|
+
}
|
|
87
|
+
export interface ResolvedPersonalAgentsConfig {
|
|
88
|
+
protocol: PersonalAgentProtocol;
|
|
89
|
+
audience: string;
|
|
90
|
+
resolveAgent: PersonalAgentResolver;
|
|
91
|
+
open: boolean;
|
|
92
|
+
delegation?: ResolvedPersonalAgentDelegationConfig;
|
|
93
|
+
prefix: string;
|
|
94
|
+
}
|
|
95
|
+
export declare function normalizePersonalAgentsPrefix(prefix: string | undefined): string;
|
|
96
|
+
export declare function resolvePersonalAgentsConfig(input: PersonalAgentsConfigInput | undefined): ResolvedPersonalAgentsConfig | undefined;
|
|
97
|
+
/** `"a b c"` → `['a','b','c']` sem duplicatas, na ordem. */
|
|
98
|
+
export declare function parseScope(value: string | null | undefined): string[];
|
|
99
|
+
export declare function formatScope(scopes: Iterable<string>): string;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Personal agents — config.
|
|
3
|
+
*
|
|
4
|
+
* Um PERSONAL AGENT é uma plataforma de agente (ChatGPT, Meta AI, um assistente
|
|
5
|
+
* próprio…) que fala com este app EM NOME de um usuário. Ele se identifica com um
|
|
6
|
+
* JWT assinado pela própria chave (publicada num JWKS) — sem segredo
|
|
7
|
+
* compartilhado — e, opcionalmente, recebe do usuário uma DELEGAÇÃO: o usuário
|
|
8
|
+
* loga aqui, aprova scopes definidos pelo app, e o agente passa a agir na conta
|
|
9
|
+
* dele só dentro desses scopes.
|
|
10
|
+
*
|
|
11
|
+
* O núcleo (identidade do agente, device flow, grants, tokens de delegação,
|
|
12
|
+
* recibos) não depende de protocolo; o formato do fio vem do adapter em
|
|
13
|
+
* `protocol` (default: PACT — https://openpactprotocol.org). Ver `protocol.ts`.
|
|
14
|
+
*/
|
|
15
|
+
import { BUILTIN_PROTOCOLS, } from './protocol.js';
|
|
16
|
+
const SCOPE_ID = /^[\x21\x23-\x5B\x5D-\x7E]+$/; // RFC 6749 §3.3 scope-token
|
|
17
|
+
function assertUrl(value, what) {
|
|
18
|
+
try {
|
|
19
|
+
new URL(value);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
throw new Error(`authkit: personalAgents.${what} precisa ser uma URL absoluta (recebeu "${value}").`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function positive(value, fallback, what) {
|
|
26
|
+
if (value === undefined)
|
|
27
|
+
return fallback;
|
|
28
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
29
|
+
throw new Error(`authkit: personalAgents.delegation.${what} precisa ser > 0.`);
|
|
30
|
+
}
|
|
31
|
+
return Math.floor(value);
|
|
32
|
+
}
|
|
33
|
+
export function normalizePersonalAgentsPrefix(prefix) {
|
|
34
|
+
const trimmed = (prefix ?? '/agents').trim().replace(/\/+$/, '');
|
|
35
|
+
if (!trimmed)
|
|
36
|
+
return '/agents';
|
|
37
|
+
return trimmed.startsWith('/') ? trimmed : `/${trimmed}`;
|
|
38
|
+
}
|
|
39
|
+
export function resolvePersonalAgentsConfig(input) {
|
|
40
|
+
if (!input)
|
|
41
|
+
return undefined;
|
|
42
|
+
if (!input.audience?.trim()) {
|
|
43
|
+
throw new Error('authkit: personalAgents.audience é obrigatório (o `aud` dos JWTs dos agentes).');
|
|
44
|
+
}
|
|
45
|
+
let resolveAgent;
|
|
46
|
+
if (typeof input.agents === 'function') {
|
|
47
|
+
resolveAgent = input.agents;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const byIssuer = new Map();
|
|
51
|
+
for (const agent of input.agents ?? []) {
|
|
52
|
+
assertUrl(agent.issuer, `agents[].issuer`);
|
|
53
|
+
assertUrl(agent.jwksUri, `agents[].jwksUri`);
|
|
54
|
+
byIssuer.set(agent.issuer, agent);
|
|
55
|
+
}
|
|
56
|
+
resolveAgent = (issuer) => byIssuer.get(issuer) ?? null;
|
|
57
|
+
}
|
|
58
|
+
let delegation;
|
|
59
|
+
if (input.delegation) {
|
|
60
|
+
const d = input.delegation;
|
|
61
|
+
assertUrl(d.interfaceUrl, 'delegation.interfaceUrl');
|
|
62
|
+
const ids = Object.keys(d.scopes ?? {});
|
|
63
|
+
if (ids.length === 0) {
|
|
64
|
+
throw new Error('authkit: personalAgents.delegation.scopes precisa de pelo menos um scope.');
|
|
65
|
+
}
|
|
66
|
+
for (const id of ids) {
|
|
67
|
+
if (!SCOPE_ID.test(id)) {
|
|
68
|
+
throw new Error(`authkit: personalAgents.delegation.scopes — id inválido "${id}" (sem espaços/aspas).`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
delegation = {
|
|
72
|
+
interfaceUrl: d.interfaceUrl,
|
|
73
|
+
scopes: { ...d.scopes },
|
|
74
|
+
accessTokenTtl: positive(d.accessTokenTtl, 3600, 'accessTokenTtl'),
|
|
75
|
+
grantTtl: positive(d.grantTtl, 30 * 24 * 3600, 'grantTtl'),
|
|
76
|
+
deviceCodeTtl: positive(d.deviceCodeTtl, 600, 'deviceCodeTtl'),
|
|
77
|
+
pollInterval: positive(d.pollInterval, 5, 'pollInterval'),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const protocol = typeof input.protocol === 'object'
|
|
81
|
+
? input.protocol
|
|
82
|
+
: BUILTIN_PROTOCOLS[input.protocol ?? 'pact'];
|
|
83
|
+
if (!protocol) {
|
|
84
|
+
throw new Error(`authkit: personalAgents.protocol "${String(input.protocol)}" desconhecido (embutidos: ${Object.keys(BUILTIN_PROTOCOLS).join(', ')}).`);
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
protocol,
|
|
88
|
+
audience: input.audience,
|
|
89
|
+
resolveAgent,
|
|
90
|
+
open: input.open === true,
|
|
91
|
+
delegation,
|
|
92
|
+
prefix: normalizePersonalAgentsPrefix(input.prefix),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/** `"a b c"` → `['a','b','c']` sem duplicatas, na ordem. */
|
|
96
|
+
export function parseScope(value) {
|
|
97
|
+
return [...new Set((value ?? '').split(' ').filter(Boolean))];
|
|
98
|
+
}
|
|
99
|
+
export function formatScope(scopes) {
|
|
100
|
+
return [...scopes].join(' ');
|
|
101
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { PersonalAgentIdentity } from './agent_identity.js';
|
|
2
|
+
import { type ResolvedPersonalAgentDelegationConfig } from './config.js';
|
|
3
|
+
import type { DelegationStore } from './delegation_store.js';
|
|
4
|
+
import type { AgentSigner } from './signer.js';
|
|
5
|
+
export declare const DEVICE_CODE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
|
|
6
|
+
export declare const REFRESH_TOKEN_GRANT_TYPE = "refresh_token";
|
|
7
|
+
/** Erro OAuth (RFC 6749 §5.2 / RFC 8628 §3.5) — vira `{ error, error_description }`. */
|
|
8
|
+
export declare class AgentOAuthError extends Error {
|
|
9
|
+
readonly code: 'invalid_request' | 'invalid_client' | 'invalid_grant' | 'invalid_scope' | 'authorization_pending' | 'slow_down' | 'access_denied' | 'expired_token' | 'unsupported_grant_type';
|
|
10
|
+
readonly description: string;
|
|
11
|
+
readonly status: number;
|
|
12
|
+
constructor(code: 'invalid_request' | 'invalid_client' | 'invalid_grant' | 'invalid_scope' | 'authorization_pending' | 'slow_down' | 'access_denied' | 'expired_token' | 'unsupported_grant_type', description: string, status?: number);
|
|
13
|
+
}
|
|
14
|
+
export interface DeviceAuthorizationResponse {
|
|
15
|
+
device_code: string;
|
|
16
|
+
user_code: string;
|
|
17
|
+
verification_uri: string;
|
|
18
|
+
verification_uri_complete: string;
|
|
19
|
+
expires_in: number;
|
|
20
|
+
interval: number;
|
|
21
|
+
}
|
|
22
|
+
export interface DelegationTokenResponse {
|
|
23
|
+
token_type: 'Bearer';
|
|
24
|
+
access_token: string;
|
|
25
|
+
refresh_token: string;
|
|
26
|
+
expires_in: number;
|
|
27
|
+
scope: string;
|
|
28
|
+
}
|
|
29
|
+
/** Um pedido aguardando o usuário na tela de consentimento. */
|
|
30
|
+
export interface PendingDelegationRequest {
|
|
31
|
+
userCode: string;
|
|
32
|
+
/** `iss` do agente que pediu. */
|
|
33
|
+
clientId: string;
|
|
34
|
+
scopes: {
|
|
35
|
+
id: string;
|
|
36
|
+
description: string;
|
|
37
|
+
}[];
|
|
38
|
+
expiresAt: Date;
|
|
39
|
+
}
|
|
40
|
+
/** O que um token de delegação válido autoriza (PACT §5.5). */
|
|
41
|
+
export interface DelegationContext {
|
|
42
|
+
/** Conta NESTE app em nome da qual o agente age (`sub` do token). */
|
|
43
|
+
accountId: string;
|
|
44
|
+
scopes: string[];
|
|
45
|
+
grantId: string;
|
|
46
|
+
/** `iss` do agente. */
|
|
47
|
+
clientId: string;
|
|
48
|
+
}
|
|
49
|
+
export interface DelegationGrantSummary {
|
|
50
|
+
id: string;
|
|
51
|
+
clientId: string;
|
|
52
|
+
scopes: {
|
|
53
|
+
id: string;
|
|
54
|
+
description: string;
|
|
55
|
+
}[];
|
|
56
|
+
createdAt: Date;
|
|
57
|
+
updatedAt: Date;
|
|
58
|
+
expiresAt: Date;
|
|
59
|
+
}
|
|
60
|
+
/** Recibo de uma ação feita sob delegação (PACT §5.6). */
|
|
61
|
+
export interface DelegationReceipt {
|
|
62
|
+
jws: string;
|
|
63
|
+
claims: {
|
|
64
|
+
grantId: string;
|
|
65
|
+
user: string;
|
|
66
|
+
pa: string;
|
|
67
|
+
brand: string;
|
|
68
|
+
scopesUsed: string[];
|
|
69
|
+
actions: {
|
|
70
|
+
tool: string;
|
|
71
|
+
argsHash?: string;
|
|
72
|
+
}[];
|
|
73
|
+
ts: string;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export interface PersonalAgentDelegationDeps {
|
|
77
|
+
cfg: ResolvedPersonalAgentDelegationConfig;
|
|
78
|
+
store: DelegationStore;
|
|
79
|
+
signer: AgentSigner;
|
|
80
|
+
/** `issuer` do authorization server de delegação e URL da tela de consentimento. */
|
|
81
|
+
urls: {
|
|
82
|
+
issuer: string;
|
|
83
|
+
consent: string;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* A conta ainda pode agir? (existe e não está desabilitada). Checado em cada
|
|
87
|
+
* uso do grant: apagar ou suspender a conta corta a delegação na hora.
|
|
88
|
+
* Default: sempre ativa.
|
|
89
|
+
*/
|
|
90
|
+
isAccountActive?: (accountId: string) => Promise<boolean>;
|
|
91
|
+
now?: () => Date;
|
|
92
|
+
}
|
|
93
|
+
/** Aceita o código como o usuário digitar: minúsculas, sem hífen, com espaços. */
|
|
94
|
+
export declare function normalizeUserCode(input: unknown): string | null;
|
|
95
|
+
/**
|
|
96
|
+
* Delegação de personal agents: RFC 8628 (device code) em que o cliente OAuth é
|
|
97
|
+
* o agente — autenticado pelo JWT dele, não por client secret — e o login é o
|
|
98
|
+
* login deste app. O usuário aprova scopes definidos pelo app; o agente recebe
|
|
99
|
+
* um token assinado pelo keystore do IdP, com vida curta e refresh rotativo,
|
|
100
|
+
* revogável a qualquer momento no console de conta.
|
|
101
|
+
*
|
|
102
|
+
* Um grant por (conta, agente, usuário do agente): aprovar de novo — o step-up
|
|
103
|
+
* de um scope que faltava — SOMA scopes ao grant existente em vez de criar outro.
|
|
104
|
+
*/
|
|
105
|
+
export declare class PersonalAgentDelegation {
|
|
106
|
+
#private;
|
|
107
|
+
constructor(deps: PersonalAgentDelegationDeps);
|
|
108
|
+
get scopes(): Record<string, string>;
|
|
109
|
+
get interfaceUrl(): string;
|
|
110
|
+
/** `POST device_authorization` (PACT §5.3). */
|
|
111
|
+
requestDevice(agent: PersonalAgentIdentity, scopeParam: unknown): Promise<DeviceAuthorizationResponse>;
|
|
112
|
+
/** `POST token` com `grant_type=device_code` (RFC 8628 §3.4/§3.5). */
|
|
113
|
+
exchangeDeviceCode(agent: PersonalAgentIdentity, deviceCode: unknown): Promise<DelegationTokenResponse>;
|
|
114
|
+
/** `POST token` com `grant_type=refresh_token`. Rotativo: o refresh usado morre. */
|
|
115
|
+
refresh(agent: PersonalAgentIdentity, refreshToken: unknown): Promise<DelegationTokenResponse>;
|
|
116
|
+
/** O pedido por trás de um `user_code`, se ainda está aguardando. */
|
|
117
|
+
pendingRequest(userCodeInput: unknown): Promise<PendingDelegationRequest | null>;
|
|
118
|
+
/**
|
|
119
|
+
* O usuário aprovou `scopes` (só o que estava no pedido conta). `null` = nada
|
|
120
|
+
* foi aprovado: nenhum scope do pedido marcado, ou o pedido não está mais
|
|
121
|
+
* pendente — o chamador decide se nega.
|
|
122
|
+
*/
|
|
123
|
+
approve(input: {
|
|
124
|
+
userCode: string;
|
|
125
|
+
accountId: string;
|
|
126
|
+
scopes: string[];
|
|
127
|
+
}): Promise<{
|
|
128
|
+
grantId: string;
|
|
129
|
+
scopes: string[];
|
|
130
|
+
} | null>;
|
|
131
|
+
deny(input: {
|
|
132
|
+
userCode: string;
|
|
133
|
+
accountId: string;
|
|
134
|
+
}): Promise<boolean>;
|
|
135
|
+
listGrants(accountId: string): Promise<DelegationGrantSummary[]>;
|
|
136
|
+
/** Revoga na hora: tokens já emitidos param de valer na próxima request. */
|
|
137
|
+
revokeGrant(accountId: string, grantId: string): Promise<boolean>;
|
|
138
|
+
/** Revoga TODAS as delegações da conta. Devolve quantas estavam vivas. */
|
|
139
|
+
revokeAllGrants(accountId: string): Promise<number>;
|
|
140
|
+
/**
|
|
141
|
+
* Valida o header `X-A2A-User-Delegation: Bearer <token>` de uma request que
|
|
142
|
+
* JÁ passou pela verificação do JWT do agente (PACT §5.5). `null` = inválido
|
|
143
|
+
* (o chamador responde 401 `invalid_token`).
|
|
144
|
+
*/
|
|
145
|
+
verify(agent: PersonalAgentIdentity, header: string | null | undefined): Promise<DelegationContext | null>;
|
|
146
|
+
/** Recibo assinado de uma resposta servida sob delegação (PACT §5.6). */
|
|
147
|
+
receipt(delegation: DelegationContext, input: {
|
|
148
|
+
scopesUsed: string[];
|
|
149
|
+
actions?: {
|
|
150
|
+
tool: string;
|
|
151
|
+
argsHash?: string;
|
|
152
|
+
}[];
|
|
153
|
+
}): Promise<DelegationReceipt>;
|
|
154
|
+
}
|