@agentix-e/spel-editor 1.0.0 → 1.1.1
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 +139 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -85,6 +85,145 @@ npm install @agentix-e/spel-editor
|
|
|
85
85
|
| `--spel-border-color` | `#d0d5dd` | Editor border color |
|
|
86
86
|
| `--spel-border-radius` | `6px` | Editor border radius |
|
|
87
87
|
|
|
88
|
+
## NL Integration — Natural Language → SpEL
|
|
89
|
+
|
|
90
|
+
`@agentix-e/spel-editor` accepts `@agentix-e/nl2spel` as an **optional peer dependency**.
|
|
91
|
+
You can wire nl2spel into the editor to translate natural language input into valid SpEL expressions.
|
|
92
|
+
|
|
93
|
+
### Pattern Matching (Zero Dependencies, No API Key)
|
|
94
|
+
|
|
95
|
+
nl2spel ships with 63 built-in patterns that cover common SpEL constructs without any LLM call:
|
|
96
|
+
|
|
97
|
+
```html
|
|
98
|
+
<spel-editor id="editor" min-height="100px"></spel-editor>
|
|
99
|
+
|
|
100
|
+
<script type="module">
|
|
101
|
+
import '@agentix-e/spel-editor';
|
|
102
|
+
import { NL2SpelEngine } from '@agentix-e/nl2spel';
|
|
103
|
+
|
|
104
|
+
const editor = document.querySelector('#editor');
|
|
105
|
+
const engine = new NL2SpelEngine();
|
|
106
|
+
|
|
107
|
+
async function generateSpEL(naturalLanguage) {
|
|
108
|
+
const result = await engine.generate(naturalLanguage, { offlineOnly: true });
|
|
109
|
+
if (result.expression) {
|
|
110
|
+
editor.setValue(result.expression);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Usage:
|
|
115
|
+
await generateSpEL('amount greater than 500');
|
|
116
|
+
// Editor now shows: #amount > 500
|
|
117
|
+
</script>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### LLM-Powered: DeepSeek / OpenAI-Compatible
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
npm install @agentix-e/nl2spel-openai
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
```html
|
|
127
|
+
<spel-editor id="editor" min-height="100px"></spel-editor>
|
|
128
|
+
|
|
129
|
+
<script type="module">
|
|
130
|
+
import '@agentix-e/spel-editor';
|
|
131
|
+
import { NL2SpelEngine } from '@agentix-e/nl2spel';
|
|
132
|
+
import { OpenAICompatibleProvider } from '@agentix-e/nl2spel-openai';
|
|
133
|
+
|
|
134
|
+
const editor = document.querySelector('#editor');
|
|
135
|
+
const engine = new NL2SpelEngine();
|
|
136
|
+
|
|
137
|
+
// Register DeepSeek as the LLM provider
|
|
138
|
+
engine.registerProvider(
|
|
139
|
+
new OpenAICompatibleProvider({
|
|
140
|
+
provider: 'deepseek',
|
|
141
|
+
apiKey: 'sk-your-deepseek-key-here',
|
|
142
|
+
})
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
async function generateSpEL(naturalLanguage, contextSchema) {
|
|
146
|
+
const result = await engine.generate(naturalLanguage, { contextSchema });
|
|
147
|
+
if (result.expression) {
|
|
148
|
+
editor.setValue(result.expression);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// With context schema for smarter completions:
|
|
153
|
+
const schema = {
|
|
154
|
+
root: {
|
|
155
|
+
name: 'order',
|
|
156
|
+
type: 'Order',
|
|
157
|
+
fields: {
|
|
158
|
+
amount: { type: 'number', description: 'Order amount' },
|
|
159
|
+
status: { type: 'string', description: 'Order status' },
|
|
160
|
+
},
|
|
161
|
+
methods: {},
|
|
162
|
+
},
|
|
163
|
+
variables: {},
|
|
164
|
+
beans: {},
|
|
165
|
+
types: {},
|
|
166
|
+
functions: {},
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
// Wire the schema for context-aware diagnostics
|
|
170
|
+
editor.contextSchema = schema;
|
|
171
|
+
|
|
172
|
+
// Generate SpEL with full context
|
|
173
|
+
await generateSpEL('orders where amount exceeds one thousand and status is active', schema);
|
|
174
|
+
// Editor shows: #order.amount > 1000 and #order.status == 'active'
|
|
175
|
+
</script>
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Browser-Local LLM: WebLLM (Gemma)
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
npm install @agentix-e/nl2spel-webllm @mlc-ai/web-llm
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
```html
|
|
185
|
+
<spel-editor id="editor" min-height="100px"></spel-editor>
|
|
186
|
+
|
|
187
|
+
<script type="module">
|
|
188
|
+
import '@agentix-e/spel-editor';
|
|
189
|
+
import { NL2SpelEngine } from '@agentix-e/nl2spel';
|
|
190
|
+
import { WebLLMProvider } from '@agentix-e/nl2spel-webllm';
|
|
191
|
+
|
|
192
|
+
const editor = document.querySelector('#editor');
|
|
193
|
+
const engine = new NL2SpelEngine();
|
|
194
|
+
|
|
195
|
+
const provider = new WebLLMProvider({
|
|
196
|
+
modelId: 'gemma-2-2b-it', // 2B parameter model
|
|
197
|
+
maxTokens: 256,
|
|
198
|
+
temperature: 0.1,
|
|
199
|
+
debug: false, // Set true to see model logs
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
await provider.initialize();
|
|
203
|
+
engine.registerProvider(provider);
|
|
204
|
+
|
|
205
|
+
async function generateSpEL(naturalLanguage) {
|
|
206
|
+
const result = await engine.generate(naturalLanguage);
|
|
207
|
+
if (result.expression) {
|
|
208
|
+
editor.setValue(result.expression);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// First call loads the model (~1.5 GB download, cached in IndexedDB)
|
|
213
|
+
await generateSpEL('amount greater than 500');
|
|
214
|
+
// Subsequent calls are fast — model stays in memory
|
|
215
|
+
await generateSpEL('status is not null and not empty');
|
|
216
|
+
</script>
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Integration Pattern Summary
|
|
220
|
+
|
|
221
|
+
| Mode | Package | API Key | Data Leaves Browser | Setup |
|
|
222
|
+
|------|---------|---------|-------------------|-------|
|
|
223
|
+
| **Pattern matching** | `@agentix-e/nl2spel` | ❌ None | ❌ No | `npm install` |
|
|
224
|
+
| **DeepSeek / OpenAI** | `+ nl2spel-openai` | ✅ Required | ✅ Yes | `npm install` + API key |
|
|
225
|
+
| **Browser-local LLM** | `+ nl2spel-webllm` | ❌ None | ❌ No | 1.5 GB model download |
|
|
226
|
+
|
|
88
227
|
## License
|
|
89
228
|
|
|
90
229
|
MIT © AgentiX-E
|
package/package.json
CHANGED