@wabot-dev/framework 0.1.0-beta.43 → 0.1.0-beta.44

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.
@@ -76,6 +76,7 @@ let OpenaiChatAdapter = class OpenaiChatAdapter {
76
76
  required: tool.parameters.map((param) => param.name),
77
77
  },
78
78
  strict: true,
79
+ additionalProperties: false,
79
80
  };
80
81
  }
81
82
  mapResponse(response) {
@@ -1,4 +1,5 @@
1
1
  import { PgCrudRepository } from '../../repository/pg/PgCrudRepository.js';
2
+ import '../../../feature/chat-bot/ChatBot.js';
2
3
  import { ChatItem } from '../../../feature/chat-bot/ChatItem.js';
3
4
  import '../../../core/injection/index.js';
4
5
  import 'uuid';
@@ -4,6 +4,7 @@ import { PgChatMemory } from './PgChatMemory.js';
4
4
  import { singleton } from '../../../core/injection/index.js';
5
5
  import { PgCrudRepository } from '../../repository/pg/PgCrudRepository.js';
6
6
  import { Chat } from '../../../feature/chat-bot/Chat.js';
7
+ import '../../../feature/chat-bot/ChatBot.js';
7
8
  import 'uuid';
8
9
  import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
9
10
 
@@ -0,0 +1,41 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { Env } from '../../../core/env/Env.js';
3
+ import { CustomError } from '../../../core/error/CustomError.js';
4
+ import { singleton } from '../../../core/injection/index.js';
5
+ import { Logger } from '../../../core/logger/Logger.js';
6
+
7
+ let WabotChatAdapter = class WabotChatAdapter {
8
+ apiKey;
9
+ baseUrl;
10
+ logger = new Logger('wabot:wabot-chat-adapter');
11
+ constructor(env) {
12
+ this.apiKey = env.requireString('WABOT_API_KEY');
13
+ this.baseUrl = env.requireString('WABOT_LLM_URL');
14
+ while (this.baseUrl.endsWith('/')) {
15
+ this.baseUrl = this.baseUrl.substring(0, this.baseUrl.length - 1);
16
+ }
17
+ }
18
+ async nextItem(req) {
19
+ const response = await fetch(this.baseUrl + '/chat-bot/next-item', {
20
+ method: 'post',
21
+ headers: {
22
+ Authorization: `Bearer ${this.apiKey}`,
23
+ 'Content-Type': 'application/json',
24
+ },
25
+ body: JSON.stringify(req),
26
+ });
27
+ const data = await response.json();
28
+ if (!response.ok) {
29
+ throw new CustomError({
30
+ message: (data?.error && JSON.stringify(data.error)) ?? 'error calling wabot llm api',
31
+ });
32
+ }
33
+ return data;
34
+ }
35
+ };
36
+ WabotChatAdapter = __decorate([
37
+ singleton(),
38
+ __metadata("design:paramtypes", [Env])
39
+ ], WabotChatAdapter);
40
+
41
+ export { WabotChatAdapter };
@@ -1,6 +1,7 @@
1
1
  import { container } from '../../../core/injection/index.js';
2
2
  import { ControllerMetadataStore } from '../../../feature/chat-controller/metadata/ControllerMetadataStore.js';
3
3
  import '../../../feature/chat-controller/ChatResolver.js';
4
+ import '../../../feature/chat-bot/ChatBot.js';
4
5
  import 'uuid';
5
6
  import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
6
7
  import 'reflect-metadata';
@@ -1,6 +1,7 @@
1
1
  import { container } from '../../../core/injection/index.js';
2
2
  import { ControllerMetadataStore } from '../../../feature/chat-controller/metadata/ControllerMetadataStore.js';
3
3
  import '../../../feature/chat-controller/ChatResolver.js';
4
+ import '../../../feature/chat-bot/ChatBot.js';
4
5
  import 'uuid';
5
6
  import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
6
7
  import 'reflect-metadata';
@@ -1,6 +1,7 @@
1
1
  import { container } from '../../../core/injection/index.js';
2
2
  import { ControllerMetadataStore } from '../../../feature/chat-controller/metadata/ControllerMetadataStore.js';
3
3
  import '../../../feature/chat-controller/ChatResolver.js';
4
+ import '../../../feature/chat-bot/ChatBot.js';
4
5
  import 'uuid';
5
6
  import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
6
7
  import 'reflect-metadata';
@@ -2,6 +2,7 @@ import { container } from '../../../core/injection/index.js';
2
2
  import { WhatsappChannelConfig } from './WhatsAppChannelConfig.js';
3
3
  import { ControllerMetadataStore } from '../../../feature/chat-controller/metadata/ControllerMetadataStore.js';
4
4
  import '../../../feature/chat-controller/ChatResolver.js';
5
+ import '../../../feature/chat-bot/ChatBot.js';
5
6
  import 'uuid';
6
7
  import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
7
8
  import 'reflect-metadata';
@@ -1,3 +1,4 @@
1
+ import '../../../feature/chat-bot/ChatBot.js';
1
2
  import { ChatItem } from '../../../feature/chat-bot/ChatItem.js';
2
3
  import '../../../core/injection/index.js';
3
4
  import 'uuid';
@@ -4,6 +4,7 @@ import { WhatsAppSender } from './WhatsAppSender.js';
4
4
  import { singleton } from '../../../core/injection/index.js';
5
5
  import '../../../feature/chat-controller/metadata/ControllerMetadataStore.js';
6
6
  import { ChatResolver } from '../../../feature/chat-controller/ChatResolver.js';
7
+ import '../../../feature/chat-bot/ChatBot.js';
7
8
  import { ChatRepository } from '../../../feature/chat-bot/ChatRepository.js';
8
9
  import 'uuid';
9
10
  import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
@@ -3,6 +3,7 @@ import { WhatsAppSender } from './WhatsAppSender.js';
3
3
  import { singleton } from '../../../core/injection/index.js';
4
4
  import '../../../feature/chat-controller/metadata/ControllerMetadataStore.js';
5
5
  import { ChatResolver } from '../../../feature/chat-controller/ChatResolver.js';
6
+ import '../../../feature/chat-bot/ChatBot.js';
6
7
  import { ChatRepository } from '../../../feature/chat-bot/ChatRepository.js';
7
8
  import 'uuid';
8
9
  import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
@@ -1,6 +1,13 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import 'reflect-metadata';
3
+ import { injectable } from '../../core/injection/index.js';
4
+ import '../mindset/metadata/MindsetMetadataStore.js';
5
+ import { MindsetOperator } from '../mindset/MindsetOperator.js';
6
+ import { ChatAdapter } from './ChatAdapter.js';
1
7
  import { ChatItem } from './ChatItem.js';
8
+ import { ChatMemory } from './ChatMemory.js';
2
9
 
3
- class ChatBot {
10
+ let ChatBot = class ChatBot {
4
11
  memory;
5
12
  adapter;
6
13
  mindset;
@@ -28,8 +35,14 @@ class ChatBot {
28
35
  }
29
36
  const systemPrompt = await this.mindset.systemPrompt();
30
37
  const tools = this.mindset.tools();
38
+ const llms = await this.mindset.llms();
39
+ if (llms.length === 0) {
40
+ throw new Error(`Invalid ${this.mindset.constructor.name} - llms not found`);
41
+ }
42
+ const llm = llms[0];
31
43
  const { chatItem: newItemData } = await this.adapter.nextItem({
32
- model: 'gpt',
44
+ model: llm.model,
45
+ provider: llm.provider,
33
46
  systemPrompt,
34
47
  tools,
35
48
  prevItems: prevItems.map((x) => x.getData()),
@@ -45,6 +58,12 @@ class ChatBot {
45
58
  }
46
59
  this.processLoop(callback);
47
60
  }
48
- }
61
+ };
62
+ ChatBot = __decorate([
63
+ injectable(),
64
+ __metadata("design:paramtypes", [ChatMemory,
65
+ ChatAdapter,
66
+ MindsetOperator])
67
+ ], ChatBot);
49
68
 
50
69
  export { ChatBot };
@@ -1,5 +1,6 @@
1
1
  import { __decorate, __metadata } from 'tslib';
2
2
  import { Chat } from '../chat-bot/Chat.js';
3
+ import '../chat-bot/ChatBot.js';
3
4
  import { ChatRepository } from '../chat-bot/ChatRepository.js';
4
5
  import { injectable } from '../../core/injection/index.js';
5
6
  import 'uuid';
@@ -8,6 +8,9 @@ class Mindset {
8
8
  limits() {
9
9
  throw new Error('Method not implemented.');
10
10
  }
11
+ llms() {
12
+ throw new Error('Method not implemented.');
13
+ }
11
14
  }
12
15
 
13
16
  export { Mindset };
@@ -22,6 +22,9 @@ let MindsetOperator = class MindsetOperator {
22
22
  limits() {
23
23
  return this.mindset.limits();
24
24
  }
25
+ llms() {
26
+ return this.mindset.llms();
27
+ }
25
28
  async systemPrompt() {
26
29
  let [identity, skills, limits] = await Promise.all([
27
30
  this.identity(),
@@ -370,15 +370,21 @@ interface IMindsetIdentity {
370
370
  personality?: string;
371
371
  emotions?: string;
372
372
  }
373
+ interface IMindsetLlm {
374
+ provider?: string;
375
+ model: string;
376
+ }
373
377
  interface IMindset {
374
378
  identity(): Promise<IMindsetIdentity>;
375
379
  skills(): Promise<string>;
376
380
  limits(): Promise<string>;
381
+ llms(): Promise<IMindsetLlm[]>;
377
382
  }
378
383
  declare class Mindset implements IMindset {
379
384
  identity(): Promise<IMindsetIdentity>;
380
385
  skills(): Promise<string>;
381
386
  limits(): Promise<string>;
387
+ llms(): Promise<IMindsetLlm[]>;
382
388
  }
383
389
 
384
390
  interface IMindsetConfig {
@@ -487,6 +493,7 @@ declare class MindsetOperator implements IMindset {
487
493
  identity(): Promise<IMindsetIdentity>;
488
494
  skills(): Promise<string>;
489
495
  limits(): Promise<string>;
496
+ llms(): Promise<IMindsetLlm[]>;
490
497
  systemPrompt(): Promise<string>;
491
498
  tools(): IMindsetTool[];
492
499
  protected tool(fn: IMindsetFunctionMetadata, module: IMindsetModuleMetadata): IMindsetTool;
@@ -543,7 +550,9 @@ interface IChatAdapter {
543
550
  }
544
551
 
545
552
  declare class ChatAdapter implements IChatAdapter {
546
- nextItem(req: IChatAdapterNextItemReq): Promise<IChatAdapterNextItemRes>;
553
+ nextItem(req: IChatAdapterNextItemReq & {
554
+ provider?: string;
555
+ }): Promise<IChatAdapterNextItemRes>;
547
556
  }
548
557
 
549
558
  type IChatItemData = IEntityData & IChatItem;
@@ -910,6 +919,14 @@ declare class RamChatRepository implements IChatRepository {
910
919
  private getMemory;
911
920
  }
912
921
 
922
+ declare class WabotChatAdapter implements IChatAdapter {
923
+ private apiKey;
924
+ private baseUrl;
925
+ private logger;
926
+ constructor(env: Env);
927
+ nextItem(req: IChatAdapterNextItemReq): Promise<IChatAdapterNextItemRes>;
928
+ }
929
+
913
930
  declare function cmd(): (target: object, propertyKey: string | symbol) => void;
914
931
 
915
932
  declare class CmdChannel implements IChatChannel {
@@ -1334,4 +1351,4 @@ declare class MoneyDto {
1334
1351
  currency: string;
1335
1352
  }
1336
1353
 
1337
- export { AnthropicChatAdapter, Async, Auth, Chat, ChatAdapter, ChatBot, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, CmdChannel, Command, CommandMetadataStore, Container, ControllerMetadataStore, CustomError, DeepSeekChatAdapter, EXPRESS_REQ, EXPRESS_RES, Entity, Env, EnvWhatsAppRepository, ExpressProvider, GoogleChatAdapter, 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 IEndPointConfig, type IEndPointMetadata, type IEntityData, type IEnvType, type IFunctionCall, type IFunctionCallItem, 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 IMoneyData, type IParamConfig, type IParamDecoration, type IPersistentData, type IPgRepositoryConfig, 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, Money, MoneyDto, 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 };
1354
+ export { AnthropicChatAdapter, Async, Auth, Chat, ChatAdapter, ChatBot, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, CmdChannel, Command, CommandMetadataStore, Container, ControllerMetadataStore, CustomError, DeepSeekChatAdapter, EXPRESS_REQ, EXPRESS_RES, Entity, Env, EnvWhatsAppRepository, ExpressProvider, GoogleChatAdapter, 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 IEndPointConfig, type IEndPointMetadata, type IEntityData, type IEnvType, type IFunctionCall, type IFunctionCallItem, 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 IMindsetLlm, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleDecoration, type IMindsetModuleMetadata, type IMindsetTool, type IMindsetToolParameter, type IModelValidationError, type IModelValidationResult, type IModelValidatorsInfo, type IMoneyData, type IParamConfig, type IParamDecoration, type IPersistentData, type IPgRepositoryConfig, 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, Money, MoneyDto, 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, WabotChatAdapter, 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
@@ -69,6 +69,7 @@ export { PgChatRepository } from './addon/chat-bot/pg/PgChatRepository.js';
69
69
  export { PgChatMemory } from './addon/chat-bot/pg/PgChatMemory.js';
70
70
  export { RamChatMemory } from './addon/chat-bot/ram/RamChatMemory.js';
71
71
  export { RamChatRepository } from './addon/chat-bot/ram/RamChatRepository.js';
72
+ export { WabotChatAdapter } from './addon/chat-bot/wabot/WabotChatAdapter.js';
72
73
  export { cmd } from './addon/chat-controller/cmd/@cmd.js';
73
74
  export { CmdChannel } from './addon/chat-controller/cmd/CmdChannel.js';
74
75
  export { socket } from './addon/chat-controller/socket/@socket.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wabot-dev/framework",
3
- "version": "0.1.0-beta.43",
3
+ "version": "0.1.0-beta.44",
4
4
  "description": "Framework for IA Chat Bots",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",
@@ -16,7 +16,7 @@
16
16
  "fmt": "prettier --write .",
17
17
  "fmt:check": "prettier --check .",
18
18
  "types:check": "tsc --noEmit",
19
- "elia:dev": "yts --import ./env.mjs ./test/elia/runElia.ts"
19
+ "elia:dev": "yts --import ./env.mjs ./test/elia/run.ts"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@rollup/plugin-alias": "5.1.1",