@codexhost/cli-linux-arm64 0.12.2 → 0.13.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 +319 -64
- package/app/console-web.js +5089 -1367
- package/app/desktop-controller.mjs +259 -41
- package/app/host-runtime.mjs +5735 -1564
- package/app/plugins/antigravity/manifest.json +18 -1
- package/app/plugins/antigravity/plugin.mjs +282 -41
- package/app/plugins/claude-code/manifest.json +28 -0
- package/app/plugins/claude-code/plugin.mjs +35300 -23918
- package/app/plugins/codebuddy/manifest.json +17 -0
- package/app/plugins/codebuddy/plugin.mjs +5971 -5355
- package/app/plugins/codex-usage/manifest.json +9 -0
- package/app/plugins/codex-usage/plugin.mjs +17324 -0
- package/app/plugins/cursor-cli/manifest.json +17 -0
- package/app/plugins/cursor-cli/plugin.mjs +357 -76
- 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 +822 -241
- package/app/plugins/enabled.json +2 -1
- package/app/plugins/grok/manifest.json +21 -1
- package/app/plugins/grok/plugin.mjs +918 -258
- package/app/plugins/hermes/assets/icon.png +0 -0
- package/app/plugins/hermes/manifest.json +30 -2
- package/app/plugins/hermes/plugin.mjs +284 -32
- 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 +561 -35
- 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 +290 -21
- package/app/plugins/omp/manifest.json +21 -1
- package/app/plugins/omp/plugin.mjs +2765 -1960
- package/app/plugins/opencode/manifest.json +18 -1
- package/app/plugins/opencode/plugin.mjs +723 -146
- 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 +634 -80
- package/app/plugins/qoder-cn/manifest.json +18 -1
- package/app/plugins/qoder-cn/plugin.mjs +634 -80
- package/app/plugins/workbuddy/manifest.json +18 -0
- package/app/plugins/workbuddy/plugin.mjs +6361 -5747
- package/app/plugins/zcode/manifest.json +19 -1
- package/app/plugins/zcode/plugin.mjs +1098 -259
- package/app/renderer-extension.js +13080 -8884
- package/bin/codexhost +0 -0
- package/libexec/codexhost-shim +0 -0
- package/libexec/codexhost-updater +0 -0
- package/licenses/Cordis-LICENSE.txt +21 -0
- package/licenses/Cosmokit-LICENSE.txt +21 -0
- package/package.json +1 -1
- package/app/plugins/kiro-cli/assets/icon.svg +0 -5
|
@@ -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"
|
|
@@ -14640,6 +14988,10 @@ var CONSOLE_HOST_METHODS = Object.freeze([
|
|
|
14640
14988
|
"codexhost/account/list",
|
|
14641
14989
|
"codexhost/account/refresh",
|
|
14642
14990
|
"codexhost/account/usage/inspect",
|
|
14991
|
+
"codexhost/usage/model-prices/get",
|
|
14992
|
+
"codexhost/usage/model-prices/set",
|
|
14993
|
+
"codexhost/usage/model-prices/default",
|
|
14994
|
+
"codexhost/usage/statistics/get",
|
|
14643
14995
|
"codexhost/update/check",
|
|
14644
14996
|
"codexhost/update/start",
|
|
14645
14997
|
"codexhost/update/status"
|
|
@@ -14704,6 +15056,7 @@ var threadUsageSnapshotSchema = external_exports.object({
|
|
|
14704
15056
|
cacheWriteInputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
14705
15057
|
outputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
14706
15058
|
outputTokensPerSecond: finiteNonNegativeNumberSchema.optional(),
|
|
15059
|
+
apiOutputTokensPerSecond: finiteNonNegativeNumberSchema.optional(),
|
|
14707
15060
|
reasoningOutputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
14708
15061
|
totalTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
14709
15062
|
totalCostUsd: finiteNonNegativeNumberSchema.optional(),
|
|
@@ -14715,7 +15068,11 @@ var threadUsageSnapshotSchema = external_exports.object({
|
|
|
14715
15068
|
planFiveHourUsedPercent: cacheHitRatePercentSchema.optional(),
|
|
14716
15069
|
planFiveHourResetsAtUnix: nonNegativeSafeIntegerSchema.optional(),
|
|
14717
15070
|
planSevenDayUsedPercent: cacheHitRatePercentSchema.optional(),
|
|
14718
|
-
planSevenDayResetsAtUnix: nonNegativeSafeIntegerSchema.optional()
|
|
15071
|
+
planSevenDayResetsAtUnix: nonNegativeSafeIntegerSchema.optional(),
|
|
15072
|
+
sessionCacheHitRatePercent: cacheHitRatePercentSchema.optional(),
|
|
15073
|
+
timeToFirstOutputMs: nonNegativeSafeIntegerSchema.optional(),
|
|
15074
|
+
costSource: external_exports.enum(["publicPrice", "native"]).optional(),
|
|
15075
|
+
unpricedModels: external_exports.array(external_exports.string().min(1)).min(1).optional()
|
|
14719
15076
|
}).strict().superRefine((usage, context) => {
|
|
14720
15077
|
if (Object.keys(usage).length === 0) {
|
|
14721
15078
|
context.addIssue({ code: "custom", message: "Thread Usage must contain a reliable field" });
|
|
@@ -14736,6 +15093,20 @@ var threadUsageSnapshotSchema = external_exports.object({
|
|
|
14736
15093
|
path: ["contextWindowTokens"]
|
|
14737
15094
|
});
|
|
14738
15095
|
}
|
|
15096
|
+
if (usage.costSource !== void 0 && usage.totalCostUsd === void 0) {
|
|
15097
|
+
context.addIssue({
|
|
15098
|
+
code: "custom",
|
|
15099
|
+
message: "Thread Usage costSource must be provided with totalCostUsd",
|
|
15100
|
+
path: ["costSource"]
|
|
15101
|
+
});
|
|
15102
|
+
}
|
|
15103
|
+
if (usage.unpricedModels !== void 0 && usage.costSource !== "publicPrice") {
|
|
15104
|
+
context.addIssue({
|
|
15105
|
+
code: "custom",
|
|
15106
|
+
message: "Thread Usage unpricedModels must be provided with a publicPrice cost",
|
|
15107
|
+
path: ["unpricedModels"]
|
|
15108
|
+
});
|
|
15109
|
+
}
|
|
14739
15110
|
if (usage.planFiveHourResetsAtUnix !== void 0 && usage.planFiveHourUsedPercent === void 0) {
|
|
14740
15111
|
context.addIssue({
|
|
14741
15112
|
code: "custom",
|
|
@@ -14990,27 +15361,27 @@ var harnessModelCatalogSchema = external_exports.object({
|
|
|
14990
15361
|
}).strict().superRefine((catalog, context) => {
|
|
14991
15362
|
const refs = /* @__PURE__ */ new Set();
|
|
14992
15363
|
const thinkingIds = new Set(catalog.thinkingOptions.map(({ id }) => id));
|
|
14993
|
-
for (const [index,
|
|
14994
|
-
if (refs.has(
|
|
15364
|
+
for (const [index, model2] of catalog.models.entries()) {
|
|
15365
|
+
if (refs.has(model2.ref.id)) {
|
|
14995
15366
|
context.addIssue({
|
|
14996
15367
|
code: "custom",
|
|
14997
15368
|
message: "Model Catalog refs must be unique",
|
|
14998
15369
|
path: ["models", index, "ref", "id"]
|
|
14999
15370
|
});
|
|
15000
15371
|
}
|
|
15001
|
-
refs.add(
|
|
15002
|
-
if (
|
|
15003
|
-
if (refs.has(
|
|
15372
|
+
refs.add(model2.ref.id);
|
|
15373
|
+
if (model2.fastModel) {
|
|
15374
|
+
if (refs.has(model2.fastModel.id) || catalog.models.some((entry) => entry.ref.id === model2.fastModel?.id)) {
|
|
15004
15375
|
context.addIssue({
|
|
15005
15376
|
code: "custom",
|
|
15006
15377
|
message: "Fast Model refs must be distinct and unique",
|
|
15007
15378
|
path: ["models", index, "fastModel"]
|
|
15008
15379
|
});
|
|
15009
15380
|
}
|
|
15010
|
-
refs.add(
|
|
15381
|
+
refs.add(model2.fastModel.id);
|
|
15011
15382
|
}
|
|
15012
15383
|
const supportedThinkingIds = /* @__PURE__ */ new Set();
|
|
15013
|
-
for (const [optionIndex, optionId] of (
|
|
15384
|
+
for (const [optionIndex, optionId] of (model2.supportedThinkingOptionIds ?? []).entries()) {
|
|
15014
15385
|
if (supportedThinkingIds.has(optionId)) {
|
|
15015
15386
|
context.addIssue({
|
|
15016
15387
|
code: "custom",
|
|
@@ -15204,13 +15575,40 @@ var HARNESS_PLUGIN_LIMIT = 128;
|
|
|
15204
15575
|
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);
|
|
15205
15576
|
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");
|
|
15206
15577
|
var documentationUrlSchema = external_exports.url().refine((value) => /^https:\/\/[^/?#@]+(?:[/?#]|$)/iu.test(value), "Plugin documentation links must be credential-free HTTPS URLs");
|
|
15578
|
+
var localizedTextSchema = external_exports.object({ en: external_exports.string().max(4096), "zh-CN": external_exports.string().max(4096).optional() }).strict();
|
|
15579
|
+
var harnessInstallationGuideSchema = external_exports.object({
|
|
15580
|
+
commands: external_exports.array(external_exports.object({ terminal: external_exports.string().max(256), command: external_exports.string().max(4096) }).strict()).max(8),
|
|
15581
|
+
before: localizedTextSchema.optional(),
|
|
15582
|
+
after: localizedTextSchema.optional(),
|
|
15583
|
+
downloads: external_exports.array(external_exports.object({ label: external_exports.string().max(128), url: documentationUrlSchema }).strict()).max(8).optional()
|
|
15584
|
+
}).strict();
|
|
15207
15585
|
var pluginPresentationShape = {
|
|
15208
15586
|
id: harnessPluginIdSchema,
|
|
15209
15587
|
name: external_exports.string().trim().min(1).max(128),
|
|
15210
15588
|
version: external_exports.string().min(1).max(128),
|
|
15589
|
+
/** Capability-only plugin; omitted for existing session-capable plugins. */
|
|
15590
|
+
kind: external_exports.literal("usage").optional(),
|
|
15591
|
+
/** Original image styling or bounded vector paths; never arbitrary CSS/SVG markup. */
|
|
15592
|
+
iconStyle: external_exports.object({
|
|
15593
|
+
vector: external_exports.object({
|
|
15594
|
+
viewBox: external_exports.string().max(128).regex(/^-?\d+(?:\.\d+)?(?: +-?\d+(?:\.\d+)?){3}$/u),
|
|
15595
|
+
color: external_exports.string().regex(/^(?:currentColor|#[a-f0-9]{6})$/iu),
|
|
15596
|
+
paths: external_exports.array(external_exports.object({
|
|
15597
|
+
d: external_exports.string().min(1).max(32768).regex(/^[MmLlHhVvCcSsQqTtAaZz\d.,+eE\s-]+$/u),
|
|
15598
|
+
fillRule: external_exports.enum(["evenodd", "nonzero"]).optional(),
|
|
15599
|
+
fill: external_exports.string().regex(/^(?:currentColor|#[a-f0-9]{6})$/iu).optional()
|
|
15600
|
+
}).strict()).min(1).max(32)
|
|
15601
|
+
}).strict().optional(),
|
|
15602
|
+
background: external_exports.string().regex(/^#[a-f0-9]{6}$/iu).optional(),
|
|
15603
|
+
borderRadius: external_exports.number().min(0).max(50).optional(),
|
|
15604
|
+
paddingRatio: external_exports.number().min(0).max(0.25).optional()
|
|
15605
|
+
}).strict().optional(),
|
|
15606
|
+
installation: harnessInstallationGuideSchema.optional(),
|
|
15607
|
+
notice: localizedTextSchema.optional(),
|
|
15211
15608
|
/** The factory accepts a persisted local entrypoint through its construction context. */
|
|
15212
15609
|
launchCommand: external_exports.literal(true).optional(),
|
|
15213
15610
|
links: external_exports.object({
|
|
15611
|
+
website: documentationUrlSchema.optional(),
|
|
15214
15612
|
documentation: documentationUrlSchema.optional(),
|
|
15215
15613
|
installation: documentationUrlSchema.optional()
|
|
15216
15614
|
}).strict().optional()
|
|
@@ -15629,6 +16027,11 @@ var codexSshDraftSchema = external_exports.strictObject({
|
|
|
15629
16027
|
});
|
|
15630
16028
|
var remoteConnectionsRequestSchema = external_exports.discriminatedUnion("action", [
|
|
15631
16029
|
external_exports.strictObject({ action: external_exports.literal("list") }),
|
|
16030
|
+
external_exports.strictObject({
|
|
16031
|
+
action: external_exports.literal("read-thread"),
|
|
16032
|
+
hostId: hostId.refine((id) => id !== "local"),
|
|
16033
|
+
input: delegationReadParamsSchema
|
|
16034
|
+
}),
|
|
15632
16035
|
external_exports.strictObject({
|
|
15633
16036
|
action: external_exports.literal("save"),
|
|
15634
16037
|
draft: codexSshDraftSchema,
|
|
@@ -15652,10 +16055,6 @@ var remoteConnectionsReplySchema = external_exports.union([
|
|
|
15652
16055
|
// ../../shared-contracts/dist/index.js
|
|
15653
16056
|
var workspaceContractVersionSchema = external_exports.literal(WORKSPACE_CONTRACT_VERSION);
|
|
15654
16057
|
|
|
15655
|
-
// dist/transport.js
|
|
15656
|
-
import { spawn } from "node:child_process";
|
|
15657
|
-
import { randomUUID } from "node:crypto";
|
|
15658
|
-
|
|
15659
16058
|
// ../../harness-adapter/dist/approval.js
|
|
15660
16059
|
function invalidRequest(message) {
|
|
15661
16060
|
return { code: "invalidRequest", message, retryable: false };
|
|
@@ -15771,10 +16170,12 @@ var tokenFields = [
|
|
|
15771
16170
|
];
|
|
15772
16171
|
var safeIntegerFields = [
|
|
15773
16172
|
"planFiveHourResetsAtUnix",
|
|
15774
|
-
"planSevenDayResetsAtUnix"
|
|
16173
|
+
"planSevenDayResetsAtUnix",
|
|
16174
|
+
"timeToFirstOutputMs"
|
|
15775
16175
|
];
|
|
15776
16176
|
var percentFields = [
|
|
15777
16177
|
"cacheHitRatePercent",
|
|
16178
|
+
"sessionCacheHitRatePercent",
|
|
15778
16179
|
"planFiveHourUsedPercent",
|
|
15779
16180
|
"planSevenDayUsedPercent"
|
|
15780
16181
|
];
|
|
@@ -15782,10 +16183,14 @@ var usageFields = /* @__PURE__ */ new Set([
|
|
|
15782
16183
|
...tokenFields,
|
|
15783
16184
|
...safeIntegerFields,
|
|
15784
16185
|
...percentFields,
|
|
16186
|
+
"sessionCacheUsage",
|
|
15785
16187
|
"totalCostUsd",
|
|
15786
16188
|
"totalCredits",
|
|
15787
16189
|
"contextUsagePercent",
|
|
15788
|
-
"outputTokensPerSecond"
|
|
16190
|
+
"outputTokensPerSecond",
|
|
16191
|
+
"apiOutputTokensPerSecond",
|
|
16192
|
+
"costSource",
|
|
16193
|
+
"unpricedModels"
|
|
15789
16194
|
]);
|
|
15790
16195
|
function isRecord(value) {
|
|
15791
16196
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -15801,7 +16206,11 @@ function parseHostUsage(value) {
|
|
|
15801
16206
|
throw new Error(`Harness Usage contains unknown field '${key}'`);
|
|
15802
16207
|
}
|
|
15803
16208
|
}
|
|
15804
|
-
for (const field2 of [
|
|
16209
|
+
for (const field2 of [
|
|
16210
|
+
"totalCredits",
|
|
16211
|
+
"contextUsagePercent",
|
|
16212
|
+
"apiOutputTokensPerSecond"
|
|
16213
|
+
]) {
|
|
15805
16214
|
const candidate = value[field2];
|
|
15806
16215
|
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
|
|
15807
16216
|
throw new Error(`Harness Usage '${field2}' must be a finite non-negative number`);
|
|
@@ -15831,6 +16240,12 @@ function parseHostUsage(value) {
|
|
|
15831
16240
|
throw new Error(`Harness Usage '${field2}' must be between 0 and 100`);
|
|
15832
16241
|
}
|
|
15833
16242
|
}
|
|
16243
|
+
if (value.sessionCacheUsage !== void 0) {
|
|
16244
|
+
const totals2 = value.sessionCacheUsage;
|
|
16245
|
+
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) {
|
|
16246
|
+
throw new Error("Harness Usage 'sessionCacheUsage' must contain complete bounded token totals");
|
|
16247
|
+
}
|
|
16248
|
+
}
|
|
15834
16249
|
const hasContextUsed = value.contextUsedTokens !== void 0;
|
|
15835
16250
|
const hasContextWindow = value.contextWindowTokens !== void 0;
|
|
15836
16251
|
if (hasContextUsed !== hasContextWindow) {
|
|
@@ -15845,8 +16260,333 @@ function parseHostUsage(value) {
|
|
|
15845
16260
|
if (value.planSevenDayResetsAtUnix !== void 0 && value.planSevenDayUsedPercent === void 0) {
|
|
15846
16261
|
throw new Error("Harness Usage 'planSevenDayResetsAtUnix' must be provided with 'planSevenDayUsedPercent'");
|
|
15847
16262
|
}
|
|
16263
|
+
if (value.costSource !== void 0) {
|
|
16264
|
+
if (value.costSource !== "publicPrice" && value.costSource !== "native") {
|
|
16265
|
+
throw new Error("Harness Usage 'costSource' must be 'publicPrice' or 'native'");
|
|
16266
|
+
}
|
|
16267
|
+
if (value.totalCostUsd === void 0) {
|
|
16268
|
+
throw new Error("Harness Usage 'costSource' must be provided with 'totalCostUsd'");
|
|
16269
|
+
}
|
|
16270
|
+
}
|
|
16271
|
+
if (value.unpricedModels !== void 0) {
|
|
16272
|
+
const models = value.unpricedModels;
|
|
16273
|
+
if (!Array.isArray(models) || models.length === 0 || !models.every((model2) => typeof model2 === "string" && model2.length > 0)) {
|
|
16274
|
+
throw new Error("Harness Usage 'unpricedModels' must be a non-empty list of Model IDs");
|
|
16275
|
+
}
|
|
16276
|
+
if (value.costSource !== "publicPrice") {
|
|
16277
|
+
throw new Error("Harness Usage 'unpricedModels' must be provided with a 'publicPrice' cost");
|
|
16278
|
+
}
|
|
16279
|
+
return { ...value, unpricedModels: [...models] };
|
|
16280
|
+
}
|
|
15848
16281
|
return { ...value };
|
|
15849
16282
|
}
|
|
16283
|
+
var requestTokenFields = [
|
|
16284
|
+
"inputTokens",
|
|
16285
|
+
"cachedInputTokens",
|
|
16286
|
+
"cacheWriteInputTokens",
|
|
16287
|
+
"cacheWrite1hInputTokens",
|
|
16288
|
+
"outputTokens",
|
|
16289
|
+
"reasoningOutputTokens",
|
|
16290
|
+
"startedAtMs",
|
|
16291
|
+
"completedAtMs"
|
|
16292
|
+
];
|
|
16293
|
+
var requestFields = /* @__PURE__ */ new Set([
|
|
16294
|
+
...requestTokenFields,
|
|
16295
|
+
"requestId",
|
|
16296
|
+
"historical",
|
|
16297
|
+
"model",
|
|
16298
|
+
"provider"
|
|
16299
|
+
]);
|
|
16300
|
+
function parseHostUsageRequest(value) {
|
|
16301
|
+
if (!isRecord(value))
|
|
16302
|
+
throw new Error("Harness Usage request must be an object");
|
|
16303
|
+
for (const key of Object.keys(value)) {
|
|
16304
|
+
if (!requestFields.has(key)) {
|
|
16305
|
+
throw new Error(`Harness Usage request contains unknown field '${key}'`);
|
|
16306
|
+
}
|
|
16307
|
+
}
|
|
16308
|
+
if (typeof value.requestId !== "string" || value.requestId.length === 0) {
|
|
16309
|
+
throw new Error("Harness Usage request 'requestId' must be a non-empty string");
|
|
16310
|
+
}
|
|
16311
|
+
for (const field2 of ["model", "provider"]) {
|
|
16312
|
+
const candidate = value[field2];
|
|
16313
|
+
if (candidate !== void 0 && (typeof candidate !== "string" || candidate.length === 0)) {
|
|
16314
|
+
throw new Error(`Harness Usage request '${field2}' must be a non-empty string`);
|
|
16315
|
+
}
|
|
16316
|
+
}
|
|
16317
|
+
if (value.historical !== void 0 && typeof value.historical !== "boolean") {
|
|
16318
|
+
throw new Error("Harness Usage request 'historical' must be a boolean");
|
|
16319
|
+
}
|
|
16320
|
+
for (const field2 of requestTokenFields) {
|
|
16321
|
+
const candidate = value[field2];
|
|
16322
|
+
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
|
|
16323
|
+
throw new Error(`Harness Usage request '${field2}' must be a non-negative safe integer`);
|
|
16324
|
+
}
|
|
16325
|
+
}
|
|
16326
|
+
if (value.inputTokens === void 0 || value.outputTokens === void 0) {
|
|
16327
|
+
throw new Error("Harness Usage request must contain 'inputTokens' and 'outputTokens'");
|
|
16328
|
+
}
|
|
16329
|
+
const request = value;
|
|
16330
|
+
if ((request.cachedInputTokens ?? 0) + (request.cacheWriteInputTokens ?? 0) > request.inputTokens) {
|
|
16331
|
+
throw new Error("Harness Usage request cache Tokens must not exceed 'inputTokens'");
|
|
16332
|
+
}
|
|
16333
|
+
if ((request.reasoningOutputTokens ?? 0) > request.outputTokens) {
|
|
16334
|
+
throw new Error("Harness Usage request 'reasoningOutputTokens' must not exceed 'outputTokens'");
|
|
16335
|
+
}
|
|
16336
|
+
if (request.cacheWrite1hInputTokens !== void 0 && request.cacheWrite1hInputTokens > (request.cacheWriteInputTokens ?? -1)) {
|
|
16337
|
+
throw new Error("Harness Usage request 'cacheWrite1hInputTokens' must not exceed 'cacheWriteInputTokens'");
|
|
16338
|
+
}
|
|
16339
|
+
if (request.startedAtMs === void 0 !== (request.completedAtMs === void 0)) {
|
|
16340
|
+
throw new Error("Harness Usage request timing fields must be provided together");
|
|
16341
|
+
}
|
|
16342
|
+
if (request.startedAtMs !== void 0 && request.completedAtMs !== void 0 && request.completedAtMs < request.startedAtMs) {
|
|
16343
|
+
throw new Error("Harness Usage request 'completedAtMs' must not precede 'startedAtMs'");
|
|
16344
|
+
}
|
|
16345
|
+
return { ...request };
|
|
16346
|
+
}
|
|
16347
|
+
|
|
16348
|
+
// dist/usage.js
|
|
16349
|
+
function requestTokens(id, model2, value) {
|
|
16350
|
+
const tokens = record2(value), cache = record2(tokens.cache);
|
|
16351
|
+
const request = parseHostUsageRequest({
|
|
16352
|
+
requestId: id,
|
|
16353
|
+
...model2 ? { model: model2 } : {},
|
|
16354
|
+
inputTokens: tokens.input,
|
|
16355
|
+
outputTokens: tokens.output,
|
|
16356
|
+
...cache.read !== void 0 ? { cachedInputTokens: cache.read } : {},
|
|
16357
|
+
...cache.write !== void 0 ? { cacheWriteInputTokens: cache.write } : {},
|
|
16358
|
+
...tokens.reasoning !== void 0 ? { reasoningOutputTokens: tokens.reasoning } : {}
|
|
16359
|
+
});
|
|
16360
|
+
if (!Number.isSafeInteger(tokens.total) || tokens.total !== request.inputTokens + request.outputTokens)
|
|
16361
|
+
throw new Error("ZCode request token convention is unknown");
|
|
16362
|
+
return request;
|
|
16363
|
+
}
|
|
16364
|
+
function zcodeUsageRecord(message) {
|
|
16365
|
+
const info = message.info;
|
|
16366
|
+
if (info.role !== "assistant" || info.synthetic === true || info.semantics?.origin === "system")
|
|
16367
|
+
return { kind: "none" };
|
|
16368
|
+
if (info.time.completed === void 0)
|
|
16369
|
+
return { kind: "missing" };
|
|
16370
|
+
const tokens = record2(info.tokens), cache = record2(tokens.cache);
|
|
16371
|
+
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)
|
|
16372
|
+
return { kind: "none" };
|
|
16373
|
+
try {
|
|
16374
|
+
return {
|
|
16375
|
+
kind: "request",
|
|
16376
|
+
request: requestTokens(info.messageId, info.model?.modelId, info.tokens)
|
|
16377
|
+
};
|
|
16378
|
+
} catch {
|
|
16379
|
+
return { kind: "missing" };
|
|
16380
|
+
}
|
|
16381
|
+
}
|
|
16382
|
+
var ZcodeUsage = class {
|
|
16383
|
+
sessionId;
|
|
16384
|
+
emit;
|
|
16385
|
+
#seen = /* @__PURE__ */ new Map();
|
|
16386
|
+
#pending;
|
|
16387
|
+
#timings = /* @__PURE__ */ new Map();
|
|
16388
|
+
#complete = true;
|
|
16389
|
+
constructor(sessionId, emit) {
|
|
16390
|
+
this.sessionId = sessionId;
|
|
16391
|
+
this.emit = emit;
|
|
16392
|
+
}
|
|
16393
|
+
invalidate() {
|
|
16394
|
+
if (!this.#complete)
|
|
16395
|
+
return;
|
|
16396
|
+
this.#complete = false;
|
|
16397
|
+
this.emit({ type: "usage.history", complete: false });
|
|
16398
|
+
}
|
|
16399
|
+
replay(messages, historical) {
|
|
16400
|
+
for (const message of messages) {
|
|
16401
|
+
if (message.info.sessionId !== this.sessionId)
|
|
16402
|
+
continue;
|
|
16403
|
+
const result = zcodeUsageRecord(message);
|
|
16404
|
+
if (result.kind === "missing")
|
|
16405
|
+
this.invalidate();
|
|
16406
|
+
else if (result.kind === "request") {
|
|
16407
|
+
this.#publish({
|
|
16408
|
+
...result.request,
|
|
16409
|
+
...historical ? { historical: true } : this.#timings.get(result.request.requestId)
|
|
16410
|
+
});
|
|
16411
|
+
}
|
|
16412
|
+
}
|
|
16413
|
+
if (historical)
|
|
16414
|
+
this.emit({ type: "usage.history", complete: this.#complete });
|
|
16415
|
+
this.#pending = void 0;
|
|
16416
|
+
this.#timings.clear();
|
|
16417
|
+
}
|
|
16418
|
+
#publish(request) {
|
|
16419
|
+
if ((request.reasoningOutputTokens ?? 0) > 0) {
|
|
16420
|
+
request = { ...request };
|
|
16421
|
+
delete request.startedAtMs;
|
|
16422
|
+
delete request.completedAtMs;
|
|
16423
|
+
}
|
|
16424
|
+
const previous = this.#seen.get(request.requestId);
|
|
16425
|
+
if (previous) {
|
|
16426
|
+
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))
|
|
16427
|
+
this.invalidate();
|
|
16428
|
+
return;
|
|
16429
|
+
}
|
|
16430
|
+
this.#seen.set(request.requestId, request);
|
|
16431
|
+
this.emit({ type: "usage.request", request });
|
|
16432
|
+
}
|
|
16433
|
+
observe(event) {
|
|
16434
|
+
if (event.sessionId !== this.sessionId)
|
|
16435
|
+
return;
|
|
16436
|
+
const p = event.payload ?? {};
|
|
16437
|
+
if (event.type === "turn.started") {
|
|
16438
|
+
this.#pending = void 0;
|
|
16439
|
+
this.#timings.clear();
|
|
16440
|
+
return;
|
|
16441
|
+
}
|
|
16442
|
+
if (event.type === "model.streaming") {
|
|
16443
|
+
const pending2 = this.#pending;
|
|
16444
|
+
if (!pending2 || pending2.turnId !== event.turnId || p.source === "subagent")
|
|
16445
|
+
return;
|
|
16446
|
+
const id = text(p.assistantMessageId);
|
|
16447
|
+
if (!id)
|
|
16448
|
+
return;
|
|
16449
|
+
if (pending2.messageId && pending2.messageId !== id)
|
|
16450
|
+
pending2.ambiguous = true;
|
|
16451
|
+
pending2.messageId = id;
|
|
16452
|
+
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"))
|
|
16453
|
+
pending2.startedAtMs = event.timestamp;
|
|
16454
|
+
return;
|
|
16455
|
+
}
|
|
16456
|
+
if (event.type !== "session.updated" || p.querySource !== "main_turn")
|
|
16457
|
+
return;
|
|
16458
|
+
if (p.type === "model_request_started") {
|
|
16459
|
+
const id = text(p.requestId), model2 = text(p.modelId);
|
|
16460
|
+
if (!id || !model2)
|
|
16461
|
+
return;
|
|
16462
|
+
this.#pending = {
|
|
16463
|
+
id,
|
|
16464
|
+
model: model2,
|
|
16465
|
+
turnId: event.turnId,
|
|
16466
|
+
ambiguous: this.#pending !== void 0
|
|
16467
|
+
};
|
|
16468
|
+
return;
|
|
16469
|
+
}
|
|
16470
|
+
if (p.type !== "model_request_completed")
|
|
16471
|
+
return;
|
|
16472
|
+
const pending = this.#pending;
|
|
16473
|
+
if (!pending || pending.id !== p.requestId || pending.turnId !== event.turnId)
|
|
16474
|
+
return;
|
|
16475
|
+
this.#pending = void 0;
|
|
16476
|
+
if (pending.ambiguous || !pending.messageId || pending.model !== p.modelId)
|
|
16477
|
+
return;
|
|
16478
|
+
const start = pending.startedAtMs;
|
|
16479
|
+
if (start !== void 0 && Number.isSafeInteger(start) && Number.isSafeInteger(event.timestamp) && event.timestamp >= start)
|
|
16480
|
+
this.#timings.set(pending.messageId, {
|
|
16481
|
+
startedAtMs: start,
|
|
16482
|
+
completedAtMs: event.timestamp
|
|
16483
|
+
});
|
|
16484
|
+
const usage = record2(p.usage);
|
|
16485
|
+
if (usage.cacheReadTokens === void 0 || usage.cacheWriteTokens === void 0)
|
|
16486
|
+
return;
|
|
16487
|
+
try {
|
|
16488
|
+
const request = requestTokens(pending.messageId, pending.model, {
|
|
16489
|
+
input: usage.inputTokens,
|
|
16490
|
+
output: usage.outputTokens,
|
|
16491
|
+
total: usage.totalTokens,
|
|
16492
|
+
reasoning: usage.reasoningTokens,
|
|
16493
|
+
cache: { read: usage.cacheReadTokens, write: usage.cacheWriteTokens }
|
|
16494
|
+
});
|
|
16495
|
+
this.#publish({ ...request, ...this.#timings.get(pending.messageId) });
|
|
16496
|
+
} catch {
|
|
16497
|
+
this.invalidate();
|
|
16498
|
+
}
|
|
16499
|
+
}
|
|
16500
|
+
};
|
|
16501
|
+
|
|
16502
|
+
// dist/usage-statistics.js
|
|
16503
|
+
function zcodeDatabasePath(environment) {
|
|
16504
|
+
return path.join(environment.ZCODE_DATA_BASE_DIR?.trim() || environment.HOME || os.homedir(), ".zcode", "cli", "db", "db.sqlite");
|
|
16505
|
+
}
|
|
16506
|
+
async function readZcodeUsage(file2) {
|
|
16507
|
+
const { DatabaseSync } = await import("node:sqlite");
|
|
16508
|
+
const database = new DatabaseSync(file2, { readOnly: true });
|
|
16509
|
+
try {
|
|
16510
|
+
const entries = [];
|
|
16511
|
+
const directories = /* @__PURE__ */ new Map();
|
|
16512
|
+
const titles = /* @__PURE__ */ new Map();
|
|
16513
|
+
const hasSessions = database.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'session'").get();
|
|
16514
|
+
if (hasSessions) {
|
|
16515
|
+
const columns = new Set(database.prepare("PRAGMA table_info(session)").all().map((row) => String(row.name)));
|
|
16516
|
+
const titleColumn = columns.has("title") ? ", title" : "";
|
|
16517
|
+
for (const row of database.prepare(`SELECT id, directory${titleColumn} FROM session`).iterate()) {
|
|
16518
|
+
if (typeof row.directory === "string")
|
|
16519
|
+
directories.set(String(row.id), row.directory);
|
|
16520
|
+
const title = usageSessionTitle(row.title);
|
|
16521
|
+
if (title)
|
|
16522
|
+
titles.set(String(row.id), title);
|
|
16523
|
+
}
|
|
16524
|
+
}
|
|
16525
|
+
for (const row of database.prepare("SELECT id, session_id, data FROM message").iterate()) {
|
|
16526
|
+
let data;
|
|
16527
|
+
try {
|
|
16528
|
+
data = record2(JSON.parse(String(row.data)));
|
|
16529
|
+
} catch {
|
|
16530
|
+
continue;
|
|
16531
|
+
}
|
|
16532
|
+
if (data.role !== "assistant")
|
|
16533
|
+
continue;
|
|
16534
|
+
const modelId = text(data.modelId) || text(data.modelID);
|
|
16535
|
+
const providerId = text(data.providerId) || text(data.providerID);
|
|
16536
|
+
const parsed = messageSchema.safeParse({
|
|
16537
|
+
info: {
|
|
16538
|
+
...data,
|
|
16539
|
+
messageId: String(row.id),
|
|
16540
|
+
sessionId: String(row.session_id),
|
|
16541
|
+
...modelId && providerId ? { model: { providerId, modelId } } : {}
|
|
16542
|
+
},
|
|
16543
|
+
parts: []
|
|
16544
|
+
});
|
|
16545
|
+
if (!parsed.success)
|
|
16546
|
+
continue;
|
|
16547
|
+
const usage = zcodeUsageRecord(parsed.data);
|
|
16548
|
+
const at = nativeTimeMs(parsed.data.info.time.created);
|
|
16549
|
+
const entry = usage.kind === "request" && at !== null && usageEntryFromRequest(usage.request, at);
|
|
16550
|
+
if (entry) {
|
|
16551
|
+
const sessionId = String(row.session_id);
|
|
16552
|
+
entries.push(withUsageSession(entry, {
|
|
16553
|
+
sessionId,
|
|
16554
|
+
cwd: directories.get(sessionId),
|
|
16555
|
+
title: titles.get(sessionId)
|
|
16556
|
+
}));
|
|
16557
|
+
}
|
|
16558
|
+
}
|
|
16559
|
+
return entries;
|
|
16560
|
+
} finally {
|
|
16561
|
+
database.close();
|
|
16562
|
+
}
|
|
16563
|
+
}
|
|
16564
|
+
function createZcodeUsageStatistics(environment) {
|
|
16565
|
+
return Object.freeze({
|
|
16566
|
+
async listSources() {
|
|
16567
|
+
const file2 = zcodeDatabasePath(environment);
|
|
16568
|
+
const info = await lstat(file2).catch(() => null);
|
|
16569
|
+
if (!info?.isFile())
|
|
16570
|
+
return [];
|
|
16571
|
+
const wal = await lstat(`${file2}-wal`).catch(() => null);
|
|
16572
|
+
return [
|
|
16573
|
+
{
|
|
16574
|
+
id: file2,
|
|
16575
|
+
fingerprint: `${info.ino}:${info.size}:${info.mtimeMs}:${wal ? `${wal.size}:${wal.mtimeMs}` : "-"}`
|
|
16576
|
+
}
|
|
16577
|
+
];
|
|
16578
|
+
},
|
|
16579
|
+
readSource: (id) => readZcodeUsage(id)
|
|
16580
|
+
});
|
|
16581
|
+
}
|
|
16582
|
+
|
|
16583
|
+
// dist/adapter.js
|
|
16584
|
+
import path6 from "node:path";
|
|
16585
|
+
import { stat as stat2 } from "node:fs/promises";
|
|
16586
|
+
|
|
16587
|
+
// dist/transport.js
|
|
16588
|
+
import { spawn } from "node:child_process";
|
|
16589
|
+
import { randomUUID } from "node:crypto";
|
|
15850
16590
|
|
|
15851
16591
|
// dist/errors.js
|
|
15852
16592
|
var ZcodeError = class extends Error {
|
|
@@ -15873,136 +16613,10 @@ function nativeError(error51) {
|
|
|
15873
16613
|
return { code: "nativeFailure", message: "ZCode operation failed", retryable: false };
|
|
15874
16614
|
}
|
|
15875
16615
|
|
|
15876
|
-
// dist/protocol.js
|
|
15877
|
-
var recordSchema = external_exports.record(external_exports.string(), external_exports.unknown());
|
|
15878
|
-
var nativeModelSchema = external_exports.object({
|
|
15879
|
-
providerId: external_exports.string().min(1),
|
|
15880
|
-
modelId: external_exports.string().min(1),
|
|
15881
|
-
variant: external_exports.string().optional(),
|
|
15882
|
-
options: external_exports.object({ reasoningLevel: external_exports.string().min(1).optional() }).optional()
|
|
15883
|
-
});
|
|
15884
|
-
var levelSchema = external_exports.object({ value: external_exports.string(), label: external_exports.string() });
|
|
15885
|
-
var modelSchema = external_exports.object({
|
|
15886
|
-
ref: nativeModelSchema,
|
|
15887
|
-
label: external_exports.string(),
|
|
15888
|
-
providerLabel: external_exports.string().optional(),
|
|
15889
|
-
disabledReason: external_exports.string().optional(),
|
|
15890
|
-
contextWindow: external_exports.number().int().positive().optional(),
|
|
15891
|
-
reasoning: external_exports.object({
|
|
15892
|
-
enabled: external_exports.boolean().optional(),
|
|
15893
|
-
levels: external_exports.array(levelSchema),
|
|
15894
|
-
defaultLevel: external_exports.string().optional()
|
|
15895
|
-
}).transform((reasoning) => ({
|
|
15896
|
-
...reasoning,
|
|
15897
|
-
enabled: reasoning.enabled ?? reasoning.levels.length > 0
|
|
15898
|
-
})).optional()
|
|
15899
|
-
}).transform(({ providerLabel, ...model }) => ({
|
|
15900
|
-
...model,
|
|
15901
|
-
label: providerLabel ? `${providerLabel} / ${model.label}` : model.label
|
|
15902
|
-
}));
|
|
15903
|
-
var settingsSchema = external_exports.object({
|
|
15904
|
-
model: external_exports.object({
|
|
15905
|
-
current: nativeModelSchema.optional(),
|
|
15906
|
-
available: external_exports.array(modelSchema),
|
|
15907
|
-
lastUsed: nativeModelSchema.optional()
|
|
15908
|
-
}),
|
|
15909
|
-
thoughtLevel: external_exports.object({
|
|
15910
|
-
enabled: external_exports.boolean(),
|
|
15911
|
-
current: external_exports.string().optional(),
|
|
15912
|
-
defaultLevel: external_exports.string().optional(),
|
|
15913
|
-
available: external_exports.array(levelSchema)
|
|
15914
|
-
}),
|
|
15915
|
-
mode: external_exports.object({ current: external_exports.enum(["build", "edit", "plan", "yolo", "auto"]) })
|
|
15916
|
-
});
|
|
15917
|
-
var workspaceSchema = external_exports.object({
|
|
15918
|
-
workspacePath: external_exports.string().min(1),
|
|
15919
|
-
workspaceKey: external_exports.string().min(1),
|
|
15920
|
-
workspaceIdentity: external_exports.string().optional()
|
|
15921
|
-
});
|
|
15922
|
-
var summarySchema = external_exports.object({
|
|
15923
|
-
sessionId: external_exports.string().min(1),
|
|
15924
|
-
workspace: workspaceSchema,
|
|
15925
|
-
title: external_exports.string(),
|
|
15926
|
-
status: external_exports.string(),
|
|
15927
|
-
mode: external_exports.string(),
|
|
15928
|
-
createdAt: external_exports.number(),
|
|
15929
|
-
updatedAt: external_exports.number(),
|
|
15930
|
-
parentSessionId: external_exports.string().optional(),
|
|
15931
|
-
sessionKind: external_exports.string()
|
|
15932
|
-
});
|
|
15933
|
-
var partSchema = external_exports.object({
|
|
15934
|
-
partId: external_exports.string().min(1),
|
|
15935
|
-
messageId: external_exports.string(),
|
|
15936
|
-
sessionId: external_exports.string(),
|
|
15937
|
-
type: external_exports.string()
|
|
15938
|
-
}).catchall(external_exports.unknown());
|
|
15939
|
-
var messageSchema = external_exports.object({
|
|
15940
|
-
info: external_exports.object({
|
|
15941
|
-
messageId: external_exports.string().min(1),
|
|
15942
|
-
sessionId: external_exports.string(),
|
|
15943
|
-
role: external_exports.enum(["user", "assistant"]),
|
|
15944
|
-
parentMessageId: external_exports.string().optional(),
|
|
15945
|
-
time: external_exports.object({ created: external_exports.number(), completed: external_exports.number().optional() }),
|
|
15946
|
-
model: nativeModelSchema.optional(),
|
|
15947
|
-
finish: external_exports.string().optional(),
|
|
15948
|
-
error: recordSchema.optional(),
|
|
15949
|
-
synthetic: external_exports.boolean().optional(),
|
|
15950
|
-
visibility: external_exports.string().optional(),
|
|
15951
|
-
semantics: recordSchema.optional()
|
|
15952
|
-
}),
|
|
15953
|
-
parts: external_exports.array(partSchema)
|
|
15954
|
-
});
|
|
15955
|
-
var snapshotSchema = external_exports.object({
|
|
15956
|
-
protocol: external_exports.object({ name: external_exports.literal("ZCode Protocol"), version: external_exports.literal(1) }),
|
|
15957
|
-
session: summarySchema,
|
|
15958
|
-
settings: settingsSchema,
|
|
15959
|
-
projection: external_exports.object({
|
|
15960
|
-
status: external_exports.string(),
|
|
15961
|
-
contextUsed: external_exports.number(),
|
|
15962
|
-
contextWindow: external_exports.number(),
|
|
15963
|
-
currentTurnId: external_exports.string().optional(),
|
|
15964
|
-
backgroundJobs: external_exports.array(external_exports.unknown()).optional(),
|
|
15965
|
-
target: recordSchema.nullable().optional()
|
|
15966
|
-
}),
|
|
15967
|
-
messages: external_exports.array(messageSchema),
|
|
15968
|
-
runtime: recordSchema,
|
|
15969
|
-
target: recordSchema.nullable().optional(),
|
|
15970
|
-
slashCommands: external_exports.array(external_exports.object({ name: external_exports.string(), description: external_exports.string(), source: external_exports.string().optional() })).optional()
|
|
15971
|
-
});
|
|
15972
|
-
var workspaceStateSchema = external_exports.object({
|
|
15973
|
-
workspace: workspaceSchema,
|
|
15974
|
-
settings: settingsSchema
|
|
15975
|
-
});
|
|
15976
|
-
var eventSchema = external_exports.object({
|
|
15977
|
-
eventId: external_exports.string(),
|
|
15978
|
-
sessionId: external_exports.string(),
|
|
15979
|
-
turnId: external_exports.string().optional(),
|
|
15980
|
-
seq: external_exports.number(),
|
|
15981
|
-
timestamp: external_exports.number(),
|
|
15982
|
-
type: external_exports.string(),
|
|
15983
|
-
payload: recordSchema.optional()
|
|
15984
|
-
});
|
|
15985
|
-
var runtimeUsageSchema = external_exports.object({
|
|
15986
|
-
contextUsage: external_exports.object({
|
|
15987
|
-
used: external_exports.number().int().nonnegative(),
|
|
15988
|
-
cache: external_exports.object({
|
|
15989
|
-
totalCacheReadTokens: external_exports.number().int().nonnegative(),
|
|
15990
|
-
totalCacheWriteTokens: external_exports.number().int().nonnegative(),
|
|
15991
|
-
latestHitRate: external_exports.number().min(0).max(1).nullish()
|
|
15992
|
-
}).nullish()
|
|
15993
|
-
})
|
|
15994
|
-
});
|
|
15995
|
-
function record2(value) {
|
|
15996
|
-
return recordSchema.safeParse(value).data ?? {};
|
|
15997
|
-
}
|
|
15998
|
-
function text(value) {
|
|
15999
|
-
return typeof value === "string" ? value : "";
|
|
16000
|
-
}
|
|
16001
|
-
|
|
16002
16616
|
// dist/installation.js
|
|
16003
16617
|
import { open, stat } from "node:fs/promises";
|
|
16004
16618
|
import { homedir } from "node:os";
|
|
16005
|
-
import
|
|
16619
|
+
import path2 from "node:path";
|
|
16006
16620
|
var DEFAULT_DARWIN_APP = "/Applications/ZCode.app";
|
|
16007
16621
|
var DEFAULT_LINUX_APP = "/opt/ZCode";
|
|
16008
16622
|
async function isFile(file2) {
|
|
@@ -16047,11 +16661,11 @@ async function resolveDefaultApp(environment, platform2) {
|
|
|
16047
16661
|
if (platform2 === "linux")
|
|
16048
16662
|
return DEFAULT_LINUX_APP;
|
|
16049
16663
|
const candidates = [
|
|
16050
|
-
environment.LOCALAPPDATA &&
|
|
16051
|
-
environment.ProgramFiles &&
|
|
16664
|
+
environment.LOCALAPPDATA && path2.join(environment.LOCALAPPDATA, "Programs", "ZCode"),
|
|
16665
|
+
environment.ProgramFiles && path2.join(environment.ProgramFiles, "ZCode")
|
|
16052
16666
|
].filter(Boolean);
|
|
16053
16667
|
for (const candidate of candidates) {
|
|
16054
|
-
if (await isFile(
|
|
16668
|
+
if (await isFile(path2.join(candidate, "resources", "app.asar")))
|
|
16055
16669
|
return candidate;
|
|
16056
16670
|
}
|
|
16057
16671
|
return candidates[0] ?? "";
|
|
@@ -16063,30 +16677,30 @@ async function resolveInstallation(environment, app, platform2 = process.platfor
|
|
|
16063
16677
|
const explicitApp = app?.trim() || environment.CODEXHOST_ZCODE_APP?.trim();
|
|
16064
16678
|
const targetApp = explicitApp || await resolveDefaultApp(environment, platform2);
|
|
16065
16679
|
const missing = () => new ZcodeError("notInstalled", `ZCode Desktop was not found at ${targetApp}; install it or set its application path`);
|
|
16066
|
-
const resources = platform2 === "darwin" ?
|
|
16067
|
-
const pkg = await readPackageJsonFromAsar(
|
|
16680
|
+
const resources = platform2 === "darwin" ? path2.join(targetApp, "Contents", "Resources") : path2.join(targetApp, "resources");
|
|
16681
|
+
const pkg = await readPackageJsonFromAsar(path2.join(resources, "app.asar"));
|
|
16068
16682
|
if (!pkg?.productName || !pkg.version)
|
|
16069
16683
|
throw missing();
|
|
16070
16684
|
let runtime;
|
|
16071
16685
|
if (platform2 === "darwin") {
|
|
16072
|
-
runtime =
|
|
16686
|
+
runtime = path2.join(targetApp, "Contents", "Frameworks", `${pkg.productName} Helper.app`, "Contents", "MacOS", `${pkg.productName} Helper`);
|
|
16073
16687
|
} else if (platform2 === "win32") {
|
|
16074
|
-
runtime =
|
|
16688
|
+
runtime = path2.join(targetApp, `${pkg.productName}.exe`);
|
|
16075
16689
|
} else {
|
|
16076
16690
|
const linuxExecutableName = pkg.productName.toLowerCase().replace(/\s+/g, "-");
|
|
16077
|
-
runtime =
|
|
16691
|
+
runtime = path2.join(targetApp, linuxExecutableName);
|
|
16078
16692
|
}
|
|
16079
|
-
const cli =
|
|
16080
|
-
const builtinProviderConfig = environment.ZCODE_BUILTIN_PROVIDER_CONFIG_FILE ||
|
|
16693
|
+
const cli = path2.join(resources, "glm", "zcode.cjs");
|
|
16694
|
+
const builtinProviderConfig = environment.ZCODE_BUILTIN_PROVIDER_CONFIG_FILE || path2.join(resources, "config", "provider", "zcode-builtin.json");
|
|
16081
16695
|
if (!await isFile(runtime) || !await isFile(cli) || !await isFile(builtinProviderConfig))
|
|
16082
16696
|
throw missing();
|
|
16083
|
-
const dataRoot =
|
|
16697
|
+
const dataRoot = path2.join(environment.ZCODE_DATA_BASE_DIR?.trim() || environment.HOME || homedir(), ".zcode", "v2");
|
|
16084
16698
|
return {
|
|
16085
16699
|
runtime,
|
|
16086
16700
|
version: pkg.version,
|
|
16087
16701
|
cli,
|
|
16088
16702
|
builtinProviderConfig,
|
|
16089
|
-
personalProviderConfig: environment.ZCODE_PERSONAL_PROVIDER_CONFIG_FILE ||
|
|
16703
|
+
personalProviderConfig: environment.ZCODE_PERSONAL_PROVIDER_CONFIG_FILE || path2.join(dataRoot, "provider_config.json"),
|
|
16090
16704
|
dataRoot
|
|
16091
16705
|
};
|
|
16092
16706
|
}
|
|
@@ -16108,25 +16722,15 @@ function createZcodeInstallation(environment, app) {
|
|
|
16108
16722
|
}
|
|
16109
16723
|
|
|
16110
16724
|
// dist/account.js
|
|
16725
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
16726
|
+
import { readFile as readFile3 } from "node:fs/promises";
|
|
16727
|
+
import path5 from "node:path";
|
|
16728
|
+
|
|
16729
|
+
// dist/credentials.js
|
|
16111
16730
|
import { createDecipheriv, createHash } from "node:crypto";
|
|
16112
16731
|
import { readFile } from "node:fs/promises";
|
|
16113
16732
|
import { homedir as homedir2, platform, userInfo } from "node:os";
|
|
16114
|
-
import
|
|
16115
|
-
var SIGN_IN = "Sign in to ZCode Desktop with a Start Plan account, then try again";
|
|
16116
|
-
var builtinSchema = external_exports.object({
|
|
16117
|
-
revision: external_exports.union([external_exports.number(), external_exports.string()]),
|
|
16118
|
-
config: external_exports.object({
|
|
16119
|
-
providerConfigRules: external_exports.object({
|
|
16120
|
-
providerRules: external_exports.array(external_exports.object({
|
|
16121
|
-
providerId: external_exports.string().min(1),
|
|
16122
|
-
config: external_exports.object({
|
|
16123
|
-
builtinModelIds: external_exports.array(external_exports.string()).optional(),
|
|
16124
|
-
access: external_exports.object({ mode: external_exports.string(), accountType: external_exports.string() }).partial().optional()
|
|
16125
|
-
})
|
|
16126
|
-
}))
|
|
16127
|
-
})
|
|
16128
|
-
})
|
|
16129
|
-
});
|
|
16733
|
+
import path3 from "node:path";
|
|
16130
16734
|
function decrypt(value, environment) {
|
|
16131
16735
|
if (!value.startsWith("enc:v1:"))
|
|
16132
16736
|
return value;
|
|
@@ -16147,25 +16751,231 @@ function decrypt(value, environment) {
|
|
|
16147
16751
|
throw new ZcodeError("authenticationRequired", "Cannot decrypt ZCode credentials; ZCODE_CREDENTIAL_SECRET must match ZCode Desktop");
|
|
16148
16752
|
}
|
|
16149
16753
|
}
|
|
16150
|
-
async function
|
|
16754
|
+
async function readCredentials(installation, environment) {
|
|
16151
16755
|
let store;
|
|
16152
16756
|
try {
|
|
16153
|
-
store = JSON.parse(await readFile(
|
|
16757
|
+
store = JSON.parse(await readFile(path3.join(installation.dataRoot, "credentials.json"), "utf8"));
|
|
16154
16758
|
} catch (error51) {
|
|
16155
16759
|
if (error51.code === "ENOENT")
|
|
16156
|
-
return "";
|
|
16760
|
+
return () => "";
|
|
16157
16761
|
throw new ZcodeError("authenticationRequired", "Cannot read ZCode credentials");
|
|
16158
16762
|
}
|
|
16159
|
-
const
|
|
16160
|
-
return
|
|
16763
|
+
const values = external_exports.record(external_exports.string(), external_exports.string()).safeParse(store).data;
|
|
16764
|
+
return (key) => {
|
|
16765
|
+
const value = values?.[key];
|
|
16766
|
+
return value ? decrypt(value, environment) : "";
|
|
16767
|
+
};
|
|
16768
|
+
}
|
|
16769
|
+
async function readCredential(installation, environment, key) {
|
|
16770
|
+
return (await readCredentials(installation, environment))(key);
|
|
16771
|
+
}
|
|
16772
|
+
|
|
16773
|
+
// dist/personal-coding-plan.js
|
|
16774
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
16775
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
16776
|
+
import { homedir as homedir3 } from "node:os";
|
|
16777
|
+
import path4 from "node:path";
|
|
16778
|
+
var familySchema = external_exports.enum(["zai", "bigmodel"]);
|
|
16779
|
+
var recordSchema2 = external_exports.record(external_exports.string(), external_exports.unknown());
|
|
16780
|
+
var CONNECT = "Connect Personal Coding Plan in ZCode Desktop, then re-detect ZCode and reopen the Thread";
|
|
16781
|
+
function personalCodingPlanOrigin(family, environment) {
|
|
16782
|
+
const test = environment.ZCODE_ENV?.trim().toLowerCase() === "test";
|
|
16783
|
+
const prefix = family === "zai" ? "ZAI" : "BIGMODEL";
|
|
16784
|
+
const suffix = family === "zai" ? "BUSINESS_BASE_URL" : "API_BASE_URL";
|
|
16785
|
+
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");
|
|
16786
|
+
const url2 = new URL(origin);
|
|
16787
|
+
if (!["http:", "https:"].includes(url2.protocol) || url2.username || url2.password)
|
|
16788
|
+
throw new Error("Invalid ZCode business origin");
|
|
16789
|
+
return url2.origin;
|
|
16790
|
+
}
|
|
16791
|
+
async function readSelection(environment, family) {
|
|
16792
|
+
const home = environment.ZCODE_DESKTOP_HOME_DIR?.trim() || environment.HOME?.trim() || environment.USERPROFILE?.trim() || homedir3();
|
|
16793
|
+
let raw;
|
|
16794
|
+
try {
|
|
16795
|
+
raw = JSON.parse(await readFile2(path4.join(home, ".zcode", "v2", "setting.json"), "utf8"));
|
|
16796
|
+
} catch (error51) {
|
|
16797
|
+
if (error51.code === "ENOENT")
|
|
16798
|
+
return false;
|
|
16799
|
+
throw new ZcodeError("configurationRequired", CONNECT);
|
|
16800
|
+
}
|
|
16801
|
+
const settings = recordSchema2.parse(raw);
|
|
16802
|
+
if (settings.providerFamilyDomain !== family)
|
|
16803
|
+
return false;
|
|
16804
|
+
if (Object.hasOwn(settings, "providerFamilyConnectionSelections")) {
|
|
16805
|
+
const selections = recordSchema2.parse(settings.providerFamilyConnectionSelections);
|
|
16806
|
+
return external_exports.object({ kind: external_exports.literal("individual-coding-plan") }).safeParse(selections[family]).success;
|
|
16807
|
+
}
|
|
16808
|
+
const modes = recordSchema2.safeParse(settings.modelProviderFamilyModes).data;
|
|
16809
|
+
const keys = recordSchema2.safeParse(settings.modelProviderFamilySelectedKeys).data;
|
|
16810
|
+
return modes?.[family] !== "apiKey" && keys?.[family] === `coding-plan:builtin:${family}-coding-plan`;
|
|
16811
|
+
}
|
|
16812
|
+
var envelopeSchema = external_exports.object({
|
|
16813
|
+
success: external_exports.boolean().optional(),
|
|
16814
|
+
code: external_exports.number().optional(),
|
|
16815
|
+
data: external_exports.array(external_exports.unknown())
|
|
16816
|
+
});
|
|
16817
|
+
var subscriptionSchema = external_exports.object({
|
|
16818
|
+
productId: external_exports.string().optional(),
|
|
16819
|
+
productName: external_exports.string().optional(),
|
|
16820
|
+
status: external_exports.string(),
|
|
16821
|
+
inCurrentPeriod: external_exports.boolean()
|
|
16822
|
+
});
|
|
16823
|
+
function codingProduct(value) {
|
|
16824
|
+
const entry = recordSchema2.safeParse(value).data;
|
|
16825
|
+
return [entry?.productId, entry?.productName].some((field2) => typeof field2 === "string" && field2.toLowerCase().includes("coding"));
|
|
16826
|
+
}
|
|
16827
|
+
async function queryEntitlement(family, apiKey, environment) {
|
|
16828
|
+
try {
|
|
16829
|
+
const response = await fetch(`${personalCodingPlanOrigin(family, environment)}/api/biz/subscription/list`, {
|
|
16830
|
+
method: "GET",
|
|
16831
|
+
// The subscription endpoint accepts the model API Key, not the OAuth token or Start JWT.
|
|
16832
|
+
headers: { Authorization: apiKey.trim() },
|
|
16833
|
+
redirect: "error",
|
|
16834
|
+
signal: AbortSignal.timeout(15e3)
|
|
16835
|
+
});
|
|
16836
|
+
if (response.status === 401 || response.status === 403)
|
|
16837
|
+
return "credential-failed";
|
|
16838
|
+
if (!response.ok)
|
|
16839
|
+
return "unknown";
|
|
16840
|
+
const parsed = envelopeSchema.safeParse(await response.json());
|
|
16841
|
+
if (!parsed.success)
|
|
16842
|
+
return "unknown";
|
|
16843
|
+
const payload = parsed.data;
|
|
16844
|
+
if (payload.success === false || payload.code !== void 0 && ![0, 200].includes(payload.code))
|
|
16845
|
+
return "unknown";
|
|
16846
|
+
let malformed = false;
|
|
16847
|
+
for (const item of payload.data) {
|
|
16848
|
+
if (!codingProduct(item))
|
|
16849
|
+
continue;
|
|
16850
|
+
const subscription = subscriptionSchema.safeParse(item);
|
|
16851
|
+
if (!subscription.success)
|
|
16852
|
+
malformed = true;
|
|
16853
|
+
else if (subscription.data.status === "VALID" && subscription.data.inCurrentPeriod)
|
|
16854
|
+
return "available";
|
|
16855
|
+
}
|
|
16856
|
+
return malformed ? "unknown" : "unavailable";
|
|
16857
|
+
} catch {
|
|
16858
|
+
return "unknown";
|
|
16859
|
+
}
|
|
16161
16860
|
}
|
|
16861
|
+
var PersonalCodingPlanAccount = class {
|
|
16862
|
+
installation;
|
|
16863
|
+
environment;
|
|
16864
|
+
#authorized = /* @__PURE__ */ new Map();
|
|
16865
|
+
constructor(installation, environment) {
|
|
16866
|
+
this.installation = installation;
|
|
16867
|
+
this.environment = environment;
|
|
16868
|
+
}
|
|
16869
|
+
async #context(providerId, family) {
|
|
16870
|
+
const [credential, current] = await Promise.all([
|
|
16871
|
+
readCredentials(this.installation, this.environment),
|
|
16872
|
+
readSelection(this.environment, family)
|
|
16873
|
+
]);
|
|
16874
|
+
if (credential("oauth:active_provider") !== family)
|
|
16875
|
+
return void 0;
|
|
16876
|
+
const raw = credential(`oauth:${family}:user_info`);
|
|
16877
|
+
if (!raw)
|
|
16878
|
+
return void 0;
|
|
16879
|
+
const profile = recordSchema2.parse(JSON.parse(raw));
|
|
16880
|
+
const normalized = external_exports.object({ id: external_exports.string(), username: external_exports.string(), displayName: external_exports.string() }).safeParse(profile).data;
|
|
16881
|
+
const identity = normalized ? normalized.id.trim() : family === "zai" && typeof profile.user_id === "string" ? profile.user_id.trim() : "";
|
|
16882
|
+
if (!identity || identity === "unknown")
|
|
16883
|
+
return void 0;
|
|
16884
|
+
const key = `account-provider:coding-plan:${providerId}:account:${encodeURIComponent(identity)}:api-key`;
|
|
16885
|
+
return { identity, current, apiKey: credential(key).trim() };
|
|
16886
|
+
}
|
|
16887
|
+
async inspect(providerId, accountType) {
|
|
16888
|
+
const family = familySchema.parse(accountType);
|
|
16889
|
+
this.#authorized.delete(providerId);
|
|
16890
|
+
let current = false;
|
|
16891
|
+
try {
|
|
16892
|
+
const context = await this.#context(providerId, family);
|
|
16893
|
+
if (!context)
|
|
16894
|
+
return {
|
|
16895
|
+
availability: "unavailable",
|
|
16896
|
+
entitled: false,
|
|
16897
|
+
current,
|
|
16898
|
+
unavailableReason: "not-connected"
|
|
16899
|
+
};
|
|
16900
|
+
current = context.current;
|
|
16901
|
+
const connectionKey = createHash2("sha256").update(JSON.stringify([family, context.identity, "individual-coding-plan"])).digest("hex");
|
|
16902
|
+
const base = { current, connectionKey };
|
|
16903
|
+
if (!context.apiKey)
|
|
16904
|
+
return {
|
|
16905
|
+
...base,
|
|
16906
|
+
availability: "unavailable",
|
|
16907
|
+
entitled: false,
|
|
16908
|
+
unavailableReason: "credential-failed"
|
|
16909
|
+
};
|
|
16910
|
+
const entitlement = await queryEntitlement(family, context.apiKey, this.environment);
|
|
16911
|
+
const after = await this.#context(providerId, family);
|
|
16912
|
+
if (!after || after.identity !== context.identity || after.current !== current || after.apiKey !== context.apiKey)
|
|
16913
|
+
return { availability: "unknown", entitled: false, current: false };
|
|
16914
|
+
if (entitlement === "available") {
|
|
16915
|
+
if (current)
|
|
16916
|
+
this.#authorized.set(providerId, { family, identity: context.identity });
|
|
16917
|
+
return { ...base, availability: "available", entitled: true };
|
|
16918
|
+
}
|
|
16919
|
+
return {
|
|
16920
|
+
...base,
|
|
16921
|
+
availability: entitlement === "unknown" ? "unknown" : "unavailable",
|
|
16922
|
+
entitled: false,
|
|
16923
|
+
...entitlement === "unknown" ? {} : {
|
|
16924
|
+
unavailableReason: entitlement === "unavailable" ? "not-entitled" : "credential-failed"
|
|
16925
|
+
}
|
|
16926
|
+
};
|
|
16927
|
+
} catch {
|
|
16928
|
+
return { availability: "unknown", entitled: false, current };
|
|
16929
|
+
}
|
|
16930
|
+
}
|
|
16931
|
+
async requestAuth(request, signal) {
|
|
16932
|
+
const parsed = external_exports.object({
|
|
16933
|
+
providerId: external_exports.string(),
|
|
16934
|
+
modelSelection: external_exports.object({ providerId: external_exports.string() }),
|
|
16935
|
+
accountAccess: external_exports.object({
|
|
16936
|
+
type: external_exports.literal("zhipu-account"),
|
|
16937
|
+
mode: external_exports.literal("individual-coding-plan"),
|
|
16938
|
+
accountType: familySchema
|
|
16939
|
+
})
|
|
16940
|
+
}).safeParse(request);
|
|
16941
|
+
if (!parsed.success)
|
|
16942
|
+
throw new ZcodeError("authenticationRequired", CONNECT);
|
|
16943
|
+
const { providerId, modelSelection, accountAccess } = parsed.data;
|
|
16944
|
+
const authorized = this.#authorized.get(providerId);
|
|
16945
|
+
if (!authorized || authorized.family !== accountAccess.accountType || modelSelection.providerId !== providerId)
|
|
16946
|
+
throw new ZcodeError("authenticationRequired", CONNECT);
|
|
16947
|
+
signal.throwIfAborted();
|
|
16948
|
+
const context = await this.#context(providerId, authorized.family);
|
|
16949
|
+
signal.throwIfAborted();
|
|
16950
|
+
if (!context?.current || context.identity !== authorized.identity || !context.apiKey)
|
|
16951
|
+
throw new ZcodeError("authenticationRequired", CONNECT);
|
|
16952
|
+
return { apiKey: context.apiKey };
|
|
16953
|
+
}
|
|
16954
|
+
};
|
|
16955
|
+
|
|
16956
|
+
// dist/account.js
|
|
16957
|
+
var SIGN_IN = "Sign in to ZCode Desktop with a Start Plan account, then try again";
|
|
16958
|
+
var builtinSchema = external_exports.object({
|
|
16959
|
+
revision: external_exports.union([external_exports.number(), external_exports.string()]),
|
|
16960
|
+
config: external_exports.object({
|
|
16961
|
+
providerConfigRules: external_exports.object({
|
|
16962
|
+
providerRules: external_exports.array(external_exports.object({
|
|
16963
|
+
providerId: external_exports.string().min(1),
|
|
16964
|
+
config: external_exports.object({
|
|
16965
|
+
builtinModelIds: external_exports.array(external_exports.string()).optional(),
|
|
16966
|
+
access: external_exports.object({ mode: external_exports.string(), accountType: external_exports.string() }).partial().optional()
|
|
16967
|
+
})
|
|
16968
|
+
}))
|
|
16969
|
+
})
|
|
16970
|
+
})
|
|
16971
|
+
});
|
|
16162
16972
|
function resolveEndpointOrigin(environment) {
|
|
16163
16973
|
return environment.ZCODE_BASE_URL?.trim() || "https://zcode.z.ai";
|
|
16164
16974
|
}
|
|
16165
16975
|
async function readDeviceMid(installation) {
|
|
16166
16976
|
try {
|
|
16167
|
-
const file2 =
|
|
16168
|
-
const parsed = JSON.parse(await
|
|
16977
|
+
const file2 = path5.join(installation.dataRoot, "telemetry-state.json");
|
|
16978
|
+
const parsed = JSON.parse(await readFile3(file2, "utf8"));
|
|
16169
16979
|
return typeof parsed?.deviceMid === "string" ? parsed.deviceMid.trim() : "";
|
|
16170
16980
|
} catch {
|
|
16171
16981
|
return "";
|
|
@@ -16263,24 +17073,38 @@ async function queryStartPlanBalance(origin, appVersion, jwt2, deviceMid) {
|
|
|
16263
17073
|
}
|
|
16264
17074
|
async function accountConfig(installation, environment) {
|
|
16265
17075
|
const file2 = installation.builtinProviderConfig;
|
|
16266
|
-
const builtin = builtinSchema.parse(JSON.parse(await
|
|
16267
|
-
const basedOnZCodeBuiltinRevision = `zcode-builtin:${builtin.revision}:${
|
|
17076
|
+
const builtin = builtinSchema.parse(JSON.parse(await readFile3(file2, "utf8")));
|
|
17077
|
+
const basedOnZCodeBuiltinRevision = `zcode-builtin:${builtin.revision}:${createHash3("sha256").update(path5.resolve(file2)).digest("hex")}`;
|
|
16268
17078
|
const family = await readCredential(installation, environment, "oauth:active_provider");
|
|
16269
17079
|
let balanceData;
|
|
16270
17080
|
if (family) {
|
|
16271
|
-
|
|
16272
|
-
|
|
16273
|
-
|
|
16274
|
-
|
|
16275
|
-
|
|
17081
|
+
try {
|
|
17082
|
+
const jwt2 = await readCredential(installation, environment, "zcodejwttoken");
|
|
17083
|
+
const deviceMid = await readDeviceMid(installation);
|
|
17084
|
+
if (jwt2 && deviceMid) {
|
|
17085
|
+
const origin = resolveEndpointOrigin(environment);
|
|
17086
|
+
balanceData = await queryStartPlanBalance(origin, installation.version, jwt2, deviceMid);
|
|
17087
|
+
}
|
|
17088
|
+
} catch {
|
|
16276
17089
|
}
|
|
16277
17090
|
}
|
|
16278
17091
|
let startPlan = false;
|
|
17092
|
+
const codingPlan = new PersonalCodingPlanAccount(installation, environment);
|
|
16279
17093
|
const providers = {};
|
|
16280
17094
|
const states = {};
|
|
16281
17095
|
for (const rule of builtin.config.providerConfigRules.providerRules) {
|
|
16282
17096
|
const access = rule.config.access;
|
|
16283
|
-
if (!family || access?.
|
|
17097
|
+
if (!family || access?.accountType !== family)
|
|
17098
|
+
continue;
|
|
17099
|
+
if (access.mode === "individual-coding-plan" && (family === "zai" || family === "bigmodel")) {
|
|
17100
|
+
const state = await codingPlan.inspect(rule.providerId, family);
|
|
17101
|
+
providers[rule.providerId] = {
|
|
17102
|
+
access: { type: "zhipu-account", entitled: state.entitled }
|
|
17103
|
+
};
|
|
17104
|
+
states[rule.providerId] = state;
|
|
17105
|
+
continue;
|
|
17106
|
+
}
|
|
17107
|
+
if (access.mode !== "start-plan")
|
|
16284
17108
|
continue;
|
|
16285
17109
|
const allowedModels = resolveStartPlanModels(balanceData, rule.config.builtinModelIds);
|
|
16286
17110
|
if (allowedModels.length > 0) {
|
|
@@ -16302,7 +17126,7 @@ async function accountConfig(installation, environment) {
|
|
|
16302
17126
|
};
|
|
16303
17127
|
}
|
|
16304
17128
|
}
|
|
16305
|
-
const overlayDigest =
|
|
17129
|
+
const overlayDigest = createHash3("sha256").update(JSON.stringify([providers, states])).digest("hex").slice(0, 16);
|
|
16306
17130
|
return {
|
|
16307
17131
|
params: {
|
|
16308
17132
|
revision: `codexhost:${family || "signed-out"}:${builtin.revision}:${overlayDigest}`,
|
|
@@ -16310,16 +17134,20 @@ async function accountConfig(installation, environment) {
|
|
|
16310
17134
|
providers,
|
|
16311
17135
|
states
|
|
16312
17136
|
},
|
|
16313
|
-
startPlan
|
|
17137
|
+
startPlan,
|
|
17138
|
+
codingPlan
|
|
16314
17139
|
};
|
|
16315
17140
|
}
|
|
16316
|
-
async function providerRuntimeHeaders(
|
|
16317
|
-
|
|
16318
|
-
return {
|
|
16319
|
-
headersApplied: false,
|
|
16320
|
-
errorMessage: "codexhost supports only the ZCode Start Plan account"
|
|
16321
|
-
};
|
|
17141
|
+
async function providerRuntimeHeaders(request, signal, installation, environment, verifier, codingPlan) {
|
|
17142
|
+
const mode = external_exports.object({ mode: external_exports.string() }).safeParse(request.accountAccess).data?.mode;
|
|
16322
17143
|
try {
|
|
17144
|
+
if (mode === "individual-coding-plan")
|
|
17145
|
+
return { headersApplied: true, requestAuth: await codingPlan.requestAuth(request, signal) };
|
|
17146
|
+
if (mode !== "start-plan")
|
|
17147
|
+
return {
|
|
17148
|
+
headersApplied: false,
|
|
17149
|
+
errorMessage: "codexhost supports ZCode Start Plan and Personal Coding Plan; Team Coding Plan is not supported"
|
|
17150
|
+
};
|
|
16323
17151
|
const apiKey = await readCredential(installation, environment, "zcodejwttoken");
|
|
16324
17152
|
if (!apiKey)
|
|
16325
17153
|
return { headersApplied: false, errorMessage: SIGN_IN };
|
|
@@ -16328,7 +17156,7 @@ async function providerRuntimeHeaders(accountAccess, signal, installation, envir
|
|
|
16328
17156
|
} catch (error51) {
|
|
16329
17157
|
return {
|
|
16330
17158
|
headersApplied: false,
|
|
16331
|
-
errorMessage: error51 instanceof ZcodeError ? error51.message : "ZCode
|
|
17159
|
+
errorMessage: error51 instanceof ZcodeError ? error51.message : "ZCode account authentication failed"
|
|
16332
17160
|
};
|
|
16333
17161
|
}
|
|
16334
17162
|
}
|
|
@@ -16412,6 +17240,7 @@ var CliTransport = class {
|
|
|
16412
17240
|
// Aborting these cancels only this transport's running and queued shared verifications.
|
|
16413
17241
|
#headerRequests = /* @__PURE__ */ new Map();
|
|
16414
17242
|
#startPlan = false;
|
|
17243
|
+
#codingPlan;
|
|
16415
17244
|
#fault;
|
|
16416
17245
|
#closed = false;
|
|
16417
17246
|
#closePromise;
|
|
@@ -16434,9 +17263,10 @@ var CliTransport = class {
|
|
|
16434
17263
|
if (this.#child || this.#closed)
|
|
16435
17264
|
throw new ZcodeError("invalidState", "ZCode transport already started or closed");
|
|
16436
17265
|
const installation = await resolveInstallation(this.options.environment, this.options.app);
|
|
16437
|
-
const { params: accountParams, startPlan } = await accountConfig(installation, this.options.environment);
|
|
17266
|
+
const { params: accountParams, startPlan, codingPlan } = await accountConfig(installation, this.options.environment);
|
|
16438
17267
|
this.#installation = installation;
|
|
16439
17268
|
this.#startPlan = startPlan;
|
|
17269
|
+
this.#codingPlan = codingPlan;
|
|
16440
17270
|
const child = spawn(installation.runtime, [installation.cli, "app-server", "--stdio", "--surface", "desktop"], {
|
|
16441
17271
|
cwd: this.options.cwd,
|
|
16442
17272
|
env: {
|
|
@@ -16561,7 +17391,7 @@ var CliTransport = class {
|
|
|
16561
17391
|
this.#headerRequests.set(requestId, controller);
|
|
16562
17392
|
try {
|
|
16563
17393
|
reply({
|
|
16564
|
-
result: await providerRuntimeHeaders(params
|
|
17394
|
+
result: await providerRuntimeHeaders(params, controller.signal, this.#installation, this.options.environment, () => this.options.verifier(this.#installation.version), this.#codingPlan)
|
|
16565
17395
|
});
|
|
16566
17396
|
} finally {
|
|
16567
17397
|
this.#headerRequests.delete(requestId);
|
|
@@ -17292,32 +18122,32 @@ import { randomUUID as randomUUID2 } from "node:crypto";
|
|
|
17292
18122
|
|
|
17293
18123
|
// dist/models.js
|
|
17294
18124
|
var ZCODE_ID = harnessIdSchema.parse("zcode");
|
|
17295
|
-
function encodeModel(
|
|
18125
|
+
function encodeModel(model2) {
|
|
17296
18126
|
return harnessModelRefSchema.parse({
|
|
17297
|
-
id: `zcode-local-v1.${Buffer.from(JSON.stringify([
|
|
18127
|
+
id: `zcode-local-v1.${Buffer.from(JSON.stringify([model2.providerId, model2.modelId])).toString("base64url")}`
|
|
17298
18128
|
});
|
|
17299
18129
|
}
|
|
17300
|
-
function decodeModel(
|
|
18130
|
+
function decodeModel(model2) {
|
|
17301
18131
|
try {
|
|
17302
18132
|
const prefix = "zcode-local-v1.";
|
|
17303
|
-
const value = JSON.parse(Buffer.from(
|
|
17304
|
-
if (!
|
|
18133
|
+
const value = JSON.parse(Buffer.from(model2.id.slice(prefix.length), "base64url").toString("utf8"));
|
|
18134
|
+
if (!model2.id.startsWith(prefix) || !Array.isArray(value) || value.length !== 2)
|
|
17305
18135
|
throw new Error();
|
|
17306
18136
|
const native = nativeModelSchema.parse({ providerId: value[0], modelId: value[1] });
|
|
17307
|
-
if (encodeModel(native).id !==
|
|
18137
|
+
if (encodeModel(native).id !== model2.id)
|
|
17308
18138
|
throw new Error();
|
|
17309
18139
|
return native;
|
|
17310
18140
|
} catch {
|
|
17311
18141
|
throw new ZcodeError("invalidRequest", "Invalid ZCode model reference");
|
|
17312
18142
|
}
|
|
17313
18143
|
}
|
|
17314
|
-
function selectNativeModel(
|
|
17315
|
-
const native = decodeModel(
|
|
17316
|
-
const entry = settings.model.available.find((entry2) => encodeModel(entry2.ref).id ===
|
|
18144
|
+
function selectNativeModel(model2, settings, thinkingOption) {
|
|
18145
|
+
const native = decodeModel(model2);
|
|
18146
|
+
const entry = settings.model.available.find((entry2) => encodeModel(entry2.ref).id === model2.id && !entry2.disabledReason);
|
|
17317
18147
|
if (!entry)
|
|
17318
18148
|
throw new ZcodeError("invalidRequest", "ZCode model is not available");
|
|
17319
18149
|
const current = settings.model.current;
|
|
17320
|
-
const level = thinkingOption ?? (current && encodeModel(current).id ===
|
|
18150
|
+
const level = thinkingOption ?? (current && encodeModel(current).id === model2.id ? current.options?.reasoningLevel : void 0) ?? entry.reasoning?.defaultLevel;
|
|
17321
18151
|
if (level === void 0)
|
|
17322
18152
|
return native;
|
|
17323
18153
|
if (!entry.reasoning?.levels.some((option) => option.value === level))
|
|
@@ -17325,20 +18155,20 @@ function selectNativeModel(model, settings, thinkingOption) {
|
|
|
17325
18155
|
return { ...native, options: { reasoningLevel: level } };
|
|
17326
18156
|
}
|
|
17327
18157
|
function modelCatalog(settings) {
|
|
17328
|
-
const available = settings.model.available.filter((
|
|
18158
|
+
const available = settings.model.available.filter((model2) => !model2.disabledReason);
|
|
17329
18159
|
const levels = new Map(settings.thoughtLevel.available.map((level) => [level.value, level]));
|
|
17330
|
-
for (const
|
|
17331
|
-
for (const level of
|
|
18160
|
+
for (const model2 of available)
|
|
18161
|
+
for (const level of model2.reasoning?.levels ?? [])
|
|
17332
18162
|
levels.set(level.value, level);
|
|
17333
18163
|
const current = settings.model.current ? encodeModel(settings.model.current) : void 0;
|
|
17334
18164
|
const defaultThinking = settings.thoughtLevel.current ?? settings.thoughtLevel.defaultLevel;
|
|
17335
18165
|
return harnessModelCatalogSchema.parse({
|
|
17336
|
-
models: available.map((
|
|
17337
|
-
ref: encodeModel(
|
|
17338
|
-
label:
|
|
17339
|
-
supportedThinkingOptionIds:
|
|
18166
|
+
models: available.map((model2) => ({
|
|
18167
|
+
ref: encodeModel(model2.ref),
|
|
18168
|
+
label: model2.label,
|
|
18169
|
+
supportedThinkingOptionIds: model2.reasoning?.enabled ? model2.reasoning.levels.map((level) => level.value) : []
|
|
17340
18170
|
})),
|
|
17341
|
-
...current && available.some((
|
|
18171
|
+
...current && available.some((model2) => encodeModel(model2.ref).id === current.id) ? { defaultModel: current } : {},
|
|
17342
18172
|
thinkingOptions: [...levels.values()].map((level) => ({ id: level.value, label: level.label })),
|
|
17343
18173
|
...defaultThinking && levels.has(defaultThinking) ? { defaultThinkingOptionId: defaultThinking } : {}
|
|
17344
18174
|
});
|
|
@@ -17363,7 +18193,7 @@ function permissionModes(current = "build") {
|
|
|
17363
18193
|
function sessionState(snapshot, locator) {
|
|
17364
18194
|
const settings = snapshot.settings;
|
|
17365
18195
|
const current = settings.model.current ? encodeModel(settings.model.current) : void 0;
|
|
17366
|
-
const
|
|
18196
|
+
const model2 = settings.model.available.find((candidate) => encodeModel(candidate.ref).id === current?.id);
|
|
17367
18197
|
return {
|
|
17368
18198
|
nativeRef: nativeSessionRefSchema.parse({
|
|
17369
18199
|
harnessId: ZCODE_ID,
|
|
@@ -17372,7 +18202,7 @@ function sessionState(snapshot, locator) {
|
|
|
17372
18202
|
locator: { ...locator, cwd: snapshot.session.workspace.workspacePath }
|
|
17373
18203
|
}),
|
|
17374
18204
|
...current && settings.model.current?.providerId !== "zcode-unconfigured" ? { effectiveModel: current } : {},
|
|
17375
|
-
...
|
|
18205
|
+
...model2 ? { resolvedModelLabel: model2.label } : {},
|
|
17376
18206
|
...settings.thoughtLevel.enabled && settings.thoughtLevel.current ? {
|
|
17377
18207
|
effectiveThinkingOptionId: harnessThinkingOptionIdSchema.parse(settings.thoughtLevel.current)
|
|
17378
18208
|
} : {},
|
|
@@ -17386,7 +18216,7 @@ function sessionState(snapshot, locator) {
|
|
|
17386
18216
|
function sessionUsage(snapshot, catalog) {
|
|
17387
18217
|
const runtime = runtimeUsageSchema.safeParse(snapshot.runtime).data?.contextUsage;
|
|
17388
18218
|
const current = snapshot.settings.model.current;
|
|
17389
|
-
const window = catalog.model.available.find((
|
|
18219
|
+
const window = catalog.model.available.find((model2) => model2.ref.providerId === current?.providerId && model2.ref.modelId === current.modelId)?.contextWindow ?? snapshot.projection.contextWindow;
|
|
17390
18220
|
const cache = runtime?.cache;
|
|
17391
18221
|
const usage = {
|
|
17392
18222
|
...window > 0 ? {
|
|
@@ -17502,16 +18332,16 @@ var Diff = class {
|
|
|
17502
18332
|
}
|
|
17503
18333
|
}
|
|
17504
18334
|
}
|
|
17505
|
-
addToPath(
|
|
17506
|
-
const last =
|
|
18335
|
+
addToPath(path7, added, removed, oldPosInc, options) {
|
|
18336
|
+
const last = path7.lastComponent;
|
|
17507
18337
|
if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
|
|
17508
18338
|
return {
|
|
17509
|
-
oldPos:
|
|
18339
|
+
oldPos: path7.oldPos + oldPosInc,
|
|
17510
18340
|
lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
|
|
17511
18341
|
};
|
|
17512
18342
|
} else {
|
|
17513
18343
|
return {
|
|
17514
|
-
oldPos:
|
|
18344
|
+
oldPos: path7.oldPos + oldPosInc,
|
|
17515
18345
|
lastComponent: { count: 1, added, removed, previousComponent: last }
|
|
17516
18346
|
};
|
|
17517
18347
|
}
|
|
@@ -18572,6 +19402,7 @@ var ZcodeSession = class {
|
|
|
18572
19402
|
};
|
|
18573
19403
|
#state;
|
|
18574
19404
|
#snapshot;
|
|
19405
|
+
#usage;
|
|
18575
19406
|
#active;
|
|
18576
19407
|
#pendingInteractions = /* @__PURE__ */ new Map();
|
|
18577
19408
|
#closed = false;
|
|
@@ -18590,6 +19421,7 @@ var ZcodeSession = class {
|
|
|
18590
19421
|
this.capabilities = ZCODE_CAPABILITIES;
|
|
18591
19422
|
this.catalog = modelCatalog(nativeCatalog);
|
|
18592
19423
|
this.#snapshot = snapshot;
|
|
19424
|
+
this.#usage = new ZcodeUsage(snapshot.session.sessionId, (event) => this.#emit(event));
|
|
18593
19425
|
this.#goalActive = (snapshot.target === void 0 ? snapshot.projection.target : snapshot.target)?.status === "active";
|
|
18594
19426
|
this.#state = sessionState(snapshot, transport.locator);
|
|
18595
19427
|
this.initialState = structuredClone(this.#state);
|
|
@@ -18607,6 +19439,7 @@ var ZcodeSession = class {
|
|
|
18607
19439
|
this.#channel.emit({ kind: "event", event });
|
|
18608
19440
|
}
|
|
18609
19441
|
async subscribe() {
|
|
19442
|
+
this.#usage.replay(this.#snapshot.messages, true);
|
|
18610
19443
|
await this.transport.listen("onDynamicSessionEvent", {
|
|
18611
19444
|
sessionId: this.sessionId,
|
|
18612
19445
|
deliveryKind: "desktop-continuous",
|
|
@@ -18750,7 +19583,7 @@ var ZcodeSession = class {
|
|
|
18750
19583
|
try {
|
|
18751
19584
|
let method, params;
|
|
18752
19585
|
if (command.type === "model.select") {
|
|
18753
|
-
if (!this.catalog.models.some((
|
|
19586
|
+
if (!this.catalog.models.some((model2) => model2.ref.id === command.model.id))
|
|
18754
19587
|
return failure("invalidRequest", "ZCode model is not available");
|
|
18755
19588
|
method = "setModel";
|
|
18756
19589
|
params = {
|
|
@@ -18889,6 +19722,7 @@ var ZcodeSession = class {
|
|
|
18889
19722
|
if (event.seq <= this.#lastSeq)
|
|
18890
19723
|
return;
|
|
18891
19724
|
this.#lastSeq = event.seq;
|
|
19725
|
+
this.#usage.observe(event);
|
|
18892
19726
|
if (event.type === "session.updated" && event.payload && Object.hasOwn(event.payload, "target"))
|
|
18893
19727
|
this.#goalActive = record2(event.payload.target).status === "active";
|
|
18894
19728
|
if (event.type === "turn.started") {
|
|
@@ -18963,6 +19797,9 @@ var ZcodeSession = class {
|
|
|
18963
19797
|
} : turn?.outcome;
|
|
18964
19798
|
if (!outcome || outcome.status === "unknown")
|
|
18965
19799
|
throw new ZcodeError("protocolError", "ZCode completed without a confirmed turn outcome");
|
|
19800
|
+
if (this.#active !== active || this.#closed || this.#faulted)
|
|
19801
|
+
return;
|
|
19802
|
+
this.#usage.replay(snapshot.messages, false);
|
|
18966
19803
|
this.#finish(active, {
|
|
18967
19804
|
...outcome,
|
|
18968
19805
|
...turn?.checkpoint ? { checkpoint: turn.checkpoint } : {}
|
|
@@ -19077,8 +19914,10 @@ var ZcodeAdapter = class {
|
|
|
19077
19914
|
// One verification page and SDK instance for the whole Host, as in ZCode Desktop.
|
|
19078
19915
|
#verifier;
|
|
19079
19916
|
#prewarmed = false;
|
|
19917
|
+
usageStatistics;
|
|
19080
19918
|
constructor(options = {}) {
|
|
19081
19919
|
this.options = options;
|
|
19920
|
+
this.usageStatistics = createZcodeUsageStatistics(options.environment ?? process.env);
|
|
19082
19921
|
}
|
|
19083
19922
|
#sharedVerifier = (appVersion) => this.#verifier ??= (this.options.createVerifier ?? createZcodeVerifier)({
|
|
19084
19923
|
appVersion,
|
|
@@ -19110,7 +19949,7 @@ var ZcodeAdapter = class {
|
|
|
19110
19949
|
async inspect(input = {}) {
|
|
19111
19950
|
let transport;
|
|
19112
19951
|
try {
|
|
19113
|
-
transport = await this.#transport(
|
|
19952
|
+
transport = await this.#transport(path6.resolve(input.cwd ?? process.cwd()));
|
|
19114
19953
|
const settings = await readCatalog(transport);
|
|
19115
19954
|
const catalog = modelCatalog(settings);
|
|
19116
19955
|
if (!catalog.models.length)
|
|
@@ -19118,7 +19957,7 @@ var ZcodeAdapter = class {
|
|
|
19118
19957
|
status: "unavailable",
|
|
19119
19958
|
error: {
|
|
19120
19959
|
code: "authenticationRequired",
|
|
19121
|
-
message: "ZCode has no available models.
|
|
19960
|
+
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.",
|
|
19122
19961
|
retryable: true
|
|
19123
19962
|
}
|
|
19124
19963
|
};
|
|
@@ -19156,18 +19995,18 @@ var ZcodeAdapter = class {
|
|
|
19156
19995
|
let transport;
|
|
19157
19996
|
let createdId;
|
|
19158
19997
|
try {
|
|
19159
|
-
transport = await this.#transport(
|
|
19998
|
+
transport = await this.#transport(path6.resolve(input.cwd), input.environment);
|
|
19160
19999
|
let snapshot, settings;
|
|
19161
20000
|
if (input.kind === "create") {
|
|
19162
20001
|
settings = await readCatalog(transport);
|
|
19163
20002
|
if (input.permissionModeId && !permissionModes().modes.some((m) => m.id === input.permissionModeId))
|
|
19164
20003
|
throw new ZcodeError("invalidRequest", "Unknown ZCode permission mode");
|
|
19165
|
-
const
|
|
20004
|
+
const model2 = input.model ? selectNativeModel(input.model, settings, input.thinkingOptionId) : void 0;
|
|
19166
20005
|
const mode = input.executionPolicy === "unattended-full-access" ? "yolo" : input.permissionModeId;
|
|
19167
20006
|
const created = await transport.command(null, "createSession", {
|
|
19168
20007
|
workspaceId: input.cwd,
|
|
19169
20008
|
config: {
|
|
19170
|
-
...
|
|
20009
|
+
...model2 ? { modelSelection: model2 } : {},
|
|
19171
20010
|
...mode ? { mode } : {},
|
|
19172
20011
|
...input.thinkingOptionId ? { thought: input.thinkingOptionId } : {}
|
|
19173
20012
|
}
|