@karlorz/codexhost-cli-win32-x64 0.17.0-0 → 0.17.1-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/console-web.js +1 -1
- package/app/cpa-live-voice-hook.js +1 -1
- package/app/desktop-controller.mjs +910 -38
- package/app/host-runtime.mjs +911 -41
- package/app/plugins/antigravity/plugin.mjs +27 -7
- package/app/plugins/cursor-cli/plugin.mjs +19 -3
- package/app/plugins/kimi-code/plugin.mjs +50 -3
- package/app/plugins/pi/plugin.mjs +208 -88
- package/app/plugins/zcode/plugin.mjs +142 -9
- package/app/renderer-extension.js +800 -396
- package/bin/codexhost.exe +0 -0
- package/libexec/codexhost-node-repl.exe +0 -0
- package/libexec/codexhost-shim.exe +0 -0
- package/libexec/codexhost-updater.exe +0 -0
- package/package.json +1 -1
|
@@ -17052,7 +17052,7 @@ function createZcodeInstallation(environment, app) {
|
|
|
17052
17052
|
}
|
|
17053
17053
|
|
|
17054
17054
|
// dist/account.js
|
|
17055
|
-
import { createHash as
|
|
17055
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
17056
17056
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
17057
17057
|
import path5 from "node:path";
|
|
17058
17058
|
|
|
@@ -17101,10 +17101,100 @@ async function readCredential(installation, environment, key) {
|
|
|
17101
17101
|
}
|
|
17102
17102
|
|
|
17103
17103
|
// dist/personal-coding-plan.js
|
|
17104
|
-
import { createHash as
|
|
17104
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
17105
17105
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
17106
17106
|
import { homedir as homedir3 } from "node:os";
|
|
17107
17107
|
import path4 from "node:path";
|
|
17108
|
+
|
|
17109
|
+
// dist/project-token.js
|
|
17110
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
17111
|
+
var locationSchema = external_exports.object({
|
|
17112
|
+
organizationId: external_exports.string().trim().min(1),
|
|
17113
|
+
projectId: external_exports.string().trim().min(1),
|
|
17114
|
+
apiKeyId: external_exports.string().trim().min(1)
|
|
17115
|
+
});
|
|
17116
|
+
function readProjectCredential(credential, family, identity, origin) {
|
|
17117
|
+
const key = `project-key-location:v1:${encodeURIComponent(JSON.stringify([origin, family, identity, null, 1, "non-team"]))}`;
|
|
17118
|
+
const raw = credential(key);
|
|
17119
|
+
if (!raw)
|
|
17120
|
+
return void 0;
|
|
17121
|
+
const location = locationSchema.parse(JSON.parse(raw));
|
|
17122
|
+
const login = credential(`oauth:${family}:access_token`).trim();
|
|
17123
|
+
const loginToken = login.replace(/^Bearer\s+/i, "").trim();
|
|
17124
|
+
if (!loginToken)
|
|
17125
|
+
throw projectCredentialError();
|
|
17126
|
+
const accountScope = createHash2("sha256").update(JSON.stringify([
|
|
17127
|
+
family,
|
|
17128
|
+
"individual-coding-plan",
|
|
17129
|
+
null,
|
|
17130
|
+
login,
|
|
17131
|
+
credential("zcodejwttoken").trim() || null
|
|
17132
|
+
])).digest("hex");
|
|
17133
|
+
return { origin, loginToken, location, accountScope };
|
|
17134
|
+
}
|
|
17135
|
+
var tokenSchema = external_exports.object({
|
|
17136
|
+
success: external_exports.boolean().optional(),
|
|
17137
|
+
code: external_exports.union([external_exports.literal(0), external_exports.literal(200), external_exports.literal("0"), external_exports.literal("200")]),
|
|
17138
|
+
data: external_exports.object({
|
|
17139
|
+
enable: external_exports.boolean().optional(),
|
|
17140
|
+
accessToken: external_exports.string().trim().min(1),
|
|
17141
|
+
tokenType: external_exports.literal("Bearer"),
|
|
17142
|
+
expiresIn: external_exports.number().finite().positive(),
|
|
17143
|
+
expiresAt: external_exports.number().finite().positive()
|
|
17144
|
+
})
|
|
17145
|
+
});
|
|
17146
|
+
function projectCredentialError() {
|
|
17147
|
+
return new ZcodeError("authenticationRequired", "ZCode Personal Coding Plan project credentials are unavailable. Open the personal plan in ZCode Desktop, then re-detect ZCode and reopen the Thread");
|
|
17148
|
+
}
|
|
17149
|
+
var ProjectToken = class {
|
|
17150
|
+
#cached;
|
|
17151
|
+
async resolve(credential, appVersion, signal, rejectedFingerprint) {
|
|
17152
|
+
signal.throwIfAborted();
|
|
17153
|
+
const scope = createHash2("sha256").update(JSON.stringify(credential)).digest("hex");
|
|
17154
|
+
const cached2 = this.#cached;
|
|
17155
|
+
if (cached2?.scope === scope && cached2.fingerprint !== rejectedFingerprint && cached2.expiresAt > Date.now() + 12e4)
|
|
17156
|
+
return cached2.token;
|
|
17157
|
+
this.#cached = void 0;
|
|
17158
|
+
const { origin, location, loginToken } = credential;
|
|
17159
|
+
const url2 = `${origin}/api/biz/v1/organization/${encodeURIComponent(location.organizationId)}/projects/${encodeURIComponent(location.projectId)}/api_keys/${encodeURIComponent(location.apiKeyId)}/access_tokens`;
|
|
17160
|
+
const started = Date.now();
|
|
17161
|
+
try {
|
|
17162
|
+
const response = await fetch(url2, {
|
|
17163
|
+
method: "POST",
|
|
17164
|
+
headers: { Authorization: `Bearer ${loginToken}`, "Content-Type": "application/json" },
|
|
17165
|
+
body: JSON.stringify({ clientType: "zcode", clientVersion: appVersion }),
|
|
17166
|
+
redirect: "error",
|
|
17167
|
+
signal: AbortSignal.any([signal, AbortSignal.timeout(15e3)])
|
|
17168
|
+
});
|
|
17169
|
+
if (!response.ok)
|
|
17170
|
+
throw projectCredentialError();
|
|
17171
|
+
const parsed = tokenSchema.safeParse(await response.json());
|
|
17172
|
+
if (!parsed.success || parsed.data.success === false || parsed.data.data.enable === false)
|
|
17173
|
+
throw projectCredentialError();
|
|
17174
|
+
const data = parsed.data.data;
|
|
17175
|
+
const expiresAt = Math.min(data.expiresAt * 1e3, started + data.expiresIn * 1e3);
|
|
17176
|
+
signal.throwIfAborted();
|
|
17177
|
+
if (expiresAt <= Date.now())
|
|
17178
|
+
throw projectCredentialError();
|
|
17179
|
+
this.#cached = {
|
|
17180
|
+
scope,
|
|
17181
|
+
token: data.accessToken,
|
|
17182
|
+
expiresAt,
|
|
17183
|
+
fingerprint: createHash2("sha256").update(data.accessToken).digest("hex")
|
|
17184
|
+
};
|
|
17185
|
+
return data.accessToken;
|
|
17186
|
+
} catch (error51) {
|
|
17187
|
+
signal.throwIfAborted();
|
|
17188
|
+
if (error51 instanceof ZcodeError)
|
|
17189
|
+
throw error51;
|
|
17190
|
+
if (error51 instanceof Error && error51.name === "TimeoutError")
|
|
17191
|
+
throw new ZcodeError("unavailable", "ZCode project token request timed out. Try again.", true);
|
|
17192
|
+
throw projectCredentialError();
|
|
17193
|
+
}
|
|
17194
|
+
}
|
|
17195
|
+
};
|
|
17196
|
+
|
|
17197
|
+
// dist/personal-coding-plan.js
|
|
17108
17198
|
var familySchema = external_exports.enum(["zai", "bigmodel"]);
|
|
17109
17199
|
var recordSchema2 = external_exports.record(external_exports.string(), external_exports.unknown());
|
|
17110
17200
|
var CONNECT = "Connect Personal Coding Plan in ZCode Desktop, then re-detect ZCode and reopen the Thread";
|
|
@@ -17158,7 +17248,7 @@ async function queryEntitlement(family, apiKey, environment) {
|
|
|
17158
17248
|
try {
|
|
17159
17249
|
const response = await fetch(`${personalCodingPlanOrigin(family, environment)}/api/biz/subscription/list`, {
|
|
17160
17250
|
method: "GET",
|
|
17161
|
-
//
|
|
17251
|
+
// Legacy Desktop uses a personal API Key; project-token Desktop uses its OAuth login.
|
|
17162
17252
|
headers: { Authorization: apiKey.trim() },
|
|
17163
17253
|
redirect: "error",
|
|
17164
17254
|
signal: AbortSignal.timeout(15e3)
|
|
@@ -17192,6 +17282,8 @@ var PersonalCodingPlanAccount = class {
|
|
|
17192
17282
|
installation;
|
|
17193
17283
|
environment;
|
|
17194
17284
|
#authorized = /* @__PURE__ */ new Map();
|
|
17285
|
+
#projectToken = new ProjectToken();
|
|
17286
|
+
issue;
|
|
17195
17287
|
constructor(installation, environment) {
|
|
17196
17288
|
this.installation = installation;
|
|
17197
17289
|
this.environment = environment;
|
|
@@ -17211,12 +17303,16 @@ var PersonalCodingPlanAccount = class {
|
|
|
17211
17303
|
const identity = normalized ? normalized.id.trim() : family === "zai" && typeof profile.user_id === "string" ? profile.user_id.trim() : "";
|
|
17212
17304
|
if (!identity || identity === "unknown")
|
|
17213
17305
|
return void 0;
|
|
17306
|
+
const project2 = readProjectCredential(credential, family, identity, personalCodingPlanOrigin(family, this.environment));
|
|
17307
|
+
if (project2)
|
|
17308
|
+
return { identity, current, apiKey: project2.loginToken, project: project2 };
|
|
17214
17309
|
const key = `account-provider:coding-plan:${providerId}:account:${encodeURIComponent(identity)}:api-key`;
|
|
17215
17310
|
return { identity, current, apiKey: credential(key).trim() };
|
|
17216
17311
|
}
|
|
17217
17312
|
async inspect(providerId, accountType) {
|
|
17218
17313
|
const family = familySchema.parse(accountType);
|
|
17219
17314
|
this.#authorized.delete(providerId);
|
|
17315
|
+
this.issue = void 0;
|
|
17220
17316
|
let current = false;
|
|
17221
17317
|
try {
|
|
17222
17318
|
const context = await this.#context(providerId, family);
|
|
@@ -17228,24 +17324,29 @@ var PersonalCodingPlanAccount = class {
|
|
|
17228
17324
|
unavailableReason: "not-connected"
|
|
17229
17325
|
};
|
|
17230
17326
|
current = context.current;
|
|
17231
|
-
const connectionKey =
|
|
17327
|
+
const connectionKey = createHash3("sha256").update(JSON.stringify([family, context.identity, "individual-coding-plan"])).digest("hex");
|
|
17232
17328
|
const base = { current, connectionKey };
|
|
17233
|
-
if (!context.apiKey)
|
|
17329
|
+
if (!context.apiKey) {
|
|
17330
|
+
if (current)
|
|
17331
|
+
this.issue = "ZCode is signed in, but its Personal Coding Plan credentials are not initialized. Open the personal plan in ZCode Desktop, then re-detect ZCode. This does not mean the subscription is inactive.";
|
|
17234
17332
|
return {
|
|
17235
17333
|
...base,
|
|
17236
17334
|
availability: "unavailable",
|
|
17237
17335
|
entitled: false,
|
|
17238
17336
|
unavailableReason: "credential-failed"
|
|
17239
17337
|
};
|
|
17338
|
+
}
|
|
17240
17339
|
const entitlement = await queryEntitlement(family, context.apiKey, this.environment);
|
|
17241
17340
|
const after = await this.#context(providerId, family);
|
|
17242
|
-
if (!after || after.identity !== context.identity || after.current !== current || after.apiKey !== context.apiKey)
|
|
17341
|
+
if (!after || after.identity !== context.identity || after.current !== current || after.apiKey !== context.apiKey || JSON.stringify(after.project) !== JSON.stringify(context.project))
|
|
17243
17342
|
return { availability: "unknown", entitled: false, current: false };
|
|
17244
17343
|
if (entitlement === "available") {
|
|
17245
17344
|
if (current)
|
|
17246
17345
|
this.#authorized.set(providerId, { family, identity: context.identity });
|
|
17247
17346
|
return { ...base, availability: "available", entitled: true };
|
|
17248
17347
|
}
|
|
17348
|
+
if (current)
|
|
17349
|
+
this.issue = entitlement === "unavailable" ? "ZCode Personal Coding Plan subscription check found no active subscription. Check the selected account in ZCode Desktop, then re-detect ZCode." : "ZCode Personal Coding Plan credentials or subscription could not be verified. Open the personal plan in ZCode Desktop, then re-detect ZCode; subscription status is unknown.";
|
|
17249
17350
|
return {
|
|
17250
17351
|
...base,
|
|
17251
17352
|
availability: entitlement === "unknown" ? "unknown" : "unavailable",
|
|
@@ -17255,6 +17356,9 @@ var PersonalCodingPlanAccount = class {
|
|
|
17255
17356
|
}
|
|
17256
17357
|
};
|
|
17257
17358
|
} catch {
|
|
17359
|
+
current = await readSelection(this.environment, family).catch(() => false);
|
|
17360
|
+
if (current)
|
|
17361
|
+
this.issue = "ZCode Personal Coding Plan credentials could not be read or verified. Open the personal plan in ZCode Desktop, then re-detect ZCode; subscription status is unknown.";
|
|
17258
17362
|
return { availability: "unknown", entitled: false, current };
|
|
17259
17363
|
}
|
|
17260
17364
|
}
|
|
@@ -17266,7 +17370,9 @@ var PersonalCodingPlanAccount = class {
|
|
|
17266
17370
|
type: external_exports.literal("zhipu-account"),
|
|
17267
17371
|
mode: external_exports.literal("individual-coding-plan"),
|
|
17268
17372
|
accountType: familySchema
|
|
17269
|
-
})
|
|
17373
|
+
}),
|
|
17374
|
+
expectedAccountScope: external_exports.string().optional(),
|
|
17375
|
+
rejectedProjectTokenFingerprint: external_exports.string().optional()
|
|
17270
17376
|
}).safeParse(request);
|
|
17271
17377
|
if (!parsed.success)
|
|
17272
17378
|
throw new ZcodeError("authenticationRequired", CONNECT);
|
|
@@ -17279,6 +17385,23 @@ var PersonalCodingPlanAccount = class {
|
|
|
17279
17385
|
signal.throwIfAborted();
|
|
17280
17386
|
if (!context?.current || context.identity !== authorized.identity || !context.apiKey)
|
|
17281
17387
|
throw new ZcodeError("authenticationRequired", CONNECT);
|
|
17388
|
+
if (context.project) {
|
|
17389
|
+
const { expectedAccountScope, rejectedProjectTokenFingerprint } = parsed.data;
|
|
17390
|
+
if (expectedAccountScope !== void 0 && expectedAccountScope !== context.project.accountScope || rejectedProjectTokenFingerprint && !expectedAccountScope)
|
|
17391
|
+
throw new ZcodeError("authenticationRequired", CONNECT);
|
|
17392
|
+
const apiKey = await this.#projectToken.resolve(context.project, this.installation.version, signal, rejectedProjectTokenFingerprint);
|
|
17393
|
+
const after = await this.#context(providerId, authorized.family);
|
|
17394
|
+
signal.throwIfAborted();
|
|
17395
|
+
if (!after?.current || after.identity !== context.identity || JSON.stringify(after.project) !== JSON.stringify(context.project))
|
|
17396
|
+
throw new ZcodeError("authenticationRequired", CONNECT);
|
|
17397
|
+
return {
|
|
17398
|
+
apiKey,
|
|
17399
|
+
apiKeyId: context.project.location.apiKeyId,
|
|
17400
|
+
accountScope: context.project.accountScope
|
|
17401
|
+
};
|
|
17402
|
+
}
|
|
17403
|
+
if (parsed.data.expectedAccountScope !== void 0 || parsed.data.rejectedProjectTokenFingerprint)
|
|
17404
|
+
throw new ZcodeError("authenticationRequired", CONNECT);
|
|
17282
17405
|
return { apiKey: context.apiKey };
|
|
17283
17406
|
}
|
|
17284
17407
|
};
|
|
@@ -17404,7 +17527,7 @@ async function queryStartPlanBalance(origin, appVersion, jwt2, deviceMid) {
|
|
|
17404
17527
|
async function accountConfig(installation, environment) {
|
|
17405
17528
|
const file2 = installation.builtinProviderConfig;
|
|
17406
17529
|
const builtin = builtinSchema.parse(JSON.parse(await readFile3(file2, "utf8")));
|
|
17407
|
-
const basedOnZCodeBuiltinRevision = `zcode-builtin:${builtin.revision}:${
|
|
17530
|
+
const basedOnZCodeBuiltinRevision = `zcode-builtin:${builtin.revision}:${createHash4("sha256").update(path5.resolve(file2)).digest("hex")}`;
|
|
17408
17531
|
const family = await readCredential(installation, environment, "oauth:active_provider");
|
|
17409
17532
|
let balanceData;
|
|
17410
17533
|
if (family) {
|
|
@@ -17456,7 +17579,7 @@ async function accountConfig(installation, environment) {
|
|
|
17456
17579
|
};
|
|
17457
17580
|
}
|
|
17458
17581
|
}
|
|
17459
|
-
const overlayDigest =
|
|
17582
|
+
const overlayDigest = createHash4("sha256").update(JSON.stringify([providers, states])).digest("hex").slice(0, 16);
|
|
17460
17583
|
return {
|
|
17461
17584
|
params: {
|
|
17462
17585
|
revision: `codexhost:${family || "signed-out"}:${builtin.revision}:${overlayDigest}`,
|
|
@@ -17473,6 +17596,7 @@ async function accountConfig(installation, environment) {
|
|
|
17473
17596
|
async function providerRuntimeHeaders(request, signal, installation, environment, verifier, codingPlan) {
|
|
17474
17597
|
const mode = external_exports.object({ mode: external_exports.string() }).safeParse(request.accountAccess).data?.mode;
|
|
17475
17598
|
try {
|
|
17599
|
+
signal.throwIfAborted();
|
|
17476
17600
|
if (mode === "individual-coding-plan")
|
|
17477
17601
|
return { headersApplied: true, requestAuth: await codingPlan.requestAuth(request, signal) };
|
|
17478
17602
|
if (mode !== "start-plan")
|
|
@@ -17486,6 +17610,8 @@ async function providerRuntimeHeaders(request, signal, installation, environment
|
|
|
17486
17610
|
const headers = await verifier().verify(signal);
|
|
17487
17611
|
return { headersApplied: true, requestAuth: { apiKey, headers } };
|
|
17488
17612
|
} catch (error51) {
|
|
17613
|
+
if (signal.aborted)
|
|
17614
|
+
return { headersApplied: false };
|
|
17489
17615
|
return {
|
|
17490
17616
|
headersApplied: false,
|
|
17491
17617
|
errorMessage: error51 instanceof ZcodeError ? error51.message : "ZCode account authentication failed"
|
|
@@ -17594,6 +17720,9 @@ var CliTransport = class {
|
|
|
17594
17720
|
get startPlanChecked() {
|
|
17595
17721
|
return this.#startPlanChecked;
|
|
17596
17722
|
}
|
|
17723
|
+
get codingPlanIssue() {
|
|
17724
|
+
return this.#codingPlan?.issue;
|
|
17725
|
+
}
|
|
17597
17726
|
constructor(options) {
|
|
17598
17727
|
this.options = options;
|
|
17599
17728
|
this.#context = {
|
|
@@ -20370,6 +20499,10 @@ var ZcodeAdapter = class {
|
|
|
20370
20499
|
code: "authenticationRequired",
|
|
20371
20500
|
message: "ZCode has no available models. Sign in to ZCode Desktop with a Start Plan or Personal Coding Plan account, or add a personal provider, then re-detect ZCode. Team Coding Plan is not supported.",
|
|
20372
20501
|
retryable: true
|
|
20502
|
+
} : transport.codingPlanIssue ? {
|
|
20503
|
+
code: "configurationRequired",
|
|
20504
|
+
message: transport.codingPlanIssue,
|
|
20505
|
+
retryable: true
|
|
20373
20506
|
} : transport.startPlanChecked ? {
|
|
20374
20507
|
code: "configurationRequired",
|
|
20375
20508
|
message: "ZCode is signed in, but the account has no available models: no active Start Plan or event quota, no Personal Coding Plan, and no personal provider. Free trial and event quotas expire; subscribe to GLM Coding Plan or add a personal provider (API Key) in ZCode Desktop, then re-detect ZCode. Team Coding Plan is not supported.",
|