@jaypie/llm 1.3.3 → 1.3.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.
Files changed (177) hide show
  1. package/dist/cjs/index.cjs +906 -145
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs/index.d.cts +13 -1
  4. package/dist/cjs/{index.d.ts → src/index.d.ts} +1 -0
  5. package/dist/cjs/{operate → src/operate}/adapters/AnthropicAdapter.d.ts +1 -1
  6. package/dist/{esm → cjs/src}/operate/adapters/OpenRouterAdapter.d.ts +8 -1
  7. package/dist/cjs/src/providers/anthropic/client.d.ts +54 -0
  8. package/dist/cjs/src/providers/anthropic/types.d.ts +129 -0
  9. package/dist/{esm → cjs/src}/providers/anthropic/utils.d.ts +5 -5
  10. package/dist/cjs/src/providers/google/client.d.ts +44 -0
  11. package/dist/cjs/{providers → src/providers}/google/utils.d.ts +2 -3
  12. package/dist/cjs/src/providers/openai/client.d.ts +74 -0
  13. package/dist/cjs/src/providers/openai/responseFormat.d.ts +17 -0
  14. package/dist/{esm → cjs/src}/providers/openai/utils.d.ts +4 -4
  15. package/dist/cjs/src/providers/openrouter/client.d.ts +40 -0
  16. package/dist/{esm → cjs/src}/providers/openrouter/utils.d.ts +2 -3
  17. package/dist/cjs/{providers → src/providers}/xai/utils.d.ts +2 -2
  18. package/dist/cjs/{util → src/util}/index.d.ts +2 -0
  19. package/dist/cjs/src/util/jsonSchema.d.ts +17 -0
  20. package/dist/cjs/src/util/sse.d.ts +12 -0
  21. package/dist/esm/index.d.ts +13 -1
  22. package/dist/esm/index.js +917 -158
  23. package/dist/esm/index.js.map +1 -1
  24. package/dist/esm/src/index.d.ts +17 -0
  25. package/dist/esm/{operate → src/operate}/adapters/AnthropicAdapter.d.ts +1 -1
  26. package/dist/{cjs → esm/src}/operate/adapters/OpenRouterAdapter.d.ts +8 -1
  27. package/dist/esm/src/providers/anthropic/client.d.ts +54 -0
  28. package/dist/esm/src/providers/anthropic/types.d.ts +129 -0
  29. package/dist/{cjs → esm/src}/providers/anthropic/utils.d.ts +5 -5
  30. package/dist/esm/src/providers/google/client.d.ts +44 -0
  31. package/dist/esm/{providers → src/providers}/google/utils.d.ts +2 -3
  32. package/dist/esm/src/providers/openai/client.d.ts +74 -0
  33. package/dist/esm/src/providers/openai/responseFormat.d.ts +17 -0
  34. package/dist/{cjs → esm/src}/providers/openai/utils.d.ts +4 -4
  35. package/dist/esm/src/providers/openrouter/client.d.ts +40 -0
  36. package/dist/{cjs → esm/src}/providers/openrouter/utils.d.ts +2 -3
  37. package/dist/esm/{providers → src/providers}/xai/utils.d.ts +2 -2
  38. package/dist/esm/{util → src/util}/index.d.ts +2 -0
  39. package/dist/esm/src/util/jsonSchema.d.ts +17 -0
  40. package/dist/esm/src/util/sse.d.ts +12 -0
  41. package/package.json +4 -19
  42. package/dist/cjs/providers/anthropic/types.d.ts +0 -2
  43. package/dist/esm/providers/anthropic/types.d.ts +0 -2
  44. /package/dist/cjs/{Llm.d.ts → src/Llm.d.ts} +0 -0
  45. /package/dist/cjs/{constants.d.ts → src/constants.d.ts} +0 -0
  46. /package/dist/cjs/{observability → src/observability}/llmobs.d.ts +0 -0
  47. /package/dist/cjs/{operate → src/operate}/OperateLoop.d.ts +0 -0
  48. /package/dist/cjs/{operate → src/operate}/StreamLoop.d.ts +0 -0
  49. /package/dist/cjs/{operate → src/operate}/adapters/BedrockAdapter.d.ts +0 -0
  50. /package/dist/cjs/{operate → src/operate}/adapters/GoogleAdapter.d.ts +0 -0
  51. /package/dist/cjs/{operate → src/operate}/adapters/OpenAiAdapter.d.ts +0 -0
  52. /package/dist/cjs/{operate → src/operate}/adapters/ProviderAdapter.interface.d.ts +0 -0
  53. /package/dist/cjs/{operate → src/operate}/adapters/XaiAdapter.d.ts +0 -0
  54. /package/dist/cjs/{operate → src/operate}/adapters/index.d.ts +0 -0
  55. /package/dist/cjs/{operate → src/operate}/hooks/HookRunner.d.ts +0 -0
  56. /package/dist/cjs/{operate → src/operate}/hooks/index.d.ts +0 -0
  57. /package/dist/cjs/{operate → src/operate}/index.d.ts +0 -0
  58. /package/dist/cjs/{operate → src/operate}/input/InputProcessor.d.ts +0 -0
  59. /package/dist/cjs/{operate → src/operate}/input/index.d.ts +0 -0
  60. /package/dist/cjs/{operate → src/operate}/response/ResponseBuilder.d.ts +0 -0
  61. /package/dist/cjs/{operate → src/operate}/response/index.d.ts +0 -0
  62. /package/dist/cjs/{operate → src/operate}/retry/RetryExecutor.d.ts +0 -0
  63. /package/dist/cjs/{operate → src/operate}/retry/RetryPolicy.d.ts +0 -0
  64. /package/dist/cjs/{operate → src/operate}/retry/createStaleRejectionGuard.d.ts +0 -0
  65. /package/dist/cjs/{operate → src/operate}/retry/index.d.ts +0 -0
  66. /package/dist/cjs/{operate → src/operate}/retry/isTransientNetworkError.d.ts +0 -0
  67. /package/dist/cjs/{operate → src/operate}/types.d.ts +0 -0
  68. /package/dist/cjs/{providers → src/providers}/anthropic/AnthropicProvider.class.d.ts +0 -0
  69. /package/dist/cjs/{providers → src/providers}/anthropic/index.d.ts +0 -0
  70. /package/dist/cjs/{providers → src/providers}/bedrock/BedrockProvider.class.d.ts +0 -0
  71. /package/dist/cjs/{providers → src/providers}/bedrock/index.d.ts +0 -0
  72. /package/dist/cjs/{providers → src/providers}/bedrock/utils.d.ts +0 -0
  73. /package/dist/cjs/{providers → src/providers}/google/GoogleProvider.class.d.ts +0 -0
  74. /package/dist/cjs/{providers → src/providers}/google/index.d.ts +0 -0
  75. /package/dist/cjs/{providers → src/providers}/google/types.d.ts +0 -0
  76. /package/dist/cjs/{providers → src/providers}/openai/OpenAiProvider.class.d.ts +0 -0
  77. /package/dist/cjs/{providers → src/providers}/openai/index.d.ts +0 -0
  78. /package/dist/cjs/{providers → src/providers}/openai/types.d.ts +0 -0
  79. /package/dist/cjs/{providers → src/providers}/openrouter/OpenRouterProvider.class.d.ts +0 -0
  80. /package/dist/cjs/{providers → src/providers}/openrouter/index.d.ts +0 -0
  81. /package/dist/cjs/{providers → src/providers}/xai/XaiProvider.class.d.ts +0 -0
  82. /package/dist/cjs/{providers → src/providers}/xai/index.d.ts +0 -0
  83. /package/dist/cjs/{tools → src/tools}/Toolkit.class.d.ts +0 -0
  84. /package/dist/cjs/{tools → src/tools}/index.d.ts +0 -0
  85. /package/dist/cjs/{tools → src/tools}/random.d.ts +0 -0
  86. /package/dist/cjs/{tools → src/tools}/roll.d.ts +0 -0
  87. /package/dist/cjs/{tools → src/tools}/time.d.ts +0 -0
  88. /package/dist/cjs/{tools → src/tools}/weather.d.ts +0 -0
  89. /package/dist/cjs/{types → src/types}/LlmOperateInput.guards.d.ts +0 -0
  90. /package/dist/cjs/{types → src/types}/LlmProvider.interface.d.ts +0 -0
  91. /package/dist/cjs/{types → src/types}/LlmStreamChunk.interface.d.ts +0 -0
  92. /package/dist/cjs/{types → src/types}/LlmTool.interface.d.ts +0 -0
  93. /package/dist/cjs/{upload → src/upload}/detectMimeType.d.ts +0 -0
  94. /package/dist/cjs/{upload → src/upload}/extractPdfPages.d.ts +0 -0
  95. /package/dist/cjs/{upload → src/upload}/index.d.ts +0 -0
  96. /package/dist/cjs/{upload → src/upload}/loadLocalFile.d.ts +0 -0
  97. /package/dist/cjs/{upload → src/upload}/loadS3File.d.ts +0 -0
  98. /package/dist/cjs/{upload → src/upload}/resolveOperateInput.d.ts +0 -0
  99. /package/dist/cjs/{util → src/util}/determineModelProvider.d.ts +0 -0
  100. /package/dist/cjs/{util → src/util}/extractReasoning.d.ts +0 -0
  101. /package/dist/cjs/{util → src/util}/fillFormatArrays.d.ts +0 -0
  102. /package/dist/cjs/{util → src/util}/formatOperateInput.d.ts +0 -0
  103. /package/dist/cjs/{util → src/util}/formatOperateMessage.d.ts +0 -0
  104. /package/dist/cjs/{util → src/util}/jsonSchemaToOpenApi3.d.ts +0 -0
  105. /package/dist/cjs/{util → src/util}/logger.d.ts +0 -0
  106. /package/dist/cjs/{util → src/util}/maxTurnsFromOptions.d.ts +0 -0
  107. /package/dist/cjs/{util → src/util}/naturalZodSchema.d.ts +0 -0
  108. /package/dist/cjs/{util → src/util}/random.d.ts +0 -0
  109. /package/dist/cjs/{util → src/util}/repairFormatKeys.d.ts +0 -0
  110. /package/dist/cjs/{util → src/util}/tryParseNumber.d.ts +0 -0
  111. /package/dist/esm/{Llm.d.ts → src/Llm.d.ts} +0 -0
  112. /package/dist/esm/{constants.d.ts → src/constants.d.ts} +0 -0
  113. /package/dist/esm/{observability → src/observability}/llmobs.d.ts +0 -0
  114. /package/dist/esm/{operate → src/operate}/OperateLoop.d.ts +0 -0
  115. /package/dist/esm/{operate → src/operate}/StreamLoop.d.ts +0 -0
  116. /package/dist/esm/{operate → src/operate}/adapters/BedrockAdapter.d.ts +0 -0
  117. /package/dist/esm/{operate → src/operate}/adapters/GoogleAdapter.d.ts +0 -0
  118. /package/dist/esm/{operate → src/operate}/adapters/OpenAiAdapter.d.ts +0 -0
  119. /package/dist/esm/{operate → src/operate}/adapters/ProviderAdapter.interface.d.ts +0 -0
  120. /package/dist/esm/{operate → src/operate}/adapters/XaiAdapter.d.ts +0 -0
  121. /package/dist/esm/{operate → src/operate}/adapters/index.d.ts +0 -0
  122. /package/dist/esm/{operate → src/operate}/hooks/HookRunner.d.ts +0 -0
  123. /package/dist/esm/{operate → src/operate}/hooks/index.d.ts +0 -0
  124. /package/dist/esm/{operate → src/operate}/index.d.ts +0 -0
  125. /package/dist/esm/{operate → src/operate}/input/InputProcessor.d.ts +0 -0
  126. /package/dist/esm/{operate → src/operate}/input/index.d.ts +0 -0
  127. /package/dist/esm/{operate → src/operate}/response/ResponseBuilder.d.ts +0 -0
  128. /package/dist/esm/{operate → src/operate}/response/index.d.ts +0 -0
  129. /package/dist/esm/{operate → src/operate}/retry/RetryExecutor.d.ts +0 -0
  130. /package/dist/esm/{operate → src/operate}/retry/RetryPolicy.d.ts +0 -0
  131. /package/dist/esm/{operate → src/operate}/retry/createStaleRejectionGuard.d.ts +0 -0
  132. /package/dist/esm/{operate → src/operate}/retry/index.d.ts +0 -0
  133. /package/dist/esm/{operate → src/operate}/retry/isTransientNetworkError.d.ts +0 -0
  134. /package/dist/esm/{operate → src/operate}/types.d.ts +0 -0
  135. /package/dist/esm/{providers → src/providers}/anthropic/AnthropicProvider.class.d.ts +0 -0
  136. /package/dist/esm/{providers → src/providers}/anthropic/index.d.ts +0 -0
  137. /package/dist/esm/{providers → src/providers}/bedrock/BedrockProvider.class.d.ts +0 -0
  138. /package/dist/esm/{providers → src/providers}/bedrock/index.d.ts +0 -0
  139. /package/dist/esm/{providers → src/providers}/bedrock/utils.d.ts +0 -0
  140. /package/dist/esm/{providers → src/providers}/google/GoogleProvider.class.d.ts +0 -0
  141. /package/dist/esm/{providers → src/providers}/google/index.d.ts +0 -0
  142. /package/dist/esm/{providers → src/providers}/google/types.d.ts +0 -0
  143. /package/dist/esm/{providers → src/providers}/openai/OpenAiProvider.class.d.ts +0 -0
  144. /package/dist/esm/{providers → src/providers}/openai/index.d.ts +0 -0
  145. /package/dist/esm/{providers → src/providers}/openai/types.d.ts +0 -0
  146. /package/dist/esm/{providers → src/providers}/openrouter/OpenRouterProvider.class.d.ts +0 -0
  147. /package/dist/esm/{providers → src/providers}/openrouter/index.d.ts +0 -0
  148. /package/dist/esm/{providers → src/providers}/xai/XaiProvider.class.d.ts +0 -0
  149. /package/dist/esm/{providers → src/providers}/xai/index.d.ts +0 -0
  150. /package/dist/esm/{tools → src/tools}/Toolkit.class.d.ts +0 -0
  151. /package/dist/esm/{tools → src/tools}/index.d.ts +0 -0
  152. /package/dist/esm/{tools → src/tools}/random.d.ts +0 -0
  153. /package/dist/esm/{tools → src/tools}/roll.d.ts +0 -0
  154. /package/dist/esm/{tools → src/tools}/time.d.ts +0 -0
  155. /package/dist/esm/{tools → src/tools}/weather.d.ts +0 -0
  156. /package/dist/esm/{types → src/types}/LlmOperateInput.guards.d.ts +0 -0
  157. /package/dist/esm/{types → src/types}/LlmProvider.interface.d.ts +0 -0
  158. /package/dist/esm/{types → src/types}/LlmStreamChunk.interface.d.ts +0 -0
  159. /package/dist/esm/{types → src/types}/LlmTool.interface.d.ts +0 -0
  160. /package/dist/esm/{upload → src/upload}/detectMimeType.d.ts +0 -0
  161. /package/dist/esm/{upload → src/upload}/extractPdfPages.d.ts +0 -0
  162. /package/dist/esm/{upload → src/upload}/index.d.ts +0 -0
  163. /package/dist/esm/{upload → src/upload}/loadLocalFile.d.ts +0 -0
  164. /package/dist/esm/{upload → src/upload}/loadS3File.d.ts +0 -0
  165. /package/dist/esm/{upload → src/upload}/resolveOperateInput.d.ts +0 -0
  166. /package/dist/esm/{util → src/util}/determineModelProvider.d.ts +0 -0
  167. /package/dist/esm/{util → src/util}/extractReasoning.d.ts +0 -0
  168. /package/dist/esm/{util → src/util}/fillFormatArrays.d.ts +0 -0
  169. /package/dist/esm/{util → src/util}/formatOperateInput.d.ts +0 -0
  170. /package/dist/esm/{util → src/util}/formatOperateMessage.d.ts +0 -0
  171. /package/dist/esm/{util → src/util}/jsonSchemaToOpenApi3.d.ts +0 -0
  172. /package/dist/esm/{util → src/util}/logger.d.ts +0 -0
  173. /package/dist/esm/{util → src/util}/maxTurnsFromOptions.d.ts +0 -0
  174. /package/dist/esm/{util → src/util}/naturalZodSchema.d.ts +0 -0
  175. /package/dist/esm/{util → src/util}/random.d.ts +0 -0
  176. /package/dist/esm/{util → src/util}/repairFormatKeys.d.ts +0 -0
  177. /package/dist/esm/{util → src/util}/tryParseNumber.d.ts +0 -0
