@fungi.computer/parakeet 0.9.1 → 0.10.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/README.md CHANGED
@@ -16,13 +16,12 @@ message; the visitor mode does not register or execute slash commands.
16
16
 
17
17
  ## Set up
18
18
 
19
- Install `@fungi.computer/parakeet` from its package tarball. It requires a
20
- compatible React and React DOM pair, TanStack Query and an authorized Session
21
- supplied by the host. The manifest supports React 18.2 or 19.2 and later within
22
- those major versions. Build the dependency closure from the repository root:
19
+ Install `@fungi.computer/parakeet` from npm. It requires a compatible React and
20
+ React DOM pair, TanStack Query and an authorized Session supplied by the host.
21
+ The manifest supports React 18.2 or 19.2 and later within those major versions.
23
22
 
24
23
  ```sh
25
- pnpm turbo:run run build --filter=@fungi.computer/parakeet
24
+ npm install @fungi.computer/parakeet react react-dom @tanstack/react-query
26
25
  ```
27
26
 
28
27
  Browser hosts import `@fungi.computer/parakeet/styles.css` once. It includes the
@@ -15,6 +15,8 @@ export type ChatComposerProps = {
15
15
  queuedRecall: Pick<ComposerController, "recall" | "recallState" | "images"> | undefined;
16
16
  /** Caller-owned prompt hint; omitted for the ordinary Session composer. */
17
17
  placeholder?: string | undefined;
18
+ /** Why typing cannot work yet, such as no model connected. It disables input and sending, and replaces the hint. */
19
+ disabledReason?: string | undefined;
18
20
  /** Hide internal model, usage and status readouts for visitors. */
19
21
  showFooter?: boolean;
20
22
  /** Display-only status text supplied by the conversation's admitted entries. */
@@ -63,7 +63,7 @@ const presentations = {
63
63
  tone: "neutral",
64
64
  },
65
65
  };
66
- function HostComposerTextarea({ placeholder, onChange, onSend, onAbort, slash, slashListId, textareaId, textareaRef, value, queuedRecall, }) {
66
+ function HostComposerTextarea({ disabledReason, placeholder, onChange, onSend, onAbort, slash, slashListId, textareaId, textareaRef, value, queuedRecall, }) {
67
67
  const latestValue = useRef(value);
68
68
  const [history, setHistory] = useState([]);
69
69
  const [historyIndex, setHistoryIndex] = useState(-1);
@@ -197,7 +197,7 @@ function HostComposerTextarea({ placeholder, onChange, onSend, onAbort, slash, s
197
197
  : `${textareaId}-recall-guidance`,
198
198
  ]
199
199
  .filter((id) => id !== undefined)
200
- .join(" ") || undefined, "aria-busy": recalling, readOnly: recalling, ...(slash === undefined
200
+ .join(" ") || undefined, "aria-busy": recalling, disabled: disabledReason !== undefined, readOnly: recalling, ...(slash === undefined
201
201
  ? {}
202
202
  : completionFieldProps({
203
203
  open: listOpen,
@@ -206,7 +206,8 @@ function HostComposerTextarea({ placeholder, onChange, onSend, onAbort, slash, s
206
206
  })), className: "font-sans text-base-content", id: textareaId, onChange: (event) => {
207
207
  onChange(event.target.value);
208
208
  setHistoryIndex(-1);
209
- }, onKeyDown: onKeyDown, placeholder: placeholder ??
209
+ }, onKeyDown: onKeyDown, placeholder: disabledReason ??
210
+ placeholder ??
210
211
  (slash === undefined ? "Ask agent..." : "Ask agent… (/ for commands)"), ref: textareaRef, rows: 1, value: value }), queuedRecall === undefined ? null : (_jsx("span", { id: `${textareaId}-recall-guidance`, className: "sr-only", children: "Press Up on an empty composer to recall your newest queued message." }))] }));
211
212
  }
212
213
  /** Full Session readout for announcements; the footer only draws attention states. */
@@ -318,7 +319,7 @@ function ComposerAttachments({ images, onRemove, }) {
318
319
  onRemove(index);
319
320
  }, size: "xs", variant: "outline" }))] }, index))) }));
320
321
  }
