@axiom-lattice/protocols 7.1.0 → 7.3.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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +179 -0
- package/dist/index.d.mts +740 -8
- package/dist/index.d.ts +740 -8
- package/dist/index.js +184 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +161 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/AuthProviderProtocol.ts +80 -0
- package/src/InviteLinkStoreProtocol.ts +59 -0
- package/src/McpLatticeProtocol.ts +2 -2
- package/src/McpServerConfigStoreProtocol.ts +118 -0
- package/src/ModelProviderProtocol.ts +20 -4
- package/src/OidcIdentityClaimStoreProtocol.ts +117 -0
- package/src/OidcProviderConfigStoreProtocol.ts +84 -0
- package/src/PlatformAuditProtocol.ts +80 -0
- package/src/PlatformInvitationStoreProtocol.ts +60 -0
- package/src/PlatformMemberStoreProtocol.ts +23 -0
- package/src/PlatformOpsProtocol.ts +73 -0
- package/src/PlatformSettingsProtocol.ts +161 -0
- package/src/SandboxPluginProtocol.ts +1 -1
- package/src/UserExternalIdentityStoreProtocol.ts +53 -0
- package/src/__tests__/AuthProviderProtocol.test.ts +20 -0
- package/src/index.ts +10 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Platform-level role, independent of any tenant role. */
|
|
2
|
+
export type PlatformRole = "owner" | "admin" | "auditor";
|
|
3
|
+
|
|
4
|
+
/** Durable platform grant for a single user. */
|
|
5
|
+
export interface PlatformMember {
|
|
6
|
+
userId: string;
|
|
7
|
+
role: PlatformRole;
|
|
8
|
+
grantedBy?: string;
|
|
9
|
+
grantedAt: Date;
|
|
10
|
+
updatedAt: Date;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Persistence operations for platform members. */
|
|
14
|
+
export interface PlatformMemberStore {
|
|
15
|
+
/** Lists every platform member. */
|
|
16
|
+
list(): Promise<PlatformMember[]>;
|
|
17
|
+
/** Returns the platform member for a user, or null. */
|
|
18
|
+
get(userId: string): Promise<PlatformMember | null>;
|
|
19
|
+
/** Inserts or replaces a member keyed by user id (last write wins). */
|
|
20
|
+
upsert(member: PlatformMember): Promise<PlatformMember>;
|
|
21
|
+
/** Deletes a member. Returns whether a row was removed. */
|
|
22
|
+
delete(userId: string): Promise<boolean>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PlatformOpsProtocol
|
|
3
|
+
*
|
|
4
|
+
* Shared identity constants for the platform-scoped operations surface.
|
|
5
|
+
*
|
|
6
|
+
* The Ops Agent runs on a hidden system tenant so it can reuse the normal
|
|
7
|
+
* agent runtime (threads, runs, SSE, leases) without appearing in any tenant
|
|
8
|
+
* or agent list. These identifiers are deliberately reserved and must not be
|
|
9
|
+
* user-selectable.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Reserved tenant id that owns platform-scoped configuration and agent
|
|
14
|
+
* execution (platform model catalog, Ops Agent threads, …).
|
|
15
|
+
*/
|
|
16
|
+
export const PLATFORM_TENANT_ID = "__platform__";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Fixed key of the platform operations agent. It is registered explicitly at
|
|
20
|
+
* startup rather than created through assistant management routes.
|
|
21
|
+
*/
|
|
22
|
+
export const PLATFORM_OPS_AGENT_ID = "platform-ops";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Stable error code returned when a normal tenant route tries to mutate the
|
|
26
|
+
* hidden platform tenant.
|
|
27
|
+
*/
|
|
28
|
+
export const PLATFORM_TENANT_PROTECTED_ERROR = "PLATFORM_TENANT_PROTECTED";
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Whether a tenant id belongs to the hidden platform tenant.
|
|
32
|
+
*/
|
|
33
|
+
export function isPlatformTenantId(tenantId: string): boolean {
|
|
34
|
+
return tenantId === PLATFORM_TENANT_ID;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Stable error raised when a tenant-plane operation tries to address the
|
|
39
|
+
* hidden platform tenant.
|
|
40
|
+
*/
|
|
41
|
+
export class PlatformTenantProtectedError extends Error {
|
|
42
|
+
readonly code = PLATFORM_TENANT_PROTECTED_ERROR;
|
|
43
|
+
|
|
44
|
+
constructor(message = "The hidden platform tenant is protected") {
|
|
45
|
+
super(message);
|
|
46
|
+
this.name = "PlatformTenantProtectedError";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Rejects any attempt to create or mutate a link into the hidden platform
|
|
52
|
+
* tenant.
|
|
53
|
+
*/
|
|
54
|
+
export function assertNotPlatformTenant(tenantId: string): void {
|
|
55
|
+
if (isPlatformTenantId(tenantId)) {
|
|
56
|
+
throw new PlatformTenantProtectedError();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Fixed workspace used by Platform Ops threads inside the hidden tenant. */
|
|
61
|
+
export const PLATFORM_OPS_WORKSPACE_ID = "platform-ops";
|
|
62
|
+
|
|
63
|
+
/** Fixed project used by Platform Ops threads inside the hidden tenant. */
|
|
64
|
+
export const PLATFORM_OPS_PROJECT_ID = "platform-ops";
|
|
65
|
+
|
|
66
|
+
/** High-risk Ops playbook discriminator executed by the playbook executor. */
|
|
67
|
+
export type PlatformOpsPlaybookKind =
|
|
68
|
+
| "transfer_owner"
|
|
69
|
+
| "offboard_member"
|
|
70
|
+
| "delete_tenant"
|
|
71
|
+
| "delete_oidc_provider"
|
|
72
|
+
| "rotate_oidc_provider"
|
|
73
|
+
| "reset_settings";
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/** Source that produced an effective platform setting value. */
|
|
2
|
+
export type PlatformSettingSource = "default" | "env" | "platform";
|
|
3
|
+
|
|
4
|
+
/** Branding fields applied to the console and public surfaces. */
|
|
5
|
+
export interface PlatformBranding {
|
|
6
|
+
brandName?: string;
|
|
7
|
+
logoUrl?: string;
|
|
8
|
+
faviconUrl?: string;
|
|
9
|
+
primaryColor?: string;
|
|
10
|
+
backgroundColor?: string;
|
|
11
|
+
loginTitle?: string;
|
|
12
|
+
loginSubtitle?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Host-scoped branding and public endpoint overrides. */
|
|
16
|
+
export interface BrandingDomain {
|
|
17
|
+
host: string;
|
|
18
|
+
status?: "active" | "pending";
|
|
19
|
+
publicGatewayUrl?: string;
|
|
20
|
+
publicConsoleUrl?: string;
|
|
21
|
+
branding?: PlatformBranding;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Platform default branding plus host-specific overrides. */
|
|
25
|
+
export interface PlatformBrandingSettings {
|
|
26
|
+
default?: PlatformBranding;
|
|
27
|
+
domains?: BrandingDomain[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Branding resolved for a request host. */
|
|
31
|
+
export interface ResolvedPlatformBranding {
|
|
32
|
+
branding: PlatformBranding;
|
|
33
|
+
source: "domain" | "default";
|
|
34
|
+
host?: string;
|
|
35
|
+
publicGatewayUrl?: string;
|
|
36
|
+
publicConsoleUrl?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Platform override for one gateway rate-limit policy. */
|
|
40
|
+
export interface PlatformRateLimitPolicyOverride {
|
|
41
|
+
/** New fixed-window request limit. Omitted keeps the deployment limit. */
|
|
42
|
+
limit?: number;
|
|
43
|
+
/** Set false to disable this policy. Omitted keeps the deployment state. */
|
|
44
|
+
enabled?: boolean;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Persisted, partial platform settings document managed by platform admins. */
|
|
48
|
+
export interface PlatformSettingsDocument {
|
|
49
|
+
auth?: { emailCompletionEnabled?: boolean };
|
|
50
|
+
invite?: { defaultExpiresInHours?: number; defaultMaxUses?: number };
|
|
51
|
+
rateLimits?: {
|
|
52
|
+
/** Per-policy platform overrides keyed by policy name. */
|
|
53
|
+
policies?: Record<string, PlatformRateLimitPolicyOverride>;
|
|
54
|
+
/** PATCH-only command: remove platform overrides for these policies. */
|
|
55
|
+
resetPolicies?: string[];
|
|
56
|
+
maxActiveRunTasksPerTenant?: number | null;
|
|
57
|
+
};
|
|
58
|
+
branding?: PlatformBrandingSettings;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Stored platform settings record with version and audit metadata. */
|
|
62
|
+
export interface PlatformSettingsRecord extends PlatformSettingsDocument {
|
|
63
|
+
version: number;
|
|
64
|
+
updatedBy?: string;
|
|
65
|
+
updatedAt: Date;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Fully-resolved platform settings (no optional fields). */
|
|
69
|
+
export interface EffectivePlatformSettings {
|
|
70
|
+
auth: { emailCompletionEnabled: boolean };
|
|
71
|
+
invite: { defaultExpiresInHours: number; defaultMaxUses: number };
|
|
72
|
+
rateLimits: {
|
|
73
|
+
openApiPerMinute: number;
|
|
74
|
+
openAgentPerMinute: number;
|
|
75
|
+
a2aJsonRpcPerMinute: number;
|
|
76
|
+
a2aJsonRpcIpPerMinute: number;
|
|
77
|
+
maxActiveRunTasksPerTenant: number | null;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Read-only snapshot of effective settings, provenance, and fallbacks. */
|
|
82
|
+
export interface PlatformSettingsSnapshot {
|
|
83
|
+
version: number;
|
|
84
|
+
effective: EffectivePlatformSettings;
|
|
85
|
+
sources: Record<string, PlatformSettingSource>;
|
|
86
|
+
fallbacks: EffectivePlatformSettings;
|
|
87
|
+
updatedBy?: string;
|
|
88
|
+
updatedAt?: Date;
|
|
89
|
+
/** Time this snapshot was last loaded or applied from the store. */
|
|
90
|
+
refreshedAt?: Date;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Read-only accessor for effective platform settings. */
|
|
94
|
+
export interface PlatformSettingsProvider {
|
|
95
|
+
getSnapshot(): PlatformSettingsSnapshot;
|
|
96
|
+
getEffective(): EffectivePlatformSettings;
|
|
97
|
+
getInviteDefaults(): EffectivePlatformSettings["invite"];
|
|
98
|
+
getRateLimits(): EffectivePlatformSettings["rateLimits"];
|
|
99
|
+
/** Platform-only policy overrides; absent for consumers that do not need them. */
|
|
100
|
+
getRateLimitPolicyOverrides?(): Record<string, PlatformRateLimitPolicyOverride>;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Persistence operations for platform settings with version CAS. */
|
|
104
|
+
export interface PlatformSettingsStore {
|
|
105
|
+
get(): Promise<PlatformSettingsRecord | null>;
|
|
106
|
+
save(
|
|
107
|
+
document: PlatformSettingsDocument,
|
|
108
|
+
expectedVersion: number,
|
|
109
|
+
updatedBy?: string,
|
|
110
|
+
): Promise<PlatformSettingsRecord>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Thrown when a save is attempted against a stale settings version. */
|
|
114
|
+
export class PlatformSettingsVersionConflictError extends Error {
|
|
115
|
+
readonly code = "PLATFORM_SETTINGS_VERSION_CONFLICT";
|
|
116
|
+
constructor(
|
|
117
|
+
readonly expectedVersion: number,
|
|
118
|
+
readonly actualVersion?: number,
|
|
119
|
+
) {
|
|
120
|
+
super(`Platform settings version conflict at ${expectedVersion}`);
|
|
121
|
+
this.name = "PlatformSettingsVersionConflictError";
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Built-in fallback values used when neither platform nor env set a value. */
|
|
126
|
+
export const PLATFORM_SETTINGS_DEFAULTS = {
|
|
127
|
+
auth: { emailCompletionEnabled: false },
|
|
128
|
+
invite: { defaultExpiresInHours: 168, defaultMaxUses: 1 },
|
|
129
|
+
rateLimits: {
|
|
130
|
+
openApiPerMinute: 60_000,
|
|
131
|
+
openAgentPerMinute: 2_000,
|
|
132
|
+
a2aJsonRpcPerMinute: 600,
|
|
133
|
+
a2aJsonRpcIpPerMinute: 300,
|
|
134
|
+
maxActiveRunTasksPerTenant: null,
|
|
135
|
+
},
|
|
136
|
+
} as const satisfies EffectivePlatformSettings;
|
|
137
|
+
|
|
138
|
+
/** Branding used when neither the platform default nor a domain overrides it. */
|
|
139
|
+
export const DEFAULT_PLATFORM_BRANDING: PlatformBranding = {
|
|
140
|
+
brandName: "AlphaFina",
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Canonicalizes a request or configured host for matching.
|
|
145
|
+
*
|
|
146
|
+
* Lowercases the value, strips an optional port, unwraps bracketed IPv6
|
|
147
|
+
* literals, and removes trailing dots.
|
|
148
|
+
*/
|
|
149
|
+
export function normalizeBrandingHost(raw: string): string {
|
|
150
|
+
let host = raw.trim().toLowerCase();
|
|
151
|
+
if (host.startsWith("[")) {
|
|
152
|
+
const end = host.indexOf("]");
|
|
153
|
+
if (end !== -1) host = host.slice(1, end);
|
|
154
|
+
} else {
|
|
155
|
+
const firstColon = host.indexOf(":");
|
|
156
|
+
if (firstColon !== -1 && host.indexOf(":", firstColon + 1) === -1) {
|
|
157
|
+
host = host.slice(0, firstColon);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return host.replace(/\.+$/, "");
|
|
161
|
+
}
|
|
@@ -36,7 +36,7 @@ export interface SandboxPluginConnectionDef {
|
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* Authoritative declarative definition of a tenant plugin, stored at
|
|
39
|
-
* `/
|
|
39
|
+
* the configured agents root `/plugins/<type>/plugin.json`.
|
|
40
40
|
*/
|
|
41
41
|
export interface SandboxPluginManifest {
|
|
42
42
|
schemaVersion: 1;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export interface UserExternalIdentity {
|
|
2
|
+
userId: string;
|
|
3
|
+
providerId: string;
|
|
4
|
+
/** OIDC issuer (or derived provider key); prevents cross-IdP subject collisions. */
|
|
5
|
+
issuer: string;
|
|
6
|
+
subject: string;
|
|
7
|
+
email?: string;
|
|
8
|
+
linkedAt: Date;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class ExternalIdentityConflictError extends Error {
|
|
12
|
+
readonly code = "EXTERNAL_IDENTITY_CONFLICT";
|
|
13
|
+
|
|
14
|
+
constructor(
|
|
15
|
+
readonly providerId: string,
|
|
16
|
+
readonly issuer: string,
|
|
17
|
+
readonly subject: string,
|
|
18
|
+
) {
|
|
19
|
+
super(
|
|
20
|
+
`External identity ${providerId}/${issuer}/${subject} is already linked to another user`,
|
|
21
|
+
);
|
|
22
|
+
this.name = "ExternalIdentityConflictError";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Raised when a store cannot read back an external identity immediately after a
|
|
28
|
+
* successful write, which indicates a persistence invariant failure rather than a
|
|
29
|
+
* user-facing conflict.
|
|
30
|
+
*/
|
|
31
|
+
export class ExternalIdentityPersistError extends Error {
|
|
32
|
+
readonly code = "EXTERNAL_IDENTITY_PERSIST_FAILED";
|
|
33
|
+
|
|
34
|
+
constructor(
|
|
35
|
+
readonly providerId: string,
|
|
36
|
+
readonly issuer: string,
|
|
37
|
+
readonly subject: string,
|
|
38
|
+
) {
|
|
39
|
+
super(`Failed to persist external identity ${providerId}/${issuer}/${subject}`);
|
|
40
|
+
this.name = "ExternalIdentityPersistError";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface UserExternalIdentityStore {
|
|
45
|
+
getByProviderSubject(
|
|
46
|
+
providerId: string,
|
|
47
|
+
issuer: string,
|
|
48
|
+
subject: string,
|
|
49
|
+
): Promise<UserExternalIdentity | null>;
|
|
50
|
+
listByUser(userId: string): Promise<UserExternalIdentity[]>;
|
|
51
|
+
link(identity: UserExternalIdentity): Promise<void>;
|
|
52
|
+
unlink(providerId: string, issuer: string, subject: string): Promise<void>;
|
|
53
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AuthError, ExternalIdentityConflictError } from "../index";
|
|
2
|
+
|
|
3
|
+
describe("auth protocol contracts", () => {
|
|
4
|
+
it("preserves the AuthError code and HTTP status", () => {
|
|
5
|
+
const error = new AuthError("INVALID_STATE", 400, "bad state");
|
|
6
|
+
expect(error).toBeInstanceOf(Error);
|
|
7
|
+
expect(error.name).toBe("AuthError");
|
|
8
|
+
expect(error.code).toBe("INVALID_STATE");
|
|
9
|
+
expect(error.status).toBe(400);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("names the conflicting external identity", () => {
|
|
13
|
+
const error = new ExternalIdentityConflictError("oidc", "https://idp.example.com", "azure-oid-1");
|
|
14
|
+
expect(error.name).toBe("ExternalIdentityConflictError");
|
|
15
|
+
expect(error.code).toBe("EXTERNAL_IDENTITY_CONFLICT");
|
|
16
|
+
expect(error.providerId).toBe("oidc");
|
|
17
|
+
expect(error.issuer).toBe("https://idp.example.com");
|
|
18
|
+
expect(error.subject).toBe("azure-oid-1");
|
|
19
|
+
});
|
|
20
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -33,6 +33,8 @@ export * from "./McpServerConfigStoreProtocol";
|
|
|
33
33
|
export * from "./ModelProviderProtocol";
|
|
34
34
|
export * from "./UserStoreProtocol";
|
|
35
35
|
export * from "./UserTenantLinkProtocol";
|
|
36
|
+
export * from "./AuthProviderProtocol";
|
|
37
|
+
export * from "./UserExternalIdentityStoreProtocol";
|
|
36
38
|
export * from "./WorkflowTrackingStoreProtocol";
|
|
37
39
|
export * from "./BindingProtocol";
|
|
38
40
|
export * from "./CollectionStoreProtocol";
|
|
@@ -60,6 +62,11 @@ export * from "./ProjectBotMembershipStoreProtocol";
|
|
|
60
62
|
export * from "./ProjectRoomMessageStoreProtocol";
|
|
61
63
|
export * from "./ProjectRoomReadStateProtocol";
|
|
62
64
|
export * from "./UserPushSubscriptionStoreProtocol";
|
|
65
|
+
export * from "./OidcProviderConfigStoreProtocol";
|
|
66
|
+
export * from "./PlatformMemberStoreProtocol";
|
|
67
|
+
export * from "./PlatformInvitationStoreProtocol";
|
|
68
|
+
export * from "./OidcIdentityClaimStoreProtocol";
|
|
69
|
+
export * from "./InviteLinkStoreProtocol";
|
|
63
70
|
export * from "./PluginDeploymentStoreProtocol";
|
|
64
71
|
export * from "./LeaseStoreProtocol";
|
|
65
72
|
export * from "./OutboxStoreProtocol";
|
|
@@ -108,3 +115,6 @@ export * from "./AgentAffinity";
|
|
|
108
115
|
export * from "./OpenProtocol";
|
|
109
116
|
export * from "./McpUiProtocol";
|
|
110
117
|
export * from "./ObservabilityDashboardProtocol";
|
|
118
|
+
export * from "./PlatformSettingsProtocol";
|
|
119
|
+
export * from "./PlatformAuditProtocol";
|
|
120
|
+
export * from "./PlatformOpsProtocol";
|