@openvertice/bot-sdk 0.0.0-stage → 0.1.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.
Files changed (48) hide show
  1. package/README.md +189 -2
  2. package/dist/src/audio.d.ts +32 -0
  3. package/dist/src/audio.d.ts.map +1 -0
  4. package/dist/src/audio.js +47 -0
  5. package/dist/src/audio.js.map +1 -0
  6. package/dist/src/cliente.d.ts +213 -0
  7. package/dist/src/cliente.d.ts.map +1 -0
  8. package/dist/src/cliente.js +381 -0
  9. package/dist/src/cliente.js.map +1 -0
  10. package/dist/src/gateway.d.ts +76 -0
  11. package/dist/src/gateway.d.ts.map +1 -0
  12. package/dist/src/gateway.js +299 -0
  13. package/dist/src/gateway.js.map +1 -0
  14. package/dist/src/http.d.ts +119 -0
  15. package/dist/src/http.d.ts.map +1 -0
  16. package/dist/src/http.js +189 -0
  17. package/dist/src/http.js.map +1 -0
  18. package/dist/src/index.d.ts +19 -0
  19. package/dist/src/index.d.ts.map +1 -0
  20. package/dist/src/index.js +16 -0
  21. package/dist/src/index.js.map +1 -0
  22. package/dist/src/tipos.d.ts +243 -0
  23. package/dist/src/tipos.d.ts.map +1 -0
  24. package/dist/src/tipos.js +5 -0
  25. package/dist/src/tipos.js.map +1 -0
  26. package/dist/src/voz-wrtc.d.ts +20 -0
  27. package/dist/src/voz-wrtc.d.ts.map +1 -0
  28. package/dist/src/voz-wrtc.js +68 -0
  29. package/dist/src/voz-wrtc.js.map +1 -0
  30. package/dist/src/voz.d.ts +150 -0
  31. package/dist/src/voz.d.ts.map +1 -0
  32. package/dist/src/voz.js +311 -0
  33. package/dist/src/voz.js.map +1 -0
  34. package/dist/src/wav.d.ts +29 -0
  35. package/dist/src/wav.d.ts.map +1 -0
  36. package/dist/src/wav.js +54 -0
  37. package/dist/src/wav.js.map +1 -0
  38. package/package.json +58 -3
  39. package/src/audio.ts +88 -0
  40. package/src/cliente.ts +472 -0
  41. package/src/gateway.ts +354 -0
  42. package/src/http.ts +249 -0
  43. package/src/index.ts +41 -0
  44. package/src/tipos.ts +220 -0
  45. package/src/voz-wrtc.ts +100 -0
  46. package/src/voz.ts +407 -0
  47. package/src/wav.ts +71 -0
  48. package/src/wrtc.d.ts +4 -0
