CorfedoCorfedoDocs

TypeScript SDK

Install the core TypeScript client, search and read code, and ask Corfedo AI with streaming, reattach and your own tools.

The SDK uses ES modules on Node.js 22.12 or later. @corfedo/client is framework-independent. @corfedo/ai-sdk and @corfedo/langchain add Corfedo to the Vercel AI SDK and LangChain. The packages use Apache-2.0.

npm install @corfedo/client

client.search.search and client.code.readFile search and read code, see Search and read code. CorfedoAuthentication.signIn signs a person in, see Ask for Corfedo AI for an example.

Ask Corfedo AI

import { CorfedoClient } from '@corfedo/client';

const client = CorfedoClient.fromApiKeyFile(process.env.CORFEDO_API_KEY_FILE!);
try {
  const run = client.ai.stream({
    clientMessageId: crypto.randomUUID(),
    text: 'How are search requests routed?',
  });
  for await (const event of run) {
    if (event.type === 'text.delta') process.stdout.write(event.text);
  }
  console.log(run.outcome, run.answer, run.citations);
} finally {
  await client.close();
}

The key needs Search and read code and Ask Corfedo AI, see API keys. send waits without streaming. Continue with conversationId and a new clientMessageId. listProfiles, listConversations, getConversation and deleteConversation expose profiles and history.

reattach(runId, after) returns an observer stream. SDK sequences are bigint, while wire sequences are decimal strings. Use getRun for a snapshot and cancel to request run cancellation. Abort signals end a subscription without cancelling the run.

streamToolResults and submitToolResults return the results of your own tools. Run the calls in requiredCalls of the stream that sent the message. A reattached stream only lists pendingCalls. See Client tools.

Errors and recovery

The core uses CorfedoError and CorfedoFailure, including AccessDenied, Conflict, SpendingLimitReached and StreamFailed.

If the connection drops, the SDK reconnects for up to 30 seconds, then throws the last error. The run keeps going. Human sessions need the renewal callback.

On this page