@xynehq/jaf
Version:
Juspay Agent Framework - A purely functional agent framework with immutable state and composable tools
85 lines • 3.24 kB
JavaScript
/**
* A2A Task Memory Types for JAF
* Extends the core memory system to support A2A task queue persistence
*/
import { z } from 'zod';
// Configuration schemas for A2A task storage
export const A2ATaskMemoryConfigSchema = z.object({
type: z.enum(['memory', 'redis', 'postgres']),
keyPrefix: z.string().default('jaf:a2a:tasks:'),
defaultTtl: z.number().optional(), // Default TTL in seconds for tasks
cleanupInterval: z.number().default(3600), // Cleanup interval in seconds
maxTasks: z.number().default(10000), // Maximum tasks to store (for in-memory)
enableHistory: z.boolean().default(true), // Store task history
enableArtifacts: z.boolean().default(true), // Store task artifacts
});
export const A2AInMemoryTaskConfigSchema = A2ATaskMemoryConfigSchema.extend({
type: z.literal('memory'),
maxTasksPerContext: z.number().default(1000),
});
export const A2ARedisTaskConfigSchema = A2ATaskMemoryConfigSchema.extend({
type: z.literal('redis'),
host: z.string().default('localhost'),
port: z.number().default(6379),
password: z.string().optional(),
db: z.number().default(0),
});
export const A2APostgresTaskConfigSchema = A2ATaskMemoryConfigSchema.extend({
type: z.literal('postgres'),
host: z.string().default('localhost'),
port: z.number().default(5432),
database: z.string().default('jaf_a2a'),
username: z.string().default('postgres'),
password: z.string().optional(),
ssl: z.boolean().default(false),
tableName: z.string().default('a2a_tasks'),
maxConnections: z.number().default(10),
});
export const A2ATaskProviderConfigSchema = z.union([
A2AInMemoryTaskConfigSchema,
A2ARedisTaskConfigSchema,
A2APostgresTaskConfigSchema
]);
// Error factory functions
export const createA2ATaskError = (message, code, provider, taskId, cause) => ({
_tag: 'A2ATaskError',
message,
code,
provider,
taskId,
cause
});
export const createA2ATaskNotFoundError = (taskId, provider) => ({
_tag: 'A2ATaskNotFoundError',
message: `A2A task ${taskId} not found`,
taskId,
provider
});
export const createA2ATaskStorageError = (operation, provider, taskId, cause) => ({
_tag: 'A2ATaskStorageError',
message: `Failed to ${operation} A2A task${taskId ? ` ${taskId}` : ''} in ${provider}`,
operation,
provider,
taskId,
cause
});
// Error checking functions
export const isA2ATaskError = (error) => {
return error && typeof error === 'object' && '_tag' in error &&
(error._tag === 'A2ATaskError' ||
error._tag === 'A2ATaskNotFoundError' ||
error._tag === 'A2ATaskStorageError');
};
export const isA2ATaskNotFoundError = (error) => {
return error && error._tag === 'A2ATaskNotFoundError';
};
export const isA2ATaskStorageError = (error) => {
return error && error._tag === 'A2ATaskStorageError';
};
// A2A-specific Result functions
export const createA2ASuccess = (data) => ({ success: true, data });
export const createA2AFailure = (error) => ({ success: false, error });
// Convenience exports for backward compatibility
export const createSuccess = createA2ASuccess;
export const createFailure = createA2AFailure;
//# sourceMappingURL=types.js.map