Skip to content

Commit 2345500

Browse files
authored
Merge pull request #55 from ssdeanx/develop
chore: update dependencies and refactor workflow stages
2 parents cf43c89 + 5d63f06 commit 2345500

8 files changed

Lines changed: 158 additions & 122 deletions

eslint.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import js from '@eslint/js'
2+
import globals from "globals";
3+
import reactHooks from "eslint-plugin-react-hooks";
4+
import reactRefresh from "eslint-plugin-react-refresh";
25
import tseslint from '@typescript-eslint/eslint-plugin'
36
import tsparser from '@typescript-eslint/parser'
47
import prettierConfig from 'eslint-config-prettier'
8+
import { globalIgnores } from "eslint/config";
59

610
const ignores = [
711
'eslint.config.js',
@@ -46,7 +50,10 @@ const ignores = [
4650

4751
export default [
4852
{ ignores },
53+
globalIgnores(["dist", "node_modules"]),
4954
js.configs.recommended,
55+
reactHooks.configs.flat.recommended,
56+
reactRefresh.configs.next,
5057
prettierConfig,
5158
{
5259
files: ['**/*.ts', '**/*.tsx'],
@@ -55,6 +62,7 @@ export default [
5562
},
5663
languageOptions: {
5764
parser: tsparser,
65+
globals: globals.browser,
5866
parserOptions: {
5967
ecmaVersion: 2022,
6068
sourceType: 'module',

lib/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { type ClassValue, clsx } from "clsx"
22
import { twMerge } from "tailwind-merge"
3+
import { v4 as uuid } from "@lukeed/uuid";
34

45
export function cn(...inputs: ClassValue[]) {
56
return twMerge(clsx(inputs))
67
}
8+
export function newThreadLink(
9+
rootPath: string,
10+
agentId: string,
11+
): `/${string}/${string}/chat/${string}?new=true` {
12+
return `/${rootPath}/${agentId}/chat/${uuid()}?new=true`;
13+
}

package-lock.json

Lines changed: 57 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@
119119
"diff": "^8.0.2",
120120
"dotenv": "^17.2.3",
121121
"embla-carousel-react": "^8.6.0",
122+
"eslint-plugin-react-hooks": "^7.0.1",
123+
"eslint-plugin-react-refresh": "^0.4.23",
122124
"excalidraw-to-svg": "^3.1.0",
123125
"fast-glob": "^3.3.3",
124126
"fast-xml-parser": "^5.3.3",
@@ -216,4 +218,4 @@
216218
"body-parser": "^2.2.1",
217219
"jws": "^4.0.1"
218220
}
219-
}
221+
}

src/mastra/workflows/document-processing-workflow.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ const convertPdfToMarkdownStep = createStep({
269269
data: {
270270
status: 'in-progress',
271271
message: 'Converting PDF to markdown `...',
272-
stage: "documentProcessingAgent",
272+
stage: "convert-pdf-to-markdown",
273273
},
274274
id: "convert-pdf-to-markdown",
275275
});
@@ -318,7 +318,7 @@ const convertPdfToMarkdownStep = createStep({
318318
data: {
319319
status: "in-progress",
320320
message: 'Markdown conversion complete (90%)...',
321-
stage: "documentProcessingAgent",
321+
stage: "convert-pdf-to-markdown",
322322
},
323323
id: "convert-pdf-to-markdown",
324324
});
@@ -345,7 +345,7 @@ const convertPdfToMarkdownStep = createStep({
345345
data: {
346346
status: "done",
347347
message: "PDF converted to markdown successfully",
348-
stepId: 'convert-pdf-to-markdown',
348+
stage: 'convert-pdf-to-markdown',
349349
},
350350
id: "convert-pdf-to-markdown",
351351
});
@@ -360,9 +360,10 @@ const convertPdfToMarkdownStep = createStep({
360360
logError('convert-pdf-to-markdown', error, { contentType: inputData.contentType });
361361

362362
await writer?.custom({
363-
type: 'data-workflow-step-error',
363+
type: 'data-tool-progress',
364364
data: {
365-
stepId: 'convert-pdf-to-markdown',
365+
stage: 'convert-pdf-to-markdown',
366+
status: "done",
366367
error: error instanceof Error ? error.message : 'Unknown error',
367368
},
368369
id: "convert-pdf-to-markdown",

src/mastra/workflows/repo-ingestion-workflow.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -177,29 +177,36 @@ const ingestStep = createStep({
177177

178178
const result = await mdocumentChunker.execute({
179179
documentContent: content,
180-
documentMetadata: { filePath, source: githubRepo ? 'github' : 'local' },
180+
documentMetadata: { filePath, source: (githubRepo) ? 'github' : 'local' },
181181
chunkingStrategy: strategy,
182182
indexName: 'memory_messages_3072',
183183
generateEmbeddings: true,
184+
embeddingModel: 'google/gemini-embedding-001',
185+
embeddingBatchSize: 50,
184186
chunkSize: 512,
185187
chunkOverlap: 50,
186188
chunkSeparator: '\n'
187189
}, { writer, requestContext });
188190

189-
if (result && typeof result === 'object' && 'success' in result && result.success) {
190-
processedFiles++;
191-
totalChunks += result.chunkCount;
192-
}
193-
else if (result instanceof ZodError) {
194-
throw new Error(result.message);
195-
}
196-
else if (result instanceof Error) {
197-
throw result;
198-
} else if (result && typeof result === 'object' && 'error' in result) {
199-
throw new Error(typeof result.error === 'string' ? result.error : 'Unknown error in chunking');
200-
} else {
201-
throw new Error('Unknown error in chunking');
202-
}
191+
const isSuccessResult = (r: unknown): r is { success: true; chunkCount?: number } =>
192+
typeof r === 'object' && r !== null && 'success' in r && (r as { success: unknown }).success === true;
193+
194+
const isErrorObject = (r: unknown): r is { error: unknown } =>
195+
typeof r === 'object' && r !== null && 'error' in r;
196+
197+
if (isSuccessResult(result)) {
198+
processedFiles++;
199+
totalChunks += result.chunkCount ?? 0;
200+
} else if (result instanceof ZodError) {
201+
throw new Error(result.message);
202+
} else if (result instanceof Error) {
203+
throw result;
204+
} else if (isErrorObject(result)) {
205+
const err = result.error;
206+
throw new Error(typeof err === 'string' ? err : 'Unknown error in chunking');
207+
} else {
208+
throw new Error('Unknown error in chunking');
209+
}
203210

204211
} catch (error) {
205212
const errorObj = error instanceof Error ? error : new Error(String(error));

src/mastra/workflows/research-synthesis-workflow.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ const initializeResearchStep = createStep({
7272
await writer?.custom({
7373
type: 'data-tool-progress',
7474
data: {
75-
status: "in-progress",
76-
message: `Researching topic: ${inputData.topics}...`,
77-
stage: "researchAgent",
75+
status: "in-progress",
76+
message: `Researching topic: ${inputData.topics}...`,
77+
stage: "researchAgent",
7878
},
7979
id: 'initialize-research',
8080
});
@@ -84,7 +84,7 @@ const initializeResearchStep = createStep({
8484
maxSources: inputData.maxSourcesPerTopic,
8585
}));
8686

87-
87+
8888
logStepEnd('initialize-research', { topicsCount: topics.length }, Date.now() - startTime);
8989

9090
return topics;
@@ -109,7 +109,7 @@ const researchTopicStep = createStep({
109109
data: {
110110
status: 'in-progress',
111111
message: `Researching topic: ${inputData.topic}...`,
112-
stage: 'workflow',
112+
stage: 'research-topic-item',
113113
},
114114
id: 'research-topic-item',
115115
});
@@ -128,7 +128,7 @@ const researchTopicStep = createStep({
128128
data: {
129129
status: 'in-progress',
130130
message: `Researching topic: ${inputData.topic}...`,
131-
stage: 'workflow',
131+
stage: 'research-topic-item',
132132
},
133133
id: 'research-topic-item',
134134
});
@@ -189,7 +189,7 @@ const researchTopicStep = createStep({
189189
data: {
190190
status: 'done',
191191
message: `Research completed for ${inputData.topic}...`,
192-
stage: 'workflow',
192+
stage: 'research-topic-item',
193193
},
194194
id: 'research-topic-item',
195195
});
@@ -211,9 +211,9 @@ const researchTopicStep = createStep({
211211
await writer?.custom({
212212
type: 'data-tool-progress',
213213
data: {
214-
status: 'in-progress',
214+
status: 'done',
215215
message: `Research error for ${inputData.topic}...`,
216-
stage: 'researchAgent',
216+
stage: 'research-topic-item',
217217
},
218218
id: 'research-topic-item',
219219
});
@@ -255,6 +255,7 @@ const synthesizeResearchStep = createStep({
255255
data: {
256256
status: 'in-progress',
257257
message: 'Synthesizing research across topics...',
258+
stage: 'synthesize-research',
258259
},
259260
id: 'synthesize-research',
260261
});
@@ -269,6 +270,7 @@ const synthesizeResearchStep = createStep({
269270
data: {
270271
status: 'in-progress',
271272
message: 'AI synthesizing findings...',
273+
stage: 'synthesize-research',
272274
},
273275
id: 'synthesize-research',
274276
});
@@ -352,6 +354,7 @@ Provide:
352354
data: {
353355
status: 'done',
354356
message: 'Synthesis complete...',
357+
stage: 'synthesize-research',
355358
},
356359
id: 'synthesize-research',
357360
});
@@ -376,7 +379,7 @@ Provide:
376379
span.setAttribute('responseTimeMs', Date.now() - startTime);
377380
span.end();
378381

379-
382+
380383
logStepEnd('synthesize-research', { themesCount: synthesis.commonThemes.length }, Date.now() - startTime);
381384
return result;
382385
} catch (error) {
@@ -386,10 +389,11 @@ Provide:
386389
logError('synthesize-research', error);
387390

388391
await writer?.custom({
389-
type: 'data-workflow-step-error',
392+
type: 'data-tool-progress',
390393
data: {
391-
stepId: 'synthesize-research',
394+
stage: 'synthesize-research',
392395
error: error instanceof Error ? error.message : 'Unknown error',
396+
status: 'done',
393397
},
394398
id: 'synthesize-research',
395399
});
@@ -421,6 +425,7 @@ const generateResearchReportStep = createStep({
421425
data: {
422426
status: 'in-progress',
423427
message: 'Generating research report...',
428+
stage: 'generate-research-report',
424429
},
425430
id: 'generate-research-report',
426431
});
@@ -434,6 +439,7 @@ const generateResearchReportStep = createStep({
434439
data: {
435440
status: 'in-progress',
436441
message: 'AI generating comprehensive report...',
442+
stage: 'generate-research-report',
437443
},
438444
id: 'generate-research-report',
439445
});
@@ -502,7 +508,7 @@ ${inputData.synthesis.gaps?.map(g => `- ${g}`).join('\n') ?? 'No significant gap
502508
data: {
503509
status: 'done',
504510
message: 'Report generation complete...',
505-
stage: 'workflow',
511+
stage: 'generate-research-report',
506512
},
507513
id: 'generate-research-report',
508514
});
@@ -523,7 +529,7 @@ ${inputData.synthesis.gaps?.map(g => `- ${g}`).join('\n') ?? 'No significant gap
523529
span.setAttribute('responseTimeMs', Date.now() - startTime);
524530
span.end();
525531

526-
532+
527533
logStepEnd('generate-research-report', { reportLength: report.length }, Date.now() - startTime);
528534
return result;
529535
} catch (error) {
@@ -533,11 +539,11 @@ ${inputData.synthesis.gaps?.map(g => `- ${g}`).join('\n') ?? 'No significant gap
533539
logError('generate-research-report', error);
534540

535541
await writer?.custom({
536-
type: 'data-workflow-step-error',
542+
type: 'data-tool-progress',
537543
data: {
538-
stepId: 'generate-research-report',
544+
stage: 'generate-research-report',
539545
error: error instanceof Error ? error.message : 'Unknown error',
540-
stage: 'workflow',
546+
status: 'done'
541547
},
542548
id: 'generate-research-report',
543549
});

0 commit comments

Comments
 (0)