@xynehq/jaf
Version:
Juspay Agent Framework - A purely functional agent framework with immutable state and composable tools
730 lines • 25.2 kB
TypeScript
/**
* Pure functional A2A types for JAF
* Maintains immutability and type safety
*/
import { z } from 'zod';
export type A2AMessage = {
readonly role: 'user' | 'agent';
readonly parts: readonly A2APart[];
readonly messageId: string;
readonly contextId?: string;
readonly taskId?: string;
readonly kind: 'message';
readonly metadata?: Readonly<Record<string, any>>;
readonly extensions?: readonly string[];
readonly referenceTaskIds?: readonly string[];
};
export type A2APart = {
readonly kind: 'text';
readonly text: string;
readonly metadata?: Readonly<Record<string, any>>;
} | {
readonly kind: 'data';
readonly data: Readonly<Record<string, any>>;
readonly metadata?: Readonly<Record<string, any>>;
} | {
readonly kind: 'file';
readonly file: A2AFile;
readonly metadata?: Readonly<Record<string, any>>;
};
export type A2AFile = {
readonly bytes: string;
readonly name?: string;
readonly mimeType?: string;
} | {
readonly uri: string;
readonly name?: string;
readonly mimeType?: string;
};
export type TaskState = 'submitted' | 'working' | 'input-required' | 'completed' | 'canceled' | 'failed' | 'rejected' | 'auth-required' | 'unknown';
export type A2ATask = {
readonly id: string;
readonly contextId: string;
readonly status: {
readonly state: TaskState;
readonly message?: A2AMessage;
readonly timestamp?: string;
};
readonly history?: readonly A2AMessage[];
readonly artifacts?: readonly A2AArtifact[];
readonly metadata?: Readonly<Record<string, any>>;
readonly kind: 'task';
};
export type A2AArtifact = {
readonly artifactId: string;
readonly name?: string;
readonly description?: string;
readonly parts: readonly A2APart[];
readonly metadata?: Readonly<Record<string, any>>;
readonly extensions?: readonly string[];
};
export type AgentCard = {
readonly protocolVersion: string;
readonly name: string;
readonly description: string;
readonly url: string;
readonly preferredTransport?: string;
readonly version: string;
readonly provider?: {
readonly organization: string;
readonly url: string;
};
readonly capabilities: {
readonly streaming?: boolean;
readonly pushNotifications?: boolean;
readonly stateTransitionHistory?: boolean;
};
readonly defaultInputModes: readonly string[];
readonly defaultOutputModes: readonly string[];
readonly skills: readonly AgentSkill[];
readonly securitySchemes?: Readonly<Record<string, any>>;
readonly security?: readonly Record<string, readonly string[]>[];
};
export type AgentSkill = {
readonly id: string;
readonly name: string;
readonly description: string;
readonly tags: readonly string[];
readonly examples?: readonly string[];
readonly inputModes?: readonly string[];
readonly outputModes?: readonly string[];
};
export type JSONRPCRequest = {
readonly jsonrpc: '2.0';
readonly id: string | number;
readonly method: string;
readonly params?: Readonly<Record<string, any>>;
};
export type JSONRPCResponse = {
readonly jsonrpc: '2.0';
readonly id: string | number | null;
} & ({
readonly result: any;
readonly error?: never;
} | {
readonly result?: never;
readonly error: JSONRPCError;
});
export type JSONRPCError = {
readonly code: number;
readonly message: string;
readonly data?: any;
};
export type SendMessageRequest = JSONRPCRequest & {
readonly method: 'message/send';
readonly params: {
readonly message: A2AMessage;
readonly configuration?: MessageSendConfiguration;
readonly metadata?: Readonly<Record<string, any>>;
};
};
export type SendStreamingMessageRequest = JSONRPCRequest & {
readonly method: 'message/stream';
readonly params: {
readonly message: A2AMessage;
readonly configuration?: MessageSendConfiguration;
readonly metadata?: Readonly<Record<string, any>>;
};
};
export type MessageSendConfiguration = {
readonly acceptedOutputModes?: readonly string[];
readonly historyLength?: number;
readonly blocking?: boolean;
};
export type SendMessageResponse = JSONRPCResponse & {
readonly result: A2AMessage | A2ATask;
};
export type GetTaskRequest = JSONRPCRequest & {
readonly method: 'tasks/get';
readonly params: {
readonly id: string;
readonly historyLength?: number;
readonly metadata?: Readonly<Record<string, any>>;
};
};
export type GetTaskResponse = JSONRPCResponse & {
readonly result: A2ATask;
};
export type StreamEvent = {
readonly isTaskComplete: boolean;
readonly content?: any;
readonly updates?: string;
readonly newState?: AgentState;
readonly timestamp: string;
};
export type A2AStreamEvent = {
readonly kind: 'status-update';
readonly taskId: string;
readonly contextId: string;
readonly status: A2ATask['status'];
readonly final: boolean;
} | {
readonly kind: 'artifact-update';
readonly taskId: string;
readonly contextId: string;
readonly artifact: A2AArtifact;
readonly append?: boolean;
readonly lastChunk?: boolean;
} | {
readonly kind: 'message';
readonly message: A2AMessage;
};
export type AgentState = {
readonly sessionId: string;
readonly messages: readonly any[];
readonly context: Readonly<Record<string, any>>;
readonly artifacts: readonly any[];
readonly timestamp: string;
};
export type ToolContext = {
readonly actions: {
readonly requiresInput: boolean;
readonly skipSummarization: boolean;
readonly escalate: boolean;
};
readonly metadata: Readonly<Record<string, any>>;
};
export type A2AToolResult = {
readonly result: any;
readonly context?: ToolContext;
};
export type A2AAgentTool = {
readonly name: string;
readonly description: string;
readonly parameters: z.ZodType<any>;
readonly execute: (args: any, context?: ToolContext) => Promise<any | A2AToolResult>;
};
export type A2AAgent = {
readonly name: string;
readonly description: string;
readonly supportedContentTypes: readonly string[];
readonly instruction: string;
readonly tools: readonly A2AAgentTool[];
};
export type A2AServerConfig = {
readonly agents: ReadonlyMap<string, A2AAgent>;
readonly agentCard: {
readonly name: string;
readonly description: string;
readonly version: string;
readonly provider: {
readonly organization: string;
readonly url: string;
};
};
readonly port: number;
readonly host?: string;
readonly capabilities?: Partial<AgentCard['capabilities']>;
readonly taskProvider?: {
readonly type: 'memory' | 'redis' | 'postgres';
readonly config?: any;
readonly externalClients?: {
readonly redis?: any;
readonly postgres?: any;
};
};
};
export type A2AClientConfig = {
readonly baseUrl: string;
readonly timeout?: number;
};
export type A2AClientState = {
readonly config: A2AClientConfig;
readonly sessionId: string;
};
export declare const A2AErrorCodes: {
readonly PARSE_ERROR: -32700;
readonly INVALID_REQUEST: -32600;
readonly METHOD_NOT_FOUND: -32601;
readonly INVALID_PARAMS: -32602;
readonly INTERNAL_ERROR: -32603;
readonly TASK_NOT_FOUND: -32001;
readonly TASK_NOT_CANCELABLE: -32002;
readonly PUSH_NOTIFICATION_NOT_SUPPORTED: -32003;
readonly UNSUPPORTED_OPERATION: -32004;
readonly CONTENT_TYPE_NOT_SUPPORTED: -32005;
readonly INVALID_AGENT_RESPONSE: -32006;
};
export type A2AError = {
readonly code: typeof A2AErrorCodes[keyof typeof A2AErrorCodes];
readonly message: string;
readonly data?: any;
};
export declare const a2aMessageSchema: z.ZodObject<{
role: z.ZodEnum<["user", "agent"]>;
parts: z.ZodArray<z.ZodUnion<[z.ZodObject<{
kind: z.ZodLiteral<"text">;
text: z.ZodString;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
}, "strip", z.ZodTypeAny, {
text: string;
kind: "text";
metadata?: Record<string, any> | undefined;
}, {
text: string;
kind: "text";
metadata?: Record<string, any> | undefined;
}>, z.ZodObject<{
kind: z.ZodLiteral<"data">;
data: z.ZodRecord<z.ZodString, z.ZodAny>;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
}, "strip", z.ZodTypeAny, {
data: Record<string, any>;
kind: "data";
metadata?: Record<string, any> | undefined;
}, {
data: Record<string, any>;
kind: "data";
metadata?: Record<string, any> | undefined;
}>, z.ZodObject<{
kind: z.ZodLiteral<"file">;
file: z.ZodUnion<[z.ZodObject<{
bytes: z.ZodString;
name: z.ZodOptional<z.ZodString>;
mimeType: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
bytes: string;
name?: string | undefined;
mimeType?: string | undefined;
}, {
bytes: string;
name?: string | undefined;
mimeType?: string | undefined;
}>, z.ZodObject<{
uri: z.ZodString;
name: z.ZodOptional<z.ZodString>;
mimeType: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
uri: string;
name?: string | undefined;
mimeType?: string | undefined;
}, {
uri: string;
name?: string | undefined;
mimeType?: string | undefined;
}>]>;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
}, "strip", z.ZodTypeAny, {
file: {
bytes: string;
name?: string | undefined;
mimeType?: string | undefined;
} | {
uri: string;
name?: string | undefined;
mimeType?: string | undefined;
};
kind: "file";
metadata?: Record<string, any> | undefined;
}, {
file: {
bytes: string;
name?: string | undefined;
mimeType?: string | undefined;
} | {
uri: string;
name?: string | undefined;
mimeType?: string | undefined;
};
kind: "file";
metadata?: Record<string, any> | undefined;
}>]>, "many">;
messageId: z.ZodString;
contextId: z.ZodOptional<z.ZodString>;
taskId: z.ZodOptional<z.ZodString>;
kind: z.ZodLiteral<"message">;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
extensions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
referenceTaskIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
}, "strip", z.ZodTypeAny, {
role: "user" | "agent";
parts: ({
text: string;
kind: "text";
metadata?: Record<string, any> | undefined;
} | {
data: Record<string, any>;
kind: "data";
metadata?: Record<string, any> | undefined;
} | {
file: {
bytes: string;
name?: string | undefined;
mimeType?: string | undefined;
} | {
uri: string;
name?: string | undefined;
mimeType?: string | undefined;
};
kind: "file";
metadata?: Record<string, any> | undefined;
})[];
kind: "message";
messageId: string;
metadata?: Record<string, any> | undefined;
contextId?: string | undefined;
taskId?: string | undefined;
extensions?: string[] | undefined;
referenceTaskIds?: string[] | undefined;
}, {
role: "user" | "agent";
parts: ({
text: string;
kind: "text";
metadata?: Record<string, any> | undefined;
} | {
data: Record<string, any>;
kind: "data";
metadata?: Record<string, any> | undefined;
} | {
file: {
bytes: string;
name?: string | undefined;
mimeType?: string | undefined;
} | {
uri: string;
name?: string | undefined;
mimeType?: string | undefined;
};
kind: "file";
metadata?: Record<string, any> | undefined;
})[];
kind: "message";
messageId: string;
metadata?: Record<string, any> | undefined;
contextId?: string | undefined;
taskId?: string | undefined;
extensions?: string[] | undefined;
referenceTaskIds?: string[] | undefined;
}>;
export declare const sendMessageRequestSchema: z.ZodObject<{
jsonrpc: z.ZodLiteral<"2.0">;
id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
method: z.ZodLiteral<"message/send">;
params: z.ZodObject<{
message: z.ZodObject<{
role: z.ZodEnum<["user", "agent"]>;
parts: z.ZodArray<z.ZodUnion<[z.ZodObject<{
kind: z.ZodLiteral<"text">;
text: z.ZodString;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
}, "strip", z.ZodTypeAny, {
text: string;
kind: "text";
metadata?: Record<string, any> | undefined;
}, {
text: string;
kind: "text";
metadata?: Record<string, any> | undefined;
}>, z.ZodObject<{
kind: z.ZodLiteral<"data">;
data: z.ZodRecord<z.ZodString, z.ZodAny>;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
}, "strip", z.ZodTypeAny, {
data: Record<string, any>;
kind: "data";
metadata?: Record<string, any> | undefined;
}, {
data: Record<string, any>;
kind: "data";
metadata?: Record<string, any> | undefined;
}>, z.ZodObject<{
kind: z.ZodLiteral<"file">;
file: z.ZodUnion<[z.ZodObject<{
bytes: z.ZodString;
name: z.ZodOptional<z.ZodString>;
mimeType: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
bytes: string;
name?: string | undefined;
mimeType?: string | undefined;
}, {
bytes: string;
name?: string | undefined;
mimeType?: string | undefined;
}>, z.ZodObject<{
uri: z.ZodString;
name: z.ZodOptional<z.ZodString>;
mimeType: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
uri: string;
name?: string | undefined;
mimeType?: string | undefined;
}, {
uri: string;
name?: string | undefined;
mimeType?: string | undefined;
}>]>;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
}, "strip", z.ZodTypeAny, {
file: {
bytes: string;
name?: string | undefined;
mimeType?: string | undefined;
} | {
uri: string;
name?: string | undefined;
mimeType?: string | undefined;
};
kind: "file";
metadata?: Record<string, any> | undefined;
}, {
file: {
bytes: string;
name?: string | undefined;
mimeType?: string | undefined;
} | {
uri: string;
name?: string | undefined;
mimeType?: string | undefined;
};
kind: "file";
metadata?: Record<string, any> | undefined;
}>]>, "many">;
messageId: z.ZodString;
contextId: z.ZodOptional<z.ZodString>;
taskId: z.ZodOptional<z.ZodString>;
kind: z.ZodLiteral<"message">;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
extensions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
referenceTaskIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
}, "strip", z.ZodTypeAny, {
role: "user" | "agent";
parts: ({
text: string;
kind: "text";
metadata?: Record<string, any> | undefined;
} | {
data: Record<string, any>;
kind: "data";
metadata?: Record<string, any> | undefined;
} | {
file: {
bytes: string;
name?: string | undefined;
mimeType?: string | undefined;
} | {
uri: string;
name?: string | undefined;
mimeType?: string | undefined;
};
kind: "file";
metadata?: Record<string, any> | undefined;
})[];
kind: "message";
messageId: string;
metadata?: Record<string, any> | undefined;
contextId?: string | undefined;
taskId?: string | undefined;
extensions?: string[] | undefined;
referenceTaskIds?: string[] | undefined;
}, {
role: "user" | "agent";
parts: ({
text: string;
kind: "text";
metadata?: Record<string, any> | undefined;
} | {
data: Record<string, any>;
kind: "data";
metadata?: Record<string, any> | undefined;
} | {
file: {
bytes: string;
name?: string | undefined;
mimeType?: string | undefined;
} | {
uri: string;
name?: string | undefined;
mimeType?: string | undefined;
};
kind: "file";
metadata?: Record<string, any> | undefined;
})[];
kind: "message";
messageId: string;
metadata?: Record<string, any> | undefined;
contextId?: string | undefined;
taskId?: string | undefined;
extensions?: string[] | undefined;
referenceTaskIds?: string[] | undefined;
}>;
configuration: z.ZodOptional<z.ZodObject<{
acceptedOutputModes: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
historyLength: z.ZodOptional<z.ZodNumber>;
blocking: z.ZodOptional<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
acceptedOutputModes?: string[] | undefined;
historyLength?: number | undefined;
blocking?: boolean | undefined;
}, {
acceptedOutputModes?: string[] | undefined;
historyLength?: number | undefined;
blocking?: boolean | undefined;
}>>;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
}, "strip", z.ZodTypeAny, {
message: {
role: "user" | "agent";
parts: ({
text: string;
kind: "text";
metadata?: Record<string, any> | undefined;
} | {
data: Record<string, any>;
kind: "data";
metadata?: Record<string, any> | undefined;
} | {
file: {
bytes: string;
name?: string | undefined;
mimeType?: string | undefined;
} | {
uri: string;
name?: string | undefined;
mimeType?: string | undefined;
};
kind: "file";
metadata?: Record<string, any> | undefined;
})[];
kind: "message";
messageId: string;
metadata?: Record<string, any> | undefined;
contextId?: string | undefined;
taskId?: string | undefined;
extensions?: string[] | undefined;
referenceTaskIds?: string[] | undefined;
};
metadata?: Record<string, any> | undefined;
configuration?: {
acceptedOutputModes?: string[] | undefined;
historyLength?: number | undefined;
blocking?: boolean | undefined;
} | undefined;
}, {
message: {
role: "user" | "agent";
parts: ({
text: string;
kind: "text";
metadata?: Record<string, any> | undefined;
} | {
data: Record<string, any>;
kind: "data";
metadata?: Record<string, any> | undefined;
} | {
file: {
bytes: string;
name?: string | undefined;
mimeType?: string | undefined;
} | {
uri: string;
name?: string | undefined;
mimeType?: string | undefined;
};
kind: "file";
metadata?: Record<string, any> | undefined;
})[];
kind: "message";
messageId: string;
metadata?: Record<string, any> | undefined;
contextId?: string | undefined;
taskId?: string | undefined;
extensions?: string[] | undefined;
referenceTaskIds?: string[] | undefined;
};
metadata?: Record<string, any> | undefined;
configuration?: {
acceptedOutputModes?: string[] | undefined;
historyLength?: number | undefined;
blocking?: boolean | undefined;
} | undefined;
}>;
}, "strip", z.ZodTypeAny, {
params: {
message: {
role: "user" | "agent";
parts: ({
text: string;
kind: "text";
metadata?: Record<string, any> | undefined;
} | {
data: Record<string, any>;
kind: "data";
metadata?: Record<string, any> | undefined;
} | {
file: {
bytes: string;
name?: string | undefined;
mimeType?: string | undefined;
} | {
uri: string;
name?: string | undefined;
mimeType?: string | undefined;
};
kind: "file";
metadata?: Record<string, any> | undefined;
})[];
kind: "message";
messageId: string;
metadata?: Record<string, any> | undefined;
contextId?: string | undefined;
taskId?: string | undefined;
extensions?: string[] | undefined;
referenceTaskIds?: string[] | undefined;
};
metadata?: Record<string, any> | undefined;
configuration?: {
acceptedOutputModes?: string[] | undefined;
historyLength?: number | undefined;
blocking?: boolean | undefined;
} | undefined;
};
id: string | number;
method: "message/send";
jsonrpc: "2.0";
}, {
params: {
message: {
role: "user" | "agent";
parts: ({
text: string;
kind: "text";
metadata?: Record<string, any> | undefined;
} | {
data: Record<string, any>;
kind: "data";
metadata?: Record<string, any> | undefined;
} | {
file: {
bytes: string;
name?: string | undefined;
mimeType?: string | undefined;
} | {
uri: string;
name?: string | undefined;
mimeType?: string | undefined;
};
kind: "file";
metadata?: Record<string, any> | undefined;
})[];
kind: "message";
messageId: string;
metadata?: Record<string, any> | undefined;
contextId?: string | undefined;
taskId?: string | undefined;
extensions?: string[] | undefined;
referenceTaskIds?: string[] | undefined;
};
metadata?: Record<string, any> | undefined;
configuration?: {
acceptedOutputModes?: string[] | undefined;
historyLength?: number | undefined;
blocking?: boolean | undefined;
} | undefined;
};
id: string | number;
method: "message/send";
jsonrpc: "2.0";
}>;
//# sourceMappingURL=types.d.ts.map