@node-agent/provider 0.0.0-stage → 0.1.6
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 +21 -0
- package/README.md +167 -2
- package/dist/i18n/en.json +105 -0
- package/dist/i18n/zh-CN.json +105 -0
- package/dist/icon.svg +6 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +372 -0
- package/dist/index.js.map +1 -0
- package/dist/mode.d.ts +26 -0
- package/dist/mode.js +39 -0
- package/dist/mode.js.map +1 -0
- package/dist/persistency/history.d.ts +11 -0
- package/dist/persistency/history.js +50 -0
- package/dist/persistency/history.js.map +1 -0
- package/dist/persistency/index.d.ts +23 -0
- package/dist/persistency/index.js +33 -0
- package/dist/persistency/index.js.map +1 -0
- package/dist/persistency/local.d.ts +20 -0
- package/dist/persistency/local.js +50 -0
- package/dist/persistency/local.js.map +1 -0
- package/dist/providers/anthropic.d.ts +28 -0
- package/dist/providers/anthropic.js +538 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/base.d.ts +262 -0
- package/dist/providers/base.js +871 -0
- package/dist/providers/base.js.map +1 -0
- package/dist/providers/deepseek.d.ts +18 -0
- package/dist/providers/deepseek.js +73 -0
- package/dist/providers/deepseek.js.map +1 -0
- package/dist/providers/index.d.ts +13 -0
- package/dist/providers/index.js +30 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/responses.d.ts +28 -0
- package/dist/providers/responses.js +310 -0
- package/dist/providers/responses.js.map +1 -0
- package/dist/serve.d.ts +2 -0
- package/dist/serve.js +28 -0
- package/dist/serve.js.map +1 -0
- package/dist/ui.html +324 -0
- package/package.json +193 -4
- package/src/icon.svg +6 -0
- package/src/ui.html +324 -0
package/src/ui.html
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover" />
|
|
6
|
+
<!-- node-agent:i18n-resource -->
|
|
7
|
+
<script type="module" src="/sdk/i18n-client.js"></script>
|
|
8
|
+
<script>if (self !== top) document.documentElement.classList.add('framed')</script>
|
|
9
|
+
<style>
|
|
10
|
+
:root { color-scheme: light dark; --surface:#fff; --soft:#f6f7f9; --text:#202124; --muted:#6b7280; --line:#d9dde5; --accent:#2563eb; --accent-fill:#2563eb; }
|
|
11
|
+
@media (prefers-color-scheme:dark) { :root { --surface:#17191d; --soft:#202329; --text:#eef0f4; --muted:#a5abb5; --line:#363b45; --accent:#70a5ff; --accent-fill:#2563eb; } }
|
|
12
|
+
* { box-sizing:border-box; }
|
|
13
|
+
html, body { width:100%; height:100%; margin:0; overflow:hidden; background:var(--soft); color:var(--text); font:14px system-ui,sans-serif; }
|
|
14
|
+
main { height:100%; overflow:auto; padding:24px clamp(14px,4vw,36px); }
|
|
15
|
+
.shell { display:grid; grid-template-columns:minmax(180px,260px) minmax(0,620px); gap:24px; max-width:920px; margin:auto; }
|
|
16
|
+
.card { padding:18px; border:1px solid var(--line); border-radius:14px; background:var(--surface); }
|
|
17
|
+
h1,h2 { margin:0 0 14px; font-size:17px; }
|
|
18
|
+
.list,.form { display:grid; gap:10px; }
|
|
19
|
+
.item { display:flex; justify-content:space-between; min-height:40px; padding:8px 10px; border:1px solid var(--line); border-radius:9px; background:var(--soft); color:var(--text); }
|
|
20
|
+
.item.selected { border-color:var(--accent); }
|
|
21
|
+
label { display:grid; gap:5px; color:var(--muted); font-size:12px; }
|
|
22
|
+
/* `hidden` is a UA rule and loses to the grid above, so hiding a field needs a say here. */
|
|
23
|
+
[hidden] { display:none !important; }
|
|
24
|
+
input, select { width:100%; min-height:40px; padding:8px 10px; border:1px solid var(--line); border-radius:9px; background:var(--soft); color:var(--text); font:inherit; }
|
|
25
|
+
.actions { display:flex; flex-wrap:wrap; gap:8px; }
|
|
26
|
+
button { min-height:36px; padding:0 13px; border:0; border-radius:9px; background:var(--accent-fill); color:white; cursor:pointer; }
|
|
27
|
+
button.secondary { border:1px solid var(--line); background:var(--soft); color:var(--text); }
|
|
28
|
+
button.danger { background:#c62f35; }
|
|
29
|
+
button:disabled { opacity:.5; cursor:default; }
|
|
30
|
+
.feedback { min-height:1.5em; font-size:12px; }
|
|
31
|
+
.error { color:#e5484d; }
|
|
32
|
+
.success { color:#16803a; }
|
|
33
|
+
.note { color:var(--muted); font-size:11px; }
|
|
34
|
+
@media (max-width: 640px), (orientation: landscape) and (max-height: 480px) {
|
|
35
|
+
body { height:100dvh; }
|
|
36
|
+
main { min-height:0; padding:12px 12px calc(12px + env(safe-area-inset-bottom)); }
|
|
37
|
+
.shell { grid-template-columns:1fr; gap:12px; }
|
|
38
|
+
button { min-height:44px; }
|
|
39
|
+
/* A field and a provider row are thumb targets too, not only the buttons. */
|
|
40
|
+
input, select, .item { min-height:44px; }
|
|
41
|
+
}
|
|
42
|
+
:root.framed body { height:100%; min-height:0; }
|
|
43
|
+
</style>
|
|
44
|
+
</head>
|
|
45
|
+
<body>
|
|
46
|
+
<main>
|
|
47
|
+
<div class="shell">
|
|
48
|
+
<aside class="card">
|
|
49
|
+
<div id="provider-list" class="list"></div>
|
|
50
|
+
<button id="provider-new" class="secondary" type="button" data-text-key="new">New provider</button>
|
|
51
|
+
</aside>
|
|
52
|
+
<section class="card">
|
|
53
|
+
<h2 data-text-key="heading">LLM provider</h2>
|
|
54
|
+
<form id="provider-form" class="form" novalidate>
|
|
55
|
+
<label><span data-text-key="form.name">Name</span><input id="provider-name" required maxlength="64" autocomplete="off" /></label>
|
|
56
|
+
<label><span data-text-key="form.protocol">Protocol</span><select id="provider-type">
|
|
57
|
+
<option value="openai" data-text-key="type.openai">OpenAI-compatible</option>
|
|
58
|
+
<option value="deepseek" data-text-key="type.deepseek">DeepSeek</option>
|
|
59
|
+
<option value="anthropic" data-text-key="type.anthropic">Anthropic (Claude)</option>
|
|
60
|
+
<option value="responses" data-text-key="type.responses">OpenAI (Responses API)</option>
|
|
61
|
+
</select></label>
|
|
62
|
+
<label><span data-text-key="form.model">Model</span><input id="provider-model" required autocomplete="off" /></label>
|
|
63
|
+
<label><span data-text-key="form.baseUrl">Base URL</span><input id="provider-url" autocomplete="url" /></label>
|
|
64
|
+
<label><span data-text-key="form.apiKey">API key</span><input id="provider-key" type="password" autocomplete="new-password" placeholder="API key" data-text-placeholder-key="form.keyNew" /></label>
|
|
65
|
+
<label id="provider-organization-field"><span data-text-key="form.organization">Organization</span><input id="provider-organization" autocomplete="off" /></label>
|
|
66
|
+
<label><span data-text-key="form.timeout">Timeout (seconds)</span><input id="provider-timeout" type="number" min="0" step="any" /></label>
|
|
67
|
+
<label><span data-text-key="form.thinking">Thinking effort</span><select id="provider-thinking">
|
|
68
|
+
<option value="" data-text-key="thinking.default">Provider default</option>
|
|
69
|
+
<option value="none" data-text-key="thinking.none">none</option>
|
|
70
|
+
<option value="minimal" data-text-key="thinking.minimal">minimal</option>
|
|
71
|
+
<option value="low" data-text-key="thinking.low">low</option>
|
|
72
|
+
<option value="medium" data-text-key="thinking.medium">medium</option>
|
|
73
|
+
<option value="high" data-text-key="thinking.high">high</option>
|
|
74
|
+
<option value="xhigh" data-text-key="thinking.xhigh">very high</option>
|
|
75
|
+
<option value="max" data-text-key="thinking.max">max</option>
|
|
76
|
+
<option value="custom" data-text-key="thinking.custom">Custom…</option>
|
|
77
|
+
</select></label>
|
|
78
|
+
<label id="provider-thinking-custom-field" hidden><span data-text-key="form.thinkingCustom">Custom effort</span><input id="provider-thinking-custom" autocomplete="off" /></label>
|
|
79
|
+
<div id="provider-error" class="feedback error" role="alert"></div>
|
|
80
|
+
<div id="provider-status" class="feedback success" role="status" aria-live="polite"></div>
|
|
81
|
+
<div class="actions">
|
|
82
|
+
<button type="submit" data-text-key="form.save">Save</button>
|
|
83
|
+
<button id="provider-test" class="secondary" type="button" data-text-key="form.test">Test</button>
|
|
84
|
+
<button id="provider-delete" class="danger" type="button" data-text-key="form.delete">Delete</button>
|
|
85
|
+
</div>
|
|
86
|
+
<div id="provider-hint" class="note"></div>
|
|
87
|
+
<div id="provider-note" class="note"></div>
|
|
88
|
+
</form>
|
|
89
|
+
</section>
|
|
90
|
+
</div>
|
|
91
|
+
</main>
|
|
92
|
+
<script type="module">
|
|
93
|
+
// The page's words live in its own files — src/i18n/en.json and src/i18n/zh-CN.json. The node that
|
|
94
|
+
// draws the page embeds them as one JSON script tag, and the SDK turns each key into a `Text`, so
|
|
95
|
+
// nothing here re-states a sentence: `data-text-key` marks the markup, and a sentence this script
|
|
96
|
+
// builds itself goes through `t`.
|
|
97
|
+
import { currentLocale, resourceFromDocument, resourceTexts } from '/sdk/i18n-client.js';
|
|
98
|
+
|
|
99
|
+
const RESOURCE = resourceFromDocument();
|
|
100
|
+
const T = RESOURCE === null ? {} : resourceTexts(RESOURCE);
|
|
101
|
+
|
|
102
|
+
/** The sentence under one key, in the language the page is drawn in. */
|
|
103
|
+
const t = (key, params) => T[key]?.get(currentLocale(), params) ?? key;
|
|
104
|
+
|
|
105
|
+
(() => {
|
|
106
|
+
const INJECTED = "__NODE__";
|
|
107
|
+
const NODE = INJECTED.startsWith('__') ? location.pathname.split('/')[2] || 'provider' : INJECTED;
|
|
108
|
+
const byId = (id) => document.getElementById(id);
|
|
109
|
+
const list = byId('provider-list');
|
|
110
|
+
const form = byId('provider-form');
|
|
111
|
+
const name = byId('provider-name');
|
|
112
|
+
const model = byId('provider-model');
|
|
113
|
+
const url = byId('provider-url');
|
|
114
|
+
const key = byId('provider-key');
|
|
115
|
+
const type = byId('provider-type');
|
|
116
|
+
const organization = byId('provider-organization');
|
|
117
|
+
const organizationField = byId('provider-organization-field');
|
|
118
|
+
const hint = byId('provider-hint');
|
|
119
|
+
const timeout = byId('provider-timeout');
|
|
120
|
+
const thinking = byId('provider-thinking');
|
|
121
|
+
const thinkingCustom = byId('provider-thinking-custom');
|
|
122
|
+
const thinkingCustomField = byId('provider-thinking-custom-field');
|
|
123
|
+
const THINKING_PRESETS = ['', 'none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
|
|
124
|
+
const CUSTOM_THINKING = 'custom';
|
|
125
|
+
const error = byId('provider-error');
|
|
126
|
+
const status = byId('provider-status');
|
|
127
|
+
const note = byId('provider-note');
|
|
128
|
+
const remove = byId('provider-delete');
|
|
129
|
+
let state = null;
|
|
130
|
+
let selected = null;
|
|
131
|
+
|
|
132
|
+
// What each protocol asks of the form: the endpoint somebody is most likely to have, and the
|
|
133
|
+
// sentence about it they would otherwise have to guess — a resource key, so it is drawn in the
|
|
134
|
+
// reader's language and redrawn when that language changes.
|
|
135
|
+
const TYPES = {
|
|
136
|
+
openai: {
|
|
137
|
+
url:'https://api.openai.com/v1',
|
|
138
|
+
hint:'hint.openai',
|
|
139
|
+
},
|
|
140
|
+
deepseek: {
|
|
141
|
+
url:'https://api.deepseek.com',
|
|
142
|
+
hint:'hint.deepseek',
|
|
143
|
+
},
|
|
144
|
+
anthropic: {
|
|
145
|
+
url:'https://api.anthropic.com',
|
|
146
|
+
hint:'hint.anthropic',
|
|
147
|
+
},
|
|
148
|
+
responses: {
|
|
149
|
+
url:'https://api.openai.com/v1',
|
|
150
|
+
hint:'hint.responses',
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
const protocol = () => (TYPES[type.value] ? type.value : 'openai');
|
|
154
|
+
|
|
155
|
+
function applyThinking() {
|
|
156
|
+
thinkingCustomField.hidden = thinking.value !== CUSTOM_THINKING;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function applyType() {
|
|
160
|
+
organizationField.hidden = protocol() !== 'openai';
|
|
161
|
+
url.placeholder = TYPES[protocol()].url;
|
|
162
|
+
// The key travels on the element, so a language change redraws this sentence in place.
|
|
163
|
+
const hintKey = TYPES[protocol()].hint;
|
|
164
|
+
hint.dataset.textKey = hintKey;
|
|
165
|
+
hint.textContent = t(hintKey);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async function post(tool, args) {
|
|
169
|
+
const response = await fetch('/call', {
|
|
170
|
+
method:'POST', headers:{'content-type':'application/json'},
|
|
171
|
+
body:JSON.stringify({tool, args}),
|
|
172
|
+
});
|
|
173
|
+
return response.json();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async function call(args) {
|
|
177
|
+
error.textContent = '';
|
|
178
|
+
status.textContent = '';
|
|
179
|
+
const reply = await post(`${NODE}.providers`, args);
|
|
180
|
+
if (!reply.ok) { error.textContent = reply.error || t('error.call'); return null; }
|
|
181
|
+
state = reply.value;
|
|
182
|
+
return state;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function show(provider) {
|
|
186
|
+
selected = provider?.name ?? null;
|
|
187
|
+
const config = provider?.config ?? {};
|
|
188
|
+
name.value = provider?.name ?? '';
|
|
189
|
+
name.readOnly = Boolean(provider);
|
|
190
|
+
type.value = TYPES[config.type] ? config.type : 'openai';
|
|
191
|
+
model.value = config.model_name ?? '';
|
|
192
|
+
url.value = config.base_url ?? '';
|
|
193
|
+
key.value = '';
|
|
194
|
+
// Two sentences, one field: a saved key is kept by leaving the field blank, a new row needs one.
|
|
195
|
+
const keyKey = provider?.has_api_key ? 'form.keyKeep' : 'form.keyNew';
|
|
196
|
+
key.dataset.textPlaceholderKey = keyKey;
|
|
197
|
+
key.placeholder = t(keyKey);
|
|
198
|
+
organization.value = config.organization ?? '';
|
|
199
|
+
timeout.value = config.timeout ?? '';
|
|
200
|
+
const effort = config.thinking_effort ?? '';
|
|
201
|
+
if (THINKING_PRESETS.includes(effort)) {
|
|
202
|
+
thinking.value = effort;
|
|
203
|
+
thinkingCustom.value = '';
|
|
204
|
+
} else {
|
|
205
|
+
thinking.value = CUSTOM_THINKING;
|
|
206
|
+
thinkingCustom.value = effort;
|
|
207
|
+
}
|
|
208
|
+
applyThinking();
|
|
209
|
+
remove.disabled = !provider || (state?.providers.length ?? 0) <= 1;
|
|
210
|
+
applyType();
|
|
211
|
+
render();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function render() {
|
|
215
|
+
list.replaceChildren();
|
|
216
|
+
for (const provider of state?.providers ?? []) {
|
|
217
|
+
const button = document.createElement('button');
|
|
218
|
+
button.type = 'button';
|
|
219
|
+
button.className = `item secondary${provider.name === selected ? ' selected' : ''}`;
|
|
220
|
+
button.textContent = provider.name;
|
|
221
|
+
button.addEventListener('click', () => show(provider));
|
|
222
|
+
list.append(button);
|
|
223
|
+
}
|
|
224
|
+
const noteKey = state?.persistent ? 'note.persistent' : 'note.volatile';
|
|
225
|
+
note.dataset.textKey = noteKey;
|
|
226
|
+
note.textContent = t(noteKey);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async function load() {
|
|
230
|
+
if (!(await call({action:'list'}))) return;
|
|
231
|
+
show(state.providers.find((item) => item.name === selected) ?? state.providers[0]);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
byId('provider-new').addEventListener('click', () => show(null));
|
|
235
|
+
type.addEventListener('change', applyType);
|
|
236
|
+
thinking.addEventListener('change', applyThinking);
|
|
237
|
+
const save = form.querySelector('button[type="submit"]');
|
|
238
|
+
form.addEventListener('submit', async (event) => {
|
|
239
|
+
event.preventDefault();
|
|
240
|
+
const timeoutValue = timeout.value.trim();
|
|
241
|
+
const savedName = name.value.trim();
|
|
242
|
+
const savedModel = model.value.trim();
|
|
243
|
+
// Checked here rather than by the browser: `required` on a field the page did not fill blocks
|
|
244
|
+
// the submit event itself, so the button looks broken instead of saying what is missing.
|
|
245
|
+
if (!savedName || !savedModel) {
|
|
246
|
+
error.textContent = t('error.required');
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
const savedUrl = url.value.trim();
|
|
250
|
+
// Checked here too: a scheme-less address is a gateway typed from memory, and the request it
|
|
251
|
+
// would produce fails later with something that does not name the field.
|
|
252
|
+
if (savedUrl && !/^https?:\/\//i.test(savedUrl)) {
|
|
253
|
+
error.textContent = t('error.baseUrl');
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
save.disabled = true;
|
|
257
|
+
try {
|
|
258
|
+
const saved = await call({
|
|
259
|
+
action:'save', name:savedName,
|
|
260
|
+
config:{type:protocol(), model_name:savedModel, base_url:savedUrl || null,
|
|
261
|
+
api_key:key.value || null,
|
|
262
|
+
organization:protocol() === 'openai' ? organization.value.trim() || null : null,
|
|
263
|
+
timeout:timeoutValue === '' ? null : Number(timeoutValue),
|
|
264
|
+
thinking_effort:(thinking.value === CUSTOM_THINKING
|
|
265
|
+
? thinkingCustom.value.trim()
|
|
266
|
+
: thinking.value) || null},
|
|
267
|
+
});
|
|
268
|
+
if (!saved) return;
|
|
269
|
+
show(state.providers.find((item) => item.name === savedName));
|
|
270
|
+
status.textContent = t('status.saved', { name: savedName });
|
|
271
|
+
} catch (failure) {
|
|
272
|
+
// A dropped request or a busy node: say so, or the click looks like it did nothing.
|
|
273
|
+
error.textContent = String(failure?.message || failure);
|
|
274
|
+
} finally {
|
|
275
|
+
save.disabled = false;
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
byId('provider-test').addEventListener('click', async (event) => {
|
|
279
|
+
error.textContent = '';
|
|
280
|
+
status.textContent = '';
|
|
281
|
+
if (!selected) {
|
|
282
|
+
error.textContent = t('error.selectFirst');
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const button = event.currentTarget;
|
|
286
|
+
button.disabled = true;
|
|
287
|
+
button.textContent = t('test.testing');
|
|
288
|
+
status.textContent = t('test.testing');
|
|
289
|
+
try {
|
|
290
|
+
// The saved row, not the form: an edit nobody saved is not what this button is asked about.
|
|
291
|
+
const reply = await post(`${NODE}.chat`, {
|
|
292
|
+
name: selected,
|
|
293
|
+
messages: [{role:'user', content:'Reply with the single word OK.'}],
|
|
294
|
+
max_completion_tokens: 512,
|
|
295
|
+
});
|
|
296
|
+
if (!reply.ok) {
|
|
297
|
+
error.textContent = reply.error || t('error.callFailed');
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
const content = reply.value?.message?.content;
|
|
301
|
+
const text = typeof content === 'string' ? content.trim() : '';
|
|
302
|
+
const usage = reply.value?.usage;
|
|
303
|
+
const counts = usage
|
|
304
|
+
? t('test.usage', { prompt: usage.prompt_tokens, completion: usage.completion_tokens })
|
|
305
|
+
: '';
|
|
306
|
+
status.textContent = text
|
|
307
|
+
? t('test.ok', { reply: text, usage: counts, name: selected })
|
|
308
|
+
: t('test.empty', { usage: counts, name: selected });
|
|
309
|
+
} catch (failure) {
|
|
310
|
+
error.textContent = String(failure?.message || failure);
|
|
311
|
+
} finally {
|
|
312
|
+
button.disabled = false;
|
|
313
|
+
button.textContent = t('form.test');
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
remove.addEventListener('click', async () => {
|
|
317
|
+
if (!selected || !confirm(t('confirm.delete', { name: selected }))) return;
|
|
318
|
+
if (await call({action:'delete', name:selected})) show(state.providers[0]);
|
|
319
|
+
});
|
|
320
|
+
void load();
|
|
321
|
+
})();
|
|
322
|
+
</script>
|
|
323
|
+
</body>
|
|
324
|
+
</html>
|