@gedatou/cadenza-ai 0.7.3 → 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/dist/index.d.mts +41 -1
- package/dist/index.mjs +131 -14
- package/package.json +4 -4
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 :
|
|
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(
|
|
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.
|
|
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",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"react": ">=19",
|
|
54
54
|
"react-dom": ">=19",
|
|
55
55
|
"tailwindcss": ">=4",
|
|
56
|
-
"@gedatou/cadenza-ui": "^0.7.
|
|
56
|
+
"@gedatou/cadenza-ui": "^0.7.4"
|
|
57
57
|
},
|
|
58
58
|
"peerDependenciesMeta": {
|
|
59
59
|
"@tanstack/ai-anthropic": {
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"@tanstack/ai-react": "^0.22.3",
|
|
107
107
|
"katex": "^0.18.4",
|
|
108
108
|
"streamdown": "^2.6.0",
|
|
109
|
-
"@gedatou/cadenza-utils": "0.7.
|
|
109
|
+
"@gedatou/cadenza-utils": "0.7.4"
|
|
110
110
|
},
|
|
111
111
|
"devDependencies": {
|
|
112
112
|
"@tanstack/ai-anthropic": "^0.18.2",
|
|
@@ -129,7 +129,7 @@
|
|
|
129
129
|
"react-dom": "^19.2.8",
|
|
130
130
|
"tsdown": "^0.22.14",
|
|
131
131
|
"typescript": "^6.0.3",
|
|
132
|
-
"@gedatou/cadenza-ui": "0.7.
|
|
132
|
+
"@gedatou/cadenza-ui": "0.7.4"
|
|
133
133
|
},
|
|
134
134
|
"scripts": {
|
|
135
135
|
"build": "tsdown",
|