@jaypie/llm 1.1.30 → 1.2.0-rc.1

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,4 @@
1
- import { Anthropic } from "@anthropic-ai/sdk";
1
+ import type { Anthropic } from "@anthropic-ai/sdk";
2
2
  import { JsonObject, NaturalSchema } from "@jaypie/types";
3
3
  import { z } from "zod/v4";
4
4
  import { Toolkit } from "../../tools/Toolkit.class.js";
@@ -1,43 +1,9 @@
1
- import { log } from "@jaypie/core";
2
- import Anthropic from "@anthropic-ai/sdk";
1
+ import type Anthropic from "@anthropic-ai/sdk";
3
2
  import { LlmMessageOptions } from "../../types/LlmProvider.interface.js";
4
3
  import { z } from "zod/v4";
5
4
  import { JsonObject, NaturalSchema } from "@jaypie/types";
6
- export declare const getLogger: () => {
7
- debug: {
8
- (...args: unknown[]): void;
9
- var(key: string | Record<string, unknown>, value?: unknown): void;
10
- };
11
- error: {
12
- (...args: unknown[]): void;
13
- var(key: string | Record<string, unknown>, value?: unknown): void;
14
- };
15
- fatal: {
16
- (...args: unknown[]): void;
17
- var(key: string | Record<string, unknown>, value?: unknown): void;
18
- };
19
- info: {
20
- (...args: unknown[]): void;
21
- var(key: string | Record<string, unknown>, value?: unknown): void;
22
- };
23
- trace: {
24
- (...args: unknown[]): void;
25
- var(key: string | Record<string, unknown>, value?: unknown): void;
26
- };
27
- warn: {
28
- (...args: unknown[]): void;
29
- var(key: string | Record<string, unknown>, value?: unknown): void;
30
- };
31
- var(key: string | Record<string, unknown>, value?: unknown): void;
32
- with(tags: Record<string, unknown>): typeof log;
33
- tag(key: string | string[] | Record<string, unknown> | null, value?: string): void;
34
- untag(tags: string | string[] | Record<string, unknown> | null): void;
35
- lib(options: {
36
- level?: string;
37
- lib?: string;
38
- tags?: Record<string, unknown>;
39
- }): typeof log;
40
- };
5
+ export declare function loadSdk(): Promise<typeof import("@anthropic-ai/sdk")>;
6
+ export declare const getLogger: () => import("@jaypie/logger/dist/esm/JaypieLogger.js").default;
41
7
  export declare function initializeClient({ apiKey, }?: {
42
8
  apiKey?: string;
43
9
  }): Promise<Anthropic>;
@@ -1,41 +1,7 @@
1
- import { log as defaultLog } from "@jaypie/core";
2
- import { GoogleGenAI } from "@google/genai";
1
+ import type { GoogleGenAI } from "@google/genai";
3
2
  import { LlmMessageOptions } from "../../types/LlmProvider.interface.js";
4
- export declare const getLogger: () => {
5
- debug: {
6
- (...args: unknown[]): void;
7
- var(key: string | Record<string, unknown>, value?: unknown): void;
8
- };
9
- error: {
10
- (...args: unknown[]): void;
11
- var(key: string | Record<string, unknown>, value?: unknown): void;
12
- };
13
- fatal: {
14
- (...args: unknown[]): void;
15
- var(key: string | Record<string, unknown>, value?: unknown): void;
16
- };
17
- info: {
18
- (...args: unknown[]): void;
19
- var(key: string | Record<string, unknown>, value?: unknown): void;
20
- };
21
- trace: {
22
- (...args: unknown[]): void;
23
- var(key: string | Record<string, unknown>, value?: unknown): void;
24
- };
25
- warn: {
26
- (...args: unknown[]): void;
27
- var(key: string | Record<string, unknown>, value?: unknown): void;
28
- };
29
- var(key: string | Record<string, unknown>, value?: unknown): void;
30
- with(tags: Record<string, unknown>): typeof defaultLog;
31
- tag(key: string | string[] | Record<string, unknown> | null, value?: string): void;
32
- untag(tags: string | string[] | Record<string, unknown> | null): void;
33
- lib(options: {
34
- level?: string;
35
- lib?: string;
36
- tags?: Record<string, unknown>;
37
- }): typeof defaultLog;
38
- };
3
+ export declare function loadSdk(): Promise<typeof import("@google/genai")>;
4
+ export declare const getLogger: () => import("@jaypie/logger/dist/esm/JaypieLogger.js").default;
39
5
  export declare function initializeClient({ apiKey, }?: {
40
6
  apiKey?: string;
41
7
  }): Promise<GoogleGenAI>;
