mirror of https://github.com/buster-so/buster.git
Enhance report handling by integrating markdown to PlateJS conversion in the report retrieval process, improving content formatting and error handling. Update report update schema to accept string content for markdown streaming.
This commit is contained in:
parent
b8ad52cf28
commit
a26242c46d
|
@ -1,5 +1,6 @@
|
|||
import { getReport } from '@buster/database';
|
||||
import type { GetReportIndividualResponse } from '@buster/server-shared/reports';
|
||||
import { markdownToPlatejs } from '@buster/server-utils/report';
|
||||
import { Hono } from 'hono';
|
||||
import { HTTPException } from 'hono/http-exception';
|
||||
import { standardErrorHandler } from '../../../../utils/response';
|
||||
|
@ -10,7 +11,21 @@ export async function getReportHandler(
|
|||
): Promise<GetReportIndividualResponse> {
|
||||
const report = await getReport({ reportId, userId: user.id });
|
||||
|
||||
const response: GetReportIndividualResponse = report;
|
||||
const platejsResult = await markdownToPlatejs(report.content);
|
||||
|
||||
if (platejsResult.error) {
|
||||
console.error('Error converting markdown to PlateJS:', platejsResult.error);
|
||||
throw new HTTPException(500, {
|
||||
message: 'Error converting markdown to PlateJS',
|
||||
});
|
||||
}
|
||||
|
||||
const content = platejsResult.elements ?? [];
|
||||
|
||||
const response: GetReportIndividualResponse = {
|
||||
...report,
|
||||
content,
|
||||
};
|
||||
|
||||
return response;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const routerInstructions = `
|
||||
const _routerInstructions = `
|
||||
You are a router that decides between two modes for processing user queries in a data analysis LLM: Standard and Investigation.
|
||||
|
||||
Standard mode is the default. Use it for common questions, building charts/dashboards, narrative reports with minor analysis, single metrics, specific reports, or when the query isn't a deep research question. It handles lightweight tasks and some analysis, but not iterative deep dives.
|
||||
|
|
|
@ -6,9 +6,9 @@ import type { CoreMessage } from 'ai';
|
|||
import { wrapTraced } from 'braintrust';
|
||||
import { z } from 'zod';
|
||||
import { getSqlDialectGuidance } from '../agents/shared/sql-dialect-guidance';
|
||||
import { createThinkAndPrepInstructionsWithoutDatasets as createInvestigationInstructionsWithoutDatasets } from '../agents/think-and-prep-agent/investigation-instructions';
|
||||
import { thinkAndPrepAgent } from '../agents/think-and-prep-agent/think-and-prep-agent';
|
||||
import { createThinkAndPrepInstructionsWithoutDatasets } from '../agents/think-and-prep-agent/think-and-prep-instructions';
|
||||
import { createThinkAndPrepInstructionsWithoutDatasets as createInvestigationInstructionsWithoutDatasets } from '../agents/think-and-prep-agent/investigation-instructions';
|
||||
import type { thinkAndPrepWorkflowInputSchema } from '../schemas/workflow-schemas';
|
||||
import { ChunkProcessor } from '../utils/database/chunk-processor';
|
||||
import {
|
||||
|
@ -270,17 +270,18 @@ ${databaseContext}
|
|||
async () => {
|
||||
// Get the analysis type from the router step
|
||||
const analysisType = inputData['analysis-type-router'].analysisType.choice;
|
||||
|
||||
|
||||
console.info('Think and Prep: Using analysis type', {
|
||||
analysisType,
|
||||
reasoning: inputData['analysis-type-router'].analysisType.reasoning,
|
||||
});
|
||||
|
||||
|
||||
// Select the appropriate instructions based on analysis type
|
||||
const instructions = analysisType === 'investigation'
|
||||
? createInvestigationInstructionsWithoutDatasets(sqlDialectGuidance)
|
||||
: createThinkAndPrepInstructionsWithoutDatasets(sqlDialectGuidance);
|
||||
|
||||
const instructions =
|
||||
analysisType === 'investigation'
|
||||
? createInvestigationInstructionsWithoutDatasets(sqlDialectGuidance)
|
||||
: createThinkAndPrepInstructionsWithoutDatasets(sqlDialectGuidance);
|
||||
|
||||
// Create system messages with dataset context and instructions
|
||||
const systemMessages: CoreMessage[] = [
|
||||
{
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
import { and, eq, isNull } from 'drizzle-orm';
|
||||
import {} from 'drizzle-zod';
|
||||
import { z } from 'zod';
|
||||
import { db } from '../../connection';
|
||||
import { reportFiles } from '../../schema';
|
||||
import { workspaceSharingEnum } from '../../schema';
|
||||
import { ReportElementSchema, type ReportElements } from '../../schema-types';
|
||||
import { reportFiles, workspaceSharingEnum } from '../../schema';
|
||||
|
||||
// Type for updating reportFiles - excludes read-only fields
|
||||
type UpdateReportData = Partial<
|
||||
|
@ -20,9 +17,7 @@ const UpdateReportInputSchema = z.object({
|
|||
userId: z.string().uuid('User ID must be a valid UUID'),
|
||||
name: z.string().optional(),
|
||||
publicly_accessible: z.boolean().optional(),
|
||||
content: z.lazy(() => z.array(ReportElementSchema)).optional() as z.ZodOptional<
|
||||
z.ZodType<ReportElements>
|
||||
>,
|
||||
content: z.string().optional(),
|
||||
public_expiry_date: z.string().nullable().optional(),
|
||||
public_password: z.string().nullable().optional(),
|
||||
workspace_sharing: WorkspaceSharingSchema.optional(),
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,4 @@
|
|||
import { ReportElementsSchema } from '@buster/database';
|
||||
import { type ReportElements, ReportElementsSchema } from '@buster/database';
|
||||
import { AutoformatPlugin } from '@platejs/autoformat';
|
||||
import {
|
||||
BaseBasicBlocksPlugin,
|
||||
|
|
Loading…
Reference in New Issue