@orcalang/orca-lang 0.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/LICENSE +176 -0
- package/README.md +128 -0
- package/dist/auth/index.d.ts +6 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +6 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/lock.d.ts +2 -0
- package/dist/auth/lock.d.ts.map +1 -0
- package/dist/auth/lock.js +59 -0
- package/dist/auth/lock.js.map +1 -0
- package/dist/auth/providers/anthropic.d.ts +14 -0
- package/dist/auth/providers/anthropic.d.ts.map +1 -0
- package/dist/auth/providers/anthropic.js +145 -0
- package/dist/auth/providers/anthropic.js.map +1 -0
- package/dist/auth/providers/index.d.ts +3 -0
- package/dist/auth/providers/index.d.ts.map +1 -0
- package/dist/auth/providers/index.js +3 -0
- package/dist/auth/providers/index.js.map +1 -0
- package/dist/auth/providers/minimax.d.ts +6 -0
- package/dist/auth/providers/minimax.d.ts.map +1 -0
- package/dist/auth/providers/minimax.js +65 -0
- package/dist/auth/providers/minimax.js.map +1 -0
- package/dist/auth/refresh.d.ts +8 -0
- package/dist/auth/refresh.d.ts.map +1 -0
- package/dist/auth/refresh.js +104 -0
- package/dist/auth/refresh.js.map +1 -0
- package/dist/auth/store.d.ts +11 -0
- package/dist/auth/store.d.ts.map +1 -0
- package/dist/auth/store.js +63 -0
- package/dist/auth/store.js.map +1 -0
- package/dist/auth/types.d.ts +51 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +2 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/compiler/mermaid.d.ts +3 -0
- package/dist/compiler/mermaid.d.ts.map +1 -0
- package/dist/compiler/mermaid.js +86 -0
- package/dist/compiler/mermaid.js.map +1 -0
- package/dist/compiler/xstate.d.ts +15 -0
- package/dist/compiler/xstate.d.ts.map +1 -0
- package/dist/compiler/xstate.js +542 -0
- package/dist/compiler/xstate.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +3 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/loader.d.ts +4 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +109 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/types.d.ts +13 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +8 -0
- package/dist/config/types.js.map +1 -0
- package/dist/generators/index.d.ts +5 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators/index.js +5 -0
- package/dist/generators/index.js.map +1 -0
- package/dist/generators/registry.d.ts +12 -0
- package/dist/generators/registry.d.ts.map +1 -0
- package/dist/generators/registry.js +15 -0
- package/dist/generators/registry.js.map +1 -0
- package/dist/generators/typescript.d.ts +9 -0
- package/dist/generators/typescript.d.ts.map +1 -0
- package/dist/generators/typescript.js +55 -0
- package/dist/generators/typescript.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +630 -0
- package/dist/index.js.map +1 -0
- package/dist/llm/anthropic.d.ts +14 -0
- package/dist/llm/anthropic.d.ts.map +1 -0
- package/dist/llm/anthropic.js +87 -0
- package/dist/llm/anthropic.js.map +1 -0
- package/dist/llm/grok.d.ts +13 -0
- package/dist/llm/grok.d.ts.map +1 -0
- package/dist/llm/grok.js +60 -0
- package/dist/llm/grok.js.map +1 -0
- package/dist/llm/index.d.ts +11 -0
- package/dist/llm/index.d.ts.map +1 -0
- package/dist/llm/index.js +23 -0
- package/dist/llm/index.js.map +1 -0
- package/dist/llm/ollama.d.ts +11 -0
- package/dist/llm/ollama.d.ts.map +1 -0
- package/dist/llm/ollama.js +51 -0
- package/dist/llm/ollama.js.map +1 -0
- package/dist/llm/openai.d.ts +13 -0
- package/dist/llm/openai.d.ts.map +1 -0
- package/dist/llm/openai.js +61 -0
- package/dist/llm/openai.js.map +1 -0
- package/dist/llm/provider.d.ts +32 -0
- package/dist/llm/provider.d.ts.map +1 -0
- package/dist/llm/provider.js +2 -0
- package/dist/llm/provider.js.map +1 -0
- package/dist/parser/ast-to-markdown.d.ts +3 -0
- package/dist/parser/ast-to-markdown.d.ts.map +1 -0
- package/dist/parser/ast-to-markdown.js +209 -0
- package/dist/parser/ast-to-markdown.js.map +1 -0
- package/dist/parser/ast.d.ts +183 -0
- package/dist/parser/ast.d.ts.map +1 -0
- package/dist/parser/ast.js +3 -0
- package/dist/parser/ast.js.map +1 -0
- package/dist/parser/markdown-parser.d.ts +8 -0
- package/dist/parser/markdown-parser.d.ts.map +1 -0
- package/dist/parser/markdown-parser.js +838 -0
- package/dist/parser/markdown-parser.js.map +1 -0
- package/dist/runtime/effects.d.ts +17 -0
- package/dist/runtime/effects.d.ts.map +1 -0
- package/dist/runtime/effects.js +28 -0
- package/dist/runtime/effects.js.map +1 -0
- package/dist/runtime/machine.d.ts +8 -0
- package/dist/runtime/machine.d.ts.map +1 -0
- package/dist/runtime/machine.js +158 -0
- package/dist/runtime/machine.js.map +1 -0
- package/dist/runtime/types.d.ts +37 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime/types.js +3 -0
- package/dist/runtime/types.js.map +1 -0
- package/dist/skills.d.ts +114 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +1103 -0
- package/dist/skills.js.map +1 -0
- package/dist/tools.d.ts +18 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +124 -0
- package/dist/tools.js.map +1 -0
- package/dist/verifier/completeness.d.ts +4 -0
- package/dist/verifier/completeness.d.ts.map +1 -0
- package/dist/verifier/completeness.js +82 -0
- package/dist/verifier/completeness.js.map +1 -0
- package/dist/verifier/determinism.d.ts +17 -0
- package/dist/verifier/determinism.d.ts.map +1 -0
- package/dist/verifier/determinism.js +301 -0
- package/dist/verifier/determinism.js.map +1 -0
- package/dist/verifier/properties.d.ts +6 -0
- package/dist/verifier/properties.d.ts.map +1 -0
- package/dist/verifier/properties.js +404 -0
- package/dist/verifier/properties.js.map +1 -0
- package/dist/verifier/structural.d.ts +50 -0
- package/dist/verifier/structural.d.ts.map +1 -0
- package/dist/verifier/structural.js +692 -0
- package/dist/verifier/structural.js.map +1 -0
- package/dist/verifier/types.d.ts +40 -0
- package/dist/verifier/types.d.ts.map +1 -0
- package/dist/verifier/types.js +2 -0
- package/dist/verifier/types.js.map +1 -0
- package/package.json +49 -0
- package/src/auth/index.ts +5 -0
- package/src/auth/lock.ts +71 -0
- package/src/auth/providers/anthropic.ts +192 -0
- package/src/auth/providers/index.ts +17 -0
- package/src/auth/providers/minimax.ts +100 -0
- package/src/auth/refresh.ts +138 -0
- package/src/auth/store.ts +75 -0
- package/src/auth/types.ts +62 -0
- package/src/compiler/mermaid.ts +109 -0
- package/src/compiler/xstate.ts +615 -0
- package/src/config/index.ts +2 -0
- package/src/config/loader.ts +122 -0
- package/src/config/types.ts +21 -0
- package/src/generators/index.ts +6 -0
- package/src/generators/registry.ts +27 -0
- package/src/generators/typescript.ts +67 -0
- package/src/index.ts +671 -0
- package/src/llm/anthropic.ts +102 -0
- package/src/llm/grok.ts +73 -0
- package/src/llm/index.ts +29 -0
- package/src/llm/ollama.ts +62 -0
- package/src/llm/openai.ts +74 -0
- package/src/llm/provider.ts +35 -0
- package/src/parser/ast-to-markdown.ts +220 -0
- package/src/parser/ast.ts +236 -0
- package/src/parser/markdown-parser.ts +844 -0
- package/src/runtime/effects.ts +48 -0
- package/src/runtime/machine.ts +201 -0
- package/src/runtime/types.ts +44 -0
- package/src/skills.ts +1339 -0
- package/src/tools.ts +144 -0
- package/src/verifier/completeness.ts +89 -0
- package/src/verifier/determinism.ts +328 -0
- package/src/verifier/properties.ts +507 -0
- package/src/verifier/structural.ts +803 -0
- package/src/verifier/types.ts +45 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from 'fs';
|
|
2
|
+
import { join, dirname } from 'path';
|
|
3
|
+
import { homedir } from 'os';
|
|
4
|
+
import yaml from 'js-yaml';
|
|
5
|
+
import { OrcaConfig, DEFAULT_CONFIG } from './types.js';
|
|
6
|
+
|
|
7
|
+
let envLoaded = false;
|
|
8
|
+
|
|
9
|
+
function loadEnvFile(): void {
|
|
10
|
+
if (envLoaded) return;
|
|
11
|
+
envLoaded = true;
|
|
12
|
+
|
|
13
|
+
// Load from project root .env
|
|
14
|
+
const cwd = process.cwd();
|
|
15
|
+
const envPath = join(cwd, '.env');
|
|
16
|
+
if (existsSync(envPath)) {
|
|
17
|
+
const content = readFileSync(envPath, 'utf-8');
|
|
18
|
+
for (const line of content.split('\n')) {
|
|
19
|
+
const trimmed = line.trim();
|
|
20
|
+
if (!trimmed || trimmed.startsWith('#')) continue;
|
|
21
|
+
const eqIndex = trimmed.indexOf('=');
|
|
22
|
+
if (eqIndex === -1) continue;
|
|
23
|
+
const key = trimmed.slice(0, eqIndex).trim();
|
|
24
|
+
let value = trimmed.slice(eqIndex + 1).trim();
|
|
25
|
+
// Remove surrounding quotes
|
|
26
|
+
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
27
|
+
(value.startsWith("'") && value.endsWith("'"))) {
|
|
28
|
+
value = value.slice(1, -1);
|
|
29
|
+
}
|
|
30
|
+
if (key && !process.env[key]) {
|
|
31
|
+
process.env[key] = value;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function interpolateEnvVars(obj: unknown): unknown {
|
|
38
|
+
if (typeof obj === 'string') {
|
|
39
|
+
// Replace ${VAR_NAME} with environment variable value
|
|
40
|
+
return obj.replace(/\$\{([^}]+)\}/g, (_, varName) => {
|
|
41
|
+
const value = process.env[varName];
|
|
42
|
+
if (value === undefined) {
|
|
43
|
+
throw new Error(`Environment variable ${varName} is not set`);
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (Array.isArray(obj)) {
|
|
49
|
+
return obj.map(interpolateEnvVars);
|
|
50
|
+
}
|
|
51
|
+
if (obj !== null && typeof obj === 'object') {
|
|
52
|
+
const result: Record<string, unknown> = {};
|
|
53
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
54
|
+
result[key] = interpolateEnvVars(value);
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
return obj;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function deepMerge(target: OrcaConfig, source: Partial<OrcaConfig>): OrcaConfig {
|
|
62
|
+
const result = { ...target };
|
|
63
|
+
for (const [key, value] of Object.entries(source)) {
|
|
64
|
+
if (value !== undefined && value !== null) {
|
|
65
|
+
(result as Record<string, unknown>)[key] = value;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function loadConfig(configPath?: string): OrcaConfig {
|
|
72
|
+
loadEnvFile();
|
|
73
|
+
const configs: Partial<OrcaConfig>[] = [];
|
|
74
|
+
|
|
75
|
+
// 1. Global default
|
|
76
|
+
const globalConfigPath = join(homedir(), '.orca', 'default.yaml');
|
|
77
|
+
if (existsSync(globalConfigPath)) {
|
|
78
|
+
const content = readFileSync(globalConfigPath, 'utf-8');
|
|
79
|
+
const parsed = yaml.load(content) as Record<string, unknown>;
|
|
80
|
+
configs.push(interpolateEnvVars(parsed) as Partial<OrcaConfig>);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 2. Project config (current working directory or specified path)
|
|
84
|
+
const projectConfigPath = configPath || findProjectConfig();
|
|
85
|
+
if (projectConfigPath && existsSync(projectConfigPath)) {
|
|
86
|
+
const content = readFileSync(projectConfigPath, 'utf-8');
|
|
87
|
+
const parsed = yaml.load(content) as Record<string, unknown>;
|
|
88
|
+
configs.push(interpolateEnvVars(parsed) as Partial<OrcaConfig>);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// 3. Merge all configs in order (later ones override earlier)
|
|
92
|
+
let result = DEFAULT_CONFIG;
|
|
93
|
+
for (const config of configs) {
|
|
94
|
+
result = deepMerge(result, config);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function findProjectConfig(): string | undefined {
|
|
101
|
+
const cwd = process.cwd();
|
|
102
|
+
const possiblePaths = [
|
|
103
|
+
join(cwd, 'orca.yaml'),
|
|
104
|
+
join(cwd, '.orca.yaml'),
|
|
105
|
+
join(cwd, 'orca', 'orca.yaml'),
|
|
106
|
+
];
|
|
107
|
+
|
|
108
|
+
for (const path of possiblePaths) {
|
|
109
|
+
if (existsSync(path)) {
|
|
110
|
+
return path;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function resolveConfigOverrides(
|
|
118
|
+
config: OrcaConfig,
|
|
119
|
+
overrides: Partial<OrcaConfig>
|
|
120
|
+
): OrcaConfig {
|
|
121
|
+
return deepMerge(config, overrides);
|
|
122
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type LLMProviderType = 'anthropic' | 'openai' | 'ollama' | 'grok';
|
|
2
|
+
|
|
3
|
+
export type CodeGeneratorType = 'typescript' | 'python' | 'rust' | 'go';
|
|
4
|
+
|
|
5
|
+
export interface OrcaConfig {
|
|
6
|
+
provider: LLMProviderType;
|
|
7
|
+
model: string;
|
|
8
|
+
api_key?: string;
|
|
9
|
+
base_url?: string;
|
|
10
|
+
code_generator: CodeGeneratorType;
|
|
11
|
+
max_tokens?: number;
|
|
12
|
+
temperature?: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const DEFAULT_CONFIG: OrcaConfig = {
|
|
16
|
+
provider: 'anthropic',
|
|
17
|
+
model: 'claude-sonnet-4-6',
|
|
18
|
+
code_generator: 'typescript',
|
|
19
|
+
max_tokens: 4096,
|
|
20
|
+
temperature: 0.7,
|
|
21
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { CodeGenerator } from './registry.js';
|
|
2
|
+
export { registerCodeGenerator, getCodeGenerator, listCodeGenerators } from './registry.js';
|
|
3
|
+
export { TypeScriptCodeGenerator } from './typescript.js';
|
|
4
|
+
|
|
5
|
+
// Import to register generators
|
|
6
|
+
import './typescript.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ActionScaffold } from '../skills.js';
|
|
2
|
+
import { MachineDef } from '../parser/ast.js';
|
|
3
|
+
import { CodeGeneratorType } from '../config/types.js';
|
|
4
|
+
|
|
5
|
+
export interface CodeGenerator {
|
|
6
|
+
name(): string;
|
|
7
|
+
generate(actions: ActionScaffold[], machine: MachineDef): string;
|
|
8
|
+
generateAction(action: ActionScaffold, machine: MachineDef): string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const generators = new Map<CodeGeneratorType, () => CodeGenerator>();
|
|
12
|
+
|
|
13
|
+
export function registerCodeGenerator(type: CodeGeneratorType, factory: () => CodeGenerator): void {
|
|
14
|
+
generators.set(type, factory);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getCodeGenerator(type: CodeGeneratorType): CodeGenerator {
|
|
18
|
+
const factory = generators.get(type);
|
|
19
|
+
if (!factory) {
|
|
20
|
+
throw new Error(`No code generator registered for type: ${type}`);
|
|
21
|
+
}
|
|
22
|
+
return factory();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function listCodeGenerators(): CodeGeneratorType[] {
|
|
26
|
+
return Array.from(generators.keys());
|
|
27
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { CodeGenerator } from './registry.js';
|
|
2
|
+
import { ActionScaffold } from '../skills.js';
|
|
3
|
+
import { MachineDef } from '../parser/ast.js';
|
|
4
|
+
|
|
5
|
+
export class TypeScriptCodeGenerator implements CodeGenerator {
|
|
6
|
+
name(): string {
|
|
7
|
+
return 'typescript';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
generate(actions: ActionScaffold[], machine: MachineDef): string {
|
|
11
|
+
const lines: string[] = [
|
|
12
|
+
`// Generated by Orca`,
|
|
13
|
+
`// Machine: ${machine.name}`,
|
|
14
|
+
'',
|
|
15
|
+
`export interface Context {`,
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
// Generate context type from machine context
|
|
19
|
+
for (const field of machine.context) {
|
|
20
|
+
if (field.type) {
|
|
21
|
+
lines.push(` ${field.name}: ${field.type};`);
|
|
22
|
+
} else {
|
|
23
|
+
lines.push(` ${field.name}: string | number | boolean;`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
lines.push('}');
|
|
28
|
+
lines.push('');
|
|
29
|
+
|
|
30
|
+
// Generate event types
|
|
31
|
+
lines.push(`export type ${machine.name}Event = ${machine.events.map(e => `'${e}'`).join(' | ')};`);
|
|
32
|
+
lines.push('');
|
|
33
|
+
|
|
34
|
+
// Generate action functions
|
|
35
|
+
for (const action of actions) {
|
|
36
|
+
lines.push(this.generateAction(action, machine));
|
|
37
|
+
lines.push('');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return lines.join('\n');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
generateAction(action: ActionScaffold, machine: MachineDef): string {
|
|
44
|
+
const ctxType = 'Context';
|
|
45
|
+
|
|
46
|
+
if (action.hasEffect && action.effectType) {
|
|
47
|
+
return `// Action: ${action.name}
|
|
48
|
+
// Effect: ${action.effectType}
|
|
49
|
+
|
|
50
|
+
export function ${action.name}(ctx: ${ctxType}, event: { type: ${machine.name}Event }): [${ctxType}, Effect<${action.effectType}>] {
|
|
51
|
+
// TODO: Implement action
|
|
52
|
+
return [ctx, { type: '${action.effectType}', payload: {} }];
|
|
53
|
+
}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return `// Action: ${action.name}
|
|
57
|
+
|
|
58
|
+
export function ${action.name}(ctx: ${ctxType}): ${ctxType} {
|
|
59
|
+
// TODO: Implement action
|
|
60
|
+
return { ...ctx };
|
|
61
|
+
}`;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Register the TypeScript code generator
|
|
66
|
+
import { registerCodeGenerator } from './registry.js';
|
|
67
|
+
registerCodeGenerator('typescript', () => new TypeScriptCodeGenerator());
|