This repository was archived by the owner on Jan 13, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 108
ITO-448: Create Interactions Directly from transcribe stream #455
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import type { FastifyRequest } from 'fastify' | ||
|
|
||
| /** | ||
| * Extracts the user ID from a Fastify request. | ||
| * In production (requireAuth=true), returns the authenticated user's sub from JWT. | ||
| * In dev mode (requireAuth=false), returns 'self-hosted' as a default user ID. | ||
| * | ||
| * @param request - The Fastify request object | ||
| * @param requireAuth - Whether authentication is required (from REQUIRE_AUTH env var) | ||
| * @returns The user ID, or undefined if not authenticated and auth is required | ||
| */ | ||
| export function getUserIdFromRequest( | ||
| request: FastifyRequest, | ||
| requireAuth: boolean, | ||
| ): string | undefined { | ||
| // Try to get authenticated user ID from JWT | ||
| const authenticatedUserId = (request as any).user?.sub | ||
|
|
||
| if (authenticatedUserId) { | ||
| return authenticatedUserId | ||
| } | ||
|
|
||
| // In dev mode (auth disabled), use 'self-hosted' as default user | ||
| if (!requireAuth) { | ||
| return 'self-hosted' | ||
| } | ||
|
|
||
| // Auth required but no user found | ||
| return undefined | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { v4 as uuidv4 } from 'uuid' | ||
| import { getStorageClient } from '../../clients/s3storageClient.js' | ||
| import { createAudioKey } from '../../constants/storage.js' | ||
| import { InteractionsRepository } from '../../db/repo.js' | ||
| import type { Interaction } from '../../db/models.js' | ||
|
|
||
| export interface CreateInteractionParams { | ||
| id: string | ||
| userId: string | ||
| title: string | ||
| asrOutput: string | ||
| llmOutput: string | null | ||
| durationMs: number | ||
| rawAudio?: Buffer | ||
| } | ||
|
|
||
| /** | ||
| * Creates an interaction in the database, optionally uploading audio to S3. | ||
| * This helper is shared between the gRPC createInteraction endpoint and | ||
| * the transcribeStreamV2Handler. | ||
| */ | ||
| export async function createInteractionWithAudio( | ||
| params: CreateInteractionParams, | ||
| ): Promise<Interaction> { | ||
| const { id, userId, title, asrOutput, llmOutput, durationMs, rawAudio } = | ||
| params | ||
|
|
||
| let rawAudioId: string | undefined | ||
|
|
||
| // If raw audio is provided, upload to S3 | ||
| if (rawAudio && rawAudio.length > 0) { | ||
| const storageClient = getStorageClient() | ||
| rawAudioId = uuidv4() | ||
| const audioKey = createAudioKey(userId, rawAudioId) | ||
|
|
||
| await storageClient.uploadObject( | ||
|
||
| audioKey, | ||
| rawAudio, | ||
| undefined, // ContentType | ||
| { | ||
| userId, | ||
| interactionId: id, | ||
| timestamp: new Date().toISOString(), | ||
| }, | ||
| ) | ||
|
|
||
| console.log( | ||
| `✅ [${new Date().toISOString()}] Uploaded audio to S3: ${audioKey}`, | ||
| ) | ||
| } | ||
|
|
||
| // Create interaction in database | ||
| const interaction = await InteractionsRepository.create({ | ||
| id, | ||
| userId, | ||
| title, | ||
| asrOutput, | ||
| llmOutput, | ||
| rawAudioId, | ||
| durationMs, | ||
| }) | ||
|
|
||
| console.log( | ||
| `✅ [${new Date().toISOString()}] Created interaction: ${id}`, | ||
| ) | ||
|
|
||
| return interaction | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When running docker compose up, this script will get called and the minio buckets will get created. This makes it a little more automated to get the local stack running