@gedatou/cadenza-ai 0.7.1 → 0.7.4

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-PRESENT GGGLHHH <https://github.com/GGGLHHH>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.d.mts CHANGED
@@ -169,6 +169,30 @@ interface ServerCoverage {
169
169
  */
170
170
  declare function useServerCoverage(byok: ByokClient$1, url?: string): ServerCoverage;
171
171
  //#endregion
172
+ //#region src/runtime/message-keys.d.ts
173
+ interface MessageKeys {
174
+ messages: readonly UIMessage$1[];
175
+ /** message id → the React key it renders under. */
176
+ keys: ReadonlyMap<string, string>;
177
+ }
178
+ /**
179
+ * Carries each message's key across a render. TanStack's stream processor
180
+ * renames the optimistic assistant message to the server's `messageId` on the
181
+ * first `TEXT_MESSAGE_START` — after any thinking or tool calls that streamed
182
+ * into it. Keyed by `message.id`, the row remounts at that moment: a
183
+ * `Reasoning` restarts its timer (every block reads "1s") and forgets that it
184
+ * should fold. A message whose id is new, standing where the previous render
185
+ * had a message of the same role whose id is now gone, is that rename and
186
+ * keeps the old key.
187
+ */
188
+ declare function nextMessageKeys(previous: MessageKeys | undefined, messages: readonly UIMessage$1[]): MessageKeys;
189
+ /**
190
+ * Stable React keys for a transcript: `key={keyOf(message)}` instead of
191
+ * `key={message.id}`, so a message that TanStack renames mid-stream keeps its
192
+ * row (see `nextMessageKeys`).
193
+ */
194
+ declare function useMessageKeys(messages: readonly UIMessage$1[]): (message: UIMessage$1) => string;
195
+ //#endregion
172
196
  //#region src/runtime/messages.d.ts
173
197
  /** The message's text parts, joined by blank lines; tool calls and media are skipped. */
174
198
  declare function messageText(message: UIMessage$1): string;
@@ -197,6 +221,14 @@ declare function editAndResend(chat: EditableChat, messageId: string, content: s
197
221
  * provider signed it, or when a later text / tool-call part has started.
198
222
  */
199
223
  declare function isThinkingComplete(message: UIMessage$1, partIndex: number, status: ChatClientState$1): boolean;
224
+ /**
225
+ * The input of a tool call for a custom renderer: `part.input` once the
226
+ * arguments are complete, the partial JSON while they stream, `{}` before
227
+ * anything parses. Top-level `null`s are dropped — models write `null` for an
228
+ * optional argument they mean to omit, and a destructuring default only
229
+ * applies to `undefined`.
230
+ */
231
+ declare function toolInput<T extends object = Record<string, unknown>>(part: ToolCallPart): Partial<T>;
200
232
  interface Source {
201
233
  url: string;
202
234
  title?: string;
@@ -227,6 +259,8 @@ interface PartLabels {
227
259
  sources: (count: number) => string;
228
260
  }
229
261
  declare const DEFAULT_PART_LABELS: PartLabels;
262
+ /** `DEFAULT_PART_LABELS` in Chinese: `<PartRenderersProvider labels={ZH_PART_LABELS}>`. */
263
+ declare const ZH_PART_LABELS: PartLabels;
230
264
  /**
231
265
  * The approval interrupt as the views see it, for whichever tool set the chat
232
266
  * was created with. `useChat().interrupts` is typed per tool and
@@ -471,6 +505,8 @@ interface ByokKeyDialogLabels {
471
505
  serverKey: string;
472
506
  }
473
507
  declare const DEFAULT_BYOK_KEY_DIALOG_LABELS: ByokKeyDialogLabels;
508
+ /** `DEFAULT_BYOK_KEY_DIALOG_LABELS` in Chinese. */
509
+ declare const ZH_BYOK_KEY_DIALOG_LABELS: ByokKeyDialogLabels;
474
510
  interface ByokKeyDialogProps {
475
511
  byok: ByokClient$1;
476
512
  catalog: Catalog;
@@ -602,6 +638,8 @@ interface ContextUsageLabels {
602
638
  cacheSaved: string;
603
639
  }
604
640
  declare const DEFAULT_CONTEXT_USAGE_LABELS: ContextUsageLabels;
641
+ /** `DEFAULT_CONTEXT_USAGE_LABELS` in Chinese. */
642
+ declare const ZH_CONTEXT_USAGE_LABELS: ContextUsageLabels;
605
643
  interface ContextUsageProps {
606
644
  /** Supplies `contextWindow` (the bar) and `cost` (the price row); without it only the numbers show. */
607
645
  model?: Model;
@@ -1029,6 +1067,8 @@ interface UsageStatsLabels {
1029
1067
  modality: Record<ModalitySlice['kind'], string>;
1030
1068
  }
1031
1069
  declare const DEFAULT_USAGE_STATS_LABELS: UsageStatsLabels;
1070
+ /** `DEFAULT_USAGE_STATS_LABELS` in Chinese. */
1071
+ declare const ZH_USAGE_STATS_LABELS: UsageStatsLabels;
1032
1072
  interface UsageStatsProps {
1033
1073
  usage: TokenUsage;
1034
1074
  /** Supplies `contextWindow` (context used) and `cost` (saved by cache); without it those two tiles stay away. */
@@ -1053,4 +1093,4 @@ interface UsageStatsProps {
1053
1093
  */
1054
1094
  declare function UsageStats({ usage, model, labels: labelsProp, className }: UsageStatsProps): ReactElement;
1055
1095
  //#endregion
1056
- export { type AnyClientTool, AnyToolApprovalInterrupt, ApprovalActions, ApprovalActionsProps, ApprovalApprove, ApprovalApproveProps, ApprovalDeny, ApprovalDenyProps, ApprovalResponseInput, AttachmentDraft, AttachmentKind, AttachmentState, type ByokClient, ByokKeyDialog, ByokKeyDialogLabels, ByokKeyDialogProps, ByokKeyDialogProvider, ByokKeyDialogProviderProps, type ByokPrompt, type ByokSnapshot, Catalog, type ChatClientState, type ChatInterrupt, Composer, ComposerAttach, ComposerAttachProps, ComposerAttachments, ComposerAttachmentsProps, ComposerChangeEventDetails, ComposerDictate, ComposerDictateProps, ComposerProps, ComposerState, ComposerSubmit, ComposerSubmitProps, ComposerSubmitReason, ComposerTextarea, ComposerTextareaProps, ComposerToolbar, ComposerToolbarProps, ContextUsage, ContextUsageLabels, ContextUsageProps, ContextUsageState, CreateByokOptions, DEFAULT_BYOK_KEY_DIALOG_LABELS, DEFAULT_CONTEXT_USAGE_LABELS, DEFAULT_MAX_ATTACHMENT_BYTES, DEFAULT_PART_LABELS, DEFAULT_USAGE_STATS_LABELS, DraftAttachment, EditableChat, EventType, type InferToolInput, type InferToolOutput, type KeyStatus, type KeyringStorage, Markdown, MarkdownProps, MediaPart, MediaPartProps, MessagesToMarkdownOptions, type Modality, ModalitySlice, Model, ModelCost, ModelPicker, ModelPickerChangeEventDetails, ModelPickerProps, ModelSelection, type MultimodalContent, PartLabels, PartRenderers, PartRenderersContextValue, PartRenderersProvider, PartRenderersProviderProps, Provider, QueueList, QueueListProps, type QueuedMessage, Reasoning, ReasoningChangeEventDetails, ReasoningProps, ReasoningState, SearchToggle, SearchToggleChangeEventDetails, SearchToggleProps, type SendMessageOptions, ServerCoverage, Source, Sources, SourcesChangeEventDetails, SourcesProps, StructuredOutput, StructuredOutputProps, Suggestions, SuggestionsChangeEventDetails, SuggestionsItem, SuggestionsItemProps, SuggestionsProps, THINKING_LEVELS, ThinkingLevel, ThinkingLevelPicker, ThinkingLevelPickerChangeEventDetails, ThinkingLevelPickerProps, type ThinkingPart, ThinkingToggle, ThinkingToggleChangeEventDetails, ThinkingToggleProps, ThreadDayGroup, ThreadDayLabel, ThreadIndex, ThreadIndexOptions, ThreadList, ThreadListArchive, ThreadListArchiveProps, ThreadListChangeEventDetails, ThreadListChangeEventReason, ThreadListDelete, ThreadListDeleteProps, ThreadListGroup, ThreadListGroupLabel, ThreadListGroupLabelProps, ThreadListGroupProps, ThreadListItem, ThreadListItemProps, ThreadListItemState, ThreadListNew, ThreadListNewProps, ThreadListProps, ThreadListRename, ThreadListRenameProps, ThreadMeta, ThreadPersistenceOptions, type TokenUsage, type ToolApprovalInterrupt, ToolCallCard, ToolCallCardProps, ToolCallCardState, ToolCallChangeEventDetails, ToolCallGroup, ToolCallGroupProps, ToolCallGroupTrigger, ToolCallGroupTriggerProps, ToolRenderer, ToolRendererProps, Transcript, TranscriptAction, TranscriptActionProps, TranscriptActions, TranscriptActionsProps, TranscriptContextValue, TranscriptEmpty, TranscriptEmptyProps, TranscriptError, TranscriptErrorProps, TranscriptInterrupt, TranscriptMessage, TranscriptMessageProps, TranscriptMessageState, TranscriptParts, TranscriptPartsProps, TranscriptPending, TranscriptPendingProps, TranscriptProps, TranscriptProvider, TranscriptProviderProps, UsageMetrics, UsageStats, UsageStatsLabels, UsageStatsProps, UsageTracker, UseAttachmentDraftOptions, UseModelSelectionOptions, UseModelSelectionReturn, type WhenBusy, addTokenUsage, attachmentKindOf, clampThinkingLevel, createByok, createCatalog, createThreadIndex, defaultByokStorage, defaultCatalog, defineByok, definePartRenderers, editAndResend, estimateCost, fileToContentPart, fromSpecTokenUsage, generateMessageId, groupThreadsByDay, isByokError, isPasskeyStorageSupported, isThinkingComplete, memoryStorage, messageText, messagesToMarkdown, modelRef, newThreadId, parseModelRef, parsePartialJSON, passkeyStorage, providers, sourcesOf, supportedThinkingLevels, threadPersistence, threadTitleFrom, toolDefinition, usageMetrics, useAttachmentDraft, useComposer, useModelSelection, usePartRenderers, useServerCoverage, useStoredState, useThreadIndex, useThreadListItem, useTranscript, useUsageTracker };
1096
+ export { type AnyClientTool, AnyToolApprovalInterrupt, ApprovalActions, ApprovalActionsProps, ApprovalApprove, ApprovalApproveProps, ApprovalDeny, ApprovalDenyProps, ApprovalResponseInput, AttachmentDraft, AttachmentKind, AttachmentState, type ByokClient, ByokKeyDialog, ByokKeyDialogLabels, ByokKeyDialogProps, ByokKeyDialogProvider, ByokKeyDialogProviderProps, type ByokPrompt, type ByokSnapshot, Catalog, type ChatClientState, type ChatInterrupt, Composer, ComposerAttach, ComposerAttachProps, ComposerAttachments, ComposerAttachmentsProps, ComposerChangeEventDetails, ComposerDictate, ComposerDictateProps, ComposerProps, ComposerState, ComposerSubmit, ComposerSubmitProps, ComposerSubmitReason, ComposerTextarea, ComposerTextareaProps, ComposerToolbar, ComposerToolbarProps, ContextUsage, ContextUsageLabels, ContextUsageProps, ContextUsageState, CreateByokOptions, DEFAULT_BYOK_KEY_DIALOG_LABELS, DEFAULT_CONTEXT_USAGE_LABELS, DEFAULT_MAX_ATTACHMENT_BYTES, DEFAULT_PART_LABELS, DEFAULT_USAGE_STATS_LABELS, DraftAttachment, EditableChat, EventType, type InferToolInput, type InferToolOutput, type KeyStatus, type KeyringStorage, Markdown, MarkdownProps, MediaPart, MediaPartProps, MessageKeys, MessagesToMarkdownOptions, type Modality, ModalitySlice, Model, ModelCost, ModelPicker, ModelPickerChangeEventDetails, ModelPickerProps, ModelSelection, type MultimodalContent, PartLabels, PartRenderers, PartRenderersContextValue, PartRenderersProvider, PartRenderersProviderProps, Provider, QueueList, QueueListProps, type QueuedMessage, Reasoning, ReasoningChangeEventDetails, ReasoningProps, ReasoningState, SearchToggle, SearchToggleChangeEventDetails, SearchToggleProps, type SendMessageOptions, ServerCoverage, Source, Sources, SourcesChangeEventDetails, SourcesProps, StructuredOutput, StructuredOutputProps, Suggestions, SuggestionsChangeEventDetails, SuggestionsItem, SuggestionsItemProps, SuggestionsProps, THINKING_LEVELS, ThinkingLevel, ThinkingLevelPicker, ThinkingLevelPickerChangeEventDetails, ThinkingLevelPickerProps, type ThinkingPart, ThinkingToggle, ThinkingToggleChangeEventDetails, ThinkingToggleProps, ThreadDayGroup, ThreadDayLabel, ThreadIndex, ThreadIndexOptions, ThreadList, ThreadListArchive, ThreadListArchiveProps, ThreadListChangeEventDetails, ThreadListChangeEventReason, ThreadListDelete, ThreadListDeleteProps, ThreadListGroup, ThreadListGroupLabel, ThreadListGroupLabelProps, ThreadListGroupProps, ThreadListItem, ThreadListItemProps, ThreadListItemState, ThreadListNew, ThreadListNewProps, ThreadListProps, ThreadListRename, ThreadListRenameProps, ThreadMeta, ThreadPersistenceOptions, type TokenUsage, type ToolApprovalInterrupt, ToolCallCard, ToolCallCardProps, ToolCallCardState, ToolCallChangeEventDetails, ToolCallGroup, ToolCallGroupProps, ToolCallGroupTrigger, ToolCallGroupTriggerProps, ToolRenderer, ToolRendererProps, Transcript, TranscriptAction, TranscriptActionProps, TranscriptActions, TranscriptActionsProps, TranscriptContextValue, TranscriptEmpty, TranscriptEmptyProps, TranscriptError, TranscriptErrorProps, TranscriptInterrupt, TranscriptMessage, TranscriptMessageProps, TranscriptMessageState, TranscriptParts, TranscriptPartsProps, TranscriptPending, TranscriptPendingProps, TranscriptProps, TranscriptProvider, TranscriptProviderProps, UsageMetrics, UsageStats, UsageStatsLabels, UsageStatsProps, UsageTracker, UseAttachmentDraftOptions, UseModelSelectionOptions, UseModelSelectionReturn, type WhenBusy, ZH_BYOK_KEY_DIALOG_LABELS, ZH_CONTEXT_USAGE_LABELS, ZH_PART_LABELS, ZH_USAGE_STATS_LABELS, addTokenUsage, attachmentKindOf, clampThinkingLevel, createByok, createCatalog, createThreadIndex, defaultByokStorage, defaultCatalog, defineByok, definePartRenderers, editAndResend, estimateCost, fileToContentPart, fromSpecTokenUsage, generateMessageId, groupThreadsByDay, isByokError, isPasskeyStorageSupported, isThinkingComplete, memoryStorage, messageText, messagesToMarkdown, modelRef, newThreadId, nextMessageKeys, parseModelRef, parsePartialJSON, passkeyStorage, providers, sourcesOf, supportedThinkingLevels, threadPersistence, threadTitleFrom, toolDefinition, toolInput, usageMetrics, useAttachmentDraft, useComposer, useMessageKeys, useModelSelection, usePartRenderers, useServerCoverage, useStoredState, useThreadIndex, useThreadListItem, useTranscript, useUsageTracker };
package/dist/index.mjs CHANGED
@@ -16,8 +16,8 @@ import { t as vertex } from "./vertex-hg4Dt54O.mjs";
16
16
  import { n as clampThinkingLevel, r as supportedThinkingLevels, t as THINKING_LEVELS } from "./thinking-CH2uL1dr.mjs";
17
17
  import { Children, createContext, isValidElement, memo, use, useCallback, useEffect, useEffectEvent, useId, useMemo, useRef, useState, useSyncExternalStore } from "react";
18
18
  import { defaultByokStorage, defaultByokStorage as defaultByokStorage$1, defineByok, defineByok as defineByok$1, isPasskeyStorageSupported, memoryStorage, memoryStorage as memoryStorage$1, passkeyStorage } from "@tanstack/ai-client/byok";
19
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
20
19
  import { EventType, EventType as EventType$1, fromSpecTokenUsage, fromSpecTokenUsage as fromSpecTokenUsage$1, generateMessageId, parsePartialJSON, parsePartialJSON as parsePartialJSON$1, toolDefinition } from "@tanstack/ai/client";
20
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
21
21
  import { Attachment, AttachmentAction, AttachmentActions, AttachmentContent, AttachmentGroup, AttachmentMedia, AttachmentTitle, Bubble, BubbleContent, Button, Collapsible, CollapsiblePanel, CollapsibleTrigger, Combobox, ComboboxCollection, ComboboxEmpty, ComboboxGroup, ComboboxGroupLabel, ComboboxInput, ComboboxItem, ComboboxList, ComboboxPopup, ComboboxTrigger, ComboboxValue, Dialog, DialogBody, DialogClose, DialogDescription, DialogFooter, DialogHeader, DialogPopup, DialogTitle, Empty, Field, FieldError, FieldLabel, Input, InputGroup, InputGroupAddon, InputGroupButton, InputGroupTextarea, Item, ItemActions, ItemContent, ItemDescription, ItemGroup, ItemTitle, Marker, MarkerContent, Message, MessageContent, MessageFooter, MessageScroller, MessageScrollerContent, MessageScrollerItem, MessageScrollerProvider, MessageScrollerViewport, Progress, ScrollArea, Select, SelectItem, SelectPopup, SelectTrigger, SelectValue, Spinner, Toggle, Tooltip, TooltipPopup, TooltipTrigger, cn, createChangeEventDetails, createGenericEventDetails, dataAttr } from "@gedatou/cadenza-ui";
22
22
  import { useControllableState } from "@gedatou/cadenza-utils";
23
23
  import { IconArchive, IconArrowUp, IconBrain, IconCheck, IconClock, IconFileText, IconKey, IconMicrophone, IconPaperclip, IconPencil, IconPhoto, IconPlayerStop, IconServer, IconTrash, IconWorld, IconX } from "@tabler/icons-react";
@@ -328,6 +328,61 @@ function useServerCoverage(byok, url = "/api/ai/catalog") {
328
328
  return state;
329
329
  }
330
330
  //#endregion
331
+ //#region src/runtime/message-keys.ts
332
+ /**
333
+ * Carries each message's key across a render. TanStack's stream processor
334
+ * renames the optimistic assistant message to the server's `messageId` on the
335
+ * first `TEXT_MESSAGE_START` — after any thinking or tool calls that streamed
336
+ * into it. Keyed by `message.id`, the row remounts at that moment: a
337
+ * `Reasoning` restarts its timer (every block reads "1s") and forgets that it
338
+ * should fold. A message whose id is new, standing where the previous render
339
+ * had a message of the same role whose id is now gone, is that rename and
340
+ * keeps the old key.
341
+ */
342
+ function nextMessageKeys(previous, messages) {
343
+ const ids = new Set(messages.map((m) => m.id));
344
+ const keys = /* @__PURE__ */ new Map();
345
+ messages.forEach((message, index) => {
346
+ const known = previous?.keys.get(message.id);
347
+ const before = previous?.messages[index];
348
+ const renamed = before !== void 0 && before.role === message.role && !ids.has(before.id) ? previous?.keys.get(before.id) : void 0;
349
+ keys.set(message.id, known ?? renamed ?? message.id);
350
+ });
351
+ return {
352
+ messages,
353
+ keys
354
+ };
355
+ }
356
+ /**
357
+ * Stable React keys for a transcript: `key={keyOf(message)}` instead of
358
+ * `key={message.id}`, so a message that TanStack renames mid-stream keeps its
359
+ * row (see `nextMessageKeys`).
360
+ */
361
+ function useMessageKeys(messages) {
362
+ const [state, setState] = useState(() => nextMessageKeys(void 0, messages));
363
+ let current = state;
364
+ if (state.messages !== messages) {
365
+ current = nextMessageKeys(state, messages);
366
+ setState(current);
367
+ }
368
+ return (message) => current.keys.get(message.id) ?? message.id;
369
+ }
370
+ //#endregion
371
+ //#region src/runtime/tool-json.ts
372
+ /**
373
+ * A tool call's arguments as JSON, as far as they have streamed: the text
374
+ * itself when nothing parses yet. `ToolCallCard` shows this raw fallback;
375
+ * `toolInput` wants an object and drops it.
376
+ */
377
+ function parseToolJson(value) {
378
+ if (typeof value !== "string") return value;
379
+ try {
380
+ return parsePartialJSON$1(value) ?? value;
381
+ } catch {
382
+ return value;
383
+ }
384
+ }
385
+ //#endregion
331
386
  //#region src/runtime/messages.ts
332
387
  /** The message's text parts, joined by blank lines; tool calls and media are skipped. */
333
388
  function messageText(message) {
@@ -364,6 +419,18 @@ function isThinkingComplete(message, partIndex, status) {
364
419
  if (message.parts[partIndex]?.signature !== void 0) return true;
365
420
  return message.parts.slice(partIndex + 1).some((p) => p.type === "text" || p.type === "tool-call");
366
421
  }
422
+ /**
423
+ * The input of a tool call for a custom renderer: `part.input` once the
424
+ * arguments are complete, the partial JSON while they stream, `{}` before
425
+ * anything parses. Top-level `null`s are dropped — models write `null` for an
426
+ * optional argument they mean to omit, and a destructuring default only
427
+ * applies to `undefined`.
428
+ */
429
+ function toolInput(part) {
430
+ const value = part.input ?? (part.arguments === "" ? void 0 : parseToolJson(part.arguments));
431
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return {};
432
+ return Object.fromEntries(Object.entries(value).filter(([, v]) => v !== null));
433
+ }
367
434
  function asSource(value) {
368
435
  if (typeof value !== "object" || value === null) return void 0;
369
436
  const { url, title, snippet } = value;
@@ -413,6 +480,22 @@ const DEFAULT_PART_LABELS = {
413
480
  deny: "Deny",
414
481
  sources: (count) => `${count} sources`
415
482
  };
483
+ /** `DEFAULT_PART_LABELS` in Chinese: `<PartRenderersProvider labels={ZH_PART_LABELS}>`. */
484
+ const ZH_PART_LABELS = {
485
+ thinking: "思考中…",
486
+ thought: "思考了 ",
487
+ toolPending: "准备中",
488
+ toolRunning: "执行中",
489
+ toolApprovalRequested: "等待确认",
490
+ toolApproved: "已同意",
491
+ toolDenied: "已拒绝",
492
+ toolDone: "完成",
493
+ toolFailed: "失败",
494
+ toolGroup: (count) => `调用了 ${count} 个工具`,
495
+ approve: "同意",
496
+ deny: "拒绝",
497
+ sources: (count) => `${count} 个来源`
498
+ };
416
499
  /** Identity with a type check, so a registry can be declared outside a component. */
417
500
  function definePartRenderers(renderers) {
418
501
  return renderers;
@@ -946,6 +1029,17 @@ const DEFAULT_BYOK_KEY_DIALOG_LABELS = {
946
1029
  close: "Close",
947
1030
  serverKey: "Server key"
948
1031
  };
1032
+ /** `DEFAULT_BYOK_KEY_DIALOG_LABELS` in Chinese. */
1033
+ const ZH_BYOK_KEY_DIALOG_LABELS = {
1034
+ title: "API 密钥",
1035
+ description: "密钥只保存在本浏览器,每次请求通过请求头发送。",
1036
+ save: "保存",
1037
+ clear: "清除",
1038
+ confirm: "确认",
1039
+ unlock: "解锁",
1040
+ close: "关闭",
1041
+ serverKey: "服务端已配置密钥"
1042
+ };
949
1043
  const ByokKeyDialogContext = createContext(null);
950
1044
  if (process.env.NODE_ENV !== "production") ByokKeyDialogContext.displayName = "ByokKeyDialogContext";
951
1045
  function useByokKeyDialog() {
@@ -1410,6 +1504,18 @@ const DEFAULT_CONTEXT_USAGE_LABELS = {
1410
1504
  reasoningShare: "Reasoning",
1411
1505
  cacheSaved: "Saved by cache"
1412
1506
  };
1507
+ /** `DEFAULT_CONTEXT_USAGE_LABELS` in Chinese. */
1508
+ const ZH_CONTEXT_USAGE_LABELS = {
1509
+ prompt: "输入",
1510
+ completion: "输出",
1511
+ cached: "缓存",
1512
+ total: "合计",
1513
+ cost: "费用",
1514
+ cacheHit: "缓存命中",
1515
+ outputRatio: "输出 / 输入",
1516
+ reasoningShare: "推理占比",
1517
+ cacheSaved: "缓存节省"
1518
+ };
1413
1519
  const USD$1 = new Intl.NumberFormat("en-US", {
1414
1520
  style: "currency",
1415
1521
  currency: "USD",
@@ -2191,14 +2297,6 @@ function useOpen({ open, defaultOpen, onOpenChange }, fallback = false) {
2191
2297
  if (!details.isCanceled) setValue(next);
2192
2298
  }];
2193
2299
  }
2194
- function parseJson(value) {
2195
- if (typeof value !== "string") return value;
2196
- try {
2197
- return parsePartialJSON$1(value) ?? value;
2198
- } catch {
2199
- return value;
2200
- }
2201
- }
2202
2300
  function jsonBlock(value) {
2203
2301
  return `\`\`\`json\n${JSON.stringify(value, null, 2)}\n\`\`\``;
2204
2302
  }
@@ -2232,7 +2330,7 @@ function ToolCallCard({ part, result, interrupt: _interrupt, streaming = false,
2232
2330
  if (state.approvalRequested && !was) openForApproval();
2233
2331
  }, [state.approvalRequested]);
2234
2332
  const stateLabel = state.error ? labels.toolFailed : state.complete ? labels.toolDone : state.approvalRequested ? labels.toolApprovalRequested : state.approvalResponded ? part.approval?.approved === false ? labels.toolDenied : labels.toolApproved : part.state === "input-complete" ? labels.toolRunning : labels.toolPending;
2235
- const input = part.input ?? (part.arguments === "" ? void 0 : parseJson(part.arguments));
2333
+ const input = part.input ?? (part.arguments === "" ? void 0 : parseToolJson(part.arguments));
2236
2334
  const output = part.output ?? result?.content;
2237
2335
  const error = result?.error;
2238
2336
  return /* @__PURE__ */ jsxs(Collapsible, {
@@ -2289,7 +2387,7 @@ function ToolCallCard({ part, result, interrupt: _interrupt, streaming = false,
2289
2387
  content: jsonBlock(input),
2290
2388
  streaming: state.pending && streaming
2291
2389
  }),
2292
- output !== void 0 && /* @__PURE__ */ jsx(Markdown, { content: jsonBlock(parseJson(output)) }),
2390
+ output !== void 0 && /* @__PURE__ */ jsx(Markdown, { content: jsonBlock(parseToolJson(output)) }),
2293
2391
  error !== void 0 && /* @__PURE__ */ jsx("p", {
2294
2392
  "data-slot": "tool-call-error",
2295
2393
  className: "text-destructive",
@@ -2516,12 +2614,13 @@ function TranscriptParts({ message, className }) {
2516
2614
  }
2517
2615
  return out;
2518
2616
  };
2617
+ const ownsCard = (part) => renderers.toolCall?.[part.name] !== void 0;
2519
2618
  const nodes = [];
2520
2619
  let index = 0;
2521
2620
  while (index <= lastIndex) {
2522
2621
  const part = message.parts[index];
2523
2622
  if (part.type === "tool-call") {
2524
- if (providerExecuted(part)) {
2623
+ if (providerExecuted(part) || ownsCard(part)) {
2525
2624
  nodes.push(/* @__PURE__ */ jsx("div", { children: renderTool(part, index) }, part.id));
2526
2625
  let next = index + 1;
2527
2626
  while (next <= lastIndex && message.parts[next].type === "tool-result") next += 1;
@@ -2534,7 +2633,7 @@ function TranscriptParts({ message, className }) {
2534
2633
  while (cursor <= lastIndex) {
2535
2634
  const next = message.parts[cursor];
2536
2635
  if (next.type === "tool-call") {
2537
- if (providerExecuted(next)) break;
2636
+ if (providerExecuted(next) || ownsCard(next)) break;
2538
2637
  run.push([next, cursor]);
2539
2638
  } else if (next.type !== "tool-result") break;
2540
2639
  cursor += 1;
@@ -2691,6 +2790,24 @@ const DEFAULT_USAGE_STATS_LABELS = {
2691
2790
  document: "Document"
2692
2791
  }
2693
2792
  };
2793
+ /** `DEFAULT_USAGE_STATS_LABELS` in Chinese. */
2794
+ const ZH_USAGE_STATS_LABELS = {
2795
+ cacheHit: "缓存命中",
2796
+ cacheWrite: "缓存写入",
2797
+ outputRatio: "输出 / 输入",
2798
+ reasoningShare: "推理占比",
2799
+ contextUsed: "上下文占用",
2800
+ cacheSaved: "缓存节省",
2801
+ promptModalities: "输入模态",
2802
+ completionModalities: "输出模态",
2803
+ modality: {
2804
+ text: "文本",
2805
+ image: "图片",
2806
+ audio: "音频",
2807
+ video: "视频",
2808
+ document: "文档"
2809
+ }
2810
+ };
2694
2811
  const PERCENT = new Intl.NumberFormat("en-US", {
2695
2812
  style: "percent",
2696
2813
  maximumFractionDigits: 1
@@ -2806,4 +2923,4 @@ function UsageStats({ usage, model, labels: labelsProp, className }) {
2806
2923
  });
2807
2924
  }
2808
2925
  //#endregion
2809
- export { ApprovalActions, ApprovalApprove, ApprovalDeny, ByokKeyDialog, ByokKeyDialogProvider, Composer, ComposerAttach, ComposerAttachments, ComposerDictate, ComposerSubmit, ComposerTextarea, ComposerToolbar, ContextUsage, DEFAULT_BYOK_KEY_DIALOG_LABELS, DEFAULT_CONTEXT_USAGE_LABELS, DEFAULT_MAX_ATTACHMENT_BYTES, DEFAULT_PART_LABELS, DEFAULT_USAGE_STATS_LABELS, EventType, Markdown, MediaPart, ModelPicker, PartRenderersProvider, QueueList, Reasoning, SearchToggle, Sources, StructuredOutput, Suggestions, SuggestionsItem, THINKING_LEVELS, ThinkingLevelPicker, ThinkingToggle, ThreadList, ThreadListArchive, ThreadListDelete, ThreadListGroup, ThreadListGroupLabel, ThreadListItem, ThreadListNew, ThreadListRename, ToolCallCard, ToolCallGroup, ToolCallGroupTrigger, Transcript, TranscriptAction, TranscriptActions, TranscriptEmpty, TranscriptError, TranscriptMessage, TranscriptParts, TranscriptPending, TranscriptProvider, UsageStats, addTokenUsage, attachmentKindOf, clampThinkingLevel, createByok, createCatalog, createThreadIndex, defaultByokStorage, defaultCatalog, defineByok, definePartRenderers, editAndResend, estimateCost, fileToContentPart, fromSpecTokenUsage, generateMessageId, groupThreadsByDay, isByokError, isPasskeyStorageSupported, isThinkingComplete, memoryStorage, messageText, messagesToMarkdown, modelRef, newThreadId, parseModelRef, parsePartialJSON, passkeyStorage, providers, sourcesOf, supportedThinkingLevels, threadPersistence, threadTitleFrom, toolDefinition, usageMetrics, useAttachmentDraft, useComposer, useModelSelection, usePartRenderers, useServerCoverage, useStoredState, useThreadIndex, useThreadListItem, useTranscript, useUsageTracker };
2926
+ export { ApprovalActions, ApprovalApprove, ApprovalDeny, ByokKeyDialog, ByokKeyDialogProvider, Composer, ComposerAttach, ComposerAttachments, ComposerDictate, ComposerSubmit, ComposerTextarea, ComposerToolbar, ContextUsage, DEFAULT_BYOK_KEY_DIALOG_LABELS, DEFAULT_CONTEXT_USAGE_LABELS, DEFAULT_MAX_ATTACHMENT_BYTES, DEFAULT_PART_LABELS, DEFAULT_USAGE_STATS_LABELS, EventType, Markdown, MediaPart, ModelPicker, PartRenderersProvider, QueueList, Reasoning, SearchToggle, Sources, StructuredOutput, Suggestions, SuggestionsItem, THINKING_LEVELS, ThinkingLevelPicker, ThinkingToggle, ThreadList, ThreadListArchive, ThreadListDelete, ThreadListGroup, ThreadListGroupLabel, ThreadListItem, ThreadListNew, ThreadListRename, ToolCallCard, ToolCallGroup, ToolCallGroupTrigger, Transcript, TranscriptAction, TranscriptActions, TranscriptEmpty, TranscriptError, TranscriptMessage, TranscriptParts, TranscriptPending, TranscriptProvider, UsageStats, ZH_BYOK_KEY_DIALOG_LABELS, ZH_CONTEXT_USAGE_LABELS, ZH_PART_LABELS, ZH_USAGE_STATS_LABELS, addTokenUsage, attachmentKindOf, clampThinkingLevel, createByok, createCatalog, createThreadIndex, defaultByokStorage, defaultCatalog, defineByok, definePartRenderers, editAndResend, estimateCost, fileToContentPart, fromSpecTokenUsage, generateMessageId, groupThreadsByDay, isByokError, isPasskeyStorageSupported, isThinkingComplete, memoryStorage, messageText, messagesToMarkdown, modelRef, newThreadId, nextMessageKeys, parseModelRef, parsePartialJSON, passkeyStorage, providers, sourcesOf, supportedThinkingLevels, threadPersistence, threadTitleFrom, toolDefinition, toolInput, usageMetrics, useAttachmentDraft, useComposer, useMessageKeys, useModelSelection, usePartRenderers, useServerCoverage, useStoredState, useThreadIndex, useThreadListItem, useTranscript, useUsageTracker };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gedatou/cadenza-ai",
3
3
  "type": "module",
4
- "version": "0.7.1",
4
+ "version": "0.7.4",
5
5
  "description": "Thin TanStack AI facade — provider-agnostic chat runtime, conventions and conversation views built on cadenza-ui",
6
6
  "license": "MIT",
7
7
  "homepage": "https://cadenza-ui-docs.vercel.app",
@@ -36,14 +36,7 @@
36
36
  "dist",
37
37
  "styles.css"
38
38
  ],
39
- "scripts": {
40
- "build": "tsdown",
41
- "dev": "tsdown --watch",
42
- "typecheck": "tsc",
43
- "prepack": "pnpm run build"
44
- },
45
39
  "peerDependencies": {
46
- "@gedatou/cadenza-ui": "workspace:^",
47
40
  "@tanstack/ai-anthropic": "*",
48
41
  "@tanstack/ai-bedrock": "*",
49
42
  "@tanstack/ai-gemini": "*",
@@ -59,56 +52,88 @@
59
52
  "@tanstack/ai-vertex": "*",
60
53
  "react": ">=19",
61
54
  "react-dom": ">=19",
62
- "tailwindcss": ">=4"
55
+ "tailwindcss": ">=4",
56
+ "@gedatou/cadenza-ui": "^0.7.4"
63
57
  },
64
58
  "peerDependenciesMeta": {
65
- "@tanstack/ai-anthropic": { "optional": true },
66
- "@tanstack/ai-bedrock": { "optional": true },
67
- "@tanstack/ai-gemini": { "optional": true },
68
- "@tanstack/ai-grok": { "optional": true },
69
- "@tanstack/ai-groq": { "optional": true },
70
- "@tanstack/ai-llmgateway": { "optional": true },
71
- "@tanstack/ai-mistral": { "optional": true },
72
- "@tanstack/ai-ollama": { "optional": true },
73
- "@tanstack/ai-openai": { "optional": true },
74
- "@tanstack/ai-openrouter": { "optional": true },
75
- "@tanstack/ai-persistence": { "optional": true },
76
- "@tanstack/ai-vercel-gateway": { "optional": true },
77
- "@tanstack/ai-vertex": { "optional": true }
59
+ "@tanstack/ai-anthropic": {
60
+ "optional": true
61
+ },
62
+ "@tanstack/ai-bedrock": {
63
+ "optional": true
64
+ },
65
+ "@tanstack/ai-gemini": {
66
+ "optional": true
67
+ },
68
+ "@tanstack/ai-grok": {
69
+ "optional": true
70
+ },
71
+ "@tanstack/ai-groq": {
72
+ "optional": true
73
+ },
74
+ "@tanstack/ai-llmgateway": {
75
+ "optional": true
76
+ },
77
+ "@tanstack/ai-mistral": {
78
+ "optional": true
79
+ },
80
+ "@tanstack/ai-ollama": {
81
+ "optional": true
82
+ },
83
+ "@tanstack/ai-openai": {
84
+ "optional": true
85
+ },
86
+ "@tanstack/ai-openrouter": {
87
+ "optional": true
88
+ },
89
+ "@tanstack/ai-persistence": {
90
+ "optional": true
91
+ },
92
+ "@tanstack/ai-vercel-gateway": {
93
+ "optional": true
94
+ },
95
+ "@tanstack/ai-vertex": {
96
+ "optional": true
97
+ }
78
98
  },
79
99
  "dependencies": {
80
- "@gedatou/cadenza-utils": "workspace:*",
81
- "@streamdown/cjk": "catalog:ui",
82
- "@streamdown/code": "catalog:ui",
83
- "@streamdown/math": "catalog:ui",
84
- "@tabler/icons-react": "catalog:ui",
85
- "@tanstack/ai": "catalog:ui",
86
- "@tanstack/ai-client": "catalog:ui",
87
- "@tanstack/ai-react": "catalog:ui",
88
- "katex": "catalog:ui",
89
- "streamdown": "catalog:ui"
100
+ "@streamdown/cjk": "^1.0.3",
101
+ "@streamdown/code": "^1.1.1",
102
+ "@streamdown/math": "^1.0.2",
103
+ "@tabler/icons-react": "^3.46.0",
104
+ "@tanstack/ai": "^0.51.0",
105
+ "@tanstack/ai-client": "^0.29.1",
106
+ "@tanstack/ai-react": "^0.22.3",
107
+ "katex": "^0.18.4",
108
+ "streamdown": "^2.6.0",
109
+ "@gedatou/cadenza-utils": "0.7.4"
90
110
  },
91
111
  "devDependencies": {
92
- "@gedatou/cadenza-ui": "workspace:*",
93
- "@tanstack/ai-anthropic": "catalog:ui",
94
- "@tanstack/ai-bedrock": "catalog:ui",
95
- "@tanstack/ai-gemini": "catalog:ui",
96
- "@tanstack/ai-grok": "catalog:ui",
97
- "@tanstack/ai-groq": "catalog:ui",
98
- "@tanstack/ai-llmgateway": "catalog:ui",
99
- "@tanstack/ai-mistral": "catalog:ui",
100
- "@tanstack/ai-ollama": "catalog:ui",
101
- "@tanstack/ai-openai": "catalog:ui",
102
- "@tanstack/ai-openrouter": "catalog:ui",
103
- "@tanstack/ai-persistence": "catalog:ui",
104
- "@tanstack/ai-vercel-gateway": "catalog:ui",
105
- "@tanstack/ai-vertex": "catalog:ui",
106
- "@testing-library/react": "catalog:testing",
107
- "@testing-library/user-event": "catalog:testing",
108
- "@types/node": "catalog:types",
109
- "react": "catalog:react",
110
- "react-dom": "catalog:react",
111
- "tsdown": "catalog:cli",
112
- "typescript": "catalog:cli"
112
+ "@tanstack/ai-anthropic": "^0.18.2",
113
+ "@tanstack/ai-bedrock": "^0.3.2",
114
+ "@tanstack/ai-gemini": "^0.26.3",
115
+ "@tanstack/ai-grok": "^0.18.2",
116
+ "@tanstack/ai-groq": "^0.7.2",
117
+ "@tanstack/ai-llmgateway": "^0.1.4",
118
+ "@tanstack/ai-mistral": "^0.5.2",
119
+ "@tanstack/ai-ollama": "^0.10.2",
120
+ "@tanstack/ai-openai": "^0.22.2",
121
+ "@tanstack/ai-openrouter": "^0.19.4",
122
+ "@tanstack/ai-persistence": "^0.5.3",
123
+ "@tanstack/ai-vercel-gateway": "^0.2.4",
124
+ "@tanstack/ai-vertex": "^0.2.4",
125
+ "@testing-library/react": "^16.3.2",
126
+ "@testing-library/user-event": "^14.6.3",
127
+ "@types/node": "^26.2.0",
128
+ "react": "^19.2.8",
129
+ "react-dom": "^19.2.8",
130
+ "tsdown": "^0.22.14",
131
+ "typescript": "^6.0.3",
132
+ "@gedatou/cadenza-ui": "0.7.4"
133
+ },
134
+ "scripts": {
135
+ "build": "tsdown",
136
+ "dev": "tsdown --watch",
137
+ "typecheck": "tsc"
113
138
  }
114
- }
139
+ }