@jaypie/llm 1.1.29 → 1.1.30

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 (67) hide show
  1. package/dist/cjs/constants.d.ts +38 -1
  2. package/dist/cjs/index.cjs +2975 -986
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs/index.d.ts +2 -0
  5. package/dist/cjs/operate/OperateLoop.d.ts +61 -0
  6. package/dist/cjs/operate/adapters/AnthropicAdapter.d.ts +32 -0
  7. package/dist/cjs/operate/adapters/GeminiAdapter.d.ts +37 -0
  8. package/dist/cjs/operate/adapters/OpenAiAdapter.d.ts +30 -0
  9. package/dist/cjs/operate/adapters/OpenRouterAdapter.d.ts +96 -0
  10. package/dist/cjs/operate/adapters/ProviderAdapter.interface.d.ts +177 -0
  11. package/dist/cjs/operate/adapters/index.d.ts +6 -0
  12. package/dist/cjs/operate/hooks/HookRunner.d.ts +78 -0
  13. package/dist/cjs/operate/hooks/index.d.ts +2 -0
  14. package/dist/cjs/operate/index.d.ts +14 -0
  15. package/dist/cjs/operate/input/InputProcessor.d.ts +40 -0
  16. package/dist/cjs/operate/input/index.d.ts +2 -0
  17. package/dist/cjs/operate/response/ResponseBuilder.d.ts +89 -0
  18. package/dist/cjs/operate/response/index.d.ts +2 -0
  19. package/dist/cjs/operate/retry/RetryExecutor.d.ts +39 -0
  20. package/dist/cjs/operate/retry/RetryPolicy.d.ts +35 -0
  21. package/dist/cjs/operate/retry/index.d.ts +4 -0
  22. package/dist/cjs/operate/types.d.ts +136 -0
  23. package/dist/cjs/providers/anthropic/AnthropicProvider.class.d.ts +2 -0
  24. package/dist/cjs/providers/gemini/GeminiProvider.class.d.ts +17 -0
  25. package/dist/cjs/providers/gemini/index.d.ts +3 -0
  26. package/dist/cjs/providers/gemini/types.d.ts +185 -0
  27. package/dist/cjs/providers/gemini/utils.d.ts +51 -0
  28. package/dist/cjs/providers/openai/OpenAiProvider.class.d.ts +2 -0
  29. package/dist/cjs/providers/openrouter/OpenRouterProvider.class.d.ts +17 -0
  30. package/dist/cjs/providers/openrouter/index.d.ts +2 -0
  31. package/dist/cjs/providers/openrouter/utils.d.ts +49 -0
  32. package/dist/esm/constants.d.ts +38 -1
  33. package/dist/esm/index.d.ts +2 -0
  34. package/dist/esm/index.js +2976 -989
  35. package/dist/esm/index.js.map +1 -1
  36. package/dist/esm/operate/OperateLoop.d.ts +61 -0
  37. package/dist/esm/operate/adapters/AnthropicAdapter.d.ts +32 -0
  38. package/dist/esm/operate/adapters/GeminiAdapter.d.ts +37 -0
  39. package/dist/esm/operate/adapters/OpenAiAdapter.d.ts +30 -0
  40. package/dist/esm/operate/adapters/OpenRouterAdapter.d.ts +96 -0
  41. package/dist/esm/operate/adapters/ProviderAdapter.interface.d.ts +177 -0
  42. package/dist/esm/operate/adapters/index.d.ts +6 -0
  43. package/dist/esm/operate/hooks/HookRunner.d.ts +78 -0
  44. package/dist/esm/operate/hooks/index.d.ts +2 -0
  45. package/dist/esm/operate/index.d.ts +14 -0
  46. package/dist/esm/operate/input/InputProcessor.d.ts +40 -0
  47. package/dist/esm/operate/input/index.d.ts +2 -0
  48. package/dist/esm/operate/response/ResponseBuilder.d.ts +89 -0
  49. package/dist/esm/operate/response/index.d.ts +2 -0
  50. package/dist/esm/operate/retry/RetryExecutor.d.ts +39 -0
  51. package/dist/esm/operate/retry/RetryPolicy.d.ts +35 -0
  52. package/dist/esm/operate/retry/index.d.ts +4 -0
  53. package/dist/esm/operate/types.d.ts +136 -0
  54. package/dist/esm/providers/anthropic/AnthropicProvider.class.d.ts +2 -0
  55. package/dist/esm/providers/gemini/GeminiProvider.class.d.ts +17 -0
  56. package/dist/esm/providers/gemini/index.d.ts +3 -0
  57. package/dist/esm/providers/gemini/types.d.ts +185 -0
  58. package/dist/esm/providers/gemini/utils.d.ts +51 -0
  59. package/dist/esm/providers/openai/OpenAiProvider.class.d.ts +2 -0
  60. package/dist/esm/providers/openrouter/OpenRouterProvider.class.d.ts +17 -0
  61. package/dist/esm/providers/openrouter/index.d.ts +2 -0
  62. package/dist/esm/providers/openrouter/utils.d.ts +49 -0
  63. package/package.json +7 -5
  64. package/dist/cjs/providers/anthropic/operate.d.ts +0 -16
  65. package/dist/cjs/providers/openai/operate.d.ts +0 -26
  66. package/dist/esm/providers/anthropic/operate.d.ts +0 -16
  67. package/dist/esm/providers/openai/operate.d.ts +0 -26
