@openvertice/bot-sdk 0.0.0-stage → 0.1.1
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/README.md +198 -2
- package/dist/src/audio.d.ts +32 -0
- package/dist/src/audio.d.ts.map +1 -0
- package/dist/src/audio.js +47 -0
- package/dist/src/audio.js.map +1 -0
- package/dist/src/cliente.d.ts +213 -0
- package/dist/src/cliente.d.ts.map +1 -0
- package/dist/src/cliente.js +381 -0
- package/dist/src/cliente.js.map +1 -0
- package/dist/src/gateway.d.ts +81 -0
- package/dist/src/gateway.d.ts.map +1 -0
- package/dist/src/gateway.js +431 -0
- package/dist/src/gateway.js.map +1 -0
- package/dist/src/http.d.ts +119 -0
- package/dist/src/http.d.ts.map +1 -0
- package/dist/src/http.js +189 -0
- package/dist/src/http.js.map +1 -0
- package/dist/src/index.d.ts +19 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +16 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/tipos.d.ts +243 -0
- package/dist/src/tipos.d.ts.map +1 -0
- package/dist/src/tipos.js +5 -0
- package/dist/src/tipos.js.map +1 -0
- package/dist/src/voz-wrtc.d.ts +20 -0
- package/dist/src/voz-wrtc.d.ts.map +1 -0
- package/dist/src/voz-wrtc.js +68 -0
- package/dist/src/voz-wrtc.js.map +1 -0
- package/dist/src/voz.d.ts +150 -0
- package/dist/src/voz.d.ts.map +1 -0
- package/dist/src/voz.js +311 -0
- package/dist/src/voz.js.map +1 -0
- package/dist/src/wav.d.ts +29 -0
- package/dist/src/wav.d.ts.map +1 -0
- package/dist/src/wav.js +54 -0
- package/dist/src/wav.js.map +1 -0
- package/package.json +42 -3
package/dist/src/http.js
ADDED
|
@@ -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":"http.js","sourceRoot":"","sources":["../../src/http.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAQvB;IACA;IARX;;;;OAIG;IACH,YACE,QAAgB,EACP,MAAc,EACd,SAAwB,IAAI;QAErC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAHP,WAAM,GAAN,MAAM,CAAQ;QACd,WAAM,GAAN,MAAM,CAAsB;QAGrC,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;IAC1B,CAAC;CACF;AAYD,yEAAyE;AACzE,MAAM,SAAS,GAAG,MAAM,CAAC;AAEzB;;;;;;GAMG;AACH,MAAM,OAAO,IAAI;IACN,KAAK,CAAS;IACd,MAAM,CAAS;IACf,MAAM,CAAe;IAE9B;;;OAGG;IACH,YAAY,EAAE,OAAO,GAAG,uBAAuB,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAc;QACjF,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QAC3E,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM,GAAG,KAAK,C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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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,gFAAgF;AAChF,qBAAqB;AACrB;;;;;GAKG;AACH,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAkB9C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAQ/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/** Contract version this SDK implements. */
|
|
2
|
+
export declare const CONTRATO = "2026-10";
|
|
3
|
+
/** Gateway event families a bot may subscribe to. */
|
|
4
|
+
export type Intencao = "MESSAGES" | "MEMBERS" | "ROOMS" | "PRESENCE";
|
|
5
|
+
/** A text channel as the server grants it to this bot. */
|
|
6
|
+
export interface CanalDeTexto {
|
|
7
|
+
/** Stable channel code used in every API call (for example `"MURAL"`). */
|
|
8
|
+
code: string;
|
|
9
|
+
/** Name people see ("Música"); falls back to `code` if the room is gone. */
|
|
10
|
+
nome: string;
|
|
11
|
+
/** Whether the bot may read what is posted here. */
|
|
12
|
+
escutar: boolean;
|
|
13
|
+
/** Whether the bot may post here. */
|
|
14
|
+
falar: boolean;
|
|
15
|
+
/** Command prefix of the channel; `null` = the bot receives everything it can hear. */
|
|
16
|
+
prefixo: string | null;
|
|
17
|
+
}
|
|
18
|
+
/** A voice channel the bot is allowed to join. */
|
|
19
|
+
export interface CanalDeVoz {
|
|
20
|
+
code: string;
|
|
21
|
+
nome: string;
|
|
22
|
+
}
|
|
23
|
+
/** STUN/TURN server handed to the WebRTC peer connection. */
|
|
24
|
+
export interface ServidorIce {
|
|
25
|
+
/** One URL or a list of them (`stun:`, `turn:`). */
|
|
26
|
+
urls: string | string[];
|
|
27
|
+
username?: string;
|
|
28
|
+
credential?: string;
|
|
29
|
+
}
|
|
30
|
+
/** Rate limits the server enforces for this bot. */
|
|
31
|
+
export interface Limites {
|
|
32
|
+
/** Messages per minute. */
|
|
33
|
+
mensagensPorMinuto: number;
|
|
34
|
+
/** `identify` attempts per minute. */
|
|
35
|
+
identifyPorMinuto: number;
|
|
36
|
+
/** Session lifetime in seconds. */
|
|
37
|
+
sessaoSegundos: number;
|
|
38
|
+
}
|
|
39
|
+
/** Response of `GET /api/bots/gateway`: everything this bot is allowed to do. */
|
|
40
|
+
export interface Descoberta {
|
|
41
|
+
/** Contract version the server speaks; compare it with `CONTRATO`. */
|
|
42
|
+
contrato: string;
|
|
43
|
+
/** The identity the server assigned to the bot. */
|
|
44
|
+
bot: {
|
|
45
|
+
id: string;
|
|
46
|
+
usuario: string;
|
|
47
|
+
exibicao: string;
|
|
48
|
+
};
|
|
49
|
+
/** Where to connect and how often to send heartbeats. */
|
|
50
|
+
gateway: {
|
|
51
|
+
versao: number;
|
|
52
|
+
url: string;
|
|
53
|
+
heartbeatMs: number;
|
|
54
|
+
};
|
|
55
|
+
/** Channels the panel granted, split by kind. */
|
|
56
|
+
canais: {
|
|
57
|
+
texto: CanalDeTexto[];
|
|
58
|
+
voz: CanalDeVoz[];
|
|
59
|
+
};
|
|
60
|
+
/** Event families the panel granted. */
|
|
61
|
+
intents: Intencao[];
|
|
62
|
+
/** ICE servers to use for voice. */
|
|
63
|
+
iceServers: ServidorIce[];
|
|
64
|
+
/** Effective rate limits. */
|
|
65
|
+
limites: Limites;
|
|
66
|
+
}
|
|
67
|
+
/** Response of `POST /api/bots/session`: a short-lived gateway credential. */
|
|
68
|
+
export interface Sessao {
|
|
69
|
+
/** The session token, sent on `identify` and on message requests. */
|
|
70
|
+
sessao: string;
|
|
71
|
+
/** Expiry as a Unix timestamp in milliseconds. */
|
|
72
|
+
expiraEm: number;
|
|
73
|
+
/** Gateway endpoint and cadence to use with this session. */
|
|
74
|
+
gateway: {
|
|
75
|
+
versao: number;
|
|
76
|
+
url: string;
|
|
77
|
+
heartbeatMs: number;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** A file attached to a message. */
|
|
81
|
+
export interface AnexoDaMensagem {
|
|
82
|
+
/** Original file name, as uploaded. */
|
|
83
|
+
nome: string;
|
|
84
|
+
/** MIME type. */
|
|
85
|
+
mime: string;
|
|
86
|
+
/** Size in bytes. */
|
|
87
|
+
tamanho: number;
|
|
88
|
+
/** Absolute URL to download the file. */
|
|
89
|
+
url: string;
|
|
90
|
+
}
|
|
91
|
+
/** Link preview the server resolved for a message. */
|
|
92
|
+
export interface PreviaDeLink {
|
|
93
|
+
/** URL the preview was built from. */
|
|
94
|
+
url: string;
|
|
95
|
+
/** Page title, when the server could read one. */
|
|
96
|
+
titulo: string | null;
|
|
97
|
+
/** Page description, when available. */
|
|
98
|
+
descricao: string | null;
|
|
99
|
+
/** Preview image URL, when available. */
|
|
100
|
+
imagem: string | null;
|
|
101
|
+
/** Site name (host) shown next to the preview. */
|
|
102
|
+
site: string;
|
|
103
|
+
}
|
|
104
|
+
/** A message, as delivered by `message.created` and returned by the send routes. */
|
|
105
|
+
export interface Mensagem {
|
|
106
|
+
/** Message id, unique inside the channel. */
|
|
107
|
+
id: string;
|
|
108
|
+
/** Code of the channel the message belongs to. */
|
|
109
|
+
sala?: string;
|
|
110
|
+
/** Display name of the author. */
|
|
111
|
+
autor: string;
|
|
112
|
+
/** Author id, used to tell the bot's own messages apart. */
|
|
113
|
+
autorId?: string | null;
|
|
114
|
+
/** `true` when the author is a bot — this one included. */
|
|
115
|
+
autorBot: boolean;
|
|
116
|
+
/** Kind of payload the message carries. */
|
|
117
|
+
tipo?: "texto" | "arquivo" | "voz";
|
|
118
|
+
/** Text content; `null` for attachments without a caption. */
|
|
119
|
+
texto: string | null;
|
|
120
|
+
/** Creation time as a Unix timestamp in milliseconds. */
|
|
121
|
+
criadaEm: number;
|
|
122
|
+
/** When the message was pinned, if it was. */
|
|
123
|
+
fixadaEm?: number | null;
|
|
124
|
+
/** Who pinned the message. */
|
|
125
|
+
fixadaPor?: string | null;
|
|
126
|
+
/** Attachment, when `tipo` is `arquivo` or `voz`. */
|
|
127
|
+
arquivo?: AnexoDaMensagem | null;
|
|
128
|
+
/** Resolved link preview, when the message contains a link. */
|
|
129
|
+
previa?: PreviaDeLink | null;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The payload of `voice.signal` — the raw WebRTC `signal`, untranslated.
|
|
133
|
+
*
|
|
134
|
+
* The SDP travels under two names because both sides of the protocol already
|
|
135
|
+
* existed: `sdp` is the bot contract's name (server/bots/README.md) and
|
|
136
|
+
* `description.sdp` is what the browser client reads
|
|
137
|
+
* (`client/src/types/signaling.ts`). Senders fill in both; receivers accept
|
|
138
|
+
* either one.
|
|
139
|
+
*/
|
|
140
|
+
export interface SinalDeVoz {
|
|
141
|
+
/** `"offer"`, `"answer"` or `"candidate"`. */
|
|
142
|
+
type?: string;
|
|
143
|
+
/** Session description, in the bot contract's name. */
|
|
144
|
+
sdp?: string;
|
|
145
|
+
/** Session description, in the browser client's shape. */
|
|
146
|
+
description?: {
|
|
147
|
+
type?: string;
|
|
148
|
+
sdp?: string;
|
|
149
|
+
};
|
|
150
|
+
/** ICE candidate, when `type` is `"candidate"`. */
|
|
151
|
+
candidate?: unknown;
|
|
152
|
+
[chave: string]: unknown;
|
|
153
|
+
}
|
|
154
|
+
/** A command announced on `identify`, used by the client's autocomplete. */
|
|
155
|
+
export interface ComandoAnunciado {
|
|
156
|
+
/** Command name, without the channel prefix (e.g. `"tocar"`). */
|
|
157
|
+
nome: string;
|
|
158
|
+
/** Short, human-readable summary shown next to the suggestion. */
|
|
159
|
+
descricao?: string;
|
|
160
|
+
}
|
|
161
|
+
/** Someone else in the voice room. */
|
|
162
|
+
export interface PeerDaVoz {
|
|
163
|
+
/** Peer id inside the room. */
|
|
164
|
+
id: string;
|
|
165
|
+
/** Display name. */
|
|
166
|
+
nome: string;
|
|
167
|
+
/** `true` when the peer is a bot. */
|
|
168
|
+
bot?: boolean;
|
|
169
|
+
}
|
|
170
|
+
/** Events dispatched by the gateway (op 0), keyed by event name, with the shape of their `d`. */
|
|
171
|
+
export interface Eventos {
|
|
172
|
+
/** Sent once per connection, right after `identify` (or `resume`) succeeds. */
|
|
173
|
+
ready: {
|
|
174
|
+
/** The bot's identity on the server. */
|
|
175
|
+
bot: {
|
|
176
|
+
id: string;
|
|
177
|
+
usuario: string;
|
|
178
|
+
exibicao: string;
|
|
179
|
+
};
|
|
180
|
+
/** Text channels with full settings; voice channels as bare codes. */
|
|
181
|
+
canais: {
|
|
182
|
+
texto: CanalDeTexto[];
|
|
183
|
+
voz: string[];
|
|
184
|
+
};
|
|
185
|
+
/** Event families the server accepted. */
|
|
186
|
+
intents: Intencao[];
|
|
187
|
+
/** Channels where the read subscription took effect (they exist and grant access). */
|
|
188
|
+
ouvindo: string[];
|
|
189
|
+
/** Commands this process announced, for the client's autocomplete. */
|
|
190
|
+
comandos: ComandoAnunciado[];
|
|
191
|
+
/** ICE servers to use for voice. */
|
|
192
|
+
iceServers: ServidorIce[];
|
|
193
|
+
/** Id of the session this connection is using. */
|
|
194
|
+
sessao: string;
|
|
195
|
+
};
|
|
196
|
+
/** A message was posted in a channel the bot listens to. */
|
|
197
|
+
"message.created": Mensagem;
|
|
198
|
+
/**
|
|
199
|
+
* Someone called the bot with `@login`/`@display`.
|
|
200
|
+
*
|
|
201
|
+
* Arrives even in channels with a prefix (where `message.created` would not)
|
|
202
|
+
* and, in channels without a prefix, alongside it.
|
|
203
|
+
*/
|
|
204
|
+
mention: Mensagem;
|
|
205
|
+
/** A message was deleted; `sala` is the channel code it belonged to. */
|
|
206
|
+
"message.deleted": {
|
|
207
|
+
id: string;
|
|
208
|
+
sala: string;
|
|
209
|
+
};
|
|
210
|
+
/** An operation failed; `codigo` tells channel errors from voice errors. */
|
|
211
|
+
error: {
|
|
212
|
+
codigo: string;
|
|
213
|
+
mensagem: string;
|
|
214
|
+
};
|
|
215
|
+
/** The bot is now in the voice room. */
|
|
216
|
+
"voice.joined": {
|
|
217
|
+
/** Channel code. */
|
|
218
|
+
code: string;
|
|
219
|
+
/** Channel name. */
|
|
220
|
+
nome: string;
|
|
221
|
+
/** The bot's id in the room: it settles the crossed offer (glare). */
|
|
222
|
+
eu: string;
|
|
223
|
+
/** Peers already in the room. */
|
|
224
|
+
peers: PeerDaVoz[];
|
|
225
|
+
};
|
|
226
|
+
/** Another peer joined the voice room. */
|
|
227
|
+
"voice.peer.joined": PeerDaVoz;
|
|
228
|
+
/** Another peer left the voice room. */
|
|
229
|
+
"voice.peer.left": {
|
|
230
|
+
id: string;
|
|
231
|
+
};
|
|
232
|
+
/** The bot left (or was removed from) the voice room. */
|
|
233
|
+
"voice.left": {
|
|
234
|
+
code: string;
|
|
235
|
+
motivo: string;
|
|
236
|
+
};
|
|
237
|
+
/** WebRTC signaling addressed to this bot by peer `de`. */
|
|
238
|
+
"voice.signal": {
|
|
239
|
+
de: string;
|
|
240
|
+
signal: SinalDeVoz;
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=tipos.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tipos.d.ts","sourceRoot":"","sources":["../../src/tipos.ts"],"names":[],"mappings":"AAGA,4CAA4C;AAC5C,eAAO,MAAM,QAAQ,YAAY,CAAC;AAElC,qDAAqD;AACrD,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,SAAS,GAAG,OAAO,GAAG,UAAU,CAAC;AAErE,0DAA0D;AAC1D,MAAM,WAAW,YAAY;IAC3B,0EAA0E;IAC1E,IAAI,EAAE,MAAM,CAAC;IACb,4EAA4E;IAC5E,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,OAAO,EAAE,OAAO,CAAC;IACjB,qCAAqC;IACrC,KAA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 2026-10).
|
|
2
|
+
// They are the boundary: if the server changes a field, it changes here too.
|
|
3
|
+
/** Contract version this SDK implements. */
|
|
4
|
+
export const CONTRATO = "2026-10";
|
|
5
|
+
//# sourceMappingURL=tipos.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tipos.js","sourceRoot":"","sources":["../../src/tipos.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,6EAA6E;AAE7E,4CAA4C;AAC5C,MAAM,CAAC,MAAM,QAAQ,GAAG,SAAS,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { TransporteDeVoz } from "./voz.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates the Node voice transport backed by `@roamhq/wrtc`.
|
|
4
|
+
*
|
|
5
|
+
* The returned transport mirrors the browser's `RTCPeerConnection` API, so the
|
|
6
|
+
* mesh code in voz.ts does not need to know which runtime it is running on.
|
|
7
|
+
* Every connection it opens is tracked, and `fechar()` closes them all.
|
|
8
|
+
*
|
|
9
|
+
* @returns A transport that creates peer connections and audio sources.
|
|
10
|
+
* @throws {Error} When `@roamhq/wrtc` is not installed.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const transporte = await criarTransporteWrtc();
|
|
15
|
+
* const voz = new Voz(bot, { transporte });
|
|
16
|
+
* await voz.entrar("PATIO");
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function criarTransporteWrtc(): Promise<TransporteDeVoz>;
|
|
20
|
+
//# sourceMappingURL=voz-wrtc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"voz-wrtc.d.ts","sourceRoot":"","sources":["../../src/voz-wrtc.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAA8B,eAAe,EAAE,MAAM,UAAU,CAAC;AAqD5E;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,eAAe,CAAC,CAwBpE"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** Module cache: the native addon is imported at most once per process. */
|
|
2
|
+
let carregado = null;
|
|
3
|
+
/**
|
|
4
|
+
* Imports `@roamhq/wrtc` on first use.
|
|
5
|
+
*
|
|
6
|
+
* The import is dynamic on purpose: a bot that only handles text must not pay
|
|
7
|
+
* for (or fail because of) a native dependency it never uses.
|
|
8
|
+
*
|
|
9
|
+
* @returns The wrtc module, memoised after the first call.
|
|
10
|
+
* @throws {Error} With install instructions when the optional dependency is missing.
|
|
11
|
+
*/
|
|
12
|
+
async function carregarWrtc() {
|
|
13
|
+
if (carregado)
|
|
14
|
+
return carregado;
|
|
15
|
+
try {
|
|
16
|
+
const modulo = (await import("@roamhq/wrtc"));
|
|
17
|
+
carregado = "RTCPeerConnection" in modulo ? modulo : modulo.default;
|
|
18
|
+
return carregado;
|
|
19
|
+
}
|
|
20
|
+
catch (erro) {
|
|
21
|
+
throw new Error("A voz do bot precisa de `@roamhq/wrtc`. Instale com `npm i @roamhq/wrtc` " +
|
|
22
|
+
`no projeto do bot (o texto funciona sem ele). Detalhe: ${erro instanceof Error ? erro.message : String(erro)}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Creates the Node voice transport backed by `@roamhq/wrtc`.
|
|
27
|
+
*
|
|
28
|
+
* The returned transport mirrors the browser's `RTCPeerConnection` API, so the
|
|
29
|
+
* mesh code in voz.ts does not need to know which runtime it is running on.
|
|
30
|
+
* Every connection it opens is tracked, and `fechar()` closes them all.
|
|
31
|
+
*
|
|
32
|
+
* @returns A transport that creates peer connections and audio sources.
|
|
33
|
+
* @throws {Error} When `@roamhq/wrtc` is not installed.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const transporte = await criarTransporteWrtc();
|
|
38
|
+
* const voz = new Voz(bot, { transporte });
|
|
39
|
+
* await voz.entrar("PATIO");
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export async function criarTransporteWrtc() {
|
|
43
|
+
const wrtc = await carregarWrtc();
|
|
44
|
+
const abertas = new Set();
|
|
45
|
+
return {
|
|
46
|
+
/** Opens a peer connection configured with the server-provided ICE servers. */
|
|
47
|
+
criarConexao({ iceServers }) {
|
|
48
|
+
const conexao = new wrtc.RTCPeerConnection({
|
|
49
|
+
iceServers: iceServers.map((servidor) => ({
|
|
50
|
+
urls: servidor.urls,
|
|
51
|
+
...(servidor.username ? { username: servidor.username } : {}),
|
|
52
|
+
...(servidor.credential ? { credential: servidor.credential } : {}),
|
|
53
|
+
})),
|
|
54
|
+
});
|
|
55
|
+
abertas.add(conexao);
|
|
56
|
+
return conexao;
|
|
57
|
+
},
|
|
58
|
+
/** Creates the PCM source that feeds the published audio track. */
|
|
59
|
+
criarFonteDeAudio: () => new wrtc.nonstandard.RTCAudioSource(),
|
|
60
|
+
/** Closes every connection this transport opened. */
|
|
61
|
+
fechar() {
|
|
62
|
+
for (const conexao of abertas)
|
|
63
|
+
conexao.close();
|
|
64
|
+
abertas.clear();
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=voz-wrtc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"voz-wrtc.js","sourceRoot":"","sources":["../../src/voz-wrtc.ts"],"names":[],"mappings":"AA4BA,2EAA2E;AAC3E,IAAI,SAAS,GAAsB,IAAI,CAAC;AAExC;;;;;;;;GAQG;AACH,KAAK,UAAU,YAAY;IACzB,IAAI,SAAS;QAAE,OAAO,SAAS,CAAC;IAChC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,cAAc,CAAC,CAEjB,CAAC;QAC5B,SAAS,GAAG,mBAAmB,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;QACpE,OAAO,SAAS,CA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