@jini-ai/core 0.6.22 → 0.7.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/CHANGELOG.md +24 -0
- package/dist/approval.d.ts +49 -3
- package/dist/approval.js +47 -10
- package/dist/batch-tool-inputs.d.ts +13 -0
- package/dist/batch-tool-inputs.js +37 -6
- package/dist/contracts/cards.d.ts +382 -0
- package/dist/contracts/cards.js +2 -0
- package/dist/contracts/content-types.d.ts +32 -0
- package/dist/contracts/content-types.js +3 -0
- package/dist/contracts/credentials.d.ts +402 -0
- package/dist/contracts/credentials.js +2 -0
- package/dist/contracts/hosted-mcp/config.d.ts +253 -0
- package/dist/contracts/hosted-mcp/config.js +2 -0
- package/dist/contracts/hosted-mcp/record.d.ts +198 -0
- package/dist/contracts/hosted-mcp/record.js +2 -0
- package/dist/contracts/hosted-mcp/vocabulary.d.ts +14 -0
- package/dist/contracts/hosted-mcp/vocabulary.js +2 -0
- package/dist/contracts/hosted-mcp.d.ts +5 -0
- package/dist/contracts/hosted-mcp.js +2 -0
- package/dist/contracts/mail/adapter-module.d.ts +31 -0
- package/dist/contracts/mail/adapter-module.js +2 -0
- package/dist/contracts/mail/engine-contracts.d.ts +130 -0
- package/dist/contracts/mail/engine-contracts.js +2 -0
- package/dist/contracts/mail/ports.d.ts +93 -0
- package/dist/contracts/mail/ports.js +3 -0
- package/dist/contracts/mail/provider.d.ts +84 -0
- package/dist/contracts/mail/provider.js +2 -0
- package/dist/contracts/mail.d.ts +128 -0
- package/dist/contracts/mail.js +3 -0
- package/dist/contracts/oauth/details.d.ts +46 -0
- package/dist/contracts/oauth/details.js +2 -0
- package/dist/contracts/oauth/flow.d.ts +253 -0
- package/dist/contracts/oauth/flow.js +2 -0
- package/dist/contracts/oauth.d.ts +139 -0
- package/dist/contracts/oauth.js +2 -0
- package/dist/contracts/vault/ports.d.ts +34 -0
- package/dist/contracts/vault/ports.js +2 -0
- package/dist/contracts/vault/records.d.ts +149 -0
- package/dist/contracts/vault/records.js +2 -0
- package/dist/contracts/vault/vendor-credential-sets.d.ts +75 -0
- package/dist/contracts/vault/vendor-credential-sets.js +7 -0
- package/dist/contracts/vault.d.ts +14 -0
- package/dist/contracts/vault.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/primitives/http.d.ts +2 -0
- package/dist/settings/agent-value-write-tools.d.ts +3 -1
- package/dist/settings/agent-value-write-tools.js +11 -4
- package/dist/settings/tool-registrations.js +1 -1
- package/dist/surface-cards.d.ts +2 -0
- package/dist/surface-cards.js +2 -0
- package/dist/teardown.d.ts +30 -0
- package/dist/teardown.js +43 -0
- package/dist/text/descriptor-i18n.d.ts +24 -0
- package/dist/text/descriptor-i18n.js +65 -0
- package/dist/text/index.d.ts +2 -0
- package/dist/text/index.js +1 -0
- package/dist/tool-metadata-types.d.ts +6 -0
- package/dist/user-facing-error.d.ts +28 -1
- package/dist/user-facing-error.js +87 -4
- package/package.json +44 -2
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/** @agent-note Types only. The runtime parts come from the host; this area usually from `@jini-ai/mcp/federation/hosted` (values) and `@jini-ai/integrations/api-connections/hosted-mcp` (sign-in). */
|
|
2
|
+
import type { Clock as ClockPort, ISODateTime } from '../../primitives/time.js';
|
|
3
|
+
import type { UUID } from '../../primitives/ids.js';
|
|
4
|
+
import type { KeyringPort, SealedSecret, SecretSealerPort } from '../vault.js';
|
|
5
|
+
/** Exact source identity and prior access decision captured before an access-only update; no credential bytes. */
|
|
6
|
+
/** @agent-note Built only by `externalMcpAccessSnapshot` from the row the host just read; compared field-for-field by the repo's `updateAccessIfCurrent`. Contains no credential bytes; `admissionRevision` is the sha256 hex of the row's source identity. */
|
|
7
|
+
export interface ExternalMcpAccessSnapshot {
|
|
8
|
+
readonly admissionRevision: string;
|
|
9
|
+
readonly enabled: boolean;
|
|
10
|
+
readonly allowedToolNames: string | null;
|
|
11
|
+
readonly writeAllowedToolNames: string | null;
|
|
12
|
+
readonly writeGrantsUpdatedByPrincipalId: string | null;
|
|
13
|
+
readonly writeGrantsUpdatedAt: ISODateTime | null;
|
|
14
|
+
readonly provisionedByPluginId: string | null;
|
|
15
|
+
}
|
|
16
|
+
/** The access-only command accepted by the owner after a bound human approval. */
|
|
17
|
+
/** @agent-note The access-only command a host accepts after a bound human approval; `expected` must be the snapshot captured before the approval was shown, never re-read after. */
|
|
18
|
+
export interface ExternalMcpApprovedAccess {
|
|
19
|
+
readonly workspaceId: string;
|
|
20
|
+
readonly serverId: string;
|
|
21
|
+
readonly expected: ExternalMcpAccessSnapshot;
|
|
22
|
+
readonly access: {
|
|
23
|
+
readonly enabled: boolean;
|
|
24
|
+
readonly allowedToolNames: readonly string[];
|
|
25
|
+
readonly writeAllowedToolNames: readonly string[];
|
|
26
|
+
};
|
|
27
|
+
readonly principalId: string;
|
|
28
|
+
}
|
|
29
|
+
/** @agent-note The ONE canonical saved row. Fulfilled by the host's repository (SQL or memory). Field names, `null`s, sealed envelopes and plain-text JSON columns are the saved format: never normalize, reseal or rename on read; writes keep serialization/AAD/ids. `transport`/`authMode`/`oauthGrant`/`oauthStatus` stay `string` so unknown saved values load. Never copy this shape into a host type. */
|
|
30
|
+
export interface ExternalMcpServerRecord {
|
|
31
|
+
workspaceId: UUID;
|
|
32
|
+
serverId: string;
|
|
33
|
+
label: string | null;
|
|
34
|
+
/** The Agent Plugin id that auto-provisioned this row, or `null` for an operator-created one.
|
|
35
|
+
* @agent-note Only the trusted plugin provisioner sets this on creation; subsequent saves preserve it and never clear it. */
|
|
36
|
+
provisionedByPluginId: string | null;
|
|
37
|
+
transport: string;
|
|
38
|
+
/** How credentials are obtained. Independent of `transport` — see this file's header. */
|
|
39
|
+
authMode: string;
|
|
40
|
+
enabled: boolean;
|
|
41
|
+
command: string | null;
|
|
42
|
+
/** Endpoint for a remote transport. NULL for `stdio`, where `command` is used instead. */
|
|
43
|
+
url: string | null;
|
|
44
|
+
/** JSON array of argv strings, as stored. */
|
|
45
|
+
args: string | null;
|
|
46
|
+
/** JSON array of admissible remote tool names, as stored. */
|
|
47
|
+
allowedToolNames: string | null;
|
|
48
|
+
/**
|
|
49
|
+
* JSON array of remote tool names separately authorized to write, as stored. `trust.ts` R3's
|
|
50
|
+
* override — a tool declaring `readOnlyHint: false` is admitted only when it also appears in
|
|
51
|
+
* {@link allowedToolNames}. See `@jini-ai/mcp/federation`'s `FederatedMcpConnectionConfig
|
|
52
|
+
* .writeAllowedToolNames` for the full argument.
|
|
53
|
+
*/
|
|
54
|
+
writeAllowedToolNames: string | null;
|
|
55
|
+
/** Principal who last CHANGED {@link writeAllowedToolNames}'s contents. `null` until that list is
|
|
56
|
+
* ever touched, or for a row written before this column existed. */
|
|
57
|
+
writeGrantsUpdatedByPrincipalId: string | null;
|
|
58
|
+
/** When {@link writeAllowedToolNames} was last changed. `null` under the same condition. */
|
|
59
|
+
writeGrantsUpdatedAt: ISODateTime | null;
|
|
60
|
+
/** JSON array of env variable names, as stored. Plaintext by design. */
|
|
61
|
+
envNames: string | null;
|
|
62
|
+
sealedEnv: SealedSecret | null;
|
|
63
|
+
/** Which registered provider descriptor this connection authorizes against. */
|
|
64
|
+
oauthProviderId: string | null;
|
|
65
|
+
oauthGrant: string | null;
|
|
66
|
+
/** Plaintext: a client id is not a secret — it travels in the authorization URL by design. */
|
|
67
|
+
oauthClientId: string | null;
|
|
68
|
+
/** JSON object of operator-typed endpoints, when this connection defines its own provider instead
|
|
69
|
+
* of naming a registered one. Non-secret. */
|
|
70
|
+
oauthEndpointsJson: string | null;
|
|
71
|
+
/** JSON array of requested scopes. Non-secret. */
|
|
72
|
+
oauthScopesJson: string | null;
|
|
73
|
+
oauthStatus: string | null;
|
|
74
|
+
/**
|
|
75
|
+
* PLAINTEXT absolute expiry of the stored access token, beside the sealed blob rather than inside
|
|
76
|
+
* it. Exactly the split this file already makes for `envNames` beside `sealedEnv`, and here it is
|
|
77
|
+
* load-bearing rather than merely convenient: expiry has to be checkable by a scheduler and
|
|
78
|
+
* displayable in the admin tab, and neither can afford a keyring round trip — nor should either be
|
|
79
|
+
* a code path that decrypts a live token to answer a question about when it dies.
|
|
80
|
+
*/
|
|
81
|
+
oauthExpiresAt: ISODateTime | null;
|
|
82
|
+
/**
|
|
83
|
+
* For `stdio` + `oauth`: which child-process environment variable receives the access token.
|
|
84
|
+
* Plaintext because it is a NAME, exactly as `envNames` is.
|
|
85
|
+
*/
|
|
86
|
+
oauthTokenEnvName: string | null;
|
|
87
|
+
/**
|
|
88
|
+
* Cross-process refresh lease. Held while one process is redeeming the refresh token, so the other
|
|
89
|
+
* — the admin web server and the agent daemon are separate processes with separate database
|
|
90
|
+
* handles — does not redeem the same single-use rotating token. Plaintext for the same reason as
|
|
91
|
+
* `oauthExpiresAt`: a lease you must decrypt to inspect is a lease you cannot break after a crash.
|
|
92
|
+
*/
|
|
93
|
+
oauthRefreshLeaseUntil: ISODateTime | null;
|
|
94
|
+
/** Sealed `{ clientSecret?, tokens? }`.
|
|
95
|
+
* @agent-note Writers must open, update and reseal the whole payload, preserving members they did not explicitly change or clear; writing tokens alone would erase the client secret. */
|
|
96
|
+
sealedOAuth: SealedSecret | null;
|
|
97
|
+
/** Compatibility read field; normalized vault envelopes use lineage 1. */
|
|
98
|
+
aadVersion: number;
|
|
99
|
+
/** Compatibility read field; actual authenticated context lives on the vault row. */
|
|
100
|
+
oauthAadVersion: number;
|
|
101
|
+
createdAt: ISODateTime;
|
|
102
|
+
updatedAt: ISODateTime;
|
|
103
|
+
}
|
|
104
|
+
/** A conditional access-only write. Credential and connection configuration are never replaced. */
|
|
105
|
+
/** @agent-note Built by the host from an `ExternalMcpApprovedAccess`; the repository applies it atomically or returns `false`. Credential and connection columns are never part of it. */
|
|
106
|
+
export interface ExternalMcpAccessUpdate {
|
|
107
|
+
readonly workspaceId: UUID;
|
|
108
|
+
readonly serverId: string;
|
|
109
|
+
readonly expected: ExternalMcpAccessSnapshot;
|
|
110
|
+
readonly access: {
|
|
111
|
+
readonly enabled: boolean;
|
|
112
|
+
readonly allowedToolNames: string;
|
|
113
|
+
readonly writeAllowedToolNames: string;
|
|
114
|
+
};
|
|
115
|
+
readonly principalId: string;
|
|
116
|
+
readonly nowIso: ISODateTime;
|
|
117
|
+
}
|
|
118
|
+
/** Workspace-scoped persistence. Multi-row per workspace, so list/upsert/delete rather
|
|
119
|
+
* than a single-row find/upsert. */
|
|
120
|
+
/** @agent-note Fulfilled by the host (SQL or memory adapter). The store, the sign-in service and the plugin connect seam must receive the SAME repository instance, because sealed envelopes carry private repository context only that repository rebuilds. */
|
|
121
|
+
export interface ExternalMcpServerRepoPort {
|
|
122
|
+
/** @agent-note Workspace-scoped; returns whole saved rows, never views. */
|
|
123
|
+
listByWorkspaceId(workspaceId: UUID): Promise<ExternalMcpServerRecord[]>;
|
|
124
|
+
/** @agent-note Returns the whole saved row or `null`; at most one row read per call. */
|
|
125
|
+
findByServerId(input: {
|
|
126
|
+
workspaceId: UUID;
|
|
127
|
+
serverId: string;
|
|
128
|
+
}): Promise<ExternalMcpServerRecord | null>;
|
|
129
|
+
/** @agent-note Writes the whole row in one transaction (row, vault pointer, status and expiry together). */
|
|
130
|
+
upsert(record: ExternalMcpServerRecord): Promise<void>;
|
|
131
|
+
/** Compare the approved snapshot and update access atomically, preserving credential columns. */
|
|
132
|
+
/** @agent-note Compare-and-set against `expected`; `false` means the row changed since approval and nothing was written. */
|
|
133
|
+
updateAccessIfCurrent(required: ExternalMcpAccessUpdate, optional?: Record<string, never>): Promise<boolean>;
|
|
134
|
+
/** @agent-note Returns whether a row existed. */
|
|
135
|
+
deleteByServerId(input: {
|
|
136
|
+
workspaceId: UUID;
|
|
137
|
+
serverId: string;
|
|
138
|
+
}): Promise<boolean>;
|
|
139
|
+
/**
|
|
140
|
+
* Atomically claims the OAuth refresh lease for one row, iff nobody holds an unexpired one.
|
|
141
|
+
*
|
|
142
|
+
* A COMPARE-AND-SET, not a read-then-write, and that is the entire point: `upsert` cannot express
|
|
143
|
+
* it, because between reading "no lease" and writing "my lease" the other process does the same
|
|
144
|
+
* and both go on to redeem the same single-use rotating refresh token. One statement with the
|
|
145
|
+
* condition in its `WHERE` is what makes the loser observable.
|
|
146
|
+
*
|
|
147
|
+
* @returns `true` when this caller now holds the lease.
|
|
148
|
+
*/
|
|
149
|
+
/** @agent-note Compare-and-set in one statement; only the caller that gets `true` may redeem the refresh token. */
|
|
150
|
+
tryClaimOAuthRefreshLease(input: {
|
|
151
|
+
workspaceId: UUID;
|
|
152
|
+
serverId: string;
|
|
153
|
+
/** Now, per the caller's clock. A lease at or before this instant is treated as abandoned. */
|
|
154
|
+
nowIso: ISODateTime;
|
|
155
|
+
/** When this claim expires, so a crashed holder cannot wedge the connection forever. */
|
|
156
|
+
leaseUntil: ISODateTime;
|
|
157
|
+
}): Promise<boolean>;
|
|
158
|
+
/** Releases the lease unconditionally. Safe when not held — the lease is advisory and
|
|
159
|
+
* time-bounded, so a spurious release costs at most one extra refresh attempt. */
|
|
160
|
+
/** @agent-note Unconditional and idempotent; call after every claimed refresh, success or failure. */
|
|
161
|
+
releaseOAuthRefreshLease(input: {
|
|
162
|
+
workspaceId: UUID;
|
|
163
|
+
serverId: string;
|
|
164
|
+
}): Promise<void>;
|
|
165
|
+
}
|
|
166
|
+
/** @agent-note Host-wired: `repo` is the same instance the sign-in service gets; `sealer`/`keyring` usually from `@jini-ai/platform/secrets`; `clock` from the host. */
|
|
167
|
+
export interface ExternalMcpStoreDeps {
|
|
168
|
+
repo: ExternalMcpServerRepoPort;
|
|
169
|
+
sealer: SecretSealerPort;
|
|
170
|
+
keyring: KeyringPort;
|
|
171
|
+
clock: ClockPort;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Resolves an `oauth` row's contribution to the child environment.
|
|
175
|
+
*
|
|
176
|
+
* Kept behind a port rather than inlined, so this store never imports a token endpoint, a refresher,
|
|
177
|
+
* or an OAuth implementation at all: the boot path asks for a token, and whoever wired the daemon decides where
|
|
178
|
+
* it comes from. That is also what keeps this module testable without a network.
|
|
179
|
+
*/
|
|
180
|
+
/** @agent-note Fulfilled by the sign-in service's `tokenResolver`; the store calls it once per OAuth row read and never imports OAuth itself. */
|
|
181
|
+
export interface ExternalMcpOAuthTokenResolverPort {
|
|
182
|
+
/** Undefined identifies an existing local connection. Shared failures must throw, never fall back. */
|
|
183
|
+
/** @agent-note Optional; a shared-binding failure throws and never falls back to a local token. */
|
|
184
|
+
resolveSharedAccessToken?(input: {
|
|
185
|
+
serverId: string;
|
|
186
|
+
}): Promise<string | undefined>;
|
|
187
|
+
/**
|
|
188
|
+
* Returns the access token to inject, refreshing first when it is due.
|
|
189
|
+
*
|
|
190
|
+
* @throws When the connection needs re-authorization or the provider could not be reached. The
|
|
191
|
+
* caller turns that into a per-server failure entry rather than letting it abort the whole read.
|
|
192
|
+
*/
|
|
193
|
+
/** @agent-note At most one leased refresh per call; throws a terminal error when re-authorization is needed. */
|
|
194
|
+
resolveAccessToken(input: {
|
|
195
|
+
serverId: string;
|
|
196
|
+
}): Promise<string>;
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=record.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** @agent-note Types only. The runtime parts come from the host; this area usually from `@jini-ai/mcp/federation/hosted` (values) and `@jini-ai/integrations/api-connections/hosted-mcp` (sign-in). */
|
|
2
|
+
/** @agent-note Saved as plain text in the row's `transport`; the record keeps `string` so an unknown saved value still loads. Runtime tuple: `SUPPORTED_EXTERNAL_MCP_TRANSPORTS` (`@jini-ai/mcp/federation/hosted`). Never rename a literal: saved rows and admission revisions carry it. */
|
|
3
|
+
export type ExternalMcpTransport = "stdio" | "streamable_http";
|
|
4
|
+
/** @agent-note Saved in `oauthGrant` as plain text (RFC 6749/8628 grant names). Runtime tuple: `EXTERNAL_MCP_OAUTH_GRANTS`. Never rename a literal. */
|
|
5
|
+
export type ExternalMcpOAuthGrant = "authorization_code" | "device_code";
|
|
6
|
+
/** @agent-note Saved in `authMode`; readers default an absent/unknown value to `static_env` via `resolveExternalMcpAuthMode` (host-wired from `@jini-ai/mcp/federation/hosted`). Part of the admission-revision hash input, so never rename a literal. */
|
|
7
|
+
export type ExternalMcpAuthMode = "none" | "static_env" | "oauth";
|
|
8
|
+
/** @agent-note Saved in `oauthStatus`; readers default an absent/unknown value to `disconnected` via `resolveExternalMcpOAuthStatus`. Never rename a literal. */
|
|
9
|
+
export type ExternalMcpOAuthStatus = "disconnected" | "pending" | "connected" | "needs_reauth";
|
|
10
|
+
/** Why an admitted federated tool is refused on THIS call. Every value pairs with one D3 message in
|
|
11
|
+
* {@link revocationMessage} — see that lookup for the exact, test-pinned wording. */
|
|
12
|
+
/** @agent-note Each value keys exactly one host-supplied refusal message; the host owns the wording and its tests pin it. Adding a value requires every host message table to add one. */
|
|
13
|
+
export type ExternalMcpRevocationReason = "removed" | "turned-off" | "disconnected" | "changed" | "tool-not-allowed" | "write-not-allowed" | "unverifiable";
|
|
14
|
+
//# sourceMappingURL=vocabulary.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** @agent-note Types only. The runtime parts come from the host; this area usually from `@jini-ai/mcp/federation/hosted` (values) and `@jini-ai/integrations/api-connections/hosted-mcp` (sign-in). */
|
|
2
|
+
export type * from './hosted-mcp/vocabulary.js';
|
|
3
|
+
export type * from './hosted-mcp/record.js';
|
|
4
|
+
export type * from './hosted-mcp/config.js';
|
|
5
|
+
//# sourceMappingURL=hosted-mcp.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { HttpClientPort } from '../../primitives/index.js';
|
|
2
|
+
import type { MailerPort } from './ports.js';
|
|
3
|
+
/** @agent-note Types only. The runtime parts come from the host; this area usually from `@jini-ai/platform`. */
|
|
4
|
+
export interface MailAdapterCredential {
|
|
5
|
+
readonly token: string;
|
|
6
|
+
readonly baseUrl?: string;
|
|
7
|
+
readonly username?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface MailAdapterKit {
|
|
10
|
+
/** Provider requests must use the guarded outbound HTTP seam so its egress policy applies. */
|
|
11
|
+
readonly httpClient: HttpClientPort;
|
|
12
|
+
}
|
|
13
|
+
export interface MailAdapterCreateContext {
|
|
14
|
+
readonly credential: MailAdapterCredential;
|
|
15
|
+
readonly kit: MailAdapterKit;
|
|
16
|
+
/** Sample at the point of use. Hosts normalize this to the real clock when omitted. */
|
|
17
|
+
readonly now?: () => Date;
|
|
18
|
+
/** Per-install configuration; only the provider module owns its schema and validation. */
|
|
19
|
+
readonly settings?: unknown;
|
|
20
|
+
}
|
|
21
|
+
/** Provider modules return the ordinary mail port; the shared contract names no vendor. */
|
|
22
|
+
export interface MailAdapterModule {
|
|
23
|
+
/** Optional host-resolved account connection for domain reads only. The host validates the
|
|
24
|
+
* HTTPS origin and plugin ownership; this credential must never replace the sending key. */
|
|
25
|
+
readonly domainReadConnection?: {
|
|
26
|
+
readonly serverId: string;
|
|
27
|
+
readonly baseUrl: string;
|
|
28
|
+
};
|
|
29
|
+
create(context: MailAdapterCreateContext): MailerPort;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=adapter-module.d.ts.map
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/** @agent-note Types only. The runtime parts come from the host; this area usually from `@jini-ai/platform`. */
|
|
2
|
+
import type { MailAdapterCredential } from "./adapter-module.js";
|
|
3
|
+
import type { MailDomainState, MailProviderCapabilities, MailProviderRegistry, MailProviderSetting, MailStatus } from "./provider.js";
|
|
4
|
+
/** Metadata only: the host reads these facts before decrypting a credential. */
|
|
5
|
+
export interface MailCredentialFact {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly label: string;
|
|
8
|
+
readonly vaultRevision?: number;
|
|
9
|
+
readonly updatedAt: string;
|
|
10
|
+
}
|
|
11
|
+
/** Credential presence exposed in configuration reports; never a token or username. */
|
|
12
|
+
export interface MailProviderCredentialFacts {
|
|
13
|
+
readonly required: boolean;
|
|
14
|
+
readonly saved: boolean;
|
|
15
|
+
readonly label?: string;
|
|
16
|
+
readonly credentialId?: string;
|
|
17
|
+
readonly updatedAt?: string;
|
|
18
|
+
}
|
|
19
|
+
/** Declarative setup copy belongs to the host or plugin. */
|
|
20
|
+
export interface MailProviderField {
|
|
21
|
+
readonly key: string;
|
|
22
|
+
readonly label: string;
|
|
23
|
+
readonly type: "secret" | "text" | "url" | "email";
|
|
24
|
+
readonly required: boolean;
|
|
25
|
+
readonly defaultValue?: string;
|
|
26
|
+
readonly placeholder?: string;
|
|
27
|
+
readonly help?: string;
|
|
28
|
+
readonly helpUrl?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface MailProviderSetup {
|
|
31
|
+
readonly fields: readonly MailProviderField[];
|
|
32
|
+
readonly helpUrl?: string;
|
|
33
|
+
}
|
|
34
|
+
/** Safe host-supplied projection; configuration building and product copy stay in the host. */
|
|
35
|
+
export interface MailProviderConfiguration {
|
|
36
|
+
readonly pluginId?: string;
|
|
37
|
+
readonly id: string;
|
|
38
|
+
readonly label: string;
|
|
39
|
+
readonly origin: "core" | "plugin";
|
|
40
|
+
readonly hosted: boolean;
|
|
41
|
+
readonly lanes: readonly ("transactional" | "bulk")[];
|
|
42
|
+
readonly capabilities: Pick<MailProviderCapabilities, "feedback" | "domainVerification" | "rateLimit">;
|
|
43
|
+
readonly credential: MailProviderCredentialFacts;
|
|
44
|
+
readonly selectable: boolean;
|
|
45
|
+
readonly refusal?: string;
|
|
46
|
+
readonly setup: MailProviderSetup;
|
|
47
|
+
}
|
|
48
|
+
export interface MailProviderConfigurationReport {
|
|
49
|
+
readonly setting: MailProviderSetting;
|
|
50
|
+
readonly providers: readonly MailProviderConfiguration[];
|
|
51
|
+
readonly refusals: readonly string[];
|
|
52
|
+
}
|
|
53
|
+
/** A provider failure safe for callers; contains neither credentials nor message bodies. */
|
|
54
|
+
export interface MailProviderError {
|
|
55
|
+
readonly at: string;
|
|
56
|
+
readonly providerId: string | null;
|
|
57
|
+
readonly source: "send" | "check";
|
|
58
|
+
readonly code?: string;
|
|
59
|
+
readonly message: string;
|
|
60
|
+
}
|
|
61
|
+
/** Alias the provider's existing verdict vocabulary instead of defining another taxonomy. */
|
|
62
|
+
export type ProviderDomainState = MailDomainState;
|
|
63
|
+
/** Provider verification is independent of DNS answers and credential presence. */
|
|
64
|
+
export type SenderDomainVerification = {
|
|
65
|
+
state: ProviderDomainState;
|
|
66
|
+
domain: string;
|
|
67
|
+
providerId: string;
|
|
68
|
+
} | {
|
|
69
|
+
state: "no_sender";
|
|
70
|
+
providerId: string | null;
|
|
71
|
+
} | {
|
|
72
|
+
state: "no_provider";
|
|
73
|
+
domain: string;
|
|
74
|
+
providerId: string | null;
|
|
75
|
+
} | {
|
|
76
|
+
state: "unsupported";
|
|
77
|
+
domain: string;
|
|
78
|
+
providerId: string;
|
|
79
|
+
} | {
|
|
80
|
+
state: "unknown";
|
|
81
|
+
domain?: string;
|
|
82
|
+
providerId: string | null;
|
|
83
|
+
reason: string;
|
|
84
|
+
};
|
|
85
|
+
export interface MailStatusReport extends MailStatus {
|
|
86
|
+
readonly senderDomainVerification?: SenderDomainVerification;
|
|
87
|
+
readonly providers: readonly MailProviderConfiguration[];
|
|
88
|
+
readonly refusals: readonly string[];
|
|
89
|
+
readonly checkedAt: string;
|
|
90
|
+
readonly lastError?: MailProviderError;
|
|
91
|
+
}
|
|
92
|
+
export type MailProviderCheck = {
|
|
93
|
+
ok: true;
|
|
94
|
+
label: string;
|
|
95
|
+
} | {
|
|
96
|
+
ok: false;
|
|
97
|
+
reason: string;
|
|
98
|
+
};
|
|
99
|
+
/** Host-built catalog: trusted loading, labels and setup copy remain outside the engine. */
|
|
100
|
+
export interface MailProviderCatalog {
|
|
101
|
+
readonly registry: MailProviderRegistry;
|
|
102
|
+
readonly pluginIds: readonly string[];
|
|
103
|
+
readonly refusals: readonly string[];
|
|
104
|
+
credentialLabelFor(required: {
|
|
105
|
+
id: string;
|
|
106
|
+
}): string | undefined;
|
|
107
|
+
setupFor(required: {
|
|
108
|
+
id: string;
|
|
109
|
+
}): MailProviderSetup;
|
|
110
|
+
}
|
|
111
|
+
/** Host settings adapter; reads do not infer provider selection from saved credentials. */
|
|
112
|
+
export interface MailProviderSettingPort {
|
|
113
|
+
read(required: Record<string, never>): Promise<MailProviderSetting | null>;
|
|
114
|
+
write(required: {
|
|
115
|
+
setting: MailProviderSetting;
|
|
116
|
+
}): Promise<void>;
|
|
117
|
+
}
|
|
118
|
+
/** Host owns metadata lookup and decryption. Metadata may fail independently of key resolution. */
|
|
119
|
+
export interface MailCredentialPort {
|
|
120
|
+
readFact(required: {
|
|
121
|
+
label: string;
|
|
122
|
+
}): Promise<MailCredentialFact | undefined>;
|
|
123
|
+
resolve(required: {
|
|
124
|
+
catalog: MailProviderCatalog;
|
|
125
|
+
id: string;
|
|
126
|
+
}): Promise<MailAdapterCredential | null>;
|
|
127
|
+
}
|
|
128
|
+
/** Read-only provider verdict; implementations return unknown on lookup/provider failures. */
|
|
129
|
+
export type SenderDomainVerificationPort = () => Promise<SenderDomainVerification>;
|
|
130
|
+
//# sourceMappingURL=engine-contracts.d.ts.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/** @agent-note Types only. The runtime parts come from the host; this area usually from `@jini-ai/platform`. */
|
|
2
|
+
import type { UUID } from "../../primitives/index.js";
|
|
3
|
+
import type { MailerCapabilities, MailerSendResult, OutboundEmail, MailerSendRequired, MailerBatchRequired, MailerOptional } from "../mail.js";
|
|
4
|
+
export type { MailerCapabilities, MailerSendOptions, MailerSendResult, OutboundEmail } from "../mail.js";
|
|
5
|
+
export interface MailerPort {
|
|
6
|
+
capabilities(_required: Record<string, never>): MailerCapabilities;
|
|
7
|
+
send(required: MailerSendRequired, optional?: MailerOptional): Promise<MailerSendResult>;
|
|
8
|
+
sendBatch(required: MailerBatchRequired, optional?: MailerOptional): Promise<readonly MailerSendResult[]>;
|
|
9
|
+
}
|
|
10
|
+
export type ConsoleMailerAdapter = MailerPort;
|
|
11
|
+
export type InMemoryMailerAdapter = MailerPort;
|
|
12
|
+
/** `all` blocks every send (hard bounce, manual); `bulk` blocks only bulk mail (complaints), so a
|
|
13
|
+
* member who marked a newsletter as spam can still receive their own sign-in link. */
|
|
14
|
+
export type MailSuppressionScope = "all" | "bulk";
|
|
15
|
+
export interface MailSuppressionRepoPort {
|
|
16
|
+
isSuppressed(required: {
|
|
17
|
+
workspaceId: UUID;
|
|
18
|
+
normalizedAddress: string;
|
|
19
|
+
/** The lane being sent: `transactional` consults `all` only, `bulk` consults both scopes. */
|
|
20
|
+
lane: MailDeliveryLane;
|
|
21
|
+
}): Promise<boolean>;
|
|
22
|
+
suppress(required: {
|
|
23
|
+
workspaceId: UUID;
|
|
24
|
+
normalizedAddress: string;
|
|
25
|
+
scope: MailSuppressionScope;
|
|
26
|
+
reason: "bounced" | "complained" | "manual";
|
|
27
|
+
}): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
/** Hard delivery lanes. Distinct from `MailerSendOptions.lane` (interactive/notification readiness). */
|
|
30
|
+
export type MailDeliveryLane = "transactional" | "bulk";
|
|
31
|
+
export type MailLedgerOutcome = "reserved" | "sent" | "failed" | "unknown";
|
|
32
|
+
export interface MailSendLedgerPort {
|
|
33
|
+
/**
|
|
34
|
+
* Atomically insert (workspaceId, idempotencyKey, recipient) as `reserved`. An existing row is
|
|
35
|
+
* returned as-is, except `failed`, which the port flips back to `reserved` in the same statement
|
|
36
|
+
* (a definitive failure means nothing was sent, so retrying under the same identity is safe).
|
|
37
|
+
* With `optional.reclaimUnknown`, an `unknown` row with the SAME payloadHash is flipped to
|
|
38
|
+
* `reserved` in that same statement too: the caller that wins the flip is the only one that
|
|
39
|
+
* re-sends, and a concurrent retry sees `reserved` (an unknown outcome) instead of also re-sending.
|
|
40
|
+
*/
|
|
41
|
+
reserve(required: {
|
|
42
|
+
workspaceId: UUID;
|
|
43
|
+
idempotencyKey: string;
|
|
44
|
+
recipient: string;
|
|
45
|
+
payloadHash: string;
|
|
46
|
+
lane: MailDeliveryLane;
|
|
47
|
+
providerId: string;
|
|
48
|
+
}, optional?: {
|
|
49
|
+
reclaimUnknown?: boolean;
|
|
50
|
+
}): Promise<{
|
|
51
|
+
status: "reserved";
|
|
52
|
+
} | {
|
|
53
|
+
status: "existing";
|
|
54
|
+
outcome: Exclude<MailLedgerOutcome, "failed">;
|
|
55
|
+
payloadHash: string;
|
|
56
|
+
providerMessageId?: string;
|
|
57
|
+
}>;
|
|
58
|
+
mark(required: {
|
|
59
|
+
workspaceId: UUID;
|
|
60
|
+
idempotencyKey: string;
|
|
61
|
+
recipient: string;
|
|
62
|
+
outcome: Exclude<MailLedgerOutcome, "reserved">;
|
|
63
|
+
providerMessageId?: string;
|
|
64
|
+
errorCode?: string;
|
|
65
|
+
}): Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
/** @deprecated Racy check-then-send pair; use {@link MailSendLedgerPort}. Kept for type consumers. */
|
|
68
|
+
export interface MailSendDedupRepoPort {
|
|
69
|
+
wasSent(required: {
|
|
70
|
+
workspaceId: UUID;
|
|
71
|
+
idempotencyKey: string;
|
|
72
|
+
}): Promise<boolean>;
|
|
73
|
+
markSent(required: {
|
|
74
|
+
workspaceId: UUID;
|
|
75
|
+
idempotencyKey: string;
|
|
76
|
+
}): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
/** Test/capture mode sink: messages are stored for the operator instead of leaving the process. */
|
|
79
|
+
export interface MailCapturePort {
|
|
80
|
+
capture(required: {
|
|
81
|
+
message: OutboundEmail;
|
|
82
|
+
lane: MailDeliveryLane;
|
|
83
|
+
idempotencyKey: string;
|
|
84
|
+
}): Promise<{
|
|
85
|
+
id: string;
|
|
86
|
+
}>;
|
|
87
|
+
}
|
|
88
|
+
export interface DeliveryReadinessPolicy {
|
|
89
|
+
isReady(required: {
|
|
90
|
+
capabilityName: string;
|
|
91
|
+
}): boolean;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=ports.d.ts.map
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { DomainRequirement, ProviderContext, ProviderRegistry, ProviderResult } from '../../provider-registry.js';
|
|
2
|
+
import type { HttpClientPort } from '../../primitives/index.js';
|
|
3
|
+
import type { MailAdapterCredential, MailAdapterModule } from './adapter-module.js';
|
|
4
|
+
import type { MailDeliveryLane } from './ports.js';
|
|
5
|
+
import type { MailerFeedbackEvent } from '../mail.js';
|
|
6
|
+
/** @agent-note Types only. The runtime parts come from the host; this area usually from `@jini-ai/platform`. */
|
|
7
|
+
/** Provider token bucket: sustained rate plus burst. Absent = no provider-declared limit. */
|
|
8
|
+
export interface MailRateLimit {
|
|
9
|
+
readonly perSecond: number;
|
|
10
|
+
readonly burst: number;
|
|
11
|
+
}
|
|
12
|
+
export interface MailProviderCapabilities {
|
|
13
|
+
/** False for local drivers (console): they never count as real delivery. */
|
|
14
|
+
readonly hosted: boolean;
|
|
15
|
+
/** True exactly when the module ships a {@link MailFeedbackParser}. */
|
|
16
|
+
readonly feedback: boolean;
|
|
17
|
+
/** True exactly when the module implements domainRequirements + domainStatus. */
|
|
18
|
+
readonly domainVerification: boolean;
|
|
19
|
+
readonly rateLimit?: MailRateLimit;
|
|
20
|
+
}
|
|
21
|
+
export interface MailFeedbackParser {
|
|
22
|
+
/** Raw bytes in; never throws. Any of `secrets` may match so a webhook secret can rotate. */
|
|
23
|
+
verify(required: {
|
|
24
|
+
rawBody: Uint8Array;
|
|
25
|
+
headers: Readonly<Record<string, string>>;
|
|
26
|
+
secrets: readonly string[];
|
|
27
|
+
now: number;
|
|
28
|
+
}): boolean;
|
|
29
|
+
/** Headers are passed so a parser can key events on a delivery id (e.g. `svix-id`).
|
|
30
|
+
* Each event must carry eventId + recipient, or the ingest drops it (no dedup key, no suppression key). */
|
|
31
|
+
parse(required: {
|
|
32
|
+
rawBody: Uint8Array;
|
|
33
|
+
workspaceId: string;
|
|
34
|
+
headers: Readonly<Record<string, string>>;
|
|
35
|
+
}): readonly MailerFeedbackEvent[] | {
|
|
36
|
+
error: string;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** Per-call context: who the call acts for plus the host-resolved credential and guarded HTTP. */
|
|
40
|
+
export interface MailProviderCallContext extends ProviderContext {
|
|
41
|
+
readonly credential: MailAdapterCredential;
|
|
42
|
+
readonly httpClient: HttpClientPort;
|
|
43
|
+
}
|
|
44
|
+
export type MailDomainState = "verified" | "pending" | "failed" | "not_found";
|
|
45
|
+
export interface MailProviderModule extends MailAdapterModule {
|
|
46
|
+
readonly id: string;
|
|
47
|
+
readonly label: string;
|
|
48
|
+
/** Credential fields the host must resolve (e.g. `token`, `username`, `baseUrl`). */
|
|
49
|
+
readonly credentialKeys: readonly string[];
|
|
50
|
+
/** Separate vault key for the webhook signing secret, so it rotates independently of the API key. */
|
|
51
|
+
readonly webhookSecretKey?: string;
|
|
52
|
+
readonly capabilities: MailProviderCapabilities;
|
|
53
|
+
readonly feedback?: MailFeedbackParser;
|
|
54
|
+
/** DNS records the provider needs before it will send as `domain`; satisfied through the DNS port. */
|
|
55
|
+
domainRequirements?(ctx: MailProviderCallContext, required: {
|
|
56
|
+
domain: string;
|
|
57
|
+
}): Promise<ProviderResult<DomainRequirement>>;
|
|
58
|
+
domainStatus?(ctx: MailProviderCallContext, required: {
|
|
59
|
+
domain: string;
|
|
60
|
+
}): Promise<ProviderResult<{
|
|
61
|
+
domain: string;
|
|
62
|
+
state: MailDomainState;
|
|
63
|
+
}>>;
|
|
64
|
+
}
|
|
65
|
+
export type MailProviderRegistry = ProviderRegistry<MailProviderModule>;
|
|
66
|
+
/** One provider per lane; equal ids today, separable later without a data migration. null = unconfigured. */
|
|
67
|
+
export interface MailProviderSetting {
|
|
68
|
+
readonly transactional: string | null;
|
|
69
|
+
readonly bulk: string | null;
|
|
70
|
+
}
|
|
71
|
+
export type MailLaneState = "ready" | "unconfigured" | "unknown_provider" | "missing_credential" | "local_only";
|
|
72
|
+
export interface MailLaneStatus {
|
|
73
|
+
readonly lane: MailDeliveryLane;
|
|
74
|
+
readonly providerId: string | null;
|
|
75
|
+
readonly state: MailLaneState;
|
|
76
|
+
}
|
|
77
|
+
export type MailStatusWarning = "sender_unverified" | "sender_unknown";
|
|
78
|
+
export interface MailStatus {
|
|
79
|
+
/** `unconfigured` drives the blocking admin banner; owner sign-in must never depend on mail. */
|
|
80
|
+
readonly state: "ready" | "unconfigured" | "degraded";
|
|
81
|
+
readonly lanes: readonly MailLaneStatus[];
|
|
82
|
+
readonly warnings: readonly MailStatusWarning[];
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=provider.d.ts.map
|