@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
package/examples/sentiment.koi
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
// ============================================================
|
|
2
|
-
// Koi — Sentiment Analysis Skill Demo
|
|
3
|
-
// Skill with agents using playbooks ONLY (LLM execution)
|
|
4
|
-
// ============================================================
|
|
5
|
-
|
|
6
|
-
package "demo.koi.sentiment"
|
|
7
|
-
|
|
8
|
-
role Worker { can execute, can propose }
|
|
9
|
-
role Reviewer { can critique, can approve }
|
|
10
|
-
|
|
11
|
-
Skill SentimentAnalysis {
|
|
12
|
-
affordance """
|
|
13
|
-
Analyzes text sentiment and returns positive/neutral/negative classification.
|
|
14
|
-
Uses 2 agents: Analyst (drafts analysis) + Reviewer (validates and normalizes).
|
|
15
|
-
Both agents use playbooks executed by LLM.
|
|
16
|
-
"""
|
|
17
|
-
|
|
18
|
-
// Agent with ONLY playbook (LLM executes this)
|
|
19
|
-
Agent Analyst : Worker {
|
|
20
|
-
llm default = { provider: "openai", model: "gpt-4o-mini", temperature: 0.3, max_tokens: 300 }
|
|
21
|
-
|
|
22
|
-
on analyze(args: Json) {
|
|
23
|
-
playbook """
|
|
24
|
-
You are a sentiment analysis expert. Analyze the sentiment of the text provided in args.text.
|
|
25
|
-
|
|
26
|
-
Your task:
|
|
27
|
-
1. Determine if the sentiment is positive, neutral, or negative
|
|
28
|
-
2. Assign a confidence score between 0 and 1
|
|
29
|
-
3. Provide a brief rationale (max 100 characters)
|
|
30
|
-
|
|
31
|
-
Return ONLY this exact JSON structure (no markdown, no explanations):
|
|
32
|
-
{
|
|
33
|
-
"label": "positive|neutral|negative",
|
|
34
|
-
"score": 0.85,
|
|
35
|
-
"rationale": "Brief explanation here"
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
Rules:
|
|
39
|
-
- Base your analysis ONLY on the provided text
|
|
40
|
-
- If ambiguous, use "neutral" with score ~0.5
|
|
41
|
-
- Keep rationale under 100 characters
|
|
42
|
-
"""
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Agent with ONLY playbook (LLM executes this)
|
|
47
|
-
Agent Reviewer : Reviewer {
|
|
48
|
-
llm default = { provider: "openai", model: "gpt-4o-mini", temperature: 0.0, max_tokens: 200 }
|
|
49
|
-
|
|
50
|
-
on normalize(args: Json) {
|
|
51
|
-
playbook """
|
|
52
|
-
You are a quality reviewer. Validate and normalize the sentiment analysis draft in args.draft.
|
|
53
|
-
|
|
54
|
-
Your task:
|
|
55
|
-
1. Ensure label is exactly "positive", "neutral", or "negative"
|
|
56
|
-
2. Ensure score is a number between 0 and 1
|
|
57
|
-
3. Ensure rationale is under 100 characters
|
|
58
|
-
4. Fix any issues while preserving the original intent
|
|
59
|
-
|
|
60
|
-
Return ONLY this exact JSON structure (no markdown, no explanations):
|
|
61
|
-
{
|
|
62
|
-
"label": "positive|neutral|negative",
|
|
63
|
-
"score": 0.85,
|
|
64
|
-
"rationale": "Brief explanation here"
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
If the draft is missing fields, fill them conservatively (neutral, score 0.5).
|
|
68
|
-
"""
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
Team Internal {
|
|
73
|
-
analyst = Analyst
|
|
74
|
-
reviewer = Reviewer
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export async function run(input: any): Promise<any> {
|
|
78
|
-
const text = "I absolutely love this product! It works perfectly and exceeded all my expectations."
|
|
79
|
-
|
|
80
|
-
const draft =
|
|
81
|
-
await send Internal.event("analyze").role(Worker).any()({ text: text }) timeout 15s
|
|
82
|
-
|
|
83
|
-
const final =
|
|
84
|
-
await send Internal.event("normalize").role(Reviewer).any()({ draft: draft }) timeout 10s
|
|
85
|
-
|
|
86
|
-
return final
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
run SentimentAnalysis.run({})
|
package/examples/simple.koi
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
// ============================================================
|
|
2
|
-
// Koi — Simple Example
|
|
3
|
-
// Minimal example showing agent communication with procedural code
|
|
4
|
-
// ============================================================
|
|
5
|
-
|
|
6
|
-
package "demo.koi.simple"
|
|
7
|
-
|
|
8
|
-
role Worker { can execute }
|
|
9
|
-
role Lead { can delegate }
|
|
10
|
-
|
|
11
|
-
// Agent with procedural code only (no playbook)
|
|
12
|
-
Agent Greeter : Worker {
|
|
13
|
-
on greet(args: Json) {
|
|
14
|
-
const name = args.name
|
|
15
|
-
return { message: "Hello, " + name + "!" }
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Agent with procedural code only (no playbook)
|
|
20
|
-
Agent Processor : Worker {
|
|
21
|
-
on process(args: Json) {
|
|
22
|
-
const msg = args.message
|
|
23
|
-
const upper = "PROCESSED: " + msg
|
|
24
|
-
return { result: upper }
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
Team SimpleTeam {
|
|
29
|
-
greeter = Greeter
|
|
30
|
-
processor = Processor
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Orchestrator with procedural code
|
|
34
|
-
Agent Orchestrator : Lead {
|
|
35
|
-
uses Team SimpleTeam
|
|
36
|
-
|
|
37
|
-
on start(args: Json) {
|
|
38
|
-
const greeting =
|
|
39
|
-
await send peers.event("greet").role(Worker).any()({ name: "Koi" }) timeout 5s
|
|
40
|
-
|
|
41
|
-
const processed =
|
|
42
|
-
await send peers.event("process").role(Worker).any()({ message: greeting.message }) timeout 5s
|
|
43
|
-
|
|
44
|
-
return processed
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
run Orchestrator.start({})
|
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
// ============================================================
|
|
2
|
-
// Task Chaining Demo
|
|
3
|
-
// Demonstrates automatic output→input chaining between tasks
|
|
4
|
-
// ============================================================
|
|
5
|
-
|
|
6
|
-
package "demo.koi.chaining"
|
|
7
|
-
|
|
8
|
-
role Worker { can execute }
|
|
9
|
-
role Assistant { can help }
|
|
10
|
-
|
|
11
|
-
// ============================================================
|
|
12
|
-
// Specialized Worker Agents
|
|
13
|
-
// ============================================================
|
|
14
|
-
|
|
15
|
-
Agent FrenchTranslator : Worker {
|
|
16
|
-
llm default = { provider: "openai", model: "gpt-4o-mini", temperature: 0.2, max_tokens: 200 }
|
|
17
|
-
|
|
18
|
-
on translate(args: Json) {
|
|
19
|
-
playbook """
|
|
20
|
-
You are a specialized worker agent. Do NOT return actions, only direct results.
|
|
21
|
-
|
|
22
|
-
Translate the following text to French: ${JSON.stringify(args.text)}
|
|
23
|
-
|
|
24
|
-
Return ONLY valid JSON (NO actions field):
|
|
25
|
-
{
|
|
26
|
-
"translated": "text in French",
|
|
27
|
-
"original": "original text",
|
|
28
|
-
"language": "french"
|
|
29
|
-
}
|
|
30
|
-
"""
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
Agent WordCounter : Worker {
|
|
35
|
-
llm default = { provider: "openai", model: "gpt-4o-mini", temperature: 0.1, max_tokens: 200 }
|
|
36
|
-
|
|
37
|
-
on count(args: Json) {
|
|
38
|
-
playbook """
|
|
39
|
-
You are a specialized worker agent. Do NOT return actions, only direct results.
|
|
40
|
-
|
|
41
|
-
Count the number of words in this text: ${JSON.stringify(args.text)}
|
|
42
|
-
|
|
43
|
-
Return ONLY valid JSON (NO actions field):
|
|
44
|
-
{
|
|
45
|
-
"wordCount": <number>,
|
|
46
|
-
"text": "the text that was counted"
|
|
47
|
-
}
|
|
48
|
-
"""
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
Agent TextFormatter : Worker {
|
|
53
|
-
llm default = { provider: "openai", model: "gpt-4o-mini", temperature: 0.1, max_tokens: 200 }
|
|
54
|
-
|
|
55
|
-
on format(args: Json) {
|
|
56
|
-
playbook """
|
|
57
|
-
You are a specialized worker agent. Do NOT return actions, only direct results.
|
|
58
|
-
|
|
59
|
-
Convert this text to uppercase: ${JSON.stringify(args.text)}
|
|
60
|
-
|
|
61
|
-
Return ONLY valid JSON (NO actions field):
|
|
62
|
-
{
|
|
63
|
-
"formatted": "TEXT IN UPPERCASE",
|
|
64
|
-
"original": "original text"
|
|
65
|
-
}
|
|
66
|
-
"""
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
Agent CharacterCounter : Worker {
|
|
71
|
-
llm default = { provider: "openai", model: "gpt-4o-mini", temperature: 0.1, max_tokens: 200 }
|
|
72
|
-
|
|
73
|
-
on countChars(args: Json) {
|
|
74
|
-
playbook """
|
|
75
|
-
You are a specialized worker agent. Do NOT return actions, only direct results.
|
|
76
|
-
|
|
77
|
-
Count the number of characters in this text: ${JSON.stringify(args.text)}
|
|
78
|
-
|
|
79
|
-
Return ONLY valid JSON (NO actions field):
|
|
80
|
-
{
|
|
81
|
-
"charCount": <number>,
|
|
82
|
-
"text": "the text that was counted"
|
|
83
|
-
}
|
|
84
|
-
"""
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
Agent DataValidator : Worker {
|
|
89
|
-
llm default = { provider: "openai", model: "gpt-4o-mini", temperature: 0.1, max_tokens: 200 }
|
|
90
|
-
|
|
91
|
-
on validate(args: Json) {
|
|
92
|
-
playbook """
|
|
93
|
-
You are a specialized worker agent. Do NOT return actions, only direct results.
|
|
94
|
-
|
|
95
|
-
Validate this email: ${JSON.stringify(args.email)}
|
|
96
|
-
|
|
97
|
-
Check if it's a valid email format.
|
|
98
|
-
|
|
99
|
-
Return ONLY valid JSON (NO actions field):
|
|
100
|
-
{
|
|
101
|
-
"valid": true/false,
|
|
102
|
-
"email": "the email",
|
|
103
|
-
"message": "validation message"
|
|
104
|
-
}
|
|
105
|
-
"""
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// ============================================================
|
|
110
|
-
// Regular Assistant - NO special orchestrator knowledge
|
|
111
|
-
// ============================================================
|
|
112
|
-
|
|
113
|
-
Agent TaskAssistant : Assistant {
|
|
114
|
-
llm default = { provider: "openai", model: "gpt-4o-mini", temperature: 0.3, max_tokens: 800 }
|
|
115
|
-
|
|
116
|
-
on helpUser(args: Json) {
|
|
117
|
-
playbook """
|
|
118
|
-
User request: ${args.request}
|
|
119
|
-
|
|
120
|
-
Help accomplish this request. If it requires multiple steps:
|
|
121
|
-
1. Break it down into sequential tasks
|
|
122
|
-
2. Chain outputs: use previous results as inputs for next tasks
|
|
123
|
-
|
|
124
|
-
The system will automatically:
|
|
125
|
-
- Execute each task
|
|
126
|
-
- Pass outputs to next task
|
|
127
|
-
- Route to appropriate team members
|
|
128
|
-
|
|
129
|
-
Return your plan or result as JSON.
|
|
130
|
-
"""
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// ============================================================
|
|
135
|
-
// Team
|
|
136
|
-
// ============================================================
|
|
137
|
-
|
|
138
|
-
Team AssistantTeam {
|
|
139
|
-
taskAssistant = TaskAssistant
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// ============================================================
|
|
143
|
-
// Demo Runner
|
|
144
|
-
// ============================================================
|
|
145
|
-
|
|
146
|
-
Agent DemoRunner : Assistant {
|
|
147
|
-
uses Team AssistantTeam
|
|
148
|
-
|
|
149
|
-
on runDemo(args: Json) {
|
|
150
|
-
console.log("╔════════════════════════════════════════════╗")
|
|
151
|
-
console.log("║ Task Chaining Demo ║")
|
|
152
|
-
console.log("║ Output → Input Automatic Chaining ║")
|
|
153
|
-
console.log("╚════════════════════════════════════════════╝\n")
|
|
154
|
-
|
|
155
|
-
// ============================================================
|
|
156
|
-
// Test 1: Translate → Count Words
|
|
157
|
-
// ============================================================
|
|
158
|
-
console.log("📋 Test 1: Translate to French → Count Words")
|
|
159
|
-
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
|
|
160
|
-
console.log('Request: "Translate Hello world to French and then count the words"\n')
|
|
161
|
-
|
|
162
|
-
const test1 = await send peers.event("helpUser").role(Assistant).any()({
|
|
163
|
-
request: "Translate 'Hello world' to French and then count the words in the translation"
|
|
164
|
-
}) timeout 30s
|
|
165
|
-
|
|
166
|
-
console.log("✅ Result:")
|
|
167
|
-
console.log(JSON.stringify(test1, null, 2))
|
|
168
|
-
console.log("\nExpected flow:")
|
|
169
|
-
console.log(" 1. FrenchTranslator → { translated: 'Bonjour monde' }")
|
|
170
|
-
console.log(" 2. WordCounter(previousResult.translated) → { wordCount: 2 }")
|
|
171
|
-
console.log("\n")
|
|
172
|
-
|
|
173
|
-
// ============================================================
|
|
174
|
-
// Test 2: Format → Count Characters
|
|
175
|
-
// ============================================================
|
|
176
|
-
console.log("📋 Test 2: Format to Uppercase → Count Characters")
|
|
177
|
-
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
|
|
178
|
-
console.log('Request: "Format hello to uppercase and count characters"\n')
|
|
179
|
-
|
|
180
|
-
const test2 = await send peers.event("helpUser").role(Assistant).any()({
|
|
181
|
-
request: "Format the word hello to uppercase and then count the characters"
|
|
182
|
-
}) timeout 30s
|
|
183
|
-
|
|
184
|
-
console.log("✅ Result:")
|
|
185
|
-
console.log(JSON.stringify(test2, null, 2))
|
|
186
|
-
console.log("\nExpected flow:")
|
|
187
|
-
console.log(" 1. TextFormatter → { formatted: 'HELLO' }")
|
|
188
|
-
console.log(" 2. CharacterCounter(previousResult.formatted) → { charCount: 5 }")
|
|
189
|
-
console.log("\n")
|
|
190
|
-
|
|
191
|
-
// ============================================================
|
|
192
|
-
// Test 3: Chain of 3 Tasks
|
|
193
|
-
// ============================================================
|
|
194
|
-
console.log("📋 Test 3: Three-Step Chain")
|
|
195
|
-
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
|
|
196
|
-
console.log('Request: "Validate email, format it, count words"\n')
|
|
197
|
-
|
|
198
|
-
const test3 = await send peers.event("helpUser").role(Assistant).any()({
|
|
199
|
-
request: "Validate the email user@test.com, then format it to uppercase, then count how many words it has"
|
|
200
|
-
}) timeout 30s
|
|
201
|
-
|
|
202
|
-
console.log("✅ Result:")
|
|
203
|
-
console.log(JSON.stringify(test3, null, 2))
|
|
204
|
-
console.log("\nExpected flow:")
|
|
205
|
-
console.log(" 1. DataValidator → { valid: true, email: 'user@test.com' }")
|
|
206
|
-
console.log(" 2. TextFormatter(previousResult.email) → { formatted: 'USER@TEST.COM' }")
|
|
207
|
-
console.log(" 3. WordCounter(previousResult.formatted) → { wordCount: 1 }")
|
|
208
|
-
console.log("\n")
|
|
209
|
-
|
|
210
|
-
// ============================================================
|
|
211
|
-
// Test 4: Complex Original Request
|
|
212
|
-
// ============================================================
|
|
213
|
-
console.log("📋 Test 4: Your Original Example")
|
|
214
|
-
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
|
|
215
|
-
console.log('Request: "Traduce al frances y luego cuenta el numero de palabras"\n')
|
|
216
|
-
|
|
217
|
-
const test4 = await send peers.event("helpUser").role(Assistant).any()({
|
|
218
|
-
request: "Traduce 'artificial intelligence' al frances y luego cuenta el numero de palabras"
|
|
219
|
-
}) timeout 30s
|
|
220
|
-
|
|
221
|
-
console.log("✅ Result:")
|
|
222
|
-
console.log(JSON.stringify(test4, null, 2))
|
|
223
|
-
console.log("\nExpected flow:")
|
|
224
|
-
console.log(" 1. FrenchTranslator → { translated: 'intelligence artificielle' }")
|
|
225
|
-
console.log(" 2. WordCounter(previousResult.translated) → { wordCount: 2 }")
|
|
226
|
-
console.log("\n")
|
|
227
|
-
|
|
228
|
-
console.log("✅ All chaining tests completed!")
|
|
229
|
-
console.log("")
|
|
230
|
-
console.log("🔑 Key Points:")
|
|
231
|
-
console.log(" - LLM creates plan with chained actions")
|
|
232
|
-
console.log(" - Each action references previous results: $-{previousResult.field}")
|
|
233
|
-
console.log(" - Runtime resolves references before executing")
|
|
234
|
-
console.log(" - Output of action N becomes input of action N+1")
|
|
235
|
-
console.log(" - NO manual wiring needed!")
|
|
236
|
-
|
|
237
|
-
return {
|
|
238
|
-
success: true,
|
|
239
|
-
tests_completed: 4
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
run DemoRunner.runDemo({})
|
package/examples/test-await.koi
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
package "test"
|
|
2
|
-
|
|
3
|
-
role Worker { can execute }
|
|
4
|
-
|
|
5
|
-
Agent A : Worker {
|
|
6
|
-
on test(args: Json) {
|
|
7
|
-
const x = 5
|
|
8
|
-
return { x: x }
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
Team T {
|
|
13
|
-
a = A
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
Agent B : Worker {
|
|
17
|
-
uses Team T
|
|
18
|
-
on start(args: Json) {
|
|
19
|
-
const result = await send peers.event("test").role(Worker).any()({}) timeout 2s
|
|
20
|
-
return result
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
package "test.crypto.sha256"
|
|
2
|
-
|
|
3
|
-
// Import crypto-js from npm for SHA256 hashing
|
|
4
|
-
import "crypto-js"
|
|
5
|
-
|
|
6
|
-
role SecurityAgent { can hash, can verify }
|
|
7
|
-
|
|
8
|
-
Agent HashAgent : SecurityAgent {
|
|
9
|
-
on hashPassword(args: Json) {
|
|
10
|
-
console.log("=".repeat(60))
|
|
11
|
-
console.log("Crypto SHA256 Test - Password Hashing")
|
|
12
|
-
console.log("=".repeat(60))
|
|
13
|
-
|
|
14
|
-
const password = args.password
|
|
15
|
-
console.log("\nOriginal password:", password)
|
|
16
|
-
|
|
17
|
-
// Hash with SHA256 (using chained method syntax)
|
|
18
|
-
const hash = crypto_js.SHA256(password).toString()
|
|
19
|
-
console.log("SHA256 hash:", hash)
|
|
20
|
-
|
|
21
|
-
// Hash with SHA512 for comparison
|
|
22
|
-
const hash512 = crypto_js.SHA512(password).toString()
|
|
23
|
-
console.log("SHA512 hash:", hash512)
|
|
24
|
-
|
|
25
|
-
// Hash with MD5 (less secure, for demonstration)
|
|
26
|
-
const hashMD5 = crypto_js.MD5(password).toString()
|
|
27
|
-
console.log("MD5 hash:", hashMD5)
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
password: password,
|
|
31
|
-
sha256: hash,
|
|
32
|
-
sha512: hash512,
|
|
33
|
-
md5: hashMD5
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
on verifyHash(args: Json) {
|
|
38
|
-
console.log("\n" + "=".repeat(60))
|
|
39
|
-
console.log("Hash Verification Test")
|
|
40
|
-
console.log("=".repeat(60))
|
|
41
|
-
|
|
42
|
-
const input = args.input
|
|
43
|
-
const expectedHash = args.expectedHash
|
|
44
|
-
|
|
45
|
-
console.log("\nInput:", input)
|
|
46
|
-
console.log("Expected hash:", expectedHash)
|
|
47
|
-
|
|
48
|
-
// Calculate hash (using chained method syntax)
|
|
49
|
-
const calculatedHash = crypto_js.SHA256(input).toString()
|
|
50
|
-
console.log("Calculated hash:", calculatedHash)
|
|
51
|
-
|
|
52
|
-
// Verify
|
|
53
|
-
const isValid = calculatedHash == expectedHash
|
|
54
|
-
console.log("Hash matches:", isValid)
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
input: input,
|
|
58
|
-
expectedHash: expectedHash,
|
|
59
|
-
calculatedHash: calculatedHash,
|
|
60
|
-
isValid: isValid
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
on hashData(args: Json) {
|
|
65
|
-
console.log("\n" + "=".repeat(60))
|
|
66
|
-
console.log("Data Integrity Test - JSON Hashing")
|
|
67
|
-
console.log("=".repeat(60))
|
|
68
|
-
|
|
69
|
-
const data = args.data
|
|
70
|
-
console.log("\nOriginal data:", JSON.stringify(data))
|
|
71
|
-
|
|
72
|
-
// Convert to JSON string and hash (using chained method syntax)
|
|
73
|
-
const dataString = JSON.stringify(data)
|
|
74
|
-
const hash = crypto_js.SHA256(dataString).toString()
|
|
75
|
-
console.log("SHA256 hash:", hash)
|
|
76
|
-
|
|
77
|
-
// Simulate data tampering
|
|
78
|
-
const tamperedData = { name: data.name, age: 99, email: data.email }
|
|
79
|
-
const tamperedString = JSON.stringify(tamperedData)
|
|
80
|
-
const tamperedHash = crypto_js.SHA256(tamperedString).toString()
|
|
81
|
-
console.log("\nTampered data:", JSON.stringify(tamperedData))
|
|
82
|
-
console.log("Tampered hash:", tamperedHash)
|
|
83
|
-
console.log("Hashes match:", hash == tamperedHash)
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
original: {
|
|
87
|
-
data: data,
|
|
88
|
-
hash: hash
|
|
89
|
-
},
|
|
90
|
-
tampered: {
|
|
91
|
-
data: tamperedData,
|
|
92
|
-
hash: tamperedHash
|
|
93
|
-
},
|
|
94
|
-
isCompromised: hash != tamperedHash
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
on compareAlgorithms(args: Json) {
|
|
99
|
-
console.log("\n" + "=".repeat(60))
|
|
100
|
-
console.log("Algorithm Comparison Test")
|
|
101
|
-
console.log("=".repeat(60))
|
|
102
|
-
|
|
103
|
-
const text = args.text
|
|
104
|
-
console.log("\nText to hash:", text)
|
|
105
|
-
|
|
106
|
-
// Hash with different algorithms (using chained method syntax)
|
|
107
|
-
const md5 = crypto_js.MD5(text).toString()
|
|
108
|
-
const sha1 = crypto_js.SHA1(text).toString()
|
|
109
|
-
const sha256 = crypto_js.SHA256(text).toString()
|
|
110
|
-
const sha512 = crypto_js.SHA512(text).toString()
|
|
111
|
-
const sha3 = crypto_js.SHA3(text).toString()
|
|
112
|
-
|
|
113
|
-
console.log("\nMD5 (32 chars):", md5)
|
|
114
|
-
console.log("SHA1 (40 chars):", sha1)
|
|
115
|
-
console.log("SHA256 (64 chars):", sha256)
|
|
116
|
-
console.log("SHA512 (128 chars):", sha512)
|
|
117
|
-
console.log("SHA3 (64 chars):", sha3)
|
|
118
|
-
|
|
119
|
-
console.log("\nHash lengths:")
|
|
120
|
-
console.log(" MD5:", md5.length, "characters")
|
|
121
|
-
console.log(" SHA1:", sha1.length, "characters")
|
|
122
|
-
console.log(" SHA256:", sha256.length, "characters")
|
|
123
|
-
console.log(" SHA512:", sha512.length, "characters")
|
|
124
|
-
console.log(" SHA3:", sha3.length, "characters")
|
|
125
|
-
|
|
126
|
-
return {
|
|
127
|
-
text: text,
|
|
128
|
-
hashes: {
|
|
129
|
-
md5: md5,
|
|
130
|
-
sha1: sha1,
|
|
131
|
-
sha256: sha256,
|
|
132
|
-
sha512: sha512,
|
|
133
|
-
sha3: sha3
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
Team HashTeam {
|
|
140
|
-
hasher = HashAgent
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
Agent Coordinator : SecurityAgent {
|
|
144
|
-
uses Team HashTeam
|
|
145
|
-
|
|
146
|
-
on runTests(args: Json) {
|
|
147
|
-
console.log("\n" + "█".repeat(60))
|
|
148
|
-
console.log("█" + " ".repeat(58) + "█")
|
|
149
|
-
console.log("█" + " Crypto-JS SHA256 Integration Test Suite".padEnd(58) + "█")
|
|
150
|
-
console.log("█" + " ".repeat(58) + "█")
|
|
151
|
-
console.log("█".repeat(60))
|
|
152
|
-
|
|
153
|
-
// Test 1: Hash password
|
|
154
|
-
const result1 = await send peers.event("hashPassword").role(SecurityAgent).any()({
|
|
155
|
-
password: "MySecurePassword123!"
|
|
156
|
-
}) timeout 10s
|
|
157
|
-
|
|
158
|
-
// Test 2: Verify hash
|
|
159
|
-
const result2 = await send peers.event("verifyHash").role(SecurityAgent).any()({
|
|
160
|
-
input: "MySecurePassword123!",
|
|
161
|
-
expectedHash: result1.sha256
|
|
162
|
-
}) timeout 10s
|
|
163
|
-
|
|
164
|
-
// Test 3: Hash structured data
|
|
165
|
-
const result3 = await send peers.event("hashData").role(SecurityAgent).any()({
|
|
166
|
-
data: {
|
|
167
|
-
name: "Alice",
|
|
168
|
-
age: 30,
|
|
169
|
-
email: "alice@example.com"
|
|
170
|
-
}
|
|
171
|
-
}) timeout 10s
|
|
172
|
-
|
|
173
|
-
// Test 4: Compare algorithms
|
|
174
|
-
const result4 = await send peers.event("compareAlgorithms").role(SecurityAgent).any()({
|
|
175
|
-
text: "The quick brown fox jumps over the lazy dog"
|
|
176
|
-
}) timeout 10s
|
|
177
|
-
|
|
178
|
-
console.log("\n" + "█".repeat(60))
|
|
179
|
-
console.log("█" + " ".repeat(58) + "█")
|
|
180
|
-
console.log("█" + " All Crypto Tests Completed Successfully!".padEnd(58) + "█")
|
|
181
|
-
console.log("█" + " ".repeat(58) + "█")
|
|
182
|
-
console.log("█".repeat(60))
|
|
183
|
-
|
|
184
|
-
return {
|
|
185
|
-
success: true,
|
|
186
|
-
tests: {
|
|
187
|
-
passwordHashing: result1,
|
|
188
|
-
hashVerification: result2,
|
|
189
|
-
dataIntegrity: result3,
|
|
190
|
-
algorithmComparison: result4
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
run Coordinator.runTests({})
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// Test delegation with explicit data passing
|
|
2
|
-
package "test.delegation"
|
|
3
|
-
|
|
4
|
-
role Worker { can execute }
|
|
5
|
-
|
|
6
|
-
// Specialist that saves users
|
|
7
|
-
Agent Saver : Worker {
|
|
8
|
-
llm default = { provider: "openai", model: "gpt-4o-mini" }
|
|
9
|
-
|
|
10
|
-
on saveUser(args: Json) {
|
|
11
|
-
playbook """
|
|
12
|
-
Save a user to registry with key "user:${args.id}".
|
|
13
|
-
User data: name="${args.name}", age=${args.age}
|
|
14
|
-
|
|
15
|
-
Return: { "saved": true, "id": "${args.id}", "name": "${args.name}" }
|
|
16
|
-
"""
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Team containing the saver
|
|
21
|
-
Team SaverTeam {
|
|
22
|
-
saver = Saver
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Orchestrator that delegates
|
|
26
|
-
Agent Orchestrator : Worker {
|
|
27
|
-
llm default = { provider: "openai", model: "gpt-4o-mini" }
|
|
28
|
-
uses Team SaverTeam
|
|
29
|
-
|
|
30
|
-
on start(args: Json) {
|
|
31
|
-
playbook """
|
|
32
|
-
Delegate the task of saving a user named "TestUser" with ID "123" and age 25.
|
|
33
|
-
|
|
34
|
-
CRITICAL: Pass data: { "id": "123", "name": "TestUser", "age": 25 }
|
|
35
|
-
|
|
36
|
-
Return the result from the delegation.
|
|
37
|
-
"""
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
run Orchestrator.start({})
|