@cartanova/qgrid-cli 2.14.0 → 2.15.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.
Files changed (37) hide show
  1. package/bundle/dist/utils/providers/anthropic/anthropic-dispatcher.js +12 -13
  2. package/bundle/dist/utils/providers/anthropic/anthropic-quota.js +10 -6
  3. package/bundle/dist/utils/providers/common/model-cost.js +10 -1
  4. package/bundle/dist/utils/providers/grok/grok-dispatcher.js +15 -15
  5. package/bundle/dist/utils/providers/openai/openai-dispatcher.js +3 -2
  6. package/bundle/src/utils/providers/anthropic/anthropic-dispatcher.test.ts +31 -4
  7. package/bundle/src/utils/providers/anthropic/anthropic-dispatcher.ts +14 -14
  8. package/bundle/src/utils/providers/anthropic/anthropic-quota.test.ts +12 -7
  9. package/bundle/src/utils/providers/anthropic/anthropic-quota.ts +17 -7
  10. package/bundle/src/utils/providers/common/effort.test.ts +1 -0
  11. package/bundle/src/utils/providers/common/model-cost.test.ts +5 -0
  12. package/bundle/src/utils/providers/common/model-cost.ts +12 -0
  13. package/bundle/src/utils/providers/grok/grok-dispatcher.test.ts +23 -7
  14. package/bundle/src/utils/providers/grok/grok-dispatcher.ts +19 -23
  15. package/bundle/src/utils/providers/openai/openai-dispatcher.test.ts +9 -8
  16. package/bundle/src/utils/providers/openai/openai-dispatcher.ts +3 -1
  17. package/bundle/web-dist/client/assets/{index-Cj7ZXipM.js → index-JkBenvsH.js} +3 -3
  18. package/bundle/web-dist/client/assets/{logs-DSuoyKRh.js → logs-UozX8VD5.js} +1 -1
  19. package/bundle/web-dist/client/assets/{monit-BwLPgwHG.js → monit-CQ6cVvzc.js} +1 -1
  20. package/bundle/web-dist/client/assets/{routes-_R4-gxLV.js → routes-BkeaYiBN.js} +2 -2
  21. package/bundle/web-dist/client/assets/{settings-ZBCgAZaZ.js → settings-DJdBEFoL.js} +1 -1
  22. package/bundle/web-dist/client/assets/{show-DFFBtBqe.js → show-CcKkiy8Y.js} +1 -1
  23. package/bundle/web-dist/client/assets/{tokens-DYSfYz8A.js → tokens-DuLrdLMa.js} +1 -1
  24. package/bundle/web-dist/client/assets/{use-oauth-login-flow-CN8nxeAR.js → use-oauth-login-flow-CFJY-N99.js} +1 -1
  25. package/bundle/web-dist/client/assets/{use-update-token-mutation-B-N8fFUm.js → use-update-token-mutation-CrEi7wJa.js} +1 -1
  26. package/bundle/web-dist/client/index.html +1 -1
  27. package/bundle/web-dist/server/assets/{routes-CjWxvHAO.js → routes-CCdBJqP_.js} +11 -10
  28. package/bundle/web-dist/server/entry-server.generated.js +3 -2
  29. package/package.json +1 -1
  30. package/skills/qgrid/references/ai-sdk-provider-contract.md +1 -1
  31. package/skills/qgrid/references/anthropic-claude-code-runtime.md +4 -3
  32. package/skills/qgrid/references/decision-rationale.md +4 -4
  33. package/skills/qgrid/references/docs-workflow.md +10 -0
  34. package/skills/qgrid/references/grok-runtime.md +4 -1
  35. package/skills/qgrid/references/openai-codex-runtime.md +22 -5
  36. package/skills/qgrid/references/sonamu-api-web-flow.md +5 -1
  37. package/skills/qgrid/references/token-auth-quota-lifecycle.md +8 -5
