@jini-ai/chat 0.7.3-next.3 → 0.7.4

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +35 -0
  3. package/dist/core/assistant-client/ag-ui-browser-delivery.d.ts +43 -0
  4. package/dist/core/assistant-client/ag-ui-browser-delivery.js +113 -0
  5. package/dist/core/assistant-client/ag-ui-confirmation-session.d.ts +60 -0
  6. package/dist/core/assistant-client/ag-ui-confirmation-session.js +138 -0
  7. package/dist/core/assistant-client/ag-ui-live-turn.d.ts +85 -0
  8. package/dist/core/assistant-client/ag-ui-live-turn.js +296 -0
  9. package/dist/core/assistant-client/ag-ui-transport.d.ts +6 -0
  10. package/dist/core/assistant-client/ag-ui-transport.js +3 -0
  11. package/dist/core/assistant-client/messages.d.ts +2 -0
  12. package/dist/core/user-text-redaction.js +8 -1
  13. package/dist/react/chat-cleanup/ChatCleanupPanel.d.ts +23 -6
  14. package/dist/react/chat-cleanup/ChatCleanupPanel.js +25 -8
  15. package/dist/react/chat-cleanup/chat-cleanup.hooks.d.ts +6 -0
  16. package/dist/react/components/ChatCleanupDialog.js +4 -1
  17. package/dist/react/components/ChatSettingsDialog.d.ts +3 -0
  18. package/dist/react/components/ChatSettingsDialog.js +3 -3
  19. package/dist/react/components/ConversationList.creation.d.ts +19 -0
  20. package/dist/react/components/ConversationList.creation.js +25 -0
  21. package/dist/react/components/ConversationList.d.ts +21 -1
  22. package/dist/react/components/ConversationList.hooks.d.ts +5 -1
  23. package/dist/react/components/ConversationList.hooks.js +10 -2
  24. package/dist/react/components/ConversationList.js +30 -10
  25. package/dist/react/components/Icon.d.ts +1 -1
  26. package/dist/react/components/Icon.js +7 -0
  27. package/dist/react/components/ToolCard.rules.js +9 -6
  28. package/dist/react/features/chat-pane/styles.d.ts +1 -1
  29. package/dist/react/features/chat-pane/styles.js +3 -0
  30. package/dist/react/index.d.ts +1 -1
  31. package/dist/react/styles/chat-settings.css +28 -0
  32. package/dist/store/runtime/attempt-base-retention.js +3 -2
  33. package/package.json +16 -16
