@kadi.build/core 0.0.1-alpha.3 → 0.0.1-alpha.5

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.
Files changed (128) hide show
  1. package/README.md +754 -606
  2. package/dist/KadiClient.d.ts +440 -0
  3. package/dist/KadiClient.d.ts.map +1 -0
  4. package/dist/KadiClient.js +1518 -0
  5. package/dist/KadiClient.js.map +1 -0
  6. package/dist/errors/error-codes.d.ts +215 -0
  7. package/dist/errors/error-codes.d.ts.map +1 -0
  8. package/dist/errors/error-codes.js +295 -0
  9. package/dist/errors/error-codes.js.map +1 -0
  10. package/dist/index.d.ts +15 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +24 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/loadAbility.d.ts +106 -0
  15. package/dist/loadAbility.d.ts.map +1 -0
  16. package/dist/loadAbility.js +376 -0
  17. package/dist/loadAbility.js.map +1 -0
  18. package/dist/messages/BrokerMessages.d.ts +84 -0
  19. package/dist/messages/BrokerMessages.d.ts.map +1 -0
  20. package/dist/messages/BrokerMessages.js +125 -0
  21. package/dist/messages/BrokerMessages.js.map +1 -0
  22. package/dist/messages/MessageBuilder.d.ts +83 -0
  23. package/dist/messages/MessageBuilder.d.ts.map +1 -0
  24. package/dist/messages/MessageBuilder.js +144 -0
  25. package/dist/messages/MessageBuilder.js.map +1 -0
  26. package/dist/schemas/events.schemas.d.ts +177 -0
  27. package/dist/schemas/events.schemas.d.ts.map +1 -0
  28. package/dist/schemas/events.schemas.js +265 -0
  29. package/dist/schemas/events.schemas.js.map +1 -0
  30. package/dist/schemas/index.d.ts +3 -0
  31. package/dist/schemas/index.d.ts.map +1 -0
  32. package/dist/schemas/index.js +4 -0
  33. package/dist/schemas/index.js.map +1 -0
  34. package/dist/schemas/kadi.schemas.d.ts +70 -0
  35. package/dist/schemas/kadi.schemas.d.ts.map +1 -0
  36. package/dist/schemas/kadi.schemas.js +120 -0
  37. package/dist/schemas/kadi.schemas.js.map +1 -0
  38. package/dist/transports/BrokerTransport.d.ts +106 -0
  39. package/dist/transports/BrokerTransport.d.ts.map +1 -0
  40. package/dist/transports/BrokerTransport.js +177 -0
  41. package/dist/transports/BrokerTransport.js.map +1 -0
  42. package/dist/transports/NativeTransport.d.ts +82 -0
  43. package/dist/transports/NativeTransport.d.ts.map +1 -0
  44. package/dist/transports/NativeTransport.js +263 -0
  45. package/dist/transports/NativeTransport.js.map +1 -0
  46. package/dist/transports/StdioTransport.d.ts +112 -0
  47. package/dist/transports/StdioTransport.d.ts.map +1 -0
  48. package/dist/transports/StdioTransport.js +445 -0
  49. package/dist/transports/StdioTransport.js.map +1 -0
  50. package/dist/transports/Transport.d.ts +93 -0
  51. package/dist/transports/Transport.d.ts.map +1 -0
  52. package/dist/transports/Transport.js +13 -0
  53. package/dist/transports/Transport.js.map +1 -0
  54. package/dist/types/broker.d.ts +31 -0
  55. package/dist/types/broker.d.ts.map +1 -0
  56. package/dist/types/broker.js +6 -0
  57. package/dist/types/broker.js.map +1 -0
  58. package/dist/types/core.d.ts +139 -0
  59. package/dist/types/core.d.ts.map +1 -0
  60. package/dist/types/core.js +26 -0
  61. package/dist/types/core.js.map +1 -0
  62. package/dist/types/events.d.ts +186 -0
  63. package/dist/types/events.d.ts.map +1 -0
  64. package/dist/types/events.js +16 -0
  65. package/dist/types/events.js.map +1 -0
  66. package/dist/types/index.d.ts +9 -0
  67. package/dist/types/index.d.ts.map +1 -0
  68. package/dist/types/index.js +13 -0
  69. package/dist/types/index.js.map +1 -0
  70. package/dist/types/protocol.d.ts +160 -0
  71. package/dist/types/protocol.d.ts.map +1 -0
  72. package/dist/types/protocol.js +5 -0
  73. package/dist/types/protocol.js.map +1 -0
  74. package/dist/utils/agentUtils.d.ts +187 -0
  75. package/dist/utils/agentUtils.d.ts.map +1 -0
  76. package/dist/utils/agentUtils.js +185 -0
  77. package/dist/utils/agentUtils.js.map +1 -0
  78. package/dist/utils/commandUtils.d.ts +45 -0
  79. package/dist/utils/commandUtils.d.ts.map +1 -0
  80. package/dist/utils/commandUtils.js +145 -0
  81. package/dist/utils/commandUtils.js.map +1 -0
  82. package/dist/utils/configUtils.d.ts +55 -0
  83. package/dist/utils/configUtils.d.ts.map +1 -0
  84. package/dist/utils/configUtils.js +100 -0
  85. package/dist/utils/configUtils.js.map +1 -0
  86. package/dist/utils/logger.d.ts +59 -0
  87. package/dist/utils/logger.d.ts.map +1 -0
  88. package/dist/utils/logger.js +122 -0
  89. package/dist/utils/logger.js.map +1 -0
  90. package/dist/utils/pathUtils.d.ts +48 -0
  91. package/dist/utils/pathUtils.d.ts.map +1 -0
  92. package/dist/utils/pathUtils.js +128 -0
  93. package/dist/utils/pathUtils.js.map +1 -0
  94. package/package.json +56 -5
  95. package/agent.json +0 -18
  96. package/examples/example-abilities/echo-js/README.md +0 -131
  97. package/examples/example-abilities/echo-js/agent.json +0 -63
  98. package/examples/example-abilities/echo-js/package.json +0 -24
  99. package/examples/example-abilities/echo-js/service.js +0 -43
  100. package/examples/example-abilities/hash-go/agent.json +0 -53
  101. package/examples/example-abilities/hash-go/cmd/hash_ability/main.go +0 -340
  102. package/examples/example-abilities/hash-go/go.mod +0 -3
  103. package/examples/example-agent/abilities/echo-js/0.0.1/README.md +0 -131
  104. package/examples/example-agent/abilities/echo-js/0.0.1/agent.json +0 -63
  105. package/examples/example-agent/abilities/echo-js/0.0.1/package-lock.json +0 -93
  106. package/examples/example-agent/abilities/echo-js/0.0.1/package.json +0 -24
  107. package/examples/example-agent/abilities/echo-js/0.0.1/service.js +0 -41
  108. package/examples/example-agent/abilities/hash-go/0.0.1/agent.json +0 -53
  109. package/examples/example-agent/abilities/hash-go/0.0.1/bin/hash_ability +0 -0
  110. package/examples/example-agent/abilities/hash-go/0.0.1/cmd/hash_ability/main.go +0 -340
  111. package/examples/example-agent/abilities/hash-go/0.0.1/go.mod +0 -3
  112. package/examples/example-agent/agent.json +0 -39
  113. package/examples/example-agent/index.js +0 -102
  114. package/examples/example-agent/package-lock.json +0 -93
  115. package/examples/example-agent/package.json +0 -17
  116. package/src/KadiAbility.js +0 -478
  117. package/src/index.js +0 -65
  118. package/src/loadAbility.js +0 -1086
  119. package/src/servers/BaseRpcServer.js +0 -404
  120. package/src/servers/BrokerRpcServer.js +0 -776
  121. package/src/servers/StdioRpcServer.js +0 -360
  122. package/src/transport/BrokerMessageBuilder.js +0 -377
  123. package/src/transport/IpcMessageBuilder.js +0 -1229
  124. package/src/utils/agentUtils.js +0 -137
  125. package/src/utils/commandUtils.js +0 -64
  126. package/src/utils/configUtils.js +0 -72
  127. package/src/utils/logger.js +0 -161
  128. package/src/utils/pathUtils.js +0 -86
