@ljoukov/llm 0.1.3 → 2.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/dist/index.d.cts CHANGED
@@ -29,7 +29,7 @@ type LlmToolCallContext = {
29
29
  };
30
30
  declare function getCurrentToolCallContext(): LlmToolCallContext | null;
31
31
  type JsonSchema = Record<string, unknown>;
32
- type LlmRole = "user" | "model" | "system" | "tool";
32
+ type LlmRole = "user" | "assistant" | "system" | "developer" | "tool";
33
33
  type LlmInlineDataPart = {
34
34
  type: "inlineData";
35
35
  data: string;
@@ -93,11 +93,45 @@ type LlmTextStream = {
93
93
  readonly result: Promise<LlmTextResult>;
94
94
  readonly abort: () => void;
95
95
  };
96
+ type DeepPartial<T> = T extends ReadonlyArray<infer Item> ? ReadonlyArray<DeepPartial<Item>> : T extends Array<infer Item> ? Array<DeepPartial<Item>> : T extends object ? {
97
+ [K in keyof T]?: DeepPartial<T[K]>;
98
+ } : T;
99
+ type LlmJsonPartialEvent<T> = {
100
+ readonly type: "json";
101
+ readonly stage: "partial";
102
+ readonly value: DeepPartial<T>;
103
+ };
104
+ type LlmJsonFinalEvent<T> = {
105
+ readonly type: "json";
106
+ readonly stage: "final";
107
+ readonly value: T;
108
+ };
109
+ type LlmJsonStreamEvent<T> = LlmStreamEvent | LlmJsonPartialEvent<T> | LlmJsonFinalEvent<T>;
110
+ type LlmJsonStream<T> = {
111
+ readonly events: AsyncIterable<LlmJsonStreamEvent<T>>;
112
+ readonly result: Promise<{
113
+ readonly value: T;
114
+ readonly rawText: string;
115
+ readonly result: LlmTextResult;
116
+ }>;
117
+ readonly abort: () => void;
118
+ };
119
+ type LlmInputMessage = {
120
+ readonly role: "user" | "assistant" | "system" | "developer";
121
+ readonly content: string | readonly LlmContentPart[];
122
+ };
96
123
  type LlmInput = {
97
- readonly prompt: string;
98
- readonly systemPrompt?: string;
99
- } | {
100
- readonly contents: readonly LlmContent[];
124
+ /**
125
+ * OpenAI-style input:
126
+ * - a plain string becomes one user message
127
+ * - message arrays allow multi-turn + role-specific content
128
+ */
129
+ readonly input: string | readonly LlmInputMessage[];
130
+ /**
131
+ * OpenAI-style top-level instructions.
132
+ * Applied as a system message before input.
133
+ */
134
+ readonly instructions?: string;
101
135
  };
102
136
  type LlmBaseRequest = {
103
137
  readonly model: string;
@@ -117,6 +151,18 @@ type LlmJsonRequest<T> = LlmInput & LlmBaseRequest & {
117
151
  readonly openAiSchemaName?: string;
118
152
  readonly maxAttempts?: number;
119
153
  readonly normalizeJson?: (value: unknown) => unknown;
154
+ /**
155
+ * Optional streaming callback. Useful to surface thought deltas while still
156
+ * returning a single validated JSON result.
157
+ */
158
+ readonly onEvent?: (event: LlmStreamEvent) => void;
159
+ };
160
+ type LlmJsonStreamRequest<T> = LlmJsonRequest<T> & {
161
+ /**
162
+ * - "partial" (default): emit best-effort partial JSON snapshots while streaming.
163
+ * - "final": stream thought deltas but only emit the final validated JSON value.
164
+ */
165
+ readonly streamMode?: "partial" | "final";
120
166
  };
121
167
  declare class LlmJsonCallError extends Error {
122
168
  readonly attempts: ReadonlyArray<{
@@ -195,6 +241,7 @@ declare function convertGooglePartsToLlmParts(parts: readonly Part[]): LlmConten
195
241
  declare function parseJsonFromLlmText(rawText: string): unknown;
196
242
  declare function streamText(request: LlmTextRequest): LlmTextStream;
197
243
  declare function generateText(request: LlmTextRequest): Promise<LlmTextResult>;
244
+ declare function streamJson<T>(request: LlmJsonStreamRequest<T>): LlmJsonStream<T>;
198
245
  declare function generateJson<T>(request: LlmJsonRequest<T>): Promise<{
199
246
  readonly value: T;
200
247
  readonly rawText: string;
@@ -223,6 +270,207 @@ declare function loadEnvFromFile(filePath: string, { override }?: {
223
270
  override?: boolean;
224
271
  }): void;
225
272
 
273
+ type AgentPathKind = "file" | "directory" | "symlink" | "other";
274
+ type AgentPathInfo = {
275
+ readonly kind: AgentPathKind;
276
+ readonly mtimeMs: number;
277
+ };
278
+ type AgentDirectoryEntry = {
279
+ readonly name: string;
280
+ readonly path: string;
281
+ readonly kind: AgentPathKind;
282
+ readonly mtimeMs: number;
283
+ };
284
+ interface AgentFilesystem {
285
+ readTextFile(filePath: string): Promise<string>;
286
+ writeTextFile(filePath: string, content: string): Promise<void>;
287
+ deleteFile(filePath: string): Promise<void>;
288
+ ensureDir(directoryPath: string): Promise<void>;
289
+ readDir(directoryPath: string): Promise<readonly AgentDirectoryEntry[]>;
290
+ stat(entryPath: string): Promise<AgentPathInfo>;
291
+ }
292
+ declare class InMemoryAgentFilesystem implements AgentFilesystem {
293
+ #private;
294
+ constructor(initialFiles?: Record<string, string>);
295
+ readTextFile(filePath: string): Promise<string>;
296
+ writeTextFile(filePath: string, content: string): Promise<void>;
297
+ deleteFile(filePath: string): Promise<void>;
298
+ ensureDir(directoryPath: string): Promise<void>;
299
+ readDir(directoryPath: string): Promise<readonly AgentDirectoryEntry[]>;
300
+ stat(entryPath: string): Promise<AgentPathInfo>;
301
+ snapshot(): Record<string, string>;
302
+ }
303
+ declare function createNodeAgentFilesystem(): AgentFilesystem;
304
+ declare function createInMemoryAgentFilesystem(initialFiles?: Record<string, string>): InMemoryAgentFilesystem;
305
+
306
+ type AgentFilesystemToolProfile = "auto" | "model-agnostic" | "codex" | "gemini";
307
+ type AgentFilesystemToolName = "apply_patch" | "read_file" | "write_file" | "replace" | "list_dir" | "list_directory" | "grep_files" | "grep_search" | "glob";
308
+ type AgentFilesystemToolAction = "read" | "write" | "delete" | "move" | "list" | "search";
309
+ type AgentFilesystemToolAccessContext = {
310
+ readonly cwd: string;
311
+ readonly tool: AgentFilesystemToolName;
312
+ readonly action: AgentFilesystemToolAction;
313
+ readonly path: string;
314
+ readonly fromPath?: string;
315
+ readonly toPath?: string;
316
+ readonly pattern?: string;
317
+ readonly include?: string;
318
+ };
319
+ type AgentFilesystemToolAccessHook = (context: AgentFilesystemToolAccessContext) => Promise<void> | void;
320
+ type AgentFilesystemToolsOptions = {
321
+ readonly cwd?: string;
322
+ readonly fs?: AgentFilesystem;
323
+ readonly allowOutsideCwd?: boolean;
324
+ readonly checkAccess?: AgentFilesystemToolAccessHook;
325
+ readonly maxLineLength?: number;
326
+ readonly grepMaxScannedFiles?: number;
327
+ readonly applyPatch?: {
328
+ readonly maxPatchBytes?: number;
329
+ };
330
+ };
331
+ declare const codexReadFileInputSchema: z.ZodObject<{
332
+ file_path: z.ZodString;
333
+ offset: z.ZodOptional<z.ZodNumber>;
334
+ limit: z.ZodOptional<z.ZodNumber>;
335
+ mode: z.ZodOptional<z.ZodEnum<{
336
+ slice: "slice";
337
+ indentation: "indentation";
338
+ }>>;
339
+ indentation: z.ZodOptional<z.ZodObject<{
340
+ anchor_line: z.ZodOptional<z.ZodNumber>;
341
+ max_levels: z.ZodOptional<z.ZodNumber>;
342
+ include_siblings: z.ZodOptional<z.ZodBoolean>;
343
+ include_header: z.ZodOptional<z.ZodBoolean>;
344
+ max_lines: z.ZodOptional<z.ZodNumber>;
345
+ }, z.core.$strip>>;
346
+ }, z.core.$strip>;
347
+ declare const codexListDirInputSchema: z.ZodObject<{
348
+ dir_path: z.ZodString;
349
+ offset: z.ZodOptional<z.ZodNumber>;
350
+ limit: z.ZodOptional<z.ZodNumber>;
351
+ depth: z.ZodOptional<z.ZodNumber>;
352
+ }, z.core.$strip>;
353
+ declare const codexGrepFilesInputSchema: z.ZodObject<{
354
+ pattern: z.ZodString;
355
+ include: z.ZodOptional<z.ZodString>;
356
+ path: z.ZodOptional<z.ZodString>;
357
+ limit: z.ZodOptional<z.ZodNumber>;
358
+ }, z.core.$strip>;
359
+ declare const applyPatchInputSchema: z.ZodObject<{
360
+ input: z.ZodString;
361
+ }, z.core.$strip>;
362
+ declare const geminiReadFileInputSchema: z.ZodObject<{
363
+ file_path: z.ZodString;
364
+ offset: z.ZodOptional<z.ZodNumber>;
365
+ limit: z.ZodOptional<z.ZodNumber>;
366
+ }, z.core.$strip>;
367
+ declare const geminiWriteFileInputSchema: z.ZodObject<{
368
+ file_path: z.ZodString;
369
+ content: z.ZodString;
370
+ }, z.core.$strip>;
371
+ declare const geminiReplaceInputSchema: z.ZodObject<{
372
+ file_path: z.ZodString;
373
+ instruction: z.ZodString;
374
+ old_string: z.ZodString;
375
+ new_string: z.ZodString;
376
+ expected_replacements: z.ZodOptional<z.ZodNumber>;
377
+ }, z.core.$strip>;
378
+ declare const geminiListDirectoryInputSchema: z.ZodObject<{
379
+ dir_path: z.ZodString;
380
+ ignore: z.ZodOptional<z.ZodArray<z.ZodString>>;
381
+ file_filtering_options: z.ZodOptional<z.ZodObject<{
382
+ respect_git_ignore: z.ZodOptional<z.ZodBoolean>;
383
+ respect_gemini_ignore: z.ZodOptional<z.ZodBoolean>;
384
+ }, z.core.$strip>>;
385
+ }, z.core.$strip>;
386
+ declare const geminiGrepSearchInputSchema: z.ZodObject<{
387
+ pattern: z.ZodString;
388
+ dir_path: z.ZodOptional<z.ZodString>;
389
+ include: z.ZodOptional<z.ZodString>;
390
+ exclude_pattern: z.ZodOptional<z.ZodString>;
391
+ names_only: z.ZodOptional<z.ZodBoolean>;
392
+ max_matches_per_file: z.ZodOptional<z.ZodNumber>;
393
+ total_max_matches: z.ZodOptional<z.ZodNumber>;
394
+ }, z.core.$strip>;
395
+ declare const geminiGlobInputSchema: z.ZodObject<{
396
+ pattern: z.ZodString;
397
+ dir_path: z.ZodOptional<z.ZodString>;
398
+ case_sensitive: z.ZodOptional<z.ZodBoolean>;
399
+ respect_git_ignore: z.ZodOptional<z.ZodBoolean>;
400
+ respect_gemini_ignore: z.ZodOptional<z.ZodBoolean>;
401
+ }, z.core.$strip>;
402
+ type CodexReadFileToolInput = z.output<typeof codexReadFileInputSchema>;
403
+ type CodexListDirToolInput = z.output<typeof codexListDirInputSchema>;
404
+ type CodexGrepFilesToolInput = z.output<typeof codexGrepFilesInputSchema>;
405
+ type CodexApplyPatchToolInput = z.output<typeof applyPatchInputSchema>;
406
+ type GeminiReadFileToolInput = z.output<typeof geminiReadFileInputSchema>;
407
+ type GeminiWriteFileToolInput = z.output<typeof geminiWriteFileInputSchema>;
408
+ type GeminiReplaceToolInput = z.output<typeof geminiReplaceInputSchema>;
409
+ type GeminiListDirectoryToolInput = z.output<typeof geminiListDirectoryInputSchema>;
410
+ type GeminiGrepSearchToolInput = z.output<typeof geminiGrepSearchInputSchema>;
411
+ type GeminiGlobToolInput = z.output<typeof geminiGlobInputSchema>;
412
+ declare function resolveFilesystemToolProfile(model: string, profile?: AgentFilesystemToolProfile): Exclude<AgentFilesystemToolProfile, "auto">;
413
+ declare function createFilesystemToolSetForModel(model: string, profileOrOptions?: AgentFilesystemToolProfile | AgentFilesystemToolsOptions, maybeOptions?: AgentFilesystemToolsOptions): LlmToolSet;
414
+ declare function createCodexFilesystemToolSet(options?: AgentFilesystemToolsOptions): LlmToolSet;
415
+ declare function createGeminiFilesystemToolSet(options?: AgentFilesystemToolsOptions): LlmToolSet;
416
+ declare function createModelAgnosticFilesystemToolSet(options?: AgentFilesystemToolsOptions): LlmToolSet;
417
+ declare function createCodexApplyPatchTool(options?: AgentFilesystemToolsOptions): LlmExecutableTool<typeof applyPatchInputSchema, string>;
418
+ declare function createCodexReadFileTool(options?: AgentFilesystemToolsOptions): LlmExecutableTool<typeof codexReadFileInputSchema, string>;
419
+ declare function createListDirTool(options?: AgentFilesystemToolsOptions): LlmExecutableTool<typeof codexListDirInputSchema, string>;
420
+ declare function createGrepFilesTool(options?: AgentFilesystemToolsOptions): LlmExecutableTool<typeof codexGrepFilesInputSchema, string>;
421
+ declare function createReadFileTool(options?: AgentFilesystemToolsOptions): LlmExecutableTool<typeof geminiReadFileInputSchema, string>;
422
+ declare function createWriteFileTool(options?: AgentFilesystemToolsOptions): LlmExecutableTool<typeof geminiWriteFileInputSchema, string>;
423
+ declare function createReplaceTool(options?: AgentFilesystemToolsOptions): LlmExecutableTool<typeof geminiReplaceInputSchema, string>;
424
+ declare function createListDirectoryTool(options?: AgentFilesystemToolsOptions): LlmExecutableTool<typeof geminiListDirectoryInputSchema, string>;
425
+ declare function createGrepSearchTool(options?: AgentFilesystemToolsOptions): LlmExecutableTool<typeof geminiGrepSearchInputSchema, string>;
426
+ declare function createGlobTool(options?: AgentFilesystemToolsOptions): LlmExecutableTool<typeof geminiGlobInputSchema, string>;
427
+
428
+ type AgentFilesystemToolConfig = {
429
+ readonly enabled?: boolean;
430
+ readonly profile?: AgentFilesystemToolProfile;
431
+ readonly options?: AgentFilesystemToolsOptions;
432
+ };
433
+ type AgentFilesystemToolSelection = boolean | AgentFilesystemToolProfile | AgentFilesystemToolConfig;
434
+ type RunAgentLoopRequest = Omit<LlmToolLoopRequest, "tools"> & {
435
+ readonly tools?: LlmToolSet;
436
+ readonly filesystemTool?: AgentFilesystemToolSelection;
437
+ readonly filesystem_tool?: AgentFilesystemToolSelection;
438
+ };
439
+ declare function runAgentLoop(request: RunAgentLoopRequest): Promise<LlmToolLoopResult>;
440
+
441
+ type ApplyPatchAccessContext = {
442
+ readonly cwd: string;
443
+ readonly kind: "add" | "delete" | "update" | "move";
444
+ readonly path: string;
445
+ readonly fromPath?: string;
446
+ readonly toPath?: string;
447
+ };
448
+ type ApplyPatchAccessHook = (context: ApplyPatchAccessContext) => Promise<void> | void;
449
+ type ApplyPatchRequest = {
450
+ readonly patch: string;
451
+ readonly cwd?: string;
452
+ readonly fs?: AgentFilesystem;
453
+ readonly allowOutsideCwd?: boolean;
454
+ readonly checkAccess?: ApplyPatchAccessHook;
455
+ readonly maxPatchBytes?: number;
456
+ };
457
+ type ApplyPatchResult = {
458
+ readonly success: true;
459
+ readonly summary: string;
460
+ readonly added: readonly string[];
461
+ readonly modified: readonly string[];
462
+ readonly deleted: readonly string[];
463
+ };
464
+ type CreateApplyPatchToolOptions = Omit<ApplyPatchRequest, "patch"> & {
465
+ readonly description?: string;
466
+ };
467
+ declare const applyPatchToolInputSchema: z.ZodObject<{
468
+ input: z.ZodString;
469
+ }, z.core.$strip>;
470
+ type ApplyPatchToolInput = z.output<typeof applyPatchToolInputSchema>;
471
+ declare function createApplyPatchTool(options?: CreateApplyPatchToolOptions): LlmExecutableTool<typeof applyPatchToolInputSchema, ApplyPatchResult>;
472
+ declare function applyPatch(request: ApplyPatchRequest): Promise<ApplyPatchResult>;
473
+
226
474
  type ChatGptAuthProfile = {
227
475
  readonly access: string;
228
476
  readonly refresh: string;
@@ -249,4 +497,4 @@ type GeminiConfiguration = {
249
497
  };
250
498
  declare function configureGemini(options?: GeminiConfiguration): void;
251
499
 
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 };
500
+ 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, type ChatGptAuthProfile, type CodexApplyPatchToolInput, type CodexGrepFilesToolInput, type CodexListDirToolInput, type CodexReadFileToolInput, type CreateApplyPatchToolOptions, type GeminiGlobToolInput, type GeminiGrepSearchToolInput, type GeminiListDirectoryToolInput, type GeminiModelId, type GeminiReadFileToolInput, type GeminiReplaceToolInput, type GeminiWriteFileToolInput, InMemoryAgentFilesystem, type JsonSchema, type LlmBaseRequest, type LlmBlockedEvent, type LlmContent, type LlmContentPart, type LlmExecutableTool, 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, createGlobTool, createGrepFilesTool, createGrepSearchTool, createInMemoryAgentFilesystem, createListDirTool, createListDirectoryTool, createModelAgnosticFilesystemToolSet, createNodeAgentFilesystem, createReadFileTool, createReplaceTool, createWriteFileTool, encodeChatGptAuthJson, encodeChatGptAuthJsonB64, estimateCallCostUsd, exchangeChatGptOauthCode, generateImageInBatches, generateImages, generateJson, generateText, getChatGptAuthProfile, getCurrentToolCallContext, isGeminiModelId, loadEnvFromFile, loadLocalEnv, parseJsonFromLlmText, refreshChatGptOauthToken, resolveFilesystemToolProfile, runAgentLoop, runToolLoop, sanitisePartForLogging, streamJson, streamText, stripCodexCitationMarkers, toGeminiJsonSchema, tool };
package/dist/index.d.ts CHANGED
@@ -29,7 +29,7 @@ type LlmToolCallContext = {
29
29
  };
30
30
  declare function getCurrentToolCallContext(): LlmToolCallContext | null;
31
31
  type JsonSchema = Record<string, unknown>;
32
- type LlmRole = "user" | "model" | "system" | "tool";
32
+ type LlmRole = "user" | "assistant" | "system" | "developer" | "tool";
33
33
  type LlmInlineDataPart = {
34
34
  type: "inlineData";
35
35
  data: string;
@@ -93,11 +93,45 @@ type LlmTextStream = {
93
93
  readonly result: Promise<LlmTextResult>;
94
94
  readonly abort: () => void;
95
95
  };
96
+ type DeepPartial<T> = T extends ReadonlyArray<infer Item> ? ReadonlyArray<DeepPartial<Item>> : T extends Array<infer Item> ? Array<DeepPartial<Item>> : T extends object ? {
97
+ [K in keyof T]?: DeepPartial<T[K]>;
98
+ } : T;
99
+ type LlmJsonPartialEvent<T> = {
100
+ readonly type: "json";
101
+ readonly stage: "partial";
102
+ readonly value: DeepPartial<T>;
103
+ };
104
+ type LlmJsonFinalEvent<T> = {
105
+ readonly type: "json";
106
+ readonly stage: "final";
107
+ readonly value: T;
108
+ };
109
+ type LlmJsonStreamEvent<T> = LlmStreamEvent | LlmJsonPartialEvent<T> | LlmJsonFinalEvent<T>;
110
+ type LlmJsonStream<T> = {
111
+ readonly events: AsyncIterable<LlmJsonStreamEvent<T>>;
112
+ readonly result: Promise<{
113
+ readonly value: T;
114
+ readonly rawText: string;
115
+ readonly result: LlmTextResult;
116
+ }>;
117
+ readonly abort: () => void;
118
+ };
119
+ type LlmInputMessage = {
120
+ readonly role: "user" | "assistant" | "system" | "developer";
121
+ readonly content: string | readonly LlmContentPart[];
122
+ };
96
123
  type LlmInput = {
97
- readonly prompt: string;
98
- readonly systemPrompt?: string;
99
- } | {
100
- readonly contents: readonly LlmContent[];
124
+ /**
125
+ * OpenAI-style input:
126
+ * - a plain string becomes one user message
127
+ * - message arrays allow multi-turn + role-specific content
128
+ */
129
+ readonly input: string | readonly LlmInputMessage[];
130
+ /**
131
+ * OpenAI-style top-level instructions.
132
+ * Applied as a system message before input.
133
+ */
134
+ readonly instructions?: string;
101
135
  };
102
136
  type LlmBaseRequest = {
103
137
  readonly model: string;
@@ -117,6 +151,18 @@ type LlmJsonRequest<T> = LlmInput & LlmBaseRequest & {
117
151
  readonly openAiSchemaName?: string;
118
152
  readonly maxAttempts?: number;
119
153
  readonly normalizeJson?: (value: unknown) => unknown;
154
+ /**
155
+ * Optional streaming callback. Useful to surface thought deltas while still
156
+ * returning a single validated JSON result.
157
+ */
158
+ readonly onEvent?: (event: LlmStreamEvent) => void;
159
+ };
160
+ type LlmJsonStreamRequest<T> = LlmJsonRequest<T> & {
161
+ /**
162
+ * - "partial" (default): emit best-effort partial JSON snapshots while streaming.
163
+ * - "final": stream thought deltas but only emit the final validated JSON value.
164
+ */
165
+ readonly streamMode?: "partial" | "final";
120
166
  };
121
167
  declare class LlmJsonCallError extends Error {
122
168
  readonly attempts: ReadonlyArray<{
@@ -195,6 +241,7 @@ declare function convertGooglePartsToLlmParts(parts: readonly Part[]): LlmConten
195
241
  declare function parseJsonFromLlmText(rawText: string): unknown;
196
242
  declare function streamText(request: LlmTextRequest): LlmTextStream;
197
243
  declare function generateText(request: LlmTextRequest): Promise<LlmTextResult>;
244
+ declare function streamJson<T>(request: LlmJsonStreamRequest<T>): LlmJsonStream<T>;
198
245
  declare function generateJson<T>(request: LlmJsonRequest<T>): Promise<{
199
246
  readonly value: T;
200
247
  readonly rawText: string;
@@ -223,6 +270,207 @@ declare function loadEnvFromFile(filePath: string, { override }?: {
223
270
  override?: boolean;
224
271
  }): void;
225
272
 
273
+ type AgentPathKind = "file" | "directory" | "symlink" | "other";
274
+ type AgentPathInfo = {
275
+ readonly kind: AgentPathKind;
276
+ readonly mtimeMs: number;
277
+ };
278
+ type AgentDirectoryEntry = {
279
+ readonly name: string;
280
+ readonly path: string;
281
+ readonly kind: AgentPathKind;
282
+ readonly mtimeMs: number;
283
+ };
284
+ interface AgentFilesystem {
285
+ readTextFile(filePath: string): Promise<string>;
286
+ writeTextFile(filePath: string, content: string): Promise<void>;
287
+ deleteFile(filePath: string): Promise<void>;
288
+ ensureDir(directoryPath: string): Promise<void>;
289
+ readDir(directoryPath: string): Promise<readonly AgentDirectoryEntry[]>;
290
+ stat(entryPath: string): Promise<AgentPathInfo>;
291
+ }
292
+ declare class InMemoryAgentFilesystem implements AgentFilesystem {
293
+ #private;
294
+ constructor(initialFiles?: Record<string, string>);
295
+ readTextFile(filePath: string): Promise<string>;
296
+ writeTextFile(filePath: string, content: string): Promise<void>;
297
+ deleteFile(filePath: string): Promise<void>;
298
+ ensureDir(directoryPath: string): Promise<void>;
299
+ readDir(directoryPath: string): Promise<readonly AgentDirectoryEntry[]>;
300
+ stat(entryPath: string): Promise<AgentPathInfo>;
301
+ snapshot(): Record<string, string>;
302
+ }
303
+ declare function createNodeAgentFilesystem(): AgentFilesystem;
304
+ declare function createInMemoryAgentFilesystem(initialFiles?: Record<string, string>): InMemoryAgentFilesystem;
305
+
306
+ type AgentFilesystemToolProfile = "auto" | "model-agnostic" | "codex" | "gemini";
307
+ type AgentFilesystemToolName = "apply_patch" | "read_file" | "write_file" | "replace" | "list_dir" | "list_directory" | "grep_files" | "grep_search" | "glob";
308
+ type AgentFilesystemToolAction = "read" | "write" | "delete" | "move" | "list" | "search";
309
+ type AgentFilesystemToolAccessContext = {
310
+ readonly cwd: string;
311
+ readonly tool: AgentFilesystemToolName;
312
+ readonly action: AgentFilesystemToolAction;
313
+ readonly path: string;
314
+ readonly fromPath?: string;
315
+ readonly toPath?: string;
316
+ readonly pattern?: string;
317
+ readonly include?: string;
318
+ };
319
+ type AgentFilesystemToolAccessHook = (context: AgentFilesystemToolAccessContext) => Promise<void> | void;
320
+ type AgentFilesystemToolsOptions = {
321
+ readonly cwd?: string;
322
+ readonly fs?: AgentFilesystem;
323
+ readonly allowOutsideCwd?: boolean;
324
+ readonly checkAccess?: AgentFilesystemToolAccessHook;
325
+ readonly maxLineLength?: number;
326
+ readonly grepMaxScannedFiles?: number;
327
+ readonly applyPatch?: {
328
+ readonly maxPatchBytes?: number;
329
+ };
330
+ };
331
+ declare const codexReadFileInputSchema: z.ZodObject<{
332
+ file_path: z.ZodString;
333
+ offset: z.ZodOptional<z.ZodNumber>;
334
+ limit: z.ZodOptional<z.ZodNumber>;
335
+ mode: z.ZodOptional<z.ZodEnum<{
336
+ slice: "slice";
337
+ indentation: "indentation";
338
+ }>>;
339
+ indentation: z.ZodOptional<z.ZodObject<{
340
+ anchor_line: z.ZodOptional<z.ZodNumber>;
341
+ max_levels: z.ZodOptional<z.ZodNumber>;
342
+ include_siblings: z.ZodOptional<z.ZodBoolean>;
343
+ include_header: z.ZodOptional<z.ZodBoolean>;
344
+ max_lines: z.ZodOptional<z.ZodNumber>;
345
+ }, z.core.$strip>>;
346
+ }, z.core.$strip>;
347
+ declare const codexListDirInputSchema: z.ZodObject<{
348
+ dir_path: z.ZodString;
349
+ offset: z.ZodOptional<z.ZodNumber>;
350
+ limit: z.ZodOptional<z.ZodNumber>;
351
+ depth: z.ZodOptional<z.ZodNumber>;
352
+ }, z.core.$strip>;
353
+ declare const codexGrepFilesInputSchema: z.ZodObject<{
354
+ pattern: z.ZodString;
355
+ include: z.ZodOptional<z.ZodString>;
356
+ path: z.ZodOptional<z.ZodString>;
357
+ limit: z.ZodOptional<z.ZodNumber>;
358
+ }, z.core.$strip>;
359
+ declare const applyPatchInputSchema: z.ZodObject<{
360
+ input: z.ZodString;
361
+ }, z.core.$strip>;
362
+ declare const geminiReadFileInputSchema: z.ZodObject<{
363
+ file_path: z.ZodString;
364
+ offset: z.ZodOptional<z.ZodNumber>;
365
+ limit: z.ZodOptional<z.ZodNumber>;
366
+ }, z.core.$strip>;
367
+ declare const geminiWriteFileInputSchema: z.ZodObject<{
368
+ file_path: z.ZodString;
369
+ content: z.ZodString;
370
+ }, z.core.$strip>;
371
+ declare const geminiReplaceInputSchema: z.ZodObject<{
372
+ file_path: z.ZodString;
373
+ instruction: z.ZodString;
374
+ old_string: z.ZodString;
375
+ new_string: z.ZodString;
376
+ expected_replacements: z.ZodOptional<z.ZodNumber>;
377
+ }, z.core.$strip>;
378
+ declare const geminiListDirectoryInputSchema: z.ZodObject<{
379
+ dir_path: z.ZodString;
380
+ ignore: z.ZodOptional<z.ZodArray<z.ZodString>>;
381
+ file_filtering_options: z.ZodOptional<z.ZodObject<{
382
+ respect_git_ignore: z.ZodOptional<z.ZodBoolean>;
383
+ respect_gemini_ignore: z.ZodOptional<z.ZodBoolean>;
384
+ }, z.core.$strip>>;
385
+ }, z.core.$strip>;
386
+ declare const geminiGrepSearchInputSchema: z.ZodObject<{
387
+ pattern: z.ZodString;
388
+ dir_path: z.ZodOptional<z.ZodString>;
389
+ include: z.ZodOptional<z.ZodString>;
390
+ exclude_pattern: z.ZodOptional<z.ZodString>;
391
+ names_only: z.ZodOptional<z.ZodBoolean>;
392
+ max_matches_per_file: z.ZodOptional<z.ZodNumber>;
393
+ total_max_matches: z.ZodOptional<z.ZodNumber>;
394
+ }, z.core.$strip>;
395
+ declare const geminiGlobInputSchema: z.ZodObject<{
396
+ pattern: z.ZodString;
397
+ dir_path: z.ZodOptional<z.ZodString>;
398
+ case_sensitive: z.ZodOptional<z.ZodBoolean>;
399
+ respect_git_ignore: z.ZodOptional<z.ZodBoolean>;
400
+ respect_gemini_ignore: z.ZodOptional<z.ZodBoolean>;
401
+ }, z.core.$strip>;
402
+ type CodexReadFileToolInput = z.output<typeof codexReadFileInputSchema>;
403
+ type CodexListDirToolInput = z.output<typeof codexListDirInputSchema>;
404
+ type CodexGrepFilesToolInput = z.output<typeof codexGrepFilesInputSchema>;
405
+ type CodexApplyPatchToolInput = z.output<typeof applyPatchInputSchema>;
406
+ type GeminiReadFileToolInput = z.output<typeof geminiReadFileInputSchema>;
407
+ type GeminiWriteFileToolInput = z.output<typeof geminiWriteFileInputSchema>;
408
+ type GeminiReplaceToolInput = z.output<typeof geminiReplaceInputSchema>;
409
+ type GeminiListDirectoryToolInput = z.output<typeof geminiListDirectoryInputSchema>;
410
+ type GeminiGrepSearchToolInput = z.output<typeof geminiGrepSearchInputSchema>;
411
+ type GeminiGlobToolInput = z.output<typeof geminiGlobInputSchema>;
412
+ declare function resolveFilesystemToolProfile(model: string, profile?: AgentFilesystemToolProfile): Exclude<AgentFilesystemToolProfile, "auto">;
413
+ declare function createFilesystemToolSetForModel(model: string, profileOrOptions?: AgentFilesystemToolProfile | AgentFilesystemToolsOptions, maybeOptions?: AgentFilesystemToolsOptions): LlmToolSet;
414
+ declare function createCodexFilesystemToolSet(options?: AgentFilesystemToolsOptions): LlmToolSet;
415
+ declare function createGeminiFilesystemToolSet(options?: AgentFilesystemToolsOptions): LlmToolSet;
416
+ declare function createModelAgnosticFilesystemToolSet(options?: AgentFilesystemToolsOptions): LlmToolSet;
417
+ declare function createCodexApplyPatchTool(options?: AgentFilesystemToolsOptions): LlmExecutableTool<typeof applyPatchInputSchema, string>;
418
+ declare function createCodexReadFileTool(options?: AgentFilesystemToolsOptions): LlmExecutableTool<typeof codexReadFileInputSchema, string>;
419
+ declare function createListDirTool(options?: AgentFilesystemToolsOptions): LlmExecutableTool<typeof codexListDirInputSchema, string>;
420
+ declare function createGrepFilesTool(options?: AgentFilesystemToolsOptions): LlmExecutableTool<typeof codexGrepFilesInputSchema, string>;
421
+ declare function createReadFileTool(options?: AgentFilesystemToolsOptions): LlmExecutableTool<typeof geminiReadFileInputSchema, string>;
422
+ declare function createWriteFileTool(options?: AgentFilesystemToolsOptions): LlmExecutableTool<typeof geminiWriteFileInputSchema, string>;
423
+ declare function createReplaceTool(options?: AgentFilesystemToolsOptions): LlmExecutableTool<typeof geminiReplaceInputSchema, string>;
424
+ declare function createListDirectoryTool(options?: AgentFilesystemToolsOptions): LlmExecutableTool<typeof geminiListDirectoryInputSchema, string>;
425
+ declare function createGrepSearchTool(options?: AgentFilesystemToolsOptions): LlmExecutableTool<typeof geminiGrepSearchInputSchema, string>;
426
+ declare function createGlobTool(options?: AgentFilesystemToolsOptions): LlmExecutableTool<typeof geminiGlobInputSchema, string>;
427
+
428
+ type AgentFilesystemToolConfig = {
429
+ readonly enabled?: boolean;
430
+ readonly profile?: AgentFilesystemToolProfile;
431
+ readonly options?: AgentFilesystemToolsOptions;
432
+ };
433
+ type AgentFilesystemToolSelection = boolean | AgentFilesystemToolProfile | AgentFilesystemToolConfig;
434
+ type RunAgentLoopRequest = Omit<LlmToolLoopRequest, "tools"> & {
435
+ readonly tools?: LlmToolSet;
436
+ readonly filesystemTool?: AgentFilesystemToolSelection;
437
+ readonly filesystem_tool?: AgentFilesystemToolSelection;
438
+ };
439
+ declare function runAgentLoop(request: RunAgentLoopRequest): Promise<LlmToolLoopResult>;
440
+
441
+ type ApplyPatchAccessContext = {
442
+ readonly cwd: string;
443
+ readonly kind: "add" | "delete" | "update" | "move";
444
+ readonly path: string;
445
+ readonly fromPath?: string;
446
+ readonly toPath?: string;
447
+ };
448
+ type ApplyPatchAccessHook = (context: ApplyPatchAccessContext) => Promise<void> | void;
449
+ type ApplyPatchRequest = {
450
+ readonly patch: string;
451
+ readonly cwd?: string;
452
+ readonly fs?: AgentFilesystem;
453
+ readonly allowOutsideCwd?: boolean;
454
+ readonly checkAccess?: ApplyPatchAccessHook;
455
+ readonly maxPatchBytes?: number;
456
+ };
457
+ type ApplyPatchResult = {
458
+ readonly success: true;
459
+ readonly summary: string;
460
+ readonly added: readonly string[];
461
+ readonly modified: readonly string[];
462
+ readonly deleted: readonly string[];
463
+ };
464
+ type CreateApplyPatchToolOptions = Omit<ApplyPatchRequest, "patch"> & {
465
+ readonly description?: string;
466
+ };
467
+ declare const applyPatchToolInputSchema: z.ZodObject<{
468
+ input: z.ZodString;
469
+ }, z.core.$strip>;
470
+ type ApplyPatchToolInput = z.output<typeof applyPatchToolInputSchema>;
471
+ declare function createApplyPatchTool(options?: CreateApplyPatchToolOptions): LlmExecutableTool<typeof applyPatchToolInputSchema, ApplyPatchResult>;
472
+ declare function applyPatch(request: ApplyPatchRequest): Promise<ApplyPatchResult>;
473
+
226
474
  type ChatGptAuthProfile = {
227
475
  readonly access: string;
228
476
  readonly refresh: string;
@@ -249,4 +497,4 @@ type GeminiConfiguration = {
249
497
  };
250
498
  declare function configureGemini(options?: GeminiConfiguration): void;
251
499
 
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 };
500
+ 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, type ChatGptAuthProfile, type CodexApplyPatchToolInput, type CodexGrepFilesToolInput, type CodexListDirToolInput, type CodexReadFileToolInput, type CreateApplyPatchToolOptions, type GeminiGlobToolInput, type GeminiGrepSearchToolInput, type GeminiListDirectoryToolInput, type GeminiModelId, type GeminiReadFileToolInput, type GeminiReplaceToolInput, type GeminiWriteFileToolInput, InMemoryAgentFilesystem, type JsonSchema, type LlmBaseRequest, type LlmBlockedEvent, type LlmContent, type LlmContentPart, type LlmExecutableTool, 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, createGlobTool, createGrepFilesTool, createGrepSearchTool, createInMemoryAgentFilesystem, createListDirTool, createListDirectoryTool, createModelAgnosticFilesystemToolSet, createNodeAgentFilesystem, createReadFileTool, createReplaceTool, createWriteFileTool, encodeChatGptAuthJson, encodeChatGptAuthJsonB64, estimateCallCostUsd, exchangeChatGptOauthCode, generateImageInBatches, generateImages, generateJson, generateText, getChatGptAuthProfile, getCurrentToolCallContext, isGeminiModelId, loadEnvFromFile, loadLocalEnv, parseJsonFromLlmText, refreshChatGptOauthToken, resolveFilesystemToolProfile, runAgentLoop, runToolLoop, sanitisePartForLogging, streamJson, streamText, stripCodexCitationMarkers, toGeminiJsonSchema, tool };