@nextclaw/server 0.6.9 → 0.6.11

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,5 +1,5 @@
1
1
  import * as NextclawCore from '@nextclaw/core';
2
- import { CronService, Config, ConfigActionExecuteRequest as ConfigActionExecuteRequest$1, ConfigActionExecuteResult as ConfigActionExecuteResult$1 } from '@nextclaw/core';
2
+ import { ThinkingLevel, CronService, Config, ConfigActionExecuteRequest as ConfigActionExecuteRequest$1, ConfigActionExecuteResult as ConfigActionExecuteResult$1 } from '@nextclaw/core';
3
3
  import { Hono } from 'hono';
4
4
 
5
5
  type ApiError = {
@@ -26,6 +26,10 @@ type ProviderConfigView = {
26
26
  extraHeaders?: Record<string, string> | null;
27
27
  wireApi?: "auto" | "chat" | "responses" | null;
28
28
  models?: string[];
29
+ modelThinking?: Record<string, {
30
+ supported: ThinkingLevel[];
31
+ default?: ThinkingLevel | null;
32
+ }>;
29
33
  };
30
34
  type ProviderConfigUpdate = {
31
35
  displayName?: string | null;
@@ -34,6 +38,10 @@ type ProviderConfigUpdate = {
34
38
  extraHeaders?: Record<string, string> | null;
35
39
  wireApi?: "auto" | "chat" | "responses" | null;
36
40
  models?: string[] | null;
41
+ modelThinking?: Record<string, {
42
+ supported?: ThinkingLevel[];
43
+ default?: ThinkingLevel | null;
44
+ }> | null;
37
45
  };
38
46
  type ProviderConnectionTestRequest = ProviderConfigUpdate & {
39
47
  model?: string | null;
package/dist/index.js CHANGED
@@ -26,7 +26,9 @@ import {
26
26
  hasSecretRef,
27
27
  isSensitiveConfigPath,
28
28
  SessionManager,
29
- getWorkspacePathFromConfig
29
+ getWorkspacePathFromConfig,
30
+ normalizeThinkingLevels,
31
+ parseThinkingLevel
30
32
  } from "@nextclaw/core";
31
33
 
32
34
  // src/ui/provider-overrides.ts
@@ -184,7 +186,8 @@ function createDefaultProviderConfig(defaultWireApi = "auto") {
184
186
  apiBase: null,
185
187
  extraHeaders: null,
186
188
  wireApi: defaultWireApi,
187
- models: []
189
+ models: [],
190
+ modelThinking: {}
188
191
  };
189
192
  }
190
193
  function ensureProviderConfig(config, providerName) {
@@ -454,6 +457,29 @@ function normalizeModelList(input) {
454
457
  }
455
458
  return [...deduped];
456
459
  }
460
+ function normalizeModelThinkingConfig(input) {
461
+ if (!input || typeof input !== "object") {
462
+ return {};
463
+ }
464
+ const normalized = {};
465
+ for (const [rawModel, rawValue] of Object.entries(input)) {
466
+ const model = rawModel.trim();
467
+ if (!model || !rawValue || typeof rawValue !== "object") {
468
+ continue;
469
+ }
470
+ const supported = normalizeThinkingLevels(rawValue.supported);
471
+ if (supported.length === 0) {
472
+ continue;
473
+ }
474
+ const defaultLevel = parseThinkingLevel(rawValue.default);
475
+ if (defaultLevel && supported.includes(defaultLevel)) {
476
+ normalized[model] = { supported, default: defaultLevel };
477
+ } else {
478
+ normalized[model] = { supported };
479
+ }
480
+ }
481
+ return normalized;
482
+ }
457
483
  function toProviderView(config, provider, providerName, uiHints, spec) {
458
484
  const apiKeyPath = `providers.${providerName}.apiKey`;
459
485
  const apiKeyRefSet = hasSecretRef(config, apiKeyPath);
@@ -469,7 +495,8 @@ function toProviderView(config, provider, providerName, uiHints, spec) {
469
495
  apiKeyMasked: masked.apiKeyMasked ?? (apiKeyRefSet ? "****" : void 0),
470
496
  apiBase: provider.apiBase ?? null,
471
497
  extraHeaders: extraHeaders && Object.keys(extraHeaders).length > 0 ? extraHeaders : null,
472
- models: normalizeModelList(provider.models ?? [])
498
+ models: normalizeModelList(provider.models ?? []),
499
+ modelThinking: normalizeModelThinkingConfig(provider.modelThinking ?? {})
473
500
  };
474
501
  const supportsWireApi = Boolean(spec?.supportsWireApi) || isCustomProviderName(providerName);
475
502
  if (supportsWireApi) {
@@ -776,6 +803,9 @@ function updateProvider(configPath, providerName, patch) {
776
803
  if (Object.prototype.hasOwnProperty.call(patch, "models")) {
777
804
  provider.models = normalizeModelList(patch.models ?? []);
778
805
  }
806
+ if (Object.prototype.hasOwnProperty.call(patch, "modelThinking")) {
807
+ provider.modelThinking = normalizeModelThinkingConfig(patch.modelThinking ?? {});
808
+ }
779
809
  const next = ConfigSchema.parse(config);
780
810
  saveConfig(next, configPath);
781
811
  const uiHints = buildUiHints(next);
@@ -793,7 +823,8 @@ function createCustomProvider(configPath, patch = {}) {
793
823
  apiBase: normalizeOptionalString(patch.apiBase),
794
824
  extraHeaders: normalizeHeaders(patch.extraHeaders ?? null),
795
825
  wireApi: patch.wireApi ?? "auto",
796
- models: normalizeModelList(patch.models ?? [])
826
+ models: normalizeModelList(patch.models ?? []),
827
+ modelThinking: normalizeModelThinkingConfig(patch.modelThinking ?? {})
797
828
  };
798
829
  const next = ConfigSchema.parse(config);
799
830
  saveConfig(next, configPath);
@@ -1509,7 +1540,8 @@ function setProviderApiKey(params) {
1509
1540
  apiBase: null,
1510
1541
  extraHeaders: null,
1511
1542
  wireApi: "auto",
1512
- models: []
1543
+ models: [],
1544
+ modelThinking: {}
1513
1545
  };
1514
1546
  }
1515
1547
  const target = providers[params.provider];
@@ -2027,6 +2059,17 @@ function readNonEmptyString(value) {
2027
2059
  const trimmed = value.trim();
2028
2060
  return trimmed || void 0;
2029
2061
  }
2062
+ function formatUserFacingError(error, maxChars = 320) {
2063
+ const raw = error instanceof Error ? error.message || error.name || "Unknown error" : String(error ?? "Unknown error");
2064
+ const normalized = raw.replace(/\s+/g, " ").trim();
2065
+ if (!normalized) {
2066
+ return "Unknown error";
2067
+ }
2068
+ if (normalized.length <= maxChars) {
2069
+ return normalized;
2070
+ }
2071
+ return `${normalized.slice(0, Math.max(0, maxChars - 3)).trimEnd()}...`;
2072
+ }
2030
2073
  function normalizeSessionType2(value) {
2031
2074
  return readNonEmptyString(value)?.toLowerCase();
2032
2075
  }
@@ -3371,7 +3414,7 @@ function createUiRouter(options) {
3371
3414
  options.publish({ type: "config.updated", payload: { path: "session" } });
3372
3415
  return c.json(ok(response));
3373
3416
  } catch (error) {
3374
- return c.json(err("CHAT_TURN_FAILED", String(error)), 500);
3417
+ return c.json(err("CHAT_TURN_FAILED", formatUserFacingError(error)), 500);
3375
3418
  }
3376
3419
  });
3377
3420
  app.post("/api/chat/turn/stop", async (c) => {
@@ -3449,7 +3492,7 @@ function createUiRouter(options) {
3449
3492
  try {
3450
3493
  managedRun = await chatRuntime.startTurnRun(request);
3451
3494
  } catch (error) {
3452
- return c.json(err("CHAT_TURN_FAILED", String(error)), 500);
3495
+ return c.json(err("CHAT_TURN_FAILED", formatUserFacingError(error)), 500);
3453
3496
  }
3454
3497
  if (readNonEmptyString(managedRun.runId)) {
3455
3498
  runId = readNonEmptyString(managedRun.runId);
@@ -3511,7 +3554,7 @@ function createUiRouter(options) {
3511
3554
  if (typed.type === "error") {
3512
3555
  push("error", {
3513
3556
  code: "CHAT_TURN_FAILED",
3514
- message: typed.error
3557
+ message: formatUserFacingError(typed.error)
3515
3558
  });
3516
3559
  return;
3517
3560
  }
@@ -3572,7 +3615,7 @@ function createUiRouter(options) {
3572
3615
  if (typed.type === "error") {
3573
3616
  push("error", {
3574
3617
  code: "CHAT_TURN_FAILED",
3575
- message: typed.error
3618
+ message: formatUserFacingError(typed.error)
3576
3619
  });
3577
3620
  return;
3578
3621
  }
@@ -3588,7 +3631,7 @@ function createUiRouter(options) {
3588
3631
  } catch (error) {
3589
3632
  push("error", {
3590
3633
  code: "CHAT_TURN_FAILED",
3591
- message: String(error)
3634
+ message: formatUserFacingError(error)
3592
3635
  });
3593
3636
  } finally {
3594
3637
  controller.close();
@@ -3714,7 +3757,7 @@ function createUiRouter(options) {
3714
3757
  if (typed.type === "error") {
3715
3758
  push("error", {
3716
3759
  code: "CHAT_TURN_FAILED",
3717
- message: typed.error
3760
+ message: formatUserFacingError(typed.error)
3718
3761
  });
3719
3762
  return;
3720
3763
  }
@@ -3724,7 +3767,7 @@ function createUiRouter(options) {
3724
3767
  if (latestRun?.state === "failed") {
3725
3768
  push("error", {
3726
3769
  code: "CHAT_TURN_FAILED",
3727
- message: latestRun.error ?? "chat run failed"
3770
+ message: formatUserFacingError(latestRun.error ?? "chat run failed")
3728
3771
  });
3729
3772
  return;
3730
3773
  }
@@ -3733,7 +3776,7 @@ function createUiRouter(options) {
3733
3776
  } catch (error) {
3734
3777
  push("error", {
3735
3778
  code: "CHAT_TURN_FAILED",
3736
- message: String(error)
3779
+ message: formatUserFacingError(error)
3737
3780
  });
3738
3781
  } finally {
3739
3782
  controller.close();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextclaw/server",
3
- "version": "0.6.9",
3
+ "version": "0.6.11",
4
4
  "private": false,
5
5
  "description": "Nextclaw UI/API server.",
6
6
  "type": "module",
@@ -18,9 +18,9 @@
18
18
  "@hono/node-server": "^1.13.3",
19
19
  "hono": "^4.6.2",
20
20
  "ws": "^8.18.0",
21
- "@nextclaw/openclaw-compat": "0.2.4",
22
- "@nextclaw/core": "0.7.5",
23
- "@nextclaw/runtime": "0.1.4"
21
+ "@nextclaw/core": "0.7.7",
22
+ "@nextclaw/openclaw-compat": "0.2.6",
23
+ "@nextclaw/runtime": "0.1.6"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/node": "^20.17.6",