@@ -1,43 +1,8 @@
1
- import { log as defaultLog } from "@jaypie/core";
2
1
  import { JsonObject, NaturalSchema } from "@jaypie/types";
3
2
  import { OpenAI } from "openai";
4
3
  import { z } from "zod/v4";
5
4
  import { LlmMessageOptions } from "../../types/LlmProvider.interface.js";
6
- export declare const getLogger: () => {
7
- debug: {
8
- (...args: unknown[]): void;
9
- var(key: string | Record<string, unknown>, value?: unknown): void;
10
- };
11
- error: {
12
- (...args: unknown[]): void;
13
- var(key: string | Record<string, unknown>, value?: unknown): void;
14
- };
15
- fatal: {
16
- (...args: unknown[]): void;
17
- var(key: string | Record<string, unknown>, value?: unknown): void;
18
- };
19
- info: {
20
- (...args: unknown[]): void;
21
- var(key: string | Record<string, unknown>, value?: unknown): void;
22
- };
23
- trace: {
24
- (...args: unknown[]): void;
25
- var(key: string | Record<string, unknown>, value?: unknown): void;
26
- };
27
- warn: {
28
- (...args: unknown[]): void;
29
- var(key: string | Record<string, unknown>, value?: unknown): void;
30
- };
31
- var(key: string | Record<string, unknown>, value?: unknown): void;
32
- with(tags: Record<string, unknown>): typeof defaultLog;
33
- tag(key: string | string[] | Record<string, unknown> | null, value?: string): void;
34
- untag(tags: string | string[] | Record<string, unknown> | null): void;
35
- lib(options: {
36
- level?: string;
37
- lib?: string;
38
- tags?: Record<string, unknown>;
39
- }): typeof defaultLog;
40
- };
5
+ export declare const getLogger: () => import("@jaypie/logger/dist/esm/JaypieLogger.js").default;
41
6
  export declare function initializeClient({ apiKey, }?: {
42
7
  apiKey?: string;
43
8
  }): Promise<OpenAI>;
@@ -1,41 +1,7 @@
1
- import { log as defaultLog } from "@jaypie/core";
2
- import { OpenRouter } from "@openrouter/sdk";
1
+ import type { OpenRouter } from "@openrouter/sdk";
3
2
  import { LlmMessageOptions } from "../../types/LlmProvider.interface.js";
4
- export declare const getLogger: () => {
5
- debug: {
6
- (...args: unknown[]): void;
7
- var(key: string | Record<string, unknown>, value?: unknown): void;
8
- };
9
- error: {
10
- (...args: unknown[]): void;
11
- var(key: string | Record<string, unknown>, value?: unknown): void;
12
- };
13
- fatal: {
14
- (...args: unknown[]): void;
15
- var(key: string | Record<string, unknown>, value?: unknown): void;
16
- };
17
- info: {
18
- (...args: unknown[]): void;
19
- var(key: string | Record<string, unknown>, value?: unknown): void;
20
- };
21
- trace: {
22
- (...args: unknown[]): void;
23
- var(key: string | Record<string, unknown>, value?: unknown): void;
24
- };
25
- warn: {
26
- (...args: unknown[]): void;
27
- var(key: string | Record<string, unknown>, value?: unknown): void;
28
- };
29
- var(key: string | Record<string, unknown>, value?: unknown): void;
30
- with(tags: Record<string, unknown>): typeof defaultLog;
31
- tag(key: string | string[] | Record<string, unknown> | null, value?: string): void;
32
- untag(tags: string | string[] | Record<string, unknown> | null): void;
33
- lib(options: {
34
- level?: string;
35
- lib?: string;
36
- tags?: Record<string, unknown>;
37
- }): typeof defaultLog;
38
- };
3
+ export declare function loadSdk(): Promise<typeof import("@openrouter/sdk")>;
4
+ export declare const getLogger: () => import("@jaypie/logger/dist/esm/JaypieLogger.js").default;
39
5
  export declare function initializeClient({ apiKey, }?: {
40
6
  apiKey?: string;
41
7
  }): Promise<OpenRouter>;
