modelglot 7.0.0__py3-none-any.whl
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.
- modelglot/__init__.py +1 -0
- modelglot/api/__init__.py +1 -0
- modelglot/api/admin_cache.py +50 -0
- modelglot/api/admin_routes.py +826 -0
- modelglot/api/admin_security.py +67 -0
- modelglot/api/admin_static/admin.css +1325 -0
- modelglot/api/admin_static/admin.js +2715 -0
- modelglot/api/admin_static/api_key_editor.js +216 -0
- modelglot/api/admin_static/code_sessions.css +109 -0
- modelglot/api/admin_static/code_sessions.js +1740 -0
- modelglot/api/admin_static/form_controls.js +15 -0
- modelglot/api/admin_static/index.html +447 -0
- modelglot/api/admin_static/model_combobox.js +274 -0
- modelglot/api/admin_static/model_picker_details.js +406 -0
- modelglot/api/admin_static/providers/LICENSE-llamacpp.txt +21 -0
- modelglot/api/admin_static/providers/LICENSE-lobe-icons.txt +21 -0
- modelglot/api/admin_static/providers/SOURCES.md +62 -0
- modelglot/api/admin_static/providers/agnesai.svg +1 -0
- modelglot/api/admin_static/providers/alibabacloud-color.svg +1 -0
- modelglot/api/admin_static/providers/anthropic.svg +1 -0
- modelglot/api/admin_static/providers/atlascloud.svg +1 -0
- modelglot/api/admin_static/providers/azure-color.svg +1 -0
- modelglot/api/admin_static/providers/bedrock-color.svg +1 -0
- modelglot/api/admin_static/providers/cerebras-color.svg +1 -0
- modelglot/api/admin_static/providers/cheaperinference.svg +5 -0
- modelglot/api/admin_static/providers/chutes.png +0 -0
- modelglot/api/admin_static/providers/cline.svg +1 -0
- modelglot/api/admin_static/providers/cloudflare-color.svg +1 -0
- modelglot/api/admin_static/providers/cohere-color.svg +1 -0
- modelglot/api/admin_static/providers/deepinfra-color.svg +1 -0
- modelglot/api/admin_static/providers/deepseek-color.svg +1 -0
- modelglot/api/admin_static/providers/experiential.svg +9 -0
- modelglot/api/admin_static/providers/featherless-color.svg +1 -0
- modelglot/api/admin_static/providers/fireworks-color.svg +1 -0
- modelglot/api/admin_static/providers/gemini-color.svg +1 -0
- modelglot/api/admin_static/providers/githubcopilot.svg +1 -0
- modelglot/api/admin_static/providers/groq.svg +1 -0
- modelglot/api/admin_static/providers/huggingface-color.svg +1 -0
- modelglot/api/admin_static/providers/kilocode.svg +1 -0
- modelglot/api/admin_static/providers/kimi-color.svg +1 -0
- modelglot/api/admin_static/providers/lightning.png +0 -0
- modelglot/api/admin_static/providers/llamacpp.svg +77 -0
- modelglot/api/admin_static/providers/llm7.png +0 -0
- modelglot/api/admin_static/providers/lmstudio.svg +1 -0
- modelglot/api/admin_static/providers/minimax-color.svg +1 -0
- modelglot/api/admin_static/providers/mistral-color.svg +1 -0
- modelglot/api/admin_static/providers/nararoute.png +0 -0
- modelglot/api/admin_static/providers/nebius.svg +1 -0
- modelglot/api/admin_static/providers/novita-color.svg +1 -0
- modelglot/api/admin_static/providers/nvidia-color.svg +1 -0
- modelglot/api/admin_static/providers/ollama.svg +1 -0
- modelglot/api/admin_static/providers/openai.svg +1 -0
- modelglot/api/admin_static/providers/opencode.svg +1 -0
- modelglot/api/admin_static/providers/openrouter.svg +1 -0
- modelglot/api/admin_static/providers/opper.svg +3 -0
- modelglot/api/admin_static/providers/orcarouter.png +0 -0
- modelglot/api/admin_static/providers/poolside-color.svg +1 -0
- modelglot/api/admin_static/providers/qwen-color.svg +1 -0
- modelglot/api/admin_static/providers/sambanova-color.svg +1 -0
- modelglot/api/admin_static/providers/scaleway.svg +11 -0
- modelglot/api/admin_static/providers/siliconcloud-color.svg +1 -0
- modelglot/api/admin_static/providers/together-color.svg +1 -0
- modelglot/api/admin_static/providers/tokenrouter.png +0 -0
- modelglot/api/admin_static/providers/vercel.svg +1 -0
- modelglot/api/admin_static/providers/vertexai-color.svg +1 -0
- modelglot/api/admin_static/providers/wafer.png +0 -0
- modelglot/api/admin_static/providers/wandb.png +0 -0
- modelglot/api/admin_static/providers/xai.svg +1 -0
- modelglot/api/admin_static/providers/xkiro.png +0 -0
- modelglot/api/admin_static/providers/zai.svg +1 -0
- modelglot/api/admin_static/providers/zenmux.svg +1 -0
- modelglot/api/admin_static/session_layout.css +552 -0
- modelglot/api/admin_static/session_ui.js +211 -0
- modelglot/api/admin_static/token_optimization.css +398 -0
- modelglot/api/admin_static/token_optimization.js +439 -0
- modelglot/api/app.py +219 -0
- modelglot/api/classifier_projection.py +47 -0
- modelglot/api/code_sessions_routes.py +387 -0
- modelglot/api/dependencies.py +168 -0
- modelglot/api/detection.py +34 -0
- modelglot/api/generation_paths.py +23 -0
- modelglot/api/handlers/__init__.py +7 -0
- modelglot/api/handlers/chat.py +116 -0
- modelglot/api/handlers/classifier_response.py +32 -0
- modelglot/api/handlers/gemini.py +112 -0
- modelglot/api/handlers/messages.py +355 -0
- modelglot/api/handlers/responses.py +170 -0
- modelglot/api/handlers/token_count.py +97 -0
- modelglot/api/inline_system_turns.py +41 -0
- modelglot/api/markdown.py +73 -0
- modelglot/api/model_catalog.py +308 -0
- modelglot/api/ports.py +150 -0
- modelglot/api/request_errors.py +113 -0
- modelglot/api/request_ids.py +103 -0
- modelglot/api/request_lifetime.py +135 -0
- modelglot/api/request_outcomes.py +231 -0
- modelglot/api/response_streams.py +495 -0
- modelglot/api/routes.py +463 -0
- modelglot/api/stream_delivery.py +151 -0
- modelglot/api/stream_frames.py +42 -0
- modelglot/api/stream_publication.py +358 -0
- modelglot/api/usage_csv.py +106 -0
- modelglot/api/validation_log.py +46 -0
- modelglot/application/__init__.py +1 -0
- modelglot/application/code_sessions/__init__.py +33 -0
- modelglot/application/code_sessions/models.py +250 -0
- modelglot/application/code_sessions/ports.py +230 -0
- modelglot/application/code_sessions/service.py +1196 -0
- modelglot/application/code_sessions/state.py +692 -0
- modelglot/application/connected_accounts.py +96 -0
- modelglot/application/errors.py +42 -0
- modelglot/application/execution.py +486 -0
- modelglot/application/model_catalog.py +204 -0
- modelglot/application/model_fallback/__init__.py +6 -0
- modelglot/application/model_fallback/decision.py +85 -0
- modelglot/application/model_fallback/runner.py +129 -0
- modelglot/application/model_fallback/traces.py +85 -0
- modelglot/application/model_fallback/types.py +15 -0
- modelglot/application/model_metadata.py +29 -0
- modelglot/application/model_titles.py +154 -0
- modelglot/application/ports.py +216 -0
- modelglot/application/readiness.py +43 -0
- modelglot/application/reasoning.py +203 -0
- modelglot/application/response_collection.py +155 -0
- modelglot/application/routing.py +413 -0
- modelglot/application/session_events.py +140 -0
- modelglot/application/token_optimization.py +328 -0
- modelglot/application/usage_events.py +820 -0
- modelglot/application/web_tools/__init__.py +1 -0
- modelglot/application/web_tools/ports.py +35 -0
- modelglot/application/web_tools/request.py +483 -0
- modelglot/application/web_tools/service.py +626 -0
- modelglot/assets/app-icon.icns +0 -0
- modelglot/assets/app-icon.ico +0 -0
- modelglot/assets/app-icon.png +0 -0
- modelglot/assets/app-icon.svg +22 -0
- modelglot/assets/macos/modelglot-desktop-arm64 +0 -0
- modelglot/assets/macos/modelglot-desktop-x86_64 +0 -0
- modelglot/cli/__init__.py +5 -0
- modelglot/cli/clipboard.py +14 -0
- modelglot/cli/commands.py +463 -0
- modelglot/cli/desktop.py +170 -0
- modelglot/cli/desktop_assets.py +31 -0
- modelglot/cli/desktop_entrypoint.py +40 -0
- modelglot/cli/desktop_notifications.py +108 -0
- modelglot/cli/desktop_tray.py +523 -0
- modelglot/cli/doctor.py +49 -0
- modelglot/cli/entrypoints.py +35 -0
- modelglot/cli/launchers/__init__.py +1 -0
- modelglot/cli/launchers/agy.py +70 -0
- modelglot/cli/launchers/aider.py +53 -0
- modelglot/cli/launchers/aider_config.py +83 -0
- modelglot/cli/launchers/catalog_http.py +139 -0
- modelglot/cli/launchers/claude.py +34 -0
- modelglot/cli/launchers/cline.py +78 -0
- modelglot/cli/launchers/cline_config.py +123 -0
- modelglot/cli/launchers/codex.py +47 -0
- modelglot/cli/launchers/common.py +453 -0
- modelglot/cli/launchers/dsh.py +145 -0
- modelglot/cli/launchers/grok.py +117 -0
- modelglot/cli/launchers/hermes.py +87 -0
- modelglot/cli/launchers/hermes_config.py +136 -0
- modelglot/cli/launchers/muse.py +68 -0
- modelglot/cli/launchers/opencode.py +85 -0
- modelglot/cli/launchers/opencode_config.py +112 -0
- modelglot/cli/launchers/pi.py +70 -0
- modelglot/cli/launchers/pi_extension.ts +193 -0
- modelglot/cli/launchers/runner.py +152 -0
- modelglot/cli/local_http.py +12 -0
- modelglot/cli/macos_app.py +143 -0
- modelglot/cli/managed/__init__.py +6 -0
- modelglot/cli/managed/claude.py +225 -0
- modelglot/cli/managed/diagnostics.py +47 -0
- modelglot/cli/managed/manager.py +207 -0
- modelglot/cli/managed/session.py +298 -0
- modelglot/cli/process_registry.py +77 -0
- modelglot/cli/server_socket.py +71 -0
- modelglot/cli/uvicorn_server.py +97 -0
- modelglot/cli/windows_app_identity.py +340 -0
- modelglot/cli/windows_desktop_notifications.py +226 -0
- modelglot/config/__init__.py +10 -0
- modelglot/config/admin/__init__.py +1 -0
- modelglot/config/admin/credentials.py +137 -0
- modelglot/config/admin/custom_providers.py +102 -0
- modelglot/config/admin/manifest.py +670 -0
- modelglot/config/admin/persistence.py +306 -0
- modelglot/config/admin/provider_manifest.py +500 -0
- modelglot/config/admin/specs.py +78 -0
- modelglot/config/admin/state.py +18 -0
- modelglot/config/admin/status.py +116 -0
- modelglot/config/admin/validation.py +40 -0
- modelglot/config/admin/values.py +172 -0
- modelglot/config/api_keys.py +66 -0
- modelglot/config/constants.py +15 -0
- modelglot/config/custom_providers.py +137 -0
- modelglot/config/env_files.py +54 -0
- modelglot/config/env_migrations.py +518 -0
- modelglot/config/errors.py +9 -0
- modelglot/config/loader.py +204 -0
- modelglot/config/logging_config.py +139 -0
- modelglot/config/model_catalog_mapping.py +44 -0
- modelglot/config/model_catalog_metadata.py +41 -0
- modelglot/config/model_refs.py +213 -0
- modelglot/config/model_title_overrides.py +22 -0
- modelglot/config/paths.py +132 -0
- modelglot/config/provider_catalog.py +843 -0
- modelglot/config/provider_proxies.py +32 -0
- modelglot/config/reasoning.py +25 -0
- modelglot/config/server_urls.py +55 -0
- modelglot/config/settings.py +889 -0
- modelglot/core/__init__.py +15 -0
- modelglot/core/anthropic/__init__.py +98 -0
- modelglot/core/anthropic/content.py +43 -0
- modelglot/core/anthropic/conversion.py +906 -0
- modelglot/core/anthropic/errors.py +125 -0
- modelglot/core/anthropic/image_sources.py +77 -0
- modelglot/core/anthropic/models.py +215 -0
- modelglot/core/anthropic/native.py +168 -0
- modelglot/core/anthropic/native_stream.py +290 -0
- modelglot/core/anthropic/passthrough.py +115 -0
- modelglot/core/anthropic/request_serialization.py +77 -0
- modelglot/core/anthropic/request_snapshot.py +33 -0
- modelglot/core/anthropic/server_tool_sse.py +240 -0
- modelglot/core/anthropic/server_tool_types.py +10 -0
- modelglot/core/anthropic/sse_aggregation.py +156 -0
- modelglot/core/anthropic/stream_contracts.py +217 -0
- modelglot/core/anthropic/streaming/__init__.py +25 -0
- modelglot/core/anthropic/streaming/decoder.py +68 -0
- modelglot/core/anthropic/streaming/emitter.py +62 -0
- modelglot/core/anthropic/streaming/ledger.py +443 -0
- modelglot/core/anthropic/thinking.py +140 -0
- modelglot/core/anthropic/tokens.py +141 -0
- modelglot/core/anthropic/tool_calls.py +139 -0
- modelglot/core/anthropic/tool_results.py +63 -0
- modelglot/core/anthropic/usage.py +38 -0
- modelglot/core/anthropic/utils.py +7 -0
- modelglot/core/async_iterators.py +26 -0
- modelglot/core/async_rwlock.py +52 -0
- modelglot/core/async_tasks.py +30 -0
- modelglot/core/chat_completions/__init__.py +1 -0
- modelglot/core/chat_completions/messages_stream.py +142 -0
- modelglot/core/chat_completions/request.py +610 -0
- modelglot/core/chat_completions/response.py +338 -0
- modelglot/core/chat_completions/responses_stream.py +302 -0
- modelglot/core/chat_completions/tool_calls.py +667 -0
- modelglot/core/continuation_overlap.py +490 -0
- modelglot/core/continuation_request.py +248 -0
- modelglot/core/continuation_stream.py +279 -0
- modelglot/core/data/README.md +12 -0
- modelglot/core/data/TIKTOKEN-LICENSE +21 -0
- modelglot/core/data/cl100k_base.tiktoken +100256 -0
- modelglot/core/delivered_response.py +694 -0
- modelglot/core/diagnostics.py +317 -0
- modelglot/core/failures.py +53 -0
- modelglot/core/gateway_model_ids.py +73 -0
- modelglot/core/gemini/__init__.py +6 -0
- modelglot/core/gemini/errors.py +27 -0
- modelglot/core/gemini/history.py +91 -0
- modelglot/core/gemini/messages_stream.py +168 -0
- modelglot/core/gemini/models.py +263 -0
- modelglot/core/gemini/native_request.py +664 -0
- modelglot/core/gemini/replay.py +199 -0
- modelglot/core/gemini/request.py +453 -0
- modelglot/core/gemini/response.py +285 -0
- modelglot/core/gemini/responses_stream.py +315 -0
- modelglot/core/gemini/schema.py +118 -0
- modelglot/core/gemini/tokens.py +32 -0
- modelglot/core/gemini/web_search_replay.py +153 -0
- modelglot/core/history_replay.py +1336 -0
- modelglot/core/interprocess_lock.py +90 -0
- modelglot/core/json_types.py +70 -0
- modelglot/core/model_capabilities.py +10 -0
- modelglot/core/openai_chat.py +54 -0
- modelglot/core/openai_responses/__init__.py +105 -0
- modelglot/core/openai_responses/chat_request.py +736 -0
- modelglot/core/openai_responses/errors.py +78 -0
- modelglot/core/openai_responses/events.py +110 -0
- modelglot/core/openai_responses/ids.py +32 -0
- modelglot/core/openai_responses/items.py +35 -0
- modelglot/core/openai_responses/messages_request.py +644 -0
- modelglot/core/openai_responses/messages_stream.py +391 -0
- modelglot/core/openai_responses/models.py +33 -0
- modelglot/core/openai_responses/native.py +165 -0
- modelglot/core/openai_responses/provider_input.py +412 -0
- modelglot/core/openai_responses/provider_stream.py +445 -0
- modelglot/core/openai_responses/reasoning.py +73 -0
- modelglot/core/openai_responses/streaming/__init__.py +1 -0
- modelglot/core/openai_responses/streaming/blocks.py +37 -0
- modelglot/core/openai_responses/streaming/completion.py +178 -0
- modelglot/core/openai_responses/streaming/error_mapping.py +16 -0
- modelglot/core/openai_responses/streaming/event_builders.py +250 -0
- modelglot/core/openai_responses/streaming/ledger.py +96 -0
- modelglot/core/openai_responses/tokens.py +133 -0
- modelglot/core/openai_responses/tool_adaptation.py +761 -0
- modelglot/core/openai_responses/tool_calls.py +347 -0
- modelglot/core/openai_responses/tool_search.py +204 -0
- modelglot/core/openai_responses/tools.py +145 -0
- modelglot/core/openai_tool_names.py +163 -0
- modelglot/core/rate_limit.py +79 -0
- modelglot/core/reasoning.py +136 -0
- modelglot/core/recovery_limits.py +3 -0
- modelglot/core/replay_finalization.py +110 -0
- modelglot/core/request_outcomes.py +81 -0
- modelglot/core/stream_delivery.py +69 -0
- modelglot/core/stream_output.py +92 -0
- modelglot/core/stream_recovery.py +162 -0
- modelglot/core/token_estimation.py +79 -0
- modelglot/core/tool_call_buffer.py +122 -0
- modelglot/core/tool_schema_patterns.py +169 -0
- modelglot/core/trace.py +232 -0
- modelglot/core/version.py +15 -0
- modelglot/core/web_tools.py +17 -0
- modelglot/core/windows_dpi.py +25 -0
- modelglot/harnesses/__init__.py +1 -0
- modelglot/harnesses/antigravity.py +203 -0
- modelglot/harnesses/claude.py +49 -0
- modelglot/harnesses/claude_desktop_integration.py +517 -0
- modelglot/harnesses/claude_integration.py +174 -0
- modelglot/harnesses/claude_onboarding.py +43 -0
- modelglot/harnesses/codex.py +96 -0
- modelglot/harnesses/codex_integration.py +229 -0
- modelglot/harnesses/codex_model_catalog.py +127 -0
- modelglot/harnesses/config_file.py +71 -0
- modelglot/harnesses/dsh_config.py +118 -0
- modelglot/harnesses/dsh_desktop_integration.py +216 -0
- modelglot/harnesses/dsh_files.py +170 -0
- modelglot/harnesses/environment.py +78 -0
- modelglot/harnesses/integration_cleanup.py +159 -0
- modelglot/harnesses/jetbrains_acp_integration.py +239 -0
- modelglot/harnesses/launch.py +21 -0
- modelglot/harnesses/model_policy.py +21 -0
- modelglot/harnesses/resources.py +42 -0
- modelglot/harnesses/vscode_chat_integration.py +148 -0
- modelglot/messaging/__init__.py +16 -0
- modelglot/messaging/cli_event_constants.py +66 -0
- modelglot/messaging/command_context.py +99 -0
- modelglot/messaging/command_dispatcher.py +31 -0
- modelglot/messaging/commands.py +182 -0
- modelglot/messaging/delivery_failures/__init__.py +39 -0
- modelglot/messaging/delivery_failures/decision.py +92 -0
- modelglot/messaging/delivery_failures/queue.py +16 -0
- modelglot/messaging/event_parser.py +184 -0
- modelglot/messaging/limiter.py +296 -0
- modelglot/messaging/managed_protocols.py +37 -0
- modelglot/messaging/models.py +56 -0
- modelglot/messaging/node_event_pipeline.py +124 -0
- modelglot/messaging/node_runner.py +404 -0
- modelglot/messaging/platforms/__init__.py +20 -0
- modelglot/messaging/platforms/discord.py +322 -0
- modelglot/messaging/platforms/discord_inbound.py +116 -0
- modelglot/messaging/platforms/discord_io.py +258 -0
- modelglot/messaging/platforms/factory.py +109 -0
- modelglot/messaging/platforms/outbox.py +146 -0
- modelglot/messaging/platforms/ports.py +99 -0
- modelglot/messaging/platforms/telegram.py +312 -0
- modelglot/messaging/platforms/telegram_inbound.py +135 -0
- modelglot/messaging/platforms/telegram_io.py +355 -0
- modelglot/messaging/platforms/voice_flow.py +387 -0
- modelglot/messaging/rendering/__init__.py +3 -0
- modelglot/messaging/rendering/discord_markdown.py +327 -0
- modelglot/messaging/rendering/markdown_tables.py +47 -0
- modelglot/messaging/rendering/profiles.py +53 -0
- modelglot/messaging/rendering/telegram_markdown.py +340 -0
- modelglot/messaging/safe_diagnostics.py +15 -0
- modelglot/messaging/transcript/__init__.py +6 -0
- modelglot/messaging/transcript/buffer.py +225 -0
- modelglot/messaging/transcript/context.py +18 -0
- modelglot/messaging/transcript/renderer.py +65 -0
- modelglot/messaging/transcript/segments.py +175 -0
- modelglot/messaging/transcript/subagents.py +108 -0
- modelglot/messaging/transcription.py +147 -0
- modelglot/messaging/trees/__init__.py +46 -0
- modelglot/messaging/trees/graph.py +264 -0
- modelglot/messaging/trees/identity.py +16 -0
- modelglot/messaging/trees/manager.py +712 -0
- modelglot/messaging/trees/node.py +56 -0
- modelglot/messaging/trees/ports.py +35 -0
- modelglot/messaging/trees/processor.py +287 -0
- modelglot/messaging/trees/queue.py +47 -0
- modelglot/messaging/trees/repository.py +146 -0
- modelglot/messaging/trees/runtime.py +525 -0
- modelglot/messaging/trees/snapshot.py +224 -0
- modelglot/messaging/trees/transaction.py +54 -0
- modelglot/messaging/trees/transitions.py +175 -0
- modelglot/messaging/turn_intake.py +236 -0
- modelglot/messaging/ui_updates.py +99 -0
- modelglot/messaging/voice.py +376 -0
- modelglot/messaging/workflow.py +707 -0
- modelglot/providers/__init__.py +12 -0
- modelglot/providers/admission.py +1167 -0
- modelglot/providers/admission_capacity.py +71 -0
- modelglot/providers/admission_policy.py +33 -0
- modelglot/providers/admission_registry.py +74 -0
- modelglot/providers/alibaba_cloud/__init__.py +5 -0
- modelglot/providers/alibaba_cloud/client.py +148 -0
- modelglot/providers/anthropic/__init__.py +5 -0
- modelglot/providers/anthropic/headers.py +68 -0
- modelglot/providers/anthropic/models.py +63 -0
- modelglot/providers/anthropic/provider.py +370 -0
- modelglot/providers/anthropic_messages/__init__.py +1 -0
- modelglot/providers/anthropic_messages/discovery.py +81 -0
- modelglot/providers/anthropic_messages/request_policy.py +170 -0
- modelglot/providers/anthropic_messages/transport.py +670 -0
- modelglot/providers/anthropic_messages/wire.py +110 -0
- modelglot/providers/attempt_loop/__init__.py +16 -0
- modelglot/providers/attempt_loop/attempt.py +78 -0
- modelglot/providers/attempt_loop/loop.py +495 -0
- modelglot/providers/base.py +126 -0
- modelglot/providers/canonical_failures.py +57 -0
- modelglot/providers/cloudflare/__init__.py +8 -0
- modelglot/providers/cloudflare/client.py +198 -0
- modelglot/providers/continuation.py +442 -0
- modelglot/providers/credential_validation.py +383 -0
- modelglot/providers/custom.py +424 -0
- modelglot/providers/deepseek/__init__.py +5 -0
- modelglot/providers/deepseek/client.py +123 -0
- modelglot/providers/deepseek/compat.py +246 -0
- modelglot/providers/endpoint.py +26 -0
- modelglot/providers/endpoint_types.py +25 -0
- modelglot/providers/failure_classification/__init__.py +6 -0
- modelglot/providers/failure_classification/classifier.py +211 -0
- modelglot/providers/failure_classification/evidence.py +220 -0
- modelglot/providers/failure_classification/verdict.py +26 -0
- modelglot/providers/failure_reporting.py +113 -0
- modelglot/providers/gemini/__init__.py +5 -0
- modelglot/providers/gemini/client.py +313 -0
- modelglot/providers/gemini/stream.py +353 -0
- modelglot/providers/gemini/transport.py +317 -0
- modelglot/providers/github_copilot/__init__.py +1 -0
- modelglot/providers/github_copilot/auth.py +502 -0
- modelglot/providers/github_copilot/broker.py +248 -0
- modelglot/providers/github_copilot/lifecycle.py +18 -0
- modelglot/providers/github_copilot/login.py +113 -0
- modelglot/providers/github_copilot/native_cli.py +83 -0
- modelglot/providers/github_copilot/provider.py +480 -0
- modelglot/providers/github_copilot/request_policy.py +125 -0
- modelglot/providers/github_copilot/responses_events.py +90 -0
- modelglot/providers/github_copilot/sdk.py +496 -0
- modelglot/providers/github_copilot/types.py +67 -0
- modelglot/providers/google_openai/__init__.py +15 -0
- modelglot/providers/google_openai/provider.py +125 -0
- modelglot/providers/google_openai/reasoning.py +114 -0
- modelglot/providers/google_openai/thought_signatures.py +150 -0
- modelglot/providers/groq/__init__.py +5 -0
- modelglot/providers/groq/client.py +366 -0
- modelglot/providers/groq/tpm.py +114 -0
- modelglot/providers/history_negotiation.py +286 -0
- modelglot/providers/history_replay.py +433 -0
- modelglot/providers/http.py +133 -0
- modelglot/providers/kilo/__init__.py +5 -0
- modelglot/providers/kilo/client.py +55 -0
- modelglot/providers/kilo/models.py +59 -0
- modelglot/providers/lmstudio/__init__.py +5 -0
- modelglot/providers/lmstudio/client.py +146 -0
- modelglot/providers/lmstudio/tokens.py +107 -0
- modelglot/providers/mistral/__init__.py +5 -0
- modelglot/providers/mistral/caching.py +59 -0
- modelglot/providers/mistral/client.py +237 -0
- modelglot/providers/mistral/reasoning.py +369 -0
- modelglot/providers/model_catalog_logos.py +191 -0
- modelglot/providers/model_catalog_source.py +357 -0
- modelglot/providers/model_listing.py +496 -0
- modelglot/providers/nvidia_nim/__init__.py +5 -0
- modelglot/providers/nvidia_nim/client.py +202 -0
- modelglot/providers/nvidia_nim/models.py +74 -0
- modelglot/providers/nvidia_nim/request_options.py +109 -0
- modelglot/providers/nvidia_nim/retry.py +32 -0
- modelglot/providers/nvidia_nim/tool_schema.py +256 -0
- modelglot/providers/nvidia_nim/voice.py +119 -0
- modelglot/providers/open_router/__init__.py +5 -0
- modelglot/providers/open_router/client.py +132 -0
- modelglot/providers/openai_api/__init__.py +5 -0
- modelglot/providers/openai_api/provider.py +215 -0
- modelglot/providers/openai_chat/__init__.py +91 -0
- modelglot/providers/openai_chat/base_url.py +7 -0
- modelglot/providers/openai_chat/behavior.py +155 -0
- modelglot/providers/openai_chat/client.py +40 -0
- modelglot/providers/openai_chat/extra_body.py +63 -0
- modelglot/providers/openai_chat/gemini_output.py +154 -0
- modelglot/providers/openai_chat/media_support.py +146 -0
- modelglot/providers/openai_chat/native_output.py +78 -0
- modelglot/providers/openai_chat/output_cap.py +212 -0
- modelglot/providers/openai_chat/profiles.py +875 -0
- modelglot/providers/openai_chat/provider.py +308 -0
- modelglot/providers/openai_chat/reasoning.py +178 -0
- modelglot/providers/openai_chat/reasoning_details.py +402 -0
- modelglot/providers/openai_chat/request_policy.py +146 -0
- modelglot/providers/openai_chat/stream_output.py +704 -0
- modelglot/providers/openai_chat/transport.py +1454 -0
- modelglot/providers/openai_chat/usage.py +117 -0
- modelglot/providers/openai_client.py +77 -0
- modelglot/providers/openai_codex/__init__.py +1 -0
- modelglot/providers/openai_codex/auth.py +650 -0
- modelglot/providers/openai_codex/endpoint.py +53 -0
- modelglot/providers/openai_codex/login.py +275 -0
- modelglot/providers/openai_codex/provider.py +354 -0
- modelglot/providers/openai_responses/__init__.py +5 -0
- modelglot/providers/openai_responses/presentation.py +130 -0
- modelglot/providers/openai_responses/transport.py +690 -0
- modelglot/providers/openai_stream.py +44 -0
- modelglot/providers/opencode/__init__.py +5 -0
- modelglot/providers/opencode/catalog.py +340 -0
- modelglot/providers/opencode/provider.py +455 -0
- modelglot/providers/reasoning_compatibility.py +210 -0
- modelglot/providers/recovery_errors.py +35 -0
- modelglot/providers/recovery_policy/__init__.py +38 -0
- modelglot/providers/recovery_policy/decision.py +138 -0
- modelglot/providers/recovery_policy/timing.py +62 -0
- modelglot/providers/request_correction/__init__.py +28 -0
- modelglot/providers/request_correction/corrector.py +88 -0
- modelglot/providers/request_correction/rejection.py +72 -0
- modelglot/providers/runtime/__init__.py +10 -0
- modelglot/providers/runtime/config.py +126 -0
- modelglot/providers/runtime/discovery.py +159 -0
- modelglot/providers/runtime/factory.py +389 -0
- modelglot/providers/runtime/model_cache.py +96 -0
- modelglot/providers/runtime/runtime.py +151 -0
- modelglot/providers/stream_failure_resolution/__init__.py +26 -0
- modelglot/providers/stream_failure_resolution/decision.py +123 -0
- modelglot/providers/stream_read.py +19 -0
- modelglot/providers/stream_recovery.py +7 -0
- modelglot/providers/vertex/__init__.py +5 -0
- modelglot/providers/vertex/auth.py +105 -0
- modelglot/providers/vertex/client.py +146 -0
- modelglot/providers/vertex/endpoint.py +50 -0
- modelglot/providers/vertex/models.py +52 -0
- modelglot/runtime/__init__.py +1 -0
- modelglot/runtime/application.py +774 -0
- modelglot/runtime/asgi.py +64 -0
- modelglot/runtime/bootstrap.py +185 -0
- modelglot/runtime/code_sessions_sqlite.py +873 -0
- modelglot/runtime/codex_app_server.py +781 -0
- modelglot/runtime/codex_catalog.py +62 -0
- modelglot/runtime/codex_protocol.py +690 -0
- modelglot/runtime/configuration.py +93 -0
- modelglot/runtime/diagnostics.py +426 -0
- modelglot/runtime/folder_picker.py +129 -0
- modelglot/runtime/integration_service.py +785 -0
- modelglot/runtime/lifecycle.py +38 -0
- modelglot/runtime/messaging_import.py +207 -0
- modelglot/runtime/messaging_service.py +344 -0
- modelglot/runtime/messaging_sqlite.py +196 -0
- modelglot/runtime/native_folder_dialog.py +137 -0
- modelglot/runtime/provider_manager.py +1004 -0
- modelglot/runtime/retired_chat.py +47 -0
- modelglot/runtime/sqlite_database.py +459 -0
- modelglot/runtime/sqlite_migrations/__init__.py +27 -0
- modelglot/runtime/sqlite_migrations/v0001_code_schema.py +101 -0
- modelglot/runtime/sqlite_migrations/v0002_code_permissions.py +16 -0
- modelglot/runtime/sqlite_migrations/v0003_code_context_usage.py +10 -0
- modelglot/runtime/sqlite_migrations/v0004_messaging_schema.py +108 -0
- modelglot/runtime/sqlite_migrations/v0005_active_code_prompts.py +10 -0
- modelglot/runtime/sqlite_migrations/v0006_usage_events.py +70 -0
- modelglot/runtime/token_optimization.py +367 -0
- modelglot/runtime/usage_events.py +326 -0
- modelglot/runtime/usage_events_sqlite.py +373 -0
- modelglot/runtime/web_tools/__init__.py +1 -0
- modelglot/runtime/web_tools/client.py +250 -0
- modelglot/runtime/web_tools/constants.py +17 -0
- modelglot/runtime/web_tools/egress.py +107 -0
- modelglot/runtime/web_tools/parsers.py +85 -0
- modelglot/updater/__init__.py +1 -0
- modelglot/updater/check.py +147 -0
- modelglot/updater/desktop.py +346 -0
- modelglot-7.0.0.data/scripts/modelglot-update +4 -0
- modelglot-7.0.0.data/scripts/modelglot-update.cmd +7 -0
- modelglot-7.0.0.dist-info/METADATA +866 -0
- modelglot-7.0.0.dist-info/RECORD +571 -0
- modelglot-7.0.0.dist-info/WHEEL +4 -0
- modelglot-7.0.0.dist-info/entry_points.txt +17 -0
- modelglot-7.0.0.dist-info/licenses/LICENSE +239 -0
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
"""Same-provider continuation using evidence from the public delivery boundary."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
from dataclasses import dataclass, replace
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from modelglot.core.continuation_request import (
|
|
8
|
+
ContinuationRequest,
|
|
9
|
+
UpstreamProtocol,
|
|
10
|
+
)
|
|
11
|
+
from modelglot.core.delivered_response import (
|
|
12
|
+
is_structured_text_format,
|
|
13
|
+
)
|
|
14
|
+
from modelglot.core.failures import ExecutionFailure, FailureKind
|
|
15
|
+
from modelglot.core.history_replay import protected_reasoning
|
|
16
|
+
from modelglot.core.json_types import (
|
|
17
|
+
JsonObject,
|
|
18
|
+
JsonValue,
|
|
19
|
+
json_array,
|
|
20
|
+
json_object,
|
|
21
|
+
json_objects,
|
|
22
|
+
optional_string,
|
|
23
|
+
)
|
|
24
|
+
from modelglot.core.openai_responses import is_client_call
|
|
25
|
+
from modelglot.core.stream_recovery import (
|
|
26
|
+
RecoveryAction,
|
|
27
|
+
SourceRecoverySnapshot,
|
|
28
|
+
StreamFailureContext,
|
|
29
|
+
assess_recovery,
|
|
30
|
+
)
|
|
31
|
+
from modelglot.core.trace import trace_event
|
|
32
|
+
|
|
33
|
+
from .admission import ProviderExecution
|
|
34
|
+
|
|
35
|
+
_USAGE_FIELDS = {
|
|
36
|
+
"messages": {
|
|
37
|
+
"input_tokens",
|
|
38
|
+
"output_tokens",
|
|
39
|
+
"cache_read_input_tokens",
|
|
40
|
+
"cache_creation_input_tokens",
|
|
41
|
+
"reasoning_tokens",
|
|
42
|
+
},
|
|
43
|
+
"chat": {
|
|
44
|
+
"prompt_tokens",
|
|
45
|
+
"completion_tokens",
|
|
46
|
+
"total_tokens",
|
|
47
|
+
"prompt_cache_hit_tokens",
|
|
48
|
+
"prompt_cache_miss_tokens",
|
|
49
|
+
"prompt_tokens_details",
|
|
50
|
+
"completion_tokens_details",
|
|
51
|
+
},
|
|
52
|
+
"responses": {
|
|
53
|
+
"input_tokens",
|
|
54
|
+
"output_tokens",
|
|
55
|
+
"total_tokens",
|
|
56
|
+
"input_tokens_details",
|
|
57
|
+
"output_tokens_details",
|
|
58
|
+
},
|
|
59
|
+
"gemini": {
|
|
60
|
+
"promptTokenCount",
|
|
61
|
+
"cachedContentTokenCount",
|
|
62
|
+
"candidatesTokenCount",
|
|
63
|
+
"thoughtsTokenCount",
|
|
64
|
+
"totalTokenCount",
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
_USAGE_DETAIL_FIELDS = {
|
|
68
|
+
"cached_tokens",
|
|
69
|
+
"cache_write_tokens",
|
|
70
|
+
"cache_creation_tokens",
|
|
71
|
+
"reasoning_tokens",
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class SourceRecoveryState:
|
|
76
|
+
"""Native source evidence cannot be inferred from buffered public events."""
|
|
77
|
+
|
|
78
|
+
def __init__(
|
|
79
|
+
self,
|
|
80
|
+
execution: ProviderExecution,
|
|
81
|
+
*,
|
|
82
|
+
previous: SourceRecoveryState | None = None,
|
|
83
|
+
) -> None:
|
|
84
|
+
self._execution = execution
|
|
85
|
+
self._prior_unsafe_reason = (
|
|
86
|
+
previous.unsafe_reason or previous._prior_unsafe_reason
|
|
87
|
+
if previous is not None
|
|
88
|
+
else None
|
|
89
|
+
)
|
|
90
|
+
self.unsafe_reason: str | None = None
|
|
91
|
+
self._pending_reasoning: set[int | str] = set()
|
|
92
|
+
self._signed: set[int | str] = set()
|
|
93
|
+
self._handoff_blocked = False
|
|
94
|
+
self._usage_protocol: UpstreamProtocol | None = None
|
|
95
|
+
self._usage: JsonObject = {}
|
|
96
|
+
|
|
97
|
+
@property
|
|
98
|
+
def can_handoff(self) -> bool:
|
|
99
|
+
return not self._handoff_blocked and not self._pending_reasoning
|
|
100
|
+
|
|
101
|
+
def snapshot(
|
|
102
|
+
self,
|
|
103
|
+
*,
|
|
104
|
+
body: dict[str, Any],
|
|
105
|
+
protocol: UpstreamProtocol,
|
|
106
|
+
normal_stop_seen: bool,
|
|
107
|
+
for_model_fallback: bool = False,
|
|
108
|
+
) -> SourceRecoverySnapshot:
|
|
109
|
+
return SourceRecoverySnapshot(
|
|
110
|
+
normal_stop_seen=normal_stop_seen,
|
|
111
|
+
structured_output=_structured_output(body, protocol),
|
|
112
|
+
unsafe_reason=self.unsafe_reason
|
|
113
|
+
or (self._prior_unsafe_reason if for_model_fallback else None),
|
|
114
|
+
can_handoff=self.can_handoff,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
def usage_snapshot(self) -> tuple[UpstreamProtocol, JsonObject] | None:
|
|
118
|
+
"""Return only allow-listed native usage fields collected for this attempt."""
|
|
119
|
+
|
|
120
|
+
if self._usage_protocol is None:
|
|
121
|
+
return None
|
|
122
|
+
return self._usage_protocol, dict(self._usage)
|
|
123
|
+
|
|
124
|
+
def _observe_usage(self, protocol: UpstreamProtocol, usage: JsonObject) -> None:
|
|
125
|
+
self._usage_protocol = protocol
|
|
126
|
+
for key in _USAGE_FIELDS[protocol]:
|
|
127
|
+
if key not in usage:
|
|
128
|
+
continue
|
|
129
|
+
value = usage[key]
|
|
130
|
+
if key.endswith("_details") and isinstance(value, dict):
|
|
131
|
+
self._usage[key] = {
|
|
132
|
+
detail: value[detail]
|
|
133
|
+
for detail in _USAGE_DETAIL_FIELDS
|
|
134
|
+
if detail in value
|
|
135
|
+
}
|
|
136
|
+
else:
|
|
137
|
+
self._usage[key] = value
|
|
138
|
+
|
|
139
|
+
def observe(
|
|
140
|
+
self,
|
|
141
|
+
protocol: UpstreamProtocol,
|
|
142
|
+
payload: Mapping[str, JsonValue],
|
|
143
|
+
*,
|
|
144
|
+
continuing: bool = False,
|
|
145
|
+
) -> None:
|
|
146
|
+
kind = str(payload.get("type", ""))
|
|
147
|
+
usage = payload.get("usage")
|
|
148
|
+
if protocol == "messages" and kind == "message_start":
|
|
149
|
+
usage = json_object(payload.get("message", {})).get("usage")
|
|
150
|
+
elif protocol == "responses":
|
|
151
|
+
usage = json_object(payload.get("response", {})).get("usage")
|
|
152
|
+
elif protocol == "gemini":
|
|
153
|
+
usage = payload.get("usageMetadata")
|
|
154
|
+
if isinstance(usage, dict) and usage:
|
|
155
|
+
self._observe_usage(protocol, usage)
|
|
156
|
+
trace_event(
|
|
157
|
+
stage="provider",
|
|
158
|
+
event="provider.attempt.usage",
|
|
159
|
+
source="provider",
|
|
160
|
+
request_id=self._execution.request_id,
|
|
161
|
+
execution_id=self._execution.execution_id,
|
|
162
|
+
attempt=self._execution.attempts_started,
|
|
163
|
+
usage=usage,
|
|
164
|
+
)
|
|
165
|
+
if protocol == "gemini":
|
|
166
|
+
# The final native replay carrier is published only after the source
|
|
167
|
+
# completes. A call alone cannot prove its late signature is complete.
|
|
168
|
+
self._handoff_blocked = True
|
|
169
|
+
for candidate in json_objects(payload.get("candidates", [])):
|
|
170
|
+
for part in json_objects(
|
|
171
|
+
json_object(candidate.get("content", {})).get("parts", [])
|
|
172
|
+
):
|
|
173
|
+
if part.get("thoughtSignature") and self.unsafe_reason is None:
|
|
174
|
+
self.unsafe_reason = "signed_thinking"
|
|
175
|
+
if any(
|
|
176
|
+
key
|
|
177
|
+
not in {"text", "thought", "thoughtSignature", "functionCall"}
|
|
178
|
+
for key in part
|
|
179
|
+
):
|
|
180
|
+
self.unsafe_reason = "native_content"
|
|
181
|
+
elif protocol == "chat":
|
|
182
|
+
choices = list(json_objects(payload.get("choices", [])))
|
|
183
|
+
if len(choices) > 1 or any(
|
|
184
|
+
choice.get("index", 0) != 0 or choice.get("logprobs")
|
|
185
|
+
for choice in choices
|
|
186
|
+
):
|
|
187
|
+
self.unsafe_reason = "native_content"
|
|
188
|
+
self._handoff_blocked = True
|
|
189
|
+
for choice in choices:
|
|
190
|
+
delta = json_object(choice.get("delta") or {})
|
|
191
|
+
if protected_reasoning({"extra_content": delta.get("extra_content")}):
|
|
192
|
+
self.unsafe_reason = "native_content"
|
|
193
|
+
details = delta.get("reasoning_details")
|
|
194
|
+
if delta.get("audio") or (
|
|
195
|
+
details
|
|
196
|
+
and (
|
|
197
|
+
not isinstance(details, list)
|
|
198
|
+
or any(
|
|
199
|
+
not isinstance(detail, dict)
|
|
200
|
+
or detail.get("type")
|
|
201
|
+
not in ("reasoning.text", "reasoning.summary")
|
|
202
|
+
or protected_reasoning(detail)
|
|
203
|
+
for detail in details
|
|
204
|
+
)
|
|
205
|
+
)
|
|
206
|
+
):
|
|
207
|
+
self.unsafe_reason = "native_content"
|
|
208
|
+
self._handoff_blocked = True
|
|
209
|
+
elif protocol == "messages" and kind in (
|
|
210
|
+
"content_block_start",
|
|
211
|
+
"content_block_delta",
|
|
212
|
+
"content_block_stop",
|
|
213
|
+
):
|
|
214
|
+
index = payload.get("index")
|
|
215
|
+
if not isinstance(index, int) or isinstance(index, bool) or index < 0:
|
|
216
|
+
# The Messages parser classifies malformed block events for retries.
|
|
217
|
+
return
|
|
218
|
+
block = payload.get("content_block")
|
|
219
|
+
if isinstance(block, dict) and block.get("type") in (
|
|
220
|
+
"thinking",
|
|
221
|
+
"redacted_thinking",
|
|
222
|
+
):
|
|
223
|
+
self.unsafe_reason = "signed_thinking"
|
|
224
|
+
self._pending_reasoning.add(index)
|
|
225
|
+
if block.get("signature") or block.get("data"):
|
|
226
|
+
self._signed.add(index)
|
|
227
|
+
if isinstance(block, dict) and block.get("type") not in (
|
|
228
|
+
"text",
|
|
229
|
+
"tool_use",
|
|
230
|
+
"thinking",
|
|
231
|
+
"redacted_thinking",
|
|
232
|
+
):
|
|
233
|
+
self.unsafe_reason = "native_content"
|
|
234
|
+
self._handoff_blocked = True
|
|
235
|
+
delta = json_object(payload.get("delta") or {})
|
|
236
|
+
if (isinstance(block, dict) and block.get("citations")) or delta.get(
|
|
237
|
+
"type"
|
|
238
|
+
) == "citations_delta":
|
|
239
|
+
self.unsafe_reason = "native_content"
|
|
240
|
+
self._handoff_blocked = True
|
|
241
|
+
if delta.get("type") in ("thinking_delta", "signature_delta"):
|
|
242
|
+
self.unsafe_reason = "signed_thinking"
|
|
243
|
+
if delta.get("signature"):
|
|
244
|
+
self._signed.add(index)
|
|
245
|
+
if kind == "content_block_stop" and index in self._signed:
|
|
246
|
+
self._pending_reasoning.discard(index)
|
|
247
|
+
elif protocol == "responses":
|
|
248
|
+
item = payload.get("item")
|
|
249
|
+
if isinstance(item, dict):
|
|
250
|
+
self._response_item(item, completed=kind == "response.output_item.done")
|
|
251
|
+
response = payload.get("response")
|
|
252
|
+
if isinstance(response, dict):
|
|
253
|
+
for item in json_array(response.get("output", [])):
|
|
254
|
+
if isinstance(item, dict):
|
|
255
|
+
self._response_item(
|
|
256
|
+
item, completed=item.get("status") == "completed"
|
|
257
|
+
)
|
|
258
|
+
part = payload.get("part")
|
|
259
|
+
if (
|
|
260
|
+
kind in {"response.content_part.added", "response.content_part.done"}
|
|
261
|
+
and isinstance(part, dict)
|
|
262
|
+
and part.get("annotations")
|
|
263
|
+
):
|
|
264
|
+
self.unsafe_reason = "native_content"
|
|
265
|
+
self._handoff_blocked = True
|
|
266
|
+
if kind.startswith(
|
|
267
|
+
(
|
|
268
|
+
"response.web_search",
|
|
269
|
+
"response.code_interpreter",
|
|
270
|
+
"response.mcp_",
|
|
271
|
+
"response.image_generation",
|
|
272
|
+
"response.audio",
|
|
273
|
+
)
|
|
274
|
+
):
|
|
275
|
+
self.unsafe_reason = "hosted_or_native_content"
|
|
276
|
+
self._handoff_blocked = True
|
|
277
|
+
if kind == "response.output_text.annotation.added":
|
|
278
|
+
self.unsafe_reason = "native_content"
|
|
279
|
+
self._handoff_blocked = True
|
|
280
|
+
if (
|
|
281
|
+
continuing
|
|
282
|
+
and self.unsafe_reason
|
|
283
|
+
and not (protocol == "gemini" and self.unsafe_reason == "signed_thinking")
|
|
284
|
+
):
|
|
285
|
+
raise ExecutionFailure(
|
|
286
|
+
kind=FailureKind.UPSTREAM,
|
|
287
|
+
status_code=502,
|
|
288
|
+
message="The continuation returned native state that cannot be combined with the delivered response.",
|
|
289
|
+
retryable=False,
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
def _response_item(self, item: JsonObject, *, completed: bool) -> None:
|
|
293
|
+
if item.get("type") not in ("message", "reasoning") and not is_client_call(
|
|
294
|
+
item
|
|
295
|
+
):
|
|
296
|
+
self.unsafe_reason = "hosted_or_native_content"
|
|
297
|
+
self._handoff_blocked = True
|
|
298
|
+
identity = optional_string(item.get("id")) or ""
|
|
299
|
+
if item.get("encrypted_content"):
|
|
300
|
+
self.unsafe_reason = "opaque_reasoning"
|
|
301
|
+
if not completed:
|
|
302
|
+
self._pending_reasoning.add(identity)
|
|
303
|
+
if completed:
|
|
304
|
+
self._pending_reasoning.discard(identity)
|
|
305
|
+
if any(
|
|
306
|
+
part.get("annotations")
|
|
307
|
+
or part.get("type")
|
|
308
|
+
not in ("output_text", "refusal", "reasoning_text", "summary_text")
|
|
309
|
+
for field in ("content", "summary")
|
|
310
|
+
for part in json_objects(item.get(field) or [])
|
|
311
|
+
):
|
|
312
|
+
self.unsafe_reason = "native_content"
|
|
313
|
+
self._handoff_blocked = True
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
@dataclass(frozen=True, slots=True)
|
|
317
|
+
class PublicRecovery:
|
|
318
|
+
body: dict[str, Any] | None = None
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
def public_stream_failure(
|
|
322
|
+
failure: ExecutionFailure,
|
|
323
|
+
*,
|
|
324
|
+
source: SourceRecoveryState,
|
|
325
|
+
body: dict[str, Any],
|
|
326
|
+
protocol: UpstreamProtocol,
|
|
327
|
+
normal_stop_seen: bool,
|
|
328
|
+
responses_failure_payload: JsonObject | None = None,
|
|
329
|
+
) -> ExecutionFailure:
|
|
330
|
+
"""Retain source evidence until routing has decided the public outcome."""
|
|
331
|
+
snapshot = source.snapshot(
|
|
332
|
+
body=body,
|
|
333
|
+
protocol=protocol,
|
|
334
|
+
normal_stop_seen=normal_stop_seen,
|
|
335
|
+
for_model_fallback=True,
|
|
336
|
+
)
|
|
337
|
+
if (
|
|
338
|
+
failure.stream_context is not None
|
|
339
|
+
and failure.stream_context.source.unsafe_reason
|
|
340
|
+
):
|
|
341
|
+
snapshot = replace(
|
|
342
|
+
snapshot, unsafe_reason=failure.stream_context.source.unsafe_reason
|
|
343
|
+
)
|
|
344
|
+
return replace(
|
|
345
|
+
failure,
|
|
346
|
+
stream_context=StreamFailureContext(snapshot, responses_failure_payload),
|
|
347
|
+
)
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
def _structured_output(
|
|
351
|
+
body: Mapping[str, JsonValue], protocol: UpstreamProtocol
|
|
352
|
+
) -> bool:
|
|
353
|
+
if protocol == "gemini":
|
|
354
|
+
config = json_object(body.get("generationConfig") or {})
|
|
355
|
+
format_ = json_object(config.get("responseFormat") or {})
|
|
356
|
+
text = json_object(format_.get("text") or {})
|
|
357
|
+
return (
|
|
358
|
+
config.get("responseMimeType") == "application/json"
|
|
359
|
+
or text.get("mimeType") == "APPLICATION_JSON"
|
|
360
|
+
or bool(
|
|
361
|
+
config.get("responseSchema")
|
|
362
|
+
or config.get("responseJsonSchema")
|
|
363
|
+
or text.get("schema")
|
|
364
|
+
)
|
|
365
|
+
)
|
|
366
|
+
if protocol == "chat":
|
|
367
|
+
extra = json_object(body.get("extra_body") or {})
|
|
368
|
+
value = extra.get("response_format", body.get("response_format"))
|
|
369
|
+
else:
|
|
370
|
+
options = json_object(
|
|
371
|
+
body.get("text" if protocol == "responses" else "output_config") or {}
|
|
372
|
+
)
|
|
373
|
+
value = options.get("format")
|
|
374
|
+
return is_structured_text_format(value)
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
def public_recovery(
|
|
378
|
+
execution: ProviderExecution,
|
|
379
|
+
*,
|
|
380
|
+
body: dict[str, Any],
|
|
381
|
+
request: ContinuationRequest,
|
|
382
|
+
retryable: bool,
|
|
383
|
+
normal_stop_seen: bool,
|
|
384
|
+
source: SourceRecoveryState,
|
|
385
|
+
) -> PublicRecovery | None:
|
|
386
|
+
delivery = execution.delivery
|
|
387
|
+
if delivery is None or not delivery.content_released:
|
|
388
|
+
return None
|
|
389
|
+
if not retryable:
|
|
390
|
+
return None
|
|
391
|
+
assessment = assess_recovery(
|
|
392
|
+
content_released=True,
|
|
393
|
+
prefix=delivery.prefix,
|
|
394
|
+
source=source.snapshot(
|
|
395
|
+
body=body, protocol=request.protocol, normal_stop_seen=normal_stop_seen
|
|
396
|
+
),
|
|
397
|
+
retryable=retryable,
|
|
398
|
+
)
|
|
399
|
+
if assessment.action is RecoveryAction.STOP:
|
|
400
|
+
trace_event(
|
|
401
|
+
stage="provider",
|
|
402
|
+
event="provider.recovery.ineligible",
|
|
403
|
+
source="provider",
|
|
404
|
+
request_id=execution.request_id,
|
|
405
|
+
reason=assessment.reason,
|
|
406
|
+
)
|
|
407
|
+
return None
|
|
408
|
+
if assessment.action is RecoveryAction.HANDOFF:
|
|
409
|
+
delivery.begin_continuation(handoff=True)
|
|
410
|
+
trace_event(
|
|
411
|
+
stage="provider",
|
|
412
|
+
event="provider.recovery.tool_handoff",
|
|
413
|
+
source="provider",
|
|
414
|
+
request_id=execution.request_id,
|
|
415
|
+
usage_estimated=True,
|
|
416
|
+
)
|
|
417
|
+
return PublicRecovery()
|
|
418
|
+
if not execution.can_attempt:
|
|
419
|
+
trace_event(
|
|
420
|
+
stage="provider",
|
|
421
|
+
event="provider.recovery.exhausted",
|
|
422
|
+
source="provider",
|
|
423
|
+
request_id=execution.request_id,
|
|
424
|
+
attempts_started=execution.attempts_started,
|
|
425
|
+
max_attempts=execution.max_attempts,
|
|
426
|
+
)
|
|
427
|
+
return None
|
|
428
|
+
seed = assessment.seed
|
|
429
|
+
if seed is None:
|
|
430
|
+
return None
|
|
431
|
+
replacement = request.build(body, seed)
|
|
432
|
+
delivery.begin_continuation()
|
|
433
|
+
trace_event(
|
|
434
|
+
stage="provider",
|
|
435
|
+
event="provider.recovery.continuation",
|
|
436
|
+
source="provider",
|
|
437
|
+
request_id=execution.request_id,
|
|
438
|
+
attempts_started=execution.attempts_started,
|
|
439
|
+
max_attempts=execution.max_attempts,
|
|
440
|
+
usage_estimated=True,
|
|
441
|
+
)
|
|
442
|
+
return PublicRecovery(body=replacement)
|