@gemies/sdk 10.8.0 → 10.9.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/CHANGELOG.md +20 -0
- package/README.md +4 -0
- package/package.json +1 -1
- package/src/components/GemieChatContent.tsx +82 -3
- package/src/components/GemieComposer.tsx +4 -0
- package/src/components/thread/FollowUpStatus.tsx +35 -0
- package/src/components/thread/GemieThread.tsx +25 -1
- package/src/components/thread/ThreadFindBar.tsx +121 -0
- package/src/components/thread/ThreadPanel.tsx +34 -0
- package/src/components/thread/ThreadRow.tsx +44 -9
- package/src/components/thread/ThreadSearch.tsx +61 -78
- package/src/components/thread/ThreadTurns.tsx +94 -0
- package/src/hooks/useFindShortcut.ts +57 -0
- package/src/hooks/useRowJump.ts +79 -0
- package/src/hooks/useThreadNavigation.ts +134 -0
- package/src/hooks/useTimelineWindow.ts +18 -1
- package/src/lib/copy-en.ts +11 -0
- package/src/lib/copy-es.ts +11 -0
- package/src/runtime/thread/thread-find.ts +95 -0
- package/src/runtime/use-approval-actions.ts +7 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { messageText } from '../../lib/content-utils';
|
|
2
|
+
import type { Message } from '../types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Finding words in the open thread, and the turns it can be jumped between, as data.
|
|
6
|
+
*
|
|
7
|
+
* Both read only the rows already loaded, which includes those above the mounted window
|
|
8
|
+
* (`timeline.ts`) but not history the thread has not paged in yet.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** A turn of the thread, as the jump list names it: the person's message that opened it. */
|
|
12
|
+
export interface ThreadTurn {
|
|
13
|
+
/** The id of the person's message, which is the row a jump lands on. */
|
|
14
|
+
id: string;
|
|
15
|
+
/** Its first words, on one line. Empty for a turn that was only attachments. */
|
|
16
|
+
preview: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** How much of a question the jump list shows. */
|
|
20
|
+
const PREVIEW_LENGTH = 120;
|
|
21
|
+
|
|
22
|
+
const FENCE = /^[ \t]*(```|~~~).*$/;
|
|
23
|
+
const BLOCK_TAG =
|
|
24
|
+
/\[\/?(?:ALIA_)?(?:COMPACTLIST|BANNER|COMPARISON|TIMELINE|IMAGE|CREDIBILITY)\b[^\]]*\]/g;
|
|
25
|
+
|
|
26
|
+
/** One line of Markdown without the marks a reader never sees. */
|
|
27
|
+
function stripInline(line: string): string {
|
|
28
|
+
return (
|
|
29
|
+
line
|
|
30
|
+
.replace(/^[ \t]*(?:#{1,6}[ \t]+|>[ \t]?|[-*+][ \t]+|\d+\.[ \t]+)/, '')
|
|
31
|
+
// An image or a link reads as its text; the address is not on screen.
|
|
32
|
+
.replace(/!?\[([^\]]*)\]\([^)]*\)/g, '$1')
|
|
33
|
+
.replace(/(\*\*|__|~~)(?=\S)(.+?)\1/g, '$2')
|
|
34
|
+
// Single marks only around a whole run, so `snake_case` and `2 * 3` stay as written.
|
|
35
|
+
.replace(/(?<![\w*_])([*_])(?!\s)([^*_\n]+?)\1(?![\w*_])/g, '$2')
|
|
36
|
+
.replace(/`([^`]*)`/g, '$1')
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A reply's Markdown as the words it draws. Code inside a fence is kept exactly. */
|
|
41
|
+
function withoutMarkdown(source: string): string {
|
|
42
|
+
const out: string[] = [];
|
|
43
|
+
let fenced = false;
|
|
44
|
+
for (const line of source.replace(BLOCK_TAG, ' ').split('\n')) {
|
|
45
|
+
if (FENCE.test(line)) fenced = !fenced;
|
|
46
|
+
else out.push(fenced ? line : stripInline(line));
|
|
47
|
+
}
|
|
48
|
+
return out.join('\n');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const visible = new WeakMap<Message, string>();
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The words a row shows: a question as typed, a reply without its Markdown. Remembered per message
|
|
55
|
+
* object, which a streamed token replaces, so an open find re-reads only the reply being written.
|
|
56
|
+
*/
|
|
57
|
+
export function visibleText(message: Message): string {
|
|
58
|
+
let text = visible.get(message);
|
|
59
|
+
if (text === undefined) {
|
|
60
|
+
const words = messageText(message);
|
|
61
|
+
text = (message.role === 'assistant' ? withoutMarkdown(words) : words)
|
|
62
|
+
.replace(/\s+/g, ' ')
|
|
63
|
+
.trim();
|
|
64
|
+
visible.set(message, text);
|
|
65
|
+
}
|
|
66
|
+
return text;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Case and accents are not what a person is looking for: "informacion" finds "Información". */
|
|
70
|
+
function fold(text: string): string {
|
|
71
|
+
return text
|
|
72
|
+
.normalize('NFD')
|
|
73
|
+
.replace(/\p{Mark}/gu, '')
|
|
74
|
+
.toLowerCase();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** The ids of the messages whose visible words contain `query`, in reading order. */
|
|
78
|
+
export function findMatches(rows: readonly Message[], query: string): string[] {
|
|
79
|
+
const wanted = fold(query.replace(/\s+/g, ' ').trim());
|
|
80
|
+
if (wanted === '') return [];
|
|
81
|
+
return rows.filter((row) => fold(visibleText(row)).includes(wanted)).map((row) => row.id);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The index `delta` steps from `index` among `count` matches, wrapping at both ends. */
|
|
85
|
+
export function stepMatch(index: number, delta: 1 | -1, count: number): number {
|
|
86
|
+
if (count === 0) return -1;
|
|
87
|
+
return (index + delta + count) % count;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The thread's turns, one per message of the person's, in reading order. */
|
|
91
|
+
export function threadTurns(rows: readonly Message[]): ThreadTurn[] {
|
|
92
|
+
return rows
|
|
93
|
+
.filter((row) => row.role === 'user')
|
|
94
|
+
.map((row) => ({ id: row.id, preview: visibleText(row).slice(0, PREVIEW_LENGTH) }));
|
|
95
|
+
}
|
|
@@ -26,6 +26,8 @@ export interface ApprovalActions {
|
|
|
26
26
|
readonly canAnswer: boolean;
|
|
27
27
|
/** Questions whose answer is on its way: nothing is offered for them until it arrives. */
|
|
28
28
|
readonly sending: ReadonlySet<string>;
|
|
29
|
+
/** Those of `sending` whose answer carries words for the agent: a reply steering the turn. */
|
|
30
|
+
readonly steering: ReadonlySet<string>;
|
|
29
31
|
/** Questions whose answer could not be sent: offered again, with a line saying so. */
|
|
30
32
|
readonly failed: ReadonlySet<string>;
|
|
31
33
|
/** The oldest question still waiting: the one the bar and the shortcuts are about. */
|
|
@@ -81,6 +83,7 @@ export function useApprovalActions({
|
|
|
81
83
|
grants: source,
|
|
82
84
|
}: UseApprovalActionsInput): ApprovalActions {
|
|
83
85
|
const [sending, setSending] = useState<ReadonlySet<string>>(() => new Set());
|
|
86
|
+
const [steering, setSteering] = useState<ReadonlySet<string>>(() => new Set());
|
|
84
87
|
const [failed, setFailed] = useState<ReadonlySet<string>>(() => new Set());
|
|
85
88
|
// The guard is a ref: two presses in one frame both see the same render's state.
|
|
86
89
|
const inFlight = useRef(new Set<string>());
|
|
@@ -91,6 +94,7 @@ export function useApprovalActions({
|
|
|
91
94
|
if (!onDecide || entry.outcome !== 'pending' || inFlight.current.has(id)) return false;
|
|
92
95
|
inFlight.current.add(id);
|
|
93
96
|
setSending((s) => mark(s, id, true));
|
|
97
|
+
if (details?.feedback) setSteering((s) => mark(s, id, true));
|
|
94
98
|
setFailed((f) => mark(f, id, false));
|
|
95
99
|
try {
|
|
96
100
|
await onDecide(entry, decision, details);
|
|
@@ -104,6 +108,7 @@ export function useApprovalActions({
|
|
|
104
108
|
} finally {
|
|
105
109
|
inFlight.current.delete(id);
|
|
106
110
|
setSending((s) => mark(s, id, false));
|
|
111
|
+
setSteering((s) => mark(s, id, false));
|
|
107
112
|
}
|
|
108
113
|
},
|
|
109
114
|
[onDecide, onSettled, onStopTurn],
|
|
@@ -151,12 +156,13 @@ export function useApprovalActions({
|
|
|
151
156
|
agentName,
|
|
152
157
|
canAnswer: onDecide !== undefined,
|
|
153
158
|
sending,
|
|
159
|
+
steering,
|
|
154
160
|
failed,
|
|
155
161
|
pending,
|
|
156
162
|
grants,
|
|
157
163
|
revokeGrant,
|
|
158
164
|
decide,
|
|
159
165
|
}),
|
|
160
|
-
[entries, agentName, onDecide, sending, failed, pending, grants, revokeGrant, decide],
|
|
166
|
+
[entries, agentName, onDecide, sending, steering, failed, pending, grants, revokeGrant, decide],
|
|
161
167
|
);
|
|
162
168
|
}
|