@ljoukov/llm 0.1.0
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/LICENSE +21 -0
- package/README.md +195 -0
- package/dist/index.cjs +3470 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +252 -0
- package/dist/index.d.ts +252 -0
- package/dist/index.js +3412 -0
- package/dist/index.js.map +1 -0
- package/package.json +56 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import { GroundingMetadata, Part } from '@google/genai';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { ResponseTextConfig } from 'openai/resources/responses/responses';
|
|
5
|
+
|
|
6
|
+
type LlmUsageTokens = {
|
|
7
|
+
readonly promptTokens?: number;
|
|
8
|
+
readonly cachedTokens?: number;
|
|
9
|
+
readonly responseTokens?: number;
|
|
10
|
+
readonly responseImageTokens?: number;
|
|
11
|
+
readonly thinkingTokens?: number;
|
|
12
|
+
readonly totalTokens?: number;
|
|
13
|
+
readonly toolUsePromptTokens?: number;
|
|
14
|
+
};
|
|
15
|
+
declare function estimateCallCostUsd({ modelId, tokens, responseImages, imageSize, }: {
|
|
16
|
+
modelId: string;
|
|
17
|
+
tokens: LlmUsageTokens | undefined;
|
|
18
|
+
responseImages: number;
|
|
19
|
+
imageSize?: string;
|
|
20
|
+
}): number;
|
|
21
|
+
|
|
22
|
+
type OpenAiReasoningEffort = "low" | "medium" | "high" | "xhigh";
|
|
23
|
+
|
|
24
|
+
type LlmToolCallContext = {
|
|
25
|
+
readonly toolName: string;
|
|
26
|
+
readonly toolId: string;
|
|
27
|
+
readonly turn: number;
|
|
28
|
+
readonly toolIndex: number;
|
|
29
|
+
};
|
|
30
|
+
declare function getCurrentToolCallContext(): LlmToolCallContext | null;
|
|
31
|
+
type JsonSchema = Record<string, unknown>;
|
|
32
|
+
type LlmRole = "user" | "model" | "system" | "tool";
|
|
33
|
+
type LlmInlineDataPart = {
|
|
34
|
+
type: "inlineData";
|
|
35
|
+
data: string;
|
|
36
|
+
mimeType?: string;
|
|
37
|
+
};
|
|
38
|
+
type LlmContentPart = {
|
|
39
|
+
type: "text";
|
|
40
|
+
text: string;
|
|
41
|
+
thought?: boolean;
|
|
42
|
+
} | LlmInlineDataPart;
|
|
43
|
+
type LlmContent = {
|
|
44
|
+
readonly role: LlmRole;
|
|
45
|
+
readonly parts: readonly LlmContentPart[];
|
|
46
|
+
};
|
|
47
|
+
type LlmImageSize = "1K" | "2K" | "4K";
|
|
48
|
+
type LlmWebSearchMode = "cached" | "live";
|
|
49
|
+
type LlmToolConfig = {
|
|
50
|
+
readonly type: "web-search";
|
|
51
|
+
readonly mode?: LlmWebSearchMode;
|
|
52
|
+
} | {
|
|
53
|
+
readonly type: "code-execution";
|
|
54
|
+
};
|
|
55
|
+
type LlmTextDeltaEvent = {
|
|
56
|
+
readonly type: "delta";
|
|
57
|
+
readonly channel: "response";
|
|
58
|
+
readonly text: string;
|
|
59
|
+
} | {
|
|
60
|
+
readonly type: "delta";
|
|
61
|
+
readonly channel: "thought";
|
|
62
|
+
readonly text: string;
|
|
63
|
+
};
|
|
64
|
+
type LlmUsageEvent = {
|
|
65
|
+
readonly type: "usage";
|
|
66
|
+
readonly usage: LlmUsageTokens;
|
|
67
|
+
readonly costUsd: number;
|
|
68
|
+
readonly modelVersion: string;
|
|
69
|
+
};
|
|
70
|
+
type LlmModelEvent = {
|
|
71
|
+
readonly type: "model";
|
|
72
|
+
readonly modelVersion: string;
|
|
73
|
+
};
|
|
74
|
+
type LlmBlockedEvent = {
|
|
75
|
+
readonly type: "blocked";
|
|
76
|
+
};
|
|
77
|
+
type LlmStreamEvent = LlmTextDeltaEvent | LlmUsageEvent | LlmModelEvent | LlmBlockedEvent;
|
|
78
|
+
type LlmProvider = "openai" | "chatgpt" | "gemini";
|
|
79
|
+
type LlmTextResult = {
|
|
80
|
+
readonly provider: LlmProvider;
|
|
81
|
+
readonly model: string;
|
|
82
|
+
readonly modelVersion: string;
|
|
83
|
+
readonly content?: LlmContent;
|
|
84
|
+
readonly text: string;
|
|
85
|
+
readonly thoughts: string;
|
|
86
|
+
readonly blocked: boolean;
|
|
87
|
+
readonly usage?: LlmUsageTokens;
|
|
88
|
+
readonly costUsd: number;
|
|
89
|
+
readonly grounding?: GroundingMetadata;
|
|
90
|
+
};
|
|
91
|
+
type LlmTextStream = {
|
|
92
|
+
readonly events: AsyncIterable<LlmStreamEvent>;
|
|
93
|
+
readonly result: Promise<LlmTextResult>;
|
|
94
|
+
readonly abort: () => void;
|
|
95
|
+
};
|
|
96
|
+
type LlmInput = {
|
|
97
|
+
readonly prompt: string;
|
|
98
|
+
readonly systemPrompt?: string;
|
|
99
|
+
} | {
|
|
100
|
+
readonly contents: readonly LlmContent[];
|
|
101
|
+
};
|
|
102
|
+
type LlmBaseRequest = {
|
|
103
|
+
readonly model: string;
|
|
104
|
+
readonly tools?: readonly LlmToolConfig[];
|
|
105
|
+
readonly responseMimeType?: string;
|
|
106
|
+
readonly responseJsonSchema?: JsonSchema;
|
|
107
|
+
readonly responseModalities?: readonly string[];
|
|
108
|
+
readonly imageAspectRatio?: string;
|
|
109
|
+
readonly imageSize?: LlmImageSize;
|
|
110
|
+
readonly openAiReasoningEffort?: OpenAiReasoningEffort;
|
|
111
|
+
readonly openAiTextFormat?: ResponseTextConfig["format"];
|
|
112
|
+
readonly signal?: AbortSignal;
|
|
113
|
+
};
|
|
114
|
+
type LlmTextRequest = LlmInput & LlmBaseRequest;
|
|
115
|
+
type LlmJsonRequest<T> = LlmInput & LlmBaseRequest & {
|
|
116
|
+
readonly schema: z.ZodType<T>;
|
|
117
|
+
readonly openAiSchemaName?: string;
|
|
118
|
+
readonly maxAttempts?: number;
|
|
119
|
+
readonly normalizeJson?: (value: unknown) => unknown;
|
|
120
|
+
};
|
|
121
|
+
declare class LlmJsonCallError extends Error {
|
|
122
|
+
readonly attempts: ReadonlyArray<{
|
|
123
|
+
readonly attempt: number;
|
|
124
|
+
readonly rawText: string;
|
|
125
|
+
readonly error: unknown;
|
|
126
|
+
}>;
|
|
127
|
+
constructor(message: string, attempts: ReadonlyArray<{
|
|
128
|
+
readonly attempt: number;
|
|
129
|
+
readonly rawText: string;
|
|
130
|
+
readonly error: unknown;
|
|
131
|
+
}>);
|
|
132
|
+
}
|
|
133
|
+
type LlmImageData = {
|
|
134
|
+
readonly mimeType?: string;
|
|
135
|
+
readonly data: Buffer;
|
|
136
|
+
};
|
|
137
|
+
type LlmGenerateImagesRequest = {
|
|
138
|
+
readonly model: string;
|
|
139
|
+
readonly stylePrompt: string;
|
|
140
|
+
readonly styleImages?: readonly LlmImageData[];
|
|
141
|
+
readonly imagePrompts: readonly string[];
|
|
142
|
+
readonly imageGradingPrompt: string;
|
|
143
|
+
readonly maxAttempts?: number;
|
|
144
|
+
readonly imageAspectRatio?: string;
|
|
145
|
+
readonly imageSize?: LlmImageSize;
|
|
146
|
+
readonly signal?: AbortSignal;
|
|
147
|
+
};
|
|
148
|
+
type LlmExecutableTool<Schema extends z.ZodType, Output> = {
|
|
149
|
+
readonly description?: string;
|
|
150
|
+
readonly inputSchema: Schema;
|
|
151
|
+
readonly execute: (input: z.output<Schema>) => Promise<Output> | Output;
|
|
152
|
+
};
|
|
153
|
+
type LlmToolSet = Record<string, LlmExecutableTool<z.ZodType, unknown>>;
|
|
154
|
+
declare function tool<Schema extends z.ZodType, Output>(options: {
|
|
155
|
+
readonly description?: string;
|
|
156
|
+
readonly inputSchema: Schema;
|
|
157
|
+
readonly execute: (input: z.output<Schema>) => Promise<Output> | Output;
|
|
158
|
+
}): LlmExecutableTool<Schema, Output>;
|
|
159
|
+
type LlmToolCallResult = {
|
|
160
|
+
readonly toolName: string;
|
|
161
|
+
readonly input: unknown;
|
|
162
|
+
readonly output: unknown;
|
|
163
|
+
readonly error?: string;
|
|
164
|
+
readonly callId?: string;
|
|
165
|
+
};
|
|
166
|
+
type LlmToolLoopStep = {
|
|
167
|
+
readonly step: number;
|
|
168
|
+
readonly modelVersion: string;
|
|
169
|
+
readonly text?: string;
|
|
170
|
+
readonly thoughts?: string;
|
|
171
|
+
readonly toolCalls: readonly LlmToolCallResult[];
|
|
172
|
+
readonly usage?: LlmUsageTokens;
|
|
173
|
+
readonly costUsd: number;
|
|
174
|
+
};
|
|
175
|
+
type LlmToolLoopResult = {
|
|
176
|
+
readonly text: string;
|
|
177
|
+
readonly thoughts: string;
|
|
178
|
+
readonly steps: readonly LlmToolLoopStep[];
|
|
179
|
+
readonly totalCostUsd: number;
|
|
180
|
+
};
|
|
181
|
+
type LlmToolLoopRequest = LlmInput & {
|
|
182
|
+
readonly model: string;
|
|
183
|
+
readonly tools: LlmToolSet;
|
|
184
|
+
readonly modelTools?: readonly LlmToolConfig[];
|
|
185
|
+
readonly maxSteps?: number;
|
|
186
|
+
readonly openAiReasoningEffort?: OpenAiReasoningEffort;
|
|
187
|
+
readonly onEvent?: (event: LlmStreamEvent) => void;
|
|
188
|
+
readonly signal?: AbortSignal;
|
|
189
|
+
};
|
|
190
|
+
declare function toGeminiJsonSchema(schema: z.ZodType, options?: {
|
|
191
|
+
name?: string;
|
|
192
|
+
}): JsonSchema;
|
|
193
|
+
declare function sanitisePartForLogging(part: LlmContentPart): unknown;
|
|
194
|
+
declare function convertGooglePartsToLlmParts(parts: readonly Part[]): LlmContentPart[];
|
|
195
|
+
declare function parseJsonFromLlmText(rawText: string): unknown;
|
|
196
|
+
declare function streamText(request: LlmTextRequest): LlmTextStream;
|
|
197
|
+
declare function generateText(request: LlmTextRequest): Promise<LlmTextResult>;
|
|
198
|
+
declare function generateJson<T>(request: LlmJsonRequest<T>): Promise<{
|
|
199
|
+
readonly value: T;
|
|
200
|
+
readonly rawText: string;
|
|
201
|
+
readonly result: LlmTextResult;
|
|
202
|
+
}>;
|
|
203
|
+
declare function runToolLoop(request: LlmToolLoopRequest): Promise<LlmToolLoopResult>;
|
|
204
|
+
declare function generateImages(request: LlmGenerateImagesRequest): Promise<LlmImageData[]>;
|
|
205
|
+
declare function generateImageInBatches(request: LlmGenerateImagesRequest & {
|
|
206
|
+
batchSize: number;
|
|
207
|
+
overlapSize: number;
|
|
208
|
+
}): Promise<LlmImageData[]>;
|
|
209
|
+
declare function stripCodexCitationMarkers(value: string): {
|
|
210
|
+
text: string;
|
|
211
|
+
stripped: boolean;
|
|
212
|
+
};
|
|
213
|
+
declare function appendMarkdownSourcesSection(value: string, sources: readonly string[]): string;
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Loads `.env.local` from `process.cwd()` once.
|
|
217
|
+
*
|
|
218
|
+
* - Does not override already-set `process.env` values.
|
|
219
|
+
* - Missing file is silently ignored.
|
|
220
|
+
*/
|
|
221
|
+
declare function loadLocalEnv(): void;
|
|
222
|
+
declare function loadEnvFromFile(filePath: string, { override }?: {
|
|
223
|
+
override?: boolean;
|
|
224
|
+
}): void;
|
|
225
|
+
|
|
226
|
+
type ChatGptAuthProfile = {
|
|
227
|
+
readonly access: string;
|
|
228
|
+
readonly refresh: string;
|
|
229
|
+
readonly expires: number;
|
|
230
|
+
readonly accountId: string;
|
|
231
|
+
readonly idToken?: string;
|
|
232
|
+
};
|
|
233
|
+
declare function encodeChatGptAuthJson(profile: ChatGptAuthProfile): string;
|
|
234
|
+
declare function encodeChatGptAuthJsonB64(profile: ChatGptAuthProfile): string;
|
|
235
|
+
declare function exchangeChatGptOauthCode({ code, verifier, redirectUri, }: {
|
|
236
|
+
code: string;
|
|
237
|
+
verifier: string;
|
|
238
|
+
redirectUri?: string;
|
|
239
|
+
}): Promise<ChatGptAuthProfile>;
|
|
240
|
+
declare function refreshChatGptOauthToken(refreshToken: string): Promise<ChatGptAuthProfile>;
|
|
241
|
+
declare function getChatGptAuthProfile(): Promise<ChatGptAuthProfile>;
|
|
242
|
+
|
|
243
|
+
declare const GEMINI_MODEL_IDS: readonly ["gemini-3-pro-preview", "gemini-2.5-pro", "gemini-flash-latest", "gemini-flash-lite-latest"];
|
|
244
|
+
type GeminiModelId = (typeof GEMINI_MODEL_IDS)[number];
|
|
245
|
+
declare function isGeminiModelId(value: string): value is GeminiModelId;
|
|
246
|
+
type GeminiConfiguration = {
|
|
247
|
+
readonly projectId?: string;
|
|
248
|
+
readonly location?: string;
|
|
249
|
+
};
|
|
250
|
+
declare function configureGemini(options?: GeminiConfiguration): void;
|
|
251
|
+
|
|
252
|
+
export { type ChatGptAuthProfile, type GeminiModelId, type JsonSchema, type LlmBaseRequest, type LlmBlockedEvent, type LlmContent, type LlmContentPart, type LlmExecutableTool, type LlmImageData, type LlmImageSize, type LlmInput, LlmJsonCallError, type LlmJsonRequest, type LlmModelEvent, type LlmProvider, type LlmStreamEvent, type LlmTextDeltaEvent, type LlmTextRequest, type LlmTextResult, type LlmTextStream, type LlmToolCallContext, type LlmToolCallResult, type LlmToolConfig, type LlmToolLoopRequest, type LlmToolLoopResult, type LlmToolLoopStep, type LlmToolSet, type LlmUsageEvent, type LlmUsageTokens, type LlmWebSearchMode, appendMarkdownSourcesSection, configureGemini, convertGooglePartsToLlmParts, encodeChatGptAuthJson, encodeChatGptAuthJsonB64, estimateCallCostUsd, exchangeChatGptOauthCode, generateImageInBatches, generateImages, generateJson, generateText, getChatGptAuthProfile, getCurrentToolCallContext, isGeminiModelId, loadEnvFromFile, loadLocalEnv, parseJsonFromLlmText, refreshChatGptOauthToken, runToolLoop, sanitisePartForLogging, streamText, stripCodexCitationMarkers, toGeminiJsonSchema, tool };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import { GroundingMetadata, Part } from '@google/genai';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { ResponseTextConfig } from 'openai/resources/responses/responses';
|
|
5
|
+
|
|
6
|
+
type LlmUsageTokens = {
|
|
7
|
+
readonly promptTokens?: number;
|
|
8
|
+
readonly cachedTokens?: number;
|
|
9
|
+
readonly responseTokens?: number;
|
|
10
|
+
readonly responseImageTokens?: number;
|
|
11
|
+
readonly thinkingTokens?: number;
|
|
12
|
+
readonly totalTokens?: number;
|
|
13
|
+
readonly toolUsePromptTokens?: number;
|
|
14
|
+
};
|
|
15
|
+
declare function estimateCallCostUsd({ modelId, tokens, responseImages, imageSize, }: {
|
|
16
|
+
modelId: string;
|
|
17
|
+
tokens: LlmUsageTokens | undefined;
|
|
18
|
+
responseImages: number;
|
|
19
|
+
imageSize?: string;
|
|
20
|
+
}): number;
|
|
21
|
+
|
|
22
|
+
type OpenAiReasoningEffort = "low" | "medium" | "high" | "xhigh";
|
|
23
|
+
|
|
24
|
+
type LlmToolCallContext = {
|
|
25
|
+
readonly toolName: string;
|
|
26
|
+
readonly toolId: string;
|
|
27
|
+
readonly turn: number;
|
|
28
|
+
readonly toolIndex: number;
|
|
29
|
+
};
|
|
30
|
+
declare function getCurrentToolCallContext(): LlmToolCallContext | null;
|
|
31
|
+
type JsonSchema = Record<string, unknown>;
|
|
32
|
+
type LlmRole = "user" | "model" | "system" | "tool";
|
|
33
|
+
type LlmInlineDataPart = {
|
|
34
|
+
type: "inlineData";
|
|
35
|
+
data: string;
|
|
36
|
+
mimeType?: string;
|
|
37
|
+
};
|
|
38
|
+
type LlmContentPart = {
|
|
39
|
+
type: "text";
|
|
40
|
+
text: string;
|
|
41
|
+
thought?: boolean;
|
|
42
|
+
} | LlmInlineDataPart;
|
|
43
|
+
type LlmContent = {
|
|
44
|
+
readonly role: LlmRole;
|
|
45
|
+
readonly parts: readonly LlmContentPart[];
|
|
46
|
+
};
|
|
47
|
+
type LlmImageSize = "1K" | "2K" | "4K";
|
|
48
|
+
type LlmWebSearchMode = "cached" | "live";
|
|
49
|
+
type LlmToolConfig = {
|
|
50
|
+
readonly type: "web-search";
|
|
51
|
+
readonly mode?: LlmWebSearchMode;
|
|
52
|
+
} | {
|
|
53
|
+
readonly type: "code-execution";
|
|
54
|
+
};
|
|
55
|
+
type LlmTextDeltaEvent = {
|
|
56
|
+
readonly type: "delta";
|
|
57
|
+
readonly channel: "response";
|
|
58
|
+
readonly text: string;
|
|
59
|
+
} | {
|
|
60
|
+
readonly type: "delta";
|
|
61
|
+
readonly channel: "thought";
|
|
62
|
+
readonly text: string;
|
|
63
|
+
};
|
|
64
|
+
type LlmUsageEvent = {
|
|
65
|
+
readonly type: "usage";
|
|
66
|
+
readonly usage: LlmUsageTokens;
|
|
67
|
+
readonly costUsd: number;
|
|
68
|
+
readonly modelVersion: string;
|
|
69
|
+
};
|
|
70
|
+
type LlmModelEvent = {
|
|
71
|
+
readonly type: "model";
|
|
72
|
+
readonly modelVersion: string;
|
|
73
|
+
};
|
|
74
|
+
type LlmBlockedEvent = {
|
|
75
|
+
readonly type: "blocked";
|
|
76
|
+
};
|
|
77
|
+
type LlmStreamEvent = LlmTextDeltaEvent | LlmUsageEvent | LlmModelEvent | LlmBlockedEvent;
|
|
78
|
+
type LlmProvider = "openai" | "chatgpt" | "gemini";
|
|
79
|
+
type LlmTextResult = {
|
|
80
|
+
readonly provider: LlmProvider;
|
|
81
|
+
readonly model: string;
|
|
82
|
+
readonly modelVersion: string;
|
|
83
|
+
readonly content?: LlmContent;
|
|
84
|
+
readonly text: string;
|
|
85
|
+
readonly thoughts: string;
|
|
86
|
+
readonly blocked: boolean;
|
|
87
|
+
readonly usage?: LlmUsageTokens;
|
|
88
|
+
readonly costUsd: number;
|
|
89
|
+
readonly grounding?: GroundingMetadata;
|
|
90
|
+
};
|
|
91
|
+
type LlmTextStream = {
|
|
92
|
+
readonly events: AsyncIterable<LlmStreamEvent>;
|
|
93
|
+
readonly result: Promise<LlmTextResult>;
|
|
94
|
+
readonly abort: () => void;
|
|
95
|
+
};
|
|
96
|
+
type LlmInput = {
|
|
97
|
+
readonly prompt: string;
|
|
98
|
+
readonly systemPrompt?: string;
|
|
99
|
+
} | {
|
|
100
|
+
readonly contents: readonly LlmContent[];
|
|
101
|
+
};
|
|
102
|
+
type LlmBaseRequest = {
|
|
103
|
+
readonly model: string;
|
|
104
|
+
readonly tools?: readonly LlmToolConfig[];
|
|
105
|
+
readonly responseMimeType?: string;
|
|
106
|
+
readonly responseJsonSchema?: JsonSchema;
|
|
107
|
+
readonly responseModalities?: readonly string[];
|
|
108
|
+
readonly imageAspectRatio?: string;
|
|
109
|
+
readonly imageSize?: LlmImageSize;
|
|
110
|
+
readonly openAiReasoningEffort?: OpenAiReasoningEffort;
|
|
111
|
+
readonly openAiTextFormat?: ResponseTextConfig["format"];
|
|
112
|
+
readonly signal?: AbortSignal;
|
|
113
|
+
};
|
|
114
|
+
type LlmTextRequest = LlmInput & LlmBaseRequest;
|
|
115
|
+
type LlmJsonRequest<T> = LlmInput & LlmBaseRequest & {
|
|
116
|
+
readonly schema: z.ZodType<T>;
|
|
117
|
+
readonly openAiSchemaName?: string;
|
|
118
|
+
readonly maxAttempts?: number;
|
|
119
|
+
readonly normalizeJson?: (value: unknown) => unknown;
|
|
120
|
+
};
|
|
121
|
+
declare class LlmJsonCallError extends Error {
|
|
122
|
+
readonly attempts: ReadonlyArray<{
|
|
123
|
+
readonly attempt: number;
|
|
124
|
+
readonly rawText: string;
|
|
125
|
+
readonly error: unknown;
|
|
126
|
+
}>;
|
|
127
|
+
constructor(message: string, attempts: ReadonlyArray<{
|
|
128
|
+
readonly attempt: number;
|
|
129
|
+
readonly rawText: string;
|
|
130
|
+
readonly error: unknown;
|
|
131
|
+
}>);
|
|
132
|
+
}
|
|
133
|
+
type LlmImageData = {
|
|
134
|
+
readonly mimeType?: string;
|
|
135
|
+
readonly data: Buffer;
|
|
136
|
+
};
|
|
137
|
+
type LlmGenerateImagesRequest = {
|
|
138
|
+
readonly model: string;
|
|
139
|
+
readonly stylePrompt: string;
|
|
140
|
+
readonly styleImages?: readonly LlmImageData[];
|
|
141
|
+
readonly imagePrompts: readonly string[];
|
|
142
|
+
readonly imageGradingPrompt: string;
|
|
143
|
+
readonly maxAttempts?: number;
|
|
144
|
+
readonly imageAspectRatio?: string;
|
|
145
|
+
readonly imageSize?: LlmImageSize;
|
|
146
|
+
readonly signal?: AbortSignal;
|
|
147
|
+
};
|
|
148
|
+
type LlmExecutableTool<Schema extends z.ZodType, Output> = {
|
|
149
|
+
readonly description?: string;
|
|
150
|
+
readonly inputSchema: Schema;
|
|
151
|
+
readonly execute: (input: z.output<Schema>) => Promise<Output> | Output;
|
|
152
|
+
};
|
|
153
|
+
type LlmToolSet = Record<string, LlmExecutableTool<z.ZodType, unknown>>;
|
|
154
|
+
declare function tool<Schema extends z.ZodType, Output>(options: {
|
|
155
|
+
readonly description?: string;
|
|
156
|
+
readonly inputSchema: Schema;
|
|
157
|
+
readonly execute: (input: z.output<Schema>) => Promise<Output> | Output;
|
|
158
|
+
}): LlmExecutableTool<Schema, Output>;
|
|
159
|
+
type LlmToolCallResult = {
|
|
160
|
+
readonly toolName: string;
|
|
161
|
+
readonly input: unknown;
|
|
162
|
+
readonly output: unknown;
|
|
163
|
+
readonly error?: string;
|
|
164
|
+
readonly callId?: string;
|
|
165
|
+
};
|
|
166
|
+
type LlmToolLoopStep = {
|
|
167
|
+
readonly step: number;
|
|
168
|
+
readonly modelVersion: string;
|
|
169
|
+
readonly text?: string;
|
|
170
|
+
readonly thoughts?: string;
|
|
171
|
+
readonly toolCalls: readonly LlmToolCallResult[];
|
|
172
|
+
readonly usage?: LlmUsageTokens;
|
|
173
|
+
readonly costUsd: number;
|
|
174
|
+
};
|
|
175
|
+
type LlmToolLoopResult = {
|
|
176
|
+
readonly text: string;
|
|
177
|
+
readonly thoughts: string;
|
|
178
|
+
readonly steps: readonly LlmToolLoopStep[];
|
|
179
|
+
readonly totalCostUsd: number;
|
|
180
|
+
};
|
|
181
|
+
type LlmToolLoopRequest = LlmInput & {
|
|
182
|
+
readonly model: string;
|
|
183
|
+
readonly tools: LlmToolSet;
|
|
184
|
+
readonly modelTools?: readonly LlmToolConfig[];
|
|
185
|
+
readonly maxSteps?: number;
|
|
186
|
+
readonly openAiReasoningEffort?: OpenAiReasoningEffort;
|
|
187
|
+
readonly onEvent?: (event: LlmStreamEvent) => void;
|
|
188
|
+
readonly signal?: AbortSignal;
|
|
189
|
+
};
|
|
190
|
+
declare function toGeminiJsonSchema(schema: z.ZodType, options?: {
|
|
191
|
+
name?: string;
|
|
192
|
+
}): JsonSchema;
|
|
193
|
+
declare function sanitisePartForLogging(part: LlmContentPart): unknown;
|
|
194
|
+
declare function convertGooglePartsToLlmParts(parts: readonly Part[]): LlmContentPart[];
|
|
195
|
+
declare function parseJsonFromLlmText(rawText: string): unknown;
|
|
196
|
+
declare function streamText(request: LlmTextRequest): LlmTextStream;
|
|
197
|
+
declare function generateText(request: LlmTextRequest): Promise<LlmTextResult>;
|
|
198
|
+
declare function generateJson<T>(request: LlmJsonRequest<T>): Promise<{
|
|
199
|
+
readonly value: T;
|
|
200
|
+
readonly rawText: string;
|
|
201
|
+
readonly result: LlmTextResult;
|
|
202
|
+
}>;
|
|
203
|
+
declare function runToolLoop(request: LlmToolLoopRequest): Promise<LlmToolLoopResult>;
|
|
204
|
+
declare function generateImages(request: LlmGenerateImagesRequest): Promise<LlmImageData[]>;
|
|
205
|
+
declare function generateImageInBatches(request: LlmGenerateImagesRequest & {
|
|
206
|
+
batchSize: number;
|
|
207
|
+
overlapSize: number;
|
|
208
|
+
}): Promise<LlmImageData[]>;
|
|
209
|
+
declare function stripCodexCitationMarkers(value: string): {
|
|
210
|
+
text: string;
|
|
211
|
+
stripped: boolean;
|
|
212
|
+
};
|
|
213
|
+
declare function appendMarkdownSourcesSection(value: string, sources: readonly string[]): string;
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Loads `.env.local` from `process.cwd()` once.
|
|
217
|
+
*
|
|
218
|
+
* - Does not override already-set `process.env` values.
|
|
219
|
+
* - Missing file is silently ignored.
|
|
220
|
+
*/
|
|
221
|
+
declare function loadLocalEnv(): void;
|
|
222
|
+
declare function loadEnvFromFile(filePath: string, { override }?: {
|
|
223
|
+
override?: boolean;
|
|
224
|
+
}): void;
|
|
225
|
+
|
|
226
|
+
type ChatGptAuthProfile = {
|
|
227
|
+
readonly access: string;
|
|
228
|
+
readonly refresh: string;
|
|
229
|
+
readonly expires: number;
|
|
230
|
+
readonly accountId: string;
|
|
231
|
+
readonly idToken?: string;
|
|
232
|
+
};
|
|
233
|
+
declare function encodeChatGptAuthJson(profile: ChatGptAuthProfile): string;
|
|
234
|
+
declare function encodeChatGptAuthJsonB64(profile: ChatGptAuthProfile): string;
|
|
235
|
+
declare function exchangeChatGptOauthCode({ code, verifier, redirectUri, }: {
|
|
236
|
+
code: string;
|
|
237
|
+
verifier: string;
|
|
238
|
+
redirectUri?: string;
|
|
239
|
+
}): Promise<ChatGptAuthProfile>;
|
|
240
|
+
declare function refreshChatGptOauthToken(refreshToken: string): Promise<ChatGptAuthProfile>;
|
|
241
|
+
declare function getChatGptAuthProfile(): Promise<ChatGptAuthProfile>;
|
|
242
|
+
|
|
243
|
+
declare const GEMINI_MODEL_IDS: readonly ["gemini-3-pro-preview", "gemini-2.5-pro", "gemini-flash-latest", "gemini-flash-lite-latest"];
|
|
244
|
+
type GeminiModelId = (typeof GEMINI_MODEL_IDS)[number];
|
|
245
|
+
declare function isGeminiModelId(value: string): value is GeminiModelId;
|
|
246
|
+
type GeminiConfiguration = {
|
|
247
|
+
readonly projectId?: string;
|
|
248
|
+
readonly location?: string;
|
|
249
|
+
};
|
|
250
|
+
declare function configureGemini(options?: GeminiConfiguration): void;
|
|
251
|
+
|
|
252
|
+
export { type ChatGptAuthProfile, type GeminiModelId, type JsonSchema, type LlmBaseRequest, type LlmBlockedEvent, type LlmContent, type LlmContentPart, type LlmExecutableTool, type LlmImageData, type LlmImageSize, type LlmInput, LlmJsonCallError, type LlmJsonRequest, type LlmModelEvent, type LlmProvider, type LlmStreamEvent, type LlmTextDeltaEvent, type LlmTextRequest, type LlmTextResult, type LlmTextStream, type LlmToolCallContext, type LlmToolCallResult, type LlmToolConfig, type LlmToolLoopRequest, type LlmToolLoopResult, type LlmToolLoopStep, type LlmToolSet, type LlmUsageEvent, type LlmUsageTokens, type LlmWebSearchMode, appendMarkdownSourcesSection, configureGemini, convertGooglePartsToLlmParts, encodeChatGptAuthJson, encodeChatGptAuthJsonB64, estimateCallCostUsd, exchangeChatGptOauthCode, generateImageInBatches, generateImages, generateJson, generateText, getChatGptAuthProfile, getCurrentToolCallContext, isGeminiModelId, loadEnvFromFile, loadLocalEnv, parseJsonFromLlmText, refreshChatGptOauthToken, runToolLoop, sanitisePartForLogging, streamText, stripCodexCitationMarkers, toGeminiJsonSchema, tool };
|