@@ -0,0 +1,17 @@
1
+ export { default as Llm } from "./Llm.js";
2
+ export * as LLM from "./constants.js";
3
+ export type { LlmFallbackConfig, LlmHistory, LlmInputContent, LlmInputContentFile, LlmInputContentImage, LlmInputContentText, LlmInputMessage, LlmMessageOptions, LlmOperateInput, LlmOperateInputContent, LlmOperateInputFile, LlmOperateInputImage, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProvider, } from "./types/LlmProvider.interface.js";
4
+ export { LlmMessageRole, LlmMessageType, } from "./types/LlmProvider.interface.js";
5
+ export { isLlmOperateInput, isLlmOperateInputContent, isLlmOperateInputFile, isLlmOperateInputImage, } from "./types/LlmOperateInput.guards.js";
6
+ export type { LlmTool } from "./types/LlmTool.interface.js";
7
+ export type { LlmStreamChunk, LlmStreamChunkDone, LlmStreamChunkError, LlmStreamChunkText, LlmStreamChunkToolCall, LlmStreamChunkToolResult, } from "./types/LlmStreamChunk.interface.js";
8
+ export { LlmStreamChunkType } from "./types/LlmStreamChunk.interface.js";
9
+ export { JaypieToolkit, toolkit, Toolkit, tools } from "./tools/index.js";
10
+ export { extractReasoning } from "./util/extractReasoning.js";
11
+ export { jsonSchemaToNaturalSchema, naturalSchemaToJsonSchema, } from "./util/jsonSchema.js";
12
+ export { BedrockProvider } from "./providers/bedrock/index.js";
13
+ /** @deprecated Use GoogleProvider — "Google" is the provider; Gemini is the model family */
14
+ export { GoogleProvider as GeminiProvider } from "./providers/google/index.js";
15
+ export { GoogleProvider } from "./providers/google/index.js";
16
+ export { OpenRouterProvider } from "./providers/openrouter/index.js";
17
+ export { XaiProvider } from "./providers/xai/index.js";
@@ -1,10 +1,10 @@
1
- import type { Anthropic } from "@anthropic-ai/sdk";
2
1
  import { JsonObject, NaturalSchema } from "@jaypie/types";
