@moxt-ai/mobius 0.0.469 → 0.0.471

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.
@@ -5,7 +5,7 @@ import {
5
5
  __toESM,
6
6
  __using,
7
7
  package_default
8
- } from "./chunk-N3SPAVPT.js";
8
+ } from "./chunk-HPFAJPEN.js";
9
9
 
10
10
  // ../../node_modules/.pnpm/ignore@7.0.9/node_modules/ignore/index.js
11
11
  var require_ignore = __commonJS({
@@ -21407,6 +21407,90 @@ var encodeSessionPermissionRespondCommand = (message) => encodeZodMessage(messag
21407
21407
  var decodeSessionElicitationRespondCommand = (encoded) => decodeZodMessage(encoded, sessionElicitationRespondCommandSchema);
21408
21408
  var encodeSessionElicitationRespondCommand = (message) => encodeZodMessage(message, sessionElicitationRespondCommandSchema);
21409
21409
 
21410
+ // ../mobius-sdk/src/protocol/session/prompt/usage.ts
21411
+ var TOKEN_COUNT = external_exports.number().int().nonnegative();
21412
+ function normalizeQuotaTokenCount(value) {
21413
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
21414
+ return value;
21415
+ }
21416
+ if (Reflect.has(value, "inputTokens") || Reflect.has(value, "outputTokens") || Reflect.has(value, "totalTokens")) {
21417
+ return value;
21418
+ }
21419
+ if (!Reflect.has(value, "input_tokens") && !Reflect.has(value, "output_tokens")) {
21420
+ return value;
21421
+ }
21422
+ const inputTokens = Reflect.get(value, "input_tokens");
21423
+ const outputTokens = Reflect.get(value, "output_tokens");
21424
+ const reportedTotal = Reflect.get(value, "total_tokens");
21425
+ return {
21426
+ cachedInputTokens: Reflect.get(value, "cached_input_tokens"),
21427
+ cachedWriteTokens: Reflect.get(value, "cached_write_tokens"),
21428
+ inputTokens,
21429
+ outputTokens,
21430
+ reasoningOutputTokens: Reflect.get(value, "reasoning_output_tokens"),
21431
+ totalTokens: reportedTotal === void 0 && typeof inputTokens === "number" && typeof outputTokens === "number" ? inputTokens + outputTokens : reportedTotal
21432
+ };
21433
+ }
21434
+ var promptUsageSchema = external_exports.object({
21435
+ cachedReadTokens: TOKEN_COUNT.nullish(),
21436
+ cachedWriteTokens: TOKEN_COUNT.nullish(),
21437
+ inputTokens: TOKEN_COUNT,
21438
+ outputTokens: TOKEN_COUNT,
21439
+ thoughtTokens: TOKEN_COUNT.nullish(),
21440
+ totalTokens: TOKEN_COUNT
21441
+ }).readonly();
21442
+ var quotaTokenCountSchema = external_exports.preprocess(
21443
+ normalizeQuotaTokenCount,
21444
+ external_exports.object({
21445
+ cachedInputTokens: TOKEN_COUNT.optional(),
21446
+ cachedWriteTokens: TOKEN_COUNT.optional(),
21447
+ inputTokens: TOKEN_COUNT,
21448
+ outputTokens: TOKEN_COUNT,
21449
+ reasoningOutputTokens: TOKEN_COUNT.optional(),
21450
+ totalTokens: TOKEN_COUNT
21451
+ }).readonly()
21452
+ );
21453
+ var promptMetadataSchema = external_exports.object({
21454
+ messageId: external_exports.string().min(1).max(2048).optional(),
21455
+ quota: external_exports.object({
21456
+ model_usage: external_exports.array(
21457
+ external_exports.object({
21458
+ model: external_exports.string().min(1).max(255),
21459
+ token_count: quotaTokenCountSchema
21460
+ }).readonly()
21461
+ ).max(100).readonly(),
21462
+ token_count: quotaTokenCountSchema.nullable()
21463
+ }).readonly().optional()
21464
+ }).readonly();
21465
+ var turnTokenUsageSchema = external_exports.object({
21466
+ // All input, including cache reads and cache writes.
21467
+ inputTokens: TOKEN_COUNT,
21468
+ // The part of `inputTokens` read from the prompt cache.
21469
+ cachedInputTokens: TOKEN_COUNT,
21470
+ // The part of `inputTokens` written to the prompt cache.
21471
+ cacheWriteTokens: TOKEN_COUNT,
21472
+ // All output, including reasoning.
21473
+ outputTokens: TOKEN_COUNT,
21474
+ // The part of `outputTokens` spent on reasoning; absent when the Agent does not report it separately.
21475
+ reasoningTokens: TOKEN_COUNT.optional()
21476
+ }).readonly().refine(
21477
+ (usage) => usage.cachedInputTokens + usage.cacheWriteTokens <= usage.inputTokens && (usage.reasoningTokens ?? 0) <= usage.outputTokens
21478
+ );
21479
+ var agentPromptResponseSchema = external_exports.object({
21480
+ _meta: promptMetadataSchema.nullish(),
21481
+ stopReason: external_exports.enum(["end_turn", "max_tokens", "max_turn_requests", "refusal", "cancelled"]),
21482
+ usage: promptUsageSchema.nullish()
21483
+ }).readonly();
21484
+ function decodeAgentPromptResponse(value) {
21485
+ const result = agentPromptResponseSchema.safeParse(value);
21486
+ if (!result.success) {
21487
+ throw new ProtocolMessageError("Invalid agent prompt response", {
21488
+ cause: result.error
21489
+ });
21490
+ }
21491
+ return result.data;
21492
+ }
21493
+
21410
21494
  // ../mobius-sdk/src/protocol/session/events/index.ts
21411
21495
  var MAX_EVENT_COUNT = 1e4;
21412
21496
  var MAX_COLLECTION_SIZE2 = 1e3;
@@ -21682,12 +21766,14 @@ var sessionBackgroundTaskSchema = external_exports.object({
21682
21766
  toolCallId: external_exports.string().min(1).max(2048).optional().catch(void 0),
21683
21767
  description: external_exports.string().max(500).optional().catch(void 0)
21684
21768
  }).readonly();
21769
+ var promptTokenUsage = turnTokenUsageSchema.optional().catch(void 0);
21685
21770
  var promptCompletedSchema = external_exports.object({
21686
21771
  ...lifecycleBase,
21687
21772
  kind: external_exports.literal("prompt.completed"),
21688
21773
  execution: external_exports.literal("not-started").optional(),
21689
21774
  messageId: promptMessageId.optional(),
21690
- stopReason: shortString
21775
+ stopReason: shortString,
21776
+ usage: promptTokenUsage
21691
21777
  }).readonly();
21692
21778
  var promptFailedSchema = external_exports.object({
21693
21779
  ...lifecycleBase,
@@ -21695,7 +21781,8 @@ var promptFailedSchema = external_exports.object({
21695
21781
  code: identifierStringSchema,
21696
21782
  kind: external_exports.literal("prompt.failed"),
21697
21783
  message: external_exports.string().min(1).max(500),
21698
- messageId: promptMessageId.optional()
21784
+ messageId: promptMessageId.optional(),
21785
+ usage: promptTokenUsage
21699
21786
  }).readonly();
21700
21787
  var lifecycleMetadataSchema = external_exports.discriminatedUnion("kind", [
21701
21788
  // `changedByCommandId` names the command whose admission to or departure from the queue changed it. Runtimes
@@ -22760,76 +22847,6 @@ var encodeSessionPromptSuggestionReadCommand = (message) => encodeZodMessage(mes
22760
22847
  var decodeSessionPromptSuggestionReadResult = (encoded) => decodeZodMessage(encoded, sessionPromptSuggestionReadResultSchema);
22761
22848
  var encodeSessionPromptSuggestionReadResult = (message) => encodeZodMessage(message, sessionPromptSuggestionReadResultSchema);
22762
22849
 
22763
- // ../mobius-sdk/src/protocol/session/prompt/usage.ts
22764
- var TOKEN_COUNT = external_exports.number().int().nonnegative();
22765
- function normalizeQuotaTokenCount(value) {
22766
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
22767
- return value;
22768
- }
22769
- if (Reflect.has(value, "inputTokens") || Reflect.has(value, "outputTokens") || Reflect.has(value, "totalTokens")) {
22770
- return value;
22771
- }
22772
- if (!Reflect.has(value, "input_tokens") && !Reflect.has(value, "output_tokens")) {
22773
- return value;
22774
- }
22775
- const inputTokens = Reflect.get(value, "input_tokens");
22776
- const outputTokens = Reflect.get(value, "output_tokens");
22777
- const reportedTotal = Reflect.get(value, "total_tokens");
22778
- return {
22779
- cachedInputTokens: Reflect.get(value, "cached_input_tokens"),
22780
- cachedWriteTokens: Reflect.get(value, "cached_write_tokens"),
22781
- inputTokens,
22782
- outputTokens,
22783
- reasoningOutputTokens: Reflect.get(value, "reasoning_output_tokens"),
22784
- totalTokens: reportedTotal === void 0 && typeof inputTokens === "number" && typeof outputTokens === "number" ? inputTokens + outputTokens : reportedTotal
22785
- };
22786
- }
22787
- var promptUsageSchema = external_exports.object({
22788
- cachedReadTokens: TOKEN_COUNT.nullish(),
22789
- cachedWriteTokens: TOKEN_COUNT.nullish(),
22790
- inputTokens: TOKEN_COUNT,
22791
- outputTokens: TOKEN_COUNT,
22792
- thoughtTokens: TOKEN_COUNT.nullish(),
22793
- totalTokens: TOKEN_COUNT
22794
- }).readonly();
22795
- var quotaTokenCountSchema = external_exports.preprocess(
22796
- normalizeQuotaTokenCount,
22797
- external_exports.object({
22798
- cachedInputTokens: TOKEN_COUNT.optional(),
22799
- cachedWriteTokens: TOKEN_COUNT.optional(),
22800
- inputTokens: TOKEN_COUNT,
22801
- outputTokens: TOKEN_COUNT,
22802
- reasoningOutputTokens: TOKEN_COUNT.optional(),
22803
- totalTokens: TOKEN_COUNT
22804
- }).readonly()
22805
- );
22806
- var promptMetadataSchema = external_exports.object({
22807
- messageId: external_exports.string().min(1).max(2048).optional(),
22808
- quota: external_exports.object({
22809
- model_usage: external_exports.array(
22810
- external_exports.object({
22811
- model: external_exports.string().min(1).max(255),
22812
- token_count: quotaTokenCountSchema
22813
- }).readonly()
22814
- ).max(100).readonly(),
22815
- token_count: quotaTokenCountSchema.nullable()
22816
- }).readonly().optional()
22817
- }).readonly();
22818
- var agentPromptResponseSchema = external_exports.object({
22819
- _meta: promptMetadataSchema.nullish(),
22820
- stopReason: external_exports.enum(["end_turn", "max_tokens", "max_turn_requests", "refusal", "cancelled"]),
22821
- usage: promptUsageSchema.nullish()
22822
- }).readonly();
22823
- function decodeAgentPromptResponse(value) {
22824
- const result = agentPromptResponseSchema.safeParse(value);
22825
- if (!result.success) {
22826
- throw new ProtocolMessageError("Invalid agent prompt response", {
22827
- cause: result.error
22828
- });
22829
- }
22830
- return result.data;
22831
- }
22832
-
22833
22850
  // ../mobius-sdk/src/protocol/session/workspace/files.ts
22834
22851
  var WORKSPACE_FILES_LIST_KIND = "workspace.files.list";
22835
22852
  var WORKSPACE_FILES_KIND = "workspace.files";
@@ -76608,6 +76625,14 @@ var CLAUDE_USAGE_TIMEOUT_MILLISECONDS = 2e4;
76608
76625
  var MAX_CLI_OUTPUT_BYTES = 256 * 1024;
76609
76626
  var SESSION_WINDOW_MINUTES = 5 * 60;
76610
76627
  var WEEKLY_WINDOW_MINUTES = 7 * 24 * 60;
76628
+ var CLAUDE_AUTH_OVERRIDE_ENV_KEYS = [
76629
+ "ANTHROPIC_API_KEY",
76630
+ "ANTHROPIC_AUTH_TOKEN",
76631
+ "ANTHROPIC_BASE_URL",
76632
+ "CLAUDE_CODE_USE_BEDROCK",
76633
+ "CLAUDE_CODE_USE_VERTEX",
76634
+ "CLAUDE_CODE_USE_FOUNDRY"
76635
+ ];
76611
76636
  var authStatusSchema = external_exports.object({
76612
76637
  loggedIn: external_exports.boolean(),
76613
76638
  authMethod: external_exports.string().nullish(),
@@ -76886,13 +76911,34 @@ function claudeRateLimitEventToReport(info, observedAt) {
76886
76911
  return null;
76887
76912
  }
76888
76913
  }
76914
+ function buildClaudeSubscriptionEnvironment(environment) {
76915
+ const merged = { ...process.env, ...environment };
76916
+ for (const key of CLAUDE_AUTH_OVERRIDE_ENV_KEYS) {
76917
+ delete merged[key];
76918
+ }
76919
+ return merged;
76920
+ }
76921
+ function isClaudeAiSubscriptionAuth(auth) {
76922
+ if (!auth.loggedIn) {
76923
+ return false;
76924
+ }
76925
+ const provider = auth.apiProvider?.trim();
76926
+ const method = auth.authMethod?.trim();
76927
+ if (provider !== void 0 && provider.length > 0 && provider !== "firstParty") {
76928
+ return false;
76929
+ }
76930
+ if (method !== void 0 && method.length > 0 && method !== "claude.ai" && method !== "oauth") {
76931
+ return false;
76932
+ }
76933
+ return true;
76934
+ }
76889
76935
  async function runCliCommand(params) {
76890
76936
  params.signal.throwIfAborted();
76891
76937
  const launch = executableLaunch2(params.command, [...params.args]);
76892
76938
  const child = spawn5(launch.command, [...launch.arguments], {
76893
76939
  cwd: params.cwd,
76894
76940
  ...platformSpawnOptions,
76895
- env: { ...process.env, ...params.environment },
76941
+ env: params.env ?? { ...process.env, ...params.environment },
76896
76942
  shell: false,
76897
76943
  stdio: ["ignore", "pipe", "pipe"]
76898
76944
  });
@@ -76940,13 +76986,14 @@ async function runCliCommand(params) {
76940
76986
  });
76941
76987
  });
76942
76988
  }
76943
- async function readClaudeAuthStatus(options) {
76989
+ async function readClaudeAuthStatus(options, probe) {
76944
76990
  try {
76945
76991
  const result = await runCliCommand({
76946
76992
  command: options.command,
76947
- args: ["auth", "status"],
76993
+ args: probe.args,
76948
76994
  cwd: options.cwd,
76949
76995
  environment: options.environment,
76996
+ ...probe.env === void 0 ? {} : { env: probe.env },
76950
76997
  signal: options.signal,
76951
76998
  timeoutMs: CLAUDE_AUTH_TIMEOUT_MILLISECONDS
76952
76999
  });
@@ -77373,7 +77420,7 @@ function parseClaudeCliUsageOutput(output2, auth, checkedAt) {
77373
77420
  ...credits === void 0 ? {} : { credits }
77374
77421
  };
77375
77422
  }
77376
- async function readClaudeUsageViaSdk(options, auth, checkedAt) {
77423
+ async function readClaudeUsageViaSdk(options, auth, checkedAt, env) {
77377
77424
  const probeController = new AbortController();
77378
77425
  const timeoutSignal = AbortSignal.any([
77379
77426
  options.signal,
@@ -77390,8 +77437,7 @@ async function readClaudeUsageViaSdk(options, auth, checkedAt) {
77390
77437
  abortController: probeController,
77391
77438
  cwd: options.cwd,
77392
77439
  env: {
77393
- ...process.env,
77394
- ...options.environment,
77440
+ ...env,
77395
77441
  CLAUDE_CODE_EXECUTABLE: options.command
77396
77442
  },
77397
77443
  pathToClaudeCodeExecutable: options.command,
@@ -77422,30 +77468,43 @@ async function readClaudeUsageViaSdk(options, auth, checkedAt) {
77422
77468
  async function readClaudeUsageQuota(options) {
77423
77469
  options.signal.throwIfAborted();
77424
77470
  const checkedAt = (/* @__PURE__ */ new Date()).toISOString();
77425
- const auth = await readClaudeAuthStatus(options);
77426
- if (auth !== null) {
77427
- if (!auth.loggedIn) {
77428
- return {
77429
- agentId: "claude",
77430
- status: "unauthenticated",
77431
- checkedAt,
77432
- message: "Sign in to Claude Code on this computer to view subscription quotas."
77433
- };
77434
- }
77435
- const provider = auth.apiProvider?.trim();
77436
- const method = auth.authMethod?.trim();
77437
- if (provider !== void 0 && provider.length > 0 && provider !== "firstParty" || method !== void 0 && method.length > 0 && method !== "claude.ai" && method !== "oauth") {
77438
- return {
77439
- agentId: "claude",
77440
- status: "unsupported",
77441
- checkedAt,
77442
- reason: "api_key",
77443
- message: "Claude Code is not using a Claude.ai subscription."
77444
- };
77471
+ const subscriptionEnv = buildClaudeSubscriptionEnvironment(options.environment);
77472
+ const storedAuth = await readClaudeAuthStatus(options, {
77473
+ args: ["--setting-sources", "", "auth", "status"],
77474
+ env: subscriptionEnv
77475
+ });
77476
+ let auth = null;
77477
+ let useStoredLogin = false;
77478
+ if (storedAuth !== null && isClaudeAiSubscriptionAuth(storedAuth)) {
77479
+ auth = storedAuth;
77480
+ useStoredLogin = true;
77481
+ } else {
77482
+ const defaultAuth = await readClaudeAuthStatus(options, { args: ["auth", "status"] });
77483
+ const effectiveAuth = defaultAuth ?? storedAuth;
77484
+ if (effectiveAuth !== null) {
77485
+ if (!effectiveAuth.loggedIn) {
77486
+ return {
77487
+ agentId: "claude",
77488
+ status: "unauthenticated",
77489
+ checkedAt,
77490
+ message: "Sign in to Claude Code on this computer to view subscription quotas."
77491
+ };
77492
+ }
77493
+ if (!isClaudeAiSubscriptionAuth(effectiveAuth)) {
77494
+ return {
77495
+ agentId: "claude",
77496
+ status: "unsupported",
77497
+ checkedAt,
77498
+ reason: "api_key",
77499
+ message: "Claude Code is not using a Claude.ai subscription."
77500
+ };
77501
+ }
77502
+ auth = effectiveAuth;
77445
77503
  }
77446
77504
  }
77505
+ const probeEnv = useStoredLogin ? subscriptionEnv : { ...process.env, ...options.environment };
77447
77506
  try {
77448
- return await readClaudeUsageViaSdk(options, auth, checkedAt);
77507
+ return await readClaudeUsageViaSdk(options, auth, checkedAt, probeEnv);
77449
77508
  } catch (sdkError) {
77450
77509
  if (options.signal.aborted) {
77451
77510
  throw options.signal.reason ?? sdkError;
@@ -77453,9 +77512,10 @@ async function readClaudeUsageQuota(options) {
77453
77512
  try {
77454
77513
  const cliResult = await runCliCommand({
77455
77514
  command: options.command,
77456
- args: ["-p", "/usage"],
77515
+ args: useStoredLogin ? ["-p", "/usage", "--setting-sources", ""] : ["-p", "/usage"],
77457
77516
  cwd: options.cwd,
77458
77517
  environment: options.environment,
77518
+ env: probeEnv,
77459
77519
  signal: options.signal,
77460
77520
  timeoutMs: CLAUDE_USAGE_TIMEOUT_MILLISECONDS
77461
77521
  });
@@ -106242,4 +106302,4 @@ export {
106242
106302
  * MIT Licensed
106243
106303
  *)
106244
106304
  */
106245
- //# sourceMappingURL=chunk-YEFL2MHP.js.map
106305
+ //# sourceMappingURL=chunk-7XY5VCQJ.js.map