snow-ai 0.4.0 → 0.4.3
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/api/anthropic.js +16 -10
- package/package.json +2 -2
package/dist/api/anthropic.js
CHANGED
|
@@ -6,6 +6,8 @@ import { logger } from '../utils/logger.js';
|
|
|
6
6
|
import { addProxyToFetchOptions } from '../utils/proxyUtils.js';
|
|
7
7
|
import { saveUsageToFile } from '../utils/usageLogger.js';
|
|
8
8
|
let anthropicConfig = null;
|
|
9
|
+
// Persistent userId that remains the same until application restart
|
|
10
|
+
let persistentUserId = null;
|
|
9
11
|
function getAnthropicConfig() {
|
|
10
12
|
if (!anthropicConfig) {
|
|
11
13
|
const config = getOpenAiConfig();
|
|
@@ -27,18 +29,22 @@ function getAnthropicConfig() {
|
|
|
27
29
|
}
|
|
28
30
|
export function resetAnthropicClient() {
|
|
29
31
|
anthropicConfig = null;
|
|
32
|
+
persistentUserId = null; // Reset userId on client reset
|
|
30
33
|
}
|
|
31
34
|
/**
|
|
32
|
-
* Generate a user_id
|
|
35
|
+
* Generate a persistent user_id that remains the same until application restart
|
|
36
|
+
* Format: user_<hash>_account__session_<uuid>
|
|
33
37
|
* This matches Anthropic's expected format for tracking and caching
|
|
34
|
-
* The hash is based on sessionId only to keep it consistent within the same session
|
|
35
38
|
*/
|
|
36
|
-
function
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
function getPersistentUserId() {
|
|
40
|
+
if (!persistentUserId) {
|
|
41
|
+
const sessionId = randomUUID();
|
|
42
|
+
const hash = createHash('sha256')
|
|
43
|
+
.update(`anthropic_user_${sessionId}`)
|
|
44
|
+
.digest('hex');
|
|
45
|
+
persistentUserId = `user_${hash}_account__session_${sessionId}`;
|
|
46
|
+
}
|
|
47
|
+
return persistentUserId;
|
|
42
48
|
}
|
|
43
49
|
/**
|
|
44
50
|
* Convert OpenAI-style tools to Anthropic tool format
|
|
@@ -286,8 +292,8 @@ export async function* createStreamingAnthropicCompletion(options, abortSignal,
|
|
|
286
292
|
yield* withRetryGenerator(async function* () {
|
|
287
293
|
const config = getAnthropicConfig();
|
|
288
294
|
const { system, messages } = convertToAnthropicMessages(options.messages, options.includeBuiltinSystemPrompt !== false);
|
|
289
|
-
|
|
290
|
-
const userId =
|
|
295
|
+
// Use persistent userId that remains the same until application restart
|
|
296
|
+
const userId = getPersistentUserId();
|
|
291
297
|
const requestBody = {
|
|
292
298
|
model: options.model,
|
|
293
299
|
max_tokens: options.max_tokens || 4096,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "snow-ai",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Intelligent Command Line Assistant powered by AI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"ink-spinner": "^5.0.0",
|
|
57
57
|
"ink-text-input": "^6.0.0",
|
|
58
58
|
"meow": "^11.0.0",
|
|
59
|
+
"prettier": "^2.8.7",
|
|
59
60
|
"puppeteer-core": "^24.25.0",
|
|
60
61
|
"react": "^18.2.0",
|
|
61
62
|
"string-width": "^7.2.0",
|
|
@@ -75,7 +76,6 @@
|
|
|
75
76
|
"eslint-plugin-react": "^7.32.2",
|
|
76
77
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
77
78
|
"ink-testing-library": "^3.0.0",
|
|
78
|
-
"prettier": "^2.8.7",
|
|
79
79
|
"ts-node": "^10.9.1",
|
|
80
80
|
"typescript": "^5.0.3",
|
|
81
81
|
"xo": "^0.53.1"
|