@wabot-dev/framework 0.1.0-beta.30 → 0.1.0-beta.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,117 @@
1
+ import { Logger } from '../../../core/logger/Logger.js';
2
+ import { Anthropic } from '@anthropic-ai/sdk';
3
+
4
+ class ClaudeChatAdapter {
5
+ anthropic;
6
+ logger = new Logger('wabot:claude-chat-adapter');
7
+ constructor() {
8
+ const apiKey = process.env.CLAUDE_API_KEY;
9
+ if (!apiKey) {
10
+ throw new Error('CLAUDE_API_KEY env variable is required');
11
+ }
12
+ this.anthropic = new Anthropic({ apiKey });
13
+ }
14
+ async nextItem(req) {
15
+ const tools = req.tools.map((x) => this.mapTool(x));
16
+ const messages = this.mapChatItems(req.prevItems);
17
+ const request = {
18
+ model: req.model,
19
+ max_tokens: 4096,
20
+ system: req.systemPrompt,
21
+ messages,
22
+ tools: tools.length > 0 ? tools : undefined,
23
+ };
24
+ this.logger.debug(`Call Claude API with Request: ${JSON.stringify(request)}`);
25
+ const response = await this.anthropic.messages.create(request);
26
+ return this.mapResponse(response);
27
+ }
28
+ mapChatItems(chatItems) {
29
+ const messages = [];
30
+ for (const chatItem of chatItems) {
31
+ switch (chatItem.type) {
32
+ case 'humanMessage':
33
+ messages.push(this.mapHumanMessage(chatItem.humanMessage));
34
+ break;
35
+ case 'botMessage':
36
+ messages.push(this.mapBotMessage(chatItem.botMessage));
37
+ break;
38
+ case 'functionCall':
39
+ messages.push(...this.mapFunctionCall(chatItem.functionCall));
40
+ break;
41
+ }
42
+ }
43
+ return messages;
44
+ }
45
+ mapHumanMessage(item) {
46
+ if (!item.text) {
47
+ throw new Error('User message content is empty');
48
+ }
49
+ return { role: 'user', content: item.text };
50
+ }
51
+ mapBotMessage(item) {
52
+ if (!item.text) {
53
+ throw new Error('Assistant message content is empty');
54
+ }
55
+ return { role: 'assistant', content: item.text };
56
+ }
57
+ mapFunctionCall(item) {
58
+ return [
59
+ {
60
+ role: 'assistant',
61
+ content: [
62
+ {
63
+ type: 'tool_use',
64
+ id: item.id,
65
+ name: item.name,
66
+ input: JSON.parse(item.arguments || '{}'),
67
+ },
68
+ ],
69
+ },
70
+ {
71
+ role: 'user',
72
+ content: [
73
+ {
74
+ type: 'tool_result',
75
+ tool_use_id: item.id,
76
+ content: item.result || 'No result',
77
+ },
78
+ ],
79
+ },
80
+ ];
81
+ }
82
+ mapTool(tool) {
83
+ return {
84
+ name: tool.name,
85
+ description: tool.description,
86
+ input_schema: {
87
+ type: 'object',
88
+ properties: tool.parameters.reduce((prev, param) => ({
89
+ ...prev,
90
+ [param.name]: { type: param.type, description: param.description },
91
+ }), {}),
92
+ required: tool.parameters.map((param) => param.name),
93
+ },
94
+ };
95
+ }
96
+ mapResponse(response) {
97
+ const content = response.content[0];
98
+ if (content.type === 'text') {
99
+ return { type: 'botMessage', botMessage: { text: content.text } };
100
+ }
101
+ else if (content.type === 'tool_use') {
102
+ return {
103
+ type: 'functionCall',
104
+ functionCall: {
105
+ id: content.id,
106
+ name: content.name,
107
+ arguments: JSON.stringify(content.input),
108
+ },
109
+ };
110
+ }
111
+ else {
112
+ throw new Error('Not supported Claude Response');
113
+ }
114
+ }
115
+ }
116
+
117
+ export { ClaudeChatAdapter };
@@ -0,0 +1,125 @@
1
+ import { Logger } from '../../../core/logger/Logger.js';
2
+ import { OpenAI } from 'openai';
3
+
4
+ class DeepSeekChatAdapter {
5
+ deepSeek;
6
+ logger = new Logger('wabot:deepseek-chat-adapter');
7
+ constructor() {
8
+ const apiKey = process.env.DEEPSEEK_API_KEY;
9
+ const baseURL = process.env.DEEPSEEK_BASE_URL;
10
+ if (!apiKey) {
11
+ throw new Error('DEEPSEEK_API_KEY env variable is required');
12
+ }
13
+ if (!baseURL) {
14
+ throw new Error('DEEPSEEK_BASE_URL env variable is required');
15
+ }
16
+ this.deepSeek = new OpenAI({
17
+ apiKey,
18
+ baseURL,
19
+ });
20
+ }
21
+ async nextItem(req) {
22
+ const deepSeekInput = [];
23
+ deepSeekInput.push({ role: 'system', content: req.systemPrompt });
24
+ deepSeekInput.push(...this.mapChatItems(req.prevItems));
25
+ const tools = req.tools.map((x) => this.mapTool(x));
26
+ const response = await this.deepSeek.chat.completions.create({
27
+ model: req.model,
28
+ messages: deepSeekInput,
29
+ tools,
30
+ tool_choice: 'auto',
31
+ });
32
+ return this.mapResponse(response);
33
+ }
34
+ mapChatItems(chatItems) {
35
+ const deepSeekInput = [];
36
+ for (const chatItem of chatItems) {
37
+ switch (chatItem.type) {
38
+ case 'humanMessage':
39
+ deepSeekInput.push(this.mapHumanMessage(chatItem.humanMessage));
40
+ break;
41
+ case 'botMessage':
42
+ deepSeekInput.push(this.mapBotMessage(chatItem.botMessage));
43
+ break;
44
+ case 'functionCall':
45
+ deepSeekInput.push(...this.mapFunctionCall(chatItem.functionCall));
46
+ break;
47
+ }
48
+ }
49
+ return deepSeekInput;
50
+ }
51
+ mapHumanMessage(item) {
52
+ if (!item.text) {
53
+ throw new Error('User message content is empty');
54
+ }
55
+ return { role: 'user', content: item.text };
56
+ }
57
+ mapBotMessage(item) {
58
+ if (!item.text) {
59
+ throw new Error('Assistant message content is empty');
60
+ }
61
+ return { role: 'assistant', content: item.text };
62
+ }
63
+ mapFunctionCall(item) {
64
+ return [
65
+ {
66
+ role: 'assistant',
67
+ tool_calls: [
68
+ {
69
+ id: item.id,
70
+ type: 'function',
71
+ function: {
72
+ name: item.name,
73
+ arguments: item.arguments || '{}',
74
+ },
75
+ },
76
+ ],
77
+ },
78
+ {
79
+ role: 'tool',
80
+ tool_call_id: item.id,
81
+ content: item.result ?? 'No result',
82
+ },
83
+ ];
84
+ }
85
+ mapTool(tool) {
86
+ return {
87
+ type: 'function',
88
+ function: {
89
+ name: tool.name,
90
+ description: tool.description,
91
+ parameters: {
92
+ type: 'object',
93
+ properties: tool.parameters.reduce((prev, param) => ({
94
+ ...prev,
95
+ [param.name]: { type: param.type, description: param.description },
96
+ }), {}),
97
+ required: tool.parameters.map((param) => param.name),
98
+ additionalProperties: false,
99
+ },
100
+ strict: true,
101
+ },
102
+ };
103
+ }
104
+ mapResponse(response) {
105
+ const { tool_calls: responseFunctionCall, content: responseText } = response.choices?.[0]?.message ?? {};
106
+ if (responseText) {
107
+ return { type: 'botMessage', botMessage: { text: responseText } };
108
+ }
109
+ else if (responseFunctionCall && responseFunctionCall[0]?.type === 'function') {
110
+ return {
111
+ type: 'functionCall',
112
+ functionCall: {
113
+ id: responseFunctionCall[0].id,
114
+ name: responseFunctionCall[0].function.name,
115
+ arguments: responseFunctionCall[0].function.arguments,
116
+ },
117
+ };
118
+ }
119
+ else {
120
+ throw new Error('Not supported DeepSeek Response');
121
+ }
122
+ }
123
+ }
124
+
125
+ export { DeepSeekChatAdapter };
@@ -1,9 +1,9 @@
1
1
  import { __decorate, __metadata } from 'tslib';