@@ -0,0 +1,89 @@
1
+ import { JsonObject, JsonReturn } from "@jaypie/types";
2
+ import { LlmHistory, LlmOperateResponse, LlmResponseStatus, LlmUsage, LlmUsageItem } from "../../types/LlmProvider.interface.js";
3
+ type LlmOutput = LlmOperateResponse["output"];
4
+ export interface ResponseBuilderConfig {
5
+ model: string;
6
+ provider: string;
7
+ }
8
+ export interface LlmError {
9
+ detail?: string;
10
+ status: number | string;
11
+ title: string;
12
+ }
13
+ /**
14
+ * ResponseBuilder provides a fluent API for constructing LlmOperateResponse objects.
15
+ * It standardizes response construction across providers.
16
+ */
17
+ export declare class ResponseBuilder {
18
+ private response;
19
+ constructor(config: ResponseBuilderConfig);
20
+ /**
21
+ * Set the response content
22
+ */
23
+ setContent(content: string | JsonObject | undefined): this;
24
+ /**
25
+ * Set the response status
26
+ */
27
+ setStatus(status: LlmResponseStatus): this;
28
+ /**
29
+ * Set an error on the response
30
+ */
31
+ setError(error: LlmError): this;
32
+ /**
33
+ * Set the history
34
+ */
35
+ setHistory(history: LlmHistory): this;
36
+ /**
37
+ * Append items to the history
38
+ */
39
+ appendToHistory(...items: LlmHistory): this;
40
+ /**
41
+ * Set the output
42
+ */
43
+ setOutput(output: LlmOutput): this;
44
+ /**
45
+ * Append items to the output
46
+ */
47
+ appendToOutput(...items: LlmOutput): this;
48
+ /**
49
+ * Add a raw provider response
50
+ */
51
+ addResponse(response: JsonReturn): this;
52
+ /**
53
+ * Add a usage entry for a single API call
54
+ */
55
+ addUsage(usage: LlmUsageItem): this;
56
+ /**
57
+ * Set the entire usage array
58
+ */
59
+ setUsage(usage: LlmUsage): this;
60
+ /**
61
+ * Get the current usage array for modifications
62
+ */
63
+ getUsage(): LlmUsage;
64
+ /**
65
+ * Get the current history for modifications
66
+ */
67
+ getHistory(): LlmHistory;
68
+ /**
69
+ * Get the current output for modifications
70
+ */
71
+ getOutput(): LlmOutput;
72
+ /**
73
+ * Mark response as completed
74
+ */
75
+ complete(): this;
76
+ /**
77
+ * Mark response as incomplete (e.g., max turns exceeded)
78
+ */
79
+ incomplete(): this;
80
+ /**
81
+ * Build and return the final response object
82
+ */
83
+ build(): LlmOperateResponse;
84
+ }
85
+ /**
86
+ * Factory function to create a new ResponseBuilder
87
+ */
88
+ export declare function createResponseBuilder(config: ResponseBuilderConfig): ResponseBuilder;
89
+ export {};
@@ -0,0 +1,2 @@
1
+ export { createResponseBuilder, ResponseBuilder } from "./ResponseBuilder.js";
2
+ export type { LlmError, ResponseBuilderConfig } from "./ResponseBuilder.js";
@@ -0,0 +1,39 @@
1
+ import { HookRunner, LlmHooks } from "../hooks/HookRunner.js";
2
+ import { RetryPolicy } from "./RetryPolicy.js";
3
+ export interface RetryContext {
4
+ input: unknown;
5
+ options?: unknown;
6
+ providerRequest: unknown;
7
+ }
8
+ export interface ErrorClassifier {
9
+ isRetryable(error: unknown): boolean;
10
+ isKnownError(error: unknown): boolean;
11
+ }
12
+ export interface RetryExecutorConfig {
13
+ errorClassifier: ErrorClassifier;
14
+ hookRunner?: HookRunner;
15
+ policy?: RetryPolicy;
16
+ }
17
+ export interface ExecuteOptions {
18
+ context: RetryContext;
19
+ hooks?: LlmHooks;
20
+ }
21
+ /**
22
+ * RetryExecutor handles the retry loop logic for LLM API calls.
23
+ * It provides exponential backoff, error classification, and hook execution.
24
+ */
25
+ export declare class RetryExecutor {
26
+ private readonly policy;
27
+ private readonly hookRunner;
28
+ private readonly errorClassifier;
29
+ constructor(config: RetryExecutorConfig);
30
+ /**
31
+ * Execute an operation with retry logic
32
+ *
33
+ * @param operation - The async operation to execute
34
+ * @param options - Execution options including context and hooks
35
+ * @returns The result of the operation
36
+ * @throws BadGatewayError if all retries are exhausted or error is not retryable
37
+ */
38
+ execute<T>(operation: () => Promise<T>, options: ExecuteOptions): Promise<T>;
39
+ }
@@ -0,0 +1,35 @@
1
+ export declare const DEFAULT_INITIAL_DELAY_MS = 1000;
2
+ export declare const DEFAULT_MAX_DELAY_MS = 32000;
3
+ export declare const DEFAULT_BACKOFF_FACTOR = 2;
4
+ export declare const DEFAULT_MAX_RETRIES = 6;
5
+ export declare const MAX_RETRIES_ABSOLUTE_LIMIT = 72;
6
+ export interface RetryPolicyConfig {
7
+ /** Initial delay in milliseconds before first retry. Default: 1000 */
8
+ initialDelayMs?: number;
9
+ /** Maximum delay in milliseconds between retries. Default: 32000 */
10
+ maxDelayMs?: number;
11
+ /** Backoff multiplier for exponential backoff. Default: 2 */
12
+ backoffFactor?: number;
13
+ /** Maximum number of retries. Default: 6 */
14
+ maxRetries?: number;
15
+ }
16
+ /**
17
+ * RetryPolicy encapsulates retry configuration and delay calculation
18
+ * for the operate loop's retry logic.
19
+ */
20
+ export declare class RetryPolicy {
21
+ readonly initialDelayMs: number;
22
+ readonly maxDelayMs: number;
23
+ readonly backoffFactor: number;
24
+ readonly maxRetries: number;
25
+ constructor(config?: RetryPolicyConfig);
26
+ /**
27
+ * Calculate the delay for a given attempt number (0-indexed)
28
+ */
29
+ getDelayForAttempt(attempt: number): number;
30
+ /**
31
+ * Check if another retry should be attempted
32
+ */
33
+ shouldRetry(currentAttempt: number): boolean;
34
+ }
35
+ export declare const defaultRetryPolicy: RetryPolicy;
@@ -0,0 +1,4 @@
1
+ export { DEFAULT_BACKOFF_FACTOR, DEFAULT_INITIAL_DELAY_MS, DEFAULT_MAX_DELAY_MS, DEFAULT_MAX_RETRIES, defaultRetryPolicy, MAX_RETRIES_ABSOLUTE_LIMIT, RetryPolicy, } from "./RetryPolicy.js";
2
+ export type { RetryPolicyConfig } from "./RetryPolicy.js";
3
+ export { RetryExecutor } from "./RetryExecutor.js";
4
+ export type { ErrorClassifier, ExecuteOptions, RetryContext, RetryExecutorConfig, } from "./RetryExecutor.js";
@@ -0,0 +1,136 @@
1
+ import { JsonObject } from "@jaypie/types";
2
+ import { LlmHistory, LlmMessageType, LlmOperateOptions, LlmUsageItem } from "../types/LlmProvider.interface.js";
3
+ import { Toolkit } from "../tools/Toolkit.class.js";
4
+ /**
5
+ * Standardized tool call representation across providers
6
+ */
7
+ export interface StandardToolCall {
8
+ /** Unique identifier for this tool call */
9
+ callId: string;
10
+ /** Name of the tool being called */
11
+ name: string;
12
+ /** JSON string of arguments */
13
+ arguments: string;
14
+ /** Original provider-specific tool call object */
15
+ raw: unknown;
16
+ }
17
+ /**
18
+ * Standardized tool result to send back to the provider
19
+ */
20
+ export interface StandardToolResult {
21
+ /** The call ID this result corresponds to */
22
+ callId: string;
23
+ /** JSON string of the result */
24
+ output: string;
25
+ /** Whether the tool call was successful */
26
+ success: boolean;
27
+ /** Error message if the tool call failed */
28
+ error?: string;
29
+ }
30
+ /**
31
+ * Parsed response from a provider API call
32
+ */
33
+ export interface ParsedResponse {
34
+ /** The text content of the response, if any */
35
+ content?: string | JsonObject;
36
+ /** Whether the response contains tool calls */
37
+ hasToolCalls: boolean;
38
+ /** The stop reason from the provider */
39
+ stopReason?: string;
40
+ /** Usage information for this response */
41
+ usage?: LlmUsageItem;
42
+ /** Raw provider response for storage */
43
+ raw: unknown;
44
+ }
45
+ /**
46
+ * Context passed to hooks and utilities during the operate loop
47
+ */
48
+ export interface OperateContext {
49
+ /** The hooks configuration */
50
+ hooks: LlmOperateOptions["hooks"];
51
+ /** The operate options */
52
+ options: LlmOperateOptions;
53
+ }
54
+ /**
55
+ * Provider-agnostic request options
56
+ * Each adapter will convert this to provider-specific format
57
+ */
58
+ export interface OperateRequest {
59
+ /** The model to use */
60
+ model: string;
61
+ /** The conversation history/messages */
62
+ messages: LlmHistory;
63
+ /** System instructions (if separate from messages) */
64
+ system?: string;
65
+ /** Additional instructions to append */
66
+ instructions?: string;
67
+ /** Tools available for the model */
68
+ tools?: ProviderToolDefinition[];
69
+ /** Structured output format */
70
+ format?: JsonObject;
71
+ /** Provider-specific options */
72
+ providerOptions?: JsonObject;
73
+ /** User identifier for tracking */
74
+ user?: string;
75
+ }
76
+ /**
77
+ * Tool definition in provider-agnostic format
78
+ */
79
+ export interface ProviderToolDefinition {
80
+ /** Tool name */
81
+ name: string;
82
+ /** Tool description */
83
+ description: string;
84
+ /** JSON Schema for parameters */
85
+ parameters: JsonObject;
86
+ }
87
+ /**
88
+ * Categories of errors for retry logic
89
+ */
90
+ export declare enum ErrorCategory {
91
+ /** Error is transient and can be retried */
92
+ Retryable = "retryable",
93
+ /** Error is due to rate limiting */
94
+ RateLimit = "rate_limit",
95
+ /** Error cannot be recovered from */
96
+ Unrecoverable = "unrecoverable",
97
+ /** Error type is unknown */
98
+ Unknown = "unknown"
99
+ }
100
+ /**
101
+ * Classified error with metadata
102
+ */
103
+ export interface ClassifiedError {
104
+ /** The original error */
105
+ error: unknown;
106
+ /** Category of the error */
107
+ category: ErrorCategory;
108
+ /** Whether a retry should be attempted */
109
+ shouldRetry: boolean;
110
+ /** Suggested delay before retry (if applicable) */
111
+ suggestedDelayMs?: number;
112
+ }
113
+ import type { ResponseBuilder } from "./response/ResponseBuilder.js";
114
+ /**
115
+ * Internal state of the operate loop
116
+ */
117
+ export interface OperateLoopState {
118
+ /** Current conversation input/messages */
119
+ currentInput: LlmHistory;
120
+ /** Current turn number (0-indexed, incremented at start of each turn) */
121
+ currentTurn: number;
122
+ /** Formatted output schema for structured output */
123
+ formattedFormat?: JsonObject;
124
+ /** Formatted tools for the provider */
125
+ formattedTools?: ProviderToolDefinition[];
126
+ /** Maximum allowed turns */
127
+ maxTurns: number;
128
+ /** Response builder instance */
129
+ responseBuilder: ResponseBuilder;
130
+ /** The toolkit for tool calls */
131
+ toolkit?: Toolkit;
132
+ }
133
+ /**
134
+ * Re-export message type for convenience in adapters
135
+ */
136
+ export { LlmMessageType };
@@ -3,6 +3,7 @@ import { LlmHistory, LlmInputMessage, LlmMessageOptions, LlmOperateOptions, LlmO
3
3
  export declare class AnthropicProvider implements LlmProvider {
4
4
  private model;
5
5
  private _client?;
6
+ private _operateLoop?;
6
7
  private apiKey?;
7
8
  private log;
8
9
  private conversationHistory;
@@ -10,6 +11,7 @@ export declare class AnthropicProvider implements LlmProvider {
10
11
  apiKey?: string;
11
12
  });
12
13
  private getClient;
14
+ private getOperateLoop;
13
15
  send(message: string, options?: LlmMessageOptions): Promise<string | JsonObject>;
14
16
  operate(input: string | LlmHistory | LlmInputMessage, options?: LlmOperateOptions): Promise<LlmOperateResponse>;
15
17
  }
