notsleep 1.0.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/.env.example +117 -0
- package/LICENSE +21 -0
- package/README.md +341 -0
- package/dashboard/index.html +893 -0
- package/dist/agent.d.ts +162 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +1064 -0
- package/dist/agent.js.map +1 -0
- package/dist/api.d.ts +10 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +39 -0
- package/dist/api.js.map +1 -0
- package/dist/checkpoint.d.ts +52 -0
- package/dist/checkpoint.d.ts.map +1 -0
- package/dist/checkpoint.js +234 -0
- package/dist/checkpoint.js.map +1 -0
- package/dist/config.d.ts +24 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +265 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +15 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +237 -0
- package/dist/context.js.map +1 -0
- package/dist/cost.d.ts +26 -0
- package/dist/cost.d.ts.map +1 -0
- package/dist/cost.js +161 -0
- package/dist/cost.js.map +1 -0
- package/dist/dashboard.d.ts +96 -0
- package/dist/dashboard.d.ts.map +1 -0
- package/dist/dashboard.js +292 -0
- package/dist/dashboard.js.map +1 -0
- package/dist/fileconfig.d.ts +129 -0
- package/dist/fileconfig.d.ts.map +1 -0
- package/dist/fileconfig.js +391 -0
- package/dist/fileconfig.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +882 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +9 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +221 -0
- package/dist/init.js.map +1 -0
- package/dist/logger.d.ts +33 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +150 -0
- package/dist/logger.js.map +1 -0
- package/dist/modelsdev.d.ts +63 -0
- package/dist/modelsdev.d.ts.map +1 -0
- package/dist/modelsdev.js +265 -0
- package/dist/modelsdev.js.map +1 -0
- package/dist/parallel.d.ts +54 -0
- package/dist/parallel.d.ts.map +1 -0
- package/dist/parallel.js +139 -0
- package/dist/parallel.js.map +1 -0
- package/dist/pool.d.ts +17 -0
- package/dist/pool.d.ts.map +1 -0
- package/dist/pool.js +53 -0
- package/dist/pool.js.map +1 -0
- package/dist/provider.d.ts +60 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +396 -0
- package/dist/provider.js.map +1 -0
- package/dist/registry.d.ts +60 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +153 -0
- package/dist/registry.js.map +1 -0
- package/dist/safety.d.ts +21 -0
- package/dist/safety.d.ts.map +1 -0
- package/dist/safety.js +118 -0
- package/dist/safety.js.map +1 -0
- package/dist/schema.d.ts +9 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +166 -0
- package/dist/schema.js.map +1 -0
- package/dist/test-dashboard.d.ts +5 -0
- package/dist/test-dashboard.d.ts.map +1 -0
- package/dist/test-dashboard.js +202 -0
- package/dist/test-dashboard.js.map +1 -0
- package/dist/tools.d.ts +27 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +1212 -0
- package/dist/tools.js.map +1 -0
- package/dist/types.d.ts +180 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +14 -0
- package/dist/types.js.map +1 -0
- package/dist/worktree.d.ts +50 -0
- package/dist/worktree.d.ts.map +1 -0
- package/dist/worktree.js +186 -0
- package/dist/worktree.js.map +1 -0
- package/package.json +67 -0
package/dist/provider.js
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// NotSleep - Unified LLM Provider Abstraction
|
|
4
|
+
// ============================================================
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.LLMProvider = void 0;
|
|
10
|
+
const openai_1 = __importDefault(require("openai"));
|
|
11
|
+
const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
|
|
12
|
+
/**
|
|
13
|
+
* Converts our ToolDefinition[] to provider-specific tool format.
|
|
14
|
+
* Handles retries with exponential backoff.
|
|
15
|
+
* Normalizes responses to a unified LLMResponse format.
|
|
16
|
+
*
|
|
17
|
+
* Supports two endpoints — primary (chat) and an optional cheaper small model
|
|
18
|
+
* (chatSmall) — which may be different providers entirely. Clients are built
|
|
19
|
+
* lazily and cached per (baseURL, apiKey), so a mixed setup (e.g. Anthropic
|
|
20
|
+
* primary + OpenAI small) works without extra wiring.
|
|
21
|
+
*/
|
|
22
|
+
class LLMProvider {
|
|
23
|
+
config;
|
|
24
|
+
logger;
|
|
25
|
+
primary;
|
|
26
|
+
small;
|
|
27
|
+
openaiClients = new Map();
|
|
28
|
+
anthropicClients = new Map();
|
|
29
|
+
constructor(config, logger) {
|
|
30
|
+
this.config = config;
|
|
31
|
+
this.logger = logger;
|
|
32
|
+
this.primary = this.endpointFromConfig();
|
|
33
|
+
if (config.smallModel) {
|
|
34
|
+
this.small = {
|
|
35
|
+
type: config.smallModel.provider,
|
|
36
|
+
model: config.smallModel.model,
|
|
37
|
+
apiKey: config.smallModel.apiKey,
|
|
38
|
+
baseURL: config.smallModel.baseURL,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** Build the primary endpoint from the resolved config blocks. */
|
|
43
|
+
endpointFromConfig() {
|
|
44
|
+
if (this.config.provider === 'openai') {
|
|
45
|
+
const o = this.config.openai;
|
|
46
|
+
return { type: 'openai', model: o.model, apiKey: o.apiKey, baseURL: o.baseURL };
|
|
47
|
+
}
|
|
48
|
+
const a = this.config.anthropic;
|
|
49
|
+
return { type: 'anthropic', model: a.model, apiKey: a.apiKey, baseURL: a.baseURL };
|
|
50
|
+
}
|
|
51
|
+
getOpenAIClient(ep) {
|
|
52
|
+
const key = `${ep.baseURL || ''}|${ep.apiKey}`;
|
|
53
|
+
let client = this.openaiClients.get(key);
|
|
54
|
+
if (!client) {
|
|
55
|
+
client = new openai_1.default({ apiKey: ep.apiKey, baseURL: ep.baseURL });
|
|
56
|
+
this.openaiClients.set(key, client);
|
|
57
|
+
}
|
|
58
|
+
return client;
|
|
59
|
+
}
|
|
60
|
+
getAnthropicClient(ep) {
|
|
61
|
+
const key = `${ep.baseURL || ''}|${ep.apiKey}`;
|
|
62
|
+
let client = this.anthropicClients.get(key);
|
|
63
|
+
if (!client) {
|
|
64
|
+
client = new sdk_1.default({ apiKey: ep.apiKey, baseURL: ep.baseURL });
|
|
65
|
+
this.anthropicClients.set(key, client);
|
|
66
|
+
}
|
|
67
|
+
return client;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Send messages to the PRIMARY model and get a response.
|
|
71
|
+
* Automatically retries on transient errors with exponential backoff.
|
|
72
|
+
*/
|
|
73
|
+
async chat(messages, tools, opts) {
|
|
74
|
+
return this.callEndpoint(this.primary, messages, tools, opts);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Send messages to the SMALL model (if configured), else the primary. Used
|
|
78
|
+
* for the agent's own internal calls — context summarization and follow-up
|
|
79
|
+
* task generation — so they run on a cheaper model when one is set.
|
|
80
|
+
*/
|
|
81
|
+
async chatSmall(messages, tools, opts) {
|
|
82
|
+
return this.callEndpoint(this.small ?? this.primary, messages, tools, opts);
|
|
83
|
+
}
|
|
84
|
+
/** True when a distinct small model is configured. */
|
|
85
|
+
hasSmallModel() {
|
|
86
|
+
return this.small !== undefined;
|
|
87
|
+
}
|
|
88
|
+
async callEndpoint(ep, messages, tools, opts) {
|
|
89
|
+
let lastError = null;
|
|
90
|
+
// Allow the caller to bound retries/backoff. Used by the summarization
|
|
91
|
+
// call so a flaky upstream (e.g. repeated 524s) can't block a single
|
|
92
|
+
// iteration for ~20 minutes; it fails fast and falls back to truncation.
|
|
93
|
+
const maxRetries = opts?.maxRetries ?? this.config.maxRetries;
|
|
94
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
95
|
+
try {
|
|
96
|
+
if (ep.type === 'openai') {
|
|
97
|
+
return await this.chatOpenAI(ep, messages, tools);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
return await this.chatAnthropic(ep, messages, tools);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
lastError = error;
|
|
105
|
+
const isRetryable = this.isRetryableError(error);
|
|
106
|
+
if (!isRetryable || attempt === maxRetries) {
|
|
107
|
+
throw this.enhanceError(error, ep);
|
|
108
|
+
}
|
|
109
|
+
let delay = this.calculateBackoff(attempt, error);
|
|
110
|
+
// Clamp the delay when the caller asked for a cap (even if the server
|
|
111
|
+
// sent a large Retry-After), so a bounded call stays bounded.
|
|
112
|
+
if (opts?.maxDelayMs !== undefined) {
|
|
113
|
+
delay = Math.min(delay, opts.maxDelayMs);
|
|
114
|
+
}
|
|
115
|
+
this.logger.warn(`API call failed (attempt ${attempt + 1}/${maxRetries + 1}): ${error.message}. ` +
|
|
116
|
+
`Retrying in ${(delay / 1000).toFixed(1)}s...`);
|
|
117
|
+
await this.sleep(delay);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
throw lastError || new Error('All retry attempts exhausted');
|
|
121
|
+
}
|
|
122
|
+
// ─── OpenAI Implementation ───────────────────────────────
|
|
123
|
+
async chatOpenAI(ep, messages, tools) {
|
|
124
|
+
const client = this.getOpenAIClient(ep);
|
|
125
|
+
const openaiMessages = messages.map((m) => this.toOpenAIMessage(m));
|
|
126
|
+
const openaiTools = tools
|
|
127
|
+
.filter((t) => t.name !== 'task_complete') // handled separately below
|
|
128
|
+
.map((t) => this.toOpenAITool(t));
|
|
129
|
+
// Always include task_complete
|
|
130
|
+
const taskCompleteTool = tools.find((t) => t.name === 'task_complete');
|
|
131
|
+
if (taskCompleteTool) {
|
|
132
|
+
openaiTools.push(this.toOpenAITool(taskCompleteTool));
|
|
133
|
+
}
|
|
134
|
+
const params = {
|
|
135
|
+
model: ep.model,
|
|
136
|
+
messages: openaiMessages,
|
|
137
|
+
temperature: 0.2,
|
|
138
|
+
max_tokens: 16384,
|
|
139
|
+
};
|
|
140
|
+
if (openaiTools.length > 0) {
|
|
141
|
+
params.tools = openaiTools;
|
|
142
|
+
params.tool_choice = 'auto';
|
|
143
|
+
}
|
|
144
|
+
const response = await client.chat.completions.create(params);
|
|
145
|
+
const choice = response.choices[0];
|
|
146
|
+
const toolCalls = (choice.message.tool_calls || []).map((tc) => ({
|
|
147
|
+
id: tc.id,
|
|
148
|
+
type: 'function',
|
|
149
|
+
function: {
|
|
150
|
+
name: tc.function.name,
|
|
151
|
+
arguments: tc.function.arguments,
|
|
152
|
+
},
|
|
153
|
+
}));
|
|
154
|
+
return {
|
|
155
|
+
content: choice.message.content,
|
|
156
|
+
tool_calls: toolCalls,
|
|
157
|
+
usage: {
|
|
158
|
+
prompt_tokens: response.usage?.prompt_tokens || 0,
|
|
159
|
+
completion_tokens: response.usage?.completion_tokens || 0,
|
|
160
|
+
total_tokens: response.usage?.total_tokens || 0,
|
|
161
|
+
},
|
|
162
|
+
finish_reason: choice.finish_reason || 'stop',
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
toOpenAIMessage(msg) {
|
|
166
|
+
if (msg.role === 'tool') {
|
|
167
|
+
return {
|
|
168
|
+
role: 'tool',
|
|
169
|
+
content: msg.content,
|
|
170
|
+
tool_call_id: msg.tool_call_id,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
if (msg.role === 'assistant' && msg.tool_calls && msg.tool_calls.length > 0) {
|
|
174
|
+
return {
|
|
175
|
+
role: 'assistant',
|
|
176
|
+
content: msg.content,
|
|
177
|
+
tool_calls: msg.tool_calls.map((tc) => ({
|
|
178
|
+
id: tc.id,
|
|
179
|
+
type: 'function',
|
|
180
|
+
function: {
|
|
181
|
+
name: tc.function.name,
|
|
182
|
+
arguments: tc.function.arguments,
|
|
183
|
+
},
|
|
184
|
+
})),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
return { role: msg.role, content: msg.content };
|
|
188
|
+
}
|
|
189
|
+
toOpenAITool(tool) {
|
|
190
|
+
return {
|
|
191
|
+
type: 'function',
|
|
192
|
+
function: {
|
|
193
|
+
name: tool.name,
|
|
194
|
+
description: tool.description,
|
|
195
|
+
parameters: tool.parameters,
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
// ─── Anthropic Implementation ────────────────────────────
|
|
200
|
+
async chatAnthropic(ep, messages, tools) {
|
|
201
|
+
const client = this.getAnthropicClient(ep);
|
|
202
|
+
// Anthropic separates system prompt from messages
|
|
203
|
+
const systemPrompt = messages.find((m) => m.role === 'system')?.content || '';
|
|
204
|
+
const nonSystemMessages = messages.filter((m) => m.role !== 'system');
|
|
205
|
+
const anthropicMessages = this.toAnthropicMessages(nonSystemMessages);
|
|
206
|
+
const anthropicTools = tools.map((t) => this.toAnthropicTool(t));
|
|
207
|
+
const params = {
|
|
208
|
+
model: ep.model,
|
|
209
|
+
max_tokens: 16384,
|
|
210
|
+
system: systemPrompt,
|
|
211
|
+
messages: anthropicMessages,
|
|
212
|
+
};
|
|
213
|
+
if (anthropicTools.length > 0) {
|
|
214
|
+
params.tools = anthropicTools;
|
|
215
|
+
}
|
|
216
|
+
const response = await client.messages.create(params);
|
|
217
|
+
// Parse Anthropic response into unified format
|
|
218
|
+
let content = null;
|
|
219
|
+
const toolCalls = [];
|
|
220
|
+
for (const block of response.content) {
|
|
221
|
+
if (block.type === 'text') {
|
|
222
|
+
content = (content || '') + block.text;
|
|
223
|
+
}
|
|
224
|
+
else if (block.type === 'tool_use') {
|
|
225
|
+
toolCalls.push({
|
|
226
|
+
id: block.id,
|
|
227
|
+
type: 'function',
|
|
228
|
+
function: {
|
|
229
|
+
name: block.name,
|
|
230
|
+
arguments: JSON.stringify(block.input),
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
content,
|
|
237
|
+
tool_calls: toolCalls,
|
|
238
|
+
usage: {
|
|
239
|
+
prompt_tokens: response.usage?.input_tokens || 0,
|
|
240
|
+
completion_tokens: response.usage?.output_tokens || 0,
|
|
241
|
+
total_tokens: (response.usage?.input_tokens || 0) + (response.usage?.output_tokens || 0),
|
|
242
|
+
},
|
|
243
|
+
finish_reason: response.stop_reason || 'end_turn',
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
toAnthropicMessages(messages) {
|
|
247
|
+
const result = [];
|
|
248
|
+
// Append a content block to a message of the given role, MERGING with the
|
|
249
|
+
// previous message when it shares the same role. Anthropic requires roles
|
|
250
|
+
// to strictly alternate (user/assistant/user/...), so consecutive
|
|
251
|
+
// same-role messages — e.g. a tool_result (user) followed by a system
|
|
252
|
+
// nudge or error message (also user) — must be combined into one message
|
|
253
|
+
// with multiple content blocks, or the API returns a 400.
|
|
254
|
+
const push = (role, block) => {
|
|
255
|
+
const last = result[result.length - 1];
|
|
256
|
+
if (last && last.role === role) {
|
|
257
|
+
if (!Array.isArray(last.content)) {
|
|
258
|
+
last.content = [{ type: 'text', text: last.content }];
|
|
259
|
+
}
|
|
260
|
+
last.content.push(block);
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
result.push({ role, content: [block] });
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
for (const msg of messages) {
|
|
267
|
+
if (msg.role === 'assistant') {
|
|
268
|
+
if (msg.content) {
|
|
269
|
+
push('assistant', { type: 'text', text: msg.content });
|
|
270
|
+
}
|
|
271
|
+
if (msg.tool_calls) {
|
|
272
|
+
for (const tc of msg.tool_calls) {
|
|
273
|
+
let input;
|
|
274
|
+
try {
|
|
275
|
+
input = JSON.parse(tc.function.arguments);
|
|
276
|
+
}
|
|
277
|
+
catch {
|
|
278
|
+
input = {};
|
|
279
|
+
}
|
|
280
|
+
push('assistant', {
|
|
281
|
+
type: 'tool_use',
|
|
282
|
+
id: tc.id,
|
|
283
|
+
name: tc.function.name,
|
|
284
|
+
input,
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
else if (msg.role === 'tool') {
|
|
290
|
+
// Tool results map to a user message with tool_result content blocks.
|
|
291
|
+
push('user', {
|
|
292
|
+
type: 'tool_result',
|
|
293
|
+
tool_use_id: msg.tool_call_id,
|
|
294
|
+
content: msg.content,
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
else if (msg.role === 'user') {
|
|
298
|
+
push('user', { type: 'text', text: msg.content });
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
// Anthropic requires the first message to have the 'user' role. If the
|
|
302
|
+
// conversation somehow begins with an assistant turn (e.g. an odd
|
|
303
|
+
// checkpoint), drop leading assistant messages so the request is valid.
|
|
304
|
+
while (result.length > 0 && result[0].role !== 'user') {
|
|
305
|
+
result.shift();
|
|
306
|
+
}
|
|
307
|
+
return result;
|
|
308
|
+
}
|
|
309
|
+
toAnthropicTool(tool) {
|
|
310
|
+
return {
|
|
311
|
+
name: tool.name,
|
|
312
|
+
description: tool.description,
|
|
313
|
+
input_schema: tool.parameters,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
// ─── Retry Logic ─────────────────────────────────────────
|
|
317
|
+
isRetryableError(error) {
|
|
318
|
+
// Rate limits
|
|
319
|
+
if (error?.status === 429)
|
|
320
|
+
return true;
|
|
321
|
+
// Request timeout
|
|
322
|
+
if (error?.status === 408)
|
|
323
|
+
return true;
|
|
324
|
+
// Server errors
|
|
325
|
+
if (error?.status >= 500)
|
|
326
|
+
return true;
|
|
327
|
+
// Network errors (Node-level)
|
|
328
|
+
if (error?.code === 'ECONNRESET' || error?.code === 'ETIMEDOUT' ||
|
|
329
|
+
error?.code === 'ENOTFOUND' || error?.code === 'ECONNREFUSED' ||
|
|
330
|
+
error?.code === 'EPIPE' || error?.code === 'EAI_AGAIN')
|
|
331
|
+
return true;
|
|
332
|
+
// SDK-level connection/timeout errors (OpenAI & Anthropic wrap these and
|
|
333
|
+
// often don't expose a numeric status). Match by class name defensively.
|
|
334
|
+
const name = error?.name || error?.constructor?.name;
|
|
335
|
+
if (name === 'APIConnectionError' || name === 'APIConnectionTimeoutError' ||
|
|
336
|
+
name === 'InternalServerError' || name === 'AbortError')
|
|
337
|
+
return true;
|
|
338
|
+
// Overloaded (Anthropic)
|
|
339
|
+
if (error?.error?.type === 'overloaded_error')
|
|
340
|
+
return true;
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
343
|
+
calculateBackoff(attempt, error) {
|
|
344
|
+
// Check for Retry-After header
|
|
345
|
+
const retryAfter = error?.headers?.['retry-after'];
|
|
346
|
+
if (retryAfter) {
|
|
347
|
+
const retryMs = parseInt(retryAfter, 10) * 1000;
|
|
348
|
+
if (!isNaN(retryMs))
|
|
349
|
+
return retryMs;
|
|
350
|
+
}
|
|
351
|
+
// Exponential backoff with jitter
|
|
352
|
+
const baseDelay = this.config.retryBaseDelayMs;
|
|
353
|
+
const maxDelay = 120000; // 2 minutes max
|
|
354
|
+
const delay = Math.min(baseDelay * Math.pow(2, attempt), maxDelay);
|
|
355
|
+
const jitter = delay * 0.2 * Math.random();
|
|
356
|
+
return delay + jitter;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Wrap common API errors with actionable, user-friendly messages so the
|
|
360
|
+
* operator can fix config issues without digging through raw HTTP bodies.
|
|
361
|
+
*/
|
|
362
|
+
enhanceError(error, ep = this.primary) {
|
|
363
|
+
const status = error?.status;
|
|
364
|
+
const provider = ep.type;
|
|
365
|
+
const model = ep.model;
|
|
366
|
+
if (status === 401) {
|
|
367
|
+
const envVar = provider === 'openai' ? 'OPENAI_API_KEY' : 'ANTHROPIC_API_KEY';
|
|
368
|
+
return Object.assign(new Error(`Authentication failed (HTTP 401) for ${provider}. ` +
|
|
369
|
+
`Your API key is missing or invalid. ` +
|
|
370
|
+
`Check the ${envVar} environment variable or --${provider === 'openai' ? 'openai-key' : 'anthropic-key'} flag.`), { cause: error });
|
|
371
|
+
}
|
|
372
|
+
if (status === 403) {
|
|
373
|
+
return Object.assign(new Error(`Access denied (HTTP 403) for ${provider}. ` +
|
|
374
|
+
`Your API key does not have permission to use model "${model}". ` +
|
|
375
|
+
`Check your organization settings, billing status, and model access.`), { cause: error });
|
|
376
|
+
}
|
|
377
|
+
if (status === 404) {
|
|
378
|
+
return Object.assign(new Error(`Model not found (HTTP 404): "${model}" is not a valid ${provider} model. ` +
|
|
379
|
+
`Use --model to specify a different model. ` +
|
|
380
|
+
`Run with --help to see available options.`), { cause: error });
|
|
381
|
+
}
|
|
382
|
+
if (status === 400 || status === 422) {
|
|
383
|
+
const body = error?.error?.message || error?.message || 'unknown';
|
|
384
|
+
return Object.assign(new Error(`Invalid request (HTTP ${status}) from ${provider}: ${body}. ` +
|
|
385
|
+
`This usually means the request parameters are malformed. ` +
|
|
386
|
+
`If this persists, try a different model or check your configuration.`), { cause: error });
|
|
387
|
+
}
|
|
388
|
+
// For any other error, return as-is
|
|
389
|
+
return error;
|
|
390
|
+
}
|
|
391
|
+
sleep(ms) {
|
|
392
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
exports.LLMProvider = LLMProvider;
|
|
396
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,8CAA8C;AAC9C,+DAA+D;;;;;;AAE/D,oDAA4B;AAC5B,4DAA0C;AAgB1C;;;;;;;;;GASG;AACH,MAAa,WAAW;IACd,MAAM,CAAc;IACpB,MAAM,CAAS;IAEN,OAAO,CAAW;IAClB,KAAK,CAAY;IAE1B,aAAa,GAAG,IAAI,GA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|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** The protocol used to talk to a provider. */
|
|
2
|
+
export type ProviderType = 'openai' | 'anthropic';
|
|
3
|
+
/** A known provider's connection defaults. */
|
|
4
|
+
export interface RegistryProvider {
|
|
5
|
+
/** Protocol: 'openai' (OpenAI-compatible) or 'anthropic' (native SDK). */
|
|
6
|
+
type: ProviderType;
|
|
7
|
+
/** Base URL for the API. Undefined = the SDK's default (official endpoint). */
|
|
8
|
+
baseURL?: string;
|
|
9
|
+
/** Environment variable the API key is read from when not given explicitly. */
|
|
10
|
+
envKey?: string;
|
|
11
|
+
/** Human label for diagnostics. */
|
|
12
|
+
label?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Built-in providers. Keyed by the short name used in "provider/model".
|
|
16
|
+
* baseURLs reflect each provider's public OpenAI-compatible endpoint.
|
|
17
|
+
*/
|
|
18
|
+
export declare const BUILTIN_PROVIDERS: Record<string, RegistryProvider>;
|
|
19
|
+
/** A user-supplied provider entry from notsleep.json (all fields optional). */
|
|
20
|
+
export interface UserProvider {
|
|
21
|
+
type?: ProviderType;
|
|
22
|
+
baseURL?: string;
|
|
23
|
+
apiKey?: string;
|
|
24
|
+
}
|
|
25
|
+
/** A fully-resolved active model ready to construct a client from. */
|
|
26
|
+
export interface ResolvedModel {
|
|
27
|
+
/** Registry name of the provider, e.g. 'groq'. */
|
|
28
|
+
providerName: string;
|
|
29
|
+
/** Protocol to use. */
|
|
30
|
+
type: ProviderType;
|
|
31
|
+
/** The model id passed to the API (may contain '/', e.g. openrouter). */
|
|
32
|
+
model: string;
|
|
33
|
+
/** Resolved API key. */
|
|
34
|
+
apiKey: string;
|
|
35
|
+
/** Resolved base URL (may be undefined = SDK default). */
|
|
36
|
+
baseURL?: string;
|
|
37
|
+
}
|
|
38
|
+
/** True when a string is a unified "provider/model" selector. */
|
|
39
|
+
export declare function isModelRef(value: string | undefined): value is string;
|
|
40
|
+
/**
|
|
41
|
+
* Split "provider/model" on the FIRST slash only, so model ids that
|
|
42
|
+
* themselves contain slashes (e.g. "anthropic/claude-3.5-sonnet" on
|
|
43
|
+
* OpenRouter) are preserved.
|
|
44
|
+
*/
|
|
45
|
+
export declare function parseModelRef(ref: string): {
|
|
46
|
+
providerName: string;
|
|
47
|
+
model: string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Resolve a "provider/model" reference against the built-in registry,
|
|
51
|
+
* overlaid with user-defined providers from config. Returns a fully
|
|
52
|
+
* resolved model spec, or throws with an actionable message.
|
|
53
|
+
*
|
|
54
|
+
* @param ref e.g. "groq/llama-3.3-70b-versatile"
|
|
55
|
+
* @param userProviders the `providers` map from notsleep.json (env refs
|
|
56
|
+
* already resolved), or undefined.
|
|
57
|
+
* @param env environment (defaults to process.env), for envKey lookup.
|
|
58
|
+
*/
|
|
59
|
+
export declare function resolveModelRef(ref: string, userProviders?: Record<string, UserProvider>, env?: NodeJS.ProcessEnv): ResolvedModel;
|
|
60
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAoBA,+CAA+C;AAC/C,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,WAAW,CAAC;AAElD,8CAA8C;AAC9C,MAAM,WAAW,gBAAgB;IAC/B,0EAA0E;IAC1E,IAAI,EAAE,YAAY,CAAC;IACnB,+EAA+E;IAC/E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+EAA+E;IAC/E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mCAAmC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAuE9D,CAAC;AAEF,+EAA+E;AAC/E,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,sEAAsE;AACtE,MAAM,WAAW,aAAa;IAC5B,kDAAkD;IAClD,YAAY,EAAE,MAAM,CAAC;IACrB,uBAAuB;IACvB,IAAI,EAAE,YAAY,CAAC;IACnB,yEAAyE;IACzE,KAAK,EAAE,MAAM,CAAC;IACd,wBAAwB;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,iEAAiE;AACjE,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,KAAK,IAAI,MAAM,CAErE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAMlF;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,MAAM,EACX,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,EAC5C,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,aAAa,CAmCf"}
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// NotSleep - Built-in Provider Registry
|
|
4
|
+
// ============================================================
|
|
5
|
+
//
|
|
6
|
+
// A small registry of well-known LLM providers, in the spirit of
|
|
7
|
+
// OpenCode / models.dev. The insight it exploits: almost every provider
|
|
8
|
+
// speaks the OpenAI-compatible protocol (POST /v1/chat/completions), so
|
|
9
|
+
// they can all be driven by the OpenAI SDK with a different `baseURL` and
|
|
10
|
+
// `apiKey`. Only Anthropic needs its native SDK (`type: 'anthropic'`).
|
|
11
|
+
//
|
|
12
|
+
// A model is selected with a unified "provider/model" string, e.g.
|
|
13
|
+
// "groq/llama-3.3-70b-versatile"
|
|
14
|
+
// "openrouter/anthropic/claude-3.5-sonnet" (model id may contain '/')
|
|
15
|
+
// "anthropic/claude-sonnet-4-20250514"
|
|
16
|
+
//
|
|
17
|
+
// Users can add providers or override any field (apiKey, baseURL, type)
|
|
18
|
+
// via the `providers` map in notsleep.json. Unknown provider names are
|
|
19
|
+
// allowed as long as the user defines them there.
|
|
20
|
+
// ============================================================
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.BUILTIN_PROVIDERS = void 0;
|
|
23
|
+
exports.isModelRef = isModelRef;
|
|
24
|
+
exports.parseModelRef = parseModelRef;
|
|
25
|
+
exports.resolveModelRef = resolveModelRef;
|
|
26
|
+
/**
|
|
27
|
+
* Built-in providers. Keyed by the short name used in "provider/model".
|
|
28
|
+
* baseURLs reflect each provider's public OpenAI-compatible endpoint.
|
|
29
|
+
*/
|
|
30
|
+
exports.BUILTIN_PROVIDERS = {
|
|
31
|
+
openai: { type: 'openai', envKey: 'OPENAI_API_KEY', label: 'OpenAI' },
|
|
32
|
+
anthropic: { type: 'anthropic', envKey: 'ANTHROPIC_API_KEY', label: 'Anthropic' },
|
|
33
|
+
openrouter: {
|
|
34
|
+
type: 'openai',
|
|
35
|
+
baseURL: 'https://openrouter.ai/api/v1',
|
|
36
|
+
envKey: 'OPENROUTER_API_KEY',
|
|
37
|
+
label: 'OpenRouter',
|
|
38
|
+
},
|
|
39
|
+
groq: {
|
|
40
|
+
type: 'openai',
|
|
41
|
+
baseURL: 'https://api.groq.com/openai/v1',
|
|
42
|
+
envKey: 'GROQ_API_KEY',
|
|
43
|
+
label: 'Groq',
|
|
44
|
+
},
|
|
45
|
+
deepseek: {
|
|
46
|
+
type: 'openai',
|
|
47
|
+
baseURL: 'https://api.deepseek.com/v1',
|
|
48
|
+
envKey: 'DEEPSEEK_API_KEY',
|
|
49
|
+
label: 'DeepSeek',
|
|
50
|
+
},
|
|
51
|
+
together: {
|
|
52
|
+
type: 'openai',
|
|
53
|
+
baseURL: 'https://api.together.xyz/v1',
|
|
54
|
+
envKey: 'TOGETHER_API_KEY',
|
|
55
|
+
label: 'Together AI',
|
|
56
|
+
},
|
|
57
|
+
xai: {
|
|
58
|
+
type: 'openai',
|
|
59
|
+
baseURL: 'https://api.x.ai/v1',
|
|
60
|
+
envKey: 'XAI_API_KEY',
|
|
61
|
+
label: 'xAI (Grok)',
|
|
62
|
+
},
|
|
63
|
+
fireworks: {
|
|
64
|
+
type: 'openai',
|
|
65
|
+
baseURL: 'https://api.fireworks.ai/inference/v1',
|
|
66
|
+
envKey: 'FIREWORKS_API_KEY',
|
|
67
|
+
label: 'Fireworks AI',
|
|
68
|
+
},
|
|
69
|
+
mistral: {
|
|
70
|
+
type: 'openai',
|
|
71
|
+
baseURL: 'https://api.mistral.ai/v1',
|
|
72
|
+
envKey: 'MISTRAL_API_KEY',
|
|
73
|
+
label: 'Mistral',
|
|
74
|
+
},
|
|
75
|
+
perplexity: {
|
|
76
|
+
type: 'openai',
|
|
77
|
+
baseURL: 'https://api.perplexity.ai',
|
|
78
|
+
envKey: 'PERPLEXITY_API_KEY',
|
|
79
|
+
label: 'Perplexity',
|
|
80
|
+
},
|
|
81
|
+
gemini: {
|
|
82
|
+
type: 'openai',
|
|
83
|
+
baseURL: 'https://generativelanguage.googleapis.com/v1beta/openai/',
|
|
84
|
+
envKey: 'GEMINI_API_KEY',
|
|
85
|
+
label: 'Google Gemini',
|
|
86
|
+
},
|
|
87
|
+
ollama: {
|
|
88
|
+
type: 'openai',
|
|
89
|
+
baseURL: 'http://localhost:11434/v1',
|
|
90
|
+
// Local server: no real key, but the OpenAI SDK requires a non-empty one.
|
|
91
|
+
envKey: 'OLLAMA_API_KEY',
|
|
92
|
+
label: 'Ollama (local)',
|
|
93
|
+
},
|
|
94
|
+
limitrouter: {
|
|
95
|
+
type: 'openai',
|
|
96
|
+
baseURL: 'https://limitrouter.com/v1',
|
|
97
|
+
envKey: 'OPENAI_API_KEY',
|
|
98
|
+
label: 'LimitRouter',
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
/** True when a string is a unified "provider/model" selector. */
|
|
102
|
+
function isModelRef(value) {
|
|
103
|
+
return typeof value === 'string' && value.includes('/') && value.indexOf('/') > 0;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Split "provider/model" on the FIRST slash only, so model ids that
|
|
107
|
+
* themselves contain slashes (e.g. "anthropic/claude-3.5-sonnet" on
|
|
108
|
+
* OpenRouter) are preserved.
|
|
109
|
+
*/
|
|
110
|
+
function parseModelRef(ref) {
|
|
111
|
+
const slash = ref.indexOf('/');
|
|
112
|
+
return {
|
|
113
|
+
providerName: ref.slice(0, slash).trim(),
|
|
114
|
+
model: ref.slice(slash + 1).trim(),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Resolve a "provider/model" reference against the built-in registry,
|
|
119
|
+
* overlaid with user-defined providers from config. Returns a fully
|
|
120
|
+
* resolved model spec, or throws with an actionable message.
|
|
121
|
+
*
|
|
122
|
+
* @param ref e.g. "groq/llama-3.3-70b-versatile"
|
|
123
|
+
* @param userProviders the `providers` map from notsleep.json (env refs
|
|
124
|
+
* already resolved), or undefined.
|
|
125
|
+
* @param env environment (defaults to process.env), for envKey lookup.
|
|
126
|
+
*/
|
|
127
|
+
function resolveModelRef(ref, userProviders, env = process.env) {
|
|
128
|
+
const { providerName, model } = parseModelRef(ref);
|
|
129
|
+
if (!providerName || !model) {
|
|
130
|
+
throw new Error(`Invalid model "${ref}". Use the "provider/model" format, e.g. "groq/llama-3.3-70b-versatile".`);
|
|
131
|
+
}
|
|
132
|
+
const builtin = exports.BUILTIN_PROVIDERS[providerName];
|
|
133
|
+
const user = userProviders?.[providerName];
|
|
134
|
+
if (!builtin && !user) {
|
|
135
|
+
const known = Object.keys(exports.BUILTIN_PROVIDERS).join(', ');
|
|
136
|
+
throw new Error(`Unknown provider "${providerName}" in model "${ref}". ` +
|
|
137
|
+
`Either use a built-in provider (${known}) or define "${providerName}" ` +
|
|
138
|
+
`in the "providers" section of your config with a baseURL and apiKey.`);
|
|
139
|
+
}
|
|
140
|
+
const type = user?.type ?? builtin?.type ?? 'openai';
|
|
141
|
+
const baseURL = user?.baseURL ?? builtin?.baseURL;
|
|
142
|
+
// API key: explicit user value wins; otherwise read the registry env var.
|
|
143
|
+
let apiKey = user?.apiKey ?? '';
|
|
144
|
+
if (!apiKey && builtin?.envKey) {
|
|
145
|
+
apiKey = env[builtin.envKey] ?? '';
|
|
146
|
+
}
|
|
147
|
+
// Local providers (Ollama) work without a real key; give the SDK a filler.
|
|
148
|
+
if (!apiKey && providerName === 'ollama') {
|
|
149
|
+
apiKey = 'ollama';
|
|
150
|
+
}
|
|
151
|
+
return { providerName, type, model, apiKey, baseURL };
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,wCAAwC;AACxC,+DAA+D;AAC/D,EAAE;AACF,iEAAiE;AACjE,wEAAwE;AACxE,wEAAwE;AACxE,0EAA0E;AAC1E,uEAAuE;AACvE,EAAE;AACF,mEAAmE;AACnE,mCAAmC;AACnC,0EAA0E;AAC1E,yCAAyC;AACzC,EAAE;AACF,wEAAwE;AACxE,uEAAuE;AACvE,kDAAkD;AAClD,+DAA+D;;;AAoH/D,gCAEC;AAOD,sCAMC;AAYD,0CAuCC;AArKD;;;GAGG;AACU,QAAA,iBAAiB,GAAqC;IACjE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE,KAAK,EAAE,QAAQ,EAAE;IACrE,SAAS,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,mBAAmB,EAAE,KAAK,EAAE,WAAW,EAAE;IAEjF,UAAU,EAAE;QACV,IAAI,EAAE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AK,CACb,qBAAqB,YAAY,eAAe,GAAG,KAAK;YACxD,mCAAmC,KAAK,gBAAgB,YAAY,IAAI;YACxE,sEAAsE,CACvE,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAiB,IAAI,EAAE,IAAI,IAAI,OAAO,EAAE,IAAI,IAAI,QAAQ,CAAC;IACnE,MAAM,OAAO,GAAG,IAAI,EAAE,OAAO,IAAI,OAAO,EAAE,OAAO,CAAC;IAElD,0EAA0E;IAC1E,IAAI,MAAM,GAAG,IAAI,EAAE,MAAM,IAAI,EAAE,CAAC;IAChC,IAAI,CAAC,MAAM,IAAI,OAAO,EAAE,MAAM,EAAE,CAAC;QAC/B,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IACrC,CAAC;IACD,2EAA2E;IAC3E,IAAI,CAAC,MAAM,IAAI,YAAY,KAAK,QAAQ,EAAE,CAAC;QACzC,MAAM,GAAG,QAAQ,CAAC;IACpB,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;AACxD,CAAC"}
|
package/dist/safety.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* True if `child` is the same as, or nested inside, `parent`.
|
|
3
|
+
* Comparison is case-insensitive on Windows (path.relative handles this).
|
|
4
|
+
*/
|
|
5
|
+
export declare function isPathWithin(child: string, parent: string): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Decide whether a file-writing/deleting operation is allowed to touch
|
|
8
|
+
* `target`. Writes are confined to the workspace root or the OS temp dir.
|
|
9
|
+
* Returns the resolved absolute path when allowed, or a reason when not.
|
|
10
|
+
*/
|
|
11
|
+
export declare function assertWritablePath(target: string, workspaceRoot: string): {
|
|
12
|
+
allowed: boolean;
|
|
13
|
+
resolved: string;
|
|
14
|
+
reason?: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Inspect a shell command for destructive operations. Returns a human
|
|
18
|
+
* reason string if the command should be refused, or null if it is allowed.
|
|
19
|
+
*/
|
|
20
|
+
export declare function checkShellCommand(command: string): string | null;
|
|
21
|
+
//# sourceMappingURL=safety.d.ts.map
|