@@ -1,71 +1,2 @@
1
- import { log as defaultLog } from "@jaypie/core";
2
- export declare const getLogger: () => {
3
- debug: {
4
- (...args: unknown[]): void;
5
- var(key: string | Record<string, unknown>, value?: unknown): void;
6
- };
7
- error: {
8
- (...args: unknown[]): void;
9
- var(key: string | Record<string, unknown>, value?: unknown): void;
10
- };
11
- fatal: {
12
- (...args: unknown[]): void;
13
- var(key: string | Record<string, unknown>, value?: unknown): void;
14
- };
15
- info: {
16
- (...args: unknown[]): void;
17
- var(key: string | Record<string, unknown>, value?: unknown): void;
18
- };
19
- trace: {
20
- (...args: unknown[]): void;
21
- var(key: string | Record<string, unknown>, value?: unknown): void;
22
- };
23
- warn: {
24
- (...args: unknown[]): void;
25
- var(key: string | Record<string, unknown>, value?: unknown): void;
26
- };
27
- var(key: string | Record<string, unknown>, value?: unknown): void;
28
- with(tags: Record<string, unknown>): typeof defaultLog;
29
- tag(key: string | string[] | Record<string, unknown> | null, value?: string): void;
30
- untag(tags: string | string[] | Record<string, unknown> | null): void;
31
- lib(options: {
32
- level?: string;
33
- lib?: string;
34
- tags?: Record<string, unknown>;
35
- }): typeof defaultLog;
36
- };
37
- export declare const log: {
38
- debug: {
39
- (...args: unknown[]): void;
40
- var(key: string | Record<string, unknown>, value?: unknown): void;
41
- };
42
- error: {
43
- (...args: unknown[]): void;
44
- var(key: string | Record<string, unknown>, value?: unknown): void;
45
- };
46
- fatal: {
47
- (...args: unknown[]): void;
48
- var(key: string | Record<string, unknown>, value?: unknown): void;
49
- };
50
- info: {
51
- (...args: unknown[]): void;
52
- var(key: string | Record<string, unknown>, value?: unknown): void;
53
- };
54
- trace: {
55
- (...args: unknown[]): void;
56
- var(key: string | Record<string, unknown>, value?: unknown): void;
57
- };
58
- warn: {
59
- (...args: unknown[]): void;
60
- var(key: string | Record<string, unknown>, value?: unknown): void;
61
- };
62
- var(key: string | Record<string, unknown>, value?: unknown): void;
63
- with(tags: Record<string, unknown>): typeof defaultLog;
64
- tag(key: string | string[] | Record<string, unknown> | null, value?: string): void;
65
- untag(tags: string | string[] | Record<string, unknown> | null): void;
66
- lib(options: {
67
- level?: string;
68
- lib?: string;
69
- tags?: Record<string, unknown>;
70
- }): typeof defaultLog;
71
- };
1
+ export declare const getLogger: () => import("@jaypie/logger/dist/esm/JaypieLogger").default;
2
+ export declare const log: import("@jaypie/logger/dist/esm/JaypieLogger").default;
package/dist/esm/index.js CHANGED
@@ -1,13 +1,11 @@
1
1
  import { ConfigurationError, BadGatewayError, TooManyRequestsError, NotImplementedError } from '@jaypie/errors';
