@codeworksh/aikit 0.11.0 → 0.12.0-canary.47.1.g3f60acd1
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.
- package/cli.mjs +3 -3
- package/{copilot-JLgwmznn.mjs → copilot-DvUXC6Kx.mjs} +2 -2
- package/{copilot-JLgwmznn.mjs.map → copilot-DvUXC6Kx.mjs.map} +1 -1
- package/{copilot-headers-BvQ3FFn-.mjs → copilot-headers-BLnBaJyp.mjs} +2 -2
- package/{copilot-headers-BvQ3FFn-.mjs.map → copilot-headers-BLnBaJyp.mjs.map} +1 -1
- package/{github-copilot-C7oJ2Tfp.mjs → github-copilot-BcmOr0jd.mjs} +2 -2
- package/{github-copilot-C7oJ2Tfp.mjs.map → github-copilot-BcmOr0jd.mjs.map} +1 -1
- package/github-copilot-llyP2NK4.mjs +3 -0
- package/index.d.mts +3 -3
- package/index.mjs +5 -5
- package/index.mjs.map +1 -1
- package/model-Cjp-Dr8V.mjs +13955 -0
- package/model-Cjp-Dr8V.mjs.map +1 -0
- package/{model-DCfjY0fS.d.mts → model-D3wc9-u4.d.mts} +42 -19
- package/modelgen-BdiCqi-R.mjs +730 -0
- package/modelgen-BdiCqi-R.mjs.map +1 -0
- package/modelgen.d.mts +20 -3
- package/modelgen.mjs +61 -2
- package/modelgen.mjs.map +1 -0
- package/oauth/github/copilot.mjs +1 -1
- package/{openai-codex-Dj0oh0UV.mjs → openai-codex-C1Yb02kM.mjs} +2 -2
- package/{openai-codex-Dj0oh0UV.mjs.map → openai-codex-C1Yb02kM.mjs.map} +1 -1
- package/openai-codex-CHxShIN3.mjs +2 -0
- package/package.json +10 -10
- package/{registry-CfGgGfSs.mjs → registry-u49t0S4S.mjs} +4 -4
- package/{registry-CfGgGfSs.mjs.map → registry-u49t0S4S.mjs.map} +1 -1
- package/github-copilot-CLJx-bcP.mjs +0 -3
- package/model-D-FoGzVN.mjs +0 -522
- package/model-D-FoGzVN.mjs.map +0 -1
- package/modelgen-D6UBM1fq.mjs +0 -561
- package/modelgen-D6UBM1fq.mjs.map +0 -1
- package/openai-codex-CIBVNhQx.mjs +0 -2
package/model-D-FoGzVN.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"model-D-FoGzVN.mjs","names":["KnownProviderEnum","KnownProviderEnumSchema","Type","ModelCatalogLoadError","Filesystem.readText","ModelCatalog.KnownProviderEnum","ModelCatalog.KnownProviderEnumSchema","ModelCatalog.ModelCatalogLoadError","Type","ModelCatalog.path","ModelCatalog.get"],"sources":["../../src/utils/lazy.ts","../../src/utils/error.ts","../../src/utils/filesystem.ts","../../src/model/catalog.ts","../../src/model/model.ts"],"sourcesContent":["export function lazy<T>(fn: () => T) {\n\tlet value: T | undefined;\n\tlet loaded = false;\n\n\tconst result = (): T => {\n\t\tif (loaded) return value as T;\n\t\tvalue = fn();\n\t\tloaded = true;\n\t\treturn value as T;\n\t};\n\n\tresult.reset = () => {\n\t\tloaded = false;\n\t\tvalue = undefined;\n\t};\n\n\treturn result;\n}\n","import type { Static, TSchema } from \"typebox\";\n\ntype SchemaLike = TSchema;\ntype StaticData<Data extends SchemaLike> = Static<Data>;\n\nexport abstract class NamedError extends Error {\n\tabstract schema(): SchemaLike;\n\tabstract toObject(): { name: string; data: unknown };\n\n\tstatic create<Name extends string, Data extends SchemaLike>(name: Name, data: Data) {\n\t\tconst schema = {\n\t\t\t$id: name,\n\t\t\ttype: \"object\",\n\t\t\trequired: [\"name\", \"data\"],\n\t\t\tproperties: {\n\t\t\t\tname: {\n\t\t\t\t\tconst: name,\n\t\t\t\t},\n\t\t\t\tdata,\n\t\t\t},\n\t\t} as const;\n\n\t\tconst result = class extends NamedError {\n\t\t\tpublic static readonly Schema = schema;\n\n\t\t\tpublic override readonly name = name as Name;\n\n\t\t\tpublic readonly data: StaticData<Data>;\n\n\t\t\tconstructor(data: StaticData<Data>, options?: ErrorOptions) {\n\t\t\t\tsuper(name, options);\n\t\t\t\tthis.data = data;\n\t\t\t\tthis.name = name;\n\t\t\t}\n\n\t\t\tstatic isInstance(input: unknown): input is InstanceType<typeof result> {\n\t\t\t\treturn typeof input === \"object\" && input !== null && \"name\" in input && input.name === name;\n\t\t\t}\n\n\t\t\tschema() {\n\t\t\t\treturn schema;\n\t\t\t}\n\n\t\t\ttoObject() {\n\t\t\t\treturn {\n\t\t\t\t\tname,\n\t\t\t\t\tdata: this.data,\n\t\t\t\t};\n\t\t\t}\n\t\t};\n\n\t\tObject.defineProperty(result, \"name\", { value: name });\n\t\treturn result;\n\t}\n\n\tpublic static readonly Unknown = NamedError.create(\"UnknownError\", {\n\t\ttype: \"object\",\n\t\trequired: [\"message\"],\n\t\tproperties: {\n\t\t\tmessage: {\n\t\t\t\ttype: \"string\",\n\t\t\t},\n\t\t},\n\t});\n}\n","import { mkdir, readFile, rename, rm, writeFile } from \"fs/promises\";\nimport { dirname } from \"path\";\n\nexport async function readText(path: string): Promise<string> {\n\treturn readFile(path, \"utf-8\");\n}\n\nexport async function readJson<T = unknown>(path: string): Promise<T> {\n\treturn JSON.parse(await readFile(path, \"utf-8\"));\n}\n\nfunction isEnoent(error: unknown): error is { code: \"ENOENT\" } {\n\treturn (\n\t\ttypeof error === \"object\" && error !== null && \"code\" in error && (error as { code: string }).code === \"ENOENT\"\n\t);\n}\n\nexport async function write(path: string, content: string | Buffer | Uint8Array, mode?: number): Promise<void> {\n\ttry {\n\t\tif (mode) {\n\t\t\tawait writeFile(path, content, { mode });\n\t\t} else {\n\t\t\tawait writeFile(path, content);\n\t\t}\n\t} catch (error) {\n\t\tif (isEnoent(error)) {\n\t\t\tawait mkdir(dirname(path), { recursive: true });\n\t\t\tif (mode) {\n\t\t\t\tawait writeFile(path, content, { mode });\n\t\t\t} else {\n\t\t\t\tawait writeFile(path, content);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tthrow error;\n\t}\n}\n\nexport async function writeJson(path: string, data: unknown, mode?: number): Promise<void> {\n\treturn write(path, JSON.stringify(data, null, 2), mode);\n}\n\n/**\n * Write through a temp file and rename it into place, so a concurrent reader\n * sees either the old content or the new, never a partial file.\n */\nexport async function writeJsonAtomic(path: string, data: unknown): Promise<void> {\n\tconst temp = `${path}.${process.pid}.${Date.now()}.tmp`;\n\ttry {\n\t\tawait writeJson(temp, data);\n\t\tawait rename(temp, path);\n\t} catch (error) {\n\t\tawait rm(temp, { force: true });\n\t\tthrow error;\n\t}\n}\n","import { join, resolve } from \"node:path\";\nimport Type, { type Static } from \"typebox\";\nimport { NamedError } from \"../utils/error.ts\";\nimport * as Filesystem from \"../utils/filesystem.ts\";\nimport { lazy } from \"../utils/lazy.ts\";\n\n// known AI SDK LLM providers\n// used as the public protocol discriminator for the AI SDK transport layer\nexport const KnownProviderEnum = {\n\tanthropic: \"anthropic\",\n\tgoogle: \"google\",\n\tgoogleVertex: \"google-vertex\",\n\tgoogleVertexAnthropic: \"google-vertex-anthropic\",\n\tgithubCopilot: \"github-copilot\",\n\topenai: \"openai\",\n\topenaiCompatible: \"openai-compatible\",\n\topenaiCodex: \"openai-codex\",\n\topenrouter: \"openrouter\",\n\txai: \"xai\",\n} as const;\nexport const KnownProviderEnumSchema = Type.Union([\n\tType.Literal(KnownProviderEnum.anthropic),\n\tType.Literal(KnownProviderEnum.google),\n\tType.Literal(KnownProviderEnum.googleVertex),\n\tType.Literal(KnownProviderEnum.googleVertexAnthropic),\n\tType.Literal(KnownProviderEnum.githubCopilot),\n\tType.Literal(KnownProviderEnum.openai),\n\tType.Literal(KnownProviderEnum.openaiCompatible),\n\tType.Literal(KnownProviderEnum.openaiCodex),\n\tType.Literal(KnownProviderEnum.openrouter),\n\tType.Literal(KnownProviderEnum.xai),\n]);\nexport type KnownProviderEnum = Static<typeof KnownProviderEnumSchema>;\n\nexport type GeneratedCatalog = Partial<Record<string, Record<string, unknown>>>;\ntype LazyGeneratedCatalog = ReturnType<typeof lazy<Promise<GeneratedCatalog>>>;\n\nexport const ModelCatalogLoadError = NamedError.create(\n\t\"ModelCatalogLoadError\",\n\tType.Object({\n\t\tpath: Type.String(),\n\t\treason: Type.Union([\n\t\t\tType.Literal(\"missing\"),\n\t\t\tType.Literal(\"unreadable\"),\n\t\t\tType.Literal(\"empty\"),\n\t\t\tType.Literal(\"invalid\"),\n\t\t]),\n\t\tmessage: Type.String(),\n\t}),\n);\nexport type ModelCatalogLoadError = InstanceType<typeof ModelCatalogLoadError>;\n\nexport function projectRoot(): string {\n\treturn process.cwd();\n}\n\nexport const filename = \"models.gen.json\";\n\nlet configured: string | undefined;\n\n/**\n * Read the catalog from `catalogPath` instead of `./models.gen.json`, for an\n * embedder that keeps it elsewhere. `CODEWORK_MODELS_FILE` still wins.\n */\nexport function configure(catalogPath: string): void {\n\tconfigured = resolve(catalogPath);\n\tdata.reset();\n}\n\nexport function path(): string {\n\treturn resolve(process.env.CODEWORK_MODELS_FILE ?? configured ?? join(projectRoot(), filename));\n}\n\nexport async function load(catalogPath = path()): Promise<GeneratedCatalog> {\n\tlet content: string;\n\ttry {\n\t\tcontent = await Filesystem.readText(catalogPath);\n\t} catch (cause) {\n\t\tconst value =\n\t\t\ttypeof cause === \"object\" && cause !== null && \"code\" in cause && typeof cause.code === \"string\"\n\t\t\t\t? cause.code\n\t\t\t\t: undefined;\n\t\tconst reason = value === \"ENOENT\" ? \"missing\" : \"unreadable\";\n\t\tthrow new ModelCatalogLoadError(\n\t\t\t{\n\t\t\t\tpath: catalogPath,\n\t\t\t\treason,\n\t\t\t\tmessage:\n\t\t\t\t\treason === \"missing\"\n\t\t\t\t\t\t? `model catalog not found at ${catalogPath}`\n\t\t\t\t\t\t: `model catalog could not be read at ${catalogPath}`,\n\t\t\t},\n\t\t\t{ cause },\n\t\t);\n\t}\n\tif (!content.trim()) {\n\t\tthrow new ModelCatalogLoadError({\n\t\t\tpath: catalogPath,\n\t\t\treason: \"empty\",\n\t\t\tmessage: `model catalog is empty at ${catalogPath}`,\n\t\t});\n\t}\n\ttry {\n\t\tconst parsed: unknown = JSON.parse(content);\n\t\tif (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) throw new Error(\"expected an object\");\n\t\treturn parsed as GeneratedCatalog;\n\t} catch (cause) {\n\t\tthrow new ModelCatalogLoadError(\n\t\t\t{\n\t\t\t\tpath: catalogPath,\n\t\t\t\treason: \"invalid\",\n\t\t\t\tmessage: `model catalog contains invalid json at ${catalogPath}`,\n\t\t\t},\n\t\t\t{ cause },\n\t\t);\n\t}\n}\n\nexport const data: LazyGeneratedCatalog = lazy(() => load());\n\nexport async function get(): Promise<GeneratedCatalog> {\n\treturn data();\n}\n","import Type, { type Static } from \"typebox\";\nimport { lazy } from \"../utils/lazy.ts\";\nimport * as ModelCatalog from \"./catalog.ts\";\n\n// re-export\nexport const KnownProviderEnum = ModelCatalog.KnownProviderEnum;\nexport const KnownProviderEnumSchema = ModelCatalog.KnownProviderEnumSchema;\nexport type KnownProviderEnum = ModelCatalog.KnownProviderEnum;\n\nexport const ModelCatalogLoadError = ModelCatalog.ModelCatalogLoadError;\nexport type ModelCatalogLoadError = ModelCatalog.ModelCatalogLoadError;\n\n// Common reasoning-effort levels used by adapters that expose model reasoning,\n// thinking, or deliberation controls. Protocol-specific layers can map these\n// values to native fields like OpenAI `reasoning_effort`, Anthropic `thinking`,\n// or Gemini `thinkingConfig`.\nexport const ThinkingLevelEnum = {\n\t// Disable explicit reasoning controls when the provider supports turning them off.\n\toff: \"off\",\n\t// Smallest reasoning budget/effort above off; useful for fastest low-cost responses.\n\tminimal: \"minimal\",\n\t// Light reasoning for simple tasks that still benefit from some deliberation.\n\tlow: \"low\",\n\t// Balanced default for general tasks.\n\tmedium: \"medium\",\n\t// Higher reasoning effort for complex coding, analysis, or planning.\n\thigh: \"high\",\n\t// Extra-high reasoning effort for difficult tasks when supported by the model.\n\txhigh: \"xhigh\",\n\t// Maximum provider-defined effort above xhigh when explicitly supported by the model.\n\tmax: \"max\",\n} as const;\n\nexport const ThinkingLevel = Type.Union([\n\tType.Literal(ThinkingLevelEnum.off),\n\tType.Literal(ThinkingLevelEnum.minimal),\n\tType.Literal(ThinkingLevelEnum.low),\n\tType.Literal(ThinkingLevelEnum.medium),\n\tType.Literal(ThinkingLevelEnum.high),\n\tType.Literal(ThinkingLevelEnum.xhigh),\n\tType.Literal(ThinkingLevelEnum.max),\n]);\nexport type ThinkingLevel = Static<typeof ThinkingLevel>;\n\nexport const ActiveThinkingLevel = Type.Union([\n\tType.Literal(ThinkingLevelEnum.minimal),\n\tType.Literal(ThinkingLevelEnum.low),\n\tType.Literal(ThinkingLevelEnum.medium),\n\tType.Literal(ThinkingLevelEnum.high),\n\tType.Literal(ThinkingLevelEnum.xhigh),\n\tType.Literal(ThinkingLevelEnum.max),\n]);\nexport type ActiveThinkingLevel = Static<typeof ActiveThinkingLevel>;\n\nexport const ThinkingBudgets = Type.Partial(Type.Record(ActiveThinkingLevel, Type.Number()));\nexport type ThinkingBudgets = Static<typeof ThinkingBudgets>;\n\n// Note: order of entries matters!\nconst ACTIVE_THINKING_LEVELS = [\n\tThinkingLevelEnum.minimal,\n\tThinkingLevelEnum.low,\n\tThinkingLevelEnum.medium,\n\tThinkingLevelEnum.high,\n\tThinkingLevelEnum.xhigh,\n\tThinkingLevelEnum.max,\n] as const satisfies readonly ActiveThinkingLevel[];\nconst MODEL_THINKING_LEVELS = [\n\tThinkingLevelEnum.off,\n\t...ACTIVE_THINKING_LEVELS,\n] as const satisfies readonly ThinkingLevel[];\n\nexport const ProviderInfo = Type.Object({\n\tid: Type.String(),\n\tname: Type.String(),\n\tsource: Type.Enum([\"env\", \"config\", \"custom\", \"api\", \"unknown\"]),\n\tenv: Type.Array(Type.String()),\n\tkey: Type.Optional(Type.String()), // runtime api/oauth key\n\toptions: Type.Optional(Type.Record(Type.String(), Type.Any())),\n});\nexport type ProviderInfo = Static<typeof ProviderInfo>;\n\nconst InputSchema = Type.Array(Type.Union([Type.Literal(\"text\"), Type.Literal(\"image\")]));\nconst CostRatesSchema = Type.Object({\n\tinput: Type.Number(),\n\toutput: Type.Number(),\n\tcacheRead: Type.Number(),\n\tcacheWrite: Type.Number(),\n});\nconst CostTierSchema = Type.Object({\n\t...CostRatesSchema.properties,\n\tinputTokensAbove: Type.Number(),\n});\nconst CostSchema = Type.Object({\n\t...CostRatesSchema.properties,\n\ttiers: Type.Optional(Type.Array(CostTierSchema)),\n\tserviceTierMultipliers: Type.Optional(Type.Record(Type.String(), Type.Number())),\n});\nconst SupportedProtocolsSchema = Type.Partial(\n\tType.Object({\n\t\tanthropic: KnownProviderEnumSchema,\n\t\tgoogle: KnownProviderEnumSchema,\n\t\tgoogleVertex: KnownProviderEnumSchema,\n\t\tgoogleVertexAnthropic: KnownProviderEnumSchema,\n\t\tgithubCopilot: KnownProviderEnumSchema,\n\t\topenai: KnownProviderEnumSchema,\n\t\topenaiCompatible: KnownProviderEnumSchema,\n\t\topenaiCodex: KnownProviderEnumSchema,\n\t\topenrouter: KnownProviderEnumSchema,\n\t\txai: KnownProviderEnumSchema,\n\t}),\n);\n\nexport const APIMethodEnum = {\n\tlanguageModel: \"languageModel\",\n\tchat: \"chat\",\n\tcompletion: \"completion\",\n\tcompletionModel: \"completionModel\",\n\tmessages: \"messages\",\n\tresponses: \"responses\",\n} as const;\nexport const APIMethodEnumSchema = Type.Union([\n\tType.Literal(APIMethodEnum.languageModel),\n\tType.Literal(APIMethodEnum.chat),\n\tType.Literal(APIMethodEnum.completion),\n\tType.Literal(APIMethodEnum.completionModel),\n\tType.Literal(APIMethodEnum.messages),\n\tType.Literal(APIMethodEnum.responses),\n]);\nexport type APIMethodEnum = Static<typeof APIMethodEnumSchema>;\n\nexport const APIMetadataSchema = Type.Object({\n\tid: Type.Optional(Type.String()),\n\turl: Type.Optional(Type.String()),\n\tmethod: Type.Optional(APIMethodEnumSchema),\n});\nexport type APIMetadata = Static<typeof APIMetadataSchema>;\n\nexport const ThinkingLevelMapSchema = Type.Partial(\n\tType.Record(\n\t\tThinkingLevel, // Safe key validation\n\t\tType.Union([Type.String(), Type.Null()]), // Allowed values\n\t),\n);\nexport type ThinkingLevelMap = Static<typeof ThinkingLevelMapSchema>;\n\nexport const CompatibilitySchema = Type.Object({\n\t/** The Google protocol accepts thinking levels rather than a token budget. */\n\tsupportsThinkingLevel: Type.Optional(Type.Boolean()),\n\tsupportsToolSearch: Type.Optional(Type.Boolean()),\n\tsupportsAdditionalTools: Type.Optional(Type.Boolean()),\n\tsupportsStrictMode: Type.Optional(Type.Boolean()),\n\tsupportsOpenAIGrammarTools: Type.Optional(Type.Boolean()),\n\t/** The model takes a thinking-token budget as a top-level request field. */\n\tsupportsThinkingTokenBudget: Type.Optional(Type.Boolean()),\n\t/** Claude model that sizes its own thinking, driven by `effort` instead of a token budget. */\n\tforceAdaptiveThinking: Type.Optional(Type.Boolean()),\n\t/** Name of that field, when it is not the conventional `thinking_token_budget`. */\n\tthinkingTokenBudgetField: Type.Optional(Type.String()),\n});\nexport type Compatibility = Static<typeof CompatibilitySchema>;\n\n/**\n * Claude models that decide their own thinking depth.\n *\n * These take an `effort` level and let the model size each turn's reasoning; the\n * older models take a fixed `budget_tokens` instead. Sending a budget to an\n * adaptive model pins it to one depth for every turn, which is the thing adaptive\n * thinking exists to avoid.\n */\nexport function isAnthropicAdaptiveThinkingModel(modelId: string): boolean {\n\treturn [\n\t\t\"opus-4-6\",\n\t\t\"opus-4.6\",\n\t\t\"opus-4-7\",\n\t\t\"opus-4.7\",\n\t\t\"opus-4-8\",\n\t\t\"opus-4.8\",\n\t\t\"opus-5\",\n\t\t\"opus.5\",\n\t\t\"sonnet-4-6\",\n\t\t\"sonnet-4.6\",\n\t\t\"sonnet-5\",\n\t\t\"sonnet.5\",\n\t\t\"fable-5\",\n\t\t\"haiku-5\",\n\t\t\"haiku.5\",\n\t].some((needle) => modelId.includes(needle));\n}\n\nexport const Schema = Type.Object({\n\tid: Type.String(),\n\tname: Type.String(),\n\tprovider: ProviderInfo,\n\tbaseUrl: Type.String(),\n\treasoning: Type.Boolean(),\n\tthinkingLevelMap: Type.Optional(ThinkingLevelMapSchema),\n\t/** Default budgets; request-level thinkingBudgets take precedence. */\n\tthinkingBudgets: Type.Optional(ThinkingBudgets),\n\tinput: InputSchema,\n\tcost: CostSchema,\n\tcontextWindow: Type.Number(),\n\tmaxTokens: Type.Number(),\n\theaders: Type.Optional(Type.Record(Type.String(), Type.String())),\n\tnpm: Type.Optional(Type.String()),\n\tapi: Type.Optional(APIMetadataSchema),\n\tproviderOptionsKey: Type.Optional(Type.String()),\n\toptions: Type.Optional(Type.Record(Type.String(), Type.Unknown())),\n\tproviderOptions: Type.Optional(Type.Record(Type.String(), Type.Unknown())),\n\tcompat: Type.Optional(CompatibilitySchema),\n\tprotocol: KnownProviderEnumSchema, // provider as the underlying protocol\n\tsupportedProtocols: Type.Optional(SupportedProtocolsSchema), // provider as the underlying supported protocols\n});\n\nexport const ExtrasSchema = Type.Object({});\n\nexport const Info = Type.Evaluate(Type.Intersect([Schema, ExtrasSchema]));\nexport type Info = Static<typeof Info>;\nexport type TModel<TProtocol extends KnownProviderEnum> = Omit<Info, \"protocol\"> & { protocol: TProtocol };\n\nexport function calculateCost(\n\tmodel: Info,\n\tusage: {\n\t\tinput: number;\n\t\toutput: number;\n\t\tcacheRead: number;\n\t\tcacheWrite: number;\n\t\tcacheWrite1h?: number;\n\t\tcost: {\n\t\t\tinput: number;\n\t\t\toutput: number;\n\t\t\tcacheRead: number;\n\t\t\tcacheWrite: number;\n\t\t\ttotal: number;\n\t\t};\n\t},\n): void {\n\tconst inputTokens = usage.input + usage.cacheRead + usage.cacheWrite;\n\tlet rates = model.cost;\n\tlet matchedThreshold = -1;\n\tfor (const tier of model.cost.tiers ?? []) {\n\t\tif (inputTokens > tier.inputTokensAbove && tier.inputTokensAbove > matchedThreshold) {\n\t\t\trates = tier;\n\t\t\tmatchedThreshold = tier.inputTokensAbove;\n\t\t}\n\t}\n\n\t// Anthropic charges 2x base input for 1h cache writes; `cost.cacheWrite` is the 5m rate.\n\tconst longWrite = usage.cacheWrite1h ?? 0;\n\tconst shortWrite = usage.cacheWrite - longWrite;\n\n\tusage.cost.input = (usage.input / 1_000_000) * rates.input;\n\tusage.cost.output = (usage.output / 1_000_000) * rates.output;\n\tusage.cost.cacheRead = (usage.cacheRead / 1_000_000) * rates.cacheRead;\n\tusage.cost.cacheWrite = (rates.cacheWrite * shortWrite + rates.input * 2 * longWrite) / 1_000_000;\n\tusage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;\n}\n\nexport type BuiltInModels = Partial<Record<string, Record<string, Info>>>;\n\nexport function normalizeInput(input?: string[]): Array<\"text\" | \"image\"> {\n\tconst normalized = new Set<\"text\" | \"image\">();\n\tfor (const modality of input ?? [\"text\"]) {\n\t\tif (modality === \"text\" || modality === \"image\") {\n\t\t\tnormalized.add(modality);\n\t\t}\n\t}\n\tif (normalized.size === 0) normalized.add(\"text\");\n\treturn [...normalized];\n}\n\n/** Where the catalog is read from: `CODEWORK_MODELS_FILE`, the configured path, or `./models.gen.json`. */\nexport const catalogPath = ModelCatalog.path;\n\n/** Read the catalog from `path` from now on, dropping whatever was already loaded. */\nexport function configureCatalog(path: string): void {\n\tModelCatalog.configure(path);\n\tregistry.reset();\n}\n\n/** Drop the loaded catalog, so the next lookup re-reads the file -- after it was regenerated. */\nexport function reloadCatalog(): void {\n\tModelCatalog.data.reset();\n\tregistry.reset();\n}\n\nexport async function getBuiltInModels(): Promise<BuiltInModels> {\n\treturn (await ModelCatalog.get()) as BuiltInModels;\n}\n\nexport const registry = lazy(async () => {\n\tconst registry: Map<string, Map<string, Info>> = new Map();\n\tconst models = await getBuiltInModels();\n\tfor (const [provider, value] of Object.entries(models) as Array<[string, Record<string, Info>]>) {\n\t\tconst providerModels = new Map<string, Info>();\n\t\tfor (const [id, model] of Object.entries(value)) {\n\t\t\tproviderModels.set(id, model);\n\t\t}\n\t\tregistry.set(provider, providerModels);\n\t}\n\treturn registry;\n});\n\n/**\n * The key a provider's own option bag is filed under.\n *\n * Providers that speak another provider's protocol still carry their own option\n * namespace, so this is not always the protocol.\n */\n/**\n * The request-body field a model takes its thinking-token budget in, if any.\n *\n * OpenAI-compatible endpoints have no standard place for this, so each one names\n * its own field; a bare `supportsThinkingTokenBudget` means the conventional name.\n */\nexport function thinkingTokenBudgetField(model: Info): string | undefined {\n\tif (model.compat?.thinkingTokenBudgetField) return model.compat.thinkingTokenBudgetField;\n\treturn model.compat?.supportsThinkingTokenBudget ? \"thinking_token_budget\" : undefined;\n}\n\nexport function optionsKey(model: Info): string {\n\treturn model.providerOptionsKey ?? model.protocol;\n}\n\nexport function supportsProtocol(model: Info, protocol: KnownProviderEnum): boolean {\n\tif (model.protocol === protocol) return true;\n\treturn Object.values(model.supportedProtocols ?? {}).includes(protocol);\n}\n\nexport type ProviderToProtocol<TProvider extends string> = TProvider extends KnownProviderEnum\n\t? TProvider\n\t: KnownProviderEnum;\n\nexport async function getModel<\n\tTProvider extends string,\n\tTProtocol extends KnownProviderEnum = ProviderToProtocol<TProvider>,\n>(\n\tprovider: TProvider,\n\tmodel: string,\n\toverrides?: Partial<Info> & { protocol?: TProtocol },\n): Promise<TModel<TProtocol> | undefined> {\n\tconst data = await registry();\n\tconst providerModels = data.get(provider);\n\tconst result = providerModels?.get(model);\n\tif (result && overrides) {\n\t\tif (overrides.protocol && !supportsProtocol(result, overrides.protocol)) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn {\n\t\t\t...result,\n\t\t\t...overrides,\n\t\t} as TModel<TProtocol>;\n\t}\n\treturn result as TModel<TProtocol> | undefined;\n}\n\nexport async function getProviders(): Promise<string[]> {\n\tconst data = await registry();\n\treturn Array.from(data.keys());\n}\n\nexport async function getModels<TProvider extends string>(provider: TProvider): Promise<Info[]> {\n\tconst data = await registry();\n\tconst models = data.get(provider);\n\treturn models ? Array.from(models.values()) : [];\n}\n\n/**\n * Check if two models are equal by comparing both their id and provider id.\n * Returns false if either model is null or undefined.\n */\nexport function modelsAreEqual(a: Info | null | undefined, b: Info | null | undefined): boolean {\n\tif (!a || !b) return false;\n\treturn a.id === b.id && a.provider.id === b.provider.id;\n}\n\nexport function getSupportedThinkingLevels<TProtocol extends KnownProviderEnum>(\n\tmodel: TModel<TProtocol>,\n): ThinkingLevel[] {\n\tif (!model.reasoning) return [\"off\"];\n\n\treturn MODEL_THINKING_LEVELS.filter((level) => {\n\t\tconst mapped = model.thinkingLevelMap?.[level];\n\t\tif (mapped === null) return false;\n\t\tif (level === \"xhigh\" || level === \"max\") return mapped !== undefined;\n\t\treturn true;\n\t});\n}\n\nexport function clampThinkingLevel<TProtocol extends KnownProviderEnum>(\n\tmodel: TModel<TProtocol>,\n\tlevel: ThinkingLevel,\n): ThinkingLevel {\n\tconst availableLevels = getSupportedThinkingLevels(model);\n\tif (availableLevels.includes(level)) return level;\n\n\tconst requestedIndex = MODEL_THINKING_LEVELS.indexOf(level);\n\tif (requestedIndex === -1) return availableLevels[0] ?? \"off\";\n\n\t// walk up the ladder from the point and pick first supported\n\t// biased to avail more thinking, then less not round to nearest.\n\tfor (let i = requestedIndex; i < MODEL_THINKING_LEVELS.length; i++) {\n\t\tconst candidate = MODEL_THINKING_LEVELS[i]!;\n\t\tif (availableLevels.includes(candidate)) return candidate;\n\t}\n\t// otherwise walk down from the point\n\tfor (let i = requestedIndex - 1; i >= 0; i--) {\n\t\tconst candidate = MODEL_THINKING_LEVELS[i]!;\n\t\tif (availableLevels.includes(candidate)) return candidate;\n\t}\n\treturn availableLevels[0] ?? \"off\";\n}\n"],"mappings":";;;;;;AAAA,SAAgB,KAAQ,IAAa;CACpC,IAAI;CACJ,IAAI,SAAS;CAEb,MAAM,eAAkB;EACvB,IAAI,QAAQ,OAAO;EACnB,QAAQ,GAAG;EACX,SAAS;EACT,OAAO;CACR;CAEA,OAAO,cAAc;EACpB,SAAS;EACT,QAAQ,KAAA;CACT;CAEA,OAAO;AACR;;;ACZA,IAAsB,aAAtB,MAAsB,mBAAmB,MAAM;CAI9C,OAAO,OAAqD,MAA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@@ -1,561 +0,0 @@
|
|
|
1
|
-
import { C as writeJsonAtomic, S as readJson, _ as normalizeInput, i as KnownProviderEnum, m as isAnthropicAdaptiveThinkingModel, t as APIMethodEnum, x as path } from "./model-D-FoGzVN.mjs";
|
|
2
|
-
import { a as protocolForPackage, n as isAISDKPackage } from "./registry-CfGgGfSs.mjs";
|
|
3
|
-
import { n as GITHUB_COPILOT_STATIC_HEADERS } from "./copilot-headers-BvQ3FFn-.mjs";
|
|
4
|
-
import { resolve } from "node:path";
|
|
5
|
-
import { mapValues, pickBy, pipe } from "remeda";
|
|
6
|
-
//#region src/cli/modelgen.ts
|
|
7
|
-
const DEFAULT_PROVIDER_BASE_URLS = {
|
|
8
|
-
[KnownProviderEnum.anthropic]: "https://api.anthropic.com/v1",
|
|
9
|
-
[KnownProviderEnum.openai]: "https://api.openai.com/v1",
|
|
10
|
-
[KnownProviderEnum.openrouter]: "https://openrouter.ai/api/v1",
|
|
11
|
-
[KnownProviderEnum.xai]: "https://api.x.ai/v1"
|
|
12
|
-
};
|
|
13
|
-
function modelsDevURL() {
|
|
14
|
-
return process.env.OPENCODE_MODELS_URL || "https://models.dev";
|
|
15
|
-
}
|
|
16
|
-
function modelsDevPath() {
|
|
17
|
-
return process.env.OPENCODE_MODELS_DEV_FILE;
|
|
18
|
-
}
|
|
19
|
-
async function pullModelsDevData() {
|
|
20
|
-
const path = modelsDevPath();
|
|
21
|
-
if (path) {
|
|
22
|
-
const result = await readJson(path).catch(() => void 0);
|
|
23
|
-
if (result) return result;
|
|
24
|
-
}
|
|
25
|
-
const response = await fetch(`${modelsDevURL()}/api.json`);
|
|
26
|
-
if (!response.ok) throw new Error(`models.dev responded ${response.status} ${response.statusText}`);
|
|
27
|
-
return await response.json();
|
|
28
|
-
}
|
|
29
|
-
function toModelValue(providerId, provider, model) {
|
|
30
|
-
return applyModification(providerId, provider, model);
|
|
31
|
-
}
|
|
32
|
-
function loadBuiltInFromModelsDev(catalog) {
|
|
33
|
-
return pipe(catalog, pickBy((provider) => Object.values(provider.models).some((model) => Boolean(model.tool_call) && isAISDKPackage(resolveModelNpm(provider, model)))), mapValues((provider, providerId) => pipe(provider.models, pickBy((model) => Boolean(model.tool_call) && isAISDKPackage(resolveModelNpm(provider, model))), mapValues((model) => toModelValue(providerId, provider, model)), pickBy((model) => model !== void 0))));
|
|
34
|
-
}
|
|
35
|
-
function resolveModelNpm(provider, model) {
|
|
36
|
-
return model.provider?.npm ?? provider.npm ?? "@ai-sdk/openai-compatible";
|
|
37
|
-
}
|
|
38
|
-
function resolveModelBaseUrl(provider, model) {
|
|
39
|
-
const npm = resolveModelNpm(provider, model);
|
|
40
|
-
const protocol = protocolForPackage(npm);
|
|
41
|
-
return model.baseUrl ?? model.provider?.api ?? provider.api ?? DEFAULT_PROVIDER_BASE_URLS[protocol] ?? "";
|
|
42
|
-
}
|
|
43
|
-
function resolveModelAPIMethod(npm) {
|
|
44
|
-
const protocol = protocolForPackage(npm);
|
|
45
|
-
if (protocol === KnownProviderEnum.openai || protocol === KnownProviderEnum.xai) return APIMethodEnum.responses;
|
|
46
|
-
return APIMethodEnum.languageModel;
|
|
47
|
-
}
|
|
48
|
-
function resolveProviderOptionsKey(protocol) {
|
|
49
|
-
if (protocol === KnownProviderEnum.openaiCompatible) return "openai-compatible";
|
|
50
|
-
if (protocol === KnownProviderEnum.googleVertex) return "google-vertex";
|
|
51
|
-
if (protocol === KnownProviderEnum.googleVertexAnthropic) return "google-vertex-anthropic";
|
|
52
|
-
return protocol;
|
|
53
|
-
}
|
|
54
|
-
const OPENAI_RESPONSES_NONE_REASONING_MODELS = /* @__PURE__ */ new Set([
|
|
55
|
-
"gpt-5.1",
|
|
56
|
-
"gpt-5.2",
|
|
57
|
-
"gpt-5.3-codex",
|
|
58
|
-
"gpt-5.4",
|
|
59
|
-
"gpt-5.4-mini",
|
|
60
|
-
"gpt-5.4-nano",
|
|
61
|
-
"gpt-5.5",
|
|
62
|
-
"gpt-5.6-luna",
|
|
63
|
-
"gpt-5.6-sol",
|
|
64
|
-
"gpt-5.6-terra",
|
|
65
|
-
"gpt-6-luna",
|
|
66
|
-
"gpt-6-sol"
|
|
67
|
-
]);
|
|
68
|
-
const OPENAI_NO_MINIMAL_REASONING = /gpt-5\.[456]|gpt-6/;
|
|
69
|
-
function isOpenAiResponses(model) {
|
|
70
|
-
return model.protocol === KnownProviderEnum.openai || model.protocol === KnownProviderEnum.openaiCodex;
|
|
71
|
-
}
|
|
72
|
-
function supportsOpenAiXhigh(model) {
|
|
73
|
-
return /gpt-5\.[2-5]/.test(model.id) || supportsOpenAiMax(model);
|
|
74
|
-
}
|
|
75
|
-
function supportsOpenAiMax(model) {
|
|
76
|
-
return isOpenAiResponses(model) && /gpt-5\.6|gpt-6/.test(model.id);
|
|
77
|
-
}
|
|
78
|
-
function mergeThinkingLevelMap(model, map) {
|
|
79
|
-
model.thinkingLevelMap = {
|
|
80
|
-
...model.thinkingLevelMap,
|
|
81
|
-
...map
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
function mergeCompat(model, compat) {
|
|
85
|
-
model.compat = {
|
|
86
|
-
...model.compat,
|
|
87
|
-
...compat
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
function applyGoogleThinkingMetadata(model) {
|
|
91
|
-
const id = model.id.toLowerCase();
|
|
92
|
-
const supportsThinkingLevel = /gemini-3(?:\.\d+)?-(?:pro|flash)|gemma-?4/.test(id) || id === "gemini-flash-latest" || id === "gemini-flash-lite-latest";
|
|
93
|
-
mergeCompat(model, { supportsThinkingLevel });
|
|
94
|
-
if (supportsThinkingLevel) return;
|
|
95
|
-
model.thinkingBudgets = [
|
|
96
|
-
["2.5-pro", {
|
|
97
|
-
minimal: 128,
|
|
98
|
-
low: 2048,
|
|
99
|
-
medium: 8192,
|
|
100
|
-
high: 32768
|
|
101
|
-
}],
|
|
102
|
-
["2.5-flash-lite", {
|
|
103
|
-
minimal: 512,
|
|
104
|
-
low: 2048,
|
|
105
|
-
medium: 8192,
|
|
106
|
-
high: 24576
|
|
107
|
-
}],
|
|
108
|
-
["2.5-flash", {
|
|
109
|
-
minimal: 128,
|
|
110
|
-
low: 2048,
|
|
111
|
-
medium: 8192,
|
|
112
|
-
high: 24576
|
|
113
|
-
}]
|
|
114
|
-
].find(([family]) => id.includes(family))?.[1] ?? {
|
|
115
|
-
minimal: -1,
|
|
116
|
-
low: -1,
|
|
117
|
-
medium: -1,
|
|
118
|
-
high: -1
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
function applyModelMetadata(model) {
|
|
122
|
-
if (model.protocol === KnownProviderEnum.google || model.protocol === KnownProviderEnum.googleVertex) applyGoogleThinkingMetadata(model);
|
|
123
|
-
if (model.protocol === KnownProviderEnum.openai || model.protocol === KnownProviderEnum.openaiCodex) model.cost.serviceTierMultipliers = {
|
|
124
|
-
flex: .5,
|
|
125
|
-
priority: model.id === "gpt-5.5" ? 2.5 : 2
|
|
126
|
-
};
|
|
127
|
-
if ((model.protocol === KnownProviderEnum.google || model.protocol === KnownProviderEnum.googleVertex) && /gemini-3(?:\.\d+)?-pro|gemini-3\.[78]-flash/.test(model.id.toLowerCase())) mergeThinkingLevelMap(model, {
|
|
128
|
-
off: "low",
|
|
129
|
-
minimal: null
|
|
130
|
-
});
|
|
131
|
-
if ((model.protocol === KnownProviderEnum.anthropic || model.protocol === KnownProviderEnum.googleVertexAnthropic) && isAnthropicAdaptiveThinkingModel(model.id)) mergeCompat(model, { forceAdaptiveThinking: true });
|
|
132
|
-
if (model.protocol === KnownProviderEnum.openai && model.id.startsWith("gpt-5")) mergeThinkingLevelMap(model, { off: null });
|
|
133
|
-
if (model.protocol === KnownProviderEnum.openai && model.provider.id === "openai" && OPENAI_RESPONSES_NONE_REASONING_MODELS.has(model.id)) mergeThinkingLevelMap(model, { off: "none" });
|
|
134
|
-
if (supportsOpenAiXhigh(model)) mergeThinkingLevelMap(model, { xhigh: "xhigh" });
|
|
135
|
-
if (isOpenAiResponses(model) && OPENAI_NO_MINIMAL_REASONING.test(model.id)) mergeThinkingLevelMap(model, { minimal: null });
|
|
136
|
-
if (supportsOpenAiMax(model)) mergeThinkingLevelMap(model, { max: "max" });
|
|
137
|
-
if (model.id.includes("opus-4-6") || model.id.includes("opus-4.6")) mergeThinkingLevelMap(model, { xhigh: "max" });
|
|
138
|
-
if (model.id.includes("opus-4-7") || model.id.includes("opus-4.7")) mergeThinkingLevelMap(model, { xhigh: "xhigh" });
|
|
139
|
-
if (isAnthropicMessages(model)) applyAnthropicMetadata(model);
|
|
140
|
-
}
|
|
141
|
-
function isAnthropicMessages(model) {
|
|
142
|
-
return model.protocol === KnownProviderEnum.anthropic || model.protocol === KnownProviderEnum.googleVertexAnthropic;
|
|
143
|
-
}
|
|
144
|
-
function applyAnthropicMetadata(model) {
|
|
145
|
-
const id = model.id;
|
|
146
|
-
if (/sonnet-4[-.]5/.test(id)) model.contextWindow = 2e5;
|
|
147
|
-
if (/(opus|sonnet)-4[-.]6/.test(id)) mergeThinkingLevelMap(model, { max: "max" });
|
|
148
|
-
if (/opus-4[-.][78]|(opus|sonnet|fable|haiku)-5/.test(id)) mergeThinkingLevelMap(model, {
|
|
149
|
-
xhigh: "xhigh",
|
|
150
|
-
max: "max"
|
|
151
|
-
});
|
|
152
|
-
if (/(opus|sonnet)-5[-.]5/.test(id)) mergeThinkingLevelMap(model, {
|
|
153
|
-
off: null,
|
|
154
|
-
minimal: null
|
|
155
|
-
});
|
|
156
|
-
if (/fable-5/.test(id)) mergeThinkingLevelMap(model, { off: null });
|
|
157
|
-
}
|
|
158
|
-
const OPENAI_CODEX_PROVIDER_ID = "openai-codex";
|
|
159
|
-
const OPENAI_CODEX_NPM = "@codeworksh/ai-sdk-openai-codex";
|
|
160
|
-
const OPENAI_CODEX_BASE_URL = "https://chatgpt.com/backend-api";
|
|
161
|
-
const OPENAI_CODEX_CONTEXT = 272e3;
|
|
162
|
-
const OPENAI_CODEX_GPT_56_CONTEXT = 272e3;
|
|
163
|
-
const OPENAI_CODEX_SPARK_CONTEXT = 128e3;
|
|
164
|
-
const OPENAI_CODEX_MAX_TOKENS = 128e3;
|
|
165
|
-
const OPENAI_LONG_CONTEXT_INPUT_THRESHOLD = 272e3;
|
|
166
|
-
const OPENAI_CODEX_TOOL_SEARCH_MODEL_IDS = /* @__PURE__ */ new Set([
|
|
167
|
-
"gpt-5.4",
|
|
168
|
-
"gpt-5.4-mini",
|
|
169
|
-
"gpt-5.5",
|
|
170
|
-
"gpt-5.6-luna",
|
|
171
|
-
"gpt-5.6-sol",
|
|
172
|
-
"gpt-5.6-terra",
|
|
173
|
-
"gpt-6-luna"
|
|
174
|
-
]);
|
|
175
|
-
const OPENAI_CODEX_ADDITIONAL_TOOLS_MODEL_IDS = /* @__PURE__ */ new Set([
|
|
176
|
-
"gpt-5.6-luna",
|
|
177
|
-
"gpt-5.6-sol",
|
|
178
|
-
"gpt-5.6-terra",
|
|
179
|
-
"gpt-6-luna"
|
|
180
|
-
]);
|
|
181
|
-
const OPENAI_CODEX_NONE_REASONING_MODEL_IDS = /* @__PURE__ */ new Set([
|
|
182
|
-
"gpt-5.5",
|
|
183
|
-
"gpt-5.6-luna",
|
|
184
|
-
"gpt-6-luna"
|
|
185
|
-
]);
|
|
186
|
-
function roundCost(value) {
|
|
187
|
-
return Number(value.toFixed(6));
|
|
188
|
-
}
|
|
189
|
-
function withOpenAiLongContextPricing(cost) {
|
|
190
|
-
return {
|
|
191
|
-
...cost,
|
|
192
|
-
tiers: [{
|
|
193
|
-
inputTokensAbove: OPENAI_LONG_CONTEXT_INPUT_THRESHOLD,
|
|
194
|
-
input: roundCost(cost.input * 2),
|
|
195
|
-
output: roundCost(cost.output * 1.5),
|
|
196
|
-
cacheRead: roundCost(cost.cacheRead * 2),
|
|
197
|
-
cacheWrite: roundCost(cost.cacheWrite * 2)
|
|
198
|
-
}]
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
const OPENAI_CODEX_COSTS = {
|
|
202
|
-
"gpt-5.6-luna": {
|
|
203
|
-
input: .2,
|
|
204
|
-
output: 1.2,
|
|
205
|
-
cacheRead: .02,
|
|
206
|
-
cacheWrite: .25
|
|
207
|
-
},
|
|
208
|
-
"gpt-5.6-terra": {
|
|
209
|
-
input: 2,
|
|
210
|
-
output: 12,
|
|
211
|
-
cacheRead: .2,
|
|
212
|
-
cacheWrite: 2.5
|
|
213
|
-
},
|
|
214
|
-
"gpt-6-luna": {
|
|
215
|
-
input: .1,
|
|
216
|
-
output: .5,
|
|
217
|
-
cacheRead: .01,
|
|
218
|
-
cacheWrite: .125
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
const OPENAI_CODEX_MODELS = [
|
|
222
|
-
{
|
|
223
|
-
id: "gpt-5.3-codex-spark",
|
|
224
|
-
name: "GPT-5.3 Codex Spark",
|
|
225
|
-
input: ["text"],
|
|
226
|
-
cost: {
|
|
227
|
-
input: 1.75,
|
|
228
|
-
output: 14,
|
|
229
|
-
cacheRead: .175,
|
|
230
|
-
cacheWrite: 0
|
|
231
|
-
},
|
|
232
|
-
contextWindow: OPENAI_CODEX_SPARK_CONTEXT
|
|
233
|
-
},
|
|
234
|
-
{
|
|
235
|
-
id: "gpt-5.4",
|
|
236
|
-
name: "GPT-5.4",
|
|
237
|
-
input: ["text", "image"],
|
|
238
|
-
cost: withOpenAiLongContextPricing({
|
|
239
|
-
input: 2.5,
|
|
240
|
-
output: 15,
|
|
241
|
-
cacheRead: .25,
|
|
242
|
-
cacheWrite: 0
|
|
243
|
-
}),
|
|
244
|
-
contextWindow: OPENAI_CODEX_CONTEXT
|
|
245
|
-
},
|
|
246
|
-
{
|
|
247
|
-
id: "gpt-5.4-mini",
|
|
248
|
-
name: "GPT-5.4 mini",
|
|
249
|
-
input: ["text", "image"],
|
|
250
|
-
cost: {
|
|
251
|
-
input: .75,
|
|
252
|
-
output: 4.5,
|
|
253
|
-
cacheRead: .075,
|
|
254
|
-
cacheWrite: 0
|
|
255
|
-
},
|
|
256
|
-
contextWindow: OPENAI_CODEX_CONTEXT
|
|
257
|
-
},
|
|
258
|
-
{
|
|
259
|
-
id: "gpt-5.5",
|
|
260
|
-
name: "GPT-5.5",
|
|
261
|
-
input: ["text", "image"],
|
|
262
|
-
cost: withOpenAiLongContextPricing({
|
|
263
|
-
input: 5,
|
|
264
|
-
output: 30,
|
|
265
|
-
cacheRead: .5,
|
|
266
|
-
cacheWrite: 0
|
|
267
|
-
}),
|
|
268
|
-
contextWindow: OPENAI_CODEX_CONTEXT
|
|
269
|
-
},
|
|
270
|
-
{
|
|
271
|
-
id: "gpt-5.6-luna",
|
|
272
|
-
name: "GPT-5.6 Luna",
|
|
273
|
-
input: ["text", "image"],
|
|
274
|
-
cost: withOpenAiLongContextPricing(OPENAI_CODEX_COSTS["gpt-5.6-luna"]),
|
|
275
|
-
contextWindow: OPENAI_CODEX_GPT_56_CONTEXT,
|
|
276
|
-
thinkingLevelMap: { minimal: null }
|
|
277
|
-
},
|
|
278
|
-
{
|
|
279
|
-
id: "gpt-5.6-sol",
|
|
280
|
-
name: "GPT-5.6 Sol",
|
|
281
|
-
input: ["text", "image"],
|
|
282
|
-
cost: withOpenAiLongContextPricing({
|
|
283
|
-
input: 5,
|
|
284
|
-
output: 30,
|
|
285
|
-
cacheRead: .5,
|
|
286
|
-
cacheWrite: 6.25
|
|
287
|
-
}),
|
|
288
|
-
contextWindow: OPENAI_CODEX_GPT_56_CONTEXT,
|
|
289
|
-
thinkingLevelMap: { minimal: null }
|
|
290
|
-
},
|
|
291
|
-
{
|
|
292
|
-
id: "gpt-5.6-terra",
|
|
293
|
-
name: "GPT-5.6 Terra",
|
|
294
|
-
input: ["text", "image"],
|
|
295
|
-
cost: withOpenAiLongContextPricing(OPENAI_CODEX_COSTS["gpt-5.6-terra"]),
|
|
296
|
-
contextWindow: OPENAI_CODEX_GPT_56_CONTEXT,
|
|
297
|
-
thinkingLevelMap: { minimal: null }
|
|
298
|
-
},
|
|
299
|
-
{
|
|
300
|
-
id: "gpt-6-luna",
|
|
301
|
-
name: "GPT-6 Luna",
|
|
302
|
-
input: ["text", "image"],
|
|
303
|
-
cost: withOpenAiLongContextPricing(OPENAI_CODEX_COSTS["gpt-6-luna"]),
|
|
304
|
-
contextWindow: OPENAI_CODEX_GPT_56_CONTEXT
|
|
305
|
-
}
|
|
306
|
-
];
|
|
307
|
-
function openAICodexBuiltInModels() {
|
|
308
|
-
const models = {};
|
|
309
|
-
for (const seed of OPENAI_CODEX_MODELS) {
|
|
310
|
-
const supportsToolSearch = OPENAI_CODEX_TOOL_SEARCH_MODEL_IDS.has(seed.id);
|
|
311
|
-
const supportsAdditionalTools = OPENAI_CODEX_ADDITIONAL_TOOLS_MODEL_IDS.has(seed.id);
|
|
312
|
-
const info = {
|
|
313
|
-
...seed,
|
|
314
|
-
provider: {
|
|
315
|
-
id: OPENAI_CODEX_PROVIDER_ID,
|
|
316
|
-
name: "OpenAI Codex (ChatGPT)",
|
|
317
|
-
source: "custom",
|
|
318
|
-
env: ["OPENAI_CODEX_API_KEY"]
|
|
319
|
-
},
|
|
320
|
-
baseUrl: OPENAI_CODEX_BASE_URL,
|
|
321
|
-
reasoning: true,
|
|
322
|
-
thinkingLevelMap: {
|
|
323
|
-
off: OPENAI_CODEX_NONE_REASONING_MODEL_IDS.has(seed.id) ? "none" : null,
|
|
324
|
-
...seed.thinkingLevelMap
|
|
325
|
-
},
|
|
326
|
-
maxTokens: OPENAI_CODEX_MAX_TOKENS,
|
|
327
|
-
npm: OPENAI_CODEX_NPM,
|
|
328
|
-
api: {
|
|
329
|
-
id: seed.id,
|
|
330
|
-
url: OPENAI_CODEX_BASE_URL,
|
|
331
|
-
method: APIMethodEnum.responses
|
|
332
|
-
},
|
|
333
|
-
providerOptionsKey: OPENAI_CODEX_PROVIDER_ID,
|
|
334
|
-
compat: {
|
|
335
|
-
supportsOpenAIGrammarTools: true,
|
|
336
|
-
...supportsToolSearch ? { supportsToolSearch: true } : {},
|
|
337
|
-
...supportsAdditionalTools ? { supportsAdditionalTools: true } : {}
|
|
338
|
-
},
|
|
339
|
-
protocol: KnownProviderEnum.openaiCodex
|
|
340
|
-
};
|
|
341
|
-
applyModelMetadata(info);
|
|
342
|
-
models[seed.id] = info;
|
|
343
|
-
}
|
|
344
|
-
return models;
|
|
345
|
-
}
|
|
346
|
-
const GITHUB_COPILOT_PROVIDER_ID = "github-copilot";
|
|
347
|
-
const GITHUB_COPILOT_NPM = "@codeworksh/ai-sdk-github-copilot";
|
|
348
|
-
const GITHUB_COPILOT_BASE_URL = "https://api.githubcopilot.com";
|
|
349
|
-
const GITHUB_COPILOT_EXTENDED_CONTEXT = 1e6;
|
|
350
|
-
const GITHUB_COPILOT_EXTENDED_CONTEXT_MODELS = /* @__PURE__ */ new Set([
|
|
351
|
-
"claude-fable-5",
|
|
352
|
-
"claude-opus-4.6",
|
|
353
|
-
"claude-opus-4.7",
|
|
354
|
-
"claude-opus-4.8",
|
|
355
|
-
"claude-opus-5",
|
|
356
|
-
"claude-sonnet-4.6",
|
|
357
|
-
"claude-sonnet-5",
|
|
358
|
-
"gpt-5.3-codex",
|
|
359
|
-
"gpt-5.4",
|
|
360
|
-
"gpt-5.5"
|
|
361
|
-
]);
|
|
362
|
-
const GITHUB_COPILOT_THINKING_LEVEL_OVERRIDES = {
|
|
363
|
-
"claude-opus-4.7": { minimal: "low" },
|
|
364
|
-
"claude-opus-4.8": { minimal: "low" },
|
|
365
|
-
"claude-opus-5": { minimal: "low" },
|
|
366
|
-
"claude-sonnet-4.6": {
|
|
367
|
-
minimal: "low",
|
|
368
|
-
max: "max"
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
/**
|
|
372
|
-
* The offline routing approximation (pi). The live `/models` response's
|
|
373
|
-
* `supported_endpoints` is authoritative at runtime.
|
|
374
|
-
*
|
|
375
|
-
* - `claude-(haiku|sonnet|opus|fable)-[45]` → Anthropic Messages
|
|
376
|
-
* - `gpt-*`, `grok-*`, `oswe*`, `mai-*` → OpenAI Responses
|
|
377
|
-
* - everything else → OpenAI Chat Completions
|
|
378
|
-
*/
|
|
379
|
-
function githubCopilotApiMethod(modelId) {
|
|
380
|
-
if (/^claude-(haiku|sonnet|opus|fable)-[45]([.-]|$)/.test(modelId)) return APIMethodEnum.messages;
|
|
381
|
-
const gpt = /^gpt-(\d+)/.exec(modelId);
|
|
382
|
-
if (gpt !== null && Number(gpt[1]) >= 5 || modelId.startsWith("grok-") || modelId.startsWith("oswe") || modelId.startsWith("mai-")) return APIMethodEnum.responses;
|
|
383
|
-
return APIMethodEnum.chat;
|
|
384
|
-
}
|
|
385
|
-
/** Effort values models.dev advertises for a model, when it lists any. */
|
|
386
|
-
function githubCopilotEffortValues(model) {
|
|
387
|
-
for (const option of model.reasoning_options ?? []) if (option.type === "effort" && Array.isArray(option.values)) return new Set(option.values);
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* Derive the level map from models.dev `reasoning_options`: a level maps to
|
|
391
|
-
* itself only when the endpoint actually advertises it. `minimal` degrades to
|
|
392
|
-
* `low` — the lowest effort every reasoning model accepts.
|
|
393
|
-
*/
|
|
394
|
-
function githubCopilotThinkingLevels(model, method) {
|
|
395
|
-
const efforts = githubCopilotEffortValues(model);
|
|
396
|
-
const map = {};
|
|
397
|
-
if (method !== APIMethodEnum.messages) map.off = null;
|
|
398
|
-
if (!efforts) return Object.keys(map).length > 0 ? map : void 0;
|
|
399
|
-
if (efforts.has("minimal")) map.minimal = "minimal";
|
|
400
|
-
else if (efforts.has("low")) map.minimal = "low";
|
|
401
|
-
for (const level of [
|
|
402
|
-
"low",
|
|
403
|
-
"medium",
|
|
404
|
-
"high",
|
|
405
|
-
"xhigh",
|
|
406
|
-
"max"
|
|
407
|
-
]) map[level] = efforts.has(level) ? level : null;
|
|
408
|
-
return map;
|
|
409
|
-
}
|
|
410
|
-
function githubCopilotCostTiers(model) {
|
|
411
|
-
const tiers = model.cost?.tiers?.flatMap((tier) => {
|
|
412
|
-
const context = tier.tier;
|
|
413
|
-
if (context?.type !== "context" || context.size === void 0) return [];
|
|
414
|
-
return [{
|
|
415
|
-
inputTokensAbove: context.size,
|
|
416
|
-
input: tier.input ?? 0,
|
|
417
|
-
output: tier.output ?? 0,
|
|
418
|
-
cacheRead: tier.cache_read ?? 0,
|
|
419
|
-
cacheWrite: tier.cache_write ?? 0
|
|
420
|
-
}];
|
|
421
|
-
});
|
|
422
|
-
return tiers && tiers.length > 0 ? tiers : void 0;
|
|
423
|
-
}
|
|
424
|
-
function githubCopilotBuiltInModels(provider) {
|
|
425
|
-
const models = {};
|
|
426
|
-
if (!provider) return models;
|
|
427
|
-
for (const [id, source] of Object.entries(provider.models)) {
|
|
428
|
-
if (source.tool_call !== true) continue;
|
|
429
|
-
if (source.status === "deprecated") continue;
|
|
430
|
-
if (id === "gpt-5-chat-latest") continue;
|
|
431
|
-
const base = applyModification(GITHUB_COPILOT_PROVIDER_ID, provider, source);
|
|
432
|
-
if (!base) continue;
|
|
433
|
-
const method = githubCopilotApiMethod(id);
|
|
434
|
-
const tiers = githubCopilotCostTiers(source);
|
|
435
|
-
const info = {
|
|
436
|
-
...base,
|
|
437
|
-
provider: {
|
|
438
|
-
id: GITHUB_COPILOT_PROVIDER_ID,
|
|
439
|
-
name: "GitHub Copilot",
|
|
440
|
-
source: "custom",
|
|
441
|
-
env: ["COPILOT_GITHUB_TOKEN"]
|
|
442
|
-
},
|
|
443
|
-
baseUrl: GITHUB_COPILOT_BASE_URL,
|
|
444
|
-
headers: { ...GITHUB_COPILOT_STATIC_HEADERS },
|
|
445
|
-
cost: {
|
|
446
|
-
...base.cost,
|
|
447
|
-
...tiers ? { tiers } : {}
|
|
448
|
-
},
|
|
449
|
-
npm: GITHUB_COPILOT_NPM,
|
|
450
|
-
api: {
|
|
451
|
-
id,
|
|
452
|
-
url: GITHUB_COPILOT_BASE_URL,
|
|
453
|
-
method
|
|
454
|
-
},
|
|
455
|
-
providerOptionsKey: GITHUB_COPILOT_PROVIDER_ID,
|
|
456
|
-
protocol: KnownProviderEnum.githubCopilot,
|
|
457
|
-
...method === APIMethodEnum.responses ? { providerOptions: {
|
|
458
|
-
...base.providerOptions,
|
|
459
|
-
[GITHUB_COPILOT_PROVIDER_ID]: {
|
|
460
|
-
store: false,
|
|
461
|
-
include: ["reasoning.encrypted_content"]
|
|
462
|
-
}
|
|
463
|
-
} } : {}
|
|
464
|
-
};
|
|
465
|
-
if (GITHUB_COPILOT_EXTENDED_CONTEXT_MODELS.has(id)) info.contextWindow = GITHUB_COPILOT_EXTENDED_CONTEXT;
|
|
466
|
-
if (method === APIMethodEnum.messages && isAnthropicAdaptiveThinkingModel(id)) mergeCompat(info, { forceAdaptiveThinking: true });
|
|
467
|
-
const gpt = /^gpt-(\d+)/.exec(id);
|
|
468
|
-
if (method === APIMethodEnum.responses && gpt !== null && Number(gpt[1]) >= 5) mergeCompat(info, { supportsOpenAIGrammarTools: true });
|
|
469
|
-
if (id.startsWith("gpt-5")) mergeThinkingLevelMap(info, {
|
|
470
|
-
off: null,
|
|
471
|
-
minimal: "low"
|
|
472
|
-
});
|
|
473
|
-
if (id.includes("fable-5")) mergeThinkingLevelMap(info, {
|
|
474
|
-
off: null,
|
|
475
|
-
xhigh: "xhigh",
|
|
476
|
-
max: "max"
|
|
477
|
-
});
|
|
478
|
-
const levels = githubCopilotThinkingLevels(source, method);
|
|
479
|
-
if (levels) mergeThinkingLevelMap(info, levels);
|
|
480
|
-
const override = GITHUB_COPILOT_THINKING_LEVEL_OVERRIDES[id];
|
|
481
|
-
if (override) mergeThinkingLevelMap(info, override);
|
|
482
|
-
models[id] = info;
|
|
483
|
-
}
|
|
484
|
-
return models;
|
|
485
|
-
}
|
|
486
|
-
async function generateModels(args = {}) {
|
|
487
|
-
const path$1 = resolve(args.path ?? path());
|
|
488
|
-
const catalog = await pullModelsDevData();
|
|
489
|
-
const modelsDev = loadBuiltInFromModelsDev(catalog);
|
|
490
|
-
const customCodexModels = openAICodexBuiltInModels();
|
|
491
|
-
const copilotProvider = catalog[GITHUB_COPILOT_PROVIDER_ID];
|
|
492
|
-
const allModels = {
|
|
493
|
-
...modelsDev,
|
|
494
|
-
[OPENAI_CODEX_PROVIDER_ID]: customCodexModels,
|
|
495
|
-
...copilotProvider ? { [GITHUB_COPILOT_PROVIDER_ID]: githubCopilotBuiltInModels(copilotProvider) } : {}
|
|
496
|
-
};
|
|
497
|
-
await writeJsonAtomic(path$1, allModels);
|
|
498
|
-
return path$1;
|
|
499
|
-
}
|
|
500
|
-
const ModelgenCommand = {
|
|
501
|
-
command: "modelgen [path]",
|
|
502
|
-
describe: "generate models.gen.json",
|
|
503
|
-
builder: (yargs) => yargs.positional("path", {
|
|
504
|
-
type: "string",
|
|
505
|
-
describe: "output path (defaults to CODEWORK_MODELS_FILE or ./models.gen.json)"
|
|
506
|
-
}),
|
|
507
|
-
handler: async (args) => {
|
|
508
|
-
const path = await generateModels(args);
|
|
509
|
-
console.log(`Generated model catalog at ${path}`);
|
|
510
|
-
}
|
|
511
|
-
};
|
|
512
|
-
function applyModification(providerId, provider, model) {
|
|
513
|
-
const npm = resolveModelNpm(provider, model);
|
|
514
|
-
if (!isAISDKPackage(npm)) return;
|
|
515
|
-
const protocol = protocolForPackage(npm);
|
|
516
|
-
const baseUrl = resolveModelBaseUrl(provider, model);
|
|
517
|
-
const providerInfo = {
|
|
518
|
-
id: providerId,
|
|
519
|
-
name: provider.name,
|
|
520
|
-
source: "api",
|
|
521
|
-
env: provider.env
|
|
522
|
-
};
|
|
523
|
-
if (provider.key) providerInfo.key = provider.key;
|
|
524
|
-
const api = {
|
|
525
|
-
id: model.id,
|
|
526
|
-
method: resolveModelAPIMethod(npm)
|
|
527
|
-
};
|
|
528
|
-
if (baseUrl) api.url = baseUrl;
|
|
529
|
-
const info = {
|
|
530
|
-
id: model.id,
|
|
531
|
-
name: model.name,
|
|
532
|
-
provider: providerInfo,
|
|
533
|
-
baseUrl,
|
|
534
|
-
reasoning: Boolean(model.reasoning),
|
|
535
|
-
input: normalizeInput(model.modalities.input),
|
|
536
|
-
cost: {
|
|
537
|
-
input: model.cost?.input ?? 0,
|
|
538
|
-
output: model.cost?.output ?? 0,
|
|
539
|
-
cacheRead: model.cost?.cache_read ?? 0,
|
|
540
|
-
cacheWrite: model.cost?.cache_write ?? 0
|
|
541
|
-
},
|
|
542
|
-
contextWindow: model.limit?.context ?? 4096,
|
|
543
|
-
maxTokens: model.limit?.output ?? 4096,
|
|
544
|
-
headers: {
|
|
545
|
-
...provider.headers,
|
|
546
|
-
...model.provider?.headers,
|
|
547
|
-
...model.headers
|
|
548
|
-
},
|
|
549
|
-
npm,
|
|
550
|
-
api,
|
|
551
|
-
providerOptionsKey: resolveProviderOptionsKey(protocol),
|
|
552
|
-
protocol
|
|
553
|
-
};
|
|
554
|
-
if (Object.keys(info.headers ?? {}).length === 0) delete info.headers;
|
|
555
|
-
applyModelMetadata(info);
|
|
556
|
-
return info;
|
|
557
|
-
}
|
|
558
|
-
//#endregion
|
|
559
|
-
export { generateModels as n, ModelgenCommand as t };
|
|
560
|
-
|
|
561
|
-
//# sourceMappingURL=modelgen-D6UBM1fq.mjs.map
|