Skip to main content
Complete API documentation for the @corti/ai-sdk-adapter package.

Functions

convertToParams()

Converts an array of CortiUIMessage objects (from the Vercel AI SDK useChat hook) into A2A MessageSendParams ready to send to a Corti agent.
function convertToParams(
  messages: CortiUIMessage[],
  credentials?: ExpertCredential[]
): MessageSendParams;
ParameterTypeRequiredDescription
messagesCortiUIMessage[]YesThe messages array from useChat.
credentialsExpertCredential[]NoCredentials for MCP servers.
Returns: MessageSendParams — an A2A-compatible params object you can pass to client.sendMessage() or client.sendMessageStream(). Automatic behavior:
  • Extracts contextId from the last assistant message to maintain conversation context.
  • Includes taskId only when the last assistant message has state: 'input-required'.
  • Attaches credentials only on the first message.

toUIMessageStream()

Converts an A2A streaming response into a UI message stream compatible with the Vercel AI SDK’s createUIMessageStreamResponse().
function toUIMessageStream(
  a2aStream: AsyncIterable<StreamEvent>,
  options?: StreamConversionOptions
): ReadableStream;
ParameterTypeRequiredDescription
a2aStreamAsyncIterable<StreamEvent>YesThe stream returned by client.sendMessageStream().
optionsStreamConversionOptionsNoConfiguration including lifecycle callbacks.
Returns: ReadableStream — a stream you can pass to createUIMessageStreamResponse({ stream }).

createA2AClientFactory()

Creates a factory for building A2A clients that are pre-configured with Corti authentication.
function createA2AClientFactory(
  cortiClient: CortiClient
): A2AClientFactory;
ParameterTypeRequiredDescription
cortiClientCortiClientYesAn authenticated CortiClient instance from @corti/lib.
Returns: A2AClientFactory — a factory with a createFromUrl(url, agentId) method to build A2A clients. Usage:
import { createA2AClientFactory } from '@corti/ai-sdk-adapter';
import { CortiClient } from '@corti/lib';

const corti = new CortiClient({ /* config */ });
const factory = createA2AClientFactory(corti);

const agentUrl = await corti.agents.getCardUrl("YOUR_AGENT_ID");
const client = factory.createFromUrl(agentUrl.toString(), '');

createFetchImplementation()

Creates a fetch-compatible function that automatically injects Corti authentication headers into every request. This is the lower-level primitive used internally by createA2AClientFactory(), but you can use it directly when you need a custom A2A client setup.
function createFetchImplementation(
  client: CortiClient
): (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
ParameterTypeRequiredDescription
clientCortiClientYesAn authenticated CortiClient instance from @corti/sdk.
Returns: A fetch-compatible function (input, init?) => Promise<Response> that adds Corti authentication to outgoing requests. Usage:
import { createFetchImplementation } from '@corti/ai-sdk-adapter';
import { CortiClient } from '@corti/sdk';
import { ClientFactory } from '@a2a-js/sdk/client';

const corti = new CortiClient({ /* config */ });
const fetch = createFetchImplementation(corti);

// Use with A2A ClientFactory directly
const factory = new ClientFactory({ fetch });

Types

CortiUIMessage

Extends the standard Vercel AI SDK UIMessage with A2A-specific metadata and data parts.
import type { CortiUIMessage } from '@corti/ai-sdk-adapter';
Metadata fields:
FieldTypeDescription
contextIdstringConversation context identifier.
taskIdstringTask identifier for multi-turn interactions.
historyobject[]Conversation history from the A2A response.
creditsnumberCredits consumed by this response.
statestringTask state (e.g., 'completed', 'input-required').
Custom data parts:
Part discriminatorTypeDescription
data-textCortiTextPartText content with an optional name.
data-jsonCortiJSONPartStructured JSON data with a name.
data-status-updateCortiStatusUpdateStatus update from the agent.

CortiTextPart

A text data part. Alias for string.
type CortiTextPart = string;

CortiJSONPart

A JSON data part. Alias for JSONValue from @ai-sdk/provider.
type CortiJSONPart = JSONValue;

CortiStatusUpdate

A status update emitted by the agent during streaming.
type CortiStatusUpdate = {
  state: string;
  message?: string;
};
FieldTypeRequiredDescription
statestringYesCurrent task state.
messagestringNoOptional human-readable status message.

ExpertCredential

Credentials for authenticating with MCP servers connected to a Corti agent.
type ExpertCredential =
  | {
      mcp_name: string;
      token: string;
      type: 'bearer';
    }
  | {
      mcp_name: string;
      client_id: string;
      client_secret: string;
      type: 'oauth2.0';
    };
FieldTypeDescription
mcp_namestringName of the MCP server to authenticate with.
tokenstringBearer token (when type is 'bearer').
client_idstringOAuth client ID (when type is 'oauth2.0').
client_secretstringOAuth client secret (when type is 'oauth2.0').
type'bearer' | 'oauth2.0'Authentication method.

StreamConversionOptions

Options passed to toUIMessageStream() to configure stream behavior.
interface StreamConversionOptions {
  callbacks?: {
    onStart?: () => void;
    onEvent?: (event: StreamEvent) => void;
    onFinish?: (state: TaskStatus) => void;
    onError?: (error: Error) => void;
    onAbort?: () => void;
  };
}
Callback reference:
CallbackParametersDescription
onStartCalled when streaming begins.
onEventevent: StreamEventCalled on each new event from the A2A stream.
onFinishstate: TaskStatusCalled when the stream completes with the final task status.
onErrorerror: ErrorCalled if an error occurs during streaming.
onAbortCalled when the stream is aborted by the client.