@getpaseo/server 0.1.2 → 0.1.3
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/server/client/daemon-client.d.ts +11 -5
- package/dist/server/client/daemon-client.d.ts.map +1 -1
- package/dist/server/client/daemon-client.js +54 -46
- package/dist/server/client/daemon-client.js.map +1 -1
- package/dist/server/server/agent/agent-manager.d.ts +7 -0
- package/dist/server/server/agent/agent-manager.d.ts.map +1 -1
- package/dist/server/server/agent/agent-manager.js +41 -1
- package/dist/server/server/agent/agent-manager.js.map +1 -1
- package/dist/server/server/agent/providers/claude/tool-call-detail-parser.d.ts.map +1 -1
- package/dist/server/server/agent/providers/claude/tool-call-detail-parser.js +62 -12
- package/dist/server/server/agent/providers/claude/tool-call-detail-parser.js.map +1 -1
- package/dist/server/server/agent/providers/claude/tool-call-mapper.d.ts +4 -4
- package/dist/server/server/agent/providers/claude/tool-call-mapper.d.ts.map +1 -1
- package/dist/server/server/agent/providers/claude/tool-call-mapper.js +99 -50
- package/dist/server/server/agent/providers/claude/tool-call-mapper.js.map +1 -1
- package/dist/server/server/agent/providers/claude-agent.d.ts.map +1 -1
- package/dist/server/server/agent/providers/claude-agent.js +17 -10
- package/dist/server/server/agent/providers/claude-agent.js.map +1 -1
- package/dist/server/server/agent/providers/codex/tool-call-detail-parser.d.ts +0 -1
- package/dist/server/server/agent/providers/codex/tool-call-detail-parser.d.ts.map +1 -1
- package/dist/server/server/agent/providers/codex/tool-call-detail-parser.js +67 -30
- package/dist/server/server/agent/providers/codex/tool-call-detail-parser.js.map +1 -1
- package/dist/server/server/agent/providers/codex/tool-call-mapper.d.ts +1 -1
- package/dist/server/server/agent/providers/codex/tool-call-mapper.d.ts.map +1 -1
- package/dist/server/server/agent/providers/codex/tool-call-mapper.js +293 -266
- package/dist/server/server/agent/providers/codex/tool-call-mapper.js.map +1 -1
- package/dist/server/server/agent/providers/codex-app-server-agent.d.ts +1 -1
- package/dist/server/server/agent/providers/codex-app-server-agent.d.ts.map +1 -1
- package/dist/server/server/agent/providers/codex-app-server-agent.js +24 -14
- package/dist/server/server/agent/providers/codex-app-server-agent.js.map +1 -1
- package/dist/server/server/agent/providers/codex-rollout-timeline.d.ts.map +1 -1
- package/dist/server/server/agent/providers/codex-rollout-timeline.js +5 -4
- package/dist/server/server/agent/providers/codex-rollout-timeline.js.map +1 -1
- package/dist/server/server/agent/providers/opencode/tool-call-detail-parser.d.ts.map +1 -1
- package/dist/server/server/agent/providers/opencode/tool-call-detail-parser.js +8 -2
- package/dist/server/server/agent/providers/opencode/tool-call-detail-parser.js.map +1 -1
- package/dist/server/server/agent/providers/opencode/tool-call-mapper.d.ts +1 -1
- package/dist/server/server/agent/providers/opencode/tool-call-mapper.d.ts.map +1 -1
- package/dist/server/server/agent/providers/opencode/tool-call-mapper.js +121 -45
- package/dist/server/server/agent/providers/opencode/tool-call-mapper.js.map +1 -1
- package/dist/server/server/agent/providers/opencode-agent.d.ts.map +1 -1
- package/dist/server/server/agent/providers/opencode-agent.js +87 -35
- package/dist/server/server/agent/providers/opencode-agent.js.map +1 -1
- package/dist/server/server/agent/providers/tool-call-detail-primitives.d.ts +2 -2
- package/dist/server/server/agent/providers/tool-call-detail-primitives.d.ts.map +1 -1
- package/dist/server/server/agent/providers/tool-call-detail-primitives.js +23 -6
- package/dist/server/server/agent/providers/tool-call-detail-primitives.js.map +1 -1
- package/dist/server/server/agent/providers/tool-call-mapper-utils.d.ts +0 -1
- package/dist/server/server/agent/providers/tool-call-mapper-utils.d.ts.map +1 -1
- package/dist/server/server/agent/providers/tool-call-mapper-utils.js +0 -10
- package/dist/server/server/agent/providers/tool-call-mapper-utils.js.map +1 -1
- package/dist/server/server/agent/tts-manager.d.ts.map +1 -1
- package/dist/server/server/agent/tts-manager.js +0 -14
- package/dist/server/server/agent/tts-manager.js.map +1 -1
- package/dist/server/server/bootstrap.d.ts.map +1 -1
- package/dist/server/server/bootstrap.js +0 -2
- package/dist/server/server/bootstrap.js.map +1 -1
- package/dist/server/server/dictation/dictation-stream-manager.d.ts.map +1 -1
- package/dist/server/server/dictation/dictation-stream-manager.js +2 -13
- package/dist/server/server/dictation/dictation-stream-manager.js.map +1 -1
- package/dist/server/server/exports.d.ts +1 -0
- package/dist/server/server/exports.d.ts.map +1 -1
- package/dist/server/server/exports.js +1 -0
- package/dist/server/server/exports.js.map +1 -1
- package/dist/server/server/persisted-config.d.ts +32 -18
- package/dist/server/server/persisted-config.d.ts.map +1 -1
- package/dist/server/server/persisted-config.js +2 -0
- package/dist/server/server/persisted-config.js.map +1 -1
- package/dist/server/server/relay-transport.d.ts.map +1 -1
- package/dist/server/server/relay-transport.js +78 -11
- package/dist/server/server/relay-transport.js.map +1 -1
- package/dist/server/server/session.d.ts +2 -8
- package/dist/server/server/session.d.ts.map +1 -1
- package/dist/server/server/session.js +120 -249
- package/dist/server/server/session.js.map +1 -1
- package/dist/server/server/speech/providers/local/config.d.ts.map +1 -1
- package/dist/server/server/speech/providers/local/config.js +11 -8
- package/dist/server/server/speech/providers/local/config.js.map +1 -1
- package/dist/server/server/speech/providers/local/runtime.d.ts.map +1 -1
- package/dist/server/server/speech/providers/local/runtime.js +9 -6
- package/dist/server/server/speech/providers/local/runtime.js.map +1 -1
- package/dist/server/server/speech/providers/local/sherpa/model-downloader.d.ts.map +1 -1
- package/dist/server/server/speech/providers/local/sherpa/model-downloader.js +134 -52
- package/dist/server/server/speech/providers/local/sherpa/model-downloader.js.map +1 -1
- package/dist/server/server/speech/providers/openai/config.d.ts.map +1 -1
- package/dist/server/server/speech/providers/openai/config.js +10 -5
- package/dist/server/server/speech/providers/openai/config.js.map +1 -1
- package/dist/server/server/speech/providers/openai/runtime.d.ts.map +1 -1
- package/dist/server/server/speech/providers/openai/runtime.js +17 -6
- package/dist/server/server/speech/providers/openai/runtime.js.map +1 -1
- package/dist/server/server/speech/speech-config-resolver.d.ts.map +1 -1
- package/dist/server/server/speech/speech-config-resolver.js +25 -4
- package/dist/server/server/speech/speech-config-resolver.js.map +1 -1
- package/dist/server/server/speech/speech-runtime.d.ts.map +1 -1
- package/dist/server/server/speech/speech-runtime.js +44 -15
- package/dist/server/server/speech/speech-runtime.js.map +1 -1
- package/dist/server/server/speech/speech-types.d.ts +3 -0
- package/dist/server/server/speech/speech-types.d.ts.map +1 -1
- package/dist/server/server/speech/speech-types.js +1 -0
- package/dist/server/server/speech/speech-types.js.map +1 -1
- package/dist/server/server/websocket-server.d.ts.map +1 -1
- package/dist/server/server/websocket-server.js +2 -40
- package/dist/server/server/websocket-server.js.map +1 -1
- package/dist/server/shared/messages.d.ts +680 -1328
- package/dist/server/shared/messages.d.ts.map +1 -1
- package/dist/server/shared/messages.js +41 -32
- package/dist/server/shared/messages.js.map +1 -1
- package/dist/server/utils/checkout-git.d.ts +5 -1
- package/dist/server/utils/checkout-git.d.ts.map +1 -1
- package/dist/server/utils/checkout-git.js +222 -75
- package/dist/server/utils/checkout-git.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { CODEX_BUILTIN_TOOL_NAMES, deriveCodexToolDetail, normalizeCodexFilePath, } from "./tool-call-detail-parser.js";
|
|
2
|
+
import { extractCodexShellOutput, truncateDiffText, } from "../tool-call-mapper-utils.js";
|
|
3
|
+
import { deriveCodexToolDetail, normalizeCodexFilePath, } from "./tool-call-detail-parser.js";
|
|
5
4
|
const FAILED_STATUSES = new Set(["failed", "error", "errored", "rejected", "denied"]);
|
|
6
5
|
const CANCELED_STATUSES = new Set(["canceled", "cancelled", "interrupted", "aborted"]);
|
|
7
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([
|
|
9
|
+
"running",
|
|
10
|
+
"completed",
|
|
11
|
+
"failed",
|
|
12
|
+
"canceled",
|
|
13
|
+
]);
|
|
8
14
|
const CodexRolloutToolCallParamsSchema = z
|
|
9
15
|
.object({
|
|
10
16
|
callId: z.string().optional().nullable(),
|
|
@@ -14,16 +20,145 @@ const CodexRolloutToolCallParamsSchema = z
|
|
|
14
20
|
error: z.unknown().optional(),
|
|
15
21
|
})
|
|
16
22
|
.passthrough();
|
|
23
|
+
const CodexNormalizedToolCallPass1Schema = z
|
|
24
|
+
.object({
|
|
25
|
+
callId: z.string().min(1),
|
|
26
|
+
name: z.string().min(1),
|
|
27
|
+
input: z.unknown().nullable(),
|
|
28
|
+
output: z.unknown().nullable(),
|
|
29
|
+
status: CodexToolCallStatusSchema,
|
|
30
|
+
error: z.unknown().nullable(),
|
|
31
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
32
|
+
cwd: z.string().nullable().optional(),
|
|
33
|
+
})
|
|
34
|
+
.passthrough();
|
|
35
|
+
const CodexShellToolNameSchema = z.union([
|
|
36
|
+
z.literal("Bash"),
|
|
37
|
+
z.literal("shell"),
|
|
38
|
+
z.literal("bash"),
|
|
39
|
+
z.literal("exec"),
|
|
40
|
+
z.literal("exec_command"),
|
|
41
|
+
z.literal("command"),
|
|
42
|
+
]);
|
|
43
|
+
const CodexReadToolNameSchema = z.union([z.literal("read"), z.literal("read_file")]);
|
|
44
|
+
const CodexWriteToolNameSchema = z.union([
|
|
45
|
+
z.literal("write"),
|
|
46
|
+
z.literal("write_file"),
|
|
47
|
+
z.literal("create_file"),
|
|
48
|
+
]);
|
|
49
|
+
const CodexEditToolNameSchema = z.union([
|
|
50
|
+
z.literal("edit"),
|
|
51
|
+
z.literal("apply_patch"),
|
|
52
|
+
z.literal("apply_diff"),
|
|
53
|
+
]);
|
|
54
|
+
const CodexSearchToolNameSchema = z.union([z.literal("search"), z.literal("web_search")]);
|
|
55
|
+
const CodexSpeakToolNameSchema = z.literal("paseo.speak");
|
|
56
|
+
const CodexToolKindSchema = z.enum(["shell", "read", "write", "edit", "search", "speak", "unknown"]);
|
|
57
|
+
const CodexToolCallPass2BaseSchema = CodexNormalizedToolCallPass1Schema.extend({
|
|
58
|
+
toolKind: CodexToolKindSchema,
|
|
59
|
+
});
|
|
60
|
+
const CodexToolCallPass2EnvelopeSchema = z.union([
|
|
61
|
+
CodexNormalizedToolCallPass1Schema.extend({
|
|
62
|
+
name: CodexShellToolNameSchema,
|
|
63
|
+
}).transform((envelope) => ({ ...envelope, toolKind: "shell" })),
|
|
64
|
+
CodexNormalizedToolCallPass1Schema.extend({
|
|
65
|
+
name: CodexReadToolNameSchema,
|
|
66
|
+
}).transform((envelope) => ({ ...envelope, toolKind: "read" })),
|
|
67
|
+
CodexNormalizedToolCallPass1Schema.extend({
|
|
68
|
+
name: CodexWriteToolNameSchema,
|
|
69
|
+
}).transform((envelope) => ({ ...envelope, toolKind: "write" })),
|
|
70
|
+
CodexNormalizedToolCallPass1Schema.extend({
|
|
71
|
+
name: CodexEditToolNameSchema,
|
|
72
|
+
}).transform((envelope) => ({ ...envelope, toolKind: "edit" })),
|
|
73
|
+
CodexNormalizedToolCallPass1Schema.extend({
|
|
74
|
+
name: CodexSearchToolNameSchema,
|
|
75
|
+
}).transform((envelope) => ({ ...envelope, toolKind: "search" })),
|
|
76
|
+
CodexNormalizedToolCallPass1Schema.extend({
|
|
77
|
+
name: CodexSpeakToolNameSchema,
|
|
78
|
+
}).transform((envelope) => ({ ...envelope, toolKind: "speak" })),
|
|
79
|
+
CodexNormalizedToolCallPass1Schema.transform((envelope) => ({
|
|
80
|
+
...envelope,
|
|
81
|
+
name: envelope.name.trim(),
|
|
82
|
+
toolKind: "unknown",
|
|
83
|
+
})),
|
|
84
|
+
]);
|
|
85
|
+
const CodexNormalizedToolCallPass2Schema = z.discriminatedUnion("toolKind", [
|
|
86
|
+
CodexToolCallPass2BaseSchema.extend({
|
|
87
|
+
toolKind: z.literal("shell"),
|
|
88
|
+
name: CodexShellToolNameSchema,
|
|
89
|
+
}),
|
|
90
|
+
CodexToolCallPass2BaseSchema.extend({
|
|
91
|
+
toolKind: z.literal("read"),
|
|
92
|
+
name: CodexReadToolNameSchema,
|
|
93
|
+
}),
|
|
94
|
+
CodexToolCallPass2BaseSchema.extend({
|
|
95
|
+
toolKind: z.literal("write"),
|
|
96
|
+
name: CodexWriteToolNameSchema,
|
|
97
|
+
}),
|
|
98
|
+
CodexToolCallPass2BaseSchema.extend({
|
|
99
|
+
toolKind: z.literal("edit"),
|
|
100
|
+
name: CodexEditToolNameSchema,
|
|
101
|
+
}),
|
|
102
|
+
CodexToolCallPass2BaseSchema.extend({
|
|
103
|
+
toolKind: z.literal("search"),
|
|
104
|
+
name: CodexSearchToolNameSchema,
|
|
105
|
+
}),
|
|
106
|
+
CodexToolCallPass2BaseSchema.extend({
|
|
107
|
+
toolKind: z.literal("speak"),
|
|
108
|
+
name: CodexSpeakToolNameSchema,
|
|
109
|
+
}),
|
|
110
|
+
CodexToolCallPass2BaseSchema.extend({
|
|
111
|
+
toolKind: z.literal("unknown"),
|
|
112
|
+
}),
|
|
113
|
+
]);
|
|
114
|
+
function toToolCallTimelineItem(envelope) {
|
|
115
|
+
const name = envelope.toolKind === "speak" ? "speak" : envelope.name;
|
|
116
|
+
const parsedDetail = deriveCodexToolDetail({
|
|
117
|
+
name,
|
|
118
|
+
input: envelope.input,
|
|
119
|
+
output: envelope.output,
|
|
120
|
+
cwd: envelope.cwd ?? null,
|
|
121
|
+
});
|
|
122
|
+
const detail = envelope.toolKind === "edit" &&
|
|
123
|
+
envelope.status !== "running" &&
|
|
124
|
+
!hasRenderableEditDetail(parsedDetail)
|
|
125
|
+
? {
|
|
126
|
+
type: "unknown",
|
|
127
|
+
input: envelope.input,
|
|
128
|
+
output: envelope.output,
|
|
129
|
+
}
|
|
130
|
+
: parsedDetail;
|
|
131
|
+
if (envelope.status === "failed") {
|
|
132
|
+
return {
|
|
133
|
+
type: "tool_call",
|
|
134
|
+
callId: envelope.callId,
|
|
135
|
+
name,
|
|
136
|
+
status: "failed",
|
|
137
|
+
error: envelope.error ?? { message: "Tool call failed" },
|
|
138
|
+
detail,
|
|
139
|
+
...(envelope.metadata ? { metadata: envelope.metadata } : {}),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
type: "tool_call",
|
|
144
|
+
callId: envelope.callId,
|
|
145
|
+
name,
|
|
146
|
+
status: envelope.status,
|
|
147
|
+
error: null,
|
|
148
|
+
detail,
|
|
149
|
+
...(envelope.metadata ? { metadata: envelope.metadata } : {}),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
17
152
|
// ---------------------------------------------------------------------------
|
|
18
153
|
// Thread-item parsing
|
|
19
154
|
// ---------------------------------------------------------------------------
|
|
20
155
|
const CodexCommandExecutionItemSchema = z
|
|
21
156
|
.object({
|
|
22
157
|
type: z.literal("commandExecution"),
|
|
23
|
-
id: z.string().
|
|
158
|
+
id: z.string().min(1),
|
|
24
159
|
status: z.string().optional(),
|
|
25
160
|
error: z.unknown().optional(),
|
|
26
|
-
command:
|
|
161
|
+
command: CodexCommandValueSchema.optional(),
|
|
27
162
|
cwd: z.string().optional(),
|
|
28
163
|
aggregatedOutput: z.string().optional(),
|
|
29
164
|
exitCode: z.number().nullable().optional(),
|
|
@@ -32,7 +167,7 @@ const CodexCommandExecutionItemSchema = z
|
|
|
32
167
|
const CodexFileChangeItemSchema = z
|
|
33
168
|
.object({
|
|
34
169
|
type: z.literal("fileChange"),
|
|
35
|
-
id: z.string().
|
|
170
|
+
id: z.string().min(1),
|
|
36
171
|
status: z.string().optional(),
|
|
37
172
|
error: z.unknown().optional(),
|
|
38
173
|
changes: z
|
|
@@ -42,10 +177,7 @@ const CodexFileChangeItemSchema = z
|
|
|
42
177
|
kind: z.string().optional(),
|
|
43
178
|
diff: z.string().optional(),
|
|
44
179
|
patch: z.string().optional(),
|
|
45
|
-
unified_diff: z.string().optional(),
|
|
46
|
-
unifiedDiff: z.string().optional(),
|
|
47
180
|
content: z.string().optional(),
|
|
48
|
-
newString: z.string().optional(),
|
|
49
181
|
})
|
|
50
182
|
.passthrough())
|
|
51
183
|
.optional(),
|
|
@@ -54,12 +186,10 @@ const CodexFileChangeItemSchema = z
|
|
|
54
186
|
const CodexMcpToolCallItemSchema = z
|
|
55
187
|
.object({
|
|
56
188
|
type: z.literal("mcpToolCall"),
|
|
57
|
-
id: z.string().
|
|
58
|
-
callID: z.string().optional(),
|
|
59
|
-
call_id: z.string().optional(),
|
|
189
|
+
id: z.string().min(1),
|
|
60
190
|
status: z.string().optional(),
|
|
61
191
|
error: z.unknown().optional(),
|
|
62
|
-
tool: z.string().
|
|
192
|
+
tool: z.string().min(1),
|
|
63
193
|
server: z.string().optional(),
|
|
64
194
|
arguments: z.unknown().optional(),
|
|
65
195
|
result: z.unknown().optional(),
|
|
@@ -68,7 +198,7 @@ const CodexMcpToolCallItemSchema = z
|
|
|
68
198
|
const CodexWebSearchItemSchema = z
|
|
69
199
|
.object({
|
|
70
200
|
type: z.literal("webSearch"),
|
|
71
|
-
id: z.string().
|
|
201
|
+
id: z.string().min(1),
|
|
72
202
|
status: z.string().optional(),
|
|
73
203
|
error: z.unknown().optional(),
|
|
74
204
|
query: z.string().optional(),
|
|
@@ -81,14 +211,6 @@ const CodexThreadItemSchema = z.discriminatedUnion("type", [
|
|
|
81
211
|
CodexMcpToolCallItemSchema,
|
|
82
212
|
CodexWebSearchItemSchema,
|
|
83
213
|
]);
|
|
84
|
-
function coerceCallId(raw, name, input) {
|
|
85
|
-
return coerceToolCallId({
|
|
86
|
-
providerPrefix: "codex",
|
|
87
|
-
rawCallId: raw,
|
|
88
|
-
toolName: name,
|
|
89
|
-
input,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
214
|
function maybeUnwrapShellWrapperCommand(command) {
|
|
93
215
|
const trimmed = command.trim();
|
|
94
216
|
const wrapperMatch = trimmed.match(/^(?:\/bin\/)?(?:zsh|bash|sh)\s+-(?:lc|c)\s+([\s\S]+)$/);
|
|
@@ -136,6 +258,9 @@ function looksLikeUnifiedDiff(text) {
|
|
|
136
258
|
normalized.startsWith("--- ") ||
|
|
137
259
|
normalized.startsWith("+++ "));
|
|
138
260
|
}
|
|
261
|
+
function isRecord(value) {
|
|
262
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
263
|
+
}
|
|
139
264
|
function parseCodexApplyPatchDirective(line) {
|
|
140
265
|
const trimmed = line.trim();
|
|
141
266
|
if (trimmed.startsWith("*** Add File:")) {
|
|
@@ -149,6 +274,15 @@ function parseCodexApplyPatchDirective(line) {
|
|
|
149
274
|
}
|
|
150
275
|
return null;
|
|
151
276
|
}
|
|
277
|
+
function extractPatchPrimaryFilePath(patch) {
|
|
278
|
+
for (const line of patch.split(/\r?\n/)) {
|
|
279
|
+
const directive = parseCodexApplyPatchDirective(line);
|
|
280
|
+
if (directive && directive.path.length > 0) {
|
|
281
|
+
return directive.path;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return undefined;
|
|
285
|
+
}
|
|
152
286
|
function looksLikeCodexApplyPatch(text) {
|
|
153
287
|
const normalized = text.trimStart();
|
|
154
288
|
if (!normalized) {
|
|
@@ -230,17 +364,50 @@ function asEditTextFields(text) {
|
|
|
230
364
|
}
|
|
231
365
|
return { newString: text };
|
|
232
366
|
}
|
|
233
|
-
function
|
|
234
|
-
if (typeof
|
|
235
|
-
|
|
367
|
+
function normalizeRolloutEditInput(input) {
|
|
368
|
+
if (typeof input === "string") {
|
|
369
|
+
const textFields = asEditTextFields(input);
|
|
370
|
+
const path = extractPatchPrimaryFilePath(input);
|
|
371
|
+
return {
|
|
372
|
+
...(path ? { path } : {}),
|
|
373
|
+
...(textFields.unifiedDiff ? { patch: textFields.unifiedDiff } : {}),
|
|
374
|
+
...(textFields.newString ? { content: textFields.newString } : {}),
|
|
375
|
+
};
|
|
236
376
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
return { patch: truncateDiffText(classified.text) };
|
|
377
|
+
if (!isRecord(input)) {
|
|
378
|
+
return input;
|
|
240
379
|
}
|
|
241
|
-
|
|
380
|
+
const candidatePatchText = (typeof input.patch === "string" && input.patch) ||
|
|
381
|
+
(typeof input.diff === "string" && input.diff) ||
|
|
382
|
+
(typeof input.unified_diff === "string" && input.unified_diff) ||
|
|
383
|
+
(typeof input.unifiedDiff === "string" && input.unifiedDiff) ||
|
|
384
|
+
(typeof input.content === "string" && input.content) ||
|
|
385
|
+
undefined;
|
|
386
|
+
if (!candidatePatchText) {
|
|
387
|
+
return input;
|
|
388
|
+
}
|
|
389
|
+
const textFields = asEditTextFields(candidatePatchText);
|
|
390
|
+
const rawPath = (typeof input.path === "string" && input.path.trim().length > 0 ? input.path : undefined) ||
|
|
391
|
+
(typeof input.file_path === "string" && input.file_path.trim().length > 0
|
|
392
|
+
? input.file_path
|
|
393
|
+
: undefined) ||
|
|
394
|
+
(typeof input.filePath === "string" && input.filePath.trim().length > 0
|
|
395
|
+
? input.filePath
|
|
396
|
+
: undefined) ||
|
|
397
|
+
extractPatchPrimaryFilePath(candidatePatchText);
|
|
398
|
+
const { patch: _patch, diff: _diff, unified_diff: _unifiedDiffSnake, unifiedDiff: _unifiedDiffCamel, ...rest } = input;
|
|
399
|
+
const normalized = {
|
|
400
|
+
...rest,
|
|
401
|
+
...(rawPath ? { path: rawPath } : {}),
|
|
402
|
+
...(textFields.unifiedDiff ? { patch: textFields.unifiedDiff } : {}),
|
|
403
|
+
...(textFields.newString ? { content: textFields.newString } : {}),
|
|
404
|
+
};
|
|
405
|
+
if (textFields.unifiedDiff && "content" in normalized) {
|
|
406
|
+
delete normalized.content;
|
|
407
|
+
}
|
|
408
|
+
return normalized;
|
|
242
409
|
}
|
|
243
|
-
function
|
|
410
|
+
function asEditFileOutputFields(text) {
|
|
244
411
|
if (typeof text !== "string" || text.length === 0) {
|
|
245
412
|
return {};
|
|
246
413
|
}
|
|
@@ -250,14 +417,6 @@ function asPatchOrContentFields(text) {
|
|
|
250
417
|
}
|
|
251
418
|
return { content: text };
|
|
252
419
|
}
|
|
253
|
-
function hasRenderableEditContent(detail) {
|
|
254
|
-
if (detail.type !== "edit") {
|
|
255
|
-
return false;
|
|
256
|
-
}
|
|
257
|
-
return ((typeof detail.unifiedDiff === "string" && detail.unifiedDiff.length > 0) ||
|
|
258
|
-
(typeof detail.newString === "string" && detail.newString.length > 0) ||
|
|
259
|
-
(typeof detail.oldString === "string" && detail.oldString.length > 0));
|
|
260
|
-
}
|
|
261
420
|
function pickFirstPatchLikeString(values) {
|
|
262
421
|
for (const value of values) {
|
|
263
422
|
if (typeof value === "string" && value.length > 0) {
|
|
@@ -266,9 +425,13 @@ function pickFirstPatchLikeString(values) {
|
|
|
266
425
|
}
|
|
267
426
|
return undefined;
|
|
268
427
|
}
|
|
269
|
-
function
|
|
270
|
-
|
|
271
|
-
|
|
428
|
+
function hasRenderableEditDetail(detail) {
|
|
429
|
+
if (detail.type !== "edit") {
|
|
430
|
+
return true;
|
|
431
|
+
}
|
|
432
|
+
return ((typeof detail.unifiedDiff === "string" && detail.unifiedDiff.trim().length > 0) ||
|
|
433
|
+
(typeof detail.newString === "string" && detail.newString.trim().length > 0) ||
|
|
434
|
+
(typeof detail.oldString === "string" && detail.oldString.trim().length > 0));
|
|
272
435
|
}
|
|
273
436
|
function resolveStatus(rawStatus, error, output) {
|
|
274
437
|
if (error !== undefined && error !== null) {
|
|
@@ -291,36 +454,11 @@ function resolveStatus(rawStatus, error, output) {
|
|
|
291
454
|
}
|
|
292
455
|
return output !== null && output !== undefined ? "completed" : "running";
|
|
293
456
|
}
|
|
294
|
-
function buildToolCall(params) {
|
|
295
|
-
if (params.status === "failed") {
|
|
296
|
-
return {
|
|
297
|
-
type: "tool_call",
|
|
298
|
-
callId: params.callId,
|
|
299
|
-
name: params.name,
|
|
300
|
-
status: "failed",
|
|
301
|
-
error: params.error ?? { message: "Tool call failed" },
|
|
302
|
-
detail: params.detail,
|
|
303
|
-
...(params.metadata ? { metadata: params.metadata } : {}),
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
return {
|
|
307
|
-
type: "tool_call",
|
|
308
|
-
callId: params.callId,
|
|
309
|
-
name: params.name,
|
|
310
|
-
status: params.status,
|
|
311
|
-
error: null,
|
|
312
|
-
detail: params.detail,
|
|
313
|
-
...(params.metadata ? { metadata: params.metadata } : {}),
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
457
|
function buildMcpToolName(server, tool) {
|
|
317
458
|
const trimmedTool = tool.trim();
|
|
318
459
|
if (!trimmedTool) {
|
|
319
460
|
return "tool";
|
|
320
461
|
}
|
|
321
|
-
if (CODEX_BUILTIN_TOOL_NAMES.has(trimmedTool)) {
|
|
322
|
-
return trimmedTool;
|
|
323
|
-
}
|
|
324
462
|
const trimmedServer = typeof server === "string" ? server.trim() : "";
|
|
325
463
|
if (trimmedServer.length > 0) {
|
|
326
464
|
return `${trimmedServer}.${trimmedTool}`;
|
|
@@ -330,86 +468,16 @@ function buildMcpToolName(server, tool) {
|
|
|
330
468
|
function toNullableObject(value) {
|
|
331
469
|
return Object.keys(value).length > 0 ? value : null;
|
|
332
470
|
}
|
|
333
|
-
function
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
if (trimmed.startsWith("*** Add File:")) {
|
|
337
|
-
return trimmed.replace("*** Add File:", "").trim();
|
|
338
|
-
}
|
|
339
|
-
if (trimmed.startsWith("*** Update File:")) {
|
|
340
|
-
return trimmed.replace("*** Update File:", "").trim();
|
|
341
|
-
}
|
|
342
|
-
if (trimmed.startsWith("*** Delete File:")) {
|
|
343
|
-
return trimmed.replace("*** Delete File:", "").trim();
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
return undefined;
|
|
347
|
-
}
|
|
348
|
-
function isRecord(value) {
|
|
349
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
350
|
-
}
|
|
351
|
-
function normalizeApplyPatchInput(input) {
|
|
352
|
-
if (typeof input === "string") {
|
|
353
|
-
const filePath = extractPatchPrimaryFilePath(input);
|
|
354
|
-
const textFields = asPatchOrContentFields(input);
|
|
355
|
-
return filePath ? { path: filePath, ...textFields } : textFields;
|
|
356
|
-
}
|
|
357
|
-
if (!isRecord(input)) {
|
|
358
|
-
return input;
|
|
359
|
-
}
|
|
360
|
-
const existingPath = (typeof input.path === "string" && input.path.trim().length > 0 && input.path.trim()) ||
|
|
361
|
-
(typeof input.file_path === "string" &&
|
|
362
|
-
input.file_path.trim().length > 0 &&
|
|
363
|
-
input.file_path.trim()) ||
|
|
364
|
-
(typeof input.filePath === "string" &&
|
|
365
|
-
input.filePath.trim().length > 0 &&
|
|
366
|
-
input.filePath.trim());
|
|
367
|
-
const patchText = (typeof input.patch === "string" && input.patch) ||
|
|
368
|
-
(typeof input.diff === "string" && input.diff) ||
|
|
369
|
-
(typeof input.unified_diff === "string" && input.unified_diff) ||
|
|
370
|
-
(typeof input.unifiedDiff === "string" && input.unifiedDiff) ||
|
|
371
|
-
undefined;
|
|
372
|
-
const contentText = typeof input.content === "string" ? input.content : undefined;
|
|
373
|
-
const inferredPatchFromContent = !patchText && typeof contentText === "string" ? contentText : undefined;
|
|
374
|
-
const patchOrContentText = patchText ?? inferredPatchFromContent;
|
|
375
|
-
if (existingPath && !patchOrContentText) {
|
|
376
|
-
return input;
|
|
377
|
-
}
|
|
378
|
-
if (!patchOrContentText) {
|
|
379
|
-
return input;
|
|
380
|
-
}
|
|
381
|
-
const base = removePatchLikeFields(input);
|
|
382
|
-
if (inferredPatchFromContent) {
|
|
383
|
-
delete base.content;
|
|
384
|
-
}
|
|
385
|
-
const filePath = existingPath || extractPatchPrimaryFilePath(patchOrContentText);
|
|
386
|
-
const textFields = asPatchOrContentFields(patchOrContentText);
|
|
387
|
-
return filePath ? { ...base, path: filePath, ...textFields } : { ...base, ...textFields };
|
|
388
|
-
}
|
|
389
|
-
function deriveApplyPatchDetailFromInput(input, cwd) {
|
|
390
|
-
if (!isRecord(input)) {
|
|
471
|
+
function toToolCallFromNormalizedEnvelope(envelope) {
|
|
472
|
+
const pass2Envelope = CodexToolCallPass2EnvelopeSchema.safeParse(envelope);
|
|
473
|
+
if (!pass2Envelope.success) {
|
|
391
474
|
return null;
|
|
392
475
|
}
|
|
393
|
-
const
|
|
394
|
-
|
|
395
|
-
(typeof input.filePath === "string" && input.filePath.trim()) ||
|
|
396
|
-
"";
|
|
397
|
-
if (!pathValue) {
|
|
476
|
+
const parsed = CodexNormalizedToolCallPass2Schema.safeParse(pass2Envelope.data);
|
|
477
|
+
if (!parsed.success) {
|
|
398
478
|
return null;
|
|
399
479
|
}
|
|
400
|
-
|
|
401
|
-
const diffText = (typeof input.patch === "string" && input.patch) ||
|
|
402
|
-
(typeof input.diff === "string" && input.diff) ||
|
|
403
|
-
(typeof input.unified_diff === "string" && input.unified_diff) ||
|
|
404
|
-
(typeof input.unifiedDiff === "string" && input.unifiedDiff) ||
|
|
405
|
-
(typeof input.content === "string" && input.content) ||
|
|
406
|
-
undefined;
|
|
407
|
-
const textFields = asEditTextFields(diffText);
|
|
408
|
-
return {
|
|
409
|
-
type: "edit",
|
|
410
|
-
filePath: normalizedPath,
|
|
411
|
-
...textFields,
|
|
412
|
-
};
|
|
480
|
+
return toToolCallTimelineItem(parsed.data);
|
|
413
481
|
}
|
|
414
482
|
function mapCommandExecutionItem(item) {
|
|
415
483
|
const command = normalizeCommandExecutionCommand(item.command);
|
|
@@ -425,30 +493,18 @@ function mapCommandExecutionItem(item) {
|
|
|
425
493
|
...(item.exitCode !== undefined ? { exitCode: item.exitCode } : {}),
|
|
426
494
|
}
|
|
427
495
|
: null;
|
|
428
|
-
const detail = command
|
|
429
|
-
? {
|
|
430
|
-
type: "shell",
|
|
431
|
-
command,
|
|
432
|
-
...(item.cwd ? { cwd: item.cwd } : {}),
|
|
433
|
-
...(parsedOutput ? { output: parsedOutput } : {}),
|
|
434
|
-
...(item.exitCode !== undefined ? { exitCode: item.exitCode } : {}),
|
|
435
|
-
}
|
|
436
|
-
: {
|
|
437
|
-
type: "unknown",
|
|
438
|
-
input,
|
|
439
|
-
output,
|
|
440
|
-
};
|
|
441
496
|
const name = "shell";
|
|
442
|
-
const callId = coerceCallId(item.id, name, input);
|
|
443
497
|
const error = item.error ?? null;
|
|
444
498
|
const status = resolveStatus(item.status, error, output);
|
|
445
|
-
return
|
|
446
|
-
callId,
|
|
499
|
+
return {
|
|
500
|
+
callId: item.id,
|
|
447
501
|
name,
|
|
502
|
+
input,
|
|
503
|
+
output,
|
|
448
504
|
status,
|
|
449
505
|
error,
|
|
450
|
-
|
|
451
|
-
}
|
|
506
|
+
cwd: item.cwd ?? null,
|
|
507
|
+
};
|
|
452
508
|
}
|
|
453
509
|
function mapFileChangeItem(item, options) {
|
|
454
510
|
const changes = item.changes ?? [];
|
|
@@ -463,15 +519,12 @@ function mapFileChangeItem(item, options) {
|
|
|
463
519
|
diff: pickFirstPatchLikeString([
|
|
464
520
|
change.diff,
|
|
465
521
|
change.patch,
|
|
466
|
-
change.unified_diff,
|
|
467
|
-
change.unifiedDiff,
|
|
468
522
|
change.content,
|
|
469
|
-
change.newString,
|
|
470
523
|
]),
|
|
471
524
|
};
|
|
472
525
|
})
|
|
473
526
|
.filter((change) => change.path !== undefined);
|
|
474
|
-
const
|
|
527
|
+
const inputBase = {
|
|
475
528
|
...(files.length > 0
|
|
476
529
|
? {
|
|
477
530
|
files: files.map((file) => ({
|
|
@@ -480,7 +533,7 @@ function mapFileChangeItem(item, options) {
|
|
|
480
533
|
})),
|
|
481
534
|
}
|
|
482
535
|
: {}),
|
|
483
|
-
}
|
|
536
|
+
};
|
|
484
537
|
const output = toNullableObject({
|
|
485
538
|
...(files.length > 0
|
|
486
539
|
? {
|
|
@@ -492,149 +545,123 @@ function mapFileChangeItem(item, options) {
|
|
|
492
545
|
}
|
|
493
546
|
: {}),
|
|
494
547
|
});
|
|
495
|
-
const firstFile = files[0];
|
|
496
|
-
const firstTextFields = asEditTextFields(firstFile?.diff);
|
|
497
|
-
const hasFirstTextFields = Object.keys(firstTextFields).length > 0;
|
|
498
|
-
const detail = firstFile?.path
|
|
499
|
-
? hasFirstTextFields
|
|
500
|
-
? {
|
|
501
|
-
type: "edit",
|
|
502
|
-
filePath: firstFile.path,
|
|
503
|
-
...firstTextFields,
|
|
504
|
-
}
|
|
505
|
-
: {
|
|
506
|
-
type: "unknown",
|
|
507
|
-
input,
|
|
508
|
-
output,
|
|
509
|
-
}
|
|
510
|
-
: {
|
|
511
|
-
type: "unknown",
|
|
512
|
-
input,
|
|
513
|
-
output,
|
|
514
|
-
};
|
|
515
548
|
const name = "apply_patch";
|
|
516
|
-
const callId = coerceCallId(item.id, name, input);
|
|
517
549
|
const error = item.error ?? null;
|
|
518
550
|
const status = resolveStatus(item.status, error, output);
|
|
519
|
-
|
|
520
|
-
|
|
551
|
+
const firstFile = files[0];
|
|
552
|
+
const firstTextFields = asEditTextFields(firstFile?.diff);
|
|
553
|
+
const hasFirstTextFields = Object.keys(firstTextFields).length > 0;
|
|
554
|
+
const input = toNullableObject({
|
|
555
|
+
...inputBase,
|
|
556
|
+
...(firstFile?.path && hasFirstTextFields ? { path: firstFile.path } : {}),
|
|
557
|
+
...(hasFirstTextFields && firstTextFields.unifiedDiff
|
|
558
|
+
? { patch: firstTextFields.unifiedDiff }
|
|
559
|
+
: {}),
|
|
560
|
+
...(hasFirstTextFields && firstTextFields.newString
|
|
561
|
+
? { content: firstTextFields.newString }
|
|
562
|
+
: {}),
|
|
563
|
+
});
|
|
564
|
+
return {
|
|
565
|
+
callId: item.id,
|
|
521
566
|
name,
|
|
567
|
+
input,
|
|
568
|
+
output,
|
|
522
569
|
status,
|
|
523
570
|
error,
|
|
524
|
-
|
|
525
|
-
}
|
|
571
|
+
cwd: options?.cwd ?? null,
|
|
572
|
+
};
|
|
526
573
|
}
|
|
527
574
|
function mapMcpToolCallItem(item, options) {
|
|
528
|
-
const tool = item.tool
|
|
575
|
+
const tool = item.tool.trim();
|
|
576
|
+
if (!tool) {
|
|
577
|
+
return null;
|
|
578
|
+
}
|
|
529
579
|
const name = buildMcpToolName(item.server, tool);
|
|
530
580
|
const input = item.arguments ?? null;
|
|
531
581
|
const output = item.result ?? null;
|
|
532
582
|
const error = item.error ?? null;
|
|
533
|
-
const callId = coerceCallId(item.id ?? item.callID ?? item.call_id, name, input);
|
|
534
583
|
const status = resolveStatus(item.status, error, output);
|
|
535
|
-
|
|
536
|
-
|
|
584
|
+
return {
|
|
585
|
+
callId: item.id,
|
|
586
|
+
name,
|
|
537
587
|
input,
|
|
538
588
|
output,
|
|
539
|
-
cwd: options?.cwd ?? null,
|
|
540
|
-
});
|
|
541
|
-
return buildToolCall({
|
|
542
|
-
callId,
|
|
543
|
-
name,
|
|
544
589
|
status,
|
|
545
590
|
error,
|
|
546
|
-
|
|
547
|
-
}
|
|
591
|
+
cwd: options?.cwd ?? null,
|
|
592
|
+
};
|
|
548
593
|
}
|
|
549
594
|
function mapWebSearchItem(item) {
|
|
550
595
|
const input = item.query !== undefined ? { query: item.query } : null;
|
|
551
596
|
const output = item.action ?? null;
|
|
552
597
|
const name = "web_search";
|
|
553
|
-
const callId = coerceCallId(item.id, name, input);
|
|
554
598
|
const error = item.error ?? null;
|
|
555
599
|
const status = resolveStatus(item.status ?? "completed", error, output);
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
type: "search",
|
|
559
|
-
query: item.query,
|
|
560
|
-
}
|
|
561
|
-
: {
|
|
562
|
-
type: "unknown",
|
|
563
|
-
input,
|
|
564
|
-
output,
|
|
565
|
-
};
|
|
566
|
-
return buildToolCall({
|
|
567
|
-
callId,
|
|
600
|
+
return {
|
|
601
|
+
callId: item.id,
|
|
568
602
|
name,
|
|
603
|
+
input,
|
|
604
|
+
output,
|
|
569
605
|
status,
|
|
570
606
|
error,
|
|
571
|
-
|
|
572
|
-
}
|
|
607
|
+
cwd: null,
|
|
608
|
+
};
|
|
573
609
|
}
|
|
574
|
-
function
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
throw new Error(`Unhandled Codex thread item type: ${String(exhaustiveCheck)}`);
|
|
588
|
-
}
|
|
610
|
+
function mapThreadItemToNormalizedEnvelope(item, options) {
|
|
611
|
+
switch (item.type) {
|
|
612
|
+
case "commandExecution":
|
|
613
|
+
return mapCommandExecutionItem(item);
|
|
614
|
+
case "fileChange":
|
|
615
|
+
return mapFileChangeItem(item, options);
|
|
616
|
+
case "mcpToolCall":
|
|
617
|
+
return mapMcpToolCallItem(item, options);
|
|
618
|
+
case "webSearch":
|
|
619
|
+
return mapWebSearchItem(item);
|
|
620
|
+
default: {
|
|
621
|
+
const exhaustiveCheck = item;
|
|
622
|
+
throw new Error(`Unhandled Codex thread item type: ${String(exhaustiveCheck)}`);
|
|
589
623
|
}
|
|
590
|
-
}
|
|
624
|
+
}
|
|
591
625
|
}
|
|
592
626
|
// ---------------------------------------------------------------------------
|
|
593
627
|
// Public API
|
|
594
628
|
// ---------------------------------------------------------------------------
|
|
595
629
|
export function mapCodexToolCallFromThreadItem(item, options) {
|
|
596
|
-
const parsed =
|
|
630
|
+
const parsed = CodexThreadItemSchema.safeParse(item);
|
|
597
631
|
if (!parsed.success) {
|
|
598
632
|
return null;
|
|
599
633
|
}
|
|
600
|
-
|
|
634
|
+
const envelope = mapThreadItemToNormalizedEnvelope(parsed.data, options);
|
|
635
|
+
if (!envelope) {
|
|
636
|
+
return null;
|
|
637
|
+
}
|
|
638
|
+
return toToolCallFromNormalizedEnvelope(envelope);
|
|
601
639
|
}
|
|
602
640
|
export function mapCodexRolloutToolCall(params) {
|
|
603
|
-
const parsed = CodexRolloutToolCallParamsSchema.
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
const
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
641
|
+
const parsed = CodexRolloutToolCallParamsSchema.safeParse(params);
|
|
642
|
+
if (!parsed.success) {
|
|
643
|
+
return null;
|
|
644
|
+
}
|
|
645
|
+
const normalizedName = parsed.data.name.trim();
|
|
646
|
+
const normalizedInput = normalizedName === "apply_patch" || normalizedName === "apply_diff"
|
|
647
|
+
? normalizeRolloutEditInput(parsed.data.input ?? null)
|
|
648
|
+
: parsed.data.input ?? null;
|
|
649
|
+
const pass1 = CodexNormalizedToolCallPass1Schema.safeParse({
|
|
650
|
+
callId: typeof parsed.data.callId === "string" ? parsed.data.callId.trim() : "",
|
|
651
|
+
name: normalizedName,
|
|
652
|
+
input: normalizedInput,
|
|
653
|
+
output: parsed.data.output ?? null,
|
|
654
|
+
error: parsed.data.error ?? null,
|
|
655
|
+
status: resolveStatus("completed", parsed.data.error ?? null, parsed.data.output ?? null),
|
|
617
656
|
cwd: params.cwd ?? null,
|
|
618
657
|
});
|
|
619
|
-
if (
|
|
620
|
-
|
|
621
|
-
if (fallbackDetail) {
|
|
622
|
-
detail = fallbackDetail;
|
|
623
|
-
}
|
|
658
|
+
if (!pass1.success) {
|
|
659
|
+
return null;
|
|
624
660
|
}
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
input,
|
|
629
|
-
output,
|
|
630
|
-
};
|
|
661
|
+
const mapped = toToolCallFromNormalizedEnvelope(pass1.data);
|
|
662
|
+
if (!mapped) {
|
|
663
|
+
return null;
|
|
631
664
|
}
|
|
632
|
-
return
|
|
633
|
-
callId,
|
|
634
|
-
name: parsed.name,
|
|
635
|
-
status,
|
|
636
|
-
error,
|
|
637
|
-
detail,
|
|
638
|
-
});
|
|
665
|
+
return mapped;
|
|
639
666
|
}
|
|
640
667
|
//# sourceMappingURL=tool-call-mapper.js.map
|