@gemies/sdk 9.1.0 → 9.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gemies/sdk",
3
- "version": "9.1.0",
3
+ "version": "9.2.0",
4
4
  "description": "The Gemies SDK: the conversation runtime, chat UI, voice calls and dictation for Oxy apps that talk to a gemie",
5
5
  "main": "src/index.ts",
6
6
  "react-native": "src/index.ts",
@@ -407,6 +407,8 @@ function GemieConversationView({
407
407
  suggestedNewConversation,
408
408
  dismissSuggestedNewConversation,
409
409
  agentRun,
410
+ approvals,
411
+ settleApproval,
410
412
  failedTurn,
411
413
  retryFailedTurn,
412
414
  } = thread;
@@ -644,6 +646,22 @@ function GemieConversationView({
644
646
  [suggestedNewConversation, acceptNewConversation, dismissSuggestedNewConversation],
645
647
  );
646
648
 
649
+ // A coding CLI's question to its own user (ADR 0043 §5): the host carries the answer to Gemies.
650
+ const decideApproval = runtime.host.onApprovalDecision;
651
+ const approvalCards = useMemo(
652
+ () => ({
653
+ entries: approvals,
654
+ agentName: lead.name,
655
+ onDecide:
656
+ decideApproval === undefined
657
+ ? undefined
658
+ : (entry: (typeof approvals)[number], decision: 'allow' | 'deny') =>
659
+ decideApproval(entry.requestId, entry.agentId, decision),
660
+ onSettled: settleApproval,
661
+ }),
662
+ [approvals, lead.name, decideApproval, settleApproval],
663
+ );
664
+
647
665
  // ── The chrome ──
648
666
  const latestMessages = useRef(messages);
649
667
  latestMessages.current = messages;
@@ -800,6 +818,7 @@ function GemieConversationView({
800
818
  onRegenerate={composer.regenerate}
801
819
  onStartEdit={edit.start}
802
820
  newConversationOffer={newConversationOffer}
821
+ approvals={approvalCards}
803
822
  agentActivity={agentRun === null ? null : agentActivity}
804
823
  call={voice.isActive ? { agentState: voice.agentState } : undefined}
805
824
  empty={welcome}
@@ -0,0 +1,114 @@
1
+ import { Notification } from '@oxy.so/bloom/notification';
2
+ import { Muted } from '@oxy.so/bloom/typography';
3
+ import React, { useCallback, useState } from 'react';
4
+ import { View } from 'react-native';
5
+ import { useLabels } from '../../lib/labels';
6
+ import {
7
+ ApprovalExpiredError,
8
+ type ApprovalDecision,
9
+ type ApprovalEntry,
10
+ type ApprovalOutcome,
11
+ } 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
+ }
25
+
26
+ /**
27
+ * 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 two answers. The CLI waits
29
+ * for the person; once answered the card shrinks to one line saying how it ended.
30
+ *
31
+ * This is the CLI's prompt to the person who runs it, not a permission Gemies or Oxy asks for.
32
+ */
33
+ export const ApprovalCards = React.memo(function ApprovalCards({
34
+ entries,
35
+ agentName,
36
+ onDecide,
37
+ onSettled,
38
+ }: ApprovalsProps) {
39
+ return (
40
+ <>
41
+ {entries.map((entry) => (
42
+ <ApprovalCard
43
+ key={entry.requestId}
44
+ entry={entry}
45
+ agentName={agentName}
46
+ onDecide={onDecide}
47
+ onSettled={onSettled}
48
+ />
49
+ ))}
50
+ </>
51
+ );
52
+ });
53
+
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
+ }) {
65
+ 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
+
86
+ if (entry.outcome !== 'pending') {
87
+ return (
88
+ <View className="px-4 py-1" accessibilityRole="text">
89
+ <Muted>{t(`chat.approval.resolved.${entry.outcome}`, { tool: entry.tool })}</Muted>
90
+ </View>
91
+ );
92
+ }
93
+
94
+ const description = [entry.summary, failed ? t('chat.approval.sendFailed') : undefined]
95
+ .filter(Boolean)
96
+ .join('\n');
97
+ return (
98
+ <Notification
99
+ status="warning"
100
+ title={t('chat.approval.title', { agent: agentName, tool: entry.tool })}
101
+ description={description === '' ? undefined : description}
102
+ // While an answer is on its way there is nothing to press: a second tap must not send another.
103
+ actions={
104
+ onDecide && !sending
105
+ ? [
106
+ { label: t('chat.approval.deny'), onPress: () => decide('deny') },
107
+ { label: t('chat.approval.allow'), onPress: () => decide('allow') },
108
+ ]
109
+ : undefined
110
+ }
111
+ dismissible={false}
112
+ />
113
+ );
114
+ }
@@ -32,6 +32,7 @@ import type { ThreadHistory } from '../../runtime/thread/thread-history';
32
32
  import type { AgentState } from '../../types';
33
33
  import { AgentResultCard } from './AgentResultCard';
34
34
  import { AgentTaskCard } from './AgentTaskCard';
35
+ import { type ApprovalsProps, ApprovalCards } from './ApprovalCard';
35
36
  import { NewConversationOffer } from './NewConversationOffer';
36
37
  import { type ThreadActions, ThreadRow } from './ThreadRow';
37
38
 
@@ -81,6 +82,11 @@ export interface GemieThreadProps {
81
82
  /** Load one of this conversation's questions into the composer to rewrite it. */
82
83
  onStartEdit?: (userMessageId: string) => void;
83
84
  newConversationOffer?: NewConversationOfferProps;
85
+ /**
86
+ * A coding CLI asking its own user for permission to run something on their computer, while the
87
+ * turn waits (ADR 0043 §5). Drawn after the turns, where the person is looking.
88
+ */
89
+ approvals?: ApprovalsProps;
84
90
  /** The run an agent is on for this conversation: in progress, or the card it leaves. */
85
91
  agentActivity?: AgentActivityState | null;
86
92
  /**
@@ -136,6 +142,7 @@ export const GemieThread = memo(function GemieThread({
136
142
  onRegenerate,
137
143
  onStartEdit,
138
144
  newConversationOffer,
145
+ approvals,
139
146
  agentActivity,
140
147
  call,
141
148
  empty,
@@ -375,6 +382,10 @@ export const GemieThread = memo(function GemieThread({
375
382
  )
376
383
  ) : null}
377
384
 
385
+ {approvals === undefined || approvals.entries.length === 0 ? null : (
386
+ <ApprovalCards {...approvals} />
387
+ )}
388
+
378
389
  {/* The agent's offer to start the next stretch fresh. Last in the list on purpose: it
379
390
  must not cover what is being read, and ignoring it has to leave the thread exactly as
380
391
  it was. */}
@@ -85,6 +85,13 @@ export const COPY_EN: Readonly<Record<string, CopyEntry>> = {
85
85
  'chat.edit': 'Edit',
86
86
  'chat.feedbackFailed': "Your feedback couldn't be saved.",
87
87
  'chat.like': 'Like',
88
+ 'chat.approval.allow': 'Allow',
89
+ 'chat.approval.deny': 'Deny',
90
+ 'chat.approval.resolved.allow': '%{tool}: allowed',
91
+ 'chat.approval.resolved.deny': '%{tool}: denied',
92
+ 'chat.approval.resolved.expired': '%{tool}: timed out',
93
+ 'chat.approval.sendFailed': "Your answer couldn't be sent. Try again.",
94
+ 'chat.approval.title': '%{agent} wants to run %{tool}',
88
95
  'chat.newConversationAccept': 'Start a new one',
89
96
  'chat.newConversationDismiss': 'Not now',
90
97
  'chat.newConversationOffer': 'Start a new conversation?',
@@ -81,6 +81,13 @@ export const COPY_ES: Readonly<Record<string, CopyEntry>> = {
81
81
  'chat.edit': 'Editar',
82
82
  'chat.feedbackFailed': 'No se ha podido guardar tu opinión.',
83
83
  'chat.like': 'Me gusta',
84
+ 'chat.approval.allow': 'Permitir',
85
+ 'chat.approval.deny': 'Denegar',
86
+ 'chat.approval.resolved.allow': '%{tool}: permitido',
87
+ 'chat.approval.resolved.deny': '%{tool}: denegado',
88
+ 'chat.approval.resolved.expired': '%{tool}: sin respuesta a tiempo',
89
+ 'chat.approval.sendFailed': 'No se pudo enviar tu respuesta. Inténtalo de nuevo.',
90
+ 'chat.approval.title': '%{agent} quiere ejecutar %{tool}',
84
91
  'chat.newConversationAccept': 'Empezar una nueva',
85
92
  'chat.newConversationDismiss': 'Ahora no',
86
93
  'chat.newConversationOffer': '¿Empezar una conversación nueva?',
@@ -0,0 +1,99 @@
1
+ /**
2
+ * A coding CLI asking its own user for permission, in the conversation (Gemies ADR 0043 §5).
3
+ *
4
+ * During a turn with an external agent (Claude Code on the person's computer), the CLI may stop and
5
+ * ask whether it can run something there. The turn waits; the stream carries two named events:
6
+ *
7
+ * `alia.cli_permission_request` the CLI asks: which tool, on what.
8
+ * `alia.cli_permission_resolved` the answer was given, or the time ran out.
9
+ *
10
+ * This is the third-party CLI's prompt to the person who runs it, on their own machine. It is not
11
+ * an Oxy grant: nothing here reaches Oxy, and the SDK does not know the endpoint that carries the
12
+ * answer — the host does (`GemieRuntimeHost.onApprovalDecision`).
13
+ */
14
+
15
+ export type ApprovalDecision = 'allow' | 'deny';
16
+ export type ApprovalOutcome = ApprovalDecision | 'expired';
17
+
18
+ export interface ApprovalRequest {
19
+ readonly requestId: string;
20
+ readonly agentId: string;
21
+ /** The CLI's tool: `Bash`, `Edit`, … */
22
+ readonly tool: string;
23
+ /** What it would act on (a command, a path), as the daemon reported it. */
24
+ readonly summary?: string;
25
+ /** ISO time after which the CLI is told no. */
26
+ readonly expiresAt: string;
27
+ }
28
+
29
+ /** A request and where it stands: waiting for the person, or how it ended. */
30
+ export interface ApprovalEntry extends ApprovalRequest {
31
+ readonly outcome: 'pending' | ApprovalOutcome;
32
+ }
33
+
34
+ const text = (value: unknown, max: number): string | undefined =>
35
+ typeof value === 'string' && value !== '' ? value.slice(0, max) : undefined;
36
+
37
+ /** The request in an `alia.cli_permission_request` frame, or `null` when the frame is not one. */
38
+ export function parseApprovalRequest(data: unknown): ApprovalRequest | null {
39
+ if (data === null || typeof data !== 'object') return null;
40
+ const d = data as Record<string, unknown>;
41
+ const requestId = text(d.requestId, 100);
42
+ const agentId = text(d.agentId, 100);
43
+ const tool = text(d.tool, 80);
44
+ const expiresAt = text(d.expiresAt, 40);
45
+ if (!requestId || !agentId || !tool || !expiresAt || Number.isNaN(Date.parse(expiresAt))) {
46
+ return null;
47
+ }
48
+ const summary = text(d.summary, 200);
49
+ return { requestId, agentId, tool, ...(summary ? { summary } : {}), expiresAt };
50
+ }
51
+
52
+ /** The answer in an `alia.cli_permission_resolved` frame, or `null` when the frame is not one. */
53
+ export function parseApprovalResolved(
54
+ data: unknown,
55
+ ): { requestId: string; outcome: ApprovalOutcome } | null {
56
+ if (data === null || typeof data !== 'object') return null;
57
+ const d = data as Record<string, unknown>;
58
+ const requestId = text(d.requestId, 100);
59
+ if (!requestId) return null;
60
+ const decision = d.decision;
61
+ if (decision !== 'allow' && decision !== 'deny' && decision !== 'expired') return null;
62
+ return { requestId, outcome: decision };
63
+ }
64
+
65
+ /** A request arrived: waiting, once. A repeat of one already here changes nothing. */
66
+ export function withApprovalRequest(
67
+ list: readonly ApprovalEntry[],
68
+ request: ApprovalRequest,
69
+ ): ApprovalEntry[] {
70
+ if (list.some((entry) => entry.requestId === request.requestId)) return [...list];
71
+ return [...list, { ...request, outcome: 'pending' }];
72
+ }
73
+
74
+ /** A request was answered. The first answer stands; an unknown request is ignored. */
75
+ export function withApprovalOutcome(
76
+ list: readonly ApprovalEntry[],
77
+ requestId: string,
78
+ outcome: ApprovalOutcome,
79
+ ): ApprovalEntry[] {
80
+ return list.map((entry) =>
81
+ entry.requestId === requestId && entry.outcome === 'pending' ? { ...entry, outcome } : entry,
82
+ );
83
+ }
84
+
85
+ /**
86
+ * What a host's `onApprovalDecision` rejects with when the question is no longer open (answered
87
+ * elsewhere, or its time ran out): the card then reads "Timed out" instead of offering a retry.
88
+ */
89
+ export class ApprovalExpiredError extends Error {
90
+ constructor() {
91
+ super('The approval request is no longer open');
92
+ this.name = 'ApprovalExpiredError';
93
+ }
94
+ }
95
+
96
+ /** What a new turn keeps of the last one's approvals: the ones still waiting. */
97
+ export function stillPending(list: readonly ApprovalEntry[]): ApprovalEntry[] {
98
+ return list.filter((entry) => entry.outcome === 'pending');
99
+ }
@@ -104,6 +104,16 @@ export interface GemieRuntimeHost {
104
104
  onFeatureLocked?: (key: string) => void;
105
105
  /** A delegated agent started a run of its own for this turn. */
106
106
  onAgentTurn?: (turn: AgentRun & { conversationId: string | null }) => void;
107
+ /**
108
+ * The person answered a coding CLI that asked for permission to run something on their own
109
+ * computer (`alia.cli_permission_request`, ADR 0043). The host carries the answer to Gemies; the
110
+ * promise rejects when it could not be sent. Omitted, the request is shown with no way to answer.
111
+ */
112
+ onApprovalDecision?: (
113
+ requestId: string,
114
+ agentId: string,
115
+ decision: 'allow' | 'deny',
116
+ ) => Promise<void>;
107
117
  /** The agent's row in the host's list, ahead of the server: your line, then her answer. */
108
118
  onTurnPreview?: (agentId: string | null | undefined, text: string) => void;
109
119
  /**
@@ -12,6 +12,8 @@
12
12
  */
13
13
 
14
14
  export { GemieRuntimeProvider, useGemieRuntime } from './config';
15
+ export { ApprovalExpiredError } from './approvals';
16
+ export type { ApprovalDecision, ApprovalEntry, ApprovalRequest } from './approvals';
15
17
  export type {
16
18
  GemieArtifact,
17
19
  GemieRuntimeConfig,
@@ -28,6 +28,15 @@ import {
28
28
  import { createRandomUuid } from './random-uuid';
29
29
  import { createChatTurnControl } from './chat-turn-control';
30
30
  import { awaitTurnPreparation } from './turn-preparation';
31
+ import {
32
+ type ApprovalEntry,
33
+ type ApprovalOutcome,
34
+ parseApprovalRequest,
35
+ parseApprovalResolved,
36
+ stillPending,
37
+ withApprovalOutcome,
38
+ withApprovalRequest,
39
+ } from './approvals';
31
40
  import { type GemieHostTools, HostOutcomeQueue, hostRequest } from './host-tools';
32
41
  import { API_ROUTES } from './routes';
33
42
  import { createSseFrameReader } from './sse-frame-reader';
@@ -243,6 +252,11 @@ export function useConversationStream({
243
252
  * was.
244
253
  */
245
254
  const [suggestedNewConversation, setSuggestedNewConversation] = useState<string | null>(null);
255
+ /**
256
+ * A coding CLI's questions to its own user, this turn's and any still waiting (`approvals.ts`).
257
+ * Held beside the messages, not in them: a question is not part of what was said.
258
+ */
259
+ const [approvals, setApprovals] = useState<ApprovalEntry[]>([]);
246
260
  /** The run a delegated agent started for this conversation (`alia.agent_turn`), or `null`. */
247
261
  const [agentRun, setAgentRun] = useState<AgentRun | null>(null);
248
262
  /**
@@ -375,6 +389,7 @@ export function useConversationStream({
375
389
  const conversationRef = useRef(conversationId);
376
390
  useEffect(() => {
377
391
  setFailedTurn(null);
392
+ setApprovals([]);
378
393
  retryRef.current = null;
379
394
  turnOptionsRef.current.clear();
380
395
  // Outcomes answer this conversation's calls. The first turn of a new chat gives it its id,
@@ -424,6 +439,7 @@ export function useConversationStream({
424
439
  setConversationTitle(null);
425
440
  setSuggestedNewConversation(null);
426
441
  setAgentRun(null);
442
+ setApprovals([]);
427
443
  setFailedTurn(null);
428
444
  retryRef.current = null;
429
445
  turnOptionsRef.current.clear();
@@ -438,6 +454,8 @@ export function useConversationStream({
438
454
  // A new send answers the old failure, whether it is the retry or a fresh
439
455
  // message: either way the card comes down.
440
456
  setFailedTurn(null);
457
+ // The last turn's answered questions are history; one still waiting stays.
458
+ setApprovals(stillPending);
441
459
  retryRef.current = null;
442
460
 
443
461
  // Everything the send is about to change, so a turn that produces no real
@@ -1204,6 +1222,20 @@ export function useConversationStream({
1204
1222
  );
1205
1223
  continue;
1206
1224
  }
1225
+ case 'alia.cli_permission_request': {
1226
+ const request = parseApprovalRequest(parsed);
1227
+ if (request) setApprovals((prev) => withApprovalRequest(prev, request));
1228
+ continue;
1229
+ }
1230
+ case 'alia.cli_permission_resolved': {
1231
+ const resolved = parseApprovalResolved(parsed);
1232
+ if (resolved) {
1233
+ setApprovals((prev) =>
1234
+ withApprovalOutcome(prev, resolved.requestId, resolved.outcome),
1235
+ );
1236
+ }
1237
+ continue;
1238
+ }
1207
1239
  case 'alia.agent_turn': {
1208
1240
  if (parsed.turnId) {
1209
1241
  const run = {
@@ -1675,6 +1707,11 @@ export function useConversationStream({
1675
1707
  if (!isLoading) setComposerPhase('idle');
1676
1708
  }, [isLoading, setComposerPhase]);
1677
1709
 
1710
+ /** The person's own answer, shown at once; the stream's `alia.cli_permission_resolved` repeats it. */
1711
+ const settleApproval = useCallback((requestId: string, outcome: ApprovalOutcome) => {
1712
+ setApprovals((prev) => withApprovalOutcome(prev, requestId, outcome));
1713
+ }, []);
1714
+
1678
1715
  /** Put the offer away. It wrote nothing, so there is nothing else to undo. */
1679
1716
  const dismissSuggestedNewConversation = useCallback(() => {
1680
1717
  setSuggestedNewConversation(null);
@@ -1700,6 +1737,8 @@ export function useConversationStream({
1700
1737
  suggestedNewConversation,
1701
1738
  dismissSuggestedNewConversation,
1702
1739
  agentRun,
1740
+ approvals,
1741
+ settleApproval,
1703
1742
  failedTurn,
1704
1743
  retryFailedTurn,
1705
1744
  clearFailedTurn,
@@ -157,6 +157,8 @@ export function useConversationThread({
157
157
  suggestedNewConversation,
158
158
  dismissSuggestedNewConversation,
159
159
  agentRun,
160
+ approvals,
161
+ settleApproval,
160
162
  failedTurn,
161
163
  retryFailedTurn: retry,
162
164
  clearFailedTurn,
@@ -624,6 +626,8 @@ export function useConversationThread({
624
626
  suggestedNewConversation,
625
627
  dismissSuggestedNewConversation,
626
628
  agentRun,
629
+ approvals,
630
+ settleApproval,
627
631
  failedTurn,
628
632
  retryFailedTurn,
629
633
  };