@liberseek/boft-cli-win32-arm64 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/host-runtime.mjs +315 -175
- package/app/plugins/antigravity/plugin.mjs +18 -2
- package/app/plugins/claude-code/plugin.mjs +239 -37
- package/app/plugins/deepseek-harness/plugin.mjs +18 -2
- package/app/plugins/grok/plugin.mjs +1982 -1602
- package/app/plugins/omp/plugin.mjs +18 -2
- package/app/plugins/opencode/plugin.mjs +18 -2
- package/app/plugins/pi/plugin.mjs +18 -2
- package/app/renderer-extension.js +87 -6
- package/bin/codexhost.exe +0 -0
- package/libexec/codexhost-node-repl.exe +0 -0
- package/libexec/codexhost-shim.exe +0 -0
- package/libexec/codexhost-updater.exe +0 -0
- package/package.json +1 -1
package/app/host-runtime.mjs
CHANGED
|
@@ -5002,6 +5002,9 @@ function parseModelProviderAuth(source) {
|
|
|
5002
5002
|
const tables = tomlProviderTableNames(providerId);
|
|
5003
5003
|
let currentTable = "";
|
|
5004
5004
|
let name;
|
|
5005
|
+
let baseUrl;
|
|
5006
|
+
let bearerToken;
|
|
5007
|
+
let envKey;
|
|
5005
5008
|
let requiresOpenAiAuth;
|
|
5006
5009
|
let hasLocalApiCredential = false;
|
|
5007
5010
|
for (const rawLine of source.split(/\r?\n/u)) {
|
|
@@ -5018,14 +5021,23 @@ function parseModelProviderAuth(source) {
|
|
|
5018
5021
|
const key = assignment[1] ?? "";
|
|
5019
5022
|
const value2 = tomlUnquote(assignment[2] ?? "");
|
|
5020
5023
|
if (key === "name" && value2) name = value2;
|
|
5024
|
+
if (key === "base_url" && value2) baseUrl = value2;
|
|
5021
5025
|
if (key === "requires_openai_auth") requiresOpenAiAuth = tomlBoolean(value2);
|
|
5022
|
-
if (
|
|
5026
|
+
if (key === "experimental_bearer_token" && value2.trim().length > 0) {
|
|
5027
|
+
bearerToken = value2.trim();
|
|
5028
|
+
hasLocalApiCredential = true;
|
|
5029
|
+
}
|
|
5030
|
+
if (key === "env_key" && value2.trim().length > 0) {
|
|
5031
|
+
envKey = value2.trim();
|
|
5023
5032
|
hasLocalApiCredential = true;
|
|
5024
5033
|
}
|
|
5025
5034
|
}
|
|
5026
5035
|
return {
|
|
5027
5036
|
id: providerId,
|
|
5028
5037
|
...name ? { name } : {},
|
|
5038
|
+
...baseUrl ? { baseUrl } : {},
|
|
5039
|
+
...bearerToken ? { bearerToken } : {},
|
|
5040
|
+
...envKey ? { envKey } : {},
|
|
5029
5041
|
requiresOpenAiAuth: requiresOpenAiAuth ?? providerId === "openai",
|
|
5030
5042
|
hasLocalApiCredential
|
|
5031
5043
|
};
|
|
@@ -5069,6 +5081,24 @@ async function readOptionalUtf8(file2) {
|
|
|
5069
5081
|
throw error51;
|
|
5070
5082
|
}
|
|
5071
5083
|
}
|
|
5084
|
+
function authJsonApiKey(authJson) {
|
|
5085
|
+
if (!authJson) return void 0;
|
|
5086
|
+
try {
|
|
5087
|
+
const auth = JSON.parse(authJson);
|
|
5088
|
+
return typeof auth.api_key === "string" && auth.api_key.trim() ? auth.api_key.trim() : void 0;
|
|
5089
|
+
} catch {
|
|
5090
|
+
return void 0;
|
|
5091
|
+
}
|
|
5092
|
+
}
|
|
5093
|
+
function inspectCodexApiUsageSource(input) {
|
|
5094
|
+
const provider = parseModelProviderAuth(input.configToml);
|
|
5095
|
+
const baseUrl = provider?.baseUrl?.trim();
|
|
5096
|
+
if (!baseUrl) return null;
|
|
5097
|
+
const env = input.env ?? process.env;
|
|
5098
|
+
const apiKey = provider?.bearerToken?.trim() || authJsonApiKey(input.authJson) || (provider?.envKey ? env[provider.envKey]?.trim() : void 0);
|
|
5099
|
+
if (!apiKey) return null;
|
|
5100
|
+
return { baseUrl, apiKey };
|
|
5101
|
+
}
|
|
5072
5102
|
async function inspectCodexHomeAuth(codexHome) {
|
|
5073
5103
|
const root = path4.resolve(codexHome);
|
|
5074
5104
|
const [configToml, authJson] = await Promise.all([
|
|
@@ -5080,6 +5110,87 @@ async function inspectCodexHomeAuth(codexHome) {
|
|
|
5080
5110
|
...authJson ? { authJson } : {}
|
|
5081
5111
|
});
|
|
5082
5112
|
}
|
|
5113
|
+
async function inspectCodexHomeApiUsageSource(codexHome, env = process.env) {
|
|
5114
|
+
const root = path4.resolve(codexHome);
|
|
5115
|
+
const [configToml, authJson] = await Promise.all([
|
|
5116
|
+
readOptionalUtf8(path4.join(root, "config.toml")),
|
|
5117
|
+
readOptionalUtf8(path4.join(root, "auth.json"))
|
|
5118
|
+
]);
|
|
5119
|
+
return inspectCodexApiUsageSource({
|
|
5120
|
+
...configToml ? { configToml } : {},
|
|
5121
|
+
...authJson ? { authJson } : {},
|
|
5122
|
+
env
|
|
5123
|
+
});
|
|
5124
|
+
}
|
|
5125
|
+
|
|
5126
|
+
// packages/host-runtime/src/account/codex-api-usage.ts
|
|
5127
|
+
var REQUEST_TIMEOUT_MS = 15e3;
|
|
5128
|
+
function isRecord(value2) {
|
|
5129
|
+
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
5130
|
+
}
|
|
5131
|
+
function finiteNumber(value2) {
|
|
5132
|
+
if (typeof value2 === "number" && Number.isFinite(value2)) return value2;
|
|
5133
|
+
if (typeof value2 === "string" && value2.trim()) {
|
|
5134
|
+
const parsed = Number(value2);
|
|
5135
|
+
if (Number.isFinite(parsed)) return parsed;
|
|
5136
|
+
}
|
|
5137
|
+
return void 0;
|
|
5138
|
+
}
|
|
5139
|
+
function text(value2) {
|
|
5140
|
+
return typeof value2 === "string" && value2.trim() ? value2.trim() : void 0;
|
|
5141
|
+
}
|
|
5142
|
+
function boolean(value2) {
|
|
5143
|
+
return typeof value2 === "boolean" ? value2 : void 0;
|
|
5144
|
+
}
|
|
5145
|
+
function codexApiUsageUrl(baseUrl) {
|
|
5146
|
+
const trimmed = baseUrl.trim().replace(/\/+$/u, "");
|
|
5147
|
+
if (!trimmed) throw new Error("Codex API usage base URL is empty");
|
|
5148
|
+
const withPath = /\/v1$/iu.test(trimmed) ? `${trimmed}/usage` : `${trimmed}/v1/usage`;
|
|
5149
|
+
const parsed = new URL(withPath);
|
|
5150
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
5151
|
+
throw new Error("Codex API usage URL must be http or https");
|
|
5152
|
+
}
|
|
5153
|
+
return parsed.toString();
|
|
5154
|
+
}
|
|
5155
|
+
function extractCodexApiUsage(response) {
|
|
5156
|
+
if (!isRecord(response)) return null;
|
|
5157
|
+
const quota = isRecord(response.quota) ? response.quota : void 0;
|
|
5158
|
+
const remaining = finiteNumber(response.remaining) ?? finiteNumber(quota?.remaining) ?? finiteNumber(response.balance);
|
|
5159
|
+
if (remaining === void 0) return null;
|
|
5160
|
+
const isValid = boolean(response.is_active) ?? boolean(response.isValid) ?? true;
|
|
5161
|
+
if (!isValid) throw new Error("Codex API usage is inactive");
|
|
5162
|
+
return {
|
|
5163
|
+
remaining,
|
|
5164
|
+
unit: text(response.unit) ?? text(quota?.unit) ?? "USD"
|
|
5165
|
+
};
|
|
5166
|
+
}
|
|
5167
|
+
function projectCodexApiUsageToCredits(usage) {
|
|
5168
|
+
return {
|
|
5169
|
+
remaining: usage.remaining,
|
|
5170
|
+
unit: usage.unit,
|
|
5171
|
+
periodType: "unknown"
|
|
5172
|
+
};
|
|
5173
|
+
}
|
|
5174
|
+
async function inspectCodexApiAccountCredits(codexHome, input = {}) {
|
|
5175
|
+
const source = input.source === void 0 ? await inspectCodexHomeApiUsageSource(codexHome, input.env) : input.source;
|
|
5176
|
+
if (!source) return null;
|
|
5177
|
+
const fetchImpl = input.fetch ?? fetch;
|
|
5178
|
+
const timeout = AbortSignal.timeout(REQUEST_TIMEOUT_MS);
|
|
5179
|
+
const signal = input.signal ? AbortSignal.any([input.signal, timeout]) : timeout;
|
|
5180
|
+
const response = await fetchImpl(codexApiUsageUrl(source.baseUrl), {
|
|
5181
|
+
method: "GET",
|
|
5182
|
+
headers: {
|
|
5183
|
+
Accept: "application/json",
|
|
5184
|
+
Authorization: `Bearer ${source.apiKey}`
|
|
5185
|
+
},
|
|
5186
|
+
signal
|
|
5187
|
+
});
|
|
5188
|
+
if (!response.ok) {
|
|
5189
|
+
throw new Error(`Codex API usage request failed (${response.status})`);
|
|
5190
|
+
}
|
|
5191
|
+
const usage = extractCodexApiUsage(await response.json());
|
|
5192
|
+
return usage ? projectCodexApiUsageToCredits(usage) : null;
|
|
5193
|
+
}
|
|
5083
5194
|
|
|
5084
5195
|
// node_modules/zod/v4/classic/external.js
|
|
5085
5196
|
var external_exports = {};
|
|
@@ -5174,7 +5285,7 @@ __export(external_exports, {
|
|
|
5174
5285
|
base64: () => base642,
|
|
5175
5286
|
base64url: () => base64url2,
|
|
5176
5287
|
bigint: () => bigint2,
|
|
5177
|
-
boolean: () =>
|
|
5288
|
+
boolean: () => boolean3,
|
|
5178
5289
|
catch: () => _catch2,
|
|
5179
5290
|
check: () => check,
|
|
5180
5291
|
cidrv4: () => cidrv42,
|
|
@@ -6609,7 +6720,7 @@ __export(regexes_exports, {
|
|
|
6609
6720
|
base64: () => base64,
|
|
6610
6721
|
base64url: () => base64url,
|
|
6611
6722
|
bigint: () => bigint,
|
|
6612
|
-
boolean: () =>
|
|
6723
|
+
boolean: () => boolean2,
|
|
6613
6724
|
browserEmail: () => browserEmail,
|
|
6614
6725
|
cidrv4: () => cidrv4,
|
|
6615
6726
|
cidrv6: () => cidrv6,
|
|
@@ -6734,7 +6845,7 @@ var string = (params) => {
|
|
|
6734
6845
|
var bigint = /^-?\d+n?$/;
|
|
6735
6846
|
var integer = /^-?\d+$/;
|
|
6736
6847
|
var number = /^-?\d+(?:\.\d+)?$/;
|
|
6737
|
-
var
|
|
6848
|
+
var boolean2 = /^(?:true|false)$/i;
|
|
6738
6849
|
var _null = /^null$/i;
|
|
6739
6850
|
var _undefined = /^undefined$/i;
|
|
6740
6851
|
var lowercase = /^[^A-Z]*$/;
|
|
@@ -7820,7 +7931,7 @@ var $ZodNumberFormat = /* @__PURE__ */ $constructor("$ZodNumberFormat", (inst, d
|
|
|
7820
7931
|
});
|
|
7821
7932
|
var $ZodBoolean = /* @__PURE__ */ $constructor("$ZodBoolean", (inst, def) => {
|
|
7822
7933
|
$ZodType.init(inst, def);
|
|
7823
|
-
inst._zod.pattern =
|
|
7934
|
+
inst._zod.pattern = boolean2;
|
|
7824
7935
|
inst._zod.parse = (payload, _ctx) => {
|
|
7825
7936
|
if (def.coerce)
|
|
7826
7937
|
try {
|
|
@@ -12719,8 +12830,8 @@ function ko_default() {
|
|
|
12719
12830
|
}
|
|
12720
12831
|
|
|
12721
12832
|
// node_modules/zod/v4/locales/lt.js
|
|
12722
|
-
var capitalizeFirstCharacter = (
|
|
12723
|
-
return
|
|
12833
|
+
var capitalizeFirstCharacter = (text2) => {
|
|
12834
|
+
return text2.charAt(0).toUpperCase() + text2.slice(1);
|
|
12724
12835
|
};
|
|
12725
12836
|
function getUnitTypeFromNumber(number4) {
|
|
12726
12837
|
const abs = Math.abs(number4);
|
|
@@ -17551,7 +17662,7 @@ __export(schemas_exports2, {
|
|
|
17551
17662
|
base64: () => base642,
|
|
17552
17663
|
base64url: () => base64url2,
|
|
17553
17664
|
bigint: () => bigint2,
|
|
17554
|
-
boolean: () =>
|
|
17665
|
+
boolean: () => boolean3,
|
|
17555
17666
|
catch: () => _catch2,
|
|
17556
17667
|
check: () => check,
|
|
17557
17668
|
cidrv4: () => cidrv42,
|
|
@@ -18294,7 +18405,7 @@ var ZodBoolean = /* @__PURE__ */ $constructor("ZodBoolean", (inst, def) => {
|
|
|
18294
18405
|
ZodType.init(inst, def);
|
|
18295
18406
|
inst._zod.processJSONSchema = (ctx, json2, params) => booleanProcessor(inst, ctx, json2, params);
|
|
18296
18407
|
});
|
|
18297
|
-
function
|
|
18408
|
+
function boolean3(params) {
|
|
18298
18409
|
return _boolean(ZodBoolean, params);
|
|
18299
18410
|
}
|
|
18300
18411
|
var ZodBigInt = /* @__PURE__ */ $constructor("ZodBigInt", (inst, def) => {
|
|
@@ -19049,7 +19160,7 @@ var stringbool = (...args) => _stringbool({
|
|
|
19049
19160
|
}, ...args);
|
|
19050
19161
|
function json(params) {
|
|
19051
19162
|
const jsonSchema = lazy(() => {
|
|
19052
|
-
return union([string2(params), number2(),
|
|
19163
|
+
return union([string2(params), number2(), boolean3(), _null3(), array(jsonSchema), record2(string2(), jsonSchema)]);
|
|
19053
19164
|
});
|
|
19054
19165
|
return jsonSchema;
|
|
19055
19166
|
}
|
|
@@ -19571,7 +19682,7 @@ function fromJSONSchema(schema, params) {
|
|
|
19571
19682
|
var coerce_exports = {};
|
|
19572
19683
|
__export(coerce_exports, {
|
|
19573
19684
|
bigint: () => bigint3,
|
|
19574
|
-
boolean: () =>
|
|
19685
|
+
boolean: () => boolean4,
|
|
19575
19686
|
date: () => date4,
|
|
19576
19687
|
number: () => number3,
|
|
19577
19688
|
string: () => string3
|
|
@@ -19582,7 +19693,7 @@ function string3(params) {
|
|
|
19582
19693
|
function number3(params) {
|
|
19583
19694
|
return _coercedNumber(ZodNumber, params);
|
|
19584
19695
|
}
|
|
19585
|
-
function
|
|
19696
|
+
function boolean4(params) {
|
|
19586
19697
|
return _coercedBoolean(ZodBoolean, params);
|
|
19587
19698
|
}
|
|
19588
19699
|
function bigint3(params) {
|
|
@@ -19677,12 +19788,28 @@ var accountResetCreditsSchema = external_exports.object({
|
|
|
19677
19788
|
var accountCreditsSnapshotSchema = external_exports.object({
|
|
19678
19789
|
/** Native label when the primary limit is scoped to a model or product group. */
|
|
19679
19790
|
label: external_exports.string().min(1).optional(),
|
|
19680
|
-
usedPercent: usagePercentSchema,
|
|
19791
|
+
usedPercent: usagePercentSchema.optional(),
|
|
19792
|
+
remaining: external_exports.number().finite().optional(),
|
|
19793
|
+
unit: external_exports.string().trim().min(1).max(32).optional(),
|
|
19681
19794
|
resetsAt: external_exports.string().min(1).optional(),
|
|
19682
19795
|
periodType: external_exports.enum(["weekly", "monthly", "five_hour", "seven_day", "unknown"]),
|
|
19683
19796
|
productUsage: external_exports.array(accountCreditsProductUsageSchema).min(1).optional(),
|
|
19684
19797
|
resetCredits: accountResetCreditsSchema.optional()
|
|
19685
|
-
}).strict()
|
|
19798
|
+
}).strict().superRefine((credits, context) => {
|
|
19799
|
+
if (credits.usedPercent === void 0 && credits.remaining === void 0) {
|
|
19800
|
+
context.addIssue({
|
|
19801
|
+
code: "custom",
|
|
19802
|
+
message: "Account credits must include usedPercent or remaining"
|
|
19803
|
+
});
|
|
19804
|
+
}
|
|
19805
|
+
if (credits.remaining !== void 0 && !credits.unit) {
|
|
19806
|
+
context.addIssue({
|
|
19807
|
+
code: "custom",
|
|
19808
|
+
message: "Account remaining credits require a unit",
|
|
19809
|
+
path: ["unit"]
|
|
19810
|
+
});
|
|
19811
|
+
}
|
|
19812
|
+
});
|
|
19686
19813
|
var threadUsageInspectionParamsSchema = external_exports.object({
|
|
19687
19814
|
threadId: hostThreadIdSchema,
|
|
19688
19815
|
refresh: external_exports.literal("exact").optional()
|
|
@@ -20542,11 +20669,11 @@ var usageFields = /* @__PURE__ */ new Set([
|
|
|
20542
20669
|
...percentFields,
|
|
20543
20670
|
"totalCostUsd"
|
|
20544
20671
|
]);
|
|
20545
|
-
function
|
|
20672
|
+
function isRecord2(value2) {
|
|
20546
20673
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
20547
20674
|
}
|
|
20548
20675
|
function parseHostUsage(value2) {
|
|
20549
|
-
if (!
|
|
20676
|
+
if (!isRecord2(value2))
|
|
20550
20677
|
throw new Error("Harness Usage must be an object");
|
|
20551
20678
|
const keys = Object.keys(value2);
|
|
20552
20679
|
if (keys.length === 0)
|
|
@@ -21448,24 +21575,24 @@ var TITLE_MAX_LENGTH = 150;
|
|
|
21448
21575
|
var DESCRIPTION_MAX_LENGTH = 500;
|
|
21449
21576
|
var SERVER_NAME_MAX_LENGTH = 80;
|
|
21450
21577
|
var ELLIPSIS = "…";
|
|
21451
|
-
function
|
|
21578
|
+
function isRecord3(value2) {
|
|
21452
21579
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
21453
21580
|
}
|
|
21454
21581
|
function boundedText(value2, field, maxLength) {
|
|
21455
|
-
const
|
|
21456
|
-
if (
|
|
21582
|
+
const text2 = value2.trim();
|
|
21583
|
+
if (text2.length === 0 || text2.length > maxLength) {
|
|
21457
21584
|
throw new Error(`Host Approval ${field} must contain 1 to ${maxLength} characters`);
|
|
21458
21585
|
}
|
|
21459
|
-
return
|
|
21586
|
+
return text2;
|
|
21460
21587
|
}
|
|
21461
21588
|
function clampedText(value2, field, maxLength) {
|
|
21462
|
-
const
|
|
21463
|
-
if (
|
|
21589
|
+
const text2 = value2.trim();
|
|
21590
|
+
if (text2.length === 0) {
|
|
21464
21591
|
throw new Error(`Host Approval ${field} must contain at least 1 character`);
|
|
21465
21592
|
}
|
|
21466
|
-
const characters = [...
|
|
21593
|
+
const characters = [...text2];
|
|
21467
21594
|
if (characters.length <= maxLength)
|
|
21468
|
-
return
|
|
21595
|
+
return text2;
|
|
21469
21596
|
return `${characters.slice(0, maxLength - 1).join("").trimEnd()}${ELLIPSIS}`;
|
|
21470
21597
|
}
|
|
21471
21598
|
function actionsForEffect(interaction, effect) {
|
|
@@ -21502,7 +21629,7 @@ function responseError(message) {
|
|
|
21502
21629
|
function responsePersist(value2) {
|
|
21503
21630
|
if (value2 === void 0 || value2 === null)
|
|
21504
21631
|
return null;
|
|
21505
|
-
if (!
|
|
21632
|
+
if (!isRecord3(value2) || Object.keys(value2).length !== 1 || value2.persist !== "session" && value2.persist !== "always") {
|
|
21506
21633
|
throw responseError("contains malformed persist metadata");
|
|
21507
21634
|
}
|
|
21508
21635
|
return value2.persist;
|
|
@@ -21545,7 +21672,7 @@ function projectCodexApprovalRequest(input) {
|
|
|
21545
21672
|
},
|
|
21546
21673
|
denyResponse,
|
|
21547
21674
|
parseResponse(result) {
|
|
21548
|
-
if (!
|
|
21675
|
+
if (!isRecord3(result) || typeof result.action !== "string") {
|
|
21549
21676
|
throw responseError("missing action");
|
|
21550
21677
|
}
|
|
21551
21678
|
if (Object.keys(result).some((key) => key !== "action" && key !== "content" && key !== "_meta")) {
|
|
@@ -21553,7 +21680,7 @@ function projectCodexApprovalRequest(input) {
|
|
|
21553
21680
|
}
|
|
21554
21681
|
const selectedPersist = responsePersist(result._meta);
|
|
21555
21682
|
if (result.action === "accept") {
|
|
21556
|
-
if ("content" in result && (!
|
|
21683
|
+
if ("content" in result && (!isRecord3(result.content) || Object.keys(result.content).length !== 0)) {
|
|
21557
21684
|
throw responseError("contains non-empty accepted content");
|
|
21558
21685
|
}
|
|
21559
21686
|
if (selectedPersist === "session") {
|
|
@@ -21580,7 +21707,7 @@ function projectCodexApprovalRequest(input) {
|
|
|
21580
21707
|
}
|
|
21581
21708
|
|
|
21582
21709
|
// packages/protocol-core/dist/codex-question.js
|
|
21583
|
-
function
|
|
21710
|
+
function isRecord4(value2) {
|
|
21584
21711
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
21585
21712
|
}
|
|
21586
21713
|
function responseError2(message) {
|
|
@@ -21649,7 +21776,7 @@ function projectCodexQuestionRequest(input) {
|
|
|
21649
21776
|
}
|
|
21650
21777
|
},
|
|
21651
21778
|
parseResponse(result) {
|
|
21652
|
-
if (!
|
|
21779
|
+
if (!isRecord4(result) || !isRecord4(result.answers)) {
|
|
21653
21780
|
throw responseError2("missing answers object");
|
|
21654
21781
|
}
|
|
21655
21782
|
const rawAnswers = result.answers;
|
|
@@ -21662,7 +21789,7 @@ function projectCodexQuestionRequest(input) {
|
|
|
21662
21789
|
const question = interaction.questions.find(({ id: id2 }) => id2 === questionId);
|
|
21663
21790
|
if (!question)
|
|
21664
21791
|
throw responseError2("contains an unknown Question ID");
|
|
21665
|
-
if (!
|
|
21792
|
+
if (!isRecord4(answerValue) || !Array.isArray(answerValue.answers)) {
|
|
21666
21793
|
throw responseError2("answer entry has no answers array");
|
|
21667
21794
|
}
|
|
21668
21795
|
const values = answerValue.answers;
|
|
@@ -21747,7 +21874,7 @@ function projectCodexThreadUsage(input) {
|
|
|
21747
21874
|
}
|
|
21748
21875
|
|
|
21749
21876
|
// packages/protocol-core/dist/codex-native-usage.js
|
|
21750
|
-
function
|
|
21877
|
+
function isRecord5(value2) {
|
|
21751
21878
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
21752
21879
|
}
|
|
21753
21880
|
function nonNegativeSafeInteger(value2) {
|
|
@@ -21777,20 +21904,20 @@ function addBreakdown(target, source) {
|
|
|
21777
21904
|
}
|
|
21778
21905
|
}
|
|
21779
21906
|
function observeCodexTokenUsage(value2) {
|
|
21780
|
-
if (!
|
|
21907
|
+
if (!isRecord5(value2) || value2.method !== "thread/tokenUsage/updated")
|
|
21781
21908
|
return null;
|
|
21782
21909
|
const params = value2.params;
|
|
21783
|
-
if (!
|
|
21910
|
+
if (!isRecord5(params))
|
|
21784
21911
|
return null;
|
|
21785
21912
|
const threadId3 = hostThreadIdSchema.safeParse(params.threadId);
|
|
21786
21913
|
const turnId = hostTurnIdSchema.safeParse(params.turnId);
|
|
21787
21914
|
if (!threadId3.success || !turnId.success)
|
|
21788
21915
|
return null;
|
|
21789
21916
|
const tokenUsage = params.tokenUsage;
|
|
21790
|
-
if (!
|
|
21917
|
+
if (!isRecord5(tokenUsage))
|
|
21791
21918
|
return null;
|
|
21792
|
-
const total =
|
|
21793
|
-
const last =
|
|
21919
|
+
const total = isRecord5(tokenUsage.total) ? tokenUsage.total : void 0;
|
|
21920
|
+
const last = isRecord5(tokenUsage.last) ? tokenUsage.last : void 0;
|
|
21794
21921
|
const usage = {};
|
|
21795
21922
|
addBreakdown(usage, total);
|
|
21796
21923
|
const contextUsedTokens = nonNegativeSafeInteger(last?.totalTokens);
|
|
@@ -21815,7 +21942,7 @@ function observeCodexTokenUsage(value2) {
|
|
|
21815
21942
|
}
|
|
21816
21943
|
}
|
|
21817
21944
|
function parseRateLimitWindow(value2) {
|
|
21818
|
-
if (!
|
|
21945
|
+
if (!isRecord5(value2))
|
|
21819
21946
|
return null;
|
|
21820
21947
|
const usedPercent = finitePercent(value2.usedPercent);
|
|
21821
21948
|
const windowDurationMins = nonNegativeSafeInteger(value2.windowDurationMins);
|
|
@@ -21826,7 +21953,7 @@ function parseRateLimitWindow(value2) {
|
|
|
21826
21953
|
return { usedPercent, windowDurationMins, ...resetsAt !== void 0 ? { resetsAt } : {} };
|
|
21827
21954
|
}
|
|
21828
21955
|
function parseRateLimitCandidate(value2, options2 = {}) {
|
|
21829
|
-
if (!
|
|
21956
|
+
if (!isRecord5(value2))
|
|
21830
21957
|
return null;
|
|
21831
21958
|
if (options2.genericOnly && value2.limitId !== void 0 && value2.limitId !== null && value2.limitId !== "codex") {
|
|
21832
21959
|
return null;
|
|
@@ -21836,16 +21963,16 @@ function parseRateLimitCandidate(value2, options2 = {}) {
|
|
|
21836
21963
|
return primary || secondary ? { primary, secondary } : null;
|
|
21837
21964
|
}
|
|
21838
21965
|
function rateLimitCandidates(value2) {
|
|
21839
|
-
if (!
|
|
21966
|
+
if (!isRecord5(value2))
|
|
21840
21967
|
return [];
|
|
21841
|
-
const result =
|
|
21842
|
-
if (!
|
|
21968
|
+
const result = isRecord5(value2.result) ? value2.result : value2;
|
|
21969
|
+
if (!isRecord5(result))
|
|
21843
21970
|
return [];
|
|
21844
21971
|
const candidates = [];
|
|
21845
21972
|
const base = parseRateLimitCandidate(result.rateLimits, { genericOnly: true });
|
|
21846
21973
|
if (base)
|
|
21847
21974
|
candidates.push(base);
|
|
21848
|
-
const notificationParams =
|
|
21975
|
+
const notificationParams = isRecord5(value2.params) ? value2.params : void 0;
|
|
21849
21976
|
const notificationSnapshot = parseRateLimitCandidate(notificationParams?.rateLimits, {
|
|
21850
21977
|
genericOnly: true
|
|
21851
21978
|
});
|
|
@@ -21889,14 +22016,14 @@ function parseAvailableCount(value2) {
|
|
|
21889
22016
|
return void 0;
|
|
21890
22017
|
}
|
|
21891
22018
|
function rateLimitResetCreditsSummary(value2) {
|
|
21892
|
-
if (!
|
|
22019
|
+
if (!isRecord5(value2))
|
|
21893
22020
|
return null;
|
|
21894
|
-
const result =
|
|
21895
|
-
const fromResult =
|
|
22021
|
+
const result = isRecord5(value2.result) ? value2.result : value2;
|
|
22022
|
+
const fromResult = isRecord5(result) && isRecord5(result.rateLimitResetCredits) ? result.rateLimitResetCredits : null;
|
|
21896
22023
|
if (fromResult)
|
|
21897
22024
|
return fromResult;
|
|
21898
|
-
const params =
|
|
21899
|
-
return
|
|
22025
|
+
const params = isRecord5(value2.params) ? value2.params : void 0;
|
|
22026
|
+
return isRecord5(params?.rateLimitResetCredits) ? params.rateLimitResetCredits : null;
|
|
21900
22027
|
}
|
|
21901
22028
|
function observeCodexRateLimitResetCredits(value2) {
|
|
21902
22029
|
const summary = rateLimitResetCreditsSummary(value2);
|
|
@@ -21908,7 +22035,7 @@ function observeCodexRateLimitResetCredits(value2) {
|
|
|
21908
22035
|
const expiresAtUnix = [];
|
|
21909
22036
|
if (Array.isArray(summary.credits)) {
|
|
21910
22037
|
for (const credit of summary.credits) {
|
|
21911
|
-
if (!
|
|
22038
|
+
if (!isRecord5(credit))
|
|
21912
22039
|
continue;
|
|
21913
22040
|
if (credit.status !== void 0 && credit.status !== "available")
|
|
21914
22041
|
continue;
|
|
@@ -21977,11 +22104,11 @@ function itemStatus(outcome) {
|
|
|
21977
22104
|
return "inProgress";
|
|
21978
22105
|
return outcome.status === "succeeded" ? "completed" : "failed";
|
|
21979
22106
|
}
|
|
21980
|
-
function
|
|
22107
|
+
function isRecord6(value2) {
|
|
21981
22108
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
21982
22109
|
}
|
|
21983
22110
|
function nestedString(value2, keys) {
|
|
21984
|
-
if (!
|
|
22111
|
+
if (!isRecord6(value2))
|
|
21985
22112
|
return void 0;
|
|
21986
22113
|
for (const key of keys) {
|
|
21987
22114
|
const field = value2[key];
|
|
@@ -21998,8 +22125,8 @@ function nestedString(value2, keys) {
|
|
|
21998
22125
|
function toolOutputText(item) {
|
|
21999
22126
|
if (!item.output)
|
|
22000
22127
|
return null;
|
|
22001
|
-
const
|
|
22002
|
-
return
|
|
22128
|
+
const text2 = item.output.content.filter((content) => content.type === "text").map(({ text: text3 }) => text3).join("");
|
|
22129
|
+
return text2.length > 0 ? text2 : null;
|
|
22003
22130
|
}
|
|
22004
22131
|
function toolCommandLine(toolName, args) {
|
|
22005
22132
|
const lower = toolName.toLowerCase().replaceAll(/[_-]/g, "");
|
|
@@ -22153,8 +22280,8 @@ function planFromTodoValue(value2) {
|
|
|
22153
22280
|
if (value2 && typeof value2 === "object" && "content" in value2 && Array.isArray(value2.content)) {
|
|
22154
22281
|
const output = value2;
|
|
22155
22282
|
if (output) {
|
|
22156
|
-
const
|
|
22157
|
-
const fromText = planFromChecklistText(
|
|
22283
|
+
const text2 = output.content.flatMap((entry) => entry.type === "text" ? [entry.text] : []).join("\n");
|
|
22284
|
+
const fromText = planFromChecklistText(text2);
|
|
22158
22285
|
if (fromText)
|
|
22159
22286
|
return fromText;
|
|
22160
22287
|
}
|
|
@@ -22162,7 +22289,7 @@ function planFromTodoValue(value2) {
|
|
|
22162
22289
|
const record3 = unwrapToolRecord(value2);
|
|
22163
22290
|
if (!record3)
|
|
22164
22291
|
return planFromChecklistText(typeof value2 === "string" ? value2 : null);
|
|
22165
|
-
if (
|
|
22292
|
+
if (isRecord6(record3.TodosUpdated)) {
|
|
22166
22293
|
const nested = planFromTodoValue(record3.TodosUpdated);
|
|
22167
22294
|
if (nested)
|
|
22168
22295
|
return nested;
|
|
@@ -22177,7 +22304,7 @@ function planFromTodoValue(value2) {
|
|
|
22177
22304
|
plan.push({ step: entry.trim(), status: "pending" });
|
|
22178
22305
|
continue;
|
|
22179
22306
|
}
|
|
22180
|
-
if (!
|
|
22307
|
+
if (!isRecord6(entry))
|
|
22181
22308
|
continue;
|
|
22182
22309
|
const step = nestedString(entry, ["content", "step", "text", "title", "description", "task"]);
|
|
22183
22310
|
if (!step)
|
|
@@ -22232,7 +22359,7 @@ function unwrapToolRecord(value2) {
|
|
|
22232
22359
|
}
|
|
22233
22360
|
if (Array.isArray(value2))
|
|
22234
22361
|
return { todos: value2 };
|
|
22235
|
-
if (!
|
|
22362
|
+
if (!isRecord6(value2))
|
|
22236
22363
|
return null;
|
|
22237
22364
|
for (const wrapper of ["input", "arguments", "params"]) {
|
|
22238
22365
|
if (value2[wrapper] === void 0)
|
|
@@ -22714,10 +22841,10 @@ var CodexTurnProjector = class {
|
|
|
22714
22841
|
});
|
|
22715
22842
|
} else if (event.update.type === "output.replace") {
|
|
22716
22843
|
if (next.type === "toolExecution" && toolCommandLine(next.toolName, next.arguments)) {
|
|
22717
|
-
const
|
|
22718
|
-
if (
|
|
22844
|
+
const text2 = toolOutputText(next);
|
|
22845
|
+
if (text2) {
|
|
22719
22846
|
const previousText = previous.type === "toolExecution" ? toolOutputText(previous) ?? "" : "";
|
|
22720
|
-
const delta =
|
|
22847
|
+
const delta = text2.startsWith(previousText) ? text2.slice(previousText.length) : text2;
|
|
22721
22848
|
if (delta.length > 0) {
|
|
22722
22849
|
projected.streamedCommandOutput = true;
|
|
22723
22850
|
messages.push({
|
|
@@ -23041,7 +23168,7 @@ var CodexTurnProjector = class {
|
|
|
23041
23168
|
};
|
|
23042
23169
|
|
|
23043
23170
|
// packages/protocol-core/dist/thread-fork.js
|
|
23044
|
-
function
|
|
23171
|
+
function isRecord7(value2) {
|
|
23045
23172
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
23046
23173
|
}
|
|
23047
23174
|
function optionalText(params, name, options2 = {}) {
|
|
@@ -23064,7 +23191,7 @@ function optionalBoolean(params, name) {
|
|
|
23064
23191
|
function decodeThreadForkRequest(request) {
|
|
23065
23192
|
if (request.method !== "thread/fork")
|
|
23066
23193
|
return null;
|
|
23067
|
-
if (!
|
|
23194
|
+
if (!isRecord7(request.params))
|
|
23068
23195
|
throw new Error("thread/fork params must be an object");
|
|
23069
23196
|
const params = request.params;
|
|
23070
23197
|
const threadId3 = optionalText(params, "threadId");
|
|
@@ -23100,7 +23227,7 @@ function decodeThreadForkRequest(request) {
|
|
|
23100
23227
|
function decodeThreadRevertRequest(request) {
|
|
23101
23228
|
if (request.method !== "thread/revert")
|
|
23102
23229
|
return null;
|
|
23103
|
-
if (!
|
|
23230
|
+
if (!isRecord7(request.params))
|
|
23104
23231
|
throw new Error("thread/revert params must be an object");
|
|
23105
23232
|
const { threadId: threadId3, beforeTurnId } = request.params;
|
|
23106
23233
|
if (typeof threadId3 !== "string" || threadId3.length === 0) {
|
|
@@ -23114,7 +23241,7 @@ function decodeThreadRevertRequest(request) {
|
|
|
23114
23241
|
function decodeThreadRollbackRequest(request) {
|
|
23115
23242
|
if (request.method !== "thread/rollback")
|
|
23116
23243
|
return null;
|
|
23117
|
-
if (!
|
|
23244
|
+
if (!isRecord7(request.params))
|
|
23118
23245
|
throw new Error("thread/rollback params must be an object");
|
|
23119
23246
|
const { threadId: threadId3, numTurns } = request.params;
|
|
23120
23247
|
if (typeof threadId3 !== "string" || threadId3.length === 0) {
|
|
@@ -23211,13 +23338,13 @@ var THREAD_SOURCE_KINDS = /* @__PURE__ */ new Set([
|
|
|
23211
23338
|
"subAgentOther",
|
|
23212
23339
|
"unknown"
|
|
23213
23340
|
]);
|
|
23214
|
-
function
|
|
23341
|
+
function isRecord8(value2) {
|
|
23215
23342
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
23216
23343
|
}
|
|
23217
23344
|
function paramsObject(request, method) {
|
|
23218
23345
|
if (request.params === void 0 && method === "thread/list")
|
|
23219
23346
|
return {};
|
|
23220
|
-
if (!
|
|
23347
|
+
if (!isRecord8(request.params))
|
|
23221
23348
|
throw new Error(`${method} params must be an object`);
|
|
23222
23349
|
return request.params;
|
|
23223
23350
|
}
|
|
@@ -23289,7 +23416,7 @@ function cursorPayload(value2) {
|
|
|
23289
23416
|
};
|
|
23290
23417
|
}
|
|
23291
23418
|
function parseCursorPayload(value2) {
|
|
23292
|
-
if (!
|
|
23419
|
+
if (!isRecord8(value2) || value2.formatVersion !== 1)
|
|
23293
23420
|
throw new Error("Host cursor is invalid");
|
|
23294
23421
|
const { queryFingerprint: fingerprint, sortDirection: sortDirection2, officialCursor, officialDone } = value2;
|
|
23295
23422
|
const { externalAnchor: externalAnchor2, externalDone } = value2;
|
|
@@ -23298,7 +23425,7 @@ function parseCursorPayload(value2) {
|
|
|
23298
23425
|
}
|
|
23299
23426
|
let anchor = null;
|
|
23300
23427
|
if (externalAnchor2 !== null) {
|
|
23301
|
-
if (!
|
|
23428
|
+
if (!isRecord8(externalAnchor2) || !Number.isSafeInteger(externalAnchor2.timestamp) || typeof externalAnchor2.threadId !== "string" || externalAnchor2.threadId.length === 0) {
|
|
23302
23429
|
throw new Error("Host cursor is invalid");
|
|
23303
23430
|
}
|
|
23304
23431
|
anchor = {
|
|
@@ -23418,7 +23545,7 @@ function decodeThreadMetadataUpdateRequest(request) {
|
|
|
23418
23545
|
if (params.gitInfo === null) {
|
|
23419
23546
|
gitInfo = null;
|
|
23420
23547
|
} else if (params.gitInfo !== void 0) {
|
|
23421
|
-
if (!
|
|
23548
|
+
if (!isRecord8(params.gitInfo)) {
|
|
23422
23549
|
throw new Error("thread/metadata/update params.gitInfo must be an object or null");
|
|
23423
23550
|
}
|
|
23424
23551
|
gitInfo = {};
|
|
@@ -23446,7 +23573,7 @@ function optionalCursor(value2, name) {
|
|
|
23446
23573
|
return value2;
|
|
23447
23574
|
}
|
|
23448
23575
|
function decodeOfficialThreadListPage(value2) {
|
|
23449
|
-
if (!
|
|
23576
|
+
if (!isRecord8(value2) || !Array.isArray(value2.data) || value2.data.some((row) => !isRecord8(row))) {
|
|
23450
23577
|
throw new Error("Official thread/list response is invalid");
|
|
23451
23578
|
}
|
|
23452
23579
|
return {
|
|
@@ -24872,10 +24999,10 @@ function serializeCursor(anchor, includeAnchor) {
|
|
|
24872
24999
|
return JSON.stringify({ anchor, includeAnchor });
|
|
24873
25000
|
}
|
|
24874
25001
|
function parseCursor(value2) {
|
|
24875
|
-
const
|
|
24876
|
-
if (
|
|
25002
|
+
const text2 = optionalText2(value2, "cursor");
|
|
25003
|
+
if (text2 === null) return null;
|
|
24877
25004
|
try {
|
|
24878
|
-
const parsed = JSON.parse(
|
|
25005
|
+
const parsed = JSON.parse(text2);
|
|
24879
25006
|
if (typeof parsed === "object" && parsed !== null && typeof parsed.anchor === "string" && parsed.anchor.length > 0 && typeof parsed.includeAnchor === "boolean") {
|
|
24880
25007
|
return { anchor: parsed.anchor, includeAnchor: parsed.includeAnchor };
|
|
24881
25008
|
}
|
|
@@ -25738,8 +25865,8 @@ function parseInput(params) {
|
|
|
25738
25865
|
)) {
|
|
25739
25866
|
throw new ExternalSteerError(-32602, "External steering requires text input");
|
|
25740
25867
|
}
|
|
25741
|
-
const
|
|
25742
|
-
if (!
|
|
25868
|
+
const text2 = params.input.map((item) => item.text).join("\n");
|
|
25869
|
+
if (!text2.trim())
|
|
25743
25870
|
throw new ExternalSteerError(-32602, "External steering input must not be empty");
|
|
25744
25871
|
const clientUserMessageId = params.clientUserMessageId;
|
|
25745
25872
|
if (clientUserMessageId != null && (typeof clientUserMessageId !== "string" || !clientUserMessageId.trim())) {
|
|
@@ -25747,7 +25874,7 @@ function parseInput(params) {
|
|
|
25747
25874
|
}
|
|
25748
25875
|
return {
|
|
25749
25876
|
expectedTurnId: params.expectedTurnId,
|
|
25750
|
-
text,
|
|
25877
|
+
text: text2,
|
|
25751
25878
|
...typeof clientUserMessageId === "string" ? { clientUserMessageId } : {}
|
|
25752
25879
|
};
|
|
25753
25880
|
}
|
|
@@ -25893,7 +26020,7 @@ import { createHash as createHash3 } from "node:crypto";
|
|
|
25893
26020
|
var CURSOR_PREFIX = "codexhost:thread-messages:v1:";
|
|
25894
26021
|
var DEFAULT_MESSAGE_LIMIT = 25;
|
|
25895
26022
|
var MAX_MESSAGE_LIMIT = 100;
|
|
25896
|
-
function
|
|
26023
|
+
function isRecord9(value2) {
|
|
25897
26024
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
25898
26025
|
}
|
|
25899
26026
|
function stringValue(value2) {
|
|
@@ -25902,12 +26029,12 @@ function stringValue(value2) {
|
|
|
25902
26029
|
function textFromUserItem(item) {
|
|
25903
26030
|
if (!Array.isArray(item.content)) return "";
|
|
25904
26031
|
return item.content.flatMap(
|
|
25905
|
-
(part) =>
|
|
26032
|
+
(part) => isRecord9(part) && part.type === "text" && typeof part.text === "string" ? [part.text] : []
|
|
25906
26033
|
).join("\n");
|
|
25907
26034
|
}
|
|
25908
26035
|
function threadStatus(value2, running) {
|
|
25909
26036
|
if (running) return "running";
|
|
25910
|
-
if (
|
|
26037
|
+
if (isRecord9(value2)) {
|
|
25911
26038
|
if (value2.type === "active") return "running";
|
|
25912
26039
|
}
|
|
25913
26040
|
return "completed";
|
|
@@ -25924,15 +26051,15 @@ function allVisibleMessages(turns) {
|
|
|
25924
26051
|
const turnId = stringValue(turn.id);
|
|
25925
26052
|
if (!turnId || !Array.isArray(turn.items)) continue;
|
|
25926
26053
|
const agentItems = turn.items.filter(
|
|
25927
|
-
(item) =>
|
|
26054
|
+
(item) => isRecord9(item) && item.type === "agentMessage"
|
|
25928
26055
|
);
|
|
25929
26056
|
for (const item of turn.items) {
|
|
25930
|
-
if (!
|
|
26057
|
+
if (!isRecord9(item)) continue;
|
|
25931
26058
|
const id2 = stringValue(item.id);
|
|
25932
26059
|
if (!id2) continue;
|
|
25933
26060
|
if (item.type === "userMessage") {
|
|
25934
|
-
const
|
|
25935
|
-
if (
|
|
26061
|
+
const text2 = textFromUserItem(item);
|
|
26062
|
+
if (text2) messages.push({ id: id2, turnId, role: "user", text: text2 });
|
|
25936
26063
|
} else if (item.type === "agentMessage" && typeof item.text === "string" && item.text) {
|
|
25937
26064
|
const itemIndex = agentItems.indexOf(item);
|
|
25938
26065
|
const phase = item.phase === "commentary" || item.phase === "final" ? item.phase : turn.status === "inProgress" || itemIndex < agentItems.length - 1 ? "commentary" : "final";
|
|
@@ -25999,10 +26126,10 @@ function projectDelegationThreadSnapshot(input) {
|
|
|
25999
26126
|
const status = input.running ? "running" : latestTurnStatus === "failed" || latestTurnStatus === "interrupted" ? latestTurnStatus : threadStatus(input.thread.status, input.running);
|
|
26000
26127
|
const latestTurnMessages = latestTurnId ? visible.filter((message) => message.turnId === latestTurnId && message.role === "agent") : [];
|
|
26001
26128
|
const final = latestTurnMessages.filter((message) => message.phase === "final").at(-1);
|
|
26002
|
-
const progress = latestTurnMessages.filter((message) => message.phase !== "final").map(({ id: id2, turnId, text }) => ({ id: id2, turnId, text }));
|
|
26129
|
+
const progress = latestTurnMessages.filter((message) => message.phase !== "final").map(({ id: id2, turnId, text: text2 }) => ({ id: id2, turnId, text: text2 }));
|
|
26003
26130
|
const result = input.running ? { availability: "pending" } : final ? { availability: "available", text: final.text } : {
|
|
26004
26131
|
availability: "unavailable",
|
|
26005
|
-
...
|
|
26132
|
+
...isRecord9(latestTurn?.error) && typeof latestTurn.error.message === "string" ? { message: latestTurn.error.message } : {}
|
|
26006
26133
|
};
|
|
26007
26134
|
const offset = options2.view === "messages" ? decodeCursor(input.threadId, options2.cursor) : visible.length;
|
|
26008
26135
|
const page = options2.view === "messages" ? visible.slice(offset, offset + options2.limit) : void 0;
|
|
@@ -27157,7 +27284,7 @@ import { mkdir as mkdir6 } from "node:fs/promises";
|
|
|
27157
27284
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
27158
27285
|
var INTERNAL_REQUEST_PREFIX = "codexhost:official:";
|
|
27159
27286
|
var MAX_RETIRED_IDS = 1024;
|
|
27160
|
-
function
|
|
27287
|
+
function isRecord10(value2) {
|
|
27161
27288
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
27162
27289
|
}
|
|
27163
27290
|
var OfficialRequestBroker = class {
|
|
@@ -27200,7 +27327,7 @@ var OfficialRequestBroker = class {
|
|
|
27200
27327
|
});
|
|
27201
27328
|
}
|
|
27202
27329
|
handle(value2) {
|
|
27203
|
-
if (!
|
|
27330
|
+
if (!isRecord10(value2) || typeof value2.id !== "string") return false;
|
|
27204
27331
|
const pending = this.#pending.get(value2.id);
|
|
27205
27332
|
if (!pending) return this.#retired.has(value2.id);
|
|
27206
27333
|
clearTimeout(pending.timeout);
|
|
@@ -27791,11 +27918,11 @@ async function aggregateOfficialAccountThreadListPage(input) {
|
|
|
27791
27918
|
}
|
|
27792
27919
|
|
|
27793
27920
|
// packages/host-runtime/src/route-observation.ts
|
|
27794
|
-
function
|
|
27921
|
+
function isRecord11(value2) {
|
|
27795
27922
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
27796
27923
|
}
|
|
27797
27924
|
function classifyThreadPurpose(request) {
|
|
27798
|
-
return
|
|
27925
|
+
return isRecord11(request.params) && request.params.ephemeral === true ? "ephemeral" : "conversation";
|
|
27799
27926
|
}
|
|
27800
27927
|
var RequestRouteObservationTracker = class {
|
|
27801
27928
|
#nextCreateOrdinal = 0;
|
|
@@ -27820,13 +27947,13 @@ var RequestRouteObservationTracker = class {
|
|
|
27820
27947
|
this.#createByThreadId.set(threadId3, tracked);
|
|
27821
27948
|
}
|
|
27822
27949
|
bindOfficialResponse(response) {
|
|
27823
|
-
if (!
|
|
27950
|
+
if (!isRecord11(response) || !("id" in response)) return;
|
|
27824
27951
|
const tracked = this.#pendingByRequestId.get(response.id);
|
|
27825
27952
|
if (!tracked) return;
|
|
27826
27953
|
this.#pendingByRequestId.delete(response.id);
|
|
27827
27954
|
const result = response.result;
|
|
27828
|
-
const thread =
|
|
27829
|
-
if (
|
|
27955
|
+
const thread = isRecord11(result) ? result.thread : null;
|
|
27956
|
+
if (isRecord11(thread) && typeof thread.id === "string") {
|
|
27830
27957
|
this.#createByThreadId.set(thread.id, tracked);
|
|
27831
27958
|
}
|
|
27832
27959
|
}
|
|
@@ -27869,11 +27996,11 @@ var OfficialThreadListError = class extends Error {
|
|
|
27869
27996
|
}
|
|
27870
27997
|
rpcError;
|
|
27871
27998
|
};
|
|
27872
|
-
function
|
|
27999
|
+
function isRecord12(value2) {
|
|
27873
28000
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
27874
28001
|
}
|
|
27875
28002
|
function officialThreadListPageFromResponse(response) {
|
|
27876
|
-
if (
|
|
28003
|
+
if (isRecord12(response.error)) {
|
|
27877
28004
|
if (!Number.isSafeInteger(response.error.code) || typeof response.error.message !== "string") {
|
|
27878
28005
|
throw new Error("Official thread/list error response is invalid");
|
|
27879
28006
|
}
|
|
@@ -28038,14 +28165,14 @@ var THREAD_USAGE_UPDATED_METHOD = "codexhost/thread/usage/updated";
|
|
|
28038
28165
|
function delay3(milliseconds) {
|
|
28039
28166
|
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
28040
28167
|
}
|
|
28041
|
-
function
|
|
28168
|
+
function isRecord13(value2) {
|
|
28042
28169
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
28043
28170
|
}
|
|
28044
28171
|
function isCreditsAdapter(adapter) {
|
|
28045
28172
|
return typeof adapter.credits === "function";
|
|
28046
28173
|
}
|
|
28047
28174
|
function projectAccountCredits(value2) {
|
|
28048
|
-
if (!
|
|
28175
|
+
if (!isRecord13(value2)) return null;
|
|
28049
28176
|
const rest = { ...value2 };
|
|
28050
28177
|
delete rest.fetchedAt;
|
|
28051
28178
|
const parsed = accountCreditsSnapshotSchema.safeParse(rest);
|
|
@@ -28165,14 +28292,14 @@ function classifyCreateRequestRoute(request, defaultAgent) {
|
|
|
28165
28292
|
};
|
|
28166
28293
|
}
|
|
28167
28294
|
function requestObject(request) {
|
|
28168
|
-
if (!
|
|
28295
|
+
if (!isRecord13(request.params)) throw new Error(`${request.method} params must be an object`);
|
|
28169
28296
|
return request.params;
|
|
28170
28297
|
}
|
|
28171
28298
|
function requestText(params) {
|
|
28172
28299
|
if (!Array.isArray(params.input)) throw new Error("turn/start input must be an array");
|
|
28173
|
-
const
|
|
28174
|
-
if (!
|
|
28175
|
-
return
|
|
28300
|
+
const text2 = params.input.filter((item) => isRecord13(item) && item.type === "text").map((item) => item.text).filter((value2) => typeof value2 === "string").join("\n");
|
|
28301
|
+
if (!text2) throw new Error("turn/start must contain text input");
|
|
28302
|
+
return text2;
|
|
28176
28303
|
}
|
|
28177
28304
|
function sandboxResult(params) {
|
|
28178
28305
|
const sandbox = params.sandbox;
|
|
@@ -28310,7 +28437,7 @@ var AppServerHost = class {
|
|
|
28310
28437
|
externalRuntime: this.#externalRuntime,
|
|
28311
28438
|
repository: this.#repository,
|
|
28312
28439
|
registerExternalThread: (input) => this.#registerExternalThread(input),
|
|
28313
|
-
startExternalTurn: (thread,
|
|
28440
|
+
startExternalTurn: (thread, text2, turnId) => this.#startDelegatedExternalTurn(thread, text2, turnId),
|
|
28314
28441
|
notifyThreadStarted: (thread) => this.#notifyExternalThreadStarted(thread),
|
|
28315
28442
|
inspectOfficial: (input) => this.#inspectOfficialDelegationTarget(input),
|
|
28316
28443
|
readOfficial: (input) => this.#readOfficialDelegationThread(input),
|
|
@@ -28455,12 +28582,12 @@ var AppServerHost = class {
|
|
|
28455
28582
|
for (const resolve of waiters) resolve();
|
|
28456
28583
|
}
|
|
28457
28584
|
#observeOfficialTurnStartResponse(value2) {
|
|
28458
|
-
if (!
|
|
28585
|
+
if (!isRecord13(value2) || !("id" in value2)) return;
|
|
28459
28586
|
const threadId3 = this.#pendingOfficialTurnStarts.get(value2.id);
|
|
28460
28587
|
if (!threadId3) return;
|
|
28461
28588
|
this.#pendingOfficialTurnStarts.delete(value2.id);
|
|
28462
|
-
const result =
|
|
28463
|
-
const turn = result &&
|
|
28589
|
+
const result = isRecord13(value2.result) ? value2.result : null;
|
|
28590
|
+
const turn = result && isRecord13(result.turn) ? result.turn : null;
|
|
28464
28591
|
if (turn && typeof turn.id === "string") {
|
|
28465
28592
|
this.#activeOfficialTurns.set(threadId3, turn.id);
|
|
28466
28593
|
}
|
|
@@ -28474,7 +28601,7 @@ var AppServerHost = class {
|
|
|
28474
28601
|
async #forwardDesktop() {
|
|
28475
28602
|
for await (const frame of readLfFrames(this.#options.desktopInput)) {
|
|
28476
28603
|
const parsed = parseJsonFrame(frame);
|
|
28477
|
-
if (
|
|
28604
|
+
if (isRecord13(parsed) && parsed.method === "initialized" && !("id" in parsed)) {
|
|
28478
28605
|
continue;
|
|
28479
28606
|
}
|
|
28480
28607
|
if (await this.#handleDesktopApprovalResponse(parsed)) continue;
|
|
@@ -28685,7 +28812,7 @@ var AppServerHost = class {
|
|
|
28685
28812
|
continue;
|
|
28686
28813
|
}
|
|
28687
28814
|
if (request.method === "thread/fork") {
|
|
28688
|
-
const params =
|
|
28815
|
+
const params = isRecord13(request.params) ? request.params : {};
|
|
28689
28816
|
const resolution = typeof params.threadId === "string" ? await this.#resolveExternalThread(params.threadId) : { kind: "official" };
|
|
28690
28817
|
if (resolution.kind === "error") {
|
|
28691
28818
|
await this.#writer.json(
|
|
@@ -28708,7 +28835,7 @@ var AppServerHost = class {
|
|
|
28708
28835
|
}
|
|
28709
28836
|
}
|
|
28710
28837
|
if (request.method === "thread/revert") {
|
|
28711
|
-
const params =
|
|
28838
|
+
const params = isRecord13(request.params) ? request.params : {};
|
|
28712
28839
|
const resolution = typeof params.threadId === "string" ? await this.#resolveExternalThread(params.threadId) : { kind: "official" };
|
|
28713
28840
|
if (resolution.kind === "error") {
|
|
28714
28841
|
await this.#writer.json(
|
|
@@ -28731,7 +28858,7 @@ var AppServerHost = class {
|
|
|
28731
28858
|
}
|
|
28732
28859
|
}
|
|
28733
28860
|
if (request.method === "thread/rollback") {
|
|
28734
|
-
const params =
|
|
28861
|
+
const params = isRecord13(request.params) ? request.params : {};
|
|
28735
28862
|
const resolution = typeof params.threadId === "string" ? await this.#resolveExternalThread(params.threadId) : { kind: "official" };
|
|
28736
28863
|
if (resolution.kind === "error") {
|
|
28737
28864
|
await this.#writer.json(
|
|
@@ -28883,7 +29010,7 @@ var AppServerHost = class {
|
|
|
28883
29010
|
continue;
|
|
28884
29011
|
}
|
|
28885
29012
|
}
|
|
28886
|
-
if (request.method.startsWith("thread/") && !EXPLICIT_EXTERNAL_THREAD_METHODS.has(request.method) &&
|
|
29013
|
+
if (request.method.startsWith("thread/") && !EXPLICIT_EXTERNAL_THREAD_METHODS.has(request.method) && isRecord13(request.params) && typeof request.params.threadId === "string") {
|
|
28887
29014
|
const location = await this.#locateExternalThread(request.params.threadId);
|
|
28888
29015
|
if (await this.#writeResolutionError(request, location)) continue;
|
|
28889
29016
|
if (location.kind === "external") {
|
|
@@ -28901,7 +29028,7 @@ var AppServerHost = class {
|
|
|
28901
29028
|
await this.#codexRuntimePool.close();
|
|
28902
29029
|
}
|
|
28903
29030
|
async #forwardOfficialNonRequest(value2, frame) {
|
|
28904
|
-
const response =
|
|
29031
|
+
const response = isRecord13(value2) ? value2 : null;
|
|
28905
29032
|
const request = response && (typeof response.id === "string" || typeof response.id === "number") ? this.#officialServerRequestAccounts.get(response.id) : null;
|
|
28906
29033
|
if (request && response) {
|
|
28907
29034
|
this.#officialServerRequestAccounts.delete(response.id);
|
|
@@ -28915,7 +29042,7 @@ var AppServerHost = class {
|
|
|
28915
29042
|
}
|
|
28916
29043
|
async #forwardOfficialRequest(request, frame) {
|
|
28917
29044
|
try {
|
|
28918
|
-
const params =
|
|
29045
|
+
const params = isRecord13(request.params) ? request.params : null;
|
|
28919
29046
|
const requestedAccountId = request.method === "thread/start" && typeof params?.__codexhostAccountId === "string" ? params.__codexhostAccountId : null;
|
|
28920
29047
|
const threadId3 = params && typeof params.threadId === "string" ? params.threadId : null;
|
|
28921
29048
|
const loginId = params && typeof params.loginId === "string" ? params.loginId : null;
|
|
@@ -28966,7 +29093,7 @@ var AppServerHost = class {
|
|
|
28966
29093
|
const parsed = input.value;
|
|
28967
29094
|
this.#observeOfficialTurnStartResponse(parsed);
|
|
28968
29095
|
let forwarded = parsed;
|
|
28969
|
-
if (
|
|
29096
|
+
if (isRecord13(parsed) && typeof parsed.method === "string" && "id" in parsed) {
|
|
28970
29097
|
const originalId = parsed.id;
|
|
28971
29098
|
if (typeof originalId === "string" || typeof originalId === "number") {
|
|
28972
29099
|
const forwardedId = `codexhost:official:${++this.#nextOfficialServerRequestId}`;
|
|
@@ -28977,12 +29104,12 @@ var AppServerHost = class {
|
|
|
28977
29104
|
forwarded = { ...parsed, id: forwardedId };
|
|
28978
29105
|
}
|
|
28979
29106
|
}
|
|
28980
|
-
if (
|
|
29107
|
+
if (isRecord13(parsed) && !("method" in parsed) && "id" in parsed) {
|
|
28981
29108
|
const requestKey = this.#officialRequestKey(input.accountId, parsed.id);
|
|
28982
29109
|
const loginAccountId = this.#pendingOfficialLoginStarts.get(requestKey);
|
|
28983
29110
|
if (loginAccountId) {
|
|
28984
29111
|
this.#pendingOfficialLoginStarts.delete(requestKey);
|
|
28985
|
-
const result =
|
|
29112
|
+
const result = isRecord13(parsed.result) ? parsed.result : null;
|
|
28986
29113
|
const loginId = result && typeof result.loginId === "string" ? result.loginId : null;
|
|
28987
29114
|
if (result && loginId) {
|
|
28988
29115
|
this.#officialLoginSessions.set(this.#loginSessionKey(loginAccountId, loginId), {
|
|
@@ -28996,8 +29123,8 @@ var AppServerHost = class {
|
|
|
28996
29123
|
const pending = this.#pendingOfficialThreadBindings.get(requestKey);
|
|
28997
29124
|
if (pending) {
|
|
28998
29125
|
this.#pendingOfficialThreadBindings.delete(requestKey);
|
|
28999
|
-
const result =
|
|
29000
|
-
const thread = result &&
|
|
29126
|
+
const result = isRecord13(parsed.result) ? parsed.result : null;
|
|
29127
|
+
const thread = result && isRecord13(result.thread) ? result.thread : null;
|
|
29001
29128
|
const threadId3 = thread && typeof thread.id === "string" ? thread.id : null;
|
|
29002
29129
|
if (threadId3) {
|
|
29003
29130
|
try {
|
|
@@ -29012,7 +29139,7 @@ var AppServerHost = class {
|
|
|
29012
29139
|
}
|
|
29013
29140
|
}
|
|
29014
29141
|
}
|
|
29015
|
-
if (
|
|
29142
|
+
if (isRecord13(parsed) && parsed.method === "account/login/completed" && isRecord13(parsed.params)) {
|
|
29016
29143
|
const notificationLoginId = typeof parsed.params.loginId === "string" ? parsed.params.loginId : null;
|
|
29017
29144
|
const accountSessions = notificationLoginId ? [] : [...this.#officialLoginSessions.values()].filter(
|
|
29018
29145
|
(candidate) => candidate.accountId === input.accountId
|
|
@@ -29036,7 +29163,7 @@ var AppServerHost = class {
|
|
|
29036
29163
|
}
|
|
29037
29164
|
return;
|
|
29038
29165
|
}
|
|
29039
|
-
const accountScopedNotification =
|
|
29166
|
+
const accountScopedNotification = isRecord13(parsed) && typeof parsed.method === "string" && (parsed.method === "account/updated" || parsed.method.startsWith("account/rateLimits/"));
|
|
29040
29167
|
if (accountScopedNotification) {
|
|
29041
29168
|
if (parsed.method === "account/updated") this.#resetOfficialUsageState(input.accountId);
|
|
29042
29169
|
}
|
|
@@ -29072,8 +29199,19 @@ var AppServerHost = class {
|
|
|
29072
29199
|
try {
|
|
29073
29200
|
if (request.method === "codexhost/account/usage/inspect") {
|
|
29074
29201
|
const { accountId } = codexAccountUsageParamsSchema.parse(requestObject(request));
|
|
29075
|
-
|
|
29076
|
-
|
|
29202
|
+
const account = await this.#accountRepository.get(accountId);
|
|
29203
|
+
if (!account) throw new Error("Unknown Codex Account");
|
|
29204
|
+
const auth = await inspectCodexHomeAuth(account.codexHome);
|
|
29205
|
+
if (auth.kind === "api") {
|
|
29206
|
+
const accountCredits2 = await inspectCodexApiAccountCredits(account.codexHome);
|
|
29207
|
+
const result2 = codexAccountUsageResultSchema.parse({
|
|
29208
|
+
accountId,
|
|
29209
|
+
usage: null,
|
|
29210
|
+
...accountCredits2 ? { accountCredits: accountCredits2 } : {}
|
|
29211
|
+
});
|
|
29212
|
+
await this.#writer.json(rpcEnvelope(request, { result: jsonValueSchema.parse(result2) }));
|
|
29213
|
+
return;
|
|
29214
|
+
}
|
|
29077
29215
|
await this.#refreshOfficialRateLimits(accountId);
|
|
29078
29216
|
const usage = this.#officialRateLimits.get(accountId);
|
|
29079
29217
|
const accountCredits = this.#officialAccountCredits(accountId);
|
|
@@ -29093,11 +29231,11 @@ var AppServerHost = class {
|
|
|
29093
29231
|
const response2 = await runtime.request("account/rateLimitResetCredit/consume", {
|
|
29094
29232
|
idempotencyKey: params2.idempotencyKey ?? randomUUID8()
|
|
29095
29233
|
});
|
|
29096
|
-
if (
|
|
29234
|
+
if (isRecord13(response2.error)) {
|
|
29097
29235
|
await this.#writer.json(rpcEnvelope(request, { error: response2.error }));
|
|
29098
29236
|
return;
|
|
29099
29237
|
}
|
|
29100
|
-
const result =
|
|
29238
|
+
const result = isRecord13(response2.result) ? response2.result : null;
|
|
29101
29239
|
const outcome = codexAccountResetCreditConsumeOutcomeSchema.safeParse(result?.outcome);
|
|
29102
29240
|
if (!outcome.success) throw new Error("Official reset-credit consume response is invalid");
|
|
29103
29241
|
this.#officialRateLimits.reset(params2.accountId);
|
|
@@ -29199,11 +29337,11 @@ var AppServerHost = class {
|
|
|
29199
29337
|
const response2 = await runtime.request("account/login/start", {
|
|
29200
29338
|
type: "chatgptDeviceCode"
|
|
29201
29339
|
});
|
|
29202
|
-
if (
|
|
29340
|
+
if (isRecord13(response2.error)) {
|
|
29203
29341
|
await this.#writer.json(rpcEnvelope(request, { error: response2.error }));
|
|
29204
29342
|
return;
|
|
29205
29343
|
}
|
|
29206
|
-
const result =
|
|
29344
|
+
const result = isRecord13(response2.result) ? response2.result : null;
|
|
29207
29345
|
if (!result || result.type !== "chatgptDeviceCode" || typeof result.loginId !== "string" || typeof result.verificationUrl !== "string" || typeof result.userCode !== "string") {
|
|
29208
29346
|
throw new Error("Official account/login/start response is invalid");
|
|
29209
29347
|
}
|
|
@@ -29232,7 +29370,7 @@ var AppServerHost = class {
|
|
|
29232
29370
|
return;
|
|
29233
29371
|
}
|
|
29234
29372
|
const response = await (await this.#codexRuntimePool.get(session.accountId)).request("account/login/cancel", { loginId: params.loginId });
|
|
29235
|
-
if (
|
|
29373
|
+
if (isRecord13(response.error)) {
|
|
29236
29374
|
await this.#writer.json(rpcEnvelope(request, { error: response.error }));
|
|
29237
29375
|
return;
|
|
29238
29376
|
}
|
|
@@ -29264,8 +29402,8 @@ var AppServerHost = class {
|
|
|
29264
29402
|
for (const account of await this.#accountRepository.list()) {
|
|
29265
29403
|
try {
|
|
29266
29404
|
const response = await (await this.#codexRuntimePool.get(account.accountId)).request("account/read", { refreshToken: false });
|
|
29267
|
-
const result =
|
|
29268
|
-
const officialAccount = result &&
|
|
29405
|
+
const result = isRecord13(response.result) ? response.result : null;
|
|
29406
|
+
const officialAccount = result && isRecord13(result.account) ? result.account : null;
|
|
29269
29407
|
if (!officialAccount) continue;
|
|
29270
29408
|
const email3 = typeof officialAccount.email === "string" ? officialAccount.email.trim() : "";
|
|
29271
29409
|
const parsedPlanType = codexAccountPlanTypeSchema.safeParse(officialAccount.planType);
|
|
@@ -29300,10 +29438,10 @@ var AppServerHost = class {
|
|
|
29300
29438
|
return this.#uniqueLoginSession(loginId)?.accountId;
|
|
29301
29439
|
}
|
|
29302
29440
|
async #observeOfficialTurnLifecycle(value2) {
|
|
29303
|
-
if (!
|
|
29441
|
+
if (!isRecord13(value2) || !isRecord13(value2.params)) return;
|
|
29304
29442
|
const params = value2.params;
|
|
29305
29443
|
if (value2.method === "turn/started" && typeof params.threadId === "string") {
|
|
29306
|
-
const turn =
|
|
29444
|
+
const turn = isRecord13(params.turn) ? params.turn : null;
|
|
29307
29445
|
if (turn && typeof turn.id === "string") {
|
|
29308
29446
|
this.#forgetPendingOfficialTurnStarts(params.threadId);
|
|
29309
29447
|
this.#activeOfficialTurns.set(params.threadId, turn.id);
|
|
@@ -29316,7 +29454,7 @@ var AppServerHost = class {
|
|
|
29316
29454
|
const delegation = await this.#repository.getDelegationByChild(
|
|
29317
29455
|
hostThreadIdSchema.parse(params.threadId)
|
|
29318
29456
|
);
|
|
29319
|
-
const turn =
|
|
29457
|
+
const turn = isRecord13(params.turn) ? params.turn : null;
|
|
29320
29458
|
const status = turn?.status === "failed" ? "failed" : turn?.status === "interrupted" || turn?.status === "cancelled" ? "interrupted" : "completed";
|
|
29321
29459
|
if (this.#pendingOfficialDelegationThreads.has(params.threadId)) {
|
|
29322
29460
|
this.#pendingOfficialTerminalStatuses.set(params.threadId, status);
|
|
@@ -29346,21 +29484,21 @@ var AppServerHost = class {
|
|
|
29346
29484
|
}
|
|
29347
29485
|
async #inspectOfficialDelegationTarget(input) {
|
|
29348
29486
|
const response = await this.#requestOfficial("model/list", {});
|
|
29349
|
-
if (
|
|
29487
|
+
if (isRecord13(response.error)) {
|
|
29350
29488
|
throw new DelegationControlError(
|
|
29351
29489
|
"DELEGATION_FAILED",
|
|
29352
29490
|
typeof response.error.message === "string" ? response.error.message : "Official Model catalog could not be read"
|
|
29353
29491
|
);
|
|
29354
29492
|
}
|
|
29355
|
-
const result =
|
|
29493
|
+
const result = isRecord13(response.result) ? response.result : null;
|
|
29356
29494
|
const data = result && Array.isArray(result.data) ? result.data : [];
|
|
29357
29495
|
const thinkingById = /* @__PURE__ */ new Map();
|
|
29358
29496
|
const models = data.flatMap((candidate) => {
|
|
29359
|
-
if (!
|
|
29497
|
+
if (!isRecord13(candidate) || typeof candidate.model !== "string" || !candidate.model.trim()) {
|
|
29360
29498
|
return [];
|
|
29361
29499
|
}
|
|
29362
29500
|
const supportedThinkingOptionIds = Array.isArray(candidate.supportedReasoningEfforts) ? candidate.supportedReasoningEfforts.flatMap((option) => {
|
|
29363
|
-
if (!
|
|
29501
|
+
if (!isRecord13(option) || typeof option.reasoningEffort !== "string" || !option.reasoningEffort.trim()) {
|
|
29364
29502
|
return [];
|
|
29365
29503
|
}
|
|
29366
29504
|
const id2 = harnessThinkingOptionIdSchema.safeParse(option.reasoningEffort);
|
|
@@ -29380,9 +29518,9 @@ var AppServerHost = class {
|
|
|
29380
29518
|
];
|
|
29381
29519
|
});
|
|
29382
29520
|
const defaultEntry = data.find(
|
|
29383
|
-
(candidate) =>
|
|
29521
|
+
(candidate) => isRecord13(candidate) && candidate.isDefault === true
|
|
29384
29522
|
);
|
|
29385
|
-
const defaultModel =
|
|
29523
|
+
const defaultModel = isRecord13(defaultEntry) && typeof defaultEntry.model === "string" ? encodeOfficialCodexModelRef(defaultEntry.model) : void 0;
|
|
29386
29524
|
return {
|
|
29387
29525
|
harnessId: input.harnessId,
|
|
29388
29526
|
inspection: {
|
|
@@ -29489,8 +29627,8 @@ var AppServerHost = class {
|
|
|
29489
29627
|
ephemeral: false,
|
|
29490
29628
|
historyMode: "paginated"
|
|
29491
29629
|
});
|
|
29492
|
-
const startedResult =
|
|
29493
|
-
const thread = startedResult &&
|
|
29630
|
+
const startedResult = isRecord13(started.result) ? started.result : null;
|
|
29631
|
+
const thread = startedResult && isRecord13(startedResult.thread) ? startedResult.thread : null;
|
|
29494
29632
|
const threadId3 = thread && typeof thread.id === "string" ? thread.id : null;
|
|
29495
29633
|
if (!threadId3) throw new Error("Official thread/start returned no Thread identity");
|
|
29496
29634
|
await this.#codexRuntimePool.bindThread(threadId3, activeRuntime.account.accountId);
|
|
@@ -29503,8 +29641,8 @@ var AppServerHost = class {
|
|
|
29503
29641
|
...nativeModelId ? { model: nativeModelId } : {},
|
|
29504
29642
|
...input.thinkingOptionId ? { effort: input.thinkingOptionId } : {}
|
|
29505
29643
|
});
|
|
29506
|
-
const turnResult =
|
|
29507
|
-
const turnValue = turnResult &&
|
|
29644
|
+
const turnResult = isRecord13(turn.result) ? turn.result : null;
|
|
29645
|
+
const turnValue = turnResult && isRecord13(turnResult.turn) ? turnResult.turn : null;
|
|
29508
29646
|
const parsedTurnId = turnValue && typeof turnValue.id === "string" ? turnValue.id : null;
|
|
29509
29647
|
if (!parsedTurnId) throw new Error("Official turn/start returned no Turn identity");
|
|
29510
29648
|
turnId = parsedTurnId;
|
|
@@ -29573,27 +29711,27 @@ var AppServerHost = class {
|
|
|
29573
29711
|
threadId: input.threadId,
|
|
29574
29712
|
includeTurns: true
|
|
29575
29713
|
});
|
|
29576
|
-
if (
|
|
29714
|
+
if (isRecord13(current.error) || !isRecord13(current.result)) {
|
|
29577
29715
|
throw new DelegationControlError("THREAD_NOT_FOUND", "Official Thread was not found");
|
|
29578
29716
|
}
|
|
29579
|
-
const currentThread =
|
|
29717
|
+
const currentThread = isRecord13(current.result.thread) ? current.result.thread : null;
|
|
29580
29718
|
const currentTurns = currentThread && Array.isArray(currentThread.turns) ? currentThread.turns : [];
|
|
29581
29719
|
const latestTurn = currentTurns.at(-1);
|
|
29582
|
-
if (currentThread &&
|
|
29720
|
+
if (currentThread && isRecord13(currentThread.status) && currentThread.status.type === "active" || isRecord13(latestTurn) && (latestTurn.status === "inProgress" || latestTurn.status === "running")) {
|
|
29583
29721
|
throw new DelegationControlError("THREAD_BUSY", "Thread already has an active Turn");
|
|
29584
29722
|
}
|
|
29585
29723
|
const response = await this.#requestOfficial("turn/start", {
|
|
29586
29724
|
threadId: input.threadId,
|
|
29587
29725
|
input: [{ type: "text", text: input.message }]
|
|
29588
29726
|
});
|
|
29589
|
-
if (
|
|
29727
|
+
if (isRecord13(response.error)) {
|
|
29590
29728
|
throw new DelegationControlError(
|
|
29591
29729
|
"DELEGATION_FAILED",
|
|
29592
29730
|
typeof response.error.message === "string" ? response.error.message : "Turn start failed"
|
|
29593
29731
|
);
|
|
29594
29732
|
}
|
|
29595
|
-
const result =
|
|
29596
|
-
const turn = result &&
|
|
29733
|
+
const result = isRecord13(response.result) ? response.result : null;
|
|
29734
|
+
const turn = result && isRecord13(result.turn) ? result.turn : null;
|
|
29597
29735
|
const turnId = turn && typeof turn.id === "string" ? turn.id : null;
|
|
29598
29736
|
if (!turnId) throw new Error("Official turn/start returned no Turn identity");
|
|
29599
29737
|
this.#activeOfficialTurns.set(input.threadId, turnId);
|
|
@@ -29615,13 +29753,13 @@ var AppServerHost = class {
|
|
|
29615
29753
|
threadId: input.threadId,
|
|
29616
29754
|
includeTurns: true
|
|
29617
29755
|
});
|
|
29618
|
-
if (
|
|
29756
|
+
if (isRecord13(current.error) || !isRecord13(current.result)) {
|
|
29619
29757
|
throw new DelegationControlError("THREAD_NOT_FOUND", "Official Thread was not found");
|
|
29620
29758
|
}
|
|
29621
|
-
const currentThread =
|
|
29759
|
+
const currentThread = isRecord13(current.result.thread) ? current.result.thread : null;
|
|
29622
29760
|
const currentTurns = currentThread && Array.isArray(currentThread.turns) ? currentThread.turns : [];
|
|
29623
29761
|
const latestTurn = currentTurns.at(-1);
|
|
29624
|
-
if (
|
|
29762
|
+
if (isRecord13(latestTurn) && typeof latestTurn.id === "string" && (latestTurn.status === "inProgress" || latestTurn.status === "running")) {
|
|
29625
29763
|
turnId = latestTurn.id;
|
|
29626
29764
|
this.#activeOfficialTurns.set(input.threadId, turnId);
|
|
29627
29765
|
} else {
|
|
@@ -29632,7 +29770,7 @@ var AppServerHost = class {
|
|
|
29632
29770
|
threadId: input.threadId,
|
|
29633
29771
|
turnId
|
|
29634
29772
|
});
|
|
29635
|
-
if (
|
|
29773
|
+
if (isRecord13(response.error)) {
|
|
29636
29774
|
throw new DelegationControlError(
|
|
29637
29775
|
"DELEGATION_FAILED",
|
|
29638
29776
|
typeof response.error.message === "string" ? response.error.message : "Turn cancel failed"
|
|
@@ -29645,18 +29783,18 @@ var AppServerHost = class {
|
|
|
29645
29783
|
threadId: input.threadId,
|
|
29646
29784
|
includeTurns: true
|
|
29647
29785
|
});
|
|
29648
|
-
if (
|
|
29786
|
+
if (isRecord13(response.error)) {
|
|
29649
29787
|
throw new DelegationControlError(
|
|
29650
29788
|
"THREAD_NOT_FOUND",
|
|
29651
29789
|
typeof response.error.message === "string" ? response.error.message : "Official Thread was not found"
|
|
29652
29790
|
);
|
|
29653
29791
|
}
|
|
29654
|
-
const result =
|
|
29655
|
-
const thread = result &&
|
|
29792
|
+
const result = isRecord13(response.result) ? response.result : null;
|
|
29793
|
+
const thread = result && isRecord13(result.thread) ? result.thread : null;
|
|
29656
29794
|
if (!thread)
|
|
29657
29795
|
throw new DelegationControlError("THREAD_NOT_FOUND", "Official Thread was not found");
|
|
29658
|
-
const turns = Array.isArray(thread.turns) ? thread.turns.filter((turn) =>
|
|
29659
|
-
const running = this.#activeOfficialTurns.has(input.threadId) ||
|
|
29796
|
+
const turns = Array.isArray(thread.turns) ? thread.turns.filter((turn) => isRecord13(turn)) : [];
|
|
29797
|
+
const running = this.#activeOfficialTurns.has(input.threadId) || isRecord13(thread.status) && thread.status.type === "active";
|
|
29660
29798
|
const snapshot = projectDelegationThreadSnapshot({
|
|
29661
29799
|
threadId: input.threadId,
|
|
29662
29800
|
harnessId: "codex",
|
|
@@ -29715,7 +29853,7 @@ var AppServerHost = class {
|
|
|
29715
29853
|
threads: result.data.flatMap((entry) => {
|
|
29716
29854
|
if (typeof entry.id !== "string") return [];
|
|
29717
29855
|
const record3 = records.find((candidate) => candidate.hostThreadId === entry.id);
|
|
29718
|
-
const status =
|
|
29856
|
+
const status = isRecord13(entry.status) && entry.status.type === "active" ? "running" : "completed";
|
|
29719
29857
|
return [
|
|
29720
29858
|
{
|
|
29721
29859
|
threadId: entry.id,
|
|
@@ -30860,10 +30998,10 @@ var AppServerHost = class {
|
|
|
30860
30998
|
...typeof params.serviceTier === "string" ? { serviceTier: params.serviceTier } : {}
|
|
30861
30999
|
});
|
|
30862
31000
|
try {
|
|
30863
|
-
if (params.initialTurnsPage !== void 0 && params.initialTurnsPage !== null && !
|
|
31001
|
+
if (params.initialTurnsPage !== void 0 && params.initialTurnsPage !== null && !isRecord13(params.initialTurnsPage)) {
|
|
30864
31002
|
throw new ExternalHistoryRequestError("initialTurnsPage must be an object");
|
|
30865
31003
|
}
|
|
30866
|
-
const initialPageParams =
|
|
31004
|
+
const initialPageParams = isRecord13(params.initialTurnsPage) ? params.initialTurnsPage : null;
|
|
30867
31005
|
const initialTurnsPage = initialPageParams ? listExternalTurns(turns, initialPageParams) : null;
|
|
30868
31006
|
const paginated = thread.record.historyMode === "paginated";
|
|
30869
31007
|
const turnsBackwardsCursor = paginated ? listExternalTurns(turns, { limit: 1, itemsView: "notLoaded" }).backwardsCursor : null;
|
|
@@ -30893,7 +31031,7 @@ var AppServerHost = class {
|
|
|
30893
31031
|
const active = thread.projectedTurns.get(thread.activeTurnId);
|
|
30894
31032
|
return active ? [...thread.turns, active.projector.pendingTurn()] : thread.turns;
|
|
30895
31033
|
}
|
|
30896
|
-
async #startDelegatedExternalTurn(thread,
|
|
31034
|
+
async #startDelegatedExternalTurn(thread, text2, requestedTurnId) {
|
|
30897
31035
|
if (thread.running || this.#externalSteering.hasPending(thread.id)) {
|
|
30898
31036
|
throw new Error("External Thread already has an active Turn");
|
|
30899
31037
|
}
|
|
@@ -30904,7 +31042,7 @@ var AppServerHost = class {
|
|
|
30904
31042
|
turnId,
|
|
30905
31043
|
cwd: thread.cwd,
|
|
30906
31044
|
startedAtMs: Date.now(),
|
|
30907
|
-
initialInput: [{ type: "text", text }]
|
|
31045
|
+
initialInput: [{ type: "text", text: text2 }]
|
|
30908
31046
|
})
|
|
30909
31047
|
};
|
|
30910
31048
|
thread.running = true;
|
|
@@ -30917,7 +31055,7 @@ var AppServerHost = class {
|
|
|
30917
31055
|
const result = await thread.session.execute({
|
|
30918
31056
|
type: "turn.start",
|
|
30919
31057
|
turnId,
|
|
30920
|
-
input: [{ type: "text", text }]
|
|
31058
|
+
input: [{ type: "text", text: text2 }]
|
|
30921
31059
|
});
|
|
30922
31060
|
if (!result.ok) {
|
|
30923
31061
|
thread.running = false;
|
|
@@ -30951,14 +31089,14 @@ var AppServerHost = class {
|
|
|
30951
31089
|
return;
|
|
30952
31090
|
}
|
|
30953
31091
|
}
|
|
30954
|
-
let
|
|
31092
|
+
let text2;
|
|
30955
31093
|
try {
|
|
30956
|
-
|
|
31094
|
+
text2 = requestText(params);
|
|
30957
31095
|
} catch (error51) {
|
|
30958
31096
|
await this.#writer.json(rpcError(request, -32602, errorMessage3(error51)));
|
|
30959
31097
|
return;
|
|
30960
31098
|
}
|
|
30961
|
-
const commandCandidate =
|
|
31099
|
+
const commandCandidate = text2.trimStart();
|
|
30962
31100
|
if (thread.session.commands && /^\/[^\s/]+(?:\s|$)/u.test(commandCandidate)) {
|
|
30963
31101
|
const commandText = commandCandidate.trimEnd();
|
|
30964
31102
|
this.#pendingExternalCommandRequests.add(thread.id);
|
|
@@ -31004,7 +31142,7 @@ var AppServerHost = class {
|
|
|
31004
31142
|
return;
|
|
31005
31143
|
}
|
|
31006
31144
|
try {
|
|
31007
|
-
const started = await this.#beginExternalTurn(thread,
|
|
31145
|
+
const started = await this.#beginExternalTurn(thread, text2);
|
|
31008
31146
|
try {
|
|
31009
31147
|
await this.#writer.json(rpcEnvelope(request, { result: { turn: started.turn } }));
|
|
31010
31148
|
} finally {
|
|
@@ -31025,7 +31163,7 @@ var AppServerHost = class {
|
|
|
31025
31163
|
const started = await this.#externalSteering.run(
|
|
31026
31164
|
thread,
|
|
31027
31165
|
requestObject(request),
|
|
31028
|
-
(
|
|
31166
|
+
(text2) => this.#beginExternalTurn(thread, text2)
|
|
31029
31167
|
);
|
|
31030
31168
|
try {
|
|
31031
31169
|
await this.#writer.json(rpcEnvelope(request, { result: { turnId: started.turnId } }));
|
|
@@ -31044,7 +31182,7 @@ var AppServerHost = class {
|
|
|
31044
31182
|
this.#signalActiveWorkChanged();
|
|
31045
31183
|
}
|
|
31046
31184
|
}
|
|
31047
|
-
async #beginExternalTurn(thread,
|
|
31185
|
+
async #beginExternalTurn(thread, text2) {
|
|
31048
31186
|
if (this.#closeRequested || this.#externalRuntime.get(thread.id) !== thread) {
|
|
31049
31187
|
throw new ExternalSteerError(-32073, "External Thread is no longer available");
|
|
31050
31188
|
}
|
|
@@ -31070,7 +31208,7 @@ var AppServerHost = class {
|
|
|
31070
31208
|
const result = await thread.session.execute({
|
|
31071
31209
|
type: "turn.start",
|
|
31072
31210
|
turnId,
|
|
31073
|
-
input: [{ type: "text", text }]
|
|
31211
|
+
input: [{ type: "text", text: text2 }]
|
|
31074
31212
|
});
|
|
31075
31213
|
if (!result.ok) throw new ExternalSteerError(-32073, result.error.message);
|
|
31076
31214
|
return { turnId, turn: projection.projector.pendingTurn(), gate };
|
|
@@ -31473,7 +31611,7 @@ var AppServerHost = class {
|
|
|
31473
31611
|
const previousItems = new Map(
|
|
31474
31612
|
child.turns.flatMap(
|
|
31475
31613
|
(turn) => Array.isArray(turn.items) ? turn.items.flatMap(
|
|
31476
|
-
(item) =>
|
|
31614
|
+
(item) => isRecord13(item) && typeof item.id === "string" ? [[item.id, JSON.stringify(item)]] : []
|
|
31477
31615
|
) : []
|
|
31478
31616
|
)
|
|
31479
31617
|
);
|
|
@@ -31486,7 +31624,7 @@ var AppServerHost = class {
|
|
|
31486
31624
|
for (const turn of child.turns) {
|
|
31487
31625
|
if (typeof turn.id !== "string" || !Array.isArray(turn.items)) continue;
|
|
31488
31626
|
const changedItems = turn.items.filter(
|
|
31489
|
-
(item) =>
|
|
31627
|
+
(item) => isRecord13(item) && typeof item.id === "string" && previousItems.get(item.id) !== JSON.stringify(item)
|
|
31490
31628
|
);
|
|
31491
31629
|
if (changedItems.length > 0) {
|
|
31492
31630
|
await this.#writer.json({
|
|
@@ -31618,7 +31756,7 @@ var AppServerHost = class {
|
|
|
31618
31756
|
}
|
|
31619
31757
|
}
|
|
31620
31758
|
async #handleDesktopApprovalResponse(value2) {
|
|
31621
|
-
if (!
|
|
31759
|
+
if (!isRecord13(value2) || !isHostApprovalRequestId(value2.id)) return false;
|
|
31622
31760
|
const pending = this.#pendingDesktopApprovals.get(value2.id);
|
|
31623
31761
|
if (!pending) return true;
|
|
31624
31762
|
this.#pendingDesktopApprovals.delete(value2.id);
|
|
@@ -31740,7 +31878,7 @@ var AppServerHost = class {
|
|
|
31740
31878
|
}
|
|
31741
31879
|
}
|
|
31742
31880
|
async #handleDesktopQuestionResponse(value2) {
|
|
31743
|
-
if (!
|
|
31881
|
+
if (!isRecord13(value2) || !isHostQuestionRequestId(value2.id)) return false;
|
|
31744
31882
|
const pending = this.#pendingDesktopQuestions.get(value2.id);
|
|
31745
31883
|
if (!pending) return true;
|
|
31746
31884
|
this.#pendingDesktopQuestions.delete(value2.id);
|
|
@@ -31936,9 +32074,11 @@ var DelegationControlRegistry = class {
|
|
|
31936
32074
|
);
|
|
31937
32075
|
}
|
|
31938
32076
|
if (registrations.length === 1) return registrations[0];
|
|
31939
|
-
throw new DelegationControlError(
|
|
31940
|
-
|
|
31941
|
-
|
|
32077
|
+
throw new DelegationControlError(
|
|
32078
|
+
"PARENT_THREAD_AMBIGUOUS",
|
|
32079
|
+
"Thread is not owned by exactly one active Host Runtime session",
|
|
32080
|
+
{ matchingRuntimeCount: 0 }
|
|
32081
|
+
);
|
|
31942
32082
|
}
|
|
31943
32083
|
#compareThreads(left, right, sort) {
|
|
31944
32084
|
const field = sort.startsWith("created") ? "createdAt" : "updatedAt";
|