@bastani/pi-ai 0.9.39 → 0.9.40-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +2 -0
  3. package/dist/api/azure-openai-responses.d.ts.map +1 -1
  4. package/dist/api/azure-openai-responses.js +6 -2
  5. package/dist/api/azure-openai-responses.js.map +1 -1
  6. package/dist/api/openai-codex-responses.d.ts.map +1 -1
  7. package/dist/api/openai-codex-responses.js +6 -2
  8. package/dist/api/openai-codex-responses.js.map +1 -1
  9. package/dist/api/openai-completions.d.ts.map +1 -1
  10. package/dist/api/openai-completions.js +9 -3
  11. package/dist/api/openai-completions.js.map +1 -1
  12. package/dist/api/openai-responses-shared.d.ts +16 -0
  13. package/dist/api/openai-responses-shared.d.ts.map +1 -1
  14. package/dist/api/openai-responses-shared.js +60 -8
  15. package/dist/api/openai-responses-shared.js.map +1 -1
  16. package/dist/api/openai-responses.d.ts.map +1 -1
  17. package/dist/api/openai-responses.js +2 -2
  18. package/dist/api/openai-responses.js.map +1 -1
  19. package/dist/api/system-one-shared.d.ts +10 -0
  20. package/dist/api/system-one-shared.d.ts.map +1 -1
  21. package/dist/api/system-one-shared.js +34 -4
  22. package/dist/api/system-one-shared.js.map +1 -1
  23. package/dist/api/typesafe-system-one.d.ts.map +1 -1
  24. package/dist/api/typesafe-system-one.js +3 -1
  25. package/dist/api/typesafe-system-one.js.map +1 -1
  26. package/dist/providers/data/.manifest.json +1 -1
  27. package/dist/providers/data/amazon-bedrock.json +1 -1
  28. package/dist/providers/data/azure.json +1 -1
  29. package/dist/providers/data/cloudflare-ai-gateway.json +1 -1
  30. package/dist/providers/data/cloudflare-workers-ai.json +1 -1
  31. package/dist/providers/data/google.json +1 -1
  32. package/dist/providers/data/huggingface.json +1 -1
  33. package/dist/providers/data/minimax-cn.json +1 -1
  34. package/dist/providers/data/minimax.json +1 -1
  35. package/dist/providers/data/mistral.json +1 -1
  36. package/dist/providers/data/moonshotai-cn.json +1 -1
  37. package/dist/providers/data/openai-codex.json +1 -1
  38. package/dist/providers/data/openai.json +1 -1
  39. package/dist/providers/data/opencode-go.json +1 -1
  40. package/dist/providers/data/opencode.json +1 -1
  41. package/dist/providers/data/openrouter.json +1 -1
  42. package/dist/providers/data/qwen-token-plan-cn.json +1 -1
  43. package/dist/providers/data/qwen-token-plan.json +1 -1
  44. package/dist/providers/data/radius.json +1 -1
  45. package/dist/providers/data/together.json +1 -1
  46. package/dist/providers/data/typesafe.json +1 -1
  47. package/dist/providers/data/vercel-ai-gateway.json +1 -1
  48. package/dist/providers/data/xai.json +1 -1
  49. package/dist/utils/overflow.d.ts.map +1 -1
  50. package/dist/utils/overflow.js +5 -1
  51. package/dist/utils/overflow.js.map +1 -1
  52. package/dist/utils/transcript.d.ts +22 -8
  53. package/dist/utils/transcript.d.ts.map +1 -1
  54. package/dist/utils/transcript.js +29 -18
  55. package/dist/utils/transcript.js.map +1 -1
  56. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"openai-responses.js","sourceRoot":"","sources":["../../src/api/openai-responses.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAclD,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrF,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;A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MAAM,GAAG,yBAAyB,KAAK,SAAS,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,mCAAmC,CAAC;YAC/G,MAAM,CAAC,SAAS,GAAG;gBAClB,MAAM,EAAE,MAAwD;gBAChE,OAAO,EAAE,OAAO,EAAE,gBAAgB,IAAI,MAAM;aAC5C,CAAC;YACF,MAAM,CAAC,OAAO,GAAG,CAAC,6BAA6B,CAAC,CAAC;QAClD,CAAC;aAAM,IAAI,KAAK,CAAC,QAAQ,KAAK,gBAAgB,IAAI,KAAK,CAAC,gBAAgB,EAAE,GAAG,KAAK,IAAI,EAAE,CAAC;YACxF,MAAM,CAAC,SAAS,GAAG;gBAClB,MAAM,EAAE,CAAC,KAAK,CAAC,gBAAgB,EAAE,GAAG,IAAI,MAAM,CAAmD;aACjG,CAAC;QACH,CAAC;QACD,IAAI,KAAK,CAAC,QAAQ,KAAK,KAAK;YAAE,MAAM,CAAC,OAAO,GAAG,CAAC,6BAA6B,CAAC,CAAC;IAChF,CAAC;IAED,+EAA+E;IAC/E,MAAM,cAAc,GAAG,qBAAqB,CAAC,KAAK,EAAE,eAAe,IAAI,KAAK,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC;IACvG,IAAI,cAAc,EAAE,CAAC;QACpB,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC;AAED,SAAS,+BAA+B,CACvC,KAAgC,EAChC,kBAAoD;IAEpD,OAAO,2BAA2B,CAAC,KAAK,EAAE,2BAA2B,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC;AACnG,CAAC","sourcesContent":["import type { ResponseCreateParamsStreaming } from \"openai/resources/responses/responses.js\";\nimport { clampThinkingLevel } from \"../models.ts\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tCacheRetention,\n\tModel,\n\tOpenAIResponsesCompat,\n\tProviderEnv,\n\tProviderHeaders,\n\tSimpleStreamOptions,\n\tStreamFunction,\n\tStreamOptions,\n\tTranscriptContext,\n} from \"../types.ts\";\nimport { formatProviderError, normalizeProviderError } from \"../utils/error-body.ts\";\nimport { AssistantMessageEventStream } from \"../utils/event-stream.ts\";\nimport { headersToRecord } from \"../utils/headers.ts\";\nimport { getPiUserAgent } from \"../utils/pi-user-agent.ts\";\nimport { getProviderEnvValue } from \"../utils/provider-env.ts\";\nimport { retryProviderRequest } from \"../utils/provider-retry.ts\";\nimport { getProviderRetryAfterMs } from \"../utils/retry-hints.ts\";\nimport { createStreamDeadline, withStreamDeadline } from \"../utils/stream-deadline.ts\";\nimport { getDeclaredTools, resolveTranscript, resolveTranscriptTools } from \"../utils/transcript.ts\";\nimport { createGrammarToolInputProperties } from \"./constrained-sampling.ts\";\nimport {\n\tbuildCopilotDynamicHeaders,\n\thasCopilotVisionInput,\n\tpreserveCopilotIntegrationHeader,\n} from \"./github-copilot-headers.ts\";\nimport { clampOpenAIPromptCacheKey } from \"./openai-prompt-cache.ts\";\nimport {\n\tappendServiceTierRejectedWarning,\n\tapplyServiceTierPricing,\n\tassertPayloadPreservesFastRoute,\n\tconvertResponsesMessages,\n\tconvertResponsesTools,\n\tisChatGPTSubscriptionToken,\n\tisServiceTierRejection,\n\topenAIServiceTierForRequest,\n\tprocessResponsesStream,\n\ttype ResponsesServiceTier,\n\tresolveChatGPTBackendServiceTier,\n\tresolveRequestedServiceTier,\n} from \"./openai-responses-shared.ts\";\nimport { RetryHintOpenAI } from \"./openai-retry-hint-client.ts\";\nimport { buildBaseOptions, resolveSamplingParams } from \"./simple-options.ts\";\n\nconst OPENAI_TOOL_CALL_PROVIDERS = new Set([\"openai\", \"openai-api\", \"openai-codex\", \"opencode\"]);\n// OpenAI Responses rejects max_output_tokens below 16: https://github.com/earendil-works/pi/issues/6265\nconst OPENAI_RESPONSES_MIN_OUTPUT_TOKENS = 16;\nconst CHATGPT_USAGE_URL = \"https://chatgpt.com/settings/usage\";\nconst CONFIGURATION_UPDATE_REQUEST_EFFORT = \"medium\";\n\nfunction isChatGPTSignIn(model: Model<\"openai-responses\">, apiKey: string | undefined): boolean {\n\treturn (\n\t\tmodel.provider === \"openai\" &&\n\t\tmodel.baseUrl === \"https://api.openai.com/v1\" &&\n\t\tapiKey !== undefined &&\n\t\t!apiKey.startsWith(\"sk-\")\n\t);\n}\n\nfunction headerValue(headers: ProviderHeaders | undefined, name: string): string | undefined {\n\tif (!headers) return undefined;\n\tconst expected = name.toLowerCase();\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tif (key.toLowerCase() === expected && value !== null && value.trim().length > 0) return value.trim();\n\t}\n\treturn undefined;\n}\n\nfunction hasHeader(headers: ProviderHeaders | undefined, name: string): boolean {\n\treturn headerValue(headers, name) !== undefined;\n}\n\nfunction bearerToken(apiKey: string | undefined, headers: ProviderHeaders | undefined): string | undefined {\n\treturn apiKey ?? headerValue(headers, \"authorization\")?.replace(/^Bearer\\s+/i, \"\");\n}\n\nfunction getClientApiKey(provider: string, apiKey: string | undefined, headers: ProviderHeaders | undefined): string {\n\tif (apiKey) return apiKey;\n\tif (hasHeader(headers, \"authorization\") || hasHeader(headers, \"cf-aig-authorization\")) return \"unused\";\n\tthrow new Error(`No API key for provider: ${provider}`);\n}\n\nfunction detectSessionAffinityFormat(model: Pick<Model<\"openai-responses\">, \"provider\" | \"baseUrl\">) {\n\treturn model.provider === \"openrouter\" || model.baseUrl.includes(\"openrouter.ai\") ? \"openrouter\" : \"openai\";\n}\n\n/**\n * Resolve cache retention preference.\n * Defaults to \"short\" and uses PI_CACHE_RETENTION for backward compatibility.\n */\nfunction resolveCacheRetention(cacheRetention?: CacheRetention, env?: ProviderEnv): CacheRetention {\n\tif (cacheRetention) {\n\t\treturn cacheRetention;\n\t}\n\tif (getProviderEnvValue(\"PI_CACHE_RETENTION\", env) === \"long\") {\n\t\treturn \"long\";\n\t}\n\treturn \"short\";\n}\n\nfunction getCompat(model: Model<\"openai-responses\">): Required<OpenAIResponsesCompat> {\n\treturn {\n\t\tsupportsDeveloperRole: model.compat?.supportsDeveloperRole ?? true,\n\t\tsupportsMidConvoSystemMessages: model.compat?.supportsMidConvoSystemMessages ?? false,\n\t\tsessionAffinityFormat: model.compat?.sessionAffinityFormat ?? detectSessionAffinityFormat(model),\n\t\tsupportsLongCacheRetention: model.compat?.supportsLongCacheRetention ?? true,\n\t\tsupportsStrictMode: model.compat?.supportsStrictMode ?? false,\n\t\tsupportsOpenAIGrammarTools: model.compat?.supportsOpenAIGrammarTools ?? false,\n\t\tsupportsAdditionalTools: model.compat?.supportsAdditionalTools ?? false,\n\t\tsupportsToolSearch: model.compat?.supportsToolSearch ?? false,\n\t\tsupportsExplicitPromptCacheMode: model.compat?.supportsExplicitPromptCacheMode ?? false,\n\t\tsupportsMaxOutputTokens: model.compat?.supportsMaxOutputTokens ?? true,\n\t\tsupportsMidConvoEffort: model.compat?.supportsMidConvoEffort ?? false,\n\t};\n}\n\n/** Effort to send in configuration_update items, or undefined to send it as reasoning.effort. */\nfunction getConfigurationUpdateEffort(\n\tmodel: Model<\"openai-responses\">,\n\toptions: OpenAIResponsesOptions | undefined,\n\tcompat: Required<OpenAIResponsesCompat>,\n): string | undefined {\n\tif (\n\t\t!compat.supportsMidConvoEffort ||\n\t\t!options?.reasoningEffort ||\n\t\t// Sign in with ChatGPT rejects configuration_update items.\n\t\tisChatGPTSignIn(model, options.apiKey) ||\n\t\tisChatGPTSubscriptionToken(bearerToken(options.apiKey, options.headers))\n\t) {\n\t\treturn undefined;\n\t}\n\treturn model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;\n}\n\nfunction getPromptCacheRetention(\n\tcompat: Required<OpenAIResponsesCompat>,\n\tcacheRetention: CacheRetention,\n): \"24h\" | undefined {\n\treturn cacheRetention === \"long\" && compat.supportsLongCacheRetention && !compat.supportsExplicitPromptCacheMode\n\t\t? \"24h\"\n\t\t: undefined;\n}\n\nfunction getPromptCacheOptions(\n\tcompat: Required<OpenAIResponsesCompat>,\n\tcacheRetention: CacheRetention,\n): ResponseCreateParamsStreaming[\"prompt_cache_options\"] {\n\tif (!compat.supportsExplicitPromptCacheMode) return undefined;\n\tif (cacheRetention === \"none\") return { mode: \"explicit\" };\n\tif (cacheRetention === \"long\" && compat.supportsLongCacheRetention) return { ttl: \"30m\" };\n\treturn undefined;\n}\n\n// OpenAI Responses-specific options\nexport interface OpenAIResponsesOptions extends StreamOptions {\n\treasoningEffort?: \"minimal\" | \"low\" | \"medium\" | \"high\" | \"xhigh\" | \"max\";\n\treasoningSummary?: \"auto\" | \"detailed\" | \"concise\" | null;\n\tserviceTier?: ResponsesServiceTier;\n\ttoolChoice?: ResponseCreateParamsStreaming[\"tool_choice\"];\n}\n\n/**\n * Generate function for OpenAI Responses API\n */\nexport const stream: StreamFunction<\"openai-responses\", OpenAIResponsesOptions> = (\n\tmodel: Model<\"openai-responses\">,\n\tcontext: TranscriptContext,\n\toptions?: OpenAIResponsesOptions,\n): AssistantMessageEventStream => {\n\tconst stream = new AssistantMessageEventStream();\n\tconst normalizedContext = resolveTranscript(context, getCompat(model).supportsMidConvoSystemMessages);\n\n\t// Start async processing\n\t(async () => {\n\t\tconst compat = getCompat(model);\n\t\tconst configurationUpdateEffort = getConfigurationUpdateEffort(model, options, compat);\n\t\tconst output: AssistantMessage = {\n\t\t\trole: \"assistant\",\n\t\t\tcontent: [],\n\t\t\tapi: model.api as Api,\n\t\t\tprovider: model.provider,\n\t\t\tmodel: model.id,\n\t\t\t...(configurationUpdateEffort === undefined ? {} : { providerThinkingLevel: configurationUpdateEffort }),\n\t\t\tusage: {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\tcacheRead: 0,\n\t\t\t\tcacheWrite: 0,\n\t\t\t\ttotalTokens: 0,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t},\n\t\t\tstopReason: \"pending\",\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\n\t\tconst streamDeadline = createStreamDeadline(options?.streamDeadlineMs, options?.signal);\n\n\t\ttry {\n\t\t\t// Create OpenAI client\n\t\t\tconst apiKey = getClientApiKey(model.provider, options?.apiKey, options?.headers);\n\t\t\tconst chatGPTBackend = isChatGPTSubscriptionToken(bearerToken(options?.apiKey, options?.headers));\n\t\t\tconst cacheRetention = resolveCacheRetention(options?.cacheRetention, options?.env);\n\t\t\tconst cacheSessionId = cacheRetention === \"none\" ? undefined : options?.sessionId;\n\t\t\tconst grammarToolInputProperties = createGrammarToolInputProperties(\n\t\t\t\tgetDeclaredTools(normalizedContext.messages),\n\t\t\t\tcompat.supportsOpenAIGrammarTools,\n\t\t\t);\n\t\t\tconst client = createClient(\n\t\t\t\tmodel,\n\t\t\t\tnormalizedContext,\n\t\t\t\tapiKey,\n\t\t\t\toptions?.headers,\n\t\t\t\toptions?.fetch,\n\t\t\t\tcacheSessionId,\n\t\t\t\toptions?.apiKey,\n\t\t\t);\n\t\t\tlet params = buildParams(\n\t\t\t\tmodel,\n\t\t\t\tnormalizedContext,\n\t\t\t\toptions,\n\t\t\t\tcompat,\n\t\t\t\tgrammarToolInputProperties,\n\t\t\t\tconfigurationUpdateEffort,\n\t\t\t);\n\t\t\tconst nextParams = await options?.onPayload?.(params, model);\n\t\t\tif (nextParams !== undefined) {\n\t\t\t\tparams = nextParams as ResponseCreateParamsStreaming;\n\t\t\t}\n\t\t\tassertPayloadPreservesFastRoute(model, params);\n\t\t\tconst requestOptions = {\n\t\t\t\t...(streamDeadline.signal ? { signal: streamDeadline.signal } : {}),\n\t\t\t\t...(options?.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {}),\n\t\t\t\tmaxRetries: 0,\n\t\t\t};\n\t\t\tconst sendRequest = (requestParams: ResponseCreateParamsStreaming) =>\n\t\t\t\tretryProviderRequest(() => client.responses.create(requestParams, requestOptions).withResponse(), {\n\t\t\t\t\tmaxRetries: options?.maxRetries,\n\t\t\t\t\tmaxRetryDelayMs: options?.maxRetryDelayMs,\n\t\t\t\t\tsignal: streamDeadline.signal,\n\t\t\t\t});\n\t\t\tlet startEmitted = false;\n\t\t\t// Every attempt reports its HTTP response before its body is consumed, and the message stream starts\n\t\t\t// once. A streamed request reports a rejected service_tier as an `error` event after HTTP 200, so the\n\t\t\t// response preamble is read before the request counts as accepted.\n\t\t\tconst openStream = async (requestParams: ResponseCreateParamsStreaming) => {\n\t\t\t\tconst { data, response } = await sendRequest(requestParams);\n\t\t\t\tawait options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);\n\t\t\t\tif (!startEmitted) {\n\t\t\t\t\tstartEmitted = true;\n\t\t\t\t\tstream.push({ type: \"start\", partial: output });\n\t\t\t\t}\n\t\t\t\treturn readResponsePreamble(withStreamDeadline(data, streamDeadline.deadlineMs, streamDeadline.abort));\n\t\t\t};\n\t\t\tlet requestedServiceTier = resolveOpenAIRequestServiceTier(model, options?.serviceTier);\n\t\t\tlet openaiStream: Awaited<ReturnType<typeof openStream>>;\n\t\t\ttry {\n\t\t\t\topenaiStream = await openStream(params);\n\t\t\t} catch (error) {\n\t\t\t\tif (params.service_tier == null || !isServiceTierRejection(error)) throw error;\n\t\t\t\tconst rejectedServiceTier = params.service_tier;\n\t\t\t\tconst { service_tier: _rejectedServiceTier, ...defaultTierParams } = params;\n\t\t\t\topenaiStream = await openStream(defaultTierParams);\n\t\t\t\trequestedServiceTier = undefined;\n\t\t\t\tappendServiceTierRejectedWarning(output, model, rejectedServiceTier);\n\t\t\t}\n\n\t\t\tawait processResponsesStream(openaiStream, output, stream, model, {\n\t\t\t\tonProviderStreamEvent: options?.onProviderStreamEvent,\n\t\t\t\tserviceTier: requestedServiceTier,\n\t\t\t\tgrammarToolInputProperties,\n\t\t\t\tapplyServiceTierPricing: (usage, serviceTier) => applyServiceTierPricing(usage, serviceTier, model),\n\t\t\t\t...(chatGPTBackend\n\t\t\t\t\t? { resolveServiceTier: resolveChatGPTBackendServiceTier }\n\t\t\t\t\t: { warnOnServiceTierDowngrade: true }),\n\t\t\t});\n\n\t\t\tif (options?.signal?.aborted) {\n\t\t\t\tthrow new Error(\"Request was aborted\");\n\t\t\t}\n\n\t\t\tif (output.stopReason === \"pending\") {\n\t\t\t\tthrow new Error(\"OpenAI Responses stream ended without a stop reason\");\n\t\t\t}\n\t\t\tif (output.stopReason === \"aborted\" || output.stopReason === \"error\") {\n\t\t\t\tthrow new Error(output.errorMessage || \"An unknown error occurred\");\n\t\t\t}\n\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason, message: output });\n\t\t\tstream.end();\n\t\t} catch (error) {\n\t\t\tfor (const block of output.content) {\n\t\t\t\tdelete (block as { index?: number }).index;\n\t\t\t\t// Streaming scratch buffers are only used during parsing; never persist them.\n\t\t\t\tdelete (block as { partialJson?: string }).partialJson;\n\t\t\t\tdelete (block as { customInput?: unknown }).customInput;\n\t\t\t}\n\t\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\toutput.retryAfterMs = error instanceof Error ? getProviderRetryAfterMs(error) : undefined;\n\t\t\tconst errorMessage = formatProviderError(\n\t\t\t\tnormalizeProviderError(error),\n\t\t\t\t`${model.provider === \"openai\" || model.provider === \"openai-api\" ? \"OpenAI\" : model.provider} API error`,\n\t\t\t);\n\t\t\toutput.errorMessage = errorMessage.includes(\"subscription_sharing_usage_limit_exceeded\")\n\t\t\t\t? `${errorMessage}\\nCheck your ChatGPT usage: ${CHATGPT_USAGE_URL}`\n\t\t\t\t: errorMessage;\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason, error: output });\n\t\t\tstream.end();\n\t\t} finally {\n\t\t\tstreamDeadline.cleanup();\n\t\t}\n\t})();\n\n\treturn stream;\n};\n\nconst RESPONSE_PREAMBLE_EVENT_TYPES = new Set([\"response.created\", \"response.in_progress\", \"response.queued\"]);\n\nfunction failedResponseTierRejection(event: { type: string } | undefined): Error | undefined {\n\tif (event?.type !== \"response.failed\") return undefined;\n\tconst failure = (event as { response?: { error?: { code?: string | null; message?: string } | null } }).response\n\t\t?.error;\n\tif (!failure?.message) return undefined;\n\tconst error = new Error(failure.message);\n\treturn isServiceTierRejection(error) ? error : undefined;\n}\n\n/**\n * Read a stream up to its first event after the response preamble, so an error the server raises\n * before producing output is thrown here. Returns a stream that replays every event read.\n */\nasync function readResponsePreamble<T extends { type: string }>(events: AsyncIterable<T>): Promise<AsyncIterable<T>> {\n\tconst iterator = events[Symbol.asyncIterator]();\n\tconst preamble: T[] = [];\n\tlet done = false;\n\ttry {\n\t\tfor (;;) {\n\t\t\tconst next = await iterator.next();\n\t\t\tif (next.done) {\n\t\t\t\tdone = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tpreamble.push(next.value);\n\t\t\tif (!RESPONSE_PREAMBLE_EVENT_TYPES.has(next.value.type)) break;\n\t\t}\n\t} catch (error) {\n\t\tawait iterator.return?.();\n\t\tthrow error;\n\t}\n\tconst tierRejection = failedResponseTierRejection(preamble.at(-1));\n\tif (tierRejection) {\n\t\tawait iterator.return?.();\n\t\tthrow tierRejection;\n\t}\n\treturn (async function* () {\n\t\ttry {\n\t\t\tyield* preamble;\n\t\t\tif (done) return;\n\t\t\tfor (;;) {\n\t\t\t\tconst next = await iterator.next();\n\t\t\t\tif (next.done) return;\n\t\t\t\tyield next.value;\n\t\t\t}\n\t\t} finally {\n\t\t\tawait iterator.return?.();\n\t\t}\n\t})();\n}\n\nexport const streamSimple: StreamFunction<\"openai-responses\", SimpleStreamOptions> = (\n\tmodel: Model<\"openai-responses\">,\n\tcontext: TranscriptContext,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream => {\n\tgetClientApiKey(model.provider, options?.apiKey, options?.headers);\n\n\tconst base = {\n\t\t...buildBaseOptions(model, context, options, options?.apiKey),\n\t\ttoolChoice: options?.toolChoice,\n\t} satisfies OpenAIResponsesOptions;\n\tconst clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : undefined;\n\tconst reasoningEffort = clampedReasoning === \"off\" ? undefined : clampedReasoning;\n\n\treturn stream(model, context, {\n\t\t...base,\n\t\treasoningEffort,\n\t} satisfies OpenAIResponsesOptions);\n};\n\nfunction createClient(\n\tmodel: Model<\"openai-responses\">,\n\tcontext: TranscriptContext,\n\tapiKey: string,\n\toptionsHeaders?: ProviderHeaders,\n\tfetch?: typeof globalThis.fetch,\n\tsessionId?: string,\n\tcopilotApiKey?: string,\n) {\n\tconst compat = getCompat(model);\n\tconst headers: ProviderHeaders = { \"User-Agent\": getPiUserAgent(), ...model.headers };\n\tif (model.provider === \"github-copilot\") {\n\t\tconst hasImages = hasCopilotVisionInput(context.messages);\n\t\tconst copilotHeaders = preserveCopilotIntegrationHeader(\n\t\t\tmodel.headers,\n\t\t\tbuildCopilotDynamicHeaders({\n\t\t\t\tmessages: context.messages,\n\t\t\t\thasImages,\n\t\t\t\tapiKey: copilotApiKey,\n\t\t\t}),\n\t\t);\n\t\tObject.assign(headers, copilotHeaders);\n\t}\n\n\tif (sessionId) {\n\t\tif (compat.sessionAffinityFormat === \"openrouter\") {\n\t\t\theaders[\"x-session-id\"] = sessionId;\n\t\t} else {\n\t\t\tif (compat.sessionAffinityFormat === \"openai\") {\n\t\t\t\theaders.session_id = sessionId;\n\t\t\t}\n\t\t\theaders[\"x-client-request-id\"] = sessionId;\n\t\t}\n\t}\n\n\t// Merge options headers last so they can override defaults\n\tif (optionsHeaders) {\n\t\tObject.assign(headers, optionsHeaders);\n\t}\n\n\treturn new RetryHintOpenAI({\n\t\tapiKey,\n\t\tbaseURL: model.baseUrl,\n\t\tdangerouslyAllowBrowser: true,\n\t\tfetch,\n\t\tdefaultHeaders: headers,\n\t});\n}\n\nfunction buildParams(\n\tmodel: Model<\"openai-responses\">,\n\tcontext: TranscriptContext,\n\toptions: OpenAIResponsesOptions | undefined,\n\tcompat: Required<OpenAIResponsesCompat>,\n\tgrammarToolInputProperties: ReadonlyMap<string, string>,\n\tconfigurationUpdateEffort: string | undefined,\n) {\n\tconst transcriptTools = resolveTranscriptTools(\n\t\tcontext.messages,\n\t\tcompat.supportsAdditionalTools || compat.supportsToolSearch,\n\t);\n\tconst messages = convertResponsesMessages(model, context, OPENAI_TOOL_CALL_PROVIDERS, {\n\t\tgrammarToolInputProperties,\n\t\tsupportsMidConvoSystemMessages: compat.supportsMidConvoSystemMessages,\n\t\tsupportsAdditionalTools: compat.supportsAdditionalTools,\n\t\tsupportsToolSearch: compat.supportsToolSearch,\n\t\ttoolOptions: {\n\t\t\tsupportsStrictMode: compat.supportsStrictMode,\n\t\t\tsupportsOpenAIGrammarTools: compat.supportsOpenAIGrammarTools,\n\t\t},\n\t\tconfigurationUpdateEffort,\n\t});\n\n\tconst cacheRetention = resolveCacheRetention(options?.cacheRetention, options?.env);\n\tconst omitUnsupportedFields = isChatGPTSignIn(model, options?.apiKey);\n\tconst params: ResponseCreateParamsStreaming = {\n\t\t// A fast variant keeps its canonical `-fast` id on the model object — that is the identity the\n\t\t// caller selected and records — while routing to the base upstream model plus a service tier.\n\t\tmodel: model.fastRoute?.upstreamModelId ?? model.id,\n\t\tinput: messages,\n\t\tstream: true,\n\t\tprompt_cache_key: cacheRetention === \"none\" ? undefined : clampOpenAIPromptCacheKey(options?.sessionId),\n\t\tprompt_cache_retention: omitUnsupportedFields ? undefined : getPromptCacheRetention(compat, cacheRetention),\n\t\tprompt_cache_options: omitUnsupportedFields ? undefined : getPromptCacheOptions(compat, cacheRetention),\n\t\tstore: false,\n\t};\n\n\tif (options?.maxTokens && compat.supportsMaxOutputTokens && !omitUnsupportedFields) {\n\t\tparams.max_output_tokens = Math.max(options.maxTokens, OPENAI_RESPONSES_MIN_OUTPUT_TOKENS);\n\t}\n\n\tif (options?.temperature !== undefined && !omitUnsupportedFields) {\n\t\tparams.temperature = options?.temperature;\n\t}\n\n\tconst requestedServiceTier = resolveOpenAIRequestServiceTier(model, options?.serviceTier);\n\tif (requestedServiceTier !== undefined) {\n\t\tparams.service_tier = requestedServiceTier;\n\t}\n\n\tif (transcriptTools.requestTools.length > 0) {\n\t\tparams.tools = convertResponsesTools(transcriptTools.requestTools, {\n\t\t\tsupportsStrictMode: compat.supportsStrictMode,\n\t\t\tsupportsOpenAIGrammarTools: compat.supportsOpenAIGrammarTools,\n\t\t});\n\t}\n\n\tif (options?.toolChoice !== undefined) {\n\t\tparams.tool_choice = options.toolChoice;\n\t}\n\n\tconst reasoningEffort = options?.reasoningEffort ?? (options?.reasoningSummary ? \"medium\" : undefined);\n\tif (model.reasoning) {\n\t\tif (reasoningEffort) {\n\t\t\tconst requestedEffort = options?.reasoningEffort\n\t\t\t\t? (model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort)\n\t\t\t\t: reasoningEffort;\n\t\t\tconst effort = configurationUpdateEffort === undefined ? requestedEffort : CONFIGURATION_UPDATE_REQUEST_EFFORT;\n\t\t\tparams.reasoning = {\n\t\t\t\teffort: effort as NonNullable<typeof params.reasoning>[\"effort\"],\n\t\t\t\tsummary: options?.reasoningSummary || \"auto\",\n\t\t\t};\n\t\t\tparams.include = [\"reasoning.encrypted_content\"];\n\t\t} else if (model.provider !== \"github-copilot\" && model.thinkingLevelMap?.off !== null) {\n\t\t\tparams.reasoning = {\n\t\t\t\teffort: (model.thinkingLevelMap?.off ?? \"none\") as NonNullable<typeof params.reasoning>[\"effort\"],\n\t\t\t};\n\t\t}\n\t\tif (model.provider === \"xai\") params.include = [\"reasoning.encrypted_content\"];\n\t}\n\n\t// Last so model and request sampling parameters override named request fields.\n\tconst samplingParams = resolveSamplingParams(model, reasoningEffort ?? \"off\", options?.samplingParams);\n\tif (samplingParams) {\n\t\tObject.assign(params, samplingParams);\n\t}\n\n\treturn params;\n}\n\nfunction resolveOpenAIRequestServiceTier(\n\tmodel: Model<\"openai-responses\">,\n\toptionsServiceTier: ResponsesServiceTier | undefined,\n): ResponsesServiceTier | undefined {\n\treturn openAIServiceTierForRequest(model, resolveRequestedServiceTier(model, optionsServiceTier));\n}\n"]}
