CleverCase

Rakontevr SDK

Vendor SDK modules, CleverCase gateway wiring, and Gladys/Iorek integration

Rakontevr SDK

CleverCase V2 vendors @rakontevr/sdk under vendor/rakontevr/sdk/. The SDK is the HTTP and streaming client surface for BuilderHub, unified-agent, realtime streams, necromancy bundles, and tenant environments. CleverCase wraps the SDK with server-side gateway helpers so service keys and metering headers never reach the browser.

Module map

SubpathModulePurpose
@rakontevr/sdkindex.tsBarrel export
@rakontevr/sdk/httphttp-client.tscreateRakontevrClient — typed fetch with auth
@rakontevr/sdk/unified-agentunified-agent.tsBuilderHub Lyra/unified-agent JSON calls
@rakontevr/sdk/agentsagents.tsPublished agent chat (agentChat, agentChatStream)
@rakontevr/sdk/streamsstreams.tsWebSocket sidecar for activity/RSP progress
@rakontevr/sdk/ssesse.tsparseSseStream, parseSseResponse
@rakontevr/sdk/necromancynecromancy.tsBundle list/push for necromancy reanimate
@rakontevr/sdk/agent-marketplaceagent-marketplace.tsAgent blueprint catalog
@rakontevr/sdk/environmentsenvironments.tsManaged preview/staging environments

unified-agent

callUnifiedAgent posts to ${baseUrl}/api/builderhub/unified-agent with identity headers (X-User-Id, X-Tenant-Id, X-Trace-Id, X-Task-Type, X-Agent-Tier). Options include memoryTier, pack, surfaceContext, multimodal attachments, and streaming via stream: true.

CleverCase does not call the SDK directly from browser code. Server routes use gladys-iorek-server.ts, which mirrors callUnifiedAgent streaming semantics while avoiding Turbopack symlink issues with the scoped package root.

agents

agentChat and agentChatStream target the published agent chat API for non-Gladys personas. Gladys legal queries route through unified-agent with personaId: "gladys" and domain: "legal" instead.

streams

connectStreams opens a WebSocket sidecar for channels such as activity, rsp-progress, and metering. Use subscribeChannels after onopen. In Node, pass WebSocketImpl from the ws package.

http-client

createRakontevrClient centralizes base URL, bearer/PAT auth, and tenant scoping:

import { createRakontevrClient } from "@rakontevr/sdk";

const client = createRakontevrClient({
  baseUrl: process.env.RAKONTEVR_API_BASE_URL!,
  auth: { kind: "bearer", token: process.env.RAKONTEVR_SERVICE_KEY! },
  tenantId: "00000000-0000-4000-a000-000000000003",
});

sse

parseSseStream consumes text/event-stream bodies and yields { event, data } tuples. Gladys BFF pipes upstream SSE through this parser before re-emitting events to the browser.

necromancy

necromancyListBundles and necromancyPushBundle sync reanimated schema bundles between CleverCase and the platform necromancy registry. The Prisma schema header // Generated by necromancy reanimate reflects this pipeline.

agent-marketplace

createAgentMarketplaceClient lists and executes published agent blueprints. CleverCase workflow agent_task nodes can dispatch marketplace agents when configured in template graphs.

environments

createEnvironment, provisionEnvironmentDns, and shareEnvironment manage preview environments for BuilderHub experiences. CleverCase tenant UUID 00000000-0000-4000-a000-000000000003 scopes all environment calls.

CleverCase: rak-gateway.ts

src/lib/clevercase/rak-gateway.ts stamps upstream identity for metering and audit:

ExportRole
buildRakGatewayHeadersMerges telemetry headers + Authorization: Bearer <serviceKey>
fetchViaRakGatewayServer-side fetch to BuilderHub/gateway paths
createGatewayTraceIdUUID trace correlation (X-Trace-Id)
createGatewaySpanIdSpan correlation (X-Span-Id)

Headers include X-User-Id, X-Tenant-Id, X-Metering-User-Id, X-Task-Type, and X-Agent-Tier. When the telemetry client is available, header stamping delegates to getClevercaseTelemetryClient().buildHeaders().

CleverCase: gladys-iorek-server.ts

streamGladysAsk is the server-side Gladys → Iorek client:

  1. Resolves runtime config from getGladysRuntimeConfig() (env overrides).
  2. POSTs to /api/builderhub/unified-agent with stream: true.
  3. Parses upstream SSE via parseSseStream.
  4. Returns { answer, traceId } after done event.

Default surface context:

{
  surface: "clevercase-experience",
  personaId: "gladys",
  domain: "legal",
  virtualModel: "iorek",      // or iorek-v4 via CC_GLADYS_VIRTUAL_MODEL
  agentTier: "goliath",       // floor via CC_GLADYS_AGENT_TIER
}

Env overrides:

EnvDefaultPurpose
CC_GLADYS_AGENT_TIERgoliathMinimum agent tier
CC_GLADYS_VIRTUAL_MODELiorekVirtual model id
CC_GLADYS_AGENT_MODE0Set 1 for agent-mode tool loops

Request flow (Gladys)

On this page