@zihin/agent-client 0.7.0 → 0.9.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 CHANGED
@@ -23,7 +23,8 @@ simples, e oferece **dois estilos** de invocação:
23
23
  npm install @zihin/agent-client
24
24
  ```
25
25
 
26
- Requer Node >= 18 (usa `fetch`/`ReadableStream` globais).
26
+ Requer Node >= 20.16 (usa `fetch`/`ReadableStream` globais; o `signRequest` do build ESM usa
27
+ `process.getBuiltinModule`, 20.16+). Node 18 saiu de suporte em 04/2025 e deixou de ser testado a partir da 0.8.
27
28
 
28
29
  ## Uso — caminho direto
29
30
 
@@ -418,7 +419,7 @@ correlacionar com o console.
418
419
  `delayMs`/`reason`/`status`) e `onError(err)` — chamado quando uma operação falha em definitivo
419
420
  (inclusive `aborted`; filtre por `err.kind`). Exceção lançada dentro do hook é engolida e nunca
420
421
  mascara o erro original.
421
- - **`fetch` injetável** — `fetch?` na config; por padrão usa `globalThis.fetch` (Node ≥18). Um
422
+ - **`fetch` injetável** — `fetch?` na config; por padrão usa `globalThis.fetch` (Node ≥20.16). Um
422
423
  preflight dá erro `config` claro se não houver fetch.
423
424
  - **Portável** — sem `Buffer`; `node:crypto` só é carregado se você usar `signRequest`. Roda em Node;
424
425
  para edge/serverless, injete `fetch` se necessário. O pacote publica **CJS e ESM** (`exports` map):
@@ -447,6 +448,29 @@ const zihin = createClient({
447
448
  > um host que **resolva** para IP privado (DNS rebinding) passa. Isto não substitui bloqueio de
448
449
  > egresso na borda de rede — mantenha o whitelist (default) em ambiente sensível.
449
450
 
451
+ ## Runtime injetável (`@zihin/agent-client/core`)
452
+
453
+ O entry principal já usa os timers globais e `process.emitWarning` — nada muda para quem importa
454
+ `@zihin/agent-client`. O entry `@zihin/agent-client/core` é o mesmo núcleo **sem** essas
455
+ referências globais, para hosts que as proíbem no código publicado (o scanner de nó verificado do
456
+ n8n reprova `setTimeout`, `globalThis`, `process` e `console`). Ali o cliente exige `runtime`:
457
+
458
+ ```ts
459
+ import { createClient } from '@zihin/agent-client/core';
460
+ import { sleepWithAbort } from 'n8n-workflow';
461
+
462
+ const zihin = createClient({
463
+ apiKey,
464
+ runtime: {
465
+ sleep: sleepWithAbort, // backoff entre tentativas e relógio do deadline
466
+ warn: (code, msg) => logger.warn(`[${code}] ${msg}`), // opcional; ausente = silencioso
467
+ },
468
+ });
469
+ ```
470
+
471
+ `sleep(ms, signal)` deve resolver após `ms`, rejeitar se `signal` abortar e manter o processo vivo
472
+ enquanto pendente. Qualquer rejeição vira `ZihinAgentError` com `kind: 'aborted'`.
473
+
450
474
  ## Segurança
451
475
 
452
476
  Reusa as primitivas de `security.ts`: validação SSRF da base URL (whitelist Zihin por padrão; libere