@push.rocks/smartai 0.7.7 → 0.9.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/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/provider.anthropic.d.ts +6 -0
- package/dist_ts/provider.anthropic.js +39 -8
- package/dist_ts/provider.elevenlabs.js +4 -2
- package/dist_ts/provider.openai.js +7 -4
- package/npmextra.json +12 -6
- package/package.json +22 -15
- package/readme.hints.md +210 -1
- package/readme.md +136 -81
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/provider.anthropic.ts +45 -7
- package/ts/provider.elevenlabs.ts +3 -1
- package/ts/provider.openai.ts +7 -3
package/ts/provider.anthropic.ts
CHANGED
|
@@ -20,6 +20,7 @@ export interface IAnthropicProviderOptions {
|
|
|
20
20
|
enableWebSearch?: boolean;
|
|
21
21
|
searchDomainAllowList?: string[];
|
|
22
22
|
searchDomainBlockList?: string[];
|
|
23
|
+
extendedThinking?: 'quick' | 'normal' | 'deep' | 'off';
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export class AnthropicProvider extends MultiModalModel {
|
|
@@ -42,6 +43,25 @@ export class AnthropicProvider extends MultiModalModel {
|
|
|
42
43
|
await super.stop();
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Returns the thinking configuration based on provider options.
|
|
48
|
+
* Defaults to 'normal' mode (8000 tokens) if not specified.
|
|
49
|
+
*/
|
|
50
|
+
private getThinkingConfig(): { type: 'enabled'; budget_tokens: number } | undefined {
|
|
51
|
+
const mode = this.options.extendedThinking ?? 'normal';
|
|
52
|
+
|
|
53
|
+
const budgetMap = {
|
|
54
|
+
quick: 2048,
|
|
55
|
+
normal: 8000,
|
|
56
|
+
deep: 16000,
|
|
57
|
+
off: 0,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const budget = budgetMap[mode];
|
|
61
|
+
|
|
62
|
+
return budget > 0 ? { type: 'enabled', budget_tokens: budget } : undefined;
|
|
63
|
+
}
|
|
64
|
+
|
|
45
65
|
public async chatStream(input: ReadableStream<Uint8Array>): Promise<ReadableStream<string>> {
|
|
46
66
|
// Create a TextDecoder to handle incoming chunks
|
|
47
67
|
const decoder = new TextDecoder();
|
|
@@ -76,12 +96,14 @@ export class AnthropicProvider extends MultiModalModel {
|
|
|
76
96
|
|
|
77
97
|
// If we have a complete message, send it to Anthropic
|
|
78
98
|
if (currentMessage) {
|
|
99
|
+
const thinkingConfig = this.getThinkingConfig();
|
|
79
100
|
const stream = await this.anthropicApiClient.messages.create({
|
|
80
101
|
model: 'claude-sonnet-4-5-20250929',
|
|
81
102
|
messages: [{ role: currentMessage.role, content: currentMessage.content }],
|
|
82
103
|
system: '',
|
|
83
104
|
stream: true,
|
|
84
|
-
max_tokens:
|
|
105
|
+
max_tokens: 20000,
|
|
106
|
+
...(thinkingConfig && { thinking: thinkingConfig }),
|
|
85
107
|
});
|
|
86
108
|
|
|
87
109
|
// Process each chunk from Anthropic
|
|
@@ -120,6 +142,7 @@ export class AnthropicProvider extends MultiModalModel {
|
|
|
120
142
|
content: msg.content
|
|
121
143
|
}));
|
|
122
144
|
|
|
145
|
+
const thinkingConfig = this.getThinkingConfig();
|
|
123
146
|
const result = await this.anthropicApiClient.messages.create({
|
|
124
147
|
model: 'claude-sonnet-4-5-20250929',
|
|
125
148
|
system: optionsArg.systemMessage,
|
|
@@ -127,7 +150,8 @@ export class AnthropicProvider extends MultiModalModel {
|
|
|
127
150
|
...messages,
|
|
128
151
|
{ role: 'user' as const, content: optionsArg.userMessage }
|
|
129
152
|
],
|
|
130
|
-
max_tokens:
|
|
153
|
+
max_tokens: 20000,
|
|
154
|
+
...(thinkingConfig && { thinking: thinkingConfig }),
|
|
131
155
|
});
|
|
132
156
|
|
|
133
157
|
// Extract text content from the response
|
|
@@ -167,13 +191,15 @@ export class AnthropicProvider extends MultiModalModel {
|
|
|
167
191
|
}
|
|
168
192
|
];
|
|
169
193
|
|
|
194
|
+
const thinkingConfig = this.getThinkingConfig();
|
|
170
195
|
const result = await this.anthropicApiClient.messages.create({
|
|
171
196
|
model: 'claude-sonnet-4-5-20250929',
|
|
172
197
|
messages: [{
|
|
173
198
|
role: 'user',
|
|
174
199
|
content
|
|
175
200
|
}],
|
|
176
|
-
max_tokens:
|
|
201
|
+
max_tokens: 10000,
|
|
202
|
+
...(thinkingConfig && { thinking: thinkingConfig }),
|
|
177
203
|
});
|
|
178
204
|
|
|
179
205
|
// Extract text content from the response
|
|
@@ -229,6 +255,7 @@ export class AnthropicProvider extends MultiModalModel {
|
|
|
229
255
|
});
|
|
230
256
|
}
|
|
231
257
|
|
|
258
|
+
const thinkingConfig = this.getThinkingConfig();
|
|
232
259
|
const result = await this.anthropicApiClient.messages.create({
|
|
233
260
|
model: 'claude-sonnet-4-5-20250929',
|
|
234
261
|
system: optionsArg.systemMessage,
|
|
@@ -236,7 +263,8 @@ export class AnthropicProvider extends MultiModalModel {
|
|
|
236
263
|
...messages,
|
|
237
264
|
{ role: 'user', content }
|
|
238
265
|
],
|
|
239
|
-
max_tokens:
|
|
266
|
+
max_tokens: 20000,
|
|
267
|
+
...(thinkingConfig && { thinking: thinkingConfig }),
|
|
240
268
|
});
|
|
241
269
|
|
|
242
270
|
// Extract text content from the response
|
|
@@ -286,10 +314,14 @@ export class AnthropicProvider extends MultiModalModel {
|
|
|
286
314
|
}
|
|
287
315
|
|
|
288
316
|
// Configure the request based on search depth
|
|
289
|
-
const maxTokens = optionsArg.searchDepth === 'deep' ?
|
|
290
|
-
optionsArg.searchDepth === 'advanced' ?
|
|
317
|
+
const maxTokens = optionsArg.searchDepth === 'deep' ? 20000 :
|
|
318
|
+
optionsArg.searchDepth === 'advanced' ? 20000 : 20000;
|
|
319
|
+
|
|
320
|
+
// Add thinking configuration if enabled
|
|
321
|
+
const thinkingConfig = this.getThinkingConfig();
|
|
291
322
|
|
|
292
323
|
// Create the research request
|
|
324
|
+
// Note: When thinking is enabled, temperature must be 1 (or omitted)
|
|
293
325
|
const requestParams: any = {
|
|
294
326
|
model: 'claude-sonnet-4-5-20250929',
|
|
295
327
|
system: systemMessage,
|
|
@@ -300,7 +332,8 @@ export class AnthropicProvider extends MultiModalModel {
|
|
|
300
332
|
}
|
|
301
333
|
],
|
|
302
334
|
max_tokens: maxTokens,
|
|
303
|
-
temperature
|
|
335
|
+
// Only set temperature when thinking is NOT enabled
|
|
336
|
+
...(thinkingConfig ? {} : { temperature: 0.7 })
|
|
304
337
|
};
|
|
305
338
|
|
|
306
339
|
// Add tools if web search is enabled
|
|
@@ -308,6 +341,11 @@ export class AnthropicProvider extends MultiModalModel {
|
|
|
308
341
|
requestParams.tools = tools;
|
|
309
342
|
}
|
|
310
343
|
|
|
344
|
+
// Add thinking configuration if enabled
|
|
345
|
+
if (thinkingConfig) {
|
|
346
|
+
requestParams.thinking = thinkingConfig;
|
|
347
|
+
}
|
|
348
|
+
|
|
311
349
|
// Execute the research request
|
|
312
350
|
const result = await this.anthropicApiClient.messages.create(requestParams);
|
|
313
351
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as plugins from './plugins.js';
|
|
2
|
+
import { Readable } from 'stream';
|
|
2
3
|
|
|
3
4
|
import { MultiModalModel } from './abstract.classes.multimodal.js';
|
|
4
5
|
import type {
|
|
@@ -83,7 +84,8 @@ export class ElevenLabsProvider extends MultiModalModel {
|
|
|
83
84
|
throw new Error(`ElevenLabs API error: ${response.status} ${response.statusText} - ${errorText}`);
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
const
|
|
87
|
+
const webStream = response.stream();
|
|
88
|
+
const nodeStream = Readable.fromWeb(webStream as any);
|
|
87
89
|
return nodeStream;
|
|
88
90
|
}
|
|
89
91
|
|
package/ts/provider.openai.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as plugins from './plugins.js';
|
|
2
2
|
import * as paths from './paths.js';
|
|
3
3
|
import { Readable } from 'stream';
|
|
4
|
+
import { toFile } from 'openai';
|
|
4
5
|
|
|
5
6
|
// Custom type definition for chat completion messages
|
|
6
7
|
export type TChatCompletionRequestMessage = {
|
|
@@ -405,16 +406,19 @@ export class OpenAiProvider extends MultiModalModel {
|
|
|
405
406
|
const model = optionsArg.model || this.options.imageModel || 'gpt-image-1';
|
|
406
407
|
|
|
407
408
|
try {
|
|
409
|
+
// Convert Buffer to uploadable file format for OpenAI API
|
|
410
|
+
const imageFile = await toFile(optionsArg.image, 'image.png', { type: 'image/png' });
|
|
411
|
+
|
|
408
412
|
const requestParams: any = {
|
|
409
413
|
model,
|
|
410
|
-
image:
|
|
414
|
+
image: imageFile,
|
|
411
415
|
prompt: optionsArg.prompt,
|
|
412
416
|
n: optionsArg.n || 1,
|
|
413
417
|
};
|
|
414
418
|
|
|
415
|
-
// Add mask if provided
|
|
419
|
+
// Add mask if provided (also convert to file format)
|
|
416
420
|
if (optionsArg.mask) {
|
|
417
|
-
requestParams.mask = optionsArg.mask;
|
|
421
|
+
requestParams.mask = await toFile(optionsArg.mask, 'mask.png', { type: 'image/png' });
|
|
418
422
|
}
|
|
419
423
|
|
|
420
424
|
// Add gpt-image-1 specific parameters
|