2
- import Anthropic, { RateLimitError, APIConnectionError, APIConnectionTimeoutError, InternalServerError, AuthenticationError, BadRequestError, NotFoundError, PermissionDeniedError } from '@anthropic-ai/sdk';
3
2
  import { z } from 'zod/v4';
4
- import { placeholders, log as log$2, JAYPIE, resolveValue, sleep, ConfigurationError as ConfigurationError$1 } from '@jaypie/core';
3
+ import { placeholders, JAYPIE, resolveValue, sleep } from '@jaypie/kit';
4
+ import { log as log$2 } from '@jaypie/logger';
5
5
  import RandomLib from 'random';
6
- import { RateLimitError as RateLimitError$1, APIConnectionError as APIConnectionError$1, APIConnectionTimeoutError as APIConnectionTimeoutError$1, InternalServerError as InternalServerError$1, APIUserAbortError, AuthenticationError as AuthenticationError$1, BadRequestError as BadRequestError$1, ConflictError, NotFoundError as NotFoundError$1, PermissionDeniedError as PermissionDeniedError$1, UnprocessableEntityError, OpenAI } from 'openai';
6
+ import { RateLimitError, APIConnectionError, APIConnectionTimeoutError, InternalServerError, APIUserAbortError, AuthenticationError, BadRequestError, ConflictError, NotFoundError, PermissionDeniedError, UnprocessableEntityError, OpenAI } from 'openai';
7
7
  import { zodResponseFormat } from 'openai/helpers/zod';
8
8
  import { getEnvSecret } from '@jaypie/aws';
9
- import { GoogleGenAI } from '@google/genai';
10
- import { OpenRouter } from '@openrouter/sdk';
11
9
  import { fetchWeatherApi } from 'openmeteo';
12
10
 