@@ -0,0 +1,296 @@
1
+ import { EventType } from '@ag-ui/core';
2
+ import { createAgUiToAgentTranslationState, translateAgUiEventToAgentEvent } from '../ag-ui/event-reduction.js';
3
+ import { createAgUiFetchAgent } from './ag-ui-fetch-agent.js';
4
+ import { createAgUiBrowserDelivery } from './ag-ui-browser-delivery.js';
5
+ import { createAgUiConfirmationSession } from './ag-ui-confirmation-session.js';
6
+ function closeSegment({ segment }, _optional = {}) {
7
+ if (segment.closed)
8
+ return;
9
+ segment.closed = true;
10
+ segment.reportAccepted({ accepted: false });
11
+ segment.browser?.close({});
12
+ segment.confirmation?.close({});
13
+ segment.detach({});
14
+ segment.controller.abort();
15
+ }
16
+ function settle({ state, failure, stopped = false, result }, _optional = {}) {
17
+ if (state.settled)
18
+ return;
19
+ // Latch and revoke before crossing any host callback, which can synchronously Stop again.
20
+ state.settled = true;
21
+ clearTimeout(state.idle);
22
+ clearTimeout(state.approval);
23
+ state.attachment.removeEventListener('abort', state.onAbort);
24
+ if (state.active)
25
+ closeSegment({ segment: state.active });
26
+ state.confirmation?.dispose({});
27
+ state.browser?.dispose({});
28
+ state.controller.abort();
29
+ const outcome = failure ? 'failed' : stopped ? 'stopped' : 'finished';
30
+ try {
31
+ if (failure)
32
+ state.ports.onFailure({ failure }, {});
33
+ }
34
+ finally {
35
+ state.ports.onDone({ outcome, events: [...state.events], ...(result === undefined ? {} : { result }) }, {});
36
+ }
37
+ }
38
+ function stop({ state, failure }, _optional = {}) {
39
+ if (state.settled || state.stopping)
40
+ return;
41
+ state.stopping = true;
42
+ try {
43
+ state.ports.onStop({}, {});
44
+ }
45
+ finally {
46
+ // Abort lets the confirmation's first-answer latch send one independent cancellation.
47
+ // Final disposal afterwards must not steal an unanswered right from that abort listener.
48
+ state.controller.abort();
49
+ settle({ state, stopped: true, ...(failure ? { failure } : {}) });
50
+ }
51
+ }
52
+ function armIdle({ state }, _optional = {}) {
53
+ if (state.settled || state.stopping)
54
+ return;
55
+ clearTimeout(state.idle);
56
+ state.idle = setTimeout(() => stop({ state, failure: { kind: 'timeout' } }), state.idleTimeoutMs);
57
+ }
58
+ function park({ state }, _optional = {}) {
59
+ const segment = state.active;
60
+ if (!segment || state.settled || state.stopping)
61
+ return;
62
+ segment.parked = true;
63
+ clearTimeout(state.idle);
64
+ clearTimeout(state.approval);
65
+ state.approval = setTimeout(() => stop({ state, failure: { kind: 'timeout' } }), Math.min(state.approvalTimeoutMs, state.idleTimeoutMs));
66
+ // Do this before showing the card: its callback may synchronously answer and open a resume.
67
+ closeSegment({ segment });
68
+ }
69
+ /** Race host work even when its implementation ignores AbortSignal. The original promise always
70
+ * has a rejection observer, so a late failure cannot escape into a later turn. */
71
+ async function untilAborted({ signal, work }, _optional = {}) {
72
+ signal.throwIfAborted();
73
+ let abort = () => { };
74
+ const stopped = new Promise((_resolve, reject) => {
75
+ abort = () => reject(signal.reason);
76
+ signal.addEventListener('abort', abort, { once: true });
77
+ });
78
+ try {
79
+ return await Promise.race([stopped, Promise.resolve().then(() => {
80
+ signal.throwIfAborted();
81
+ return work({});
82
+ })]);
83
+ }
84
+ finally {
85
+ signal.removeEventListener('abort', abort);
86
+ }
87
+ }
88
+ function cancelBody({ response }, _optional = {}) {
89
+ void response.body?.cancel().catch(() => { });
90
+ }
91
+ async function request({ state, segment, input, signal }, _optional = {}) {
92
+ const headers = await untilAborted({ signal, work: () => state.ports.headers({ signal }, {}) });
93
+ signal.throwIfAborted();
94
+ const response = await untilAborted({ signal, work: () => {
95
+ const pending = state.ports.request({ input, headers, signal }, {});
96
+ // A fetch port ignoring cancellation may still hand back an unread socket after Stop.
97
+ void pending.then(late => { if (signal.aborted)
98
+ cancelBody({ response: late }); }, () => { });
99
+ return pending;
100
+ } });
101
+ if (signal.aborted) {
102
+ cancelBody({ response });
103
+ signal.throwIfAborted();
104
+ }
105
+ if (!response.ok)
106
+ return refuse({ state, segment, response, signal });
107
+ segment.streaming = true;
108
+ clearTimeout(state.approval);
109
+ state.approval = undefined;
110
+ armIdle({ state });
111
+ segment.reportAccepted({ accepted: true });
112
+ return response;
113
+ }
114
+ async function refuse({ state, segment, response, signal }, _optional = {}) {
115
+ let error;
116
+ try {
117
+ error = await untilAborted({ signal, work: () => state.ports.refusal({ response, signal }, {}) });
118
+ }
119
+ catch (cause) {
120
+ error = cause;
121
+ }
122
+ finally {
123
+ cancelBody({ response });
124
+ }
125
+ segment.reportAccepted({ accepted: false });
126
+ if (!state.settled)
127
+ settle({ state, failure: { kind: 'refusal', error } });
128
+ // Settlement aborted this segment. Its rejection only stops the fetch agent reading the body.
129
+ throw signal.reason;
130
+ }
131
+ function active({ state, segment }, _optional = {}) {
132
+ return !state.settled && !state.stopping && state.active === segment && !segment.closed;
133
+ }
134
+ function matches({ segment, event }, _optional = {}) {
135
+ return event.threadId === segment.input.threadId && event.runId === segment.input.runId;
136
+ }
137
+ function receiveText({ state, segment, event }, _optional = {}) {
138
+ if (event.type !== EventType.TEXT_MESSAGE_CONTENT)
139
+ return;
140
+ // The shared reducer owns text semantics. No custom/tool/result data reaches this projection.
141
+ for (const reduced of translateAgUiEventToAgentEvent({ event, state: segment.reduction })) {
142
+ if (reduced.kind !== 'text')
143
+ continue;
144
+ if (reduced.text.trim())
145
+ state.replied = true;
146
+ state.events.push(reduced);
147
+ state.ports.onEvent({ event: reduced }, {});
148
+ }
149
+ }
150
+ function observeLive({ state, segment, event }, _optional = {}) {
151
+ // Both live bindings observe lifecycle frames; browser delivery always observes first.
152
+ segment.browser?.observe({ event });
153
+ const observation = segment.confirmation?.observe({ event });
154
+ if (!active({ state, segment }) || observation === 'closed')
155
+ return false;
156
+ if (observation === 'invalid') {
157
+ settle({ state, failure: { kind: 'invalid-interrupt' } });
158
+ return false;
159
+ }
160
+ return true;
161
+ }
162
+ function finishEvent({ state, event }, _optional = {}) {
163
+ if (event.outcome?.type === 'interrupt') {
164
+ settle({ state, failure: { kind: 'invalid-interrupt' } });
165
+ return;
166
+ }
167
+ const failure = state.replied ? undefined : { kind: 'no-reply' };
168
+ settle({ state, ...(failure ? { failure } : {}), result: event.result });
169
+ }
170
+ function receive({ state, segment, event }, _optional = {}) {
171
+ if (!active({ state, segment }))
172
+ return;
173
+ if (!observeLive({ state, segment, event }))
174
+ return;
175
+ if (event.type === EventType.RUN_ERROR) {
176
+ settle({ state, failure: { kind: 'run', event } });
177
+ return;
178
+ }
179
+ if (event.type === EventType.RUN_STARTED && matches({ segment, event }))
180
+ segment.started = true;
181
+ if (!segment.started)
182
+ return;
183
+ if (event.type === EventType.RUN_FINISHED && matches({ segment, event })) {
184
+ finishEvent({ state, event });
185
+ return;
186
+ }
187
+ receiveText({ state, segment, event });
188
+ }
189
+ async function deliverSegment({ state, segment }, _optional = {}) {
190
+ const agent = createAgUiFetchAgent({ request: required => request({ state, segment, ...required }) }, {
191
+ abortController: segment.controller,
192
+ // Heartbeats and partial frames count as activity before framing or validation.
193
+ onBytes: () => { if (active({ state, segment }))
194
+ armIdle({ state }); },
195
+ });
196
+ try {
197
+ await agent.run(segment.input).subscribe({
198
+ next: event => receive({ state, segment, event }),
199
+ error: error => {
200
+ if (active({ state, segment }))
201
+ settle({ state, failure: { kind: segment.streaming ? 'stream' : 'request', error } });
202
+ },
203
+ complete: () => { if (active({ state, segment }))
204
+ settle({ state, failure: { kind: 'incomplete' } }); },
205
+ });
206
+ }
207
+ finally {
208
+ closeSegment({ segment });
209
+ }
210
+ }
211
+ function newSegment({ state, input, reportAccepted }, _optional = {}) {
212
+ const controller = new AbortController();
213
+ const abort = () => controller.abort();
214
+ state.controller.signal.addEventListener('abort', abort, { once: true });
215
+ return { input, reportAccepted, controller,
216
+ detach: _required => state.controller.signal.removeEventListener('abort', abort),
217
+ reduction: createAgUiToAgentTranslationState({ customEventNames: { usage: '', status: '', extensionPrefix: '' } }),
218
+ started: false, streaming: false, parked: false, closed: false };
219
+ }
220
+ function canStartSegment({ state, input }, _optional = {}) {
221
+ if (state.settled || state.stopping || state.runs.has(input.runId))
222
+ return false;
223
+ if (state.active && !state.active.parked)
224
+ return false;
225
+ return state.threadId === undefined || state.threadId === input.threadId;
226
+ }
227
+ function startSegment({ state, input }, _optional = {}) {
228
+ if (!canStartSegment({ state, input })) {
229
+ return { accepted: Promise.resolve(false), completed: Promise.resolve() };
230
+ }
231
+ if (state.active)
232
+ closeSegment({ segment: state.active });
233
+ state.threadId = input.threadId;
234
+ state.runs.add(input.runId);
235
+ let report = (_value) => { };
236
+ let reported = false;
237
+ const accepted = new Promise(resolve => { report = resolve; });
238
+ const segment = newSegment({ state, input, reportAccepted: ({ accepted: value }) => {
239
+ if (reported)
240
+ return;
241
+ reported = true;
242
+ report(value);
243
+ } });
244
+ state.active = segment;
245
+ segment.browser = state.browser?.beginSegment(input);
246
+ segment.confirmation = state.confirmation?.beginSegment(input);
247
+ // The original card deadline stays armed during resume header acquisition; starting a POST
248
+ // cannot renew a human approval. HTTP acceptance switches back to ordinary byte-based idle.
249
+ if (state.approval === undefined)
250
+ armIdle({ state });
251
+ return { accepted, completed: deliverSegment({ state, segment }) };
252
+ }
253
+ function bindLivePorts({ state, confirmation, browser }, _optional = {}) {
254
+ if (browser)
255
+ state.browser = createAgUiBrowserDelivery({ ...browser, signal: state.controller.signal });
256
+ if (!confirmation)
257
+ return;
258
+ state.confirmation = createAgUiConfirmationSession({ signal: state.controller.signal, ports: {
259
+ ...confirmation,
260
+ resume: ({ input }) => startSegment({ state, input }).accepted,
261
+ onResumeError: ({ error }) => settle({ state, failure: { kind: 'request', error } }),
262
+ onConfirmation: (required, optional) => {
263
+ if (required.interrupt)
264
+ park({ state });
265
+ confirmation.onConfirmation(required, optional);
266
+ },
267
+ } });
268
+ }
269
+ function validateTimeouts({ idleTimeoutMs, approvalTimeoutMs }, _optional = {}) {
270
+ for (const value of [idleTimeoutMs, approvalTimeoutMs]) {
271
+ if (!Number.isSafeInteger(value) || value <= 0 || value > 2_147_483_647) {
272
+ throw new RangeError('Live turn idle and approval timeouts must be positive timer-safe integer milliseconds');
273
+ }
274
+ }
275
+ }
276
+ /** One opt-in, non-durable logical turn across start and confirmation resumes. Hosts retain
277
+ * request construction, identity, admission, safe copy and authorized page execution. Never feed
278
+ * replay/history through this runner. Durable detach/recovery uses the canonical run bindings.
279
+ */
280
+ export function createAgUiLiveTurn({ signal, ports, idleTimeoutMs, approvalTimeoutMs, confirmation, browser }, _optional = {}) {
281
+ validateTimeouts({ idleTimeoutMs, approvalTimeoutMs });
282
+ const state = { ports, attachment: signal, controller: new AbortController(), idleTimeoutMs,
283
+ approvalTimeoutMs, events: [], runs: new Set(), settled: false, stopping: false, replied: false, onAbort: () => { } };
284
+ bindLivePorts({ state, confirmation, browser });
285
+ state.onAbort = () => stop({ state });
286
+ signal.addEventListener('abort', state.onAbort, { once: true });
287
+ if (signal.aborted)
288
+ stop({ state });
289
+ return {
290
+ signal: state.controller.signal,
291
+ startSegment: (required, _optional = {}) => startSegment({ state, ...required }),
292
+ answer: (required, _optional = {}) => state.confirmation?.answer(required) ?? Promise.resolve(false),
293
+ stop: (_required, _optional = {}) => stop({ state }),
294
+ };
295
+ }
296
+ //# sourceMappingURL=ag-ui-live-turn.js.map
@@ -17,6 +17,12 @@ import type { DurableRunBinding } from "./durable-run-subscription.js";
17
17
  import type { AgentEvent } from "@jini-ai/core/contracts/site/chat-core";
