@koi-language/koi 1.0.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/QUICKSTART.md +89 -0
- package/README.md +545 -0
- package/examples/actions-demo.koi +177 -0
- package/examples/cache-test.koi +29 -0
- package/examples/calculator.koi +61 -0
- package/examples/clear-registry.js +33 -0
- package/examples/clear-registry.koi +30 -0
- package/examples/code-introspection-test.koi +149 -0
- package/examples/counter.koi +132 -0
- package/examples/delegation-test.koi +52 -0
- package/examples/directory-import-test.koi +84 -0
- package/examples/hello-world-claude.koi +52 -0
- package/examples/hello-world.koi +52 -0
- package/examples/hello.koi +24 -0
- package/examples/mcp-example.koi +70 -0
- package/examples/multi-event-handler-test.koi +144 -0
- package/examples/new-import-test.koi +89 -0
- package/examples/pipeline.koi +162 -0
- package/examples/registry-demo.koi +184 -0
- package/examples/registry-playbook-demo.koi +162 -0
- package/examples/registry-playbook-email-compositor-2.koi +140 -0
- package/examples/registry-playbook-email-compositor.koi +140 -0
- package/examples/sentiment.koi +90 -0
- package/examples/simple.koi +48 -0
- package/examples/skill-import-test.koi +76 -0
- package/examples/skills/advanced/index.koi +95 -0
- package/examples/skills/math-operations.koi +69 -0
- package/examples/skills/string-operations.koi +56 -0
- package/examples/task-chaining-demo.koi +244 -0
- package/examples/test-await.koi +22 -0
- package/examples/test-crypto-sha256.koi +196 -0
- package/examples/test-delegation.koi +41 -0
- package/examples/test-multi-team-routing.koi +258 -0
- package/examples/test-no-handler.koi +35 -0
- package/examples/test-npm-import.koi +67 -0
- package/examples/test-parse.koi +10 -0
- package/examples/test-peers-with-team.koi +59 -0
- package/examples/test-permissions-fail.koi +20 -0
- package/examples/test-permissions.koi +36 -0
- package/examples/test-simple-registry.koi +31 -0
- package/examples/test-typescript-import.koi +64 -0
- package/examples/test-uses-team-syntax.koi +25 -0
- package/examples/test-uses-team.koi +31 -0
- package/examples/utils/calculator.test.ts +144 -0
- package/examples/utils/calculator.ts +56 -0
- package/examples/utils/math-helpers.js +50 -0
- package/examples/utils/math-helpers.ts +55 -0
- package/examples/web-delegation-demo.koi +165 -0
- package/package.json +78 -0
- package/src/cli/koi.js +793 -0
- package/src/compiler/build-optimizer.js +447 -0
- package/src/compiler/cache-manager.js +274 -0
- package/src/compiler/import-resolver.js +369 -0
- package/src/compiler/parser.js +7542 -0
- package/src/compiler/transpiler.js +1105 -0
- package/src/compiler/typescript-transpiler.js +148 -0
- package/src/grammar/koi.pegjs +767 -0
- package/src/runtime/action-registry.js +172 -0
- package/src/runtime/actions/call-skill.js +45 -0
- package/src/runtime/actions/format.js +115 -0
- package/src/runtime/actions/print.js +42 -0
- package/src/runtime/actions/registry-delete.js +37 -0
- package/src/runtime/actions/registry-get.js +37 -0
- package/src/runtime/actions/registry-keys.js +33 -0
- package/src/runtime/actions/registry-search.js +34 -0
- package/src/runtime/actions/registry-set.js +50 -0
- package/src/runtime/actions/return.js +31 -0
- package/src/runtime/actions/send-message.js +58 -0
- package/src/runtime/actions/update-state.js +36 -0
- package/src/runtime/agent.js +1368 -0
- package/src/runtime/cli-logger.js +205 -0
- package/src/runtime/incremental-json-parser.js +201 -0
- package/src/runtime/index.js +33 -0
- package/src/runtime/llm-provider.js +1372 -0
- package/src/runtime/mcp-client.js +1171 -0
- package/src/runtime/planner.js +273 -0
- package/src/runtime/registry-backends/keyv-sqlite.js +215 -0
- package/src/runtime/registry-backends/local.js +260 -0
- package/src/runtime/registry.js +162 -0
- package/src/runtime/role.js +14 -0
- package/src/runtime/router.js +395 -0
- package/src/runtime/runtime.js +113 -0
- package/src/runtime/skill-selector.js +173 -0
- package/src/runtime/skill.js +25 -0
- package/src/runtime/team.js +162 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Transpile TypeScript files to JavaScript
|
|
7
|
+
*/
|
|
8
|
+
export class TypeScriptTranspiler {
|
|
9
|
+
constructor() {
|
|
10
|
+
// Default TypeScript compiler options
|
|
11
|
+
this.compilerOptions = {
|
|
12
|
+
target: ts.ScriptTarget.ES2020,
|
|
13
|
+
module: ts.ModuleKind.ES2020,
|
|
14
|
+
moduleResolution: ts.ModuleResolutionKind.NodeNext,
|
|
15
|
+
esModuleInterop: true,
|
|
16
|
+
allowSyntheticDefaultImports: true,
|
|
17
|
+
skipLibCheck: true,
|
|
18
|
+
forceConsistentCasingInFileNames: true,
|
|
19
|
+
resolveJsonModule: true,
|
|
20
|
+
isolatedModules: true,
|
|
21
|
+
declaration: false,
|
|
22
|
+
sourceMap: false,
|
|
23
|
+
inlineSourceMap: false,
|
|
24
|
+
inlineSources: false,
|
|
25
|
+
removeComments: false,
|
|
26
|
+
preserveConstEnums: true,
|
|
27
|
+
strict: false,
|
|
28
|
+
noImplicitAny: false
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Transpile a TypeScript file to JavaScript
|
|
34
|
+
* @param {string} tsFilePath - Path to the TypeScript file
|
|
35
|
+
* @param {string} outputPath - Optional output path (defaults to same directory with .js extension)
|
|
36
|
+
* @returns {string} - Path to the generated JavaScript file
|
|
37
|
+
*/
|
|
38
|
+
transpile(tsFilePath, outputPath = null) {
|
|
39
|
+
// Read TypeScript source
|
|
40
|
+
const tsSource = fs.readFileSync(tsFilePath, 'utf-8');
|
|
41
|
+
|
|
42
|
+
// Determine output path
|
|
43
|
+
if (!outputPath) {
|
|
44
|
+
outputPath = tsFilePath.replace(/\.tsx?$/, '.js');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Check if JS file exists and is newer than TS file
|
|
48
|
+
if (fs.existsSync(outputPath)) {
|
|
49
|
+
const tsStats = fs.statSync(tsFilePath);
|
|
50
|
+
const jsStats = fs.statSync(outputPath);
|
|
51
|
+
if (jsStats.mtime > tsStats.mtime) {
|
|
52
|
+
// JS file is up to date
|
|
53
|
+
return outputPath;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Transpile TypeScript to JavaScript
|
|
58
|
+
const result = ts.transpileModule(tsSource, {
|
|
59
|
+
compilerOptions: this.compilerOptions,
|
|
60
|
+
fileName: path.basename(tsFilePath)
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Write output
|
|
64
|
+
fs.writeFileSync(outputPath, result.outputText);
|
|
65
|
+
|
|
66
|
+
return outputPath;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Transpile multiple TypeScript files
|
|
71
|
+
* @param {string[]} tsFilePaths - Array of TypeScript file paths
|
|
72
|
+
* @returns {Map<string, string>} - Map of original path to transpiled path
|
|
73
|
+
*/
|
|
74
|
+
transpileMultiple(tsFilePaths) {
|
|
75
|
+
const resultMap = new Map();
|
|
76
|
+
|
|
77
|
+
for (const tsPath of tsFilePaths) {
|
|
78
|
+
try {
|
|
79
|
+
const jsPath = this.transpile(tsPath);
|
|
80
|
+
resultMap.set(tsPath, jsPath);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.warn(`⚠️ Failed to transpile ${tsPath}: ${error.message}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return resultMap;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Load TypeScript config from tsconfig.json if available
|
|
91
|
+
* @param {string} projectDir - Project directory to search for tsconfig.json
|
|
92
|
+
*/
|
|
93
|
+
loadTsConfig(projectDir) {
|
|
94
|
+
const tsconfigPath = this.findTsConfig(projectDir);
|
|
95
|
+
|
|
96
|
+
if (tsconfigPath) {
|
|
97
|
+
try {
|
|
98
|
+
const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
|
|
99
|
+
if (configFile.error) {
|
|
100
|
+
console.warn(`⚠️ Error reading tsconfig.json: ${configFile.error.messageText}`);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const parsedConfig = ts.parseJsonConfigFileContent(
|
|
105
|
+
configFile.config,
|
|
106
|
+
ts.sys,
|
|
107
|
+
path.dirname(tsconfigPath)
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
if (parsedConfig.errors.length > 0) {
|
|
111
|
+
console.warn(`⚠️ Error parsing tsconfig.json:`, parsedConfig.errors[0].messageText);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Merge with default options
|
|
116
|
+
this.compilerOptions = {
|
|
117
|
+
...this.compilerOptions,
|
|
118
|
+
...parsedConfig.options
|
|
119
|
+
};
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.warn(`⚠️ Failed to load tsconfig.json: ${error.message}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Find tsconfig.json by walking up directory tree
|
|
128
|
+
*/
|
|
129
|
+
findTsConfig(startDir) {
|
|
130
|
+
let currentDir = startDir;
|
|
131
|
+
|
|
132
|
+
while (true) {
|
|
133
|
+
const tsconfigPath = path.join(currentDir, 'tsconfig.json');
|
|
134
|
+
if (fs.existsSync(tsconfigPath)) {
|
|
135
|
+
return tsconfigPath;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const parentDir = path.dirname(currentDir);
|
|
139
|
+
if (parentDir === currentDir) {
|
|
140
|
+
// Reached root
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
currentDir = parentDir;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
}
|