hobots 2.3.0 → 2.4.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.cjs +22 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -4
- package/dist/index.d.ts +18 -4
- package/dist/index.js +22 -6
- package/dist/index.js.map +1 -1
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +29 -3
- package/dist/protocol.d.ts +29 -3
- package/docs/api-reference.md +1 -1
- package/docs/concepts.md +5 -1
- package/docs/protocol.md +1 -0
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Breadcrumb, EventUser, EventType, MachineSnapshot, EventPayload, TransactionPayload, HeartbeatPayload, StepStatus, RunLogLevel, StepData, RunItemStatus, RunProgress, RunAttachmentContentType } from './protocol.cjs';
|
|
1
|
+
import { Breadcrumb, EventUser, EventType, MachineSnapshot, EventPayload, TransactionPayload, HeartbeatPayload, StepStatus, RunLogLevel, StepData, RunItemStatus, RunProgress, RunAttachmentContentType, EnvironmentInput } from './protocol.cjs';
|
|
2
2
|
export { BreadcrumbLevel, Envelope, EnvelopeItem, ExceptionData, InstanceInfo, MachineProcess, PollRequest, PollResponse, RunAttachmentConfirmRequest, RunAttachmentConfirmResponse, RunAttachmentCreateRequest, RunAttachmentCreateResponse, RunDescriptor, RunError, RunItemInput, RunItemsCreateRequest, RunItemsCreateResponse, RunLogEntry, RunStatus, RunUpdateRequest, RunUpdateResponse, RunUpdateStatus, StackFrame } from './protocol.cjs';
|
|
3
3
|
|
|
4
4
|
/** Aceita tudo que o handler pode ter em mãos: bytes ou um caminho de arquivo (só Node). */
|
|
@@ -95,6 +95,12 @@ declare class Client {
|
|
|
95
95
|
private prepareEvent;
|
|
96
96
|
sendTransaction(payload: TransactionPayload): void;
|
|
97
97
|
sendHeartbeat(payload: HeartbeatPayload): void;
|
|
98
|
+
/**
|
|
99
|
+
* Ambiente do item: o dele, senão o do init(), senão produção. Centralizado
|
|
100
|
+
* porque evento, transaction e heartbeat precisam responder igual — o servidor
|
|
101
|
+
* normaliza apelidos legados, então aqui basta repassar.
|
|
102
|
+
*/
|
|
103
|
+
private resolveEnvironment;
|
|
98
104
|
flush(timeoutMs?: number): Promise<boolean>;
|
|
99
105
|
close(timeoutMs?: number): Promise<boolean>;
|
|
100
106
|
}
|
|
@@ -162,7 +168,7 @@ declare class Transaction {
|
|
|
162
168
|
|
|
163
169
|
/** Opções de tasks dentro de `init({ tasks: ... })`. Credencial (clientSecret), identidade (instanceId) e debug vêm do init. */
|
|
164
170
|
interface TasksOptions {
|
|
165
|
-
/** Intervalo entre polls sem trabalho. Default:
|
|
171
|
+
/** Intervalo entre polls sem trabalho. Default: 2_000 (mínimo 1_000) */
|
|
166
172
|
pollIntervalMs?: number;
|
|
167
173
|
/** Runs simultâneas (1..5). Default: 1 (sequencial) */
|
|
168
174
|
concurrency?: number;
|
|
@@ -285,8 +291,16 @@ interface HeartbeatOptions {
|
|
|
285
291
|
interface InitOptions {
|
|
286
292
|
/** O Client Secret do agente (hb_…) — a mesma credencial para telemetria e tasks. Copie em Configurações → Agentes. */
|
|
287
293
|
clientSecret: string;
|
|
288
|
-
/**
|
|
289
|
-
|
|
294
|
+
/**
|
|
295
|
+
* Ambiente lógico onde este robô roda: 'development', 'testing', 'staging'
|
|
296
|
+
* (homologação) ou 'production'. Vai em todo evento e transaction E na
|
|
297
|
+
* identidade da instância — é por ele que as regras de alerta decidem se
|
|
298
|
+
* notificam. Default: 'production'.
|
|
299
|
+
*
|
|
300
|
+
* Um valor livre herdado continua valendo — o servidor normaliza apelidos
|
|
301
|
+
* como 'prod' e 'qa'.
|
|
302
|
+
*/
|
|
303
|
+
environment?: EnvironmentInput;
|
|
290
304
|
/** Versão do programa, ex.: 'robo-nfe@1.4.2' */
|
|
291
305
|
release?: string;
|
|
292
306
|
/** Identificador único e estável desta instância — a identidade do agente no painel (heartbeat e poll de tasks convergem nele) */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Breadcrumb, EventUser, EventType, MachineSnapshot, EventPayload, TransactionPayload, HeartbeatPayload, StepStatus, RunLogLevel, StepData, RunItemStatus, RunProgress, RunAttachmentContentType } from './protocol.js';
|
|
1
|
+
import { Breadcrumb, EventUser, EventType, MachineSnapshot, EventPayload, TransactionPayload, HeartbeatPayload, StepStatus, RunLogLevel, StepData, RunItemStatus, RunProgress, RunAttachmentContentType, EnvironmentInput } from './protocol.js';
|
|
2
2
|
export { BreadcrumbLevel, Envelope, EnvelopeItem, ExceptionData, InstanceInfo, MachineProcess, PollRequest, PollResponse, RunAttachmentConfirmRequest, RunAttachmentConfirmResponse, RunAttachmentCreateRequest, RunAttachmentCreateResponse, RunDescriptor, RunError, RunItemInput, RunItemsCreateRequest, RunItemsCreateResponse, RunLogEntry, RunStatus, RunUpdateRequest, RunUpdateResponse, RunUpdateStatus, StackFrame } from './protocol.js';
|
|
3
3
|
|
|
4
4
|
/** Aceita tudo que o handler pode ter em mãos: bytes ou um caminho de arquivo (só Node). */
|
|
@@ -95,6 +95,12 @@ declare class Client {
|
|
|
95
95
|
private prepareEvent;
|
|
96
96
|
sendTransaction(payload: TransactionPayload): void;
|
|
97
97
|
sendHeartbeat(payload: HeartbeatPayload): void;
|
|
98
|
+
/**
|
|
99
|
+
* Ambiente do item: o dele, senão o do init(), senão produção. Centralizado
|
|
100
|
+
* porque evento, transaction e heartbeat precisam responder igual — o servidor
|
|
101
|
+
* normaliza apelidos legados, então aqui basta repassar.
|
|
102
|
+
*/
|
|
103
|
+
private resolveEnvironment;
|
|
98
104
|
flush(timeoutMs?: number): Promise<boolean>;
|
|
99
105
|
close(timeoutMs?: number): Promise<boolean>;
|
|
100
106
|
}
|
|
@@ -162,7 +168,7 @@ declare class Transaction {
|
|
|
162
168
|
|
|
163
169
|
/** Opções de tasks dentro de `init({ tasks: ... })`. Credencial (clientSecret), identidade (instanceId) e debug vêm do init. */
|
|
164
170
|
interface TasksOptions {
|
|
165
|
-
/** Intervalo entre polls sem trabalho. Default:
|
|
171
|
+
/** Intervalo entre polls sem trabalho. Default: 2_000 (mínimo 1_000) */
|
|
166
172
|
pollIntervalMs?: number;
|
|
167
173
|
/** Runs simultâneas (1..5). Default: 1 (sequencial) */
|
|
168
174
|
concurrency?: number;
|
|
@@ -285,8 +291,16 @@ interface HeartbeatOptions {
|
|
|
285
291
|
interface InitOptions {
|
|
286
292
|
/** O Client Secret do agente (hb_…) — a mesma credencial para telemetria e tasks. Copie em Configurações → Agentes. */
|
|
287
293
|
clientSecret: string;
|
|
288
|
-
/**
|
|
289
|
-
|
|
294
|
+
/**
|
|
295
|
+
* Ambiente lógico onde este robô roda: 'development', 'testing', 'staging'
|
|
296
|
+
* (homologação) ou 'production'. Vai em todo evento e transaction E na
|
|
297
|
+
* identidade da instância — é por ele que as regras de alerta decidem se
|
|
298
|
+
* notificam. Default: 'production'.
|
|
299
|
+
*
|
|
300
|
+
* Um valor livre herdado continua valendo — o servidor normaliza apelidos
|
|
301
|
+
* como 'prod' e 'qa'.
|
|
302
|
+
*/
|
|
303
|
+
environment?: EnvironmentInput;
|
|
290
304
|
/** Versão do programa, ex.: 'robo-nfe@1.4.2' */
|
|
291
305
|
release?: string;
|
|
292
306
|
/** Identificador único e estável desta instância — a identidade do agente no painel (heartbeat e poll de tasks convergem nele) */
|
package/dist/index.js
CHANGED
|
@@ -103,7 +103,7 @@ function scrubSecrets(text) {
|
|
|
103
103
|
|
|
104
104
|
// src/utils.ts
|
|
105
105
|
var SDK_NAME = "hobots";
|
|
106
|
-
var SDK_VERSION = true ? "2.
|
|
106
|
+
var SDK_VERSION = true ? "2.4.0" : "0.0.0-dev";
|
|
107
107
|
function isNode() {
|
|
108
108
|
return typeof process !== "undefined" && typeof process.versions?.node === "string";
|
|
109
109
|
}
|
|
@@ -457,7 +457,7 @@ var Client = class {
|
|
|
457
457
|
...event,
|
|
458
458
|
type: hint?.type ?? event.type ?? scope2.type ?? "error",
|
|
459
459
|
release: event.release ?? this.options.release,
|
|
460
|
-
environment:
|
|
460
|
+
environment: this.resolveEnvironment(event.environment),
|
|
461
461
|
tags: Object.keys(tags).length > 0 ? tags : void 0,
|
|
462
462
|
extra: Object.keys(extra).length > 0 ? extra : void 0,
|
|
463
463
|
user: event.user ?? scope2.user,
|
|
@@ -472,7 +472,7 @@ var Client = class {
|
|
|
472
472
|
payload: {
|
|
473
473
|
...payload,
|
|
474
474
|
release: payload.release ?? this.options.release,
|
|
475
|
-
environment:
|
|
475
|
+
environment: this.resolveEnvironment(payload.environment),
|
|
476
476
|
tags: { ...this.options.tags, ...payload.tags }
|
|
477
477
|
}
|
|
478
478
|
});
|
|
@@ -480,9 +480,22 @@ var Client = class {
|
|
|
480
480
|
sendHeartbeat(payload) {
|
|
481
481
|
this.transport.enqueue({
|
|
482
482
|
type: "heartbeat",
|
|
483
|
-
payload: {
|
|
483
|
+
payload: {
|
|
484
|
+
...payload,
|
|
485
|
+
release: payload.release ?? this.options.release,
|
|
486
|
+
// o ambiente viaja no beat: é assim que a instância se classifica no app
|
|
487
|
+
environment: this.resolveEnvironment(payload.environment)
|
|
488
|
+
}
|
|
484
489
|
});
|
|
485
490
|
}
|
|
491
|
+
/**
|
|
492
|
+
* Ambiente do item: o dele, senão o do init(), senão produção. Centralizado
|
|
493
|
+
* porque evento, transaction e heartbeat precisam responder igual — o servidor
|
|
494
|
+
* normaliza apelidos legados, então aqui basta repassar.
|
|
495
|
+
*/
|
|
496
|
+
resolveEnvironment(value) {
|
|
497
|
+
return value ?? this.options.environment ?? "production";
|
|
498
|
+
}
|
|
486
499
|
flush(timeoutMs) {
|
|
487
500
|
return this.transport.flush(timeoutMs);
|
|
488
501
|
}
|
|
@@ -1931,7 +1944,7 @@ function installShutdownHandlers(agent2) {
|
|
|
1931
1944
|
}
|
|
1932
1945
|
|
|
1933
1946
|
// src/tasks/agent.ts
|
|
1934
|
-
var DEFAULT_POLL_INTERVAL_MS =
|
|
1947
|
+
var DEFAULT_POLL_INTERVAL_MS = 2e3;
|
|
1935
1948
|
var MIN_POLL_INTERVAL_MS = 1e3;
|
|
1936
1949
|
var MAX_CONCURRENCY = 5;
|
|
1937
1950
|
var POLL_RETRY_DELAYS_MS = [1e3, 4e3, 16e3];
|
|
@@ -2062,6 +2075,9 @@ var TaskAgent = class {
|
|
|
2062
2075
|
instance_id: this.instanceId,
|
|
2063
2076
|
version: SDK_VERSION,
|
|
2064
2077
|
host: hostname(),
|
|
2078
|
+
// ambiente da instância: em agentes poll-only (sem heartbeat) este é o
|
|
2079
|
+
// único canal por onde o servidor descobre onde o robô está rodando
|
|
2080
|
+
environment: this.options.environment,
|
|
2065
2081
|
tasks: [...this.registry.keys()],
|
|
2066
2082
|
// o servidor calcula a tolerância de offline (3×) a partir disto em
|
|
2067
2083
|
// agentes poll-only — sem o campo, um poll lento flaparia offline/online.
|
|
@@ -2251,7 +2267,7 @@ function init(options) {
|
|
|
2251
2267
|
if (options.tasks) {
|
|
2252
2268
|
const tasksOptions = options.tasks === true ? {} : options.tasks;
|
|
2253
2269
|
agent = new TaskAgent(
|
|
2254
|
-
{ ...tasksOptions, config, instanceId: options.instanceId, debug: options.debug, client, machineSampler },
|
|
2270
|
+
{ ...tasksOptions, config, instanceId: options.instanceId, environment: options.environment, debug: options.debug, client, machineSampler },
|
|
2255
2271
|
registry
|
|
2256
2272
|
);
|
|
2257
2273
|
}
|