@codelia/core 0.1.75 → 0.1.77

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 DELETED
@@ -1,875 +0,0 @@
1
- import { JSONSchema7 } from 'json-schema';
2
- import { ZodSchema } from 'zod';
3
- import { Logger } from 'openai/client';
4
- import { AgentEvent, SessionStateSummary as SessionStateSummary$1, ModelReasoningLevel } from '@codelia/shared-types';
5
- export { AgentEvent, FinalResponseEvent, ReasoningEvent, StepCompleteEvent, StepStartEvent, TextEvent, ToolCallEvent, ToolResultEvent } from '@codelia/shared-types';
6
- import Anthropic from '@anthropic-ai/sdk';
7
- import { MessageCreateParamsNonStreaming, OutputConfig } from '@anthropic-ai/sdk/resources/messages/messages';
8
- import OpenAI, { ClientOptions } from 'openai';
9
- import { ResponsesClientEvent, ResponseCreateParamsBase, ResponseTextConfig } from 'openai/resources/responses/responses';
10
- import { ResponsesWS } from 'openai/resources/responses/ws';
11
- import { ReasoningEffort } from 'openai/resources/shared';
12
-
13
- /**
14
- * Message Content Parts
15
- */
16
- type TextPart = {
17
- type: "text";
18
- text: string;
19
- };
20
- type ImagePart = {
21
- type: "image_url";
22
- image_url: {
23
- url: string;
24
- detail?: "auto" | "low" | "high";
25
- media_type?: "image/png" | "image/jpeg" | "image/webp" | "image/gif";
26
- };
27
- };
28
- type DocumentPart = {
29
- type: "document";
30
- source: {
31
- data: string;
32
- media_type: "application/pdf";
33
- };
34
- };
35
- type OtherPart = {
36
- type: "other";
37
- provider: string;
38
- kind: string;
39
- payload: unknown;
40
- };
41
- type ContentPart = TextPart | ImagePart | DocumentPart | OtherPart;
42
-
43
- /**
44
- * Tool Call
45
- */
46
- type ToolCall = {
47
- id: string;
48
- type: "function";
49
- function: {
50
- name: string;
51
- arguments: string;
52
- };
53
- provider_meta?: unknown;
54
- };
55
- /**
56
- * Tool Definition
57
- */
58
- type FunctionToolDefinition = {
59
- type?: "function";
60
- name: string;
61
- description: string;
62
- parameters: JSONSchema7;
63
- strict?: boolean;
64
- };
65
- type HostedSearchUserLocation = {
66
- city?: string;
67
- country?: string;
68
- region?: string;
69
- timezone?: string;
70
- };
71
- type HostedSearchToolDefinition = {
72
- type: "hosted_search";
73
- name: string;
74
- provider?: "openai" | "anthropic" | "openrouter" | "google";
75
- search_context_size?: "low" | "medium" | "high";
76
- allowed_domains?: string[];
77
- blocked_domains?: string[];
78
- max_uses?: number;
79
- user_location?: HostedSearchUserLocation;
80
- };
81
- type ToolDefinition = FunctionToolDefinition | HostedSearchToolDefinition;
82
- type ToolChoice = "auto" | "required" | "none" | string;
83
- type JsonValue = string | number | boolean | null | {
84
- [key: string]: JsonValue;
85
- } | JsonValue[];
86
- type ToolResult = {
87
- type: "text";
88
- text: string;
89
- } | {
90
- type: "parts";
91
- parts: ContentPart[];
92
- } | {
93
- type: "json";
94
- value: unknown;
95
- };
96
- type ToolReturn = ToolResult | string | ContentPart[] | JsonValue;
97
-
98
- /**
99
- * Base Message
100
- */
101
- type UserMessage = {
102
- role: "user";
103
- content: string | ContentPart[];
104
- name?: string;
105
- };
106
- type SystemMessage = {
107
- role: "system";
108
- content: string | TextPart[];
109
- name?: string;
110
- cache?: boolean;
111
- };
112
- type AssistantMessage = {
113
- role: "assistant";
114
- content: string | ContentPart[] | null;
115
- name?: string;
116
- tool_calls?: ToolCall[];
117
- refusal?: string | null;
118
- };
119
- type ToolOutputRef = {
120
- id: string;
121
- byte_size?: number;
122
- line_count?: number;
123
- };
124
- type ReasoningMessage<T = unknown> = {
125
- role: "reasoning";
126
- content: string | null;
127
- raw_item?: T | null;
128
- };
129
- type ToolMessage = {
130
- role: "tool";
131
- tool_call_id: string;
132
- tool_name: string;
133
- content: string | ContentPart[];
134
- is_error?: boolean;
135
- output_ref?: ToolOutputRef;
136
- trimmed?: boolean;
137
- };
138
- type BaseMessage = UserMessage | SystemMessage | AssistantMessage | ToolMessage | ReasoningMessage;
139
-
140
- type ChatInvokeUsage = {
141
- model: string;
142
- provider_model?: string | null;
143
- input_tokens: number;
144
- input_cached_tokens?: number | null;
145
- input_cache_creation_tokens?: number | null;
146
- input_image_tokens?: number | null;
147
- output_tokens: number;
148
- total_tokens: number;
149
- };
150
- type ChatInvokeCompletion = {
151
- messages: BaseMessage[];
152
- usage?: ChatInvokeUsage | null;
153
- stop_reason?: string | null;
154
- provider_meta?: unknown;
155
- };
156
-
157
- type ToolOutputCacheRecord = {
158
- tool_call_id: string;
159
- tool_name: string;
160
- content: string;
161
- is_error?: boolean;
162
- };
163
- type ToolOutputCacheReadOptions = {
164
- offset?: number;
165
- limit?: number;
166
- };
167
- type ToolOutputCacheReadLineOptions = {
168
- line_number: number;
169
- char_offset?: number;
170
- char_limit?: number;
171
- };
172
- type ToolOutputCacheSearchOptions = {
173
- pattern: string;
174
- regex?: boolean;
175
- before?: number;
176
- after?: number;
177
- max_matches?: number;
178
- };
179
- type ToolOutputCacheStore = {
180
- save: (record: ToolOutputCacheRecord) => Promise<ToolOutputRef> | ToolOutputRef;
181
- read?: (refId: string, options?: ToolOutputCacheReadOptions) => Promise<string> | string;
182
- readLine?: (refId: string, options: ToolOutputCacheReadLineOptions) => Promise<string> | string;
183
- grep?: (refId: string, options: ToolOutputCacheSearchOptions) => Promise<string> | string;
184
- };
185
-
186
- type ModelCost = {
187
- input?: number;
188
- output?: number;
189
- reasoning?: number;
190
- cacheRead?: number;
191
- cacheWrite?: number;
192
- inputAudio?: number;
193
- outputAudio?: number;
194
- };
195
- type ModelLimits = {
196
- contextWindow?: number;
197
- inputTokens?: number;
198
- outputTokens?: number;
199
- };
200
- type ModelCapabilities = {
201
- supportsFast?: boolean;
202
- };
203
- type ModelEntry = {
204
- provider: string;
205
- modelId: string;
206
- releaseDate?: string;
207
- lastUpdated?: string;
208
- cost?: ModelCost;
209
- limits?: ModelLimits;
210
- capabilities?: ModelCapabilities;
211
- };
212
- type ModelMetadataIndex = {
213
- models: Record<string, Record<string, ModelEntry>>;
214
- };
215
- interface ModelMetadataService {
216
- getModelEntry(provider: string, modelId: string): Promise<ModelEntry | null>;
217
- getModelEntries(provider: string): Promise<ModelEntry[] | null>;
218
- getAllModelEntries(): Promise<Record<string, Record<string, ModelEntry>>>;
219
- }
220
-
221
- type AgentServices = {
222
- modelMetadata?: ModelMetadataService;
223
- toolOutputCacheStore?: ToolOutputCacheStore | null;
224
- monotonicNowMs?: () => number;
225
- };
226
-
227
- type ProviderName = "openai" | "anthropic" | "openrouter" | "google" | "zai";
228
- type ChatInvokeInput = {
229
- messages: BaseMessage[];
230
- model?: string;
231
- tools?: ToolDefinition[] | null;
232
- toolChoice?: ToolChoice | null;
233
- signal?: AbortSignal;
234
- };
235
- type ChatInvokeContext = {
236
- sessionKey?: string;
237
- };
238
- interface BaseChatModel<P extends ProviderName = ProviderName, O = unknown> {
239
- readonly provider: P;
240
- readonly model: string;
241
- ainvoke(input: ChatInvokeInput & {
242
- options?: O;
243
- }, context?: ChatInvokeContext): Promise<ChatInvokeCompletion>;
244
- onHistoryCompacted?(context?: ChatInvokeContext): void | Promise<void>;
245
- }
246
-
247
- type ModelSpec = {
248
- id: string;
249
- provider: ProviderName;
250
- providerModelId?: string;
251
- aliases?: string[];
252
- contextWindow?: number;
253
- maxInputTokens?: number;
254
- maxOutputTokens?: number;
255
- supportsTools?: boolean;
256
- supportsVision?: boolean;
257
- supportsReasoning?: boolean;
258
- supportsFast?: boolean;
259
- supportsJsonSchema?: boolean;
260
- };
261
- type ModelRegistry = {
262
- modelsById: Record<string, ModelSpec>;
263
- aliasesByProvider: Record<ProviderName, Record<string, string>>;
264
- };
265
- declare function createModelRegistry(specs: ModelSpec[]): ModelRegistry;
266
- declare function registerModels(registry: ModelRegistry, specs: ModelSpec[]): void;
267
- declare function resolveModel(registry: ModelRegistry, idOrAlias: string, provider?: ProviderName): ModelSpec | undefined;
268
- declare function listModels(registry: ModelRegistry, provider?: ProviderName): ModelSpec[];
269
- declare function isUsableModelSpec(spec: ModelSpec | undefined): boolean;
270
- declare function resolveProviderModelId(registry: ModelRegistry, idOrAlias: string, provider?: ProviderName): string | undefined;
271
- declare function supportsFastMode(registry: ModelRegistry, idOrAlias: string, provider?: ProviderName): boolean;
272
- declare function applyModelMetadata(registry: ModelRegistry, index: ModelMetadataIndex): ModelRegistry;
273
-
274
- type CompactionConfig = {
275
- enabled?: boolean;
276
- auto?: boolean;
277
- thresholdRatio?: number;
278
- model?: string | null;
279
- summaryPrompt?: string;
280
- summaryDirectives?: string[];
281
- retainPrompt?: string | null;
282
- retainDirectives?: string[];
283
- retainLastTurns?: number;
284
- };
285
-
286
- type ToolOutputCacheConfig = {
287
- enabled?: boolean;
288
- contextBudgetTokens?: number | null;
289
- totalBudgetTrim?: boolean;
290
- maxMessageBytes?: number;
291
- maxLineLength?: number;
292
- };
293
-
294
- type ToolOutputCacheDependencies = {
295
- modelRegistry: ModelRegistry;
296
- store?: ToolOutputCacheStore | null;
297
- };
298
- type TrimResult = {
299
- messages: BaseMessage[];
300
- trimmed: boolean;
301
- };
302
- declare class ToolOutputCacheService {
303
- private readonly config;
304
- private readonly modelRegistry;
305
- private readonly store?;
306
- constructor(config: ToolOutputCacheConfig, deps: ToolOutputCacheDependencies);
307
- processToolMessage(message: ToolMessage): Promise<ToolMessage>;
308
- trimMessages(llm: BaseChatModel, messages: BaseMessage[]): Promise<TrimResult>;
309
- private persistToolOutput;
310
- private resolveContextBudgetTokens;
311
- }
312
-
313
- type UsageSummary = {
314
- total_calls: number;
315
- total_tokens: number;
316
- total_input_tokens: number;
317
- total_output_tokens: number;
318
- total_cached_input_tokens: number;
319
- total_cache_creation_tokens: number;
320
- total_cost_usd?: number | null;
321
- by_model: Record<string, {
322
- calls: number;
323
- input_tokens: number;
324
- output_tokens: number;
325
- cached_input_tokens: number;
326
- cache_creation_tokens: number;
327
- total_tokens: number;
328
- cost_usd?: number | null;
329
- }>;
330
- };
331
-
332
- type DependencyKey<T> = {
333
- id: string;
334
- create: () => T | Promise<T>;
335
- };
336
- type ToolContext = {
337
- signal?: AbortSignal;
338
- logger?: Logger;
339
- now?: () => Date;
340
- deps: Record<string, unknown>;
341
- resolve: <T>(key: DependencyKey<T>) => Promise<T>;
342
- };
343
-
344
- type DefineToolOptions<TInput, TResult extends ToolReturn = ToolReturn> = {
345
- name: string;
346
- description: string;
347
- input: ZodSchema<TInput>;
348
- execute: (input: TInput, ctx: ToolContext) => Promise<TResult> | TResult;
349
- };
350
- type Tool = {
351
- name: string;
352
- description: string;
353
- definition: ToolDefinition;
354
- executeRaw: (rawArgsJson: string, ctx: ToolContext) => Promise<ToolResult>;
355
- };
356
- type ToolExecution = {
357
- message: ToolMessage;
358
- done?: boolean;
359
- finalMessage?: string;
360
- };
361
-
362
- type ToolPermissionDecision = {
363
- decision: "allow" | "deny";
364
- reason?: string;
365
- stop_turn?: boolean;
366
- };
367
- type ToolPermissionHook = (call: ToolCall, rawArgs: string, ctx: ToolContext) => Promise<ToolPermissionDecision> | ToolPermissionDecision;
368
-
369
- type SessionHeader = {
370
- type: "header";
371
- schema_version: 1;
372
- run_id: string;
373
- session_id?: string;
374
- started_at: string;
375
- client?: {
376
- name: string;
377
- version: string;
378
- };
379
- server?: {
380
- name: string;
381
- version: string;
382
- };
383
- model?: {
384
- provider?: string;
385
- name?: string;
386
- reasoning?: string;
387
- fast?: boolean;
388
- source?: "config" | "session";
389
- };
390
- prompts?: {
391
- system?: string;
392
- };
393
- tools?: {
394
- definitions?: ToolDefinition[];
395
- source?: string;
396
- };
397
- runtime?: {
398
- cwd?: string;
399
- os?: string;
400
- arch?: string;
401
- version?: string;
402
- };
403
- meta?: Record<string, unknown>;
404
- };
405
- type RunStartRecord = {
406
- type: "run.start";
407
- run_id: string;
408
- session_id?: string;
409
- ts: string;
410
- input: {
411
- type: "text";
412
- text: string;
413
- } | {
414
- type: "parts";
415
- parts: Array<{
416
- type: "text";
417
- text: string;
418
- } | {
419
- type: "image_url";
420
- image_url: {
421
- url: string;
422
- detail?: "auto" | "low" | "high";
423
- media_type?: "image/png" | "image/jpeg" | "image/webp" | "image/gif";
424
- };
425
- }>;
426
- };
427
- ui_context?: unknown;
428
- meta?: Record<string, unknown>;
429
- };
430
- type RunContextRecord = {
431
- type: "run.context";
432
- run_id: string;
433
- ts: string;
434
- context_left_percent: number;
435
- meta?: Record<string, unknown>;
436
- };
437
- type AgentEventRecord = {
438
- type: "agent.event";
439
- run_id: string;
440
- ts: string;
441
- seq: number;
442
- event: AgentEvent;
443
- meta?: Record<string, unknown>;
444
- };
445
- type ToolOutputRecord = {
446
- type: "tool.output";
447
- run_id: string;
448
- ts: string;
449
- tool: string;
450
- tool_call_id: string;
451
- result_raw: string;
452
- is_error?: boolean;
453
- output_ref?: ToolOutputRef;
454
- meta?: Record<string, unknown>;
455
- };
456
- type LlmRequestRecord = {
457
- type: "llm.request";
458
- run_id: string;
459
- ts: string;
460
- seq: number;
461
- model?: {
462
- provider?: string;
463
- name?: string;
464
- reasoning?: string;
465
- fast?: boolean;
466
- };
467
- input: {
468
- messages: BaseMessage[];
469
- tools?: ToolDefinition[] | null;
470
- tool_choice?: ToolChoice | null;
471
- model?: string;
472
- session_key?: string;
473
- };
474
- meta?: Record<string, unknown>;
475
- };
476
- type LlmResponseRecord = {
477
- type: "llm.response";
478
- run_id: string;
479
- ts: string;
480
- seq: number;
481
- output: {
482
- messages: BaseMessage[];
483
- usage?: ChatInvokeUsage | null;
484
- stop_reason?: string | null;
485
- provider_meta?: unknown;
486
- };
487
- meta?: Record<string, unknown>;
488
- };
489
- type RunStatusRecord = {
490
- type: "run.status";
491
- run_id: string;
492
- ts: string;
493
- status: "running" | "awaiting_ui" | "completed" | "error" | "cancelled";
494
- message?: string;
495
- meta?: Record<string, unknown>;
496
- };
497
- type RunErrorRecord = {
498
- type: "run.error";
499
- run_id: string;
500
- ts: string;
501
- error: {
502
- name: string;
503
- message: string;
504
- stack?: string;
505
- };
506
- meta?: Record<string, unknown>;
507
- };
508
- type RunEndRecord = {
509
- type: "run.end";
510
- run_id: string;
511
- ts: string;
512
- outcome: "completed" | "cancelled" | "error";
513
- final?: string;
514
- meta?: Record<string, unknown>;
515
- };
516
- type SessionRecord = SessionHeader | RunStartRecord | RunContextRecord | AgentEventRecord | ToolOutputRecord | LlmRequestRecord | LlmResponseRecord | RunStatusRecord | RunErrorRecord | RunEndRecord;
517
- type SessionStore = {
518
- filePath?: string;
519
- append: (record: SessionRecord) => Promise<void> | void;
520
- };
521
- type RunEventStoreInit = {
522
- runId: string;
523
- startedAt: string;
524
- };
525
- type RunEventStoreFactory = {
526
- create: (init: RunEventStoreInit) => SessionStore;
527
- };
528
- type SessionState = {
529
- schema_version: 1;
530
- session_id: string;
531
- updated_at: string;
532
- run_id?: string;
533
- invoke_seq?: number;
534
- messages: BaseMessage[];
535
- meta?: Record<string, unknown>;
536
- };
537
- type SessionStateSummary = SessionStateSummary$1;
538
- type SessionStateStore = {
539
- load: (sessionId: string) => Promise<SessionState | null>;
540
- save: (state: SessionState) => Promise<void>;
541
- list: () => Promise<SessionStateSummary[]>;
542
- };
543
- type AgentSession = {
544
- run_id: string;
545
- session_id?: string;
546
- invoke_seq?: number;
547
- on_error?: (error: unknown, record: SessionRecord) => void;
548
- append: (record: SessionRecord) => void;
549
- };
550
-
551
- type AgentRunOptions = {
552
- session?: AgentSession;
553
- signal?: AbortSignal;
554
- forceCompaction?: boolean;
555
- tools?: Tool[];
556
- toolChoice?: ToolChoice;
557
- };
558
- type AgentOptions = {
559
- llm: BaseChatModel;
560
- tools: Tool[];
561
- hostedTools?: ToolDefinition[];
562
- systemPrompt?: string;
563
- maxIterations?: number;
564
- toolChoice?: ToolChoice;
565
- compaction?: CompactionConfig | null;
566
- toolOutputCache?: ToolOutputCacheConfig | null;
567
- services?: AgentServices;
568
- modelRegistry?: ModelRegistry;
569
- enableUsageTracking?: boolean;
570
- requireDoneTool?: boolean;
571
- llmMaxRetries?: number;
572
- llmRetryBaseDelayMs?: number;
573
- llmRetryMaxDelayMs?: number;
574
- llmRetryableStatusCodes?: number[];
575
- canExecuteTool?: ToolPermissionHook;
576
- };
577
- declare class Agent {
578
- private readonly llm;
579
- private readonly tools;
580
- private readonly hostedTools;
581
- private readonly systemPrompt?;
582
- private readonly maxIterations;
583
- private readonly toolChoice?;
584
- private readonly requireDoneTool;
585
- private readonly compactionService?;
586
- private readonly toolOutputCacheService?;
587
- private readonly services;
588
- private readonly modelRegistry;
589
- private readonly canExecuteTool?;
590
- private readonly monotonicNowMs;
591
- private history;
592
- private usageService;
593
- constructor(options: AgentOptions);
594
- getUsageSummary(): UsageSummary;
595
- getContextLeftPercent(): number | null;
596
- getHistoryMessages(): BaseMessage[];
597
- replaceHistoryMessages(messages: BaseMessage[]): void;
598
- private checkAndCompact;
599
- private trimToolOutputs;
600
- private processToolMessage;
601
- private buildToolContext;
602
- private recordLlmRequest;
603
- private resolveSessionKey;
604
- private buildInvokeContext;
605
- private recordLlmResponse;
606
- run(message: string | ContentPart[], options?: AgentRunOptions): Promise<string>;
607
- runStream(message: string | ContentPart[], options?: AgentRunOptions): AsyncGenerator<AgentEvent>;
608
- private generateFinalResponse;
609
- private executeToolCall;
610
- }
611
-
612
- type StringifyContentMode = "display" | "log";
613
- type StringifyContentOptions = {
614
- mode?: StringifyContentMode;
615
- joiner?: string;
616
- includeOtherPayload?: boolean;
617
- };
618
- declare const stringifyContentParts: (content: ContentPart[], options?: StringifyContentOptions) => string;
619
- declare const stringifyContent: (content: string | ContentPart[] | null | undefined, options?: StringifyContentOptions) => string;
620
-
621
- type StorageLayout = "home" | "xdg";
622
- type StoragePaths = {
623
- root: string;
624
- configDir: string;
625
- configFile: string;
626
- authFile: string;
627
- mcpAuthFile: string;
628
- projectsFile: string;
629
- cacheDir: string;
630
- toolOutputCacheDir: string;
631
- sessionsDir: string;
632
- logsDir: string;
633
- };
634
- type ResolveStorageOptions = {
635
- layout?: StorageLayout;
636
- rootOverride?: string;
637
- };
638
- interface StoragePathService {
639
- resolvePaths(options?: ResolveStorageOptions): StoragePaths;
640
- }
641
-
642
- declare const PROVIDER_NAME$3: "anthropic";
643
- type AnthropicOutputEffort = NonNullable<OutputConfig["effort"]> | "xhigh";
644
- type AnthropicOutputConfig = Omit<OutputConfig, "effort"> & {
645
- effort?: AnthropicOutputEffort | null;
646
- };
647
- type AnthropicMessageCreateParams = Omit<MessageCreateParamsNonStreaming, "output_config"> & {
648
- output_config?: AnthropicOutputConfig | null;
649
- speed?: "standard" | "fast" | null;
650
- betas?: string[];
651
- };
652
- type AnthropicInvokeOptions = Partial<Omit<AnthropicMessageCreateParams, "model" | "messages" | "tools" | "tool_choice" | "system" | "stream">>;
653
- type ChatAnthropicOptions = {
654
- client?: Anthropic;
655
- clientOptions?: ConstructorParameters<typeof Anthropic>[0];
656
- model?: string;
657
- maxTokens?: number;
658
- invokeOptions?: AnthropicInvokeOptions;
659
- fastMode?: boolean;
660
- reasoningLevelRequested?: ModelReasoningLevel;
661
- reasoningLevelApplied?: ModelReasoningLevel;
662
- reasoningFallbackApplied?: boolean;
663
- reasoningBudgetPreset?: string;
664
- };
665
- declare class ChatAnthropic implements BaseChatModel<typeof PROVIDER_NAME$3, AnthropicInvokeOptions> {
666
- readonly provider: typeof PROVIDER_NAME$3;
667
- readonly model: string;
668
- private readonly client;
669
- private readonly defaultMaxTokens;
670
- private readonly defaultInvokeOptions;
671
- private readonly fastMode;
672
- private readonly reasoningLevelMeta;
673
- private debugInvokeSeq;
674
- private lastDebugRequestPayload;
675
- constructor(options?: ChatAnthropicOptions);
676
- ainvoke(input: ChatInvokeInput & {
677
- options?: AnthropicInvokeOptions;
678
- }, _context?: ChatInvokeContext): Promise<ChatInvokeCompletion>;
679
- private nextDebugInvokeSeq;
680
- private debugRequestIfEnabled;
681
- private debugResponseIfEnabled;
682
- }
683
-
684
- /**
685
- * Responses API reasoning values supported by Codelia models. The generated
686
- * OpenAI SDK type can lag newly released provider values such as `max`.
687
- */
688
- type ResponsesReasoningEffort = ReasoningEffort | "max";
689
-
690
- type OpenAiWebsocketMode = "off" | "auto" | "on";
691
- type OpenAiWebsocketApiVersion = "v1" | "v2";
692
- type OpenAiResponsesWsLike = {
693
- on(event: string, listener: (event: unknown) => void): OpenAiResponsesWsLike;
694
- off?: (event: string, listener: (event: unknown) => void) => OpenAiResponsesWsLike;
695
- send(event: ResponsesClientEvent): void;
696
- close(props?: {
697
- code: number;
698
- reason: string;
699
- }): void;
700
- };
701
-
702
- declare const PROVIDER_NAME$2: "openai";
703
- type OpenAITextVerbosity = Exclude<ResponseTextConfig["verbosity"], null>;
704
- type OpenAIInvokeOptions = Omit<ResponseCreateParamsBase, "model" | "input" | "tools" | "tool_choice" | "stream"> & {
705
- reasoningEffort?: ResponsesReasoningEffort;
706
- textVerbosity?: OpenAITextVerbosity;
707
- serviceTier?: ResponseCreateParamsBase["service_tier"];
708
- };
709
- type OpenAIResponsesWsOptions = NonNullable<ConstructorParameters<typeof ResponsesWS>[1]> & {
710
- headers?: Record<string, string>;
711
- };
712
-
713
- type ChatOpenAIOptions = {
714
- client?: OpenAI;
715
- clientOptions?: ClientOptions;
716
- model?: string;
717
- providerModel?: string;
718
- reasoningEffort?: ResponsesReasoningEffort;
719
- reasoningLevelRequested?: ModelReasoningLevel;
720
- reasoningLevelApplied?: ModelReasoningLevel;
721
- reasoningFallbackApplied?: boolean;
722
- textVerbosity?: OpenAITextVerbosity;
723
- serviceTier?: ResponseCreateParamsBase["service_tier"];
724
- websocketMode?: OpenAiWebsocketMode;
725
- websocketApiVersion?: OpenAiWebsocketApiVersion;
726
- createResponsesWs?: (client: OpenAI, options?: OpenAIResponsesWsOptions) => OpenAiResponsesWsLike;
727
- websocketConnectTimeoutMs?: number;
728
- websocketResponseIdleTimeoutMs?: number;
729
- };
730
- declare class ChatOpenAI implements BaseChatModel<typeof PROVIDER_NAME$2, OpenAIInvokeOptions> {
731
- readonly provider: typeof PROVIDER_NAME$2;
732
- readonly model: string;
733
- private readonly providerModel;
734
- private readonly client;
735
- private readonly defaultReasoningEffort?;
736
- private readonly reasoningLevelMeta;
737
- private readonly defaultTextVerbosity?;
738
- private readonly defaultServiceTier?;
739
- private readonly websocketMode;
740
- private readonly websocketApiVersion;
741
- private readonly wsTransport;
742
- private debugInvokeSeq;
743
- private lastDebugRequestPayload;
744
- private readonly wsStateBySessionKey;
745
- private readonly wsDisabledUntilBySessionKey;
746
- private wsReconnectCount;
747
- constructor(options?: ChatOpenAIOptions);
748
- ainvoke(input: ChatInvokeInput & {
749
- options?: OpenAIInvokeOptions;
750
- }, context?: ChatInvokeContext): Promise<ChatInvokeCompletion>;
751
- onHistoryCompacted(context?: ChatInvokeContext): void;
752
- private invokeWithTransport;
753
- private invokeHttpTransportWithDebug;
754
- private persistWsSessionState;
755
- private buildWsLastInput;
756
- private invokeViaWs;
757
- private closeWsSafely;
758
- private closeWsWithoutMaskingPrimaryError;
759
- private isWsConnectionReuseExpired;
760
- private isWsReconnectRetryableError;
761
- private isWsConnectionReusable;
762
- private extractWsErrorCode;
763
- private clearWsSessionState;
764
- private evictIdleWsSessionState;
765
- private isWsSessionDisabled;
766
- private getIncrementalInput;
767
- private nextDebugInvokeSeq;
768
- private debugRequestIfEnabled;
769
- private debugResponseIfEnabled;
770
- private debugEmptyCompletionIfEnabled;
771
- private getHttpStreamDebugObserver;
772
- }
773
-
774
- declare const PROVIDER_NAME$1: "openrouter";
775
- type OpenRouterTextVerbosity = Exclude<ResponseTextConfig["verbosity"], null>;
776
- type OpenRouterInvokeOptions = Omit<ResponseCreateParamsBase, "model" | "input" | "tools" | "tool_choice" | "stream"> & {
777
- reasoningEffort?: ResponsesReasoningEffort;
778
- textVerbosity?: OpenRouterTextVerbosity;
779
- };
780
- type ChatOpenRouterOptions = {
781
- client?: OpenAI;
782
- clientOptions?: ClientOptions;
783
- model?: string;
784
- reasoningEffort?: ResponsesReasoningEffort;
785
- reasoningLevelRequested?: ModelReasoningLevel;
786
- reasoningLevelApplied?: ModelReasoningLevel;
787
- reasoningFallbackApplied?: boolean;
788
- textVerbosity?: OpenRouterTextVerbosity;
789
- };
790
- declare class ChatOpenRouter implements BaseChatModel<typeof PROVIDER_NAME$1, OpenRouterInvokeOptions> {
791
- readonly provider: typeof PROVIDER_NAME$1;
792
- readonly model: string;
793
- private readonly client;
794
- private readonly defaultReasoningEffort?;
795
- private readonly reasoningLevelMeta;
796
- private readonly defaultTextVerbosity?;
797
- private debugInvokeSeq;
798
- private lastDebugRequestPayload;
799
- constructor(options?: ChatOpenRouterOptions);
800
- ainvoke(input: ChatInvokeInput & {
801
- options?: OpenRouterInvokeOptions;
802
- }, context?: ChatInvokeContext): Promise<ChatInvokeCompletion>;
803
- private nextDebugInvokeSeq;
804
- private debugRequestIfEnabled;
805
- private debugResponseIfEnabled;
806
- }
807
-
808
- type ZaiReasoningEffort = "high" | "max";
809
-
810
- declare const PROVIDER_NAME: "zai";
811
- type ZaiAppliedReasoningLevel = Extract<ModelReasoningLevel, "high" | "xhigh" | "max">;
812
- type ZaiInvokeOptions = {
813
- max_tokens?: number;
814
- temperature?: number;
815
- top_p?: number;
816
- reasoningEffort?: ZaiReasoningEffort | null;
817
- [key: string]: unknown;
818
- };
819
- type ChatZaiOptions = {
820
- apiKey?: string;
821
- baseURL?: string;
822
- fetch?: typeof fetch;
823
- model?: string;
824
- timeoutMs?: number | null;
825
- reasoningEffort?: ZaiReasoningEffort | null;
826
- reasoningLevelRequested?: ModelReasoningLevel;
827
- reasoningLevelApplied?: ZaiAppliedReasoningLevel;
828
- reasoningFallbackApplied?: boolean;
829
- };
830
- declare class ChatZai implements BaseChatModel<typeof PROVIDER_NAME, ZaiInvokeOptions> {
831
- readonly provider: typeof PROVIDER_NAME;
832
- readonly model: string;
833
- private readonly apiKey?;
834
- private readonly baseURL;
835
- private readonly fetchImpl;
836
- private readonly timeoutMs;
837
- private readonly defaultReasoningEffort;
838
- private readonly reasoningLevelMeta;
839
- private debugInvokeSeq;
840
- private lastDebugRequestPayload;
841
- constructor(options?: ChatZaiOptions);
842
- ainvoke(input: ChatInvokeInput & {
843
- options?: ZaiInvokeOptions;
844
- }, _context?: ChatInvokeContext): Promise<ChatInvokeCompletion>;
845
- private streamRequest;
846
- private nextDebugInvokeSeq;
847
- private debugRequestIfEnabled;
848
- private debugResponseIfEnabled;
849
- }
850
-
851
- declare const ANTHROPIC_DEFAULT_MODEL = "claude-sonnet-4-5";
852
- declare const ANTHROPIC_MODELS: ModelSpec[];
853
-
854
- declare const GOOGLE_MODELS: ModelSpec[];
855
-
856
- declare const OPENAI_DEFAULT_MODEL = "gpt-5.6";
857
- declare const OPENAI_DEFAULT_REASONING_EFFORT = "medium";
858
- declare const OPENAI_MODELS: ModelSpec[];
859
-
860
- declare const ZAI_DEFAULT_MODEL = "glm-5.2";
861
- declare const ZAI_REASONING_EFFORT_MODELS: Set<string>;
862
- declare const ZAI_MODELS: ModelSpec[];
863
-
864
- declare const DEFAULT_MODEL_REGISTRY: ModelRegistry;
865
-
866
- declare const getDefaultSystemPromptPath: () => string;
867
-
868
- declare function defineTool<TInput, TResult extends ToolReturn>(toolOptions: DefineToolOptions<TInput, TResult>): Tool;
869
-
870
- declare class TaskComplete extends Error {
871
- readonly finalMessage?: string;
872
- constructor(finalMessage?: string);
873
- }
874
-
875
- export { ANTHROPIC_DEFAULT_MODEL, ANTHROPIC_MODELS, Agent, type AgentEventRecord, type AgentOptions, type AgentRunOptions, type AgentServices, type AgentSession, type BaseChatModel, type BaseMessage, ChatAnthropic, type ChatInvokeContext, type ChatInvokeInput, ChatOpenAI, ChatOpenRouter, ChatZai, type ContentPart, DEFAULT_MODEL_REGISTRY, type DependencyKey, GOOGLE_MODELS, type LlmRequestRecord, type LlmResponseRecord, type ModelCapabilities, type ModelCost, type ModelEntry, type ModelLimits, type ModelMetadataIndex, type ModelMetadataService, type ModelRegistry, type ModelSpec, OPENAI_DEFAULT_MODEL, OPENAI_DEFAULT_REASONING_EFFORT, OPENAI_MODELS, type ResolveStorageOptions, type RunContextRecord, type RunEndRecord, type RunErrorRecord, type RunEventStoreFactory, type RunEventStoreInit, type RunStartRecord, type RunStatusRecord, type SessionHeader, type SessionRecord, type SessionState, type SessionStateStore, type SessionStateSummary, type SessionStore, type StorageLayout, type StoragePathService, type StoragePaths, type StringifyContentMode, type StringifyContentOptions, TaskComplete, type Tool, type ToolChoice, type ToolContext, type ToolDefinition, type ToolExecution, type ToolOutputCacheConfig, type ToolOutputCacheReadOptions, type ToolOutputCacheRecord, type ToolOutputCacheSearchOptions, ToolOutputCacheService, type ToolOutputCacheStore, type ToolOutputRecord, type ToolOutputRef, type ToolPermissionDecision, type ToolPermissionHook, type ToolResult, ZAI_DEFAULT_MODEL, ZAI_MODELS, ZAI_REASONING_EFFORT_MODELS, applyModelMetadata, createModelRegistry, defineTool, getDefaultSystemPromptPath, isUsableModelSpec, listModels, registerModels, resolveModel, resolveProviderModelId, stringifyContent, stringifyContentParts, supportsFastMode };