OctoBus Service Package
Purpose
Use this skill to develop OctoBus service packages, especially JavaScript packages built with @chaitin-ai/octobus-sdk. The output should be an importable npm-compatible package, not just loose handler code.
Reference Map
Read only the references needed for the task:
references/service-package-contract.md: OctoBus package manifest, import/build/runtime rules, long-running vs on-demand behavior.references/js-sdk.md:@chaitin-ai/octobus-sdkAPIs, runtime commands, handler context, errors, validation, and local development commands.references/generation-and-tests.md: workflow for generating packages from API docs/samples and the expected test strategy.
Default Workflow
- Inspect available context: API docs, request/response examples, existing client code, current package files, or similar examples under
examples/. - Design the proto first: stable package name, normally unary RPC methods, request/response messages, field names with JSON compatibility, and explicit error behavior.
- For new JavaScript packages, prefer starting from
npx octobus-sdk bootstrap --name ... --out ..., then edit the generated proto, schemas, and handler. Use--runtime-mode long-runningonly when a persistent gRPC service is required. - Create or update the package files:
service.json- root
package.jsonwithbintargets; for multi-service packages, each service rootservice.json.namemust match a rootbinkey proto/*.protobin/*.jsor TypeScript source plus build outputconfig.schema.jsonandsecret.schema.jsonwhen configuration or credentials are required- tests beside the package when the package owns meaningful logic
- Implement handlers with
@chaitin-ai/octobus-sdk. Do not reimplement the OctoBusserve/invokeprotocol, gRPC health checks, descriptor loading, ProtoJSON rendering, or CLI plumbing unless the user explicitly asks for a non-SDK package. - Use mainstream libraries for foundational concerns such as HTTP clients, schema validation, retries, date parsing, OAuth/JWT, and URL construction. Avoid ad hoc protocol clients when an established package exists.
- Validate locally:
npm installornpm cinpx octobus-sdk validate --strictwhen all declared methods should be implementednpx octobus-sdk client-stub --transport connector--transport grpcwhen client generation matters- package tests (
npm test,node --test,vitest, etc.) node <bin> --runtime dev --port 50051 --config-json '{}' --secret-json '{}'for runtime smoke tests when usefulnpm pack --dry-runto confirm package contentsoctobus service import --id <id> <package-dir>for end-to-end import when OctoBus is available
Generation Rules
- Prefer a small, explicit proto surface over mirroring an entire upstream API mechanically.
- Prefer unary RPC methods for agent/tool-facing packages, especially on-demand packages and methods exposed through the generated local CLI. Use streaming only when the service is long-running and real gRPC clients need server, client, or bidirectional streams.
- Keep secrets out of config. Put tokens, passwords, API keys, and private keys in
secretSchema. - Map upstream validation failures to
grpcInvalidArgumentError, auth failures togrpcUnauthenticatedErrororgrpcPermissionDeniedError, missing resources togrpcNotFoundError, and transient upstream failures togrpcUnavailableError. - Use
ctx.getMetadata()/ctx.getMetadataAll()for request metadata andctx.config/ctx.secretfor instance data. OctoBus control metadata (x-octobus-*) is stripped before handlers run; OctoBus-scoped business metadata must usex-octobus-ext-*, for examplex-octobus-ext-username. - Preserve handler keys exactly as
<proto.package>.<Service>/<Method>, for examplegitlab.v1.GitLabService/GetIssue. - For on-demand packages, set
service.json.runtime.modetoon-demandand keep handlers stateless enough for one-process-per-request execution. - For long-running packages, assume multiple instances share the package runtime directory but have separate workdirs.
Quality Bar
Generated packages should include tests that cover:
- request mapping from proto-shaped input to upstream calls
- response mapping back to proto-shaped objects
- config and secret handling
- upstream error mapping to gRPC errors
- handler validation against proto methods
For packages with nontrivial upstream integration, isolate business logic from SDK glue so unit tests can mock HTTP/API clients without starting gRPC.
Useful Existing Examples
- Long-running JavaScript example:
examples/calculator-js - On-demand JavaScript example:
examples/calculator-on-demand-js - Streaming JavaScript example:
examples/streaming-js - SDK tests and fixtures:
sdk/tests