Download packages/ai/src/utils/diagnostics.ts from SaylorTwift/pi: direct link, hf CLI and curl.
- Browser
- Download file 1.38 kB
-
https://huggingface.co/SaylorTwift/pi/resolve/main/packages/ai/src/utils/diagnostics.ts
- Command line
-
hf download hf://SaylorTwift/pi/packages/ai/src/utils/diagnostics.ts
-
curl -L -o diagnostics.ts https://huggingface.co/SaylorTwift/pi/resolve/main/packages/ai/src/utils/diagnostics.ts
1.38 kB
| export interface DiagnosticErrorInfo { | |
| name?: string; | |
| message: string; | |
| stack?: string; | |
| code?: string | number; | |
| } | |
| export interface AssistantMessageDiagnostic { | |
| type: string; | |
| timestamp: number; | |
| error?: DiagnosticErrorInfo; | |
| details?: Record<string, unknown>; | |
| } | |
| export function formatThrownValue(value: unknown): string { | |
| if (value instanceof Error) return value.message || value.name; | |
| if (typeof value === "string") return value; | |
| return String(value); | |
| } | |
| export function extractDiagnosticError(error: unknown): DiagnosticErrorInfo { | |
| if (!(error instanceof Error)) return { name: "ThrownValue", message: formatThrownValue(error) }; | |
| const code = (error as Error & { code?: unknown }).code; | |
| return { | |
| name: error.name || undefined, | |
| message: error.message || error.name, | |
| stack: error.stack, | |
| code: typeof code === "string" || typeof code === "number" ? code : undefined, | |
| }; | |
| } | |
| export function createAssistantMessageDiagnostic( | |
| type: string, | |
| error: unknown, | |
| details?: Record<string, unknown>, | |
| ): AssistantMessageDiagnostic { | |
| return { type, timestamp: Date.now(), error: extractDiagnosticError(error), details }; | |
| } | |
| export function appendAssistantMessageDiagnostic<T extends { diagnostics?: AssistantMessageDiagnostic[] }>( | |
| message: T, | |
| diagnostic: AssistantMessageDiagnostic, | |
| ): void { | |
| message.diagnostics = [...(message.diagnostics ?? []), diagnostic]; | |
| } | |