@@ -0,0 +1,17 @@
1
+ import { JsonObject } from "@jaypie/types";
2
+ import { LlmHistory, LlmInputMessage, LlmMessageOptions, LlmOperateOptions, LlmOperateResponse, LlmProvider } from "../../types/LlmProvider.interface.js";
3
+ export declare class GeminiProvider implements LlmProvider {
4
+ private model;
5
+ private _client?;
6
+ private _operateLoop?;
7
+ private apiKey?;
8
+ private log;
9
+ private conversationHistory;
10
+ constructor(model?: string, { apiKey }?: {
11
+ apiKey?: string;
12
+ });
13
+ private getClient;
14
+ private getOperateLoop;
15
+ send(message: string, options?: LlmMessageOptions): Promise<string | JsonObject>;
16
+ operate(input: string | LlmHistory | LlmInputMessage, options?: LlmOperateOptions): Promise<LlmOperateResponse>;
17
+ }
@@ -0,0 +1,3 @@
1
+ export { GeminiProvider } from "./GeminiProvider.class.js";
2
+ export * from "./types.js";
3
+ export * from "./utils.js";
@@ -0,0 +1,185 @@
1
+ import { JsonObject } from "@jaypie/types";
2
+ import { LlmMessageRole } from "../../types/LlmProvider.interface.js";
3
+ export declare const ROLE_MAP: Record<LlmMessageRole, "user" | "model">;
4
+ /**
5
+ * A part of content - can be text, function call, or function response
6
+ */
7
+ export interface GeminiPart {
8
+ text?: string;
9
+ thought?: boolean;
10
+ thoughtSignature?: string;
11
+ functionCall?: GeminiFunctionCall;
12
+ functionResponse?: GeminiFunctionResponse;
13
+ inlineData?: {
14
+ mimeType: string;
15
+ data: string;
16
+ };
17
+ fileData?: {
18
+ mimeType?: string;
19
+ fileUri: string;
20
+ };
21
+ }
22
+ /**
23
+ * A function call made by the model
24
+ */
25
+ export interface GeminiFunctionCall {
26
+ name?: string;
27
+ args?: Record<string, unknown>;
28
+ id?: string;
29
+ }
30
+ /**
31
+ * A response to a function call
32
+ */
33
+ export interface GeminiFunctionResponse {
34
+ name: string;
35
+ response: Record<string, unknown>;
36
+ }
37
+ /**
38
+ * Content represents a message in the conversation
39
+ */
40
+ export interface GeminiContent {
41
+ role: "user" | "model";
42
+ parts?: GeminiPart[];
43
+ }
44
+ /**
45
+ * Function declaration for tools
46
+ */
47
+ export interface GeminiFunctionDeclaration {
48
+ name: string;
49
+ description: string;
50
+ parameters: JsonObject;
51
+ }
52
+ /**
53
+ * Tool definition containing function declarations
54
+ */
55
+ export interface GeminiTool {
56
+ functionDeclarations?: GeminiFunctionDeclaration[];
57
+ googleSearch?: Record<string, unknown>;
58
+ codeExecution?: Record<string, unknown>;
59
+ }
60
+ /**
61
+ * Configuration for a generate content request
62
+ * This is a simplified internal type - we use the SDK's actual types at runtime
63
+ */
64
+ export interface GeminiGenerateContentConfig {
65
+ systemInstruction?: string;
66
+ tools?: GeminiTool[];
67
+ toolConfig?: {
68
+ functionCallingConfig?: {
69
+ mode?: "AUTO" | "ANY" | "NONE";
70
+ allowedFunctionNames?: string[];
71
+ };
72
+ };
73
+ responseMimeType?: string;
74
+ responseJsonSchema?: JsonObject;
75
+ temperature?: number;
76
+ topP?: number;
77
+ topK?: number;
78
+ maxOutputTokens?: number;
79
+ stopSequences?: string[];
80
+ candidateCount?: number;
81
+ }
82
+ /**
83
+ * Request structure for generateContent API
84
+ */
85
+ export interface GeminiRequest {
86
+ model: string;
87
+ contents: GeminiContent[];
88
+ config?: GeminiGenerateContentConfig;
89
+ }
90
+ /**
91
+ * Usage metadata from the response
92
+ */
93
+ export interface GeminiUsageMetadata {
94
+ promptTokenCount?: number;
95
+ candidatesTokenCount?: number;
96
+ totalTokenCount?: number;
97
+ thoughtsTokenCount?: number;
98
+ cachedContentTokenCount?: number;
99
+ }
100
+ /**
101
+ * A response candidate from the model
102
+ */
103
+ export interface GeminiCandidate {
104
+ content?: GeminiContent;
105
+ finishReason?: string;
106
+ index?: number;
107
+ safetyRatings?: Array<{
108
+ category: string;
109
+ probability: string;
110
+ blocked?: boolean;
111
+ }>;
112
+ citationMetadata?: {
113
+ citations?: Array<{
114
+ startIndex?: number;
115
+ endIndex?: number;
116
+ uri?: string;
117
+ title?: string;
118
+ license?: string;
119
+ publicationDate?: {
120
+ year?: number;
121
+ month?: number;
122
+ day?: number;
123
+ };
124
+ }>;
125
+ };
126
+ tokenCount?: number;
127
+ avgLogprobs?: number;
128
+ }
129
+ /**
130
+ * Prompt feedback from the API
131
+ */
132
+ export interface GeminiPromptFeedback {
133
+ blockReason?: string;
134
+ safetyRatings?: Array<{
135
+ category: string;
136
+ probability: string;
137
+ blocked?: boolean;
138
+ }>;
139
+ }
140
+ /**
141
+ * Raw response from Gemini API
142
+ */
143
+ export interface GeminiRawResponse {
144
+ candidates?: GeminiCandidate[];
145
+ promptFeedback?: GeminiPromptFeedback;
146
+ usageMetadata?: GeminiUsageMetadata;
147
+ modelVersion?: string;
148
+ responseId?: string;
149
+ createTime?: string;
150
+ text?: string;
151
+ functionCalls?: GeminiFunctionCall[];
152
+ }
153
+ /**
154
+ * Error information from Gemini API
155
+ */
156
+ export interface GeminiErrorInfo {
157
+ status?: number;
158
+ code?: number;
159
+ message?: string;
160
+ details?: Array<{
161
+ "@type"?: string;
162
+ reason?: string;
163
+ domain?: string;
164
+ metadata?: Record<string, string>;
165
+ }>;
166
+ }
167
+ /**
168
+ * Finish reasons returned by Gemini
169
+ */
170
+ export declare const FINISH_REASON: {
171
+ readonly FINISH_REASON_UNSPECIFIED: "FINISH_REASON_UNSPECIFIED";
172
+ readonly STOP: "STOP";
173
+ readonly MAX_TOKENS: "MAX_TOKENS";
174
+ readonly SAFETY: "SAFETY";
175
+ readonly RECITATION: "RECITATION";
176
+ readonly LANGUAGE: "LANGUAGE";
177
+ readonly OTHER: "OTHER";
178
+ readonly BLOCKLIST: "BLOCKLIST";
179
+ readonly PROHIBITED_CONTENT: "PROHIBITED_CONTENT";
180
+ readonly SPII: "SPII";
181
+ readonly MALFORMED_FUNCTION_CALL: "MALFORMED_FUNCTION_CALL";
182
+ readonly IMAGE_SAFETY: "IMAGE_SAFETY";
183
+ readonly UNEXPECTED_TOOL_CALL: "UNEXPECTED_TOOL_CALL";
184
+ };
185
+ export type GeminiFinishReason = (typeof FINISH_REASON)[keyof typeof FINISH_REASON];
@@ -0,0 +1,51 @@
1
+ import { log as defaultLog } from "@jaypie/core";
2
+ import { GoogleGenAI } from "@google/genai";
3
+ 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
+ };
39
+ export declare function initializeClient({ apiKey, }?: {
40
+ apiKey?: string;
41
+ }): Promise<GoogleGenAI>;
42
+ export interface ChatMessage {
43
+ role: "user" | "model";
44
+ content: string;
45
+ }
46
+ export declare function formatSystemMessage(systemPrompt: string, { data, placeholders }?: Pick<LlmMessageOptions, "data" | "placeholders">): string;
47
+ export declare function formatUserMessage(message: string, { data, placeholders }?: Pick<LlmMessageOptions, "data" | "placeholders">): ChatMessage;
48
+ export declare function prepareMessages(message: string, { data, placeholders }?: LlmMessageOptions): {
49
+ messages: ChatMessage[];
50
+ systemInstruction?: string;
51
+ };
@@ -3,6 +3,7 @@ import { LlmHistory, LlmInputMessage, LlmMessageOptions, LlmOperateOptions, LlmO
3
3
  export declare class OpenAiProvider implements LlmProvider {
4
4
  private model;
5
5
  private _client?;
6
+ private _operateLoop?;
6
7
  private apiKey?;
7
8
  private log;
8
9
  private conversationHistory;
@@ -10,6 +11,7 @@ export declare class OpenAiProvider implements LlmProvider {
10
11
  apiKey?: string;
11
12
  });
12
13
  private getClient;
14
+ private getOperateLoop;
13
15
  send(message: string, options?: LlmMessageOptions): Promise<string | JsonObject>;
14
16
  operate(input: string | LlmHistory | LlmInputMessage, options?: LlmOperateOptions): Promise<LlmOperateResponse>;
15
17
  }
