@useavalon/caelence-agent 0.2.2-canary.6 → 0.2.2-canary.7

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.
@@ -1,6 +1,8 @@
1
+ import { ArrowUDownLeftIcon } from "@phosphor-icons/react/dist/csr/ArrowUDownLeft";
1
2
  import { ArrowUpRightIcon } from "@phosphor-icons/react/dist/csr/ArrowUpRight";
2
3
  import { CaretDownIcon } from "@phosphor-icons/react/dist/csr/CaretDown";
3
4
  import { CheckIcon } from "@phosphor-icons/react/dist/csr/Check";
5
+ import { CircleIcon } from "@phosphor-icons/react/dist/csr/Circle";
4
6
  import { FileIcon } from "@phosphor-icons/react/dist/csr/File";
5
7
  import { FolderSimpleIcon } from "@phosphor-icons/react/dist/csr/FolderSimple";
6
8
  import { GearIcon } from "@phosphor-icons/react/dist/csr/Gear";
@@ -92,17 +94,22 @@ import { FloatNotice } from "./FloatNotice";
92
94
  import { integrationMatches } from "./integration-search";
93
95
  import { LogoMark } from "./LogoMark";
94
96
  import { McpPanel } from "./McpPanel";
97
+ import { PipelineTrack } from "./PipelineTrack";
95
98
  import { PlatformPane } from "./PlatformPane";
96
99
  import { pickerKeyAction, pickerStartIndex, stepIndex } from "./picker-nav";
100
+ import { pipelineProgress } from "./pipeline";
97
101
  import { formatPlatformOutput, isPlatformTool } from "./platform";
98
102
  import {
99
103
  enqueueMessage,
104
+ promoteQueued,
100
105
  type QueuedMessage,
101
106
  removeQueued,
102
107
  setQueuedText,
103
108
  updateQueued,
104
109
  } from "./queue";
105
- import { canvaViewUrl, splitRichText } from "./rich-text";
110
+ import { ReplySources } from "./ReplySources";
111
+ import { canvaViewUrl, looksLikeWebUrl, splitRichText, webHref } from "./rich-text";
112
+ import { ShimmerPhrase } from "./ShimmerPhrase";
106
113
  import { SkillsPanel } from "./SkillsPanel";
107
114
  import { clampMenuPosition } from "./session-menu";