2
2
  import { Logger } from '../../../core/logger/Logger.js';
3
3
  import { WhatsAppReceiver } from './WhatsAppReceiver.js';
4
- import { singleton } from 'tsyringe';
5
4
  import { WabotDevConnection } from './WabotDevConnection.js';
6
5
  import { devListentEvent } from './WabotDevSocketContracts.js';
6
+ import { singleton } from '../../../core/injection/index.js';
7
7
 
8
8
  let WhatsAppReceiverByDevConnection = class WhatsAppReceiverByDevConnection extends WhatsAppReceiver {
9
9
  wabotDevConnection;
@@ -1,9 +1,9 @@
1
1
  import { __decorate, __metadata } from 'tslib';
2
2
  import { Logger } from '../../../core/logger/Logger.js';
3
3
  import { WhatsAppReceiver } from './WhatsAppReceiver.js';
4
- import { singleton } from 'tsyringe';
5
4
  import { ExpressProvider } from '../../../feature/express/ExpressProvider.js';
6
5
  import { WhatsAppRepository } from './WhatsAppRepository.js';
6
+ import { singleton } from '../../../core/injection/index.js';
7
7
 
8
8
  let WhatsAppReceiverByWebHook = class WhatsAppReceiverByWebHook extends WhatsAppReceiver {
9
9
  expressProvider;
@@ -1,5 +1,5 @@
1
1
  import { __decorate, __metadata } from 'tslib';
2
- import { singleton } from 'tsyringe';
2
+ import { singleton } from '../injection/index.js';
3
3
 
4
4
  let Env = class Env {
5
5
  envType;
@@ -1,9 +1,9 @@
1
1
  import { __decorate, __metadata } from 'tslib';
2
2
  import { HttpServerProvider } from '../http/HttpServerProvider.js';
3
3
  import express from 'express';
4
- import { singleton } from 'tsyringe';
5
4
  import bodyParser from 'body-parser';
6
5
  import { Logger } from '../../core/logger/Logger.js';
6
+ import { singleton } from '../../core/injection/index.js';
7
7
 
8
8
  let ExpressProvider = class ExpressProvider {
9
9
  httpServerProvider;
@@ -1,7 +1,7 @@
1
1
  import { __decorate } from 'tslib';
2
+ import { singleton } from '../../core/injection/index.js';
2
3
  import { Logger } from '../../core/logger/Logger.js';
3
4
  import { Server } from 'http';
4
- import { singleton } from 'tsyringe';
5
5
 
6
6
  let HttpServerProvider = class HttpServerProvider {
7
7
  server = null;
@@ -1,8 +1,8 @@
1
1
  import { __decorate, __metadata } from 'tslib';
2
+ import { singleton } from '../../core/injection/index.js';
2
3
  import { Logger } from '../../core/logger/Logger.js';
3
4
  import { HttpServerProvider } from '../http/HttpServerProvider.js';
4
5
  import { Server } from 'socket.io';
5
- import { singleton } from 'tsyringe';
6
6
 
7
7
  let SocketServerProvider = class SocketServerProvider {
8
8
  httpServerProvider;
@@ -794,10 +794,30 @@ declare class PgJobRepository extends PgCrudRepository<Job> implements IJobRepos
794
794
  constructor(pool: Pool);
795
795
  }
796
796
 
797
- declare class DummyClaudeChatBotAdapter {
797
+ declare class ClaudeChatAdapter implements IChatAdapter {
798
+ private anthropic;
799
+ private logger;
800
+ constructor();
801
+ nextItem(req: IChatAdapterNextItemReq): Promise<IChatItem>;
802
+ private mapChatItems;
803
+ private mapHumanMessage;
804
+ private mapBotMessage;
805
+ private mapFunctionCall;
806
+ private mapTool;
807
+ private mapResponse;
798
808
  }
799
809
 
800
- declare class DummyDeepSeekChatBotAdapter {
810
+ declare class DeepSeekChatAdapter implements IChatAdapter {
811
+ private deepSeek;
812
+ private logger;
813
+ constructor();
814
+ nextItem(req: IChatAdapterNextItemReq): Promise<IChatItem>;
815
+ private mapChatItems;
816
+ private mapHumanMessage;
817
+ private mapBotMessage;
818
+ private mapFunctionCall;
819
+ private mapTool;
820
+ private mapResponse;
801
821
  }
802
822
 
803
823
  declare class OpenaiChatAdapter implements IChatAdapter {
@@ -1259,4 +1279,4 @@ interface IValidateMaxOptions {
1259
1279
  }
1260
1280
  declare function validateMax(value: any, options: IValidateMaxOptions): IValidationResult<any>;
1261
1281
 
1262
- export { Async, Auth, Chat, ChatAdapter, ChatBot, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, CmdChannel, Command, CommandMetadataStore, Container, ControllerMetadataStore, CustomError, DummyClaudeChatBotAdapter, DummyDeepSeekChatBotAdapter, Entity, Env, EnvWhatsAppRepository, ExpressProvider, HtmlModule, HttpServerProvider, type IArrayValidationError, type IArrayValidationResult, type IBotMessageItem, type IChannelMessage, type IChannelMetadata, type IChatAdapter, type IChatAdapterNextItemReq, type IChatBot, type IChatBotMetadata, type IChatChannel, type IChatConnection, type IChatControllerMetadata, type IChatData, type IChatItem, type IChatItemData, type IChatItemType, type IChatMemory, type IChatMessage, type IChatRepository, type IChatType, type ICommandConfig, type ICommandHandler, type ICommandHandlerConfig, type IConstructor, type ICrudRepository, type ICustomErrorData, type IEndPointMetadata, type IEntityData, type IEnvType, type IFunctionCall, type IFunctionCallItem, type IGetConfig, type IGetWhatsAppTemplateRequest, type IHtmlModuleOptions, type IHumanMessageItem, type IJobData, type IJobEvent, type IJobEventListener, type IJobRepository, type IJwtRefreshTokenData, type IListenWhatsAppMessageRequest, type IMessageContext, type IMessageMetadata, type IMiddleware, type IMiddlewareMetadata, type IMindset, type IMindsetDecoration, type IMindsetFunctionConfig, type IMindsetFunctionDecoration, type IMindsetFunctionMetadata, type IMindsetFunctionParamMetadata, type IMindsetIdentity, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleDecoration, type IMindsetModuleMetadata, type IMindsetTool, type IMindsetToolParameter, type IModelValidationError, type IModelValidationResult, type IModelValidatorsInfo, type IParamConfig, type IParamDecoration, type IPersistentData, type IPgRepositoryConfig, type IPostConfig, type IPrimitive, type IPropertyValidatorInfo, type IReceivedMessage, type IRestControllerConfig, type IRestControllerMetadata, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type ISocketChannelConfig, type ISocketChannelReceivedMessage, type IStorableData, type ITelegramChannelConfig, type IValidateArrayOptions, type IValidateArrayOptionsWithItemsValidators, type IValidateMaxOptions, type IValidateMinOptions, type IValidationError, type IValidationResult, type IValidator, type IValidatorMetadata, type IWhatsAppBusinessAccount, type IWhatsAppBusinessNumber, type IWhatsAppContact, type IWhatsAppData, type IWhatsAppMessage, type IWhatsAppMessageListener, type IWhatsAppRepository, type IWhatsAppSenderOptions, type IWhatsAppTemplate, type IWhatsAppTemplateComponent, type IWhatsAppTemplateMessage, type IWhatsAppTemplateParameter, type IWhatsAppTemplateResponse, type IWhatsAppWebhookPayload, type IWhatsappChannelConfig, type IchatControllerConfig, Job, JobRepository, JobRunner, JobsEventsHub, Jwt, JwtAccessAndRefreshTokenDto, JwtConfig, JwtGuardMiddleware, JwtRefreshToken, JwtRefreshTokenRepository, JwtSigner, JwtTokenDto, Lifecycle, Logger, MINDSET_DECORATION_MINDSET, MINDSET_FUNCTION_DECORATION_FUNCTION, MINDSET_MODULE_DECORATION_MODULE, Mapper, Mindset, MindsetMetadataStore, MindsetOperator, OpenaiChatAdapter, PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM, Persistent, PgChatMemory, PgChatRepository, PgCrudRepository, PgJobRepository, PgRepositoryBase, PgWhatsAppRepository, RamChatMemory, RamChatRepository, Random, RestControllerMetadataStore, SocketChannel, SocketChannelConfig, SocketServerProvider, Storable, TelegramChannel, TelegramChannelConfig, ValidationMetadataStore, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByDevConnection, WhatsAppReceiverByWebHook, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByDevConnection, WhatsappChannelConfig, chatBot, chatController, chatItemTypeOptions, cmd, command, commandHandler, container, get, inject, injectable, isArray, isBoolean, isDate, isModel, isNotEmpty, isNumber, isOptional, isPresent, isString, jwtGuard, max, middleware, min, mindset, mindsetFunction, mindsetModule, modelInfo, param, post, restController, runAsyncCommandHandlers, runChatControllers, runRestControllers, scoped, singleton, socket, telegram, validate, validateArray, validateIsBoolean, validateIsDate, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsString, validateMax, validateMin, validateModel, whatsapp };
1282
+ export { Async, Auth, Chat, ChatAdapter, ChatBot, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, ClaudeChatAdapter, CmdChannel, Command, CommandMetadataStore, Container, ControllerMetadataStore, CustomError, DeepSeekChatAdapter, Entity, Env, EnvWhatsAppRepository, ExpressProvider, HtmlModule, HttpServerProvider, type IArrayValidationError, type IArrayValidationResult, type IBotMessageItem, type IChannelMessage, type IChannelMetadata, type IChatAdapter, type IChatAdapterNextItemReq, type IChatBot, type IChatBotMetadata, type IChatChannel, type IChatConnection, type IChatControllerMetadata, type IChatData, type IChatItem, type IChatItemData, type IChatItemType, type IChatMemory, type IChatMessage, type IChatRepository, type IChatType, type ICommandConfig, type ICommandHandler, type ICommandHandlerConfig, type IConstructor, type ICrudRepository, type ICustomErrorData, type IEndPointMetadata, type IEntityData, type IEnvType, type IFunctionCall, type IFunctionCallItem, type IGetConfig, type IGetWhatsAppTemplateRequest, type IHtmlModuleOptions, type IHumanMessageItem, type IJobData, type IJobEvent, type IJobEventListener, type IJobRepository, type IJwtRefreshTokenData, type IListenWhatsAppMessageRequest, type IMessageContext, type IMessageMetadata, type IMiddleware, type IMiddlewareMetadata, type IMindset, type IMindsetDecoration, type IMindsetFunctionConfig, type IMindsetFunctionDecoration, type IMindsetFunctionMetadata, type IMindsetFunctionParamMetadata, type IMindsetIdentity, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleDecoration, type IMindsetModuleMetadata, type IMindsetTool, type IMindsetToolParameter, type IModelValidationError, type IModelValidationResult, type IModelValidatorsInfo, type IParamConfig, type IParamDecoration, type IPersistentData, type IPgRepositoryConfig, type IPostConfig, type IPrimitive, type IPropertyValidatorInfo, type IReceivedMessage, type IRestControllerConfig, type IRestControllerMetadata, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type ISocketChannelConfig, type ISocketChannelReceivedMessage, type IStorableData, type ITelegramChannelConfig, type IValidateArrayOptions, type IValidateArrayOptionsWithItemsValidators, type IValidateMaxOptions, type IValidateMinOptions, type IValidationError, type IValidationResult, type IValidator, type IValidatorMetadata, type IWhatsAppBusinessAccount, type IWhatsAppBusinessNumber, type IWhatsAppContact, type IWhatsAppData, type IWhatsAppMessage, type IWhatsAppMessageListener, type IWhatsAppRepository, type IWhatsAppSenderOptions, type IWhatsAppTemplate, type IWhatsAppTemplateComponent, type IWhatsAppTemplateMessage, type IWhatsAppTemplateParameter, type IWhatsAppTemplateResponse, type IWhatsAppWebhookPayload, type IWhatsappChannelConfig, type IchatControllerConfig, Job, JobRepository, JobRunner, JobsEventsHub, Jwt, JwtAccessAndRefreshTokenDto, JwtConfig, JwtGuardMiddleware, JwtRefreshToken, JwtRefreshTokenRepository, JwtSigner, JwtTokenDto, Lifecycle, Logger, MINDSET_DECORATION_MINDSET, MINDSET_FUNCTION_DECORATION_FUNCTION, MINDSET_MODULE_DECORATION_MODULE, Mapper, Mindset, MindsetMetadataStore, MindsetOperator, OpenaiChatAdapter, PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM, Persistent, PgChatMemory, PgChatRepository, PgCrudRepository, PgJobRepository, PgRepositoryBase, PgWhatsAppRepository, RamChatMemory, RamChatRepository, Random, RestControllerMetadataStore, SocketChannel, SocketChannelConfig, SocketServerProvider, Storable, TelegramChannel, TelegramChannelConfig, ValidationMetadataStore, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByDevConnection, WhatsAppReceiverByWebHook, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByDevConnection, WhatsappChannelConfig, chatBot, chatController, chatItemTypeOptions, cmd, command, commandHandler, container, get, inject, injectable, isArray, isBoolean, isDate, isModel, isNotEmpty, isNumber, isOptional, isPresent, isString, jwtGuard, max, middleware, min, mindset, mindsetFunction, mindsetModule, modelInfo, param, post, restController, runAsyncCommandHandlers, runChatControllers, runRestControllers, scoped, singleton, socket, telegram, validate, validateArray, validateIsBoolean, validateIsDate, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsString, validateMax, validateMin, validateModel, whatsapp };
package/dist/src/index.js CHANGED
@@ -59,8 +59,8 @@ export { runRestControllers } from './feature/rest-controller/runRestControllers
59
59
  export { Auth } from './feature/rest-controller/auth/Auth.js';
60
60
  export { SocketServerProvider } from './feature/socket/SocketServerProvider.js';
61
61
  export { PgJobRepository } from './addon/async/pg/PgJobRepository.js';
62
- export { DummyClaudeChatBotAdapter } from './addon/chat-bot/claude/ClaudeChatBotAdapter.js';
63
- export { DummyDeepSeekChatBotAdapter } from './addon/chat-bot/deepseek/DeepSeekChatBotAdapter.js';
62
+ export { ClaudeChatAdapter } from './addon/chat-bot/claude/ClaudeChatAdapter.js';
63
+ export { DeepSeekChatAdapter } from './addon/chat-bot/deepseek/DeepSeekChatAdapter.js';
64
64
  export { OpenaiChatAdapter } from './addon/chat-bot/openia/OpenaiChatAdapter.js';
65
65
  export { PgChatRepository } from './addon/chat-bot/pg/PgChatRepository.js';
66
66
  export { PgChatMemory } from './addon/chat-bot/pg/PgChatMemory.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wabot-dev/framework",
3
- "version": "0.1.0-beta.30",
3
+ "version": "0.1.0-beta.32",
4
4
  "description": "Framework for IA Chat Bots",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",
@@ -1,107 +0,0 @@
1
- // import { injectable } from '@/injection'
2
- // import { Anthropic } from '@anthropic-ai/sdk'
3
- // import { ChatBotAdapter } from '@/chatbot'
4
- // import type { ChatItem } from '@/core'
5
- // import { MindsetOperator } from '@/mindset'
6
- // import { Logger } from '@/logger'
7
- class DummyClaudeChatBotAdapter {
8
- }
9
- // @injectable()
10
- // export class ClaudeChatBotAdapter extends ChatBotAdapter {
11
- // private anthropic: Anthropic
12
- // private model: string
13
- // private logger = new Logger('wabot:claude-chat-bot-adapter')
14
- // constructor(mindset: MindsetOperator) {
15
- // super(mindset)
16
- // const apiKey = process.env.CLAUDE_API_KEY
17
- // if (!apiKey) {
18
- // throw new Error(`CLAUDE_API_KEY env variable is required`)
19
- // }
20
- // const model = process.env.CLAUDE_CHAT_MODEL
21
- // if (!model) {
22
- // throw new Error(`CLAUDE_CHAT_MODEL env variable is required`)
23
- // }
24
- // this.anthropic = new Anthropic({ apiKey })
25
- // this.model = model
26
- // }
27
- // override async generateNextChatItem(chatItems: ChatItem[]): Promise<ChatItem> {
28
- // const systemPrompt = await this.systemPrompt()
29
- // const tools = (await this.mindset.allFunctionsDescriptors()).map((fn) => {
30
- // return {
31
- // name: fn.name,
32
- // description: fn.description,
33
- // input_schema: {
34
- // ...fn.parameters,
35
- // type: 'object' as const
36
- // }
37
- // }
38
- // })
39
- // const messages = this.mapChatItems(chatItems)
40
- // const request = {
41
- // model: this.model,
42
- // max_tokens: 4096,
43
- // system: systemPrompt,
44
- // messages,
45
- // tools: tools.length > 0 ? tools : undefined,
46
- // }
47
- // this.logger.debug(`Call Claude API with Request: ${JSON.stringify(request)}`)
48
- // const response = await this.anthropic.messages.create(request)
49
- // let newChatItem: ChatItem
50
- // const content = response.content[0]
51
- // if (content.type === 'text') {
52
- // newChatItem = await this.buildBotMessageItem(content.text)
53
- // } else if (content.type === 'tool_use') {
54
- // newChatItem = await this.buildFunctionCallItem(
55
- // content.id,
56
- // content.name,
57
- // JSON.stringify(content.input),
58
- // )
59
- // } else {
60
- // throw new Error('Not supported Claude Response')
61
- // }
62
- // return newChatItem
63
- // }
64
- // private mapChatItems(chatItems: ChatItem[]): Anthropic.Messages.MessageParam[] {
65
- // // const messages: Anthropic.Messages.MessageParam[] = []
66
- // // for (const item of chatItems) {
67
- // // const itemData = item.getData()
68
- // // if (itemData.type === 'CONNECTION_MESSAGE') {
69
- // // if (!itemData.content.text) {
70
- // // throw new Error('User message content is empty')
71
- // // }
72
- // // messages.push({ role: 'user', content: itemData.content.text })
73
- // // } else if (itemData.type === 'BOT_MESSAGE') {
74
- // // if (!itemData.content.text) {
75
- // // throw new Error('Assistant message content is empty')
76
- // // }
77
- // // messages.push({ role: 'assistant', content: itemData.content.text })
78
- // // } else if (itemData.type === 'FUNCTION_CALL') {
79
- // // messages.push({
80
- // // role: 'assistant',
81
- // // content: [
82
- // // {
83
- // // type: 'tool_use',
84
- // // id: itemData.content.id,
85
- // // name: itemData.content.name,
86
- // // input: JSON.parse(itemData.content.arguments || '{}')
87
- // // }
88
- // // ]
89
- // // })
90
- // // messages.push({
91
- // // role: 'user',
92
- // // content: [
93
- // // {
94
- // // type: 'tool_result',
95
- // // tool_use_id: itemData.content.id,
96
- // // content: itemData.content.result || 'No result'
97
- // // }
98
- // // ]
99
- // // })
100
- // // }
101
- // // }
102
- // // return messages
103
- // return []
104
- // }
105
- // }
106
-
107
- export { DummyClaudeChatBotAdapter };
@@ -1,103 +0,0 @@
1
- // import { injectable } from '@/injection'
2
- // import { OpenAI } from 'openai'
3
- // import { ChatBotAdapter } from '@/chatbot'
4
- // import type { ChatItem } from '@/core'
5
- // import { MindsetOperator } from '@/mindset'
6
- class DummyDeepSeekChatBotAdapter {
7
- }
8
- // @injectable()
9
- // export class DeepSeekChatBotAdapter extends ChatBotAdapter {
10
- // private deepSeek: OpenAI
11
- // private model: string
12
- // constructor(mindset: MindsetOperator) {
13
- // super(mindset)
14
- // const model = process.env.DEEPSEEK_CHAT_MODEL
15
- // const apiKey = process.env.DEEPSEEK_API_KEY
16
- // const baseURL = process.env.DEEPSEEK_BASE_URL
17
- // this.validateEnvVariables([model, apiKey, baseURL])
18
- // this.model = model || 'deepseek-chat'
19
- // this.deepSeek = new OpenAI({
20
- // apiKey: apiKey,
21
- // baseURL: baseURL,
22
- // })
23
- // }
24
- // validateEnvVariables(envVariables: (string | undefined)[]): void {
25
- // envVariables.forEach((envVariable) => {
26
- // if (!envVariable) {
27
- // throw new Error('Missing environment variable')
28
- // }
29
- // })
30
- // }
31
- // override async generateNextChatItem(chatItems: ChatItem[]): Promise<ChatItem> {
32
- // const systemPrompt = await this.systemPrompt()
33
- // const tools = (await this.mindset.allFunctionsDescriptors()).map((fn) => {
34
- // const parameters = { ...fn.parameters, additionalProperties: false, type: 'object' }
35
- // return {
36
- // type: 'function',
37
- // function: { name: fn.name, description: fn.description, parameters, strict: true },
38
- // } as const
39
- // })
40
- // const response = await this.deepSeek.chat.completions.create({
41
- // model: this.model,
42
- // messages: [{ role: 'system', content: systemPrompt }, ...this.mapChatItems(chatItems)],
43
- // tools: tools,
44
- // tool_choice: 'auto',
45
- // })
46
- // let newChatItem: ChatItem
47
- // const { tool_calls: responseFunctionCall, content: responseText } =
48
- // response.choices?.[0]?.message ?? {}
49
- // if (responseText) {
50
- // newChatItem = await this.buildBotMessageItem(responseText)
51
- // } else if (responseFunctionCall && responseFunctionCall[0]?.type == 'function') {
52
- // newChatItem = await this.buildFunctionCallItem(
53
- // responseFunctionCall[0].id,
54
- // responseFunctionCall[0].function.name,
55
- // responseFunctionCall[0].function.arguments,
56
- // )
57
- // } else {
58
- // throw new Error('Not supported DeepSeek Response')
59
- // }
60
- // return newChatItem
61
- // }
62
- // private mapChatItems(chatItems: ChatItem[]): OpenAI.Chat.ChatCompletionMessageParam[] {
63
- // // const deepSeekInput: OpenAI.Chat.ChatCompletionMessageParam[] = []
64
- // // for (const item of chatItems) {
65
- // // const itemData = item.getData()
66
- // // if (itemData.type === 'CONNECTION_MESSAGE') {
67
- // // if (!itemData.content.text) {
68
- // // throw new Error('System message content is empty')
69
- // // }
70
- // // deepSeekInput.push({ role: 'user', content: itemData.content.text })
71
- // // } else if (itemData.type === 'BOT_MESSAGE') {
72
- // // if (!itemData.content.text) {
73
- // // throw new Error('System message content is empty')
74
- // // }
75
- // // deepSeekInput.push({ role: 'assistant', content: itemData.content.text })
76
- // // }
77
- // // if (itemData.type === 'FUNCTION_CALL') {
78
- // // deepSeekInput.push({
79
- // // role: 'assistant',
80
- // // tool_calls: [
81
- // // {
82
- // // id: itemData.content.id,
83
- // // type: 'function',
84
- // // function: {
85
- // // name: itemData.content.name,
86
- // // arguments: JSON.stringify(itemData.content.arguments),
87
- // // },
88
- // // },
89
- // // ],
90
- // // })
91
- // // deepSeekInput.push({
92
- // // role: 'tool',
93
- // // tool_call_id: itemData.content.id,
94
- // // content: itemData.content.result ?? 'No result',
95
- // // })
96
- // // }
97
- // // }
98
- // // return deepSeekInput
99
- // return []
100
- // }
101
- // }
102
-
103
- export { DummyDeepSeekChatBotAdapter };