feat: polish release v2 experience (#6800)
This commit is contained in:
1 parent
925b0fb801
commit
a4a903d7c3
295 files changed
+10627
-7115
No files matched your search
@@ -1,9 +1,8 @@
|
||||
import type { UIMessage } from "ai";
|
||||
|
||||
const inlineAttachmentUrlPattern = /^data:[^,]+;base64,/u;
|
||||
import { isRecord } from "@homarr/common";
|
||||
|
||||
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
||||
typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
const inlineAttachmentUrlPattern = /^data:[^,]+;base64,/u;
|
||||
|
||||
const isFilePart = (value: unknown): value is Record<string, unknown> & { type: "file" } =>
|
||||
isRecord(value) && value.type === "file";
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { isRecord } from "@homarr/common";
|
||||
|
||||
export interface AssistantConversationExportMessage {
|
||||
id: string;
|
||||
parentId: string | null;
|
||||
@@ -25,8 +27,7 @@ const bearerTokenPattern = /\bBearer\s+[A-Za-z0-9._~+/-]{16,}=*/giu;
|
||||
const commonApiKeyPattern = /\bsk-(?:or-v1-)?[A-Za-z0-9_-]{16,}\b/giu;
|
||||
const maxDebugStringLength = 12_000;
|
||||
|
||||
const asRecord = (value: unknown): Record<string, unknown> | null =>
|
||||
typeof value === "object" && value !== null && !Array.isArray(value) ? (value as Record<string, unknown>) : null;
|
||||
const asRecord = (value: unknown): Record<string, unknown> | null => (isRecord(value) ? value : null);
|
||||
|
||||
const redactDebugValue = (value: unknown, key?: string): unknown => {
|
||||
if (key && sensitiveKeyPattern.test(key)) return "[redacted]";
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import type { UIMessage } from "ai";
|
||||
|
||||
import { isRecord } from "@homarr/common";
|
||||
|
||||
export type AssistantUsage = {
|
||||
inputTokens?: number;
|
||||
outputTokens?: number;
|
||||
@@ -140,12 +142,11 @@ const getWebSearchSources = (value: unknown): AssistantWebSearchSource[] => {
|
||||
if (!Array.isArray(value)) return [];
|
||||
const sources = new Map<string, AssistantWebSearchSource>();
|
||||
for (const item of value) {
|
||||
if (!item || typeof item !== "object" || Array.isArray(item)) continue;
|
||||
const candidate = item as Record<string, unknown>;
|
||||
if (typeof candidate.url !== "string" || !URL.canParse(candidate.url)) continue;
|
||||
const url = new URL(candidate.url);
|
||||
if (!isRecord(item)) continue;
|
||||
if (typeof item.url !== "string" || !URL.canParse(item.url)) continue;
|
||||
const url = new URL(item.url);
|
||||
if ((url.protocol !== "http:" && url.protocol !== "https:") || url.username || url.password) continue;
|
||||
const title = typeof candidate.title === "string" ? candidate.title.trim().slice(0, 200) : "";
|
||||
const title = typeof item.title === "string" ? item.title.trim().slice(0, 200) : "";
|
||||
if (!sources.has(url.href)) sources.set(url.href, { url: url.href, ...(title ? { title } : {}) });
|
||||
if (sources.size >= 12) break;
|
||||
}
|
||||
@@ -153,10 +154,10 @@ const getWebSearchSources = (value: unknown): AssistantWebSearchSource[] => {
|
||||
};
|
||||
|
||||
export const getAssistantUsage = (metadata: unknown): AssistantUsage | null => {
|
||||
if (!metadata || typeof metadata !== "object" || Array.isArray(metadata) || !("usage" in metadata)) return null;
|
||||
if (!isRecord(metadata) || !("usage" in metadata)) return null;
|
||||
const usage = metadata.usage;
|
||||
if (!usage || typeof usage !== "object" || Array.isArray(usage)) return null;
|
||||
const value = usage as Record<string, unknown>;
|
||||
if (!isRecord(usage)) return null;
|
||||
const value = usage;
|
||||
return {
|
||||
...(getFiniteNonNegativeNumber(value.inputTokens) !== undefined
|
||||
? { inputTokens: getFiniteNonNegativeNumber(value.inputTokens) }
|
||||
@@ -180,11 +181,11 @@ export const getAssistantUsage = (metadata: unknown): AssistantUsage | null => {
|
||||
};
|
||||
|
||||
export const getAssistantTelemetry = (metadata: unknown): AssistantRequestTelemetry | null => {
|
||||
if (!metadata || typeof metadata !== "object" || Array.isArray(metadata)) return null;
|
||||
const custom = (metadata as { custom?: unknown }).custom;
|
||||
if (!custom || typeof custom !== "object" || Array.isArray(custom)) return null;
|
||||
const telemetry = (custom as { telemetry?: unknown }).telemetry;
|
||||
if (!telemetry || typeof telemetry !== "object" || Array.isArray(telemetry)) return null;
|
||||
if (!isRecord(metadata)) return null;
|
||||
const custom = metadata.custom;
|
||||
if (!isRecord(custom)) return null;
|
||||
const telemetry = custom.telemetry;
|
||||
if (!isRecord(telemetry)) return null;
|
||||
const value = telemetry as Partial<AssistantRequestTelemetry>;
|
||||
if (
|
||||
typeof value.requestId !== "string" ||
|
||||
@@ -196,8 +197,8 @@ export const getAssistantTelemetry = (metadata: unknown): AssistantRequestTeleme
|
||||
}
|
||||
const steps = Array.isArray(value.steps)
|
||||
? value.steps.flatMap((step): AssistantRequestStep[] => {
|
||||
if (!step || typeof step !== "object" || Array.isArray(step)) return [];
|
||||
const candidate = step as Record<string, unknown>;
|
||||
if (!isRecord(step)) return [];
|
||||
const candidate = step;
|
||||
const index = getFiniteNonNegativeNumber(candidate.index);
|
||||
const durationMs = getFiniteNonNegativeNumber(candidate.durationMs);
|
||||
const modelDurationMs = getFiniteNonNegativeNumber(candidate.modelDurationMs);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const asRecord = (value: unknown): Record<string, unknown> | null =>
|
||||
typeof value === "object" && value !== null && !Array.isArray(value) ? (value as Record<string, unknown>) : null;
|
||||
import { isRecord } from "@homarr/common";
|
||||
|
||||
const asRecord = (value: unknown): Record<string, unknown> | null => (isRecord(value) ? value : null);
|
||||
|
||||
export const getAssistantIconSearchQuery = (toolName: string, args: unknown) => {
|
||||
if (toolName !== "icon_findIcons") return null;
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
import { IconCheck, IconChevronDown, IconLink, IconRobot, IconX } from "@tabler/icons-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
import { isRecord } from "@homarr/common";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
|
||||
import classes from "./assistant-panel.module.css";
|
||||
@@ -154,9 +155,9 @@ const ToolResultPresentation = ({ result, toolName }: { result: unknown; toolNam
|
||||
};
|
||||
|
||||
const getToolResultNavigation = (result: unknown) => {
|
||||
if (typeof result !== "object" || result === null || Array.isArray(result)) return [];
|
||||
if (!isRecord(result)) return [];
|
||||
|
||||
const record = result as Record<string, unknown>;
|
||||
const record = result;
|
||||
const candidates = [
|
||||
{ href: record.previewPath, translationKey: "toolNavigation.openPreview" as const },
|
||||
{ href: record.managementPath, translationKey: "toolNavigation.openWidget" as const },
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { isRecord } from "@homarr/common";
|
||||
|
||||
const collectionKeys = [
|
||||
"items",
|
||||
"results",
|
||||
@@ -86,8 +88,7 @@ interface ToolResultPresentationOptions {
|
||||
toolName?: string;
|
||||
}
|
||||
|
||||
const asRecord = (value: unknown): Record<string, unknown> | undefined =>
|
||||
typeof value === "object" && value !== null && !Array.isArray(value) ? (value as Record<string, unknown>) : undefined;
|
||||
const asRecord = (value: unknown): Record<string, unknown> | undefined => (isRecord(value) ? value : undefined);
|
||||
|
||||
const toDisplayValue = (value: unknown): ToolResultPrimitive | undefined => {
|
||||
if (typeof value === "string") {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { isRecord } from "@homarr/common";
|
||||
|
||||
const targetKeys = ["name", "title", "query", "searchText", "appName", "widgetName"] as const;
|
||||
|
||||
export const getAssistantToolTraceTarget = (args: unknown): string | null => {
|
||||
if (!args || typeof args !== "object" || Array.isArray(args)) return null;
|
||||
const record = args as Record<string, unknown>;
|
||||
if (!isRecord(args)) return null;
|
||||
const record = args;
|
||||
|
||||
for (const key of targetKeys) {
|
||||
const value = record[key];
|
||||
|
||||
Reference in new issue
Block a user