@@ -75,6 +75,7 @@ describe("calculateCostUsd", () => {
75
75
  it.each([
76
76
  ["gpt-6-astra", 2.6],
77
77
  ["gpt-6.1-sol", 0.5],
78
+ ["gpt-6.1-terra", 0.25],
78
79
  ["gpt-6-sol", 0.52],
79
80
  ["gpt-6-luna", 0.026],
80
81
  ["gpt-5.6-sol", 1.04],
@@ -130,6 +131,7 @@ describe("calculateCostUsd", () => {
130
131
  it.each([
131
132
  ["gpt-6-astra", 10, 50, 1, 12.5],
132
133
  ["gpt-6.1-sol", 2, 10, 0.1, 2.5],
134
+ ["gpt-6.1-terra", 1, 5, 0.05, 1.25],
133
135
  ["gpt-6-sol", 2, 10, 0.2, 2.5],
134
136
  ["gpt-6-luna", 0.1, 0.5, 0.01, 0.125],
135
137
  ["gpt-5.6-sol", 4, 20, 0.4, 5],
@@ -217,6 +219,7 @@ describe("calculateCostUsd", () => {
217
219
  it.each([
218
220
  ["gpt-6-astra", 10, 50, 1, 12.5, 5.6125],
219
221
  ["gpt-6.1-sol", 2, 10, 0.1, 2.5, 1.1175],
222
+ ["gpt-6.1-terra", 1, 5, 0.05, 1.25, 0.55875],
220
223
  ["gpt-6-sol", 2, 10, 0.2, 2.5, 1.1225],
221
224
  ["gpt-6-luna", 0.1, 0.5, 0.01, 0.125, 0.056125],
222
225
  ["gpt-5.6-sol", 4, 20, 0.4, 5, 2.245],
@@ -246,6 +249,7 @@ describe("calculateCostUsd", () => {
246
249
  it.each([
247
250
  ["gpt-6-astra", 2.475],
248
251
  ["gpt-6.1-sol", 0.455],
252
+ ["gpt-6.1-terra", 0.2275],
249
253
  ["gpt-6-sol", 0.495],
250
254
  ["gpt-6-luna", 0.02475],
251
255
  ["gpt-5.6-sol", 0.99],
@@ -264,6 +268,7 @@ describe("calculateCostUsd", () => {
264
268
  it.each([
265
269
  ["gpt-6-astra", 2.725],
266
270
  ["gpt-6.1-sol", 0.505],
271
+ ["gpt-6.1-terra", 0.2525],
267
272
  ["gpt-6-sol", 0.545],
268
273
  ["gpt-6-luna", 0.02725],
269
274
  ["gpt-5.6-sol", 1.09],
@@ -79,6 +79,17 @@ const OPENAI_COSTS = new Map<string, OpenAIModelSpec>(
79
79
  cacheCreationInputTokens: 2.5,
80
80
  longContext: LONG_CONTEXT_272K,
81
81
  },
82
+ // GPT-6.1 Terra (2026-10-26 출시): Standard API pricing verified 2026-10-27. GPT-6.1 Sol 의 정확히 절반 단가.
83
+ // Codex 카탈로그(2026-10-27, client 0.164.0)는 ultra 까지 허용하고 기본 effort 는 low 다.
84
+ // @see https://developers.openai.com/api/docs/models/gpt-6.1-terra
85
+ "gpt-6.1-terra": {
86
+ maxEffort: "ultra",
87
+ inputTokens: 1,
88
+ outputTokens: 5,
89
+ cachedInputTokens: 0.05,
90
+ cacheCreationInputTokens: 1.25,
91
+ longContext: LONG_CONTEXT_272K,
92
+ },
82
93
  // GPT-6 Sol, Luna (2026-09-22 출시): Standard API pricing verified 2026-09-23. GPT-5.6 Sol/Luna 의 절반 단가.
83
94
  // Codex 카탈로그(2026-09-23)는 Sol 에 ultra, Luna 에 max 까지 허용하고 기본 effort 는 둘 다 medium 이다.
84
95
  // @see https://developers.openai.com/api/docs/models/gpt-6-sol
@@ -366,6 +377,7 @@ const OPENAI_FAST_MULTIPLIERS = new Map<string, number>(
366
377
  Object.entries({
367
378
  "gpt-6-astra": 2,
368
379
  "gpt-6.1-sol": 2,
380
+ "gpt-6.1-terra": 2,
369
381
  "gpt-6-sol": 2,
370
382
  "gpt-6-luna": 2,
371
383
  "gpt-5.6-sol": 2,
@@ -354,7 +354,7 @@ describe("GrokDispatcher selection", () => {
354
354
  const preferred = await h.dispatcher.selectToken("chat", { preferredTokenId: 2 });
355
355
  expect(preferred.token.id).toBe(2);
356
356
  preferred.release();
357
- h.billing.set(1, billingAt(90));
357
+ h.billing.set(1, billingAt(100));
358
358
  await expect(
359
359
  h.dispatcher.selectToken("chat", { preferredTokenId: 1, requirePreferredToken: true }),
360
360
  ).rejects.toBeInstanceOf(QuotaThresholdExceededError);
@@ -460,13 +460,29 @@ describe("GrokDispatcher selection", () => {
460
460
  expect(h.events.some((event) => event.startsWith("/billing"))).toBe(true);
461
461
  });
462
462
 
463
- it("blocks over-threshold tokens and reports QuotaThresholdExceededError", async () => {
463
+ it("ignores the configured threshold while weekly quota remains", async () => {
464
464
  const h = createHarness();
465
- h.add(1, 1, 50);
466
- h.billing.set(1, billingAt(75));
465
+ h.add(1, 1, 75);
466
+ h.billing.set(1, billingAt(92));
467
+ const reservation = await h.dispatcher.selectToken("chat");
468
+ expect(reservation.token.id).toBe(1);
469
+ reservation.release();
470
+ expect(h.dispatcher.getQuotaSnapshot()[0]).toMatchObject({ threshold: 100, blocked: false });
471
+ });
472
+
473
+ it.each([75, null])("blocks exhausted weekly quota with configured threshold %s", async (threshold) => {
474
+ const h = createHarness();
475
+ h.add(1, 1, threshold);
476
+ h.billing.set(1, billingAt(100));
467
477
  await expect(h.dispatcher.selectToken("chat")).rejects.toBeInstanceOf(
468
478
  QuotaThresholdExceededError,
469
479
  );
480
+ expect(h.dispatcher.getQuotaSnapshot()[0]).toMatchObject({ threshold: 100, blocked: true });
481
+ h.clock.now += 61_000;
482
+ h.billing.set(1, billingAt(92));
483
+ const reservation = await h.dispatcher.selectToken("chat");
484
+ expect(reservation.token.id).toBe(1);
485
+ reservation.release();
470
486
  });
471
487
  });
472
488
 
@@ -596,7 +612,7 @@ describe("GrokDispatcher chat", () => {
596
612
  expect(h.clock.now - startedAt).toBe(30_000);
597
613
  });
598
614
 
599
- it("blocks an exhausted token until a fresh billing read below threshold", async () => {
615
+ it("clears an exhaustion block after fresh billing falls below 100%", async () => {
600
616
  const h = createHarness();
601
617
  h.add(1, 5, 80);
602
618
  h.add(2, 1);
@@ -609,7 +625,7 @@ describe("GrokDispatcher chat", () => {
609
625
  await h.dispatcher.prefetch(token);
610
626
  expect(h.dispatcher.isEligible(token, "chat")).toBe(false);
611
627
  h.clock.now += 61_000;
612
- h.billing.set(1, billingAt(50));
628
+ h.billing.set(1, billingAt(92));
613
629
  await h.dispatcher.prefetch(token);
614
630
  expect(h.dispatcher.isEligible(token, "chat")).toBe(true);
615
631
  });
@@ -980,7 +996,7 @@ describe("GrokDispatcher media", () => {
980
996
  };
981
997
  const h = createHarness({ media, maxInflightPerToken: 1 });
982
998
  h.add(1, 1, 50);
983
- h.billing.set(1, billingAt(75));
999
+ h.billing.set(1, billingAt(100));
984
1000
  const token = h.dispatcher.tokens.get(1)!;
985
1001
  token.cooldowns.set("video", h.clock.now + 120_000);
986
1002
  token.inFlight = 1;
@@ -86,6 +86,7 @@ export const GROK_REFRESH_FAILED_COOLDOWN_MS = 5_000;
86
86
  export const GROK_MAX_STALE_AUTH_RETRIES = 1;
87
87
  const DEFAULT_REQUEST_TIMEOUT_MS = 600_000;
88
88
  const DEFAULT_IDLE_TIMEOUT_MS = 300_000;
89
+ const GROK_WEEKLY_QUOTA_LIMIT = 100;
89
90
 
90
91
  // ---------------------------------------------------------------------------
91
92
  // Errors
@@ -820,7 +821,7 @@ export class GrokDispatcher implements GrokProviderDispatcher, MediaDispatcher,
820
821
 
821
822
  if ((token.quotaBlocks.get(requestClass) ?? 0) > now) return "quota";
822
823
 
823
- if (token.quotaThreshold !== null && token.overThreshold) return "quota";
824
+ if (token.overThreshold) return "quota";
824
825
 
825
826
  if ((token.cooldowns.get(requestClass) ?? 0) > now) return "cooldown";
826
827
 
@@ -838,29 +839,19 @@ export class GrokDispatcher implements GrokProviderDispatcher, MediaDispatcher,
838
839
  * Refreshes the 60 s settings/subscription/billing caches. Lookup failures fail open, so an
839
840
  * expired bearer is refreshed first: a lookup with it would fail and open every gate. A failed
840
841
  * refresh therefore takes the token out of selection (`refresh_failed`) instead of failing open.
841
- * Billing is read only when a threshold or quota block gates the token, unless `includeBilling`.
842
+ * Weekly exhaustion is checked for every token, independently of its configured threshold.
842
843
  */
843
- async prefetch(
844
- token: GrokTokenState,
845
- signal?: AbortSignal,
846
- includeBilling = false,
847
- ): Promise<void> {
844
+ async prefetch(token: GrokTokenState, signal?: AbortSignal): Promise<void> {
848
845
  if (!token.credentials || token.invalidReason || token.reauthRequired) return;
849
846
  let now = this.now();
850
847
  const tasks: Promise<void>[] = [];
851
848
 
852
- const wantsBilling = () =>
853
- includeBilling ||
854
- token.quotaThreshold !== null ||
855
- [...token.quotaBlocks.values()].some((until) => until > now);
856
-
857
849
  const stale = (entry: Cached<unknown> | undefined) =>
858
850
  !entry ||
859
851
  entry.generation !== token.generation ||
860
852
  now - entry.fetchedAt >= GROK_LOOKUP_CACHE_TTL_MS;
861
853
 
862
- const billingDue = () =>
863
- wantsBilling() && stale(token.billing) && now >= token.billingNotBefore;
854
+ const billingDue = () => stale(token.billing) && now >= token.billingNotBefore;
864
855
 
865
856
  if (!stale(token.settings) && !stale(token.subscription) && !billingDue()) return;
866
857
 
@@ -903,7 +894,7 @@ export class GrokDispatcher implements GrokProviderDispatcher, MediaDispatcher,
903
894
  async refreshUsage(tokenId: number): Promise<void> {
904
895
  const token = this.tokens.get(tokenId);
905
896
 
906
- if (token) await this.prefetch(token, undefined, true);
897
+ if (token) await this.prefetch(token);
907
898
  }
908
899
 
909
900
  /** Transient refresh failure for `presented`; ignored when the token already holds newer ones. */
@@ -1036,18 +1027,18 @@ export class GrokDispatcher implements GrokProviderDispatcher, MediaDispatcher,
1036
1027
  return;
1037
1028
  }
1038
1029
 
1039
- const limit = token.quotaThreshold ?? 100;
1040
- const over = token.quotaThreshold !== null && result.utilizationPct >= token.quotaThreshold;
1030
+ const limit = GROK_WEEKLY_QUOTA_LIMIT;
1031
+ const over = result.utilizationPct >= limit;
1041
1032
 
1042
1033
  if (over && !token.overThreshold) {
1043
1034
  logger.info(
1044
- `quota_threshold gate: over_threshold ${token.name}[${token.id}] (${result.utilizationPct}% >= ${token.quotaThreshold}%)`,
1035
+ `quota_threshold gate: over_threshold ${token.name}[${token.id}] (${result.utilizationPct}% >= ${limit}%)`,
1045
1036
  );
1046
1037
  }
1047
1038
 
1048
1039
  if (!over && token.overThreshold) {
1049
1040
  logger.info(
1050
- `quota_threshold gate: recovered ${token.name}[${token.id}] (${result.utilizationPct}% < ${token.quotaThreshold}%)`,
1041
+ `quota_threshold gate: recovered ${token.name}[${token.id}] (${result.utilizationPct}% < ${limit}%)`,
1051
1042
  );
1052
1043
  }
1053
1044
 
@@ -1202,7 +1193,12 @@ export class GrokDispatcher implements GrokProviderDispatcher, MediaDispatcher,
1202
1193
  if (present.has("quota")) {
1203
1194
  const over = [...reasons].flatMap(([token, reason]) =>
1204
1195
  reason === "quota"
1205
- ? [{ name: token.name, threshold: token.overThreshold ? token.quotaThreshold : null }]
1196
+ ? [
1197
+ {
1198
+ name: token.name,
1199
+ threshold: token.overThreshold ? GROK_WEEKLY_QUOTA_LIMIT : null,
1200
+ },
1201
+ ]
1206
1202
  : [],
1207
1203
  );
1208
1204
 
@@ -1231,7 +1227,7 @@ export class GrokDispatcher implements GrokProviderDispatcher, MediaDispatcher,
1231
1227
  if (reason === "quota") {
1232
1228
  return new QuotaThresholdExceededError(
1233
1229
  quotaMessage([
1234
- { name: token.name, threshold: token.overThreshold ? token.quotaThreshold : null },
1230
+ { name: token.name, threshold: token.overThreshold ? GROK_WEEKLY_QUOTA_LIMIT : null },
1235
1231
  ]),
1236
1232
  );
1237
1233
  }
@@ -2097,7 +2093,7 @@ export class GrokDispatcher implements GrokProviderDispatcher, MediaDispatcher,
2097
2093
  fetchedAt: token.billing!.fetchedAt,
2098
2094
  }
2099
2095
  : null,
2100
- quotaThreshold: token.quotaThreshold,
2096
+ quotaThreshold: GROK_WEEKLY_QUOTA_LIMIT,
2101
2097
  overThreshold: token.overThreshold,
2102
2098
  onDemandExcluded: settings?.kind === "ok" && settings.onDemandEnabled === true,
2103
2099
  zdrVideoExcluded: token.zdr === true,
@@ -2141,7 +2137,7 @@ export class GrokDispatcher implements GrokProviderDispatcher, MediaDispatcher,
2141
2137
  return {
2142
2138
  name: token.name,
2143
2139
  usedPercent: fresh ? billing.utilizationPct : null,
2144
- threshold: token.quotaThreshold,
2140
+ threshold: GROK_WEEKLY_QUOTA_LIMIT,
2145
2141
  blocked:
2146
2142
  token.overThreshold || [...token.quotaBlocks.values()].some((until) => until > now),
2147
2143
  resetsAt: fresh ? billing.periodEndMs : null,
@@ -53,7 +53,7 @@ async function tickTimer(): Promise<void> {
53
53
  }
54
54
 
55
55
  describe("OpenAIDispatcher direct runtime", () => {
56
- it.each(["gpt-6-sol", "gpt-6-luna", "gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna", "gpt-5.5"])(
56
+ it.each(["gpt-6.1-terra", "gpt-6-sol", "gpt-6-luna", "gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna", "gpt-5.5"])(
57
57
  "disables thinking and omits summaries through generate/stream for %s",
58
58
  async (model) => {
59
59
  const run = vi.fn((options: OpenAIResponsesOptions) => {
@@ -946,13 +946,13 @@ describe("OpenAIDispatcher direct runtime", () => {
946
946
  expect(started).not.toHaveBeenCalled();
947
947
  });
948
948
 
949
- it("routes past an over-threshold token instead of treating it as capacity", async () => {
949
+ it("applies the configured threshold to the OpenAI weekly primary window", async () => {
950
950
  const names: string[] = [];
951
951
  const d = new OpenAIDispatcher(config(), {
952
952
  clientFactory: () => ({ responses: () => events({ type: "completed", responseId: "r" }) }),
953
953
  fetch: async () =>
954
954
  new Response(
955
- JSON.stringify({ rate_limits: { primary_window: { used_percent: 90 } } }),
955
+ JSON.stringify({ rate_limits: { primary_window: { used_percent: 90, limit_window_seconds: 604_800 } } }),
956
956
  { status: 200, headers: { "content-type": "application/json" } },
957
957
  ),
958
958
  });
@@ -1008,13 +1008,14 @@ describe("effort 어휘 해석 (Codex 카탈로그 기준)", () => {
1008
1008
  return mapped?.reasoning?.effort;
1009
1009
  }
1010
1010
 
1011
- it("모델이 지원하는 값은 그대로 보내고, 상한 초과·공개 API 어휘는 reasoning 에서 빼 백엔드 기본값을 쓴다", async () => {
1012
- await expect(mappedEffortFor("gpt-6-astra", "ultra")).resolves.toBe("ultra");
1013
- await expect(mappedEffortFor("gpt-6.1-sol", "ultra")).resolves.toBe("ultra");
1014
- await expect(mappedEffortFor("gpt-6-sol", "ultra")).resolves.toBe("ultra");
1011
+ it("모델이 지원하는 값은 그대로 보내되 ultra 는 wire 상한인 max 로 보내고, 상한 초과·공개 API 어휘는 reasoning 에서 빼 백엔드 기본값을 쓴다", async () => {
1012
+ await expect(mappedEffortFor("gpt-6-astra", "ultra")).resolves.toBe("max");
1013
+ await expect(mappedEffortFor("gpt-6.1-sol", "ultra")).resolves.toBe("max");
1014
+ await expect(mappedEffortFor("gpt-6.1-terra", "ultra")).resolves.toBe("max");
1015
+ await expect(mappedEffortFor("gpt-6-sol", "ultra")).resolves.toBe("max");
1015
1016
  await expect(mappedEffortFor("gpt-6-luna", "max")).resolves.toBe("max");
1016
1017
  await expect(mappedEffortFor("gpt-6-luna", "ultra")).resolves.toBeUndefined();
1017
- await expect(mappedEffortFor("gpt-5.6-terra", "ultra")).resolves.toBe("ultra");
1018
+ await expect(mappedEffortFor("gpt-5.6-terra", "ultra")).resolves.toBe("max");
1018
1019
  await expect(mappedEffortFor("gpt-5.5", "xhigh")).resolves.toBe("xhigh");
1019
1020
  await expect(mappedEffortFor("gpt-5.5", "max")).resolves.toBeUndefined();
1020
1021
  await expect(mappedEffortFor("gpt-5.6-terra", "minimal")).resolves.toBeUndefined();
@@ -35,6 +35,7 @@ const logger = getLogger(["qgrid", "openai-dispatcher"]);
35
35
 
36
36
  // Verified with the subscription Responses backend; public API support is not sufficient.
37
37
  const THINKING_OFF_MODELS = new Set([
38
+ "gpt-6.1-terra",
38
39
  "gpt-6-sol",
39
40
  "gpt-6-luna",
40
41
  "gpt-5.6-sol",
@@ -189,7 +190,8 @@ function asReasoning(req: GenerateRequest): OpenAIReasoning | undefined {
189
190
 
190
191
  const reasoning: OpenAIReasoning = {};
191
192
 
192
- if (effort) reasoning.effort = effort;
193
+ // ultra is a Codex client mode (sub-agent delegation), not a wire value; the backend accepts up to max.
194
+ if (effort) reasoning.effort = effort === "ultra" ? "max" : effort;
193
195
 
194
196
  if (summary) reasoning.summary = summary;
195
197