portal-aiatende-api 0.2.0 → 0.3.0
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.
- package/dist/index.d.mts +13 -2
- package/dist/index.d.ts +13 -2
- package/dist/index.js +27 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.d.mts
CHANGED
|
@@ -288,12 +288,23 @@ declare class ClientsResource extends BaseResource {
|
|
|
288
288
|
getByWazzupChannelId(channelId: string): Promise<Client | null>;
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
+
/** Uma mensagem simplificada do histórico da conversa, enviada pro Portal reescrever a
|
|
292
|
+
* pergunta de acompanhamento como consulta autônoma antes de gerar o embedding. */
|
|
293
|
+
interface ConversationHistoryMessage {
|
|
294
|
+
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
295
|
+
content: string;
|
|
296
|
+
}
|
|
291
297
|
interface GetInternalContextParams {
|
|
292
298
|
/** Id do AiConfig do cliente — o Portal usa a `apiKey` configurada nele pra gerar o embedding da pergunta. */
|
|
293
299
|
aiConfigId: string;
|
|
294
300
|
/** Pergunta em texto puro do usuário. O embedding é gerado internamente pelo Portal (RagService.getEmbedding), não pelo chamador. */
|
|
295
301
|
question: string;
|
|
296
|
-
|
|
302
|
+
/** Últimas mensagens da conversa (mais antiga → mais recente), sem incluir `question`. Quando
|
|
303
|
+
* presente e não vazio, o Portal reescreve `question` como uma consulta autônoma (LLM rewrite)
|
|
304
|
+
* antes de buscar na base de conhecimento — melhora o recall em perguntas de acompanhamento
|
|
305
|
+
* (ex.: "e o azul?"). Omitir ou passar array vazio preserva o comportamento anterior (busca
|
|
306
|
+
* direto pela `question`, sem custo extra). */
|
|
307
|
+
conversationHistory?: ConversationHistoryMessage[];
|
|
297
308
|
}
|
|
298
309
|
interface InternalContextChunk {
|
|
299
310
|
chunkId?: string;
|
|
@@ -324,4 +335,4 @@ declare class PortalApiError extends Error {
|
|
|
324
335
|
constructor(message: string, info?: Partial<PortalApiError>);
|
|
325
336
|
}
|
|
326
337
|
|
|
327
|
-
export { type AiActivationSchedule, type AiConfig, type AiExperiment, type AiExperimentConfig, type AiExperimentCriteria, type AiExperimentVariant, type AiPrompt, type BusinessHours, type CalendarConfig, type Client, type ClientsListResponse, ClientsResource, type DateException, type GetInternalContextParams, type InternalContextChunk, type InternalContextResult, KnowledgeResource, type KommoAccount, type KommoConfig, type LossReasonMapping, type NudgeSettings, type PipelineMapping, PortalApiError, PortalClient, type PortalClientConfig, type StageMapping, type TimeRange, type Wazzup, type WazzupChannel };
|
|
338
|
+
export { type AiActivationSchedule, type AiConfig, type AiExperiment, type AiExperimentConfig, type AiExperimentCriteria, type AiExperimentVariant, type AiPrompt, type BusinessHours, type CalendarConfig, type Client, type ClientsListResponse, ClientsResource, type ConversationHistoryMessage, type DateException, type GetInternalContextParams, type InternalContextChunk, type InternalContextResult, KnowledgeResource, type KommoAccount, type KommoConfig, type LossReasonMapping, type NudgeSettings, type PipelineMapping, PortalApiError, PortalClient, type PortalClientConfig, type StageMapping, type TimeRange, type Wazzup, type WazzupChannel };
|
package/dist/index.d.ts
CHANGED
|
@@ -288,12 +288,23 @@ declare class ClientsResource extends BaseResource {
|
|
|
288
288
|
getByWazzupChannelId(channelId: string): Promise<Client | null>;
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
+
/** Uma mensagem simplificada do histórico da conversa, enviada pro Portal reescrever a
|
|
292
|
+
* pergunta de acompanhamento como consulta autônoma antes de gerar o embedding. */
|
|
293
|
+
interface ConversationHistoryMessage {
|
|
294
|
+
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
295
|
+
content: string;
|
|
296
|
+
}
|
|
291
297
|
interface GetInternalContextParams {
|
|
292
298
|
/** Id do AiConfig do cliente — o Portal usa a `apiKey` configurada nele pra gerar o embedding da pergunta. */
|
|
293
299
|
aiConfigId: string;
|
|
294
300
|
/** Pergunta em texto puro do usuário. O embedding é gerado internamente pelo Portal (RagService.getEmbedding), não pelo chamador. */
|
|
295
301
|
question: string;
|
|
296
|
-
|
|
302
|
+
/** Últimas mensagens da conversa (mais antiga → mais recente), sem incluir `question`. Quando
|
|
303
|
+
* presente e não vazio, o Portal reescreve `question` como uma consulta autônoma (LLM rewrite)
|
|
304
|
+
* antes de buscar na base de conhecimento — melhora o recall em perguntas de acompanhamento
|
|
305
|
+
* (ex.: "e o azul?"). Omitir ou passar array vazio preserva o comportamento anterior (busca
|
|
306
|
+
* direto pela `question`, sem custo extra). */
|
|
307
|
+
conversationHistory?: ConversationHistoryMessage[];
|
|
297
308
|
}
|
|
298
309
|
interface InternalContextChunk {
|
|
299
310
|
chunkId?: string;
|
|
@@ -324,4 +335,4 @@ declare class PortalApiError extends Error {
|
|
|
324
335
|
constructor(message: string, info?: Partial<PortalApiError>);
|
|
325
336
|
}
|
|
326
337
|
|
|
327
|
-
export { type AiActivationSchedule, type AiConfig, type AiExperiment, type AiExperimentConfig, type AiExperimentCriteria, type AiExperimentVariant, type AiPrompt, type BusinessHours, type CalendarConfig, type Client, type ClientsListResponse, ClientsResource, type DateException, type GetInternalContextParams, type InternalContextChunk, type InternalContextResult, KnowledgeResource, type KommoAccount, type KommoConfig, type LossReasonMapping, type NudgeSettings, type PipelineMapping, PortalApiError, PortalClient, type PortalClientConfig, type StageMapping, type TimeRange, type Wazzup, type WazzupChannel };
|
|
338
|
+
export { type AiActivationSchedule, type AiConfig, type AiExperiment, type AiExperimentConfig, type AiExperimentCriteria, type AiExperimentVariant, type AiPrompt, type BusinessHours, type CalendarConfig, type Client, type ClientsListResponse, ClientsResource, type ConversationHistoryMessage, type DateException, type GetInternalContextParams, type InternalContextChunk, type InternalContextResult, KnowledgeResource, type KommoAccount, type KommoConfig, type LossReasonMapping, type NudgeSettings, type PipelineMapping, PortalApiError, PortalClient, type PortalClientConfig, type StageMapping, type TimeRange, type Wazzup, type WazzupChannel };
|
package/dist/index.js
CHANGED
|
@@ -67,17 +67,7 @@ var ClientsResource = class extends BaseResource {
|
|
|
67
67
|
};
|
|
68
68
|
|
|
69
69
|
// src/resources/knowledge/index.ts
|
|
70
|
-
var
|
|
71
|
-
/** Recupera trechos relevantes da base RAG do cliente pra uma pergunta em texto puro (`POST /api/knowledge/internal/context`). O Portal gera o embedding internamente usando a `apiKey` do AiConfig. */
|
|
72
|
-
async getInternalContext(params) {
|
|
73
|
-
const response = await this.client.post("/api/knowledge/internal/context", {
|
|
74
|
-
aiConfigId: params.aiConfigId,
|
|
75
|
-
question: params.question,
|
|
76
|
-
conversationHistory: params.conversationHistory
|
|
77
|
-
});
|
|
78
|
-
return response.data;
|
|
79
|
-
}
|
|
80
|
-
};
|
|
70
|
+
var import_zod = require("zod");
|
|
81
71
|
|
|
82
72
|
// src/errors.ts
|
|
83
73
|
var PortalApiError = class extends Error {
|
|
@@ -93,6 +83,32 @@ var PortalApiError = class extends Error {
|
|
|
93
83
|
}
|
|
94
84
|
};
|
|
95
85
|
|
|
86
|
+
// src/resources/knowledge/index.ts
|
|
87
|
+
var internalContextChunkSchema = import_zod.z.object({
|
|
88
|
+
chunkId: import_zod.z.string().optional(),
|
|
89
|
+
content: import_zod.z.string(),
|
|
90
|
+
similarity: import_zod.z.number(),
|
|
91
|
+
metadata: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional()
|
|
92
|
+
});
|
|
93
|
+
var internalContextResultSchema = import_zod.z.array(internalContextChunkSchema);
|
|
94
|
+
var KnowledgeResource = class extends BaseResource {
|
|
95
|
+
/** Recupera trechos relevantes da base RAG do cliente pra uma pergunta em texto puro (`POST /api/knowledge/internal/context`). O Portal gera o embedding internamente usando a `apiKey` do AiConfig. */
|
|
96
|
+
async getInternalContext(params) {
|
|
97
|
+
const response = await this.client.post("/api/knowledge/internal/context", {
|
|
98
|
+
aiConfigId: params.aiConfigId,
|
|
99
|
+
question: params.question,
|
|
100
|
+
conversationHistory: params.conversationHistory
|
|
101
|
+
});
|
|
102
|
+
const parsed = internalContextResultSchema.safeParse(response.data);
|
|
103
|
+
if (!parsed.success) {
|
|
104
|
+
throw new PortalApiError("Resposta inv\xE1lida de /api/knowledge/internal/context", {
|
|
105
|
+
raw: parsed.error.flatten()
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return parsed.data;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
96
112
|
// src/client.ts
|
|
97
113
|
var DEFAULT_BASE_URL = "https://portal.aiatende.com.br";
|
|
98
114
|
var PortalClient = class {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/client.ts","../src/base.ts","../src/resources/clients/index.ts","../src/resources/knowledge/index.ts","../src/errors.ts"],"sourcesContent":["export * from './client';\nexport * from './types';\nexport * from './errors';\nexport * from './resources/clients';\nexport * from './resources/clients/types';\nexport * from './resources/knowledge';\nexport * from './resources/knowledge/types';\n","import axios, { AxiosInstance } from 'axios';\nimport { PortalClientConfig } from './types';\nimport { ClientsResource } from './resources/clients';\nimport { KnowledgeResource } from './resources/knowledge';\nimport { PortalApiError } from './errors';\n\nconst DEFAULT_BASE_URL = 'https://portal.aiatende.com.br';\n\nexport class PortalClient {\n public config: PortalClientConfig;\n public httpClient: AxiosInstance;\n\n public clients: ClientsResource;\n public knowledge: KnowledgeResource;\n\n constructor(config: PortalClientConfig) {\n this.config = config;\n\n this.httpClient = axios.create({\n baseURL: config.baseUrl || DEFAULT_BASE_URL,\n headers: {\n 'Content-Type': 'application/json',\n 'x-api-key': config.apiKey,\n 'x-internal-token': config.apiKey\n }\n });\n\n this.httpClient.interceptors.response.use(\n (response) => response,\n (error) => {\n if (error.response) {\n const errData = error.response.data;\n throw new PortalApiError(errData?.error || 'Portal API Error', {\n status: error.response.status,\n raw: errData\n });\n }\n throw error;\n }\n );\n\n this.clients = new ClientsResource(this.httpClient);\n this.knowledge = new KnowledgeResource(this.httpClient);\n }\n}\n","import { AxiosInstance } from 'axios';\n\nexport abstract class BaseResource {\n protected client: AxiosInstance;\n\n constructor(client: AxiosInstance) {\n this.client = client;\n }\n}\n","import { BaseResource } from '../../base';\nimport { Client, ClientsListResponse } from './types';\n\nexport class ClientsResource extends BaseResource {\n /** Busca o Client dono de um subdomínio Kommo (`GET /api/clients?kommo_subdomain=...`). */\n async getByKommoSubdomain(subdomain: string): Promise<Client | null> {\n const response = await this.client.get<ClientsListResponse>('/api/clients', {\n params: { kommo_subdomain: subdomain, includeConfigs: true }\n });\n return response.data.data[0] ?? null;\n }\n\n /** Busca o Client dono de um canal Wazzup (`GET /api/clients?channelId=...`). */\n async getByWazzupChannelId(channelId: string): Promise<Client | null> {\n const response = await this.client.get<ClientsListResponse>('/api/clients', {\n params: { channelId, includeConfigs: true }\n });\n return response.data.data[0] ?? null;\n }\n}\n","import { BaseResource } from '../../base';\nimport { GetInternalContextParams, InternalContextResult } from './types';\n\nexport class KnowledgeResource extends BaseResource {\n /** Recupera trechos relevantes da base RAG do cliente pra uma pergunta em texto puro (`POST /api/knowledge/internal/context`). O Portal gera o embedding internamente usando a `apiKey` do AiConfig. */\n async getInternalContext(params: GetInternalContextParams): Promise<InternalContextResult> {\n const response = await this.client.post<
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/client.ts","../src/base.ts","../src/resources/clients/index.ts","../src/resources/knowledge/index.ts","../src/errors.ts"],"sourcesContent":["export * from './client';\nexport * from './types';\nexport * from './errors';\nexport * from './resources/clients';\nexport * from './resources/clients/types';\nexport * from './resources/knowledge';\nexport * from './resources/knowledge/types';\n","import axios, { AxiosInstance } from 'axios';\nimport { PortalClientConfig } from './types';\nimport { ClientsResource } from './resources/clients';\nimport { KnowledgeResource } from './resources/knowledge';\nimport { PortalApiError } from './errors';\n\nconst DEFAULT_BASE_URL = 'https://portal.aiatende.com.br';\n\nexport class PortalClient {\n public config: PortalClientConfig;\n public httpClient: AxiosInstance;\n\n public clients: ClientsResource;\n public knowledge: KnowledgeResource;\n\n constructor(config: PortalClientConfig) {\n this.config = config;\n\n this.httpClient = axios.create({\n baseURL: config.baseUrl || DEFAULT_BASE_URL,\n headers: {\n 'Content-Type': 'application/json',\n 'x-api-key': config.apiKey,\n 'x-internal-token': config.apiKey\n }\n });\n\n this.httpClient.interceptors.response.use(\n (response) => response,\n (error) => {\n if (error.response) {\n const errData = error.response.data;\n throw new PortalApiError(errData?.error || 'Portal API Error', {\n status: error.response.status,\n raw: errData\n });\n }\n throw error;\n }\n );\n\n this.clients = new ClientsResource(this.httpClient);\n this.knowledge = new KnowledgeResource(this.httpClient);\n }\n}\n","import { AxiosInstance } from 'axios';\n\nexport abstract class BaseResource {\n protected client: AxiosInstance;\n\n constructor(client: AxiosInstance) {\n this.client = client;\n }\n}\n","import { BaseResource } from '../../base';\nimport { Client, ClientsListResponse } from './types';\n\nexport class ClientsResource extends BaseResource {\n /** Busca o Client dono de um subdomínio Kommo (`GET /api/clients?kommo_subdomain=...`). */\n async getByKommoSubdomain(subdomain: string): Promise<Client | null> {\n const response = await this.client.get<ClientsListResponse>('/api/clients', {\n params: { kommo_subdomain: subdomain, includeConfigs: true }\n });\n return response.data.data[0] ?? null;\n }\n\n /** Busca o Client dono de um canal Wazzup (`GET /api/clients?channelId=...`). */\n async getByWazzupChannelId(channelId: string): Promise<Client | null> {\n const response = await this.client.get<ClientsListResponse>('/api/clients', {\n params: { channelId, includeConfigs: true }\n });\n return response.data.data[0] ?? null;\n }\n}\n","import { z } from 'zod';\nimport { BaseResource } from '../../base';\nimport { PortalApiError } from '../../errors';\nimport { GetInternalContextParams, InternalContextResult } from './types';\n\nconst internalContextChunkSchema = z.object({\n chunkId: z.string().optional(),\n content: z.string(),\n similarity: z.number(),\n metadata: z.record(z.string(), z.unknown()).optional(),\n});\n\nconst internalContextResultSchema = z.array(internalContextChunkSchema);\n\nexport class KnowledgeResource extends BaseResource {\n /** Recupera trechos relevantes da base RAG do cliente pra uma pergunta em texto puro (`POST /api/knowledge/internal/context`). O Portal gera o embedding internamente usando a `apiKey` do AiConfig. */\n async getInternalContext(params: GetInternalContextParams): Promise<InternalContextResult> {\n const response = await this.client.post<unknown>('/api/knowledge/internal/context', {\n aiConfigId: params.aiConfigId,\n question: params.question,\n conversationHistory: params.conversationHistory\n });\n\n const parsed = internalContextResultSchema.safeParse(response.data);\n if (!parsed.success) {\n throw new PortalApiError('Resposta inválida de /api/knowledge/internal/context', {\n raw: parsed.error.flatten(),\n });\n }\n return parsed.data;\n }\n}\n","export class PortalApiError extends Error {\n status?: number;\n raw?: unknown;\n\n constructor(message: string, info?: Partial<PortalApiError>) {\n super(message);\n this.name = 'PortalApiError';\n\n if (info) {\n this.status = info.status;\n this.raw = info.raw;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAqC;;;ACE9B,IAAe,eAAf,MAA4B;AAAA,EACvB;AAAA,EAEV,YAAY,QAAuB;AACjC,SAAK,SAAS;AAAA,EAChB;AACF;;;ACLO,IAAM,kBAAN,cAA8B,aAAa;AAAA;AAAA,EAEhD,MAAM,oBAAoB,WAA2C;AACnE,UAAM,WAAW,MAAM,KAAK,OAAO,IAAyB,gBAAgB;AAAA,MAC1E,QAAQ,EAAE,iBAAiB,WAAW,gBAAgB,KAAK;AAAA,IAC7D,CAAC;AACD,WAAO,SAAS,KAAK,KAAK,CAAC,KAAK;AAAA,EAClC;AAAA;AAAA,EAGA,MAAM,qBAAqB,WAA2C;AACpE,UAAM,WAAW,MAAM,KAAK,OAAO,IAAyB,gBAAgB;AAAA,MAC1E,QAAQ,EAAE,WAAW,gBAAgB,KAAK;AAAA,IAC5C,CAAC;AACD,WAAO,SAAS,KAAK,KAAK,CAAC,KAAK;AAAA,EAClC;AACF;;;ACnBA,iBAAkB;;;ACAX,IAAM,iBAAN,cAA6B,MAAM;AAAA,EACxC;AAAA,EACA;AAAA,EAEA,YAAY,SAAiB,MAAgC;AA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AAI,MAAM,UAAU;AAClB,gBAAM,UAAU,MAAM,SAAS;AAC/B,gBAAM,IAAI,eAAe,SAAS,SAAS,oBAAoB;AAAA,YAC7D,QAAQ,MAAM,SAAS;AAAA,YACvB,KAAK;AAAA,UACP,CAAC;AAAA,QACH;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAEA,SAAK,UAAU,IAAI,gBAAgB,KAAK,UAAU;AAClD,SAAK,YAAY,IAAI,kBAAkB,KAAK,UAAU;AAAA,EACxD;AACF;","names":["axios"]}
|
package/dist/index.mjs
CHANGED
|
@@ -28,17 +28,7 @@ var ClientsResource = class extends BaseResource {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
// src/resources/knowledge/index.ts
|
|
31
|
-
|
|
32
|
-
/** Recupera trechos relevantes da base RAG do cliente pra uma pergunta em texto puro (`POST /api/knowledge/internal/context`). O Portal gera o embedding internamente usando a `apiKey` do AiConfig. */
|
|
33
|
-
async getInternalContext(params) {
|
|
34
|
-
const response = await this.client.post("/api/knowledge/internal/context", {
|
|
35
|
-
aiConfigId: params.aiConfigId,
|
|
36
|
-
question: params.question,
|
|
37
|
-
conversationHistory: params.conversationHistory
|
|
38
|
-
});
|
|
39
|
-
return response.data;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
31
|
+
import { z } from "zod";
|
|
42
32
|
|
|
43
33
|
// src/errors.ts
|
|
44
34
|
var PortalApiError = class extends Error {
|
|
@@ -54,6 +44,32 @@ var PortalApiError = class extends Error {
|
|
|
54
44
|
}
|
|
55
45
|
};
|
|
56
46
|
|
|
47
|
+
// src/resources/knowledge/index.ts
|
|
48
|
+
var internalContextChunkSchema = z.object({
|
|
49
|
+
chunkId: z.string().optional(),
|
|
50
|
+
content: z.string(),
|
|
51
|
+
similarity: z.number(),
|
|
52
|
+
metadata: z.record(z.string(), z.unknown()).optional()
|
|
53
|
+
});
|
|
54
|
+
var internalContextResultSchema = z.array(internalContextChunkSchema);
|
|
55
|
+
var KnowledgeResource = class extends BaseResource {
|
|
56
|
+
/** Recupera trechos relevantes da base RAG do cliente pra uma pergunta em texto puro (`POST /api/knowledge/internal/context`). O Portal gera o embedding internamente usando a `apiKey` do AiConfig. */
|
|
57
|
+
async getInternalContext(params) {
|
|
58
|
+
const response = await this.client.post("/api/knowledge/internal/context", {
|
|
59
|
+
aiConfigId: params.aiConfigId,
|
|
60
|
+
question: params.question,
|
|
61
|
+
conversationHistory: params.conversationHistory
|
|
62
|
+
});
|
|
63
|
+
const parsed = internalContextResultSchema.safeParse(response.data);
|
|
64
|
+
if (!parsed.success) {
|
|
65
|
+
throw new PortalApiError("Resposta inv\xE1lida de /api/knowledge/internal/context", {
|
|
66
|
+
raw: parsed.error.flatten()
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return parsed.data;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
57
73
|
// src/client.ts
|
|
58
74
|
var DEFAULT_BASE_URL = "https://portal.aiatende.com.br";
|
|
59
75
|
var PortalClient = class {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts","../src/base.ts","../src/resources/clients/index.ts","../src/resources/knowledge/index.ts","../src/errors.ts"],"sourcesContent":["import axios, { AxiosInstance } from 'axios';\nimport { PortalClientConfig } from './types';\nimport { ClientsResource } from './resources/clients';\nimport { KnowledgeResource } from './resources/knowledge';\nimport { PortalApiError } from './errors';\n\nconst DEFAULT_BASE_URL = 'https://portal.aiatende.com.br';\n\nexport class PortalClient {\n public config: PortalClientConfig;\n public httpClient: AxiosInstance;\n\n public clients: ClientsResource;\n public knowledge: KnowledgeResource;\n\n constructor(config: PortalClientConfig) {\n this.config = config;\n\n this.httpClient = axios.create({\n baseURL: config.baseUrl || DEFAULT_BASE_URL,\n headers: {\n 'Content-Type': 'application/json',\n 'x-api-key': config.apiKey,\n 'x-internal-token': config.apiKey\n }\n });\n\n this.httpClient.interceptors.response.use(\n (response) => response,\n (error) => {\n if (error.response) {\n const errData = error.response.data;\n throw new PortalApiError(errData?.error || 'Portal API Error', {\n status: error.response.status,\n raw: errData\n });\n }\n throw error;\n }\n );\n\n this.clients = new ClientsResource(this.httpClient);\n this.knowledge = new KnowledgeResource(this.httpClient);\n }\n}\n","import { AxiosInstance } from 'axios';\n\nexport abstract class BaseResource {\n protected client: AxiosInstance;\n\n constructor(client: AxiosInstance) {\n this.client = client;\n }\n}\n","import { BaseResource } from '../../base';\nimport { Client, ClientsListResponse } from './types';\n\nexport class ClientsResource extends BaseResource {\n /** Busca o Client dono de um subdomínio Kommo (`GET /api/clients?kommo_subdomain=...`). */\n async getByKommoSubdomain(subdomain: string): Promise<Client | null> {\n const response = await this.client.get<ClientsListResponse>('/api/clients', {\n params: { kommo_subdomain: subdomain, includeConfigs: true }\n });\n return response.data.data[0] ?? null;\n }\n\n /** Busca o Client dono de um canal Wazzup (`GET /api/clients?channelId=...`). */\n async getByWazzupChannelId(channelId: string): Promise<Client | null> {\n const response = await this.client.get<ClientsListResponse>('/api/clients', {\n params: { channelId, includeConfigs: true }\n });\n return response.data.data[0] ?? null;\n }\n}\n","import { BaseResource } from '../../base';\nimport { GetInternalContextParams, InternalContextResult } from './types';\n\nexport class KnowledgeResource extends BaseResource {\n /** Recupera trechos relevantes da base RAG do cliente pra uma pergunta em texto puro (`POST /api/knowledge/internal/context`). O Portal gera o embedding internamente usando a `apiKey` do AiConfig. */\n async getInternalContext(params: GetInternalContextParams): Promise<InternalContextResult> {\n const response = await this.client.post<
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/base.ts","../src/resources/clients/index.ts","../src/resources/knowledge/index.ts","../src/errors.ts"],"sourcesContent":["import axios, { AxiosInstance } from 'axios';\nimport { PortalClientConfig } from './types';\nimport { ClientsResource } from './resources/clients';\nimport { KnowledgeResource } from './resources/knowledge';\nimport { PortalApiError } from './errors';\n\nconst DEFAULT_BASE_URL = 'https://portal.aiatende.com.br';\n\nexport class PortalClient {\n public config: PortalClientConfig;\n public httpClient: AxiosInstance;\n\n public clients: ClientsResource;\n public knowledge: KnowledgeResource;\n\n constructor(config: PortalClientConfig) {\n this.config = config;\n\n this.httpClient = axios.create({\n baseURL: config.baseUrl || DEFAULT_BASE_URL,\n headers: {\n 'Content-Type': 'application/json',\n 'x-api-key': config.apiKey,\n 'x-internal-token': config.apiKey\n }\n });\n\n this.httpClient.interceptors.response.use(\n (response) => response,\n (error) => {\n if (error.response) {\n const errData = error.response.data;\n throw new PortalApiError(errData?.error || 'Portal API Error', {\n status: error.response.status,\n raw: errData\n });\n }\n throw error;\n }\n );\n\n this.clients = new ClientsResource(this.httpClient);\n this.knowledge = new KnowledgeResource(this.httpClient);\n }\n}\n","import { AxiosInstance } from 'axios';\n\nexport abstract class BaseResource {\n protected client: AxiosInstance;\n\n constructor(client: AxiosInstance) {\n this.client = client;\n }\n}\n","import { BaseResource } from '../../base';\nimport { Client, ClientsListResponse } from './types';\n\nexport class ClientsResource extends BaseResource {\n /** Busca o Client dono de um subdomínio Kommo (`GET /api/clients?kommo_subdomain=...`). */\n async getByKommoSubdomain(subdomain: string): Promise<Client | null> {\n const response = await this.client.get<ClientsListResponse>('/api/clients', {\n params: { kommo_subdomain: subdomain, includeConfigs: true }\n });\n return response.data.data[0] ?? null;\n }\n\n /** Busca o Client dono de um canal Wazzup (`GET /api/clients?channelId=...`). */\n async getByWazzupChannelId(channelId: string): Promise<Client | null> {\n const response = await this.client.get<ClientsListResponse>('/api/clients', {\n params: { channelId, includeConfigs: true }\n });\n return response.data.data[0] ?? null;\n }\n}\n","import { z } from 'zod';\nimport { BaseResource } from '../../base';\nimport { PortalApiError } from '../../errors';\nimport { GetInternalContextParams, InternalContextResult } from './types';\n\nconst internalContextChunkSchema = z.object({\n chunkId: z.string().optional(),\n content: z.string(),\n similarity: z.number(),\n metadata: z.record(z.string(), z.unknown()).optional(),\n});\n\nconst internalContextResultSchema = z.array(internalContextChunkSchema);\n\nexport class KnowledgeResource extends BaseResource {\n /** Recupera trechos relevantes da base RAG do cliente pra uma pergunta em texto puro (`POST /api/knowledge/internal/context`). O Portal gera o embedding internamente usando a `apiKey` do AiConfig. */\n async getInternalContext(params: GetInternalContextParams): Promise<InternalContextResult> {\n const response = await this.client.post<unknown>('/api/knowledge/internal/context', {\n aiConfigId: params.aiConfigId,\n question: params.question,\n conversationHistory: params.conversationHistory\n });\n\n const parsed = internalContextResultSchema.safeParse(response.data);\n if (!parsed.success) {\n throw new PortalApiError('Resposta inválida de /api/knowledge/internal/context', {\n raw: parsed.error.flatten(),\n });\n }\n return parsed.data;\n }\n}\n","export class PortalApiError extends Error {\n status?: number;\n raw?: unknown;\n\n constructor(message: string, info?: Partial<PortalApiError>) {\n super(message);\n this.name = 'PortalApiError';\n\n if (info) {\n this.status = info.status;\n this.raw = info.raw;\n }\n }\n}\n"],"mappings":";AAAA,OAAO,WAA8B;;;ACE9B,IAAe,eAAf,MAA4B;AAAA,EACvB;AAAA,EAEV,YAAY,QAAuB;AACjC,SAAK,SAAS;AAAA,EAChB;AACF;;;ACLO,IAAM,kBAAN,cAA8B,aAAa;AAAA;AAAA,EAEhD,MAAM,oBAAoB,WAA2C;AACnE,UAAM,WAAW,MAAM,KAAK,OAAO,IAAyB,gBAAgB;AAAA,MAC1E,QAAQ,EAAE,iBAAiB,WAAW,gBAAgB,KAAK;AAAA,IAC7D,CAAC;AACD,WAAO,SAAS,KAAK,KAAK,CAAC,KAAK;AAAA,EAClC;AAAA;AAAA,EAGA,MAAM,qBAAqB,WAA2C;AACpE,UAAM,WAAW,MAAM,KAAK,OAAO,IAAyB,gBAAgB;AAAA,MAC1E,QAAQ,EAAE,WAAW,gBAAgB,KAAK;AAAA,IAC5C,CAAC;AACD,WAAO,SAAS,KAAK,KAAK,CAAC,KAAK;AAAA,EAClC;AACF;;;ACnBA,SAAS,SAAS;;;ACAX,IAAM,iBAAN,cAA6B,MAAM;AAAA,EACxC;AAAA,EACA;AAAA,EAEA,YAAY,SAAiB,MAAgC;AAC3D,UA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U;AAClB,gBAAM,UAAU,MAAM,SAAS;AAC/B,gBAAM,IAAI,eAAe,SAAS,SAAS,oBAAoB;AAAA,YAC7D,QAAQ,MAAM,SAAS;AAAA,YACvB,KAAK;AAAA,UACP,CAAC;AAAA,QACH;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAEA,SAAK,UAAU,IAAI,gBAAgB,KAAK,UAAU;AAClD,SAAK,YAAY,IAAI,kBAAkB,KAAK,UAAU;AAAA,EACxD;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "portal-aiatende-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Cliente TypeScript tipado para a API interna do Portal AI Atende.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"license": "ISC",
|
|
24
24
|
"type": "commonjs",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"axios": "^1.15.2"
|
|
26
|
+
"axios": "^1.15.2",
|
|
27
|
+
"zod": "^4.3.6"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
30
|
"@types/node": "^22.10.0",
|