@xpert-ai/plugin-openai 0.0.5 → 0.2.0

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/llm/llm.js CHANGED
@@ -3,7 +3,7 @@ var OpenAILargeLanguageModel_1;
3
3
  import { __decorate, __metadata } from "tslib";
4
4
  import { HumanMessage } from '@langchain/core/messages';
5
5
  import { ChatOpenAI } from '@langchain/openai';
6
- import { AiModelTypeEnum } from '@metad/contracts';
6
+ import { AiModelTypeEnum } from '@xpert-ai/contracts';
7
7
  import { Injectable, Logger } from '@nestjs/common';
8
8
  import { CredentialsValidateFailedError, getErrorMessage, LargeLanguageModel, } from '@xpert-ai/plugin-sdk';
9
9
  import { isNil, omitBy } from 'lodash-es';
@@ -54,8 +54,8 @@ let OpenAILargeLanguageModel = OpenAILargeLanguageModel_1 = class OpenAILargeLan
54
54
  const model = copilotModel.model;
55
55
  const hasCustomEndpoint = !!credentials?.endpoint_url?.trim();
56
56
  const streaming = modelOptions?.streaming ?? !hasCustomEndpoint;
57
- const supportsSamplingParams = shouldEnableSamplingParameters(credentials?.sampling_parameters, params.configuration?.baseURL, model);
58
57
  const reasoningEffort = normalizeOpenAIReasoningEffort(model, modelOptions?.reasoning_effort);
58
+ const supportsSamplingParams = shouldEnableSamplingParameters(credentials?.sampling_parameters, params.configuration?.baseURL, model, reasoningEffort);
59
59
  const reasoning = this.getReasoningOptions(model, reasoningEffort);
60
60
  const langChainReasoning = this.toLangChainReasoning(reasoning);
61
61
  const supportsResponseFormat = shouldEnableResponseFormat(params.configuration?.baseURL, model);
@@ -74,15 +74,12 @@ let OpenAILargeLanguageModel = OpenAILargeLanguageModel_1 = class OpenAILargeLan
74
74
  maxRetries: modelOptions?.maxRetries,
75
75
  useResponsesApi: true,
76
76
  reasoning: langChainReasoning,
77
- responses: new OpenAIReasoningResponsesModel({
78
- ...params,
79
- model,
80
- reasoning: langChainReasoning
81
- }),
82
77
  streamUsage: streaming,
83
78
  }, isNil);
