@codelia/runtime 0.1.23 → 0.1.26

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.
Files changed (3) hide show
  1. package/dist/index.cjs +117 -26
  2. package/dist/index.js +117 -26
  3. package/package.json +9 -9
package/dist/index.cjs CHANGED
@@ -734,7 +734,8 @@ var resolveModelConfig = async (workingDir) => {
734
734
  provider: effective.model?.provider,
735
735
  name: effective.model?.name,
736
736
  reasoning: effective.model?.reasoning,
737
- verbosity: effective.model?.verbosity
737
+ verbosity: effective.model?.verbosity,
738
+ experimental: effective.experimental
738
739
  };
739
740
  };
740
741
  var resolveTuiConfig = async (workingDir) => {
@@ -903,19 +904,27 @@ var updateTuiTheme = async (workingDir, theme) => {
903
904
  return target;
904
905
  };
905
906
  var resolveReasoningEffort = (value) => {
906
- return resolveModelLevelOption(value, "model.reasoning");
907
+ return resolveModelLevelOption(value, "model.reasoning", {
908
+ allowXhigh: true
909
+ });
907
910
  };
908
911
  var resolveTextVerbosity = (value) => {
909
- return resolveModelLevelOption(value, "model.verbosity");
912
+ return resolveModelLevelOption(value, "model.verbosity", {
913
+ allowXhigh: false
914
+ });
910
915
  };
911
- var resolveModelLevelOption = (value, fieldName) => {
916
+ function resolveModelLevelOption(value, fieldName, options) {
912
917
  if (!value) return void 0;
913
918
  const normalized = value.trim().toLowerCase();
914
919
  if (normalized === "low" || normalized === "medium" || normalized === "high") {
915
920
  return normalized;
916
921
  }
917
- throw new Error(`Invalid ${fieldName}: ${value}. Expected low|medium|high.`);
918
- };
922
+ if (options.allowXhigh && normalized === "xhigh") {
923
+ return normalized;
924
+ }
925
+ const expected = options.allowXhigh ? "low|medium|high|xhigh" : "low|medium|high";
926
+ throw new Error(`Invalid ${fieldName}: ${value}. Expected ${expected}.`);
927
+ }
919
928
  var loadSystemPrompt = async (workingDir) => {
920
929
  const promptPath = process.env.CODELIA_SYSTEM_PROMPT_PATH ? import_node_path2.default.resolve(process.env.CODELIA_SYSTEM_PROMPT_PATH) : (0, import_core.getDefaultSystemPromptPath)();
921
930
  try {
@@ -5043,10 +5052,15 @@ var buildOpenAiClientOptions = (authResolver, auth) => {
5043
5052
  },
5044
5053
  { preconnect: fetch.preconnect }
5045
5054
  );
5055
+ const defaultHeaders = {};
5056
+ if (accountId) {
5057
+ defaultHeaders["ChatGPT-Account-ID"] = accountId;
5058
+ }
5046
5059
  return {
5047
5060
  apiKey,
5048
5061
  baseURL: OPENAI_OAUTH_BASE_URL,
5049
- fetch: fetchWithAccount
5062
+ fetch: fetchWithAccount,
5063
+ ...Object.keys(defaultHeaders).length > 0 ? { defaultHeaders } : {}
5050
5064
  };
5051
5065
  };
5052
5066
  var buildOpenRouterClientOptions = (auth) => {
@@ -5380,11 +5394,13 @@ var createAgentFactory = (state, options = {}) => {
5380
5394
  case "openai": {
5381
5395
  const reasoningEffort = resolveReasoningEffort(modelConfig.reasoning);
5382
5396
  const textVerbosity = resolveTextVerbosity(modelConfig.verbosity);
5397
+ const websocketMode = modelConfig.experimental?.openai?.websocket_mode;
5383
5398
  llm = new import_core18.ChatOpenAI({
5384
5399
  clientOptions: buildOpenAiClientOptions(authResolver, providerAuth),
5385
5400
  ...modelConfig.name ? { model: modelConfig.name } : {},
5386
5401
  ...reasoningEffort ? { reasoningEffort } : {},
5387
- ...textVerbosity ? { textVerbosity } : {}
5402
+ ...textVerbosity ? { textVerbosity } : {},
5403
+ ...websocketMode ? { websocketMode } : {}
5388
5404
  });
5389
5405
  break;
5390
5406
  }
@@ -7555,6 +7571,11 @@ var DEBUG_MAX_CONTENT_CHARS = 2e3;
7555
7571
  var DEBUG_MAX_LOG_CHARS = 2e4;
7556
7572
  var DEBUG_MAX_EVENT_RESULT_CHARS = 500;
7557
7573
  var DEBUG_MAX_EVENT_ARGS_CHARS = 2e3;
7574
+ var DEBUG_ERROR_MESSAGE_MAX_CHARS = 2e3;
7575
+ var DEBUG_ERROR_STACK_MAX_CHARS = 8e3;
7576
+ var DEBUG_ERROR_CHAIN_MAX_CHARS = 4e3;
7577
+ var DEBUG_ERROR_EXTRAS_MAX_CHARS = 4e3;
7578
+ var DEBUG_PROVIDER_META_STRING_MAX_CHARS = 80;
7558
7579
  var truncateText2 = (value, maxChars) => {
7559
7580
  if (value.length <= maxChars) return value;
7560
7581
  return `${value.slice(0, maxChars)}...[truncated]`;
@@ -7719,6 +7740,93 @@ var normalizeToolCallHistory = (messages) => {
7719
7740
  }
7720
7741
  return changed ? normalized : messages;
7721
7742
  };
7743
+ var formatErrorForDebugLog = (error) => {
7744
+ const parts = [];
7745
+ parts.push(`name=${error.name}`);
7746
+ parts.push(
7747
+ `message=${truncateText2(error.message, DEBUG_ERROR_MESSAGE_MAX_CHARS)}`
7748
+ );
7749
+ if (error.stack) {
7750
+ parts.push(`stack=${truncateText2(error.stack, DEBUG_ERROR_STACK_MAX_CHARS)}`);
7751
+ }
7752
+ const causeChain = [];
7753
+ let depth = 0;
7754
+ let current = error.cause;
7755
+ const seen = /* @__PURE__ */ new Set();
7756
+ while (current !== void 0 && current !== null && depth < 4) {
7757
+ if (seen.has(current)) {
7758
+ causeChain.push("[circular]");
7759
+ break;
7760
+ }
7761
+ seen.add(current);
7762
+ if (current instanceof Error) {
7763
+ causeChain.push(`${current.name}: ${current.message}`);
7764
+ current = current.cause;
7765
+ depth += 1;
7766
+ continue;
7767
+ }
7768
+ causeChain.push(stringifyUnknown(current));
7769
+ break;
7770
+ }
7771
+ if (causeChain.length > 0) {
7772
+ parts.push(
7773
+ `cause_chain=${truncateText2(causeChain.join(" <- "), DEBUG_ERROR_CHAIN_MAX_CHARS)}`
7774
+ );
7775
+ }
7776
+ const extras = Object.entries(
7777
+ error
7778
+ ).filter(([key]) => key !== "name" && key !== "message" && key !== "stack");
7779
+ if (extras.length > 0) {
7780
+ parts.push(
7781
+ `extras=${truncateText2(
7782
+ stringifyUnknown(Object.fromEntries(extras)),
7783
+ DEBUG_ERROR_EXTRAS_MAX_CHARS
7784
+ )}`
7785
+ );
7786
+ }
7787
+ return parts.join(" ");
7788
+ };
7789
+ var summarizeProviderMeta = (value) => {
7790
+ if (value === null || value === void 0) {
7791
+ return null;
7792
+ }
7793
+ if (typeof value === "string") {
7794
+ return value.length > DEBUG_PROVIDER_META_STRING_MAX_CHARS ? `${value.slice(0, DEBUG_PROVIDER_META_STRING_MAX_CHARS - 3)}...` : value;
7795
+ }
7796
+ if (Array.isArray(value)) {
7797
+ return `array(len=${value.length})`;
7798
+ }
7799
+ if (typeof value === "object") {
7800
+ const obj = value;
7801
+ const details = [];
7802
+ if (typeof obj.transport === "string") {
7803
+ details.push(`transport=${obj.transport}`);
7804
+ }
7805
+ if (typeof obj.websocket_mode === "string") {
7806
+ details.push(`websocket_mode=${obj.websocket_mode}`);
7807
+ }
7808
+ if (typeof obj.response_id === "string") {
7809
+ details.push(`response_id=${obj.response_id}`);
7810
+ }
7811
+ if (typeof obj.chain_reset === "boolean") {
7812
+ details.push(`chain_reset=${obj.chain_reset ? "true" : "false"}`);
7813
+ }
7814
+ if (typeof obj.fallback_used === "boolean") {
7815
+ details.push(`fallback_used=${obj.fallback_used ? "true" : "false"}`);
7816
+ }
7817
+ if (typeof obj.ws_input_mode === "string") {
7818
+ details.push(`ws_input_mode=${obj.ws_input_mode}`);
7819
+ }
7820
+ if (details.length > 0) {
7821
+ return details.join(" ");
7822
+ }
7823
+ const keys = Object.keys(obj);
7824
+ if (keys.length === 0) return "object";
7825
+ const shown = keys.slice(0, 4).join(",");
7826
+ return keys.length > 4 ? `object(keys=${shown},...)` : `object(keys=${shown})`;
7827
+ }
7828
+ return typeof value;
7829
+ };
7722
7830
  var isAbortLikeError = (error) => error.name === "AbortError" || error.name === "APIUserAbortError" || error.name === "AbortSignal" || /aborted|abort/i.test(error.message);
7723
7831
 
7724
7832
  // src/rpc/skill-mentions.ts
@@ -7853,24 +7961,6 @@ var toTimestampMs = (value) => {
7853
7961
  const ms = Date.parse(value);
7854
7962
  return Number.isFinite(ms) ? ms : null;
7855
7963
  };
7856
- var summarizeProviderMeta = (value) => {
7857
- if (value === null || value === void 0) {
7858
- return null;
7859
- }
7860
- if (typeof value === "string") {
7861
- return value.length > 80 ? `${value.slice(0, 77)}...` : value;
7862
- }
7863
- if (Array.isArray(value)) {
7864
- return `array(len=${value.length})`;
7865
- }
7866
- if (typeof value === "object") {
7867
- const keys = Object.keys(value);
7868
- if (keys.length === 0) return "object";
7869
- const shown = keys.slice(0, 4).join(",");
7870
- return keys.length > 4 ? `object(keys=${shown},...)` : `object(keys=${shown})`;
7871
- }
7872
- return typeof value;
7873
- };
7874
7964
  var createRunHandlers = ({
7875
7965
  state,
7876
7966
  getAgent,
@@ -8255,6 +8345,7 @@ var createRunHandlers = ({
8255
8345
  emitRunEnd(runId, "cancelled", finalResponse);
8256
8346
  return;
8257
8347
  }
8348
+ logRunDebug(log2, runId, `stream.error ${formatErrorForDebugLog(err)}`);
8258
8349
  await queueSessionSave("error");
8259
8350
  emitRunSummaryDiagnostics();
8260
8351
  emitRunStatus(runId, "error", err.message);
package/dist/index.js CHANGED
@@ -724,7 +724,8 @@ var resolveModelConfig = async (workingDir) => {
724
724
  provider: effective.model?.provider,
725
725
  name: effective.model?.name,
726
726
  reasoning: effective.model?.reasoning,
727
- verbosity: effective.model?.verbosity
727
+ verbosity: effective.model?.verbosity,
728
+ experimental: effective.experimental
728
729
  };
729
730
  };
730
731
  var resolveTuiConfig = async (workingDir) => {
@@ -893,19 +894,27 @@ var updateTuiTheme = async (workingDir, theme) => {
893
894
  return target;
894
895
  };
895
896
  var resolveReasoningEffort = (value) => {
896
- return resolveModelLevelOption(value, "model.reasoning");
897
+ return resolveModelLevelOption(value, "model.reasoning", {
898
+ allowXhigh: true
899
+ });
897
900
  };
898
901
  var resolveTextVerbosity = (value) => {
899
- return resolveModelLevelOption(value, "model.verbosity");
902
+ return resolveModelLevelOption(value, "model.verbosity", {
903
+ allowXhigh: false
904
+ });
900
905
  };
901
- var resolveModelLevelOption = (value, fieldName) => {
906
+ function resolveModelLevelOption(value, fieldName, options) {
902
907
  if (!value) return void 0;
903
908
  const normalized = value.trim().toLowerCase();
904
909
  if (normalized === "low" || normalized === "medium" || normalized === "high") {
905
910
  return normalized;
906
911
  }
907
- throw new Error(`Invalid ${fieldName}: ${value}. Expected low|medium|high.`);
908
- };
912
+ if (options.allowXhigh && normalized === "xhigh") {
913
+ return normalized;
914
+ }
915
+ const expected = options.allowXhigh ? "low|medium|high|xhigh" : "low|medium|high";
916
+ throw new Error(`Invalid ${fieldName}: ${value}. Expected ${expected}.`);
917
+ }
909
918
  var loadSystemPrompt = async (workingDir) => {
910
919
  const promptPath = process.env.CODELIA_SYSTEM_PROMPT_PATH ? path2.resolve(process.env.CODELIA_SYSTEM_PROMPT_PATH) : getDefaultSystemPromptPath();
911
920
  try {
@@ -5033,10 +5042,15 @@ var buildOpenAiClientOptions = (authResolver, auth) => {
5033
5042
  },
5034
5043
  { preconnect: fetch.preconnect }
5035
5044
  );
5045
+ const defaultHeaders = {};
5046
+ if (accountId) {
5047
+ defaultHeaders["ChatGPT-Account-ID"] = accountId;
5048
+ }
5036
5049
  return {
5037
5050
  apiKey,
5038
5051
  baseURL: OPENAI_OAUTH_BASE_URL,
5039
- fetch: fetchWithAccount
5052
+ fetch: fetchWithAccount,
5053
+ ...Object.keys(defaultHeaders).length > 0 ? { defaultHeaders } : {}
5040
5054
  };
5041
5055
  };
5042
5056
  var buildOpenRouterClientOptions = (auth) => {
@@ -5370,11 +5384,13 @@ var createAgentFactory = (state, options = {}) => {
5370
5384
  case "openai": {
5371
5385
  const reasoningEffort = resolveReasoningEffort(modelConfig.reasoning);
5372
5386
  const textVerbosity = resolveTextVerbosity(modelConfig.verbosity);
5387
+ const websocketMode = modelConfig.experimental?.openai?.websocket_mode;
5373
5388
  llm = new ChatOpenAI({
5374
5389
  clientOptions: buildOpenAiClientOptions(authResolver, providerAuth),
5375
5390
  ...modelConfig.name ? { model: modelConfig.name } : {},
5376
5391
  ...reasoningEffort ? { reasoningEffort } : {},
5377
- ...textVerbosity ? { textVerbosity } : {}
5392
+ ...textVerbosity ? { textVerbosity } : {},
5393
+ ...websocketMode ? { websocketMode } : {}
5378
5394
  });
5379
5395
  break;
5380
5396
  }
@@ -7571,6 +7587,11 @@ var DEBUG_MAX_CONTENT_CHARS = 2e3;
7571
7587
  var DEBUG_MAX_LOG_CHARS = 2e4;
7572
7588
  var DEBUG_MAX_EVENT_RESULT_CHARS = 500;
7573
7589
  var DEBUG_MAX_EVENT_ARGS_CHARS = 2e3;
7590
+ var DEBUG_ERROR_MESSAGE_MAX_CHARS = 2e3;
7591
+ var DEBUG_ERROR_STACK_MAX_CHARS = 8e3;
7592
+ var DEBUG_ERROR_CHAIN_MAX_CHARS = 4e3;
7593
+ var DEBUG_ERROR_EXTRAS_MAX_CHARS = 4e3;
7594
+ var DEBUG_PROVIDER_META_STRING_MAX_CHARS = 80;
7574
7595
  var truncateText2 = (value, maxChars) => {
7575
7596
  if (value.length <= maxChars) return value;
7576
7597
  return `${value.slice(0, maxChars)}...[truncated]`;
@@ -7735,6 +7756,93 @@ var normalizeToolCallHistory = (messages) => {
7735
7756
  }
7736
7757
  return changed ? normalized : messages;
7737
7758
  };
7759
+ var formatErrorForDebugLog = (error) => {
7760
+ const parts = [];
7761
+ parts.push(`name=${error.name}`);
7762
+ parts.push(
7763
+ `message=${truncateText2(error.message, DEBUG_ERROR_MESSAGE_MAX_CHARS)}`
7764
+ );
7765
+ if (error.stack) {
7766
+ parts.push(`stack=${truncateText2(error.stack, DEBUG_ERROR_STACK_MAX_CHARS)}`);
7767
+ }
7768
+ const causeChain = [];
7769
+ let depth = 0;
7770
+ let current = error.cause;
7771
+ const seen = /* @__PURE__ */ new Set();
7772
+ while (current !== void 0 && current !== null && depth < 4) {
7773
+ if (seen.has(current)) {
7774
+ causeChain.push("[circular]");
7775
+ break;
7776
+ }
7777
+ seen.add(current);
7778
+ if (current instanceof Error) {
7779
+ causeChain.push(`${current.name}: ${current.message}`);
7780
+ current = current.cause;
7781
+ depth += 1;
7782
+ continue;
7783
+ }
7784
+ causeChain.push(stringifyUnknown(current));
7785
+ break;
7786
+ }
7787
+ if (causeChain.length > 0) {
7788
+ parts.push(
7789
+ `cause_chain=${truncateText2(causeChain.join(" <- "), DEBUG_ERROR_CHAIN_MAX_CHARS)}`
7790
+ );
7791
+ }
7792
+ const extras = Object.entries(
7793
+ error
7794
+ ).filter(([key]) => key !== "name" && key !== "message" && key !== "stack");
7795
+ if (extras.length > 0) {
7796
+ parts.push(
7797
+ `extras=${truncateText2(
7798
+ stringifyUnknown(Object.fromEntries(extras)),
7799
+ DEBUG_ERROR_EXTRAS_MAX_CHARS
7800
+ )}`
7801
+ );
7802
+ }
7803
+ return parts.join(" ");
7804
+ };
7805
+ var summarizeProviderMeta = (value) => {
7806
+ if (value === null || value === void 0) {
7807
+ return null;
7808
+ }
7809
+ if (typeof value === "string") {
7810
+ return value.length > DEBUG_PROVIDER_META_STRING_MAX_CHARS ? `${value.slice(0, DEBUG_PROVIDER_META_STRING_MAX_CHARS - 3)}...` : value;
7811
+ }
7812
+ if (Array.isArray(value)) {
7813
+ return `array(len=${value.length})`;
7814
+ }
7815
+ if (typeof value === "object") {
7816
+ const obj = value;
7817
+ const details = [];
7818
+ if (typeof obj.transport === "string") {
7819
+ details.push(`transport=${obj.transport}`);
7820
+ }
7821
+ if (typeof obj.websocket_mode === "string") {
7822
+ details.push(`websocket_mode=${obj.websocket_mode}`);
7823
+ }
7824
+ if (typeof obj.response_id === "string") {
7825
+ details.push(`response_id=${obj.response_id}`);
7826
+ }
7827
+ if (typeof obj.chain_reset === "boolean") {
7828
+ details.push(`chain_reset=${obj.chain_reset ? "true" : "false"}`);
7829
+ }
7830
+ if (typeof obj.fallback_used === "boolean") {
7831
+ details.push(`fallback_used=${obj.fallback_used ? "true" : "false"}`);
7832
+ }
7833
+ if (typeof obj.ws_input_mode === "string") {
7834
+ details.push(`ws_input_mode=${obj.ws_input_mode}`);
7835
+ }
7836
+ if (details.length > 0) {
7837
+ return details.join(" ");
7838
+ }
7839
+ const keys = Object.keys(obj);
7840
+ if (keys.length === 0) return "object";
7841
+ const shown = keys.slice(0, 4).join(",");
7842
+ return keys.length > 4 ? `object(keys=${shown},...)` : `object(keys=${shown})`;
7843
+ }
7844
+ return typeof value;
7845
+ };
7738
7846
  var isAbortLikeError = (error) => error.name === "AbortError" || error.name === "APIUserAbortError" || error.name === "AbortSignal" || /aborted|abort/i.test(error.message);
7739
7847
 
7740
7848
  // src/rpc/skill-mentions.ts
@@ -7869,24 +7977,6 @@ var toTimestampMs = (value) => {
7869
7977
  const ms = Date.parse(value);
7870
7978
  return Number.isFinite(ms) ? ms : null;
7871
7979
  };
7872
- var summarizeProviderMeta = (value) => {
7873
- if (value === null || value === void 0) {
7874
- return null;
7875
- }
7876
- if (typeof value === "string") {
7877
- return value.length > 80 ? `${value.slice(0, 77)}...` : value;
7878
- }
7879
- if (Array.isArray(value)) {
7880
- return `array(len=${value.length})`;
7881
- }
7882
- if (typeof value === "object") {
7883
- const keys = Object.keys(value);
7884
- if (keys.length === 0) return "object";
7885
- const shown = keys.slice(0, 4).join(",");
7886
- return keys.length > 4 ? `object(keys=${shown},...)` : `object(keys=${shown})`;
7887
- }
7888
- return typeof value;
7889
- };
7890
7980
  var createRunHandlers = ({
7891
7981
  state,
7892
7982
  getAgent,
@@ -8271,6 +8361,7 @@ var createRunHandlers = ({
8271
8361
  emitRunEnd(runId, "cancelled", finalResponse);
8272
8362
  return;
8273
8363
  }
8364
+ logRunDebug(log2, runId, `stream.error ${formatErrorForDebugLog(err)}`);
8274
8365
  await queueSessionSave("error");
8275
8366
  emitRunSummaryDiagnostics();
8276
8367
  emitRunStatus(runId, "error", err.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codelia/runtime",
3
- "version": "0.1.23",
3
+ "version": "0.1.26",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=20 <25"
@@ -23,14 +23,14 @@
23
23
  "typecheck": "tsc --noEmit"
24
24
  },
25
25
  "dependencies": {
26
- "@codelia/config": "0.1.23",
27
- "@codelia/config-loader": "0.1.23",
28
- "@codelia/core": "0.1.23",
29
- "@codelia/logger": "0.1.23",
30
- "@codelia/model-metadata": "0.1.23",
31
- "@codelia/protocol": "0.1.23",
32
- "@codelia/shared-types": "0.1.23",
33
- "@codelia/storage": "0.1.23",
26
+ "@codelia/config": "0.1.26",
27
+ "@codelia/config-loader": "0.1.26",
28
+ "@codelia/core": "0.1.26",
29
+ "@codelia/logger": "0.1.26",
30
+ "@codelia/model-metadata": "0.1.26",
31
+ "@codelia/protocol": "0.1.26",
32
+ "@codelia/shared-types": "0.1.26",
33
+ "@codelia/storage": "0.1.26",
34
34
  "eventsource-parser": "^3.0.6",
35
35
  "oauth4webapi": "^3.8.4",
36
36
  "zod": "^4.3.5"