@gemies/sdk 10.0.3 → 10.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +17 -0
  3. package/package.json +2 -1
  4. package/src/ask-lean.ts +11 -0
  5. package/src/components/GemieAskCore.tsx +1 -0
  6. package/src/components/GemieAskProviderLean.tsx +26 -0
  7. package/src/components/GemieAskSheet.tsx +7 -47
  8. package/src/components/GemieAskSheetBase.tsx +53 -0
  9. package/src/components/GemieAskSheetLean.tsx +10 -0
  10. package/src/components/GemieChatContent.tsx +32 -1
  11. package/src/components/GemieChatSheet.tsx +5 -0
  12. package/src/components/canvas/ChartRenderer.tsx +6 -3
  13. package/src/components/charts/chart-cards.ts +34 -0
  14. package/src/components/charts/default-chart-cards.ts +12 -0
  15. package/src/components/diff/FileChangeSection.tsx +172 -0
  16. package/src/components/diff/FileChangesCard.tsx +51 -0
  17. package/src/components/diff/FileChangesViewer.tsx +135 -0
  18. package/src/components/diff/PatchLines.tsx +119 -0
  19. package/src/components/diff/diff-renderer.ts +38 -0
  20. package/src/components/thread/ActionApprovalCard.tsx +95 -0
  21. package/src/components/thread/GemieThread.tsx +17 -0
  22. package/src/components/thread/ThreadRow.tsx +16 -1
  23. package/src/components/thread/ToolResultCard.tsx +16 -7
  24. package/src/index.ts +10 -0
  25. package/src/lib/copy-en.ts +40 -0
  26. package/src/lib/copy-es.ts +43 -0
  27. package/src/runtime/action-approvals.ts +127 -0
  28. package/src/runtime/config.tsx +16 -0
  29. package/src/runtime/index.ts +1 -0
  30. package/src/runtime/model.ts +1 -0
  31. package/src/runtime/routes.ts +5 -0
  32. package/src/runtime/thread/file-changes.ts +150 -0
  33. package/src/runtime/use-conversation-stream.ts +5 -1
  34. package/src/text.ts +3 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,46 @@
1
1
  # @gemies/sdk
2
2
 
3
+ ## 10.2.0
4
+
5
+ ### The files an agent changed, as a diff
6
+
7
+ A turn in which an external agent (Claude Code, Codex, OpenCode) edited files now ends with a
8
+ "N files changed +X −Y" chip under it, and the chip opens a viewer: one section per file with its
9
+ `+`/`−` counts, folding on its own and all at once, copying its path, with a choice of unified or
10
+ split layout where the host's renderer has both, and line wrapping. The patches come from the edit
11
+ call's tool result (`changes`, one standard `diff --git` patch per file, made by the server from
12
+ whatever each CLI recorded). A file with no patch says why: binary, too large to keep, or never
13
+ recorded by the agent.
14
+
15
+ The SDK draws a patch itself, as numbered monospace lines with the added and removed ones tinted,
16
+ on every platform, a page of 400 lines at a time. A host that wants more passes `fileDiffRenderer`
17
+ to `GemieChatContent` (`{ PatchView, layouts }`, typed `GemieFileDiffRenderer`): the Gemies web app
18
+ brings `@pierre/diffs`, with syntax highlighting in a worker pool and a split layout, which the SDK
19
+ does not depend on. `PatchLines` is exported as the fallback for a host's own renderer while it loads.
20
+
21
+ `@gemies/sdk/model` carries the data side: `fileChangesOf`, `turnFileChanges`, `fileChangeTotals`
22
+ and `patchLines`.
23
+
24
+ ## 10.1.0
25
+
26
+ ### `@gemies/sdk/ask/lean`
27
+
28
+ A new entry: `@gemies/sdk/ask` whose sheet brings no chart cards of its own. The host passes
29
+ `chartCards` (`{ LineChartCard, BarListCard }`, typed `GemieChartCards`) to its `GemieAskProvider`,
30
+ and the conversation draws a market or FairCoin quote and a generated chart with them. An app that
31
+ draws the same cards on a lazy screen of its own loads them once, through its own `import()`,
32
+ instead of having them shared between that screen's chunk and the sheet's and hoisted into its
33
+ first paint (`__common.js`) on web. Without `chartCards`, a quote says its price in words and a
34
+ generated chart is not drawn.
35
+
36
+ Every other entry draws as before, with Bloom's cards: they now come from one module
37
+ (`components/charts/default-chart-cards`) that the root, `@gemies/sdk/text` and the default ask
38
+ sheets import. `scripts/check-entry-isolation.mjs` holds that every entry that draws the chat
39
+ brings them, that no other SDK module imports `@oxy.so/bloom/chart-cards`, and that
40
+ `@gemies/sdk/ask/lean` never reaches them, not even behind its lazy sheet.
41
+
42
+ `GemieChatSheet` and `GemieChatContent` take `chartCards` too, over the entry's own.
43
+
3
44
  ## 10.0.0