1
+ {"version":3,"file":"openai-responses.js","sourceRoot":"","sources":["../../src/api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AAE,OAAO,EAAE,cAAc,CAAC,CAAC;IACvG,IAAI,cAAc,EAAE,CAAC;QACpB,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC;AAED,SAAS,+BAA+B,CACvC,KAAgC,EAChC,kBAAoD;IAEpD,OAAO,2BAA2B,CAAC,KAAK,EAAE,2BAA2B,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC;AACnG,CAAC","sourcesContent":["import type { ResponseCreateParamsStreaming } from \"openai/resources/responses/responses.js\";\nimport { clampThinkingLevel } from \"../models.ts\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tCacheRetention,\n\tModel,\n\tOpenAIResponsesCompat,\n\tProviderEnv,\n\tProviderHeaders,\n\tSimpleStreamOptions,\n\tStreamFunction,\n\tStreamOptions,\n\tTranscriptContext,\n} from \"../types.ts\";\nimport { formatProviderError, normalizeProviderError } from \"../utils/error-body.ts\";\nimport { AssistantMessageEventStream } from \"../utils/event-stream.ts\";\nimport { headersToRecord } from \"../utils/headers.ts\";\nimport { getPiUserAgent } from \"../utils/pi-user-agent.ts\";\nimport { getProviderEnvValue } from \"../utils/provider-env.ts\";\nimport { retryProviderRequest } from \"../utils/provider-retry.ts\";\nimport { getProviderRetryAfterMs } from \"../utils/retry-hints.ts\";\nimport { createStreamDeadline, withStreamDeadline } from \"../utils/stream-deadline.ts\";\nimport { getDeclaredTools, resolveTranscript, resolveTranscriptTools } from \"../utils/transcript.ts\";\nimport { createGrammarToolInputProperties } from \"./constrained-sampling.ts\";\nimport {\n\tbuildCopilotDynamicHeaders,\n\thasCopilotVisionInput,\n\tpreserveCopilotIntegrationHeader,\n} from \"./github-copilot-headers.ts\";\nimport { clampOpenAIPromptCacheKey } from \"./openai-prompt-cache.ts\";\nimport {\n\tappendServiceTierRejectedWarning,\n\tapplyServiceTierPricing,\n\tassertPayloadPreservesFastRoute,\n\tconvertResponsesMessages,\n\tconvertResponsesTools,\n\tgetResponsesToolSupport,\n\tisChatGPTSubscriptionToken,\n\tisServiceTierRejection,\n\topenAIServiceTierForRequest,\n\tprocessResponsesStream,\n\ttype ResponsesServiceTier,\n\tresolveChatGPTBackendServiceTier,\n\tresolveRequestedServiceTier,\n} from \"./openai-responses-shared.ts\";\nimport { RetryHintOpenAI } from \"./openai-retry-hint-client.ts\";\nimport { buildBaseOptions, resolveSamplingParams } from \"./simple-options.ts\";\n\nconst OPENAI_TOOL_CALL_PROVIDERS = new Set([\"openai\", \"openai-api\", \"openai-codex\", \"opencode\"]);\n// OpenAI Responses rejects max_output_tokens below 16: https://github.com/earendil-works/pi/issues/6265\nconst OPENAI_RESPONSES_MIN_OUTPUT_TOKENS = 16;\nconst CHATGPT_USAGE_URL = \"https://chatgpt.com/settings/usage\";\nconst CONFIGURATION_UPDATE_REQUEST_EFFORT = \"medium\";\n\nfunction isChatGPTSignIn(model: Model<\"openai-responses\">, apiKey: string | undefined): boolean {\n\treturn (\n\t\tmodel.provider === \"openai\" &&\n\t\tmodel.baseUrl === \"https://api.openai.com/v1\" &&\n\t\tapiKey !== undefined &&\n\t\t!apiKey.startsWith(\"sk-\")\n\t);\n}\n\nfunction headerValue(headers: ProviderHeaders | undefined, name: string): string | undefined {\n\tif (!headers) return undefined;\n\tconst expected = name.toLowerCase();\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tif (key.toLowerCase() === expected && value !== null && value.trim().length > 0) return value.trim();\n\t}\n\treturn undefined;\n}\n\nfunction hasHeader(headers: ProviderHeaders | undefined, name: string): boolean {\n\treturn headerValue(headers, name) !== undefined;\n}\n\nfunction bearerToken(apiKey: string | undefined, headers: ProviderHeaders | undefined): string | undefined {\n\treturn apiKey ?? headerValue(headers, \"authorization\")?.replace(/^Bearer\\s+/i, \"\");\n}\n\nfunction getClientApiKey(provider: string, apiKey: string | undefined, headers: ProviderHeaders | undefined): string {\n\tif (apiKey) return apiKey;\n\tif (hasHeader(headers, \"authorization\") || hasHeader(headers, \"cf-aig-authorization\")) return \"unused\";\n\tthrow new Error(`No API key for provider: ${provider}`);\n}\n\nfunction detectSessionAffinityFormat(model: Pick<Model<\"openai-responses\">, \"provider\" | \"baseUrl\">) {\n\treturn model.provider === \"openrouter\" || model.baseUrl.includes(\"openrouter.ai\") ? \"openrouter\" : \"openai\";\n}\n\n/**\n * Resolve cache retention preference.\n * Defaults to \"short\" and uses PI_CACHE_RETENTION for backward compatibility.\n */\nfunction resolveCacheRetention(cacheRetention?: CacheRetention, env?: ProviderEnv): CacheRetention {\n\tif (cacheRetention) {\n\t\treturn cacheRetention;\n\t}\n\tif (getProviderEnvValue(\"PI_CACHE_RETENTION\", env) === \"long\") {\n\t\treturn \"long\";\n\t}\n\treturn \"short\";\n}\n\nfunction getCompat(model: Model<\"openai-responses\">): Required<OpenAIResponsesCompat> {\n\treturn {\n\t\tsupportsDeveloperRole: model.compat?.supportsDeveloperRole ?? true,\n\t\tsupportsMidConvoSystemMessages: model.compat?.supportsMidConvoSystemMessages ?? false,\n\t\tsessionAffinityFormat: model.compat?.sessionAffinityFormat ?? detectSessionAffinityFormat(model),\n\t\tsupportsLongCacheRetention: model.compat?.supportsLongCacheRetention ?? true,\n\t\tsupportsStrictMode: model.compat?.supportsStrictMode ?? false,\n\t\tsupportsOpenAIGrammarTools: model.compat?.supportsOpenAIGrammarTools ?? false,\n\t\tsupportsAdditionalTools: model.compat?.supportsAdditionalTools ?? false,\n\t\tsupportsToolSearch: model.compat?.supportsToolSearch ?? false,\n\t\tsupportsExplicitPromptCacheMode: model.compat?.supportsExplicitPromptCacheMode ?? false,\n\t\tsupportsMaxOutputTokens: model.compat?.supportsMaxOutputTokens ?? true,\n\t\tsupportsMidConvoEffort: model.compat?.supportsMidConvoEffort ?? false,\n\t};\n}\n\n/** Effort to send in configuration_update items, or undefined to send it as reasoning.effort. */\nfunction getConfigurationUpdateEffort(\n\tmodel: Model<\"openai-responses\">,\n\toptions: OpenAIResponsesOptions | undefined,\n\tcompat: Required<OpenAIResponsesCompat>,\n): string | undefined {\n\tif (\n\t\t!compat.supportsMidConvoEffort ||\n\t\t!options?.reasoningEffort ||\n\t\t// Sign in with ChatGPT rejects configuration_update items.\n\t\tisChatGPTSignIn(model, options.apiKey) ||\n\t\tisChatGPTSubscriptionToken(bearerToken(options.apiKey, options.headers))\n\t) {\n\t\treturn undefined;\n\t}\n\treturn model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;\n}\n\nfunction getPromptCacheRetention(\n\tcompat: Required<OpenAIResponsesCompat>,\n\tcacheRetention: CacheRetention,\n): \"24h\" | undefined {\n\treturn cacheRetention === \"long\" && compat.supportsLongCacheRetention && !compat.supportsExplicitPromptCacheMode\n\t\t? \"24h\"\n\t\t: undefined;\n}\n\nfunction getPromptCacheOptions(\n\tcompat: Required<OpenAIResponsesCompat>,\n\tcacheRetention: CacheRetention,\n): ResponseCreateParamsStreaming[\"prompt_cache_options\"] {\n\tif (!compat.supportsExplicitPromptCacheMode) return undefined;\n\tif (cacheRetention === \"none\") return { mode: \"explicit\" };\n\tif (cacheRetention === \"long\" && compat.supportsLongCacheRetention) return { ttl: \"30m\" };\n\treturn undefined;\n}\n\n// OpenAI Responses-specific options\nexport interface OpenAIResponsesOptions extends StreamOptions {\n\treasoningEffort?: \"minimal\" | \"low\" | \"medium\" | \"high\" | \"xhigh\" | \"max\";\n\treasoningSummary?: \"auto\" | \"detailed\" | \"concise\" | null;\n\tserviceTier?: ResponsesServiceTier;\n\ttoolChoice?: ResponseCreateParamsStreaming[\"tool_choice\"];\n}\n\n/**\n * Generate function for OpenAI Responses API\n */\nexport const stream: StreamFunction<\"openai-responses\", OpenAIResponsesOptions> = (\n\tmodel: Model<\"openai-responses\">,\n\tcontext: TranscriptContext,\n\toptions?: OpenAIResponsesOptions,\n): AssistantMessageEventStream => {\n\tconst stream = new AssistantMessageEventStream();\n\tconst normalizedContext = resolveTranscript(context, getCompat(model).supportsMidConvoSystemMessages);\n\n\t// Start async processing\n\t(async () => {\n\t\tconst compat = getCompat(model);\n\t\tconst configurationUpdateEffort = getConfigurationUpdateEffort(model, options, compat);\n\t\tconst output: AssistantMessage = {\n\t\t\trole: \"assistant\",\n\t\t\tcontent: [],\n\t\t\tapi: model.api as Api,\n\t\t\tprovider: model.provider,\n\t\t\tmodel: model.id,\n\t\t\t...(configurationUpdateEffort === undefined ? {} : { providerThinkingLevel: configurationUpdateEffort }),\n\t\t\tusage: {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\tcacheRead: 0,\n\t\t\t\tcacheWrite: 0,\n\t\t\t\ttotalTokens: 0,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t},\n\t\t\tstopReason: \"pending\",\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\n\t\tconst streamDeadline = createStreamDeadline(options?.streamDeadlineMs, options?.signal);\n\n\t\ttry {\n\t\t\t// Create OpenAI client\n\t\t\tconst apiKey = getClientApiKey(model.provider, options?.apiKey, options?.headers);\n\t\t\tconst chatGPTBackend = isChatGPTSubscriptionToken(bearerToken(options?.apiKey, options?.headers));\n\t\t\tconst cacheRetention = resolveCacheRetention(options?.cacheRetention, options?.env);\n\t\t\tconst cacheSessionId = cacheRetention === \"none\" ? undefined : options?.sessionId;\n\t\t\tconst grammarToolInputProperties = createGrammarToolInputProperties(\n\t\t\t\tgetDeclaredTools(normalizedContext.messages),\n\t\t\t\tcompat.supportsOpenAIGrammarTools,\n\t\t\t);\n\t\t\tconst client = createClient(\n\t\t\t\tmodel,\n\t\t\t\tnormalizedContext,\n\t\t\t\tapiKey,\n\t\t\t\toptions?.headers,\n\t\t\t\toptions?.fetch,\n\t\t\t\tcacheSessionId,\n\t\t\t\toptions?.apiKey,\n\t\t\t);\n\t\t\tlet params = buildParams(\n\t\t\t\tmodel,\n\t\t\t\tnormalizedContext,\n\t\t\t\toptions,\n\t\t\t\tcompat,\n\t\t\t\tgrammarToolInputProperties,\n\t\t\t\tconfigurationUpdateEffort,\n\t\t\t);\n\t\t\tconst nextParams = await options?.onPayload?.(params, model);\n\t\t\tif (nextParams !== undefined) {\n\t\t\t\tparams = nextParams as ResponseCreateParamsStreaming;\n\t\t\t}\n\t\t\tassertPayloadPreservesFastRoute(model, params);\n\t\t\tconst requestOptions = {\n\t\t\t\t...(streamDeadline.signal ? { signal: streamDeadline.signal } : {}),\n\t\t\t\t...(options?.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {}),\n\t\t\t\tmaxRetries: 0,\n\t\t\t};\n\t\t\tconst sendRequest = (requestParams: ResponseCreateParamsStreaming) =>\n\t\t\t\tretryProviderRequest(() => client.responses.create(requestParams, requestOptions).withResponse(), {\n\t\t\t\t\tmaxRetries: options?.maxRetries,\n\t\t\t\t\tmaxRetryDelayMs: options?.maxRetryDelayMs,\n\t\t\t\t\tsignal: streamDeadline.signal,\n\t\t\t\t});\n\t\t\tlet startEmitted = false;\n\t\t\t// Every attempt reports its HTTP response before its body is consumed, and the message stream starts\n\t\t\t// once. A streamed request reports a rejected service_tier as an `error` event after HTTP 200, so the\n\t\t\t// response preamble is read before the request counts as accepted.\n\t\t\tconst openStream = async (requestParams: ResponseCreateParamsStreaming) => {\n\t\t\t\tconst { data, response } = await sendRequest(requestParams);\n\t\t\t\tawait options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);\n\t\t\t\tif (!startEmitted) {\n\t\t\t\t\tstartEmitted = true;\n\t\t\t\t\tstream.push({ type: \"start\", partial: output });\n\t\t\t\t}\n\t\t\t\treturn readResponsePreamble(withStreamDeadline(data, streamDeadline.deadlineMs, streamDeadline.abort));\n\t\t\t};\n\t\t\tlet requestedServiceTier = resolveOpenAIRequestServiceTier(model, options?.serviceTier);\n\t\t\tlet openaiStream: Awaited<ReturnType<typeof openStream>>;\n\t\t\ttry {\n\t\t\t\topenaiStream = await openStream(params);\n\t\t\t} catch (error) {\n\t\t\t\tif (params.service_tier == null || !isServiceTierRejection(error)) throw error;\n\t\t\t\tconst rejectedServiceTier = params.service_tier;\n\t\t\t\tconst { service_tier: _rejectedServiceTier, ...defaultTierParams } = params;\n\t\t\t\topenaiStream = await openStream(defaultTierParams);\n\t\t\t\trequestedServiceTier = undefined;\n\t\t\t\tappendServiceTierRejectedWarning(output, model, rejectedServiceTier);\n\t\t\t}\n\n\t\t\tawait processResponsesStream(openaiStream, output, stream, model, {\n\t\t\t\tonProviderStreamEvent: options?.onProviderStreamEvent,\n\t\t\t\tserviceTier: requestedServiceTier,\n\t\t\t\tgrammarToolInputProperties,\n\t\t\t\tapplyServiceTierPricing: (usage, serviceTier) => applyServiceTierPricing(usage, serviceTier, model),\n\t\t\t\t...(chatGPTBackend\n\t\t\t\t\t? { resolveServiceTier: resolveChatGPTBackendServiceTier }\n\t\t\t\t\t: { warnOnServiceTierDowngrade: true }),\n\t\t\t});\n\n\t\t\tif (options?.signal?.aborted) {\n\t\t\t\tthrow new Error(\"Request was aborted\");\n\t\t\t}\n\n\t\t\tif (output.stopReason === \"pending\") {\n\t\t\t\tthrow new Error(\"OpenAI Responses stream ended without a stop reason\");\n\t\t\t}\n\t\t\tif (output.stopReason === \"aborted\" || output.stopReason === \"error\") {\n\t\t\t\tthrow new Error(output.errorMessage || \"An unknown error occurred\");\n\t\t\t}\n\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason, message: output });\n\t\t\tstream.end();\n\t\t} catch (error) {\n\t\t\tfor (const block of output.content) {\n\t\t\t\tdelete (block as { index?: number }).index;\n\t\t\t\t// Streaming scratch buffers are only used during parsing; never persist them.\n\t\t\t\tdelete (block as { partialJson?: string }).partialJson;\n\t\t\t\tdelete (block as { customInput?: unknown }).customInput;\n\t\t\t}\n\t\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\toutput.retryAfterMs = error instanceof Error ? getProviderRetryAfterMs(error) : undefined;\n\t\t\tconst errorMessage = formatProviderError(\n\t\t\t\tnormalizeProviderError(error),\n\t\t\t\t`${model.provider === \"openai\" || model.provider === \"openai-api\" ? \"OpenAI\" : model.provider} API error`,\n\t\t\t);\n\t\t\toutput.errorMessage = errorMessage.includes(\"subscription_sharing_usage_limit_exceeded\")\n\t\t\t\t? `${errorMessage}\\nCheck your ChatGPT usage: ${CHATGPT_USAGE_URL}`\n\t\t\t\t: errorMessage;\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason, error: output });\n\t\t\tstream.end();\n\t\t} finally {\n\t\t\tstreamDeadline.cleanup();\n\t\t}\n\t})();\n\n\treturn stream;\n};\n\nconst RESPONSE_PREAMBLE_EVENT_TYPES = new Set([\"response.created\", \"response.in_progress\", \"response.queued\"]);\n\nfunction failedResponseTierRejection(event: { type: string } | undefined): Error | undefined {\n\tif (event?.type !== \"response.failed\") return undefined;\n\tconst failure = (event as { response?: { error?: { code?: string | null; message?: string } | null } }).response\n\t\t?.error;\n\tif (!failure?.message) return undefined;\n\tconst error = new Error(failure.message);\n\treturn isServiceTierRejection(error) ? error : undefined;\n}\n\n/**\n * Read a stream up to its first event after the response preamble, so an error the server raises\n * before producing output is thrown here. Returns a stream that replays every event read.\n */\nasync function readResponsePreamble<T extends { type: string }>(events: AsyncIterable<T>): Promise<AsyncIterable<T>> {\n\tconst iterator = events[Symbol.asyncIterator]();\n\tconst preamble: T[] = [];\n\tlet done = false;\n\ttry {\n\t\tfor (;;) {\n\t\t\tconst next = await iterator.next();\n\t\t\tif (next.done) {\n\t\t\t\tdone = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tpreamble.push(next.value);\n\t\t\tif (!RESPONSE_PREAMBLE_EVENT_TYPES.has(next.value.type)) break;\n\t\t}\n\t} catch (error) {\n\t\tawait iterator.return?.();\n\t\tthrow error;\n\t}\n\tconst tierRejection = failedResponseTierRejection(preamble.at(-1));\n\tif (tierRejection) {\n\t\tawait iterator.return?.();\n\t\tthrow tierRejection;\n\t}\n\treturn (async function* () {\n\t\ttry {\n\t\t\tyield* preamble;\n\t\t\tif (done) return;\n\t\t\tfor (;;) {\n\t\t\t\tconst next = await iterator.next();\n\t\t\t\tif (next.done) return;\n\t\t\t\tyield next.value;\n\t\t\t}\n\t\t} finally {\n\t\t\tawait iterator.return?.();\n\t\t}\n\t})();\n}\n\nexport const streamSimple: StreamFunction<\"openai-responses\", SimpleStreamOptions> = (\n\tmodel: Model<\"openai-responses\">,\n\tcontext: TranscriptContext,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream => {\n\tgetClientApiKey(model.provider, options?.apiKey, options?.headers);\n\n\tconst base = {\n\t\t...buildBaseOptions(model, context, options, options?.apiKey),\n\t\ttoolChoice: options?.toolChoice,\n\t} satisfies OpenAIResponsesOptions;\n\tconst clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : undefined;\n\tconst reasoningEffort = clampedReasoning === \"off\" ? undefined : clampedReasoning;\n\n\treturn stream(model, context, {\n\t\t...base,\n\t\treasoningEffort,\n\t} satisfies OpenAIResponsesOptions);\n};\n\nfunction createClient(\n\tmodel: Model<\"openai-responses\">,\n\tcontext: TranscriptContext,\n\tapiKey: string,\n\toptionsHeaders?: ProviderHeaders,\n\tfetch?: typeof globalThis.fetch,\n\tsessionId?: string,\n\tcopilotApiKey?: string,\n) {\n\tconst compat = getCompat(model);\n\tconst headers: ProviderHeaders = { \"User-Agent\": getPiUserAgent(), ...model.headers };\n\tif (model.provider === \"github-copilot\") {\n\t\tconst hasImages = hasCopilotVisionInput(context.messages);\n\t\tconst copilotHeaders = preserveCopilotIntegrationHeader(\n\t\t\tmodel.headers,\n\t\t\tbuildCopilotDynamicHeaders({\n\t\t\t\tmessages: context.messages,\n\t\t\t\thasImages,\n\t\t\t\tapiKey: copilotApiKey,\n\t\t\t}),\n\t\t);\n\t\tObject.assign(headers, copilotHeaders);\n\t}\n\n\tif (sessionId) {\n\t\tif (compat.sessionAffinityFormat === \"openrouter\") {\n\t\t\theaders[\"x-session-id\"] = sessionId;\n\t\t} else {\n\t\t\tif (compat.sessionAffinityFormat === \"openai\") {\n\t\t\t\theaders.session_id = sessionId;\n\t\t\t}\n\t\t\theaders[\"x-client-request-id\"] = sessionId;\n\t\t}\n\t}\n\n\t// Merge options headers last so they can override defaults\n\tif (optionsHeaders) {\n\t\tObject.assign(headers, optionsHeaders);\n\t}\n\n\treturn new RetryHintOpenAI({\n\t\tapiKey,\n\t\tbaseURL: model.baseUrl,\n\t\tdangerouslyAllowBrowser: true,\n\t\tfetch,\n\t\tdefaultHeaders: headers,\n\t});\n}\n\nfunction buildParams(\n\tmodel: Model<\"openai-responses\">,\n\tcontext: TranscriptContext,\n\toptions: OpenAIResponsesOptions | undefined,\n\tcompat: Required<OpenAIResponsesCompat>,\n\tgrammarToolInputProperties: ReadonlyMap<string, string>,\n\tconfigurationUpdateEffort: string | undefined,\n) {\n\tconst transcriptTools = resolveTranscriptTools(context.messages, getResponsesToolSupport(compat));\n\tconst messages = convertResponsesMessages(model, context, OPENAI_TOOL_CALL_PROVIDERS, {\n\t\tgrammarToolInputProperties,\n\t\tsupportsMidConvoSystemMessages: compat.supportsMidConvoSystemMessages,\n\t\tsupportsAdditionalTools: compat.supportsAdditionalTools,\n\t\tsupportsToolSearch: compat.supportsToolSearch,\n\t\ttoolOptions: {\n\t\t\tsupportsStrictMode: compat.supportsStrictMode,\n\t\t\tsupportsOpenAIGrammarTools: compat.supportsOpenAIGrammarTools,\n\t\t},\n\t\tconfigurationUpdateEffort,\n\t});\n\n\tconst cacheRetention = resolveCacheRetention(options?.cacheRetention, options?.env);\n\tconst omitUnsupportedFields = isChatGPTSignIn(model, options?.apiKey);\n\tconst params: ResponseCreateParamsStreaming = {\n\t\t// A fast variant keeps its canonical `-fast` id on the model object — that is the identity the\n\t\t// caller selected and records — while routing to the base upstream model plus a service tier.\n\t\tmodel: model.fastRoute?.upstreamModelId ?? model.id,\n\t\tinput: messages,\n\t\tstream: true,\n\t\tprompt_cache_key: cacheRetention === \"none\" ? undefined : clampOpenAIPromptCacheKey(options?.sessionId),\n\t\tprompt_cache_retention: omitUnsupportedFields ? undefined : getPromptCacheRetention(compat, cacheRetention),\n\t\tprompt_cache_options: omitUnsupportedFields ? undefined : getPromptCacheOptions(compat, cacheRetention),\n\t\tstore: false,\n\t};\n\n\tif (options?.maxTokens && compat.supportsMaxOutputTokens && !omitUnsupportedFields) {\n\t\tparams.max_output_tokens = Math.max(options.maxTokens, OPENAI_RESPONSES_MIN_OUTPUT_TOKENS);\n\t}\n\n\tif (options?.temperature !== undefined && !omitUnsupportedFields) {\n\t\tparams.temperature = options?.temperature;\n\t}\n\n\tconst requestedServiceTier = resolveOpenAIRequestServiceTier(model, options?.serviceTier);\n\tif (requestedServiceTier !== undefined) {\n\t\tparams.service_tier = requestedServiceTier;\n\t}\n\n\tif (transcriptTools.requestTools.length > 0) {\n\t\tparams.tools = convertResponsesTools(transcriptTools.requestTools, {\n\t\t\tsupportsStrictMode: compat.supportsStrictMode,\n\t\t\tsupportsOpenAIGrammarTools: compat.supportsOpenAIGrammarTools,\n\t\t});\n\t}\n\n\tif (options?.toolChoice !== undefined) {\n\t\tparams.tool_choice = options.toolChoice;\n\t}\n\n\tconst reasoningEffort = options?.reasoningEffort ?? (options?.reasoningSummary ? \"medium\" : undefined);\n\tif (model.reasoning) {\n\t\tif (reasoningEffort) {\n\t\t\tconst requestedEffort = options?.reasoningEffort\n\t\t\t\t? (model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort)\n\t\t\t\t: reasoningEffort;\n\t\t\tconst effort = configurationUpdateEffort === undefined ? requestedEffort : CONFIGURATION_UPDATE_REQUEST_EFFORT;\n\t\t\tparams.reasoning = {\n\t\t\t\teffort: effort as NonNullable<typeof params.reasoning>[\"effort\"],\n\t\t\t\tsummary: options?.reasoningSummary || \"auto\",\n\t\t\t};\n\t\t\tparams.include = [\"reasoning.encrypted_content\"];\n\t\t} else if (model.provider !== \"github-copilot\" && model.thinkingLevelMap?.off !== null) {\n\t\t\tparams.reasoning = {\n\t\t\t\teffort: (model.thinkingLevelMap?.off ?? \"none\") as NonNullable<typeof params.reasoning>[\"effort\"],\n\t\t\t};\n\t\t}\n\t\tif (model.provider === \"xai\") params.include = [\"reasoning.encrypted_content\"];\n\t}\n\n\t// Last so model and request sampling parameters override named request fields.\n\tconst samplingParams = resolveSamplingParams(model, reasoningEffort ?? \"off\", options?.samplingParams);\n\tif (samplingParams) {\n\t\tObject.assign(params, samplingParams);\n\t}\n\n\treturn params;\n}\n\nfunction resolveOpenAIRequestServiceTier(\n\tmodel: Model<\"openai-responses\">,\n\toptionsServiceTier: ResponsesServiceTier | undefined,\n): ResponsesServiceTier | undefined {\n\treturn openAIServiceTierForRequest(model, resolveRequestedServiceTier(model, optionsServiceTier));\n}\n"]}
@@ -1,8 +1,16 @@
1
1
  import type { ClassifierApi, ClassifierContext, ClassifierModel, ClassifierOptions, ClassifierResult } from "../types.ts";
2
+ /** Base64 image in the System One request's top-level `assets` map. */
3
+ export interface SystemOneImageAsset {
4
+ type: "image";
5
+ format: "png" | "jpg";
6
+ data_base64: string;
7
+ }
2
8
  /** TypeSafe System One request body without the transport-specific envelope. */
3
9
  export interface SystemOneWireRequest {
4
10
  state: ClassifierContext["state"];
5
11
  questions: Record<string, unknown>;
12
+ /** Images keyed by the references listed in `state.images`. */
13
+ assets?: Record<string, SystemOneImageAsset>;
6
14
  }
7
15
  /** Differences between services that serve System One models. */
8
16
  export interface SystemOneTransport {
@@ -16,6 +24,8 @@ export interface SystemOneTransport {
16
24
  payload(model: ClassifierModel<ClassifierApi>, request: SystemOneWireRequest): unknown;
17
25
  /** Extracts the System One output, including answers and usage. */
18
26
  output(body: unknown): Record<string, unknown>;
27
+ /** Whether the service accepts `context.images` as `assets` for this model. Images are rejected when omitted. */
28
+ acceptsImages?(model: ClassifierModel<ClassifierApi>): boolean;
19
29
  }
20
30
  /** Runs one System One classification over the given transport. */
21
31
  export declare function classifySystemOne(transport: SystemOneTransport, model: ClassifierModel<ClassifierApi>, context: ClassifierContext, options: ClassifierOptions | undefined): Promise<ClassifierResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"system-one-shared.d.ts","sourceRoot":"","sources":["../../src/api/system-one-shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEX,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,MAAM,aAAa,CAAC;AAIrB,gFAAgF;AAChF,MAAM,WAAW,oBAAoB;IACpC,KAAK,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,iEAAiE;AACjE,MAAM,WAAW,kBAAkB;IAClC,oDAAoD;IACpD,GAAG,EAAE,aAAa,CAAC;IACnB,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,4BAA4B;IAC5B,GAAG,CAAC,KAAK,EAAE,eAAe,CAAC,aAAa,CAAC,GAAG,GAAG,CAAC;IAChD,sEAAsE;IACtE,OAAO,CAAC,KAAK,EAAE,eAAe,CAAC,aAAa,CAAC,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC;IACvF,mEAAmE;IACnE,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/C;AAyFD,mEAAmE;AACnE,wBAAsB,iBAAiB,CACtC,SAAS,EAAE,kBAAkB,EAC7B,KAAK,EAAE,eAAe,CAAC,aAAa,CAAC,EACrC,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,iBAAiB,GAAG,SAAS,GACpC,OAAO,CAAC,gBAAgB,CAAC,CA+B3B"}
1
+ {"version":3,"file":"system-one-shared.d.ts","sourceRoot":"","sources":["../../src/api/system-one-shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEX,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,MAAM,aAAa,CAAC;AAIrB,uEAAuE;AACvE,MAAM,WAAW,mBAAmB;IACnC,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,KAAK,GAAG,KAAK,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,gFAAgF;AAChF,MAAM,WAAW,oBAAoB;IACpC,KAAK,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,+DAA+D;IAC/D,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;CAC7C;AAED,iEAAiE;AACjE,MAAM,WAAW,kBAAkB;IAClC,oDAAoD;IACpD,GAAG,EAAE,aAAa,CAAC;IACnB,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,4BAA4B;IAC5B,GAAG,CAAC,KAAK,EAAE,eAAe,CAAC,aAAa,CAAC,GAAG,GAAG,CAAC;IAChD,sEAAsE;IACtE,OAAO,CAAC,KAAK,EAAE,eAAe,CAAC,aAAa,CAAC,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC;IACvF,mEAAmE;IACnE,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/C,iHAAiH;IACjH,aAAa,CAAC,CAAC,KAAK,EAAE,eAAe,CAAC,aAAa,CAAC,GAAG,OAAO,CAAC;CAC/D;AAsHD,mEAAmE;AACnE,wBAAsB,iBAAiB,CACtC,SAAS,EAAE,kBAAkB,EAC7B,KAAK,EAAE,eAAe,CAAC,aAAa,CAAC,EACrC,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,iBAAiB,GAAG,SAAS,GACpC,OAAO,CAAC,gBAAgB,CAAC,CAiC3B"}
@@ -1,5 +1,32 @@
1
1
  import { formatProviderError, normalizeProviderError } from "../utils/error-body.js";
2
2
  import { isRecord, parseClassifierUsage, postClassifierRequest, requiredNumber } from "./classifier-shared.js";
3
+ const IMAGES_STATE_FIELD = "images";
4
+ const IMAGE_FORMATS = new Map([
5
+ ["image/png", "png"],
6
+ ["image/jpeg", "jpg"],
7
+ ["image/jpg", "jpg"],
8
+ ]);
9
+ /** Lists each image once in `assets` under a fresh UUID and writes the UUIDs into `state.images`, in order. */
10
+ function imageAssets(label, context) {
11
+ const images = context.images ?? [];
12
+ if (images.length === 0)
13
+ return { state: context.state };
14
+ if (Object.hasOwn(context.state, IMAGES_STATE_FIELD)) {
15
+ throw new Error(`${label} lists images in state.${IMAGES_STATE_FIELD}; rename that state field to send images`);
16
+ }
17
+ const assets = {};
18
+ for (const image of images) {
19
+ const format = IMAGE_FORMATS.get(image.mimeType.toLowerCase());
20
+ if (!format)
21
+ throw new Error(`${label} accepts only PNG or JPEG images, got ${image.mimeType}`);
22
+ assets[crypto.randomUUID()] = {
23
+ type: "image",
24
+ format,
25
+ data_base64: image.data.replace(/^data:[^,]*,/u, ""),
26
+ };
27
+ }
28
+ return { state: { ...context.state, [IMAGES_STATE_FIELD]: Object.keys(assets) }, assets };
29
+ }
3
30
  function unitInterval(label, value, field) {
4
31
  const number = requiredNumber(label, value, field);
5
32
  if (number < 0 || number > 1)
@@ -73,13 +100,15 @@ function parseAnswers(label, value, context) {
73
100
  return Object.fromEntries(answers);
74
101
  }
75
102
  /** Maps public `bool` questions to TypeSafe's wire-level `noul` type. */
76
- function wireRequest(context) {
103
+ function wireRequest(label, context) {
104
+ const { state, assets } = imageAssets(label, context);
77
105
  return {
78
- state: context.state,
106
+ state,
79
107
  questions: Object.fromEntries(Object.entries(context.questions).map(([id, question]) => [
80
108
  id,
81
109
  question.type === "bool" ? { ...question, type: "noul" } : question,
82
110
  ])),
111
+ ...(assets ? { assets } : {}),
83
112
  };
84
113
  }
85
114
  /** Runs one System One classification over the given transport. */
@@ -95,9 +124,10 @@ export async function classifySystemOne(transport, model, context, options) {
95
124
  try {
96
125
  if (model.api !== transport.api)
97
126
  throw new Error(`Unsupported classifier API: ${model.api}`);
98
- if (context.images?.length)
127
+ if (context.images?.length && !transport.acceptsImages?.(model)) {
99
128
  throw new Error(`${transport.label} does not support image input`);
100
- const body = await postClassifierRequest(transport.label, transport.url(model), model, transport.payload(model, wireRequest(context)), options);
129
+ }
130
+ const body = await postClassifierRequest(transport.label, transport.url(model), model, transport.payload(model, wireRequest(transport.label, context)), options);
101
131
  const result = transport.output(body);
102
132
  // Malformed answers may still be billed, so retain usage before parsing them.
103
133
  const usage = parseClassifierUsage(result.usage, model);
@@ -1 +1 @@
1
- {"version":3,"file":"system-one-shared.js","sourceRoot":"","sources":["../../src/api/system-one-shared.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrF,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAuB/G,SAAS,YAAY,CAAC,KAAa,EAAE,KAAc,EAAE,KAAa;IACjE,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACnD,IAAI,MAAM,GAAG,CAAC,IAAI,MAAM,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,wBAAwB,KAAK,EAAE,CAAC,CAAC;IACvF,OAAO,MAAM,CAAC;AACf,CAAC;AAED,SAAS,aAAa,CAAC,KAAa,EAAE,KAAc,EAAE,EAAU;IAC/D,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,uCAAuC,EAAE,EAAE,CAAC,CAAC;IAC3F,OAAO,MAAM,CAAC,WAAW,CACxB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,WAAW,CAAC,EAAE,EAAE,CAAC;QACjD,GAAG;QACH,YAAY,CAAC,KAAK,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IAAI,GAAG,MAAM,qBAAqB,CACvC,SAAS,CAAC,KAAK,EACf,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,EACpB,KAAK,EACL,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,EAC9C,OAAO,CACP,CAAC;QACF,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACtC,8EAA8E;QAC9E,MAAM,KAAK,GAAG,oBAAoB,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QACxD,IAAI,KAAK;YAAE,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;QAChC,MAAM,CAAC,OAAO,GAAG,YAAY,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxE,OAAO,MAAM,CAAC;IACf,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,CAAC,UAAU,GAAG,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;QACnE,MAAM,CAAC,YAAY,GAAG,mBAAmB,CAAC,sBAAsB,CAAC,KAAK,CAAC,EAAE,GAAG,SAAS,CAAC,KAAK,QAAQ,CAAC,CAAC;QACrG,OAAO,MAAM,CAAC;IACf,CAAC;AACF,CAAC","sourcesContent":["import type {\n\tClassifierAnswer,\n\tClassifierApi,\n\tClassifierContext,\n\tClassifierModel,\n\tClassifierOptions,\n\tClassifierResult,\n} from \"../types.ts\";\nimport { formatProviderError, normalizeProviderError } from \"../utils/error-body.ts\";\nimport { isRecord, parseClassifierUsage, postClassifierRequest, requiredNumber } from \"./classifier-shared.ts\";\n\n/** TypeSafe System One request body without the transport-specific envelope. */\nexport interface SystemOneWireRequest {\n\tstate: ClassifierContext[\"state\"];\n\tquestions: Record<string, unknown>;\n}\n\n/** Differences between services that serve System One models. */\nexport interface SystemOneTransport {\n\t/** Classifier API implemented by this transport. */\n\tapi: ClassifierApi;\n\t/** Service name used in error messages. */\n\tlabel: string;\n\t/** Absolute request URL. */\n\turl(model: ClassifierModel<ClassifierApi>): URL;\n\t/** Wraps the System One request in the service's request envelope. */\n\tpayload(model: ClassifierModel<ClassifierApi>, request: SystemOneWireRequest): unknown;\n\t/** Extracts the System One output, including answers and usage. */\n\toutput(body: unknown): Record<string, unknown>;\n}\n\n\nfunction unitInterval(label: string, value: unknown, field: string): number {\n\tconst number = requiredNumber(label, value, field);\n\tif (number < 0 || number > 1) throw new Error(`${label} returned an invalid ${field}`);\n\treturn number;\n}\n\nfunction probabilities(label: string, value: unknown, id: string): Record<string, number> {\n\tif (!isRecord(value)) throw new Error(`${label} returned invalid probabilities for ${id}`);\n\treturn Object.fromEntries(\n\t\tObject.entries(value).map(([key, probability]) => [\n\t\t\tkey,\n\t\t\tunitInterval(label, probability, `probability for ${id}.${key}`),\n\t\t]),\n\t);\n}\n\nfunction parseAnswers(label: string, value: unknown, context: ClassifierContext): Record<string, ClassifierAnswer> {\n\tif (!isRecord(value)) throw new Error(`${label} returned an unexpected response`);\n\tconst answers: Array<[string, ClassifierAnswer]> = [];\n\tfor (const [id, question] of Object.entries(context.questions)) {\n\t\tconst answer = value[id];\n\t\tif (!isRecord(answer)) throw new Error(`${label} did not return an answer for ${id}`);\n\t\tif (question.type === \"choice\") {\n\t\t\tif (\n\t\t\t\tanswer.type !== \"choice\" ||\n\t\t\t\ttypeof answer.choice !== \"string\" ||\n\t\t\t\t!Object.hasOwn(question.criteria, answer.choice)\n\t\t\t) {\n\t\t\t\tthrow new Error(`${label} did not return a valid choice answer for ${id}`);\n\t\t\t}\n\t\t\tconst choiceProbabilities = probabilities(label, answer.probabilities, id);\n\t\t\tif (Object.keys(choiceProbabilities).some((key) => !Object.hasOwn(question.criteria, key))) {\n\t\t\t\tthrow new Error(`${label} returned an unknown choice probability for ${id}`);\n\t\t\t}\n\t\t\tanswers.push([\n\t\t\t\tid,\n\t\t\t\t{\n\t\t\t\t\ttype: \"choice\",\n\t\t\t\t\tchoice: answer.choice,\n\t\t\t\t\tprobabilities: choiceProbabilities,\n\t\t\t\t\tconfidence: unitInterval(label, answer.confidence, `confidence for ${id}`),\n\t\t\t\t},\n\t\t\t]);\n\t\t} else if (question.type === \"score\") {\n\t\t\tif (answer.type !== \"score\") throw new Error(`${label} did not return a score answer for ${id}`);\n\t\t\tconst score = requiredNumber(label, answer.score, `score for ${id}`);\n\t\t\tif (score < 0 || score > question.criteria.length - 1) {\n\t\t\t\tthrow new Error(`${label} returned an invalid score for ${id}`);\n\t\t\t}\n\t\t\tanswers.push([\n\t\t\t\tid,\n\t\t\t\t{\n\t\t\t\t\ttype: \"score\",\n\t\t\t\t\tscore,\n\t\t\t\t\tconfidence: unitInterval(label, answer.confidence, `confidence for ${id}`),\n\t\t\t\t},\n\t\t\t]);\n\t\t} else {\n\t\t\tif (answer.type !== \"noul\") throw new Error(`${label} did not return a bool answer for ${id}`);\n\t\t\tanswers.push([\n\t\t\t\tid,\n\t\t\t\t{\n\t\t\t\t\ttype: \"bool\",\n\t\t\t\t\tprobability: unitInterval(label, answer.noul, `probability for ${id}`),\n\t\t\t\t},\n\t\t\t]);\n\t\t}\n\t}\n\treturn Object.fromEntries(answers);\n}\n\n\n/** Maps public `bool` questions to TypeSafe's wire-level `noul` type. */\nfunction wireRequest(context: ClassifierContext): SystemOneWireRequest {\n\treturn {\n\t\tstate: context.state,\n\t\tquestions: Object.fromEntries(\n\t\t\tObject.entries(context.questions).map(([id, question]) => [\n\t\t\t\tid,\n\t\t\t\tquestion.type === \"bool\" ? { ...question, type: \"noul\" } : question,\n\t\t\t]),\n\t\t),\n\t};\n}\n\n\n/** Runs one System One classification over the given transport. */\nexport async function classifySystemOne(\n\ttransport: SystemOneTransport,\n\tmodel: ClassifierModel<ClassifierApi>,\n\tcontext: ClassifierContext,\n\toptions: ClassifierOptions | undefined,\n): Promise<ClassifierResult> {\n\tconst output: ClassifierResult = {\n\t\tapi: model.api,\n\t\tprovider: model.provider,\n\t\tmodel: model.id,\n\t\tanswers: {},\n\t\tstopReason: \"stop\",\n\t\ttimestamp: Date.now(),\n\t};\n\n\ttry {\n\t\tif (model.api !== transport.api) throw new Error(`Unsupported classifier API: ${model.api}`);\n\t\tif (context.images?.length) throw new Error(`${transport.label} does not support image input`);\n\t\tconst body = await postClassifierRequest(\n\t\t\ttransport.label,\n\t\t\ttransport.url(model),\n\t\t\tmodel,\n\t\t\ttransport.payload(model, wireRequest(context)),\n\t\t\toptions,\n\t\t);\n\t\tconst result = transport.output(body);\n\t\t// Malformed answers may still be billed, so retain usage before parsing them.\n\t\tconst usage = parseClassifierUsage(result.usage, model);\n\t\tif (usage) output.usage = usage;\n\t\toutput.answers = parseAnswers(transport.label, result.answers, context);\n\t\treturn output;\n\t} catch (error) {\n\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\toutput.errorMessage = formatProviderError(normalizeProviderError(error), `${transport.label} error`);\n\t\treturn output;\n\t}\n}\n"]}
1
+ {"version":3,"file":"system-one-shared.js","sourceRoot":"","sources":["../../src/api/system-one-shared.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrF,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAiC/G,MAAM,kBAAkB,GAAG,QAAQ,CAAC;AACpC,MAAM,aAAa,GAAG,IAAI,GAAG,CAAwC;IACpE,CAAC,WAAW,EAAE,KAAK,CAAC;IACpB,CAAC,YAAY,EAAE,KAAK,CAAC;IACrB,CAAC,WAAW,EAAE,KAAK,CAAC;CACpB,CAAC,CAAC;AAEH,+GAA+G;AAC/G,SAAS,WAAW,CAAC,KAAa,EAAE,OAA0B;IAC7D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC;IACpC,I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GAAG,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;QACnE,MAAM,CAAC,YAAY,GAAG,mBAAmB,CAAC,sBAAsB,CAAC,KAAK,CAAC,EAAE,GAAG,SAAS,CAAC,KAAK,QAAQ,CAAC,CAAC;QACrG,OAAO,MAAM,CAAC;IACf,CAAC;AACF,CAAC","sourcesContent":["import type {\n\tClassifierAnswer,\n\tClassifierApi,\n\tClassifierContext,\n\tClassifierModel,\n\tClassifierOptions,\n\tClassifierResult,\n} from \"../types.ts\";\nimport { formatProviderError, normalizeProviderError } from \"../utils/error-body.ts\";\nimport { isRecord, parseClassifierUsage, postClassifierRequest, requiredNumber } from \"./classifier-shared.ts\";\n\n/** Base64 image in the System One request's top-level `assets` map. */\nexport interface SystemOneImageAsset {\n\ttype: \"image\";\n\tformat: \"png\" | \"jpg\";\n\tdata_base64: string;\n}\n\n/** TypeSafe System One request body without the transport-specific envelope. */\nexport interface SystemOneWireRequest {\n\tstate: ClassifierContext[\"state\"];\n\tquestions: Record<string, unknown>;\n\t/** Images keyed by the references listed in `state.images`. */\n\tassets?: Record<string, SystemOneImageAsset>;\n}\n\n/** Differences between services that serve System One models. */\nexport interface SystemOneTransport {\n\t/** Classifier API implemented by this transport. */\n\tapi: ClassifierApi;\n\t/** Service name used in error messages. */\n\tlabel: string;\n\t/** Absolute request URL. */\n\turl(model: ClassifierModel<ClassifierApi>): URL;\n\t/** Wraps the System One request in the service's request envelope. */\n\tpayload(model: ClassifierModel<ClassifierApi>, request: SystemOneWireRequest): unknown;\n\t/** Extracts the System One output, including answers and usage. */\n\toutput(body: unknown): Record<string, unknown>;\n\t/** Whether the service accepts `context.images` as `assets` for this model. Images are rejected when omitted. */\n\tacceptsImages?(model: ClassifierModel<ClassifierApi>): boolean;\n}\n\nconst IMAGES_STATE_FIELD = \"images\";\nconst IMAGE_FORMATS = new Map<string, SystemOneImageAsset[\"format\"]>([\n\t[\"image/png\", \"png\"],\n\t[\"image/jpeg\", \"jpg\"],\n\t[\"image/jpg\", \"jpg\"],\n]);\n\n/** Lists each image once in `assets` under a fresh UUID and writes the UUIDs into `state.images`, in order. */\nfunction imageAssets(label: string, context: ClassifierContext): Pick<SystemOneWireRequest, \"state\" | \"assets\"> {\n\tconst images = context.images ?? [];\n\tif (images.length === 0) return { state: context.state };\n\tif (Object.hasOwn(context.state, IMAGES_STATE_FIELD)) {\n\t\tthrow new Error(`${label} lists images in state.${IMAGES_STATE_FIELD}; rename that state field to send images`);\n\t}\n\tconst assets: Record<string, SystemOneImageAsset> = {};\n\tfor (const image of images) {\n\t\tconst format = IMAGE_FORMATS.get(image.mimeType.toLowerCase());\n\t\tif (!format) throw new Error(`${label} accepts only PNG or JPEG images, got ${image.mimeType}`);\n\t\tassets[crypto.randomUUID()] = {\n\t\t\ttype: \"image\",\n\t\t\tformat,\n\t\t\tdata_base64: image.data.replace(/^data:[^,]*,/u, \"\"),\n\t\t};\n\t}\n\treturn { state: { ...context.state, [IMAGES_STATE_FIELD]: Object.keys(assets) }, assets };\n}\n\n\nfunction unitInterval(label: string, value: unknown, field: string): number {\n\tconst number = requiredNumber(label, value, field);\n\tif (number < 0 || number > 1) throw new Error(`${label} returned an invalid ${field}`);\n\treturn number;\n}\n\nfunction probabilities(label: string, value: unknown, id: string): Record<string, number> {\n\tif (!isRecord(value)) throw new Error(`${label} returned invalid probabilities for ${id}`);\n\treturn Object.fromEntries(\n\t\tObject.entries(value).map(([key, probability]) => [\n\t\t\tkey,\n\t\t\tunitInterval(label, probability, `probability for ${id}.${key}`),\n\t\t]),\n\t);\n}\n\nfunction parseAnswers(label: string, value: unknown, context: ClassifierContext): Record<string, ClassifierAnswer> {\n\tif (!isRecord(value)) throw new Error(`${label} returned an unexpected response`);\n\tconst answers: Array<[string, ClassifierAnswer]> = [];\n\tfor (const [id, question] of Object.entries(context.questions)) {\n\t\tconst answer = value[id];\n\t\tif (!isRecord(answer)) throw new Error(`${label} did not return an answer for ${id}`);\n\t\tif (question.type === \"choice\") {\n\t\t\tif (\n\t\t\t\tanswer.type !== \"choice\" ||\n\t\t\t\ttypeof answer.choice !== \"string\" ||\n\t\t\t\t!Object.hasOwn(question.criteria, answer.choice)\n\t\t\t) {\n\t\t\t\tthrow new Error(`${label} did not return a valid choice answer for ${id}`);\n\t\t\t}\n\t\t\tconst choiceProbabilities = probabilities(label, answer.probabilities, id);\n\t\t\tif (Object.keys(choiceProbabilities).some((key) => !Object.hasOwn(question.criteria, key))) {\n\t\t\t\tthrow new Error(`${label} returned an unknown choice probability for ${id}`);\n\t\t\t}\n\t\t\tanswers.push([\n\t\t\t\tid,\n\t\t\t\t{\n\t\t\t\t\ttype: \"choice\",\n\t\t\t\t\tchoice: answer.choice,\n\t\t\t\t\tprobabilities: choiceProbabilities,\n\t\t\t\t\tconfidence: unitInterval(label, answer.confidence, `confidence for ${id}`),\n\t\t\t\t},\n\t\t\t]);\n\t\t} else if (question.type === \"score\") {\n\t\t\tif (answer.type !== \"score\") throw new Error(`${label} did not return a score answer for ${id}`);\n\t\t\tconst score = requiredNumber(label, answer.score, `score for ${id}`);\n\t\t\tif (score < 0 || score > question.criteria.length - 1) {\n\t\t\t\tthrow new Error(`${label} returned an invalid score for ${id}`);\n\t\t\t}\n\t\t\tanswers.push([\n\t\t\t\tid,\n\t\t\t\t{\n\t\t\t\t\ttype: \"score\",\n\t\t\t\t\tscore,\n\t\t\t\t\tconfidence: unitInterval(label, answer.confidence, `confidence for ${id}`),\n\t\t\t\t},\n\t\t\t]);\n\t\t} else {\n\t\t\tif (answer.type !== \"noul\") throw new Error(`${label} did not return a bool answer for ${id}`);\n\t\t\tanswers.push([\n\t\t\t\tid,\n\t\t\t\t{\n\t\t\t\t\ttype: \"bool\",\n\t\t\t\t\tprobability: unitInterval(label, answer.noul, `probability for ${id}`),\n\t\t\t\t},\n\t\t\t]);\n\t\t}\n\t}\n\treturn Object.fromEntries(answers);\n}\n\n\n/** Maps public `bool` questions to TypeSafe's wire-level `noul` type. */\nfunction wireRequest(label: string, context: ClassifierContext): SystemOneWireRequest {\n\tconst { state, assets } = imageAssets(label, context);\n\treturn {\n\t\tstate,\n\t\tquestions: Object.fromEntries(\n\t\t\tObject.entries(context.questions).map(([id, question]) => [\n\t\t\t\tid,\n\t\t\t\tquestion.type === \"bool\" ? { ...question, type: \"noul\" } : question,\n\t\t\t]),\n\t\t),\n\t\t...(assets ? { assets } : {}),\n\t};\n}\n\n\n/** Runs one System One classification over the given transport. */\nexport async function classifySystemOne(\n\ttransport: SystemOneTransport,\n\tmodel: ClassifierModel<ClassifierApi>,\n\tcontext: ClassifierContext,\n\toptions: ClassifierOptions | undefined,\n): Promise<ClassifierResult> {\n\tconst output: ClassifierResult = {\n\t\tapi: model.api,\n\t\tprovider: model.provider,\n\t\tmodel: model.id,\n\t\tanswers: {},\n\t\tstopReason: \"stop\",\n\t\ttimestamp: Date.now(),\n\t};\n\n\ttry {\n\t\tif (model.api !== transport.api) throw new Error(`Unsupported classifier API: ${model.api}`);\n\t\tif (context.images?.length && !transport.acceptsImages?.(model)) {\n\t\t\tthrow new Error(`${transport.label} does not support image input`);\n\t\t}\n\t\tconst body = await postClassifierRequest(\n\t\t\ttransport.label,\n\t\t\ttransport.url(model),\n\t\t\tmodel,\n\t\t\ttransport.payload(model, wireRequest(transport.label, context)),\n\t\t\toptions,\n\t\t);\n\t\tconst result = transport.output(body);\n\t\t// Malformed answers may still be billed, so retain usage before parsing them.\n\t\tconst usage = parseClassifierUsage(result.usage, model);\n\t\tif (usage) output.usage = usage;\n\t\toutput.answers = parseAnswers(transport.label, result.answers, context);\n\t\treturn output;\n\t} catch (error) {\n\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\toutput.errorMessage = formatProviderError(normalizeProviderError(error), `${transport.label} error`);\n\t\treturn output;\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"typesafe-system-one.d.ts","sourceRoot":"","sources":["../../src/api/typesafe-system-one.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAmBzE,gGAAgG;AAChG,eAAO,MAAM,QAAQ,EAAE,kBAAkB,CAAC,iBAAiB,CACL,CAAC"}
1
+ {"version":3,"file":"typesafe-system-one.d.ts","sourceRoot":"","sources":["../../src/api/typesafe-system-one.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAqBzE,gGAAgG;AAChG,eAAO,MAAM,QAAQ,EAAE,kBAAkB,CAAC,iBAAiB,CACL,CAAC"}
@@ -2,7 +2,8 @@ import { isRecord } from "./classifier-shared.js";
2
2
  import { classifySystemOne } from "./system-one-shared.js";
3
3
  /**
4
4
  * TypeSafe's native System One protocol. OpenRouter serves the same protocol,
5
- * so both providers use this API with different base URLs.
5
+ * so both providers use this API with different base URLs. Only direct TypeSafe
6
+ * models with image input send images, as referenced `assets`.
6
7
  */
7
8
  const transport = {
8
9
  api: "typesafe-system-one",
@@ -14,6 +15,7 @@ const transport = {
14
15
  throw new Error("System One API returned an unexpected response");
15
16
  return body;
16
17
  },
18
+ acceptsImages: (model) => model.provider === "typesafe" && model.input.includes("image"),
17
19
  };
18
20
  /** TypeSafe System One classification with public `bool` values mapped to wire-level `noul`. */
19
21
  export const classify = (model, context, options) => classifySystemOne(transport, model, context, options);
@@ -1 +1 @@
1
- {"version":3,"file":"typesafe-system-one.js","sourceRoot":"","sources":["../../src/api/typesafe-system-one.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAA2B,MAAM,wBAAwB,CAAC;AAEpF;;;GAGG;AACH,MAAM,SAAS,GAAuB;IACrC,GAAG,EAAE,qBAAqB;IAC1B,KAAK,EAAE,gBAAgB;IACvB,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC;IAC9E,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,GAAG,OAAO,EAAE,CAAC;IAC9D,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;QAChB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;QACvF,OAAO,IAAI,CAAC;IACb,CAAC;CACD,CAAC;AAEF,gGAAgG;AAChG,MAAM,CAAC,MAAM,QAAQ,GAA0C,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAC1F,iBAAiB,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC","sourcesContent":["import type { ClassifierFunction, ClassifierOptions } from \"../types.ts\";\nimport { isRecord } from \"./classifier-shared.ts\";\nimport { classifySystemOne, type SystemOneTransport } from \"./system-one-shared.ts\";\n\n/**\n * TypeSafe's native System One protocol. OpenRouter serves the same protocol,\n * so both providers use this API with different base URLs.\n */\nconst transport: SystemOneTransport = {\n\tapi: \"typesafe-system-one\",\n\tlabel: \"System One API\",\n\turl: (model) => new URL(\"systemone\", `${model.baseUrl.replace(/\\/+$/u, \"\")}/`),\n\tpayload: (model, request) => ({ model: model.id, ...request }),\n\toutput: (body) => {\n\t\tif (!isRecord(body)) throw new Error(\"System One API returned an unexpected response\");\n\t\treturn body;\n\t},\n};\n\n/** TypeSafe System One classification with public `bool` values mapped to wire-level `noul`. */\nexport const classify: ClassifierFunction<ClassifierOptions> = (model, context, options) =>\n\tclassifySystemOne(transport, model, context, options);\n"]}
1
+ {"version":3,"file":"typesafe-system-one.js","sourceRoot":"","sources":["../../src/api/typesafe-system-one.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAA2B,MAAM,wBAAwB,CAAC;AAEpF;;;;GAIG;AACH,MAAM,SAAS,GAAuB;IACrC,GAAG,EAAE,qBAAqB;IAC1B,KAAK,EAAE,gBAAgB;IACvB,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC;IAC9E,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,GAAG,OAAO,EAAE,CAAC;IAC9D,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;QAChB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;QACvF,OAAO,IAAI,CAAC;IACb,CAAC;IACD,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,KAAK,UAAU,IAAI,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC;CACxF,CAAC;AAEF,gGAAgG;AAChG,MAAM,CAAC,MAAM,QAAQ,GAA0C,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAC1F,iBAAiB,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC","sourcesContent":["import type { ClassifierFunction, ClassifierOptions } from \"../types.ts\";\nimport { isRecord } from \"./classifier-shared.ts\";\nimport { classifySystemOne, type SystemOneTransport } from \"./system-one-shared.ts\";\n\n/**\n * TypeSafe's native System One protocol. OpenRouter serves the same protocol,\n * so both providers use this API with different base URLs. Only direct TypeSafe\n * models with image input send images, as referenced `assets`.\n */\nconst transport: SystemOneTransport = {\n\tapi: \"typesafe-system-one\",\n\tlabel: \"System One API\",\n\turl: (model) => new URL(\"systemone\", `${model.baseUrl.replace(/\\/+$/u, \"\")}/`),\n\tpayload: (model, request) => ({ model: model.id, ...request }),\n\toutput: (body) => {\n\t\tif (!isRecord(body)) throw new Error(\"System One API returned an unexpected response\");\n\t\treturn body;\n\t},\n\tacceptsImages: (model) => model.provider === \"typesafe\" && model.input.includes(\"image\"),\n};\n\n/** TypeSafe System One classification with public `bool` values mapped to wire-level `noul`. */\nexport const classify: ClassifierFunction<ClassifierOptions> = (model, context, options) =>\n\tclassifySystemOne(transport, model, context, options);\n"]}
@@ -1 +1 @@
1
- {"schemaVersion":6,"generatedAt":"2026-10-19T02:58:24.501Z","structureHash":"f1d86396c28ccc1dc5eefd6846f3caac8c28755d2a2e4b462986b53850cc4ef6","files":{"amazon-bedrock.json":"be629dd7c5c0b7ba27e7a335fb329df45b1107e2287b1a6c8e37e9cf46026c0b","ant-ling.json":"628feab3ef6c7d80ce96f75999804e1d9f05fec3851e5302e30fff3b69db90f6","anthropic.json":"f797095e492df25157b14e399ff8030b4d0a75e698f415534cc79f606cf99ffb","azure.json":"7ed02356b4481d76a213de14f704c9d4e52ba2ca73cc710b2e06ebe9cdf24929","baseten.json":"df00cca103845b5b0ae6736c046e9500e4328eda3ad26cd0266541f2a5840cb1","cerebras.json":"3eccb58c5de3d0dc7ba49dc6e477ba29f00cb3150ce0a35cc90d59e6b5ab368e","cloudflare-ai-gateway.json":"f918c5f2503f3bb29abf20342ec1473a84c2b1fe69820c4e81234f19b6d50bb6","cloudflare-workers-ai.json":"98b9c8cb412139ae3f5d2f5e49134f8412ed4e139a12bf6cb3aeba38aacc6bb3","deepseek.json":"10a296fb3e898f7715c80890c8af0af4f5fd58f22dbcd6612fdc5d762157ccdc","fireworks.json":"8e862806b0a69cefc6585c38b103de1baae782c51409748c6d16199daedcf1ca","github-copilot.json":"519a4b716d7fbd6692b8237bd19ef8b6188e4e1976d65175d6f6bedc8b5d20a8","google-vertex.json":"564d692a4292ef12e98c8ec056a39948ea64e10851f5ddaaebcc37b585545231","google.json":"e13d3c51b13028d8253153165f7438ea2f3c3eaa8f209be952d3e9ded4494b5a","groq.json":"910952ad9dad07856983459d63fce0148dba1203edd7b10d801a77c5824f3405","huggingface.json":"6399e958790a9d90c21fb55d1cbef8569427a1ceb28de86dadeb3b4454ecfade","kimi-coding.json":"728d5ddb63ef52130552022d5ae2fd138fdc131ff854ac8c3b10ccaad355ab39","meta.json":"563f5ec07973f52ab8c3eb26ef91a36ad8a79e950b37174935666cdcb624bf35","minimax-cn.json":"1bbfbd11c3edbd141841d3cef027e12157218f1aec92477e15772116c1fabe7a","minimax.json":"a4b6864bd97eddf5749b2e117f643e751ec237408e8e24bec9e2f947782fa244","mistral.json":"063879a9525c9d71c33308b46f70ab7ea3926c7cbe977d29b81df387acd60242","moonshotai-cn.json":"79c9585dc84ee525ebaebbc78b3c55f3d369ec884d4f943488f1e0b14e3587f5","moonshotai.json":"1da2c4e34f22aef17a07c974d85bdee8e1b68b6dc712e3769c935b3f1e7dadca","nvidia.json":"dcf20f026f1a5cbb9001adf35e4831dcf761b0dde866d5eddf63015aa41151ec","openai-codex.json":"dc82505193e712c78ff4695f18a2a67f903833335659bf943a45fc06306b0dbd","openai-decisions.json":"0c7d54fcbac5e7388872a85c0db7f336c5a57c82d403266e9ae04f87561daf4f","openai-images.json":"885b1c5ec4198ebe2b73518e61cbf989a7cad9229d01813635f361b29a909562","openai.json":"cc17bd713fdaac9a754327431083a95fc153fa860bb2c4c77f5ce591c2f7f411","opencode-go.json":"77101e824fec441c13cf5f1da3d9f2e3957f08d8714a101b529c5765f3852048","opencode.json":"f8949143bfb3f5b8cd17f497c11e3f1d6c4e867d745946ad7e355060a92ccbb2","openrouter.json":"54777cf178934a5c7abccfb454d62f416b861918c8e1ebe95df9cab995b4106e","qwen-token-plan-cn.json":"2469a4091c474ec3db0a49a9962d8d2726c074ad9065b96bc4e0c87861c4c6c5","qwen-token-plan-individual.json":"0fb7cf64faf39d1a3b0a884210a86c87084b805eda15644f5f39293287b959dd","qwen-token-plan.json":"eff10620cb577142de4ec02698d5961a71fda2fe4f6ae7ea9432bad9d6844176","radius.json":"611401f29004dfcdfb49dbcae7467cfb9f8f127c5bc35f19400bb76bc8079152","together.json":"4d216aea80b30408b97cf695462cdc721b2e9be12fabc042b60ac7576278e8a8","typesafe.json":"a4429a2f696d5cc5273969af61a7310bda07d6bdcd27bf9ac9c76c534cc43716","vercel-ai-gateway.json":"304ed5236a69f0a3a3c9bf61eec8cd52b348efdee422bef2fd7f5115ceb9917d","xai.json":"879c49b78b663a52a220ac4ee013e726b10c4f50aaa03bc58ee53a4b54c76928","xiaomi-token-plan-ams.json":"bfd33741da693bdb8e8ebd4e7b90c3e90820aa18432ad081a5a98db13c6bd296","xiaomi-token-plan-cn.json":"4b61d78feae3a926fda918c3fd3a9afaf2ca60c1bba0af8270a5398fb50a983e","xiaomi-token-plan-sgp.json":"b05a197ce24fd69fc9440f4ba929984ac7a0fefbe8083268734b422e721987ec","xiaomi.json":"495b5fddf3c3ec8904fecc15c4c19536f4961dce7b51512b6909d2df2e739824","zai-coding-cn.json":"cc9e0768e726ef55d2b7af853ac5f3585dc72575932cb38840a3877d18736b78","zai.json":"58e6642fdfb736f0b9a4a277c760c536a3cea66a030abbfb2615f7b2851d5c6f"}}
1
+ {"schemaVersion":6,"generatedAt":"2026-10-20T18:23:51.998Z","structureHash":"164efa82c62dcbb7af775c8e3c635e9d6000b7c3b7f67d8a98464c1f66d1b5b1","files":{"amazon-bedrock.json":"3ca8bd1dd1b12d9b1241026c5edb6785bfb5d71225d48055848d6bbc625647d4","ant-ling.json":"628feab3ef6c7d80ce96f75999804e1d9f05fec3851e5302e30fff3b69db90f6","anthropic.json":"f797095e492df25157b14e399ff8030b4d0a75e698f415534cc79f606cf99ffb","azure.json":"b5cadb3c4b0a93c8558cf99927e0f00deee5ba0a1b4c8329dc12dc3be99b2b94","baseten.json":"df00cca103845b5b0ae6736c046e9500e4328eda3ad26cd0266541f2a5840cb1","cerebras.json":"3eccb58c5de3d0dc7ba49dc6e477ba29f00cb3150ce0a35cc90d59e6b5ab368e","cloudflare-ai-gateway.json":"0e06e0b4ad5710a1f4ae3076bea136f0a3bd47e2be35ead8ae714b65d22a936a","cloudflare-workers-ai.json":"89e822178dee9fc8702c8d4ea0f30b85f7525ce4e38b5e26cc5d62cc2784a93a","deepseek.json":"10a296fb3e898f7715c80890c8af0af4f5fd58f22dbcd6612fdc5d762157ccdc","fireworks.json":"8e862806b0a69cefc6585c38b103de1baae782c51409748c6d16199daedcf1ca","github-copilot.json":"519a4b716d7fbd6692b8237bd19ef8b6188e4e1976d65175d6f6bedc8b5d20a8","google-vertex.json":"564d692a4292ef12e98c8ec056a39948ea64e10851f5ddaaebcc37b585545231","google.json":"b61fb0e27da5be60e1112e46955c5923656cb4d62bb221f834a9463d764ef5de","groq.json":"910952ad9dad07856983459d63fce0148dba1203edd7b10d801a77c5824f3405","huggingface.json":"af9215bf3f27a162836effceb609652c6ca64dd96e02408f3f12ab92de687db0","kimi-coding.json":"728d5ddb63ef52130552022d5ae2fd138fdc131ff854ac8c3b10ccaad355ab39","meta.json":"563f5ec07973f52ab8c3eb26ef91a36ad8a79e950b37174935666cdcb624bf35","minimax-cn.json":"fa15d1f67a07046d38e191af9bd97ed922ba45a99a11af4ad281151cc6b762aa","minimax.json":"1e0459dda3858ea24151182106fc4179b95f43a0a8dffc1c3d2e7db4c2d9206e","mistral.json":"066079b17e077eb793ffa9574acd5f2bbe4d4f9566b12b6207a7c9b19b2db413","moonshotai-cn.json":"0dbd6b063a0abdbe55d5dc59dd4dade566c2ea817ad6184bc8d20655ecba1daf","moonshotai.json":"1da2c4e34f22aef17a07c974d85bdee8e1b68b6dc712e3769c935b3f1e7dadca","nvidia.json":"dcf20f026f1a5cbb9001adf35e4831dcf761b0dde866d5eddf63015aa41151ec","openai-codex.json":"d20e2c769968eb4070df70a73cc093aebd741fb734532cbb5b0a8b61b36b61de","openai-decisions.json":"0c7d54fcbac5e7388872a85c0db7f336c5a57c82d403266e9ae04f87561daf4f","openai-images.json":"885b1c5ec4198ebe2b73518e61cbf989a7cad9229d01813635f361b29a909562","openai.json":"6b8461776f8367d160fff29253c0326f74af1fc41258c77e6bf7151a33d20e35","opencode-go.json":"a6c2dee4bbd147e56a46f7171445236263ba7da8f56bd88f081a273cb7870ec8","opencode.json":"2ee60f9e8804bda5ebfeb52ce1a47e2c3c63c5c8dc731a70a7cc909efb65141e","openrouter.json":"a7d2e6e193484876b92a8fcfc6434de2e84d84f55b37351ede5610d549b4406e","qwen-token-plan-cn.json":"64427a6adeb3e7dd1857d68bef9bb12097632b646ed151b740e209143e31341e","qwen-token-plan-individual.json":"0fb7cf64faf39d1a3b0a884210a86c87084b805eda15644f5f39293287b959dd","qwen-token-plan.json":"37b9a76c54090228d1026a8f0fcb4d304b00d64b1a3a94cb2ae6e677d2c52b13","radius.json":"764d7457b8a88df8072d7d34946a009127abe2300f91d79d3178a7f63c54e5fd","together.json":"27df6f6d645a531b0ec8f38b897ba64eb0bf490014d50aa0f16f0e54b1801aa4","typesafe.json":"547d8b7a85771ceb0cfdf684e427b285a0125fd67e779af51f05ae13080db046","vercel-ai-gateway.json":"773b176757549b1751ce035ac564db54b0f1036cf1f47fbca4c572f3bda64bc6","xai.json":"59f8a7bdf14e79ba1b0d0a37e56251bbf100420bdac7d6af5942508fdb990f11","xiaomi-token-plan-ams.json":"bfd33741da693bdb8e8ebd4e7b90c3e90820aa18432ad081a5a98db13c6bd296","xiaomi-token-plan-cn.json":"4b61d78feae3a926fda918c3fd3a9afaf2ca60c1bba0af8270a5398fb50a983e","xiaomi-token-plan-sgp.json":"b05a197ce24fd69fc9440f4ba929984ac7a0fefbe8083268734b422e721987ec","xiaomi.json":"495b5fddf3c3ec8904fecc15c4c19536f4961dce7b51512b6909d2df2e739824","zai-coding-cn.json":"cc9e0768e726ef55d2b7af853ac5f3585dc72575932cb38840a3877d18736b78","zai.json":"58e6642fdfb736f0b9a4a277c760c536a3cea66a030abbfb2615f7b2851d5c6f"}}