@@ -0,0 +1,299 @@
1
+ /** `WebSocket.readyState` for an open socket. */
2
+ const ABERTO = 1;
3
+ /** How long without any server frame before the connection is assumed dead. */
4
+ const SEM_SINAL_MS = 90_000;
5
+ /** Codes where retrying is pointless: the server refused the bot. */
6
+ const DEFINITIVOS = new Set([4001, 4003, 4005]);
7
+ /** Another connection took over this bot: reconnecting would fight over it. */
8
+ const OUTRA_CONEXAO = 4000;
9
+ /** Session closed (rotated token, disabled bot): it does not come back on its own. */
10
+ const SESSAO_ENCERRADA = 4009;
11
+ /** Expired session: renew the token and come back. */
12
+ const SESSAO_EXPIRADA = 4002;
13
+ /**
14
+ * WebSocket client for the Vértice gateway.
15
+ *
16
+ * It speaks the `{op, t, d, s}` envelope: op 10 `hello`, op 2 `identify` (or
17
+ * op 6 `resume`), op 1 heartbeat, op 11 heartbeat ack, op 0 dispatch and op 4
18
+ * action. Heartbeat, session resume and reconnection with exponential backoff
19
+ * are handled here, so bot authors never have to.
20
+ *
21
+ * One instance per bot: `conectar()` resolves only after `ready` arrives.
22
+ */
23
+ export class Gateway {
24
+ opcoes;
25
+ #ws = null;
26
+ #sessao = null;
27
+ #seq = 0;
28
+ #batida = null;
29
+ #vigia = null;
30
+ #recuo = null;
31
+ #tentativa = 0;
32
+ #encerrado = false;
33
+ #estado = "conectando";
34
+ /** @param opcoes Endpoints, credentials and hooks used by the connection. */
35
+ constructor(opcoes) {
36
+ this.opcoes = opcoes;
37
+ }
38
+ /** Current connection state. */
39
+ get estado() {
40
+ return this.#estado;
41
+ }
42
+ /** Session in use, or `null` before the first connection attempt. */
43
+ get sessaoAtual() {
44
+ return this.#sessao;
45
+ }
46
+ /**
47
+ * Opens the socket and resolves once the bot is identified (`ready`).
48
+ *
49
+ * @returns A promise that settles when the gateway is truly ready.
50
+ * @throws {Error} When the server refuses the bot or the socket cannot open.
51
+ */
52
+ conectar() {
53
+ this.#encerrado = false;
54
+ return this.#abrir();
55
+ }
56
+ /**
57
+ * Opens one socket attempt.
58
+ *
59
+ * Resolves on the first dispatched event — in practice `ready` — and rejects
60
+ * if the socket fails before that.
61
+ */
62
+ async #abrir() {
63
+ this.#mudar("conectando");
64
+ const sessao = await this.opcoes.sessao();
65
+ this.#sessao = sessao;
66
+ return new Promise((resolver, rejeitar) => {
67
+ let concluido = false;
68
+ const falhar = (erro) => {
69
+ if (concluido)
70
+ return;
71
+ concluido = true;
72
+ rejeitar(erro);
73
+ };
74
+ let ws;
75
+ try {
76
+ ws = new WebSocket(this.opcoes.url);
77
+ }
78
+ catch (erro) {
79
+ falhar(erro instanceof Error ? erro : new Error(String(erro)));
80
+ return;
81
+ }
82
+ this.#ws = ws;
83
+ ws.addEventListener("error", () => falhar(new Error("não consegui abrir o gateway")));
84
+ ws.addEventListener("message", (evento) => {
85
+ const envelope = this.#ler(evento);
86
+ if (!envelope)
87
+ return;
88
+ this.#armarVigia();
89
+ // hello: now it is safe to identify (or to resume, if a seq exists).
90
+ if (envelope.op === 10) {
91
+ this.#identificar(ws, sessao);
92
+ return;
93
+ }
94
+ this.#receber(envelope, () => {
95
+ if (concluido)
96
+ return;
97
+ concluido = true;
98
+ resolver();
99
+ });
100
+ });
101
+ ws.addEventListener("close", (evento) => {
102
+ this.#aoFechar(evento.code, evento.reason);
103
+ if (this.#encerrado)
104
+ falhar(new Error("gateway encerrado"));
105
+ });
106
+ });
107
+ }
108
+ /**
109
+ * Sends `identify` (op 2) on a fresh connection, or `resume` (op 6) when a
110
+ * sequence number from a previous connection is available.
111
+ *
112
+ * @param ws Socket already past `hello`.
113
+ * @param sessao Session to present to the server.
114
+ */
115
+ #identificar(ws, sessao) {
116
+ const comandos = this.opcoes.comandos ?? [];
117
+ const envelope = this.#seq > 0
118
+ ? { op: 6, d: { sessao: sessao.sessao, seq: this.#seq, comandos } }
119
+ : {
120
+ op: 2,
121
+ d: { sessao: sessao.sessao, intents: this.opcoes.intents, comandos },
122
+ };
123
+ ws.send(JSON.stringify(envelope));
124
+ }
125
+ /**
126
+ * Parses one socket frame, discarding anything that is not a valid envelope.
127
+ *
128
+ * @param evento Raw `message` event from the socket.
129
+ * @returns The envelope, or `null` when the payload is not JSON or has no `op`.
130
+ */
131
+ #ler(evento) {
132
+ try {
133
+ const bruto = typeof evento.data === "string" ? evento.data : String(evento.data);
134
+ const envelope = JSON.parse(bruto);
135
+ return typeof envelope?.op === "number" ? envelope : null;
136
+ }
137
+ catch {
138
+ return null;
139
+ }
140
+ }
141
+ /**
142
+ * Handles one gateway frame.
143
+ *
144
+ * op 0 is a dispatch, op 11 is the heartbeat ack and everything else is
145
+ * ignored here.
146
+ *
147
+ * @param envelope Frame received from the socket.
148
+ * @param aoPronto Called once, as soon as `ready` marks the bot as connected.
149
+ */
150
+ #receber(envelope, aoPronto) {
151
+ if (envelope.op === 11)
152
+ return;
153
+ if (envelope.op !== 0 || !envelope.t)
154
+ return;
155
+ if (typeof envelope.s === "number")
156
+ this.#seq = envelope.s;
157
+ if (envelope.t === "ready") {
158
+ this.#tentativa = 0;
159
+ this.#mudar("pronto");
160
+ this.#bater();
161
+ aoPronto();
162
+ }
163
+ this.opcoes.aoEvento(envelope.t, envelope.d);
164
+ }
165
+ /**
166
+ * Sends an action (op 4) to the gateway.
167
+ *
168
+ * Voice uses this for `voz.entrar`, `voz.sair` and `voice.signal`; the same
169
+ * route carries `comandos` updates.
170
+ *
171
+ * @param tipo Action name understood by the server.
172
+ * @param dados Action payload, merged into `d`.
173
+ * @throws {Error} When the gateway is not connected.
174
+ */
175
+ agir(tipo, dados = {}) {
176
+ const ws = this.#ws;
177
+ if (!ws || ws.readyState !== ABERTO)
178
+ throw new Error("O gateway não está conectado.");
179
+ ws.send(JSON.stringify({ op: 4, d: { tipo, ...dados } }));
180
+ }
181
+ /**
182
+ * Closes the connection on purpose: it will not reconnect.
183
+ *
184
+ * @param codigo WebSocket close code sent to the server.
185
+ * @param motivo Human-readable reason sent to the server.
186
+ */
187
+ fechar(codigo = 1000, motivo = "pedido do bot") {
188
+ this.#encerrado = true;
189
+ this.#limpar();
190
+ try {
191
+ this.#ws?.close(codigo, motivo);
192
+ }
193
+ catch {
194
+ /* it was already closing */
195
+ }
196
+ this.#ws = null;
197
+ this.#mudar("encerrado");
198
+ }
199
+ /**
200
+ * Stores the new state, notifies the bot and logs the detail, when there is one.
201
+ *
202
+ * @param estado New connection state.
203
+ * @param detalhe Optional human-readable explanation for logs and errors.
204
+ */
205
+ #mudar(estado, detalhe) {
206
+ this.#estado = estado;
207
+ this.opcoes.aoEstado?.(estado, detalhe);
208
+ if (detalhe)
209
+ this.opcoes.log?.(`[${estado}] ${detalhe}`);
210
+ }
211
+ /**
212
+ * (Re)starts the heartbeat timer, sending op 1 with the last sequence number.
213
+ *
214
+ * The interval is left `unref`'d so it never keeps the process alive.
215
+ */
216
+ #bater() {
217
+ if (this.#batida)
218
+ clearInterval(this.#batida);
219
+ this.#batida = setInterval(() => {
220
+ const ws = this.#ws;
221
+ if (!ws || ws.readyState !== ABERTO)
222
+ return;
223
+ ws.send(JSON.stringify({ op: 1, d: this.#seq }));
224
+ }, this.opcoes.heartbeatMs);
225
+ this.#batida.unref?.();
226
+ }
227
+ /**
228
+ * With nothing from the server for more than 90 s, the connection died
229
+ * silently (proxy, NAT). Drops it so the reconnect logic kicks in: it is the
230
+ * same deadline the server uses.
231
+ */
232
+ #armarVigia() {
233
+ if (this.#vigia)
234
+ clearTimeout(this.#vigia);
235
+ this.#vigia = setTimeout(() => {
236
+ if (this.#estado === "encerrado")
237
+ return;
238
+ this.opcoes.log?.("sem sinal do servidor; reconectando");
239
+ try {
240
+ this.#ws?.close(4000, "sem sinal");
241
+ }
242
+ catch {
243
+ /* it had already dropped */
244
+ }
245
+ }, SEM_SINAL_MS);
246
+ this.#vigia.unref?.();
247
+ }
248
+ /**
249
+ * Decides what to do when the socket closes: come back or stop for good.
250
+ *
251
+ * @param codigo WebSocket close code.
252
+ * @param motivo Close reason, used in the log and in the state detail.
253
+ */
254
+ #aoFechar(codigo, motivo) {
255
+ this.#limpar();
256
+ this.#ws = null;
257
+ if (this.#encerrado)
258
+ return;
259
+ if (DEFINITIVOS.has(codigo)) {
260
+ this.#mudar("recusado", `${codigo}: ${motivo}`);
261
+ this.#encerrado = true;
262
+ return;
263
+ }
264
+ if (codigo === OUTRA_CONEXAO) {
265
+ this.#mudar("recusado", "outra conexão assumiu este bot");
266
+ this.#encerrado = true;
267
+ return;
268
+ }
269
+ if (codigo === SESSAO_ENCERRADA) {
270
+ this.#mudar("recusado", "a sessão foi encerrada (token girado ou bot desativado)");
271
+ this.#encerrado = true;
272
+ return;
273
+ }
274
+ // 4002 (expired session) and network drops: renew the session and come back.
275
+ this.#tentativa += 1;
276
+ const espera = Math.min(30_000, 500 * 2 ** Math.min(this.#tentativa, 6));
277
+ this.#mudar("reconectando", `${codigo || "sem código"}: volta em ${espera} ms (tentativa ${this.#tentativa})`);
278
+ this.#recuo = setTimeout(() => {
279
+ if (this.#encerrado)
280
+ return;
281
+ // On an expired session, the client's `sessao()` already asks for another one.
282
+ this.#abrir().catch((erro) => this.#mudar("reconectando", `falhou: ${erro.message}`));
283
+ }, espera);
284
+ this.#recuo.unref?.();
285
+ }
286
+ /** Clears every timer, so a closed gateway leaves no handles behind. */
287
+ #limpar() {
288
+ if (this.#batida)
289
+ clearInterval(this.#batida);
290
+ if (this.#vigia)
291
+ clearTimeout(this.#vigia);
292
+ if (this.#recuo)
293
+ clearTimeout(this.#recuo);
294
+ this.#batida = null;
295
+ this.#vigia = null;
296
+ this.#recuo = null;
297
+ }
298
+ }
299
+ //# sourceMappingURL=gateway.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gateway.js","sourceRoot":"","sources":["../../src/gateway.ts"],"names":[],"mappings":"AAOA,iDAAiD;AACjD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119 @@
1
+ import type { Descoberta, Intencao, Mensagem, Sessao } from "./tipos.js";
2
+ /**
3
+ * Error thrown for every non-2xx response from the bot API.
4
+ *
5
+ * It carries the HTTP status and, when the server sends one, the machine-readable
6
+ * `codigo` (e.g. `"canal"`, `"voz"`), so callers can react to the cause instead
7
+ * of parsing the message.
8
+ */
9
+ export declare class ErroDaApi extends Error {
10
+ readonly status: number;
11
+ readonly codigo: string | null;
12
+ /**
13
+ * @param mensagem Human-readable message taken from the server payload.
14
+ * @param status HTTP status code of the failed response.
15
+ * @param codigo Server error code, when the payload provided one.
16
+ */
17
+ constructor(mensagem: string, status: number, codigo?: string | null);
18
+ }
19
+ /** Credentials and transport used by every {@link Http} call. */
20
+ export interface OpcoesHttp {
21
+ /** Server base URL, e.g. `https://vertice.example` (default: `http://localhost:8080`). */
22
+ baseUrl?: string;
23
+ /** Bot token (`vtb_…`), copied from the admin panel. */
24
+ token: string;
25
+ /** Injectable for tests; defaults to the global `fetch`. */
26
+ fetch?: typeof fetch;
27
+ }
28
+ /**
29
+ * Minimal HTTP client for the `/api/bots/*` routes.
30
+ *
31
+ * Requests authenticate as `Bot <token>` until a session exists, then as
32
+ * `Bearer <sessao>` — the form the server expects on message routes. There is
33
+ * no runtime dependency: it uses the global `fetch` from Node 22+.
34
+ */
35
+ export declare class Http {
36
+ #private;
37
+ /**
38
+ * @param options Base URL, bot token and an optional `fetch` implementation.
39
+ * @throws {Error} When the token is missing or empty.
40
+ */
41
+ constructor({ baseUrl, token, fetch: buscar }: OpcoesHttp);
42
+ /**
43
+ * Fetches the discovery document: what this bot may do, as configured in the panel.
44
+ *
45
+ * @returns Channels, intents, ICE servers and rate limits granted to the bot.
46
+ * @throws {ErroDaApi} When the token is rejected.
47
+ */
48
+ descobrir(): Promise<Descoberta>;
49
+ /**
50
+ * Exchanges the bot token for a short-lived session (15 minutes).
51
+ *
52
+ * The SDK renews it on its own shortly before it expires.
53
+ *
54
+ * @returns The new session and its expiry.
55
+ * @throws {ErroDaApi} When the token is invalid or the bot is disabled.
56
+ */
57
+ abrirSessao(): Promise<Sessao>;
58
+ /**
59
+ * Posts a text message over HTTP (the gateway can do the same over WebSocket).
60
+ *
61
+ * @param code Channel code.
62
+ * @param texto Message content.
63
+ * @param sessao Session token; when absent, the bot token is used.
64
+ * @returns The message the server created (id, timestamp, …).
65
+ * @throws {ErroDaApi} When the channel does not exist or the bot cannot post.
66
+ */
67
+ enviar(code: string, texto: string, sessao?: string): Promise<Mensagem>;
68
+ /**
69
+ * Reads one page of channel history (up to 100 messages).
70
+ *
71
+ * @param code Channel code.
72
+ * @param options `antesDe` to page backwards; `sessao` to authenticate with a session.
73
+ * @returns The page, plus `temMais` telling whether another page exists.
74
+ * @throws {ErroDaApi} When the bot cannot read the channel.
75
+ */
76
+ historico(code: string, { antesDe, sessao }?: {
77
+ antesDe?: number;
78
+ sessao?: string;
79
+ }): Promise<{
80
+ sala: string;
81
+ mensagens: Mensagem[];
82
+ temMais: boolean;
83
+ }>;
84
+ /**
85
+ * Uploads a file (or a voice message) to a channel.
86
+ *
87
+ * The body goes raw, with the type in the headers — the same path the chat
88
+ * upload uses, without multipart.
89
+ *
90
+ * @param code Channel code.
91
+ * @param corpo File bytes.
92
+ * @param options File name, MIME type, whether it is a voice message, and session.
93
+ * @returns The message the server created.
94
+ * @throws {ErroDaApi} When the upload fails or the response carries no message.
95
+ */
96
+ enviarArquivo(code: string, corpo: Uint8Array, { nome, mime, tipo, sessao, }?: {
97
+ nome?: string;
98
+ mime?: string;
99
+ tipo?: "arquivo" | "voz";
100
+ sessao?: string;
101
+ }): Promise<Mensagem>;
102
+ /**
103
+ * Deletes one of the bot's own messages (the server refuses anyone else's).
104
+ *
105
+ * @param code Channel code the message belongs to.
106
+ * @param id Message id.
107
+ * @param sessao Session token; when absent, the bot token is used.
108
+ * @throws {ErroDaApi} When the message is not the bot's or is already gone.
109
+ */
110
+ apagar(code: string, id: string, sessao?: string): Promise<void>;
111
+ /**
112
+ * Lists the intents the server granted, for callers that want to check before connecting.
113
+ *
114
+ * @returns The intent names granted to this bot.
115
+ * @throws {ErroDaApi} When discovery fails.
116
+ */
117
+ intents(): Promise<Intencao[]>;
118
+ }
119
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/http.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzE;;;;;;GAMG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAQhC,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IARhC;;;;OAIG;gBAED,QAAQ,EAAE,MAAM,EACP,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,MAAM,GAAG,IAAW;CAKxC;AAED,iEAAiE;AACjE,MAAM,WAAW,UAAU;IACzB,0FAA0F;IAC1F,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wDAAwD;IACxD,KAAK,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAKD;;;;;;GAMG;AACH,qBAAa,IAAI;;IAKf;;;OAGG;gBACS,EAAE,OAAiC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,UAAU;IAyDnF;;;;;OAKG;IACH,SAAS,IAAI,OAAO,CAAC,UAAU,CAAC;IAIhC;;;;;;;OAOG;IACH,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAI9B;;;;;;;;OAQG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAQ7E;;;;;;;OAOG;IACH,SAAS,CACP,IAAI,EAAE,MAAM,EACZ,EAAE,OAAO,EAAE,MAAM,EAAE,GAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO,GAC9D,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,QAAQ,EAAE,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAQrE;;;;;;;;;;;OAWG;IACG,aAAa,CACjB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,UAAU,EACjB,EACE,IAAgB,EAChB,IAAiC,EACjC,IAAgB,EAChB,MAAM,GACP,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,SAAS,GAAG,KAAK,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO,GAClF,OAAO,CAAC,QAAQ,CAAC;IAgCpB;;;;;;;OAOG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOtE;;;;;OAKG;IACG,OAAO,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;CAGrC"}
@@ -0,0 +1,189 @@
1
+ /**
2
+ * Error thrown for every non-2xx response from the bot API.
3
+ *
4
+ * It carries the HTTP status and, when the server sends one, the machine-readable
5
+ * `codigo` (e.g. `"canal"`, `"voz"`), so callers can react to the cause instead
6
+ * of parsing the message.
7
+ */
8
+ export class ErroDaApi extends Error {
9
+ status;
10
+ codigo;
11
+ /**
12
+ * @param mensagem Human-readable message taken from the server payload.
13
+ * @param status HTTP status code of the failed response.
14
+ * @param codigo Server error code, when the payload provided one.
15
+ */
16
+ constructor(mensagem, status, codigo = null) {
17
+ super(mensagem);
18
+ this.status = status;
19
+ this.codigo = codigo;
20
+ this.name = "ErroDaApi";
21
+ }
22
+ }
23
+ /** Trailing slashes, removed so every path can safely start with `/`. */
24
+ const SEM_BARRA = /\/+$/;
25
+ /**
26
+ * Minimal HTTP client for the `/api/bots/*` routes.
27
+ *
28
+ * Requests authenticate as `Bot <token>` until a session exists, then as
29
+ * `Bearer <sessao>` — the form the server expects on message routes. There is
30
+ * no runtime dependency: it uses the global `fetch` from Node 22+.
31
+ */
32
+ export class Http {
33
+ #base;
34
+ #token;
35
+ #fetch;
36
+ /**
37
+ * @param options Base URL, bot token and an optional `fetch` implementation.
38
+ * @throws {Error} When the token is missing or empty.
39
+ */
40
+ constructor({ baseUrl = "http://localhost:8080", token, fetch: buscar }) {
41
+ if (!token)
42
+ throw new Error("Falta o token do bot (o `vtb_…` do painel).");
43
+ this.#base = baseUrl.replace(SEM_BARRA, "");
44
+ this.#token = token;
45
+ this.#fetch = buscar ?? globalThis.fetch;
46
+ }
47
+ /**
48
+ * Performs a JSON request and unwraps the response.
49
+ *
50
+ * @typeParam T Expected shape of the response body.
51
+ * @param caminho Path relative to the base URL (e.g. `/api/bots/gateway`).
52
+ * @param options HTTP method, session token and JSON body.
53
+ * @returns The parsed body, or `null` when the server sent no content.
54
+ * @throws {ErroDaApi} When the response status is not 2xx.
55
+ */
56
+ async #pedir(caminho, { metodo = "GET", sessao, corpo, } = {}) {
57
+ const cabecalhos = {
58
+ Accept: "application/json",
59
+ // The bot token always works; the session only once one is in hand.
60
+ Authorization: sessao ? `Bearer ${sessao}` : `Bot ${this.#token}`,
61
+ };
62
+ let envio;
63
+ if (corpo !== undefined) {
64
+ cabecalhos["Content-Type"] = "application/json";
65
+ envio = JSON.stringify(corpo);
66
+ }
67
+ const resposta = await this.#fetch(this.#base + caminho, {
68
+ method: metodo,
69
+ headers: cabecalhos,
70
+ body: envio,
71
+ });
72
+ const texto = await resposta.text();
73
+ let dados = null;
74
+ try {
75
+ dados = texto ? JSON.parse(texto) : null;
76
+ }
77
+ catch {
78
+ dados = null;
79
+ }
80
+ if (!resposta.ok) {
81
+ const erro = (dados ?? {});
82
+ throw new ErroDaApi(erro.erro ?? `O servidor respondeu ${resposta.status}.`, resposta.status, erro.codigo ?? null);
83
+ }
84
+ return dados;
85
+ }
86
+ /**
87
+ * Fetches the discovery document: what this bot may do, as configured in the panel.
88
+ *
89
+ * @returns Channels, intents, ICE servers and rate limits granted to the bot.
90
+ * @throws {ErroDaApi} When the token is rejected.
91
+ */
92
+ descobrir() {
93
+ return this.#pedir("/api/bots/gateway");
94
+ }
95
+ /**
96
+ * Exchanges the bot token for a short-lived session (15 minutes).
97
+ *
98
+ * The SDK renews it on its own shortly before it expires.
99
+ *
100
+ * @returns The new session and its expiry.
101
+ * @throws {ErroDaApi} When the token is invalid or the bot is disabled.
102
+ */
103
+ abrirSessao() {
104
+ return this.#pedir("/api/bots/session", { metodo: "POST" });
105
+ }
106
+ /**
107
+ * Posts a text message over HTTP (the gateway can do the same over WebSocket).
108
+ *
109
+ * @param code Channel code.
110
+ * @param texto Message content.
111
+ * @param sessao Session token; when absent, the bot token is used.
112
+ * @returns The message the server created (id, timestamp, …).
113
+ * @throws {ErroDaApi} When the channel does not exist or the bot cannot post.
114
+ */
115
+ async enviar(code, texto, sessao) {
116
+ const resposta = await this.#pedir(`/api/bots/channels/${encodeURIComponent(code)}/messages`, { metodo: "POST", sessao, corpo: { content: texto } });
117
+ return resposta.mensagem;
118
+ }
119
+ /**
120
+ * Reads one page of channel history (up to 100 messages).
121
+ *
122
+ * @param code Channel code.
123
+ * @param options `antesDe` to page backwards; `sessao` to authenticate with a session.
124
+ * @returns The page, plus `temMais` telling whether another page exists.
125
+ * @throws {ErroDaApi} When the bot cannot read the channel.
126
+ */
127
+ historico(code, { antesDe, sessao } = {}) {
128
+ const consulta = antesDe ? `?antesDe=${antesDe}` : "";
129
+ return this.#pedir(`/api/bots/channels/${encodeURIComponent(code)}/messages${consulta}`, { sessao });
130
+ }
131
+ /**
132
+ * Uploads a file (or a voice message) to a channel.
133
+ *
134
+ * The body goes raw, with the type in the headers — the same path the chat
135
+ * upload uses, without multipart.
136
+ *
137
+ * @param code Channel code.
138
+ * @param corpo File bytes.
139
+ * @param options File name, MIME type, whether it is a voice message, and session.
140
+ * @returns The message the server created.
141
+ * @throws {ErroDaApi} When the upload fails or the response carries no message.
142
+ */
143
+ async enviarArquivo(code, corpo, { nome = "arquivo", mime = "application/octet-stream", tipo = "arquivo", sessao, } = {}) {
144
+ const resposta = await this.#fetch(`${this.#base}/api/bots/channels/${encodeURIComponent(code)}/messages`, {
145
+ method: "POST",
146
+ headers: {
147
+ Authorization: sessao ? `Bearer ${sessao}` : `Bot ${this.#token}`,
148
+ "Content-Type": mime,
149
+ // The server undoes the percent-encoding, so accented names survive intact.
150
+ "X-Vertice-Nome": encodeURIComponent(nome),
151
+ "X-Vertice-Tipo": tipo,
152
+ },
153
+ body: corpo,
154
+ });
155
+ const texto = await resposta.text();
156
+ const dados = (() => {
157
+ try {
158
+ return JSON.parse(texto);
159
+ }
160
+ catch {
161
+ return {};
162
+ }
163
+ })();
164
+ if (!resposta.ok || !dados.mensagem)
165
+ throw new ErroDaApi(dados.erro ?? `O servidor respondeu ${resposta.status}.`, resposta.status, dados.codigo ?? null);
166
+ return dados.mensagem;
167
+ }
168
+ /**
169
+ * Deletes one of the bot's own messages (the server refuses anyone else's).
170
+ *
171
+ * @param code Channel code the message belongs to.
172
+ * @param id Message id.
173
+ * @param sessao Session token; when absent, the bot token is used.
174
+ * @throws {ErroDaApi} When the message is not the bot's or is already gone.
175
+ */
176
+ async apagar(code, id, sessao) {
177
+ await this.#pedir(`/api/bots/messages/${encodeURIComponent(id)}?canal=${encodeURIComponent(code)}`, { metodo: "DELETE", sessao });
178
+ }
179
+ /**
180
+ * Lists the intents the server granted, for callers that want to check before connecting.
181
+ *
182
+ * @returns The intent names granted to this bot.
183
+ * @throws {ErroDaApi} When discovery fails.
184
+ */
185
+ async intents() {
186
+ return (await this.descobrir()).intents;
187
+ }
188
+ }
189
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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MAAM,KAAK,GAAG,CAAC,GAAG,EAAE;YAClB,IAAI,CAAC;gBACH,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAA4D,CAAC;YACtF,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,EAA6D,CAAC;YACvE,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;QACL,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ;YACjC,MAAM,IAAI,SAAS,CACjB,KAAK,CAAC,IAAI,IAAI,wBAAwB,QAAQ,CAAC,MAAM,GAAG,EACxD,QAAQ,CAAC,MAAM,EACf,KAAK,CAAC,MAAM,IAAI,IAAI,CACrB,CAAC;QACJ,OAAO,KAAK,CAAC,QAAQ,CAAC;IACxB,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,MAAM,CAAC,IAAY,EAAE,EAAU,EAAE,MAAe;QACpD,MAAM,IAAI,CAAC,MAAM,CACf,sBAAsB,kBAAkB,CAAC,EAAE,CAAC,UAAU,kBAAkB,CAAC,IAAI,CAAC,EAAE,EAChF,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,CAC7B,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,OAAO;QACX,OAAO,CAAC,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC;IAC1C,CAAC;CACF"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Public surface of `@openvertice/bot-sdk`.
3
+ *
4
+ * Everything a bot needs lives behind this module: the {@link Bot} client, the
5
+ * {@link Voz} mesh client, the contract types and the audio helpers.
6
+ */
7
+ export { Bot, ErroDaApi } from "./cliente.js";
8
+ export type { ContextoDoComando, OpcoesDoBot } from "./cliente.js";
9
+ export type { EstadoDoGateway, OpcoesGateway } from "./gateway.js";
10
+ export type { AnexoDaMensagem, CanalDeTexto, CanalDeVoz, Descoberta, Eventos, Intencao, Limites, Mensagem, PeerDaVoz, PreviaDeLink, ServidorIce, Sessao, SinalDeVoz, } from "./tipos.js";
11
+ export { CONTRATO } from "./tipos.js";
12
+ export { Voz } from "./voz.js";
13
+ export type { ConexaoDeVoz, EntradaNaVoz, FonteDeAudio, OpcoesDeVoz, TransporteDeVoz, } from "./voz.js";
14
+ export { criarTransporteWrtc } from "./voz-wrtc.js";
15
+ export { tocarTom } from "./audio.js";
16
+ export type { OpcoesDoTom } from "./audio.js";
17
+ export { wavDeTom } from "./wav.js";
18
+ export type { OpcoesDoWav } from "./wav.js";
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACnE,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACnE,YAAY,EACV,eAAe,EACf,YAAY,EACZ,UAAU,EACV,UAAU,EACV,OAAO,EACP,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,WAAW,EACX,MAAM,EACN,UAAU,GACX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,eAAe,GAChB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,16 @@
1
+ // Vértice bot SDK entry point (`@openvertice/bot-sdk`). The contract belongs to
2
+ // the server (server/bots/README.md); this module exports only what a bot needs
3
+ // in order to exist.
4
+ /**
5
+ * Public surface of `@openvertice/bot-sdk`.
6
+ *
7
+ * Everything a bot needs lives behind this module: the {@link Bot} client, the
8
+ * {@link Voz} mesh client, the contract types and the audio helpers.
9
+ */
10
+ export { Bot, ErroDaApi } from "./cliente.js";
11
+ export { CONTRATO } from "./tipos.js";
12
+ export { Voz } from "./voz.js";
13
+ export { criarTransporteWrtc } from "./voz-wrtc.js";
14
+ export { tocarTom } from "./audio.js";
15
+ export { wavDeTom } from "./wav.js";
16
+ //# sourceMappingURL=index.js.map