@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.
Files changed (183) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +128 -0
  3. package/dist/auth/index.d.ts +6 -0
  4. package/dist/auth/index.d.ts.map +1 -0
  5. package/dist/auth/index.js +6 -0
  6. package/dist/auth/index.js.map +1 -0
  7. package/dist/auth/lock.d.ts +2 -0
  8. package/dist/auth/lock.d.ts.map +1 -0
  9. package/dist/auth/lock.js +59 -0
  10. package/dist/auth/lock.js.map +1 -0
  11. package/dist/auth/providers/anthropic.d.ts +14 -0
  12. package/dist/auth/providers/anthropic.d.ts.map +1 -0
  13. package/dist/auth/providers/anthropic.js +145 -0
  14. package/dist/auth/providers/anthropic.js.map +1 -0
  15. package/dist/auth/providers/index.d.ts +3 -0
  16. package/dist/auth/providers/index.d.ts.map +1 -0
  17. package/dist/auth/providers/index.js +3 -0
  18. package/dist/auth/providers/index.js.map +1 -0
  19. package/dist/auth/providers/minimax.d.ts +6 -0
  20. package/dist/auth/providers/minimax.d.ts.map +1 -0
  21. package/dist/auth/providers/minimax.js +65 -0
  22. package/dist/auth/providers/minimax.js.map +1 -0
  23. package/dist/auth/refresh.d.ts +8 -0
  24. package/dist/auth/refresh.d.ts.map +1 -0
  25. package/dist/auth/refresh.js +104 -0
  26. package/dist/auth/refresh.js.map +1 -0
  27. package/dist/auth/store.d.ts +11 -0
  28. package/dist/auth/store.d.ts.map +1 -0
  29. package/dist/auth/store.js +63 -0
  30. package/dist/auth/store.js.map +1 -0
  31. package/dist/auth/types.d.ts +51 -0
  32. package/dist/auth/types.d.ts.map +1 -0
  33. package/dist/auth/types.js +2 -0
  34. package/dist/auth/types.js.map +1 -0
  35. package/dist/compiler/mermaid.d.ts +3 -0
  36. package/dist/compiler/mermaid.d.ts.map +1 -0
  37. package/dist/compiler/mermaid.js +86 -0
  38. package/dist/compiler/mermaid.js.map +1 -0
  39. package/dist/compiler/xstate.d.ts +15 -0
  40. package/dist/compiler/xstate.d.ts.map +1 -0
  41. package/dist/compiler/xstate.js +542 -0
  42. package/dist/compiler/xstate.js.map +1 -0
  43. package/dist/config/index.d.ts +3 -0
  44. package/dist/config/index.d.ts.map +1 -0
  45. package/dist/config/index.js +3 -0
  46. package/dist/config/index.js.map +1 -0
  47. package/dist/config/loader.d.ts +4 -0
  48. package/dist/config/loader.d.ts.map +1 -0
  49. package/dist/config/loader.js +109 -0
  50. package/dist/config/loader.js.map +1 -0
  51. package/dist/config/types.d.ts +13 -0
  52. package/dist/config/types.d.ts.map +1 -0
  53. package/dist/config/types.js +8 -0
  54. package/dist/config/types.js.map +1 -0
  55. package/dist/generators/index.d.ts +5 -0
  56. package/dist/generators/index.d.ts.map +1 -0
  57. package/dist/generators/index.js +5 -0
  58. package/dist/generators/index.js.map +1 -0
  59. package/dist/generators/registry.d.ts +12 -0
  60. package/dist/generators/registry.d.ts.map +1 -0
  61. package/dist/generators/registry.js +15 -0
  62. package/dist/generators/registry.js.map +1 -0
  63. package/dist/generators/typescript.d.ts +9 -0
  64. package/dist/generators/typescript.d.ts.map +1 -0
  65. package/dist/generators/typescript.js +55 -0
  66. package/dist/generators/typescript.js.map +1 -0
  67. package/dist/index.d.ts +10 -0
  68. package/dist/index.d.ts.map +1 -0
  69. package/dist/index.js +630 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/llm/anthropic.d.ts +14 -0
  72. package/dist/llm/anthropic.d.ts.map +1 -0
  73. package/dist/llm/anthropic.js +87 -0
  74. package/dist/llm/anthropic.js.map +1 -0
  75. package/dist/llm/grok.d.ts +13 -0
  76. package/dist/llm/grok.d.ts.map +1 -0
  77. package/dist/llm/grok.js +60 -0
  78. package/dist/llm/grok.js.map +1 -0
  79. package/dist/llm/index.d.ts +11 -0
  80. package/dist/llm/index.d.ts.map +1 -0
  81. package/dist/llm/index.js +23 -0
  82. package/dist/llm/index.js.map +1 -0
  83. package/dist/llm/ollama.d.ts +11 -0
  84. package/dist/llm/ollama.d.ts.map +1 -0
  85. package/dist/llm/ollama.js +51 -0
  86. package/dist/llm/ollama.js.map +1 -0
  87. package/dist/llm/openai.d.ts +13 -0
  88. package/dist/llm/openai.d.ts.map +1 -0
  89. package/dist/llm/openai.js +61 -0
  90. package/dist/llm/openai.js.map +1 -0
  91. package/dist/llm/provider.d.ts +32 -0
  92. package/dist/llm/provider.d.ts.map +1 -0
  93. package/dist/llm/provider.js +2 -0
  94. package/dist/llm/provider.js.map +1 -0
  95. package/dist/parser/ast-to-markdown.d.ts +3 -0
  96. package/dist/parser/ast-to-markdown.d.ts.map +1 -0
  97. package/dist/parser/ast-to-markdown.js +209 -0
  98. package/dist/parser/ast-to-markdown.js.map +1 -0
  99. package/dist/parser/ast.d.ts +183 -0
  100. package/dist/parser/ast.d.ts.map +1 -0
  101. package/dist/parser/ast.js +3 -0
  102. package/dist/parser/ast.js.map +1 -0
  103. package/dist/parser/markdown-parser.d.ts +8 -0
  104. package/dist/parser/markdown-parser.d.ts.map +1 -0
  105. package/dist/parser/markdown-parser.js +838 -0
  106. package/dist/parser/markdown-parser.js.map +1 -0
  107. package/dist/runtime/effects.d.ts +17 -0
  108. package/dist/runtime/effects.d.ts.map +1 -0
  109. package/dist/runtime/effects.js +28 -0
  110. package/dist/runtime/effects.js.map +1 -0
  111. package/dist/runtime/machine.d.ts +8 -0
  112. package/dist/runtime/machine.d.ts.map +1 -0
  113. package/dist/runtime/machine.js +158 -0
  114. package/dist/runtime/machine.js.map +1 -0
  115. package/dist/runtime/types.d.ts +37 -0
  116. package/dist/runtime/types.d.ts.map +1 -0
  117. package/dist/runtime/types.js +3 -0
  118. package/dist/runtime/types.js.map +1 -0
  119. package/dist/skills.d.ts +114 -0
  120. package/dist/skills.d.ts.map +1 -0
  121. package/dist/skills.js +1103 -0
  122. package/dist/skills.js.map +1 -0
  123. package/dist/tools.d.ts +18 -0
  124. package/dist/tools.d.ts.map +1 -0
  125. package/dist/tools.js +124 -0
  126. package/dist/tools.js.map +1 -0
  127. package/dist/verifier/completeness.d.ts +4 -0
  128. package/dist/verifier/completeness.d.ts.map +1 -0
  129. package/dist/verifier/completeness.js +82 -0
  130. package/dist/verifier/completeness.js.map +1 -0
  131. package/dist/verifier/determinism.d.ts +17 -0
  132. package/dist/verifier/determinism.d.ts.map +1 -0
  133. package/dist/verifier/determinism.js +301 -0
  134. package/dist/verifier/determinism.js.map +1 -0
  135. package/dist/verifier/properties.d.ts +6 -0
  136. package/dist/verifier/properties.d.ts.map +1 -0
  137. package/dist/verifier/properties.js +404 -0
  138. package/dist/verifier/properties.js.map +1 -0
  139. package/dist/verifier/structural.d.ts +50 -0
  140. package/dist/verifier/structural.d.ts.map +1 -0
  141. package/dist/verifier/structural.js +692 -0
  142. package/dist/verifier/structural.js.map +1 -0
  143. package/dist/verifier/types.d.ts +40 -0
  144. package/dist/verifier/types.d.ts.map +1 -0
  145. package/dist/verifier/types.js +2 -0
  146. package/dist/verifier/types.js.map +1 -0
  147. package/package.json +49 -0
  148. package/src/auth/index.ts +5 -0
  149. package/src/auth/lock.ts +71 -0
  150. package/src/auth/providers/anthropic.ts +192 -0
  151. package/src/auth/providers/index.ts +17 -0
  152. package/src/auth/providers/minimax.ts +100 -0
  153. package/src/auth/refresh.ts +138 -0
  154. package/src/auth/store.ts +75 -0
  155. package/src/auth/types.ts +62 -0
  156. package/src/compiler/mermaid.ts +109 -0
  157. package/src/compiler/xstate.ts +615 -0
  158. package/src/config/index.ts +2 -0
  159. package/src/config/loader.ts +122 -0
  160. package/src/config/types.ts +21 -0
  161. package/src/generators/index.ts +6 -0
  162. package/src/generators/registry.ts +27 -0
  163. package/src/generators/typescript.ts +67 -0
  164. package/src/index.ts +671 -0
  165. package/src/llm/anthropic.ts +102 -0
  166. package/src/llm/grok.ts +73 -0
  167. package/src/llm/index.ts +29 -0
  168. package/src/llm/ollama.ts +62 -0
  169. package/src/llm/openai.ts +74 -0
  170. package/src/llm/provider.ts +35 -0
  171. package/src/parser/ast-to-markdown.ts +220 -0
  172. package/src/parser/ast.ts +236 -0
  173. package/src/parser/markdown-parser.ts +844 -0
  174. package/src/runtime/effects.ts +48 -0
  175. package/src/runtime/machine.ts +201 -0
  176. package/src/runtime/types.ts +44 -0
  177. package/src/skills.ts +1339 -0
  178. package/src/tools.ts +144 -0
  179. package/src/verifier/completeness.ts +89 -0
  180. package/src/verifier/determinism.ts +328 -0
  181. package/src/verifier/properties.ts +507 -0
  182. package/src/verifier/structural.ts +803 -0
  183. package/src/verifier/types.ts +45 -0
