@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,48 @@
|
|
|
1
|
+
// Effect routing and execution for Orca runtime
|
|
2
|
+
|
|
3
|
+
export interface Effect<T = unknown> {
|
|
4
|
+
type: string;
|
|
5
|
+
payload: T;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface EffectResult {
|
|
9
|
+
status: 'success' | 'failure' | 'timeout';
|
|
10
|
+
data?: unknown;
|
|
11
|
+
error?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type EffectHandler<T = unknown> = (effect: Effect<T>) => Promise<EffectResult> | EffectResult;
|
|
15
|
+
|
|
16
|
+
export interface EffectRouter {
|
|
17
|
+
register<T>(type: string, handler: EffectHandler<T>): void;
|
|
18
|
+
route<T>(effect: Effect<T>): Promise<EffectResult>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function createEffectRouter(handlers?: Record<string, EffectHandler>): EffectRouter {
|
|
22
|
+
const handlerMap = new Map<string, EffectHandler<unknown>>();
|
|
23
|
+
if (handlers) {
|
|
24
|
+
for (const [key, value] of Object.entries(handlers)) {
|
|
25
|
+
handlerMap.set(key, value as EffectHandler<unknown>);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
register(type, handler) {
|
|
31
|
+
handlerMap.set(type, handler as EffectHandler<unknown>);
|
|
32
|
+
},
|
|
33
|
+
route(effect) {
|
|
34
|
+
const handler = handlerMap.get(effect.type) as EffectHandler<unknown> | undefined;
|
|
35
|
+
if (!handler) {
|
|
36
|
+
return Promise.resolve({
|
|
37
|
+
status: 'failure' as const,
|
|
38
|
+
error: `No handler registered for effect type: ${effect.type}`,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return Promise.resolve(handler(effect));
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function emit<T>(payload: T, type: string = 'anonymous'): Effect<T> {
|
|
47
|
+
return { type, payload };
|
|
48
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// Orca Machine Runtime - creates executable state machines
|
|
2
|
+
|
|
3
|
+
import { createActor, createMachine, fromPromise } from 'xstate';
|
|
4
|
+
import { assign } from 'xstate';
|
|
5
|
+
import type { Actor } from 'xstate';
|
|
6
|
+
import { compileToXStateMachine, CompiledMachine } from '../compiler/xstate.js';
|
|
7
|
+
import { MachineDef } from '../parser/ast.js';
|
|
8
|
+
import {
|
|
9
|
+
EffectHandlers,
|
|
10
|
+
OrcaMachineOptions,
|
|
11
|
+
OrcaState,
|
|
12
|
+
OrcaSnapshot,
|
|
13
|
+
OrcaMachine,
|
|
14
|
+
} from './types.js';
|
|
15
|
+
import type { Effect } from './effects.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Create an executable Orca machine with effect handling
|
|
19
|
+
*/
|
|
20
|
+
export function createOrcaMachine(
|
|
21
|
+
machineOrDef: MachineDef | CompiledMachine,
|
|
22
|
+
options: OrcaMachineOptions
|
|
23
|
+
): OrcaMachine {
|
|
24
|
+
let compiled: CompiledMachine;
|
|
25
|
+
let machineDef: MachineDef;
|
|
26
|
+
|
|
27
|
+
if ('effectMeta' in machineOrDef) {
|
|
28
|
+
compiled = machineOrDef;
|
|
29
|
+
machineDef = {} as MachineDef;
|
|
30
|
+
} else {
|
|
31
|
+
machineDef = machineOrDef;
|
|
32
|
+
compiled = compileToXStateMachine(machineDef);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Preprocess the config to inline fromPromise for effect invocations
|
|
36
|
+
const config = preprocessEffectInvokes(compiled.config, compiled.effectMeta.effectfulActions, options.effectHandlers);
|
|
37
|
+
|
|
38
|
+
// Create the XState machine
|
|
39
|
+
const machine = createMachine(config);
|
|
40
|
+
|
|
41
|
+
// Create and start the actor
|
|
42
|
+
const actor = createActor(machine);
|
|
43
|
+
|
|
44
|
+
// Set up transition observer
|
|
45
|
+
if (options.onTransition) {
|
|
46
|
+
actor.subscribe((state) => {
|
|
47
|
+
options.onTransition?.({
|
|
48
|
+
value: state.value as string,
|
|
49
|
+
context: state.context as Record<string, unknown>,
|
|
50
|
+
status: state.status as 'active' | 'done' | 'error',
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return new OrcaMachineImpl(actor, machine, options);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Preprocess the machine config to replace __effect__:type references
|
|
60
|
+
* with actual fromPromise inline invocations.
|
|
61
|
+
*/
|
|
62
|
+
function preprocessEffectInvokes(
|
|
63
|
+
config: any,
|
|
64
|
+
effectfulActions: CompiledMachine['effectMeta']['effectfulActions'],
|
|
65
|
+
handlers: EffectHandlers
|
|
66
|
+
): any {
|
|
67
|
+
// Build a map of effectType -> handler
|
|
68
|
+
const handlerMap = new Map<string, any>();
|
|
69
|
+
for (const action of effectfulActions) {
|
|
70
|
+
const handler = handlers[action.effectType];
|
|
71
|
+
if (handler && typeof handler === 'function') {
|
|
72
|
+
handlerMap.set(action.effectType, { handler, action });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Deep clone the config preserving functions
|
|
77
|
+
const processedConfig = deepCloneWithInvokeReplacement(config, handlerMap);
|
|
78
|
+
|
|
79
|
+
return processedConfig;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Deep clone config while replacing __effect__:type invoke src with fromPromise.
|
|
84
|
+
* Preserves functions (unlike JSON serialization).
|
|
85
|
+
*/
|
|
86
|
+
function deepCloneWithInvokeReplacement(obj: any, handlerMap: Map<string, any>): any {
|
|
87
|
+
if (obj === null || typeof obj !== 'object') {
|
|
88
|
+
return obj;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (Array.isArray(obj)) {
|
|
92
|
+
return obj.map(item => deepCloneWithInvokeReplacement(item, handlerMap));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Check if this is an invoke object with __effect__:type src
|
|
96
|
+
if ('src' in obj && typeof obj.src === 'string' && obj.src.startsWith('__effect__:')) {
|
|
97
|
+
const effectType = obj.src.replace('__effect__:', '');
|
|
98
|
+
const entryHandler = handlerMap.get(effectType);
|
|
99
|
+
|
|
100
|
+
if (entryHandler) {
|
|
101
|
+
// Create new invoke object with fromPromise replacing the string src
|
|
102
|
+
const newObj: any = { ...obj };
|
|
103
|
+
newObj.src = fromPromise(async ({ input }: { input: any }) => {
|
|
104
|
+
const effect: Effect = {
|
|
105
|
+
type: effectType,
|
|
106
|
+
payload: input,
|
|
107
|
+
};
|
|
108
|
+
try {
|
|
109
|
+
const result = await Promise.resolve(entryHandler.handler(effect));
|
|
110
|
+
return result;
|
|
111
|
+
} catch (err) {
|
|
112
|
+
throw err;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
// Clone other properties recursively
|
|
116
|
+
for (const key of Object.keys(obj)) {
|
|
117
|
+
if (key !== 'src') {
|
|
118
|
+
newObj[key] = deepCloneWithInvokeReplacement(obj[key], handlerMap);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return newObj;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Regular object - clone all properties
|
|
126
|
+
const newObj: any = {};
|
|
127
|
+
for (const key of Object.keys(obj)) {
|
|
128
|
+
newObj[key] = deepCloneWithInvokeReplacement(obj[key], handlerMap);
|
|
129
|
+
}
|
|
130
|
+
return newObj;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
class OrcaMachineImpl implements OrcaMachine {
|
|
134
|
+
private actor: Actor<any>;
|
|
135
|
+
private machineLogic: ReturnType<typeof createMachine>;
|
|
136
|
+
private options: OrcaMachineOptions;
|
|
137
|
+
|
|
138
|
+
constructor(actor: Actor<any>, machineLogic: ReturnType<typeof createMachine>, options: OrcaMachineOptions) {
|
|
139
|
+
this.actor = actor;
|
|
140
|
+
this.machineLogic = machineLogic;
|
|
141
|
+
this.options = options;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
start(): void {
|
|
145
|
+
this.actor.start();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
stop(): void {
|
|
149
|
+
this.actor.stop();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async send(event: unknown): Promise<void> {
|
|
153
|
+
this.actor.send(event as any);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
getState(): OrcaState {
|
|
157
|
+
const state = this.actor.getSnapshot();
|
|
158
|
+
return {
|
|
159
|
+
value: state.value as string,
|
|
160
|
+
context: state.context as Record<string, unknown>,
|
|
161
|
+
status: state.status as 'active' | 'done' | 'error',
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
snapshot(): OrcaSnapshot {
|
|
166
|
+
return {
|
|
167
|
+
state: this.getState(),
|
|
168
|
+
timestamp: Date.now(),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
restore(snapshot: OrcaSnapshot): void {
|
|
173
|
+
// Stop the current actor
|
|
174
|
+
this.actor.stop();
|
|
175
|
+
|
|
176
|
+
// Build a persisted snapshot compatible with XState v5
|
|
177
|
+
const restoredSnapshot = this.machineLogic.resolveState({
|
|
178
|
+
value: snapshot.state.value,
|
|
179
|
+
context: snapshot.state.context,
|
|
180
|
+
} as any);
|
|
181
|
+
|
|
182
|
+
// Create a new actor from the persisted state
|
|
183
|
+
const newActor = createActor(this.machineLogic, {
|
|
184
|
+
snapshot: restoredSnapshot,
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// Re-attach transition observer
|
|
188
|
+
if (this.options.onTransition) {
|
|
189
|
+
newActor.subscribe((state) => {
|
|
190
|
+
this.options.onTransition?.({
|
|
191
|
+
value: state.value as string,
|
|
192
|
+
context: state.context as Record<string, unknown>,
|
|
193
|
+
status: state.status as 'active' | 'done' | 'error',
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
this.actor = newActor;
|
|
199
|
+
this.actor.start();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Runtime types for Orca machine execution
|
|
2
|
+
|
|
3
|
+
import type { Effect, EffectResult } from './effects.js';
|
|
4
|
+
export type { Effect, EffectResult, EffectHandler, EffectRouter } from './effects.js';
|
|
5
|
+
export { createEffectRouter } from './effects.js';
|
|
6
|
+
|
|
7
|
+
export interface EffectHandlers {
|
|
8
|
+
[effectType: string]: (effect: Effect) => Promise<EffectResult>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface EffectResponseMapping {
|
|
12
|
+
[effectType: string]: {
|
|
13
|
+
success?: string;
|
|
14
|
+
failure?: string;
|
|
15
|
+
timeout?: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface OrcaMachineOptions {
|
|
20
|
+
effectHandlers: EffectHandlers;
|
|
21
|
+
effectResponses?: EffectResponseMapping;
|
|
22
|
+
onTransition?: (state: OrcaState) => void;
|
|
23
|
+
onEffect?: (effect: Effect) => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface OrcaState {
|
|
27
|
+
value: string;
|
|
28
|
+
context: Record<string, unknown>;
|
|
29
|
+
status: 'active' | 'done' | 'error';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface OrcaSnapshot {
|
|
33
|
+
state: OrcaState;
|
|
34
|
+
timestamp: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface OrcaMachine {
|
|
38
|
+
start(): void;
|
|
39
|
+
stop(): void;
|
|
40
|
+
send(event: unknown): Promise<void>;
|
|
41
|
+
getState(): OrcaState;
|
|
42
|
+
snapshot(): OrcaSnapshot;
|
|
43
|
+
restore(snapshot: OrcaSnapshot): void;
|
|
44
|
+
}
|