@utcp/sdk
Version:
Universal Tool Calling Protocol (UTCP) client library for TypeScript
210 lines • 8.73 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProviderUnionSchema = exports.TextProviderSchema = exports.MCPProviderSchema = exports.McpConfigSchema = exports.McpServerSchema = exports.McpHttpServerSchema = exports.McpStdioServerSchema = exports.WebRTCProviderSchema = exports.UDPProviderSchema = exports.TCPProviderSchema = exports.GraphQLProviderSchema = exports.GRPCProviderSchema = exports.WebSocketProviderSchema = exports.CliProviderSchema = exports.StreamableHttpProviderSchema = exports.SSEProviderSchema = exports.HttpProviderSchema = exports.ProviderSchema = exports.ProviderTypeSchema = void 0;
const zod_1 = require("zod");
const auth_1 = require("./auth");
/**
* Provider types supported by UTCP
*/
exports.ProviderTypeSchema = zod_1.z.enum([
'http', // RESTful HTTP/HTTPS API
'sse', // Server-Sent Events
'http_stream', // HTTP Chunked Transfer Encoding
'cli', // Command Line Interface
'websocket', // WebSocket bidirectional connection
'grpc', // gRPC (Google Remote Procedure Call)
'graphql', // GraphQL query language
'tcp', // Raw TCP socket
'udp', // User Datagram Protocol
'webrtc', // Web Real-Time Communication
'mcp', // Model Context Protocol
'text', // Text file provider
]);
/**
* Base Provider schema
*/
exports.ProviderSchema = zod_1.z.object({
name: zod_1.z.string().optional().default(() => crypto.randomUUID()),
provider_type: exports.ProviderTypeSchema,
});
/**
* HTTP Provider schema for RESTful HTTP/HTTPS API tools
*/
exports.HttpProviderSchema = exports.ProviderSchema.extend({
provider_type: zod_1.z.literal('http'),
http_method: zod_1.z.enum(['GET', 'POST', 'PUT', 'DELETE', 'PATCH']).default('GET'),
url: zod_1.z.string(),
content_type: zod_1.z.string().default('application/json'),
auth: auth_1.AuthSchema.optional(),
headers: zod_1.z.record(zod_1.z.string()).optional(),
body_field: zod_1.z.string().optional().default('body').describe('The name of the single input field to be sent as the request body.'),
header_fields: zod_1.z.array(zod_1.z.string()).optional().describe('List of input fields to be sent as request headers.'),
});
/**
* SSE Provider schema for Server-Sent Events tools
*/
exports.SSEProviderSchema = exports.ProviderSchema.extend({
provider_type: zod_1.z.literal('sse'),
url: zod_1.z.string(),
event_type: zod_1.z.string().optional(),
reconnect: zod_1.z.boolean().default(true),
retry_timeout: zod_1.z.number().default(30000), // Retry timeout in milliseconds if disconnected
auth: auth_1.AuthSchema.optional(),
headers: zod_1.z.record(zod_1.z.string()).optional(),
body_field: zod_1.z.string().optional().describe('The name of the single input field to be sent as the request body.'),
header_fields: zod_1.z.array(zod_1.z.string()).optional().describe('List of input fields to be sent as request headers for the initial connection.'),
});
/**
* HTTP Streaming Provider schema for HTTP Chunked Transfer Encoding tools
*/
exports.StreamableHttpProviderSchema = exports.ProviderSchema.extend({
provider_type: zod_1.z.literal('http_stream'),
url: zod_1.z.string(),
http_method: zod_1.z.enum(['GET', 'POST']).default('GET'),
content_type: zod_1.z.string().default('application/octet-stream'),
chunk_size: zod_1.z.number().default(4096), // Size of chunks in bytes
timeout: zod_1.z.number().default(60000), // Timeout in milliseconds
headers: zod_1.z.record(zod_1.z.string()).optional(),
auth: auth_1.AuthSchema.optional(),
body_field: zod_1.z.string().optional().describe('The name of the single input field to be sent as the request body.'),
header_fields: zod_1.z.array(zod_1.z.string()).optional().describe('List of input fields to be sent as request headers.'),
});
/**
* CLI Provider schema for Command Line Interface tools
*/
exports.CliProviderSchema = exports.ProviderSchema.extend({
provider_type: zod_1.z.literal('cli'),
command_name: zod_1.z.string(),
env_vars: zod_1.z.record(zod_1.z.string()).optional().describe('Environment variables to set when executing the command'),
working_dir: zod_1.z.string().optional().describe('Working directory for command execution'),
auth: zod_1.z.null(),
});
/**
* WebSocket Provider schema for WebSocket tools
*/
exports.WebSocketProviderSchema = exports.ProviderSchema.extend({
provider_type: zod_1.z.literal('websocket'),
url: zod_1.z.string(),
protocol: zod_1.z.string().optional(),
keep_alive: zod_1.z.boolean().default(true),
auth: auth_1.AuthSchema.optional(),
headers: zod_1.z.record(zod_1.z.string()).optional(),
header_fields: zod_1.z.array(zod_1.z.string()).optional().describe('List of input fields to be sent as request headers for the initial connection.'),
});
/**
* gRPC Provider schema for gRPC tools
*/
exports.GRPCProviderSchema = exports.ProviderSchema.extend({
provider_type: zod_1.z.literal('grpc'),
host: zod_1.z.string(),
port: zod_1.z.number(),
service_name: zod_1.z.string(),
method_name: zod_1.z.string(),
use_ssl: zod_1.z.boolean().default(false),
auth: auth_1.AuthSchema.optional(),
});
/**
* GraphQL Provider schema for GraphQL tools
*/
exports.GraphQLProviderSchema = exports.ProviderSchema.extend({
provider_type: zod_1.z.literal('graphql'),
url: zod_1.z.string(),
operation_type: zod_1.z.enum(['query', 'mutation', 'subscription']).default('query'),
operation_name: zod_1.z.string().optional(),
auth: auth_1.AuthSchema.optional(),
headers: zod_1.z.record(zod_1.z.string()).optional(),
header_fields: zod_1.z.array(zod_1.z.string()).optional().describe('List of input fields to be sent as request headers for the initial connection.'),
});
/**
* TCP Provider schema for raw TCP socket tools
*/
exports.TCPProviderSchema = exports.ProviderSchema.extend({
provider_type: zod_1.z.literal('tcp'),
host: zod_1.z.string(),
port: zod_1.z.number(),
timeout: zod_1.z.number().default(30000),
auth: zod_1.z.null(),
});
/**
* UDP Provider schema for UDP socket tools
*/
exports.UDPProviderSchema = exports.ProviderSchema.extend({
provider_type: zod_1.z.literal('udp'),
host: zod_1.z.string(),
port: zod_1.z.number(),
timeout: zod_1.z.number().default(30000),
auth: zod_1.z.null(),
});
/**
* WebRTC Provider schema for Web Real-Time Communication tools
*/
exports.WebRTCProviderSchema = exports.ProviderSchema.extend({
provider_type: zod_1.z.literal('webrtc'),
signaling_server: zod_1.z.string(),
peer_id: zod_1.z.string(),
data_channel_name: zod_1.z.string().default('tools'),
auth: zod_1.z.null(),
});
/**
* MCP Stdio Server schema for MCP servers connected via stdio
*/
exports.McpStdioServerSchema = zod_1.z.object({
transport: zod_1.z.literal('stdio'),
command: zod_1.z.string(),
args: zod_1.z.array(zod_1.z.string()).optional().default([]),
env: zod_1.z.record(zod_1.z.string()).optional().default({}),
});
/**
* MCP HTTP Server schema for MCP servers connected via streamable HTTP
*/
exports.McpHttpServerSchema = zod_1.z.object({
transport: zod_1.z.literal('http'),
url: zod_1.z.string(),
});
/**
* Combined MCP Server types
*/
exports.McpServerSchema = zod_1.z.discriminatedUnion('transport', [
exports.McpStdioServerSchema,
exports.McpHttpServerSchema,
]);
/**
* MCP Configuration schema
*/
exports.McpConfigSchema = zod_1.z.object({
mcpServers: zod_1.z.record(exports.McpServerSchema),
});
/**
* MCP Provider schema for Model Context Protocol tools
*/
exports.MCPProviderSchema = exports.ProviderSchema.extend({
provider_type: zod_1.z.literal('mcp'),
config: exports.McpConfigSchema,
auth: auth_1.OAuth2AuthSchema.optional(),
});
/**
* Text Provider schema for text file-based tools
*/
exports.TextProviderSchema = exports.ProviderSchema.extend({
provider_type: zod_1.z.literal('text'),
file_path: zod_1.z.string().describe('The path to the file containing the tool definitions.'),
auth: zod_1.z.null().optional().default(null),
});
/**
* Combined Provider schema using discriminated union based on provider_type
*/
exports.ProviderUnionSchema = zod_1.z.discriminatedUnion('provider_type', [
exports.HttpProviderSchema,
exports.SSEProviderSchema,
exports.StreamableHttpProviderSchema,
exports.CliProviderSchema,
exports.WebSocketProviderSchema,
exports.GRPCProviderSchema,
exports.GraphQLProviderSchema,
exports.TCPProviderSchema,
exports.UDPProviderSchema,
exports.WebRTCProviderSchema,
exports.MCPProviderSchema,
exports.TextProviderSchema,
]);
//# sourceMappingURL=provider.js.map