Skip to content

Commit a1fbff5

Browse files
committed
Implement version 3 of AI table request handling and update related components
1 parent 87c132a commit a1fbff5

6 files changed

Lines changed: 408 additions & 12 deletions

File tree

backend/src/ai-core/providers/langchain-bedrock.provider.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export class LangchainBedrockProvider implements IAIProvider {
185185
stream: AsyncIterable<AIMessageChunk>,
186186
): Promise<IterableReadableStream<AIStreamChunk>> {
187187
async function* generateChunks(): AsyncGenerator<AIStreamChunk> {
188-
let currentToolCalls: Map<number, AIToolCall> = new Map();
188+
let currentToolCalls: Map<number, { id: string; name: string; argsString: string }> = new Map();
189189

190190
for await (const chunk of stream) {
191191
if (chunk.tool_call_chunks && chunk.tool_call_chunks.length > 0) {
@@ -196,7 +196,7 @@ export class LangchainBedrockProvider implements IAIProvider {
196196
currentToolCalls.set(index, {
197197
id: toolCallChunk.id || '',
198198
name: toolCallChunk.name || '',
199-
arguments: {},
199+
argsString: '',
200200
});
201201
}
202202

@@ -209,12 +209,7 @@ export class LangchainBedrockProvider implements IAIProvider {
209209
currentCall.name = toolCallChunk.name;
210210
}
211211
if (toolCallChunk.args) {
212-
try {
213-
const parsedArgs = JSON.parse(toolCallChunk.args);
214-
currentCall.arguments = { ...currentCall.arguments, ...parsedArgs };
215-
} catch {
216-
// Accumulate partial JSON - will be parsed when complete
217-
}
212+
currentCall.argsString += toolCallChunk.args;
218213
}
219214
}
220215
}
@@ -231,11 +226,24 @@ export class LangchainBedrockProvider implements IAIProvider {
231226
}
232227
}
233228

234-
for (const toolCall of currentToolCalls.values()) {
235-
if (toolCall.name) {
229+
for (const toolCallData of currentToolCalls.values()) {
230+
if (toolCallData.name) {
231+
let parsedArgs: Record<string, unknown> = {};
232+
if (toolCallData.argsString) {
233+
try {
234+
parsedArgs = JSON.parse(toolCallData.argsString);
235+
} catch {
236+
// Failed to parse args, use empty object
237+
}
238+
}
239+
236240
yield {
237241
type: 'tool_call',
238-
toolCall,
242+
toolCall: {
243+
id: toolCallData.id,
244+
name: toolCallData.name,
245+
arguments: parsedArgs,
246+
},
239247
};
240248
}
241249
}

backend/src/common/data-injection.tokens.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export enum UseCaseType {
158158
DELETE_API_KEY = 'DELETE_API_KEY',
159159

160160
REQUEST_INFO_FROM_TABLE_WITH_AI_V2 = 'REQUEST_INFO_FROM_TABLE_WITH_AI_V2',
161+
REQUEST_INFO_FROM_TABLE_WITH_AI_V3 = 'REQUEST_INFO_FROM_TABLE_WITH_AI_V3',
161162
REQUEST_AI_SETTINGS_AND_WIDGETS_CREATION = 'REQUEST_AI_SETTINGS_AND_WIDGETS_CREATION',
162163

163164
CREATE_TABLE_FILTERS = 'CREATE_TABLE_FILTERS',

backend/src/entities/ai/ai.module.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { UserEntity } from '../user/user.entity.js';
88
import { AiService } from './ai.service.js';
99
import { RequestAISettingsAndWidgetsCreationUseCase } from './use-cases/request-ai-settings-and-widgets-creation.use.case.js';
1010
import { RequestInfoFromTableWithAIUseCaseV5 } from './use-cases/request-info-from-table-with-ai-v5.use.case.js';
11+
import { RequestInfoFromTableWithAIUseCaseV6 } from './use-cases/request-info-from-table-with-ai-v6.use.case.js';
1112
import { UserAIRequestsControllerV2 } from './user-ai-requests-v2.controller.js';
1213

1314
@Global()
@@ -22,6 +23,10 @@ import { UserAIRequestsControllerV2 } from './user-ai-requests-v2.controller.js'
2223
provide: UseCaseType.REQUEST_INFO_FROM_TABLE_WITH_AI_V2,
2324
useClass: RequestInfoFromTableWithAIUseCaseV5,
2425
},
26+
{
27+
provide: UseCaseType.REQUEST_INFO_FROM_TABLE_WITH_AI_V3,
28+
useClass: RequestInfoFromTableWithAIUseCaseV6,
29+
},
2530
{
2631
provide: UseCaseType.REQUEST_AI_SETTINGS_AND_WIDGETS_CREATION,
2732
useClass: RequestAISettingsAndWidgetsCreationUseCase,
@@ -37,6 +42,7 @@ export class AIModule implements NestModule {
3742
.apply(AuthMiddleware)
3843
.forRoutes(
3944
{ path: '/ai/v2/request/:connectionId', method: RequestMethod.POST },
45+
{ path: '/ai/v3/request/:connectionId', method: RequestMethod.POST },
4046
{ path: '/ai/v2/setup/:connectionId', method: RequestMethod.GET },
4147
);
4248
}

0 commit comments

Comments
 (0)