3
2
  import { z } from "zod/v4";
4
3
  import { Toolkit } from "../../tools/Toolkit.class.js";
5
4
  import { LlmHistory, LlmOperateOptions, LlmUsageItem } from "../../types/LlmProvider.interface.js";
6
5
  import { LlmStreamChunk } from "../../types/LlmStreamChunk.interface.js";
7
6
  import { ClassifiedError, OperateRequest, ParsedResponse, ProviderToolDefinition, StandardToolCall, StandardToolResult } from "../types.js";
7
+ import { Anthropic } from "../../providers/anthropic/types.js";
8
8
  import { BaseProviderAdapter } from "./ProviderAdapter.interface.js";
9
9
  /**
10
10
  * Local extension of the SDK's `MessageCreateParams` to carry
@@ -129,7 +129,14 @@ export declare class OpenRouterAdapter extends BaseProviderAdapter {
129
129
  * camelCase shape, forwarding only the fields we care about (the SDK
130
130
  * silently strips unknown fields).
131
131
  */
132
- private toSdkChatParams;
132
+ /**
133
+ * Serialize the internal request into the OpenAI-compatible wire body for
134
+ * OpenRouter's Chat Completions endpoint. Top-level fields (model, tools,
135
+ * tool_choice, response_format, user, temperature, and any providerOptions)
136
+ * are already wire-shaped (snake_case); only messages carry camelCase tool
137
+ * fields that must become snake_case on the wire.
138
+ */
139
+ private toWireBody;
133
140
  /**
134
141
  * Rebuild a structured-output request without `response_format`, swapping in
135
142
  * the legacy fake-tool emulation. Used as a runtime fallback when a model
@@ -0,0 +1,54 @@
1
+ import { Anthropic } from "./types.js";
2
+ export declare class AnthropicApiError extends Error {
3
+ readonly status: number;
4
+ readonly error?: {
5
+ message?: string;
6
+ };
7
+ constructor(status: number, message: string, error?: {
8
+ message?: string;
9
+ });
10
+ }
11
+ export declare class BadRequestError extends AnthropicApiError {
12
+ }
13
+ export declare class AuthenticationError extends AnthropicApiError {
14
+ }
15
+ export declare class PermissionDeniedError extends AnthropicApiError {
16
+ }
17
+ export declare class NotFoundError extends AnthropicApiError {
18
+ }
19
+ export declare class RateLimitError extends AnthropicApiError {
20
+ }
21
+ export declare class InternalServerError extends AnthropicApiError {
22
+ }
23
+ export declare class APIConnectionError extends AnthropicApiError {
24
+ }
25
+ export interface AnthropicClientOptions {
26
+ apiKey: string;
27
+ baseURL?: string;
28
+ }
29
+ export interface CreateOptions {
30
+ signal?: AbortSignal;
31
+ }
32
+ interface MessagesApi {
33
+ create(params: Anthropic.MessageCreateParamsStreaming, options?: CreateOptions): Promise<AsyncIterable<Anthropic.MessageStreamEvent>>;
34
+ create(params: Anthropic.MessageCreateParams, options?: CreateOptions): Promise<Anthropic.Message>;
35
+ }
36
+ /**
37
+ * Minimal `fetch`-based client for Anthropic's Messages API. Replaces
38
+ * `@anthropic-ai/sdk` — the adapter only needs `messages.create` (streaming and
39
+ * non-streaming), header auth, and HTTP errors whose class names drive
40
+ * `classifyError`. Internal request params are already Anthropic's wire shape,
41
+ * so they serialize verbatim. Exposes a `messages` facade mirroring the SDK so
42
+ * the adapter call sites are unchanged.
43
+ */
44
+ export declare class AnthropicClient {
45
+ private readonly apiKey;
46
+ private readonly baseURL;
47
+ readonly messages: MessagesApi;
48
+ constructor({ apiKey, baseURL, }: AnthropicClientOptions);
49
+ private headers;
50
+ private toError;
51
+ private createMessage;
52
+ private createStream;
53
+ }
54
+ export {};
@@ -0,0 +1,129 @@
1
+ import { JsonObject } from "@jaypie/types";
2
+ import { LlmMessageRole } from "../../types/LlmProvider.interface.js";
3
+ export declare const ROLE_MAP: Record<LlmMessageRole, string>;
4
+ export declare namespace Anthropic {
5
+ interface TextBlock {
6
+ type: "text";
7
+ text: string;
8
+ }
9
+ interface ToolUseBlock {
10
+ type: "tool_use";
11
+ id: string;
12
+ name: string;
13
+ input: unknown;
14
+ }
15
+ interface ThinkingBlock {
16
+ type: "thinking";
17
+ thinking: string;
18
+ signature?: string;
19
+ }
20
+ type ContentBlock = TextBlock | ToolUseBlock | ThinkingBlock;
21
+ interface Base64ImageSource {
22
+ type: "base64";
23
+ media_type: string;
24
+ data: string;
25
+ }
26
+ interface Base64PDFSource {
27
+ type: "base64";
28
+ media_type: string;
29
+ data: string;
30
+ }
31
+ interface ToolResultBlockParam {
32
+ type: "tool_result";
33
+ tool_use_id: string;
34
+ content: string;
35
+ }
36
+ type ContentBlockParam = {
37
+ type: "text";
38
+ text: string;
39
+ } | {
40
+ type: "image";
41
+ source: Base64ImageSource | {
42
+ type: "url";
43
+ url: string;
44
+ };
45
+ } | {
46
+ type: "document";
47
+ source: Base64PDFSource | {
48
+ type: "url";
49
+ url: string;
50
+ };
51
+ } | ToolUseBlock | ToolResultBlockParam;
52
+ interface MessageParam {
53
+ role: "user" | "assistant";
54
+ content: string | ContentBlockParam[];
55
+ }
56
+ namespace Messages {
57
+ namespace Tool {
58
+ type InputSchema = JsonObject;
59
+ }
60
+ }
61
+ interface Tool {
62
+ name: string;
63
+ description?: string;
64
+ input_schema: Messages.Tool.InputSchema;
65
+ type?: "custom";
66
+ }
67
+ interface Usage {
68
+ input_tokens: number;
69
+ output_tokens: number;
70
+ thinking_tokens?: number;
71
+ }
72
+ interface MessageCreateParams {
73
+ model: string;
74
+ messages: MessageParam[];
75
+ max_tokens: number;
76
+ system?: string;
77
+ tools?: Tool[];
78
+ tool_choice?: {
79
+ type: "auto" | "any" | "tool";
80
+ name?: string;
81
+ };
82
+ temperature?: number;
83
+ stream?: boolean;
84
+ [key: string]: unknown;
85
+ }
86
+ type MessageCreateParamsStreaming = MessageCreateParams & {
87
+ stream: true;
88
+ };
89
+ interface Message {
90
+ id: string;
91
+ type: "message";
92
+ role: "assistant";
93
+ model: string;
94
+ content: ContentBlock[];
95
+ stop_reason: string | null;
96
+ stop_sequence?: string | null;
97
+ usage: Usage;
98
+ }
99
+ type ContentBlockDelta = {
100
+ type: "text_delta";
101
+ text: string;
102
+ } | {
103
+ type: "input_json_delta";
104
+ partial_json: string;
105
+ };
106
+ type MessageStreamEvent = {
107
+ type: "message_start";
108
+ message: Message;
109
+ } | {
110
+ type: "content_block_start";
111
+ index: number;
112
+ content_block: ContentBlock;
113
+ } | {
114
+ type: "content_block_delta";
115
+ index: number;
116
+ delta: ContentBlockDelta;
117
+ } | {
118
+ type: "content_block_stop";
119
+ index: number;
120
+ } | {
121
+ type: "message_delta";
122
+ delta: Record<string, unknown>;
123
+ usage: Usage;
124
+ } | {
125
+ type: "message_stop";
126
+ } | {
127
+ type: "ping";
128
+ };
129
+ }
@@ -1,15 +1,15 @@
1
1
  import { createLogger } from "@jaypie/logger";
