@cartanova/qgrid-cli 2.22.2 → 2.23.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 (77) hide show
  1. package/bundle/dist/application/qgrid/model-catalog.js +62 -0
  2. package/bundle/dist/application/qgrid/openai-compat.js +127 -0
  3. package/bundle/dist/application/qgrid/qgrid-run-lifecycle.js +2 -2
  4. package/bundle/dist/application/qgrid/qgrid.frame.js +204 -8
  5. package/bundle/dist/application/qgrid/qgrid.types.js +82 -2
  6. package/bundle/dist/application/qgrid/transcribe-stream.js +282 -0
  7. package/bundle/dist/application/queries.generated.js +2 -1
  8. package/bundle/dist/application/request-log/request-log.model.js +5 -4
  9. package/bundle/dist/server-error-handler.js +6 -3
  10. package/bundle/dist/sonamu.config.js +5 -2
  11. package/bundle/dist/utils/providers/anthropic/anthropic-constants.js +8 -2
  12. package/bundle/dist/utils/providers/anthropic/anthropic-quota.js +1 -1
  13. package/bundle/dist/utils/providers/common/model-cost.js +29 -2
  14. package/bundle/dist/utils/providers/openai/openai-dispatcher.js +9 -1
  15. package/bundle/dist/utils/providers/openai/openai-realtime-protocol.js +38 -6
  16. package/bundle/dist/utils/providers/openai/openai-voice-client.js +131 -3
  17. package/bundle/src/application/qgrid/model-catalog.test.ts +37 -0
  18. package/bundle/src/application/qgrid/model-catalog.ts +85 -0
  19. package/bundle/src/application/qgrid/openai-compat.test.ts +99 -0
  20. package/bundle/src/application/qgrid/openai-compat.ts +157 -0
  21. package/bundle/src/application/qgrid/qgrid-run-lifecycle.test.ts +1 -1
  22. package/bundle/src/application/qgrid/qgrid-run-lifecycle.ts +1 -1
  23. package/bundle/src/application/qgrid/qgrid.frame.test.ts +5 -0
  24. package/bundle/src/application/qgrid/qgrid.frame.ts +294 -0
  25. package/bundle/src/application/qgrid/qgrid.types.ts +134 -0
  26. package/bundle/src/application/qgrid/transcribe-stream.test.ts +165 -0
  27. package/bundle/src/application/qgrid/transcribe-stream.ts +381 -0
  28. package/bundle/src/application/queries.generated.ts +3 -0
  29. package/bundle/src/application/request-log/request-log.model.test.ts +4 -3
  30. package/bundle/src/application/request-log/request-log.model.ts +4 -3
  31. package/bundle/src/application/sonamu.generated.http +12 -0
  32. package/bundle/src/server-error-handler.ts +10 -7
  33. package/bundle/src/sonamu.config.ts +4 -0
  34. package/bundle/src/utils/providers/anthropic/anthropic-constants.test.ts +3 -0
  35. package/bundle/src/utils/providers/anthropic/anthropic-constants.ts +3 -1
  36. package/bundle/src/utils/providers/anthropic/anthropic-quota.ts +1 -1
  37. package/bundle/src/utils/providers/common/effort.test.ts +2 -0
  38. package/bundle/src/utils/providers/common/model-cost.test.ts +11 -0
  39. package/bundle/src/utils/providers/common/model-cost.ts +43 -5
  40. package/bundle/src/utils/providers/openai/openai-dispatcher.ts +15 -0
  41. package/bundle/src/utils/providers/openai/openai-realtime-protocol.ts +46 -5
  42. package/bundle/src/utils/providers/openai/openai-voice-client.test.ts +89 -2
  43. package/bundle/src/utils/providers/openai/openai-voice-client.ts +188 -0
  44. package/bundle/web-dist/client/assets/index-CtkfXtee.js +104 -0
  45. package/bundle/web-dist/client/assets/logs-C_U9lGtE.js +1 -0
  46. package/bundle/web-dist/client/assets/{monit-0qjGcPcD.js → monit-CNQyE4bk.js} +1 -1
  47. package/bundle/web-dist/client/assets/{routes-D53FyOOp.js → routes-72N6ogd2.js} +2 -2
  48. package/bundle/web-dist/client/assets/{settings-Cbz57odO.js → settings-DbwnDBrc.js} +1 -1
  49. package/bundle/web-dist/client/assets/{show-Boi25Rbi.js → show-BPkKGDnC.js} +2 -2
  50. package/bundle/web-dist/client/assets/tokens-2ig4rFfF.js +1 -0
  51. package/bundle/web-dist/client/assets/{use-oauth-login-flow-CjFv4NI0.js → use-oauth-login-flow-CvjEVH_T.js} +1 -1
  52. package/bundle/web-dist/client/assets/use-update-token-mutation-C8viUPmK.js +1 -0
  53. package/bundle/web-dist/client/assets/{voice-BDO8X2H0.js → voice-D2RSPjn9.js} +2 -2
  54. package/bundle/web-dist/client/index.html +1 -1
  55. package/bundle/web-dist/server/assets/{TimedPlayer-mpJpP5tQ.js → TimedPlayer-B9ds1sqM.js} +1 -1
  56. package/bundle/web-dist/server/assets/{logs-CFa_xamY.js → logs-JziKvWBp.js} +3 -3
  57. package/bundle/web-dist/server/assets/{monit-BF6osfj5.js → monit-CzjNOowb.js} +2 -2
  58. package/bundle/web-dist/server/assets/{plus-DwQFfeid.js → plus-BrRDgdaN.js} +1 -1
  59. package/bundle/web-dist/server/assets/{refresh-cw-Bj-Jxeb6.js → refresh-cw-wU5-wVTi.js} +1 -1
  60. package/bundle/web-dist/server/assets/{request-model-D_iYrudl.js → request-model-D07WSRKx.js} +1 -1
  61. package/bundle/web-dist/server/assets/{routes-B6be8sJP.js → routes-C1tDj0QN.js} +3 -3
  62. package/bundle/web-dist/server/assets/{services.generated-D0995hJr.js → services.generated-rlOX8J2n.js} +201 -0
  63. package/bundle/web-dist/server/assets/{settings-DAle7AgI.js → settings-DJQUI8bU.js} +3 -3
  64. package/bundle/web-dist/server/assets/{show-BTSdMDoM.js → show-BElTj6MG.js} +3 -3
  65. package/bundle/web-dist/server/assets/{tokens-Bc9flfLz.js → tokens-CRpUPv-5.js} +4 -4
  66. package/bundle/web-dist/server/assets/{use-oauth-login-flow-C7c0gCjf.js → use-oauth-login-flow-DLRPNhNE.js} +1 -1
  67. package/bundle/web-dist/server/assets/{use-update-token-mutation-DLJDGdxu.js → use-update-token-mutation-DJkct-j8.js} +1 -1
  68. package/bundle/web-dist/server/assets/{voice-CEQT57xZ.js → voice-BZBlBBpn.js} +4 -10
  69. package/bundle/web-dist/server/entry-server.generated.js +118 -26
  70. package/package.json +1 -1
  71. package/skills/qgrid/references/anthropic-claude-code-runtime.md +4 -3
  72. package/skills/qgrid/references/openai-codex-runtime.md +29 -10
  73. package/skills/qgrid/references/sonamu-api-web-flow.md +1 -1
  74. package/bundle/web-dist/client/assets/index-CiSsWsVT.js +0 -104
  75. package/bundle/web-dist/client/assets/logs-Bir9gDzp.js +0 -1
  76. package/bundle/web-dist/client/assets/tokens-BuK8BpAd.js +0 -1
  77. package/bundle/web-dist/client/assets/use-update-token-mutation-BKufO9oe.js +0 -1