@@ -0,0 +1,75 @@
1
+ import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs';
2
+ import { join } from 'path';
3
+ import { homedir } from 'os';
4
+ import { AuthProfileStore, AuthProfile } from './types.js';
5
+
6
+ const STORE_VERSION = 1;
7
+
8
+ export function getOrcaDir(): string {
9
+ return join(homedir(), '.orca');
10
+ }
11
+
12
+ export function getAuthStorePath(): string {
13
+ return join(getOrcaDir(), 'auth_profiles.json');
14
+ }
15
+
16
+ export function ensureOrcaDir(): void {
17
+ const dir = getOrcaDir();
18
+ if (!existsSync(dir)) {
19
+ mkdirSync(dir, { mode: 0o700, recursive: true });
20
+ }
21
+ }
22
+
23
+ export function loadAuthStore(): AuthProfileStore {
24
+ const path = getAuthStorePath();
25
+ ensureOrcaDir();
26
+
27
+ if (!existsSync(path)) {
28
+ return { version: STORE_VERSION, profiles: {} };
29
+ }
30
+
31
+ try {
32
+ const content = readFileSync(path, 'utf-8');
33
+ const store = JSON.parse(content) as AuthProfileStore;
34
+ return {
35
+ version: store.version ?? STORE_VERSION,
36
+ profiles: store.profiles ?? {},
37
+ };
38
+ } catch {
39
+ return { version: STORE_VERSION, profiles: {} };
40
+ }
41
+ }
42
+
43
+ export function saveAuthStore(store: AuthProfileStore): void {
44
+ const path = getAuthStorePath();
45
+ ensureOrcaDir();
46
+
47
+ // Set restrictive permissions (owner read/write only)
48
+ writeFileSync(path, JSON.stringify(store, null, 2), { mode: 0o600 });
49
+ }
50
+
51
+ export function getAuthProfile(profileId: string): AuthProfile | null {
52
+ const store = loadAuthStore();
53
+ return store.profiles[profileId] ?? null;
54
+ }
55
+
56
+ export function setAuthProfile(profileId: string, profile: AuthProfile): void {
57
+ const store = loadAuthStore();
58
+ store.profiles[profileId] = profile;
59
+ saveAuthStore(store);
60
+ }
61
+
62
+ export function deleteAuthProfile(profileId: string): boolean {
63
+ const store = loadAuthStore();
64
+ if (store.profiles[profileId]) {
65
+ delete store.profiles[profileId];
66
+ saveAuthStore(store);
67
+ return true;
68
+ }
69
+ return false;
70
+ }
71
+
72
+ export function listAuthProfiles(): string[] {
73
+ const store = loadAuthStore();
74
+ return Object.keys(store.profiles);
75
+ }
@@ -0,0 +1,62 @@
1
+ export type AuthMode = 'api_key' | 'oauth' | 'token';
2
+
3
+ export interface ApiKeyCredential {
4
+ type: 'api_key';
5
+ provider: string;
6
+ key: string;
7
+ email?: string;
8
+ }
9
+
10
+ export interface OAuthCredential {
11
+ type: 'oauth';
12
+ provider: string;
13
+ access: string;
14
+ refresh: string;
15
+ expires: number; // Unix timestamp
16
+ email?: string;
17
+ }
18
+
19
+ export interface TokenCredential {
20
+ type: 'token';
21
+ provider: string;
22
+ token: string;
23
+ expires?: number; // Unix timestamp
24
+ email?: string;
25
+ }
26
+
27
+ export type AuthCredential = ApiKeyCredential | OAuthCredential | TokenCredential;
28
+
29
+ export interface AuthProfile {
30
+ mode: AuthMode;
31
+ provider: string;
32
+ email?: string;
33
+ // api_key mode
34
+ key?: string;
35
+ keyRef?: string;
36
+ // token mode
37
+ token?: string;
38
+ tokenRef?: string;
39
+ // oauth mode
40
+ access?: string;
41
+ refresh?: string;
42
+ expires?: number;
43
+ }
44
+
45
+ export interface AuthProfileStore {
46
+ version: number;
47
+ profiles: Record<string, AuthProfile>;
48
+ }
49
+
50
+ export interface AuthProfileResult {
51
+ apiKey: string;
52
+ provider: string;
53
+ email?: string;
54
+ }
55
+
56
+ export type OAuthProvider = 'anthropic' | 'minimax';
57
+
58
+ export interface TokenRefreshResult {
59
+ access: string;
60
+ refresh?: string;
61
+ expires: number;
62
+ }
@@ -0,0 +1,109 @@
1
+ import { MachineDef, StateDef } from '../parser/ast.js';
2
+
3
+ export function compileToMermaid(machine: MachineDef): string {
4
+ const lines: string[] = [];
5
+
6
+ lines.push(`stateDiagram-v2`);
7
+ lines.push(` direction LR`);
8
+ lines.push(``);
9
+
10
+ // Add initial state transition
11
+ lines.push(` [*] --> ${getInitialStateName(machine)}`);
12
+
13
+ // Add termination transitions for top-level final states
14
+ for (const state of machine.states) {
15
+ if (state.isFinal) {
16
+ lines.push(` ${state.name} --> [*]`);
17
+ }
18
+ }
19
+
20
+ lines.push(``);
21
+
22
+ // Render compound/parallel state bodies
23
+ for (const state of machine.states) {
24
+ renderStateBody(state, machine, lines, ' ');
25
+ }
26
+
27
+ // Add transitions
28
+ for (const t of machine.transitions) {
29
+ let label = t.event;
30
+ if (t.guard) {
31
+ label += ` [${t.guard.negated ? '!' : ''}${t.guard.name}]`;
32
+ }
33
+ if (t.action && t.action !== '_') {
34
+ label += ` / ${t.action}`;
35
+ }
36
+ lines.push(` ${t.source} --> ${t.target} : ${label}`);
37
+ }
38
+
39
+ return lines.join('\n');
40
+ }
41
+
42
+ function renderStateBody(state: StateDef, machine: MachineDef, lines: string[], indent: string): void {
43
+ // Hierarchical compound states
44
+ if (state.contains && state.contains.length > 0) {
45
+ lines.push(`${indent}state ${state.name} {`);
46
+ const inner = indent + ' ';
47
+
48
+ // Initial child transition
49
+ const initialChild = state.contains.find(s => s.isInitial) || state.contains[0];
50
+ lines.push(`${inner}[*] --> ${initialChild.name}`);
51
+
52
+ // Final child transitions
53
+ for (const child of state.contains) {
54
+ if (child.isFinal) {
55
+ lines.push(`${inner}${child.name} --> [*]`);
56
+ }
57
+ }
58
+
59
+ // Recurse into children that are themselves compound/parallel
60
+ for (const child of state.contains) {
61
+ renderStateBody(child, machine, lines, inner);
62
+ }
63
+
64
+ lines.push(`${indent}}`);
65
+ }
66
+
67
+ // Parallel states
68
+ if (state.parallel) {
69
+ lines.push(`${indent}state ${state.name} {`);
70
+ const inner = indent + ' ';
71
+
72
+ for (let i = 0; i < state.parallel.regions.length; i++) {
73
+ const region = state.parallel.regions[i];
74
+
75
+ // Region separator between regions
76
+ if (i > 0) {
77
+ lines.push(`${inner}--`);
78
+ }
79
+
80
+ lines.push(`${inner}state ${region.name} {`);
81
+ const regionInner = inner + ' ';
82
+
83
+ // Initial child transition within region
84
+ const initialChild = region.states.find(s => s.isInitial) || region.states[0];
85
+ lines.push(`${regionInner}[*] --> ${initialChild.name}`);
86
+
87
+ // Final child transitions within region
88
+ for (const child of region.states) {
89
+ if (child.isFinal) {
90
+ lines.push(`${regionInner}${child.name} --> [*]`);
91
+ }
92
+ }
93
+
94
+ // Recurse into children
95
+ for (const child of region.states) {
96
+ renderStateBody(child, machine, lines, regionInner);
97
+ }
98
+
99
+ lines.push(`${inner}}`);
100
+ }
101
+
102
+ lines.push(`${indent}}`);
103
+ }
104
+ }
105
+
106
+ function getInitialStateName(machine: MachineDef): string {
107
+ const initial = machine.states.find(s => s.isInitial);
108
+ return initial?.name || machine.states[0]?.name || 'unknown';
109
+ }