321
- export const ChatComposer = memo(function ChatComposer({ queuedRecall, onImagesChange, placeholder, showFooter = true, statusChips, actionVariant = "primary", draft, failure, failureCause, admissionError, model, onAbort, onChange, onRetry, onSend, status, viewState, textareaRef, usage, context, slash, }) {
322
+ export const ChatComposer = memo(function ChatComposer({ queuedRecall, onImagesChange, placeholder, disabledReason, showFooter = true, statusChips, actionVariant = "primary", draft, failure, failureCause, admissionError, model, onAbort, onChange, onRetry, onSend, status, viewState, textareaRef, usage, context, slash, }) {
322
323
  const textareaId = useId();
323
324
  const slashListId = `${textareaId}-commands`;
324
325
  const fileInput = useRef(null);
@@ -353,8 +354,9 @@ export const ChatComposer = memo(function ChatComposer({ queuedRecall, onImagesC
353
354
  blocked: recallBusy,
354
355
  });
355
356
  const sendLabel = busy ? "Queue follow-up" : "Send message";
356
- const sendAction = (_jsx(SendAction, { "aria-label": sendLabel, className: "composer-send-key", disabled: sendState === "busy" &&
357
- (recallBusy || status === "queued" || status === "cancelling"), onClick: () => {
357
+ const sendAction = (_jsx(SendAction, { "aria-label": sendLabel, className: "composer-send-key", disabled: disabledReason !== undefined ||
358
+ (sendState === "busy" &&
359
+ (recallBusy || status === "queued" || status === "cancelling")), onClick: () => {
358
360
  onSend(busy ? "followUp" : "steer");
359
361
  }, onStop: onAbort, state: sendState, stopLabel: "Stop current turn", title: sendState === "busy"
360
362
  ? "Stop the current turn. Queued messages keep running in order."
@@ -392,7 +394,7 @@ export const ChatComposer = memo(function ChatComposer({ queuedRecall, onImagesC
392
394
  onImagesChange(images.filter((_image, at) => at !== index));
393
395
  } })) : undefined, input: _jsxs(_Fragment, { children: [takeover === undefined || slash === undefined ? null : (_jsx(DecisionComposer, { item: takeover, position: slash.awaiting.position, total: slash.awaiting.total, onLater: () => {
394
396
  slash.store.awaiting.later(takeover.key);
395
- }, takeFocus: hadFocus.current }, takeover.key)), _jsx("div", { hidden: takeover !== undefined, children: _jsx(HostComposerTextarea, { queuedRecall: queuedRecall, placeholder: placeholder, onChange: onChange, onAbort: onAbort, onSend: () => {
397
+ }, takeFocus: hadFocus.current }, takeover.key)), _jsx("div", { hidden: takeover !== undefined, children: _jsx(HostComposerTextarea, { disabledReason: disabledReason, queuedRecall: queuedRecall, placeholder: placeholder, onChange: onChange, onAbort: onAbort, onSend: () => {
396
398
  onSend(busy ? "followUp" : "steer");
397
399
  }, slash: slash, slashListId: slashListId, textareaId: textareaId, textareaRef: textareaRef, value: draft }) })] }), row:
398
400
  // A decision brings its own Later and Send row to the bottom edge.
@@ -4,4 +4,4 @@ export declare function RunFailureNotice({ failure, cause, onRetry, }: Readonly<
4
4
  failure: NonNullable<ComposerController["failure"]>;
5
5
  cause?: string | undefined;
6
6
  onRetry: () => void;
7
- }>): import("react/jsx-runtime").JSX.Element;
7
+ }>): import("react/jsx-runtime").JSX.Element | null;
@@ -1,7 +1,9 @@
1
- import { Fragment as _Fragment, jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
- import { Alert } from "@fungi.computer/caps/components/alert";
3
- import { Button } from "@fungi.computer/caps/components/button";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { SetupNotice } from "@fungi.computer/caps/blocks/setup-notice";
3
+ import { FailureLine } from "@fungi.computer/caps/components/failure-line";
4
4
  import { boundedDiagnostic } from "@fungi.computer/bird-dog/effect";
5
+ import { useContext } from "react";
6
+ import { ParakeetHostFactsContext } from "../host-facts.js";
5
7
  const messages = {
6
8
  admission: "Your prompt didn’t make it through. Let’s give it another go.",
7
9
  failed: "The run stopped. Check the message above before trying again.",
@@ -10,6 +12,12 @@ const messages = {
10
12
  };
11
13
  /** Session failures do not carry a billing receipt; never promise a refund. */
12
14
  export function RunFailureNotice({ failure, cause, onRetry, }) {
15
+ const { billing = true, modelSetup } = useContext(ParakeetHostFactsContext);
16
+ // With no model connected the timeline already says so, once, with the fix.
17
+ if (failure === "failed" && modelSetup?.state === "missing")
18
+ return null;
19
+ if (failure === "admission" && modelSetup?.state === "missing")
20
+ return (_jsx(SetupNotice, { cause: "No model is connected to this workspace.", fix: modelSetup.fix, need: "No model could answer", variant: "inline" }));
13
21
  const bounded = cause === undefined ? undefined : boundedDiagnostic(cause);
14
22
  // Diagnostic metadata is useful to the owner, not a public explanation.
15
23
  const publicCause = bounded !== undefined &&
@@ -18,5 +26,13 @@ export function RunFailureNotice({ failure, cause, onRetry, }) {
18
26
  ? bounded
19
27
  : undefined;
20
28
  const interruptedWithReason = failure === "interrupted" && publicCause !== undefined;
21
- return (_jsx(Alert, { tone: "warning", title: failure === "cancelled" ? "Taking a breather" : "A little tangle", description: interruptedWithReason ? (_jsxs(_Fragment, { children: ["This turn stopped before it finished: ", publicCause, ". Your prompt is still here."] })) : (_jsxs(_Fragment, { children: [messages[failure], " If the model didn\u2019t start, there\u2019s no charge. Model work already done can still use credits.", publicCause ? _jsx("span", { className: "block", children: publicCause }) : null] })), action: failure === "cancelled" ? undefined : (_jsx(Button, { "aria-label": "Retry prompt", variant: "outline", onClick: onRetry, children: "Retry" })) }));
29
+ const credits = billing
30
+ ? " If the model didn’t start, there’s no charge. Model work already done can still use credits."
31
+ : "";
32
+ const message = interruptedWithReason
33
+ ? `This turn stopped before it finished: ${publicCause}. Your prompt is still here.`
34
+ : `${messages[failure]}${credits}${publicCause ? ` ${publicCause}` : ""}`;
35
+ return (_jsx(FailureLine, { message: message, role: "alert", ...(failure === "cancelled"
36
+ ? {}
37
+ : { onRetry, retryAriaLabel: "Retry prompt" }) }));
22
38
  }
@@ -1,10 +1,13 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { Sigil } from "@fungi.computer/sigils";
3
3
  import { Button } from "@fungi.computer/caps/components/button";
4
- import { memo } from "react";
4
+ import { memo, useContext } from "react";
5
5
  import { disclosureOpen, initialToolDisclosure, } from "../core/tool-groups.js";
6
6
  import { assistantMessageVisible } from "../core/assistant-visibility.js";
7
7
  import { formatTokenCount } from "../core/format-context.js";
8
+ import { SetupNotice } from "@fungi.computer/caps/blocks/setup-notice";
9
+ import { FailureLine } from "@fungi.computer/caps/components/failure-line";
10
+ import { ParakeetHostFactsContext, plainModelFailure } from "../host-facts.js";
8
11
  import { ChatMessage, PendingMessageStatus } from "./ChatMessage.js";
9
12
  import { ToolGroup } from "./ToolGroup.js";
10
13
  const ignoreToggle = () => undefined;
@@ -15,6 +18,7 @@ const compactionNoticeLabel = {
15
18
  insufficient: "compaction skipped: the summary would not fit",
16
19
  };
17
20
  export const TimelineItem = memo(function TimelineItem({ item, onDismissFailed, onCancelQueued, cancellingQueued = false, renderToolActions, claimsToolMedia, renderAssistantAttachment, formatAssistantText, toolDisclosure = initialToolDisclosure, onToggleTool = ignoreToggle, }) {
21
+ const facts = useContext(ParakeetHostFactsContext);
18
22
  switch (item.kind) {
19
23
  case "user_message": {
20
24
  const pending = item.status === "pending" || item.status === "queued";
@@ -41,12 +45,21 @@ export const TimelineItem = memo(function TimelineItem({ item, onDismissFailed,
41
45
  }
42
46
  return (_jsxs(_Fragment, { children: [item.author ? (_jsx("div", { className: "px-3 text-xs text-dim", "data-author": item.author.id, children: item.author.name })) : null, _jsx(ChatMessage, { pending: pending, speaker: "user", children: item.text }), failed, cancelAction] }));
43
47
  }
44
- case "assistant_message":
48
+ case "assistant_message": {
45
49
  if (!assistantMessageVisible(item))
46
50
  return null;
51
+ const modelFailure = item.isError
52
+ ? plainModelFailure(item.text)
53
+ : undefined;
54
+ if (modelFailure !== undefined) {
55
+ // One line per run of identical failures, never the raw code.
56
+ return modelFailure.unreachable &&
57
+ facts.modelSetup?.state === "missing" ? (_jsx(SetupNotice, { cause: "No model is connected to this workspace.", fix: facts.modelSetup.fix, need: "No model could answer", variant: "inline" })) : (_jsx(FailureLine, { count: item.repeatCount ?? 1, message: modelFailure.message }));
58
+ }
47
59
  return (_jsxs(_Fragment, { children: [item.author ? (_jsx("div", { className: "px-3 text-xs text-dim", "data-author": item.author.id, children: item.author.name })) : null, _jsx(ChatMessage, { isError: item.isError === true, pending: item.pending, speaker: "agent", ...(item.thinking ? { thinking: item.thinking } : {}), children: formatAssistantText?.(item.text) ?? item.text }), item.isError && item.repeatCount !== undefined ? (_jsxs("span", { className: "px-3 text-error", children: ["x", item.repeatCount] })) : null, item.isError && item.errorDetail ? (_jsx("p", { className: "px-3 text-dim", children: item.errorDetail })) : null, item.isError && item.providerError !== undefined ? (_jsx("div", { className: "px-3 text-error", "data-provider-error": item.id, children: _jsxs("details", { children: [_jsx("summary", { children: "Provider details (latest response)" }), _jsx("pre", { className: "whitespace-pre-wrap", children: item.providerError })] }) })) : null, !item.pending && !item.isError
48
60
  ? renderAssistantAttachment?.(item.text)
49
61
  : null] }));
62
+ }
50
63
  case "tool_group":
51
64
  return (_jsx(ToolGroup, { disclosure: toolDisclosure, group: item, onToggle: onToggleTool, renderToolActions: renderToolActions, claimsToolMedia: claimsToolMedia }));
52
65
  case "compaction_divider":
@@ -129,8 +129,9 @@ function collapseProviderErrors(rows, breakBefore) {
129
129
  row.isError &&
130
130
  prior?.kind === "assistant_message" &&
131
131
  prior.isError &&
132
- row.providerError !== undefined &&
133
- prior.providerError !== undefined &&
132
+ // Error-only turns repeat too: a provider detail is not required to fold.
133
+ (row.providerError === undefined) ===
134
+ (prior.providerError === undefined) &&
134
135
  row.text === prior.text &&
135
136
  row.errorDetail === prior.errorDetail &&
136
137
  row.thinking === prior.thinking &&
@@ -140,7 +141,9 @@ function collapseProviderErrors(rows, breakBefore) {
140
141
  ...prior,
141
142
  repeatCount: (prior.repeatCount ?? 1) + 1,
142
143
  // Details show the latest response, including its request id.
143
- providerError: row.providerError,
144
+ ...(row.providerError !== undefined && {
145
+ providerError: row.providerError,
146
+ }),
144
147
  };
145
148
  aliases.set(row.id, prior.id);
146
149
  }
@@ -0,0 +1,35 @@
1
+ /** Whether a model is connected, with the one fix the host offers. */
2
+ export type ParakeetModelSetup = Readonly<{
3
+ /** `missing` turns a model failure into the setup notice; `unknown` leaves it a failure. */
4
+ state: "ready" | "missing" | "unknown";
5
+ /** Opens the host's model setup, such as Keys. Required: a notice never has a dead button. */
6
+ fix: Readonly<{
7
+ /** The button text, such as "Add a model key". */
8
+ label: string;
9
+ /** Called when the person chooses it. */
10
+ onSelect: () => void;
11
+ }>;
12
+ }>;
13
+ /** What the host knows that the conversation needs to speak plainly. */
14
+ export type ParakeetHostFacts = Readonly<{
15
+ /** Absent means unknown: failures show as failures, never as setup. */
16
+ modelSetup?: ParakeetModelSetup | undefined;
17
+ /** False when the host has no billing, so no sentence promises or denies credits. Default true. */
18
+ billing?: boolean | undefined;
19
+ /** One-click prompts the empty conversation offers; each sends as written. */
20
+ starters?: readonly string[] | undefined;
21
+ }>;
22
+ /** Provided by the conversation view; read by the failure and empty states. */
23
+ export declare const ParakeetHostFactsContext: import("react").Context<Readonly<{
24
+ /** Absent means unknown: failures show as failures, never as setup. */
25
+ modelSetup?: ParakeetModelSetup | undefined;
26
+ /** False when the host has no billing, so no sentence promises or denies credits. Default true. */
27
+ billing?: boolean | undefined;
28
+ /** One-click prompts the empty conversation offers; each sends as written. */
29
+ starters?: readonly string[] | undefined;
30
+ }>>;
31
+ /** A model run that failed, with the plain sentence for its cause; undefined for any other text. */
32
+ export declare function plainModelFailure(text: string): Readonly<{
33
+ unreachable: boolean;
34
+ message: string;
35
+ }> | undefined;
@@ -0,0 +1,16 @@
1
+ import { createContext } from "react";
2
+ /** Provided by the conversation view; read by the failure and empty states. */
3
+ export const ParakeetHostFactsContext = createContext({});
4
+ const modelFailure = /^Model request failed \(([a-z_]+)\)\./u;
5
+ /** A model run that failed, with the plain sentence for its cause; undefined for any other text. */
6
+ export function plainModelFailure(text) {
7
+ const code = modelFailure.exec(text)?.[1];
8
+ if (code === undefined)
9
+ return undefined;
10
+ return code === "provider_unavailable" || code === "setup_required"
11
+ ? {
12
+ unreachable: true,
13
+ message: "The model provider couldn't be reached. Try again.",
14
+ }
15
+ : { unreachable: false, message: "The model request failed. Try again." };
16
+ }
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export type { ParakeetVisitor } from "./parakeet.js";
7
7
  export { InteractionPanel, type InteractionPanelProps, } from "./components/InteractionPanel.js";
8
8
  export type { QueuedRecallState, QueuedRecallOutcome, ParakeetAssistantMessageItem, ComposerController, ParakeetDraftCheckpoint, ParakeetDraftIdentity, ParakeetDraftStorage, ParakeetModel, ParakeetSession, ParakeetStatus, ParakeetTimelineItem, ParakeetToolArguments, ParakeetToolCallSection, ParakeetToolCallView, ParakeetToolDiffFile, ParakeetToolDiffHunk, ParakeetToolDiffLine, ParakeetToolDiffRow, ParakeetToolExcerptLine, ParakeetToolMatch, ParakeetToolOutputLine, ParakeetToolGroupItem, ParakeetToolItem, ParakeetToolKind, ToolDisclosureState, ParakeetUsage, ParakeetUserMessageItem, StatusController, TimelineController, MarkdownBlock, MarkdownInline, } from "./headless.js";
9
9
  export type { ParakeetProps, ParakeetViewProps } from "./parakeet.js";
10
+ export type { ParakeetHostFacts, ParakeetModelSetup } from "./host-facts.js";
10
11
  export type { ParakeetAuthor, ParakeetAuthorOf } from "./core/author-labels.js";
11
12
  export type { ParakeetSessionCommand, ParakeetPromptResult, } from "./session.js";
12
13
  export * from "./agent-head.js";
@@ -1,4 +1,5 @@
1
1
  import type { ClientEntryV1 } from "@fungi.computer/shiitake/client-entry";
2
+ import { type ParakeetHostFacts } from "./host-facts.js";
2
3
  import { type ReactElement, type ReactNode } from "react";
3
4
  import { type ParakeetAuthorOf } from "./core/author-labels.js";
4
5
  import type { ToolItem } from "./store/types.js";
@@ -43,6 +44,8 @@ export type ParakeetProps = Readonly<{
43
44
  onOpen?: ((target: NonNullable<RowV1["open"]>) => void) | undefined;
44
45
  /** Optional caller-owned empty conversation state. */
45
46
  empty?: ReactNode | undefined;
47
+ /** What the host knows: model setup, billing and starter prompts. */
48
+ hostFacts?: ParakeetHostFacts | undefined;
46
49
  /** Optional host Whistle runtime; Parakeet makes its own when omitted. */
47
50
  commands?: ParakeetCommandRuntime | undefined;
48
51
  }>;
@@ -68,6 +71,8 @@ export type ParakeetViewProps = Readonly<{
68
71
  onOpen?: ((target: NonNullable<RowV1["open"]>) => void) | undefined;
69
72
  /** Optional caller-owned empty conversation state. */
70
73
  empty?: ReactNode | undefined;
74
+ /** What the host knows: model setup, billing and starter prompts. */
75
+ hostFacts?: ParakeetHostFacts | undefined;
71
76
  /**
72
77
  * Optional host Whistle runtime holding the host's own commands. Parakeet
73
78
  * adds its built-ins and the Session's advertised commands to it, and makes
@@ -76,6 +81,6 @@ export type ParakeetViewProps = Readonly<{
76
81
  commands?: ParakeetCommandRuntime | undefined;
77
82
  }>;
78
83
  /** Render the retained conversation surface within one Parakeet provider. */
79
- export declare function ParakeetView({ disambiguateAuthors, visitor, composerActionVariant, empty, commands, renderToolActions, claimsToolMedia, renderAssistantAttachment, formatAssistantText, onLink, onOpen, }: ParakeetViewProps): ReactElement;
84
+ export declare function ParakeetView({ disambiguateAuthors, visitor, composerActionVariant, empty, hostFacts, commands, renderToolActions, claimsToolMedia, renderAssistantAttachment, formatAssistantText, onLink, onOpen, }: ParakeetViewProps): ReactElement;
80
85
  /** Standalone typed composer and exact-message timeline. */
81
- export declare function Parakeet({ authorOf, disambiguateAuthors, visitor, markdownPolicy, composerActionVariant, empty, session, clients, renderToolActions, claimsToolMedia, renderAssistantAttachment, formatAssistantText, commands, onLink, onOpen, }: ParakeetProps): ReactElement;
86
+ export declare function Parakeet({ authorOf, disambiguateAuthors, visitor, markdownPolicy, composerActionVariant, empty, hostFacts, session, clients, renderToolActions, claimsToolMedia, renderAssistantAttachment, formatAssistantText, commands, onLink, onOpen, }: ParakeetProps): ReactElement;
package/dist/parakeet.js CHANGED
@@ -1,10 +1,13 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { Button } from "@fungi.computer/caps/components/button";
3
+ import { SetupNotice } from "@fungi.computer/caps/blocks/setup-notice";
4
+ import { EmptyState } from "@fungi.computer/caps/blocks/empty-state";
5
+ import { ParakeetHostFactsContext, } from "./host-facts.js";
3
6
  import { Dialog, DialogContent } from "@fungi.computer/caps/components/dialog";
4
7
  import { ScrollToBottomBlob } from "@fungi.computer/caps/components/scroll-to-bottom-blob";
5
8
  import { createWhistle } from "@fungi.computer/whistle";
6
9
  import { useVirtualizer } from "@tanstack/react-virtual";
7
- import { useCallback, useEffect, useMemo, useRef, useState, } from "react";
10
+ import { useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
8
11
  import { ParakeetProvider, useComposer, useClientContributions, useDismissFailedPrompt, useStatus, useTimeline, } from "./conversation.js";
9
12
  import { awaitingTakeover } from "./core/awaiting-answer.js";
10
13
  import { initialToolDisclosure, toggleDisclosure } from "./core/tool-groups.js";
@@ -19,7 +22,7 @@ import { useSlashCommands, } from "./commands/use-slash-commands.js";
19
22
  import { TimelineItem } from "./components/TimelineItem.js";
20
23
  import { MarkdownPolicyContext } from "./components/MarkdownRenderer.js";
21
24
  /** Render the retained conversation surface within one Parakeet provider. */
22
- export function ParakeetView({ disambiguateAuthors, visitor, composerActionVariant, empty, commands, renderToolActions, claimsToolMedia, renderAssistantAttachment, formatAssistantText, onLink, onOpen, }) {
25
+ export function ParakeetView({ disambiguateAuthors, visitor, composerActionVariant, empty, hostFacts, commands, renderToolActions, claimsToolMedia, renderAssistantAttachment, formatAssistantText, onLink, onOpen, }) {
23
26
  const textareaRef = useRef(null);
24
27
  const [ownCommands] = useState(() => createWhistle());
25
28
  const slash = useSlashCommands({
@@ -40,46 +43,47 @@ export function ParakeetView({ disambiguateAuthors, visitor, composerActionVaria
40
43
  timelineController.commandAnchors,
41
44
  timelineController.positionAnchors,
42
45
  ]);
43
- return (_jsxs("div", { className: "parakeet flex h-full flex-col items-stretch", "data-parakeet": "standalone", "data-testid": "parakeet-view", onClickCapture: (event) => {
44
- const anchor = event.target instanceof Element
45
- ? event.target.closest("a[href]")
46
- : null;
47
- if (anchor instanceof HTMLAnchorElement && onLink?.(anchor.href))
48
- event.preventDefault();
49
- }, children: [_jsxs("div", { className: "flex h-full w-full flex-col border-r border-base-300", children: [_jsx(ConversationTimeline, { disambiguateAuthors: visitor === undefined && disambiguateAuthors === true, clientActions: clientActions, onOpen: onOpen, focusAfterJump: textareaRef, empty: empty, renderToolActions: renderToolActions, claimsToolMedia: claimsToolMedia, renderAssistantAttachment: renderAssistantAttachment, formatAssistantText: formatAssistantText }), contributions.some(({ entryId, value }) => value.panel.some((row) => JSON.stringify([entryId, row.id]) !== answering)) ? (_jsx("section", { "aria-label": "Session extension controls", className: "w-full shrink-0 border-t border-base-300 bg-base-100", children: contributions.map(({ entryId, value: contribution }) => {
50
- const value = {
51
- ...contribution,
52
- panel: contribution.panel.filter((row) => JSON.stringify([entryId, row.id]) !== answering),
53
- };
54
- // An extension's retained-event notice and null-anchor rows
55
- // join its own footer entry; one with no panel row here keeps
56
- // none of this, rather than growing a section just to show it.
57
- const omittedHere = value.panel.length === 0
58
- ? undefined
59
- : placed.omitted.find((entry) => entry.entryId === entryId);
60
- const unanchoredHere = value.panel.length === 0
61
- ? []
62
- : placed.unanchored
63
- .filter((entry) => entry.entryId === entryId)
64
- .flatMap(({ cell }) => cell.rows.map((row) => ({
65
- ...row,
66
- id: `unanchored:${cell.id}:${row.id}`,
67
- })));
68
- return (_jsx(ClientRows, { entryId: entryId, rows: [
69
- ...value.panel,
70
- ...(omittedHere === undefined
71
- ? []
72
- : [
73
- {
74
- id: `omitted:${entryId}`,
75
- title: `${String(omittedHere.count)} earlier change${omittedHere.count === 1 ? "" : "s"} omitted`,
76
- tone: "muted",
77
- },
78
- ]),
79
- ...unanchoredHere,
80
- ], actions: clientActions, onOpen: onOpen }, entryId));
81
- }) })) : null, _jsx(ConversationWaiting, { clientActions: clientActions }), _jsx(ConversationComposer, { visitor: visitor, textareaRef: textareaRef, composerActionVariant: composerActionVariant, slash: slash })] }), visitor === undefined ? _jsx(ConversationInteraction, { slash: slash }) : null] }));
46
+ return (_jsx(ParakeetHostFactsContext.Provider, { value: hostFacts ?? noHostFacts, children: _jsxs("div", { className: "parakeet flex h-full flex-col items-stretch", "data-parakeet": "standalone", "data-testid": "parakeet-view", onClickCapture: (event) => {
47
+ const anchor = event.target instanceof Element
48
+ ? event.target.closest("a[href]")
49
+ : null;
50
+ if (anchor instanceof HTMLAnchorElement && onLink?.(anchor.href))
51
+ event.preventDefault();
52
+ }, children: [_jsxs("div", { className: "flex h-full w-full flex-col border-r border-base-300", children: [_jsx(ConversationTimeline, { disambiguateAuthors: visitor === undefined && disambiguateAuthors === true, clientActions: clientActions, onOpen: onOpen, focusAfterJump: textareaRef, empty: empty, renderToolActions: renderToolActions, claimsToolMedia: claimsToolMedia, renderAssistantAttachment: renderAssistantAttachment, formatAssistantText: formatAssistantText }), contributions.some(({ entryId, value }) => value.panel.some((row) => JSON.stringify([entryId, row.id]) !== answering)) ? (_jsx("section", { "aria-label": "Session extension controls", className: "w-full shrink-0 border-t border-base-300 bg-base-100", children: contributions.map(({ entryId, value: contribution }) => {
53
+ const value = {
54
+ ...contribution,
55
+ panel: contribution.panel.filter((row) => JSON.stringify([entryId, row.id]) !== answering),
56
+ };
57
+ // An extension's retained-event notice and null-anchor rows
58
+ // join its own footer entry; one with no panel row here keeps
59
+ // none of this, rather than growing a section just to show it.
60
+ const omittedHere = value.panel.length === 0
61
+ ? undefined
62
+ : placed.omitted.find((entry) => entry.entryId === entryId);
63
+ const unanchoredHere = value.panel.length === 0
64
+ ? []
65
+ : placed.unanchored
66
+ .filter((entry) => entry.entryId === entryId)
67
+ .flatMap(({ cell }) => cell.rows.map((row) => ({
68
+ ...row,
69
+ id: `unanchored:${cell.id}:${row.id}`,
70
+ })));
71
+ return (_jsx(ClientRows, { entryId: entryId, rows: [
72
+ ...value.panel,
73
+ ...(omittedHere === undefined
74
+ ? []
75
+ : [
76
+ {
77
+ id: `omitted:${entryId}`,
78
+ title: `${String(omittedHere.count)} earlier change${omittedHere.count === 1 ? "" : "s"} omitted`,
79
+ tone: "muted",
80
+ },
81
+ ]),
82
+ ...unanchoredHere,
83
+ ], actions: clientActions, onOpen: onOpen }, entryId));
84
+ }) })) : null, _jsx(ConversationWaiting, { clientActions: clientActions }), _jsx(ConversationComposer, { visitor: visitor, textareaRef: textareaRef, composerActionVariant: composerActionVariant, slash: slash })] }), visitor === undefined ? (_jsx(ConversationInteraction, { slash: slash })) : null] }) }));
82
85
  }
86
+ const noHostFacts = {};
83
87
  const busyStatuses = new Set([
84
88
  "cancelling",
85
89
  "queued",
@@ -217,7 +221,25 @@ function ConversationTimeline({ disambiguateAuthors, clientActions, onOpen, focu
217
221
  },
218
222
  }
219
223
  : item, onDismissFailed: dismissFailed, onCancelQueued: cancelQueued, cancellingQueued: timelineController.cancellingQueued, onToggleTool: toggleTool, renderToolActions: renderToolActions, claimsToolMedia: claimsToolMedia, renderAssistantAttachment: renderAssistantAttachment, formatAssistantText: formatAssistantText, toolDisclosure: toolDisclosure }), placed.after.get(item.id)?.map(({ entryId, cell }) => (_jsx(ClientRows, { entryId: entryId, rows: cell.rows, actions: clientActions, onOpen: onOpen }, `${entryId}:${cell.id}`)))] }, virtualItem.key));
220
- }) })) : before.length > 0 ? (before) : hasMoreHistory ? null : ((empty ?? (_jsx("div", { className: "flex h-full items-center justify-center text-center", children: _jsxs("div", { children: [_jsx("p", { className: "mb-1 text-xs text-base-content", children: "Ready" }), _jsx("p", { className: "text-[10px] text-dim", children: "What would you like to build?" })] }) })))) }), count > 0 ? (_jsx(ScrollToBottomBlob, { direction: "forward", unread: unread, focusAfterJump: focusAfterJump, onJump: jumpToBottom, scrollerRef: scrollerRef })) : null] }));
224
+ }) })) : before.length > 0 ? (before) : hasMoreHistory ? null : ((empty ?? _jsx(ConversationStarters, {}))) }), count > 0 ? (_jsx(ScrollToBottomBlob, { direction: "forward", unread: unread, focusAfterJump: focusAfterJump, onJump: jumpToBottom, scrollerRef: scrollerRef })) : null] }));
225
+ }
226
+ /** The empty conversation: host starter chips when there are any, the quiet prompt otherwise. */
227
+ function ConversationStarters() {
228
+ const { modelSetup, starters } = useContext(ParakeetHostFactsContext);
229
+ const composer = useComposer();
230
+ // Known up front, before any run: say so once, with the fix as the one action.
231
+ if (modelSetup?.state === "missing")
232
+ return (_jsx("div", { className: "flex h-full items-center justify-center", children: _jsx(SetupNotice, { cause: "No model is connected to this workspace yet.", fix: modelSetup.fix, need: "Connect a model to start", variant: "panel" }) }));
233
+ if (starters === undefined || starters.length === 0)
234
+ return (_jsx("div", { className: "flex h-full items-center justify-center text-center", children: _jsxs("div", { children: [_jsx("p", { className: "mb-1 text-xs text-base-content", children: "Ready" }), _jsx("p", { className: "text-[10px] text-dim", children: "What would you like to build?" })] }) }));
235
+ return (_jsx("div", { className: "flex h-full items-center justify-center", children: _jsx(EmptyState, { description: "Pick one to start, or type your own below.", suggestions: starters.map((prompt) => ({
236
+ label: prompt,
237
+ onSelect: () => {
238
+ // Same path as typing it: the draft is the prompt, then it sends.
239
+ composer.setDraft(prompt);
240
+ composer.send();
241
+ },
242
+ })), title: "What would you like to do?", variant: "quiet" }) }));
221
243
  }
