@getpaseo/server 0.1.37 → 0.1.38
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/dist/scripts/dev-runner.js +1 -1
- package/dist/scripts/dev-runner.js.map +1 -1
- package/dist/scripts/{daemon-runner.js → supervisor-entrypoint.js} +7 -9
- package/dist/scripts/supervisor-entrypoint.js.map +1 -0
- package/dist/scripts/supervisor.js +17 -1
- package/dist/scripts/supervisor.js.map +1 -1
- package/dist/server/server/bootstrap.d.ts +0 -4
- package/dist/server/server/bootstrap.d.ts.map +1 -1
- package/dist/server/server/bootstrap.js +8 -22
- package/dist/server/server/bootstrap.js.map +1 -1
- package/dist/server/server/index.js +0 -4
- package/dist/server/server/index.js.map +1 -1
- package/dist/server/server/pid-lock.d.ts +7 -2
- package/dist/server/server/pid-lock.d.ts.map +1 -1
- package/dist/server/server/pid-lock.js +21 -0
- package/dist/server/server/pid-lock.js.map +1 -1
- package/dist/server/server/session.d.ts.map +1 -1
- package/dist/server/server/session.js +2 -2
- package/dist/server/server/session.js.map +1 -1
- package/dist/src/server/pid-lock.js +21 -0
- package/dist/src/server/pid-lock.js.map +1 -1
- package/package.json +3 -3
- package/dist/scripts/daemon-runner.js.map +0 -1
- package/dist/src/server/agent/activity-curator.js +0 -243
- package/dist/src/server/agent/activity-curator.js.map +0 -1
- package/dist/src/server/agent/agent-manager.js +0 -1855
- package/dist/src/server/agent/agent-manager.js.map +0 -1
- package/dist/src/server/agent/agent-metadata-generator.js +0 -161
- package/dist/src/server/agent/agent-metadata-generator.js.map +0 -1
- package/dist/src/server/agent/agent-projections.js +0 -254
- package/dist/src/server/agent/agent-projections.js.map +0 -1
- package/dist/src/server/agent/agent-response-loop.js +0 -304
- package/dist/src/server/agent/agent-response-loop.js.map +0 -1
- package/dist/src/server/agent/agent-sdk-types.js +0 -12
- package/dist/src/server/agent/agent-sdk-types.js.map +0 -1
- package/dist/src/server/agent/agent-storage.js +0 -302
- package/dist/src/server/agent/agent-storage.js.map +0 -1
- package/dist/src/server/agent/agent-title-limits.js +0 -3
- package/dist/src/server/agent/agent-title-limits.js.map +0 -1
- package/dist/src/server/agent/audio-utils.js +0 -19
- package/dist/src/server/agent/audio-utils.js.map +0 -1
- package/dist/src/server/agent/dictation-debug.js +0 -50
- package/dist/src/server/agent/dictation-debug.js.map +0 -1
- package/dist/src/server/agent/mcp-server.js +0 -754
- package/dist/src/server/agent/mcp-server.js.map +0 -1
- package/dist/src/server/agent/orchestrator-instructions.js +0 -51
- package/dist/src/server/agent/orchestrator-instructions.js.map +0 -1
- package/dist/src/server/agent/pcm16-resampler.js +0 -63
- package/dist/src/server/agent/pcm16-resampler.js.map +0 -1
- package/dist/src/server/agent/provider-launch-config.js +0 -213
- package/dist/src/server/agent/provider-launch-config.js.map +0 -1
- package/dist/src/server/agent/provider-manifest.js +0 -127
- package/dist/src/server/agent/provider-manifest.js.map +0 -1
- package/dist/src/server/agent/provider-registry.js +0 -45
- package/dist/src/server/agent/provider-registry.js.map +0 -1
- package/dist/src/server/agent/providers/claude/partial-json.js +0 -306
- package/dist/src/server/agent/providers/claude/partial-json.js.map +0 -1
- package/dist/src/server/agent/providers/claude/sdk-model-resolver.js +0 -104
- package/dist/src/server/agent/providers/claude/sdk-model-resolver.js.map +0 -1
- package/dist/src/server/agent/providers/claude/sidechain-tracker.js +0 -230
- package/dist/src/server/agent/providers/claude/sidechain-tracker.js.map +0 -1
- package/dist/src/server/agent/providers/claude/task-notification-tool-call.js +0 -267
- package/dist/src/server/agent/providers/claude/task-notification-tool-call.js.map +0 -1
- package/dist/src/server/agent/providers/claude/tool-call-detail-parser.js +0 -121
- package/dist/src/server/agent/providers/claude/tool-call-detail-parser.js.map +0 -1
- package/dist/src/server/agent/providers/claude/tool-call-mapper.js +0 -252
- package/dist/src/server/agent/providers/claude/tool-call-mapper.js.map +0 -1
- package/dist/src/server/agent/providers/claude-agent.js +0 -3166
- package/dist/src/server/agent/providers/claude-agent.js.map +0 -1
- package/dist/src/server/agent/providers/codex/tool-call-detail-parser.js +0 -104
- package/dist/src/server/agent/providers/codex/tool-call-detail-parser.js.map +0 -1
- package/dist/src/server/agent/providers/codex/tool-call-mapper.js +0 -758
- package/dist/src/server/agent/providers/codex/tool-call-mapper.js.map +0 -1
- package/dist/src/server/agent/providers/codex-app-server-agent.js +0 -2949
- package/dist/src/server/agent/providers/codex-app-server-agent.js.map +0 -1
- package/dist/src/server/agent/providers/codex-rollout-timeline.js +0 -544
- package/dist/src/server/agent/providers/codex-rollout-timeline.js.map +0 -1
- package/dist/src/server/agent/providers/opencode/tool-call-detail-parser.js +0 -39
- package/dist/src/server/agent/providers/opencode/tool-call-detail-parser.js.map +0 -1
- package/dist/src/server/agent/providers/opencode/tool-call-mapper.js +0 -144
- package/dist/src/server/agent/providers/opencode/tool-call-mapper.js.map +0 -1
- package/dist/src/server/agent/providers/opencode-agent.js +0 -1193
- package/dist/src/server/agent/providers/opencode-agent.js.map +0 -1
- package/dist/src/server/agent/providers/tool-call-detail-primitives.js +0 -686
- package/dist/src/server/agent/providers/tool-call-detail-primitives.js.map +0 -1
- package/dist/src/server/agent/providers/tool-call-mapper-utils.js +0 -115
- package/dist/src/server/agent/providers/tool-call-mapper-utils.js.map +0 -1
- package/dist/src/server/agent/recordings-debug.js +0 -19
- package/dist/src/server/agent/recordings-debug.js.map +0 -1
- package/dist/src/server/agent/stt-debug.js +0 -33
- package/dist/src/server/agent/stt-debug.js.map +0 -1
- package/dist/src/server/agent/stt-manager.js +0 -232
- package/dist/src/server/agent/stt-manager.js.map +0 -1
- package/dist/src/server/agent/timeline-append.js +0 -27
- package/dist/src/server/agent/timeline-append.js.map +0 -1
- package/dist/src/server/agent/timeline-projection.js +0 -215
- package/dist/src/server/agent/timeline-projection.js.map +0 -1
- package/dist/src/server/agent/tool-name-normalization.js +0 -45
- package/dist/src/server/agent/tool-name-normalization.js.map +0 -1
- package/dist/src/server/agent/tts-debug.js +0 -24
- package/dist/src/server/agent/tts-debug.js.map +0 -1
- package/dist/src/server/agent/tts-manager.js +0 -374
- package/dist/src/server/agent/tts-manager.js.map +0 -1
- package/dist/src/server/agent/wait-for-agent-tracker.js +0 -53
- package/dist/src/server/agent/wait-for-agent-tracker.js.map +0 -1
- package/dist/src/server/agent-attention-policy.js +0 -40
- package/dist/src/server/agent-attention-policy.js.map +0 -1
- package/dist/src/server/allowed-hosts.js +0 -94
- package/dist/src/server/allowed-hosts.js.map +0 -1
- package/dist/src/server/bootstrap.js +0 -620
- package/dist/src/server/bootstrap.js.map +0 -1
- package/dist/src/server/chat/chat-mentions.js +0 -71
- package/dist/src/server/chat/chat-mentions.js.map +0 -1
- package/dist/src/server/chat/chat-rpc-schemas.js +0 -103
- package/dist/src/server/chat/chat-rpc-schemas.js.map +0 -1
- package/dist/src/server/chat/chat-service.js +0 -330
- package/dist/src/server/chat/chat-service.js.map +0 -1
- package/dist/src/server/chat/chat-types.js +0 -22
- package/dist/src/server/chat/chat-types.js.map +0 -1
- package/dist/src/server/checkout-diff-manager.js +0 -272
- package/dist/src/server/checkout-diff-manager.js.map +0 -1
- package/dist/src/server/checkout-git-utils.js +0 -37
- package/dist/src/server/checkout-git-utils.js.map +0 -1
- package/dist/src/server/client-message-id.js +0 -12
- package/dist/src/server/client-message-id.js.map +0 -1
- package/dist/src/server/config.js +0 -73
- package/dist/src/server/config.js.map +0 -1
- package/dist/src/server/connection-offer.js +0 -59
- package/dist/src/server/connection-offer.js.map +0 -1
- package/dist/src/server/daemon-keypair.js +0 -40
- package/dist/src/server/daemon-keypair.js.map +0 -1
- package/dist/src/server/daemon-version.js +0 -22
- package/dist/src/server/daemon-version.js.map +0 -1
- package/dist/src/server/dictation/dictation-stream-manager.js +0 -571
- package/dist/src/server/dictation/dictation-stream-manager.js.map +0 -1
- package/dist/src/server/file-download/token-store.js +0 -40
- package/dist/src/server/file-download/token-store.js.map +0 -1
- package/dist/src/server/file-explorer/service.js +0 -180
- package/dist/src/server/file-explorer/service.js.map +0 -1
- package/dist/src/server/json-utils.js +0 -45
- package/dist/src/server/json-utils.js.map +0 -1
- package/dist/src/server/loop/rpc-schemas.js +0 -159
- package/dist/src/server/loop/rpc-schemas.js.map +0 -1
- package/dist/src/server/loop-service.js +0 -741
- package/dist/src/server/loop-service.js.map +0 -1
- package/dist/src/server/messages.js +0 -29
- package/dist/src/server/messages.js.map +0 -1
- package/dist/src/server/package-version.js +0 -46
- package/dist/src/server/package-version.js.map +0 -1
- package/dist/src/server/pairing-offer.js +0 -45
- package/dist/src/server/pairing-offer.js.map +0 -1
- package/dist/src/server/pairing-qr.js +0 -45
- package/dist/src/server/pairing-qr.js.map +0 -1
- package/dist/src/server/path-utils.js +0 -20
- package/dist/src/server/path-utils.js.map +0 -1
- package/dist/src/server/persisted-config.js +0 -265
- package/dist/src/server/persisted-config.js.map +0 -1
- package/dist/src/server/persistence-hooks.js +0 -60
- package/dist/src/server/persistence-hooks.js.map +0 -1
- package/dist/src/server/push/push-service.js +0 -68
- package/dist/src/server/push/push-service.js.map +0 -1
- package/dist/src/server/push/token-store.js +0 -70
- package/dist/src/server/push/token-store.js.map +0 -1
- package/dist/src/server/relay-transport.js +0 -461
- package/dist/src/server/relay-transport.js.map +0 -1
- package/dist/src/server/schedule/cron.js +0 -103
- package/dist/src/server/schedule/cron.js.map +0 -1
- package/dist/src/server/schedule/rpc-schemas.js +0 -112
- package/dist/src/server/schedule/rpc-schemas.js.map +0 -1
- package/dist/src/server/schedule/service.js +0 -397
- package/dist/src/server/schedule/service.js.map +0 -1
- package/dist/src/server/schedule/store.js +0 -56
- package/dist/src/server/schedule/store.js.map +0 -1
- package/dist/src/server/schedule/types.js +0 -73
- package/dist/src/server/schedule/types.js.map +0 -1
- package/dist/src/server/server-id.js +0 -63
- package/dist/src/server/server-id.js.map +0 -1
- package/dist/src/server/session.js +0 -6381
- package/dist/src/server/session.js.map +0 -1
- package/dist/src/server/speech/audio.js +0 -101
- package/dist/src/server/speech/audio.js.map +0 -1
- package/dist/src/server/speech/provider-resolver.js +0 -7
- package/dist/src/server/speech/provider-resolver.js.map +0 -1
- package/dist/src/server/speech/providers/local/config.js +0 -74
- package/dist/src/server/speech/providers/local/config.js.map +0 -1
- package/dist/src/server/speech/providers/local/models.js +0 -17
- package/dist/src/server/speech/providers/local/models.js.map +0 -1
- package/dist/src/server/speech/providers/local/pocket/pocket-tts-onnx.js +0 -436
- package/dist/src/server/speech/providers/local/pocket/pocket-tts-onnx.js.map +0 -1
- package/dist/src/server/speech/providers/local/runtime.js +0 -238
- package/dist/src/server/speech/providers/local/runtime.js.map +0 -1
- package/dist/src/server/speech/providers/local/sherpa/model-catalog.js +0 -166
- package/dist/src/server/speech/providers/local/sherpa/model-catalog.js.map +0 -1
- package/dist/src/server/speech/providers/local/sherpa/model-downloader.js +0 -165
- package/dist/src/server/speech/providers/local/sherpa/model-downloader.js.map +0 -1
- package/dist/src/server/speech/providers/local/sherpa/sherpa-offline-recognizer.js +0 -73
- package/dist/src/server/speech/providers/local/sherpa/sherpa-offline-recognizer.js.map +0 -1
- package/dist/src/server/speech/providers/local/sherpa/sherpa-online-recognizer.js +0 -84
- package/dist/src/server/speech/providers/local/sherpa/sherpa-online-recognizer.js.map +0 -1
- package/dist/src/server/speech/providers/local/sherpa/sherpa-onnx-loader.js +0 -11
- package/dist/src/server/speech/providers/local/sherpa/sherpa-onnx-loader.js.map +0 -1
- package/dist/src/server/speech/providers/local/sherpa/sherpa-onnx-node-loader.js +0 -102
- package/dist/src/server/speech/providers/local/sherpa/sherpa-onnx-node-loader.js.map +0 -1
- package/dist/src/server/speech/providers/local/sherpa/sherpa-parakeet-realtime-session.js +0 -135
- package/dist/src/server/speech/providers/local/sherpa/sherpa-parakeet-realtime-session.js.map +0 -1
- package/dist/src/server/speech/providers/local/sherpa/sherpa-parakeet-stt.js +0 -130
- package/dist/src/server/speech/providers/local/sherpa/sherpa-parakeet-stt.js.map +0 -1
- package/dist/src/server/speech/providers/local/sherpa/sherpa-realtime-session.js +0 -110
- package/dist/src/server/speech/providers/local/sherpa/sherpa-realtime-session.js.map +0 -1
- package/dist/src/server/speech/providers/local/sherpa/sherpa-stt.js +0 -138
- package/dist/src/server/speech/providers/local/sherpa/sherpa-stt.js.map +0 -1
- package/dist/src/server/speech/providers/local/sherpa/sherpa-tts.js +0 -98
- package/dist/src/server/speech/providers/local/sherpa/sherpa-tts.js.map +0 -1
- package/dist/src/server/speech/providers/local/sherpa/silero-vad-provider.js +0 -23
- package/dist/src/server/speech/providers/local/sherpa/silero-vad-provider.js.map +0 -1
- package/dist/src/server/speech/providers/local/sherpa/silero-vad-session.js +0 -107
- package/dist/src/server/speech/providers/local/sherpa/silero-vad-session.js.map +0 -1
- package/dist/src/server/speech/providers/openai/config.js +0 -80
- package/dist/src/server/speech/providers/openai/config.js.map +0 -1
- package/dist/src/server/speech/providers/openai/realtime-transcription-session.js +0 -168
- package/dist/src/server/speech/providers/openai/realtime-transcription-session.js.map +0 -1
- package/dist/src/server/speech/providers/openai/runtime.js +0 -112
- package/dist/src/server/speech/providers/openai/runtime.js.map +0 -1
- package/dist/src/server/speech/providers/openai/stt.js +0 -206
- package/dist/src/server/speech/providers/openai/stt.js.map +0 -1
- package/dist/src/server/speech/providers/openai/tts.js +0 -46
- package/dist/src/server/speech/providers/openai/tts.js.map +0 -1
- package/dist/src/server/speech/speech-config-resolver.js +0 -102
- package/dist/src/server/speech/speech-config-resolver.js.map +0 -1
- package/dist/src/server/speech/speech-provider.js +0 -2
- package/dist/src/server/speech/speech-provider.js.map +0 -1
- package/dist/src/server/speech/speech-runtime.js +0 -530
- package/dist/src/server/speech/speech-runtime.js.map +0 -1
- package/dist/src/server/speech/speech-types.js +0 -8
- package/dist/src/server/speech/speech-types.js.map +0 -1
- package/dist/src/server/speech/turn-detection-provider.js +0 -2
- package/dist/src/server/speech/turn-detection-provider.js.map +0 -1
- package/dist/src/server/utils/diff-highlighter.js +0 -257
- package/dist/src/server/utils/diff-highlighter.js.map +0 -1
- package/dist/src/server/voice/fixed-duration-pcm-ring-buffer.js +0 -35
- package/dist/src/server/voice/fixed-duration-pcm-ring-buffer.js.map +0 -1
- package/dist/src/server/voice/voice-turn-controller.js +0 -159
- package/dist/src/server/voice/voice-turn-controller.js.map +0 -1
- package/dist/src/server/voice-config.js +0 -51
- package/dist/src/server/voice-config.js.map +0 -1
- package/dist/src/server/voice-mcp-bridge-command.js +0 -31
- package/dist/src/server/voice-mcp-bridge-command.js.map +0 -1
- package/dist/src/server/voice-mcp-bridge.js +0 -109
- package/dist/src/server/voice-mcp-bridge.js.map +0 -1
- package/dist/src/server/voice-permission-policy.js +0 -13
- package/dist/src/server/voice-permission-policy.js.map +0 -1
- package/dist/src/server/voice-types.js +0 -2
- package/dist/src/server/voice-types.js.map +0 -1
- package/dist/src/server/websocket-server.js +0 -1048
- package/dist/src/server/websocket-server.js.map +0 -1
- package/dist/src/server/workspace-registry-bootstrap.js +0 -98
- package/dist/src/server/workspace-registry-bootstrap.js.map +0 -1
- package/dist/src/server/workspace-registry-model.js +0 -175
- package/dist/src/server/workspace-registry-model.js.map +0 -1
- package/dist/src/server/workspace-registry.js +0 -151
- package/dist/src/server/workspace-registry.js.map +0 -1
- package/dist/src/server/worktree-bootstrap.js +0 -508
- package/dist/src/server/worktree-bootstrap.js.map +0 -1
- package/dist/src/shared/agent-attention-notification.js +0 -130
- package/dist/src/shared/agent-attention-notification.js.map +0 -1
- package/dist/src/shared/agent-lifecycle.js +0 -8
- package/dist/src/shared/agent-lifecycle.js.map +0 -1
- package/dist/src/shared/connection-offer.js +0 -17
- package/dist/src/shared/connection-offer.js.map +0 -1
- package/dist/src/shared/daemon-endpoints.js +0 -122
- package/dist/src/shared/daemon-endpoints.js.map +0 -1
- package/dist/src/shared/messages.js +0 -2107
- package/dist/src/shared/messages.js.map +0 -1
- package/dist/src/shared/path-utils.js +0 -16
- package/dist/src/shared/path-utils.js.map +0 -1
- package/dist/src/shared/terminal-stream-protocol.js +0 -99
- package/dist/src/shared/terminal-stream-protocol.js.map +0 -1
- package/dist/src/shared/tool-call-display.js +0 -122
- package/dist/src/shared/tool-call-display.js.map +0 -1
- package/dist/src/terminal/terminal-manager.js +0 -136
- package/dist/src/terminal/terminal-manager.js.map +0 -1
- package/dist/src/terminal/terminal.js +0 -333
- package/dist/src/terminal/terminal.js.map +0 -1
- package/dist/src/utils/checkout-git.js +0 -1518
- package/dist/src/utils/checkout-git.js.map +0 -1
- package/dist/src/utils/directory-suggestions.js +0 -671
- package/dist/src/utils/directory-suggestions.js.map +0 -1
- package/dist/src/utils/path.js +0 -15
- package/dist/src/utils/path.js.map +0 -1
- package/dist/src/utils/project-icon.js +0 -389
- package/dist/src/utils/project-icon.js.map +0 -1
- package/dist/src/utils/worktree-metadata.js +0 -116
- package/dist/src/utils/worktree-metadata.js.map +0 -1
- package/dist/src/utils/worktree.js +0 -744
- package/dist/src/utils/worktree.js.map +0 -1
|
@@ -1,758 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { extractCodexShellOutput, truncateDiffText } from "../tool-call-mapper-utils.js";
|
|
3
|
-
import { deriveCodexToolDetail, normalizeCodexFilePath } from "./tool-call-detail-parser.js";
|
|
4
|
-
const FAILED_STATUSES = new Set(["failed", "error", "errored", "rejected", "denied"]);
|
|
5
|
-
const CANCELED_STATUSES = new Set(["canceled", "cancelled", "interrupted", "aborted"]);
|
|
6
|
-
const COMPLETED_STATUSES = new Set(["completed", "complete", "done", "success", "succeeded"]);
|
|
7
|
-
const CodexCommandValueSchema = z.union([z.string(), z.array(z.string())]);
|
|
8
|
-
const CodexToolCallStatusSchema = z.enum(["running", "completed", "failed", "canceled"]);
|
|
9
|
-
const CodexRolloutToolCallParamsSchema = z
|
|
10
|
-
.object({
|
|
11
|
-
callId: z.string().optional().nullable(),
|
|
12
|
-
name: z.string().min(1),
|
|
13
|
-
input: z.unknown().optional(),
|
|
14
|
-
output: z.unknown().optional(),
|
|
15
|
-
error: z.unknown().optional(),
|
|
16
|
-
})
|
|
17
|
-
.passthrough();
|
|
18
|
-
const CodexNormalizedToolCallPass1Schema = z
|
|
19
|
-
.object({
|
|
20
|
-
callId: z.string().min(1),
|
|
21
|
-
name: z.string().min(1),
|
|
22
|
-
input: z.unknown().nullable(),
|
|
23
|
-
output: z.unknown().nullable(),
|
|
24
|
-
status: CodexToolCallStatusSchema,
|
|
25
|
-
error: z.unknown().nullable(),
|
|
26
|
-
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
27
|
-
cwd: z.string().nullable().optional(),
|
|
28
|
-
})
|
|
29
|
-
.passthrough();
|
|
30
|
-
const CodexShellToolNameSchema = z.union([
|
|
31
|
-
z.literal("Bash"),
|
|
32
|
-
z.literal("shell"),
|
|
33
|
-
z.literal("bash"),
|
|
34
|
-
z.literal("exec"),
|
|
35
|
-
z.literal("exec_command"),
|
|
36
|
-
z.literal("command"),
|
|
37
|
-
]);
|
|
38
|
-
const CodexReadToolNameSchema = z.union([z.literal("read"), z.literal("read_file")]);
|
|
39
|
-
const CodexWriteToolNameSchema = z.union([
|
|
40
|
-
z.literal("write"),
|
|
41
|
-
z.literal("write_file"),
|
|
42
|
-
z.literal("create_file"),
|
|
43
|
-
]);
|
|
44
|
-
const CodexEditToolNameSchema = z.union([
|
|
45
|
-
z.literal("edit"),
|
|
46
|
-
z.literal("apply_patch"),
|
|
47
|
-
z.literal("apply_diff"),
|
|
48
|
-
]);
|
|
49
|
-
const CodexSearchToolNameSchema = z.union([z.literal("search"), z.literal("web_search")]);
|
|
50
|
-
const CodexSpeakToolNameSchema = z.literal("paseo.speak");
|
|
51
|
-
const CodexToolKindSchema = z.enum([
|
|
52
|
-
"shell",
|
|
53
|
-
"read",
|
|
54
|
-
"write",
|
|
55
|
-
"edit",
|
|
56
|
-
"search",
|
|
57
|
-
"speak",
|
|
58
|
-
"unknown",
|
|
59
|
-
]);
|
|
60
|
-
const CodexToolCallPass2BaseSchema = CodexNormalizedToolCallPass1Schema.extend({
|
|
61
|
-
toolKind: CodexToolKindSchema,
|
|
62
|
-
});
|
|
63
|
-
const CodexToolCallPass2EnvelopeSchema = z.union([
|
|
64
|
-
CodexNormalizedToolCallPass1Schema.extend({
|
|
65
|
-
name: CodexShellToolNameSchema,
|
|
66
|
-
}).transform((envelope) => ({ ...envelope, toolKind: "shell" })),
|
|
67
|
-
CodexNormalizedToolCallPass1Schema.extend({
|
|
68
|
-
name: CodexReadToolNameSchema,
|
|
69
|
-
}).transform((envelope) => ({ ...envelope, toolKind: "read" })),
|
|
70
|
-
CodexNormalizedToolCallPass1Schema.extend({
|
|
71
|
-
name: CodexWriteToolNameSchema,
|
|
72
|
-
}).transform((envelope) => ({ ...envelope, toolKind: "write" })),
|
|
73
|
-
CodexNormalizedToolCallPass1Schema.extend({
|
|
74
|
-
name: CodexEditToolNameSchema,
|
|
75
|
-
}).transform((envelope) => ({ ...envelope, toolKind: "edit" })),
|
|
76
|
-
CodexNormalizedToolCallPass1Schema.extend({
|
|
77
|
-
name: CodexSearchToolNameSchema,
|
|
78
|
-
}).transform((envelope) => ({ ...envelope, toolKind: "search" })),
|
|
79
|
-
CodexNormalizedToolCallPass1Schema.extend({
|
|
80
|
-
name: CodexSpeakToolNameSchema,
|
|
81
|
-
}).transform((envelope) => ({ ...envelope, toolKind: "speak" })),
|
|
82
|
-
CodexNormalizedToolCallPass1Schema.transform((envelope) => ({
|
|
83
|
-
...envelope,
|
|
84
|
-
name: envelope.name.trim(),
|
|
85
|
-
toolKind: "unknown",
|
|
86
|
-
})),
|
|
87
|
-
]);
|
|
88
|
-
const CodexNormalizedToolCallPass2Schema = z.discriminatedUnion("toolKind", [
|
|
89
|
-
CodexToolCallPass2BaseSchema.extend({
|
|
90
|
-
toolKind: z.literal("shell"),
|
|
91
|
-
name: CodexShellToolNameSchema,
|
|
92
|
-
}),
|
|
93
|
-
CodexToolCallPass2BaseSchema.extend({
|
|
94
|
-
toolKind: z.literal("read"),
|
|
95
|
-
name: CodexReadToolNameSchema,
|
|
96
|
-
}),
|
|
97
|
-
CodexToolCallPass2BaseSchema.extend({
|
|
98
|
-
toolKind: z.literal("write"),
|
|
99
|
-
name: CodexWriteToolNameSchema,
|
|
100
|
-
}),
|
|
101
|
-
CodexToolCallPass2BaseSchema.extend({
|
|
102
|
-
toolKind: z.literal("edit"),
|
|
103
|
-
name: CodexEditToolNameSchema,
|
|
104
|
-
}),
|
|
105
|
-
CodexToolCallPass2BaseSchema.extend({
|
|
106
|
-
toolKind: z.literal("search"),
|
|
107
|
-
name: CodexSearchToolNameSchema,
|
|
108
|
-
}),
|
|
109
|
-
CodexToolCallPass2BaseSchema.extend({
|
|
110
|
-
toolKind: z.literal("speak"),
|
|
111
|
-
name: CodexSpeakToolNameSchema,
|
|
112
|
-
}),
|
|
113
|
-
CodexToolCallPass2BaseSchema.extend({
|
|
114
|
-
toolKind: z.literal("unknown"),
|
|
115
|
-
}),
|
|
116
|
-
]);
|
|
117
|
-
function toToolCallTimelineItem(envelope) {
|
|
118
|
-
const name = envelope.toolKind === "speak" ? "speak" : envelope.name;
|
|
119
|
-
const parsedDetail = deriveCodexToolDetail({
|
|
120
|
-
name,
|
|
121
|
-
input: envelope.input,
|
|
122
|
-
output: envelope.output,
|
|
123
|
-
cwd: envelope.cwd ?? null,
|
|
124
|
-
});
|
|
125
|
-
const detail = envelope.toolKind === "edit" &&
|
|
126
|
-
envelope.status !== "running" &&
|
|
127
|
-
!hasRenderableEditDetail(parsedDetail)
|
|
128
|
-
? {
|
|
129
|
-
type: "unknown",
|
|
130
|
-
input: envelope.input,
|
|
131
|
-
output: envelope.output,
|
|
132
|
-
}
|
|
133
|
-
: parsedDetail;
|
|
134
|
-
if (envelope.status === "failed") {
|
|
135
|
-
return {
|
|
136
|
-
type: "tool_call",
|
|
137
|
-
callId: envelope.callId,
|
|
138
|
-
name,
|
|
139
|
-
status: "failed",
|
|
140
|
-
error: envelope.error ?? { message: "Tool call failed" },
|
|
141
|
-
detail,
|
|
142
|
-
...(envelope.metadata ? { metadata: envelope.metadata } : {}),
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
return {
|
|
146
|
-
type: "tool_call",
|
|
147
|
-
callId: envelope.callId,
|
|
148
|
-
name,
|
|
149
|
-
status: envelope.status,
|
|
150
|
-
error: null,
|
|
151
|
-
detail,
|
|
152
|
-
...(envelope.metadata ? { metadata: envelope.metadata } : {}),
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
// ---------------------------------------------------------------------------
|
|
156
|
-
// Thread-item parsing
|
|
157
|
-
// ---------------------------------------------------------------------------
|
|
158
|
-
const CodexCommandExecutionItemSchema = z
|
|
159
|
-
.object({
|
|
160
|
-
type: z.literal("commandExecution"),
|
|
161
|
-
id: z.string().min(1),
|
|
162
|
-
status: z.string().optional(),
|
|
163
|
-
error: z.unknown().optional(),
|
|
164
|
-
command: CodexCommandValueSchema.optional(),
|
|
165
|
-
cwd: z.string().optional(),
|
|
166
|
-
aggregatedOutput: z.string().optional(),
|
|
167
|
-
exitCode: z.number().nullable().optional(),
|
|
168
|
-
})
|
|
169
|
-
.passthrough();
|
|
170
|
-
const CodexFileChangeItemSchema = z
|
|
171
|
-
.object({
|
|
172
|
-
type: z.literal("fileChange"),
|
|
173
|
-
id: z.string().min(1),
|
|
174
|
-
status: z.string().optional(),
|
|
175
|
-
error: z.unknown().optional(),
|
|
176
|
-
changes: z.unknown().optional(),
|
|
177
|
-
})
|
|
178
|
-
.passthrough();
|
|
179
|
-
const CodexMcpToolCallItemSchema = z
|
|
180
|
-
.object({
|
|
181
|
-
type: z.literal("mcpToolCall"),
|
|
182
|
-
id: z.string().min(1),
|
|
183
|
-
status: z.string().optional(),
|
|
184
|
-
error: z.unknown().optional(),
|
|
185
|
-
tool: z.string().min(1),
|
|
186
|
-
server: z.string().optional(),
|
|
187
|
-
arguments: z.unknown().optional(),
|
|
188
|
-
result: z.unknown().optional(),
|
|
189
|
-
})
|
|
190
|
-
.passthrough();
|
|
191
|
-
const CodexWebSearchItemSchema = z
|
|
192
|
-
.object({
|
|
193
|
-
type: z.literal("webSearch"),
|
|
194
|
-
id: z.string().min(1),
|
|
195
|
-
status: z.string().optional(),
|
|
196
|
-
error: z.unknown().optional(),
|
|
197
|
-
query: z.string().optional(),
|
|
198
|
-
action: z.unknown().optional(),
|
|
199
|
-
})
|
|
200
|
-
.passthrough();
|
|
201
|
-
const CodexThreadItemSchema = z.discriminatedUnion("type", [
|
|
202
|
-
CodexCommandExecutionItemSchema,
|
|
203
|
-
CodexFileChangeItemSchema,
|
|
204
|
-
CodexMcpToolCallItemSchema,
|
|
205
|
-
CodexWebSearchItemSchema,
|
|
206
|
-
]);
|
|
207
|
-
function maybeUnwrapShellWrapperCommand(command) {
|
|
208
|
-
const trimmed = command.trim();
|
|
209
|
-
const wrapperMatch = trimmed.match(/^(?:\/bin\/)?(?:zsh|bash|sh)\s+-(?:lc|c)\s+([\s\S]+)$/);
|
|
210
|
-
if (!wrapperMatch) {
|
|
211
|
-
return trimmed;
|
|
212
|
-
}
|
|
213
|
-
const candidate = wrapperMatch[1]?.trim() ?? "";
|
|
214
|
-
if (!candidate) {
|
|
215
|
-
return trimmed;
|
|
216
|
-
}
|
|
217
|
-
if ((candidate.startsWith('"') && candidate.endsWith('"')) ||
|
|
218
|
-
(candidate.startsWith("'") && candidate.endsWith("'"))) {
|
|
219
|
-
return candidate.slice(1, -1);
|
|
220
|
-
}
|
|
221
|
-
return candidate;
|
|
222
|
-
}
|
|
223
|
-
function normalizeCommandExecutionCommand(value) {
|
|
224
|
-
if (typeof value === "string") {
|
|
225
|
-
const normalized = maybeUnwrapShellWrapperCommand(value);
|
|
226
|
-
return normalized.length > 0 ? normalized : undefined;
|
|
227
|
-
}
|
|
228
|
-
if (!Array.isArray(value)) {
|
|
229
|
-
return undefined;
|
|
230
|
-
}
|
|
231
|
-
const parts = value
|
|
232
|
-
.filter((entry) => typeof entry === "string")
|
|
233
|
-
.map((entry) => entry.trim())
|
|
234
|
-
.filter((entry) => entry.length > 0);
|
|
235
|
-
if (parts.length === 0) {
|
|
236
|
-
return undefined;
|
|
237
|
-
}
|
|
238
|
-
if (parts.length >= 3 && (parts[1] === "-lc" || parts[1] === "-c")) {
|
|
239
|
-
const unwrapped = parts[2]?.trim();
|
|
240
|
-
return unwrapped && unwrapped.length > 0 ? unwrapped : undefined;
|
|
241
|
-
}
|
|
242
|
-
return parts.join(" ");
|
|
243
|
-
}
|
|
244
|
-
function looksLikeUnifiedDiff(text) {
|
|
245
|
-
const normalized = text.trimStart();
|
|
246
|
-
if (!normalized) {
|
|
247
|
-
return false;
|
|
248
|
-
}
|
|
249
|
-
return (normalized.startsWith("diff --git") ||
|
|
250
|
-
normalized.startsWith("@@") ||
|
|
251
|
-
normalized.startsWith("--- ") ||
|
|
252
|
-
normalized.startsWith("+++ "));
|
|
253
|
-
}
|
|
254
|
-
function isRecord(value) {
|
|
255
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
256
|
-
}
|
|
257
|
-
function parseCodexApplyPatchDirective(line) {
|
|
258
|
-
const trimmed = line.trim();
|
|
259
|
-
if (trimmed.startsWith("*** Add File:")) {
|
|
260
|
-
return { kind: "add", path: trimmed.replace("*** Add File:", "").trim() };
|
|
261
|
-
}
|
|
262
|
-
if (trimmed.startsWith("*** Update File:")) {
|
|
263
|
-
return { kind: "update", path: trimmed.replace("*** Update File:", "").trim() };
|
|
264
|
-
}
|
|
265
|
-
if (trimmed.startsWith("*** Delete File:")) {
|
|
266
|
-
return { kind: "delete", path: trimmed.replace("*** Delete File:", "").trim() };
|
|
267
|
-
}
|
|
268
|
-
return null;
|
|
269
|
-
}
|
|
270
|
-
function extractPatchPrimaryFilePath(patch) {
|
|
271
|
-
for (const line of patch.split(/\r?\n/)) {
|
|
272
|
-
const directive = parseCodexApplyPatchDirective(line);
|
|
273
|
-
if (directive && directive.path.length > 0) {
|
|
274
|
-
return directive.path;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
return undefined;
|
|
278
|
-
}
|
|
279
|
-
function looksLikeCodexApplyPatch(text) {
|
|
280
|
-
const normalized = text.trimStart();
|
|
281
|
-
if (!normalized) {
|
|
282
|
-
return false;
|
|
283
|
-
}
|
|
284
|
-
if (normalized.startsWith("*** Begin Patch")) {
|
|
285
|
-
return true;
|
|
286
|
-
}
|
|
287
|
-
return text.split(/\r?\n/).some((line) => parseCodexApplyPatchDirective(line) !== null);
|
|
288
|
-
}
|
|
289
|
-
function normalizeDiffHeaderPath(rawPath) {
|
|
290
|
-
return rawPath.trim().replace(/^["']+|["']+$/g, "");
|
|
291
|
-
}
|
|
292
|
-
function codexApplyPatchToUnifiedDiff(text) {
|
|
293
|
-
const lines = text.replace(/\r\n/g, "\n").split("\n");
|
|
294
|
-
const output = [];
|
|
295
|
-
let sawDiffContent = false;
|
|
296
|
-
for (const line of lines) {
|
|
297
|
-
const directive = parseCodexApplyPatchDirective(line);
|
|
298
|
-
if (directive) {
|
|
299
|
-
const path = normalizeDiffHeaderPath(directive.path);
|
|
300
|
-
if (path.length > 0) {
|
|
301
|
-
if (output.length > 0 && output[output.length - 1] !== "") {
|
|
302
|
-
output.push("");
|
|
303
|
-
}
|
|
304
|
-
const left = directive.kind === "add" ? "/dev/null" : `a/${path}`;
|
|
305
|
-
const right = directive.kind === "delete" ? "/dev/null" : `b/${path}`;
|
|
306
|
-
output.push(`diff --git a/${path} b/${path}`);
|
|
307
|
-
output.push(`--- ${left}`);
|
|
308
|
-
output.push(`+++ ${right}`);
|
|
309
|
-
sawDiffContent = true;
|
|
310
|
-
}
|
|
311
|
-
continue;
|
|
312
|
-
}
|
|
313
|
-
const trimmed = line.trim();
|
|
314
|
-
if (trimmed === "*** Begin Patch" ||
|
|
315
|
-
trimmed === "*** End Patch" ||
|
|
316
|
-
trimmed === "*** End of File" ||
|
|
317
|
-
trimmed.startsWith("*** Move to:")) {
|
|
318
|
-
continue;
|
|
319
|
-
}
|
|
320
|
-
if (line.startsWith("@@")) {
|
|
321
|
-
output.push(line);
|
|
322
|
-
sawDiffContent = true;
|
|
323
|
-
continue;
|
|
324
|
-
}
|
|
325
|
-
if (line.startsWith("+") || line.startsWith("-") || line.startsWith(" ")) {
|
|
326
|
-
output.push(line);
|
|
327
|
-
sawDiffContent = true;
|
|
328
|
-
continue;
|
|
329
|
-
}
|
|
330
|
-
if (line.startsWith("\")) {
|
|
331
|
-
output.push(line);
|
|
332
|
-
sawDiffContent = true;
|
|
333
|
-
continue;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
if (!sawDiffContent) {
|
|
337
|
-
return text;
|
|
338
|
-
}
|
|
339
|
-
const normalized = output.join("\n").trim();
|
|
340
|
-
return normalized.length > 0 ? normalized : text;
|
|
341
|
-
}
|
|
342
|
-
function contentToDeletionDiff(filePath, content) {
|
|
343
|
-
const lines = content.replace(/\r\n/g, "\n").split("\n");
|
|
344
|
-
const output = [];
|
|
345
|
-
output.push(`diff --git a/${filePath} b/${filePath}`);
|
|
346
|
-
output.push(`--- a/${filePath}`);
|
|
347
|
-
output.push(`+++ /dev/null`);
|
|
348
|
-
const nonEmpty = lines.filter((l) => l.length > 0 || lines.indexOf(l) < lines.length - 1);
|
|
349
|
-
if (nonEmpty.length > 0) {
|
|
350
|
-
output.push(`@@ -1,${nonEmpty.length} +0,0 @@`);
|
|
351
|
-
for (const line of nonEmpty) {
|
|
352
|
-
output.push(`-${line}`);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
return output.join("\n");
|
|
356
|
-
}
|
|
357
|
-
function classifyDiffLikeText(text) {
|
|
358
|
-
if (looksLikeUnifiedDiff(text)) {
|
|
359
|
-
return { isDiff: true, text };
|
|
360
|
-
}
|
|
361
|
-
if (looksLikeCodexApplyPatch(text)) {
|
|
362
|
-
return { isDiff: true, text: codexApplyPatchToUnifiedDiff(text) };
|
|
363
|
-
}
|
|
364
|
-
return { isDiff: false, text };
|
|
365
|
-
}
|
|
366
|
-
function asEditTextFields(text) {
|
|
367
|
-
if (typeof text !== "string" || text.length === 0) {
|
|
368
|
-
return {};
|
|
369
|
-
}
|
|
370
|
-
const classified = classifyDiffLikeText(text);
|
|
371
|
-
if (classified.isDiff) {
|
|
372
|
-
return { unifiedDiff: truncateDiffText(classified.text) };
|
|
373
|
-
}
|
|
374
|
-
return { newString: text };
|
|
375
|
-
}
|
|
376
|
-
function normalizeRolloutEditInput(input) {
|
|
377
|
-
if (typeof input === "string") {
|
|
378
|
-
const textFields = asEditTextFields(input);
|
|
379
|
-
const path = extractPatchPrimaryFilePath(input);
|
|
380
|
-
return {
|
|
381
|
-
...(path ? { path } : {}),
|
|
382
|
-
...(textFields.unifiedDiff ? { patch: textFields.unifiedDiff } : {}),
|
|
383
|
-
...(textFields.newString ? { content: textFields.newString } : {}),
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
if (!isRecord(input)) {
|
|
387
|
-
return input;
|
|
388
|
-
}
|
|
389
|
-
const candidatePatchText = (typeof input.patch === "string" && input.patch) ||
|
|
390
|
-
(typeof input.diff === "string" && input.diff) ||
|
|
391
|
-
(typeof input.unified_diff === "string" && input.unified_diff) ||
|
|
392
|
-
(typeof input.unifiedDiff === "string" && input.unifiedDiff) ||
|
|
393
|
-
(typeof input.content === "string" && input.content) ||
|
|
394
|
-
undefined;
|
|
395
|
-
if (!candidatePatchText) {
|
|
396
|
-
return input;
|
|
397
|
-
}
|
|
398
|
-
const textFields = asEditTextFields(candidatePatchText);
|
|
399
|
-
const rawPath = (typeof input.path === "string" && input.path.trim().length > 0 ? input.path : undefined) ||
|
|
400
|
-
(typeof input.file_path === "string" && input.file_path.trim().length > 0
|
|
401
|
-
? input.file_path
|
|
402
|
-
: undefined) ||
|
|
403
|
-
(typeof input.filePath === "string" && input.filePath.trim().length > 0
|
|
404
|
-
? input.filePath
|
|
405
|
-
: undefined) ||
|
|
406
|
-
extractPatchPrimaryFilePath(candidatePatchText);
|
|
407
|
-
const { patch: _patch, diff: _diff, unified_diff: _unifiedDiffSnake, unifiedDiff: _unifiedDiffCamel, ...rest } = input;
|
|
408
|
-
const normalized = {
|
|
409
|
-
...rest,
|
|
410
|
-
...(rawPath ? { path: rawPath } : {}),
|
|
411
|
-
...(textFields.unifiedDiff ? { patch: textFields.unifiedDiff } : {}),
|
|
412
|
-
...(textFields.newString ? { content: textFields.newString } : {}),
|
|
413
|
-
};
|
|
414
|
-
if (textFields.unifiedDiff && "content" in normalized) {
|
|
415
|
-
delete normalized.content;
|
|
416
|
-
}
|
|
417
|
-
return normalized;
|
|
418
|
-
}
|
|
419
|
-
function asEditFileOutputFields(text) {
|
|
420
|
-
if (typeof text !== "string" || text.length === 0) {
|
|
421
|
-
return {};
|
|
422
|
-
}
|
|
423
|
-
const classified = classifyDiffLikeText(text);
|
|
424
|
-
if (classified.isDiff) {
|
|
425
|
-
return { patch: truncateDiffText(classified.text) };
|
|
426
|
-
}
|
|
427
|
-
return { content: text };
|
|
428
|
-
}
|
|
429
|
-
function pickFirstPatchLikeString(values) {
|
|
430
|
-
for (const value of values) {
|
|
431
|
-
if (typeof value === "string" && value.length > 0) {
|
|
432
|
-
return value;
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
return undefined;
|
|
436
|
-
}
|
|
437
|
-
function hasRenderableEditDetail(detail) {
|
|
438
|
-
if (detail.type !== "edit") {
|
|
439
|
-
return true;
|
|
440
|
-
}
|
|
441
|
-
return ((typeof detail.unifiedDiff === "string" && detail.unifiedDiff.trim().length > 0) ||
|
|
442
|
-
(typeof detail.newString === "string" && detail.newString.trim().length > 0) ||
|
|
443
|
-
(typeof detail.oldString === "string" && detail.oldString.trim().length > 0));
|
|
444
|
-
}
|
|
445
|
-
function resolveStatus(rawStatus, error, output) {
|
|
446
|
-
if (error !== undefined && error !== null) {
|
|
447
|
-
return "failed";
|
|
448
|
-
}
|
|
449
|
-
if (typeof rawStatus === "string") {
|
|
450
|
-
const normalized = rawStatus.trim().toLowerCase();
|
|
451
|
-
if (normalized.length > 0) {
|
|
452
|
-
if (FAILED_STATUSES.has(normalized)) {
|
|
453
|
-
return "failed";
|
|
454
|
-
}
|
|
455
|
-
if (CANCELED_STATUSES.has(normalized)) {
|
|
456
|
-
return "canceled";
|
|
457
|
-
}
|
|
458
|
-
if (COMPLETED_STATUSES.has(normalized)) {
|
|
459
|
-
return "completed";
|
|
460
|
-
}
|
|
461
|
-
return "running";
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
return output !== null && output !== undefined ? "completed" : "running";
|
|
465
|
-
}
|
|
466
|
-
function buildMcpToolName(server, tool) {
|
|
467
|
-
const trimmedTool = tool.trim();
|
|
468
|
-
if (!trimmedTool) {
|
|
469
|
-
return "tool";
|
|
470
|
-
}
|
|
471
|
-
const trimmedServer = typeof server === "string" ? server.trim() : "";
|
|
472
|
-
if (trimmedServer.length > 0) {
|
|
473
|
-
return `${trimmedServer}.${trimmedTool}`;
|
|
474
|
-
}
|
|
475
|
-
return trimmedTool;
|
|
476
|
-
}
|
|
477
|
-
function toNullableObject(value) {
|
|
478
|
-
return Object.keys(value).length > 0 ? value : null;
|
|
479
|
-
}
|
|
480
|
-
function toToolCallFromNormalizedEnvelope(envelope) {
|
|
481
|
-
const pass2Envelope = CodexToolCallPass2EnvelopeSchema.safeParse(envelope);
|
|
482
|
-
if (!pass2Envelope.success) {
|
|
483
|
-
return null;
|
|
484
|
-
}
|
|
485
|
-
const parsed = CodexNormalizedToolCallPass2Schema.safeParse(pass2Envelope.data);
|
|
486
|
-
if (!parsed.success) {
|
|
487
|
-
return null;
|
|
488
|
-
}
|
|
489
|
-
return toToolCallTimelineItem(parsed.data);
|
|
490
|
-
}
|
|
491
|
-
function mapCommandExecutionItem(item) {
|
|
492
|
-
const command = normalizeCommandExecutionCommand(item.command);
|
|
493
|
-
const parsedOutput = extractCodexShellOutput(item.aggregatedOutput);
|
|
494
|
-
const input = toNullableObject({
|
|
495
|
-
...(command !== undefined ? { command } : {}),
|
|
496
|
-
...(item.cwd !== undefined ? { cwd: item.cwd } : {}),
|
|
497
|
-
});
|
|
498
|
-
const output = parsedOutput !== undefined || item.exitCode !== undefined
|
|
499
|
-
? {
|
|
500
|
-
...(command !== undefined ? { command } : {}),
|
|
501
|
-
...(parsedOutput !== undefined ? { output: parsedOutput } : {}),
|
|
502
|
-
...(item.exitCode !== undefined ? { exitCode: item.exitCode } : {}),
|
|
503
|
-
}
|
|
504
|
-
: null;
|
|
505
|
-
const name = "shell";
|
|
506
|
-
const error = item.error ?? null;
|
|
507
|
-
const status = resolveStatus(item.status, error, output);
|
|
508
|
-
return {
|
|
509
|
-
callId: item.id,
|
|
510
|
-
name,
|
|
511
|
-
input,
|
|
512
|
-
output,
|
|
513
|
-
status,
|
|
514
|
-
error,
|
|
515
|
-
cwd: item.cwd ?? null,
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
function parseFileChangePath(entry, options, fallbackPath) {
|
|
519
|
-
const rawPath = (typeof entry.path === "string" && entry.path.trim().length > 0
|
|
520
|
-
? entry.path.trim()
|
|
521
|
-
: undefined) ??
|
|
522
|
-
(typeof entry.file_path === "string" && entry.file_path.trim().length > 0
|
|
523
|
-
? entry.file_path.trim()
|
|
524
|
-
: undefined) ??
|
|
525
|
-
(typeof entry.filePath === "string" && entry.filePath.trim().length > 0
|
|
526
|
-
? entry.filePath.trim()
|
|
527
|
-
: undefined) ??
|
|
528
|
-
(typeof fallbackPath === "string" && fallbackPath.trim().length > 0
|
|
529
|
-
? fallbackPath.trim()
|
|
530
|
-
: undefined);
|
|
531
|
-
if (!rawPath) {
|
|
532
|
-
return undefined;
|
|
533
|
-
}
|
|
534
|
-
return normalizeCodexFilePath(rawPath, options?.cwd);
|
|
535
|
-
}
|
|
536
|
-
function parseFileChangeKind(entry) {
|
|
537
|
-
return ((typeof entry.kind === "string" && entry.kind) ||
|
|
538
|
-
(typeof entry.type === "string" && entry.type) ||
|
|
539
|
-
undefined);
|
|
540
|
-
}
|
|
541
|
-
function parseFileChangeDiff(entry) {
|
|
542
|
-
return pickFirstPatchLikeString([
|
|
543
|
-
entry.diff,
|
|
544
|
-
entry.patch,
|
|
545
|
-
entry.unified_diff,
|
|
546
|
-
entry.unifiedDiff,
|
|
547
|
-
entry.content,
|
|
548
|
-
entry.newString,
|
|
549
|
-
]);
|
|
550
|
-
}
|
|
551
|
-
function toFileChangeEntry(entry, options, fallbackPath) {
|
|
552
|
-
const path = parseFileChangePath(entry, options, fallbackPath);
|
|
553
|
-
if (!path) {
|
|
554
|
-
return null;
|
|
555
|
-
}
|
|
556
|
-
return {
|
|
557
|
-
path,
|
|
558
|
-
kind: parseFileChangeKind(entry),
|
|
559
|
-
diff: parseFileChangeDiff(entry),
|
|
560
|
-
};
|
|
561
|
-
}
|
|
562
|
-
function parseFileChangeEntries(changes, options) {
|
|
563
|
-
if (!changes) {
|
|
564
|
-
return [];
|
|
565
|
-
}
|
|
566
|
-
if (Array.isArray(changes)) {
|
|
567
|
-
return changes
|
|
568
|
-
.map((entry) => (isRecord(entry) ? toFileChangeEntry(entry, options) : null))
|
|
569
|
-
.filter((entry) => entry !== null);
|
|
570
|
-
}
|
|
571
|
-
if (!isRecord(changes)) {
|
|
572
|
-
return [];
|
|
573
|
-
}
|
|
574
|
-
if (Array.isArray(changes.files)) {
|
|
575
|
-
return parseFileChangeEntries(changes.files, options);
|
|
576
|
-
}
|
|
577
|
-
const singleEntry = toFileChangeEntry(changes, options);
|
|
578
|
-
if (singleEntry) {
|
|
579
|
-
return [singleEntry];
|
|
580
|
-
}
|
|
581
|
-
return Object.entries(changes)
|
|
582
|
-
.map(([path, value]) => {
|
|
583
|
-
if (isRecord(value)) {
|
|
584
|
-
return toFileChangeEntry(value, options, path);
|
|
585
|
-
}
|
|
586
|
-
if (typeof value === "string") {
|
|
587
|
-
const normalizedPath = normalizeCodexFilePath(path.trim(), options?.cwd);
|
|
588
|
-
if (!normalizedPath) {
|
|
589
|
-
return null;
|
|
590
|
-
}
|
|
591
|
-
return { path: normalizedPath, diff: value };
|
|
592
|
-
}
|
|
593
|
-
return null;
|
|
594
|
-
})
|
|
595
|
-
.filter((entry) => entry !== null);
|
|
596
|
-
}
|
|
597
|
-
function resolveFileChangeTextFields(file) {
|
|
598
|
-
if (!file) {
|
|
599
|
-
return {};
|
|
600
|
-
}
|
|
601
|
-
const isDelete = file.kind === "delete";
|
|
602
|
-
if (isDelete && file.diff) {
|
|
603
|
-
const classified = classifyDiffLikeText(file.diff);
|
|
604
|
-
if (classified.isDiff) {
|
|
605
|
-
return { unifiedDiff: truncateDiffText(classified.text) };
|
|
606
|
-
}
|
|
607
|
-
return { unifiedDiff: truncateDiffText(contentToDeletionDiff(file.path, file.diff)) };
|
|
608
|
-
}
|
|
609
|
-
if (isDelete && !file.diff) {
|
|
610
|
-
return { unifiedDiff: contentToDeletionDiff(file.path, "") };
|
|
611
|
-
}
|
|
612
|
-
return asEditTextFields(file.diff);
|
|
613
|
-
}
|
|
614
|
-
function mapFileChangeItem(item, options) {
|
|
615
|
-
const files = parseFileChangeEntries(item.changes, options);
|
|
616
|
-
const inputBase = {
|
|
617
|
-
...(files.length > 0
|
|
618
|
-
? {
|
|
619
|
-
files: files.map((file) => ({
|
|
620
|
-
path: file.path,
|
|
621
|
-
...(file.kind !== undefined ? { kind: file.kind } : {}),
|
|
622
|
-
})),
|
|
623
|
-
}
|
|
624
|
-
: {}),
|
|
625
|
-
};
|
|
626
|
-
const output = toNullableObject({
|
|
627
|
-
...(files.length > 0
|
|
628
|
-
? {
|
|
629
|
-
files: files.map((file) => ({
|
|
630
|
-
path: file.path,
|
|
631
|
-
...(file.kind !== undefined ? { kind: file.kind } : {}),
|
|
632
|
-
...(file.kind === "delete"
|
|
633
|
-
? { patch: resolveFileChangeTextFields(file).unifiedDiff }
|
|
634
|
-
: asEditFileOutputFields(file.diff)),
|
|
635
|
-
})),
|
|
636
|
-
}
|
|
637
|
-
: {}),
|
|
638
|
-
});
|
|
639
|
-
const name = "apply_patch";
|
|
640
|
-
const error = item.error ?? null;
|
|
641
|
-
const status = resolveStatus(item.status, error, output);
|
|
642
|
-
const firstFile = files[0];
|
|
643
|
-
const firstTextFields = resolveFileChangeTextFields(firstFile);
|
|
644
|
-
const hasFirstTextFields = Object.keys(firstTextFields).length > 0;
|
|
645
|
-
const input = toNullableObject({
|
|
646
|
-
...inputBase,
|
|
647
|
-
...(firstFile?.path && hasFirstTextFields ? { path: firstFile.path } : {}),
|
|
648
|
-
...(hasFirstTextFields && firstTextFields.unifiedDiff
|
|
649
|
-
? { patch: firstTextFields.unifiedDiff }
|
|
650
|
-
: {}),
|
|
651
|
-
...(hasFirstTextFields && firstTextFields.newString
|
|
652
|
-
? { content: firstTextFields.newString }
|
|
653
|
-
: {}),
|
|
654
|
-
});
|
|
655
|
-
return {
|
|
656
|
-
callId: item.id,
|
|
657
|
-
name,
|
|
658
|
-
input,
|
|
659
|
-
output,
|
|
660
|
-
status,
|
|
661
|
-
error,
|
|
662
|
-
cwd: options?.cwd ?? null,
|
|
663
|
-
};
|
|
664
|
-
}
|
|
665
|
-
function mapMcpToolCallItem(item, options) {
|
|
666
|
-
const tool = item.tool.trim();
|
|
667
|
-
if (!tool) {
|
|
668
|
-
return null;
|
|
669
|
-
}
|
|
670
|
-
const name = buildMcpToolName(item.server, tool);
|
|
671
|
-
const input = item.arguments ?? null;
|
|
672
|
-
const output = item.result ?? null;
|
|
673
|
-
const error = item.error ?? null;
|
|
674
|
-
const status = resolveStatus(item.status, error, output);
|
|
675
|
-
return {
|
|
676
|
-
callId: item.id,
|
|
677
|
-
name,
|
|
678
|
-
input,
|
|
679
|
-
output,
|
|
680
|
-
status,
|
|
681
|
-
error,
|
|
682
|
-
cwd: options?.cwd ?? null,
|
|
683
|
-
};
|
|
684
|
-
}
|
|
685
|
-
function mapWebSearchItem(item) {
|
|
686
|
-
const input = item.query !== undefined ? { query: item.query } : null;
|
|
687
|
-
const output = item.action ?? null;
|
|
688
|
-
const name = "web_search";
|
|
689
|
-
const error = item.error ?? null;
|
|
690
|
-
const status = resolveStatus(item.status ?? "completed", error, output);
|
|
691
|
-
return {
|
|
692
|
-
callId: item.id,
|
|
693
|
-
name,
|
|
694
|
-
input,
|
|
695
|
-
output,
|
|
696
|
-
status,
|
|
697
|
-
error,
|
|
698
|
-
cwd: null,
|
|
699
|
-
};
|
|
700
|
-
}
|
|
701
|
-
function mapThreadItemToNormalizedEnvelope(item, options) {
|
|
702
|
-
switch (item.type) {
|
|
703
|
-
case "commandExecution":
|
|
704
|
-
return mapCommandExecutionItem(item);
|
|
705
|
-
case "fileChange":
|
|
706
|
-
return mapFileChangeItem(item, options);
|
|
707
|
-
case "mcpToolCall":
|
|
708
|
-
return mapMcpToolCallItem(item, options);
|
|
709
|
-
case "webSearch":
|
|
710
|
-
return mapWebSearchItem(item);
|
|
711
|
-
default: {
|
|
712
|
-
const exhaustiveCheck = item;
|
|
713
|
-
throw new Error(`Unhandled Codex thread item type: ${String(exhaustiveCheck)}`);
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
// ---------------------------------------------------------------------------
|
|
718
|
-
// Public API
|
|
719
|
-
// ---------------------------------------------------------------------------
|
|
720
|
-
export function mapCodexToolCallFromThreadItem(item, options) {
|
|
721
|
-
const parsed = CodexThreadItemSchema.safeParse(item);
|
|
722
|
-
if (!parsed.success) {
|
|
723
|
-
return null;
|
|
724
|
-
}
|
|
725
|
-
const envelope = mapThreadItemToNormalizedEnvelope(parsed.data, options);
|
|
726
|
-
if (!envelope) {
|
|
727
|
-
return null;
|
|
728
|
-
}
|
|
729
|
-
return toToolCallFromNormalizedEnvelope(envelope);
|
|
730
|
-
}
|
|
731
|
-
export function mapCodexRolloutToolCall(params) {
|
|
732
|
-
const parsed = CodexRolloutToolCallParamsSchema.safeParse(params);
|
|
733
|
-
if (!parsed.success) {
|
|
734
|
-
return null;
|
|
735
|
-
}
|
|
736
|
-
const normalizedName = parsed.data.name.trim();
|
|
737
|
-
const normalizedInput = normalizedName === "apply_patch" || normalizedName === "apply_diff"
|
|
738
|
-
? normalizeRolloutEditInput(parsed.data.input ?? null)
|
|
739
|
-
: (parsed.data.input ?? null);
|
|
740
|
-
const pass1 = CodexNormalizedToolCallPass1Schema.safeParse({
|
|
741
|
-
callId: typeof parsed.data.callId === "string" ? parsed.data.callId.trim() : "",
|
|
742
|
-
name: normalizedName,
|
|
743
|
-
input: normalizedInput,
|
|
744
|
-
output: parsed.data.output ?? null,
|
|
745
|
-
error: parsed.data.error ?? null,
|
|
746
|
-
status: resolveStatus("completed", parsed.data.error ?? null, parsed.data.output ?? null),
|
|
747
|
-
cwd: params.cwd ?? null,
|
|
748
|
-
});
|
|
749
|
-
if (!pass1.success) {
|
|
750
|
-
return null;
|
|
751
|
-
}
|
|
752
|
-
const mapped = toToolCallFromNormalizedEnvelope(pass1.data);
|
|
753
|
-
if (!mapped) {
|
|
754
|
-
return null;
|
|
755
|
-
}
|
|
756
|
-
return mapped;
|
|
757
|
-
}
|
|
758
|
-
//# sourceMappingURL=tool-call-mapper.js.map
|