108
115
  import {
@@ -116,6 +123,7 @@ import {
116
123
  import {
117
124
  type FoldEntry,
118
125
  groupTranscriptLines,
126
+ liveStatusPhrases,
119
127
  type ToolLine,
120
128
  thoughtSummary,
121
129
  thoughtTools,
@@ -463,9 +471,10 @@ export function App(): React.ReactElement {
463
471
  suffix?: string;
464
472
  } | null>(null);
465
473
  const [editingQueuedId, setEditingQueuedId] = useState<string | null>(null);
466
- const [integrations, setIntegrations] = useState<PublicIntegration[]>([]);
474
+ const [queueOpen, setQueueOpen] = useState(true);
467
475
  const [notice, setNotice] = useState<{ text: string; id: number } | null>(null);
468
476
  const [attachments, setAttachments] = useState<ComposerAttachment[]>([]);
477
+ const [integrations, setIntegrations] = useState<PublicIntegration[]>([]);
469
478
  const [fileDrag, setFileDrag] = useState(false);
470
479
  const transcriptRef = useRef<HTMLDivElement>(null);
471
480
  const inputRef = useRef<HTMLTextAreaElement>(null);
@@ -549,9 +558,17 @@ export function App(): React.ReactElement {
549
558
 
550
559
  useEffect(() => {
551
560
  if (!bridge) return;
561
+ let cancelled = false;
552
562
  void getIntegrations(bridge)
553
- .then((result) => setIntegrations(result.items))
554
- .catch(() => undefined);
563
+ .then((result) => {
564
+ if (!cancelled) setIntegrations(result.items);
565
+ })
566
+ .catch(() => {
567
+ if (!cancelled) setIntegrations([]);
568
+ });
569
+ return () => {
570
+ cancelled = true;
571
+ };
555
572
  }, [bridge]);
556
573
 
557
574
  useEffect(() => {
@@ -928,6 +945,7 @@ export function App(): React.ReactElement {
928
945
  setView("chat");
929
946
  if (status === "running" || status === "approval" || sendingRef.current) {
930
947
  setQueueSync(enqueueMessage(queueRef.current, toSend, `q-${Date.now()}`, pendingFiles));
948
+ setQueueOpen(true);
931
949
  return;
932
950
  }
933
951
  await sendTurn(toSend, undefined, pendingFiles);
@@ -944,6 +962,20 @@ export function App(): React.ReactElement {
944
962
  takeAttachments,
945
963
  ]);
946
964
 
965
+ const sendQueuedNow = useCallback(
966
+ async (id: string) => {
967
+ const item = queueRef.current.find((row) => row.id === id);
968
+ if (!item || !bridge) return;
969
+ if (status === "running" || status === "approval" || sendingRef.current) {
970
+ setQueueSync(promoteQueued(queueRef.current, id));
971
+ return;
972
+ }
973
+ setQueueSync(removeQueued(queueRef.current, id));
974
+ await sendTurn(item.text, undefined, item.attachments ?? []);
975
+ },
976
+ [bridge, sendTurn, setQueueSync, status],
977
+ );
978
+
947
979
  const stop = useCallback(async () => {
948
980
  if (!bridge) return;
949
981
  await abortTurn(bridge);
@@ -1549,6 +1581,7 @@ export function App(): React.ReactElement {
1549
1581
  <TranscriptLine
1550
1582
  key={line.key}
1551
1583
  line={line}
1584
+ lines={lines}
1552
1585
  bridge={bridge}
1553
1586
  integrations={integrations}
1554
1587
  editing={
@@ -1667,64 +1700,25 @@ export function App(): React.ReactElement {
1667
1700
  <footer className="desk-composer">
1668
1701
  {fileDrag ? <p className="desk-composer__drop">Drop files to attach</p> : null}
1669
1702
  {queue.length > 0 ? (
1670
- <ul className="desk-queue" aria-label="Queued messages">
1671
- {queue.map((item) => (
1672
- <li key={item.id} className="desk-queue-item">
1673
- {editingQueuedId === item.id ? (
1674
- <textarea
1675
- className="cel-input desk-compose-input"
1676
- rows={2}
1677
- value={item.text}
1678
- aria-label="Edit queued message"
1679
- onChange={(event) =>
1680
- setQueueSync(
1681
- setQueuedText(queueRef.current, item.id, event.target.value),
1682
- )
1683
- }
1684
- onKeyDown={(event) => {
1685
- if (event.key === "Enter" && !event.shiftKey) {
1686
- event.preventDefault();
1687
- setQueueSync(updateQueued(queueRef.current, item.id, item.text));
1688
- setEditingQueuedId(null);
1689
- }
1690
- if (event.key === "Escape") {
1691
- event.preventDefault();
1692
- setEditingQueuedId(null);
1693
- }
1694
- }}
1695
- onBlur={() => {
1696
- setQueueSync(updateQueued(queueRef.current, item.id, item.text));
1697
- setEditingQueuedId(null);
1698
- }}
1699
- />
1700
- ) : (
1701
- <div className="desk-queue-copy">
1702
- <AttachmentThumbs items={item.attachments ?? []} />
1703
- {item.text ? (
1704
- <button
1705
- type="button"
1706
- className="desk-queue-text"
1707
- onClick={() => setEditingQueuedId(item.id)}
1708
- >
1709
- {item.text}
1710
- </button>
1711
- ) : null}
1712
- </div>
1713
- )}
1714
- <button
1715
- type="button"
1716
- className="cel-btn cel-btn--quiet cel-btn--compact"
1717
- aria-label="Remove from queue"
1718
- onClick={() => {
1719
- if (editingQueuedId === item.id) setEditingQueuedId(null);
1720
- setQueueSync(removeQueued(queueRef.current, item.id));
1721
- }}
1722
- >
1723
- <XIcon size={16} weight="regular" />
1724
- </button>
1725
- </li>
1726
- ))}
1727
- </ul>
1703
+ <QueuePanel
1704
+ queue={queue}
1705
+ open={queueOpen}
1706
+ editingId={editingQueuedId}
1707
+ onToggle={() => setQueueOpen((current) => !current)}
1708
+ onEdit={setEditingQueuedId}
1709
+ onChangeText={(id, text) =>
1710
+ setQueueSync(setQueuedText(queueRef.current, id, text))
1711
+ }
1712
+ onCommitText={(id, text) => {
1713
+ setQueueSync(updateQueued(queueRef.current, id, text));
1714
+ setEditingQueuedId(null);
1715
+ }}
1716
+ onSendNow={(id) => void sendQueuedNow(id)}
1717
+ onRemove={(id) => {
1718
+ if (editingQueuedId === id) setEditingQueuedId(null);
1719
+ setQueueSync(removeQueued(queueRef.current, id));
1720
+ }}
1721
+ />
1728
1722
  ) : null}
1729
1723
  {mediaModels.length > 0 && mediaOpen ? (
1730
1724
  <section className="desk-composer__meta">
@@ -2369,6 +2363,121 @@ function SettingsPanel(
2369
2363
  );
2370
2364
  }
2371
2365
 
2366
+ function QueuePanel(
2367
+ props: Readonly<{
2368
+ queue: QueuedMessage[];
2369
+ open: boolean;
2370
+ editingId: string | null;
2371
+ onToggle: () => void;
2372
+ onEdit: (id: string | null) => void;
2373
+ onChangeText: (id: string, text: string) => void;
2374
+ onCommitText: (id: string, text: string) => void;
2375
+ onSendNow: (id: string) => void;
2376
+ onRemove: (id: string) => void;
2377
+ }>,
2378
+ ): React.ReactElement {
2379
+ const editRef = useRef<HTMLTextAreaElement>(null);
2380
+ const count = props.queue.length;
2381
+ const title = count === 1 ? "1 queued message" : `${count} queued messages`;
2382
+ useEffect(() => {
2383
+ if (props.editingId) editRef.current?.focus();
2384
+ }, [props.editingId]);
2385
+ return (
2386
+ <section className="desk-queue">
2387
+ <button
2388
+ type="button"
2389
+ className="desk-queue__head"
2390
+ aria-expanded={props.open}
2391
+ onClick={props.onToggle}
2392
+ >
2393
+ <CaretDownIcon className="desk-queue__caret" size={12} weight="bold" aria-hidden="true" />
2394
+ {title}
2395
+ </button>
2396
+ {props.open ? (
2397
+ <ul className="desk-queue__list">
2398
+ {props.queue.map((item) => {
2399
+ const editing = props.editingId === item.id;
2400
+ return (
2401
+ <li key={item.id} className={`desk-queue-item${editing ? " is-editing" : ""}`}>
2402
+ <button
2403
+ type="button"
2404
+ className="desk-queue__pick"
2405
+ aria-label="Send now"
2406
+ onClick={() => props.onSendNow(item.id)}
2407
+ >
2408
+ <CircleIcon size={16} weight="regular" aria-hidden="true" />
2409
+ </button>
2410
+ {editing ? (
2411
+ <textarea
2412
+ ref={editRef}
2413
+ className="cel-input desk-compose-input desk-queue__input"
2414
+ rows={2}
2415
+ value={item.text}
2416
+ aria-label="Edit queued message"
2417
+ onChange={(event) => props.onChangeText(item.id, event.target.value)}
2418
+ onKeyDown={(event) => {
2419
+ if (event.key === "Enter" && !event.shiftKey) {
2420
+ event.preventDefault();
2421
+ props.onCommitText(item.id, item.text);
2422
+ }
2423
+ if (event.key === "Escape") {
2424
+ event.preventDefault();
2425
+ props.onEdit(null);
2426
+ }
2427
+ }}
2428
+ onBlur={() => props.onCommitText(item.id, item.text)}
2429
+ />
2430
+ ) : (
2431
+ <div className="desk-queue-copy">
2432
+ <AttachmentThumbs items={item.attachments ?? []} />
2433
+ {item.text ? (
2434
+ <button
2435
+ type="button"
2436
+ className="desk-queue-text"
2437
+ onClick={() => props.onEdit(item.id)}
2438
+ >
2439
+ {item.text}
2440
+ </button>
2441
+ ) : null}
2442
+ </div>
2443
+ )}
2444
+ {editing ? null : (
2445
+ <div className="desk-queue__actions">
2446
+ <button
2447
+ type="button"
2448
+ className="desk-queue__act"
2449
+ onClick={() => props.onSendNow(item.id)}
2450
+ >
2451
+ Send now
2452
+ <ArrowUDownLeftIcon size={12} weight="bold" aria-hidden="true" />
2453
+ </button>
2454
+ <button
2455
+ type="button"
2456
+ className="desk-queue__icon"
2457
+ aria-label="Edit queued message"
2458
+ onClick={() => props.onEdit(item.id)}
2459
+ >
2460
+ <PencilSimpleIcon size={14} weight="regular" />
2461
+ </button>
2462
+ <button
2463
+ type="button"
2464
+ className="desk-queue__icon"
2465
+ aria-label="Remove from queue"
2466
+ onClick={() => props.onRemove(item.id)}
2467
+ >
2468
+ <TrashIcon size={14} weight="regular" />
2469
+ </button>
2470
+ </div>
2471
+ )}
2472
+ </li>
2473
+ );
2474
+ })}
2475
+ </ul>
2476
+ ) : null}
2477
+ </section>
2478
+ );
2479
+ }
2480
+
2372
2481
  function ThoughtFold(
2373
2482
  props: Readonly<{
2374
2483
  entries: FoldEntry[];
@@ -2376,32 +2485,33 @@ function ThoughtFold(
2376
2485
  warmupSeed?: number;
2377
2486
  }>,
2378
2487
  ): React.ReactElement {
2379
- const { entries, live, warmupSeed } = props;
2488
+ const { entries, live } = props;
2380
2489
  const tools = thoughtTools(entries);
2381
2490
  const summary = thoughtSummary(tools, live, {
2382
2491
  warmup: entries.length === 0,
2383
- seed: warmupSeed ?? 0,
2492
+ seed: props.warmupSeed ?? 0,
2384
2493
  });
2494
+ const phrases = live ? liveStatusPhrases(tools, entries.length === 0) : [summary.headline];
2495
+ const pipe = live ? pipelineProgress(tools) : undefined;
2385
2496
  const hasBody = entries.some((entry) =>
2386
2497
  entry.type === "note" ? entry.text.trim().length > 0 : true,
2387
2498
  );
2499
+ const headline = (
2500
+ <span className="desk-thought__copy">
2501
+ <span className="desk-thought__headline">
2502
+ <ShimmerPhrase phrases={phrases} live={live} tone={pipe ? "pipe" : undefined} />
2503
+ </span>
2504
+ {pipe ? <PipelineTrack steps={pipe.steps} /> : null}
2505
+ </span>
2506
+ );
2388
2507
  if (!hasBody) {
2389
2508
  return (
2390
- <p className="desk-thought desk-thought--plain">
2391
- <span className="desk-thought__headline">{summary.headline}</span>
2392
- </p>
2509
+ <p className={`desk-thought desk-thought--plain${pipe ? " is-pipe" : ""}`}>{headline}</p>
2393
2510
  );
2394
2511
  }
2395
2512
  return (
2396
- <details className="desk-thought">
2397
- <summary>
2398
- <span className="desk-thought__copy">
2399
- <span className="desk-thought__headline">{summary.headline}</span>
2400
- {live && summary.activity ? (
2401
- <span className="desk-thought__activity">{summary.activity}</span>
2402
- ) : null}
2403
- </span>
2404
- </summary>
2513
+ <details className={`desk-thought${pipe ? " is-pipe" : ""}`}>
2514
+ <summary>{headline}</summary>
2405
2515
  <div className="desk-thought__body">
2406
2516
  {entries.map((entry) => {
2407
2517
  if (entry.type === "note") {
@@ -2525,7 +2635,9 @@ function UserTranscriptLine(
2525
2635
  function TranscriptLine(
2526
2636
  props: Readonly<{
2527
2637
  line: StreamLine;
2638
+ lines: StreamLine[];
2528
2639
  bridge: BridgeClient | null;
2640
+ integrations: PublicIntegration[];
2529
2641
  editing?: string | null;
2530
2642
  onStartEdit?: () => void;
2531
2643
  onEditChange?: (text: string) => void;
@@ -2533,7 +2645,6 @@ function TranscriptLine(
2533
2645
  onEditCancel?: () => void;
2534
2646
  onOpenUrl?: (url: string) => void;
2535
2647
  onOpenFile?: (path: string, reveal: boolean) => void;
2536
- integrations?: PublicIntegration[];
2537
2648
  }>,
2538
2649
  ): React.ReactElement {
2539
2650
  const { line, bridge, onOpenUrl, onOpenFile } = props;
@@ -2560,6 +2671,13 @@ function TranscriptLine(
2560
2671
  onOpenUrl={onOpenUrl}
2561
2672
  onOpenFile={onOpenFile}
2562
2673
  />
2674
+ <ReplySources
2675
+ lines={props.lines}
2676
+ assistantKey={line.key}
2677
+ bridge={bridge}
2678
+ onOpenUrl={onOpenUrl}
2679
+ onOpenFile={onOpenFile}
2680
+ />
2563
2681
  </div>
2564
2682
  </article>
2565
2683
  );
@@ -2568,7 +2686,7 @@ function TranscriptLine(
2568
2686
  if (isPlatformTool(line.name)) {
2569
2687
  const body = formatPlatformOutput(line.output ?? "");
2570
2688
  return (
2571
- <PlatformPane line={line} integrations={props.integrations ?? []}>
2689
+ <PlatformPane line={line} integrations={props.integrations}>
2572
2690
  {body ? (
2573
2691
  <RichBody text={body} bridge={bridge} onOpenUrl={onOpenUrl} onOpenFile={onOpenFile} />
2574
2692
  ) : null}
@@ -2650,6 +2768,7 @@ function RichBody(
2650
2768
  path={part.path}
2651
2769
  label={part.label}
2652
2770
  onOpenFile={props.onOpenFile}
2771
+ onOpenUrl={props.onOpenUrl}
2653
2772
  />
2654
2773
  );
2655
2774
  }
@@ -2689,8 +2808,14 @@ function FileLink(
2689
2808
  path: string;
2690
2809
  label: string;
2691
2810
  onOpenFile?: (path: string, reveal: boolean) => void;
2811
+ onOpenUrl?: (url: string) => void;
2692
2812
  }>,
2693
2813
  ): React.ReactElement {
2814
+ if (looksLikeWebUrl(props.path)) {
2815
+ return (
2816
+ <ExternalLink href={webHref(props.path)} label={props.label} onOpenUrl={props.onOpenUrl} />
2817
+ );
2818
+ }
2694
2819
  return (
2695
2820
  <span className="desk-file">
2696
2821
  <button
@@ -0,0 +1,19 @@
1
+ import type { ReactElement } from "react";
2
+ import type { PipeStep } from "./pipeline";
3
+
4
+ export function PipelineTrack(
5
+ props: Readonly<{ steps: readonly PipeStep[] }>,
6
+ ): ReactElement | null {
7
+ if (props.steps.length === 0) return null;
8
+ const label = props.steps.map((step) => step.label).join(", ");
9
+ return (
10
+ <div className="desk-pipe" role="img" aria-label={label}>
11
+ {props.steps.map((step, index) => (
12
+ <span key={step.id} className={`desk-pipe__unit is-${step.status}`}>
13
+ {index > 0 ? <span className="desk-pipe__seg" aria-hidden="true" /> : null}
14
+ <span className="desk-pipe__dot" aria-hidden="true" />
15
+ </span>
16
+ ))}
17
+ </div>
18
+ );
19
+ }