4
45
 
5
46
  Built on `@oxy.so/services` 15. The runtime's own data moved off React Query onto
package/README.md CHANGED
@@ -163,6 +163,7 @@ one is the same conversation in the others.
163
163
  | One "Ask" sheet at the app's root, loaded with the first `ask` | `@gemies/sdk/ask` | yes, in the sheet's chunk |
164
164
  | The root's eager Ask provider and hook | `@gemies/sdk/ask/eager` | yes, loaded eagerly |
165
165
  | The same, text only | `@gemies/sdk/ask/text` | no |
166
+ | `@gemies/sdk/ask` without Bloom's chart cards: you pass your own (`chartCards`) | `@gemies/sdk/ask/lean` | yes, in the sheet's chunk |
166
167
  | Data only: conversations, the stream, the model | `@gemies/sdk/runtime`, `@gemies/sdk/model` | no |
167
168
  | Her face on a button | `@gemies/sdk/avatar` | no |
168
169
  | Character parser and runtime URL | `@gemies/sdk/character` | no |
@@ -222,6 +223,22 @@ of `@gemies/sdk/ask`. So either mount the provider from `@gemies/sdk/ask`, or la
222
223
  own module that imports the root entry (or `@gemies/sdk/text`). Don't do both, or the chat they
223
224
  share lands in `__common.js`. The text-only entries draw no extra boundary either.
224
225
 
226
+ The same goes for what the sheet shares with your own lazy screens. The sheet draws charts (a
227
+ market quote, a generated chart) with Bloom's `LineChartCard` and `BarListCard`; if your app also
228
+ draws them on a lazy screen of its own, the two chunks share them and Metro hoists them into
229
+ `__common.js`. Mount the provider from `@gemies/sdk/ask/lean` instead and pass `chartCards`, the
230
+ two cards loaded through the same `import()` your screen uses, so they load once, in their own
231
+ chunk:
232
+
233
+ ```tsx
234
+ import { GemieAskProvider } from '@gemies/sdk/ask/lean';
235
+ import type { GemieChartCards } from '@gemies/sdk/ask/lean';
236
+
237
+ <GemieAskProvider chartCards={myLazyChartCards /* GemieChartCards */}>{children}</GemieAskProvider>;
238
+ ```
239
+
240
+ Without `chartCards` the lean sheet says a quote's price in words and draws no generated chart.
241
+
225
242
  The sheet offers the person's latest conversations with its lead under the greeting
226
243
  (`recentConversations={false}` turns it off). The code that configures the sheet sits above it, so
227
244
  `GemieAskProvider` forwards a ref to the same `GemieAsk` for it.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gemies/sdk",
3
- "version": "10.0.3",
3
+ "version": "10.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",
@@ -11,6 +11,7 @@
11
11
  "./accounts": "./src/accounts.ts",
12
12
  "./ask": "./src/ask.ts",
13
13
  "./ask/eager": "./src/ask-eager.ts",
14
+ "./ask/lean": "./src/ask-lean.ts",
14
15
  "./ask/text": "./src/ask-text.ts",
15
16
  "./avatar": "./src/avatar.ts",
16
17
  "./character": "./src/character.ts",
@@ -0,0 +1,11 @@
1
+ // @gemies/sdk/ask/lean — `@gemies/sdk/ask` whose sheet brings no chart cards of its own
2
+ // The same provider and hook; the host passes `chartCards` (Bloom's `LineChartCard` and
3
+ // `BarListCard`, loaded however it likes) and the conversation draws its charts with them.
4
+
5
+ export { GemieAskProvider, useAskGemie } from './components/GemieAskProviderLean';
6
+ export type {
7
+ GemieAsk,
8
+ GemieAskAgents,
9
+ GemieAskProviderProps,
10
+ } from './components/GemieAskProviderLean';
11
+ export type { GemieChartCards } from './components/charts/chart-cards';
@@ -44,6 +44,7 @@ export interface GemieAskProviderProps
44
44
  | 'app'
