2026-06-12 11:08:08 +00:00
|
|
|
import type { CodexInputItem } from "../../domain/chat/input";
|
2026-06-09 22:47:29 +00:00
|
|
|
|
2026-06-18 01:29:42 +00:00
|
|
|
type AppServerUserInputImageDetail = "auto" | "low" | "high" | "original";
|
|
|
|
|
|
2026-06-16 08:08:55 +00:00
|
|
|
type AppServerUserInput =
|
|
|
|
|
| { type: "text"; text: string; text_elements: [] }
|
2026-06-18 01:29:42 +00:00
|
|
|
| { type: "image"; detail?: AppServerUserInputImageDetail; url: string }
|
|
|
|
|
| { type: "localImage"; detail?: AppServerUserInputImageDetail; path: string }
|
2026-06-16 08:08:55 +00:00
|
|
|
| { type: "skill"; name: string; path: string }
|
|
|
|
|
| { type: "mention"; name: string; path: string };
|
2026-06-10 02:49:43 +00:00
|
|
|
|
2026-06-16 08:08:55 +00:00
|
|
|
interface AppServerAdditionalContextEntry {
|
|
|
|
|
value: string;
|
|
|
|
|
kind: "untrusted" | "application";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function toAppServerUserInput(input: readonly CodexInputItem[]): AppServerUserInput[] {
|
2026-06-18 01:29:42 +00:00
|
|
|
return input.flatMap((item) => appServerUserInputItemFromCodexInputItem(item));
|
2026-06-09 22:47:29 +00:00
|
|
|
}
|
2026-06-16 02:01:21 +00:00
|
|
|
|
2026-06-16 08:08:55 +00:00
|
|
|
export function additionalContextFromCodexInput(
|
|
|
|
|
input: readonly CodexInputItem[],
|
|
|
|
|
): Record<string, AppServerAdditionalContextEntry> | undefined {
|
|
|
|
|
const additionalContext: Record<string, AppServerAdditionalContextEntry> = {};
|
2026-06-16 02:01:21 +00:00
|
|
|
for (const item of input) {
|
|
|
|
|
if (item.type !== "additionalContext") continue;
|
|
|
|
|
if (!item.key || !item.value) continue;
|
|
|
|
|
additionalContext[item.key] = { value: item.value, kind: item.kind };
|
|
|
|
|
}
|
|
|
|
|
return Object.keys(additionalContext).length > 0 ? additionalContext : undefined;
|
|
|
|
|
}
|
2026-06-18 01:29:42 +00:00
|
|
|
|
|
|
|
|
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<CodexInputItem, { type: "image" | "localImage" }>["detail"]): {
|
|
|
|
|
detail?: AppServerUserInputImageDetail;
|
|
|
|
|
} {
|
2026-06-27 04:39:14 +00:00
|
|
|
return detail === undefined ? {} : { detail };
|
2026-06-18 01:29:42 +00:00
|
|
|
}
|