@codelia/core 0.1.80 → 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.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<ProviderName, Record<string, string>>;
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;
@@ -406,6 +442,11 @@ type ToolPermissionDecision = {
406
442
  reason?: string;
407
443
  stop_turn?: boolean;
408
444
  };
445
+ /** Carries a permission decision made inside a tool's shared execution gate. */
446
+ declare class ToolPermissionDenied extends Error {
447
+ readonly decision: ToolPermissionDecision;
448
+ constructor(decision: ToolPermissionDecision);
449
+ }
409
450
  type ToolPermissionHook = (call: ToolCall, rawArgs: string, ctx: ToolContext) => Promise<ToolPermissionDecision> | ToolPermissionDecision;
410
451
 
411
452
  type SessionHeader = {
@@ -454,17 +495,7 @@ type RunStartRecord = {
454
495
  text: string;
455
496
  } | {
456
497
  type: "parts";
457
- parts: Array<{
458
- type: "text";
459
- text: string;
460
- } | {
461
- type: "image_url";
462
- image_url: {
463
- url: string;
464
- detail?: "auto" | "low" | "high";
465
- media_type?: "image/png" | "image/jpeg" | "image/webp" | "image/gif";
466
- };
467
- }>;
498
+ parts: ContentPart[];
468
499
  };
469
500
  ui_context?: unknown;
470
501
  meta?: Record<string, unknown>;
@@ -522,6 +553,7 @@ type LlmResponseRecord = {
522
553
  seq: number;
523
554
  output: {
524
555
  messages: BaseMessage[];
556
+ timing?: LlmCallTiming;
525
557
  usage?: ChatInvokeUsage | null;
526
558
  stop_reason?: string | null;
527
559
  provider_meta?: unknown;
@@ -547,6 +579,7 @@ type RunErrorRecord = {
547
579
  provider?: ProviderName;
548
580
  kind?: ProviderFailureKind;
549
581
  status?: number;
582
+ code?: string;
550
583
  attempts?: number;
551
584
  max_attempts?: number;
552
585
  };
@@ -596,6 +629,8 @@ type AgentSession = {
596
629
  };
597
630
 
598
631
  type AgentRunOptions = {
632
+ /** Untrusted messages polled only between model/tool batches; never starts a nested run. */
633
+ pollMessages?: () => Promise<string[]>;
599
634
  session?: AgentSession;
600
635
  signal?: AbortSignal;
601
636
  forceCompaction?: boolean;
@@ -640,6 +675,7 @@ declare class Agent {
640
675
  private readonly llmRetryDependencies;
641
676
  private history;
642
677
  private usageService;
678
+ private imageUsageBaseline?;
643
679
  constructor(options: AgentOptions);
644
680
  getUsageSummary(): UsageSummary;
645
681
  getContextLeftPercent(): number | null;
@@ -827,10 +863,13 @@ declare class ChatOpenAI implements BaseChatModel<typeof PROVIDER_NAME$3, OpenAI
827
863
  private readonly wsStateBySessionKey;
828
864
  private readonly wsDisabledUntilBySessionKey;
829
865
  private wsReconnectCount;
866
+ private readonly codexTurns;
830
867
  constructor(options?: ChatOpenAIOptions);
831
868
  ainvoke(input: ChatInvokeInput & {
832
869
  options?: OpenAIInvokeOptions;
833
870
  }, context?: ChatInvokeContext): Promise<ChatInvokeCompletion>;
871
+ private createCodexMetadata;
872
+ private resolveCodexTurn;
834
873
  onHistoryCompacted(context?: ChatInvokeContext): void;
835
874
  private invokeWithTransport;
836
875
  private invokeHttpTransportWithDebug;
@@ -839,7 +878,6 @@ declare class ChatOpenAI implements BaseChatModel<typeof PROVIDER_NAME$3, OpenAI
839
878
  private invokeViaWs;
840
879
  private closeWsSafely;
841
880
  private closeWsWithoutMaskingPrimaryError;
842
- private isWsConnectionReuseExpired;
843
881
  private isWsReconnectRetryableError;
844
882
  private isWsConnectionReusable;
845
883
  private extractWsErrorCode;
@@ -996,4 +1034,36 @@ declare class TaskComplete extends Error {
996
1034
  constructor(finalMessage?: string);
997
1035
  }
998
1036
 
999
- 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, ChatXai, ChatZai, type ContentPart, DEFAULT_MODEL_REGISTRY, type DependencyKey, GOOGLE_MODELS, 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 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, 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 };
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 };