222
244
  /** Independently contributed waiting controls; queued messages stay in the transcript. */
223
245
  function ConversationWaiting({ clientActions, }) {
@@ -235,6 +257,7 @@ function ConversationWaiting({ clientActions, }) {
235
257
  }, children: extensionWaiting.value.waiting.cancel.label })] })) }));
236
258
  }
237
259
  function ConversationComposer({ visitor, textareaRef, composerActionVariant, slash, }) {
260
+ const hostFacts = useContext(ParakeetHostFactsContext);
238
261
  const composer = useComposer();
239
262
  const sessionStatus = useStatus();
240
263
  const contributions = useClientContributions();
@@ -266,6 +289,10 @@ function ConversationComposer({ visitor, textareaRef, composerActionVariant, sla
266
289
  onSend: slash.submit,
267
290
  slash: visitor === undefined ? slash : undefined,
268
291
  placeholder: visitor === undefined ? undefined : `Ask ${visitor.agentName}…`,
292
+ // No model means no reply: say why instead of taking a prompt that cannot work.
293
+ disabledReason: hostFacts.modelSetup?.state === "missing"
294
+ ? "Connect a model to start chatting"
295
+ : undefined,
269
296
  showFooter: visitor === undefined,
270
297
  status: sessionStatus.status,
271
298
  viewState: sessionStatus.viewState,
@@ -277,6 +304,6 @@ function ConversationComposer({ visitor, textareaRef, composerActionVariant, sla
277
304
  return _jsx(ChatComposer, { ...composerProps });
278
305
  }
279
306
  /** Standalone typed composer and exact-message timeline. */
280
- export function Parakeet({ authorOf, disambiguateAuthors, visitor, markdownPolicy = "session", composerActionVariant, empty, session, clients, renderToolActions, claimsToolMedia, renderAssistantAttachment, formatAssistantText, commands, onLink, onOpen, }) {
281
- return (_jsx(MarkdownPolicyContext.Provider, { value: markdownPolicy, children: _jsx(ParakeetProvider, { session: session, clients: clients, authorOf: authorOf, children: _jsx(ParakeetView, { disambiguateAuthors: disambiguateAuthors, visitor: visitor, composerActionVariant: composerActionVariant, empty: empty, renderToolActions: renderToolActions, claimsToolMedia: claimsToolMedia, renderAssistantAttachment: renderAssistantAttachment, formatAssistantText: formatAssistantText, commands: commands, onLink: onLink, onOpen: onOpen }) }) }));
307
+ export function Parakeet({ authorOf, disambiguateAuthors, visitor, markdownPolicy = "session", composerActionVariant, empty, hostFacts, session, clients, renderToolActions, claimsToolMedia, renderAssistantAttachment, formatAssistantText, commands, onLink, onOpen, }) {
308
+ return (_jsx(MarkdownPolicyContext.Provider, { value: markdownPolicy, children: _jsx(ParakeetProvider, { session: session, clients: clients, authorOf: authorOf, children: _jsx(ParakeetView, { disambiguateAuthors: disambiguateAuthors, visitor: visitor, composerActionVariant: composerActionVariant, empty: empty, hostFacts: hostFacts, renderToolActions: renderToolActions, claimsToolMedia: claimsToolMedia, renderAssistantAttachment: renderAssistantAttachment, formatAssistantText: formatAssistantText, commands: commands, onLink: onLink, onOpen: onOpen }) }) }));
282
309
  }