13
11
  const PROVIDER = {
@@ -690,16 +688,17 @@ var ErrorCategory;
690
688
  // Constants
691
689
  //
692
690
  const STRUCTURED_OUTPUT_TOOL_NAME$2 = "structured_output";
693
- const RETRYABLE_ERROR_TYPES$1 = [
694
- APIConnectionError,
695
- APIConnectionTimeoutError,
696
- InternalServerError,
691
+ // Error names for classification (using string names since SDK is optional)
692
+ const RETRYABLE_ERROR_NAMES = [
693
+ "APIConnectionError",
694
+ "APIConnectionTimeoutError",
695
+ "InternalServerError",
697
696
  ];
698
- const NOT_RETRYABLE_ERROR_TYPES$1 = [
699
- AuthenticationError,
700
- BadRequestError,
701
- NotFoundError,
702
- PermissionDeniedError,
697
+ const NOT_RETRYABLE_ERROR_NAMES = [
698
+ "AuthenticationError",
699
+ "BadRequestError",
700
+ "NotFoundError",
701
+ "PermissionDeniedError",
703
702
  ];
704
703
  //
705
704
  //
@@ -907,8 +906,9 @@ class AnthropicAdapter extends BaseProviderAdapter {
907
906
  // Error Classification
908
907
  //
909
908
  classifyError(error) {
909
+ const errorName = error?.constructor?.name;
910
910
  // Check for rate limit error
911
- if (error instanceof RateLimitError) {
911
+ if (errorName === "RateLimitError") {
912
912
  return {
913
913
  error,
914
914
  category: ErrorCategory.RateLimit,
@@ -917,24 +917,20 @@ class AnthropicAdapter extends BaseProviderAdapter {
917
917
  };
918
918
  }
919
919
  // Check for retryable errors
920
- for (const ErrorType of RETRYABLE_ERROR_TYPES$1) {
921
- if (error instanceof ErrorType) {
922
- return {
923
- error,
924
- category: ErrorCategory.Retryable,
925
- shouldRetry: true,
926
- };
927
- }
920
+ if (RETRYABLE_ERROR_NAMES.includes(errorName)) {
921
+ return {
922
+ error,
923
+ category: ErrorCategory.Retryable,
924
+ shouldRetry: true,
925
+ };
928
926
  }
929
927
  // Check for non-retryable errors
930
- for (const ErrorType of NOT_RETRYABLE_ERROR_TYPES$1) {
931
- if (error instanceof ErrorType) {
932
- return {
933
- error,
934
- category: ErrorCategory.Unrecoverable,
935
- shouldRetry: false,
936
- };
937
- }
928
+ if (NOT_RETRYABLE_ERROR_NAMES.includes(errorName)) {
929
+ return {
930
+ error,
931
+ category: ErrorCategory.Unrecoverable,
932
+ shouldRetry: false,
933
+ };
938
934
  }
939
935
  // Unknown error - treat as potentially retryable
940
936
  return {
@@ -1503,18 +1499,18 @@ const geminiAdapter = new GeminiAdapter();
1503
1499
  // Constants
1504
1500
  //
1505
1501
  const RETRYABLE_ERROR_TYPES = [
1506
- APIConnectionError$1,
1507
- APIConnectionTimeoutError$1,
1508
- InternalServerError$1,
1502
+ APIConnectionError,
1503
+ APIConnectionTimeoutError,
1504
+ InternalServerError,
1509
1505
  ];
1510
1506
  const NOT_RETRYABLE_ERROR_TYPES = [
1511
1507
  APIUserAbortError,
1512
- AuthenticationError$1,
1513
- BadRequestError$1,
1508
+ AuthenticationError,
1509
+ BadRequestError,
1514
1510
  ConflictError,
1515
- NotFoundError$1,
1516
- PermissionDeniedError$1,
1517
- RateLimitError$1,
1511
+ NotFoundError,
1512
+ PermissionDeniedError,
1513
+ RateLimitError,
1518
1514
  UnprocessableEntityError,
1519
1515
  ];
1520
1516
  //
@@ -1713,7 +1709,7 @@ class OpenAiAdapter extends BaseProviderAdapter {
1713
1709
  //
1714
1710
  classifyError(error) {
1715
1711
  // Check for rate limit error
1716
- if (error instanceof RateLimitError$1) {
1712
+ if (error instanceof RateLimitError) {
1717
1713
  return {
1718
1714
  error,
1719
1715
  category: ErrorCategory.RateLimit,
@@ -3153,6 +3149,19 @@ function createOperateLoop(config) {
3153
3149
  return new OperateLoop(config);
3154
3150
  }
3155
3151
 
3152
+ // SDK loader with caching
3153
+ let cachedSdk$2 = null;
3154
+ async function loadSdk$2() {
3155
+ if (cachedSdk$2)
3156
+ return cachedSdk$2;
3157
+ try {
3158
+ cachedSdk$2 = await import('@anthropic-ai/sdk');
3159
+ return cachedSdk$2;
3160
+ }
3161
+ catch {
3162
+ throw new ConfigurationError("@anthropic-ai/sdk is required but not installed. Run: npm install @anthropic-ai/sdk");
3163
+ }
3164
+ }
3156
3165
  // Logger
3157
3166
  const getLogger$3 = () => log$2.lib({ lib: JAYPIE.LIB.LLM });
3158
3167
  // Client initialization
@@ -3160,9 +3169,10 @@ async function initializeClient$3({ apiKey, } = {}) {
3160
3169
  const logger = getLogger$3();
3161
3170
  const resolvedApiKey = apiKey || (await getEnvSecret("ANTHROPIC_API_KEY"));
3162
3171
  if (!resolvedApiKey) {
3163
- throw new ConfigurationError$1("The application could not resolve the required API key: ANTHROPIC_API_KEY");
3172
+ throw new ConfigurationError("The application could not resolve the required API key: ANTHROPIC_API_KEY");
3164
3173
  }
3165
- const client = new Anthropic({ apiKey: resolvedApiKey });
3174
+ const sdk = await loadSdk$2();
3175
+ const client = new sdk.default({ apiKey: resolvedApiKey });
3166
3176
  logger.trace("Initialized Anthropic client");
3167
3177
  return client;
3168
3178
  }
@@ -3332,6 +3342,19 @@ class AnthropicProvider {
3332
3342
  }
3333
3343
  }
3334
3344
 
3345
+ // SDK loader with caching
3346
+ let cachedSdk$1 = null;
3347
+ async function loadSdk$1() {
3348
+ if (cachedSdk$1)
3349
+ return cachedSdk$1;
3350
+ try {
3351
+ cachedSdk$1 = await import('@google/genai');
3352
+ return cachedSdk$1;
3353
+ }
3354
+ catch {
3355
+ throw new ConfigurationError("@google/genai is required but not installed. Run: npm install @google/genai");
3356
+ }
3357
+ }
3335
3358
  // Logger
3336
3359
  const getLogger$2 = () => log$2.lib({ lib: JAYPIE.LIB.LLM });
3337
3360
  // Client initialization
@@ -3339,9 +3362,10 @@ async function initializeClient$2({ apiKey, } = {}) {
3339
3362
  const logger = getLogger$2();
3340
3363
  const resolvedApiKey = apiKey || (await getEnvSecret("GEMINI_API_KEY"));
3341
3364
  if (!resolvedApiKey) {
3342
- throw new ConfigurationError$1("The application could not resolve the requested keys");
3365
+ throw new ConfigurationError("The application could not resolve the requested keys");
3343
3366
  }
3344
- const client = new GoogleGenAI({ apiKey: resolvedApiKey });
3367
+ const sdk = await loadSdk$1();
3368
+ const client = new sdk.GoogleGenAI({ apiKey: resolvedApiKey });
3345
3369
  logger.trace("Initialized Gemini client");
3346
3370
  return client;
3347
3371
  }
@@ -3455,7 +3479,7 @@ async function initializeClient$1({ apiKey, } = {}) {
3455
3479
  const logger = getLogger$1();
3456
3480
  const resolvedApiKey = apiKey || (await getEnvSecret("OPENAI_API_KEY"));
3457
3481
  if (!resolvedApiKey) {
3458
- throw new ConfigurationError$1("The application could not resolve the requested keys");
3482
+ throw new ConfigurationError("The application could not resolve the requested keys");
3459
3483
  }
3460
3484
  const client = new OpenAI({ apiKey: resolvedApiKey });
3461
3485
  logger.trace("Initialized OpenAI client");
@@ -3596,6 +3620,19 @@ class OpenAiProvider {
3596
3620
  }
3597
3621
  }
3598
3622
 
3623
+ // SDK loader with caching
3624
+ let cachedSdk = null;
3625
+ async function loadSdk() {
3626
+ if (cachedSdk)
3627
+ return cachedSdk;
3628
+ try {
3629
+ cachedSdk = await import('@openrouter/sdk');
3630
+ return cachedSdk;
3631
+ }
3632
+ catch {
3633
+ throw new ConfigurationError("@openrouter/sdk is required but not installed. Run: npm install @openrouter/sdk");
3634
+ }
3635
+ }
3599
3636
  // Logger
3600
3637
  const getLogger = () => log$2.lib({ lib: JAYPIE.LIB.LLM });
3601
3638
  // Client initialization
@@ -3603,9 +3640,10 @@ async function initializeClient({ apiKey, } = {}) {
3603
3640
  const logger = getLogger();
3604
3641
  const resolvedApiKey = apiKey || (await getEnvSecret("OPENROUTER_API_KEY"));
3605
3642
  if (!resolvedApiKey) {
3606
- throw new ConfigurationError$1("The application could not resolve the requested keys");
3643
+ throw new ConfigurationError("The application could not resolve the requested keys");
3607
3644
  }
3608
- const client = new OpenRouter({ apiKey: resolvedApiKey });
3645
+ const sdk = await loadSdk();
3646
+ const client = new sdk.OpenRouter({ apiKey: resolvedApiKey });
3609
3647
  logger.trace("Initialized OpenRouter client");
3610
3648
  return client;
3611
3649
  }