45
45
  | 'hostTools'
46
46
  | 'toolRenderers'
47
+ | 'chartCards'
47
48
  | 'labels'
48
49
  | 'voice'
49
50
  | 'clientContext'
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The ask provider of `@gemies/sdk/ask/lean`: `@gemies/sdk/ask`'s, whose sheet comes without
3
+ * Bloom's chart cards. The host draws the charts with its own (`chartCards`), so an app that
4
+ * already loads those cards behind an `import()` of its own (its insights, say) loads them once, in
5
+ * that chunk, instead of having them shared between its chunk and the sheet's — and hoisted into
6
+ * its first paint (`__common.js`) for it.
7
+ *
8
+ * Its `import()` is the one async boundary of this entry, as in `GemieAskProviderLazy`.
9
+ */
10
+
11
+ import { lazy, Suspense } from 'react';
12
+ import { type AskSheetComponent, createAskProvider } from './GemieAskCore';
13
+
14
+ const loadSheet = () => import('./GemieAskSheetLean');
15
+ const LazyAskSheet = lazy(() => loadSheet().then((module) => ({ default: module.GemieAskSheet })));
16
+
17
+ const SuspendedAskSheet: AskSheetComponent = (props) => (
18
+ <Suspense fallback={null}>
19
+ <LazyAskSheet {...props} />
20
+ </Suspense>
21
+ );
22
+
23
+ export type { GemieAsk, GemieAskAgents, GemieAskProviderProps } from './GemieAskCore';
24
+ export { useAskGemie } from './GemieAskCore';
25
+
26
+ export const GemieAskProvider = createAskProvider(SuspendedAskSheet, loadSheet);
@@ -1,51 +1,11 @@
1
1
  /**
2
- * The sheet `GemieAskProvider` mounts, in its own module so the provider can load it lazily: an app
3
- * that mounts the provider at its root carries only the provider in its entry bundle, and the
4
- * chat — thread, composer, voice, renderers — arrives with the first `ask`.
5
- *
6
- * It presents the opening it is handed once it is mounted, which is the only moment a lazily
7
- * loaded sheet can be presented, and tells the provider the opening is spent.
2
+ * The sheet `GemieAskProvider` mounts, drawing its charts with Bloom's cards: what
3
+ * `@gemies/sdk/ask/text` loads with the first `ask`, and what `GemieAskSheetWithVoice` wraps for
4
+ * `@gemies/sdk/ask`, `/ask/eager` and the root. `@gemies/sdk/ask/lean` loads `GemieAskSheetBase`
5
+ * without them, so a host there brings its own (`chartCards`).
8
6
  */
9
7
 
10
- import { forwardRef, useEffect, useImperativeHandle, useRef } from 'react';
11
- import type { GemieTurn } from '../hooks/useChatComposer';
12
- import { GemieChatSheet, type GemieChatSheetProps, type GemieChatSheetRef } from './GemieChatSheet';
8
+ import './charts/default-chart-cards';
13
9
 
