Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions backend/src/ai-core/providers/langchain-bedrock.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export class LangchainBedrockProvider implements IAIProvider {
stream: AsyncIterable<AIMessageChunk>,
): Promise<IterableReadableStream<AIStreamChunk>> {
async function* generateChunks(): AsyncGenerator<AIStreamChunk> {
let currentToolCalls: Map<number, AIToolCall> = new Map();
let currentToolCalls: Map<number, { id: string; name: string; argsString: string }> = new Map();

for await (const chunk of stream) {
if (chunk.tool_call_chunks && chunk.tool_call_chunks.length > 0) {
Expand All @@ -196,7 +196,7 @@ export class LangchainBedrockProvider implements IAIProvider {
currentToolCalls.set(index, {
id: toolCallChunk.id || '',
name: toolCallChunk.name || '',
arguments: {},
argsString: '',
});
}

Expand All @@ -209,12 +209,7 @@ export class LangchainBedrockProvider implements IAIProvider {
currentCall.name = toolCallChunk.name;
}
if (toolCallChunk.args) {
try {
const parsedArgs = JSON.parse(toolCallChunk.args);
currentCall.arguments = { ...currentCall.arguments, ...parsedArgs };
} catch {
// Accumulate partial JSON - will be parsed when complete
}
currentCall.argsString += toolCallChunk.args;
}
}
}
Expand All @@ -231,11 +226,24 @@ export class LangchainBedrockProvider implements IAIProvider {
}
}

for (const toolCall of currentToolCalls.values()) {
if (toolCall.name) {
for (const toolCallData of currentToolCalls.values()) {
if (toolCallData.name) {
let parsedArgs: Record<string, unknown> = {};
if (toolCallData.argsString) {
try {
parsedArgs = JSON.parse(toolCallData.argsString);
} catch {
// Failed to parse args, use empty object
}
}

yield {
type: 'tool_call',
toolCall,
toolCall: {
id: toolCallData.id,
name: toolCallData.name,
arguments: parsedArgs,
},
};
}
}
Expand Down
1 change: 1 addition & 0 deletions backend/src/common/data-injection.tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export enum UseCaseType {
DELETE_API_KEY = 'DELETE_API_KEY',

REQUEST_INFO_FROM_TABLE_WITH_AI_V2 = 'REQUEST_INFO_FROM_TABLE_WITH_AI_V2',
REQUEST_INFO_FROM_TABLE_WITH_AI_V3 = 'REQUEST_INFO_FROM_TABLE_WITH_AI_V3',
REQUEST_AI_SETTINGS_AND_WIDGETS_CREATION = 'REQUEST_AI_SETTINGS_AND_WIDGETS_CREATION',

CREATE_TABLE_FILTERS = 'CREATE_TABLE_FILTERS',
Expand Down
6 changes: 6 additions & 0 deletions backend/src/entities/ai/ai.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { UserEntity } from '../user/user.entity.js';
import { AiService } from './ai.service.js';
import { RequestAISettingsAndWidgetsCreationUseCase } from './use-cases/request-ai-settings-and-widgets-creation.use.case.js';
import { RequestInfoFromTableWithAIUseCaseV5 } from './use-cases/request-info-from-table-with-ai-v5.use.case.js';
import { RequestInfoFromTableWithAIUseCaseV6 } from './use-cases/request-info-from-table-with-ai-v6.use.case.js';
import { UserAIRequestsControllerV2 } from './user-ai-requests-v2.controller.js';

@Global()
Expand All @@ -22,6 +23,10 @@ import { UserAIRequestsControllerV2 } from './user-ai-requests-v2.controller.js'
provide: UseCaseType.REQUEST_INFO_FROM_TABLE_WITH_AI_V2,
useClass: RequestInfoFromTableWithAIUseCaseV5,
},
{
provide: UseCaseType.REQUEST_INFO_FROM_TABLE_WITH_AI_V3,
useClass: RequestInfoFromTableWithAIUseCaseV6,
},
{
provide: UseCaseType.REQUEST_AI_SETTINGS_AND_WIDGETS_CREATION,
useClass: RequestAISettingsAndWidgetsCreationUseCase,
Expand All @@ -37,6 +42,7 @@ export class AIModule implements NestModule {
.apply(AuthMiddleware)
.forRoutes(
{ path: '/ai/v2/request/:connectionId', method: RequestMethod.POST },
{ path: '/ai/v3/request/:connectionId', method: RequestMethod.POST },
{ path: '/ai/v2/setup/:connectionId', method: RequestMethod.GET },
);
}
Expand Down
Loading
Loading