@codelia/core 0.1.71 → 0.1.74

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 CHANGED
@@ -69,47 +69,42 @@ var import_config = require("@codelia/config");
69
69
  var OPENAI_DEFAULT_MODEL = "gpt-5.6";
70
70
  var OPENAI_DEFAULT_REASONING_EFFORT = "medium";
71
71
  var GPT_5_6_CONTEXT_WINDOW = 105e4;
72
- var GPT_5_6_MAX_INPUT_TOKENS = 922e3;
72
+ var GPT_5_6_CAPPED_INPUT_TOKENS = 27e4;
73
+ var GPT_5_6_FULL_INPUT_TOKENS = 922e3;
73
74
  var GPT_5_6_MAX_OUTPUT_TOKENS = 128e3;
74
75
  var GPT_5_4_CAPPED_INPUT_TOKENS = 272e3;
75
- var OPENAI_MODELS = [
76
- {
77
- id: OPENAI_DEFAULT_MODEL,
78
- provider: "openai",
79
- aliases: ["default"]
80
- },
81
- {
82
- id: "gpt-5.6",
83
- provider: "openai",
84
- contextWindow: GPT_5_6_CONTEXT_WINDOW,
85
- maxInputTokens: GPT_5_6_MAX_INPUT_TOKENS,
86
- maxOutputTokens: GPT_5_6_MAX_OUTPUT_TOKENS,
87
- supportsFast: true
88
- },
76
+ var GPT_5_6_PROVIDER_MODELS = [
77
+ "gpt-5.6",
78
+ "gpt-5.6-sol",
79
+ "gpt-5.6-terra",
80
+ "gpt-5.6-luna"
81
+ ];
82
+ var buildGpt56Models = (providerModelId) => [
89
83
  {
90
- id: "gpt-5.6-sol",
84
+ id: providerModelId,
91
85
  provider: "openai",
92
86
  contextWindow: GPT_5_6_CONTEXT_WINDOW,
93
- maxInputTokens: GPT_5_6_MAX_INPUT_TOKENS,
87
+ maxInputTokens: GPT_5_6_CAPPED_INPUT_TOKENS,
94
88
  maxOutputTokens: GPT_5_6_MAX_OUTPUT_TOKENS,
95
89
  supportsFast: true
96
90
  },
97
91
  {
98
- id: "gpt-5.6-terra",
92
+ id: `${providerModelId}-1M`,
99
93
  provider: "openai",
94
+ providerModelId,
95
+ aliases: [`${providerModelId}-1m`, `${providerModelId}-full`],
100
96
  contextWindow: GPT_5_6_CONTEXT_WINDOW,
101
- maxInputTokens: GPT_5_6_MAX_INPUT_TOKENS,
102
- maxOutputTokens: GPT_5_6_MAX_OUTPUT_TOKENS,
103
- supportsFast: true
104
- },
97
+ maxInputTokens: GPT_5_6_FULL_INPUT_TOKENS,
98
+ maxOutputTokens: GPT_5_6_MAX_OUTPUT_TOKENS
99
+ }
100
+ ];
101
+ var OPENAI_MODELS = [
105
102
  {
106
- id: "gpt-5.6-luna",
103
+ id: OPENAI_DEFAULT_MODEL,
107
104
  provider: "openai",
108
- contextWindow: GPT_5_6_CONTEXT_WINDOW,
109
- maxInputTokens: GPT_5_6_MAX_INPUT_TOKENS,
110
- maxOutputTokens: GPT_5_6_MAX_OUTPUT_TOKENS,
111
- supportsFast: true
105
+ aliases: ["default"]
112
106
  },
107
+ ...GPT_5_6_PROVIDER_MODELS.flatMap(buildGpt56Models),
113
108
  {
114
109
  id: "gpt-5.5",
115
110
  provider: "openai",
@@ -333,6 +328,9 @@ var stringifyContent = (content, options = {}) => {
333
328
  return stringifyContentParts(content, options);
334
329
  };
335
330
 
331
+ // src/agent/agent.ts
332
+ var import_node_perf_hooks = require("perf_hooks");
333
+
336
334
  // src/history/store.ts
337
335
  var MessageHistoryAdapter = class {
338
336
  messages = [];
@@ -1217,6 +1215,8 @@ var TaskComplete = class extends Error {
1217
1215
 
1218
1216
  // src/agent/agent.ts
1219
1217
  var DEFAULT_MAX_ITERATIONS = 200;
1218
+ var defaultMonotonicNowMs = () => import_node_perf_hooks.performance.now();
1219
+ var elapsedMilliseconds = (startedAt, monotonicNowMs) => Math.max(0, Math.round(monotonicNowMs() - startedAt));
1220
1220
  function toolResultToContent(result) {
1221
1221
  if (result.type === "text") return result.text;
1222
1222
  if (result.type === "parts") return result.parts;
@@ -1367,6 +1367,7 @@ var Agent = class {
1367
1367
  services;
1368
1368
  modelRegistry;
1369
1369
  canExecuteTool;
1370
+ monotonicNowMs;
1370
1371
  //private readonly dependencyOverrides?: DependencyOverrides;
1371
1372
  history;
1372
1373
  usageService;
@@ -1380,6 +1381,7 @@ var Agent = class {
1380
1381
  this.toolChoice = options.toolChoice ?? void 0;
1381
1382
  this.requireDoneTool = options.requireDoneTool ?? false;
1382
1383
  this.services = options.services ?? {};
1384
+ this.monotonicNowMs = this.services.monotonicNowMs ?? defaultMonotonicNowMs;
1383
1385
  this.modelRegistry = options.modelRegistry ?? DEFAULT_MODEL_REGISTRY;
1384
1386
  this.compactionService = options.compaction === null ? null : new CompactionService(options.compaction ?? {}, {
1385
1387
  modelRegistry: this.modelRegistry
@@ -1704,7 +1706,7 @@ var Agent = class {
1704
1706
  tool_call_id: toolCall.id
1705
1707
  };
1706
1708
  yield toolCallEvent;
1707
- const startTime = Date.now();
1709
+ const monotonicStartedAt = this.monotonicNowMs();
1708
1710
  try {
1709
1711
  throwIfAborted(signal);
1710
1712
  const execution = await this.executeToolCall(
@@ -1741,7 +1743,10 @@ var Agent = class {
1741
1743
  is_error: processedMessage.is_error
1742
1744
  };
1743
1745
  yield toolResultEvent;
1744
- const durationMs = Date.now() - startTime;
1746
+ const durationMs = elapsedMilliseconds(
1747
+ monotonicStartedAt,
1748
+ this.monotonicNowMs
1749
+ );
1745
1750
  const stepCompleteEvent = {
1746
1751
  type: "step_complete",
1747
1752
  step_id: toolCall.id,
@@ -1796,7 +1801,10 @@ var Agent = class {
1796
1801
  is_error: true
1797
1802
  };
1798
1803
  yield toolResultEvent;
1799
- const durationMs = Date.now() - startTime;
1804
+ const durationMs = elapsedMilliseconds(
1805
+ monotonicStartedAt,
1806
+ this.monotonicNowMs
1807
+ );
1800
1808
  const stepCompleteEvent = {
1801
1809
  type: "step_complete",
1802
1810
  step_id: toolCall.id,
@@ -2574,7 +2582,10 @@ var ChatAnthropic = class {
2574
2582
  const response = this.fastMode ? await this.client.beta.messages.create(
2575
2583
  request,
2576
2584
  requestOptions
2577
- ) : await this.client.messages.create(request, requestOptions);
2585
+ ) : await this.client.messages.create(
2586
+ request,
2587
+ requestOptions
2588
+ );
2578
2589
  await this.debugResponseIfEnabled(response, debugSeq);
2579
2590
  return toChatInvokeCompletion(response, {
2580
2591
  reasoning_requested: this.reasoningLevelMeta.requested,
@@ -3257,6 +3268,9 @@ var invokeOpenAiHttp = async (client, request, signal, sessionIdHeader, onEvent)
3257
3268
  return stream.finalResponse();
3258
3269
  };
3259
3270
 
3271
+ // src/llm/openai/responses-reasoning.ts
3272
+ var toSdkReasoningEffort = (effort) => effort;
3273
+
3260
3274
  // src/llm/openai/serializer.ts
3261
3275
  var toOpenAiOtherPart = (kind, payload) => ({
3262
3276
  type: "other",
@@ -4483,7 +4497,10 @@ var ChatOpenAI = class {
4483
4497
  }
4484
4498
  request.include = Array.from(includeSet);
4485
4499
  const effort = reasoningEffort ?? this.defaultReasoningEffort;
4486
- request.reasoning = { effort, summary: DEFAULT_REASONING_SUMMARY };
4500
+ request.reasoning = {
4501
+ effort: toSdkReasoningEffort(effort),
4502
+ summary: DEFAULT_REASONING_SUMMARY
4503
+ };
4487
4504
  const verbosity = textVerbosity ?? this.defaultTextVerbosity;
4488
4505
  if (verbosity) {
4489
4506
  request.text = {
@@ -5484,7 +5501,10 @@ var ChatOpenRouter = class {
5484
5501
  }
5485
5502
  request.include = Array.from(includeSet);
5486
5503
  const effort = reasoningEffort ?? this.defaultReasoningEffort;
5487
- request.reasoning = { effort, summary: DEFAULT_REASONING_SUMMARY2 };
5504
+ request.reasoning = {
5505
+ effort: toSdkReasoningEffort(effort),
5506
+ summary: DEFAULT_REASONING_SUMMARY2
5507
+ };
5488
5508
  const verbosity = textVerbosity ?? this.defaultTextVerbosity;
5489
5509
  if (verbosity) {
5490
5510
  request.text = {
@@ -5657,10 +5677,6 @@ function toZaiTools(tools) {
5657
5677
  parameters: tool.parameters
5658
5678
  }
5659
5679
  });
5660
- continue;
5661
- }
5662
- if (isHostedSearchToolDefinition(tool)) {
5663
- continue;
5664
5680
  }
5665
5681
  }
5666
5682
  return mapped.length ? mapped : void 0;
@@ -6157,62 +6173,103 @@ var getDefaultSystemPromptPath = () => promptPath;
6157
6173
 
6158
6174
  // src/tools/define.ts
6159
6175
  var import_zod = require("zod");
6160
- var mapSchema = (schema, transform) => {
6161
- if (!schema || typeof schema !== "object") return schema;
6162
- const next = transform({ ...schema });
6163
- if (next.properties) {
6164
- const updated = {};
6165
- for (const [key, value] of Object.entries(next.properties)) {
6166
- updated[key] = mapSchema(value, transform);
6176
+ var schemaAllowsNull = (schema) => {
6177
+ if (schema.type === "null") return true;
6178
+ if (Array.isArray(schema.type) && schema.type.includes("null")) return true;
6179
+ return [...schema.anyOf ?? [], ...schema.oneOf ?? []].some(
6180
+ (variant) => variant !== true && variant !== false && schemaAllowsNull(variant)
6181
+ );
6182
+ };
6183
+ var withOptionalNullHint = (description) => {
6184
+ const hint = "Pass null to omit this optional value and use its default behavior.";
6185
+ if (!description) return hint;
6186
+ return description.includes(hint) ? description : `${description} ${hint}`;
6187
+ };
6188
+ var nullableOptionalProperty = (schema) => {
6189
+ if (schemaAllowsNull(schema)) {
6190
+ return { ...schema, description: withOptionalNullHint(schema.description) };
6191
+ }
6192
+ const { description, ...inner } = schema;
6193
+ return {
6194
+ description: withOptionalNullHint(description),
6195
+ anyOf: [inner, { type: "null" }]
6196
+ };
6197
+ };
6198
+ var toStrictToolSchema = (schema) => {
6199
+ const originalRequired = new Set(schema.required ?? []);
6200
+ const next = { ...schema };
6201
+ if (next.type === "object") {
6202
+ next.additionalProperties ??= false;
6203
+ if (next.properties) {
6204
+ const properties = {};
6205
+ for (const [key, property] of Object.entries(next.properties)) {
6206
+ const normalized = toStrictToolSchema(property);
6207
+ properties[key] = originalRequired.has(key) ? normalized : nullableOptionalProperty(normalized);
6208
+ }
6209
+ next.properties = properties;
6210
+ const propertyKeys = Object.keys(properties);
6211
+ if (propertyKeys.length > 0) next.required = propertyKeys;
6167
6212
  }
6168
- next.properties = updated;
6169
6213
  }
6170
6214
  if (next.items) {
6171
- if (Array.isArray(next.items)) {
6172
- next.items = next.items.map(
6173
- (item) => mapSchema(item, transform)
6174
- );
6175
- } else {
6176
- next.items = mapSchema(next.items, transform);
6177
- }
6215
+ next.items = Array.isArray(next.items) ? next.items.map((item) => toStrictToolSchema(item)) : toStrictToolSchema(next.items);
6178
6216
  }
6179
6217
  if (next.anyOf) {
6180
6218
  next.anyOf = next.anyOf.map(
6181
- (item) => mapSchema(item, transform)
6219
+ (item) => item === true || item === false ? item : toStrictToolSchema(item)
6182
6220
  );
6183
6221
  }
6184
6222
  if (next.oneOf) {
6185
6223
  next.oneOf = next.oneOf.map(
6186
- (item) => mapSchema(item, transform)
6224
+ (item) => item === true || item === false ? item : toStrictToolSchema(item)
6187
6225
  );
6188
6226
  }
6189
6227
  if (next.allOf) {
6190
6228
  next.allOf = next.allOf.map(
6191
- (item) => mapSchema(item, transform)
6229
+ (item) => item === true || item === false ? item : toStrictToolSchema(item)
6192
6230
  );
6193
6231
  }
6194
6232
  if (next.not) {
6195
- next.not = mapSchema(next.not, transform);
6233
+ next.not = toStrictToolSchema(next.not);
6234
+ }
6235
+ if (next.additionalProperties && next.additionalProperties !== true) {
6236
+ next.additionalProperties = toStrictToolSchema(
6237
+ next.additionalProperties
6238
+ );
6196
6239
  }
6197
6240
  return next;
6198
6241
  };
6199
- var withNoAdditionalProperties = (schema) => mapSchema(schema, (next) => {
6200
- if (next.type === "object" && next.additionalProperties === void 0) {
6201
- next.additionalProperties = false;
6242
+ var normalizeOptionalNulls = (value, schema) => {
6243
+ if (Array.isArray(value) && schema.items && !Array.isArray(schema.items)) {
6244
+ return value.map(
6245
+ (item) => normalizeOptionalNulls(item, schema.items)
6246
+ );
6202
6247
  }
6203
- return next;
6204
- });
6205
- var withRequiredProperties = (schema) => mapSchema(schema, (next) => {
6206
- if (next.type === "object" && next.properties) {
6207
- const propertyKeys = Object.keys(next.properties);
6208
- if (propertyKeys.length > 0) {
6209
- next.required = Array.from(
6210
- /* @__PURE__ */ new Set([...next.required ?? [], ...propertyKeys])
6248
+ if (!value || typeof value !== "object" || Array.isArray(value)) return value;
6249
+ const normalized = { ...value };
6250
+ if (schema.type === "object" && schema.properties) {
6251
+ const required = new Set(schema.required ?? []);
6252
+ for (const [key, property] of Object.entries(schema.properties)) {
6253
+ if (!(key in normalized)) continue;
6254
+ if (normalized[key] === null && !required.has(key)) {
6255
+ delete normalized[key];
6256
+ continue;
6257
+ }
6258
+ normalized[key] = normalizeOptionalNulls(
6259
+ normalized[key],
6260
+ property
6211
6261
  );
6212
6262
  }
6213
6263
  }
6214
- return next;
6215
- });
6264
+ for (const variant of [...schema.anyOf ?? [], ...schema.oneOf ?? []]) {
6265
+ if (variant === true || variant === false) continue;
6266
+ Object.assign(
6267
+ normalized,
6268
+ normalizeOptionalNulls(normalized, variant)
6269
+ );
6270
+ }
6271
+ return normalized;
6272
+ };
6216
6273
  var withTopLevelObjectTypeForObjectUnions = (schema) => {
6217
6274
  if (schema.type !== void 0) return schema;
6218
6275
  const variants = (Array.isArray(schema.anyOf) && schema.anyOf.length > 0 ? schema.anyOf : Array.isArray(schema.oneOf) && schema.oneOf.length > 0 ? schema.oneOf : null) ?? null;
@@ -6238,7 +6295,7 @@ function defineTool(toolOptions) {
6238
6295
  io: "input"
6239
6296
  });
6240
6297
  const strictParameters = withTopLevelObjectTypeForObjectUnions(
6241
- withRequiredProperties(withNoAdditionalProperties(parameters))
6298
+ toStrictToolSchema(parameters)
6242
6299
  );
6243
6300
  return {
6244
6301
  name: toolOptions.name,
@@ -6258,7 +6315,9 @@ function defineTool(toolOptions) {
6258
6315
  `Invalid tool arguments JSON for ${toolOptions.name}: ${String(error)}`
6259
6316
  );
6260
6317
  }
6261
- const parsed = toolOptions.input.safeParse(rawArgs);
6318
+ const parsed = toolOptions.input.safeParse(
6319
+ normalizeOptionalNulls(rawArgs, parameters)
6320
+ );
6262
6321
  if (!parsed.success) {
6263
6322
  throw new Error(
6264
6323
  `Tool input validation failed for ${toolOptions.name}: ${parsed.error.message}`
package/dist/index.d.cts CHANGED
@@ -4,7 +4,7 @@ import { Logger } from 'openai/client';
4
4
  import { AgentEvent, SessionStateSummary as SessionStateSummary$1, ModelReasoningLevel } from '@codelia/shared-types';
5
5
  export { AgentEvent, FinalResponseEvent, ReasoningEvent, StepCompleteEvent, StepStartEvent, TextEvent, ToolCallEvent, ToolResultEvent } from '@codelia/shared-types';
6
6
  import Anthropic from '@anthropic-ai/sdk';
7
- import { MessageCreateParamsNonStreaming } from '@anthropic-ai/sdk/resources/messages/messages';
7
+ import { MessageCreateParamsNonStreaming, OutputConfig } from '@anthropic-ai/sdk/resources/messages/messages';
8
8
  import OpenAI, { ClientOptions } from 'openai';
9
9
  import { ResponsesClientEvent, ResponseCreateParamsBase, ResponseTextConfig } from 'openai/resources/responses/responses';
10
10
  import { ResponsesWS } from 'openai/resources/responses/ws';
@@ -221,6 +221,7 @@ interface ModelMetadataService {
221
221
  type AgentServices = {
222
222
  modelMetadata?: ModelMetadataService;
223
223
  toolOutputCacheStore?: ToolOutputCacheStore | null;
224
+ monotonicNowMs?: () => number;
224
225
  };
225
226
 
226
227
  type ProviderName = "openai" | "anthropic" | "openrouter" | "google" | "zai";
@@ -586,6 +587,7 @@ declare class Agent {
586
587
  private readonly services;
587
588
  private readonly modelRegistry;
588
589
  private readonly canExecuteTool?;
590
+ private readonly monotonicNowMs;
589
591
  private history;
590
592
  private usageService;
591
593
  constructor(options: AgentOptions);
@@ -638,7 +640,12 @@ interface StoragePathService {
638
640
  }
639
641
 
640
642
  declare const PROVIDER_NAME$3: "anthropic";
641
- type AnthropicMessageCreateParams = MessageCreateParamsNonStreaming & {
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;
642
649
  speed?: "standard" | "fast" | null;
643
650
  betas?: string[];
644
651
  };
@@ -674,6 +681,12 @@ declare class ChatAnthropic implements BaseChatModel<typeof PROVIDER_NAME$3, Ant
674
681
  private debugResponseIfEnabled;
675
682
  }
676
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
+
677
690
  type OpenAiWebsocketMode = "off" | "auto" | "on";
678
691
  type OpenAiWebsocketApiVersion = "v1" | "v2";
679
692
  type OpenAiResponsesWsLike = {
@@ -689,7 +702,7 @@ type OpenAiResponsesWsLike = {
689
702
  declare const PROVIDER_NAME$2: "openai";
690
703
  type OpenAITextVerbosity = Exclude<ResponseTextConfig["verbosity"], null>;
691
704
  type OpenAIInvokeOptions = Omit<ResponseCreateParamsBase, "model" | "input" | "tools" | "tool_choice" | "stream"> & {
692
- reasoningEffort?: ReasoningEffort;
705
+ reasoningEffort?: ResponsesReasoningEffort;
693
706
  textVerbosity?: OpenAITextVerbosity;
694
707
  serviceTier?: ResponseCreateParamsBase["service_tier"];
695
708
  };
@@ -702,7 +715,7 @@ type ChatOpenAIOptions = {
702
715
  clientOptions?: ClientOptions;
703
716
  model?: string;
704
717
  providerModel?: string;
705
- reasoningEffort?: ReasoningEffort;
718
+ reasoningEffort?: ResponsesReasoningEffort;
706
719
  reasoningLevelRequested?: ModelReasoningLevel;
707
720
  reasoningLevelApplied?: ModelReasoningLevel;
708
721
  reasoningFallbackApplied?: boolean;
@@ -761,14 +774,14 @@ declare class ChatOpenAI implements BaseChatModel<typeof PROVIDER_NAME$2, OpenAI
761
774
  declare const PROVIDER_NAME$1: "openrouter";
762
775
  type OpenRouterTextVerbosity = Exclude<ResponseTextConfig["verbosity"], null>;
763
776
  type OpenRouterInvokeOptions = Omit<ResponseCreateParamsBase, "model" | "input" | "tools" | "tool_choice" | "stream"> & {
764
- reasoningEffort?: ReasoningEffort;
777
+ reasoningEffort?: ResponsesReasoningEffort;
765
778
  textVerbosity?: OpenRouterTextVerbosity;
766
779
  };
767
780
  type ChatOpenRouterOptions = {
768
781
  client?: OpenAI;
769
782
  clientOptions?: ClientOptions;
770
783
  model?: string;
771
- reasoningEffort?: ReasoningEffort;
784
+ reasoningEffort?: ResponsesReasoningEffort;
772
785
  reasoningLevelRequested?: ModelReasoningLevel;
773
786
  reasoningLevelApplied?: ModelReasoningLevel;
774
787
  reasoningFallbackApplied?: boolean;
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import { Logger } from 'openai/client';
4
4
  import { AgentEvent, SessionStateSummary as SessionStateSummary$1, ModelReasoningLevel } from '@codelia/shared-types';
5
5
  export { AgentEvent, FinalResponseEvent, ReasoningEvent, StepCompleteEvent, StepStartEvent, TextEvent, ToolCallEvent, ToolResultEvent } from '@codelia/shared-types';
6
6
  import Anthropic from '@anthropic-ai/sdk';
7
- import { MessageCreateParamsNonStreaming } from '@anthropic-ai/sdk/resources/messages/messages';
7
+ import { MessageCreateParamsNonStreaming, OutputConfig } from '@anthropic-ai/sdk/resources/messages/messages';
8
8
  import OpenAI, { ClientOptions } from 'openai';
9
9
  import { ResponsesClientEvent, ResponseCreateParamsBase, ResponseTextConfig } from 'openai/resources/responses/responses';
10
10
  import { ResponsesWS } from 'openai/resources/responses/ws';
@@ -221,6 +221,7 @@ interface ModelMetadataService {
221
221
  type AgentServices = {
222
222
  modelMetadata?: ModelMetadataService;
223
223
  toolOutputCacheStore?: ToolOutputCacheStore | null;
224
+ monotonicNowMs?: () => number;
224
225
  };
225
226
 
226
227
  type ProviderName = "openai" | "anthropic" | "openrouter" | "google" | "zai";
@@ -586,6 +587,7 @@ declare class Agent {
586
587
  private readonly services;
587
588
  private readonly modelRegistry;
588
589
  private readonly canExecuteTool?;
590
+ private readonly monotonicNowMs;
589
591
  private history;
590
592
  private usageService;
591
593
  constructor(options: AgentOptions);
@@ -638,7 +640,12 @@ interface StoragePathService {
638
640
  }
639
641
 
640
642
  declare const PROVIDER_NAME$3: "anthropic";
641
- type AnthropicMessageCreateParams = MessageCreateParamsNonStreaming & {
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;
642
649
  speed?: "standard" | "fast" | null;
643
650
  betas?: string[];
644
651
  };
@@ -674,6 +681,12 @@ declare class ChatAnthropic implements BaseChatModel<typeof PROVIDER_NAME$3, Ant
674
681
  private debugResponseIfEnabled;
675
682
  }
676
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
+
677
690
  type OpenAiWebsocketMode = "off" | "auto" | "on";
678
691
  type OpenAiWebsocketApiVersion = "v1" | "v2";
679
692
  type OpenAiResponsesWsLike = {
@@ -689,7 +702,7 @@ type OpenAiResponsesWsLike = {
689
702
  declare const PROVIDER_NAME$2: "openai";
690
703
  type OpenAITextVerbosity = Exclude<ResponseTextConfig["verbosity"], null>;
691
704
  type OpenAIInvokeOptions = Omit<ResponseCreateParamsBase, "model" | "input" | "tools" | "tool_choice" | "stream"> & {
692
- reasoningEffort?: ReasoningEffort;
705
+ reasoningEffort?: ResponsesReasoningEffort;
693
706
  textVerbosity?: OpenAITextVerbosity;
694
707
  serviceTier?: ResponseCreateParamsBase["service_tier"];
695
708
  };
@@ -702,7 +715,7 @@ type ChatOpenAIOptions = {
702
715
  clientOptions?: ClientOptions;
703
716
  model?: string;
704
717
  providerModel?: string;
705
- reasoningEffort?: ReasoningEffort;
718
+ reasoningEffort?: ResponsesReasoningEffort;
706
719
  reasoningLevelRequested?: ModelReasoningLevel;
707
720
  reasoningLevelApplied?: ModelReasoningLevel;
708
721
  reasoningFallbackApplied?: boolean;
@@ -761,14 +774,14 @@ declare class ChatOpenAI implements BaseChatModel<typeof PROVIDER_NAME$2, OpenAI
761
774
  declare const PROVIDER_NAME$1: "openrouter";
762
775
  type OpenRouterTextVerbosity = Exclude<ResponseTextConfig["verbosity"], null>;
763
776
  type OpenRouterInvokeOptions = Omit<ResponseCreateParamsBase, "model" | "input" | "tools" | "tool_choice" | "stream"> & {
764
- reasoningEffort?: ReasoningEffort;
777
+ reasoningEffort?: ResponsesReasoningEffort;
765
778
  textVerbosity?: OpenRouterTextVerbosity;
766
779
  };
767
780
  type ChatOpenRouterOptions = {
768
781
  client?: OpenAI;
769
782
  clientOptions?: ClientOptions;
770
783
  model?: string;
771
- reasoningEffort?: ReasoningEffort;
784
+ reasoningEffort?: ResponsesReasoningEffort;
772
785
  reasoningLevelRequested?: ModelReasoningLevel;
773
786
  reasoningLevelApplied?: ModelReasoningLevel;
774
787
  reasoningFallbackApplied?: boolean;
package/dist/index.js CHANGED
@@ -5,47 +5,42 @@ import { configRegistry } from "@codelia/config";
5
5
  var OPENAI_DEFAULT_MODEL = "gpt-5.6";
6
6
  var OPENAI_DEFAULT_REASONING_EFFORT = "medium";
7
7
  var GPT_5_6_CONTEXT_WINDOW = 105e4;
8
- var GPT_5_6_MAX_INPUT_TOKENS = 922e3;
8
+ var GPT_5_6_CAPPED_INPUT_TOKENS = 27e4;
9
+ var GPT_5_6_FULL_INPUT_TOKENS = 922e3;
9
10
  var GPT_5_6_MAX_OUTPUT_TOKENS = 128e3;
10
11
  var GPT_5_4_CAPPED_INPUT_TOKENS = 272e3;
11
- var OPENAI_MODELS = [
12
- {
13
- id: OPENAI_DEFAULT_MODEL,
14
- provider: "openai",
15
- aliases: ["default"]
16
- },
17
- {
18
- id: "gpt-5.6",
19
- provider: "openai",
20
- contextWindow: GPT_5_6_CONTEXT_WINDOW,
21
- maxInputTokens: GPT_5_6_MAX_INPUT_TOKENS,
22
- maxOutputTokens: GPT_5_6_MAX_OUTPUT_TOKENS,
23
- supportsFast: true
24
- },
12
+ var GPT_5_6_PROVIDER_MODELS = [
13
+ "gpt-5.6",
14
+ "gpt-5.6-sol",
15
+ "gpt-5.6-terra",
16
+ "gpt-5.6-luna"
17
+ ];
18
+ var buildGpt56Models = (providerModelId) => [
25
19
  {
26
- id: "gpt-5.6-sol",
20
+ id: providerModelId,
27
21
  provider: "openai",
28
22
  contextWindow: GPT_5_6_CONTEXT_WINDOW,
29
- maxInputTokens: GPT_5_6_MAX_INPUT_TOKENS,
23
+ maxInputTokens: GPT_5_6_CAPPED_INPUT_TOKENS,
30
24
  maxOutputTokens: GPT_5_6_MAX_OUTPUT_TOKENS,
31
25
  supportsFast: true
32
26
  },
33
27
  {
34
- id: "gpt-5.6-terra",
28
+ id: `${providerModelId}-1M`,
35
29
  provider: "openai",
30
+ providerModelId,
31
+ aliases: [`${providerModelId}-1m`, `${providerModelId}-full`],
36
32
  contextWindow: GPT_5_6_CONTEXT_WINDOW,
37
- maxInputTokens: GPT_5_6_MAX_INPUT_TOKENS,
38
- maxOutputTokens: GPT_5_6_MAX_OUTPUT_TOKENS,
39
- supportsFast: true
40
- },
33
+ maxInputTokens: GPT_5_6_FULL_INPUT_TOKENS,
34
+ maxOutputTokens: GPT_5_6_MAX_OUTPUT_TOKENS
35
+ }
36
+ ];
37
+ var OPENAI_MODELS = [
41
38
  {
42
- id: "gpt-5.6-luna",
39
+ id: OPENAI_DEFAULT_MODEL,
43
40
  provider: "openai",
44
- contextWindow: GPT_5_6_CONTEXT_WINDOW,
45
- maxInputTokens: GPT_5_6_MAX_INPUT_TOKENS,
46
- maxOutputTokens: GPT_5_6_MAX_OUTPUT_TOKENS,
47
- supportsFast: true
41
+ aliases: ["default"]
48
42
  },
43
+ ...GPT_5_6_PROVIDER_MODELS.flatMap(buildGpt56Models),
49
44
  {
50
45
  id: "gpt-5.5",
51
46
  provider: "openai",
@@ -269,6 +264,9 @@ var stringifyContent = (content, options = {}) => {
269
264
  return stringifyContentParts(content, options);
270
265
  };
271
266
 
267
+ // src/agent/agent.ts
268
+ import { performance } from "perf_hooks";
269
+
272
270
  // src/history/store.ts
273
271
  var MessageHistoryAdapter = class {
274
272
  messages = [];
@@ -1153,6 +1151,8 @@ var TaskComplete = class extends Error {
1153
1151
 
1154
1152
  // src/agent/agent.ts
1155
1153
  var DEFAULT_MAX_ITERATIONS = 200;
1154
+ var defaultMonotonicNowMs = () => performance.now();
1155
+ var elapsedMilliseconds = (startedAt, monotonicNowMs) => Math.max(0, Math.round(monotonicNowMs() - startedAt));
1156
1156
  function toolResultToContent(result) {
1157
1157
  if (result.type === "text") return result.text;
1158
1158
  if (result.type === "parts") return result.parts;
@@ -1303,6 +1303,7 @@ var Agent = class {
1303
1303
  services;
1304
1304
  modelRegistry;
1305
1305
  canExecuteTool;
1306
+ monotonicNowMs;
1306
1307
  //private readonly dependencyOverrides?: DependencyOverrides;
1307
1308
  history;
1308
1309
  usageService;
@@ -1316,6 +1317,7 @@ var Agent = class {
1316
1317
  this.toolChoice = options.toolChoice ?? void 0;
1317
1318
  this.requireDoneTool = options.requireDoneTool ?? false;
1318
1319
  this.services = options.services ?? {};
1320
+ this.monotonicNowMs = this.services.monotonicNowMs ?? defaultMonotonicNowMs;
1319
1321
  this.modelRegistry = options.modelRegistry ?? DEFAULT_MODEL_REGISTRY;
1320
1322
  this.compactionService = options.compaction === null ? null : new CompactionService(options.compaction ?? {}, {
1321
1323
  modelRegistry: this.modelRegistry
@@ -1640,7 +1642,7 @@ var Agent = class {
1640
1642
  tool_call_id: toolCall.id
1641
1643
  };
1642
1644
  yield toolCallEvent;
1643
- const startTime = Date.now();
1645
+ const monotonicStartedAt = this.monotonicNowMs();
1644
1646
  try {
1645
1647
  throwIfAborted(signal);
1646
1648
  const execution = await this.executeToolCall(
@@ -1677,7 +1679,10 @@ var Agent = class {
1677
1679
  is_error: processedMessage.is_error
1678
1680
  };
1679
1681
  yield toolResultEvent;
1680
- const durationMs = Date.now() - startTime;
1682
+ const durationMs = elapsedMilliseconds(
1683
+ monotonicStartedAt,
1684
+ this.monotonicNowMs
1685
+ );
1681
1686
  const stepCompleteEvent = {
1682
1687
  type: "step_complete",
1683
1688
  step_id: toolCall.id,
@@ -1732,7 +1737,10 @@ var Agent = class {
1732
1737
  is_error: true
1733
1738
  };
1734
1739
  yield toolResultEvent;
1735
- const durationMs = Date.now() - startTime;
1740
+ const durationMs = elapsedMilliseconds(
1741
+ monotonicStartedAt,
1742
+ this.monotonicNowMs
1743
+ );
1736
1744
  const stepCompleteEvent = {
1737
1745
  type: "step_complete",
1738
1746
  step_id: toolCall.id,
@@ -2510,7 +2518,10 @@ var ChatAnthropic = class {
2510
2518
  const response = this.fastMode ? await this.client.beta.messages.create(
2511
2519
  request,
2512
2520
  requestOptions
2513
- ) : await this.client.messages.create(request, requestOptions);
2521
+ ) : await this.client.messages.create(
2522
+ request,
2523
+ requestOptions
2524
+ );
2514
2525
  await this.debugResponseIfEnabled(response, debugSeq);
2515
2526
  return toChatInvokeCompletion(response, {
2516
2527
  reasoning_requested: this.reasoningLevelMeta.requested,
@@ -3193,6 +3204,9 @@ var invokeOpenAiHttp = async (client, request, signal, sessionIdHeader, onEvent)
3193
3204
  return stream.finalResponse();
3194
3205
  };
3195
3206
 
3207
+ // src/llm/openai/responses-reasoning.ts
3208
+ var toSdkReasoningEffort = (effort) => effort;
3209
+
3196
3210
  // src/llm/openai/serializer.ts
3197
3211
  var toOpenAiOtherPart = (kind, payload) => ({
3198
3212
  type: "other",
@@ -4419,7 +4433,10 @@ var ChatOpenAI = class {
4419
4433
  }
4420
4434
  request.include = Array.from(includeSet);
4421
4435
  const effort = reasoningEffort ?? this.defaultReasoningEffort;
4422
- request.reasoning = { effort, summary: DEFAULT_REASONING_SUMMARY };
4436
+ request.reasoning = {
4437
+ effort: toSdkReasoningEffort(effort),
4438
+ summary: DEFAULT_REASONING_SUMMARY
4439
+ };
4423
4440
  const verbosity = textVerbosity ?? this.defaultTextVerbosity;
4424
4441
  if (verbosity) {
4425
4442
  request.text = {
@@ -5420,7 +5437,10 @@ var ChatOpenRouter = class {
5420
5437
  }
5421
5438
  request.include = Array.from(includeSet);
5422
5439
  const effort = reasoningEffort ?? this.defaultReasoningEffort;
5423
- request.reasoning = { effort, summary: DEFAULT_REASONING_SUMMARY2 };
5440
+ request.reasoning = {
5441
+ effort: toSdkReasoningEffort(effort),
5442
+ summary: DEFAULT_REASONING_SUMMARY2
5443
+ };
5424
5444
  const verbosity = textVerbosity ?? this.defaultTextVerbosity;
5425
5445
  if (verbosity) {
5426
5446
  request.text = {
@@ -5593,10 +5613,6 @@ function toZaiTools(tools) {
5593
5613
  parameters: tool.parameters
5594
5614
  }
5595
5615
  });
5596
- continue;
5597
- }
5598
- if (isHostedSearchToolDefinition(tool)) {
5599
- continue;
5600
5616
  }
5601
5617
  }
5602
5618
  return mapped.length ? mapped : void 0;
@@ -6092,62 +6108,103 @@ var getDefaultSystemPromptPath = () => promptPath;
6092
6108
 
6093
6109
  // src/tools/define.ts
6094
6110
  import { toJSONSchema } from "zod";
6095
- var mapSchema = (schema, transform) => {
6096
- if (!schema || typeof schema !== "object") return schema;
6097
- const next = transform({ ...schema });
6098
- if (next.properties) {
6099
- const updated = {};
6100
- for (const [key, value] of Object.entries(next.properties)) {
6101
- updated[key] = mapSchema(value, transform);
6111
+ var schemaAllowsNull = (schema) => {
6112
+ if (schema.type === "null") return true;
6113
+ if (Array.isArray(schema.type) && schema.type.includes("null")) return true;
6114
+ return [...schema.anyOf ?? [], ...schema.oneOf ?? []].some(
6115
+ (variant) => variant !== true && variant !== false && schemaAllowsNull(variant)
6116
+ );
6117
+ };
6118
+ var withOptionalNullHint = (description) => {
6119
+ const hint = "Pass null to omit this optional value and use its default behavior.";
6120
+ if (!description) return hint;
6121
+ return description.includes(hint) ? description : `${description} ${hint}`;
6122
+ };
6123
+ var nullableOptionalProperty = (schema) => {
6124
+ if (schemaAllowsNull(schema)) {
6125
+ return { ...schema, description: withOptionalNullHint(schema.description) };
6126
+ }
6127
+ const { description, ...inner } = schema;
6128
+ return {
6129
+ description: withOptionalNullHint(description),
6130
+ anyOf: [inner, { type: "null" }]
6131
+ };
6132
+ };
6133
+ var toStrictToolSchema = (schema) => {
6134
+ const originalRequired = new Set(schema.required ?? []);
6135
+ const next = { ...schema };
6136
+ if (next.type === "object") {
6137
+ next.additionalProperties ??= false;
6138
+ if (next.properties) {
6139
+ const properties = {};
6140
+ for (const [key, property] of Object.entries(next.properties)) {
6141
+ const normalized = toStrictToolSchema(property);
6142
+ properties[key] = originalRequired.has(key) ? normalized : nullableOptionalProperty(normalized);
6143
+ }
6144
+ next.properties = properties;
6145
+ const propertyKeys = Object.keys(properties);
6146
+ if (propertyKeys.length > 0) next.required = propertyKeys;
6102
6147
  }
6103
- next.properties = updated;
6104
6148
  }
6105
6149
  if (next.items) {
6106
- if (Array.isArray(next.items)) {
6107
- next.items = next.items.map(
6108
- (item) => mapSchema(item, transform)
6109
- );
6110
- } else {
6111
- next.items = mapSchema(next.items, transform);
6112
- }
6150
+ next.items = Array.isArray(next.items) ? next.items.map((item) => toStrictToolSchema(item)) : toStrictToolSchema(next.items);
6113
6151
  }
6114
6152
  if (next.anyOf) {
6115
6153
  next.anyOf = next.anyOf.map(
6116
- (item) => mapSchema(item, transform)
6154
+ (item) => item === true || item === false ? item : toStrictToolSchema(item)
6117
6155
  );
6118
6156
  }
6119
6157
  if (next.oneOf) {
6120
6158
  next.oneOf = next.oneOf.map(
6121
- (item) => mapSchema(item, transform)
6159
+ (item) => item === true || item === false ? item : toStrictToolSchema(item)
6122
6160
  );
6123
6161
  }
6124
6162
  if (next.allOf) {
6125
6163
  next.allOf = next.allOf.map(
6126
- (item) => mapSchema(item, transform)
6164
+ (item) => item === true || item === false ? item : toStrictToolSchema(item)
6127
6165
  );
6128
6166
  }
6129
6167
  if (next.not) {
6130
- next.not = mapSchema(next.not, transform);
6168
+ next.not = toStrictToolSchema(next.not);
6169
+ }
6170
+ if (next.additionalProperties && next.additionalProperties !== true) {
6171
+ next.additionalProperties = toStrictToolSchema(
6172
+ next.additionalProperties
6173
+ );
6131
6174
  }
6132
6175
  return next;
6133
6176
  };
6134
- var withNoAdditionalProperties = (schema) => mapSchema(schema, (next) => {
6135
- if (next.type === "object" && next.additionalProperties === void 0) {
6136
- next.additionalProperties = false;
6177
+ var normalizeOptionalNulls = (value, schema) => {
6178
+ if (Array.isArray(value) && schema.items && !Array.isArray(schema.items)) {
6179
+ return value.map(
6180
+ (item) => normalizeOptionalNulls(item, schema.items)
6181
+ );
6137
6182
  }
6138
- return next;
6139
- });
6140
- var withRequiredProperties = (schema) => mapSchema(schema, (next) => {
6141
- if (next.type === "object" && next.properties) {
6142
- const propertyKeys = Object.keys(next.properties);
6143
- if (propertyKeys.length > 0) {
6144
- next.required = Array.from(
6145
- /* @__PURE__ */ new Set([...next.required ?? [], ...propertyKeys])
6183
+ if (!value || typeof value !== "object" || Array.isArray(value)) return value;
6184
+ const normalized = { ...value };
6185
+ if (schema.type === "object" && schema.properties) {
6186
+ const required = new Set(schema.required ?? []);
6187
+ for (const [key, property] of Object.entries(schema.properties)) {
6188
+ if (!(key in normalized)) continue;
6189
+ if (normalized[key] === null && !required.has(key)) {
6190
+ delete normalized[key];
6191
+ continue;
6192
+ }
6193
+ normalized[key] = normalizeOptionalNulls(
6194
+ normalized[key],
6195
+ property
6146
6196
  );
6147
6197
  }
6148
6198
  }
6149
- return next;
6150
- });
6199
+ for (const variant of [...schema.anyOf ?? [], ...schema.oneOf ?? []]) {
6200
+ if (variant === true || variant === false) continue;
6201
+ Object.assign(
6202
+ normalized,
6203
+ normalizeOptionalNulls(normalized, variant)
6204
+ );
6205
+ }
6206
+ return normalized;
6207
+ };
6151
6208
  var withTopLevelObjectTypeForObjectUnions = (schema) => {
6152
6209
  if (schema.type !== void 0) return schema;
6153
6210
  const variants = (Array.isArray(schema.anyOf) && schema.anyOf.length > 0 ? schema.anyOf : Array.isArray(schema.oneOf) && schema.oneOf.length > 0 ? schema.oneOf : null) ?? null;
@@ -6173,7 +6230,7 @@ function defineTool(toolOptions) {
6173
6230
  io: "input"
6174
6231
  });
6175
6232
  const strictParameters = withTopLevelObjectTypeForObjectUnions(
6176
- withRequiredProperties(withNoAdditionalProperties(parameters))
6233
+ toStrictToolSchema(parameters)
6177
6234
  );
6178
6235
  return {
6179
6236
  name: toolOptions.name,
@@ -6193,7 +6250,9 @@ function defineTool(toolOptions) {
6193
6250
  `Invalid tool arguments JSON for ${toolOptions.name}: ${String(error)}`
6194
6251
  );
6195
6252
  }
6196
- const parsed = toolOptions.input.safeParse(rawArgs);
6253
+ const parsed = toolOptions.input.safeParse(
6254
+ normalizeOptionalNulls(rawArgs, parameters)
6255
+ );
6197
6256
  if (!parsed.success) {
6198
6257
  throw new Error(
6199
6258
  `Tool input validation failed for ${toolOptions.name}: ${parsed.error.message}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codelia/core",
3
- "version": "0.1.71",
3
+ "version": "0.1.74",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -25,8 +25,8 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@anthropic-ai/sdk": "^0.110.0",
28
- "@codelia/config": "0.1.71",
29
- "@codelia/shared-types": "0.1.71",
28
+ "@codelia/config": "0.1.74",
29
+ "@codelia/shared-types": "0.1.74",
30
30
  "@google-cloud/vertexai": "^1.10.0",
31
31
  "@google/genai": "^1.43.0",
32
32
  "json-schema": "^0.4.0",
package/prompts/system.md CHANGED
@@ -44,7 +44,7 @@ You can use a small set of tools (names vary by UI, but conceptually):
44
44
  - `webfetch` to fetch and normalize a specific HTTP(S) URL.
45
45
  - Shell / execution:
46
46
  - `shell` to start shell commands (optionally with detached wait).
47
- - `shell_list` / `shell_status` / `shell_logs` / `shell_wait` / `shell_result` / `shell_cancel` to inspect and control retained shell tasks.
47
+ - `shell_list` / `shell_status` / `shell_logs` / `shell_wait` / `shell_result` / `shell_cancel` to inspect and control retained shell tasks, and `shell_stdin_write` for bounded writes to explicitly piped detached tasks.
48
48
  - Planning:
49
49
  - `todo_read` / `todo_new` / `todo_append` / `todo_patch` / `todo_clear` to manage task checklists when helpful.
50
50
 
@@ -81,6 +81,7 @@ Shell / execution:
81
81
  - Use timeouts, one-shot commands, or controlled detached-wait execution when appropriate.
82
82
  - `shell` starts runtime-managed child processes; use `detached_wait=true` when you want to skip the attached wait and keep working, but do not treat it as persistence across runtime exit.
83
83
  - Use `shell_list` / `shell_status` / `shell_logs` / `shell_wait` / `shell_result` / `shell_cancel` to monitor and control retained shell work instead of treating it as fire-and-forget.
84
+ - Use `stdin_mode=pipe` only with `detached_wait=true`; send bounded UTF-8 input with `shell_stdin_write`, inspect responses with `shell_logs`, and close stdin when no more input is needed.
84
85
  - Treat detached-wait shell tasks as managed child jobs, not as fire-and-forget services: check status when progress matters, wait for the final result before relying on it, and cancel tasks that are no longer useful.
85
86
  - When work depends on background processes, ports, pidfiles, or other shared machine resources, check for conflicts with leftover state from earlier attempts and avoid relying on ambiguous ownership.
86
87
  - If work must survive runtime exit or behave like a service, start it explicitly out of process using shell-native detach/daemonization for that environment (for example `nohup`, `setsid`, `disown`, a service manager, or `docker compose up -d`) and verify readiness/liveness separately.