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

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.
@@ -94,12 +94,13 @@ class ClaudeChatAdapter {
94
94
  };
95
95
  }
96
96
  mapResponse(response) {
97
+ let chatItem;
97
98
  const content = response.content[0];
98
99
  if (content.type === 'text') {
99
- return { type: 'botMessage', botMessage: { text: content.text } };
100
+ chatItem = { type: 'botMessage', botMessage: { text: content.text } };
100
101
  }
101
102
  else if (content.type === 'tool_use') {
102
- return {
103
+ chatItem = {
103
104
  type: 'functionCall',
104
105
  functionCall: {
105
106
  id: content.id,
@@ -111,6 +112,17 @@ class ClaudeChatAdapter {
111
112
  else {
112
113
  throw new Error('Not supported Claude Response');
113
114
  }
115
+ let usage;
116
+ if (response.usage) {
117
+ usage = {
118
+ inputTokens: response.usage.input_tokens,
119
+ outputTokens: response.usage.output_tokens,
120
+ };
121
+ }
122
+ else {
123
+ throw new Error('Unable to found usage info');
124
+ }
125
+ return { chatItem, usage };
114
126
  }
115
127
  }
116
128
 
@@ -102,12 +102,13 @@ class DeepSeekChatAdapter {
102
102
  };
103
103
  }
104
104
  mapResponse(response) {
105
+ let chatItem;
105
106
  const { tool_calls: responseFunctionCall, content: responseText } = response.choices?.[0]?.message ?? {};
106
107
  if (responseText) {
107
- return { type: 'botMessage', botMessage: { text: responseText } };
108
+ chatItem = { type: 'botMessage', botMessage: { text: responseText } };
108
109
  }
109
110
  else if (responseFunctionCall && responseFunctionCall[0]?.type === 'function') {
110
- return {
111
+ chatItem = {
111
112
  type: 'functionCall',
112
113
  functionCall: {
113
114
  id: responseFunctionCall[0].id,
@@ -119,6 +120,17 @@ class DeepSeekChatAdapter {
119
120
  else {
120
121
  throw new Error('Not supported DeepSeek Response');
121
122
  }
123
+ let usage;
124
+ if (response.usage) {
125
+ usage = {
126
+ inputTokens: response.usage.prompt_tokens,
127
+ outputTokens: response.usage.completion_tokens,
128
+ };
129
+ }
130
+ else {
131
+ throw new Error('Unable to found usage info');
132
+ }
133
+ return { chatItem, usage };
122
134
  }
123
135
  }
124
136
 
@@ -77,12 +77,12 @@ class OpenaiChatAdapter {
77
77
  };
78
78
  }
79
79
  mapResponse(response) {
80
- let newItem;
80
+ let chatItem;
81
81
  if (response.output_text) {
82
- newItem = { type: 'botMessage', botMessage: { text: response.output_text } };
82
+ chatItem = { type: 'botMessage', botMessage: { text: response.output_text } };
83
83
  }
84
84
  else if (response.output && response.output[0]?.type == 'function_call') {
85
- newItem = {
85
+ chatItem = {
86
86
  type: 'functionCall',
87
87
  functionCall: {
88
88
  id: response.output[0].call_id,
@@ -94,7 +94,17 @@ class OpenaiChatAdapter {
94
94
  else {
95
95
  throw new Error('Not supported OpenIA Response');
96
96
  }
97
- return newItem;
97
+ let usage;
98
+ if (response.usage) {
99
+ usage = {
100
+ inputTokens: response.usage.input_tokens,
101
+ outputTokens: response.usage.output_tokens,
102
+ };
103
+ }
104
+ else {
105
+ throw new Error('Unable to found usage info');
106
+ }
107
+ return { chatItem, usage };
98
108
  }
99
109
  }
100
110
 
@@ -1,6 +1,6 @@
1
1
  class ChatAdapter {
2
2
  nextItem(req) {
3
- throw new Error("Method not implemented.");
3
+ throw new Error('Method not implemented.');
4
4
  }
5
5
  }
6
6
 
@@ -28,7 +28,7 @@ class ChatBot {
28
28
  }
29
29
  const systemPrompt = await this.mindset.systemPrompt();
30
30
  const tools = this.mindset.tools();
31
- const newItemData = await this.adapter.nextItem({
31
+ const { chatItem: newItemData } = await this.adapter.nextItem({
32
32
  model: 'gpt',
33
33
  systemPrompt,
34
34
  tools,
@@ -514,18 +514,27 @@ type IFunctionCallItem = {
514
514
  type IChatItem = IBotMessageItem | IHumanMessageItem | IFunctionCallItem;
515
515
  type IChatItemType = (typeof chatItemTypeOptions)[number];
516
516
 
517
+ interface ILanguageModelUsage {
518
+ inputTokens: number;
519
+ outputTokens: number;
520
+ }
521
+
517
522
  interface IChatAdapterNextItemReq {
518
523
  model: string;
519
524
  systemPrompt: string;
520
525
  tools: IMindsetTool[];
521
526
  prevItems: IChatItem[];
522
527
  }
528
+ interface IChatAdapterNextItemRes {
529
+ chatItem: IChatItem;
530
+ usage: ILanguageModelUsage;
531
+ }
523
532
  interface IChatAdapter {
524
- nextItem(req: IChatAdapterNextItemReq): Promise<IChatItem>;
533
+ nextItem(req: IChatAdapterNextItemReq): Promise<IChatAdapterNextItemRes>;
525
534
  }
526
535
 
527
536
  declare class ChatAdapter implements IChatAdapter {
528
- nextItem(req: IChatAdapterNextItemReq): Promise<IChatItem>;
537
+ nextItem(req: IChatAdapterNextItemReq): Promise<IChatAdapterNextItemRes>;
529
538
  }
530
539
 
531
540
  type IChatItemData = IEntityData & IChatItem;
@@ -798,7 +807,7 @@ declare class ClaudeChatAdapter implements IChatAdapter {
798
807
  private anthropic;
799
808
  private logger;
800
809
  constructor();
801
- nextItem(req: IChatAdapterNextItemReq): Promise<IChatItem>;
810
+ nextItem(req: IChatAdapterNextItemReq): Promise<IChatAdapterNextItemRes>;
802
811
  private mapChatItems;
803
812
  private mapHumanMessage;
804
813
  private mapBotMessage;
@@ -811,7 +820,7 @@ declare class DeepSeekChatAdapter implements IChatAdapter {
811
820
  private deepSeek;
812
821
  private logger;
813
822
  constructor();
814
- nextItem(req: IChatAdapterNextItemReq): Promise<IChatItem>;
823
+ nextItem(req: IChatAdapterNextItemReq): Promise<IChatAdapterNextItemRes>;
815
824
  private mapChatItems;
816
825
  private mapHumanMessage;
817
826
  private mapBotMessage;
@@ -823,7 +832,7 @@ declare class DeepSeekChatAdapter implements IChatAdapter {
823
832
  declare class OpenaiChatAdapter implements IChatAdapter {
824
833
  private openai;
825
834
  private logger;
826
- nextItem(req: IChatAdapterNextItemReq): Promise<IChatItem>;
835
+ nextItem(req: IChatAdapterNextItemReq): Promise<IChatAdapterNextItemRes>;
827
836
  private mapChatItems;
828
837
  private mapConectionMessage;
829
838
  private mapBotMessage;
@@ -1279,4 +1288,4 @@ interface IValidateMaxOptions {
1279
1288
  }
1280
1289
  declare function validateMax(value: any, options: IValidateMaxOptions): IValidationResult<any>;
1281
1290
 
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 };
1291
+ 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 IChatAdapterNextItemRes, 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 ILanguageModelUsage, 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wabot-dev/framework",
3
- "version": "0.1.0-beta.32",
3
+ "version": "0.1.0-beta.33",
4
4
  "description": "Framework for IA Chat Bots",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",