@jini-ai/chat 0.7.3-next.4 → 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.
- package/CHANGELOG.md +7 -0
- package/README.md +35 -0
- package/dist/core/assistant-client/ag-ui-browser-delivery.d.ts +43 -0
- package/dist/core/assistant-client/ag-ui-browser-delivery.js +113 -0
- package/dist/core/assistant-client/ag-ui-confirmation-session.d.ts +60 -0
- package/dist/core/assistant-client/ag-ui-confirmation-session.js +138 -0
- package/dist/core/assistant-client/ag-ui-live-turn.d.ts +85 -0
- package/dist/core/assistant-client/ag-ui-live-turn.js +296 -0
- package/dist/core/assistant-client/ag-ui-transport.d.ts +6 -0
- package/dist/core/assistant-client/ag-ui-transport.js +3 -0
- package/dist/core/assistant-client/messages.d.ts +2 -0
- package/dist/core/user-text-redaction.js +8 -1
- package/dist/react/components/ConversationList.creation.d.ts +19 -0
- package/dist/react/components/ConversationList.creation.js +25 -0
- package/dist/react/components/ConversationList.d.ts +16 -1
- package/dist/react/components/ConversationList.hooks.d.ts +5 -1
- package/dist/react/components/ConversationList.hooks.js +10 -2
- package/dist/react/components/ConversationList.js +11 -12
- package/dist/react/components/Icon.d.ts +1 -1
- package/dist/react/components/Icon.js +2 -0
- package/dist/react/components/ToolCard.rules.js +9 -6
- package/dist/react/features/chat-pane/styles.d.ts +1 -1
- package/dist/react/features/chat-pane/styles.js +3 -0
- package/dist/react/index.d.ts +1 -1
- package/dist/store/runtime/attempt-base-retention.js +3 -2
- 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) {
|
|
@@ -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. */
|
|
@@ -83,5 +98,5 @@ export declare const defaultConversationListHooks: {
|
|
|
83
98
|
useConversationListView: typeof useConversationListView;
|
|
84
99
|
};
|
|
85
100
|
export type ConversationListHooks = typeof defaultConversationListHooks;
|
|
86
|
-
export declare function ConversationList({ conversations: savedConversations, activeConversationId, onSelect, onCreate, onDelete, onRename, onSearch, confirmDelete, createDisabled, emptyState, triggerLabel, nativeTitle, hooks, report, selectable, selectedIds, onTogglePin, onSelectionChange, selectionActions, }: 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;
|
|
87
102
|
//# sourceMappingURL=ConversationList.d.ts.map
|
|
@@ -19,12 +19,13 @@ export declare function useConversationListTitles({ conversations, serverResults
|
|
|
19
19
|
rawTitles: ReadonlyMap<string, string | null>;
|
|
20
20
|
};
|
|
21
21
|
/** Manage search, selection timing, rename, deletion, and host effects for the switcher. */
|
|
22
|
-
export declare function useConversationListView({ savedConversations, activeConversationId, onSelect, onCreate, onDelete, onRename, onSearch, confirmDelete, emptyState, t }: {
|
|
22
|
+
export declare function useConversationListView({ savedConversations, activeConversationId, onSelect, onCreate, creationActions, onDelete, onRename, onSearch, confirmDelete, emptyState, t }: {
|
|
23
23
|
savedConversations: ConversationListProps['conversations'];
|
|
24
24
|
activeConversationId: ConversationListProps['activeConversationId'];
|
|
25
25
|
onSelect: ConversationListProps['onSelect'];
|
|
26
26
|
onCreate: ConversationListProps['onCreate'];
|
|
27
27
|
onDelete: ConversationListProps['onDelete'];
|
|
28
|
+
creationActions?: ConversationListProps['creationActions'];
|
|
28
29
|
onRename: ConversationListProps['onRename'];
|
|
29
30
|
onSearch: ConversationListProps['onSearch'];
|
|
30
31
|
confirmDelete: ConversationListProps['confirmDelete'];
|
|
@@ -51,6 +52,9 @@ export declare function useConversationListView({ savedConversations, activeConv
|
|
|
51
52
|
emptyLabel: () => string | number | bigint | boolean | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined>;
|
|
52
53
|
scheduleSelect: (id: string) => void;
|
|
53
54
|
createConversation: () => void;
|
|
55
|
+
createForKind: ({ kind }: {
|
|
56
|
+
kind: NonNullable<ConversationListItem["kind"]>;
|
|
57
|
+
}, _optional?: {}) => void;
|
|
54
58
|
selectionAnchor: import("react").RefObject<string | null>;
|
|
55
59
|
};
|
|
56
60
|
//# sourceMappingURL=ConversationList.hooks.d.ts.map
|
|
@@ -47,7 +47,7 @@ function runConversationListHostEffect({ effectName, effect }, { report } = {})
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
/** Manage search, selection timing, rename, deletion, and host effects for the switcher. */
|
|
50
|
-
export function useConversationListView({ savedConversations, activeConversationId, onSelect, onCreate, onDelete, onRename, onSearch, confirmDelete, emptyState, t }, { report } = {}) {
|
|
50
|
+
export function useConversationListView({ savedConversations, activeConversationId, onSelect, onCreate, creationActions, onDelete, onRename, onSearch, confirmDelete, emptyState, t }, { report } = {}) {
|
|
51
51
|
const [open, setOpen] = useState(false);
|
|
52
52
|
const [query, setQuery] = useState('');
|
|
53
53
|
const [savedServerResults, setServerResults] = useState(null);
|
|
@@ -198,6 +198,14 @@ export function useConversationListView({ savedConversations, activeConversation
|
|
|
198
198
|
runConversationListHostEffect({ effectName: 'onCreate', effect: () => onCreate() }, { report });
|
|
199
199
|
setOpen(false);
|
|
200
200
|
};
|
|
201
|
-
|
|
201
|
+
const createForKind = ({ kind }, _optional = {}) => {
|
|
202
|
+
const action = creationActions?.[kind];
|
|
203
|
+
// Never fall back to onCreate: that could write a site chat into desktop history or vice versa.
|
|
204
|
+
if (!action || action.disabled)
|
|
205
|
+
return;
|
|
206
|
+
runConversationListHostEffect({ effectName: `onCreate:${kind}`, effect: action.onCreate }, { report });
|
|
207
|
+
setOpen(false);
|
|
208
|
+
};
|
|
209
|
+
return { open, setOpen, query, setQuery, conversations, rawTitles, editingId, setEditingId, rootRef, visible, now, commitRename, startRename, requestDelete, active, emptyLabel, scheduleSelect, createConversation, createForKind, selectionAnchor };
|
|
202
210
|
}
|
|
203
211
|
//# sourceMappingURL=ConversationList.hooks.js.map
|
|
@@ -25,6 +25,7 @@ import { Icon } from './Icon.js';
|
|
|
25
25
|
import { useConversationListView } from './ConversationList.hooks.js';
|
|
26
26
|
import { conversationTriggerAttributes } from './ConversationList.rules.js';
|
|
27
27
|
import { ConversationTitleEditor } from './ConversationTitleEditor.js';
|
|
28
|
+
import { ConversationCreationButtons, ConversationKindIcon } from './ConversationList.creation.js';
|
|
28
29
|
function relativeTime(updatedAt, now) {
|
|
29
30
|
if (updatedAt === undefined)
|
|
30
31
|
return '';
|
|
@@ -92,24 +93,22 @@ function ConversationItemBody({ item, view, t, onRename }) {
|
|
|
92
93
|
}
|
|
93
94
|
function ConversationRow({ item, view, t, activeConversationId, selectable, selectedIds, onSelectionChange, onTogglePin, onRename, onDelete }) {
|
|
94
95
|
const { editingId, startRename, requestDelete } = view;
|
|
95
|
-
return (_jsxs("div", { className: `jini-conv-item${item.id === activeConversationId ? ' jini-conv-item-active' : ''}`, "data-testid": `conversation-item-${item.id}`, children: [selectable ? _jsx(SelectCheckbox, { item: item, view: view, t: t, selectedIds: selectedIds, onSelectionChange: onSelectionChange }) : null, _jsx(ConversationItemBody, { item: item, view: view, t: t, onRename: onRename }), onTogglePin ? _jsx(PinButton, { item: item, t: t, onTogglePin: onTogglePin }) : null, _jsx(ConversationActions, { itemId: item.id, editing: editingId === item.id, canRename: Boolean(onRename), canDelete: Boolean(onDelete), onRename: () => startRename(item.id), onDelete: () => requestDelete(item), t: t })] }));
|
|
96
|
+
return (_jsxs("div", { className: `jini-conv-item${item.id === activeConversationId ? ' jini-conv-item-active' : ''}`, "data-testid": `conversation-item-${item.id}`, children: [selectable ? _jsx(SelectCheckbox, { item: item, view: view, t: t, selectedIds: selectedIds, onSelectionChange: onSelectionChange }) : null, _jsx(ConversationKindIcon, { kind: item.kind, t: t }), _jsx(ConversationItemBody, { item: item, view: view, t: t, onRename: onRename }), onTogglePin ? _jsx(PinButton, { item: item, t: t, onTogglePin: onTogglePin }) : null, _jsx(ConversationActions, { itemId: item.id, editing: editingId === item.id, canRename: Boolean(onRename), canDelete: Boolean(onDelete), onRename: () => startRename(item.id), onDelete: () => requestDelete(item), t: t })] }));
|
|
96
97
|
}
|
|
97
|
-
/** The open menu's heading with its count and
|
|
98
|
-
function ConversationMenuHead({ view, t, createDisabled }) {
|
|
99
|
-
const { query, setQuery, conversations, createConversation } = view;
|
|
100
|
-
return _jsxs(_Fragment, { children: [_jsxs("div", { className: "jini-conv-head", children: [_jsxs("span", { className: "jini-conv-heading", children: [t('Conversations'), _jsx("span", { className: "jini-conv-count", "data-testid": "conversation-count", children: conversations.length })] }),
|
|
101
|
-
// `disabled` alone guards this: a disabled button never dispatches a click.
|
|
102
|
-
onClick: createConversation, children: [_jsx(Icon, { name: "plus", size: 12 }), _jsx("span", { children: t('New') })] })] }), _jsxs("label", { className: "jini-conv-search", children: [_jsx(Icon, { name: "search", size: 13 }), _jsx("input", { type: "search", value: query, placeholder: t('Search conversations'), "data-testid": "conversation-search", onChange: (event) => setQuery(event.currentTarget.value) })] })] });
|
|
98
|
+
/** The open menu's heading with its count and creation actions, then the search field. */
|
|
99
|
+
function ConversationMenuHead({ view, t, createDisabled, creationActions }) {
|
|
100
|
+
const { query, setQuery, conversations, createConversation, createForKind } = view;
|
|
101
|
+
return _jsxs(_Fragment, { children: [_jsxs("div", { className: "jini-conv-head", children: [_jsxs("span", { className: "jini-conv-heading", children: [t('Conversations'), _jsx("span", { className: "jini-conv-count", "data-testid": "conversation-count", children: conversations.length })] }), _jsx(ConversationCreationButtons, { actions: creationActions, disabled: createDisabled, t: t, onCreate: createConversation, onCreateKind: createForKind })] }), _jsxs("label", { className: "jini-conv-search", children: [_jsx(Icon, { name: "search", size: 13 }), _jsx("input", { type: "search", value: query, placeholder: t('Search conversations'), "data-testid": "conversation-search", onChange: (event) => setQuery(event.currentTarget.value) })] })] });
|
|
103
102
|
}
|
|
104
103
|
/** The menu's scrolling rows (or its empty line), then the host's selection actions while ticking. */
|
|
105
104
|
function ConversationRows({ view, t, selectionActions, ...rowProps }) {
|
|
106
|
-
const {
|
|
107
|
-
return _jsxs(_Fragment, { children: [_jsx("div", { className: "jini-conv-list", "data-testid": "conversation-list", children:
|
|
105
|
+
const { visible, emptyLabel } = view;
|
|
106
|
+
return _jsxs(_Fragment, { children: [_jsx("div", { className: "jini-conv-list", "data-testid": "conversation-list", children: visible.length === 0 ? (_jsx("div", { className: "jini-conv-empty", children: emptyLabel() })) : (visible.map((item) => _jsx(ConversationRow, { item: item, view: view, t: t, ...rowProps }, item.id))) }), rowProps.selectable && selectionActions ? (_jsx("div", { className: "jini-conv-selection-actions", "data-testid": "conversation-selection-actions", children: selectionActions })) : null] });
|
|
108
107
|
}
|
|
109
|
-
export function ConversationList({ conversations: savedConversations, activeConversationId, onSelect, onCreate, onDelete, onRename, onSearch, confirmDelete, createDisabled = false, emptyState, triggerLabel, nativeTitle = true, hooks, report, selectable, selectedIds, onTogglePin, onSelectionChange, selectionActions, }, _optional = {}) {
|
|
108
|
+
export function ConversationList({ conversations: savedConversations, activeConversationId, onSelect, onCreate, creationActions, onDelete, onRename, onSearch, confirmDelete, createDisabled = false, emptyState, triggerLabel, nativeTitle = true, hooks, report, selectable, selectedIds, onTogglePin, onSelectionChange, selectionActions, }, _optional = {}) {
|
|
110
109
|
const t = hooks.useT();
|
|
111
|
-
const view = hooks.useConversationListView({ savedConversations, activeConversationId, onSelect, onCreate, onDelete, onRename, onSearch, confirmDelete, emptyState, t }, { report });
|
|
110
|
+
const view = hooks.useConversationListView({ savedConversations, activeConversationId, onSelect, onCreate, creationActions, onDelete, onRename, onSearch, confirmDelete, emptyState, t }, { report });
|
|
112
111
|
const { open, setOpen, active, rootRef } = view;
|
|
113
|
-
return (_jsxs("div", { className: "jini-conv", ref: rootRef, children: [_jsx("button", { type: "button", className: `jini-conv-trigger${open ? ' jini-conv-trigger-open' : ''}`, "aria-haspopup": "menu", "aria-expanded": open, ...conversationTriggerAttributes({ activeTitle: active?.title, t }, { label: triggerLabel, nativeTitle }), "data-testid": "conversation-trigger", onClick: () => setOpen((v) => !v), children: _jsx(Icon, { name: "comment", size: 16 }) }), open ? (_jsxs("div", { className: "jini-conv-menu", role: "menu", "data-testid": "conversation-menu", children: [_jsx(ConversationMenuHead, { view: view, t: t, createDisabled: createDisabled }), _jsx(ConversationRows, { view: view, t: t, activeConversationId: activeConversationId, selectable: selectable, selectedIds: selectedIds, onSelectionChange: onSelectionChange, onTogglePin: onTogglePin, onRename: onRename, onDelete: onDelete, selectionActions: selectionActions })] })) : null] }));
|
|
112
|
+
return (_jsxs("div", { className: "jini-conv", ref: rootRef, children: [_jsx("button", { type: "button", className: `jini-conv-trigger${open ? ' jini-conv-trigger-open' : ''}`, "aria-haspopup": "menu", "aria-expanded": open, ...conversationTriggerAttributes({ activeTitle: active?.title, t }, { label: triggerLabel, nativeTitle }), "data-testid": "conversation-trigger", onClick: () => setOpen((v) => !v), children: _jsx(Icon, { name: "comment", size: 16 }) }), open ? (_jsxs("div", { className: "jini-conv-menu", role: "menu", "data-testid": "conversation-menu", children: [_jsx(ConversationMenuHead, { view: view, t: t, createDisabled: createDisabled, creationActions: creationActions }), _jsx(ConversationRows, { view: view, t: t, activeConversationId: activeConversationId, selectable: selectable, selectedIds: selectedIds, onSelectionChange: onSelectionChange, onTogglePin: onTogglePin, onRename: onRename, onDelete: onDelete, selectionActions: selectionActions })] })) : null] }));
|
|
114
113
|
}
|
|
115
114
|
//# sourceMappingURL=ConversationList.js.map
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* AgentIcon and WorkingDirPicker.
|
|
8
8
|
*/
|
|
9
9
|
import type { SVGProps } from 'react';
|
|
10
|
-
export type IconName = 'spinner' | 'check' | 'close' | 'chevron-down' | 'chevron-left' | 'chevron-right' | 'attach' | 'folder' | 'file' | 'image' | 'x' | 'comment' | 'search' | 'plus' | 'pencil' | 'copy' | 'external-link' | 'retry' | 'pin' | 'broom';
|
|
10
|
+
export type IconName = 'spinner' | 'check' | 'close' | 'chevron-down' | 'chevron-left' | 'chevron-right' | 'attach' | 'folder' | 'file' | 'image' | 'x' | 'comment' | 'search' | 'plus' | 'monitor' | 'globe' | 'pencil' | 'copy' | 'external-link' | 'retry' | 'pin' | 'broom';
|
|
11
11
|
interface IconProps extends Omit<SVGProps<SVGSVGElement>, 'name'> {
|
|
12
12
|
name: IconName;
|
|
13
13
|
size?: number | string;
|
|
@@ -12,6 +12,8 @@ const ICON_GLYPHS = {
|
|
|
12
12
|
comment: (_jsx("path", { d: "M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" })),
|
|
13
13
|
search: _jsxs(_Fragment, { children: [_jsx("circle", { cx: "11", cy: "11", r: "7" }), _jsx("path", { d: "m20 20-3.5-3.5" })] }),
|
|
14
14
|
plus: _jsxs(_Fragment, { children: [_jsx("path", { d: "M12 5v14" }), _jsx("path", { d: "M5 12h14" })] }),
|
|
15
|
+
monitor: _jsxs(_Fragment, { children: [_jsx("rect", { x: "3", y: "3", width: "18", height: "13", rx: "2" }), _jsx("path", { d: "M12 16v5M8 21h8" })] }),
|
|
16
|
+
globe: _jsxs(_Fragment, { children: [_jsx("circle", { cx: "12", cy: "12", r: "9" }), _jsx("ellipse", { cx: "12", cy: "12", rx: "4", ry: "9" }), _jsx("path", { d: "M3 12h18" })] }),
|
|
15
17
|
'chevron-left': _jsx("path", { d: "m15 18-6-6 6-6" }),
|
|
16
18
|
'chevron-right': _jsx("path", { d: "m9 18 6-6-6-6" }),
|
|
17
19
|
attach: _jsx("path", { d: "m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48" }),
|
|
@@ -43,8 +43,7 @@ function resultName(content) {
|
|
|
43
43
|
catch {
|
|
44
44
|
return undefined;
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
return undefined;
|
|
46
|
+
// A successful JSON parse of text starting with `{` always produces an object.
|
|
48
47
|
const obj = parsed;
|
|
49
48
|
if (isErrorResult(obj))
|
|
50
49
|
return undefined;
|
|
@@ -52,11 +51,15 @@ function resultName(content) {
|
|
|
52
51
|
const nested = Object.values(obj).filter((v) => v != null && typeof v === 'object' && !Array.isArray(v) && !isErrorResult(v));
|
|
53
52
|
return firstReadable(obj, RESULT_NAME_KEYS) ?? nested.map((v) => firstReadable(v, RESULT_NAME_KEYS)).find(Boolean);
|
|
54
53
|
}
|
|
55
|
-
/** A batch member's own target
|
|
56
|
-
function memberTarget(first) {
|
|
54
|
+
/** A batch member's own target, including its read window so separate sections stay distinguishable. O(k). */
|
|
55
|
+
function memberTarget({ first }, _options = {}) {
|
|
57
56
|
if (readable(first))
|
|
58
57
|
return first;
|
|
59
|
-
|
|
58
|
+
if (first == null || typeof first !== 'object')
|
|
59
|
+
return undefined;
|
|
60
|
+
const member = first;
|
|
61
|
+
// Batch envelopes keep pagination on each member; the outer call has no offset to display.
|
|
62
|
+
return targetAtOffset({ target: firstReadable(member, SUMMARY_KEYS), offset: member.offset, limit: member.limit });
|
|
60
63
|
}
|
|
61
64
|
/** A shallow batch target, independent of CLI and collection key. No document-body traversal.
|
|
62
65
|
* O(k) in the envelope and first member's key counts; never scans or serializes all members.
|
|
@@ -65,7 +68,7 @@ function batchTarget(input) {
|
|
|
65
68
|
const members = Array.isArray(input) ? input : Object.values(input).find(Array.isArray);
|
|
66
69
|
if (!members?.length)
|
|
67
70
|
return undefined;
|
|
68
|
-
const target = memberTarget(members[0]);
|
|
71
|
+
const target = memberTarget({ first: members[0] });
|
|
69
72
|
if (!target)
|
|
70
73
|
return `${members.length} ${members.length === 1 ? 'item' : 'items'}`;
|
|
71
74
|
return members.length === 1 ? target : `${target} +${members.length - 1}`;
|