mixdog 0.9.152 → 0.9.154
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/LICENSES/browser-import-NOTICE.txt +11 -0
- package/NOTICE.md +11 -0
- package/README.md +8 -10
- package/package.json +19 -3
- package/scripts/computer-task-cost-report.mjs +144 -0
- package/scripts/run-office-live-tests.mjs +32 -0
- package/src/agents/front-worker/AGENT.md +13 -0
- package/src/agents/front-worker/agent.json +6 -0
- package/src/agents/heavy-worker/AGENT.md +10 -11
- package/src/agents/heavy-worker/agent.json +1 -1
- package/src/agents/maintainer/AGENT.md +0 -2
- package/src/agents/reviewer/AGENT.md +9 -13
- package/src/agents/reviewer/agent.json +1 -1
- package/src/agents/security/AGENT.md +14 -0
- package/src/agents/security/agent.json +6 -0
- package/src/agents/worker/AGENT.md +8 -8
- package/src/agents/worker/agent.json +1 -1
- package/src/agents/writer/AGENT.md +14 -0
- package/src/agents/writer/agent.json +6 -0
- package/src/rules/agent/00-common.md +4 -7
- package/src/rules/lead/01-general.md +0 -3
- package/src/rules/shared/10-tool-workflow.md +10 -2
- package/src/rules/shared/60-verification.md +2 -0
- package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch.mjs +183 -26
- package/src/runtime/agent/orchestrator/agent-runtime/session-builder.mjs +4 -0
- package/src/runtime/agent/orchestrator/cache-break-trace.mjs +109 -0
- package/src/runtime/agent/orchestrator/config.mjs +7 -2
- package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +16 -3
- package/src/runtime/agent/orchestrator/providers/lib/anthropic-request-utils.mjs +9 -1
- package/src/runtime/agent/orchestrator/providers/media-normalization.mjs +30 -9
- package/src/runtime/agent/orchestrator/providers/openai-codex-metadata.mjs +18 -26
- package/src/runtime/agent/orchestrator/providers/openai-oauth-http-sse.mjs +25 -2
- package/src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs +103 -10
- package/src/runtime/agent/orchestrator/providers/openai-turn-state.mjs +68 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-delta.mjs +36 -11
- package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +140 -86
- package/src/runtime/agent/orchestrator/providers/openai-ws-stream.mjs +9 -13
- package/src/runtime/agent/orchestrator/session/agent-loop.mjs +72 -4
- package/src/runtime/agent/orchestrator/session/browser-snapshot-supersession.mjs +61 -0
- package/src/runtime/agent/orchestrator/session/compact/handoff.mjs +0 -22
- package/src/runtime/agent/orchestrator/session/compact/messages.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/compact/runner.mjs +11 -23
- package/src/runtime/agent/orchestrator/session/compact/summary.mjs +28 -269
- package/src/runtime/agent/orchestrator/session/compact.mjs +0 -6
- package/src/runtime/agent/orchestrator/session/context-utils.mjs +86 -11
- package/src/runtime/agent/orchestrator/session/eager-dispatch.mjs +17 -1
- package/src/runtime/agent/orchestrator/session/image-strip-recovery.mjs +12 -8
- package/src/runtime/agent/orchestrator/session/loop/compact-policy.mjs +110 -2
- package/src/runtime/agent/orchestrator/session/loop/pre-dispatch-deny.mjs +3 -16
- package/src/runtime/agent/orchestrator/session/loop/recall-fasttrack.mjs +80 -18
- package/src/runtime/agent/orchestrator/session/loop/steering.mjs +6 -0
- package/src/runtime/agent/orchestrator/session/loop/tool-exec.mjs +3 -0
- package/src/runtime/agent/orchestrator/session/loop/tool-helpers.mjs +6 -0
- package/src/runtime/agent/orchestrator/session/manager/ask-session.mjs +80 -21
- package/src/runtime/agent/orchestrator/session/manager/compaction-runner.mjs +33 -72
- package/src/runtime/agent/orchestrator/session/manager/session-crud.mjs +21 -2
- package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +25 -51
- package/src/runtime/agent/orchestrator/session/manager/status-telemetry.mjs +3 -0
- package/src/runtime/agent/orchestrator/session/manager/tool-resolution.mjs +4 -110
- package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-journal.mjs +39 -15
- package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint.mjs +14 -4
- package/src/runtime/agent/orchestrator/session/pre-send-compact.mjs +41 -8
- package/src/runtime/agent/orchestrator/session/provider-prefix-guard.mjs +129 -12
- package/src/runtime/agent/orchestrator/session/send-with-recovery.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/store/listing.mjs +8 -1
- package/src/runtime/agent/orchestrator/session/store/save-worker.mjs +15 -1
- package/src/runtime/agent/orchestrator/session/store-summary-index.mjs +36 -2
- package/src/runtime/agent/orchestrator/session/store-summary-reader.mjs +157 -30
- package/src/runtime/agent/orchestrator/session/store-summary-visibility.mjs +57 -0
- package/src/runtime/agent/orchestrator/session/store.mjs +3 -1
- package/src/runtime/agent/orchestrator/session/tool-batch.mjs +22 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-special-files.mjs +6 -6
- package/src/runtime/agent/orchestrator/tools/progress-message.mjs +4 -0
- package/src/runtime/attachments/pdf-extract.mjs +3 -0
- package/src/runtime/attachments/pdfjs-runtime.mjs +13 -0
- package/src/runtime/browser-bridge/action-schema.mjs +251 -0
- package/src/runtime/browser-bridge/client.mjs +75 -26
- package/src/runtime/browser-bridge/tool-defs.mjs +132 -15
- package/src/runtime/computer-bridge/action-schema.mjs +653 -0
- package/src/runtime/computer-bridge/client.mjs +211 -28
- package/src/runtime/computer-bridge/tool-defs.mjs +25 -45
- package/src/runtime/office/assurance-benchmark.mjs +358 -0
- package/src/runtime/office/assurance.mjs +833 -0
- package/src/runtime/office/benchmark.mjs +496 -0
- package/src/runtime/office/capabilities.mjs +551 -0
- package/src/runtime/office/com-adapter.mjs +283 -0
- package/src/runtime/office/content-model.mjs +183 -0
- package/src/runtime/office/contract-benchmark.mjs +105 -0
- package/src/runtime/office/design-library.mjs +1562 -0
- package/src/runtime/office/design-system.mjs +1966 -0
- package/src/runtime/office/index.mjs +2413 -0
- package/src/runtime/office/journal.mjs +82 -0
- package/src/runtime/office/office-com-host.ps1 +3781 -0
- package/src/runtime/office/office-com-session-host.ps1 +855 -0
- package/src/runtime/office/ooxml-validator.mjs +271 -0
- package/src/runtime/office/pagination.mjs +132 -0
- package/src/runtime/office/pdf-adapter.mjs +591 -0
- package/src/runtime/office/pdf-analysis.mjs +372 -0
- package/src/runtime/office/pdf-render.mjs +167 -0
- package/src/runtime/office/pdf-security.mjs +63 -0
- package/src/runtime/office/polish-benchmark.mjs +190 -0
- package/src/runtime/office/portable-ooxml.mjs +1867 -0
- package/src/runtime/office/quality-live-benchmark.mjs +486 -0
- package/src/runtime/office/quality-pipeline.mjs +136 -0
- package/src/runtime/office/tabular.mjs +302 -0
- package/src/runtime/office/templates/mixdog-executive.pptx +0 -0
- package/src/runtime/office/templates/mixdog-executive.pptx.mixdog.json +190 -0
- package/src/runtime/office/tool-defs.mjs +113 -0
- package/src/runtime/office/visual-diff.mjs +89 -0
- package/src/runtime/office/xlsx-assertions.mjs +172 -0
- package/src/runtime/office/xlsx-contract.mjs +147 -0
- package/src/runtime/shared/agent-route-config.mjs +9 -0
- package/src/runtime/shared/tool-execution-contract.mjs +16 -0
- package/src/runtime/shared/tool-surface.mjs +9 -0
- package/src/session-runtime/context-status.mjs +9 -3
- package/src/session-runtime/deferred-tool-delta.mjs +104 -0
- package/src/session-runtime/goal-runtime.mjs +617 -197
- package/src/session-runtime/lifecycle-api.mjs +50 -8
- package/src/session-runtime/provider-request-snapshot.mjs +33 -9
- package/src/session-runtime/resource-api.mjs +31 -94
- package/src/session-runtime/runtime-core.mjs +78 -26
- package/src/session-runtime/session-lifecycle.mjs +34 -12
- package/src/session-runtime/session-title.mjs +2 -2
- package/src/session-runtime/session-turn-api.mjs +15 -14
- package/src/session-runtime/tool-catalog-data.mjs +1 -1
- package/src/session-runtime/tool-catalog.mjs +38 -99
- package/src/session-runtime/tool-defs.mjs +6 -1
- package/src/session-runtime/tool-surface.mjs +18 -8
- package/src/session-runtime/workflow-agents-api.mjs +8 -25
- package/src/session-runtime/workflow.mjs +8 -6
- package/src/standalone/agent-tool/helpers.mjs +2 -2
- package/src/standalone/agent-tool/job-views.mjs +3 -1
- package/src/standalone/agent-tool/notify.mjs +5 -1
- package/src/standalone/agent-tool/render.mjs +3 -0
- package/src/standalone/agent-tool/spawn-flow.mjs +61 -16
- package/src/standalone/agent-tool/tool-def.mjs +1 -1
- package/src/standalone/agent-tool/worker-index.mjs +123 -0
- package/src/standalone/agent-tool/worker-rows.mjs +2 -1
- package/src/standalone/agent-tool.mjs +57 -10
- package/src/standalone/daemon.mjs +105 -6
- package/src/standalone/session-runtime-host.mjs +61 -48
- package/src/standalone/session-runtime-inline-host.mjs +34 -127
- package/src/standalone/session-runtime-worker.mjs +20 -198
- package/src/standalone/session-service.mjs +632 -7
- package/src/tui/dist/index.mjs +24 -1
- package/src/tui/lib/voice-setup.mjs +4 -1
- package/src/tui/session/context-state.mjs +2 -13
- package/src/tui/session/goal-continuation.mjs +38 -7
- package/src/tui/session/session-api-ext.mjs +9 -0
- package/src/tui/session/session-api.mjs +15 -1
- package/src/tui/session/session-flow.mjs +25 -1
- package/src/tui/session/turn.mjs +88 -16
- package/src/tui/session-local.mjs +25 -3
- package/src/vendor/statusline/src/gateway/route-meta.mjs +31 -0
- package/scripts/generate-voice-runtime-manifest.test.mjs +0 -135
- package/scripts/native-binary-arch.test.mjs +0 -111
- package/scripts/patch-replay.test.mjs +0 -94
- package/src/headless-exec.test.mjs +0 -539
- package/src/runtime/agent/orchestrator/agent-trace-timing.test.mjs +0 -57
- package/src/runtime/agent/orchestrator/context/collect-skills.test.mjs +0 -153
- package/src/runtime/agent/orchestrator/mcp/cancellation.test.mjs +0 -139
- package/src/runtime/agent/orchestrator/mcp/features.test.mjs +0 -66
- package/src/runtime/agent/orchestrator/mcp/security.test.mjs +0 -80
- package/src/runtime/agent/orchestrator/providers/anthropic-fast-mode.test.mjs +0 -90
- package/src/runtime/agent/orchestrator/providers/anthropic-server-fallback.test.mjs +0 -215
- package/src/runtime/agent/orchestrator/providers/antigravity-oauth.test.mjs +0 -165
- package/src/runtime/agent/orchestrator/providers/media-parity.test.mjs +0 -142
- package/src/runtime/agent/orchestrator/providers/openai-codex-identity.test.mjs +0 -153
- package/src/runtime/agent/orchestrator/providers/openai-codex-model.test.mjs +0 -24
- package/src/runtime/agent/orchestrator/providers/openai-ws-delta-parity.test.mjs +0 -190
- package/src/runtime/agent/orchestrator/providers/provider-replay.test.mjs +0 -235
- package/src/runtime/agent/orchestrator/providers/sse-framing.test.mjs +0 -719
- package/src/runtime/agent/orchestrator/session/cache/prefetch-cache.test.mjs +0 -40
- package/src/runtime/agent/orchestrator/session/compact-policy.test.mjs +0 -176
- package/src/runtime/agent/orchestrator/session/compaction-read-reset.test.mjs +0 -161
- package/src/runtime/agent/orchestrator/session/eager-dispatch.test.mjs +0 -115
- package/src/runtime/agent/orchestrator/session/evidence-union.test.mjs +0 -228
- package/src/runtime/agent/orchestrator/session/image-strip-recovery.test.mjs +0 -245
- package/src/runtime/agent/orchestrator/session/lossless-tool-output.test.mjs +0 -125
- package/src/runtime/agent/orchestrator/session/manager/pending-messages-persistence.test.mjs +0 -325
- package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.test.mjs +0 -70
- package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-journal.test.mjs +0 -457
- package/src/runtime/agent/orchestrator/session/provider-prefix-guard.test.mjs +0 -117
- package/src/runtime/agent/orchestrator/session/reduction-metrics.test.mjs +0 -87
- package/src/runtime/agent/orchestrator/session/store/serialize.test.mjs +0 -60
- package/src/runtime/agent/orchestrator/session/store-summary-reader.test.mjs +0 -583
- package/src/runtime/agent/orchestrator/session/task-wait-control.test.mjs +0 -78
- package/src/runtime/agent/orchestrator/tools/builtin/absence-absorption.test.mjs +0 -43
- package/src/runtime/agent/orchestrator/tools/builtin/absolute-glob-expand.test.mjs +0 -63
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool-cwd-env.test.mjs +0 -14
- package/src/runtime/agent/orchestrator/tools/builtin/edit-encoding-eol.test.mjs +0 -224
- package/src/runtime/agent/orchestrator/tools/builtin/edit-sequential-occupation.test.mjs +0 -224
- package/src/runtime/agent/orchestrator/tools/builtin/enoent-outside-project.test.mjs +0 -56
- package/src/runtime/agent/orchestrator/tools/builtin/find-search-budget.test.mjs +0 -103
- package/src/runtime/agent/orchestrator/tools/builtin/git-command-policy.test.mjs +0 -30
- package/src/runtime/agent/orchestrator/tools/builtin/git-command-tool.test.mjs +0 -390
- package/src/runtime/agent/orchestrator/tools/builtin/git-repo-rw-lock.test.mjs +0 -83
- package/src/runtime/agent/orchestrator/tools/builtin/grep-output-budget.test.mjs +0 -31
- package/src/runtime/agent/orchestrator/tools/builtin/grep-single-file-rescue.test.mjs +0 -106
- package/src/runtime/agent/orchestrator/tools/builtin/lib/shell-job-records.test.mjs +0 -102
- package/src/runtime/agent/orchestrator/tools/builtin/list-tool-integrity.test.mjs +0 -152
- package/src/runtime/agent/orchestrator/tools/builtin/native-search-health.test.mjs +0 -24
- package/src/runtime/agent/orchestrator/tools/builtin/native-search-transport.test.mjs +0 -24
- package/src/runtime/agent/orchestrator/tools/builtin/noise-dir-visibility.test.mjs +0 -69
- package/src/runtime/agent/orchestrator/tools/builtin/read-glob-survey.test.mjs +0 -71
- package/src/runtime/agent/orchestrator/tools/builtin/runtime-capabilities.test.mjs +0 -56
- package/src/runtime/agent/orchestrator/tools/builtin/search-builders.test.mjs +0 -16
- package/src/runtime/agent/orchestrator/tools/builtin/search-glob-top-k.test.mjs +0 -39
- package/src/runtime/agent/orchestrator/tools/builtin/write-symlink.test.mjs +0 -153
- package/src/runtime/agent/orchestrator/tools/code-graph/aggregate-anchor-relocation.test.mjs +0 -55
- package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.test.mjs +0 -88
- package/src/runtime/agent/orchestrator/tools/code-graph/loose-file-target.test.mjs +0 -72
- package/src/runtime/agent/orchestrator/tools/code-graph/memory-cache.test.mjs +0 -54
- package/src/runtime/agent/orchestrator/tools/code-graph/search-references.test.mjs +0 -20
- package/src/runtime/agent/orchestrator/tools/code-graph/symbol-search-scope.test.mjs +0 -55
- package/src/runtime/agent/orchestrator/tools/code-graph/text-span-mask.test.mjs +0 -268
- package/src/runtime/agent/orchestrator/tools/env-scrub.test.mjs +0 -57
- package/src/runtime/agent/orchestrator/tools/graph-binary-fetcher.test.mjs +0 -19
- package/src/runtime/agent/orchestrator/tools/lib/native-spawn-client.test.mjs +0 -104
- package/src/runtime/agent/orchestrator/tools/patch/engine-contract-gate.test.mjs +0 -661
- package/src/runtime/agent/orchestrator/tools/patch/patch-codec-eol.test.mjs +0 -552
- package/src/runtime/agent/orchestrator/tools/patch/patch-symlink.test.mjs +0 -141
- package/src/runtime/agent/orchestrator/tools/patch/v4a-pure-move.test.mjs +0 -57
- package/src/runtime/agent/orchestrator/tools/patch/v4a-section-coalesce.test.mjs +0 -81
- package/src/runtime/agent/orchestrator/tools/spawn-binary-fetcher.test.mjs +0 -52
- package/src/runtime/attachments/store.test.mjs +0 -209
- package/src/runtime/channels/lib/voice-runtime-fetcher.test.mjs +0 -17
- package/src/runtime/channels/lib/webhook/deliveries.test.mjs +0 -18
- package/src/runtime/channels/lib/webhook/relay-tunnel.test.mjs +0 -68
- package/src/runtime/media/adapters/codex-image.test.mjs +0 -22
- package/src/runtime/media/download.test.mjs +0 -52
- package/src/runtime/media/renditions.test.mjs +0 -99
- package/src/runtime/media/store.test.mjs +0 -159
- package/src/runtime/memory/lib/archive-security.test.mjs +0 -128
- package/src/runtime/memory/lib/embedding-model-config.test.mjs +0 -33
- package/src/runtime/memory/lib/http-wire.test.mjs +0 -15
- package/src/runtime/memory/lib/memory-cycle-packets.test.mjs +0 -49
- package/src/runtime/memory/lib/memory-cycle2-shared.test.mjs +0 -78
- package/src/runtime/memory/lib/memory-embedding-migration.test.mjs +0 -50
- package/src/runtime/memory/lib/pg/process.test.mjs +0 -36
- package/src/runtime/memory/lib/trace-store.test.mjs +0 -57
- package/src/runtime/memory/lib/transcript-ingest.test.mjs +0 -52
- package/src/runtime/shared/background-tasks.test.mjs +0 -78
- package/src/runtime/shared/bounded-download.test.mjs +0 -41
- package/src/runtime/shared/channel-notification-routing.test.mjs +0 -25
- package/src/runtime/shared/child-spawn-remote.test.mjs +0 -124
- package/src/runtime/shared/remote-intent.test.mjs +0 -40
- package/src/runtime/shared/resource-admission.test.mjs +0 -43
- package/src/runtime/shared/runtime-root.test.mjs +0 -34
- package/src/runtime/shared/schedule-time.test.mjs +0 -29
- package/src/runtime/shared/session-runtime-health.test.mjs +0 -83
- package/src/runtime/shared/skill-document.test.mjs +0 -81
- package/src/runtime/shared/tool-surface.test.mjs +0 -87
- package/src/runtime/shared/update-checker.test.mjs +0 -33
- package/src/runtime/shared/user-cwd.test.mjs +0 -43
- package/src/runtime/shared/webhook-session-run.test.mjs +0 -14
- package/src/session-runtime/agent-disable.test.mjs +0 -123
- package/src/session-runtime/cwd-plugins.test.mjs +0 -75
- package/src/session-runtime/cwd-tool-routing.test.mjs +0 -61
- package/src/session-runtime/global-extensions.test.mjs +0 -28
- package/src/session-runtime/goal-runtime.test.mjs +0 -108
- package/src/session-runtime/lifecycle-api.test.mjs +0 -21
- package/src/session-runtime/model-settings-persist.test.mjs +0 -105
- package/src/session-runtime/notification-bus.test.mjs +0 -148
- package/src/session-runtime/plugin-mcp-standard.test.mjs +0 -177
- package/src/session-runtime/prewarm.test.mjs +0 -52
- package/src/session-runtime/provider-request-snapshot.test.mjs +0 -37
- package/src/session-runtime/resource-api-global.test.mjs +0 -69
- package/src/session-runtime/session-lifecycle.test.mjs +0 -125
- package/src/session-runtime/session-title.test.mjs +0 -36
- package/src/session-runtime/skills-api.test.mjs +0 -99
- package/src/session-runtime/tool-policy-surface.test.mjs +0 -331
- package/src/standalone/agent-tool/helpers.test.mjs +0 -62
- package/src/standalone/agent-tool/notify.test.mjs +0 -37
- package/src/standalone/agent-tool/spawn-flow.test.mjs +0 -63
- package/src/standalone/channel-restart.test.mjs +0 -145
- package/src/standalone/channel-session-router.test.mjs +0 -37
- package/src/standalone/channel-worker-heartbeat.test.mjs +0 -30
- package/src/standalone/hook-bus/handlers.test.mjs +0 -88
- package/src/standalone/plugin-admin.test.mjs +0 -173
- package/src/standalone/session-runtime-agent-control-client.test.mjs +0 -71
- package/src/standalone/session-runtime-dispatch-cancel.test.mjs +0 -139
- package/src/standalone/session-runtime-host-factory.test.mjs +0 -31
- package/src/standalone/session-runtime-host-health.test.mjs +0 -160
- package/src/standalone/session-runtime-inline-host.test.mjs +0 -83
- package/src/standalone/session-runtime-provider-cooldown.test.mjs +0 -80
- package/src/standalone/session-runtime-shard-host.test.mjs +0 -569
- package/src/standalone/session-runtime-shard-router.test.mjs +0 -101
- package/src/tui/app/live-spinner-visibility.test.mjs +0 -44
- package/src/tui/app/panel-epoch.test.mjs +0 -1009
- package/src/tui/app/panel-handoff.test.mjs +0 -311
- package/src/tui/app/prompt-submit.test.mjs +0 -206
- package/src/tui/session/completion-card-restore.test.mjs +0 -111
- package/src/tui/session/goal-continuation.test.mjs +0 -84
- package/src/tui/session/oauth-flows.test.mjs +0 -134
- package/src/tui/session/queue-helpers.test.mjs +0 -46
- package/src/tui/session/session-action-surface.test.mjs +0 -108
- package/src/tui/session/task-wait-submit.test.mjs +0 -80
- package/src/tui/session/tool-result-status.test.mjs +0 -131
- package/src/tui/session/tui-steering-persist.test.mjs +0 -104
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import test from 'node:test';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
SERVER_SIDE_FALLBACK_BETA_HEADER,
|
|
6
|
-
buildAnthropicBetaHeaders,
|
|
7
|
-
} from './anthropic-betas.mjs';
|
|
8
|
-
import { _buildRequestBodyForCacheSmoke } from './anthropic-oauth.mjs';
|
|
9
|
-
import {
|
|
10
|
-
applyAnthropicServerFallback,
|
|
11
|
-
parseAnthropicFallbackBlock,
|
|
12
|
-
supportsAnthropicServerFallback,
|
|
13
|
-
} from './anthropic-server-fallback.mjs';
|
|
14
|
-
import { parseSSEStream } from './anthropic-sse.mjs';
|
|
15
|
-
import { normalizeAnthropicNonStreamingResponse } from './lib/anthropic-request-utils.mjs';
|
|
16
|
-
import { agentLoop } from '../session/agent-loop.mjs';
|
|
17
|
-
|
|
18
|
-
const fallbackBlock = {
|
|
19
|
-
type: 'fallback',
|
|
20
|
-
from: { model: 'claude-opus-5' },
|
|
21
|
-
to: { model: 'claude-opus-4-8' },
|
|
22
|
-
trigger: { type: 'refusal', category: 'cyber' },
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
test('server fallback defaults only eligible Anthropic model families', () => {
|
|
26
|
-
assert.equal(supportsAnthropicServerFallback('claude-opus-5'), true);
|
|
27
|
-
assert.equal(supportsAnthropicServerFallback('claude-fable-5-20260801'), true);
|
|
28
|
-
assert.equal(supportsAnthropicServerFallback('claude-opus-4-8'), false);
|
|
29
|
-
|
|
30
|
-
const body = {};
|
|
31
|
-
assert.equal(applyAnthropicServerFallback(body, 'claude-opus-5'), true);
|
|
32
|
-
assert.equal(body.fallbacks, 'default');
|
|
33
|
-
|
|
34
|
-
const disabled = {};
|
|
35
|
-
assert.equal(
|
|
36
|
-
applyAnthropicServerFallback(disabled, 'claude-opus-5', { enabled: false }),
|
|
37
|
-
false,
|
|
38
|
-
);
|
|
39
|
-
assert.equal('fallbacks' in disabled, false);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test('server fallback beta header is request-gated and deduplicated', () => {
|
|
43
|
-
assert.equal(
|
|
44
|
-
buildAnthropicBetaHeaders({ base: '', serverFallback: false }).includes(SERVER_SIDE_FALLBACK_BETA_HEADER),
|
|
45
|
-
false,
|
|
46
|
-
);
|
|
47
|
-
const headers = buildAnthropicBetaHeaders({
|
|
48
|
-
base: SERVER_SIDE_FALLBACK_BETA_HEADER,
|
|
49
|
-
serverFallback: true,
|
|
50
|
-
}).split(',');
|
|
51
|
-
assert.equal(headers.filter((item) => item === SERVER_SIDE_FALLBACK_BETA_HEADER).length, 1);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('OAuth request body opts eligible models into Anthropic default fallback', () => {
|
|
55
|
-
const opus5 = _buildRequestBodyForCacheSmoke([], 'claude-opus-5');
|
|
56
|
-
assert.equal(opus5.fallbacks, 'default');
|
|
57
|
-
|
|
58
|
-
const opus48 = _buildRequestBodyForCacheSmoke([], 'claude-opus-4-8');
|
|
59
|
-
assert.equal('fallbacks' in opus48, false);
|
|
60
|
-
|
|
61
|
-
const disabled = _buildRequestBodyForCacheSmoke(
|
|
62
|
-
[],
|
|
63
|
-
'claude-opus-5',
|
|
64
|
-
[],
|
|
65
|
-
{ serverFallback: false },
|
|
66
|
-
);
|
|
67
|
-
assert.equal('fallbacks' in disabled, false);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test('fallback block parser uses structured model and refusal category fields', () => {
|
|
71
|
-
assert.deepEqual(parseAnthropicFallbackBlock(fallbackBlock), {
|
|
72
|
-
trigger: 'refusal',
|
|
73
|
-
originalModel: 'claude-opus-5',
|
|
74
|
-
fallbackModel: 'claude-opus-4-8',
|
|
75
|
-
category: 'cyber',
|
|
76
|
-
});
|
|
77
|
-
assert.equal(parseAnthropicFallbackBlock({ type: 'text', text: 'fallback' }), null);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
const encoder = new TextEncoder();
|
|
81
|
-
function sseResponse(events) {
|
|
82
|
-
const chunks = events.map((event) => (
|
|
83
|
-
encoder.encode(`event: ${event.type}\ndata: ${JSON.stringify(event)}\n\n`)
|
|
84
|
-
));
|
|
85
|
-
let index = 0;
|
|
86
|
-
return {
|
|
87
|
-
body: {
|
|
88
|
-
getReader() {
|
|
89
|
-
return {
|
|
90
|
-
read() {
|
|
91
|
-
if (index < chunks.length) {
|
|
92
|
-
return Promise.resolve({ done: false, value: chunks[index++] });
|
|
93
|
-
}
|
|
94
|
-
return Promise.resolve({ done: true, value: undefined });
|
|
95
|
-
},
|
|
96
|
-
cancel() { return Promise.resolve(); },
|
|
97
|
-
releaseLock() {},
|
|
98
|
-
};
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
test('SSE parser records server fallback and attributes the turn to the serving model', async () => {
|
|
105
|
-
const state = {
|
|
106
|
-
attemptIndex: 0,
|
|
107
|
-
sawMessageStart: false,
|
|
108
|
-
sawCompleted: false,
|
|
109
|
-
emittedToolCall: false,
|
|
110
|
-
partialToolCall: false,
|
|
111
|
-
emittedThinking: false,
|
|
112
|
-
emittedText: false,
|
|
113
|
-
};
|
|
114
|
-
const result = await parseSSEStream(
|
|
115
|
-
sseResponse([
|
|
116
|
-
{
|
|
117
|
-
type: 'message_start',
|
|
118
|
-
message: {
|
|
119
|
-
model: 'claude-opus-5',
|
|
120
|
-
usage: { input_tokens: 10 },
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
{ type: 'content_block_start', index: 0, content_block: fallbackBlock },
|
|
124
|
-
{ type: 'content_block_stop', index: 0 },
|
|
125
|
-
{ type: 'content_block_start', index: 1, content_block: { type: 'text', text: '' } },
|
|
126
|
-
{ type: 'content_block_delta', index: 1, delta: { type: 'text_delta', text: 'done' } },
|
|
127
|
-
{ type: 'content_block_stop', index: 1 },
|
|
128
|
-
{
|
|
129
|
-
type: 'message_delta',
|
|
130
|
-
delta: { stop_reason: 'end_turn' },
|
|
131
|
-
usage: { output_tokens: 2 },
|
|
132
|
-
},
|
|
133
|
-
{ type: 'message_stop' },
|
|
134
|
-
]),
|
|
135
|
-
null,
|
|
136
|
-
() => {},
|
|
137
|
-
() => {},
|
|
138
|
-
() => {},
|
|
139
|
-
state,
|
|
140
|
-
() => {},
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
assert.equal(result.content, 'done');
|
|
144
|
-
assert.equal(result.model, 'claude-opus-4-8');
|
|
145
|
-
assert.equal(result.stopReason, 'end_turn');
|
|
146
|
-
assert.equal(result.contentBlockTypes.includes('fallback'), true);
|
|
147
|
-
assert.deepEqual(result.providerMetadata, {
|
|
148
|
-
anthropicFallbacks: [{
|
|
149
|
-
trigger: 'refusal',
|
|
150
|
-
originalModel: 'claude-opus-5',
|
|
151
|
-
fallbackModel: 'claude-opus-4-8',
|
|
152
|
-
category: 'cyber',
|
|
153
|
-
}],
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
test('agent loop reports the actual serving model in per-request usage deltas', async () => {
|
|
158
|
-
const deltas = [];
|
|
159
|
-
const provider = {
|
|
160
|
-
name: 'anthropic-oauth',
|
|
161
|
-
async send() {
|
|
162
|
-
return {
|
|
163
|
-
content: 'done',
|
|
164
|
-
model: 'claude-opus-4-8',
|
|
165
|
-
stopReason: 'end_turn',
|
|
166
|
-
usage: {
|
|
167
|
-
inputTokens: 1,
|
|
168
|
-
outputTokens: 2,
|
|
169
|
-
cachedTokens: 3,
|
|
170
|
-
cacheWriteTokens: 4,
|
|
171
|
-
promptTokens: 8,
|
|
172
|
-
},
|
|
173
|
-
};
|
|
174
|
-
},
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
const result = await agentLoop(
|
|
178
|
-
provider,
|
|
179
|
-
[{ role: 'user', content: 'test' }],
|
|
180
|
-
'claude-opus-5',
|
|
181
|
-
[],
|
|
182
|
-
async () => {},
|
|
183
|
-
process.cwd(),
|
|
184
|
-
{
|
|
185
|
-
sessionId: 'server-fallback-usage-test',
|
|
186
|
-
onUsageDelta: (delta) => deltas.push(delta),
|
|
187
|
-
},
|
|
188
|
-
);
|
|
189
|
-
|
|
190
|
-
assert.equal(result.model, 'claude-opus-4-8');
|
|
191
|
-
assert.equal(deltas.length, 1);
|
|
192
|
-
assert.equal(deltas[0].requestedModel, 'claude-opus-5');
|
|
193
|
-
assert.equal(deltas[0].model, 'claude-opus-4-8');
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
test('non-streaming normalizer excludes fallback blocks and preserves metadata', () => {
|
|
197
|
-
const result = normalizeAnthropicNonStreamingResponse({
|
|
198
|
-
model: 'claude-opus-5',
|
|
199
|
-
content: [
|
|
200
|
-
fallbackBlock,
|
|
201
|
-
{ type: 'text', text: 'done' },
|
|
202
|
-
],
|
|
203
|
-
stop_reason: 'end_turn',
|
|
204
|
-
usage: { input_tokens: 10, output_tokens: 2 },
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
assert.equal(result.content, 'done');
|
|
208
|
-
assert.equal(result.model, 'claude-opus-4-8');
|
|
209
|
-
assert.deepEqual(result.providerMetadata?.anthropicFallbacks, [{
|
|
210
|
-
trigger: 'refusal',
|
|
211
|
-
originalModel: 'claude-opus-5',
|
|
212
|
-
fallbackModel: 'claude-opus-4-8',
|
|
213
|
-
category: 'cyber',
|
|
214
|
-
}]);
|
|
215
|
-
});
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
// Wire-shape checks for the Antigravity Cloud Code Assist transport. The
|
|
2
|
-
// backend rejects a malformed envelope with an opaque 400, so the request
|
|
3
|
-
// wrapper, the impersonation headers, the thinking-signature sentinel, and the
|
|
4
|
-
// `{ response: … }` chunk unwrapping are all pinned here.
|
|
5
|
-
import test from 'node:test';
|
|
6
|
-
import assert from 'node:assert/strict';
|
|
7
|
-
|
|
8
|
-
import { AntigravityOAuthProvider } from './antigravity-oauth.mjs';
|
|
9
|
-
import { antigravityHeaders, codeAssistMetadata } from './antigravity-oauth-tokens.mjs';
|
|
10
|
-
|
|
11
|
-
function sseResponse(chunks, { status = 200 } = {}) {
|
|
12
|
-
const body = chunks.map((chunk) => `data: ${JSON.stringify(chunk)}\n\n`).join('');
|
|
13
|
-
return new Response(body, {
|
|
14
|
-
status,
|
|
15
|
-
headers: { 'content-type': 'text/event-stream' },
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function candidateChunk(parts, finishReason = null) {
|
|
20
|
-
return {
|
|
21
|
-
response: {
|
|
22
|
-
candidates: [{ content: { role: 'model', parts }, ...(finishReason ? { finishReason } : {}) }],
|
|
23
|
-
...(finishReason ? { usageMetadata: { promptTokenCount: 11, candidatesTokenCount: 5 } } : {}),
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function providerWith(fetchFn, overrides = {}) {
|
|
29
|
-
return new AntigravityOAuthProvider({
|
|
30
|
-
fetchFn,
|
|
31
|
-
preconnectFn: () => {},
|
|
32
|
-
ensureAuthFn: async () => ({
|
|
33
|
-
accessToken: 'access-token',
|
|
34
|
-
projectId: 'test-project',
|
|
35
|
-
email: 'dev@example.com',
|
|
36
|
-
}),
|
|
37
|
-
...overrides,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
test('requests carry the Cloud Code Assist envelope and Antigravity identity', async () => {
|
|
42
|
-
let seen = null;
|
|
43
|
-
const provider = providerWith(async (url, init) => {
|
|
44
|
-
seen = { url, init, body: JSON.parse(init.body) };
|
|
45
|
-
return sseResponse([candidateChunk([{ text: 'hi' }], 'STOP')]);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
await provider.send(
|
|
49
|
-
[{ role: 'system', content: 'be brief' }, { role: 'user', content: 'hello' }],
|
|
50
|
-
'gemini-3-pro-high',
|
|
51
|
-
[],
|
|
52
|
-
{},
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
assert.match(seen.url, /\/v1internal:streamGenerateContent\?alt=sse$/);
|
|
56
|
-
assert.equal(seen.body.project, 'test-project');
|
|
57
|
-
assert.equal(seen.body.model, 'gemini-3-pro-high');
|
|
58
|
-
assert.equal(seen.body.requestType, 'agent');
|
|
59
|
-
assert.equal(seen.body.userAgent, 'antigravity');
|
|
60
|
-
assert.match(String(seen.body.requestId), /^agent-/);
|
|
61
|
-
// System prompts ride as an object tagged role "user"; a bare string 400s.
|
|
62
|
-
assert.equal(seen.body.request.systemInstruction.role, 'user');
|
|
63
|
-
assert.equal(seen.body.request.systemInstruction.parts[0].text, 'be brief');
|
|
64
|
-
assert.equal(seen.body.request.contents[0].role, 'user');
|
|
65
|
-
assert.equal(seen.init.headers.Authorization, 'Bearer access-token');
|
|
66
|
-
assert.equal(seen.init.headers.Accept, 'text/event-stream');
|
|
67
|
-
assert.equal(seen.init.headers['User-Agent'], antigravityHeaders()['User-Agent']);
|
|
68
|
-
assert.equal(codeAssistMetadata().ideType, 'ANTIGRAVITY');
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('replayed thinking parts are re-stamped with the accepted sentinel', async () => {
|
|
72
|
-
let seen = null;
|
|
73
|
-
const provider = providerWith(async (_url, init) => {
|
|
74
|
-
seen = JSON.parse(init.body);
|
|
75
|
-
return sseResponse([candidateChunk([{ text: 'done' }], 'STOP')]);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
await provider.send(
|
|
79
|
-
[
|
|
80
|
-
{ role: 'user', content: 'first' },
|
|
81
|
-
{
|
|
82
|
-
role: 'assistant',
|
|
83
|
-
content: 'answer',
|
|
84
|
-
// Thinking is replayed from the recorded provider metadata, exactly as a
|
|
85
|
-
// resumed session hands it back.
|
|
86
|
-
providerMetadata: {
|
|
87
|
-
gemini: { thoughtParts: [{ text: 'because…', thoughtSignature: 'stale-signature' }] },
|
|
88
|
-
},
|
|
89
|
-
toolCalls: [{ id: 'call_1', name: 'read', arguments: { path: 'a.txt' } }],
|
|
90
|
-
},
|
|
91
|
-
{ role: 'tool', toolCallId: 'call_1', name: 'read', content: 'file body' },
|
|
92
|
-
{ role: 'user', content: 'second' },
|
|
93
|
-
],
|
|
94
|
-
'claude-opus-4-6-thinking',
|
|
95
|
-
[],
|
|
96
|
-
{},
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
const thoughtParts = seen.request.contents
|
|
100
|
-
.flatMap((entry) => entry.parts || [])
|
|
101
|
-
.filter((part) => part?.thought === true);
|
|
102
|
-
assert.ok(thoughtParts.length > 0, 'expected a replayed thinking part');
|
|
103
|
-
for (const part of thoughtParts) {
|
|
104
|
-
assert.equal(part.thoughtSignature, 'skip_thought_signature_validator');
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
test('Claude thinking models request the interleaved-thinking beta', async () => {
|
|
109
|
-
let headers = null;
|
|
110
|
-
const provider = providerWith(async (_url, init) => {
|
|
111
|
-
headers = init.headers;
|
|
112
|
-
return sseResponse([candidateChunk([{ text: 'ok' }], 'STOP')]);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
await provider.send([{ role: 'user', content: 'hi' }], 'claude-opus-4-6-thinking', [], {});
|
|
116
|
-
assert.equal(headers['anthropic-beta'], 'interleaved-thinking-2025-05-14');
|
|
117
|
-
|
|
118
|
-
await provider.send([{ role: 'user', content: 'hi' }], 'gemini-3-pro-high', [], {});
|
|
119
|
-
assert.equal(headers['anthropic-beta'], undefined);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
test('nested response chunks stream text and tool calls', async () => {
|
|
123
|
-
const deltas = [];
|
|
124
|
-
const toolCalls = [];
|
|
125
|
-
const provider = providerWith(async () => sseResponse([
|
|
126
|
-
candidateChunk([{ text: 'Hel' }]),
|
|
127
|
-
candidateChunk([{ text: 'lo' }]),
|
|
128
|
-
candidateChunk([{ functionCall: { name: 'read', args: { path: 'a.txt' } } }], 'STOP'),
|
|
129
|
-
]));
|
|
130
|
-
|
|
131
|
-
const result = await provider.send([{ role: 'user', content: 'hi' }], 'gemini-3-pro-high', [
|
|
132
|
-
{ name: 'read', description: 'read a file', parameters: { type: 'object', properties: {} } },
|
|
133
|
-
], {
|
|
134
|
-
onTextDelta: (text) => deltas.push(text),
|
|
135
|
-
onToolCall: (call) => toolCalls.push(call),
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
assert.equal(result.content, 'Hello');
|
|
139
|
-
assert.equal(deltas.join(''), 'Hello');
|
|
140
|
-
assert.equal(result.toolCalls?.length, 1);
|
|
141
|
-
assert.equal(result.toolCalls[0].name, 'read');
|
|
142
|
-
assert.equal(toolCalls.length, 1);
|
|
143
|
-
assert.equal(result.usage.inputTokens, 11);
|
|
144
|
-
assert.equal(result.usage.outputTokens, 5);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
test('a failing endpoint fails over to the next one before surfacing an error', async () => {
|
|
148
|
-
const tried = [];
|
|
149
|
-
const provider = providerWith(async (url) => {
|
|
150
|
-
tried.push(new URL(url).host);
|
|
151
|
-
if (tried.length === 1) {
|
|
152
|
-
return new Response(JSON.stringify({ error: { code: 500, message: 'backend' } }), {
|
|
153
|
-
status: 500,
|
|
154
|
-
headers: { 'content-type': 'application/json' },
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
return sseResponse([candidateChunk([{ text: 'recovered' }], 'STOP')]);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
const result = await provider.send([{ role: 'user', content: 'hi' }], 'gemini-3-pro-high', [], {});
|
|
161
|
-
assert.equal(result.content, 'recovered');
|
|
162
|
-
assert.equal(tried.length, 2);
|
|
163
|
-
assert.equal(tried[0], 'daily-cloudcode-pa.sandbox.googleapis.com');
|
|
164
|
-
assert.notEqual(tried[1], tried[0]);
|
|
165
|
-
});
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import test from 'node:test';
|
|
3
|
-
import { toAnthropicMessages } from './anthropic-messages.mjs';
|
|
4
|
-
import { toGeminiContents } from './gemini-schema.mjs';
|
|
5
|
-
import { toOpenAIMessages, toXaiResponsesInput } from './openai-compat-wire.mjs';
|
|
6
|
-
import { convertMessagesToResponsesInput } from './openai-responses-payload.mjs';
|
|
7
|
-
|
|
8
|
-
const IMAGE_DATA = 'AAECAw==';
|
|
9
|
-
|
|
10
|
-
function mixedImageContent(text = 'Image read successfully') {
|
|
11
|
-
return {
|
|
12
|
-
content: [
|
|
13
|
-
{ type: 'text', text },
|
|
14
|
-
{ type: 'image', data: IMAGE_DATA, mimeType: 'image/png' },
|
|
15
|
-
],
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function imageHistory(content = mixedImageContent()) {
|
|
20
|
-
return [
|
|
21
|
-
{ role: 'user', content: 'inspect the image' },
|
|
22
|
-
{
|
|
23
|
-
role: 'assistant',
|
|
24
|
-
content: '',
|
|
25
|
-
toolCalls: [{ id: 'call_1', name: 'read', arguments: { file_path: 'shot.png' } }],
|
|
26
|
-
},
|
|
27
|
-
{ role: 'tool', toolCallId: 'call_1', toolKind: 'normal', content },
|
|
28
|
-
];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function occurrences(value, needle) {
|
|
32
|
-
return JSON.stringify(value).split(needle).length - 1;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
test('OpenAI Responses keeps text, image, and file in one function output', () => {
|
|
36
|
-
const content = mixedImageContent();
|
|
37
|
-
content.content.push({
|
|
38
|
-
type: 'file',
|
|
39
|
-
data: 'JVBERi0xLjQ=',
|
|
40
|
-
mimeType: 'application/pdf',
|
|
41
|
-
filename: 'report.pdf',
|
|
42
|
-
});
|
|
43
|
-
const history = imageHistory(content);
|
|
44
|
-
const before = JSON.stringify(history);
|
|
45
|
-
const input = convertMessagesToResponsesInput(history);
|
|
46
|
-
const output = input.find((item) => item.type === 'function_call_output')?.output;
|
|
47
|
-
assert.deepEqual(output, [
|
|
48
|
-
{ type: 'input_text', text: 'Image read successfully' },
|
|
49
|
-
{ type: 'input_image', image_url: `data:image/png;base64,${IMAGE_DATA}` },
|
|
50
|
-
{
|
|
51
|
-
type: 'input_file',
|
|
52
|
-
filename: 'report.pdf',
|
|
53
|
-
file_data: 'data:application/pdf;base64,JVBERi0xLjQ=',
|
|
54
|
-
},
|
|
55
|
-
]);
|
|
56
|
-
assert.equal(input.filter((item) => item?.role === 'user').length, 1);
|
|
57
|
-
assert.equal(occurrences(input, 'Image read successfully'), 1);
|
|
58
|
-
assert.equal(JSON.stringify(history), before);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test('OpenAI Chat-compatible sends tool text once and media-only user content', () => {
|
|
62
|
-
const history = imageHistory();
|
|
63
|
-
const messages = toOpenAIMessages(history, 'openai');
|
|
64
|
-
const tool = messages.find((message) => message.role === 'tool');
|
|
65
|
-
const media = messages.filter((message) => message.role === 'user').at(-1);
|
|
66
|
-
assert.equal(tool.content, 'Image read successfully');
|
|
67
|
-
assert.deepEqual(media.content, [{
|
|
68
|
-
type: 'image_url',
|
|
69
|
-
image_url: { url: `data:image/png;base64,${IMAGE_DATA}` },
|
|
70
|
-
}]);
|
|
71
|
-
assert.equal(occurrences(messages, 'Image read successfully'), 1);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test('xAI Responses keeps text output and sends image-only user content', () => {
|
|
75
|
-
const history = imageHistory();
|
|
76
|
-
const { input } = toXaiResponsesInput(history, {
|
|
77
|
-
xaiResponses: { previousResponseId: 'resp_1', seenMessageCount: 0, model: 'grok-4' },
|
|
78
|
-
}, { model: 'grok-4' });
|
|
79
|
-
const tool = input.find((item) => item.type === 'function_call_output');
|
|
80
|
-
const media = input.filter((item) => item?.role === 'user').at(-1);
|
|
81
|
-
assert.equal(tool.output, 'Image read successfully');
|
|
82
|
-
assert.deepEqual(media.content, [{
|
|
83
|
-
type: 'input_image',
|
|
84
|
-
image_url: `data:image/png;base64,${IMAGE_DATA}`,
|
|
85
|
-
}]);
|
|
86
|
-
assert.equal(occurrences(input, 'Image read successfully'), 1);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
test('Anthropic retains one structured tool_result with text and image', () => {
|
|
90
|
-
const history = imageHistory();
|
|
91
|
-
const messages = toAnthropicMessages(history);
|
|
92
|
-
const toolResult = messages
|
|
93
|
-
.flatMap((message) => Array.isArray(message.content) ? message.content : [])
|
|
94
|
-
.find((part) => part?.type === 'tool_result');
|
|
95
|
-
assert.equal(toolResult.content[0].text, 'Image read successfully');
|
|
96
|
-
assert.equal(toolResult.content[1].type, 'image');
|
|
97
|
-
assert.equal(toolResult.content[1].source.data, IMAGE_DATA);
|
|
98
|
-
assert.equal(occurrences(messages, 'Image read successfully'), 1);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
test('Gemini 3 nests media and IDs inside one function-response turn', () => {
|
|
102
|
-
const contents = toGeminiContents(imageHistory(), 'gemini-3-pro-preview');
|
|
103
|
-
const functionCall = contents[1].parts[0].functionCall;
|
|
104
|
-
const functionResponse = contents[2].parts[0].functionResponse;
|
|
105
|
-
assert.equal(functionCall.id, 'call_1');
|
|
106
|
-
assert.equal(functionResponse.id, 'call_1');
|
|
107
|
-
assert.equal(functionResponse.response.result, 'Image read successfully');
|
|
108
|
-
assert.equal(functionResponse.parts[0].inlineData.data, IMAGE_DATA);
|
|
109
|
-
assert.equal(contents.length, 3);
|
|
110
|
-
assert.equal(occurrences(contents, 'Image read successfully'), 1);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
test('Gemini 2 merges parallel responses, omits IDs, then sends media', () => {
|
|
114
|
-
const history = [
|
|
115
|
-
{ role: 'user', content: 'inspect both' },
|
|
116
|
-
{
|
|
117
|
-
role: 'assistant',
|
|
118
|
-
content: '',
|
|
119
|
-
toolCalls: [
|
|
120
|
-
{ id: 'call_1', name: 'read', arguments: { file_path: 'shot.png' } },
|
|
121
|
-
{ id: 'call_2', name: 'list', arguments: { path: 'src' } },
|
|
122
|
-
],
|
|
123
|
-
},
|
|
124
|
-
{ role: 'tool', toolCallId: 'call_1', content: mixedImageContent() },
|
|
125
|
-
{ role: 'tool', toolCallId: 'call_2', content: 'second result' },
|
|
126
|
-
];
|
|
127
|
-
const contents = toGeminiContents(history, 'gemini-2.5-pro');
|
|
128
|
-
assert.equal(contents[1].parts.length, 2);
|
|
129
|
-
assert.equal('id' in contents[1].parts[0].functionCall, false);
|
|
130
|
-
assert.equal(contents[2].parts.length, 2);
|
|
131
|
-
assert.equal(contents[2].parts.every((part) => part?.functionResponse), true);
|
|
132
|
-
assert.equal('id' in contents[2].parts[0].functionResponse, false);
|
|
133
|
-
assert.equal('parts' in contents[2].parts[0].functionResponse, false);
|
|
134
|
-
assert.deepEqual(contents[3].parts, [{
|
|
135
|
-
inlineData: {
|
|
136
|
-
mimeType: 'image/png',
|
|
137
|
-
data: IMAGE_DATA,
|
|
138
|
-
displayName: 'tool_media_1',
|
|
139
|
-
},
|
|
140
|
-
}]);
|
|
141
|
-
assert.equal(occurrences(contents, 'Image read successfully'), 1);
|
|
142
|
-
});
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { test } from 'node:test';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
codexWireSendOpts,
|
|
6
|
-
ensureCodexWireSessionId,
|
|
7
|
-
isUuidV7,
|
|
8
|
-
mintUuidV7,
|
|
9
|
-
} from '../session/manager/session-id.mjs';
|
|
10
|
-
import { buildStableProviderPromptCacheKey } from '../agent-runtime/cache-strategy.mjs';
|
|
11
|
-
import {
|
|
12
|
-
_codexWsCompatibilityHeaders,
|
|
13
|
-
_withCodexWsClientMetadata,
|
|
14
|
-
} from './openai-codex-metadata.mjs';
|
|
15
|
-
import { codexOriginator, codexUserAgent } from './codex-client-meta.mjs';
|
|
16
|
-
|
|
17
|
-
test('Codex wire identity is a real time-based UUIDv7 and remains session-stable', () => {
|
|
18
|
-
const now = Date.now();
|
|
19
|
-
const first = mintUuidV7(now);
|
|
20
|
-
const second = mintUuidV7(now);
|
|
21
|
-
assert.equal(isUuidV7(first), true);
|
|
22
|
-
assert.equal(isUuidV7(second), true);
|
|
23
|
-
assert.notEqual(first, second);
|
|
24
|
-
assert.equal(Number.parseInt(first.replace(/-/g, '').slice(0, 12), 16), now);
|
|
25
|
-
|
|
26
|
-
const session = { provider: 'openai-oauth' };
|
|
27
|
-
const sessionId = ensureCodexWireSessionId(session);
|
|
28
|
-
assert.equal(isUuidV7(sessionId), true);
|
|
29
|
-
assert.equal(ensureCodexWireSessionId(session), sessionId);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test('Codex cache key and every wire session identity use the same UUIDv7', () => {
|
|
33
|
-
const sessionId = mintUuidV7();
|
|
34
|
-
const turnStartedAtUnixMs = Date.now();
|
|
35
|
-
const turnId = mintUuidV7(turnStartedAtUnixMs);
|
|
36
|
-
const session = {
|
|
37
|
-
provider: 'openai-oauth',
|
|
38
|
-
id: 'exec_internal_id',
|
|
39
|
-
codexWireSessionId: sessionId,
|
|
40
|
-
promptCacheKey: 'mixdog-codex',
|
|
41
|
-
};
|
|
42
|
-
const promptCacheKey = buildStableProviderPromptCacheKey('openai-oauth', {
|
|
43
|
-
sessionId: session.id,
|
|
44
|
-
codexSessionId: sessionId,
|
|
45
|
-
codexThreadId: sessionId,
|
|
46
|
-
session,
|
|
47
|
-
});
|
|
48
|
-
assert.equal(promptCacheKey, sessionId);
|
|
49
|
-
// The reference client derives its User-Agent from the originator, so the
|
|
50
|
-
// pair can never disagree on the wire.
|
|
51
|
-
assert.equal(codexUserAgent().startsWith(`${codexOriginator()}/`), true);
|
|
52
|
-
|
|
53
|
-
const frame = _withCodexWsClientMetadata(
|
|
54
|
-
{ prompt_cache_key: promptCacheKey },
|
|
55
|
-
{},
|
|
56
|
-
true,
|
|
57
|
-
{
|
|
58
|
-
cacheKey: promptCacheKey,
|
|
59
|
-
poolKey: session.id,
|
|
60
|
-
sendOpts: {
|
|
61
|
-
codexSessionId: sessionId,
|
|
62
|
-
codexThreadId: sessionId,
|
|
63
|
-
turnId,
|
|
64
|
-
windowId: `${sessionId}:0`,
|
|
65
|
-
turnStartedAtUnixMs,
|
|
66
|
-
session,
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
);
|
|
70
|
-
assert.equal(frame.prompt_cache_key, sessionId);
|
|
71
|
-
assert.equal(frame.client_metadata.session_id, sessionId);
|
|
72
|
-
assert.equal(frame.client_metadata.thread_id, sessionId);
|
|
73
|
-
assert.equal(frame.client_metadata.turn_id, turnId);
|
|
74
|
-
assert.equal(frame.client_metadata['x-codex-window-id'], `${sessionId}:0`);
|
|
75
|
-
const turnMetadata = JSON.parse(frame.client_metadata['x-codex-turn-metadata']);
|
|
76
|
-
assert.equal(turnMetadata.session_id, sessionId);
|
|
77
|
-
assert.equal(turnMetadata.thread_id, sessionId);
|
|
78
|
-
assert.equal(turnMetadata.turn_id, turnId);
|
|
79
|
-
assert.match(turnMetadata.installation_id, /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/);
|
|
80
|
-
assert.equal(turnMetadata.agent_name, '/root');
|
|
81
|
-
assert.equal(turnMetadata.sandbox, 'none');
|
|
82
|
-
assert.equal(turnMetadata.sandbox_mode, 'danger-full-access');
|
|
83
|
-
assert.equal(turnMetadata.auto_review_enabled, false);
|
|
84
|
-
assert.equal(turnMetadata.node_repl_auto_review_required, false);
|
|
85
|
-
assert.equal(turnMetadata.node_repl_disabled, false);
|
|
86
|
-
assert.equal(turnMetadata.turn_started_at_unix_ms, turnStartedAtUnixMs);
|
|
87
|
-
|
|
88
|
-
const prewarmHeaders = _codexWsCompatibilityHeaders({
|
|
89
|
-
cacheKey: promptCacheKey,
|
|
90
|
-
poolKey: session.id,
|
|
91
|
-
model: 'gpt-5.6-sol',
|
|
92
|
-
handshake: true,
|
|
93
|
-
sendOpts: {
|
|
94
|
-
codexSessionId: sessionId,
|
|
95
|
-
codexThreadId: sessionId,
|
|
96
|
-
requestKind: 'prewarm',
|
|
97
|
-
session,
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
assert.equal(prewarmHeaders['session-id'], sessionId);
|
|
101
|
-
assert.equal(prewarmHeaders['thread-id'], sessionId);
|
|
102
|
-
assert.equal(prewarmHeaders['x-client-request-id'], sessionId);
|
|
103
|
-
assert.equal('x-codex-installation-id' in prewarmHeaders, false);
|
|
104
|
-
const prewarmMetadata = JSON.parse(prewarmHeaders['x-codex-turn-metadata']);
|
|
105
|
-
assert.equal(prewarmMetadata.request_kind, 'prewarm');
|
|
106
|
-
assert.equal(prewarmMetadata.turn_id, '');
|
|
107
|
-
assert.equal(prewarmMetadata.installation_id, turnMetadata.installation_id);
|
|
108
|
-
assert.equal('turn_started_at_unix_ms' in prewarmMetadata, false);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
// A compaction summary is a request of the same session: same thread identity,
|
|
112
|
-
// same window, same prompt-cache slot — only the request kind and turn id move.
|
|
113
|
-
test('compaction shares the session identity and cache slot with its turns', () => {
|
|
114
|
-
const session = { provider: 'openai-oauth', id: 'sess_internal_1' };
|
|
115
|
-
const turn = codexWireSendOpts(session, {
|
|
116
|
-
turnId: mintUuidV7(),
|
|
117
|
-
startedAtMs: Date.now(),
|
|
118
|
-
});
|
|
119
|
-
const compaction = codexWireSendOpts(session, { requestKind: 'compaction' });
|
|
120
|
-
|
|
121
|
-
assert.equal(compaction.codexSessionId, turn.codexSessionId);
|
|
122
|
-
assert.equal(compaction.codexThreadId, turn.codexThreadId);
|
|
123
|
-
assert.equal(compaction.windowId, turn.windowId);
|
|
124
|
-
assert.equal(turn.requestKind, 'turn');
|
|
125
|
-
assert.equal(compaction.requestKind, 'compaction');
|
|
126
|
-
assert.notEqual(compaction.turnId, turn.turnId);
|
|
127
|
-
assert.equal(isUuidV7(compaction.turnId), true);
|
|
128
|
-
|
|
129
|
-
// The compaction call runs on its own socket bucket (`:compact` session id)
|
|
130
|
-
// yet must still resolve to the turn's prompt-cache key.
|
|
131
|
-
assert.equal(
|
|
132
|
-
buildStableProviderPromptCacheKey('openai-oauth', {
|
|
133
|
-
sessionId: `${session.id}:compact`,
|
|
134
|
-
session,
|
|
135
|
-
...compaction,
|
|
136
|
-
}),
|
|
137
|
-
buildStableProviderPromptCacheKey('openai-oauth', {
|
|
138
|
-
sessionId: session.id,
|
|
139
|
-
session,
|
|
140
|
-
...turn,
|
|
141
|
-
}),
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
const frame = _withCodexWsClientMetadata({}, {}, true, {
|
|
145
|
-
cacheKey: compaction.codexSessionId,
|
|
146
|
-
poolKey: `${session.id}:compact`,
|
|
147
|
-
sendOpts: { ...compaction, session },
|
|
148
|
-
});
|
|
149
|
-
const turnMetadata = JSON.parse(frame.client_metadata['x-codex-turn-metadata']);
|
|
150
|
-
assert.equal(turnMetadata.request_kind, 'compaction');
|
|
151
|
-
assert.equal(turnMetadata.session_id, turn.codexSessionId);
|
|
152
|
-
assert.equal(turnMetadata.thread_id, turn.codexThreadId);
|
|
153
|
-
});
|