14
- /** What the person asked for: a turn to send, or a stored conversation to pick up again. */
15
- export interface GemieAskOpening {
16
- turn: GemieTurn | undefined;
17
- conversationId?: string;
18
- /** Changes on every `ask`, so asking the same agent twice opens twice. */
19
- serial: number;
20
- }
21
-
22
- export interface GemieAskSheetProps extends GemieChatSheetProps {
23
- /** The opening to present once mounted; `null` when there is none waiting. */
24
- opening: GemieAskOpening | null;
25
- /** The opening was presented. */
26
- onOpened: () => void;
27
- }
28
-
29
- export const GemieAskSheet = forwardRef<GemieChatSheetRef, GemieAskSheetProps>(
30
- function GemieAskSheet({ opening, onOpened, ...sheet }, ref) {
31
- const sheetRef = useRef<GemieChatSheetRef>(null);
32
- useImperativeHandle(
33
- ref,
34
- () => ({
35
- present: (turn?: GemieTurn) => sheetRef.current?.present(turn),
36
- resume: (conversationId: string) => sheetRef.current?.resume(conversationId),
37
- dismiss: () => sheetRef.current?.dismiss(),
38
- }),
39
- [],
40
- );
41
-
42
- useEffect(() => {
43
- if (opening === null) return;
44
- if (opening.conversationId !== undefined) sheetRef.current?.resume(opening.conversationId);
45
- else sheetRef.current?.present(opening.turn);
46
- onOpened();
47
- }, [opening, onOpened]);
48
-
49
- return <GemieChatSheet ref={sheetRef} {...sheet} />;
50
- },
51
- );
10
+ export { GemieAskSheet } from './GemieAskSheetBase';
11
+ export type { GemieAskOpening, GemieAskSheetProps } from './GemieAskSheetBase';
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The sheet `GemieAskProvider` mounts, in its own module so the provider can load it lazily: an app
3
+ * that mounts the provider at its root carries only the provider in its entry bundle, and the
4
+ * chat — thread, composer, voice, renderers — arrives with the first `ask`.
5
+ *
6
+ * It presents the opening it is handed once it is mounted, which is the only moment a lazily
7
+ * loaded sheet can be presented, and tells the provider the opening is spent.
8
+ *
9
+ * It brings no chart cards: `GemieAskSheet` adds Bloom's, and `@gemies/sdk/ask/lean`'s host its own.
10
+ */
11
+
12
+ import { forwardRef, useEffect, useImperativeHandle, useRef } from 'react';
13
+ import type { GemieTurn } from '../hooks/useChatComposer';
14
+ import { GemieChatSheet, type GemieChatSheetProps, type GemieChatSheetRef } from './GemieChatSheet';
15
+
16
+ /** What the person asked for: a turn to send, or a stored conversation to pick up again. */
17
+ export interface GemieAskOpening {
18
+ turn: GemieTurn | undefined;
19
+ conversationId?: string;
20
+ /** Changes on every `ask`, so asking the same agent twice opens twice. */
21
+ serial: number;
22
+ }
23
+
24
+ export interface GemieAskSheetProps extends GemieChatSheetProps {
25
+ /** The opening to present once mounted; `null` when there is none waiting. */
26
+ opening: GemieAskOpening | null;
27
+ /** The opening was presented. */
28
+ onOpened: () => void;
29
+ }
30
+
31
+ export const GemieAskSheet = forwardRef<GemieChatSheetRef, GemieAskSheetProps>(
32
+ function GemieAskSheet({ opening, onOpened, ...sheet }, ref) {
33
+ const sheetRef = useRef<GemieChatSheetRef>(null);
34
+ useImperativeHandle(
35
+ ref,
36
+ () => ({
37
+ present: (turn?: GemieTurn) => sheetRef.current?.present(turn),
38
+ resume: (conversationId: string) => sheetRef.current?.resume(conversationId),
39
+ dismiss: () => sheetRef.current?.dismiss(),
40
+ }),
41
+ [],
42
+ );
43
+
44
+ useEffect(() => {
45
+ if (opening === null) return;
46
+ if (opening.conversationId !== undefined) sheetRef.current?.resume(opening.conversationId);
47
+ else sheetRef.current?.present(opening.turn);
48
+ onOpened();
49
+ }, [opening, onOpened]);
50
+
51
+ return <GemieChatSheet ref={sheetRef} {...sheet} />;
52
+ },
53
+ );
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The ask sheet with the voice call and without Bloom's chart cards: what `@gemies/sdk/ask/lean`
3
+ * loads with the first `ask`. Its charts are drawn with the host's `chartCards`; with none, a quote
4
+ * says its price in words and a generated chart is not drawn.
5
+ */
6
+
7
+ import { GemieAskSheet as TextAskSheet } from './GemieAskSheetBase';
8
+ import { withVoiceCall } from './voice/withVoiceCall';
9
+
10
+ export const GemieAskSheet = withVoiceCall(TextAskSheet, 'GemieAskSheet');
@@ -1,3 +1,4 @@
1
+ import { useConversationActionApprovals } from '../runtime/action-approvals';
1
2
  /**
2
3
  * The conversation: header, thread and composer, with its voice call. The one screen of the
3
4
  * bottom sheet, `GemieChatScreen` and the Alia app — they are frames around this.
@@ -60,6 +61,8 @@ import {
60
61
  leadOf,
61
62
  } from '../lib/participants';
62
63
  import { type GemieToolRenderers, GemieToolRenderersProvider } from '../lib/tool-renderers';
64
+ import { type GemieChartCards, GemieChartCardsProvider } from './charts/chart-cards';
65
+ import { type GemieFileDiffRenderer, GemieFileDiffRendererProvider } from './diff/diff-renderer';
63
66
  import { KeyboardSafeAreaFloor } from '../lib/keyboard';
64
67
  import { type GemieChatLabels, GemieChatLabelsProvider, useLabels } from '../lib/labels';
65
68
  import { type DeviceModel, buildPowerLevelOptions } from '../lib/power-level-options';
@@ -181,6 +184,16 @@ export interface GemieChatContentProps {
181
184
  hostTools?: GemieHostTools;
182
185
  /** The app's own drawing of a catalogue tool's result, keyed `<app>:<tool>`, before the generic card. */
