@adonis-agora/authkit-server 1.0.0-rc.1 → 1.0.0-rc.10
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 +94 -0
- package/README.md +4 -5
- package/build/commands/agora_doctor.d.ts +22 -0
- package/build/commands/agora_doctor.js +109 -0
- package/build/commands/clients_create.d.ts +4 -0
- package/build/commands/clients_create.js +97 -0
- package/build/commands/commands.json +78 -0
- package/build/commands/doctor.js +8 -74
- package/build/host/views/account/apps.edge +1 -5
- package/build/host/views/account/extension.edge +77 -0
- package/build/host/views/account/mfa.edge +2 -0
- package/build/host/views/account/partials/extension_actions.edge +14 -0
- package/build/host/views/account/partials/extension_block.edge +197 -0
- package/build/host/views/account/partials/extension_value.edge +8 -0
- package/build/host/views/account/partials/nav.edge +14 -0
- package/build/host/views/account/security.edge +1 -5
- package/build/host/views/account/tokens.edge +2 -2
- package/build/host/views/agents/consent.edge +11 -2
- package/build/host/views/agents/done.edge +1 -1
- package/build/host/views/partials/styles.edge +1 -1
- package/build/index.d.ts +12 -12
- package/build/index.js +7 -9
- package/build/providers/authkit_server_provider.js +28 -8
- package/build/src/account/extension.d.ts +10 -0
- package/build/src/account/extension.js +9 -0
- package/build/src/account/http.d.ts +77 -0
- package/build/src/account/http.js +381 -0
- package/build/src/account/mount.d.ts +40 -0
- package/build/src/account/mount.js +171 -0
- package/build/src/account/registry.d.ts +41 -0
- package/build/src/account/registry.js +81 -0
- package/build/src/account/remote.d.ts +72 -0
- package/build/src/account/remote.js +406 -0
- package/build/src/account/runtime.d.ts +289 -0
- package/build/src/account/runtime.js +641 -0
- package/build/src/accounts/account_store.d.ts +6 -0
- package/build/src/accounts/lucid_store/organizations.js +6 -0
- package/build/src/agents/config.d.ts +9 -13
- package/build/src/agents/config.js +17 -11
- package/build/src/agents/delegation_service.js +3 -3
- package/build/src/agents/delegation_store.d.ts +3 -2
- package/build/src/agents/delegation_store.js +6 -5
- package/build/src/agents/extension.d.ts +261 -0
- package/build/src/agents/extension.js +40 -0
- package/build/src/agents/middleware.js +1 -1
- package/build/src/agents/protocol.d.ts +4 -4
- package/build/src/agents/registry_store.d.ts +3 -2
- package/build/src/agents/registry_store.js +1 -1
- package/build/src/agents/runtime.d.ts +26 -7
- package/build/src/agents/runtime.js +110 -75
- package/build/src/audit/audit_sink.d.ts +1 -1
- package/build/src/audit/audit_sink.js +10 -1
- package/build/src/console_switcher.d.ts +132 -0
- package/build/src/console_switcher.js +206 -0
- package/build/src/define_config.d.ts +34 -12
- package/build/src/define_config.js +15 -7
- package/build/src/dev_tools/contract.d.ts +72 -0
- package/build/src/dev_tools/contract.js +10 -0
- package/build/src/dev_tools/gate.d.ts +17 -0
- package/build/src/dev_tools/gate.js +69 -0
- package/build/src/dev_tools/register.d.ts +11 -0
- package/build/src/dev_tools/register.js +25 -0
- package/build/src/dev_tools/tools.d.ts +24 -0
- package/build/src/dev_tools/tools.js +384 -0
- package/build/src/doctor/agora_checks.d.ts +15 -0
- package/build/src/doctor/agora_checks.js +150 -0
- package/build/src/doctor/agora_doctor.d.ts +115 -0
- package/build/src/doctor/agora_doctor.js +692 -0
- package/build/src/doctor/doctor_input.d.ts +27 -0
- package/build/src/doctor/doctor_input.js +86 -0
- package/build/src/doctor/index.d.ts +5 -0
- package/build/src/doctor/index.js +4 -0
- package/build/src/host/access_token_verifier.js +7 -0
- package/build/src/host/account_api/account_api_controller.js +8 -6
- package/build/src/host/account_session_sign_in.d.ts +12 -0
- package/build/src/host/account_session_sign_in.js +19 -0
- package/build/src/host/admin_api/admin_users_service.d.ts +5 -2
- package/build/src/host/admin_api/api_clients_controller.d.ts +37 -0
- package/build/src/host/admin_api/api_clients_controller.js +31 -1
- package/build/src/host/admin_api/dto.d.ts +3 -1
- package/build/src/host/admin_api/dto.js +2 -0
- package/build/src/host/admin_authorize.d.ts +8 -0
- package/build/src/host/admin_authorize.js +25 -0
- package/build/src/host/admin_clients_service.d.ts +20 -0
- package/build/src/host/admin_clients_service.js +55 -0
- package/build/src/host/admin_console/admin_console_entry.d.ts +14 -0
- package/build/src/host/admin_console/admin_console_entry.js +80 -0
- package/build/src/host/admin_console/admin_shell_controller.js +8 -0
- package/build/src/host/admin_console/console_clients_controller.d.ts +41 -0
- package/build/src/host/admin_console/console_clients_controller.js +34 -1
- package/build/src/host/admin_console/console_personal_agents_controller.d.ts +1 -6
- package/build/src/host/admin_console/console_personal_agents_controller.js +50 -30
- package/build/src/host/admin_console/console_switcher_controller.d.ts +11 -0
- package/build/src/host/admin_console/console_switcher_controller.js +23 -0
- package/build/src/host/admin_sessions_service.js +8 -5
- package/build/src/host/admin_validators.d.ts +29 -0
- package/build/src/host/admin_validators.js +30 -0
- package/build/src/host/auth_host_config.d.ts +9 -2
- package/build/src/host/controllers/account_apps_controller.js +15 -11
- package/build/src/host/csrf.d.ts +3 -3
- package/build/src/host/csrf.js +3 -13
- package/build/src/host/default_mailer.d.ts +11 -6
- package/build/src/host/default_mailer.js +16 -12
- package/build/src/host/i18n.d.ts +41 -14
- package/build/src/host/i18n.js +55 -13
- package/build/src/host/rate_limit.d.ts +8 -0
- package/build/src/host/rate_limit.js +9 -0
- package/build/src/host/register_auth_host.d.ts +14 -0
- package/build/src/host/register_auth_host.js +167 -106
- package/build/src/host/renderers/edge_renderer.js +5 -0
- package/build/src/host/renderers/inertia_renderer.js +7 -1
- package/build/src/host/screen_props.d.ts +39 -8
- package/build/src/host/ui-dist/assets/index-Dq3dJVBv.js +67 -0
- package/build/src/host/ui-dist/assets/{index-DTSmD4RU.css → index-WNIyCEPA.css} +1 -1
- package/build/src/host/ui-dist/index.html +2 -2
- package/build/src/provider/build_provider.js +37 -6
- package/build/src/provider/oidc_service.d.ts +1 -1
- package/build/src/provider/oidc_service.js +1 -1
- package/build/src/schema/ensure.d.ts +14 -0
- package/build/src/schema/ensure.js +43 -150
- package/build/src/service_tenants/client_metadata.d.ts +39 -0
- package/build/src/service_tenants/client_metadata.js +80 -0
- package/build/src/service_tenants/config.d.ts +44 -0
- package/build/src/service_tenants/config.js +44 -0
- package/build/src/service_tenants/provider_hooks.d.ts +52 -0
- package/build/src/service_tenants/provider_hooks.js +124 -0
- package/build/src/service_tenants/tenant_verifier.d.ts +73 -0
- package/build/src/service_tenants/tenant_verifier.js +104 -0
- package/build/src/tenancy/tenant_labels.d.ts +30 -0
- package/build/src/tenancy/tenant_labels.js +64 -0
- package/build/types.d.ts +3 -1
- package/package.json +9 -6
- package/build/src/agents/poppy/client_registry.d.ts +0 -50
- package/build/src/agents/poppy/client_registry.js +0 -260
- package/build/src/agents/poppy/config.d.ts +0 -396
- package/build/src/agents/poppy/config.js +0 -228
- package/build/src/agents/poppy/dpop.d.ts +0 -61
- package/build/src/agents/poppy/dpop.js +0 -158
- package/build/src/agents/poppy/email_code_sign_in.d.ts +0 -27
- package/build/src/agents/poppy/email_code_sign_in.js +0 -140
- package/build/src/agents/poppy/errors.d.ts +0 -25
- package/build/src/agents/poppy/errors.js +0 -25
- package/build/src/agents/poppy/replay.d.ts +0 -25
- package/build/src/agents/poppy/replay.js +0 -106
- package/build/src/agents/poppy/resource.d.ts +0 -100
- package/build/src/agents/poppy/resource.js +0 -129
- package/build/src/agents/poppy/safe_fetch.d.ts +0 -48
- package/build/src/agents/poppy/safe_fetch.js +0 -262
- package/build/src/agents/poppy/service.d.ts +0 -293
- package/build/src/agents/poppy/service.js +0 -1458
- package/build/src/agents/poppy/session_jwt.d.ts +0 -30
- package/build/src/agents/poppy/session_jwt.js +0 -133
- package/build/src/agents/poppy/store.d.ts +0 -106
- package/build/src/agents/poppy/store.js +0 -261
- package/build/src/agents/poppy/web_session.d.ts +0 -39
- package/build/src/agents/poppy/web_session.js +0 -122
- package/build/src/host/controllers/poppy_consent_controller.d.ts +0 -19
- package/build/src/host/controllers/poppy_consent_controller.js +0 -199
- package/build/src/host/controllers/poppy_controller.d.ts +0 -33
- package/build/src/host/controllers/poppy_controller.js +0 -219
- package/build/src/host/poppy_session_key.d.ts +0 -9
- package/build/src/host/poppy_session_key.js +0 -9
- package/build/src/host/ui-dist/assets/index-D0EIeyKK.js +0 -67
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* recibos) não depende de protocolo; o formato do fio vem do adapter em
|
|
13
13
|
* `protocol` (default: PACT — https://openpactprotocol.org). Ver `protocol.ts`.
|
|
14
14
|
*/
|
|
15
|
-
import { type
|
|
15
|
+
import { type PersonalAgentExtension, type ResolvedPersonalAgentExtension } from './extension.js';
|
|
16
16
|
import { type BuiltinProtocolId, type PersonalAgentProtocol } from './protocol.js';
|
|
17
17
|
/** Registro de um personal agent conhecido (PACT §3.1). */
|
|
18
18
|
export interface PersonalAgentRegistration {
|
|
@@ -58,8 +58,8 @@ export interface PersonalAgentsConfigInput {
|
|
|
58
58
|
/**
|
|
59
59
|
* Valor que os personal agents põem no `aud` do JWT deles (PACT). Opaco e
|
|
60
60
|
* atribuído por ESTE app no registro do agente — um valor por app, não
|
|
61
|
-
* derivado de URL. Liga o PACT; obrigatório, a não ser num app
|
|
62
|
-
*
|
|
61
|
+
* derivado de URL. Liga o PACT; obrigatório, a não ser num app que só usa
|
|
62
|
+
* `extensions` (sem `audience`).
|
|
63
63
|
*/
|
|
64
64
|
audience?: string;
|
|
65
65
|
/**
|
|
@@ -79,14 +79,10 @@ export interface PersonalAgentsConfigInput {
|
|
|
79
79
|
/** Prefixo das rotas (`{prefix}/oauth/*`, `{prefix}/consent`). Default: `/agents`. */
|
|
80
80
|
prefix?: string;
|
|
81
81
|
/**
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* `poppy/config.ts`.
|
|
85
|
-
*
|
|
86
|
-
* @experimental Poppy (Personal Agent Protocol) Draft 0.3 — acompanha a spec em desenvolvimento e PODE MUDAR
|
|
87
|
-
* de forma incompatível fora de majors enquanto ela for draft.
|
|
82
|
+
* Outros protocolos de personal agents, de pacotes à parte, ao lado do PACT
|
|
83
|
+
* (ex.: `poppy()` de `@adonis-agora/authkit-poppy`). Ver {@link PersonalAgentExtension}.
|
|
88
84
|
*/
|
|
89
|
-
|
|
85
|
+
extensions?: PersonalAgentExtension[];
|
|
90
86
|
}
|
|
91
87
|
export interface ResolvedPersonalAgentDelegationConfig {
|
|
92
88
|
interfaceUrl: string;
|
|
@@ -108,11 +104,11 @@ export interface ResolvedPersonalAgentsConfig {
|
|
|
108
104
|
open: boolean;
|
|
109
105
|
delegation?: ResolvedPersonalAgentDelegationConfig;
|
|
110
106
|
prefix: string;
|
|
111
|
-
/**
|
|
112
|
-
|
|
107
|
+
/** `extensions` resolvidas, na ordem do config. */
|
|
108
|
+
extensions: ResolvedPersonalAgentExtension[];
|
|
113
109
|
}
|
|
114
110
|
export declare function normalizePersonalAgentsPrefix(prefix: string | undefined): string;
|
|
115
|
-
export declare function resolvePersonalAgentsConfig(input: PersonalAgentsConfigInput | undefined): ResolvedPersonalAgentsConfig | undefined;
|
|
111
|
+
export declare function resolvePersonalAgentsConfig(input: PersonalAgentsConfigInput | undefined, issuer?: string): ResolvedPersonalAgentsConfig | undefined;
|
|
116
112
|
/** `"a b c"` → `['a','b','c']` sem duplicatas, na ordem. */
|
|
117
113
|
export declare function parseScope(value: string | null | undefined): string[];
|
|
118
114
|
export declare function formatScope(scopes: Iterable<string>): string;
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* recibos) não depende de protocolo; o formato do fio vem do adapter em
|
|
13
13
|
* `protocol` (default: PACT — https://openpactprotocol.org). Ver `protocol.ts`.
|
|
14
14
|
*/
|
|
15
|
-
import {
|
|
15
|
+
import { resolvePersonalAgentExtensions, } from './extension.js';
|
|
16
16
|
import { BUILTIN_PROTOCOLS, } from './protocol.js';
|
|
17
17
|
const SCOPE_ID = /^[\x21\x23-\x5B\x5D-\x7E]+$/; // RFC 6749 §3.3 scope-token
|
|
18
18
|
function assertUrl(value, what) {
|
|
@@ -37,19 +37,20 @@ export function normalizePersonalAgentsPrefix(prefix) {
|
|
|
37
37
|
return '/agents';
|
|
38
38
|
return trimmed.startsWith('/') ? trimmed : `/${trimmed}`;
|
|
39
39
|
}
|
|
40
|
-
export function resolvePersonalAgentsConfig(input) {
|
|
40
|
+
export function resolvePersonalAgentsConfig(input, issuer = '') {
|
|
41
41
|
if (!input)
|
|
42
42
|
return undefined;
|
|
43
|
+
// 0.x → 1.0: o Poppy virou o pacote `@adonis-agora/authkit-poppy`.
|
|
44
|
+
if ('poppy' in input) {
|
|
45
|
+
throw new Error('authkit: `personalAgents.poppy` saiu do authkit-server — instale `@adonis-agora/authkit-poppy` e use `personalAgents.extensions: [poppy({ ... })]`.');
|
|
46
|
+
}
|
|
43
47
|
const pact = !!input.audience?.trim();
|
|
44
|
-
if (!pact && !input.
|
|
45
|
-
throw new Error('authkit: personalAgents.audience é obrigatório (o `aud` dos JWTs dos agentes PACT) — ou configure só `personalAgents.
|
|
48
|
+
if (!pact && !input.extensions?.length) {
|
|
49
|
+
throw new Error('authkit: personalAgents.audience é obrigatório (o `aud` dos JWTs dos agentes PACT) — ou configure só `personalAgents.extensions`.');
|
|
46
50
|
}
|
|
47
51
|
if (!pact && input.delegation) {
|
|
48
52
|
throw new Error('authkit: personalAgents.delegation é do PACT e exige `personalAgents.audience`.');
|
|
49
53
|
}
|
|
50
|
-
if (input.protocol === 'poppy') {
|
|
51
|
-
throw new Error('authkit: o Poppy não é um `protocol` do PACT — configure-o em `personalAgents.poppy` (os dois convivem).');
|
|
52
|
-
}
|
|
53
54
|
let resolveAgent;
|
|
54
55
|
let staticAgents = null;
|
|
55
56
|
if (typeof input.agents === 'function') {
|
|
@@ -94,9 +95,14 @@ export function resolvePersonalAgentsConfig(input) {
|
|
|
94
95
|
throw new Error(`authkit: personalAgents.protocol "${String(input.protocol)}" desconhecido (embutidos: ${Object.keys(BUILTIN_PROTOCOLS).join(', ')}).`);
|
|
95
96
|
}
|
|
96
97
|
const prefix = normalizePersonalAgentsPrefix(input.prefix);
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
const extensions = resolvePersonalAgentExtensions(input.extensions, {
|
|
99
|
+
issuer,
|
|
100
|
+
delegationScopes: input.delegation?.scopes ? { ...input.delegation.scopes } : null,
|
|
101
|
+
});
|
|
102
|
+
for (const extension of extensions) {
|
|
103
|
+
if (pact && (extension.prefix === prefix || extension.prefix.startsWith(`${prefix}/`))) {
|
|
104
|
+
throw new Error(`authkit: o prefixo "${extension.prefix}" de personalAgents.extensions "${extension.id}" não pode ficar debaixo de personalAgents.prefix ("${prefix}").`);
|
|
105
|
+
}
|
|
100
106
|
}
|
|
101
107
|
return {
|
|
102
108
|
pact,
|
|
@@ -107,7 +113,7 @@ export function resolvePersonalAgentsConfig(input) {
|
|
|
107
113
|
open: input.open === true,
|
|
108
114
|
delegation,
|
|
109
115
|
prefix,
|
|
110
|
-
|
|
116
|
+
extensions,
|
|
111
117
|
};
|
|
112
118
|
}
|
|
113
119
|
/** `"a b c"` → `['a','b','c']` sem duplicatas, na ordem. */
|
|
@@ -31,11 +31,11 @@ function newUserCode() {
|
|
|
31
31
|
return `${code.slice(0, 4)}-${code.slice(4)}`;
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
|
-
* A tabela de grants é compartilhada com
|
|
35
|
-
* o PACT só enxerga os dele
|
|
34
|
+
* A tabela de grants é compartilhada com as `personalAgents.extensions` (cada uma com o seu
|
|
35
|
+
* prefixo de id): o PACT só enxerga os dele, `agrant_`.
|
|
36
36
|
*/
|
|
37
37
|
function isPactGrant(id) {
|
|
38
|
-
return
|
|
38
|
+
return id.startsWith('agrant_');
|
|
39
39
|
}
|
|
40
40
|
/** Aceita o código como o usuário digitar: minúsculas, sem hífen, com espaços. */
|
|
41
41
|
export function normalizeUserCode(input) {
|
|
@@ -38,7 +38,8 @@ export interface GrantRow {
|
|
|
38
38
|
updatedAt: Date;
|
|
39
39
|
}
|
|
40
40
|
export interface LiveGrantFilter {
|
|
41
|
-
|
|
41
|
+
/** Só os grants com este prefixo de id (`agrant_` = PACT; o `grantIdPrefix` de uma extension). */
|
|
42
|
+
idPrefix?: string;
|
|
42
43
|
clientId?: string;
|
|
43
44
|
accountId?: string;
|
|
44
45
|
}
|
|
@@ -88,7 +89,7 @@ export declare class DelegationStore {
|
|
|
88
89
|
}): Promise<GrantRow[]>;
|
|
89
90
|
countLiveGrants(now: Date, filter?: LiveGrantFilter): Promise<number>;
|
|
90
91
|
/** Conexões vivas de um protocolo por agente: `client_id` → número de grants. */
|
|
91
|
-
countLiveGrantsByClient(now: Date,
|
|
92
|
+
countLiveGrantsByClient(now: Date, idPrefix: string): Promise<Map<string, number>>;
|
|
92
93
|
/** Ids dos grants não revogados de um agente (vivos ou não) — para revogar todos. */
|
|
93
94
|
unrevokedGrantIdsOfClient(clientId: string): Promise<string[]>;
|
|
94
95
|
/** Revoga um grant sem checar a conta — reação a reuso de refresh token. */
|
|
@@ -186,12 +186,13 @@ export class DelegationStore {
|
|
|
186
186
|
// ─── console admin (todas as contas) ──────────────────────────────────────
|
|
187
187
|
/**
|
|
188
188
|
* Grants vivos (não revogados nem expirados em `now`), de todas as contas. O
|
|
189
|
-
* protocolo sai do prefixo do id: `agrant_` (PACT) ou `
|
|
189
|
+
* protocolo sai do prefixo do id: `agrant_` (PACT) ou o `grantIdPrefix` de uma extension.
|
|
190
190
|
*/
|
|
191
191
|
#live(now, filter = {}) {
|
|
192
192
|
let q = this.conn().from(GRANT_TABLE).whereNull('revoked_at').where('expires_at', '>', now);
|
|
193
|
-
|
|
194
|
-
|
|
193
|
+
// O prefixo é `[a-z0-9]+_`: o `_` do LIKE (um caractere qualquer) casa com ele mesmo.
|
|
194
|
+
if (filter.idPrefix)
|
|
195
|
+
q = q.where('id', 'like', `${filter.idPrefix}%`);
|
|
195
196
|
if (filter.clientId)
|
|
196
197
|
q = q.where('client_id', filter.clientId);
|
|
197
198
|
if (filter.accountId)
|
|
@@ -211,8 +212,8 @@ export class DelegationStore {
|
|
|
211
212
|
return Number(row?.total ?? 0);
|
|
212
213
|
}
|
|
213
214
|
/** Conexões vivas de um protocolo por agente: `client_id` → número de grants. */
|
|
214
|
-
async countLiveGrantsByClient(now,
|
|
215
|
-
const rows = await this.#live(now, {
|
|
215
|
+
async countLiveGrantsByClient(now, idPrefix) {
|
|
216
|
+
const rows = await this.#live(now, { idPrefix })
|
|
216
217
|
.select('client_id')
|
|
217
218
|
.count('* as total')
|
|
218
219
|
.groupBy('client_id');
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Personal-agent protocol extensions — the surface another package uses to plug a personal-agent
|
|
3
|
+
* protocol into the auth host (`personalAgents.extensions` in `config/authkit.ts`).
|
|
4
|
+
*
|
|
5
|
+
* **Stable for all of 1.x.** Everything in this file follows semver: a 1.x release only adds
|
|
6
|
+
* optional members. A protocol package (such as `@adonis-agora/authkit-poppy`) can change as fast
|
|
7
|
+
* as its spec does without forcing a major here.
|
|
8
|
+
*
|
|
9
|
+
* What an extension gets:
|
|
10
|
+
*
|
|
11
|
+
* - its own routes under the auth host, with the account guard and the rate-limit buckets of the
|
|
12
|
+
* built-in screens ({@link PersonalAgentRouteKit});
|
|
13
|
+
* - a shared grant ledger (`auth_agent_grants` / `auth_agent_refresh_tokens`) scoped to its grant-id
|
|
14
|
+
* prefix, so the account console ("Connected apps"), the account API, "sign out everywhere", account
|
|
15
|
+
* deletion and the admin console list and revoke its connections with no extra code
|
|
16
|
+
* ({@link PersonalAgentGrantLedger});
|
|
17
|
+
* - the admin console's allow/block registry (`auth_agent_registry`), keyed by its protocol id;
|
|
18
|
+
* - its own lib-owned tables, created with AuthKit's (`schema.autoManage`) — {@link AuthkitTable};
|
|
19
|
+
* - access tokens minted by the OIDC provider for MCP resources ({@link PersonalAgentAccessTokens});
|
|
20
|
+
* - message catalogs merged into AuthKit's i18n (host overrides in `i18n.messages` still win).
|
|
21
|
+
*
|
|
22
|
+
* What it gives back: a {@link PersonalAgentProtocolRuntime} — list, revoke and name its
|
|
23
|
+
* connections.
|
|
24
|
+
*/
|
|
25
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
26
|
+
/**
|
|
27
|
+
* A lib-owned table: created when missing, new columns added with `ALTER ADD`, never dropped or
|
|
28
|
+
* altered. The builders receive a Knex `TableBuilder`.
|
|
29
|
+
*/
|
|
30
|
+
export interface AuthkitTable {
|
|
31
|
+
name: string;
|
|
32
|
+
/** Full builder — runs when the table does not exist. */
|
|
33
|
+
create: (table: any) => void;
|
|
34
|
+
/**
|
|
35
|
+
* One builder per column — runs (`ALTER ADD`) when the table exists but the column does not.
|
|
36
|
+
* No constraints that break on populated tables (unique/FK belong in `create`).
|
|
37
|
+
*/
|
|
38
|
+
columns: Record<string, (table: any) => void>;
|
|
39
|
+
/** Indexes ensured by name, also on tables that already existed. `create` must declare them. */
|
|
40
|
+
indexes?: Array<{
|
|
41
|
+
name: string;
|
|
42
|
+
columns: string[];
|
|
43
|
+
}>;
|
|
44
|
+
}
|
|
45
|
+
/** A row of the shared grant ledger (`auth_agent_grants`). */
|
|
46
|
+
export interface PersonalAgentGrant {
|
|
47
|
+
/** Starts with the extension's `grantIdPrefix`. */
|
|
48
|
+
id: string;
|
|
49
|
+
accountId: string;
|
|
50
|
+
/** The agent's identifier in its protocol (a PACT `iss`, a Poppy `client_id`…). */
|
|
51
|
+
clientId: string;
|
|
52
|
+
/** The agent's own user id, when the protocol has one. `''` otherwise. */
|
|
53
|
+
agentSub: string;
|
|
54
|
+
/** Space-separated scopes. */
|
|
55
|
+
scope: string;
|
|
56
|
+
expiresAt: Date;
|
|
57
|
+
revokedAt: Date | null;
|
|
58
|
+
createdAt: Date;
|
|
59
|
+
updatedAt: Date;
|
|
60
|
+
}
|
|
61
|
+
/** A refresh token of the ledger — only its hash is stored. */
|
|
62
|
+
export interface PersonalAgentRefreshToken {
|
|
63
|
+
grantId: string;
|
|
64
|
+
expiresAt: Date;
|
|
65
|
+
usedAt: Date | null;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The shared grant ledger, scoped to one extension: every read and write only sees grants whose id
|
|
69
|
+
* starts with the extension's `grantIdPrefix`. Grants written here show up in the account and admin
|
|
70
|
+
* consoles and are revoked by "sign out everywhere", password reset and account deletion.
|
|
71
|
+
*/
|
|
72
|
+
export interface PersonalAgentGrantLedger {
|
|
73
|
+
/** Throws when `grant.id` does not start with the extension's prefix. */
|
|
74
|
+
insertGrant(grant: Omit<PersonalAgentGrant, 'revokedAt'>): Promise<void>;
|
|
75
|
+
/** `null` when missing or not this extension's. */
|
|
76
|
+
findGrant(id: string): Promise<PersonalAgentGrant | null>;
|
|
77
|
+
/** Unrevoked grants of the account (expired ones included), newest first. */
|
|
78
|
+
listGrants(accountId: string): Promise<PersonalAgentGrant[]>;
|
|
79
|
+
/** Ids of the agent's unrevoked grants, across accounts. */
|
|
80
|
+
unrevokedGrantIdsOfClient(clientId: string): Promise<string[]>;
|
|
81
|
+
/** Revokes the grant (no-op when already revoked or not this extension's). */
|
|
82
|
+
revokeGrantById(id: string, at: Date): Promise<void>;
|
|
83
|
+
insertRefreshToken(token: {
|
|
84
|
+
tokenHash: string;
|
|
85
|
+
grantId: string;
|
|
86
|
+
expiresAt: Date;
|
|
87
|
+
createdAt: Date;
|
|
88
|
+
}): Promise<void>;
|
|
89
|
+
/** `null` when unknown. The caller checks the grant through {@link findGrant}. */
|
|
90
|
+
findRefreshToken(tokenHash: string): Promise<PersonalAgentRefreshToken | null>;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Access tokens of the OIDC provider for MCP resources — the same tokens AuthKit's MCP integration
|
|
94
|
+
* (`mcp` in `defineConfig`, or `Symbol.for('@adonis-agora/oauth:resources')`) already accepts.
|
|
95
|
+
*/
|
|
96
|
+
export interface PersonalAgentAccessTokens {
|
|
97
|
+
/** `mcp` is enabled in `defineConfig`. */
|
|
98
|
+
readonly mcpEnabled: boolean;
|
|
99
|
+
/** `url` is a registered MCP resource of this app. */
|
|
100
|
+
isMcpResource(url: string): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Mints an access token bound to `resource`, under a provider grant with `grantId` (created when
|
|
103
|
+
* missing). `grantType` becomes the token's `gty`. `null` when the provider is not available.
|
|
104
|
+
*/
|
|
105
|
+
mint(input: {
|
|
106
|
+
grantId: string;
|
|
107
|
+
accountId: string;
|
|
108
|
+
clientId: string;
|
|
109
|
+
scope: string;
|
|
110
|
+
resource: string;
|
|
111
|
+
/** Seconds. */
|
|
112
|
+
expiresIn: number;
|
|
113
|
+
/** When the extension's grant expires — the provider grant lives as long. */
|
|
114
|
+
grantExpiresAt: Date;
|
|
115
|
+
grantType: string;
|
|
116
|
+
}): Promise<string | null>;
|
|
117
|
+
/** Revokes the provider grant and its access tokens. */
|
|
118
|
+
revokeGrant(grantId: string): Promise<void>;
|
|
119
|
+
}
|
|
120
|
+
/** What the host hands to {@link PersonalAgentExtensionDefinition.setup}. */
|
|
121
|
+
export interface PersonalAgentHost {
|
|
122
|
+
/** The extension's protocol id. */
|
|
123
|
+
readonly protocol: string;
|
|
124
|
+
/** The OIDC issuer (`defineConfig({ issuer })`). Derive public URLs from its origin. */
|
|
125
|
+
readonly issuer: string;
|
|
126
|
+
/** The Lucid connection AuthKit's tables live on (`schema.connection`). */
|
|
127
|
+
db(): any;
|
|
128
|
+
readonly grants: PersonalAgentGrantLedger;
|
|
129
|
+
/** The admin console's verdict on an agent of this protocol. `null` = not listed. */
|
|
130
|
+
registryStatus(identifier: string): Promise<'allowed' | 'blocked' | null>;
|
|
131
|
+
/** A stable per-app secret for `label` (HMAC of the app key). Same on every instance. */
|
|
132
|
+
deriveSecret(label: string): Buffer;
|
|
133
|
+
/** The account exists and is not disabled. */
|
|
134
|
+
isAccountActive(accountId: string): Promise<boolean>;
|
|
135
|
+
/** Resolves a container binding (`'redis'`…). Throws outside an app. */
|
|
136
|
+
make(binding: string): Promise<any>;
|
|
137
|
+
readonly accessTokens: PersonalAgentAccessTokens;
|
|
138
|
+
/** The clock (tests inject one). */
|
|
139
|
+
now(): Date;
|
|
140
|
+
}
|
|
141
|
+
/** One connection of an account, as the account console and API show it. */
|
|
142
|
+
export interface PersonalAgentGrantSummary {
|
|
143
|
+
id: string;
|
|
144
|
+
clientId: string;
|
|
145
|
+
scopes: Array<{
|
|
146
|
+
id: string;
|
|
147
|
+
description: string;
|
|
148
|
+
}>;
|
|
149
|
+
createdAt: Date;
|
|
150
|
+
updatedAt: Date;
|
|
151
|
+
expiresAt: Date;
|
|
152
|
+
}
|
|
153
|
+
/** What the admin console shows about an extension. */
|
|
154
|
+
export interface PersonalAgentConsoleSummary {
|
|
155
|
+
/** Only listed agents may connect. */
|
|
156
|
+
requireRegistration: boolean;
|
|
157
|
+
/** The config's allow/block list is a function, which the console cannot list. */
|
|
158
|
+
hostResolver: boolean;
|
|
159
|
+
/** Agent identifiers may be `http://` URLs (development only). */
|
|
160
|
+
allowHttpIdentifiers: boolean;
|
|
161
|
+
/** Agents the config lists, by identifier. */
|
|
162
|
+
configured: {
|
|
163
|
+
allowed: readonly string[];
|
|
164
|
+
blocked: readonly string[];
|
|
165
|
+
};
|
|
166
|
+
/** Label of the identifier field (`'Client ID (metadata URL)'`). */
|
|
167
|
+
identifierLabel: string;
|
|
168
|
+
/** Example identifier for the field. */
|
|
169
|
+
identifierPlaceholder?: string;
|
|
170
|
+
}
|
|
171
|
+
/** The running protocol, built once per app by {@link PersonalAgentExtensionDefinition.setup}. */
|
|
172
|
+
export interface PersonalAgentProtocolRuntime {
|
|
173
|
+
/** Live connections of the account (account console and `GET /account/api/agents`). */
|
|
174
|
+
listAccountGrants(accountId: string): Promise<PersonalAgentGrantSummary[]>;
|
|
175
|
+
/** Revokes one connection OF THE ACCOUNT. `false` = not found, not the account's, or revoked. */
|
|
176
|
+
revokeAccountGrant(accountId: string, grantId: string): Promise<boolean>;
|
|
177
|
+
/** Revokes every connection of the account. Returns how many were live. */
|
|
178
|
+
revokeAllAccountGrants(accountId: string): Promise<number>;
|
|
179
|
+
/** Revokes a connection of any account (admin console). The host checked that it is live. */
|
|
180
|
+
revokeGrant(grantId: string): Promise<void>;
|
|
181
|
+
/** Disconnects an agent from every account (admin console block). Returns how many were live. */
|
|
182
|
+
disconnectAgent(identifier: string): Promise<number>;
|
|
183
|
+
/** The agent's display name. */
|
|
184
|
+
displayName(identifier: string): Promise<string>;
|
|
185
|
+
consoleSummary(): PersonalAgentConsoleSummary;
|
|
186
|
+
}
|
|
187
|
+
/** Route helpers for {@link PersonalAgentExtensionDefinition.routes}. */
|
|
188
|
+
export interface PersonalAgentRouteKit {
|
|
189
|
+
/**
|
|
190
|
+
* The account-session guard of the consent screens: a signed-out visitor goes to the login and
|
|
191
|
+
* comes back, idle sessions end, and a personal agent's own browser gets 403.
|
|
192
|
+
*/
|
|
193
|
+
accountGuard: (ctx: HttpContext, next: () => Promise<void>) => Promise<unknown>;
|
|
194
|
+
/** Rate-limit buckets of the built-in screens (no-op when `rateLimit` is off). */
|
|
195
|
+
throttle: {
|
|
196
|
+
/** Per IP, the login bucket — pages that write something without authentication. */
|
|
197
|
+
login<R>(route: R): R;
|
|
198
|
+
/** Per IP, the one-time-code bucket — screens that take a typed code. */
|
|
199
|
+
otp<R>(route: R): R;
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
/** What {@link PersonalAgentExtension.resolve} receives. */
|
|
203
|
+
export interface PersonalAgentExtensionContext {
|
|
204
|
+
/** The OIDC issuer. */
|
|
205
|
+
issuer: string;
|
|
206
|
+
/** `personalAgents.delegation.scopes`, when PACT delegation is configured. */
|
|
207
|
+
delegationScopes: Readonly<Record<string, string>> | null;
|
|
208
|
+
}
|
|
209
|
+
/** A resolved extension. */
|
|
210
|
+
export interface PersonalAgentExtensionDefinition<R extends PersonalAgentProtocolRuntime = PersonalAgentProtocolRuntime> {
|
|
211
|
+
/** Name shown in the admin console (`'Poppy'`). */
|
|
212
|
+
label: string;
|
|
213
|
+
/**
|
|
214
|
+
* Prefix of the ids of the grants it writes to the ledger (`'pgrant_'`). Ends with `_`, unique
|
|
215
|
+
* among extensions, never `agrant_` (PACT).
|
|
216
|
+
*/
|
|
217
|
+
grantIdPrefix: string;
|
|
218
|
+
/**
|
|
219
|
+
* Path prefix of its routes (`'/poppy'`). Must not sit under the OIDC `mountPath` nor under
|
|
220
|
+
* `personalAgents.prefix`.
|
|
221
|
+
*/
|
|
222
|
+
prefix: string;
|
|
223
|
+
/** Exact paths `authkitCsrfExceptions` exempts (server-to-server or cross-site POSTs). */
|
|
224
|
+
csrfExemptPaths?: readonly string[];
|
|
225
|
+
/** Lib-owned tables, ensured with AuthKit's own. */
|
|
226
|
+
tables?: readonly AuthkitTable[];
|
|
227
|
+
/** `locale → key → text`, merged under AuthKit's catalogs (host overrides win). */
|
|
228
|
+
messages?: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
229
|
+
/**
|
|
230
|
+
* The session belongs to a personal agent's browser: the account and admin consoles answer 403
|
|
231
|
+
* to it. Synchronous — reads the session only.
|
|
232
|
+
*/
|
|
233
|
+
isAgentBrowser?(ctx: HttpContext): boolean;
|
|
234
|
+
/** Runs once when the provider boots, after the config resolved. */
|
|
235
|
+
boot?(): void | Promise<void>;
|
|
236
|
+
/** Registers its routes on the app router (from `registerAuthHost`). */
|
|
237
|
+
routes?(router: any, kit: PersonalAgentRouteKit): void;
|
|
238
|
+
/** Builds the runtime — once per app, on first use. */
|
|
239
|
+
setup(host: PersonalAgentHost): Promise<R>;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* A personal-agent protocol packaged for `personalAgents.extensions`.
|
|
243
|
+
*
|
|
244
|
+
* ```ts
|
|
245
|
+
* // config/authkit.ts
|
|
246
|
+
* import { poppy } from '@adonis-agora/authkit-poppy'
|
|
247
|
+
* personalAgents: { extensions: [poppy({ organization: { name: 'Shop', domain: 'shop.example' } })] }
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
export interface PersonalAgentExtension<R extends PersonalAgentProtocolRuntime = PersonalAgentProtocolRuntime> {
|
|
251
|
+
/** Protocol id: 2–16 characters of `a-z`, `0-9`, `-`. Never `pact`. */
|
|
252
|
+
readonly id: string;
|
|
253
|
+
/** Validates the extension's own config and resolves it. Runs when `defineConfig` resolves. */
|
|
254
|
+
resolve(context: PersonalAgentExtensionContext): PersonalAgentExtensionDefinition<R>;
|
|
255
|
+
}
|
|
256
|
+
/** A resolved extension, with its id. */
|
|
257
|
+
export type ResolvedPersonalAgentExtension = PersonalAgentExtensionDefinition & {
|
|
258
|
+
readonly id: string;
|
|
259
|
+
};
|
|
260
|
+
/** Resolves and validates `personalAgents.extensions`. */
|
|
261
|
+
export declare function resolvePersonalAgentExtensions(input: readonly PersonalAgentExtension[] | undefined, context: PersonalAgentExtensionContext): ResolvedPersonalAgentExtension[];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const EXTENSION_ID = /^[a-z0-9-]{2,16}$/;
|
|
2
|
+
const GRANT_PREFIX = /^[a-z0-9]+_$/;
|
|
3
|
+
function normalizePrefix(prefix, id) {
|
|
4
|
+
const trimmed = (prefix ?? '').trim().replace(/\/+$/, '');
|
|
5
|
+
if (!trimmed || trimmed === '/') {
|
|
6
|
+
throw new Error(`authkit: personalAgents.extensions "${id}" — prefix is required.`);
|
|
7
|
+
}
|
|
8
|
+
return trimmed.startsWith('/') ? trimmed : `/${trimmed}`;
|
|
9
|
+
}
|
|
10
|
+
/** Resolves and validates `personalAgents.extensions`. */
|
|
11
|
+
export function resolvePersonalAgentExtensions(input, context) {
|
|
12
|
+
const out = [];
|
|
13
|
+
for (const extension of input ?? []) {
|
|
14
|
+
const id = extension?.id;
|
|
15
|
+
if (typeof id !== 'string' || !EXTENSION_ID.test(id) || id === 'pact') {
|
|
16
|
+
throw new Error(`authkit: personalAgents.extensions — invalid id "${String(id)}" (2–16 of a-z, 0-9, -; not "pact").`);
|
|
17
|
+
}
|
|
18
|
+
if (out.some((e) => e.id === id)) {
|
|
19
|
+
throw new Error(`authkit: personalAgents.extensions — "${id}" is listed twice.`);
|
|
20
|
+
}
|
|
21
|
+
const definition = extension.resolve(context);
|
|
22
|
+
if (!GRANT_PREFIX.test(definition.grantIdPrefix) || definition.grantIdPrefix === 'agrant_') {
|
|
23
|
+
throw new Error(`authkit: personalAgents.extensions "${id}" — invalid grantIdPrefix "${definition.grantIdPrefix}".`);
|
|
24
|
+
}
|
|
25
|
+
if (out.some((e) => e.grantIdPrefix === definition.grantIdPrefix)) {
|
|
26
|
+
throw new Error(`authkit: personalAgents.extensions "${id}" — grantIdPrefix "${definition.grantIdPrefix}" is already taken.`);
|
|
27
|
+
}
|
|
28
|
+
const prefix = normalizePrefix(definition.prefix, id);
|
|
29
|
+
for (const other of out) {
|
|
30
|
+
if (other.prefix === prefix ||
|
|
31
|
+
other.prefix.startsWith(`${prefix}/`) ||
|
|
32
|
+
prefix.startsWith(`${other.prefix}/`)) {
|
|
33
|
+
throw new Error(`authkit: personalAgents.extensions "${id}" — prefix "${prefix}" overlaps "${other.id}" ("${other.prefix}").`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// A plain object literal: its own members are the definition.
|
|
37
|
+
out.push({ ...definition, id, prefix });
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
@@ -40,7 +40,7 @@ export function personalAgentAuth(options = {}) {
|
|
|
40
40
|
const mode = options.delegation ?? 'optional';
|
|
41
41
|
return async (ctx, next) => {
|
|
42
42
|
const runtime = await personalAgentsFor(ctx);
|
|
43
|
-
// Sem PACT (app
|
|
43
|
+
// Sem PACT (app só com extensions) não há JWT de agente para verificar.
|
|
44
44
|
if (!runtime?.config.pact)
|
|
45
45
|
return ctx.response.notFound();
|
|
46
46
|
const { protocol } = runtime.config;
|
|
@@ -10,10 +10,10 @@ import type { DelegationReceipt } from './delegation_service.js';
|
|
|
10
10
|
* MESMA família (JWT do agente + token de delegação) entra como mais um objeto
|
|
11
11
|
* desta interface, passado direto em `personalAgents.protocol`.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
13
|
+
* Um protocolo de outro modelo (ex.: um authorization server OAuth próprio, como o
|
|
14
|
+
* Personal Agent Protocol de `@adonis-agora/authkit-poppy`) não é um adapter daqui:
|
|
15
|
+
* liga-se em `personalAgents.extensions` (ver `extension.ts`), ao lado do PACT,
|
|
16
|
+
* reaproveitando o núcleo de grants.
|
|
17
17
|
*/
|
|
18
18
|
export interface PersonalAgentProtocol {
|
|
19
19
|
/** Identificador estável (`'pact'`). */
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export declare const REGISTRY_TABLE = "auth_agent_registry";
|
|
2
|
-
|
|
2
|
+
/** `'pact'` ou o id de uma extension (`personalAgents.extensions`). */
|
|
3
|
+
export type AgentProtocolId = 'pact' | (string & {});
|
|
3
4
|
export type AgentRegistryStatus = 'allowed' | 'blocked';
|
|
4
5
|
export interface AgentRegistryRow {
|
|
5
6
|
id: string;
|
|
6
7
|
protocol: AgentProtocolId;
|
|
7
|
-
/** PACT: o `iss` do agente.
|
|
8
|
+
/** PACT: o `iss` do agente. Extensions: o identificador do agente no protocolo delas. */
|
|
8
9
|
identifier: string;
|
|
9
10
|
status: AgentRegistryStatus;
|
|
10
11
|
name: string | null;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* `auth_agent_registry` (ver `schema/ensure.ts`). SOMA ao `defineConfig`:
|
|
4
4
|
*
|
|
5
5
|
* - `allowed`: o agente entra mesmo fora da lista do config (PACT: issuer + JWKS;
|
|
6
|
-
*
|
|
6
|
+
* extensions: o identificador do agente no protocolo delas).
|
|
7
7
|
* - `blocked`: o agente é recusado mesmo que o config o liste — bloquear é a
|
|
8
8
|
* ação de emergência, e precisa valer sem deploy.
|
|
9
9
|
*
|
|
@@ -4,8 +4,7 @@ import { PersonalAgentVerifier } from './agent_identity.js';
|
|
|
4
4
|
import type { ResolvedPersonalAgentsConfig } from './config.js';
|
|
5
5
|
import { PersonalAgentDelegation } from './delegation_service.js';
|
|
6
6
|
import { DelegationStore, type GrantRow } from './delegation_store.js';
|
|
7
|
-
import type {
|
|
8
|
-
import { PoppyService } from './poppy/service.js';
|
|
7
|
+
import type { PersonalAgentProtocolRuntime, ResolvedPersonalAgentExtension } from './extension.js';
|
|
9
8
|
import { type AgentProtocolId, AgentRegistryStore } from './registry_store.js';
|
|
10
9
|
/** URLs públicas do authorization server de delegação. */
|
|
11
10
|
export interface PersonalAgentUrls {
|
|
@@ -31,9 +30,15 @@ export interface PersonalAgentsRuntime {
|
|
|
31
30
|
verifier: PersonalAgentVerifier;
|
|
32
31
|
/** `null` quando o app não configurou `personalAgents.delegation`. */
|
|
33
32
|
delegation: PersonalAgentDelegation | null;
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Runtimes de `personalAgents.extensions`, por id do protocolo. Vazio sem extensions ou sem
|
|
35
|
+
* banco.
|
|
36
|
+
*/
|
|
37
|
+
extensions: Map<string, {
|
|
38
|
+
extension: ResolvedPersonalAgentExtension;
|
|
39
|
+
runtime: PersonalAgentProtocolRuntime;
|
|
40
|
+
}>;
|
|
41
|
+
/** Revoga um grant de personal agent DA CONTA (PACT ou de uma extension). */
|
|
37
42
|
revokeAgentGrant(accountId: string, grantId: string): Promise<boolean>;
|
|
38
43
|
/** Revoga todos os grants de personal agents da conta. Devolve quantos estavam vivos. */
|
|
39
44
|
revokeAllAgentGrants(accountId: string): Promise<number>;
|
|
@@ -52,8 +57,6 @@ export interface PersonalAgentsRuntime {
|
|
|
52
57
|
export interface BuildPersonalAgentsOptions {
|
|
53
58
|
/** Resolve serviços do container (redis do replay store). */
|
|
54
59
|
make?: (binding: string) => Promise<any>;
|
|
55
|
-
/** Busca de JSON (metadata/JWKS dos agentes Poppy) — injetável nos testes. */
|
|
56
|
-
fetchJson?: JsonFetcher;
|
|
57
60
|
now?: () => Date;
|
|
58
61
|
}
|
|
59
62
|
/**
|
|
@@ -63,3 +66,19 @@ export interface BuildPersonalAgentsOptions {
|
|
|
63
66
|
export declare function buildPersonalAgentsRuntime(service: OidcService, makeDb: () => Promise<any>, options?: BuildPersonalAgentsOptions): Promise<PersonalAgentsRuntime | null>;
|
|
64
67
|
/** Runtime a partir de uma request. */
|
|
65
68
|
export declare function personalAgentsFor(ctx: HttpContext): Promise<PersonalAgentsRuntime | null>;
|
|
69
|
+
/** Where {@link personalAgentExtensionRuntime} builds the runtime from, outside a request. */
|
|
70
|
+
export interface PersonalAgentRuntimeSource {
|
|
71
|
+
service: OidcService;
|
|
72
|
+
/** The Lucid `Database` (the `lucid.db` binding). */
|
|
73
|
+
db(): Promise<unknown>;
|
|
74
|
+
make?(binding: string): Promise<unknown>;
|
|
75
|
+
now?(): Date;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The runtime an extension's `setup` built (`personalAgents.extensions`), by protocol id. `null`
|
|
79
|
+
* when the extension is not configured (or there is no database). Takes the request, an explicit
|
|
80
|
+
* source (tests, scripts) or nothing (the booted app).
|
|
81
|
+
*
|
|
82
|
+
* Stable for 1.x — see `extension.ts`.
|
|
83
|
+
*/
|
|
84
|
+
export declare function personalAgentExtensionRuntime<R extends PersonalAgentProtocolRuntime = PersonalAgentProtocolRuntime>(id: string, from?: HttpContext | PersonalAgentRuntimeSource): Promise<R | null>;
|