@crossworks/client-types 0.230.43

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/LICENSE.md ADDED
@@ -0,0 +1,135 @@
1
+ # License
2
+
3
+ Mantle is **dual-licensed** by Cross Works Engineering (Pty) Ltd:
4
+
5
+ 1. **Public license — Functional Source License 1.1 (MIT Future), reproduced in
6
+ full below.** Free to use, self-host, modify, and run for any purpose that is
7
+ not a Competing Use (see the _Permitted Purpose_ clause). Two years after each
8
+ version is first published, that version automatically converts to the MIT
9
+ license.
10
+ 2. **Commercial license — see [`LICENSE-COMMERCIAL.md`](./LICENSE-COMMERCIAL.md).**
11
+ A paid agreement that lifts the FSL's _Competing Use_ restriction for partners
12
+ who want to embed Mantle in a commercial product or offer it as a service
13
+ during the two-year window. Contact **licensing@crossworks.engineering**.
14
+
15
+ For a plain-language explanation of how the two licenses fit together and what the
16
+ key terms mean, see [`LICENSING.md`](./LICENSING.md). Third-party open-source
17
+ components bundled with Mantle are attributed in
18
+ [`THIRD-PARTY-NOTICES.md`](./THIRD-PARTY-NOTICES.md).
19
+
20
+ The "Change Date" for each release is **two years after that release is first made
21
+ available** under this license; on the Change Date that release becomes available
22
+ under the MIT license (the _Grant of Future License_ below).
23
+
24
+ ---
25
+
26
+ # Functional Source License, Version 1.1, MIT Future License
27
+
28
+ ## Abbreviation
29
+
30
+ FSL-1.1-MIT
31
+
32
+ ## Notice
33
+
34
+ Copyright 2026 Cross Works Engineering (Pty) Ltd
35
+
36
+ ## Terms and Conditions
37
+
38
+ ### Licensor ("We")
39
+
40
+ The party offering the Software under these Terms and Conditions.
41
+
42
+ ### The Software
43
+
44
+ The "Software" is each version of the software that we make available under
45
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
46
+ Conditions with the Software.
47
+
48
+ ### License Grant
49
+
50
+ Subject to your compliance with this License Grant and the Patents,
51
+ Redistribution and Trademark clauses below, we hereby grant you the right to
52
+ use, copy, modify, create derivative works, publicly perform, publicly display
53
+ and redistribute the Software for any Permitted Purpose identified below.
54
+
55
+ ### Permitted Purpose
56
+
57
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
58
+ means making the Software available to others in a commercial product or
59
+ service that:
60
+
61
+ 1. substitutes for the Software;
62
+
63
+ 2. substitutes for any other product or service we offer using the Software
64
+ that exists as of the date we make the Software available; or
65
+
66
+ 3. offers the same or substantially similar functionality as the Software.
67
+
68
+ Permitted Purposes specifically include using the Software:
69
+
70
+ 1. for your internal use and access;
71
+
72
+ 2. for non-commercial education;
73
+
74
+ 3. for non-commercial research; and
75
+
76
+ 4. in connection with professional services that you provide to a licensee
77
+ using the Software in accordance with these Terms and Conditions.
78
+
79
+ ### Patents
80
+
81
+ To the extent your use for a Permitted Purpose would necessarily infringe our
82
+ patents, the license grant above includes a license under our patents. If you
83
+ make a claim against any party that the Software infringes or contributes to
84
+ the infringement of any patent, then your patent license to the Software ends
85
+ immediately.
86
+
87
+ ### Redistribution
88
+
89
+ The Terms and Conditions apply to all copies, modifications and derivatives of
90
+ the Software.
91
+
92
+ If you redistribute any copies, modifications or derivatives of the Software,
93
+ you must include a copy of or a link to these Terms and Conditions and not
94
+ remove any copyright notices provided in or with the Software.
95
+
96
+ ### Disclaimer
97
+
98
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
99
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
100
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
101
+
102
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
103
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
104
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
105
+
106
+ ### Trademarks
107
+
108
+ Except for displaying the License Details and identifying us as the origin of
109
+ the Software, you have no right under these Terms and Conditions to use our
110
+ trademarks, trade names, service marks or product names.
111
+
112
+ ## Grant of Future License
113
+
114
+ We hereby irrevocably grant you an additional license to use the Software under
115
+ the MIT license that is effective on the second anniversary of the date we make
116
+ the Software available. On or after that date, you may use the Software under
117
+ the MIT license, in which case the following will apply:
118
+
119
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
120
+ this software and associated documentation files (the "Software"), to deal in
121
+ the Software without restriction, including without limitation the rights to
122
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
123
+ of the Software, and to permit persons to whom the Software is furnished to do
124
+ so, subject to the following conditions:
125
+
126
+ The above copyright notice and this permission notice shall be included in all
127
+ copies or substantial portions of the Software.
128
+
129
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
130
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
131
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
132
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
133
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
134
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
135
+ SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@crossworks/client-types",
3
+ "version": "0.230.43",
4
+ "type": "module",
5
+ "main": "./src/index.ts",
6
+ "types": "./src/index.ts",
7
+ "exports": {
8
+ ".": "./src/index.ts",
9
+ "./*": "./src/*.ts"
10
+ },
11
+ "devDependencies": {
12
+ "@types/node": "^22.20.1"
13
+ },
14
+ "license": "SEE LICENSE IN LICENSE.md",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/crossworks-engineering/mantle"
18
+ },
19
+ "scripts": {
20
+ "typecheck": "tsc --noEmit"
21
+ }
22
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Aside — gradient styling helpers (the single source of truth for how an aside
3
+ * box is painted). Shared by the live editor NodeView (`aside-view.tsx`) and the
4
+ * server-side public renderer (`lib/render-page-doc.ts`) so an aside looks the
5
+ * same in both. Framework-free + pure (the random pickers run client-side only,
6
+ * on slash-insert / swatch-click), so this module is safe to import from a
7
+ * server file.
8
+ *
9
+ * The gradient is built from a SELECTED themed colour (`chart-1..5`, never a raw
10
+ * hex — themes redefine these vars) plus an `angle`. It blends the base colour
11
+ * into the cyclically-next chart colour and layers a soft radial glow whose
12
+ * corner tracks the angle, so each aside reads as a distinct, on-theme panel.
13
+ */
14
+
15
+ export const ASIDE_COLORS = ['chart-1', 'chart-2', 'chart-3', 'chart-4', 'chart-5'] as const;
16
+ export type AsideColor = (typeof ASIDE_COLORS)[number];
17
+
18
+ export const DEFAULT_ASIDE_COLOR: AsideColor = 'chart-1';
19
+ export const DEFAULT_ASIDE_ANGLE = 135;
20
+
21
+ export function normalizeAsideColor(v: unknown): AsideColor {
22
+ return (ASIDE_COLORS as readonly string[]).includes(v as string)
23
+ ? (v as AsideColor)
24
+ : DEFAULT_ASIDE_COLOR;
25
+ }
26
+
27
+ /** Wrap any value into a clean 0–359 integer angle. */
28
+ export function normalizeAsideAngle(v: unknown): number {
29
+ const n = Math.round(Number(v));
30
+ if (!Number.isFinite(n)) return DEFAULT_ASIDE_ANGLE;
31
+ return ((n % 360) + 360) % 360;
32
+ }
33
+
34
+ /** The cyclically-next chart colour — the gradient's second stop. */
35
+ function secondaryColor(color: AsideColor): AsideColor {
36
+ const i = ASIDE_COLORS.indexOf(color);
37
+ return ASIDE_COLORS[(i + 1) % ASIDE_COLORS.length]!;
38
+ }
39
+
40
+ const RADIAL_CORNERS = ['top left', 'top right', 'bottom right', 'bottom left'] as const;
41
+
42
+ /**
43
+ * The full `background` shorthand for an aside: a soft radial glow (corner
44
+ * derived from the angle) layered over a directional two-tone wash. Uses
45
+ * `color-mix` + theme vars so it tracks the active theme and light/dark.
46
+ */
47
+ export function asideBackground(color: AsideColor, angle: number): string {
48
+ const a = normalizeAsideAngle(angle);
49
+ const c1 = `var(--${color})`;
50
+ const c2 = `var(--${secondaryColor(color)})`;
51
+ const corner = RADIAL_CORNERS[Math.floor(a / 90) % 4]!;
52
+ const radial = `radial-gradient(circle at ${corner}, color-mix(in oklab, ${c2} 22%, transparent), transparent 62%)`;
53
+ const linear = `linear-gradient(${a}deg, color-mix(in oklab, ${c1} 16%, transparent), color-mix(in oklab, ${c2} 7%, transparent))`;
54
+ return `${radial}, ${linear}`;
55
+ }
56
+
57
+ /** A faint themed border that pairs with the gradient fill. */
58
+ export function asideBorderColor(color: AsideColor): string {
59
+ return `color-mix(in oklab, var(--${color}) 30%, transparent)`;
60
+ }
61
+
62
+ /** Random themed colour — used when inserting a fresh aside (client-side only). */
63
+ export function randomAsideColor(): AsideColor {
64
+ return ASIDE_COLORS[Math.floor(Math.random() * ASIDE_COLORS.length)]!;
65
+ }
66
+
67
+ /** Random gradient angle — used when inserting / reshuffling (client-side only). */
68
+ export function randomAsideAngle(): number {
69
+ return Math.floor(Math.random() * 360);
70
+ }
@@ -0,0 +1,49 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { ASSISTANT_TURN_MAX_CHARS, longMessageNoteTitle } from './assistant-limits';
3
+
4
+ describe('ASSISTANT_TURN_MAX_CHARS', () => {
5
+ it('is the number the turn route validates against', () => {
6
+ // Pinned deliberately: the composer offloads at this number and the route
7
+ // rejects above it. If they ever drift, a long paste 400s again.
8
+ expect(ASSISTANT_TURN_MAX_CHARS).toBe(20_000);
9
+ });
10
+ });
11
+
12
+ describe('longMessageNoteTitle', () => {
13
+ it('uses the first non-empty line', () => {
14
+ expect(longMessageNoteTitle('Feature Upgrade Roadmap\n\nbody text')).toBe(
15
+ 'Feature Upgrade Roadmap',
16
+ );
17
+ });
18
+
19
+ it('skips leading blank lines', () => {
20
+ expect(longMessageNoteTitle('\n\n \nThe actual title\nmore')).toBe('The actual title');
21
+ });
22
+
23
+ it('strips markdown heading, bullet and ordered-item punctuation', () => {
24
+ expect(longMessageNoteTitle('### Phase 2 — Size S/L')).toBe('Phase 2 — Size S/L');
25
+ expect(longMessageNoteTitle('- a bulleted opener')).toBe('a bulleted opener');
26
+ expect(longMessageNoteTitle('> quoted opener')).toBe('quoted opener');
27
+ expect(longMessageNoteTitle('1. first step')).toBe('first step');
28
+ });
29
+
30
+ it('skips a bare code fence and takes the line after it', () => {
31
+ expect(longMessageNoteTitle('```json\n{"a":1}')).toBe('{"a":1}');
32
+ });
33
+
34
+ it('truncates to the notes API title limit with an ellipsis', () => {
35
+ const title = longMessageNoteTitle('x'.repeat(500));
36
+ expect(title).toHaveLength(200);
37
+ expect(title.endsWith('…')).toBe(true);
38
+ });
39
+
40
+ it('keeps a title exactly at the limit intact', () => {
41
+ expect(longMessageNoteTitle('y'.repeat(200))).toBe('y'.repeat(200));
42
+ });
43
+
44
+ it('falls back when there is no usable line', () => {
45
+ expect(longMessageNoteTitle('')).toBe('Long message');
46
+ expect(longMessageNoteTitle('\n\n \n')).toBe('Long message');
47
+ expect(longMessageNoteTitle('```', 'Pasted text')).toBe('Pasted text');
48
+ });
49
+ });
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The size ceiling on one assistant turn's text, shared by the composer and the
3
+ * route that validates it.
4
+ *
5
+ * It used to live only in the route's zod schema. The composer had no idea it
6
+ * existed, so pasting a long plan cleared the box, dropped the message from the
7
+ * transcript, and surfaced zod's own words — "Too big: expected string to have
8
+ * <=20000 characters" — in 10px type beside the composer. From the user's seat a
9
+ * message simply vanished, and since a rejected turn writes NOTHING to
10
+ * `assistant_messages`, the whole failure was invisible server-side too. Both
11
+ * ends now read the same number, and the composer offloads rather than fails.
12
+ */
13
+
14
+ /** Max characters accepted for one turn's `text` — INCLUDING the context
15
+ * preamble and focus directive the composer appends, which is what the route
16
+ * actually measures. */
17
+ export const ASSISTANT_TURN_MAX_CHARS = 20_000;
18
+
19
+ /** Longest title the notes API accepts (`POST /api/notes`). */
20
+ const NOTE_TITLE_MAX = 200;
21
+
22
+ /**
23
+ * A note title for an offloaded over-long message: its first non-empty line,
24
+ * trimmed of markdown heading/quote/list punctuation so the title reads as
25
+ * prose. Falls back to a generic label when the body opens with no usable line
26
+ * (a bare code fence, say).
27
+ */
28
+ export function longMessageNoteTitle(body: string, fallback = 'Long message'): string {
29
+ for (const raw of body.split('\n')) {
30
+ const line = raw
31
+ .trim()
32
+ .replace(/^#{1,6}\s+/, '') // heading
33
+ .replace(/^[>*+-]\s+/, '') // quote / bullet
34
+ .replace(/^\d+[.)]\s+/, '') // ordered item
35
+ .replace(/^```.*$/, '') // fence opener
36
+ .trim();
37
+ if (!line) continue;
38
+ return line.length > NOTE_TITLE_MAX ? `${line.slice(0, NOTE_TITLE_MAX - 1)}…` : line;
39
+ }
40
+ return fallback;
41
+ }