@artinet/sdk
Version:
TypeScript SDK for Agentic Communication
145 lines • 4.84 kB
TypeScript
import express, { Response } from "express";
import { CorsOptions } from "cors";
import http from "http";
import type { AgentCard, Task, Message, SendStreamingMessageRequest, TaskResubscriptionRequest, MessageSendConfiguration } from "../types/index.js";
import { TaskStore, TaskAndHistory } from "./interfaces/store.js";
import { TaskHandler, TaskContext } from "../types/index.js";
import { A2AServerParams, JSONRPCServerType } from "./interfaces/params.js";
import { Server } from "./interfaces/server.js";
import { ExpressServer } from "./lib/express-server.js";
/**
* @deprecated Use ExpressServer instead.
* Implements an A2A protocol compliant server using Express.
* Handles task creation, streaming, cancellation and more.
* Uses Jayson for JSON-RPC handling.
*/
export declare class A2AServer implements Server {
protected expressServer: ExpressServer;
/**
* Returns the base path for the server
*/
getBasePath(): string;
/**
* Returns the CORS options for the server
*/
getCorsOptions(): CorsOptions;
/**
* Returns the agent card for the server
*/
getCard(): AgentCard;
/**
* Returns the task store
*/
getTaskStore(): TaskStore;
/**
* Returns the task handler
*/
getTaskHandler(): TaskHandler;
/**
* Returns the set of active cancellations
*/
getActiveCancellations(): Set<string>;
/**
* Returns the map of active streams
*/
getActiveStreams(): Map<string, Response[]>;
/**
* Returns the port number
*/
getPort(): number;
/**
* Returns the JSON-RPC server
*/
getRpcServer(): JSONRPCServerType;
/**
* Returns the server instance
*/
getServerInstance(): http.Server | undefined;
/**
* Returns the Express app
*/
getExpressApp(): express.Express;
/**
* Returns a task context for the specified task and messages
*/
getTaskContext(task: Task, userMessage: Message, history: Message[]): TaskContext;
/**
* Returns the default agent card
*/
defaultAgentCard(): AgentCard;
/**
* Creates a new A2AServer.
* @param handler The task handler function that will process tasks
* @param options Options for configuring the server
*/
constructor(params: A2AServerParams);
/**
* Starts the Express server listening on the specified port.
* @returns The running Express application instance.
*/
start(): express.Express;
/**
* Stops the server and closes all connections.
* @returns A promise that resolves when the server is stopped.
*/
stop(): Promise<void>;
/**
* Registers the server with the A2A registry.
* @returns A promise that resolves to the registration ID or an empty string if registration fails.
*/
registerServer(): Promise<string>;
/**
* Handles task cancellation
* @param data Task and history data
* @param res Response object
*/
onCancel(context: TaskContext, data: TaskAndHistory, res: Response): Promise<void>;
/**
* Handles cleanup when a task stream ends
* @param taskId The task ID
* @param res Response object
*/
onEnd(taskId: string, res: Response): Promise<void>;
/**
* Handles the message/stream method.
* @param req The SendTaskRequest object
* @param res The Express Response object
*/
handleTaskSendSubscribe(req: SendStreamingMessageRequest, res: Response): Promise<void>;
/**
* Handles the tasks/resubscribe method.
* @param req The TaskResubscriptionRequest object
* @param res The Express Response object
*/
handleTaskResubscribe(req: TaskResubscriptionRequest, res: Response): Promise<void>;
/**
* Adds a response stream to the tracking map for a task.
* @param taskId The task ID
* @param res The response stream
*/
addStreamForTask(taskId: string, res: Response): void;
/**
* Removes a response stream from the tracking map for a task.
* @param taskId The task ID
* @param res The response stream
*/
removeStreamForTask(taskId: string, res: Response): void;
/**
* Initializes the default agent card
*/
static defaultAgentCard(): AgentCard;
/**
* Creates a TaskContext object for a task handler.
* @param task The task
* @param userMessage The user message
* @param history The message history
* @returns A TaskContext object
*/
createTaskContext(task: Task, userMessage: Message, history: Message[], configuration?: MessageSendConfiguration): TaskContext;
/**
* Closes any active streams for a task.
* @param taskId The task ID
*/
closeStreamsForTask(taskId: string): void;
}
//# sourceMappingURL=a2a-server.d.ts.map