2
- 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 function loadSdk(): Promise<typeof import("@anthropic-ai/sdk")>;
5
+ import { AnthropicClient } from "./client.js";
6
+ import type { Anthropic } from "./types.js";
7
7
  export declare const getLogger: () => ReturnType<typeof createLogger>;
8
8
  export declare function initializeClient({ apiKey, }?: {
9
9
  apiKey?: string;
10
- }): Promise<Anthropic>;
10
+ }): Promise<AnthropicClient>;
11
11
  export declare function formatSystemMessage(systemPrompt: string, { data, placeholders }?: Pick<LlmMessageOptions, "data" | "placeholders">): string;
12
12
  export declare function formatUserMessage(message: string, { data, placeholders }?: Pick<LlmMessageOptions, "data" | "placeholders">): Anthropic.MessageParam;
13
13
  export declare function prepareMessages(message: string, { data, placeholders }?: LlmMessageOptions): Anthropic.MessageParam[];
14
- export declare function createTextCompletion(client: Anthropic, messages: Anthropic.MessageParam[], model: string, systemMessage?: string): Promise<string>;
15
- export declare function createStructuredCompletion(client: Anthropic, messages: Anthropic.MessageParam[], model: string, responseSchema: z.ZodType | NaturalSchema, systemMessage?: string): Promise<JsonObject>;
14
+ export declare function createTextCompletion(client: AnthropicClient, messages: Anthropic.MessageParam[], model: string, systemMessage?: string): Promise<string>;
15
+ export declare function createStructuredCompletion(client: AnthropicClient, messages: Anthropic.MessageParam[], model: string, responseSchema: z.ZodType | NaturalSchema, systemMessage?: string): Promise<JsonObject>;
@@ -0,0 +1,44 @@
1
+ import { GeminiContent, GeminiGenerateContentConfig, GeminiRawResponse } from "./types.js";
2
+ export interface GoogleClientOptions {
3
+ apiKey: string;
4
+ baseURL?: string;
5
+ }
6
+ export interface GenerateContentParams {
7
+ model: string;
8
+ contents: GeminiContent[];
9
+ config?: GeminiGenerateContentConfig;
10
+ }
11
+ export interface GenerateContentOptions {
12
+ signal?: AbortSignal;
13
+ }
14
+ /**
15
+ * HTTP error carrying the upstream status and parsed API message. The
16
+ * GoogleAdapter classifies errors by reading `.status` / `.code` and
17
+ * `.message`, so this shape keeps `classifyError` working unchanged after
18
+ * dropping the SDK.
19
+ */
20
+ export declare class GoogleHttpError extends Error {
21
+ readonly status: number;
22
+ readonly code: number;
23
+ constructor(status: number, message: string);
24
+ }
25
+ /**
26
+ * Minimal `fetch`-based client for Google's Generative Language (Gemini) REST
27
+ * API. Replaces `@google/genai` — the adapter only needs `generateContent`
28
+ * (streaming and non-streaming), an api-key header, and HTTP error surfacing.
29
+ * Exposes a `models` facade mirroring the SDK so the adapter call sites are
30
+ * unchanged.
31
+ */
32
+ export declare class GoogleClient {
33
+ private readonly apiKey;
34
+ private readonly baseURL;
35
+ readonly models: {
36
+ generateContent: (params: GenerateContentParams, options?: GenerateContentOptions) => Promise<GeminiRawResponse>;
37
+ generateContentStream: (params: GenerateContentParams, options?: GenerateContentOptions) => Promise<AsyncIterable<GeminiRawResponse>>;
38
+ };
39
+ constructor({ apiKey, baseURL }: GoogleClientOptions);
40
+ private headers;
41
+ private toError;
42
+ private generateContent;
43
+ private generateContentStream;
44
+ }
@@ -1,11 +1,10 @@
1
1
  import { createLogger } from "@jaypie/logger";
