@codelia/core 0.1.82 → 0.1.84
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 +3632 -2331
- package/dist/index.d.ts +310 -161
- package/dist/index.js +3622 -2329
- package/package.json +4 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,51 +1,17 @@
|
|
|
1
1
|
import * as _codelia_shared_types from '@codelia/shared-types';
|
|
2
|
-
import { LlmCallTiming, ProviderName, AgentEvent, SessionStateSummary as SessionStateSummary$1, ModelReasoningLevel } from '@codelia/shared-types';
|
|
3
|
-
export { AgentEvent, FinalResponseEvent, LlmRetryEvent, LlmStatusEvent, ReasoningEvent, StepCompleteEvent, StepStartEvent, TextEvent, ToolCallEvent, ToolResultEvent } from '@codelia/shared-types';
|
|
2
|
+
import { ContentPart, TextPart, LlmCallTiming, ProviderName, ImagePart, ModelFastMode, AgentEvent, RunErrorInfo, SessionStateSummary as SessionStateSummary$1, ContextUsage, ModelReasoningLevel } from '@codelia/shared-types';
|
|
3
|
+
export { AgentEvent, AttachmentRefPart, ContentPart, FinalResponseEvent, HiddenUserMessageEvent, LlmRetryEvent, LlmStatusEvent, ReasoningDeltaEvent, ReasoningEvent, SteerAppliedEvent, StepCompleteEvent, StepStartEvent, TextDeltaEvent, TextEvent, ToolCallEvent, ToolResultEvent } from '@codelia/shared-types';
|
|
4
4
|
import { JSONSchema7 } from 'json-schema';
|
|
5
5
|
import { ZodSchema } from 'zod';
|
|
6
6
|
import { Logger } from 'openai/client';
|
|
7
7
|
import Anthropic from '@anthropic-ai/sdk';
|
|
8
8
|
import { MessageCreateParamsNonStreaming, OutputConfig } from '@anthropic-ai/sdk/resources/messages/messages';
|
|
9
|
+
import { ResponsesProviderConfig } from '@codelia/config';
|
|
10
|
+
import { ResponseCreateParamsBase, ResponsesClientEvent, ResponseTextConfig } from 'openai/resources/responses/responses';
|
|
11
|
+
import { GoogleGenAI } from '@google/genai';
|
|
9
12
|
import OpenAI, { ClientOptions } from 'openai';
|
|
10
|
-
import { ResponsesClientEvent, ResponseCreateParamsBase, ResponseTextConfig } from 'openai/resources/responses/responses';
|
|
11
13
|
import { ResponsesWS } from 'openai/resources/responses/ws';
|
|
12
14
|
import { ReasoningEffort } from 'openai/resources/shared';
|
|
13
|
-
import { ResponsesProviderConfig } from '@codelia/config';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Message Content Parts
|
|
17
|
-
*/
|
|
18
|
-
type ImageRefPart = {
|
|
19
|
-
type: "image_ref";
|
|
20
|
-
image_ref: _codelia_shared_types.ImageArtifactRef;
|
|
21
|
-
detail?: "auto" | "low" | "high";
|
|
22
|
-
};
|
|
23
|
-
type TextPart = {
|
|
24
|
-
type: "text";
|
|
25
|
-
text: string;
|
|
26
|
-
};
|
|
27
|
-
type ImagePart = {
|
|
28
|
-
type: "image_url";
|
|
29
|
-
image_url: {
|
|
30
|
-
url: string;
|
|
31
|
-
detail?: "auto" | "low" | "high";
|
|
32
|
-
media_type?: "image/png" | "image/jpeg" | "image/webp" | "image/gif";
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
type DocumentPart = {
|
|
36
|
-
type: "document";
|
|
37
|
-
source: {
|
|
38
|
-
data: string;
|
|
39
|
-
media_type: "application/pdf";
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
type OtherPart = {
|
|
43
|
-
type: "other";
|
|
44
|
-
provider: string;
|
|
45
|
-
kind: string;
|
|
46
|
-
payload: unknown;
|
|
47
|
-
};
|
|
48
|
-
type ContentPart = TextPart | ImagePart | ImageRefPart | DocumentPart | OtherPart;
|
|
49
15
|
|
|
50
16
|
/**
|
|
51
17
|
* Tool Call
|
|
@@ -136,6 +102,8 @@ type AssistantMessage = {
|
|
|
136
102
|
name?: string;
|
|
137
103
|
tool_calls?: ToolCall[];
|
|
138
104
|
refusal?: string | null;
|
|
105
|
+
/** Provider-owned response metadata, preserved for exact history replay. */
|
|
106
|
+
provider_meta?: unknown;
|
|
139
107
|
};
|
|
140
108
|
type ToolOutputRef = {
|
|
141
109
|
id: string;
|
|
@@ -152,6 +120,7 @@ type ToolMessage = {
|
|
|
152
120
|
tool_call_id: string;
|
|
153
121
|
tool_name: string;
|
|
154
122
|
content: string | ContentPart[];
|
|
123
|
+
display_content?: string;
|
|
155
124
|
is_error?: boolean;
|
|
156
125
|
output_ref?: ToolOutputRef;
|
|
157
126
|
trimmed?: boolean;
|
|
@@ -177,6 +146,114 @@ type ChatInvokeCompletion = {
|
|
|
177
146
|
provider_meta?: unknown;
|
|
178
147
|
};
|
|
179
148
|
|
|
149
|
+
type ProviderFailureKind = "rate_limit" | "overloaded" | "timeout" | "network" | "hard_quota" | "auth" | "permission" | "validation" | "provider" | "cancelled";
|
|
150
|
+
type RetryDelaySource = "retry-after" | "reset-header" | "provider-body" | "backoff";
|
|
151
|
+
type ProviderFailure = {
|
|
152
|
+
provider: ProviderName;
|
|
153
|
+
kind: ProviderFailureKind;
|
|
154
|
+
retryable: boolean;
|
|
155
|
+
safeMessage: string;
|
|
156
|
+
/** Explicit safe context only, never a raw provider message. */
|
|
157
|
+
detail?: string;
|
|
158
|
+
status?: number;
|
|
159
|
+
code?: string;
|
|
160
|
+
retryAfterMs?: number;
|
|
161
|
+
delaySource?: Exclude<RetryDelaySource, "backoff">;
|
|
162
|
+
delivery?: "none" | "buffered" | "committed";
|
|
163
|
+
};
|
|
164
|
+
type ProviderFailureClassifier = (error: unknown) => ProviderFailure | null;
|
|
165
|
+
declare class ProviderFailureError extends Error {
|
|
166
|
+
readonly failure: ProviderFailure;
|
|
167
|
+
readonly attempts: number;
|
|
168
|
+
readonly maxAttempts: number;
|
|
169
|
+
constructor(failure: ProviderFailure, options?: {
|
|
170
|
+
attempts?: number;
|
|
171
|
+
maxAttempts?: number;
|
|
172
|
+
cause?: unknown;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
declare const isProviderFailureError: (error: unknown) => error is ProviderFailureError;
|
|
176
|
+
|
|
177
|
+
type ImageTokenInput = {
|
|
178
|
+
width?: number;
|
|
179
|
+
height?: number;
|
|
180
|
+
detail?: "auto" | "low" | "high";
|
|
181
|
+
};
|
|
182
|
+
type ImageTokenEstimate = {
|
|
183
|
+
tokens: number;
|
|
184
|
+
method: "patch" | "tile" | "fallback";
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
type LlmRetryPolicy = {
|
|
188
|
+
maxRetries: number;
|
|
189
|
+
baseDelayMs: number;
|
|
190
|
+
maxDelayMs: number;
|
|
191
|
+
maxRetryAfterMs: number;
|
|
192
|
+
retryWindowMs: number;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* One provisional chunk of streamed model output. `index` numbers the streamed
|
|
197
|
+
* blocks of one kind in this response, in order of their first delta. It is a
|
|
198
|
+
* grouping key for provisional display, not a position in the completion.
|
|
199
|
+
*/
|
|
200
|
+
type ChatStreamDelta = {
|
|
201
|
+
kind: "text" | "reasoning";
|
|
202
|
+
index: number;
|
|
203
|
+
delta: string;
|
|
204
|
+
};
|
|
205
|
+
/** Per-attempt sink for streamed deltas. Providers that do not stream ignore it. */
|
|
206
|
+
type ChatStreamDeltaSink = (delta: ChatStreamDelta) => void;
|
|
207
|
+
type ChatInvokeInput = {
|
|
208
|
+
messages: BaseMessage[];
|
|
209
|
+
model?: string;
|
|
210
|
+
tools?: ToolDefinition[] | null;
|
|
211
|
+
toolChoice?: ToolChoice | null;
|
|
212
|
+
signal?: AbortSignal;
|
|
213
|
+
/** Optional, per-attempt. Absent means providers keep their non-delta path unchanged. */
|
|
214
|
+
onDelta?: ChatStreamDeltaSink;
|
|
215
|
+
};
|
|
216
|
+
type ChatInvokeContext = {
|
|
217
|
+
sessionKey?: string;
|
|
218
|
+
/** One user turn; distinct from a durable session key. */
|
|
219
|
+
turnKey?: string;
|
|
220
|
+
onProviderStatus?: (event: _codelia_shared_types.LlmStatusEvent) => void;
|
|
221
|
+
};
|
|
222
|
+
interface BaseChatModel<P extends ProviderName = ProviderName, O = unknown> {
|
|
223
|
+
readonly provider: P;
|
|
224
|
+
readonly model: string;
|
|
225
|
+
ainvoke(input: ChatInvokeInput & {
|
|
226
|
+
options?: O;
|
|
227
|
+
}, context?: ChatInvokeContext): Promise<ChatInvokeCompletion>;
|
|
228
|
+
classifyFailure?: ProviderFailureClassifier;
|
|
229
|
+
/** Endpoint-owned retry policy takes precedence over Agent defaults. */
|
|
230
|
+
readonly retryPolicy?: Partial<LlmRetryPolicy>;
|
|
231
|
+
/** Optional model-specific vision estimate; never a billing usage report. */
|
|
232
|
+
estimateImageTokens?(image: ImageTokenInput): ImageTokenEstimate;
|
|
233
|
+
onHistoryCompacted?(context?: ChatInvokeContext): void | Promise<void>;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
declare const responseDetails: {
|
|
237
|
+
readonly invalid_event: "The response stream contained an invalid event.";
|
|
238
|
+
readonly invalid_completion: "The provider returned an incomplete or invalid completion record.";
|
|
239
|
+
readonly after_completion: "The provider emitted output after completion.";
|
|
240
|
+
readonly invalid_step_index: "The response stream contained an invalid step index.";
|
|
241
|
+
readonly invalid_step: "The response contained a duplicate or invalid step.";
|
|
242
|
+
readonly out_of_order: "The response stream contained an out-of-order step.";
|
|
243
|
+
readonly invalid_tool_arguments: "The response contained incomplete or invalid tool arguments.";
|
|
244
|
+
readonly unsupported_event: "The response stream contained an unsupported event type.";
|
|
245
|
+
readonly invalid_delta: "The response contained an invalid output delta.";
|
|
246
|
+
readonly unsupported_content: "The response contained unsupported content.";
|
|
247
|
+
readonly unsupported_delta: "The response contained an unsupported output delta type.";
|
|
248
|
+
readonly incomplete: "The response stream ended before completion.";
|
|
249
|
+
readonly missing_step: "The response stream omitted a required step.";
|
|
250
|
+
readonly invalid_output: "The response contained invalid model output.";
|
|
251
|
+
readonly nonterminal: "The provider response did not complete in a valid terminal state.";
|
|
252
|
+
readonly empty: "The provider returned no model output.";
|
|
253
|
+
};
|
|
254
|
+
/** Explicitly trusted local diagnostics; never accept a provider message/body here. */
|
|
255
|
+
declare const createProviderResponseError: (provider: ProviderName, reason: keyof typeof responseDetails) => ProviderFailureError;
|
|
256
|
+
|
|
180
257
|
type ToolOutputCacheRecord = {
|
|
181
258
|
tool_call_id: string;
|
|
182
259
|
tool_name: string;
|
|
@@ -222,6 +299,8 @@ type ModelLimits = {
|
|
|
222
299
|
};
|
|
223
300
|
type ModelCapabilities = {
|
|
224
301
|
supportsFast?: boolean;
|
|
302
|
+
supportsVision?: boolean;
|
|
303
|
+
supportsTools?: boolean;
|
|
225
304
|
};
|
|
226
305
|
type ModelEntry = {
|
|
227
306
|
provider: string;
|
|
@@ -241,8 +320,11 @@ interface ModelMetadataService {
|
|
|
241
320
|
getAllModelEntries(): Promise<Record<string, Record<string, ModelEntry>>>;
|
|
242
321
|
}
|
|
243
322
|
|
|
323
|
+
type ResolveImage = (ref: _codelia_shared_types.ImageArtifactRef, signal?: AbortSignal) => Promise<ImagePart>;
|
|
244
324
|
type AgentServices = {
|
|
245
|
-
resolveImage?:
|
|
325
|
+
resolveImage?: ResolveImage;
|
|
326
|
+
/** Undefined shares the existing image store. Null disables copied-image resolution. */
|
|
327
|
+
resolveAttachmentImage?: ResolveImage | null;
|
|
246
328
|
modelMetadata?: ModelMetadataService;
|
|
247
329
|
toolOutputCacheStore?: ToolOutputCacheStore | null;
|
|
248
330
|
monotonicNowMs?: () => number;
|
|
@@ -251,77 +333,6 @@ type AgentServices = {
|
|
|
251
333
|
llmRetrySleep?: (delayMs: number, signal?: AbortSignal) => Promise<void>;
|
|
252
334
|
};
|
|
253
335
|
|
|
254
|
-
type ProviderFailureKind = "rate_limit" | "overloaded" | "timeout" | "network" | "hard_quota" | "auth" | "permission" | "validation" | "provider" | "cancelled";
|
|
255
|
-
type RetryDelaySource = "retry-after" | "reset-header" | "provider-body" | "backoff";
|
|
256
|
-
type ProviderFailure = {
|
|
257
|
-
provider: ProviderName;
|
|
258
|
-
kind: ProviderFailureKind;
|
|
259
|
-
retryable: boolean;
|
|
260
|
-
safeMessage: string;
|
|
261
|
-
status?: number;
|
|
262
|
-
code?: string;
|
|
263
|
-
retryAfterMs?: number;
|
|
264
|
-
delaySource?: Exclude<RetryDelaySource, "backoff">;
|
|
265
|
-
delivery?: "none" | "buffered" | "committed";
|
|
266
|
-
};
|
|
267
|
-
type ProviderFailureClassifier = (error: unknown) => ProviderFailure | null;
|
|
268
|
-
declare class ProviderFailureError extends Error {
|
|
269
|
-
readonly failure: ProviderFailure;
|
|
270
|
-
readonly attempts: number;
|
|
271
|
-
readonly maxAttempts: number;
|
|
272
|
-
constructor(failure: ProviderFailure, options?: {
|
|
273
|
-
attempts?: number;
|
|
274
|
-
maxAttempts?: number;
|
|
275
|
-
cause?: unknown;
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
declare const isProviderFailureError: (error: unknown) => error is ProviderFailureError;
|
|
279
|
-
|
|
280
|
-
type LlmRetryPolicy = {
|
|
281
|
-
maxRetries: number;
|
|
282
|
-
baseDelayMs: number;
|
|
283
|
-
maxDelayMs: number;
|
|
284
|
-
maxRetryAfterMs: number;
|
|
285
|
-
retryWindowMs: number;
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
type ImageTokenInput = {
|
|
289
|
-
width?: number;
|
|
290
|
-
height?: number;
|
|
291
|
-
detail?: "auto" | "low" | "high";
|
|
292
|
-
};
|
|
293
|
-
type ImageTokenEstimate = {
|
|
294
|
-
tokens: number;
|
|
295
|
-
method: "patch" | "tile" | "fallback";
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
type ChatInvokeInput = {
|
|
299
|
-
messages: BaseMessage[];
|
|
300
|
-
model?: string;
|
|
301
|
-
tools?: ToolDefinition[] | null;
|
|
302
|
-
toolChoice?: ToolChoice | null;
|
|
303
|
-
signal?: AbortSignal;
|
|
304
|
-
};
|
|
305
|
-
type ChatInvokeContext = {
|
|
306
|
-
sessionKey?: string;
|
|
307
|
-
/** One user turn; distinct from a durable session key. */
|
|
308
|
-
turnKey?: string;
|
|
309
|
-
onProviderStatus?: (event: _codelia_shared_types.LlmStatusEvent) => void;
|
|
310
|
-
};
|
|
311
|
-
interface BaseChatModel<P extends ProviderName = ProviderName, O = unknown> {
|
|
312
|
-
readonly provider: P;
|
|
313
|
-
readonly model: string;
|
|
314
|
-
ainvoke(input: ChatInvokeInput & {
|
|
315
|
-
options?: O;
|
|
316
|
-
}, context?: ChatInvokeContext): Promise<ChatInvokeCompletion>;
|
|
317
|
-
classifyFailure?: ProviderFailureClassifier;
|
|
318
|
-
/** Endpoint-owned retry policy takes precedence over Agent defaults. */
|
|
319
|
-
readonly retryPolicy?: Partial<LlmRetryPolicy>;
|
|
320
|
-
/** Optional model-specific vision estimate; never a billing usage report. */
|
|
321
|
-
estimateImageTokens?(image: ImageTokenInput): ImageTokenEstimate;
|
|
322
|
-
onHistoryCompacted?(context?: ChatInvokeContext): void | Promise<void>;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
336
|
type ModelSpec = {
|
|
326
337
|
id: string;
|
|
327
338
|
provider: ProviderName;
|
|
@@ -422,12 +433,15 @@ type ToolContext = {
|
|
|
422
433
|
type DefineToolOptions<TInput, TResult extends ToolReturn = ToolReturn> = {
|
|
423
434
|
name: string;
|
|
424
435
|
description: string;
|
|
436
|
+
/** Optional transcript/diagnostic substitute for sensitive model-facing results. */
|
|
437
|
+
displayResult?: string;
|
|
425
438
|
input: ZodSchema<TInput>;
|
|
426
439
|
execute: (input: TInput, ctx: ToolContext) => Promise<TResult> | TResult;
|
|
427
440
|
};
|
|
428
441
|
type Tool = {
|
|
429
442
|
name: string;
|
|
430
443
|
description: string;
|
|
444
|
+
displayResult?: string;
|
|
431
445
|
definition: ToolDefinition;
|
|
432
446
|
executeRaw: (rawArgsJson: string, ctx: ToolContext) => Promise<ToolResult>;
|
|
433
447
|
};
|
|
@@ -467,7 +481,7 @@ type SessionHeader = {
|
|
|
467
481
|
provider?: string;
|
|
468
482
|
name?: string;
|
|
469
483
|
reasoning?: string;
|
|
470
|
-
fast?:
|
|
484
|
+
fast?: ModelFastMode;
|
|
471
485
|
source?: "config" | "session";
|
|
472
486
|
};
|
|
473
487
|
prompts?: {
|
|
@@ -535,7 +549,7 @@ type LlmRequestRecord = {
|
|
|
535
549
|
provider?: string;
|
|
536
550
|
name?: string;
|
|
537
551
|
reasoning?: string;
|
|
538
|
-
fast?:
|
|
552
|
+
fast?: ModelFastMode;
|
|
539
553
|
};
|
|
540
554
|
input: {
|
|
541
555
|
messages: BaseMessage[];
|
|
@@ -560,6 +574,16 @@ type LlmResponseRecord = {
|
|
|
560
574
|
};
|
|
561
575
|
meta?: Record<string, unknown>;
|
|
562
576
|
};
|
|
577
|
+
/** Compact accounting only; never includes messages or opaque provider payloads. */
|
|
578
|
+
type LlmUsageRecord = {
|
|
579
|
+
type: "llm.usage";
|
|
580
|
+
run_id: string;
|
|
581
|
+
session_id?: string;
|
|
582
|
+
ts: string;
|
|
583
|
+
seq: number;
|
|
584
|
+
model?: LlmRequestRecord["model"];
|
|
585
|
+
output: Pick<LlmResponseRecord["output"], "usage" | "timing" | "stop_reason">;
|
|
586
|
+
};
|
|
563
587
|
type RunStatusRecord = {
|
|
564
588
|
type: "run.status";
|
|
565
589
|
run_id: string;
|
|
@@ -572,16 +596,9 @@ type RunErrorRecord = {
|
|
|
572
596
|
type: "run.error";
|
|
573
597
|
run_id: string;
|
|
574
598
|
ts: string;
|
|
575
|
-
error: {
|
|
576
|
-
name: string;
|
|
577
|
-
message: string;
|
|
599
|
+
error: RunErrorInfo & {
|
|
578
600
|
stack?: string;
|
|
579
|
-
provider?: ProviderName;
|
|
580
601
|
kind?: ProviderFailureKind;
|
|
581
|
-
status?: number;
|
|
582
|
-
code?: string;
|
|
583
|
-
attempts?: number;
|
|
584
|
-
max_attempts?: number;
|
|
585
602
|
};
|
|
586
603
|
meta?: Record<string, unknown>;
|
|
587
604
|
};
|
|
@@ -593,7 +610,7 @@ type RunEndRecord = {
|
|
|
593
610
|
final?: string;
|
|
594
611
|
meta?: Record<string, unknown>;
|
|
595
612
|
};
|
|
596
|
-
type SessionRecord = SessionHeader | RunStartRecord | RunContextRecord | AgentEventRecord | ToolOutputRecord | LlmRequestRecord | LlmResponseRecord | RunStatusRecord | RunErrorRecord | RunEndRecord;
|
|
613
|
+
type SessionRecord = SessionHeader | RunStartRecord | RunContextRecord | AgentEventRecord | ToolOutputRecord | LlmRequestRecord | LlmResponseRecord | LlmUsageRecord | RunStatusRecord | RunErrorRecord | RunEndRecord;
|
|
597
614
|
type SessionStore = {
|
|
598
615
|
filePath?: string;
|
|
599
616
|
append: (record: SessionRecord) => Promise<void> | void;
|
|
@@ -615,10 +632,36 @@ type SessionState = {
|
|
|
615
632
|
meta?: Record<string, unknown>;
|
|
616
633
|
};
|
|
617
634
|
type SessionStateSummary = SessionStateSummary$1;
|
|
635
|
+
type ConversationMessage = {
|
|
636
|
+
id: string;
|
|
637
|
+
role: BaseMessage["role"];
|
|
638
|
+
text: string;
|
|
639
|
+
truncated: boolean;
|
|
640
|
+
next_offset?: number;
|
|
641
|
+
};
|
|
642
|
+
type ConversationSearchResult = {
|
|
643
|
+
matches: ConversationMessage[];
|
|
644
|
+
next_cursor?: string;
|
|
645
|
+
};
|
|
618
646
|
type SessionStateStore = {
|
|
619
647
|
load: (sessionId: string) => Promise<SessionState | null>;
|
|
620
648
|
save: (state: SessionState) => Promise<void>;
|
|
621
649
|
list: () => Promise<SessionStateSummary[]>;
|
|
650
|
+
appendMessages?: (sessionId: string, messages: BaseMessage[]) => Promise<void>;
|
|
651
|
+
searchMessages?: (sessionId: string, options: {
|
|
652
|
+
query: string;
|
|
653
|
+
cursor?: string;
|
|
654
|
+
limit?: number;
|
|
655
|
+
}) => Promise<ConversationSearchResult>;
|
|
656
|
+
readMessage?: (sessionId: string, options: {
|
|
657
|
+
id: string;
|
|
658
|
+
offset?: number;
|
|
659
|
+
limit?: number;
|
|
660
|
+
}) => Promise<ConversationMessage | null>;
|
|
661
|
+
updateMetadata?: (sessionId: string, patch: {
|
|
662
|
+
pinned?: boolean;
|
|
663
|
+
archived?: boolean;
|
|
664
|
+
}) => Promise<SessionStateSummary>;
|
|
622
665
|
};
|
|
623
666
|
type AgentSession = {
|
|
624
667
|
run_id: string;
|
|
@@ -626,16 +669,28 @@ type AgentSession = {
|
|
|
626
669
|
invoke_seq?: number;
|
|
627
670
|
on_error?: (error: unknown, record: SessionRecord) => void;
|
|
628
671
|
append: (record: SessionRecord) => void;
|
|
672
|
+
/** Await durable originals before admitting messages or discarding context. */
|
|
673
|
+
recordMessages?: (messages: BaseMessage[]) => Promise<void>;
|
|
629
674
|
};
|
|
630
675
|
|
|
676
|
+
type PolledMessage = string | {
|
|
677
|
+
kind: "hidden" | "steer";
|
|
678
|
+
content: string | ContentPart[];
|
|
679
|
+
steer_id?: string;
|
|
680
|
+
};
|
|
631
681
|
type AgentRunOptions = {
|
|
632
682
|
/** Untrusted messages polled only between model/tool batches; never starts a nested run. */
|
|
633
|
-
pollMessages?: () => Promise<
|
|
683
|
+
pollMessages?: () => Promise<PolledMessage[]>;
|
|
634
684
|
session?: AgentSession;
|
|
635
685
|
signal?: AbortSignal;
|
|
636
686
|
forceCompaction?: boolean;
|
|
637
687
|
tools?: Tool[];
|
|
638
688
|
toolChoice?: ToolChoice;
|
|
689
|
+
/**
|
|
690
|
+
* Opt-in: also yield provisional `text.delta` / `reasoning.delta` events while a
|
|
691
|
+
* model step streams. Complete `text` / `reasoning` / `final` events are unchanged.
|
|
692
|
+
*/
|
|
693
|
+
streamDeltas?: boolean;
|
|
639
694
|
};
|
|
640
695
|
type AgentOptions = {
|
|
641
696
|
llm: BaseChatModel;
|
|
@@ -675,11 +730,18 @@ declare class Agent {
|
|
|
675
730
|
private readonly llmRetryDependencies;
|
|
676
731
|
private history;
|
|
677
732
|
private usageService;
|
|
733
|
+
/** Tool definitions of the latest model call (includes per-run client tools). */
|
|
734
|
+
private lastToolDefinitions;
|
|
678
735
|
private imageUsageBaseline?;
|
|
679
736
|
constructor(options: AgentOptions);
|
|
680
737
|
getUsageSummary(): UsageSummary;
|
|
681
738
|
getContextLeftPercent(): number | null;
|
|
739
|
+
/** Last provider-reported usage; a new object per completed model call. */
|
|
740
|
+
getLastUsage(): ChatInvokeUsage | null;
|
|
741
|
+
/** Context window usage with an estimated per-category breakdown. */
|
|
742
|
+
getContextUsage(): ContextUsage;
|
|
682
743
|
getHistoryMessages(): BaseMessage[];
|
|
744
|
+
private recordOriginals;
|
|
683
745
|
replaceHistoryMessages(messages: BaseMessage[]): void;
|
|
684
746
|
private checkAndCompact;
|
|
685
747
|
private trimToolOutputs;
|
|
@@ -690,6 +752,8 @@ declare class Agent {
|
|
|
690
752
|
private recordLlmResponse;
|
|
691
753
|
private invokeModelWithRetry;
|
|
692
754
|
run(message: string | ContentPart[], options?: AgentRunOptions): Promise<string>;
|
|
755
|
+
canUseVisualAttachments(): boolean;
|
|
756
|
+
private get attachmentImageResolver();
|
|
693
757
|
runStream(message: string | ContentPart[], options?: AgentRunOptions): AsyncGenerator<AgentEvent>;
|
|
694
758
|
private generateFinalResponse;
|
|
695
759
|
}
|
|
@@ -767,6 +831,87 @@ declare class ChatAnthropic implements BaseChatModel<typeof PROVIDER_NAME$5, Ant
|
|
|
767
831
|
private debugResponseIfEnabled;
|
|
768
832
|
}
|
|
769
833
|
|
|
834
|
+
type ResponsesInvokeOptions = {
|
|
835
|
+
reasoningEffort?: ModelReasoningLevel;
|
|
836
|
+
maxOutputTokens?: number;
|
|
837
|
+
text?: ResponseCreateParamsBase["text"];
|
|
838
|
+
};
|
|
839
|
+
/** Stateless HTTP Responses transport, independently named and authenticated. */
|
|
840
|
+
declare class ChatResponses implements BaseChatModel<string, ResponsesInvokeOptions> {
|
|
841
|
+
readonly provider: string;
|
|
842
|
+
readonly model: string;
|
|
843
|
+
readonly retryPolicy: {
|
|
844
|
+
baseDelayMs?: number | undefined;
|
|
845
|
+
maxRetries: number;
|
|
846
|
+
};
|
|
847
|
+
private readonly client;
|
|
848
|
+
private readonly endpoint;
|
|
849
|
+
private readonly reasoningEffort?;
|
|
850
|
+
private readonly textVerbosity?;
|
|
851
|
+
constructor(options: {
|
|
852
|
+
provider: string;
|
|
853
|
+
model: string;
|
|
854
|
+
endpoint: ResponsesProviderConfig;
|
|
855
|
+
apiKey: string;
|
|
856
|
+
reasoningEffort?: ModelReasoningLevel;
|
|
857
|
+
textVerbosity?: "low" | "medium" | "high";
|
|
858
|
+
fetch?: typeof fetch;
|
|
859
|
+
});
|
|
860
|
+
readonly classifyFailure: (error: unknown) => ProviderFailure;
|
|
861
|
+
ainvoke(input: ChatInvokeInput & {
|
|
862
|
+
options?: ResponsesInvokeOptions;
|
|
863
|
+
}, context?: ChatInvokeContext): Promise<ChatInvokeCompletion>;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
/** Official stateless Responses endpoint with independent API-key authentication. */
|
|
867
|
+
declare class ChatDeepSeek implements BaseChatModel<"deepseek", ResponsesInvokeOptions> {
|
|
868
|
+
readonly provider: "deepseek";
|
|
869
|
+
readonly model: string;
|
|
870
|
+
readonly retryPolicy: {
|
|
871
|
+
baseDelayMs?: number | undefined;
|
|
872
|
+
maxRetries: number;
|
|
873
|
+
};
|
|
874
|
+
private readonly transport;
|
|
875
|
+
private readonly requestedEffort;
|
|
876
|
+
constructor(options: {
|
|
877
|
+
apiKey: string;
|
|
878
|
+
model?: string;
|
|
879
|
+
reasoningEffort?: ModelReasoningLevel;
|
|
880
|
+
fetch?: typeof fetch;
|
|
881
|
+
});
|
|
882
|
+
readonly classifyFailure: (error: unknown) => ProviderFailure;
|
|
883
|
+
ainvoke(input: ChatInvokeInput & {
|
|
884
|
+
options?: ResponsesInvokeOptions;
|
|
885
|
+
}, context?: ChatInvokeContext): Promise<{
|
|
886
|
+
provider_meta: {
|
|
887
|
+
reasoning_requested: "low" | "high" | "medium" | "xhigh" | "max";
|
|
888
|
+
reasoning_applied: "low" | "high" | "max";
|
|
889
|
+
reasoning_effort: "low" | "high" | "max";
|
|
890
|
+
reasoning_fallback: boolean;
|
|
891
|
+
};
|
|
892
|
+
usage?: ChatInvokeUsage | null;
|
|
893
|
+
messages: BaseMessage[];
|
|
894
|
+
timing?: _codelia_shared_types.LlmCallTiming;
|
|
895
|
+
stop_reason?: string | null;
|
|
896
|
+
}>;
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
type ChatGoogleOptions = {
|
|
900
|
+
apiKey: string;
|
|
901
|
+
model?: string;
|
|
902
|
+
thinkingLevel?: "low" | "medium" | "high" | "xhigh";
|
|
903
|
+
client?: GoogleGenAI;
|
|
904
|
+
};
|
|
905
|
+
declare class ChatGoogle implements BaseChatModel<"google"> {
|
|
906
|
+
readonly provider: "google";
|
|
907
|
+
readonly classifyFailure: (error: unknown) => ProviderFailure;
|
|
908
|
+
readonly model: string;
|
|
909
|
+
private readonly client;
|
|
910
|
+
private readonly thinkingLevel?;
|
|
911
|
+
constructor(options: ChatGoogleOptions);
|
|
912
|
+
ainvoke(input: ChatInvokeInput): Promise<ChatInvokeCompletion>;
|
|
913
|
+
}
|
|
914
|
+
|
|
770
915
|
declare const PROVIDER_NAME$4: "moonshot";
|
|
771
916
|
type MoonshotInvokeOptions = {
|
|
772
917
|
max_completion_tokens?: number;
|
|
@@ -780,7 +925,9 @@ type ChatMoonshotOptions = {
|
|
|
780
925
|
timeoutMs?: number;
|
|
781
926
|
maxRetries?: number;
|
|
782
927
|
reasoningLevelRequested?: ModelReasoningLevel;
|
|
928
|
+
reasoningEffort?: MoonshotReasoningEffort;
|
|
783
929
|
};
|
|
930
|
+
type MoonshotReasoningEffort = "low" | "high" | "max";
|
|
784
931
|
declare class ChatMoonshot implements BaseChatModel<typeof PROVIDER_NAME$4, MoonshotInvokeOptions> {
|
|
785
932
|
readonly provider: typeof PROVIDER_NAME$4;
|
|
786
933
|
readonly model: string;
|
|
@@ -788,6 +935,7 @@ declare class ChatMoonshot implements BaseChatModel<typeof PROVIDER_NAME$4, Moon
|
|
|
788
935
|
private readonly apiKey?;
|
|
789
936
|
private readonly clientOptions;
|
|
790
937
|
private readonly reasoningLevelRequested;
|
|
938
|
+
private readonly reasoningEffort;
|
|
791
939
|
private debugInvokeSeq;
|
|
792
940
|
private lastDebugRequestPayload;
|
|
793
941
|
constructor(options?: ChatMoonshotOptions);
|
|
@@ -819,10 +967,12 @@ type OpenAiResponsesWsLike = {
|
|
|
819
967
|
|
|
820
968
|
declare const PROVIDER_NAME$3: "openai";
|
|
821
969
|
type OpenAITextVerbosity = Exclude<ResponseTextConfig["verbosity"], null>;
|
|
970
|
+
/** The SDK service-tier union can lag public OpenAI API additions. */
|
|
971
|
+
type OpenAiServiceTier = ResponseCreateParamsBase["service_tier"] | "ultrafast";
|
|
822
972
|
type OpenAIInvokeOptions = Omit<ResponseCreateParamsBase, "model" | "input" | "tools" | "tool_choice" | "stream"> & {
|
|
823
973
|
reasoningEffort?: ResponsesReasoningEffort;
|
|
824
974
|
textVerbosity?: OpenAITextVerbosity;
|
|
825
|
-
serviceTier?:
|
|
975
|
+
serviceTier?: OpenAiServiceTier;
|
|
826
976
|
};
|
|
827
977
|
type OpenAIResponsesWsOptions = NonNullable<ConstructorParameters<typeof ResponsesWS>[1]> & {
|
|
828
978
|
headers?: Record<string, string>;
|
|
@@ -838,7 +988,7 @@ type ChatOpenAIOptions = {
|
|
|
838
988
|
reasoningLevelApplied?: ModelReasoningLevel;
|
|
839
989
|
reasoningFallbackApplied?: boolean;
|
|
840
990
|
textVerbosity?: OpenAITextVerbosity;
|
|
841
|
-
serviceTier?:
|
|
991
|
+
serviceTier?: OpenAiServiceTier;
|
|
842
992
|
websocketMode?: OpenAiWebsocketMode;
|
|
843
993
|
websocketApiVersion?: OpenAiWebsocketApiVersion;
|
|
844
994
|
createResponsesWs?: (client: OpenAI, options?: OpenAIResponsesWsOptions) => OpenAiResponsesWsLike;
|
|
@@ -928,7 +1078,7 @@ declare class ChatOpenRouter implements BaseChatModel<typeof PROVIDER_NAME$2, Op
|
|
|
928
1078
|
}
|
|
929
1079
|
|
|
930
1080
|
declare const PROVIDER_NAME$1: "xai";
|
|
931
|
-
type XaiReasoningEffort = "low" | "medium" | "high";
|
|
1081
|
+
type XaiReasoningEffort = "low" | "medium" | "high" | "xhigh";
|
|
932
1082
|
type XaiInvokeOptions = Omit<ResponseCreateParamsBase, "model" | "input" | "tools" | "tool_choice" | "stream" | "reasoning"> & {
|
|
933
1083
|
reasoningEffort?: XaiReasoningEffort;
|
|
934
1084
|
};
|
|
@@ -959,10 +1109,10 @@ declare class ChatXai implements BaseChatModel<typeof PROVIDER_NAME$1, XaiInvoke
|
|
|
959
1109
|
private debugResponseIfEnabled;
|
|
960
1110
|
}
|
|
961
1111
|
|
|
962
|
-
type ZaiReasoningEffort = "high" | "max";
|
|
1112
|
+
type ZaiReasoningEffort = "low" | "high" | "max";
|
|
963
1113
|
|
|
964
1114
|
declare const PROVIDER_NAME: "zai";
|
|
965
|
-
type ZaiAppliedReasoningLevel = Extract<ModelReasoningLevel, "high" | "xhigh" | "max">;
|
|
1115
|
+
type ZaiAppliedReasoningLevel = Extract<ModelReasoningLevel, "low" | "high" | "xhigh" | "max">;
|
|
966
1116
|
type ZaiInvokeOptions = {
|
|
967
1117
|
max_tokens?: number;
|
|
968
1118
|
temperature?: number;
|
|
@@ -1006,9 +1156,40 @@ declare class ChatZai implements BaseChatModel<typeof PROVIDER_NAME, ZaiInvokeOp
|
|
|
1006
1156
|
declare const ANTHROPIC_DEFAULT_MODEL = "claude-sonnet-4-5";
|
|
1007
1157
|
declare const ANTHROPIC_MODELS: ModelSpec[];
|
|
1008
1158
|
|
|
1159
|
+
declare const DEEPSEEK_DEFAULT_MODEL = "deepseek-flash";
|
|
1160
|
+
declare const DEEPSEEK_MODELS: ({
|
|
1161
|
+
id: string;
|
|
1162
|
+
provider: string;
|
|
1163
|
+
aliases: string[];
|
|
1164
|
+
contextWindow: number;
|
|
1165
|
+
maxInputTokens: number;
|
|
1166
|
+
maxOutputTokens: number;
|
|
1167
|
+
supportsTools: true;
|
|
1168
|
+
supportsReasoning: true;
|
|
1169
|
+
supportsJsonSchema: true;
|
|
1170
|
+
supportsVision: true;
|
|
1171
|
+
supportsFast: false;
|
|
1172
|
+
} | {
|
|
1173
|
+
id: string;
|
|
1174
|
+
provider: string;
|
|
1175
|
+
contextWindow: number;
|
|
1176
|
+
maxInputTokens: number;
|
|
1177
|
+
maxOutputTokens: number;
|
|
1178
|
+
supportsTools: true;
|
|
1179
|
+
supportsReasoning: true;
|
|
1180
|
+
supportsJsonSchema: true;
|
|
1181
|
+
supportsVision: false;
|
|
1182
|
+
supportsFast: false;
|
|
1183
|
+
aliases?: undefined;
|
|
1184
|
+
})[];
|
|
1185
|
+
/** DeepSeek documents medium/xhigh as aliases of high. */
|
|
1186
|
+
declare const resolveDeepSeekEffort: (requested: ModelReasoningLevel) => "low" | "high" | "max";
|
|
1187
|
+
|
|
1188
|
+
declare const GOOGLE_DEFAULT_MODEL = "gemini-3.8-flash";
|
|
1009
1189
|
declare const GOOGLE_MODELS: ModelSpec[];
|
|
1010
1190
|
|
|
1011
1191
|
declare const MOONSHOT_DEFAULT_MODEL = "kimi-k3";
|
|
1192
|
+
declare const MOONSHOT_K3_1_MODELS: Set<string>;
|
|
1012
1193
|
declare const MOONSHOT_MODELS: ModelSpec[];
|
|
1013
1194
|
|
|
1014
1195
|
declare const OPENAI_DEFAULT_MODEL = "gpt-5.6";
|
|
@@ -1034,36 +1215,4 @@ declare class TaskComplete extends Error {
|
|
|
1034
1215
|
constructor(finalMessage?: string);
|
|
1035
1216
|
}
|
|
1036
1217
|
|
|
1037
|
-
type ResponsesInvokeOptions
|
|
1038
|
-
reasoningEffort?: ModelReasoningLevel;
|
|
1039
|
-
maxOutputTokens?: number;
|
|
1040
|
-
text?: ResponseCreateParamsBase["text"];
|
|
1041
|
-
};
|
|
1042
|
-
/** Stateless HTTP Responses transport, independently named and authenticated. */
|
|
1043
|
-
declare class ChatResponses implements BaseChatModel<string, ResponsesInvokeOptions> {
|
|
1044
|
-
readonly provider: string;
|
|
1045
|
-
readonly model: string;
|
|
1046
|
-
readonly retryPolicy: {
|
|
1047
|
-
baseDelayMs?: number | undefined;
|
|
1048
|
-
maxRetries: number;
|
|
1049
|
-
};
|
|
1050
|
-
private readonly client;
|
|
1051
|
-
private readonly endpoint;
|
|
1052
|
-
private readonly reasoningEffort?;
|
|
1053
|
-
private readonly textVerbosity?;
|
|
1054
|
-
constructor(options: {
|
|
1055
|
-
provider: string;
|
|
1056
|
-
model: string;
|
|
1057
|
-
endpoint: ResponsesProviderConfig;
|
|
1058
|
-
apiKey: string;
|
|
1059
|
-
reasoningEffort?: ModelReasoningLevel;
|
|
1060
|
-
textVerbosity?: "low" | "medium" | "high";
|
|
1061
|
-
fetch?: typeof fetch;
|
|
1062
|
-
});
|
|
1063
|
-
readonly classifyFailure: (error: unknown) => ProviderFailure;
|
|
1064
|
-
ainvoke(input: ChatInvokeInput & {
|
|
1065
|
-
options?: ResponsesInvokeOptions;
|
|
1066
|
-
}, context?: ChatInvokeContext): Promise<ChatInvokeCompletion>;
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
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, ChatMoonshot, ChatOpenAI, ChatOpenRouter, ChatResponses, ChatXai, ChatZai, type ContentPart, DEFAULT_MODEL_REGISTRY, type DependencyKey, GOOGLE_MODELS, type ImageTokenEstimate, type ImageTokenInput, type LlmRequestRecord, type LlmResponseRecord, MOONSHOT_DEFAULT_MODEL, MOONSHOT_MODELS, 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 ProviderFailure, type ProviderFailureClassifier, ProviderFailureError, type ProviderFailureKind, type ResolveStorageOptions, type ResponsesInvokeOptions, type RetryDelaySource, 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, ToolPermissionDenied, type ToolPermissionHook, type ToolResult, XAI_DEFAULT_MODEL, XAI_DEFAULT_REASONING_EFFORT, XAI_MODELS, ZAI_DEFAULT_MODEL, ZAI_MODELS, ZAI_REASONING_EFFORT_MODELS, applyModelMetadata, createModelRegistry, defineTool, getDefaultSystemPromptPath, isProviderFailureError, isUsableModelSpec, listModels, registerModels, resolveModel, resolveProviderModelId, stringifyContent, stringifyContentParts, supportsFastMode };
|
|
1218
|
+
export { ANTHROPIC_DEFAULT_MODEL, ANTHROPIC_MODELS, Agent, type AgentEventRecord, type AgentOptions, type AgentRunOptions, type AgentServices, type AgentSession, type BaseChatModel, type BaseMessage, ChatAnthropic, ChatDeepSeek, ChatGoogle, type ChatInvokeContext, type ChatInvokeInput, ChatMoonshot, ChatOpenAI, ChatOpenRouter, ChatResponses, type ChatStreamDelta, type ChatStreamDeltaSink, ChatXai, ChatZai, type ConversationMessage, type ConversationSearchResult, DEEPSEEK_DEFAULT_MODEL, DEEPSEEK_MODELS, DEFAULT_MODEL_REGISTRY, type DependencyKey, GOOGLE_DEFAULT_MODEL, GOOGLE_MODELS, type ImageTokenEstimate, type ImageTokenInput, type LlmRequestRecord, type LlmResponseRecord, type LlmUsageRecord, MOONSHOT_DEFAULT_MODEL, MOONSHOT_K3_1_MODELS, MOONSHOT_MODELS, 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 PolledMessage, type ProviderFailure, type ProviderFailureClassifier, ProviderFailureError, type ProviderFailureKind, type ResolveStorageOptions, type ResponsesInvokeOptions, type RetryDelaySource, 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, ToolPermissionDenied, type ToolPermissionHook, type ToolResult, XAI_DEFAULT_MODEL, XAI_DEFAULT_REASONING_EFFORT, XAI_MODELS, ZAI_DEFAULT_MODEL, ZAI_MODELS, ZAI_REASONING_EFFORT_MODELS, applyModelMetadata, createModelRegistry, createProviderResponseError, defineTool, getDefaultSystemPromptPath, isProviderFailureError, isUsableModelSpec, listModels, registerModels, resolveDeepSeekEffort, resolveModel, resolveProviderModelId, stringifyContent, stringifyContentParts, supportsFastMode };
|