@gemies/sdk 10.3.0 → 10.5.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 +60 -0
- package/package.json +1 -1
- package/src/components/ApprovalBar.tsx +131 -0
- package/src/components/GemieChatContent.tsx +54 -20
- package/src/components/GemieComposer.tsx +7 -0
- package/src/components/thread/AgentWork.tsx +262 -0
- package/src/components/thread/ApprovalCard.tsx +73 -71
- package/src/components/thread/CommandOutput.tsx +106 -0
- package/src/components/thread/GemieThread.tsx +4 -3
- package/src/components/thread/ThreadRow.tsx +21 -1
- package/src/hooks/useApprovalShortcuts.ts +93 -0
- package/src/lib/copy-en.ts +31 -4
- package/src/lib/copy-es.ts +31 -4
- package/src/realtime/contract.ts +18 -1
- package/src/realtime/react.tsx +8 -5
- package/src/runtime/approvals.ts +150 -13
- package/src/runtime/config.tsx +16 -4
- package/src/runtime/index.ts +9 -1
- package/src/runtime/model.ts +2 -0
- package/src/runtime/thread/agent-work.ts +192 -0
- package/src/runtime/thread/command-output.ts +51 -0
- package/src/runtime/use-approval-actions.ts +162 -0
- package/src/runtime/use-conversation-stream.ts +21 -7
- package/src/runtime/use-step-output.ts +42 -0
|
@@ -1,111 +1,79 @@
|
|
|
1
|
+
import { Button } from '@oxy.so/bloom/button';
|
|
1
2
|
import { Notification } from '@oxy.so/bloom/notification';
|
|
2
3
|
import { Muted } from '@oxy.so/bloom/typography';
|
|
3
|
-
import React
|
|
4
|
+
import React from 'react';
|
|
4
5
|
import { StyleSheet, View } from 'react-native';
|
|
5
6
|
import { useLabels } from '../../lib/labels';
|
|
6
7
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
approvalOptionLabel,
|
|
9
|
+
orderedApprovalOptions,
|
|
9
10
|
type ApprovalEntry,
|
|
10
|
-
type
|
|
11
|
+
type ApprovalGrant,
|
|
11
12
|
} from '../../runtime/approvals';
|
|
12
|
-
|
|
13
|
-
export interface ApprovalsProps {
|
|
14
|
-
readonly entries: readonly ApprovalEntry[];
|
|
15
|
-
/** Who is asking: the agent's name, as the thread names it. */
|
|
16
|
-
readonly agentName: string;
|
|
17
|
-
/**
|
|
18
|
-
* Carries the person's answer to Gemies. Rejects with `ApprovalExpiredError` when the question is
|
|
19
|
-
* no longer open. Omitted, a question is shown with no way to answer it.
|
|
20
|
-
*/
|
|
21
|
-
readonly onDecide?: (entry: ApprovalEntry, decision: ApprovalDecision) => Promise<void>;
|
|
22
|
-
/** The answer is known here (the person's own, or the question closed): show it now. */
|
|
23
|
-
readonly onSettled: (requestId: string, outcome: ApprovalOutcome) => void;
|
|
24
|
-
}
|
|
13
|
+
import type { ApprovalActions } from '../../runtime/use-approval-actions';
|
|
25
14
|
|
|
26
15
|
/**
|
|
27
16
|
* A coding CLI asking its own user for permission to run something on their computer, in the
|
|
28
|
-
* conversation (Gemies ADR 0043 §5): who is asking, what for, and the
|
|
29
|
-
* for the person; once answered the card shrinks to one line saying how it ended.
|
|
17
|
+
* conversation (Gemies ADR 0043 §5): who is asking, what for, and the answers it offers. The CLI
|
|
18
|
+
* waits for the person; once answered the card shrinks to one line saying how it ended.
|
|
30
19
|
*
|
|
31
|
-
* This is the CLI's prompt to the person who runs it, not a permission Gemies or Oxy asks for.
|
|
20
|
+
* This is the CLI's prompt to the person who runs it, not a permission Gemies or Oxy asks for. The
|
|
21
|
+
* composer shows the same question in a compact bar; both answer through the same actions, so a
|
|
22
|
+
* question answered in one is answered in both.
|
|
32
23
|
*/
|
|
33
24
|
export const ApprovalCards = React.memo(function ApprovalCards({
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}: ApprovalsProps) {
|
|
25
|
+
approvals,
|
|
26
|
+
}: {
|
|
27
|
+
approvals: ApprovalActions;
|
|
28
|
+
}) {
|
|
39
29
|
return (
|
|
40
30
|
<>
|
|
41
|
-
{entries.map((entry) => (
|
|
42
|
-
<ApprovalCard
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
onDecide={onDecide}
|
|
47
|
-
onSettled={onSettled}
|
|
48
|
-
/>
|
|
31
|
+
{approvals.entries.map((entry) => (
|
|
32
|
+
<ApprovalCard key={entry.requestId} entry={entry} approvals={approvals} />
|
|
33
|
+
))}
|
|
34
|
+
{approvals.grants.map((grant) => (
|
|
35
|
+
<ApprovalGrantRow key={grant.id} grant={grant} approvals={approvals} />
|
|
49
36
|
))}
|
|
50
37
|
</>
|
|
51
38
|
);
|
|
52
39
|
});
|
|
53
40
|
|
|
54
|
-
function ApprovalCard({
|
|
55
|
-
entry,
|
|
56
|
-
agentName,
|
|
57
|
-
onDecide,
|
|
58
|
-
onSettled,
|
|
59
|
-
}: {
|
|
60
|
-
entry: ApprovalEntry;
|
|
61
|
-
agentName: string;
|
|
62
|
-
onDecide: ApprovalsProps['onDecide'];
|
|
63
|
-
onSettled: ApprovalsProps['onSettled'];
|
|
64
|
-
}) {
|
|
41
|
+
function ApprovalCard({ entry, approvals }: { entry: ApprovalEntry; approvals: ApprovalActions }) {
|
|
65
42
|
const { t } = useLabels();
|
|
66
|
-
const [sending, setSending] = useState(false);
|
|
67
|
-
const [failed, setFailed] = useState(false);
|
|
68
|
-
|
|
69
|
-
const decide = useCallback(
|
|
70
|
-
(decision: ApprovalDecision) => {
|
|
71
|
-
if (sending || !onDecide) return;
|
|
72
|
-
setSending(true);
|
|
73
|
-
setFailed(false);
|
|
74
|
-
onDecide(entry, decision).then(
|
|
75
|
-
() => onSettled(entry.requestId, decision),
|
|
76
|
-
(error: unknown) => {
|
|
77
|
-
setSending(false);
|
|
78
|
-
if (error instanceof ApprovalExpiredError) onSettled(entry.requestId, 'expired');
|
|
79
|
-
else setFailed(true);
|
|
80
|
-
},
|
|
81
|
-
);
|
|
82
|
-
},
|
|
83
|
-
[sending, onDecide, entry, onSettled],
|
|
84
|
-
);
|
|
85
43
|
|
|
86
44
|
if (entry.outcome !== 'pending') {
|
|
45
|
+
const line = t(
|
|
46
|
+
entry.auto ? 'chat.approval.resolved.auto' : `chat.approval.resolved.${entry.outcome}`,
|
|
47
|
+
{ tool: entry.tool },
|
|
48
|
+
);
|
|
87
49
|
return (
|
|
88
50
|
<View style={styles.resolved} accessibilityRole="text">
|
|
89
|
-
<Muted>{
|
|
51
|
+
<Muted>{entry.feedback ? `${line} · “${entry.feedback}”` : line}</Muted>
|
|
90
52
|
</View>
|
|
91
53
|
);
|
|
92
54
|
}
|
|
93
55
|
|
|
94
|
-
const description = [
|
|
56
|
+
const description = [
|
|
57
|
+
entry.summary,
|
|
58
|
+
approvals.failed.has(entry.requestId) ? t('chat.approval.sendFailed') : undefined,
|
|
59
|
+
]
|
|
95
60
|
.filter(Boolean)
|
|
96
61
|
.join('\n');
|
|
62
|
+
const sending = approvals.sending.has(entry.requestId);
|
|
97
63
|
return (
|
|
98
64
|
<Notification
|
|
99
65
|
status="warning"
|
|
100
|
-
title={t('chat.approval.title', { agent: agentName, tool: entry.tool })}
|
|
66
|
+
title={t('chat.approval.title', { agent: approvals.agentName, tool: entry.tool })}
|
|
101
67
|
description={description === '' ? undefined : description}
|
|
102
68
|
// While an answer is on its way there is nothing to press: a second tap must not send another.
|
|
103
69
|
actions={
|
|
104
|
-
|
|
105
|
-
?
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
70
|
+
approvals.canAnswer && !sending
|
|
71
|
+
? orderedApprovalOptions(entry.options).map((option) => ({
|
|
72
|
+
label: approvalOptionLabel(option, t),
|
|
73
|
+
onPress: () => void approvals.decide(entry, option.kind, { optionId: option.id }),
|
|
74
|
+
...(option.kind === 'allow' ? {} : { appearance: 'subtle' as const }),
|
|
75
|
+
...(option.kind === 'cancel' ? { tone: 'danger' as const } : {}),
|
|
76
|
+
}))
|
|
109
77
|
: undefined
|
|
110
78
|
}
|
|
111
79
|
dismissible={false}
|
|
@@ -113,6 +81,40 @@ function ApprovalCard({
|
|
|
113
81
|
);
|
|
114
82
|
}
|
|
115
83
|
|
|
84
|
+
/** What the person allowed for the session, with the way to take it back. */
|
|
85
|
+
function ApprovalGrantRow({
|
|
86
|
+
grant,
|
|
87
|
+
approvals,
|
|
88
|
+
}: {
|
|
89
|
+
grant: ApprovalGrant;
|
|
90
|
+
approvals: ApprovalActions;
|
|
91
|
+
}) {
|
|
92
|
+
const { t } = useLabels();
|
|
93
|
+
return (
|
|
94
|
+
<View style={styles.grant}>
|
|
95
|
+
<Muted style={styles.grantText} numberOfLines={1}>
|
|
96
|
+
{`${t('chat.approval.grant', { tool: grant.tool })}: ${grant.target}`}
|
|
97
|
+
</Muted>
|
|
98
|
+
<Button
|
|
99
|
+
size="xs"
|
|
100
|
+
appearance="plain"
|
|
101
|
+
tone="neutral"
|
|
102
|
+
onPress={() => void approvals.revokeGrant(grant.id)}
|
|
103
|
+
>
|
|
104
|
+
{t('chat.approval.revoke')}
|
|
105
|
+
</Button>
|
|
106
|
+
</View>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
116
110
|
const styles = StyleSheet.create({
|
|
117
111
|
resolved: { paddingHorizontal: 16, paddingVertical: 4 },
|
|
112
|
+
grant: {
|
|
113
|
+
flexDirection: 'row',
|
|
114
|
+
alignItems: 'center',
|
|
115
|
+
gap: 8,
|
|
116
|
+
paddingHorizontal: 16,
|
|
117
|
+
paddingVertical: 2,
|
|
118
|
+
},
|
|
119
|
+
grantText: { flexShrink: 1 },
|
|
118
120
|
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Button } from '@oxy.so/bloom/button';
|
|
2
|
+
import { Pre } from '@oxy.so/bloom/code';
|
|
3
|
+
import { Muted } from '@oxy.so/bloom/typography';
|
|
4
|
+
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
5
|
+
import {
|
|
6
|
+
type NativeScrollEvent,
|
|
7
|
+
type NativeSyntheticEvent,
|
|
8
|
+
ScrollView,
|
|
9
|
+
type ScrollViewInstance,
|
|
10
|
+
StyleSheet,
|
|
11
|
+
View,
|
|
12
|
+
} from 'react-native';
|
|
13
|
+
import { copyText } from '../../lib/clipboard';
|
|
14
|
+
import { useLabels } from '../../lib/labels';
|
|
15
|
+
import { displayOutput } from '../../runtime/thread/command-output';
|
|
16
|
+
import type { StepOutput } from '../../runtime/thread/agent-work';
|
|
17
|
+
|
|
18
|
+
/** How far from the end still counts as following it. */
|
|
19
|
+
const FOLLOW_SLACK_PX = 24;
|
|
20
|
+
const MAX_HEIGHT = 240;
|
|
21
|
+
|
|
22
|
+
export interface CommandOutputProps {
|
|
23
|
+
/** What the command printed, as far as known; `null` before anything arrived. */
|
|
24
|
+
output: StepOutput | null;
|
|
25
|
+
/** The command is still running: more may come. */
|
|
26
|
+
running: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* What one command printed: monospace, escapes removed, the tail of it, with Copy.
|
|
31
|
+
*
|
|
32
|
+
* It follows the end while the reader is at the end: output that arrives scrolls in. Scroll up to
|
|
33
|
+
* read something and it stops following and offers "Jump to latest", so reading is never fought
|
|
34
|
+
* by the next line. Output cut to its tail says so above it.
|
|
35
|
+
*
|
|
36
|
+
* It draws what it is given and knows nothing of how it arrives: the step mounts it when opened
|
|
37
|
+
* and hands it the live output (`useStepOutput`) or what was stored.
|
|
38
|
+
*/
|
|
39
|
+
export function CommandOutput({ output, running }: CommandOutputProps) {
|
|
40
|
+
const { t } = useLabels();
|
|
41
|
+
const scroll = useRef<ScrollViewInstance>(null);
|
|
42
|
+
const following = useRef(true);
|
|
43
|
+
const [away, setAway] = useState(false);
|
|
44
|
+
const raw = output?.text ?? '';
|
|
45
|
+
const text = useMemo(() => displayOutput(raw), [raw]);
|
|
46
|
+
|
|
47
|
+
const onScroll = useCallback((event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
48
|
+
const { contentOffset, contentSize, layoutMeasurement } = event.nativeEvent;
|
|
49
|
+
const atEnd =
|
|
50
|
+
contentSize.height - (contentOffset.y + layoutMeasurement.height) <= FOLLOW_SLACK_PX;
|
|
51
|
+
following.current = atEnd;
|
|
52
|
+
setAway(!atEnd);
|
|
53
|
+
}, []);
|
|
54
|
+
|
|
55
|
+
const onContentSizeChange = useCallback(() => {
|
|
56
|
+
if (following.current) scroll.current?.scrollToEnd({ animated: false });
|
|
57
|
+
}, []);
|
|
58
|
+
|
|
59
|
+
const jumpToLatest = useCallback(() => {
|
|
60
|
+
following.current = true;
|
|
61
|
+
setAway(false);
|
|
62
|
+
scroll.current?.scrollToEnd({ animated: true });
|
|
63
|
+
}, []);
|
|
64
|
+
|
|
65
|
+
if (text === '') {
|
|
66
|
+
return <Muted>{running ? t('work.waitingOutput') : t('work.noOutput')}</Muted>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<View style={styles.root}>
|
|
71
|
+
<View style={styles.header}>
|
|
72
|
+
{output?.truncated ? <Muted>{t('work.outputTruncated')}</Muted> : <View />}
|
|
73
|
+
<Button appearance="plain" tone="neutral" size="xs" onPress={() => void copyText(text, t)}>
|
|
74
|
+
{t('work.copy')}
|
|
75
|
+
</Button>
|
|
76
|
+
</View>
|
|
77
|
+
<View>
|
|
78
|
+
<ScrollView
|
|
79
|
+
ref={scroll}
|
|
80
|
+
style={styles.scroll}
|
|
81
|
+
nestedScrollEnabled
|
|
82
|
+
scrollEventThrottle={32}
|
|
83
|
+
onScroll={onScroll}
|
|
84
|
+
onContentSizeChange={onContentSizeChange}
|
|
85
|
+
testID="command-output-scroll"
|
|
86
|
+
>
|
|
87
|
+
<Pre selectable>{text}</Pre>
|
|
88
|
+
</ScrollView>
|
|
89
|
+
{away ? (
|
|
90
|
+
<View style={styles.jump}>
|
|
91
|
+
<Button appearance="outline" tone="neutral" size="xs" onPress={jumpToLatest}>
|
|
92
|
+
{t('work.jumpToLatest')}
|
|
93
|
+
</Button>
|
|
94
|
+
</View>
|
|
95
|
+
) : null}
|
|
96
|
+
</View>
|
|
97
|
+
</View>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const styles = StyleSheet.create({
|
|
102
|
+
root: { gap: 4 },
|
|
103
|
+
header: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' },
|
|
104
|
+
scroll: { maxHeight: MAX_HEIGHT },
|
|
105
|
+
jump: { position: 'absolute', right: 8, bottom: 8 },
|
|
106
|
+
});
|
|
@@ -36,7 +36,8 @@ import type { ThreadHistory } from '../../runtime/thread/thread-history';
|
|
|
36
36
|
import type { AgentState } from '../../types';
|
|
37
37
|
import { AgentResultCard } from './AgentResultCard';
|
|
38
38
|
import { AgentTaskCard } from './AgentTaskCard';
|
|
39
|
-
import
|
|
39
|
+
import type { ApprovalActions } from '../../runtime/use-approval-actions';
|
|
40
|
+
import { ApprovalCards } from './ApprovalCard';
|
|
40
41
|
import { NewConversationOffer } from './NewConversationOffer';
|
|
41
42
|
import { type ThreadActions, ThreadRow } from './ThreadRow';
|
|
42
43
|
|
|
@@ -90,7 +91,7 @@ export interface GemieThreadProps {
|
|
|
90
91
|
* A coding CLI asking its own user for permission to run something on their computer, while the
|
|
91
92
|
* turn waits (ADR 0043 §5). Drawn after the turns, where the person is looking.
|
|
92
93
|
*/
|
|
93
|
-
approvals?:
|
|
94
|
+
approvals?: ApprovalActions;
|
|
94
95
|
actionApprovals?: ConversationActionApprovals;
|
|
95
96
|
/** The run an agent is on for this conversation: in progress, or the card it leaves. */
|
|
96
97
|
agentActivity?: AgentActivityState | null;
|
|
@@ -404,7 +405,7 @@ export const GemieThread = memo(function GemieThread({
|
|
|
404
405
|
) : null}
|
|
405
406
|
|
|
406
407
|
{approvals === undefined || approvals.entries.length === 0 ? null : (
|
|
407
|
-
<ApprovalCards {
|
|
408
|
+
<ApprovalCards approvals={approvals} />
|
|
408
409
|
)}
|
|
409
410
|
|
|
410
411
|
{/* The agent's offer to start the next stretch fresh. Last in the list on purpose: it
|
|
@@ -36,9 +36,11 @@ import { isWebInvocation, taskListLog, webSearchLog } from '../../lib/work-log';
|
|
|
36
36
|
import { useGemieRuntime } from '../../runtime/config';
|
|
37
37
|
import {
|
|
38
38
|
type Message,
|
|
39
|
+
buildAgentWork,
|
|
39
40
|
cardOf,
|
|
40
41
|
formatElapsed,
|
|
41
42
|
getToolPillLabel,
|
|
43
|
+
isExternalStep,
|
|
42
44
|
turnFileChanges,
|
|
43
45
|
} from '../../runtime/model';
|
|
44
46
|
import type { OpenThought } from '../../hooks/useOpenThought';
|
|
@@ -46,6 +48,7 @@ import { PlanPreviewCard } from '../PlanPreviewCard';
|
|
|
46
48
|
import { AskedQuestions } from '../QuestionCard';
|
|
47
49
|
import { CanvasComponent } from '../canvas/CanvasComponent';
|
|
48
50
|
import { ReplyMarkdown } from '../ReplyMarkdown';
|
|
51
|
+
import { AgentWork } from './AgentWork';
|
|
49
52
|
import { MessageBlockBoundary } from './MessageBlockBoundary';
|
|
50
53
|
import { FileChangesCard } from '../diff/FileChangesCard';
|
|
51
54
|
import { ToolResultCard } from './ToolResultCard';
|
|
@@ -219,6 +222,7 @@ export const ThreadRow = memo(function ThreadRow({
|
|
|
219
222
|
isLastReply={isLastReply}
|
|
220
223
|
isLoading={isLoading}
|
|
221
224
|
storedIn={storedIn}
|
|
225
|
+
conversationId={conversationId}
|
|
222
226
|
actions={actions}
|
|
223
227
|
copyAction={copyAction}
|
|
224
228
|
readAloudState={readAloudState}
|
|
@@ -238,6 +242,8 @@ interface ReplyTurnProps {
|
|
|
238
242
|
isLastReply: boolean;
|
|
239
243
|
isLoading: boolean;
|
|
240
244
|
storedIn: string | undefined;
|
|
245
|
+
/** The conversation the turn is in, saved or not: a running step's output is followed under it. */
|
|
246
|
+
conversationId: string | undefined;
|
|
241
247
|
actions: ThreadActions;
|
|
242
248
|
copyAction: AiChatTurnAction | null;
|
|
243
249
|
readAloudState: ReadAloudState;
|
|
@@ -254,6 +260,7 @@ function ReplyTurn({
|
|
|
254
260
|
isLastReply,
|
|
255
261
|
isLoading,
|
|
256
262
|
storedIn,
|
|
263
|
+
conversationId,
|
|
257
264
|
actions,
|
|
258
265
|
copyAction,
|
|
259
266
|
readAloudState,
|
|
@@ -321,8 +328,13 @@ function ReplyTurn({
|
|
|
321
328
|
|
|
322
329
|
// The calls the work summary lists: every one that did not draw its own card. Read on each
|
|
323
330
|
// render — the list changes per streamed tool event and the row is memoised on `message`.
|
|
331
|
+
// An external agent's steps are not in it: they are their own work log, whatever draws the turn.
|
|
324
332
|
const workInvocations = toolInvocations.filter(
|
|
325
|
-
(call) =>
|
|
333
|
+
(call) =>
|
|
334
|
+
cardOf(call) === null &&
|
|
335
|
+
!isQuestionInvocation(call) &&
|
|
336
|
+
!renderedCalls.has(call) &&
|
|
337
|
+
!isExternalStep(call),
|
|
326
338
|
);
|
|
327
339
|
const questions = toolInvocations.flatMap((call) => askedQuestions(call) ?? []);
|
|
328
340
|
const toolCards = toolInvocations.flatMap((call, index) => {
|
|
@@ -334,6 +346,8 @@ function ReplyTurn({
|
|
|
334
346
|
const fileChanges = turnFileChanges(toolInvocations);
|
|
335
347
|
/** The template swaps the steps for the reply once the turn is done. */
|
|
336
348
|
const turnWorking = isLoading && isLastReply && message.isStreaming === true;
|
|
349
|
+
// What a coding agent on the person's computer did: one row, whoever's turn it is.
|
|
350
|
+
const agentWork = buildAgentWork(toolInvocations, turnWorking);
|
|
337
351
|
|
|
338
352
|
// Where the turn went — searches, page visits, research — as a `WebSearch` trail with its
|
|
339
353
|
// sources, and everything else it did as a `TaskList`. Both are driven by `revealed` from the
|
|
@@ -426,6 +440,7 @@ function ReplyTurn({
|
|
|
426
440
|
agent !== undefined ||
|
|
427
441
|
text.length > 0 ||
|
|
428
442
|
hasWorkLog ||
|
|
443
|
+
agentWork !== null ||
|
|
429
444
|
toolCards.length > 0 ||
|
|
430
445
|
fileChanges.length > 0 ||
|
|
431
446
|
rendered.length > 0 ||
|
|
@@ -535,6 +550,11 @@ function ReplyTurn({
|
|
|
535
550
|
onPress={viewDetails}
|
|
536
551
|
/>
|
|
537
552
|
)}
|
|
553
|
+
{agentWork === null ? null : (
|
|
554
|
+
<MessageBlockBoundary>
|
|
555
|
+
<AgentWork work={agentWork} conversationId={conversationId} />
|
|
556
|
+
</MessageBlockBoundary>
|
|
557
|
+
)}
|
|
538
558
|
{taskLog === null ? null : (
|
|
539
559
|
<TaskList
|
|
540
560
|
tasks={taskLog.tasks}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
|
+
|
|
4
|
+
/** What a shortcut does; each is absent when the question does not offer it. */
|
|
5
|
+
export interface ApprovalShortcutActions {
|
|
6
|
+
readonly approve?: () => void;
|
|
7
|
+
readonly approveForSession?: () => void;
|
|
8
|
+
readonly decline?: () => void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** The key that does each thing, so the buttons can name it. */
|
|
12
|
+
export const APPROVAL_SHORTCUT_KEYS = {
|
|
13
|
+
approve: 'Y',
|
|
14
|
+
approveForSession: 'A',
|
|
15
|
+
decline: 'N',
|
|
16
|
+
} as const;
|
|
17
|
+
|
|
18
|
+
/** The part of a key event the shortcuts read. */
|
|
19
|
+
export interface ShortcutKeyEvent {
|
|
20
|
+
readonly key: string;
|
|
21
|
+
readonly ctrlKey?: boolean;
|
|
22
|
+
readonly metaKey?: boolean;
|
|
23
|
+
readonly altKey?: boolean;
|
|
24
|
+
readonly shiftKey?: boolean;
|
|
25
|
+
readonly isComposing?: boolean;
|
|
26
|
+
/** The key is being held down. */
|
|
27
|
+
readonly repeat?: boolean;
|
|
28
|
+
readonly defaultPrevented?: boolean;
|
|
29
|
+
readonly target?: unknown;
|
|
30
|
+
preventDefault?: () => void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Whether keys typed here are text: a field, or anything the person can edit. */
|
|
34
|
+
function isEditing(target: unknown): boolean {
|
|
35
|
+
const el = target as { tagName?: string; isContentEditable?: boolean } | null;
|
|
36
|
+
if (el === null || typeof el !== 'object') return false;
|
|
37
|
+
const tag = el.tagName?.toLowerCase();
|
|
38
|
+
return tag === 'input' || tag === 'textarea' || tag === 'select' || el.isContentEditable === true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* What a key does to the question: `Y` approves it once, `A` allows it for the session, `N`
|
|
43
|
+
* declines it. Only a bare key pressed once counts — a held key must not answer the next question
|
|
44
|
+
* too — and not while the person is typing: the composer is where they write the reply that
|
|
45
|
+
* declines with feedback, and its letters are theirs. `Escape` is left alone: it closes whatever
|
|
46
|
+
* is open over the chat, and closing something must not decline a request.
|
|
47
|
+
*/
|
|
48
|
+
export function approvalShortcut(
|
|
49
|
+
event: ShortcutKeyEvent,
|
|
50
|
+
actions: ApprovalShortcutActions,
|
|
51
|
+
): (() => void) | undefined {
|
|
52
|
+
if (event.defaultPrevented || event.isComposing || event.repeat) return undefined;
|
|
53
|
+
if (event.ctrlKey || event.metaKey || event.altKey || event.shiftKey) return undefined;
|
|
54
|
+
if (isEditing(event.target)) return undefined;
|
|
55
|
+
switch (event.key) {
|
|
56
|
+
case 'y':
|
|
57
|
+
case 'Y':
|
|
58
|
+
return actions.approve;
|
|
59
|
+
case 'a':
|
|
60
|
+
case 'A':
|
|
61
|
+
return actions.approveForSession;
|
|
62
|
+
case 'n':
|
|
63
|
+
case 'N':
|
|
64
|
+
return actions.decline;
|
|
65
|
+
default:
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The keyboard shortcuts of the question the composer's bar shows, on web (there is no keyboard to
|
|
72
|
+
* speak of elsewhere). `target` is where keys are heard: the document, unless a test brings its own.
|
|
73
|
+
*/
|
|
74
|
+
export function useApprovalShortcuts(
|
|
75
|
+
actions: ApprovalShortcutActions | undefined,
|
|
76
|
+
target:
|
|
77
|
+
| Pick<EventTarget, 'addEventListener' | 'removeEventListener'>
|
|
78
|
+
| undefined = Platform.OS === 'web'
|
|
79
|
+
? (globalThis as { document?: Document }).document
|
|
80
|
+
: undefined,
|
|
81
|
+
): void {
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (actions === undefined || target === undefined) return;
|
|
84
|
+
const onKeyDown = (event: Event) => {
|
|
85
|
+
const run = approvalShortcut(event as unknown as ShortcutKeyEvent, actions);
|
|
86
|
+
if (run === undefined) return;
|
|
87
|
+
(event as unknown as ShortcutKeyEvent).preventDefault?.();
|
|
88
|
+
run();
|
|
89
|
+
};
|
|
90
|
+
target.addEventListener('keydown', onKeyDown);
|
|
91
|
+
return () => target.removeEventListener('keydown', onKeyDown);
|
|
92
|
+
}, [actions, target]);
|
|
93
|
+
}
|
package/src/lib/copy-en.ts
CHANGED
|
@@ -125,11 +125,23 @@ export const COPY_EN: Readonly<Record<string, CopyEntry>> = {
|
|
|
125
125
|
'chat.actionApproval.status.expired': 'Expired',
|
|
126
126
|
'chat.actionApproval.sent': 'Sent',
|
|
127
127
|
'chat.actionApproval.decisionFailed': 'Your decision couldn’t be saved. Try again.',
|
|
128
|
-
'chat.approval.
|
|
129
|
-
'chat.approval.
|
|
130
|
-
'chat.approval.
|
|
131
|
-
'chat.approval.
|
|
128
|
+
'chat.approval.bar.more': '%{count} more waiting',
|
|
129
|
+
'chat.approval.bar.replyHint': 'Reply below to decline and tell %{agent} why.',
|
|
130
|
+
'chat.approval.bar.title': '%{agent} is waiting to run %{tool}',
|
|
131
|
+
'chat.approval.grant': 'Allowed for this session — %{tool}',
|
|
132
|
+
'chat.approval.option.allow': 'Approve',
|
|
133
|
+
'chat.approval.option.allow_session': 'Always allow this session',
|
|
134
|
+
'chat.approval.option.cancel': 'Stop',
|
|
135
|
+
'chat.approval.option.deny': 'Decline',
|
|
136
|
+
'chat.approval.replyPlaceholder': 'Decline and tell %{agent} why…',
|
|
137
|
+
'chat.approval.resolved.allow': '%{tool}: approved',
|
|
138
|
+
'chat.approval.resolved.allow_session': '%{tool}: allowed for this session',
|
|
139
|
+
'chat.approval.resolved.auto': '%{tool}: allowed, as you did for this session',
|
|
140
|
+
'chat.approval.resolved.cancel': '%{tool}: stopped',
|
|
141
|
+
'chat.approval.resolved.deny': '%{tool}: declined',
|
|
142
|
+
'chat.approval.resolved.ended': '%{tool}: closed with the turn',
|
|
132
143
|
'chat.approval.resolved.expired': '%{tool}: timed out',
|
|
144
|
+
'chat.approval.revoke': 'Revoke',
|
|
133
145
|
'chat.approval.sendFailed': "Your answer couldn't be sent. Try again.",
|
|
134
146
|
'chat.approval.title': '%{agent} wants to run %{tool}',
|
|
135
147
|
'chat.newConversationAccept': 'Start a new one',
|
|
@@ -518,4 +530,19 @@ export const COPY_EN: Readonly<Record<string, CopyEntry>> = {
|
|
|
518
530
|
'weather.condition.snow-showers': 'Snow showers',
|
|
519
531
|
'weather.condition.thunderstorm': 'Thunderstorm',
|
|
520
532
|
'weather.toggleUnit': 'Switch temperature unit',
|
|
533
|
+
'work.copy': 'Copy output',
|
|
534
|
+
'work.declined': 'Declined',
|
|
535
|
+
'work.exitCode': 'Exit code {{code}}',
|
|
536
|
+
'work.failed': 'Failed',
|
|
537
|
+
'work.failedCount': { one: '1 failed', other: '{{count}} failed' },
|
|
538
|
+
'work.interrupted': 'Stopped',
|
|
539
|
+
'work.jumpToLatest': 'Jump to latest',
|
|
540
|
+
'work.noOutput': 'No output',
|
|
541
|
+
'work.outputTruncated': 'Earlier output not shown',
|
|
542
|
+
'work.steps': { one: '1 step', other: '{{count}} steps' },
|
|
543
|
+
'work.waitingOutput': 'No output yet',
|
|
544
|
+
'work.worked': 'Worked · {{steps}}',
|
|
545
|
+
'work.workedFor': 'Worked for {{elapsed}} · {{steps}}',
|
|
546
|
+
'work.working': 'Working · {{steps}}',
|
|
547
|
+
'work.workingFor': 'Working for {{elapsed}} · {{steps}}',
|
|
521
548
|
};
|
package/src/lib/copy-es.ts
CHANGED
|
@@ -124,11 +124,23 @@ export const COPY_ES: Readonly<Record<string, CopyEntry>> = {
|
|
|
124
124
|
'chat.actionApproval.status.expired': 'Caducado',
|
|
125
125
|
'chat.actionApproval.sent': 'Enviado',
|
|
126
126
|
'chat.actionApproval.decisionFailed': 'Tu decisión no se pudo guardar. Inténtalo de nuevo.',
|
|
127
|
-
'chat.approval.
|
|
128
|
-
'chat.approval.
|
|
129
|
-
'chat.approval.
|
|
130
|
-
'chat.approval.
|
|
127
|
+
'chat.approval.bar.more': '%{count} más esperando',
|
|
128
|
+
'chat.approval.bar.replyHint': 'Responde abajo para rechazar y decirle a %{agent} por qué.',
|
|
129
|
+
'chat.approval.bar.title': '%{agent} espera para ejecutar %{tool}',
|
|
130
|
+
'chat.approval.grant': 'Permitido en esta sesión — %{tool}',
|
|
131
|
+
'chat.approval.option.allow': 'Aprobar',
|
|
132
|
+
'chat.approval.option.allow_session': 'Permitir siempre en esta sesión',
|
|
133
|
+
'chat.approval.option.cancel': 'Detener',
|
|
134
|
+
'chat.approval.option.deny': 'Rechazar',
|
|
135
|
+
'chat.approval.replyPlaceholder': 'Rechaza y dile a %{agent} por qué…',
|
|
136
|
+
'chat.approval.resolved.allow': '%{tool}: aprobado',
|
|
137
|
+
'chat.approval.resolved.allow_session': '%{tool}: permitido en esta sesión',
|
|
138
|
+
'chat.approval.resolved.auto': '%{tool}: permitido, como indicaste para esta sesión',
|
|
139
|
+
'chat.approval.resolved.cancel': '%{tool}: detenido',
|
|
140
|
+
'chat.approval.resolved.deny': '%{tool}: rechazado',
|
|
141
|
+
'chat.approval.resolved.ended': '%{tool}: cerrado con el turno',
|
|
131
142
|
'chat.approval.resolved.expired': '%{tool}: sin respuesta a tiempo',
|
|
143
|
+
'chat.approval.revoke': 'Revocar',
|
|
132
144
|
'chat.approval.sendFailed': 'No se pudo enviar tu respuesta. Inténtalo de nuevo.',
|
|
133
145
|
'chat.approval.title': '%{agent} quiere ejecutar %{tool}',
|
|
134
146
|
'chat.newConversationAccept': 'Empezar una nueva',
|
|
@@ -523,4 +535,19 @@ export const COPY_ES: Readonly<Record<string, CopyEntry>> = {
|
|
|
523
535
|
'weather.condition.snow-showers': 'Chubascos de nieve',
|
|
524
536
|
'weather.condition.thunderstorm': 'Tormenta',
|
|
525
537
|
'weather.toggleUnit': 'Cambiar unidad de temperatura',
|
|
538
|
+
'work.copy': 'Copiar salida',
|
|
539
|
+
'work.declined': 'Rechazado',
|
|
540
|
+
'work.exitCode': 'Código de salida {{code}}',
|
|
541
|
+
'work.failed': 'Falló',
|
|
542
|
+
'work.failedCount': { one: '1 con error', other: '{{count}} con error' },
|
|
543
|
+
'work.interrupted': 'Detenido',
|
|
544
|
+
'work.jumpToLatest': 'Ir a lo último',
|
|
545
|
+
'work.noOutput': 'Sin salida',
|
|
546
|
+
'work.outputTruncated': 'No se muestra la salida anterior',
|
|
547
|
+
'work.steps': { one: '1 paso', other: '{{count}} pasos' },
|
|
548
|
+
'work.waitingOutput': 'Aún sin salida',
|
|
549
|
+
'work.worked': 'Trabajó · {{steps}}',
|
|
550
|
+
'work.workedFor': 'Trabajó durante {{elapsed}} · {{steps}}',
|
|
551
|
+
'work.working': 'Trabajando · {{steps}}',
|
|
552
|
+
'work.workingFor': 'Trabajando durante {{elapsed}} · {{steps}}',
|
|
526
553
|
};
|
package/src/realtime/contract.ts
CHANGED
|
@@ -12,11 +12,16 @@ import type { Message } from '../runtime/types';
|
|
|
12
12
|
export const REALTIME_EVENT = 'rt';
|
|
13
13
|
/** Client → server: catch up from a cursor. */
|
|
14
14
|
export const REALTIME_SYNC = 'rt:sync';
|
|
15
|
-
/** Client → server: follow a topic (`agent:<id>`, `agent-session:<id>`). */
|
|
15
|
+
/** Client → server: follow a topic (`agent:<id>`, `agent-session:<id>`, `step-output:<conversation>:<call>`). */
|
|
16
16
|
export const REALTIME_SUBSCRIBE = 'rt:subscribe';
|
|
17
17
|
/** Client → server: stop following a topic. */
|
|
18
18
|
export const REALTIME_UNSUBSCRIBE = 'rt:unsubscribe';
|
|
19
19
|
|
|
20
|
+
/** What a client names to follow one command step's output (the API's `stepOutputTopic`). */
|
|
21
|
+
export function stepOutputTopic(conversationId: string, toolCallId: string): string {
|
|
22
|
+
return `step-output:${conversationId}:${toolCallId}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
20
25
|
/** Durable: numbered per account, replayed to a client that reconnects. */
|
|
21
26
|
export const REALTIME_DURABLE_TYPES = [
|
|
22
27
|
'conversation',
|
|
@@ -36,6 +41,7 @@ export const REALTIME_SIGNAL_TYPES = [
|
|
|
36
41
|
'presence',
|
|
37
42
|
'runtimes',
|
|
38
43
|
'agent.activity',
|
|
44
|
+
'step.output',
|
|
39
45
|
] as const;
|
|
40
46
|
|
|
41
47
|
export type RealtimeDurableType = (typeof REALTIME_DURABLE_TYPES)[number];
|
|
@@ -150,6 +156,17 @@ export interface RealtimeData {
|
|
|
150
156
|
readonly sessionId: string;
|
|
151
157
|
readonly agentId: string;
|
|
152
158
|
};
|
|
159
|
+
/**
|
|
160
|
+
* What a command step has printed, on `step-output:<conversation>:<call>`: the TAIL of its
|
|
161
|
+
* output so far, whole (a late follower is right again on the next frame), never a diff.
|
|
162
|
+
*/
|
|
163
|
+
'step.output': {
|
|
164
|
+
readonly conversationId: string;
|
|
165
|
+
readonly toolCallId: string;
|
|
166
|
+
readonly text: string;
|
|
167
|
+
/** Output before `text` was dropped. */
|
|
168
|
+
readonly truncated: boolean;
|
|
169
|
+
};
|
|
153
170
|
}
|
|
154
171
|
|
|
155
172
|
const TYPES: ReadonlySet<string> = new Set<string>([
|