codex-multi-auth 1.2.0 → 1.2.2
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/README.md +49 -32
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +929 -1712
- package/dist/index.js.map +1 -1
- package/dist/lib/accounts.d.ts +10 -0
- package/dist/lib/accounts.d.ts.map +1 -1
- package/dist/lib/accounts.js +312 -69
- package/dist/lib/accounts.js.map +1 -1
- package/dist/lib/auth/index.d.ts +2 -0
- package/dist/lib/auth/index.d.ts.map +1 -0
- package/dist/lib/auth/index.js +2 -0
- package/dist/lib/auth/index.js.map +1 -0
- package/dist/lib/circuit-breaker.d.ts +4 -0
- package/dist/lib/circuit-breaker.d.ts.map +1 -1
- package/dist/lib/circuit-breaker.js +33 -1
- package/dist/lib/circuit-breaker.js.map +1 -1
- package/dist/lib/codex-cli/index.d.ts +5 -0
- package/dist/lib/codex-cli/index.d.ts.map +1 -0
- package/dist/lib/codex-cli/index.js +5 -0
- package/dist/lib/codex-cli/index.js.map +1 -0
- package/dist/lib/codex-manager/auth-commands.d.ts +72 -0
- package/dist/lib/codex-manager/auth-commands.d.ts.map +1 -0
- package/dist/lib/codex-manager/auth-commands.js +643 -0
- package/dist/lib/codex-manager/auth-commands.js.map +1 -0
- package/dist/lib/codex-manager/backend-category-entry.d.ts +103 -0
- package/dist/lib/codex-manager/backend-category-entry.d.ts.map +1 -0
- package/dist/lib/codex-manager/backend-category-entry.js +23 -0
- package/dist/lib/codex-manager/backend-category-entry.js.map +1 -0
- package/dist/lib/codex-manager/backend-category-helpers.d.ts +10 -0
- package/dist/lib/codex-manager/backend-category-helpers.d.ts.map +1 -0
- package/dist/lib/codex-manager/backend-category-helpers.js +29 -0
- package/dist/lib/codex-manager/backend-category-helpers.js.map +1 -0
- package/dist/lib/codex-manager/backend-category-prompt.d.ts +55 -0
- package/dist/lib/codex-manager/backend-category-prompt.d.ts.map +1 -0
- package/dist/lib/codex-manager/backend-category-prompt.js +178 -0
- package/dist/lib/codex-manager/backend-category-prompt.js.map +1 -0
- package/dist/lib/codex-manager/backend-settings-controller.d.ts +11 -0
- package/dist/lib/codex-manager/backend-settings-controller.d.ts.map +1 -0
- package/dist/lib/codex-manager/backend-settings-controller.js +14 -0
- package/dist/lib/codex-manager/backend-settings-controller.js.map +1 -0
- package/dist/lib/codex-manager/backend-settings-entry.d.ts +20 -0
- package/dist/lib/codex-manager/backend-settings-entry.d.ts.map +1 -0
- package/dist/lib/codex-manager/backend-settings-entry.js +12 -0
- package/dist/lib/codex-manager/backend-settings-entry.js.map +1 -0
- package/dist/lib/codex-manager/backend-settings-helpers.d.ts +16 -0
- package/dist/lib/codex-manager/backend-settings-helpers.d.ts.map +1 -0
- package/dist/lib/codex-manager/backend-settings-helpers.js +102 -0
- package/dist/lib/codex-manager/backend-settings-helpers.js.map +1 -0
- package/dist/lib/codex-manager/backend-settings-prompt.d.ts +49 -0
- package/dist/lib/codex-manager/backend-settings-prompt.d.ts.map +1 -0
- package/dist/lib/codex-manager/backend-settings-prompt.js +121 -0
- package/dist/lib/codex-manager/backend-settings-prompt.js.map +1 -0
- package/dist/lib/codex-manager/backend-settings-schema.d.ts +55 -0
- package/dist/lib/codex-manager/backend-settings-schema.d.ts.map +1 -0
- package/dist/lib/codex-manager/backend-settings-schema.js +264 -0
- package/dist/lib/codex-manager/backend-settings-schema.js.map +1 -0
- package/dist/lib/codex-manager/behavior-settings-panel.d.ts +33 -0
- package/dist/lib/codex-manager/behavior-settings-panel.d.ts.map +1 -0
- package/dist/lib/codex-manager/behavior-settings-panel.js +180 -0
- package/dist/lib/codex-manager/behavior-settings-panel.js.map +1 -0
- package/dist/lib/codex-manager/commands/best.d.ts +81 -0
- package/dist/lib/codex-manager/commands/best.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/best.js +223 -0
- package/dist/lib/codex-manager/commands/best.js.map +1 -0
- package/dist/lib/codex-manager/commands/check.d.ts +7 -0
- package/dist/lib/codex-manager/commands/check.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/check.js +5 -0
- package/dist/lib/codex-manager/commands/check.js.map +1 -0
- package/dist/lib/codex-manager/commands/config-explain.d.ts +7 -0
- package/dist/lib/codex-manager/commands/config-explain.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/config-explain.js +31 -0
- package/dist/lib/codex-manager/commands/config-explain.js.map +1 -0
- package/dist/lib/codex-manager/commands/debug-bundle.d.ts +28 -0
- package/dist/lib/codex-manager/commands/debug-bundle.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/debug-bundle.js +62 -0
- package/dist/lib/codex-manager/commands/debug-bundle.js.map +1 -0
- package/dist/lib/codex-manager/commands/doctor.d.ts +85 -0
- package/dist/lib/codex-manager/commands/doctor.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/doctor.js +424 -0
- package/dist/lib/codex-manager/commands/doctor.js.map +1 -0
- package/dist/lib/codex-manager/commands/fix.d.ts +92 -0
- package/dist/lib/codex-manager/commands/fix.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/fix.js +347 -0
- package/dist/lib/codex-manager/commands/fix.js.map +1 -0
- package/dist/lib/codex-manager/commands/forecast.d.ts +71 -0
- package/dist/lib/codex-manager/commands/forecast.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/forecast.js +371 -0
- package/dist/lib/codex-manager/commands/forecast.js.map +1 -0
- package/dist/lib/codex-manager/commands/init-config.d.ts +15 -0
- package/dist/lib/codex-manager/commands/init-config.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/init-config.js +95 -0
- package/dist/lib/codex-manager/commands/init-config.js.map +1 -0
- package/dist/lib/codex-manager/commands/report.d.ts +25 -0
- package/dist/lib/codex-manager/commands/report.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/report.js +399 -0
- package/dist/lib/codex-manager/commands/report.js.map +1 -0
- package/dist/lib/codex-manager/commands/status.d.ts +23 -0
- package/dist/lib/codex-manager/commands/status.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/status.js +50 -0
- package/dist/lib/codex-manager/commands/status.js.map +1 -0
- package/dist/lib/codex-manager/commands/switch.d.ts +22 -0
- package/dist/lib/codex-manager/commands/switch.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/switch.js +41 -0
- package/dist/lib/codex-manager/commands/switch.js.map +1 -0
- package/dist/lib/codex-manager/commands/verify-flagged.d.ts +69 -0
- package/dist/lib/codex-manager/commands/verify-flagged.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/verify-flagged.js +251 -0
- package/dist/lib/codex-manager/commands/verify-flagged.js.map +1 -0
- package/dist/lib/codex-manager/dashboard-display-panel.d.ts +40 -0
- package/dist/lib/codex-manager/dashboard-display-panel.d.ts.map +1 -0
- package/dist/lib/codex-manager/dashboard-display-panel.js +187 -0
- package/dist/lib/codex-manager/dashboard-display-panel.js.map +1 -0
- package/dist/lib/codex-manager/dashboard-formatters.d.ts +6 -0
- package/dist/lib/codex-manager/dashboard-formatters.d.ts.map +1 -0
- package/dist/lib/codex-manager/dashboard-formatters.js +19 -0
- package/dist/lib/codex-manager/dashboard-formatters.js.map +1 -0
- package/dist/lib/codex-manager/dashboard-settings-controller.d.ts +12 -0
- package/dist/lib/codex-manager/dashboard-settings-controller.d.ts.map +1 -0
- package/dist/lib/codex-manager/dashboard-settings-controller.js +17 -0
- package/dist/lib/codex-manager/dashboard-settings-controller.js.map +1 -0
- package/dist/lib/codex-manager/dashboard-settings-data.d.ts +10 -0
- package/dist/lib/codex-manager/dashboard-settings-data.d.ts.map +1 -0
- package/dist/lib/codex-manager/dashboard-settings-data.js +95 -0
- package/dist/lib/codex-manager/dashboard-settings-data.js.map +1 -0
- package/dist/lib/codex-manager/dashboard-settings-entry.d.ts +22 -0
- package/dist/lib/codex-manager/dashboard-settings-entry.d.ts.map +1 -0
- package/dist/lib/codex-manager/dashboard-settings-entry.js +13 -0
- package/dist/lib/codex-manager/dashboard-settings-entry.js.map +1 -0
- package/dist/lib/codex-manager/experimental-settings-entry.d.ts +7 -0
- package/dist/lib/codex-manager/experimental-settings-entry.d.ts.map +1 -0
- package/dist/lib/codex-manager/experimental-settings-entry.js +30 -0
- package/dist/lib/codex-manager/experimental-settings-entry.js.map +1 -0
- package/dist/lib/codex-manager/experimental-settings-prompt.d.ts +66 -0
- package/dist/lib/codex-manager/experimental-settings-prompt.d.ts.map +1 -0
- package/dist/lib/codex-manager/experimental-settings-prompt.js +221 -0
- package/dist/lib/codex-manager/experimental-settings-prompt.js.map +1 -0
- package/dist/lib/codex-manager/experimental-settings-schema.d.ts +23 -0
- package/dist/lib/codex-manager/experimental-settings-schema.d.ts.map +1 -0
- package/dist/lib/codex-manager/experimental-settings-schema.js +34 -0
- package/dist/lib/codex-manager/experimental-settings-schema.js.map +1 -0
- package/dist/lib/codex-manager/experimental-sync-target-entry.d.ts +30 -0
- package/dist/lib/codex-manager/experimental-sync-target-entry.d.ts.map +1 -0
- package/dist/lib/codex-manager/experimental-sync-target-entry.js +16 -0
- package/dist/lib/codex-manager/experimental-sync-target-entry.js.map +1 -0
- package/dist/lib/codex-manager/experimental-sync-target.d.ts +23 -0
- package/dist/lib/codex-manager/experimental-sync-target.d.ts.map +1 -0
- package/dist/lib/codex-manager/experimental-sync-target.js +39 -0
- package/dist/lib/codex-manager/experimental-sync-target.js.map +1 -0
- package/dist/lib/codex-manager/forecast-report-commands.d.ts +54 -0
- package/dist/lib/codex-manager/forecast-report-commands.d.ts.map +1 -0
- package/dist/lib/codex-manager/forecast-report-commands.js +443 -0
- package/dist/lib/codex-manager/forecast-report-commands.js.map +1 -0
- package/dist/lib/codex-manager/help.d.ts +36 -0
- package/dist/lib/codex-manager/help.d.ts.map +1 -0
- package/dist/lib/codex-manager/help.js +125 -0
- package/dist/lib/codex-manager/help.js.map +1 -0
- package/dist/lib/codex-manager/repair-commands.d.ts +70 -0
- package/dist/lib/codex-manager/repair-commands.d.ts.map +1 -0
- package/dist/lib/codex-manager/repair-commands.js +1671 -0
- package/dist/lib/codex-manager/repair-commands.js.map +1 -0
- package/dist/lib/codex-manager/settings-hub-entry.d.ts +30 -0
- package/dist/lib/codex-manager/settings-hub-entry.d.ts.map +1 -0
- package/dist/lib/codex-manager/settings-hub-entry.js +11 -0
- package/dist/lib/codex-manager/settings-hub-entry.js.map +1 -0
- package/dist/lib/codex-manager/settings-hub-menu.d.ts +30 -0
- package/dist/lib/codex-manager/settings-hub-menu.d.ts.map +1 -0
- package/dist/lib/codex-manager/settings-hub-menu.js +37 -0
- package/dist/lib/codex-manager/settings-hub-menu.js.map +1 -0
- package/dist/lib/codex-manager/settings-hub-prompt.d.ts +25 -0
- package/dist/lib/codex-manager/settings-hub-prompt.d.ts.map +1 -0
- package/dist/lib/codex-manager/settings-hub-prompt.js +23 -0
- package/dist/lib/codex-manager/settings-hub-prompt.js.map +1 -0
- package/dist/lib/codex-manager/settings-hub.d.ts +10 -29
- package/dist/lib/codex-manager/settings-hub.d.ts.map +1 -1
- package/dist/lib/codex-manager/settings-hub.js +260 -2168
- package/dist/lib/codex-manager/settings-hub.js.map +1 -1
- package/dist/lib/codex-manager/settings-panels.d.ts +56 -0
- package/dist/lib/codex-manager/settings-panels.d.ts.map +1 -0
- package/dist/lib/codex-manager/settings-panels.js +73 -0
- package/dist/lib/codex-manager/settings-panels.js.map +1 -0
- package/dist/lib/codex-manager/settings-persist-utils.d.ts +9 -0
- package/dist/lib/codex-manager/settings-persist-utils.d.ts.map +1 -0
- package/dist/lib/codex-manager/settings-persist-utils.js +33 -0
- package/dist/lib/codex-manager/settings-persist-utils.js.map +1 -0
- package/dist/lib/codex-manager/settings-preview.d.ts +12 -0
- package/dist/lib/codex-manager/settings-preview.d.ts.map +1 -0
- package/dist/lib/codex-manager/settings-preview.js +118 -0
- package/dist/lib/codex-manager/settings-preview.js.map +1 -0
- package/dist/lib/codex-manager/settings-write-queue.d.ts +14 -0
- package/dist/lib/codex-manager/settings-write-queue.d.ts.map +1 -0
- package/dist/lib/codex-manager/settings-write-queue.js +88 -0
- package/dist/lib/codex-manager/settings-write-queue.js.map +1 -0
- package/dist/lib/codex-manager/statusline-order.d.ts +3 -0
- package/dist/lib/codex-manager/statusline-order.d.ts.map +1 -0
- package/dist/lib/codex-manager/statusline-order.js +17 -0
- package/dist/lib/codex-manager/statusline-order.js.map +1 -0
- package/dist/lib/codex-manager/statusline-settings-panel.d.ts +40 -0
- package/dist/lib/codex-manager/statusline-settings-panel.d.ts.map +1 -0
- package/dist/lib/codex-manager/statusline-settings-panel.js +167 -0
- package/dist/lib/codex-manager/statusline-settings-panel.js.map +1 -0
- package/dist/lib/codex-manager/theme-settings-panel.d.ts +26 -0
- package/dist/lib/codex-manager/theme-settings-panel.d.ts.map +1 -0
- package/dist/lib/codex-manager/theme-settings-panel.js +131 -0
- package/dist/lib/codex-manager/theme-settings-panel.js.map +1 -0
- package/dist/lib/codex-manager/unified-settings-controller.d.ts +27 -0
- package/dist/lib/codex-manager/unified-settings-controller.d.ts.map +1 -0
- package/dist/lib/codex-manager/unified-settings-controller.js +50 -0
- package/dist/lib/codex-manager/unified-settings-controller.js.map +1 -0
- package/dist/lib/codex-manager/unified-settings-entry.d.ts +6 -0
- package/dist/lib/codex-manager/unified-settings-entry.d.ts.map +1 -0
- package/dist/lib/codex-manager/unified-settings-entry.js +23 -0
- package/dist/lib/codex-manager/unified-settings-entry.js.map +1 -0
- package/dist/lib/codex-manager.d.ts.map +1 -1
- package/dist/lib/codex-manager.js +441 -2199
- package/dist/lib/codex-manager.js.map +1 -1
- package/dist/lib/config.d.ts +38 -0
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +371 -9
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/errors.d.ts +9 -0
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +13 -0
- package/dist/lib/errors.js.map +1 -1
- package/dist/lib/forecast.d.ts +17 -0
- package/dist/lib/forecast.d.ts.map +1 -1
- package/dist/lib/forecast.js +33 -6
- package/dist/lib/forecast.js.map +1 -1
- package/dist/lib/health.d.ts +1 -0
- package/dist/lib/health.d.ts.map +1 -1
- package/dist/lib/health.js +6 -2
- package/dist/lib/health.js.map +1 -1
- package/dist/lib/named-backup-export.js +2 -2
- package/dist/lib/named-backup-export.js.map +1 -1
- package/dist/lib/parallel-probe.d.ts +1 -1
- package/dist/lib/parallel-probe.d.ts.map +1 -1
- package/dist/lib/parallel-probe.js +5 -2
- package/dist/lib/parallel-probe.js.map +1 -1
- package/dist/lib/proactive-refresh.d.ts +1 -1
- package/dist/lib/proactive-refresh.d.ts.map +1 -1
- package/dist/lib/proactive-refresh.js +14 -5
- package/dist/lib/proactive-refresh.js.map +1 -1
- package/dist/lib/prompts/codex.d.ts +8 -3
- package/dist/lib/prompts/codex.d.ts.map +1 -1
- package/dist/lib/prompts/codex.js +16 -26
- package/dist/lib/prompts/codex.js.map +1 -1
- package/dist/lib/refresh-guardian.d.ts +3 -0
- package/dist/lib/refresh-guardian.d.ts.map +1 -1
- package/dist/lib/refresh-guardian.js +142 -52
- package/dist/lib/refresh-guardian.js.map +1 -1
- package/dist/lib/request/failover-config.d.ts +4 -0
- package/dist/lib/request/failover-config.d.ts.map +1 -0
- package/dist/lib/request/failover-config.js +15 -0
- package/dist/lib/request/failover-config.js.map +1 -0
- package/dist/lib/request/fetch-helpers.d.ts +10 -4
- package/dist/lib/request/fetch-helpers.d.ts.map +1 -1
- package/dist/lib/request/fetch-helpers.js +77 -21
- package/dist/lib/request/fetch-helpers.js.map +1 -1
- package/dist/lib/request/helpers/model-map.d.ts +49 -12
- package/dist/lib/request/helpers/model-map.d.ts.map +1 -1
- package/dist/lib/request/helpers/model-map.js +303 -108
- package/dist/lib/request/helpers/model-map.js.map +1 -1
- package/dist/lib/request/helpers/tool-utils.d.ts +2 -15
- package/dist/lib/request/helpers/tool-utils.d.ts.map +1 -1
- package/dist/lib/request/helpers/tool-utils.js +40 -27
- package/dist/lib/request/helpers/tool-utils.js.map +1 -1
- package/dist/lib/request/index.d.ts +5 -0
- package/dist/lib/request/index.d.ts.map +1 -0
- package/dist/lib/request/index.js +5 -0
- package/dist/lib/request/index.js.map +1 -0
- package/dist/lib/request/request-init.d.ts +3 -0
- package/dist/lib/request/request-init.d.ts.map +1 -0
- package/dist/lib/request/request-init.js +50 -0
- package/dist/lib/request/request-init.js.map +1 -0
- package/dist/lib/request/request-transformer.d.ts +19 -6
- package/dist/lib/request/request-transformer.d.ts.map +1 -1
- package/dist/lib/request/request-transformer.js +210 -193
- package/dist/lib/request/request-transformer.js.map +1 -1
- package/dist/lib/request/response-compaction.d.ts +20 -0
- package/dist/lib/request/response-compaction.d.ts.map +1 -0
- package/dist/lib/request/response-compaction.js +124 -0
- package/dist/lib/request/response-compaction.js.map +1 -0
- package/dist/lib/request/response-handler.d.ts +2 -0
- package/dist/lib/request/response-handler.d.ts.map +1 -1
- package/dist/lib/request/response-handler.js +567 -11
- package/dist/lib/request/response-handler.js.map +1 -1
- package/dist/lib/request/response-metadata.d.ts +3 -0
- package/dist/lib/request/response-metadata.d.ts.map +1 -0
- package/dist/lib/request/response-metadata.js +61 -0
- package/dist/lib/request/response-metadata.js.map +1 -0
- package/dist/lib/request/wait-utils.d.ts +14 -0
- package/dist/lib/request/wait-utils.d.ts.map +1 -0
- package/dist/lib/request/wait-utils.js +44 -0
- package/dist/lib/request/wait-utils.js.map +1 -0
- package/dist/lib/rotation.d.ts +14 -11
- package/dist/lib/rotation.d.ts.map +1 -1
- package/dist/lib/rotation.js +36 -30
- package/dist/lib/rotation.js.map +1 -1
- package/dist/lib/runtime/account-check-helpers.d.ts +8 -0
- package/dist/lib/runtime/account-check-helpers.d.ts.map +1 -0
- package/dist/lib/runtime/account-check-helpers.js +30 -0
- package/dist/lib/runtime/account-check-helpers.js.map +1 -0
- package/dist/lib/runtime/account-check-types.d.ts +18 -0
- package/dist/lib/runtime/account-check-types.d.ts.map +1 -0
- package/dist/lib/runtime/account-check-types.js +12 -0
- package/dist/lib/runtime/account-check-types.js.map +1 -0
- package/dist/lib/runtime/account-check.d.ts +48 -0
- package/dist/lib/runtime/account-check.d.ts.map +1 -0
- package/dist/lib/runtime/account-check.js +202 -0
- package/dist/lib/runtime/account-check.js.map +1 -0
- package/dist/lib/runtime/account-health-check.d.ts +8 -0
- package/dist/lib/runtime/account-health-check.d.ts.map +1 -0
- package/dist/lib/runtime/account-health-check.js +30 -0
- package/dist/lib/runtime/account-health-check.js.map +1 -0
- package/dist/lib/runtime/account-manager-cache-entry.d.ts +25 -0
- package/dist/lib/runtime/account-manager-cache-entry.d.ts.map +1 -0
- package/dist/lib/runtime/account-manager-cache-entry.js +17 -0
- package/dist/lib/runtime/account-manager-cache-entry.js.map +1 -0
- package/dist/lib/runtime/account-manager-cache.d.ts +25 -0
- package/dist/lib/runtime/account-manager-cache.d.ts.map +1 -0
- package/dist/lib/runtime/account-manager-cache.js +44 -0
- package/dist/lib/runtime/account-manager-cache.js.map +1 -0
- package/dist/lib/runtime/account-pool.d.ts +23 -0
- package/dist/lib/runtime/account-pool.d.ts.map +1 -0
- package/dist/lib/runtime/account-pool.js +138 -0
- package/dist/lib/runtime/account-pool.js.map +1 -0
- package/dist/lib/runtime/account-scope.d.ts +10 -0
- package/dist/lib/runtime/account-scope.d.ts.map +1 -0
- package/dist/lib/runtime/account-scope.js +13 -0
- package/dist/lib/runtime/account-scope.js.map +1 -0
- package/dist/lib/runtime/account-select-event.d.ts +19 -0
- package/dist/lib/runtime/account-select-event.d.ts.map +1 -0
- package/dist/lib/runtime/account-select-event.js +53 -0
- package/dist/lib/runtime/account-select-event.js.map +1 -0
- package/dist/lib/runtime/account-selection.d.ts +28 -0
- package/dist/lib/runtime/account-selection.d.ts.map +1 -0
- package/dist/lib/runtime/account-selection.js +46 -0
- package/dist/lib/runtime/account-selection.js.map +1 -0
- package/dist/lib/runtime/account-state.d.ts +13 -0
- package/dist/lib/runtime/account-state.d.ts.map +1 -0
- package/dist/lib/runtime/account-state.js +38 -0
- package/dist/lib/runtime/account-state.js.map +1 -0
- package/dist/lib/runtime/account-status.d.ts +13 -0
- package/dist/lib/runtime/account-status.d.ts.map +1 -0
- package/dist/lib/runtime/account-status.js +37 -0
- package/dist/lib/runtime/account-status.js.map +1 -0
- package/dist/lib/runtime/account-storage-scope-entry.d.ts +26 -0
- package/dist/lib/runtime/account-storage-scope-entry.d.ts.map +1 -0
- package/dist/lib/runtime/account-storage-scope-entry.js +15 -0
- package/dist/lib/runtime/account-storage-scope-entry.js.map +1 -0
- package/dist/lib/runtime/auth-facade.d.ts +51 -0
- package/dist/lib/runtime/auth-facade.d.ts.map +1 -0
- package/dist/lib/runtime/auth-facade.js +48 -0
- package/dist/lib/runtime/auth-facade.js.map +1 -0
- package/dist/lib/runtime/browser-oauth-flow.d.ts +32 -0
- package/dist/lib/runtime/browser-oauth-flow.d.ts.map +1 -0
- package/dist/lib/runtime/browser-oauth-flow.js +31 -0
- package/dist/lib/runtime/browser-oauth-flow.js.map +1 -0
- package/dist/lib/runtime/capability-boost.d.ts +25 -0
- package/dist/lib/runtime/capability-boost.d.ts.map +1 -0
- package/dist/lib/runtime/capability-boost.js +26 -0
- package/dist/lib/runtime/capability-boost.js.map +1 -0
- package/dist/lib/runtime/event-handler.d.ts +53 -0
- package/dist/lib/runtime/event-handler.d.ts.map +1 -0
- package/dist/lib/runtime/event-handler.js +46 -0
- package/dist/lib/runtime/event-handler.js.map +1 -0
- package/dist/lib/runtime/flagged-verify-types.d.ts +9 -0
- package/dist/lib/runtime/flagged-verify-types.d.ts.map +1 -0
- package/dist/lib/runtime/flagged-verify-types.js +7 -0
- package/dist/lib/runtime/flagged-verify-types.js.map +1 -0
- package/dist/lib/runtime/hydrate-emails.d.ts +13 -0
- package/dist/lib/runtime/hydrate-emails.d.ts.map +1 -0
- package/dist/lib/runtime/hydrate-emails.js +56 -0
- package/dist/lib/runtime/hydrate-emails.js.map +1 -0
- package/dist/lib/runtime/live-sync-entry.d.ts +36 -0
- package/dist/lib/runtime/live-sync-entry.d.ts.map +1 -0
- package/dist/lib/runtime/live-sync-entry.js +14 -0
- package/dist/lib/runtime/live-sync-entry.js.map +1 -0
- package/dist/lib/runtime/live-sync.d.ts +35 -0
- package/dist/lib/runtime/live-sync.d.ts.map +1 -0
- package/dist/lib/runtime/live-sync.js +65 -0
- package/dist/lib/runtime/live-sync.js.map +1 -0
- package/dist/lib/runtime/loader-setup.d.ts +9 -0
- package/dist/lib/runtime/loader-setup.d.ts.map +1 -0
- package/dist/lib/runtime/loader-setup.js +8 -0
- package/dist/lib/runtime/loader-setup.js.map +1 -0
- package/dist/lib/runtime/login-menu-accounts.d.ts +29 -0
- package/dist/lib/runtime/login-menu-accounts.d.ts.map +1 -0
- package/dist/lib/runtime/login-menu-accounts.js +33 -0
- package/dist/lib/runtime/login-menu-accounts.js.map +1 -0
- package/dist/lib/runtime/manual-oauth-flow.d.ts +40 -0
- package/dist/lib/runtime/manual-oauth-flow.d.ts.map +1 -0
- package/dist/lib/runtime/manual-oauth-flow.js +71 -0
- package/dist/lib/runtime/manual-oauth-flow.js.map +1 -0
- package/dist/lib/runtime/metrics.d.ts +29 -0
- package/dist/lib/runtime/metrics.d.ts.map +1 -0
- package/dist/lib/runtime/metrics.js +97 -0
- package/dist/lib/runtime/metrics.js.map +1 -0
- package/dist/lib/runtime/oauth-browser-flow.d.ts +9 -0
- package/dist/lib/runtime/oauth-browser-flow.d.ts.map +1 -0
- package/dist/lib/runtime/oauth-browser-flow.js +34 -0
- package/dist/lib/runtime/oauth-browser-flow.js.map +1 -0
- package/dist/lib/runtime/preemptive-quota.d.ts +13 -0
- package/dist/lib/runtime/preemptive-quota.d.ts.map +1 -0
- package/dist/lib/runtime/preemptive-quota.js +9 -0
- package/dist/lib/runtime/preemptive-quota.js.map +1 -0
- package/dist/lib/runtime/quota-headers.d.ts +12 -0
- package/dist/lib/runtime/quota-headers.d.ts.map +1 -0
- package/dist/lib/runtime/quota-headers.js +131 -0
- package/dist/lib/runtime/quota-headers.js.map +1 -0
- package/dist/lib/runtime/quota-probe.d.ts +18 -0
- package/dist/lib/runtime/quota-probe.d.ts.map +1 -0
- package/dist/lib/runtime/quota-probe.js +82 -0
- package/dist/lib/runtime/quota-probe.js.map +1 -0
- package/dist/lib/runtime/quota-settings.d.ts +14 -0
- package/dist/lib/runtime/quota-settings.d.ts.map +1 -0
- package/dist/lib/runtime/quota-settings.js +12 -0
- package/dist/lib/runtime/quota-settings.js.map +1 -0
- package/dist/lib/runtime/refresh-guardian-entry.d.ts +32 -0
- package/dist/lib/runtime/refresh-guardian-entry.d.ts.map +1 -0
- package/dist/lib/runtime/refresh-guardian-entry.js +12 -0
- package/dist/lib/runtime/refresh-guardian-entry.js.map +1 -0
- package/dist/lib/runtime/refresh-guardian.d.ts +24 -0
- package/dist/lib/runtime/refresh-guardian.d.ts.map +1 -0
- package/dist/lib/runtime/refresh-guardian.js +32 -0
- package/dist/lib/runtime/refresh-guardian.js.map +1 -0
- package/dist/lib/runtime/request-init.d.ts +5 -0
- package/dist/lib/runtime/request-init.d.ts.map +1 -0
- package/dist/lib/runtime/request-init.js +50 -0
- package/dist/lib/runtime/request-init.js.map +1 -0
- package/dist/lib/runtime/runtime-services.d.ts +58 -0
- package/dist/lib/runtime/runtime-services.d.ts.map +1 -0
- package/dist/lib/runtime/runtime-services.js +87 -0
- package/dist/lib/runtime/runtime-services.js.map +1 -0
- package/dist/lib/runtime/session-affinity-entry.d.ts +30 -0
- package/dist/lib/runtime/session-affinity-entry.d.ts.map +1 -0
- package/dist/lib/runtime/session-affinity-entry.js +11 -0
- package/dist/lib/runtime/session-affinity-entry.js.map +1 -0
- package/dist/lib/runtime/session-affinity.d.ts +13 -0
- package/dist/lib/runtime/session-affinity.d.ts.map +1 -0
- package/dist/lib/runtime/session-affinity.js +17 -0
- package/dist/lib/runtime/session-affinity.js.map +1 -0
- package/dist/lib/runtime/session-recovery.d.ts +8 -0
- package/dist/lib/runtime/session-recovery.d.ts.map +1 -0
- package/dist/lib/runtime/session-recovery.js +7 -0
- package/dist/lib/runtime/session-recovery.js.map +1 -0
- package/dist/lib/runtime/status-marker.d.ts +3 -0
- package/dist/lib/runtime/status-marker.d.ts.map +1 -0
- package/dist/lib/runtime/status-marker.js +15 -0
- package/dist/lib/runtime/status-marker.js.map +1 -0
- package/dist/lib/runtime/storage-scope.d.ts +13 -0
- package/dist/lib/runtime/storage-scope.d.ts.map +1 -0
- package/dist/lib/runtime/storage-scope.js +14 -0
- package/dist/lib/runtime/storage-scope.js.map +1 -0
- package/dist/lib/runtime/toast.d.ts +16 -0
- package/dist/lib/runtime/toast.d.ts.map +1 -0
- package/dist/lib/runtime/toast.js +16 -0
- package/dist/lib/runtime/toast.js.map +1 -0
- package/dist/lib/runtime/ui-runtime-entry.d.ts +7 -0
- package/dist/lib/runtime/ui-runtime-entry.d.ts.map +1 -0
- package/dist/lib/runtime/ui-runtime-entry.js +4 -0
- package/dist/lib/runtime/ui-runtime-entry.js.map +1 -0
- package/dist/lib/runtime/ui-runtime.d.ts +9 -0
- package/dist/lib/runtime/ui-runtime.d.ts.map +1 -0
- package/dist/lib/runtime/ui-runtime.js +23 -0
- package/dist/lib/runtime/ui-runtime.js.map +1 -0
- package/dist/lib/runtime/verify-flagged.d.ts +44 -0
- package/dist/lib/runtime/verify-flagged.d.ts.map +1 -0
- package/dist/lib/runtime/verify-flagged.js +84 -0
- package/dist/lib/runtime/verify-flagged.js.map +1 -0
- package/dist/lib/schemas.d.ts +2 -0
- package/dist/lib/schemas.d.ts.map +1 -1
- package/dist/lib/schemas.js +2 -0
- package/dist/lib/schemas.js.map +1 -1
- package/dist/lib/session-affinity.d.ts +10 -0
- package/dist/lib/session-affinity.d.ts.map +1 -1
- package/dist/lib/session-affinity.js +53 -6
- package/dist/lib/session-affinity.js.map +1 -1
- package/dist/lib/storage/account-clear-entry.d.ts +16 -0
- package/dist/lib/storage/account-clear-entry.d.ts.map +1 -0
- package/dist/lib/storage/account-clear-entry.js +12 -0
- package/dist/lib/storage/account-clear-entry.js.map +1 -0
- package/dist/lib/storage/account-clear.d.ts +8 -0
- package/dist/lib/storage/account-clear.d.ts.map +1 -0
- package/dist/lib/storage/account-clear.js +29 -0
- package/dist/lib/storage/account-clear.js.map +1 -0
- package/dist/lib/storage/account-match-utils.d.ts +9 -0
- package/dist/lib/storage/account-match-utils.d.ts.map +1 -0
- package/dist/lib/storage/account-match-utils.js +45 -0
- package/dist/lib/storage/account-match-utils.js.map +1 -0
- package/dist/lib/storage/account-persistence.d.ts +3 -0
- package/dist/lib/storage/account-persistence.d.ts.map +1 -0
- package/dist/lib/storage/account-persistence.js +12 -0
- package/dist/lib/storage/account-persistence.js.map +1 -0
- package/dist/lib/storage/account-port.d.ts +50 -0
- package/dist/lib/storage/account-port.d.ts.map +1 -0
- package/dist/lib/storage/account-port.js +43 -0
- package/dist/lib/storage/account-port.js.map +1 -0
- package/dist/lib/storage/account-save-entry.d.ts +7 -0
- package/dist/lib/storage/account-save-entry.d.ts.map +1 -0
- package/dist/lib/storage/account-save-entry.js +6 -0
- package/dist/lib/storage/account-save-entry.js.map +1 -0
- package/dist/lib/storage/account-save.d.ts +30 -0
- package/dist/lib/storage/account-save.d.ts.map +1 -0
- package/dist/lib/storage/account-save.js +49 -0
- package/dist/lib/storage/account-save.js.map +1 -0
- package/dist/lib/storage/account-snapshot.d.ts +25 -0
- package/dist/lib/storage/account-snapshot.d.ts.map +1 -0
- package/dist/lib/storage/account-snapshot.js +78 -0
- package/dist/lib/storage/account-snapshot.js.map +1 -0
- package/dist/lib/storage/backup-metadata-builder.d.ts +32 -0
- package/dist/lib/storage/backup-metadata-builder.d.ts.map +1 -0
- package/dist/lib/storage/backup-metadata-builder.js +77 -0
- package/dist/lib/storage/backup-metadata-builder.js.map +1 -0
- package/dist/lib/storage/backup-metadata.d.ts +29 -0
- package/dist/lib/storage/backup-metadata.d.ts.map +1 -0
- package/dist/lib/storage/backup-metadata.js +16 -0
- package/dist/lib/storage/backup-metadata.js.map +1 -0
- package/dist/lib/storage/backup-paths.d.ts +10 -0
- package/dist/lib/storage/backup-paths.d.ts.map +1 -0
- package/dist/lib/storage/backup-paths.js +27 -0
- package/dist/lib/storage/backup-paths.js.map +1 -0
- package/dist/lib/storage/backup-restore.d.ts +11 -0
- package/dist/lib/storage/backup-restore.d.ts.map +1 -0
- package/dist/lib/storage/backup-restore.js +52 -0
- package/dist/lib/storage/backup-restore.js.map +1 -0
- package/dist/lib/storage/cache-artifacts.d.ts +2 -0
- package/dist/lib/storage/cache-artifacts.d.ts.map +1 -0
- package/dist/lib/storage/cache-artifacts.js +4 -0
- package/dist/lib/storage/cache-artifacts.js.map +1 -0
- package/dist/lib/storage/error-hints.d.ts +10 -0
- package/dist/lib/storage/error-hints.d.ts.map +1 -0
- package/dist/lib/storage/error-hints.js +36 -0
- package/dist/lib/storage/error-hints.js.map +1 -0
- package/dist/lib/storage/file-paths.d.ts +6 -0
- package/dist/lib/storage/file-paths.d.ts.map +1 -0
- package/dist/lib/storage/file-paths.js +17 -0
- package/dist/lib/storage/file-paths.js.map +1 -0
- package/dist/lib/storage/fixture-guards.d.ts +4 -0
- package/dist/lib/storage/fixture-guards.d.ts.map +1 -0
- package/dist/lib/storage/fixture-guards.js +27 -0
- package/dist/lib/storage/fixture-guards.js.map +1 -0
- package/dist/lib/storage/flagged-entry.d.ts +15 -0
- package/dist/lib/storage/flagged-entry.d.ts.map +1 -0
- package/dist/lib/storage/flagged-entry.js +12 -0
- package/dist/lib/storage/flagged-entry.js.map +1 -0
- package/dist/lib/storage/flagged-load-entry.d.ts +20 -0
- package/dist/lib/storage/flagged-load-entry.d.ts.map +1 -0
- package/dist/lib/storage/flagged-load-entry.js +13 -0
- package/dist/lib/storage/flagged-load-entry.js.map +1 -0
- package/dist/lib/storage/flagged-save-entry.d.ts +7 -0
- package/dist/lib/storage/flagged-save-entry.d.ts.map +1 -0
- package/dist/lib/storage/flagged-save-entry.js +6 -0
- package/dist/lib/storage/flagged-save-entry.js.map +1 -0
- package/dist/lib/storage/flagged-storage-file.d.ts +7 -0
- package/dist/lib/storage/flagged-storage-file.d.ts.map +1 -0
- package/dist/lib/storage/flagged-storage-file.js +25 -0
- package/dist/lib/storage/flagged-storage-file.js.map +1 -0
- package/dist/lib/storage/flagged-storage-io.d.ts +28 -0
- package/dist/lib/storage/flagged-storage-io.d.ts.map +1 -0
- package/dist/lib/storage/flagged-storage-io.js +135 -0
- package/dist/lib/storage/flagged-storage-io.js.map +1 -0
- package/dist/lib/storage/flagged-storage.d.ts +6 -0
- package/dist/lib/storage/flagged-storage.d.ts.map +1 -0
- package/dist/lib/storage/flagged-storage.js +90 -0
- package/dist/lib/storage/flagged-storage.js.map +1 -0
- package/dist/lib/storage/gitignore.d.ts +7 -0
- package/dist/lib/storage/gitignore.d.ts.map +1 -0
- package/dist/lib/storage/gitignore.js +34 -0
- package/dist/lib/storage/gitignore.js.map +1 -0
- package/dist/lib/storage/hash.d.ts +2 -0
- package/dist/lib/storage/hash.d.ts.map +1 -0
- package/dist/lib/storage/hash.js +5 -0
- package/dist/lib/storage/hash.js.map +1 -0
- package/dist/lib/storage/identity.d.ts +21 -0
- package/dist/lib/storage/identity.d.ts.map +1 -0
- package/dist/lib/storage/identity.js +59 -0
- package/dist/lib/storage/identity.js.map +1 -0
- package/dist/lib/storage/import-export.d.ts +24 -0
- package/dist/lib/storage/import-export.d.ts.map +1 -0
- package/dist/lib/storage/import-export.js +108 -0
- package/dist/lib/storage/import-export.js.map +1 -0
- package/dist/lib/storage/metadata-section.d.ts +16 -0
- package/dist/lib/storage/metadata-section.d.ts.map +1 -0
- package/dist/lib/storage/metadata-section.js +16 -0
- package/dist/lib/storage/metadata-section.js.map +1 -0
- package/dist/lib/storage/named-backup-entry.d.ts +15 -0
- package/dist/lib/storage/named-backup-entry.d.ts.map +1 -0
- package/dist/lib/storage/named-backup-entry.js +7 -0
- package/dist/lib/storage/named-backup-entry.js.map +1 -0
- package/dist/lib/storage/named-backups-entry.d.ts +19 -0
- package/dist/lib/storage/named-backups-entry.d.ts.map +1 -0
- package/dist/lib/storage/named-backups-entry.js +7 -0
- package/dist/lib/storage/named-backups-entry.js.map +1 -0
- package/dist/lib/storage/named-backups.d.ts +15 -0
- package/dist/lib/storage/named-backups.d.ts.map +1 -0
- package/dist/lib/storage/named-backups.js +68 -0
- package/dist/lib/storage/named-backups.js.map +1 -0
- package/dist/lib/storage/path-state.d.ts +9 -0
- package/dist/lib/storage/path-state.d.ts.map +1 -0
- package/dist/lib/storage/path-state.js +20 -0
- package/dist/lib/storage/path-state.js.map +1 -0
- package/dist/lib/storage/project-migration.d.ts +10 -0
- package/dist/lib/storage/project-migration.d.ts.map +1 -0
- package/dist/lib/storage/project-migration.js +38 -0
- package/dist/lib/storage/project-migration.js.map +1 -0
- package/dist/lib/storage/record-utils.d.ts +3 -0
- package/dist/lib/storage/record-utils.d.ts.map +1 -0
- package/dist/lib/storage/record-utils.js +9 -0
- package/dist/lib/storage/record-utils.js.map +1 -0
- package/dist/lib/storage/restore-assessment.d.ts +7 -0
- package/dist/lib/storage/restore-assessment.d.ts.map +1 -0
- package/dist/lib/storage/restore-assessment.js +42 -0
- package/dist/lib/storage/restore-assessment.js.map +1 -0
- package/dist/lib/storage/restore-backup-entry.d.ts +24 -0
- package/dist/lib/storage/restore-backup-entry.d.ts.map +1 -0
- package/dist/lib/storage/restore-backup-entry.js +10 -0
- package/dist/lib/storage/restore-backup-entry.js.map +1 -0
- package/dist/lib/storage/restore-metadata.d.ts +10 -0
- package/dist/lib/storage/restore-metadata.d.ts.map +1 -0
- package/dist/lib/storage/restore-metadata.js +18 -0
- package/dist/lib/storage/restore-metadata.js.map +1 -0
- package/dist/lib/storage/restore.d.ts +14 -0
- package/dist/lib/storage/restore.d.ts.map +1 -0
- package/dist/lib/storage/restore.js +53 -0
- package/dist/lib/storage/restore.js.map +1 -0
- package/dist/lib/storage/snapshot-inspectors.d.ts +22 -0
- package/dist/lib/storage/snapshot-inspectors.d.ts.map +1 -0
- package/dist/lib/storage/snapshot-inspectors.js +95 -0
- package/dist/lib/storage/snapshot-inspectors.js.map +1 -0
- package/dist/lib/storage/storage-parser.d.ts +15 -0
- package/dist/lib/storage/storage-parser.d.ts.map +1 -0
- package/dist/lib/storage/storage-parser.js +16 -0
- package/dist/lib/storage/storage-parser.js.map +1 -0
- package/dist/lib/storage/transactions.d.ts +23 -0
- package/dist/lib/storage/transactions.d.ts.map +1 -0
- package/dist/lib/storage/transactions.js +64 -0
- package/dist/lib/storage/transactions.js.map +1 -0
- package/dist/lib/storage.d.ts +8 -47
- package/dist/lib/storage.d.ts.map +1 -1
- package/dist/lib/storage.js +482 -1044
- package/dist/lib/storage.js.map +1 -1
- package/dist/lib/types.d.ts +80 -1
- package/dist/lib/types.d.ts.map +1 -1
- package/package.json +41 -4
- package/scripts/check-pack-budget-lib.js +114 -0
- package/scripts/check-pack-budget.mjs +10 -0
- package/scripts/codex-multi-auth.js +34 -10
- package/scripts/install-codex-auth-utils.js +54 -14
- package/scripts/install-codex-auth.js +62 -33
- package/scripts/update-vendor-provenance.mjs +96 -0
- package/scripts/verify-vendor-provenance.mjs +53 -0
|
@@ -1,16 +1,515 @@
|
|
|
1
1
|
import { createLogger, logRequest, LOGGING_ENABLED } from "../logger.js";
|
|
2
2
|
import { PLUGIN_NAME } from "../constants.js";
|
|
3
|
+
import { isRecord } from "../utils.js";
|
|
3
4
|
const log = createLogger("response-handler");
|
|
4
5
|
const MAX_SSE_SIZE = 10 * 1024 * 1024; // 10MB limit to prevent memory exhaustion
|
|
5
6
|
const DEFAULT_STREAM_STALL_TIMEOUT_MS = 45_000;
|
|
7
|
+
const MAX_SYNTHESIZED_EVENT_INDEX = 255;
|
|
8
|
+
function createParsedResponseState() {
|
|
9
|
+
return {
|
|
10
|
+
finalResponse: null,
|
|
11
|
+
lastPhase: null,
|
|
12
|
+
outputItems: new Map(),
|
|
13
|
+
outputText: new Map(),
|
|
14
|
+
outputTextPhases: new Map(),
|
|
15
|
+
phaseTextSegments: new Map(),
|
|
16
|
+
phaseSegmentOrder: new Map(),
|
|
17
|
+
phaseText: new Map(),
|
|
18
|
+
reasoningSummaryText: new Map(),
|
|
19
|
+
seenResponseIds: new Set(),
|
|
20
|
+
encounteredError: false,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function toMutableRecord(value) {
|
|
24
|
+
return isRecord(value) ? { ...value } : null;
|
|
25
|
+
}
|
|
26
|
+
function getNumberField(record, key) {
|
|
27
|
+
const value = record[key];
|
|
28
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Read a trimmed, non-empty string field for identifier-like values.
|
|
32
|
+
*
|
|
33
|
+
* For textual payloads where whitespace is meaningful, use a field-specific
|
|
34
|
+
* accessor such as `getDeltaField` instead of reusing this helper.
|
|
35
|
+
*/
|
|
36
|
+
function getStringField(record, key) {
|
|
37
|
+
const value = record[key];
|
|
38
|
+
return typeof value === "string" && value.trim().length > 0 ? value : null;
|
|
39
|
+
}
|
|
40
|
+
function getDeltaField(record, key) {
|
|
41
|
+
const value = record[key];
|
|
42
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
43
|
+
}
|
|
44
|
+
function isValidSynthesizedIndex(index) {
|
|
45
|
+
return (index !== null &&
|
|
46
|
+
Number.isInteger(index) &&
|
|
47
|
+
index >= 0 &&
|
|
48
|
+
index <= MAX_SYNTHESIZED_EVENT_INDEX);
|
|
49
|
+
}
|
|
50
|
+
function cloneContentArray(content) {
|
|
51
|
+
if (!Array.isArray(content))
|
|
52
|
+
return [];
|
|
53
|
+
return content.filter(isRecord).map((part) => ({ ...part }));
|
|
54
|
+
}
|
|
55
|
+
function mergeRecord(base, update) {
|
|
56
|
+
if (!base)
|
|
57
|
+
return { ...update };
|
|
58
|
+
const merged = { ...base, ...update };
|
|
59
|
+
if ("content" in update || "content" in base) {
|
|
60
|
+
const updateContent = cloneContentArray(update.content);
|
|
61
|
+
merged.content =
|
|
62
|
+
updateContent.length > 0 || !("content" in base)
|
|
63
|
+
? updateContent
|
|
64
|
+
: cloneContentArray(base.content);
|
|
65
|
+
}
|
|
66
|
+
return merged;
|
|
67
|
+
}
|
|
68
|
+
function makeOutputTextKey(outputIndex, contentIndex) {
|
|
69
|
+
if (!isValidSynthesizedIndex(outputIndex) ||
|
|
70
|
+
!isValidSynthesizedIndex(contentIndex)) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
return `${outputIndex}:${contentIndex}`;
|
|
74
|
+
}
|
|
75
|
+
function makePhaseTextSegmentKey(phase, outputTextKey) {
|
|
76
|
+
return `${phase}\u0000${outputTextKey}`;
|
|
77
|
+
}
|
|
78
|
+
function makeSummaryKey(outputIndex, summaryIndex) {
|
|
79
|
+
if (!isValidSynthesizedIndex(outputIndex) ||
|
|
80
|
+
!isValidSynthesizedIndex(summaryIndex)) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
return `${outputIndex}:${summaryIndex}`;
|
|
84
|
+
}
|
|
85
|
+
function getPartText(part) {
|
|
86
|
+
if (!isRecord(part))
|
|
87
|
+
return null;
|
|
88
|
+
const text = getStringField(part, "text");
|
|
89
|
+
if (text)
|
|
90
|
+
return text;
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
function capturePhase(state, phase) {
|
|
94
|
+
if (typeof phase !== "string" || phase.trim().length === 0)
|
|
95
|
+
return;
|
|
96
|
+
state.lastPhase = phase.trim();
|
|
97
|
+
}
|
|
98
|
+
function rememberPhaseSegmentOrder(state, phase, segmentKey) {
|
|
99
|
+
const existingOrder = state.phaseSegmentOrder.get(phase);
|
|
100
|
+
if (existingOrder?.includes(segmentKey)) {
|
|
101
|
+
return existingOrder;
|
|
102
|
+
}
|
|
103
|
+
const nextOrder = [...(existingOrder ?? []), segmentKey];
|
|
104
|
+
state.phaseSegmentOrder.set(phase, nextOrder);
|
|
105
|
+
return nextOrder;
|
|
106
|
+
}
|
|
107
|
+
function removePhaseSegmentOrder(state, phase, segmentKey) {
|
|
108
|
+
const existingOrder = state.phaseSegmentOrder.get(phase);
|
|
109
|
+
if (!existingOrder)
|
|
110
|
+
return;
|
|
111
|
+
const nextOrder = existingOrder.filter((key) => key !== segmentKey);
|
|
112
|
+
if (nextOrder.length === 0) {
|
|
113
|
+
state.phaseSegmentOrder.delete(phase);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
state.phaseSegmentOrder.set(phase, nextOrder);
|
|
117
|
+
}
|
|
118
|
+
function rebuildPhaseText(state, phase) {
|
|
119
|
+
const orderedKeys = state.phaseSegmentOrder.get(phase) ?? [];
|
|
120
|
+
const text = orderedKeys
|
|
121
|
+
.map((key) => state.phaseTextSegments.get(key) ?? "")
|
|
122
|
+
.filter((value) => value.length > 0)
|
|
123
|
+
.join("");
|
|
124
|
+
if (text.length === 0) {
|
|
125
|
+
state.phaseText.delete(phase);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
state.phaseText.set(phase, text);
|
|
129
|
+
}
|
|
130
|
+
function setPhaseTextSegment(state, phase, outputTextKey, text) {
|
|
131
|
+
const normalizedPhase = typeof phase === "string" && phase.trim().length > 0
|
|
132
|
+
? phase.trim()
|
|
133
|
+
: state.outputTextPhases.get(outputTextKey) ?? null;
|
|
134
|
+
if (!normalizedPhase)
|
|
135
|
+
return;
|
|
136
|
+
state.outputTextPhases.set(outputTextKey, normalizedPhase);
|
|
137
|
+
state.lastPhase = normalizedPhase;
|
|
138
|
+
const segmentKey = makePhaseTextSegmentKey(normalizedPhase, outputTextKey);
|
|
139
|
+
if (!text || text.length === 0) {
|
|
140
|
+
state.phaseTextSegments.delete(segmentKey);
|
|
141
|
+
removePhaseSegmentOrder(state, normalizedPhase, segmentKey);
|
|
142
|
+
rebuildPhaseText(state, normalizedPhase);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
rememberPhaseSegmentOrder(state, normalizedPhase, segmentKey);
|
|
146
|
+
state.phaseTextSegments.set(segmentKey, text);
|
|
147
|
+
rebuildPhaseText(state, normalizedPhase);
|
|
148
|
+
}
|
|
149
|
+
function appendPhaseTextSegment(state, phase, outputTextKey, delta) {
|
|
150
|
+
if (!delta || delta.length === 0) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const normalizedPhase = typeof phase === "string" && phase.trim().length > 0
|
|
154
|
+
? phase.trim()
|
|
155
|
+
: state.outputTextPhases.get(outputTextKey) ?? null;
|
|
156
|
+
if (!normalizedPhase)
|
|
157
|
+
return;
|
|
158
|
+
state.outputTextPhases.set(outputTextKey, normalizedPhase);
|
|
159
|
+
state.lastPhase = normalizedPhase;
|
|
160
|
+
const segmentKey = makePhaseTextSegmentKey(normalizedPhase, outputTextKey);
|
|
161
|
+
const phaseOrder = rememberPhaseSegmentOrder(state, normalizedPhase, segmentKey);
|
|
162
|
+
const existing = state.phaseTextSegments.get(segmentKey) ?? "";
|
|
163
|
+
state.phaseTextSegments.set(segmentKey, `${existing}${delta}`);
|
|
164
|
+
if (phaseOrder[phaseOrder.length - 1] === segmentKey) {
|
|
165
|
+
const existingPhaseText = state.phaseText.get(normalizedPhase) ?? "";
|
|
166
|
+
state.phaseText.set(normalizedPhase, `${existingPhaseText}${delta}`);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
rebuildPhaseText(state, normalizedPhase);
|
|
170
|
+
}
|
|
171
|
+
function upsertOutputItem(state, outputIndex, item) {
|
|
172
|
+
if (!isValidSynthesizedIndex(outputIndex) || !isRecord(item))
|
|
173
|
+
return;
|
|
174
|
+
const current = state.outputItems.get(outputIndex) ?? null;
|
|
175
|
+
const merged = mergeRecord(current, item);
|
|
176
|
+
state.outputItems.set(outputIndex, merged);
|
|
177
|
+
capturePhase(state, merged.phase);
|
|
178
|
+
}
|
|
179
|
+
function setOutputTextValue(state, outputIndex, contentIndex, text, phase = undefined) {
|
|
180
|
+
const key = makeOutputTextKey(outputIndex, contentIndex);
|
|
181
|
+
if (!key)
|
|
182
|
+
return;
|
|
183
|
+
if (!text) {
|
|
184
|
+
state.outputText.delete(key);
|
|
185
|
+
setPhaseTextSegment(state, phase, key, null);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
state.outputText.set(key, text);
|
|
189
|
+
setPhaseTextSegment(state, phase, key, text);
|
|
190
|
+
}
|
|
191
|
+
function appendOutputTextValue(state, outputIndex, contentIndex, delta, phase = undefined) {
|
|
192
|
+
if (!delta)
|
|
193
|
+
return;
|
|
194
|
+
const key = makeOutputTextKey(outputIndex, contentIndex);
|
|
195
|
+
if (!key)
|
|
196
|
+
return;
|
|
197
|
+
const existing = state.outputText.get(key) ?? "";
|
|
198
|
+
state.outputText.set(key, `${existing}${delta}`);
|
|
199
|
+
appendPhaseTextSegment(state, phase, key, delta);
|
|
200
|
+
}
|
|
201
|
+
function setReasoningSummaryValue(state, outputIndex, summaryIndex, text) {
|
|
202
|
+
const key = makeSummaryKey(outputIndex, summaryIndex);
|
|
203
|
+
if (!key)
|
|
204
|
+
return;
|
|
205
|
+
if (!text) {
|
|
206
|
+
state.reasoningSummaryText.delete(key);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
state.reasoningSummaryText.set(key, text);
|
|
210
|
+
}
|
|
211
|
+
function appendReasoningSummaryValue(state, outputIndex, summaryIndex, delta) {
|
|
212
|
+
if (!delta)
|
|
213
|
+
return;
|
|
214
|
+
const key = makeSummaryKey(outputIndex, summaryIndex);
|
|
215
|
+
if (!key)
|
|
216
|
+
return;
|
|
217
|
+
const existing = state.reasoningSummaryText.get(key) ?? "";
|
|
218
|
+
state.reasoningSummaryText.set(key, `${existing}${delta}`);
|
|
219
|
+
}
|
|
220
|
+
function ensureOutputItemAtIndex(output, index) {
|
|
221
|
+
if (!isValidSynthesizedIndex(index))
|
|
222
|
+
return null;
|
|
223
|
+
while (output.length <= index) {
|
|
224
|
+
output.push({});
|
|
225
|
+
}
|
|
226
|
+
const current = output[index];
|
|
227
|
+
if (!isRecord(current)) {
|
|
228
|
+
output[index] = {};
|
|
229
|
+
}
|
|
230
|
+
return isRecord(output[index]) ? output[index] : null;
|
|
231
|
+
}
|
|
232
|
+
function ensureContentPartAtIndex(item, index) {
|
|
233
|
+
if (!isValidSynthesizedIndex(index))
|
|
234
|
+
return null;
|
|
235
|
+
const content = Array.isArray(item.content) ? [...item.content] : [];
|
|
236
|
+
while (content.length <= index) {
|
|
237
|
+
content.push({});
|
|
238
|
+
}
|
|
239
|
+
const current = content[index];
|
|
240
|
+
if (!isRecord(current)) {
|
|
241
|
+
content[index] = {};
|
|
242
|
+
}
|
|
243
|
+
item.content = content;
|
|
244
|
+
return isRecord(content[index]) ? content[index] : null;
|
|
245
|
+
}
|
|
246
|
+
function applyAccumulatedOutputText(response, state) {
|
|
247
|
+
if (state.outputText.size === 0)
|
|
248
|
+
return;
|
|
249
|
+
const output = Array.isArray(response.output) ? [...response.output] : [];
|
|
250
|
+
for (const [key, text] of state.outputText.entries()) {
|
|
251
|
+
const [outputIndexText, contentIndexText] = key.split(":");
|
|
252
|
+
const outputIndex = Number.parseInt(outputIndexText ?? "", 10);
|
|
253
|
+
const contentIndex = Number.parseInt(contentIndexText ?? "", 10);
|
|
254
|
+
if (!isValidSynthesizedIndex(outputIndex) ||
|
|
255
|
+
!isValidSynthesizedIndex(contentIndex)) {
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
const item = ensureOutputItemAtIndex(output, outputIndex);
|
|
259
|
+
if (!item)
|
|
260
|
+
continue;
|
|
261
|
+
const part = ensureContentPartAtIndex(item, contentIndex);
|
|
262
|
+
if (!part)
|
|
263
|
+
continue;
|
|
264
|
+
if (!getStringField(part, "type")) {
|
|
265
|
+
part.type = "output_text";
|
|
266
|
+
}
|
|
267
|
+
if (typeof part.text === "string") {
|
|
268
|
+
setPhaseTextSegment(state, part.phase, key, part.text);
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
part.text = text;
|
|
272
|
+
}
|
|
273
|
+
if (output.length > 0) {
|
|
274
|
+
response.output = output;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
function mergeOutputItemsIntoResponse(response, state) {
|
|
278
|
+
if (state.outputItems.size === 0)
|
|
279
|
+
return;
|
|
280
|
+
const output = Array.isArray(response.output) ? [...response.output] : [];
|
|
281
|
+
for (const [outputIndex, item] of state.outputItems.entries()) {
|
|
282
|
+
if (!isValidSynthesizedIndex(outputIndex))
|
|
283
|
+
continue;
|
|
284
|
+
while (output.length <= outputIndex) {
|
|
285
|
+
output.push({});
|
|
286
|
+
}
|
|
287
|
+
output[outputIndex] = mergeRecord(toMutableRecord(output[outputIndex]), item);
|
|
288
|
+
}
|
|
289
|
+
response.output = output;
|
|
290
|
+
}
|
|
291
|
+
function collectMessageOutputText(output) {
|
|
292
|
+
return output
|
|
293
|
+
.filter(isRecord)
|
|
294
|
+
.map((item) => {
|
|
295
|
+
if (item.type !== "message")
|
|
296
|
+
return "";
|
|
297
|
+
const content = Array.isArray(item.content) ? item.content : [];
|
|
298
|
+
return content
|
|
299
|
+
.filter(isRecord)
|
|
300
|
+
.map((part) => {
|
|
301
|
+
if (part.type !== "output_text")
|
|
302
|
+
return "";
|
|
303
|
+
return typeof part.text === "string" ? part.text : "";
|
|
304
|
+
})
|
|
305
|
+
.join("");
|
|
306
|
+
})
|
|
307
|
+
.filter((text) => text.length > 0)
|
|
308
|
+
.join("");
|
|
309
|
+
}
|
|
310
|
+
function collectReasoningSummaryText(output) {
|
|
311
|
+
return output
|
|
312
|
+
.filter(isRecord)
|
|
313
|
+
.map((item) => {
|
|
314
|
+
if (item.type !== "reasoning")
|
|
315
|
+
return "";
|
|
316
|
+
const summary = Array.isArray(item.summary) ? item.summary : [];
|
|
317
|
+
return summary
|
|
318
|
+
.filter(isRecord)
|
|
319
|
+
.map((part) => (typeof part.text === "string" ? part.text : ""))
|
|
320
|
+
.filter((text) => text.length > 0)
|
|
321
|
+
.join("\n\n");
|
|
322
|
+
})
|
|
323
|
+
.filter((text) => text.length > 0)
|
|
324
|
+
.join("\n\n");
|
|
325
|
+
}
|
|
326
|
+
function applyReasoningSummaries(response, state) {
|
|
327
|
+
if (state.reasoningSummaryText.size === 0)
|
|
328
|
+
return;
|
|
329
|
+
const output = Array.isArray(response.output) ? [...response.output] : [];
|
|
330
|
+
for (const [key, text] of state.reasoningSummaryText.entries()) {
|
|
331
|
+
const [outputIndexText, summaryIndexText] = key.split(":");
|
|
332
|
+
const outputIndex = Number.parseInt(outputIndexText ?? "", 10);
|
|
333
|
+
const summaryIndex = Number.parseInt(summaryIndexText ?? "", 10);
|
|
334
|
+
if (!isValidSynthesizedIndex(outputIndex) ||
|
|
335
|
+
!isValidSynthesizedIndex(summaryIndex)) {
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
const item = ensureOutputItemAtIndex(output, outputIndex);
|
|
339
|
+
if (!item)
|
|
340
|
+
continue;
|
|
341
|
+
const summary = Array.isArray(item.summary) ? [...item.summary] : [];
|
|
342
|
+
while (summary.length <= summaryIndex) {
|
|
343
|
+
summary.push({});
|
|
344
|
+
}
|
|
345
|
+
const current = summary[summaryIndex];
|
|
346
|
+
const nextPart = isRecord(current) ? { ...current } : {};
|
|
347
|
+
if (!getStringField(nextPart, "type")) {
|
|
348
|
+
nextPart.type = "summary_text";
|
|
349
|
+
}
|
|
350
|
+
if (typeof nextPart.text === "string") {
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
nextPart.text = text;
|
|
354
|
+
summary[summaryIndex] = nextPart;
|
|
355
|
+
item.summary = summary;
|
|
356
|
+
if (!getStringField(item, "type")) {
|
|
357
|
+
item.type = "reasoning";
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
if (output.length > 0) {
|
|
361
|
+
response.output = output;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
function finalizeParsedResponse(state) {
|
|
365
|
+
const response = state.finalResponse ? { ...state.finalResponse } : null;
|
|
366
|
+
if (!response)
|
|
367
|
+
return null;
|
|
368
|
+
if (state.encounteredError)
|
|
369
|
+
return null;
|
|
370
|
+
mergeOutputItemsIntoResponse(response, state);
|
|
371
|
+
applyAccumulatedOutputText(response, state);
|
|
372
|
+
applyReasoningSummaries(response, state);
|
|
373
|
+
const output = Array.isArray(response.output) ? response.output : [];
|
|
374
|
+
if (typeof response.output_text !== "string") {
|
|
375
|
+
const outputText = collectMessageOutputText(output);
|
|
376
|
+
if (outputText.length > 0) {
|
|
377
|
+
response.output_text = outputText;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
const reasoningSummaryText = collectReasoningSummaryText(output);
|
|
381
|
+
if (reasoningSummaryText.length > 0 &&
|
|
382
|
+
typeof response.reasoning_summary_text !== "string") {
|
|
383
|
+
response.reasoning_summary_text = reasoningSummaryText;
|
|
384
|
+
}
|
|
385
|
+
if (state.lastPhase && typeof response.phase !== "string") {
|
|
386
|
+
response.phase = state.lastPhase;
|
|
387
|
+
}
|
|
388
|
+
if (state.phaseText.size > 0) {
|
|
389
|
+
const phaseText = {};
|
|
390
|
+
for (const [phase, text] of state.phaseText.entries()) {
|
|
391
|
+
phaseText[phase] = text;
|
|
392
|
+
if (phase === "commentary")
|
|
393
|
+
response.commentary_text = text;
|
|
394
|
+
if (phase === "final_answer")
|
|
395
|
+
response.final_answer_text = text;
|
|
396
|
+
}
|
|
397
|
+
response.phase_text = phaseText;
|
|
398
|
+
}
|
|
399
|
+
return response;
|
|
400
|
+
}
|
|
401
|
+
function extractResponseId(response) {
|
|
402
|
+
if (!response || typeof response !== "object")
|
|
403
|
+
return null;
|
|
404
|
+
const candidate = response.id;
|
|
405
|
+
return typeof candidate === "string" && candidate.trim().length > 0
|
|
406
|
+
? candidate.trim()
|
|
407
|
+
: null;
|
|
408
|
+
}
|
|
409
|
+
function notifyResponseId(state, onResponseId, response) {
|
|
410
|
+
const responseId = extractResponseId(response);
|
|
411
|
+
if (!responseId || !onResponseId || state.seenResponseIds.has(responseId))
|
|
412
|
+
return;
|
|
413
|
+
state.seenResponseIds.add(responseId);
|
|
414
|
+
try {
|
|
415
|
+
onResponseId(responseId);
|
|
416
|
+
}
|
|
417
|
+
catch (error) {
|
|
418
|
+
log.warn("Failed to persist response id from upstream event", {
|
|
419
|
+
error: String(error),
|
|
420
|
+
responseId,
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
function truncateDiagnosticText(value, maxLength = 400) {
|
|
425
|
+
if (typeof value !== "string")
|
|
426
|
+
return undefined;
|
|
427
|
+
const trimmed = value.trim();
|
|
428
|
+
if (trimmed.length === 0)
|
|
429
|
+
return undefined;
|
|
430
|
+
return trimmed.length > maxLength ? `${trimmed.slice(0, maxLength)}...` : trimmed;
|
|
431
|
+
}
|
|
432
|
+
function logStreamDiagnostics(finalResponse) {
|
|
433
|
+
if (!LOGGING_ENABLED || !isRecord(finalResponse)) {
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
const responseId = extractResponseId(finalResponse);
|
|
437
|
+
const phase = getStringField(finalResponse, "phase");
|
|
438
|
+
const commentaryText = truncateDiagnosticText(finalResponse.commentary_text);
|
|
439
|
+
const finalAnswerText = truncateDiagnosticText(finalResponse.final_answer_text);
|
|
440
|
+
const reasoningSummaryText = truncateDiagnosticText(finalResponse.reasoning_summary_text);
|
|
441
|
+
if (phase || commentaryText || finalAnswerText || reasoningSummaryText) {
|
|
442
|
+
logRequest("stream-diagnostics", {
|
|
443
|
+
...(responseId ? { responseId } : {}),
|
|
444
|
+
...(phase ? { phase } : {}),
|
|
445
|
+
...(commentaryText ? { commentaryText } : {}),
|
|
446
|
+
...(finalAnswerText ? { finalAnswerText } : {}),
|
|
447
|
+
...(reasoningSummaryText ? { reasoningSummaryText } : {}),
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
function maybeCaptureResponseEvent(state, data, onResponseId) {
|
|
452
|
+
if (data.type === "error") {
|
|
453
|
+
log.error("SSE error event received", { error: data });
|
|
454
|
+
state.encounteredError = true;
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
if (data.type === "response.done" || data.type === "response.completed") {
|
|
458
|
+
if (isRecord(data.response)) {
|
|
459
|
+
state.finalResponse = { ...data.response };
|
|
460
|
+
}
|
|
461
|
+
notifyResponseId(state, onResponseId, data.response);
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
const eventRecord = toMutableRecord(data);
|
|
465
|
+
if (!eventRecord)
|
|
466
|
+
return;
|
|
467
|
+
const outputIndex = getNumberField(eventRecord, "output_index");
|
|
468
|
+
if (data.type === "response.output_item.added" || data.type === "response.output_item.done") {
|
|
469
|
+
upsertOutputItem(state, outputIndex, eventRecord.item);
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
if (data.type === "response.output_text.delta") {
|
|
473
|
+
appendOutputTextValue(state, outputIndex, getNumberField(eventRecord, "content_index"), getDeltaField(eventRecord, "delta"), eventRecord.phase);
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
if (data.type === "response.output_text.done") {
|
|
477
|
+
setOutputTextValue(state, outputIndex, getNumberField(eventRecord, "content_index"), getStringField(eventRecord, "text"), eventRecord.phase);
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
if (data.type === "response.content_part.added" || data.type === "response.content_part.done") {
|
|
481
|
+
const part = toMutableRecord(eventRecord.part);
|
|
482
|
+
if (!part || getStringField(part, "type") !== "output_text") {
|
|
483
|
+
capturePhase(state, part?.phase);
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
setOutputTextValue(state, outputIndex, getNumberField(eventRecord, "content_index"), getPartText(part), part.phase);
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
if (data.type === "response.reasoning_summary_text.delta") {
|
|
490
|
+
appendReasoningSummaryValue(state, outputIndex, getNumberField(eventRecord, "summary_index"), getDeltaField(eventRecord, "delta"));
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
if (data.type === "response.reasoning_summary_text.done") {
|
|
494
|
+
setReasoningSummaryValue(state, outputIndex, getNumberField(eventRecord, "summary_index"), getStringField(eventRecord, "text"));
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
if (data.type === "response.reasoning_summary_part.added" ||
|
|
498
|
+
data.type === "response.reasoning_summary_part.done") {
|
|
499
|
+
setReasoningSummaryValue(state, outputIndex, getNumberField(eventRecord, "summary_index"), getPartText(eventRecord.part));
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
capturePhase(state, eventRecord.phase);
|
|
503
|
+
}
|
|
6
504
|
/**
|
|
7
505
|
|
|
8
506
|
* Parse SSE stream to extract final response
|
|
9
507
|
* @param sseText - Complete SSE stream text
|
|
10
508
|
* @returns Final response object or null if not found
|
|
11
509
|
*/
|
|
12
|
-
function parseSseStream(sseText) {
|
|
510
|
+
function parseSseStream(sseText, onResponseId) {
|
|
13
511
|
const lines = sseText.split(/\r?\n/);
|
|
512
|
+
const state = createParsedResponseState();
|
|
14
513
|
for (const line of lines) {
|
|
15
514
|
const trimmedLine = line.trim();
|
|
16
515
|
if (trimmedLine.startsWith('data: ')) {
|
|
@@ -19,20 +518,16 @@ function parseSseStream(sseText) {
|
|
|
19
518
|
continue;
|
|
20
519
|
try {
|
|
21
520
|
const data = JSON.parse(payload);
|
|
22
|
-
|
|
23
|
-
|
|
521
|
+
maybeCaptureResponseEvent(state, data, onResponseId);
|
|
522
|
+
if (state.encounteredError)
|
|
24
523
|
return null;
|
|
25
|
-
}
|
|
26
|
-
if (data.type === 'response.done' || data.type === 'response.completed') {
|
|
27
|
-
return data.response;
|
|
28
|
-
}
|
|
29
524
|
}
|
|
30
525
|
catch {
|
|
31
526
|
// Skip malformed JSON
|
|
32
527
|
}
|
|
33
528
|
}
|
|
34
529
|
}
|
|
35
|
-
return
|
|
530
|
+
return finalizeParsedResponse(state);
|
|
36
531
|
}
|
|
37
532
|
/**
|
|
38
533
|
* Convert SSE stream response to JSON for generateText()
|
|
@@ -63,10 +558,12 @@ export async function convertSseToJson(response, headers, options) {
|
|
|
63
558
|
logRequest("stream-full", { fullContent: fullText });
|
|
64
559
|
}
|
|
65
560
|
// Parse SSE events to extract the final response
|
|
66
|
-
const finalResponse = parseSseStream(fullText);
|
|
561
|
+
const finalResponse = parseSseStream(fullText, options?.onResponseId);
|
|
67
562
|
if (!finalResponse) {
|
|
68
563
|
log.warn("Could not find final response in SSE stream");
|
|
69
|
-
logRequest("stream-error", {
|
|
564
|
+
logRequest("stream-error", {
|
|
565
|
+
error: "No terminal response event found in SSE stream",
|
|
566
|
+
});
|
|
70
567
|
// Return original stream if we can't parse
|
|
71
568
|
return new Response(fullText, {
|
|
72
569
|
status: response.status,
|
|
@@ -74,6 +571,7 @@ export async function convertSseToJson(response, headers, options) {
|
|
|
74
571
|
headers: headers,
|
|
75
572
|
});
|
|
76
573
|
}
|
|
574
|
+
logStreamDiagnostics(finalResponse);
|
|
77
575
|
// Return as plain JSON (not SSE)
|
|
78
576
|
const jsonHeaders = new Headers(headers);
|
|
79
577
|
jsonHeaders.set('content-type', 'application/json; charset=utf-8');
|
|
@@ -96,6 +594,50 @@ export async function convertSseToJson(response, headers, options) {
|
|
|
96
594
|
reader.releaseLock();
|
|
97
595
|
}
|
|
98
596
|
}
|
|
597
|
+
function createResponseIdCapturingStream(body, onResponseId) {
|
|
598
|
+
const decoder = new TextDecoder();
|
|
599
|
+
let bufferedText = "";
|
|
600
|
+
const state = createParsedResponseState();
|
|
601
|
+
const processBufferedLines = (flush = false) => {
|
|
602
|
+
if (state.encounteredError)
|
|
603
|
+
return;
|
|
604
|
+
const lines = bufferedText.split(/\r?\n/);
|
|
605
|
+
if (!flush) {
|
|
606
|
+
bufferedText = lines.pop() ?? "";
|
|
607
|
+
}
|
|
608
|
+
else {
|
|
609
|
+
bufferedText = "";
|
|
610
|
+
}
|
|
611
|
+
for (const rawLine of lines) {
|
|
612
|
+
const trimmedLine = rawLine.trim();
|
|
613
|
+
if (!trimmedLine.startsWith("data: "))
|
|
614
|
+
continue;
|
|
615
|
+
const payload = trimmedLine.slice(6).trim();
|
|
616
|
+
if (!payload || payload === "[DONE]")
|
|
617
|
+
continue;
|
|
618
|
+
try {
|
|
619
|
+
const data = JSON.parse(payload);
|
|
620
|
+
maybeCaptureResponseEvent(state, data, onResponseId);
|
|
621
|
+
if (state.encounteredError)
|
|
622
|
+
break;
|
|
623
|
+
}
|
|
624
|
+
catch {
|
|
625
|
+
// Ignore malformed SSE lines and keep forwarding the raw stream.
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
return body.pipeThrough(new TransformStream({
|
|
630
|
+
transform(chunk, controller) {
|
|
631
|
+
bufferedText += decoder.decode(chunk, { stream: true });
|
|
632
|
+
processBufferedLines();
|
|
633
|
+
controller.enqueue(chunk);
|
|
634
|
+
},
|
|
635
|
+
flush() {
|
|
636
|
+
bufferedText += decoder.decode();
|
|
637
|
+
processBufferedLines(true);
|
|
638
|
+
},
|
|
639
|
+
}));
|
|
640
|
+
}
|
|
99
641
|
/**
|
|
100
642
|
* Ensure response has content-type header
|
|
101
643
|
* @param headers - Response headers
|
|
@@ -115,7 +657,7 @@ async function readWithTimeout(reader, timeoutMs) {
|
|
|
115
657
|
reader.read(),
|
|
116
658
|
new Promise((_, reject) => {
|
|
117
659
|
timeoutId = setTimeout(() => {
|
|
118
|
-
reject(new Error(`SSE stream stalled for ${timeoutMs}ms while waiting for response
|
|
660
|
+
reject(new Error(`SSE stream stalled for ${timeoutMs}ms while waiting for a terminal response event`));
|
|
119
661
|
}, timeoutMs);
|
|
120
662
|
}),
|
|
121
663
|
]);
|
|
@@ -152,4 +694,18 @@ export function isEmptyResponse(body) {
|
|
|
152
694
|
}
|
|
153
695
|
return false;
|
|
154
696
|
}
|
|
697
|
+
export function attachResponseIdCapture(response, headers, onResponseId) {
|
|
698
|
+
if (!response.body || !onResponseId) {
|
|
699
|
+
return new Response(response.body, {
|
|
700
|
+
status: response.status,
|
|
701
|
+
statusText: response.statusText,
|
|
702
|
+
headers,
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
return new Response(createResponseIdCapturingStream(response.body, onResponseId), {
|
|
706
|
+
status: response.status,
|
|
707
|
+
statusText: response.statusText,
|
|
708
|
+
headers,
|
|
709
|
+
});
|
|
710
|
+
}
|
|
155
711
|
//# sourceMappingURL=response-handler.js.map
|