Spaces:
Sleeping
Sleeping
Download backend/src/lib/assistantRouting/requestedMode.ts from bardd/mike-backend: direct link, hf CLI and curl.
- Browser
- Download file 1.67 kB
-
https://huggingface.co/spaces/bardd/mike-backend/resolve/main/backend/src/lib/assistantRouting/requestedMode.ts
- Command line
-
hf download hf://spaces/bardd/mike-backend/backend/src/lib/assistantRouting/requestedMode.ts
-
curl -L -o requestedMode.ts https://huggingface.co/spaces/bardd/mike-backend/resolve/main/backend/src/lib/assistantRouting/requestedMode.ts
1.67 kB
| /** | |
| * Canonical assistant requested-mode ownership. | |
| * | |
| * Source of truth for the `requested_mode` chat request field. During | |
| * migration `documentMode.ts` may re-export these symbols for legacy | |
| * callers; assistant routes must import them from here. | |
| */ | |
| export type RequestedAssistantMode = | |
| | "auto" | |
| | "answer" | |
| | "comments" | |
| | "document_edit" | |
| | "workflow_review" | |
| | "document_generation" | |
| | "web_search"; | |
| export const REQUESTED_ASSISTANT_MODES: readonly RequestedAssistantMode[] = [ | |
| "auto", | |
| "answer", | |
| "comments", | |
| "document_edit", | |
| "workflow_review", | |
| "document_generation", | |
| "web_search", | |
| ]; | |
| /** | |
| * Validate an untrusted `requested_mode` request field. Throws a tagged error | |
| * whose message contains `invalid_requested_mode` so routes can translate it to | |
| * an HTTP 400 before any model/provider/tool/storage/database side effect. | |
| * | |
| * Preserves legacy behavior: | |
| * - missing, null, or empty returns "auto"; | |
| * - any non-matching value throws a tagged error. | |
| */ | |
| export function parseRequestedAssistantMode( | |
| value: unknown, | |
| ): RequestedAssistantMode { | |
| if (value === undefined || value === null || value === "") return "auto"; | |
| if ( | |
| typeof value === "string" && | |
| (REQUESTED_ASSISTANT_MODES as readonly string[]).includes(value) | |
| ) { | |
| return value as RequestedAssistantMode; | |
| } | |
| throw new Error(`invalid_requested_mode: ${String(value)}`); | |
| } | |
| export function isRequestedAssistantMode( | |
| value: unknown, | |
| ): value is RequestedAssistantMode { | |
| return ( | |
| typeof value === "string" && | |
| (REQUESTED_ASSISTANT_MODES as readonly string[]).includes(value) | |
| ); | |
| } | |