@blackbelt-technology/pi-dashboard-client-utils 0.8.0 → 0.10.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 +35 -3
- package/src/ActionList.tsx +54 -30
- package/src/ActionListMenuContext.ts +19 -0
- package/src/Dialog.tsx +38 -16
- package/src/LayerPortal.tsx +40 -6
- package/src/Popover.tsx +25 -23
- package/src/SearchableSelectDialog.tsx +94 -31
- package/src/StatusPill.tsx +28 -58
- package/src/ZoomControls.tsx +28 -15
- package/src/identity/dpop.ts +91 -0
- package/src/identity/login-flow.ts +197 -0
- package/src/identity/oidc-flow.ts +96 -0
- package/src/identity/pkce.ts +129 -0
- package/src/identity/token-store.ts +66 -0
- package/src/mdi-by-key.ts +90 -0
- package/src/minimal-chat/MinimalChatView.tsx +107 -14
- package/src/minimal-chat/index.ts +2 -0
- package/src/minimal-chat/live-tail-text.ts +27 -0
- package/src/minimal-chat/types.ts +26 -0
- package/src/tone.ts +28 -0
- package/src/useZoomPan.ts +33 -13
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OIDC public-client PKCE (RFC 7636) primitives for the browser identity plane
|
|
3
|
+
* (openspec §12.1 / design D-topology-B). Pure functions over WebCrypto —
|
|
4
|
+
* `globalThis.crypto` works in the browser and in the jsdom/Node test env.
|
|
5
|
+
*
|
|
6
|
+
* The verifier is a high-entropy random string; the challenge is
|
|
7
|
+
* `BASE64URL(SHA-256(verifier))` with method `S256` (the only method we send —
|
|
8
|
+
* `plain` is disallowed by RFC 9700 for public clients).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** A PKCE verifier/challenge pair. `method` is always `S256`. */
|
|
12
|
+
export interface PkcePair {
|
|
13
|
+
verifier: string;
|
|
14
|
+
challenge: string;
|
|
15
|
+
method: "S256";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Base64url (no padding) encode raw bytes — the RFC 7636 A-Z a-z 0-9 -_ set. */
|
|
19
|
+
function base64UrlEncode(bytes: Uint8Array): string {
|
|
20
|
+
let bin = "";
|
|
21
|
+
for (const b of bytes) bin += String.fromCharCode(b);
|
|
22
|
+
return btoa(bin).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Generate a code verifier: 32 random bytes → base64url (43 chars), inside the
|
|
27
|
+
* RFC 7636 43–128 length window.
|
|
28
|
+
*/
|
|
29
|
+
export function createCodeVerifier(): string {
|
|
30
|
+
const bytes = new Uint8Array(32);
|
|
31
|
+
crypto.getRandomValues(bytes);
|
|
32
|
+
return base64UrlEncode(bytes);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
// Pure-JS SHA-256 fallback (D17/R1). `crypto.subtle` exists only in secure
|
|
37
|
+
// contexts (HTTPS or localhost); on a plain-HTTP non-loopback origin — the
|
|
38
|
+
// legitimate remote topology-B case, e.g. `http://<tailnet-ip>:<port>` — it is
|
|
39
|
+
// undefined and S256 derivation would throw. FIPS 180-4, test-vectored against
|
|
40
|
+
// WebCrypto (`pkce-sha256-fallback.test.ts`). Used ONLY when `subtle` is
|
|
41
|
+
// absent; `crypto.getRandomValues` is never emulated (it exists everywhere).
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
|
|
44
|
+
// prettier-ignore
|
|
45
|
+
const K = new Uint32Array([
|
|
46
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
47
|
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
48
|
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
49
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
50
|
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
51
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
52
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
53
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
const rotr = (x: number, n: number): number => (x >>> n) | (x << (32 - n));
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* FIPS 180-4 SHA-256 of raw bytes — the insecure-context fallback digest.
|
|
60
|
+
* Exported for known-answer/parity tests only; production callers go through
|
|
61
|
+
* `deriveCodeChallenge`, which prefers WebCrypto when available.
|
|
62
|
+
*/
|
|
63
|
+
export function sha256Bytes(data: Uint8Array): Uint8Array {
|
|
64
|
+
const H = new Uint32Array([
|
|
65
|
+
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
|
|
66
|
+
]);
|
|
67
|
+
const l = data.length;
|
|
68
|
+
// Smallest multiple of 64 that fits message + 0x80 marker + 64-bit length.
|
|
69
|
+
const padded = new Uint8Array((((l + 8) >> 6) + 1) << 6);
|
|
70
|
+
padded.set(data);
|
|
71
|
+
padded[l] = 0x80;
|
|
72
|
+
const dv = new DataView(padded.buffer);
|
|
73
|
+
dv.setUint32(padded.length - 8, Math.floor(l / 0x20000000));
|
|
74
|
+
dv.setUint32(padded.length - 4, (l << 3) >>> 0);
|
|
75
|
+
const w = new Uint32Array(64);
|
|
76
|
+
for (let off = 0; off < padded.length; off += 64) {
|
|
77
|
+
for (let i = 0; i < 16; i++) w[i] = dv.getUint32(off + i * 4);
|
|
78
|
+
for (let i = 16; i < 64; i++) {
|
|
79
|
+
const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ (w[i - 15] >>> 3);
|
|
80
|
+
const s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ (w[i - 2] >>> 10);
|
|
81
|
+
w[i] = (w[i - 16] + s0 + w[i - 7] + s1) >>> 0;
|
|
82
|
+
}
|
|
83
|
+
let a = H[0], b = H[1], c = H[2], d = H[3], e = H[4], f = H[5], g = H[6], h = H[7];
|
|
84
|
+
for (let i = 0; i < 64; i++) {
|
|
85
|
+
const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
86
|
+
const ch = (e & f) ^ (~e & g);
|
|
87
|
+
const t1 = (h + S1 + ch + K[i] + w[i]) >>> 0;
|
|
88
|
+
const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
|
|
89
|
+
const maj = (a & b) ^ (a & c) ^ (b & c);
|
|
90
|
+
const t2 = (S0 + maj) >>> 0;
|
|
91
|
+
h = g; g = f; f = e; e = (d + t1) >>> 0; d = c; c = b; b = a; a = (t1 + t2) >>> 0;
|
|
92
|
+
}
|
|
93
|
+
H[0] = (H[0] + a) >>> 0; H[1] = (H[1] + b) >>> 0; H[2] = (H[2] + c) >>> 0; H[3] = (H[3] + d) >>> 0;
|
|
94
|
+
H[4] = (H[4] + e) >>> 0; H[5] = (H[5] + f) >>> 0; H[6] = (H[6] + g) >>> 0; H[7] = (H[7] + h) >>> 0;
|
|
95
|
+
}
|
|
96
|
+
const out = new Uint8Array(32);
|
|
97
|
+
const ov = new DataView(out.buffer);
|
|
98
|
+
for (let i = 0; i < 8; i++) ov.setUint32(i * 4, H[i]);
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Derive the S256 challenge for a verifier: base64url(SHA-256(verifier)).
|
|
104
|
+
* Prefers WebCrypto; falls back to the pure-JS digest when `crypto.subtle`
|
|
105
|
+
* is unavailable (insecure context — plain-HTTP non-loopback origin, D17/R1).
|
|
106
|
+
* Method stays `S256` either way; RFC 9700 forbids `plain`.
|
|
107
|
+
*/
|
|
108
|
+
export async function deriveCodeChallenge(verifier: string): Promise<string> {
|
|
109
|
+
const bytes = new TextEncoder().encode(verifier);
|
|
110
|
+
if (crypto.subtle) {
|
|
111
|
+
const digest = await crypto.subtle.digest("SHA-256", bytes);
|
|
112
|
+
return base64UrlEncode(new Uint8Array(digest));
|
|
113
|
+
}
|
|
114
|
+
return base64UrlEncode(sha256Bytes(bytes));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Create a fresh verifier + its S256 challenge. */
|
|
118
|
+
export async function createPkcePair(): Promise<PkcePair> {
|
|
119
|
+
const verifier = createCodeVerifier();
|
|
120
|
+
const challenge = await deriveCodeChallenge(verifier);
|
|
121
|
+
return { verifier, challenge, method: "S256" };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** A random URL-safe `state`/`nonce` value (32 bytes base64url). */
|
|
125
|
+
export function createRandomState(): string {
|
|
126
|
+
const bytes = new Uint8Array(32);
|
|
127
|
+
crypto.getRandomValues(bytes);
|
|
128
|
+
return base64UrlEncode(bytes);
|
|
129
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory access-token store for the browser identity plane (openspec §12.1).
|
|
3
|
+
*
|
|
4
|
+
* The access token is held in a module-scoped variable — NEVER localStorage /
|
|
5
|
+
* sessionStorage / cookie (RFC 9700 public-client guidance: an access token in
|
|
6
|
+
* web storage is XSS-exfiltratable). It lives only for the tab's lifetime; a
|
|
7
|
+
* reload re-runs the PKCE flow (silent via the IdP session when present).
|
|
8
|
+
*
|
|
9
|
+
* Distinct from the paired-device bearer (`lib/pairing/device-auth.ts`), which
|
|
10
|
+
* is a durable localStorage credential for a phone paired via `/pair`. The two
|
|
11
|
+
* never mix: the identity-plane bearer is this in-memory token.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
interface TokenState {
|
|
15
|
+
accessToken: string;
|
|
16
|
+
/** Epoch ms after which the token is treated as expired (from `expires_in`). */
|
|
17
|
+
expiresAt: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let state: TokenState | null = null;
|
|
21
|
+
|
|
22
|
+
/** ID token retained solely as a future `id_token_hint` for RP-initiated logout (D18). */
|
|
23
|
+
let idToken: string | null = null;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Store an access token with its `expires_in` (seconds). A non-positive or
|
|
27
|
+
* missing lifetime stores the token with an already-past expiry, so a caller
|
|
28
|
+
* that ignores `expiresAt` still gets a token while a caller that honors it
|
|
29
|
+
* treats it as needing refresh.
|
|
30
|
+
*/
|
|
31
|
+
export function setAccessToken(accessToken: string, expiresInSeconds: number): void {
|
|
32
|
+
state = { accessToken, expiresAt: Date.now() + Math.max(0, expiresInSeconds) * 1000 };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The current access token, or null when absent or expired. */
|
|
36
|
+
export function getAccessToken(now: number = Date.now()): string | null {
|
|
37
|
+
if (!state) return null;
|
|
38
|
+
if (now >= state.expiresAt) return null;
|
|
39
|
+
return state.accessToken;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Epoch ms the current token expires at, or null when no token is held. */
|
|
43
|
+
export function getExpiresAt(): number | null {
|
|
44
|
+
return state?.expiresAt ?? null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** True when a live (non-expired) token is held. */
|
|
48
|
+
export function hasLiveToken(now: number = Date.now()): boolean {
|
|
49
|
+
return getAccessToken(now) !== null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Retain the id_token (in-memory only) for logout's `id_token_hint` (D18). */
|
|
53
|
+
export function setIdToken(token: string): void {
|
|
54
|
+
idToken = token;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The retained id_token, or null. Not lifetime-checked — hint use only. */
|
|
58
|
+
export function getIdToken(): string | null {
|
|
59
|
+
return idToken;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Forget the in-memory tokens (logout / expiry / reconnect-on-401). */
|
|
63
|
+
export function clearAccessToken(): void {
|
|
64
|
+
state = null;
|
|
65
|
+
idToken = null;
|
|
66
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy MDI icon-by-key resolver.
|
|
3
|
+
*
|
|
4
|
+
* Resolving an icon from a runtime key string (`"mdiRefresh"`) needs the FULL
|
|
5
|
+
* `@mdi/js` namespace (~2.78 MB raw), which must stay off the cold landing
|
|
6
|
+
* load (iOS Safari WebContent memory kills, #712). The set is fetched on
|
|
7
|
+
* demand, the first time a key is resolved, and shared by every resolver.
|
|
8
|
+
*
|
|
9
|
+
* The dynamic import targets `@mdi/js/commonjs/mdi.js` — a DISTINCT module
|
|
10
|
+
* identity from the `@mdi/js` ESM entry that named imports use. Rollup cannot
|
|
11
|
+
* split one module across chunks, so importing `@mdi/js` itself would keep the
|
|
12
|
+
* whole namespace in the eager graph.
|
|
13
|
+
*
|
|
14
|
+
* While loading, and for unknown keys, resolvers return `null` (render
|
|
15
|
+
* nothing). A failed import resolves to `null` and clears the memo, so a
|
|
16
|
+
* later call retries.
|
|
17
|
+
*
|
|
18
|
+
* See change: harden-ios-safari-memory-and-ws-diagnostics (design D1).
|
|
19
|
+
*/
|
|
20
|
+
import { useEffect, useState } from "react";
|
|
21
|
+
|
|
22
|
+
type IconSet = Record<string, unknown>;
|
|
23
|
+
type Importer = () => Promise<unknown>;
|
|
24
|
+
|
|
25
|
+
const defaultImporter: Importer = () => import("@mdi/js/commonjs/mdi.js");
|
|
26
|
+
|
|
27
|
+
let importer: Importer = defaultImporter;
|
|
28
|
+
let loaded: IconSet | null = null;
|
|
29
|
+
let pending: Promise<IconSet | null> | null = null;
|
|
30
|
+
/** Bumped by the test reset so an in-flight import cannot repopulate the set. */
|
|
31
|
+
let generation = 0;
|
|
32
|
+
|
|
33
|
+
/** Load (once) and return the full icon set, or `null` if the import failed. */
|
|
34
|
+
export function loadMdiIconSet(): Promise<IconSet | null> {
|
|
35
|
+
if (loaded) return Promise.resolve(loaded);
|
|
36
|
+
if (pending) return pending;
|
|
37
|
+
const gen = generation;
|
|
38
|
+
pending = importer().then(
|
|
39
|
+
(mod) => {
|
|
40
|
+
const m = mod as { default?: unknown };
|
|
41
|
+
const set = (m && typeof m.default === "object" && m.default !== null ? m.default : mod) as IconSet;
|
|
42
|
+
if (gen === generation) loaded = set;
|
|
43
|
+
return set;
|
|
44
|
+
},
|
|
45
|
+
() => {
|
|
46
|
+
if (gen === generation) pending = null; // retry on the next call
|
|
47
|
+
return null;
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
return pending;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Synchronous lookup: the SVG path if the set is loaded and the key is known, else `null`. */
|
|
54
|
+
export function resolveMdiIconSync(key: string | undefined | null): string | null {
|
|
55
|
+
if (!loaded || !key || typeof key !== "string" || !key.startsWith("mdi")) return null;
|
|
56
|
+
const path = loaded[key];
|
|
57
|
+
return typeof path === "string" && path.length > 0 ? path : null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Hook: resolves `key`, triggering the lazy load and re-rendering once it lands. */
|
|
61
|
+
export function useMdiIconByKey(key: string | undefined | null): string | null {
|
|
62
|
+
const [, setTick] = useState(0);
|
|
63
|
+
const path = resolveMdiIconSync(key);
|
|
64
|
+
// Only keys that could resolve justify fetching the ~2.8 MB set.
|
|
65
|
+
const needsLoad = !loaded && typeof key === "string" && key.startsWith("mdi");
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (!needsLoad) return;
|
|
68
|
+
let alive = true;
|
|
69
|
+
void loadMdiIconSet().then((set) => {
|
|
70
|
+
if (alive && set) setTick((t) => t + 1);
|
|
71
|
+
});
|
|
72
|
+
return () => {
|
|
73
|
+
alive = false;
|
|
74
|
+
};
|
|
75
|
+
}, [needsLoad]);
|
|
76
|
+
return path;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Test seam: replace the dynamic importer. */
|
|
80
|
+
export function __setMdiIconSetImporterForTests(fn: Importer): void {
|
|
81
|
+
importer = fn;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Test seam: forget the loaded set and restore the real importer. */
|
|
85
|
+
export function __resetMdiIconSetForTests(): void {
|
|
86
|
+
importer = defaultImporter;
|
|
87
|
+
loaded = null;
|
|
88
|
+
pending = null;
|
|
89
|
+
generation++;
|
|
90
|
+
}
|
|
@@ -17,8 +17,9 @@
|
|
|
17
17
|
*
|
|
18
18
|
* See change: extract-minimal-chat-view.
|
|
19
19
|
*/
|
|
20
|
-
|
|
21
|
-
import {
|
|
20
|
+
|
|
21
|
+
import { useUiPrimitive, useUiPrimitiveOrNull } from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
22
|
+
import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
|
|
22
23
|
import {
|
|
23
24
|
mdiAlertCircle,
|
|
24
25
|
mdiArrowLeft,
|
|
@@ -26,11 +27,15 @@ import {
|
|
|
26
27
|
mdiCircle,
|
|
27
28
|
mdiCircleOutline,
|
|
28
29
|
mdiCloseCircle,
|
|
30
|
+
mdiHeadLightbulb,
|
|
31
|
+
mdiPencil,
|
|
29
32
|
} from "@mdi/js";
|
|
30
|
-
import {
|
|
31
|
-
import
|
|
33
|
+
import { Icon } from "@mdi/react";
|
|
34
|
+
import React from "react";
|
|
35
|
+
import { plainTail } from "./live-tail-text.js";
|
|
32
36
|
import type {
|
|
33
37
|
MinimalChatEntry,
|
|
38
|
+
MinimalChatLiveEntry,
|
|
34
39
|
MinimalChatStatus,
|
|
35
40
|
MinimalChatViewProps,
|
|
36
41
|
} from "./types.js";
|
|
@@ -113,12 +118,7 @@ function ToolCallEntry({
|
|
|
113
118
|
entry.input && typeof entry.input === "object" && !Array.isArray(entry.input)
|
|
114
119
|
? (entry.input as Record<string, unknown>)
|
|
115
120
|
: { value: entry.input };
|
|
116
|
-
const result =
|
|
117
|
-
entry.output === undefined
|
|
118
|
-
? undefined
|
|
119
|
-
: typeof entry.output === "string"
|
|
120
|
-
? entry.output
|
|
121
|
-
: JSON.stringify(entry.output, null, 2);
|
|
121
|
+
const result = formatToolOutput(entry.output);
|
|
122
122
|
if (ToolCallStepImpl) {
|
|
123
123
|
const toolCallId = `minimal-${index}`;
|
|
124
124
|
const status = entry.isError ? "error" : entry.output !== undefined ? "complete" : "running";
|
|
@@ -197,14 +197,14 @@ function TextEntry({ text }: { text: string }) {
|
|
|
197
197
|
);
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
-
function ThinkingEntry({ text }: { text: string }) {
|
|
200
|
+
function ThinkingEntry({ text, defaultExpanded }: { text: string; defaultExpanded?: boolean }) {
|
|
201
201
|
// Prefer the shell-registered `thinkingBlock` primitive for parity with
|
|
202
202
|
// the main chat view. Falls back to a simple inline rendition when the
|
|
203
203
|
// primitive is not registered.
|
|
204
204
|
// See change: fix-flows-plugin-polish (chat-view parity).
|
|
205
205
|
const ThinkingBlockImpl = useUiPrimitiveOrNull(UI_PRIMITIVE_KEYS.thinkingBlock);
|
|
206
206
|
if (ThinkingBlockImpl) {
|
|
207
|
-
return <ThinkingBlockImpl content={text} />;
|
|
207
|
+
return <ThinkingBlockImpl content={text} defaultExpanded={defaultExpanded} />;
|
|
208
208
|
}
|
|
209
209
|
return <FallbackThinkingEntry text={text} />;
|
|
210
210
|
}
|
|
@@ -229,6 +229,80 @@ function FallbackThinkingEntry({ text }: { text: string }) {
|
|
|
229
229
|
);
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
+
/**
|
|
233
|
+
* In-progress block (streaming tail), mock `mockups/live-tail.html`:
|
|
234
|
+
* main-chat ThinkingBlock header (icon, label, pulsing dots) over a tinted
|
|
235
|
+
* box at READING size (13px), line breaks kept, newest line at the bottom,
|
|
236
|
+
* oldest fading out at the top (mask, not a leading "…"), pulse caret.
|
|
237
|
+
* Thinking = purple rail/tint; writing = neutral, markdown markers stripped
|
|
238
|
+
* (the tail is a partial block). See change: stream-subagent-reasoning-and-stable-card.
|
|
239
|
+
*/
|
|
240
|
+
function LiveEntry({ entry }: { entry: MinimalChatLiveEntry }) {
|
|
241
|
+
const isThinking = entry.kind === "thinking";
|
|
242
|
+
const body = isThinking ? entry.text : plainTail(entry.text);
|
|
243
|
+
return (
|
|
244
|
+
<div
|
|
245
|
+
data-testid="minimal-live-entry"
|
|
246
|
+
data-kind={entry.kind}
|
|
247
|
+
className={`border-l-2 pl-3 py-1 ${isThinking ? "border-purple-500/30" : "border-[var(--text-muted)]"}`}
|
|
248
|
+
>
|
|
249
|
+
<div className="flex items-center gap-1.5 text-xs text-[var(--text-tertiary)]">
|
|
250
|
+
<span className={`inline-flex ${isThinking ? "text-purple-400" : ""}`}>
|
|
251
|
+
<Icon path={isThinking ? mdiHeadLightbulb : mdiPencil} size={0.55} />
|
|
252
|
+
</span>
|
|
253
|
+
<span>
|
|
254
|
+
{isThinking ? "Reasoning" : "Writing"}
|
|
255
|
+
<span className="ml-1 motion-safe:animate-pulse">…</span>
|
|
256
|
+
<span className="sr-only"> in progress</span>
|
|
257
|
+
</span>
|
|
258
|
+
</div>
|
|
259
|
+
<div
|
|
260
|
+
className={`mt-1 ml-4 rounded-xl border shadow-md ${
|
|
261
|
+
isThinking ? "bg-purple-500/5 border-purple-500/10" : "bg-[var(--bg-tertiary)] border-[var(--border-subtle)]"
|
|
262
|
+
}`}
|
|
263
|
+
>
|
|
264
|
+
<div
|
|
265
|
+
className={
|
|
266
|
+
entry.growing
|
|
267
|
+
? "px-3 py-2"
|
|
268
|
+
: "max-h-36 overflow-hidden flex flex-col justify-end px-3 py-2 [mask-image:linear-gradient(to_bottom,transparent_0,#000_22%)]"
|
|
269
|
+
}
|
|
270
|
+
>
|
|
271
|
+
<div className="text-[13px] leading-5 text-[var(--text-secondary)] whitespace-pre-line break-words">
|
|
272
|
+
{body}
|
|
273
|
+
<span
|
|
274
|
+
className={`inline-block w-0.5 h-[0.95em] align-[-0.12em] ml-0.5 motion-safe:animate-pulse ${
|
|
275
|
+
isThinking ? "bg-purple-400/70" : "bg-[var(--text-tertiary)]"
|
|
276
|
+
}`}
|
|
277
|
+
/>
|
|
278
|
+
</div>
|
|
279
|
+
</div>
|
|
280
|
+
</div>
|
|
281
|
+
</div>
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Tool output as text: a string as-is; a `{ content: [{ type: "text", text }] }`
|
|
287
|
+
* result envelope as its texts joined by newlines; anything else as JSON.
|
|
288
|
+
* See change: add-plugin-bridge-contributions (D11).
|
|
289
|
+
*/
|
|
290
|
+
export function formatToolOutput(output: unknown): string | undefined {
|
|
291
|
+
if (output === undefined) return undefined;
|
|
292
|
+
if (typeof output === "string") return output;
|
|
293
|
+
if (output && typeof output === "object" && !Array.isArray(output)) {
|
|
294
|
+
const content = (output as { content?: unknown }).content;
|
|
295
|
+
if (Array.isArray(content) && content.length > 0) {
|
|
296
|
+
const texts = content.filter(
|
|
297
|
+
(b): b is { type: "text"; text: string } =>
|
|
298
|
+
!!b && typeof b === "object" && (b as { type?: unknown }).type === "text" && typeof (b as { text?: unknown }).text === "string",
|
|
299
|
+
);
|
|
300
|
+
if (texts.length === content.length) return texts.map((b) => b.text).join("\n");
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return JSON.stringify(output, null, 2);
|
|
304
|
+
}
|
|
305
|
+
|
|
232
306
|
function ErrorEntry({ text }: { text: string }) {
|
|
233
307
|
return <div className="py-1.5 pl-3 text-sm text-red-400">{text}</div>;
|
|
234
308
|
}
|
|
@@ -248,6 +322,8 @@ export function MinimalChatView({
|
|
|
248
322
|
footer,
|
|
249
323
|
activity,
|
|
250
324
|
sessionId,
|
|
325
|
+
liveEntry,
|
|
326
|
+
expandLastThinking,
|
|
251
327
|
}: MinimalChatViewProps) {
|
|
252
328
|
// Soft-read formatters — fall back to identity formatting when the
|
|
253
329
|
// primitive registry is partially populated (matches the spec’s
|
|
@@ -345,6 +421,16 @@ export function MinimalChatView({
|
|
|
345
421
|
? "flex flex-col h-full overflow-hidden"
|
|
346
422
|
: "flex flex-col h-[60vh] overflow-hidden";
|
|
347
423
|
|
|
424
|
+
// Newest reasoning entry opens on mount while the producer is live, so a
|
|
425
|
+
// just-finished block stays readable (main-chat parity). Mount-time only.
|
|
426
|
+
let lastThinkingIdx = -1;
|
|
427
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
428
|
+
if (entries[i].kind === "thinking") {
|
|
429
|
+
lastThinkingIdx = i;
|
|
430
|
+
break;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
348
434
|
const defaultEmpty = "No activity yet";
|
|
349
435
|
const empty = emptyMessage ?? defaultEmpty;
|
|
350
436
|
|
|
@@ -357,7 +443,7 @@ export function MinimalChatView({
|
|
|
357
443
|
// See change: fix-flows-plugin-polish (scrollbar fix).
|
|
358
444
|
const body = (
|
|
359
445
|
<div className="flex-1 min-h-0 overflow-y-auto px-3 py-2 space-y-0.5">
|
|
360
|
-
{entries.length === 0 ? (
|
|
446
|
+
{entries.length === 0 && !liveEntry ? (
|
|
361
447
|
<div className="text-sm text-[var(--text-muted)] py-4 text-center">{empty}</div>
|
|
362
448
|
) : (
|
|
363
449
|
entries.map((entry, i) => {
|
|
@@ -367,7 +453,13 @@ export function MinimalChatView({
|
|
|
367
453
|
case "text":
|
|
368
454
|
return <TextEntry key={i} text={entry.text} />;
|
|
369
455
|
case "thinking":
|
|
370
|
-
return
|
|
456
|
+
return (
|
|
457
|
+
<ThinkingEntry
|
|
458
|
+
key={i}
|
|
459
|
+
text={entry.text}
|
|
460
|
+
defaultExpanded={expandLastThinking && i === lastThinkingIdx}
|
|
461
|
+
/>
|
|
462
|
+
);
|
|
371
463
|
case "error":
|
|
372
464
|
return <ErrorEntry key={i} text={entry.text} />;
|
|
373
465
|
default:
|
|
@@ -376,6 +468,7 @@ export function MinimalChatView({
|
|
|
376
468
|
})
|
|
377
469
|
)}
|
|
378
470
|
{footer}
|
|
471
|
+
{liveEntry && <LiveEntry entry={liveEntry} />}
|
|
379
472
|
</div>
|
|
380
473
|
);
|
|
381
474
|
|
|
@@ -7,8 +7,10 @@
|
|
|
7
7
|
* See change: extract-minimal-chat-view.
|
|
8
8
|
*/
|
|
9
9
|
export { MinimalChatView, statusVisualsFor, extractInputPreview } from "./MinimalChatView.js";
|
|
10
|
+
export { currentSentence, plainTail } from "./live-tail-text.js";
|
|
10
11
|
export type {
|
|
11
12
|
MinimalChatEntry,
|
|
13
|
+
MinimalChatLiveEntry,
|
|
12
14
|
MinimalChatMeta,
|
|
13
15
|
MinimalChatMode,
|
|
14
16
|
MinimalChatStatus,
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text helpers for a subagent's streaming tail (a bounded SUFFIX of a block
|
|
3
|
+
* that is still being written). Partial markdown renders badly, so previews
|
|
4
|
+
* strip simple markers while keeping line breaks.
|
|
5
|
+
*
|
|
6
|
+
* See change: stream-subagent-reasoning-and-stable-card.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** Strip heading/bullet/code/bold markers; keep line breaks. */
|
|
10
|
+
export function plainTail(text: string): string {
|
|
11
|
+
return text
|
|
12
|
+
.replace(/^#{1,6}\s+/gm, "")
|
|
13
|
+
.replace(/^(\s*)[-*]\s+/gm, "$1• ")
|
|
14
|
+
.replace(/`/g, "")
|
|
15
|
+
.replace(/\*\*/g, "");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The sentence currently being written, flattened to one line (card ticker).
|
|
20
|
+
* When the last sentence just ended, returns that sentence.
|
|
21
|
+
*/
|
|
22
|
+
export function currentSentence(text: string): string {
|
|
23
|
+
const flat = plainTail(text).replace(/\s+/g, " ").trim();
|
|
24
|
+
if (!flat) return "";
|
|
25
|
+
const parts = flat.split(/(?<=[.!?:])\s+/);
|
|
26
|
+
return parts[parts.length - 1] ?? flat;
|
|
27
|
+
}
|
|
@@ -99,4 +99,30 @@ export interface MinimalChatViewProps {
|
|
|
99
99
|
* See change: improve-flow-ui.
|
|
100
100
|
*/
|
|
101
101
|
hideToolStatusIcon?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Optional in-progress block (e.g. a running subagent's streaming thinking
|
|
104
|
+
* or text tail). Rendered after `entries` with an "in progress" affordance;
|
|
105
|
+
* counts as body content, so the empty state is suppressed while present.
|
|
106
|
+
*
|
|
107
|
+
* See change: stream-subagent-reasoning-and-stable-card.
|
|
108
|
+
*/
|
|
109
|
+
liveEntry?: MinimalChatLiveEntry;
|
|
110
|
+
/**
|
|
111
|
+
* When true, the newest `thinking` entry mounts expanded (running agents:
|
|
112
|
+
* a just-finished block stays readable). See change:
|
|
113
|
+
* stream-subagent-reasoning-and-stable-card.
|
|
114
|
+
*/
|
|
115
|
+
expandLastThinking?: boolean;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** In-progress thinking/text block rendered after the finished entries. */
|
|
119
|
+
export interface MinimalChatLiveEntry {
|
|
120
|
+
kind: "thinking" | "text";
|
|
121
|
+
text: string;
|
|
122
|
+
/**
|
|
123
|
+
* The FULL block so far (delta stream), rendered growing like the main
|
|
124
|
+
* chat's live block. Absent = a bounded tail, rendered as the fading window.
|
|
125
|
+
* See change: add-plugin-bridge-contributions (D8).
|
|
126
|
+
*/
|
|
127
|
+
growing?: boolean;
|
|
102
128
|
}
|
package/src/tone.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tone → class helpers. Total and prototype-safe: any non-UiTone value yields
|
|
3
|
+
* "" / undefined. Maps hold complete literals (Tailwind scans them); a tone is
|
|
4
|
+
* never interpolated. See change: colorize-actions-menus.
|
|
5
|
+
*/
|
|
6
|
+
import { isUiTone, type UiTone } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
|
|
7
|
+
|
|
8
|
+
const ICON: Record<UiTone, string> = {
|
|
9
|
+
go: "text-[var(--accent-green-text)]",
|
|
10
|
+
create: "text-[var(--accent-blue-text)]",
|
|
11
|
+
caution: "text-[var(--accent-orange-text)]",
|
|
12
|
+
danger: "text-[var(--accent-red-text)]",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const DANGER_ROW =
|
|
16
|
+
"hover:bg-[var(--tint-red-bg)] focus:bg-[var(--tint-red-bg)] hover:text-[var(--accent-red-text)] focus:text-[var(--accent-red-text)]";
|
|
17
|
+
|
|
18
|
+
export function toneIconClass(tone: unknown, opts: { disabled: boolean }): string {
|
|
19
|
+
return isUiTone(tone) && !opts.disabled ? ICON[tone] : "";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function toneRowClass(tone: unknown, opts: { disabled: boolean }): string {
|
|
23
|
+
return tone === "danger" && !opts.disabled ? DANGER_ROW : "";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function toneAttr(tone: unknown): UiTone | undefined {
|
|
27
|
+
return isUiTone(tone) ? tone : undefined;
|
|
28
|
+
}
|