hobots 1.10.0 → 2.0.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/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { Breadcrumb, EventUser, Severity, EventPayload, TransactionPayload, HeartbeatPayload, StepStatus, RunLogLevel, StepData, RunItemStatus, RunAttachmentContentType } from './protocol.cjs';
2
- export { AgentInfo, Envelope, EnvelopeItem, ExceptionData, PollRequest, PollResponse, RunAttachmentConfirmRequest, RunAttachmentConfirmResponse, RunAttachmentCreateRequest, RunAttachmentCreateResponse, RunDescriptor, RunError, RunItemInput, RunItemsCreateRequest, RunItemsCreateResponse, RunLogEntry, RunStatus, RunUpdateRequest, RunUpdateResponse, RunUpdateStatus, StackFrame } from './protocol.cjs';
1
+ import { Breadcrumb, EventUser, EventType, EventPayload, TransactionPayload, HeartbeatPayload, StepStatus, RunLogLevel, StepData, RunItemStatus, RunAttachmentContentType } from './protocol.cjs';
2
+ export { BreadcrumbLevel, Envelope, EnvelopeItem, ExceptionData, InstanceInfo, 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). */
5
5
  type AttachInput = Uint8Array | ArrayBuffer | string;
@@ -25,7 +25,7 @@ declare class Scope {
25
25
  user?: EventUser;
26
26
  contexts: Record<string, Record<string, unknown>>;
27
27
  extra: Record<string, unknown>;
28
- level?: Severity;
28
+ type?: EventType;
29
29
  fingerprint?: string[];
30
30
  breadcrumbs: Breadcrumb[];
31
31
  setTag(key: string, value: string): this;
@@ -34,7 +34,7 @@ declare class Scope {
34
34
  setContext(name: string, context: Record<string, unknown> | null): this;
35
35
  setExtra(key: string, value: unknown): this;
36
36
  setExtras(extras: Record<string, unknown>): this;
37
- setLevel(level: Severity): this;
37
+ setType(type: EventType): this;
38
38
  setFingerprint(fingerprint: string[]): this;
39
39
  addBreadcrumb(crumb: BreadcrumbInput, maxBreadcrumbs: number): this;
40
40
  clearBreadcrumbs(): this;
@@ -50,6 +50,8 @@ interface Logger {
50
50
  declare class Client {
51
51
  #private;
52
52
  readonly logger: Logger;
53
+ /** Eco de lifecycle (Transaction.emit) e afins só imprimem no terminal com debug ligado. */
54
+ readonly debug: boolean;
53
55
  private readonly transport;
54
56
  constructor(options: InitOptions, config?: ResolvedConfig);
55
57
  get options(): InitOptions;
@@ -57,7 +59,7 @@ declare class Client {
57
59
  /** Serialização explícita nunca inclui o secret. */
58
60
  toJSON(): Record<string, unknown>;
59
61
  captureException(error: unknown, hint: CaptureHint | undefined, scope: Scope): string;
60
- captureMessage(message: string, level: Severity, hint: CaptureHint | undefined, scope: Scope): string;
62
+ captureMessage(message: string, type: EventType, hint: CaptureHint | undefined, scope: Scope): string;
61
63
  captureEvent(event: EventPayload, hint: CaptureHint | undefined, scope: Scope): string;
62
64
  private prepareEvent;
63
65
  sendTransaction(payload: TransactionPayload): void;
@@ -110,9 +112,10 @@ declare class Transaction {
110
112
  /** Correlaciona a uma execução de task — preenchido automaticamente em ctx.tx */
111
113
  runId?: string | undefined);
112
114
  /**
113
- * Ecoa no terminal o início/fim de uma step ou transaction (sempre, independente de
114
- * sampling ou do debug) e espelha a linha no sink de lifecycle, se conectado — é
115
- * assim que os eventos de performance também aparecem nos logs da run no app.
115
+ * Registra o início/fim de uma step ou transaction: espelha a linha no sink de
116
+ * lifecycle, se conectado (é assim que os eventos de performance aparecem nos
117
+ * logs da run no app), e ecoa no terminal apenas com `debug: true` — o SDK não
118
+ * escreve no stdout do processo do usuário sem permissão.
116
119
  */
117
120
  emit(kind: 'transaction' | 'step', phase: 'start' | 'finish', label: string, startTs?: string, endTs?: string, status?: StepStatus | string): void;
118
121
  /** Conecta o espelho de lifecycle (RunReporter) e faz replay do backlog em ordem. */
@@ -274,7 +277,7 @@ interface CaptureAttachment {
274
277
  contentType?: RunAttachmentContentType;
275
278
  }
276
279
  interface CaptureHint {
277
- level?: Severity;
280
+ type?: EventType;
278
281
  tags?: Record<string, string>;
279
282
  extra?: Record<string, unknown>;
280
283
  fingerprint?: string[];
@@ -302,7 +305,7 @@ declare function getClient(): Client | undefined;
302
305
  * como miniatura na linha de log da run correspondente ao erro.
303
306
  */
304
307
  declare function captureException(error: unknown, hint?: CaptureHint): string | undefined;
305
- declare function captureMessage(message: string, level?: Severity, hint?: CaptureHint): string | undefined;
308
+ declare function captureMessage(message: string, type?: EventType, hint?: CaptureHint): string | undefined;
306
309
  /** Registra um breadcrumb — anexado aos próximos eventos como trilha do que aconteceu antes. */
307
310
  declare function addBreadcrumb(crumb: BreadcrumbInput): void;
308
311
  declare function setTag(key: string, value: string): void;
@@ -333,4 +336,4 @@ declare function close(timeoutMs?: number): Promise<boolean>;
333
336
 
334
337
  declare function scrubSecrets(text: string): string;
335
338
 
336
- export { type AttachInput, Breadcrumb, type BreadcrumbInput, type CaptureAttachment, type CaptureHint, Client, DEFAULT_BASE_URL, EventPayload, EventUser, type HeartbeatOptions, HeartbeatPayload, type InitOptions, RunAttachmentContentType, type RunContext, type RunItemOptions, RunItemStatus, type RunItems, RunLogLevel, Scope, Severity, Step, StepData, type TaskHandler, type TasksOptions, Transaction, TransactionPayload, addBreadcrumb, captureException, captureMessage, close, flush, getClient, init, register, scrubSecrets, setContext, setExtra, setTag, setTags, setUser, start, startTransaction, stop, withScope };
339
+ export { type AttachInput, Breadcrumb, type BreadcrumbInput, type CaptureAttachment, type CaptureHint, Client, DEFAULT_BASE_URL, EventPayload, EventType, EventUser, type HeartbeatOptions, HeartbeatPayload, type InitOptions, RunAttachmentContentType, type RunContext, type RunItemOptions, RunItemStatus, type RunItems, RunLogLevel, Scope, Step, StepData, type TaskHandler, type TasksOptions, Transaction, TransactionPayload, addBreadcrumb, captureException, captureMessage, close, flush, getClient, init, register, scrubSecrets, setContext, setExtra, setTag, setTags, setUser, start, startTransaction, stop, withScope };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Breadcrumb, EventUser, Severity, EventPayload, TransactionPayload, HeartbeatPayload, StepStatus, RunLogLevel, StepData, RunItemStatus, RunAttachmentContentType } from './protocol.js';
2
- export { AgentInfo, Envelope, EnvelopeItem, ExceptionData, PollRequest, PollResponse, RunAttachmentConfirmRequest, RunAttachmentConfirmResponse, RunAttachmentCreateRequest, RunAttachmentCreateResponse, RunDescriptor, RunError, RunItemInput, RunItemsCreateRequest, RunItemsCreateResponse, RunLogEntry, RunStatus, RunUpdateRequest, RunUpdateResponse, RunUpdateStatus, StackFrame } from './protocol.js';
1
+ import { Breadcrumb, EventUser, EventType, EventPayload, TransactionPayload, HeartbeatPayload, StepStatus, RunLogLevel, StepData, RunItemStatus, RunAttachmentContentType } from './protocol.js';
2
+ export { BreadcrumbLevel, Envelope, EnvelopeItem, ExceptionData, InstanceInfo, 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). */
5
5
  type AttachInput = Uint8Array | ArrayBuffer | string;
@@ -25,7 +25,7 @@ declare class Scope {
25
25
  user?: EventUser;
26
26
  contexts: Record<string, Record<string, unknown>>;
27
27
  extra: Record<string, unknown>;
28
- level?: Severity;
28
+ type?: EventType;
29
29
  fingerprint?: string[];
30
30
  breadcrumbs: Breadcrumb[];
31
31
  setTag(key: string, value: string): this;
@@ -34,7 +34,7 @@ declare class Scope {
34
34
  setContext(name: string, context: Record<string, unknown> | null): this;
35
35
  setExtra(key: string, value: unknown): this;
36
36
  setExtras(extras: Record<string, unknown>): this;
37
- setLevel(level: Severity): this;
37
+ setType(type: EventType): this;
38
38
  setFingerprint(fingerprint: string[]): this;
39
39
  addBreadcrumb(crumb: BreadcrumbInput, maxBreadcrumbs: number): this;
40
40
  clearBreadcrumbs(): this;
@@ -50,6 +50,8 @@ interface Logger {
50
50
  declare class Client {
51
51
  #private;
52
52
  readonly logger: Logger;
53
+ /** Eco de lifecycle (Transaction.emit) e afins só imprimem no terminal com debug ligado. */
54
+ readonly debug: boolean;
53
55
  private readonly transport;
54
56
  constructor(options: InitOptions, config?: ResolvedConfig);
55
57
  get options(): InitOptions;
@@ -57,7 +59,7 @@ declare class Client {
57
59
  /** Serialização explícita nunca inclui o secret. */
58
60
  toJSON(): Record<string, unknown>;
59
61
  captureException(error: unknown, hint: CaptureHint | undefined, scope: Scope): string;
60
- captureMessage(message: string, level: Severity, hint: CaptureHint | undefined, scope: Scope): string;
62
+ captureMessage(message: string, type: EventType, hint: CaptureHint | undefined, scope: Scope): string;
61
63
  captureEvent(event: EventPayload, hint: CaptureHint | undefined, scope: Scope): string;
62
64
  private prepareEvent;
63
65
  sendTransaction(payload: TransactionPayload): void;
@@ -110,9 +112,10 @@ declare class Transaction {
110
112
  /** Correlaciona a uma execução de task — preenchido automaticamente em ctx.tx */
111
113
  runId?: string | undefined);
112
114
  /**
113
- * Ecoa no terminal o início/fim de uma step ou transaction (sempre, independente de
114
- * sampling ou do debug) e espelha a linha no sink de lifecycle, se conectado — é
115
- * assim que os eventos de performance também aparecem nos logs da run no app.
115
+ * Registra o início/fim de uma step ou transaction: espelha a linha no sink de
116
+ * lifecycle, se conectado (é assim que os eventos de performance aparecem nos
117
+ * logs da run no app), e ecoa no terminal apenas com `debug: true` — o SDK não
118
+ * escreve no stdout do processo do usuário sem permissão.
116
119
  */
117
120
  emit(kind: 'transaction' | 'step', phase: 'start' | 'finish', label: string, startTs?: string, endTs?: string, status?: StepStatus | string): void;
118
121
  /** Conecta o espelho de lifecycle (RunReporter) e faz replay do backlog em ordem. */
@@ -274,7 +277,7 @@ interface CaptureAttachment {
274
277
  contentType?: RunAttachmentContentType;
275
278
  }
276
279
  interface CaptureHint {
277
- level?: Severity;
280
+ type?: EventType;
278
281
  tags?: Record<string, string>;
279
282
  extra?: Record<string, unknown>;
280
283
  fingerprint?: string[];
@@ -302,7 +305,7 @@ declare function getClient(): Client | undefined;
302
305
  * como miniatura na linha de log da run correspondente ao erro.
303
306
  */
304
307
  declare function captureException(error: unknown, hint?: CaptureHint): string | undefined;
305
- declare function captureMessage(message: string, level?: Severity, hint?: CaptureHint): string | undefined;
308
+ declare function captureMessage(message: string, type?: EventType, hint?: CaptureHint): string | undefined;
306
309
  /** Registra um breadcrumb — anexado aos próximos eventos como trilha do que aconteceu antes. */
307
310
  declare function addBreadcrumb(crumb: BreadcrumbInput): void;
308
311
  declare function setTag(key: string, value: string): void;
@@ -333,4 +336,4 @@ declare function close(timeoutMs?: number): Promise<boolean>;
333
336
 
334
337
  declare function scrubSecrets(text: string): string;
335
338
 
336
- export { type AttachInput, Breadcrumb, type BreadcrumbInput, type CaptureAttachment, type CaptureHint, Client, DEFAULT_BASE_URL, EventPayload, EventUser, type HeartbeatOptions, HeartbeatPayload, type InitOptions, RunAttachmentContentType, type RunContext, type RunItemOptions, RunItemStatus, type RunItems, RunLogLevel, Scope, Severity, Step, StepData, type TaskHandler, type TasksOptions, Transaction, TransactionPayload, addBreadcrumb, captureException, captureMessage, close, flush, getClient, init, register, scrubSecrets, setContext, setExtra, setTag, setTags, setUser, start, startTransaction, stop, withScope };
339
+ export { type AttachInput, Breadcrumb, type BreadcrumbInput, type CaptureAttachment, type CaptureHint, Client, DEFAULT_BASE_URL, EventPayload, EventType, EventUser, type HeartbeatOptions, HeartbeatPayload, type InitOptions, RunAttachmentContentType, type RunContext, type RunItemOptions, RunItemStatus, type RunItems, RunLogLevel, Scope, Step, StepData, type TaskHandler, type TasksOptions, Transaction, TransactionPayload, addBreadcrumb, captureException, captureMessage, close, flush, getClient, init, register, scrubSecrets, setContext, setExtra, setTag, setTags, setUser, start, startTransaction, stop, withScope };
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 ? "1.10.0" : "0.0.0-dev";
106
+ var SDK_VERSION = true ? "2.0.1" : "0.0.0-dev";
107
107
  function isNode() {
108
108
  return typeof process !== "undefined" && typeof process.versions?.node === "string";
109
109
  }
@@ -233,34 +233,34 @@ function safeString(value) {
233
233
  }
234
234
  return String(value);
235
235
  }
236
- function eventFromException(error, level = "error") {
237
- let type;
236
+ function eventFromException(error, type = "error") {
237
+ let exceptionType;
238
238
  let value;
239
239
  let frames = [];
240
240
  if (error instanceof Error) {
241
- type = error.name || "Error";
241
+ exceptionType = error.name || "Error";
242
242
  value = scrubSecrets(error.message);
243
243
  frames = parseStacktrace(error.stack);
244
244
  } else {
245
- type = "NonError";
245
+ exceptionType = "NonError";
246
246
  value = scrubSecrets(safeString(error));
247
247
  }
248
248
  return {
249
249
  event_id: uuid4(),
250
250
  timestamp: nowISO(),
251
- level,
251
+ type,
252
252
  exception: {
253
- type,
253
+ type: exceptionType,
254
254
  value,
255
255
  ...frames.length > 0 ? { stacktrace: { frames } } : {}
256
256
  }
257
257
  };
258
258
  }
259
- function eventFromMessage(message, level = "info") {
259
+ function eventFromMessage(message, type = "warning") {
260
260
  return {
261
261
  event_id: uuid4(),
262
262
  timestamp: nowISO(),
263
- level,
263
+ type,
264
264
  message: scrubSecrets(message)
265
265
  };
266
266
  }
@@ -296,7 +296,8 @@ var Transport = class {
296
296
  return;
297
297
  }
298
298
  if (this.buffer.length >= this.maxQueueSize) {
299
- this.buffer.shift();
299
+ const dropIndex = this.buffer.findIndex((queued) => queued.type !== "heartbeat");
300
+ this.buffer.splice(dropIndex === -1 ? 0 : dropIndex, 1);
300
301
  this.logger.warn("fila cheia, item mais antigo descartado");
301
302
  }
302
303
  this.buffer.push(item);
@@ -387,6 +388,8 @@ function runtimeContexts() {
387
388
  }
388
389
  var Client = class {
389
390
  logger;
391
+ /** Eco de lifecycle (Transaction.emit) e afins só imprimem no terminal com debug ligado. */
392
+ debug;
390
393
  // campos privados + getters de protótipo: o clientSecret não aparece em
391
394
  // JSON.stringify/serialização enumerável do Client (ex.: um objeto capturado
392
395
  // que referencie o client), mas client.options/config seguem funcionando
@@ -395,7 +398,8 @@ var Client = class {
395
398
  transport;
396
399
  constructor(options, config = resolveConfig(options)) {
397
400
  this.#options = options;
398
- this.logger = makeLogger(!!options.debug);
401
+ this.debug = !!options.debug;
402
+ this.logger = makeLogger(this.debug);
399
403
  this.#config = config;
400
404
  this.transport = new Transport({
401
405
  endpoint: this.#config.ingestEndpoint,
@@ -419,10 +423,10 @@ var Client = class {
419
423
  return `Client { baseUrl: '${this.#config.baseUrl}' }`;
420
424
  }
421
425
  captureException(error, hint, scope2) {
422
- return this.captureEvent(eventFromException(error, hint?.level ?? "error"), hint, scope2);
426
+ return this.captureEvent(eventFromException(error, hint?.type ?? "error"), hint, scope2);
423
427
  }
424
- captureMessage(message, level, hint, scope2) {
425
- return this.captureEvent(eventFromMessage(message, level), hint, scope2);
428
+ captureMessage(message, type, hint, scope2) {
429
+ return this.captureEvent(eventFromMessage(message, type), hint, scope2);
426
430
  }
427
431
  captureEvent(event, hint, scope2) {
428
432
  const sampleRate = this.options.sampleRate ?? 1;
@@ -444,7 +448,7 @@ var Client = class {
444
448
  const extra = { ...scope2.extra, ...event.extra, ...hint?.extra };
445
449
  return {
446
450
  ...event,
447
- level: hint?.level ?? event.level ?? scope2.level ?? "error",
451
+ type: hint?.type ?? event.type ?? scope2.type ?? "error",
448
452
  release: event.release ?? this.options.release,
449
453
  environment: event.environment ?? this.options.environment ?? "production",
450
454
  tags: Object.keys(tags).length > 0 ? tags : void 0,
@@ -482,6 +486,8 @@ var Client = class {
482
486
 
483
487
  // src/heartbeat.ts
484
488
  var DEFAULT_INTERVAL_MS = 3e4;
489
+ var MIN_REPORTED_INTERVAL_MS = 1e3;
490
+ var MAX_REPORTED_INTERVAL_MS = 9e5;
485
491
  var Heartbeat = class {
486
492
  constructor(client2, options = {}, instanceId) {
487
493
  this.client = client2;
@@ -498,12 +504,22 @@ var Heartbeat = class {
498
504
  start() {
499
505
  if (this.timer) return;
500
506
  this.beat();
501
- this.timer = setInterval(() => this.beat(), this.intervalMs);
507
+ this.schedule();
508
+ }
509
+ /** Jitter de ±10%: uma frota iniciada junto não sincroniza todos os beats no mesmo segundo. */
510
+ schedule() {
511
+ this.timer = setTimeout(
512
+ () => {
513
+ this.beat();
514
+ this.schedule();
515
+ },
516
+ this.intervalMs * (0.9 + Math.random() * 0.2)
517
+ );
502
518
  unrefTimer(this.timer);
503
519
  }
504
520
  stop() {
505
521
  if (this.timer) {
506
- clearInterval(this.timer);
522
+ clearTimeout(this.timer);
507
523
  this.timer = void 0;
508
524
  }
509
525
  }
@@ -511,7 +527,7 @@ var Heartbeat = class {
511
527
  this.client.sendHeartbeat({
512
528
  instance_id: this.instanceId,
513
529
  name: this.name,
514
- interval_ms: this.intervalMs,
530
+ interval_ms: Math.min(Math.max(this.intervalMs, MIN_REPORTED_INTERVAL_MS), MAX_REPORTED_INTERVAL_MS),
515
531
  timestamp: nowISO(),
516
532
  metadata: this.metadata
517
533
  });
@@ -550,7 +566,7 @@ function installGlobalHandlers(client2, getScope) {
550
566
  process.on(
551
567
  "uncaughtException",
552
568
  markInternal((error) => {
553
- client2.captureException(error, { level: "fatal", tags: { mechanism: "uncaughtException" } }, getScope());
569
+ client2.captureException(error, { type: "fatal", tags: { mechanism: "uncaughtException" } }, getScope());
554
570
  void client2.flush(2e3).then(async () => {
555
571
  if (externalListenerCount("uncaughtException") === 0) {
556
572
  await awaitEmergencyTasks(EMERGENCY_REPORT_CAP_MS);
@@ -563,7 +579,7 @@ function installGlobalHandlers(client2, getScope) {
563
579
  process.on(
564
580
  "unhandledRejection",
565
581
  markInternal((reason) => {
566
- client2.captureException(reason, { level: "error", tags: { mechanism: "unhandledRejection" } }, getScope());
582
+ client2.captureException(reason, { type: "error", tags: { mechanism: "unhandledRejection" } }, getScope());
567
583
  void client2.flush(2e3);
568
584
  })
569
585
  );
@@ -594,7 +610,7 @@ var Scope = class _Scope {
594
610
  user;
595
611
  contexts = {};
596
612
  extra = {};
597
- level;
613
+ type;
598
614
  fingerprint;
599
615
  breadcrumbs = [];
600
616
  setTag(key, value) {
@@ -625,8 +641,8 @@ var Scope = class _Scope {
625
641
  Object.assign(this.extra, extras);
626
642
  return this;
627
643
  }
628
- setLevel(level) {
629
- this.level = level;
644
+ setType(type) {
645
+ this.type = type;
630
646
  return this;
631
647
  }
632
648
  setFingerprint(fingerprint) {
@@ -650,7 +666,7 @@ var Scope = class _Scope {
650
666
  next.user = this.user ? { ...this.user } : void 0;
651
667
  next.contexts = Object.fromEntries(Object.entries(this.contexts).map(([k, v]) => [k, { ...v }]));
652
668
  next.extra = { ...this.extra };
653
- next.level = this.level;
669
+ next.type = this.type;
654
670
  next.fingerprint = this.fingerprint ? [...this.fingerprint] : void 0;
655
671
  next.breadcrumbs = [...this.breadcrumbs];
656
672
  return next;
@@ -758,15 +774,18 @@ var Transaction = class {
758
774
  // antes do RunReporter conectar) — replay no setLifecycleSink
759
775
  lifecycleBacklog = [];
760
776
  /**
761
- * Ecoa no terminal o início/fim de uma step ou transaction (sempre, independente de
762
- * sampling ou do debug) e espelha a linha no sink de lifecycle, se conectado — é
763
- * assim que os eventos de performance também aparecem nos logs da run no app.
777
+ * Registra o início/fim de uma step ou transaction: espelha a linha no sink de
778
+ * lifecycle, se conectado (é assim que os eventos de performance aparecem nos
779
+ * logs da run no app), e ecoa no terminal apenas com `debug: true` — o SDK não
780
+ * escreve no stdout do processo do usuário sem permissão.
764
781
  */
765
782
  emit(kind, phase, label, startTs, endTs, status) {
766
783
  const durationMs = startTs && endTs ? new Date(endTs).getTime() - new Date(startTs).getTime() : void 0;
767
- const tag = colorize(`[hobots:${kind}] ${phase.toUpperCase()}`, phase === "finish" ? colorForStatus(status ?? "ok") : "cyan");
768
784
  const suffix = durationMs != null ? ` (${durationMs}ms)` : "";
769
- console.log(`${tag} ${label}${suffix}`);
785
+ if (this.client?.debug) {
786
+ const tag = colorize(`[hobots:${kind}] ${phase.toUpperCase()}`, phase === "finish" ? colorForStatus(status ?? "ok") : "cyan");
787
+ console.log(`${tag} ${label}${suffix}`);
788
+ }
770
789
  const level = phase === "finish" ? levelForStatus(status ?? "ok") : "info";
771
790
  const message = `[${kind}] ${phase.toUpperCase()} ${label}${suffix}`;
772
791
  if (this.lifecycleSink) this.lifecycleSink(level, message);
@@ -1813,13 +1832,17 @@ var TaskAgent = class {
1813
1832
  try {
1814
1833
  const response = await this.api.poll(
1815
1834
  {
1816
- agent: {
1835
+ instance: {
1817
1836
  // identidade canônica do agente no painel — o mesmo instanceId do
1818
1837
  // heartbeat da Telemetria, então os dois canais convergem em um agente
1819
1838
  instance_id: this.instanceId,
1820
1839
  version: SDK_VERSION,
1821
1840
  host: hostname(),
1822
- tasks: [...this.registry.keys()]
1841
+ tasks: [...this.registry.keys()],
1842
+ // o servidor calcula a tolerância de offline (3×) a partir disto em
1843
+ // agentes poll-only — sem o campo, um poll lento flaparia offline/online.
1844
+ // Clampado à faixa aceita pelo schema do poll (1s..15min).
1845
+ poll_interval_ms: Math.min(Math.max(this.pollIntervalMs, 1e3), 9e5)
1823
1846
  },
1824
1847
  max: Math.min(MAX_CONCURRENCY, this.concurrency - this.activeRuns.size),
1825
1848
  tasks: [...this.registry.keys()]
@@ -2003,10 +2026,10 @@ function init(options) {
2003
2026
  function getClient() {
2004
2027
  return client;
2005
2028
  }
2006
- function toRunLogLevel(level) {
2007
- return level === "fatal" ? "error" : level;
2029
+ function toRunLogLevel(type) {
2030
+ return type === "fatal" ? "error" : type;
2008
2031
  }
2009
- function forwardAttachment(attachment, message, level) {
2032
+ function forwardAttachment(attachment, message, type) {
2010
2033
  const attach = currentRunAttach();
2011
2034
  if (!attach) {
2012
2035
  client?.logger.warn("attachment descartado \u2014 s\xF3 \xE9 suportado dentro de uma execu\xE7\xE3o de task (register/start)");
@@ -2015,7 +2038,7 @@ function forwardAttachment(attachment, message, level) {
2015
2038
  const withMeta = typeof attachment === "object" && "image" in attachment ? attachment : { image: attachment };
2016
2039
  void attach(withMeta.image, {
2017
2040
  message,
2018
- level: toRunLogLevel(level),
2041
+ level: toRunLogLevel(type),
2019
2042
  caption: withMeta.caption,
2020
2043
  contentType: withMeta.contentType
2021
2044
  });
@@ -2023,15 +2046,15 @@ function forwardAttachment(attachment, message, level) {
2023
2046
  function captureException(error, hint) {
2024
2047
  if (hint?.attachment) {
2025
2048
  const message = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
2026
- forwardAttachment(hint.attachment, message, hint.level ?? "error");
2049
+ forwardAttachment(hint.attachment, message, hint.type ?? "error");
2027
2050
  }
2028
2051
  return client?.captureException(error, hint, scope);
2029
2052
  }
2030
- function captureMessage(message, level = "info", hint) {
2053
+ function captureMessage(message, type = "warning", hint) {
2031
2054
  if (hint?.attachment) {
2032
- forwardAttachment(hint.attachment, message, hint.level ?? level);
2055
+ forwardAttachment(hint.attachment, message, hint.type ?? type);
2033
2056
  }
2034
- return client?.captureMessage(message, level, hint, scope);
2057
+ return client?.captureMessage(message, type, hint, scope);
2035
2058
  }
2036
2059
  function addBreadcrumb(crumb) {
2037
2060
  scope.addBreadcrumb(crumb, client?.options.maxBreadcrumbs ?? DEFAULT_MAX_BREADCRUMBS);