@cartanova/qgrid-cli 2.13.1 → 2.14.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.
Files changed (30) hide show
  1. package/bundle/dist/application/qgrid/qgrid.frame.js +6 -2
  2. package/bundle/dist/utils/providers/anthropic/anthropic-quota.js +3 -3
  3. package/bundle/dist/utils/providers/common/model-cost.js +31 -7
  4. package/bundle/dist/utils/providers/grok/grok-constants.js +2 -2
  5. package/bundle/dist/utils/providers/grok/grok-media-client.js +2 -2
  6. package/bundle/src/application/qgrid/qgrid.frame.test.ts +22 -8
  7. package/bundle/src/application/qgrid/qgrid.frame.ts +6 -1
  8. package/bundle/src/utils/providers/anthropic/anthropic-quota.test.ts +20 -1
  9. package/bundle/src/utils/providers/anthropic/anthropic-quota.ts +2 -2
  10. package/bundle/src/utils/providers/common/model-cost.test.ts +26 -4
  11. package/bundle/src/utils/providers/common/model-cost.ts +44 -11
  12. package/bundle/src/utils/providers/grok/grok-constants.ts +2 -2
  13. package/bundle/src/utils/providers/grok/grok-media-client.test.ts +6 -6
  14. package/bundle/src/utils/providers/grok/grok-types.test.ts +4 -4
  15. package/bundle/web-dist/client/assets/{index-DplV-wqZ.js → index-Cj7ZXipM.js} +3 -3
  16. package/bundle/web-dist/client/assets/{logs-st46aRba.js → logs-DSuoyKRh.js} +1 -1
  17. package/bundle/web-dist/client/assets/{monit-BMXR2tY2.js → monit-BwLPgwHG.js} +1 -1
  18. package/bundle/web-dist/client/assets/{routes-BWPjgvhg.js → routes-_R4-gxLV.js} +1 -1
  19. package/bundle/web-dist/client/assets/{settings-DTXZjDAw.js → settings-ZBCgAZaZ.js} +1 -1
  20. package/bundle/web-dist/client/assets/{show-CdWNFPyS.js → show-DFFBtBqe.js} +1 -1
  21. package/bundle/web-dist/client/assets/{tokens-eA34Gw5f.js → tokens-DYSfYz8A.js} +1 -1
  22. package/bundle/web-dist/client/assets/{use-oauth-login-flow-CcUdLsa7.js → use-oauth-login-flow-CN8nxeAR.js} +1 -1
  23. package/bundle/web-dist/client/assets/{use-update-token-mutation-D2r5K5Bz.js → use-update-token-mutation-B-N8fFUm.js} +1 -1
  24. package/bundle/web-dist/client/index.html +1 -1
  25. package/bundle/web-dist/server/entry-server.generated.js +1 -1
  26. package/package.json +1 -1
  27. package/skills/qgrid/references/anthropic-claude-code-runtime.md +2 -2
  28. package/skills/qgrid/references/decision-rationale.md +3 -2
  29. package/skills/qgrid/references/grok-runtime.md +6 -0
  30. package/skills/qgrid/references/token-auth-quota-lifecycle.md +3 -2
@@ -34,6 +34,25 @@ describe("readAnthropicQuotaUsage", () => {
34
34
  });
35
35
  });
36
36
 
