-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai-agent-schema.json
More file actions
192 lines (192 loc) · 8.28 KB
/
ai-agent-schema.json
File metadata and controls
192 lines (192 loc) · 8.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "ts-json-rpc AI/LLM Agent Documentation Schema",
"description": "Structured documentation schema for LLM/AI agents to understand and work with the ts-json-rpc library",
"type": "object",
"properties": {
"library": {
"type": "object",
"properties": {
"name": "ts-json-rpc",
"version": "1.0.0",
"description": "A robust, type-safe, and transport-agnostic TypeScript library for building JSON-RPC 2.0 clients and servers",
"architecture": "monorepo",
"packages": {
"type": "array",
"items": [
{
"name": "@ts-json-rpc/core",
"purpose": "Core types and utilities for JSON-RPC 2.0 implementation",
"exports": [
"JSONRPCRequest",
"JSONRPCNotification",
"JSONRPCResponse",
"JSONRPCError",
"createJsonRpcRequest",
"createJsonRpcNotification",
"createJsonRpcError",
"isJSONRPCRequest",
"isJSONRPCResponse",
"JSONRPC_ERROR_CODES"
]
},
{
"name": "@ts-json-rpc/client",
"purpose": "Type-safe JSON-RPC 2.0 client implementation",
"exports": [
"JsonRpcClient",
"JsonRpcClientTransport",
"createJsonRpcClient"
]
},
{
"name": "@ts-json-rpc/server",
"purpose": "Type-safe JSON-RPC 2.0 server implementation",
"exports": [
"JsonRpcServer",
"JsonRpcMethodHandler",
"JsonRpcMethodMap",
"JsonRpcServerOptions",
"createJsonRpcServer"
]
}
]
}
}
},
"common_patterns": {
"type": "object",
"properties": {
"client_setup": {
"description": "How to create and configure a JSON-RPC client",
"example": "import { createJsonRpcClient } from '@ts-json-rpc/client';\nconst transport = async (request) => { /* HTTP transport */ };\nconst client = createJsonRpcClient(transport);"
},
"server_setup": {
"description": "How to create and configure a JSON-RPC server",
"example": "import { createJsonRpcServer } from '@ts-json-rpc/server';\nconst methods = { add: (params) => params.a + params.b };\nconst server = createJsonRpcServer(methods);"
},
"making_requests": {
"description": "How to make RPC calls",
"example": "const result = await client.call<number>('add', { a: 1, b: 2 });"
},
"sending_notifications": {
"description": "How to send notifications (no response expected)",
"example": "client.notify('log', { message: 'Hello world' });"
},
"error_handling": {
"description": "How to handle JSON-RPC errors",
"example": "try { const result = await client.call('method', params); } catch (error) { console.log(error.code, error.message); }"
}
}
},
"integration_guides": {
"type": "object",
"properties": {
"http_transport": {
"description": "Using with HTTP transport (fetch, axios, etc.)",
"example": "const transport = async (request) => {\n const response = await fetch('/api/jsonrpc', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(request)\n });\n return response.json();\n};"
},
"websocket_transport": {
"description": "Using with WebSocket transport",
"example": "const transport = async (request) => {\n return new Promise((resolve) => {\n websocket.send(JSON.stringify(request));\n websocket.onmessage = (event) => resolve(JSON.parse(event.data));\n });\n};"
},
"express_server": {
"description": "Integrating server with Express.js",
"example": "app.post('/api/jsonrpc', async (req, res) => {\n const response = await server.handleJsonRpcRequest(req.body);\n if (response !== null) {\n res.json(response);\n } else {\n res.status(204).send();\n }\n});"
}
}
},
"type_definitions": {
"type": "object",
"properties": {
"core_types": {
"JSONRPCRequest": "Interface for JSON-RPC 2.0 request messages with method, params, and id",
"JSONRPCNotification": "Interface for JSON-RPC 2.0 notification messages (requests without id)",
"JSONRPCResponse": "Union type for success or error response messages",
"JSONRPCError": "Interface for JSON-RPC error objects with code, message, and optional data"
},
"client_types": {
"JsonRpcClient": "Client interface with call() and notify() methods",
"JsonRpcClientTransport": "Function type for transport implementation"
},
"server_types": {
"JsonRpcMethodHandler": "Function type for method handlers that process requests",
"JsonRpcMethodMap": "Record mapping method names to handler functions",
"JsonRpcServerOptions": "Configuration options for server behavior"
}
}
},
"troubleshooting": {
"type": "object",
"properties": {
"common_errors": [
{
"error": "Method not found",
"cause": "Server doesn't have a handler for the requested method",
"solution": "Add method handler to server methods map"
},
{
"error": "Invalid params",
"cause": "Parameters don't match expected method signature",
"solution": "Ensure params match method handler parameter types"
},
{
"error": "Parse error",
"cause": "Invalid JSON in request payload",
"solution": "Validate JSON before sending to server"
},
{
"error": "Transport error",
"cause": "Network or transport layer failure",
"solution": "Implement proper error handling in transport function"
}
]
}
},
"best_practices": {
"type": "array",
"items": [
"Always use TypeScript for better type safety and IDE support",
"Implement proper error handling in transport functions",
"Use meaningful method names that describe the operation",
"Validate parameters in method handlers before processing",
"Handle both synchronous and asynchronous method handlers",
"Use notifications for fire-and-forget operations",
"Implement context passing for user authentication and session data",
"Use batch requests for multiple related operations",
"Configure appropriate logging for debugging and monitoring",
"Test both success and error scenarios in your implementations"
]
},
"testing": {
"type": "object",
"properties": {
"framework": "Vitest",
"test_patterns": [
"Mock transport functions for client testing",
"Test method handlers independently from server",
"Test error conditions and edge cases",
"Verify JSON-RPC 2.0 specification compliance",
"Test batch request/response handling",
"Test notification handling (no response expected)"
],
"example_test": "const mockTransport = vi.fn().mockResolvedValue({ jsonrpc: '2.0', result: 42, id: 1 });\nconst client = createJsonRpcClient(mockTransport);\nconst result = await client.call('test', {});\nexpect(result).toBe(42);"
}
},
"development": {
"type": "object",
"properties": {
"scripts": {
"build": "npm run build - Build all packages",
"test": "npm test - Run all tests with coverage",
"lint": "npm run lint - Check code style with ESLint",
"format": "npm run format - Format code with Prettier",
"docs": "npm run docs - Generate API documentation",
"changelog": "npm run changelog - Generate changelog from commits"
},
"conventional_commits": "Uses conventional commit format for automated changelog generation",
"code_style": "ESLint + Prettier with TypeScript strict mode"
}
}
}
}