@axiom-lattice/protocols 7.2.0 → 7.4.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 +182 -0
- package/dist/index.d.mts +262 -14
- package/dist/index.d.ts +262 -14
- package/dist/index.js +258 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +240 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/AuthCssContract.ts +45 -0
- package/src/CollectionStoreProtocol.ts +8 -0
- package/src/McpLatticeProtocol.ts +2 -2
- package/src/McpServerConfigStoreProtocol.ts +118 -0
- package/src/McpUiProtocol.ts +2 -0
- package/src/ModelProviderProtocol.ts +20 -4
- package/src/OpenProtocol.ts +2 -2
- package/src/PlatformAuditProtocol.ts +80 -0
- package/src/PlatformBrandingCss.ts +180 -0
- package/src/PlatformOpsProtocol.ts +73 -0
- package/src/PlatformSettingsProtocol.ts +18 -4
- package/src/PluginProtocol.ts +9 -0
- package/src/SandboxResourceProtocol.ts +1 -1
- package/src/__tests__/PlatformBrandingCss.test.ts +103 -0
- package/src/index.ts +4 -0
package/package.json
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** Stable `data-axiom-part` attribute values for the auth CSS contract. */
|
|
2
|
+
export const AUTH_CSS_CONTRACT_PARTS = [
|
|
3
|
+
"page",
|
|
4
|
+
"card",
|
|
5
|
+
"header",
|
|
6
|
+
"logo",
|
|
7
|
+
"logo-image",
|
|
8
|
+
"title",
|
|
9
|
+
"subtitle",
|
|
10
|
+
"form",
|
|
11
|
+
"field",
|
|
12
|
+
"input",
|
|
13
|
+
"submit",
|
|
14
|
+
"sso",
|
|
15
|
+
"sso-button",
|
|
16
|
+
"alert",
|
|
17
|
+
"footer",
|
|
18
|
+
"link",
|
|
19
|
+
"cancel",
|
|
20
|
+
"tenant-list",
|
|
21
|
+
"tenant-card",
|
|
22
|
+
"tenant-search",
|
|
23
|
+
"tenant-footer",
|
|
24
|
+
"invite-notice",
|
|
25
|
+
] as const;
|
|
26
|
+
|
|
27
|
+
/** Stable CSS custom properties exposed by the auth CSS contract. */
|
|
28
|
+
export const AUTH_CSS_CONTRACT_VARIABLES = [
|
|
29
|
+
"--axiom-auth-primary",
|
|
30
|
+
"--axiom-auth-primary-hover",
|
|
31
|
+
"--axiom-auth-primary-active",
|
|
32
|
+
"--axiom-auth-bg",
|
|
33
|
+
"--axiom-auth-surface",
|
|
34
|
+
"--axiom-auth-text",
|
|
35
|
+
"--axiom-auth-text-secondary",
|
|
36
|
+
"--axiom-auth-border",
|
|
37
|
+
"--axiom-auth-radius",
|
|
38
|
+
"--axiom-auth-page-padding",
|
|
39
|
+
"--axiom-auth-card-width",
|
|
40
|
+
"--axiom-auth-card-padding",
|
|
41
|
+
"--axiom-auth-card-shadow",
|
|
42
|
+
"--axiom-auth-card-shadow-hover",
|
|
43
|
+
"--axiom-auth-logo-size",
|
|
44
|
+
"--axiom-auth-input-height",
|
|
45
|
+
] as const;
|
|
@@ -5,6 +5,14 @@
|
|
|
5
5
|
* Provides standardized interfaces for collection management across all implementations.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Maximum number of entries accepted by one collection batch write.
|
|
10
|
+
*
|
|
11
|
+
* Shared by the agent tool, gateway validation, and SDK-facing contract so the
|
|
12
|
+
* limit cannot drift between surfaces.
|
|
13
|
+
*/
|
|
14
|
+
export const COLLECTION_ENTRY_BATCH_MAX = 50;
|
|
15
|
+
|
|
8
16
|
/**
|
|
9
17
|
* Collection field type definition
|
|
10
18
|
*/
|
|
@@ -11,7 +11,7 @@ import { BaseLatticeProtocol, LatticeMessage } from "./BaseLatticeProtocol";
|
|
|
11
11
|
/**
|
|
12
12
|
* MCP transport type
|
|
13
13
|
*/
|
|
14
|
-
export type McpTransportType = "stdio" | "streamable_http"
|
|
14
|
+
export type McpTransportType = "stdio" | "streamable_http";
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* MCP protocol era selection for client connections.
|
|
@@ -41,7 +41,7 @@ export interface McpServerConfig {
|
|
|
41
41
|
/** Environment variables (stdio transport; credentials passed to the server process) */
|
|
42
42
|
env?: Record<string, string>;
|
|
43
43
|
/**
|
|
44
|
-
* Custom HTTP headers sent with every request (streamable_http
|
|
44
|
+
* Custom HTTP headers sent with every request (streamable_http only).
|
|
45
45
|
* Commonly used for authentication, e.g. `{ Authorization: "Bearer <token>" }`.
|
|
46
46
|
* Ignored for stdio transport. Values are encrypted at rest by config stores.
|
|
47
47
|
*/
|
|
@@ -21,6 +21,12 @@ export interface McpServerConfigEntry {
|
|
|
21
21
|
*/
|
|
22
22
|
tenantId: string;
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Personal assistant that owns this configuration, when it belongs to the
|
|
26
|
+
* personal data domain. Tenant-scoped entries leave this undefined.
|
|
27
|
+
*/
|
|
28
|
+
ownerAssistantId?: string;
|
|
29
|
+
|
|
24
30
|
/**
|
|
25
31
|
* Business key for the configuration (unique within tenant)
|
|
26
32
|
*/
|
|
@@ -227,3 +233,115 @@ export interface McpServerConfigStore {
|
|
|
227
233
|
*/
|
|
228
234
|
hasConfig(tenantId: string, id: string): Promise<boolean>;
|
|
229
235
|
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* MCP server configuration owned by one personal assistant.
|
|
239
|
+
*
|
|
240
|
+
* Personal configs live in a separate store surface so tenant-only code paths
|
|
241
|
+
* can never read them by accident; the owning assistant id is part of every
|
|
242
|
+
* lookup key.
|
|
243
|
+
*/
|
|
244
|
+
export interface PersonalMcpServerConfigEntry extends McpServerConfigEntry {
|
|
245
|
+
/** Personal assistant that owns this configuration. */
|
|
246
|
+
ownerAssistantId: string;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Store operations for the personal MCP data domain.
|
|
251
|
+
*
|
|
252
|
+
* Every method scopes by `(tenantId, ownerAssistantId)`. Implementations must
|
|
253
|
+
* never merge personal rows into the tenant-only methods of
|
|
254
|
+
* {@link McpServerConfigStore}.
|
|
255
|
+
*/
|
|
256
|
+
export interface PersonalMcpServerConfigStore {
|
|
257
|
+
/** List all personal MCP configs belonging to one assistant. */
|
|
258
|
+
getAllConfigsForAssistant(
|
|
259
|
+
tenantId: string,
|
|
260
|
+
ownerAssistantId: string,
|
|
261
|
+
): Promise<PersonalMcpServerConfigEntry[]>;
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* List every personal MCP config across tenants.
|
|
265
|
+
*
|
|
266
|
+
* Intended for operations and tests only; startup restoration must not call
|
|
267
|
+
* it (personal connections are established lazily).
|
|
268
|
+
*/
|
|
269
|
+
getAllPersonalConfigsWithoutTenant(): Promise<PersonalMcpServerConfigEntry[]>;
|
|
270
|
+
|
|
271
|
+
/** Get one personal config by id, scoped to its assistant. */
|
|
272
|
+
getConfigByIdForAssistant(
|
|
273
|
+
tenantId: string,
|
|
274
|
+
ownerAssistantId: string,
|
|
275
|
+
id: string,
|
|
276
|
+
): Promise<PersonalMcpServerConfigEntry | null>;
|
|
277
|
+
|
|
278
|
+
/** Get one personal config by business key, scoped to its assistant. */
|
|
279
|
+
getConfigByKeyForAssistant(
|
|
280
|
+
tenantId: string,
|
|
281
|
+
ownerAssistantId: string,
|
|
282
|
+
key: string,
|
|
283
|
+
): Promise<PersonalMcpServerConfigEntry | null>;
|
|
284
|
+
|
|
285
|
+
/** Create a personal config for one assistant. */
|
|
286
|
+
createConfigForAssistant(
|
|
287
|
+
tenantId: string,
|
|
288
|
+
ownerAssistantId: string,
|
|
289
|
+
id: string,
|
|
290
|
+
data: CreateMcpServerConfigRequest,
|
|
291
|
+
): Promise<PersonalMcpServerConfigEntry>;
|
|
292
|
+
|
|
293
|
+
/** Update a personal config by id, scoped to its assistant. */
|
|
294
|
+
updateConfigForAssistant(
|
|
295
|
+
tenantId: string,
|
|
296
|
+
ownerAssistantId: string,
|
|
297
|
+
id: string,
|
|
298
|
+
updates: Partial<UpdateMcpServerConfigRequest>,
|
|
299
|
+
): Promise<PersonalMcpServerConfigEntry | null>;
|
|
300
|
+
|
|
301
|
+
/** Delete one personal config by id; returns whether a row was removed. */
|
|
302
|
+
deleteConfigForAssistant(
|
|
303
|
+
tenantId: string,
|
|
304
|
+
ownerAssistantId: string,
|
|
305
|
+
id: string,
|
|
306
|
+
): Promise<boolean>;
|
|
307
|
+
|
|
308
|
+
/** Delete every personal config owned by one assistant; returns the count. */
|
|
309
|
+
deleteConfigsForAssistant(
|
|
310
|
+
tenantId: string,
|
|
311
|
+
ownerAssistantId: string,
|
|
312
|
+
): Promise<number>;
|
|
313
|
+
|
|
314
|
+
/** Check whether a personal config id exists for one assistant. */
|
|
315
|
+
hasConfigForAssistant(
|
|
316
|
+
tenantId: string,
|
|
317
|
+
ownerAssistantId: string,
|
|
318
|
+
id: string,
|
|
319
|
+
): Promise<boolean>;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** A store that serves both the tenant and personal MCP data domains. */
|
|
323
|
+
export type McpConfigStoreWithPersonal =
|
|
324
|
+
McpServerConfigStore & PersonalMcpServerConfigStore;
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Narrow a store to the personal MCP surface at runtime.
|
|
328
|
+
*
|
|
329
|
+
* Custom hosts may register a tenant-only MCP store; callers use this guard to
|
|
330
|
+
* degrade gracefully instead of assuming the personal methods exist.
|
|
331
|
+
*/
|
|
332
|
+
export function isPersonalMcpServerConfigStore(
|
|
333
|
+
store: McpServerConfigStore,
|
|
334
|
+
): store is McpConfigStoreWithPersonal {
|
|
335
|
+
const candidate = store as Partial<PersonalMcpServerConfigStore>;
|
|
336
|
+
return (
|
|
337
|
+
typeof candidate.getAllConfigsForAssistant === "function" &&
|
|
338
|
+
typeof candidate.getAllPersonalConfigsWithoutTenant === "function" &&
|
|
339
|
+
typeof candidate.getConfigByIdForAssistant === "function" &&
|
|
340
|
+
typeof candidate.getConfigByKeyForAssistant === "function" &&
|
|
341
|
+
typeof candidate.createConfigForAssistant === "function" &&
|
|
342
|
+
typeof candidate.updateConfigForAssistant === "function" &&
|
|
343
|
+
typeof candidate.deleteConfigForAssistant === "function" &&
|
|
344
|
+
typeof candidate.deleteConfigsForAssistant === "function" &&
|
|
345
|
+
typeof candidate.hasConfigForAssistant === "function"
|
|
346
|
+
);
|
|
347
|
+
}
|
package/src/McpUiProtocol.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { LLMConfig } from "./ModelLatticeProtocol";
|
|
11
|
+
import { PLATFORM_TENANT_ID } from "./PlatformOpsProtocol";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Wire protocol used to talk to the upstream provider.
|
|
@@ -65,6 +66,20 @@ export const DEFAULT_MODEL_KEY = "default";
|
|
|
65
66
|
export const EMBEDDING_DEFAULT_KEY = "default:embedding";
|
|
66
67
|
export const ASR_DEFAULT_KEY = "default:asr";
|
|
67
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Reserved tenant id for the platform-owned model provider catalog.
|
|
71
|
+
*
|
|
72
|
+
* The platform catalog lives in the same encrypted `modelProvider` store as a
|
|
73
|
+
* tenant's own providers, under this reserved id. It is deliberately distinct
|
|
74
|
+
* from the deployment `"default"` namespace, which holds the models registered
|
|
75
|
+
* from environment configuration at boot.
|
|
76
|
+
*
|
|
77
|
+
* Resolution uses it as the second step: a tenant with providers of its own
|
|
78
|
+
* never reaches it, a tenant with none falls back to it while it has providers,
|
|
79
|
+
* and only an empty platform catalog falls through to the deployment namespace.
|
|
80
|
+
*/
|
|
81
|
+
export const PLATFORM_MODEL_TENANT_ID = PLATFORM_TENANT_ID;
|
|
82
|
+
|
|
68
83
|
/**
|
|
69
84
|
* Build the tenant-scoped model key.
|
|
70
85
|
*
|
|
@@ -445,11 +460,12 @@ export interface ModelSelection {
|
|
|
445
460
|
*/
|
|
446
461
|
kind?: ModelKind;
|
|
447
462
|
/**
|
|
448
|
-
* Whether this is the tenant's default model.
|
|
463
|
+
* Whether this is the tenant's default model of its kind.
|
|
449
464
|
*
|
|
450
|
-
*
|
|
451
|
-
*
|
|
452
|
-
*
|
|
465
|
+
* The flag is scoped per *(tenant, kind)*: at most one chat model, one
|
|
466
|
+
* embedding model, and one ASR model may carry it. Omitted means "leave the
|
|
467
|
+
* stored flag alone"; a default can only be replaced, never dropped by
|
|
468
|
+
* omission — see `ModelProviderStore.getDefaultModel`.
|
|
453
469
|
*/
|
|
454
470
|
isDefault?: boolean;
|
|
455
471
|
}
|
package/src/OpenProtocol.ts
CHANGED
|
@@ -18,7 +18,7 @@ export interface OpenGrantSelector {
|
|
|
18
18
|
export interface OpenGrant {
|
|
19
19
|
domain: string;
|
|
20
20
|
/**
|
|
21
|
-
* Action names (
|
|
21
|
+
* Action names (collection: ["search_collection"]) or instance ids (agent: [assistantId]).
|
|
22
22
|
* Absent/empty = every action in the domain.
|
|
23
23
|
*/
|
|
24
24
|
items?: string[];
|
|
@@ -71,7 +71,7 @@ export type OpenCapabilitySource = "builtin" | "plugin" | "agent";
|
|
|
71
71
|
|
|
72
72
|
/** A selectable grant item: an action name or an instance id. */
|
|
73
73
|
export interface OpenCatalogItem {
|
|
74
|
-
/** Grant item value: action name (
|
|
74
|
+
/** Grant item value: action name (collection → "search_collection") or instance id (agent → assistantId). */
|
|
75
75
|
id: string;
|
|
76
76
|
/** Full MCP tool name when this item is exclusively exposed (informational). */
|
|
77
77
|
toolName: string;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/** Actor on whose behalf a platform-level audit record was produced. */
|
|
2
|
+
export type PlatformAuditInitiator =
|
|
3
|
+
| { type: "human"; userId: string; role: "owner" | "admin" | "auditor" }
|
|
4
|
+
| { type: "bootstrap" }
|
|
5
|
+
| { type: "system"; component: string };
|
|
6
|
+
|
|
7
|
+
/** Execution surface that performed the audited platform operation. */
|
|
8
|
+
export type PlatformAuditExecutor =
|
|
9
|
+
| { type: "admin_center"; route: string }
|
|
10
|
+
| {
|
|
11
|
+
type: "ops_agent";
|
|
12
|
+
agentId: "platform-ops";
|
|
13
|
+
threadId: string;
|
|
14
|
+
runId: string;
|
|
15
|
+
toolName: string;
|
|
16
|
+
}
|
|
17
|
+
| { type: "bootstrap" }
|
|
18
|
+
| { type: "system"; component: string };
|
|
19
|
+
|
|
20
|
+
/** Entry point that originated a platform-level audit record. */
|
|
21
|
+
export type PlatformAuditSource =
|
|
22
|
+
| "admin_center"
|
|
23
|
+
| "ops_agent"
|
|
24
|
+
| "bootstrap"
|
|
25
|
+
| "system";
|
|
26
|
+
|
|
27
|
+
/** Kind of platform operation captured by an audit record. */
|
|
28
|
+
export type PlatformAuditAction = "write" | "playbook";
|
|
29
|
+
|
|
30
|
+
/** Terminal outcome of the audited operation. */
|
|
31
|
+
export type PlatformAuditStatus = "ok" | "error" | "cancelled";
|
|
32
|
+
|
|
33
|
+
/** Input accepted when appending a platform audit record. */
|
|
34
|
+
export interface PlatformAuditAppendInput {
|
|
35
|
+
initiator: PlatformAuditInitiator;
|
|
36
|
+
source: PlatformAuditSource;
|
|
37
|
+
executor: PlatformAuditExecutor;
|
|
38
|
+
tenantId?: string;
|
|
39
|
+
action: PlatformAuditAction;
|
|
40
|
+
status: PlatformAuditStatus;
|
|
41
|
+
summary: Record<string, unknown>;
|
|
42
|
+
before?: Record<string, unknown>;
|
|
43
|
+
after?: Record<string, unknown>;
|
|
44
|
+
errorCode?: string;
|
|
45
|
+
durationMs: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Persisted platform audit record. */
|
|
49
|
+
export interface PlatformAuditRecord extends PlatformAuditAppendInput {
|
|
50
|
+
id: string;
|
|
51
|
+
createdAt: Date;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Filter and pagination options for querying platform audit records.
|
|
56
|
+
*
|
|
57
|
+
* Results are ordered newest-first by `createdAt` descending, then by `id`
|
|
58
|
+
* descending as a total-order tie-break. `from` is inclusive and `to` is
|
|
59
|
+
* exclusive on `createdAt`. `limit` defaults to 100; negative `offset` and
|
|
60
|
+
* `limit` values are clamped to 0. `initiatorUserId` matches human initiators
|
|
61
|
+
* only.
|
|
62
|
+
*/
|
|
63
|
+
export interface PlatformAuditQuery {
|
|
64
|
+
initiatorUserId?: string;
|
|
65
|
+
source?: PlatformAuditSource;
|
|
66
|
+
tenantId?: string;
|
|
67
|
+
action?: PlatformAuditAction;
|
|
68
|
+
status?: PlatformAuditStatus;
|
|
69
|
+
from?: string;
|
|
70
|
+
to?: string;
|
|
71
|
+
limit?: number;
|
|
72
|
+
offset?: number;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Persistence operations for platform audit records. */
|
|
76
|
+
export interface PlatformAuditStore {
|
|
77
|
+
append(record: PlatformAuditAppendInput): Promise<PlatformAuditRecord>;
|
|
78
|
+
get(id: string): Promise<PlatformAuditRecord | null>;
|
|
79
|
+
query(params: PlatformAuditQuery): Promise<PlatformAuditRecord[]>;
|
|
80
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/** Maximum stored size of one branding customCss field (64 KiB). */
|
|
2
|
+
export const MAX_CUSTOM_CSS_LENGTH = 65_536;
|
|
3
|
+
|
|
4
|
+
const IDENTIFIER_CHAR = /[A-Za-z0-9_-]/;
|
|
5
|
+
|
|
6
|
+
function skipQuoted(css: string, start: number): number {
|
|
7
|
+
const quote = css[start];
|
|
8
|
+
let index = start + 1;
|
|
9
|
+
while (index < css.length) {
|
|
10
|
+
if (css[index] === "\\") {
|
|
11
|
+
index += 2;
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
if (css[index] === quote) return index + 1;
|
|
15
|
+
index += 1;
|
|
16
|
+
}
|
|
17
|
+
return css.length;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface DecodedEscape {
|
|
21
|
+
value: string;
|
|
22
|
+
next: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Decodes one CSS backslash escape starting at `index` (a backslash). */
|
|
26
|
+
function decodeCssEscapeAt(css: string, index: number): DecodedEscape {
|
|
27
|
+
let cursor = index + 1;
|
|
28
|
+
if (cursor >= css.length) return { value: "", next: cursor };
|
|
29
|
+
const escaped = css[cursor];
|
|
30
|
+
if (escaped === "\n" || escaped === "\f" || escaped === "\r") {
|
|
31
|
+
if (escaped === "\r" && css[cursor + 1] === "\n") cursor += 1;
|
|
32
|
+
return { value: "", next: cursor + 1 };
|
|
33
|
+
}
|
|
34
|
+
const hex = /^[0-9a-fA-F]{1,6}/.exec(css.slice(cursor));
|
|
35
|
+
if (hex) {
|
|
36
|
+
cursor += hex[0].length;
|
|
37
|
+
if (cursor < css.length && /\s/.test(css[cursor])) {
|
|
38
|
+
if (css[cursor] === "\r" && css[cursor + 1] === "\n") cursor += 1;
|
|
39
|
+
cursor += 1;
|
|
40
|
+
}
|
|
41
|
+
const codePoint = Number.parseInt(hex[0], 16);
|
|
42
|
+
if (
|
|
43
|
+
codePoint === 0 ||
|
|
44
|
+
codePoint > 0x10ffff ||
|
|
45
|
+
(codePoint >= 0xd800 && codePoint <= 0xdfff)
|
|
46
|
+
) {
|
|
47
|
+
return { value: "\uFFFD", next: cursor };
|
|
48
|
+
}
|
|
49
|
+
return { value: String.fromCodePoint(codePoint), next: cursor };
|
|
50
|
+
}
|
|
51
|
+
return { value: escaped, next: cursor + 1 };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Reads a CSS identifier, decoding escapes, so `u\72l` is recognized. */
|
|
55
|
+
function readDecodedIdentifier(
|
|
56
|
+
css: string,
|
|
57
|
+
start: number,
|
|
58
|
+
): { value: string; next: number } | null {
|
|
59
|
+
let value = "";
|
|
60
|
+
let index = start;
|
|
61
|
+
let consumed = false;
|
|
62
|
+
while (index < css.length) {
|
|
63
|
+
const current = css[index];
|
|
64
|
+
if (current === "\\") {
|
|
65
|
+
const decoded = decodeCssEscapeAt(css, index);
|
|
66
|
+
value += decoded.value;
|
|
67
|
+
index = decoded.next;
|
|
68
|
+
consumed = true;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (!IDENTIFIER_CHAR.test(current) && current.charCodeAt(0) < 0x80) break;
|
|
72
|
+
value += current;
|
|
73
|
+
index += 1;
|
|
74
|
+
consumed = true;
|
|
75
|
+
}
|
|
76
|
+
return consumed ? { value, next: index } : null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function matchUrlToken(css: string, start: number): number | null {
|
|
80
|
+
if (start > 0 && IDENTIFIER_CHAR.test(css[start - 1])) return null;
|
|
81
|
+
const identifier = readDecodedIdentifier(css, start);
|
|
82
|
+
if (!identifier || identifier.value.toLowerCase() !== "url") return null;
|
|
83
|
+
let index = identifier.next;
|
|
84
|
+
while (index < css.length && /\s/.test(css[index])) index += 1;
|
|
85
|
+
if (css[index] !== "(") return null;
|
|
86
|
+
return index + 1;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function skipUrlContents(css: string, start: number): number | null {
|
|
90
|
+
let index = start;
|
|
91
|
+
while (index < css.length && /\s/.test(css[index])) index += 1;
|
|
92
|
+
if (css[index] === '"' || css[index] === "'") {
|
|
93
|
+
index = skipQuoted(css, index);
|
|
94
|
+
while (index < css.length && /\s/.test(css[index])) index += 1;
|
|
95
|
+
if (css[index] !== ")") return null;
|
|
96
|
+
return index + 1;
|
|
97
|
+
}
|
|
98
|
+
const end = css.indexOf(")", index);
|
|
99
|
+
return end === -1 ? null : end + 1;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Removes quoted strings, unquoted or quoted `url(...)` contents, and
|
|
104
|
+
* comments. `url(...)` contents are removed before comment scanning so a
|
|
105
|
+
* `/*` sequence inside a URL cannot swallow an `@import` that follows it.
|
|
106
|
+
*/
|
|
107
|
+
function stripCssForImportScan(css: string): string {
|
|
108
|
+
let out = "";
|
|
109
|
+
let index = 0;
|
|
110
|
+
while (index < css.length) {
|
|
111
|
+
const current = css[index];
|
|
112
|
+
const next = css[index + 1];
|
|
113
|
+
if (current === "/" && next === "*") {
|
|
114
|
+
const end = css.indexOf("*/", index + 2);
|
|
115
|
+
index = end === -1 ? css.length : end + 2;
|
|
116
|
+
out += " ";
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (current === '"' || current === "'") {
|
|
120
|
+
index = skipQuoted(css, index);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const urlContentStart = matchUrlToken(css, index);
|
|
124
|
+
if (urlContentStart !== null) {
|
|
125
|
+
const urlEnd = skipUrlContents(css, urlContentStart);
|
|
126
|
+
if (urlEnd !== null) {
|
|
127
|
+
index = urlEnd;
|
|
128
|
+
out += "url()";
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
out += current;
|
|
133
|
+
index += 1;
|
|
134
|
+
}
|
|
135
|
+
return out;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Decodes CSS backslash escapes so encoded directives become visible. */
|
|
139
|
+
function decodeCssEscapes(css: string): string {
|
|
140
|
+
let out = "";
|
|
141
|
+
let index = 0;
|
|
142
|
+
while (index < css.length) {
|
|
143
|
+
const current = css[index];
|
|
144
|
+
if (current !== "\\") {
|
|
145
|
+
out += current;
|
|
146
|
+
index += 1;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const decoded = decodeCssEscapeAt(css, index);
|
|
150
|
+
out += decoded.value;
|
|
151
|
+
index = decoded.next;
|
|
152
|
+
}
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** True when the CSS contains an `@import` outside comments/strings/urls. */
|
|
157
|
+
export function hasCssImport(css: string): boolean {
|
|
158
|
+
const stripped = stripCssForImportScan(css);
|
|
159
|
+
return /@import\b/i.test(decodeCssEscapes(stripped));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** True when the CSS can terminate the injected `<style>` element. */
|
|
163
|
+
export function hasStyleBreakout(css: string): boolean {
|
|
164
|
+
return /<\/style/i.test(css);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Result of validating a customCss value. */
|
|
168
|
+
export type CustomCssValidation =
|
|
169
|
+
| { ok: true }
|
|
170
|
+
| { ok: false; reason: "length" | "import" | "breakout" };
|
|
171
|
+
|
|
172
|
+
/** Validates a customCss value against the v1 rules. */
|
|
173
|
+
export function validateCustomCss(value: unknown): CustomCssValidation {
|
|
174
|
+
if (typeof value !== "string" || value.length > MAX_CUSTOM_CSS_LENGTH) {
|
|
175
|
+
return { ok: false, reason: "length" };
|
|
176
|
+
}
|
|
177
|
+
if (hasCssImport(value)) return { ok: false, reason: "import" };
|
|
178
|
+
if (hasStyleBreakout(value)) return { ok: false, reason: "breakout" };
|
|
179
|
+
return { ok: true };
|
|
180
|
+
}
|
|
@@ -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";
|
|
@@ -10,6 +10,7 @@ export interface PlatformBranding {
|
|
|
10
10
|
backgroundColor?: string;
|
|
11
11
|
loginTitle?: string;
|
|
12
12
|
loginSubtitle?: string;
|
|
13
|
+
customCss?: string;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
/** Host-scoped branding and public endpoint overrides. */
|
|
@@ -36,15 +37,23 @@ export interface ResolvedPlatformBranding {
|
|
|
36
37
|
publicConsoleUrl?: string;
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
/** Platform override for one gateway rate-limit policy. */
|
|
41
|
+
export interface PlatformRateLimitPolicyOverride {
|
|
42
|
+
/** New fixed-window request limit. Omitted keeps the deployment limit. */
|
|
43
|
+
limit?: number;
|
|
44
|
+
/** Set false to disable this policy. Omitted keeps the deployment state. */
|
|
45
|
+
enabled?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
39
48
|
/** Persisted, partial platform settings document managed by platform admins. */
|
|
40
49
|
export interface PlatformSettingsDocument {
|
|
41
50
|
auth?: { emailCompletionEnabled?: boolean };
|
|
42
51
|
invite?: { defaultExpiresInHours?: number; defaultMaxUses?: number };
|
|
43
52
|
rateLimits?: {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
53
|
+
/** Per-policy platform overrides keyed by policy name. */
|
|
54
|
+
policies?: Record<string, PlatformRateLimitPolicyOverride>;
|
|
55
|
+
/** PATCH-only command: remove platform overrides for these policies. */
|
|
56
|
+
resetPolicies?: string[];
|
|
48
57
|
maxActiveRunTasksPerTenant?: number | null;
|
|
49
58
|
};
|
|
50
59
|
branding?: PlatformBrandingSettings;
|
|
@@ -88,6 +97,8 @@ export interface PlatformSettingsProvider {
|
|
|
88
97
|
getEffective(): EffectivePlatformSettings;
|
|
89
98
|
getInviteDefaults(): EffectivePlatformSettings["invite"];
|
|
90
99
|
getRateLimits(): EffectivePlatformSettings["rateLimits"];
|
|
100
|
+
/** Platform-only policy overrides; absent for consumers that do not need them. */
|
|
101
|
+
getRateLimitPolicyOverrides?(): Record<string, PlatformRateLimitPolicyOverride>;
|
|
91
102
|
}
|
|
92
103
|
|
|
93
104
|
/** Persistence operations for platform settings with version CAS. */
|
|
@@ -128,6 +139,9 @@ export const PLATFORM_SETTINGS_DEFAULTS = {
|
|
|
128
139
|
/** Branding used when neither the platform default nor a domain overrides it. */
|
|
129
140
|
export const DEFAULT_PLATFORM_BRANDING: PlatformBranding = {
|
|
130
141
|
brandName: "AlphaFina",
|
|
142
|
+
logoUrl: "/logo.png",
|
|
143
|
+
primaryColor: "#5b50c6",
|
|
144
|
+
backgroundColor: "#ffffff",
|
|
131
145
|
};
|
|
132
146
|
|
|
133
147
|
/**
|