Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@codespar/types

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codespar/types

Shared session interface contract for codespar runtimes

latest
Source
npmnpm
Version
0.10.0
Version published
Maintainers
2
Created
Source

@codespar/types

Zero-dependency TypeScript package defining the shared session interface hierarchy for CodeSpar runtimes.

Any runtime that implements SessionBase — the managed CodeSpar backend, Anthropic Managed Agents, a self-hosted server, or a test double — is a first-class citizen in the SDK ecosystem. The contract is the only coupling between runtimes and the tools that run on top of them.

Install

npm install @codespar/types

Interfaces

SessionBase

The minimal interface any runtime must implement.

import type { SessionBase } from "@codespar/types";

interface SessionBase {
  readonly id: string;
  readonly status: "active" | "closed" | "error";

  execute(toolName: string, params: Record<string, unknown>): Promise<ToolResult>;
  send(message: string): Promise<SendResult>;
  sendStream(message: string): AsyncIterable<StreamEvent>;
  connections(): Promise<BaseConnection[]>;
  close(): Promise<void>;
}

Session

The codespar-specific extension of SessionBase, used when a session was created through the managed CodeSpar API.

import type { Session } from "@codespar/types";

interface Session extends SessionBase {
  proxyExecute(request: ProxyRequest): Promise<ProxyResult>;
  authorize(serverId: string, config: AuthConfig): Promise<AuthResult>;

  // Tool discovery + connection wizard (codespar_discover / codespar_manage_connections)
  discover(useCase: string, options?: DiscoverOptions): Promise<DiscoverResult>;
  connectionWizard(options: ConnectionWizardOptions): Promise<ConnectionWizardResult>;

  // Meta-tool wrappers — typed payloads, same wire as session.execute(...)
  charge(args: ChargeArgs): Promise<ChargeResult>;
  ship(args: ShipArgs): Promise<ShipResult>;

  // Async settlement (codespar_charge / codespar_pay)
  paymentStatus(toolCallId: string): Promise<PaymentStatusResult>;
  paymentStatusStream(
    toolCallId: string,
    options: PaymentStatusStreamOptions,
  ): Promise<PaymentStatusResult>;

  // Async verification (codespar_kyc)
  verificationStatus(toolCallId: string): Promise<VerificationStatusResult>;
  verificationStatusStream(
    toolCallId: string,
    options: VerificationStatusStreamOptions,
  ): Promise<VerificationStatusResult>;

  mcp?: {
    url: string;
    headers: Record<string, string>;
  };
}

isCodesparSession

Type guard to narrow a SessionBase to Session when you need codespar-specific methods.

import { isCodesparSession } from "@codespar/types";

function useSession(session: SessionBase) {
  if (isCodesparSession(session)) {
    // session is Session here — proxyExecute, authorize, mcp available
    const config = session.mcp;
  }
}

Wire types

TypeDescription
ToolResultReturn value of execute()success, data, error, duration, server, tool
SendResultReturn value of send()message, tool_calls, iterations
StreamEventUnion of events yielded by sendStream()user_message, assistant_text, tool_use, tool_result, done, error
BaseConnectionEntry from connections()id, connected
ServerConnectionExtended connection with name and provider metadata
ProxyRequestInput to proxyExecute()server, endpoint, method, body, headers
ProxyResultReturn value of proxyExecute()status, data, headers, duration, proxy_call_id
AuthConfigInput to authorize()redirectUri, scopes?
AuthResultReturn value of authorize()linkToken, authorizeUrl, expiresAt
DiscoverOptions / DiscoverResult / DiscoverToolMatch / DiscoverPlanStepWire shapes for session.discover(...) (codespar_discover)
ConnectionWizardOptions / ConnectionWizardResult / ConnectionStatusRowWire shapes for session.connectionWizard(...) (codespar_manage_connections)
ChargeArgs / ChargeBuyer / ChargeResultWire shapes for session.charge(...) (codespar_charge, inbound)
ShipArgs / ShipAddress / ShipItem / ShipResultWire shapes for session.ship(...) (codespar_ship)
PaymentStatus / PaymentStatusResult / PaymentStatusEventWire shapes for session.paymentStatus(toolCallId) — async webhook correlation
PaymentStatusStreamOptionsOptions for session.paymentStatusStream(...)onUpdate?, signal?
VerificationStatus / VerificationStatusResult / VerificationStatusEventWire shapes for session.verificationStatus(toolCallId) — async KYC poll
VerificationStatusStreamOptionsOptions for session.verificationStatusStream(...)onUpdate?, signal?

Conformance testing

@codespar/types ships a runContractSuite helper under a /testing subpath export. It registers a Vitest test suite that exercises the five SessionBase methods against a live HTTP endpoint.

// my-runtime.test.ts
import { runContractSuite } from "@codespar/types/testing";

// Skip unless the env vars are present
const apiKey = process.env["MY_RUNTIME_API_KEY"];
const baseUrl = process.env["MY_RUNTIME_BASE_URL"] ?? "http://localhost:3000";

if (apiKey) {
  runContractSuite(baseUrl, apiKey);
}

The suite opens a session via POST /v1/sessions with Authorization: Bearer <apiKey> and body { servers: [], user_id: "contract-suite" }, then validates:

  • execute() calls a registered tool and returns a ToolResult
  • send() returns a SendResult with a message field
  • sendStream() yields well-typed StreamEvents including a done event
  • connections() returns entries with id and connected fields
  • close() transitions session.status to "closed"

See docs/custom-session-runtime.md for a full implementation guide.

Need more?

Need governance, budget limits, and audit trails for agent payments? CodeSpar Enterprise adds policy engine, payment routing, and compliance templates on top of these MCP servers.

License

MIT — codespar.dev

Keywords

codespar

FAQs

Package last updated on 29 May 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts