@codex-app-sdk/backend 0.15.1 → 0.16.0
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/index.js +1176 -998
- package/dist/index.js.map +1 -1
- package/dist/node/codex-surface-data.d.ts +4 -0
- package/dist/node/codex-surface-data.d.ts.map +1 -1
- package/dist/node/codex-surface-notifications-controller.d.ts.map +1 -1
- package/dist/node/codex-surface-usage-controller.d.ts +11 -0
- package/dist/node/codex-surface-usage-controller.d.ts.map +1 -0
- package/dist/node/codex-surface.d.ts +10 -1
- package/dist/node/codex-surface.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -949,19 +949,374 @@ function Tt(e) {
|
|
|
949
949
|
return t.href;
|
|
950
950
|
}
|
|
951
951
|
//#endregion
|
|
952
|
+
//#region src/node/codex-file-attachment.ts
|
|
953
|
+
var Et = "<attached_file>\n", Dt = "\n</attached_file>";
|
|
954
|
+
function Ot(e, t) {
|
|
955
|
+
return {
|
|
956
|
+
type: "text",
|
|
957
|
+
text: `${Et}${JSON.stringify({
|
|
958
|
+
name: e,
|
|
959
|
+
path: t
|
|
960
|
+
}).replaceAll("<", "\\u003c")}${Dt}`,
|
|
961
|
+
text_elements: []
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
function kt(e) {
|
|
965
|
+
if (!e.startsWith(Et) || !e.endsWith(Dt)) return null;
|
|
966
|
+
try {
|
|
967
|
+
let t = JSON.parse(e.slice(16, -17));
|
|
968
|
+
if (typeof t != "object" || !t || Array.isArray(t)) return null;
|
|
969
|
+
let n = t;
|
|
970
|
+
return typeof n.name == "string" && typeof n.path == "string" && n.path.length > 0 ? {
|
|
971
|
+
name: n.name,
|
|
972
|
+
path: n.path
|
|
973
|
+
} : null;
|
|
974
|
+
} catch {
|
|
975
|
+
return null;
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
//#endregion
|
|
979
|
+
//#region src/node/codex-surface-settings.ts
|
|
980
|
+
function k(e, t) {
|
|
981
|
+
return e.find((e) => e.id === t || e.model === t) ?? e.find((e) => e.isDefault) ?? e[0] ?? null;
|
|
982
|
+
}
|
|
983
|
+
function At(e, t) {
|
|
984
|
+
let n = e.find((e) => e.id === t || e.model === t);
|
|
985
|
+
if (!n) throw Error(`Unknown model '${t}'`);
|
|
986
|
+
return n;
|
|
987
|
+
}
|
|
988
|
+
function jt(e, t) {
|
|
989
|
+
if (!t) return;
|
|
990
|
+
if (!e) throw Error(`Cannot select reasoning effort '${t}' without a model`);
|
|
991
|
+
let n = e.supportedReasoningEfforts?.map((e) => e.reasoningEffort) ?? [];
|
|
992
|
+
if (n.length > 0 && !n.includes(t)) throw Error(`Reasoning effort '${t}' is not available for '${e.displayName}'`);
|
|
993
|
+
}
|
|
994
|
+
function A(e) {
|
|
995
|
+
return e.defaultReasoningEffort ?? e.supportedReasoningEfforts?.[0]?.reasoningEffort ?? null;
|
|
996
|
+
}
|
|
997
|
+
function Mt(e) {
|
|
998
|
+
return e.defaultServiceTier ?? null;
|
|
999
|
+
}
|
|
1000
|
+
function j(e, t) {
|
|
1001
|
+
if (!t) return;
|
|
1002
|
+
if (!e) throw Error(`Cannot select service tier '${t}' without a model`);
|
|
1003
|
+
if (t === "default" || t === e.defaultServiceTier) return;
|
|
1004
|
+
let n = e.serviceTiers?.map((e) => e.id) ?? [];
|
|
1005
|
+
if (n.length > 0 && !n.includes(t)) throw Error(`Service tier '${t}' is not available for '${e.displayName}'`);
|
|
1006
|
+
}
|
|
1007
|
+
function Nt(e, t) {
|
|
1008
|
+
let n = new Set(e.filter((e) => e.allowed).map((e) => e.id)), r = [];
|
|
1009
|
+
return n.has(":workspace") && M(t?.allowedApprovalPolicies, "on-request") && M(t?.allowedApprovalsReviewers, "user") && r.push("ask-for-approval"), n.has(":workspace") && M(t?.allowedApprovalPolicies, "on-request") && M(t?.allowedApprovalsReviewers, "auto_review") && r.push("approve-for-me"), (n.has(":danger-full-access") || n.has(":danger-no-sandbox")) && M(t?.allowedApprovalPolicies, "never") && M(t?.allowedApprovalsReviewers, "user") && r.push("full-access"), r;
|
|
1010
|
+
}
|
|
1011
|
+
function M(e, t) {
|
|
1012
|
+
return !Array.isArray(e) || e.length === 0 || e.includes(t);
|
|
1013
|
+
}
|
|
1014
|
+
function Pt(e) {
|
|
1015
|
+
return e === "full-access" ? {
|
|
1016
|
+
approvalPolicy: "never",
|
|
1017
|
+
approvalsReviewer: "user",
|
|
1018
|
+
permissions: ":danger-full-access"
|
|
1019
|
+
} : {
|
|
1020
|
+
approvalPolicy: "on-request",
|
|
1021
|
+
approvalsReviewer: e === "approve-for-me" ? "auto_review" : "user",
|
|
1022
|
+
permissions: ":workspace"
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
function Ft(e) {
|
|
1026
|
+
return Pt(e);
|
|
1027
|
+
}
|
|
1028
|
+
function It(e, t, n, r) {
|
|
1029
|
+
let i = r?.id;
|
|
1030
|
+
return e === "never" && (n.type === "dangerFullAccess" || i === ":danger-full-access" || i === ":danger-no-sandbox") ? "full-access" : e === "on-request" && (t === "auto_review" || t === "guardian_subagent") ? "approve-for-me" : e === "on-request" ? "ask-for-approval" : null;
|
|
1031
|
+
}
|
|
1032
|
+
function Lt(e, t, n) {
|
|
1033
|
+
let r = k(t, e.model);
|
|
1034
|
+
return {
|
|
1035
|
+
approvalPreset: It(e.approvalPolicy, e.approvalsReviewer, e.sandbox, e.activePermissionProfile) ?? n.approvalPreset,
|
|
1036
|
+
planMode: n.planMode,
|
|
1037
|
+
selectedModelId: r?.id ?? n.selectedModelId,
|
|
1038
|
+
selectedReasoningEffort: e.reasoningEffort ?? (r ? A(r) : null),
|
|
1039
|
+
selectedServiceTier: e.serviceTier === void 0 ? r ? Mt(r) : null : e.serviceTier
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
function Rt(e, t, n) {
|
|
1043
|
+
let r = k(t, e.model);
|
|
1044
|
+
return {
|
|
1045
|
+
approvalPreset: It(e.approvalPolicy, e.approvalsReviewer, e.sandboxPolicy, e.activePermissionProfile) ?? n.approvalPreset,
|
|
1046
|
+
planMode: e.collaborationMode.mode === "plan",
|
|
1047
|
+
selectedModelId: r?.id ?? n.selectedModelId,
|
|
1048
|
+
selectedReasoningEffort: e.effort ?? (r ? A(r) : null),
|
|
1049
|
+
selectedServiceTier: e.serviceTier === void 0 ? r ? Mt(r) : null : e.serviceTier
|
|
1050
|
+
};
|
|
1051
|
+
}
|
|
1052
|
+
function zt(e, t) {
|
|
1053
|
+
let n = k(e.models, e.selectedModelId);
|
|
1054
|
+
if (t.modelId && (n = e.models.find((e) => e.id === t.modelId) ?? null, !n)) throw Error(`Unknown model '${t.modelId}'`);
|
|
1055
|
+
let r = t.reasoningEffort ?? e.selectedReasoningEffort, i = t.serviceTier === void 0 ? e.selectedServiceTier ?? null : t.serviceTier, a = n?.supportedReasoningEfforts?.map((e) => e.reasoningEffort) ?? [];
|
|
1056
|
+
if (t.reasoningEffort && a.length > 0 && !a.includes(t.reasoningEffort)) throw Error(`Reasoning effort '${t.reasoningEffort}' is not available for '${n.displayName}'`);
|
|
1057
|
+
return t.modelId && a.length > 0 && (!r || !a.includes(r)) && (r = n ? A(n) : null), t.serviceTier !== void 0 && j(n, i), t.serviceTier === void 0 && t.modelId && i && !n.serviceTiers?.some((e) => e.id === i) && (i = n ? Mt(n) : null), {
|
|
1058
|
+
approvalPreset: t.approvalPreset ?? e.approvalPreset,
|
|
1059
|
+
planMode: t.planMode ?? e.planMode,
|
|
1060
|
+
selectedModelId: n?.id ?? null,
|
|
1061
|
+
selectedReasoningEffort: r,
|
|
1062
|
+
selectedServiceTier: i
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
function Bt(e, t, n) {
|
|
1066
|
+
return {
|
|
1067
|
+
mode: e ? "plan" : "default",
|
|
1068
|
+
settings: {
|
|
1069
|
+
model: t,
|
|
1070
|
+
reasoning_effort: n,
|
|
1071
|
+
developer_instructions: null
|
|
1072
|
+
}
|
|
1073
|
+
};
|
|
1074
|
+
}
|
|
1075
|
+
function Vt(e, t) {
|
|
1076
|
+
let n = k(e.models, e.selectedModelId), r = t.model ?? n?.model, i = t.reasoningEffort ?? e.selectedReasoningEffort, a = t.planMode ?? e.planMode;
|
|
1077
|
+
return {
|
|
1078
|
+
...r ? { model: r } : {},
|
|
1079
|
+
...i ? { effort: i } : {},
|
|
1080
|
+
...r ? { collaborationMode: Bt(a, r, i) } : {},
|
|
1081
|
+
...t.serviceTier === void 0 ? e.selectedServiceTier ? { serviceTier: e.selectedServiceTier } : {} : { serviceTier: t.serviceTier }
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
//#endregion
|
|
1085
|
+
//#region src/node/codex-surface-data.ts
|
|
1086
|
+
function N(e) {
|
|
1087
|
+
let t = e.preview.trim(), n = t.split("\n")[0];
|
|
1088
|
+
return {
|
|
1089
|
+
id: e.id,
|
|
1090
|
+
...e.sessionId ? { sessionId: e.sessionId } : {},
|
|
1091
|
+
...e.parentThreadId ? { parentConversationId: e.parentThreadId } : {},
|
|
1092
|
+
...e.agentNickname ? { agentNickname: e.agentNickname } : {},
|
|
1093
|
+
...e.agentRole ? { agentRole: e.agentRole } : {},
|
|
1094
|
+
title: e.name?.trim() || n.trim() || "Untitled conversation",
|
|
1095
|
+
preview: t,
|
|
1096
|
+
cwd: e.cwd,
|
|
1097
|
+
status: e.status.type === "active" ? "active" : e.status.type === "systemError" ? "error" : "idle",
|
|
1098
|
+
turnCount: e.turns.length,
|
|
1099
|
+
createdAt: (/* @__PURE__ */ new Date(e.createdAt * 1e3)).toISOString(),
|
|
1100
|
+
updatedAt: (/* @__PURE__ */ new Date((e.recencyAt ?? e.updatedAt) * 1e3)).toISOString()
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
function Ht(e, t) {
|
|
1104
|
+
let n = new Map(e.map((e) => [e.id, e])), r = t.map((e) => {
|
|
1105
|
+
let t = n.get(e.id);
|
|
1106
|
+
return t && ie(t, e) ? t : e;
|
|
1107
|
+
});
|
|
1108
|
+
return r.length === e.length && r.every((t, n) => t === e[n]) ? e : r;
|
|
1109
|
+
}
|
|
1110
|
+
function P(e, t) {
|
|
1111
|
+
return [t, ...e.filter((e) => e.id !== t.id)].sort((e, t) => t.updatedAt.localeCompare(e.updatedAt));
|
|
1112
|
+
}
|
|
1113
|
+
function Ut(e, t) {
|
|
1114
|
+
let n = t.model ? At(e.models, t.model) : k(e.models, e.selectedModelId);
|
|
1115
|
+
return jt(n, t.reasoningEffort), j(n, t.serviceTier), {
|
|
1116
|
+
...t,
|
|
1117
|
+
...t.attachments ? { attachments: Wt(t.attachments) } : {},
|
|
1118
|
+
...t.model && n ? { model: n.model } : {}
|
|
1119
|
+
};
|
|
1120
|
+
}
|
|
1121
|
+
function Wt(e) {
|
|
1122
|
+
return e.map((e) => {
|
|
1123
|
+
let t = e.path.trim();
|
|
1124
|
+
if (!t) throw Error("Attachment paths cannot be empty");
|
|
1125
|
+
if (!v(t)) throw Error(`Attachment path must be absolute: '${t}'`);
|
|
1126
|
+
if (e.type === "image") return {
|
|
1127
|
+
...e,
|
|
1128
|
+
path: t
|
|
1129
|
+
};
|
|
1130
|
+
let n = e.name?.trim();
|
|
1131
|
+
return {
|
|
1132
|
+
...e,
|
|
1133
|
+
path: t,
|
|
1134
|
+
...n ? { name: n } : {}
|
|
1135
|
+
};
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
function Gt(e) {
|
|
1139
|
+
return e.type === "image" ? {
|
|
1140
|
+
type: "localImage",
|
|
1141
|
+
path: e.path,
|
|
1142
|
+
...e.detail === void 0 ? {} : { detail: e.detail }
|
|
1143
|
+
} : Ot(e.name ?? g(e.path), e.path);
|
|
1144
|
+
}
|
|
1145
|
+
function Kt(e) {
|
|
1146
|
+
let t = e.name?.trim() || g(e.path);
|
|
1147
|
+
return e.type === "image" ? {
|
|
1148
|
+
type: "attachment",
|
|
1149
|
+
attachment: {
|
|
1150
|
+
kind: "image",
|
|
1151
|
+
name: t,
|
|
1152
|
+
path: e.path,
|
|
1153
|
+
url: e.previewUrl ?? re(e.path).href,
|
|
1154
|
+
...e.mimeType ? { mimeType: e.mimeType } : {}
|
|
1155
|
+
}
|
|
1156
|
+
} : {
|
|
1157
|
+
type: "attachment",
|
|
1158
|
+
attachment: {
|
|
1159
|
+
kind: "file",
|
|
1160
|
+
name: t,
|
|
1161
|
+
path: e.path,
|
|
1162
|
+
...e.mimeType ? { mimeType: e.mimeType } : {}
|
|
1163
|
+
}
|
|
1164
|
+
};
|
|
1165
|
+
}
|
|
1166
|
+
function qt(e) {
|
|
1167
|
+
let t = e.metadata?.turnId;
|
|
1168
|
+
return e.turnId ?? (typeof t == "string" ? t : null);
|
|
1169
|
+
}
|
|
1170
|
+
function Jt(e) {
|
|
1171
|
+
return e.parts.filter((e) => e.type === "text").map((e) => e.text).join("\n").trim();
|
|
1172
|
+
}
|
|
1173
|
+
function Yt(e) {
|
|
1174
|
+
return e.parts.flatMap((e) => {
|
|
1175
|
+
if (e.type !== "attachment") return [];
|
|
1176
|
+
let t = e.attachment, n = t.path;
|
|
1177
|
+
return n ? t.kind === "image" ? [{
|
|
1178
|
+
type: "image",
|
|
1179
|
+
path: n,
|
|
1180
|
+
name: t.name,
|
|
1181
|
+
...t.mimeType ? { mimeType: t.mimeType } : {},
|
|
1182
|
+
...t.url?.startsWith("data:image/") ? { previewUrl: t.url } : {}
|
|
1183
|
+
}] : [{
|
|
1184
|
+
type: "file",
|
|
1185
|
+
path: n,
|
|
1186
|
+
name: t.name,
|
|
1187
|
+
...t.mimeType ? { mimeType: t.mimeType } : {}
|
|
1188
|
+
}] : [];
|
|
1189
|
+
});
|
|
1190
|
+
}
|
|
1191
|
+
function Xt(e) {
|
|
1192
|
+
return {
|
|
1193
|
+
totalTokens: e.totalTokens,
|
|
1194
|
+
inputTokens: e.inputTokens,
|
|
1195
|
+
cachedInputTokens: e.cachedInputTokens,
|
|
1196
|
+
cacheWriteInputTokens: e.cacheWriteInputTokens ?? null,
|
|
1197
|
+
outputTokens: e.outputTokens,
|
|
1198
|
+
reasoningOutputTokens: e.reasoningOutputTokens
|
|
1199
|
+
};
|
|
1200
|
+
}
|
|
1201
|
+
function Zt(e) {
|
|
1202
|
+
let t = e.modelContextWindow, n = e.last.totalTokens, r = typeof t == "number" && t > 0 ? Math.min(100, Math.max(0, n / t * 100)) : null;
|
|
1203
|
+
return {
|
|
1204
|
+
totalTokens: e.total.totalTokens,
|
|
1205
|
+
inputTokens: e.total.inputTokens,
|
|
1206
|
+
cachedInputTokens: e.total.cachedInputTokens,
|
|
1207
|
+
outputTokens: e.total.outputTokens,
|
|
1208
|
+
reasoningOutputTokens: e.total.reasoningOutputTokens,
|
|
1209
|
+
lastTotalTokens: e.last.totalTokens,
|
|
1210
|
+
modelContextWindow: t,
|
|
1211
|
+
usedPercent: r
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
function F(e) {
|
|
1215
|
+
return e.type === "active" ? {
|
|
1216
|
+
type: "active",
|
|
1217
|
+
activeFlags: [...e.activeFlags]
|
|
1218
|
+
} : { type: e.type };
|
|
1219
|
+
}
|
|
1220
|
+
function Qt(e) {
|
|
1221
|
+
return e.type === "active" ? "active" : e.type === "systemError" ? "error" : "idle";
|
|
1222
|
+
}
|
|
1223
|
+
function $t(e) {
|
|
1224
|
+
let t = e.rateLimitsByLimitId ? Object.fromEntries(Object.entries(e.rateLimitsByLimitId).filter((e) => !!e[1]).map(([e, t]) => [e, nn(t)])) : null;
|
|
1225
|
+
return {
|
|
1226
|
+
rateLimits: nn(e.rateLimits),
|
|
1227
|
+
rateLimitsByLimitId: t,
|
|
1228
|
+
rateLimitResetCredits: e.rateLimitResetCredits ? {
|
|
1229
|
+
availableCount: en(e.rateLimitResetCredits.availableCount),
|
|
1230
|
+
credits: e.rateLimitResetCredits.credits?.map((e) => ({ ...e })) ?? null
|
|
1231
|
+
} : null
|
|
1232
|
+
};
|
|
1233
|
+
}
|
|
1234
|
+
function en(e) {
|
|
1235
|
+
if (typeof e == "bigint" && e >= 0n) return e.toString();
|
|
1236
|
+
if (typeof e == "number" && Number.isSafeInteger(e) && e >= 0) return String(e);
|
|
1237
|
+
if (typeof e == "string" && /^(0|[1-9][0-9]*)$/.test(e)) return e;
|
|
1238
|
+
throw Error("Invalid account count: expected an exact nonnegative integer");
|
|
1239
|
+
}
|
|
1240
|
+
function tn(e) {
|
|
1241
|
+
let t = (e) => e === null ? null : en(e);
|
|
1242
|
+
return {
|
|
1243
|
+
summary: {
|
|
1244
|
+
lifetimeTokens: t(e.summary.lifetimeTokens),
|
|
1245
|
+
peakDailyTokens: t(e.summary.peakDailyTokens),
|
|
1246
|
+
longestRunningTurnSec: t(e.summary.longestRunningTurnSec),
|
|
1247
|
+
currentStreakDays: t(e.summary.currentStreakDays),
|
|
1248
|
+
longestStreakDays: t(e.summary.longestStreakDays)
|
|
1249
|
+
},
|
|
1250
|
+
dailyUsageBuckets: e.dailyUsageBuckets?.map((e) => ({
|
|
1251
|
+
startDate: e.startDate,
|
|
1252
|
+
tokens: en(e.tokens)
|
|
1253
|
+
})) ?? null
|
|
1254
|
+
};
|
|
1255
|
+
}
|
|
1256
|
+
function nn(e) {
|
|
1257
|
+
return {
|
|
1258
|
+
limitId: e.limitId,
|
|
1259
|
+
limitName: e.limitName,
|
|
1260
|
+
primary: e.primary ? { ...e.primary } : null,
|
|
1261
|
+
secondary: e.secondary ? { ...e.secondary } : null,
|
|
1262
|
+
credits: e.credits ? { ...e.credits } : null,
|
|
1263
|
+
individualLimit: e.individualLimit ? { ...e.individualLimit } : null,
|
|
1264
|
+
planType: e.planType,
|
|
1265
|
+
rateLimitReachedType: e.rateLimitReachedType
|
|
1266
|
+
};
|
|
1267
|
+
}
|
|
1268
|
+
function rn(e, t) {
|
|
1269
|
+
let n = nn(t);
|
|
1270
|
+
if (!e) return {
|
|
1271
|
+
rateLimits: n,
|
|
1272
|
+
rateLimitsByLimitId: n.limitId ? { [n.limitId]: n } : null,
|
|
1273
|
+
rateLimitResetCredits: null
|
|
1274
|
+
};
|
|
1275
|
+
let r = an(e.rateLimits, n), i = e.rateLimitsByLimitId ? { ...e.rateLimitsByLimitId } : {};
|
|
1276
|
+
return r.limitId && (i[r.limitId] = an(i[r.limitId] ?? r, n)), {
|
|
1277
|
+
...e,
|
|
1278
|
+
rateLimits: r,
|
|
1279
|
+
rateLimitsByLimitId: Object.keys(i).length > 0 ? i : null
|
|
1280
|
+
};
|
|
1281
|
+
}
|
|
1282
|
+
function an(e, t) {
|
|
1283
|
+
return {
|
|
1284
|
+
limitId: t.limitId ?? e.limitId,
|
|
1285
|
+
limitName: t.limitName ?? e.limitName,
|
|
1286
|
+
primary: t.primary ? {
|
|
1287
|
+
...e.primary ?? {},
|
|
1288
|
+
...t.primary
|
|
1289
|
+
} : e.primary,
|
|
1290
|
+
secondary: t.secondary ? {
|
|
1291
|
+
...e.secondary ?? {},
|
|
1292
|
+
...t.secondary
|
|
1293
|
+
} : e.secondary,
|
|
1294
|
+
credits: t.credits ? {
|
|
1295
|
+
...e.credits ?? {},
|
|
1296
|
+
...t.credits
|
|
1297
|
+
} : e.credits,
|
|
1298
|
+
individualLimit: t.individualLimit ? {
|
|
1299
|
+
...e.individualLimit ?? {},
|
|
1300
|
+
...t.individualLimit
|
|
1301
|
+
} : e.individualLimit,
|
|
1302
|
+
planType: t.planType ?? e.planType,
|
|
1303
|
+
rateLimitReachedType: t.rateLimitReachedType ?? e.rateLimitReachedType
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1306
|
+
//#endregion
|
|
952
1307
|
//#region src/node/codex-surface-transport-options.ts
|
|
953
|
-
function
|
|
1308
|
+
function on(e) {
|
|
954
1309
|
return "type" in e && e.type === "unixSocket";
|
|
955
1310
|
}
|
|
956
|
-
function
|
|
957
|
-
let t = e.codexHome === void 0 ? void 0 :
|
|
1311
|
+
function sn(e) {
|
|
1312
|
+
let t = e.codexHome === void 0 ? void 0 : cn(e.codexHome), n = e.transport?.codexHome;
|
|
958
1313
|
if (t !== void 0 && n !== void 0 && t !== n) throw Error("Codex surface codexHome conflicts with transport.codexHome");
|
|
959
1314
|
return {
|
|
960
1315
|
...e.transport ?? {},
|
|
961
1316
|
...t === void 0 ? {} : { codexHome: t }
|
|
962
1317
|
};
|
|
963
1318
|
}
|
|
964
|
-
function
|
|
1319
|
+
function cn(e) {
|
|
965
1320
|
let t = e.trim();
|
|
966
1321
|
if (!t) throw Error("Codex surface codexHome cannot be empty");
|
|
967
1322
|
if (!v(t)) throw Error("Codex surface codexHome must be an absolute path");
|
|
@@ -969,7 +1324,7 @@ function Ot(e) {
|
|
|
969
1324
|
}
|
|
970
1325
|
//#endregion
|
|
971
1326
|
//#region src/node/codex-surface-authentication-controller.ts
|
|
972
|
-
var
|
|
1327
|
+
var ln = class {
|
|
973
1328
|
client;
|
|
974
1329
|
host;
|
|
975
1330
|
accountRefreshPromise = null;
|
|
@@ -1153,7 +1508,7 @@ var kt = class {
|
|
|
1153
1508
|
};
|
|
1154
1509
|
//#endregion
|
|
1155
1510
|
//#region src/node/codex-conversation-handle.ts
|
|
1156
|
-
function
|
|
1511
|
+
function un(e, t) {
|
|
1157
1512
|
let n = async (e) => (await e(), t.getSnapshot());
|
|
1158
1513
|
return {
|
|
1159
1514
|
id: e,
|
|
@@ -1193,64 +1548,37 @@ function At(e, t) {
|
|
|
1193
1548
|
};
|
|
1194
1549
|
}
|
|
1195
1550
|
//#endregion
|
|
1196
|
-
//#region src/node/codex-file-attachment.ts
|
|
1197
|
-
var jt = "<attached_file>\n", Mt = "\n</attached_file>";
|
|
1198
|
-
function Nt(e, t) {
|
|
1199
|
-
return {
|
|
1200
|
-
type: "text",
|
|
1201
|
-
text: `${jt}${JSON.stringify({
|
|
1202
|
-
name: e,
|
|
1203
|
-
path: t
|
|
1204
|
-
}).replaceAll("<", "\\u003c")}${Mt}`,
|
|
1205
|
-
text_elements: []
|
|
1206
|
-
};
|
|
1207
|
-
}
|
|
1208
|
-
function Pt(e) {
|
|
1209
|
-
if (!e.startsWith(jt) || !e.endsWith(Mt)) return null;
|
|
1210
|
-
try {
|
|
1211
|
-
let t = JSON.parse(e.slice(16, -17));
|
|
1212
|
-
if (typeof t != "object" || !t || Array.isArray(t)) return null;
|
|
1213
|
-
let n = t;
|
|
1214
|
-
return typeof n.name == "string" && typeof n.path == "string" && n.path.length > 0 ? {
|
|
1215
|
-
name: n.name,
|
|
1216
|
-
path: n.path
|
|
1217
|
-
} : null;
|
|
1218
|
-
} catch {
|
|
1219
|
-
return null;
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1222
|
-
//#endregion
|
|
1223
1551
|
//#region src/node/tool-output.ts
|
|
1224
|
-
var
|
|
1225
|
-
function
|
|
1552
|
+
var dn = "Result returned in structuredContent.";
|
|
1553
|
+
function I(e) {
|
|
1226
1554
|
if (typeof e == "string") return e;
|
|
1227
|
-
if (Array.isArray(e)) return e.map((e) =>
|
|
1228
|
-
if (!
|
|
1229
|
-
let t = "structuredContent" in e ?
|
|
1555
|
+
if (Array.isArray(e)) return e.map((e) => I(e)).filter(Boolean).join("\n\n") || void 0;
|
|
1556
|
+
if (!pn(e)) return JSON.stringify(e);
|
|
1557
|
+
let t = "structuredContent" in e ? I(e.structuredContent) : void 0;
|
|
1230
1558
|
if (t) {
|
|
1231
|
-
let n =
|
|
1232
|
-
return !n || n.trim() ===
|
|
1559
|
+
let n = fn(e);
|
|
1560
|
+
return !n || n.trim() === dn ? t : `${n}\n\n${t}`;
|
|
1233
1561
|
}
|
|
1234
|
-
return
|
|
1562
|
+
return fn(e) ?? JSON.stringify(e);
|
|
1235
1563
|
}
|
|
1236
|
-
function
|
|
1564
|
+
function fn(e) {
|
|
1237
1565
|
if (typeof e.text == "string") return e.text;
|
|
1238
1566
|
if (typeof e.content == "string") return e.content;
|
|
1239
|
-
if (Array.isArray(e.content)) return
|
|
1567
|
+
if (Array.isArray(e.content)) return I(e.content);
|
|
1240
1568
|
}
|
|
1241
|
-
function
|
|
1569
|
+
function pn(e) {
|
|
1242
1570
|
return !!(e && typeof e == "object" && !Array.isArray(e));
|
|
1243
1571
|
}
|
|
1244
1572
|
//#endregion
|
|
1245
1573
|
//#region src/node/codex-tool-part-adapter.ts
|
|
1246
|
-
var
|
|
1247
|
-
function
|
|
1574
|
+
var mn = "Result returned in structuredContent.", hn = 32 * 1024;
|
|
1575
|
+
function gn(e, t) {
|
|
1248
1576
|
let n = e.status;
|
|
1249
1577
|
if (e.kind === "command") {
|
|
1250
|
-
let r =
|
|
1251
|
-
return
|
|
1578
|
+
let r = V(e.input) ? e.input : {}, i = typeof r.cwd == "string" ? r.cwd : t ?? void 0;
|
|
1579
|
+
return Tn(r.commandActions).flatMap((e) => {
|
|
1252
1580
|
if (e.type !== "read") return [];
|
|
1253
|
-
let t =
|
|
1581
|
+
let t = Ln(e.path ?? e.name, i);
|
|
1254
1582
|
return t ? [{
|
|
1255
1583
|
action: "read",
|
|
1256
1584
|
path: t,
|
|
@@ -1259,12 +1587,12 @@ function Bt(e, t) {
|
|
|
1259
1587
|
});
|
|
1260
1588
|
}
|
|
1261
1589
|
if (e.kind !== "fileChange") return [];
|
|
1262
|
-
let r =
|
|
1590
|
+
let r = V(e.input) ? e.input : {}, i = e.metadata ?? {};
|
|
1263
1591
|
return (Array.isArray(i.changes) ? i.changes : Array.isArray(r.changes) ? r.changes : []).flatMap((e) => {
|
|
1264
|
-
if (!
|
|
1265
|
-
let r =
|
|
1592
|
+
if (!V(e) || typeof e.path != "string") return [];
|
|
1593
|
+
let r = B(e.kind);
|
|
1266
1594
|
if (r === "delete") return [];
|
|
1267
|
-
let i =
|
|
1595
|
+
let i = Ln(e.path, t ?? void 0);
|
|
1268
1596
|
return i ? [{
|
|
1269
1597
|
action: r === "add" ? "create" : "edit",
|
|
1270
1598
|
path: i,
|
|
@@ -1272,10 +1600,10 @@ function Bt(e, t) {
|
|
|
1272
1600
|
}] : [];
|
|
1273
1601
|
});
|
|
1274
1602
|
}
|
|
1275
|
-
function
|
|
1276
|
-
if (!
|
|
1603
|
+
function L(e, t = {}) {
|
|
1604
|
+
if (!V(e) || typeof e.id != "string") return null;
|
|
1277
1605
|
if (e.type === "commandExecution") {
|
|
1278
|
-
let n = typeof e.command == "string" ? e.command : "command", r =
|
|
1606
|
+
let n = typeof e.command == "string" ? e.command : "command", r = R(e.status), i = Sn(r, e.commandActions, n), a = t.includeCommandOutput && typeof e.aggregatedOutput == "string" ? e.aggregatedOutput : void 0;
|
|
1279
1607
|
return {
|
|
1280
1608
|
type: "tool",
|
|
1281
1609
|
id: e.id,
|
|
@@ -1300,14 +1628,14 @@ function A(e, t = {}) {
|
|
|
1300
1628
|
};
|
|
1301
1629
|
}
|
|
1302
1630
|
if (e.type === "mcpToolCall") {
|
|
1303
|
-
let t = typeof e.server == "string" ? e.server : "mcp", n = typeof e.tool == "string" ? e.tool : "tool", r =
|
|
1631
|
+
let t = typeof e.server == "string" ? e.server : "mcp", n = typeof e.tool == "string" ? e.tool : "tool", r = Gn(Bn(e.error)), i = H(e.arguments), a = H(e.result);
|
|
1304
1632
|
return {
|
|
1305
1633
|
type: "tool",
|
|
1306
1634
|
id: e.id,
|
|
1307
1635
|
kind: "mcp",
|
|
1308
1636
|
title: `${t}.${n}`,
|
|
1309
|
-
status:
|
|
1310
|
-
body: r ??
|
|
1637
|
+
status: R(e.status),
|
|
1638
|
+
body: r ?? Gn(Vn(a)),
|
|
1311
1639
|
...i === void 0 ? {} : { input: i },
|
|
1312
1640
|
...a === void 0 ? {} : { output: a },
|
|
1313
1641
|
metadata: {
|
|
@@ -1320,14 +1648,14 @@ function A(e, t = {}) {
|
|
|
1320
1648
|
};
|
|
1321
1649
|
}
|
|
1322
1650
|
if (e.type === "dynamicToolCall") {
|
|
1323
|
-
let t = typeof e.tool == "string" ? e.tool : "tool", n = typeof e.namespace == "string" ? e.namespace : null, r =
|
|
1651
|
+
let t = typeof e.tool == "string" ? e.tool : "tool", n = typeof e.namespace == "string" ? e.namespace : null, r = H(e.arguments), i = H(e.contentItems);
|
|
1324
1652
|
return {
|
|
1325
1653
|
type: "tool",
|
|
1326
1654
|
id: e.id,
|
|
1327
1655
|
kind: "dynamic",
|
|
1328
1656
|
title: n ? `${n}.${t}` : t,
|
|
1329
|
-
status:
|
|
1330
|
-
body:
|
|
1657
|
+
status: R(e.status),
|
|
1658
|
+
body: Gn(Un(i)),
|
|
1331
1659
|
...r === void 0 ? {} : { input: r },
|
|
1332
1660
|
...i === void 0 ? {} : { output: i },
|
|
1333
1661
|
metadata: {
|
|
@@ -1339,7 +1667,7 @@ function A(e, t = {}) {
|
|
|
1339
1667
|
};
|
|
1340
1668
|
}
|
|
1341
1669
|
if (e.type === "fileChange") {
|
|
1342
|
-
let n = Array.isArray(e.changes) ? e.changes : [], r =
|
|
1670
|
+
let n = Array.isArray(e.changes) ? e.changes : [], r = R(e.status), i = Mn(r, n);
|
|
1343
1671
|
return {
|
|
1344
1672
|
type: "tool",
|
|
1345
1673
|
id: e.id,
|
|
@@ -1347,7 +1675,7 @@ function A(e, t = {}) {
|
|
|
1347
1675
|
title: n.length === 1 ? "1 file change" : `${n.length} file changes`,
|
|
1348
1676
|
status: r,
|
|
1349
1677
|
...i ? { statusText: i } : {},
|
|
1350
|
-
body:
|
|
1678
|
+
body: Wn(n),
|
|
1351
1679
|
input: { changes: n },
|
|
1352
1680
|
metadata: {
|
|
1353
1681
|
changes: n,
|
|
@@ -1376,19 +1704,19 @@ function A(e, t = {}) {
|
|
|
1376
1704
|
id: e.id,
|
|
1377
1705
|
kind: "dynamic",
|
|
1378
1706
|
title: "image_generation",
|
|
1379
|
-
status:
|
|
1707
|
+
status: R(e.status),
|
|
1380
1708
|
body: typeof e.revisedPrompt == "string" ? e.revisedPrompt : void 0,
|
|
1381
1709
|
input: { revisedPrompt: e.revisedPrompt },
|
|
1382
1710
|
output: e.savedPath,
|
|
1383
1711
|
metadata: { savedPath: e.savedPath }
|
|
1384
1712
|
} : null;
|
|
1385
1713
|
}
|
|
1386
|
-
function
|
|
1387
|
-
if (!
|
|
1714
|
+
function _n(e) {
|
|
1715
|
+
if (!V(e) || e.type !== "commandExecution" || typeof e.command != "string") return !1;
|
|
1388
1716
|
let t = e.command;
|
|
1389
|
-
return
|
|
1717
|
+
return En(t) || Dn(t) || On(t);
|
|
1390
1718
|
}
|
|
1391
|
-
function
|
|
1719
|
+
function vn(e, t) {
|
|
1392
1720
|
return {
|
|
1393
1721
|
itemId: e,
|
|
1394
1722
|
bodyDelta: t,
|
|
@@ -1401,11 +1729,11 @@ function Ht(e, t) {
|
|
|
1401
1729
|
}
|
|
1402
1730
|
};
|
|
1403
1731
|
}
|
|
1404
|
-
function
|
|
1405
|
-
let n =
|
|
1732
|
+
function yn(e, t) {
|
|
1733
|
+
let n = Mn("running", t);
|
|
1406
1734
|
return {
|
|
1407
1735
|
itemId: e,
|
|
1408
|
-
body:
|
|
1736
|
+
body: Wn(t),
|
|
1409
1737
|
...n ? { statusText: n } : {},
|
|
1410
1738
|
input: { changes: t },
|
|
1411
1739
|
metadata: { changes: t },
|
|
@@ -1416,13 +1744,13 @@ function Ut(e, t) {
|
|
|
1416
1744
|
title: t.length === 1 ? "1 file change" : `${t.length} file changes`,
|
|
1417
1745
|
status: "running",
|
|
1418
1746
|
...n ? { statusText: n } : {},
|
|
1419
|
-
body:
|
|
1747
|
+
body: Wn(t),
|
|
1420
1748
|
input: { changes: t },
|
|
1421
1749
|
metadata: { changes: t }
|
|
1422
1750
|
}
|
|
1423
1751
|
};
|
|
1424
1752
|
}
|
|
1425
|
-
function
|
|
1753
|
+
function bn(e, t) {
|
|
1426
1754
|
return {
|
|
1427
1755
|
itemId: e,
|
|
1428
1756
|
bodyAppend: t,
|
|
@@ -1435,12 +1763,12 @@ function Wt(e, t) {
|
|
|
1435
1763
|
}
|
|
1436
1764
|
};
|
|
1437
1765
|
}
|
|
1438
|
-
function
|
|
1439
|
-
let i =
|
|
1766
|
+
function xn(e, t, n, r = "completed") {
|
|
1767
|
+
let i = H(t), a = Gn(I(i));
|
|
1440
1768
|
return {
|
|
1441
1769
|
itemId: e,
|
|
1442
1770
|
title: n && n.trim() ? n : void 0,
|
|
1443
|
-
status:
|
|
1771
|
+
status: R(r),
|
|
1444
1772
|
body: a,
|
|
1445
1773
|
...i === void 0 ? {} : { output: i },
|
|
1446
1774
|
fallbackToolPart: {
|
|
@@ -1448,21 +1776,21 @@ function Gt(e, t, n, r = "completed") {
|
|
|
1448
1776
|
id: e,
|
|
1449
1777
|
kind: "generic",
|
|
1450
1778
|
title: n && n.trim() ? n : "Tool output",
|
|
1451
|
-
status:
|
|
1779
|
+
status: R(r),
|
|
1452
1780
|
body: a,
|
|
1453
1781
|
...i === void 0 ? {} : { output: i }
|
|
1454
1782
|
}
|
|
1455
1783
|
};
|
|
1456
1784
|
}
|
|
1457
|
-
function
|
|
1785
|
+
function R(e) {
|
|
1458
1786
|
return e === "completed" || e === "succeeded" || e === "success" ? "completed" : e === "failed" || e === "error" || e === "declined" || e === "incomplete" || e === "canceled" || e === "cancelled" ? "failed" : "running";
|
|
1459
1787
|
}
|
|
1460
|
-
function
|
|
1461
|
-
let r =
|
|
1788
|
+
function Sn(e, t, n) {
|
|
1789
|
+
let r = Cn(e, t, n);
|
|
1462
1790
|
return r ? JSON.stringify(r) : void 0;
|
|
1463
1791
|
}
|
|
1464
|
-
function
|
|
1465
|
-
let r =
|
|
1792
|
+
function Cn(e, t, n) {
|
|
1793
|
+
let r = Tn(t), i = new Set(r.map((e) => e.type));
|
|
1466
1794
|
if (r.length === 0) return {
|
|
1467
1795
|
action: "run",
|
|
1468
1796
|
phase: e,
|
|
@@ -1470,37 +1798,37 @@ function qt(e, t, n) {
|
|
|
1470
1798
|
source: "codex"
|
|
1471
1799
|
};
|
|
1472
1800
|
if (i.size === 1 && i.has("read")) {
|
|
1473
|
-
let t =
|
|
1801
|
+
let t = z(r.map((e) => e.name ?? e.path));
|
|
1474
1802
|
return {
|
|
1475
1803
|
action: "read",
|
|
1476
1804
|
phase: e,
|
|
1477
1805
|
params: {
|
|
1478
1806
|
names: t,
|
|
1479
|
-
target:
|
|
1807
|
+
target: An(t, n)
|
|
1480
1808
|
},
|
|
1481
1809
|
source: "codex"
|
|
1482
1810
|
};
|
|
1483
1811
|
}
|
|
1484
1812
|
if (i.size === 1 && i.has("listFiles")) {
|
|
1485
|
-
let t =
|
|
1813
|
+
let t = z(r.map((e) => e.path ?? e.command));
|
|
1486
1814
|
return {
|
|
1487
1815
|
action: "list",
|
|
1488
1816
|
phase: e,
|
|
1489
1817
|
params: {
|
|
1490
1818
|
targets: t,
|
|
1491
|
-
target:
|
|
1819
|
+
target: kn(t, n)
|
|
1492
1820
|
},
|
|
1493
1821
|
source: "codex"
|
|
1494
1822
|
};
|
|
1495
1823
|
}
|
|
1496
1824
|
if (i.size === 1 && i.has("search")) {
|
|
1497
|
-
let t =
|
|
1825
|
+
let t = z(r.map((e) => e.query && e.path ? `"${e.query}" in ${e.path}` : e.query ?? e.path ?? e.command));
|
|
1498
1826
|
return {
|
|
1499
1827
|
action: "search",
|
|
1500
1828
|
phase: e,
|
|
1501
1829
|
params: {
|
|
1502
1830
|
targets: t,
|
|
1503
|
-
target:
|
|
1831
|
+
target: kn(t, n)
|
|
1504
1832
|
},
|
|
1505
1833
|
source: "codex"
|
|
1506
1834
|
};
|
|
@@ -1510,16 +1838,16 @@ function qt(e, t, n) {
|
|
|
1510
1838
|
phase: e,
|
|
1511
1839
|
params: {
|
|
1512
1840
|
actions: r.map((e) => e.type),
|
|
1513
|
-
target:
|
|
1841
|
+
target: kn(z(r.map(wn)), n)
|
|
1514
1842
|
},
|
|
1515
1843
|
source: "codex"
|
|
1516
1844
|
};
|
|
1517
1845
|
}
|
|
1518
|
-
function
|
|
1846
|
+
function wn(e) {
|
|
1519
1847
|
return e.path ?? e.name ?? e.query ?? e.command;
|
|
1520
1848
|
}
|
|
1521
|
-
function
|
|
1522
|
-
return Array.isArray(e) ? e.flatMap((e) => !
|
|
1849
|
+
function Tn(e) {
|
|
1850
|
+
return Array.isArray(e) ? e.flatMap((e) => !V(e) || e.type !== "read" && e.type !== "listFiles" && e.type !== "search" ? [] : [{
|
|
1523
1851
|
command: typeof e.command == "string" ? e.command : void 0,
|
|
1524
1852
|
name: typeof e.name == "string" ? e.name : void 0,
|
|
1525
1853
|
path: typeof e.path == "string" ? e.path : void 0,
|
|
@@ -1527,35 +1855,35 @@ function Yt(e) {
|
|
|
1527
1855
|
type: e.type
|
|
1528
1856
|
}]) : [];
|
|
1529
1857
|
}
|
|
1530
|
-
function
|
|
1858
|
+
function En(e) {
|
|
1531
1859
|
return /(?:^|[\s;"'(|&])apply_patch(?:\s|$)/u.test(e);
|
|
1532
1860
|
}
|
|
1533
|
-
function
|
|
1861
|
+
function Dn(e) {
|
|
1534
1862
|
return /(?:^|[\s;"'(|&])(?:cat|printf|echo)\b[\s\S]*>>?\s*(?:"[^"]+"|'[^']+'|[^\s;"'&|]+)(?=$|[\s;&|])/u.test(e);
|
|
1535
1863
|
}
|
|
1536
|
-
function
|
|
1864
|
+
function On(e) {
|
|
1537
1865
|
return /(?:^|[\s;"'(|&])tee(?:\s+-a)?\s+(?!-)(?:"[^"]+"|'[^']+'|[^\s;"'&|]+)(?=$|[\s;&|])/u.test(e);
|
|
1538
1866
|
}
|
|
1539
|
-
function
|
|
1867
|
+
function z(e) {
|
|
1540
1868
|
return [...new Set(e.map((e) => e?.trim()).filter((e) => !!e))];
|
|
1541
1869
|
}
|
|
1542
|
-
function
|
|
1870
|
+
function kn(e, t) {
|
|
1543
1871
|
return e.length === 0 ? t : e.length <= 3 ? e.join(", ") : `${e.slice(0, 3).join(", ")} and ${e.length - 3} more`;
|
|
1544
1872
|
}
|
|
1545
|
-
function
|
|
1546
|
-
return
|
|
1873
|
+
function An(e, t) {
|
|
1874
|
+
return jn(e, t);
|
|
1547
1875
|
}
|
|
1548
|
-
function
|
|
1549
|
-
return
|
|
1876
|
+
function jn(e, t) {
|
|
1877
|
+
return kn(z(e.map(zn)), t);
|
|
1550
1878
|
}
|
|
1551
|
-
function
|
|
1552
|
-
let n =
|
|
1879
|
+
function Mn(e, t) {
|
|
1880
|
+
let n = Nn(e, t);
|
|
1553
1881
|
return n ? JSON.stringify(n) : void 0;
|
|
1554
1882
|
}
|
|
1555
|
-
function
|
|
1883
|
+
function Nn(e, t) {
|
|
1556
1884
|
let n = t.flatMap((e) => {
|
|
1557
|
-
if (!
|
|
1558
|
-
let t = typeof e.path == "string" ? e.path : void 0, n =
|
|
1885
|
+
if (!V(e)) return [];
|
|
1886
|
+
let t = typeof e.path == "string" ? e.path : void 0, n = B(e.kind), r = Fn(e);
|
|
1559
1887
|
return [{
|
|
1560
1888
|
addedLines: r.addedLines,
|
|
1561
1889
|
kind: n,
|
|
@@ -1564,9 +1892,9 @@ function rn(e, t) {
|
|
|
1564
1892
|
}];
|
|
1565
1893
|
});
|
|
1566
1894
|
if (!n.length) return;
|
|
1567
|
-
let r = n.reduce((e, t) => e + t.addedLines, 0), i = n.reduce((e, t) => e + t.removedLines, 0), a =
|
|
1895
|
+
let r = n.reduce((e, t) => e + t.addedLines, 0), i = n.reduce((e, t) => e + t.removedLines, 0), a = z(n.map((e) => e.path)), o = jn(a, `${n.length} files`);
|
|
1568
1896
|
return {
|
|
1569
|
-
action:
|
|
1897
|
+
action: Pn(n.map((e) => e.kind)),
|
|
1570
1898
|
phase: e,
|
|
1571
1899
|
params: {
|
|
1572
1900
|
addedLines: r,
|
|
@@ -1577,20 +1905,20 @@ function rn(e, t) {
|
|
|
1577
1905
|
source: "codex"
|
|
1578
1906
|
};
|
|
1579
1907
|
}
|
|
1580
|
-
function
|
|
1908
|
+
function Pn(e) {
|
|
1581
1909
|
return e.every((e) => e === "add") ? "create" : e.every((e) => e === "delete") ? "delete" : "edit";
|
|
1582
1910
|
}
|
|
1583
|
-
function
|
|
1584
|
-
let t = typeof e.diff == "string" ? e.diff : void 0, n =
|
|
1911
|
+
function Fn(e) {
|
|
1912
|
+
let t = typeof e.diff == "string" ? e.diff : void 0, n = B(e.kind);
|
|
1585
1913
|
return n === "add" ? {
|
|
1586
|
-
addedLines:
|
|
1914
|
+
addedLines: Rn(t),
|
|
1587
1915
|
removedLines: 0
|
|
1588
1916
|
} : n === "delete" ? {
|
|
1589
1917
|
addedLines: 0,
|
|
1590
|
-
removedLines:
|
|
1591
|
-
} :
|
|
1918
|
+
removedLines: Rn(t)
|
|
1919
|
+
} : In(t);
|
|
1592
1920
|
}
|
|
1593
|
-
function
|
|
1921
|
+
function In(e) {
|
|
1594
1922
|
if (!e) return {
|
|
1595
1923
|
addedLines: 0,
|
|
1596
1924
|
removedLines: 0
|
|
@@ -1602,54 +1930,54 @@ function sn(e) {
|
|
|
1602
1930
|
removedLines: n
|
|
1603
1931
|
};
|
|
1604
1932
|
}
|
|
1605
|
-
function
|
|
1933
|
+
function B(e) {
|
|
1606
1934
|
if (e === "add" || e === "delete") return e;
|
|
1607
|
-
if (
|
|
1935
|
+
if (V(e) && typeof e.type == "string") return B(e.type);
|
|
1608
1936
|
}
|
|
1609
|
-
function
|
|
1937
|
+
function Ln(e, t) {
|
|
1610
1938
|
let n = e?.trim();
|
|
1611
1939
|
if (n) {
|
|
1612
1940
|
if (v(n)) return n;
|
|
1613
1941
|
if (!(!t || !v(t))) return x(t, n);
|
|
1614
1942
|
}
|
|
1615
1943
|
}
|
|
1616
|
-
function
|
|
1944
|
+
function Rn(e) {
|
|
1617
1945
|
if (!e) return 0;
|
|
1618
1946
|
let t = e.split(/\r\n|\r|\n/);
|
|
1619
1947
|
for (; t.at(-1) === "";) t.pop();
|
|
1620
1948
|
return t.length;
|
|
1621
1949
|
}
|
|
1622
|
-
function
|
|
1950
|
+
function zn(e) {
|
|
1623
1951
|
return e.split(/[\\/]/).filter(Boolean).at(-1) ?? e;
|
|
1624
1952
|
}
|
|
1625
|
-
function
|
|
1626
|
-
if (
|
|
1953
|
+
function Bn(e) {
|
|
1954
|
+
if (V(e)) return typeof e.message == "string" ? e.message : void 0;
|
|
1627
1955
|
}
|
|
1628
|
-
function
|
|
1629
|
-
if (!
|
|
1630
|
-
let t =
|
|
1631
|
-
return n ? !t || t.trim() ===
|
|
1956
|
+
function Vn(e) {
|
|
1957
|
+
if (!V(e)) return;
|
|
1958
|
+
let t = Hn(e.content), n = "structuredContent" in e ? I(e.structuredContent) : void 0;
|
|
1959
|
+
return n ? !t || t.trim() === mn ? n : `${t}\n\n${n}` : t;
|
|
1632
1960
|
}
|
|
1633
|
-
function
|
|
1634
|
-
if (Array.isArray(e)) return e.map((e) =>
|
|
1961
|
+
function Hn(e) {
|
|
1962
|
+
if (Array.isArray(e)) return e.map((e) => V(e) ? typeof e.text == "string" ? e.text : JSON.stringify(e) : "").filter(Boolean).join("\n\n") || void 0;
|
|
1635
1963
|
}
|
|
1636
|
-
function
|
|
1637
|
-
if (Array.isArray(e)) return e.map((e) =>
|
|
1964
|
+
function Un(e) {
|
|
1965
|
+
if (Array.isArray(e)) return e.map((e) => V(e) && typeof e.text == "string" ? e.text : JSON.stringify(e)).filter(Boolean).join("\n\n") || void 0;
|
|
1638
1966
|
}
|
|
1639
|
-
function
|
|
1640
|
-
return e.map((e) =>
|
|
1967
|
+
function Wn(e) {
|
|
1968
|
+
return e.map((e) => V(e) ? `${B(e.kind) ?? "update"} ${typeof e.path == "string" ? e.path : "unknown"}` : JSON.stringify(e)).join("\n") || void 0;
|
|
1641
1969
|
}
|
|
1642
|
-
function
|
|
1970
|
+
function V(e) {
|
|
1643
1971
|
return !!(e && typeof e == "object" && !Array.isArray(e));
|
|
1644
1972
|
}
|
|
1645
|
-
function
|
|
1646
|
-
return e !== void 0 && Buffer.byteLength(e) <=
|
|
1973
|
+
function Gn(e) {
|
|
1974
|
+
return e !== void 0 && Buffer.byteLength(e) <= hn ? e : void 0;
|
|
1647
1975
|
}
|
|
1648
|
-
function
|
|
1649
|
-
if (!(e === void 0 || !
|
|
1976
|
+
function H(e) {
|
|
1977
|
+
if (!(e === void 0 || !Kn(e, hn))) return e;
|
|
1650
1978
|
}
|
|
1651
|
-
function
|
|
1652
|
-
if (
|
|
1979
|
+
function Kn(e, t) {
|
|
1980
|
+
if (qn(e, t, /* @__PURE__ */ new Set())) return !1;
|
|
1653
1981
|
try {
|
|
1654
1982
|
let n = JSON.stringify(e);
|
|
1655
1983
|
return n !== void 0 && Buffer.byteLength(n) <= t;
|
|
@@ -1657,28 +1985,28 @@ function _n(e, t) {
|
|
|
1657
1985
|
return !1;
|
|
1658
1986
|
}
|
|
1659
1987
|
}
|
|
1660
|
-
function
|
|
1988
|
+
function qn(e, t, n) {
|
|
1661
1989
|
if (typeof e == "string") return Buffer.byteLength(e) > t;
|
|
1662
1990
|
if (typeof e != "object" || !e) return !1;
|
|
1663
1991
|
if (n.has(e)) return !0;
|
|
1664
1992
|
n.add(e);
|
|
1665
|
-
let r = (Array.isArray(e) ? e : Object.values(e)).some((e) =>
|
|
1993
|
+
let r = (Array.isArray(e) ? e : Object.values(e)).some((e) => qn(e, t, n));
|
|
1666
1994
|
return n.delete(e), r;
|
|
1667
1995
|
}
|
|
1668
1996
|
//#endregion
|
|
1669
1997
|
//#region src/node/codex-surface-message-state.ts
|
|
1670
|
-
function
|
|
1998
|
+
function Jn(e) {
|
|
1671
1999
|
for (let t = e.length - 1; t >= 0; --t) {
|
|
1672
2000
|
let n = e[t];
|
|
1673
2001
|
if (n?.status === "inProgress") return n.id;
|
|
1674
2002
|
}
|
|
1675
2003
|
return null;
|
|
1676
2004
|
}
|
|
1677
|
-
function
|
|
1678
|
-
let i = [...e], a =
|
|
2005
|
+
function U(e, t, n, r = {}) {
|
|
2006
|
+
let i = [...e], a = K(i, (e) => e.metadata?.turnId === n), o = a >= 0 ? i[a] : void 0;
|
|
1679
2007
|
if (o?.role === "assistant" && o.kind === void 0 && o.status === "streaming") return i;
|
|
1680
2008
|
if (r.forceSegment) {
|
|
1681
|
-
let e =
|
|
2009
|
+
let e = K(i, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n), t = e >= 0 ? i[e] : void 0;
|
|
1682
2010
|
t?.parts.length === 0 ? i.splice(e, 1) : t && i.splice(e, 1, {
|
|
1683
2011
|
...t,
|
|
1684
2012
|
status: "complete"
|
|
@@ -1698,9 +2026,9 @@ function I(e, t, n, r = {}) {
|
|
|
1698
2026
|
}
|
|
1699
2027
|
}), i;
|
|
1700
2028
|
}
|
|
1701
|
-
function
|
|
2029
|
+
function Yn(e, t, n, r, i, a) {
|
|
1702
2030
|
if (!i) return [...e];
|
|
1703
|
-
let o =
|
|
2031
|
+
let o = U(e, t, n), s = K(o, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n), c = s >= 0 ? o[s] : void 0;
|
|
1704
2032
|
if (!c) return o;
|
|
1705
2033
|
let l = [...c.parts], u = l.at(-1);
|
|
1706
2034
|
return u?.type === "text" && u.itemId === r ? l.splice(l.length - 1, 1, {
|
|
@@ -1716,9 +2044,9 @@ function bn(e, t, n, r, i, a) {
|
|
|
1716
2044
|
...c,
|
|
1717
2045
|
status: "streaming",
|
|
1718
2046
|
parts: l
|
|
1719
|
-
}),
|
|
2047
|
+
}), G(o, t);
|
|
1720
2048
|
}
|
|
1721
|
-
function
|
|
2049
|
+
function Xn(e, t, n, r, i) {
|
|
1722
2050
|
let a = i.map((e, t) => {
|
|
1723
2051
|
let n = e.trim();
|
|
1724
2052
|
return n ? {
|
|
@@ -1729,16 +2057,16 @@ function xn(e, t, n, r, i) {
|
|
|
1729
2057
|
} : null;
|
|
1730
2058
|
}).filter((e) => e !== null);
|
|
1731
2059
|
if (a.length === 0) return [...e];
|
|
1732
|
-
let o =
|
|
2060
|
+
let o = U(e, t, n), s = K(o, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n), c = s >= 0 ? o[s] : void 0;
|
|
1733
2061
|
if (!c) return o;
|
|
1734
2062
|
let l = c.parts.findIndex((e) => e.type === "reasoning" && e.itemId === r), u = c.parts.filter((e) => e.type !== "reasoning" || e.itemId !== r);
|
|
1735
2063
|
return u.splice(l >= 0 ? l : u.length, 0, ...a), o.splice(s, 1, {
|
|
1736
2064
|
...c,
|
|
1737
2065
|
status: "streaming",
|
|
1738
2066
|
parts: u
|
|
1739
|
-
}),
|
|
2067
|
+
}), G(o, t);
|
|
1740
2068
|
}
|
|
1741
|
-
function
|
|
2069
|
+
function Zn(e, t, n, r, i, a) {
|
|
1742
2070
|
let o = [...e];
|
|
1743
2071
|
for (let e = o.length - 1; e >= 0; --e) {
|
|
1744
2072
|
let s = o[e];
|
|
@@ -1754,9 +2082,9 @@ function Sn(e, t, n, r, i, a) {
|
|
|
1754
2082
|
}), o.splice(e, 1, {
|
|
1755
2083
|
...s,
|
|
1756
2084
|
parts: l
|
|
1757
|
-
}),
|
|
2085
|
+
}), G(o, t);
|
|
1758
2086
|
}
|
|
1759
|
-
let s =
|
|
2087
|
+
let s = U(o, t, n), c = K(s, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n), l = c >= 0 ? s[c] : void 0;
|
|
1760
2088
|
if (!l) return s;
|
|
1761
2089
|
let u = {
|
|
1762
2090
|
type: "text",
|
|
@@ -1767,10 +2095,10 @@ function Sn(e, t, n, r, i, a) {
|
|
|
1767
2095
|
return s.splice(c, 1, {
|
|
1768
2096
|
...l,
|
|
1769
2097
|
parts: [...l.parts, u]
|
|
1770
|
-
}),
|
|
2098
|
+
}), G(s, t);
|
|
1771
2099
|
}
|
|
1772
|
-
function
|
|
1773
|
-
return
|
|
2100
|
+
function Qn(e, t, n, r) {
|
|
2101
|
+
return G(e.map((e) => {
|
|
1774
2102
|
if (e.role !== "assistant" || e.metadata?.turnId !== n) return e;
|
|
1775
2103
|
let t = e.parts.filter((e) => e.type !== "text" || e.itemId !== r);
|
|
1776
2104
|
return t.length === e.parts.length ? e : {
|
|
@@ -1779,16 +2107,16 @@ function Cn(e, t, n, r) {
|
|
|
1779
2107
|
};
|
|
1780
2108
|
}), t);
|
|
1781
2109
|
}
|
|
1782
|
-
function
|
|
2110
|
+
function $n(e) {
|
|
1783
2111
|
let t = /<proposed_plan>([\s\S]*?)<\/proposed_plan>/iu.exec(e), n = t?.[1]?.trim() ?? "";
|
|
1784
2112
|
return !t || !n ? null : {
|
|
1785
2113
|
markdown: n,
|
|
1786
2114
|
visibleText: `${e.slice(0, t.index)}${e.slice(t.index + t[0].length)}`.trim()
|
|
1787
2115
|
};
|
|
1788
2116
|
}
|
|
1789
|
-
function
|
|
2117
|
+
function W(e, t, n, r) {
|
|
1790
2118
|
let i = [...e], a = i.findIndex((e) => e.role === "assistant" && e.metadata?.turnId === n && e.parts.some((e) => e.type === "tool" && e.id === r.id));
|
|
1791
|
-
a < 0 && (i =
|
|
2119
|
+
a < 0 && (i = U(i, t, n), a = K(i, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n));
|
|
1792
2120
|
let o = a >= 0 ? i[a] : void 0;
|
|
1793
2121
|
if (!o) return i;
|
|
1794
2122
|
let s = [...o.parts], c = s.findIndex((e) => e.type === "tool" && e.id === r.id);
|
|
@@ -1800,7 +2128,7 @@ function L(e, t, n, r) {
|
|
|
1800
2128
|
body: r.body ?? e.body,
|
|
1801
2129
|
input: r.input ?? e.input,
|
|
1802
2130
|
output: r.output ?? e.output,
|
|
1803
|
-
statusText: r.statusText ??
|
|
2131
|
+
statusText: r.statusText ?? or(e.statusText, r.status),
|
|
1804
2132
|
metadata: {
|
|
1805
2133
|
...e.metadata ?? {},
|
|
1806
2134
|
...r.metadata ?? {}
|
|
@@ -1810,11 +2138,11 @@ function L(e, t, n, r) {
|
|
|
1810
2138
|
return i.splice(a, 1, {
|
|
1811
2139
|
...o,
|
|
1812
2140
|
parts: s
|
|
1813
|
-
}),
|
|
2141
|
+
}), G(i, t);
|
|
1814
2142
|
}
|
|
1815
|
-
function
|
|
2143
|
+
function er(e, t, n, r) {
|
|
1816
2144
|
let i = [...e], a = i.findIndex((e) => e.role === "assistant" && e.metadata?.turnId === n && e.parts.some((e) => e.type === "media" && e.itemId === r.itemId));
|
|
1817
|
-
a < 0 && r.itemId && (a = i.findIndex((e) => e.role === "assistant" && e.metadata?.turnId === n && e.parts.some((e) => e.type === "tool" && e.id === r.itemId))), a < 0 && (i =
|
|
2145
|
+
a < 0 && r.itemId && (a = i.findIndex((e) => e.role === "assistant" && e.metadata?.turnId === n && e.parts.some((e) => e.type === "tool" && e.id === r.itemId))), a < 0 && (i = U(i, t, n), a = K(i, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n));
|
|
1818
2146
|
let o = a >= 0 ? i[a] : void 0;
|
|
1819
2147
|
if (!o) return i;
|
|
1820
2148
|
let s = [...o.parts], c = s.findIndex((e) => e.type === "media" && e.itemId === r.itemId);
|
|
@@ -1822,25 +2150,25 @@ function Tn(e, t, n, r) {
|
|
|
1822
2150
|
...o,
|
|
1823
2151
|
status: "streaming",
|
|
1824
2152
|
parts: s
|
|
1825
|
-
}),
|
|
2153
|
+
}), G(i, t);
|
|
1826
2154
|
}
|
|
1827
|
-
function
|
|
2155
|
+
function tr(e, t, n, r) {
|
|
1828
2156
|
let i = [...e], a = i.findIndex((e) => e.role === "assistant" && e.metadata?.turnId === n && e.parts.some((e) => e.type === "question" && e.request.id === r.request.id));
|
|
1829
|
-
a < 0 && (i =
|
|
2157
|
+
a < 0 && (i = U(i, t, n), a = K(i, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n));
|
|
1830
2158
|
let o = a >= 0 ? i[a] : void 0;
|
|
1831
2159
|
if (!o) return i;
|
|
1832
2160
|
let s = [...o.parts], c = s.findIndex((e) => e.type === "question" && e.request.id === r.request.id);
|
|
1833
2161
|
return c >= 0 ? s.splice(c, 1, r) : s.push(r), i.splice(a, 1, {
|
|
1834
2162
|
...o,
|
|
1835
2163
|
parts: s
|
|
1836
|
-
}),
|
|
2164
|
+
}), G(i, t);
|
|
1837
2165
|
}
|
|
1838
|
-
function
|
|
2166
|
+
function nr(e, t) {
|
|
1839
2167
|
return e.itemId === t.itemId && e.media.url === t.media.url && e.media.alt === t.media.alt && e.media.mimeType === t.media.mimeType && e.media.prompt === t.media.prompt && e.media.title === t.media.title;
|
|
1840
2168
|
}
|
|
1841
|
-
function
|
|
2169
|
+
function rr(e, t, n, r) {
|
|
1842
2170
|
let i = [...e], a = i.findIndex((e) => e.role === "assistant" && e.metadata?.turnId === n && e.parts.some((e) => e.type === "tool" && e.id === r.itemId));
|
|
1843
|
-
if (a < 0) return r.fallbackToolPart ?
|
|
2171
|
+
if (a < 0) return r.fallbackToolPart ? rr(W(i, t, n, r.fallbackToolPart), t, n, {
|
|
1844
2172
|
...r,
|
|
1845
2173
|
fallbackToolPart: void 0
|
|
1846
2174
|
}) : i;
|
|
@@ -1866,12 +2194,12 @@ function On(e, t, n, r) {
|
|
|
1866
2194
|
parts: s
|
|
1867
2195
|
}), i) : i;
|
|
1868
2196
|
}
|
|
1869
|
-
function
|
|
2197
|
+
function ir(e, t, n, r = "streaming") {
|
|
1870
2198
|
if (e.some((e) => e.kind === "compaction" && e.metadata?.turnId === n)) return e.map((e) => r === "complete" && e.kind === "compaction" && e.metadata?.turnId === n ? {
|
|
1871
2199
|
...e,
|
|
1872
2200
|
status: r
|
|
1873
2201
|
} : e);
|
|
1874
|
-
let i = [...e], a =
|
|
2202
|
+
let i = [...e], a = K(i, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n), o = a >= 0 ? i[a] : void 0;
|
|
1875
2203
|
return o?.parts.length === 0 ? i.splice(a, 1) : o && i.splice(a, 1, {
|
|
1876
2204
|
...o,
|
|
1877
2205
|
status: "complete"
|
|
@@ -1887,16 +2215,16 @@ function kn(e, t, n, r = "streaming") {
|
|
|
1887
2215
|
conversationId: t,
|
|
1888
2216
|
turnId: n
|
|
1889
2217
|
}
|
|
1890
|
-
}),
|
|
2218
|
+
}), G(i, t);
|
|
1891
2219
|
}
|
|
1892
|
-
function
|
|
2220
|
+
function ar(e, t, n) {
|
|
1893
2221
|
let r = n === "completed" ? "completed" : "failed";
|
|
1894
2222
|
return e.map((e) => {
|
|
1895
2223
|
if (e.metadata?.turnId !== t) return e;
|
|
1896
2224
|
let n = !1, i = e.parts.map((e) => e.type !== "tool" || e.status !== "running" ? e : (n = !0, {
|
|
1897
2225
|
...e,
|
|
1898
2226
|
status: r,
|
|
1899
|
-
statusText:
|
|
2227
|
+
statusText: or(e.statusText, r)
|
|
1900
2228
|
}));
|
|
1901
2229
|
return n ? {
|
|
1902
2230
|
...e,
|
|
@@ -1904,7 +2232,7 @@ function An(e, t, n) {
|
|
|
1904
2232
|
} : e;
|
|
1905
2233
|
});
|
|
1906
2234
|
}
|
|
1907
|
-
function
|
|
2235
|
+
function or(e, t) {
|
|
1908
2236
|
if (t === "running" || !e) return e;
|
|
1909
2237
|
try {
|
|
1910
2238
|
let n = JSON.parse(e);
|
|
@@ -1916,27 +2244,27 @@ function jn(e, t) {
|
|
|
1916
2244
|
return e;
|
|
1917
2245
|
}
|
|
1918
2246
|
}
|
|
1919
|
-
function
|
|
2247
|
+
function G(e, t) {
|
|
1920
2248
|
let n = e.map((e, t) => ({
|
|
1921
2249
|
message: e,
|
|
1922
2250
|
index: t
|
|
1923
2251
|
})).filter(({ message: e }) => e.metadata?.conversationId === t).at(-1)?.index ?? -1;
|
|
1924
2252
|
return e.filter((e, r) => e.metadata?.conversationId !== t || r === n || e.role !== "assistant" || e.kind !== void 0 || e.parts.length > 0);
|
|
1925
2253
|
}
|
|
1926
|
-
function
|
|
2254
|
+
function K(e, t) {
|
|
1927
2255
|
for (let n = e.length - 1; n >= 0; --n) {
|
|
1928
2256
|
let r = e[n];
|
|
1929
2257
|
if (r !== void 0 && t(r)) return n;
|
|
1930
2258
|
}
|
|
1931
2259
|
return -1;
|
|
1932
2260
|
}
|
|
1933
|
-
function
|
|
2261
|
+
function sr(e, t) {
|
|
1934
2262
|
return e.includes(t) ? [...e] : [...e, t];
|
|
1935
2263
|
}
|
|
1936
|
-
function
|
|
2264
|
+
function cr(e, t) {
|
|
1937
2265
|
return [e?.trim() ?? "", ...t.map((e) => `${e.status === "completed" ? "- [x]" : "- [ ]"} ${e.step}`)].filter(Boolean).join("\n");
|
|
1938
2266
|
}
|
|
1939
|
-
function
|
|
2267
|
+
function lr(e, t, n) {
|
|
1940
2268
|
return {
|
|
1941
2269
|
type: "tool",
|
|
1942
2270
|
id: `plan-progress-${e}`,
|
|
@@ -1959,19 +2287,19 @@ function Pn(e, t, n) {
|
|
|
1959
2287
|
}
|
|
1960
2288
|
//#endregion
|
|
1961
2289
|
//#region src/node/codex-conversation-history.ts
|
|
1962
|
-
var
|
|
2290
|
+
var ur = 16 * 1024 * 1024, dr = /* @__PURE__ */ new Set([
|
|
1963
2291
|
"image/avif",
|
|
1964
2292
|
"image/gif",
|
|
1965
2293
|
"image/jpeg",
|
|
1966
2294
|
"image/png",
|
|
1967
2295
|
"image/webp"
|
|
1968
2296
|
]);
|
|
1969
|
-
function
|
|
1970
|
-
return (Array.isArray(e.turns) ? e.turns : []).flatMap((t) =>
|
|
2297
|
+
function fr(e) {
|
|
2298
|
+
return (Array.isArray(e.turns) ? e.turns : []).flatMap((t) => mr(e.id, t));
|
|
1971
2299
|
}
|
|
1972
|
-
function
|
|
2300
|
+
function pr(e, t) {
|
|
1973
2301
|
let n = /* @__PURE__ */ new Map();
|
|
1974
|
-
for (let t of e) for (let e of t.parts) e.type !== "attachment" || e.attachment.kind !== "image" || !e.attachment.path ||
|
|
2302
|
+
for (let t of e) for (let e of t.parts) e.type !== "attachment" || e.attachment.kind !== "image" || !e.attachment.path || Dr(e.attachment.url) && n.set(e.attachment.path, e.attachment.url);
|
|
1975
2303
|
return n.size === 0 ? [...t] : t.map((e) => {
|
|
1976
2304
|
let t = !1, r = e.parts.map((e) => {
|
|
1977
2305
|
if (e.type !== "attachment" || e.attachment.kind !== "image" || !e.attachment.path) return e;
|
|
@@ -1990,14 +2318,14 @@ function Rn(e, t) {
|
|
|
1990
2318
|
} : e;
|
|
1991
2319
|
});
|
|
1992
2320
|
}
|
|
1993
|
-
function
|
|
1994
|
-
let n = [], r = [], i =
|
|
2321
|
+
function mr(e, t) {
|
|
2322
|
+
let n = [], r = [], i = jr(t.startedAt ?? t.completedAt), a = 0, o = !1, s = /* @__PURE__ */ new Set(), c = () => {
|
|
1995
2323
|
if (r.length === 0) return;
|
|
1996
2324
|
let o = a === 0 ? "" : `-segment-${a}`;
|
|
1997
2325
|
n.push({
|
|
1998
2326
|
id: `assistant-${t.id}${o}`,
|
|
1999
2327
|
role: "assistant",
|
|
2000
|
-
status:
|
|
2328
|
+
status: Ar(t.status),
|
|
2001
2329
|
turnId: t.id,
|
|
2002
2330
|
parts: [...r],
|
|
2003
2331
|
createdAt: i,
|
|
@@ -2009,7 +2337,7 @@ function zn(e, t) {
|
|
|
2009
2337
|
};
|
|
2010
2338
|
for (let a of Array.isArray(t.items) ? t.items : []) {
|
|
2011
2339
|
if (a.type === "userMessage") {
|
|
2012
|
-
let r =
|
|
2340
|
+
let r = vr(a), l = br(a);
|
|
2013
2341
|
if (r.length > 0) {
|
|
2014
2342
|
let u = o, d = u ? null : JSON.stringify(r);
|
|
2015
2343
|
if (d && s.has(d)) continue;
|
|
@@ -2026,7 +2354,7 @@ function zn(e, t) {
|
|
|
2026
2354
|
turnId: t.id,
|
|
2027
2355
|
...l.length > 0 ? {
|
|
2028
2356
|
asyncQuestionRequestIds: l,
|
|
2029
|
-
asyncQuestionAnswers:
|
|
2357
|
+
asyncQuestionAnswers: xr(a)
|
|
2030
2358
|
} : {}
|
|
2031
2359
|
}
|
|
2032
2360
|
});
|
|
@@ -2052,7 +2380,7 @@ function zn(e, t) {
|
|
|
2052
2380
|
continue;
|
|
2053
2381
|
}
|
|
2054
2382
|
if (a.type === "agentMessage") {
|
|
2055
|
-
let n = typeof a.text == "string" ? a.text : "", i =
|
|
2383
|
+
let n = typeof a.text == "string" ? a.text : "", i = gr(e, t.id, a, !0), s = a.phase === "final_answer" ? $n(n) : null;
|
|
2056
2384
|
s && !i ? s.visibleText && (o = !0, r.push({
|
|
2057
2385
|
type: "text",
|
|
2058
2386
|
text: s.visibleText,
|
|
@@ -2088,17 +2416,17 @@ function zn(e, t) {
|
|
|
2088
2416
|
}));
|
|
2089
2417
|
continue;
|
|
2090
2418
|
}
|
|
2091
|
-
let l =
|
|
2419
|
+
let l = L(a);
|
|
2092
2420
|
l && (o = !0, r.push(l));
|
|
2093
|
-
let u =
|
|
2421
|
+
let u = _r(a);
|
|
2094
2422
|
u && (o = !0, r.push(u));
|
|
2095
2423
|
}
|
|
2096
|
-
return c(), t.status === "inProgress" ? n :
|
|
2424
|
+
return c(), t.status === "inProgress" ? n : ar(n, t.id, t.status);
|
|
2097
2425
|
}
|
|
2098
|
-
function
|
|
2099
|
-
let r =
|
|
2426
|
+
function hr(e, t, n) {
|
|
2427
|
+
let r = jr(t.startedAt);
|
|
2100
2428
|
if (n.type === "userMessage") {
|
|
2101
|
-
let i =
|
|
2429
|
+
let i = vr(n), a = br(n);
|
|
2102
2430
|
return i.length > 0 ? {
|
|
2103
2431
|
id: n.clientId ?? `user-${e}-${t.id}-${n.id}`,
|
|
2104
2432
|
role: "user",
|
|
@@ -2112,13 +2440,13 @@ function Bn(e, t, n) {
|
|
|
2112
2440
|
itemId: n.id,
|
|
2113
2441
|
...a.length > 0 ? {
|
|
2114
2442
|
asyncQuestionRequestIds: a,
|
|
2115
|
-
asyncQuestionAnswers:
|
|
2443
|
+
asyncQuestionAnswers: xr(n)
|
|
2116
2444
|
} : {}
|
|
2117
2445
|
}
|
|
2118
2446
|
} : null;
|
|
2119
2447
|
}
|
|
2120
2448
|
if (n.type === "agentMessage" || n.type === "exitedReviewMode") {
|
|
2121
|
-
let i = n.type === "agentMessage" ? n.text : n.review, a = n.type === "agentMessage" && n.phase === "final_answer" ?
|
|
2449
|
+
let i = n.type === "agentMessage" ? n.text : n.review, a = n.type === "agentMessage" && n.phase === "final_answer" ? $n(i) : null, o = n.type === "agentMessage" ? gr(e, t.id, n, !0) : null, s = [...!o && (a?.visibleText || !a && i) ? [{
|
|
2122
2450
|
type: "text",
|
|
2123
2451
|
text: a?.visibleText ?? i,
|
|
2124
2452
|
itemId: n.id,
|
|
@@ -2127,7 +2455,7 @@ function Bn(e, t, n) {
|
|
|
2127
2455
|
return s.length > 0 ? {
|
|
2128
2456
|
id: `assistant-${n.id}`,
|
|
2129
2457
|
role: "assistant",
|
|
2130
|
-
status:
|
|
2458
|
+
status: Ar(t.status),
|
|
2131
2459
|
turnId: t.id,
|
|
2132
2460
|
parts: s,
|
|
2133
2461
|
createdAt: r,
|
|
@@ -2151,7 +2479,7 @@ function Bn(e, t, n) {
|
|
|
2151
2479
|
return i.length > 0 ? {
|
|
2152
2480
|
id: `assistant-${n.id}`,
|
|
2153
2481
|
role: "assistant",
|
|
2154
|
-
status:
|
|
2482
|
+
status: Ar(t.status),
|
|
2155
2483
|
turnId: t.id,
|
|
2156
2484
|
parts: i,
|
|
2157
2485
|
createdAt: r,
|
|
@@ -2162,14 +2490,14 @@ function Bn(e, t, n) {
|
|
|
2162
2490
|
}
|
|
2163
2491
|
} : null;
|
|
2164
2492
|
}
|
|
2165
|
-
let i = [], a =
|
|
2493
|
+
let i = [], a = L(n);
|
|
2166
2494
|
a && i.push(a);
|
|
2167
|
-
let o =
|
|
2495
|
+
let o = _r(n);
|
|
2168
2496
|
o && i.push(o);
|
|
2169
2497
|
let s = i.length > 0 ? {
|
|
2170
2498
|
id: `assistant-${n.id}`,
|
|
2171
2499
|
role: "assistant",
|
|
2172
|
-
status:
|
|
2500
|
+
status: Ar(t.status),
|
|
2173
2501
|
turnId: t.id,
|
|
2174
2502
|
parts: i,
|
|
2175
2503
|
createdAt: r,
|
|
@@ -2179,9 +2507,9 @@ function Bn(e, t, n) {
|
|
|
2179
2507
|
itemId: n.id
|
|
2180
2508
|
}
|
|
2181
2509
|
} : null;
|
|
2182
|
-
return !s || t.status === "inProgress" ? s :
|
|
2510
|
+
return !s || t.status === "inProgress" ? s : ar([s], t.id, t.status)[0] ?? null;
|
|
2183
2511
|
}
|
|
2184
|
-
function
|
|
2512
|
+
function gr(e, t, n, r = !1) {
|
|
2185
2513
|
if (n.delivery !== "async") return null;
|
|
2186
2514
|
let i = n.questions ?? [], a = i.length > 0 ? i.map((e, t) => ({
|
|
2187
2515
|
id: JSON.stringify([
|
|
@@ -2223,9 +2551,9 @@ function Vn(e, t, n, r = !1) {
|
|
|
2223
2551
|
...r ? { historical: !0 } : {}
|
|
2224
2552
|
};
|
|
2225
2553
|
}
|
|
2226
|
-
function
|
|
2227
|
-
if (e.type !== "imageGeneration" ||
|
|
2228
|
-
let t = typeof e.savedPath == "string" && v(e.savedPath) ? e.savedPath : null, n = t ?
|
|
2554
|
+
function _r(e) {
|
|
2555
|
+
if (e.type !== "imageGeneration" || L(e)?.status !== "completed") return null;
|
|
2556
|
+
let t = typeof e.savedPath == "string" && v(e.savedPath) ? e.savedPath : null, n = t ? Tr(t) : void 0, r = n && dr.has(n) ? t : null, i = Er(typeof e.result == "string" ? e.result.trim() : ""), a = i?.url ?? (r ? re(r).href : void 0);
|
|
2229
2557
|
if (!a) return null;
|
|
2230
2558
|
let o = typeof e.revisedPrompt == "string" ? e.revisedPrompt.trim() : "";
|
|
2231
2559
|
return {
|
|
@@ -2240,21 +2568,21 @@ function Hn(e) {
|
|
|
2240
2568
|
}
|
|
2241
2569
|
};
|
|
2242
2570
|
}
|
|
2243
|
-
function
|
|
2244
|
-
let t = Array.isArray(e.content) ? e.content : [], n = t.some((e) =>
|
|
2571
|
+
function vr(e) {
|
|
2572
|
+
let t = Array.isArray(e.content) ? e.content : [], n = t.some((e) => q(e) && e.type === "text" && typeof e.text == "string" && e.text.length > 0), r = [], i = [], a = /* @__PURE__ */ new Set(), o = () => {
|
|
2245
2573
|
i.length > 0 && r.push({
|
|
2246
2574
|
type: "text",
|
|
2247
2575
|
text: i.join("\n")
|
|
2248
2576
|
}), i = [];
|
|
2249
2577
|
};
|
|
2250
2578
|
for (let e of t) {
|
|
2251
|
-
if (
|
|
2579
|
+
if (q(e) && e.type === "skill" && typeof e.name == "string") {
|
|
2252
2580
|
if (n) continue;
|
|
2253
2581
|
let t = e.name.toLowerCase();
|
|
2254
2582
|
if (a.has(t)) continue;
|
|
2255
2583
|
a.add(t);
|
|
2256
2584
|
}
|
|
2257
|
-
let t =
|
|
2585
|
+
let t = yr(e), s = kt(t);
|
|
2258
2586
|
if (s) {
|
|
2259
2587
|
o(), r.push({
|
|
2260
2588
|
type: "attachment",
|
|
@@ -2269,7 +2597,7 @@ function Un(e) {
|
|
|
2269
2597
|
i.push(t);
|
|
2270
2598
|
continue;
|
|
2271
2599
|
}
|
|
2272
|
-
let c =
|
|
2600
|
+
let c = Cr(e);
|
|
2273
2601
|
c && (o(), r.push({
|
|
2274
2602
|
type: "attachment",
|
|
2275
2603
|
attachment: c
|
|
@@ -2277,26 +2605,26 @@ function Un(e) {
|
|
|
2277
2605
|
}
|
|
2278
2606
|
return o(), r;
|
|
2279
2607
|
}
|
|
2280
|
-
function
|
|
2281
|
-
return !
|
|
2608
|
+
function yr(e) {
|
|
2609
|
+
return !q(e) || typeof e.type != "string" ? "" : e.type === "text" && typeof e.text == "string" ? Sr(e.text)?.displayText ?? e.text : e.type === "skill" && typeof e.name == "string" ? `$${e.name}` : "";
|
|
2282
2610
|
}
|
|
2283
|
-
function
|
|
2611
|
+
function br(e) {
|
|
2284
2612
|
let t = /* @__PURE__ */ new Set();
|
|
2285
|
-
for (let n of Array.isArray(e.content) ? e.content : []) if (!(!
|
|
2613
|
+
for (let n of Array.isArray(e.content) ? e.content : []) if (!(!q(n) || n.type !== "text" || typeof n.text != "string")) for (let e of Sr(n.text)?.requestIds ?? []) t.add(e);
|
|
2286
2614
|
return [...t];
|
|
2287
2615
|
}
|
|
2288
|
-
function
|
|
2616
|
+
function xr(e) {
|
|
2289
2617
|
let t = {};
|
|
2290
|
-
for (let n of Array.isArray(e.content) ? e.content : []) !
|
|
2618
|
+
for (let n of Array.isArray(e.content) ? e.content : []) !q(n) || n.type !== "text" || typeof n.text != "string" || Object.assign(t, Sr(n.text)?.answers);
|
|
2291
2619
|
return t;
|
|
2292
2620
|
}
|
|
2293
|
-
function
|
|
2621
|
+
function Sr(e) {
|
|
2294
2622
|
let t = e.match(/^<send_user_message_question_reply>\s*([\s\S]*?)\s*<\/send_user_message_question_reply>$/);
|
|
2295
2623
|
if (!t?.[1]) return null;
|
|
2296
2624
|
try {
|
|
2297
2625
|
let e = JSON.parse(t[1]);
|
|
2298
2626
|
if (!Array.isArray(e)) return null;
|
|
2299
|
-
let n = e.filter((e) =>
|
|
2627
|
+
let n = e.filter((e) => q(e) && typeof e.questionItemId == "string" && typeof e.question == "string" && typeof e.answer == "string");
|
|
2300
2628
|
if (n.length === 0) return null;
|
|
2301
2629
|
let r = n.flatMap((e) => {
|
|
2302
2630
|
try {
|
|
@@ -2314,10 +2642,10 @@ function qn(e) {
|
|
|
2314
2642
|
return null;
|
|
2315
2643
|
}
|
|
2316
2644
|
}
|
|
2317
|
-
function
|
|
2318
|
-
if (!
|
|
2645
|
+
function Cr(e) {
|
|
2646
|
+
if (!q(e) || typeof e.type != "string") return null;
|
|
2319
2647
|
if (e.type === "mention" && typeof e.path == "string") {
|
|
2320
|
-
let t = typeof e.name == "string" && e.name.trim() ? e.name.trim() :
|
|
2648
|
+
let t = typeof e.name == "string" && e.name.trim() ? e.name.trim() : wr(e.path, "File"), n = Tr(e.path);
|
|
2321
2649
|
return {
|
|
2322
2650
|
kind: "file",
|
|
2323
2651
|
name: t,
|
|
@@ -2326,26 +2654,26 @@ function Jn(e) {
|
|
|
2326
2654
|
};
|
|
2327
2655
|
}
|
|
2328
2656
|
if (e.type === "image" && typeof e.url == "string") {
|
|
2329
|
-
let t =
|
|
2657
|
+
let t = Tr(e.url);
|
|
2330
2658
|
return {
|
|
2331
2659
|
kind: "image",
|
|
2332
|
-
name:
|
|
2660
|
+
name: wr(e.url, "Image"),
|
|
2333
2661
|
url: e.url,
|
|
2334
2662
|
...t ? { mimeType: t } : {}
|
|
2335
2663
|
};
|
|
2336
2664
|
}
|
|
2337
2665
|
if (e.type === "localImage" && typeof e.path == "string") {
|
|
2338
|
-
let t =
|
|
2666
|
+
let t = Tr(e.path);
|
|
2339
2667
|
return {
|
|
2340
2668
|
kind: "image",
|
|
2341
|
-
name:
|
|
2669
|
+
name: wr(e.path, "Image"),
|
|
2342
2670
|
path: e.path,
|
|
2343
2671
|
...t ? { mimeType: t } : {}
|
|
2344
2672
|
};
|
|
2345
2673
|
}
|
|
2346
2674
|
return null;
|
|
2347
2675
|
}
|
|
2348
|
-
function
|
|
2676
|
+
function wr(e, t) {
|
|
2349
2677
|
try {
|
|
2350
2678
|
let n = /^[a-z][a-z\d+.-]*:/i.test(e) ? new URL(e).pathname : e;
|
|
2351
2679
|
return g(decodeURIComponent(n)).trim() || t;
|
|
@@ -2353,7 +2681,7 @@ function Yn(e, t) {
|
|
|
2353
2681
|
return g(e).trim() || t;
|
|
2354
2682
|
}
|
|
2355
2683
|
}
|
|
2356
|
-
function
|
|
2684
|
+
function Tr(e) {
|
|
2357
2685
|
let t = /^data:([^;,]+)/i.exec(e)?.[1]?.toLowerCase();
|
|
2358
2686
|
if (t) return t;
|
|
2359
2687
|
let n = "";
|
|
@@ -2375,23 +2703,23 @@ function Xn(e) {
|
|
|
2375
2703
|
webp: "image/webp"
|
|
2376
2704
|
}[n];
|
|
2377
2705
|
}
|
|
2378
|
-
function
|
|
2706
|
+
function Er(e) {
|
|
2379
2707
|
if (!e) return null;
|
|
2380
|
-
let t = (/^data:image\/[a-z0-9.+-]+;base64,([a-z0-9+/=\s]+)$/i.exec(e)?.[1] ?? e).replace(/\s+/g, ""), n = Math.ceil(
|
|
2708
|
+
let t = (/^data:image\/[a-z0-9.+-]+;base64,([a-z0-9+/=\s]+)$/i.exec(e)?.[1] ?? e).replace(/\s+/g, ""), n = Math.ceil(ur / 3) * 4 + 4;
|
|
2381
2709
|
if (!t || t.length > n || t.length % 4 != 0 || !/^[a-z0-9+/]+={0,2}$/i.test(t)) return null;
|
|
2382
2710
|
let r = Buffer.from(t, "base64");
|
|
2383
|
-
if (r.byteLength === 0 || r.byteLength >
|
|
2384
|
-
let i =
|
|
2711
|
+
if (r.byteLength === 0 || r.byteLength > ur) return null;
|
|
2712
|
+
let i = Or(r);
|
|
2385
2713
|
return i ? {
|
|
2386
2714
|
url: `data:${i};base64,${t}`,
|
|
2387
2715
|
mimeType: i
|
|
2388
2716
|
} : null;
|
|
2389
2717
|
}
|
|
2390
|
-
function
|
|
2718
|
+
function Dr(e) {
|
|
2391
2719
|
return !!(e && e.length <= 16 * 1024 * 1024 && /^data:image\/(?:avif|bmp|gif|heic|heif|jpe?g|png|webp);base64,[a-z\d+/]+={0,2}$/i.test(e));
|
|
2392
2720
|
}
|
|
2393
|
-
function
|
|
2394
|
-
if (
|
|
2721
|
+
function Or(e) {
|
|
2722
|
+
if (kr(e, [
|
|
2395
2723
|
137,
|
|
2396
2724
|
80,
|
|
2397
2725
|
78,
|
|
@@ -2401,7 +2729,7 @@ function $n(e) {
|
|
|
2401
2729
|
26,
|
|
2402
2730
|
10
|
|
2403
2731
|
])) return "image/png";
|
|
2404
|
-
if (
|
|
2732
|
+
if (kr(e, [
|
|
2405
2733
|
255,
|
|
2406
2734
|
216,
|
|
2407
2735
|
255
|
|
@@ -2409,50 +2737,50 @@ function $n(e) {
|
|
|
2409
2737
|
let t = Buffer.from(e.subarray(0, 12)).toString("ascii");
|
|
2410
2738
|
return t.startsWith("GIF87a") || t.startsWith("GIF89a") ? "image/gif" : t.startsWith("RIFF") && t.slice(8, 12) === "WEBP" ? "image/webp" : e.byteLength >= 12 && t.slice(4, 12) === "ftypavif" ? "image/avif" : null;
|
|
2411
2739
|
}
|
|
2412
|
-
function
|
|
2740
|
+
function kr(e, t) {
|
|
2413
2741
|
return t.every((t, n) => e[n] === t);
|
|
2414
2742
|
}
|
|
2415
|
-
function
|
|
2743
|
+
function Ar(e) {
|
|
2416
2744
|
return e === "inProgress" ? "streaming" : e === "failed" ? "error" : "complete";
|
|
2417
2745
|
}
|
|
2418
|
-
function
|
|
2746
|
+
function jr(e) {
|
|
2419
2747
|
return typeof e != "number" || !Number.isFinite(e) ? (/* @__PURE__ */ new Date(0)).toISOString() : (/* @__PURE__ */ new Date(e * 1e3)).toISOString();
|
|
2420
2748
|
}
|
|
2421
|
-
function
|
|
2749
|
+
function q(e) {
|
|
2422
2750
|
return !!(e && typeof e == "object" && !Array.isArray(e));
|
|
2423
2751
|
}
|
|
2424
2752
|
//#endregion
|
|
2425
2753
|
//#region src/node/codex-raw-response-item-adapter.ts
|
|
2426
|
-
function
|
|
2427
|
-
if (!
|
|
2754
|
+
function Mr(e) {
|
|
2755
|
+
if (!Vr(e) || typeof e.type != "string") return null;
|
|
2428
2756
|
if (e.type === "local_shell_call") {
|
|
2429
|
-
let t =
|
|
2757
|
+
let t = L(Nr(e));
|
|
2430
2758
|
return {
|
|
2431
|
-
type:
|
|
2759
|
+
type: Lr(e.status) ? "item.completed" : "item.started",
|
|
2432
2760
|
payload: { toolPart: t }
|
|
2433
2761
|
};
|
|
2434
2762
|
}
|
|
2435
2763
|
return e.type === "function_call" ? {
|
|
2436
2764
|
type: "item.started",
|
|
2437
|
-
payload: { toolPart:
|
|
2438
|
-
} : e.type === "function_call_output" ?
|
|
2765
|
+
payload: { toolPart: L(Pr(e)) }
|
|
2766
|
+
} : e.type === "function_call_output" ? Fr(e.call_id, e.output) : e.type === "custom_tool_call" ? {
|
|
2439
2767
|
type: "item.started",
|
|
2440
|
-
payload: { toolPart:
|
|
2768
|
+
payload: { toolPart: L({
|
|
2441
2769
|
type: "dynamicToolCall",
|
|
2442
|
-
id:
|
|
2770
|
+
id: Y(e.call_id) ?? J(e),
|
|
2443
2771
|
namespace: null,
|
|
2444
|
-
tool:
|
|
2772
|
+
tool: Y(e.name) ?? "custom_tool",
|
|
2445
2773
|
status: e.status,
|
|
2446
|
-
arguments:
|
|
2774
|
+
arguments: Y(e.input) ?? "",
|
|
2447
2775
|
contentItems: null,
|
|
2448
2776
|
success: null,
|
|
2449
2777
|
durationMs: null
|
|
2450
2778
|
}) }
|
|
2451
|
-
} : e.type === "custom_tool_call_output" ?
|
|
2779
|
+
} : e.type === "custom_tool_call_output" ? Fr(e.call_id, e.output, Y(e.name) ?? void 0) : e.type === "tool_search_call" ? {
|
|
2452
2780
|
type: "item.started",
|
|
2453
|
-
payload: { toolPart:
|
|
2781
|
+
payload: { toolPart: L({
|
|
2454
2782
|
type: "dynamicToolCall",
|
|
2455
|
-
id:
|
|
2783
|
+
id: Y(e.call_id) ?? J(e),
|
|
2456
2784
|
namespace: "codex",
|
|
2457
2785
|
tool: "tool_search",
|
|
2458
2786
|
status: e.status,
|
|
@@ -2464,20 +2792,20 @@ function rr(e) {
|
|
|
2464
2792
|
}) }
|
|
2465
2793
|
} : e.type === "tool_search_output" ? {
|
|
2466
2794
|
type: "item.updated",
|
|
2467
|
-
payload:
|
|
2795
|
+
payload: xn(Y(e.call_id) ?? J(e), e.tools, "tool_search", e.status)
|
|
2468
2796
|
} : e.type === "web_search_call" ? {
|
|
2469
2797
|
type: "item.completed",
|
|
2470
|
-
payload: { toolPart:
|
|
2798
|
+
payload: { toolPart: L({
|
|
2471
2799
|
type: "webSearch",
|
|
2472
|
-
id:
|
|
2473
|
-
query:
|
|
2800
|
+
id: J(e),
|
|
2801
|
+
query: zr(e.action),
|
|
2474
2802
|
action: e.action
|
|
2475
2803
|
}) }
|
|
2476
2804
|
} : e.type === "image_generation_call" ? {
|
|
2477
2805
|
type: "item.completed",
|
|
2478
|
-
payload: { toolPart:
|
|
2806
|
+
payload: { toolPart: L({
|
|
2479
2807
|
type: "dynamicToolCall",
|
|
2480
|
-
id:
|
|
2808
|
+
id: Y(e.id) ?? J(e),
|
|
2481
2809
|
namespace: null,
|
|
2482
2810
|
tool: "image_generation",
|
|
2483
2811
|
status: e.status,
|
|
@@ -2488,29 +2816,29 @@ function rr(e) {
|
|
|
2488
2816
|
}) }
|
|
2489
2817
|
} : null;
|
|
2490
2818
|
}
|
|
2491
|
-
function
|
|
2492
|
-
let t =
|
|
2819
|
+
function Nr(e) {
|
|
2820
|
+
let t = Vr(e.action) ? e.action : {}, n = Array.isArray(t.command) ? Br(t.command) : Y(t.command) ?? "local shell";
|
|
2493
2821
|
return {
|
|
2494
2822
|
type: "commandExecution",
|
|
2495
|
-
id:
|
|
2823
|
+
id: Y(e.call_id) ?? J(e),
|
|
2496
2824
|
command: n,
|
|
2497
|
-
cwd:
|
|
2825
|
+
cwd: Y(t.working_directory) ?? "",
|
|
2498
2826
|
processId: null,
|
|
2499
2827
|
source: "agent",
|
|
2500
|
-
status:
|
|
2828
|
+
status: Ir(e.status),
|
|
2501
2829
|
commandActions: [],
|
|
2502
2830
|
aggregatedOutput: null,
|
|
2503
2831
|
exitCode: null,
|
|
2504
2832
|
durationMs: null
|
|
2505
2833
|
};
|
|
2506
2834
|
}
|
|
2507
|
-
function
|
|
2508
|
-
let t =
|
|
2509
|
-
return t === "shell_command" &&
|
|
2835
|
+
function Pr(e) {
|
|
2836
|
+
let t = Y(e.name) ?? "function_call", n = Rr(e.arguments), r = Y(e.call_id) ?? J(e);
|
|
2837
|
+
return t === "shell_command" && Vr(n) ? {
|
|
2510
2838
|
type: "commandExecution",
|
|
2511
2839
|
id: r,
|
|
2512
|
-
command:
|
|
2513
|
-
cwd:
|
|
2840
|
+
command: Y(n.command) ?? t,
|
|
2841
|
+
cwd: Y(n.workdir) ?? Y(n.cwd) ?? "",
|
|
2514
2842
|
processId: null,
|
|
2515
2843
|
source: "agent",
|
|
2516
2844
|
status: "inProgress",
|
|
@@ -2521,7 +2849,7 @@ function ar(e) {
|
|
|
2521
2849
|
} : {
|
|
2522
2850
|
type: "dynamicToolCall",
|
|
2523
2851
|
id: r,
|
|
2524
|
-
namespace:
|
|
2852
|
+
namespace: Y(e.namespace),
|
|
2525
2853
|
tool: t,
|
|
2526
2854
|
status: "inProgress",
|
|
2527
2855
|
arguments: n,
|
|
@@ -2530,19 +2858,19 @@ function ar(e) {
|
|
|
2530
2858
|
durationMs: null
|
|
2531
2859
|
};
|
|
2532
2860
|
}
|
|
2533
|
-
function
|
|
2861
|
+
function Fr(e, t, n) {
|
|
2534
2862
|
return {
|
|
2535
2863
|
type: "item.updated",
|
|
2536
|
-
payload:
|
|
2864
|
+
payload: xn(Y(e) ?? "raw-response-output", t, n)
|
|
2537
2865
|
};
|
|
2538
2866
|
}
|
|
2539
|
-
function
|
|
2867
|
+
function Ir(e) {
|
|
2540
2868
|
return e === "completed" ? "completed" : e === "incomplete" || e === "failed" || e === "error" ? "failed" : "inProgress";
|
|
2541
2869
|
}
|
|
2542
|
-
function
|
|
2870
|
+
function Lr(e) {
|
|
2543
2871
|
return e === "completed" || e === "failed" || e === "error" || e === "incomplete";
|
|
2544
2872
|
}
|
|
2545
|
-
function
|
|
2873
|
+
function Rr(e) {
|
|
2546
2874
|
if (typeof e != "string") return e;
|
|
2547
2875
|
try {
|
|
2548
2876
|
return JSON.parse(e);
|
|
@@ -2550,71 +2878,71 @@ function lr(e) {
|
|
|
2550
2878
|
return e;
|
|
2551
2879
|
}
|
|
2552
2880
|
}
|
|
2553
|
-
function
|
|
2554
|
-
return
|
|
2881
|
+
function zr(e) {
|
|
2882
|
+
return Vr(e) ? Y(e.query) ?? Y(e.searchTerm) ?? "web search" : "web search";
|
|
2555
2883
|
}
|
|
2556
|
-
function
|
|
2884
|
+
function Br(e) {
|
|
2557
2885
|
return e.map((e) => {
|
|
2558
2886
|
let t = String(e);
|
|
2559
2887
|
return /\s/.test(t) ? JSON.stringify(t) : t;
|
|
2560
2888
|
}).join(" ");
|
|
2561
2889
|
}
|
|
2562
|
-
function
|
|
2563
|
-
return (
|
|
2890
|
+
function J(e) {
|
|
2891
|
+
return (Y(e.call_id) ?? Y(e.id)) || `raw-${e.type}`;
|
|
2564
2892
|
}
|
|
2565
|
-
function
|
|
2893
|
+
function Y(e) {
|
|
2566
2894
|
return typeof e == "string" && e.length > 0 ? e : null;
|
|
2567
2895
|
}
|
|
2568
|
-
function
|
|
2896
|
+
function Vr(e) {
|
|
2569
2897
|
return !!(e && typeof e == "object" && !Array.isArray(e));
|
|
2570
2898
|
}
|
|
2571
2899
|
//#endregion
|
|
2572
2900
|
//#region src/node/codex-surface-events.ts
|
|
2573
|
-
function
|
|
2901
|
+
function Hr(e, t) {
|
|
2574
2902
|
return `${e}\u0000${t}`;
|
|
2575
2903
|
}
|
|
2576
|
-
function
|
|
2904
|
+
function X(e) {
|
|
2577
2905
|
return typeof e == "number" && Number.isFinite(e) ? (/* @__PURE__ */ new Date(e * 1e3)).toISOString() : (/* @__PURE__ */ new Date()).toISOString();
|
|
2578
2906
|
}
|
|
2579
|
-
function
|
|
2907
|
+
function Ur(e) {
|
|
2580
2908
|
return typeof e == "number" && Number.isFinite(e) ? (/* @__PURE__ */ new Date(e * 1e3)).toISOString() : null;
|
|
2581
2909
|
}
|
|
2582
|
-
function
|
|
2910
|
+
function Wr(e) {
|
|
2583
2911
|
return e ? {
|
|
2584
2912
|
message: e.message,
|
|
2585
2913
|
additionalDetails: e.additionalDetails,
|
|
2586
2914
|
codexErrorInfo: e.codexErrorInfo
|
|
2587
2915
|
} : null;
|
|
2588
2916
|
}
|
|
2589
|
-
function
|
|
2917
|
+
function Z(e, t = !1) {
|
|
2590
2918
|
return {
|
|
2591
2919
|
id: e.id,
|
|
2592
2920
|
status: e.status,
|
|
2593
|
-
error:
|
|
2921
|
+
error: Wr(e.error),
|
|
2594
2922
|
willRetry: t,
|
|
2595
|
-
startedAt:
|
|
2596
|
-
completedAt:
|
|
2923
|
+
startedAt: Ur(e.startedAt),
|
|
2924
|
+
completedAt: Ur(e.completedAt),
|
|
2597
2925
|
durationMs: e.durationMs ?? null
|
|
2598
2926
|
};
|
|
2599
2927
|
}
|
|
2600
|
-
function
|
|
2928
|
+
function Q(e, t) {
|
|
2601
2929
|
let n = e.findIndex((e) => e.id === t.id);
|
|
2602
2930
|
if (n < 0) return [...e, t];
|
|
2603
2931
|
let r = [...e];
|
|
2604
2932
|
return r.splice(n, 1, t), r;
|
|
2605
2933
|
}
|
|
2606
|
-
function
|
|
2934
|
+
function Gr(e, t) {
|
|
2607
2935
|
return JSON.stringify(e) === JSON.stringify(t);
|
|
2608
2936
|
}
|
|
2609
|
-
function
|
|
2937
|
+
function Kr() {
|
|
2610
2938
|
return `user-${globalThis.crypto.randomUUID()}`;
|
|
2611
2939
|
}
|
|
2612
|
-
function
|
|
2940
|
+
function qr() {
|
|
2613
2941
|
return `queued-prompt-${globalThis.crypto.randomUUID()}`;
|
|
2614
2942
|
}
|
|
2615
2943
|
//#endregion
|
|
2616
2944
|
//#region src/node/codex-surface-subagents.ts
|
|
2617
|
-
function
|
|
2945
|
+
function Jr(e) {
|
|
2618
2946
|
let t = {};
|
|
2619
2947
|
for (let [n, r] of Object.entries(e.agentsStates)) r && (t[n] = {
|
|
2620
2948
|
status: r.status,
|
|
@@ -2634,7 +2962,7 @@ function yr(e) {
|
|
|
2634
2962
|
}
|
|
2635
2963
|
//#endregion
|
|
2636
2964
|
//#region src/node/codex-surface-items-controller.ts
|
|
2637
|
-
var
|
|
2965
|
+
var Yr = class {
|
|
2638
2966
|
host;
|
|
2639
2967
|
commandOutputForwardItemIds = /* @__PURE__ */ new Set();
|
|
2640
2968
|
fileActivityKeys = /* @__PURE__ */ new Set();
|
|
@@ -2652,13 +2980,13 @@ var br = class {
|
|
|
2652
2980
|
for (let e of this.reviewOutputByTurn.keys()) e.startsWith(t) && this.reviewOutputByTurn.delete(e);
|
|
2653
2981
|
}
|
|
2654
2982
|
isForwardingCommandOutput(e, t) {
|
|
2655
|
-
return this.commandOutputForwardItemIds.has(
|
|
2983
|
+
return this.commandOutputForwardItemIds.has(Hr(e, t));
|
|
2656
2984
|
}
|
|
2657
2985
|
applyAgentDelta(e) {
|
|
2658
2986
|
let t = this.host.requireRuntime(e.threadId);
|
|
2659
2987
|
this.host.markRuntimeTurnActive(t, e.turnId);
|
|
2660
2988
|
let n = t.messages.flatMap((e) => e.parts).find((t) => t.type === "text" && t.itemId === e.itemId)?.phase;
|
|
2661
|
-
this.host.patchRuntime(e.threadId, { messages:
|
|
2989
|
+
this.host.patchRuntime(e.threadId, { messages: Yn(t.messages, e.threadId, e.turnId, e.itemId, e.delta, n) });
|
|
2662
2990
|
let r = this.host.assistantMessageForTurn(e.threadId, e.turnId);
|
|
2663
2991
|
r && this.host.emitEvent("notification", {
|
|
2664
2992
|
type: "message.delta",
|
|
@@ -2676,7 +3004,7 @@ var br = class {
|
|
|
2676
3004
|
let t = this.host.requireRuntime(e.threadId);
|
|
2677
3005
|
this.host.markRuntimeTurnActive(t, e.turnId);
|
|
2678
3006
|
let n = `${t.planMarkdownByTurn.get(e.turnId) ?? ""}${e.delta}`;
|
|
2679
|
-
t.planMarkdownByTurn.set(e.turnId, n), this.host.patchRuntime(e.threadId, { messages:
|
|
3007
|
+
t.planMarkdownByTurn.set(e.turnId, n), this.host.patchRuntime(e.threadId, { messages: W(t.messages, e.threadId, e.turnId, lr(e.turnId, n, "running")) }), this.host.emitEvent("notification", {
|
|
2680
3008
|
type: "plan.delta",
|
|
2681
3009
|
conversationId: e.threadId,
|
|
2682
3010
|
turnId: e.turnId,
|
|
@@ -2690,7 +3018,7 @@ var br = class {
|
|
|
2690
3018
|
applyPlanUpdated(e) {
|
|
2691
3019
|
let t = this.host.requireRuntime(e.threadId);
|
|
2692
3020
|
this.host.markRuntimeTurnActive(t, e.turnId);
|
|
2693
|
-
let n =
|
|
3021
|
+
let n = cr(e.explanation, e.plan), r = (/* @__PURE__ */ new Date()).toISOString();
|
|
2694
3022
|
t.planMarkdownByTurn.set(e.turnId, n), this.host.patchRuntime(e.threadId, {
|
|
2695
3023
|
executionPlan: {
|
|
2696
3024
|
turnId: e.turnId,
|
|
@@ -2699,7 +3027,7 @@ var br = class {
|
|
|
2699
3027
|
markdown: n,
|
|
2700
3028
|
updatedAt: r
|
|
2701
3029
|
},
|
|
2702
|
-
messages:
|
|
3030
|
+
messages: W(t.messages, e.threadId, e.turnId, lr(e.turnId, n, "completed"))
|
|
2703
3031
|
}), this.host.emitEvent("notification", {
|
|
2704
3032
|
type: "plan.updated",
|
|
2705
3033
|
conversationId: e.threadId,
|
|
@@ -2715,13 +3043,13 @@ var br = class {
|
|
|
2715
3043
|
applyRawResponseItem(e) {
|
|
2716
3044
|
let t = this.host.requireRuntime(e.threadId);
|
|
2717
3045
|
this.host.markRuntimeTurnActive(t, e.turnId);
|
|
2718
|
-
let n =
|
|
3046
|
+
let n = Mr(e.item);
|
|
2719
3047
|
if (!n) return;
|
|
2720
3048
|
if (n.type === "item.updated") {
|
|
2721
3049
|
this.applyToolUpdate(e.threadId, e.turnId, n.payload);
|
|
2722
3050
|
return;
|
|
2723
3051
|
}
|
|
2724
|
-
this.host.patchRuntime(e.threadId, { messages:
|
|
3052
|
+
this.host.patchRuntime(e.threadId, { messages: W(t.messages, e.threadId, e.turnId, n.payload.toolPart) });
|
|
2725
3053
|
let r = this.host.messageContainingTool(e.threadId, e.turnId, n.payload.toolPart.id);
|
|
2726
3054
|
r && (this.host.emitEvent("notification", {
|
|
2727
3055
|
type: n.type === "item.completed" ? "tool.completed" : "tool.started",
|
|
@@ -2742,7 +3070,7 @@ var br = class {
|
|
|
2742
3070
|
startedAt: ("startedAtMs" in e ? e.startedAtMs : e.completedAtMs) / 1e3
|
|
2743
3071
|
};
|
|
2744
3072
|
if (e.item.type === "userMessage") {
|
|
2745
|
-
let t =
|
|
3073
|
+
let t = hr(e.threadId, i, e.item);
|
|
2746
3074
|
if (!t || n.messages.some((e) => e.id === t.id)) return;
|
|
2747
3075
|
let a = n.messages.some((t) => t.role === "assistant" && t.metadata?.turnId === e.turnId && t.parts.length > 0), o = !a && r ? n.messages.map((e) => e.role === "user" && e.kind !== "steer" && !e.turnId && JSON.stringify(e.parts) === JSON.stringify(t.parts)).lastIndexOf(!0) : -1;
|
|
2748
3076
|
if (o >= 0) {
|
|
@@ -2768,7 +3096,7 @@ var br = class {
|
|
|
2768
3096
|
...t,
|
|
2769
3097
|
kind: "steer"
|
|
2770
3098
|
} : t, c = [...n.messages, s];
|
|
2771
|
-
this.host.patchRuntime(e.threadId, { messages: a ?
|
|
3099
|
+
this.host.patchRuntime(e.threadId, { messages: a ? U(c, e.threadId, e.turnId, { forceSegment: !0 }) : c }), this.host.emitEvent("notification", {
|
|
2772
3100
|
type: "message.appended",
|
|
2773
3101
|
conversationId: e.threadId,
|
|
2774
3102
|
turnId: e.turnId,
|
|
@@ -2779,7 +3107,7 @@ var br = class {
|
|
|
2779
3107
|
if (e.item.type === "reasoning") {
|
|
2780
3108
|
if (e.item.summary.filter((e) => e.trim().length > 0).length === 0) return;
|
|
2781
3109
|
let t = this.host.assistantMessageForTurn(e.threadId, e.turnId), r = t ? JSON.stringify(t.parts) : null;
|
|
2782
|
-
this.host.patchRuntime(e.threadId, { messages:
|
|
3110
|
+
this.host.patchRuntime(e.threadId, { messages: Xn(n.messages, e.threadId, e.turnId, e.item.id, e.item.summary) });
|
|
2783
3111
|
let i = this.host.assistantMessageForTurn(e.threadId, e.turnId);
|
|
2784
3112
|
if (!i || JSON.stringify(i.parts) === r) return;
|
|
2785
3113
|
this.host.emitEvent("notification", {
|
|
@@ -2791,10 +3119,10 @@ var br = class {
|
|
|
2791
3119
|
return;
|
|
2792
3120
|
}
|
|
2793
3121
|
if (e.item.type === "agentMessage" && t && n.planMode && e.item.phase === "final_answer") {
|
|
2794
|
-
let t =
|
|
3122
|
+
let t = $n(e.item.text);
|
|
2795
3123
|
if (t) {
|
|
2796
|
-
let r = this.host.assistantMessageForTurn(e.threadId, e.turnId), i =
|
|
2797
|
-
t.visibleText && (i =
|
|
3124
|
+
let r = this.host.assistantMessageForTurn(e.threadId, e.turnId), i = Qn(n.messages, e.threadId, e.turnId, e.item.id);
|
|
3125
|
+
t.visibleText && (i = Zn(i, e.threadId, e.turnId, e.item.id, t.visibleText, e.item.phase)), i = W(i, e.threadId, e.turnId, lr(e.turnId, t.markdown, "completed")), n.planMarkdownByTurn.set(e.turnId, t.markdown), this.host.patchRuntime(e.threadId, { messages: i });
|
|
2798
3126
|
let a = this.host.assistantMessageForTurn(e.threadId, e.turnId);
|
|
2799
3127
|
a && this.host.emitEvent("notification", {
|
|
2800
3128
|
type: r ? "message.updated" : "message.appended",
|
|
@@ -2816,11 +3144,11 @@ var br = class {
|
|
|
2816
3144
|
if (e.item.type === "agentMessage" || e.item.type === "exitedReviewMode") {
|
|
2817
3145
|
let t = e.item.type === "agentMessage" ? e.item.text : e.item.review, r = e.item.type === "agentMessage" ? e.item.phase ?? void 0 : void 0;
|
|
2818
3146
|
if (!t && e.item.type !== "agentMessage") return;
|
|
2819
|
-
let i =
|
|
3147
|
+
let i = Hr(e.threadId, e.turnId);
|
|
2820
3148
|
if (e.item.type === "agentMessage" && this.reviewOutputByTurn.get(i) === t) return;
|
|
2821
3149
|
e.item.type === "exitedReviewMode" && this.reviewOutputByTurn.set(i, t);
|
|
2822
|
-
let a = new Set(n.messages.map((e) => e.id)), o = this.host.assistantMessageForTurn(e.threadId, e.turnId), s = o ? JSON.stringify(o.parts) : null, c = new Set(o?.parts.flatMap((e) => e.type === "question" ? [e.request.id] : []) ?? []), l = n.messages.flatMap((e) => e.parts).find((t) => t.type === "text" && t.itemId === e.item.id)?.text ?? "", u = e.item.type === "agentMessage" ?
|
|
2823
|
-
if (u && (f =
|
|
3150
|
+
let a = new Set(n.messages.map((e) => e.id)), o = this.host.assistantMessageForTurn(e.threadId, e.turnId), s = o ? JSON.stringify(o.parts) : null, c = new Set(o?.parts.flatMap((e) => e.type === "question" ? [e.request.id] : []) ?? []), l = n.messages.flatMap((e) => e.parts).find((t) => t.type === "text" && t.itemId === e.item.id)?.text ?? "", u = e.item.type === "agentMessage" ? gr(e.threadId, e.turnId, e.item) : null, d = u ? "" : t, f = u ? Qn(n.messages, e.threadId, e.turnId, e.item.id) : Zn(n.messages, e.threadId, e.turnId, e.item.id, t, r);
|
|
3151
|
+
if (u && (f = tr(f, e.threadId, e.turnId, u)), this.host.patchRuntime(e.threadId, { messages: f }), !d && !u) return;
|
|
2824
3152
|
let p = this.host.assistantMessageForTurn(e.threadId, e.turnId);
|
|
2825
3153
|
if (p && !a.has(p.id)) this.host.emitEvent("notification", {
|
|
2826
3154
|
type: "message.appended",
|
|
@@ -2864,7 +3192,7 @@ var br = class {
|
|
|
2864
3192
|
if (e.item.type === "plan") {
|
|
2865
3193
|
if (!t) return;
|
|
2866
3194
|
let r = e.item.text.trim() || n.planMarkdownByTurn.get(e.turnId) || "";
|
|
2867
|
-
n.planMarkdownByTurn.set(e.turnId, r), this.host.patchRuntime(e.threadId, { messages:
|
|
3195
|
+
n.planMarkdownByTurn.set(e.turnId, r), this.host.patchRuntime(e.threadId, { messages: W(n.messages, e.threadId, e.turnId, lr(e.turnId, r, "completed")) }), this.host.emitEvent("notification", {
|
|
2868
3196
|
type: "plan.completed",
|
|
2869
3197
|
conversationId: e.threadId,
|
|
2870
3198
|
turnId: e.turnId,
|
|
@@ -2876,7 +3204,7 @@ var br = class {
|
|
|
2876
3204
|
return;
|
|
2877
3205
|
}
|
|
2878
3206
|
if (e.item.type === "contextCompaction") {
|
|
2879
|
-
if (this.host.patchRuntime(e.threadId, { messages:
|
|
3207
|
+
if (this.host.patchRuntime(e.threadId, { messages: ir(n.messages, e.threadId, e.turnId, t ? "complete" : "streaming") }), t) {
|
|
2880
3208
|
let t = this.host.requireRuntime(e.threadId).messages.find((t) => t.kind === "compaction" && t.metadata?.turnId === e.turnId);
|
|
2881
3209
|
t && this.host.emitEvent("notification", {
|
|
2882
3210
|
type: "context.compactionCompleted",
|
|
@@ -2902,7 +3230,7 @@ var br = class {
|
|
|
2902
3230
|
turnId: e.turnId,
|
|
2903
3231
|
payload: {
|
|
2904
3232
|
lifecycle: t ? "completed" : "started",
|
|
2905
|
-
toolCall:
|
|
3233
|
+
toolCall: Jr(e.item)
|
|
2906
3234
|
}
|
|
2907
3235
|
});
|
|
2908
3236
|
return;
|
|
@@ -2924,13 +3252,13 @@ var br = class {
|
|
|
2924
3252
|
});
|
|
2925
3253
|
return;
|
|
2926
3254
|
}
|
|
2927
|
-
let a = this.shouldForwardCommandOutput(e.threadId, t, e.item), o =
|
|
3255
|
+
let a = this.shouldForwardCommandOutput(e.threadId, t, e.item), o = L(e.item, {
|
|
2928
3256
|
includeCommandOutput: a,
|
|
2929
3257
|
cwd: n.cwd
|
|
2930
|
-
}), s =
|
|
3258
|
+
}), s = _r(e.item);
|
|
2931
3259
|
if (!o && !s) return;
|
|
2932
|
-
let c = s ? !n.messages.some((e) => e.parts.some((e) => e.type === "media" &&
|
|
2933
|
-
s && (l =
|
|
3260
|
+
let c = s ? !n.messages.some((e) => e.parts.some((e) => e.type === "media" && nr(e, s))) : !1, l = o ? W(n.messages, e.threadId, e.turnId, o) : [...n.messages];
|
|
3261
|
+
s && (l = er(l, e.threadId, e.turnId, s)), this.host.patchRuntime(e.threadId, { messages: l });
|
|
2934
3262
|
let u = o ? this.host.messageContainingTool(e.threadId, e.turnId, o.id) : this.host.assistantMessageForTurn(e.threadId, e.turnId);
|
|
2935
3263
|
u && o && this.host.emitEvent("notification", {
|
|
2936
3264
|
type: t ? "tool.completed" : "tool.started",
|
|
@@ -2950,25 +3278,25 @@ var br = class {
|
|
|
2950
3278
|
shouldForwardCommandOutput(e, t, n) {
|
|
2951
3279
|
let r = "id" in n && typeof n.id == "string" ? n.id : null;
|
|
2952
3280
|
if (!r) return !1;
|
|
2953
|
-
let i =
|
|
3281
|
+
let i = Hr(e, r);
|
|
2954
3282
|
if (!t) {
|
|
2955
|
-
let e =
|
|
3283
|
+
let e = _n(n);
|
|
2956
3284
|
return e ? this.commandOutputForwardItemIds.add(i) : this.commandOutputForwardItemIds.delete(i), e;
|
|
2957
3285
|
}
|
|
2958
|
-
let a = this.commandOutputForwardItemIds.has(i) ||
|
|
3286
|
+
let a = this.commandOutputForwardItemIds.has(i) || _n(n);
|
|
2959
3287
|
return this.commandOutputForwardItemIds.delete(i), a;
|
|
2960
3288
|
}
|
|
2961
3289
|
applyToolUpdate(e, t, n) {
|
|
2962
3290
|
let r = this.host.requireRuntime(e);
|
|
2963
3291
|
this.host.markRuntimeTurnActive(r, t);
|
|
2964
|
-
let i = r.cwd &&
|
|
3292
|
+
let i = r.cwd && Xr(n) ? {
|
|
2965
3293
|
...n,
|
|
2966
3294
|
metadata: {
|
|
2967
3295
|
...n.metadata,
|
|
2968
3296
|
cwd: r.cwd
|
|
2969
3297
|
}
|
|
2970
3298
|
} : n;
|
|
2971
|
-
this.host.patchRuntime(e, { messages:
|
|
3299
|
+
this.host.patchRuntime(e, { messages: rr(r.messages, e, t, i) });
|
|
2972
3300
|
let a = this.host.messageContainingTool(e, t, n.itemId);
|
|
2973
3301
|
a && this.host.emitEvent("notification", {
|
|
2974
3302
|
type: "tool.updated",
|
|
@@ -2983,7 +3311,7 @@ var br = class {
|
|
|
2983
3311
|
a && o && this.emitFileActivities(e, t, a.id, o.id, o, r.cwd);
|
|
2984
3312
|
}
|
|
2985
3313
|
emitFileActivities(e, t, n, r, i, a) {
|
|
2986
|
-
for (let o of
|
|
3314
|
+
for (let o of gn(i, a)) {
|
|
2987
3315
|
let i = `${e}\u0000${r}\u0000${o.action}\u0000${o.path}\u0000${o.status}`;
|
|
2988
3316
|
this.fileActivityKeys.has(i) || (this.fileActivityKeys.add(i), this.host.emitEvent("notification", {
|
|
2989
3317
|
type: "file.activity",
|
|
@@ -3004,7 +3332,7 @@ var br = class {
|
|
|
3004
3332
|
t.turnIds.includes(e.turn.id) || t.turnIds.push(e.turn.id);
|
|
3005
3333
|
let n = t.activeTurnId !== e.turn.id && t.turnStartPending;
|
|
3006
3334
|
t.activeTurnId === e.turn.id && (t.activeTurnId = null);
|
|
3007
|
-
let r = n || t.activeTurnId !== null, i = e.turn.status === "failed" ? "error" : "complete", a =
|
|
3335
|
+
let r = n || t.activeTurnId !== null, i = e.turn.status === "failed" ? "error" : "complete", a = ar(t.messages, e.turn.id, e.turn.status).map((t) => t.metadata?.turnId === e.turn.id ? {
|
|
3008
3336
|
...t,
|
|
3009
3337
|
status: i
|
|
3010
3338
|
} : t).filter((t) => !(t.role === "assistant" && t.metadata?.turnId === e.turn.id && t.kind === void 0 && t.parts.length === 0));
|
|
@@ -3016,7 +3344,7 @@ var br = class {
|
|
|
3016
3344
|
},
|
|
3017
3345
|
turnStartPending: n,
|
|
3018
3346
|
messages: a,
|
|
3019
|
-
turns:
|
|
3347
|
+
turns: Q(t.turns, Z(e.turn))
|
|
3020
3348
|
}), this.host.patch({ conversations: this.host.getState().conversations.map((n) => n.id === e.threadId ? {
|
|
3021
3349
|
...n,
|
|
3022
3350
|
status: r ? "active" : e.turn.status === "failed" ? "error" : "idle",
|
|
@@ -3030,26 +3358,26 @@ var br = class {
|
|
|
3030
3358
|
turnId: e.turn.id,
|
|
3031
3359
|
payload: {
|
|
3032
3360
|
status: e.turn.status,
|
|
3033
|
-
error:
|
|
3361
|
+
error: Wr(e.turn.error),
|
|
3034
3362
|
willRetry: !1,
|
|
3035
|
-
startedAt:
|
|
3036
|
-
completedAt:
|
|
3363
|
+
startedAt: Ur(e.turn.startedAt),
|
|
3364
|
+
completedAt: Ur(e.turn.completedAt),
|
|
3037
3365
|
durationMs: e.turn.durationMs ?? null
|
|
3038
3366
|
}
|
|
3039
3367
|
}), this.host.emitConversationActivity(e.threadId, "notification"), t.planMarkdownByTurn.delete(e.turn.id), this.host.sendNextQueuedPrompt(e.threadId);
|
|
3040
3368
|
}
|
|
3041
3369
|
};
|
|
3042
|
-
function
|
|
3370
|
+
function Xr(e) {
|
|
3043
3371
|
if (e.fallbackToolPart?.kind === "fileChange") return !0;
|
|
3044
3372
|
let t = e.input, n = e.metadata;
|
|
3045
|
-
return
|
|
3373
|
+
return Zr(t) && Array.isArray(t.changes) || Zr(n) && Array.isArray(n.changes);
|
|
3046
3374
|
}
|
|
3047
|
-
function
|
|
3375
|
+
function Zr(e) {
|
|
3048
3376
|
return typeof e == "object" && !!e;
|
|
3049
3377
|
}
|
|
3050
3378
|
//#endregion
|
|
3051
3379
|
//#region src/node/codex-surface-client-requests-controller.ts
|
|
3052
|
-
var
|
|
3380
|
+
var Qr = class {
|
|
3053
3381
|
host;
|
|
3054
3382
|
pending = /* @__PURE__ */ new Map();
|
|
3055
3383
|
constructor(e) {
|
|
@@ -3098,12 +3426,12 @@ var Cr = class {
|
|
|
3098
3426
|
"deny"
|
|
3099
3427
|
].includes(r)) throw Error(`Invalid tool confirmation decision '${String(r)}'`);
|
|
3100
3428
|
this.pending.delete(t.id);
|
|
3101
|
-
let i = this.host.requireRuntime(n.threadId), a =
|
|
3429
|
+
let i = this.host.requireRuntime(n.threadId), a = sr(i.answeredClientRequestIds, t.id);
|
|
3102
3430
|
if (n.kind === "ask_user") {
|
|
3103
3431
|
let e = t.payload?.answers ?? {};
|
|
3104
3432
|
n.responder.resolve({ answers: e }), this.host.patchRuntime(n.threadId, {
|
|
3105
3433
|
answeredClientRequestIds: a,
|
|
3106
|
-
messages:
|
|
3434
|
+
messages: rr(i.messages, n.threadId, n.turnId, {
|
|
3107
3435
|
itemId: n.itemId,
|
|
3108
3436
|
output: { answers: e }
|
|
3109
3437
|
})
|
|
@@ -3112,7 +3440,7 @@ var Cr = class {
|
|
|
3112
3440
|
let e = r;
|
|
3113
3441
|
n.responder.resolve(Ze(e)), this.host.patchRuntime(n.threadId, {
|
|
3114
3442
|
answeredClientRequestIds: a,
|
|
3115
|
-
messages:
|
|
3443
|
+
messages: rr(i.messages, n.threadId, n.displayTurnId, {
|
|
3116
3444
|
itemId: n.itemId,
|
|
3117
3445
|
output: { decision: e }
|
|
3118
3446
|
})
|
|
@@ -3151,7 +3479,7 @@ var Cr = class {
|
|
|
3151
3479
|
${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ? s[0].answer : s.map((e) => `${e.question}: ${e.answer}`).join("\n");
|
|
3152
3480
|
await this.host.answerAsyncQuestion(a.runtime.threadId, e, t);
|
|
3153
3481
|
}
|
|
3154
|
-
this.host.patchRuntime(a.runtime.threadId, { answeredClientRequestIds:
|
|
3482
|
+
this.host.patchRuntime(a.runtime.threadId, { answeredClientRequestIds: sr(a.runtime.answeredClientRequestIds, t.id) }), this.host.emitEvent("action", {
|
|
3155
3483
|
type: "clientRequest.resolved",
|
|
3156
3484
|
conversationId: a.runtime.threadId,
|
|
3157
3485
|
...a.request.turnId ? { turnId: a.request.turnId } : {},
|
|
@@ -3166,7 +3494,7 @@ ${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ?
|
|
|
3166
3494
|
let n = this.pending.get(e);
|
|
3167
3495
|
if (this.pending.delete(e), n) {
|
|
3168
3496
|
let t = this.host.requireRuntime(n.threadId);
|
|
3169
|
-
this.host.patchRuntime(n.threadId, { answeredClientRequestIds:
|
|
3497
|
+
this.host.patchRuntime(n.threadId, { answeredClientRequestIds: sr(t.answeredClientRequestIds, e) });
|
|
3170
3498
|
}
|
|
3171
3499
|
this.maybeClearWaitingBusy(t), n && this.host.emitEvent("notification", {
|
|
3172
3500
|
type: "clientRequest.resolved",
|
|
@@ -3214,7 +3542,7 @@ ${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ?
|
|
|
3214
3542
|
responder: t
|
|
3215
3543
|
}), this.host.patchRuntime(n, {
|
|
3216
3544
|
busy: !0,
|
|
3217
|
-
messages:
|
|
3545
|
+
messages: W(o.messages, n, r, {
|
|
3218
3546
|
type: "tool",
|
|
3219
3547
|
id: i,
|
|
3220
3548
|
kind: "generic",
|
|
@@ -3313,7 +3641,7 @@ ${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ?
|
|
|
3313
3641
|
};
|
|
3314
3642
|
this.host.patchRuntime(n.threadId, {
|
|
3315
3643
|
busy: !0,
|
|
3316
|
-
messages:
|
|
3644
|
+
messages: W(o.messages, n.threadId, s, f)
|
|
3317
3645
|
});
|
|
3318
3646
|
let p = this.host.messageContainingTool(n.threadId, s, l);
|
|
3319
3647
|
return p && this.host.emitEvent("notification", {
|
|
@@ -3331,408 +3659,112 @@ ${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ?
|
|
|
3331
3659
|
payload: { request: structuredClone(d) }
|
|
3332
3660
|
}), this.host.emitConversationActivity(n.threadId, "notification"), !0;
|
|
3333
3661
|
}
|
|
3334
|
-
},
|
|
3335
|
-
function
|
|
3336
|
-
return {
|
|
3337
|
-
id: e.id,
|
|
3338
|
-
model: e.model,
|
|
3339
|
-
displayName: e.displayName,
|
|
3340
|
-
description: e.description,
|
|
3341
|
-
hidden: e.hidden,
|
|
3342
|
-
supportedReasoningEfforts: e.supportedReasoningEfforts,
|
|
3343
|
-
defaultReasoningEffort: e.defaultReasoningEffort,
|
|
3344
|
-
...e.serviceTiers.length > 0 ? { serviceTiers: e.serviceTiers.map((e) => ({
|
|
3345
|
-
id: e.id,
|
|
3346
|
-
name: e.name,
|
|
3347
|
-
description: e.description
|
|
3348
|
-
})) } : {},
|
|
3349
|
-
...e.defaultServiceTier ? { defaultServiceTier: e.defaultServiceTier } : {},
|
|
3350
|
-
isDefault: e.isDefault,
|
|
3351
|
-
providerMetadata: {
|
|
3352
|
-
inputModalities: e.inputModalities,
|
|
3353
|
-
serviceTiers: e.serviceTiers,
|
|
3354
|
-
supportsPersonality: e.supportsPersonality,
|
|
3355
|
-
upgrade: e.upgrade,
|
|
3356
|
-
upgradeInfo: e.upgradeInfo
|
|
3357
|
-
}
|
|
3358
|
-
};
|
|
3359
|
-
}
|
|
3360
|
-
async function Er(e, t) {
|
|
3361
|
-
return Promise.all(e.filter((e) => e.enabled).map((e) => Dr(e, t)));
|
|
3362
|
-
}
|
|
3363
|
-
async function Dr(e, t) {
|
|
3364
|
-
let n = K(e.interface?.brandColor), r = Nr(e.interface?.defaultPrompt), [i, a] = await Promise.all([e.interface?.iconSmall ? t(e.interface.iconSmall) : void 0, e.interface?.iconLarge ? t(e.interface.iconLarge) : void 0]);
|
|
3365
|
-
return {
|
|
3366
|
-
name: e.name,
|
|
3367
|
-
description: e.description,
|
|
3368
|
-
shortDescription: e.shortDescription ?? e.interface?.shortDescription,
|
|
3369
|
-
displayName: e.interface?.displayName,
|
|
3370
|
-
iconSmall: i,
|
|
3371
|
-
iconLarge: a,
|
|
3372
|
-
...n ? { brandColor: n } : {},
|
|
3373
|
-
...r === void 0 ? {} : { defaultPrompt: r },
|
|
3374
|
-
path: e.path,
|
|
3375
|
-
scope: e.scope,
|
|
3376
|
-
enabled: e.enabled
|
|
3377
|
-
};
|
|
3378
|
-
}
|
|
3379
|
-
async function Or(e, t) {
|
|
3380
|
-
let n = e.interface, r = Ar(n?.composerIconUrl), i = Ar(n?.logoUrl), a = Ar(n?.logoUrlDark), o = K(n?.displayName) ?? e.name, s = K(n?.shortDescription), c = K(n?.longDescription), l = K(n?.brandColor), u = r ?? i ?? await kr([n?.composerIcon, n?.logo], t), d = r ?? a ?? i ?? await kr([
|
|
3381
|
-
n?.composerIcon,
|
|
3382
|
-
n?.logoDark,
|
|
3383
|
-
n?.logo
|
|
3384
|
-
], t);
|
|
3385
|
-
return {
|
|
3386
|
-
id: e.id,
|
|
3387
|
-
name: e.name,
|
|
3388
|
-
displayName: o,
|
|
3389
|
-
...s ? { shortDescription: s } : {},
|
|
3390
|
-
...c ? { longDescription: c } : {},
|
|
3391
|
-
...l ? { brandColor: l } : {},
|
|
3392
|
-
...u ? { iconUrl: u } : {},
|
|
3393
|
-
...d ? { iconUrlDark: d } : {},
|
|
3394
|
-
enabled: e.enabled
|
|
3395
|
-
};
|
|
3396
|
-
}
|
|
3397
|
-
async function kr(e, t) {
|
|
3398
|
-
for (let n of e) {
|
|
3399
|
-
if (!n) continue;
|
|
3400
|
-
let e = await t(n);
|
|
3401
|
-
if (e) return e;
|
|
3402
|
-
}
|
|
3403
|
-
}
|
|
3404
|
-
function Ar(e) {
|
|
3405
|
-
let t = K(e);
|
|
3406
|
-
try {
|
|
3407
|
-
return new URL(t).protocol === "https:" ? t : void 0;
|
|
3408
|
-
} catch {}
|
|
3409
|
-
}
|
|
3410
|
-
function jr(e) {
|
|
3411
|
-
switch (_(e).toLowerCase()) {
|
|
3412
|
-
case ".avif": return "image/avif";
|
|
3413
|
-
case ".bmp": return "image/bmp";
|
|
3414
|
-
case ".gif": return "image/gif";
|
|
3415
|
-
case ".ico": return "image/x-icon";
|
|
3416
|
-
case ".jpeg":
|
|
3417
|
-
case ".jpg": return "image/jpeg";
|
|
3418
|
-
case ".png": return "image/png";
|
|
3419
|
-
case ".svg": return "image/svg+xml";
|
|
3420
|
-
case ".webp": return "image/webp";
|
|
3421
|
-
}
|
|
3422
|
-
}
|
|
3423
|
-
function Mr(e, t) {
|
|
3424
|
-
let n = t.trim();
|
|
3425
|
-
if (!/^[a-z\d+/]+={0,2}$/i.test(n)) return;
|
|
3426
|
-
let r = n.replace(/=+$/, "");
|
|
3427
|
-
if (r.length % 4 == 1) return;
|
|
3428
|
-
let i = n.length - r.length, a = (4 - r.length % 4) % 4;
|
|
3429
|
-
if (!(i !== 0 && i !== a) && !(Math.floor(r.length * 3 / 4) > wr)) return `data:${e};base64,${`${r}${"=".repeat((4 - r.length % 4) % 4)}`}`;
|
|
3430
|
-
}
|
|
3431
|
-
function K(e) {
|
|
3432
|
-
return (typeof e == "string" ? e.trim() : void 0) || void 0;
|
|
3433
|
-
}
|
|
3434
|
-
function Nr(e) {
|
|
3435
|
-
return typeof e == "string" ? e : void 0;
|
|
3436
|
-
}
|
|
3437
|
-
//#endregion
|
|
3438
|
-
//#region src/node/codex-surface-settings.ts
|
|
3439
|
-
function q(e, t) {
|
|
3440
|
-
return e.find((e) => e.id === t || e.model === t) ?? e.find((e) => e.isDefault) ?? e[0] ?? null;
|
|
3441
|
-
}
|
|
3442
|
-
function Pr(e, t) {
|
|
3443
|
-
let n = e.find((e) => e.id === t || e.model === t);
|
|
3444
|
-
if (!n) throw Error(`Unknown model '${t}'`);
|
|
3445
|
-
return n;
|
|
3446
|
-
}
|
|
3447
|
-
function Fr(e, t) {
|
|
3448
|
-
if (!t) return;
|
|
3449
|
-
if (!e) throw Error(`Cannot select reasoning effort '${t}' without a model`);
|
|
3450
|
-
let n = e.supportedReasoningEfforts?.map((e) => e.reasoningEffort) ?? [];
|
|
3451
|
-
if (n.length > 0 && !n.includes(t)) throw Error(`Reasoning effort '${t}' is not available for '${e.displayName}'`);
|
|
3452
|
-
}
|
|
3453
|
-
function J(e) {
|
|
3454
|
-
return e.defaultReasoningEffort ?? e.supportedReasoningEfforts?.[0]?.reasoningEffort ?? null;
|
|
3455
|
-
}
|
|
3456
|
-
function Ir(e) {
|
|
3457
|
-
return e.defaultServiceTier ?? null;
|
|
3458
|
-
}
|
|
3459
|
-
function Y(e, t) {
|
|
3460
|
-
if (!t) return;
|
|
3461
|
-
if (!e) throw Error(`Cannot select service tier '${t}' without a model`);
|
|
3462
|
-
if (t === "default" || t === e.defaultServiceTier) return;
|
|
3463
|
-
let n = e.serviceTiers?.map((e) => e.id) ?? [];
|
|
3464
|
-
if (n.length > 0 && !n.includes(t)) throw Error(`Service tier '${t}' is not available for '${e.displayName}'`);
|
|
3465
|
-
}
|
|
3466
|
-
function Lr(e, t) {
|
|
3467
|
-
let n = new Set(e.filter((e) => e.allowed).map((e) => e.id)), r = [];
|
|
3468
|
-
return n.has(":workspace") && X(t?.allowedApprovalPolicies, "on-request") && X(t?.allowedApprovalsReviewers, "user") && r.push("ask-for-approval"), n.has(":workspace") && X(t?.allowedApprovalPolicies, "on-request") && X(t?.allowedApprovalsReviewers, "auto_review") && r.push("approve-for-me"), (n.has(":danger-full-access") || n.has(":danger-no-sandbox")) && X(t?.allowedApprovalPolicies, "never") && X(t?.allowedApprovalsReviewers, "user") && r.push("full-access"), r;
|
|
3469
|
-
}
|
|
3470
|
-
function X(e, t) {
|
|
3471
|
-
return !Array.isArray(e) || e.length === 0 || e.includes(t);
|
|
3472
|
-
}
|
|
3473
|
-
function Rr(e) {
|
|
3474
|
-
return e === "full-access" ? {
|
|
3475
|
-
approvalPolicy: "never",
|
|
3476
|
-
approvalsReviewer: "user",
|
|
3477
|
-
permissions: ":danger-full-access"
|
|
3478
|
-
} : {
|
|
3479
|
-
approvalPolicy: "on-request",
|
|
3480
|
-
approvalsReviewer: e === "approve-for-me" ? "auto_review" : "user",
|
|
3481
|
-
permissions: ":workspace"
|
|
3482
|
-
};
|
|
3483
|
-
}
|
|
3484
|
-
function zr(e) {
|
|
3485
|
-
return Rr(e);
|
|
3486
|
-
}
|
|
3487
|
-
function Br(e, t, n, r) {
|
|
3488
|
-
let i = r?.id;
|
|
3489
|
-
return e === "never" && (n.type === "dangerFullAccess" || i === ":danger-full-access" || i === ":danger-no-sandbox") ? "full-access" : e === "on-request" && (t === "auto_review" || t === "guardian_subagent") ? "approve-for-me" : e === "on-request" ? "ask-for-approval" : null;
|
|
3490
|
-
}
|
|
3491
|
-
function Vr(e, t, n) {
|
|
3492
|
-
let r = q(t, e.model);
|
|
3493
|
-
return {
|
|
3494
|
-
approvalPreset: Br(e.approvalPolicy, e.approvalsReviewer, e.sandbox, e.activePermissionProfile) ?? n.approvalPreset,
|
|
3495
|
-
planMode: n.planMode,
|
|
3496
|
-
selectedModelId: r?.id ?? n.selectedModelId,
|
|
3497
|
-
selectedReasoningEffort: e.reasoningEffort ?? (r ? J(r) : null),
|
|
3498
|
-
selectedServiceTier: e.serviceTier === void 0 ? r ? Ir(r) : null : e.serviceTier
|
|
3499
|
-
};
|
|
3500
|
-
}
|
|
3501
|
-
function Hr(e, t, n) {
|
|
3502
|
-
let r = q(t, e.model);
|
|
3503
|
-
return {
|
|
3504
|
-
approvalPreset: Br(e.approvalPolicy, e.approvalsReviewer, e.sandboxPolicy, e.activePermissionProfile) ?? n.approvalPreset,
|
|
3505
|
-
planMode: e.collaborationMode.mode === "plan",
|
|
3506
|
-
selectedModelId: r?.id ?? n.selectedModelId,
|
|
3507
|
-
selectedReasoningEffort: e.effort ?? (r ? J(r) : null),
|
|
3508
|
-
selectedServiceTier: e.serviceTier === void 0 ? r ? Ir(r) : null : e.serviceTier
|
|
3509
|
-
};
|
|
3510
|
-
}
|
|
3511
|
-
function Ur(e, t) {
|
|
3512
|
-
let n = q(e.models, e.selectedModelId);
|
|
3513
|
-
if (t.modelId && (n = e.models.find((e) => e.id === t.modelId) ?? null, !n)) throw Error(`Unknown model '${t.modelId}'`);
|
|
3514
|
-
let r = t.reasoningEffort ?? e.selectedReasoningEffort, i = t.serviceTier === void 0 ? e.selectedServiceTier ?? null : t.serviceTier, a = n?.supportedReasoningEfforts?.map((e) => e.reasoningEffort) ?? [];
|
|
3515
|
-
if (t.reasoningEffort && a.length > 0 && !a.includes(t.reasoningEffort)) throw Error(`Reasoning effort '${t.reasoningEffort}' is not available for '${n.displayName}'`);
|
|
3516
|
-
return t.modelId && a.length > 0 && (!r || !a.includes(r)) && (r = n ? J(n) : null), t.serviceTier !== void 0 && Y(n, i), t.serviceTier === void 0 && t.modelId && i && !n.serviceTiers?.some((e) => e.id === i) && (i = n ? Ir(n) : null), {
|
|
3517
|
-
approvalPreset: t.approvalPreset ?? e.approvalPreset,
|
|
3518
|
-
planMode: t.planMode ?? e.planMode,
|
|
3519
|
-
selectedModelId: n?.id ?? null,
|
|
3520
|
-
selectedReasoningEffort: r,
|
|
3521
|
-
selectedServiceTier: i
|
|
3522
|
-
};
|
|
3523
|
-
}
|
|
3524
|
-
function Wr(e, t, n) {
|
|
3525
|
-
return {
|
|
3526
|
-
mode: e ? "plan" : "default",
|
|
3527
|
-
settings: {
|
|
3528
|
-
model: t,
|
|
3529
|
-
reasoning_effort: n,
|
|
3530
|
-
developer_instructions: null
|
|
3531
|
-
}
|
|
3532
|
-
};
|
|
3533
|
-
}
|
|
3534
|
-
function Gr(e, t) {
|
|
3535
|
-
let n = q(e.models, e.selectedModelId), r = t.model ?? n?.model, i = t.reasoningEffort ?? e.selectedReasoningEffort, a = t.planMode ?? e.planMode;
|
|
3536
|
-
return {
|
|
3537
|
-
...r ? { model: r } : {},
|
|
3538
|
-
...i ? { effort: i } : {},
|
|
3539
|
-
...r ? { collaborationMode: Wr(a, r, i) } : {},
|
|
3540
|
-
...t.serviceTier === void 0 ? e.selectedServiceTier ? { serviceTier: e.selectedServiceTier } : {} : { serviceTier: t.serviceTier }
|
|
3541
|
-
};
|
|
3542
|
-
}
|
|
3543
|
-
//#endregion
|
|
3544
|
-
//#region src/node/codex-surface-data.ts
|
|
3545
|
-
function Z(e) {
|
|
3546
|
-
let t = e.preview.trim(), n = t.split("\n")[0];
|
|
3547
|
-
return {
|
|
3548
|
-
id: e.id,
|
|
3549
|
-
...e.sessionId ? { sessionId: e.sessionId } : {},
|
|
3550
|
-
...e.parentThreadId ? { parentConversationId: e.parentThreadId } : {},
|
|
3551
|
-
...e.agentNickname ? { agentNickname: e.agentNickname } : {},
|
|
3552
|
-
...e.agentRole ? { agentRole: e.agentRole } : {},
|
|
3553
|
-
title: e.name?.trim() || n.trim() || "Untitled conversation",
|
|
3554
|
-
preview: t,
|
|
3555
|
-
cwd: e.cwd,
|
|
3556
|
-
status: e.status.type === "active" ? "active" : e.status.type === "systemError" ? "error" : "idle",
|
|
3557
|
-
turnCount: e.turns.length,
|
|
3558
|
-
createdAt: (/* @__PURE__ */ new Date(e.createdAt * 1e3)).toISOString(),
|
|
3559
|
-
updatedAt: (/* @__PURE__ */ new Date((e.recencyAt ?? e.updatedAt) * 1e3)).toISOString()
|
|
3560
|
-
};
|
|
3561
|
-
}
|
|
3562
|
-
function Kr(e, t) {
|
|
3563
|
-
let n = new Map(e.map((e) => [e.id, e])), r = t.map((e) => {
|
|
3564
|
-
let t = n.get(e.id);
|
|
3565
|
-
return t && ie(t, e) ? t : e;
|
|
3566
|
-
});
|
|
3567
|
-
return r.length === e.length && r.every((t, n) => t === e[n]) ? e : r;
|
|
3568
|
-
}
|
|
3569
|
-
function Q(e, t) {
|
|
3570
|
-
return [t, ...e.filter((e) => e.id !== t.id)].sort((e, t) => t.updatedAt.localeCompare(e.updatedAt));
|
|
3571
|
-
}
|
|
3572
|
-
function qr(e, t) {
|
|
3573
|
-
let n = t.model ? Pr(e.models, t.model) : q(e.models, e.selectedModelId);
|
|
3574
|
-
return Fr(n, t.reasoningEffort), Y(n, t.serviceTier), {
|
|
3575
|
-
...t,
|
|
3576
|
-
...t.attachments ? { attachments: Jr(t.attachments) } : {},
|
|
3577
|
-
...t.model && n ? { model: n.model } : {}
|
|
3662
|
+
}, $r = 256 * 1024;
|
|
3663
|
+
function ei(e) {
|
|
3664
|
+
return {
|
|
3665
|
+
id: e.id,
|
|
3666
|
+
model: e.model,
|
|
3667
|
+
displayName: e.displayName,
|
|
3668
|
+
description: e.description,
|
|
3669
|
+
hidden: e.hidden,
|
|
3670
|
+
supportedReasoningEfforts: e.supportedReasoningEfforts,
|
|
3671
|
+
defaultReasoningEffort: e.defaultReasoningEffort,
|
|
3672
|
+
...e.serviceTiers.length > 0 ? { serviceTiers: e.serviceTiers.map((e) => ({
|
|
3673
|
+
id: e.id,
|
|
3674
|
+
name: e.name,
|
|
3675
|
+
description: e.description
|
|
3676
|
+
})) } : {},
|
|
3677
|
+
...e.defaultServiceTier ? { defaultServiceTier: e.defaultServiceTier } : {},
|
|
3678
|
+
isDefault: e.isDefault,
|
|
3679
|
+
providerMetadata: {
|
|
3680
|
+
inputModalities: e.inputModalities,
|
|
3681
|
+
serviceTiers: e.serviceTiers,
|
|
3682
|
+
supportsPersonality: e.supportsPersonality,
|
|
3683
|
+
upgrade: e.upgrade,
|
|
3684
|
+
upgradeInfo: e.upgradeInfo
|
|
3685
|
+
}
|
|
3578
3686
|
};
|
|
3579
3687
|
}
|
|
3580
|
-
function
|
|
3581
|
-
return e.map((e) =>
|
|
3582
|
-
let t = e.path.trim();
|
|
3583
|
-
if (!t) throw Error("Attachment paths cannot be empty");
|
|
3584
|
-
if (!v(t)) throw Error(`Attachment path must be absolute: '${t}'`);
|
|
3585
|
-
if (e.type === "image") return {
|
|
3586
|
-
...e,
|
|
3587
|
-
path: t
|
|
3588
|
-
};
|
|
3589
|
-
let n = e.name?.trim();
|
|
3590
|
-
return {
|
|
3591
|
-
...e,
|
|
3592
|
-
path: t,
|
|
3593
|
-
...n ? { name: n } : {}
|
|
3594
|
-
};
|
|
3595
|
-
});
|
|
3688
|
+
async function ti(e, t) {
|
|
3689
|
+
return Promise.all(e.filter((e) => e.enabled).map((e) => ni(e, t)));
|
|
3596
3690
|
}
|
|
3597
|
-
function
|
|
3598
|
-
|
|
3599
|
-
|
|
3691
|
+
async function ni(e, t) {
|
|
3692
|
+
let n = $(e.interface?.brandColor), r = ci(e.interface?.defaultPrompt), [i, a] = await Promise.all([e.interface?.iconSmall ? t(e.interface.iconSmall) : void 0, e.interface?.iconLarge ? t(e.interface.iconLarge) : void 0]);
|
|
3693
|
+
return {
|
|
3694
|
+
name: e.name,
|
|
3695
|
+
description: e.description,
|
|
3696
|
+
shortDescription: e.shortDescription ?? e.interface?.shortDescription,
|
|
3697
|
+
displayName: e.interface?.displayName,
|
|
3698
|
+
iconSmall: i,
|
|
3699
|
+
iconLarge: a,
|
|
3700
|
+
...n ? { brandColor: n } : {},
|
|
3701
|
+
...r === void 0 ? {} : { defaultPrompt: r },
|
|
3600
3702
|
path: e.path,
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
}
|
|
3604
|
-
function Xr(e) {
|
|
3605
|
-
let t = e.name?.trim() || g(e.path);
|
|
3606
|
-
return e.type === "image" ? {
|
|
3607
|
-
type: "attachment",
|
|
3608
|
-
attachment: {
|
|
3609
|
-
kind: "image",
|
|
3610
|
-
name: t,
|
|
3611
|
-
path: e.path,
|
|
3612
|
-
url: e.previewUrl ?? re(e.path).href,
|
|
3613
|
-
...e.mimeType ? { mimeType: e.mimeType } : {}
|
|
3614
|
-
}
|
|
3615
|
-
} : {
|
|
3616
|
-
type: "attachment",
|
|
3617
|
-
attachment: {
|
|
3618
|
-
kind: "file",
|
|
3619
|
-
name: t,
|
|
3620
|
-
path: e.path,
|
|
3621
|
-
...e.mimeType ? { mimeType: e.mimeType } : {}
|
|
3622
|
-
}
|
|
3703
|
+
scope: e.scope,
|
|
3704
|
+
enabled: e.enabled
|
|
3623
3705
|
};
|
|
3624
3706
|
}
|
|
3625
|
-
function
|
|
3626
|
-
let
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
}
|
|
3632
|
-
function $r(e) {
|
|
3633
|
-
return e.parts.flatMap((e) => {
|
|
3634
|
-
if (e.type !== "attachment") return [];
|
|
3635
|
-
let t = e.attachment, n = t.path;
|
|
3636
|
-
return n ? t.kind === "image" ? [{
|
|
3637
|
-
type: "image",
|
|
3638
|
-
path: n,
|
|
3639
|
-
name: t.name,
|
|
3640
|
-
...t.mimeType ? { mimeType: t.mimeType } : {},
|
|
3641
|
-
...t.url?.startsWith("data:image/") ? { previewUrl: t.url } : {}
|
|
3642
|
-
}] : [{
|
|
3643
|
-
type: "file",
|
|
3644
|
-
path: n,
|
|
3645
|
-
name: t.name,
|
|
3646
|
-
...t.mimeType ? { mimeType: t.mimeType } : {}
|
|
3647
|
-
}] : [];
|
|
3648
|
-
});
|
|
3649
|
-
}
|
|
3650
|
-
function ei(e) {
|
|
3651
|
-
let t = e.modelContextWindow, n = e.last.totalTokens, r = typeof t == "number" && t > 0 ? Math.min(100, Math.max(0, n / t * 100)) : null;
|
|
3707
|
+
async function ri(e, t) {
|
|
3708
|
+
let n = e.interface, r = ai(n?.composerIconUrl), i = ai(n?.logoUrl), a = ai(n?.logoUrlDark), o = $(n?.displayName) ?? e.name, s = $(n?.shortDescription), c = $(n?.longDescription), l = $(n?.brandColor), u = r ?? i ?? await ii([n?.composerIcon, n?.logo], t), d = r ?? a ?? i ?? await ii([
|
|
3709
|
+
n?.composerIcon,
|
|
3710
|
+
n?.logoDark,
|
|
3711
|
+
n?.logo
|
|
3712
|
+
], t);
|
|
3652
3713
|
return {
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3714
|
+
id: e.id,
|
|
3715
|
+
name: e.name,
|
|
3716
|
+
displayName: o,
|
|
3717
|
+
...s ? { shortDescription: s } : {},
|
|
3718
|
+
...c ? { longDescription: c } : {},
|
|
3719
|
+
...l ? { brandColor: l } : {},
|
|
3720
|
+
...u ? { iconUrl: u } : {},
|
|
3721
|
+
...d ? { iconUrlDark: d } : {},
|
|
3722
|
+
enabled: e.enabled
|
|
3661
3723
|
};
|
|
3662
3724
|
}
|
|
3663
|
-
function
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3725
|
+
async function ii(e, t) {
|
|
3726
|
+
for (let n of e) {
|
|
3727
|
+
if (!n) continue;
|
|
3728
|
+
let e = await t(n);
|
|
3729
|
+
if (e) return e;
|
|
3730
|
+
}
|
|
3668
3731
|
}
|
|
3669
|
-
function
|
|
3670
|
-
|
|
3732
|
+
function ai(e) {
|
|
3733
|
+
let t = $(e);
|
|
3734
|
+
try {
|
|
3735
|
+
return new URL(t).protocol === "https:" ? t : void 0;
|
|
3736
|
+
} catch {}
|
|
3671
3737
|
}
|
|
3672
|
-
function
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3738
|
+
function oi(e) {
|
|
3739
|
+
switch (_(e).toLowerCase()) {
|
|
3740
|
+
case ".avif": return "image/avif";
|
|
3741
|
+
case ".bmp": return "image/bmp";
|
|
3742
|
+
case ".gif": return "image/gif";
|
|
3743
|
+
case ".ico": return "image/x-icon";
|
|
3744
|
+
case ".jpeg":
|
|
3745
|
+
case ".jpg": return "image/jpeg";
|
|
3746
|
+
case ".png": return "image/png";
|
|
3747
|
+
case ".svg": return "image/svg+xml";
|
|
3748
|
+
case ".webp": return "image/webp";
|
|
3749
|
+
}
|
|
3682
3750
|
}
|
|
3683
|
-
function
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
individualLimit: e.individualLimit ? { ...e.individualLimit } : null,
|
|
3691
|
-
planType: e.planType,
|
|
3692
|
-
rateLimitReachedType: e.rateLimitReachedType
|
|
3693
|
-
};
|
|
3751
|
+
function si(e, t) {
|
|
3752
|
+
let n = t.trim();
|
|
3753
|
+
if (!/^[a-z\d+/]+={0,2}$/i.test(n)) return;
|
|
3754
|
+
let r = n.replace(/=+$/, "");
|
|
3755
|
+
if (r.length % 4 == 1) return;
|
|
3756
|
+
let i = n.length - r.length, a = (4 - r.length % 4) % 4;
|
|
3757
|
+
if (!(i !== 0 && i !== a) && !(Math.floor(r.length * 3 / 4) > $r)) return `data:${e};base64,${`${r}${"=".repeat((4 - r.length % 4) % 4)}`}`;
|
|
3694
3758
|
}
|
|
3695
|
-
function
|
|
3696
|
-
|
|
3697
|
-
if (!e) return {
|
|
3698
|
-
rateLimits: n,
|
|
3699
|
-
rateLimitsByLimitId: n.limitId ? { [n.limitId]: n } : null,
|
|
3700
|
-
rateLimitResetCredits: null
|
|
3701
|
-
};
|
|
3702
|
-
let r = ai(e.rateLimits, n), i = e.rateLimitsByLimitId ? { ...e.rateLimitsByLimitId } : {};
|
|
3703
|
-
return r.limitId && (i[r.limitId] = ai(i[r.limitId] ?? r, n)), {
|
|
3704
|
-
...e,
|
|
3705
|
-
rateLimits: r,
|
|
3706
|
-
rateLimitsByLimitId: Object.keys(i).length > 0 ? i : null
|
|
3707
|
-
};
|
|
3759
|
+
function $(e) {
|
|
3760
|
+
return (typeof e == "string" ? e.trim() : void 0) || void 0;
|
|
3708
3761
|
}
|
|
3709
|
-
function
|
|
3710
|
-
return
|
|
3711
|
-
limitId: t.limitId ?? e.limitId,
|
|
3712
|
-
limitName: t.limitName ?? e.limitName,
|
|
3713
|
-
primary: t.primary ? {
|
|
3714
|
-
...e.primary ?? {},
|
|
3715
|
-
...t.primary
|
|
3716
|
-
} : e.primary,
|
|
3717
|
-
secondary: t.secondary ? {
|
|
3718
|
-
...e.secondary ?? {},
|
|
3719
|
-
...t.secondary
|
|
3720
|
-
} : e.secondary,
|
|
3721
|
-
credits: t.credits ? {
|
|
3722
|
-
...e.credits ?? {},
|
|
3723
|
-
...t.credits
|
|
3724
|
-
} : e.credits,
|
|
3725
|
-
individualLimit: t.individualLimit ? {
|
|
3726
|
-
...e.individualLimit ?? {},
|
|
3727
|
-
...t.individualLimit
|
|
3728
|
-
} : e.individualLimit,
|
|
3729
|
-
planType: t.planType ?? e.planType,
|
|
3730
|
-
rateLimitReachedType: t.rateLimitReachedType ?? e.rateLimitReachedType
|
|
3731
|
-
};
|
|
3762
|
+
function ci(e) {
|
|
3763
|
+
return typeof e == "string" ? e : void 0;
|
|
3732
3764
|
}
|
|
3733
3765
|
//#endregion
|
|
3734
3766
|
//#region src/node/codex-surface-catalog-controller.ts
|
|
3735
|
-
var
|
|
3767
|
+
var li = class {
|
|
3736
3768
|
client;
|
|
3737
3769
|
cwd;
|
|
3738
3770
|
host;
|
|
@@ -3767,7 +3799,7 @@ var oi = class {
|
|
|
3767
3799
|
async loadSkills(e = !1, t = "action") {
|
|
3768
3800
|
e && this.iconDataUrls.clear(), this.host.patch({ skillCatalogStatus: "loading" }), this.emitSkills(this.cwd ?? null, [], "loading", t);
|
|
3769
3801
|
try {
|
|
3770
|
-
let n = await
|
|
3802
|
+
let n = await ti((await this.client.request("skills/list", {
|
|
3771
3803
|
...this.cwd ? { cwds: [this.cwd] } : {},
|
|
3772
3804
|
forceReload: e
|
|
3773
3805
|
})).data.flatMap((e) => e.skills), (e) => this.iconDataUrl(e));
|
|
@@ -3784,7 +3816,7 @@ var oi = class {
|
|
|
3784
3816
|
}
|
|
3785
3817
|
async listSkills(e = {}) {
|
|
3786
3818
|
await this.host.ensureConnected(), e.forceReload && this.iconDataUrls.clear();
|
|
3787
|
-
let t = await
|
|
3819
|
+
let t = await ti((await this.client.request("skills/list", {
|
|
3788
3820
|
...e.cwd ? { cwds: [e.cwd] } : {},
|
|
3789
3821
|
forceReload: e.forceReload ?? !1
|
|
3790
3822
|
})).data.flatMap((e) => e.skills), (e) => this.iconDataUrl(e));
|
|
@@ -3796,7 +3828,7 @@ var oi = class {
|
|
|
3796
3828
|
}
|
|
3797
3829
|
async loadPermissionProfiles() {
|
|
3798
3830
|
try {
|
|
3799
|
-
let e = await this.requestPermissionProfiles(this.cwd), t = (await this.client.request("configRequirements/read", void 0)).requirements, n =
|
|
3831
|
+
let e = await this.requestPermissionProfiles(this.cwd), t = (await this.client.request("configRequirements/read", void 0)).requirements, n = Nt(e, t), r = this.host.preferredApprovalPreset();
|
|
3800
3832
|
this.host.patch({
|
|
3801
3833
|
permissionProfiles: e,
|
|
3802
3834
|
approvalPresets: n,
|
|
@@ -3812,7 +3844,7 @@ var oi = class {
|
|
|
3812
3844
|
}
|
|
3813
3845
|
async loadRateLimits() {
|
|
3814
3846
|
try {
|
|
3815
|
-
let e =
|
|
3847
|
+
let e = $t(await this.client.request("account/rateLimits/read", void 0));
|
|
3816
3848
|
this.host.patch({ rateLimits: e }), this.host.emitEvent("action", {
|
|
3817
3849
|
type: "rateLimits.changed",
|
|
3818
3850
|
payload: { rateLimits: structuredClone(e) }
|
|
@@ -3838,12 +3870,12 @@ var oi = class {
|
|
|
3838
3870
|
}), (async () => ({
|
|
3839
3871
|
profiles: await this.requestPermissionProfiles(e),
|
|
3840
3872
|
requirements: (await this.client.request("configRequirements/read", void 0)).requirements
|
|
3841
|
-
}))()]), a = r.status === "fulfilled" ? await
|
|
3873
|
+
}))()]), a = r.status === "fulfilled" ? await ti(r.value.data.flatMap((e) => e.skills), (e) => this.iconDataUrl(e)) : [], o = i.status === "fulfilled" ? i.value.profiles : [];
|
|
3842
3874
|
return {
|
|
3843
3875
|
skills: a,
|
|
3844
3876
|
skillCatalogStatus: r.status === "fulfilled" ? "loaded" : "error",
|
|
3845
3877
|
permissionProfiles: o,
|
|
3846
|
-
approvalPresets: i.status === "fulfilled" ?
|
|
3878
|
+
approvalPresets: i.status === "fulfilled" ? Nt(o, i.value.requirements) : []
|
|
3847
3879
|
};
|
|
3848
3880
|
}
|
|
3849
3881
|
schedulePluginRefresh(e = !1) {
|
|
@@ -3870,18 +3902,18 @@ var oi = class {
|
|
|
3870
3902
|
cursor: n,
|
|
3871
3903
|
includeHidden: e
|
|
3872
3904
|
});
|
|
3873
|
-
t.push(...r.data.map(
|
|
3905
|
+
t.push(...r.data.map(ei)), n = r.nextCursor;
|
|
3874
3906
|
} while (n);
|
|
3875
3907
|
return t;
|
|
3876
3908
|
}
|
|
3877
3909
|
applyModels(e, t) {
|
|
3878
|
-
let n =
|
|
3910
|
+
let n = k(e, this.host.getState().selectedModelId);
|
|
3879
3911
|
this.host.patch({
|
|
3880
3912
|
models: e,
|
|
3881
3913
|
modelCatalogStatus: "loaded",
|
|
3882
3914
|
selectedModelId: n?.id ?? null,
|
|
3883
|
-
selectedReasoningEffort: n ?
|
|
3884
|
-
selectedServiceTier: n ?
|
|
3915
|
+
selectedReasoningEffort: n ? A(n) : null,
|
|
3916
|
+
selectedServiceTier: n ? Mt(n) : null
|
|
3885
3917
|
}), this.emitModels(e, "loaded", t);
|
|
3886
3918
|
}
|
|
3887
3919
|
emitModels(e, t, n = "action") {
|
|
@@ -3940,7 +3972,7 @@ var oi = class {
|
|
|
3940
3972
|
try {
|
|
3941
3973
|
let t = await this.client.request("plugin/installed", { ...e.length > 0 ? { cwds: [...e] } : {} }), n = /* @__PURE__ */ new Map();
|
|
3942
3974
|
for (let e of t.marketplaces) for (let t of e.plugins) n.has(t.id) || n.set(t.id, t);
|
|
3943
|
-
let r =
|
|
3975
|
+
let r = Ht(this.host.getState().plugins, await Promise.all([...n.values()].map((e) => ri(e, (e) => this.iconDataUrl(e)))));
|
|
3944
3976
|
if (this.host.isClosed() || this.host.authenticationBlocksBootstrap()) return;
|
|
3945
3977
|
this.host.patch({
|
|
3946
3978
|
plugins: r,
|
|
@@ -3971,9 +4003,9 @@ var oi = class {
|
|
|
3971
4003
|
}
|
|
3972
4004
|
async readIconDataUrl(e) {
|
|
3973
4005
|
if (!v(e)) return;
|
|
3974
|
-
let t =
|
|
4006
|
+
let t = oi(e);
|
|
3975
4007
|
if (t) try {
|
|
3976
|
-
return
|
|
4008
|
+
return si(t, (await this.client.request("fs/readFile", { path: e })).dataBase64);
|
|
3977
4009
|
} catch {
|
|
3978
4010
|
return;
|
|
3979
4011
|
}
|
|
@@ -3981,18 +4013,18 @@ var oi = class {
|
|
|
3981
4013
|
};
|
|
3982
4014
|
//#endregion
|
|
3983
4015
|
//#region src/node/codex-approvals.ts
|
|
3984
|
-
function
|
|
4016
|
+
function ui(e, t) {
|
|
3985
4017
|
let n = [
|
|
3986
4018
|
e.onServerRequest("item/commandExecution/requestApproval", (e, n) => (t({
|
|
3987
|
-
approval:
|
|
3988
|
-
resolve: (t, r) => n.resolve({ decision:
|
|
4019
|
+
approval: di(e.id, e.params),
|
|
4020
|
+
resolve: (t, r) => n.resolve({ decision: mi(e.params, t, r) })
|
|
3989
4021
|
}), !0)),
|
|
3990
4022
|
e.onServerRequest("item/fileChange/requestApproval", (e, n) => (t({
|
|
3991
|
-
approval:
|
|
4023
|
+
approval: fi(e.id, e.params),
|
|
3992
4024
|
resolve: (e, t) => n.resolve({ decision: e === "deny" ? "decline" : t === "session" ? "acceptForSession" : "accept" })
|
|
3993
4025
|
}), !0)),
|
|
3994
4026
|
e.onServerRequest("item/permissions/requestApproval", (e, n) => (t({
|
|
3995
|
-
approval:
|
|
4027
|
+
approval: pi(e.id, e.params),
|
|
3996
4028
|
resolve: (t, r) => n.resolve({
|
|
3997
4029
|
permissions: t === "deny" ? {} : {
|
|
3998
4030
|
...e.params.permissions.fileSystem ? { fileSystem: e.params.permissions.fileSystem } : {},
|
|
@@ -4030,8 +4062,8 @@ function si(e, t) {
|
|
|
4030
4062
|
for (let e of n) e();
|
|
4031
4063
|
};
|
|
4032
4064
|
}
|
|
4033
|
-
function
|
|
4034
|
-
let n = t.availableDecisions, r =
|
|
4065
|
+
function di(e, t) {
|
|
4066
|
+
let n = t.availableDecisions, r = hi(t.additionalPermissions), i = [...t.networkApprovalContext ? [{
|
|
4035
4067
|
kind: "network",
|
|
4036
4068
|
enabled: !0,
|
|
4037
4069
|
host: t.networkApprovalContext.host,
|
|
@@ -4054,7 +4086,7 @@ function ci(e, t) {
|
|
|
4054
4086
|
} : {}
|
|
4055
4087
|
};
|
|
4056
4088
|
}
|
|
4057
|
-
function
|
|
4089
|
+
function fi(e, t) {
|
|
4058
4090
|
return {
|
|
4059
4091
|
id: String(e),
|
|
4060
4092
|
kind: "file-change",
|
|
@@ -4065,8 +4097,8 @@ function li(e, t) {
|
|
|
4065
4097
|
...t.reason || t.grantRoot ? { description: t.reason ?? `Write under ${t.grantRoot}` } : {}
|
|
4066
4098
|
};
|
|
4067
4099
|
}
|
|
4068
|
-
function
|
|
4069
|
-
let n =
|
|
4100
|
+
function pi(e, t) {
|
|
4101
|
+
let n = hi(t.permissions);
|
|
4070
4102
|
return {
|
|
4071
4103
|
id: String(e),
|
|
4072
4104
|
kind: "permissions",
|
|
@@ -4079,13 +4111,13 @@ function ui(e, t) {
|
|
|
4079
4111
|
...n.length ? { requestedPermissions: n } : {}
|
|
4080
4112
|
};
|
|
4081
4113
|
}
|
|
4082
|
-
function
|
|
4114
|
+
function mi(e, t, n) {
|
|
4083
4115
|
let r = e.availableDecisions, i = t === "deny" ? "decline" : n === "session" ? "acceptForSession" : "accept";
|
|
4084
4116
|
if (!r || r.includes(i)) return i;
|
|
4085
4117
|
if (t === "deny" && r.includes("cancel")) return "cancel";
|
|
4086
4118
|
throw Error(`Approval decision '${t}:${n}' is not available for this command`);
|
|
4087
4119
|
}
|
|
4088
|
-
function
|
|
4120
|
+
function hi(e) {
|
|
4089
4121
|
if (!e) return [];
|
|
4090
4122
|
let t = [];
|
|
4091
4123
|
if (e.network && t.push({
|
|
@@ -4105,12 +4137,12 @@ function fi(e) {
|
|
|
4105
4137
|
for (let n of e.fileSystem.entries ?? []) t.push({
|
|
4106
4138
|
kind: "filesystem",
|
|
4107
4139
|
access: n.access,
|
|
4108
|
-
path:
|
|
4140
|
+
path: gi(n.path)
|
|
4109
4141
|
});
|
|
4110
4142
|
}
|
|
4111
4143
|
return t;
|
|
4112
4144
|
}
|
|
4113
|
-
function
|
|
4145
|
+
function gi(e) {
|
|
4114
4146
|
if (e.type === "path") return e.path;
|
|
4115
4147
|
if (e.type === "glob_pattern") return e.pattern;
|
|
4116
4148
|
let t = e.value;
|
|
@@ -4125,12 +4157,12 @@ function pi(e) {
|
|
|
4125
4157
|
}
|
|
4126
4158
|
//#endregion
|
|
4127
4159
|
//#region src/node/codex-surface-approvals-controller.ts
|
|
4128
|
-
var
|
|
4160
|
+
var _i = class {
|
|
4129
4161
|
host;
|
|
4130
4162
|
pending = /* @__PURE__ */ new Map();
|
|
4131
4163
|
unsubscribeHandler;
|
|
4132
4164
|
constructor(e, t) {
|
|
4133
|
-
this.host = t, this.unsubscribeHandler =
|
|
4165
|
+
this.host = t, this.unsubscribeHandler = ui(e, (e) => this.add(e));
|
|
4134
4166
|
}
|
|
4135
4167
|
close() {
|
|
4136
4168
|
this.unsubscribeHandler(), this.pending.clear();
|
|
@@ -4211,7 +4243,7 @@ var mi = class {
|
|
|
4211
4243
|
};
|
|
4212
4244
|
//#endregion
|
|
4213
4245
|
//#region src/node/codex-surface-mcp.ts
|
|
4214
|
-
function
|
|
4246
|
+
function vi(e) {
|
|
4215
4247
|
if (!Array.isArray(e)) throw TypeError("Codex MCP servers must be an array");
|
|
4216
4248
|
let t = /* @__PURE__ */ new Set();
|
|
4217
4249
|
return e.map((e, n) => {
|
|
@@ -4220,10 +4252,10 @@ function hi(e) {
|
|
|
4220
4252
|
if (!r || !/^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(r)) throw TypeError(`Codex MCP server ${n + 1} name must match ^[A-Za-z0-9][A-Za-z0-9_-]*$`);
|
|
4221
4253
|
if (t.has(r)) throw Error(`Duplicate Codex MCP server '${r}'`);
|
|
4222
4254
|
t.add(r);
|
|
4223
|
-
let i =
|
|
4255
|
+
let i = yi(e.transport, r), a = e.toolApprovalMode;
|
|
4224
4256
|
if (a !== void 0 && a !== "auto" && a !== "prompt" && a !== "writes" && a !== "approve") throw TypeError(`Codex MCP server '${r}' tool approval mode is invalid`);
|
|
4225
4257
|
if (e.required !== void 0 && typeof e.required != "boolean") throw TypeError(`Codex MCP server '${r}' required flag must be a boolean`);
|
|
4226
|
-
let o = e.enabledTools === void 0 ? void 0 :
|
|
4258
|
+
let o = e.enabledTools === void 0 ? void 0 : bi(e.enabledTools, `Codex MCP server '${r}' enabled tool`), s = Si(e.startupTimeoutMs, `Codex MCP server '${r}' startup timeout`), c = Si(e.toolTimeoutMs, `Codex MCP server '${r}' tool timeout`);
|
|
4227
4259
|
return {
|
|
4228
4260
|
name: r,
|
|
4229
4261
|
transport: i,
|
|
@@ -4235,7 +4267,7 @@ function hi(e) {
|
|
|
4235
4267
|
};
|
|
4236
4268
|
});
|
|
4237
4269
|
}
|
|
4238
|
-
function
|
|
4270
|
+
function yi(e, t) {
|
|
4239
4271
|
if (!e || typeof e != "object" || Array.isArray(e)) throw TypeError(`Codex MCP server '${t}' transport must be an object`);
|
|
4240
4272
|
if (e.type === "http") {
|
|
4241
4273
|
let n = e.url?.trim(), r;
|
|
@@ -4253,7 +4285,7 @@ function gi(e, t) {
|
|
|
4253
4285
|
if (e.type !== "stdio") throw TypeError(`Codex MCP server '${t}' transport type is invalid`);
|
|
4254
4286
|
let n = e.command?.trim();
|
|
4255
4287
|
if (!n) throw TypeError(`Codex MCP server '${t}' command cannot be empty`);
|
|
4256
|
-
let r = e.args === void 0 ? void 0 :
|
|
4288
|
+
let r = e.args === void 0 ? void 0 : bi(e.args, `Codex MCP server '${t}' argument`), i = e.cwd?.trim();
|
|
4257
4289
|
if (i !== void 0 && (!i || !v(i))) throw TypeError(`Codex MCP server '${t}' cwd must be an absolute path`);
|
|
4258
4290
|
let a;
|
|
4259
4291
|
if (e.env !== void 0) {
|
|
@@ -4264,7 +4296,7 @@ function gi(e, t) {
|
|
|
4264
4296
|
a[n] = r;
|
|
4265
4297
|
}
|
|
4266
4298
|
}
|
|
4267
|
-
let o = e.envVars === void 0 ? void 0 :
|
|
4299
|
+
let o = e.envVars === void 0 ? void 0 : xi(e.envVars, t);
|
|
4268
4300
|
return {
|
|
4269
4301
|
type: "stdio",
|
|
4270
4302
|
command: n,
|
|
@@ -4274,7 +4306,7 @@ function gi(e, t) {
|
|
|
4274
4306
|
...o === void 0 ? {} : { envVars: o }
|
|
4275
4307
|
};
|
|
4276
4308
|
}
|
|
4277
|
-
function
|
|
4309
|
+
function bi(e, t) {
|
|
4278
4310
|
if (!Array.isArray(e)) throw TypeError(`${t}s must be an array`);
|
|
4279
4311
|
let n = e.map((e) => {
|
|
4280
4312
|
if (typeof e != "string" || !e.trim()) throw TypeError(`${t} cannot be empty`);
|
|
@@ -4282,18 +4314,18 @@ function _i(e, t) {
|
|
|
4282
4314
|
});
|
|
4283
4315
|
return [...new Set(n)];
|
|
4284
4316
|
}
|
|
4285
|
-
function
|
|
4286
|
-
let n =
|
|
4317
|
+
function xi(e, t) {
|
|
4318
|
+
let n = bi(e, `Codex MCP server '${t}' environment variable`);
|
|
4287
4319
|
for (let e of n) if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(e)) throw TypeError(`Codex MCP server '${t}' environment variable '${e}' is invalid`);
|
|
4288
4320
|
return n;
|
|
4289
4321
|
}
|
|
4290
|
-
function
|
|
4322
|
+
function Si(e, t) {
|
|
4291
4323
|
if (e !== void 0) {
|
|
4292
4324
|
if (!Number.isFinite(e) || e <= 0) throw TypeError(`${t} must be a positive finite number`);
|
|
4293
4325
|
return e;
|
|
4294
4326
|
}
|
|
4295
4327
|
}
|
|
4296
|
-
function
|
|
4328
|
+
function Ci(e) {
|
|
4297
4329
|
let t = {};
|
|
4298
4330
|
for (let n of e) {
|
|
4299
4331
|
let e = n.transport.type === "http" ? { url: n.transport.url } : {
|
|
@@ -4307,7 +4339,7 @@ function bi(e) {
|
|
|
4307
4339
|
}
|
|
4308
4340
|
return t;
|
|
4309
4341
|
}
|
|
4310
|
-
function
|
|
4342
|
+
function wi(e, t) {
|
|
4311
4343
|
if (t.length !== 0) for (let n of Object.keys(e)) {
|
|
4312
4344
|
if (n === "mcp_servers") throw Error("Raw mcp_servers config cannot be combined with typed Codex MCP servers");
|
|
4313
4345
|
for (let e of t) {
|
|
@@ -4318,13 +4350,13 @@ function xi(e, t) {
|
|
|
4318
4350
|
}
|
|
4319
4351
|
//#endregion
|
|
4320
4352
|
//#region src/node/codex-surface-extensions-controller.ts
|
|
4321
|
-
var
|
|
4353
|
+
var Ti = class {
|
|
4322
4354
|
extensions;
|
|
4323
4355
|
hostOptionsForThread;
|
|
4324
4356
|
dynamicTools = /* @__PURE__ */ new Map();
|
|
4325
4357
|
defaultMcpServers;
|
|
4326
4358
|
constructor(e, t, n) {
|
|
4327
|
-
this.extensions = e, this.hostOptionsForThread = n, this.defaultMcpServers =
|
|
4359
|
+
this.extensions = e, this.hostOptionsForThread = n, this.defaultMcpServers = vi(t);
|
|
4328
4360
|
for (let t of e) for (let e of t.dynamicTools ?? []) {
|
|
4329
4361
|
let t = e.name.trim();
|
|
4330
4362
|
if (!t) throw Error("Dynamic tool names cannot be empty");
|
|
@@ -4348,13 +4380,13 @@ var Si = class {
|
|
|
4348
4380
|
}));
|
|
4349
4381
|
}
|
|
4350
4382
|
async conversationExtension(e, t = {}, n = this.defaultMcpServers) {
|
|
4351
|
-
let r =
|
|
4383
|
+
let r = Ci(n), i = [], a;
|
|
4352
4384
|
for (let t of this.extensions) {
|
|
4353
4385
|
if (!t.configureConversation) continue;
|
|
4354
4386
|
let o = await t.configureConversation(e);
|
|
4355
|
-
o.config && (
|
|
4387
|
+
o.config && (wi(o.config, n), Object.assign(r, o.config)), o.baseInstructions !== void 0 && (a = o.baseInstructions), o.developerInstructions?.trim() && i.push(o.developerInstructions.trim());
|
|
4356
4388
|
}
|
|
4357
|
-
return t.config && (
|
|
4389
|
+
return t.config && (wi(t.config, n), Object.assign(r, t.config)), t.baseInstructions !== void 0 && (a = t.baseInstructions), t.developerInstructions?.trim() && i.push(t.developerInstructions.trim()), {
|
|
4358
4390
|
...a === void 0 ? {} : { baseInstructions: a },
|
|
4359
4391
|
...Object.keys(r).length === 0 ? {} : { config: r },
|
|
4360
4392
|
...i.length === 0 ? {} : { developerInstructions: i.join("\n\n") }
|
|
@@ -4413,7 +4445,7 @@ var Si = class {
|
|
|
4413
4445
|
});
|
|
4414
4446
|
}
|
|
4415
4447
|
}
|
|
4416
|
-
},
|
|
4448
|
+
}, Ei = 50, Di = 25, Oi = 25, ki = class {
|
|
4417
4449
|
client;
|
|
4418
4450
|
conversationLimit;
|
|
4419
4451
|
host;
|
|
@@ -4432,7 +4464,7 @@ var Si = class {
|
|
|
4432
4464
|
return await this.host.ensureConnected(), this.load();
|
|
4433
4465
|
}
|
|
4434
4466
|
async load() {
|
|
4435
|
-
let e =
|
|
4467
|
+
let e = Ht(this.host.getState().conversations, await this.requestConversations({ limit: this.conversationLimit }));
|
|
4436
4468
|
this.host.patch({ conversations: e }), this.host.schedulePluginRefresh(!0);
|
|
4437
4469
|
for (let t of e) this.host.emitSummaryUpserted(t, "listed", "action");
|
|
4438
4470
|
return this.host.getSnapshot();
|
|
@@ -4465,7 +4497,7 @@ var Si = class {
|
|
|
4465
4497
|
let n = await this.client.request("thread/unarchive", { threadId: t });
|
|
4466
4498
|
if (n.thread.id !== t) throw Error(`Codex thread/unarchive returned '${n.thread.id}' for requested thread '${t}'`);
|
|
4467
4499
|
let r = this.summaryWithKnownTurnCount(n.thread);
|
|
4468
|
-
return this.host.patch({ conversations:
|
|
4500
|
+
return this.host.patch({ conversations: P(this.host.getState().conversations, r) }), this.host.emitSummaryUpserted(r, "updated", "action"), this.host.getSnapshot();
|
|
4469
4501
|
}
|
|
4470
4502
|
hydrateCompleteHistory(e, t = {}) {
|
|
4471
4503
|
if (this.host.requireRuntime(e).fullHistoryHydrated && !t.restart) return Promise.resolve();
|
|
@@ -4482,7 +4514,7 @@ var Si = class {
|
|
|
4482
4514
|
let t = await this.client.request("thread/turns/list", {
|
|
4483
4515
|
threadId: e,
|
|
4484
4516
|
cursor: null,
|
|
4485
|
-
limit:
|
|
4517
|
+
limit: Ei,
|
|
4486
4518
|
sortDirection: "desc",
|
|
4487
4519
|
itemsView: "full"
|
|
4488
4520
|
});
|
|
@@ -4530,7 +4562,7 @@ var Si = class {
|
|
|
4530
4562
|
let i = new Set(this.host.requireRuntime(e).turnIds), a = await this.client.request("thread/turns/list", {
|
|
4531
4563
|
threadId: e,
|
|
4532
4564
|
cursor: t,
|
|
4533
|
-
limit:
|
|
4565
|
+
limit: Di,
|
|
4534
4566
|
sortDirection: "desc",
|
|
4535
4567
|
itemsView: "full"
|
|
4536
4568
|
}), o = [...a.data].reverse(), s = new Set(o.map((e) => e.id).filter((e) => !i.has(e)));
|
|
@@ -4561,8 +4593,8 @@ var Si = class {
|
|
|
4561
4593
|
}
|
|
4562
4594
|
async emitHistoryChunks(e, t) {
|
|
4563
4595
|
for (let n = t.length; n > 0;) {
|
|
4564
|
-
let r = Math.max(0, n -
|
|
4565
|
-
this.host.emitHistoryPrepended(e, t.slice(r, n), "lifecycle"), await
|
|
4596
|
+
let r = Math.max(0, n - Oi);
|
|
4597
|
+
this.host.emitHistoryPrepended(e, t.slice(r, n), "lifecycle"), await Ai(), n = r;
|
|
4566
4598
|
}
|
|
4567
4599
|
}
|
|
4568
4600
|
async refreshCompleteHistory(e) {
|
|
@@ -4598,10 +4630,10 @@ var Si = class {
|
|
|
4598
4630
|
let i = /* @__PURE__ */ new Set();
|
|
4599
4631
|
r.activeTurnId && i.add(r.activeTurnId);
|
|
4600
4632
|
for (let e of t) e.status === "inProgress" && r.turnIds.includes(e.id) && i.add(e.id);
|
|
4601
|
-
let a = new Set(t.filter((e) => !i.has(e.id)).map((e) => e.id)), o = t.filter((e) => a.has(e.id)), s = r.turnIds.filter((e) => !a.has(e)), c = r.turns.filter((e) => !a.has(e.id)), l = r.messages.filter((e) => e.turnId === void 0 || !a.has(e.turnId)), u =
|
|
4633
|
+
let a = new Set(t.filter((e) => !i.has(e.id)).map((e) => e.id)), o = t.filter((e) => a.has(e.id)), s = r.turnIds.filter((e) => !a.has(e)), c = r.turns.filter((e) => !a.has(e.id)), l = r.messages.filter((e) => e.turnId === void 0 || !a.has(e.turnId)), u = pr(r.messages, o.flatMap((t) => mr(e, t)));
|
|
4602
4634
|
this.host.patchRuntime(e, {
|
|
4603
4635
|
turnIds: [...o.map((e) => e.id), ...s],
|
|
4604
|
-
turns: [...o.map((e) =>
|
|
4636
|
+
turns: [...o.map((e) => Z(e)), ...c],
|
|
4605
4637
|
messages: [...u, ...l]
|
|
4606
4638
|
});
|
|
4607
4639
|
let d = this.host.requireRuntime(e).turnIds.length, f = this.host.getState();
|
|
@@ -4613,7 +4645,7 @@ var Si = class {
|
|
|
4613
4645
|
return p && this.host.emitSummaryUpserted(p, "updated", "action"), u.filter((e) => e.turnId !== void 0 && n.has(e.turnId));
|
|
4614
4646
|
}
|
|
4615
4647
|
summaryWithKnownTurnCount(e) {
|
|
4616
|
-
let t =
|
|
4648
|
+
let t = N(e), n = this.host.runtime(e.id);
|
|
4617
4649
|
if (n?.hydrated) return {
|
|
4618
4650
|
...t,
|
|
4619
4651
|
turnCount: n.turnIds.length
|
|
@@ -4625,12 +4657,12 @@ var Si = class {
|
|
|
4625
4657
|
} : t;
|
|
4626
4658
|
}
|
|
4627
4659
|
};
|
|
4628
|
-
function
|
|
4660
|
+
function Ai() {
|
|
4629
4661
|
return new Promise((e) => setTimeout(e, 0));
|
|
4630
4662
|
}
|
|
4631
4663
|
//#endregion
|
|
4632
4664
|
//#region src/node/codex-surface-conversation-settings-controller.ts
|
|
4633
|
-
var
|
|
4665
|
+
var ji = class {
|
|
4634
4666
|
client;
|
|
4635
4667
|
defaults;
|
|
4636
4668
|
host;
|
|
@@ -4642,7 +4674,7 @@ var Oi = class {
|
|
|
4642
4674
|
}
|
|
4643
4675
|
threadStartSettings(e, t) {
|
|
4644
4676
|
let n = this.preferredApprovalPreset(), r = e.approvalPreset ?? (e.approvalMode === void 0 && e.permissionMode === void 0 ? t.includes(n ?? "ask-for-approval") ? n : t[0] ?? null : null);
|
|
4645
|
-
if (r) return
|
|
4677
|
+
if (r) return Pt(r);
|
|
4646
4678
|
let i = e.approvalMode ?? this.defaults.approvalMode, a = e.permissionMode ?? this.defaults.permissionMode ?? "read-only";
|
|
4647
4679
|
return {
|
|
4648
4680
|
approvalPolicy: i === "ask" ? "on-request" : "never",
|
|
@@ -4668,23 +4700,23 @@ var Oi = class {
|
|
|
4668
4700
|
async update(e) {
|
|
4669
4701
|
let t = this.host.getState(), n = t.activeConversationId;
|
|
4670
4702
|
if (!n) {
|
|
4671
|
-
let n =
|
|
4703
|
+
let n = zt(t, e);
|
|
4672
4704
|
if (e.approvalPreset && !t.approvalPresets.includes(e.approvalPreset)) throw Error(`Approval preset '${e.approvalPreset}' is not available`);
|
|
4673
4705
|
return this.host.patch(n), this.host.getSnapshot();
|
|
4674
4706
|
}
|
|
4675
4707
|
return await this.updateForThread(n, e), this.host.getSnapshot();
|
|
4676
4708
|
}
|
|
4677
4709
|
async updateForThread(e, t) {
|
|
4678
|
-
let n = await this.host.ensureThreadReady(e), r = this.host.snapshotForRuntime(n), i =
|
|
4710
|
+
let n = await this.host.ensureThreadReady(e), r = this.host.snapshotForRuntime(n), i = zt(r, t), a = n.approvalPreset !== i.approvalPreset || n.selectedModelId !== i.selectedModelId || n.selectedReasoningEffort !== i.selectedReasoningEffort || n.selectedServiceTier !== i.selectedServiceTier || n.planMode !== i.planMode;
|
|
4679
4711
|
if (t.approvalPreset && !r.approvalPresets.includes(t.approvalPreset)) throw Error(`Approval preset '${t.approvalPreset}' is not available`);
|
|
4680
|
-
let o =
|
|
4712
|
+
let o = k(this.host.getState().models, i.selectedModelId);
|
|
4681
4713
|
await this.client.request("thread/settings/update", {
|
|
4682
4714
|
threadId: e,
|
|
4683
|
-
...t.approvalPreset ?
|
|
4715
|
+
...t.approvalPreset ? Ft(t.approvalPreset) : {},
|
|
4684
4716
|
...t.modelId && o ? { model: o.model } : {},
|
|
4685
4717
|
...t.reasoningEffort || t.modelId ? { effort: i.selectedReasoningEffort } : {},
|
|
4686
4718
|
...t.serviceTier !== void 0 || t.modelId ? { serviceTier: i.selectedServiceTier } : {},
|
|
4687
|
-
...o && (typeof t.planMode == "boolean" || t.modelId || t.reasoningEffort) ? { collaborationMode:
|
|
4719
|
+
...o && (typeof t.planMode == "boolean" || t.modelId || t.reasoningEffort) ? { collaborationMode: Bt(i.planMode, o.model, i.selectedReasoningEffort) } : {}
|
|
4688
4720
|
}), this.host.patchRuntime(e, i), a && this.host.emitConversationSettings(e, "action");
|
|
4689
4721
|
}
|
|
4690
4722
|
async setGoal(e, t) {
|
|
@@ -4703,7 +4735,7 @@ var Oi = class {
|
|
|
4703
4735
|
...n === void 0 ? {} : { tokenBudget: n }
|
|
4704
4736
|
});
|
|
4705
4737
|
if (a.goal.threadId !== e) throw Error(`Codex thread/goal/set returned a goal for '${a.goal.threadId}' instead of '${e}'`);
|
|
4706
|
-
let o = !
|
|
4738
|
+
let o = !Gr(r.goal, a.goal);
|
|
4707
4739
|
this.host.patchRuntime(e, { goal: { ...a.goal } }), o && this.host.emitEvent("action", {
|
|
4708
4740
|
type: "conversation.goalChanged",
|
|
4709
4741
|
conversationId: e,
|
|
@@ -4725,7 +4757,7 @@ var Oi = class {
|
|
|
4725
4757
|
payload: { goal: null }
|
|
4726
4758
|
});
|
|
4727
4759
|
}
|
|
4728
|
-
},
|
|
4760
|
+
}, Mi = "Review the current code changes (staged, unstaged, and untracked files) and provide prioritized findings.", Ni = class {
|
|
4729
4761
|
client;
|
|
4730
4762
|
host;
|
|
4731
4763
|
constructor(e, t) {
|
|
@@ -4762,22 +4794,22 @@ var Oi = class {
|
|
|
4762
4794
|
if (i.reviewThreadId !== e) throw Error(`Codex review/start returned unexpected review thread '${i.reviewThreadId}' for inline review on thread '${e}'`);
|
|
4763
4795
|
let a = n.turnIds.includes(i.turn.id);
|
|
4764
4796
|
n.activeTurnId = i.turn.status === "inProgress" ? i.turn.id : null, n.turnIds.includes(i.turn.id) || n.turnIds.push(i.turn.id), this.host.patchConversationTurnCount(e, n.turnIds.length, "action");
|
|
4765
|
-
let o =
|
|
4797
|
+
let o = mr(e, i.turn).filter((e) => !n.messages.some((t) => t.id === e.id)).map((e) => e.role === "user" ? {
|
|
4766
4798
|
...e,
|
|
4767
4799
|
parts: r.type === "uncommittedChanges" ? e.parts.map((e) => e.type === "text" && e.text === "current changes" ? {
|
|
4768
4800
|
...e,
|
|
4769
|
-
text:
|
|
4801
|
+
text: Mi
|
|
4770
4802
|
} : e) : e.parts,
|
|
4771
4803
|
metadata: {
|
|
4772
4804
|
...e.metadata,
|
|
4773
4805
|
reviewPrompt: !0
|
|
4774
4806
|
}
|
|
4775
|
-
} : e), s =
|
|
4807
|
+
} : e), s = Pi(n.messages, i.turn.id, o);
|
|
4776
4808
|
this.host.patchRuntime(e, {
|
|
4777
4809
|
busy: n.activeTurnId !== null,
|
|
4778
4810
|
turnStartPending: !1,
|
|
4779
|
-
turns:
|
|
4780
|
-
messages: n.activeTurnId ?
|
|
4811
|
+
turns: Q(n.turns, Z(i.turn)),
|
|
4812
|
+
messages: n.activeTurnId ? U(s, e, i.turn.id) : s
|
|
4781
4813
|
});
|
|
4782
4814
|
for (let t of o) this.host.emitEvent("action", {
|
|
4783
4815
|
type: "message.appended",
|
|
@@ -4789,7 +4821,7 @@ var Oi = class {
|
|
|
4789
4821
|
type: "turn.started",
|
|
4790
4822
|
conversationId: e,
|
|
4791
4823
|
turnId: i.turn.id,
|
|
4792
|
-
payload: { startedAt:
|
|
4824
|
+
payload: { startedAt: X(i.turn.startedAt) }
|
|
4793
4825
|
}), this.host.emitConversationActivity(e, "action");
|
|
4794
4826
|
} catch (t) {
|
|
4795
4827
|
throw this.host.patchRuntime(e, {
|
|
@@ -4822,11 +4854,11 @@ var Oi = class {
|
|
|
4822
4854
|
return await this.editTurnForThread(n, e, t), this.host.getSnapshot();
|
|
4823
4855
|
}
|
|
4824
4856
|
async editTurnForThread(e, t, n) {
|
|
4825
|
-
let r = (await this.host.ensureThreadReady(e)).messages.find((e) => e.role === "user" && e.kind !== "steer" &&
|
|
4857
|
+
let r = (await this.host.ensureThreadReady(e)).messages.find((e) => e.role === "user" && e.kind !== "steer" && qt(e) === t);
|
|
4826
4858
|
if (!r) throw Error(`Could not find the user prompt for Codex turn '${t}'`);
|
|
4827
4859
|
let i = n.trim();
|
|
4828
4860
|
if (!i) throw Error("Cannot replace a turn prompt with empty content");
|
|
4829
|
-
let a =
|
|
4861
|
+
let a = Yt(r);
|
|
4830
4862
|
await this.rollbackToTurn(e, t), await this.host.sendMessageToThread(e, i, a.length > 0 ? { attachments: a } : {});
|
|
4831
4863
|
}
|
|
4832
4864
|
async retryTurn(e) {
|
|
@@ -4834,11 +4866,11 @@ var Oi = class {
|
|
|
4834
4866
|
return await this.retryTurnForThread(t, e), this.host.getSnapshot();
|
|
4835
4867
|
}
|
|
4836
4868
|
async retryTurnForThread(e, t) {
|
|
4837
|
-
let n = (await this.host.ensureThreadReady(e)).messages.find((e) => e.role === "user" && e.kind !== "steer" &&
|
|
4869
|
+
let n = (await this.host.ensureThreadReady(e)).messages.find((e) => e.role === "user" && e.kind !== "steer" && qt(e) === t);
|
|
4838
4870
|
if (!n) throw Error("Could not find the user prompt for this turn");
|
|
4839
|
-
let r =
|
|
4871
|
+
let r = Jt(n);
|
|
4840
4872
|
if (!r) throw Error("Could not find the user prompt for this turn");
|
|
4841
|
-
let i =
|
|
4873
|
+
let i = Yt(n);
|
|
4842
4874
|
await this.rollbackToTurn(e, t), await this.host.sendMessageToThread(e, r, i.length > 0 ? { attachments: i } : {});
|
|
4843
4875
|
}
|
|
4844
4876
|
async rollbackToTurn(e, t) {
|
|
@@ -4855,10 +4887,10 @@ var Oi = class {
|
|
|
4855
4887
|
numTurns: n.turnIds.length - r
|
|
4856
4888
|
});
|
|
4857
4889
|
if (i.thread.id !== e) throw Error(`Codex thread/rollback returned '${i.thread.id}' for requested thread '${e}'`);
|
|
4858
|
-
n.turnIds = i.thread.turns.map((e) => e.id), n.turns = i.thread.turns.map((e) =>
|
|
4859
|
-
let a =
|
|
4860
|
-
this.host.patch({ conversations:
|
|
4861
|
-
messages:
|
|
4890
|
+
n.turnIds = i.thread.turns.map((e) => e.id), n.turns = i.thread.turns.map((e) => Z(e)), n.activeTurnId = null;
|
|
4891
|
+
let a = N(i.thread);
|
|
4892
|
+
this.host.patch({ conversations: P(this.host.getState().conversations, a) }), this.host.patchRuntime(e, {
|
|
4893
|
+
messages: fr(i.thread),
|
|
4862
4894
|
answeredClientRequestIds: [],
|
|
4863
4895
|
busy: !1,
|
|
4864
4896
|
turnStartPending: !1,
|
|
@@ -4874,15 +4906,15 @@ var Oi = class {
|
|
|
4874
4906
|
});
|
|
4875
4907
|
if (i.thread.id !== e) throw Error(`Codex thread/revert returned '${i.thread.id}' for requested thread '${e}'`);
|
|
4876
4908
|
let a = r.turnIds.slice(0, n), o = new Set(a), s = r.messages.filter((e) => {
|
|
4877
|
-
let t =
|
|
4909
|
+
let t = qt(e);
|
|
4878
4910
|
return t === null || o.has(t);
|
|
4879
4911
|
});
|
|
4880
4912
|
r.turnIds = a, r.turns = r.turns.filter((e) => o.has(e.id)), r.activeTurnId = null;
|
|
4881
4913
|
let c = {
|
|
4882
|
-
...
|
|
4914
|
+
...N(i.thread),
|
|
4883
4915
|
turnCount: a.length
|
|
4884
4916
|
};
|
|
4885
|
-
this.host.patch({ conversations:
|
|
4917
|
+
this.host.patch({ conversations: P(this.host.getState().conversations, c) }), this.host.patchRuntime(e, {
|
|
4886
4918
|
messages: s,
|
|
4887
4919
|
answeredClientRequestIds: [],
|
|
4888
4920
|
busy: !1,
|
|
@@ -4901,7 +4933,7 @@ var Oi = class {
|
|
|
4901
4933
|
return e;
|
|
4902
4934
|
}
|
|
4903
4935
|
};
|
|
4904
|
-
function
|
|
4936
|
+
function Pi(e, t, n) {
|
|
4905
4937
|
let r = e.findIndex((e) => e.turnId === t);
|
|
4906
4938
|
return r < 0 ? [...e, ...n] : [
|
|
4907
4939
|
...e.slice(0, r),
|
|
@@ -4911,7 +4943,7 @@ function ji(e, t, n) {
|
|
|
4911
4943
|
}
|
|
4912
4944
|
//#endregion
|
|
4913
4945
|
//#region src/node/codex-surface-messages-controller.ts
|
|
4914
|
-
var
|
|
4946
|
+
var Fi = class {
|
|
4915
4947
|
client;
|
|
4916
4948
|
host;
|
|
4917
4949
|
constructor(e, t) {
|
|
@@ -4967,7 +4999,7 @@ var Mi = class {
|
|
|
4967
4999
|
let s = et(i);
|
|
4968
5000
|
if (s) return this.host.startReviewForThread(e, { target: s });
|
|
4969
5001
|
n = {
|
|
4970
|
-
...
|
|
5002
|
+
...Ut(this.host.snapshotForRuntime(r), n),
|
|
4971
5003
|
...n.skills ? { skills: rt(n.skills, r.skills) } : {}
|
|
4972
5004
|
}, await this.sendPromptToThread(e, i, n);
|
|
4973
5005
|
}
|
|
@@ -4991,20 +5023,20 @@ var Mi = class {
|
|
|
4991
5023
|
let n = await this.client.request("turn/start", {
|
|
4992
5024
|
threadId: e,
|
|
4993
5025
|
input: [],
|
|
4994
|
-
...
|
|
5026
|
+
...Vt(this.host.snapshotForRuntime(t), {})
|
|
4995
5027
|
}), r = t.turnIds.includes(n.turn.id);
|
|
4996
5028
|
t.activeTurnId = n.turn.status === "inProgress" ? n.turn.id : null, r || t.turnIds.push(n.turn.id), this.host.patchConversationTurnCount(e, t.turnIds.length, "action");
|
|
4997
5029
|
let i = n.turn.status === "inProgress";
|
|
4998
5030
|
this.host.patchRuntime(e, {
|
|
4999
5031
|
busy: i,
|
|
5000
5032
|
turnStartPending: !1,
|
|
5001
|
-
turns:
|
|
5002
|
-
messages: i ?
|
|
5033
|
+
turns: Q(t.turns, Z(n.turn)),
|
|
5034
|
+
messages: i ? U(t.messages, e, n.turn.id) : t.messages
|
|
5003
5035
|
}), this.host.patchConversationStatus(e, i ? "active" : "idle", "action"), i && !r && this.host.emitEvent("action", {
|
|
5004
5036
|
type: "turn.started",
|
|
5005
5037
|
conversationId: e,
|
|
5006
5038
|
turnId: n.turn.id,
|
|
5007
|
-
payload: { startedAt:
|
|
5039
|
+
payload: { startedAt: X(n.turn.startedAt) }
|
|
5008
5040
|
}), this.host.emitConversationActivity(e, "action");
|
|
5009
5041
|
} catch (t) {
|
|
5010
5042
|
throw this.host.patchRuntime(e, {
|
|
@@ -5015,23 +5047,23 @@ var Mi = class {
|
|
|
5015
5047
|
}
|
|
5016
5048
|
}
|
|
5017
5049
|
async sendPromptToThread(e, t, n = {}, r) {
|
|
5018
|
-
let i = this.host.requireRuntime(e), a =
|
|
5050
|
+
let i = this.host.requireRuntime(e), a = Ut(this.host.snapshotForRuntime(i), n), o = r?.trim() || t, s = it(nt(t, i.skills), rt(a.skills ?? [], i.skills)), c = Wt(a.attachments ?? []);
|
|
5019
5051
|
if (i.busy) {
|
|
5020
5052
|
this.host.patchRuntime(e, { queuedPrompts: [...i.queuedPrompts, {
|
|
5021
|
-
id:
|
|
5053
|
+
id: qr(),
|
|
5022
5054
|
text: o,
|
|
5023
5055
|
...Object.keys(a).length > 0 ? { options: a } : {}
|
|
5024
5056
|
}] }), this.emitQueuedPrompts(e);
|
|
5025
5057
|
return;
|
|
5026
5058
|
}
|
|
5027
|
-
let l =
|
|
5059
|
+
let l = Kr(), u = {
|
|
5028
5060
|
id: l,
|
|
5029
5061
|
role: "user",
|
|
5030
5062
|
status: "complete",
|
|
5031
5063
|
parts: [{
|
|
5032
5064
|
type: "text",
|
|
5033
5065
|
text: o
|
|
5034
|
-
}, ...c.map(
|
|
5066
|
+
}, ...c.map(Kt)],
|
|
5035
5067
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5036
5068
|
metadata: {
|
|
5037
5069
|
conversationId: e,
|
|
@@ -5058,14 +5090,14 @@ var Mi = class {
|
|
|
5058
5090
|
text: t,
|
|
5059
5091
|
text_elements: []
|
|
5060
5092
|
},
|
|
5061
|
-
...c.map(
|
|
5093
|
+
...c.map(Gt),
|
|
5062
5094
|
...s.map((e) => ({
|
|
5063
5095
|
type: "skill",
|
|
5064
5096
|
name: e.name,
|
|
5065
5097
|
path: e.path
|
|
5066
5098
|
}))
|
|
5067
5099
|
],
|
|
5068
|
-
...
|
|
5100
|
+
...Vt(this.host.snapshotForRuntime(i), a),
|
|
5069
5101
|
...a.outputSchema === void 0 ? {} : { outputSchema: a.outputSchema }
|
|
5070
5102
|
}), r = i.turnIds.includes(n.turn.id);
|
|
5071
5103
|
i.activeTurnId = n.turn.status === "inProgress" ? n.turn.id : null, i.turnIds.includes(n.turn.id) || i.turnIds.push(n.turn.id), this.host.patchConversationTurnCount(e, i.turnIds.length, "action");
|
|
@@ -5080,8 +5112,8 @@ var Mi = class {
|
|
|
5080
5112
|
this.host.patchRuntime(e, {
|
|
5081
5113
|
busy: o,
|
|
5082
5114
|
turnStartPending: !1,
|
|
5083
|
-
turns:
|
|
5084
|
-
messages: o ?
|
|
5115
|
+
turns: Q(i.turns, Z(n.turn)),
|
|
5116
|
+
messages: o ? U(u, e, n.turn.id) : u
|
|
5085
5117
|
}), this.host.patchConversationStatus(e, o ? "active" : "idle", "action");
|
|
5086
5118
|
let d = u.find((e) => e.id === l);
|
|
5087
5119
|
d && this.host.emitEvent("action", {
|
|
@@ -5093,7 +5125,7 @@ var Mi = class {
|
|
|
5093
5125
|
type: "turn.started",
|
|
5094
5126
|
conversationId: e,
|
|
5095
5127
|
turnId: n.turn.id,
|
|
5096
|
-
payload: { startedAt:
|
|
5128
|
+
payload: { startedAt: X(n.turn.startedAt) }
|
|
5097
5129
|
}), this.host.emitConversationActivity(e, "action");
|
|
5098
5130
|
} catch (t) {
|
|
5099
5131
|
throw this.host.patchRuntime(e, {
|
|
@@ -5111,7 +5143,7 @@ var Mi = class {
|
|
|
5111
5143
|
let i = await this.host.ensureThreadReady(e), a = t.trim(), o = r?.trim() || a;
|
|
5112
5144
|
if (!a) throw Error("Cannot steer with an empty message");
|
|
5113
5145
|
if (!i.activeTurnId) throw Error("There is no active turn to steer");
|
|
5114
|
-
let s =
|
|
5146
|
+
let s = Wt(n.attachments ?? []), c = Kr(), l = {
|
|
5115
5147
|
id: c,
|
|
5116
5148
|
kind: "steer",
|
|
5117
5149
|
role: "user",
|
|
@@ -5119,7 +5151,7 @@ var Mi = class {
|
|
|
5119
5151
|
parts: [{
|
|
5120
5152
|
type: "text",
|
|
5121
5153
|
text: o
|
|
5122
|
-
}, ...s.map(
|
|
5154
|
+
}, ...s.map(Kt)],
|
|
5123
5155
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5124
5156
|
turnId: i.activeTurnId,
|
|
5125
5157
|
metadata: {
|
|
@@ -5130,7 +5162,7 @@ var Mi = class {
|
|
|
5130
5162
|
};
|
|
5131
5163
|
this.host.patchRuntime(e, {
|
|
5132
5164
|
error: null,
|
|
5133
|
-
messages:
|
|
5165
|
+
messages: U([...i.messages, l], e, i.activeTurnId, { forceSegment: !0 })
|
|
5134
5166
|
}), this.host.emitEvent("action", {
|
|
5135
5167
|
type: "message.appended",
|
|
5136
5168
|
conversationId: e,
|
|
@@ -5146,9 +5178,9 @@ var Mi = class {
|
|
|
5146
5178
|
type: "text",
|
|
5147
5179
|
text: a,
|
|
5148
5180
|
text_elements: []
|
|
5149
|
-
}, ...s.map(
|
|
5181
|
+
}, ...s.map(Gt)]
|
|
5150
5182
|
}), n = i.turnIds.includes(t.turnId);
|
|
5151
|
-
i.activeTurnId = t.turnId, i.turnIds.includes(t.turnId) || i.turnIds.push(t.turnId), i.turns =
|
|
5183
|
+
i.activeTurnId = t.turnId, i.turnIds.includes(t.turnId) || i.turnIds.push(t.turnId), i.turns = Q(i.turns, {
|
|
5152
5184
|
id: t.turnId,
|
|
5153
5185
|
status: "inProgress",
|
|
5154
5186
|
error: null,
|
|
@@ -5165,7 +5197,7 @@ var Mi = class {
|
|
|
5165
5197
|
turnId: t.turnId
|
|
5166
5198
|
}
|
|
5167
5199
|
} : e);
|
|
5168
|
-
this.host.patchRuntime(e, { messages:
|
|
5200
|
+
this.host.patchRuntime(e, { messages: G(U(r, e, t.turnId), e) }), n || this.host.emitEvent("action", {
|
|
5169
5201
|
type: "turn.started",
|
|
5170
5202
|
conversationId: e,
|
|
5171
5203
|
turnId: t.turnId,
|
|
@@ -5243,7 +5275,7 @@ var Mi = class {
|
|
|
5243
5275
|
if (!e) throw Error("There is no active conversation");
|
|
5244
5276
|
return e;
|
|
5245
5277
|
}
|
|
5246
|
-
},
|
|
5278
|
+
}, Ii = 5, Li = class {
|
|
5247
5279
|
client;
|
|
5248
5280
|
options;
|
|
5249
5281
|
catalog;
|
|
@@ -5281,9 +5313,9 @@ var Mi = class {
|
|
|
5281
5313
|
let i = this.host.getState(), a = e.approvalPreset ?? (e.approvalMode === void 0 && e.permissionMode === void 0 && i.approvalPreset && r.approvalPresets.includes(i.approvalPreset) ? i.approvalPreset : void 0), o = this.settings.threadStartSettings({
|
|
5282
5314
|
...e,
|
|
5283
5315
|
...a ? { approvalPreset: a } : {}
|
|
5284
|
-
}, r.approvalPresets), s =
|
|
5285
|
-
|
|
5286
|
-
let f = t.mcpServers === void 0 ? this.extensions.defaultMcpServers :
|
|
5316
|
+
}, r.approvalPresets), s = k(i.models, i.selectedModelId), c = e.model ? At(i.models, e.model) : s, l = c?.model, u = e.reasoningEffort ?? (c?.id === s?.id ? i.selectedReasoningEffort : c ? A(c) : null) ?? void 0, d = e.serviceTier === void 0 ? c?.id === s?.id ? i.selectedServiceTier ?? null : c?.defaultServiceTier ?? null : e.serviceTier;
|
|
5317
|
+
jt(c, u), j(c, d);
|
|
5318
|
+
let f = t.mcpServers === void 0 ? this.extensions.defaultMcpServers : vi(t.mcpServers), p = await this.extensions.conversationExtension({
|
|
5287
5319
|
operation: "start",
|
|
5288
5320
|
conversationId: null,
|
|
5289
5321
|
cwd: n,
|
|
@@ -5300,11 +5332,11 @@ var Mi = class {
|
|
|
5300
5332
|
...d === void 0 ? {} : { serviceTier: d },
|
|
5301
5333
|
...e.threadSource === void 0 ? {} : { threadSource: e.threadSource },
|
|
5302
5334
|
serviceName: "codex_app_sdk"
|
|
5303
|
-
}), h =
|
|
5335
|
+
}), h = Lt(m, i.models, i);
|
|
5304
5336
|
u && (await this.client.request("thread/settings/update", {
|
|
5305
5337
|
threadId: m.thread.id,
|
|
5306
5338
|
effort: u,
|
|
5307
|
-
...c ? { collaborationMode:
|
|
5339
|
+
...c ? { collaborationMode: Bt(i.planMode, c.model, u) } : {}
|
|
5308
5340
|
}), h.selectedReasoningEffort = u), d !== void 0 && (h.selectedServiceTier = d), c && (h.selectedModelId = c.id), a && (h.approvalPreset = a);
|
|
5309
5341
|
let g = this.host.createRuntime(m.thread.id, {
|
|
5310
5342
|
hydrated: !0,
|
|
@@ -5314,7 +5346,7 @@ var Mi = class {
|
|
|
5314
5346
|
turnIds: [],
|
|
5315
5347
|
messages: [],
|
|
5316
5348
|
answeredClientRequestIds: [],
|
|
5317
|
-
threadStatus:
|
|
5349
|
+
threadStatus: F(m.thread.status),
|
|
5318
5350
|
...r,
|
|
5319
5351
|
...h
|
|
5320
5352
|
});
|
|
@@ -5323,10 +5355,10 @@ var Mi = class {
|
|
|
5323
5355
|
...t,
|
|
5324
5356
|
mcpServers: f
|
|
5325
5357
|
});
|
|
5326
|
-
let _ =
|
|
5358
|
+
let _ = N(m.thread);
|
|
5327
5359
|
return this.host.patch({
|
|
5328
5360
|
activeConversationId: m.thread.id,
|
|
5329
|
-
conversations:
|
|
5361
|
+
conversations: P(i.conversations, _),
|
|
5330
5362
|
...this.host.runtimeProjection(g)
|
|
5331
5363
|
}), this.host.emitSummaryUpserted(_, "created", "action"), this.host.emitSelected(m.thread.id), this.emitConversationState(m.thread.id), this.host.getSnapshot();
|
|
5332
5364
|
}
|
|
@@ -5376,13 +5408,13 @@ var Mi = class {
|
|
|
5376
5408
|
historyLoadingOlder: !1,
|
|
5377
5409
|
fullHistoryHydrated: !0,
|
|
5378
5410
|
busy: !!n.activeTurnId,
|
|
5379
|
-
threadStatus:
|
|
5411
|
+
threadStatus: F(t.thread.status)
|
|
5380
5412
|
}), i = {
|
|
5381
|
-
...
|
|
5413
|
+
...N(t.thread),
|
|
5382
5414
|
turnCount: r.turnIds.length
|
|
5383
5415
|
}, a = this.host.getState();
|
|
5384
5416
|
return this.host.patch({
|
|
5385
|
-
conversations:
|
|
5417
|
+
conversations: P(a.conversations, i),
|
|
5386
5418
|
...a.activeConversationId === e ? this.host.runtimeProjection(r) : {}
|
|
5387
5419
|
}), this.host.emitSummaryUpserted(i, "updated", "action"), this.host.emitHistoryReplaced(e, "resync", "action"), this.host.emitConversationActivity(e, "action"), this.historySnapshot(e, r);
|
|
5388
5420
|
} catch (t) {
|
|
@@ -5398,7 +5430,7 @@ var Mi = class {
|
|
|
5398
5430
|
...n
|
|
5399
5431
|
}, a = {
|
|
5400
5432
|
...i,
|
|
5401
|
-
mcpServers: i.mcpServers === void 0 ? this.extensions.defaultMcpServers :
|
|
5433
|
+
mcpServers: i.mcpServers === void 0 ? this.extensions.defaultMcpServers : vi(i.mcpServers)
|
|
5402
5434
|
};
|
|
5403
5435
|
this.hostOptionsByThread.set(e, a);
|
|
5404
5436
|
let o = await this.extensions.conversationExtension({
|
|
@@ -5416,7 +5448,7 @@ var Mi = class {
|
|
|
5416
5448
|
threadId: e,
|
|
5417
5449
|
excludeTurns: !0,
|
|
5418
5450
|
initialTurnsPage: {
|
|
5419
|
-
limit:
|
|
5451
|
+
limit: Ii,
|
|
5420
5452
|
sortDirection: "desc",
|
|
5421
5453
|
itemsView: "full"
|
|
5422
5454
|
},
|
|
@@ -5429,20 +5461,20 @@ var Mi = class {
|
|
|
5429
5461
|
let i = t.initialTurnsPage ?? await this.client.request("thread/turns/list", {
|
|
5430
5462
|
threadId: t.thread.id,
|
|
5431
5463
|
cursor: null,
|
|
5432
|
-
limit:
|
|
5464
|
+
limit: Ii,
|
|
5433
5465
|
sortDirection: "desc",
|
|
5434
5466
|
itemsView: "full"
|
|
5435
|
-
}), d = [...i.data].reverse(), f = t.cwd ?? t.thread.cwd ?? a.cwd, p = await this.catalog.loadConversationCatalogs(f), m = s.turns.filter((e) => c.get(e.id) !== e), h = s.threadStatus !== u && s.threadStatus ? s.threadStatus :
|
|
5467
|
+
}), d = [...i.data].reverse(), f = t.cwd ?? t.thread.cwd ?? a.cwd, p = await this.catalog.loadConversationCatalogs(f), m = s.turns.filter((e) => c.get(e.id) !== e), h = s.threadStatus !== u && s.threadStatus ? s.threadStatus : F(t.thread.status), g = d.map((e) => h.type === "idle" && e.status === "inProgress" ? {
|
|
5436
5468
|
...e,
|
|
5437
5469
|
status: "interrupted"
|
|
5438
|
-
} : e), _ = new Map(g.map((e) => [e.id,
|
|
5470
|
+
} : e), _ = new Map(g.map((e) => [e.id, Z(e)]));
|
|
5439
5471
|
for (let e of m) _.set(e.id, e);
|
|
5440
|
-
let v = m.length > 0 ? s.activeTurnId : h.type === "active" ?
|
|
5472
|
+
let v = m.length > 0 ? s.activeTurnId : h.type === "active" ? Jn(d) : null, y = pr(s.messages, fr({
|
|
5441
5473
|
...t.thread,
|
|
5442
5474
|
turns: g
|
|
5443
5475
|
})), b = new Map(y.map((e) => [e.id, e]));
|
|
5444
5476
|
for (let e of s.messages) l.get(e.id) !== e && b.set(e.id, e);
|
|
5445
|
-
let x = v ?
|
|
5477
|
+
let x = v ? U([...b.values()], t.thread.id, v) : [...b.values()], S = this.host.createRuntime(t.thread.id, {
|
|
5446
5478
|
hydrated: !0,
|
|
5447
5479
|
historyMode: t.thread.historyMode ?? "legacy",
|
|
5448
5480
|
loadingStrategy: a.loadingStrategy ?? this.options.loadingStrategy ?? "lazy",
|
|
@@ -5460,13 +5492,13 @@ var Mi = class {
|
|
|
5460
5492
|
goal: n ? { ...n } : null,
|
|
5461
5493
|
threadStatus: h,
|
|
5462
5494
|
...p,
|
|
5463
|
-
...
|
|
5495
|
+
...Lt(t, this.host.getState().models, this.host.snapshotForRuntime(s))
|
|
5464
5496
|
}), C = {
|
|
5465
|
-
...
|
|
5497
|
+
...N(t.thread),
|
|
5466
5498
|
turnCount: d.length
|
|
5467
5499
|
}, ee = this.host.getState();
|
|
5468
5500
|
return this.host.patch({
|
|
5469
|
-
conversations:
|
|
5501
|
+
conversations: P(ee.conversations, C),
|
|
5470
5502
|
...ee.activeConversationId === t.thread.id ? this.host.runtimeProjection(S) : {}
|
|
5471
5503
|
}), this.host.emitSummaryUpserted(C, "resumed", "action"), this.host.emitHistoryReplaced(t.thread.id, r, "action"), this.emitConversationState(t.thread.id), S.loadingStrategy === "eager" && i.nextCursor !== null && this.conversations.hydrateCompleteHistory(t.thread.id, {
|
|
5472
5504
|
cursor: i.nextCursor,
|
|
@@ -5489,7 +5521,7 @@ var Mi = class {
|
|
|
5489
5521
|
threadStatus: structuredClone(t.threadStatus)
|
|
5490
5522
|
};
|
|
5491
5523
|
}
|
|
5492
|
-
},
|
|
5524
|
+
}, Ri = class {
|
|
5493
5525
|
authentication;
|
|
5494
5526
|
approvals;
|
|
5495
5527
|
catalog;
|
|
@@ -5505,16 +5537,16 @@ var Mi = class {
|
|
|
5505
5537
|
case "thread/started": {
|
|
5506
5538
|
this.host.createRuntime(e.params.thread.id, {
|
|
5507
5539
|
historyMode: e.params.thread.historyMode ?? "legacy",
|
|
5508
|
-
threadStatus:
|
|
5540
|
+
threadStatus: F(e.params.thread.status)
|
|
5509
5541
|
});
|
|
5510
|
-
let t =
|
|
5511
|
-
this.host.patch({ conversations:
|
|
5542
|
+
let t = N(e.params.thread);
|
|
5543
|
+
this.host.patch({ conversations: P(this.host.getState().conversations, t) }), this.host.emitSummaryUpserted(t, "started", "notification"), this.host.emitConversationActivity(e.params.thread.id, "notification");
|
|
5512
5544
|
return;
|
|
5513
5545
|
}
|
|
5514
5546
|
case "thread/status/changed": {
|
|
5515
5547
|
let { threadId: t, status: n } = e.params, r = this.host.requireRuntime(t), i = n.type === "systemError";
|
|
5516
5548
|
(i || n.type === "idle" && !r.turnStartPending) && (r.activeTurnId = null), this.host.patchRuntime(t, {
|
|
5517
|
-
threadStatus:
|
|
5549
|
+
threadStatus: F(n),
|
|
5518
5550
|
busy: i ? !1 : r.turnStartPending || n.type === "active" || r.activeTurnId !== null,
|
|
5519
5551
|
...i ? {
|
|
5520
5552
|
turnStartPending: !1,
|
|
@@ -5524,7 +5556,7 @@ var Mi = class {
|
|
|
5524
5556
|
let a = this.host.getState();
|
|
5525
5557
|
this.host.patch({ conversations: a.conversations.map((e) => e.id === t ? {
|
|
5526
5558
|
...e,
|
|
5527
|
-
status:
|
|
5559
|
+
status: Qt(n)
|
|
5528
5560
|
} : e) });
|
|
5529
5561
|
let o = this.host.getState().conversations.find((e) => e.id === t);
|
|
5530
5562
|
o && this.host.emitSummaryUpserted(o, "updated", "notification"), this.host.emitConversationActivity(t, "notification"), n.type === "idle" && this.host.sendNextQueuedPrompt(t);
|
|
@@ -5566,12 +5598,12 @@ var Mi = class {
|
|
|
5566
5598
|
return;
|
|
5567
5599
|
}
|
|
5568
5600
|
case "thread/settings/updated": {
|
|
5569
|
-
let t = this.host.requireRuntime(e.params.threadId), n = this.host.getState(), r =
|
|
5601
|
+
let t = this.host.requireRuntime(e.params.threadId), n = this.host.getState(), r = Rt(e.params.threadSettings, n.models, this.host.snapshotForRuntime(t)), i = t.approvalPreset !== r.approvalPreset || t.selectedModelId !== r.selectedModelId || t.selectedReasoningEffort !== r.selectedReasoningEffort || t.selectedServiceTier !== r.selectedServiceTier || t.planMode !== r.planMode;
|
|
5570
5602
|
this.host.patchRuntime(e.params.threadId, r), i && this.host.emitConversationSettings(e.params.threadId, "notification");
|
|
5571
5603
|
return;
|
|
5572
5604
|
}
|
|
5573
5605
|
case "thread/goal/updated":
|
|
5574
|
-
if (
|
|
5606
|
+
if (Gr(this.host.requireRuntime(e.params.threadId).goal, e.params.goal)) return;
|
|
5575
5607
|
this.host.patchRuntime(e.params.threadId, { goal: { ...e.params.goal } }), this.host.emitEvent("notification", {
|
|
5576
5608
|
type: "conversation.goalChanged",
|
|
5577
5609
|
conversationId: e.params.threadId,
|
|
@@ -5588,15 +5620,38 @@ var Mi = class {
|
|
|
5588
5620
|
});
|
|
5589
5621
|
return;
|
|
5590
5622
|
case "thread/tokenUsage/updated": {
|
|
5591
|
-
let t =
|
|
5623
|
+
let t = Zt(e.params.tokenUsage);
|
|
5592
5624
|
this.host.patchRuntime(e.params.threadId, { contextUsage: t }), this.host.emitEvent("notification", {
|
|
5593
5625
|
type: "conversation.contextUsageChanged",
|
|
5594
5626
|
conversationId: e.params.threadId,
|
|
5595
5627
|
turnId: e.params.turnId,
|
|
5596
5628
|
payload: { contextUsage: structuredClone(t) }
|
|
5629
|
+
}), this.host.emitEvent("notification", {
|
|
5630
|
+
type: "conversation.executionUsageChanged",
|
|
5631
|
+
conversationId: e.params.threadId,
|
|
5632
|
+
turnId: e.params.turnId,
|
|
5633
|
+
payload: { usage: {
|
|
5634
|
+
last: Xt(e.params.tokenUsage.last),
|
|
5635
|
+
total: Xt(e.params.tokenUsage.total),
|
|
5636
|
+
execution: null,
|
|
5637
|
+
model: null,
|
|
5638
|
+
observedStart: !1
|
|
5639
|
+
} }
|
|
5597
5640
|
});
|
|
5598
5641
|
return;
|
|
5599
5642
|
}
|
|
5643
|
+
case "model/rerouted":
|
|
5644
|
+
this.host.emitEvent("notification", {
|
|
5645
|
+
type: "turn.modelRerouted",
|
|
5646
|
+
conversationId: e.params.threadId,
|
|
5647
|
+
turnId: e.params.turnId,
|
|
5648
|
+
payload: {
|
|
5649
|
+
fromModel: e.params.fromModel,
|
|
5650
|
+
toModel: e.params.toModel,
|
|
5651
|
+
reason: e.params.reason
|
|
5652
|
+
}
|
|
5653
|
+
});
|
|
5654
|
+
return;
|
|
5600
5655
|
case "turn/started": {
|
|
5601
5656
|
let t = this.host.requireRuntime(e.params.threadId), n = t.activeTurnId === e.params.turn.id;
|
|
5602
5657
|
this.host.markRuntimeTurnActive(t, e.params.turn.id), this.host.patchConversationTurnCount(e.params.threadId, t.turnIds.length), this.host.patchRuntime(e.params.threadId, {
|
|
@@ -5604,13 +5659,13 @@ var Mi = class {
|
|
|
5604
5659
|
turnStartPending: !1,
|
|
5605
5660
|
error: null,
|
|
5606
5661
|
turnGitDiff: null,
|
|
5607
|
-
turns:
|
|
5608
|
-
messages:
|
|
5662
|
+
turns: Q(t.turns, Z(e.params.turn)),
|
|
5663
|
+
messages: U(t.messages, e.params.threadId, e.params.turn.id, { createdAt: X(e.params.turn.startedAt) })
|
|
5609
5664
|
}), this.host.patchConversationStatus(e.params.threadId, "active"), n || this.host.emitEvent("notification", {
|
|
5610
5665
|
type: "turn.started",
|
|
5611
5666
|
conversationId: e.params.threadId,
|
|
5612
5667
|
turnId: e.params.turn.id,
|
|
5613
|
-
payload: { startedAt:
|
|
5668
|
+
payload: { startedAt: X(e.params.turn.startedAt) }
|
|
5614
5669
|
}), this.host.emitConversationActivity(e.params.threadId, "notification");
|
|
5615
5670
|
return;
|
|
5616
5671
|
}
|
|
@@ -5626,13 +5681,13 @@ var Mi = class {
|
|
|
5626
5681
|
return;
|
|
5627
5682
|
case "item/commandExecution/outputDelta":
|
|
5628
5683
|
if (!this.items.isForwardingCommandOutput(e.params.threadId, e.params.itemId)) return;
|
|
5629
|
-
this.items.applyToolUpdate(e.params.threadId, e.params.turnId,
|
|
5684
|
+
this.items.applyToolUpdate(e.params.threadId, e.params.turnId, vn(e.params.itemId, e.params.delta));
|
|
5630
5685
|
return;
|
|
5631
5686
|
case "item/fileChange/patchUpdated":
|
|
5632
|
-
this.items.applyToolUpdate(e.params.threadId, e.params.turnId,
|
|
5687
|
+
this.items.applyToolUpdate(e.params.threadId, e.params.turnId, yn(e.params.itemId, e.params.changes));
|
|
5633
5688
|
return;
|
|
5634
5689
|
case "item/mcpToolCall/progress":
|
|
5635
|
-
this.items.applyToolUpdate(e.params.threadId, e.params.turnId,
|
|
5690
|
+
this.items.applyToolUpdate(e.params.threadId, e.params.turnId, bn(e.params.itemId, e.params.message));
|
|
5636
5691
|
return;
|
|
5637
5692
|
case "rawResponseItem/completed":
|
|
5638
5693
|
this.items.applyRawResponseItem(e.params);
|
|
@@ -5646,7 +5701,7 @@ var Mi = class {
|
|
|
5646
5701
|
return;
|
|
5647
5702
|
}
|
|
5648
5703
|
case "turn/diff/updated": {
|
|
5649
|
-
let t =
|
|
5704
|
+
let t = In(e.params.diff);
|
|
5650
5705
|
this.host.patchRuntime(e.params.threadId, { turnGitDiff: {
|
|
5651
5706
|
turnId: e.params.turnId,
|
|
5652
5707
|
addedLines: t.addedLines,
|
|
@@ -5662,7 +5717,7 @@ var Mi = class {
|
|
|
5662
5717
|
}
|
|
5663
5718
|
case "thread/compacted": {
|
|
5664
5719
|
let t = this.host.requireRuntime(e.params.threadId);
|
|
5665
|
-
this.host.patchRuntime(e.params.threadId, { messages:
|
|
5720
|
+
this.host.patchRuntime(e.params.threadId, { messages: ir(t.messages, e.params.threadId, e.params.turnId, "complete") });
|
|
5666
5721
|
let n = this.host.requireRuntime(e.params.threadId).messages.find((t) => t.kind === "compaction" && t.metadata?.turnId === e.params.turnId);
|
|
5667
5722
|
this.host.emitEvent("notification", {
|
|
5668
5723
|
type: "context.compactionCompleted",
|
|
@@ -5682,7 +5737,7 @@ var Mi = class {
|
|
|
5682
5737
|
let t = this.host.requireRuntime(e.params.threadId), n = !e.params.willRetry && t.activeTurnId === e.params.turnId;
|
|
5683
5738
|
n && (t.activeTurnId = null), this.host.patchRuntime(e.params.threadId, {
|
|
5684
5739
|
error: e.params.error.message,
|
|
5685
|
-
turns:
|
|
5740
|
+
turns: Q(t.turns, {
|
|
5686
5741
|
...t.turns.find((t) => t.id === e.params.turnId) ?? {
|
|
5687
5742
|
id: e.params.turnId,
|
|
5688
5743
|
status: "inProgress",
|
|
@@ -5691,7 +5746,7 @@ var Mi = class {
|
|
|
5691
5746
|
durationMs: null
|
|
5692
5747
|
},
|
|
5693
5748
|
status: e.params.willRetry ? "inProgress" : "failed",
|
|
5694
|
-
error:
|
|
5749
|
+
error: Wr(e.params.error),
|
|
5695
5750
|
willRetry: e.params.willRetry
|
|
5696
5751
|
}),
|
|
5697
5752
|
...n ? {
|
|
@@ -5703,7 +5758,7 @@ var Mi = class {
|
|
|
5703
5758
|
conversationId: e.params.threadId,
|
|
5704
5759
|
turnId: e.params.turnId,
|
|
5705
5760
|
payload: {
|
|
5706
|
-
error:
|
|
5761
|
+
error: Wr(e.params.error),
|
|
5707
5762
|
willRetry: e.params.willRetry
|
|
5708
5763
|
}
|
|
5709
5764
|
}), this.host.emitConversationActivity(e.params.threadId, "notification");
|
|
@@ -5711,7 +5766,7 @@ var Mi = class {
|
|
|
5711
5766
|
}
|
|
5712
5767
|
case "account/rateLimits/updated": {
|
|
5713
5768
|
let t = this.host.getState();
|
|
5714
|
-
this.host.patch({ rateLimits:
|
|
5769
|
+
this.host.patch({ rateLimits: rn(t.rateLimits, e.params.rateLimits) }), this.host.emitEvent("notification", {
|
|
5715
5770
|
type: "rateLimits.changed",
|
|
5716
5771
|
payload: { rateLimits: structuredClone(this.host.getState().rateLimits) }
|
|
5717
5772
|
});
|
|
@@ -5824,7 +5879,6 @@ var Mi = class {
|
|
|
5824
5879
|
case "item/reasoning/summaryTextDelta":
|
|
5825
5880
|
case "item/reasoning/summaryPartAdded":
|
|
5826
5881
|
case "item/reasoning/textDelta":
|
|
5827
|
-
case "model/rerouted":
|
|
5828
5882
|
case "model/verification":
|
|
5829
5883
|
case "turn/moderationMetadata":
|
|
5830
5884
|
case "model/safetyBuffering/updated":
|
|
@@ -5850,7 +5904,7 @@ var Mi = class {
|
|
|
5850
5904
|
default: return this.host.unknownNotification(e);
|
|
5851
5905
|
}
|
|
5852
5906
|
}
|
|
5853
|
-
},
|
|
5907
|
+
}, zi = class {
|
|
5854
5908
|
approvals;
|
|
5855
5909
|
clientRequests;
|
|
5856
5910
|
host;
|
|
@@ -5911,7 +5965,7 @@ var Mi = class {
|
|
|
5911
5965
|
conversationId: e,
|
|
5912
5966
|
payload: {
|
|
5913
5967
|
historyLoading: n.historyLoading,
|
|
5914
|
-
historyState:
|
|
5968
|
+
historyState: Hi(n),
|
|
5915
5969
|
error: n.error
|
|
5916
5970
|
}
|
|
5917
5971
|
});
|
|
@@ -6005,7 +6059,7 @@ var Mi = class {
|
|
|
6005
6059
|
reason: t,
|
|
6006
6060
|
messages: structuredClone(r.messages),
|
|
6007
6061
|
threadStatus: structuredClone(r.threadStatus),
|
|
6008
|
-
state:
|
|
6062
|
+
state: Bi(r)
|
|
6009
6063
|
}
|
|
6010
6064
|
});
|
|
6011
6065
|
}
|
|
@@ -6017,7 +6071,7 @@ var Mi = class {
|
|
|
6017
6071
|
conversationId: e,
|
|
6018
6072
|
payload: {
|
|
6019
6073
|
messages: structuredClone(t.map((e) => r.get(e.id) ?? e)),
|
|
6020
|
-
state:
|
|
6074
|
+
state: Vi(this.require(e))
|
|
6021
6075
|
}
|
|
6022
6076
|
});
|
|
6023
6077
|
}
|
|
@@ -6028,7 +6082,7 @@ var Mi = class {
|
|
|
6028
6082
|
return [...this.require(e).messages].reverse().find((e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === t) ?? null;
|
|
6029
6083
|
}
|
|
6030
6084
|
markTurnActive(e, t) {
|
|
6031
|
-
e.activeTurnId = t, e.busy = !0, e.turnStartPending = !1, e.turnIds.includes(t) || e.turnIds.push(t), e.turns =
|
|
6085
|
+
e.activeTurnId = t, e.busy = !0, e.turnStartPending = !1, e.turnIds.includes(t) || e.turnIds.push(t), e.turns = Q(e.turns, {
|
|
6032
6086
|
id: t,
|
|
6033
6087
|
status: "inProgress",
|
|
6034
6088
|
error: null,
|
|
@@ -6059,7 +6113,7 @@ var Mi = class {
|
|
|
6059
6113
|
i && this.emitSummaryUpserted(i, "updated", n);
|
|
6060
6114
|
}
|
|
6061
6115
|
};
|
|
6062
|
-
function
|
|
6116
|
+
function Bi(e) {
|
|
6063
6117
|
return structuredClone({
|
|
6064
6118
|
activeTurnId: e.activeTurnId,
|
|
6065
6119
|
answeredClientRequestIds: e.answeredClientRequestIds,
|
|
@@ -6068,21 +6122,21 @@ function Li(e) {
|
|
|
6068
6122
|
error: e.error,
|
|
6069
6123
|
executionPlan: e.executionPlan,
|
|
6070
6124
|
historyLoading: e.historyLoading,
|
|
6071
|
-
historyState:
|
|
6125
|
+
historyState: Hi(e),
|
|
6072
6126
|
turnGitDiff: e.turnGitDiff,
|
|
6073
6127
|
turnIds: e.turnIds,
|
|
6074
6128
|
turns: e.turns
|
|
6075
6129
|
});
|
|
6076
6130
|
}
|
|
6077
|
-
function
|
|
6131
|
+
function Vi(e) {
|
|
6078
6132
|
return structuredClone({
|
|
6079
6133
|
historyLoading: e.historyLoading,
|
|
6080
|
-
historyState:
|
|
6134
|
+
historyState: Hi(e),
|
|
6081
6135
|
turnIds: e.turnIds,
|
|
6082
6136
|
turns: e.turns
|
|
6083
6137
|
});
|
|
6084
6138
|
}
|
|
6085
|
-
function
|
|
6139
|
+
function Hi(e) {
|
|
6086
6140
|
return {
|
|
6087
6141
|
loadingStrategy: e.loadingStrategy,
|
|
6088
6142
|
hasOlder: e.historyHasOlder,
|
|
@@ -6092,7 +6146,7 @@ function zi(e) {
|
|
|
6092
6146
|
}
|
|
6093
6147
|
//#endregion
|
|
6094
6148
|
//#region src/node/codex-surface-connection-controller.ts
|
|
6095
|
-
var
|
|
6149
|
+
var Ui = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_request_user_input"]), Wi = class {
|
|
6096
6150
|
client;
|
|
6097
6151
|
options;
|
|
6098
6152
|
authentication;
|
|
@@ -6155,7 +6209,7 @@ var Bi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6155
6209
|
limit: 100,
|
|
6156
6210
|
threadId: null
|
|
6157
6211
|
});
|
|
6158
|
-
for (let e of n.data)
|
|
6212
|
+
for (let e of n.data) Ui.has(e.name) && !e.enabled && (t[e.name] = !0);
|
|
6159
6213
|
e = n.nextCursor;
|
|
6160
6214
|
} while (e);
|
|
6161
6215
|
Object.keys(t).length > 0 && await this.client.request("experimentalFeature/enablement/set", { enablement: t });
|
|
@@ -6289,7 +6343,7 @@ var Bi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6289
6343
|
error: null
|
|
6290
6344
|
});
|
|
6291
6345
|
}
|
|
6292
|
-
},
|
|
6346
|
+
}, Gi = 5, Ki = class {
|
|
6293
6347
|
client;
|
|
6294
6348
|
loadingStrategy;
|
|
6295
6349
|
catalog;
|
|
@@ -6301,9 +6355,9 @@ var Bi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6301
6355
|
async fork(e, t = {}, n = {}, r = {}) {
|
|
6302
6356
|
let i = this.host.requireRuntime(e);
|
|
6303
6357
|
if ((i.busy || i.activeTurnId) && !r.beforeTurnId && (!r.lastTurnId || r.lastTurnId === i.activeTurnId)) throw Error("Cannot fork a conversation while its current turn is still active");
|
|
6304
|
-
let a = t.cwd ?? i.cwd ?? n.cwd, o = await this.catalog.loadConversationCatalogs(a ?? void 0), s = this.host.getState(), c = t.model ?
|
|
6305
|
-
|
|
6306
|
-
let l = n.mcpServers === void 0 ? this.extensions.defaultMcpServers :
|
|
6358
|
+
let a = t.cwd ?? i.cwd ?? n.cwd, o = await this.catalog.loadConversationCatalogs(a ?? void 0), s = this.host.getState(), c = t.model ? At(s.models, t.model) : k(s.models, i.selectedModelId);
|
|
6359
|
+
jt(c, t.reasoningEffort), j(c, t.serviceTier);
|
|
6360
|
+
let l = n.mcpServers === void 0 ? this.extensions.defaultMcpServers : vi(n.mcpServers), u = await this.extensions.conversationExtension({
|
|
6307
6361
|
operation: "start",
|
|
6308
6362
|
conversationId: null,
|
|
6309
6363
|
cwd: a ?? void 0,
|
|
@@ -6321,24 +6375,24 @@ var Bi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6321
6375
|
...u.baseInstructions === void 0 ? {} : { baseInstructions: u.baseInstructions },
|
|
6322
6376
|
...u.developerInstructions === void 0 ? {} : { developerInstructions: u.developerInstructions },
|
|
6323
6377
|
...u.config === void 0 ? {} : { config: u.config },
|
|
6324
|
-
...
|
|
6378
|
+
...qi(t, o.approvalPresets)
|
|
6325
6379
|
});
|
|
6326
6380
|
if (!d.thread.id || d.thread.id === e) throw Error(`Codex thread/fork returned an invalid new thread id '${d.thread.id}'`);
|
|
6327
6381
|
t.reasoningEffort && await this.client.request("thread/settings/update", {
|
|
6328
6382
|
threadId: d.thread.id,
|
|
6329
6383
|
effort: t.reasoningEffort,
|
|
6330
|
-
...c ? { collaborationMode:
|
|
6384
|
+
...c ? { collaborationMode: Bt(i.planMode, c.model, t.reasoningEffort) } : {}
|
|
6331
6385
|
});
|
|
6332
6386
|
let [f, p] = await Promise.all([this.client.request("thread/turns/list", {
|
|
6333
6387
|
threadId: d.thread.id,
|
|
6334
6388
|
cursor: null,
|
|
6335
|
-
limit:
|
|
6389
|
+
limit: Gi,
|
|
6336
6390
|
sortDirection: "desc",
|
|
6337
6391
|
itemsView: "full"
|
|
6338
|
-
}), this.client.request("thread/goal/get", { threadId: d.thread.id }).then((e) => e.goal).catch(() => null)]), m = [...f.data].reverse(), h =
|
|
6392
|
+
}), this.client.request("thread/goal/get", { threadId: d.thread.id }).then((e) => e.goal).catch(() => null)]), m = [...f.data].reverse(), h = Jn(m), g = fr({
|
|
6339
6393
|
...d.thread,
|
|
6340
6394
|
turns: m
|
|
6341
|
-
}), _ = h ?
|
|
6395
|
+
}), _ = h ? U(g, d.thread.id, h) : g, v = n.loadingStrategy ?? this.loadingStrategy ?? "lazy", y = this.host.createRuntime(d.thread.id, {
|
|
6342
6396
|
hydrated: !0,
|
|
6343
6397
|
historyMode: d.thread.historyMode ?? "legacy",
|
|
6344
6398
|
loadingStrategy: v,
|
|
@@ -6348,14 +6402,14 @@ var Bi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6348
6402
|
fullHistoryHydrated: f.nextCursor === null,
|
|
6349
6403
|
cwd: d.cwd ?? d.thread.cwd ?? a ?? null,
|
|
6350
6404
|
activeTurnId: h,
|
|
6351
|
-
turns: m.map((e) =>
|
|
6405
|
+
turns: m.map((e) => Z(e)),
|
|
6352
6406
|
turnIds: m.map((e) => e.id),
|
|
6353
6407
|
messages: _,
|
|
6354
6408
|
busy: !!h,
|
|
6355
6409
|
goal: p ? { ...p } : null,
|
|
6356
|
-
threadStatus:
|
|
6410
|
+
threadStatus: F(d.thread.status),
|
|
6357
6411
|
...o,
|
|
6358
|
-
...
|
|
6412
|
+
...Lt(d, s.models, this.host.snapshotForRuntime(i))
|
|
6359
6413
|
});
|
|
6360
6414
|
t.reasoningEffort && (y.selectedReasoningEffort = t.reasoningEffort), t.serviceTier !== void 0 && (y.selectedServiceTier = t.serviceTier), t.model && c && (y.selectedModelId = c.id), this.host.rememberHostOptions(d.thread.id, {
|
|
6361
6415
|
...n,
|
|
@@ -6364,20 +6418,20 @@ var Bi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6364
6418
|
mcpServers: l
|
|
6365
6419
|
});
|
|
6366
6420
|
let b = {
|
|
6367
|
-
...
|
|
6421
|
+
...N(d.thread),
|
|
6368
6422
|
turnCount: m.length
|
|
6369
6423
|
};
|
|
6370
|
-
return this.host.patch({ conversations:
|
|
6424
|
+
return this.host.patch({ conversations: P(this.host.getState().conversations, b) }), this.host.emitSummaryUpserted(b), this.host.emitHistoryReplaced(d.thread.id), this.host.emitConversationActivity(d.thread.id), this.host.emitConversationSettings(d.thread.id), this.host.emitConversationSkills(d.thread.id), this.host.emitConversationPermissions(d.thread.id), v === "eager" && f.nextCursor !== null && this.host.hydrateCompleteHistory(d.thread.id).catch(() => void 0), d.thread.id;
|
|
6371
6425
|
}
|
|
6372
6426
|
async forkTurn(e, t, n = {}, r = {}) {
|
|
6373
6427
|
if (!this.host.requireRuntime(e).turnIds.includes(t)) throw Error(`Cannot fork at unknown Codex turn '${t}'`);
|
|
6374
6428
|
return this.fork(e, n, r, { lastTurnId: t });
|
|
6375
6429
|
}
|
|
6376
6430
|
};
|
|
6377
|
-
function
|
|
6431
|
+
function qi(e, t) {
|
|
6378
6432
|
if (e.approvalPreset) {
|
|
6379
6433
|
if (!t.includes(e.approvalPreset)) throw Error(`Approval preset '${e.approvalPreset}' is not available`);
|
|
6380
|
-
return
|
|
6434
|
+
return Pt(e.approvalPreset);
|
|
6381
6435
|
}
|
|
6382
6436
|
return {
|
|
6383
6437
|
...e.approvalMode === void 0 ? {} : { approvalPolicy: e.approvalMode === "ask" ? "on-request" : "never" },
|
|
@@ -6386,27 +6440,27 @@ function Wi(e, t) {
|
|
|
6386
6440
|
}
|
|
6387
6441
|
//#endregion
|
|
6388
6442
|
//#region src/node/codex-markdown-images.ts
|
|
6389
|
-
var
|
|
6443
|
+
var Ji = /(?<!\[)!\[([^\]]*)\]\(([^)\s]+)(?:\s+["']([^"']*)["'])?\)/g, Yi = /* @__PURE__ */ new Set([
|
|
6390
6444
|
".avif",
|
|
6391
6445
|
".gif",
|
|
6392
6446
|
".jpeg",
|
|
6393
6447
|
".jpg",
|
|
6394
6448
|
".png",
|
|
6395
6449
|
".webp"
|
|
6396
|
-
]),
|
|
6450
|
+
]), Xi = class {
|
|
6397
6451
|
client;
|
|
6398
6452
|
constructor(e) {
|
|
6399
6453
|
this.client = e;
|
|
6400
6454
|
}
|
|
6401
6455
|
async hydrate(e, t) {
|
|
6402
|
-
let n =
|
|
6403
|
-
return
|
|
6456
|
+
let n = $i(e);
|
|
6457
|
+
return Qi(e, (await Promise.all(Array.from(e.matchAll(Ji), async (e) => {
|
|
6404
6458
|
let r = e.index ?? 0;
|
|
6405
|
-
if (
|
|
6406
|
-
let i = e[2], a =
|
|
6459
|
+
if (ea(r, n)) return null;
|
|
6460
|
+
let i = e[2], a = Zi(i, t);
|
|
6407
6461
|
if (!a) return null;
|
|
6408
6462
|
try {
|
|
6409
|
-
let t =
|
|
6463
|
+
let t = Er((await this.client.request("fs/readFile", { path: a })).dataBase64);
|
|
6410
6464
|
if (!t) return null;
|
|
6411
6465
|
let n = e[0].indexOf("](") + 2;
|
|
6412
6466
|
return {
|
|
@@ -6420,7 +6474,7 @@ var Gi = /(?<!\[)!\[([^\]]*)\]\(([^)\s]+)(?:\s+["']([^"']*)["'])?\)/g, Ki = /* @
|
|
|
6420
6474
|
}))).filter((e) => e !== null));
|
|
6421
6475
|
}
|
|
6422
6476
|
};
|
|
6423
|
-
function
|
|
6477
|
+
function Zi(e, t) {
|
|
6424
6478
|
let n = e.trim();
|
|
6425
6479
|
if (!n || /[\u0000-\u001f\u007f]/.test(n)) return null;
|
|
6426
6480
|
let r;
|
|
@@ -6435,18 +6489,18 @@ function Ji(e, t) {
|
|
|
6435
6489
|
} catch {
|
|
6436
6490
|
return null;
|
|
6437
6491
|
}
|
|
6438
|
-
if (!
|
|
6492
|
+
if (!Yi.has(_(r).toLowerCase())) return null;
|
|
6439
6493
|
if (v(r)) return r;
|
|
6440
6494
|
if (!t || !v(t)) return null;
|
|
6441
6495
|
let i = x(t, r), a = b(t, i);
|
|
6442
6496
|
return a === ".." || a.startsWith(`..${S}`) || v(a) ? null : i;
|
|
6443
6497
|
}
|
|
6444
|
-
function
|
|
6498
|
+
function Qi(e, t) {
|
|
6445
6499
|
let n = e;
|
|
6446
6500
|
for (let e of t.sort((e, t) => t.start - e.start)) n = `${n.slice(0, e.start)}${e.value}${n.slice(e.end)}`;
|
|
6447
6501
|
return n;
|
|
6448
6502
|
}
|
|
6449
|
-
function
|
|
6503
|
+
function $i(e) {
|
|
6450
6504
|
let t = [], n = /(^|\n)(```|~~~)/g, r;
|
|
6451
6505
|
for (; (r = n.exec(e)) !== null;) {
|
|
6452
6506
|
let i = r[2], a = r[1], o = r.index + a.length, s = RegExp(`(^|\\n)${i}`, "g");
|
|
@@ -6467,15 +6521,15 @@ function Xi(e) {
|
|
|
6467
6521
|
}
|
|
6468
6522
|
return t;
|
|
6469
6523
|
}
|
|
6470
|
-
function
|
|
6524
|
+
function ea(e, t) {
|
|
6471
6525
|
return t.some((t) => e >= t.start && e <= t.end);
|
|
6472
6526
|
}
|
|
6473
|
-
var
|
|
6474
|
-
async function
|
|
6527
|
+
var ta = /<context>[\s\S]*?<\/context>\s*/g, na = /<in-app-browser-context(?:\s[^>]*)?>[\s\S]*?<\/in-app-browser-context>\s*/g, ra = /^[ \t]*## My request for Codex:[ \t]*$/m;
|
|
6528
|
+
async function ia(e, t) {
|
|
6475
6529
|
let n = D(t);
|
|
6476
6530
|
return {
|
|
6477
6531
|
conversationId: n,
|
|
6478
|
-
prompts:
|
|
6532
|
+
prompts: aa((await e.request("thread/turns/list", {
|
|
6479
6533
|
threadId: n,
|
|
6480
6534
|
cursor: null,
|
|
6481
6535
|
limit: 100,
|
|
@@ -6484,20 +6538,20 @@ async function ta(e, t) {
|
|
|
6484
6538
|
})).data)
|
|
6485
6539
|
};
|
|
6486
6540
|
}
|
|
6487
|
-
function
|
|
6541
|
+
function aa(e) {
|
|
6488
6542
|
return [...e].reverse().flatMap((e) => e.items.flatMap((e) => {
|
|
6489
6543
|
if (e.type !== "userMessage") return [];
|
|
6490
|
-
let t =
|
|
6544
|
+
let t = oa(e.content.flatMap((e) => e.type === "text" ? [e.text] : []).join(""));
|
|
6491
6545
|
return t && t !== "(no user instructions)" ? [t] : [];
|
|
6492
6546
|
}));
|
|
6493
6547
|
}
|
|
6494
|
-
function
|
|
6495
|
-
let t = e.replace(
|
|
6496
|
-
return (n === t ? n : n.replace(
|
|
6548
|
+
function oa(e) {
|
|
6549
|
+
let t = e.replace(ta, ""), n = t.replace(na, "");
|
|
6550
|
+
return (n === t ? n : n.replace(ra, "")).trim();
|
|
6497
6551
|
}
|
|
6498
6552
|
//#endregion
|
|
6499
6553
|
//#region src/node/codex-surface-text-generation-controller.ts
|
|
6500
|
-
var
|
|
6554
|
+
var sa = 12e4, ca = class {
|
|
6501
6555
|
client;
|
|
6502
6556
|
defaultCwd;
|
|
6503
6557
|
host;
|
|
@@ -6508,7 +6562,7 @@ var ia = 12e4, aa = class {
|
|
|
6508
6562
|
}
|
|
6509
6563
|
handleNotification(e) {
|
|
6510
6564
|
e.method === "thread/started" && e.params.thread.ephemeral && this.hiddenThreadIds.add(e.params.thread.id);
|
|
6511
|
-
let t =
|
|
6565
|
+
let t = fa(e);
|
|
6512
6566
|
if (!t || !this.hiddenThreadIds.has(t)) return !1;
|
|
6513
6567
|
let n = this.pendingByThread.get(t);
|
|
6514
6568
|
return n && this.consumeNotification(n, e), (e.method === "thread/closed" || e.method === "thread/deleted") && this.hiddenThreadIds.delete(t), !0;
|
|
@@ -6516,10 +6570,10 @@ var ia = 12e4, aa = class {
|
|
|
6516
6570
|
async generate(e, t = {}) {
|
|
6517
6571
|
let n = e.trim();
|
|
6518
6572
|
if (!n) throw Error("Generation prompt cannot be empty");
|
|
6519
|
-
if (t.signal?.aborted) throw
|
|
6573
|
+
if (t.signal?.aborted) throw pa();
|
|
6520
6574
|
await this.host.ensureConnected();
|
|
6521
|
-
let r = this.host.getSnapshot(), i =
|
|
6522
|
-
|
|
6575
|
+
let r = this.host.getSnapshot(), i = k(r.models, r.selectedModelId), a = t.model ? At(r.models, t.model) : i, o = a?.model, s = t.reasoningEffort ?? (a?.id === i?.id ? r.selectedReasoningEffort : a ? A(a) : null) ?? void 0, c = t.serviceTier === void 0 ? a?.id === i?.id ? r.selectedServiceTier : a?.defaultServiceTier ?? null : t.serviceTier;
|
|
6576
|
+
jt(a, s), j(a, c);
|
|
6523
6577
|
let l = await this.client.request("thread/start", {
|
|
6524
6578
|
approvalPolicy: "never",
|
|
6525
6579
|
approvalsReviewer: "user",
|
|
@@ -6535,15 +6589,15 @@ var ia = 12e4, aa = class {
|
|
|
6535
6589
|
serviceName: "codex_app_sdk",
|
|
6536
6590
|
threadSource: "sdk_ephemeral_generation"
|
|
6537
6591
|
}), u = l.thread.id;
|
|
6538
|
-
if (!l.thread.ephemeral) throw await
|
|
6539
|
-
if (this.hiddenThreadIds.add(u), t.signal?.aborted) throw await
|
|
6540
|
-
let d =
|
|
6592
|
+
if (!l.thread.ephemeral) throw await la(() => this.client.request("thread/delete", { threadId: u })), Error("Codex app-server did not create an ephemeral generation thread");
|
|
6593
|
+
if (this.hiddenThreadIds.add(u), t.signal?.aborted) throw await la(() => this.client.request("thread/unsubscribe", { threadId: u })), this.hiddenThreadIds.delete(u), pa();
|
|
6594
|
+
let d = ua();
|
|
6541
6595
|
this.pendingByThread.set(u, d);
|
|
6542
|
-
let f = null, p = !1, m = () => d.reject(
|
|
6596
|
+
let f = null, p = !1, m = () => d.reject(pa());
|
|
6543
6597
|
t.signal?.addEventListener("abort", m);
|
|
6544
6598
|
let h = setTimeout(() => {
|
|
6545
6599
|
d.reject(/* @__PURE__ */ Error("Codex ephemeral generation timed out"));
|
|
6546
|
-
}, t.timeoutMs ??
|
|
6600
|
+
}, t.timeoutMs ?? sa);
|
|
6547
6601
|
try {
|
|
6548
6602
|
let e = await this.client.request("turn/start", {
|
|
6549
6603
|
threadId: u,
|
|
@@ -6559,18 +6613,18 @@ var ia = 12e4, aa = class {
|
|
|
6559
6613
|
serviceTier: c,
|
|
6560
6614
|
...t.outputSchema === void 0 ? {} : { outputSchema: t.outputSchema }
|
|
6561
6615
|
});
|
|
6562
|
-
f = e.turn.id, d.turnId = f,
|
|
6616
|
+
f = e.turn.id, d.turnId = f, da(d, e.turn);
|
|
6563
6617
|
let r = await d.promise;
|
|
6564
6618
|
return p = !0, r;
|
|
6565
6619
|
} finally {
|
|
6566
6620
|
if (clearTimeout(h), t.signal?.removeEventListener("abort", m), this.pendingByThread.delete(u), !p && f) {
|
|
6567
6621
|
let e = f;
|
|
6568
|
-
await
|
|
6622
|
+
await la(() => this.client.request("turn/interrupt", {
|
|
6569
6623
|
threadId: u,
|
|
6570
6624
|
turnId: e
|
|
6571
6625
|
}));
|
|
6572
6626
|
}
|
|
6573
|
-
await
|
|
6627
|
+
await la(() => this.client.request("thread/unsubscribe", { threadId: u })), this.hiddenThreadIds.delete(u);
|
|
6574
6628
|
}
|
|
6575
6629
|
}
|
|
6576
6630
|
close(e = /* @__PURE__ */ Error("Codex surface closed")) {
|
|
@@ -6593,16 +6647,16 @@ var ia = 12e4, aa = class {
|
|
|
6593
6647
|
}
|
|
6594
6648
|
if (t.method === "turn/completed") {
|
|
6595
6649
|
if (e.turnId && t.params.turn.id !== e.turnId) return;
|
|
6596
|
-
|
|
6650
|
+
da(e, t.params.turn);
|
|
6597
6651
|
}
|
|
6598
6652
|
}
|
|
6599
6653
|
};
|
|
6600
|
-
async function
|
|
6654
|
+
async function la(e) {
|
|
6601
6655
|
try {
|
|
6602
6656
|
await e();
|
|
6603
6657
|
} catch {}
|
|
6604
6658
|
}
|
|
6605
|
-
function
|
|
6659
|
+
function ua() {
|
|
6606
6660
|
let e, t, n = {
|
|
6607
6661
|
promise: new Promise((n, r) => {
|
|
6608
6662
|
e = n, t = r;
|
|
@@ -6618,7 +6672,7 @@ function sa() {
|
|
|
6618
6672
|
};
|
|
6619
6673
|
return n.promise.catch(() => void 0), n;
|
|
6620
6674
|
}
|
|
6621
|
-
function
|
|
6675
|
+
function da(e, t) {
|
|
6622
6676
|
for (let n of t.items) {
|
|
6623
6677
|
if (n.type !== "agentMessage") continue;
|
|
6624
6678
|
let t = n.text.trim();
|
|
@@ -6640,17 +6694,98 @@ function ca(e, t) {
|
|
|
6640
6694
|
}
|
|
6641
6695
|
e.resolve({ text: n });
|
|
6642
6696
|
}
|
|
6643
|
-
function
|
|
6697
|
+
function fa(e) {
|
|
6644
6698
|
if (e.method === "thread/started") return e.params.thread.id;
|
|
6645
6699
|
let t = e.params;
|
|
6646
6700
|
return typeof t.threadId == "string" ? t.threadId : null;
|
|
6647
6701
|
}
|
|
6648
|
-
function
|
|
6702
|
+
function pa() {
|
|
6649
6703
|
return /* @__PURE__ */ Error("Codex ephemeral generation was aborted");
|
|
6650
6704
|
}
|
|
6651
6705
|
//#endregion
|
|
6706
|
+
//#region src/node/codex-surface-usage-controller.ts
|
|
6707
|
+
var ma = class {
|
|
6708
|
+
threads = /* @__PURE__ */ new Map();
|
|
6709
|
+
clear() {
|
|
6710
|
+
this.threads.clear();
|
|
6711
|
+
}
|
|
6712
|
+
observe(e, t) {
|
|
6713
|
+
if (!("conversationId" in t)) return t;
|
|
6714
|
+
let n = t.conversationId;
|
|
6715
|
+
if (t.type === "conversation.historyReplaced" || t.type === "conversation.summaryRemoved") return this.threads.delete(n), t;
|
|
6716
|
+
if (t.type === "turn.started" && e !== "lifecycle") {
|
|
6717
|
+
let e = this.thread(n);
|
|
6718
|
+
return e.executions.has(t.turnId) || e.executions.set(t.turnId, {
|
|
6719
|
+
baseline: e.lastUsageTurnId === t.turnId ? null : e.total,
|
|
6720
|
+
latest: null
|
|
6721
|
+
}), e.activeTurnId = t.turnId, t;
|
|
6722
|
+
}
|
|
6723
|
+
if (t.type === "turn.completed") {
|
|
6724
|
+
let e = this.threads.get(n);
|
|
6725
|
+
return e?.activeTurnId === t.turnId && (e.activeTurnId = null), {
|
|
6726
|
+
...t,
|
|
6727
|
+
payload: {
|
|
6728
|
+
...t.payload,
|
|
6729
|
+
executionUsage: structuredClone(e?.executions.get(t.turnId)?.latest ?? null)
|
|
6730
|
+
}
|
|
6731
|
+
};
|
|
6732
|
+
}
|
|
6733
|
+
if (t.type !== "conversation.executionUsageChanged") return t;
|
|
6734
|
+
let r = this.thread(n), i = r.executions.get(t.turnId), a = t.payload.usage, o = r.activeTurnId !== null && r.activeTurnId !== t.turnId;
|
|
6735
|
+
if (o) {
|
|
6736
|
+
let e = r.executions.get(r.activeTurnId);
|
|
6737
|
+
e && (e.baseline = null), i && (i.baseline = null);
|
|
6738
|
+
}
|
|
6739
|
+
i && (!ga(a.total) || i.latest && !_a(i.latest.total, a.total)) && (i.baseline = null);
|
|
6740
|
+
let s = i?.baseline ? va(i.baseline, a.total) : null;
|
|
6741
|
+
i && s === null && (i.baseline = null);
|
|
6742
|
+
let c = {
|
|
6743
|
+
...a,
|
|
6744
|
+
execution: s,
|
|
6745
|
+
observedStart: !!i
|
|
6746
|
+
};
|
|
6747
|
+
return i && (i.latest = structuredClone(c)), r.total = !o && ga(a.total) ? structuredClone(a.total) : null, r.lastUsageTurnId = t.turnId, {
|
|
6748
|
+
...t,
|
|
6749
|
+
payload: { usage: c }
|
|
6750
|
+
};
|
|
6751
|
+
}
|
|
6752
|
+
thread(e) {
|
|
6753
|
+
let t = this.threads.get(e);
|
|
6754
|
+
return t || (t = {
|
|
6755
|
+
total: null,
|
|
6756
|
+
lastUsageTurnId: null,
|
|
6757
|
+
activeTurnId: null,
|
|
6758
|
+
executions: /* @__PURE__ */ new Map()
|
|
6759
|
+
}, this.threads.set(e, t)), t;
|
|
6760
|
+
}
|
|
6761
|
+
}, ha = [
|
|
6762
|
+
"totalTokens",
|
|
6763
|
+
"inputTokens",
|
|
6764
|
+
"cachedInputTokens",
|
|
6765
|
+
"outputTokens",
|
|
6766
|
+
"reasoningOutputTokens"
|
|
6767
|
+
];
|
|
6768
|
+
function ga(e) {
|
|
6769
|
+
return ha.every((t) => Number.isSafeInteger(e[t]) && e[t] >= 0) && (e.cacheWriteInputTokens === null || Number.isSafeInteger(e.cacheWriteInputTokens) && e.cacheWriteInputTokens >= 0) && e.totalTokens === e.inputTokens + e.outputTokens && e.cachedInputTokens <= e.inputTokens && e.reasoningOutputTokens <= e.outputTokens;
|
|
6770
|
+
}
|
|
6771
|
+
function _a(e, t) {
|
|
6772
|
+
return ha.every((n) => t[n] >= e[n]) && (e.cacheWriteInputTokens === null || t.cacheWriteInputTokens === null || t.cacheWriteInputTokens >= e.cacheWriteInputTokens);
|
|
6773
|
+
}
|
|
6774
|
+
function va(e, t) {
|
|
6775
|
+
if (!ga(e) || !ga(t) || !_a(e, t)) return null;
|
|
6776
|
+
let n = {
|
|
6777
|
+
totalTokens: t.totalTokens - e.totalTokens,
|
|
6778
|
+
inputTokens: t.inputTokens - e.inputTokens,
|
|
6779
|
+
cachedInputTokens: t.cachedInputTokens - e.cachedInputTokens,
|
|
6780
|
+
cacheWriteInputTokens: e.cacheWriteInputTokens === null || t.cacheWriteInputTokens === null ? null : t.cacheWriteInputTokens - e.cacheWriteInputTokens,
|
|
6781
|
+
outputTokens: t.outputTokens - e.outputTokens,
|
|
6782
|
+
reasoningOutputTokens: t.reasoningOutputTokens - e.reasoningOutputTokens
|
|
6783
|
+
};
|
|
6784
|
+
return ga(n) ? n : null;
|
|
6785
|
+
}
|
|
6786
|
+
//#endregion
|
|
6652
6787
|
//#region src/node/codex-surface.ts
|
|
6653
|
-
var
|
|
6788
|
+
var ya = class {
|
|
6654
6789
|
options;
|
|
6655
6790
|
client;
|
|
6656
6791
|
listeners = /* @__PURE__ */ new Set();
|
|
@@ -6681,19 +6816,21 @@ var da = class {
|
|
|
6681
6816
|
unsubscribeToolInputRequests;
|
|
6682
6817
|
unsubscribeMcpElicitationRequests;
|
|
6683
6818
|
eventSequence = 0;
|
|
6819
|
+
usage = new ma();
|
|
6820
|
+
accountGeneration = 0;
|
|
6684
6821
|
pendingMarkdownImageHydrations = /* @__PURE__ */ new Set();
|
|
6685
6822
|
closed = !1;
|
|
6686
6823
|
state = _t(bt());
|
|
6687
6824
|
constructor(e = {}) {
|
|
6688
|
-
this.options = e, this.extensions = new
|
|
6689
|
-
let n =
|
|
6690
|
-
this.client = e.client ?? new t(
|
|
6825
|
+
this.options = e, this.extensions = new Ti(e.extensions ?? [], e.mcpServers ?? [], (e) => this.lifecycle.hostOptions(e));
|
|
6826
|
+
let n = sn(e);
|
|
6827
|
+
this.client = e.client ?? new t(on(n) ? new Ke(n) : new Ve(n), e.onListenerError ? { onListenerError: e.onListenerError } : {}), this.markdownImages = new Xi(this.client), this.authentication = new ln(this.client, {
|
|
6691
6828
|
bootstrapSurfaceData: (e) => this.connection.bootstrapSurfaceData(e),
|
|
6692
6829
|
clearAuthenticatedSurfaceData: () => this.connection.clearAuthenticatedSurfaceData(),
|
|
6693
6830
|
getSnapshot: () => this.getSnapshot(),
|
|
6694
6831
|
patchAuthentication: (e, t) => this.connection.patchAuthentication(e, t),
|
|
6695
6832
|
reportError: (e) => this.patch({ error: O(e) })
|
|
6696
|
-
}), this.items = new
|
|
6833
|
+
}), this.items = new Yr({
|
|
6697
6834
|
assistantMessageForTurn: (e, t) => this.assistantMessageForTurn(e, t),
|
|
6698
6835
|
emitConversationActivity: (e, t) => this.emitConversationActivity(e, t),
|
|
6699
6836
|
emitEvent: (e, t) => this.emitEvent(e, t),
|
|
@@ -6707,7 +6844,7 @@ var da = class {
|
|
|
6707
6844
|
sendNextQueuedPrompt: (e) => {
|
|
6708
6845
|
this.messagesController.sendNextQueuedPrompt(e);
|
|
6709
6846
|
}
|
|
6710
|
-
}), this.approvals = new
|
|
6847
|
+
}), this.approvals = new _i(this.client, {
|
|
6711
6848
|
activeConversationId: () => this.state.activeConversationId,
|
|
6712
6849
|
createRuntime: (e, t) => this.createRuntime(e, t),
|
|
6713
6850
|
emitConversationActivity: (e, t) => this.emitConversationActivity(e, t),
|
|
@@ -6717,7 +6854,7 @@ var da = class {
|
|
|
6717
6854
|
patch: (e) => this.patch(e),
|
|
6718
6855
|
patchConversationStatus: (e, t) => this.patchConversationStatus(e, t),
|
|
6719
6856
|
patchRuntime: (e, t) => this.patchRuntime(e, t)
|
|
6720
|
-
}), this.clientRequests = new
|
|
6857
|
+
}), this.clientRequests = new Qr({
|
|
6721
6858
|
activeConversationId: () => this.state.activeConversationId,
|
|
6722
6859
|
answerAsyncQuestion: (e, t, n) => this.messagesController.answerAsyncQuestion(e, t, n),
|
|
6723
6860
|
emitConversationActivity: (e, t) => this.emitConversationActivity(e, t),
|
|
@@ -6727,13 +6864,13 @@ var da = class {
|
|
|
6727
6864
|
messageContainingTool: (e, t, n) => this.messageContainingTool(e, t, n),
|
|
6728
6865
|
patchRuntime: (e, t) => this.patchRuntime(e, t),
|
|
6729
6866
|
requireRuntime: (e) => this.requireRuntime(e)
|
|
6730
|
-
}), this.runtimeState = new
|
|
6867
|
+
}), this.runtimeState = new zi(this.approvals, this.clientRequests, {
|
|
6731
6868
|
emitEvent: (e, t) => this.emitEvent(e, t),
|
|
6732
6869
|
getState: () => this.state,
|
|
6733
6870
|
notifyConversationListeners: (e) => this.notifyConversationListeners(e),
|
|
6734
6871
|
patch: (e, t) => this.patch(e, t),
|
|
6735
6872
|
schedulePluginRefresh: () => this.catalog.schedulePluginRefresh()
|
|
6736
|
-
}), this.conversationSettings = new
|
|
6873
|
+
}), this.conversationSettings = new ji(this.client, {
|
|
6737
6874
|
approvalMode: e.approvalMode,
|
|
6738
6875
|
approvalPreset: e.approvalPreset,
|
|
6739
6876
|
permissionMode: e.permissionMode
|
|
@@ -6751,7 +6888,7 @@ var da = class {
|
|
|
6751
6888
|
patch: (e) => this.patch(e),
|
|
6752
6889
|
patchRuntime: (e, t) => this.patchRuntime(e, t),
|
|
6753
6890
|
snapshotForRuntime: (e) => this.snapshotForRuntime(e)
|
|
6754
|
-
}), this.turnActions = new
|
|
6891
|
+
}), this.turnActions = new Ni(this.client, {
|
|
6755
6892
|
createConversation: async () => {
|
|
6756
6893
|
await this.createConversation();
|
|
6757
6894
|
},
|
|
@@ -6768,7 +6905,7 @@ var da = class {
|
|
|
6768
6905
|
patchConversationTurnCount: (e, t, n) => this.patchConversationTurnCount(e, t, n),
|
|
6769
6906
|
patchRuntime: (e, t) => this.patchRuntime(e, t),
|
|
6770
6907
|
sendMessageToThread: (e, t, n) => this.messagesController.sendToThread(e, t, n)
|
|
6771
|
-
}), this.messagesController = new
|
|
6908
|
+
}), this.messagesController = new Fi(this.client, {
|
|
6772
6909
|
clearGoalForThread: (e) => this.conversationSettings.clearGoalForThread(e),
|
|
6773
6910
|
compactForThread: (e) => this.turnActions.compactForThread(e),
|
|
6774
6911
|
createConversation: async () => {
|
|
@@ -6791,7 +6928,7 @@ var da = class {
|
|
|
6791
6928
|
startReviewForThread: (e, t) => this.turnActions.startReviewForThread(e, t),
|
|
6792
6929
|
updateSettings: (e) => this.conversationSettings.update(e),
|
|
6793
6930
|
updateSettingsForThread: (e, t) => this.conversationSettings.updateForThread(e, t)
|
|
6794
|
-
}), this.catalog = new
|
|
6931
|
+
}), this.catalog = new li(this.client, e.cwd, {
|
|
6795
6932
|
authenticationBlocksBootstrap: () => this.authentication.blocksBootstrap(),
|
|
6796
6933
|
emitConversationSkills: (e, t) => this.emitConversationSkills(e, t),
|
|
6797
6934
|
emitEvent: (e, t) => this.emitEvent(e, t),
|
|
@@ -6802,7 +6939,7 @@ var da = class {
|
|
|
6802
6939
|
patchRuntime: (e, t) => this.patchRuntime(e, t),
|
|
6803
6940
|
preferredApprovalPreset: () => this.conversationSettings.preferredApprovalPreset(),
|
|
6804
6941
|
runtimes: () => this.runtimeState.values()
|
|
6805
|
-
}), this.conversations = new
|
|
6942
|
+
}), this.conversations = new ki(this.client, e.conversationLimit, {
|
|
6806
6943
|
emitHistoryPrepended: (e, t, n) => this.emitHistoryPrepended(e, t, n),
|
|
6807
6944
|
emitSummaryUpserted: (e, t, n) => this.emitSummaryUpserted(e, t, n),
|
|
6808
6945
|
ensureConnected: () => this.ensureConnected(),
|
|
@@ -6814,7 +6951,7 @@ var da = class {
|
|
|
6814
6951
|
requireRuntime: (e) => this.requireRuntime(e),
|
|
6815
6952
|
runtime: (e) => this.runtimeState.get(e),
|
|
6816
6953
|
schedulePluginRefresh: (e) => this.catalog.schedulePluginRefresh(e)
|
|
6817
|
-
}), this.lifecycle = new
|
|
6954
|
+
}), this.lifecycle = new Li(this.client, e, this.catalog, this.extensions, this.conversationSettings, this.conversations, {
|
|
6818
6955
|
activateRuntime: (e) => this.activateRuntime(e),
|
|
6819
6956
|
createRuntime: (e, t) => this.createRuntime(e, t),
|
|
6820
6957
|
emitConversationActivity: (e, t) => this.emitConversationActivity(e, t),
|
|
@@ -6836,7 +6973,7 @@ var da = class {
|
|
|
6836
6973
|
runtime: (e) => this.runtimeState.get(e),
|
|
6837
6974
|
runtimeProjection: (e) => this.runtimeProjection(e),
|
|
6838
6975
|
snapshotForRuntime: (e) => this.snapshotForRuntime(e)
|
|
6839
|
-
}), this.forks = new
|
|
6976
|
+
}), this.forks = new Ki(this.client, e.loadingStrategy, this.catalog, this.extensions, {
|
|
6840
6977
|
createRuntime: (e, t) => this.createRuntime(e, t),
|
|
6841
6978
|
emitConversationActivity: (e) => this.emitConversationActivity(e, "action"),
|
|
6842
6979
|
emitConversationPermissions: (e) => this.emitConversationPermissions(e, "action"),
|
|
@@ -6850,7 +6987,7 @@ var da = class {
|
|
|
6850
6987
|
rememberHostOptions: (e, t) => this.lifecycle.rememberHostOptions(e, t),
|
|
6851
6988
|
requireRuntime: (e) => this.requireRuntime(e),
|
|
6852
6989
|
snapshotForRuntime: (e) => this.snapshotForRuntime(e)
|
|
6853
|
-
}), this.connection = new
|
|
6990
|
+
}), this.connection = new Wi(this.client, e, this.authentication, this.approvals, this.catalog, this.clientRequests, this.conversations, this.items, this.lifecycle, this.runtimeState, {
|
|
6854
6991
|
clearConversationHandles: () => this.conversationHandles.clear(),
|
|
6855
6992
|
clearPendingForThread: (e, t, n) => this.clearPendingForThread(e, t, n),
|
|
6856
6993
|
closed: () => this.closed,
|
|
@@ -6862,7 +6999,7 @@ var da = class {
|
|
|
6862
6999
|
getSnapshot: () => this.getSnapshot(),
|
|
6863
7000
|
getState: () => this.state,
|
|
6864
7001
|
patch: (e) => this.patch(e)
|
|
6865
|
-
}), this.notifications = new
|
|
7002
|
+
}), this.notifications = new Ri(this.authentication, this.approvals, this.catalog, this.clientRequests, this.conversations, this.items, {
|
|
6866
7003
|
clearPendingForThread: (e, t, n) => this.clearPendingForThread(e, t, n),
|
|
6867
7004
|
createRuntime: (e, t) => this.createRuntime(e, t),
|
|
6868
7005
|
emitConversationActivity: (e, t) => this.emitConversationActivity(e, t),
|
|
@@ -6886,13 +7023,13 @@ var da = class {
|
|
|
6886
7023
|
},
|
|
6887
7024
|
snapshotForRuntime: (e) => this.snapshotForRuntime(e),
|
|
6888
7025
|
unknownNotification: (e) => this.handleUnknownNotification(e)
|
|
6889
|
-
}), this.textGeneration = new
|
|
7026
|
+
}), this.textGeneration = new ca(this.client, e.cwd, {
|
|
6890
7027
|
ensureConnected: () => this.ensureConnected(),
|
|
6891
7028
|
getSnapshot: () => this.getSnapshot()
|
|
6892
7029
|
}), this.unsubscribeNotification = this.client.onNotification((e) => {
|
|
6893
|
-
this.textGeneration.handleNotification(e) || this.notifications.handle(e);
|
|
7030
|
+
(e.method === "account/updated" || e.method === "account/login/completed") && (this.accountGeneration += 1, this.usage.clear()), this.textGeneration.handleNotification(e) || this.notifications.handle(e);
|
|
6894
7031
|
}), this.unsubscribeDisconnect = this.client.onDisconnect((e) => {
|
|
6895
|
-
this.textGeneration.close(e), this.connection.handleDisconnect(e);
|
|
7032
|
+
this.accountGeneration += 1, this.usage.clear(), this.textGeneration.close(e), this.connection.handleDisconnect(e);
|
|
6896
7033
|
}), this.unsubscribeToolInputRequests = this.client.onServerRequest("item/tool/requestUserInput", (e, t) => this.clientRequests.handleToolInputRequest(e, t)), this.unsubscribeMcpElicitationRequests = this.client.onServerRequest("mcpServer/elicitation/request", (e, t) => this.clientRequests.handleMcpElicitationRequest(e, t)), this.client.onServerRequest("item/tool/call", async (e, t) => {
|
|
6897
7034
|
await this.extensions.handleDynamicToolCall(e, t);
|
|
6898
7035
|
}), this.client.onServerRequest("account/chatgptAuthTokens/refresh", (e, t) => {
|
|
@@ -6916,13 +7053,41 @@ var da = class {
|
|
|
6916
7053
|
return this.textGeneration.generate(e, t);
|
|
6917
7054
|
}
|
|
6918
7055
|
async refreshAccount() {
|
|
6919
|
-
return this.connection.refreshAccount();
|
|
7056
|
+
return this.accountGeneration += 1, this.connection.refreshAccount();
|
|
7057
|
+
}
|
|
7058
|
+
async readRateLimits(e) {
|
|
7059
|
+
return this.requestForAccount(() => this.client.request("account/rateLimits/read", e), (e) => {
|
|
7060
|
+
let t = $t(e);
|
|
7061
|
+
return this.patch({ rateLimits: t }), this.emitEvent("action", {
|
|
7062
|
+
type: "rateLimits.changed",
|
|
7063
|
+
payload: { rateLimits: structuredClone(t) }
|
|
7064
|
+
}), structuredClone(t);
|
|
7065
|
+
});
|
|
7066
|
+
}
|
|
7067
|
+
async readAccountUsage() {
|
|
7068
|
+
return this.requestForAccount(() => this.client.request("account/usage/read", {}), tn);
|
|
7069
|
+
}
|
|
7070
|
+
async consumeRateLimitResetCredit(e) {
|
|
7071
|
+
if (!e || typeof e.idempotencyKey != "string" || !e.idempotencyKey.trim() || e.creditId !== void 0 && (typeof e.creditId != "string" || !e.creditId.trim())) throw TypeError("Reset-credit options require non-empty identifiers");
|
|
7072
|
+
let t = {
|
|
7073
|
+
idempotencyKey: e.idempotencyKey,
|
|
7074
|
+
...e.creditId === void 0 ? {} : { creditId: e.creditId }
|
|
7075
|
+
};
|
|
7076
|
+
return this.requestForAccount(() => this.client.request("account/rateLimitResetCredit/consume", t), (e) => {
|
|
7077
|
+
switch (e?.outcome) {
|
|
7078
|
+
case "reset":
|
|
7079
|
+
case "alreadyRedeemed":
|
|
7080
|
+
case "nothingToReset":
|
|
7081
|
+
case "noCredit": return { outcome: e.outcome };
|
|
7082
|
+
default: throw Error("Invalid reset-credit outcome");
|
|
7083
|
+
}
|
|
7084
|
+
});
|
|
6920
7085
|
}
|
|
6921
7086
|
async startChatGptLogin() {
|
|
6922
|
-
return this.connection.startChatGptLogin();
|
|
7087
|
+
return this.accountGeneration += 1, this.connection.startChatGptLogin();
|
|
6923
7088
|
}
|
|
6924
7089
|
async startChatGptDeviceCodeLogin() {
|
|
6925
|
-
return this.connection.startChatGptDeviceCodeLogin();
|
|
7090
|
+
return this.accountGeneration += 1, this.connection.startChatGptDeviceCodeLogin();
|
|
6926
7091
|
}
|
|
6927
7092
|
async readRemoteControlStatus() {
|
|
6928
7093
|
return this.connection.readRemoteControlStatus();
|
|
@@ -6952,7 +7117,7 @@ var da = class {
|
|
|
6952
7117
|
return this.connection.cancelLogin(e);
|
|
6953
7118
|
}
|
|
6954
7119
|
async logout() {
|
|
6955
|
-
return this.connection.logout();
|
|
7120
|
+
return this.accountGeneration += 1, this.connection.logout();
|
|
6956
7121
|
}
|
|
6957
7122
|
async refreshConversations() {
|
|
6958
7123
|
return this.conversations.refresh();
|
|
@@ -7031,7 +7196,7 @@ var da = class {
|
|
|
7031
7196
|
return this.lifecycle.readHistory(e);
|
|
7032
7197
|
}
|
|
7033
7198
|
async readConversationPromptHistory(e = this.state.activeConversationId ?? "") {
|
|
7034
|
-
return await this.ensureConnected(),
|
|
7199
|
+
return await this.ensureConnected(), ia(this.client, e);
|
|
7035
7200
|
}
|
|
7036
7201
|
async loadOlderConversationHistory(e = this.state.activeConversationId ?? "") {
|
|
7037
7202
|
return this.conversations.loadOlderHistory(D(e));
|
|
@@ -7100,7 +7265,7 @@ var da = class {
|
|
|
7100
7265
|
conversation(e) {
|
|
7101
7266
|
let t = D(e), n = this.conversationHandles.get(t);
|
|
7102
7267
|
if (n) return n;
|
|
7103
|
-
let r =
|
|
7268
|
+
let r = un(t, {
|
|
7104
7269
|
clearGoal: () => this.conversationSettings.clearGoalForThread(t),
|
|
7105
7270
|
compact: () => this.turnActions.compactForThread(t),
|
|
7106
7271
|
continueInterruptedTurn: () => this.messagesController.continueInterruptedTurnForThread(t),
|
|
@@ -7212,7 +7377,7 @@ var da = class {
|
|
|
7212
7377
|
}
|
|
7213
7378
|
async close() {
|
|
7214
7379
|
if (!this.closed) {
|
|
7215
|
-
this.closed = !0, this.unsubscribeNotification(), this.unsubscribeToolInputRequests(), this.unsubscribeMcpElicitationRequests(), this.unsubscribeDisconnect(), this.approvals.close(), this.clientRequests.clear(), this.items.reset(), this.catalog.reset(!1), this.textGeneration.close();
|
|
7380
|
+
this.closed = !0, this.usage.clear(), this.unsubscribeNotification(), this.unsubscribeToolInputRequests(), this.unsubscribeMcpElicitationRequests(), this.unsubscribeDisconnect(), this.approvals.close(), this.clientRequests.clear(), this.items.reset(), this.catalog.reset(!1), this.textGeneration.close();
|
|
7216
7381
|
for (let e of this.runtimeState.values()) e.activeTurnId = null, e.busy = !1, e.turnStartPending = !1;
|
|
7217
7382
|
await this.client.close(), this.patch({
|
|
7218
7383
|
status: "idle",
|
|
@@ -7372,7 +7537,20 @@ var da = class {
|
|
|
7372
7537
|
..."params" in t ? { params: t.params } : {}
|
|
7373
7538
|
});
|
|
7374
7539
|
}
|
|
7540
|
+
async requestForAccount(e, t) {
|
|
7541
|
+
await this.ensureConnected(), await this.authentication.pendingRefresh();
|
|
7542
|
+
let n = this.accountGeneration, r = Ct(this.state.authentication), i = await e();
|
|
7543
|
+
if (this.closed || n !== this.accountGeneration || r !== Ct(this.state.authentication)) throw Error("Account changed during account operation");
|
|
7544
|
+
return t(i);
|
|
7545
|
+
}
|
|
7375
7546
|
emitEvent(e, t) {
|
|
7547
|
+
if (t = this.usage.observe(e, t), t.type === "conversation.executionUsageChanged" || t.type === "turn.completed") {
|
|
7548
|
+
let e = this.runtimeState.get(t.conversationId), n = t.type === "turn.completed" ? t.payload.executionUsage : t.payload.usage, r = t.turnId;
|
|
7549
|
+
e?.turns.some((e) => e.id === r) && this.patchRuntime(t.conversationId, { turns: e.turns.map((e) => e.id === r ? {
|
|
7550
|
+
...e,
|
|
7551
|
+
executionUsage: structuredClone(n)
|
|
7552
|
+
} : e) });
|
|
7553
|
+
}
|
|
7376
7554
|
let n = {
|
|
7377
7555
|
...t,
|
|
7378
7556
|
seq: ++this.eventSequence,
|
|
@@ -7406,19 +7584,19 @@ var da = class {
|
|
|
7406
7584
|
for (let e of this.conversationListeners.keys()) this.notifyConversationListeners(e);
|
|
7407
7585
|
}
|
|
7408
7586
|
};
|
|
7409
|
-
function
|
|
7410
|
-
return new
|
|
7587
|
+
function ba(e = {}) {
|
|
7588
|
+
return new ya(e);
|
|
7411
7589
|
}
|
|
7412
7590
|
//#endregion
|
|
7413
7591
|
//#region src/node/codex-app-backend-cache.ts
|
|
7414
|
-
var
|
|
7592
|
+
var xa = {
|
|
7415
7593
|
set(e, t) {
|
|
7416
7594
|
return setTimeout(e, t);
|
|
7417
7595
|
},
|
|
7418
7596
|
clear(e) {
|
|
7419
7597
|
clearTimeout(e);
|
|
7420
7598
|
}
|
|
7421
|
-
},
|
|
7599
|
+
}, Sa = class {
|
|
7422
7600
|
options;
|
|
7423
7601
|
records = /* @__PURE__ */ new Map();
|
|
7424
7602
|
now;
|
|
@@ -7431,7 +7609,7 @@ var pa = {
|
|
|
7431
7609
|
constructor(e) {
|
|
7432
7610
|
if (this.options = e, !Number.isFinite(e.ttlMs) || e.ttlMs <= 0) throw Error("Codex backend cache ttlMs must be greater than zero");
|
|
7433
7611
|
if (e.sweepIntervalMs !== void 0 && e.sweepIntervalMs !== null && (!Number.isFinite(e.sweepIntervalMs) || e.sweepIntervalMs <= 0)) throw Error("Codex backend cache sweepIntervalMs must be greater than zero");
|
|
7434
|
-
this.now = e.now ?? Date.now, this.scheduler = e.scheduler ??
|
|
7612
|
+
this.now = e.now ?? Date.now, this.scheduler = e.scheduler ?? xa, this.sweepIntervalMs = e.sweepIntervalMs ?? null;
|
|
7435
7613
|
}
|
|
7436
7614
|
get size() {
|
|
7437
7615
|
return this.records.size;
|
|
@@ -7529,7 +7707,7 @@ var pa = {
|
|
|
7529
7707
|
assertOpen() {
|
|
7530
7708
|
if (this.closed) throw Error("Codex backend cache is closed");
|
|
7531
7709
|
}
|
|
7532
|
-
},
|
|
7710
|
+
}, Ca = class {
|
|
7533
7711
|
surface;
|
|
7534
7712
|
moduleServices = /* @__PURE__ */ new Map();
|
|
7535
7713
|
ttlCaches = /* @__PURE__ */ new Set();
|
|
@@ -7545,7 +7723,7 @@ var pa = {
|
|
|
7545
7723
|
if (n.has(e)) throw Error(`Duplicate Codex backend module '${e}'`);
|
|
7546
7724
|
n.add(e);
|
|
7547
7725
|
}
|
|
7548
|
-
this.surface = e.surface ?? new
|
|
7726
|
+
this.surface = e.surface ?? new ya(e.surfaceOptions);
|
|
7549
7727
|
for (let { id: e, module: n } of t) this.moduleServices.set(e, n.create({
|
|
7550
7728
|
surface: this.surface,
|
|
7551
7729
|
closeBackend: () => this.close(),
|
|
@@ -7559,7 +7737,7 @@ var pa = {
|
|
|
7559
7737
|
}
|
|
7560
7738
|
createTtlCache(e) {
|
|
7561
7739
|
if (this.closePromise) throw Error("Cannot create a cache after the Codex backend is closed");
|
|
7562
|
-
let t = new
|
|
7740
|
+
let t = new Sa(e);
|
|
7563
7741
|
return this.ttlCaches.add(t), t;
|
|
7564
7742
|
}
|
|
7565
7743
|
close() {
|
|
@@ -7569,16 +7747,16 @@ var pa = {
|
|
|
7569
7747
|
await Promise.all([...this.ttlCaches].map((e) => e.close())), await this.surface.close();
|
|
7570
7748
|
}
|
|
7571
7749
|
};
|
|
7572
|
-
function
|
|
7573
|
-
return new
|
|
7750
|
+
function wa(e = {}) {
|
|
7751
|
+
return new Ca(e);
|
|
7574
7752
|
}
|
|
7575
7753
|
//#endregion
|
|
7576
7754
|
//#region src/node/apple-speech-transcription.ts
|
|
7577
|
-
async function
|
|
7755
|
+
async function Ta(e, t = {}, n = {}) {
|
|
7578
7756
|
let r = n.fs ?? l, i = n.spawn ?? o, a = n.tmpdir ?? f.tmpdir, s = await r.mkdtemp(h.join(a(), "codex-app-sdk-apple-stt-")), c = h.join(s, "input.wav"), u = h.join(s, "output.txt");
|
|
7579
7757
|
try {
|
|
7580
|
-
let a = await
|
|
7581
|
-
return await r.writeFile(c, e), await
|
|
7758
|
+
let a = await Aa(Ea(n.assetsPath), s, r);
|
|
7759
|
+
return await r.writeFile(c, e), await Oa(i, a, Da(c, u, t)), { text: (await r.readFile(u, "utf8")).trim() };
|
|
7582
7760
|
} catch (e) {
|
|
7583
7761
|
return {
|
|
7584
7762
|
text: "",
|
|
@@ -7591,10 +7769,10 @@ async function _a(e, t = {}, n = {}) {
|
|
|
7591
7769
|
});
|
|
7592
7770
|
}
|
|
7593
7771
|
}
|
|
7594
|
-
function
|
|
7595
|
-
return h.join(e ??
|
|
7772
|
+
function Ea(e, t = {}) {
|
|
7773
|
+
return h.join(e ?? ka(t), "apple-speechanalyzer-cli");
|
|
7596
7774
|
}
|
|
7597
|
-
function
|
|
7775
|
+
function Da(e, t, n) {
|
|
7598
7776
|
let r = [
|
|
7599
7777
|
"--input-audio-path",
|
|
7600
7778
|
e,
|
|
@@ -7603,7 +7781,7 @@ function ya(e, t, n) {
|
|
|
7603
7781
|
], i = n.locale?.trim();
|
|
7604
7782
|
return i && r.push("--locale", i), n.live && r.push("--live"), r;
|
|
7605
7783
|
}
|
|
7606
|
-
function
|
|
7784
|
+
function Oa(e, t, n) {
|
|
7607
7785
|
return new Promise((r, i) => {
|
|
7608
7786
|
let a = e(t, n), o = "";
|
|
7609
7787
|
a.stderr?.on("data", (e) => {
|
|
@@ -7619,7 +7797,7 @@ function ba(e, t, n) {
|
|
|
7619
7797
|
});
|
|
7620
7798
|
});
|
|
7621
7799
|
}
|
|
7622
|
-
function
|
|
7800
|
+
function ka(e) {
|
|
7623
7801
|
let t = (e.env ?? process.env).CODEX_APP_SDK_ASSETS_PATH?.trim();
|
|
7624
7802
|
if (t) return t;
|
|
7625
7803
|
let n = process.resourcesPath, r = e.resourcesPath === void 0 ? n : e.resourcesPath ?? void 0, i = e.existsSync ?? c;
|
|
@@ -7650,18 +7828,18 @@ function xa(e) {
|
|
|
7650
7828
|
let u = import.meta.url, d = e.moduleUrl === void 0 ? u : e.moduleUrl ?? void 0, f = d ? h.dirname(ne(d)) : s, p = [h.resolve(f, "../assets"), h.resolve(f, "../../assets")];
|
|
7651
7829
|
return p.find((e) => i(h.join(e, "apple-speechanalyzer-cli"))) ?? p[0];
|
|
7652
7830
|
}
|
|
7653
|
-
async function
|
|
7831
|
+
async function Aa(e, t, n) {
|
|
7654
7832
|
let r = h.join(t, "apple-speechanalyzer-cli");
|
|
7655
7833
|
return await n.copyFile(e, r), await n.chmod(r, 448), r;
|
|
7656
7834
|
}
|
|
7657
7835
|
//#endregion
|
|
7658
7836
|
//#region src/node/apple-speech-session.ts
|
|
7659
|
-
async function
|
|
7837
|
+
async function ja(e, t, n = {}) {
|
|
7660
7838
|
if (n.signal?.throwIfAborted(), !Number.isInteger(e.sampleRate) || e.sampleRate < 8e3 || e.sampleRate > 96e3) throw Error("Unsupported speech sample rate.");
|
|
7661
7839
|
let r = await se(h.join(m(), "codex-sdk-live-speech-")), i;
|
|
7662
7840
|
try {
|
|
7663
7841
|
let t = h.join(r, "apple-speechanalyzer-cli");
|
|
7664
|
-
await oe(
|
|
7842
|
+
await oe(Ea(n.assetsPath), t), await ae(t, 448), n.signal?.throwIfAborted(), i = (n.spawn ?? o)(t, [
|
|
7665
7843
|
"--stream",
|
|
7666
7844
|
"--sample-rate",
|
|
7667
7845
|
String(e.sampleRate),
|
|
@@ -7763,6 +7941,6 @@ async function Ca(e, t, n = {}) {
|
|
|
7763
7941
|
};
|
|
7764
7942
|
}
|
|
7765
7943
|
//#endregion
|
|
7766
|
-
export {
|
|
7944
|
+
export { Ca as CodexAppBackend, Sa as CodexAppBackendTtlCache, Ve as CodexAppServerStdioTransport, Ke as CodexAppServerUnixSocketTransport, ya as CodexSurface, _r as codexItemToMediaPart, hr as codexItemToSurfaceMessage, L as codexItemToToolPart, me as codexRuntimePathEntries, fr as codexThreadToSurfaceMessages, mr as codexTurnToSurfaceMessages, wa as createCodexAppBackend, ba as createCodexSurface, pe as discoverCodexExecutable, pr as preserveHistoricalAttachmentPreviews, Ea as resolveAppleSpeechAnalyzerPath, ge as resolveCodexRuntime, ja as startAppleSpeechSession, Ta as transcribeWithAppleSpeechAnalyzer, he as withCodexRuntimePath };
|
|
7767
7945
|
|
|
7768
7946
|
//# sourceMappingURL=index.js.map
|