@gemies/sdk 10.7.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 +44 -0
- package/README.md +4 -0
- package/package.json +1 -1
- package/src/components/GemieChatContent.tsx +83 -3
- package/src/components/GemieComposer.tsx +31 -2
- package/src/components/PlanPreviewCard.tsx +71 -18
- package/src/components/QuestionCard.tsx +47 -18
- 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/useApprovalShortcuts.ts +1 -1
- package/src/hooks/useFindShortcut.ts +57 -0
- package/src/hooks/useQuestionKeyboard.ts +193 -0
- package/src/hooks/useRowJump.ts +79 -0
- package/src/hooks/useThreadNavigation.ts +134 -0
- package/src/hooks/useTimelineWindow.ts +18 -1
- package/src/index.ts +1 -0
- package/src/lib/copy-en.ts +16 -0
- package/src/lib/copy-es.ts +16 -0
- package/src/lib/deferred/markdown-file.ts +5 -0
- package/src/lib/deferred/markdown-file.web.ts +8 -0
- package/src/lib/markdown-file.ts +39 -0
- package/src/lib/plan-markdown.ts +19 -0
- package/src/runtime/index.ts +1 -0
- package/src/runtime/markdown-file.ts +14 -0
- package/src/runtime/thread/conversation-export.ts +1 -1
- package/src/runtime/thread/thread-find.ts +95 -0
- package/src/runtime/use-approval-actions.ts +7 -1
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ComponentRef,
|
|
3
|
+
type Ref,
|
|
4
|
+
type RefObject,
|
|
5
|
+
useCallback,
|
|
6
|
+
useEffect,
|
|
7
|
+
useImperativeHandle,
|
|
8
|
+
useRef,
|
|
9
|
+
} from 'react';
|
|
10
|
+
import { Platform, type View } from 'react-native';
|
|
11
|
+
import { isEditing, type ShortcutKeyEvent } from './useApprovalShortcuts';
|
|
12
|
+
|
|
13
|
+
/** What a key pressed inside the question card asks of it. */
|
|
14
|
+
export type QuestionKeyCommand =
|
|
15
|
+
| 'previous'
|
|
16
|
+
| 'next'
|
|
17
|
+
| 'first'
|
|
18
|
+
| 'last'
|
|
19
|
+
/** Next, or Done on the last question. */
|
|
20
|
+
| 'confirm'
|
|
21
|
+
| 'dismiss'
|
|
22
|
+
/** Out of the free-text field, back to the options, keeping what was typed. */
|
|
23
|
+
| 'leaveField'
|
|
24
|
+
/** A held key: it must not answer the next question too. */
|
|
25
|
+
| 'swallow';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* What a key does while the focus is in the question card. Enter, Space and the digits that pick an
|
|
29
|
+
* answer are the card's own (Bloom's `Questionnaire`); this adds what it lacks. As with the
|
|
30
|
+
* approval keys, a held key counts once and an input method's keys are left to it.
|
|
31
|
+
*/
|
|
32
|
+
export function questionKey(event: ShortcutKeyEvent): QuestionKeyCommand | undefined {
|
|
33
|
+
if (event.defaultPrevented || event.isComposing || event.altKey || event.shiftKey) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
const { key } = event;
|
|
37
|
+
const typing = isEditing(event.target);
|
|
38
|
+
if (event.repeat && (key === 'Enter' || (!typing && /^[ 1-9]$/.test(key)))) return 'swallow';
|
|
39
|
+
if (event.ctrlKey || event.metaKey) return key === 'Enter' ? 'confirm' : undefined;
|
|
40
|
+
switch (key) {
|
|
41
|
+
case 'ArrowUp':
|
|
42
|
+
return 'previous';
|
|
43
|
+
case 'ArrowDown':
|
|
44
|
+
return 'next';
|
|
45
|
+
case 'Home':
|
|
46
|
+
return typing ? undefined : 'first';
|
|
47
|
+
case 'End':
|
|
48
|
+
return typing ? undefined : 'last';
|
|
49
|
+
case 'Escape': {
|
|
50
|
+
if (event.repeat) return 'swallow';
|
|
51
|
+
const draft = typing ? (event.target as { value?: string }).value : undefined;
|
|
52
|
+
return draft ? 'leaveField' : 'dismiss';
|
|
53
|
+
}
|
|
54
|
+
default:
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** How a host moves the keyboard into the card. */
|
|
60
|
+
export interface QuestionCardHandle {
|
|
61
|
+
/** Focus the picked answer, or the first. `false` where there is no keyboard focus to move. */
|
|
62
|
+
focus: () => boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface QuestionKeyboardOptions {
|
|
66
|
+
/** The `testID` given to the `Questionnaire`, whose rows and buttons are found by it. */
|
|
67
|
+
testID: string;
|
|
68
|
+
/** Take the focus when the card appears and nothing else holds it. */
|
|
69
|
+
autoFocus: boolean;
|
|
70
|
+
onDismiss?: () => void;
|
|
71
|
+
/** The card is about to go and it was the keyboard that sent it away. */
|
|
72
|
+
onReturnFocus?: () => void;
|
|
73
|
+
ref?: Ref<QuestionCardHandle>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
interface QuestionKeyboard {
|
|
77
|
+
/** For the view around the card: where its keys are heard. */
|
|
78
|
+
rootRef: RefObject<ComponentRef<typeof View> | null>;
|
|
79
|
+
/** Call before the card goes: gives the focus back if the keyboard is what is leaving it. */
|
|
80
|
+
leave: () => void;
|
|
81
|
+
/** Hand the focus back as `leave` does, then dismiss. */
|
|
82
|
+
dismiss: () => void;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const isWeb = () => Platform.OS === 'web';
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The question card's keyboard, on web (elsewhere the platform's own focus handling stands): the
|
|
89
|
+
* arrows, Home and End move between the answers, ⌘/Ctrl+Enter goes on, Escape puts the card away as
|
|
90
|
+
* its dismiss button does, and a keyboard answer hands the focus back to the composer.
|
|
91
|
+
*/
|
|
92
|
+
export function useQuestionKeyboard({
|
|
93
|
+
testID,
|
|
94
|
+
autoFocus,
|
|
95
|
+
onDismiss,
|
|
96
|
+
onReturnFocus,
|
|
97
|
+
ref,
|
|
98
|
+
}: QuestionKeyboardOptions): QuestionKeyboard {
|
|
99
|
+
const rootRef = useRef<ComponentRef<typeof View>>(null);
|
|
100
|
+
/** Whether the last thing done in the card was a key: a tap must not raise a phone's keyboard. */
|
|
101
|
+
const byKeyboard = useRef(false);
|
|
102
|
+
const latest = useRef({ onDismiss, onReturnFocus });
|
|
103
|
+
latest.current = { onDismiss, onReturnFocus };
|
|
104
|
+
|
|
105
|
+
const root = useCallback(
|
|
106
|
+
() => (isWeb() ? (rootRef.current as unknown as HTMLElement | null) : null),
|
|
107
|
+
[],
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
/** The answers of the question on screen, in order, the free-text field last. */
|
|
111
|
+
const answers = useCallback(
|
|
112
|
+
() =>
|
|
113
|
+
Array.from(
|
|
114
|
+
root()?.querySelectorAll<HTMLElement>(
|
|
115
|
+
`[data-testid^="${testID}-option-"], [data-testid="${testID}-other-input"]`,
|
|
116
|
+
) ?? [],
|
|
117
|
+
),
|
|
118
|
+
[root, testID],
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const focus = useCallback(() => {
|
|
122
|
+
const all = answers();
|
|
123
|
+
const picked = all.find(
|
|
124
|
+
(el) =>
|
|
125
|
+
el.getAttribute('aria-pressed') === 'true' || el.getAttribute('aria-checked') === 'true',
|
|
126
|
+
);
|
|
127
|
+
const target = picked ?? all[0];
|
|
128
|
+
// The card is docked in view; moving into it must not scroll the page under it.
|
|
129
|
+
target?.focus({ preventScroll: true });
|
|
130
|
+
return target !== undefined;
|
|
131
|
+
}, [answers]);
|
|
132
|
+
|
|
133
|
+
const leave = useCallback(() => {
|
|
134
|
+
const node = root();
|
|
135
|
+
if (!byKeyboard.current || !node?.contains(document.activeElement)) return;
|
|
136
|
+
latest.current.onReturnFocus?.();
|
|
137
|
+
}, [root]);
|
|
138
|
+
|
|
139
|
+
const dismiss = useCallback(() => {
|
|
140
|
+
leave();
|
|
141
|
+
latest.current.onDismiss?.();
|
|
142
|
+
}, [leave]);
|
|
143
|
+
|
|
144
|
+
useImperativeHandle(ref, () => ({ focus }), [focus]);
|
|
145
|
+
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
if (!autoFocus || !root()) return;
|
|
148
|
+
const active = document.activeElement;
|
|
149
|
+
if (active === null || active === document.body) focus();
|
|
150
|
+
}, [autoFocus, root, focus]);
|
|
151
|
+
|
|
152
|
+
useEffect(() => {
|
|
153
|
+
const node = root();
|
|
154
|
+
if (!node) return;
|
|
155
|
+
const move = (to: (index: number, count: number) => number) => {
|
|
156
|
+
const all = answers();
|
|
157
|
+
if (all.length === 0) return;
|
|
158
|
+
const index = all.indexOf(document.activeElement as HTMLElement);
|
|
159
|
+
all[(to(index, all.length) + all.length) % all.length]?.focus();
|
|
160
|
+
};
|
|
161
|
+
const run: Record<QuestionKeyCommand, () => void> = {
|
|
162
|
+
previous: () => move((index, count) => (index < 0 ? count - 1 : index - 1)),
|
|
163
|
+
next: () => move((index) => index + 1),
|
|
164
|
+
first: () => move(() => 0),
|
|
165
|
+
last: () => move((_, count) => count - 1),
|
|
166
|
+
confirm: () => node.querySelector<HTMLElement>(`[data-testid="${testID}-next"]`)?.click(),
|
|
167
|
+
dismiss,
|
|
168
|
+
leaveField: () => void focus(),
|
|
169
|
+
swallow: () => {},
|
|
170
|
+
};
|
|
171
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
172
|
+
byKeyboard.current = true;
|
|
173
|
+
const command = questionKey(event);
|
|
174
|
+
if (command === undefined || (command === 'dismiss' && !latest.current.onDismiss)) return;
|
|
175
|
+
// Heard on the way down and stopped here: the focused row would take ⌘Enter as a press, and
|
|
176
|
+
// whatever is open under the card would take its Escape.
|
|
177
|
+
event.preventDefault();
|
|
178
|
+
event.stopPropagation();
|
|
179
|
+
run[command]();
|
|
180
|
+
};
|
|
181
|
+
const onPointerDown = () => {
|
|
182
|
+
byKeyboard.current = false;
|
|
183
|
+
};
|
|
184
|
+
node.addEventListener('keydown', onKeyDown, true);
|
|
185
|
+
node.addEventListener('pointerdown', onPointerDown, true);
|
|
186
|
+
return () => {
|
|
187
|
+
node.removeEventListener('keydown', onKeyDown, true);
|
|
188
|
+
node.removeEventListener('pointerdown', onPointerDown, true);
|
|
189
|
+
};
|
|
190
|
+
}, [root, answers, focus, dismiss, testID]);
|
|
191
|
+
|
|
192
|
+
return { rootRef, leave, dismiss };
|
|
193
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { AiChatThreadHandle } from '@oxy.so/bloom/ai-chat';
|
|
2
|
+
import { type ComponentRef, type RefObject, useCallback, useLayoutEffect, useRef } from 'react';
|
|
3
|
+
import type { View } from 'react-native';
|
|
4
|
+
import type { ThreadJumpTarget } from './useThreadNavigation';
|
|
5
|
+
import { nextFrame } from './useTimelineWindow';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A mounted view: a row of the thread, or the list that holds them. An interface rather than an
|
|
9
|
+
* alias, so a declaration that returns one can name it (see `TextInputHandle`).
|
|
10
|
+
*/
|
|
11
|
+
export interface RowView extends ComponentRef<typeof View> {}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The room the find bar takes at the top of the thread, px: its card at its tallest, with the
|
|
15
|
+
* line about unloaded history. The thread keeps that much clear while it marks a match.
|
|
16
|
+
*/
|
|
17
|
+
export const FIND_BAR_CLEARANCE = 104;
|
|
18
|
+
|
|
19
|
+
interface Options {
|
|
20
|
+
/** The row asked for, if any. A new `request` asks again. */
|
|
21
|
+
target: ThreadJumpTarget | null | undefined;
|
|
22
|
+
/** Every row's id, in reading order. */
|
|
23
|
+
ids: readonly string[];
|
|
24
|
+
/** Mount the row at this index (`useTimelineWindow.reveal`). */
|
|
25
|
+
reveal: (index: number) => void;
|
|
26
|
+
threadRef: RefObject<AiChatThreadHandle | null>;
|
|
27
|
+
/** Room to leave above the row, px: what floats over the top of the thread. */
|
|
28
|
+
clearance: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Bring a row into view.
|
|
33
|
+
*
|
|
34
|
+
* Bloom's thread scrolls to an offset, not to an index, so the row is first mounted (it may be
|
|
35
|
+
* above the window) and then measured against the list. It is measured when the jump is made
|
|
36
|
+
* rather than remembered from its layout: a row's position changes whenever anything above it
|
|
37
|
+
* does, and on web no layout event says so.
|
|
38
|
+
*/
|
|
39
|
+
export function useRowJump({ target, ids, reveal, threadRef, clearance }: Options) {
|
|
40
|
+
const rows = useRef(new Map<string, RowView>());
|
|
41
|
+
const listRef = useRef<RowView | null>(null);
|
|
42
|
+
const waiting = useRef<string | null>(null);
|
|
43
|
+
const latest = useRef({ ids, reveal });
|
|
44
|
+
useLayoutEffect(() => {
|
|
45
|
+
latest.current = { ids, reveal };
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const registerRow = useCallback((id: string, node: RowView | null) => {
|
|
49
|
+
if (node === null) rows.current.delete(id);
|
|
50
|
+
else rows.current.set(id, node);
|
|
51
|
+
}, []);
|
|
52
|
+
|
|
53
|
+
const request = target?.request;
|
|
54
|
+
const targetId = target?.id;
|
|
55
|
+
useLayoutEffect(() => {
|
|
56
|
+
if (request === undefined || targetId === undefined) return;
|
|
57
|
+
const index = latest.current.ids.indexOf(targetId);
|
|
58
|
+
if (index === -1) return;
|
|
59
|
+
waiting.current = targetId;
|
|
60
|
+
latest.current.reveal(index);
|
|
61
|
+
}, [request, targetId]);
|
|
62
|
+
|
|
63
|
+
// After every commit, because the row asked for may mount a render after it was asked for.
|
|
64
|
+
useLayoutEffect(() => {
|
|
65
|
+
const id = waiting.current;
|
|
66
|
+
const row = id === null ? undefined : rows.current.get(id);
|
|
67
|
+
const list = listRef.current;
|
|
68
|
+
if (row === undefined || list === null) return;
|
|
69
|
+
waiting.current = null;
|
|
70
|
+
// A frame later, once the rows revealed with it have laid out.
|
|
71
|
+
nextFrame(() => {
|
|
72
|
+
row.measureLayout(list, (_x, y) => {
|
|
73
|
+
threadRef.current?.scrollToOffset({ offset: Math.max(0, y - clearance) });
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return { listRef, registerRow };
|
|
79
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { findMatches, stepMatch, threadTurns } from '../runtime/thread/thread-find';
|
|
3
|
+
import type { Message } from '../runtime/types';
|
|
4
|
+
|
|
5
|
+
/** Ask the thread to bring a row into view. `request` tells two asks for the same row apart. */
|
|
6
|
+
export interface ThreadJumpTarget {
|
|
7
|
+
id: string;
|
|
8
|
+
request: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface NavigationState {
|
|
12
|
+
panel: 'find' | 'turns' | null;
|
|
13
|
+
query: string;
|
|
14
|
+
/** The match the reader is on, by message id: ids survive the rows changing around it. */
|
|
15
|
+
activeId: string | null;
|
|
16
|
+
jump: ThreadJumpTarget | null;
|
|
17
|
+
/** Bumped each time find is asked for, so an open bar takes the caret back. */
|
|
18
|
+
focusRequest: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const CLOSED: NavigationState = {
|
|
22
|
+
panel: null,
|
|
23
|
+
query: '',
|
|
24
|
+
activeId: null,
|
|
25
|
+
jump: null,
|
|
26
|
+
focusRequest: 0,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const NOTHING: readonly string[] = [];
|
|
30
|
+
|
|
31
|
+
const jumpTo = (current: NavigationState, id: string): ThreadJumpTarget => ({
|
|
32
|
+
id,
|
|
33
|
+
request: (current.jump?.request ?? 0) + 1,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Moving around a long thread: the find bar's query and current match, the list of turns, and the
|
|
38
|
+
* row either of them asks the thread to show.
|
|
39
|
+
*
|
|
40
|
+
* Matches are numbered in reading order and a search starts on the newest, which is where the
|
|
41
|
+
* reader already is. Only something the person does moves the thread: a reply streaming in can
|
|
42
|
+
* add a match, and never scrolls to it.
|
|
43
|
+
*/
|
|
44
|
+
export function useThreadNavigation(rows: readonly Message[], conversationId: string | undefined) {
|
|
45
|
+
const [state, setState] = useState<NavigationState & { owner: string | undefined }>({
|
|
46
|
+
...CLOSED,
|
|
47
|
+
owner: conversationId,
|
|
48
|
+
});
|
|
49
|
+
// Another conversation has other words: nothing found or listed carries over.
|
|
50
|
+
if (state.owner !== conversationId) setState({ ...CLOSED, owner: conversationId });
|
|
51
|
+
|
|
52
|
+
// Read through a ref by the actions, which must not change identity per streamed token.
|
|
53
|
+
const latestRows = useRef(rows);
|
|
54
|
+
latestRows.current = rows;
|
|
55
|
+
|
|
56
|
+
const finding = state.panel === 'find';
|
|
57
|
+
const matches = useMemo(
|
|
58
|
+
() => (finding ? findMatches(rows, state.query) : NOTHING),
|
|
59
|
+
[finding, rows, state.query],
|
|
60
|
+
);
|
|
61
|
+
const found = state.activeId === null ? -1 : matches.indexOf(state.activeId);
|
|
62
|
+
// A match that is gone (the reply was edited or regenerated) hands over to the newest.
|
|
63
|
+
const current = found === -1 ? matches.length - 1 : found;
|
|
64
|
+
|
|
65
|
+
const turns = useMemo(
|
|
66
|
+
() => (state.panel === 'turns' ? threadTurns(rows) : []),
|
|
67
|
+
[state.panel, rows],
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const openFind = useCallback(() => {
|
|
71
|
+
setState((s) => ({
|
|
72
|
+
...(s.panel === 'find' ? s : { ...CLOSED, owner: s.owner, jump: s.jump }),
|
|
73
|
+
panel: 'find',
|
|
74
|
+
focusRequest: s.focusRequest + 1,
|
|
75
|
+
}));
|
|
76
|
+
}, []);
|
|
77
|
+
const openTurns = useCallback(() => {
|
|
78
|
+
setState((s) => ({ ...CLOSED, owner: s.owner, jump: s.jump, panel: 'turns' }));
|
|
79
|
+
}, []);
|
|
80
|
+
const close = useCallback(() => {
|
|
81
|
+
setState((s) =>
|
|
82
|
+
s.panel === null ? s : { ...CLOSED, owner: s.owner, jump: s.jump, panel: null },
|
|
83
|
+
);
|
|
84
|
+
}, []);
|
|
85
|
+
|
|
86
|
+
const setQuery = useCallback((query: string) => {
|
|
87
|
+
const newest = findMatches(latestRows.current, query).at(-1) ?? null;
|
|
88
|
+
setState((s) => ({
|
|
89
|
+
...s,
|
|
90
|
+
query,
|
|
91
|
+
activeId: newest,
|
|
92
|
+
jump: newest === null ? s.jump : jumpTo(s, newest),
|
|
93
|
+
}));
|
|
94
|
+
}, []);
|
|
95
|
+
|
|
96
|
+
const step = useCallback((delta: 1 | -1) => {
|
|
97
|
+
setState((s) => {
|
|
98
|
+
const ids = findMatches(latestRows.current, s.query);
|
|
99
|
+
const at = s.activeId === null ? -1 : ids.indexOf(s.activeId);
|
|
100
|
+
const next = ids[stepMatch(at === -1 ? ids.length - 1 : at, delta, ids.length)];
|
|
101
|
+
return next === undefined ? s : { ...s, activeId: next, jump: jumpTo(s, next) };
|
|
102
|
+
});
|
|
103
|
+
}, []);
|
|
104
|
+
const older = useCallback(() => step(-1), [step]);
|
|
105
|
+
const newer = useCallback(() => step(1), [step]);
|
|
106
|
+
|
|
107
|
+
/** Land on a turn from the list, and close the list over it. */
|
|
108
|
+
const jumpToTurn = useCallback((id: string) => {
|
|
109
|
+
setState((s) => ({ ...CLOSED, owner: s.owner, panel: null, jump: jumpTo(s, id) }));
|
|
110
|
+
}, []);
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
panel: state.panel,
|
|
114
|
+
query: state.query,
|
|
115
|
+
/** How many loaded messages hold the query. */
|
|
116
|
+
total: matches.length,
|
|
117
|
+
/** The current match's position, counted from 0 in reading order; -1 with none. */
|
|
118
|
+
current,
|
|
119
|
+
/** The message the thread marks: the current match, while find is open. */
|
|
120
|
+
highlightedId: matches[current] ?? null,
|
|
121
|
+
jump: state.jump,
|
|
122
|
+
focusRequest: state.focusRequest,
|
|
123
|
+
turns,
|
|
124
|
+
openFind,
|
|
125
|
+
openTurns,
|
|
126
|
+
close,
|
|
127
|
+
setQuery,
|
|
128
|
+
older,
|
|
129
|
+
newer,
|
|
130
|
+
jumpToTurn,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export type ThreadNavigation = ReturnType<typeof useThreadNavigation>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type Message,
|
|
3
3
|
TAIL,
|
|
4
|
+
FOCUS_MARGIN,
|
|
4
5
|
TOP,
|
|
5
6
|
type TimelineAnchor,
|
|
6
7
|
type TimelinePosition,
|
|
@@ -79,7 +80,7 @@ function awaitingRows(pending: { current: PendingScroll | null }, ids: readonly
|
|
|
79
80
|
/** The state before the first key: nothing mounted yet, so nothing to remember. */
|
|
80
81
|
const MOUNTING = Symbol('mounting');
|
|
81
82
|
|
|
82
|
-
const nextFrame = (run: () => void): void => {
|
|
83
|
+
export const nextFrame = (run: () => void): void => {
|
|
83
84
|
if (typeof requestAnimationFrame === 'function') requestAnimationFrame(run);
|
|
84
85
|
else setTimeout(run, 0);
|
|
85
86
|
};
|
|
@@ -205,6 +206,21 @@ export function useTimelineWindow({
|
|
|
205
206
|
loadHistory?.();
|
|
206
207
|
}, [setAnchor]);
|
|
207
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Mount the row at `index` for a jump to it, with a few rows above, and keep it mounted. A
|
|
211
|
+
* scroll still waiting (a restore) gives way to it.
|
|
212
|
+
*/
|
|
213
|
+
const reveal = useCallback(
|
|
214
|
+
(index: number) => {
|
|
215
|
+
pending.current = null;
|
|
216
|
+
atBottom.current = false;
|
|
217
|
+
const { ids: rows, start: first } = latest.current;
|
|
218
|
+
const wanted = Math.max(0, index - FOCUS_MARGIN);
|
|
219
|
+
if (wanted < first) setAnchor(pinAnchor(rows, wanted));
|
|
220
|
+
},
|
|
221
|
+
[setAnchor],
|
|
222
|
+
);
|
|
223
|
+
|
|
208
224
|
const handleScroll = useCallback(
|
|
209
225
|
(event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
210
226
|
const { contentOffset, contentSize, layoutMeasurement } = event.nativeEvent;
|
|
@@ -248,6 +264,7 @@ export function useTimelineWindow({
|
|
|
248
264
|
return {
|
|
249
265
|
/** Index of the first mounted row. */
|
|
250
266
|
start,
|
|
267
|
+
reveal,
|
|
251
268
|
/** For `AiChatThread`: absent when there is nothing above to reveal or load. */
|
|
252
269
|
onStartReached: start > 0 || onLoadHistory !== undefined ? handleStartReached : undefined,
|
|
253
270
|
onScroll: handleScroll,
|
package/src/index.ts
CHANGED
|
@@ -82,6 +82,7 @@ export type { DeviceModel } from './lib/power-level-options';
|
|
|
82
82
|
export { GemieWelcomeMessage } from './components/GemieWelcomeMessage';
|
|
83
83
|
export { PlanPreviewCard } from './components/PlanPreviewCard';
|
|
84
84
|
export { AskedQuestions, QuestionCard } from './components/QuestionCard';
|
|
85
|
+
export type { QuestionCardHandle } from './hooks/useQuestionKeyboard';
|
|
85
86
|
export { GemieComposer } from './components/GemieComposer';
|
|
86
87
|
export type {
|
|
87
88
|
GemieComposerProps,
|
package/src/lib/copy-en.ts
CHANGED
|
@@ -112,6 +112,14 @@ export const COPY_EN: Readonly<Record<string, CopyEntry>> = {
|
|
|
112
112
|
'chat.fileChanges.unified': 'Unified',
|
|
113
113
|
'chat.fileChanges.unrecorded': 'The agent did not record what changed in this file',
|
|
114
114
|
'chat.fileChanges.wrap': 'Wrap lines',
|
|
115
|
+
'chat.find.count': '{{current}} of {{total}}',
|
|
116
|
+
'chat.find.loadedOnly': 'Only the messages loaded here are searched.',
|
|
117
|
+
'chat.find.newer': 'Next match',
|
|
118
|
+
'chat.find.none': 'No matches',
|
|
119
|
+
'chat.find.older': 'Previous match',
|
|
120
|
+
'chat.find.placeholder': 'Find in conversation',
|
|
121
|
+
'chat.followUp.queued': 'Waiting to send your message…',
|
|
122
|
+
'chat.followUp.steering': 'Sending your reply to {{agent}}…',
|
|
115
123
|
'chat.like': 'Like',
|
|
116
124
|
'chat.actionApproval.send': 'Send',
|
|
117
125
|
'chat.actionApproval.approve': 'Approve',
|
|
@@ -190,6 +198,9 @@ export const COPY_EN: Readonly<Record<string, CopyEntry>> = {
|
|
|
190
198
|
'chat.turnFailed': "Alia couldn't answer right now.",
|
|
191
199
|
'chat.turnFailedRetryHint': 'Try again.',
|
|
192
200
|
'chat.turnInterrupted': 'Alia was interrupted before finishing.',
|
|
201
|
+
'chat.turns.attachment': 'Attachment',
|
|
202
|
+
'chat.turns.loadEarlier': 'Load earlier messages',
|
|
203
|
+
'chat.turns.title': 'Jump to a turn',
|
|
193
204
|
'chat.working': 'Working',
|
|
194
205
|
'chat.yesterday': 'Yesterday',
|
|
195
206
|
'common.close': 'Close',
|
|
@@ -417,6 +428,11 @@ export const COPY_EN: Readonly<Record<string, CopyEntry>> = {
|
|
|
417
428
|
'panels.form.enter': 'Enter {{field}}',
|
|
418
429
|
'panels.form.select': 'Select…',
|
|
419
430
|
'panels.form.submit': 'Submit',
|
|
431
|
+
'planCard.collapse': 'Collapse plan',
|
|
432
|
+
'planCard.copy': 'Copy plan',
|
|
433
|
+
'planCard.download': 'Download plan as Markdown',
|
|
434
|
+
'planCard.downloadFailed': "Couldn't download the plan",
|
|
435
|
+
'planCard.expand': 'Expand plan',
|
|
420
436
|
'powerLevels.auto.description': 'Picks the right level for each message',
|
|
421
437
|
'powerLevels.auto.label': 'Auto',
|
|
422
438
|
'powerLevels.high.description': 'Thinks harder on tougher questions',
|
package/src/lib/copy-es.ts
CHANGED
|
@@ -111,6 +111,14 @@ export const COPY_ES: Readonly<Record<string, CopyEntry>> = {
|
|
|
111
111
|
'chat.fileChanges.unified': 'Unificada',
|
|
112
112
|
'chat.fileChanges.unrecorded': 'El agente no registró qué cambió en este archivo',
|
|
113
113
|
'chat.fileChanges.wrap': 'Ajustar líneas',
|
|
114
|
+
'chat.find.count': '{{current}} de {{total}}',
|
|
115
|
+
'chat.find.loadedOnly': 'Solo se busca en los mensajes cargados aquí.',
|
|
116
|
+
'chat.find.newer': 'Coincidencia siguiente',
|
|
117
|
+
'chat.find.none': 'Sin coincidencias',
|
|
118
|
+
'chat.find.older': 'Coincidencia anterior',
|
|
119
|
+
'chat.find.placeholder': 'Buscar en la conversación',
|
|
120
|
+
'chat.followUp.queued': 'Esperando para enviar tu mensaje…',
|
|
121
|
+
'chat.followUp.steering': 'Enviando tu respuesta a {{agent}}…',
|
|
114
122
|
'chat.like': 'Me gusta',
|
|
115
123
|
'chat.actionApproval.send': 'Enviar',
|
|
116
124
|
'chat.actionApproval.approve': 'Aprobar',
|
|
@@ -189,6 +197,9 @@ export const COPY_ES: Readonly<Record<string, CopyEntry>> = {
|
|
|
189
197
|
'chat.turnFailed': 'Alia no ha podido responder ahora mismo.',
|
|
190
198
|
'chat.turnFailedRetryHint': 'Inténtalo de nuevo.',
|
|
191
199
|
'chat.turnInterrupted': 'Alia se interrumpió antes de terminar.',
|
|
200
|
+
'chat.turns.attachment': 'Adjunto',
|
|
201
|
+
'chat.turns.loadEarlier': 'Cargar mensajes anteriores',
|
|
202
|
+
'chat.turns.title': 'Ir a un turno',
|
|
192
203
|
'chat.working': 'Trabajando',
|
|
193
204
|
'chat.yesterday': 'Ayer',
|
|
194
205
|
'common.close': 'Cerrar',
|
|
@@ -422,6 +433,11 @@ export const COPY_ES: Readonly<Record<string, CopyEntry>> = {
|
|
|
422
433
|
'panels.form.enter': 'Escribe {{field}}',
|
|
423
434
|
'panels.form.select': 'Selecciona…',
|
|
424
435
|
'panels.form.submit': 'Enviar',
|
|
436
|
+
'planCard.collapse': 'Contraer el plan',
|
|
437
|
+
'planCard.copy': 'Copiar el plan',
|
|
438
|
+
'planCard.download': 'Descargar el plan en Markdown',
|
|
439
|
+
'planCard.downloadFailed': 'No se pudo descargar el plan',
|
|
440
|
+
'planCard.expand': 'Desplegar el plan',
|
|
425
441
|
'powerLevels.auto.description': 'Elige el nivel adecuado para cada mensaje',
|
|
426
442
|
'powerLevels.auto.label': 'Auto',
|
|
427
443
|
'powerLevels.high.description': 'Piensa más en las preguntas difíciles',
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Markdown file writer on web, imported statically: an `import()` here would be an async chunk
|
|
3
|
+
* boundary inside the SDK (see `./image-data-url.web.ts`). Native keeps the lazy load.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import * as MarkdownFile from '../markdown-file';
|
|
7
|
+
|
|
8
|
+
export const loadMarkdownFile = async () => MarkdownFile;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { File, Paths } from 'expo-file-system';
|
|
2
|
+
import { Platform, Share } from 'react-native';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Hand a Markdown document to the person, however this platform does that.
|
|
6
|
+
*
|
|
7
|
+
* On web that is a download: a `Blob` behind a temporary object URL, clicked
|
|
8
|
+
* through an anchor that names the file. The URL is revoked once the click
|
|
9
|
+
* has been dispatched — synchronously would race the browser reading it.
|
|
10
|
+
*
|
|
11
|
+
* On a phone the document is written to the CACHE directory (the system may
|
|
12
|
+
* reclaim it, which is right for a file whose only purpose is to be handed
|
|
13
|
+
* on) and offered through React Native's own share sheet: iOS's sheet takes a
|
|
14
|
+
* file `url` and shares the `.md` itself, while Android's `Share.share` accepts
|
|
15
|
+
* only `message`, so there the sheet carries the document's text.
|
|
16
|
+
*/
|
|
17
|
+
export async function deliverMarkdownFile(
|
|
18
|
+
filename: string,
|
|
19
|
+
content: string,
|
|
20
|
+
title: string,
|
|
21
|
+
): Promise<void> {
|
|
22
|
+
if (Platform.OS === 'web') {
|
|
23
|
+
const blob = new Blob([content], { type: 'text/markdown;charset=utf-8' });
|
|
24
|
+
const url = URL.createObjectURL(blob);
|
|
25
|
+
const anchor = document.createElement('a');
|
|
26
|
+
anchor.href = url;
|
|
27
|
+
anchor.download = filename;
|
|
28
|
+
anchor.rel = 'noopener';
|
|
29
|
+
document.body.appendChild(anchor);
|
|
30
|
+
anchor.click();
|
|
31
|
+
anchor.remove();
|
|
32
|
+
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const file = new File(Paths.cache, filename);
|
|
37
|
+
await file.write(content);
|
|
38
|
+
await Share.share(Platform.OS === 'ios' ? { url: file.uri, title } : { message: content, title });
|
|
39
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PlanStep } from '../types';
|
|
2
|
+
|
|
3
|
+
/** Continuation lines belong to the list item they follow, so they are indented under it. */
|
|
4
|
+
const indented = (text: string) =>
|
|
5
|
+
text
|
|
6
|
+
.split('\n')
|
|
7
|
+
.map((line) => line.trim())
|
|
8
|
+
.filter(Boolean)
|
|
9
|
+
.join('\n ');
|
|
10
|
+
|
|
11
|
+
/** A plan as a Markdown document: its title, then the steps as a numbered list. */
|
|
12
|
+
export function planMarkdown(title: string, steps: readonly PlanStep[]): string {
|
|
13
|
+
const items = steps.map((step, index) => {
|
|
14
|
+
const action = `${index + 1}. ${indented(step.action)}`;
|
|
15
|
+
const description = indented(step.description ?? '');
|
|
16
|
+
return description ? `${action}\n ${description}` : action;
|
|
17
|
+
});
|
|
18
|
+
return `# ${title}\n\n${items.join('\n')}\n`;
|
|
19
|
+
}
|
package/src/runtime/index.ts
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { loadMarkdownFile } from '../lib/deferred/markdown-file';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Hand a Markdown document to the person as a file: a download on web, the share sheet on a phone
|
|
5
|
+
* (`lib/markdown-file.ts`). A conversation's export and a plan's download both go through here.
|
|
6
|
+
*/
|
|
7
|
+
export async function deliverMarkdownFile(
|
|
8
|
+
filename: string,
|
|
9
|
+
content: string,
|
|
10
|
+
title: string,
|
|
11
|
+
): Promise<void> {
|
|
12
|
+
const { deliverMarkdownFile: deliver } = await loadMarkdownFile();
|
|
13
|
+
await deliver(filename, content, title);
|
|
14
|
+
}
|
|
@@ -7,7 +7,7 @@ import { extractSources } from './thought-utils';
|
|
|
7
7
|
* Pure, and deliberately so: the header's menu item is the only thing that
|
|
8
8
|
* asks for this, and what it hands over is the same `messages` array the
|
|
9
9
|
* screen is streaming into. Everything about DELIVERY — a download on web, the
|
|
10
|
-
* share sheet on a phone — lives in `
|
|
10
|
+
* share sheet on a phone — lives in `lib/markdown-file.ts`, so this module can
|
|
11
11
|
* be tested against a string and nothing else.
|
|
12
12
|
*
|
|
13
13
|
* ## What is kept and what is left out
|