diff --git a/src/app-server/protocol/catalog.ts b/src/app-server/protocol/catalog.ts index 1eaa7731..472307df 100644 --- a/src/app-server/protocol/catalog.ts +++ b/src/app-server/protocol/catalog.ts @@ -36,14 +36,16 @@ export interface CatalogHookMetadata { enabled: boolean; isManaged: boolean; currentHash: string; - trustStatus: HookItem["trustStatus"]; + trustStatus: AppServerHookTrustStatus; [key: string]: unknown; } +type AppServerHookTrustStatus = "managed" | "untrusted" | "trusted" | "modified"; + export interface AppServerHookOperation { key: string; currentHash: string; - trustStatus: HookItem["trustStatus"]; + trustStatus: AppServerHookTrustStatus; } function modelMetadataFromCatalogModel(model: CatalogModel): ModelMetadata { @@ -93,7 +95,7 @@ function hookItemFromCatalogHook(hook: CatalogHookMetadata): HookItem { enabled: hook.enabled, isManaged: hook.isManaged, currentHash: hook.currentHash, - trustStatus: hook.trustStatus, + trustStatus: hookTrustStatusFromCatalogTrustStatus(hook.trustStatus), }; } @@ -105,6 +107,14 @@ export function appServerHookOperationFromHookItem(hook: HookItem): AppServerHoo return { key: hook.key, currentHash: hook.currentHash, - trustStatus: hook.trustStatus, + trustStatus: appServerHookTrustStatus(hook.trustStatus), }; } + +function hookTrustStatusFromCatalogTrustStatus(status: AppServerHookTrustStatus): HookItem["trustStatus"] { + return status; +} + +function appServerHookTrustStatus(status: HookItem["trustStatus"]): AppServerHookTrustStatus { + return status; +} diff --git a/src/app-server/protocol/request-input.ts b/src/app-server/protocol/request-input.ts index 52b0e51b..46bc99ee 100644 --- a/src/app-server/protocol/request-input.ts +++ b/src/app-server/protocol/request-input.ts @@ -1,9 +1,11 @@ import type { CodexInputItem } from "../../domain/chat/input"; +type AppServerUserInputImageDetail = "auto" | "low" | "high" | "original"; + type AppServerUserInput = | { type: "text"; text: string; text_elements: [] } - | { type: "image"; detail?: "auto" | "low" | "high" | "original"; url: string } - | { type: "localImage"; detail?: "auto" | "low" | "high" | "original"; path: string } + | { type: "image"; detail?: AppServerUserInputImageDetail; url: string } + | { type: "localImage"; detail?: AppServerUserInputImageDetail; path: string } | { type: "skill"; name: string; path: string } | { type: "mention"; name: string; path: string }; @@ -13,11 +15,7 @@ interface AppServerAdditionalContextEntry { } export function toAppServerUserInput(input: readonly CodexInputItem[]): AppServerUserInput[] { - return input.flatMap((item) => { - if (item.type === "text") return { type: "text", text: item.text, text_elements: [] }; - if (item.type === "additionalContext") return []; - return { ...item }; - }); + return input.flatMap((item) => appServerUserInputItemFromCodexInputItem(item)); } export function additionalContextFromCodexInput( @@ -31,3 +29,32 @@ export function additionalContextFromCodexInput( } return Object.keys(additionalContext).length > 0 ? additionalContext : undefined; } + +function appServerUserInputItemFromCodexInputItem(item: CodexInputItem): AppServerUserInput[] { + switch (item.type) { + case "text": + return [{ type: "text", text: item.text, text_elements: [] }]; + case "image": + return [{ type: "image", url: item.url, ...appServerImageDetailProp(item.detail) }]; + case "localImage": + return [{ type: "localImage", path: item.path, ...appServerImageDetailProp(item.detail) }]; + case "skill": + return [{ type: "skill", name: item.name, path: item.path }]; + case "mention": + return [{ type: "mention", name: item.name, path: item.path }]; + case "additionalContext": + return []; + } +} + +function appServerImageDetailProp(detail: Extract["detail"]): { + detail?: AppServerUserInputImageDetail; +} { + return detail === undefined ? {} : { detail: appServerUserInputImageDetail(detail) }; +} + +function appServerUserInputImageDetail( + detail: NonNullable["detail"]>, +): AppServerUserInputImageDetail { + return detail; +}