@liberseek/boft-cli-linux-x64 0.7.8 → 0.8.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/README.md +1 -1
- package/THIRD_PARTY_NOTICES.txt +8 -0
- package/app/codexhost-distribution.json +1 -1
- package/app/console-server.mjs +16801 -16440
- package/app/console-web.js +9774 -3685
- package/app/desktop-controller.mjs +16475 -374
- package/app/host-runtime.mjs +9052 -1793
- package/app/plugins/antigravity/manifest.json +18 -1
- package/app/plugins/antigravity/plugin.mjs +357 -42
- package/app/plugins/claude-code/manifest.json +28 -0
- package/app/plugins/claude-code/plugin.mjs +1448 -491
- package/app/plugins/codebuddy/manifest.json +17 -0
- package/app/plugins/codebuddy/plugin.mjs +6589 -5423
- package/app/plugins/codex-usage/manifest.json +9 -0
- package/app/plugins/codex-usage/plugin.mjs +16750 -0
- package/app/plugins/cursor-cli/manifest.json +18 -1
- package/app/plugins/cursor-cli/plugin.mjs +782 -197
- package/app/plugins/deepseek-harness/assets/icon.svg +1 -0
- package/app/plugins/deepseek-harness/manifest.json +35 -2
- package/app/plugins/deepseek-harness/plugin.mjs +879 -242
- package/app/plugins/enabled.json +3 -1
- package/app/plugins/grok/manifest.json +21 -1
- package/app/plugins/grok/plugin.mjs +1274 -241
- package/app/plugins/hermes/assets/icon.png +0 -0
- package/app/plugins/hermes/manifest.json +30 -2
- package/app/plugins/hermes/plugin.mjs +3493 -7686
- package/app/plugins/kimi-code/assets/icon.svg +5 -0
- package/app/plugins/kimi-code/manifest.json +25 -2
- package/app/plugins/kimi-code/plugin.mjs +922 -76
- package/app/plugins/kiro-cli/assets/kiro-agent.svg +11 -0
- package/app/plugins/kiro-cli/manifest.json +18 -1
- package/app/plugins/kiro-cli/plugin.mjs +658 -57
- package/app/plugins/muse/manifest.json +18 -1
- package/app/plugins/muse/plugin.mjs +332 -17
- package/app/plugins/omp/manifest.json +21 -1
- package/app/plugins/omp/plugin.mjs +2320 -1131
- package/app/plugins/opencode/manifest.json +18 -1
- package/app/plugins/opencode/plugin.mjs +979 -184
- package/app/plugins/pi/manifest.json +32 -0
- package/app/plugins/pi/plugin.mjs +2785 -2090
- package/app/plugins/qoder/manifest.json +18 -1
- package/app/plugins/qoder/plugin.mjs +832 -82
- package/app/plugins/qoder-cn/manifest.json +18 -1
- package/app/plugins/qoder-cn/plugin.mjs +832 -82
- package/app/plugins/workbuddy/manifest.json +18 -0
- package/app/plugins/workbuddy/plugin.mjs +6947 -5773
- package/app/plugins/zcode/assets/icon.svg +8 -0
- package/app/plugins/zcode/manifest.json +32 -0
- package/app/plugins/zcode/plugin.mjs +20110 -0
- package/app/renderer-extension.js +4762 -2470
- package/bin/boft +0 -0
- package/libexec/boft-shim +0 -0
- package/libexec/boft-updater +0 -0
- package/licenses/Cordis-LICENSE.txt +21 -0
- package/licenses/Cosmokit-LICENSE.txt +21 -0
- package/package.json +1 -1
- package/app/plugins/kiro-cli/assets/icon.svg +0 -5
|
@@ -233,11 +233,11 @@ function harnessCandidates(spec, input, dependencies = {}) {
|
|
|
233
233
|
}
|
|
234
234
|
function resolveHarnessExecutable(spec, input, dependencies = {}) {
|
|
235
235
|
const platform = input.platform ?? process.platform;
|
|
236
|
-
const isExecutable = dependencies.isExecutable ?? ((
|
|
237
|
-
const runnable = spec.runnableCandidate ?? ((
|
|
236
|
+
const isExecutable = dependencies.isExecutable ?? ((candidate2) => isExecutableFile(candidate2, platform));
|
|
237
|
+
const runnable = spec.runnableCandidate ?? ((candidate2) => candidate2);
|
|
238
238
|
const context = { platform, isExecutable };
|
|
239
|
-
for (const { candidate, source } of harnessCandidates(spec, input, dependencies)) {
|
|
240
|
-
const executable = runnable(
|
|
239
|
+
for (const { candidate: candidate2, source } of harnessCandidates(spec, input, dependencies)) {
|
|
240
|
+
const executable = runnable(candidate2, context);
|
|
241
241
|
if (executable !== void 0 && isExecutable(executable))
|
|
242
242
|
return { executable, source };
|
|
243
243
|
}
|
|
@@ -396,7 +396,7 @@ async function npmInstallation(command, packages, environment) {
|
|
|
396
396
|
const npm = resolveHarnessExecutable({ id: "npm", command: "npm", installRoots: { posix: [], windows: [] } }, { environment: env });
|
|
397
397
|
let globalInstall = modules === globalRoot;
|
|
398
398
|
if (process.platform === "win32") {
|
|
399
|
-
const
|
|
399
|
+
const project2 = (await Promise.all(["package.json", "package-lock.json", "npm-shrinkwrap.json"].map((file2) => readFile(path4.join(prefix, file2), "utf8").then(() => true, (error51) => error51.code !== "ENOENT")))).some(Boolean);
|
|
400
400
|
const bins = typeof metadata.bin === "string" ? { [name.split("/").at(-1) ?? name]: metadata.bin } : metadata.bin ?? {};
|
|
401
401
|
const launchers = await Promise.all(Object.entries(bins).map(async ([bin, entry]) => {
|
|
402
402
|
if (path4.basename(bin) !== bin || entry.includes(".."))
|
|
@@ -407,7 +407,7 @@ async function npmInstallation(command, packages, environment) {
|
|
|
407
407
|
const shim = await readFile(path4.join(prefix, `${bin}.cmd`), "utf8").catch(() => "");
|
|
408
408
|
return referencesNpmBin(shim, name, entry);
|
|
409
409
|
}));
|
|
410
|
-
globalInstall = globalInstall && !
|
|
410
|
+
globalInstall = globalInstall && !project2 && launchers.some(Boolean);
|
|
411
411
|
}
|
|
412
412
|
const canUpdate = globalInstall && !!npm;
|
|
413
413
|
return {
|
|
@@ -487,10 +487,50 @@ function createHarnessInstaller(environment, source) {
|
|
|
487
487
|
};
|
|
488
488
|
}
|
|
489
489
|
|
|
490
|
-
// dist/
|
|
491
|
-
import
|
|
492
|
-
import
|
|
493
|
-
import
|
|
490
|
+
// dist/usage-statistics.js
|
|
491
|
+
import os2 from "node:os";
|
|
492
|
+
import path5 from "node:path";
|
|
493
|
+
import { lstat } from "node:fs/promises";
|
|
494
|
+
|
|
495
|
+
// ../../harness-adapter/dist/usage-statistics.js
|
|
496
|
+
var MAX_SESSION_ID_LENGTH = 512;
|
|
497
|
+
var MAX_CWD_LENGTH = 4096;
|
|
498
|
+
function sessionIdOk(value) {
|
|
499
|
+
return typeof value === "string" && value.length > 0 && value.length <= MAX_SESSION_ID_LENGTH;
|
|
500
|
+
}
|
|
501
|
+
function cwdOk(value) {
|
|
502
|
+
return typeof value === "string" && value.length > 0 && value.length <= MAX_CWD_LENGTH && !value.includes("\0") && (value.startsWith("/") || /^[A-Za-z]:[\\/]/u.test(value) || value.startsWith("\\\\"));
|
|
503
|
+
}
|
|
504
|
+
function withUsageSession(entry, session) {
|
|
505
|
+
const sessionId = sessionIdOk(session.sessionId) ? session.sessionId : void 0;
|
|
506
|
+
const cwd = cwdOk(session.cwd) ? session.cwd : void 0;
|
|
507
|
+
if (sessionId === void 0 && cwd === void 0)
|
|
508
|
+
return entry;
|
|
509
|
+
return {
|
|
510
|
+
...entry,
|
|
511
|
+
...sessionId !== void 0 ? { sessionId } : {},
|
|
512
|
+
...cwd !== void 0 ? { cwd } : {}
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
function usageEntryFromRequest(request, occurredAtMs) {
|
|
516
|
+
if (!Number.isSafeInteger(occurredAtMs) || occurredAtMs <= 0)
|
|
517
|
+
return null;
|
|
518
|
+
return {
|
|
519
|
+
id: request.requestId,
|
|
520
|
+
occurredAtMs,
|
|
521
|
+
...request.model !== void 0 ? { model: request.model } : {},
|
|
522
|
+
inputTokens: request.inputTokens,
|
|
523
|
+
...request.cachedInputTokens !== void 0 ? { cachedInputTokens: request.cachedInputTokens } : {},
|
|
524
|
+
...request.cacheWriteInputTokens !== void 0 ? { cacheWriteInputTokens: request.cacheWriteInputTokens } : {},
|
|
525
|
+
...request.cacheWrite1hInputTokens !== void 0 ? { cacheWrite1hInputTokens: request.cacheWrite1hInputTokens } : {},
|
|
526
|
+
outputTokens: request.outputTokens,
|
|
527
|
+
...request.reasoningOutputTokens !== void 0 ? { reasoningOutputTokens: request.reasoningOutputTokens } : {}
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
function nativeTimeMs(value) {
|
|
531
|
+
const time3 = typeof value === "number" ? value : typeof value === "string" ? Date.parse(value) : Number.NaN;
|
|
532
|
+
return Number.isFinite(time3) && time3 > 0 ? Math.floor(time3) : null;
|
|
533
|
+
}
|
|
494
534
|
|
|
495
535
|
// ../../../node_modules/zod/v4/classic/external.js
|
|
496
536
|
var external_exports = {};
|
|
@@ -1258,10 +1298,10 @@ function mergeDefs(...defs) {
|
|
|
1258
1298
|
function cloneDef(schema) {
|
|
1259
1299
|
return mergeDefs(schema._zod.def);
|
|
1260
1300
|
}
|
|
1261
|
-
function getElementAtPath(obj,
|
|
1262
|
-
if (!
|
|
1301
|
+
function getElementAtPath(obj, path14) {
|
|
1302
|
+
if (!path14)
|
|
1263
1303
|
return obj;
|
|
1264
|
-
return
|
|
1304
|
+
return path14.reduce((acc, key) => acc?.[key], obj);
|
|
1265
1305
|
}
|
|
1266
1306
|
function promiseAllObject(promisesObj) {
|
|
1267
1307
|
const keys = Object.keys(promisesObj);
|
|
@@ -1670,11 +1710,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
1670
1710
|
}
|
|
1671
1711
|
return false;
|
|
1672
1712
|
}
|
|
1673
|
-
function prefixIssues(
|
|
1713
|
+
function prefixIssues(path14, issues) {
|
|
1674
1714
|
return issues.map((iss) => {
|
|
1675
1715
|
var _a3;
|
|
1676
1716
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
1677
|
-
iss.path.unshift(
|
|
1717
|
+
iss.path.unshift(path14);
|
|
1678
1718
|
return iss;
|
|
1679
1719
|
});
|
|
1680
1720
|
}
|
|
@@ -1821,16 +1861,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1821
1861
|
}
|
|
1822
1862
|
function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
1823
1863
|
const fieldErrors = { _errors: [] };
|
|
1824
|
-
const processError = (error52,
|
|
1864
|
+
const processError = (error52, path14 = []) => {
|
|
1825
1865
|
for (const issue2 of error52.issues) {
|
|
1826
1866
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1827
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1867
|
+
issue2.errors.map((issues) => processError({ issues }, [...path14, ...issue2.path]));
|
|
1828
1868
|
} else if (issue2.code === "invalid_key") {
|
|
1829
|
-
processError({ issues: issue2.issues }, [...
|
|
1869
|
+
processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
|
|
1830
1870
|
} else if (issue2.code === "invalid_element") {
|
|
1831
|
-
processError({ issues: issue2.issues }, [...
|
|
1871
|
+
processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
|
|
1832
1872
|
} else {
|
|
1833
|
-
const fullpath = [...
|
|
1873
|
+
const fullpath = [...path14, ...issue2.path];
|
|
1834
1874
|
if (fullpath.length === 0) {
|
|
1835
1875
|
fieldErrors._errors.push(mapper(issue2));
|
|
1836
1876
|
} else {
|
|
@@ -1857,17 +1897,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1857
1897
|
}
|
|
1858
1898
|
function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
1859
1899
|
const result = { errors: [] };
|
|
1860
|
-
const processError = (error52,
|
|
1900
|
+
const processError = (error52, path14 = []) => {
|
|
1861
1901
|
var _a3, _b;
|
|
1862
1902
|
for (const issue2 of error52.issues) {
|
|
1863
1903
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1864
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1904
|
+
issue2.errors.map((issues) => processError({ issues }, [...path14, ...issue2.path]));
|
|
1865
1905
|
} else if (issue2.code === "invalid_key") {
|
|
1866
|
-
processError({ issues: issue2.issues }, [...
|
|
1906
|
+
processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
|
|
1867
1907
|
} else if (issue2.code === "invalid_element") {
|
|
1868
|
-
processError({ issues: issue2.issues }, [...
|
|
1908
|
+
processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
|
|
1869
1909
|
} else {
|
|
1870
|
-
const fullpath = [...
|
|
1910
|
+
const fullpath = [...path14, ...issue2.path];
|
|
1871
1911
|
if (fullpath.length === 0) {
|
|
1872
1912
|
result.errors.push(mapper(issue2));
|
|
1873
1913
|
continue;
|
|
@@ -1899,8 +1939,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1899
1939
|
}
|
|
1900
1940
|
function toDotPath(_path) {
|
|
1901
1941
|
const segs = [];
|
|
1902
|
-
const
|
|
1903
|
-
for (const seg of
|
|
1942
|
+
const path14 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
1943
|
+
for (const seg of path14) {
|
|
1904
1944
|
if (typeof seg === "number")
|
|
1905
1945
|
segs.push(`[${seg}]`);
|
|
1906
1946
|
else if (typeof seg === "symbol")
|
|
@@ -5128,8 +5168,8 @@ function az_default() {
|
|
|
5128
5168
|
}
|
|
5129
5169
|
|
|
5130
5170
|
// ../../../node_modules/zod/v4/locales/be.js
|
|
5131
|
-
function getBelarusianPlural(
|
|
5132
|
-
const absCount = Math.abs(
|
|
5171
|
+
function getBelarusianPlural(count2, one, few, many) {
|
|
5172
|
+
const absCount = Math.abs(count2);
|
|
5133
5173
|
const lastDigit = absCount % 10;
|
|
5134
5174
|
const lastTwoDigits = absCount % 100;
|
|
5135
5175
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -7207,8 +7247,8 @@ function hu_default() {
|
|
|
7207
7247
|
}
|
|
7208
7248
|
|
|
7209
7249
|
// ../../../node_modules/zod/v4/locales/hy.js
|
|
7210
|
-
function getArmenianPlural(
|
|
7211
|
-
return Math.abs(
|
|
7250
|
+
function getArmenianPlural(count2, one, many) {
|
|
7251
|
+
return Math.abs(count2) === 1 ? one : many;
|
|
7212
7252
|
}
|
|
7213
7253
|
function withDefiniteArticle(word) {
|
|
7214
7254
|
if (!word)
|
|
@@ -9336,8 +9376,8 @@ function ro_default() {
|
|
|
9336
9376
|
}
|
|
9337
9377
|
|
|
9338
9378
|
// ../../../node_modules/zod/v4/locales/ru.js
|
|
9339
|
-
function getRussianPlural(
|
|
9340
|
-
const absCount = Math.abs(
|
|
9379
|
+
function getRussianPlural(count2, one, few, many) {
|
|
9380
|
+
const absCount = Math.abs(count2);
|
|
9341
9381
|
const lastDigit = absCount % 10;
|
|
9342
9382
|
const lastTwoDigits = absCount % 100;
|
|
9343
9383
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -14592,13 +14632,13 @@ function resolveRef(ref, ctx) {
|
|
|
14592
14632
|
if (!ref.startsWith("#")) {
|
|
14593
14633
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
14594
14634
|
}
|
|
14595
|
-
const
|
|
14596
|
-
if (
|
|
14635
|
+
const path14 = ref.slice(1).split("/").filter(Boolean);
|
|
14636
|
+
if (path14.length === 0) {
|
|
14597
14637
|
return ctx.rootSchema;
|
|
14598
14638
|
}
|
|
14599
14639
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
14600
|
-
if (
|
|
14601
|
-
const key =
|
|
14640
|
+
if (path14[0] === defsKey) {
|
|
14641
|
+
const key = path14[1];
|
|
14602
14642
|
if (!key || !ctx.defs[key]) {
|
|
14603
14643
|
throw new Error(`Reference not found: ${ref}`);
|
|
14604
14644
|
}
|
|
@@ -15006,6 +15046,15 @@ function date4(params) {
|
|
|
15006
15046
|
// ../../../node_modules/zod/v4/classic/external.js
|
|
15007
15047
|
config(en_default());
|
|
15008
15048
|
|
|
15049
|
+
// ../../shared-contracts/dist/delegation-read.js
|
|
15050
|
+
var REMOTE_THREAD_REPLY_MAX_BYTES = 16 * 1024 * 1024;
|
|
15051
|
+
var delegationReadParamsSchema = external_exports.strictObject({
|
|
15052
|
+
threadId: external_exports.string().min(1).max(1024),
|
|
15053
|
+
view: external_exports.enum(["result", "messages"]),
|
|
15054
|
+
cursor: external_exports.string().min(1).max(8192).optional(),
|
|
15055
|
+
limit: external_exports.number().int().min(1).max(100).optional()
|
|
15056
|
+
});
|
|
15057
|
+
|
|
15009
15058
|
// ../../shared-contracts/dist/credential-imports.js
|
|
15010
15059
|
var credentialSourceSchema = external_exports.object({
|
|
15011
15060
|
id: external_exports.string().min(1).max(256),
|
|
@@ -15076,6 +15125,153 @@ var harnessDisplaySetSchema = external_exports.strictObject({
|
|
|
15076
15125
|
initializeOnly: external_exports.boolean().optional()
|
|
15077
15126
|
});
|
|
15078
15127
|
|
|
15128
|
+
// ../../shared-contracts/dist/model-price-overrides.js
|
|
15129
|
+
var usdPerMillionTokens = external_exports.number().finite().nonnegative();
|
|
15130
|
+
var modelPriceOverrideSchema = external_exports.strictObject({
|
|
15131
|
+
input: usdPerMillionTokens,
|
|
15132
|
+
output: usdPerMillionTokens,
|
|
15133
|
+
cacheRead: usdPerMillionTokens.optional(),
|
|
15134
|
+
cacheWrite: usdPerMillionTokens.optional(),
|
|
15135
|
+
cacheWrite1h: usdPerMillionTokens.optional()
|
|
15136
|
+
});
|
|
15137
|
+
var modelPriceKeySchema = external_exports.string().max(512).refine((key) => key.trim() === key && key.length > 0, "Model ID is required");
|
|
15138
|
+
var modelPriceOverridesSchema = external_exports.strictObject({
|
|
15139
|
+
/** Absolute path of the Host's `pricing.json`. */
|
|
15140
|
+
path: external_exports.string(),
|
|
15141
|
+
entries: external_exports.array(external_exports.strictObject({ key: external_exports.string(), price: modelPriceOverrideSchema })),
|
|
15142
|
+
/** Why the existing file is unusable; the Host then ignores it and refuses to overwrite it. */
|
|
15143
|
+
error: external_exports.string().nullable()
|
|
15144
|
+
});
|
|
15145
|
+
var modelPriceOverridesGetSchema = external_exports.strictObject({});
|
|
15146
|
+
var modelPriceOverridesSetSchema = external_exports.strictObject({
|
|
15147
|
+
key: modelPriceKeySchema,
|
|
15148
|
+
price: modelPriceOverrideSchema.nullable(),
|
|
15149
|
+
previousKey: modelPriceKeySchema.optional()
|
|
15150
|
+
});
|
|
15151
|
+
var modelPriceDefaultParamsSchema = external_exports.strictObject({
|
|
15152
|
+
model: modelPriceKeySchema
|
|
15153
|
+
});
|
|
15154
|
+
var modelPriceSuggestionSchema = external_exports.strictObject({
|
|
15155
|
+
/** Verified from catalog canonical links, not inferred from names or equal prices. */
|
|
15156
|
+
official: external_exports.boolean().optional(),
|
|
15157
|
+
canonicalModelId: external_exports.string().min(1).optional(),
|
|
15158
|
+
provider: external_exports.string().min(1).max(512),
|
|
15159
|
+
model: external_exports.string().min(1).max(512),
|
|
15160
|
+
price: modelPriceOverrideSchema
|
|
15161
|
+
});
|
|
15162
|
+
var modelPriceDefaultResultSchema = external_exports.strictObject({
|
|
15163
|
+
price: modelPriceOverrideSchema.nullable(),
|
|
15164
|
+
/** Local catalog suggestions only; never used automatically for pricing. */
|
|
15165
|
+
suggestions: external_exports.array(modelPriceSuggestionSchema).max(6).optional()
|
|
15166
|
+
});
|
|
15167
|
+
|
|
15168
|
+
// ../../shared-contracts/dist/usage-statistics.js
|
|
15169
|
+
var USAGE_STATISTICS_RANGES = ["today", "7d", "30d", "90d", "all"];
|
|
15170
|
+
var count = external_exports.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
|
|
15171
|
+
var localDate = external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/u);
|
|
15172
|
+
var harness = external_exports.string().min(1).max(128);
|
|
15173
|
+
var model = external_exports.string().min(1).max(512);
|
|
15174
|
+
var project = external_exports.string().min(1).max(4096);
|
|
15175
|
+
var usageStatisticsParamsSchema = external_exports.strictObject({
|
|
15176
|
+
range: external_exports.enum(USAGE_STATISTICS_RANGES),
|
|
15177
|
+
harness: harness.optional(),
|
|
15178
|
+
model: model.nullable().optional(),
|
|
15179
|
+
project: project.nullable().optional(),
|
|
15180
|
+
/** One local date inside the range. */
|
|
15181
|
+
date: localDate.optional()
|
|
15182
|
+
});
|
|
15183
|
+
var usageStatisticsTotalsSchema = external_exports.strictObject({
|
|
15184
|
+
requests: count,
|
|
15185
|
+
inputTokens: count,
|
|
15186
|
+
cachedInputTokens: count,
|
|
15187
|
+
cacheWriteInputTokens: count,
|
|
15188
|
+
cacheKnownInputTokens: count,
|
|
15189
|
+
outputTokens: count,
|
|
15190
|
+
reasoningOutputTokens: count,
|
|
15191
|
+
/** USD at the public price, summed over the priced requests only. */
|
|
15192
|
+
costUsd: external_exports.number().finite().min(0),
|
|
15193
|
+
/** Requests without a price (or the cache data the price needs); not in `costUsd`. */
|
|
15194
|
+
unpricedRequests: count,
|
|
15195
|
+
/**
|
|
15196
|
+
* Requests whose storage gave no token counts: counted as requests, with neither tokens nor
|
|
15197
|
+
* cost, and not as unpriced.
|
|
15198
|
+
*/
|
|
15199
|
+
unmeteredRequests: count
|
|
15200
|
+
});
|
|
15201
|
+
var totals = usageStatisticsTotalsSchema.shape;
|
|
15202
|
+
var usageStatisticsSessionSchema = external_exports.strictObject({
|
|
15203
|
+
harness,
|
|
15204
|
+
sessionId: external_exports.string().min(1).max(512),
|
|
15205
|
+
project: project.nullable(),
|
|
15206
|
+
/** Models the session used, most requests first. */
|
|
15207
|
+
models: external_exports.array(model).max(16),
|
|
15208
|
+
firstAtMs: count,
|
|
15209
|
+
lastAtMs: count,
|
|
15210
|
+
...totals
|
|
15211
|
+
});
|
|
15212
|
+
var usageStatisticsResultSchema = external_exports.strictObject({
|
|
15213
|
+
range: external_exports.enum(USAGE_STATISTICS_RANGES),
|
|
15214
|
+
/** First local date of the range; null for all time. */
|
|
15215
|
+
from: localDate.nullable(),
|
|
15216
|
+
to: localDate,
|
|
15217
|
+
/** The filters these figures apply, echoed so a late answer to older filters is recognised. */
|
|
15218
|
+
filters: external_exports.strictObject({
|
|
15219
|
+
harness: harness.nullable(),
|
|
15220
|
+
model: model.nullable(),
|
|
15221
|
+
unknownModel: external_exports.boolean(),
|
|
15222
|
+
project: project.nullable(),
|
|
15223
|
+
unknownProject: external_exports.boolean(),
|
|
15224
|
+
date: localDate.nullable()
|
|
15225
|
+
}),
|
|
15226
|
+
/** Reading of native storage: incomplete while the first read, or a refresh, is under way. */
|
|
15227
|
+
reading: external_exports.strictObject({ complete: external_exports.boolean(), sources: count, read: count }),
|
|
15228
|
+
/** Harnesses whose storage could not be read; their part is missing, the rest is complete. */
|
|
15229
|
+
failures: external_exports.array(external_exports.strictObject({ harness, message: external_exports.string().max(2048) })).max(256),
|
|
15230
|
+
/** Every value seen in the range, ignoring the filters, to choose filters from. */
|
|
15231
|
+
options: external_exports.strictObject({
|
|
15232
|
+
harnesses: external_exports.array(harness).max(256),
|
|
15233
|
+
models: external_exports.array(model.nullable()).max(4096),
|
|
15234
|
+
projects: external_exports.array(project.nullable()).max(4096)
|
|
15235
|
+
}),
|
|
15236
|
+
/** Current display metadata, scoped by Harness. Never a pricing or filter identity.
|
|
15237
|
+
* Optional for older Hosts; missing/conflicting labels fall back to the native model ID.
|
|
15238
|
+
*/
|
|
15239
|
+
modelLabels: external_exports.array(external_exports.strictObject({ harness, model, label: model })).max(4096).optional(),
|
|
15240
|
+
/** Native credits, all filters applied, never combined across Harnesses or treated as USD.
|
|
15241
|
+
* Only groups with at least one reported value appear; reportedRequests exposes partial data.
|
|
15242
|
+
*/
|
|
15243
|
+
credits: external_exports.array(external_exports.strictObject({
|
|
15244
|
+
harness,
|
|
15245
|
+
model: model.nullable(),
|
|
15246
|
+
credits: external_exports.number().finite().min(0),
|
|
15247
|
+
reportedRequests: count,
|
|
15248
|
+
requests: count
|
|
15249
|
+
})).max(4096).optional(),
|
|
15250
|
+
/** All filters applied. */
|
|
15251
|
+
totals: usageStatisticsTotalsSchema,
|
|
15252
|
+
/** Each date and Harness of the range: every filter except the day. */
|
|
15253
|
+
daily: external_exports.array(external_exports.strictObject({ date: localDate, harness, ...totals })).max(2e5),
|
|
15254
|
+
/** Local weekday (0 = Sunday) and hour, all filters applied. */
|
|
15255
|
+
hourly: external_exports.array(external_exports.strictObject({
|
|
15256
|
+
weekday: external_exports.number().int().min(0).max(6),
|
|
15257
|
+
hour: external_exports.number().int().min(0).max(23),
|
|
15258
|
+
...totals
|
|
15259
|
+
})).max(168),
|
|
15260
|
+
byHarness: external_exports.array(external_exports.strictObject({ harness, ...totals })).max(256),
|
|
15261
|
+
byModel: external_exports.array(external_exports.strictObject({
|
|
15262
|
+
model: model.nullable(),
|
|
15263
|
+
...totals,
|
|
15264
|
+
/** Requests priced by what the Harness recorded they cost, not by a price list. */
|
|
15265
|
+
harnessPricedRequests: count
|
|
15266
|
+
})).max(4096),
|
|
15267
|
+
byProject: external_exports.array(external_exports.strictObject({ project: project.nullable(), ...totals })).max(4096),
|
|
15268
|
+
/**
|
|
15269
|
+
* The sessions that spent the most, by cost and by tokens without cache, all filters applied;
|
|
15270
|
+
* requests without a native session are not listed here but count everywhere else.
|
|
15271
|
+
*/
|
|
15272
|
+
sessions: external_exports.array(usageStatisticsSessionSchema).max(100)
|
|
15273
|
+
});
|
|
15274
|
+
|
|
15079
15275
|
// ../../shared-contracts/dist/ids.js
|
|
15080
15276
|
var opaqueIdSchema = external_exports.string().refine((value) => value.trim().length > 0, {
|
|
15081
15277
|
message: "Identifier must not be empty or whitespace"
|
|
@@ -15086,6 +15282,10 @@ var hostTurnIdSchema = opaqueIdSchema.brand();
|
|
|
15086
15282
|
var hostItemIdSchema = opaqueIdSchema.brand();
|
|
15087
15283
|
var hostInteractionIdSchema = opaqueIdSchema.brand();
|
|
15088
15284
|
|
|
15285
|
+
// ../../shared-contracts/dist/thread-prewarm.js
|
|
15286
|
+
var threadPrewarmDiscardParamsSchema = external_exports.object({ threadId: hostThreadIdSchema });
|
|
15287
|
+
var threadPrewarmDiscardResultSchema = external_exports.object({ discarded: external_exports.boolean() });
|
|
15288
|
+
|
|
15089
15289
|
// ../../shared-contracts/dist/harness-plugins.js
|
|
15090
15290
|
var HARNESS_PLUGIN_MANIFEST_MAX_BYTES = 32 * 1024;
|
|
15091
15291
|
var HARNESS_PLUGIN_ICON_MAX_BYTES = 128 * 1024;
|
|
@@ -15093,13 +15293,40 @@ var HARNESS_PLUGIN_LIMIT = 128;
|
|
|
15093
15293
|
var harnessPluginIdSchema = external_exports.string().min(1).max(128).regex(/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/u).refine((id) => id !== "codex", "The official Codex identity is reserved").pipe(harnessIdSchema);
|
|
15094
15294
|
var relativeResourceSchema = external_exports.string().min(1).max(512).refine((value) => !/[\\\u0000:#?]/u.test(value) && !value.startsWith("/") && !value.split("/").some((part) => part === ".." || part === ""), "Plugin resources must be relative paths inside the plugin");
|
|
15095
15295
|
var documentationUrlSchema = external_exports.url().refine((value) => /^https:\/\/[^/?#@]+(?:[/?#]|$)/iu.test(value), "Plugin documentation links must be credential-free HTTPS URLs");
|
|
15296
|
+
var localizedTextSchema = external_exports.object({ en: external_exports.string().max(4096), "zh-CN": external_exports.string().max(4096).optional() }).strict();
|
|
15297
|
+
var harnessInstallationGuideSchema = external_exports.object({
|
|
15298
|
+
commands: external_exports.array(external_exports.object({ terminal: external_exports.string().max(256), command: external_exports.string().max(4096) }).strict()).max(8),
|
|
15299
|
+
before: localizedTextSchema.optional(),
|
|
15300
|
+
after: localizedTextSchema.optional(),
|
|
15301
|
+
downloads: external_exports.array(external_exports.object({ label: external_exports.string().max(128), url: documentationUrlSchema }).strict()).max(8).optional()
|
|
15302
|
+
}).strict();
|
|
15096
15303
|
var pluginPresentationShape = {
|
|
15097
15304
|
id: harnessPluginIdSchema,
|
|
15098
15305
|
name: external_exports.string().trim().min(1).max(128),
|
|
15099
15306
|
version: external_exports.string().min(1).max(128),
|
|
15307
|
+
/** Capability-only plugin; omitted for existing session-capable plugins. */
|
|
15308
|
+
kind: external_exports.literal("usage").optional(),
|
|
15309
|
+
/** Original image styling or bounded vector paths; never arbitrary CSS/SVG markup. */
|
|
15310
|
+
iconStyle: external_exports.object({
|
|
15311
|
+
vector: external_exports.object({
|
|
15312
|
+
viewBox: external_exports.string().max(128).regex(/^-?\d+(?:\.\d+)?(?: +-?\d+(?:\.\d+)?){3}$/u),
|
|
15313
|
+
color: external_exports.string().regex(/^(?:currentColor|#[a-f0-9]{6})$/iu),
|
|
15314
|
+
paths: external_exports.array(external_exports.object({
|
|
15315
|
+
d: external_exports.string().min(1).max(32768).regex(/^[MmLlHhVvCcSsQqTtAaZz\d.,+eE\s-]+$/u),
|
|
15316
|
+
fillRule: external_exports.enum(["evenodd", "nonzero"]).optional(),
|
|
15317
|
+
fill: external_exports.string().regex(/^(?:currentColor|#[a-f0-9]{6})$/iu).optional()
|
|
15318
|
+
}).strict()).min(1).max(32)
|
|
15319
|
+
}).strict().optional(),
|
|
15320
|
+
background: external_exports.string().regex(/^#[a-f0-9]{6}$/iu).optional(),
|
|
15321
|
+
borderRadius: external_exports.number().min(0).max(50).optional(),
|
|
15322
|
+
paddingRatio: external_exports.number().min(0).max(0.25).optional()
|
|
15323
|
+
}).strict().optional(),
|
|
15324
|
+
installation: harnessInstallationGuideSchema.optional(),
|
|
15325
|
+
notice: localizedTextSchema.optional(),
|
|
15100
15326
|
/** The factory accepts a persisted local entrypoint through its construction context. */
|
|
15101
15327
|
launchCommand: external_exports.literal(true).optional(),
|
|
15102
15328
|
links: external_exports.object({
|
|
15329
|
+
website: documentationUrlSchema.optional(),
|
|
15103
15330
|
documentation: documentationUrlSchema.optional(),
|
|
15104
15331
|
installation: documentationUrlSchema.optional()
|
|
15105
15332
|
}).strict().optional()
|
|
@@ -15153,6 +15380,9 @@ var consoleOpenResultSchema = external_exports.strictObject({
|
|
|
15153
15380
|
url: external_exports.string().max(2048).regex(/^http:\/\/(?:127\.0\.0\.1|localhost):\d{1,5}\/(?:\?.*)?$/u)
|
|
15154
15381
|
});
|
|
15155
15382
|
var CONSOLE_HOST_METHODS = Object.freeze([
|
|
15383
|
+
"codexhost/console/remote-connections",
|
|
15384
|
+
"codexhost/runtime/status",
|
|
15385
|
+
"codexhost/remote/ssh-setup",
|
|
15156
15386
|
"codexhost/harness/plugins/list",
|
|
15157
15387
|
"codexhost/harness/display-settings/get",
|
|
15158
15388
|
"codexhost/harness/display-settings/set",
|
|
@@ -15173,6 +15403,10 @@ var CONSOLE_HOST_METHODS = Object.freeze([
|
|
|
15173
15403
|
"codexhost/account/list",
|
|
15174
15404
|
"codexhost/account/refresh",
|
|
15175
15405
|
"codexhost/account/usage/inspect",
|
|
15406
|
+
"codexhost/usage/model-prices/get",
|
|
15407
|
+
"codexhost/usage/model-prices/set",
|
|
15408
|
+
"codexhost/usage/model-prices/default",
|
|
15409
|
+
"codexhost/usage/statistics/get",
|
|
15176
15410
|
"codexhost/update/check",
|
|
15177
15411
|
"codexhost/update/start",
|
|
15178
15412
|
"codexhost/update/status"
|
|
@@ -15237,6 +15471,7 @@ var threadUsageSnapshotSchema = external_exports.object({
|
|
|
15237
15471
|
cacheWriteInputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
15238
15472
|
outputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
15239
15473
|
outputTokensPerSecond: finiteNonNegativeNumberSchema.optional(),
|
|
15474
|
+
apiOutputTokensPerSecond: finiteNonNegativeNumberSchema.optional(),
|
|
15240
15475
|
reasoningOutputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
15241
15476
|
totalTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
15242
15477
|
totalCostUsd: finiteNonNegativeNumberSchema.optional(),
|
|
@@ -15248,7 +15483,11 @@ var threadUsageSnapshotSchema = external_exports.object({
|
|
|
15248
15483
|
planFiveHourUsedPercent: cacheHitRatePercentSchema.optional(),
|
|
15249
15484
|
planFiveHourResetsAtUnix: nonNegativeSafeIntegerSchema.optional(),
|
|
15250
15485
|
planSevenDayUsedPercent: cacheHitRatePercentSchema.optional(),
|
|
15251
|
-
planSevenDayResetsAtUnix: nonNegativeSafeIntegerSchema.optional()
|
|
15486
|
+
planSevenDayResetsAtUnix: nonNegativeSafeIntegerSchema.optional(),
|
|
15487
|
+
sessionCacheHitRatePercent: cacheHitRatePercentSchema.optional(),
|
|
15488
|
+
timeToFirstOutputMs: nonNegativeSafeIntegerSchema.optional(),
|
|
15489
|
+
costSource: external_exports.enum(["publicPrice", "native"]).optional(),
|
|
15490
|
+
unpricedModels: external_exports.array(external_exports.string().min(1)).min(1).optional()
|
|
15252
15491
|
}).strict().superRefine((usage, context) => {
|
|
15253
15492
|
if (Object.keys(usage).length === 0) {
|
|
15254
15493
|
context.addIssue({ code: "custom", message: "Thread Usage must contain a reliable field" });
|
|
@@ -15269,6 +15508,20 @@ var threadUsageSnapshotSchema = external_exports.object({
|
|
|
15269
15508
|
path: ["contextWindowTokens"]
|
|
15270
15509
|
});
|
|
15271
15510
|
}
|
|
15511
|
+
if (usage.costSource !== void 0 && usage.totalCostUsd === void 0) {
|
|
15512
|
+
context.addIssue({
|
|
15513
|
+
code: "custom",
|
|
15514
|
+
message: "Thread Usage costSource must be provided with totalCostUsd",
|
|
15515
|
+
path: ["costSource"]
|
|
15516
|
+
});
|
|
15517
|
+
}
|
|
15518
|
+
if (usage.unpricedModels !== void 0 && usage.costSource !== "publicPrice") {
|
|
15519
|
+
context.addIssue({
|
|
15520
|
+
code: "custom",
|
|
15521
|
+
message: "Thread Usage unpricedModels must be provided with a publicPrice cost",
|
|
15522
|
+
path: ["unpricedModels"]
|
|
15523
|
+
});
|
|
15524
|
+
}
|
|
15272
15525
|
if (usage.planFiveHourResetsAtUnix !== void 0 && usage.planFiveHourUsedPercent === void 0) {
|
|
15273
15526
|
context.addIssue({
|
|
15274
15527
|
code: "custom",
|
|
@@ -15538,27 +15791,27 @@ var harnessModelCatalogSchema = external_exports.object({
|
|
|
15538
15791
|
}).strict().superRefine((catalog, context) => {
|
|
15539
15792
|
const refs = /* @__PURE__ */ new Set();
|
|
15540
15793
|
const thinkingIds = new Set(catalog.thinkingOptions.map(({ id }) => id));
|
|
15541
|
-
for (const [index,
|
|
15542
|
-
if (refs.has(
|
|
15794
|
+
for (const [index, model2] of catalog.models.entries()) {
|
|
15795
|
+
if (refs.has(model2.ref.id)) {
|
|
15543
15796
|
context.addIssue({
|
|
15544
15797
|
code: "custom",
|
|
15545
15798
|
message: "Model Catalog refs must be unique",
|
|
15546
15799
|
path: ["models", index, "ref", "id"]
|
|
15547
15800
|
});
|
|
15548
15801
|
}
|
|
15549
|
-
refs.add(
|
|
15550
|
-
if (
|
|
15551
|
-
if (refs.has(
|
|
15802
|
+
refs.add(model2.ref.id);
|
|
15803
|
+
if (model2.fastModel) {
|
|
15804
|
+
if (refs.has(model2.fastModel.id) || catalog.models.some((entry) => entry.ref.id === model2.fastModel?.id)) {
|
|
15552
15805
|
context.addIssue({
|
|
15553
15806
|
code: "custom",
|
|
15554
15807
|
message: "Fast Model refs must be distinct and unique",
|
|
15555
15808
|
path: ["models", index, "fastModel"]
|
|
15556
15809
|
});
|
|
15557
15810
|
}
|
|
15558
|
-
refs.add(
|
|
15811
|
+
refs.add(model2.fastModel.id);
|
|
15559
15812
|
}
|
|
15560
15813
|
const supportedThinkingIds = /* @__PURE__ */ new Set();
|
|
15561
|
-
for (const [optionIndex, optionId] of (
|
|
15814
|
+
for (const [optionIndex, optionId] of (model2.supportedThinkingOptionIds ?? []).entries()) {
|
|
15562
15815
|
if (supportedThinkingIds.has(optionId)) {
|
|
15563
15816
|
context.addIssue({
|
|
15564
15817
|
code: "custom",
|
|
@@ -16098,6 +16351,85 @@ var updateStatusResultSchema = external_exports.strictObject({
|
|
|
16098
16351
|
status: updateStatusSchema.nullable()
|
|
16099
16352
|
});
|
|
16100
16353
|
|
|
16354
|
+
// ../../shared-contracts/dist/remote-runtime.js
|
|
16355
|
+
var remoteUpdatePhaseSchema = external_exports.enum([
|
|
16356
|
+
"idle",
|
|
16357
|
+
"installing",
|
|
16358
|
+
"restarting",
|
|
16359
|
+
"succeeded",
|
|
16360
|
+
"failed"
|
|
16361
|
+
]);
|
|
16362
|
+
var runtimeStatusSchema = external_exports.object({
|
|
16363
|
+
runningVersion: external_exports.string().nullable(),
|
|
16364
|
+
installedVersion: external_exports.string().nullable(),
|
|
16365
|
+
restartRequired: external_exports.boolean(),
|
|
16366
|
+
remote: external_exports.boolean(),
|
|
16367
|
+
updateSupported: external_exports.boolean(),
|
|
16368
|
+
update: external_exports.object({
|
|
16369
|
+
phase: remoteUpdatePhaseSchema,
|
|
16370
|
+
targetVersion: external_exports.string().nullable(),
|
|
16371
|
+
error: external_exports.string().nullable()
|
|
16372
|
+
})
|
|
16373
|
+
});
|
|
16374
|
+
var remoteUpdateParamsSchema = external_exports.object({
|
|
16375
|
+
version: external_exports.string().regex(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/u)
|
|
16376
|
+
}).strict();
|
|
16377
|
+
var remoteSshSetupParamsSchema = external_exports.object({
|
|
16378
|
+
hostname: external_exports.string().min(1).max(1024).refine((value) => !value.startsWith("-") && !/\s/u.test(value)),
|
|
16379
|
+
port: external_exports.number().int().min(1).max(65535).nullable(),
|
|
16380
|
+
identity: external_exports.string().max(4096).nullable(),
|
|
16381
|
+
action: external_exports.enum(["inspect", "install", "update", "repair", "uninstall"]),
|
|
16382
|
+
uninstallPackage: external_exports.boolean().optional(),
|
|
16383
|
+
version: external_exports.string().regex(/^\d+\.\d+\.\d+$/u).nullable()
|
|
16384
|
+
}).strict();
|
|
16385
|
+
var remoteSshSetupResultSchema = external_exports.object({ state: external_exports.enum(["installed", "not-installed"]) }).strict();
|
|
16386
|
+
|
|
16387
|
+
// ../../shared-contracts/dist/remote-connections.js
|
|
16388
|
+
var hostId = external_exports.string().min(1).max(1024);
|
|
16389
|
+
var codexSshConnectionSchema = external_exports.object({
|
|
16390
|
+
hostId,
|
|
16391
|
+
displayName: external_exports.string().min(1).max(1024),
|
|
16392
|
+
source: external_exports.enum(["codex-managed", "discovered"]),
|
|
16393
|
+
sshAlias: external_exports.string().max(1024).nullable(),
|
|
16394
|
+
sshHost: external_exports.string().min(1).max(1024),
|
|
16395
|
+
sshPort: external_exports.number().int().min(1).max(65535).nullable(),
|
|
16396
|
+
identity: external_exports.string().max(4096).nullable(),
|
|
16397
|
+
autoConnect: external_exports.boolean(),
|
|
16398
|
+
connectionAnalyticsId: external_exports.string().max(1024).optional()
|
|
16399
|
+
});
|
|
16400
|
+
var codexSshDraftSchema = external_exports.strictObject({
|
|
16401
|
+
displayName: external_exports.string().min(1).max(1024),
|
|
16402
|
+
hostname: external_exports.string().min(1).max(1024),
|
|
16403
|
+
sshPort: external_exports.number().int().min(1).max(65535).nullable(),
|
|
16404
|
+
identity: external_exports.string().max(4096).nullable()
|
|
16405
|
+
});
|
|
16406
|
+
var remoteConnectionsRequestSchema = external_exports.discriminatedUnion("action", [
|
|
16407
|
+
external_exports.strictObject({ action: external_exports.literal("list") }),
|
|
16408
|
+
external_exports.strictObject({
|
|
16409
|
+
action: external_exports.literal("read-thread"),
|
|
16410
|
+
hostId: hostId.refine((id) => id !== "local"),
|
|
16411
|
+
input: delegationReadParamsSchema
|
|
16412
|
+
}),
|
|
16413
|
+
external_exports.strictObject({
|
|
16414
|
+
action: external_exports.literal("save"),
|
|
16415
|
+
draft: codexSshDraftSchema,
|
|
16416
|
+
previous: codexSshConnectionSchema.nullable()
|
|
16417
|
+
}),
|
|
16418
|
+
external_exports.strictObject({ action: external_exports.literal("remove"), previous: codexSshConnectionSchema }),
|
|
16419
|
+
external_exports.strictObject({ action: external_exports.literal("connect"), hostId, enabled: external_exports.boolean() }),
|
|
16420
|
+
external_exports.strictObject({ action: external_exports.literal("state"), hostId }),
|
|
16421
|
+
external_exports.strictObject({ action: external_exports.literal("runtime"), hostId }),
|
|
16422
|
+
external_exports.strictObject({
|
|
16423
|
+
action: external_exports.literal("update"),
|
|
16424
|
+
hostId: hostId.refine((id) => id !== "local"),
|
|
16425
|
+
version: remoteUpdateParamsSchema.shape.version
|
|
16426
|
+
})
|
|
16427
|
+
]);
|
|
16428
|
+
var remoteConnectionsReplySchema = external_exports.union([
|
|
16429
|
+
external_exports.strictObject({ result: jsonValueSchema }),
|
|
16430
|
+
external_exports.strictObject({ error: external_exports.strictObject({ code: external_exports.number().int(), message: external_exports.string() }) })
|
|
16431
|
+
]);
|
|
16432
|
+
|
|
16101
16433
|
// ../../shared-contracts/dist/index.js
|
|
16102
16434
|
var workspaceContractVersionSchema = external_exports.literal(WORKSPACE_CONTRACT_VERSION);
|
|
16103
16435
|
|
|
@@ -16209,7 +16541,6 @@ var tokenFields = [
|
|
|
16209
16541
|
"cachedInputTokens",
|
|
16210
16542
|
"cacheWriteInputTokens",
|
|
16211
16543
|
"outputTokens",
|
|
16212
|
-
"outputTokensPerSecond",
|
|
16213
16544
|
"reasoningOutputTokens",
|
|
16214
16545
|
"totalTokens",
|
|
16215
16546
|
"contextWindowTokens",
|
|
@@ -16217,10 +16548,12 @@ var tokenFields = [
|
|
|
16217
16548
|
];
|
|
16218
16549
|
var safeIntegerFields = [
|
|
16219
16550
|
"planFiveHourResetsAtUnix",
|
|
16220
|
-
"planSevenDayResetsAtUnix"
|
|
16551
|
+
"planSevenDayResetsAtUnix",
|
|
16552
|
+
"timeToFirstOutputMs"
|
|
16221
16553
|
];
|
|
16222
16554
|
var percentFields = [
|
|
16223
16555
|
"cacheHitRatePercent",
|
|
16556
|
+
"sessionCacheHitRatePercent",
|
|
16224
16557
|
"planFiveHourUsedPercent",
|
|
16225
16558
|
"planSevenDayUsedPercent"
|
|
16226
16559
|
];
|
|
@@ -16228,9 +16561,14 @@ var usageFields = /* @__PURE__ */ new Set([
|
|
|
16228
16561
|
...tokenFields,
|
|
16229
16562
|
...safeIntegerFields,
|
|
16230
16563
|
...percentFields,
|
|
16564
|
+
"sessionCacheUsage",
|
|
16231
16565
|
"totalCostUsd",
|
|
16232
16566
|
"totalCredits",
|
|
16233
|
-
"contextUsagePercent"
|
|
16567
|
+
"contextUsagePercent",
|
|
16568
|
+
"outputTokensPerSecond",
|
|
16569
|
+
"apiOutputTokensPerSecond",
|
|
16570
|
+
"costSource",
|
|
16571
|
+
"unpricedModels"
|
|
16234
16572
|
]);
|
|
16235
16573
|
function isRecord(value) {
|
|
16236
16574
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -16246,21 +16584,25 @@ function parseHostUsage(value) {
|
|
|
16246
16584
|
throw new Error(`Harness Usage contains unknown field '${key}'`);
|
|
16247
16585
|
}
|
|
16248
16586
|
}
|
|
16249
|
-
for (const field of [
|
|
16250
|
-
|
|
16251
|
-
|
|
16587
|
+
for (const field of [
|
|
16588
|
+
"totalCredits",
|
|
16589
|
+
"contextUsagePercent",
|
|
16590
|
+
"apiOutputTokensPerSecond"
|
|
16591
|
+
]) {
|
|
16592
|
+
const candidate2 = value[field];
|
|
16593
|
+
if (candidate2 !== void 0 && (typeof candidate2 !== "number" || !Number.isFinite(candidate2) || candidate2 < 0)) {
|
|
16252
16594
|
throw new Error(`Harness Usage '${field}' must be a finite non-negative number`);
|
|
16253
16595
|
}
|
|
16254
16596
|
}
|
|
16255
16597
|
for (const field of tokenFields) {
|
|
16256
|
-
const
|
|
16257
|
-
if (
|
|
16598
|
+
const candidate2 = value[field];
|
|
16599
|
+
if (candidate2 !== void 0 && (typeof candidate2 !== "number" || !Number.isSafeInteger(candidate2) || candidate2 < 0)) {
|
|
16258
16600
|
throw new Error(`Harness Usage '${field}' must be a non-negative safe integer`);
|
|
16259
16601
|
}
|
|
16260
16602
|
}
|
|
16261
16603
|
for (const field of safeIntegerFields) {
|
|
16262
|
-
const
|
|
16263
|
-
if (
|
|
16604
|
+
const candidate2 = value[field];
|
|
16605
|
+
if (candidate2 !== void 0 && (typeof candidate2 !== "number" || !Number.isSafeInteger(candidate2) || candidate2 < 0)) {
|
|
16264
16606
|
throw new Error(`Harness Usage '${field}' must be a non-negative safe integer`);
|
|
16265
16607
|
}
|
|
16266
16608
|
}
|
|
@@ -16271,17 +16613,23 @@ function parseHostUsage(value) {
|
|
|
16271
16613
|
throw new Error("Harness Usage 'totalCostUsd' must be a finite non-negative number");
|
|
16272
16614
|
}
|
|
16273
16615
|
for (const field of ["totalCredits", "contextUsagePercent"]) {
|
|
16274
|
-
const
|
|
16275
|
-
if (
|
|
16616
|
+
const candidate2 = value[field];
|
|
16617
|
+
if (candidate2 !== void 0 && (typeof candidate2 !== "number" || !Number.isFinite(candidate2) || candidate2 < 0)) {
|
|
16276
16618
|
throw new Error(`Harness Usage '${field}' must be a finite non-negative number`);
|
|
16277
16619
|
}
|
|
16278
16620
|
}
|
|
16279
16621
|
for (const field of percentFields) {
|
|
16280
|
-
const
|
|
16281
|
-
if (
|
|
16622
|
+
const candidate2 = value[field];
|
|
16623
|
+
if (candidate2 !== void 0 && (typeof candidate2 !== "number" || !Number.isFinite(candidate2) || candidate2 < 0 || candidate2 > 100)) {
|
|
16282
16624
|
throw new Error(`Harness Usage '${field}' must be between 0 and 100`);
|
|
16283
16625
|
}
|
|
16284
16626
|
}
|
|
16627
|
+
if (value.sessionCacheUsage !== void 0) {
|
|
16628
|
+
const totals2 = value.sessionCacheUsage;
|
|
16629
|
+
if (!isRecord(totals2) || Object.keys(totals2).some((key) => key !== "inputTokens" && key !== "cachedInputTokens") || typeof totals2.inputTokens !== "number" || !Number.isSafeInteger(totals2.inputTokens) || totals2.inputTokens < 0 || typeof totals2.cachedInputTokens !== "number" || !Number.isSafeInteger(totals2.cachedInputTokens) || totals2.cachedInputTokens < 0 || totals2.cachedInputTokens > totals2.inputTokens) {
|
|
16630
|
+
throw new Error("Harness Usage 'sessionCacheUsage' must contain complete bounded token totals");
|
|
16631
|
+
}
|
|
16632
|
+
}
|
|
16285
16633
|
const hasContextUsed = value.contextUsedTokens !== void 0;
|
|
16286
16634
|
const hasContextWindow = value.contextWindowTokens !== void 0;
|
|
16287
16635
|
if (hasContextUsed !== hasContextWindow) {
|
|
@@ -16296,8 +16644,217 @@ function parseHostUsage(value) {
|
|
|
16296
16644
|
if (value.planSevenDayResetsAtUnix !== void 0 && value.planSevenDayUsedPercent === void 0) {
|
|
16297
16645
|
throw new Error("Harness Usage 'planSevenDayResetsAtUnix' must be provided with 'planSevenDayUsedPercent'");
|
|
16298
16646
|
}
|
|
16647
|
+
if (value.costSource !== void 0) {
|
|
16648
|
+
if (value.costSource !== "publicPrice" && value.costSource !== "native") {
|
|
16649
|
+
throw new Error("Harness Usage 'costSource' must be 'publicPrice' or 'native'");
|
|
16650
|
+
}
|
|
16651
|
+
if (value.totalCostUsd === void 0) {
|
|
16652
|
+
throw new Error("Harness Usage 'costSource' must be provided with 'totalCostUsd'");
|
|
16653
|
+
}
|
|
16654
|
+
}
|
|
16655
|
+
if (value.unpricedModels !== void 0) {
|
|
16656
|
+
const models = value.unpricedModels;
|
|
16657
|
+
if (!Array.isArray(models) || models.length === 0 || !models.every((model2) => typeof model2 === "string" && model2.length > 0)) {
|
|
16658
|
+
throw new Error("Harness Usage 'unpricedModels' must be a non-empty list of Model IDs");
|
|
16659
|
+
}
|
|
16660
|
+
if (value.costSource !== "publicPrice") {
|
|
16661
|
+
throw new Error("Harness Usage 'unpricedModels' must be provided with a 'publicPrice' cost");
|
|
16662
|
+
}
|
|
16663
|
+
return { ...value, unpricedModels: [...models] };
|
|
16664
|
+
}
|
|
16299
16665
|
return { ...value };
|
|
16300
16666
|
}
|
|
16667
|
+
var requestTokenFields = [
|
|
16668
|
+
"inputTokens",
|
|
16669
|
+
"cachedInputTokens",
|
|
16670
|
+
"cacheWriteInputTokens",
|
|
16671
|
+
"cacheWrite1hInputTokens",
|
|
16672
|
+
"outputTokens",
|
|
16673
|
+
"reasoningOutputTokens",
|
|
16674
|
+
"startedAtMs",
|
|
16675
|
+
"completedAtMs"
|
|
16676
|
+
];
|
|
16677
|
+
var requestFields = /* @__PURE__ */ new Set([
|
|
16678
|
+
...requestTokenFields,
|
|
16679
|
+
"requestId",
|
|
16680
|
+
"historical",
|
|
16681
|
+
"model",
|
|
16682
|
+
"provider"
|
|
16683
|
+
]);
|
|
16684
|
+
function parseHostUsageRequest(value) {
|
|
16685
|
+
if (!isRecord(value))
|
|
16686
|
+
throw new Error("Harness Usage request must be an object");
|
|
16687
|
+
for (const key of Object.keys(value)) {
|
|
16688
|
+
if (!requestFields.has(key)) {
|
|
16689
|
+
throw new Error(`Harness Usage request contains unknown field '${key}'`);
|
|
16690
|
+
}
|
|
16691
|
+
}
|
|
16692
|
+
if (typeof value.requestId !== "string" || value.requestId.length === 0) {
|
|
16693
|
+
throw new Error("Harness Usage request 'requestId' must be a non-empty string");
|
|
16694
|
+
}
|
|
16695
|
+
for (const field of ["model", "provider"]) {
|
|
16696
|
+
const candidate2 = value[field];
|
|
16697
|
+
if (candidate2 !== void 0 && (typeof candidate2 !== "string" || candidate2.length === 0)) {
|
|
16698
|
+
throw new Error(`Harness Usage request '${field}' must be a non-empty string`);
|
|
16699
|
+
}
|
|
16700
|
+
}
|
|
16701
|
+
if (value.historical !== void 0 && typeof value.historical !== "boolean") {
|
|
16702
|
+
throw new Error("Harness Usage request 'historical' must be a boolean");
|
|
16703
|
+
}
|
|
16704
|
+
for (const field of requestTokenFields) {
|
|
16705
|
+
const candidate2 = value[field];
|
|
16706
|
+
if (candidate2 !== void 0 && (typeof candidate2 !== "number" || !Number.isSafeInteger(candidate2) || candidate2 < 0)) {
|
|
16707
|
+
throw new Error(`Harness Usage request '${field}' must be a non-negative safe integer`);
|
|
16708
|
+
}
|
|
16709
|
+
}
|
|
16710
|
+
if (value.inputTokens === void 0 || value.outputTokens === void 0) {
|
|
16711
|
+
throw new Error("Harness Usage request must contain 'inputTokens' and 'outputTokens'");
|
|
16712
|
+
}
|
|
16713
|
+
const request = value;
|
|
16714
|
+
if ((request.cachedInputTokens ?? 0) + (request.cacheWriteInputTokens ?? 0) > request.inputTokens) {
|
|
16715
|
+
throw new Error("Harness Usage request cache Tokens must not exceed 'inputTokens'");
|
|
16716
|
+
}
|
|
16717
|
+
if ((request.reasoningOutputTokens ?? 0) > request.outputTokens) {
|
|
16718
|
+
throw new Error("Harness Usage request 'reasoningOutputTokens' must not exceed 'outputTokens'");
|
|
16719
|
+
}
|
|
16720
|
+
if (request.cacheWrite1hInputTokens !== void 0 && request.cacheWrite1hInputTokens > (request.cacheWriteInputTokens ?? -1)) {
|
|
16721
|
+
throw new Error("Harness Usage request 'cacheWrite1hInputTokens' must not exceed 'cacheWriteInputTokens'");
|
|
16722
|
+
}
|
|
16723
|
+
if (request.startedAtMs === void 0 !== (request.completedAtMs === void 0)) {
|
|
16724
|
+
throw new Error("Harness Usage request timing fields must be provided together");
|
|
16725
|
+
}
|
|
16726
|
+
if (request.startedAtMs !== void 0 && request.completedAtMs !== void 0 && request.completedAtMs < request.startedAtMs) {
|
|
16727
|
+
throw new Error("Harness Usage request 'completedAtMs' must not precede 'startedAtMs'");
|
|
16728
|
+
}
|
|
16729
|
+
return { ...request };
|
|
16730
|
+
}
|
|
16731
|
+
|
|
16732
|
+
// dist/v2/usage.js
|
|
16733
|
+
function v2UsageRequest(message, historical, firstOutputAtMs) {
|
|
16734
|
+
if (message.type !== "assistant" || !message.tokens)
|
|
16735
|
+
return null;
|
|
16736
|
+
const { input, output, reasoning, cache } = message.tokens;
|
|
16737
|
+
const { streamed } = message.time;
|
|
16738
|
+
return parseHostUsageRequest({
|
|
16739
|
+
requestId: message.id,
|
|
16740
|
+
...historical ? { historical: true } : {},
|
|
16741
|
+
model: message.model.id,
|
|
16742
|
+
// Built-in OpenCode providers use models.dev IDs. A custom provider ID matches no price
|
|
16743
|
+
// entry, so Host falls back to the exact model ID.
|
|
16744
|
+
provider: message.model.providerID,
|
|
16745
|
+
inputTokens: input + cache.read + cache.write,
|
|
16746
|
+
cachedInputTokens: cache.read,
|
|
16747
|
+
cacheWriteInputTokens: cache.write,
|
|
16748
|
+
outputTokens: output + reasoning,
|
|
16749
|
+
reasoningOutputTokens: reasoning,
|
|
16750
|
+
// End at stream completion, not step completion, which can include tool execution.
|
|
16751
|
+
// Without a native stream end, keep the usage but do not guess its generation duration.
|
|
16752
|
+
...!historical && firstOutputAtMs !== void 0 && streamed !== void 0 && streamed >= firstOutputAtMs ? { startedAtMs: firstOutputAtMs, completedAtMs: streamed } : {}
|
|
16753
|
+
});
|
|
16754
|
+
}
|
|
16755
|
+
|
|
16756
|
+
// dist/usage-statistics.js
|
|
16757
|
+
function parseRowData(data) {
|
|
16758
|
+
try {
|
|
16759
|
+
return JSON.parse(String(data));
|
|
16760
|
+
} catch {
|
|
16761
|
+
return null;
|
|
16762
|
+
}
|
|
16763
|
+
}
|
|
16764
|
+
function isRecord2(value) {
|
|
16765
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16766
|
+
}
|
|
16767
|
+
function openCodeDatabasePath(environment) {
|
|
16768
|
+
const home = environment.HOME || environment.USERPROFILE || os2.homedir();
|
|
16769
|
+
const directory = path5.join(environment.XDG_DATA_HOME || path5.join(home, ".local", "share"), "opencode");
|
|
16770
|
+
const configured = environment.OPENCODE_DB;
|
|
16771
|
+
if (configured === ":memory:")
|
|
16772
|
+
return null;
|
|
16773
|
+
return configured ? path5.resolve(directory, configured) : path5.join(directory, "opencode.db");
|
|
16774
|
+
}
|
|
16775
|
+
async function fingerprint(file2) {
|
|
16776
|
+
const info = await lstat(file2).catch(() => null);
|
|
16777
|
+
if (!info?.isFile())
|
|
16778
|
+
return null;
|
|
16779
|
+
const wal = await lstat(`${file2}-wal`).catch(() => null);
|
|
16780
|
+
return `${info.ino}:${info.size}:${info.mtimeMs}:${wal ? `${wal.size}:${wal.mtimeMs}` : "-"}`;
|
|
16781
|
+
}
|
|
16782
|
+
async function readOpenCodeUsage(file2) {
|
|
16783
|
+
const { DatabaseSync } = await import("node:sqlite");
|
|
16784
|
+
const database = new DatabaseSync(file2, { readOnly: true });
|
|
16785
|
+
try {
|
|
16786
|
+
const tables = new Set(database.prepare("SELECT name FROM sqlite_master WHERE type = 'table'").all().map((row) => String(row.name)));
|
|
16787
|
+
const directories = /* @__PURE__ */ new Map();
|
|
16788
|
+
for (const table of ["session", "session_v2"]) {
|
|
16789
|
+
if (!tables.has(table))
|
|
16790
|
+
continue;
|
|
16791
|
+
for (const row of database.prepare(`SELECT id, directory FROM ${table}`).iterate()) {
|
|
16792
|
+
if (typeof row.directory === "string")
|
|
16793
|
+
directories.set(String(row.id), row.directory);
|
|
16794
|
+
}
|
|
16795
|
+
}
|
|
16796
|
+
const entries = /* @__PURE__ */ new Map();
|
|
16797
|
+
const add = (message, createdAtMs, session) => {
|
|
16798
|
+
let request;
|
|
16799
|
+
try {
|
|
16800
|
+
request = v2UsageRequest(message, true);
|
|
16801
|
+
} catch {
|
|
16802
|
+
return;
|
|
16803
|
+
}
|
|
16804
|
+
const at = nativeTimeMs(createdAtMs);
|
|
16805
|
+
const entry = request && at !== null && usageEntryFromRequest(request, at);
|
|
16806
|
+
if (entry && !entries.has(entry.id)) {
|
|
16807
|
+
const sessionId = typeof session === "string" ? session : void 0;
|
|
16808
|
+
entries.set(entry.id, withUsageSession(entry, {
|
|
16809
|
+
sessionId,
|
|
16810
|
+
cwd: sessionId === void 0 ? void 0 : directories.get(sessionId)
|
|
16811
|
+
}));
|
|
16812
|
+
}
|
|
16813
|
+
};
|
|
16814
|
+
if (tables.has("session_message")) {
|
|
16815
|
+
for (const row of database.prepare("SELECT id, session_id, data FROM session_message WHERE type = 'assistant'").iterate()) {
|
|
16816
|
+
const data = parseRowData(row.data);
|
|
16817
|
+
if (!isRecord2(data))
|
|
16818
|
+
continue;
|
|
16819
|
+
add({ ...data, id: String(row.id), type: "assistant" }, isRecord2(data.time) ? data.time.created : void 0, row.session_id);
|
|
16820
|
+
}
|
|
16821
|
+
}
|
|
16822
|
+
const migrated = tables.has("kv") && /"phase"\s*:\s*"completed"/u.test(String(database.prepare("SELECT value FROM kv WHERE key = 'migration.v1-v2'").get()?.value ?? ""));
|
|
16823
|
+
if (tables.has("message") && !migrated) {
|
|
16824
|
+
for (const row of database.prepare("SELECT id, session_id, data FROM message").iterate()) {
|
|
16825
|
+
const data = parseRowData(row.data);
|
|
16826
|
+
if (!isRecord2(data) || data.role !== "assistant" || typeof data.modelID !== "string") {
|
|
16827
|
+
continue;
|
|
16828
|
+
}
|
|
16829
|
+
add({
|
|
16830
|
+
id: String(row.id),
|
|
16831
|
+
type: "assistant",
|
|
16832
|
+
model: { id: data.modelID, providerID: data.providerID },
|
|
16833
|
+
tokens: data.tokens,
|
|
16834
|
+
time: data.time
|
|
16835
|
+
}, isRecord2(data.time) ? data.time.created : void 0, row.session_id);
|
|
16836
|
+
}
|
|
16837
|
+
}
|
|
16838
|
+
return [...entries.values()];
|
|
16839
|
+
} finally {
|
|
16840
|
+
database.close();
|
|
16841
|
+
}
|
|
16842
|
+
}
|
|
16843
|
+
function createOpenCodeUsageStatistics(environment) {
|
|
16844
|
+
return Object.freeze({
|
|
16845
|
+
async listSources() {
|
|
16846
|
+
const file2 = openCodeDatabasePath(environment);
|
|
16847
|
+
const stamp = file2 ? await fingerprint(file2) : null;
|
|
16848
|
+
return file2 && stamp ? [{ id: file2, fingerprint: stamp }] : [];
|
|
16849
|
+
},
|
|
16850
|
+
readSource: (id) => readOpenCodeUsage(id)
|
|
16851
|
+
});
|
|
16852
|
+
}
|
|
16853
|
+
|
|
16854
|
+
// dist/opencode-adapter.js
|
|
16855
|
+
import { randomUUID } from "node:crypto";
|
|
16856
|
+
import fs4 from "node:fs";
|
|
16857
|
+
import path9 from "node:path";
|
|
16301
16858
|
|
|
16302
16859
|
// dist/model-catalog.js
|
|
16303
16860
|
import { Buffer as Buffer2 } from "node:buffer";
|
|
@@ -16308,10 +16865,10 @@ function assertNonBlank(value, label) {
|
|
|
16308
16865
|
if (!value.trim())
|
|
16309
16866
|
throw new Error(`OpenCode ${label} must not be empty`);
|
|
16310
16867
|
}
|
|
16311
|
-
function encodeOpenCodeModelRef(
|
|
16312
|
-
assertNonBlank(
|
|
16313
|
-
assertNonBlank(
|
|
16314
|
-
const encoded = Buffer2.from(JSON.stringify([
|
|
16868
|
+
function encodeOpenCodeModelRef(model2) {
|
|
16869
|
+
assertNonBlank(model2.providerID, "Provider ID");
|
|
16870
|
+
assertNonBlank(model2.modelID, "Model ID");
|
|
16871
|
+
const encoded = Buffer2.from(JSON.stringify([model2.providerID, model2.modelID]), "utf8").toString("base64url");
|
|
16315
16872
|
const id = `${MODEL_REF_PREFIX}${encoded}`;
|
|
16316
16873
|
if (id.length > HARNESS_MODEL_REF_MAX_LENGTH) {
|
|
16317
16874
|
throw new Error("OpenCode Model identity is too long for a Model Ref");
|
|
@@ -16369,29 +16926,29 @@ function compareText(left, right) {
|
|
|
16369
16926
|
}
|
|
16370
16927
|
function modelsForConnectedProviders(catalog) {
|
|
16371
16928
|
const connected = new Set(catalog.connected);
|
|
16372
|
-
return catalog.all.flatMap((provider) => connected.has(provider.id) ? Object.values(provider.models).map((
|
|
16929
|
+
return catalog.all.flatMap((provider) => connected.has(provider.id) ? Object.values(provider.models).map((model2) => ({ provider, model: model2 })) : []);
|
|
16373
16930
|
}
|
|
16374
16931
|
function normalizeOpenCodeModelCatalog(catalog) {
|
|
16375
16932
|
const nativeModels = modelsForConnectedProviders(catalog);
|
|
16376
16933
|
const variants = /* @__PURE__ */ new Set();
|
|
16377
|
-
for (const { model } of nativeModels) {
|
|
16378
|
-
for (const variant of Object.keys(
|
|
16934
|
+
for (const { model: model2 } of nativeModels) {
|
|
16935
|
+
for (const variant of Object.keys(model2.variants ?? {}))
|
|
16379
16936
|
variants.add(variant);
|
|
16380
16937
|
}
|
|
16381
16938
|
const thinkingOptions = [
|
|
16382
16939
|
variantOption(void 0),
|
|
16383
16940
|
...[...variants].sort(compareText).map((variant) => variantOption(variant))
|
|
16384
16941
|
];
|
|
16385
|
-
const models = nativeModels.map(({ provider, model }) => ({
|
|
16386
|
-
ref: encodeOpenCodeModelRef({ providerID: provider.id, modelID:
|
|
16387
|
-
label: `${provider.name} / ${
|
|
16388
|
-
resolvedModelLabel: `${provider.id}/${
|
|
16942
|
+
const models = nativeModels.map(({ provider, model: model2 }) => ({
|
|
16943
|
+
ref: encodeOpenCodeModelRef({ providerID: provider.id, modelID: model2.id }),
|
|
16944
|
+
label: `${provider.name} / ${model2.name}`,
|
|
16945
|
+
resolvedModelLabel: `${provider.id}/${model2.id}`,
|
|
16389
16946
|
supportedThinkingOptionIds: [
|
|
16390
16947
|
DEFAULT_VARIANT_ID,
|
|
16391
|
-
...Object.keys(
|
|
16948
|
+
...Object.keys(model2.variants ?? {}).sort(compareText).map(encodeOpenCodeVariant)
|
|
16392
16949
|
]
|
|
16393
16950
|
})).sort((left, right) => compareText(left.label, right.label) || compareText(left.ref.id, right.ref.id));
|
|
16394
|
-
const defaultNative = catalog.connected.map((providerID) => ({ providerID, modelID: catalog.default[providerID] })).find((
|
|
16951
|
+
const defaultNative = catalog.connected.map((providerID) => ({ providerID, modelID: catalog.default[providerID] })).find((candidate2) => typeof candidate2.modelID === "string" && candidate2.modelID.length > 0);
|
|
16395
16952
|
const defaultModel = defaultNative ? encodeOpenCodeModelRef(defaultNative) : void 0;
|
|
16396
16953
|
return harnessModelCatalogSchema.parse({
|
|
16397
16954
|
models,
|
|
@@ -16400,9 +16957,9 @@ function normalizeOpenCodeModelCatalog(catalog) {
|
|
|
16400
16957
|
defaultThinkingOptionId: DEFAULT_VARIANT_ID
|
|
16401
16958
|
});
|
|
16402
16959
|
}
|
|
16403
|
-
function openCodeContextWindow(catalog,
|
|
16404
|
-
const provider = catalog.all.find(({ id }) => id ===
|
|
16405
|
-
const context = provider?.models[
|
|
16960
|
+
function openCodeContextWindow(catalog, model2) {
|
|
16961
|
+
const provider = catalog.all.find(({ id }) => id === model2.providerID);
|
|
16962
|
+
const context = provider?.models[model2.modelID]?.limit.context;
|
|
16406
16963
|
return typeof context === "number" && Number.isSafeInteger(context) && context > 0 ? context : void 0;
|
|
16407
16964
|
}
|
|
16408
16965
|
|
|
@@ -16725,7 +17282,7 @@ import { spawn, spawnSync } from "node:child_process";
|
|
|
16725
17282
|
import fs2 from "node:fs";
|
|
16726
17283
|
import { createServer } from "node:net";
|
|
16727
17284
|
import { homedir as homedir2, tmpdir as tmpdir2 } from "node:os";
|
|
16728
|
-
import
|
|
17285
|
+
import path7 from "node:path";
|
|
16729
17286
|
|
|
16730
17287
|
// ../../../node_modules/@opencode-ai/sdk/dist/v2/gen/core/serverSentEvents.gen.js
|
|
16731
17288
|
var createSseClient = ({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url: url2, ...options }) => {
|
|
@@ -16951,7 +17508,7 @@ var serializeObjectParam = ({ allowReserved, explode, name, style, value, valueO
|
|
|
16951
17508
|
|
|
16952
17509
|
// ../../../node_modules/@opencode-ai/sdk/dist/v2/gen/core/utils.gen.js
|
|
16953
17510
|
var PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
16954
|
-
var defaultPathSerializer = ({ path:
|
|
17511
|
+
var defaultPathSerializer = ({ path: path14, url: _url2 }) => {
|
|
16955
17512
|
let url2 = _url2;
|
|
16956
17513
|
const matches = _url2.match(PATH_PARAM_RE);
|
|
16957
17514
|
if (matches) {
|
|
@@ -16970,7 +17527,7 @@ var defaultPathSerializer = ({ path: path12, url: _url2 }) => {
|
|
|
16970
17527
|
name = name.substring(1);
|
|
16971
17528
|
style = "matrix";
|
|
16972
17529
|
}
|
|
16973
|
-
const value =
|
|
17530
|
+
const value = path14[name];
|
|
16974
17531
|
if (value === void 0 || value === null) {
|
|
16975
17532
|
continue;
|
|
16976
17533
|
}
|
|
@@ -17001,11 +17558,11 @@ var defaultPathSerializer = ({ path: path12, url: _url2 }) => {
|
|
|
17001
17558
|
}
|
|
17002
17559
|
return url2;
|
|
17003
17560
|
};
|
|
17004
|
-
var getUrl = ({ baseUrl, path:
|
|
17561
|
+
var getUrl = ({ baseUrl, path: path14, query, querySerializer, url: _url2 }) => {
|
|
17005
17562
|
const pathUrl = _url2.startsWith("/") ? _url2 : `/${_url2}`;
|
|
17006
17563
|
let url2 = (baseUrl ?? "") + pathUrl;
|
|
17007
|
-
if (
|
|
17008
|
-
url2 = defaultPathSerializer({ path:
|
|
17564
|
+
if (path14) {
|
|
17565
|
+
url2 = defaultPathSerializer({ path: path14, url: url2 });
|
|
17009
17566
|
}
|
|
17010
17567
|
let search = query ? querySerializer(query) : "";
|
|
17011
17568
|
if (search.startsWith("?")) {
|
|
@@ -22128,7 +22685,7 @@ function createOpencodeClient(config2) {
|
|
|
22128
22685
|
}
|
|
22129
22686
|
|
|
22130
22687
|
// dist/command.js
|
|
22131
|
-
import
|
|
22688
|
+
import path6 from "node:path";
|
|
22132
22689
|
var OpenCodeExecutableError = class extends Error {
|
|
22133
22690
|
code = "OPENCODE_NOT_FOUND";
|
|
22134
22691
|
constructor(message = "OpenCode CLI is not installed") {
|
|
@@ -22162,7 +22719,7 @@ function resolveOpenCodeExecutable(input = {}, dependencies = {}) {
|
|
|
22162
22719
|
}, dependencies);
|
|
22163
22720
|
if (!resolution)
|
|
22164
22721
|
throw new OpenCodeExecutableError();
|
|
22165
|
-
return targetPath(platform).isAbsolute(resolution.executable) ? resolution.executable :
|
|
22722
|
+
return targetPath(platform).isAbsolute(resolution.executable) ? resolution.executable : path6.resolve(resolution.executable);
|
|
22166
22723
|
}
|
|
22167
22724
|
function openCodeServerInvocation(executable, environment, platform = process.platform, port = 0) {
|
|
22168
22725
|
return commandInvocation(executable, ["serve", "--hostname=127.0.0.1", `--port=${port}`], environment, platform);
|
|
@@ -22190,14 +22747,14 @@ function freeLoopbackPort() {
|
|
|
22190
22747
|
});
|
|
22191
22748
|
});
|
|
22192
22749
|
}
|
|
22193
|
-
function
|
|
22750
|
+
function isRecord3(value) {
|
|
22194
22751
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22195
22752
|
}
|
|
22196
22753
|
function errorText(error51) {
|
|
22197
22754
|
return error51 instanceof Error ? error51.message : String(error51);
|
|
22198
22755
|
}
|
|
22199
22756
|
function isMissingExecutable(error51) {
|
|
22200
|
-
return
|
|
22757
|
+
return isRecord3(error51) && error51.code === "ENOENT";
|
|
22201
22758
|
}
|
|
22202
22759
|
function classifySdkError(error51, operation) {
|
|
22203
22760
|
if (error51 instanceof OpenCodeTransportError)
|
|
@@ -22252,20 +22809,20 @@ function signalProcessTree(child, signal) {
|
|
|
22252
22809
|
try {
|
|
22253
22810
|
process.kill(-child.pid, signal);
|
|
22254
22811
|
} catch (error51) {
|
|
22255
|
-
if (!
|
|
22812
|
+
if (!isRecord3(error51) || error51.code !== "ESRCH")
|
|
22256
22813
|
throw error51;
|
|
22257
22814
|
}
|
|
22258
22815
|
}
|
|
22259
22816
|
function safeOpenCodeServerCwd(environment) {
|
|
22260
22817
|
const candidates = [environment.USERPROFILE, environment.HOME, homedir2(), tmpdir2()];
|
|
22261
|
-
for (const
|
|
22262
|
-
if (!
|
|
22818
|
+
for (const candidate2 of candidates) {
|
|
22819
|
+
if (!candidate2 || !path7.isAbsolute(candidate2))
|
|
22263
22820
|
continue;
|
|
22264
22821
|
try {
|
|
22265
|
-
if (!fs2.statSync(
|
|
22822
|
+
if (!fs2.statSync(candidate2).isDirectory())
|
|
22266
22823
|
continue;
|
|
22267
|
-
fs2.accessSync(
|
|
22268
|
-
return
|
|
22824
|
+
fs2.accessSync(candidate2, fs2.constants.R_OK | fs2.constants.W_OK);
|
|
22825
|
+
return candidate2;
|
|
22269
22826
|
} catch {
|
|
22270
22827
|
}
|
|
22271
22828
|
}
|
|
@@ -22283,7 +22840,7 @@ function managedOpenCodeEnvironment(environment, executionPolicy = "default") {
|
|
|
22283
22840
|
if (existing !== void 0) {
|
|
22284
22841
|
try {
|
|
22285
22842
|
const parsed = JSON.parse(existing);
|
|
22286
|
-
if (!
|
|
22843
|
+
if (!isRecord3(parsed))
|
|
22287
22844
|
throw new Error("OpenCode config content must be an object");
|
|
22288
22845
|
config2 = { ...parsed };
|
|
22289
22846
|
} catch (error51) {
|
|
@@ -22606,11 +23163,11 @@ var SdkOpenCodeTransport = class {
|
|
|
22606
23163
|
parts: [{ type: "text", text: input.text }]
|
|
22607
23164
|
}), this.#commandTimeoutMs, "OpenCode prompt admission"), "prompt admission");
|
|
22608
23165
|
}
|
|
22609
|
-
async summarize(sessionID,
|
|
23166
|
+
async summarize(sessionID, model2) {
|
|
22610
23167
|
const client2 = await this.#getClient();
|
|
22611
23168
|
responseData2(await withTimeout2(client2.session.summarize({
|
|
22612
23169
|
sessionID,
|
|
22613
|
-
...
|
|
23170
|
+
...model2 ? { providerID: model2.providerID, modelID: model2.modelID } : {}
|
|
22614
23171
|
}), this.#commandTimeoutMs, "OpenCode context compaction"), "context compaction");
|
|
22615
23172
|
}
|
|
22616
23173
|
async abort(sessionID) {
|
|
@@ -22708,7 +23265,7 @@ var SdkOpenCodeTransport = class {
|
|
|
22708
23265
|
|
|
22709
23266
|
// dist/file-change-verification.js
|
|
22710
23267
|
import fs3 from "node:fs";
|
|
22711
|
-
import
|
|
23268
|
+
import path8 from "node:path";
|
|
22712
23269
|
function missingPath(error51) {
|
|
22713
23270
|
if (!error51 || typeof error51 !== "object")
|
|
22714
23271
|
return false;
|
|
@@ -22720,33 +23277,33 @@ function hasDotPathSegment(value) {
|
|
|
22720
23277
|
return segments.some((segment) => segment === "." || segment === "..");
|
|
22721
23278
|
}
|
|
22722
23279
|
function canonicalDirectoryPath(value) {
|
|
22723
|
-
let
|
|
23280
|
+
let candidate2 = path8.resolve(value);
|
|
22724
23281
|
const missingSegments = [];
|
|
22725
23282
|
for (; ; ) {
|
|
22726
23283
|
try {
|
|
22727
|
-
return
|
|
23284
|
+
return path8.join(fs3.realpathSync.native(candidate2), ...missingSegments);
|
|
22728
23285
|
} catch (error51) {
|
|
22729
23286
|
if (!missingPath(error51))
|
|
22730
23287
|
return void 0;
|
|
22731
|
-
const parent =
|
|
22732
|
-
if (parent ===
|
|
23288
|
+
const parent = path8.dirname(candidate2);
|
|
23289
|
+
if (parent === candidate2)
|
|
22733
23290
|
return void 0;
|
|
22734
|
-
missingSegments.unshift(
|
|
22735
|
-
|
|
23291
|
+
missingSegments.unshift(path8.basename(candidate2));
|
|
23292
|
+
candidate2 = parent;
|
|
22736
23293
|
}
|
|
22737
23294
|
}
|
|
22738
23295
|
}
|
|
22739
23296
|
function canonicalFilePath(value) {
|
|
22740
|
-
const absolute =
|
|
22741
|
-
const parent = canonicalDirectoryPath(
|
|
22742
|
-
return parent ?
|
|
23297
|
+
const absolute = path8.resolve(value);
|
|
23298
|
+
const parent = canonicalDirectoryPath(path8.dirname(absolute));
|
|
23299
|
+
return parent ? path8.join(parent, path8.basename(absolute)) : void 0;
|
|
22743
23300
|
}
|
|
22744
|
-
function pathIsWithin(root,
|
|
22745
|
-
const relative =
|
|
22746
|
-
return allowRoot && relative === "" || relative !== "" && relative !== ".." && !relative.startsWith(`..${
|
|
23301
|
+
function pathIsWithin(root, candidate2, allowRoot) {
|
|
23302
|
+
const relative = path8.relative(root, candidate2);
|
|
23303
|
+
return allowRoot && relative === "" || relative !== "" && relative !== ".." && !relative.startsWith(`..${path8.sep}`) && !path8.isAbsolute(relative);
|
|
22747
23304
|
}
|
|
22748
23305
|
function verifiedOpenCodeWorktree(sessionDirectory, paths) {
|
|
22749
|
-
if (!paths || typeof paths !== "object" || typeof sessionDirectory !== "string" || typeof paths.directory !== "string" || typeof paths.worktree !== "string" || hasDotPathSegment(sessionDirectory) || hasDotPathSegment(paths.directory) || hasDotPathSegment(paths.worktree) || !
|
|
23306
|
+
if (!paths || typeof paths !== "object" || typeof sessionDirectory !== "string" || typeof paths.directory !== "string" || typeof paths.worktree !== "string" || hasDotPathSegment(sessionDirectory) || hasDotPathSegment(paths.directory) || hasDotPathSegment(paths.worktree) || !path8.isAbsolute(sessionDirectory) || !path8.isAbsolute(paths.directory) || !path8.isAbsolute(paths.worktree)) {
|
|
22750
23307
|
return void 0;
|
|
22751
23308
|
}
|
|
22752
23309
|
const session = canonicalDirectoryPath(sessionDirectory);
|
|
@@ -22758,11 +23315,11 @@ function verifiedOpenCodeWorktree(sessionDirectory, paths) {
|
|
|
22758
23315
|
return worktree;
|
|
22759
23316
|
}
|
|
22760
23317
|
function openCodeFileIdentity(file2, worktree) {
|
|
22761
|
-
if (typeof file2 !== "string" || typeof worktree !== "string" || hasDotPathSegment(file2) || hasDotPathSegment(worktree) || !
|
|
23318
|
+
if (typeof file2 !== "string" || typeof worktree !== "string" || hasDotPathSegment(file2) || hasDotPathSegment(worktree) || !path8.isAbsolute(worktree) || !file2 || file2.includes("\0") || file2.includes("\n") || file2.includes("\r")) {
|
|
22762
23319
|
return void 0;
|
|
22763
23320
|
}
|
|
22764
|
-
const
|
|
22765
|
-
return
|
|
23321
|
+
const candidate2 = canonicalFilePath(path8.isAbsolute(file2) ? file2 : path8.resolve(worktree, file2));
|
|
23322
|
+
return candidate2 && pathIsWithin(worktree, candidate2, false) ? candidate2 : void 0;
|
|
22766
23323
|
}
|
|
22767
23324
|
|
|
22768
23325
|
// dist/usage.js
|
|
@@ -22818,12 +23375,12 @@ function storedSelection(session) {
|
|
|
22818
23375
|
}
|
|
22819
23376
|
return { providerID, modelID, ...typeof variant === "string" ? { variant } : {} };
|
|
22820
23377
|
}
|
|
22821
|
-
function selectionMetadata(session,
|
|
23378
|
+
function selectionMetadata(session, model2, variant) {
|
|
22822
23379
|
return {
|
|
22823
23380
|
...session.metadata,
|
|
22824
23381
|
[SELECTION_METADATA_KEY]: {
|
|
22825
|
-
providerID:
|
|
22826
|
-
modelID:
|
|
23382
|
+
providerID: model2.providerID,
|
|
23383
|
+
modelID: model2.modelID,
|
|
22827
23384
|
...variant ? { variant } : {}
|
|
22828
23385
|
}
|
|
22829
23386
|
};
|
|
@@ -22919,17 +23476,17 @@ async function readProjection(transport, sessionID, providerCatalog, toolOutputL
|
|
|
22919
23476
|
diffsByUserMessageId: new Map(diffEntries),
|
|
22920
23477
|
toolOutputLimit
|
|
22921
23478
|
});
|
|
22922
|
-
const
|
|
23479
|
+
const model2 = nativeModelFromSession(session, messages);
|
|
22923
23480
|
const nativeVariant = nativeVariantFromSession(session, messages);
|
|
22924
|
-
const nativeModel =
|
|
23481
|
+
const nativeModel = model2 ? providerCatalog.all.find(({ id }) => id === model2.providerID)?.models[model2.modelID] : void 0;
|
|
22925
23482
|
const variant = nativeVariant === "default" && nativeModel && !Object.hasOwn(nativeModel.variants ?? {}, "default") ? void 0 : nativeVariant;
|
|
22926
|
-
const usage = projectOpenCodeUsage(openCodeAssistantMessages(session, messages),
|
|
23483
|
+
const usage = projectOpenCodeUsage(openCodeAssistantMessages(session, messages), model2 ? openCodeContextWindow(providerCatalog, model2) : void 0);
|
|
22927
23484
|
return {
|
|
22928
23485
|
session,
|
|
22929
23486
|
messages,
|
|
22930
23487
|
snapshot,
|
|
22931
23488
|
usage,
|
|
22932
|
-
...
|
|
23489
|
+
...model2 ? { model: model2 } : {},
|
|
22933
23490
|
...variant ? { variant } : {}
|
|
22934
23491
|
};
|
|
22935
23492
|
}
|
|
@@ -22990,20 +23547,20 @@ async function deriveOpenCodeHistory(options) {
|
|
|
22990
23547
|
retainedCount = boundary.sourceTurnCount - 1;
|
|
22991
23548
|
}
|
|
22992
23549
|
const expectedHistory = structuredClone(semanticHistory(before.snapshot).slice(0, retainedCount));
|
|
22993
|
-
let
|
|
22994
|
-
if (
|
|
23550
|
+
let candidate2 = await transport.forkSession(source.id, messageID);
|
|
23551
|
+
if (candidate2.id === source.id) {
|
|
22995
23552
|
throw new OpenCodeTransportError("protocolError", "OpenCode Fork did not create a distinct Native Session");
|
|
22996
23553
|
}
|
|
22997
|
-
const candidateID =
|
|
22998
|
-
options.onCreated(
|
|
22999
|
-
if (
|
|
23554
|
+
const candidateID = candidate2.id;
|
|
23555
|
+
options.onCreated(candidate2);
|
|
23556
|
+
if (candidate2.directory !== expectedSource.directory) {
|
|
23000
23557
|
throw new OpenCodeTransportError("protocolError", "OpenCode Fork changed working directory");
|
|
23001
23558
|
}
|
|
23002
23559
|
if (expectedSource.model) {
|
|
23003
|
-
|
|
23560
|
+
candidate2 = await transport.updateSessionMetadata(candidateID, selectionMetadata(candidate2, expectedSource.model, expectedSource.variant));
|
|
23004
23561
|
}
|
|
23005
|
-
if (!isDeepStrictEqual(
|
|
23006
|
-
|
|
23562
|
+
if (!isDeepStrictEqual(candidate2.permission ?? [], expectedSource.permission ?? [])) {
|
|
23563
|
+
candidate2 = await transport.updateSessionPermission(candidateID, expectedSource.permission ?? []);
|
|
23007
23564
|
}
|
|
23008
23565
|
const [derived, after, candidateStatus, sourceStatus] = await Promise.all([
|
|
23009
23566
|
read(candidateID),
|
|
@@ -23011,7 +23568,7 @@ async function deriveOpenCodeHistory(options) {
|
|
|
23011
23568
|
transport.getStatus(candidateID),
|
|
23012
23569
|
transport.getStatus(source.id)
|
|
23013
23570
|
]);
|
|
23014
|
-
if (derived.session.id !== candidateID ||
|
|
23571
|
+
if (derived.session.id !== candidateID || candidate2.id !== candidateID || derived.session.directory !== before.session.directory || candidateStatus.type !== "idle" || sourceStatus.type !== "idle" || !isDeepStrictEqual(semanticHistory(derived.snapshot), expectedHistory) || !isDeepStrictEqual(sourceState(after), expectedSource) || !isDeepStrictEqual(derived.model, expectedSource.model) || derived.variant !== expectedSource.variant || !isDeepStrictEqual(derived.session.permission ?? [], expectedSource.permission ?? [])) {
|
|
23015
23572
|
throw new OpenCodeTransportError("protocolError", "OpenCode derived history, source or configuration changed during Fork");
|
|
23016
23573
|
}
|
|
23017
23574
|
return derived.session;
|
|
@@ -23055,13 +23612,13 @@ function sameCwd(left, right) {
|
|
|
23055
23612
|
try {
|
|
23056
23613
|
return fs4.realpathSync.native(value);
|
|
23057
23614
|
} catch {
|
|
23058
|
-
return
|
|
23615
|
+
return path9.resolve(value);
|
|
23059
23616
|
}
|
|
23060
23617
|
};
|
|
23061
23618
|
return canonical(left) === canonical(right);
|
|
23062
23619
|
}
|
|
23063
|
-
function sessionState(session, modelCatalog,
|
|
23064
|
-
const effectiveModel =
|
|
23620
|
+
function sessionState(session, modelCatalog, model2, variant, executionPolicy = "default", permissionModeId = OPENCODE_DEFAULT_PERMISSION_MODE_ID) {
|
|
23621
|
+
const effectiveModel = model2 ? encodeOpenCodeModelRef(model2) : void 0;
|
|
23065
23622
|
const modelEntry = effectiveModel ? modelCatalog.models.find(({ ref }) => ref.id === effectiveModel.id) : void 0;
|
|
23066
23623
|
const availableThinkingOptions = modelEntry?.supportedThinkingOptionIds?.map((id) => modelCatalog.thinkingOptions.find((option) => option.id === id)).filter((option) => Boolean(option));
|
|
23067
23624
|
const effectiveThinkingOptionId = encodeOpenCodeVariant(variant);
|
|
@@ -23468,8 +24025,8 @@ var OpenCodeHarnessSession = class {
|
|
|
23468
24025
|
};
|
|
23469
24026
|
}
|
|
23470
24027
|
const modelRef = this.#model ? encodeOpenCodeModelRef(this.#model) : void 0;
|
|
23471
|
-
const
|
|
23472
|
-
if (!
|
|
24028
|
+
const model2 = modelRef ? this.#modelCatalog.models.find(({ ref }) => ref.id === modelRef.id) : void 0;
|
|
24029
|
+
if (!model2?.supportedThinkingOptionIds?.includes(command.thinkingOptionId)) {
|
|
23473
24030
|
return {
|
|
23474
24031
|
ok: false,
|
|
23475
24032
|
error: {
|
|
@@ -24148,9 +24705,9 @@ var OpenCodeHarnessSession = class {
|
|
|
24148
24705
|
if (active.userMessageID)
|
|
24149
24706
|
return;
|
|
24150
24707
|
const candidates = messages.filter(({ info }) => info.role === "user" && !active.preexistingUserMessageIds.has(info.id));
|
|
24151
|
-
const [
|
|
24152
|
-
if (candidates.length === 1 &&
|
|
24153
|
-
this.#bindUserMessage(active,
|
|
24708
|
+
const [candidate2] = candidates;
|
|
24709
|
+
if (candidates.length === 1 && candidate2) {
|
|
24710
|
+
this.#bindUserMessage(active, candidate2.info.id);
|
|
24154
24711
|
return;
|
|
24155
24712
|
}
|
|
24156
24713
|
const parents = new Set(messages.filter(({ info }) => info.role === "assistant").map(({ info }) => info.parentID));
|
|
@@ -24319,14 +24876,14 @@ var OpenCodeAdapter = class {
|
|
|
24319
24876
|
const modelCatalog = normalizeOpenCodeModelCatalog(providers);
|
|
24320
24877
|
let session;
|
|
24321
24878
|
if (input.kind === "create") {
|
|
24322
|
-
const
|
|
24879
|
+
const model2 = input.model ? decodeOpenCodeModelRef(input.model) : void 0;
|
|
24323
24880
|
const variant = input.thinkingOptionId ? decodeOpenCodeVariant(input.thinkingOptionId) : void 0;
|
|
24324
24881
|
if (input.model && !modelCatalog.models.some(({ ref }) => ref.id === input.model?.id)) {
|
|
24325
24882
|
throw new OpenCodeTransportError("protocolError", "Requested OpenCode Model is absent from the connected Provider catalog");
|
|
24326
24883
|
}
|
|
24327
24884
|
const permission = requestedPermissionMode && requestedPermissionMode !== "default" ? requestedPermissionRules(void 0, requestedPermissionMode) : void 0;
|
|
24328
24885
|
session = await transport.createSession({
|
|
24329
|
-
...
|
|
24886
|
+
...model2 ? { model: model2 } : {},
|
|
24330
24887
|
...variant ? { variant } : {},
|
|
24331
24888
|
...permission ? { permission } : {}
|
|
24332
24889
|
});
|
|
@@ -24368,8 +24925,8 @@ var OpenCodeAdapter = class {
|
|
|
24368
24925
|
input,
|
|
24369
24926
|
providers,
|
|
24370
24927
|
toolOutputLimit: this.#toolOutputLimit,
|
|
24371
|
-
onCreated: (
|
|
24372
|
-
createdForCleanup =
|
|
24928
|
+
onCreated: (candidate2) => {
|
|
24929
|
+
createdForCleanup = candidate2;
|
|
24373
24930
|
}
|
|
24374
24931
|
});
|
|
24375
24932
|
}
|
|
@@ -24436,12 +24993,12 @@ async function detectOpenCode(options) {
|
|
|
24436
24993
|
}
|
|
24437
24994
|
|
|
24438
24995
|
// dist/v2/adapter.js
|
|
24439
|
-
import
|
|
24996
|
+
import fs7 from "node:fs";
|
|
24440
24997
|
import { isDeepStrictEqual as isDeepStrictEqual2 } from "node:util";
|
|
24441
24998
|
|
|
24442
24999
|
// dist/v2/state.js
|
|
24443
25000
|
import fs5 from "node:fs";
|
|
24444
|
-
import
|
|
25001
|
+
import path10 from "node:path";
|
|
24445
25002
|
var harnessId = harnessIdSchema.parse("opencode");
|
|
24446
25003
|
function failure(message, code = "nativeFailure") {
|
|
24447
25004
|
return {
|
|
@@ -24461,7 +25018,7 @@ function sameDirectory(left, right) {
|
|
|
24461
25018
|
try {
|
|
24462
25019
|
return fs5.realpathSync(value);
|
|
24463
25020
|
} catch {
|
|
24464
|
-
return
|
|
25021
|
+
return path10.resolve(value);
|
|
24465
25022
|
}
|
|
24466
25023
|
};
|
|
24467
25024
|
return canonical(left) === canonical(right);
|
|
@@ -24483,17 +25040,17 @@ function v2Locator(ref) {
|
|
|
24483
25040
|
return { directory: locator.directory, executionPolicy: locator.executionPolicy };
|
|
24484
25041
|
}
|
|
24485
25042
|
function v2Catalog(models, defaultModel) {
|
|
24486
|
-
const enabled = models.filter((
|
|
24487
|
-
const variants = [...new Set(enabled.flatMap((
|
|
24488
|
-
const ref = (
|
|
25043
|
+
const enabled = models.filter((model2) => model2.enabled);
|
|
25044
|
+
const variants = [...new Set(enabled.flatMap((model2) => model2.variants.map((v) => v.id)))].sort();
|
|
25045
|
+
const ref = (model2) => encodeOpenCodeModelRef({ providerID: model2.providerID, modelID: model2.id });
|
|
24489
25046
|
return harnessModelCatalogSchema.parse({
|
|
24490
|
-
models: enabled.map((
|
|
24491
|
-
ref: ref(
|
|
24492
|
-
label: `${
|
|
24493
|
-
resolvedModelLabel: `${
|
|
25047
|
+
models: enabled.map((model2) => ({
|
|
25048
|
+
ref: ref(model2),
|
|
25049
|
+
label: `${model2.providerID} / ${model2.name}`,
|
|
25050
|
+
resolvedModelLabel: `${model2.providerID}/${model2.id}`,
|
|
24494
25051
|
supportedThinkingOptionIds: [
|
|
24495
25052
|
encodeOpenCodeVariant(void 0),
|
|
24496
|
-
...
|
|
25053
|
+
...model2.variants.map((v) => encodeOpenCodeVariant(v.id))
|
|
24497
25054
|
]
|
|
24498
25055
|
})),
|
|
24499
25056
|
...defaultModel && enabled.some((m) => ref(m).id === ref(defaultModel).id) ? { defaultModel: ref(defaultModel) } : {},
|
|
@@ -24510,12 +25067,12 @@ function v2Permissions(current = [], mode) {
|
|
|
24510
25067
|
return selected === "default" ? rules : [...rules, { action: "*", resource: "*", effect: selected }];
|
|
24511
25068
|
}
|
|
24512
25069
|
function v2State(session, catalog, policy) {
|
|
24513
|
-
const
|
|
24514
|
-
const entry = catalog.models.find((
|
|
25070
|
+
const model2 = session.model ? encodeOpenCodeModelRef({ providerID: session.model.providerID, modelID: session.model.id }) : void 0;
|
|
25071
|
+
const entry = catalog.models.find((candidate2) => candidate2.ref.id === model2?.id);
|
|
24515
25072
|
const mode = session.permissions?.findLast((rule) => rule.action === "*" && rule.resource === "*");
|
|
24516
25073
|
return {
|
|
24517
25074
|
nativeRef: v2Ref(session, policy),
|
|
24518
|
-
...
|
|
25075
|
+
...model2 ? { effectiveModel: model2 } : {},
|
|
24519
25076
|
...entry ? {
|
|
24520
25077
|
resolvedModelLabel: entry.resolvedModelLabel ?? entry.label,
|
|
24521
25078
|
availableThinkingOptions: catalog.thinkingOptions.filter((v) => entry.supportedThinkingOptionIds?.includes(v.id)),
|
|
@@ -26376,7 +26933,7 @@ var V2Connection = class {
|
|
|
26376
26933
|
};
|
|
26377
26934
|
|
|
26378
26935
|
// dist/v2/history.js
|
|
26379
|
-
import
|
|
26936
|
+
import path11 from "node:path";
|
|
26380
26937
|
async function readMessages(client2, sessionID) {
|
|
26381
26938
|
const messages = [];
|
|
26382
26939
|
let cursor;
|
|
@@ -26395,11 +26952,12 @@ async function readMessages(client2, sessionID) {
|
|
|
26395
26952
|
} while (cursor);
|
|
26396
26953
|
return messages;
|
|
26397
26954
|
}
|
|
26398
|
-
var contentId = (messageID,
|
|
26955
|
+
var contentId = (messageID, type, ordinal) => hostItemIdSchema.parse(`${messageID}:${type}:${ordinal}`);
|
|
26399
26956
|
function assistantItems2(message, limit) {
|
|
26400
|
-
|
|
26401
|
-
|
|
26957
|
+
const ordinals = { text: 0, reasoning: 0 };
|
|
26958
|
+
return message.content.map((part) => {
|
|
26402
26959
|
if (part.type === "text" || part.type === "reasoning") {
|
|
26960
|
+
const itemId2 = contentId(message.id, part.type, ordinals[part.type]++);
|
|
26403
26961
|
return {
|
|
26404
26962
|
item: {
|
|
26405
26963
|
type: part.type === "text" ? "agentMessage" : "reasoning",
|
|
@@ -26414,7 +26972,7 @@ function assistantItems2(message, limit) {
|
|
|
26414
26972
|
return {
|
|
26415
26973
|
item: {
|
|
26416
26974
|
type: "toolExecution",
|
|
26417
|
-
itemId:
|
|
26975
|
+
itemId: hostItemIdSchema.parse(`${message.id}:tool:${part.id}`),
|
|
26418
26976
|
toolName: part.name,
|
|
26419
26977
|
namespace: "opencode",
|
|
26420
26978
|
arguments: typeof state.input === "string" ? state.input : state.input,
|
|
@@ -26501,9 +27059,9 @@ function fileChanges(session, turn, diffs) {
|
|
|
26501
27059
|
if (!diffs.length)
|
|
26502
27060
|
return void 0;
|
|
26503
27061
|
const changes = diffs.map((diff) => {
|
|
26504
|
-
const absolute =
|
|
26505
|
-
const relative =
|
|
26506
|
-
if (relative.startsWith(`..${
|
|
27062
|
+
const absolute = path11.resolve(session.location.directory, diff.file);
|
|
27063
|
+
const relative = path11.relative(session.location.directory, absolute);
|
|
27064
|
+
if (relative.startsWith(`..${path11.sep}`) || relative === ".." || path11.isAbsolute(relative))
|
|
26507
27065
|
throw new Error("OpenCode v2 diff escaped the Session directory");
|
|
26508
27066
|
return {
|
|
26509
27067
|
path: absolute,
|
|
@@ -26544,6 +27102,110 @@ function terminalItemOutcome(outcome) {
|
|
|
26544
27102
|
return outcome.status === "unknown" ? { status: "failed", error: failure(outcome.reason, "protocolError") } : outcome;
|
|
26545
27103
|
}
|
|
26546
27104
|
|
|
27105
|
+
// dist/v2/session-import.js
|
|
27106
|
+
import fs6 from "node:fs";
|
|
27107
|
+
import path12 from "node:path";
|
|
27108
|
+
|
|
27109
|
+
// ../../harness-adapter/dist/session-import.js
|
|
27110
|
+
function sessionImportTitle(value, maxLength = HARNESS_SESSION_IMPORT_TITLE_MAX_LENGTH) {
|
|
27111
|
+
if (typeof value !== "string")
|
|
27112
|
+
return null;
|
|
27113
|
+
const normalized = value.replaceAll("\0", "").replaceAll(/\s+/gu, " ").trim();
|
|
27114
|
+
if (!normalized)
|
|
27115
|
+
return null;
|
|
27116
|
+
if (normalized.length <= maxLength)
|
|
27117
|
+
return normalized;
|
|
27118
|
+
const characters = [...normalized];
|
|
27119
|
+
if (characters.length <= maxLength)
|
|
27120
|
+
return normalized;
|
|
27121
|
+
return `${characters.slice(0, maxLength - 1).join("").trimEnd()}…`;
|
|
27122
|
+
}
|
|
27123
|
+
function sessionImportCandidate(input) {
|
|
27124
|
+
const time3 = typeof input.updatedAt === "number" ? input.updatedAt : typeof input.updatedAt === "string" ? Date.parse(input.updatedAt) : Number.NaN;
|
|
27125
|
+
const parsed = harnessSessionImportCandidateSchema.safeParse({
|
|
27126
|
+
nativeSessionId: input.nativeSessionId,
|
|
27127
|
+
cwd: input.cwd,
|
|
27128
|
+
title: typeof input.title === "string" && input.title.trim().length > 0 ? input.title : null,
|
|
27129
|
+
updatedAt: Math.floor(time3),
|
|
27130
|
+
// Unknown must stay unknown; only an explicit boolean is a native statement.
|
|
27131
|
+
running: typeof input.running === "boolean" ? input.running : null
|
|
27132
|
+
});
|
|
27133
|
+
return parsed.success ? parsed.data : null;
|
|
27134
|
+
}
|
|
27135
|
+
|
|
27136
|
+
// dist/v2/session-import.js
|
|
27137
|
+
var PAGE_SIZE = 200;
|
|
27138
|
+
var MAX_PAGES = 1e4;
|
|
27139
|
+
function existingDirectory(directory) {
|
|
27140
|
+
if (typeof directory !== "string" || !path12.isAbsolute(directory))
|
|
27141
|
+
return null;
|
|
27142
|
+
try {
|
|
27143
|
+
return fs6.statSync(directory).isDirectory() ? directory : null;
|
|
27144
|
+
} catch {
|
|
27145
|
+
return null;
|
|
27146
|
+
}
|
|
27147
|
+
}
|
|
27148
|
+
function candidate(info, active) {
|
|
27149
|
+
if (info.parentID || info.time.archived !== void 0)
|
|
27150
|
+
return null;
|
|
27151
|
+
const cwd = existingDirectory(info.location.directory);
|
|
27152
|
+
if (!cwd)
|
|
27153
|
+
return null;
|
|
27154
|
+
return sessionImportCandidate({
|
|
27155
|
+
nativeSessionId: info.id,
|
|
27156
|
+
cwd,
|
|
27157
|
+
title: sessionImportTitle(info.title),
|
|
27158
|
+
updatedAt: info.time.updated,
|
|
27159
|
+
// This server only knows its own executions; another process may still hold the Session.
|
|
27160
|
+
running: active[info.id] ? true : null
|
|
27161
|
+
});
|
|
27162
|
+
}
|
|
27163
|
+
async function listV2SessionCandidates(client2) {
|
|
27164
|
+
const active = await client2.session.active();
|
|
27165
|
+
const candidates = /* @__PURE__ */ new Map();
|
|
27166
|
+
const cursors = /* @__PURE__ */ new Set();
|
|
27167
|
+
let cursor;
|
|
27168
|
+
for (let page = 0; page < MAX_PAGES; page += 1) {
|
|
27169
|
+
const response = await client2.session.list({
|
|
27170
|
+
limit: PAGE_SIZE,
|
|
27171
|
+
...cursor ? { cursor } : {}
|
|
27172
|
+
});
|
|
27173
|
+
for (const info of response.data) {
|
|
27174
|
+
const entry = candidate(info, active);
|
|
27175
|
+
if (entry)
|
|
27176
|
+
candidates.set(entry.nativeSessionId, entry);
|
|
27177
|
+
}
|
|
27178
|
+
const next = response.cursor.next;
|
|
27179
|
+
if (!next || cursors.has(next))
|
|
27180
|
+
break;
|
|
27181
|
+
cursors.add(next);
|
|
27182
|
+
cursor = next;
|
|
27183
|
+
}
|
|
27184
|
+
return [...candidates.values()];
|
|
27185
|
+
}
|
|
27186
|
+
async function resolveV2SessionCandidate(client2, nativeSessionId) {
|
|
27187
|
+
const active = await client2.session.active();
|
|
27188
|
+
const cursors = /* @__PURE__ */ new Set();
|
|
27189
|
+
let cursor;
|
|
27190
|
+
for (let page = 0; page < MAX_PAGES; page += 1) {
|
|
27191
|
+
const response = await client2.session.list({
|
|
27192
|
+
limit: PAGE_SIZE,
|
|
27193
|
+
...cursor ? { cursor } : {}
|
|
27194
|
+
});
|
|
27195
|
+
const info = response.data.find((entry) => entry.id === nativeSessionId);
|
|
27196
|
+
if (info) {
|
|
27197
|
+
const entry = candidate(info, active);
|
|
27198
|
+
return entry ? { candidate: entry, nativeRef: v2Ref(info, "default") } : null;
|
|
27199
|
+
}
|
|
27200
|
+
const next = response.cursor.next;
|
|
27201
|
+
if (!next || cursors.has(next))
|
|
27202
|
+
break;
|
|
27203
|
+
cursors.add(next);
|
|
27204
|
+
cursor = next;
|
|
27205
|
+
}
|
|
27206
|
+
return null;
|
|
27207
|
+
}
|
|
27208
|
+
|
|
26547
27209
|
// dist/v2/interactions.js
|
|
26548
27210
|
function permissionInteraction(request, turnId) {
|
|
26549
27211
|
return {
|
|
@@ -26675,6 +27337,14 @@ function v2Capabilities(catalog) {
|
|
|
26675
27337
|
history: { fork: true, forkAcrossCwd: false, rollbackLastTurn: true }
|
|
26676
27338
|
};
|
|
26677
27339
|
}
|
|
27340
|
+
var FIRST_OUTPUT_EVENTS = /* @__PURE__ */ new Set([
|
|
27341
|
+
"session.reasoning.started",
|
|
27342
|
+
"session.reasoning.delta",
|
|
27343
|
+
"session.text.started",
|
|
27344
|
+
"session.text.delta",
|
|
27345
|
+
"session.tool.input.started",
|
|
27346
|
+
"session.tool.input.delta"
|
|
27347
|
+
]);
|
|
26678
27348
|
var V2Session = class {
|
|
26679
27349
|
client;
|
|
26680
27350
|
connection;
|
|
@@ -26698,6 +27368,11 @@ var V2Session = class {
|
|
|
26698
27368
|
#reconciling;
|
|
26699
27369
|
#timer;
|
|
26700
27370
|
#configuring = false;
|
|
27371
|
+
#cacheHitRatePercent;
|
|
27372
|
+
/** Assistant messages already published as usage requests. */
|
|
27373
|
+
#meteredMessages = /* @__PURE__ */ new Set();
|
|
27374
|
+
/** Adapter receive time of each assistant message's first reasoning, text or tool input. */
|
|
27375
|
+
#firstOutputAt = /* @__PURE__ */ new Map();
|
|
26701
27376
|
constructor(client2, connection, info, catalog, policy, limit, onClosed) {
|
|
26702
27377
|
this.client = client2;
|
|
26703
27378
|
this.connection = connection;
|
|
@@ -26742,6 +27417,7 @@ var V2Session = class {
|
|
|
26742
27417
|
}
|
|
26743
27418
|
})();
|
|
26744
27419
|
});
|
|
27420
|
+
await this.#replayUsage();
|
|
26745
27421
|
this.#timer = setInterval(() => {
|
|
26746
27422
|
void this.#refresh();
|
|
26747
27423
|
}, 400);
|
|
@@ -26810,22 +27486,22 @@ var V2Session = class {
|
|
|
26810
27486
|
permissions: v2Permissions(this.info.permissions, command.permissionModeId)
|
|
26811
27487
|
});
|
|
26812
27488
|
} else {
|
|
26813
|
-
let
|
|
27489
|
+
let model2 = this.info.model;
|
|
26814
27490
|
if (command.type === "model.select") {
|
|
26815
27491
|
if (!this.catalog.models.some((m) => m.ref.id === command.model.id))
|
|
26816
27492
|
throw new Error("OpenCode Model is not available");
|
|
26817
27493
|
const decoded = decodeOpenCodeModelRef(command.model);
|
|
26818
|
-
|
|
27494
|
+
model2 = { providerID: decoded.providerID, id: decoded.modelID };
|
|
26819
27495
|
} else {
|
|
26820
|
-
if (!
|
|
27496
|
+
if (!model2)
|
|
26821
27497
|
throw new Error("Select a Model before a Thinking option");
|
|
26822
27498
|
const state = v2State(this.info, this.catalog, this.policy);
|
|
26823
27499
|
if (!state.availableThinkingOptions?.some((v) => v.id === command.thinkingOptionId))
|
|
26824
27500
|
throw new Error("Thinking option is unavailable for this Model");
|
|
26825
27501
|
const variant = decodeOpenCodeVariant(command.thinkingOptionId);
|
|
26826
|
-
|
|
27502
|
+
model2 = { providerID: model2.providerID, id: model2.id, ...variant ? { variant } : {} };
|
|
26827
27503
|
}
|
|
26828
|
-
await this.client.session.switchModel({ sessionID: this.info.id, model });
|
|
27504
|
+
await this.client.session.switchModel({ sessionID: this.info.id, model: model2 });
|
|
26829
27505
|
}
|
|
26830
27506
|
this.info = await this.client.session.get({ sessionID: this.info.id });
|
|
26831
27507
|
this.#emit({
|
|
@@ -26909,11 +27585,14 @@ var V2Session = class {
|
|
|
26909
27585
|
const active = this.#active;
|
|
26910
27586
|
if (!active || !("data" in event) || !("sessionID" in event.data) || event.data.sessionID !== this.info.id)
|
|
26911
27587
|
return;
|
|
27588
|
+
if (FIRST_OUTPUT_EVENTS.has(event.type) && "assistantMessageID" in event.data && typeof event.data.assistantMessageID === "string" && !this.#firstOutputAt.has(event.data.assistantMessageID))
|
|
27589
|
+
this.#firstOutputAt.set(event.data.assistantMessageID, Date.now());
|
|
26912
27590
|
if (event.type === "session.step.started")
|
|
26913
27591
|
active.assistants.add(event.data.assistantMessageID);
|
|
26914
27592
|
if ((event.type === "session.text.delta" || event.type === "session.reasoning.delta") && active.assistants.has(event.data.assistantMessageID)) {
|
|
26915
|
-
const
|
|
26916
|
-
const
|
|
27593
|
+
const contentType = event.type === "session.text.delta" ? "text" : "reasoning";
|
|
27594
|
+
const itemId2 = contentId(event.data.assistantMessageID, contentType, event.data.ordinal);
|
|
27595
|
+
const type = contentType === "text" ? "agentMessage" : "reasoning";
|
|
26917
27596
|
const previous = active.transient.get(itemId2);
|
|
26918
27597
|
const item = {
|
|
26919
27598
|
type,
|
|
@@ -26927,6 +27606,56 @@ var V2Session = class {
|
|
|
26927
27606
|
if (!event.type.endsWith(".delta"))
|
|
26928
27607
|
void this.#refresh();
|
|
26929
27608
|
}
|
|
27609
|
+
/** Publishes assistant messages not yet metered; returns false when one is unusable. */
|
|
27610
|
+
#meterUsage(messages, historical) {
|
|
27611
|
+
let usable = true;
|
|
27612
|
+
const previousCacheHitRate = this.#cacheHitRatePercent;
|
|
27613
|
+
for (const message of messages) {
|
|
27614
|
+
let request;
|
|
27615
|
+
try {
|
|
27616
|
+
request = v2UsageRequest(message, historical, this.#firstOutputAt.get(message.id));
|
|
27617
|
+
} catch {
|
|
27618
|
+
this.#cacheHitRatePercent = void 0;
|
|
27619
|
+
if (this.#meteredMessages.has(message.id))
|
|
27620
|
+
continue;
|
|
27621
|
+
this.#meteredMessages.add(message.id);
|
|
27622
|
+
if (!historical)
|
|
27623
|
+
this.#emit({ type: "usage.history", complete: false });
|
|
27624
|
+
usable = false;
|
|
27625
|
+
continue;
|
|
27626
|
+
}
|
|
27627
|
+
if (!request)
|
|
27628
|
+
continue;
|
|
27629
|
+
this.#cacheHitRatePercent = request.inputTokens > 0 && request.cachedInputTokens !== void 0 ? request.cachedInputTokens / request.inputTokens * 100 : void 0;
|
|
27630
|
+
if (this.#meteredMessages.has(message.id))
|
|
27631
|
+
continue;
|
|
27632
|
+
this.#meteredMessages.add(message.id);
|
|
27633
|
+
this.#firstOutputAt.delete(message.id);
|
|
27634
|
+
this.#emit({ type: "usage.request", request });
|
|
27635
|
+
}
|
|
27636
|
+
if (this.#cacheHitRatePercent !== previousCacheHitRate)
|
|
27637
|
+
this.#emit({
|
|
27638
|
+
type: "session.usage.changed",
|
|
27639
|
+
usage: this.#usage()
|
|
27640
|
+
});
|
|
27641
|
+
return usable;
|
|
27642
|
+
}
|
|
27643
|
+
#usage() {
|
|
27644
|
+
const usage = v2Usage(this.info);
|
|
27645
|
+
if (this.#cacheHitRatePercent !== void 0)
|
|
27646
|
+
usage.cacheHitRatePercent = this.#cacheHitRatePercent;
|
|
27647
|
+
return usage;
|
|
27648
|
+
}
|
|
27649
|
+
/** Replays every metered request of the native history, then declares it complete. */
|
|
27650
|
+
async #replayUsage() {
|
|
27651
|
+
let complete = false;
|
|
27652
|
+
try {
|
|
27653
|
+
complete = this.#meterUsage(await readMessages(this.client, this.info.id), true);
|
|
27654
|
+
} catch {
|
|
27655
|
+
complete = false;
|
|
27656
|
+
}
|
|
27657
|
+
this.#emit({ type: "usage.history", complete });
|
|
27658
|
+
}
|
|
26930
27659
|
#refresh() {
|
|
26931
27660
|
if (this.#closed || !this.#active?.admitted)
|
|
26932
27661
|
return Promise.resolve();
|
|
@@ -26945,6 +27674,7 @@ var V2Session = class {
|
|
|
26945
27674
|
if (this.#active !== active || this.#closed)
|
|
26946
27675
|
return;
|
|
26947
27676
|
this.info = info;
|
|
27677
|
+
this.#meterUsage(messages, false);
|
|
26948
27678
|
const turns = snapshot.turns.filter((t) => !active.baseline.has(t.nativeTurnRef.nativeTurnKey));
|
|
26949
27679
|
if (turns.length > 1)
|
|
26950
27680
|
throw new Error("Concurrent native prompts cannot be assigned to one Host Turn");
|
|
@@ -27041,7 +27771,7 @@ var V2Session = class {
|
|
|
27041
27771
|
});
|
|
27042
27772
|
this.#emit({
|
|
27043
27773
|
type: "session.usage.changed",
|
|
27044
|
-
usage:
|
|
27774
|
+
usage: this.#usage(),
|
|
27045
27775
|
observedForTurnId: active.turnId
|
|
27046
27776
|
});
|
|
27047
27777
|
this.#active = void 0;
|
|
@@ -27175,9 +27905,42 @@ var V2Adapter = class {
|
|
|
27175
27905
|
this.#connections.delete(connection);
|
|
27176
27906
|
}
|
|
27177
27907
|
}
|
|
27908
|
+
sessionImport = {
|
|
27909
|
+
listCandidates: () => this.#discover((client2) => listV2SessionCandidates(client2)),
|
|
27910
|
+
resolveCandidate: async (nativeSessionId) => {
|
|
27911
|
+
const source = await this.#discover((client2) => resolveV2SessionCandidate(client2, nativeSessionId));
|
|
27912
|
+
if (!source.ok)
|
|
27913
|
+
return source;
|
|
27914
|
+
return source.value ? { ok: true, value: source.value } : {
|
|
27915
|
+
ok: false,
|
|
27916
|
+
error: failure("OpenCode Session is no longer importable", "sessionNotFound")
|
|
27917
|
+
};
|
|
27918
|
+
}
|
|
27919
|
+
};
|
|
27920
|
+
/** Read-only discovery on a private server: no Session is created, loaded or prompted. */
|
|
27921
|
+
async #discover(read) {
|
|
27922
|
+
if (this.#closed)
|
|
27923
|
+
return { ok: false, error: failure("OpenCode Adapter is closed", "invalidState") };
|
|
27924
|
+
const connection = new V2Connection(this.options, process.cwd());
|
|
27925
|
+
this.#connections.add(connection);
|
|
27926
|
+
try {
|
|
27927
|
+
const value = await read(await connection.client());
|
|
27928
|
+
if (this.#closed)
|
|
27929
|
+
throw new Error("OpenCode Adapter closed during Session discovery");
|
|
27930
|
+
return { ok: true, value };
|
|
27931
|
+
} catch {
|
|
27932
|
+
return {
|
|
27933
|
+
ok: false,
|
|
27934
|
+
error: this.#closed ? failure("OpenCode Adapter is closed", "invalidState") : failure("OpenCode sessions could not be read; check the installation and retry", "unavailable")
|
|
27935
|
+
};
|
|
27936
|
+
} finally {
|
|
27937
|
+
await connection.close();
|
|
27938
|
+
this.#connections.delete(connection);
|
|
27939
|
+
}
|
|
27940
|
+
}
|
|
27178
27941
|
async open(input) {
|
|
27179
27942
|
try {
|
|
27180
|
-
input = { ...input, cwd:
|
|
27943
|
+
input = { ...input, cwd: fs7.realpathSync(input.cwd) };
|
|
27181
27944
|
} catch (error51) {
|
|
27182
27945
|
return errorResult(error51);
|
|
27183
27946
|
}
|
|
@@ -27204,10 +27967,10 @@ var V2Adapter = class {
|
|
|
27204
27967
|
const catalog = await this.#catalog(client2, input.cwd);
|
|
27205
27968
|
let info;
|
|
27206
27969
|
if (input.kind === "create") {
|
|
27207
|
-
const
|
|
27970
|
+
const model2 = selectedModel(input, catalog);
|
|
27208
27971
|
info = await client2.session.create({
|
|
27209
27972
|
location: { directory: input.cwd },
|
|
27210
|
-
...
|
|
27973
|
+
...model2 ? { model: model2 } : {},
|
|
27211
27974
|
permissions: v2Permissions([], input.permissionModeId ?? harnessPermissionModeIdSchema.parse(policy === "unattended-full-access" ? "allow" : "default"))
|
|
27212
27975
|
});
|
|
27213
27976
|
created = info.id;
|
|
@@ -27224,19 +27987,19 @@ var V2Adapter = class {
|
|
|
27224
27987
|
if (input.kind !== "resume") {
|
|
27225
27988
|
const parent = info;
|
|
27226
27989
|
const turns = source.snapshot.turns;
|
|
27227
|
-
let
|
|
27990
|
+
let count2;
|
|
27228
27991
|
if (input.kind === "rollbackLastTurn") {
|
|
27229
27992
|
if (!turns.length)
|
|
27230
27993
|
throw new Error("OpenCode history is empty");
|
|
27231
|
-
|
|
27994
|
+
count2 = turns.length - 1;
|
|
27232
27995
|
} else {
|
|
27233
27996
|
if (input.checkpoint.harnessId !== harnessId || input.checkpoint.nativeSessionId !== info.id)
|
|
27234
27997
|
throw new Error("Checkpoint belongs to another Session");
|
|
27235
|
-
|
|
27236
|
-
if (!
|
|
27998
|
+
count2 = turns.findIndex((turn) => turn.checkpoint?.checkpointId === input.checkpoint.checkpointId) + 1;
|
|
27999
|
+
if (!count2 || JSON.stringify(turns[count2 - 1]?.checkpoint) !== JSON.stringify(input.checkpoint))
|
|
27237
28000
|
throw new Error("OpenCode checkpoint does not match native history");
|
|
27238
28001
|
}
|
|
27239
|
-
const before = turns[
|
|
28002
|
+
const before = turns[count2]?.nativeTurnRef.nativeTurnKey;
|
|
27240
28003
|
info = await client2.session.fork({ sessionID: parent.id, ...before ? { before } : {} });
|
|
27241
28004
|
if (info.id === parent.id)
|
|
27242
28005
|
throw new Error("OpenCode fork returned its source Session");
|
|
@@ -27251,7 +28014,7 @@ var V2Adapter = class {
|
|
|
27251
28014
|
await client2.session.switchModel({ sessionID: info.id, model: parent.model });
|
|
27252
28015
|
info = await client2.session.get({ sessionID: info.id });
|
|
27253
28016
|
const derived = await readHistory(client2, info, this.options.toolOutputLimit ?? 64e3);
|
|
27254
|
-
if (historyContent(derived.snapshot, false) !== historyContent({ turns: turns.slice(0,
|
|
28017
|
+
if (historyContent(derived.snapshot, false) !== historyContent({ turns: turns.slice(0, count2) }, false))
|
|
27255
28018
|
throw new Error("OpenCode fork did not preserve the exact history prefix");
|
|
27256
28019
|
if (!isDeepStrictEqual2(info.permissions ?? [], parent.permissions ?? []) || !isDeepStrictEqual2(info.model, parent.model))
|
|
27257
28020
|
throw new Error("OpenCode fork did not preserve the current configuration");
|
|
@@ -27300,14 +28063,14 @@ function selectedModel(input, catalog) {
|
|
|
27300
28063
|
throw new Error("Thinking selection requires a Model");
|
|
27301
28064
|
return void 0;
|
|
27302
28065
|
}
|
|
27303
|
-
const entry = catalog.models.find((
|
|
28066
|
+
const entry = catalog.models.find((model3) => model3.ref.id === selected.id);
|
|
27304
28067
|
if (!entry)
|
|
27305
28068
|
throw new Error("OpenCode Model is not available");
|
|
27306
28069
|
if (input.thinkingOptionId && !entry.supportedThinkingOptionIds?.includes(input.thinkingOptionId))
|
|
27307
28070
|
throw new Error("OpenCode Thinking option is not available for this Model");
|
|
27308
|
-
const
|
|
28071
|
+
const model2 = decodeOpenCodeModelRef(selected);
|
|
27309
28072
|
const variant = input.thinkingOptionId ? decodeOpenCodeVariant(input.thinkingOptionId) : void 0;
|
|
27310
|
-
return { providerID:
|
|
28073
|
+
return { providerID: model2.providerID, id: model2.modelID, ...variant ? { variant } : {} };
|
|
27311
28074
|
}
|
|
27312
28075
|
function historyContent(snapshot, identities = true) {
|
|
27313
28076
|
return JSON.stringify(snapshot.turns.map((turn) => ({
|
|
@@ -27331,9 +28094,11 @@ var OpenCodeAdapter2 = class {
|
|
|
27331
28094
|
commandCatalog = openCodeCommandCatalog;
|
|
27332
28095
|
#adapters = /* @__PURE__ */ new Set();
|
|
27333
28096
|
#closed = false;
|
|
28097
|
+
usageStatistics;
|
|
27334
28098
|
constructor(options = {}, dependencies) {
|
|
27335
28099
|
this.options = options;
|
|
27336
28100
|
this.dependencies = dependencies;
|
|
28101
|
+
this.usageStatistics = createOpenCodeUsageStatistics(options.environment ?? process.env);
|
|
27337
28102
|
}
|
|
27338
28103
|
async #select(environment, input) {
|
|
27339
28104
|
if (this.#closed)
|
|
@@ -27357,6 +28122,36 @@ var OpenCodeAdapter2 = class {
|
|
|
27357
28122
|
this.#adapters.add(adapter);
|
|
27358
28123
|
return adapter;
|
|
27359
28124
|
}
|
|
28125
|
+
sessionImport = {
|
|
28126
|
+
listCandidates: () => this.#discover((imports) => imports.listCandidates()),
|
|
28127
|
+
resolveCandidate: (nativeSessionId) => this.#discover((imports) => imports.resolveCandidate(nativeSessionId))
|
|
28128
|
+
};
|
|
28129
|
+
/** Session import follows the selected CLI's protocol, like every other operation. */
|
|
28130
|
+
async #discover(read) {
|
|
28131
|
+
if (this.#closed)
|
|
28132
|
+
return { ok: false, error: failure("OpenCode Adapter is closed", "invalidState") };
|
|
28133
|
+
let adapter;
|
|
28134
|
+
try {
|
|
28135
|
+
adapter = await this.#select();
|
|
28136
|
+
if (!(adapter instanceof V2Adapter))
|
|
28137
|
+
return {
|
|
28138
|
+
ok: false,
|
|
28139
|
+
// v1 answers per project only; there is no native listing across projects to import from.
|
|
28140
|
+
error: failure("OpenCode Session import requires OpenCode v2", "unsupported")
|
|
28141
|
+
};
|
|
28142
|
+
return await read(adapter.sessionImport);
|
|
28143
|
+
} catch (error51) {
|
|
28144
|
+
return {
|
|
28145
|
+
ok: false,
|
|
28146
|
+
error: this.#closed ? failure("OpenCode Adapter is closed", "invalidState") : normalize(error51)
|
|
28147
|
+
};
|
|
28148
|
+
} finally {
|
|
28149
|
+
if (adapter) {
|
|
28150
|
+
await adapter.close();
|
|
28151
|
+
this.#adapters.delete(adapter);
|
|
28152
|
+
}
|
|
28153
|
+
}
|
|
28154
|
+
}
|
|
27360
28155
|
async inspect(input = {}) {
|
|
27361
28156
|
let adapter;
|
|
27362
28157
|
try {
|
|
@@ -27413,7 +28208,7 @@ function normalize(error51) {
|
|
|
27413
28208
|
// dist/installation.js
|
|
27414
28209
|
import { realpath as realpath2 } from "node:fs/promises";
|
|
27415
28210
|
import { homedir as homedir3 } from "node:os";
|
|
27416
|
-
import
|
|
28211
|
+
import path13 from "node:path";
|
|
27417
28212
|
function createOpenCodeInstallation(environment, command) {
|
|
27418
28213
|
let update;
|
|
27419
28214
|
return createInstallationManager({
|
|
@@ -27434,8 +28229,8 @@ function createOpenCodeInstallation(environment, command) {
|
|
|
27434
28229
|
const release = JSON.parse(await fetchInstallationText("https://api.github.com/repos/anomalyco/opencode/releases/latest"));
|
|
27435
28230
|
latestVersion = installationVersion(release.tag_name);
|
|
27436
28231
|
const home = environment.HOME ?? environment.USERPROFILE ?? homedir3();
|
|
27437
|
-
const standard =
|
|
27438
|
-
canUpdate = process.platform !== "win32" &&
|
|
28232
|
+
const standard = path13.join(home, ".opencode", "bin", process.platform === "win32" ? "opencode.exe" : "opencode");
|
|
28233
|
+
canUpdate = process.platform !== "win32" && path13.resolve(executable) === standard && await realpath2(executable) === standard;
|
|
27439
28234
|
update = async (version2) => {
|
|
27440
28235
|
await runInstallationCommand(executable, ["upgrade", version2, "--method", "curl"], environment, 3e5);
|
|
27441
28236
|
};
|