@bolt-foundry/gambit 0.8.3 → 0.8.5-rc.4
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/CHANGELOG.md +34 -2
- package/README.md +79 -16
- package/esm/_dnt.polyfills.d.ts +17 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +122 -0
- package/esm/deps/jsr.io/@std/collections/1.1.5/deep_merge.d.ts +322 -0
- package/esm/deps/jsr.io/@std/collections/1.1.5/deep_merge.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.1.5/deep_merge.js +105 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_create_walk_entry.d.ts +14 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_create_walk_entry.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_create_walk_entry.js +34 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_get_file_info_type.d.ts +13 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_get_file_info_type.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_get_file_info_type.js +18 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_is_same_path.d.ts +10 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_is_same_path.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_is_same_path.js +17 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_is_subdir.d.ts +12 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_is_subdir.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_is_subdir.js +25 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_to_path_string.d.ts +9 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_to_path_string.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_to_path_string.js +13 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/copy.d.ts +117 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/copy.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/copy.js +313 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/empty_dir.d.ts +48 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/empty_dir.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/empty_dir.js +87 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_dir.d.ts +49 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_dir.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_dir.js +102 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_file.d.ts +47 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_file.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_file.js +90 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_link.d.ts +49 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_link.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_link.js +61 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_symlink.d.ts +70 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_symlink.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_symlink.js +156 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/eol.d.ts +52 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/eol.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/eol.js +67 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/exists.d.ts +218 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/exists.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/exists.js +271 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/expand_glob.d.ts +267 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/expand_glob.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/expand_glob.js +442 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/mod.d.ts +29 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/mod.js +29 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/move.d.ts +86 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/move.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/move.js +142 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/walk.d.ts +777 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/walk.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/walk.js +846 -0
- package/esm/deps/jsr.io/@std/json/1.0.2/types.d.ts +5 -0
- package/esm/deps/jsr.io/@std/json/1.0.2/types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/json/1.0.2/types.js +3 -0
- package/esm/deps/jsr.io/@std/jsonc/1.0.2/mod.d.ts +20 -0
- package/esm/deps/jsr.io/@std/jsonc/1.0.2/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/jsonc/1.0.2/mod.js +21 -0
- package/esm/deps/jsr.io/@std/jsonc/1.0.2/parse.d.ts +21 -0
- package/esm/deps/jsr.io/@std/jsonc/1.0.2/parse.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/jsonc/1.0.2/parse.js +320 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/_parser.d.ts +93 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/_parser.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/_parser.js +753 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/mod.d.ts +109 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/mod.js +110 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/parse.d.ts +21 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/parse.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/parse.js +25 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/stringify.d.ts +35 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/stringify.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/stringify.js +283 -0
- package/esm/gambit/simulator-ui/dist/bundle.js +10647 -4637
- package/esm/gambit/simulator-ui/dist/bundle.js.map +4 -4
- package/esm/mod.d.ts +13 -3
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +8 -2
- package/esm/src/cli_utils.d.ts +1 -0
- package/esm/src/cli_utils.d.ts.map +1 -1
- package/esm/src/cli_utils.js +13 -1
- package/esm/src/default_runtime.d.ts +46 -0
- package/esm/src/default_runtime.d.ts.map +1 -0
- package/esm/src/default_runtime.js +415 -0
- package/esm/src/durable_streams.js +26 -1
- package/esm/src/model_matchers.d.ts +10 -0
- package/esm/src/model_matchers.d.ts.map +1 -0
- package/esm/src/model_matchers.js +26 -0
- package/esm/src/openai_compat.d.ts +12 -1
- package/esm/src/openai_compat.d.ts.map +1 -1
- package/esm/src/openai_compat.js +53 -1
- package/esm/src/project_config.d.ts +47 -0
- package/esm/src/project_config.d.ts.map +1 -0
- package/esm/src/project_config.js +134 -0
- package/esm/src/providers/codex.d.ts +37 -0
- package/esm/src/providers/codex.d.ts.map +1 -0
- package/esm/src/providers/codex.js +810 -0
- package/esm/src/providers/google.d.ts +3 -1
- package/esm/src/providers/google.d.ts.map +1 -1
- package/esm/src/providers/google.js +82 -6
- package/esm/src/providers/ollama.d.ts +3 -1
- package/esm/src/providers/ollama.d.ts.map +1 -1
- package/esm/src/providers/ollama.js +238 -15
- package/esm/src/providers/openrouter.d.ts +6 -2
- package/esm/src/providers/openrouter.d.ts.map +1 -1
- package/esm/src/providers/openrouter.js +260 -23
- package/esm/src/providers/router.d.ts +19 -0
- package/esm/src/providers/router.d.ts.map +1 -0
- package/esm/src/providers/router.js +93 -0
- package/esm/src/server.d.ts +9 -0
- package/esm/src/server.d.ts.map +1 -1
- package/esm/src/server.js +3186 -652
- package/esm/src/server_feedback_grading_routes.d.ts +32 -0
- package/esm/src/server_feedback_grading_routes.d.ts.map +1 -0
- package/esm/src/server_feedback_grading_routes.js +305 -0
- package/esm/src/server_helpers.d.ts +4 -0
- package/esm/src/server_helpers.d.ts.map +1 -0
- package/esm/src/server_helpers.js +46 -0
- package/esm/src/server_session_store.d.ts +87 -0
- package/esm/src/server_session_store.d.ts.map +1 -0
- package/esm/src/server_session_store.js +873 -0
- package/esm/src/server_types.d.ts +110 -0
- package/esm/src/server_types.d.ts.map +1 -0
- package/esm/src/server_types.js +1 -0
- package/esm/src/server_ui_routes.d.ts +33 -0
- package/esm/src/server_ui_routes.d.ts.map +1 -0
- package/esm/src/server_ui_routes.js +135 -0
- package/esm/src/session_artifacts.d.ts +22 -0
- package/esm/src/session_artifacts.d.ts.map +1 -0
- package/esm/src/session_artifacts.js +243 -0
- package/esm/src/trace.d.ts.map +1 -1
- package/esm/src/trace.js +6 -3
- package/esm/src/workspace.d.ts +19 -0
- package/esm/src/workspace.d.ts.map +1 -0
- package/esm/src/workspace.js +164 -0
- package/esm/src/workspace_contract.d.ts +76 -0
- package/esm/src/workspace_contract.d.ts.map +1 -0
- package/esm/src/workspace_contract.js +74 -0
- package/package.json +2 -2
- package/script/_dnt.polyfills.d.ts +17 -0
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +122 -0
- package/script/deps/jsr.io/@std/collections/1.1.5/deep_merge.d.ts +322 -0
- package/script/deps/jsr.io/@std/collections/1.1.5/deep_merge.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/collections/1.1.5/deep_merge.js +108 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_create_walk_entry.d.ts +14 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_create_walk_entry.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_create_walk_entry.js +71 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_get_file_info_type.d.ts +13 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_get_file_info_type.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_get_file_info_type.js +21 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_is_same_path.d.ts +10 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_is_same_path.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_is_same_path.js +20 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_is_subdir.d.ts +12 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_is_subdir.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_is_subdir.js +28 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_to_path_string.d.ts +9 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_to_path_string.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_to_path_string.js +16 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/copy.d.ts +117 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/copy.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/copy.js +350 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/empty_dir.d.ts +48 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/empty_dir.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/empty_dir.js +124 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_dir.d.ts +49 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_dir.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_dir.js +139 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_file.d.ts +47 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_file.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_file.js +127 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_link.d.ts +49 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_link.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_link.js +98 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_symlink.d.ts +70 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_symlink.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_symlink.js +193 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/eol.d.ts +52 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/eol.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/eol.js +105 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/exists.d.ts +218 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/exists.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/exists.js +308 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/expand_glob.d.ts +267 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/expand_glob.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/expand_glob.js +479 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/mod.d.ts +29 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/mod.js +45 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/move.d.ts +86 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/move.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/move.js +179 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/walk.d.ts +777 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/walk.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/walk.js +883 -0
- package/script/deps/jsr.io/@std/json/1.0.2/types.d.ts +5 -0
- package/script/deps/jsr.io/@std/json/1.0.2/types.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/json/1.0.2/types.js +4 -0
- package/script/deps/jsr.io/@std/jsonc/1.0.2/mod.d.ts +20 -0
- package/script/deps/jsr.io/@std/jsonc/1.0.2/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/jsonc/1.0.2/mod.js +37 -0
- package/script/deps/jsr.io/@std/jsonc/1.0.2/parse.d.ts +21 -0
- package/script/deps/jsr.io/@std/jsonc/1.0.2/parse.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/jsonc/1.0.2/parse.js +323 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/_parser.d.ts +93 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/_parser.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/_parser.js +781 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/mod.d.ts +109 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/mod.js +126 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/parse.d.ts +21 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/parse.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/parse.js +28 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/stringify.d.ts +35 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/stringify.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/stringify.js +286 -0
- package/script/gambit/simulator-ui/dist/bundle.js +10647 -4637
- package/script/gambit/simulator-ui/dist/bundle.js.map +4 -4
- package/script/mod.d.ts +13 -3
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +14 -5
- package/script/src/cli_utils.d.ts +1 -0
- package/script/src/cli_utils.d.ts.map +1 -1
- package/script/src/cli_utils.js +14 -1
- package/script/src/default_runtime.d.ts +46 -0
- package/script/src/default_runtime.d.ts.map +1 -0
- package/script/src/default_runtime.js +452 -0
- package/script/src/durable_streams.js +26 -1
- package/script/src/model_matchers.d.ts +10 -0
- package/script/src/model_matchers.d.ts.map +1 -0
- package/script/src/model_matchers.js +29 -0
- package/script/src/openai_compat.d.ts +12 -1
- package/script/src/openai_compat.d.ts.map +1 -1
- package/script/src/openai_compat.js +85 -0
- package/script/src/project_config.d.ts +47 -0
- package/script/src/project_config.d.ts.map +1 -0
- package/script/src/project_config.js +173 -0
- package/script/src/providers/codex.d.ts +37 -0
- package/script/src/providers/codex.d.ts.map +1 -0
- package/script/src/providers/codex.js +850 -0
- package/script/src/providers/google.d.ts +3 -1
- package/script/src/providers/google.d.ts.map +1 -1
- package/script/src/providers/google.js +82 -6
- package/script/src/providers/ollama.d.ts +3 -1
- package/script/src/providers/ollama.d.ts.map +1 -1
- package/script/src/providers/ollama.js +238 -15
- package/script/src/providers/openrouter.d.ts +6 -2
- package/script/src/providers/openrouter.d.ts.map +1 -1
- package/script/src/providers/openrouter.js +260 -23
- package/script/src/providers/router.d.ts +19 -0
- package/script/src/providers/router.d.ts.map +1 -0
- package/script/src/providers/router.js +96 -0
- package/script/src/server.d.ts +9 -0
- package/script/src/server.d.ts.map +1 -1
- package/script/src/server.js +3193 -659
- package/script/src/server_feedback_grading_routes.d.ts +32 -0
- package/script/src/server_feedback_grading_routes.d.ts.map +1 -0
- package/script/src/server_feedback_grading_routes.js +343 -0
- package/script/src/server_helpers.d.ts +4 -0
- package/script/src/server_helpers.d.ts.map +1 -0
- package/script/src/server_helpers.js +84 -0
- package/script/src/server_session_store.d.ts +87 -0
- package/script/src/server_session_store.d.ts.map +1 -0
- package/script/src/server_session_store.js +910 -0
- package/script/src/server_types.d.ts +110 -0
- package/script/src/server_types.d.ts.map +1 -0
- package/script/src/server_types.js +2 -0
- package/script/src/server_ui_routes.d.ts +33 -0
- package/script/src/server_ui_routes.d.ts.map +1 -0
- package/script/src/server_ui_routes.js +172 -0
- package/script/src/session_artifacts.d.ts +22 -0
- package/script/src/session_artifacts.d.ts.map +1 -0
- package/script/src/session_artifacts.js +279 -0
- package/script/src/trace.d.ts.map +1 -1
- package/script/src/trace.js +6 -3
- package/script/src/workspace.d.ts +19 -0
- package/script/src/workspace.d.ts.map +1 -0
- package/script/src/workspace.js +201 -0
- package/script/src/workspace_contract.d.ts +76 -0
- package/script/src/workspace_contract.d.ts.map +1 -0
- package/script/src/workspace_contract.js +82 -0
|
@@ -0,0 +1,850 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.CODEX_PREFIX = void 0;
|
|
37
|
+
exports.createCodexProvider = createCodexProvider;
|
|
38
|
+
exports.parseCodexArgsForTest = parseCodexArgsForTest;
|
|
39
|
+
exports.parseCodexStdoutForTest = parseCodexStdoutForTest;
|
|
40
|
+
exports.safeJsonForTest = safeJsonForTest;
|
|
41
|
+
const dntShim = __importStar(require("../../_dnt.shims.js"));
|
|
42
|
+
const path = __importStar(require("../../deps/jsr.io/@std/path/1.1.4/mod.js"));
|
|
43
|
+
exports.CODEX_PREFIX = "codex-cli/";
|
|
44
|
+
const CODEX_THREAD_META_KEY = "codex.threadId";
|
|
45
|
+
const BOT_ROOT_ENV = "GAMBIT_BOT_ROOT";
|
|
46
|
+
const CODEX_MCP_ENV = "GAMBIT_CODEX_ENABLE_MCP";
|
|
47
|
+
const CODEX_DISABLE_MCP_ENV = "GAMBIT_CODEX_DISABLE_MCP";
|
|
48
|
+
const CODEX_REASONING_EFFORT_ENV = "GAMBIT_CODEX_REASONING_EFFORT";
|
|
49
|
+
const CODEX_REASONING_SUMMARY_ENV = "GAMBIT_CODEX_REASONING_SUMMARY";
|
|
50
|
+
const CODEX_VERBOSITY_ENV = "GAMBIT_CODEX_VERBOSITY";
|
|
51
|
+
const CODEX_BIN_ENV = "GAMBIT_CODEX_BIN";
|
|
52
|
+
const MCP_ROOT_DECK_PATH_ENV = "GAMBIT_MCP_ROOT_DECK_PATH";
|
|
53
|
+
const MCP_SERVER_PATH = path.resolve(path.dirname(path.fromFileUrl(globalThis[Symbol.for("import-meta-ponyfill-commonjs")](require, module).url)), "../mcp_server.ts");
|
|
54
|
+
const REASONING_EFFORT_VALUES = new Set([
|
|
55
|
+
"none",
|
|
56
|
+
"minimal",
|
|
57
|
+
"low",
|
|
58
|
+
"medium",
|
|
59
|
+
"high",
|
|
60
|
+
"xhigh",
|
|
61
|
+
]);
|
|
62
|
+
const REASONING_SUMMARY_VALUES = new Set([
|
|
63
|
+
"none",
|
|
64
|
+
"auto",
|
|
65
|
+
"concise",
|
|
66
|
+
"detailed",
|
|
67
|
+
]);
|
|
68
|
+
const VERBOSITY_VALUES = new Set([
|
|
69
|
+
"low",
|
|
70
|
+
"medium",
|
|
71
|
+
"high",
|
|
72
|
+
]);
|
|
73
|
+
function runCwd() {
|
|
74
|
+
const botRoot = dntShim.Deno.env.get(BOT_ROOT_ENV);
|
|
75
|
+
if (typeof botRoot === "string" && botRoot.trim().length > 0) {
|
|
76
|
+
return botRoot.trim();
|
|
77
|
+
}
|
|
78
|
+
return dntShim.Deno.cwd();
|
|
79
|
+
}
|
|
80
|
+
function shouldEnableMcpBridge() {
|
|
81
|
+
const parseTruthy = (value) => {
|
|
82
|
+
const normalized = value.trim().toLowerCase();
|
|
83
|
+
if (!normalized)
|
|
84
|
+
return false;
|
|
85
|
+
return normalized === "1" || normalized === "true" || normalized === "yes";
|
|
86
|
+
};
|
|
87
|
+
const disableRaw = dntShim.Deno.env.get(CODEX_DISABLE_MCP_ENV);
|
|
88
|
+
if (disableRaw && parseTruthy(disableRaw))
|
|
89
|
+
return false;
|
|
90
|
+
const enableRaw = dntShim.Deno.env.get(CODEX_MCP_ENV);
|
|
91
|
+
if (!enableRaw)
|
|
92
|
+
return true;
|
|
93
|
+
const normalized = enableRaw.trim().toLowerCase();
|
|
94
|
+
return normalized === "1" || normalized === "true" || normalized === "yes";
|
|
95
|
+
}
|
|
96
|
+
function tomlString(value) {
|
|
97
|
+
return `"${value.replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`;
|
|
98
|
+
}
|
|
99
|
+
function tomlStringArray(values) {
|
|
100
|
+
return `[${values.map(tomlString).join(",")}]`;
|
|
101
|
+
}
|
|
102
|
+
function codexConfigArgs(input) {
|
|
103
|
+
const args = [];
|
|
104
|
+
const params = input.params ?? {};
|
|
105
|
+
const reasoning = asRecord(params.reasoning);
|
|
106
|
+
const effort = typeof reasoning.effort === "string"
|
|
107
|
+
? assertEnumForCallTime({
|
|
108
|
+
value: reasoning.effort,
|
|
109
|
+
allowed: REASONING_EFFORT_VALUES,
|
|
110
|
+
field: "reasoning.effort",
|
|
111
|
+
})
|
|
112
|
+
: dntShim.Deno.env.get(CODEX_REASONING_EFFORT_ENV);
|
|
113
|
+
if (typeof effort === "string" && effort.trim()) {
|
|
114
|
+
args.push("-c", `model_reasoning_effort=${tomlString(effort.trim())}`);
|
|
115
|
+
}
|
|
116
|
+
const summary = typeof reasoning.summary === "string"
|
|
117
|
+
? assertEnumForCallTime({
|
|
118
|
+
value: reasoning.summary,
|
|
119
|
+
allowed: REASONING_SUMMARY_VALUES,
|
|
120
|
+
field: "reasoning.summary",
|
|
121
|
+
})
|
|
122
|
+
: dntShim.Deno.env.get(CODEX_REASONING_SUMMARY_ENV);
|
|
123
|
+
if (typeof summary === "string" && summary.trim()) {
|
|
124
|
+
args.push("-c", `model_reasoning_summary=${tomlString(summary.trim())}`);
|
|
125
|
+
}
|
|
126
|
+
const verbosity = typeof params.verbosity === "string"
|
|
127
|
+
? assertEnumForCallTime({
|
|
128
|
+
value: params.verbosity,
|
|
129
|
+
allowed: VERBOSITY_VALUES,
|
|
130
|
+
field: "verbosity",
|
|
131
|
+
})
|
|
132
|
+
: dntShim.Deno.env.get(CODEX_VERBOSITY_ENV);
|
|
133
|
+
if (typeof verbosity === "string" && verbosity.trim()) {
|
|
134
|
+
args.push("-c", `model_verbosity=${tomlString(verbosity.trim())}`);
|
|
135
|
+
}
|
|
136
|
+
if (shouldEnableMcpBridge()) {
|
|
137
|
+
args.push("-c", `mcp_servers.gambit.command=${tomlString("deno")}`);
|
|
138
|
+
args.push("-c", `mcp_servers.gambit.args=${tomlStringArray(["run", "-A", MCP_SERVER_PATH])}`);
|
|
139
|
+
args.push("-c", `mcp_servers.gambit.cwd=${tomlString(input.cwd)}`);
|
|
140
|
+
args.push("-c", `mcp_servers.gambit.env.GAMBIT_BOT_ROOT=${tomlString(input.cwd)}`);
|
|
141
|
+
const rootDeckPath = input.deckPath?.trim();
|
|
142
|
+
if (rootDeckPath) {
|
|
143
|
+
args.push("-c", `mcp_servers.gambit.env.${MCP_ROOT_DECK_PATH_ENV}=${tomlString(rootDeckPath)}`);
|
|
144
|
+
}
|
|
145
|
+
args.push("-c", "mcp_servers.gambit.enabled=true");
|
|
146
|
+
args.push("-c", "mcp_servers.gambit.startup_timeout_sec=30");
|
|
147
|
+
args.push("-c", "mcp_servers.gambit.tool_timeout_sec=30");
|
|
148
|
+
}
|
|
149
|
+
return args;
|
|
150
|
+
}
|
|
151
|
+
function normalizeCodexModel(model) {
|
|
152
|
+
const trimmed = model.trim();
|
|
153
|
+
if (!trimmed)
|
|
154
|
+
return "";
|
|
155
|
+
if (trimmed === "codex-cli")
|
|
156
|
+
return "default";
|
|
157
|
+
if (trimmed === "codex" || trimmed.startsWith("codex/")) {
|
|
158
|
+
throw new Error('Legacy Codex model prefix "codex" is no longer supported. Use "codex-cli/default" or "codex-cli/<model>".');
|
|
159
|
+
}
|
|
160
|
+
if (trimmed.startsWith(exports.CODEX_PREFIX)) {
|
|
161
|
+
const stripped = trimmed.slice(exports.CODEX_PREFIX.length).trim();
|
|
162
|
+
if (!stripped) {
|
|
163
|
+
throw new Error('Codex model prefix requires a model segment. Use "codex-cli/default" or "codex-cli/<model>".');
|
|
164
|
+
}
|
|
165
|
+
return stripped;
|
|
166
|
+
}
|
|
167
|
+
return trimmed;
|
|
168
|
+
}
|
|
169
|
+
function assertEnumForCallTime(input) {
|
|
170
|
+
const normalized = input.value.trim().toLowerCase();
|
|
171
|
+
if (!normalized)
|
|
172
|
+
return normalized;
|
|
173
|
+
if (input.allowed.has(normalized))
|
|
174
|
+
return normalized;
|
|
175
|
+
const allowed = Array.from(input.allowed).join(", ");
|
|
176
|
+
throw new Error(`Invalid Codex call-time ${input.field}: "${input.value}". Allowed values: ${allowed}.`);
|
|
177
|
+
}
|
|
178
|
+
function safeJsonObject(text) {
|
|
179
|
+
try {
|
|
180
|
+
const parsed = JSON.parse(text);
|
|
181
|
+
if (parsed && typeof parsed === "object") {
|
|
182
|
+
return parsed;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
// ignore parse failure
|
|
187
|
+
}
|
|
188
|
+
return {};
|
|
189
|
+
}
|
|
190
|
+
function parseJsonValue(text) {
|
|
191
|
+
try {
|
|
192
|
+
return JSON.parse(text);
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
return text;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function asRecord(value) {
|
|
199
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
200
|
+
return value;
|
|
201
|
+
}
|
|
202
|
+
return {};
|
|
203
|
+
}
|
|
204
|
+
function emitCodexToolEvents(input) {
|
|
205
|
+
const payloadType = typeof input.event.type === "string"
|
|
206
|
+
? input.event.type
|
|
207
|
+
: "";
|
|
208
|
+
if (!payloadType.startsWith("item."))
|
|
209
|
+
return;
|
|
210
|
+
const item = input.event.item;
|
|
211
|
+
if (!item || typeof item !== "object" || Array.isArray(item))
|
|
212
|
+
return;
|
|
213
|
+
const record = item;
|
|
214
|
+
const itemType = typeof record.type === "string" ? record.type : "";
|
|
215
|
+
const callId = typeof record.id === "string"
|
|
216
|
+
? record.id
|
|
217
|
+
: typeof record.call_id === "string"
|
|
218
|
+
? record.call_id
|
|
219
|
+
: "";
|
|
220
|
+
if (!callId)
|
|
221
|
+
return;
|
|
222
|
+
if (itemType === "reasoning" || itemType === "agent_message")
|
|
223
|
+
return;
|
|
224
|
+
const name = typeof record.tool === "string"
|
|
225
|
+
? record.tool
|
|
226
|
+
: typeof record.name === "string"
|
|
227
|
+
? record.name
|
|
228
|
+
: input.toolNames.get(callId) ?? itemType;
|
|
229
|
+
const normalizedArgs = (() => {
|
|
230
|
+
if (itemType === "command_execution") {
|
|
231
|
+
return { command: record.command ?? "" };
|
|
232
|
+
}
|
|
233
|
+
if (itemType === "file_change") {
|
|
234
|
+
return { changes: record.changes ?? [] };
|
|
235
|
+
}
|
|
236
|
+
const rawArgs = record.arguments;
|
|
237
|
+
return typeof rawArgs === "string"
|
|
238
|
+
? parseJsonValue(rawArgs)
|
|
239
|
+
: rawArgs ?? {};
|
|
240
|
+
})();
|
|
241
|
+
if (!input.emittedCalls.has(callId)) {
|
|
242
|
+
input.emittedCalls.add(callId);
|
|
243
|
+
input.toolNames.set(callId, name);
|
|
244
|
+
input.emit({
|
|
245
|
+
type: "tool.call",
|
|
246
|
+
actionCallId: callId,
|
|
247
|
+
name,
|
|
248
|
+
args: normalizedArgs,
|
|
249
|
+
toolKind: "mcp_bridge",
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
if (input.emittedResults.has(callId))
|
|
253
|
+
return;
|
|
254
|
+
const resolvedName = name ?? input.toolNames.get(callId) ?? itemType;
|
|
255
|
+
if (!resolvedName)
|
|
256
|
+
return;
|
|
257
|
+
const isTerminal = payloadType === "item.completed" ||
|
|
258
|
+
payloadType === "item.done";
|
|
259
|
+
if (!isTerminal)
|
|
260
|
+
return;
|
|
261
|
+
input.emittedResults.add(callId);
|
|
262
|
+
const result = (() => {
|
|
263
|
+
if (itemType === "mcp_tool_call") {
|
|
264
|
+
return {
|
|
265
|
+
server: record.server ?? "",
|
|
266
|
+
status: record.status ?? "",
|
|
267
|
+
result: record.result ?? null,
|
|
268
|
+
error: record.error ?? null,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
if (itemType === "command_execution") {
|
|
272
|
+
return {
|
|
273
|
+
command: record.command ?? "",
|
|
274
|
+
status: record.status ?? "",
|
|
275
|
+
output: record.aggregated_output ?? "",
|
|
276
|
+
exit_code: record.exit_code ?? null,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
if (itemType === "file_change") {
|
|
280
|
+
return {
|
|
281
|
+
status: record.status ?? "",
|
|
282
|
+
changes: record.changes ?? [],
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
return record ?? null;
|
|
286
|
+
})();
|
|
287
|
+
input.emit({
|
|
288
|
+
type: "tool.result",
|
|
289
|
+
actionCallId: callId,
|
|
290
|
+
name: resolvedName,
|
|
291
|
+
result,
|
|
292
|
+
toolKind: "mcp_bridge",
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
function extractTextParts(value) {
|
|
296
|
+
if (typeof value === "string")
|
|
297
|
+
return [value];
|
|
298
|
+
if (!Array.isArray(value))
|
|
299
|
+
return [];
|
|
300
|
+
const parts = [];
|
|
301
|
+
for (const entry of value) {
|
|
302
|
+
if (!entry || typeof entry !== "object")
|
|
303
|
+
continue;
|
|
304
|
+
const record = entry;
|
|
305
|
+
if (typeof record.text === "string")
|
|
306
|
+
parts.push(record.text);
|
|
307
|
+
}
|
|
308
|
+
return parts;
|
|
309
|
+
}
|
|
310
|
+
function emitCodexReasoningEvents(input) {
|
|
311
|
+
const payloadType = typeof input.event.type === "string"
|
|
312
|
+
? input.event.type
|
|
313
|
+
: "";
|
|
314
|
+
if (!payloadType.startsWith("item."))
|
|
315
|
+
return;
|
|
316
|
+
const item = input.event.item;
|
|
317
|
+
if (!item || typeof item !== "object" || Array.isArray(item))
|
|
318
|
+
return;
|
|
319
|
+
const record = item;
|
|
320
|
+
if (record.type !== "reasoning")
|
|
321
|
+
return;
|
|
322
|
+
const itemId = typeof record.id === "string" ? record.id : "reasoning";
|
|
323
|
+
const outputIndex = 0;
|
|
324
|
+
const contentIndex = 0;
|
|
325
|
+
if (payloadType === "item.delta") {
|
|
326
|
+
const deltaText = typeof record.text === "string"
|
|
327
|
+
? record.text
|
|
328
|
+
: extractTextParts(record.content).join("");
|
|
329
|
+
if (deltaText) {
|
|
330
|
+
input.emit({
|
|
331
|
+
type: "response.reasoning.delta",
|
|
332
|
+
output_index: outputIndex,
|
|
333
|
+
item_id: itemId,
|
|
334
|
+
content_index: contentIndex,
|
|
335
|
+
delta: deltaText,
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
if (payloadType === "item.completed" || payloadType === "item.done") {
|
|
340
|
+
const doneText = typeof record.text === "string"
|
|
341
|
+
? record.text
|
|
342
|
+
: extractTextParts(record.content).join("");
|
|
343
|
+
input.emit({
|
|
344
|
+
type: "response.reasoning.done",
|
|
345
|
+
output_index: outputIndex,
|
|
346
|
+
item_id: itemId,
|
|
347
|
+
content_index: contentIndex,
|
|
348
|
+
text: doneText,
|
|
349
|
+
});
|
|
350
|
+
const summaryParts = Array.isArray(record.summary) ? record.summary : [];
|
|
351
|
+
summaryParts.forEach((part, idx) => {
|
|
352
|
+
if (!part || typeof part !== "object")
|
|
353
|
+
return;
|
|
354
|
+
const partRecord = part;
|
|
355
|
+
const text = typeof partRecord.text === "string" ? partRecord.text : "";
|
|
356
|
+
input.emit({
|
|
357
|
+
type: "response.reasoning_summary_part.added",
|
|
358
|
+
output_index: outputIndex,
|
|
359
|
+
item_id: itemId,
|
|
360
|
+
summary_index: idx,
|
|
361
|
+
part: {
|
|
362
|
+
type: "summary_text",
|
|
363
|
+
text,
|
|
364
|
+
},
|
|
365
|
+
});
|
|
366
|
+
input.emit({
|
|
367
|
+
type: "response.reasoning_summary_part.done",
|
|
368
|
+
output_index: outputIndex,
|
|
369
|
+
item_id: itemId,
|
|
370
|
+
summary_index: idx,
|
|
371
|
+
part: {
|
|
372
|
+
type: "summary_text",
|
|
373
|
+
text,
|
|
374
|
+
},
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
function responseItemsToChatMessages(items, instructions) {
|
|
380
|
+
const messages = [];
|
|
381
|
+
if (typeof instructions === "string" && instructions.trim().length > 0) {
|
|
382
|
+
messages.push({ role: "system", content: instructions });
|
|
383
|
+
}
|
|
384
|
+
for (const item of items) {
|
|
385
|
+
if (item.type === "message") {
|
|
386
|
+
const content = item.content.map((part) => part.text).join("");
|
|
387
|
+
messages.push({ role: item.role, content });
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
if (item.type === "function_call") {
|
|
391
|
+
messages.push({
|
|
392
|
+
role: "assistant",
|
|
393
|
+
content: null,
|
|
394
|
+
tool_calls: [{
|
|
395
|
+
id: item.call_id,
|
|
396
|
+
type: "function",
|
|
397
|
+
function: { name: item.name, arguments: item.arguments },
|
|
398
|
+
}],
|
|
399
|
+
});
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
if (item.type === "function_call_output") {
|
|
403
|
+
messages.push({
|
|
404
|
+
role: "tool",
|
|
405
|
+
content: item.output,
|
|
406
|
+
tool_call_id: item.call_id,
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
return messages;
|
|
411
|
+
}
|
|
412
|
+
function responseItemsFromAssistantMessage(message) {
|
|
413
|
+
const output = [];
|
|
414
|
+
if (typeof message.content === "string" && message.content.length > 0) {
|
|
415
|
+
output.push({
|
|
416
|
+
type: "message",
|
|
417
|
+
role: "assistant",
|
|
418
|
+
content: [{ type: "output_text", text: message.content }],
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
if (message.tool_calls) {
|
|
422
|
+
for (const call of message.tool_calls) {
|
|
423
|
+
output.push({
|
|
424
|
+
type: "function_call",
|
|
425
|
+
call_id: call.id,
|
|
426
|
+
name: call.function.name,
|
|
427
|
+
arguments: call.function.arguments,
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
return output;
|
|
432
|
+
}
|
|
433
|
+
function stringContent(content) {
|
|
434
|
+
if (typeof content === "string")
|
|
435
|
+
return content.trim();
|
|
436
|
+
return "";
|
|
437
|
+
}
|
|
438
|
+
function renderMessagesForPrompt(messages) {
|
|
439
|
+
return messages
|
|
440
|
+
.map((message) => {
|
|
441
|
+
const content = stringContent(message.content);
|
|
442
|
+
if (!content)
|
|
443
|
+
return "";
|
|
444
|
+
return `${message.role.toUpperCase()}:\n${content}`;
|
|
445
|
+
})
|
|
446
|
+
.filter(Boolean)
|
|
447
|
+
.join("\n\n");
|
|
448
|
+
}
|
|
449
|
+
function latestUserPrompt(messages) {
|
|
450
|
+
for (let idx = messages.length - 1; idx >= 0; idx -= 1) {
|
|
451
|
+
const msg = messages[idx];
|
|
452
|
+
if (msg.role !== "user")
|
|
453
|
+
continue;
|
|
454
|
+
const content = stringContent(msg.content);
|
|
455
|
+
if (content)
|
|
456
|
+
return content;
|
|
457
|
+
}
|
|
458
|
+
return "";
|
|
459
|
+
}
|
|
460
|
+
function promptForCodexTurn(input) {
|
|
461
|
+
if (input.priorThreadId) {
|
|
462
|
+
// Thread resume should be incremental: only send the newest user turn.
|
|
463
|
+
return latestUserPrompt(input.messages);
|
|
464
|
+
}
|
|
465
|
+
return renderMessagesForPrompt(input.messages);
|
|
466
|
+
}
|
|
467
|
+
function parseNumber(input) {
|
|
468
|
+
return typeof input === "number" && Number.isFinite(input) ? input : 0;
|
|
469
|
+
}
|
|
470
|
+
function parseCodexStdout(stdout) {
|
|
471
|
+
let threadId;
|
|
472
|
+
let assistantText = "";
|
|
473
|
+
let usage;
|
|
474
|
+
for (const line of stdout.split(/\r?\n/)) {
|
|
475
|
+
const trimmed = line.trim();
|
|
476
|
+
if (!trimmed.startsWith("{"))
|
|
477
|
+
continue;
|
|
478
|
+
let parsed = null;
|
|
479
|
+
try {
|
|
480
|
+
parsed = JSON.parse(trimmed);
|
|
481
|
+
}
|
|
482
|
+
catch {
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
if (!parsed || typeof parsed !== "object")
|
|
486
|
+
continue;
|
|
487
|
+
if (parsed.type === "thread.started") {
|
|
488
|
+
if (typeof parsed.thread_id === "string" && parsed.thread_id.trim()) {
|
|
489
|
+
threadId = parsed.thread_id.trim();
|
|
490
|
+
}
|
|
491
|
+
continue;
|
|
492
|
+
}
|
|
493
|
+
if (parsed.type === "item.completed") {
|
|
494
|
+
const item = parsed.item;
|
|
495
|
+
if (!item || typeof item !== "object")
|
|
496
|
+
continue;
|
|
497
|
+
if (item.type !== "agent_message")
|
|
498
|
+
continue;
|
|
499
|
+
if (typeof item.text !== "string")
|
|
500
|
+
continue;
|
|
501
|
+
const content = item.text.trim();
|
|
502
|
+
if (content)
|
|
503
|
+
assistantText = content;
|
|
504
|
+
continue;
|
|
505
|
+
}
|
|
506
|
+
if (parsed.type === "turn.completed") {
|
|
507
|
+
const rawUsage = parsed.usage;
|
|
508
|
+
if (!rawUsage || typeof rawUsage !== "object")
|
|
509
|
+
continue;
|
|
510
|
+
usage = {
|
|
511
|
+
promptTokens: parseNumber(rawUsage.input_tokens),
|
|
512
|
+
completionTokens: parseNumber(rawUsage.output_tokens),
|
|
513
|
+
totalTokens: parseNumber(rawUsage.total_tokens),
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
return { threadId, assistantText, usage };
|
|
518
|
+
}
|
|
519
|
+
function buildUpdatedState(input) {
|
|
520
|
+
const priorState = input.priorState;
|
|
521
|
+
const baseMessages = input.messages.map((message) => ({ ...message }));
|
|
522
|
+
baseMessages.push({ role: "assistant", content: input.assistantText });
|
|
523
|
+
const meta = { ...(priorState?.meta ?? {}) };
|
|
524
|
+
if (input.threadId) {
|
|
525
|
+
meta[CODEX_THREAD_META_KEY] = input.threadId;
|
|
526
|
+
}
|
|
527
|
+
return {
|
|
528
|
+
runId: priorState?.runId ?? crypto.randomUUID(),
|
|
529
|
+
messages: baseMessages,
|
|
530
|
+
format: priorState?.format ?? "chat",
|
|
531
|
+
items: priorState?.items,
|
|
532
|
+
messageRefs: priorState?.messageRefs,
|
|
533
|
+
feedback: priorState?.feedback,
|
|
534
|
+
traces: priorState?.traces,
|
|
535
|
+
meta,
|
|
536
|
+
notes: priorState?.notes,
|
|
537
|
+
conversationScore: priorState?.conversationScore,
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
function defaultCommandRunner(input) {
|
|
541
|
+
const codexBin = dntShim.Deno.env.get(CODEX_BIN_ENV)?.trim() || "codex";
|
|
542
|
+
const child = new dntShim.Deno.Command(codexBin, {
|
|
543
|
+
args: input.args,
|
|
544
|
+
cwd: input.cwd,
|
|
545
|
+
stdout: "piped",
|
|
546
|
+
stderr: "piped",
|
|
547
|
+
}).spawn();
|
|
548
|
+
const abort = () => {
|
|
549
|
+
try {
|
|
550
|
+
child.kill("SIGTERM");
|
|
551
|
+
}
|
|
552
|
+
catch {
|
|
553
|
+
// ignore
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
if (input.signal?.aborted) {
|
|
557
|
+
abort();
|
|
558
|
+
}
|
|
559
|
+
else if (input.signal) {
|
|
560
|
+
input.signal.addEventListener("abort", abort, { once: true });
|
|
561
|
+
}
|
|
562
|
+
const readStream = async (stream, onLine) => {
|
|
563
|
+
if (!stream)
|
|
564
|
+
return new Uint8Array();
|
|
565
|
+
const reader = stream.getReader();
|
|
566
|
+
const decoder = new TextDecoder();
|
|
567
|
+
const chunks = [];
|
|
568
|
+
let buffered = "";
|
|
569
|
+
while (true) {
|
|
570
|
+
const { value, done } = await reader.read();
|
|
571
|
+
if (done)
|
|
572
|
+
break;
|
|
573
|
+
if (value) {
|
|
574
|
+
chunks.push(value);
|
|
575
|
+
if (onLine) {
|
|
576
|
+
buffered += decoder.decode(value, { stream: true });
|
|
577
|
+
const parts = buffered.split(/\r?\n/);
|
|
578
|
+
buffered = parts.pop() ?? "";
|
|
579
|
+
for (const line of parts)
|
|
580
|
+
onLine(line);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
if (onLine && buffered.trim())
|
|
585
|
+
onLine(buffered);
|
|
586
|
+
const total = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
587
|
+
const out = new Uint8Array(total);
|
|
588
|
+
let offset = 0;
|
|
589
|
+
for (const chunk of chunks) {
|
|
590
|
+
out.set(chunk, offset);
|
|
591
|
+
offset += chunk.length;
|
|
592
|
+
}
|
|
593
|
+
return out;
|
|
594
|
+
};
|
|
595
|
+
return Promise.all([
|
|
596
|
+
child.status,
|
|
597
|
+
readStream(child.stdout, input.onStdoutLine),
|
|
598
|
+
readStream(child.stderr),
|
|
599
|
+
]).then(([status, stdout, stderr]) => ({
|
|
600
|
+
success: status.success,
|
|
601
|
+
code: status.code,
|
|
602
|
+
stdout,
|
|
603
|
+
stderr,
|
|
604
|
+
})).finally(() => {
|
|
605
|
+
if (input.signal) {
|
|
606
|
+
input.signal.removeEventListener("abort", abort);
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
function buildCodexStreamHandler(input) {
|
|
611
|
+
const toolNames = new Map();
|
|
612
|
+
const emittedCalls = new Set();
|
|
613
|
+
const emittedResults = new Set();
|
|
614
|
+
return (event) => {
|
|
615
|
+
emitCodexReasoningEvents({
|
|
616
|
+
event,
|
|
617
|
+
emit: input.emitTool,
|
|
618
|
+
});
|
|
619
|
+
emitCodexToolEvents({
|
|
620
|
+
event,
|
|
621
|
+
emit: input.emitTool,
|
|
622
|
+
toolNames,
|
|
623
|
+
emittedCalls,
|
|
624
|
+
emittedResults,
|
|
625
|
+
});
|
|
626
|
+
input.emitRaw(event);
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
function createCodexProvider(opts) {
|
|
630
|
+
const runCommand = opts?.runCommand ?? defaultCommandRunner;
|
|
631
|
+
const runChat = async (input) => {
|
|
632
|
+
if (input.signal?.aborted) {
|
|
633
|
+
throw new DOMException("Run canceled", "AbortError");
|
|
634
|
+
}
|
|
635
|
+
const streamHandler = (input.onStreamEvent || input.onTraceEvent)
|
|
636
|
+
? buildCodexStreamHandler({
|
|
637
|
+
emitRaw: (event) => input.onStreamEvent?.(event),
|
|
638
|
+
emitTool: (event) => {
|
|
639
|
+
input.onStreamEvent?.(event);
|
|
640
|
+
input.onTraceEvent?.(event);
|
|
641
|
+
},
|
|
642
|
+
})
|
|
643
|
+
: undefined;
|
|
644
|
+
const priorThreadIdRaw = input.state?.meta?.[CODEX_THREAD_META_KEY];
|
|
645
|
+
const priorThreadId = typeof priorThreadIdRaw === "string" &&
|
|
646
|
+
priorThreadIdRaw.trim().length > 0
|
|
647
|
+
? priorThreadIdRaw.trim()
|
|
648
|
+
: undefined;
|
|
649
|
+
const model = normalizeCodexModel(input.model);
|
|
650
|
+
const prompt = promptForCodexTurn({
|
|
651
|
+
messages: input.messages,
|
|
652
|
+
priorThreadId,
|
|
653
|
+
});
|
|
654
|
+
const cwd = runCwd();
|
|
655
|
+
const args = priorThreadId
|
|
656
|
+
? [
|
|
657
|
+
"exec",
|
|
658
|
+
"resume",
|
|
659
|
+
"--skip-git-repo-check",
|
|
660
|
+
"--json",
|
|
661
|
+
]
|
|
662
|
+
: ["exec", "--skip-git-repo-check", "--json"];
|
|
663
|
+
args.push(...codexConfigArgs({
|
|
664
|
+
cwd,
|
|
665
|
+
deckPath: input.deckPath,
|
|
666
|
+
params: input.params,
|
|
667
|
+
}));
|
|
668
|
+
if (model && model !== "default") {
|
|
669
|
+
args.push("-m", model);
|
|
670
|
+
}
|
|
671
|
+
if (priorThreadId) {
|
|
672
|
+
args.push(priorThreadId);
|
|
673
|
+
}
|
|
674
|
+
args.push(prompt);
|
|
675
|
+
const handleStdoutLine = (line) => {
|
|
676
|
+
const trimmed = line.trim();
|
|
677
|
+
if (!trimmed.startsWith("{"))
|
|
678
|
+
return;
|
|
679
|
+
try {
|
|
680
|
+
const parsed = JSON.parse(trimmed);
|
|
681
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed) &&
|
|
682
|
+
streamHandler) {
|
|
683
|
+
streamHandler(parsed);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
catch {
|
|
687
|
+
// ignore malformed/non-json lines
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
const out = await runCommand({
|
|
691
|
+
args,
|
|
692
|
+
cwd,
|
|
693
|
+
signal: input.signal,
|
|
694
|
+
onStdoutLine: streamHandler ? handleStdoutLine : undefined,
|
|
695
|
+
});
|
|
696
|
+
if (input.signal?.aborted) {
|
|
697
|
+
throw new DOMException("Run canceled", "AbortError");
|
|
698
|
+
}
|
|
699
|
+
const stdout = new TextDecoder().decode(out.stdout);
|
|
700
|
+
const stderr = new TextDecoder().decode(out.stderr);
|
|
701
|
+
if (!out.success) {
|
|
702
|
+
throw new Error(`codex exec failed (exit ${out.code}): ${stderr.trim() || stdout.trim()}`);
|
|
703
|
+
}
|
|
704
|
+
const parsed = parseCodexStdout(stdout);
|
|
705
|
+
const threadId = parsed.threadId ?? priorThreadId;
|
|
706
|
+
if (input.stream && input.onStreamText && parsed.assistantText) {
|
|
707
|
+
input.onStreamText(parsed.assistantText);
|
|
708
|
+
}
|
|
709
|
+
const updatedState = buildUpdatedState({
|
|
710
|
+
priorState: input.state,
|
|
711
|
+
messages: input.messages,
|
|
712
|
+
assistantText: parsed.assistantText,
|
|
713
|
+
threadId,
|
|
714
|
+
});
|
|
715
|
+
return {
|
|
716
|
+
message: { role: "assistant", content: parsed.assistantText },
|
|
717
|
+
finishReason: "stop",
|
|
718
|
+
updatedState,
|
|
719
|
+
usage: parsed.usage,
|
|
720
|
+
};
|
|
721
|
+
};
|
|
722
|
+
return {
|
|
723
|
+
async responses(input) {
|
|
724
|
+
const streamHandler = input.onStreamEvent
|
|
725
|
+
? buildCodexStreamHandler({
|
|
726
|
+
emitRaw: (event) => {
|
|
727
|
+
input.onStreamEvent?.({
|
|
728
|
+
type: "codex.event",
|
|
729
|
+
payload: event,
|
|
730
|
+
});
|
|
731
|
+
},
|
|
732
|
+
emitTool: (event) => {
|
|
733
|
+
input.onStreamEvent?.(event);
|
|
734
|
+
},
|
|
735
|
+
})
|
|
736
|
+
: undefined;
|
|
737
|
+
const result = await runChat({
|
|
738
|
+
model: input.request.model,
|
|
739
|
+
messages: responseItemsToChatMessages(input.request.input, input.request.instructions),
|
|
740
|
+
stream: input.request.stream,
|
|
741
|
+
params: input.request.params,
|
|
742
|
+
state: input.state,
|
|
743
|
+
deckPath: input.deckPath,
|
|
744
|
+
signal: input.signal,
|
|
745
|
+
onStreamEvent: streamHandler,
|
|
746
|
+
});
|
|
747
|
+
const output = responseItemsFromAssistantMessage(result.message);
|
|
748
|
+
const responseId = `codex-${crypto.randomUUID()}`;
|
|
749
|
+
const createdAt = Math.floor(Date.now() / 1000);
|
|
750
|
+
if (input.request.stream) {
|
|
751
|
+
input.onStreamEvent?.({
|
|
752
|
+
type: "response.created",
|
|
753
|
+
sequence_number: 0,
|
|
754
|
+
response: {
|
|
755
|
+
id: responseId,
|
|
756
|
+
object: "response",
|
|
757
|
+
model: input.request.model,
|
|
758
|
+
created_at: createdAt,
|
|
759
|
+
created: createdAt,
|
|
760
|
+
status: "in_progress",
|
|
761
|
+
output: [],
|
|
762
|
+
error: null,
|
|
763
|
+
},
|
|
764
|
+
});
|
|
765
|
+
if (typeof result.message.content === "string" && result.message.content) {
|
|
766
|
+
input.onStreamEvent?.({
|
|
767
|
+
type: "response.output_text.delta",
|
|
768
|
+
sequence_number: 1,
|
|
769
|
+
output_index: 0,
|
|
770
|
+
delta: result.message.content,
|
|
771
|
+
});
|
|
772
|
+
input.onStreamEvent?.({
|
|
773
|
+
type: "response.output_text.done",
|
|
774
|
+
sequence_number: 2,
|
|
775
|
+
output_index: 0,
|
|
776
|
+
text: result.message.content,
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
output.forEach((item, index) => {
|
|
780
|
+
input.onStreamEvent?.({
|
|
781
|
+
type: "response.output_item.added",
|
|
782
|
+
sequence_number: 3 + (index * 2),
|
|
783
|
+
output_index: index,
|
|
784
|
+
item,
|
|
785
|
+
});
|
|
786
|
+
input.onStreamEvent?.({
|
|
787
|
+
type: "response.output_item.done",
|
|
788
|
+
sequence_number: 4 + (index * 2),
|
|
789
|
+
output_index: index,
|
|
790
|
+
item,
|
|
791
|
+
});
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
const response = {
|
|
795
|
+
id: responseId,
|
|
796
|
+
object: "response",
|
|
797
|
+
model: input.request.model,
|
|
798
|
+
created_at: createdAt,
|
|
799
|
+
created: createdAt,
|
|
800
|
+
status: "completed",
|
|
801
|
+
output,
|
|
802
|
+
usage: result.usage,
|
|
803
|
+
error: null,
|
|
804
|
+
updatedState: result.updatedState,
|
|
805
|
+
};
|
|
806
|
+
if (input.request.stream) {
|
|
807
|
+
input.onStreamEvent?.({
|
|
808
|
+
type: "response.completed",
|
|
809
|
+
sequence_number: 1000,
|
|
810
|
+
response,
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
return response;
|
|
814
|
+
},
|
|
815
|
+
chat: runChat,
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
function parseCodexArgsForTest(input) {
|
|
819
|
+
const priorThreadIdRaw = input.state?.meta?.[CODEX_THREAD_META_KEY];
|
|
820
|
+
const priorThreadId = typeof priorThreadIdRaw === "string" &&
|
|
821
|
+
priorThreadIdRaw.trim().length > 0
|
|
822
|
+
? priorThreadIdRaw.trim()
|
|
823
|
+
: undefined;
|
|
824
|
+
const model = normalizeCodexModel(input.model);
|
|
825
|
+
const prompt = promptForCodexTurn({
|
|
826
|
+
messages: input.messages,
|
|
827
|
+
priorThreadId,
|
|
828
|
+
});
|
|
829
|
+
const args = priorThreadId
|
|
830
|
+
? ["exec", "resume", "--skip-git-repo-check", "--json"]
|
|
831
|
+
: ["exec", "--skip-git-repo-check", "--json"];
|
|
832
|
+
args.push(...codexConfigArgs({
|
|
833
|
+
cwd: input.cwd ?? runCwd(),
|
|
834
|
+
deckPath: input.deckPath,
|
|
835
|
+
params: input.params,
|
|
836
|
+
}));
|
|
837
|
+
if (model && model !== "default") {
|
|
838
|
+
args.push("-m", model);
|
|
839
|
+
}
|
|
840
|
+
if (priorThreadId)
|
|
841
|
+
args.push(priorThreadId);
|
|
842
|
+
args.push(prompt);
|
|
843
|
+
return args;
|
|
844
|
+
}
|
|
845
|
+
function parseCodexStdoutForTest(stdout) {
|
|
846
|
+
return parseCodexStdout(stdout);
|
|
847
|
+
}
|
|
848
|
+
function safeJsonForTest(text) {
|
|
849
|
+
return safeJsonObject(text);
|
|
850
|
+
}
|