@liberseek/boft-cli-linux-x64 0.7.9 → 0.8.1
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 +9 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/console-server.mjs +322 -67
- package/app/console-web.js +9202 -5218
- package/app/desktop-controller.mjs +259 -42
- package/app/host-runtime.mjs +6250 -1689
- package/app/plugins/antigravity/manifest.json +18 -1
- package/app/plugins/antigravity/plugin.mjs +283 -42
- package/app/plugins/claude-code/manifest.json +28 -0
- package/app/plugins/claude-code/plugin.mjs +35676 -24151
- package/app/plugins/codebuddy/manifest.json +17 -0
- package/app/plugins/codebuddy/plugin.mjs +5972 -5356
- package/app/plugins/codex-usage/manifest.json +9 -0
- package/app/plugins/codex-usage/plugin.mjs +17386 -0
- package/app/plugins/cursor-cli/manifest.json +18 -1
- package/app/plugins/cursor-cli/plugin.mjs +358 -77
- 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 +823 -242
- package/app/plugins/enabled.json +2 -1
- package/app/plugins/grok/manifest.json +21 -1
- package/app/plugins/grok/plugin.mjs +933 -268
- package/app/plugins/hermes/assets/icon.png +0 -0
- package/app/plugins/hermes/manifest.json +30 -2
- package/app/plugins/hermes/plugin.mjs +469 -73
- 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 +562 -36
- 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 +291 -22
- package/app/plugins/muse/manifest.json +18 -1
- package/app/plugins/muse/plugin.mjs +258 -17
- package/app/plugins/omp/manifest.json +21 -1
- package/app/plugins/omp/plugin.mjs +2763 -1958
- package/app/plugins/opencode/manifest.json +18 -1
- package/app/plugins/opencode/plugin.mjs +724 -147
- package/app/plugins/pi/manifest.json +32 -0
- package/app/plugins/pi/plugin.mjs +2908 -2312
- package/app/plugins/qoder/manifest.json +18 -1
- package/app/plugins/qoder/plugin.mjs +635 -81
- package/app/plugins/qoder-cn/manifest.json +18 -1
- package/app/plugins/qoder-cn/plugin.mjs +635 -81
- package/app/plugins/workbuddy/manifest.json +18 -0
- package/app/plugins/workbuddy/plugin.mjs +6362 -5748
- package/app/plugins/zcode/manifest.json +19 -1
- package/app/plugins/zcode/plugin.mjs +1117 -278
- package/app/renderer-extension.js +14675 -10087
- 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 +4 -4
- package/app/plugins/kiro-cli/assets/icon.svg +0 -5
|
@@ -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,66 @@ 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
|
+
var MAX_SESSION_TITLE_LENGTH = 200;
|
|
499
|
+
function usageSessionTitle(value) {
|
|
500
|
+
if (typeof value !== "string")
|
|
501
|
+
return void 0;
|
|
502
|
+
const normalized = value.replaceAll("\0", "").replaceAll(/\s+/gu, " ").trim();
|
|
503
|
+
if (!normalized)
|
|
504
|
+
return void 0;
|
|
505
|
+
if (normalized.length <= MAX_SESSION_TITLE_LENGTH)
|
|
506
|
+
return normalized;
|
|
507
|
+
const characters = [...normalized];
|
|
508
|
+
if (characters.length <= MAX_SESSION_TITLE_LENGTH)
|
|
509
|
+
return normalized;
|
|
510
|
+
return `${characters.slice(0, MAX_SESSION_TITLE_LENGTH - 1).join("").trimEnd()}…`;
|
|
511
|
+
}
|
|
512
|
+
function sessionIdOk(value) {
|
|
513
|
+
return typeof value === "string" && value.length > 0 && value.length <= MAX_SESSION_ID_LENGTH;
|
|
514
|
+
}
|
|
515
|
+
function cwdOk(value) {
|
|
516
|
+
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("\\\\"));
|
|
517
|
+
}
|
|
518
|
+
function withUsageSession(entry, session) {
|
|
519
|
+
const sessionId = sessionIdOk(session.sessionId) ? session.sessionId : void 0;
|
|
520
|
+
const cwd = cwdOk(session.cwd) ? session.cwd : void 0;
|
|
521
|
+
const sessionTitle = sessionId !== void 0 ? usageSessionTitle(session.title) : void 0;
|
|
522
|
+
if (sessionId === void 0 && cwd === void 0)
|
|
523
|
+
return entry;
|
|
524
|
+
return {
|
|
525
|
+
...entry,
|
|
526
|
+
...sessionId !== void 0 ? { sessionId } : {},
|
|
527
|
+
...cwd !== void 0 ? { cwd } : {},
|
|
528
|
+
...sessionTitle !== void 0 ? { sessionTitle } : {}
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
function usageEntryFromRequest(request, occurredAtMs) {
|
|
532
|
+
if (!Number.isSafeInteger(occurredAtMs) || occurredAtMs <= 0)
|
|
533
|
+
return null;
|
|
534
|
+
return {
|
|
535
|
+
id: request.requestId,
|
|
536
|
+
occurredAtMs,
|
|
537
|
+
...request.model !== void 0 ? { model: request.model } : {},
|
|
538
|
+
inputTokens: request.inputTokens,
|
|
539
|
+
...request.cachedInputTokens !== void 0 ? { cachedInputTokens: request.cachedInputTokens } : {},
|
|
540
|
+
...request.cacheWriteInputTokens !== void 0 ? { cacheWriteInputTokens: request.cacheWriteInputTokens } : {},
|
|
541
|
+
...request.cacheWrite1hInputTokens !== void 0 ? { cacheWrite1hInputTokens: request.cacheWrite1hInputTokens } : {},
|
|
542
|
+
outputTokens: request.outputTokens,
|
|
543
|
+
...request.reasoningOutputTokens !== void 0 ? { reasoningOutputTokens: request.reasoningOutputTokens } : {}
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
function nativeTimeMs(value) {
|
|
547
|
+
const time3 = typeof value === "number" ? value : typeof value === "string" ? Date.parse(value) : Number.NaN;
|
|
548
|
+
return Number.isFinite(time3) && time3 > 0 ? Math.floor(time3) : null;
|
|
549
|
+
}
|
|
494
550
|
|
|
495
551
|
// ../../../node_modules/zod/v4/classic/external.js
|
|
496
552
|
var external_exports = {};
|
|
@@ -1258,10 +1314,10 @@ function mergeDefs(...defs) {
|
|
|
1258
1314
|
function cloneDef(schema) {
|
|
1259
1315
|
return mergeDefs(schema._zod.def);
|
|
1260
1316
|
}
|
|
1261
|
-
function getElementAtPath(obj,
|
|
1262
|
-
if (!
|
|
1317
|
+
function getElementAtPath(obj, path14) {
|
|
1318
|
+
if (!path14)
|
|
1263
1319
|
return obj;
|
|
1264
|
-
return
|
|
1320
|
+
return path14.reduce((acc, key) => acc?.[key], obj);
|
|
1265
1321
|
}
|
|
1266
1322
|
function promiseAllObject(promisesObj) {
|
|
1267
1323
|
const keys = Object.keys(promisesObj);
|
|
@@ -1670,11 +1726,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
1670
1726
|
}
|
|
1671
1727
|
return false;
|
|
1672
1728
|
}
|
|
1673
|
-
function prefixIssues(
|
|
1729
|
+
function prefixIssues(path14, issues) {
|
|
1674
1730
|
return issues.map((iss) => {
|
|
1675
1731
|
var _a3;
|
|
1676
1732
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
1677
|
-
iss.path.unshift(
|
|
1733
|
+
iss.path.unshift(path14);
|
|
1678
1734
|
return iss;
|
|
1679
1735
|
});
|
|
1680
1736
|
}
|
|
@@ -1821,16 +1877,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1821
1877
|
}
|
|
1822
1878
|
function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
1823
1879
|
const fieldErrors = { _errors: [] };
|
|
1824
|
-
const processError = (error52,
|
|
1880
|
+
const processError = (error52, path14 = []) => {
|
|
1825
1881
|
for (const issue2 of error52.issues) {
|
|
1826
1882
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1827
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1883
|
+
issue2.errors.map((issues) => processError({ issues }, [...path14, ...issue2.path]));
|
|
1828
1884
|
} else if (issue2.code === "invalid_key") {
|
|
1829
|
-
processError({ issues: issue2.issues }, [...
|
|
1885
|
+
processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
|
|
1830
1886
|
} else if (issue2.code === "invalid_element") {
|
|
1831
|
-
processError({ issues: issue2.issues }, [...
|
|
1887
|
+
processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
|
|
1832
1888
|
} else {
|
|
1833
|
-
const fullpath = [...
|
|
1889
|
+
const fullpath = [...path14, ...issue2.path];
|
|
1834
1890
|
if (fullpath.length === 0) {
|
|
1835
1891
|
fieldErrors._errors.push(mapper(issue2));
|
|
1836
1892
|
} else {
|
|
@@ -1857,17 +1913,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1857
1913
|
}
|
|
1858
1914
|
function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
1859
1915
|
const result = { errors: [] };
|
|
1860
|
-
const processError = (error52,
|
|
1916
|
+
const processError = (error52, path14 = []) => {
|
|
1861
1917
|
var _a3, _b;
|
|
1862
1918
|
for (const issue2 of error52.issues) {
|
|
1863
1919
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1864
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1920
|
+
issue2.errors.map((issues) => processError({ issues }, [...path14, ...issue2.path]));
|
|
1865
1921
|
} else if (issue2.code === "invalid_key") {
|
|
1866
|
-
processError({ issues: issue2.issues }, [...
|
|
1922
|
+
processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
|
|
1867
1923
|
} else if (issue2.code === "invalid_element") {
|
|
1868
|
-
processError({ issues: issue2.issues }, [...
|
|
1924
|
+
processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
|
|
1869
1925
|
} else {
|
|
1870
|
-
const fullpath = [...
|
|
1926
|
+
const fullpath = [...path14, ...issue2.path];
|
|
1871
1927
|
if (fullpath.length === 0) {
|
|
1872
1928
|
result.errors.push(mapper(issue2));
|
|
1873
1929
|
continue;
|
|
@@ -1899,8 +1955,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1899
1955
|
}
|
|
1900
1956
|
function toDotPath(_path) {
|
|
1901
1957
|
const segs = [];
|
|
1902
|
-
const
|
|
1903
|
-
for (const seg of
|
|
1958
|
+
const path14 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
1959
|
+
for (const seg of path14) {
|
|
1904
1960
|
if (typeof seg === "number")
|
|
1905
1961
|
segs.push(`[${seg}]`);
|
|
1906
1962
|
else if (typeof seg === "symbol")
|
|
@@ -5128,8 +5184,8 @@ function az_default() {
|
|
|
5128
5184
|
}
|
|
5129
5185
|
|
|
5130
5186
|
// ../../../node_modules/zod/v4/locales/be.js
|
|
5131
|
-
function getBelarusianPlural(
|
|
5132
|
-
const absCount = Math.abs(
|
|
5187
|
+
function getBelarusianPlural(count2, one, few, many) {
|
|
5188
|
+
const absCount = Math.abs(count2);
|
|
5133
5189
|
const lastDigit = absCount % 10;
|
|
5134
5190
|
const lastTwoDigits = absCount % 100;
|
|
5135
5191
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -7207,8 +7263,8 @@ function hu_default() {
|
|
|
7207
7263
|
}
|
|
7208
7264
|
|
|
7209
7265
|
// ../../../node_modules/zod/v4/locales/hy.js
|
|
7210
|
-
function getArmenianPlural(
|
|
7211
|
-
return Math.abs(
|
|
7266
|
+
function getArmenianPlural(count2, one, many) {
|
|
7267
|
+
return Math.abs(count2) === 1 ? one : many;
|
|
7212
7268
|
}
|
|
7213
7269
|
function withDefiniteArticle(word) {
|
|
7214
7270
|
if (!word)
|
|
@@ -9336,8 +9392,8 @@ function ro_default() {
|
|
|
9336
9392
|
}
|
|
9337
9393
|
|
|
9338
9394
|
// ../../../node_modules/zod/v4/locales/ru.js
|
|
9339
|
-
function getRussianPlural(
|
|
9340
|
-
const absCount = Math.abs(
|
|
9395
|
+
function getRussianPlural(count2, one, few, many) {
|
|
9396
|
+
const absCount = Math.abs(count2);
|
|
9341
9397
|
const lastDigit = absCount % 10;
|
|
9342
9398
|
const lastTwoDigits = absCount % 100;
|
|
9343
9399
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -14592,13 +14648,13 @@ function resolveRef(ref, ctx) {
|
|
|
14592
14648
|
if (!ref.startsWith("#")) {
|
|
14593
14649
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
14594
14650
|
}
|
|
14595
|
-
const
|
|
14596
|
-
if (
|
|
14651
|
+
const path14 = ref.slice(1).split("/").filter(Boolean);
|
|
14652
|
+
if (path14.length === 0) {
|
|
14597
14653
|
return ctx.rootSchema;
|
|
14598
14654
|
}
|
|
14599
14655
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
14600
|
-
if (
|
|
14601
|
-
const key =
|
|
14656
|
+
if (path14[0] === defsKey) {
|
|
14657
|
+
const key = path14[1];
|
|
14602
14658
|
if (!key || !ctx.defs[key]) {
|
|
14603
14659
|
throw new Error(`Reference not found: ${ref}`);
|
|
14604
14660
|
}
|
|
@@ -15006,6 +15062,15 @@ function date4(params) {
|
|
|
15006
15062
|
// ../../../node_modules/zod/v4/classic/external.js
|
|
15007
15063
|
config(en_default());
|
|
15008
15064
|
|
|
15065
|
+
// ../../shared-contracts/dist/delegation-read.js
|
|
15066
|
+
var REMOTE_THREAD_REPLY_MAX_BYTES = 16 * 1024 * 1024;
|
|
15067
|
+
var delegationReadParamsSchema = external_exports.strictObject({
|
|
15068
|
+
threadId: external_exports.string().min(1).max(1024),
|
|
15069
|
+
view: external_exports.enum(["result", "messages"]),
|
|
15070
|
+
cursor: external_exports.string().min(1).max(8192).optional(),
|
|
15071
|
+
limit: external_exports.number().int().min(1).max(100).optional()
|
|
15072
|
+
});
|
|
15073
|
+
|
|
15009
15074
|
// ../../shared-contracts/dist/credential-imports.js
|
|
15010
15075
|
var credentialSourceSchema = external_exports.object({
|
|
15011
15076
|
id: external_exports.string().min(1).max(256),
|
|
@@ -15076,6 +15141,160 @@ var harnessDisplaySetSchema = external_exports.strictObject({
|
|
|
15076
15141
|
initializeOnly: external_exports.boolean().optional()
|
|
15077
15142
|
});
|
|
15078
15143
|
|
|
15144
|
+
// ../../shared-contracts/dist/model-price-overrides.js
|
|
15145
|
+
var usdPerMillionTokens = external_exports.number().finite().nonnegative();
|
|
15146
|
+
var modelPriceOverrideSchema = external_exports.strictObject({
|
|
15147
|
+
input: usdPerMillionTokens,
|
|
15148
|
+
output: usdPerMillionTokens,
|
|
15149
|
+
cacheRead: usdPerMillionTokens.optional(),
|
|
15150
|
+
cacheWrite: usdPerMillionTokens.optional(),
|
|
15151
|
+
cacheWrite1h: usdPerMillionTokens.optional()
|
|
15152
|
+
});
|
|
15153
|
+
var modelPriceKeySchema = external_exports.string().max(512).refine((key) => key.trim() === key && key.length > 0, "Model ID is required");
|
|
15154
|
+
var modelPriceOverridesSchema = external_exports.strictObject({
|
|
15155
|
+
/** Absolute path of the Host's `pricing.json`. */
|
|
15156
|
+
path: external_exports.string(),
|
|
15157
|
+
entries: external_exports.array(external_exports.strictObject({ key: external_exports.string(), price: modelPriceOverrideSchema })),
|
|
15158
|
+
/** Why the existing file is unusable; the Host then ignores it and refuses to overwrite it. */
|
|
15159
|
+
error: external_exports.string().nullable()
|
|
15160
|
+
});
|
|
15161
|
+
var modelPriceOverridesGetSchema = external_exports.strictObject({});
|
|
15162
|
+
var modelPriceOverridesSetSchema = external_exports.strictObject({
|
|
15163
|
+
key: modelPriceKeySchema,
|
|
15164
|
+
price: modelPriceOverrideSchema.nullable(),
|
|
15165
|
+
previousKey: modelPriceKeySchema.optional()
|
|
15166
|
+
});
|
|
15167
|
+
var modelPriceDefaultParamsSchema = external_exports.strictObject({
|
|
15168
|
+
model: modelPriceKeySchema
|
|
15169
|
+
});
|
|
15170
|
+
var modelPriceSuggestionSchema = external_exports.strictObject({
|
|
15171
|
+
/** Verified from catalog canonical links, not inferred from names or equal prices. */
|
|
15172
|
+
official: external_exports.boolean().optional(),
|
|
15173
|
+
canonicalModelId: external_exports.string().min(1).optional(),
|
|
15174
|
+
provider: external_exports.string().min(1).max(512),
|
|
15175
|
+
model: external_exports.string().min(1).max(512),
|
|
15176
|
+
price: modelPriceOverrideSchema
|
|
15177
|
+
});
|
|
15178
|
+
var modelPriceDefaultResultSchema = external_exports.strictObject({
|
|
15179
|
+
price: modelPriceOverrideSchema.nullable(),
|
|
15180
|
+
/** Local catalog suggestions only; never used automatically for pricing. */
|
|
15181
|
+
suggestions: external_exports.array(modelPriceSuggestionSchema).max(6).optional()
|
|
15182
|
+
});
|
|
15183
|
+
|
|
15184
|
+
// ../../shared-contracts/dist/usage-statistics.js
|
|
15185
|
+
var USAGE_STATISTICS_RANGES = ["today", "7d", "30d", "90d", "all"];
|
|
15186
|
+
var count = external_exports.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
|
|
15187
|
+
var localDate = external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/u);
|
|
15188
|
+
var harness = external_exports.string().min(1).max(128);
|
|
15189
|
+
var model = external_exports.string().min(1).max(512);
|
|
15190
|
+
var project = external_exports.string().min(1).max(4096);
|
|
15191
|
+
var usageStatisticsParamsSchema = external_exports.strictObject({
|
|
15192
|
+
range: external_exports.enum(USAGE_STATISTICS_RANGES),
|
|
15193
|
+
harness: harness.optional(),
|
|
15194
|
+
model: model.nullable().optional(),
|
|
15195
|
+
project: project.nullable().optional(),
|
|
15196
|
+
/** One local date inside the range. */
|
|
15197
|
+
date: localDate.optional()
|
|
15198
|
+
});
|
|
15199
|
+
var usageStatisticsTotalsSchema = external_exports.strictObject({
|
|
15200
|
+
requests: count,
|
|
15201
|
+
inputTokens: count,
|
|
15202
|
+
cachedInputTokens: count,
|
|
15203
|
+
cacheWriteInputTokens: count,
|
|
15204
|
+
cacheKnownInputTokens: count,
|
|
15205
|
+
outputTokens: count,
|
|
15206
|
+
reasoningOutputTokens: count,
|
|
15207
|
+
/** USD at the public price, summed over the priced requests only. */
|
|
15208
|
+
costUsd: external_exports.number().finite().min(0),
|
|
15209
|
+
/** Requests without a price (or the cache data the price needs); not in `costUsd`. */
|
|
15210
|
+
unpricedRequests: count,
|
|
15211
|
+
/**
|
|
15212
|
+
* Requests whose storage gave no token counts: counted as requests, with neither tokens nor
|
|
15213
|
+
* cost, and not as unpriced.
|
|
15214
|
+
*/
|
|
15215
|
+
unmeteredRequests: count
|
|
15216
|
+
});
|
|
15217
|
+
var totals = usageStatisticsTotalsSchema.shape;
|
|
15218
|
+
var usageStatisticsSessionSchema = external_exports.strictObject({
|
|
15219
|
+
harness,
|
|
15220
|
+
sessionId: external_exports.string().min(1).max(512),
|
|
15221
|
+
project: project.nullable(),
|
|
15222
|
+
/** Persisted Desktop title for a mapped Session, otherwise its native name; may be absent. */
|
|
15223
|
+
title: external_exports.string().min(1).max(200).optional(),
|
|
15224
|
+
/** Models the session used, most requests first. */
|
|
15225
|
+
models: external_exports.array(model).max(16),
|
|
15226
|
+
firstAtMs: count,
|
|
15227
|
+
lastAtMs: count,
|
|
15228
|
+
...totals
|
|
15229
|
+
});
|
|
15230
|
+
var usageStatisticsResultSchema = external_exports.strictObject({
|
|
15231
|
+
range: external_exports.enum(USAGE_STATISTICS_RANGES),
|
|
15232
|
+
/** First local date of the range; null for all time. */
|
|
15233
|
+
from: localDate.nullable(),
|
|
15234
|
+
to: localDate,
|
|
15235
|
+
/** The filters these figures apply, echoed so a late answer to older filters is recognised. */
|
|
15236
|
+
filters: external_exports.strictObject({
|
|
15237
|
+
harness: harness.nullable(),
|
|
15238
|
+
model: model.nullable(),
|
|
15239
|
+
unknownModel: external_exports.boolean(),
|
|
15240
|
+
project: project.nullable(),
|
|
15241
|
+
unknownProject: external_exports.boolean(),
|
|
15242
|
+
date: localDate.nullable()
|
|
15243
|
+
}),
|
|
15244
|
+
/** Reading of native storage: incomplete while the first read, or a refresh, is under way. */
|
|
15245
|
+
reading: external_exports.strictObject({ complete: external_exports.boolean(), sources: count, read: count }),
|
|
15246
|
+
/** Harnesses whose storage could not be read; their part is missing, the rest is complete. */
|
|
15247
|
+
failures: external_exports.array(external_exports.strictObject({ harness, message: external_exports.string().max(2048) })).max(256),
|
|
15248
|
+
/** Every value seen in the range, ignoring the filters, to choose filters from. */
|
|
15249
|
+
options: external_exports.strictObject({
|
|
15250
|
+
harnesses: external_exports.array(harness).max(256),
|
|
15251
|
+
models: external_exports.array(model.nullable()).max(4096),
|
|
15252
|
+
projects: external_exports.array(project.nullable()).max(4096)
|
|
15253
|
+
}),
|
|
15254
|
+
/** Current display metadata, scoped by Harness. Never a pricing or filter identity.
|
|
15255
|
+
* Optional for older Hosts; missing/conflicting labels fall back to the native model ID.
|
|
15256
|
+
*/
|
|
15257
|
+
modelLabels: external_exports.array(external_exports.strictObject({ harness, model, label: model })).max(4096).optional(),
|
|
15258
|
+
/** Native credits, all filters applied, never combined across Harnesses or treated as USD.
|
|
15259
|
+
* Only groups with at least one reported value appear; reportedRequests exposes partial data.
|
|
15260
|
+
*/
|
|
15261
|
+
credits: external_exports.array(external_exports.strictObject({
|
|
15262
|
+
harness,
|
|
15263
|
+
model: model.nullable(),
|
|
15264
|
+
credits: external_exports.number().finite().min(0),
|
|
15265
|
+
reportedRequests: count,
|
|
15266
|
+
requests: count
|
|
15267
|
+
})).max(4096).optional(),
|
|
15268
|
+
/** All filters applied. */
|
|
15269
|
+
totals: usageStatisticsTotalsSchema,
|
|
15270
|
+
/** Each date and Harness of the range: every filter except the day. */
|
|
15271
|
+
daily: external_exports.array(external_exports.strictObject({ date: localDate, harness, ...totals })).max(2e5),
|
|
15272
|
+
/** Local weekday (0 = Sunday) and hour, all filters applied. */
|
|
15273
|
+
hourly: external_exports.array(external_exports.strictObject({
|
|
15274
|
+
weekday: external_exports.number().int().min(0).max(6),
|
|
15275
|
+
hour: external_exports.number().int().min(0).max(23),
|
|
15276
|
+
...totals
|
|
15277
|
+
})).max(168),
|
|
15278
|
+
byHarness: external_exports.array(external_exports.strictObject({ harness, ...totals })).max(256),
|
|
15279
|
+
byModel: external_exports.array(external_exports.strictObject({
|
|
15280
|
+
model: model.nullable(),
|
|
15281
|
+
...totals,
|
|
15282
|
+
/** Requests priced by what the Harness recorded they cost, not by a price list. */
|
|
15283
|
+
harnessPricedRequests: count
|
|
15284
|
+
})).max(4096),
|
|
15285
|
+
byProject: external_exports.array(external_exports.strictObject({ project: project.nullable(), ...totals })).max(4096),
|
|
15286
|
+
/**
|
|
15287
|
+
* The sessions that spent the most, by cost and by tokens without cache, all filters applied;
|
|
15288
|
+
* requests without a native session are not listed here but count everywhere else.
|
|
15289
|
+
*/
|
|
15290
|
+
sessions: external_exports.array(usageStatisticsSessionSchema).max(100),
|
|
15291
|
+
/**
|
|
15292
|
+
* The sessions last active in the range, newest first, all filters applied. Optional for older
|
|
15293
|
+
* Hosts; missing is treated as no list rather than no sessions.
|
|
15294
|
+
*/
|
|
15295
|
+
recentSessions: external_exports.array(usageStatisticsSessionSchema).max(100).optional()
|
|
15296
|
+
});
|
|
15297
|
+
|
|
15079
15298
|
// ../../shared-contracts/dist/ids.js
|
|
15080
15299
|
var opaqueIdSchema = external_exports.string().refine((value) => value.trim().length > 0, {
|
|
15081
15300
|
message: "Identifier must not be empty or whitespace"
|
|
@@ -15097,13 +15316,40 @@ var HARNESS_PLUGIN_LIMIT = 128;
|
|
|
15097
15316
|
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);
|
|
15098
15317
|
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");
|
|
15099
15318
|
var documentationUrlSchema = external_exports.url().refine((value) => /^https:\/\/[^/?#@]+(?:[/?#]|$)/iu.test(value), "Plugin documentation links must be credential-free HTTPS URLs");
|
|
15319
|
+
var localizedTextSchema = external_exports.object({ en: external_exports.string().max(4096), "zh-CN": external_exports.string().max(4096).optional() }).strict();
|
|
15320
|
+
var harnessInstallationGuideSchema = external_exports.object({
|
|
15321
|
+
commands: external_exports.array(external_exports.object({ terminal: external_exports.string().max(256), command: external_exports.string().max(4096) }).strict()).max(8),
|
|
15322
|
+
before: localizedTextSchema.optional(),
|
|
15323
|
+
after: localizedTextSchema.optional(),
|
|
15324
|
+
downloads: external_exports.array(external_exports.object({ label: external_exports.string().max(128), url: documentationUrlSchema }).strict()).max(8).optional()
|
|
15325
|
+
}).strict();
|
|
15100
15326
|
var pluginPresentationShape = {
|
|
15101
15327
|
id: harnessPluginIdSchema,
|
|
15102
15328
|
name: external_exports.string().trim().min(1).max(128),
|
|
15103
15329
|
version: external_exports.string().min(1).max(128),
|
|
15330
|
+
/** Capability-only plugin; omitted for existing session-capable plugins. */
|
|
15331
|
+
kind: external_exports.literal("usage").optional(),
|
|
15332
|
+
/** Original image styling or bounded vector paths; never arbitrary CSS/SVG markup. */
|
|
15333
|
+
iconStyle: external_exports.object({
|
|
15334
|
+
vector: external_exports.object({
|
|
15335
|
+
viewBox: external_exports.string().max(128).regex(/^-?\d+(?:\.\d+)?(?: +-?\d+(?:\.\d+)?){3}$/u),
|
|
15336
|
+
color: external_exports.string().regex(/^(?:currentColor|#[a-f0-9]{6})$/iu),
|
|
15337
|
+
paths: external_exports.array(external_exports.object({
|
|
15338
|
+
d: external_exports.string().min(1).max(32768).regex(/^[MmLlHhVvCcSsQqTtAaZz\d.,+eE\s-]+$/u),
|
|
15339
|
+
fillRule: external_exports.enum(["evenodd", "nonzero"]).optional(),
|
|
15340
|
+
fill: external_exports.string().regex(/^(?:currentColor|#[a-f0-9]{6})$/iu).optional()
|
|
15341
|
+
}).strict()).min(1).max(32)
|
|
15342
|
+
}).strict().optional(),
|
|
15343
|
+
background: external_exports.string().regex(/^#[a-f0-9]{6}$/iu).optional(),
|
|
15344
|
+
borderRadius: external_exports.number().min(0).max(50).optional(),
|
|
15345
|
+
paddingRatio: external_exports.number().min(0).max(0.25).optional()
|
|
15346
|
+
}).strict().optional(),
|
|
15347
|
+
installation: harnessInstallationGuideSchema.optional(),
|
|
15348
|
+
notice: localizedTextSchema.optional(),
|
|
15104
15349
|
/** The factory accepts a persisted local entrypoint through its construction context. */
|
|
15105
15350
|
launchCommand: external_exports.literal(true).optional(),
|
|
15106
15351
|
links: external_exports.object({
|
|
15352
|
+
website: documentationUrlSchema.optional(),
|
|
15107
15353
|
documentation: documentationUrlSchema.optional(),
|
|
15108
15354
|
installation: documentationUrlSchema.optional()
|
|
15109
15355
|
}).strict().optional()
|
|
@@ -15180,6 +15426,10 @@ var CONSOLE_HOST_METHODS = Object.freeze([
|
|
|
15180
15426
|
"codexhost/account/list",
|
|
15181
15427
|
"codexhost/account/refresh",
|
|
15182
15428
|
"codexhost/account/usage/inspect",
|
|
15429
|
+
"codexhost/usage/model-prices/get",
|
|
15430
|
+
"codexhost/usage/model-prices/set",
|
|
15431
|
+
"codexhost/usage/model-prices/default",
|
|
15432
|
+
"codexhost/usage/statistics/get",
|
|
15183
15433
|
"codexhost/update/check",
|
|
15184
15434
|
"codexhost/update/start",
|
|
15185
15435
|
"codexhost/update/status"
|
|
@@ -15244,6 +15494,7 @@ var threadUsageSnapshotSchema = external_exports.object({
|
|
|
15244
15494
|
cacheWriteInputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
15245
15495
|
outputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
15246
15496
|
outputTokensPerSecond: finiteNonNegativeNumberSchema.optional(),
|
|
15497
|
+
apiOutputTokensPerSecond: finiteNonNegativeNumberSchema.optional(),
|
|
15247
15498
|
reasoningOutputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
15248
15499
|
totalTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
15249
15500
|
totalCostUsd: finiteNonNegativeNumberSchema.optional(),
|
|
@@ -15255,7 +15506,11 @@ var threadUsageSnapshotSchema = external_exports.object({
|
|
|
15255
15506
|
planFiveHourUsedPercent: cacheHitRatePercentSchema.optional(),
|
|
15256
15507
|
planFiveHourResetsAtUnix: nonNegativeSafeIntegerSchema.optional(),
|
|
15257
15508
|
planSevenDayUsedPercent: cacheHitRatePercentSchema.optional(),
|
|
15258
|
-
planSevenDayResetsAtUnix: nonNegativeSafeIntegerSchema.optional()
|
|
15509
|
+
planSevenDayResetsAtUnix: nonNegativeSafeIntegerSchema.optional(),
|
|
15510
|
+
sessionCacheHitRatePercent: cacheHitRatePercentSchema.optional(),
|
|
15511
|
+
timeToFirstOutputMs: nonNegativeSafeIntegerSchema.optional(),
|
|
15512
|
+
costSource: external_exports.enum(["publicPrice", "native"]).optional(),
|
|
15513
|
+
unpricedModels: external_exports.array(external_exports.string().min(1)).min(1).optional()
|
|
15259
15514
|
}).strict().superRefine((usage, context) => {
|
|
15260
15515
|
if (Object.keys(usage).length === 0) {
|
|
15261
15516
|
context.addIssue({ code: "custom", message: "Thread Usage must contain a reliable field" });
|
|
@@ -15276,6 +15531,20 @@ var threadUsageSnapshotSchema = external_exports.object({
|
|
|
15276
15531
|
path: ["contextWindowTokens"]
|
|
15277
15532
|
});
|
|
15278
15533
|
}
|
|
15534
|
+
if (usage.costSource !== void 0 && usage.totalCostUsd === void 0) {
|
|
15535
|
+
context.addIssue({
|
|
15536
|
+
code: "custom",
|
|
15537
|
+
message: "Thread Usage costSource must be provided with totalCostUsd",
|
|
15538
|
+
path: ["costSource"]
|
|
15539
|
+
});
|
|
15540
|
+
}
|
|
15541
|
+
if (usage.unpricedModels !== void 0 && usage.costSource !== "publicPrice") {
|
|
15542
|
+
context.addIssue({
|
|
15543
|
+
code: "custom",
|
|
15544
|
+
message: "Thread Usage unpricedModels must be provided with a publicPrice cost",
|
|
15545
|
+
path: ["unpricedModels"]
|
|
15546
|
+
});
|
|
15547
|
+
}
|
|
15279
15548
|
if (usage.planFiveHourResetsAtUnix !== void 0 && usage.planFiveHourUsedPercent === void 0) {
|
|
15280
15549
|
context.addIssue({
|
|
15281
15550
|
code: "custom",
|
|
@@ -15545,27 +15814,27 @@ var harnessModelCatalogSchema = external_exports.object({
|
|
|
15545
15814
|
}).strict().superRefine((catalog, context) => {
|
|
15546
15815
|
const refs = /* @__PURE__ */ new Set();
|
|
15547
15816
|
const thinkingIds = new Set(catalog.thinkingOptions.map(({ id }) => id));
|
|
15548
|
-
for (const [index,
|
|
15549
|
-
if (refs.has(
|
|
15817
|
+
for (const [index, model2] of catalog.models.entries()) {
|
|
15818
|
+
if (refs.has(model2.ref.id)) {
|
|
15550
15819
|
context.addIssue({
|
|
15551
15820
|
code: "custom",
|
|
15552
15821
|
message: "Model Catalog refs must be unique",
|
|
15553
15822
|
path: ["models", index, "ref", "id"]
|
|
15554
15823
|
});
|
|
15555
15824
|
}
|
|
15556
|
-
refs.add(
|
|
15557
|
-
if (
|
|
15558
|
-
if (refs.has(
|
|
15825
|
+
refs.add(model2.ref.id);
|
|
15826
|
+
if (model2.fastModel) {
|
|
15827
|
+
if (refs.has(model2.fastModel.id) || catalog.models.some((entry) => entry.ref.id === model2.fastModel?.id)) {
|
|
15559
15828
|
context.addIssue({
|
|
15560
15829
|
code: "custom",
|
|
15561
15830
|
message: "Fast Model refs must be distinct and unique",
|
|
15562
15831
|
path: ["models", index, "fastModel"]
|
|
15563
15832
|
});
|
|
15564
15833
|
}
|
|
15565
|
-
refs.add(
|
|
15834
|
+
refs.add(model2.fastModel.id);
|
|
15566
15835
|
}
|
|
15567
15836
|
const supportedThinkingIds = /* @__PURE__ */ new Set();
|
|
15568
|
-
for (const [optionIndex, optionId] of (
|
|
15837
|
+
for (const [optionIndex, optionId] of (model2.supportedThinkingOptionIds ?? []).entries()) {
|
|
15569
15838
|
if (supportedThinkingIds.has(optionId)) {
|
|
15570
15839
|
context.addIssue({
|
|
15571
15840
|
code: "custom",
|
|
@@ -16159,6 +16428,11 @@ var codexSshDraftSchema = external_exports.strictObject({
|
|
|
16159
16428
|
});
|
|
16160
16429
|
var remoteConnectionsRequestSchema = external_exports.discriminatedUnion("action", [
|
|
16161
16430
|
external_exports.strictObject({ action: external_exports.literal("list") }),
|
|
16431
|
+
external_exports.strictObject({
|
|
16432
|
+
action: external_exports.literal("read-thread"),
|
|
16433
|
+
hostId: hostId.refine((id) => id !== "local"),
|
|
16434
|
+
input: delegationReadParamsSchema
|
|
16435
|
+
}),
|
|
16162
16436
|
external_exports.strictObject({
|
|
16163
16437
|
action: external_exports.literal("save"),
|
|
16164
16438
|
draft: codexSshDraftSchema,
|
|
@@ -16290,7 +16564,6 @@ var tokenFields = [
|
|
|
16290
16564
|
"cachedInputTokens",
|
|
16291
16565
|
"cacheWriteInputTokens",
|
|
16292
16566
|
"outputTokens",
|
|
16293
|
-
"outputTokensPerSecond",
|
|
16294
16567
|
"reasoningOutputTokens",
|
|
16295
16568
|
"totalTokens",
|
|
16296
16569
|
"contextWindowTokens",
|
|
@@ -16298,10 +16571,12 @@ var tokenFields = [
|
|
|
16298
16571
|
];
|
|
16299
16572
|
var safeIntegerFields = [
|
|
16300
16573
|
"planFiveHourResetsAtUnix",
|
|
16301
|
-
"planSevenDayResetsAtUnix"
|
|
16574
|
+
"planSevenDayResetsAtUnix",
|
|
16575
|
+
"timeToFirstOutputMs"
|
|
16302
16576
|
];
|
|
16303
16577
|
var percentFields = [
|
|
16304
16578
|
"cacheHitRatePercent",
|
|
16579
|
+
"sessionCacheHitRatePercent",
|
|
16305
16580
|
"planFiveHourUsedPercent",
|
|
16306
16581
|
"planSevenDayUsedPercent"
|
|
16307
16582
|
];
|
|
@@ -16309,9 +16584,14 @@ var usageFields = /* @__PURE__ */ new Set([
|
|
|
16309
16584
|
...tokenFields,
|
|
16310
16585
|
...safeIntegerFields,
|
|
16311
16586
|
...percentFields,
|
|
16587
|
+
"sessionCacheUsage",
|
|
16312
16588
|
"totalCostUsd",
|
|
16313
16589
|
"totalCredits",
|
|
16314
|
-
"contextUsagePercent"
|
|
16590
|
+
"contextUsagePercent",
|
|
16591
|
+
"outputTokensPerSecond",
|
|
16592
|
+
"apiOutputTokensPerSecond",
|
|
16593
|
+
"costSource",
|
|
16594
|
+
"unpricedModels"
|
|
16315
16595
|
]);
|
|
16316
16596
|
function isRecord(value) {
|
|
16317
16597
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -16327,7 +16607,11 @@ function parseHostUsage(value) {
|
|
|
16327
16607
|
throw new Error(`Harness Usage contains unknown field '${key}'`);
|
|
16328
16608
|
}
|
|
16329
16609
|
}
|
|
16330
|
-
for (const field of [
|
|
16610
|
+
for (const field of [
|
|
16611
|
+
"totalCredits",
|
|
16612
|
+
"contextUsagePercent",
|
|
16613
|
+
"apiOutputTokensPerSecond"
|
|
16614
|
+
]) {
|
|
16331
16615
|
const candidate2 = value[field];
|
|
16332
16616
|
if (candidate2 !== void 0 && (typeof candidate2 !== "number" || !Number.isFinite(candidate2) || candidate2 < 0)) {
|
|
16333
16617
|
throw new Error(`Harness Usage '${field}' must be a finite non-negative number`);
|
|
@@ -16363,6 +16647,12 @@ function parseHostUsage(value) {
|
|
|
16363
16647
|
throw new Error(`Harness Usage '${field}' must be between 0 and 100`);
|
|
16364
16648
|
}
|
|
16365
16649
|
}
|
|
16650
|
+
if (value.sessionCacheUsage !== void 0) {
|
|
16651
|
+
const totals2 = value.sessionCacheUsage;
|
|
16652
|
+
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) {
|
|
16653
|
+
throw new Error("Harness Usage 'sessionCacheUsage' must contain complete bounded token totals");
|
|
16654
|
+
}
|
|
16655
|
+
}
|
|
16366
16656
|
const hasContextUsed = value.contextUsedTokens !== void 0;
|
|
16367
16657
|
const hasContextWindow = value.contextWindowTokens !== void 0;
|
|
16368
16658
|
if (hasContextUsed !== hasContextWindow) {
|
|
@@ -16377,8 +16667,224 @@ function parseHostUsage(value) {
|
|
|
16377
16667
|
if (value.planSevenDayResetsAtUnix !== void 0 && value.planSevenDayUsedPercent === void 0) {
|
|
16378
16668
|
throw new Error("Harness Usage 'planSevenDayResetsAtUnix' must be provided with 'planSevenDayUsedPercent'");
|
|
16379
16669
|
}
|
|
16670
|
+
if (value.costSource !== void 0) {
|
|
16671
|
+
if (value.costSource !== "publicPrice" && value.costSource !== "native") {
|
|
16672
|
+
throw new Error("Harness Usage 'costSource' must be 'publicPrice' or 'native'");
|
|
16673
|
+
}
|
|
16674
|
+
if (value.totalCostUsd === void 0) {
|
|
16675
|
+
throw new Error("Harness Usage 'costSource' must be provided with 'totalCostUsd'");
|
|
16676
|
+
}
|
|
16677
|
+
}
|
|
16678
|
+
if (value.unpricedModels !== void 0) {
|
|
16679
|
+
const models = value.unpricedModels;
|
|
16680
|
+
if (!Array.isArray(models) || models.length === 0 || !models.every((model2) => typeof model2 === "string" && model2.length > 0)) {
|
|
16681
|
+
throw new Error("Harness Usage 'unpricedModels' must be a non-empty list of Model IDs");
|
|
16682
|
+
}
|
|
16683
|
+
if (value.costSource !== "publicPrice") {
|
|
16684
|
+
throw new Error("Harness Usage 'unpricedModels' must be provided with a 'publicPrice' cost");
|
|
16685
|
+
}
|
|
16686
|
+
return { ...value, unpricedModels: [...models] };
|
|
16687
|
+
}
|
|
16380
16688
|
return { ...value };
|
|
16381
16689
|
}
|
|
16690
|
+
var requestTokenFields = [
|
|
16691
|
+
"inputTokens",
|
|
16692
|
+
"cachedInputTokens",
|
|
16693
|
+
"cacheWriteInputTokens",
|
|
16694
|
+
"cacheWrite1hInputTokens",
|
|
16695
|
+
"outputTokens",
|
|
16696
|
+
"reasoningOutputTokens",
|
|
16697
|
+
"startedAtMs",
|
|
16698
|
+
"completedAtMs"
|
|
16699
|
+
];
|
|
16700
|
+
var requestFields = /* @__PURE__ */ new Set([
|
|
16701
|
+
...requestTokenFields,
|
|
16702
|
+
"requestId",
|
|
16703
|
+
"historical",
|
|
16704
|
+
"model",
|
|
16705
|
+
"provider"
|
|
16706
|
+
]);
|
|
16707
|
+
function parseHostUsageRequest(value) {
|
|
16708
|
+
if (!isRecord(value))
|
|
16709
|
+
throw new Error("Harness Usage request must be an object");
|
|
16710
|
+
for (const key of Object.keys(value)) {
|
|
16711
|
+
if (!requestFields.has(key)) {
|
|
16712
|
+
throw new Error(`Harness Usage request contains unknown field '${key}'`);
|
|
16713
|
+
}
|
|
16714
|
+
}
|
|
16715
|
+
if (typeof value.requestId !== "string" || value.requestId.length === 0) {
|
|
16716
|
+
throw new Error("Harness Usage request 'requestId' must be a non-empty string");
|
|
16717
|
+
}
|
|
16718
|
+
for (const field of ["model", "provider"]) {
|
|
16719
|
+
const candidate2 = value[field];
|
|
16720
|
+
if (candidate2 !== void 0 && (typeof candidate2 !== "string" || candidate2.length === 0)) {
|
|
16721
|
+
throw new Error(`Harness Usage request '${field}' must be a non-empty string`);
|
|
16722
|
+
}
|
|
16723
|
+
}
|
|
16724
|
+
if (value.historical !== void 0 && typeof value.historical !== "boolean") {
|
|
16725
|
+
throw new Error("Harness Usage request 'historical' must be a boolean");
|
|
16726
|
+
}
|
|
16727
|
+
for (const field of requestTokenFields) {
|
|
16728
|
+
const candidate2 = value[field];
|
|
16729
|
+
if (candidate2 !== void 0 && (typeof candidate2 !== "number" || !Number.isSafeInteger(candidate2) || candidate2 < 0)) {
|
|
16730
|
+
throw new Error(`Harness Usage request '${field}' must be a non-negative safe integer`);
|
|
16731
|
+
}
|
|
16732
|
+
}
|
|
16733
|
+
if (value.inputTokens === void 0 || value.outputTokens === void 0) {
|
|
16734
|
+
throw new Error("Harness Usage request must contain 'inputTokens' and 'outputTokens'");
|
|
16735
|
+
}
|
|
16736
|
+
const request = value;
|
|
16737
|
+
if ((request.cachedInputTokens ?? 0) + (request.cacheWriteInputTokens ?? 0) > request.inputTokens) {
|
|
16738
|
+
throw new Error("Harness Usage request cache Tokens must not exceed 'inputTokens'");
|
|
16739
|
+
}
|
|
16740
|
+
if ((request.reasoningOutputTokens ?? 0) > request.outputTokens) {
|
|
16741
|
+
throw new Error("Harness Usage request 'reasoningOutputTokens' must not exceed 'outputTokens'");
|
|
16742
|
+
}
|
|
16743
|
+
if (request.cacheWrite1hInputTokens !== void 0 && request.cacheWrite1hInputTokens > (request.cacheWriteInputTokens ?? -1)) {
|
|
16744
|
+
throw new Error("Harness Usage request 'cacheWrite1hInputTokens' must not exceed 'cacheWriteInputTokens'");
|
|
16745
|
+
}
|
|
16746
|
+
if (request.startedAtMs === void 0 !== (request.completedAtMs === void 0)) {
|
|
16747
|
+
throw new Error("Harness Usage request timing fields must be provided together");
|
|
16748
|
+
}
|
|
16749
|
+
if (request.startedAtMs !== void 0 && request.completedAtMs !== void 0 && request.completedAtMs < request.startedAtMs) {
|
|
16750
|
+
throw new Error("Harness Usage request 'completedAtMs' must not precede 'startedAtMs'");
|
|
16751
|
+
}
|
|
16752
|
+
return { ...request };
|
|
16753
|
+
}
|
|
16754
|
+
|
|
16755
|
+
// dist/v2/usage.js
|
|
16756
|
+
function v2UsageRequest(message, historical, firstOutputAtMs) {
|
|
16757
|
+
if (message.type !== "assistant" || !message.tokens)
|
|
16758
|
+
return null;
|
|
16759
|
+
const { input, output, reasoning, cache } = message.tokens;
|
|
16760
|
+
const { streamed } = message.time;
|
|
16761
|
+
return parseHostUsageRequest({
|
|
16762
|
+
requestId: message.id,
|
|
16763
|
+
...historical ? { historical: true } : {},
|
|
16764
|
+
model: message.model.id,
|
|
16765
|
+
// Built-in OpenCode providers use models.dev IDs. A custom provider ID matches no price
|
|
16766
|
+
// entry, so Host falls back to the exact model ID.
|
|
16767
|
+
provider: message.model.providerID,
|
|
16768
|
+
inputTokens: input + cache.read + cache.write,
|
|
16769
|
+
cachedInputTokens: cache.read,
|
|
16770
|
+
cacheWriteInputTokens: cache.write,
|
|
16771
|
+
outputTokens: output + reasoning,
|
|
16772
|
+
reasoningOutputTokens: reasoning,
|
|
16773
|
+
// End at stream completion, not step completion, which can include tool execution.
|
|
16774
|
+
// Without a native stream end, keep the usage but do not guess its generation duration.
|
|
16775
|
+
...!historical && firstOutputAtMs !== void 0 && streamed !== void 0 && streamed >= firstOutputAtMs ? { startedAtMs: firstOutputAtMs, completedAtMs: streamed } : {}
|
|
16776
|
+
});
|
|
16777
|
+
}
|
|
16778
|
+
|
|
16779
|
+
// dist/usage-statistics.js
|
|
16780
|
+
function parseRowData(data) {
|
|
16781
|
+
try {
|
|
16782
|
+
return JSON.parse(String(data));
|
|
16783
|
+
} catch {
|
|
16784
|
+
return null;
|
|
16785
|
+
}
|
|
16786
|
+
}
|
|
16787
|
+
function isRecord2(value) {
|
|
16788
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16789
|
+
}
|
|
16790
|
+
function openCodeDatabasePath(environment) {
|
|
16791
|
+
const home = environment.HOME || environment.USERPROFILE || os2.homedir();
|
|
16792
|
+
const directory = path5.join(environment.XDG_DATA_HOME || path5.join(home, ".local", "share"), "opencode");
|
|
16793
|
+
const configured = environment.OPENCODE_DB;
|
|
16794
|
+
if (configured === ":memory:")
|
|
16795
|
+
return null;
|
|
16796
|
+
return configured ? path5.resolve(directory, configured) : path5.join(directory, "opencode.db");
|
|
16797
|
+
}
|
|
16798
|
+
async function fingerprint(file2) {
|
|
16799
|
+
const info = await lstat(file2).catch(() => null);
|
|
16800
|
+
if (!info?.isFile())
|
|
16801
|
+
return null;
|
|
16802
|
+
const wal = await lstat(`${file2}-wal`).catch(() => null);
|
|
16803
|
+
return `${info.ino}:${info.size}:${info.mtimeMs}:${wal ? `${wal.size}:${wal.mtimeMs}` : "-"}`;
|
|
16804
|
+
}
|
|
16805
|
+
async function readOpenCodeUsage(file2) {
|
|
16806
|
+
const { DatabaseSync } = await import("node:sqlite");
|
|
16807
|
+
const database = new DatabaseSync(file2, { readOnly: true });
|
|
16808
|
+
try {
|
|
16809
|
+
const tables = new Set(database.prepare("SELECT name FROM sqlite_master WHERE type = 'table'").all().map((row) => String(row.name)));
|
|
16810
|
+
const directories = /* @__PURE__ */ new Map();
|
|
16811
|
+
const titles = /* @__PURE__ */ new Map();
|
|
16812
|
+
for (const table of ["session", "session_v2"]) {
|
|
16813
|
+
if (!tables.has(table))
|
|
16814
|
+
continue;
|
|
16815
|
+
const columns = new Set(database.prepare(`PRAGMA table_info(${table})`).all().map((row) => String(row.name)));
|
|
16816
|
+
const titleColumn = columns.has("title") ? ", title" : "";
|
|
16817
|
+
for (const row of database.prepare(`SELECT id, directory${titleColumn} FROM ${table}`).iterate()) {
|
|
16818
|
+
if (typeof row.directory === "string")
|
|
16819
|
+
directories.set(String(row.id), row.directory);
|
|
16820
|
+
const title = usageSessionTitle(row.title);
|
|
16821
|
+
if (title)
|
|
16822
|
+
titles.set(String(row.id), title);
|
|
16823
|
+
}
|
|
16824
|
+
}
|
|
16825
|
+
const entries = /* @__PURE__ */ new Map();
|
|
16826
|
+
const add = (message, createdAtMs, session) => {
|
|
16827
|
+
let request;
|
|
16828
|
+
try {
|
|
16829
|
+
request = v2UsageRequest(message, true);
|
|
16830
|
+
} catch {
|
|
16831
|
+
return;
|
|
16832
|
+
}
|
|
16833
|
+
const at = nativeTimeMs(createdAtMs);
|
|
16834
|
+
const entry = request && at !== null && usageEntryFromRequest(request, at);
|
|
16835
|
+
if (entry && !entries.has(entry.id)) {
|
|
16836
|
+
const sessionId = typeof session === "string" ? session : void 0;
|
|
16837
|
+
entries.set(entry.id, withUsageSession(entry, {
|
|
16838
|
+
sessionId,
|
|
16839
|
+
cwd: sessionId === void 0 ? void 0 : directories.get(sessionId),
|
|
16840
|
+
title: sessionId === void 0 ? void 0 : titles.get(sessionId)
|
|
16841
|
+
}));
|
|
16842
|
+
}
|
|
16843
|
+
};
|
|
16844
|
+
if (tables.has("session_message")) {
|
|
16845
|
+
for (const row of database.prepare("SELECT id, session_id, data FROM session_message WHERE type = 'assistant'").iterate()) {
|
|
16846
|
+
const data = parseRowData(row.data);
|
|
16847
|
+
if (!isRecord2(data))
|
|
16848
|
+
continue;
|
|
16849
|
+
add({ ...data, id: String(row.id), type: "assistant" }, isRecord2(data.time) ? data.time.created : void 0, row.session_id);
|
|
16850
|
+
}
|
|
16851
|
+
}
|
|
16852
|
+
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 ?? ""));
|
|
16853
|
+
if (tables.has("message") && !migrated) {
|
|
16854
|
+
for (const row of database.prepare("SELECT id, session_id, data FROM message").iterate()) {
|
|
16855
|
+
const data = parseRowData(row.data);
|
|
16856
|
+
if (!isRecord2(data) || data.role !== "assistant" || typeof data.modelID !== "string") {
|
|
16857
|
+
continue;
|
|
16858
|
+
}
|
|
16859
|
+
add({
|
|
16860
|
+
id: String(row.id),
|
|
16861
|
+
type: "assistant",
|
|
16862
|
+
model: { id: data.modelID, providerID: data.providerID },
|
|
16863
|
+
tokens: data.tokens,
|
|
16864
|
+
time: data.time
|
|
16865
|
+
}, isRecord2(data.time) ? data.time.created : void 0, row.session_id);
|
|
16866
|
+
}
|
|
16867
|
+
}
|
|
16868
|
+
return [...entries.values()];
|
|
16869
|
+
} finally {
|
|
16870
|
+
database.close();
|
|
16871
|
+
}
|
|
16872
|
+
}
|
|
16873
|
+
function createOpenCodeUsageStatistics(environment) {
|
|
16874
|
+
return Object.freeze({
|
|
16875
|
+
async listSources() {
|
|
16876
|
+
const file2 = openCodeDatabasePath(environment);
|
|
16877
|
+
const stamp = file2 ? await fingerprint(file2) : null;
|
|
16878
|
+
return file2 && stamp ? [{ id: file2, fingerprint: stamp }] : [];
|
|
16879
|
+
},
|
|
16880
|
+
readSource: (id) => readOpenCodeUsage(id)
|
|
16881
|
+
});
|
|
16882
|
+
}
|
|
16883
|
+
|
|
16884
|
+
// dist/opencode-adapter.js
|
|
16885
|
+
import { randomUUID } from "node:crypto";
|
|
16886
|
+
import fs4 from "node:fs";
|
|
16887
|
+
import path9 from "node:path";
|
|
16382
16888
|
|
|
16383
16889
|
// dist/model-catalog.js
|
|
16384
16890
|
import { Buffer as Buffer2 } from "node:buffer";
|
|
@@ -16389,10 +16895,10 @@ function assertNonBlank(value, label) {
|
|
|
16389
16895
|
if (!value.trim())
|
|
16390
16896
|
throw new Error(`OpenCode ${label} must not be empty`);
|
|
16391
16897
|
}
|
|
16392
|
-
function encodeOpenCodeModelRef(
|
|
16393
|
-
assertNonBlank(
|
|
16394
|
-
assertNonBlank(
|
|
16395
|
-
const encoded = Buffer2.from(JSON.stringify([
|
|
16898
|
+
function encodeOpenCodeModelRef(model2) {
|
|
16899
|
+
assertNonBlank(model2.providerID, "Provider ID");
|
|
16900
|
+
assertNonBlank(model2.modelID, "Model ID");
|
|
16901
|
+
const encoded = Buffer2.from(JSON.stringify([model2.providerID, model2.modelID]), "utf8").toString("base64url");
|
|
16396
16902
|
const id = `${MODEL_REF_PREFIX}${encoded}`;
|
|
16397
16903
|
if (id.length > HARNESS_MODEL_REF_MAX_LENGTH) {
|
|
16398
16904
|
throw new Error("OpenCode Model identity is too long for a Model Ref");
|
|
@@ -16450,26 +16956,26 @@ function compareText(left, right) {
|
|
|
16450
16956
|
}
|
|
16451
16957
|
function modelsForConnectedProviders(catalog) {
|
|
16452
16958
|
const connected = new Set(catalog.connected);
|
|
16453
|
-
return catalog.all.flatMap((provider) => connected.has(provider.id) ? Object.values(provider.models).map((
|
|
16959
|
+
return catalog.all.flatMap((provider) => connected.has(provider.id) ? Object.values(provider.models).map((model2) => ({ provider, model: model2 })) : []);
|
|
16454
16960
|
}
|
|
16455
16961
|
function normalizeOpenCodeModelCatalog(catalog) {
|
|
16456
16962
|
const nativeModels = modelsForConnectedProviders(catalog);
|
|
16457
16963
|
const variants = /* @__PURE__ */ new Set();
|
|
16458
|
-
for (const { model } of nativeModels) {
|
|
16459
|
-
for (const variant of Object.keys(
|
|
16964
|
+
for (const { model: model2 } of nativeModels) {
|
|
16965
|
+
for (const variant of Object.keys(model2.variants ?? {}))
|
|
16460
16966
|
variants.add(variant);
|
|
16461
16967
|
}
|
|
16462
16968
|
const thinkingOptions = [
|
|
16463
16969
|
variantOption(void 0),
|
|
16464
16970
|
...[...variants].sort(compareText).map((variant) => variantOption(variant))
|
|
16465
16971
|
];
|
|
16466
|
-
const models = nativeModels.map(({ provider, model }) => ({
|
|
16467
|
-
ref: encodeOpenCodeModelRef({ providerID: provider.id, modelID:
|
|
16468
|
-
label: `${provider.name} / ${
|
|
16469
|
-
resolvedModelLabel: `${provider.id}/${
|
|
16972
|
+
const models = nativeModels.map(({ provider, model: model2 }) => ({
|
|
16973
|
+
ref: encodeOpenCodeModelRef({ providerID: provider.id, modelID: model2.id }),
|
|
16974
|
+
label: `${provider.name} / ${model2.name}`,
|
|
16975
|
+
resolvedModelLabel: `${provider.id}/${model2.id}`,
|
|
16470
16976
|
supportedThinkingOptionIds: [
|
|
16471
16977
|
DEFAULT_VARIANT_ID,
|
|
16472
|
-
...Object.keys(
|
|
16978
|
+
...Object.keys(model2.variants ?? {}).sort(compareText).map(encodeOpenCodeVariant)
|
|
16473
16979
|
]
|
|
16474
16980
|
})).sort((left, right) => compareText(left.label, right.label) || compareText(left.ref.id, right.ref.id));
|
|
16475
16981
|
const defaultNative = catalog.connected.map((providerID) => ({ providerID, modelID: catalog.default[providerID] })).find((candidate2) => typeof candidate2.modelID === "string" && candidate2.modelID.length > 0);
|
|
@@ -16481,9 +16987,9 @@ function normalizeOpenCodeModelCatalog(catalog) {
|
|
|
16481
16987
|
defaultThinkingOptionId: DEFAULT_VARIANT_ID
|
|
16482
16988
|
});
|
|
16483
16989
|
}
|
|
16484
|
-
function openCodeContextWindow(catalog,
|
|
16485
|
-
const provider = catalog.all.find(({ id }) => id ===
|
|
16486
|
-
const context = provider?.models[
|
|
16990
|
+
function openCodeContextWindow(catalog, model2) {
|
|
16991
|
+
const provider = catalog.all.find(({ id }) => id === model2.providerID);
|
|
16992
|
+
const context = provider?.models[model2.modelID]?.limit.context;
|
|
16487
16993
|
return typeof context === "number" && Number.isSafeInteger(context) && context > 0 ? context : void 0;
|
|
16488
16994
|
}
|
|
16489
16995
|
|
|
@@ -16806,7 +17312,7 @@ import { spawn, spawnSync } from "node:child_process";
|
|
|
16806
17312
|
import fs2 from "node:fs";
|
|
16807
17313
|
import { createServer } from "node:net";
|
|
16808
17314
|
import { homedir as homedir2, tmpdir as tmpdir2 } from "node:os";
|
|
16809
|
-
import
|
|
17315
|
+
import path7 from "node:path";
|
|
16810
17316
|
|
|
16811
17317
|
// ../../../node_modules/@opencode-ai/sdk/dist/v2/gen/core/serverSentEvents.gen.js
|
|
16812
17318
|
var createSseClient = ({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url: url2, ...options }) => {
|
|
@@ -17032,7 +17538,7 @@ var serializeObjectParam = ({ allowReserved, explode, name, style, value, valueO
|
|
|
17032
17538
|
|
|
17033
17539
|
// ../../../node_modules/@opencode-ai/sdk/dist/v2/gen/core/utils.gen.js
|
|
17034
17540
|
var PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
17035
|
-
var defaultPathSerializer = ({ path:
|
|
17541
|
+
var defaultPathSerializer = ({ path: path14, url: _url2 }) => {
|
|
17036
17542
|
let url2 = _url2;
|
|
17037
17543
|
const matches = _url2.match(PATH_PARAM_RE);
|
|
17038
17544
|
if (matches) {
|
|
@@ -17051,7 +17557,7 @@ var defaultPathSerializer = ({ path: path13, url: _url2 }) => {
|
|
|
17051
17557
|
name = name.substring(1);
|
|
17052
17558
|
style = "matrix";
|
|
17053
17559
|
}
|
|
17054
|
-
const value =
|
|
17560
|
+
const value = path14[name];
|
|
17055
17561
|
if (value === void 0 || value === null) {
|
|
17056
17562
|
continue;
|
|
17057
17563
|
}
|
|
@@ -17082,11 +17588,11 @@ var defaultPathSerializer = ({ path: path13, url: _url2 }) => {
|
|
|
17082
17588
|
}
|
|
17083
17589
|
return url2;
|
|
17084
17590
|
};
|
|
17085
|
-
var getUrl = ({ baseUrl, path:
|
|
17591
|
+
var getUrl = ({ baseUrl, path: path14, query, querySerializer, url: _url2 }) => {
|
|
17086
17592
|
const pathUrl = _url2.startsWith("/") ? _url2 : `/${_url2}`;
|
|
17087
17593
|
let url2 = (baseUrl ?? "") + pathUrl;
|
|
17088
|
-
if (
|
|
17089
|
-
url2 = defaultPathSerializer({ path:
|
|
17594
|
+
if (path14) {
|
|
17595
|
+
url2 = defaultPathSerializer({ path: path14, url: url2 });
|
|
17090
17596
|
}
|
|
17091
17597
|
let search = query ? querySerializer(query) : "";
|
|
17092
17598
|
if (search.startsWith("?")) {
|
|
@@ -22209,7 +22715,7 @@ function createOpencodeClient(config2) {
|
|
|
22209
22715
|
}
|
|
22210
22716
|
|
|
22211
22717
|
// dist/command.js
|
|
22212
|
-
import
|
|
22718
|
+
import path6 from "node:path";
|
|
22213
22719
|
var OpenCodeExecutableError = class extends Error {
|
|
22214
22720
|
code = "OPENCODE_NOT_FOUND";
|
|
22215
22721
|
constructor(message = "OpenCode CLI is not installed") {
|
|
@@ -22243,7 +22749,7 @@ function resolveOpenCodeExecutable(input = {}, dependencies = {}) {
|
|
|
22243
22749
|
}, dependencies);
|
|
22244
22750
|
if (!resolution)
|
|
22245
22751
|
throw new OpenCodeExecutableError();
|
|
22246
|
-
return targetPath(platform).isAbsolute(resolution.executable) ? resolution.executable :
|
|
22752
|
+
return targetPath(platform).isAbsolute(resolution.executable) ? resolution.executable : path6.resolve(resolution.executable);
|
|
22247
22753
|
}
|
|
22248
22754
|
function openCodeServerInvocation(executable, environment, platform = process.platform, port = 0) {
|
|
22249
22755
|
return commandInvocation(executable, ["serve", "--hostname=127.0.0.1", `--port=${port}`], environment, platform);
|
|
@@ -22271,14 +22777,14 @@ function freeLoopbackPort() {
|
|
|
22271
22777
|
});
|
|
22272
22778
|
});
|
|
22273
22779
|
}
|
|
22274
|
-
function
|
|
22780
|
+
function isRecord3(value) {
|
|
22275
22781
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22276
22782
|
}
|
|
22277
22783
|
function errorText(error51) {
|
|
22278
22784
|
return error51 instanceof Error ? error51.message : String(error51);
|
|
22279
22785
|
}
|
|
22280
22786
|
function isMissingExecutable(error51) {
|
|
22281
|
-
return
|
|
22787
|
+
return isRecord3(error51) && error51.code === "ENOENT";
|
|
22282
22788
|
}
|
|
22283
22789
|
function classifySdkError(error51, operation) {
|
|
22284
22790
|
if (error51 instanceof OpenCodeTransportError)
|
|
@@ -22333,14 +22839,14 @@ function signalProcessTree(child, signal) {
|
|
|
22333
22839
|
try {
|
|
22334
22840
|
process.kill(-child.pid, signal);
|
|
22335
22841
|
} catch (error51) {
|
|
22336
|
-
if (!
|
|
22842
|
+
if (!isRecord3(error51) || error51.code !== "ESRCH")
|
|
22337
22843
|
throw error51;
|
|
22338
22844
|
}
|
|
22339
22845
|
}
|
|
22340
22846
|
function safeOpenCodeServerCwd(environment) {
|
|
22341
22847
|
const candidates = [environment.USERPROFILE, environment.HOME, homedir2(), tmpdir2()];
|
|
22342
22848
|
for (const candidate2 of candidates) {
|
|
22343
|
-
if (!candidate2 || !
|
|
22849
|
+
if (!candidate2 || !path7.isAbsolute(candidate2))
|
|
22344
22850
|
continue;
|
|
22345
22851
|
try {
|
|
22346
22852
|
if (!fs2.statSync(candidate2).isDirectory())
|
|
@@ -22364,7 +22870,7 @@ function managedOpenCodeEnvironment(environment, executionPolicy = "default") {
|
|
|
22364
22870
|
if (existing !== void 0) {
|
|
22365
22871
|
try {
|
|
22366
22872
|
const parsed = JSON.parse(existing);
|
|
22367
|
-
if (!
|
|
22873
|
+
if (!isRecord3(parsed))
|
|
22368
22874
|
throw new Error("OpenCode config content must be an object");
|
|
22369
22875
|
config2 = { ...parsed };
|
|
22370
22876
|
} catch (error51) {
|
|
@@ -22687,11 +23193,11 @@ var SdkOpenCodeTransport = class {
|
|
|
22687
23193
|
parts: [{ type: "text", text: input.text }]
|
|
22688
23194
|
}), this.#commandTimeoutMs, "OpenCode prompt admission"), "prompt admission");
|
|
22689
23195
|
}
|
|
22690
|
-
async summarize(sessionID,
|
|
23196
|
+
async summarize(sessionID, model2) {
|
|
22691
23197
|
const client2 = await this.#getClient();
|
|
22692
23198
|
responseData2(await withTimeout2(client2.session.summarize({
|
|
22693
23199
|
sessionID,
|
|
22694
|
-
...
|
|
23200
|
+
...model2 ? { providerID: model2.providerID, modelID: model2.modelID } : {}
|
|
22695
23201
|
}), this.#commandTimeoutMs, "OpenCode context compaction"), "context compaction");
|
|
22696
23202
|
}
|
|
22697
23203
|
async abort(sessionID) {
|
|
@@ -22789,7 +23295,7 @@ var SdkOpenCodeTransport = class {
|
|
|
22789
23295
|
|
|
22790
23296
|
// dist/file-change-verification.js
|
|
22791
23297
|
import fs3 from "node:fs";
|
|
22792
|
-
import
|
|
23298
|
+
import path8 from "node:path";
|
|
22793
23299
|
function missingPath(error51) {
|
|
22794
23300
|
if (!error51 || typeof error51 !== "object")
|
|
22795
23301
|
return false;
|
|
@@ -22801,33 +23307,33 @@ function hasDotPathSegment(value) {
|
|
|
22801
23307
|
return segments.some((segment) => segment === "." || segment === "..");
|
|
22802
23308
|
}
|
|
22803
23309
|
function canonicalDirectoryPath(value) {
|
|
22804
|
-
let candidate2 =
|
|
23310
|
+
let candidate2 = path8.resolve(value);
|
|
22805
23311
|
const missingSegments = [];
|
|
22806
23312
|
for (; ; ) {
|
|
22807
23313
|
try {
|
|
22808
|
-
return
|
|
23314
|
+
return path8.join(fs3.realpathSync.native(candidate2), ...missingSegments);
|
|
22809
23315
|
} catch (error51) {
|
|
22810
23316
|
if (!missingPath(error51))
|
|
22811
23317
|
return void 0;
|
|
22812
|
-
const parent =
|
|
23318
|
+
const parent = path8.dirname(candidate2);
|
|
22813
23319
|
if (parent === candidate2)
|
|
22814
23320
|
return void 0;
|
|
22815
|
-
missingSegments.unshift(
|
|
23321
|
+
missingSegments.unshift(path8.basename(candidate2));
|
|
22816
23322
|
candidate2 = parent;
|
|
22817
23323
|
}
|
|
22818
23324
|
}
|
|
22819
23325
|
}
|
|
22820
23326
|
function canonicalFilePath(value) {
|
|
22821
|
-
const absolute =
|
|
22822
|
-
const parent = canonicalDirectoryPath(
|
|
22823
|
-
return parent ?
|
|
23327
|
+
const absolute = path8.resolve(value);
|
|
23328
|
+
const parent = canonicalDirectoryPath(path8.dirname(absolute));
|
|
23329
|
+
return parent ? path8.join(parent, path8.basename(absolute)) : void 0;
|
|
22824
23330
|
}
|
|
22825
23331
|
function pathIsWithin(root, candidate2, allowRoot) {
|
|
22826
|
-
const relative =
|
|
22827
|
-
return allowRoot && relative === "" || relative !== "" && relative !== ".." && !relative.startsWith(`..${
|
|
23332
|
+
const relative = path8.relative(root, candidate2);
|
|
23333
|
+
return allowRoot && relative === "" || relative !== "" && relative !== ".." && !relative.startsWith(`..${path8.sep}`) && !path8.isAbsolute(relative);
|
|
22828
23334
|
}
|
|
22829
23335
|
function verifiedOpenCodeWorktree(sessionDirectory, paths) {
|
|
22830
|
-
if (!paths || typeof paths !== "object" || typeof sessionDirectory !== "string" || typeof paths.directory !== "string" || typeof paths.worktree !== "string" || hasDotPathSegment(sessionDirectory) || hasDotPathSegment(paths.directory) || hasDotPathSegment(paths.worktree) || !
|
|
23336
|
+
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)) {
|
|
22831
23337
|
return void 0;
|
|
22832
23338
|
}
|
|
22833
23339
|
const session = canonicalDirectoryPath(sessionDirectory);
|
|
@@ -22839,10 +23345,10 @@ function verifiedOpenCodeWorktree(sessionDirectory, paths) {
|
|
|
22839
23345
|
return worktree;
|
|
22840
23346
|
}
|
|
22841
23347
|
function openCodeFileIdentity(file2, worktree) {
|
|
22842
|
-
if (typeof file2 !== "string" || typeof worktree !== "string" || hasDotPathSegment(file2) || hasDotPathSegment(worktree) || !
|
|
23348
|
+
if (typeof file2 !== "string" || typeof worktree !== "string" || hasDotPathSegment(file2) || hasDotPathSegment(worktree) || !path8.isAbsolute(worktree) || !file2 || file2.includes("\0") || file2.includes("\n") || file2.includes("\r")) {
|
|
22843
23349
|
return void 0;
|
|
22844
23350
|
}
|
|
22845
|
-
const candidate2 = canonicalFilePath(
|
|
23351
|
+
const candidate2 = canonicalFilePath(path8.isAbsolute(file2) ? file2 : path8.resolve(worktree, file2));
|
|
22846
23352
|
return candidate2 && pathIsWithin(worktree, candidate2, false) ? candidate2 : void 0;
|
|
22847
23353
|
}
|
|
22848
23354
|
|
|
@@ -22899,12 +23405,12 @@ function storedSelection(session) {
|
|
|
22899
23405
|
}
|
|
22900
23406
|
return { providerID, modelID, ...typeof variant === "string" ? { variant } : {} };
|
|
22901
23407
|
}
|
|
22902
|
-
function selectionMetadata(session,
|
|
23408
|
+
function selectionMetadata(session, model2, variant) {
|
|
22903
23409
|
return {
|
|
22904
23410
|
...session.metadata,
|
|
22905
23411
|
[SELECTION_METADATA_KEY]: {
|
|
22906
|
-
providerID:
|
|
22907
|
-
modelID:
|
|
23412
|
+
providerID: model2.providerID,
|
|
23413
|
+
modelID: model2.modelID,
|
|
22908
23414
|
...variant ? { variant } : {}
|
|
22909
23415
|
}
|
|
22910
23416
|
};
|
|
@@ -23000,17 +23506,17 @@ async function readProjection(transport, sessionID, providerCatalog, toolOutputL
|
|
|
23000
23506
|
diffsByUserMessageId: new Map(diffEntries),
|
|
23001
23507
|
toolOutputLimit
|
|
23002
23508
|
});
|
|
23003
|
-
const
|
|
23509
|
+
const model2 = nativeModelFromSession(session, messages);
|
|
23004
23510
|
const nativeVariant = nativeVariantFromSession(session, messages);
|
|
23005
|
-
const nativeModel =
|
|
23511
|
+
const nativeModel = model2 ? providerCatalog.all.find(({ id }) => id === model2.providerID)?.models[model2.modelID] : void 0;
|
|
23006
23512
|
const variant = nativeVariant === "default" && nativeModel && !Object.hasOwn(nativeModel.variants ?? {}, "default") ? void 0 : nativeVariant;
|
|
23007
|
-
const usage = projectOpenCodeUsage(openCodeAssistantMessages(session, messages),
|
|
23513
|
+
const usage = projectOpenCodeUsage(openCodeAssistantMessages(session, messages), model2 ? openCodeContextWindow(providerCatalog, model2) : void 0);
|
|
23008
23514
|
return {
|
|
23009
23515
|
session,
|
|
23010
23516
|
messages,
|
|
23011
23517
|
snapshot,
|
|
23012
23518
|
usage,
|
|
23013
|
-
...
|
|
23519
|
+
...model2 ? { model: model2 } : {},
|
|
23014
23520
|
...variant ? { variant } : {}
|
|
23015
23521
|
};
|
|
23016
23522
|
}
|
|
@@ -23136,13 +23642,13 @@ function sameCwd(left, right) {
|
|
|
23136
23642
|
try {
|
|
23137
23643
|
return fs4.realpathSync.native(value);
|
|
23138
23644
|
} catch {
|
|
23139
|
-
return
|
|
23645
|
+
return path9.resolve(value);
|
|
23140
23646
|
}
|
|
23141
23647
|
};
|
|
23142
23648
|
return canonical(left) === canonical(right);
|
|
23143
23649
|
}
|
|
23144
|
-
function sessionState(session, modelCatalog,
|
|
23145
|
-
const effectiveModel =
|
|
23650
|
+
function sessionState(session, modelCatalog, model2, variant, executionPolicy = "default", permissionModeId = OPENCODE_DEFAULT_PERMISSION_MODE_ID) {
|
|
23651
|
+
const effectiveModel = model2 ? encodeOpenCodeModelRef(model2) : void 0;
|
|
23146
23652
|
const modelEntry = effectiveModel ? modelCatalog.models.find(({ ref }) => ref.id === effectiveModel.id) : void 0;
|
|
23147
23653
|
const availableThinkingOptions = modelEntry?.supportedThinkingOptionIds?.map((id) => modelCatalog.thinkingOptions.find((option) => option.id === id)).filter((option) => Boolean(option));
|
|
23148
23654
|
const effectiveThinkingOptionId = encodeOpenCodeVariant(variant);
|
|
@@ -23549,8 +24055,8 @@ var OpenCodeHarnessSession = class {
|
|
|
23549
24055
|
};
|
|
23550
24056
|
}
|
|
23551
24057
|
const modelRef = this.#model ? encodeOpenCodeModelRef(this.#model) : void 0;
|
|
23552
|
-
const
|
|
23553
|
-
if (!
|
|
24058
|
+
const model2 = modelRef ? this.#modelCatalog.models.find(({ ref }) => ref.id === modelRef.id) : void 0;
|
|
24059
|
+
if (!model2?.supportedThinkingOptionIds?.includes(command.thinkingOptionId)) {
|
|
23554
24060
|
return {
|
|
23555
24061
|
ok: false,
|
|
23556
24062
|
error: {
|
|
@@ -24400,14 +24906,14 @@ var OpenCodeAdapter = class {
|
|
|
24400
24906
|
const modelCatalog = normalizeOpenCodeModelCatalog(providers);
|
|
24401
24907
|
let session;
|
|
24402
24908
|
if (input.kind === "create") {
|
|
24403
|
-
const
|
|
24909
|
+
const model2 = input.model ? decodeOpenCodeModelRef(input.model) : void 0;
|
|
24404
24910
|
const variant = input.thinkingOptionId ? decodeOpenCodeVariant(input.thinkingOptionId) : void 0;
|
|
24405
24911
|
if (input.model && !modelCatalog.models.some(({ ref }) => ref.id === input.model?.id)) {
|
|
24406
24912
|
throw new OpenCodeTransportError("protocolError", "Requested OpenCode Model is absent from the connected Provider catalog");
|
|
24407
24913
|
}
|
|
24408
24914
|
const permission = requestedPermissionMode && requestedPermissionMode !== "default" ? requestedPermissionRules(void 0, requestedPermissionMode) : void 0;
|
|
24409
24915
|
session = await transport.createSession({
|
|
24410
|
-
...
|
|
24916
|
+
...model2 ? { model: model2 } : {},
|
|
24411
24917
|
...variant ? { variant } : {},
|
|
24412
24918
|
...permission ? { permission } : {}
|
|
24413
24919
|
});
|
|
@@ -24522,7 +25028,7 @@ import { isDeepStrictEqual as isDeepStrictEqual2 } from "node:util";
|
|
|
24522
25028
|
|
|
24523
25029
|
// dist/v2/state.js
|
|
24524
25030
|
import fs5 from "node:fs";
|
|
24525
|
-
import
|
|
25031
|
+
import path10 from "node:path";
|
|
24526
25032
|
var harnessId = harnessIdSchema.parse("opencode");
|
|
24527
25033
|
function failure(message, code = "nativeFailure") {
|
|
24528
25034
|
return {
|
|
@@ -24542,7 +25048,7 @@ function sameDirectory(left, right) {
|
|
|
24542
25048
|
try {
|
|
24543
25049
|
return fs5.realpathSync(value);
|
|
24544
25050
|
} catch {
|
|
24545
|
-
return
|
|
25051
|
+
return path10.resolve(value);
|
|
24546
25052
|
}
|
|
24547
25053
|
};
|
|
24548
25054
|
return canonical(left) === canonical(right);
|
|
@@ -24564,17 +25070,17 @@ function v2Locator(ref) {
|
|
|
24564
25070
|
return { directory: locator.directory, executionPolicy: locator.executionPolicy };
|
|
24565
25071
|
}
|
|
24566
25072
|
function v2Catalog(models, defaultModel) {
|
|
24567
|
-
const enabled = models.filter((
|
|
24568
|
-
const variants = [...new Set(enabled.flatMap((
|
|
24569
|
-
const ref = (
|
|
25073
|
+
const enabled = models.filter((model2) => model2.enabled);
|
|
25074
|
+
const variants = [...new Set(enabled.flatMap((model2) => model2.variants.map((v) => v.id)))].sort();
|
|
25075
|
+
const ref = (model2) => encodeOpenCodeModelRef({ providerID: model2.providerID, modelID: model2.id });
|
|
24570
25076
|
return harnessModelCatalogSchema.parse({
|
|
24571
|
-
models: enabled.map((
|
|
24572
|
-
ref: ref(
|
|
24573
|
-
label: `${
|
|
24574
|
-
resolvedModelLabel: `${
|
|
25077
|
+
models: enabled.map((model2) => ({
|
|
25078
|
+
ref: ref(model2),
|
|
25079
|
+
label: `${model2.providerID} / ${model2.name}`,
|
|
25080
|
+
resolvedModelLabel: `${model2.providerID}/${model2.id}`,
|
|
24575
25081
|
supportedThinkingOptionIds: [
|
|
24576
25082
|
encodeOpenCodeVariant(void 0),
|
|
24577
|
-
...
|
|
25083
|
+
...model2.variants.map((v) => encodeOpenCodeVariant(v.id))
|
|
24578
25084
|
]
|
|
24579
25085
|
})),
|
|
24580
25086
|
...defaultModel && enabled.some((m) => ref(m).id === ref(defaultModel).id) ? { defaultModel: ref(defaultModel) } : {},
|
|
@@ -24591,12 +25097,12 @@ function v2Permissions(current = [], mode) {
|
|
|
24591
25097
|
return selected === "default" ? rules : [...rules, { action: "*", resource: "*", effect: selected }];
|
|
24592
25098
|
}
|
|
24593
25099
|
function v2State(session, catalog, policy) {
|
|
24594
|
-
const
|
|
24595
|
-
const entry = catalog.models.find((candidate2) => candidate2.ref.id ===
|
|
25100
|
+
const model2 = session.model ? encodeOpenCodeModelRef({ providerID: session.model.providerID, modelID: session.model.id }) : void 0;
|
|
25101
|
+
const entry = catalog.models.find((candidate2) => candidate2.ref.id === model2?.id);
|
|
24596
25102
|
const mode = session.permissions?.findLast((rule) => rule.action === "*" && rule.resource === "*");
|
|
24597
25103
|
return {
|
|
24598
25104
|
nativeRef: v2Ref(session, policy),
|
|
24599
|
-
...
|
|
25105
|
+
...model2 ? { effectiveModel: model2 } : {},
|
|
24600
25106
|
...entry ? {
|
|
24601
25107
|
resolvedModelLabel: entry.resolvedModelLabel ?? entry.label,
|
|
24602
25108
|
availableThinkingOptions: catalog.thinkingOptions.filter((v) => entry.supportedThinkingOptionIds?.includes(v.id)),
|
|
@@ -26457,7 +26963,7 @@ var V2Connection = class {
|
|
|
26457
26963
|
};
|
|
26458
26964
|
|
|
26459
26965
|
// dist/v2/history.js
|
|
26460
|
-
import
|
|
26966
|
+
import path11 from "node:path";
|
|
26461
26967
|
async function readMessages(client2, sessionID) {
|
|
26462
26968
|
const messages = [];
|
|
26463
26969
|
let cursor;
|
|
@@ -26476,11 +26982,12 @@ async function readMessages(client2, sessionID) {
|
|
|
26476
26982
|
} while (cursor);
|
|
26477
26983
|
return messages;
|
|
26478
26984
|
}
|
|
26479
|
-
var contentId = (messageID,
|
|
26985
|
+
var contentId = (messageID, type, ordinal) => hostItemIdSchema.parse(`${messageID}:${type}:${ordinal}`);
|
|
26480
26986
|
function assistantItems2(message, limit) {
|
|
26481
|
-
|
|
26482
|
-
|
|
26987
|
+
const ordinals = { text: 0, reasoning: 0 };
|
|
26988
|
+
return message.content.map((part) => {
|
|
26483
26989
|
if (part.type === "text" || part.type === "reasoning") {
|
|
26990
|
+
const itemId2 = contentId(message.id, part.type, ordinals[part.type]++);
|
|
26484
26991
|
return {
|
|
26485
26992
|
item: {
|
|
26486
26993
|
type: part.type === "text" ? "agentMessage" : "reasoning",
|
|
@@ -26495,7 +27002,7 @@ function assistantItems2(message, limit) {
|
|
|
26495
27002
|
return {
|
|
26496
27003
|
item: {
|
|
26497
27004
|
type: "toolExecution",
|
|
26498
|
-
itemId:
|
|
27005
|
+
itemId: hostItemIdSchema.parse(`${message.id}:tool:${part.id}`),
|
|
26499
27006
|
toolName: part.name,
|
|
26500
27007
|
namespace: "opencode",
|
|
26501
27008
|
arguments: typeof state.input === "string" ? state.input : state.input,
|
|
@@ -26582,9 +27089,9 @@ function fileChanges(session, turn, diffs) {
|
|
|
26582
27089
|
if (!diffs.length)
|
|
26583
27090
|
return void 0;
|
|
26584
27091
|
const changes = diffs.map((diff) => {
|
|
26585
|
-
const absolute =
|
|
26586
|
-
const relative =
|
|
26587
|
-
if (relative.startsWith(`..${
|
|
27092
|
+
const absolute = path11.resolve(session.location.directory, diff.file);
|
|
27093
|
+
const relative = path11.relative(session.location.directory, absolute);
|
|
27094
|
+
if (relative.startsWith(`..${path11.sep}`) || relative === ".." || path11.isAbsolute(relative))
|
|
26588
27095
|
throw new Error("OpenCode v2 diff escaped the Session directory");
|
|
26589
27096
|
return {
|
|
26590
27097
|
path: absolute,
|
|
@@ -26627,7 +27134,7 @@ function terminalItemOutcome(outcome) {
|
|
|
26627
27134
|
|
|
26628
27135
|
// dist/v2/session-import.js
|
|
26629
27136
|
import fs6 from "node:fs";
|
|
26630
|
-
import
|
|
27137
|
+
import path12 from "node:path";
|
|
26631
27138
|
|
|
26632
27139
|
// ../../harness-adapter/dist/session-import.js
|
|
26633
27140
|
function sessionImportTitle(value, maxLength = HARNESS_SESSION_IMPORT_TITLE_MAX_LENGTH) {
|
|
@@ -26660,7 +27167,7 @@ function sessionImportCandidate(input) {
|
|
|
26660
27167
|
var PAGE_SIZE = 200;
|
|
26661
27168
|
var MAX_PAGES = 1e4;
|
|
26662
27169
|
function existingDirectory(directory) {
|
|
26663
|
-
if (typeof directory !== "string" || !
|
|
27170
|
+
if (typeof directory !== "string" || !path12.isAbsolute(directory))
|
|
26664
27171
|
return null;
|
|
26665
27172
|
try {
|
|
26666
27173
|
return fs6.statSync(directory).isDirectory() ? directory : null;
|
|
@@ -26860,6 +27367,14 @@ function v2Capabilities(catalog) {
|
|
|
26860
27367
|
history: { fork: true, forkAcrossCwd: false, rollbackLastTurn: true }
|
|
26861
27368
|
};
|
|
26862
27369
|
}
|
|
27370
|
+
var FIRST_OUTPUT_EVENTS = /* @__PURE__ */ new Set([
|
|
27371
|
+
"session.reasoning.started",
|
|
27372
|
+
"session.reasoning.delta",
|
|
27373
|
+
"session.text.started",
|
|
27374
|
+
"session.text.delta",
|
|
27375
|
+
"session.tool.input.started",
|
|
27376
|
+
"session.tool.input.delta"
|
|
27377
|
+
]);
|
|
26863
27378
|
var V2Session = class {
|
|
26864
27379
|
client;
|
|
26865
27380
|
connection;
|
|
@@ -26883,6 +27398,11 @@ var V2Session = class {
|
|
|
26883
27398
|
#reconciling;
|
|
26884
27399
|
#timer;
|
|
26885
27400
|
#configuring = false;
|
|
27401
|
+
#cacheHitRatePercent;
|
|
27402
|
+
/** Assistant messages already published as usage requests. */
|
|
27403
|
+
#meteredMessages = /* @__PURE__ */ new Set();
|
|
27404
|
+
/** Adapter receive time of each assistant message's first reasoning, text or tool input. */
|
|
27405
|
+
#firstOutputAt = /* @__PURE__ */ new Map();
|
|
26886
27406
|
constructor(client2, connection, info, catalog, policy, limit, onClosed) {
|
|
26887
27407
|
this.client = client2;
|
|
26888
27408
|
this.connection = connection;
|
|
@@ -26927,6 +27447,7 @@ var V2Session = class {
|
|
|
26927
27447
|
}
|
|
26928
27448
|
})();
|
|
26929
27449
|
});
|
|
27450
|
+
await this.#replayUsage();
|
|
26930
27451
|
this.#timer = setInterval(() => {
|
|
26931
27452
|
void this.#refresh();
|
|
26932
27453
|
}, 400);
|
|
@@ -26995,22 +27516,22 @@ var V2Session = class {
|
|
|
26995
27516
|
permissions: v2Permissions(this.info.permissions, command.permissionModeId)
|
|
26996
27517
|
});
|
|
26997
27518
|
} else {
|
|
26998
|
-
let
|
|
27519
|
+
let model2 = this.info.model;
|
|
26999
27520
|
if (command.type === "model.select") {
|
|
27000
27521
|
if (!this.catalog.models.some((m) => m.ref.id === command.model.id))
|
|
27001
27522
|
throw new Error("OpenCode Model is not available");
|
|
27002
27523
|
const decoded = decodeOpenCodeModelRef(command.model);
|
|
27003
|
-
|
|
27524
|
+
model2 = { providerID: decoded.providerID, id: decoded.modelID };
|
|
27004
27525
|
} else {
|
|
27005
|
-
if (!
|
|
27526
|
+
if (!model2)
|
|
27006
27527
|
throw new Error("Select a Model before a Thinking option");
|
|
27007
27528
|
const state = v2State(this.info, this.catalog, this.policy);
|
|
27008
27529
|
if (!state.availableThinkingOptions?.some((v) => v.id === command.thinkingOptionId))
|
|
27009
27530
|
throw new Error("Thinking option is unavailable for this Model");
|
|
27010
27531
|
const variant = decodeOpenCodeVariant(command.thinkingOptionId);
|
|
27011
|
-
|
|
27532
|
+
model2 = { providerID: model2.providerID, id: model2.id, ...variant ? { variant } : {} };
|
|
27012
27533
|
}
|
|
27013
|
-
await this.client.session.switchModel({ sessionID: this.info.id, model });
|
|
27534
|
+
await this.client.session.switchModel({ sessionID: this.info.id, model: model2 });
|
|
27014
27535
|
}
|
|
27015
27536
|
this.info = await this.client.session.get({ sessionID: this.info.id });
|
|
27016
27537
|
this.#emit({
|
|
@@ -27094,11 +27615,14 @@ var V2Session = class {
|
|
|
27094
27615
|
const active = this.#active;
|
|
27095
27616
|
if (!active || !("data" in event) || !("sessionID" in event.data) || event.data.sessionID !== this.info.id)
|
|
27096
27617
|
return;
|
|
27618
|
+
if (FIRST_OUTPUT_EVENTS.has(event.type) && "assistantMessageID" in event.data && typeof event.data.assistantMessageID === "string" && !this.#firstOutputAt.has(event.data.assistantMessageID))
|
|
27619
|
+
this.#firstOutputAt.set(event.data.assistantMessageID, Date.now());
|
|
27097
27620
|
if (event.type === "session.step.started")
|
|
27098
27621
|
active.assistants.add(event.data.assistantMessageID);
|
|
27099
27622
|
if ((event.type === "session.text.delta" || event.type === "session.reasoning.delta") && active.assistants.has(event.data.assistantMessageID)) {
|
|
27100
|
-
const
|
|
27101
|
-
const
|
|
27623
|
+
const contentType = event.type === "session.text.delta" ? "text" : "reasoning";
|
|
27624
|
+
const itemId2 = contentId(event.data.assistantMessageID, contentType, event.data.ordinal);
|
|
27625
|
+
const type = contentType === "text" ? "agentMessage" : "reasoning";
|
|
27102
27626
|
const previous = active.transient.get(itemId2);
|
|
27103
27627
|
const item = {
|
|
27104
27628
|
type,
|
|
@@ -27112,6 +27636,56 @@ var V2Session = class {
|
|
|
27112
27636
|
if (!event.type.endsWith(".delta"))
|
|
27113
27637
|
void this.#refresh();
|
|
27114
27638
|
}
|
|
27639
|
+
/** Publishes assistant messages not yet metered; returns false when one is unusable. */
|
|
27640
|
+
#meterUsage(messages, historical) {
|
|
27641
|
+
let usable = true;
|
|
27642
|
+
const previousCacheHitRate = this.#cacheHitRatePercent;
|
|
27643
|
+
for (const message of messages) {
|
|
27644
|
+
let request;
|
|
27645
|
+
try {
|
|
27646
|
+
request = v2UsageRequest(message, historical, this.#firstOutputAt.get(message.id));
|
|
27647
|
+
} catch {
|
|
27648
|
+
this.#cacheHitRatePercent = void 0;
|
|
27649
|
+
if (this.#meteredMessages.has(message.id))
|
|
27650
|
+
continue;
|
|
27651
|
+
this.#meteredMessages.add(message.id);
|
|
27652
|
+
if (!historical)
|
|
27653
|
+
this.#emit({ type: "usage.history", complete: false });
|
|
27654
|
+
usable = false;
|
|
27655
|
+
continue;
|
|
27656
|
+
}
|
|
27657
|
+
if (!request)
|
|
27658
|
+
continue;
|
|
27659
|
+
this.#cacheHitRatePercent = request.inputTokens > 0 && request.cachedInputTokens !== void 0 ? request.cachedInputTokens / request.inputTokens * 100 : void 0;
|
|
27660
|
+
if (this.#meteredMessages.has(message.id))
|
|
27661
|
+
continue;
|
|
27662
|
+
this.#meteredMessages.add(message.id);
|
|
27663
|
+
this.#firstOutputAt.delete(message.id);
|
|
27664
|
+
this.#emit({ type: "usage.request", request });
|
|
27665
|
+
}
|
|
27666
|
+
if (this.#cacheHitRatePercent !== previousCacheHitRate)
|
|
27667
|
+
this.#emit({
|
|
27668
|
+
type: "session.usage.changed",
|
|
27669
|
+
usage: this.#usage()
|
|
27670
|
+
});
|
|
27671
|
+
return usable;
|
|
27672
|
+
}
|
|
27673
|
+
#usage() {
|
|
27674
|
+
const usage = v2Usage(this.info);
|
|
27675
|
+
if (this.#cacheHitRatePercent !== void 0)
|
|
27676
|
+
usage.cacheHitRatePercent = this.#cacheHitRatePercent;
|
|
27677
|
+
return usage;
|
|
27678
|
+
}
|
|
27679
|
+
/** Replays every metered request of the native history, then declares it complete. */
|
|
27680
|
+
async #replayUsage() {
|
|
27681
|
+
let complete = false;
|
|
27682
|
+
try {
|
|
27683
|
+
complete = this.#meterUsage(await readMessages(this.client, this.info.id), true);
|
|
27684
|
+
} catch {
|
|
27685
|
+
complete = false;
|
|
27686
|
+
}
|
|
27687
|
+
this.#emit({ type: "usage.history", complete });
|
|
27688
|
+
}
|
|
27115
27689
|
#refresh() {
|
|
27116
27690
|
if (this.#closed || !this.#active?.admitted)
|
|
27117
27691
|
return Promise.resolve();
|
|
@@ -27130,6 +27704,7 @@ var V2Session = class {
|
|
|
27130
27704
|
if (this.#active !== active || this.#closed)
|
|
27131
27705
|
return;
|
|
27132
27706
|
this.info = info;
|
|
27707
|
+
this.#meterUsage(messages, false);
|
|
27133
27708
|
const turns = snapshot.turns.filter((t) => !active.baseline.has(t.nativeTurnRef.nativeTurnKey));
|
|
27134
27709
|
if (turns.length > 1)
|
|
27135
27710
|
throw new Error("Concurrent native prompts cannot be assigned to one Host Turn");
|
|
@@ -27226,7 +27801,7 @@ var V2Session = class {
|
|
|
27226
27801
|
});
|
|
27227
27802
|
this.#emit({
|
|
27228
27803
|
type: "session.usage.changed",
|
|
27229
|
-
usage:
|
|
27804
|
+
usage: this.#usage(),
|
|
27230
27805
|
observedForTurnId: active.turnId
|
|
27231
27806
|
});
|
|
27232
27807
|
this.#active = void 0;
|
|
@@ -27422,10 +27997,10 @@ var V2Adapter = class {
|
|
|
27422
27997
|
const catalog = await this.#catalog(client2, input.cwd);
|
|
27423
27998
|
let info;
|
|
27424
27999
|
if (input.kind === "create") {
|
|
27425
|
-
const
|
|
28000
|
+
const model2 = selectedModel(input, catalog);
|
|
27426
28001
|
info = await client2.session.create({
|
|
27427
28002
|
location: { directory: input.cwd },
|
|
27428
|
-
...
|
|
28003
|
+
...model2 ? { model: model2 } : {},
|
|
27429
28004
|
permissions: v2Permissions([], input.permissionModeId ?? harnessPermissionModeIdSchema.parse(policy === "unattended-full-access" ? "allow" : "default"))
|
|
27430
28005
|
});
|
|
27431
28006
|
created = info.id;
|
|
@@ -27442,19 +28017,19 @@ var V2Adapter = class {
|
|
|
27442
28017
|
if (input.kind !== "resume") {
|
|
27443
28018
|
const parent = info;
|
|
27444
28019
|
const turns = source.snapshot.turns;
|
|
27445
|
-
let
|
|
28020
|
+
let count2;
|
|
27446
28021
|
if (input.kind === "rollbackLastTurn") {
|
|
27447
28022
|
if (!turns.length)
|
|
27448
28023
|
throw new Error("OpenCode history is empty");
|
|
27449
|
-
|
|
28024
|
+
count2 = turns.length - 1;
|
|
27450
28025
|
} else {
|
|
27451
28026
|
if (input.checkpoint.harnessId !== harnessId || input.checkpoint.nativeSessionId !== info.id)
|
|
27452
28027
|
throw new Error("Checkpoint belongs to another Session");
|
|
27453
|
-
|
|
27454
|
-
if (!
|
|
28028
|
+
count2 = turns.findIndex((turn) => turn.checkpoint?.checkpointId === input.checkpoint.checkpointId) + 1;
|
|
28029
|
+
if (!count2 || JSON.stringify(turns[count2 - 1]?.checkpoint) !== JSON.stringify(input.checkpoint))
|
|
27455
28030
|
throw new Error("OpenCode checkpoint does not match native history");
|
|
27456
28031
|
}
|
|
27457
|
-
const before = turns[
|
|
28032
|
+
const before = turns[count2]?.nativeTurnRef.nativeTurnKey;
|
|
27458
28033
|
info = await client2.session.fork({ sessionID: parent.id, ...before ? { before } : {} });
|
|
27459
28034
|
if (info.id === parent.id)
|
|
27460
28035
|
throw new Error("OpenCode fork returned its source Session");
|
|
@@ -27469,7 +28044,7 @@ var V2Adapter = class {
|
|
|
27469
28044
|
await client2.session.switchModel({ sessionID: info.id, model: parent.model });
|
|
27470
28045
|
info = await client2.session.get({ sessionID: info.id });
|
|
27471
28046
|
const derived = await readHistory(client2, info, this.options.toolOutputLimit ?? 64e3);
|
|
27472
|
-
if (historyContent(derived.snapshot, false) !== historyContent({ turns: turns.slice(0,
|
|
28047
|
+
if (historyContent(derived.snapshot, false) !== historyContent({ turns: turns.slice(0, count2) }, false))
|
|
27473
28048
|
throw new Error("OpenCode fork did not preserve the exact history prefix");
|
|
27474
28049
|
if (!isDeepStrictEqual2(info.permissions ?? [], parent.permissions ?? []) || !isDeepStrictEqual2(info.model, parent.model))
|
|
27475
28050
|
throw new Error("OpenCode fork did not preserve the current configuration");
|
|
@@ -27518,14 +28093,14 @@ function selectedModel(input, catalog) {
|
|
|
27518
28093
|
throw new Error("Thinking selection requires a Model");
|
|
27519
28094
|
return void 0;
|
|
27520
28095
|
}
|
|
27521
|
-
const entry = catalog.models.find((
|
|
28096
|
+
const entry = catalog.models.find((model3) => model3.ref.id === selected.id);
|
|
27522
28097
|
if (!entry)
|
|
27523
28098
|
throw new Error("OpenCode Model is not available");
|
|
27524
28099
|
if (input.thinkingOptionId && !entry.supportedThinkingOptionIds?.includes(input.thinkingOptionId))
|
|
27525
28100
|
throw new Error("OpenCode Thinking option is not available for this Model");
|
|
27526
|
-
const
|
|
28101
|
+
const model2 = decodeOpenCodeModelRef(selected);
|
|
27527
28102
|
const variant = input.thinkingOptionId ? decodeOpenCodeVariant(input.thinkingOptionId) : void 0;
|
|
27528
|
-
return { providerID:
|
|
28103
|
+
return { providerID: model2.providerID, id: model2.modelID, ...variant ? { variant } : {} };
|
|
27529
28104
|
}
|
|
27530
28105
|
function historyContent(snapshot, identities = true) {
|
|
27531
28106
|
return JSON.stringify(snapshot.turns.map((turn) => ({
|
|
@@ -27549,9 +28124,11 @@ var OpenCodeAdapter2 = class {
|
|
|
27549
28124
|
commandCatalog = openCodeCommandCatalog;
|
|
27550
28125
|
#adapters = /* @__PURE__ */ new Set();
|
|
27551
28126
|
#closed = false;
|
|
28127
|
+
usageStatistics;
|
|
27552
28128
|
constructor(options = {}, dependencies) {
|
|
27553
28129
|
this.options = options;
|
|
27554
28130
|
this.dependencies = dependencies;
|
|
28131
|
+
this.usageStatistics = createOpenCodeUsageStatistics(options.environment ?? process.env);
|
|
27555
28132
|
}
|
|
27556
28133
|
async #select(environment, input) {
|
|
27557
28134
|
if (this.#closed)
|
|
@@ -27661,7 +28238,7 @@ function normalize(error51) {
|
|
|
27661
28238
|
// dist/installation.js
|
|
27662
28239
|
import { realpath as realpath2 } from "node:fs/promises";
|
|
27663
28240
|
import { homedir as homedir3 } from "node:os";
|
|
27664
|
-
import
|
|
28241
|
+
import path13 from "node:path";
|
|
27665
28242
|
function createOpenCodeInstallation(environment, command) {
|
|
27666
28243
|
let update;
|
|
27667
28244
|
return createInstallationManager({
|
|
@@ -27682,8 +28259,8 @@ function createOpenCodeInstallation(environment, command) {
|
|
|
27682
28259
|
const release = JSON.parse(await fetchInstallationText("https://api.github.com/repos/anomalyco/opencode/releases/latest"));
|
|
27683
28260
|
latestVersion = installationVersion(release.tag_name);
|
|
27684
28261
|
const home = environment.HOME ?? environment.USERPROFILE ?? homedir3();
|
|
27685
|
-
const standard =
|
|
27686
|
-
canUpdate = process.platform !== "win32" &&
|
|
28262
|
+
const standard = path13.join(home, ".opencode", "bin", process.platform === "win32" ? "opencode.exe" : "opencode");
|
|
28263
|
+
canUpdate = process.platform !== "win32" && path13.resolve(executable) === standard && await realpath2(executable) === standard;
|
|
27687
28264
|
update = async (version2) => {
|
|
27688
28265
|
await runInstallationCommand(executable, ["upgrade", version2, "--method", "curl"], environment, 3e5);
|
|
27689
28266
|
};
|