@hoplogic/engine 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/README.md +112 -0
- package/dist/index.cjs +651 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +249 -0
- package/dist/index.d.ts +249 -0
- package/dist/index.js +639 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
package/README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# @hoplogic/engine
|
|
2
|
+
|
|
3
|
+
HopSpec execution engine for TypeScript — step orchestration, LLM verification, retry loops.
|
|
4
|
+
|
|
5
|
+
Bring your own LLM: the engine uses Protocol interfaces (`HopLLM`, `HopVerifier`) so you can plug in any LLM SDK (Vercel AI SDK, OpenAI, Anthropic, etc.).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @hoplogic/engine
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Basic: Execute a HopSpec
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { HopJIT } from "@hoplogic/engine"
|
|
19
|
+
import type { HopLLM, LLMResult } from "@hoplogic/engine"
|
|
20
|
+
|
|
21
|
+
// Implement the HopLLM protocol with your preferred SDK
|
|
22
|
+
const llm: HopLLM = {
|
|
23
|
+
async query(prompt, options): Promise<LLMResult> {
|
|
24
|
+
// Call your LLM here
|
|
25
|
+
const response = await myLLM.generate(prompt)
|
|
26
|
+
return { success: true, content: response }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const jit = new HopJIT({ llm, maxRetries: 3 })
|
|
31
|
+
const result = await jit.runSpec(hopspecMarkdown, { question: "What is 1+1?" })
|
|
32
|
+
|
|
33
|
+
console.log(result.status) // "ok" | "fail" | "need_input"
|
|
34
|
+
console.log(result.output) // execution output
|
|
35
|
+
console.log(result.stats) // { llm_calls: 2, verify_calls: 1, retries: 0 }
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### With Verification
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import type { HopVerifier, VerifyResult } from "@hoplogic/engine"
|
|
42
|
+
|
|
43
|
+
const verifier: HopVerifier = {
|
|
44
|
+
async verify(task, context, result): Promise<VerifyResult> {
|
|
45
|
+
// Independent LLM call to verify the result
|
|
46
|
+
return { passed: true, reason: "Result is correct" }
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const jit = new HopJIT({ llm, verifier, maxRetries: 3 })
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Low-level: SpecExecutor
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { SpecExecutor } from "@hoplogic/engine"
|
|
57
|
+
import type { StepInfo } from "@hoplogic/spec"
|
|
58
|
+
|
|
59
|
+
const executor = new SpecExecutor({ llm, verifier, maxRetries: 3 })
|
|
60
|
+
const result = await executor.execute(steps, inputContext)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Protocols
|
|
64
|
+
|
|
65
|
+
### HopLLM
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
interface HopLLM {
|
|
69
|
+
query(prompt: string, options?: LLMOptions): Promise<LLMResult>
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface LLMOptions {
|
|
73
|
+
systemPrompt?: string
|
|
74
|
+
responseFormat?: ZodSchema // for structured output
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
interface LLMResult {
|
|
78
|
+
success: boolean
|
|
79
|
+
content: string
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### HopVerifier
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
interface HopVerifier {
|
|
87
|
+
verify(task: string, context: string, result: string): Promise<VerifyResult>
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
interface VerifyResult {
|
|
91
|
+
passed: boolean
|
|
92
|
+
reason: string
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Step Types
|
|
97
|
+
|
|
98
|
+
The engine executes 7 step types:
|
|
99
|
+
|
|
100
|
+
| Type | Description |
|
|
101
|
+
|------|-------------|
|
|
102
|
+
| `LLM` | LLM inference with optional verification |
|
|
103
|
+
| `code` | JavaScript expression evaluation (sandboxed via `new Function`) |
|
|
104
|
+
| `loop` | For-each or while loops with break/continue |
|
|
105
|
+
| `branch` | Conditional execution |
|
|
106
|
+
| `flow` | Control flow: exit, continue, break |
|
|
107
|
+
| `call` | External function calls |
|
|
108
|
+
| `subtask` | Grouped sub-steps |
|
|
109
|
+
|
|
110
|
+
## License
|
|
111
|
+
|
|
112
|
+
MIT
|