@axiom-lattice/protocols 7.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axiom-lattice/protocols",
3
- "version": "7.3.0",
3
+ "version": "7.4.0",
4
4
  "description": "Unified protocol type definitions for Axiom Lattice framework",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -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
  */
@@ -53,6 +53,8 @@ export interface McpUiResourcePayload {
53
53
  csp?: McpUiCsp;
54
54
  permissions?: McpUiPermissions;
55
55
  prefersBorder?: boolean;
56
+ /** Built-in, trusted UI may run in the host origin (see PluginToolUi). */
57
+ trustedSameOrigin?: boolean;
56
58
  stale?: boolean;
57
59
  }
58
60
 
@@ -18,7 +18,7 @@ export interface OpenGrantSelector {
18
18
  export interface OpenGrant {
19
19
  domain: string;
20
20
  /**
21
- * Action names (kb: ["search"]) or instance ids (agent: [assistantId]).
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 (kb → "search") or instance id (agent → assistantId). */
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,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
+ }
@@ -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. */
@@ -138,6 +139,9 @@ export const PLATFORM_SETTINGS_DEFAULTS = {
138
139
  /** Branding used when neither the platform default nor a domain overrides it. */
139
140
  export const DEFAULT_PLATFORM_BRANDING: PlatformBranding = {
140
141
  brandName: "AlphaFina",
142
+ logoUrl: "/logo.png",
143
+ primaryColor: "#5b50c6",
144
+ backgroundColor: "#ffffff",
141
145
  };
142
146
 
143
147
  /**
@@ -100,6 +100,15 @@ export interface PluginToolUi {
100
100
  csp?: McpUiCsp;
101
101
  permissions?: McpUiPermissions;
102
102
  prefersBorder?: boolean;
103
+ /**
104
+ * Allow this UI to run in the same origin as the host.
105
+ *
106
+ * Only honored for built-in plugins (`meta.source` starts with `builtin:`);
107
+ * tenant sandbox plugins and external MCP servers never receive it. This
108
+ * lets a trusted first-party UI embed a same-origin console page without the
109
+ * opaque-origin sandbox blocking it.
110
+ */
111
+ trustedSameOrigin?: boolean;
103
112
  }
104
113
 
105
114
  /**
@@ -70,7 +70,7 @@ interface ShareRecordBase {
70
70
  passwordHash: string | null;
71
71
  expiresAt: Date | null;
72
72
  maxAccess: number | null;
73
- /** Extra Open-door grants appended to sandbox tokens (V1: kb read-only). */
73
+ /** Extra Open-door grants appended to sandbox tokens (V1: collection search read-only). */
74
74
  openGrants?: OpenGrant[];
75
75
  accessCount: number;
76
76
  revoked: boolean;
@@ -0,0 +1,103 @@
1
+ import {
2
+ MAX_CUSTOM_CSS_LENGTH,
3
+ hasCssImport,
4
+ hasStyleBreakout,
5
+ validateCustomCss,
6
+ } from "../PlatformBrandingCss";
7
+
8
+ describe("PlatformBrandingCss", () => {
9
+ it("accepts ordinary CSS including fonts and urls", () => {
10
+ expect(
11
+ validateCustomCss(
12
+ "@font-face { font-family: X; src: url('/x.woff2'); } #app { color: red; }",
13
+ ),
14
+ ).toEqual({ ok: true });
15
+ });
16
+
17
+ it("rejects @import outside comments and strings", () => {
18
+ expect(hasCssImport("@import url('x.css');")).toBe(true);
19
+ expect(hasCssImport("@IMPORT url('x.css');")).toBe(true);
20
+ expect(hasCssImport("/* @import url('x.css'); */")).toBe(false);
21
+ expect(hasCssImport('a::after { content: "@import"; }')).toBe(false);
22
+ });
23
+
24
+ it("detects CSS-escaped @import variants", () => {
25
+ expect(hasCssImport("@\\69 mport url(x.css);")).toBe(true);
26
+ expect(hasCssImport("@im\\port url(x.css);")).toBe(true);
27
+ expect(hasCssImport("@IM\\50 ORT url(x.css);")).toBe(true);
28
+ });
29
+
30
+ it("detects CSS-escaped url() tokens", () => {
31
+ expect(hasCssImport("u\\72l(/*)}@import url(//evil);")).toBe(true);
32
+ expect(hasCssImport("\\75 rl(/*)}@import url(//evil);")).toBe(true);
33
+ });
34
+
35
+ it("treats comments as token separators before url()", () => {
36
+ expect(hasCssImport('@import/**/url("x.css")')).toBe(true);
37
+ expect(hasCssImport('@import/*x*/url("x.css")')).toBe(true);
38
+ expect(hasCssImport('@IMPORT/**/URL("x.css")')).toBe(true);
39
+ });
40
+
41
+ it("keeps scanning after an unterminated url(", () => {
42
+ expect(hasCssImport("x{} url( } @import url(evil")).toBe(true);
43
+ });
44
+
45
+ it("ends an unquoted url() at the first closing parenthesis", () => {
46
+ expect(
47
+ hasCssImport('url(foo(bar) {} @import url("/evil.css"); )'),
48
+ ).toBe(true);
49
+ expect(
50
+ hasCssImport('a url(foo(bar) {} @import url("/evil.css"); )'),
51
+ ).toBe(true);
52
+ });
53
+
54
+ it("skips quoted url() content containing a closing parenthesis", () => {
55
+ expect(hasCssImport('url("a)b") @import url(evil);')).toBe(true);
56
+ });
57
+
58
+ it("ignores @import text inside a url() string", () => {
59
+ expect(validateCustomCss("a{background:url('@import')}")).toEqual({
60
+ ok: true,
61
+ });
62
+ });
63
+
64
+ it("does not let a comment opener inside url() swallow a later @import", () => {
65
+ expect(
66
+ hasCssImport("a{background:url(/x/*)}@import url(//evil.example/x.css);"),
67
+ ).toBe(true);
68
+ });
69
+
70
+ it("rejects style breakout sequences", () => {
71
+ expect(hasStyleBreakout("a { color: red } </style><script>")).toBe(true);
72
+ expect(hasStyleBreakout("a { color: red } </STYLE><script>")).toBe(true);
73
+ expect(hasStyleBreakout("a { color: red }")).toBe(false);
74
+ });
75
+
76
+ it("accepts exactly the maximum length", () => {
77
+ expect(validateCustomCss("a".repeat(MAX_CUSTOM_CSS_LENGTH))).toEqual({
78
+ ok: true,
79
+ });
80
+ });
81
+
82
+ it("rejects oversize and non-string values", () => {
83
+ expect(validateCustomCss("a".repeat(MAX_CUSTOM_CSS_LENGTH + 1))).toEqual({
84
+ ok: false,
85
+ reason: "length",
86
+ });
87
+ expect(validateCustomCss(null)).toEqual({ ok: false, reason: "length" });
88
+ expect(
89
+ validateCustomCss("@import " + "a".repeat(MAX_CUSTOM_CSS_LENGTH)),
90
+ ).toEqual({ ok: false, reason: "length" });
91
+ });
92
+
93
+ it("reports the first violated rule", () => {
94
+ expect(validateCustomCss("@import url('x.css');")).toEqual({
95
+ ok: false,
96
+ reason: "import",
97
+ });
98
+ expect(validateCustomCss("a{} </style>")).toEqual({
99
+ ok: false,
100
+ reason: "breakout",
101
+ });
102
+ });
103
+ });
package/src/index.ts CHANGED
@@ -116,5 +116,7 @@ export * from "./OpenProtocol";
116
116
  export * from "./McpUiProtocol";
117
117
  export * from "./ObservabilityDashboardProtocol";
118
118
  export * from "./PlatformSettingsProtocol";
119
+ export * from "./PlatformBrandingCss";
120
+ export * from "./AuthCssContract";
119
121
  export * from "./PlatformAuditProtocol";
120
122
  export * from "./PlatformOpsProtocol";