@@ -0,0 +1,17 @@
1
+ import { JsonObject } from "@jaypie/types";
2
+ import { LlmHistory, LlmInputMessage, LlmMessageOptions, LlmOperateOptions, LlmOperateResponse, LlmProvider } from "../../types/LlmProvider.interface.js";
3
+ export declare class OpenRouterProvider implements LlmProvider {
4
+ private model;
5
+ private _client?;
6
+ private _operateLoop?;
7
+ private apiKey?;
8
+ private log;
9
+ private conversationHistory;
10
+ constructor(model?: string, { apiKey }?: {
11
+ apiKey?: string;
12
+ });
13
+ private getClient;
14
+ private getOperateLoop;
15
+ send(message: string, options?: LlmMessageOptions): Promise<string | JsonObject>;
16
+ operate(input: string | LlmHistory | LlmInputMessage, options?: LlmOperateOptions): Promise<LlmOperateResponse>;
17
+ }
@@ -0,0 +1,2 @@
1
+ export { OpenRouterProvider } from "./OpenRouterProvider.class.js";
2
+ export * from "./utils.js";
@@ -0,0 +1,49 @@
1
+ import { log as defaultLog } from "@jaypie/core";
2
+ import { OpenRouter } from "@openrouter/sdk";
3
+ 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
+ };
39
+ export declare function initializeClient({ apiKey, }?: {
40
+ apiKey?: string;
41
+ }): Promise<OpenRouter>;
42
+ export declare function getDefaultModel(): string;
43
+ export interface ChatMessage {
44
+ role: "system" | "user" | "assistant";
45
+ content: string;
46
+ }
47
+ export declare function formatSystemMessage(systemPrompt: string, { data, placeholders }?: Pick<LlmMessageOptions, "data" | "placeholders">): ChatMessage;
48
+ export declare function formatUserMessage(message: string, { data, placeholders }?: Pick<LlmMessageOptions, "data" | "placeholders">): ChatMessage;
49
+ export declare function prepareMessages(message: string, { system, data, placeholders }?: LlmMessageOptions): ChatMessage[];