Skip to content

Implement the Gradient Labs Node.js / TypeScript client#1

Merged
gmtuca merged 5 commits into
mainfrom
implement-nodejs-client
Jun 16, 2026
Merged

Implement the Gradient Labs Node.js / TypeScript client#1
gmtuca merged 5 commits into
mainfrom
implement-nodejs-client

Conversation

@gmtuca

@gmtuca gmtuca commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Implements @gradient-labs/client, the official Node.js / TypeScript client for the public Gradient Labs API, following nodejs_CLIENT_PLAN.md.

What's included

  • Full public API surface as resource namespaces: client.conversations.start(...), client.tools.list(...), etc. Covers every endpoint in platform/openapi/spec.json (Integration + Management roles). GET /spec.json is intentionally omitted; the deprecated GET /conversations/{id} is exposed as conversations.getDeprecated().
  • Zero runtime dependencies — built-in fetch + node:crypto. Node 20+.
  • Typed errors: GradientLabsErrorConfigurationError / ApiError (with statusCode, code, details, traceId) and typed ErrorCode constants.
  • Open string enums with values sourced from the Go backend.
  • Cursor pagination: Page<T> + listAll() async iterators.
  • Webhooks: WebhookVerifier.verify / .parse — HMAC-SHA256 over <ts>.<body>, leeway check, constant-time compare, discriminated-union events, and X-GradientLabs-Token passthrough.
  • Build: dual ESM + CJS + .d.ts via tsup. Examples for 7 resource groups. CI (Node 20/22) + tag-triggered npm publish (provenance).

Correctness review

A dedicated review pass cross-checked every endpoint, field, enum, and webhook payload against the Go backend (platform/support-platforms/public-api, platform/apis/public-management-api, and the webhook publishers). Findings were fixed in this branch:

  • Back-office webhook events corrected to the real { back_office_task: ... } shape.
  • action.execute / resource.pull conversation payloads split out (with customer_source + metadata + optional back_office_task); plain conversation events carry {id, customer_id} only; added last_customer_message_id.
  • Required vs optional request fields aligned with backend validators (payload, agent_id required; resources, attachment summary/description, GatedConfig optional).

Quality gate

tsc, eslint, prettier --check, tsup build, and 40/40 vitest tests all pass (no network required).

🤖 Generated with Claude Code

gmtuca and others added 5 commits June 16, 2026 14:42
Full client for the public Gradient Labs API per nodejs_CLIENT_PLAN.md:

- Resource-namespaced API (client.conversations.start, client.tools.list, ...)
  covering all Integration and Management endpoints in the OpenAPI spec.
- Zero runtime dependencies: built-in fetch + node:crypto.
- Typed error hierarchy (GradientLabsError / ConfigurationError / ApiError)
  with traceId helper and typed ErrorCode constants.
- Open string enums sourced from the Go source.
- Cursor pagination with Page<T> + listAll() async iterators.
- WebhookVerifier: HMAC-SHA256 signature + leeway check, constant-time compare,
  typed discriminated-union events, X-GradientLabs-Token passthrough.
- 36 offline tests (webhook, errors, http, types), examples for 7 groups,
  dual ESM/CJS build via tsup, CI + publish workflows.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…end review

Cross-checked against the Go backend webhook publishers and request validators:

- Webhooks: back-office events carry the full task under a single
  'back_office_task' key (was a wrong '{task, ...siblings}' shape); the three
  back-office events now reuse the full BackOfficeTask model.
- Webhooks: split conversation payload types — agent.message/hand_off/finished
  carry {id, customer_id} only (no metadata); action.execute/resource.pull use
  ActionWebhookConversation ({id, customer_id, customer_source, metadata}) and an
  optional back_office_task ref; both are optional. Added last_customer_message_id
  to AgentMessageEvent.
- Required fields: ReturnAsyncToolResultParams.payload and
  CreateBackOfficeTaskParams.agent_id are required server-side (validation.Required).
- Optional fields: ResumeConversationParams.resources, Attachment.summary/
  description, and ProcedureVersion.GatedConfig are optional/nullable in the API.
- Tests: added pagination.test.ts (paginate + procedures.listAll) and corrected
  the webhook event fixtures to the real shapes. 40 tests pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
agent_id is an ordinary parameter (e.g. "boagent_12345"), not an
environment concern; use a literal placeholder in the example.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The npm organization is 'gradientlabs', so the package is @gradientlabs/client.
Updated package.json/lockfile, README, examples, plan, and source references.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The plan file has served its purpose now the client is implemented.
Drop it along with the .prettierignore entry and the enums.ts comment
that pointed at it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gmtuca gmtuca merged commit 5ea48b9 into main Jun 16, 2026
2 checks passed
@gmtuca gmtuca deleted the implement-nodejs-client branch June 16, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant