hobots 4.5.0 → 5.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.
- package/README.md +15 -11
- package/dist/{chunk-HKCDMUA3.js → chunk-6YTOYIZM.js} +2 -1
- package/dist/chunk-6YTOYIZM.js.map +1 -0
- package/dist/cli.cjs +250 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/index.cjs +1970 -1464
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +125 -254
- package/dist/index.d.ts +125 -254
- package/dist/index.js +1970 -1465
- package/dist/index.js.map +1 -1
- package/dist/protocol.cjs +1 -0
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +25 -3
- package/dist/protocol.d.ts +25 -3
- package/dist/protocol.js +1 -1
- package/docs/README.md +2 -2
- package/docs/api-reference.md +21 -7
- package/docs/concepts.md +11 -11
- package/docs/getting-started.md +1 -1
- package/docs/protocol.md +5 -5
- package/docs/runs.md +97 -23
- package/package.json +4 -1
- package/dist/chunk-HKCDMUA3.js.map +0 -1
package/dist/protocol.cjs
CHANGED
|
@@ -40,6 +40,7 @@ var protocol_limits_default = {
|
|
|
40
40
|
MAX_ITEM_PAYLOAD_BYTES: 16384,
|
|
41
41
|
MAX_ITEM_COLUMNS: 12,
|
|
42
42
|
MAX_ITEM_COLUMN_LABEL_CHARS: 60,
|
|
43
|
+
MAX_ITEMS_DONE_PER_PAGE: 1e3,
|
|
43
44
|
MAX_ATTACHMENT_BYTES: 5242880,
|
|
44
45
|
MAX_ATTACHMENTS_PER_RUN: 20,
|
|
45
46
|
MAX_ATTACHMENTS_PER_LOG_ENTRY: 4,
|
package/dist/protocol.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/protocol.ts","../protocol-limits.json","../src/wire-limits.ts"],"sourcesContent":["/**\n * Tipos do protocolo do Hobots (SDK → servidor).\n *\n * Este arquivo é a fonte de verdade do wire format: reexporta tipos (o app valida\n * os payloads com zod e trava o drift via `satisfies z.ZodType<...>` contra eles)\n * e os LIMITES numéricos do wire (WIRE_LIMITS, de protocol-limits.json) — o único\n * valor de runtime daqui, para a api aplicar exatamente os caps que o SDK aplica.\n */\n\nexport { WIRE_LIMITS, type WireLimits } from './wire-limits';\n\nimport type { EnvironmentInput } from './environment-protocol';\nimport type { MachineSnapshot } from './machine-protocol';\n\n// Wire format de execuções (agente ↔ servidor) — reexportado aqui para o app\n// consumir tudo de `hobots/protocol`.\nexport type {\n RunStatus,\n RunUpdateStatus,\n RunLogLevel,\n RunLogEntry,\n InstanceInfo,\n PollRequest,\n RunDescriptor,\n PollResponse,\n RunCreateRequest,\n RunCreateResponse,\n RunStartRequest,\n RunStartResponse,\n RunError,\n RunProgress,\n RunUpdateRequest,\n RunUpdateResponse,\n RunItemStatus,\n RunItemInput,\n RunItemsCreateRequest,\n RunItemsCreateResponse,\n ItemColumn,\n ItemsDeclaration,\n InstanceMode,\n RunAttachmentContentType,\n RunAttachmentCreateRequest,\n RunAttachmentCreateResponse,\n RunAttachmentConfirmRequest,\n RunAttachmentConfirmResponse,\n FileStorage,\n FileRef,\n FileDownloadResponse,\n} from './tasks/protocol';\n\n// Snapshot de recursos da máquina — usado no heartbeat, no poll e em contexts.machine.\nexport type { MachineProcess, MachineSnapshot } from './machine-protocol';\nexport type { Environment, EnvironmentInput } from './environment-protocol';\n\n/**\n * Tipo de um evento — o que ele é, não o quanto ele fala. Só 'fatal', 'error' e\n * 'warning' viram issue; 'success' é ingerido e nunca abre issue.\n * Ruído de log não é evento: para isso existem os logs da execução (RunLogLevel)\n * e as breadcrumbs, que têm níveis próprios com 'debug'/'info'.\n */\nexport type EventType = 'fatal' | 'error' | 'warning' | 'success';\n\n/** Nível de uma breadcrumb — trilha do que aconteceu antes, aqui log é bem-vindo. */\nexport type BreadcrumbLevel = 'debug' | 'info' | 'warning' | 'error' | 'fatal';\n\n/** Frames em ordem innermost-first (mesma ordem impressa pelo V8). */\nexport interface StackFrame {\n function?: string;\n filename?: string;\n lineno?: number;\n colno?: number;\n in_app: boolean;\n}\n\nexport interface Breadcrumb {\n /** ISO 8601 */\n timestamp: string;\n type?: string;\n category?: string;\n message?: string;\n level?: BreadcrumbLevel;\n data?: Record<string, unknown>;\n}\n\nexport interface ExceptionData {\n type: string;\n value: string;\n stacktrace?: { frames: StackFrame[] };\n}\n\nexport interface EventUser {\n id?: string;\n username?: string;\n email?: string;\n}\n\nexport interface EventPayload {\n /** uuid v4 sem hífens (32 hex), gerado pelo SDK */\n event_id: string;\n /** ISO 8601 */\n timestamp: string;\n type: EventType;\n message?: string;\n exception?: ExceptionData;\n /** Override de agrupamento; quando ausente o servidor calcula pelo stack trace */\n fingerprint?: string[];\n breadcrumbs?: Breadcrumb[];\n tags?: Record<string, string>;\n user?: EventUser;\n contexts?: Record<string, Record<string, unknown>>;\n extra?: Record<string, unknown>;\n release?: string;\n environment?: EnvironmentInput;\n}\n\n/** Status de uma step (etapa). `warning` = terminou, mas merece atenção (não é falha). */\nexport type StepStatus = 'ok' | 'warning' | 'error' | 'cancelled';\n\nexport interface StepData {\n /** 16 hex */\n step_id: string;\n parent_step_id?: string;\n op?: string;\n description?: string;\n status?: StepStatus;\n /** ISO 8601 */\n start_timestamp: string;\n /** ISO 8601 (fim da step) */\n timestamp: string;\n data?: Record<string, unknown>;\n}\n\nexport interface TransactionPayload {\n event_id: string;\n name: string;\n op?: string;\n status: string;\n start_timestamp: string;\n timestamp: string;\n steps: StepData[];\n tags?: Record<string, string>;\n release?: string;\n environment?: EnvironmentInput;\n /** Correlaciona esta transaction a uma execução do agente (hobots.
|
|
1
|
+
{"version":3,"sources":["../src/protocol.ts","../protocol-limits.json","../src/wire-limits.ts"],"sourcesContent":["/**\n * Tipos do protocolo do Hobots (SDK → servidor).\n *\n * Este arquivo é a fonte de verdade do wire format: reexporta tipos (o app valida\n * os payloads com zod e trava o drift via `satisfies z.ZodType<...>` contra eles)\n * e os LIMITES numéricos do wire (WIRE_LIMITS, de protocol-limits.json) — o único\n * valor de runtime daqui, para a api aplicar exatamente os caps que o SDK aplica.\n */\n\nexport { WIRE_LIMITS, type WireLimits } from './wire-limits';\n\nimport type { EnvironmentInput } from './environment-protocol';\nimport type { MachineSnapshot } from './machine-protocol';\n\n// Wire format de execuções (agente ↔ servidor) — reexportado aqui para o app\n// consumir tudo de `hobots/protocol`.\nexport type {\n RunStatus,\n RunUpdateStatus,\n RunLogLevel,\n RunLogEntry,\n InstanceInfo,\n PollRequest,\n RunDescriptor,\n PollResponse,\n RunCreateRequest,\n RunCreateResponse,\n RunStartRequest,\n RunStartResponse,\n RunError,\n RunProgress,\n RunUpdateRequest,\n RunUpdateResponse,\n RunItemStatus,\n RunItemInput,\n RunItemsCreateRequest,\n RunItemsCreateResponse,\n RunItemsDoneRequest,\n RunItemsDoneResponse,\n ItemColumn,\n ItemsDeclaration,\n InstanceMode,\n RunAttachmentContentType,\n RunAttachmentCreateRequest,\n RunAttachmentCreateResponse,\n RunAttachmentConfirmRequest,\n RunAttachmentConfirmResponse,\n FileStorage,\n FileRef,\n FileDownloadResponse,\n} from './tasks/protocol';\n\n// Snapshot de recursos da máquina — usado no heartbeat, no poll e em contexts.machine.\nexport type { MachineProcess, MachineSnapshot } from './machine-protocol';\nexport type { Environment, EnvironmentInput } from './environment-protocol';\n\n/**\n * Tipo de um evento — o que ele é, não o quanto ele fala. Só 'fatal', 'error' e\n * 'warning' viram issue; 'success' é ingerido e nunca abre issue.\n * Ruído de log não é evento: para isso existem os logs da execução (RunLogLevel)\n * e as breadcrumbs, que têm níveis próprios com 'debug'/'info'.\n */\nexport type EventType = 'fatal' | 'error' | 'warning' | 'success';\n\n/** Nível de uma breadcrumb — trilha do que aconteceu antes, aqui log é bem-vindo. */\nexport type BreadcrumbLevel = 'debug' | 'info' | 'warning' | 'error' | 'fatal';\n\n/** Frames em ordem innermost-first (mesma ordem impressa pelo V8). */\nexport interface StackFrame {\n function?: string;\n filename?: string;\n lineno?: number;\n colno?: number;\n in_app: boolean;\n}\n\nexport interface Breadcrumb {\n /** ISO 8601 */\n timestamp: string;\n type?: string;\n category?: string;\n message?: string;\n level?: BreadcrumbLevel;\n data?: Record<string, unknown>;\n}\n\nexport interface ExceptionData {\n type: string;\n value: string;\n stacktrace?: { frames: StackFrame[] };\n}\n\nexport interface EventUser {\n id?: string;\n username?: string;\n email?: string;\n}\n\nexport interface EventPayload {\n /** uuid v4 sem hífens (32 hex), gerado pelo SDK */\n event_id: string;\n /** ISO 8601 */\n timestamp: string;\n type: EventType;\n message?: string;\n exception?: ExceptionData;\n /** Override de agrupamento; quando ausente o servidor calcula pelo stack trace */\n fingerprint?: string[];\n breadcrumbs?: Breadcrumb[];\n tags?: Record<string, string>;\n user?: EventUser;\n contexts?: Record<string, Record<string, unknown>>;\n extra?: Record<string, unknown>;\n release?: string;\n environment?: EnvironmentInput;\n}\n\n/** Status de uma step (etapa). `warning` = terminou, mas merece atenção (não é falha). */\nexport type StepStatus = 'ok' | 'warning' | 'error' | 'cancelled';\n\nexport interface StepData {\n /** 16 hex */\n step_id: string;\n parent_step_id?: string;\n op?: string;\n description?: string;\n status?: StepStatus;\n /** ISO 8601 */\n start_timestamp: string;\n /** ISO 8601 (fim da step) */\n timestamp: string;\n data?: Record<string, unknown>;\n}\n\nexport interface TransactionPayload {\n event_id: string;\n name: string;\n op?: string;\n status: string;\n start_timestamp: string;\n timestamp: string;\n steps: StepData[];\n tags?: Record<string, string>;\n release?: string;\n environment?: EnvironmentInput;\n /** Correlaciona esta transaction a uma execução do agente (as etapas de hobots.step dentro do handler) */\n run_id?: string;\n}\n\nexport interface HeartbeatPayload {\n instance_id: string;\n name?: string;\n interval_ms: number;\n /** ISO 8601 */\n timestamp: string;\n metadata?: Record<string, unknown>;\n release?: string;\n /** Ambiente da instância — é ele que o app exibe e que as regras de alerta filtram */\n environment?: EnvironmentInput;\n /** Recursos da máquina no momento do beat (CPU, memória, disco, processo) */\n machine?: MachineSnapshot;\n}\n\nexport type EnvelopeItem =\n | { type: 'event'; payload: EventPayload }\n | { type: 'transaction'; payload: TransactionPayload }\n | { type: 'heartbeat'; payload: HeartbeatPayload };\n\nexport interface Envelope {\n sdk: { name: string; version: string };\n /** ISO 8601 */\n sent_at: string;\n items: EnvelopeItem[];\n}\n","{\n \"MAX_ITEMS_PER_ENVELOPE\": 50,\n \"HEARTBEAT_DEFAULT_INTERVAL_MS\": 30000,\n \"HEARTBEAT_MIN_INTERVAL_MS\": 1000,\n \"HEARTBEAT_MAX_INTERVAL_MS\": 900000,\n \"MAX_CLAIM_PER_POLL\": 5,\n \"MAX_LOG_MESSAGE_CHARS\": 10000,\n \"MAX_LOGS_PER_PATCH\": 100,\n \"MAX_ERROR_MESSAGE_CHARS\": 10000,\n \"MAX_ERROR_STACK_CHARS\": 20000,\n \"MAX_ITEMS_PER_REQUEST\": 500,\n \"MAX_ITEM_MESSAGE_CHARS\": 2000,\n \"MAX_ITEM_PAYLOAD_BYTES\": 16384,\n \"MAX_ITEM_COLUMNS\": 12,\n \"MAX_ITEM_COLUMN_LABEL_CHARS\": 60,\n \"MAX_ITEMS_DONE_PER_PAGE\": 1000,\n \"MAX_ATTACHMENT_BYTES\": 5242880,\n \"MAX_ATTACHMENTS_PER_RUN\": 20,\n \"MAX_ATTACHMENTS_PER_LOG_ENTRY\": 4,\n \"MAX_CAPTION_CHARS\": 200,\n \"MAX_IMAGE_DIMENSION_PX\": 20000\n}\n","import limits from '../protocol-limits.json';\n\n/**\n * Limites do wire SDK ↔ servidor — fonte ÚNICA (protocol-limits.json): o SDK\n * Node lê daqui, a @hobots/api importa de `hobots/protocol` e o SDK Python\n * confere a paridade num teste que lê o mesmo JSON. Mudar um limite = mudar o\n * JSON (e, no Python, a constante espelhada — o teste acusa).\n */\nexport const WIRE_LIMITS = limits as Readonly<typeof limits>;\nexport type WireLimits = typeof WIRE_LIMITS;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA,EACE,wBAA0B;AAAA,EAC1B,+BAAiC;AAAA,EACjC,2BAA6B;AAAA,EAC7B,2BAA6B;AAAA,EAC7B,oBAAsB;AAAA,EACtB,uBAAyB;AAAA,EACzB,oBAAsB;AAAA,EACtB,yBAA2B;AAAA,EAC3B,uBAAyB;AAAA,EACzB,uBAAyB;AAAA,EACzB,wBAA0B;AAAA,EAC1B,wBAA0B;AAAA,EAC1B,kBAAoB;AAAA,EACpB,6BAA+B;AAAA,EAC/B,yBAA2B;AAAA,EAC3B,sBAAwB;AAAA,EACxB,yBAA2B;AAAA,EAC3B,+BAAiC;AAAA,EACjC,mBAAqB;AAAA,EACrB,wBAA0B;AAC5B;;;ACbO,IAAM,cAAc;","names":[]}
|
package/dist/protocol.d.cts
CHANGED
|
@@ -146,7 +146,10 @@ interface RunDescriptor {
|
|
|
146
146
|
id: string;
|
|
147
147
|
name: string;
|
|
148
148
|
} | null;
|
|
149
|
-
/**
|
|
149
|
+
/**
|
|
150
|
+
* Origem da run: 'hobots' | 'link' | 'schedule' | 'agent' | 'local' (informativo; 'agent' = aberta pelo
|
|
151
|
+
* próprio SDK no modo start; 'local' = modo local, sem Central — nunca chega ao servidor)
|
|
152
|
+
*/
|
|
150
153
|
source: string;
|
|
151
154
|
/** ISO 8601 (relógio do servidor) */
|
|
152
155
|
created_at: string;
|
|
@@ -240,6 +243,23 @@ interface RunItemsCreateResponse {
|
|
|
240
243
|
/** Colapsados por id repetido dentro do mesmo lote (vale o de maior seq) */
|
|
241
244
|
duplicates: number;
|
|
242
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* POST /v1/runs/{id}/items/done — ids dos itens já concluídos (`succeeded`/`occurrence`)
|
|
248
|
+
* no MESMO TRABALHO: a run raiz e todas as suas reexecuções pela Central/Studio. O
|
|
249
|
+
* `items.each` consulta uma vez, no início, para pular o que já deu certo (só `failed`
|
|
250
|
+
* roda de novo). Corpo vazio = primeira página.
|
|
251
|
+
*/
|
|
252
|
+
interface RunItemsDoneRequest {
|
|
253
|
+
/** `next` da página anterior (opaco) */
|
|
254
|
+
cursor?: string;
|
|
255
|
+
/** Tamanho da página — teto WIRE_LIMITS.MAX_ITEMS_DONE_PER_PAGE (o default do servidor) */
|
|
256
|
+
limit?: number;
|
|
257
|
+
}
|
|
258
|
+
interface RunItemsDoneResponse {
|
|
259
|
+
ids: string[];
|
|
260
|
+
/** Cursor da próxima página; null = acabou */
|
|
261
|
+
next: string | null;
|
|
262
|
+
}
|
|
243
263
|
/** Formatos aceitos para anexo. O S3 valida o content-type contra a assinatura. */
|
|
244
264
|
type RunAttachmentContentType = 'image/png' | 'image/jpeg' | 'image/webp';
|
|
245
265
|
/** POST /v1/runs/{id}/attachments */
|
|
@@ -327,6 +347,7 @@ var MAX_ITEM_MESSAGE_CHARS = 2000;
|
|
|
327
347
|
var MAX_ITEM_PAYLOAD_BYTES = 16384;
|
|
328
348
|
var MAX_ITEM_COLUMNS = 12;
|
|
329
349
|
var MAX_ITEM_COLUMN_LABEL_CHARS = 60;
|
|
350
|
+
var MAX_ITEMS_DONE_PER_PAGE = 1000;
|
|
330
351
|
var MAX_ATTACHMENT_BYTES = 5242880;
|
|
331
352
|
var MAX_ATTACHMENTS_PER_RUN = 20;
|
|
332
353
|
var MAX_ATTACHMENTS_PER_LOG_ENTRY = 4;
|
|
@@ -347,6 +368,7 @@ var limits = {
|
|
|
347
368
|
MAX_ITEM_PAYLOAD_BYTES: MAX_ITEM_PAYLOAD_BYTES,
|
|
348
369
|
MAX_ITEM_COLUMNS: MAX_ITEM_COLUMNS,
|
|
349
370
|
MAX_ITEM_COLUMN_LABEL_CHARS: MAX_ITEM_COLUMN_LABEL_CHARS,
|
|
371
|
+
MAX_ITEMS_DONE_PER_PAGE: MAX_ITEMS_DONE_PER_PAGE,
|
|
350
372
|
MAX_ATTACHMENT_BYTES: MAX_ATTACHMENT_BYTES,
|
|
351
373
|
MAX_ATTACHMENTS_PER_RUN: MAX_ATTACHMENTS_PER_RUN,
|
|
352
374
|
MAX_ATTACHMENTS_PER_LOG_ENTRY: MAX_ATTACHMENTS_PER_LOG_ENTRY,
|
|
@@ -454,7 +476,7 @@ interface TransactionPayload {
|
|
|
454
476
|
tags?: Record<string, string>;
|
|
455
477
|
release?: string;
|
|
456
478
|
environment?: EnvironmentInput;
|
|
457
|
-
/** Correlaciona esta transaction a uma execução do agente (hobots.
|
|
479
|
+
/** Correlaciona esta transaction a uma execução do agente (as etapas de hobots.step dentro do handler) */
|
|
458
480
|
run_id?: string;
|
|
459
481
|
}
|
|
460
482
|
interface HeartbeatPayload {
|
|
@@ -490,4 +512,4 @@ interface Envelope {
|
|
|
490
512
|
items: EnvelopeItem[];
|
|
491
513
|
}
|
|
492
514
|
|
|
493
|
-
export { type Breadcrumb, type BreadcrumbLevel, type Envelope, type EnvelopeItem, type Environment, type EnvironmentInput, type EventPayload, type EventType, type EventUser, type ExceptionData, type FileDownloadResponse, type FileRef, type FileStorage, type HeartbeatPayload, type InstanceInfo, type InstanceMode, type ItemColumn, type ItemsDeclaration, type MachineProcess, type MachineSnapshot, type PollRequest, type PollResponse, type RunAttachmentConfirmRequest, type RunAttachmentConfirmResponse, type RunAttachmentContentType, type RunAttachmentCreateRequest, type RunAttachmentCreateResponse, type RunCreateRequest, type RunCreateResponse, type RunDescriptor, type RunError, type RunItemInput, type RunItemStatus, type RunItemsCreateRequest, type RunItemsCreateResponse, type RunLogEntry, type RunLogLevel, type RunProgress, type RunStartRequest, type RunStartResponse, type RunStatus, type RunUpdateRequest, type RunUpdateResponse, type RunUpdateStatus, type StackFrame, type StepData, type StepStatus, type TransactionPayload, WIRE_LIMITS, type WireLimits };
|
|
515
|
+
export { type Breadcrumb, type BreadcrumbLevel, type Envelope, type EnvelopeItem, type Environment, type EnvironmentInput, type EventPayload, type EventType, type EventUser, type ExceptionData, type FileDownloadResponse, type FileRef, type FileStorage, type HeartbeatPayload, type InstanceInfo, type InstanceMode, type ItemColumn, type ItemsDeclaration, type MachineProcess, type MachineSnapshot, type PollRequest, type PollResponse, type RunAttachmentConfirmRequest, type RunAttachmentConfirmResponse, type RunAttachmentContentType, type RunAttachmentCreateRequest, type RunAttachmentCreateResponse, type RunCreateRequest, type RunCreateResponse, type RunDescriptor, type RunError, type RunItemInput, type RunItemStatus, type RunItemsCreateRequest, type RunItemsCreateResponse, type RunItemsDoneRequest, type RunItemsDoneResponse, type RunLogEntry, type RunLogLevel, type RunProgress, type RunStartRequest, type RunStartResponse, type RunStatus, type RunUpdateRequest, type RunUpdateResponse, type RunUpdateStatus, type StackFrame, type StepData, type StepStatus, type TransactionPayload, WIRE_LIMITS, type WireLimits };
|
package/dist/protocol.d.ts
CHANGED
|
@@ -146,7 +146,10 @@ interface RunDescriptor {
|
|
|
146
146
|
id: string;
|
|
147
147
|
name: string;
|
|
148
148
|
} | null;
|
|
149
|
-
/**
|
|
149
|
+
/**
|
|
150
|
+
* Origem da run: 'hobots' | 'link' | 'schedule' | 'agent' | 'local' (informativo; 'agent' = aberta pelo
|
|
151
|
+
* próprio SDK no modo start; 'local' = modo local, sem Central — nunca chega ao servidor)
|
|
152
|
+
*/
|
|
150
153
|
source: string;
|
|
151
154
|
/** ISO 8601 (relógio do servidor) */
|
|
152
155
|
created_at: string;
|
|
@@ -240,6 +243,23 @@ interface RunItemsCreateResponse {
|
|
|
240
243
|
/** Colapsados por id repetido dentro do mesmo lote (vale o de maior seq) */
|
|
241
244
|
duplicates: number;
|
|
242
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* POST /v1/runs/{id}/items/done — ids dos itens já concluídos (`succeeded`/`occurrence`)
|
|
248
|
+
* no MESMO TRABALHO: a run raiz e todas as suas reexecuções pela Central/Studio. O
|
|
249
|
+
* `items.each` consulta uma vez, no início, para pular o que já deu certo (só `failed`
|
|
250
|
+
* roda de novo). Corpo vazio = primeira página.
|
|
251
|
+
*/
|
|
252
|
+
interface RunItemsDoneRequest {
|
|
253
|
+
/** `next` da página anterior (opaco) */
|
|
254
|
+
cursor?: string;
|
|
255
|
+
/** Tamanho da página — teto WIRE_LIMITS.MAX_ITEMS_DONE_PER_PAGE (o default do servidor) */
|
|
256
|
+
limit?: number;
|
|
257
|
+
}
|
|
258
|
+
interface RunItemsDoneResponse {
|
|
259
|
+
ids: string[];
|
|
260
|
+
/** Cursor da próxima página; null = acabou */
|
|
261
|
+
next: string | null;
|
|
262
|
+
}
|
|
243
263
|
/** Formatos aceitos para anexo. O S3 valida o content-type contra a assinatura. */
|
|
244
264
|
type RunAttachmentContentType = 'image/png' | 'image/jpeg' | 'image/webp';
|
|
245
265
|
/** POST /v1/runs/{id}/attachments */
|
|
@@ -327,6 +347,7 @@ var MAX_ITEM_MESSAGE_CHARS = 2000;
|
|
|
327
347
|
var MAX_ITEM_PAYLOAD_BYTES = 16384;
|
|
328
348
|
var MAX_ITEM_COLUMNS = 12;
|
|
329
349
|
var MAX_ITEM_COLUMN_LABEL_CHARS = 60;
|
|
350
|
+
var MAX_ITEMS_DONE_PER_PAGE = 1000;
|
|
330
351
|
var MAX_ATTACHMENT_BYTES = 5242880;
|
|
331
352
|
var MAX_ATTACHMENTS_PER_RUN = 20;
|
|
332
353
|
var MAX_ATTACHMENTS_PER_LOG_ENTRY = 4;
|
|
@@ -347,6 +368,7 @@ var limits = {
|
|
|
347
368
|
MAX_ITEM_PAYLOAD_BYTES: MAX_ITEM_PAYLOAD_BYTES,
|
|
348
369
|
MAX_ITEM_COLUMNS: MAX_ITEM_COLUMNS,
|
|
349
370
|
MAX_ITEM_COLUMN_LABEL_CHARS: MAX_ITEM_COLUMN_LABEL_CHARS,
|
|
371
|
+
MAX_ITEMS_DONE_PER_PAGE: MAX_ITEMS_DONE_PER_PAGE,
|
|
350
372
|
MAX_ATTACHMENT_BYTES: MAX_ATTACHMENT_BYTES,
|
|
351
373
|
MAX_ATTACHMENTS_PER_RUN: MAX_ATTACHMENTS_PER_RUN,
|
|
352
374
|
MAX_ATTACHMENTS_PER_LOG_ENTRY: MAX_ATTACHMENTS_PER_LOG_ENTRY,
|
|
@@ -454,7 +476,7 @@ interface TransactionPayload {
|
|
|
454
476
|
tags?: Record<string, string>;
|
|
455
477
|
release?: string;
|
|
456
478
|
environment?: EnvironmentInput;
|
|
457
|
-
/** Correlaciona esta transaction a uma execução do agente (hobots.
|
|
479
|
+
/** Correlaciona esta transaction a uma execução do agente (as etapas de hobots.step dentro do handler) */
|
|
458
480
|
run_id?: string;
|
|
459
481
|
}
|
|
460
482
|
interface HeartbeatPayload {
|
|
@@ -490,4 +512,4 @@ interface Envelope {
|
|
|
490
512
|
items: EnvelopeItem[];
|
|
491
513
|
}
|
|
492
514
|
|
|
493
|
-
export { type Breadcrumb, type BreadcrumbLevel, type Envelope, type EnvelopeItem, type Environment, type EnvironmentInput, type EventPayload, type EventType, type EventUser, type ExceptionData, type FileDownloadResponse, type FileRef, type FileStorage, type HeartbeatPayload, type InstanceInfo, type InstanceMode, type ItemColumn, type ItemsDeclaration, type MachineProcess, type MachineSnapshot, type PollRequest, type PollResponse, type RunAttachmentConfirmRequest, type RunAttachmentConfirmResponse, type RunAttachmentContentType, type RunAttachmentCreateRequest, type RunAttachmentCreateResponse, type RunCreateRequest, type RunCreateResponse, type RunDescriptor, type RunError, type RunItemInput, type RunItemStatus, type RunItemsCreateRequest, type RunItemsCreateResponse, type RunLogEntry, type RunLogLevel, type RunProgress, type RunStartRequest, type RunStartResponse, type RunStatus, type RunUpdateRequest, type RunUpdateResponse, type RunUpdateStatus, type StackFrame, type StepData, type StepStatus, type TransactionPayload, WIRE_LIMITS, type WireLimits };
|
|
515
|
+
export { type Breadcrumb, type BreadcrumbLevel, type Envelope, type EnvelopeItem, type Environment, type EnvironmentInput, type EventPayload, type EventType, type EventUser, type ExceptionData, type FileDownloadResponse, type FileRef, type FileStorage, type HeartbeatPayload, type InstanceInfo, type InstanceMode, type ItemColumn, type ItemsDeclaration, type MachineProcess, type MachineSnapshot, type PollRequest, type PollResponse, type RunAttachmentConfirmRequest, type RunAttachmentConfirmResponse, type RunAttachmentContentType, type RunAttachmentCreateRequest, type RunAttachmentCreateResponse, type RunCreateRequest, type RunCreateResponse, type RunDescriptor, type RunError, type RunItemInput, type RunItemStatus, type RunItemsCreateRequest, type RunItemsCreateResponse, type RunItemsDoneRequest, type RunItemsDoneResponse, type RunLogEntry, type RunLogLevel, type RunProgress, type RunStartRequest, type RunStartResponse, type RunStatus, type RunUpdateRequest, type RunUpdateResponse, type RunUpdateStatus, type StackFrame, type StepData, type StepStatus, type TransactionPayload, WIRE_LIMITS, type WireLimits };
|
package/dist/protocol.js
CHANGED
package/docs/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
SDK JavaScript da **Hobots** para robôs (RPAs) e integrações. Cliente HTTP puro, sem dependências de runtime, Node 18+.
|
|
4
4
|
|
|
5
|
-
**O agente é a própria tarefa.** Não existe `init()` nem slug: a única chamada a `register()`/`start()` configura o processo (credenciais do ambiente, heartbeat sempre ligado, captura de erros não tratados) e diz o que o robô faz. O objeto global `hobots` expõe a execução atual — `hobots.log`, `hobots.items`, `hobots.progress`, `hobots.
|
|
5
|
+
**O agente é a própria tarefa.** Não existe `init()` nem slug: a única chamada a `register()`/`start()` configura o processo (credenciais do ambiente, heartbeat sempre ligado, captura de erros não tratados) e diz o que o robô faz. O objeto global `hobots` expõe a execução atual — `hobots.log`, `hobots.items`, `hobots.progress`, `hobots.step`… — de qualquer lugar do programa.
|
|
6
6
|
|
|
7
7
|
| Modo | Chamada | Para quê |
|
|
8
8
|
| --- | --- | --- |
|
|
@@ -15,7 +15,7 @@ Uma chamada por processo: um processo é um agente, e um agente faz uma coisa.
|
|
|
15
15
|
|
|
16
16
|
- [Getting started](./getting-started.md) — instalação, envs, o primeiro agente nos dois modos, encerramento.
|
|
17
17
|
- [Execuções](./runs.md) — handler, o objeto `hobots`, itens, progresso, anexos, cancelamento automático, retry, concorrência, idempotência.
|
|
18
|
-
- [Conceitos](./concepts.md) — o vocabulário: agente, execução, evento, issue,
|
|
18
|
+
- [Conceitos](./concepts.md) — o vocabulário: agente, execução, evento, issue, etapa, heartbeat, instância, claim.
|
|
19
19
|
- [Referência de API](./api-reference.md) — assinaturas, tabelas de opções e tempos.
|
|
20
20
|
- [Protocolo & transporte](./protocol.md) — Client Secret, endpoints (`/v1/ingest`, `/v1/runs/*`), envelope, retries, claim atômico.
|
|
21
21
|
|
package/docs/api-reference.md
CHANGED
|
@@ -18,8 +18,9 @@ ESM e CommonJS (`const { hobots } = require('hobots')`), com `.d.ts`. Depois do
|
|
|
18
18
|
| `hobots.close` | `(timeoutMs = 30_000) => Promise<boolean>` | Para o polling, espera as execuções em voo (até `timeoutMs`; as restantes viram `AgentTerminated`), para o heartbeat e faz o flush final. `false` se estourou. Um `register`/`start` depois inicia um runtime novo. |
|
|
19
19
|
| `hobots.captureException` | `(error: unknown, hint?: CaptureHint) => string \| undefined` | Issue no módulo Issues; devolve o `event_id`. Antes de iniciar o agente: descarta com aviso. |
|
|
20
20
|
| `hobots.retry` | `<T>(fn: (attempt: number) => T \| Promise<T>, options?: RetryOptions) => Promise<T>` | async-retry; dentro de uma execução usa o signal dela. |
|
|
21
|
-
| `hobots.
|
|
22
|
-
| `hobots.
|
|
21
|
+
| `hobots.step` | `<T>(name: string, fn: (etapa: StepHandle) => T \| Promise<T>, options?: StepOptions) => Promise<T>` | Registra a etapa `name` executando `fn`, com nova tentativa quando ela lança (`retries` default 1, `retryDelayMs` default 5_000). Resolve com o retorno de `fn`. Fora de uma execução: aviso único e roda `fn` com o mesmo retry, sem registrar nada. Ver [Execuções](./runs.md#etapas-hobotsstep). |
|
|
22
|
+
| `hobots.flush` | `(timeoutMs = 15_000) => Promise<void>` | Envia **agora** o que a execução atual acumulou: etapas raiz finalizadas viram transactions parciais (op `hobots.run.flush`), itens, logs e progresso pendentes saem sem esperar o throttle. Aguarda a entrega até `timeoutMs`. Nunca lança; fora de uma execução não faz nada. Feito para o modo start, a cada ciclo. |
|
|
23
|
+
| `hobots.image` | `(input: AttachInput, options?: ImageOptions) => ImageAttachment` | Embrulha um print para ir junto de um log, item ou etapa. Puro, nunca lança. |
|
|
23
24
|
| `isFileRef` / `hobots.isFileRef` | `(value: unknown) => value is FileRef` | Reconhece um arquivo de campo de upload nos params. Puro. |
|
|
24
25
|
|
|
25
26
|
## Contexto da execução (`RunContext` — os membros de `hobots` e o `ctx` do handler)
|
|
@@ -29,11 +30,11 @@ ESM e CommonJS (`const { hobots } = require('hobots')`), com `.d.ts`. Depois do
|
|
|
29
30
|
| `runId` | `string` | Identidade da execução (`''` fora de uma execução) |
|
|
30
31
|
| `params` | `Record<string, unknown>` | Params da solicitação (formulário do agente); `{}` no modo start |
|
|
31
32
|
| `log` | `RunLogger` — `debug/info/warn/error/success(message, ...rest)` | Nunca lança. Vários argumentos viram texto unidos por espaço (como `console.log`); um `hobots.image(...)` no **último** argumento vira o print da linha. Eco no terminal: `[hobots] INFO …` |
|
|
32
|
-
| `items` | `RunItems` — `add(item)`, `succeeded(payload?, opts?)`, `failed(message, payload?, opts?)`, `occurrence(message, payload?, opts?)`; `opts.id` = identidade de negócio, `opts.image` = print do item. `each(list, (element, item, index) => …, { id?, payload?, op?, description?, progress? }) => Promise<{ total, succeeded, failed, occurrence }>` processa a lista inteira: exceção no handler vira item `failed` +
|
|
33
|
+
| `items` | `RunItems` — `add(item)`, `succeeded(payload?, opts?)`, `failed(message, payload?, opts?)`, `occurrence(message, payload?, opts?)`; `opts.id` = identidade de negócio, `opts.image` = print do item. `each(list, (element, item, index) => …, { id?, payload?, op?, description?, progress? }) => Promise<{ total, succeeded, failed, occurrence }>` processa a lista inteira: exceção no handler vira item `failed` + etapa em erro e o loop segue; `item: RunItemHandle` = `succeeded(payload?, { image }?)/failed(msg, payload?, { image }?)/occurrence(…)`, `id`, `index`, `step` (`StepHandle` da etapa do item), `reported` | Ponto de parada cooperativo (o `each` para só em cancelamento/timeout) |
|
|
33
34
|
| `progress` | `RunProgressReporter` — `total(n)`, `advance(count = 1)`, `set(current, total?)`, `current`, `snapshot` | `total/advance/set` são pontos de parada |
|
|
34
35
|
| `files` | `RunFiles` — `list(): FileRef[]`, `get(field): FileRef \| FileRef[] \| undefined`, `download(refOrField: FileRef \| string, { dest? }?): Promise<string>`, `downloadAll(field, { dest? }?): Promise<string[]>`, `read(refOrField): Promise<Buffer>` | Arquivos do formulário; o download consome a origem (S3 confirmado/apagado, pasta do Studio removida). Cópias sem `dest` são apagadas no fim da execução. Respeita o `signal`. Ver [Execuções](./runs.md#arquivos-do-formulário-hobotsfiles) |
|
|
35
|
-
| `
|
|
36
|
-
| `
|
|
36
|
+
| `step(name, fn, options?)` | `<T>(name: string, fn: StepFn<T>, options?: { retries?: number; retryDelayMs?: RetryDelay }) => Promise<T>` — uma etapa no waterfall: abre, roda `fn(etapa)`, tenta de novo se lançar (`retries` default 1; 0 desliga), fecha. `warning` + `data.message` + `data.attempts` quando a nova tentativa deu certo; `error` + `data.error = { type, message }` quando esgotou (a exceção sobe); `cancelled` em cancelamento/timeout. `StepHandle` = `warning(message, { image }?)`, `image(png)`, `data(key, value)` (`attachments` reservada). Aninha automaticamente na etapa corrente. | Ponto de parada (lança `RunCanceled`) |
|
|
37
|
+
| `flush` | `(timeoutMs = 15_000) => Promise<void>` — envia já as etapas raiz finalizadas (transactions parciais, op `hobots.run.flush`) e os itens/logs/progresso pendentes | Nunca lança |
|
|
37
38
|
| `signal` | `AbortSignal` | Cancelamento (app, timeout, shutdown) |
|
|
38
39
|
| `throwIfCanceled()` | `() => void` | Lança `RunCanceled` se o signal disparou |
|
|
39
40
|
| `sleep(ms)` | `(ms: number) => Promise<void>` | Rejeita com `RunCanceled` no cancelamento |
|
|
@@ -51,7 +52,7 @@ Só há uma chamada por processo, então todas as opções são **do agente**. O
|
|
|
51
52
|
|
|
52
53
|
| Opção | Tipo | Default | Descrição |
|
|
53
54
|
| --- | --- | --- | --- |
|
|
54
|
-
| `clientSecret` | `string` | env `HOBOTS_CLIENT_SECRET` | `hb_<64 hex>`; ausente/inválido lança citando a env (sem ecoar o valor) |
|
|
55
|
+
| `clientSecret` | `string` | env `HOBOTS_CLIENT_SECRET` | `hb_<64 hex>`; ausente/inválido lança citando a env (sem ecoar o valor). Ignorado com `HOBOTS_LOCAL_RUN=1` ([modo local](./runs.md#modo-local-teste-sem-a-central)) |
|
|
55
56
|
| `instanceId` | `string` | env `HOBOTS_INSTANCE_ID` → `os.hostname()` | identidade estável da instância |
|
|
56
57
|
| `environment` | `'development' \| 'testing' \| 'staging' \| 'production' \| string` | `'production'` | vai em eventos, transactions e na instância; filtra alertas |
|
|
57
58
|
| `release` | `string` | — | versão do programa |
|
|
@@ -79,7 +80,20 @@ Só há uma chamada por processo, então todas as opções são **do agente**. O
|
|
|
79
80
|
| --- | --- | --- | --- |
|
|
80
81
|
| `concurrency` | `number` | `1` | execuções simultâneas do agente (1..5) |
|
|
81
82
|
| `pollIntervalMs` | `number` | `2_000` (mín. 1_000) | intervalo entre polls sem trabalho |
|
|
82
|
-
| `runId` | `string` | env `HOBOTS_RUN_ID` | avançado: executa só esta run (já reivindicada para a instância, ex.: pelo Studio) em vez de fazer poll — `POST /v1/runs/{id}/start`, handler uma vez e `close()`; 404/409 encerram sem rodar o handler |
|
|
83
|
+
| `runId` | `string` | env `HOBOTS_RUN_ID` | avançado: executa só esta run (já reivindicada para a instância, ex.: pelo Studio) em vez de fazer poll — `POST /v1/runs/{id}/start`, handler uma vez e `close()`; 404/409 encerram sem rodar o handler. Ignorado no modo local |
|
|
84
|
+
|
|
85
|
+
### Envs sem opção equivalente
|
|
86
|
+
|
|
87
|
+
| Env | Efeito |
|
|
88
|
+
| --- | --- |
|
|
89
|
+
| `HOBOTS_API_URL` | só em desenvolvimento: outro host da API |
|
|
90
|
+
| `HOBOTS_LOCAL_RUN` | `1` = modo local (teste sem a Central): handler uma vez, sem rede, exit code pelo desfecho — ver [Execuções](./runs.md#modo-local-teste-sem-a-central) |
|
|
91
|
+
| `HOBOTS_RUN_PARAMS` | modo local: objeto JSON dos params (ausente = `{}`); inválido → stderr + exit 2 |
|
|
92
|
+
| `HOBOTS_LOCAL_FILES_DIR` | pasta dos arquivos `storage: 'local'` deixados pelo Studio (`<dir>/<uuid>/<nome>`) |
|
|
93
|
+
|
|
94
|
+
### CLI
|
|
95
|
+
|
|
96
|
+
`npx hobots run <entry.js> [--params <arquivo.json>] [--param <chave>=<valor>]... [--file <campo>=<caminho>]... [--reset-ledger] [-- <args do bot>]` — roda o bot no modo local com o mesmo Node; exit code do bot (2 em uso errado). Detalhes em [Execuções → Modo local](./runs.md#a-cli-hobots-run).
|
|
83
97
|
|
|
84
98
|
`StartOptions = RunOptions`.
|
|
85
99
|
|
package/docs/concepts.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Conceitos
|
|
2
2
|
|
|
3
|
-
Esta página explica **o que cada coisa é** — o vocabulário que as outras páginas usam: agente, execução, item, evento, issue,
|
|
3
|
+
Esta página explica **o que cada coisa é** — o vocabulário que as outras páginas usam: agente, execução, item, evento, issue, etapa, heartbeat, instância, claim. As outras páginas mostram **como usar**; aqui está o **por que existe**.
|
|
4
4
|
|
|
5
5
|
Defaults numéricos vivem em [Tempos e intervalos](./api-reference.md#tempos-e-intervalos) e nas [tabelas de opções](./api-reference.md#tabelas-de-opções).
|
|
6
6
|
|
|
@@ -15,11 +15,11 @@ Defaults numéricos vivem em [Tempos e intervalos](./api-reference.md#tempos-e-i
|
|
|
15
15
|
| [Item](#item) | Uma unidade de trabalho entregue | Cada nota, boleto, arquivo processado |
|
|
16
16
|
| [Progresso](#progresso) | Quantos de quantos | Barra e tempo restante no app |
|
|
17
17
|
| [Log da execução](#log-da-execução) | Narração do que a execução fez | `hobots.log` — nunca lança |
|
|
18
|
-
| [Anexo](#anexo) | Um print pendurado num log, item ou
|
|
19
|
-
| [Cancelamento cooperativo](#cancelamento-cooperativo) | O app pede, o handler para no próximo ponto de parada | Automático em items/progress/
|
|
18
|
+
| [Anexo](#anexo) | Um print pendurado num log, item ou etapa | "Como estava a tela?" |
|
|
19
|
+
| [Cancelamento cooperativo](#cancelamento-cooperativo) | O app pede, o handler para no próximo ponto de parada | Automático em items/progress/step/sleep/retry |
|
|
20
20
|
| [Retry](#retry) | Tentar de novo na mesma execução | Instabilidade passageira |
|
|
21
21
|
| [Evento e issue](#evento-e-issue) | A foto de um erro, agrupada em issue | `hobots.captureException` e erros não tratados |
|
|
22
|
-
| [
|
|
22
|
+
| [Etapa](#etapa) (e a [transaction](#transaction) por trás) | Quanto demorou e onde o tempo foi — com nova tentativa | `hobots.step` |
|
|
23
23
|
| [Heartbeat](#heartbeat) | Batimento "estou vivo", sempre ligado | Saber que o robô está de pé |
|
|
24
24
|
| [instanceId](#instanceid) | A identidade da instância do robô | Env `HOBOTS_INSTANCE_ID` |
|
|
25
25
|
| [Release e environment](#release-e-environment) | Qual versão, em qual ambiente | Separar produção de homologação |
|
|
@@ -35,7 +35,7 @@ Defaults numéricos vivem em [Tempos e intervalos](./api-reference.md#tempos-e-i
|
|
|
35
35
|
| **Instância** — o par `(agente, instanceId)`; heartbeat e execuções convergem nela, com o modo (sob demanda / sempre ligado) | Módulo **Instâncias** (uptime, recursos da máquina, performance) |
|
|
36
36
|
| **Execução** — cada solicitação atendida por `register()`, ou a execução que `start()` abre sozinho | Módulo **Trabalhos** |
|
|
37
37
|
| **Evento** agrupado em **issue** — `captureException` e erros não tratados | Módulo **Issues** |
|
|
38
|
-
| **
|
|
38
|
+
| **Etapas** — `hobots.step` | Aba de performance da execução (waterfall) |
|
|
39
39
|
|
|
40
40
|
---
|
|
41
41
|
|
|
@@ -75,11 +75,11 @@ O **log da execução** narra o que aconteceu, em linhas com nível (`debug`, `i
|
|
|
75
75
|
|
|
76
76
|
## Anexo
|
|
77
77
|
|
|
78
|
-
Um **anexo** é uma imagem — na prática, um print — vinculada ao evento que ela ilustra: uma linha de log, um item ou uma
|
|
78
|
+
Um **anexo** é uma imagem — na prática, um print — vinculada ao evento que ela ilustra: uma linha de log, um item ou uma etapa. Responde "como estava a tela?" quando texto não basta. Quem captura é o seu código (Playwright, Puppeteer, um arquivo); o SDK sobe direto para o S3 por URL presignada, em segundo plano, sem atrasar o log. Enquanto sobe, o app mostra "enviando imagem…".
|
|
79
79
|
|
|
80
80
|
## Cancelamento cooperativo
|
|
81
81
|
|
|
82
|
-
Cancelar no app **não mata** o handler — o SDK não tem como interromper código arbitrário com segurança (um navegador aberto, uma transação pela metade). O que ele faz: detecta o cancelamento (o PATCH periódico recebe 409), dispara `hobots.signal` e faz o próximo **ponto de parada** lançar `RunCanceled`. Os pontos de parada são as fronteiras naturais de trabalho: registrar um item, avançar o progresso, abrir uma
|
|
82
|
+
Cancelar no app **não mata** o handler — o SDK não tem como interromper código arbitrário com segurança (um navegador aberto, uma transação pela metade). O que ele faz: detecta o cancelamento (o PATCH periódico recebe 409), dispara `hobots.signal` e faz o próximo **ponto de parada** lançar `RunCanceled`. Os pontos de parada são as fronteiras naturais de trabalho: registrar um item, avançar o progresso, abrir uma etapa, dormir, tentar de novo. Por isso, num loop comum, o cancelamento funciona sem nenhuma linha extra. `hobots.log` nunca é ponto de parada. Se o handler ignorar o signal por tempo demais (`cancelGraceMs`), o SDK libera o slot e o handler vira um zumbi cujos reportes são descartados.
|
|
83
83
|
|
|
84
84
|
## Retry
|
|
85
85
|
|
|
@@ -89,13 +89,13 @@ Uma falha do handler costuma ser passageira (portal instável, rede). O SDK **te
|
|
|
89
89
|
|
|
90
90
|
Um **evento** é a foto de um erro: tipo, mensagem, stack trace, tags, ambiente, release e como estava a máquina. `hobots.captureException(erro)` cria um; erros não tratados (`uncaughtException`, `unhandledRejection`) também. Eventos parecidos são agrupados em uma **issue** pelo servidor (por stack trace, ou pelo `fingerprint` que você definir). O `type` diz o que ele é: `fatal`, `error` e `warning` abrem issue e podem alertar; `success` é registrado e nunca alerta. Log não é evento — narração fica no log da execução.
|
|
91
91
|
|
|
92
|
-
##
|
|
92
|
+
## Etapa
|
|
93
93
|
|
|
94
|
-
Uma **
|
|
94
|
+
Uma **etapa** é um trecho medido da execução com nome de negócio — "Entrar no portal", "Buscar pedido 123". A execução diz que levou 4 minutos; as etapas dizem que 3min40 foram esperando o portal. `hobots.step(nome, fn)` é a única chamada: o SDK abre a etapa, roda `fn`, **tenta de novo** se ela lançar (1 tentativa extra por padrão; `retries: 0` desliga) e fecha. Uma etapa só na Central cobre todas as tentativas: `warning` com o motivo quando a nova tentativa deu certo (e `attempts`), `error` quando esgotou (a exceção sobe), `cancelled` em cancelamento/timeout. `hobots.step` dentro de outra etapa vira sub-etapa; dentro do handler de `items.each`, sub-etapa da etapa do item. A função recebe o handle `etapa` para o que o SDK não vê sozinho: `warning(motivo)`, `image(png)`, `data(chave, valor)`. No app isso vira o **waterfall** da execução. Abrir uma etapa é um ponto de parada cooperativo. A etapa não entra no aviso de erro no topo do trabalho — ela aparece na aba de performance.
|
|
95
95
|
|
|
96
|
-
##
|
|
96
|
+
## Transaction
|
|
97
97
|
|
|
98
|
-
Uma **
|
|
98
|
+
Uma **transaction** é o envelope do wire que carrega as etapas: cada execução tem exatamente uma, chamada `run` (op `hobots.run`), aberta e finalizada pelo SDK e correlacionada à execução pelo `run_id`. Você não a vê nem cria — só registra etapas com `hobots.step`. Num agente sempre ligado, `hobots.flush()` envia as etapas raiz já terminadas como transactions parciais (op `hobots.run.flush`).
|
|
99
99
|
|
|
100
100
|
## Heartbeat
|
|
101
101
|
|
package/docs/getting-started.md
CHANGED
|
@@ -76,4 +76,4 @@ O robô abre a própria execução ao iniciar e ela aparece em **Trabalhos** com
|
|
|
76
76
|
|
|
77
77
|
`hobots.close(timeoutMs?)` para o polling, espera as execuções em voo, para o heartbeat e faz o flush final. Sem handler próprio de `SIGINT`/`SIGTERM`, o SDK reporta as execuções ativas como `AgentTerminated` antes do processo morrer.
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
A seguir: [Execuções](./runs.md) para etapas, itens, progresso, anexos, cancelamento e retry; [Referência de API](./api-reference.md) para todas as opções.
|
package/docs/protocol.md
CHANGED
|
@@ -38,7 +38,7 @@ Endpoint fixo `POST /v1/ingest` recebe **envelopes** JSON autenticados por Beare
|
|
|
38
38
|
|
|
39
39
|
Tipos de item: `event`, `transaction`, `heartbeat` (definidos em `hobots/protocol`).
|
|
40
40
|
|
|
41
|
-
Todo `transaction` carrega `run_id`: é assim que a [transaction da execução](./concepts.md#transaction) (`hobots.
|
|
41
|
+
Todo `transaction` carrega `run_id`: é assim que a [transaction da execução](./concepts.md#transaction) (aberta pelo SDK; as etapas vêm de `hobots.step`) é correlacionada, e o que permite o app montar o waterfall de performance dentro da solicitação. Cada etapa (`StepData`) vai sem `op`, com `description` = nome (recortado em 2048 no cliente) e, quando houve mais de uma tentativa, `data.attempts`.
|
|
42
42
|
|
|
43
43
|
`items` aceita de 1 a **50** itens por envelope — acima disso a API responde `422`. O `maxBatchSize` é só o gatilho do flush: quando a fila tem mais que esse teto (burst de captures, ou fila acumulada durante uma janela de rede ruim), o transport a fatia em lotes de 50 e faz um POST por lote.
|
|
44
44
|
|
|
@@ -165,7 +165,7 @@ Corpo `RunItemsCreateRequest`:
|
|
|
165
165
|
|
|
166
166
|
Resposta `200` `RunItemsCreateResponse`: `{ "accepted": 1, "duplicates": 0 }` — `duplicates` conta os colapsados por `(run, id)` repetido no mesmo lote (vale o último reporte; no banco é upsert).
|
|
167
167
|
|
|
168
|
-
- `attachments` é **opcional** e aditivo (uma API anterior ao recurso descarta o campo). As
|
|
168
|
+
- `attachments` é **opcional** e aditivo (uma API anterior ao recurso descarta o campo). As etapas carregam o print do mesmo jeito, em `data.attachments` do `StepData` que vai no `POST /v1/ingest` da transaction — sem campo novo no wire.
|
|
169
169
|
|
|
170
170
|
- **Run cancelada/terminal aceita itens** (200): item é fato de trabalho já feito — mesmo racional do log tardio. Esta rota não tem 409.
|
|
171
171
|
- O insert e os **contadores materializados** da run (`items_total/succeeded/failed/occurrence`, que alimentam os totalizadores no app) saem num único statement atômico no servidor.
|
|
@@ -187,11 +187,11 @@ Corpo `RunAttachmentCreateRequest`:
|
|
|
187
187
|
|
|
188
188
|
```jsonc
|
|
189
189
|
{
|
|
190
|
-
"id": "<32 hex>", // gerado pelo agente, já referenciado no log/item/
|
|
190
|
+
"id": "<32 hex>", // gerado pelo agente, já referenciado no log/item/etapa
|
|
191
191
|
"content_type": "image/png", // 'image/png' | 'image/jpeg' | 'image/webp'
|
|
192
192
|
"size_bytes": 184320, // exato — entra na assinatura da URL
|
|
193
193
|
"caption": "portal após o login", // opcional, máx. 500
|
|
194
|
-
"log_ts": "…", // opcional, ISO 8601 — ts do evento (log/item/
|
|
194
|
+
"log_ts": "…", // opcional, ISO 8601 — ts do evento (log/item/etapa)
|
|
195
195
|
"width": 1920, "height": 1080 // opcionais
|
|
196
196
|
}
|
|
197
197
|
```
|
|
@@ -226,7 +226,7 @@ Confirma o upload. Corpo `RunAttachmentConfirmRequest`: `{ "status": "uploaded"
|
|
|
226
226
|
|
|
227
227
|
É **conforto de UX**, não correção: enquanto não confirmado, o app mostra a miniatura como "enviando imagem…". O agente engole falhas desta chamada.
|
|
228
228
|
|
|
229
|
-
Limites de anexo (aplicados no SDK **e** no servidor): PNG/JPEG/WEBP, 5 MB por imagem, 20 por execução, 4 por evento (linha de log, item ou
|
|
229
|
+
Limites de anexo (aplicados no SDK **e** no servidor): PNG/JPEG/WEBP, 5 MB por imagem, 20 por execução, 4 por evento (linha de log, item ou etapa).
|
|
230
230
|
|
|
231
231
|
### `POST /v1/runs/{id}/files/{fileId}/download`
|
|
232
232
|
|