@fungi.computer/parakeet 0.13.3 → 0.14.1

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.
@@ -27,6 +27,15 @@ export type ParakeetToast = Readonly<{
27
27
  variant: "info" | "warning" | "error";
28
28
  /** What happened. */
29
29
  message: string;
30
+ /** The one thing to do about it, when the host offers a place to do it. */
31
+ action?: ParakeetToastAction | undefined;
32
+ }>;
33
+ /** A toast's way forward, such as opening the host's key settings. */
34
+ export type ParakeetToastAction = Readonly<{
35
+ /** The button or link text. */
36
+ label: string;
37
+ /** Called when the person chooses it. */
38
+ onSelect: () => void;
30
39
  }>;
31
40
  /** The decisions waiting on the person, which the composer takes over for. */
32
41
  export type ParakeetAwaiting = Readonly<{
@@ -1,7 +1,7 @@
1
1
  import { openAppAgent } from "@fungi.computer/agar/agents";
2
2
  import { seedSessionQuery } from "./headless.js";
3
3
  import { createShiitakeClient, } from "@fungi.computer/shiitake/client";
4
- import { ShiitakeError } from "@fungi.computer/shiitake";
4
+ import { ShiitakeError } from "@fungi.computer/shiitake/client";
5
5
  import { EventSource as EventSourceImplementation, } from "eventsource";
6
6
  /** How long a closing conversation waits for its sends to settle. */
7
7
  const sendSettleLimitMs = 30_000;
@@ -2,7 +2,7 @@ import { type ParakeetAuthorOf } from "./core/author-labels.js";
2
2
  import { type PromptDelivery, type PromptCommand, type SessionContext, type SessionExtensionSlots, type SessionPendingPrompts } from "@fungi.computer/shiitake/client";
3
3
  import type { ClientEntryV1 } from "@fungi.computer/shiitake/client-entry";
4
4
  import { type ClientContribution } from "./core/client-contributions.js";
5
- import { type ParakeetInteractions, type ParakeetToast } from "./commands/interactions.js";
5
+ import { type ParakeetInteractions, type ParakeetToast, type ParakeetToastAction } from "./commands/interactions.js";
6
6
  import type { WhistleExecutionOutcome } from "@fungi.computer/whistle";
7
7
  import { type ReactNode } from "react";
8
8
  import { type SessionViewState } from "./core/session-view-state.js";
@@ -168,6 +168,12 @@ export type ParakeetReconnectOutcome = Readonly<{
168
168
  /** Reason suitable for presentation. */
169
169
  cause: string;
170
170
  }>;
171
+ /**
172
+ * Register where this host lets a person add a key safely: its Model keys or
173
+ * Connections settings today. A prompt refused for holding a key or password
174
+ * links here from its toast. Absent, the toast carries no action.
175
+ */
176
+ export declare function useParakeetKeySettings(action: ParakeetToastAction | undefined): void;
171
177
  /** Own one renderer-neutral conversation scope over the existing query cache. */
172
178
  export declare function ParakeetProvider({ children, session, clients, interactionStore, authorOf, onToast, draftStorage, draftIdentity, }: Readonly<{
173
179
  children: ReactNode;
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { noAuthor } from "./core/author-labels.js";
3
3
  import { nanoid } from "@fungi.computer/cairn";
4
+ import { ShiitakeError } from "@fungi.computer/shiitake/client";
4
5
  import {} from "@fungi.computer/shiitake/client";
5
6
  import { createClientContributions, } from "./core/client-contributions.js";
6
7
  import { createParakeetInteractions, } from "./commands/interactions.js";
@@ -112,7 +113,9 @@ function acquireDraftStorage(supplied) {
112
113
  return { status: "unavailable", cause };
113
114
  }
114
115
  }
115
- function createConversationAtoms(session, queryClient, authorOf, interactions, draftStorage, draftScope, contributions, shown) {
116
+ function createConversationAtoms(session, queryClient, authorOf, interactions, draftStorage, draftScope, contributions, shown,
117
+ /** Where the host lets a person add a key safely, when it has a place. */
118
+ keySettings) {
116
119
  const journal = draftJournal(draftScope, draftStorage.status === "available" ? draftStorage.storage : undefined);
117
120
  const saved = journal.read();
118
121
  let mounted = false;
@@ -683,10 +686,58 @@ function createConversationAtoms(session, queryClient, authorOf, interactions, d
683
686
  .catch((cause) => {
684
687
  if (!mounted)
685
688
  return;
689
+ if (cause instanceof ShiitakeError &&
690
+ cause.cause === "secret_in_prompt") {
691
+ set(refuseSecretAtom, admission);
692
+ return;
693
+ }
686
694
  recoveryReasons.set(admission.requestId, errorMessage(cause));
687
695
  set(recoverAdmissionsAtom);
688
696
  });
689
697
  });
698
+ /**
699
+ * The owner refused the prompt because it holds a key or password, before
700
+ * admitting anything. There is nothing to withdraw or retry: the text goes
701
+ * back to the draft so the person can take the secret out, and a toast
702
+ * (never inline text) links to the host's key settings.
703
+ */
704
+ const refuseSecretAtom = atom(null, (get, set, admission) => {
705
+ const admissions = get(rawAdmissionsAtom);
706
+ if (!admissions.some(({ requestId, status }) => requestId === admission.requestId && status === "admitting"))
707
+ return;
708
+ const remaining = admissions.filter(({ requestId }) => requestId !== admission.requestId);
709
+ const currentDraft = get(draftAtom);
710
+ const restored = !admission.restoreDraft
711
+ ? currentDraft
712
+ : currentDraft === ""
713
+ ? admission.submittedDraft
714
+ : `${currentDraft}\n\n${admission.submittedDraft}`;
715
+ const restoredImages = admission.restoreDraft
716
+ ? [...(get(draftImagesAtom) ?? []), ...(admission.images ?? [])]
717
+ : get(draftImagesAtom);
718
+ try {
719
+ set(persistAtom, {
720
+ draft: restored,
721
+ draftPayload: {
722
+ images: restoredImages,
723
+ delivery: get(draftDeliveryAtom),
724
+ },
725
+ admissions: remaining,
726
+ });
727
+ }
728
+ catch (cause) {
729
+ reportFailure("restore draft after secret refusal", cause);
730
+ }
731
+ set(draftImagesAtom, restoredImages);
732
+ set(rawAdmissionsAtom, remaining);
733
+ set(setDraftAtom, restored);
734
+ const toast = {
735
+ variant: "error",
736
+ message: "Not sent: this message contains a key or password. Nothing was saved.",
737
+ };
738
+ const action = keySettings();
739
+ interactions.toast(action === undefined ? toast : { ...toast, action });
740
+ });
690
741
  const recoverAdmissionsAtom = atom(null, (get, set) => {
691
742
  if (!mounted)
692
743
  return;
@@ -1068,6 +1119,23 @@ function useConversationScope() {
1068
1119
  throw new Error("Parakeet hooks require a ParakeetProvider");
1069
1120
  return scope;
1070
1121
  }
1122
+ /**
1123
+ * Register where this host lets a person add a key safely: its Model keys or
1124
+ * Connections settings today. A prompt refused for holding a key or password
1125
+ * links here from its toast. Absent, the toast carries no action.
1126
+ */
1127
+ export function useParakeetKeySettings(action) {
1128
+ const { keySettings } = useConversationScope();
1129
+ useEffect(() => {
1130
+ if (action === undefined)
1131
+ return undefined;
1132
+ keySettings.current = action;
1133
+ return () => {
1134
+ if (keySettings.current === action)
1135
+ keySettings.current = undefined;
1136
+ };
1137
+ }, [keySettings, action]);
1138
+ }
1071
1139
  function useStoreAtom(atom) {
1072
1140
  const { store } = useConversationScope();
1073
1141
  const subscribe = useCallback((listener) => store.sub(atom, listener), [atom, store]);
@@ -1091,16 +1159,20 @@ export function ParakeetProvider({ children, session, clients = noClients, inter
1091
1159
  const scope = useMemo(() => {
1092
1160
  const interactions = interactionStore ?? createParakeetInteractions();
1093
1161
  const contributions = atom(noContributions);
1162
+ const keySettings = {
1163
+ current: undefined,
1164
+ };
1094
1165
  const shown = (item) => item.kind !== "user_message" ||
1095
1166
  item.origin === undefined ||
1096
1167
  !footerPromptOwners.has(item.origin.extensionId);
1097
1168
  return {
1098
- atoms: createConversationAtoms(session, queryClient, authorOf, interactions, acquiredDraftStorage, draftScope, contributions, shown),
1169
+ atoms: createConversationAtoms(session, queryClient, authorOf, interactions, acquiredDraftStorage, draftScope, contributions, shown, () => keySettings.current),
1099
1170
  session,
1100
1171
  store: createStore(),
1101
1172
  contributions,
1102
1173
  interactions,
1103
1174
  shown,
1175
+ keySettings,
1104
1176
  };
1105
1177
  }, [
1106
1178
  queryClient,
@@ -5,7 +5,7 @@ export { sanitizeDisplayText } from "./core/display-text.js";
5
5
  export { formatContextUsage, formatTokenCount } from "./core/format-context.js";
6
6
  export { formatWhen, oneLine } from "./core/picker-text.js";
7
7
  export { providerChoices } from "./provider-choices.js";
8
- export { ParakeetProvider, useComposer, useClientContributions, useParakeetInteractions, useExtensionSlots, useParakeetSession, useLastSessionReplyAt, useStatus, useTimeline, type ComposerController, type ParakeetDraftCheckpoint, type ParakeetModel, type ParakeetObservation, type ParakeetReconnectOutcome, type ParakeetStatus, type ParakeetSessionViewState, type ParakeetUsage, type StatusController, type TimelineController, } from "./conversation.js";
8
+ export { ParakeetProvider, useComposer, useParakeetKeySettings, useClientContributions, useParakeetInteractions, useExtensionSlots, useParakeetSession, useLastSessionReplyAt, useStatus, useTimeline, type ComposerController, type ParakeetDraftCheckpoint, type ParakeetModel, type ParakeetObservation, type ParakeetReconnectOutcome, type ParakeetStatus, type ParakeetSessionViewState, type ParakeetUsage, type StatusController, type TimelineController, } from "./conversation.js";
9
9
  export { sessionViewState, sessionStateLabel, sessionActivityStatus, type SessionActivityStatus, type SessionViewFacts, type SessionViewState as ParakeetOwnerViewState, } from "./core/session-view-state.js";
10
10
  export { applySessionFrame, mergeTerminals, } from "./core/session-projection.js";
11
11
  export { type SessionActivity, seedSessionQuery, sessionQueryOptions, subscribeSessionActivity, } from "./core/session-query.js";
@@ -16,7 +16,7 @@ export { contributeSessionCommands, sessionCommandDefinitions, type ParakeetSess
16
16
  export { completeSlash, fuzzyMatch, keyBindings, keyLabel, parseSlashDraft, slashRegistry, type FuzzyMatch, type KeyBindingRow, type SlashCommand, type SlashCommandItem, type SlashCompletion, type SlashParse, type SlashWordItem, } from "./commands/slash.js";
17
17
  export { composerHints, fitHints, formatHints, type ComposerHintContext, type ComposerKeys, type KeyHint, } from "./commands/hints.js";
18
18
  export { isCancelledOutcome, runSlashDraft, type SlashRuntime, } from "./commands/run.js";
19
- export { createParakeetInteractions, type ParakeetInteractions, type ParakeetAwaiting, type ParakeetInteractionState, type ParakeetNotice, type ParakeetOpenInteraction, type ParakeetToast, } from "./commands/interactions.js";
19
+ export { createParakeetInteractions, type ParakeetInteractions, type ParakeetAwaiting, type ParakeetInteractionState, type ParakeetNotice, type ParakeetOpenInteraction, type ParakeetToast, type ParakeetToastAction, } from "./commands/interactions.js";
20
20
  export { parakeetBuiltinCommands, type ParakeetBuiltinOptions, } from "./commands/builtins.js";
21
21
  export { advertisedCommands, type AdvertisedCatalogError, type AdvertisedCommands, } from "./commands/advertised.js";
22
22
  export { useSlashCommands, type ParakeetCommandRuntime, type SlashCommandController, type SlashCommandOptions, } from "./commands/use-slash-commands.js";
package/dist/headless.js CHANGED
@@ -3,7 +3,7 @@ export { sanitizeDisplayText } from "./core/display-text.js";
3
3
  export { formatContextUsage, formatTokenCount } from "./core/format-context.js";
4
4
  export { formatWhen, oneLine } from "./core/picker-text.js";
5
5
  export { providerChoices } from "./provider-choices.js";
6
- export { ParakeetProvider, useComposer, useClientContributions, useParakeetInteractions, useExtensionSlots, useParakeetSession, useLastSessionReplyAt, useStatus, useTimeline, } from "./conversation.js";
6
+ export { ParakeetProvider, useComposer, useParakeetKeySettings, useClientContributions, useParakeetInteractions, useExtensionSlots, useParakeetSession, useLastSessionReplyAt, useStatus, useTimeline, } from "./conversation.js";
7
7
  export { sessionViewState, sessionStateLabel, sessionActivityStatus, } from "./core/session-view-state.js";
8
8
  export { applySessionFrame, mergeTerminals, } from "./core/session-projection.js";
9
9
  export { seedSessionQuery, sessionQueryOptions, subscribeSessionActivity, } from "./core/session-query.js";
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { ParakeetProvider, useComposer, useStatus, useTimeline, useMarkdown, disclosureOpen, formatToolDuration, formatModelIdentity, formatModelWithLevel, formatContextUsage, formatTokenCount, initialToolDisclosure, toggleAllDisclosure, toggleDisclosure, toolCallDefaultOpen, toolGroupDefaultOpen, visibleToolCalls, } from "./headless.js";
1
+ export { ParakeetProvider, useComposer, useParakeetKeySettings, useStatus, useTimeline, useMarkdown, disclosureOpen, formatToolDuration, formatModelIdentity, formatModelWithLevel, formatContextUsage, formatTokenCount, initialToolDisclosure, toggleAllDisclosure, toggleDisclosure, toolCallDefaultOpen, toolGroupDefaultOpen, visibleToolCalls, } from "./headless.js";
2
2
  export { Parakeet, ParakeetView } from "./parakeet.js";
3
3
  export { ComposerModelKey, type ComposerModelKeyProps, } from "./components/ComposerModelKey.js";
4
4
  export { composerSendState } from "./components/ComposerShell.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { ParakeetProvider, useComposer, useStatus, useTimeline, useMarkdown, disclosureOpen, formatToolDuration, formatModelIdentity, formatModelWithLevel, formatContextUsage, formatTokenCount, initialToolDisclosure, toggleAllDisclosure, toggleDisclosure, toolCallDefaultOpen, toolGroupDefaultOpen, visibleToolCalls, } from "./headless.js";
1
+ export { ParakeetProvider, useComposer, useParakeetKeySettings, useStatus, useTimeline, useMarkdown, disclosureOpen, formatToolDuration, formatModelIdentity, formatModelWithLevel, formatContextUsage, formatTokenCount, initialToolDisclosure, toggleAllDisclosure, toggleDisclosure, toolCallDefaultOpen, toolGroupDefaultOpen, visibleToolCalls, } from "./headless.js";
2
2
  export { Parakeet, ParakeetView } from "./parakeet.js";
3
3
  export { ComposerModelKey, } from "./components/ComposerModelKey.js";
4
4
  export { composerSendState } from "./components/ComposerShell.js";
package/dist/parakeet.js CHANGED
@@ -10,7 +10,7 @@ import { ScrollToBottomBlob } from "@fungi.computer/caps/components/scroll-to-bo
10
10
  import { createWhistle } from "@fungi.computer/whistle";
11
11
  import { useVirtualizer } from "@tanstack/react-virtual";
12
12
  import { useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
13
- import { ParakeetProvider, useComposer, useClientContributions, useDismissFailedPrompt, useStatus, useTimeline, } from "./conversation.js";
13
+ import { ParakeetProvider, useComposer, useParakeetKeySettings, useClientContributions, useDismissFailedPrompt, useStatus, useTimeline, } from "./conversation.js";
14
14
  import { awaitingTakeover } from "./core/awaiting-answer.js";
15
15
  import { initialToolDisclosure, toggleDisclosure } from "./core/tool-groups.js";
16
16
  import { authorDisplayNames, } from "./core/author-labels.js";
@@ -361,6 +361,12 @@ function ConversationComposer({ visitor, textareaRef, composerActionVariant, sla
361
361
  const abort = useCallback(() => {
362
362
  void composer.cancel();
363
363
  }, [composer.cancel]);
364
+ // A prompt refused for holding a key links to the host's existing key
365
+ // settings (Model keys); the Vault page takes this over when it exists.
366
+ const openKeySettings = hostFacts.modelSetup?.fix.onSelect;
367
+ useParakeetKeySettings(useMemo(() => openKeySettings === undefined
368
+ ? undefined
369
+ : { label: "Add it in settings", onSelect: openKeySettings }, [openKeySettings]));
364
370
  if (hostFacts.modelSetup?.state === "missing")
365
371
  return null;
366
372
  const composerProps = {
@@ -1,5 +1,5 @@
1
1
  import { nanoid } from "@fungi.computer/cairn";
2
- import { ShiitakeError } from "@fungi.computer/shiitake";
2
+ import { ShiitakeError } from "@fungi.computer/shiitake/client";
3
3
  import { z } from "zod";
4
4
  import { buildDurableTimeline } from "./core/build-timeline.js";
5
5
  import { formatWhen, oneLine } from "./core/picker-text.js";
@@ -261,6 +261,7 @@ failed or waits on the person. Everything else is a toast.
261
261
  type ParakeetToast = Readonly<{
262
262
  variant: "info" | "warning" | "error";
263
263
  message: string;
264
+ action?: ParakeetToastAction;
264
265
  }>;
265
266
  ```
266
267
 
@@ -269,6 +270,19 @@ what the person just did is never one: it is an echo and is not announced.
269
270
 
270
271
  ---
271
272
 
273
+ ### ParakeetToastAction
274
+
275
+ ```ts
276
+ type ParakeetToastAction = Readonly<{
277
+ label: string;
278
+ onSelect: () => void;
279
+ }>;
280
+ ```
281
+
282
+ A toast's way forward, such as opening the host's key settings.
283
+
284
+ ---
285
+
272
286
  ### ParakeetAwaiting
273
287
 
274
288
  ```ts
@@ -3423,6 +3437,12 @@ Re-exports [useComposer](index.md#usecomposer)
3423
3437
 
3424
3438
  ---
3425
3439
 
3440
+ ### useParakeetKeySettings
3441
+
3442
+ Re-exports [useParakeetKeySettings](index.md#useparakeetkeysettings)
3443
+
3444
+ ---
3445
+
3426
3446
  ### useStatus
3427
3447
 
3428
3448
  Re-exports [useStatus](index.md#usestatus)
package/docs/api/index.md CHANGED
@@ -1183,6 +1183,28 @@ the terminal draws; the command, not the page, defines the steps.
1183
1183
 
1184
1184
  ---
1185
1185
 
1186
+ ### useParakeetKeySettings()
1187
+
1188
+ ```ts
1189
+ function useParakeetKeySettings(action): void;
1190
+ ```
1191
+
1192
+ Register where this host lets a person add a key safely: its Model keys or
1193
+ Connections settings today. A prompt refused for holding a key or password links
1194
+ here from its toast. Absent, the toast carries no action.
1195
+
1196
+ #### Parameters
1197
+
1198
+ | Parameter | Type |
1199
+ | --------- | ---------------------------------------------------------------------------------- |
1200
+ | `action` | \| `Readonly`\<\{ `label`: `string`; `onSelect`: () => `void`; \}\> \| `undefined` |
1201
+
1202
+ #### Returns
1203
+
1204
+ `void`
1205
+
1206
+ ---
1207
+
1186
1208
  ### ParakeetProvider()
1187
1209
 
1188
1210
  ```ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/parakeet",
3
- "version": "0.13.3",
3
+ "version": "0.14.1",
4
4
  "author": "Levi <levi@technomancy.dev>",
5
5
  "private": false,
6
6
  "description": "Standalone React composer for a typed Shiitake Session",
@@ -69,9 +69,9 @@
69
69
  "@fungi.computer/cairn": "0.1.0",
70
70
  "@fungi.computer/caps": "0.12.1",
71
71
  "@fungi.computer/gills": "0.4.0",
72
- "@fungi.computer/knapsack": "0.4.19",
73
- "@fungi.computer/mule": "0.2.7",
74
- "@fungi.computer/shiitake": "0.20.4",
72
+ "@fungi.computer/knapsack": "0.4.20",
73
+ "@fungi.computer/mule": "0.3.0",
74
+ "@fungi.computer/shiitake": "0.21.1",
75
75
  "@fungi.computer/sigils": "0.3.2",
76
76
  "@fungi.computer/sprite": "0.2.2",
77
77
  "@fungi.computer/sprite-zdog": "0.3.2",