{"version":3,"file":"ai.mjs","names":[],"sources":["../src/lib/ai/index.ts"],"sourcesContent":["import type { OpenAIChatCompletionsTextAdapter, OpenAIChatModel } from \"@tanstack/ai-openai\";\n\n/**\n * Text adapter for the Wistron AI gateway; create it per request in a server function\n * (`getAppToken` caches the token). Chat Completions, not Responses: the gateway load-balances\n * Azure deployments, and Responses replays encrypted reasoning that other deployments cannot read\n * (400 invalid_encrypted_content).\n */\nexport const chatAdapter = async <TModel extends OpenAIChatModel>(\n  model: TModel,\n): Promise<OpenAIChatCompletionsTextAdapter<TModel>> => {\n  // Imported on call: `wcz-layout/ai` is also reachable from the browser, which must not pull in\n  // the OpenAI SDK or the server-only token code.\n  const [{ createOpenaiChatCompletions }, { getAppToken }, { serverEnv }] = await Promise.all([\n    import(\"@tanstack/ai-openai\"),\n    import(\"~/lib/auth/tokens\"),\n    import(\"~/env\"),\n  ]);\n  const { AI_BASE_URL, AI_SUBSCRIPTION_KEY } = serverEnv;\n  // Optional in the library's env, since only apps with AI features set them.\n  if (!AI_BASE_URL || !AI_SUBSCRIPTION_KEY)\n    throw new Error(\"chatAdapter needs AI_BASE_URL and AI_SUBSCRIPTION_KEY in the environment.\");\n\n  return createOpenaiChatCompletions(model, await getAppToken(\"cognitiveServices\"), {\n    baseURL: AI_BASE_URL,\n    defaultHeaders: { \"Ocp-Apim-Subscription-Key\": AI_SUBSCRIPTION_KEY },\n    // show_ui and ask_user take any MUI props, so they can never be strict; chat() hands the\n    // adapter fresh tool objects on every model call, so the warning would repeat on each one.\n    strictFallbackWarning: false,\n  });\n};\n"],"mappings":";;;;;;;AAQA,MAAa,cAAc,OACzB,UACsD;CAGtD,MAAM,CAAC,EAAE,+BAA+B,EAAE,eAAe,EAAE,eAAe,MAAM,QAAQ,IAAI;EAC1F,OAAO;EACP,OAAO,wBAAA,CAAA,MAAA,MAAA,EAAA,CAAA;EACP,OAAO,qBAAA,CAAA,MAAA,MAAA,EAAA,CAAA;CACT,CAAC;CACD,MAAM,EAAE,aAAa,wBAAwB;CAE7C,IAAI,CAAC,eAAe,CAAC,qBACnB,MAAM,IAAI,MAAM,2EAA2E;CAE7F,OAAO,4BAA4B,OAAO,MAAM,YAAY,mBAAmB,GAAG;EAChF,SAAS;EACT,gBAAgB,EAAE,6BAA6B,oBAAoB;EAGnE,uBAAuB;CACzB,CAAC;AACH"}