2
- import type { GoogleGenAI } from "@google/genai";
3
2
  import { LlmMessageOptions } from "../../types/LlmProvider.interface.js";
4
- export declare function loadSdk(): Promise<typeof import("@google/genai")>;
3
+ import { GoogleClient } from "./client.js";
5
4
  export declare const getLogger: () => ReturnType<typeof createLogger>;
6
5
  export declare function initializeClient({ apiKey, }?: {
7
6
  apiKey?: string;
8
- }): Promise<GoogleGenAI>;
7
+ }): Promise<GoogleClient>;
9
8
  export interface ChatMessage {
10
9
  role: "user" | "model";
11
10
  content: string;
@@ -0,0 +1,74 @@
1
+ import { JsonObject } from "@jaypie/types";
2
+ export declare class OpenAiApiError extends Error {
3
+ readonly status: number;
4
+ readonly error?: {
5
+ message?: string;
6
+ };
7
+ constructor(status: number, message: string, error?: {
8
+ message?: string;
9
+ });
10
+ }
11
+ export declare class BadRequestError extends OpenAiApiError {
12
+ }
13
+ export declare class AuthenticationError extends OpenAiApiError {
14
+ }
15
+ export declare class PermissionDeniedError extends OpenAiApiError {
16
+ }
17
+ export declare class NotFoundError extends OpenAiApiError {
18
+ }
19
+ export declare class ConflictError extends OpenAiApiError {
20
+ }
21
+ export declare class UnprocessableEntityError extends OpenAiApiError {
22
+ }
23
+ export declare class RateLimitError extends OpenAiApiError {
24
+ }
25
+ export declare class InternalServerError extends OpenAiApiError {
26
+ }
27
+ export declare class APIConnectionError extends OpenAiApiError {
28
+ }
29
+ export declare class APIConnectionTimeoutError extends APIConnectionError {
30
+ }
31
+ export declare class APIUserAbortError extends OpenAiApiError {
32
+ }
33
+ export interface OpenAIClientOptions {
34
+ apiKey: string;
35
+ baseURL?: string;
36
+ }
37
+ export interface RequestOptions {
38
+ signal?: AbortSignal;
39
+ }
40
+ interface ResponsesApi {
41
+ create(params: Record<string, unknown> & {
42
+ stream: true;
43
+ }, options?: RequestOptions): Promise<AsyncIterable<Record<string, unknown>>>;
44
+ create(params: Record<string, unknown>, options?: RequestOptions): Promise<JsonObject>;
45
+ }
46
+ interface ChatCompletionsApi {
47
+ create(params: Record<string, unknown>, options?: RequestOptions): Promise<JsonObject>;
48
+ parse(params: Record<string, unknown>, options?: RequestOptions): Promise<JsonObject>;
49
+ }
50
+ /**
51
+ * Minimal `fetch`-based client for the OpenAI API. Replaces the `openai` SDK —
52
+ * the adapters and provider utilities only need the Responses API
53
+ * (`/responses`, streaming and non-streaming) for `operate`/`stream` and the
54
+ * Chat Completions API (`/chat/completions`, plus a `parse` helper for
55
+ * structured output) for `send`. Mirrors the SDK's `responses.create` and
56
+ * `chat.completions.create` / `chat.completions.parse` surface so call sites are
57
+ * unchanged. Also serves xAI via a custom `baseURL`.
58
+ */
59
+ export declare class OpenAIClient {
60
+ private readonly apiKey;
61
+ private readonly baseURL;
62
+ readonly responses: ResponsesApi;
63
+ readonly chat: {
64
+ completions: ChatCompletionsApi;
65
+ };
66
+ constructor({ apiKey, baseURL }: OpenAIClientOptions);
67
+ private headers;
68
+ private post;
69
+ private toError;
70
+ private createResponse;
71
+ private createResponseStream;
72
+ private chatCompletion;
73
+ }
74
+ export {};
@@ -0,0 +1,17 @@
1
+ import { JsonObject } from "@jaypie/types";
2
+ import { z } from "zod/v4";
3
+ export interface JsonSchemaResponseFormat {
4
+ type: "json_schema";
5
+ json_schema: {
6
+ name: string;
7
+ strict: boolean;
8
+ schema: JsonObject;
9
+ };
10
+ }
11
+ /**
12
+ * Local replacement for `openai/helpers/zod`'s `zodResponseFormat`. Builds the
13
+ * `response_format` payload OpenAI's Chat Completions / Responses APIs expect
14
+ * from a Zod schema. The SDK always emits `strict: true`; callers re-derive or
15
+ * sanitize `schema` as needed (e.g. forcing `additionalProperties: false`).
16
+ */
17
+ export declare function zodResponseFormat(schema: z.ZodType, name: string): JsonSchemaResponseFormat;
@@ -1,12 +1,12 @@
1
1
  import { createLogger } from "@jaypie/logger";
2
2
  import { JsonObject, NaturalSchema } from "@jaypie/types";
3
- import { OpenAI } from "openai";
4
3
  import { z } from "zod/v4";
5
4
  import { LlmMessageOptions } from "../../types/LlmProvider.interface.js";
5
+ import { OpenAIClient } from "./client.js";
6
6
  export declare const getLogger: () => ReturnType<typeof createLogger>;
7
7
  export declare function initializeClient({ apiKey, }?: {
8
8
  apiKey?: string;
9
- }): Promise<OpenAI>;
9
+ }): Promise<OpenAIClient>;
10
10
  export interface ChatMessage {
11
11
  role: "user" | "developer";
12
12
  content: string;
@@ -14,12 +14,12 @@ export interface ChatMessage {
14
14
  export declare function formatSystemMessage(systemPrompt: string, { data, placeholders }?: Pick<LlmMessageOptions, "data" | "placeholders">): ChatMessage;
15
15
  export declare function formatUserMessage(message: string, { data, placeholders }?: Pick<LlmMessageOptions, "data" | "placeholders">): ChatMessage;
16
16
  export declare function prepareMessages(message: string, { system, data, placeholders }?: LlmMessageOptions): ChatMessage[];
17
- export declare function createStructuredCompletion(client: OpenAI, { messages, responseSchema, model, }: {
17
+ export declare function createStructuredCompletion(client: OpenAIClient, { messages, responseSchema, model, }: {
18
18
  messages: ChatMessage[];
19
19
  responseSchema: z.ZodType | NaturalSchema;
20
20
  model: string;
21
21
  }): Promise<JsonObject>;
22
- export declare function createTextCompletion(client: OpenAI, { messages, model, }: {
22
+ export declare function createTextCompletion(client: OpenAIClient, { messages, model, }: {
23
23
  messages: ChatMessage[];
24
24
  model: string;
25
25
  }): Promise<string>;
@@ -0,0 +1,40 @@
1
+ import { JsonObject } from "@jaypie/types";
2
+ export interface OpenRouterClientOptions {
3
+ apiKey: string;
4
+ baseURL?: string;
5
+ }
6
+ export interface ChatCompletionOptions {
7
+ signal?: AbortSignal;
8
+ }
9
+ /**
10
+ * HTTP error carrying the upstream status and parsed API message. The
11
+ * OpenRouterAdapter classifies errors by reading `.status` / `.statusCode` and
12
+ * `.message` / `.error.message`, so this shape keeps `classifyError`,
13
+ * `isTemperatureDeprecationError`, and `isStructuredOutputUnsupportedError`
14
+ * working unchanged after dropping the SDK.
15
+ */
16
+ export declare class OpenRouterHttpError extends Error {
17
+ readonly status: number;
18
+ readonly statusCode: number;
19
+ readonly error?: {
20
+ message?: string;
21
+ };
22
+ constructor(status: number, message: string, error?: {
23
+ message?: string;
24
+ });
25
+ }
26
+ /**
27
+ * Minimal `fetch`-based client for OpenRouter's OpenAI-compatible Chat
28
+ * Completions endpoint. Replaces `@openrouter/sdk` — the adapter only needs a
29
+ * single POST (streaming and non-streaming), header auth, and HTTP error
30
+ * surfacing.
31
+ */
32
+ export declare class OpenRouterClient {
33
+ private readonly apiKey;
34
+ private readonly baseURL;
35
+ constructor({ apiKey, baseURL, }: OpenRouterClientOptions);
36
+ private headers;
37
+ private toError;
38
+ chatCompletion(body: Record<string, unknown>, { signal }?: ChatCompletionOptions): Promise<JsonObject>;
39
+ streamChatCompletion(body: Record<string, unknown>, { signal }?: ChatCompletionOptions): AsyncIterable<JsonObject>;
40
+ }
@@ -1,11 +1,10 @@
1
1
  import { createLogger } from "@jaypie/logger";
2
- import type { OpenRouter } from "@openrouter/sdk";
3
2
  import { LlmMessageOptions } from "../../types/LlmProvider.interface.js";
4
- export declare function loadSdk(): Promise<typeof import("@openrouter/sdk")>;
3
+ import { OpenRouterClient } from "./client.js";
5
4
  export declare const getLogger: () => ReturnType<typeof createLogger>;
6
5
  export declare function initializeClient({ apiKey, }?: {
7
6
  apiKey?: string;
8
- }): Promise<OpenRouter>;
7
+ }): Promise<OpenRouterClient>;
9
8
  export declare function getDefaultModel(): string;
10
9
  export interface ChatMessage {
11
10
  role: "system" | "user" | "assistant";
@@ -1,6 +1,6 @@
1
1
  import { createLogger } from "@jaypie/logger";
2
- import { OpenAI } from "openai";
2
+ import { OpenAIClient } from "../openai/client.js";
3
3
  export declare const getLogger: () => ReturnType<typeof createLogger>;
4
4
  export declare function initializeClient({ apiKey, }?: {
5
5
  apiKey?: string;
6
- }): Promise<OpenAI>;
6
+ }): Promise<OpenAIClient>;
@@ -3,10 +3,12 @@ export * from "./extractReasoning.js";
3
3
  export * from "./fillFormatArrays.js";
4
4
  export * from "./formatOperateInput.js";
5
5
  export * from "./formatOperateMessage.js";
6
+ export * from "./jsonSchema.js";
6
7
  export * from "./jsonSchemaToOpenApi3.js";
7
8
  export * from "./logger.js";
8
9
  export * from "./maxTurnsFromOptions.js";
9
10
  export * from "./naturalZodSchema.js";
10
11
  export * from "./random.js";
11
12
  export * from "./repairFormatKeys.js";
13
+ export * from "./sse.js";
12
14
  export * from "./tryParseNumber.js";
@@ -0,0 +1,17 @@
1
+ import { JsonObject, NaturalSchema } from "@jaypie/types";
2
+ /**
3
+ * Duck-type check for a bare JSON Schema object node: `{ type: "object", properties: {...} }`.
4
+ * Does not require the OpenAI-style `{ type: "json_schema", ... }` envelope.
5
+ */
6
+ export declare function isJsonSchema(value: unknown): value is JsonObject;
7
+ /**
8
+ * Convert a Natural Schema to JSON Schema. Lossless: Natural Schema is a
9
+ * strict subset of what JSON Schema can express.
10
+ */
11
+ export declare function naturalSchemaToJsonSchema(schema: NaturalSchema): JsonObject;
12
+ /**
13
+ * Convert a JSON Schema object node to Natural Schema. Lossy: constraints,
14
+ * descriptions, defaults, unions, and optionality have no Natural Schema
15
+ * representation. Dropped keywords are logged at debug level, never thrown.
16
+ */
17
+ export declare function jsonSchemaToNaturalSchema(schema: JsonObject): NaturalSchema;
@@ -0,0 +1,12 @@
1
+ import { JsonObject } from "@jaypie/types";
2
+ /**
3
+ * Parse a Server-Sent Events stream into decoded JSON chunks. Buffers across
4
+ * network reads, dispatches on newline-delimited `data:` lines, and stops at
5
+ * the done sentinel (OpenAI-style `[DONE]`; Gemini omits it and simply ends
6
+ * the stream). Comment lines (`: ...`, used for keep-alive) are ignored.
7
+ *
8
+ * Shared by the provider HTTP clients that replaced their vendor SDKs.
9
+ */
10
+ export declare function parseSseStream(body: ReadableStream<Uint8Array>, { doneSentinel }?: {
11
+ doneSentinel?: string;
12
+ }): AsyncIterable<JsonObject>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jaypie/llm",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "description": "Large language model utilities",
5
5
  "repository": {
6
6
  "type": "git",
@@ -41,41 +41,26 @@
41
41
  "dependencies": {
42
42
  "@jaypie/aws": "*",
43
43
  "@jaypie/errors": "*",
44
- "openai": "^6.9.1",
45
44
  "openmeteo": "^1.2.1",
46
45
  "pdf-lib": "^1.17.1",
47
46
  "random": "^5.3.0",
48
- "z-schema": "^6.0.2",
49
47
  "zod": "^4.1.13"
50
48
  },
51
49
  "devDependencies": {
52
- "@anthropic-ai/sdk": "^0.71.0",
53
50
  "@aws-sdk/client-bedrock-runtime": "^3.1045.0",
54
- "@google/genai": "^1.30.0",
55
51
  "@jaypie/types": "*",
56
- "@openrouter/sdk": "^0.1.27",
52
+ "@types/node": "^22.13.1",
53
+ "dotenv": "^17.4.2",
57
54
  "rollup-plugin-dts": "^6.1.1"
58
55
  },
59
56
  "peerDependencies": {
60
- "@anthropic-ai/sdk": "^0.71.0",
61
57
  "@aws-sdk/client-bedrock-runtime": "^3.1045.0",
62
- "@google/genai": "^1.30.0",
63
58
  "@jaypie/kit": "*",
64
- "@jaypie/logger": "*",
65
- "@openrouter/sdk": "^0.1.27"
59
+ "@jaypie/logger": "*"
66
60
  },
67
61
  "peerDependenciesMeta": {
68
- "@anthropic-ai/sdk": {
69
- "optional": true
70
- },
71
62
  "@aws-sdk/client-bedrock-runtime": {
72
63
  "optional": true
73
- },
74
- "@google/genai": {
75
- "optional": true
76
- },
77
- "@openrouter/sdk": {
78
- "optional": true
79
64
  }
80
65
  },
81
66
  "publishConfig": {
@@ -1,2 +0,0 @@
1
- import { LlmMessageRole } from "../../types/LlmProvider.interface.js";
2
- export declare const ROLE_MAP: Record<LlmMessageRole, string>;
@@ -1,2 +0,0 @@
1
- import { LlmMessageRole } from "../../types/LlmProvider.interface.js";
2
- export declare const ROLE_MAP: Record<LlmMessageRole, string>;
File without changes
File without changes
File without changes