@@ -24,6 +24,8 @@ export const QGRID_MODEL_GROUPS: { label: string; models: string[] }[] = [
24
24
  {
25
25
  label: "OpenAI",
26
26
  models: [
27
+ "openai/gpt-6.2-astra",
28
+ "openai/gpt-6.2-sol",
27
29
  "openai/gpt-6-astra",
28
30
  "openai/gpt-6.1-sol",
29
31
  "openai/gpt-6.1-terra",
@@ -37,6 +39,7 @@ export const QGRID_MODEL_GROUPS: { label: string; models: string[] }[] = [
37
39
  {
38
40
  label: "Anthropic",
39
41
  models: [
42
+ "anthropic/claude-fable-5-2",
40
43
  "anthropic/claude-fable-5-1",
41
44
  "anthropic/claude-fable-5",
42
45
  "anthropic/claude-opus-5-5",
@@ -593,6 +596,72 @@ export const TranscribeInput = z.object({
593
596
 
594
597
  export type TranscribeInput = z.infer<typeof TranscribeInput>;
595
598
 
599
+ // ─── Streaming transcription (WebSocket /api/qgrid/transcribeStream) ───
600
+
601
+ /** One second of 24 kHz PCM16 is 48,000 bytes, 64,000 base64 characters; frames are capped there. */
602
+ const STREAM_AUDIO_MAX_BASE64 = 64_000;
603
+
604
+ export const TranscribeStreamStart = z.object({
605
+ // openai/ only: the realtime transcription socket. Default openai/gpt-live-transcribe, the one
606
+ // model that streams text while audio is still arriving.
607
+ model: z
608
+ .string()
609
+ .regex(/^openai\/[A-Za-z0-9._-]+$/, "model must be openai/<id>")
610
+ .optional(),
611
+ language: z.string().min(1).max(16).optional(),
612
+ prompt: z.string().min(1).max(2_000).optional(),
613
+ // Mono PCM16 at this rate; 16 kHz is resampled to the upstream 24 kHz.
614
+ sampleRate: z.union([z.literal(16_000), z.literal(24_000)]),
615
+ ...MediaCallOptions,
616
+ });
617
+
618
+ export type TranscribeStreamStart = z.infer<typeof TranscribeStreamStart>;
619
+
620
+ export const TranscribeStreamInEvents = z.object({
621
+ // First message; audio before it is rejected.
622
+ start: TranscribeStreamStart,
623
+ // Base64 mono PCM16 at start.sampleRate, about 100 ms per frame, at most one second.
624
+ audio: z.object({
625
+ pcm: z
626
+ .string()
627
+ .min(1)
628
+ .max(STREAM_AUDIO_MAX_BASE64)
629
+ .refine((value) => value.length % 4 === 0 && BASE64.test(value), "pcm must be base64"),
630
+ }),
631
+ // Ends the current segment now; the server also ends segments at pauses and every 20 s.
632
+ commit: z.object({}),
633
+ // Finishes the stream: the last segment is committed and its transcript awaited before done.
634
+ stop: z.object({}),
635
+ });
636
+
637
+ export type TranscribeStreamInEvents = z.infer<typeof TranscribeStreamInEvents>;
638
+
639
+ export const TranscribeStreamOutEvents = z.object({
640
+ ready: z.object({
641
+ model: z.string(),
642
+ tokenName: z.string(),
643
+ requestLogId: z.number().optional(),
644
+ }),
645
+ // Text appended to a segment that is still being spoken.
646
+ delta: z.object({ segmentId: z.string(), text: z.string() }),
647
+ // A finished segment; times are milliseconds of audio received in this stream.
648
+ segment: z.object({
649
+ segmentId: z.string(),
650
+ text: z.string(),
651
+ startMs: z.number(),
652
+ endMs: z.number(),
653
+ }),
654
+ // fatal: the stream is over and the socket closes.
655
+ error: z.object({ message: z.string(), fatal: z.boolean() }),
656
+ done: z.object({
657
+ audioMs: z.number(),
658
+ segments: z.number(),
659
+ requestLogId: z.number().optional(),
660
+ }),
661
+ });
662
+
663
+ export type TranscribeStreamOutEvents = z.infer<typeof TranscribeStreamOutEvents>;
664
+
596
665
  const TranscribedWord = z.object({
597
666
  text: z.string(),
598
667
  start: z.number(),
@@ -962,6 +1031,71 @@ export const HealthResponse = z.object({
962
1031
 
963
1032
  export type HealthResponse = z.infer<typeof HealthResponse>;
964
1033
 
1034
+ // ─── Model catalog (GET /api/qgrid/models) ───
1035
+
1036
+ // USD per 1M tokens, from the same table that prices request logs.
1037
+ export const CatalogTokenPricing = z.object({
1038
+ input: z.number(),
1039
+ output: z.number(),
1040
+ cachedInput: z.number(),
1041
+ // Cache write without a TTL breakdown, then Anthropic's 5-minute and 1-hour rates.
1042
+ cacheWrite: z.number().optional(),
1043
+ cacheWrite5m: z.number().optional(),
1044
+ cacheWrite1h: z.number().optional(),
1045
+ // Over `threshold` input tokens the whole request is billed at these multipliers.
1046
+ longContext: z
1047
+ .object({
1048
+ threshold: z.number(),
1049
+ inputMultiplier: z.number(),
1050
+ cachedInputMultiplier: z.number(),
1051
+ outputMultiplier: z.number(),
1052
+ })
1053
+ .optional(),
1054
+ // Multiplier on every rate with serviceTier "fast".
1055
+ fastMultiplier: z.number().optional(),
1056
+ });
1057
+
1058
+ export type CatalogTokenPricing = z.infer<typeof CatalogTokenPricing>;
1059
+
1060
+ export const CatalogTextModel = z.object({
1061
+ id: z.string(),
1062
+ provider: z.string(),
1063
+ // The provider has started and has at least one active token.
1064
+ available: z.boolean(),
1065
+ pricing: CatalogTokenPricing,
1066
+ // Reasoning effort values the model accepts, lowest first.
1067
+ efforts: z.array(z.string()),
1068
+ // Whether user-message images reach the model (anthropic/ drops them).
1069
+ imageInput: z.boolean(),
1070
+ });
1071
+
1072
+ export type CatalogTextModel = z.infer<typeof CatalogTextModel>;
1073
+
1074
+ export const CatalogSpeechModel = z.object({
1075
+ id: z.string(),
1076
+ provider: z.string(),
1077
+ available: z.boolean(),
1078
+ // USD per minute of audio; absent when the model is not in the pricing table.
1079
+ usdPerMinute: z.number().optional(),
1080
+ // Whether a transcription prompt (glossary) is accepted.
1081
+ prompt: z.boolean(),
1082
+ // Whether text streams while audio is still arriving (before the segment is committed).
1083
+ liveDraft: z.boolean(),
1084
+ });
1085
+
1086
+ export type CatalogSpeechModel = z.infer<typeof CatalogSpeechModel>;
1087
+
1088
+ export const ModelCatalog = z.object({
1089
+ // query / AI SDK language models.
1090
+ text: z.array(CatalogTextModel),
1091
+ // transcribe / qgrid.transcription().
1092
+ transcription: z.array(CatalogSpeechModel),
1093
+ // WebSocket transcribeStream.
1094
+ transcriptionStream: z.array(CatalogSpeechModel),
1095
+ });
1096
+
1097
+ export type ModelCatalog = z.infer<typeof ModelCatalog>;
1098
+
965
1099
  // ─── Decisions (OpenAI native /v1/decisions wire format) ───
966
1100
  // Limits follow https://developers.openai.com/api/reference/resources/decisions/methods/create (2026-11-13).
967
1101
 
@@ -0,0 +1,165 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+ import {
3
+ type OpenAITranscriptionStream,
4
+ type OpenAITranscriptionStreamEvent,
5
+ } from "../../utils/providers/openai/openai-voice-client";
6
+ import { CommitPolicy, type StreamOutEvent, TranscribeStreamSession } from "./transcribe-stream";
7
+
8
+ const RATE = 24_000;
9
+ const frame = (amp: number, ms = 100, rate = RATE) =>
10
+ new Int16Array(Math.round((rate * ms) / 1000)).fill(Math.round(amp * 32767));
11
+
12
+ describe("CommitPolicy", () => {
13
+ it("commits after a pause that follows enough speech", () => {
14
+ const p = new CommitPolicy();
15
+ const out: string[] = [];
16
+ for (let i = 0; i < 20; i++) out.push(p.push(frame(0.2))); // 2 s speech
17
+ for (let i = 0; i < 6; i++) out.push(p.push(frame(0))); // 0.6 s pause
18
+ expect(out.slice(0, -1).every((d) => d === "none")).toBe(true);
19
+ expect(out.at(-1)).toBe("commit");
20
+ });
21
+
22
+ it("does not end a segment on a pause before minimum speech", () => {
23
+ const p = new CommitPolicy();
24
+ for (let i = 0; i < 5; i++) p.push(frame(0.2)); // 0.5 s speech
25
+ const out = Array.from({ length: 10 }, () => p.push(frame(0)));
26
+ expect(out).not.toContain("commit");
27
+ });
28
+
29
+ it("forces a commit at the length cap during continuous speech", () => {
30
+ const p = new CommitPolicy();
31
+ const out = Array.from({ length: 200 }, () => p.push(frame(0.2)));
32
+ expect(out.indexOf("commit")).toBe(199); // the 20th second
33
+ });
34
+
35
+ it("clears a buffer that holds only quiet", () => {
36
+ const p = new CommitPolicy();
37
+ const out = Array.from({ length: 10 }, () => p.push(frame(0)));
38
+ expect(out.indexOf("clear")).toBe(9);
39
+ });
40
+
41
+ it("commits a short speech tail at a long pause instead of waiting for the cap", () => {
42
+ const p = new CommitPolicy();
43
+ for (let i = 0; i < 8; i++) p.push(frame(0.2)); // 0.8 s, under the minimum
44
+ const out = Array.from({ length: 20 }, () => p.push(frame(0)));
45
+ expect(out.indexOf("commit")).toBe(19); // 2 s of quiet
46
+ });
47
+ });
48
+
49
+ function fakeUpstream() {
50
+ const calls: string[] = [];
51
+ let onEvent: (e: OpenAITranscriptionStreamEvent) => void = () => {};
52
+ const opens = vi.fn(async (handler: (e: OpenAITranscriptionStreamEvent) => void) => {
53
+ onEvent = handler;
54
+ const stream: OpenAITranscriptionStream = {
55
+ model: "gpt-live-transcribe",
56
+ append: async () => void calls.push("append"),
57
+ commit: async () => void calls.push("commit"),
58
+ clear: async () => void calls.push("clear"),
59
+ close: () => void calls.push("close"),
60
+ };
61
+ return stream;
62
+ });
63
+ return { opens, calls, send: (e: OpenAITranscriptionStreamEvent) => onEvent(e) };
64
+ }
65
+
66
+ async function speak(session: TranscribeStreamSession, speechMs: number, pauseMs: number, rate = RATE) {
67
+ for (let i = 0; i < speechMs / 100; i++) await session.audio(frame(0.2, 100, rate), rate);
68
+ for (let i = 0; i < pauseMs / 100; i++) await session.audio(frame(0, 100, rate), rate);
69
+ }
70
+
71
+ describe("TranscribeStreamSession", () => {
72
+ it("maps upstream items to segments with session-relative times", async () => {
73
+ const up = fakeUpstream();
74
+ const out: StreamOutEvent[] = [];
75
+ const session = new TranscribeStreamSession(up.opens, (e) => out.push(e));
76
+ await session.start();
77
+
78
+ // 16 kHz input is resampled; times stay in audio milliseconds.
79
+ // A live model streams deltas before the commit; the commit ack confirms the item.
80
+ await speak(session, 1000, 0, 16_000);
81
+ up.send({ type: "delta", itemId: "a", text: "안녕" });
82
+ await speak(session, 1000, 600, 16_000);
83
+ up.send({ type: "committed", itemId: "a" });
84
+ up.send({ type: "completed", itemId: "a", text: "안녕하세요." });
85
+ // gpt-transcribe sends its deltas only after the ack, while the next segment is open.
86
+ await speak(session, 2000, 600, 16_000);
87
+ await speak(session, 500, 0, 16_000);
88
+ up.send({ type: "committed", itemId: "b" });
89
+ up.send({ type: "delta", itemId: "b", text: "다음" });
90
+ up.send({ type: "completed", itemId: "b", text: "다음 안건입니다." });
91
+
92
+ expect(up.calls.filter((c) => c === "commit")).toHaveLength(2);
93
+ expect(out).toEqual([
94
+ { event: "delta", data: { segmentId: "s0", text: "안녕" } },
95
+ { event: "segment", data: { segmentId: "s0", text: "안녕하세요.", startMs: 0, endMs: 2600 } },
96
+ { event: "delta", data: { segmentId: "s1", text: "다음" } },
97
+ { event: "segment", data: { segmentId: "s1", text: "다음 안건입니다.", startMs: 2600, endMs: 5200 } },
98
+ ]);
99
+ expect(session.segments.map((s) => s.text)).toEqual(["안녕하세요.", "다음 안건입니다."]);
100
+ });
101
+
102
+ it("clears quiet-only audio instead of committing it", async () => {
103
+ const up = fakeUpstream();
104
+ const session = new TranscribeStreamSession(up.opens, () => {});
105
+ await session.start();
106
+ await speak(session, 0, 5000);
107
+ expect(up.calls).toContain("clear");
108
+ expect(up.calls).not.toContain("commit");
109
+ });
110
+
111
+ it("reopens the upstream when it closes mid-stream and keeps going", async () => {
112
+ const up = fakeUpstream();
113
+ const out: StreamOutEvent[] = [];
114
+ const session = new TranscribeStreamSession(up.opens, (e) => out.push(e));
115
+ await session.start();
116
+ up.send({ type: "closed", error: new Error("session limit") });
117
+ await vi.waitFor(() => expect(up.opens).toHaveBeenCalledTimes(2));
118
+ expect(out[0]).toEqual({
119
+ event: "error",
120
+ data: { message: "upstream session ended: session limit; reconnecting", fatal: false },
121
+ });
122
+
123
+ await speak(session, 2000, 600);
124
+ up.send({ type: "committed", itemId: "c" });
125
+ up.send({ type: "completed", itemId: "c", text: "다시 연결됐습니다." });
126
+ expect(out.at(-1)).toMatchObject({ event: "segment", data: { text: "다시 연결됐습니다." } });
127
+ });
128
+
129
+ it("stop commits the tail and waits for its transcript before closing", async () => {
130
+ const up = fakeUpstream();
131
+ const out: StreamOutEvent[] = [];
132
+ const session = new TranscribeStreamSession(up.opens, (e) => out.push(e));
133
+ await session.start();
134
+ await speak(session, 2000, 0); // speech still running when the client stops
135
+
136
+ const stopped = session.stop(5_000);
137
+ await vi.waitFor(() => expect(up.calls).toContain("commit"));
138
+ expect(up.calls).not.toContain("close");
139
+ up.send({ type: "committed", itemId: "d" });
140
+ up.send({ type: "completed", itemId: "d", text: "마지막 문장." });
141
+ await stopped;
142
+
143
+ expect(up.calls.at(-1)).toBe("close");
144
+ expect(out.at(-1)).toMatchObject({ event: "segment", data: { text: "마지막 문장.", endMs: 2000 } });
145
+ });
146
+
147
+ it("drops frames while reconnecting instead of opening a session per frame", async () => {
148
+ const up = fakeUpstream();
149
+ const out: StreamOutEvent[] = [];
150
+ let fail = false;
151
+ const opens = vi.fn(async (handler: (e: OpenAITranscriptionStreamEvent) => void) => {
152
+ if (fail) throw new Error("upstream down");
153
+
154
+ return up.opens(handler);
155
+ });
156
+ const session = new TranscribeStreamSession(opens, (e) => out.push(e));
157
+ await session.start();
158
+ fail = true;
159
+ up.send({ type: "closed", error: new Error("dropped") });
160
+ await speak(session, 2000, 0); // 20 frames during the outage
161
+ expect(opens.mock.calls.length).toBeLessThanOrEqual(2);
162
+ expect(up.calls).not.toContain("append");
163
+ expect(session.audioMs).toBe(2000); // the clock keeps counting dropped audio
164
+ });
165
+ });