@@ -1,131 +0,0 @@
1
- # Echo-JS Ability
2
-
3
- A simple echo ability that demonstrates the new **improved KadiAbility architecture**. This ability showcases how easy it is to create powerful abilities with minimal code.
4
-
5
- ## What This Demonstrates
6
-
7
- ### 🏗️ **New Architecture Benefits**
8
-
9
- 1. **Cleaner Code**: The entire ability is ~100 lines vs ~600+ lines with the old architecture
10
- 2. **Transport Abstraction**: Automatically works with stdio and broker modes
11
- 3. **Built-in Discovery**: `__kadi_init` and `__kadi_discover` methods are automatic
12
- 4. **Better Error Handling**: Protocol errors are handled gracefully
13
- 5. **Metadata Support**: Easy to add schemas and descriptions to methods
14
-
15
- ### 🚀 **Simple API**
16
-
17
- ```javascript
18
- const ability = new KadiAbility({ name: 'echo-js' });
19
-
20
- ability
21
- .method('echo', async ({ message }) => {
22
- return { echo: message, timestamp: new Date().toISOString() };
23
- })
24
- .serve();
25
- ```
26
-
27
- That's it! The new architecture handles:
28
-
29
- - LSP framing for stdio communication
30
- - Request/response correlation
31
- - Error handling
32
- - Discovery methods
33
- - Transport selection
34
-
35
- ## Available Methods
36
-
37
- ### `echo`
38
-
39
- Returns your message with metadata:
40
-
41
- ```json
42
- {
43
- "method": "echo",
44
- "params": { "message": "Hello!" }
45
- }
46
- // Returns: { "echo": "Hello!", "timestamp": "2024-...", "length": 6 }
47
- ```
48
-
49
- ### `mirror`
50
-
51
- Returns your entire input object:
52
-
53
- ```json
54
- {
55
- "method": "mirror",
56
- "params": { "foo": "bar", "numbers": [1, 2, 3] }
57
- }
58
- // Returns: { "mirrored": {...}, "metadata": {...} }
59
- ```
60
-
61
- ### `health`
62
-
63
- Returns service health status:
64
-
65
- ```json
66
- {
67
- "method": "health",
68
- "params": {}
69
- }
70
- // Returns: { "status": "healthy", "uptime": 12345, "version": "0.0.1" }
71
- ```
72
-
73
- ## Running
74
-
75
- ### Stdio Mode (default)
76
-
77
- ```bash
78
- node service.js
79
- # Then send JSON-RPC messages via stdin
80
- ```
81
-
82
- ### Broker Mode
83
-
84
- ```bash
85
- KADI_MODE=broker KADI_BROKER_URL=ws://localhost:8080 node service.js
86
- ```
87
-
88
- ### Testing
89
-
90
- ```bash
91
- node test-manual.js
92
- ```
93
-
94
- ## Architecture Comparison
95
-
96
- ### Before (Old KadiAbility)
97
-
98
- ```javascript
99
- // Had to implement:
100
- // - LSP frame reading/writing (~200 lines)
101
- // - Request/response loop (~100 lines)
102
- // - Error handling (~100 lines)
103
- // - Discovery methods (~50 lines)
104
- // - Transport management (~50 lines)
105
- // Total: ~500+ lines before any business logic!
106
- ```
107
-
108
- ### After (New Architecture)
109
-
110
- ```javascript
111
- import { KadiAbility } from '@kadi/core';
112
-
113
- const ability = new KadiAbility({ name: 'my-ability' });
114
- ability.method('myMethod', handler);
115
- ability.serve();
116
-
117
- // Everything else is handled automatically!
118
- // Focus on business logic, not plumbing.
119
- ```
120
-
121
- ## Key Features Demonstrated
122
-
123
- - ✅ **Multiple Methods**: echo, mirror, health
124
- - ✅ **Method Metadata**: Descriptions and schemas
125
- - ✅ **Error Handling**: Graceful error responses
126
- - ✅ **Event Monitoring**: Request/response logging
127
- - ✅ **Discovery**: Built-in `__kadi_init` and `__kadi_discover`
128
- - ✅ **Transport Agnostic**: Works with stdio and broker modes
129
- - ✅ **Clean Shutdown**: Handles SIGINT/SIGTERM
130
-
131
- This is what ability development should feel like! 🎉
@@ -1,63 +0,0 @@
1
- {
2
- "name": "echo-js",
3
- "kind": "ability",
4
- "version": "0.0.1",
5
- "license": "MIT",
6
- "description": "Simple echo ability that returns whatever you send to it - demonstrates the new KadiAbility architecture.",
7
- "repo": "",
8
- "brokers": {
9
- "local": "ws://127.0.0.1:8080",
10
- "remote": "ws://kadi.build:8080"
11
- },
12
- "abilities": {},
13
- "scripts": {
14
- "preflight": "npm uninstall @kadi.build/core && npm cache clean --force && npm pack ../../../../../ && npm install kadi.build-core-0.0.1-alpha.2.tgz && rm kadi.build-core-0.0.1-alpha.2.tgz",
15
- "setup": "npm install",
16
- "start": "node service.js",
17
- "stop": ""
18
- },
19
- "interfaces": {
20
- "native": {
21
- "entry": "service.js"
22
- },
23
- "stdio": {
24
- "discover": true,
25
- "timeoutMs": 10000
26
- },
27
- "broker": {
28
- "discover": true,
29
- "timeoutMs": 15000
30
- }
31
- },
32
- "exports": [
33
- {
34
- "name": "echo",
35
- "title": "Echo",
36
- "description": "Returns the exact input you provide - useful for testing.",
37
- "inputSchema": {
38
- "type": "object",
39
- "properties": {
40
- "message": {
41
- "type": "string",
42
- "description": "Message to echo back"
43
- }
44
- },
45
- "required": ["message"]
46
- },
47
- "outputSchema": {
48
- "type": "object",
49
- "properties": {
50
- "echo": {
51
- "type": "string"
52
- },
53
- "timestamp": {
54
- "type": "string"
55
- },
56
- "length": {
57
- "type": "number"
58
- }
59
- }
60
- }
61
- }
62
- ]
63
- }
@@ -1,93 +0,0 @@
1
- {
2
- "name": "echo-js",
3
- "version": "0.0.1",
4
- "lockfileVersion": 3,
5
- "requires": true,
6
- "packages": {
7
- "": {
8
- "name": "echo-js",
9
- "version": "0.0.1",
10
- "license": "MIT",
11
- "dependencies": {
12
- "@kadi.build/core": "file:kadi.build-core-0.0.1-alpha.2.tgz"
13
- }
14
- },
15
- "node_modules/@kadi.build/core": {
16
- "version": "0.0.1-alpha.2",
17
- "resolved": "file:kadi.build-core-0.0.1-alpha.2.tgz",
18
- "integrity": "sha512-2sOOpGC4+Ze3slPJOBU//d1F20svyjMjEYzGLG3P95oqab38fwm7nlu+7xv/UEhwWAkvVbkMw649lnvznSI4TQ==",
19
- "license": "MIT",
20
- "dependencies": {
21
- "chalk": "^5.5.0",
22
- "debug": "^4.4.1",
23
- "events": "^3.3.0",
24
- "ws": "^8.16.0"
25
- }
26
- },
27
- "node_modules/chalk": {
28
- "version": "5.6.0",
29
- "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.6.0.tgz",
30
- "integrity": "sha512-46QrSQFyVSEyYAgQ22hQ+zDa60YHA4fBstHmtSApj1Y5vKtG27fWowW03jCk5KcbXEWPZUIR894aARCA/G1kfQ==",
31
- "license": "MIT",
32
- "engines": {
33
- "node": "^12.17.0 || ^14.13 || >=16.0.0"
34
- },
35
- "funding": {
36
- "url": "https://github.com/chalk/chalk?sponsor=1"
37
- }
38
- },
39
- "node_modules/debug": {
40
- "version": "4.4.1",
41
- "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.1.tgz",
42
- "integrity": "sha512-KcKCqiftBJcZr++7ykoDIEwSa3XWowTfNPo92BYxjXiyYEVrUQh2aLyhxBCwww+heortUFxEJYcRzosstTEBYQ==",
43
- "license": "MIT",
44
- "dependencies": {
45
- "ms": "^2.1.3"
46
- },
47
- "engines": {
48
- "node": ">=6.0"
49
- },
50
- "peerDependenciesMeta": {
51
- "supports-color": {
52
- "optional": true
53
- }
54
- }
55
- },
56
- "node_modules/events": {
57
- "version": "3.3.0",
58
- "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz",
59
- "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==",
60
- "license": "MIT",
61
- "engines": {
62
- "node": ">=0.8.x"
63
- }
64
- },
65
- "node_modules/ms": {
66
- "version": "2.1.3",
67
- "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
68
- "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
69
- "license": "MIT"
70
- },
71
- "node_modules/ws": {
72
- "version": "8.18.3",
73
- "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.3.tgz",
74
- "integrity": "sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg==",
75
- "license": "MIT",
76
- "engines": {
77
- "node": ">=10.0.0"
78
- },
79
- "peerDependencies": {
80
- "bufferutil": "^4.0.1",
81
- "utf-8-validate": ">=5.0.2"
82
- },
83
- "peerDependenciesMeta": {
84
- "bufferutil": {
85
- "optional": true
86
- },
87
- "utf-8-validate": {
88
- "optional": true
89
- }
90
- }
91
- }
92
- }
93
- }
@@ -1,24 +0,0 @@
1
- {
2
- "name": "echo-js",
3
- "version": "0.0.1",
4
- "description": "Simple echo ability demonstrating the new KadiAbility architecture",
5
- "type": "module",
6
- "main": "service.js",
7
- "scripts": {
8
- "preflight": "",
9
- "setup": "npm install",
10
- "start": "node service.js",
11
- "test": "echo 'No tests yet'"
12
- },
13
- "keywords": [
14
- "kadi",
15
- "ability",
16
- "echo",
17
- "demo"
18
- ],
19
- "author": "",
20
- "license": "MIT",
21
- "dependencies": {
22
- "@kadi.build/core": "file:kadi.build-core-0.0.1-alpha.2.tgz"
23
- }
24
- }
@@ -1,41 +0,0 @@
1
- // echo-js/index.ts (or .js)
2
- import { KadiAbility } from '@kadi.build/core';
3
-
4
- const echoAbility = new KadiAbility({
5
- name: 'echo-js',
6
- version: '0.0.1',
7
- description: 'Simple echo ability demonstrating the new KadiAbility architecture',
8
- scope: process.env.KADI_AGENT_SCOPE,
9
- });
10
-
11
- async function echo(message) {
12
- const timestamp = new Date().toISOString();
13
- const messageText = message?.message ?? message ?? '';
14
- const length = messageText.length;
15
-
16
- echoAbility.publishEvent('echo:test-event', { from: 'message echo'});
17
- echoAbility.publishEvent('echo:test-event', { from: 'message echo 2'});
18
-
19
- return { echo: messageText, timestamp, length };
20
- }
21
-
22
- async function say_message(message) {
23
- return { message };
24
- }
25
-
26
- // Register methods
27
- echoAbility.method('echo', echo);
28
- echoAbility.method('say_message', say_message, {
29
- description: 'Say a message',
30
- inputSchema: { type: 'object', properties: { message: { type: 'string' } } },
31
- outputSchema: { type: 'object', properties: { message: { type: 'string' } } },
32
- });
33
-
34
- // For native/in-process you usually do NOT need serve().
35
- // If you keep it for other protocols, it won’t hurt, but isn’t required here.
36
- echoAbility.serve().catch((error) => {
37
- console.error(`[echo-js] Fatal error: ${error.message}`);
38
- process.exit(1);
39
- });
40
-
41
- export default echoAbility;
@@ -1,53 +0,0 @@
1
- {
2
- "name": "hash-go",
3
- "kind": "ability",
4
- "version": "0.0.1",
5
- "license": "MIT",
6
- "description": "Compute digests (sha256 default).",
7
- "repo": "",
8
- "brokers": {
9
- "local": "ws://127.0.0.1:8080",
10
- "remote": "ws://146.190.121.213:8080"
11
- },
12
- "abilities": {},
13
- "scripts": {
14
- "preflight": "",
15
- "setup": "go mod tidy && mkdir -p bin && go build -o bin/hash_ability ./cmd/hash_ability",
16
- "start": "./bin/hash_ability",
17
- "stop": ""
18
- },
19
- "interfaces": {
20
- "stdio": {
21
- "discover": true,
22
- "timeoutMs": 10000
23
- }
24
- },
25
- "exports": [
26
- {
27
- "name": "digest",
28
- "title": "Compute Digest",
29
- "description": "Return a hex digest of the input text.",
30
- "inputSchema": {
31
- "type": "object",
32
- "properties": {
33
- "text": { "type": "string", "description": "Input text" },
34
- "algo": {
35
- "type": "string",
36
- "enum": ["sha256", "md5"],
37
- "default": "sha256",
38
- "description": "Hash algorithm"
39
- }
40
- },
41
- "required": ["text"]
42
- },
43
- "outputSchema": {
44
- "type": "object",
45
- "properties": {
46
- "algo": { "type": "string" },
47
- "hex": { "type": "string" }
48
- },
49
- "required": ["algo", "hex"]
50
- }
51
- }
52
- ]
53
- }