hobots 2.3.0 → 3.0.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 +112 -369
- package/dist/index.cjs +1233 -852
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +223 -205
- package/dist/index.d.ts +223 -205
- package/dist/index.js +1233 -852
- package/dist/index.js.map +1 -1
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +43 -4
- package/dist/protocol.d.ts +43 -4
- package/docs/README.md +16 -33
- package/docs/api-reference.md +74 -213
- package/docs/concepts.md +60 -389
- package/docs/getting-started.md +38 -84
- package/docs/protocol.md +29 -19
- package/docs/tasks.md +92 -251
- package/package.json +2 -2
- package/docs/telemetry.md +0 -162
package/dist/protocol.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/protocol.ts"],"sourcesContent":["/**\n * Tipos do protocolo do Hobots (SDK → servidor).\n *\n * Este arquivo é a fonte de verdade do wire format e só pode reexportar tipos:\n * o app valida os payloads com zod e trava o drift via `satisfies z.ZodType<...>`\n * contra estes tipos (importados de `hobots/protocol`).\n */\n\nimport type { MachineSnapshot } from './machine-protocol';\n\n// Wire format de tasks (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 RunError,\n RunProgress,\n RunUpdateRequest,\n RunUpdateResponse,\n RunItemStatus,\n RunItemInput,\n RunItemsCreateRequest,\n RunItemsCreateResponse,\n RunAttachmentContentType,\n RunAttachmentCreateRequest,\n RunAttachmentCreateResponse,\n RunAttachmentConfirmRequest,\n RunAttachmentConfirmResponse,\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';\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?:
|
|
1
|
+
{"version":3,"sources":["../src/protocol.ts"],"sourcesContent":["/**\n * Tipos do protocolo do Hobots (SDK → servidor).\n *\n * Este arquivo é a fonte de verdade do wire format e só pode reexportar tipos:\n * o app valida os payloads com zod e trava o drift via `satisfies z.ZodType<...>`\n * contra estes tipos (importados de `hobots/protocol`).\n */\n\nimport type { EnvironmentInput } from './environment-protocol';\nimport type { MachineSnapshot } from './machine-protocol';\n\n// Wire format de tasks (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 RunError,\n RunProgress,\n RunUpdateRequest,\n RunUpdateResponse,\n RunItemStatus,\n RunItemInput,\n RunItemsCreateRequest,\n RunItemsCreateResponse,\n RunAttachmentContentType,\n RunAttachmentCreateRequest,\n RunAttachmentCreateResponse,\n RunAttachmentConfirmRequest,\n RunAttachmentConfirmResponse,\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 de task (ctx.tx dentro de um task 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"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/dist/protocol.d.cts
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ambiente lógico onde o robô roda.
|
|
3
|
+
*
|
|
4
|
+
* Arquivo-folha do protocolo (não importa nada): referenciado pelo heartbeat, pelo
|
|
5
|
+
* poll de tasks (`InstanceInfo.environment`) e pelos eventos/transactions, e
|
|
6
|
+
* reexportado por `hobots/protocol`.
|
|
7
|
+
*
|
|
8
|
+
* A fonte única do vocabulário (rótulos em pt-BR, apelidos legados aceitos e a
|
|
9
|
+
* normalização) vive no servidor, em packages/utils/src/environments.ts — o SDK é
|
|
10
|
+
* publicado sozinho no npm e não depende do monorepo, então o union é redeclarado
|
|
11
|
+
* aqui. O servidor normaliza o que chega: valores antigos de texto livre ('prod',
|
|
12
|
+
* 'qa', 'homologacao') continuam sendo aceitos e classificados.
|
|
13
|
+
*/
|
|
14
|
+
type Environment = 'development' | 'testing' | 'staging' | 'production';
|
|
15
|
+
/**
|
|
16
|
+
* O que o wire realmente aceita: o ambiente canônico ou uma string legada que o
|
|
17
|
+
* servidor normaliza ('prod', 'qa', 'homologacao'...). O `string & {}` preserva o
|
|
18
|
+
* autocomplete dos quatro valores sem fechar a porta para o que já roda em campo
|
|
19
|
+
* — e mantém os `satisfies z.ZodType<...>` da api fechando contra `z.string()`.
|
|
20
|
+
*/
|
|
21
|
+
type EnvironmentInput = Environment | (string & {});
|
|
22
|
+
|
|
1
23
|
/**
|
|
2
24
|
* Snapshot dos recursos da máquina onde a instância roda.
|
|
3
25
|
*
|
|
@@ -82,6 +104,8 @@ interface InstanceInfo {
|
|
|
82
104
|
version?: string;
|
|
83
105
|
/** Hostname da máquina */
|
|
84
106
|
host?: string;
|
|
107
|
+
/** Ambiente da instância — mesmo valor do heartbeat; agentes poll-only só o informam aqui */
|
|
108
|
+
environment?: EnvironmentInput;
|
|
85
109
|
/** Tasks registradas no agente */
|
|
86
110
|
tasks?: string[];
|
|
87
111
|
/**
|
|
@@ -108,7 +132,7 @@ interface RunDescriptor {
|
|
|
108
132
|
id: string;
|
|
109
133
|
name: string;
|
|
110
134
|
} | null;
|
|
111
|
-
/** Origem da run: 'hobots' | 'link' | 'schedule' (informativo) */
|
|
135
|
+
/** Origem da run: 'hobots' | 'link' | 'schedule' | 'agent' (informativo; 'agent' = aberta pelo próprio SDK, modo start) */
|
|
112
136
|
source: string;
|
|
113
137
|
/** ISO 8601 (relógio do servidor) */
|
|
114
138
|
created_at: string;
|
|
@@ -116,6 +140,19 @@ interface RunDescriptor {
|
|
|
116
140
|
interface PollResponse {
|
|
117
141
|
runs: RunDescriptor[];
|
|
118
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* POST /v1/tasks/runs — modo start do SDK: a própria instância abre a run, que já
|
|
145
|
+
* nasce 'running' (started_at = now), sem formulário nem solicitante. Dali em diante
|
|
146
|
+
* ela é reportada pelas mesmas rotas de uma run reivindicada no poll.
|
|
147
|
+
*/
|
|
148
|
+
interface RunCreateRequest {
|
|
149
|
+
/** slug da task (1..255) — vira task_runs.task_slug */
|
|
150
|
+
task: string;
|
|
151
|
+
/** presença da instância — obrigatória: a run nasce vinculada à instância */
|
|
152
|
+
instance: InstanceInfo;
|
|
153
|
+
}
|
|
154
|
+
/** Resposta (201): o mesmo descritor do poll, com params {}, form null e source 'agent'. */
|
|
155
|
+
type RunCreateResponse = RunDescriptor;
|
|
119
156
|
interface RunError {
|
|
120
157
|
/** ex.: nome da classe do erro */
|
|
121
158
|
type?: string;
|
|
@@ -275,7 +312,7 @@ interface EventPayload {
|
|
|
275
312
|
contexts?: Record<string, Record<string, unknown>>;
|
|
276
313
|
extra?: Record<string, unknown>;
|
|
277
314
|
release?: string;
|
|
278
|
-
environment?:
|
|
315
|
+
environment?: EnvironmentInput;
|
|
279
316
|
}
|
|
280
317
|
/** Status de uma step (etapa). `warning` = terminou, mas merece atenção (não é falha). */
|
|
281
318
|
type StepStatus = 'ok' | 'warning' | 'error' | 'cancelled';
|
|
@@ -302,7 +339,7 @@ interface TransactionPayload {
|
|
|
302
339
|
steps: StepData[];
|
|
303
340
|
tags?: Record<string, string>;
|
|
304
341
|
release?: string;
|
|
305
|
-
environment?:
|
|
342
|
+
environment?: EnvironmentInput;
|
|
306
343
|
/** Correlaciona esta transaction a uma execução de task (ctx.tx dentro de um task handler) */
|
|
307
344
|
run_id?: string;
|
|
308
345
|
}
|
|
@@ -314,6 +351,8 @@ interface HeartbeatPayload {
|
|
|
314
351
|
timestamp: string;
|
|
315
352
|
metadata?: Record<string, unknown>;
|
|
316
353
|
release?: string;
|
|
354
|
+
/** Ambiente da instância — é ele que o app exibe e que as regras de alerta filtram */
|
|
355
|
+
environment?: EnvironmentInput;
|
|
317
356
|
/** Recursos da máquina no momento do beat (CPU, memória, disco, processo) */
|
|
318
357
|
machine?: MachineSnapshot;
|
|
319
358
|
}
|
|
@@ -337,4 +376,4 @@ interface Envelope {
|
|
|
337
376
|
items: EnvelopeItem[];
|
|
338
377
|
}
|
|
339
378
|
|
|
340
|
-
export type { Breadcrumb, BreadcrumbLevel, Envelope, EnvelopeItem, EventPayload, EventType, EventUser, ExceptionData, HeartbeatPayload, InstanceInfo, MachineProcess, MachineSnapshot, PollRequest, PollResponse, RunAttachmentConfirmRequest, RunAttachmentConfirmResponse, RunAttachmentContentType, RunAttachmentCreateRequest, RunAttachmentCreateResponse, RunDescriptor, RunError, RunItemInput, RunItemStatus, RunItemsCreateRequest, RunItemsCreateResponse, RunLogEntry, RunLogLevel, RunProgress, RunStatus, RunUpdateRequest, RunUpdateResponse, RunUpdateStatus, StackFrame, StepData, StepStatus, TransactionPayload };
|
|
379
|
+
export type { Breadcrumb, BreadcrumbLevel, Envelope, EnvelopeItem, Environment, EnvironmentInput, EventPayload, EventType, EventUser, ExceptionData, HeartbeatPayload, InstanceInfo, MachineProcess, MachineSnapshot, PollRequest, PollResponse, RunAttachmentConfirmRequest, RunAttachmentConfirmResponse, RunAttachmentContentType, RunAttachmentCreateRequest, RunAttachmentCreateResponse, RunCreateRequest, RunCreateResponse, RunDescriptor, RunError, RunItemInput, RunItemStatus, RunItemsCreateRequest, RunItemsCreateResponse, RunLogEntry, RunLogLevel, RunProgress, RunStatus, RunUpdateRequest, RunUpdateResponse, RunUpdateStatus, StackFrame, StepData, StepStatus, TransactionPayload };
|
package/dist/protocol.d.ts
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ambiente lógico onde o robô roda.
|
|
3
|
+
*
|
|
4
|
+
* Arquivo-folha do protocolo (não importa nada): referenciado pelo heartbeat, pelo
|
|
5
|
+
* poll de tasks (`InstanceInfo.environment`) e pelos eventos/transactions, e
|
|
6
|
+
* reexportado por `hobots/protocol`.
|
|
7
|
+
*
|
|
8
|
+
* A fonte única do vocabulário (rótulos em pt-BR, apelidos legados aceitos e a
|
|
9
|
+
* normalização) vive no servidor, em packages/utils/src/environments.ts — o SDK é
|
|
10
|
+
* publicado sozinho no npm e não depende do monorepo, então o union é redeclarado
|
|
11
|
+
* aqui. O servidor normaliza o que chega: valores antigos de texto livre ('prod',
|
|
12
|
+
* 'qa', 'homologacao') continuam sendo aceitos e classificados.
|
|
13
|
+
*/
|
|
14
|
+
type Environment = 'development' | 'testing' | 'staging' | 'production';
|
|
15
|
+
/**
|
|
16
|
+
* O que o wire realmente aceita: o ambiente canônico ou uma string legada que o
|
|
17
|
+
* servidor normaliza ('prod', 'qa', 'homologacao'...). O `string & {}` preserva o
|
|
18
|
+
* autocomplete dos quatro valores sem fechar a porta para o que já roda em campo
|
|
19
|
+
* — e mantém os `satisfies z.ZodType<...>` da api fechando contra `z.string()`.
|
|
20
|
+
*/
|
|
21
|
+
type EnvironmentInput = Environment | (string & {});
|
|
22
|
+
|
|
1
23
|
/**
|
|
2
24
|
* Snapshot dos recursos da máquina onde a instância roda.
|
|
3
25
|
*
|
|
@@ -82,6 +104,8 @@ interface InstanceInfo {
|
|
|
82
104
|
version?: string;
|
|
83
105
|
/** Hostname da máquina */
|
|
84
106
|
host?: string;
|
|
107
|
+
/** Ambiente da instância — mesmo valor do heartbeat; agentes poll-only só o informam aqui */
|
|
108
|
+
environment?: EnvironmentInput;
|
|
85
109
|
/** Tasks registradas no agente */
|
|
86
110
|
tasks?: string[];
|
|
87
111
|
/**
|
|
@@ -108,7 +132,7 @@ interface RunDescriptor {
|
|
|
108
132
|
id: string;
|
|
109
133
|
name: string;
|
|
110
134
|
} | null;
|
|
111
|
-
/** Origem da run: 'hobots' | 'link' | 'schedule' (informativo) */
|
|
135
|
+
/** Origem da run: 'hobots' | 'link' | 'schedule' | 'agent' (informativo; 'agent' = aberta pelo próprio SDK, modo start) */
|
|
112
136
|
source: string;
|
|
113
137
|
/** ISO 8601 (relógio do servidor) */
|
|
114
138
|
created_at: string;
|
|
@@ -116,6 +140,19 @@ interface RunDescriptor {
|
|
|
116
140
|
interface PollResponse {
|
|
117
141
|
runs: RunDescriptor[];
|
|
118
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* POST /v1/tasks/runs — modo start do SDK: a própria instância abre a run, que já
|
|
145
|
+
* nasce 'running' (started_at = now), sem formulário nem solicitante. Dali em diante
|
|
146
|
+
* ela é reportada pelas mesmas rotas de uma run reivindicada no poll.
|
|
147
|
+
*/
|
|
148
|
+
interface RunCreateRequest {
|
|
149
|
+
/** slug da task (1..255) — vira task_runs.task_slug */
|
|
150
|
+
task: string;
|
|
151
|
+
/** presença da instância — obrigatória: a run nasce vinculada à instância */
|
|
152
|
+
instance: InstanceInfo;
|
|
153
|
+
}
|
|
154
|
+
/** Resposta (201): o mesmo descritor do poll, com params {}, form null e source 'agent'. */
|
|
155
|
+
type RunCreateResponse = RunDescriptor;
|
|
119
156
|
interface RunError {
|
|
120
157
|
/** ex.: nome da classe do erro */
|
|
121
158
|
type?: string;
|
|
@@ -275,7 +312,7 @@ interface EventPayload {
|
|
|
275
312
|
contexts?: Record<string, Record<string, unknown>>;
|
|
276
313
|
extra?: Record<string, unknown>;
|
|
277
314
|
release?: string;
|
|
278
|
-
environment?:
|
|
315
|
+
environment?: EnvironmentInput;
|
|
279
316
|
}
|
|
280
317
|
/** Status de uma step (etapa). `warning` = terminou, mas merece atenção (não é falha). */
|
|
281
318
|
type StepStatus = 'ok' | 'warning' | 'error' | 'cancelled';
|
|
@@ -302,7 +339,7 @@ interface TransactionPayload {
|
|
|
302
339
|
steps: StepData[];
|
|
303
340
|
tags?: Record<string, string>;
|
|
304
341
|
release?: string;
|
|
305
|
-
environment?:
|
|
342
|
+
environment?: EnvironmentInput;
|
|
306
343
|
/** Correlaciona esta transaction a uma execução de task (ctx.tx dentro de um task handler) */
|
|
307
344
|
run_id?: string;
|
|
308
345
|
}
|
|
@@ -314,6 +351,8 @@ interface HeartbeatPayload {
|
|
|
314
351
|
timestamp: string;
|
|
315
352
|
metadata?: Record<string, unknown>;
|
|
316
353
|
release?: string;
|
|
354
|
+
/** Ambiente da instância — é ele que o app exibe e que as regras de alerta filtram */
|
|
355
|
+
environment?: EnvironmentInput;
|
|
317
356
|
/** Recursos da máquina no momento do beat (CPU, memória, disco, processo) */
|
|
318
357
|
machine?: MachineSnapshot;
|
|
319
358
|
}
|
|
@@ -337,4 +376,4 @@ interface Envelope {
|
|
|
337
376
|
items: EnvelopeItem[];
|
|
338
377
|
}
|
|
339
378
|
|
|
340
|
-
export type { Breadcrumb, BreadcrumbLevel, Envelope, EnvelopeItem, EventPayload, EventType, EventUser, ExceptionData, HeartbeatPayload, InstanceInfo, MachineProcess, MachineSnapshot, PollRequest, PollResponse, RunAttachmentConfirmRequest, RunAttachmentConfirmResponse, RunAttachmentContentType, RunAttachmentCreateRequest, RunAttachmentCreateResponse, RunDescriptor, RunError, RunItemInput, RunItemStatus, RunItemsCreateRequest, RunItemsCreateResponse, RunLogEntry, RunLogLevel, RunProgress, RunStatus, RunUpdateRequest, RunUpdateResponse, RunUpdateStatus, StackFrame, StepData, StepStatus, TransactionPayload };
|
|
379
|
+
export type { Breadcrumb, BreadcrumbLevel, Envelope, EnvelopeItem, Environment, EnvironmentInput, EventPayload, EventType, EventUser, ExceptionData, HeartbeatPayload, InstanceInfo, MachineProcess, MachineSnapshot, PollRequest, PollResponse, RunAttachmentConfirmRequest, RunAttachmentConfirmResponse, RunAttachmentContentType, RunAttachmentCreateRequest, RunAttachmentCreateResponse, RunCreateRequest, RunCreateResponse, RunDescriptor, RunError, RunItemInput, RunItemStatus, RunItemsCreateRequest, RunItemsCreateResponse, RunLogEntry, RunLogLevel, RunProgress, RunStatus, RunUpdateRequest, RunUpdateResponse, RunUpdateStatus, StackFrame, StepData, StepStatus, TransactionPayload };
|
package/docs/README.md
CHANGED
|
@@ -1,49 +1,32 @@
|
|
|
1
1
|
# Documentação — hobots
|
|
2
2
|
|
|
3
|
-
SDK JavaScript da **Hobots** para
|
|
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
|
-
|
|
5
|
+
**Tudo é uma task.** Não existe `init()`: a primeira chamada a `register()`/`start()` configura o processo (credenciais do ambiente, heartbeat sempre ligado, captura de erros não tratados). O objeto global `hobots` expõe a execução atual — `hobots.log`, `hobots.items`, `hobots.progress`, `hobots.transaction`… — de qualquer lugar do programa.
|
|
6
6
|
|
|
7
|
-
|
|
|
7
|
+
| Modo | Chamada | Para quê |
|
|
8
8
|
| --- | --- | --- |
|
|
9
|
-
| **
|
|
10
|
-
| **
|
|
9
|
+
| **Sob demanda** | `hobots.register(task, handler, options?)` | O robô faz polling e executa uma solicitação do app (formulário/agendamento) por vez — módulo **Solicitações**. |
|
|
10
|
+
| **Sempre ligado** | `hobots.start(task, handler, options?)` | O robô abre a própria execução e roda o handler (o seu loop) dentro dela; a plataforma recebe logs, itens e progresso. |
|
|
11
11
|
|
|
12
12
|
## Páginas
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
- [Conceitos](./concepts.md) — o vocabulário:
|
|
17
|
-
- [
|
|
18
|
-
- [
|
|
19
|
-
- [Tasks](./tasks.md) — registro de handlers, `RunContext`, cancelamento, concorrência, idempotência.
|
|
20
|
-
- [Referência de API](./api-reference.md) — todas as funções e tabelas de opções com defaults.
|
|
21
|
-
- [Protocolo & transporte](./protocol.md) — o Client Secret, endpoints, envelope, retries e onde vive o claim atômico.
|
|
14
|
+
- [Getting started](./getting-started.md) — instalação, envs, primeira task nos dois modos, encerramento.
|
|
15
|
+
- [Tasks](./tasks.md) — handler, o objeto `hobots`, itens, progresso, anexos, cancelamento automático, retry, concorrência, idempotência.
|
|
16
|
+
- [Conceitos](./concepts.md) — o vocabulário: task, execução, evento, issue, transaction, step, heartbeat, instância, claim.
|
|
17
|
+
- [Referência de API](./api-reference.md) — assinaturas, tabelas de opções e tempos.
|
|
18
|
+
- [Protocolo & transporte](./protocol.md) — Client Secret, endpoints (`/v1/ingest`, `/v1/tasks/*`), envelope, retries, claim atômico.
|
|
22
19
|
|
|
23
20
|
## Exemplo mínimo
|
|
24
21
|
|
|
25
22
|
```js
|
|
26
|
-
import
|
|
27
|
-
|
|
28
|
-
// O Client Secret do agente — copie em Configurações → Agentes no app
|
|
29
|
-
const clientSecret = 'hb_<64 hex>';
|
|
30
|
-
|
|
31
|
-
// Um init só: telemetria sempre ativa; tasks habilita a execução sob demanda.
|
|
32
|
-
// O instanceId é a identidade única — o robô aparece como um agente só no painel.
|
|
33
|
-
Hobots.init({
|
|
34
|
-
clientSecret,
|
|
35
|
-
instanceId: 'vm-cliente-01',
|
|
36
|
-
heartbeat: true,
|
|
37
|
-
tasks: true,
|
|
38
|
-
});
|
|
23
|
+
import hobots from 'hobots'; // HOBOTS_CLIENT_SECRET e HOBOTS_INSTANCE_ID no ambiente
|
|
39
24
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
25
|
+
hobots.register('processar-nfe', async params => {
|
|
26
|
+
hobots.log.info(`processando lote ${params.lote}…`);
|
|
27
|
+
hobots.items.succeeded({ numero_nota: '123' }, { id: '123' });
|
|
28
|
+
hobots.log.success('concluído'); // o retorno do handler é ignorado — reporte por log/itens
|
|
43
29
|
});
|
|
44
|
-
Hobots.start(); // mantém o processo vivo aguardando execuções
|
|
45
30
|
```
|
|
46
31
|
|
|
47
|
-
> Exemplos runnable
|
|
48
|
-
> [`full.ts`](../../hobots-sdk-demos/src/full.ts)) estão em
|
|
49
|
-
> [`packages/hobots-sdk-demos`](../../hobots-sdk-demos).
|
|
32
|
+
> Exemplos runnable em [`packages/hobots-sdk-demos`](../../hobots-sdk-demos).
|