37
+ it.each([
38
+ { fiveHour: 0, sevenDay: 100, expected: 100 },
39
+ { fiveHour: 80, sevenDay: 20, expected: 80 },
40
+ { fiveHour: null, sevenDay: 100, expected: 100 },
41
+ ])("includes shared weekly usage in Opus eligibility: %j", async ({ fiveHour, sevenDay, expected }) => {
42
+ fetchUsageWithMetaMock.mockResolvedValueOnce({
43
+ data: {
44
+ five_hour: { utilization: fiveHour, resets_at: null },
45
+ seven_day: { utilization: sevenDay, resets_at: null },
46
+ },
47
+ cachedAt: Date.now(),
48
+ });
49
+
50
+ await expect(readAnthropicQuotaUsage("access-token", "claude-opus-5-5")).resolves.toMatchObject({
51
+ kind: "ok",
52
+ utilizationPct: expected,
53
+ });
54
+ });
55
+
37
56
  it("uses the separate Fable 7-day limit only for Fable family requests", async () => {
38
57
  const usage = {
39
58
  data: {
@@ -104,7 +123,7 @@ describe("readAnthropicQuotaUsage", () => {
104
123
  });
105
124
  });
106
125
 
107
- it("treats missing five_hour utilization as lookup_failed", async () => {
126
+ it("treats missing usage across applicable windows as lookup_failed", async () => {
108
127
  fetchUsageWithMetaMock.mockResolvedValueOnce({
109
128
  data: { five_hour: { utilization: null, resets_at: null } },
110
129
  cachedAt: Date.now(),
@@ -19,7 +19,7 @@ export async function readAnthropicQuotaUsage(
19
19
 
20
20
  if (data.error) return { kind: "lookup_failed", reason: data.error };
21
21
 
22
- const utilizations = [data.five_hour?.utilization];
22
+ const utilizations = [data.five_hour?.utilization, data.seven_day?.utilization];
23
23
 
24
24
  // Fable 계열(5, 5.1)은 5시간 창과 별개로 usage credits 기반 7일 버킷도 소진될 수 있다.
25
25
  if (isFableFamilyModel(model)) {
@@ -33,7 +33,7 @@ export async function readAnthropicQuotaUsage(
33
33
  );
34
34
 
35
35
  if (!Number.isFinite(utilization)) {
36
- return { kind: "lookup_failed", reason: "five_hour utilization unavailable" };
36
+ return { kind: "lookup_failed", reason: "quota utilization unavailable" };
37
37
  }
38
38
 
39
39
  return {
@@ -30,17 +30,39 @@ describe("Grok cost", () => {
30
30
  );
31
31
 
32
32
  it("prefers reported image ticks and falls back to the catalog per-image price", () => {
33
- expect(grokImageCost("grok/grok-imagine-image-quality", 2, 700_000_000)).toEqual({
33
+ expect(grokImageCost("grok/grok-imagine-image-2.0", 2, 700_000_000)).toEqual({
34
34
  costUsd: 0.07,
35
35
  costSource: "provider",
36
36
  ticks: 700_000_000,
37
37
  });
38
- expect(grokImageCost("grok-imagine-image-quality", 2)).toEqual({
39
- costUsd: 0.1,
38
+ expect(grokImageCost("grok-imagine-image-2.0", 2)).toEqual({
39
+ costUsd: 0.08,
40
40
  costSource: "pricing_table",
41
- ticks: 1_000_000_000,
41
+ ticks: 800_000_000,
42
42
  });
43
43
  expect(grokImageCost("grok-imagine-image-unknown", 1)).toBeUndefined();
44
+ expect(grokImageCost("grok-imagine-image-quality", 1)).toBeUndefined();
45
+ expect(grokImageCost("grok-imagine-image-2.0", 1, 0)?.costUsd).toBe(0);
46
+ });
47
+
48
+ it.each([
49
+ ["1k", "low", 0.04],
50
+ ["1.5k", "low", 0.05],
51
+ ["2k", "low", 0.06],
52
+ ["1k", "medium", 0.06],
53
+ ["1.5k", "medium", 0.07],
54
+ ["2k", "medium", 0.08],
55
+ ])("estimates 2.0 output at %s/%s", (resolution, quality, expected) => {
56
+ expect(grokImageCost("grok-imagine-image-2.0", 1, undefined, { resolution, quality })?.costUsd).toBe(expected);
57
+ });
58
+
59
+ it("estimates auto edits with medium output and reference-image charges", () => {
60
+ expect(grokImageCost("grok-imagine-image-2.0", 2, undefined, {
61
+ resolution: "2k", quality: "auto", inputImageCount: 2,
62
+ })?.costUsd).toBe(0.18);
63
+ expect(grokImageCost("grok-imagine-image-2.0", 1, undefined, { inputImageCount: 1 })?.costUsd).toBe(0.07);
64
+ expect(grokImageCost("grok-imagine-image", 2, undefined, { resolution: "2k", inputImageCount: 1 })?.costUsd).toBe(0.042);
65
+ expect(grokImageCost("grok-imagine-image-2.0", 1, undefined, { quality: "high" })).toBeUndefined();
44
66
  });
45
67
 
46
68
  it("reports video/voice cost only when xAI reported it", () => {
@@ -270,13 +270,33 @@ const GROK_COSTS = new Map<string, ModelCosts>(
270
270
  }),
271
271
  );
272
272
 
273
- // Ticks per generated image at the default 1k resolution (the probe's quality 1k image cost exactly
274
- // this amount). Unlisted image models have no estimate.
275
- const GROK_IMAGE_PRICE_TICKS = new Map<string, number>(
276
- Object.entries({
277
- "grok-imagine-image-quality": 500_000_000,
278
- }),
279
- );
273
+ // Per-image ticks from https://docs.x.ai/developers/pricing (2026-10-25).
274
+ const GROK_IMAGE_PRICE_TICKS = new Map<
275
+ string,
276
+ { input: number; output: Readonly<Record<string, number>> }
277
+ >([
278
+ [
279
+ "grok-imagine-image",
280
+ {
281
+ input: 20_000_000,
282
+ output: { "1k": 200_000_000, "2k": 200_000_000 },
283
+ },
284
+ ],
285
+ [
286
+ "grok-imagine-image-2.0",
287
+ {
288
+ input: 100_000_000,
289
+ output: {
290
+ "1k:low": 400_000_000,
291
+ "1.5k:low": 500_000_000,
292
+ "2k:low": 600_000_000,
293
+ "1k:medium": 600_000_000,
294
+ "1.5k:medium": 700_000_000,
295
+ "2k:medium": 800_000_000,
296
+ },
297
+ },
298
+ ],
299
+ ]);
280
300
 
281
301
  export interface GrokMediaCost {
282
302
  costUsd: number;
@@ -286,19 +306,32 @@ export interface GrokMediaCost {
286
306
  }
287
307
 
288
308
  /**
289
- * Image cost: the reported ticks when present, otherwise the per-image catalog price times the
290
- * image count. Undefined when neither is known, so callers store an unknown cost, not a guess.
309
+ * Prefer reported ticks; otherwise price output quality/resolution and input images separately.
310
+ * Unknown models or price combinations have no estimate.
291
311
  */
292
312
  export function grokImageCost(
293
313
  model: string,
294
314
  imageCount: number,
295
315
  reportedTicks?: number,
316
+ options: { resolution?: string; quality?: string; inputImageCount?: number } = {},
296
317
  ): GrokMediaCost | undefined {
297
318
  if (reportedTicks !== undefined) return grokReportedCost(reportedTicks);
298
- const perImage = GROK_IMAGE_PRICE_TICKS.get(model.split("/").pop() ?? model);
319
+ const id = model.split("/").pop() ?? model;
320
+ const prices = GROK_IMAGE_PRICE_TICKS.get(id);
321
+
322
+ if (!prices) return undefined;
323
+ const inputImageCount = options.inputImageCount ?? 0;
324
+ const resolution = options.resolution ?? "1k";
325
+ const defaultQuality = inputImageCount > 0 ? "medium" : "low";
326
+
327
+ const quality = options.quality && options.quality !== "auto" ? options.quality : defaultQuality;
328
+
329
+ const priceKey = id === "grok-imagine-image-2.0" ? `${resolution}:${quality}` : resolution;
330
+
331
+ const perImage = Object.hasOwn(prices.output, priceKey) ? prices.output[priceKey] : undefined;
299
332
 
300
333
  if (perImage === undefined) return undefined;
301
- const ticks = perImage * imageCount;
334
+ const ticks = perImage * imageCount + prices.input * inputImageCount;
302
335
 
303
336
  return { costUsd: usdFromGrokTicks(ticks), costSource: "pricing_table", ticks };
304
337
  }
@@ -55,8 +55,8 @@ export const GROK_CLIENT_MODE = "headless";
55
55
  // U0 capture 2026-10-16 (GET /models default and /settings default_model)
56
56
  export const GROK_DEFAULT_MODEL = "grok-4.7";
57
57
 
58
- // grok-build 1.0.45 image_gen/mod.rs:33
59
- export const GROK_IMAGE_DEFAULT_MODEL = "grok-imagine-image-quality";
58
+ // https://docs.x.ai/developers/migration/imagine-image-quality-nov-2
59
+ export const GROK_IMAGE_DEFAULT_MODEL = "grok-imagine-image-2.0";
60
60
 
61
61
  // grok-build 1.0.45 video_gen/mod.rs:36-40
62
62
  export const GROK_VIDEO_DEFAULT_MODEL = "grok-imagine-video-1.5";
@@ -92,7 +92,7 @@ describe("GrokMediaClient images", () => {
92
92
  // Key order matters for byte-level parity with grok-build.
93
93
  expect(JSON.stringify(sent?.body)).toBe(
94
94
  JSON.stringify({
95
- model: "grok-imagine-image-quality",
95
+ model: "grok-imagine-image-2.0",
96
96
  prompt: "red square",
97
97
  n: 1,
98
98
  aspect_ratio: "1:1",
@@ -106,20 +106,20 @@ describe("GrokMediaClient images", () => {
106
106
  it("maps SDK option names and keeps response_format b64_json", async () => {
107
107
  const { impl, calls } = fakeFetch(async () => json(imageResponse));
108
108
  await new GrokMediaClient({ fetch: impl }).generateImages(AUTH, {
109
- model: "grok-imagine-image-pro",
109
+ model: "grok-imagine-image-2.0",
110
110
  prompt: "p",
111
111
  n: 3,
112
112
  resolution: "2k",
113
- quality: "high",
113
+ quality: "medium",
114
114
  outputFormat: "png",
115
115
  });
116
116
  expect(calls[0]?.body).toEqual({
117
- model: "grok-imagine-image-pro",
117
+ model: "grok-imagine-image-2.0",
118
118
  prompt: "p",
119
119
  n: 3,
120
120
  resolution: "2k",
121
121
  response_format: "b64_json",
122
- quality: "high",
122
+ quality: "medium",
123
123
  output_format: "png",
124
124
  });
125
125
  });
@@ -255,7 +255,7 @@ describe("GrokMediaClient images", () => {
255
255
  ]);
256
256
  expect(calls[0]?.headers["content-type"]).toBe("application/json");
257
257
  expect(calls[0]?.body).toEqual({
258
- model: "grok-imagine-image-quality",
258
+ model: "grok-imagine-image-2.0",
259
259
  prompt: "make it blue",
260
260
  n: 1,
261
261
  resolution: "1k",
@@ -205,13 +205,13 @@ describe("api.x.ai schemas", () => {
205
205
  const catalog = GrokApiImageModelCatalog.parse({
206
206
  models: [
207
207
  {
208
- id: "grok-imagine-image-quality",
209
- image_price: 500000000,
210
- pricing: [{ quality: "quality", resolution: "1k", price_per_image: 500000000 }],
208
+ id: "grok-imagine-image-2.0",
209
+ image_price: 400000000,
210
+ pricing: [{ quality: "low", resolution: "1k", price_per_image: 400000000 }],
211
211
  },
212
212
  ],
213
213
  });
214
- expect(grokCatalogModels(catalog)[0]?.pricing?.[0]?.price_per_image).toBe(500000000);
214
+ expect(grokCatalogModels(catalog)[0]?.pricing?.[0]?.price_per_image).toBe(400000000);
215
215
  });
216
216
 
217
217
  it("parses image, video, STT and TTS shapes", () => {