@tanstack/ai
Version:
Type-safe TypeScript AI SDK for streaming chat, tool calling, agents, structured outputs, and multimodal generation.
123 lines (122 loc) • 5.04 kB
TypeScript
import { chat } from '../index.js';
import { summarize } from '../../summarize/index.js';
import { generateImage } from '../../generateImage/index.js';
import { generateVideo } from '../../generateVideo/index.js';
import { generateAudio } from '../../generateAudio/index.js';
import { generateSpeech } from '../../generateSpeech/index.js';
import { generateVoice } from '../../generateVoice/index.js';
import { generateTranscription } from '../../generateTranscription/index.js';
import { generateWorld } from '../../generateWorld/index.js';
import { generateLiveVideo } from '../../generateLiveVideo/index.js';
import { embed } from '../../embed/index.js';
import { rerank } from '../../rerank/index.js';
import { decide } from '../../evaluate/index.js';
import { GenerationMiddleware } from '../../middleware/types.js';
import { AnyChatMiddleware } from '../middleware/types.js';
import { PromptCacheRetention, RunAgentResumeItem } from '../../../types.js';
import { SubagentRunInput } from './define-agent.js';
import { SubagentBudget } from './limits.js';
import { ProviderKeys } from '../../../byok/keyed.js';
/**
* The fields a child `chat()` needs, in one spread:
* `chat({ adapter, messages, ...ctx.forward })`.
*/
export interface SubagentForward {
threadId: string;
runId: string;
parentRunId: string;
subagentRunId: string;
/** The agent name. Middleware reads it as `ctx.subagentName`. */
subagentName: string;
/** The subagentRunId of the child that started this one, for a nested child. */
parentSubagentRunId?: string;
resume?: Array<RunAgentResumeItem>;
/** Aborts when the parent run or the subagent group stops. */
abortController: AbortController;
/** The prompt cache retention of the parent call, when it has one. */
promptCache?: PromptCacheRetention;
}
/**
* What a host adds to every activity call an agent makes through `ctx`. Apps
* using plain `chat({ subagents })` do not set it.
*/
export interface SubagentBinding {
/**
* Added before the call's own middleware on every `ctx.chat` call. A
* child's `ctx.chat({ subagents })` passes it down to its own children.
*/
chatMiddleware?: ReadonlyArray<AnyChatMiddleware>;
/**
* Added before the call's own middleware on every generation call. A
* child's `ctx.chat({ subagents })` passes it down to its own children.
*/
generationMiddleware?: ReadonlyArray<GenerationMiddleware>;
/**
* The subagent tree budget. A child's `ctx.chat({ subagents })` passes it
* down, so limits hold across the whole tree.
*/
budget?: SubagentBudget;
/**
* The provider keys an agent reads as `ctx.keys`. `subagents.keys` sets
* them. A child's `ctx.chat({ subagents })` passes them down to its own
* children. Without them, `ctx.keys` reads each provider's `env` names.
*/
keys?: ProviderKeys;
/**
* The prompt cache retention of the parent call. A child's `ctx.chat()`
* uses it when the call gives no `promptCache`.
*/
promptCache?: PromptCacheRetention;
/**
* Starts a child without waiting for it and returns its id at once. The
* agent tools call it for `background: true`. With
* `wake: true`, the host starts a new parent turn when the child ends. It
* does not pass down to nested children.
*/
start?: (call: {
agent: string;
input?: unknown;
prompt?: string;
parentToolCallId?: string;
}, options: {
wake: true;
}) => Promise<{
subagentRunId: string;
/** Settles when the child ends. `maxConcurrent` counts the child until then. */
done: Promise<unknown>;
}>;
}
/**
* Activity functions bound to one child run. Each takes the same options as
* the plain function. Options you pass win over the bound defaults.
*/
export interface BoundActivities {
chat: typeof chat;
summarize: typeof summarize;
generateImage: typeof generateImage;
generateVideo: typeof generateVideo;
generateAudio: typeof generateAudio;
generateSpeech: typeof generateSpeech;
generateVoice: typeof generateVoice;
generateTranscription: typeof generateTranscription;
generateWorld: typeof generateWorld;
generateLiveVideo: typeof generateLiveVideo;
embed: typeof embed;
rerank: typeof rerank;
decide: typeof decide;
}
export declare function createBoundActivities(agentName: string, input: SubagentRunInput, abortController: AbortController, binding?: SubagentBinding): {
chat: typeof chat;
summarize: typeof summarize;
generateImage: typeof generateImage;
generateVideo: typeof generateVideo;
generateAudio: typeof generateAudio;
generateSpeech: typeof generateSpeech;
generateVoice: typeof generateVoice;
generateTranscription: typeof generateTranscription;
generateWorld: typeof generateWorld;
generateLiveVideo: typeof generateLiveVideo;
embed: typeof embed;
rerank: typeof rerank;
decide: typeof decide;
};