183
186
  toolRenderers?: GemieToolRenderers;
187
+ /**
188
+ * The chart cards the conversation draws with, over the entry's own (Bloom's). Only
189
+ * `@gemies/sdk/ask/lean` comes without them, so a host on it passes its own here.
190
+ */
191
+ chartCards?: GemieChartCards;
192
+ /**
193
+ * How the patch of a file an agent changed is drawn, over the SDK's plain lines. The app brings
194
+ * syntax highlighting and a split layout on the web; the SDK depends on neither.
195
+ */
196
+ fileDiffRenderer?: GemieFileDiffRenderer;
184
197
  /**
185
198
  * The lead's feature gate refused something (`attachments.documents`…): the host shows its own
186
199
  * upsell. Also called for a locked row of the attach menu.
@@ -316,6 +329,8 @@ type ConversationViewProps = Omit<
316
329
  | 'conversationId'
317
330
  | 'apiUrl'
318
331
  | 'toolRenderers'
332
+ | 'chartCards'
333
+ | 'fileDiffRenderer'
319
334
  | 'onFeatureLocked'
320
335
  > & { conversationId: string | undefined };
321
336
 
@@ -538,6 +553,11 @@ function GemieConversationView({
538
553
 
539
554
  // ── The ambient wave — one persistent overlay across idle, voice, read-aloud and dictation ──
540
555
  const tts = useTTS({ apiUrl: runtime.apiUrl, ...runtime.speech });
556
+ const actionApprovals = useConversationActionApprovals(
557
+ isAuthenticated ? user?.id : undefined,
558
+ conversationId,
559
+ isLoading,
560
+ );
541
561
  const { state: voiceState } = voice;
542
562
  const wave = useAmbientWave({
543
563
  voice: voiceState
@@ -816,6 +836,7 @@ function GemieConversationView({
816
836
  onStartEdit={edit.start}
817
837
  newConversationOffer={newConversationOffer}
818
838
  approvals={approvalCards}
839
+ actionApprovals={showsPast ? undefined : actionApprovals}
819
840
  agentActivity={agentRun === null ? null : agentActivity}
820
841
  call={voice.isActive ? { agentState: voice.agentState } : undefined}
821
842
  empty={welcome}
@@ -863,6 +884,8 @@ export function GemieChatContent({
863
884
  apiUrl,
864
885
  app,
865
886
  toolRenderers,
887
+ chartCards,
888
+ fileDiffRenderer,
866
889
  onFeatureLocked,
867
890
  ...props
868
891
  }: GemieChatContentProps) {
@@ -906,7 +929,15 @@ export function GemieChatContent({
906
929
  <GemieChatLabelsProvider labels={labels}>
907
930
  <GemieRuntimeProvider apiUrl={apiUrl ?? parent.apiUrl} host={host} app={chatApp}>
908
931
  <GemieToolRenderersProvider value={toolRenderers ?? NO_RENDERERS}>
909
- <GemieConversationView {...props} conversationId={controlledId ?? ownId} />
932
+ <GemieFileDiffRendererProvider value={fileDiffRenderer ?? null}>
933
+ {chartCards === undefined ? (
934
+ <GemieConversationView {...props} conversationId={controlledId ?? ownId} />
935
+ ) : (
936
+ <GemieChartCardsProvider value={chartCards}>
937
+ <GemieConversationView {...props} conversationId={controlledId ?? ownId} />
938
+ </GemieChartCardsProvider>
939
+ )}
940
+ </GemieFileDiffRendererProvider>
910
941
  </GemieToolRenderersProvider>
911
942
  </GemieRuntimeProvider>
912
943
  </GemieChatLabelsProvider>
@@ -17,6 +17,7 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context';
17
17
  import { BREAKPOINTS } from '@oxy.so/bloom/styles';
18
18
  import { GemieChatLabelsProvider, type GemieChatLabels } from '../lib/labels';
19
19
  import type { GemieToolRenderers } from '../lib/tool-renderers';
20
+ import type { GemieChartCards } from './charts/chart-cards';
20
21
  import { useShareHandler } from '../hooks/useShareHandler';
21
22
  import type { GemieRuntimeHost } from '../runtime/config';
22
23
  import type { GemieHostTools } from '../runtime/host-tools';
@@ -59,6 +60,8 @@ export interface GemieChatSheetProps {
59
60
  hostTools?: GemieHostTools;
60
61
  /** The app's own drawing of catalogue tools' results, keyed `<app>:<tool>`. */
