-
Notifications
You must be signed in to change notification settings - Fork 0
fix: add dataconnect-generated stubs and fix TypeScript errors in emb… #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /** | ||
| * Stub types for Firebase Data Connect SDK | ||
| * | ||
| * In production, this file would be auto-generated by Firebase Data Connect. | ||
| * For Vercel builds where Data Connect isn't available, we provide stubs | ||
| * that throw helpful errors at runtime. | ||
| */ | ||
| export interface VideoEmbedding { | ||
| id: string; | ||
| segmentType: string; | ||
| segmentIndex: number; | ||
| content: string; | ||
| job?: { | ||
| id: string; | ||
| title?: string; | ||
| videoUrl?: string; | ||
| }; | ||
| } | ||
| export interface ListEmbeddingsResponse { | ||
| data: { | ||
| videoEmbeddings: VideoEmbedding[]; | ||
| }; | ||
| } | ||
| export interface GetJobEmbeddingsResponse { | ||
| data: { | ||
| videoEmbeddings: VideoEmbedding[]; | ||
| }; | ||
| } | ||
| type UUID = `${string}-${string}-${string}-${string}-${string}`; | ||
| /** | ||
| * List embeddings - stub that throws when Data Connect unavailable | ||
| */ | ||
| export declare function listEmbeddings(_params: { | ||
| limit: number; | ||
| }): Promise<ListEmbeddingsResponse>; | ||
| /** | ||
| * Get embeddings for a specific job - stub | ||
| */ | ||
| export declare function getJobEmbeddings(_params: { | ||
| jobId: UUID; | ||
| }): Promise<GetJobEmbeddingsResponse>; | ||
| /** | ||
| * Delete embeddings for a job - stub | ||
| */ | ||
| export declare function deleteJobEmbeddings(_params: { | ||
| jobId: UUID; | ||
| }): Promise<void>; | ||
| export {}; | ||
| //# sourceMappingURL=index.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,74 @@ | ||||||
| /** | ||||||
| * Stub types for Firebase Data Connect SDK | ||||||
| * | ||||||
| * In production, this file would be auto-generated by Firebase Data Connect. | ||||||
| * For Vercel builds where Data Connect isn't available, we provide stubs | ||||||
| * that throw helpful errors at runtime. | ||||||
| */ | ||||||
|
|
||||||
| // Type definitions matching expected Data Connect schema | ||||||
| export interface VideoEmbedding { | ||||||
| id: string; | ||||||
| segmentType: string; | ||||||
| segmentIndex: number; | ||||||
| content: string; | ||||||
| job?: { | ||||||
| id: string; | ||||||
| title?: string; | ||||||
| videoUrl?: string; | ||||||
| }; | ||||||
| } | ||||||
|
|
||||||
| export interface ListEmbeddingsResponse { | ||||||
| data: { | ||||||
| videoEmbeddings: VideoEmbedding[]; | ||||||
| }; | ||||||
| } | ||||||
|
|
||||||
| export interface GetJobEmbeddingsResponse { | ||||||
| data: { | ||||||
| videoEmbeddings: VideoEmbedding[]; | ||||||
| }; | ||||||
| } | ||||||
|
|
||||||
| // UUID type for job IDs | ||||||
| type UUID = `${string}-${string}-${string}-${string}-${string}`; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||
|
|
||||||
| /** | ||||||
| * List embeddings - stub that throws when Data Connect unavailable | ||||||
| */ | ||||||
| export async function listEmbeddings(_params: { | ||||||
| limit: number; | ||||||
| }): Promise<ListEmbeddingsResponse> { | ||||||
| throw new Error( | ||||||
| "Firebase Data Connect is not configured. " + | ||||||
| "Run 'firebase dataconnect:sdk:generate' to generate the SDK, " + | ||||||
| "or use raw SQL queries for embedding operations." | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Get embeddings for a specific job - stub | ||||||
| */ | ||||||
| export async function getJobEmbeddings(_params: { | ||||||
| jobId: UUID; | ||||||
| }): Promise<GetJobEmbeddingsResponse> { | ||||||
| throw new Error( | ||||||
| "Firebase Data Connect is not configured. " + | ||||||
| "Run 'firebase dataconnect:sdk:generate' to generate the SDK, " + | ||||||
| "or use raw SQL queries for embedding operations." | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Delete embeddings for a job - stub | ||||||
| */ | ||||||
| export async function deleteJobEmbeddings(_params: { | ||||||
| jobId: UUID; | ||||||
| }): Promise<void> { | ||||||
| throw new Error( | ||||||
| "Firebase Data Connect is not configured. " + | ||||||
| "Run 'firebase dataconnect:sdk:generate' to generate the SDK, " + | ||||||
| "or use raw SQL queries for embedding operations." | ||||||
| ); | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,7 +17,8 @@ import { | |||||||||||||
| listEmbeddings, | ||||||||||||||
| getJobEmbeddings, | ||||||||||||||
| deleteJobEmbeddings, | ||||||||||||||
| } from "../dataconnect-generated"; | ||||||||||||||
| type VideoEmbedding, | ||||||||||||||
| } from "./dataconnect-generated"; | ||||||||||||||
|
|
||||||||||||||
| // ============================================================================= | ||||||||||||||
| // Types | ||||||||||||||
|
|
@@ -108,7 +109,9 @@ export async function generateEmbedding(text: string): Promise<number[]> { | |||||||||||||
| throw new Error(`Embedding API error: ${response.status} ${await response.text()}`); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| const data = await response.json(); | ||||||||||||||
| const data = (await response.json()) as { | ||||||||||||||
| predictions: Array<{ embeddings: { values: number[] } }>; | ||||||||||||||
| }; | ||||||||||||||
| return data.predictions[0].embeddings.values; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -134,8 +137,10 @@ export async function generateEmbeddings(texts: string[]): Promise<number[][]> { | |||||||||||||
| throw new Error(`Embedding API error: ${response.status} ${await response.text()}`); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| const data = await response.json(); | ||||||||||||||
| return data.predictions.map((p: { embeddings: { values: number[] } }) => p.embeddings.values); | ||||||||||||||
| const data = (await response.json()) as { | ||||||||||||||
| predictions: Array<{ embeddings: { values: number[] } }>; | ||||||||||||||
| }; | ||||||||||||||
|
Comment on lines
+140
to
+142
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This anonymous type for the API response is also used in the |
||||||||||||||
| return data.predictions.map((p) => p.embeddings.values); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
|
|
@@ -148,7 +153,7 @@ async function getAccessToken(): Promise<string> { | |||||||||||||
| "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token", | ||||||||||||||
| { headers: { "Metadata-Flavor": "Google" } } | ||||||||||||||
| ); | ||||||||||||||
|
||||||||||||||
| ); | |
| ); | |
| if (!response.ok) { | |
| const body = await response.text().catch(() => "<unable to read response body>"); | |
| throw new Error(`Metadata server error: ${response.status} ${body}`); | |
| } |
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.
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.
These
dataconnect-generatedstubs are TypeScript source, but this PR also checks in compiled artifacts (index.js,.map,.d.ts,.d.ts.map) undersrc/. Keeping build outputs alongside sources is prone to drift and can confuse module resolution; it’s usually better to commit only the.tsstub here and lettscgenerate JS/declarations intodist/during the package build.