@tanstack/ai-anthropic 0.8.4 → 0.8.5

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.
@@ -1,4 +1,5 @@
1
1
  import Anthropic_SDK from "@anthropic-ai/sdk";
2
+ import { generateId as generateId$1, getApiKeyFromEnv } from "@tanstack/ai-utils";
2
3
  function createAnthropicClient(config) {
3
4
  return new Anthropic_SDK({
4
5
  ...config,
@@ -6,17 +7,10 @@ function createAnthropicClient(config) {
6
7
  });
7
8
  }
8
9
  function getAnthropicApiKeyFromEnv() {
9
- const env = typeof globalThis !== "undefined" && globalThis.window?.env ? globalThis.window.env : typeof process !== "undefined" ? process.env : void 0;
10
- const key = env?.ANTHROPIC_API_KEY;
11
- if (!key) {
12
- throw new Error(
13
- "ANTHROPIC_API_KEY is required. Please set it in your environment variables or use the factory function with an explicit API key."
14
- );
15
- }
16
- return key;
10
+ return getApiKeyFromEnv("ANTHROPIC_API_KEY");
17
11
  }
18
12
  function generateId(prefix) {
19
- return `${prefix}-${Date.now()}-${Math.random().toString(36).substring(7)}`;
13
+ return generateId$1(prefix);
20
14
  }
21
15
  export {
22
16
  createAnthropicClient,
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sources":["../../../src/utils/client.ts"],"sourcesContent":["import Anthropic_SDK from '@anthropic-ai/sdk'\nimport type { ClientOptions } from '@anthropic-ai/sdk'\n\nexport interface AnthropicClientConfig extends ClientOptions {\n apiKey: string\n}\n\n/**\n * Creates an Anthropic SDK client instance\n */\nexport function createAnthropicClient(\n config: AnthropicClientConfig,\n): Anthropic_SDK {\n return new Anthropic_SDK({\n ...config,\n apiKey: config.apiKey,\n })\n}\n\n/**\n * Gets Anthropic API key from environment variables\n * @throws Error if ANTHROPIC_API_KEY is not found\n */\nexport function getAnthropicApiKeyFromEnv(): string {\n const env =\n typeof globalThis !== 'undefined' && (globalThis as any).window?.env\n ? (globalThis as any).window.env\n : typeof process !== 'undefined'\n ? process.env\n : undefined\n const key = env?.ANTHROPIC_API_KEY\n\n if (!key) {\n throw new Error(\n 'ANTHROPIC_API_KEY is required. Please set it in your environment variables or use the factory function with an explicit API key.',\n )\n }\n\n return key\n}\n\n/**\n * Generates a unique ID with a prefix\n */\nexport function generateId(prefix: string): string {\n return `${prefix}-${Date.now()}-${Math.random().toString(36).substring(7)}`\n}\n"],"names":[],"mappings":";AAUO,SAAS,sBACd,QACe;AACf,SAAO,IAAI,cAAc;AAAA,IACvB,GAAG;AAAA,IACH,QAAQ,OAAO;AAAA,EAAA,CAChB;AACH;AAMO,SAAS,4BAAoC;AAClD,QAAM,MACJ,OAAO,eAAe,eAAgB,WAAmB,QAAQ,MAC5D,WAAmB,OAAO,MAC3B,OAAO,YAAY,cACjB,QAAQ,MACR;AACR,QAAM,MAAM,KAAK;AAEjB,MAAI,CAAC,KAAK;AACR,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AAEA,SAAO;AACT;AAKO,SAAS,WAAW,QAAwB;AACjD,SAAO,GAAG,MAAM,IAAI,KAAK,KAAK,IAAI,KAAK,OAAA,EAAS,SAAS,EAAE,EAAE,UAAU,CAAC,CAAC;AAC3E;"}
1
+ {"version":3,"file":"client.js","sources":["../../../src/utils/client.ts"],"sourcesContent":["import Anthropic_SDK from '@anthropic-ai/sdk'\nimport { generateId as _generateId, getApiKeyFromEnv } from '@tanstack/ai-utils'\nimport type { ClientOptions } from '@anthropic-ai/sdk'\n\nexport interface AnthropicClientConfig extends ClientOptions {\n apiKey: string\n}\n\n/**\n * Creates an Anthropic SDK client instance\n */\nexport function createAnthropicClient(\n config: AnthropicClientConfig,\n): Anthropic_SDK {\n return new Anthropic_SDK({\n ...config,\n apiKey: config.apiKey,\n })\n}\n\n/**\n * Gets Anthropic API key from environment variables\n * @throws Error if ANTHROPIC_API_KEY is not found\n */\nexport function getAnthropicApiKeyFromEnv(): string {\n return getApiKeyFromEnv('ANTHROPIC_API_KEY')\n}\n\n/**\n * Generates a unique ID with a prefix\n */\nexport function generateId(prefix: string): string {\n return _generateId(prefix)\n}\n"],"names":["_generateId"],"mappings":";;AAWO,SAAS,sBACd,QACe;AACf,SAAO,IAAI,cAAc;AAAA,IACvB,GAAG;AAAA,IACH,QAAQ,OAAO;AAAA,EAAA,CAChB;AACH;AAMO,SAAS,4BAAoC;AAClD,SAAO,iBAAiB,mBAAmB;AAC7C;AAKO,SAAS,WAAW,QAAwB;AACjD,SAAOA,aAAY,MAAM;AAC3B;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/ai-anthropic",
3
- "version": "0.8.4",
3
+ "version": "0.8.5",
4
4
  "description": "Anthropic Claude adapter for TanStack AI",
5
5
  "author": "",
6
6
  "license": "MIT",
@@ -34,7 +34,8 @@
34
34
  "src"
35
35
  ],
36
36
  "dependencies": {
37
- "@anthropic-ai/sdk": "^0.71.2"
37
+ "@anthropic-ai/sdk": "^0.71.2",
38
+ "@tanstack/ai-utils": "0.2.0"
38
39
  },
39
40
  "peerDependencies": {
40
41
  "zod": "^4.0.0",
@@ -1,4 +1,5 @@
1
1
  import Anthropic_SDK from '@anthropic-ai/sdk'
2
+ import { generateId as _generateId, getApiKeyFromEnv } from '@tanstack/ai-utils'
2
3
  import type { ClientOptions } from '@anthropic-ai/sdk'
3
4
 
4
5
  export interface AnthropicClientConfig extends ClientOptions {
@@ -22,26 +23,12 @@ export function createAnthropicClient(
22
23
  * @throws Error if ANTHROPIC_API_KEY is not found
23
24
  */
24
25
  export function getAnthropicApiKeyFromEnv(): string {
25
- const env =
26
- typeof globalThis !== 'undefined' && (globalThis as any).window?.env
27
- ? (globalThis as any).window.env
28
- : typeof process !== 'undefined'
29
- ? process.env
30
- : undefined
31
- const key = env?.ANTHROPIC_API_KEY
32
-
33
- if (!key) {
34
- throw new Error(
35
- 'ANTHROPIC_API_KEY is required. Please set it in your environment variables or use the factory function with an explicit API key.',
36
- )
37
- }
38
-
39
- return key
26
+ return getApiKeyFromEnv('ANTHROPIC_API_KEY')
40
27
  }
41
28
 
42
29
  /**
43
30
  * Generates a unique ID with a prefix
44
31
  */
45
32
  export function generateId(prefix: string): string {
46
- return `${prefix}-${Date.now()}-${Math.random().toString(36).substring(7)}`
33
+ return _generateId(prefix)
47
34
  }