@alexkroman1/aai-cli 13.3.0 → 14.0.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.
- package/dist/{_agent-Clbq3a4h.mjs → _agent-BzUeqOdj.mjs} +32 -9
- package/dist/_agent.d.ts +23 -0
- package/dist/{_bundler-DEkjO1d8.mjs → _bundler-DolUCMxu.mjs} +8 -7
- package/dist/_cli-common.d.ts +45 -6
- package/dist/{_config-ZY2euhdh.mjs → _config-DYzC6WMD.mjs} +2 -2
- package/dist/_dev-env.d.ts +1 -1
- package/dist/{_dev-server-C13xuGB1.mjs → _dev-server-CSMqF8PN.mjs} +20 -22
- package/dist/_dev-vite-config.d.ts +3 -3
- package/dist/{_init-Ci4QGjp8.mjs → _init-CQ8idAwo.mjs} +9 -23
- package/dist/{_output-DbJt9gsl.mjs → _output-DBP9Op_d.mjs} +22 -13
- package/dist/_output.d.ts +10 -9
- package/dist/{_preflight-B2laWPdU.mjs → _preflight-CcAR577V.mjs} +2 -2
- package/dist/_resource-commands.d.ts +9 -9
- package/dist/{_server-common-BV4_CrP3.mjs → _server-common-vILJp3it.mjs} +1 -1
- package/dist/{_slug-api-DlKpj91X.mjs → _slug-api-CGvc2YSQ.mjs} +18 -9
- package/dist/_slug-api.d.ts +19 -0
- package/dist/{_studio-DTi3EdXQ.mjs → _studio-DnR_BqFp.mjs} +7 -3
- package/dist/_studio-commands.d.ts +13 -13
- package/dist/{_templates-V4l5sZJy.mjs → _templates-CK4oKoeX.mjs} +3 -3
- package/dist/{_typecheck-gate-sV4N5F93.mjs → _typecheck-gate-U3jcil8L.mjs} +3 -2
- package/dist/_typecheck-gate.d.ts +3 -1
- package/dist/{_utils-Dhd058D9.mjs → _utils-D5JGcjiW.mjs} +43 -1
- package/dist/_utils.d.ts +35 -0
- package/dist/{_workflow-determinism-C9l8uC2R.mjs → _workflow-determinism-CvpqMpdh.mjs} +18 -26
- package/dist/_workflow-determinism.d.ts +3 -3
- package/dist/{build-CWyFGe-W.mjs → build-Mxk8gWvX.mjs} +46 -7
- package/dist/build.d.ts +5 -0
- package/dist/cli.d.ts +1 -2
- package/dist/cli.mjs +117 -135
- package/dist/{client-bundler-CT-_26c5.mjs → client-bundler-BJgREAh6.mjs} +1 -1
- package/dist/client-bundler.mjs +1 -1
- package/dist/{delete-RqlQZ6Y_.mjs → delete-BdFnbnVR.mjs} +4 -4
- package/dist/{deploy-B7f3CK7v.mjs → deploy-uAJ4NukN.mjs} +11 -11
- package/dist/{dev-DamXieW_.mjs → dev-DApPSaE_.mjs} +3 -3
- package/dist/{eval-h3DTVfRw.mjs → eval-BK47A_K5.mjs} +3 -3
- package/dist/{init-D-vFrV8h.mjs → init-DukDxECd.mjs} +11 -19
- package/dist/{login-CDiemNmC.mjs → login-DaLrPOFg.mjs} +4 -6
- package/dist/{logs-DGwPNCzB.mjs → logs-7BRwq0cG.mjs} +21 -14
- package/dist/project-config.mjs +1 -1
- package/dist/scaffold/CLAUDE.md +84 -56
- package/dist/scaffold/package.json +4 -4
- package/dist/scaffold/server.mjs +129 -25
- package/dist/{secret-V1w7y9-j.mjs → secret-Cjp912yF.mjs} +5 -5
- package/dist/secret.d.ts +8 -6
- package/dist/{studio-BpMCfUNx.mjs → studio-CpHlNHUZ.mjs} +13 -15
- package/dist/templates/call-audit/agent.test.ts +11 -6
- package/dist/templates/call-audit/agent.ts +2 -2
- package/dist/templates/call-audit/client.tsx +27 -42
- package/dist/templates/call-audit/workflows/audit.ts +7 -5
- package/dist/templates/call-audit/workflows/ingest.ts +7 -7
- package/dist/templates/call-audit/workflows/media.ts +12 -37
- package/dist/templates/call-audit/workflows/summarize.ts +8 -8
- package/dist/templates/call-audit/workflows/sync-api.ts +3 -3
- package/dist/templates/dispatch-center/agent.test.ts +7 -7
- package/dist/templates/dispatch-center/client.tsx +53 -61
- package/dist/templates/dispatch-center/shared.ts +0 -8
- package/dist/templates/dispatch-center/tools/ops_dashboard.ts +4 -1
- package/dist/templates/embedded-assets/agent.eval.test.ts +4 -2
- package/dist/templates/health-assistant/agent.eval.test.ts +4 -2
- package/dist/templates/infocom-adventure/client.tsx +40 -36
- package/dist/templates/link-digest/agent.test.ts +3 -3
- package/dist/templates/link-digest/agent.ts +2 -2
- package/dist/templates/link-digest/client.tsx +27 -17
- package/dist/templates/link-digest/workflows/digest.ts +13 -16
- package/dist/templates/night-owl/agent.eval.test.ts +4 -2
- package/dist/templates/night-owl/client.tsx +8 -2
- package/dist/templates/pipeline-simple/agent.test.ts +2 -2
- package/dist/templates/pizza-ordering/client.tsx +5 -4
- package/dist/templates/pizza-ordering/shared.ts +3 -8
- package/dist/templates/pizza-ordering/tools/add_pizza.ts +3 -2
- package/dist/templates/pizza-ordering/tools/place_order.ts +3 -2
- package/dist/templates/pizza-ordering/tools/remove_pizza.ts +3 -2
- package/dist/templates/pizza-ordering/tools/update_pizza.ts +3 -2
- package/dist/templates/pizza-ordering/tools/view_order.ts +3 -2
- package/dist/templates/plan-and-execute/agent.test.ts +10 -5
- package/dist/templates/plan-and-execute/client.tsx +2 -2
- package/dist/templates/podcast-digest/agent.test.ts +20 -11
- package/dist/templates/podcast-digest/client.tsx +16 -22
- package/dist/templates/podcast-digest/workflows/digest.ts +21 -19
- package/dist/templates/podcast-digest/workflows/feeds.ts +61 -33
- package/dist/templates/podcast-digest/workflows/slack.ts +7 -7
- package/dist/templates/recap-workflow/agent.eval.test.ts +21 -13
- package/dist/templates/recap-workflow/agent.test.ts +27 -23
- package/dist/templates/recap-workflow/workflows/recap.ts +24 -28
- package/dist/templates/redline/agent.eval.test.ts +5 -8
- package/dist/templates/redline/agent.test.ts +1 -1
- package/dist/templates/redline/client.tsx +36 -34
- package/dist/templates/redline/workflows/redline.ts +17 -17
- package/dist/templates/research-workflow/agent.eval.test.ts +5 -5
- package/dist/templates/research-workflow/agent.test.ts +10 -7
- package/dist/templates/research-workflow/workflows/research.ts +28 -30
- package/dist/templates/retail/agent.test.ts +17 -15
- package/dist/templates/retail/cancel.ts +7 -6
- package/dist/templates/retail/client.tsx +39 -58
- package/dist/templates/retail/payment.ts +4 -3
- package/dist/templates/retail/pending.test.ts +19 -19
- package/dist/templates/retail/store.test.ts +5 -5
- package/dist/templates/retail/swap.ts +8 -11
- package/dist/templates/solo-rpg/agent.eval.test.ts +2 -16
- package/dist/templates/solo-rpg/agent.test.ts +12 -12
- package/dist/templates/solo-rpg/client.tsx +3 -3
- package/dist/templates/spoken-summary/agent.test.ts +9 -9
- package/dist/templates/spoken-summary/agent.ts +3 -3
- package/dist/templates/spoken-summary/client.tsx +23 -30
- package/dist/templates/spoken-summary/workflows/summarize.ts +11 -11
- package/dist/templates/spoken-summary/workflows/transcribe.ts +14 -14
- package/dist/templates/support-line/client.tsx +4 -3
- package/dist/templates/support-line/prompts.ts +0 -2
- package/dist/templates/transcription-workflow/agent.test.ts +20 -12
- package/dist/templates/transcription-workflow/agent.ts +2 -2
- package/dist/templates/transcription-workflow/client.tsx +15 -14
- package/dist/templates/transcription-workflow/recover.ts +1 -1
- package/dist/templates/transcription-workflow/run-panel.tsx +34 -14
- package/dist/templates/transcription-workflow/total-latency.tsx +46 -20
- package/dist/templates/transcription-workflow/workflows/batch.ts +15 -15
- package/dist/templates/transcription-workflow/workflows/downsample.ts +1 -1
- package/dist/templates/transcription-workflow/workflows/normalize.ts +15 -19
- package/dist/templates/transcription-workflow/workflows/stream.ts +12 -12
- package/dist/templates/transcription-workflow/workflows/sync-api.ts +3 -3
- package/dist/templates/transcription-workflow/workflows/transcribe.ts +23 -34
- package/dist/templates/travel-concierge/agent.eval.test.ts +2 -2
- package/dist/templates/travel-concierge/agent.test.ts +15 -7
- package/dist/templates/travel-concierge/client.tsx +2 -2
- package/dist/templates/travel-concierge/shared.ts +10 -14
- package/dist/templates/travel-concierge/tools/lookup_booking.ts +4 -3
- package/dist/templates/travel-concierge/tools/search_car_rentals.ts +3 -2
- package/dist/templates/travel-concierge/tools/search_excursions.ts +3 -2
- package/dist/templates/travel-concierge/tools/search_flights.ts +3 -2
- package/dist/templates/travel-concierge/tools/search_hotels.ts +3 -2
- package/dist/{test-guenJUxi.mjs → test-D032V2cA.mjs} +4 -17
- package/dist/typecheck.mjs +1 -1
- package/dist/worker-bundler.mjs +1 -1
- package/dist/{workflow-BZyKLkhV.mjs → workflow-CVioyO3V.mjs} +6 -5
- package/package.json +4 -4
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* - **`stepSpeak`** synthesizes from inside a step. The session TTS surface
|
|
19
19
|
* cannot: a `TtsSession` is an event stream wired into a live pipeline's
|
|
20
20
|
* playback, and a step has no turn to be part of and has to return a VALUE.
|
|
21
|
-
* - **`
|
|
21
|
+
* - **`stepWriteUpload`** puts that value somewhere. A run's OUTPUT is read back as
|
|
22
22
|
* JSON, so audio cannot travel in one — the same rule that keeps a
|
|
23
23
|
* recording's bytes out of a run's INPUT, arriving at the other end of the
|
|
24
24
|
* run. The bytes go to the store, the output carries the id, and the page
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
* expensive one.
|
|
50
50
|
*/
|
|
51
51
|
|
|
52
|
-
import type {
|
|
53
|
-
import {
|
|
54
|
-
import {
|
|
52
|
+
import type { WorkflowContext } from "@alexkroman1/aai";
|
|
53
|
+
import { stepReport, stepSpeak, stepWriteUpload, TRANSCRIBE_API } from "@alexkroman1/aai/step";
|
|
54
|
+
import { stepGenerateJsonOrFail } from "@alexkroman1/aai/step-errors";
|
|
55
55
|
import { countWords, omitUndefined } from "@alexkroman1/aai/utils";
|
|
56
56
|
// ERASED at build time, so the body can name the schema's own output type without
|
|
57
57
|
// a runtime cycle back through `agent.ts` — the same mechanism `client.tsx` uses
|
|
@@ -128,7 +128,7 @@ export type SpokenSummary = {
|
|
|
128
128
|
/** Transcribe a recording, summarize it, and read the summary back. */
|
|
129
129
|
export async function spokenSummaryFlow(
|
|
130
130
|
input: WorkflowInputOf<typeof spokenSummary>,
|
|
131
|
-
ctx:
|
|
131
|
+
ctx: WorkflowContext,
|
|
132
132
|
): Promise<SpokenSummary> {
|
|
133
133
|
const transcript = await transcribe(input.recording, ctx);
|
|
134
134
|
const summary = await ctx.step("summarize", () => summarize(transcript.text));
|
|
@@ -157,7 +157,7 @@ export async function spokenSummaryFlow(
|
|
|
157
157
|
* re-derives exactly the same sequence. It takes the `ctx` for that reason: a
|
|
158
158
|
* helper that reaches the journal has to be handed the handle.
|
|
159
159
|
*/
|
|
160
|
-
async function transcribe(recording: string, ctx:
|
|
160
|
+
async function transcribe(recording: string, ctx: WorkflowContext): Promise<Transcript> {
|
|
161
161
|
// `maxAttempts: 6` was `uploadToProvider.maxRetries = 5` — five retries after
|
|
162
162
|
// the first attempt. It is the one step here worth extra patience: it streams
|
|
163
163
|
// the whole recording, so a transient failure is expensive to reach again.
|
|
@@ -187,8 +187,8 @@ async function transcribe(recording: string, ctx: WorkflowCtx): Promise<Transcri
|
|
|
187
187
|
export async function summarize(
|
|
188
188
|
text: string,
|
|
189
189
|
): Promise<{ headline: string; points: string[]; spoken: string }> {
|
|
190
|
-
await
|
|
191
|
-
const reply = await
|
|
190
|
+
await stepReport("Summarizing the transcript.");
|
|
191
|
+
const reply = await stepGenerateJsonOrFail(
|
|
192
192
|
"Summarize this transcript of a recording.\n\n" +
|
|
193
193
|
"Answer with JSON only, in this shape:\n" +
|
|
194
194
|
`{"headline": "...", "points": ["..."], "spoken": "..."}\n\n` +
|
|
@@ -204,7 +204,7 @@ export async function summarize(
|
|
|
204
204
|
system: "You summarize recordings. You answer with JSON and nothing else.",
|
|
205
205
|
schema: SummaryReply,
|
|
206
206
|
},
|
|
207
|
-
// The `
|
|
207
|
+
// The `OrFail` caller is `stepGenerateJson` plus `throwStepError`, which
|
|
208
208
|
// reads the gateway's own status: a 429 is worth another attempt and a 400
|
|
209
209
|
// is not, and that is what tells the DevKit which.
|
|
210
210
|
);
|
|
@@ -226,7 +226,7 @@ export async function speak(
|
|
|
226
226
|
voice?: string,
|
|
227
227
|
): Promise<{ audio: string; durationMs: number }> {
|
|
228
228
|
const spoken = await stepSpeak(script, omitUndefined({ voice }));
|
|
229
|
-
const stored = await
|
|
229
|
+
const stored = await stepWriteUpload(spoken.audio, {
|
|
230
230
|
// Named, because this is what a person sees on the download link rather
|
|
231
231
|
// than an opaque id — and typed, because the byte route serves the type it
|
|
232
232
|
// was given and a browser will not play a file it was handed as bytes.
|
|
@@ -234,7 +234,7 @@ export async function speak(
|
|
|
234
234
|
type: "audio/wav",
|
|
235
235
|
});
|
|
236
236
|
|
|
237
|
-
await
|
|
237
|
+
await stepReport(
|
|
238
238
|
`Recorded a ${Math.round(spoken.durationMs / 1000)}s summary in ${spoken.voice}'s voice.`,
|
|
239
239
|
);
|
|
240
240
|
return { audio: stored.id, durationMs: spoken.durationMs };
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*
|
|
13
13
|
* **Every one of them is four lines, because the SDK owns the endpoint.**
|
|
14
14
|
* `stepTranscribeUpload` / `stepTranscribeSubmit` / `stepTranscribePoll` on
|
|
15
|
-
* `@alexkroman1/aai/step` — reached here through their `*
|
|
15
|
+
* `@alexkroman1/aai/step` — reached here through their `*OrFail` callers on
|
|
16
16
|
* `@alexkroman1/aai/step-errors` — carry the URL, the raw-key auth, the windowed
|
|
17
17
|
* streaming upload, the PLURAL `speech_models` field and the failure
|
|
18
18
|
* classification — all of which this file used to spell out, and all of which
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
* the one leg that should be as boring as possible.
|
|
41
41
|
*/
|
|
42
42
|
|
|
43
|
-
import {
|
|
43
|
+
import { stepReport, stepUploadInfo } from "@alexkroman1/aai/step";
|
|
44
44
|
import {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
stepTranscribePollOrFail,
|
|
46
|
+
stepTranscribeSubmitOrFail,
|
|
47
|
+
stepTranscribeUploadOrFail,
|
|
48
48
|
} from "@alexkroman1/aai/step-errors";
|
|
49
49
|
import { countWords, formatBytes } from "@alexkroman1/aai/utils";
|
|
50
50
|
|
|
@@ -85,24 +85,24 @@ export type Transcript = {
|
|
|
85
85
|
* expires before the next step runs; that costs one fresh upload, once, instead
|
|
86
86
|
* of five.
|
|
87
87
|
*
|
|
88
|
-
* The `
|
|
88
|
+
* The `OrFail` callers on `@alexkroman1/aai/step-errors` are the SDK's own
|
|
89
89
|
* `stepTranscribe*` plus `throwStepError` and nothing else, which is what turns
|
|
90
90
|
* the SDK's `TranscribeError` into the DevKit's verdict — a missing key and a
|
|
91
91
|
* 400 stop, a 429 waits as long as the service asked. Every step here ends the
|
|
92
92
|
* same way for the same reason.
|
|
93
93
|
*/
|
|
94
94
|
export async function uploadToProvider(uploadId: string): Promise<{ audioUrl: string }> {
|
|
95
|
-
const stored = await
|
|
96
|
-
await
|
|
95
|
+
const stored = await stepUploadInfo(uploadId);
|
|
96
|
+
await stepReport(
|
|
97
97
|
`Uploading ${stored.name || uploadId} (${formatBytes(stored.size)}) for transcription.`,
|
|
98
98
|
);
|
|
99
|
-
return await
|
|
99
|
+
return await stepTranscribeUploadOrFail(uploadId);
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
/** Create the transcription job, and answer with the id that outlives this run. */
|
|
103
103
|
export async function createJob(audioUrl: string): Promise<{ id: string }> {
|
|
104
|
-
const job = await
|
|
105
|
-
await
|
|
104
|
+
const job = await stepTranscribeSubmitOrFail(audioUrl);
|
|
105
|
+
await stepReport(`Transcribing — job ${job.id}.`);
|
|
106
106
|
return job;
|
|
107
107
|
}
|
|
108
108
|
|
|
@@ -119,11 +119,11 @@ export async function pollTranscript(
|
|
|
119
119
|
uploadId: string,
|
|
120
120
|
id: string,
|
|
121
121
|
): Promise<{ done: false } | { done: true; transcript: Transcript }> {
|
|
122
|
-
const progress = await
|
|
122
|
+
const progress = await stepTranscribePollOrFail(id);
|
|
123
123
|
if (!progress.done) return { done: false };
|
|
124
124
|
|
|
125
|
-
const stored = await
|
|
126
|
-
await
|
|
125
|
+
const stored = await stepUploadInfo(uploadId);
|
|
126
|
+
await stepReport(`Transcribed ${countWords(progress.transcript.text)} words.`);
|
|
127
127
|
return {
|
|
128
128
|
done: true,
|
|
129
129
|
transcript: {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { plural } from "@alexkroman1/aai/utils";
|
|
1
2
|
import "@alexkroman1/aai-ui/styles.css";
|
|
2
|
-
import { AutoScroll,
|
|
3
|
+
import { AutoScroll, mountClient, useAgentState } from "@alexkroman1/aai-ui";
|
|
3
4
|
import { PRODUCT, supportProjection } from "./shared.ts";
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -19,7 +20,7 @@ function TraceSidebar() {
|
|
|
19
20
|
<div>
|
|
20
21
|
<h3 className="text-sm font-bold uppercase tracking-wide opacity-60">{support.product}</h3>
|
|
21
22
|
<p className="text-xs opacity-50">
|
|
22
|
-
{support.asked.length}
|
|
23
|
+
{support.asked.length} {plural(support.asked.length, "question")} this call
|
|
23
24
|
{support.ticket ? ` · ticket ${support.ticket}` : ""}
|
|
24
25
|
</p>
|
|
25
26
|
</div>
|
|
@@ -97,7 +98,7 @@ function TraceSidebar() {
|
|
|
97
98
|
);
|
|
98
99
|
}
|
|
99
100
|
|
|
100
|
-
|
|
101
|
+
mountClient({
|
|
101
102
|
// Derived, not typed twice: `PRODUCT` comes off `knowledge.json`, which is
|
|
102
103
|
// what `agent.ts` names the agent and greets with. A knowledge base swapped
|
|
103
104
|
// for another product otherwise leaves the browser tab advertising the old
|
|
@@ -40,8 +40,6 @@ export const binaryScore = z.object({
|
|
|
40
40
|
reason: z.string().max(200).describe("One short sentence of justification"),
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
export type BinaryScore = z.infer<typeof binaryScore>;
|
|
44
|
-
|
|
45
43
|
/** Their `retrieval_grader`: deliberately NOT a stringent test. */
|
|
46
44
|
export const DOC_GRADER_SYSTEM = [
|
|
47
45
|
"You are a grader assessing whether a retrieved support document is relevant",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
|
|
21
21
|
import { readdir } from "node:fs/promises";
|
|
22
22
|
import { tmpdir } from "node:os";
|
|
23
|
-
import {
|
|
23
|
+
import { stepReadUpload, type UploadRange } from "@alexkroman1/aai/step";
|
|
24
24
|
import { FatalError, RetryableError } from "@alexkroman1/aai/step-errors";
|
|
25
|
-
import {
|
|
25
|
+
import { createWorkflowContext } from "@alexkroman1/aai/testing";
|
|
26
26
|
import {
|
|
27
27
|
installStubReporter,
|
|
28
28
|
installStubStepFetch,
|
|
@@ -41,6 +41,7 @@ import {
|
|
|
41
41
|
requestFormat,
|
|
42
42
|
} from "./workflows/downsample.ts";
|
|
43
43
|
import { cuttable, heavierThanNormalized, normalizeRecording } from "./workflows/normalize.ts";
|
|
44
|
+
import { stitchChunks, stitchTranscript, TRANSCRIPT_STREAM } from "./workflows/stitch.ts";
|
|
44
45
|
import {
|
|
45
46
|
expectedSegments,
|
|
46
47
|
nextPollDelay,
|
|
@@ -54,9 +55,6 @@ import {
|
|
|
54
55
|
import {
|
|
55
56
|
mergeTranscript,
|
|
56
57
|
splitRecording,
|
|
57
|
-
stitchChunks,
|
|
58
|
-
stitchTranscript,
|
|
59
|
-
TRANSCRIPT_STREAM,
|
|
60
58
|
type Transcript,
|
|
61
59
|
transcribeFlow,
|
|
62
60
|
transcribeSegment,
|
|
@@ -88,9 +86,9 @@ const UPLOAD_ID = "upl_test";
|
|
|
88
86
|
const STARTED_AT = 1_000_000;
|
|
89
87
|
|
|
90
88
|
/**
|
|
91
|
-
* Publish one in-memory upload, the way `
|
|
89
|
+
* Publish one in-memory upload, the way `createRuntimeServer` publishes a real store.
|
|
92
90
|
*
|
|
93
|
-
* This is the seam that makes a step testable at all: `
|
|
91
|
+
* This is the seam that makes a step testable at all: `stepReadUpload` reads a
|
|
94
92
|
* process-wide slot rather than dialling anything, so a spec supplies its own
|
|
95
93
|
* bytes with no server, no database and no HTTP.
|
|
96
94
|
*/
|
|
@@ -898,7 +896,7 @@ describe("transcribeSegment", () => {
|
|
|
898
896
|
// What makes the run's answer streamable rather than only its narration: the
|
|
899
897
|
// page stitches whatever has arrived, so the transcript renders growing
|
|
900
898
|
// instead of appearing when the last segment does. The reporter is the SDK's
|
|
901
|
-
// published slot, which is the same seam `
|
|
899
|
+
// published slot, which is the same seam `stepReport()` goes through.
|
|
902
900
|
const reported = installStubReporter();
|
|
903
901
|
stubProvider();
|
|
904
902
|
|
|
@@ -964,7 +962,7 @@ describe("transcribeSegment", () => {
|
|
|
964
962
|
// `transcribeStreamFlow`'s own `transcribeSegment` call carries the same
|
|
965
963
|
// budget and is asserted with that flow, not here — this drives only
|
|
966
964
|
// `transcribeFlow`.
|
|
967
|
-
const ctx =
|
|
965
|
+
const ctx = createWorkflowContext({
|
|
968
966
|
runSteps: false,
|
|
969
967
|
results: {
|
|
970
968
|
normalizeRecording: { recording: UPLOAD_ID, converted: false },
|
|
@@ -1116,7 +1114,7 @@ describe("the streaming flow", () => {
|
|
|
1116
1114
|
|
|
1117
1115
|
test("segmentStored refuses a window that STRADDLES a hole", () => {
|
|
1118
1116
|
// A run is contiguous, so containment in one is the whole test — and it has to
|
|
1119
|
-
// be, because `
|
|
1117
|
+
// be, because `stepReadUpload` clamps to the run a read starts in. A segment
|
|
1120
1118
|
// spanning two runs would come back short and be transcribed as a fragment,
|
|
1121
1119
|
// which is a wrong transcript rather than a failed one.
|
|
1122
1120
|
const at = poll(
|
|
@@ -1191,12 +1189,12 @@ describe("the streaming flow", () => {
|
|
|
1191
1189
|
});
|
|
1192
1190
|
|
|
1193
1191
|
test("a segment reads SHORT rather than failing when its bytes have not landed", async () => {
|
|
1194
|
-
// The property the whole flow rests on, and it predates streaming: `
|
|
1192
|
+
// The property the whole flow rests on, and it predates streaming: `stepReadUpload`
|
|
1195
1193
|
// clamps its window to what is stored. So a body that asks slightly early gets
|
|
1196
1194
|
// what exists — which is why the body checks `end <= size` and can trust the
|
|
1197
1195
|
// clamp for the final segment of a file that came up short.
|
|
1198
1196
|
publishPartial(1000, 320_000);
|
|
1199
|
-
const slice = await
|
|
1197
|
+
const slice = await stepReadUpload(UPLOAD_ID, { start: 44, end: 44 + 320_000 });
|
|
1200
1198
|
expect(slice.bytes.length).toBe(1000);
|
|
1201
1199
|
expect(slice.end).toBe(44 + 1000);
|
|
1202
1200
|
});
|
|
@@ -1356,6 +1354,16 @@ describe("normalizing the recording", () => {
|
|
|
1356
1354
|
* later in `splitRecording` with a message about a header; a `timeout`
|
|
1357
1355
|
* classified as fatal is a run that gives up on work that would have finished.
|
|
1358
1356
|
*/
|
|
1357
|
+
// Point the toolchain at nothing, so this block really is what its doc says:
|
|
1358
|
+
// a unit test that spawns no binary. Without it a developer with ffmpeg
|
|
1359
|
+
// installed runs a different test from CI, which has none — and the one
|
|
1360
|
+
// assertion below that reaches `normalizeRecording` is about a reporter line
|
|
1361
|
+
// emitted BEFORE the spawn. `unstubEnvs` is repo-wide, so there is no teardown.
|
|
1362
|
+
beforeEach(() => {
|
|
1363
|
+
vi.stubEnv("AAI_FFMPEG_PATH", "/nonexistent/ffmpeg");
|
|
1364
|
+
vi.stubEnv("AAI_FFPROBE_PATH", "/nonexistent/ffprobe");
|
|
1365
|
+
});
|
|
1366
|
+
|
|
1359
1367
|
test("a canonical WAV is cuttable, so the desk converts nothing", () => {
|
|
1360
1368
|
expect(cuttable(wavFile(MONO_16K, 32_000), 44 + 32_000)).toBe(true);
|
|
1361
1369
|
});
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
* `POST /workflows/uploads` (the browser does this for you: `uploads` below is
|
|
41
41
|
* what makes `<WorkflowFields>` render a file picker, and `useWorkflowSubmit`
|
|
42
42
|
* stores the file before starting the run), the input carries the returned id,
|
|
43
|
-
* and each step reads exactly the window it needs with `
|
|
43
|
+
* and each step reads exactly the window it needs with `stepReadUpload` — which is
|
|
44
44
|
* what keeps sixty steps from moving the same recording sixty times.
|
|
45
45
|
*
|
|
46
46
|
* None of that is this template's code. Uploads are the SDK's, for the reason
|
|
@@ -118,7 +118,7 @@ export const transcribe = workflow({
|
|
|
118
118
|
}),
|
|
119
119
|
// The one line that makes the form take a file: `<WorkflowFields>` renders a
|
|
120
120
|
// picker for this property, `useWorkflowSubmit` stores the chosen file, and
|
|
121
|
-
// the steps read it back with `
|
|
121
|
+
// the steps read it back with `stepReadUpload`.
|
|
122
122
|
uploads: ["recording"],
|
|
123
123
|
run: transcribeFlow,
|
|
124
124
|
});
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
* rather than a fourth option. A single request moves a file at one connection's
|
|
57
57
|
* throughput, which over any distance is a fraction of the link — so the SDK cuts
|
|
58
58
|
* the file into megabyte-aligned parts and sends four at once. Nothing about the
|
|
59
|
-
* workflow changes: the agent reassembles them, `
|
|
59
|
+
* workflow changes: the agent reassembles them, `stepReadUpload` reads the same
|
|
60
60
|
* windows, and the streaming flow still watches the file grow (what it polls is the
|
|
61
61
|
* CONTIGUOUS prefix, which is honest whether one connection or four are filling
|
|
62
62
|
* it).
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
* - **The page stitches with the RUN's own function.** `stitchChunks` is
|
|
84
84
|
* `workflows/stitch.ts`, imported by both, so the live text and the stored one
|
|
85
85
|
* cannot drift into two different transcripts of one recording.
|
|
86
|
-
* - **It is a SEPARATE stream from the progress log.** `
|
|
86
|
+
* - **It is a SEPARATE stream from the progress log.** `stepReport()`'s lines go to
|
|
87
87
|
* the default one, which `<WorkflowProgress>` renders verbatim; objects in
|
|
88
88
|
* there would come out as `[object Object]` between the sentences.
|
|
89
89
|
* - **The finished run wins.** Once `output` exists the panel renders that
|
|
@@ -193,7 +193,7 @@ import "@alexkroman1/aai-ui/styles.css";
|
|
|
193
193
|
import {
|
|
194
194
|
Form,
|
|
195
195
|
isTerminal,
|
|
196
|
-
|
|
196
|
+
mountPage,
|
|
197
197
|
SubmitButton,
|
|
198
198
|
UploadProgressBar,
|
|
199
199
|
useWorkflowRuns,
|
|
@@ -270,10 +270,6 @@ function TranscriptionDesk() {
|
|
|
270
270
|
// piece of state for all three hooks, because it describes the UPLOAD and every
|
|
271
271
|
// mode has one — see the module doc.
|
|
272
272
|
const [parallel, setParallel] = useState(true);
|
|
273
|
-
// Did THIS load press Transcribe? A reload cannot have, and it is the only way
|
|
274
|
-
// the page can tell "working on what you just sent" from "picking up where you
|
|
275
|
-
// left off" — the hooks report the run, not who asked for it.
|
|
276
|
-
const [startedHere, setStartedHere] = useState(false);
|
|
277
273
|
// ALL THREE hooks are called every render, because a hook may not be conditional —
|
|
278
274
|
// and that costs nothing here: none of them does anything until its `submit` is
|
|
279
275
|
// called, and `useWorkflowRun` underneath them holds no id until then either.
|
|
@@ -292,7 +288,13 @@ function TranscriptionDesk() {
|
|
|
292
288
|
// store — so it is the SAME hook against a different workflow. Only the streaming
|
|
293
289
|
// mode needs the other one, because only it needs the id before the bytes.
|
|
294
290
|
const active = mode === "streaming" ? streamed : mode === "batch" ? batched : stored;
|
|
295
|
-
|
|
291
|
+
// `startedHere` comes off the ACTIVE hook rather than being one flag for the
|
|
292
|
+
// page, and that is a fix rather than a tidy-up: a single piece of page state
|
|
293
|
+
// survived a mode switch, so pressing Transcribe in one mode and then
|
|
294
|
+
// switching made the other mode's panel claim the reader had started its run.
|
|
295
|
+
// Per-hook, switching modes shows the truth about the run being shown.
|
|
296
|
+
const { submitForm, run, upload, pending, error, reset, pauseUpload, resumeUpload, startedHere } =
|
|
297
|
+
active;
|
|
296
298
|
// History is per WORKFLOW, so the list follows the mode: two flows that produce
|
|
297
299
|
// the same output are still two different things to have run, and merging them
|
|
298
300
|
// would put a run under a heading that cannot explain it.
|
|
@@ -349,7 +351,6 @@ function TranscriptionDesk() {
|
|
|
349
351
|
<Form
|
|
350
352
|
onSubmit={(values) => {
|
|
351
353
|
total.start();
|
|
352
|
-
setStartedHere(true);
|
|
353
354
|
// Written at SUBMIT rather than on the radio, so the remembered mode
|
|
354
355
|
// is always the mode a run exists under — which is the only thing the
|
|
355
356
|
// next load can use it for.
|
|
@@ -369,8 +370,8 @@ function TranscriptionDesk() {
|
|
|
369
370
|
</Form>
|
|
370
371
|
|
|
371
372
|
<TotalLatency
|
|
372
|
-
|
|
373
|
-
|
|
373
|
+
startedAt={total.startedAt}
|
|
374
|
+
frozenMs={total.frozenMs}
|
|
374
375
|
runMs={run?.status === "completed" ? run.output.elapsedMs : undefined}
|
|
375
376
|
/>
|
|
376
377
|
|
|
@@ -394,8 +395,8 @@ function TranscriptionDesk() {
|
|
|
394
395
|
onClear={() => {
|
|
395
396
|
// A recovered run is dismissed as deliberately as one this load
|
|
396
397
|
// started: the lookup is a mount-time act, so `reset()` is not
|
|
397
|
-
// undone by a second one and Clear really does clear.
|
|
398
|
-
|
|
398
|
+
// undone by a second one and Clear really does clear. `reset()`
|
|
399
|
+
// also clears `startedHere`, which this page used to mirror here.
|
|
399
400
|
reset();
|
|
400
401
|
total.clear();
|
|
401
402
|
}}
|
|
@@ -500,4 +501,4 @@ function UploadPicker({
|
|
|
500
501
|
);
|
|
501
502
|
}
|
|
502
503
|
|
|
503
|
-
|
|
504
|
+
mountPage({ name: "Transcription Desk", component: TranscriptionDesk });
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* `client.tsx` down to the page's shape:
|
|
15
15
|
*
|
|
16
16
|
* - **A template's spec is what makes its exemplar code true**, and none of this
|
|
17
|
-
* can be tested from a `client.tsx`. That file ends in a `
|
|
17
|
+
* can be tested from a `client.tsx`. That file ends in a `mountPage()` call and
|
|
18
18
|
* imports a stylesheet, and this package's suites have no DOM at all: the
|
|
19
19
|
* vitest `include` matches `.test.ts` and not `.test.tsx`, and the scaffold
|
|
20
20
|
* declares no React testing library — so a `client.test.tsx` would be
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
import { countWords, formatDuration, plural } from "@alexkroman1/aai/utils";
|
|
22
22
|
import type { WorkflowOutputOf } from "@alexkroman1/aai/workflow-api";
|
|
23
23
|
import {
|
|
24
|
+
Facts,
|
|
24
25
|
isTerminal,
|
|
25
26
|
useWorkflowProgress,
|
|
26
27
|
WORKFLOW_STATUS_LABELS,
|
|
@@ -136,7 +137,7 @@ export function RunPanel({ run, onClear }: { run: WorkflowRun<Transcript>; onCle
|
|
|
136
137
|
above, and the reason both exist: the status is `running` for the whole
|
|
137
138
|
fan-out, so a sixty-segment recording and a one-segment recording look
|
|
138
139
|
identical while they run. These lines come from the run itself
|
|
139
|
-
(`
|
|
140
|
+
(`stepReport()` in `workflows/transcribe.ts`), and they REPLAY, so looking a
|
|
140
141
|
finished run up in the panel below shows how it got there. */}
|
|
141
142
|
<WorkflowProgress runId={run.runId} />
|
|
142
143
|
|
|
@@ -150,15 +151,25 @@ export function RunPanel({ run, onClear }: { run: WorkflowRun<Transcript>; onCle
|
|
|
150
151
|
object with optional fields. */}
|
|
151
152
|
{run.status === "completed" && (
|
|
152
153
|
<>
|
|
153
|
-
<
|
|
154
|
-
|
|
155
|
-
{
|
|
156
|
-
|
|
157
|
-
|
|
154
|
+
<Facts
|
|
155
|
+
size="xs"
|
|
156
|
+
items={[
|
|
157
|
+
`${run.output.segments} ${plural(run.output.segments, "segment")}`,
|
|
158
|
+
`${formatDuration(run.output.durationMs)} of audio`,
|
|
159
|
+
`took ${formatDuration(run.output.elapsedMs)}`,
|
|
160
|
+
`${run.output.words} words`,
|
|
161
|
+
]}
|
|
162
|
+
/>
|
|
158
163
|
<pre className="whitespace-pre-wrap text-sm leading-relaxed">{run.output.transcript}</pre>
|
|
159
164
|
</>
|
|
160
165
|
)}
|
|
161
|
-
{
|
|
166
|
+
{/* `role="alert"`, the same contract `<Form>` gives the submit error in
|
|
167
|
+
`client.tsx`: this is the outcome the reader waited minutes for. */}
|
|
168
|
+
{run.status === "failed" && (
|
|
169
|
+
<p role="alert" className="text-red-600">
|
|
170
|
+
{run.error}
|
|
171
|
+
</p>
|
|
172
|
+
)}
|
|
162
173
|
</section>
|
|
163
174
|
);
|
|
164
175
|
}
|
|
@@ -186,17 +197,26 @@ function LiveTranscript({ runId }: { runId: string }) {
|
|
|
186
197
|
// Memoized on the ARRAY, which the hook appends to per read: stitching is a
|
|
187
198
|
// seam search per segment, and a fan-out re-renders this panel on every
|
|
188
199
|
// progress poll whether or not anything arrived.
|
|
189
|
-
|
|
200
|
+
//
|
|
201
|
+
// The word count and the coverage are derived in the SAME memo, not below
|
|
202
|
+
// it: both are functions of `progress` alone, and `countWords` rescans a
|
|
203
|
+
// transcript that reaches ~14k words on a feature-length recording.
|
|
204
|
+
//
|
|
205
|
+
// `covered` is the furthest point reached, not the count: segments land out
|
|
206
|
+
// of order, so "6 segments" says nothing about how much is covered.
|
|
207
|
+
const { transcript, words, covered } = useMemo(() => {
|
|
208
|
+
const stitched = stitchChunks(progress);
|
|
209
|
+
return {
|
|
210
|
+
transcript: stitched,
|
|
211
|
+
words: countWords(stitched),
|
|
212
|
+
covered: progress.reduce((furthest, chunk) => Math.max(furthest, chunk.endMs), 0),
|
|
213
|
+
};
|
|
214
|
+
}, [progress]);
|
|
190
215
|
if (progress.length === 0) return null;
|
|
191
216
|
|
|
192
|
-
// The furthest point reached, not the count: segments land out of order, so
|
|
193
|
-
// "6 segments" says nothing about how much of the recording is covered.
|
|
194
|
-
const covered = Math.max(...progress.map((chunk) => chunk.endMs));
|
|
195
217
|
return (
|
|
196
218
|
<div className="flex flex-col gap-2">
|
|
197
|
-
<
|
|
198
|
-
{countWords(transcript)} words so far · through {formatDuration(covered)}
|
|
199
|
-
</p>
|
|
219
|
+
<Facts size="xs" items={[`${words} words so far`, `through ${formatDuration(covered)}`]} />
|
|
200
220
|
<pre className="whitespace-pre-wrap text-sm leading-relaxed opacity-80">{transcript}</pre>
|
|
201
221
|
</div>
|
|
202
222
|
);
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { formatDuration } from "@alexkroman1/aai/utils";
|
|
18
|
+
import { Facts } from "@alexkroman1/aai-ui";
|
|
18
19
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
19
20
|
|
|
20
21
|
/**
|
|
@@ -29,12 +30,17 @@ const STOPWATCH_TICK_MS = 250;
|
|
|
29
30
|
/** What {@link useTotalLatency} reports. */
|
|
30
31
|
export type TotalLatency = {
|
|
31
32
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
33
|
+
* The mark the clock started at, or undefined before the first submit.
|
|
34
|
+
*
|
|
35
|
+
* The raw mark rather than an elapsed duration, and that is the load-bearing
|
|
36
|
+
* part: an elapsed number is stale the instant it is computed, so a page
|
|
37
|
+
* holding one has to re-render to keep it true — which is what used to drive
|
|
38
|
+
* the whole tree at 4 Hz. {@link TotalLatency} turns these two marks into a
|
|
39
|
+
* duration, and only that section re-renders.
|
|
34
40
|
*/
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
|
|
41
|
+
startedAt: number | undefined;
|
|
42
|
+
/** The elapsed time at the moment the run settled, once it has. */
|
|
43
|
+
frozenMs: number | undefined;
|
|
38
44
|
/** Start (or restart) the clock. Called from the form's own submit handler. */
|
|
39
45
|
start: () => void;
|
|
40
46
|
/** Drop it, for a panel that no longer describes the submission it timed. */
|
|
@@ -53,7 +59,10 @@ export type TotalLatency = {
|
|
|
53
59
|
*
|
|
54
60
|
* - **The interval re-renders; it does not accumulate.** The elapsed time is read
|
|
55
61
|
* from the clock at render, so a tick the tab throttled or dropped cannot make
|
|
56
|
-
* the number lag behind real time.
|
|
62
|
+
* the number lag behind real time. The interval lives in {@link TotalLatency}
|
|
63
|
+
* rather than here, because a hook called from the page makes its ticks the
|
|
64
|
+
* PAGE's re-renders — the form, the upload bar, the run panel and the whole
|
|
65
|
+
* history list, four times a second, to move one duration string.
|
|
57
66
|
* - **`performance.now()`, not `Date.now()`.** It is monotonic, so a clock
|
|
58
67
|
* correction (NTP, a laptop waking up) cannot make a transcription look
|
|
59
68
|
* instant — or negative.
|
|
@@ -61,8 +70,6 @@ export type TotalLatency = {
|
|
|
61
70
|
export function useTotalLatency(inFlight: boolean): TotalLatency {
|
|
62
71
|
const [startedAt, setStartedAt] = useState<number | undefined>(undefined);
|
|
63
72
|
const [frozenMs, setFrozenMs] = useState<number | undefined>(undefined);
|
|
64
|
-
// Re-render trigger only — see the doc above.
|
|
65
|
-
const [, tick] = useState(0);
|
|
66
73
|
// Whether `inFlight` has been seen true since the last `start()`. Without it,
|
|
67
74
|
// a start that lands one render before the submission reports itself in flight
|
|
68
75
|
// would freeze the clock at zero instead of running it.
|
|
@@ -72,8 +79,7 @@ export function useTotalLatency(inFlight: boolean): TotalLatency {
|
|
|
72
79
|
if (startedAt === undefined || frozenMs !== undefined) return;
|
|
73
80
|
if (inFlight) {
|
|
74
81
|
began.current = true;
|
|
75
|
-
|
|
76
|
-
return () => clearInterval(id);
|
|
82
|
+
return;
|
|
77
83
|
}
|
|
78
84
|
// Measured here rather than at render, so the frozen number is the one at the
|
|
79
85
|
// moment the run settled rather than whenever this page next drew.
|
|
@@ -93,8 +99,8 @@ export function useTotalLatency(inFlight: boolean): TotalLatency {
|
|
|
93
99
|
}, []);
|
|
94
100
|
|
|
95
101
|
return {
|
|
96
|
-
|
|
97
|
-
|
|
102
|
+
startedAt,
|
|
103
|
+
frozenMs,
|
|
98
104
|
start,
|
|
99
105
|
clear,
|
|
100
106
|
};
|
|
@@ -114,17 +120,31 @@ export function useTotalLatency(inFlight: boolean): TotalLatency {
|
|
|
114
120
|
* notices it finished. Clamped at zero, because the two numbers come from two
|
|
115
121
|
* different clocks on two different machines and a few milliseconds the wrong way
|
|
116
122
|
* would otherwise print a negative.
|
|
123
|
+
*
|
|
124
|
+
* The stopwatch interval lives HERE rather than in {@link useTotalLatency}, so a
|
|
125
|
+
* running clock re-renders this section and nothing else.
|
|
117
126
|
*/
|
|
118
127
|
export function TotalLatency({
|
|
119
|
-
|
|
120
|
-
|
|
128
|
+
startedAt,
|
|
129
|
+
frozenMs,
|
|
121
130
|
runMs,
|
|
122
131
|
}: {
|
|
123
|
-
|
|
124
|
-
|
|
132
|
+
startedAt: number | undefined;
|
|
133
|
+
frozenMs: number | undefined;
|
|
125
134
|
runMs: number | undefined;
|
|
126
135
|
}) {
|
|
127
|
-
|
|
136
|
+
// Re-render trigger only: the elapsed time is read from the clock below, so a
|
|
137
|
+
// tick the tab throttled or dropped cannot make the number lag real time.
|
|
138
|
+
const [, tick] = useState(0);
|
|
139
|
+
const running = startedAt !== undefined && frozenMs === undefined;
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
if (!running) return;
|
|
142
|
+
const id = setInterval(() => tick((n) => n + 1), STOPWATCH_TICK_MS);
|
|
143
|
+
return () => clearInterval(id);
|
|
144
|
+
}, [running]);
|
|
145
|
+
|
|
146
|
+
if (startedAt === undefined) return null;
|
|
147
|
+
const elapsedMs = frozenMs ?? performance.now() - startedAt;
|
|
128
148
|
const outside = runMs === undefined ? undefined : Math.max(0, elapsedMs - runMs);
|
|
129
149
|
return (
|
|
130
150
|
<section className="flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1 rounded-md border px-5 py-3">
|
|
@@ -134,9 +154,15 @@ export function TotalLatency({
|
|
|
134
154
|
<span className="flex flex-wrap items-baseline gap-x-3 gap-y-1">
|
|
135
155
|
<span className="text-sm tabular-nums">{formatDuration(elapsedMs)}</span>
|
|
136
156
|
{runMs !== undefined && outside !== undefined && (
|
|
137
|
-
<
|
|
138
|
-
|
|
139
|
-
|
|
157
|
+
<Facts
|
|
158
|
+
size="xs"
|
|
159
|
+
as="span"
|
|
160
|
+
className="tabular-nums"
|
|
161
|
+
items={[
|
|
162
|
+
`${formatDuration(outside)} before the run`,
|
|
163
|
+
`${formatDuration(runMs)} inside it`,
|
|
164
|
+
]}
|
|
165
|
+
/>
|
|
140
166
|
)}
|
|
141
167
|
</span>
|
|
142
168
|
</section>
|