@rzx/ohs 1.2.0 → 1.2.7

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.js CHANGED
@@ -451789,6 +451789,27 @@ function catalogModelContextWindow(catalog, providerName, modelId) {
451789
451789
  function catalogModelOutputLimit(catalog, providerName, modelId) {
451790
451790
  return positiveLimit(catalogModelEntry(catalog, providerName, modelId)?.limit?.output);
451791
451791
  }
451792
+ function modelIdKey(value) {
451793
+ return value.replace(/-/g, "").toLowerCase();
451794
+ }
451795
+ function findCatalogModelById(catalog, modelId) {
451796
+ const target = modelIdKey(modelId.trim());
451797
+ if (!target)
451798
+ return;
451799
+ for (const provider of Object.values(catalog)) {
451800
+ if (!provider?.models)
451801
+ continue;
451802
+ for (const [key, model] of Object.entries(provider.models)) {
451803
+ if (model.status === "deprecated" || model.status === "alpha")
451804
+ continue;
451805
+ const id = typeof model.id === "string" && model.id.trim() ? model.id.trim() : key;
451806
+ if (modelIdKey(id) === target || modelIdKey(key) === target) {
451807
+ return model;
451808
+ }
451809
+ }
451810
+ }
451811
+ return;
451812
+ }
451792
451813
  function catalogModelReasoningEfforts(catalog, providerName, modelId) {
451793
451814
  if (!providerName)
451794
451815
  return;
@@ -451807,6 +451828,30 @@ var init_catalog_provider_mapping = __esm(() => {
451807
451828
  };
451808
451829
  });
451809
451830
 
451831
+ // ../../packages/server/src/application/default-services/model-limit-resolution.ts
451832
+ function resolveModelLimit(kind, input) {
451833
+ const provider = input.provider?.trim();
451834
+ const model = input.model?.trim();
451835
+ if (!provider || !model)
451836
+ return;
451837
+ const custom = customModelEntry(input.customProviders, provider, model);
451838
+ const declared = positiveLimit(kind === "context" ? custom?.contextWindow : custom?.maxOutputTokens);
451839
+ if (declared !== undefined)
451840
+ return declared;
451841
+ const fromCatalogProvider = kind === "context" ? catalogModelContextWindow(input.catalog, provider, model) : catalogModelOutputLimit(input.catalog, provider, model);
451842
+ if (fromCatalogProvider !== undefined)
451843
+ return fromCatalogProvider;
451844
+ if (!custom)
451845
+ return;
451846
+ return positiveLimit(findCatalogModelById(input.catalog, model)?.limit?.[kind]);
451847
+ }
451848
+ function customModelEntry(customProviders, provider, model) {
451849
+ return customProviders?.find((item) => item.id === provider)?.models.find((item) => item.id === model);
451850
+ }
451851
+ var init_model_limit_resolution = __esm(() => {
451852
+ init_catalog_provider_mapping();
451853
+ });
451854
+
451810
451855
  // ../../packages/server/src/application/attachments/routing/attachment-capabilities.ts
451811
451856
  function supportsNativeImageInput(context, catalog) {
451812
451857
  const request = context.requestConfiguration;
@@ -451889,15 +451934,20 @@ function createDefaultModelService(ref) {
451889
451934
  const current = ref ? await readCurrentSettings(ref) : undefined;
451890
451935
  for (const provider of current?.customProviders ?? []) {
451891
451936
  const catalogModels = provider.source === "models.dev" ? indexCatalogModels(catalog, provider.id) : undefined;
451937
+ const limitInput = (providerId, modelId) => ({
451938
+ catalog,
451939
+ customProviders: current?.customProviders,
451940
+ provider: providerId,
451941
+ model: modelId
451942
+ });
451892
451943
  result.push({
451893
451944
  name: provider.id,
451894
451945
  displayName: provider.displayName,
451895
451946
  models: provider.models.map((model) => {
451896
451947
  const catalogModel = catalogModels?.get(model.id);
451897
- if (catalogModel) {
451898
- return toModelInfo(provider.id, provider.displayName, model.id, catalogModel);
451899
- }
451900
- return {
451948
+ const contextWindow = resolveModelLimit("context", limitInput(provider.id, model.id));
451949
+ const outputLimit = resolveModelLimit("output", limitInput(provider.id, model.id));
451950
+ const base = catalogModel ? toModelInfo(provider.id, provider.displayName, model.id, catalogModel) : {
451901
451951
  id: model.id,
451902
451952
  label: model.displayName,
451903
451953
  provider: provider.displayName,
@@ -451907,6 +451957,11 @@ function createDefaultModelService(ref) {
451907
451957
  image: normalizeInputSupport(model.imageInputSupport)
451908
451958
  }
451909
451959
  };
451960
+ return {
451961
+ ...base,
451962
+ ...contextWindow !== undefined ? { contextWindow } : {},
451963
+ ...outputLimit !== undefined ? { outputLimit } : {}
451964
+ };
451910
451965
  })
451911
451966
  });
451912
451967
  }
@@ -451974,6 +452029,7 @@ var init_model_service = __esm(() => {
451974
452029
  init_src10();
451975
452030
  init_shared();
451976
452031
  init_catalog_provider_mapping();
452032
+ init_model_limit_resolution();
451977
452033
  init_attachment_capabilities();
451978
452034
  });
451979
452035
 
@@ -458453,6 +458509,14 @@ function normalizeProviderHeaders(headers) {
458453
458509
  throw error;
458454
458510
  }
458455
458511
  }
458512
+ function normalizeModelLimit(value, label) {
458513
+ if (value === undefined || value === null)
458514
+ return;
458515
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
458516
+ throw new ProviderMutationError(400, `${label}必须是大于 0 的整数。`);
458517
+ }
458518
+ return value;
458519
+ }
458456
458520
  function normalizeCustomProvider(input) {
458457
458521
  const id = typeof input.id === "string" ? input.id.trim().toLowerCase() : "";
458458
458522
  if (!id || !/^[a-z0-9][a-z0-9_-]*$/.test(id)) {
@@ -458475,11 +458539,17 @@ function normalizeCustomProvider(input) {
458475
458539
  if (!Array.isArray(input.models) || input.models.length === 0) {
458476
458540
  throw new ProviderMutationError(400, "请至少添加一个模型。");
458477
458541
  }
458478
- const models = input.models.map((model) => ({
458479
- id: model.id?.trim(),
458480
- displayName: model.displayName?.trim() || model.id?.trim(),
458481
- ...model.imageInputSupport ? { imageInputSupport: model.imageInputSupport } : {}
458482
- }));
458542
+ const models = input.models.map((model) => {
458543
+ const contextWindow = normalizeModelLimit(model.contextWindow, "上下文窗口");
458544
+ const maxOutputTokens = normalizeModelLimit(model.maxOutputTokens, "最大输出");
458545
+ return {
458546
+ id: model.id?.trim(),
458547
+ displayName: model.displayName?.trim() || model.id?.trim(),
458548
+ ...model.imageInputSupport ? { imageInputSupport: model.imageInputSupport } : {},
458549
+ ...contextWindow !== undefined ? { contextWindow } : {},
458550
+ ...maxOutputTokens !== undefined ? { maxOutputTokens } : {}
458551
+ };
458552
+ });
458483
458553
  if (models.some((model) => !model.id)) {
458484
458554
  throw new ProviderMutationError(400, "模型 ID 不能为空。");
458485
458555
  }
@@ -588515,6 +588585,7 @@ class DaemonApplication {
588515
588585
  const imageGenerationTool = createDaemonImageGenerationTool({
588516
588586
  attachments: this.attachments
588517
588587
  });
588588
+ const readLimitSettings = () => options.getSettings?.() ?? options.settings;
588518
588589
  const loadAgent = createDaemonAgentLoader({
588519
588590
  executionSurface: options.executionSurface,
588520
588591
  settings: options.settings,
@@ -588536,12 +588607,22 @@ class DaemonApplication {
588536
588607
  resolveModelContextWindow: async ({ provider, model }) => {
588537
588608
  if (!provider)
588538
588609
  return;
588539
- return catalogModelContextWindow(await this.modelCatalog.load(), provider, model);
588610
+ return resolveModelLimit("context", {
588611
+ catalog: await this.modelCatalog.load(),
588612
+ customProviders: readLimitSettings()?.customProviders,
588613
+ provider,
588614
+ model
588615
+ });
588540
588616
  },
588541
588617
  resolveModelOutputLimit: async ({ provider, model }) => {
588542
588618
  if (!provider)
588543
588619
  return;
588544
- return catalogModelOutputLimit(await this.modelCatalog.load(), provider, model);
588620
+ return resolveModelLimit("output", {
588621
+ catalog: await this.modelCatalog.load(),
588622
+ customProviders: readLimitSettings()?.customProviders,
588623
+ provider,
588624
+ model
588625
+ });
588545
588626
  },
588546
588627
  createAgent: options.createAgent,
588547
588628
  mcpRuntimeRegistry: this.mcpRuntimes,
@@ -589193,6 +589274,7 @@ var init_daemon_application = __esm(() => {
589193
589274
  init_src8();
589194
589275
  init_daemon_attachment_services();
589195
589276
  init_catalog_provider_mapping();
589277
+ init_model_limit_resolution();
589196
589278
  init_request_selection_validation();
589197
589279
  init_daemon_agent();
589198
589280
  init_mcp_oauth_application_service();
@@ -598373,4 +598455,4 @@ program.command("doctor").description("Check environment and dependencies").acti
598373
598455
  });
598374
598456
  program.parse();
598375
598457
 
598376
- //# debugId=18B7D67E419A5F4164756E2164756E21
598458
+ //# debugId=68E293090668038D64756E2164756E21