learning_ai_notes/web/src/lib/extraction-client.ts
saravanakumardb1 71062a57be fix(web): fix auth token key inconsistency and DRY getAccessToken()
feature-flags.ts and prompt-client.ts used bare 'access_token' key
instead of PRODUCT_ID-prefixed key — auth tokens were never sent.

Consolidates 10 web lib files to import the shared getAccessToken()
from api-helpers.ts instead of each redefining their own copy.
2026-04-13 09:59:18 -07:00

43 lines
1.2 KiB
TypeScript

"use client";
import { createExtractionClient, type ExtractionClient } from "@bytelyst/extraction";
import { EXTRACTION_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config";
import { getAccessToken } from "@/lib/api-helpers";
import type { NoteTask } from "@/lib/types";
let _client: ExtractionClient | null = null;
function getClient(): ExtractionClient {
if (!_client) {
_client = createExtractionClient({
baseUrl: EXTRACTION_SERVICE_URL,
getToken: getAccessToken,
});
}
return _client;
}
function slugify(value: string): string {
return value
.toLowerCase()
.replace(/[^a-z0-9]+/g, "-")
.replace(/^-+|-+$/g, "")
.slice(0, 64);
}
export async function extractSuggestedTasks(text: string): Promise<NoteTask[]> {
const response = await getClient().extract({
text,
taskId: "transcript-extraction",
productId: PRODUCT_ID,
});
return response.extractions
.filter((item) => item.extraction_class === "action_item" || item.extraction_class === "deadline")
.map((item, index) => ({
id: `extract-${slugify(item.extraction_text)}-${index}`,
title: item.extraction_text,
status: "todo",
source: "agent",
}));
}