@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/readme.hints.md CHANGED
@@ -1 +1,210 @@
1
-
1
+ # SmartAI Project Hints
2
+
3
+ ## Dependencies
4
+
5
+ - Uses `@git.zone/tstest` v3.x for testing (import from `@git.zone/tstest/tapbundle`)
6
+ - `@push.rocks/smartfile` is kept at v11 to avoid migration to factory pattern
7
+ - `@anthropic-ai/sdk` v0.71.x with extended thinking support
8
+ - `@push.rocks/smartrequest` v5.x - uses `response.stream()` + `Readable.fromWeb()` for streaming
9
+
10
+ ## Important Notes
11
+
12
+ - When extended thinking is enabled, temperature parameter must NOT be set (or set to 1)
13
+ - The `streamNode()` method was removed in smartrequest v5, use `response.stream()` with `Readable.fromWeb()` instead
14
+
15
+ ## Anthropic Extended Thinking Feature
16
+
17
+ ### Overview
18
+
19
+ The Anthropic provider now supports extended thinking by default across all methods. Extended thinking enables Claude to spend more time reasoning about complex problems before generating responses, leading to higher quality answers for difficult questions.
20
+
21
+ ### Configuration
22
+
23
+ Extended thinking is configured at the provider level during instantiation:
24
+
25
+ ```typescript
26
+ import * as smartai from '@push.rocks/smartai';
27
+
28
+ const provider = new smartai.AnthropicProvider({
29
+ anthropicToken: 'your-token-here',
30
+ extendedThinking: 'normal', // Options: 'quick' | 'normal' | 'deep' | 'off'
31
+ });
32
+ ```
33
+
34
+ ### Thinking Modes
35
+
36
+ The `extendedThinking` parameter accepts four modes:
37
+
38
+ | Mode | Budget Tokens | Use Case |
39
+ | ---------- | ------------- | ----------------------------------------------- |
40
+ | `'quick'` | 2,048 | Lightweight reasoning for simple queries |
41
+ | `'normal'` | 8,000 | **Default** - Balanced reasoning for most tasks |
42
+ | `'deep'` | 16,000 | Complex reasoning for difficult problems |
43
+ | `'off'` | 0 | Disable extended thinking |
44
+
45
+ **Default Behavior**: If `extendedThinking` is not specified, it defaults to `'normal'` mode (8,000 tokens).
46
+
47
+ ### Supported Methods
48
+
49
+ Extended thinking is automatically applied to all Anthropic provider methods:
50
+
51
+ - `chat()` - Synchronous chat
52
+ - `chatStream()` - Streaming chat
53
+ - `vision()` - Image analysis
54
+ - `document()` - PDF document processing
55
+ - `research()` - Web research with citations
56
+
57
+ ### Token Budget Constraints
58
+
59
+ **Important**: The thinking budget must be less than `max_tokens` for the API call. The current `max_tokens` values are:
60
+
61
+ - `chatStream()`: 20,000 tokens (sufficient for all modes ✓)
62
+ - `chat()`: 20,000 tokens (sufficient for all modes ✓)
63
+ - `vision()`: 10,000 tokens (sufficient for all modes ✓)
64
+ - `document()`: 20,000 tokens (sufficient for all modes ✓)
65
+ - `research()`: 20,000 tokens for all searchDepth levels (sufficient ✓)
66
+
67
+ ### Performance and Cost Implications
68
+
69
+ **Token Usage**:
70
+
71
+ - You are charged for the **full thinking tokens** generated, not just the summary
72
+ - Higher thinking budgets may result in more thorough reasoning but increased costs
73
+ - The budget is a **target**, not a strict limit - actual usage may vary
74
+
75
+ **Response Quality**:
76
+
77
+ - `'quick'`: Fast responses, basic reasoning
78
+ - `'normal'`: Good balance between quality and speed (recommended for most use cases)
79
+ - `'deep'`: Highest quality reasoning for complex problems, slower responses
80
+
81
+ **Recommendations**:
82
+
83
+ - Start with `'normal'` (default) for general usage
84
+ - Use `'deep'` for complex analytical tasks, philosophy, mathematics, or research
85
+ - Use `'quick'` for simple factual queries where deep reasoning isn't needed
86
+ - Use `'off'` only if you want traditional Claude behavior without extended thinking
87
+
88
+ ### Usage Examples
89
+
90
+ #### Example 1: Default (Normal Mode)
91
+
92
+ ```typescript
93
+ const provider = new smartai.AnthropicProvider({
94
+ anthropicToken: process.env.ANTHROPIC_TOKEN,
95
+ // extendedThinking defaults to 'normal'
96
+ });
97
+
98
+ await provider.start();
99
+
100
+ const response = await provider.chat({
101
+ systemMessage: 'You are a helpful assistant.',
102
+ userMessage: 'Explain the implications of quantum computing.',
103
+ messageHistory: [],
104
+ });
105
+ ```
106
+
107
+ #### Example 2: Deep Thinking for Complex Analysis
108
+
109
+ ```typescript
110
+ const provider = new smartai.AnthropicProvider({
111
+ anthropicToken: process.env.ANTHROPIC_TOKEN,
112
+ extendedThinking: 'deep', // 16,000 token budget
113
+ });
114
+
115
+ await provider.start();
116
+
117
+ const response = await provider.chat({
118
+ systemMessage: 'You are a philosopher and ethicist.',
119
+ userMessage: 'Analyze the trolley problem from multiple ethical frameworks.',
120
+ messageHistory: [],
121
+ });
122
+ ```
123
+
124
+ #### Example 3: Quick Mode for Simple Queries
125
+
126
+ ```typescript
127
+ const provider = new smartai.AnthropicProvider({
128
+ anthropicToken: process.env.ANTHROPIC_TOKEN,
129
+ extendedThinking: 'quick', // 2,048 token budget
130
+ });
131
+
132
+ await provider.start();
133
+
134
+ const response = await provider.chat({
135
+ systemMessage: 'You are a helpful assistant.',
136
+ userMessage: 'What is the capital of France?',
137
+ messageHistory: [],
138
+ });
139
+ ```
140
+
141
+ #### Example 4: Disable Thinking
142
+
143
+ ```typescript
144
+ const provider = new smartai.AnthropicProvider({
145
+ anthropicToken: process.env.ANTHROPIC_TOKEN,
146
+ extendedThinking: 'off', // No extended thinking
147
+ });
148
+
149
+ await provider.start();
150
+
151
+ const response = await provider.chat({
152
+ systemMessage: 'You are a helpful assistant.',
153
+ userMessage: 'Tell me a joke.',
154
+ messageHistory: [],
155
+ });
156
+ ```
157
+
158
+ #### Example 5: Extended Thinking with Vision
159
+
160
+ ```typescript
161
+ const provider = new smartai.AnthropicProvider({
162
+ anthropicToken: process.env.ANTHROPIC_TOKEN,
163
+ extendedThinking: 'normal',
164
+ });
165
+
166
+ await provider.start();
167
+
168
+ const imageBuffer = await fs.promises.readFile('./image.jpg');
169
+ const analysis = await provider.vision({
170
+ image: imageBuffer,
171
+ prompt: 'Analyze this image in detail and explain what you see.',
172
+ });
173
+ ```
174
+
175
+ ### Testing
176
+
177
+ Comprehensive tests for extended thinking are available in:
178
+
179
+ - `test/test.thinking.anthropic.ts` - Tests all thinking modes
180
+
181
+ Run tests with:
182
+
183
+ ```bash
184
+ pnpm test
185
+ ```
186
+
187
+ Run specific thinking tests:
188
+
189
+ ```bash
190
+ npx tstest test/test.thinking.anthropic.ts --verbose
191
+ ```
192
+
193
+ ### API Reference
194
+
195
+ According to Anthropic's documentation:
196
+
197
+ - Extended thinking is supported on Claude Sonnet 4.5, 4, 3.7, Haiku 4.5, and Opus 4.1, 4
198
+ - The current model used is `claude-sonnet-4-5-20250929`
199
+ - Minimum thinking budget is 1,024 tokens
200
+ - Thinking budget must be less than `max_tokens`
201
+
202
+ ### Implementation Details
203
+
204
+ The extended thinking feature is implemented via:
205
+
206
+ 1. **Interface**: `IAnthropicProviderOptions.extendedThinking` property
207
+ 2. **Helper Method**: `getThinkingConfig()` private method that maps modes to token budgets
208
+ 3. **API Parameter**: Adds `thinking: { type: 'enabled', budget_tokens: number }` to all API calls
209
+
210
+ The thinking configuration is applied automatically to all API calls when the provider is instantiated.