18
18
  export { createAgUiFetchAgent } from "./ag-ui-fetch-agent.js";
19
19
  export type { AgUiFetchAgent } from "./ag-ui-fetch-agent.js";
20
+ export { createAgUiBrowserDelivery } from "./ag-ui-browser-delivery.js";
21
+ export type { AgUiBrowserDelivery, AgUiBrowserDeliveryPorts, AgUiBrowserDeliverySegment, AgUiBrowserInvocation } from "./ag-ui-browser-delivery.js";
22
+ export { createAgUiConfirmationSession } from "./ag-ui-confirmation-session.js";
23
+ export type { AgUiConfirmationSession, AgUiConfirmationSessionPorts, AgUiConfirmationSegment, AgUiConfirmationObservation } from "./ag-ui-confirmation-session.js";
24
+ export { createAgUiLiveTurn } from "./ag-ui-live-turn.js";
25
+ export type { AgUiLiveTurn, AgUiLiveTurnPorts, AgUiLiveTurnSegment, AgUiLiveTurnResult, AgUiLiveTurnFailure } from "./ag-ui-live-turn.js";
20
26
  export interface AgUiClient {
21
27
  readonly abortController: AbortController;
22
28
  abortRun(): void;
@@ -3,6 +3,9 @@ import { EventType } from "@ag-ui/core";
3
3
  import { createAgUiApprovalRelay } from "./ag-ui-approval-relay.js";
4
4
  import { createAgUiToAgentTranslationState, translateAgUiEventToAgentEvent } from "../ag-ui/event-reduction.js";
5
5
  export { createAgUiFetchAgent } from "./ag-ui-fetch-agent.js";
6
+ export { createAgUiBrowserDelivery } from "./ag-ui-browser-delivery.js";
7
+ export { createAgUiConfirmationSession } from "./ag-ui-confirmation-session.js";
8
+ export { createAgUiLiveTurn } from "./ag-ui-live-turn.js";
6
9
  /** Only the originating attachment can authorize page execution. Read its token and tab for every
7
10
  * turn; caller-supplied tool definitions never authorize or execute a transcript event.
8
11
  * @complexity O(1) time and space.
@@ -1,6 +1,8 @@
1
1
  import type { ChatMessage } from "../messages.js";
2
2
  export interface AssistantConversation {
3
3
  id: string;
4
+ /** Transcript ownership supplied by the host; independent of active-site tools. */
5
+ kind?: 'desktop' | 'site';
4
6
  title: string | null;
5
7
  titleSource: "fallback" | "generated" | "manual";
6
8
  messageCount: number;
@@ -18,16 +18,23 @@ const CHAT_RULES = [
18
18
  export function redactUserText({ text }, { secretField = false } = {}) {
19
19
  // Existing removal markers must survive a second pass through assignment rules (api_key=…).
20
20
  const literalMarkers = new Map();
21
+ let unsafeMarkers = 0;
21
22
  let literalPrefix = 'chat_literal_';
22
23
  while (text.includes(literalPrefix))
23
24
  literalPrefix += '_';
24
25
  const protectedText = text.replace(REDACTION_MARKER, marker => {
26
+ // Marker syntax is user input too: only protect it after checking its contents, otherwise
27
+ // `[REDACTED:password=short]` bypasses storage and model-history redaction entirely.
28
+ if (redactSecretShapes({ text: marker, policy: { additionalRules: CHAT_RULES } }).redactions > 0) {
29
+ unsafeMarkers += 1;
30
+ return INTERNAL_REMOVED;
31
+ }
25
32
  const key = '[REDACTED:' + literalPrefix + literalMarkers.size + ']';
26
33
  literalMarkers.set(key, marker);
27
34
  return key;
28
35
  }).replaceAll(REMOVED, INTERNAL_REMOVED);
29
36
  const base = redactSecretShapes({ text: protectedText, policy: { additionalRules: CHAT_RULES } });
30
- let count = base.redactions;
37
+ let count = base.redactions + unsafeMarkers;
31
38
  let cleaned = base.text;
32
39
  // A labelled credential answer can be a short password with no recognisable shape at all.
33
40
  if (secretField && cleaned.trim() !== '' && cleaned !== INTERNAL_REMOVED) {
@@ -1,14 +1,31 @@
1
1
  import type { ChatCleanupConfirm, WiredChatCleanup } from "./chat-cleanup.hooks.js";
2
2
  /**
3
- * The dock's chat cleanup controls, beside the switcher: a toggle that turns on row ticking, the
4
- * 1–365 day chooser in front of `ChatCleanupDialog` (which shows the server's count, bytes and kept
5
- * reasons before anything is deleted), and "Delete selected", which asks `confirm` first. Holds no
6
- * state of its own; everything comes from the injected {@link WiredChatCleanup}.
3
+ * The chat cleanup's home in the chat settings dialog (its `displayExtra` slot): a broom toggle with
4
+ * its label, which turns on row ticking in the chat list, and the 1–365 day chooser in front of
5
+ * `ChatCleanupDialog` (which shows the server's count, bytes and kept reasons before anything is
6
+ * deleted). Holds no state of its own; everything comes from the injected {@link WiredChatCleanup}.
7
7
  *
8
- * @param props.confirm - The admin confirm dialog; delete-selected waits for its visible answer.
8
+ * Why the toggle is a plain icon button and not `cleanup.kit.Button`: the kit button is the host's
9
+ * filled action button, and as the dock header's "Clean up chats" it rendered as a large accent text
10
+ * button among the header's small icons (owner, 2026-11-29). The kit button stays for the actions.
11
+ *
12
+ * @param props.confirm - Unused here (delete-selected lives in {@link ChatCleanupSelectionActions});
13
+ * kept so both halves take the same props from the host.
9
14
  * @complexity O(k) in the number of kept chats the preview names.
10
15
  */
11
- export declare function ChatCleanupPanel({ cleanup, confirm }: {
16
+ export declare function ChatCleanupPanel({ cleanup }: {
17
+ cleanup: WiredChatCleanup;
18
+ confirm: ChatCleanupConfirm;
19
+ }, _optional?: {}): import("react").JSX.Element;
20
+ /**
21
+ * The chat list's foot while rows are ticked (`ConversationList`'s `selectionActions`): "Delete
22
+ * selected", which asks `confirm` first, and "Done", which leaves ticking mode. They sit under the
23
+ * ticks they act on; a header button for them read as unrelated chrome.
24
+ *
25
+ * @param props.confirm - The admin confirm dialog; delete-selected waits for its visible answer.
26
+ * @complexity O(1).
27
+ */
28
+ export declare function ChatCleanupSelectionActions({ cleanup, confirm }: {
12
29
  cleanup: WiredChatCleanup;
13
30
  confirm: ChatCleanupConfirm;
14
31
  }, _optional?: {}): import("react").JSX.Element;
@@ -1,17 +1,34 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { ChatCleanupDialog } from "../components/ChatCleanupDialog.js";
3
+ import { Icon } from "../components/Icon.js";
3
4
  /**
4
- * The dock's chat cleanup controls, beside the switcher: a toggle that turns on row ticking, the
5
- * 1–365 day chooser in front of `ChatCleanupDialog` (which shows the server's count, bytes and kept
6
- * reasons before anything is deleted), and "Delete selected", which asks `confirm` first. Holds no
7
- * state of its own; everything comes from the injected {@link WiredChatCleanup}.
5
+ * The chat cleanup's home in the chat settings dialog (its `displayExtra` slot): a broom toggle with
6
+ * its label, which turns on row ticking in the chat list, and the 1–365 day chooser in front of
7
+ * `ChatCleanupDialog` (which shows the server's count, bytes and kept reasons before anything is
8
+ * deleted). Holds no state of its own; everything comes from the injected {@link WiredChatCleanup}.
8
9
  *
9
- * @param props.confirm - The admin confirm dialog; delete-selected waits for its visible answer.
10
+ * Why the toggle is a plain icon button and not `cleanup.kit.Button`: the kit button is the host's
11
+ * filled action button, and as the dock header's "Clean up chats" it rendered as a large accent text
12
+ * button among the header's small icons (owner, 2026-11-29). The kit button stays for the actions.
13
+ *
14
+ * @param props.confirm - Unused here (delete-selected lives in {@link ChatCleanupSelectionActions});
15
+ * kept so both halves take the same props from the host.
10
16
  * @complexity O(k) in the number of kept chats the preview names.
11
17
  */
12
- export function ChatCleanupPanel({ cleanup, confirm }, _optional = {}) {
18
+ export function ChatCleanupPanel({ cleanup }, _optional = {}) {
19
+ return (_jsxs("div", { className: "jini-chat-cleanup", children: [_jsxs("button", { type: "button", className: "jini-chat-cleanup-toggle", "aria-expanded": cleanup.open, title: cleanup.copy.open, onClick: () => cleanup.setOpen(!cleanup.open), children: [_jsx(Icon, { name: "broom", size: 16 }), _jsx("span", { children: cleanup.copy.open })] }), cleanup.open ? _jsxs("div", { className: "jini-chat-cleanup-panel", children: [_jsxs("label", { className: "jini-chat-cleanup-age", children: [cleanup.copy.olderThan, _jsx("input", { type: "number", min: 1, max: 365, step: 1, value: Number.isNaN(cleanup.olderThanDays) ? "" : cleanup.olderThanDays, onChange: (event) => cleanup.setOlderThanDays(event.currentTarget.valueAsNumber) })] }), _jsx(ChatCleanupDialog, { useChatCleanup: cleanup.useDialog, kit: cleanup.kit, copy: cleanup.copy.dialog, onDone: () => cleanup.setOpen(false) }), cleanup.error ? _jsx("p", { role: "alert", className: "jini-chat-cleanup-error", children: cleanup.error }) : null] }) : null] }));
20
+ }
21
+ /**
22
+ * The chat list's foot while rows are ticked (`ConversationList`'s `selectionActions`): "Delete
23
+ * selected", which asks `confirm` first, and "Done", which leaves ticking mode. They sit under the
24
+ * ticks they act on; a header button for them read as unrelated chrome.
25
+ *
26
+ * @param props.confirm - The admin confirm dialog; delete-selected waits for its visible answer.
27
+ * @complexity O(1).
28
+ */
29
+ export function ChatCleanupSelectionActions({ cleanup, confirm }, _optional = {}) {
13
30
  const { Button } = cleanup.kit;
14
31
  const count = cleanup.selectedIds.length;
15
- return (_jsxs("div", { className: "assistant-chat-cleanup", children: [_jsx(Button, { type: "button", "aria-expanded": cleanup.open, onClick: () => cleanup.setOpen(!cleanup.open), children: cleanup.copy.open }), cleanup.open ? _jsxs("div", { className: "assistant-chat-cleanup__panel", children: [_jsxs("label", { children: [cleanup.copy.olderThan, _jsx("input", { type: "number", min: 1, max: 365, step: 1, value: Number.isNaN(cleanup.olderThanDays) ? "" : cleanup.olderThanDays, onChange: (event) => cleanup.setOlderThanDays(event.currentTarget.valueAsNumber) })] }), _jsx(ChatCleanupDialog, { useChatCleanup: cleanup.useDialog, kit: cleanup.kit, copy: cleanup.copy.dialog, onDone: () => cleanup.setOpen(false) }), _jsx(Button, { type: "button", disabled: count === 0, onClick: () => { void cleanup.deleteSelected({ confirm }); }, children: cleanup.copy.deleteSelected({ count }) }), cleanup.error ? _jsx("p", { role: "alert", children: cleanup.error }) : null] }) : null] }));
32
+ return _jsxs(_Fragment, { children: [_jsx(Button, { type: "button", "data-variant": "danger", disabled: count === 0, onClick: () => { void cleanup.deleteSelected({ confirm }); }, children: cleanup.copy.deleteSelected({ count }) }), _jsx(Button, { type: "button", "data-variant": "ghost", onClick: () => cleanup.setOpen(false), children: cleanup.copy.done }), cleanup.error ? _jsx("p", { role: "alert", className: "jini-chat-cleanup-error", children: cleanup.error }) : null] });
16
33
  }
17
34
  //# sourceMappingURL=ChatCleanupPanel.js.map
@@ -47,6 +47,8 @@ export interface ChatCleanupCopy {
47
47
  }) => string;
48
48
  };
49
49
  open: string;
50
+ /** Leaves row ticking from the chat list's selection actions. */
51
+ done: string;
50
52
  olderThan: string;
51
53
  deleteSelected: (required: {
52
54
  count: number;
@@ -82,6 +84,10 @@ export interface ChatCleanupClient {
82
84
  confirm: true;
83
85
  }) => Promise<ChatCleanupResult>;
84
86
  }
87
+ /**
88
+ * The host's action button. Callers pass `data-variant` ("secondary" | "danger" | "ghost") for the
89
+ * look; a hyphenated attribute keeps a plain `"button"` a valid kit, which simply ignores it.
90
+ */
85
91
  export type ChatCleanupKit = {
86
92
  Button: ElementType<ButtonHTMLAttributes<HTMLButtonElement>>;
87
93
  };
@@ -1,7 +1,10 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  export function ChatCleanupDialog({ useChatCleanup, kit: { Button }, copy, onDone }, _optional = {}) {
3
3
  const cleanup = useChatCleanup();
4
- return _jsxs("div", { role: "dialog", children: [cleanup.state === 'preview' ? _jsx(Button, { type: "button", onClick: cleanup.preview, children: copy.preview }) : null, cleanup.state === 'expired' ? _jsxs(_Fragment, { children: [_jsx("p", { children: copy.expired }), _jsx(Button, { type: "button", onClick: cleanup.choose, children: copy.choose })] }) : null, cleanup.state === 'confirm' || cleanup.state === 'partial' ? _jsxs(_Fragment, { children: [_jsx("p", { children: copy.count({ count: cleanup.count, bytes: cleanup.bytes }) }), cleanup.state === 'partial' ? _jsx("p", { children: copy.partial }) : null, _jsx("ul", { children: cleanup.kept.map(item => _jsxs("li", { children: [item.title, ": ", item.reason] }, item.id)) }), _jsx(Button, { type: "button", disabled: !cleanup.previewToken, onClick: async () => {
4
+ // A group, not role="dialog": it renders inside the chat settings modal, and a second dialog role
5
+ // nested in it would announce a dialog that never takes focus. `data-variant` asks the host's kit
6
+ // button for a quieter or a danger look; a plain `<button>` just ignores it.
7
+ return _jsxs("div", { role: "group", className: "jini-chat-cleanup-preview", children: [cleanup.state === 'preview' ? _jsx(Button, { type: "button", "data-variant": "secondary", onClick: cleanup.preview, children: copy.preview }) : null, cleanup.state === 'expired' ? _jsxs(_Fragment, { children: [_jsx("p", { children: copy.expired }), _jsx(Button, { type: "button", "data-variant": "secondary", onClick: cleanup.choose, children: copy.choose })] }) : null, cleanup.state === 'confirm' || cleanup.state === 'partial' ? _jsxs(_Fragment, { children: [_jsx("p", { children: copy.count({ count: cleanup.count, bytes: cleanup.bytes }) }), cleanup.state === 'partial' ? _jsx("p", { children: copy.partial }) : null, _jsx("ul", { children: cleanup.kept.map(item => _jsxs("li", { children: [item.title, ": ", item.reason] }, item.id)) }), _jsx(Button, { type: "button", "data-variant": "danger", disabled: !cleanup.previewToken, onClick: async () => {
5
8
  if (!cleanup.previewToken)
6
9
  return;
7
10
  const result = await cleanup.apply({ previewToken: cleanup.previewToken, confirm: true });
@@ -1,3 +1,4 @@
1
+ import { type ReactNode } from 'react';
1
2
  import { useChatSettingsView, type ChatPermissionsPort, type ChatSettingsSection } from './ChatSettingsDialog.hooks.js';
2
3
  /** Advanced chat settings; the host supplies display actions, capabilities and persistence.
3
4
  * Native dialog semantics own modal focus containment; closing restores the opener.
@@ -10,5 +11,7 @@ export declare function ChatSettingsDialog({ useChatSettingsViewHook, ...require
10
11
  displaySections: readonly ChatSettingsSection[];
11
12
  permissions: ChatPermissionsPort;
12
13
  t?: (key: string) => string;
14
+ /** A host control after the display groups (the dock's chat cleanup); absent shows nothing extra. */
15
+ displayExtra?: ReactNode;
13
16
  }): import("react").JSX.Element;
14
17
  //# sourceMappingURL=ChatSettingsDialog.d.ts.map
@@ -64,7 +64,7 @@ export function ChatSettingsDialog({ useChatSettingsViewHook = useChatSettingsVi
64
64
  const verticalOutside = y < box.top || y > box.bottom;
65
65
  if ((x === 0 && y === 0) || horizontalOutside || verticalOutside)
66
66
  required.onClose();
67
- }, children: _jsx(ChatSettingsBody, { vm: vm, titleId: titleId, closeRef: closeRef, onClose: required.onClose }) });
67
+ }, children: _jsx(ChatSettingsBody, { vm: vm, titleId: titleId, closeRef: closeRef, onClose: required.onClose, displayExtra: required.displayExtra }) });
68
68
  }
69
69
  function renderDisplaySection(section) {
70
70
  if (section.radio)
@@ -77,8 +77,8 @@ function renderDisplaySection(section) {
77
77
  function renderPermissions(vm) {
78
78
  return _jsxs(_Fragment, { children: [_jsx("p", { className: "jini-chat-settings-note", children: vm.t('Permission changes apply to the next run.') }), vm.permissions.unavailableReason && _jsx("p", { className: "jini-chat-settings-note", children: vm.t(vm.permissions.unavailableReason) }), _jsx(SettingSwitch, { className: "jini-chat-settings-row--master", label: vm.master.label, checked: vm.master.checked, disabled: vm.master.disabled, onChange: checked => vm.master.onCheckedChange({ checked }), description: vm.master.description, descriptionId: vm.master.descriptionId }), _jsx("div", { className: "jini-chat-settings-capabilities", children: vm.capabilities.map(item => _jsx(SettingSwitch, { label: item.control.label, checked: item.control.checked, disabled: item.control.disabled, onChange: checked => item.control.onCheckedChange({ checked }), description: item.description, descriptionId: item.descriptionId }, item.key)) }), vm.permissions.busy && _jsx("p", { role: "status", className: "jini-chat-settings-note", children: vm.t('Saving…') }), vm.permissions.error && _jsx("p", { role: "alert", className: "jini-chat-settings-error", children: vm.permissions.error })] });
79
79
  }
80
- function ChatSettingsBody({ vm, titleId, closeRef, onClose }) {
81
- return _jsxs(_Fragment, { children: [_jsxs("header", { className: "jini-chat-settings-header", children: [_jsx("h2", { id: titleId, className: "jini-dialog-title", children: vm.t('Chat settings') }), _jsx("button", { ref: closeRef, type: "button", className: "jini-dialog-close jini-chat-settings-close", "aria-label": vm.t('Close'), onClick: onClose, children: _jsx("span", { "aria-hidden": "true", children: "\u00D7" }) })] }), _jsx(TabBar, { tabs: vm.tabs, activeId: vm.tab, onChange: vm.setTab, ariaLabel: vm.t('Chat settings') }), _jsx("div", { className: "jini-chat-settings-body", role: "tabpanel", "aria-label": vm.tab === 'display' ? vm.t('Display') : vm.t('Agent permissions'), children: vm.tab === 'display' ? vm.display.map(renderDisplaySection)
80
+ function ChatSettingsBody({ vm, titleId, closeRef, onClose, displayExtra }) {
81
+ return _jsxs(_Fragment, { children: [_jsxs("header", { className: "jini-chat-settings-header", children: [_jsx("h2", { id: titleId, className: "jini-dialog-title", children: vm.t('Chat settings') }), _jsx("button", { ref: closeRef, type: "button", className: "jini-dialog-close jini-chat-settings-close", "aria-label": vm.t('Close'), onClick: onClose, children: _jsx("span", { "aria-hidden": "true", children: "\u00D7" }) })] }), _jsx(TabBar, { tabs: vm.tabs, activeId: vm.tab, onChange: vm.setTab, ariaLabel: vm.t('Chat settings') }), _jsx("div", { className: "jini-chat-settings-body", role: "tabpanel", "aria-label": vm.tab === 'display' ? vm.t('Display') : vm.t('Agent permissions'), children: vm.tab === 'display' ? _jsxs(_Fragment, { children: [vm.display.map(renderDisplaySection), displayExtra] })
82
82
  : renderPermissions(vm) }), " "] });
83
83
  }
84
84
  //# sourceMappingURL=ChatSettingsDialog.js.map
@@ -0,0 +1,19 @@
1
+ import type { ConversationListItem, ConversationListProps } from './ConversationList.js';
2
+ type ConversationKind = NonNullable<ConversationListItem['kind']>;
3
+ /** Keep the host's existing neutral button styling; both destinations use the same creation gate. */
4
+ export declare function ConversationCreationButtons({ actions, disabled, onCreate, onCreateKind, t }: {
5
+ actions: ConversationListProps['creationActions'];
6
+ disabled: boolean;
7
+ onCreate: () => void;
8
+ onCreateKind: (required: {
9
+ kind: ConversationKind;
10
+ }) => void;
11
+ t: (key: string) => string;
12
+ }): import("react").JSX.Element;
13
+ /** Missing kind means an older host, not evidence that a conversation belongs to the current site. */
14
+ export declare function ConversationKindIcon({ kind, t }: {
15
+ kind: ConversationListItem['kind'];
16
+ t: (key: string) => string;
17
+ }): import("react").JSX.Element | null;
18
+ export {};
19
+ //# sourceMappingURL=ConversationList.creation.d.ts.map
@@ -0,0 +1,25 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Icon } from './Icon.js';
3
+ function kindLabel({ kind }) {
4
+ return kind === 'desktop' ? 'Desktop chat' : 'Site chat';
5
+ }
6
+ function KindCreationButton({ kind, disabled, onCreate, t }) {
7
+ const label = t(kind === 'desktop' ? 'New desktop chat' : 'New site chat');
8
+ return _jsxs("button", { type: "button", className: "jini-conv-new", disabled: disabled, "aria-label": label, title: label, "data-testid": `conversation-new-${kind}`, onClick: () => onCreate({ kind }), children: [_jsx(Icon, { name: "plus", size: 12 }), _jsx(Icon, { name: kind === 'desktop' ? 'monitor' : 'globe', size: 12, "data-conversation-icon": kind === 'desktop' ? 'monitor' : 'globe' })] });
9
+ }
10
+ /** Keep the host's existing neutral button styling; both destinations use the same creation gate. */
11
+ export function ConversationCreationButtons({ actions, disabled, onCreate, onCreateKind, t }) {
12
+ // `disabled` alone guards clicks: disabled native buttons never dispatch their click handler.
13
+ if (!actions)
14
+ return _jsxs("button", { type: "button", className: "jini-conv-new", disabled: disabled, "data-testid": "conversation-new", onClick: onCreate, children: [_jsx(Icon, { name: "plus", size: 12 }), _jsx("span", { children: t('New') })] });
15
+ return _jsxs(_Fragment, { children: [_jsx(KindCreationButton, { kind: "desktop", disabled: disabled || Boolean(actions.desktop.disabled), onCreate: onCreateKind, t: t }), _jsx(KindCreationButton, { kind: "site", disabled: disabled || Boolean(actions.site.disabled), onCreate: onCreateKind, t: t })] });
16
+ }
17
+ /** Missing kind means an older host, not evidence that a conversation belongs to the current site. */
18
+ export function ConversationKindIcon({ kind, t }) {
19
+ if (!kind)
20
+ return null;
21
+ const label = t(kindLabel({ kind }));
22
+ const icon = kind === 'desktop' ? 'monitor' : 'globe';
23
+ return _jsx("span", { className: "jini-conv-item-kind", role: "img", "aria-label": label, title: label, children: _jsx(Icon, { name: icon, size: 12, "data-conversation-icon": icon }) });
24
+ }
25
+ //# sourceMappingURL=ConversationList.creation.js.map
@@ -29,6 +29,19 @@ export interface ConversationListItem {
29
29
  messageCount?: number;
30
30
  updatedAt?: number;
31
31
  pinned?: boolean;
32
+ /** Host-owned transcript location; absence keeps older hosts' rows unclassified. */
33
+ kind?: 'desktop' | 'site';
34
+ }
35
+ /** Opt in to explicit destinations. The host owns creation, selection and any site picker. */
36
+ export interface ConversationCreationActions {
37
+ desktop: {
38
+ onCreate: () => void | Promise<void>;
39
+ disabled?: boolean;
40
+ };
41
+ site: {
42
+ onCreate: () => void | Promise<void>;
43
+ disabled?: boolean;
44
+ };
32
45
  }
33
46
  export interface ConversationListProps {
34
47
  hooks: ConversationListHooks;
@@ -46,6 +59,8 @@ export interface ConversationListProps {
46
59
  activeConversationId: string | null;
47
60
  onSelect: (id: string) => void;
48
61
  onCreate: () => void | Promise<void>;
62
+ /** Replaces the legacy New action with desktop/site actions; never inferred from tool scope. */
63
+ creationActions?: ConversationCreationActions | undefined;
49
64
  /** Omit to hide deletion controls. */
50
65
  onDelete?: (id: string) => void | Promise<void>;
51
66
  /** Omit to hide renaming controls and its double-click shortcut. */
@@ -71,6 +86,11 @@ export interface ConversationListProps {
71
86
  * the icon (the browser's dark tip would otherwise show on top of it). Defaults to true.
72
87
  */
73
88
  nativeTitle?: boolean;
89
+ /**
90
+ * Shown at the foot of the open menu while `selectable` is on: the host's actions over the ticked
91
+ * rows (e.g. "Delete selected"). They live beside the ticks they act on rather than in a header.
92
+ */
93
+ selectionActions?: React.ReactNode;
74
94
  }
75
95
  /** Hooks ConversationList calls; the host passes the real ones or a test hands in fakes. */
76
96
  export declare const defaultConversationListHooks: {
@@ -78,5 +98,5 @@ export declare const defaultConversationListHooks: {
78
98
  useConversationListView: typeof useConversationListView;
79
99
  };
80
100
  export type ConversationListHooks = typeof defaultConversationListHooks;
81
- export declare function ConversationList({ conversations: savedConversations, activeConversationId, onSelect, onCreate, onDelete, onRename, onSearch, confirmDelete, createDisabled, emptyState, triggerLabel, nativeTitle, hooks, report, selectable, selectedIds, onTogglePin, onSelectionChange, }: ConversationListProps, _optional?: {}): import("react").JSX.Element;
101
+ export declare function ConversationList({ conversations: savedConversations, activeConversationId, onSelect, onCreate, creationActions, onDelete, onRename, onSearch, confirmDelete, createDisabled, emptyState, triggerLabel, nativeTitle, hooks, report, selectable, selectedIds, onTogglePin, onSelectionChange, selectionActions, }: ConversationListProps, _optional?: {}): import("react").JSX.Element;
82
102
  //# sourceMappingURL=ConversationList.d.ts.map