@wrcb/cb-common 1.0.888 → 1.0.890

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.
@@ -1,5 +1,5 @@
1
1
  import { Subjects } from '../subjects';
2
- export type AIProvider = 'openai' | 'cerebras';
2
+ export type AIProvider = 'openai' | 'cerebras' | 'openrouter';
3
3
  export type AIRequestType = 'chat' | 'tts' | 'transcribe' | 'image-generate' | 'image-edit' | 'embeddings';
4
4
  export interface AIRequestMadeEvent {
5
5
  subject: Subjects.AIRequestMade;
@@ -67,11 +67,14 @@ export declare class AIClient {
67
67
  private readonly service;
68
68
  private readonly openaiApiKey;
69
69
  private readonly cerebrasApiKey?;
70
+ private readonly openrouterApiKey?;
70
71
  private _openai?;
71
72
  private _cerebras?;
72
- constructor(natsClient: Stan, service: string, openaiApiKey: string, cerebrasApiKey?: string | undefined);
73
+ private _openrouter?;
74
+ constructor(natsClient: Stan, service: string, openaiApiKey: string, cerebrasApiKey?: string | undefined, openrouterApiKey?: string | undefined);
73
75
  private get openai();
74
76
  private get cerebras();
77
+ private get openrouter();
75
78
  private emit;
76
79
  chat(params: ChatParams): Promise<ChatResult>;
77
80
  /**
@@ -49,6 +49,9 @@ const COST_PER_1K = {
49
49
  // embeddings — cobrados só na entrada (USD por 1K tokens)
50
50
  'text-embedding-3-small': { input: 0.00002, output: 0 },
51
51
  'text-embedding-3-large': { input: 0.00013, output: 0 },
52
+ // OpenRouter. Preço do próprio provedor upstream (DeepSeek), sem markup do
53
+ // OpenRouter — conferir de novo se a rota upstream mudar.
54
+ 'deepseek/deepseek-chat-v3-0324': { input: 0.00025, output: 0.001 },
52
55
  };
53
56
  function calcCost(model, promptTokens, completionTokens) {
54
57
  var _a;
@@ -83,11 +86,12 @@ function summarizeMessages(messages) {
83
86
  .slice(0, 500);
84
87
  }
85
88
  class AIClient {
86
- constructor(natsClient, service, openaiApiKey, cerebrasApiKey) {
89
+ constructor(natsClient, service, openaiApiKey, cerebrasApiKey, openrouterApiKey) {
87
90
  this.natsClient = natsClient;
88
91
  this.service = service;
89
92
  this.openaiApiKey = openaiApiKey;
90
93
  this.cerebrasApiKey = cerebrasApiKey;
94
+ this.openrouterApiKey = openrouterApiKey;
91
95
  }
92
96
  get openai() {
93
97
  if (!this._openai)
@@ -100,6 +104,22 @@ class AIClient {
100
104
  this._cerebras = new openai_1.default({ apiKey: (_a = this.cerebrasApiKey) !== null && _a !== void 0 ? _a : '', baseURL: 'https://api.cerebras.ai/v1' });
101
105
  return this._cerebras;
102
106
  }
107
+ get openrouter() {
108
+ var _a;
109
+ if (!this._openrouter) {
110
+ this._openrouter = new openai_1.default({
111
+ apiKey: (_a = this.openrouterApiKey) !== null && _a !== void 0 ? _a : '',
112
+ baseURL: 'https://openrouter.ai/api/v1',
113
+ // Recomendados pelo OpenRouter para identificar quem está chamando —
114
+ // não afetam a resposta, só aparecem no painel deles.
115
+ defaultHeaders: {
116
+ 'HTTP-Referer': 'https://www.privateshow.com.br',
117
+ 'X-Title': 'PrivateShow CRM'
118
+ }
119
+ });
120
+ }
121
+ return this._openrouter;
122
+ }
103
123
  emit(data) {
104
124
  return __awaiter(this, void 0, void 0, function* () {
105
125
  try {
@@ -131,7 +151,11 @@ class AIClient {
131
151
  return __awaiter(this, void 0, void 0, function* () {
132
152
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
133
153
  const { provider, model, messages, maxTokens, temperature, responseFormat, tools, toolChoice, account } = params;
134
- const client = provider === 'cerebras' ? this.cerebras : this.openai;
154
+ const client = provider === 'cerebras'
155
+ ? this.cerebras
156
+ : provider === 'openrouter'
157
+ ? this.openrouter
158
+ : this.openai;
135
159
  const requestedAt = new Date().toISOString();
136
160
  const t0 = Date.now();
137
161
  const promptSummary = summarizeMessages(messages);
@@ -275,4 +275,15 @@ export interface CrmPublicPersona {
275
275
  agentId: string;
276
276
  name: string;
277
277
  publicTag: string | null;
278
+ /**
279
+ * A linha curta do card: idade, cidade, o que quiser. Texto livre, escrito
280
+ * no painel.
281
+ *
282
+ * Está aqui e não no site pela mesma razão do `name`: trocar a descrição de
283
+ * uma persona não pode exigir deploy. E NÃO é o `systemPrompt` — este é
284
+ * para o visitante ler, aquele é a receita do negócio e nunca sai do CRM.
285
+ */
286
+ publicHeadline: string | null;
287
+ /** Duas ou três frases, para o mesmo card. */
288
+ publicBio: string | null;
278
289
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wrcb/cb-common",
3
- "version": "1.0.888",
3
+ "version": "1.0.890",
4
4
  "description": "Common resources between services",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",