@nevescloud/pip 3.8.0 → 3.8.2
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/package.json +1 -1
- package/providers/anthropic.esm.js +15 -8
- package/runtime.esm.js +15 -11
package/package.json
CHANGED
|
@@ -23,8 +23,14 @@ export function anthropic({
|
|
|
23
23
|
effort,
|
|
24
24
|
cacheControl,
|
|
25
25
|
extraHeaders = {},
|
|
26
|
+
// When true, the host is routing through a proxy/bridge that injects
|
|
27
|
+
// auth + version headers server-side. The provider then sends only
|
|
28
|
+
// content-type; this avoids the CORS preflight burden of x-api-key /
|
|
29
|
+
// anthropic-version / anthropic-dangerous-direct-browser-access on
|
|
30
|
+
// proxies that haven't allowlisted those headers.
|
|
31
|
+
proxied = false,
|
|
26
32
|
} = {}) {
|
|
27
|
-
if (!apiKey) throw new Error('anthropic provider: apiKey is required');
|
|
33
|
+
if (!proxied && !apiKey) throw new Error('anthropic provider: apiKey is required (or set proxied: true when routing through a bridge that injects auth)');
|
|
28
34
|
|
|
29
35
|
return async function* anthropicProvider({ messages, tools, system, signal }) {
|
|
30
36
|
const body = {
|
|
@@ -45,15 +51,16 @@ export function anthropic({
|
|
|
45
51
|
if (effort) body.output_config = { effort };
|
|
46
52
|
if (cacheControl) body.cache_control = { type: cacheControl };
|
|
47
53
|
|
|
54
|
+
const headers = { 'content-type': 'application/json', ...extraHeaders };
|
|
55
|
+
if (!proxied) {
|
|
56
|
+
headers['x-api-key'] = apiKey;
|
|
57
|
+
headers['anthropic-version'] = ANTHROPIC_VERSION;
|
|
58
|
+
headers['anthropic-dangerous-direct-browser-access'] = 'true';
|
|
59
|
+
}
|
|
60
|
+
|
|
48
61
|
const res = await fetch(`${baseUrl}/v1/messages`, {
|
|
49
62
|
method: 'POST',
|
|
50
|
-
headers
|
|
51
|
-
'content-type': 'application/json',
|
|
52
|
-
'x-api-key': apiKey,
|
|
53
|
-
'anthropic-version': ANTHROPIC_VERSION,
|
|
54
|
-
'anthropic-dangerous-direct-browser-access': 'true',
|
|
55
|
-
...extraHeaders,
|
|
56
|
-
},
|
|
63
|
+
headers,
|
|
57
64
|
body: JSON.stringify(body),
|
|
58
65
|
signal,
|
|
59
66
|
});
|
package/runtime.esm.js
CHANGED
|
@@ -236,20 +236,19 @@ export function createRuntime({
|
|
|
236
236
|
return { clearedUI: true };
|
|
237
237
|
}
|
|
238
238
|
if (cmd === 'tools') {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
239
|
+
// The slash autocomplete dropdown enumerates registered tools via
|
|
240
|
+
// complete() — listing them as a chat turn duplicates that surface
|
|
241
|
+
// and pollutes history. Reopen the dropdown in arg-mode instead;
|
|
242
|
+
// same primitive /help and /model adopted via openCompletions.
|
|
243
|
+
if (registeredTools.size === 0) return { reply: 'No tools registered.' };
|
|
244
|
+
return { openCompletions: true };
|
|
243
245
|
}
|
|
244
246
|
if (cmd === 'model' && models.length) {
|
|
245
247
|
const arg = args.trim();
|
|
246
248
|
if (!arg) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
.map((m) => `\`${m.name}\``);
|
|
251
|
-
const tail = others.length ? ` Switch with \`/model <name>\` — try ${others.join(', ')}.` : '';
|
|
252
|
-
return { reply: `Current model: ${cur}.${tail}` };
|
|
249
|
+
// Same sub-menu pattern as /tools — open the dropdown for the user
|
|
250
|
+
// to pick a model, instead of logging "Current model: …" to chat.
|
|
251
|
+
return { openCompletions: true };
|
|
253
252
|
}
|
|
254
253
|
const target = models.find((m) => m.name.toLowerCase() === arg.toLowerCase());
|
|
255
254
|
if (!target) {
|
|
@@ -294,7 +293,12 @@ export function createRuntime({
|
|
|
294
293
|
function builtinSlash() {
|
|
295
294
|
const out = [
|
|
296
295
|
{ name: 'clear', description: 'reset conversation' },
|
|
297
|
-
{
|
|
296
|
+
{
|
|
297
|
+
name: 'tools',
|
|
298
|
+
description: 'list registered tools',
|
|
299
|
+
complete: (partial) => Array.from(registeredTools.keys())
|
|
300
|
+
.filter((n) => n.toLowerCase().startsWith(partial.toLowerCase())),
|
|
301
|
+
},
|
|
298
302
|
];
|
|
299
303
|
if (models.length) {
|
|
300
304
|
out.push({
|