@koi-language/koi 1.0.5 → 1.1.0
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 +4 -125
- package/examples/.build/agent-dialogue.ts +138 -0
- package/examples/.build/agent-dialogue.ts.map +1 -0
- package/examples/.build/chess.ts +77 -0
- package/examples/.build/chess.ts.map +1 -0
- package/examples/.build/delegation-test.ts +140 -0
- package/examples/.build/delegation-test.ts.map +1 -0
- package/examples/.build/dialog-demo.ts +77 -0
- package/examples/.build/dialog-demo.ts.map +1 -0
- package/examples/.build/hello-world.ts +77 -0
- package/examples/.build/hello-world.ts.map +1 -0
- package/examples/.build/lover-dialog-demo.ts +77 -0
- package/examples/.build/lover-dialog-demo.ts.map +1 -0
- package/examples/.build/package.json +3 -0
- package/examples/.build/registry-interactive-demo.ts +202 -0
- package/examples/.build/registry-interactive-demo.ts.map +1 -0
- package/examples/.build/registry-playbook-demo.ts +201 -0
- package/examples/.build/registry-playbook-demo.ts.map +1 -0
- package/examples/.build/tic-tac-toe.ts +77 -0
- package/examples/.build/tic-tac-toe.ts.map +1 -0
- package/examples/actions-demo.koi +8 -9
- package/examples/activists-dialogue.koi +75 -0
- package/examples/agent-dialogue.koi +66 -0
- package/examples/chess.koi +19 -0
- package/examples/counter.koi +20 -69
- package/examples/delegation-test.koi +16 -18
- package/examples/dialog-demo.koi +20 -0
- package/examples/hello-world.koi +7 -43
- package/examples/mcp-stdio-demo.koi +29 -0
- package/examples/memory-test.koi +49 -0
- package/examples/mobile-mcp-demo.koi +32 -0
- package/examples/multi-event-handler-test.koi +16 -18
- package/examples/pipeline.koi +15 -17
- package/examples/prompt-demo.koi +20 -0
- package/examples/{registry-playbook-email-compositor.koi → registry-interactive-demo.koi} +27 -27
- package/examples/registry-playbook-demo.koi +28 -28
- package/examples/skill-import-test.koi +7 -9
- package/examples/skills/.build/math-operations.ts +1656 -0
- package/examples/skills/.build/math-operations.ts.map +1 -0
- package/examples/skills/.build/package.json +3 -0
- package/examples/skills/.build/string-operations.ts +1643 -0
- package/examples/skills/.build/string-operations.ts.map +1 -0
- package/examples/skills/advanced/.build/index.ts +3223 -0
- package/examples/skills/advanced/.build/index.ts.map +1 -0
- package/examples/skills/advanced/.build/package.json +3 -0
- package/examples/skills/advanced/index.koi +3 -5
- package/examples/skills/math-operations.koi +1 -3
- package/examples/skills/string-operations.koi +1 -3
- package/examples/tic-tac-toe.koi +19 -0
- package/examples/utils/echo-mcp-server.js +141 -0
- package/examples/web-delegation-demo.koi +15 -17
- package/package.json +2 -1
- package/src/cli/koi.js +30 -41
- package/src/compiler/build-optimizer.js +204 -289
- package/src/compiler/cache-manager.js +1 -1
- package/src/compiler/import-resolver.js +5 -9
- package/src/compiler/parser.js +6072 -3476
- package/src/compiler/transpiler.js +346 -38
- package/src/grammar/koi.pegjs +302 -62
- package/src/runtime/actions/{format.js → call-llm.js} +37 -44
- package/src/runtime/actions/call-mcp.js +97 -0
- package/src/runtime/actions/if.js +179 -0
- package/src/runtime/actions/print.js +3 -1
- package/src/runtime/actions/prompt-user.js +75 -0
- package/src/runtime/actions/repeat.js +147 -0
- package/src/runtime/actions/shell.js +185 -0
- package/src/runtime/actions/while.js +205 -0
- package/src/runtime/agent.js +592 -178
- package/src/runtime/cli-display.js +26 -0
- package/src/runtime/cli-input.js +421 -0
- package/src/runtime/cli-logger.js +2 -5
- package/src/runtime/cli-markdown.js +61 -0
- package/src/runtime/cli-select.js +106 -0
- package/src/runtime/incremental-json-parser.js +51 -17
- package/src/runtime/index.js +1 -0
- package/src/runtime/llm-provider.js +1083 -572
- package/src/runtime/mcp-registry.js +141 -0
- package/src/runtime/mcp-stdio-client.js +334 -0
- package/src/runtime/planner.js +1 -1
- package/src/runtime/playbook-session.js +259 -0
- package/src/runtime/registry-backends/keyv-sqlite.js +1 -1
- package/src/runtime/registry-backends/local.js +1 -1
- package/src/runtime/router.js +22 -26
- package/src/runtime/runtime.js +7 -1
- package/examples/cache-test.koi +0 -29
- package/examples/calculator.koi +0 -61
- package/examples/clear-registry.js +0 -33
- package/examples/clear-registry.koi +0 -30
- package/examples/code-introspection-test.koi +0 -149
- package/examples/directory-import-test.koi +0 -84
- package/examples/hello-world-claude.koi +0 -52
- package/examples/hello.koi +0 -24
- package/examples/mcp-example.koi +0 -70
- package/examples/new-import-test.koi +0 -89
- package/examples/registry-demo.koi +0 -184
- package/examples/registry-playbook-email-compositor-2.koi +0 -140
- package/examples/sentiment.koi +0 -90
- package/examples/simple.koi +0 -48
- package/examples/task-chaining-demo.koi +0 -244
- package/examples/test-await.koi +0 -22
- package/examples/test-crypto-sha256.koi +0 -196
- package/examples/test-delegation.koi +0 -41
- package/examples/test-multi-team-routing.koi +0 -258
- package/examples/test-no-handler.koi +0 -35
- package/examples/test-npm-import.koi +0 -67
- package/examples/test-parse.koi +0 -10
- package/examples/test-peers-with-team.koi +0 -59
- package/examples/test-permissions-fail.koi +0 -20
- package/examples/test-permissions.koi +0 -36
- package/examples/test-simple-registry.koi +0 -31
- package/examples/test-typescript-import.koi +0 -64
- package/examples/test-uses-team-syntax.koi +0 -25
- package/examples/test-uses-team.koi +0 -31
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
package "test.multi.team.routing"
|
|
2
|
-
|
|
3
|
-
// Test: Multi-team routing with peers() and peers(TeamName)
|
|
4
|
-
// This test validates that:
|
|
5
|
-
// 1. peers.event() broadcasts to all teams
|
|
6
|
-
// 2. peers(TeamName).event() sends only to specific team
|
|
7
|
-
// 3. Multiple teams can coexist and be addressed independently
|
|
8
|
-
|
|
9
|
-
role Worker { can work, can process }
|
|
10
|
-
|
|
11
|
-
// Team A workers
|
|
12
|
-
Agent WorkerA1 : Worker {
|
|
13
|
-
on work(args: Json) {
|
|
14
|
-
return {
|
|
15
|
-
from: "WorkerA1",
|
|
16
|
-
team: "TeamA",
|
|
17
|
-
data: args
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
on process(args: Json) {
|
|
22
|
-
return {
|
|
23
|
-
from: "WorkerA1",
|
|
24
|
-
team: "TeamA",
|
|
25
|
-
operation: "process",
|
|
26
|
-
data: args
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
Agent WorkerA2 : Worker {
|
|
32
|
-
on work(args: Json) {
|
|
33
|
-
return {
|
|
34
|
-
from: "WorkerA2",
|
|
35
|
-
team: "TeamA",
|
|
36
|
-
data: args
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
on process(args: Json) {
|
|
41
|
-
return {
|
|
42
|
-
from: "WorkerA2",
|
|
43
|
-
team: "TeamA",
|
|
44
|
-
operation: "process",
|
|
45
|
-
data: args
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Team B workers
|
|
51
|
-
Agent WorkerB1 : Worker {
|
|
52
|
-
on work(args: Json) {
|
|
53
|
-
return {
|
|
54
|
-
from: "WorkerB1",
|
|
55
|
-
team: "TeamB",
|
|
56
|
-
data: args
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
on process(args: Json) {
|
|
61
|
-
return {
|
|
62
|
-
from: "WorkerB1",
|
|
63
|
-
team: "TeamB",
|
|
64
|
-
operation: "process",
|
|
65
|
-
data: args
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
Agent WorkerB2 : Worker {
|
|
71
|
-
on work(args: Json) {
|
|
72
|
-
return {
|
|
73
|
-
from: "WorkerB2",
|
|
74
|
-
team: "TeamB",
|
|
75
|
-
data: args
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
on process(args: Json) {
|
|
80
|
-
return {
|
|
81
|
-
from: "WorkerB2",
|
|
82
|
-
team: "TeamB",
|
|
83
|
-
operation: "process",
|
|
84
|
-
data: args
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Team C workers
|
|
90
|
-
Agent WorkerC1 : Worker {
|
|
91
|
-
on work(args: Json) {
|
|
92
|
-
return {
|
|
93
|
-
from: "WorkerC1",
|
|
94
|
-
team: "TeamC",
|
|
95
|
-
data: args
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
on process(args: Json) {
|
|
100
|
-
return {
|
|
101
|
-
from: "WorkerC1",
|
|
102
|
-
team: "TeamC",
|
|
103
|
-
operation: "process",
|
|
104
|
-
data: args
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Define three teams
|
|
110
|
-
Team TeamA {
|
|
111
|
-
worker1 = WorkerA1
|
|
112
|
-
worker2 = WorkerA2
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
Team TeamB {
|
|
116
|
-
worker1 = WorkerB1
|
|
117
|
-
worker2 = WorkerB2
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
Team TeamC {
|
|
121
|
-
worker1 = WorkerC1
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Coordinator that uses all three teams
|
|
125
|
-
Agent TestCoordinator : Worker {
|
|
126
|
-
uses Team TeamA, TeamB, TeamC
|
|
127
|
-
|
|
128
|
-
on runTests(args: Json) {
|
|
129
|
-
console.log("=".repeat(60))
|
|
130
|
-
console.log("Multi-Team Routing Test Suite")
|
|
131
|
-
console.log("=".repeat(60))
|
|
132
|
-
|
|
133
|
-
// Test 1: Broadcast to all teams (peers.event)
|
|
134
|
-
console.log("\n[TEST 1] Broadcast to all teams with peers.event()")
|
|
135
|
-
console.log("-".repeat(60))
|
|
136
|
-
const result1 = await send peers.event("work").role(Worker).any()({
|
|
137
|
-
test: "broadcast",
|
|
138
|
-
message: "Should reach any team"
|
|
139
|
-
}) timeout 10s
|
|
140
|
-
|
|
141
|
-
console.log("Result:", JSON.stringify(result1, null, 2))
|
|
142
|
-
const test1Pass = result1 && result1.team
|
|
143
|
-
if (test1Pass) {
|
|
144
|
-
console.log("✓ TEST 1 PASSED: Received response from", result1.team)
|
|
145
|
-
} else {
|
|
146
|
-
console.log("✗ TEST 1 FAILED: No response received")
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Test 2: Send only to TeamA
|
|
150
|
-
console.log("\n[TEST 2] Send to TeamA only with peers(TeamA).event()")
|
|
151
|
-
console.log("-".repeat(60))
|
|
152
|
-
const result2 = await send peers(TeamA).event("work").role(Worker).any()({
|
|
153
|
-
test: "teamA",
|
|
154
|
-
message: "Should only reach TeamA"
|
|
155
|
-
}) timeout 10s
|
|
156
|
-
|
|
157
|
-
console.log("Result:", JSON.stringify(result2, null, 2))
|
|
158
|
-
const test2Pass = result2 && result2.team == "TeamA"
|
|
159
|
-
if (test2Pass) {
|
|
160
|
-
console.log("✓ TEST 2 PASSED: Correctly routed to TeamA")
|
|
161
|
-
} else {
|
|
162
|
-
console.log("✗ TEST 2 FAILED: Expected team=TeamA, got", result2.team)
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// Test 3: Send only to TeamB
|
|
166
|
-
console.log("\n[TEST 3] Send to TeamB only with peers(TeamB).event()")
|
|
167
|
-
console.log("-".repeat(60))
|
|
168
|
-
const result3 = await send peers(TeamB).event("work").role(Worker).any()({
|
|
169
|
-
test: "teamB",
|
|
170
|
-
message: "Should only reach TeamB"
|
|
171
|
-
}) timeout 10s
|
|
172
|
-
|
|
173
|
-
console.log("Result:", JSON.stringify(result3, null, 2))
|
|
174
|
-
const test3Pass = result3 && result3.team == "TeamB"
|
|
175
|
-
if (test3Pass) {
|
|
176
|
-
console.log("✓ TEST 3 PASSED: Correctly routed to TeamB")
|
|
177
|
-
} else {
|
|
178
|
-
console.log("✗ TEST 3 FAILED: Expected team=TeamB, got", result3.team)
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Test 4: Send only to TeamC
|
|
182
|
-
console.log("\n[TEST 4] Send to TeamC only with peers(TeamC).event()")
|
|
183
|
-
console.log("-".repeat(60))
|
|
184
|
-
const result4 = await send peers(TeamC).event("work").role(Worker).any()({
|
|
185
|
-
test: "teamC",
|
|
186
|
-
message: "Should only reach TeamC"
|
|
187
|
-
}) timeout 10s
|
|
188
|
-
|
|
189
|
-
console.log("Result:", JSON.stringify(result4, null, 2))
|
|
190
|
-
const test4Pass = result4 && result4.team == "TeamC"
|
|
191
|
-
if (test4Pass) {
|
|
192
|
-
console.log("✓ TEST 4 PASSED: Correctly routed to TeamC")
|
|
193
|
-
} else {
|
|
194
|
-
console.log("✗ TEST 4 FAILED: Expected team=TeamC, got", result4.team)
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// Test 5: Different event to specific team
|
|
198
|
-
console.log("\n[TEST 5] Send 'process' event to TeamA only")
|
|
199
|
-
console.log("-".repeat(60))
|
|
200
|
-
const result5 = await send peers(TeamA).event("process").role(Worker).any()({
|
|
201
|
-
test: "process",
|
|
202
|
-
value: 42
|
|
203
|
-
}) timeout 10s
|
|
204
|
-
|
|
205
|
-
console.log("Result:", JSON.stringify(result5, null, 2))
|
|
206
|
-
const test5Pass = result5 && result5.team == "TeamA" && result5.operation == "process"
|
|
207
|
-
if (test5Pass) {
|
|
208
|
-
console.log("✓ TEST 5 PASSED: Process event routed to TeamA")
|
|
209
|
-
} else {
|
|
210
|
-
console.log("✗ TEST 5 FAILED: Expected TeamA process event")
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// Test 6: Verify isolation - TeamB should not receive TeamA messages
|
|
214
|
-
console.log("\n[TEST 6] Verify team isolation")
|
|
215
|
-
console.log("-".repeat(60))
|
|
216
|
-
const resultA = await send peers(TeamA).event("work").role(Worker).any()({
|
|
217
|
-
target: "TeamA"
|
|
218
|
-
}) timeout 10s
|
|
219
|
-
const resultB = await send peers(TeamB).event("work").role(Worker).any()({
|
|
220
|
-
target: "TeamB"
|
|
221
|
-
}) timeout 10s
|
|
222
|
-
|
|
223
|
-
console.log("TeamA result:", JSON.stringify(resultA, null, 2))
|
|
224
|
-
console.log("TeamB result:", JSON.stringify(resultB, null, 2))
|
|
225
|
-
const test6Pass = resultA.team == "TeamA" && resultB.team == "TeamB"
|
|
226
|
-
if (test6Pass) {
|
|
227
|
-
console.log("✓ TEST 6 PASSED: Teams are properly isolated")
|
|
228
|
-
} else {
|
|
229
|
-
console.log("✗ TEST 6 FAILED: Team isolation failed")
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// Summary
|
|
233
|
-
console.log("\n" + "=".repeat(60))
|
|
234
|
-
console.log("Test Summary")
|
|
235
|
-
console.log("=".repeat(60))
|
|
236
|
-
const allPassed = test1Pass && test2Pass && test3Pass && test4Pass && test5Pass && test6Pass
|
|
237
|
-
|
|
238
|
-
if (allPassed) {
|
|
239
|
-
console.log("\n✓ ALL 6 TESTS PASSED!")
|
|
240
|
-
} else {
|
|
241
|
-
console.log("\n✗ SOME TESTS FAILED - See results above")
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return {
|
|
245
|
-
success: allPassed,
|
|
246
|
-
results: {
|
|
247
|
-
test1: test1Pass,
|
|
248
|
-
test2: test2Pass,
|
|
249
|
-
test3: test3Pass,
|
|
250
|
-
test4: test4Pass,
|
|
251
|
-
test5: test5Pass,
|
|
252
|
-
test6: test6Pass
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
run TestCoordinator.runTests({})
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
// Test: Error when no agent can handle an event
|
|
2
|
-
|
|
3
|
-
package "test.no.handler"
|
|
4
|
-
|
|
5
|
-
role Worker { can execute }
|
|
6
|
-
|
|
7
|
-
Agent SimpleWorker : Worker {
|
|
8
|
-
on doWork(args: Json) {
|
|
9
|
-
playbook """
|
|
10
|
-
Do some work
|
|
11
|
-
Return JSON: { "result": "done" }
|
|
12
|
-
"""
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
Team SimpleTeam {
|
|
17
|
-
worker = SimpleWorker
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
Agent Requester : Worker {
|
|
21
|
-
uses Team SimpleTeam
|
|
22
|
-
|
|
23
|
-
on testNoHandler(args: Json) {
|
|
24
|
-
console.log("Testing error when no agent can handle event...")
|
|
25
|
-
|
|
26
|
-
// Try to send an event that no agent in the team can handle
|
|
27
|
-
const result = await send peers.event("nonExistentEvent").any()({
|
|
28
|
-
data: "test"
|
|
29
|
-
}) timeout 5s
|
|
30
|
-
|
|
31
|
-
return result
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
run Requester.testNoHandler({})
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
package "test.npm.import"
|
|
2
|
-
|
|
3
|
-
// Import lodash from node_modules
|
|
4
|
-
import "lodash"
|
|
5
|
-
|
|
6
|
-
role Worker { can work }
|
|
7
|
-
|
|
8
|
-
Agent DataProcessor : Worker {
|
|
9
|
-
on process(args: Json) {
|
|
10
|
-
console.log("=".repeat(60))
|
|
11
|
-
console.log("Testing NPM Package Import (lodash)")
|
|
12
|
-
console.log("=".repeat(60))
|
|
13
|
-
|
|
14
|
-
// Test chunk
|
|
15
|
-
const chunked = lodash.chunk([1, 2, 3, 4, 5, 6, 7, 8], 3)
|
|
16
|
-
console.log("\nTest 1: chunk([1-8], 3) =", JSON.stringify(chunked))
|
|
17
|
-
|
|
18
|
-
// Test uniq
|
|
19
|
-
const unique = lodash.uniq([1, 2, 2, 3, 3, 3, 4, 5, 5])
|
|
20
|
-
console.log("Test 2: uniq([1,2,2,3,3,3,4,5,5]) =", JSON.stringify(unique))
|
|
21
|
-
|
|
22
|
-
// Test pick
|
|
23
|
-
const obj = { a: 1, b: 2, c: 3, d: 4 }
|
|
24
|
-
const picked = lodash.pick(obj, ["a", "c"])
|
|
25
|
-
console.log("Test 3: pick({a:1,b:2,c:3,d:4}, ['a','c']) =", JSON.stringify(picked))
|
|
26
|
-
|
|
27
|
-
// Test sum
|
|
28
|
-
const total = lodash.sum([1, 2, 3, 4, 5])
|
|
29
|
-
console.log("Test 4: sum([1,2,3,4,5]) =", total)
|
|
30
|
-
|
|
31
|
-
// Test mean
|
|
32
|
-
const avg = lodash.mean([10, 20, 30, 40, 50])
|
|
33
|
-
console.log("Test 5: mean([10,20,30,40,50]) =", avg)
|
|
34
|
-
|
|
35
|
-
// Test reverse
|
|
36
|
-
const reversed = lodash.reverse([1, 2, 3, 4, 5])
|
|
37
|
-
console.log("Test 6: reverse([1,2,3,4,5]) =", JSON.stringify(reversed))
|
|
38
|
-
|
|
39
|
-
// Test max
|
|
40
|
-
const maximum = lodash.max([10, 50, 30, 20, 40])
|
|
41
|
-
console.log("Test 7: max([10,50,30,20,40]) =", maximum)
|
|
42
|
-
|
|
43
|
-
// Test min
|
|
44
|
-
const minimum = lodash.min([10, 50, 30, 20, 40])
|
|
45
|
-
console.log("Test 8: min([10,50,30,20,40]) =", minimum)
|
|
46
|
-
|
|
47
|
-
console.log("\n" + "=".repeat(60))
|
|
48
|
-
console.log("All lodash tests completed!")
|
|
49
|
-
console.log("=".repeat(60))
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
success: true,
|
|
53
|
-
tests: {
|
|
54
|
-
chunked: chunked,
|
|
55
|
-
unique: unique,
|
|
56
|
-
picked: picked,
|
|
57
|
-
sum: total,
|
|
58
|
-
mean: avg,
|
|
59
|
-
reversed: reversed,
|
|
60
|
-
max: maximum,
|
|
61
|
-
min: minimum
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
run DataProcessor.process({})
|
package/examples/test-parse.koi
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
package "test.peers.team"
|
|
2
|
-
|
|
3
|
-
role Worker { can work }
|
|
4
|
-
|
|
5
|
-
Agent WorkerA : Worker {
|
|
6
|
-
on work(args: Json) {
|
|
7
|
-
return { from: "WorkerA", data: args }
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
Agent WorkerB : Worker {
|
|
12
|
-
on work(args: Json) {
|
|
13
|
-
return { from: "WorkerB", data: args }
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
Team TeamA {
|
|
18
|
-
worker = WorkerA
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
Team TeamB {
|
|
22
|
-
worker = WorkerB
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
Agent Coordinator : Worker {
|
|
26
|
-
uses Team TeamA, TeamB
|
|
27
|
-
|
|
28
|
-
on coordinate(args: Json) {
|
|
29
|
-
// Test 1: Send to all teams via common router
|
|
30
|
-
console.log("Test 1: Send to all teams (peers.event)")
|
|
31
|
-
const resultAll = await send peers.event("work").role(Worker).any()({
|
|
32
|
-
message: "to all teams"
|
|
33
|
-
}) timeout 10s
|
|
34
|
-
console.log("Result from all:", JSON.stringify(resultAll))
|
|
35
|
-
|
|
36
|
-
// Test 2: Send only to TeamA
|
|
37
|
-
console.log("\nTest 2: Send to TeamA only (peers(TeamA).event)")
|
|
38
|
-
const resultTeamA = await send peers(TeamA).event("work").role(Worker).any()({
|
|
39
|
-
message: "to TeamA only"
|
|
40
|
-
}) timeout 10s
|
|
41
|
-
console.log("Result from TeamA:", JSON.stringify(resultTeamA))
|
|
42
|
-
|
|
43
|
-
// Test 3: Send only to TeamB
|
|
44
|
-
console.log("\nTest 3: Send to TeamB only (peers(TeamB).event)")
|
|
45
|
-
const resultTeamB = await send peers(TeamB).event("work").role(Worker).any()({
|
|
46
|
-
message: "to TeamB only"
|
|
47
|
-
}) timeout 10s
|
|
48
|
-
console.log("Result from TeamB:", JSON.stringify(resultTeamB))
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
success: true,
|
|
52
|
-
allTeams: resultAll,
|
|
53
|
-
teamA: resultTeamA,
|
|
54
|
-
teamB: resultTeamB
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
run Coordinator.coordinate({ test: true })
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// Test that permissions are enforced
|
|
2
|
-
package "test.permissions.fail"
|
|
3
|
-
|
|
4
|
-
// Role without execute permission
|
|
5
|
-
role ReadOnly { can registry_read }
|
|
6
|
-
|
|
7
|
-
// Agent without execute permission - should fail when trying to print
|
|
8
|
-
Agent ReadOnlyAgent : ReadOnly {
|
|
9
|
-
llm default = { provider: "openai", model: "gpt-4o-mini" }
|
|
10
|
-
|
|
11
|
-
on test(args: Json) {
|
|
12
|
-
playbook """
|
|
13
|
-
Try to print a message (should fail due to missing execute permission).
|
|
14
|
-
|
|
15
|
-
Show: "❌ This should not appear because print requires execute permission"
|
|
16
|
-
"""
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
run ReadOnlyAgent.test({})
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
// Test permissions system
|
|
2
|
-
package "test.permissions"
|
|
3
|
-
|
|
4
|
-
// Role with execute permission
|
|
5
|
-
role Worker { can execute }
|
|
6
|
-
|
|
7
|
-
// Role without execute permission (empty)
|
|
8
|
-
role ReadOnly { can registry_read }
|
|
9
|
-
|
|
10
|
-
// Agent with execute permission - should work
|
|
11
|
-
Agent TestAgent : Worker {
|
|
12
|
-
llm default = { provider: "openai", model: "gpt-4o-mini" }
|
|
13
|
-
|
|
14
|
-
on test(args: Json) {
|
|
15
|
-
playbook """
|
|
16
|
-
Print a simple message to test permissions.
|
|
17
|
-
|
|
18
|
-
Show: "✅ Print action works with execute permission"
|
|
19
|
-
"""
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Agent without execute permission - should fail
|
|
24
|
-
Agent ReadOnlyAgent : ReadOnly {
|
|
25
|
-
llm default = { provider: "openai", model: "gpt-4o-mini" }
|
|
26
|
-
|
|
27
|
-
on test(args: Json) {
|
|
28
|
-
playbook """
|
|
29
|
-
Try to print a message (should fail due to missing execute permission).
|
|
30
|
-
|
|
31
|
-
Show: "❌ This should not appear"
|
|
32
|
-
"""
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
run TestAgent.test({})
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// Simple test for registry operations
|
|
2
|
-
package "test.simple"
|
|
3
|
-
|
|
4
|
-
role Worker { can execute }
|
|
5
|
-
|
|
6
|
-
Agent SimpleWorker : Worker {
|
|
7
|
-
llm default = { provider: "openai", model: "gpt-4o-mini" }
|
|
8
|
-
|
|
9
|
-
on saveUser(args: Json) {
|
|
10
|
-
playbook """
|
|
11
|
-
Save a user to the registry with key "user:${args.id}" and value:
|
|
12
|
-
{
|
|
13
|
-
"name": "${args.name}",
|
|
14
|
-
"age": ${args.age},
|
|
15
|
-
"createdAt": "${Date.now()}"
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
Return: { "success": true, "message": "User saved" }
|
|
19
|
-
"""
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
on getUser(args: Json) {
|
|
23
|
-
playbook """
|
|
24
|
-
Get the user from registry with key "user:${args.id}".
|
|
25
|
-
If found, return: { "found": true, "user": [the complete user object] }
|
|
26
|
-
If not found, return: { "found": false }
|
|
27
|
-
"""
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
run SimpleWorker.saveUser({ id: "test1", name: "TestUser", age: 25 })
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
package "test.typescript.import"
|
|
2
|
-
|
|
3
|
-
// Import TypeScript module
|
|
4
|
-
import "./utils/math-helpers.ts"
|
|
5
|
-
|
|
6
|
-
role Worker { can work }
|
|
7
|
-
|
|
8
|
-
Agent MathAgent : Worker {
|
|
9
|
-
on calculate(args: Json) {
|
|
10
|
-
console.log("=".repeat(60))
|
|
11
|
-
console.log("Testing TypeScript Import")
|
|
12
|
-
console.log("=".repeat(60))
|
|
13
|
-
|
|
14
|
-
// Test simple functions
|
|
15
|
-
const sum = utils_math_helpers.add(5, 3)
|
|
16
|
-
console.log("\nTest 1: add(5, 3) =", sum)
|
|
17
|
-
|
|
18
|
-
const product = utils_math_helpers.multiply(4, 7)
|
|
19
|
-
console.log("Test 2: multiply(4, 7) =", product)
|
|
20
|
-
|
|
21
|
-
const fib10 = utils_math_helpers.fibonacci(10)
|
|
22
|
-
console.log("Test 3: fibonacci(10) =", fib10)
|
|
23
|
-
|
|
24
|
-
const is17Prime = utils_math_helpers.isPrime(17)
|
|
25
|
-
console.log("Test 4: isPrime(17) =", is17Prime)
|
|
26
|
-
|
|
27
|
-
// Test constants
|
|
28
|
-
console.log("\nTest 5: PI =", utils_math_helpers.PI)
|
|
29
|
-
console.log("Test 6: E =", utils_math_helpers.E)
|
|
30
|
-
|
|
31
|
-
// Test class instantiation
|
|
32
|
-
const calc = new utils_math_helpers.Calculator()
|
|
33
|
-
const r1 = calc.add(10, 20)
|
|
34
|
-
const r2 = calc.subtract(50, 15)
|
|
35
|
-
console.log("\nTest 7: Calculator.add(10, 20) =", r1)
|
|
36
|
-
console.log("Test 8: Calculator.subtract(50, 15) =", r2)
|
|
37
|
-
|
|
38
|
-
const history = calc.getHistory()
|
|
39
|
-
console.log("Test 9: Calculator history:", JSON.stringify(history))
|
|
40
|
-
|
|
41
|
-
console.log("\n" + "=".repeat(60))
|
|
42
|
-
console.log("All tests completed!")
|
|
43
|
-
console.log("=".repeat(60))
|
|
44
|
-
|
|
45
|
-
return {
|
|
46
|
-
success: true,
|
|
47
|
-
tests: {
|
|
48
|
-
add: sum,
|
|
49
|
-
multiply: product,
|
|
50
|
-
fibonacci: fib10,
|
|
51
|
-
isPrime: is17Prime,
|
|
52
|
-
pi: utils_math_helpers.PI,
|
|
53
|
-
e: utils_math_helpers.E,
|
|
54
|
-
calculator: {
|
|
55
|
-
add: r1,
|
|
56
|
-
subtract: r2,
|
|
57
|
-
history: history
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
run MathAgent.calculate({})
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
package "test.uses.team"
|
|
2
|
-
|
|
3
|
-
role Worker { can work }
|
|
4
|
-
|
|
5
|
-
Agent TestAgent : Worker {
|
|
6
|
-
on work(args: Json) {
|
|
7
|
-
return { result: "working" }
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
Team TestTeam {
|
|
12
|
-
worker = TestAgent
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
Agent MainAgent : Worker {
|
|
16
|
-
// Esta sintaxis SÍ debe funcionar
|
|
17
|
-
uses Team TestTeam
|
|
18
|
-
|
|
19
|
-
on start(args: Json) {
|
|
20
|
-
const result = await send peers.event("work").role(Worker).any()({}) timeout 5s
|
|
21
|
-
return result
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
run MainAgent.start({})
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
package "test.uses.team"
|
|
2
|
-
|
|
3
|
-
role Worker { can execute }
|
|
4
|
-
role Manager { can manage }
|
|
5
|
-
|
|
6
|
-
Agent SimpleWorker : Worker {
|
|
7
|
-
on doWork(args: Json) {
|
|
8
|
-
playbook """
|
|
9
|
-
Do some work: ${args.task}
|
|
10
|
-
Return JSON: { "result": "work done" }
|
|
11
|
-
"""
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
Team SimpleTeam {
|
|
16
|
-
worker = SimpleWorker
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
Agent TeamUser : Manager {
|
|
20
|
-
uses Team SimpleTeam
|
|
21
|
-
|
|
22
|
-
on requestWork(args: Json) {
|
|
23
|
-
playbook """
|
|
24
|
-
Request work from team: ${args.request}
|
|
25
|
-
Return JSON with actions:
|
|
26
|
-
{ "actions": [{ "intent": "do work", "data": { "task": "${args.request}" } }] }
|
|
27
|
-
"""
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
run TeamUser.requestWork({ request: "process data" })
|