@codelia/core 0.1.81 → 0.1.82
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 +1247 -175
- package/dist/index.d.ts +80 -17
- package/dist/index.js +1242 -171
- package/package.json +4 -3
- package/prompts/system.md +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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';
|
|
1
4
|
import { JSONSchema7 } from 'json-schema';
|
|
2
|
-
import { ProviderName, AgentEvent, SessionStateSummary as SessionStateSummary$1, ModelReasoningLevel } from '@codelia/shared-types';
|
|
3
|
-
export { AgentEvent, FinalResponseEvent, LlmRetryEvent, ReasoningEvent, StepCompleteEvent, StepStartEvent, TextEvent, ToolCallEvent, ToolResultEvent } from '@codelia/shared-types';
|
|
4
5
|
import { ZodSchema } from 'zod';
|
|
5
6
|
import { Logger } from 'openai/client';
|
|
6
7
|
import Anthropic from '@anthropic-ai/sdk';
|
|
@@ -9,10 +10,16 @@ import OpenAI, { ClientOptions } from 'openai';
|
|
|
9
10
|
import { ResponsesClientEvent, ResponseCreateParamsBase, ResponseTextConfig } from 'openai/resources/responses/responses';
|
|
10
11
|
import { ResponsesWS } from 'openai/resources/responses/ws';
|
|
11
12
|
import { ReasoningEffort } from 'openai/resources/shared';
|
|
13
|
+
import { ResponsesProviderConfig } from '@codelia/config';
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* Message Content Parts
|
|
15
17
|
*/
|
|
18
|
+
type ImageRefPart = {
|
|
19
|
+
type: "image_ref";
|
|
20
|
+
image_ref: _codelia_shared_types.ImageArtifactRef;
|
|
21
|
+
detail?: "auto" | "low" | "high";
|
|
22
|
+
};
|
|
16
23
|
type TextPart = {
|
|
17
24
|
type: "text";
|
|
18
25
|
text: string;
|
|
@@ -38,7 +45,7 @@ type OtherPart = {
|
|
|
38
45
|
kind: string;
|
|
39
46
|
payload: unknown;
|
|
40
47
|
};
|
|
41
|
-
type ContentPart = TextPart | ImagePart | DocumentPart | OtherPart;
|
|
48
|
+
type ContentPart = TextPart | ImagePart | ImageRefPart | DocumentPart | OtherPart;
|
|
42
49
|
|
|
43
50
|
/**
|
|
44
51
|
* Tool Call
|
|
@@ -159,10 +166,12 @@ type ChatInvokeUsage = {
|
|
|
159
166
|
input_cache_creation_tokens?: number | null;
|
|
160
167
|
input_image_tokens?: number | null;
|
|
161
168
|
output_tokens: number;
|
|
169
|
+
output_reasoning_tokens?: number | null;
|
|
162
170
|
total_tokens: number;
|
|
163
171
|
};
|
|
164
172
|
type ChatInvokeCompletion = {
|
|
165
173
|
messages: BaseMessage[];
|
|
174
|
+
timing?: LlmCallTiming;
|
|
166
175
|
usage?: ChatInvokeUsage | null;
|
|
167
176
|
stop_reason?: string | null;
|
|
168
177
|
provider_meta?: unknown;
|
|
@@ -233,6 +242,7 @@ interface ModelMetadataService {
|
|
|
233
242
|
}
|
|
234
243
|
|
|
235
244
|
type AgentServices = {
|
|
245
|
+
resolveImage?: (ref: _codelia_shared_types.ImageArtifactRef, signal?: AbortSignal) => Promise<ImagePart>;
|
|
236
246
|
modelMetadata?: ModelMetadataService;
|
|
237
247
|
toolOutputCacheStore?: ToolOutputCacheStore | null;
|
|
238
248
|
monotonicNowMs?: () => number;
|
|
@@ -249,6 +259,7 @@ type ProviderFailure = {
|
|
|
249
259
|
retryable: boolean;
|
|
250
260
|
safeMessage: string;
|
|
251
261
|
status?: number;
|
|
262
|
+
code?: string;
|
|
252
263
|
retryAfterMs?: number;
|
|
253
264
|
delaySource?: Exclude<RetryDelaySource, "backoff">;
|
|
254
265
|
delivery?: "none" | "buffered" | "committed";
|
|
@@ -266,6 +277,24 @@ declare class ProviderFailureError extends Error {
|
|
|
266
277
|
}
|
|
267
278
|
declare const isProviderFailureError: (error: unknown) => error is ProviderFailureError;
|
|
268
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
|
+
|
|
269
298
|
type ChatInvokeInput = {
|
|
270
299
|
messages: BaseMessage[];
|
|
271
300
|
model?: string;
|
|
@@ -275,6 +304,9 @@ type ChatInvokeInput = {
|
|
|
275
304
|
};
|
|
276
305
|
type ChatInvokeContext = {
|
|
277
306
|
sessionKey?: string;
|
|
307
|
+
/** One user turn; distinct from a durable session key. */
|
|
308
|
+
turnKey?: string;
|
|
309
|
+
onProviderStatus?: (event: _codelia_shared_types.LlmStatusEvent) => void;
|
|
278
310
|
};
|
|
279
311
|
interface BaseChatModel<P extends ProviderName = ProviderName, O = unknown> {
|
|
280
312
|
readonly provider: P;
|
|
@@ -283,6 +315,10 @@ interface BaseChatModel<P extends ProviderName = ProviderName, O = unknown> {
|
|
|
283
315
|
options?: O;
|
|
284
316
|
}, context?: ChatInvokeContext): Promise<ChatInvokeCompletion>;
|
|
285
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;
|
|
286
322
|
onHistoryCompacted?(context?: ChatInvokeContext): void | Promise<void>;
|
|
287
323
|
}
|
|
288
324
|
|
|
@@ -302,7 +338,7 @@ type ModelSpec = {
|
|
|
302
338
|
};
|
|
303
339
|
type ModelRegistry = {
|
|
304
340
|
modelsById: Record<string, ModelSpec>;
|
|
305
|
-
aliasesByProvider: Record<
|
|
341
|
+
aliasesByProvider: Record<string, Record<string, string>>;
|
|
306
342
|
};
|
|
307
343
|
declare function createModelRegistry(specs: ModelSpec[]): ModelRegistry;
|
|
308
344
|
declare function registerModels(registry: ModelRegistry, specs: ModelSpec[]): void;
|
|
@@ -459,17 +495,7 @@ type RunStartRecord = {
|
|
|
459
495
|
text: string;
|
|
460
496
|
} | {
|
|
461
497
|
type: "parts";
|
|
462
|
-
parts:
|
|
463
|
-
type: "text";
|
|
464
|
-
text: string;
|
|
465
|
-
} | {
|
|
466
|
-
type: "image_url";
|
|
467
|
-
image_url: {
|
|
468
|
-
url: string;
|
|
469
|
-
detail?: "auto" | "low" | "high";
|
|
470
|
-
media_type?: "image/png" | "image/jpeg" | "image/webp" | "image/gif";
|
|
471
|
-
};
|
|
472
|
-
}>;
|
|
498
|
+
parts: ContentPart[];
|
|
473
499
|
};
|
|
474
500
|
ui_context?: unknown;
|
|
475
501
|
meta?: Record<string, unknown>;
|
|
@@ -527,6 +553,7 @@ type LlmResponseRecord = {
|
|
|
527
553
|
seq: number;
|
|
528
554
|
output: {
|
|
529
555
|
messages: BaseMessage[];
|
|
556
|
+
timing?: LlmCallTiming;
|
|
530
557
|
usage?: ChatInvokeUsage | null;
|
|
531
558
|
stop_reason?: string | null;
|
|
532
559
|
provider_meta?: unknown;
|
|
@@ -552,6 +579,7 @@ type RunErrorRecord = {
|
|
|
552
579
|
provider?: ProviderName;
|
|
553
580
|
kind?: ProviderFailureKind;
|
|
554
581
|
status?: number;
|
|
582
|
+
code?: string;
|
|
555
583
|
attempts?: number;
|
|
556
584
|
max_attempts?: number;
|
|
557
585
|
};
|
|
@@ -647,6 +675,7 @@ declare class Agent {
|
|
|
647
675
|
private readonly llmRetryDependencies;
|
|
648
676
|
private history;
|
|
649
677
|
private usageService;
|
|
678
|
+
private imageUsageBaseline?;
|
|
650
679
|
constructor(options: AgentOptions);
|
|
651
680
|
getUsageSummary(): UsageSummary;
|
|
652
681
|
getContextLeftPercent(): number | null;
|
|
@@ -834,10 +863,13 @@ declare class ChatOpenAI implements BaseChatModel<typeof PROVIDER_NAME$3, OpenAI
|
|
|
834
863
|
private readonly wsStateBySessionKey;
|
|
835
864
|
private readonly wsDisabledUntilBySessionKey;
|
|
836
865
|
private wsReconnectCount;
|
|
866
|
+
private readonly codexTurns;
|
|
837
867
|
constructor(options?: ChatOpenAIOptions);
|
|
838
868
|
ainvoke(input: ChatInvokeInput & {
|
|
839
869
|
options?: OpenAIInvokeOptions;
|
|
840
870
|
}, context?: ChatInvokeContext): Promise<ChatInvokeCompletion>;
|
|
871
|
+
private createCodexMetadata;
|
|
872
|
+
private resolveCodexTurn;
|
|
841
873
|
onHistoryCompacted(context?: ChatInvokeContext): void;
|
|
842
874
|
private invokeWithTransport;
|
|
843
875
|
private invokeHttpTransportWithDebug;
|
|
@@ -846,7 +878,6 @@ declare class ChatOpenAI implements BaseChatModel<typeof PROVIDER_NAME$3, OpenAI
|
|
|
846
878
|
private invokeViaWs;
|
|
847
879
|
private closeWsSafely;
|
|
848
880
|
private closeWsWithoutMaskingPrimaryError;
|
|
849
|
-
private isWsConnectionReuseExpired;
|
|
850
881
|
private isWsReconnectRetryableError;
|
|
851
882
|
private isWsConnectionReusable;
|
|
852
883
|
private extractWsErrorCode;
|
|
@@ -1003,4 +1034,36 @@ declare class TaskComplete extends Error {
|
|
|
1003
1034
|
constructor(finalMessage?: string);
|
|
1004
1035
|
}
|
|
1005
1036
|
|
|
1006
|
-
|
|
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 };
|