@mondaydotcomorg/atp-server 0.17.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +489 -0
- package/dist/aggregator/index.d.ts +59 -0
- package/dist/aggregator/index.d.ts.map +1 -0
- package/dist/aggregator/index.js +171 -0
- package/dist/aggregator/index.js.map +1 -0
- package/dist/callback/index.d.ts +98 -0
- package/dist/callback/index.d.ts.map +1 -0
- package/dist/callback/index.js +136 -0
- package/dist/callback/index.js.map +1 -0
- package/dist/client-sessions.d.ts +82 -0
- package/dist/client-sessions.d.ts.map +1 -0
- package/dist/client-sessions.js +174 -0
- package/dist/client-sessions.js.map +1 -0
- package/dist/controllers/definitions.controller.d.ts +4 -0
- package/dist/controllers/definitions.controller.d.ts.map +1 -0
- package/dist/controllers/definitions.controller.js +11 -0
- package/dist/controllers/definitions.controller.js.map +1 -0
- package/dist/controllers/execute.controller.d.ts +18 -0
- package/dist/controllers/execute.controller.d.ts.map +1 -0
- package/dist/controllers/execute.controller.js +122 -0
- package/dist/controllers/execute.controller.js.map +1 -0
- package/dist/controllers/info.controller.d.ts +3 -0
- package/dist/controllers/info.controller.d.ts.map +1 -0
- package/dist/controllers/info.controller.js +13 -0
- package/dist/controllers/info.controller.js.map +1 -0
- package/dist/controllers/resume.controller.d.ts +11 -0
- package/dist/controllers/resume.controller.d.ts.map +1 -0
- package/dist/controllers/resume.controller.js +61 -0
- package/dist/controllers/resume.controller.js.map +1 -0
- package/dist/controllers/search.controller.d.ts +4 -0
- package/dist/controllers/search.controller.d.ts.map +1 -0
- package/dist/controllers/search.controller.js +7 -0
- package/dist/controllers/search.controller.js.map +1 -0
- package/dist/controllers/stream.controller.d.ts +19 -0
- package/dist/controllers/stream.controller.d.ts.map +1 -0
- package/dist/controllers/stream.controller.js +141 -0
- package/dist/controllers/stream.controller.js.map +1 -0
- package/dist/core/config.d.ts +161 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +7 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/http.d.ts +4 -0
- package/dist/core/http.d.ts.map +1 -0
- package/dist/core/http.js +17 -0
- package/dist/core/http.js.map +1 -0
- package/dist/create-server.d.ts +120 -0
- package/dist/create-server.d.ts.map +1 -0
- package/dist/create-server.js +423 -0
- package/dist/create-server.js.map +1 -0
- package/dist/execution-state/index.d.ts +95 -0
- package/dist/execution-state/index.d.ts.map +1 -0
- package/dist/execution-state/index.js +128 -0
- package/dist/execution-state/index.js.map +1 -0
- package/dist/executor/ast-provenance-bridge.d.ts +12 -0
- package/dist/executor/ast-provenance-bridge.d.ts.map +1 -0
- package/dist/executor/ast-provenance-bridge.js +66 -0
- package/dist/executor/ast-provenance-bridge.js.map +1 -0
- package/dist/executor/ast-tracking-runtime.d.ts +7 -0
- package/dist/executor/ast-tracking-runtime.d.ts.map +1 -0
- package/dist/executor/ast-tracking-runtime.js +559 -0
- package/dist/executor/ast-tracking-runtime.js.map +1 -0
- package/dist/executor/bootstrap-generated.d.ts +32 -0
- package/dist/executor/bootstrap-generated.d.ts.map +1 -0
- package/dist/executor/bootstrap-generated.js +90 -0
- package/dist/executor/bootstrap-generated.js.map +1 -0
- package/dist/executor/compiler-config.d.ts +32 -0
- package/dist/executor/compiler-config.d.ts.map +1 -0
- package/dist/executor/compiler-config.js +99 -0
- package/dist/executor/compiler-config.js.map +1 -0
- package/dist/executor/constants.d.ts +4 -0
- package/dist/executor/constants.d.ts.map +1 -0
- package/dist/executor/constants.js +4 -0
- package/dist/executor/constants.js.map +1 -0
- package/dist/executor/error-handler.d.ts +9 -0
- package/dist/executor/error-handler.d.ts.map +1 -0
- package/dist/executor/error-handler.js +95 -0
- package/dist/executor/error-handler.js.map +1 -0
- package/dist/executor/execution-error-handler.d.ts +7 -0
- package/dist/executor/execution-error-handler.d.ts.map +1 -0
- package/dist/executor/execution-error-handler.js +136 -0
- package/dist/executor/execution-error-handler.js.map +1 -0
- package/dist/executor/executor.d.ts +20 -0
- package/dist/executor/executor.d.ts.map +1 -0
- package/dist/executor/executor.js +452 -0
- package/dist/executor/executor.js.map +1 -0
- package/dist/executor/index.d.ts +4 -0
- package/dist/executor/index.d.ts.map +1 -0
- package/dist/executor/index.js +3 -0
- package/dist/executor/index.js.map +1 -0
- package/dist/executor/resume-handler.d.ts +9 -0
- package/dist/executor/resume-handler.d.ts.map +1 -0
- package/dist/executor/resume-handler.js +22 -0
- package/dist/executor/resume-handler.js.map +1 -0
- package/dist/executor/sandbox-builder.d.ts +29 -0
- package/dist/executor/sandbox-builder.d.ts.map +1 -0
- package/dist/executor/sandbox-builder.js +538 -0
- package/dist/executor/sandbox-builder.js.map +1 -0
- package/dist/executor/sandbox-injector.d.ts +7 -0
- package/dist/executor/sandbox-injector.d.ts.map +1 -0
- package/dist/executor/sandbox-injector.js +293 -0
- package/dist/executor/sandbox-injector.js.map +1 -0
- package/dist/executor/types.d.ts +21 -0
- package/dist/executor/types.d.ts.map +1 -0
- package/dist/executor/types.js +2 -0
- package/dist/executor/types.js.map +1 -0
- package/dist/explorer/index.d.ts +69 -0
- package/dist/explorer/index.d.ts.map +1 -0
- package/dist/explorer/index.js +228 -0
- package/dist/explorer/index.js.map +1 -0
- package/dist/handlers/definitions.handler.d.ts +3 -0
- package/dist/handlers/definitions.handler.d.ts.map +1 -0
- package/dist/handlers/definitions.handler.js +11 -0
- package/dist/handlers/definitions.handler.js.map +1 -0
- package/dist/handlers/execute.handler.d.ts +7 -0
- package/dist/handlers/execute.handler.d.ts.map +1 -0
- package/dist/handlers/execute.handler.js +225 -0
- package/dist/handlers/execute.handler.js.map +1 -0
- package/dist/handlers/explorer.handler.d.ts +4 -0
- package/dist/handlers/explorer.handler.d.ts.map +1 -0
- package/dist/handlers/explorer.handler.js +10 -0
- package/dist/handlers/explorer.handler.js.map +1 -0
- package/dist/handlers/init.handler.d.ts +5 -0
- package/dist/handlers/init.handler.d.ts.map +1 -0
- package/dist/handlers/init.handler.js +41 -0
- package/dist/handlers/init.handler.js.map +1 -0
- package/dist/handlers/resume.handler.d.ts +6 -0
- package/dist/handlers/resume.handler.d.ts.map +1 -0
- package/dist/handlers/resume.handler.js +256 -0
- package/dist/handlers/resume.handler.js.map +1 -0
- package/dist/handlers/search.handler.d.ts +5 -0
- package/dist/handlers/search.handler.d.ts.map +1 -0
- package/dist/handlers/search.handler.js +11 -0
- package/dist/handlers/search.handler.js.map +1 -0
- package/dist/http/request-handler.d.ts +15 -0
- package/dist/http/request-handler.d.ts.map +1 -0
- package/dist/http/request-handler.js +94 -0
- package/dist/http/request-handler.js.map +1 -0
- package/dist/http/router.d.ts +4 -0
- package/dist/http/router.d.ts.map +1 -0
- package/dist/http/router.js +32 -0
- package/dist/http/router.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/instrumentation/index.d.ts +5 -0
- package/dist/instrumentation/index.d.ts.map +1 -0
- package/dist/instrumentation/index.js +5 -0
- package/dist/instrumentation/index.js.map +1 -0
- package/dist/instrumentation/serializer.d.ts +61 -0
- package/dist/instrumentation/serializer.d.ts.map +1 -0
- package/dist/instrumentation/serializer.js +334 -0
- package/dist/instrumentation/serializer.js.map +1 -0
- package/dist/instrumentation/state-manager.d.ts +61 -0
- package/dist/instrumentation/state-manager.d.ts.map +1 -0
- package/dist/instrumentation/state-manager.js +205 -0
- package/dist/instrumentation/state-manager.js.map +1 -0
- package/dist/instrumentation/transformer.d.ts +9 -0
- package/dist/instrumentation/transformer.d.ts.map +1 -0
- package/dist/instrumentation/transformer.js +70 -0
- package/dist/instrumentation/transformer.js.map +1 -0
- package/dist/instrumentation/types.d.ts +59 -0
- package/dist/instrumentation/types.d.ts.map +1 -0
- package/dist/instrumentation/types.js +5 -0
- package/dist/instrumentation/types.js.map +1 -0
- package/dist/middleware/audit.d.ts +18 -0
- package/dist/middleware/audit.d.ts.map +1 -0
- package/dist/middleware/audit.js +76 -0
- package/dist/middleware/audit.js.map +1 -0
- package/dist/openapi/index.d.ts +133 -0
- package/dist/openapi/index.d.ts.map +1 -0
- package/dist/openapi/index.js +235 -0
- package/dist/openapi/index.js.map +1 -0
- package/dist/openapi-loader.d.ts +87 -0
- package/dist/openapi-loader.d.ts.map +1 -0
- package/dist/openapi-loader.js +491 -0
- package/dist/openapi-loader.js.map +1 -0
- package/dist/routes/index.d.ts +21 -0
- package/dist/routes/index.d.ts.map +1 -0
- package/dist/routes/index.js +47 -0
- package/dist/routes/index.js.map +1 -0
- package/dist/search/index.d.ts +48 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +156 -0
- package/dist/search/index.js.map +1 -0
- package/dist/security/index.d.ts +2 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +2 -0
- package/dist/security/index.js.map +1 -0
- package/dist/shutdown.d.ts +19 -0
- package/dist/shutdown.d.ts.map +1 -0
- package/dist/shutdown.js +87 -0
- package/dist/shutdown.js.map +1 -0
- package/dist/utils/banner.d.ts +12 -0
- package/dist/utils/banner.d.ts.map +1 -0
- package/dist/utils/banner.js +18 -0
- package/dist/utils/banner.js.map +1 -0
- package/dist/utils/context.d.ts +16 -0
- package/dist/utils/context.d.ts.map +1 -0
- package/dist/utils/context.js +44 -0
- package/dist/utils/context.js.map +1 -0
- package/dist/utils/error.d.ts +8 -0
- package/dist/utils/error.d.ts.map +1 -0
- package/dist/utils/error.js +17 -0
- package/dist/utils/error.js.map +1 -0
- package/dist/utils/hint-based-instrumentation.d.ts +14 -0
- package/dist/utils/hint-based-instrumentation.d.ts.map +1 -0
- package/dist/utils/hint-based-instrumentation.js +84 -0
- package/dist/utils/hint-based-instrumentation.js.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/info.d.ts +20 -0
- package/dist/utils/info.d.ts.map +1 -0
- package/dist/utils/info.js +15 -0
- package/dist/utils/info.js.map +1 -0
- package/dist/utils/provenance-reattachment.d.ts +32 -0
- package/dist/utils/provenance-reattachment.d.ts.map +1 -0
- package/dist/utils/provenance-reattachment.js +115 -0
- package/dist/utils/provenance-reattachment.js.map +1 -0
- package/dist/utils/request.d.ts +21 -0
- package/dist/utils/request.d.ts.map +1 -0
- package/dist/utils/request.js +44 -0
- package/dist/utils/request.js.map +1 -0
- package/dist/utils/response.d.ts +30 -0
- package/dist/utils/response.d.ts.map +1 -0
- package/dist/utils/response.js +53 -0
- package/dist/utils/response.js.map +1 -0
- package/dist/utils/runtime-types.d.ts +6 -0
- package/dist/utils/runtime-types.d.ts.map +1 -0
- package/dist/utils/runtime-types.js +14 -0
- package/dist/utils/runtime-types.js.map +1 -0
- package/dist/utils/schema.d.ts +9 -0
- package/dist/utils/schema.d.ts.map +1 -0
- package/dist/utils/schema.js +13 -0
- package/dist/utils/schema.js.map +1 -0
- package/dist/utils/token-emitter.d.ts +21 -0
- package/dist/utils/token-emitter.d.ts.map +1 -0
- package/dist/utils/token-emitter.js +129 -0
- package/dist/utils/token-emitter.js.map +1 -0
- package/dist/validator/index.d.ts +36 -0
- package/dist/validator/index.d.ts.map +1 -0
- package/dist/validator/index.js +224 -0
- package/dist/validator/index.js.map +1 -0
- package/package.json +68 -0
- package/src/aggregator/index.ts +207 -0
- package/src/callback/index.ts +191 -0
- package/src/client-sessions.ts +234 -0
- package/src/controllers/definitions.controller.ts +19 -0
- package/src/controllers/execute.controller.ts +166 -0
- package/src/controllers/info.controller.ts +14 -0
- package/src/controllers/resume.controller.ts +92 -0
- package/src/controllers/search.controller.ts +16 -0
- package/src/controllers/stream.controller.ts +190 -0
- package/src/core/config.ts +180 -0
- package/src/core/http.ts +21 -0
- package/src/create-server.ts +536 -0
- package/src/execution-state/index.ts +204 -0
- package/src/executor/ast-provenance-bridge.ts +80 -0
- package/src/executor/ast-tracking-runtime.ts +558 -0
- package/src/executor/bootstrap-generated.ts +90 -0
- package/src/executor/compiler-config.ts +146 -0
- package/src/executor/constants.ts +5 -0
- package/src/executor/error-handler.ts +118 -0
- package/src/executor/execution-error-handler.ts +178 -0
- package/src/executor/executor.ts +631 -0
- package/src/executor/index.ts +3 -0
- package/src/executor/resume-handler.ts +39 -0
- package/src/executor/sandbox-builder.ts +684 -0
- package/src/executor/sandbox-injector.ts +345 -0
- package/src/executor/types.ts +22 -0
- package/src/explorer/index.ts +297 -0
- package/src/handlers/definitions.handler.ts +13 -0
- package/src/handlers/execute.handler.ts +286 -0
- package/src/handlers/explorer.handler.ts +18 -0
- package/src/handlers/init.handler.ts +53 -0
- package/src/handlers/resume.handler.ts +316 -0
- package/src/handlers/search.handler.ts +32 -0
- package/src/http/request-handler.ts +117 -0
- package/src/http/router.ts +29 -0
- package/src/index.ts +60 -0
- package/src/instrumentation/index.ts +4 -0
- package/src/instrumentation/serializer.ts +421 -0
- package/src/instrumentation/state-manager.ts +237 -0
- package/src/instrumentation/transformer.ts +84 -0
- package/src/instrumentation/types.ts +76 -0
- package/src/middleware/audit.ts +101 -0
- package/src/openapi/index.ts +378 -0
- package/src/openapi-loader.ts +744 -0
- package/src/routes/index.ts +93 -0
- package/src/search/index.ts +216 -0
- package/src/security/index.ts +1 -0
- package/src/shutdown.ts +108 -0
- package/src/utils/banner.ts +25 -0
- package/src/utils/context.ts +58 -0
- package/src/utils/error.ts +25 -0
- package/src/utils/hint-based-instrumentation.ts +99 -0
- package/src/utils/index.ts +15 -0
- package/src/utils/info.ts +31 -0
- package/src/utils/provenance-reattachment.ts +144 -0
- package/src/utils/request.ts +53 -0
- package/src/utils/response.ts +69 -0
- package/src/utils/runtime-types.ts +14 -0
- package/src/utils/schema.ts +18 -0
- package/src/utils/token-emitter.ts +182 -0
- package/src/validator/index.ts +253 -0
package/README.md
ADDED
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
# @mondaydotcomorg/atp-server
|
|
2
|
+
|
|
3
|
+
Production-ready ATP server with sandboxed execution, API aggregation, semantic search, and state management.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The ATP server provides secure, sandboxed TypeScript execution with built-in runtime APIs, OpenAPI integration, MCP support, semantic search, and comprehensive observability.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @mondaydotcomorg/atp-server
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Architecture
|
|
16
|
+
|
|
17
|
+
```mermaid
|
|
18
|
+
graph TB
|
|
19
|
+
Server[AgentToolProtocolServer] --> Executor[SandboxExecutor]
|
|
20
|
+
Server --> Aggregator[APIAggregator]
|
|
21
|
+
Server --> Search[SearchEngine]
|
|
22
|
+
Server --> State[ExecutionStateManager]
|
|
23
|
+
Server --> Sessions[ClientSessionManager]
|
|
24
|
+
|
|
25
|
+
Executor --> Sandbox[VM2 Sandbox]
|
|
26
|
+
Executor --> Runtime[Runtime APIs]
|
|
27
|
+
|
|
28
|
+
Aggregator --> OpenAPI[OpenAPI Loader]
|
|
29
|
+
Aggregator --> MCP[MCP Adapter]
|
|
30
|
+
Aggregator --> Custom[Custom Functions]
|
|
31
|
+
|
|
32
|
+
Search --> Embeddings[Embedding Model]
|
|
33
|
+
|
|
34
|
+
State --> Cache[CacheProvider]
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
### Basic Server
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { createServer } from '@mondaydotcomorg/atp-server';
|
|
43
|
+
|
|
44
|
+
const server = createServer({
|
|
45
|
+
execution: {
|
|
46
|
+
timeout: 30000,
|
|
47
|
+
memory: 128 * 1024 * 1024, // 128MB
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
await server.start(3333);
|
|
52
|
+
console.log('ATP server running on http://localhost:3333');
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### With OpenAPI Integration
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { createServer, loadOpenAPI } from '@mondaydotcomorg/atp-server';
|
|
59
|
+
|
|
60
|
+
const server = createServer();
|
|
61
|
+
|
|
62
|
+
// Load OpenAPI specs
|
|
63
|
+
const githubAPI = await loadOpenAPI({
|
|
64
|
+
url: 'https://api.github.com/openapi.json',
|
|
65
|
+
name: 'github',
|
|
66
|
+
auth: {
|
|
67
|
+
type: 'bearer',
|
|
68
|
+
token: process.env.GITHUB_TOKEN,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
server.addAPIGroup(githubAPI);
|
|
73
|
+
|
|
74
|
+
await server.start(3333);
|
|
75
|
+
|
|
76
|
+
// Agents can now use:
|
|
77
|
+
// await atp.api.github.repos.get({ owner: 'user', repo: 'repo' })
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### With MCP Support
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { MCPConnector } from '@mondaydotcomorg/atp-mcp-adapter';
|
|
84
|
+
|
|
85
|
+
const mcpConnector = new MCPConnector();
|
|
86
|
+
|
|
87
|
+
const filesystemAPI = await mcpConnector.connectToMCPServer({
|
|
88
|
+
name: 'filesystem',
|
|
89
|
+
command: 'npx',
|
|
90
|
+
args: ['-y', '@modelcontextprotocol/server-filesystem', '/path/to/files'],
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
server.addAPIGroup(filesystemAPI);
|
|
94
|
+
|
|
95
|
+
// Agents can now use MCP tools:
|
|
96
|
+
// await atp.api.filesystem.read_file({ path: 'README.md' })
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### With Semantic Search
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { OpenAIEmbeddings } from '@langchain/openai';
|
|
103
|
+
|
|
104
|
+
const embeddings = new OpenAIEmbeddings();
|
|
105
|
+
|
|
106
|
+
const server = createServer({
|
|
107
|
+
discovery: {
|
|
108
|
+
embeddings, // Enable semantic search
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// Clients can search APIs semantically:
|
|
113
|
+
// client.searchQuery('How do I create a user?')
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### With Redis Cache
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import { RedisCache } from '@mondaydotcomorg/atp-providers';
|
|
120
|
+
import Redis from 'ioredis';
|
|
121
|
+
|
|
122
|
+
const redis = new Redis(process.env.REDIS_URL);
|
|
123
|
+
|
|
124
|
+
const server = createServer({
|
|
125
|
+
executionState: {
|
|
126
|
+
ttl: 3600, // 1 hour
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
server.setCacheProvider(
|
|
131
|
+
new RedisCache({
|
|
132
|
+
redis,
|
|
133
|
+
keyPrefix: 'atp:',
|
|
134
|
+
defaultTTL: 3600,
|
|
135
|
+
})
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
await server.start(3333);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### With Provenance Security
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
import {
|
|
145
|
+
ProvenanceMode,
|
|
146
|
+
preventDataExfiltration,
|
|
147
|
+
requireUserOrigin,
|
|
148
|
+
} from '@mondaydotcomorg/atp-server';
|
|
149
|
+
|
|
150
|
+
const server = createServer({
|
|
151
|
+
execution: {
|
|
152
|
+
provenanceMode: ProvenanceMode.PROXY, // or AST
|
|
153
|
+
securityPolicies: [preventDataExfiltration, requireUserOrigin],
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### With Audit Logging
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
import { JSONLAuditSink } from '@mondaydotcomorg/atp-providers';
|
|
162
|
+
|
|
163
|
+
const server = createServer({
|
|
164
|
+
audit: {
|
|
165
|
+
enabled: true,
|
|
166
|
+
sinks: [
|
|
167
|
+
new JSONLAuditSink({
|
|
168
|
+
path: './audit-logs',
|
|
169
|
+
rotateDaily: true,
|
|
170
|
+
}),
|
|
171
|
+
],
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// All execution, tool calls, LLM calls are logged
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### With OpenTelemetry
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
const server = createServer({
|
|
182
|
+
otel: {
|
|
183
|
+
enabled: true,
|
|
184
|
+
serviceName: 'my-atp-server',
|
|
185
|
+
traceEndpoint: 'http://localhost:4318/v1/traces',
|
|
186
|
+
metricsEndpoint: 'http://localhost:4318/v1/metrics',
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
// Traces and metrics exported to OTLP collector
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Custom APIs
|
|
194
|
+
|
|
195
|
+
### Add Custom Functions
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
server.addAPIGroup({
|
|
199
|
+
name: 'database',
|
|
200
|
+
type: 'custom',
|
|
201
|
+
description: 'Database operations',
|
|
202
|
+
functions: [
|
|
203
|
+
{
|
|
204
|
+
name: 'createUser',
|
|
205
|
+
description: 'Create a new user',
|
|
206
|
+
inputSchema: {
|
|
207
|
+
type: 'object',
|
|
208
|
+
properties: {
|
|
209
|
+
name: { type: 'string' },
|
|
210
|
+
email: { type: 'string' },
|
|
211
|
+
},
|
|
212
|
+
required: ['name', 'email'],
|
|
213
|
+
},
|
|
214
|
+
handler: async (input) => {
|
|
215
|
+
const user = await db.users.create(input);
|
|
216
|
+
return user;
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
],
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
// Agents can use:
|
|
223
|
+
// await atp.api.database.createUser({ name: 'Alice', email: 'alice@example.com' })
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### OAuth Integration
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
import { GoogleOAuthProvider } from '@mondaydotcomorg/atp-providers';
|
|
230
|
+
|
|
231
|
+
const oauthProvider = new GoogleOAuthProvider({
|
|
232
|
+
clientId: process.env.GOOGLE_CLIENT_ID,
|
|
233
|
+
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
|
|
234
|
+
redirectUri: 'http://localhost:3333/oauth/callback',
|
|
235
|
+
scopes: ['https://www.googleapis.com/auth/userinfo.email'],
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
server.addAPIGroup({
|
|
239
|
+
name: 'gmail',
|
|
240
|
+
type: 'oauth',
|
|
241
|
+
oauthProvider,
|
|
242
|
+
functions: [
|
|
243
|
+
{
|
|
244
|
+
name: 'sendEmail',
|
|
245
|
+
description: 'Send email via Gmail',
|
|
246
|
+
inputSchema: {
|
|
247
|
+
/* ... */
|
|
248
|
+
},
|
|
249
|
+
handler: async (input, credentials) => {
|
|
250
|
+
// Use credentials.accessToken
|
|
251
|
+
return await sendGmailEmail(input, credentials.accessToken);
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
});
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Configuration
|
|
259
|
+
|
|
260
|
+
```typescript
|
|
261
|
+
interface ServerConfig {
|
|
262
|
+
execution?: {
|
|
263
|
+
timeout?: number; // Default: 30000ms
|
|
264
|
+
memory?: number; // Default: 128MB
|
|
265
|
+
llmCalls?: number; // Max LLM calls per execution
|
|
266
|
+
provenanceMode?: ProvenanceMode; // Default: 'none'
|
|
267
|
+
securityPolicies?: SecurityPolicy[];
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
clientInit?: {
|
|
271
|
+
tokenTTL?: number; // Default: 1 hour
|
|
272
|
+
tokenRotation?: number; // Default: 30 minutes
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
executionState?: {
|
|
276
|
+
ttl?: number; // State TTL in seconds
|
|
277
|
+
maxPauseDuration?: number; // Max pause duration
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
discovery?: {
|
|
281
|
+
embeddings?: Embeddings; // Enable semantic search
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
audit?: {
|
|
285
|
+
enabled?: boolean;
|
|
286
|
+
sinks?: AuditSink[];
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
otel?: {
|
|
290
|
+
enabled?: boolean;
|
|
291
|
+
serviceName?: string;
|
|
292
|
+
traceEndpoint?: string;
|
|
293
|
+
metricsEndpoint?: string;
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
## API Groups
|
|
299
|
+
|
|
300
|
+
```typescript
|
|
301
|
+
interface APIGroupConfig {
|
|
302
|
+
name: string;
|
|
303
|
+
type: 'openapi' | 'custom' | 'mcp' | 'oauth';
|
|
304
|
+
description?: string;
|
|
305
|
+
baseUrl?: string;
|
|
306
|
+
auth?: AuthConfig;
|
|
307
|
+
functions: CustomFunctionDef[];
|
|
308
|
+
oauthProvider?: OAuthProvider;
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
## Runtime APIs Available to Agents
|
|
313
|
+
|
|
314
|
+
Agents executing code have access to these runtime APIs:
|
|
315
|
+
|
|
316
|
+
### atp.llm.\*
|
|
317
|
+
|
|
318
|
+
```typescript
|
|
319
|
+
// LLM calls (requires client.provideLLM())
|
|
320
|
+
await atp.llm.call({ prompt: 'Hello' });
|
|
321
|
+
await atp.llm.extract({ prompt: 'Extract', schema: { name: 'string' } });
|
|
322
|
+
await atp.llm.classify({ text: 'Text', categories: ['A', 'B'] });
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### atp.approval.\*
|
|
326
|
+
|
|
327
|
+
```typescript
|
|
328
|
+
// Approval requests (requires client.provideApproval())
|
|
329
|
+
const result = await atp.approval.request('Delete files?', { critical: true });
|
|
330
|
+
if (result.approved) {
|
|
331
|
+
// Proceed
|
|
332
|
+
}
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
### atp.embedding.\*
|
|
336
|
+
|
|
337
|
+
```typescript
|
|
338
|
+
// Embeddings (requires client.provideEmbedding())
|
|
339
|
+
const id = await atp.embedding.embed('Store this text');
|
|
340
|
+
const results = await atp.embedding.search('query', { topK: 5 });
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
### atp.log.\*
|
|
344
|
+
|
|
345
|
+
```typescript
|
|
346
|
+
// Logging
|
|
347
|
+
atp.log.info('Processing user request');
|
|
348
|
+
atp.log.error('Failed to connect', { error });
|
|
349
|
+
atp.log.debug('Debug info', { data });
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
### atp.progress.\*
|
|
353
|
+
|
|
354
|
+
```typescript
|
|
355
|
+
// Progress reporting
|
|
356
|
+
atp.progress.report({ current: 5, total: 10, message: 'Processing...' });
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
### atp.cache.\*
|
|
360
|
+
|
|
361
|
+
```typescript
|
|
362
|
+
// Caching (requires cache provider)
|
|
363
|
+
await atp.cache.set('key', value, 3600);
|
|
364
|
+
const cached = await atp.cache.get('key');
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
### atp.api.\*
|
|
368
|
+
|
|
369
|
+
```typescript
|
|
370
|
+
// Dynamic API calls based on loaded API groups
|
|
371
|
+
await atp.api.github.repos.get({ owner: 'user', repo: 'repo' });
|
|
372
|
+
await atp.api.database.createUser({ name: 'Alice' });
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
## Middleware
|
|
376
|
+
|
|
377
|
+
```typescript
|
|
378
|
+
import type { Middleware, RequestContext } from '@mondaydotcomorg/atp-server';
|
|
379
|
+
|
|
380
|
+
const loggingMiddleware: Middleware = async (context: RequestContext, next) => {
|
|
381
|
+
console.log(`${context.method} ${context.path}`);
|
|
382
|
+
const start = Date.now();
|
|
383
|
+
|
|
384
|
+
await next();
|
|
385
|
+
|
|
386
|
+
console.log(`Completed in ${Date.now() - start}ms`);
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
server.use(loggingMiddleware);
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
## Server Lifecycle
|
|
393
|
+
|
|
394
|
+
```typescript
|
|
395
|
+
const server = createServer(config);
|
|
396
|
+
|
|
397
|
+
// Setup
|
|
398
|
+
server.setCacheProvider(cache);
|
|
399
|
+
server.setAuthProvider(auth);
|
|
400
|
+
server.addAPIGroup(apiGroup);
|
|
401
|
+
server.use(middleware);
|
|
402
|
+
|
|
403
|
+
// Start
|
|
404
|
+
await server.start(3333);
|
|
405
|
+
|
|
406
|
+
// Shutdown
|
|
407
|
+
await server.shutdown();
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
## Execution Flow
|
|
411
|
+
|
|
412
|
+
```mermaid
|
|
413
|
+
sequenceDiagram
|
|
414
|
+
participant Client
|
|
415
|
+
participant Server
|
|
416
|
+
participant Executor
|
|
417
|
+
participant Sandbox
|
|
418
|
+
participant APIs
|
|
419
|
+
|
|
420
|
+
Client->>Server: POST /execute
|
|
421
|
+
Server->>Executor: Execute code
|
|
422
|
+
Executor->>Sandbox: Create VM
|
|
423
|
+
|
|
424
|
+
loop Code execution
|
|
425
|
+
Sandbox->>APIs: atp.api.* call
|
|
426
|
+
APIs-->>Sandbox: Result
|
|
427
|
+
|
|
428
|
+
alt Needs LLM
|
|
429
|
+
Sandbox->>Server: Pause (LLM)
|
|
430
|
+
Server->>Client: Return paused
|
|
431
|
+
Client->>Server: Resume with LLM result
|
|
432
|
+
Server->>Sandbox: Continue
|
|
433
|
+
end
|
|
434
|
+
end
|
|
435
|
+
|
|
436
|
+
Sandbox-->>Executor: Result
|
|
437
|
+
Executor-->>Server: Execution complete
|
|
438
|
+
Server-->>Client: Return result
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
## Production Deployment
|
|
442
|
+
|
|
443
|
+
### With Redis + PostgreSQL
|
|
444
|
+
|
|
445
|
+
```typescript
|
|
446
|
+
import { RedisCache } from '@mondaydotcomorg/atp-providers';
|
|
447
|
+
import { PostgresSaver } from '@langchain/langgraph-checkpoint-postgres';
|
|
448
|
+
import Redis from 'ioredis';
|
|
449
|
+
|
|
450
|
+
const redis = new Redis(process.env.REDIS_URL);
|
|
451
|
+
const cache = new RedisCache({ redis });
|
|
452
|
+
|
|
453
|
+
const server = createServer({
|
|
454
|
+
execution: {
|
|
455
|
+
timeout: 60000,
|
|
456
|
+
memory: 256 * 1024 * 1024,
|
|
457
|
+
},
|
|
458
|
+
executionState: {
|
|
459
|
+
ttl: 7200, // 2 hours
|
|
460
|
+
},
|
|
461
|
+
audit: {
|
|
462
|
+
enabled: true,
|
|
463
|
+
},
|
|
464
|
+
otel: {
|
|
465
|
+
enabled: true,
|
|
466
|
+
},
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
server.setCacheProvider(cache);
|
|
470
|
+
|
|
471
|
+
await server.start(process.env.PORT || 3333);
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
## Security Best Practices
|
|
475
|
+
|
|
476
|
+
1. **Use provenance mode** for sensitive data
|
|
477
|
+
2. **Set execution limits** (timeout, memory, LLM calls)
|
|
478
|
+
3. **Enable audit logging** for compliance
|
|
479
|
+
4. **Use OAuth** for third-party APIs
|
|
480
|
+
5. **Validate API inputs** with schemas
|
|
481
|
+
6. **Use security policies** to block malicious patterns
|
|
482
|
+
|
|
483
|
+
## TypeScript Support
|
|
484
|
+
|
|
485
|
+
Full TypeScript definitions included.
|
|
486
|
+
|
|
487
|
+
## License
|
|
488
|
+
|
|
489
|
+
MIT
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { APIGroupConfig } from '@mondaydotcomorg/atp-protocol';
|
|
2
|
+
/**
|
|
3
|
+
* APIAggregator generates TypeScript type definitions from API configurations.
|
|
4
|
+
* Converts API group definitions into TypeScript declarations for use in code generation.
|
|
5
|
+
*/
|
|
6
|
+
export declare class APIAggregator {
|
|
7
|
+
private apiGroups;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new APIAggregator instance.
|
|
10
|
+
* @param apiGroups - Array of API group configurations
|
|
11
|
+
*/
|
|
12
|
+
constructor(apiGroups: APIGroupConfig[]);
|
|
13
|
+
/**
|
|
14
|
+
* Generates TypeScript type definitions for selected API groups.
|
|
15
|
+
* @param selectedGroups - Optional array of group names to include
|
|
16
|
+
* @returns TypeScript definition string
|
|
17
|
+
*/
|
|
18
|
+
generateTypeScript(selectedGroups?: string[]): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Generates TypeScript definitions for the runtime SDK.
|
|
21
|
+
* @returns TypeScript definition string
|
|
22
|
+
*/
|
|
23
|
+
private generateRuntimeTypes;
|
|
24
|
+
/**
|
|
25
|
+
* Generates TypeScript types for a single function.
|
|
26
|
+
* @param func - Function definition
|
|
27
|
+
* @param groupName - API group name
|
|
28
|
+
* @returns TypeScript definition string
|
|
29
|
+
*/
|
|
30
|
+
private generateFunctionTypes;
|
|
31
|
+
/**
|
|
32
|
+
* Converts JSON Schema type to TypeScript type.
|
|
33
|
+
* @param type - JSON Schema type string
|
|
34
|
+
* @returns TypeScript type string
|
|
35
|
+
*/
|
|
36
|
+
private jsonSchemaTypeToTS;
|
|
37
|
+
/**
|
|
38
|
+
* Helper to check if a string is a valid JavaScript identifier
|
|
39
|
+
*/
|
|
40
|
+
private isValidIdentifier;
|
|
41
|
+
/**
|
|
42
|
+
* Helper to safely format a property name for TypeScript type definitions
|
|
43
|
+
* Returns the property name with quotes if needed, or just the name if valid
|
|
44
|
+
*/
|
|
45
|
+
private formatPropertyName;
|
|
46
|
+
/**
|
|
47
|
+
* Generates the API namespace with all function declarations.
|
|
48
|
+
* Handles hierarchical group names (e.g., "github/readOnly" -> api.github.readOnly)
|
|
49
|
+
* @param groups - API groups to include
|
|
50
|
+
* @returns TypeScript definition string
|
|
51
|
+
*/
|
|
52
|
+
private generateAPINamespace;
|
|
53
|
+
/**
|
|
54
|
+
* Gets the list of available API group names.
|
|
55
|
+
* @returns Array of API group names
|
|
56
|
+
*/
|
|
57
|
+
getApiGroups(): string[];
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/aggregator/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,+BAA+B,CAAC;AAGvF;;;GAGG;AACH,qBAAa,aAAa;IACzB,OAAO,CAAC,SAAS,CAAmB;IAEpC;;;OAGG;gBACS,SAAS,EAAE,cAAc,EAAE;IAIvC;;;;OAIG;IACG,kBAAkB,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAuBpE;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAI5B;;;;;OAKG;IACH,OAAO,CAAC,qBAAqB;IAwB7B;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IAkB1B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAIzB;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAO1B;;;;;OAKG;IACH,OAAO,CAAC,oBAAoB;IAoE5B;;;OAGG;IACH,YAAY,IAAI,MAAM,EAAE;CAGxB"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { generateRuntimeTypes } from '../utils/runtime-types.js';
|
|
2
|
+
/**
|
|
3
|
+
* APIAggregator generates TypeScript type definitions from API configurations.
|
|
4
|
+
* Converts API group definitions into TypeScript declarations for use in code generation.
|
|
5
|
+
*/
|
|
6
|
+
export class APIAggregator {
|
|
7
|
+
apiGroups;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new APIAggregator instance.
|
|
10
|
+
* @param apiGroups - Array of API group configurations
|
|
11
|
+
*/
|
|
12
|
+
constructor(apiGroups) {
|
|
13
|
+
this.apiGroups = apiGroups;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Generates TypeScript type definitions for selected API groups.
|
|
17
|
+
* @param selectedGroups - Optional array of group names to include
|
|
18
|
+
* @returns TypeScript definition string
|
|
19
|
+
*/
|
|
20
|
+
async generateTypeScript(selectedGroups) {
|
|
21
|
+
const groups = selectedGroups
|
|
22
|
+
? this.apiGroups.filter((g) => selectedGroups.includes(g.name))
|
|
23
|
+
: this.apiGroups;
|
|
24
|
+
let typescript = `// Agent Tool Protocol Runtime SDK v1.0.0\n\n`;
|
|
25
|
+
typescript += this.generateRuntimeTypes();
|
|
26
|
+
for (const group of groups) {
|
|
27
|
+
typescript += `\n// API Group: ${group.name}\n`;
|
|
28
|
+
if (group.functions) {
|
|
29
|
+
for (const func of group.functions) {
|
|
30
|
+
typescript += this.generateFunctionTypes(func, group.name);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
typescript += this.generateAPINamespace(groups);
|
|
35
|
+
return typescript;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Generates TypeScript definitions for the runtime SDK.
|
|
39
|
+
* @returns TypeScript definition string
|
|
40
|
+
*/
|
|
41
|
+
generateRuntimeTypes() {
|
|
42
|
+
return generateRuntimeTypes();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Generates TypeScript types for a single function.
|
|
46
|
+
* @param func - Function definition
|
|
47
|
+
* @param groupName - API group name
|
|
48
|
+
* @returns TypeScript definition string
|
|
49
|
+
*/
|
|
50
|
+
generateFunctionTypes(func, groupName) {
|
|
51
|
+
const inputTypeName = `${func.name}_Input`;
|
|
52
|
+
const outputTypeName = `${func.name}_Output`;
|
|
53
|
+
let typescript = `\ninterface ${inputTypeName} {\n`;
|
|
54
|
+
if (func.inputSchema?.properties) {
|
|
55
|
+
const required = func.inputSchema.required || [];
|
|
56
|
+
for (const [key, value] of Object.entries(func.inputSchema.properties)) {
|
|
57
|
+
const prop = value;
|
|
58
|
+
const tsType = this.jsonSchemaTypeToTS(prop.type ?? 'any');
|
|
59
|
+
const comment = prop.description ? ` // ${prop.description}` : '';
|
|
60
|
+
const optional = required.includes(key) ? '' : '?';
|
|
61
|
+
typescript += ` ${key}${optional}: ${tsType};${comment}\n`;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
typescript += `}\n`;
|
|
65
|
+
typescript += `\ninterface ${outputTypeName} {\n`;
|
|
66
|
+
typescript += ` [key: string]: unknown;\n`;
|
|
67
|
+
typescript += `}\n`;
|
|
68
|
+
return typescript;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Converts JSON Schema type to TypeScript type.
|
|
72
|
+
* @param type - JSON Schema type string
|
|
73
|
+
* @returns TypeScript type string
|
|
74
|
+
*/
|
|
75
|
+
jsonSchemaTypeToTS(type) {
|
|
76
|
+
switch (type) {
|
|
77
|
+
case 'string':
|
|
78
|
+
return 'string';
|
|
79
|
+
case 'number':
|
|
80
|
+
case 'integer':
|
|
81
|
+
return 'number';
|
|
82
|
+
case 'boolean':
|
|
83
|
+
return 'boolean';
|
|
84
|
+
case 'array':
|
|
85
|
+
return 'unknown[]';
|
|
86
|
+
case 'object':
|
|
87
|
+
return 'Record<string, unknown>';
|
|
88
|
+
default:
|
|
89
|
+
return 'unknown';
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Helper to check if a string is a valid JavaScript identifier
|
|
94
|
+
*/
|
|
95
|
+
isValidIdentifier(name) {
|
|
96
|
+
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Helper to safely format a property name for TypeScript type definitions
|
|
100
|
+
* Returns the property name with quotes if needed, or just the name if valid
|
|
101
|
+
*/
|
|
102
|
+
formatPropertyName(name) {
|
|
103
|
+
if (!this.isValidIdentifier(name)) {
|
|
104
|
+
return `'${name}'`;
|
|
105
|
+
}
|
|
106
|
+
return name;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Generates the API namespace with all function declarations.
|
|
110
|
+
* Handles hierarchical group names (e.g., "github/readOnly" -> api.github.readOnly)
|
|
111
|
+
* @param groups - API groups to include
|
|
112
|
+
* @returns TypeScript definition string
|
|
113
|
+
*/
|
|
114
|
+
generateAPINamespace(groups) {
|
|
115
|
+
const rootGroups = new Map();
|
|
116
|
+
for (const group of groups) {
|
|
117
|
+
if (!group.functions || group.functions.length === 0)
|
|
118
|
+
continue;
|
|
119
|
+
const parts = group.name.split('/');
|
|
120
|
+
let current = rootGroups;
|
|
121
|
+
for (let i = 0; i < parts.length; i++) {
|
|
122
|
+
const part = parts[i];
|
|
123
|
+
if (!current.has(part)) {
|
|
124
|
+
current.set(part, { functions: [], subgroups: new Map() });
|
|
125
|
+
}
|
|
126
|
+
const node = current.get(part);
|
|
127
|
+
if (i === parts.length - 1) {
|
|
128
|
+
node.functions.push(...group.functions);
|
|
129
|
+
}
|
|
130
|
+
current = node.subgroups;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const generateLevel = (groups, indent) => {
|
|
134
|
+
let ts = '';
|
|
135
|
+
for (const [name, node] of groups.entries()) {
|
|
136
|
+
if (!name)
|
|
137
|
+
continue;
|
|
138
|
+
const formattedName = this.formatPropertyName(name);
|
|
139
|
+
ts += `${indent}${formattedName}: {\n`;
|
|
140
|
+
for (const func of node.functions) {
|
|
141
|
+
if (!func.name)
|
|
142
|
+
continue;
|
|
143
|
+
const funcName = this.formatPropertyName(func.name);
|
|
144
|
+
const description = func.description && typeof func.description === 'string'
|
|
145
|
+
? func.description.replace(/\n/g, ' ').substring(0, 200)
|
|
146
|
+
: '';
|
|
147
|
+
ts += `${indent} /**\n${indent} * ${description}\n${indent} */\n`;
|
|
148
|
+
ts += `${indent} ${funcName}(params: ${func.name}_Input): Promise<${func.name}_Output>;\n`;
|
|
149
|
+
}
|
|
150
|
+
if (node.subgroups.size > 0) {
|
|
151
|
+
ts += generateLevel(node.subgroups, indent + ' ');
|
|
152
|
+
}
|
|
153
|
+
ts += `${indent}};\n`;
|
|
154
|
+
}
|
|
155
|
+
return ts;
|
|
156
|
+
};
|
|
157
|
+
let typescript = `\ndeclare const api: {\n`;
|
|
158
|
+
typescript += generateLevel(rootGroups, ' ');
|
|
159
|
+
typescript += `};\n`;
|
|
160
|
+
typescript += `\nexport { api };\n`;
|
|
161
|
+
return typescript;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Gets the list of available API group names.
|
|
165
|
+
* @returns Array of API group names
|
|
166
|
+
*/
|
|
167
|
+
getApiGroups() {
|
|
168
|
+
return this.apiGroups.map((g) => g.name);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=index.js.map
|