From 3fd3bd6b58b1c9404075c8256ff3ae99fc5b542c Mon Sep 17 00:00:00 2001 From: t Date: Fri, 16 Oct 2026 20:13:59 -0600 Subject: initial commit; basically working --- init.lua | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 init.lua (limited to 'init.lua') diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..32c98de --- /dev/null +++ b/init.lua @@ -0,0 +1,72 @@ +-- Codex subscription defaults for panto. No login, networking, or session activation. +local auth_defaults = { + type = "oauth_device", + dialect = "codex", + client_id = "app_EMoamEEZ73f0CkXaXp7hrann", + device_code_url = "https://auth.openai.com/api/accounts/deviceauth/usercode", + device_poll_url = "https://auth.openai.com/api/accounts/deviceauth/token", + verification_url = "https://auth.openai.com/codex/device", + token_url = "https://auth.openai.com/oauth/token", + account_id_jwt_claim = "https://api.openai.com/auth", +} + +local provider_defaults = { + style = "openai_responses", + model_catalog_name = "openai", + extra_headers = { + ["OpenAI-Beta"] = "responses=experimental", + originator = "codex_cli_rs", + }, +} + +local endpoint_defaults = { + openai_responses = { + base_url = "https://chatgpt.com/backend-api/codex", + dialect = "codex", + }, +} + +-- Fill only missing values; HTTP header names are case-insensitive. +local function fill_missing(target, defaults, headers) + for key, value in pairs(defaults) do + local target_key = key + if headers then + for existing in pairs(target) do + if type(existing) == "string" and existing:lower() == key:lower() then + target_key = existing + break + end + end + end + if target[target_key] == nil then + target[target_key] = type(value) == "table" and {} or value + end + if type(value) == "table" and type(target[target_key]) == "table" then + fill_missing(target[target_key], value, key == "extra_headers") + end + end +end + +return { + name = "codex", + configure = function(config) + for _, auth in pairs(config.auth or {}) do + if type(auth) == "table" and auth.panto_codex_extension == true then + fill_missing(auth, auth_defaults) + end + end + for _, provider in pairs(config.providers or {}) do + if type(provider) == "table" and provider.panto_codex_extension == true then + fill_missing(provider, provider_defaults) + if provider.endpoints == nil then + fill_missing(provider, { base_url = endpoint_defaults.openai_responses.base_url }) + if provider.style == "openai_responses" then + fill_missing(provider, { dialect = endpoint_defaults.openai_responses.dialect }) + end + else + fill_missing(provider, { endpoints = endpoint_defaults }) + end + end + end + end, +} -- cgit v1.3