@liberseek/boft-cli-win32-arm64 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.exe +0 -0
- package/libexec/boft-node-repl.exe +0 -0
- package/libexec/boft-shim.exe +0 -0
- package/libexec/boft-updater.exe +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
|
@@ -5,9 +5,66 @@ var __export = (target, all) => {
|
|
|
5
5
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
// dist/
|
|
9
|
-
import
|
|
10
|
-
import
|
|
8
|
+
// dist/usage-statistics.js
|
|
9
|
+
import os from "node:os";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { lstat } from "node:fs/promises";
|
|
12
|
+
|
|
13
|
+
// ../../harness-adapter/dist/usage-statistics.js
|
|
14
|
+
var MAX_SESSION_ID_LENGTH = 512;
|
|
15
|
+
var MAX_CWD_LENGTH = 4096;
|
|
16
|
+
var MAX_SESSION_TITLE_LENGTH = 200;
|
|
17
|
+
function usageSessionTitle(value) {
|
|
18
|
+
if (typeof value !== "string")
|
|
19
|
+
return void 0;
|
|
20
|
+
const normalized = value.replaceAll("\0", "").replaceAll(/\s+/gu, " ").trim();
|
|
21
|
+
if (!normalized)
|
|
22
|
+
return void 0;
|
|
23
|
+
if (normalized.length <= MAX_SESSION_TITLE_LENGTH)
|
|
24
|
+
return normalized;
|
|
25
|
+
const characters = [...normalized];
|
|
26
|
+
if (characters.length <= MAX_SESSION_TITLE_LENGTH)
|
|
27
|
+
return normalized;
|
|
28
|
+
return `${characters.slice(0, MAX_SESSION_TITLE_LENGTH - 1).join("").trimEnd()}…`;
|
|
29
|
+
}
|
|
30
|
+
function sessionIdOk(value) {
|
|
31
|
+
return typeof value === "string" && value.length > 0 && value.length <= MAX_SESSION_ID_LENGTH;
|
|
32
|
+
}
|
|
33
|
+
function cwdOk(value) {
|
|
34
|
+
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("\\\\"));
|
|
35
|
+
}
|
|
36
|
+
function withUsageSession(entry, session) {
|
|
37
|
+
const sessionId = sessionIdOk(session.sessionId) ? session.sessionId : void 0;
|
|
38
|
+
const cwd = cwdOk(session.cwd) ? session.cwd : void 0;
|
|
39
|
+
const sessionTitle = sessionId !== void 0 ? usageSessionTitle(session.title) : void 0;
|
|
40
|
+
if (sessionId === void 0 && cwd === void 0)
|
|
41
|
+
return entry;
|
|
42
|
+
return {
|
|
43
|
+
...entry,
|
|
44
|
+
...sessionId !== void 0 ? { sessionId } : {},
|
|
45
|
+
...cwd !== void 0 ? { cwd } : {},
|
|
46
|
+
...sessionTitle !== void 0 ? { sessionTitle } : {}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function usageEntryFromRequest(request, occurredAtMs) {
|
|
50
|
+
if (!Number.isSafeInteger(occurredAtMs) || occurredAtMs <= 0)
|
|
51
|
+
return null;
|
|
52
|
+
return {
|
|
53
|
+
id: request.requestId,
|
|
54
|
+
occurredAtMs,
|
|
55
|
+
...request.model !== void 0 ? { model: request.model } : {},
|
|
56
|
+
inputTokens: request.inputTokens,
|
|
57
|
+
...request.cachedInputTokens !== void 0 ? { cachedInputTokens: request.cachedInputTokens } : {},
|
|
58
|
+
...request.cacheWriteInputTokens !== void 0 ? { cacheWriteInputTokens: request.cacheWriteInputTokens } : {},
|
|
59
|
+
...request.cacheWrite1hInputTokens !== void 0 ? { cacheWrite1hInputTokens: request.cacheWrite1hInputTokens } : {},
|
|
60
|
+
outputTokens: request.outputTokens,
|
|
61
|
+
...request.reasoningOutputTokens !== void 0 ? { reasoningOutputTokens: request.reasoningOutputTokens } : {}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function nativeTimeMs(value) {
|
|
65
|
+
const time3 = typeof value === "number" ? value : typeof value === "string" ? Date.parse(value) : Number.NaN;
|
|
66
|
+
return Number.isFinite(time3) && time3 > 0 ? Math.floor(time3) : null;
|
|
67
|
+
}
|
|
11
68
|
|
|
12
69
|
// ../../../node_modules/zod/v4/classic/external.js
|
|
13
70
|
var external_exports = {};
|
|
@@ -775,10 +832,10 @@ function mergeDefs(...defs) {
|
|
|
775
832
|
function cloneDef(schema) {
|
|
776
833
|
return mergeDefs(schema._zod.def);
|
|
777
834
|
}
|
|
778
|
-
function getElementAtPath(obj,
|
|
779
|
-
if (!
|
|
835
|
+
function getElementAtPath(obj, path7) {
|
|
836
|
+
if (!path7)
|
|
780
837
|
return obj;
|
|
781
|
-
return
|
|
838
|
+
return path7.reduce((acc, key) => acc?.[key], obj);
|
|
782
839
|
}
|
|
783
840
|
function promiseAllObject(promisesObj) {
|
|
784
841
|
const keys = Object.keys(promisesObj);
|
|
@@ -1187,11 +1244,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
1187
1244
|
}
|
|
1188
1245
|
return false;
|
|
1189
1246
|
}
|
|
1190
|
-
function prefixIssues(
|
|
1247
|
+
function prefixIssues(path7, issues) {
|
|
1191
1248
|
return issues.map((iss) => {
|
|
1192
1249
|
var _a3;
|
|
1193
1250
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
1194
|
-
iss.path.unshift(
|
|
1251
|
+
iss.path.unshift(path7);
|
|
1195
1252
|
return iss;
|
|
1196
1253
|
});
|
|
1197
1254
|
}
|
|
@@ -1338,16 +1395,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1338
1395
|
}
|
|
1339
1396
|
function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
1340
1397
|
const fieldErrors = { _errors: [] };
|
|
1341
|
-
const processError = (error52,
|
|
1398
|
+
const processError = (error52, path7 = []) => {
|
|
1342
1399
|
for (const issue2 of error52.issues) {
|
|
1343
1400
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1344
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1401
|
+
issue2.errors.map((issues) => processError({ issues }, [...path7, ...issue2.path]));
|
|
1345
1402
|
} else if (issue2.code === "invalid_key") {
|
|
1346
|
-
processError({ issues: issue2.issues }, [...
|
|
1403
|
+
processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
|
|
1347
1404
|
} else if (issue2.code === "invalid_element") {
|
|
1348
|
-
processError({ issues: issue2.issues }, [...
|
|
1405
|
+
processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
|
|
1349
1406
|
} else {
|
|
1350
|
-
const fullpath = [...
|
|
1407
|
+
const fullpath = [...path7, ...issue2.path];
|
|
1351
1408
|
if (fullpath.length === 0) {
|
|
1352
1409
|
fieldErrors._errors.push(mapper(issue2));
|
|
1353
1410
|
} else {
|
|
@@ -1374,17 +1431,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1374
1431
|
}
|
|
1375
1432
|
function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
1376
1433
|
const result = { errors: [] };
|
|
1377
|
-
const processError = (error52,
|
|
1434
|
+
const processError = (error52, path7 = []) => {
|
|
1378
1435
|
var _a3, _b;
|
|
1379
1436
|
for (const issue2 of error52.issues) {
|
|
1380
1437
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1381
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1438
|
+
issue2.errors.map((issues) => processError({ issues }, [...path7, ...issue2.path]));
|
|
1382
1439
|
} else if (issue2.code === "invalid_key") {
|
|
1383
|
-
processError({ issues: issue2.issues }, [...
|
|
1440
|
+
processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
|
|
1384
1441
|
} else if (issue2.code === "invalid_element") {
|
|
1385
|
-
processError({ issues: issue2.issues }, [...
|
|
1442
|
+
processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
|
|
1386
1443
|
} else {
|
|
1387
|
-
const fullpath = [...
|
|
1444
|
+
const fullpath = [...path7, ...issue2.path];
|
|
1388
1445
|
if (fullpath.length === 0) {
|
|
1389
1446
|
result.errors.push(mapper(issue2));
|
|
1390
1447
|
continue;
|
|
@@ -1416,8 +1473,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1416
1473
|
}
|
|
1417
1474
|
function toDotPath(_path) {
|
|
1418
1475
|
const segs = [];
|
|
1419
|
-
const
|
|
1420
|
-
for (const seg of
|
|
1476
|
+
const path7 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
1477
|
+
for (const seg of path7) {
|
|
1421
1478
|
if (typeof seg === "number")
|
|
1422
1479
|
segs.push(`[${seg}]`);
|
|
1423
1480
|
else if (typeof seg === "symbol")
|
|
@@ -4645,8 +4702,8 @@ function az_default() {
|
|
|
4645
4702
|
}
|
|
4646
4703
|
|
|
4647
4704
|
// ../../../node_modules/zod/v4/locales/be.js
|
|
4648
|
-
function getBelarusianPlural(
|
|
4649
|
-
const absCount = Math.abs(
|
|
4705
|
+
function getBelarusianPlural(count2, one, few, many) {
|
|
4706
|
+
const absCount = Math.abs(count2);
|
|
4650
4707
|
const lastDigit = absCount % 10;
|
|
4651
4708
|
const lastTwoDigits = absCount % 100;
|
|
4652
4709
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -6724,8 +6781,8 @@ function hu_default() {
|
|
|
6724
6781
|
}
|
|
6725
6782
|
|
|
6726
6783
|
// ../../../node_modules/zod/v4/locales/hy.js
|
|
6727
|
-
function getArmenianPlural(
|
|
6728
|
-
return Math.abs(
|
|
6784
|
+
function getArmenianPlural(count2, one, many) {
|
|
6785
|
+
return Math.abs(count2) === 1 ? one : many;
|
|
6729
6786
|
}
|
|
6730
6787
|
function withDefiniteArticle(word) {
|
|
6731
6788
|
if (!word)
|
|
@@ -8853,8 +8910,8 @@ function ro_default() {
|
|
|
8853
8910
|
}
|
|
8854
8911
|
|
|
8855
8912
|
// ../../../node_modules/zod/v4/locales/ru.js
|
|
8856
|
-
function getRussianPlural(
|
|
8857
|
-
const absCount = Math.abs(
|
|
8913
|
+
function getRussianPlural(count2, one, few, many) {
|
|
8914
|
+
const absCount = Math.abs(count2);
|
|
8858
8915
|
const lastDigit = absCount % 10;
|
|
8859
8916
|
const lastTwoDigits = absCount % 100;
|
|
8860
8917
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -14109,13 +14166,13 @@ function resolveRef(ref, ctx) {
|
|
|
14109
14166
|
if (!ref.startsWith("#")) {
|
|
14110
14167
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
14111
14168
|
}
|
|
14112
|
-
const
|
|
14113
|
-
if (
|
|
14169
|
+
const path7 = ref.slice(1).split("/").filter(Boolean);
|
|
14170
|
+
if (path7.length === 0) {
|
|
14114
14171
|
return ctx.rootSchema;
|
|
14115
14172
|
}
|
|
14116
14173
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
14117
|
-
if (
|
|
14118
|
-
const key =
|
|
14174
|
+
if (path7[0] === defsKey) {
|
|
14175
|
+
const key = path7[1];
|
|
14119
14176
|
if (!key || !ctx.defs[key]) {
|
|
14120
14177
|
throw new Error(`Reference not found: ${ref}`);
|
|
14121
14178
|
}
|
|
@@ -14317,8 +14374,8 @@ function convertBaseSchema(schema, ctx) {
|
|
|
14317
14374
|
break;
|
|
14318
14375
|
}
|
|
14319
14376
|
const objectSchema2 = z.object(shape).passthrough();
|
|
14320
|
-
const
|
|
14321
|
-
zodSchema = z.intersection(objectSchema2,
|
|
14377
|
+
const recordSchema3 = z.looseRecord(keySchema, valueSchema);
|
|
14378
|
+
zodSchema = z.intersection(objectSchema2, recordSchema3);
|
|
14322
14379
|
break;
|
|
14323
14380
|
}
|
|
14324
14381
|
if (schema.patternProperties) {
|
|
@@ -14523,6 +14580,143 @@ function date4(params) {
|
|
|
14523
14580
|
// ../../../node_modules/zod/v4/classic/external.js
|
|
14524
14581
|
config(en_default());
|
|
14525
14582
|
|
|
14583
|
+
// dist/protocol.js
|
|
14584
|
+
var recordSchema = external_exports.record(external_exports.string(), external_exports.unknown());
|
|
14585
|
+
var nativeModelSchema = external_exports.object({
|
|
14586
|
+
providerId: external_exports.string().min(1),
|
|
14587
|
+
modelId: external_exports.string().min(1),
|
|
14588
|
+
variant: external_exports.string().optional(),
|
|
14589
|
+
options: external_exports.object({ reasoningLevel: external_exports.string().min(1).optional() }).optional()
|
|
14590
|
+
});
|
|
14591
|
+
var levelSchema = external_exports.object({ value: external_exports.string(), label: external_exports.string() });
|
|
14592
|
+
var modelSchema = external_exports.object({
|
|
14593
|
+
ref: nativeModelSchema,
|
|
14594
|
+
label: external_exports.string(),
|
|
14595
|
+
providerLabel: external_exports.string().optional(),
|
|
14596
|
+
disabledReason: external_exports.string().optional(),
|
|
14597
|
+
contextWindow: external_exports.number().int().positive().optional(),
|
|
14598
|
+
reasoning: external_exports.object({
|
|
14599
|
+
enabled: external_exports.boolean().optional(),
|
|
14600
|
+
levels: external_exports.array(levelSchema),
|
|
14601
|
+
defaultLevel: external_exports.string().optional()
|
|
14602
|
+
}).transform((reasoning) => ({
|
|
14603
|
+
...reasoning,
|
|
14604
|
+
enabled: reasoning.enabled ?? reasoning.levels.length > 0
|
|
14605
|
+
})).optional()
|
|
14606
|
+
}).transform(({ providerLabel, ...model2 }) => {
|
|
14607
|
+
const provider = model2.ref.providerId === "account:bigmodel-individual-coding-plan" ? "BigModel" : model2.ref.providerId === "account:zai-individual-coding-plan" ? "Z.AI" : providerLabel;
|
|
14608
|
+
return { ...model2, label: provider ? `${provider} / ${model2.label}` : model2.label };
|
|
14609
|
+
});
|
|
14610
|
+
var settingsSchema = external_exports.object({
|
|
14611
|
+
model: external_exports.object({
|
|
14612
|
+
current: nativeModelSchema.optional(),
|
|
14613
|
+
available: external_exports.array(modelSchema),
|
|
14614
|
+
lastUsed: nativeModelSchema.optional()
|
|
14615
|
+
}),
|
|
14616
|
+
thoughtLevel: external_exports.object({
|
|
14617
|
+
enabled: external_exports.boolean(),
|
|
14618
|
+
current: external_exports.string().optional(),
|
|
14619
|
+
defaultLevel: external_exports.string().optional(),
|
|
14620
|
+
available: external_exports.array(levelSchema)
|
|
14621
|
+
}),
|
|
14622
|
+
mode: external_exports.object({ current: external_exports.enum(["build", "edit", "plan", "yolo", "auto"]) })
|
|
14623
|
+
});
|
|
14624
|
+
var workspaceSchema = external_exports.object({
|
|
14625
|
+
workspacePath: external_exports.string().min(1),
|
|
14626
|
+
workspaceKey: external_exports.string().min(1),
|
|
14627
|
+
workspaceIdentity: external_exports.string().optional()
|
|
14628
|
+
});
|
|
14629
|
+
var summarySchema = external_exports.object({
|
|
14630
|
+
sessionId: external_exports.string().min(1),
|
|
14631
|
+
workspace: workspaceSchema,
|
|
14632
|
+
title: external_exports.string(),
|
|
14633
|
+
status: external_exports.string(),
|
|
14634
|
+
mode: external_exports.string(),
|
|
14635
|
+
createdAt: external_exports.number(),
|
|
14636
|
+
updatedAt: external_exports.number(),
|
|
14637
|
+
parentSessionId: external_exports.string().optional(),
|
|
14638
|
+
sessionKind: external_exports.string()
|
|
14639
|
+
});
|
|
14640
|
+
var partSchema = external_exports.object({
|
|
14641
|
+
partId: external_exports.string().min(1),
|
|
14642
|
+
messageId: external_exports.string(),
|
|
14643
|
+
sessionId: external_exports.string(),
|
|
14644
|
+
type: external_exports.string()
|
|
14645
|
+
}).catchall(external_exports.unknown());
|
|
14646
|
+
var messageSchema = external_exports.object({
|
|
14647
|
+
info: external_exports.object({
|
|
14648
|
+
messageId: external_exports.string().min(1),
|
|
14649
|
+
sessionId: external_exports.string(),
|
|
14650
|
+
role: external_exports.enum(["user", "assistant"]),
|
|
14651
|
+
parentMessageId: external_exports.string().optional(),
|
|
14652
|
+
time: external_exports.object({ created: external_exports.number(), completed: external_exports.number().optional() }),
|
|
14653
|
+
model: nativeModelSchema.optional(),
|
|
14654
|
+
// Keep telemetry unvalidated here: bad usage must not break history or the Turn.
|
|
14655
|
+
tokens: external_exports.unknown().optional(),
|
|
14656
|
+
finish: external_exports.string().optional(),
|
|
14657
|
+
error: recordSchema.optional(),
|
|
14658
|
+
synthetic: external_exports.boolean().optional(),
|
|
14659
|
+
visibility: external_exports.string().optional(),
|
|
14660
|
+
semantics: recordSchema.optional()
|
|
14661
|
+
}),
|
|
14662
|
+
parts: external_exports.array(partSchema)
|
|
14663
|
+
});
|
|
14664
|
+
var snapshotSchema = external_exports.object({
|
|
14665
|
+
protocol: external_exports.object({ name: external_exports.literal("ZCode Protocol"), version: external_exports.literal(1) }),
|
|
14666
|
+
session: summarySchema,
|
|
14667
|
+
settings: settingsSchema,
|
|
14668
|
+
projection: external_exports.object({
|
|
14669
|
+
status: external_exports.string(),
|
|
14670
|
+
contextUsed: external_exports.number(),
|
|
14671
|
+
contextWindow: external_exports.number(),
|
|
14672
|
+
currentTurnId: external_exports.string().optional(),
|
|
14673
|
+
backgroundJobs: external_exports.array(external_exports.unknown()).optional(),
|
|
14674
|
+
target: recordSchema.nullable().optional()
|
|
14675
|
+
}),
|
|
14676
|
+
messages: external_exports.array(messageSchema),
|
|
14677
|
+
runtime: recordSchema,
|
|
14678
|
+
target: recordSchema.nullable().optional(),
|
|
14679
|
+
slashCommands: external_exports.array(external_exports.object({ name: external_exports.string(), description: external_exports.string(), source: external_exports.string().optional() })).optional()
|
|
14680
|
+
});
|
|
14681
|
+
var workspaceStateSchema = external_exports.object({
|
|
14682
|
+
workspace: workspaceSchema,
|
|
14683
|
+
settings: settingsSchema
|
|
14684
|
+
});
|
|
14685
|
+
var eventSchema = external_exports.object({
|
|
14686
|
+
eventId: external_exports.string(),
|
|
14687
|
+
sessionId: external_exports.string(),
|
|
14688
|
+
turnId: external_exports.string().optional(),
|
|
14689
|
+
seq: external_exports.number(),
|
|
14690
|
+
timestamp: external_exports.number(),
|
|
14691
|
+
type: external_exports.string(),
|
|
14692
|
+
payload: recordSchema.optional()
|
|
14693
|
+
});
|
|
14694
|
+
var runtimeUsageSchema = external_exports.object({
|
|
14695
|
+
contextUsage: external_exports.object({
|
|
14696
|
+
used: external_exports.number().int().nonnegative(),
|
|
14697
|
+
cache: external_exports.object({
|
|
14698
|
+
totalCacheReadTokens: external_exports.number().int().nonnegative(),
|
|
14699
|
+
totalCacheWriteTokens: external_exports.number().int().nonnegative(),
|
|
14700
|
+
latestHitRate: external_exports.number().min(0).max(1).nullish()
|
|
14701
|
+
}).nullish()
|
|
14702
|
+
})
|
|
14703
|
+
});
|
|
14704
|
+
function record2(value) {
|
|
14705
|
+
return recordSchema.safeParse(value).data ?? {};
|
|
14706
|
+
}
|
|
14707
|
+
function text(value) {
|
|
14708
|
+
return typeof value === "string" ? value : "";
|
|
14709
|
+
}
|
|
14710
|
+
|
|
14711
|
+
// ../../shared-contracts/dist/delegation-read.js
|
|
14712
|
+
var REMOTE_THREAD_REPLY_MAX_BYTES = 16 * 1024 * 1024;
|
|
14713
|
+
var delegationReadParamsSchema = external_exports.strictObject({
|
|
14714
|
+
threadId: external_exports.string().min(1).max(1024),
|
|
14715
|
+
view: external_exports.enum(["result", "messages"]),
|
|
14716
|
+
cursor: external_exports.string().min(1).max(8192).optional(),
|
|
14717
|
+
limit: external_exports.number().int().min(1).max(100).optional()
|
|
14718
|
+
});
|
|
14719
|
+
|
|
14526
14720
|
// ../../shared-contracts/dist/credential-imports.js
|
|
14527
14721
|
var credentialSourceSchema = external_exports.object({
|
|
14528
14722
|
id: external_exports.string().min(1).max(256),
|
|
@@ -14593,6 +14787,160 @@ var harnessDisplaySetSchema = external_exports.strictObject({
|
|
|
14593
14787
|
initializeOnly: external_exports.boolean().optional()
|
|
14594
14788
|
});
|
|
14595
14789
|
|
|
14790
|
+
// ../../shared-contracts/dist/model-price-overrides.js
|
|
14791
|
+
var usdPerMillionTokens = external_exports.number().finite().nonnegative();
|
|
14792
|
+
var modelPriceOverrideSchema = external_exports.strictObject({
|
|
14793
|
+
input: usdPerMillionTokens,
|
|
14794
|
+
output: usdPerMillionTokens,
|
|
14795
|
+
cacheRead: usdPerMillionTokens.optional(),
|
|
14796
|
+
cacheWrite: usdPerMillionTokens.optional(),
|
|
14797
|
+
cacheWrite1h: usdPerMillionTokens.optional()
|
|
14798
|
+
});
|
|
14799
|
+
var modelPriceKeySchema = external_exports.string().max(512).refine((key) => key.trim() === key && key.length > 0, "Model ID is required");
|
|
14800
|
+
var modelPriceOverridesSchema = external_exports.strictObject({
|
|
14801
|
+
/** Absolute path of the Host's `pricing.json`. */
|
|
14802
|
+
path: external_exports.string(),
|
|
14803
|
+
entries: external_exports.array(external_exports.strictObject({ key: external_exports.string(), price: modelPriceOverrideSchema })),
|
|
14804
|
+
/** Why the existing file is unusable; the Host then ignores it and refuses to overwrite it. */
|
|
14805
|
+
error: external_exports.string().nullable()
|
|
14806
|
+
});
|
|
14807
|
+
var modelPriceOverridesGetSchema = external_exports.strictObject({});
|
|
14808
|
+
var modelPriceOverridesSetSchema = external_exports.strictObject({
|
|
14809
|
+
key: modelPriceKeySchema,
|
|
14810
|
+
price: modelPriceOverrideSchema.nullable(),
|
|
14811
|
+
previousKey: modelPriceKeySchema.optional()
|
|
14812
|
+
});
|
|
14813
|
+
var modelPriceDefaultParamsSchema = external_exports.strictObject({
|
|
14814
|
+
model: modelPriceKeySchema
|
|
14815
|
+
});
|
|
14816
|
+
var modelPriceSuggestionSchema = external_exports.strictObject({
|
|
14817
|
+
/** Verified from catalog canonical links, not inferred from names or equal prices. */
|
|
14818
|
+
official: external_exports.boolean().optional(),
|
|
14819
|
+
canonicalModelId: external_exports.string().min(1).optional(),
|
|
14820
|
+
provider: external_exports.string().min(1).max(512),
|
|
14821
|
+
model: external_exports.string().min(1).max(512),
|
|
14822
|
+
price: modelPriceOverrideSchema
|
|
14823
|
+
});
|
|
14824
|
+
var modelPriceDefaultResultSchema = external_exports.strictObject({
|
|
14825
|
+
price: modelPriceOverrideSchema.nullable(),
|
|
14826
|
+
/** Local catalog suggestions only; never used automatically for pricing. */
|
|
14827
|
+
suggestions: external_exports.array(modelPriceSuggestionSchema).max(6).optional()
|
|
14828
|
+
});
|
|
14829
|
+
|
|
14830
|
+
// ../../shared-contracts/dist/usage-statistics.js
|
|
14831
|
+
var USAGE_STATISTICS_RANGES = ["today", "7d", "30d", "90d", "all"];
|
|
14832
|
+
var count = external_exports.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
|
|
14833
|
+
var localDate = external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/u);
|
|
14834
|
+
var harness = external_exports.string().min(1).max(128);
|
|
14835
|
+
var model = external_exports.string().min(1).max(512);
|
|
14836
|
+
var project = external_exports.string().min(1).max(4096);
|
|
14837
|
+
var usageStatisticsParamsSchema = external_exports.strictObject({
|
|
14838
|
+
range: external_exports.enum(USAGE_STATISTICS_RANGES),
|
|
14839
|
+
harness: harness.optional(),
|
|
14840
|
+
model: model.nullable().optional(),
|
|
14841
|
+
project: project.nullable().optional(),
|
|
14842
|
+
/** One local date inside the range. */
|
|
14843
|
+
date: localDate.optional()
|
|
14844
|
+
});
|
|
14845
|
+
var usageStatisticsTotalsSchema = external_exports.strictObject({
|
|
14846
|
+
requests: count,
|
|
14847
|
+
inputTokens: count,
|
|
14848
|
+
cachedInputTokens: count,
|
|
14849
|
+
cacheWriteInputTokens: count,
|
|
14850
|
+
cacheKnownInputTokens: count,
|
|
14851
|
+
outputTokens: count,
|
|
14852
|
+
reasoningOutputTokens: count,
|
|
14853
|
+
/** USD at the public price, summed over the priced requests only. */
|
|
14854
|
+
costUsd: external_exports.number().finite().min(0),
|
|
14855
|
+
/** Requests without a price (or the cache data the price needs); not in `costUsd`. */
|
|
14856
|
+
unpricedRequests: count,
|
|
14857
|
+
/**
|
|
14858
|
+
* Requests whose storage gave no token counts: counted as requests, with neither tokens nor
|
|
14859
|
+
* cost, and not as unpriced.
|
|
14860
|
+
*/
|
|
14861
|
+
unmeteredRequests: count
|
|
14862
|
+
});
|
|
14863
|
+
var totals = usageStatisticsTotalsSchema.shape;
|
|
14864
|
+
var usageStatisticsSessionSchema = external_exports.strictObject({
|
|
14865
|
+
harness,
|
|
14866
|
+
sessionId: external_exports.string().min(1).max(512),
|
|
14867
|
+
project: project.nullable(),
|
|
14868
|
+
/** Persisted Desktop title for a mapped Session, otherwise its native name; may be absent. */
|
|
14869
|
+
title: external_exports.string().min(1).max(200).optional(),
|
|
14870
|
+
/** Models the session used, most requests first. */
|
|
14871
|
+
models: external_exports.array(model).max(16),
|
|
14872
|
+
firstAtMs: count,
|
|
14873
|
+
lastAtMs: count,
|
|
14874
|
+
...totals
|
|
14875
|
+
});
|
|
14876
|
+
var usageStatisticsResultSchema = external_exports.strictObject({
|
|
14877
|
+
range: external_exports.enum(USAGE_STATISTICS_RANGES),
|
|
14878
|
+
/** First local date of the range; null for all time. */
|
|
14879
|
+
from: localDate.nullable(),
|
|
14880
|
+
to: localDate,
|
|
14881
|
+
/** The filters these figures apply, echoed so a late answer to older filters is recognised. */
|
|
14882
|
+
filters: external_exports.strictObject({
|
|
14883
|
+
harness: harness.nullable(),
|
|
14884
|
+
model: model.nullable(),
|
|
14885
|
+
unknownModel: external_exports.boolean(),
|
|
14886
|
+
project: project.nullable(),
|
|
14887
|
+
unknownProject: external_exports.boolean(),
|
|
14888
|
+
date: localDate.nullable()
|
|
14889
|
+
}),
|
|
14890
|
+
/** Reading of native storage: incomplete while the first read, or a refresh, is under way. */
|
|
14891
|
+
reading: external_exports.strictObject({ complete: external_exports.boolean(), sources: count, read: count }),
|
|
14892
|
+
/** Harnesses whose storage could not be read; their part is missing, the rest is complete. */
|
|
14893
|
+
failures: external_exports.array(external_exports.strictObject({ harness, message: external_exports.string().max(2048) })).max(256),
|
|
14894
|
+
/** Every value seen in the range, ignoring the filters, to choose filters from. */
|
|
14895
|
+
options: external_exports.strictObject({
|
|
14896
|
+
harnesses: external_exports.array(harness).max(256),
|
|
14897
|
+
models: external_exports.array(model.nullable()).max(4096),
|
|
14898
|
+
projects: external_exports.array(project.nullable()).max(4096)
|
|
14899
|
+
}),
|
|
14900
|
+
/** Current display metadata, scoped by Harness. Never a pricing or filter identity.
|
|
14901
|
+
* Optional for older Hosts; missing/conflicting labels fall back to the native model ID.
|
|
14902
|
+
*/
|
|
14903
|
+
modelLabels: external_exports.array(external_exports.strictObject({ harness, model, label: model })).max(4096).optional(),
|
|
14904
|
+
/** Native credits, all filters applied, never combined across Harnesses or treated as USD.
|
|
14905
|
+
* Only groups with at least one reported value appear; reportedRequests exposes partial data.
|
|
14906
|
+
*/
|
|
14907
|
+
credits: external_exports.array(external_exports.strictObject({
|
|
14908
|
+
harness,
|
|
14909
|
+
model: model.nullable(),
|
|
14910
|
+
credits: external_exports.number().finite().min(0),
|
|
14911
|
+
reportedRequests: count,
|
|
14912
|
+
requests: count
|
|
14913
|
+
})).max(4096).optional(),
|
|
14914
|
+
/** All filters applied. */
|
|
14915
|
+
totals: usageStatisticsTotalsSchema,
|
|
14916
|
+
/** Each date and Harness of the range: every filter except the day. */
|
|
14917
|
+
daily: external_exports.array(external_exports.strictObject({ date: localDate, harness, ...totals })).max(2e5),
|
|
14918
|
+
/** Local weekday (0 = Sunday) and hour, all filters applied. */
|
|
14919
|
+
hourly: external_exports.array(external_exports.strictObject({
|
|
14920
|
+
weekday: external_exports.number().int().min(0).max(6),
|
|
14921
|
+
hour: external_exports.number().int().min(0).max(23),
|
|
14922
|
+
...totals
|
|
14923
|
+
})).max(168),
|
|
14924
|
+
byHarness: external_exports.array(external_exports.strictObject({ harness, ...totals })).max(256),
|
|
14925
|
+
byModel: external_exports.array(external_exports.strictObject({
|
|
14926
|
+
model: model.nullable(),
|
|
14927
|
+
...totals,
|
|
14928
|
+
/** Requests priced by what the Harness recorded they cost, not by a price list. */
|
|
14929
|
+
harnessPricedRequests: count
|
|
14930
|
+
})).max(4096),
|
|
14931
|
+
byProject: external_exports.array(external_exports.strictObject({ project: project.nullable(), ...totals })).max(4096),
|
|
14932
|
+
/**
|
|
14933
|
+
* The sessions that spent the most, by cost and by tokens without cache, all filters applied;
|
|
14934
|
+
* requests without a native session are not listed here but count everywhere else.
|
|
14935
|
+
*/
|
|
14936
|
+
sessions: external_exports.array(usageStatisticsSessionSchema).max(100),
|
|
14937
|
+
/**
|
|
14938
|
+
* The sessions last active in the range, newest first, all filters applied. Optional for older
|
|
14939
|
+
* Hosts; missing is treated as no list rather than no sessions.
|
|
14940
|
+
*/
|
|
14941
|
+
recentSessions: external_exports.array(usageStatisticsSessionSchema).max(100).optional()
|
|
14942
|
+
});
|
|
14943
|
+
|
|
14596
14944
|
// ../../shared-contracts/dist/ids.js
|
|
14597
14945
|
var opaqueIdSchema = external_exports.string().refine((value) => value.trim().length > 0, {
|
|
14598
14946
|
message: "Identifier must not be empty or whitespace"
|
|
@@ -14614,13 +14962,40 @@ var HARNESS_PLUGIN_LIMIT = 128;
|
|
|
14614
14962
|
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);
|
|
14615
14963
|
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");
|
|
14616
14964
|
var documentationUrlSchema = external_exports.url().refine((value) => /^https:\/\/[^/?#@]+(?:[/?#]|$)/iu.test(value), "Plugin documentation links must be credential-free HTTPS URLs");
|
|
14965
|
+
var localizedTextSchema = external_exports.object({ en: external_exports.string().max(4096), "zh-CN": external_exports.string().max(4096).optional() }).strict();
|
|
14966
|
+
var harnessInstallationGuideSchema = external_exports.object({
|
|
14967
|
+
commands: external_exports.array(external_exports.object({ terminal: external_exports.string().max(256), command: external_exports.string().max(4096) }).strict()).max(8),
|
|
14968
|
+
before: localizedTextSchema.optional(),
|
|
14969
|
+
after: localizedTextSchema.optional(),
|
|
14970
|
+
downloads: external_exports.array(external_exports.object({ label: external_exports.string().max(128), url: documentationUrlSchema }).strict()).max(8).optional()
|
|
14971
|
+
}).strict();
|
|
14617
14972
|
var pluginPresentationShape = {
|
|
14618
14973
|
id: harnessPluginIdSchema,
|
|
14619
14974
|
name: external_exports.string().trim().min(1).max(128),
|
|
14620
14975
|
version: external_exports.string().min(1).max(128),
|
|
14976
|
+
/** Capability-only plugin; omitted for existing session-capable plugins. */
|
|
14977
|
+
kind: external_exports.literal("usage").optional(),
|
|
14978
|
+
/** Original image styling or bounded vector paths; never arbitrary CSS/SVG markup. */
|
|
14979
|
+
iconStyle: external_exports.object({
|
|
14980
|
+
vector: external_exports.object({
|
|
14981
|
+
viewBox: external_exports.string().max(128).regex(/^-?\d+(?:\.\d+)?(?: +-?\d+(?:\.\d+)?){3}$/u),
|
|
14982
|
+
color: external_exports.string().regex(/^(?:currentColor|#[a-f0-9]{6})$/iu),
|
|
14983
|
+
paths: external_exports.array(external_exports.object({
|
|
14984
|
+
d: external_exports.string().min(1).max(32768).regex(/^[MmLlHhVvCcSsQqTtAaZz\d.,+eE\s-]+$/u),
|
|
14985
|
+
fillRule: external_exports.enum(["evenodd", "nonzero"]).optional(),
|
|
14986
|
+
fill: external_exports.string().regex(/^(?:currentColor|#[a-f0-9]{6})$/iu).optional()
|
|
14987
|
+
}).strict()).min(1).max(32)
|
|
14988
|
+
}).strict().optional(),
|
|
14989
|
+
background: external_exports.string().regex(/^#[a-f0-9]{6}$/iu).optional(),
|
|
14990
|
+
borderRadius: external_exports.number().min(0).max(50).optional(),
|
|
14991
|
+
paddingRatio: external_exports.number().min(0).max(0.25).optional()
|
|
14992
|
+
}).strict().optional(),
|
|
14993
|
+
installation: harnessInstallationGuideSchema.optional(),
|
|
14994
|
+
notice: localizedTextSchema.optional(),
|
|
14621
14995
|
/** The factory accepts a persisted local entrypoint through its construction context. */
|
|
14622
14996
|
launchCommand: external_exports.literal(true).optional(),
|
|
14623
14997
|
links: external_exports.object({
|
|
14998
|
+
website: documentationUrlSchema.optional(),
|
|
14624
14999
|
documentation: documentationUrlSchema.optional(),
|
|
14625
15000
|
installation: documentationUrlSchema.optional()
|
|
14626
15001
|
}).strict().optional()
|
|
@@ -14697,6 +15072,10 @@ var CONSOLE_HOST_METHODS = Object.freeze([
|
|
|
14697
15072
|
"codexhost/account/list",
|
|
14698
15073
|
"codexhost/account/refresh",
|
|
14699
15074
|
"codexhost/account/usage/inspect",
|
|
15075
|
+
"codexhost/usage/model-prices/get",
|
|
15076
|
+
"codexhost/usage/model-prices/set",
|
|
15077
|
+
"codexhost/usage/model-prices/default",
|
|
15078
|
+
"codexhost/usage/statistics/get",
|
|
14700
15079
|
"codexhost/update/check",
|
|
14701
15080
|
"codexhost/update/start",
|
|
14702
15081
|
"codexhost/update/status"
|
|
@@ -14761,6 +15140,7 @@ var threadUsageSnapshotSchema = external_exports.object({
|
|
|
14761
15140
|
cacheWriteInputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
14762
15141
|
outputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
14763
15142
|
outputTokensPerSecond: finiteNonNegativeNumberSchema.optional(),
|
|
15143
|
+
apiOutputTokensPerSecond: finiteNonNegativeNumberSchema.optional(),
|
|
14764
15144
|
reasoningOutputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
14765
15145
|
totalTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
14766
15146
|
totalCostUsd: finiteNonNegativeNumberSchema.optional(),
|
|
@@ -14772,7 +15152,11 @@ var threadUsageSnapshotSchema = external_exports.object({
|
|
|
14772
15152
|
planFiveHourUsedPercent: cacheHitRatePercentSchema.optional(),
|
|
14773
15153
|
planFiveHourResetsAtUnix: nonNegativeSafeIntegerSchema.optional(),
|
|
14774
15154
|
planSevenDayUsedPercent: cacheHitRatePercentSchema.optional(),
|
|
14775
|
-
planSevenDayResetsAtUnix: nonNegativeSafeIntegerSchema.optional()
|
|
15155
|
+
planSevenDayResetsAtUnix: nonNegativeSafeIntegerSchema.optional(),
|
|
15156
|
+
sessionCacheHitRatePercent: cacheHitRatePercentSchema.optional(),
|
|
15157
|
+
timeToFirstOutputMs: nonNegativeSafeIntegerSchema.optional(),
|
|
15158
|
+
costSource: external_exports.enum(["publicPrice", "native"]).optional(),
|
|
15159
|
+
unpricedModels: external_exports.array(external_exports.string().min(1)).min(1).optional()
|
|
14776
15160
|
}).strict().superRefine((usage, context) => {
|
|
14777
15161
|
if (Object.keys(usage).length === 0) {
|
|
14778
15162
|
context.addIssue({ code: "custom", message: "Thread Usage must contain a reliable field" });
|
|
@@ -14793,6 +15177,20 @@ var threadUsageSnapshotSchema = external_exports.object({
|
|
|
14793
15177
|
path: ["contextWindowTokens"]
|
|
14794
15178
|
});
|
|
14795
15179
|
}
|
|
15180
|
+
if (usage.costSource !== void 0 && usage.totalCostUsd === void 0) {
|
|
15181
|
+
context.addIssue({
|
|
15182
|
+
code: "custom",
|
|
15183
|
+
message: "Thread Usage costSource must be provided with totalCostUsd",
|
|
15184
|
+
path: ["costSource"]
|
|
15185
|
+
});
|
|
15186
|
+
}
|
|
15187
|
+
if (usage.unpricedModels !== void 0 && usage.costSource !== "publicPrice") {
|
|
15188
|
+
context.addIssue({
|
|
15189
|
+
code: "custom",
|
|
15190
|
+
message: "Thread Usage unpricedModels must be provided with a publicPrice cost",
|
|
15191
|
+
path: ["unpricedModels"]
|
|
15192
|
+
});
|
|
15193
|
+
}
|
|
14796
15194
|
if (usage.planFiveHourResetsAtUnix !== void 0 && usage.planFiveHourUsedPercent === void 0) {
|
|
14797
15195
|
context.addIssue({
|
|
14798
15196
|
code: "custom",
|
|
@@ -15062,27 +15460,27 @@ var harnessModelCatalogSchema = external_exports.object({
|
|
|
15062
15460
|
}).strict().superRefine((catalog, context) => {
|
|
15063
15461
|
const refs = /* @__PURE__ */ new Set();
|
|
15064
15462
|
const thinkingIds = new Set(catalog.thinkingOptions.map(({ id }) => id));
|
|
15065
|
-
for (const [index,
|
|
15066
|
-
if (refs.has(
|
|
15463
|
+
for (const [index, model2] of catalog.models.entries()) {
|
|
15464
|
+
if (refs.has(model2.ref.id)) {
|
|
15067
15465
|
context.addIssue({
|
|
15068
15466
|
code: "custom",
|
|
15069
15467
|
message: "Model Catalog refs must be unique",
|
|
15070
15468
|
path: ["models", index, "ref", "id"]
|
|
15071
15469
|
});
|
|
15072
15470
|
}
|
|
15073
|
-
refs.add(
|
|
15074
|
-
if (
|
|
15075
|
-
if (refs.has(
|
|
15471
|
+
refs.add(model2.ref.id);
|
|
15472
|
+
if (model2.fastModel) {
|
|
15473
|
+
if (refs.has(model2.fastModel.id) || catalog.models.some((entry) => entry.ref.id === model2.fastModel?.id)) {
|
|
15076
15474
|
context.addIssue({
|
|
15077
15475
|
code: "custom",
|
|
15078
15476
|
message: "Fast Model refs must be distinct and unique",
|
|
15079
15477
|
path: ["models", index, "fastModel"]
|
|
15080
15478
|
});
|
|
15081
15479
|
}
|
|
15082
|
-
refs.add(
|
|
15480
|
+
refs.add(model2.fastModel.id);
|
|
15083
15481
|
}
|
|
15084
15482
|
const supportedThinkingIds = /* @__PURE__ */ new Set();
|
|
15085
|
-
for (const [optionIndex, optionId] of (
|
|
15483
|
+
for (const [optionIndex, optionId] of (model2.supportedThinkingOptionIds ?? []).entries()) {
|
|
15086
15484
|
if (supportedThinkingIds.has(optionId)) {
|
|
15087
15485
|
context.addIssue({
|
|
15088
15486
|
code: "custom",
|
|
@@ -15676,6 +16074,11 @@ var codexSshDraftSchema = external_exports.strictObject({
|
|
|
15676
16074
|
});
|
|
15677
16075
|
var remoteConnectionsRequestSchema = external_exports.discriminatedUnion("action", [
|
|
15678
16076
|
external_exports.strictObject({ action: external_exports.literal("list") }),
|
|
16077
|
+
external_exports.strictObject({
|
|
16078
|
+
action: external_exports.literal("read-thread"),
|
|
16079
|
+
hostId: hostId.refine((id) => id !== "local"),
|
|
16080
|
+
input: delegationReadParamsSchema
|
|
16081
|
+
}),
|
|
15679
16082
|
external_exports.strictObject({
|
|
15680
16083
|
action: external_exports.literal("save"),
|
|
15681
16084
|
draft: codexSshDraftSchema,
|
|
@@ -15699,10 +16102,6 @@ var remoteConnectionsReplySchema = external_exports.union([
|
|
|
15699
16102
|
// ../../shared-contracts/dist/index.js
|
|
15700
16103
|
var workspaceContractVersionSchema = external_exports.literal(WORKSPACE_CONTRACT_VERSION);
|
|
15701
16104
|
|
|
15702
|
-
// dist/transport.js
|
|
15703
|
-
import { spawn } from "node:child_process";
|
|
15704
|
-
import { randomUUID } from "node:crypto";
|
|
15705
|
-
|
|
15706
16105
|
// ../../harness-adapter/dist/approval.js
|
|
15707
16106
|
function invalidRequest(message) {
|
|
15708
16107
|
return { code: "invalidRequest", message, retryable: false };
|
|
@@ -15811,7 +16210,6 @@ var tokenFields = [
|
|
|
15811
16210
|
"cachedInputTokens",
|
|
15812
16211
|
"cacheWriteInputTokens",
|
|
15813
16212
|
"outputTokens",
|
|
15814
|
-
"outputTokensPerSecond",
|
|
15815
16213
|
"reasoningOutputTokens",
|
|
15816
16214
|
"totalTokens",
|
|
15817
16215
|
"contextWindowTokens",
|
|
@@ -15819,10 +16217,12 @@ var tokenFields = [
|
|
|
15819
16217
|
];
|
|
15820
16218
|
var safeIntegerFields = [
|
|
15821
16219
|
"planFiveHourResetsAtUnix",
|
|
15822
|
-
"planSevenDayResetsAtUnix"
|
|
16220
|
+
"planSevenDayResetsAtUnix",
|
|
16221
|
+
"timeToFirstOutputMs"
|
|
15823
16222
|
];
|
|
15824
16223
|
var percentFields = [
|
|
15825
16224
|
"cacheHitRatePercent",
|
|
16225
|
+
"sessionCacheHitRatePercent",
|
|
15826
16226
|
"planFiveHourUsedPercent",
|
|
15827
16227
|
"planSevenDayUsedPercent"
|
|
15828
16228
|
];
|
|
@@ -15830,9 +16230,14 @@ var usageFields = /* @__PURE__ */ new Set([
|
|
|
15830
16230
|
...tokenFields,
|
|
15831
16231
|
...safeIntegerFields,
|
|
15832
16232
|
...percentFields,
|
|
16233
|
+
"sessionCacheUsage",
|
|
15833
16234
|
"totalCostUsd",
|
|
15834
16235
|
"totalCredits",
|
|
15835
|
-
"contextUsagePercent"
|
|
16236
|
+
"contextUsagePercent",
|
|
16237
|
+
"outputTokensPerSecond",
|
|
16238
|
+
"apiOutputTokensPerSecond",
|
|
16239
|
+
"costSource",
|
|
16240
|
+
"unpricedModels"
|
|
15836
16241
|
]);
|
|
15837
16242
|
function isRecord(value) {
|
|
15838
16243
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -15848,7 +16253,11 @@ function parseHostUsage(value) {
|
|
|
15848
16253
|
throw new Error(`Harness Usage contains unknown field '${key}'`);
|
|
15849
16254
|
}
|
|
15850
16255
|
}
|
|
15851
|
-
for (const field2 of [
|
|
16256
|
+
for (const field2 of [
|
|
16257
|
+
"totalCredits",
|
|
16258
|
+
"contextUsagePercent",
|
|
16259
|
+
"apiOutputTokensPerSecond"
|
|
16260
|
+
]) {
|
|
15852
16261
|
const candidate = value[field2];
|
|
15853
16262
|
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
|
|
15854
16263
|
throw new Error(`Harness Usage '${field2}' must be a finite non-negative number`);
|
|
@@ -15884,6 +16293,12 @@ function parseHostUsage(value) {
|
|
|
15884
16293
|
throw new Error(`Harness Usage '${field2}' must be between 0 and 100`);
|
|
15885
16294
|
}
|
|
15886
16295
|
}
|
|
16296
|
+
if (value.sessionCacheUsage !== void 0) {
|
|
16297
|
+
const totals2 = value.sessionCacheUsage;
|
|
16298
|
+
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) {
|
|
16299
|
+
throw new Error("Harness Usage 'sessionCacheUsage' must contain complete bounded token totals");
|
|
16300
|
+
}
|
|
16301
|
+
}
|
|
15887
16302
|
const hasContextUsed = value.contextUsedTokens !== void 0;
|
|
15888
16303
|
const hasContextWindow = value.contextWindowTokens !== void 0;
|
|
15889
16304
|
if (hasContextUsed !== hasContextWindow) {
|
|
@@ -15898,164 +16313,363 @@ function parseHostUsage(value) {
|
|
|
15898
16313
|
if (value.planSevenDayResetsAtUnix !== void 0 && value.planSevenDayUsedPercent === void 0) {
|
|
15899
16314
|
throw new Error("Harness Usage 'planSevenDayResetsAtUnix' must be provided with 'planSevenDayUsedPercent'");
|
|
15900
16315
|
}
|
|
16316
|
+
if (value.costSource !== void 0) {
|
|
16317
|
+
if (value.costSource !== "publicPrice" && value.costSource !== "native") {
|
|
16318
|
+
throw new Error("Harness Usage 'costSource' must be 'publicPrice' or 'native'");
|
|
16319
|
+
}
|
|
16320
|
+
if (value.totalCostUsd === void 0) {
|
|
16321
|
+
throw new Error("Harness Usage 'costSource' must be provided with 'totalCostUsd'");
|
|
16322
|
+
}
|
|
16323
|
+
}
|
|
16324
|
+
if (value.unpricedModels !== void 0) {
|
|
16325
|
+
const models = value.unpricedModels;
|
|
16326
|
+
if (!Array.isArray(models) || models.length === 0 || !models.every((model2) => typeof model2 === "string" && model2.length > 0)) {
|
|
16327
|
+
throw new Error("Harness Usage 'unpricedModels' must be a non-empty list of Model IDs");
|
|
16328
|
+
}
|
|
16329
|
+
if (value.costSource !== "publicPrice") {
|
|
16330
|
+
throw new Error("Harness Usage 'unpricedModels' must be provided with a 'publicPrice' cost");
|
|
16331
|
+
}
|
|
16332
|
+
return { ...value, unpricedModels: [...models] };
|
|
16333
|
+
}
|
|
15901
16334
|
return { ...value };
|
|
15902
16335
|
}
|
|
15903
|
-
|
|
15904
|
-
|
|
15905
|
-
|
|
15906
|
-
|
|
15907
|
-
|
|
15908
|
-
|
|
15909
|
-
|
|
15910
|
-
|
|
15911
|
-
|
|
15912
|
-
|
|
15913
|
-
|
|
16336
|
+
var requestTokenFields = [
|
|
16337
|
+
"inputTokens",
|
|
16338
|
+
"cachedInputTokens",
|
|
16339
|
+
"cacheWriteInputTokens",
|
|
16340
|
+
"cacheWrite1hInputTokens",
|
|
16341
|
+
"outputTokens",
|
|
16342
|
+
"reasoningOutputTokens",
|
|
16343
|
+
"startedAtMs",
|
|
16344
|
+
"completedAtMs"
|
|
16345
|
+
];
|
|
16346
|
+
var requestFields = /* @__PURE__ */ new Set([
|
|
16347
|
+
...requestTokenFields,
|
|
16348
|
+
"requestId",
|
|
16349
|
+
"historical",
|
|
16350
|
+
"model",
|
|
16351
|
+
"provider"
|
|
16352
|
+
]);
|
|
16353
|
+
function parseHostUsageRequest(value) {
|
|
16354
|
+
if (!isRecord(value))
|
|
16355
|
+
throw new Error("Harness Usage request must be an object");
|
|
16356
|
+
for (const key of Object.keys(value)) {
|
|
16357
|
+
if (!requestFields.has(key)) {
|
|
16358
|
+
throw new Error(`Harness Usage request contains unknown field '${key}'`);
|
|
16359
|
+
}
|
|
15914
16360
|
}
|
|
15915
|
-
|
|
15916
|
-
|
|
15917
|
-
|
|
16361
|
+
if (typeof value.requestId !== "string" || value.requestId.length === 0) {
|
|
16362
|
+
throw new Error("Harness Usage request 'requestId' must be a non-empty string");
|
|
16363
|
+
}
|
|
16364
|
+
for (const field2 of ["model", "provider"]) {
|
|
16365
|
+
const candidate = value[field2];
|
|
16366
|
+
if (candidate !== void 0 && (typeof candidate !== "string" || candidate.length === 0)) {
|
|
16367
|
+
throw new Error(`Harness Usage request '${field2}' must be a non-empty string`);
|
|
16368
|
+
}
|
|
16369
|
+
}
|
|
16370
|
+
if (value.historical !== void 0 && typeof value.historical !== "boolean") {
|
|
16371
|
+
throw new Error("Harness Usage request 'historical' must be a boolean");
|
|
16372
|
+
}
|
|
16373
|
+
for (const field2 of requestTokenFields) {
|
|
16374
|
+
const candidate = value[field2];
|
|
16375
|
+
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
|
|
16376
|
+
throw new Error(`Harness Usage request '${field2}' must be a non-negative safe integer`);
|
|
16377
|
+
}
|
|
16378
|
+
}
|
|
16379
|
+
if (value.inputTokens === void 0 || value.outputTokens === void 0) {
|
|
16380
|
+
throw new Error("Harness Usage request must contain 'inputTokens' and 'outputTokens'");
|
|
16381
|
+
}
|
|
16382
|
+
const request = value;
|
|
16383
|
+
if ((request.cachedInputTokens ?? 0) + (request.cacheWriteInputTokens ?? 0) > request.inputTokens) {
|
|
16384
|
+
throw new Error("Harness Usage request cache Tokens must not exceed 'inputTokens'");
|
|
16385
|
+
}
|
|
16386
|
+
if ((request.reasoningOutputTokens ?? 0) > request.outputTokens) {
|
|
16387
|
+
throw new Error("Harness Usage request 'reasoningOutputTokens' must not exceed 'outputTokens'");
|
|
16388
|
+
}
|
|
16389
|
+
if (request.cacheWrite1hInputTokens !== void 0 && request.cacheWrite1hInputTokens > (request.cacheWriteInputTokens ?? -1)) {
|
|
16390
|
+
throw new Error("Harness Usage request 'cacheWrite1hInputTokens' must not exceed 'cacheWriteInputTokens'");
|
|
16391
|
+
}
|
|
16392
|
+
if (request.startedAtMs === void 0 !== (request.completedAtMs === void 0)) {
|
|
16393
|
+
throw new Error("Harness Usage request timing fields must be provided together");
|
|
16394
|
+
}
|
|
16395
|
+
if (request.startedAtMs !== void 0 && request.completedAtMs !== void 0 && request.completedAtMs < request.startedAtMs) {
|
|
16396
|
+
throw new Error("Harness Usage request 'completedAtMs' must not precede 'startedAtMs'");
|
|
16397
|
+
}
|
|
16398
|
+
return { ...request };
|
|
15918
16399
|
}
|
|
15919
|
-
|
|
15920
|
-
|
|
16400
|
+
|
|
16401
|
+
// dist/usage.js
|
|
16402
|
+
function requestTokens(id, model2, value) {
|
|
16403
|
+
const tokens = record2(value), cache = record2(tokens.cache);
|
|
16404
|
+
const request = parseHostUsageRequest({
|
|
16405
|
+
requestId: id,
|
|
16406
|
+
...model2 ? { model: model2 } : {},
|
|
16407
|
+
inputTokens: tokens.input,
|
|
16408
|
+
outputTokens: tokens.output,
|
|
16409
|
+
...cache.read !== void 0 ? { cachedInputTokens: cache.read } : {},
|
|
16410
|
+
...cache.write !== void 0 ? { cacheWriteInputTokens: cache.write } : {},
|
|
16411
|
+
...tokens.reasoning !== void 0 ? { reasoningOutputTokens: tokens.reasoning } : {}
|
|
16412
|
+
});
|
|
16413
|
+
if (!Number.isSafeInteger(tokens.total) || tokens.total !== request.inputTokens + request.outputTokens)
|
|
16414
|
+
throw new Error("ZCode request token convention is unknown");
|
|
16415
|
+
return request;
|
|
16416
|
+
}
|
|
16417
|
+
function zcodeUsageRecord(message) {
|
|
16418
|
+
const info = message.info;
|
|
16419
|
+
if (info.role !== "assistant" || info.synthetic === true || info.semantics?.origin === "system")
|
|
16420
|
+
return { kind: "none" };
|
|
16421
|
+
if (info.time.completed === void 0)
|
|
16422
|
+
return { kind: "missing" };
|
|
16423
|
+
const tokens = record2(info.tokens), cache = record2(tokens.cache);
|
|
16424
|
+
if ((info.error || info.finish === "start_plan_admission_retry_discarded") && tokens.total === void 0 && tokens.input === 0 && tokens.output === 0 && tokens.reasoning === 0 && cache.read === 0 && cache.write === 0)
|
|
16425
|
+
return { kind: "none" };
|
|
16426
|
+
try {
|
|
15921
16427
|
return {
|
|
15922
|
-
|
|
15923
|
-
|
|
15924
|
-
retryable: error51.retryable
|
|
16428
|
+
kind: "request",
|
|
16429
|
+
request: requestTokens(info.messageId, info.model?.modelId, info.tokens)
|
|
15925
16430
|
};
|
|
15926
|
-
|
|
16431
|
+
} catch {
|
|
16432
|
+
return { kind: "missing" };
|
|
16433
|
+
}
|
|
15927
16434
|
}
|
|
15928
|
-
|
|
15929
|
-
|
|
15930
|
-
|
|
15931
|
-
|
|
15932
|
-
|
|
15933
|
-
|
|
15934
|
-
|
|
15935
|
-
|
|
15936
|
-
|
|
15937
|
-
|
|
15938
|
-
|
|
15939
|
-
|
|
15940
|
-
|
|
15941
|
-
|
|
15942
|
-
|
|
15943
|
-
|
|
15944
|
-
|
|
15945
|
-
|
|
15946
|
-
|
|
15947
|
-
|
|
15948
|
-
|
|
15949
|
-
|
|
15950
|
-
|
|
15951
|
-
|
|
15952
|
-
|
|
15953
|
-
|
|
15954
|
-
|
|
15955
|
-
})
|
|
15956
|
-
|
|
15957
|
-
|
|
15958
|
-
|
|
15959
|
-
|
|
15960
|
-
|
|
15961
|
-
|
|
15962
|
-
|
|
15963
|
-
|
|
15964
|
-
|
|
15965
|
-
|
|
15966
|
-
|
|
15967
|
-
|
|
15968
|
-
|
|
15969
|
-
}
|
|
15970
|
-
|
|
15971
|
-
|
|
15972
|
-
|
|
15973
|
-
|
|
15974
|
-
|
|
15975
|
-
|
|
15976
|
-
|
|
15977
|
-
|
|
15978
|
-
|
|
15979
|
-
|
|
15980
|
-
|
|
15981
|
-
|
|
15982
|
-
|
|
15983
|
-
|
|
15984
|
-
|
|
15985
|
-
|
|
15986
|
-
|
|
15987
|
-
|
|
15988
|
-
|
|
15989
|
-
|
|
15990
|
-
|
|
15991
|
-
|
|
15992
|
-
|
|
15993
|
-
|
|
15994
|
-
|
|
15995
|
-
|
|
15996
|
-
|
|
15997
|
-
|
|
15998
|
-
|
|
15999
|
-
|
|
16000
|
-
|
|
16001
|
-
|
|
16002
|
-
|
|
16003
|
-
|
|
16004
|
-
|
|
16005
|
-
|
|
16006
|
-
|
|
16007
|
-
|
|
16008
|
-
|
|
16009
|
-
|
|
16010
|
-
|
|
16011
|
-
|
|
16012
|
-
|
|
16013
|
-
|
|
16014
|
-
|
|
16015
|
-
|
|
16016
|
-
|
|
16017
|
-
|
|
16018
|
-
|
|
16019
|
-
|
|
16020
|
-
|
|
16021
|
-
|
|
16022
|
-
|
|
16023
|
-
|
|
16024
|
-
|
|
16025
|
-
|
|
16026
|
-
|
|
16027
|
-
|
|
16028
|
-
|
|
16029
|
-
|
|
16030
|
-
|
|
16031
|
-
|
|
16032
|
-
|
|
16033
|
-
|
|
16034
|
-
|
|
16035
|
-
|
|
16036
|
-
|
|
16037
|
-
|
|
16038
|
-
|
|
16039
|
-
|
|
16040
|
-
|
|
16041
|
-
|
|
16042
|
-
|
|
16043
|
-
|
|
16044
|
-
|
|
16045
|
-
|
|
16046
|
-
|
|
16047
|
-
|
|
16048
|
-
|
|
16049
|
-
|
|
16435
|
+
var ZcodeUsage = class {
|
|
16436
|
+
sessionId;
|
|
16437
|
+
emit;
|
|
16438
|
+
#seen = /* @__PURE__ */ new Map();
|
|
16439
|
+
#pending;
|
|
16440
|
+
#timings = /* @__PURE__ */ new Map();
|
|
16441
|
+
#complete = true;
|
|
16442
|
+
constructor(sessionId, emit) {
|
|
16443
|
+
this.sessionId = sessionId;
|
|
16444
|
+
this.emit = emit;
|
|
16445
|
+
}
|
|
16446
|
+
invalidate() {
|
|
16447
|
+
if (!this.#complete)
|
|
16448
|
+
return;
|
|
16449
|
+
this.#complete = false;
|
|
16450
|
+
this.emit({ type: "usage.history", complete: false });
|
|
16451
|
+
}
|
|
16452
|
+
replay(messages, historical) {
|
|
16453
|
+
for (const message of messages) {
|
|
16454
|
+
if (message.info.sessionId !== this.sessionId)
|
|
16455
|
+
continue;
|
|
16456
|
+
const result = zcodeUsageRecord(message);
|
|
16457
|
+
if (result.kind === "missing")
|
|
16458
|
+
this.invalidate();
|
|
16459
|
+
else if (result.kind === "request") {
|
|
16460
|
+
this.#publish({
|
|
16461
|
+
...result.request,
|
|
16462
|
+
...historical ? { historical: true } : this.#timings.get(result.request.requestId)
|
|
16463
|
+
});
|
|
16464
|
+
}
|
|
16465
|
+
}
|
|
16466
|
+
if (historical)
|
|
16467
|
+
this.emit({ type: "usage.history", complete: this.#complete });
|
|
16468
|
+
this.#pending = void 0;
|
|
16469
|
+
this.#timings.clear();
|
|
16470
|
+
}
|
|
16471
|
+
#publish(request) {
|
|
16472
|
+
if ((request.reasoningOutputTokens ?? 0) > 0) {
|
|
16473
|
+
request = { ...request };
|
|
16474
|
+
delete request.startedAtMs;
|
|
16475
|
+
delete request.completedAtMs;
|
|
16476
|
+
}
|
|
16477
|
+
const previous = this.#seen.get(request.requestId);
|
|
16478
|
+
if (previous) {
|
|
16479
|
+
if (previous.model !== request.model || previous.inputTokens !== request.inputTokens || previous.outputTokens !== request.outputTokens || previous.cachedInputTokens !== request.cachedInputTokens || previous.cacheWriteInputTokens !== request.cacheWriteInputTokens || (previous.reasoningOutputTokens ?? 0) !== (request.reasoningOutputTokens ?? 0))
|
|
16480
|
+
this.invalidate();
|
|
16481
|
+
return;
|
|
16482
|
+
}
|
|
16483
|
+
this.#seen.set(request.requestId, request);
|
|
16484
|
+
this.emit({ type: "usage.request", request });
|
|
16485
|
+
}
|
|
16486
|
+
observe(event) {
|
|
16487
|
+
if (event.sessionId !== this.sessionId)
|
|
16488
|
+
return;
|
|
16489
|
+
const p = event.payload ?? {};
|
|
16490
|
+
if (event.type === "turn.started") {
|
|
16491
|
+
this.#pending = void 0;
|
|
16492
|
+
this.#timings.clear();
|
|
16493
|
+
return;
|
|
16494
|
+
}
|
|
16495
|
+
if (event.type === "model.streaming") {
|
|
16496
|
+
const pending2 = this.#pending;
|
|
16497
|
+
if (!pending2 || pending2.turnId !== event.turnId || p.source === "subagent")
|
|
16498
|
+
return;
|
|
16499
|
+
const id = text(p.assistantMessageId);
|
|
16500
|
+
if (!id)
|
|
16501
|
+
return;
|
|
16502
|
+
if (pending2.messageId && pending2.messageId !== id)
|
|
16503
|
+
pending2.ambiguous = true;
|
|
16504
|
+
pending2.messageId = id;
|
|
16505
|
+
if (pending2.startedAtMs === void 0 && ((p.kind === "text_delta" || p.kind === "reasoning_delta") && text(p.delta) || p.kind === "tool_input_start" || p.kind === "tool_input_delta" && text(p.delta) || p.kind === "tool_call"))
|
|
16506
|
+
pending2.startedAtMs = event.timestamp;
|
|
16507
|
+
return;
|
|
16508
|
+
}
|
|
16509
|
+
if (event.type !== "session.updated" || p.querySource !== "main_turn")
|
|
16510
|
+
return;
|
|
16511
|
+
if (p.type === "model_request_started") {
|
|
16512
|
+
const id = text(p.requestId), model2 = text(p.modelId);
|
|
16513
|
+
if (!id || !model2)
|
|
16514
|
+
return;
|
|
16515
|
+
this.#pending = {
|
|
16516
|
+
id,
|
|
16517
|
+
model: model2,
|
|
16518
|
+
turnId: event.turnId,
|
|
16519
|
+
ambiguous: this.#pending !== void 0
|
|
16520
|
+
};
|
|
16521
|
+
return;
|
|
16522
|
+
}
|
|
16523
|
+
if (p.type !== "model_request_completed")
|
|
16524
|
+
return;
|
|
16525
|
+
const pending = this.#pending;
|
|
16526
|
+
if (!pending || pending.id !== p.requestId || pending.turnId !== event.turnId)
|
|
16527
|
+
return;
|
|
16528
|
+
this.#pending = void 0;
|
|
16529
|
+
if (pending.ambiguous || !pending.messageId || pending.model !== p.modelId)
|
|
16530
|
+
return;
|
|
16531
|
+
const start = pending.startedAtMs;
|
|
16532
|
+
if (start !== void 0 && Number.isSafeInteger(start) && Number.isSafeInteger(event.timestamp) && event.timestamp >= start)
|
|
16533
|
+
this.#timings.set(pending.messageId, {
|
|
16534
|
+
startedAtMs: start,
|
|
16535
|
+
completedAtMs: event.timestamp
|
|
16536
|
+
});
|
|
16537
|
+
const usage = record2(p.usage);
|
|
16538
|
+
if (usage.cacheReadTokens === void 0 || usage.cacheWriteTokens === void 0)
|
|
16539
|
+
return;
|
|
16540
|
+
try {
|
|
16541
|
+
const request = requestTokens(pending.messageId, pending.model, {
|
|
16542
|
+
input: usage.inputTokens,
|
|
16543
|
+
output: usage.outputTokens,
|
|
16544
|
+
total: usage.totalTokens,
|
|
16545
|
+
reasoning: usage.reasoningTokens,
|
|
16546
|
+
cache: { read: usage.cacheReadTokens, write: usage.cacheWriteTokens }
|
|
16547
|
+
});
|
|
16548
|
+
this.#publish({ ...request, ...this.#timings.get(pending.messageId) });
|
|
16549
|
+
} catch {
|
|
16550
|
+
this.invalidate();
|
|
16551
|
+
}
|
|
16552
|
+
}
|
|
16553
|
+
};
|
|
16554
|
+
|
|
16555
|
+
// dist/usage-statistics.js
|
|
16556
|
+
function zcodeDatabasePath(environment) {
|
|
16557
|
+
return path.join(environment.ZCODE_DATA_BASE_DIR?.trim() || environment.HOME || os.homedir(), ".zcode", "cli", "db", "db.sqlite");
|
|
16050
16558
|
}
|
|
16051
|
-
function
|
|
16052
|
-
|
|
16559
|
+
async function readZcodeUsage(file2) {
|
|
16560
|
+
const { DatabaseSync } = await import("node:sqlite");
|
|
16561
|
+
const database = new DatabaseSync(file2, { readOnly: true });
|
|
16562
|
+
try {
|
|
16563
|
+
const entries = [];
|
|
16564
|
+
const directories = /* @__PURE__ */ new Map();
|
|
16565
|
+
const titles = /* @__PURE__ */ new Map();
|
|
16566
|
+
const hasSessions = database.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'session'").get();
|
|
16567
|
+
if (hasSessions) {
|
|
16568
|
+
const columns = new Set(database.prepare("PRAGMA table_info(session)").all().map((row) => String(row.name)));
|
|
16569
|
+
const titleColumn = columns.has("title") ? ", title" : "";
|
|
16570
|
+
for (const row of database.prepare(`SELECT id, directory${titleColumn} FROM session`).iterate()) {
|
|
16571
|
+
if (typeof row.directory === "string")
|
|
16572
|
+
directories.set(String(row.id), row.directory);
|
|
16573
|
+
const title = usageSessionTitle(row.title);
|
|
16574
|
+
if (title)
|
|
16575
|
+
titles.set(String(row.id), title);
|
|
16576
|
+
}
|
|
16577
|
+
}
|
|
16578
|
+
for (const row of database.prepare("SELECT id, session_id, data FROM message").iterate()) {
|
|
16579
|
+
let data;
|
|
16580
|
+
try {
|
|
16581
|
+
data = record2(JSON.parse(String(row.data)));
|
|
16582
|
+
} catch {
|
|
16583
|
+
continue;
|
|
16584
|
+
}
|
|
16585
|
+
if (data.role !== "assistant")
|
|
16586
|
+
continue;
|
|
16587
|
+
const modelId = text(data.modelId) || text(data.modelID);
|
|
16588
|
+
const providerId = text(data.providerId) || text(data.providerID);
|
|
16589
|
+
const parsed = messageSchema.safeParse({
|
|
16590
|
+
info: {
|
|
16591
|
+
...data,
|
|
16592
|
+
messageId: String(row.id),
|
|
16593
|
+
sessionId: String(row.session_id),
|
|
16594
|
+
...modelId && providerId ? { model: { providerId, modelId } } : {}
|
|
16595
|
+
},
|
|
16596
|
+
parts: []
|
|
16597
|
+
});
|
|
16598
|
+
if (!parsed.success)
|
|
16599
|
+
continue;
|
|
16600
|
+
const usage = zcodeUsageRecord(parsed.data);
|
|
16601
|
+
const at = nativeTimeMs(parsed.data.info.time.created);
|
|
16602
|
+
const entry = usage.kind === "request" && at !== null && usageEntryFromRequest(usage.request, at);
|
|
16603
|
+
if (entry) {
|
|
16604
|
+
const sessionId = String(row.session_id);
|
|
16605
|
+
entries.push(withUsageSession(entry, {
|
|
16606
|
+
sessionId,
|
|
16607
|
+
cwd: directories.get(sessionId),
|
|
16608
|
+
title: titles.get(sessionId)
|
|
16609
|
+
}));
|
|
16610
|
+
}
|
|
16611
|
+
}
|
|
16612
|
+
return entries;
|
|
16613
|
+
} finally {
|
|
16614
|
+
database.close();
|
|
16615
|
+
}
|
|
16616
|
+
}
|
|
16617
|
+
function createZcodeUsageStatistics(environment) {
|
|
16618
|
+
return Object.freeze({
|
|
16619
|
+
async listSources() {
|
|
16620
|
+
const file2 = zcodeDatabasePath(environment);
|
|
16621
|
+
const info = await lstat(file2).catch(() => null);
|
|
16622
|
+
if (!info?.isFile())
|
|
16623
|
+
return [];
|
|
16624
|
+
const wal = await lstat(`${file2}-wal`).catch(() => null);
|
|
16625
|
+
return [
|
|
16626
|
+
{
|
|
16627
|
+
id: file2,
|
|
16628
|
+
fingerprint: `${info.ino}:${info.size}:${info.mtimeMs}:${wal ? `${wal.size}:${wal.mtimeMs}` : "-"}`
|
|
16629
|
+
}
|
|
16630
|
+
];
|
|
16631
|
+
},
|
|
16632
|
+
readSource: (id) => readZcodeUsage(id)
|
|
16633
|
+
});
|
|
16634
|
+
}
|
|
16635
|
+
|
|
16636
|
+
// dist/adapter.js
|
|
16637
|
+
import path6 from "node:path";
|
|
16638
|
+
import { stat as stat2 } from "node:fs/promises";
|
|
16639
|
+
|
|
16640
|
+
// dist/transport.js
|
|
16641
|
+
import { spawn } from "node:child_process";
|
|
16642
|
+
import { randomUUID } from "node:crypto";
|
|
16643
|
+
|
|
16644
|
+
// dist/errors.js
|
|
16645
|
+
var ZcodeError = class extends Error {
|
|
16646
|
+
code;
|
|
16647
|
+
retryable;
|
|
16648
|
+
rpcCode;
|
|
16649
|
+
constructor(code, message, retryable = false, rpcCode) {
|
|
16650
|
+
super(message);
|
|
16651
|
+
this.code = code;
|
|
16652
|
+
this.retryable = retryable;
|
|
16653
|
+
this.rpcCode = rpcCode;
|
|
16654
|
+
}
|
|
16655
|
+
};
|
|
16656
|
+
function failure(code, message, retryable = false) {
|
|
16657
|
+
return { ok: false, error: { code, message, retryable } };
|
|
16658
|
+
}
|
|
16659
|
+
function nativeError(error51) {
|
|
16660
|
+
if (error51 instanceof ZcodeError)
|
|
16661
|
+
return {
|
|
16662
|
+
code: error51.code,
|
|
16663
|
+
message: sanitizeDiagnosticTail(error51.message),
|
|
16664
|
+
retryable: error51.retryable
|
|
16665
|
+
};
|
|
16666
|
+
return { code: "nativeFailure", message: "ZCode operation failed", retryable: false };
|
|
16053
16667
|
}
|
|
16054
16668
|
|
|
16055
16669
|
// dist/installation.js
|
|
16056
16670
|
import { open, stat } from "node:fs/promises";
|
|
16057
16671
|
import { homedir } from "node:os";
|
|
16058
|
-
import
|
|
16672
|
+
import path2 from "node:path";
|
|
16059
16673
|
var DEFAULT_DARWIN_APP = "/Applications/ZCode.app";
|
|
16060
16674
|
var DEFAULT_LINUX_APP = "/opt/ZCode";
|
|
16061
16675
|
async function isFile(file2) {
|
|
@@ -16100,11 +16714,11 @@ async function resolveDefaultApp(environment, platform2) {
|
|
|
16100
16714
|
if (platform2 === "linux")
|
|
16101
16715
|
return DEFAULT_LINUX_APP;
|
|
16102
16716
|
const candidates = [
|
|
16103
|
-
environment.LOCALAPPDATA &&
|
|
16104
|
-
environment.ProgramFiles &&
|
|
16717
|
+
environment.LOCALAPPDATA && path2.join(environment.LOCALAPPDATA, "Programs", "ZCode"),
|
|
16718
|
+
environment.ProgramFiles && path2.join(environment.ProgramFiles, "ZCode")
|
|
16105
16719
|
].filter(Boolean);
|
|
16106
16720
|
for (const candidate of candidates) {
|
|
16107
|
-
if (await isFile(
|
|
16721
|
+
if (await isFile(path2.join(candidate, "resources", "app.asar")))
|
|
16108
16722
|
return candidate;
|
|
16109
16723
|
}
|
|
16110
16724
|
return candidates[0] ?? "";
|
|
@@ -16116,30 +16730,30 @@ async function resolveInstallation(environment, app, platform2 = process.platfor
|
|
|
16116
16730
|
const explicitApp = app?.trim() || environment.CODEXHOST_ZCODE_APP?.trim();
|
|
16117
16731
|
const targetApp = explicitApp || await resolveDefaultApp(environment, platform2);
|
|
16118
16732
|
const missing = () => new ZcodeError("notInstalled", `ZCode Desktop was not found at ${targetApp}; install it or set its application path`);
|
|
16119
|
-
const resources = platform2 === "darwin" ?
|
|
16120
|
-
const pkg = await readPackageJsonFromAsar(
|
|
16733
|
+
const resources = platform2 === "darwin" ? path2.join(targetApp, "Contents", "Resources") : path2.join(targetApp, "resources");
|
|
16734
|
+
const pkg = await readPackageJsonFromAsar(path2.join(resources, "app.asar"));
|
|
16121
16735
|
if (!pkg?.productName || !pkg.version)
|
|
16122
16736
|
throw missing();
|
|
16123
16737
|
let runtime;
|
|
16124
16738
|
if (platform2 === "darwin") {
|
|
16125
|
-
runtime =
|
|
16739
|
+
runtime = path2.join(targetApp, "Contents", "Frameworks", `${pkg.productName} Helper.app`, "Contents", "MacOS", `${pkg.productName} Helper`);
|
|
16126
16740
|
} else if (platform2 === "win32") {
|
|
16127
|
-
runtime =
|
|
16741
|
+
runtime = path2.join(targetApp, `${pkg.productName}.exe`);
|
|
16128
16742
|
} else {
|
|
16129
16743
|
const linuxExecutableName = pkg.productName.toLowerCase().replace(/\s+/g, "-");
|
|
16130
|
-
runtime =
|
|
16744
|
+
runtime = path2.join(targetApp, linuxExecutableName);
|
|
16131
16745
|
}
|
|
16132
|
-
const cli =
|
|
16133
|
-
const builtinProviderConfig = environment.ZCODE_BUILTIN_PROVIDER_CONFIG_FILE ||
|
|
16746
|
+
const cli = path2.join(resources, "glm", "zcode.cjs");
|
|
16747
|
+
const builtinProviderConfig = environment.ZCODE_BUILTIN_PROVIDER_CONFIG_FILE || path2.join(resources, "config", "provider", "zcode-builtin.json");
|
|
16134
16748
|
if (!await isFile(runtime) || !await isFile(cli) || !await isFile(builtinProviderConfig))
|
|
16135
16749
|
throw missing();
|
|
16136
|
-
const dataRoot =
|
|
16750
|
+
const dataRoot = path2.join(environment.ZCODE_DATA_BASE_DIR?.trim() || environment.HOME || homedir(), ".zcode", "v2");
|
|
16137
16751
|
return {
|
|
16138
16752
|
runtime,
|
|
16139
16753
|
version: pkg.version,
|
|
16140
16754
|
cli,
|
|
16141
16755
|
builtinProviderConfig,
|
|
16142
|
-
personalProviderConfig: environment.ZCODE_PERSONAL_PROVIDER_CONFIG_FILE ||
|
|
16756
|
+
personalProviderConfig: environment.ZCODE_PERSONAL_PROVIDER_CONFIG_FILE || path2.join(dataRoot, "provider_config.json"),
|
|
16143
16757
|
dataRoot
|
|
16144
16758
|
};
|
|
16145
16759
|
}
|
|
@@ -16161,25 +16775,15 @@ function createZcodeInstallation(environment, app) {
|
|
|
16161
16775
|
}
|
|
16162
16776
|
|
|
16163
16777
|
// dist/account.js
|
|
16778
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
16779
|
+
import { readFile as readFile3 } from "node:fs/promises";
|
|
16780
|
+
import path5 from "node:path";
|
|
16781
|
+
|
|
16782
|
+
// dist/credentials.js
|
|
16164
16783
|
import { createDecipheriv, createHash } from "node:crypto";
|
|
16165
16784
|
import { readFile } from "node:fs/promises";
|
|
16166
16785
|
import { homedir as homedir2, platform, userInfo } from "node:os";
|
|
16167
|
-
import
|
|
16168
|
-
var SIGN_IN = "Sign in to ZCode Desktop with a Start Plan account, then try again";
|
|
16169
|
-
var builtinSchema = external_exports.object({
|
|
16170
|
-
revision: external_exports.union([external_exports.number(), external_exports.string()]),
|
|
16171
|
-
config: external_exports.object({
|
|
16172
|
-
providerConfigRules: external_exports.object({
|
|
16173
|
-
providerRules: external_exports.array(external_exports.object({
|
|
16174
|
-
providerId: external_exports.string().min(1),
|
|
16175
|
-
config: external_exports.object({
|
|
16176
|
-
builtinModelIds: external_exports.array(external_exports.string()).optional(),
|
|
16177
|
-
access: external_exports.object({ mode: external_exports.string(), accountType: external_exports.string() }).partial().optional()
|
|
16178
|
-
})
|
|
16179
|
-
}))
|
|
16180
|
-
})
|
|
16181
|
-
})
|
|
16182
|
-
});
|
|
16786
|
+
import path3 from "node:path";
|
|
16183
16787
|
function decrypt(value, environment) {
|
|
16184
16788
|
if (!value.startsWith("enc:v1:"))
|
|
16185
16789
|
return value;
|
|
@@ -16200,25 +16804,231 @@ function decrypt(value, environment) {
|
|
|
16200
16804
|
throw new ZcodeError("authenticationRequired", "Cannot decrypt ZCode credentials; ZCODE_CREDENTIAL_SECRET must match ZCode Desktop");
|
|
16201
16805
|
}
|
|
16202
16806
|
}
|
|
16203
|
-
async function
|
|
16807
|
+
async function readCredentials(installation, environment) {
|
|
16204
16808
|
let store;
|
|
16205
16809
|
try {
|
|
16206
|
-
store = JSON.parse(await readFile(
|
|
16810
|
+
store = JSON.parse(await readFile(path3.join(installation.dataRoot, "credentials.json"), "utf8"));
|
|
16207
16811
|
} catch (error51) {
|
|
16208
16812
|
if (error51.code === "ENOENT")
|
|
16209
|
-
return "";
|
|
16813
|
+
return () => "";
|
|
16210
16814
|
throw new ZcodeError("authenticationRequired", "Cannot read ZCode credentials");
|
|
16211
16815
|
}
|
|
16212
|
-
const
|
|
16213
|
-
return
|
|
16816
|
+
const values = external_exports.record(external_exports.string(), external_exports.string()).safeParse(store).data;
|
|
16817
|
+
return (key) => {
|
|
16818
|
+
const value = values?.[key];
|
|
16819
|
+
return value ? decrypt(value, environment) : "";
|
|
16820
|
+
};
|
|
16214
16821
|
}
|
|
16822
|
+
async function readCredential(installation, environment, key) {
|
|
16823
|
+
return (await readCredentials(installation, environment))(key);
|
|
16824
|
+
}
|
|
16825
|
+
|
|
16826
|
+
// dist/personal-coding-plan.js
|
|
16827
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
16828
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
16829
|
+
import { homedir as homedir3 } from "node:os";
|
|
16830
|
+
import path4 from "node:path";
|
|
16831
|
+
var familySchema = external_exports.enum(["zai", "bigmodel"]);
|
|
16832
|
+
var recordSchema2 = external_exports.record(external_exports.string(), external_exports.unknown());
|
|
16833
|
+
var CONNECT = "Connect Personal Coding Plan in ZCode Desktop, then re-detect ZCode and reopen the Thread";
|
|
16834
|
+
function personalCodingPlanOrigin(family, environment) {
|
|
16835
|
+
const test = environment.ZCODE_ENV?.trim().toLowerCase() === "test";
|
|
16836
|
+
const prefix = family === "zai" ? "ZAI" : "BIGMODEL";
|
|
16837
|
+
const suffix = family === "zai" ? "BUSINESS_BASE_URL" : "API_BASE_URL";
|
|
16838
|
+
const origin = environment[`${prefix}_${suffix}`]?.trim() || environment[`${prefix}_${test ? "TEST" : "PRODUCTION"}_${suffix}`]?.trim() || (family === "zai" ? test ? "https://api.chatglm.site" : "https://api.z.ai" : test ? "https://dev.bigmodel.cn" : "https://bigmodel.cn");
|
|
16839
|
+
const url2 = new URL(origin);
|
|
16840
|
+
if (!["http:", "https:"].includes(url2.protocol) || url2.username || url2.password)
|
|
16841
|
+
throw new Error("Invalid ZCode business origin");
|
|
16842
|
+
return url2.origin;
|
|
16843
|
+
}
|
|
16844
|
+
async function readSelection(environment, family) {
|
|
16845
|
+
const home = environment.ZCODE_DESKTOP_HOME_DIR?.trim() || environment.HOME?.trim() || environment.USERPROFILE?.trim() || homedir3();
|
|
16846
|
+
let raw;
|
|
16847
|
+
try {
|
|
16848
|
+
raw = JSON.parse(await readFile2(path4.join(home, ".zcode", "v2", "setting.json"), "utf8"));
|
|
16849
|
+
} catch (error51) {
|
|
16850
|
+
if (error51.code === "ENOENT")
|
|
16851
|
+
return false;
|
|
16852
|
+
throw new ZcodeError("configurationRequired", CONNECT);
|
|
16853
|
+
}
|
|
16854
|
+
const settings = recordSchema2.parse(raw);
|
|
16855
|
+
if (settings.providerFamilyDomain !== family)
|
|
16856
|
+
return false;
|
|
16857
|
+
if (Object.hasOwn(settings, "providerFamilyConnectionSelections")) {
|
|
16858
|
+
const selections = recordSchema2.parse(settings.providerFamilyConnectionSelections);
|
|
16859
|
+
return external_exports.object({ kind: external_exports.literal("individual-coding-plan") }).safeParse(selections[family]).success;
|
|
16860
|
+
}
|
|
16861
|
+
const modes = recordSchema2.safeParse(settings.modelProviderFamilyModes).data;
|
|
16862
|
+
const keys = recordSchema2.safeParse(settings.modelProviderFamilySelectedKeys).data;
|
|
16863
|
+
return modes?.[family] !== "apiKey" && keys?.[family] === `coding-plan:builtin:${family}-coding-plan`;
|
|
16864
|
+
}
|
|
16865
|
+
var envelopeSchema = external_exports.object({
|
|
16866
|
+
success: external_exports.boolean().optional(),
|
|
16867
|
+
code: external_exports.number().optional(),
|
|
16868
|
+
data: external_exports.array(external_exports.unknown())
|
|
16869
|
+
});
|
|
16870
|
+
var subscriptionSchema = external_exports.object({
|
|
16871
|
+
productId: external_exports.string().optional(),
|
|
16872
|
+
productName: external_exports.string().optional(),
|
|
16873
|
+
status: external_exports.string(),
|
|
16874
|
+
inCurrentPeriod: external_exports.boolean()
|
|
16875
|
+
});
|
|
16876
|
+
function codingProduct(value) {
|
|
16877
|
+
const entry = recordSchema2.safeParse(value).data;
|
|
16878
|
+
return [entry?.productId, entry?.productName].some((field2) => typeof field2 === "string" && field2.toLowerCase().includes("coding"));
|
|
16879
|
+
}
|
|
16880
|
+
async function queryEntitlement(family, apiKey, environment) {
|
|
16881
|
+
try {
|
|
16882
|
+
const response = await fetch(`${personalCodingPlanOrigin(family, environment)}/api/biz/subscription/list`, {
|
|
16883
|
+
method: "GET",
|
|
16884
|
+
// The subscription endpoint accepts the model API Key, not the OAuth token or Start JWT.
|
|
16885
|
+
headers: { Authorization: apiKey.trim() },
|
|
16886
|
+
redirect: "error",
|
|
16887
|
+
signal: AbortSignal.timeout(15e3)
|
|
16888
|
+
});
|
|
16889
|
+
if (response.status === 401 || response.status === 403)
|
|
16890
|
+
return "credential-failed";
|
|
16891
|
+
if (!response.ok)
|
|
16892
|
+
return "unknown";
|
|
16893
|
+
const parsed = envelopeSchema.safeParse(await response.json());
|
|
16894
|
+
if (!parsed.success)
|
|
16895
|
+
return "unknown";
|
|
16896
|
+
const payload = parsed.data;
|
|
16897
|
+
if (payload.success === false || payload.code !== void 0 && ![0, 200].includes(payload.code))
|
|
16898
|
+
return "unknown";
|
|
16899
|
+
let malformed = false;
|
|
16900
|
+
for (const item of payload.data) {
|
|
16901
|
+
if (!codingProduct(item))
|
|
16902
|
+
continue;
|
|
16903
|
+
const subscription = subscriptionSchema.safeParse(item);
|
|
16904
|
+
if (!subscription.success)
|
|
16905
|
+
malformed = true;
|
|
16906
|
+
else if (subscription.data.status === "VALID" && subscription.data.inCurrentPeriod)
|
|
16907
|
+
return "available";
|
|
16908
|
+
}
|
|
16909
|
+
return malformed ? "unknown" : "unavailable";
|
|
16910
|
+
} catch {
|
|
16911
|
+
return "unknown";
|
|
16912
|
+
}
|
|
16913
|
+
}
|
|
16914
|
+
var PersonalCodingPlanAccount = class {
|
|
16915
|
+
installation;
|
|
16916
|
+
environment;
|
|
16917
|
+
#authorized = /* @__PURE__ */ new Map();
|
|
16918
|
+
constructor(installation, environment) {
|
|
16919
|
+
this.installation = installation;
|
|
16920
|
+
this.environment = environment;
|
|
16921
|
+
}
|
|
16922
|
+
async #context(providerId, family) {
|
|
16923
|
+
const [credential, current] = await Promise.all([
|
|
16924
|
+
readCredentials(this.installation, this.environment),
|
|
16925
|
+
readSelection(this.environment, family)
|
|
16926
|
+
]);
|
|
16927
|
+
if (credential("oauth:active_provider") !== family)
|
|
16928
|
+
return void 0;
|
|
16929
|
+
const raw = credential(`oauth:${family}:user_info`);
|
|
16930
|
+
if (!raw)
|
|
16931
|
+
return void 0;
|
|
16932
|
+
const profile = recordSchema2.parse(JSON.parse(raw));
|
|
16933
|
+
const normalized = external_exports.object({ id: external_exports.string(), username: external_exports.string(), displayName: external_exports.string() }).safeParse(profile).data;
|
|
16934
|
+
const identity = normalized ? normalized.id.trim() : family === "zai" && typeof profile.user_id === "string" ? profile.user_id.trim() : "";
|
|
16935
|
+
if (!identity || identity === "unknown")
|
|
16936
|
+
return void 0;
|
|
16937
|
+
const key = `account-provider:coding-plan:${providerId}:account:${encodeURIComponent(identity)}:api-key`;
|
|
16938
|
+
return { identity, current, apiKey: credential(key).trim() };
|
|
16939
|
+
}
|
|
16940
|
+
async inspect(providerId, accountType) {
|
|
16941
|
+
const family = familySchema.parse(accountType);
|
|
16942
|
+
this.#authorized.delete(providerId);
|
|
16943
|
+
let current = false;
|
|
16944
|
+
try {
|
|
16945
|
+
const context = await this.#context(providerId, family);
|
|
16946
|
+
if (!context)
|
|
16947
|
+
return {
|
|
16948
|
+
availability: "unavailable",
|
|
16949
|
+
entitled: false,
|
|
16950
|
+
current,
|
|
16951
|
+
unavailableReason: "not-connected"
|
|
16952
|
+
};
|
|
16953
|
+
current = context.current;
|
|
16954
|
+
const connectionKey = createHash2("sha256").update(JSON.stringify([family, context.identity, "individual-coding-plan"])).digest("hex");
|
|
16955
|
+
const base = { current, connectionKey };
|
|
16956
|
+
if (!context.apiKey)
|
|
16957
|
+
return {
|
|
16958
|
+
...base,
|
|
16959
|
+
availability: "unavailable",
|
|
16960
|
+
entitled: false,
|
|
16961
|
+
unavailableReason: "credential-failed"
|
|
16962
|
+
};
|
|
16963
|
+
const entitlement = await queryEntitlement(family, context.apiKey, this.environment);
|
|
16964
|
+
const after = await this.#context(providerId, family);
|
|
16965
|
+
if (!after || after.identity !== context.identity || after.current !== current || after.apiKey !== context.apiKey)
|
|
16966
|
+
return { availability: "unknown", entitled: false, current: false };
|
|
16967
|
+
if (entitlement === "available") {
|
|
16968
|
+
if (current)
|
|
16969
|
+
this.#authorized.set(providerId, { family, identity: context.identity });
|
|
16970
|
+
return { ...base, availability: "available", entitled: true };
|
|
16971
|
+
}
|
|
16972
|
+
return {
|
|
16973
|
+
...base,
|
|
16974
|
+
availability: entitlement === "unknown" ? "unknown" : "unavailable",
|
|
16975
|
+
entitled: false,
|
|
16976
|
+
...entitlement === "unknown" ? {} : {
|
|
16977
|
+
unavailableReason: entitlement === "unavailable" ? "not-entitled" : "credential-failed"
|
|
16978
|
+
}
|
|
16979
|
+
};
|
|
16980
|
+
} catch {
|
|
16981
|
+
return { availability: "unknown", entitled: false, current };
|
|
16982
|
+
}
|
|
16983
|
+
}
|
|
16984
|
+
async requestAuth(request, signal) {
|
|
16985
|
+
const parsed = external_exports.object({
|
|
16986
|
+
providerId: external_exports.string(),
|
|
16987
|
+
modelSelection: external_exports.object({ providerId: external_exports.string() }),
|
|
16988
|
+
accountAccess: external_exports.object({
|
|
16989
|
+
type: external_exports.literal("zhipu-account"),
|
|
16990
|
+
mode: external_exports.literal("individual-coding-plan"),
|
|
16991
|
+
accountType: familySchema
|
|
16992
|
+
})
|
|
16993
|
+
}).safeParse(request);
|
|
16994
|
+
if (!parsed.success)
|
|
16995
|
+
throw new ZcodeError("authenticationRequired", CONNECT);
|
|
16996
|
+
const { providerId, modelSelection, accountAccess } = parsed.data;
|
|
16997
|
+
const authorized = this.#authorized.get(providerId);
|
|
16998
|
+
if (!authorized || authorized.family !== accountAccess.accountType || modelSelection.providerId !== providerId)
|
|
16999
|
+
throw new ZcodeError("authenticationRequired", CONNECT);
|
|
17000
|
+
signal.throwIfAborted();
|
|
17001
|
+
const context = await this.#context(providerId, authorized.family);
|
|
17002
|
+
signal.throwIfAborted();
|
|
17003
|
+
if (!context?.current || context.identity !== authorized.identity || !context.apiKey)
|
|
17004
|
+
throw new ZcodeError("authenticationRequired", CONNECT);
|
|
17005
|
+
return { apiKey: context.apiKey };
|
|
17006
|
+
}
|
|
17007
|
+
};
|
|
17008
|
+
|
|
17009
|
+
// dist/account.js
|
|
17010
|
+
var SIGN_IN = "Sign in to ZCode Desktop with a Start Plan account, then try again";
|
|
17011
|
+
var builtinSchema = external_exports.object({
|
|
17012
|
+
revision: external_exports.union([external_exports.number(), external_exports.string()]),
|
|
17013
|
+
config: external_exports.object({
|
|
17014
|
+
providerConfigRules: external_exports.object({
|
|
17015
|
+
providerRules: external_exports.array(external_exports.object({
|
|
17016
|
+
providerId: external_exports.string().min(1),
|
|
17017
|
+
config: external_exports.object({
|
|
17018
|
+
builtinModelIds: external_exports.array(external_exports.string()).optional(),
|
|
17019
|
+
access: external_exports.object({ mode: external_exports.string(), accountType: external_exports.string() }).partial().optional()
|
|
17020
|
+
})
|
|
17021
|
+
}))
|
|
17022
|
+
})
|
|
17023
|
+
})
|
|
17024
|
+
});
|
|
16215
17025
|
function resolveEndpointOrigin(environment) {
|
|
16216
17026
|
return environment.ZCODE_BASE_URL?.trim() || "https://zcode.z.ai";
|
|
16217
17027
|
}
|
|
16218
17028
|
async function readDeviceMid(installation) {
|
|
16219
17029
|
try {
|
|
16220
|
-
const file2 =
|
|
16221
|
-
const parsed = JSON.parse(await
|
|
17030
|
+
const file2 = path5.join(installation.dataRoot, "telemetry-state.json");
|
|
17031
|
+
const parsed = JSON.parse(await readFile3(file2, "utf8"));
|
|
16222
17032
|
return typeof parsed?.deviceMid === "string" ? parsed.deviceMid.trim() : "";
|
|
16223
17033
|
} catch {
|
|
16224
17034
|
return "";
|
|
@@ -16316,24 +17126,38 @@ async function queryStartPlanBalance(origin, appVersion, jwt2, deviceMid) {
|
|
|
16316
17126
|
}
|
|
16317
17127
|
async function accountConfig(installation, environment) {
|
|
16318
17128
|
const file2 = installation.builtinProviderConfig;
|
|
16319
|
-
const builtin = builtinSchema.parse(JSON.parse(await
|
|
16320
|
-
const basedOnZCodeBuiltinRevision = `zcode-builtin:${builtin.revision}:${
|
|
17129
|
+
const builtin = builtinSchema.parse(JSON.parse(await readFile3(file2, "utf8")));
|
|
17130
|
+
const basedOnZCodeBuiltinRevision = `zcode-builtin:${builtin.revision}:${createHash3("sha256").update(path5.resolve(file2)).digest("hex")}`;
|
|
16321
17131
|
const family = await readCredential(installation, environment, "oauth:active_provider");
|
|
16322
17132
|
let balanceData;
|
|
16323
17133
|
if (family) {
|
|
16324
|
-
|
|
16325
|
-
|
|
16326
|
-
|
|
16327
|
-
|
|
16328
|
-
|
|
17134
|
+
try {
|
|
17135
|
+
const jwt2 = await readCredential(installation, environment, "zcodejwttoken");
|
|
17136
|
+
const deviceMid = await readDeviceMid(installation);
|
|
17137
|
+
if (jwt2 && deviceMid) {
|
|
17138
|
+
const origin = resolveEndpointOrigin(environment);
|
|
17139
|
+
balanceData = await queryStartPlanBalance(origin, installation.version, jwt2, deviceMid);
|
|
17140
|
+
}
|
|
17141
|
+
} catch {
|
|
16329
17142
|
}
|
|
16330
17143
|
}
|
|
16331
17144
|
let startPlan = false;
|
|
17145
|
+
const codingPlan = new PersonalCodingPlanAccount(installation, environment);
|
|
16332
17146
|
const providers = {};
|
|
16333
17147
|
const states = {};
|
|
16334
17148
|
for (const rule of builtin.config.providerConfigRules.providerRules) {
|
|
16335
17149
|
const access = rule.config.access;
|
|
16336
|
-
if (!family || access?.
|
|
17150
|
+
if (!family || access?.accountType !== family)
|
|
17151
|
+
continue;
|
|
17152
|
+
if (access.mode === "individual-coding-plan" && (family === "zai" || family === "bigmodel")) {
|
|
17153
|
+
const state = await codingPlan.inspect(rule.providerId, family);
|
|
17154
|
+
providers[rule.providerId] = {
|
|
17155
|
+
access: { type: "zhipu-account", entitled: state.entitled }
|
|
17156
|
+
};
|
|
17157
|
+
states[rule.providerId] = state;
|
|
17158
|
+
continue;
|
|
17159
|
+
}
|
|
17160
|
+
if (access.mode !== "start-plan")
|
|
16337
17161
|
continue;
|
|
16338
17162
|
const allowedModels = resolveStartPlanModels(balanceData, rule.config.builtinModelIds);
|
|
16339
17163
|
if (allowedModels.length > 0) {
|
|
@@ -16355,7 +17179,7 @@ async function accountConfig(installation, environment) {
|
|
|
16355
17179
|
};
|
|
16356
17180
|
}
|
|
16357
17181
|
}
|
|
16358
|
-
const overlayDigest =
|
|
17182
|
+
const overlayDigest = createHash3("sha256").update(JSON.stringify([providers, states])).digest("hex").slice(0, 16);
|
|
16359
17183
|
return {
|
|
16360
17184
|
params: {
|
|
16361
17185
|
revision: `codexhost:${family || "signed-out"}:${builtin.revision}:${overlayDigest}`,
|
|
@@ -16363,16 +17187,20 @@ async function accountConfig(installation, environment) {
|
|
|
16363
17187
|
providers,
|
|
16364
17188
|
states
|
|
16365
17189
|
},
|
|
16366
|
-
startPlan
|
|
17190
|
+
startPlan,
|
|
17191
|
+
codingPlan
|
|
16367
17192
|
};
|
|
16368
17193
|
}
|
|
16369
|
-
async function providerRuntimeHeaders(
|
|
16370
|
-
|
|
16371
|
-
return {
|
|
16372
|
-
headersApplied: false,
|
|
16373
|
-
errorMessage: "codexhost supports only the ZCode Start Plan account"
|
|
16374
|
-
};
|
|
17194
|
+
async function providerRuntimeHeaders(request, signal, installation, environment, verifier, codingPlan) {
|
|
17195
|
+
const mode = external_exports.object({ mode: external_exports.string() }).safeParse(request.accountAccess).data?.mode;
|
|
16375
17196
|
try {
|
|
17197
|
+
if (mode === "individual-coding-plan")
|
|
17198
|
+
return { headersApplied: true, requestAuth: await codingPlan.requestAuth(request, signal) };
|
|
17199
|
+
if (mode !== "start-plan")
|
|
17200
|
+
return {
|
|
17201
|
+
headersApplied: false,
|
|
17202
|
+
errorMessage: "codexhost supports ZCode Start Plan and Personal Coding Plan; Team Coding Plan is not supported"
|
|
17203
|
+
};
|
|
16376
17204
|
const apiKey = await readCredential(installation, environment, "zcodejwttoken");
|
|
16377
17205
|
if (!apiKey)
|
|
16378
17206
|
return { headersApplied: false, errorMessage: SIGN_IN };
|
|
@@ -16381,7 +17209,7 @@ async function providerRuntimeHeaders(accountAccess, signal, installation, envir
|
|
|
16381
17209
|
} catch (error51) {
|
|
16382
17210
|
return {
|
|
16383
17211
|
headersApplied: false,
|
|
16384
|
-
errorMessage: error51 instanceof ZcodeError ? error51.message : "ZCode
|
|
17212
|
+
errorMessage: error51 instanceof ZcodeError ? error51.message : "ZCode account authentication failed"
|
|
16385
17213
|
};
|
|
16386
17214
|
}
|
|
16387
17215
|
}
|
|
@@ -16465,6 +17293,7 @@ var CliTransport = class {
|
|
|
16465
17293
|
// Aborting these cancels only this transport's running and queued shared verifications.
|
|
16466
17294
|
#headerRequests = /* @__PURE__ */ new Map();
|
|
16467
17295
|
#startPlan = false;
|
|
17296
|
+
#codingPlan;
|
|
16468
17297
|
#fault;
|
|
16469
17298
|
#closed = false;
|
|
16470
17299
|
#closePromise;
|
|
@@ -16487,9 +17316,10 @@ var CliTransport = class {
|
|
|
16487
17316
|
if (this.#child || this.#closed)
|
|
16488
17317
|
throw new ZcodeError("invalidState", "ZCode transport already started or closed");
|
|
16489
17318
|
const installation = await resolveInstallation(this.options.environment, this.options.app);
|
|
16490
|
-
const { params: accountParams, startPlan } = await accountConfig(installation, this.options.environment);
|
|
17319
|
+
const { params: accountParams, startPlan, codingPlan } = await accountConfig(installation, this.options.environment);
|
|
16491
17320
|
this.#installation = installation;
|
|
16492
17321
|
this.#startPlan = startPlan;
|
|
17322
|
+
this.#codingPlan = codingPlan;
|
|
16493
17323
|
const child = spawn(installation.runtime, [installation.cli, "app-server", "--stdio", "--surface", "desktop"], {
|
|
16494
17324
|
cwd: this.options.cwd,
|
|
16495
17325
|
env: {
|
|
@@ -16614,7 +17444,7 @@ var CliTransport = class {
|
|
|
16614
17444
|
this.#headerRequests.set(requestId, controller);
|
|
16615
17445
|
try {
|
|
16616
17446
|
reply({
|
|
16617
|
-
result: await providerRuntimeHeaders(params
|
|
17447
|
+
result: await providerRuntimeHeaders(params, controller.signal, this.#installation, this.options.environment, () => this.options.verifier(this.#installation.version), this.#codingPlan)
|
|
16618
17448
|
});
|
|
16619
17449
|
} finally {
|
|
16620
17450
|
this.#headerRequests.delete(requestId);
|
|
@@ -17345,32 +18175,32 @@ import { randomUUID as randomUUID2 } from "node:crypto";
|
|
|
17345
18175
|
|
|
17346
18176
|
// dist/models.js
|
|
17347
18177
|
var ZCODE_ID = harnessIdSchema.parse("zcode");
|
|
17348
|
-
function encodeModel(
|
|
18178
|
+
function encodeModel(model2) {
|
|
17349
18179
|
return harnessModelRefSchema.parse({
|
|
17350
|
-
id: `zcode-local-v1.${Buffer.from(JSON.stringify([
|
|
18180
|
+
id: `zcode-local-v1.${Buffer.from(JSON.stringify([model2.providerId, model2.modelId])).toString("base64url")}`
|
|
17351
18181
|
});
|
|
17352
18182
|
}
|
|
17353
|
-
function decodeModel(
|
|
18183
|
+
function decodeModel(model2) {
|
|
17354
18184
|
try {
|
|
17355
18185
|
const prefix = "zcode-local-v1.";
|
|
17356
|
-
const value = JSON.parse(Buffer.from(
|
|
17357
|
-
if (!
|
|
18186
|
+
const value = JSON.parse(Buffer.from(model2.id.slice(prefix.length), "base64url").toString("utf8"));
|
|
18187
|
+
if (!model2.id.startsWith(prefix) || !Array.isArray(value) || value.length !== 2)
|
|
17358
18188
|
throw new Error();
|
|
17359
18189
|
const native = nativeModelSchema.parse({ providerId: value[0], modelId: value[1] });
|
|
17360
|
-
if (encodeModel(native).id !==
|
|
18190
|
+
if (encodeModel(native).id !== model2.id)
|
|
17361
18191
|
throw new Error();
|
|
17362
18192
|
return native;
|
|
17363
18193
|
} catch {
|
|
17364
18194
|
throw new ZcodeError("invalidRequest", "Invalid ZCode model reference");
|
|
17365
18195
|
}
|
|
17366
18196
|
}
|
|
17367
|
-
function selectNativeModel(
|
|
17368
|
-
const native = decodeModel(
|
|
17369
|
-
const entry = settings.model.available.find((entry2) => encodeModel(entry2.ref).id ===
|
|
18197
|
+
function selectNativeModel(model2, settings, thinkingOption) {
|
|
18198
|
+
const native = decodeModel(model2);
|
|
18199
|
+
const entry = settings.model.available.find((entry2) => encodeModel(entry2.ref).id === model2.id && !entry2.disabledReason);
|
|
17370
18200
|
if (!entry)
|
|
17371
18201
|
throw new ZcodeError("invalidRequest", "ZCode model is not available");
|
|
17372
18202
|
const current = settings.model.current;
|
|
17373
|
-
const level = thinkingOption ?? (current && encodeModel(current).id ===
|
|
18203
|
+
const level = thinkingOption ?? (current && encodeModel(current).id === model2.id ? current.options?.reasoningLevel : void 0) ?? entry.reasoning?.defaultLevel;
|
|
17374
18204
|
if (level === void 0)
|
|
17375
18205
|
return native;
|
|
17376
18206
|
if (!entry.reasoning?.levels.some((option) => option.value === level))
|
|
@@ -17378,20 +18208,20 @@ function selectNativeModel(model, settings, thinkingOption) {
|
|
|
17378
18208
|
return { ...native, options: { reasoningLevel: level } };
|
|
17379
18209
|
}
|
|
17380
18210
|
function modelCatalog(settings) {
|
|
17381
|
-
const available = settings.model.available.filter((
|
|
18211
|
+
const available = settings.model.available.filter((model2) => !model2.disabledReason);
|
|
17382
18212
|
const levels = new Map(settings.thoughtLevel.available.map((level) => [level.value, level]));
|
|
17383
|
-
for (const
|
|
17384
|
-
for (const level of
|
|
18213
|
+
for (const model2 of available)
|
|
18214
|
+
for (const level of model2.reasoning?.levels ?? [])
|
|
17385
18215
|
levels.set(level.value, level);
|
|
17386
18216
|
const current = settings.model.current ? encodeModel(settings.model.current) : void 0;
|
|
17387
18217
|
const defaultThinking = settings.thoughtLevel.current ?? settings.thoughtLevel.defaultLevel;
|
|
17388
18218
|
return harnessModelCatalogSchema.parse({
|
|
17389
|
-
models: available.map((
|
|
17390
|
-
ref: encodeModel(
|
|
17391
|
-
label:
|
|
17392
|
-
supportedThinkingOptionIds:
|
|
18219
|
+
models: available.map((model2) => ({
|
|
18220
|
+
ref: encodeModel(model2.ref),
|
|
18221
|
+
label: model2.label,
|
|
18222
|
+
supportedThinkingOptionIds: model2.reasoning?.enabled ? model2.reasoning.levels.map((level) => level.value) : []
|
|
17393
18223
|
})),
|
|
17394
|
-
...current && available.some((
|
|
18224
|
+
...current && available.some((model2) => encodeModel(model2.ref).id === current.id) ? { defaultModel: current } : {},
|
|
17395
18225
|
thinkingOptions: [...levels.values()].map((level) => ({ id: level.value, label: level.label })),
|
|
17396
18226
|
...defaultThinking && levels.has(defaultThinking) ? { defaultThinkingOptionId: defaultThinking } : {}
|
|
17397
18227
|
});
|
|
@@ -17416,7 +18246,7 @@ function permissionModes(current = "build") {
|
|
|
17416
18246
|
function sessionState(snapshot, locator) {
|
|
17417
18247
|
const settings = snapshot.settings;
|
|
17418
18248
|
const current = settings.model.current ? encodeModel(settings.model.current) : void 0;
|
|
17419
|
-
const
|
|
18249
|
+
const model2 = settings.model.available.find((candidate) => encodeModel(candidate.ref).id === current?.id);
|
|
17420
18250
|
return {
|
|
17421
18251
|
nativeRef: nativeSessionRefSchema.parse({
|
|
17422
18252
|
harnessId: ZCODE_ID,
|
|
@@ -17425,7 +18255,7 @@ function sessionState(snapshot, locator) {
|
|
|
17425
18255
|
locator: { ...locator, cwd: snapshot.session.workspace.workspacePath }
|
|
17426
18256
|
}),
|
|
17427
18257
|
...current && settings.model.current?.providerId !== "zcode-unconfigured" ? { effectiveModel: current } : {},
|
|
17428
|
-
...
|
|
18258
|
+
...model2 ? { resolvedModelLabel: model2.label } : {},
|
|
17429
18259
|
...settings.thoughtLevel.enabled && settings.thoughtLevel.current ? {
|
|
17430
18260
|
effectiveThinkingOptionId: harnessThinkingOptionIdSchema.parse(settings.thoughtLevel.current)
|
|
17431
18261
|
} : {},
|
|
@@ -17439,7 +18269,7 @@ function sessionState(snapshot, locator) {
|
|
|
17439
18269
|
function sessionUsage(snapshot, catalog) {
|
|
17440
18270
|
const runtime = runtimeUsageSchema.safeParse(snapshot.runtime).data?.contextUsage;
|
|
17441
18271
|
const current = snapshot.settings.model.current;
|
|
17442
|
-
const window = catalog.model.available.find((
|
|
18272
|
+
const window = catalog.model.available.find((model2) => model2.ref.providerId === current?.providerId && model2.ref.modelId === current.modelId)?.contextWindow ?? snapshot.projection.contextWindow;
|
|
17443
18273
|
const cache = runtime?.cache;
|
|
17444
18274
|
const usage = {
|
|
17445
18275
|
...window > 0 ? {
|
|
@@ -17555,16 +18385,16 @@ var Diff = class {
|
|
|
17555
18385
|
}
|
|
17556
18386
|
}
|
|
17557
18387
|
}
|
|
17558
|
-
addToPath(
|
|
17559
|
-
const last =
|
|
18388
|
+
addToPath(path7, added, removed, oldPosInc, options) {
|
|
18389
|
+
const last = path7.lastComponent;
|
|
17560
18390
|
if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
|
|
17561
18391
|
return {
|
|
17562
|
-
oldPos:
|
|
18392
|
+
oldPos: path7.oldPos + oldPosInc,
|
|
17563
18393
|
lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
|
|
17564
18394
|
};
|
|
17565
18395
|
} else {
|
|
17566
18396
|
return {
|
|
17567
|
-
oldPos:
|
|
18397
|
+
oldPos: path7.oldPos + oldPosInc,
|
|
17568
18398
|
lastComponent: { count: 1, added, removed, previousComponent: last }
|
|
17569
18399
|
};
|
|
17570
18400
|
}
|
|
@@ -18625,6 +19455,7 @@ var ZcodeSession = class {
|
|
|
18625
19455
|
};
|
|
18626
19456
|
#state;
|
|
18627
19457
|
#snapshot;
|
|
19458
|
+
#usage;
|
|
18628
19459
|
#active;
|
|
18629
19460
|
#pendingInteractions = /* @__PURE__ */ new Map();
|
|
18630
19461
|
#closed = false;
|
|
@@ -18643,6 +19474,7 @@ var ZcodeSession = class {
|
|
|
18643
19474
|
this.capabilities = ZCODE_CAPABILITIES;
|
|
18644
19475
|
this.catalog = modelCatalog(nativeCatalog);
|
|
18645
19476
|
this.#snapshot = snapshot;
|
|
19477
|
+
this.#usage = new ZcodeUsage(snapshot.session.sessionId, (event) => this.#emit(event));
|
|
18646
19478
|
this.#goalActive = (snapshot.target === void 0 ? snapshot.projection.target : snapshot.target)?.status === "active";
|
|
18647
19479
|
this.#state = sessionState(snapshot, transport.locator);
|
|
18648
19480
|
this.initialState = structuredClone(this.#state);
|
|
@@ -18660,6 +19492,7 @@ var ZcodeSession = class {
|
|
|
18660
19492
|
this.#channel.emit({ kind: "event", event });
|
|
18661
19493
|
}
|
|
18662
19494
|
async subscribe() {
|
|
19495
|
+
this.#usage.replay(this.#snapshot.messages, true);
|
|
18663
19496
|
await this.transport.listen("onDynamicSessionEvent", {
|
|
18664
19497
|
sessionId: this.sessionId,
|
|
18665
19498
|
deliveryKind: "desktop-continuous",
|
|
@@ -18803,7 +19636,7 @@ var ZcodeSession = class {
|
|
|
18803
19636
|
try {
|
|
18804
19637
|
let method, params;
|
|
18805
19638
|
if (command.type === "model.select") {
|
|
18806
|
-
if (!this.catalog.models.some((
|
|
19639
|
+
if (!this.catalog.models.some((model2) => model2.ref.id === command.model.id))
|
|
18807
19640
|
return failure("invalidRequest", "ZCode model is not available");
|
|
18808
19641
|
method = "setModel";
|
|
18809
19642
|
params = {
|
|
@@ -18942,6 +19775,7 @@ var ZcodeSession = class {
|
|
|
18942
19775
|
if (event.seq <= this.#lastSeq)
|
|
18943
19776
|
return;
|
|
18944
19777
|
this.#lastSeq = event.seq;
|
|
19778
|
+
this.#usage.observe(event);
|
|
18945
19779
|
if (event.type === "session.updated" && event.payload && Object.hasOwn(event.payload, "target"))
|
|
18946
19780
|
this.#goalActive = record2(event.payload.target).status === "active";
|
|
18947
19781
|
if (event.type === "turn.started") {
|
|
@@ -19016,6 +19850,9 @@ var ZcodeSession = class {
|
|
|
19016
19850
|
} : turn?.outcome;
|
|
19017
19851
|
if (!outcome || outcome.status === "unknown")
|
|
19018
19852
|
throw new ZcodeError("protocolError", "ZCode completed without a confirmed turn outcome");
|
|
19853
|
+
if (this.#active !== active || this.#closed || this.#faulted)
|
|
19854
|
+
return;
|
|
19855
|
+
this.#usage.replay(snapshot.messages, false);
|
|
19019
19856
|
this.#finish(active, {
|
|
19020
19857
|
...outcome,
|
|
19021
19858
|
...turn?.checkpoint ? { checkpoint: turn.checkpoint } : {}
|
|
@@ -19130,8 +19967,10 @@ var ZcodeAdapter = class {
|
|
|
19130
19967
|
// One verification page and SDK instance for the whole Host, as in ZCode Desktop.
|
|
19131
19968
|
#verifier;
|
|
19132
19969
|
#prewarmed = false;
|
|
19970
|
+
usageStatistics;
|
|
19133
19971
|
constructor(options = {}) {
|
|
19134
19972
|
this.options = options;
|
|
19973
|
+
this.usageStatistics = createZcodeUsageStatistics(options.environment ?? process.env);
|
|
19135
19974
|
}
|
|
19136
19975
|
#sharedVerifier = (appVersion) => this.#verifier ??= (this.options.createVerifier ?? createZcodeVerifier)({
|
|
19137
19976
|
appVersion,
|
|
@@ -19163,7 +20002,7 @@ var ZcodeAdapter = class {
|
|
|
19163
20002
|
async inspect(input = {}) {
|
|
19164
20003
|
let transport;
|
|
19165
20004
|
try {
|
|
19166
|
-
transport = await this.#transport(
|
|
20005
|
+
transport = await this.#transport(path6.resolve(input.cwd ?? process.cwd()));
|
|
19167
20006
|
const settings = await readCatalog(transport);
|
|
19168
20007
|
const catalog = modelCatalog(settings);
|
|
19169
20008
|
if (!catalog.models.length)
|
|
@@ -19171,7 +20010,7 @@ var ZcodeAdapter = class {
|
|
|
19171
20010
|
status: "unavailable",
|
|
19172
20011
|
error: {
|
|
19173
20012
|
code: "authenticationRequired",
|
|
19174
|
-
message: "ZCode has no available models.
|
|
20013
|
+
message: "ZCode has no available models. Connect Start Plan or Personal Coding Plan in ZCode Desktop, or add a personal provider, then re-detect ZCode. Team Coding Plan is not supported.",
|
|
19175
20014
|
retryable: true
|
|
19176
20015
|
}
|
|
19177
20016
|
};
|
|
@@ -19209,18 +20048,18 @@ var ZcodeAdapter = class {
|
|
|
19209
20048
|
let transport;
|
|
19210
20049
|
let createdId;
|
|
19211
20050
|
try {
|
|
19212
|
-
transport = await this.#transport(
|
|
20051
|
+
transport = await this.#transport(path6.resolve(input.cwd), input.environment);
|
|
19213
20052
|
let snapshot, settings;
|
|
19214
20053
|
if (input.kind === "create") {
|
|
19215
20054
|
settings = await readCatalog(transport);
|
|
19216
20055
|
if (input.permissionModeId && !permissionModes().modes.some((m) => m.id === input.permissionModeId))
|
|
19217
20056
|
throw new ZcodeError("invalidRequest", "Unknown ZCode permission mode");
|
|
19218
|
-
const
|
|
20057
|
+
const model2 = input.model ? selectNativeModel(input.model, settings, input.thinkingOptionId) : void 0;
|
|
19219
20058
|
const mode = input.executionPolicy === "unattended-full-access" ? "yolo" : input.permissionModeId;
|
|
19220
20059
|
const created = await transport.command(null, "createSession", {
|
|
19221
20060
|
workspaceId: input.cwd,
|
|
19222
20061
|
config: {
|
|
19223
|
-
...
|
|
20062
|
+
...model2 ? { modelSelection: model2 } : {},
|
|
19224
20063
|
...mode ? { mode } : {},
|
|
19225
20064
|
...input.thinkingOptionId ? { thought: input.thinkingOptionId } : {}
|
|
19226
20065
|
}
|