61
62
  toolRenderers?: GemieToolRenderers;
63
+ /** The chart cards the conversation draws with (see `GemieChatContentProps.chartCards`). */
64
+ chartCards?: GemieChartCards;
62
65
  /** The lead's feature gate refused something: show the app's upsell for `key`. */
63
66
  onFeatureLocked?: (key: string) => void;
64
67
  /** The power level (`auto`, `instant`, `medium`, `high`, `xhigh`, `pro`, `ultra`) or an exact `publisher/model` every turn is sent with; omitted, the server picks. */
@@ -123,6 +126,7 @@ const GemieChatSheetBody = forwardRef<GemieChatSheetRef, GemieChatSheetProps>(
123
126
  clientContext,
124
127
  hostTools,
125
128
  toolRenderers,
129
+ chartCards,
126
130
  onFeatureLocked,
127
131
  model,
128
132
  apiUrl,
@@ -281,6 +285,7 @@ const GemieChatSheetBody = forwardRef<GemieChatSheetRef, GemieChatSheetProps>(
281
285
  clientContext,
282
286
  hostTools,
283
287
  toolRenderers,
288
+ chartCards,
284
289
  onFeatureLocked,
285
290
  model,
286
291
  apiUrl,
@@ -1,8 +1,6 @@
1
1
  import { useLabels } from '../../lib/labels';
2
- // The two cards by subpath: the `chart-cards` root is every chart Bloom draws (~190 KB on web).
3
- import { BarListCard } from '@oxy.so/bloom/chart-cards/bar-list';
4
- import { LineChartCard } from '@oxy.so/bloom/chart-cards/line';
5
2
  import { formatNumber } from '@oxy.so/bloom/locale';
3
+ import { useChartCards } from '../charts/chart-cards';
6
4
 
7
5
  interface ChartData {
8
6
  chartType: 'bar' | 'line' | 'pie';
@@ -24,9 +22,14 @@ const format = (value: number) => formatNumber(value);
24
22
  * - one `line` series → `LineChartCard`;
25
23
  * - a `pie` → `BarListCard` in shares of the whole, which is what a pie says;
26
24
  * - bars, or several series → `BarListCard` in raw values, one tab per series.
25
+ *
26
+ * The cards are the entry's (Bloom's) or the host's (`chartCards`); with neither, there is no chart.
27
27
  */
28
28
  export function ChartRenderer({ data, title }: ChartRendererProps) {
29
29
  const { t } = useLabels();
30
+ const cards = useChartCards();
31
+ if (cards === null) return null;
32
+ const { LineChartCard, BarListCard } = cards;
30
33
  const { chartType, labels, datasets } = data;
31
34
  const itemsOf = (values: number[]) =>
32
35
  labels.map((label, i) => ({ label, value: values[i] || 0 }));
@@ -0,0 +1,34 @@
1
+ import type { BarListCard } from '@oxy.so/bloom/chart-cards/bar-list';
2
+ import type { LineChartCard } from '@oxy.so/bloom/chart-cards/line';
3
+ import { createContext, useContext } from 'react';
4
+
5
+ /**
6
+ * The two Bloom chart cards the conversation draws: a market or FairCoin quote and a generated
7
+ * chart's single line on `LineChartCard`, everything else a chart says on `BarListCard`.
8
+ *
9
+ * Every entry but `@gemies/sdk/ask/lean` brings Bloom's own (`./default-chart-cards`, imported for
10
+ * its effect next to the chat). `@gemies/sdk/ask/lean` brings none, so a host on it hands its own
11
+ * (`chartCards` on the provider): an app that draws the same cards behind an `import()` of its own
12
+ * keeps them out of its first paint instead of sharing them between its chunk and the sheet's.
13
+ */
14
+ export interface GemieChartCards {
15
+ LineChartCard: typeof LineChartCard;
16
+ BarListCard: typeof BarListCard;
17
+ }
18
+
19
+ let defaults: GemieChartCards | null = null;
20
+
21
+ /** Called once by `./default-chart-cards`, the only SDK module that imports the cards. */
22
+ export function provideDefaultChartCards(cards: GemieChartCards): void {
23
+ defaults = cards;
24
+ }
25
+
26
+ const ChartCardsContext = createContext<GemieChartCards | null>(null);
27
+
28
+ /** The host's own cards (`chartCards`), over the entry's default. */
29
+ export const GemieChartCardsProvider = ChartCardsContext.Provider;
30
+
31
+ /** The cards to draw with: the host's, else the entry's default; `null` when there is neither. */
32
+ export function useChartCards(): GemieChartCards | null {
33
+ return useContext(ChartCardsContext) ?? defaults;
34
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Bloom's chart cards as the conversation's default, imported for its effect by every entry that
3
+ * draws the chat except `@gemies/sdk/ask/lean`: the root and `@gemies/sdk/text` with the entry,
4
+ * `@gemies/sdk/ask`, `/ask/eager` and `/ask/text` with their sheet (`GemieAskSheet`). The only SDK
5
+ * module that imports the cards; `scripts/check-entry-isolation.mjs` holds both.
6
+ */
7
+
8
+ import { BarListCard } from '@oxy.so/bloom/chart-cards/bar-list';
9
+ import { LineChartCard } from '@oxy.so/bloom/chart-cards/line';
10
+ import { provideDefaultChartCards } from './chart-cards';
11
+
12
+ provideDefaultChartCards({ LineChartCard, BarListCard });
@@ -0,0 +1,172 @@
1
+ import { Button } from '@oxy.so/bloom/button';
2
+ import { RiArrowDownSLine } from '@oxy.so/bloom/icons/RiArrowDownSLine';
3
+ import { RiArrowRightSLine } from '@oxy.so/bloom/icons/RiArrowRightSLine';
4
+ import { RiFileCopyLine } from '@oxy.so/bloom/icons/RiFileCopyLine';
5
+ import { Item } from '@oxy.so/bloom/item';
6
+ import { createTokenStyles, useTheme } from '@oxy.so/bloom/theme';
7
+ import { Muted, Text } from '@oxy.so/bloom/typography';
8
+ import { View } from 'react-native';
9
+ import { copyText } from '../../lib/clipboard';
10
+ import { useLabels } from '../../lib/labels';
11
+ import { type CallFileChange, patchLines } from '../../runtime/thread/file-changes';
12
+ import type { DiffLayout, GemieFileDiffRenderer } from './diff-renderer';
13
+ import { PatchLines } from './PatchLines';
14
+
15
+ const MARK = { add: 'A', update: 'M', delete: 'D', rename: 'R' } as const;
16
+
17
+ /** `+12 −3`, the way a diff header says how much a file changed. */
18
+ export function DiffStat({ additions, deletions }: { additions: number; deletions: number }) {
19
+ const styles = useStyles();
20
+ const { t } = useLabels();
21
+ return (
22
+ <View
23
+ style={styles.stat}
24
+ accessible
25
+ accessibilityLabel={t('chat.fileChanges.stats', { additions, deletions })}
26
+ >
27
+ {additions > 0 || deletions === 0 ? (
28
+ <Text style={styles.added}>{`+${additions}`}</Text>
29
+ ) : null}
30
+ {deletions > 0 ? <Text style={styles.removed}>{`−${deletions}`}</Text> : null}
31
+ </View>
32
+ );
33
+ }
34
+
35
+ export interface FileChangeSectionProps {
36
+ change: CallFileChange;
37
+ expanded: boolean;
38
+ onToggle: () => void;
39
+ layout: DiffLayout;
40
+ wrap: boolean;
41
+ /** The host's drawing of a patch; the SDK's plain lines when it brought none. */
42
+ renderer: GemieFileDiffRenderer | null;
43
+ }
44
+
45
+ /**
46
+ * One changed file: a header that says what happened to it and how much (`A`/`M`/`D`/`R`, its
47
+ * path, `+X −Y`), copies its path, and folds its patch open or shut. The patch is drawn only while
48
+ * the section is open, so a long list of files costs what the person has opened.
49
+ */
50
+ export function FileChangeSection({
51
+ change,
52
+ expanded,
53
+ onToggle,
54
+ layout,
55
+ wrap,
56
+ renderer,
57
+ }: FileChangeSectionProps) {
58
+ const { t } = useLabels();
59
+ const { isDark, colors } = useTheme();
60
+ const styles = useStyles();
61
+ const Chevron = expanded ? RiArrowDownSLine : RiArrowRightSLine;
62
+ const operation = t(`chat.fileChanges.operation.${change.operation}`);
63
+ const tint = {
64
+ add: colors.success,
65
+ update: colors.warning,
66
+ delete: colors.error,
67
+ rename: colors.info,
68
+ }[change.operation];
69
+
70
+ return (
71
+ <View style={styles.section} testID={`file-change-${change.key}`}>
72
+ <Item
73
+ density="compact"
74
+ leading={
75
+ <Text style={[styles.mark, { color: tint }]} accessibilityLabel={operation}>
76
+ {MARK[change.operation]}
77
+ </Text>
78
+ }
79
+ title={change.path}
80
+ subtitle={
81
+ change.oldPath === undefined
82
+ ? undefined
83
+ : t('chat.fileChanges.renamedFrom', { path: change.oldPath })
84
+ }
85
+ trailing={
86
+ <View style={styles.trailing}>
87
+ <DiffStat additions={change.additions} deletions={change.deletions} />
88
+ <Button
89
+ iconOnly
90
+ size="sm"
91
+ appearance="plain"
92
+ tone="neutral"
93
+ leadingIcon={RiFileCopyLine}
94
+ accessibilityLabel={t('chat.fileChanges.copyPath')}
95
+ onPress={() => {
96
+ void copyText(change.path, t);
97
+ }}
98
+ />
99
+ <Chevron size="sm" fill={colors.textSecondary} />
100
+ </View>
101
+ }
102
+ expanded={expanded}
103
+ onPress={onToggle}
104
+ accessibilityLabel={`${operation}, ${change.path}`}
105
+ />
106
+ {expanded ? (
107
+ <View style={styles.body}>
108
+ <ChangeBody
109
+ change={change}
110
+ layout={layout}
111
+ wrap={wrap}
112
+ renderer={renderer}
113
+ appearance={isDark ? 'dark' : 'light'}
114
+ />
115
+ </View>
116
+ ) : null}
117
+ </View>
118
+ );
119
+ }
120
+
121
+ /** What an open section shows: the patch, or the reason there is none. */
122
+ function ChangeBody({
123
+ change,
124
+ layout,
125
+ wrap,
126
+ renderer,
127
+ appearance,
128
+ }: {
129
+ change: CallFileChange;
130
+ layout: DiffLayout;
131
+ wrap: boolean;
132
+ renderer: GemieFileDiffRenderer | null;
133
+ appearance: 'light' | 'dark';
134
+ }) {
135
+ const { t } = useLabels();
136
+ const styles = useStyles();
137
+ const say = (key: string) => (
138
+ <View style={styles.note}>
139
+ <Muted>{t(key)}</Muted>
140
+ </View>
141
+ );
142
+ if (change.binary) return say('chat.fileChanges.binary');
143
+ if (change.patch === undefined) {
144
+ return say(change.truncated ? 'chat.fileChanges.tooLarge' : 'chat.fileChanges.unrecorded');
145
+ }
146
+ // A patch with headers only: a rename with no edit, an empty file, a changed mode.
147
+ if (change.additions === 0 && change.deletions === 0 && patchLines(change.patch).length === 0) {
148
+ return say('chat.fileChanges.noContent');
149
+ }
150
+ if (renderer === null) return <PatchLines patch={change.patch} wrap={wrap} />;
151
+ const { PatchView } = renderer;
152
+ return (
153
+ <PatchView
154
+ patch={change.patch}
155
+ path={change.path}
156
+ layout={renderer.layouts.includes(layout) ? layout : 'unified'}
157
+ wrap={wrap}
158
+ appearance={appearance}
159
+ />
160
+ );
161
+ }
162
+
163
+ const useStyles = createTokenStyles((t) => ({
164
+ section: { borderTopWidth: 1, borderColor: t.border },
165
+ trailing: { flexDirection: 'row', alignItems: 'center', gap: 6 },
166
+ stat: { flexDirection: 'row', gap: 6 },
167
+ added: { fontSize: 12, fontWeight: 600, color: t.successText },
168
+ removed: { fontSize: 12, fontWeight: 600, color: t.errorText },
169
+ mark: { fontSize: 12, fontWeight: 700, width: 16, textAlign: 'center' },
170
+ body: { paddingBottom: 8 },
171
+ note: { paddingHorizontal: 16, paddingVertical: 12 },
172
+ }));