@ljoukov/llm 3.0.2 → 3.0.3
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/dist/index.cjs +131 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -7
- package/dist/index.d.ts +32 -7
- package/dist/index.js +116 -15
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
package/dist/index.d.cts
CHANGED
|
@@ -76,9 +76,18 @@ type LlmBlockedEvent = {
|
|
|
76
76
|
};
|
|
77
77
|
type LlmStreamEvent = LlmTextDeltaEvent | LlmUsageEvent | LlmModelEvent | LlmBlockedEvent;
|
|
78
78
|
type LlmProvider = "openai" | "chatgpt" | "gemini" | "fireworks";
|
|
79
|
+
declare const LLM_TEXT_MODEL_IDS: readonly ["gpt-5.3-codex", "gpt-5.3-codex-spark", "gpt-5.2", "gpt-5.1-codex-mini", "chatgpt-gpt-5.3-codex", "chatgpt-gpt-5.3-codex-spark", "chatgpt-gpt-5.2", "chatgpt-gpt-5.1-codex-mini", "kimi-k2.5", "glm-5", "minimax-m2.1", "gpt-oss-120b", "gemini-3-pro-preview", "gemini-3.1-pro-preview", "gemini-3-flash-preview", "gemini-2.5-pro", "gemini-flash-latest", "gemini-flash-lite-latest"];
|
|
80
|
+
type LlmTextModelId = (typeof LLM_TEXT_MODEL_IDS)[number];
|
|
81
|
+
declare const LLM_IMAGE_MODEL_IDS: readonly ["gemini-3-pro-image-preview"];
|
|
82
|
+
type LlmImageModelId = (typeof LLM_IMAGE_MODEL_IDS)[number];
|
|
83
|
+
declare const LLM_MODEL_IDS: readonly ["gpt-5.3-codex", "gpt-5.3-codex-spark", "gpt-5.2", "gpt-5.1-codex-mini", "chatgpt-gpt-5.3-codex", "chatgpt-gpt-5.3-codex-spark", "chatgpt-gpt-5.2", "chatgpt-gpt-5.1-codex-mini", "kimi-k2.5", "glm-5", "minimax-m2.1", "gpt-oss-120b", "gemini-3-pro-preview", "gemini-3.1-pro-preview", "gemini-3-flash-preview", "gemini-2.5-pro", "gemini-flash-latest", "gemini-flash-lite-latest", "gemini-3-pro-image-preview"];
|
|
84
|
+
type LlmModelId = (typeof LLM_MODEL_IDS)[number];
|
|
85
|
+
declare function isLlmTextModelId(value: string): value is LlmTextModelId;
|
|
86
|
+
declare function isLlmImageModelId(value: string): value is LlmImageModelId;
|
|
87
|
+
declare function isLlmModelId(value: string): value is LlmModelId;
|
|
79
88
|
type LlmTextResult = {
|
|
80
89
|
readonly provider: LlmProvider;
|
|
81
|
-
readonly model:
|
|
90
|
+
readonly model: LlmModelId;
|
|
82
91
|
readonly modelVersion: string;
|
|
83
92
|
readonly content?: LlmContent;
|
|
84
93
|
readonly text: string;
|
|
@@ -134,7 +143,7 @@ type LlmInput = {
|
|
|
134
143
|
readonly instructions?: string;
|
|
135
144
|
};
|
|
136
145
|
type LlmBaseRequest = {
|
|
137
|
-
readonly model:
|
|
146
|
+
readonly model: LlmModelId;
|
|
138
147
|
readonly tools?: readonly LlmToolConfig[];
|
|
139
148
|
readonly responseMimeType?: string;
|
|
140
149
|
readonly responseJsonSchema?: JsonSchema;
|
|
@@ -146,7 +155,10 @@ type LlmBaseRequest = {
|
|
|
146
155
|
readonly signal?: AbortSignal;
|
|
147
156
|
};
|
|
148
157
|
type LlmTextRequest = LlmInput & LlmBaseRequest;
|
|
149
|
-
type
|
|
158
|
+
type LlmStructuredRequestBase = Omit<LlmBaseRequest, "model"> & {
|
|
159
|
+
readonly model: LlmTextModelId;
|
|
160
|
+
};
|
|
161
|
+
type LlmJsonRequest<T> = LlmInput & LlmStructuredRequestBase & {
|
|
150
162
|
readonly schema: z.ZodType<T>;
|
|
151
163
|
readonly openAiSchemaName?: string;
|
|
152
164
|
readonly maxAttempts?: number;
|
|
@@ -181,7 +193,7 @@ type LlmImageData = {
|
|
|
181
193
|
readonly data: Buffer;
|
|
182
194
|
};
|
|
183
195
|
type LlmGenerateImagesRequest = {
|
|
184
|
-
readonly model:
|
|
196
|
+
readonly model: LlmImageModelId;
|
|
185
197
|
readonly stylePrompt: string;
|
|
186
198
|
readonly styleImages?: readonly LlmImageData[];
|
|
187
199
|
readonly imagePrompts: readonly string[];
|
|
@@ -245,7 +257,7 @@ type LlmToolLoopResult = {
|
|
|
245
257
|
readonly totalCostUsd: number;
|
|
246
258
|
};
|
|
247
259
|
type LlmToolLoopRequest = LlmInput & {
|
|
248
|
-
readonly model:
|
|
260
|
+
readonly model: LlmTextModelId;
|
|
249
261
|
readonly tools: LlmToolSet;
|
|
250
262
|
readonly modelTools?: readonly LlmToolConfig[];
|
|
251
263
|
readonly maxSteps?: number;
|
|
@@ -536,9 +548,22 @@ declare function refreshChatGptOauthToken(refreshToken: string, fallback?: {
|
|
|
536
548
|
}): Promise<ChatGptAuthProfile>;
|
|
537
549
|
declare function getChatGptAuthProfile(): Promise<ChatGptAuthProfile>;
|
|
538
550
|
|
|
539
|
-
declare const
|
|
551
|
+
declare const OPENAI_MODEL_IDS: readonly ["gpt-5.3-codex", "gpt-5.3-codex-spark", "gpt-5.2", "gpt-5.1-codex-mini"];
|
|
552
|
+
type OpenAiModelId = (typeof OPENAI_MODEL_IDS)[number];
|
|
553
|
+
declare function isOpenAiModelId(value: string): value is OpenAiModelId;
|
|
554
|
+
declare const CHATGPT_MODEL_IDS: readonly ["chatgpt-gpt-5.3-codex", "chatgpt-gpt-5.3-codex-spark", "chatgpt-gpt-5.2", "chatgpt-gpt-5.1-codex-mini"];
|
|
555
|
+
type ChatGptModelId = (typeof CHATGPT_MODEL_IDS)[number];
|
|
556
|
+
declare function isChatGptModelId(value: string): value is ChatGptModelId;
|
|
557
|
+
|
|
558
|
+
declare const GEMINI_TEXT_MODEL_IDS: readonly ["gemini-3-pro-preview", "gemini-3.1-pro-preview", "gemini-3-flash-preview", "gemini-2.5-pro", "gemini-flash-latest", "gemini-flash-lite-latest"];
|
|
559
|
+
declare const GEMINI_IMAGE_MODEL_IDS: readonly ["gemini-3-pro-image-preview"];
|
|
560
|
+
declare const GEMINI_MODEL_IDS: readonly ["gemini-3-pro-preview", "gemini-3.1-pro-preview", "gemini-3-flash-preview", "gemini-2.5-pro", "gemini-flash-latest", "gemini-flash-lite-latest", "gemini-3-pro-image-preview"];
|
|
540
561
|
type GeminiModelId = (typeof GEMINI_MODEL_IDS)[number];
|
|
562
|
+
type GeminiTextModelId = (typeof GEMINI_TEXT_MODEL_IDS)[number];
|
|
563
|
+
type GeminiImageModelId = (typeof GEMINI_IMAGE_MODEL_IDS)[number];
|
|
541
564
|
declare function isGeminiModelId(value: string): value is GeminiModelId;
|
|
565
|
+
declare function isGeminiTextModelId(value: string): value is GeminiTextModelId;
|
|
566
|
+
declare function isGeminiImageModelId(value: string): value is GeminiImageModelId;
|
|
542
567
|
type GeminiConfiguration = {
|
|
543
568
|
readonly projectId?: string;
|
|
544
569
|
readonly location?: string;
|
|
@@ -554,4 +579,4 @@ declare const FIREWORKS_DEFAULT_GPT_OSS_120B_MODEL: FireworksModelId;
|
|
|
554
579
|
declare function isFireworksModelId(value: string): value is FireworksModelId;
|
|
555
580
|
declare function resolveFireworksModelId(model: string): string | undefined;
|
|
556
581
|
|
|
557
|
-
export { type AgentDirectoryEntry, type AgentFilesystem, type AgentFilesystemToolAccessContext, type AgentFilesystemToolAccessHook, type AgentFilesystemToolAction, type AgentFilesystemToolConfig, type AgentFilesystemToolName, type AgentFilesystemToolProfile, type AgentFilesystemToolSelection, type AgentFilesystemToolsOptions, type AgentPathInfo, type AgentPathKind, type ApplyPatchAccessContext, type ApplyPatchAccessHook, type ApplyPatchRequest, type ApplyPatchResult, type ApplyPatchToolInput, CODEX_APPLY_PATCH_FREEFORM_TOOL_DESCRIPTION, CODEX_APPLY_PATCH_JSON_TOOL_DESCRIPTION, CODEX_APPLY_PATCH_LARK_GRAMMAR, type ChatGptAuthProfile, type CodexApplyPatchToolInput, type CodexGrepFilesToolInput, type CodexListDirToolInput, type CodexReadFileToolInput, type CreateApplyPatchToolOptions, FIREWORKS_DEFAULT_GLM_MODEL, FIREWORKS_DEFAULT_GPT_OSS_120B_MODEL, FIREWORKS_DEFAULT_KIMI_MODEL, FIREWORKS_DEFAULT_MINIMAX_MODEL, FIREWORKS_MODEL_IDS, type FireworksModelId, type GeminiGlobToolInput, type GeminiGrepSearchToolInput, type GeminiListDirectoryToolInput, type GeminiModelId, type GeminiReadFileToolInput, type GeminiReadFilesToolInput, type GeminiReplaceToolInput, type GeminiRgSearchToolInput, type GeminiWriteFileToolInput, InMemoryAgentFilesystem, type JsonSchema, type LlmBaseRequest, type LlmBlockedEvent, type LlmContent, type LlmContentPart, type LlmCustomTool, type LlmCustomToolInputFormat, type LlmExecutableTool, type LlmFunctionTool, type LlmImageData, type LlmImageSize, type LlmInput, type LlmInputMessage, LlmJsonCallError, type LlmJsonRequest, type LlmJsonStream, type LlmJsonStreamEvent, type LlmJsonStreamRequest, 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, type RunAgentLoopRequest, appendMarkdownSourcesSection, applyPatch, configureGemini, convertGooglePartsToLlmParts, createApplyPatchTool, createCodexApplyPatchTool, createCodexFilesystemToolSet, createCodexReadFileTool, createFilesystemToolSetForModel, createGeminiFilesystemToolSet, createGeminiReadFileTool, createGlobTool, createGrepFilesTool, createGrepSearchTool, createInMemoryAgentFilesystem, createListDirTool, createListDirectoryTool, createModelAgnosticFilesystemToolSet, createNodeAgentFilesystem, createReadFilesTool, createReplaceTool, createRgSearchTool, createWriteFileTool, customTool, encodeChatGptAuthJson, encodeChatGptAuthJsonB64, estimateCallCostUsd, exchangeChatGptOauthCode, generateImageInBatches, generateImages, generateJson, generateText, getChatGptAuthProfile, getCurrentToolCallContext, isFireworksModelId, isGeminiModelId, loadEnvFromFile, loadLocalEnv, parseJsonFromLlmText, refreshChatGptOauthToken, resolveFilesystemToolProfile, resolveFireworksModelId, runAgentLoop, runToolLoop, sanitisePartForLogging, streamJson, streamText, stripCodexCitationMarkers, toGeminiJsonSchema, tool };
|
|
582
|
+
export { type AgentDirectoryEntry, type AgentFilesystem, type AgentFilesystemToolAccessContext, type AgentFilesystemToolAccessHook, type AgentFilesystemToolAction, type AgentFilesystemToolConfig, type AgentFilesystemToolName, type AgentFilesystemToolProfile, type AgentFilesystemToolSelection, type AgentFilesystemToolsOptions, type AgentPathInfo, type AgentPathKind, type ApplyPatchAccessContext, type ApplyPatchAccessHook, type ApplyPatchRequest, type ApplyPatchResult, type ApplyPatchToolInput, CHATGPT_MODEL_IDS, CODEX_APPLY_PATCH_FREEFORM_TOOL_DESCRIPTION, CODEX_APPLY_PATCH_JSON_TOOL_DESCRIPTION, CODEX_APPLY_PATCH_LARK_GRAMMAR, type ChatGptAuthProfile, type ChatGptModelId, type CodexApplyPatchToolInput, type CodexGrepFilesToolInput, type CodexListDirToolInput, type CodexReadFileToolInput, type CreateApplyPatchToolOptions, FIREWORKS_DEFAULT_GLM_MODEL, FIREWORKS_DEFAULT_GPT_OSS_120B_MODEL, FIREWORKS_DEFAULT_KIMI_MODEL, FIREWORKS_DEFAULT_MINIMAX_MODEL, FIREWORKS_MODEL_IDS, type FireworksModelId, GEMINI_IMAGE_MODEL_IDS, GEMINI_MODEL_IDS, GEMINI_TEXT_MODEL_IDS, type GeminiGlobToolInput, type GeminiGrepSearchToolInput, type GeminiImageModelId, type GeminiListDirectoryToolInput, type GeminiModelId, type GeminiReadFileToolInput, type GeminiReadFilesToolInput, type GeminiReplaceToolInput, type GeminiRgSearchToolInput, type GeminiTextModelId, type GeminiWriteFileToolInput, InMemoryAgentFilesystem, type JsonSchema, LLM_IMAGE_MODEL_IDS, LLM_MODEL_IDS, LLM_TEXT_MODEL_IDS, type LlmBaseRequest, type LlmBlockedEvent, type LlmContent, type LlmContentPart, type LlmCustomTool, type LlmCustomToolInputFormat, type LlmExecutableTool, type LlmFunctionTool, type LlmImageData, type LlmImageModelId, type LlmImageSize, type LlmInput, type LlmInputMessage, LlmJsonCallError, type LlmJsonRequest, type LlmJsonStream, type LlmJsonStreamEvent, type LlmJsonStreamRequest, type LlmModelEvent, type LlmModelId, type LlmProvider, type LlmStreamEvent, type LlmTextDeltaEvent, type LlmTextModelId, 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, OPENAI_MODEL_IDS, type OpenAiModelId, type RunAgentLoopRequest, appendMarkdownSourcesSection, applyPatch, configureGemini, convertGooglePartsToLlmParts, createApplyPatchTool, createCodexApplyPatchTool, createCodexFilesystemToolSet, createCodexReadFileTool, createFilesystemToolSetForModel, createGeminiFilesystemToolSet, createGeminiReadFileTool, createGlobTool, createGrepFilesTool, createGrepSearchTool, createInMemoryAgentFilesystem, createListDirTool, createListDirectoryTool, createModelAgnosticFilesystemToolSet, createNodeAgentFilesystem, createReadFilesTool, createReplaceTool, createRgSearchTool, createWriteFileTool, customTool, encodeChatGptAuthJson, encodeChatGptAuthJsonB64, estimateCallCostUsd, exchangeChatGptOauthCode, generateImageInBatches, generateImages, generateJson, generateText, getChatGptAuthProfile, getCurrentToolCallContext, isChatGptModelId, isFireworksModelId, isGeminiImageModelId, isGeminiModelId, isGeminiTextModelId, isLlmImageModelId, isLlmModelId, isLlmTextModelId, isOpenAiModelId, loadEnvFromFile, loadLocalEnv, parseJsonFromLlmText, refreshChatGptOauthToken, resolveFilesystemToolProfile, resolveFireworksModelId, runAgentLoop, runToolLoop, sanitisePartForLogging, streamJson, streamText, stripCodexCitationMarkers, toGeminiJsonSchema, tool };
|
package/dist/index.d.ts
CHANGED
|
@@ -76,9 +76,18 @@ type LlmBlockedEvent = {
|
|
|
76
76
|
};
|
|
77
77
|
type LlmStreamEvent = LlmTextDeltaEvent | LlmUsageEvent | LlmModelEvent | LlmBlockedEvent;
|
|
78
78
|
type LlmProvider = "openai" | "chatgpt" | "gemini" | "fireworks";
|
|
79
|
+
declare const LLM_TEXT_MODEL_IDS: readonly ["gpt-5.3-codex", "gpt-5.3-codex-spark", "gpt-5.2", "gpt-5.1-codex-mini", "chatgpt-gpt-5.3-codex", "chatgpt-gpt-5.3-codex-spark", "chatgpt-gpt-5.2", "chatgpt-gpt-5.1-codex-mini", "kimi-k2.5", "glm-5", "minimax-m2.1", "gpt-oss-120b", "gemini-3-pro-preview", "gemini-3.1-pro-preview", "gemini-3-flash-preview", "gemini-2.5-pro", "gemini-flash-latest", "gemini-flash-lite-latest"];
|
|
80
|
+
type LlmTextModelId = (typeof LLM_TEXT_MODEL_IDS)[number];
|
|
81
|
+
declare const LLM_IMAGE_MODEL_IDS: readonly ["gemini-3-pro-image-preview"];
|
|
82
|
+
type LlmImageModelId = (typeof LLM_IMAGE_MODEL_IDS)[number];
|
|
83
|
+
declare const LLM_MODEL_IDS: readonly ["gpt-5.3-codex", "gpt-5.3-codex-spark", "gpt-5.2", "gpt-5.1-codex-mini", "chatgpt-gpt-5.3-codex", "chatgpt-gpt-5.3-codex-spark", "chatgpt-gpt-5.2", "chatgpt-gpt-5.1-codex-mini", "kimi-k2.5", "glm-5", "minimax-m2.1", "gpt-oss-120b", "gemini-3-pro-preview", "gemini-3.1-pro-preview", "gemini-3-flash-preview", "gemini-2.5-pro", "gemini-flash-latest", "gemini-flash-lite-latest", "gemini-3-pro-image-preview"];
|
|
84
|
+
type LlmModelId = (typeof LLM_MODEL_IDS)[number];
|
|
85
|
+
declare function isLlmTextModelId(value: string): value is LlmTextModelId;
|
|
86
|
+
declare function isLlmImageModelId(value: string): value is LlmImageModelId;
|
|
87
|
+
declare function isLlmModelId(value: string): value is LlmModelId;
|
|
79
88
|
type LlmTextResult = {
|
|
80
89
|
readonly provider: LlmProvider;
|
|
81
|
-
readonly model:
|
|
90
|
+
readonly model: LlmModelId;
|
|
82
91
|
readonly modelVersion: string;
|
|
83
92
|
readonly content?: LlmContent;
|
|
84
93
|
readonly text: string;
|
|
@@ -134,7 +143,7 @@ type LlmInput = {
|
|
|
134
143
|
readonly instructions?: string;
|
|
135
144
|
};
|
|
136
145
|
type LlmBaseRequest = {
|
|
137
|
-
readonly model:
|
|
146
|
+
readonly model: LlmModelId;
|
|
138
147
|
readonly tools?: readonly LlmToolConfig[];
|
|
139
148
|
readonly responseMimeType?: string;
|
|
140
149
|
readonly responseJsonSchema?: JsonSchema;
|
|
@@ -146,7 +155,10 @@ type LlmBaseRequest = {
|
|
|
146
155
|
readonly signal?: AbortSignal;
|
|
147
156
|
};
|
|
148
157
|
type LlmTextRequest = LlmInput & LlmBaseRequest;
|
|
149
|
-
type
|
|
158
|
+
type LlmStructuredRequestBase = Omit<LlmBaseRequest, "model"> & {
|
|
159
|
+
readonly model: LlmTextModelId;
|
|
160
|
+
};
|
|
161
|
+
type LlmJsonRequest<T> = LlmInput & LlmStructuredRequestBase & {
|
|
150
162
|
readonly schema: z.ZodType<T>;
|
|
151
163
|
readonly openAiSchemaName?: string;
|
|
152
164
|
readonly maxAttempts?: number;
|
|
@@ -181,7 +193,7 @@ type LlmImageData = {
|
|
|
181
193
|
readonly data: Buffer;
|
|
182
194
|
};
|
|
183
195
|
type LlmGenerateImagesRequest = {
|
|
184
|
-
readonly model:
|
|
196
|
+
readonly model: LlmImageModelId;
|
|
185
197
|
readonly stylePrompt: string;
|
|
186
198
|
readonly styleImages?: readonly LlmImageData[];
|
|
187
199
|
readonly imagePrompts: readonly string[];
|
|
@@ -245,7 +257,7 @@ type LlmToolLoopResult = {
|
|
|
245
257
|
readonly totalCostUsd: number;
|
|
246
258
|
};
|
|
247
259
|
type LlmToolLoopRequest = LlmInput & {
|
|
248
|
-
readonly model:
|
|
260
|
+
readonly model: LlmTextModelId;
|
|
249
261
|
readonly tools: LlmToolSet;
|
|
250
262
|
readonly modelTools?: readonly LlmToolConfig[];
|
|
251
263
|
readonly maxSteps?: number;
|
|
@@ -536,9 +548,22 @@ declare function refreshChatGptOauthToken(refreshToken: string, fallback?: {
|
|
|
536
548
|
}): Promise<ChatGptAuthProfile>;
|
|
537
549
|
declare function getChatGptAuthProfile(): Promise<ChatGptAuthProfile>;
|
|
538
550
|
|
|
539
|
-
declare const
|
|
551
|
+
declare const OPENAI_MODEL_IDS: readonly ["gpt-5.3-codex", "gpt-5.3-codex-spark", "gpt-5.2", "gpt-5.1-codex-mini"];
|
|
552
|
+
type OpenAiModelId = (typeof OPENAI_MODEL_IDS)[number];
|
|
553
|
+
declare function isOpenAiModelId(value: string): value is OpenAiModelId;
|
|
554
|
+
declare const CHATGPT_MODEL_IDS: readonly ["chatgpt-gpt-5.3-codex", "chatgpt-gpt-5.3-codex-spark", "chatgpt-gpt-5.2", "chatgpt-gpt-5.1-codex-mini"];
|
|
555
|
+
type ChatGptModelId = (typeof CHATGPT_MODEL_IDS)[number];
|
|
556
|
+
declare function isChatGptModelId(value: string): value is ChatGptModelId;
|
|
557
|
+
|
|
558
|
+
declare const GEMINI_TEXT_MODEL_IDS: readonly ["gemini-3-pro-preview", "gemini-3.1-pro-preview", "gemini-3-flash-preview", "gemini-2.5-pro", "gemini-flash-latest", "gemini-flash-lite-latest"];
|
|
559
|
+
declare const GEMINI_IMAGE_MODEL_IDS: readonly ["gemini-3-pro-image-preview"];
|
|
560
|
+
declare const GEMINI_MODEL_IDS: readonly ["gemini-3-pro-preview", "gemini-3.1-pro-preview", "gemini-3-flash-preview", "gemini-2.5-pro", "gemini-flash-latest", "gemini-flash-lite-latest", "gemini-3-pro-image-preview"];
|
|
540
561
|
type GeminiModelId = (typeof GEMINI_MODEL_IDS)[number];
|
|
562
|
+
type GeminiTextModelId = (typeof GEMINI_TEXT_MODEL_IDS)[number];
|
|
563
|
+
type GeminiImageModelId = (typeof GEMINI_IMAGE_MODEL_IDS)[number];
|
|
541
564
|
declare function isGeminiModelId(value: string): value is GeminiModelId;
|
|
565
|
+
declare function isGeminiTextModelId(value: string): value is GeminiTextModelId;
|
|
566
|
+
declare function isGeminiImageModelId(value: string): value is GeminiImageModelId;
|
|
542
567
|
type GeminiConfiguration = {
|
|
543
568
|
readonly projectId?: string;
|
|
544
569
|
readonly location?: string;
|
|
@@ -554,4 +579,4 @@ declare const FIREWORKS_DEFAULT_GPT_OSS_120B_MODEL: FireworksModelId;
|
|
|
554
579
|
declare function isFireworksModelId(value: string): value is FireworksModelId;
|
|
555
580
|
declare function resolveFireworksModelId(model: string): string | undefined;
|
|
556
581
|
|
|
557
|
-
export { type AgentDirectoryEntry, type AgentFilesystem, type AgentFilesystemToolAccessContext, type AgentFilesystemToolAccessHook, type AgentFilesystemToolAction, type AgentFilesystemToolConfig, type AgentFilesystemToolName, type AgentFilesystemToolProfile, type AgentFilesystemToolSelection, type AgentFilesystemToolsOptions, type AgentPathInfo, type AgentPathKind, type ApplyPatchAccessContext, type ApplyPatchAccessHook, type ApplyPatchRequest, type ApplyPatchResult, type ApplyPatchToolInput, CODEX_APPLY_PATCH_FREEFORM_TOOL_DESCRIPTION, CODEX_APPLY_PATCH_JSON_TOOL_DESCRIPTION, CODEX_APPLY_PATCH_LARK_GRAMMAR, type ChatGptAuthProfile, type CodexApplyPatchToolInput, type CodexGrepFilesToolInput, type CodexListDirToolInput, type CodexReadFileToolInput, type CreateApplyPatchToolOptions, FIREWORKS_DEFAULT_GLM_MODEL, FIREWORKS_DEFAULT_GPT_OSS_120B_MODEL, FIREWORKS_DEFAULT_KIMI_MODEL, FIREWORKS_DEFAULT_MINIMAX_MODEL, FIREWORKS_MODEL_IDS, type FireworksModelId, type GeminiGlobToolInput, type GeminiGrepSearchToolInput, type GeminiListDirectoryToolInput, type GeminiModelId, type GeminiReadFileToolInput, type GeminiReadFilesToolInput, type GeminiReplaceToolInput, type GeminiRgSearchToolInput, type GeminiWriteFileToolInput, InMemoryAgentFilesystem, type JsonSchema, type LlmBaseRequest, type LlmBlockedEvent, type LlmContent, type LlmContentPart, type LlmCustomTool, type LlmCustomToolInputFormat, type LlmExecutableTool, type LlmFunctionTool, type LlmImageData, type LlmImageSize, type LlmInput, type LlmInputMessage, LlmJsonCallError, type LlmJsonRequest, type LlmJsonStream, type LlmJsonStreamEvent, type LlmJsonStreamRequest, 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, type RunAgentLoopRequest, appendMarkdownSourcesSection, applyPatch, configureGemini, convertGooglePartsToLlmParts, createApplyPatchTool, createCodexApplyPatchTool, createCodexFilesystemToolSet, createCodexReadFileTool, createFilesystemToolSetForModel, createGeminiFilesystemToolSet, createGeminiReadFileTool, createGlobTool, createGrepFilesTool, createGrepSearchTool, createInMemoryAgentFilesystem, createListDirTool, createListDirectoryTool, createModelAgnosticFilesystemToolSet, createNodeAgentFilesystem, createReadFilesTool, createReplaceTool, createRgSearchTool, createWriteFileTool, customTool, encodeChatGptAuthJson, encodeChatGptAuthJsonB64, estimateCallCostUsd, exchangeChatGptOauthCode, generateImageInBatches, generateImages, generateJson, generateText, getChatGptAuthProfile, getCurrentToolCallContext, isFireworksModelId, isGeminiModelId, loadEnvFromFile, loadLocalEnv, parseJsonFromLlmText, refreshChatGptOauthToken, resolveFilesystemToolProfile, resolveFireworksModelId, runAgentLoop, runToolLoop, sanitisePartForLogging, streamJson, streamText, stripCodexCitationMarkers, toGeminiJsonSchema, tool };
|
|
582
|
+
export { type AgentDirectoryEntry, type AgentFilesystem, type AgentFilesystemToolAccessContext, type AgentFilesystemToolAccessHook, type AgentFilesystemToolAction, type AgentFilesystemToolConfig, type AgentFilesystemToolName, type AgentFilesystemToolProfile, type AgentFilesystemToolSelection, type AgentFilesystemToolsOptions, type AgentPathInfo, type AgentPathKind, type ApplyPatchAccessContext, type ApplyPatchAccessHook, type ApplyPatchRequest, type ApplyPatchResult, type ApplyPatchToolInput, CHATGPT_MODEL_IDS, CODEX_APPLY_PATCH_FREEFORM_TOOL_DESCRIPTION, CODEX_APPLY_PATCH_JSON_TOOL_DESCRIPTION, CODEX_APPLY_PATCH_LARK_GRAMMAR, type ChatGptAuthProfile, type ChatGptModelId, type CodexApplyPatchToolInput, type CodexGrepFilesToolInput, type CodexListDirToolInput, type CodexReadFileToolInput, type CreateApplyPatchToolOptions, FIREWORKS_DEFAULT_GLM_MODEL, FIREWORKS_DEFAULT_GPT_OSS_120B_MODEL, FIREWORKS_DEFAULT_KIMI_MODEL, FIREWORKS_DEFAULT_MINIMAX_MODEL, FIREWORKS_MODEL_IDS, type FireworksModelId, GEMINI_IMAGE_MODEL_IDS, GEMINI_MODEL_IDS, GEMINI_TEXT_MODEL_IDS, type GeminiGlobToolInput, type GeminiGrepSearchToolInput, type GeminiImageModelId, type GeminiListDirectoryToolInput, type GeminiModelId, type GeminiReadFileToolInput, type GeminiReadFilesToolInput, type GeminiReplaceToolInput, type GeminiRgSearchToolInput, type GeminiTextModelId, type GeminiWriteFileToolInput, InMemoryAgentFilesystem, type JsonSchema, LLM_IMAGE_MODEL_IDS, LLM_MODEL_IDS, LLM_TEXT_MODEL_IDS, type LlmBaseRequest, type LlmBlockedEvent, type LlmContent, type LlmContentPart, type LlmCustomTool, type LlmCustomToolInputFormat, type LlmExecutableTool, type LlmFunctionTool, type LlmImageData, type LlmImageModelId, type LlmImageSize, type LlmInput, type LlmInputMessage, LlmJsonCallError, type LlmJsonRequest, type LlmJsonStream, type LlmJsonStreamEvent, type LlmJsonStreamRequest, type LlmModelEvent, type LlmModelId, type LlmProvider, type LlmStreamEvent, type LlmTextDeltaEvent, type LlmTextModelId, 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, OPENAI_MODEL_IDS, type OpenAiModelId, type RunAgentLoopRequest, appendMarkdownSourcesSection, applyPatch, configureGemini, convertGooglePartsToLlmParts, createApplyPatchTool, createCodexApplyPatchTool, createCodexFilesystemToolSet, createCodexReadFileTool, createFilesystemToolSetForModel, createGeminiFilesystemToolSet, createGeminiReadFileTool, createGlobTool, createGrepFilesTool, createGrepSearchTool, createInMemoryAgentFilesystem, createListDirTool, createListDirectoryTool, createModelAgnosticFilesystemToolSet, createNodeAgentFilesystem, createReadFilesTool, createReplaceTool, createRgSearchTool, createWriteFileTool, customTool, encodeChatGptAuthJson, encodeChatGptAuthJsonB64, estimateCallCostUsd, exchangeChatGptOauthCode, generateImageInBatches, generateImages, generateJson, generateText, getChatGptAuthProfile, getCurrentToolCallContext, isChatGptModelId, isFireworksModelId, isGeminiImageModelId, isGeminiModelId, isGeminiTextModelId, isLlmImageModelId, isLlmModelId, isLlmTextModelId, isOpenAiModelId, loadEnvFromFile, loadLocalEnv, parseJsonFromLlmText, refreshChatGptOauthToken, resolveFilesystemToolProfile, resolveFireworksModelId, runAgentLoop, runToolLoop, sanitisePartForLogging, streamJson, streamText, stripCodexCitationMarkers, toGeminiJsonSchema, tool };
|
package/dist/index.js
CHANGED
|
@@ -171,9 +171,6 @@ function getOpenAiPricing(modelId) {
|
|
|
171
171
|
if (modelId.includes("gpt-5.3-codex")) {
|
|
172
172
|
return OPENAI_GPT_53_CODEX_PRICING;
|
|
173
173
|
}
|
|
174
|
-
if (modelId.includes("gpt-5-codex")) {
|
|
175
|
-
return OPENAI_GPT_53_CODEX_PRICING;
|
|
176
|
-
}
|
|
177
174
|
if (modelId.includes("gpt-5.2")) {
|
|
178
175
|
return OPENAI_GPT_52_PRICING;
|
|
179
176
|
}
|
|
@@ -696,6 +693,22 @@ var ResponsesWebSocketHttpError = class extends Error {
|
|
|
696
693
|
this.headers = options.headers;
|
|
697
694
|
}
|
|
698
695
|
};
|
|
696
|
+
var UNSUPPORTED_WEBSOCKET_STATUS_CODES = /* @__PURE__ */ new Set([400, 404, 405, 406, 426, 501]);
|
|
697
|
+
var WEBSOCKET_CONNECT_TIMEOUT_MS = 3e4;
|
|
698
|
+
function parseUnexpectedServerResponseStatus(message) {
|
|
699
|
+
const match = /unexpected server response:\s*(\d+)/i.exec(message);
|
|
700
|
+
if (!match) {
|
|
701
|
+
return null;
|
|
702
|
+
}
|
|
703
|
+
const status = Number(match[1]);
|
|
704
|
+
if (!Number.isFinite(status) || status <= 0) {
|
|
705
|
+
return null;
|
|
706
|
+
}
|
|
707
|
+
return status;
|
|
708
|
+
}
|
|
709
|
+
function supportsUnexpectedResponseEvent() {
|
|
710
|
+
return !("bun" in process.versions);
|
|
711
|
+
}
|
|
699
712
|
function resolveResponsesWebSocketMode(raw, fallback = "auto") {
|
|
700
713
|
const value = raw?.trim().toLowerCase();
|
|
701
714
|
if (value === "auto" || value === "off" || value === "only") {
|
|
@@ -730,9 +743,13 @@ function toWebSocketUrl(httpOrHttpsUrl) {
|
|
|
730
743
|
}
|
|
731
744
|
function isResponsesWebSocketUnsupportedError(error) {
|
|
732
745
|
if (error instanceof ResponsesWebSocketHttpError) {
|
|
733
|
-
return
|
|
746
|
+
return UNSUPPORTED_WEBSOCKET_STATUS_CODES.has(error.status);
|
|
734
747
|
}
|
|
735
748
|
const message = error instanceof Error ? error.message.toLowerCase() : "";
|
|
749
|
+
const status = parseUnexpectedServerResponseStatus(message);
|
|
750
|
+
if (status !== null) {
|
|
751
|
+
return UNSUPPORTED_WEBSOCKET_STATUS_CODES.has(status);
|
|
752
|
+
}
|
|
736
753
|
return message.includes("unexpected server response: 426");
|
|
737
754
|
}
|
|
738
755
|
function createAdaptiveResponsesStream(options) {
|
|
@@ -971,12 +988,20 @@ async function createResponsesWebSocketStream(options) {
|
|
|
971
988
|
}
|
|
972
989
|
async function connectWebSocket(options) {
|
|
973
990
|
return await new Promise((resolve, reject) => {
|
|
991
|
+
const shouldListenForUnexpectedResponse = supportsUnexpectedResponseEvent();
|
|
974
992
|
const socket = new WebSocket(options.url, {
|
|
975
993
|
headers: options.headers,
|
|
976
|
-
handshakeTimeout:
|
|
994
|
+
handshakeTimeout: WEBSOCKET_CONNECT_TIMEOUT_MS
|
|
977
995
|
});
|
|
978
996
|
let settled = false;
|
|
979
997
|
let responseBody = "";
|
|
998
|
+
let connectTimeout = setTimeout(() => {
|
|
999
|
+
rejectOnce(
|
|
1000
|
+
new Error(
|
|
1001
|
+
`Responses WebSocket connection timed out after ${WEBSOCKET_CONNECT_TIMEOUT_MS}ms.`
|
|
1002
|
+
)
|
|
1003
|
+
);
|
|
1004
|
+
}, WEBSOCKET_CONNECT_TIMEOUT_MS);
|
|
980
1005
|
const rejectOnce = (error) => {
|
|
981
1006
|
if (settled) {
|
|
982
1007
|
return;
|
|
@@ -1001,9 +1026,15 @@ async function connectWebSocket(options) {
|
|
|
1001
1026
|
rejectOnce(createAbortError(options.signal?.reason));
|
|
1002
1027
|
};
|
|
1003
1028
|
const cleanup = (removeAbortListener = true) => {
|
|
1029
|
+
if (connectTimeout) {
|
|
1030
|
+
clearTimeout(connectTimeout);
|
|
1031
|
+
connectTimeout = null;
|
|
1032
|
+
}
|
|
1004
1033
|
socket.removeListener("open", onOpen);
|
|
1005
1034
|
socket.removeListener("error", onError);
|
|
1006
|
-
|
|
1035
|
+
if (shouldListenForUnexpectedResponse) {
|
|
1036
|
+
socket.removeListener("unexpected-response", onUnexpectedResponse);
|
|
1037
|
+
}
|
|
1007
1038
|
if (removeAbortListener && options.signal) {
|
|
1008
1039
|
options.signal.removeEventListener("abort", onAbort);
|
|
1009
1040
|
}
|
|
@@ -1054,7 +1085,9 @@ async function connectWebSocket(options) {
|
|
|
1054
1085
|
};
|
|
1055
1086
|
socket.once("open", onOpen);
|
|
1056
1087
|
socket.once("error", onError);
|
|
1057
|
-
|
|
1088
|
+
if (shouldListenForUnexpectedResponse) {
|
|
1089
|
+
socket.once("unexpected-response", onUnexpectedResponse);
|
|
1090
|
+
}
|
|
1058
1091
|
if (options.signal) {
|
|
1059
1092
|
if (options.signal.aborted) {
|
|
1060
1093
|
onAbort();
|
|
@@ -1821,7 +1854,7 @@ function getGoogleAuthOptions(scopes) {
|
|
|
1821
1854
|
}
|
|
1822
1855
|
|
|
1823
1856
|
// src/google/client.ts
|
|
1824
|
-
var
|
|
1857
|
+
var GEMINI_TEXT_MODEL_IDS = [
|
|
1825
1858
|
"gemini-3-pro-preview",
|
|
1826
1859
|
"gemini-3.1-pro-preview",
|
|
1827
1860
|
"gemini-3-flash-preview",
|
|
@@ -1829,9 +1862,17 @@ var GEMINI_MODEL_IDS = [
|
|
|
1829
1862
|
"gemini-flash-latest",
|
|
1830
1863
|
"gemini-flash-lite-latest"
|
|
1831
1864
|
];
|
|
1865
|
+
var GEMINI_IMAGE_MODEL_IDS = ["gemini-3-pro-image-preview"];
|
|
1866
|
+
var GEMINI_MODEL_IDS = [...GEMINI_TEXT_MODEL_IDS, ...GEMINI_IMAGE_MODEL_IDS];
|
|
1832
1867
|
function isGeminiModelId(value) {
|
|
1833
1868
|
return GEMINI_MODEL_IDS.includes(value);
|
|
1834
1869
|
}
|
|
1870
|
+
function isGeminiTextModelId(value) {
|
|
1871
|
+
return GEMINI_TEXT_MODEL_IDS.includes(value);
|
|
1872
|
+
}
|
|
1873
|
+
function isGeminiImageModelId(value) {
|
|
1874
|
+
return GEMINI_IMAGE_MODEL_IDS.includes(value);
|
|
1875
|
+
}
|
|
1835
1876
|
var CLOUD_PLATFORM_SCOPE = "https://www.googleapis.com/auth/cloud-platform";
|
|
1836
1877
|
var DEFAULT_VERTEX_LOCATION = "global";
|
|
1837
1878
|
var geminiConfiguration = {};
|
|
@@ -2250,11 +2291,51 @@ async function runOpenAiCall(fn) {
|
|
|
2250
2291
|
return scheduler3.run(async () => fn(getOpenAiClient()));
|
|
2251
2292
|
}
|
|
2252
2293
|
|
|
2294
|
+
// src/openai/models.ts
|
|
2295
|
+
var OPENAI_MODEL_IDS = [
|
|
2296
|
+
"gpt-5.3-codex",
|
|
2297
|
+
"gpt-5.3-codex-spark",
|
|
2298
|
+
"gpt-5.2",
|
|
2299
|
+
"gpt-5.1-codex-mini"
|
|
2300
|
+
];
|
|
2301
|
+
function isOpenAiModelId(value) {
|
|
2302
|
+
return OPENAI_MODEL_IDS.includes(value);
|
|
2303
|
+
}
|
|
2304
|
+
var CHATGPT_MODEL_IDS = [
|
|
2305
|
+
"chatgpt-gpt-5.3-codex",
|
|
2306
|
+
"chatgpt-gpt-5.3-codex-spark",
|
|
2307
|
+
"chatgpt-gpt-5.2",
|
|
2308
|
+
"chatgpt-gpt-5.1-codex-mini"
|
|
2309
|
+
];
|
|
2310
|
+
function isChatGptModelId(value) {
|
|
2311
|
+
return CHATGPT_MODEL_IDS.includes(value);
|
|
2312
|
+
}
|
|
2313
|
+
function stripChatGptPrefix(model) {
|
|
2314
|
+
return model.slice("chatgpt-".length);
|
|
2315
|
+
}
|
|
2316
|
+
|
|
2253
2317
|
// src/llm.ts
|
|
2254
2318
|
var toolCallContextStorage = new AsyncLocalStorage();
|
|
2255
2319
|
function getCurrentToolCallContext() {
|
|
2256
2320
|
return toolCallContextStorage.getStore() ?? null;
|
|
2257
2321
|
}
|
|
2322
|
+
var LLM_TEXT_MODEL_IDS = [
|
|
2323
|
+
...OPENAI_MODEL_IDS,
|
|
2324
|
+
...CHATGPT_MODEL_IDS,
|
|
2325
|
+
...FIREWORKS_MODEL_IDS,
|
|
2326
|
+
...GEMINI_TEXT_MODEL_IDS
|
|
2327
|
+
];
|
|
2328
|
+
var LLM_IMAGE_MODEL_IDS = [...GEMINI_IMAGE_MODEL_IDS];
|
|
2329
|
+
var LLM_MODEL_IDS = [...LLM_TEXT_MODEL_IDS, ...LLM_IMAGE_MODEL_IDS];
|
|
2330
|
+
function isLlmTextModelId(value) {
|
|
2331
|
+
return isOpenAiModelId(value) || isChatGptModelId(value) || isFireworksModelId(value) || isGeminiTextModelId(value);
|
|
2332
|
+
}
|
|
2333
|
+
function isLlmImageModelId(value) {
|
|
2334
|
+
return isGeminiImageModelId(value);
|
|
2335
|
+
}
|
|
2336
|
+
function isLlmModelId(value) {
|
|
2337
|
+
return isLlmTextModelId(value) || isLlmImageModelId(value);
|
|
2338
|
+
}
|
|
2258
2339
|
var LlmJsonCallError = class extends Error {
|
|
2259
2340
|
constructor(message, attempts) {
|
|
2260
2341
|
super(message);
|
|
@@ -2612,17 +2693,22 @@ function convertLlmContentToGeminiContent(content) {
|
|
|
2612
2693
|
};
|
|
2613
2694
|
}
|
|
2614
2695
|
function resolveProvider(model) {
|
|
2615
|
-
if (model
|
|
2616
|
-
return { provider: "chatgpt", model: model
|
|
2696
|
+
if (isChatGptModelId(model)) {
|
|
2697
|
+
return { provider: "chatgpt", model: stripChatGptPrefix(model) };
|
|
2617
2698
|
}
|
|
2618
|
-
if (model
|
|
2699
|
+
if (isGeminiTextModelId(model) || isGeminiImageModelId(model)) {
|
|
2619
2700
|
return { provider: "gemini", model };
|
|
2620
2701
|
}
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2702
|
+
if (isFireworksModelId(model)) {
|
|
2703
|
+
const fireworksModel = resolveFireworksModelId(model);
|
|
2704
|
+
if (fireworksModel) {
|
|
2705
|
+
return { provider: "fireworks", model: fireworksModel };
|
|
2706
|
+
}
|
|
2707
|
+
}
|
|
2708
|
+
if (isOpenAiModelId(model)) {
|
|
2709
|
+
return { provider: "openai", model };
|
|
2624
2710
|
}
|
|
2625
|
-
|
|
2711
|
+
throw new Error(`Unsupported text model: ${model}`);
|
|
2626
2712
|
}
|
|
2627
2713
|
function isOpenAiCodexModel(modelId) {
|
|
2628
2714
|
return modelId.includes("codex");
|
|
@@ -7205,6 +7291,7 @@ function mergeToolSets(base, extra) {
|
|
|
7205
7291
|
return merged;
|
|
7206
7292
|
}
|
|
7207
7293
|
export {
|
|
7294
|
+
CHATGPT_MODEL_IDS,
|
|
7208
7295
|
CODEX_APPLY_PATCH_FREEFORM_TOOL_DESCRIPTION,
|
|
7209
7296
|
CODEX_APPLY_PATCH_JSON_TOOL_DESCRIPTION,
|
|
7210
7297
|
CODEX_APPLY_PATCH_LARK_GRAMMAR,
|
|
@@ -7213,8 +7300,15 @@ export {
|
|
|
7213
7300
|
FIREWORKS_DEFAULT_KIMI_MODEL,
|
|
7214
7301
|
FIREWORKS_DEFAULT_MINIMAX_MODEL,
|
|
7215
7302
|
FIREWORKS_MODEL_IDS,
|
|
7303
|
+
GEMINI_IMAGE_MODEL_IDS,
|
|
7304
|
+
GEMINI_MODEL_IDS,
|
|
7305
|
+
GEMINI_TEXT_MODEL_IDS,
|
|
7216
7306
|
InMemoryAgentFilesystem,
|
|
7307
|
+
LLM_IMAGE_MODEL_IDS,
|
|
7308
|
+
LLM_MODEL_IDS,
|
|
7309
|
+
LLM_TEXT_MODEL_IDS,
|
|
7217
7310
|
LlmJsonCallError,
|
|
7311
|
+
OPENAI_MODEL_IDS,
|
|
7218
7312
|
appendMarkdownSourcesSection,
|
|
7219
7313
|
applyPatch,
|
|
7220
7314
|
configureGemini,
|
|
@@ -7249,8 +7343,15 @@ export {
|
|
|
7249
7343
|
generateText,
|
|
7250
7344
|
getChatGptAuthProfile,
|
|
7251
7345
|
getCurrentToolCallContext,
|
|
7346
|
+
isChatGptModelId,
|
|
7252
7347
|
isFireworksModelId,
|
|
7348
|
+
isGeminiImageModelId,
|
|
7253
7349
|
isGeminiModelId,
|
|
7350
|
+
isGeminiTextModelId,
|
|
7351
|
+
isLlmImageModelId,
|
|
7352
|
+
isLlmModelId,
|
|
7353
|
+
isLlmTextModelId,
|
|
7354
|
+
isOpenAiModelId,
|
|
7254
7355
|
loadEnvFromFile,
|
|
7255
7356
|
loadLocalEnv,
|
|
7256
7357
|
parseJsonFromLlmText,
|