84
79
  const chatModel = new ChatOpenAI({
85
80
  ...fields,
81
+ // Custom Responses instances do not inherit ChatOpenAI constructor fields.
82
+ responses: new OpenAIReasoningResponsesModel(fields),
86
83
  verbose: options?.verbose,
87
84
  callbacks: [
88
85
  ...this.createHandleUsageCallbacks(copilot, model, credentials, handleLLMTokens),
@@ -2,6 +2,8 @@ import { AIMessage } from '@langchain/core/messages';
2
2
  import { ChatGenerationChunk } from '@langchain/core/outputs';
3
3
  import { ChatOpenAIResponses, OpenAIClient } from '@langchain/openai';
4
4
  export declare class OpenAIReasoningResponsesModel extends ChatOpenAIResponses {
5
+ protected _getReasoningParams(options?: this['ParsedCallOptions']): OpenAIClient.Reasoning | undefined;
6
+ invocationParams(options?: this['ParsedCallOptions']): ReturnType<ChatOpenAIResponses['invocationParams']>;
5
7
  protected _convertResponsesMessageToBaseMessage(response: OpenAIClient.Responses.Response): AIMessage;
6
8
  protected _convertResponsesDeltaToBaseMessageChunk(chunk: OpenAIClient.Responses.ResponseStreamEvent): ChatGenerationChunk | null;
7
9
  }
@@ -1 +1 @@
1
- {"version":3,"file":"reasoning.d.ts","sourceRoot":"","sources":["../../src/llm/reasoning.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAkB,MAAM,0BAA0B,CAAA;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAwCrE,qBAAa,6BAA8B,SAAQ,mBAAmB;cACjD,qCAAqC,CACtD,QAAQ,EAAE,YAAY,CAAC,SAAS,CAAC,QAAQ;cAexB,wCAAwC,CACzD,KAAK,EAAE,YAAY,CAAC,SAAS,CAAC,mBAAmB,GAChD,mBAAmB,GAAG,IAAI;CAqB9B"}
1
+ {"version":3,"file":"reasoning.d.ts","sourceRoot":"","sources":["../../src/llm/reasoning.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAkB,MAAM,0BAA0B,CAAA;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAkDrE,qBAAa,6BAA8B,SAAQ,mBAAmB;cACjD,mBAAmB,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC,GAAG,YAAY,CAAC,SAAS,GAAG,SAAS;IAQtG,gBAAgB,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC,GAAG,UAAU,CAAC,mBAAmB,CAAC,kBAAkB,CAAC,CAAC;cAShG,qCAAqC,CACtD,QAAQ,EAAE,YAAY,CAAC,SAAS,CAAC,QAAQ;cAgBxB,wCAAwC,CACzD,KAAK,EAAE,YAAY,CAAC,SAAS,CAAC,mBAAmB,GAChD,mBAAmB,GAAG,IAAI;CAwB9B"}
@@ -1,4 +1,5 @@
1
1
  import { ChatOpenAIResponses } from '@langchain/openai';
2
+ import { getSupportedOpenAIReasoningEfforts, shouldEnableSamplingParameters } from '../types.js';
2
3
  function extractReasoningSummaryText(reasoning) {
3
4
  if (!reasoning || typeof reasoning !== 'object') {
4
5
  return undefined;
@@ -22,9 +23,34 @@ function extractReasoningDeltaText(chunk) {
22
23
  }
23
24
  return undefined;
24
25
  }
26
+ function normalizeResponseUsage(usage) {
27
+ if (!usage)
28
+ return undefined;
29
+ return {
30
+ ...usage,
31
+ ...(usage.input_tokens_details ? { input_token_details: { cache_read: usage.input_tokens_details.cached_tokens } } : {}),
32
+ ...(usage.output_tokens_details ? { output_token_details: { reasoning: usage.output_tokens_details.reasoning_tokens } } : {})
33
+ };
34
+ }
25
35
  export class OpenAIReasoningResponsesModel extends ChatOpenAIResponses {
36
+ _getReasoningParams(options) {
37
+ // LangChain 0.6.9 only recognizes GPT-5/o-series reasoning; use our explicit catalog.
38
+ if (getSupportedOpenAIReasoningEfforts(this.model)) {
39
+ return { ...this.reasoning, ...options?.reasoning };
40
+ }
41
+ return super._getReasoningParams(options);
42
+ }
43
+ invocationParams(options) {
44
+ const params = super.invocationParams(options);
45
+ if (!shouldEnableSamplingParameters('enabled', this.clientConfig.baseURL, this.model, params.reasoning?.effort)) {
46
+ delete params.temperature;
47
+ delete params.top_p;
48
+ }
49
+ return params;
50
+ }
26
51
  _convertResponsesMessageToBaseMessage(response) {
27
52
  const message = super._convertResponsesMessageToBaseMessage(response);
53
+ message.usage_metadata = normalizeResponseUsage(response.usage);
28
54
  const reasoningContent = extractReasoningSummaryText(message.additional_kwargs?.reasoning);
29
55
  if (reasoningContent) {
30
56
  message.additional_kwargs = {
@@ -40,6 +66,9 @@ export class OpenAIReasoningResponsesModel extends ChatOpenAIResponses {
40
66
  return null;
41
67
  }
42
68
  const message = generationChunk.message;
69
+ if (chunk.type === 'response.completed') {
70
+ message.usage_metadata = normalizeResponseUsage(chunk.response.usage);
71
+ }
43
72
  const reasoningContent = extractReasoningDeltaText(chunk) ?? extractReasoningSummaryText(message.additional_kwargs?.reasoning);
44
73
  if (reasoningContent) {
45
74
  message.additional_kwargs = {
package/dist/openai.yaml CHANGED
@@ -3,8 +3,8 @@ label:
3
3
  en_US: OpenAI
4
4
  zh_Hans: OpenAI
5
5
  description:
6
- en_US: OpenAI GPT-5 and GPT-5.4 model service via Responses API.
7
- zh_Hans: OpenAI GPT-5 与 GPT-5.4 模型服务,通过 Responses API 提供。
6
+ en_US: OpenAI GPT-6 and GPT-5 model service via Responses API.
7
+ zh_Hans: OpenAI GPT-6 与 GPT-5 模型服务,通过 Responses API 提供。
8
8
  icon_small:
9
9
  en_US: icon_s_en.svg
10
10
  icon_large:
@@ -1,8 +1,10 @@
1
+ import { type NativeModelClientFactory } from '@xpert-ai/plugin-sdk';
1
2
  import { Logger } from '@nestjs/common';
2
3
  import { ModelProvider } from '@xpert-ai/plugin-sdk';
3
4
  import { OpenAICredentials } from './types.js';
4
5
  export declare class OpenAIProviderStrategy extends ModelProvider {
5
6
  logger: Logger;
7
+ readonly getNativeModelClient: NativeModelClientFactory;
6
8
  getBaseUrl(credentials: OpenAICredentials): string;
7
9
  getAuthorization(credentials: OpenAICredentials): string;
8
10
  validateProviderCredentials(credentials: OpenAICredentials): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"provider.strategy.d.ts","sourceRoot":"","sources":["../src/provider.strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAGL,aAAa,EACd,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EAEL,iBAAiB,EAElB,MAAM,YAAY,CAAA;AAyBnB,qBAEa,sBAAuB,SAAQ,aAAa;IAC9C,MAAM,SAA0C;IAEzD,UAAU,CAAC,WAAW,EAAE,iBAAiB,GAAG,MAAM;IAKlD,gBAAgB,CAAC,WAAW,EAAE,iBAAiB,GAAG,MAAM;IAIlD,2BAA2B,CAAC,WAAW,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;CAoCjF"}
1
+ {"version":3,"file":"provider.strategy.d.ts","sourceRoot":"","sources":["../src/provider.strategy.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,KAAK,wBAAwB,EAAsB,MAAM,sBAAsB,CAAA;AAC9G,OAAO,EAAc,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAGL,aAAa,EACd,MAAM,sBAAsB,CAAA;AAG7B,OAAO,EAEL,iBAAiB,EAGlB,MAAM,YAAY,CAAA;AAuBnB,qBAEa,sBAAuB,SAAQ,aAAa;IAC9C,MAAM,SAA0C;IAEzD,QAAQ,CAAC,oBAAoB,EAAE,wBAAwB,CAStD;IAED,UAAU,CAAC,WAAW,EAAE,iBAAiB,GAAG,MAAM;IAKlD,gBAAgB,CAAC,WAAW,EAAE,iBAAiB,GAAG,MAAM;IAIlD,2BAA2B,CAAC,WAAW,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;CAwCjF"}
@@ -1,10 +1,12 @@
1
1
  var OpenAIProviderStrategy_1;
2
2
  import { __decorate } from "tslib";
3
+ import { z } from 'zod';
4
+ import { nativeModelTransport } from '@xpert-ai/plugin-sdk';
3
5
  import { Injectable, Logger } from '@nestjs/common';
4
6
  import { AIModelProviderStrategy, CredentialsValidateFailedError, ModelProvider, } from '@xpert-ai/plugin-sdk';
5
- import { AiModelTypeEnum } from '@metad/contracts';
6
- import { OpenAIProvider, toCredentialKwargs, } from './types.js';
7
- const OpenAIValidationModels = ['gpt-5.4', 'gpt-5', 'gpt-5.2'];
7
+ import { AiModelTypeEnum } from '@xpert-ai/contracts';
8
+ import { OpenAIClient } from '@langchain/openai';
9
+ import { OpenAIProvider, toCredentialKwargs, isOpenAIOfficialBaseUrl, } from './types.js';
8
10
  const OpenAIValidationFallbackPatterns = [
9
11
  'model is not supported',
10
12
  'unsupported model',
@@ -27,6 +29,16 @@ let OpenAIProviderStrategy = OpenAIProviderStrategy_1 = class OpenAIProviderStra
27
29
  constructor() {
28
30
  super(...arguments);
29
31
  this.logger = new Logger(OpenAIProviderStrategy_1.name);
32
+ this.getNativeModelClient = async (protocol, model) => {
33
+ if (protocol !== 'openai_responses' || !this.getProviderModels(AiModelTypeEnum.LLM)
34
+ .some((entry) => entry.model === model.model && entry.native_protocols?.includes(protocol)))
35
+ throw new Error('Native model protocol is unavailable');
36
+ const parsed = z.object({ api_key: z.string().min(1), endpoint_url: z.string().optional() }).passthrough().parse(model.copilot?.modelProvider?.credentials);
37
+ const credentials = { api_key: parsed.api_key, endpoint_url: parsed.endpoint_url };
38
+ const manager = this.getModelManager(AiModelTypeEnum.LLM);
39
+ return { protocol, generate: nativeModelTransport({ protocol, baseUrl: this.getBaseUrl(credentials), authorization: this.getAuthorization(credentials) }),
40
+ priceUsage: (usage, context) => manager.priceActualTokenUsage(model.model, usage, context) };
41
+ };
30
42
  }
31
43
  getBaseUrl(credentials) {
32
44
  const params = toCredentialKwargs(credentials);
@@ -36,34 +48,42 @@ let OpenAIProviderStrategy = OpenAIProviderStrategy_1 = class OpenAIProviderStra
36
48
  return `Bearer ${credentials.api_key}`;
37
49
  }
38
50
  async validateProviderCredentials(credentials) {
51
+ const params = toCredentialKwargs(credentials);
52
+ if (isOpenAIOfficialBaseUrl(params.configuration.baseURL)) {
53
+ // Authentication must not depend on access to an older generation's probe model.
54
+ try {
55
+ const client = new OpenAIClient({ apiKey: params.apiKey, ...params.configuration });
56
+ await client.models.list();
57
+ return;
58
+ }
59
+ catch (error) {
60
+ throw new CredentialsValidateFailedError(error instanceof Error ? error.message : 'OpenAI credentials verification failed');
61
+ }
62
+ }
39
63
  const modelInstance = this.getModelManager(AiModelTypeEnum.LLM);
64
+ const models = this.getProviderModels(AiModelTypeEnum.LLM);
40
65
  let lastError;
41
- for (const model of OpenAIValidationModels) {
66
+ for (const { model } of models) {
42
67
  try {
43
68
  await modelInstance.validateCredentials(model, credentials);
44
69
  return;
45
70
  }
46
71
  catch (ex) {
47
- lastError = ex;
48
72
  if (!shouldRetryWithNextValidationModel(ex)) {
49
73
  if (ex instanceof CredentialsValidateFailedError) {
50
74
  throw ex;
51
75
  }
52
76
  else {
53
- this.logger.error(`${this.getProviderSchema().provider}: credentials verification failed`, ex?.stack);
77
+ this.logger.error(`${this.getProviderSchema().provider}: credentials verification failed`, ex instanceof Error ? ex.stack : undefined);
54
78
  throw ex;
55
79
  }
56
80
  }
81
+ if (ex instanceof CredentialsValidateFailedError)
82
+ lastError = ex;
57
83
  this.logger.warn(`${this.getProviderSchema().provider}: validation model '${model}' unavailable, trying next candidate`);
58
84
  }
59
85
  }
60
- if (lastError instanceof CredentialsValidateFailedError) {
61
- throw lastError;
62
- }
63
- else {
64
- this.logger.error(`${this.getProviderSchema().provider}: credentials verification failed`, lastError?.stack);
65
- throw lastError;
66
- }
86
+ throw lastError ?? new CredentialsValidateFailedError('No OpenAI models are available for credentials verification');
67
87
  }
68
88
  };
69
89
  OpenAIProviderStrategy = OpenAIProviderStrategy_1 = __decorate([
package/dist/types.d.ts CHANGED
@@ -9,8 +9,8 @@ export interface OpenAICredentials {
9
9
  endpoint_url?: string;
10
10
  sampling_parameters?: 'auto' | 'enabled' | 'disabled';
11
11
  }
12
- export type OpenAIReasoningEffort = 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
13
- export interface OpenAIModelOptions extends CommonChatModelParameters {
12
+ export type OpenAIReasoningEffort = 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';
13
+ export interface OpenAIModelOptions extends Partial<CommonChatModelParameters> {
14
14
  streaming?: boolean;
15
15
  top_p?: number;
16
16
  max_tokens?: number;
@@ -24,7 +24,7 @@ export declare function isOpenAIOfficialBaseUrl(baseURL?: string): boolean;
24
24
  export declare function isOpenAIGPT5ProModel(model?: string): boolean;
25
25
  export declare function getSupportedOpenAIReasoningEfforts(model?: string): readonly OpenAIReasoningEffort[] | undefined;
26
26
  export declare function normalizeOpenAIReasoningEffort(model?: string, effort?: OpenAIReasoningEffort): OpenAIReasoningEffort | undefined;
27
- export declare function shouldEnableSamplingParameters(mode: OpenAICredentials['sampling_parameters'], baseURL?: string, model?: string): boolean;
27
+ export declare function shouldEnableSamplingParameters(mode: OpenAICredentials['sampling_parameters'], baseURL?: string, model?: string, reasoningEffort?: OpenAIReasoningEffort): boolean;
28
28
  export declare function shouldEnableResponseFormat(baseURL?: string, model?: string): boolean;
29
29
  export declare function normalizeOpenAIMaxTokens(maxTokens?: number, baseURL?: string): number | undefined;
30
30
  export declare function toCredentialKwargs(credentials: OpenAICredentials): {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAmB,MAAM,mBAAmB,CAAA;AAClE,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAA;AAOhE,eAAO,MAAM,cAAc,WAAW,CAAA;AACtC,eAAO,MAAM,oBAAoB,8BAA8B,CAAA;AAC/D,eAAO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Aa,CAAA;CACxC;AAID,wBAAgB,sBAAsB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAuBnE;AAED,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAWjE;AAED,wBAAgB,oBAAoB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAE5D;AAED,wBAAgB,kCAAkC,CACjD,KAAK,CAAC,EAAE,MAAM,GACZ,SAAS,qBAAqB,EAAE,GAAG,SAAS,CAO9C;AAED,wBAAgB,8BAA8B,CAC7C,KAAK,CAAC,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,qBAAqB,GAC5B,qBAAqB,GAAG,SAAS,CA+BnC;AAED,wBAAgB,8BAA8B,CAC7C,IAAI,EAAE,iBAAiB,CAAC,qBAAqB,CAAC,EAC9C,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,EACd,eAAe,CAAC,EAAE,qBAAqB,GACrC,OAAO,CAuBT;AAED,wBAAgB,0BAA0B,CACzC,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,GACZ,OAAO,CAMT;AAED,wBAAgB,wBAAwB,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAUjG;AAED,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,iBAAiB;;;;;;;;;;;;;;;;;;;;;;EAYhE"}
package/dist/types.js CHANGED
@@ -8,6 +8,16 @@ export const OpenAIResponsesMinOutputTokens = 16;
8
8
  const OpenAIApiVersionPath = '/v1';
9
9
  const OpenAIOfficialHost = 'api.openai.com';
10
10
  export const SvgIcon = readFileSync(join(moduleDir, '_assets/icon_s_en.svg'), 'utf8');
11
+ const OpenAICurrentModelProfiles = [
12
+ { model: 'gpt-6-astra', supported: ['low', 'medium', 'high', 'xhigh', 'max'], defaultEffort: 'medium' },
13
+ { model: 'gpt-6.1-sol', supported: ['low', 'medium', 'high', 'xhigh', 'max'], defaultEffort: 'medium' },
14
+ { model: 'gpt-6.1-terra', supported: ['none', 'low', 'medium', 'high', 'xhigh', 'max'], defaultEffort: 'medium' },
15
+ { model: 'gpt-6-luna', supported: ['none', 'low', 'medium', 'high', 'xhigh', 'max'], defaultEffort: 'medium' },
16
+ { model: 'gpt-6-sol', supported: ['none', 'low', 'medium', 'high', 'xhigh', 'max'], defaultEffort: 'medium' },
17
+ ];
18
+ function getCurrentModelProfile(model) {
19
+ return OpenAICurrentModelProfiles.find((profile) => profile.model === model?.trim());
20
+ }
11
21
  const OpenAIReasoningEffortScale = [
12
22
  'none',
13
23
  'minimal',
@@ -15,6 +25,7 @@ const OpenAIReasoningEffortScale = [
15
25
  'medium',
16
26
  'high',
17
27
  'xhigh',
28
+ 'max',
18
29
  ];
19
30
  const OpenAIReasoningEffortProfiles = [
20
31
  {
@@ -76,11 +87,16 @@ export function getSupportedOpenAIReasoningEfforts(model) {
76
87
  if (!model?.trim()) {
77
88
  return undefined;
78
89
  }
79
- return OpenAIReasoningEffortProfiles.find(({ pattern }) => pattern.test(model.trim()))?.supported;
90
+ return getCurrentModelProfile(model)?.supported ??
91
+ OpenAIReasoningEffortProfiles.find(({ pattern }) => pattern.test(model.trim()))?.supported;
80
92
  }
81
93
  export function normalizeOpenAIReasoningEffort(model, effort) {
94
+ const currentProfile = getCurrentModelProfile(model);
82
95
  if (!effort) {
83
- return undefined;
96
+ return currentProfile?.defaultEffort;
97
+ }
98
+ if (currentProfile && effort === 'minimal') {
99
+ return 'low';
84
100
  }
85
101
  const supported = getSupportedOpenAIReasoningEfforts(model);
86
102
  if (!supported?.length) {
@@ -101,7 +117,16 @@ export function normalizeOpenAIReasoningEffort(model, effort) {
101
117
  return candidateDistance < closestDistance ? candidate : closest;
102
118
  });
103
119
  }
104
- export function shouldEnableSamplingParameters(mode, baseURL, model) {
120
+ export function shouldEnableSamplingParameters(mode, baseURL, model, reasoningEffort) {
121
+ // An endpoint override must not send parameters forbidden by the official model contract.
122
+ // GPT-5.2 and GPT-5.4 default to none when the request omits reasoning effort.
123
+ const defaultsToNone = model?.trim() === 'gpt-5.2' || model?.trim() === 'gpt-5.4';
124
+ const effectiveEffort = normalizeOpenAIReasoningEffort(model, reasoningEffort) ??
125
+ (defaultsToNone ? 'none' : undefined);
126
+ if (isOpenAIOfficialBaseUrl(baseURL) && getSupportedOpenAIReasoningEfforts(model) &&
127
+ effectiveEffort !== 'none') {
128
+ return false;
129
+ }
105
130
  if (mode === 'enabled') {
106
131
  return true;
107
132
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xpert-ai/plugin-openai",
3
- "version": "0.0.5",
4
- "description": "OpenAI GPT-5 model plugin for XpertAI platform using Responses API",
3
+ "version": "0.2.0",
4
+ "description": "OpenAI GPT-6 and GPT-5 model plugin for XpertAI platform using Responses API",
5
5
  "author": {
6
6
  "name": "XpertAI",
7
7
  "url": "https://xpertai.cn"
@@ -35,11 +35,11 @@
35
35
  "tslib": "^2.3.0"
36
36
  },
37
37
  "peerDependencies": {
38
- "@xpert-ai/plugin-sdk": "^3.7.2",
38
+ "@xpert-ai/plugin-sdk": "^3.20.0",
39
39
  "@nestjs/config": "^4.0.2",
40
40
  "chalk": "4.1.2",
41
41
  "zod": "3.25.67",
42
- "@metad/contracts": "^3.7.0",
42
+ "@xpert-ai/contracts": "^3.20.0",
43
43
  "@nestjs/common": "^11.1.6",
44
44
  "@langchain/core": "^0.3.72",
45
45
  "@langchain/openai": "0.6.9",
@@ -1,77 +0,0 @@
1
- model: gpt-5.2-chat
2
- label:
3
- en_US: GPT-5.2 Chat
4
- zh_Hans: GPT-5.2 Chat
5
- model_type: llm
6
- features:
7
- - agent-thought
8
- - tool-call
9
- - multi-tool-call
10
- - stream-tool-call
11
- - structured-output
12
- - vision
13
- model_properties:
14
- mode: chat
15
- context_size: 128000
16
- max_output: 16384
17
- parameter_rules:
18
- - name: temperature
19
- use_template: temperature
20
- default: 1
21
- min: 0.0
22
- max: 2.0
23
- help:
24
- zh_Hans: 采样温度,控制输出的随机性。
25
- en_US: Sampling temperature, controls the randomness of the output.
26
- - name: max_tokens
27
- use_template: max_tokens
28
- default: 4096
29
- min: 16
30
- max: 16384
31
- help:
32
- zh_Hans: 最大输出 token 数量。
33
- en_US: Maximum number of output tokens.
34
- - name: top_p
35
- use_template: top_p
36
- default: 1
37
- min: 0.0
38
- max: 1.0
39
- help:
40
- zh_Hans: 核采样参数,控制输出的多样性。
41
- en_US: Nucleus sampling parameter, controls output diversity.
42
- - name: frequency_penalty
43
- use_template: frequency_penalty
44
- default: 0
45
- min: -2.0
46
- max: 2.0
47
- help:
48
- zh_Hans: 降低重复内容的出现频率。
49
- en_US: Reduces repetition in the output.
50
- - name: presence_penalty
51
- label:
52
- zh_Hans: 存在惩罚
53
- en_US: Presence Penalty
54
- type: float
55
- default: 0
56
- min: -2.0
57
- max: 2.0
58
- help:
59
- zh_Hans: 提高讨论新话题的可能性。
60
- en_US: Increases the likelihood of discussing new topics.
61
- - name: response_format
62
- label:
63
- zh_Hans: 回复格式
64
- en_US: Response Format
65
- type: string
66
- help:
67
- zh_Hans: 指定模型必须输出的格式。
68
- en_US: Specifying the format that the model must output.
69
- required: false
70
- options:
71
- - text
72
- - json_object
73
- pricing:
74
- input: '1.75'
75
- output: '14'
76
- unit: '0.000001'
77
- currency: USD
@@ -1,92 +0,0 @@
1
- model: gpt-5.2-codex
2
- label:
3
- en_US: GPT-5.2 Codex
4
- zh_Hans: GPT-5.2 Codex
5
- model_type: llm
6
- features:
7
- - agent-thought
8
- - tool-call
9
- - multi-tool-call
10
- - stream-tool-call
11
- - structured-output
12
- - vision
13
- model_properties:
14
- mode: chat
15
- context_size: 400000
16
- max_output: 128000
17
- parameter_rules:
18
- - name: temperature
19
- use_template: temperature
20
- default: 1
21
- min: 0.0
22
- max: 2.0
23
- help:
24
- zh_Hans: 采样温度,控制输出的随机性。
25
- en_US: Sampling temperature, controls the randomness of the output.
26
- - name: max_tokens
27
- use_template: max_tokens
28
- default: 32768
29
- min: 16
30
- max: 128000
31
- help:
32
- zh_Hans: 最大输出 token 数量。
33
- en_US: Maximum number of output tokens.
34
- - name: top_p
35
- use_template: top_p
36
- default: 1
37
- min: 0.0
38
- max: 1.0
39
- help:
40
- zh_Hans: 核采样参数,控制输出的多样性。
41
- en_US: Nucleus sampling parameter, controls output diversity.
42
- - name: reasoning_effort
43
- label:
44
- zh_Hans: 推理力度
45
- en_US: Reasoning Effort
46
- type: string
47
- required: false
48
- default: medium
49
- options:
50
- - low
51
- - medium
52
- - high
53
- - xhigh
54
- help:
55
- zh_Hans: 控制模型推理的深度。xhigh 提供最深推理,适合更复杂的编码任务。
56
- en_US: Controls how much reasoning effort the model uses. xhigh provides the deepest reasoning for more complex coding tasks.
57
- - name: frequency_penalty
58
- use_template: frequency_penalty
59
- default: 0
60
- min: -2.0
61
- max: 2.0
62
- help:
63
- zh_Hans: 降低重复内容的出现频率。
64
- en_US: Reduces repetition in the output.
65
- - name: presence_penalty
66
- label:
67
- zh_Hans: 存在惩罚
68
- en_US: Presence Penalty
69
- type: float
70
- default: 0
71
- min: -2.0
72
- max: 2.0
73
- help:
74
- zh_Hans: 提高讨论新话题的可能性。
75
- en_US: Increases the likelihood of discussing new topics.
76
- - name: response_format
77
- label:
78
- zh_Hans: 回复格式
79
- en_US: Response Format
80
- type: string
81
- help:
82
- zh_Hans: 指定模型必须输出的格式。
83
- en_US: Specifying the format that the model must output.
84
- required: false
85
- options:
86
- - text
87
- - json_object
88
- pricing:
89
- input: '1.75'
90
- output: '14'
91
- unit: '0.000001'
92
- currency: USD
@@ -1,62 +0,0 @@
1
- model: gpt-5.4-pro
2
- label:
3
- en_US: GPT-5.4 Pro
4
- zh_Hans: GPT-5.4 Pro
5
- model_type: llm
6
- features:
7
- - agent-thought
8
- - tool-call
9
- - multi-tool-call
10
- - stream-tool-call
11
- - vision
12
- model_properties:
13
- mode: chat
14
- context_size: 400000
15
- max_output: 128000
16
- parameter_rules:
17
- - name: max_tokens
18
- use_template: max_tokens
19
- default: 32768
20
- min: 16
21
- max: 128000
22
- help:
23
- zh_Hans: 最大输出 token 数量。
24
- en_US: Maximum number of output tokens.
25
- - name: reasoning_effort
26
- label:
27
- zh_Hans: 推理力度
28
- en_US: Reasoning Effort
29
- type: string
30
- required: false
31
- default: medium
32
- options:
33
- - medium
34
- - high
35
- - xhigh
36
- help:
37
- zh_Hans: 控制模型推理的深度。Pro 模型从 medium 起步,xhigh 适合最复杂的问题。
38
- en_US: Controls how much reasoning effort the model uses. Pro models start at medium, while xhigh is best for the hardest problems.
39
- - name: frequency_penalty
40
- use_template: frequency_penalty
41
- default: 0
42
- min: -2.0
43
- max: 2.0
44
- help:
45
- zh_Hans: 降低重复内容的出现频率。
46
- en_US: Reduces repetition in the output.
47
- - name: presence_penalty
48
- label:
49
- zh_Hans: 存在惩罚
50
- en_US: Presence Penalty
51
- type: float
52
- default: 0
53
- min: -2.0
54
- max: 2.0
55
- help:
56
- zh_Hans: 提高讨论新话题的可能性。
57
- en_US: Increases the likelihood of discussing new topics.
58
- pricing:
59
- input: '25'
60
- output: '200'
61
- unit: '0.000001'
62
- currency: USD
@@ -1,93 +0,0 @@
1
- model: gpt-5.4
2
- label:
3
- en_US: GPT-5.4
4
- zh_Hans: GPT-5.4
5
- model_type: llm
6
- features:
7
- - agent-thought
8
- - tool-call
9
- - multi-tool-call
10
- - stream-tool-call
11
- - structured-output
12
- - vision
13
- model_properties:
14
- mode: chat
15
- context_size: 400000
16
- max_output: 128000
17
- parameter_rules:
18
- - name: temperature
19
- use_template: temperature
20
- default: 1
21
- min: 0.0
22
- max: 2.0
23
- help:
24
- zh_Hans: 采样温度,控制输出的随机性。
25
- en_US: Sampling temperature, controls the randomness of the output.
26
- - name: max_tokens
27
- use_template: max_tokens
28
- default: 32768
29
- min: 16
30
- max: 128000
31
- help:
32
- zh_Hans: 最大输出 token 数量。GPT-5.4 支持最大 128K 输出。
33
- en_US: Maximum number of output tokens. GPT-5.4 supports up to 128K output.
34
- - name: top_p
35
- use_template: top_p
36
- default: 1
37
- min: 0.0
38
- max: 1.0
39
- help:
40
- zh_Hans: 核采样参数,控制输出的多样性。
41
- en_US: Nucleus sampling parameter, controls output diversity.
42
- - name: reasoning_effort
43
- label:
44
- zh_Hans: 推理力度
45
- en_US: Reasoning Effort
46
- type: string
47
- required: false
48
- default: none
49
- options:
50
- - none
51
- - low
52
- - medium
53
- - high
54
- - xhigh
55
- help:
56
- zh_Hans: 控制模型推理的深度。none 为默认值,xhigh 提供最深推理但通常延迟更高。
57
- en_US: Controls how much reasoning effort the model uses. none is the default, while xhigh provides the deepest reasoning at higher latency.
58
- - name: frequency_penalty
59
- use_template: frequency_penalty
60
- default: 0
61
- min: -2.0
62
- max: 2.0
63
- help:
64
- zh_Hans: 降低重复内容的出现频率。
65
- en_US: Reduces repetition in the output.
66
- - name: presence_penalty
67
- label:
68
- zh_Hans: 存在惩罚
69
- en_US: Presence Penalty
70
- type: float
71
- default: 0
72
- min: -2.0
73
- max: 2.0
74
- help:
75
- zh_Hans: 提高讨论新话题的可能性。
76
- en_US: Increases the likelihood of discussing new topics.
77
- - name: response_format
78
- label:
79
- zh_Hans: 回复格式
80
- en_US: Response Format
81
- type: string
82
- help:
83
- zh_Hans: 指定模型必须输出的格式。
84
- en_US: Specifying the format that the model must output.
85
- required: false
86
- options:
87
- - text
88
- - json_object
89
- pricing:
90
- input: '2'
91
- output: '16'
92
- unit: '0.000001'
93
- currency: USD