@gemies/sdk 10.1.0 → 10.3.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 +39 -0
- package/package.json +1 -1
- package/src/components/GemieChatContent.tsx +23 -6
- package/src/components/diff/FileChangeSection.tsx +172 -0
- package/src/components/diff/FileChangesCard.tsx +51 -0
- package/src/components/diff/FileChangesViewer.tsx +135 -0
- package/src/components/diff/PatchLines.tsx +119 -0
- package/src/components/diff/diff-renderer.ts +38 -0
- package/src/components/thread/ActionApprovalCard.tsx +95 -0
- package/src/components/thread/GemieThread.tsx +17 -0
- package/src/components/thread/ThreadRow.tsx +16 -1
- package/src/index.ts +6 -0
- package/src/lib/copy-en.ts +40 -0
- package/src/lib/copy-es.ts +43 -0
- package/src/runtime/action-approvals.ts +127 -0
- package/src/runtime/config.tsx +16 -0
- package/src/runtime/index.ts +1 -0
- package/src/runtime/model.ts +1 -0
- package/src/runtime/resumable-stream.ts +306 -0
- package/src/runtime/routes.ts +19 -0
- package/src/runtime/sse-frame-reader.ts +20 -1
- package/src/runtime/stream-events.ts +68 -0
- package/src/runtime/thread/file-changes.ts +150 -0
- package/src/runtime/use-conversation-stream.ts +63 -30
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Badge } from '@oxy.so/bloom/badge';
|
|
2
|
+
import { Button } from '@oxy.so/bloom/button';
|
|
3
|
+
import { Card, CardBody } from '@oxy.so/bloom/card';
|
|
4
|
+
import { Muted, Text } from '@oxy.so/bloom/typography';
|
|
5
|
+
import { useRef, useState } from 'react';
|
|
6
|
+
import { StyleSheet, View } from 'react-native';
|
|
7
|
+
import { useLabels } from '../../lib/labels';
|
|
8
|
+
import type { ActionApproval, ConversationActionApprovals } from '../../runtime/action-approvals';
|
|
9
|
+
|
|
10
|
+
export function ActionApprovalCard({
|
|
11
|
+
entry,
|
|
12
|
+
decide,
|
|
13
|
+
}: {
|
|
14
|
+
entry: ActionApproval;
|
|
15
|
+
decide: ConversationActionApprovals['decide'];
|
|
16
|
+
}) {
|
|
17
|
+
const { t } = useLabels();
|
|
18
|
+
const inFlight = useRef(false);
|
|
19
|
+
const [sending, setSending] = useState(false);
|
|
20
|
+
const [error, setError] = useState(false);
|
|
21
|
+
const [decided, setDecided] = useState(false);
|
|
22
|
+
|
|
23
|
+
async function submit(decision: 'approve' | 'reject') {
|
|
24
|
+
if (inFlight.current || entry.status !== 'pending') return;
|
|
25
|
+
inFlight.current = true;
|
|
26
|
+
setSending(true);
|
|
27
|
+
setError(false);
|
|
28
|
+
try {
|
|
29
|
+
await decide(entry.id, decision);
|
|
30
|
+
setDecided(true);
|
|
31
|
+
} catch {
|
|
32
|
+
setError(true);
|
|
33
|
+
} finally {
|
|
34
|
+
inFlight.current = false;
|
|
35
|
+
setSending(false);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Card>
|
|
41
|
+
<CardBody>
|
|
42
|
+
<View style={styles.body}>
|
|
43
|
+
<View style={styles.header}>
|
|
44
|
+
<Text variant="title-1-medium">{entry.preview.title}</Text>
|
|
45
|
+
<Badge>
|
|
46
|
+
{t(
|
|
47
|
+
entry.status === 'executed' && entry.preview.action === 'send'
|
|
48
|
+
? 'chat.actionApproval.sent'
|
|
49
|
+
: `chat.actionApproval.status.${entry.status}`,
|
|
50
|
+
)}
|
|
51
|
+
</Badge>
|
|
52
|
+
</View>
|
|
53
|
+
{entry.preview.fields.map(({ name, label, value }) => (
|
|
54
|
+
<View key={name}>
|
|
55
|
+
<Muted>{label}</Muted>
|
|
56
|
+
<Text selectable>{value}</Text>
|
|
57
|
+
</View>
|
|
58
|
+
))}
|
|
59
|
+
{entry.status === 'pending' ? (
|
|
60
|
+
<View style={styles.buttons}>
|
|
61
|
+
<Button
|
|
62
|
+
appearance="outline"
|
|
63
|
+
tone="neutral"
|
|
64
|
+
size="sm"
|
|
65
|
+
disabled={sending || decided}
|
|
66
|
+
onPress={() => void submit('reject')}
|
|
67
|
+
>
|
|
68
|
+
{t('chat.actionApproval.reject')}
|
|
69
|
+
</Button>
|
|
70
|
+
<Button
|
|
71
|
+
size="sm"
|
|
72
|
+
disabled={sending || decided}
|
|
73
|
+
onPress={() => void submit('approve')}
|
|
74
|
+
>
|
|
75
|
+
{t(
|
|
76
|
+
entry.preview.action === 'send'
|
|
77
|
+
? 'chat.actionApproval.send'
|
|
78
|
+
: 'chat.actionApproval.approve',
|
|
79
|
+
)}
|
|
80
|
+
</Button>
|
|
81
|
+
</View>
|
|
82
|
+
) : null}
|
|
83
|
+
{error ? <Muted>{t('chat.actionApproval.decisionFailed')}</Muted> : null}
|
|
84
|
+
{entry.error ? <Muted>{entry.error}</Muted> : null}
|
|
85
|
+
</View>
|
|
86
|
+
</CardBody>
|
|
87
|
+
</Card>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const styles = StyleSheet.create({
|
|
92
|
+
body: { gap: 12 },
|
|
93
|
+
header: { flexDirection: 'row', flexWrap: 'wrap', alignItems: 'center', gap: 8 },
|
|
94
|
+
buttons: { flexDirection: 'row', gap: 8, justifyContent: 'flex-end' },
|
|
95
|
+
});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ConversationActionApprovals } from '../../runtime/action-approvals';
|
|
2
|
+
import { ActionApprovalCard } from './ActionApprovalCard';
|
|
1
3
|
import { AgentThinking } from '@oxy.so/bloom/agent-thinking';
|
|
2
4
|
import { AiChatThread, type AiChatThreadHandle } from '@oxy.so/bloom/ai-chat';
|
|
3
5
|
import { ChatDateHeader } from '@oxy.so/bloom/chat-screen';
|
|
@@ -89,6 +91,7 @@ export interface GemieThreadProps {
|
|
|
89
91
|
* turn waits (ADR 0043 §5). Drawn after the turns, where the person is looking.
|
|
90
92
|
*/
|
|
91
93
|
approvals?: ApprovalsProps;
|
|
94
|
+
actionApprovals?: ConversationActionApprovals;
|
|
92
95
|
/** The run an agent is on for this conversation: in progress, or the card it leaves. */
|
|
93
96
|
agentActivity?: AgentActivityState | null;
|
|
94
97
|
/**
|
|
@@ -145,6 +148,7 @@ export const GemieThread = memo(function GemieThread({
|
|
|
145
148
|
onStartEdit,
|
|
146
149
|
newConversationOffer,
|
|
147
150
|
approvals,
|
|
151
|
+
actionApprovals,
|
|
148
152
|
agentActivity,
|
|
149
153
|
call,
|
|
150
154
|
empty,
|
|
@@ -289,6 +293,15 @@ export const GemieThread = memo(function GemieThread({
|
|
|
289
293
|
);
|
|
290
294
|
}
|
|
291
295
|
|
|
296
|
+
const messageIds = new Set(rows.map((message) => message.id));
|
|
297
|
+
const renderApproval = (entry: ConversationActionApprovals['entries'][number]) =>
|
|
298
|
+
actionApprovals === undefined ? null : (
|
|
299
|
+
<ActionApprovalCard key={entry.id} entry={entry} decide={actionApprovals.decide} />
|
|
300
|
+
);
|
|
301
|
+
const detachedApprovals = actionApprovals?.entries.filter(
|
|
302
|
+
(entry) => entry.messageId === null || !messageIds.has(entry.messageId),
|
|
303
|
+
);
|
|
304
|
+
|
|
292
305
|
const renderRow = (message: Message, index: number) => {
|
|
293
306
|
const fromHistory = index < history.length;
|
|
294
307
|
const timing = timingOf(message.id);
|
|
@@ -321,6 +334,9 @@ export const GemieThread = memo(function GemieThread({
|
|
|
321
334
|
workStartedAt={timing.startedAt}
|
|
322
335
|
workEndedAt={timing.endedAt}
|
|
323
336
|
/>
|
|
337
|
+
{actionApprovals?.entries
|
|
338
|
+
.filter((entry) => entry.messageId === message.id)
|
|
339
|
+
.map(renderApproval)}
|
|
324
340
|
</Fragment>
|
|
325
341
|
);
|
|
326
342
|
};
|
|
@@ -374,6 +390,7 @@ export const GemieThread = memo(function GemieThread({
|
|
|
374
390
|
{rows
|
|
375
391
|
.slice(timeline.start)
|
|
376
392
|
.map((message, offset) => renderRow(message, timeline.start + offset))}
|
|
393
|
+
{detachedApprovals?.map(renderApproval)}
|
|
377
394
|
</View>
|
|
378
395
|
|
|
379
396
|
{/* Agent execution — in-progress card or completed result card. A run that failed has no
|
|
@@ -34,13 +34,20 @@ import { askedQuestions, isQuestionInvocation } from '../../lib/questions';
|
|
|
34
34
|
import { parseCatalogueTool, useToolRenderers } from '../../lib/tool-renderers';
|
|
35
35
|
import { isWebInvocation, taskListLog, webSearchLog } from '../../lib/work-log';
|
|
36
36
|
import { useGemieRuntime } from '../../runtime/config';
|
|
37
|
-
import {
|
|
37
|
+
import {
|
|
38
|
+
type Message,
|
|
39
|
+
cardOf,
|
|
40
|
+
formatElapsed,
|
|
41
|
+
getToolPillLabel,
|
|
42
|
+
turnFileChanges,
|
|
43
|
+
} from '../../runtime/model';
|
|
38
44
|
import type { OpenThought } from '../../hooks/useOpenThought';
|
|
39
45
|
import { PlanPreviewCard } from '../PlanPreviewCard';
|
|
40
46
|
import { AskedQuestions } from '../QuestionCard';
|
|
41
47
|
import { CanvasComponent } from '../canvas/CanvasComponent';
|
|
42
48
|
import { ReplyMarkdown } from '../ReplyMarkdown';
|
|
43
49
|
import { MessageBlockBoundary } from './MessageBlockBoundary';
|
|
50
|
+
import { FileChangesCard } from '../diff/FileChangesCard';
|
|
44
51
|
import { ToolResultCard } from './ToolResultCard';
|
|
45
52
|
import { ChatBubble } from './ChatBubble';
|
|
46
53
|
import { TurnMenu } from './TurnMenu';
|
|
@@ -323,6 +330,8 @@ function ReplyTurn({
|
|
|
323
330
|
const card = cardOf(call);
|
|
324
331
|
return card === null ? [] : [{ key: call.toolCallId || `tool-${message.id}-${index}`, card }];
|
|
325
332
|
});
|
|
333
|
+
// The files an external agent edited this turn, whose patches its edit calls carry.
|
|
334
|
+
const fileChanges = turnFileChanges(toolInvocations);
|
|
326
335
|
/** The template swaps the steps for the reply once the turn is done. */
|
|
327
336
|
const turnWorking = isLoading && isLastReply && message.isStreaming === true;
|
|
328
337
|
|
|
@@ -418,6 +427,7 @@ function ReplyTurn({
|
|
|
418
427
|
text.length > 0 ||
|
|
419
428
|
hasWorkLog ||
|
|
420
429
|
toolCards.length > 0 ||
|
|
430
|
+
fileChanges.length > 0 ||
|
|
421
431
|
rendered.length > 0 ||
|
|
422
432
|
gemieConversations.length > 0 ||
|
|
423
433
|
inlineCanvases.length > 0 ||
|
|
@@ -558,6 +568,11 @@ function ReplyTurn({
|
|
|
558
568
|
<ToolResultCard card={card} />
|
|
559
569
|
</MessageBlockBoundary>
|
|
560
570
|
))}
|
|
571
|
+
{fileChanges.length === 0 ? null : (
|
|
572
|
+
<MessageBlockBoundary>
|
|
573
|
+
<FileChangesCard changes={fileChanges} />
|
|
574
|
+
</MessageBlockBoundary>
|
|
575
|
+
)}
|
|
561
576
|
{gemieConversations.map(({ key, conversation }) => (
|
|
562
577
|
<MessageBlockBoundary key={key}>
|
|
563
578
|
<GemieConversationCard
|
package/src/index.ts
CHANGED
|
@@ -31,6 +31,12 @@ export { ANCHORS, leadToProfile } from './lib/flights';
|
|
|
31
31
|
export { parseCatalogueTool, toolRendererKey } from './lib/catalogue-tool';
|
|
32
32
|
export type { GemieToolRenderers, GemieToolResult } from './lib/tool-renderers';
|
|
33
33
|
export type { GemieChartCards } from './components/charts/chart-cards';
|
|
34
|
+
export type {
|
|
35
|
+
DiffLayout,
|
|
36
|
+
GemieFileDiffRenderer,
|
|
37
|
+
GemiePatchViewProps,
|
|
38
|
+
} from './components/diff/diff-renderer';
|
|
39
|
+
export { PatchLines } from './components/diff/PatchLines';
|
|
34
40
|
export { GemieAskProvider, useAskGemie } from './components/GemieAskProvider';
|
|
35
41
|
export type {
|
|
36
42
|
GemieAsk,
|
package/src/lib/copy-en.ts
CHANGED
|
@@ -84,7 +84,47 @@ export const COPY_EN: Readonly<Record<string, CopyEntry>> = {
|
|
|
84
84
|
'chat.dislike': 'Dislike',
|
|
85
85
|
'chat.edit': 'Edit',
|
|
86
86
|
'chat.feedbackFailed': "Your feedback couldn't be saved.",
|
|
87
|
+
'chat.fileChanges.binary': 'Binary file, no preview',
|
|
88
|
+
'chat.fileChanges.chip': { one: '1 file changed', other: '{{count}} files changed' },
|
|
89
|
+
'chat.fileChanges.collapseAll': 'Collapse all',
|
|
90
|
+
'chat.fileChanges.copyPath': 'Copy path',
|
|
91
|
+
'chat.fileChanges.expandAll': 'Expand all',
|
|
92
|
+
'chat.fileChanges.layout': 'Layout',
|
|
93
|
+
'chat.fileChanges.noContent': 'No changes to the contents',
|
|
94
|
+
'chat.fileChanges.open': {
|
|
95
|
+
one: 'Review 1 changed file, +{{additions}} −{{deletions}}',
|
|
96
|
+
other: 'Review {{count}} changed files, +{{additions}} −{{deletions}}',
|
|
97
|
+
},
|
|
98
|
+
'chat.fileChanges.operation.add': 'Added',
|
|
99
|
+
'chat.fileChanges.operation.delete': 'Deleted',
|
|
100
|
+
'chat.fileChanges.operation.rename': 'Renamed',
|
|
101
|
+
'chat.fileChanges.operation.update': 'Modified',
|
|
102
|
+
'chat.fileChanges.renamedFrom': 'Renamed from {{path}}',
|
|
103
|
+
'chat.fileChanges.showMore': { one: 'Show 1 more line', other: 'Show {{count}} more lines' },
|
|
104
|
+
'chat.fileChanges.split': 'Split',
|
|
105
|
+
'chat.fileChanges.stats': '{{additions}} lines added, {{deletions}} lines removed',
|
|
106
|
+
'chat.fileChanges.summary': {
|
|
107
|
+
one: '1 file changed, +{{additions}} −{{deletions}}',
|
|
108
|
+
other: '{{count}} files changed, +{{additions}} −{{deletions}}',
|
|
109
|
+
},
|
|
110
|
+
'chat.fileChanges.title': 'Changes',
|
|
111
|
+
'chat.fileChanges.tooLarge': 'Too large to show here',
|
|
112
|
+
'chat.fileChanges.unified': 'Unified',
|
|
113
|
+
'chat.fileChanges.unrecorded': 'The agent did not record what changed in this file',
|
|
114
|
+
'chat.fileChanges.wrap': 'Wrap lines',
|
|
87
115
|
'chat.like': 'Like',
|
|
116
|
+
'chat.actionApproval.send': 'Send',
|
|
117
|
+
'chat.actionApproval.approve': 'Approve',
|
|
118
|
+
'chat.actionApproval.reject': 'Reject',
|
|
119
|
+
'chat.actionApproval.status.pending': 'Pending approval',
|
|
120
|
+
'chat.actionApproval.status.approved': 'Approved',
|
|
121
|
+
'chat.actionApproval.status.executing': 'Sending…',
|
|
122
|
+
'chat.actionApproval.status.executed': 'Completed',
|
|
123
|
+
'chat.actionApproval.status.failed': 'Failed',
|
|
124
|
+
'chat.actionApproval.status.rejected': 'Rejected',
|
|
125
|
+
'chat.actionApproval.status.expired': 'Expired',
|
|
126
|
+
'chat.actionApproval.sent': 'Sent',
|
|
127
|
+
'chat.actionApproval.decisionFailed': 'Your decision couldn’t be saved. Try again.',
|
|
88
128
|
'chat.approval.allow': 'Allow',
|
|
89
129
|
'chat.approval.deny': 'Deny',
|
|
90
130
|
'chat.approval.resolved.allow': '%{tool}: allowed',
|
package/src/lib/copy-es.ts
CHANGED
|
@@ -80,7 +80,50 @@ export const COPY_ES: Readonly<Record<string, CopyEntry>> = {
|
|
|
80
80
|
'chat.dislike': 'No me gusta',
|
|
81
81
|
'chat.edit': 'Editar',
|
|
82
82
|
'chat.feedbackFailed': 'No se ha podido guardar tu opinión.',
|
|
83
|
+
'chat.fileChanges.binary': 'Archivo binario, sin vista previa',
|
|
84
|
+
'chat.fileChanges.chip': { one: '1 archivo cambiado', other: '{{count}} archivos cambiados' },
|
|
85
|
+
'chat.fileChanges.collapseAll': 'Contraer todo',
|
|
86
|
+
'chat.fileChanges.copyPath': 'Copiar ruta',
|
|
87
|
+
'chat.fileChanges.expandAll': 'Expandir todo',
|
|
88
|
+
'chat.fileChanges.layout': 'Disposición',
|
|
89
|
+
'chat.fileChanges.noContent': 'Sin cambios en el contenido',
|
|
90
|
+
'chat.fileChanges.open': {
|
|
91
|
+
one: 'Revisar 1 archivo cambiado, +{{additions}} −{{deletions}}',
|
|
92
|
+
other: 'Revisar {{count}} archivos cambiados, +{{additions}} −{{deletions}}',
|
|
93
|
+
},
|
|
94
|
+
'chat.fileChanges.operation.add': 'Añadido',
|
|
95
|
+
'chat.fileChanges.operation.delete': 'Eliminado',
|
|
96
|
+
'chat.fileChanges.operation.rename': 'Renombrado',
|
|
97
|
+
'chat.fileChanges.operation.update': 'Modificado',
|
|
98
|
+
'chat.fileChanges.renamedFrom': 'Renombrado desde {{path}}',
|
|
99
|
+
'chat.fileChanges.showMore': {
|
|
100
|
+
one: 'Mostrar 1 línea más',
|
|
101
|
+
other: 'Mostrar {{count}} líneas más',
|
|
102
|
+
},
|
|
103
|
+
'chat.fileChanges.split': 'Dividida',
|
|
104
|
+
'chat.fileChanges.stats': '{{additions}} líneas añadidas, {{deletions}} líneas eliminadas',
|
|
105
|
+
'chat.fileChanges.summary': {
|
|
106
|
+
one: '1 archivo cambiado, +{{additions}} −{{deletions}}',
|
|
107
|
+
other: '{{count}} archivos cambiados, +{{additions}} −{{deletions}}',
|
|
108
|
+
},
|
|
109
|
+
'chat.fileChanges.title': 'Cambios',
|
|
110
|
+
'chat.fileChanges.tooLarge': 'Demasiado grande para mostrarlo aquí',
|
|
111
|
+
'chat.fileChanges.unified': 'Unificada',
|
|
112
|
+
'chat.fileChanges.unrecorded': 'El agente no registró qué cambió en este archivo',
|
|
113
|
+
'chat.fileChanges.wrap': 'Ajustar líneas',
|
|
83
114
|
'chat.like': 'Me gusta',
|
|
115
|
+
'chat.actionApproval.send': 'Enviar',
|
|
116
|
+
'chat.actionApproval.approve': 'Aprobar',
|
|
117
|
+
'chat.actionApproval.reject': 'Rechazar',
|
|
118
|
+
'chat.actionApproval.status.pending': 'Pendiente de aprobación',
|
|
119
|
+
'chat.actionApproval.status.approved': 'Aprobado',
|
|
120
|
+
'chat.actionApproval.status.executing': 'En curso…',
|
|
121
|
+
'chat.actionApproval.status.executed': 'Completado',
|
|
122
|
+
'chat.actionApproval.status.failed': 'Fallido',
|
|
123
|
+
'chat.actionApproval.status.rejected': 'Rechazado',
|
|
124
|
+
'chat.actionApproval.status.expired': 'Caducado',
|
|
125
|
+
'chat.actionApproval.sent': 'Enviado',
|
|
126
|
+
'chat.actionApproval.decisionFailed': 'Tu decisión no se pudo guardar. Inténtalo de nuevo.',
|
|
84
127
|
'chat.approval.allow': 'Permitir',
|
|
85
128
|
'chat.approval.deny': 'Denegar',
|
|
86
129
|
'chat.approval.resolved.allow': '%{tool}: permitido',
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { useRealtimeEvent, useRealtimeReset } from '../realtime/react';
|
|
3
|
+
import { useGemieApi } from './api';
|
|
4
|
+
import { API_ROUTES } from './routes';
|
|
5
|
+
|
|
6
|
+
const STATUS_ORDER = {
|
|
7
|
+
pending: 0,
|
|
8
|
+
approved: 1,
|
|
9
|
+
executing: 2,
|
|
10
|
+
executed: 3,
|
|
11
|
+
failed: 3,
|
|
12
|
+
rejected: 3,
|
|
13
|
+
expired: 3,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export interface ActionApproval {
|
|
17
|
+
id: string;
|
|
18
|
+
conversationId: string;
|
|
19
|
+
messageId: string | null;
|
|
20
|
+
preview: {
|
|
21
|
+
title: string;
|
|
22
|
+
action: 'send' | 'approve';
|
|
23
|
+
fields: { name: string; label: string; value: string }[];
|
|
24
|
+
};
|
|
25
|
+
status: keyof typeof STATUS_ORDER;
|
|
26
|
+
expiresAt: string;
|
|
27
|
+
decidedAt: string | null;
|
|
28
|
+
error: string | null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type DecideAction = (id: string, decision: 'approve' | 'reject') => Promise<void>;
|
|
32
|
+
export interface ConversationActionApprovals {
|
|
33
|
+
entries: readonly ActionApproval[];
|
|
34
|
+
decide: DecideAction;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const NO_ENTRIES: readonly ActionApproval[] = [];
|
|
38
|
+
|
|
39
|
+
export function useConversationActionApprovals(
|
|
40
|
+
userId: string | undefined,
|
|
41
|
+
conversationId: string | undefined,
|
|
42
|
+
streaming: boolean,
|
|
43
|
+
): ConversationActionApprovals {
|
|
44
|
+
const api = useGemieApi();
|
|
45
|
+
const scope = userId && conversationId ? JSON.stringify([userId, conversationId]) : undefined;
|
|
46
|
+
const [snapshot, setSnapshot] = useState<{
|
|
47
|
+
scope: string;
|
|
48
|
+
entries: readonly ActionApproval[];
|
|
49
|
+
}>();
|
|
50
|
+
const entries = snapshot?.scope === scope ? (snapshot?.entries ?? NO_ENTRIES) : NO_ENTRIES;
|
|
51
|
+
|
|
52
|
+
const refresh = useCallback(
|
|
53
|
+
(signal?: AbortSignal) => {
|
|
54
|
+
if (!scope || !conversationId) return;
|
|
55
|
+
void api
|
|
56
|
+
.get<{ approvals: ActionApproval[] }>(API_ROUTES.actionApprovals.list, {
|
|
57
|
+
params: { conversationId },
|
|
58
|
+
signal,
|
|
59
|
+
})
|
|
60
|
+
.then(({ data }) => {
|
|
61
|
+
if (signal?.aborted || !Array.isArray(data?.approvals)) return;
|
|
62
|
+
setSnapshot((previous) => {
|
|
63
|
+
const known = previous?.scope === scope ? previous.entries : NO_ENTRIES;
|
|
64
|
+
const byId = new Map(known.map((entry) => [entry.id, entry]));
|
|
65
|
+
return {
|
|
66
|
+
scope,
|
|
67
|
+
entries: [...data.approvals].reverse().map((entry) => {
|
|
68
|
+
const old = byId.get(entry.id);
|
|
69
|
+
return old && STATUS_ORDER[old.status] > STATUS_ORDER[entry.status] ? old : entry;
|
|
70
|
+
}),
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
})
|
|
74
|
+
.catch(() => undefined);
|
|
75
|
+
},
|
|
76
|
+
[api, conversationId, scope],
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (streaming) return;
|
|
81
|
+
const controller = new AbortController();
|
|
82
|
+
refresh(controller.signal);
|
|
83
|
+
return () => controller.abort();
|
|
84
|
+
}, [refresh, streaming]);
|
|
85
|
+
|
|
86
|
+
useRealtimeEvent('conversation', ({ data }) => {
|
|
87
|
+
const change = data as { conversation?: { id?: string } };
|
|
88
|
+
if (change.conversation?.id === conversationId) refresh();
|
|
89
|
+
});
|
|
90
|
+
useRealtimeReset(refresh);
|
|
91
|
+
|
|
92
|
+
// The account event is the usual wake. Poll only while a decision or provider receipt is due.
|
|
93
|
+
const awaitingDecision = entries.some((entry) => STATUS_ORDER[entry.status] < 3);
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (!awaitingDecision) return;
|
|
96
|
+
const controller = new AbortController();
|
|
97
|
+
const timer = setInterval(() => refresh(controller.signal), 5000);
|
|
98
|
+
return () => {
|
|
99
|
+
controller.abort();
|
|
100
|
+
clearInterval(timer);
|
|
101
|
+
};
|
|
102
|
+
}, [awaitingDecision, refresh]);
|
|
103
|
+
|
|
104
|
+
const decide = useCallback<DecideAction>(
|
|
105
|
+
async (id, decision) => {
|
|
106
|
+
if (!scope) return;
|
|
107
|
+
const { data } = await api.post<ActionApproval>(
|
|
108
|
+
API_ROUTES.actionApprovals.decide(id, decision),
|
|
109
|
+
);
|
|
110
|
+
setSnapshot((previous) =>
|
|
111
|
+
previous?.scope !== scope
|
|
112
|
+
? previous
|
|
113
|
+
: {
|
|
114
|
+
scope,
|
|
115
|
+
entries: previous.entries.map((entry) =>
|
|
116
|
+
entry.id === id && STATUS_ORDER[entry.status] <= STATUS_ORDER[data.status]
|
|
117
|
+
? data
|
|
118
|
+
: entry,
|
|
119
|
+
),
|
|
120
|
+
},
|
|
121
|
+
);
|
|
122
|
+
},
|
|
123
|
+
[api, scope],
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
return { entries, decide };
|
|
127
|
+
}
|
package/src/runtime/config.tsx
CHANGED
|
@@ -22,9 +22,20 @@ export interface GemieArtifact {
|
|
|
22
22
|
timestamp: number;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* A turn answered on a lighter model because the person's credits ran out (`alia.credits_fallback`):
|
|
27
|
+
* why, and that the turn's tools are paused. Gemies pays for it; the person is charged nothing.
|
|
28
|
+
*/
|
|
29
|
+
export interface GemieCreditsFallback {
|
|
30
|
+
reason: 'credits';
|
|
31
|
+
tools: 'paused';
|
|
32
|
+
}
|
|
33
|
+
|
|
25
34
|
/** The usage frame a stream ends with: the balance left and, sometimes, a spending warning. */
|
|
26
35
|
export interface GemieUsageFrame {
|
|
27
36
|
credits_remaining?: number;
|
|
37
|
+
/** Present when Gemies funded the turn because the person's credits ran out. */
|
|
38
|
+
fallback?: GemieCreditsFallback;
|
|
28
39
|
credit_warning?: {
|
|
29
40
|
level?: string;
|
|
30
41
|
daysRemaining?: unknown;
|
|
@@ -86,6 +97,11 @@ export interface GemieRuntimeHost {
|
|
|
86
97
|
onOutput?: () => void;
|
|
87
98
|
/** The stream's usage frame: credits left and the spending warning. */
|
|
88
99
|
onUsage?: (usage: GemieUsageFrame) => void;
|
|
100
|
+
/**
|
|
101
|
+
* The turn about to stream is on the credits fallback: a lighter model with tools paused. Sent
|
|
102
|
+
* before the first token, so the host can say so while the answer arrives.
|
|
103
|
+
*/
|
|
104
|
+
onCreditsFallback?: (fallback: GemieCreditsFallback) => void;
|
|
89
105
|
/** A tool finished; `name` is the tool, `output` its structural result. */
|
|
90
106
|
onToolResult?: (result: {
|
|
91
107
|
toolCallId: string;
|
package/src/runtime/index.ts
CHANGED
package/src/runtime/model.ts
CHANGED
|
@@ -15,6 +15,7 @@ export type { Translate } from '../lib/copy';
|
|
|
15
15
|
export * from './thread/agent-activity';
|
|
16
16
|
export * from './thread/automation-labels';
|
|
17
17
|
export * from './thread/conversation-export';
|
|
18
|
+
export * from './thread/file-changes';
|
|
18
19
|
export * from './thread/message-days';
|
|
19
20
|
export * from './thread/message-processor';
|
|
20
21
|
export * from './thread/task-utils';
|