summaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua72
1 files changed, 72 insertions, 0 deletions
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,
+}