@40rty/ams-ui 0.2.2 → 0.3.1

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.
@@ -0,0 +1,58 @@
1
+ 'use client';
2
+
3
+ // src/shell/host-shell-store.ts
4
+ import * as React from "react";
5
+ var state = { islands: 0, islandSlot: null, panelSlot: null };
6
+ var listeners = /* @__PURE__ */ new Set();
7
+ var SERVER_STATE = { islands: 0, islandSlot: null, panelSlot: null };
8
+ function update(next) {
9
+ state = {
10
+ islands: next.islands === void 0 ? state.islands : next.islands,
11
+ islandSlot: next.islandSlot === void 0 ? state.islandSlot : next.islandSlot,
12
+ panelSlot: next.panelSlot === void 0 ? state.panelSlot : next.panelSlot
13
+ };
14
+ listeners.forEach((listener) => listener());
15
+ }
16
+ function subscribe(listener) {
17
+ listeners.add(listener);
18
+ return () => listeners.delete(listener);
19
+ }
20
+ function useHostShell() {
21
+ return React.useSyncExternalStore(subscribe, () => state, () => SERVER_STATE);
22
+ }
23
+ function useRegisterIsland() {
24
+ React.useEffect(() => {
25
+ update({ islands: state.islands + 1 });
26
+ return () => update({ islands: state.islands - 1 });
27
+ }, []);
28
+ }
29
+ function useIslandSlot(el) {
30
+ React.useEffect(() => {
31
+ if (el === null) return;
32
+ update({ islandSlot: el });
33
+ return () => {
34
+ if (state.islandSlot === el) update({ islandSlot: null });
35
+ };
36
+ }, [el]);
37
+ }
38
+ function usePanelSlot(el, active) {
39
+ React.useEffect(() => {
40
+ if (el === null || !active) return;
41
+ update({ panelSlot: el });
42
+ return () => {
43
+ if (state.panelSlot === el) update({ panelSlot: null });
44
+ };
45
+ }, [el, active]);
46
+ }
47
+ function stopHostKeys(event) {
48
+ event.stopPropagation();
49
+ event.nativeEvent.stopImmediatePropagation();
50
+ }
51
+
52
+ export {
53
+ useHostShell,
54
+ useRegisterIsland,
55
+ useIslandSlot,
56
+ usePanelSlot,
57
+ stopHostKeys
58
+ };
@@ -0,0 +1,218 @@
1
+ 'use client';
2
+
3
+ // src/agent/presence/read-data.ts
4
+ function factRegister(fact) {
5
+ if (fact.provenance === "recalled") return "recalled";
6
+ if (fact.provenance !== void 0) return "inferred";
7
+ return fact.tier === "profile" ? "recalled" : "inferred";
8
+ }
9
+ function readFacts(frame) {
10
+ const raw = frame.data === void 0 ? void 0 : Reflect.get(frame.data, "facts");
11
+ if (!Array.isArray(raw)) return [];
12
+ const out = [];
13
+ for (const f of raw) {
14
+ if (typeof f !== "object" || f === null) continue;
15
+ const label = Reflect.get(f, "label");
16
+ const value = Reflect.get(f, "value");
17
+ if (typeof label !== "string" || typeof value !== "string") continue;
18
+ const tier = Reflect.get(f, "tier");
19
+ const scope = Reflect.get(f, "scope");
20
+ out.push({
21
+ label,
22
+ value,
23
+ ...tier === "session" || tier === "profile" ? { tier } : {},
24
+ ...typeof scope === "string" && scope.length > 0 ? { scope } : {}
25
+ });
26
+ }
27
+ return out;
28
+ }
29
+ function factIdentity(fact) {
30
+ return `${fact.label}=${fact.value}`;
31
+ }
32
+ function readLabel(frame) {
33
+ if (frame.data === void 0) return "";
34
+ const l = Reflect.get(frame.data, "label");
35
+ return typeof l === "string" ? l : "";
36
+ }
37
+
38
+ // src/agent/presence/use-forget-fact.ts
39
+ import * as React from "react";
40
+ import { useFourtySession, useOptimisticFlowSet, useReconcileFlowSet, PRESENCE_FACT_DISMISS_SIGNAL } from "@40rty/ams-sdk";
41
+ var DISMISSED_FLOW = "presence.dismissed";
42
+ function useVisibleFacts(frame) {
43
+ return useVisibleFactList(frame !== null ? readFacts(frame) : []);
44
+ }
45
+ function useVisibleFactList(facts) {
46
+ const dismissed = useOptimisticFlowSet(DISMISSED_FLOW);
47
+ return facts.filter((f) => !dismissed.has(f.label));
48
+ }
49
+ var useUndismissedFacts = useVisibleFactList;
50
+ function useForgetFact() {
51
+ const { sendImmediateSignal } = useFourtySession();
52
+ const dismissed = useOptimisticFlowSet(DISMISSED_FLOW);
53
+ const forget = React.useCallback(
54
+ (f) => {
55
+ dismissed.add(f.label);
56
+ sendImmediateSignal({ type: PRESENCE_FACT_DISMISS_SIGNAL, payload: { label: f.label, value: f.value } });
57
+ },
58
+ [dismissed, sendImmediateSignal]
59
+ );
60
+ return { forget };
61
+ }
62
+ function useReconcileDismissed(presentLabels) {
63
+ useReconcileFlowSet(DISMISSED_FLOW, presentLabels);
64
+ }
65
+ function useDismissedLabels() {
66
+ return useOptimisticFlowSet(DISMISSED_FLOW);
67
+ }
68
+
69
+ // src/agent/presence/fact-rail.ts
70
+ var PRESENCE_FACT_LIMIT = 3;
71
+ var PRESENCE_DURABLE_SLOTS = 1;
72
+ function rankFactElements(facts, liveTurnId) {
73
+ const thisTurn = [];
74
+ const profile = [];
75
+ const older = [];
76
+ for (const el of facts) {
77
+ if (liveTurnId !== void 0 && el.turnId === liveTurnId) thisTurn.push(el);
78
+ else if (el.tier === "profile") profile.push(el);
79
+ else older.push(el);
80
+ }
81
+ return [...thisTurn, ...profile, ...newestReadFirst(older)];
82
+ }
83
+ function newestReadFirst(facts) {
84
+ const reads = /* @__PURE__ */ new Map();
85
+ for (const el of facts) {
86
+ const held = reads.get(el.turnId);
87
+ if (held === void 0) reads.set(el.turnId, [el]);
88
+ else held.push(el);
89
+ }
90
+ const out = [];
91
+ for (const read of [...reads.values()].reverse()) out.push(...read);
92
+ return out;
93
+ }
94
+ function selectPresenceFacts(facts, liveTurnId) {
95
+ return rankFactElements(facts, liveTurnId);
96
+ }
97
+ function isDurable(fact) {
98
+ return fact.tier === "profile";
99
+ }
100
+ function capWithDurableFloor(facts, limit) {
101
+ const head = facts.slice(0, limit);
102
+ if (limit < PRESENCE_DURABLE_SLOTS) return head;
103
+ if (head.some(isDurable)) return head;
104
+ const durable = facts.slice(limit).find(isDurable);
105
+ if (durable === void 0) return head;
106
+ return [...head.slice(0, limit - PRESENCE_DURABLE_SLOTS), durable];
107
+ }
108
+
109
+ // src/agent/presence/element-view.ts
110
+ function toFact(el) {
111
+ if (el.scope === void 0) {
112
+ return { label: el.label, value: el.value, tier: el.tier, provenance: el.provenance };
113
+ }
114
+ return {
115
+ label: el.label,
116
+ value: el.value,
117
+ tier: el.tier,
118
+ provenance: el.provenance,
119
+ scope: el.scope
120
+ };
121
+ }
122
+ function isWorthShowing(el) {
123
+ return el.provenance !== "stated";
124
+ }
125
+ function derivePresenceView(elements, liveTurnId) {
126
+ const sources = [];
127
+ const showable = [];
128
+ const heldLabels = [];
129
+ let voice = "";
130
+ let ask;
131
+ let concession;
132
+ for (const el of elements) {
133
+ switch (el.kind) {
134
+ case "source":
135
+ sources.push(el);
136
+ break;
137
+ case "fact":
138
+ heldLabels.push(el.label);
139
+ if (isWorthShowing(el)) showable.push(el);
140
+ break;
141
+ case "voice":
142
+ if (el.register === "lead") voice = el.text;
143
+ break;
144
+ case "ask":
145
+ ask = el;
146
+ break;
147
+ case "concession":
148
+ concession = el;
149
+ break;
150
+ }
151
+ }
152
+ const facts = selectPresenceFacts(showable, liveTurnId).map(toFact);
153
+ return { sources, facts, hiddenFacts: 0, heldLabels, voice, ask, concession };
154
+ }
155
+ function withCappedFacts(view, facts, reachable, limit) {
156
+ const drawn = capWithDurableFloor(facts, limit);
157
+ const shown = new Set(drawn.map(factIdentity));
158
+ return {
159
+ sources: view.sources,
160
+ facts: drawn,
161
+ // `+N` COUNTS WHAT THE BRIEF HOLDS AND THE BAND IS NOT SHOWING — the two are
162
+ // different lists, and counting the wrong one is a door onto an empty room.
163
+ // It was `facts.length - limit`: `facts` is the BAND's set, which includes
164
+ // the optimistic bridge (a pick shown before the agent's read lands), while
165
+ // the brief shows only what the agent knows. A visitor who picked a size got
166
+ // a "+4" whose destination held two entries. Counting the REACHABLE set that
167
+ // the band did not draw is exact by construction, whatever fills the slots.
168
+ hiddenFacts: reachable.filter((f) => !shown.has(factIdentity(f))).length,
169
+ heldLabels: view.heldLabels,
170
+ voice: view.voice,
171
+ ask: view.ask,
172
+ concession: view.concession
173
+ };
174
+ }
175
+ function viewIsEmpty(view) {
176
+ return view.sources.length === 0 && view.facts.length === 0 && view.voice.length === 0 && view.ask === void 0 && view.concession === void 0;
177
+ }
178
+ function viewHasHeld(view) {
179
+ return view.facts.length > 0 || view.voice.length > 0 || view.ask !== void 0;
180
+ }
181
+
182
+ // src/agent/presence/use-band-facts.ts
183
+ import * as React2 from "react";
184
+ import { usePresenceElements, usePresenceLiveTurn } from "@40rty/ams-sdk";
185
+ function useBandFacts() {
186
+ const elements = usePresenceElements();
187
+ const liveTurnId = usePresenceLiveTurn();
188
+ const rawView = React2.useMemo(
189
+ () => derivePresenceView(elements, liveTurnId),
190
+ [elements, liveTurnId]
191
+ );
192
+ useReconcileDismissed(rawView.heldLabels.length > 0 ? rawView.heldLabels : null);
193
+ const all = useVisibleFactList(rawView.facts);
194
+ const reachable = all;
195
+ const view = React2.useMemo(
196
+ () => withCappedFacts(rawView, all, reachable, PRESENCE_FACT_LIMIT),
197
+ [rawView, all]
198
+ );
199
+ return { view, all: reachable };
200
+ }
201
+
202
+ export {
203
+ factRegister,
204
+ readFacts,
205
+ factIdentity,
206
+ readLabel,
207
+ useVisibleFacts,
208
+ useVisibleFactList,
209
+ useUndismissedFacts,
210
+ useForgetFact,
211
+ useDismissedLabels,
212
+ PRESENCE_FACT_LIMIT,
213
+ PRESENCE_DURABLE_SLOTS,
214
+ derivePresenceView,
215
+ viewIsEmpty,
216
+ viewHasHeld,
217
+ useBandFacts
218
+ };
@@ -0,0 +1,286 @@
1
+ /* ============================================================================
2
+ <SpacefrontIsland /> — the AMS island for a host-owned page.
3
+ Published as `@40rty/ams-ui/island.css`. Plain CSS, no Tailwind, UNLAYERED:
4
+ a host's own unlayered globals beat anything in a cascade layer, so a layer
5
+ would lose to `form button { width: 100% }`.
6
+
7
+ HOST-PROOF. Every element is reset by `.fourty-si :is(…)` (0,1,1), which
8
+ beats a host's element globals (`input`, `form button`), and every rule
9
+ below is `.fourty-si .fourty-si__x` (0,2,0), which beats the reset and any
10
+ host rule short of two classes. The tests pin both numbers.
11
+
12
+ Themed ONLY through custom properties. The SHARED shell tokens come first —
13
+ the island, `thread-panel.css` and `presence.css` all read them, so a store
14
+ maps its design once:
15
+ --fourty-surface (#fff) fill
16
+ --fourty-fg (#111) text, hairlines, the send stamp
17
+ --fourty-accent (fg) hover / selected fill
18
+ --fourty-accent-fg (surface) text on the accent
19
+ --fourty-radius (16px) corner
20
+ --fourty-font-family (inherit)
21
+ Each island property below falls back to its shared token:
22
+ --fourty-island-surface (--fourty-surface)
23
+ --fourty-island-fg (--fourty-fg)
24
+ --fourty-island-radius (--fourty-radius)
25
+ --fourty-island-edge (1px hairline of fg)
26
+ --fourty-island-shadow (three-step lift)
27
+ --fourty-island-collapsed-surface (fg) pill fill
28
+ --fourty-island-collapsed-fg (surface) pill text
29
+ --fourty-island-accent (--fourty-accent)
30
+ --fourty-island-accent-fg (--fourty-accent-fg)
31
+ --fourty-island-error (#b42318)
32
+ --fourty-island-font-family (--fourty-font-family)
33
+ --fourty-island-offset-bottom (16px) clears a host bottom bar
34
+ --fourty-island-inset-left / -right (0) the column, container="viewport"
35
+ --fourty-island-max-width (640px)
36
+ --fourty-island-z-index (40)
37
+ ============================================================================ */
38
+
39
+ .fourty-si {
40
+ --_surface: var(--fourty-island-surface, var(--fourty-surface, #fff));
41
+ --_fg: var(--fourty-island-fg, var(--fourty-fg, #111));
42
+ --_accent: var(--fourty-island-accent, var(--fourty-accent, var(--_fg)));
43
+ --_accent-fg: var(--fourty-island-accent-fg, var(--fourty-accent-fg, var(--_surface)));
44
+ --_ease: cubic-bezier(0.22, 1, 0.36, 1);
45
+ position: fixed;
46
+ left: var(--fourty-island-inset-left, 0);
47
+ right: var(--fourty-island-inset-right, 0);
48
+ bottom: calc(var(--fourty-island-offset-bottom, 16px) + env(safe-area-inset-bottom, 0px));
49
+ z-index: var(--fourty-island-z-index, 40);
50
+ display: flex;
51
+ justify-content: center;
52
+ box-sizing: border-box;
53
+ padding: 0 16px;
54
+ pointer-events: none;
55
+ font-family: var(--fourty-island-font-family, var(--fourty-font-family, inherit));
56
+ font-size: 14px;
57
+ line-height: 1.4;
58
+ color: var(--_fg);
59
+ text-align: left;
60
+ }
61
+ .fourty-si[data-container='column'] {
62
+ position: sticky;
63
+ left: auto;
64
+ right: auto;
65
+ width: 100%;
66
+ }
67
+
68
+ /* The reset — the host's element globals stop here. */
69
+ .fourty-si :is(div, p, form, button, input, svg) {
70
+ all: unset;
71
+ box-sizing: border-box;
72
+ }
73
+ .fourty-si :focus-visible {
74
+ outline: 2px solid var(--_accent);
75
+ outline-offset: 2px;
76
+ }
77
+
78
+ .fourty-si .fourty-si__stack {
79
+ display: grid;
80
+ gap: 8px;
81
+ width: 100%;
82
+ max-width: var(--fourty-island-max-width, 640px);
83
+ pointer-events: auto;
84
+ animation: fourty-si-in 220ms var(--_ease);
85
+ }
86
+
87
+ /* Where <SpacefrontPresence /> attaches — above the chips and slab. */
88
+ .fourty-si .fourty-si__presence {
89
+ display: block;
90
+ }
91
+ .fourty-si .fourty-si__presence:empty {
92
+ display: none;
93
+ }
94
+
95
+ .fourty-si .fourty-si__chips {
96
+ display: flex;
97
+ flex-wrap: wrap;
98
+ justify-content: center;
99
+ gap: 8px;
100
+ }
101
+ .fourty-si .fourty-si__chip {
102
+ padding: 4px 14px;
103
+ border: 1px solid color-mix(in srgb, var(--_fg) 24%, transparent);
104
+ border-radius: 999px;
105
+ background: var(--_surface);
106
+ cursor: pointer;
107
+ transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
108
+ }
109
+
110
+ .fourty-si .fourty-si__slab {
111
+ display: flex;
112
+ flex-direction: column;
113
+ overflow: hidden;
114
+ border-radius: var(--fourty-island-radius, var(--fourty-radius, 16px));
115
+ background: var(--_surface);
116
+ box-shadow:
117
+ var(--fourty-island-edge, 0 0 0 1px color-mix(in srgb, var(--_fg) 14%, transparent)),
118
+ var(--fourty-island-shadow, 0 1px 2px color-mix(in srgb, var(--_fg) 14%, transparent),
119
+ 0 6px 16px -4px color-mix(in srgb, var(--_fg) 26%, transparent),
120
+ 0 20px 44px -12px color-mix(in srgb, var(--_fg) 36%, transparent));
121
+ }
122
+
123
+ /* The grip — the rulebook's shallow up-chevron, turned over while the thread is open. */
124
+ .fourty-si .fourty-si__grip {
125
+ display: flex;
126
+ justify-content: center;
127
+ padding: 8px 0;
128
+ cursor: pointer;
129
+ }
130
+ .fourty-si .fourty-si__chevron {
131
+ display: block;
132
+ width: 32px;
133
+ height: 5px;
134
+ overflow: visible;
135
+ color: color-mix(in srgb, var(--_fg) 42%, var(--_surface));
136
+ transition: transform 220ms var(--_ease);
137
+ }
138
+ .fourty-si .fourty-si__grip[aria-expanded='true'] .fourty-si__chevron {
139
+ transform: rotate(180deg);
140
+ }
141
+
142
+ .fourty-si .fourty-si__status {
143
+ display: block;
144
+ padding: 0 16px;
145
+ }
146
+ .fourty-si .fourty-si__latest {
147
+ display: -webkit-box;
148
+ -webkit-box-orient: vertical;
149
+ -webkit-line-clamp: 2;
150
+ overflow: hidden;
151
+ color: color-mix(in srgb, var(--_fg) 72%, transparent);
152
+ cursor: pointer;
153
+ }
154
+ .fourty-si .fourty-si__muted {
155
+ display: block;
156
+ color: color-mix(in srgb, var(--_fg) 60%, transparent);
157
+ }
158
+ .fourty-si .fourty-si__error {
159
+ display: block;
160
+ color: var(--fourty-island-error, #b42318);
161
+ }
162
+ .fourty-si .fourty-si__thread {
163
+ display: grid;
164
+ gap: 12px;
165
+ max-height: 16rem;
166
+ overflow-y: auto;
167
+ padding-bottom: 8px;
168
+ overscroll-behavior: contain;
169
+ }
170
+ .fourty-si .fourty-si__turn {
171
+ display: grid;
172
+ gap: 4px;
173
+ }
174
+ .fourty-si .fourty-si__turn p {
175
+ display: block;
176
+ }
177
+ .fourty-si .fourty-si__turn .fourty-si__asked {
178
+ color: color-mix(in srgb, var(--_fg) 55%, transparent);
179
+ }
180
+
181
+ /* Working — a light sweeping across the line while the turn is in flight. */
182
+ .fourty-si .fourty-si__working {
183
+ display: block;
184
+ color: transparent;
185
+ background: linear-gradient(100deg,
186
+ color-mix(in srgb, var(--_fg) 45%, transparent) 40%,
187
+ var(--_fg) 50%,
188
+ color-mix(in srgb, var(--_fg) 45%, transparent) 60%) 0 0 / 250% 100%;
189
+ -webkit-background-clip: text;
190
+ background-clip: text;
191
+ animation: fourty-si-shimmer 1.6s linear infinite;
192
+ }
193
+
194
+ .fourty-si .fourty-si__face {
195
+ display: flex;
196
+ align-items: center;
197
+ gap: 8px;
198
+ padding: 8px 12px 12px;
199
+ }
200
+ .fourty-si .fourty-si__field {
201
+ flex: 1 1 auto;
202
+ min-width: 0;
203
+ margin: 0;
204
+ border: 0;
205
+ background: transparent;
206
+ padding: 8px 4px;
207
+ font-size: 16px; /* under 16px iOS zooms the page on focus */
208
+ cursor: text;
209
+ }
210
+ .fourty-si .fourty-si__field::placeholder {
211
+ color: color-mix(in srgb, var(--_fg) 52%, transparent);
212
+ opacity: 1;
213
+ }
214
+
215
+ /* The send stamp — round, the slab's colours inverted. */
216
+ .fourty-si .fourty-si__stamp {
217
+ display: grid;
218
+ place-items: center;
219
+ flex: 0 0 34px;
220
+ width: 34px;
221
+ height: 34px;
222
+ margin: 0;
223
+ border: 0;
224
+ border-radius: 999px;
225
+ background: var(--_fg);
226
+ color: var(--_surface);
227
+ cursor: pointer;
228
+ transition: background-color 150ms ease, color 150ms ease, opacity 150ms ease;
229
+ }
230
+ .fourty-si .fourty-si__stamp svg {
231
+ display: block;
232
+ width: 16px;
233
+ height: 16px;
234
+ }
235
+ .fourty-si .fourty-si__stamp:disabled {
236
+ opacity: 0.4;
237
+ cursor: default;
238
+ }
239
+
240
+ /* The pill — 112 × 40, fully round (ISLAND_COLLAPSED_W/H). */
241
+ .fourty-si .fourty-si__pill {
242
+ display: grid;
243
+ place-items: center;
244
+ width: 112px;
245
+ height: 40px;
246
+ border-radius: 20px;
247
+ background: var(--fourty-island-collapsed-surface, var(--_fg));
248
+ color: var(--fourty-island-collapsed-fg, var(--_surface));
249
+ font-weight: 600;
250
+ box-shadow: 0 6px 16px -4px color-mix(in srgb, var(--_fg) 30%, transparent);
251
+ pointer-events: auto;
252
+ cursor: pointer;
253
+ animation: fourty-si-in 220ms var(--_ease);
254
+ }
255
+
256
+ @media (hover: hover) {
257
+ .fourty-si .fourty-si__chip:hover,
258
+ .fourty-si .fourty-si__stamp:not(:disabled):hover {
259
+ background: var(--_accent);
260
+ color: var(--_accent-fg);
261
+ border-color: var(--_accent);
262
+ }
263
+ }
264
+
265
+ @keyframes fourty-si-in {
266
+ from { opacity: 0; transform: translateY(8px) scale(0.98); }
267
+ }
268
+ @keyframes fourty-si-shimmer {
269
+ to { background-position: -150% 0; }
270
+ }
271
+
272
+ @media (prefers-reduced-motion: reduce) {
273
+ .fourty-si .fourty-si__stack,
274
+ .fourty-si .fourty-si__pill,
275
+ .fourty-si .fourty-si__working {
276
+ animation: none;
277
+ }
278
+ .fourty-si .fourty-si__working {
279
+ color: color-mix(in srgb, var(--_fg) 55%, transparent);
280
+ }
281
+ .fourty-si .fourty-si__chevron,
282
+ .fourty-si .fourty-si__chip,
283
+ .fourty-si .fourty-si__stamp {
284
+ transition: none;
285
+ }
286
+ }