@codexhost/cli-darwin-arm64 0.17.0 → 0.17.2

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.
@@ -28478,6 +28478,21 @@ var threadSteeringInspectParamsSchema = external_exports.object({
28478
28478
  /** The text about to be steered; a Harness command always stops and restarts. */
28479
28479
  text: external_exports.string().optional()
28480
28480
  }).strict();
28481
+ var threadSteeringContextSchema = external_exports.object({
28482
+ kind: external_exports.literal("application"),
28483
+ value: external_exports.string().transform((text, context) => {
28484
+ try {
28485
+ return JSON.parse(text);
28486
+ } catch {
28487
+ context.addIssue({ code: "custom", message: "Invalid steering context JSON" });
28488
+ return external_exports.NEVER;
28489
+ }
28490
+ }).pipe(external_exports.object({
28491
+ expectedTurnId: hostTurnIdSchema,
28492
+ clientUserMessageId: external_exports.string().min(1),
28493
+ delivery: external_exports.enum(["newTurn", "activeTurn"])
28494
+ }).strict())
28495
+ }).strict().transform((context) => context.value);
28481
28496
  var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
28482
28497
  var threadSteeringInspectResultSchema = external_exports.object({
28483
28498
  delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
@@ -28075,6 +28075,21 @@ var threadSteeringInspectParamsSchema = external_exports.object({
28075
28075
  /** The text about to be steered; a Harness command always stops and restarts. */
28076
28076
  text: external_exports.string().optional()
28077
28077
  }).strict();
28078
+ var threadSteeringContextSchema = external_exports.object({
28079
+ kind: external_exports.literal("application"),
28080
+ value: external_exports.string().transform((text, context) => {
28081
+ try {
28082
+ return JSON.parse(text);
28083
+ } catch {
28084
+ context.addIssue({ code: "custom", message: "Invalid steering context JSON" });
28085
+ return external_exports.NEVER;
28086
+ }
28087
+ }).pipe(external_exports.object({
28088
+ expectedTurnId: hostTurnIdSchema,
28089
+ clientUserMessageId: external_exports.string().min(1),
28090
+ delivery: external_exports.enum(["newTurn", "activeTurn"])
28091
+ }).strict())
28092
+ }).strict().transform((context) => context.value);
28078
28093
  var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
28079
28094
  var threadSteeringInspectResultSchema = external_exports.object({
28080
28095
  delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
@@ -22380,6 +22380,21 @@ var threadSteeringInspectParamsSchema = external_exports.object({
22380
22380
  /** The text about to be steered; a Harness command always stops and restarts. */
22381
22381
  text: external_exports.string().optional()
22382
22382
  }).strict();
22383
+ var threadSteeringContextSchema = external_exports.object({
22384
+ kind: external_exports.literal("application"),
22385
+ value: external_exports.string().transform((text, context) => {
22386
+ try {
22387
+ return JSON.parse(text);
22388
+ } catch {
22389
+ context.addIssue({ code: "custom", message: "Invalid steering context JSON" });
22390
+ return external_exports.NEVER;
22391
+ }
22392
+ }).pipe(external_exports.object({
22393
+ expectedTurnId: hostTurnIdSchema,
22394
+ clientUserMessageId: external_exports.string().min(1),
22395
+ delivery: external_exports.enum(["newTurn", "activeTurn"])
22396
+ }).strict())
22397
+ }).strict().transform((context) => context.value);
22383
22398
  var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
22384
22399
  var threadSteeringInspectResultSchema = external_exports.object({
22385
22400
  delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
@@ -15492,6 +15492,21 @@ var threadSteeringInspectParamsSchema = external_exports.object({
15492
15492
  /** The text about to be steered; a Harness command always stops and restarts. */
15493
15493
  text: external_exports.string().optional()
15494
15494
  }).strict();
15495
+ var threadSteeringContextSchema = external_exports.object({
15496
+ kind: external_exports.literal("application"),
15497
+ value: external_exports.string().transform((text2, context) => {
15498
+ try {
15499
+ return JSON.parse(text2);
15500
+ } catch {
15501
+ context.addIssue({ code: "custom", message: "Invalid steering context JSON" });
15502
+ return external_exports.NEVER;
15503
+ }
15504
+ }).pipe(external_exports.object({
15505
+ expectedTurnId: hostTurnIdSchema,
15506
+ clientUserMessageId: external_exports.string().min(1),
15507
+ delivery: external_exports.enum(["newTurn", "activeTurn"])
15508
+ }).strict())
15509
+ }).strict().transform((context) => context.value);
15495
15510
  var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
15496
15511
  var threadSteeringInspectResultSchema = external_exports.object({
15497
15512
  delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
@@ -15678,6 +15678,21 @@ var threadSteeringInspectParamsSchema = external_exports.object({
15678
15678
  /** The text about to be steered; a Harness command always stops and restarts. */
15679
15679
  text: external_exports.string().optional()
15680
15680
  }).strict();
15681
+ var threadSteeringContextSchema = external_exports.object({
15682
+ kind: external_exports.literal("application"),
15683
+ value: external_exports.string().transform((text2, context) => {
15684
+ try {
15685
+ return JSON.parse(text2);
15686
+ } catch {
15687
+ context.addIssue({ code: "custom", message: "Invalid steering context JSON" });
15688
+ return external_exports.NEVER;
15689
+ }
15690
+ }).pipe(external_exports.object({
15691
+ expectedTurnId: hostTurnIdSchema,
15692
+ clientUserMessageId: external_exports.string().min(1),
15693
+ delivery: external_exports.enum(["newTurn", "activeTurn"])
15694
+ }).strict())
15695
+ }).strict().transform((context) => context.value);
15681
15696
  var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
15682
15697
  var threadSteeringInspectResultSchema = external_exports.object({
15683
15698
  delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
@@ -16879,7 +16894,7 @@ function createZcodeInstallation(environment, app) {
16879
16894
  }
16880
16895
 
16881
16896
  // dist/account.js
16882
- import { createHash as createHash3 } from "node:crypto";
16897
+ import { createHash as createHash4 } from "node:crypto";
16883
16898
  import { readFile as readFile3 } from "node:fs/promises";
16884
16899
  import path5 from "node:path";
16885
16900
 
@@ -16928,10 +16943,100 @@ async function readCredential(installation, environment, key) {
16928
16943
  }
16929
16944
 
16930
16945
  // dist/personal-coding-plan.js
16931
- import { createHash as createHash2 } from "node:crypto";
16946
+ import { createHash as createHash3 } from "node:crypto";
16932
16947
  import { readFile as readFile2 } from "node:fs/promises";
16933
16948
  import { homedir as homedir3 } from "node:os";
16934
16949
  import path4 from "node:path";
16950
+
16951
+ // dist/project-token.js
16952
+ import { createHash as createHash2 } from "node:crypto";
16953
+ var locationSchema = external_exports.object({
16954
+ organizationId: external_exports.string().trim().min(1),
16955
+ projectId: external_exports.string().trim().min(1),
16956
+ apiKeyId: external_exports.string().trim().min(1)
16957
+ });
16958
+ function readProjectCredential(credential, family, identity, origin) {
16959
+ const key = `project-key-location:v1:${encodeURIComponent(JSON.stringify([origin, family, identity, null, 1, "non-team"]))}`;
16960
+ const raw = credential(key);
16961
+ if (!raw)
16962
+ return void 0;
16963
+ const location = locationSchema.parse(JSON.parse(raw));
16964
+ const login = credential(`oauth:${family}:access_token`).trim();
16965
+ const loginToken = login.replace(/^Bearer\s+/i, "").trim();
16966
+ if (!loginToken)
16967
+ throw projectCredentialError();
16968
+ const accountScope = createHash2("sha256").update(JSON.stringify([
16969
+ family,
16970
+ "individual-coding-plan",
16971
+ null,
16972
+ login,
16973
+ credential("zcodejwttoken").trim() || null
16974
+ ])).digest("hex");
16975
+ return { origin, loginToken, location, accountScope };
16976
+ }
16977
+ var tokenSchema = external_exports.object({
16978
+ success: external_exports.boolean().optional(),
16979
+ code: external_exports.union([external_exports.literal(0), external_exports.literal(200), external_exports.literal("0"), external_exports.literal("200")]),
16980
+ data: external_exports.object({
16981
+ enable: external_exports.boolean().optional(),
16982
+ accessToken: external_exports.string().trim().min(1),
16983
+ tokenType: external_exports.literal("Bearer"),
16984
+ expiresIn: external_exports.number().finite().positive(),
16985
+ expiresAt: external_exports.number().finite().positive()
16986
+ })
16987
+ });
16988
+ function projectCredentialError() {
16989
+ 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");
16990
+ }
16991
+ var ProjectToken = class {
16992
+ #cached;
16993
+ async resolve(credential, appVersion, signal, rejectedFingerprint) {
16994
+ signal.throwIfAborted();
16995
+ const scope = createHash2("sha256").update(JSON.stringify(credential)).digest("hex");
16996
+ const cached2 = this.#cached;
16997
+ if (cached2?.scope === scope && cached2.fingerprint !== rejectedFingerprint && cached2.expiresAt > Date.now() + 12e4)
16998
+ return cached2.token;
16999
+ this.#cached = void 0;
17000
+ const { origin, location, loginToken } = credential;
17001
+ const url2 = `${origin}/api/biz/v1/organization/${encodeURIComponent(location.organizationId)}/projects/${encodeURIComponent(location.projectId)}/api_keys/${encodeURIComponent(location.apiKeyId)}/access_tokens`;
17002
+ const started = Date.now();
17003
+ try {
17004
+ const response = await fetch(url2, {
17005
+ method: "POST",
17006
+ headers: { Authorization: `Bearer ${loginToken}`, "Content-Type": "application/json" },
17007
+ body: JSON.stringify({ clientType: "zcode", clientVersion: appVersion }),
17008
+ redirect: "error",
17009
+ signal: AbortSignal.any([signal, AbortSignal.timeout(15e3)])
17010
+ });
17011
+ if (!response.ok)
17012
+ throw projectCredentialError();
17013
+ const parsed = tokenSchema.safeParse(await response.json());
17014
+ if (!parsed.success || parsed.data.success === false || parsed.data.data.enable === false)
17015
+ throw projectCredentialError();
17016
+ const data = parsed.data.data;
17017
+ const expiresAt = Math.min(data.expiresAt * 1e3, started + data.expiresIn * 1e3);
17018
+ signal.throwIfAborted();
17019
+ if (expiresAt <= Date.now())
17020
+ throw projectCredentialError();
17021
+ this.#cached = {
17022
+ scope,
17023
+ token: data.accessToken,
17024
+ expiresAt,
17025
+ fingerprint: createHash2("sha256").update(data.accessToken).digest("hex")
17026
+ };
17027
+ return data.accessToken;
17028
+ } catch (error51) {
17029
+ signal.throwIfAborted();
17030
+ if (error51 instanceof ZcodeError)
17031
+ throw error51;
17032
+ if (error51 instanceof Error && error51.name === "TimeoutError")
17033
+ throw new ZcodeError("unavailable", "ZCode project token request timed out. Try again.", true);
17034
+ throw projectCredentialError();
17035
+ }
17036
+ }
17037
+ };
17038
+
17039
+ // dist/personal-coding-plan.js
16935
17040
  var familySchema = external_exports.enum(["zai", "bigmodel"]);
16936
17041
  var recordSchema2 = external_exports.record(external_exports.string(), external_exports.unknown());
16937
17042
  var CONNECT = "Connect Personal Coding Plan in ZCode Desktop, then re-detect ZCode and reopen the Thread";
@@ -16985,7 +17090,7 @@ async function queryEntitlement(family, apiKey, environment) {
16985
17090
  try {
16986
17091
  const response = await fetch(`${personalCodingPlanOrigin(family, environment)}/api/biz/subscription/list`, {
16987
17092
  method: "GET",
16988
- // The subscription endpoint accepts the model API Key, not the OAuth token or Start JWT.
17093
+ // Legacy Desktop uses a personal API Key; project-token Desktop uses its OAuth login.
16989
17094
  headers: { Authorization: apiKey.trim() },
16990
17095
  redirect: "error",
16991
17096
  signal: AbortSignal.timeout(15e3)
@@ -17019,6 +17124,8 @@ var PersonalCodingPlanAccount = class {
17019
17124
  installation;
17020
17125
  environment;
17021
17126
  #authorized = /* @__PURE__ */ new Map();
17127
+ #projectToken = new ProjectToken();
17128
+ issue;
17022
17129
  constructor(installation, environment) {
17023
17130
  this.installation = installation;
17024
17131
  this.environment = environment;
@@ -17038,12 +17145,16 @@ var PersonalCodingPlanAccount = class {
17038
17145
  const identity = normalized ? normalized.id.trim() : family === "zai" && typeof profile.user_id === "string" ? profile.user_id.trim() : "";
17039
17146
  if (!identity || identity === "unknown")
17040
17147
  return void 0;
17148
+ const project2 = readProjectCredential(credential, family, identity, personalCodingPlanOrigin(family, this.environment));
17149
+ if (project2)
17150
+ return { identity, current, apiKey: project2.loginToken, project: project2 };
17041
17151
  const key = `account-provider:coding-plan:${providerId}:account:${encodeURIComponent(identity)}:api-key`;
17042
17152
  return { identity, current, apiKey: credential(key).trim() };
17043
17153
  }
17044
17154
  async inspect(providerId, accountType) {
17045
17155
  const family = familySchema.parse(accountType);
17046
17156
  this.#authorized.delete(providerId);
17157
+ this.issue = void 0;
17047
17158
  let current = false;
17048
17159
  try {
17049
17160
  const context = await this.#context(providerId, family);
@@ -17055,24 +17166,29 @@ var PersonalCodingPlanAccount = class {
17055
17166
  unavailableReason: "not-connected"
17056
17167
  };
17057
17168
  current = context.current;
17058
- const connectionKey = createHash2("sha256").update(JSON.stringify([family, context.identity, "individual-coding-plan"])).digest("hex");
17169
+ const connectionKey = createHash3("sha256").update(JSON.stringify([family, context.identity, "individual-coding-plan"])).digest("hex");
17059
17170
  const base = { current, connectionKey };
17060
- if (!context.apiKey)
17171
+ if (!context.apiKey) {
17172
+ if (current)
17173
+ 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.";
17061
17174
  return {
17062
17175
  ...base,
17063
17176
  availability: "unavailable",
17064
17177
  entitled: false,
17065
17178
  unavailableReason: "credential-failed"
17066
17179
  };
17180
+ }
17067
17181
  const entitlement = await queryEntitlement(family, context.apiKey, this.environment);
17068
17182
  const after = await this.#context(providerId, family);
17069
- if (!after || after.identity !== context.identity || after.current !== current || after.apiKey !== context.apiKey)
17183
+ if (!after || after.identity !== context.identity || after.current !== current || after.apiKey !== context.apiKey || JSON.stringify(after.project) !== JSON.stringify(context.project))
17070
17184
  return { availability: "unknown", entitled: false, current: false };
17071
17185
  if (entitlement === "available") {
17072
17186
  if (current)
17073
17187
  this.#authorized.set(providerId, { family, identity: context.identity });
17074
17188
  return { ...base, availability: "available", entitled: true };
17075
17189
  }
17190
+ if (current)
17191
+ 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.";
17076
17192
  return {
17077
17193
  ...base,
17078
17194
  availability: entitlement === "unknown" ? "unknown" : "unavailable",
@@ -17082,6 +17198,9 @@ var PersonalCodingPlanAccount = class {
17082
17198
  }
17083
17199
  };
17084
17200
  } catch {
17201
+ current = await readSelection(this.environment, family).catch(() => false);
17202
+ if (current)
17203
+ 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.";
17085
17204
  return { availability: "unknown", entitled: false, current };
17086
17205
  }
17087
17206
  }
@@ -17093,7 +17212,9 @@ var PersonalCodingPlanAccount = class {
17093
17212
  type: external_exports.literal("zhipu-account"),
17094
17213
  mode: external_exports.literal("individual-coding-plan"),
17095
17214
  accountType: familySchema
17096
- })
17215
+ }),
17216
+ expectedAccountScope: external_exports.string().optional(),
17217
+ rejectedProjectTokenFingerprint: external_exports.string().optional()
17097
17218
  }).safeParse(request);
17098
17219
  if (!parsed.success)
17099
17220
  throw new ZcodeError("authenticationRequired", CONNECT);
@@ -17106,6 +17227,23 @@ var PersonalCodingPlanAccount = class {
17106
17227
  signal.throwIfAborted();
17107
17228
  if (!context?.current || context.identity !== authorized.identity || !context.apiKey)
17108
17229
  throw new ZcodeError("authenticationRequired", CONNECT);
17230
+ if (context.project) {
17231
+ const { expectedAccountScope, rejectedProjectTokenFingerprint } = parsed.data;
17232
+ if (expectedAccountScope !== void 0 && expectedAccountScope !== context.project.accountScope || rejectedProjectTokenFingerprint && !expectedAccountScope)
17233
+ throw new ZcodeError("authenticationRequired", CONNECT);
17234
+ const apiKey = await this.#projectToken.resolve(context.project, this.installation.version, signal, rejectedProjectTokenFingerprint);
17235
+ const after = await this.#context(providerId, authorized.family);
17236
+ signal.throwIfAborted();
17237
+ if (!after?.current || after.identity !== context.identity || JSON.stringify(after.project) !== JSON.stringify(context.project))
17238
+ throw new ZcodeError("authenticationRequired", CONNECT);
17239
+ return {
17240
+ apiKey,
17241
+ apiKeyId: context.project.location.apiKeyId,
17242
+ accountScope: context.project.accountScope
17243
+ };
17244
+ }
17245
+ if (parsed.data.expectedAccountScope !== void 0 || parsed.data.rejectedProjectTokenFingerprint)
17246
+ throw new ZcodeError("authenticationRequired", CONNECT);
17109
17247
  return { apiKey: context.apiKey };
17110
17248
  }
17111
17249
  };
@@ -17231,7 +17369,7 @@ async function queryStartPlanBalance(origin, appVersion, jwt2, deviceMid) {
17231
17369
  async function accountConfig(installation, environment) {
17232
17370
  const file2 = installation.builtinProviderConfig;
17233
17371
  const builtin = builtinSchema.parse(JSON.parse(await readFile3(file2, "utf8")));
17234
- const basedOnZCodeBuiltinRevision = `zcode-builtin:${builtin.revision}:${createHash3("sha256").update(path5.resolve(file2)).digest("hex")}`;
17372
+ const basedOnZCodeBuiltinRevision = `zcode-builtin:${builtin.revision}:${createHash4("sha256").update(path5.resolve(file2)).digest("hex")}`;
17235
17373
  const family = await readCredential(installation, environment, "oauth:active_provider");
17236
17374
  let balanceData;
17237
17375
  if (family) {
@@ -17283,7 +17421,7 @@ async function accountConfig(installation, environment) {
17283
17421
  };
17284
17422
  }
17285
17423
  }
17286
- const overlayDigest = createHash3("sha256").update(JSON.stringify([providers, states])).digest("hex").slice(0, 16);
17424
+ const overlayDigest = createHash4("sha256").update(JSON.stringify([providers, states])).digest("hex").slice(0, 16);
17287
17425
  return {
17288
17426
  params: {
17289
17427
  revision: `codexhost:${family || "signed-out"}:${builtin.revision}:${overlayDigest}`,
@@ -17300,6 +17438,7 @@ async function accountConfig(installation, environment) {
17300
17438
  async function providerRuntimeHeaders(request, signal, installation, environment, verifier, codingPlan) {
17301
17439
  const mode = external_exports.object({ mode: external_exports.string() }).safeParse(request.accountAccess).data?.mode;
17302
17440
  try {
17441
+ signal.throwIfAborted();
17303
17442
  if (mode === "individual-coding-plan")
17304
17443
  return { headersApplied: true, requestAuth: await codingPlan.requestAuth(request, signal) };
17305
17444
  if (mode !== "start-plan")
@@ -17313,6 +17452,8 @@ async function providerRuntimeHeaders(request, signal, installation, environment
17313
17452
  const headers = await verifier().verify(signal);
17314
17453
  return { headersApplied: true, requestAuth: { apiKey, headers } };
17315
17454
  } catch (error51) {
17455
+ if (signal.aborted)
17456
+ return { headersApplied: false };
17316
17457
  return {
17317
17458
  headersApplied: false,
17318
17459
  errorMessage: error51 instanceof ZcodeError ? error51.message : "ZCode account authentication failed"
@@ -17421,6 +17562,9 @@ var CliTransport = class {
17421
17562
  get startPlanChecked() {
17422
17563
  return this.#startPlanChecked;
17423
17564
  }
17565
+ get codingPlanIssue() {
17566
+ return this.#codingPlan?.issue;
17567
+ }
17424
17568
  constructor(options) {
17425
17569
  this.options = options;
17426
17570
  this.#context = {
@@ -20144,6 +20288,10 @@ var ZcodeAdapter = class {
20144
20288
  code: "authenticationRequired",
20145
20289
  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.",
20146
20290
  retryable: true
20291
+ } : transport.codingPlanIssue ? {
20292
+ code: "configurationRequired",
20293
+ message: transport.codingPlanIssue,
20294
+ retryable: true
20147
20295
  } : transport.startPlanChecked ? {
20148
20296
  code: "configurationRequired",
20149
20297
  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.",