@xpert-ai/plugin-openai 0.0.3 → 0.0.4

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.
@@ -47,13 +47,13 @@ parameter_rules:
47
47
  required: false
48
48
  default: medium
49
49
  options:
50
- - minimal
51
50
  - low
52
51
  - medium
53
52
  - high
53
+ - xhigh
54
54
  help:
55
- zh_Hans: 控制模型推理的深度。high 提供最深度的推理,minimal 适合更快的响应。
56
- en_US: Controls how much reasoning effort the model uses. high provides the deepest reasoning, while minimal favors faster responses.
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
57
  - name: frequency_penalty
58
58
  use_template: frequency_penalty
59
59
  default: 0
@@ -30,13 +30,12 @@ parameter_rules:
30
30
  required: false
31
31
  default: medium
32
32
  options:
33
- - minimal
34
- - low
35
33
  - medium
36
34
  - high
35
+ - xhigh
37
36
  help:
38
- zh_Hans: 控制模型推理的深度。high 提供最深度的推理,minimal 适合更快的响应。
39
- en_US: Controls how much reasoning effort the model uses. high provides the deepest reasoning, while minimal favors faster responses.
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.
40
39
  - name: frequency_penalty
41
40
  use_template: frequency_penalty
42
41
  default: 0
@@ -45,15 +45,16 @@ parameter_rules:
45
45
  en_US: Reasoning Effort
46
46
  type: string
47
47
  required: false
48
- default: medium
48
+ default: none
49
49
  options:
50
- - minimal
50
+ - none
51
51
  - low
52
52
  - medium
53
53
  - high
54
+ - xhigh
54
55
  help:
55
- zh_Hans: 控制模型推理的深度。high 提供最深度的推理,minimal 适合更快的响应。
56
- en_US: Controls how much reasoning effort the model uses. high provides the deepest reasoning, while minimal favors faster responses.
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.
57
58
  - name: frequency_penalty
58
59
  use_template: frequency_penalty
59
60
  default: 0
@@ -47,13 +47,13 @@ parameter_rules:
47
47
  required: false
48
48
  default: medium
49
49
  options:
50
- - minimal
51
50
  - low
52
51
  - medium
53
52
  - high
53
+ - xhigh
54
54
  help:
55
- zh_Hans: 控制模型推理的深度。high 提供最深度的推理,minimal 适合更快的响应。
56
- en_US: Controls how much reasoning effort the model uses. high provides the deepest reasoning, while minimal favors faster responses.
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
57
  - name: frequency_penalty
58
58
  use_template: frequency_penalty
59
59
  default: 0
@@ -30,13 +30,12 @@ parameter_rules:
30
30
  required: false
31
31
  default: medium
32
32
  options:
33
- - minimal
34
- - low
35
33
  - medium
36
34
  - high
35
+ - xhigh
37
36
  help:
38
- zh_Hans: 控制模型推理的深度。high 提供最深度的推理,minimal 适合更快的响应。
39
- en_US: Controls how much reasoning effort the model uses. high provides the deepest reasoning, while minimal favors faster responses.
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.
40
39
  - name: frequency_penalty
41
40
  use_template: frequency_penalty
42
41
  default: 0
@@ -45,15 +45,16 @@ parameter_rules:
45
45
  en_US: Reasoning Effort
46
46
  type: string
47
47
  required: false
48
- default: medium
48
+ default: none
49
49
  options:
50
- - minimal
50
+ - none
51
51
  - low
52
52
  - medium
53
53
  - high
54
+ - xhigh
54
55
  help:
55
- zh_Hans: 控制模型推理的深度。high 提供最深度的推理,minimal 适合更快的响应。
56
- en_US: Controls how much reasoning effort the model uses. high provides the deepest reasoning, while minimal favors faster responses.
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.
57
58
  - name: frequency_penalty
58
59
  use_template: frequency_penalty
59
60
  default: 0
package/dist/llm/llm.d.ts CHANGED
@@ -8,6 +8,8 @@ export declare class OpenAILargeLanguageModel extends LargeLanguageModel {
8
8
  readonly modelProvider: OpenAIProviderStrategy;
9
9
  constructor(modelProvider: OpenAIProviderStrategy);
10
10
  validateCredentials(model: string, credentials: OpenAICredentials): Promise<void>;
11
+ private getReasoningOptions;
12
+ private toLangChainReasoning;
11
13
  getChatModel(copilotModel: ICopilotModel, options?: TChatModelOptions): ChatOpenAI<import("@langchain/openai").ChatOpenAICallOptions>;
12
14
  }
13
15
  //# sourceMappingURL=llm.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"llm.d.ts","sourceRoot":"","sources":["../../src/llm/llm.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAmB,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAEjE,OAAO,EAGL,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EACL,iBAAiB,EAKlB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAEhE,qBACa,wBAAyB,SAAQ,kBAAkB;;aAGhC,aAAa,EAAE,sBAAsB;gBAArC,aAAa,EAAE,sBAAsB;IAI7D,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAgB9E,YAAY,CAAC,YAAY,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,iBAAiB;CAyD/E"}
1
+ {"version":3,"file":"llm.d.ts","sourceRoot":"","sources":["../../src/llm/llm.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAgB,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAmB,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAEjE,OAAO,EAGL,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EAGL,iBAAiB,EAKlB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAOhE,qBACa,wBAAyB,SAAQ,kBAAkB;;aAGhC,aAAa,EAAE,sBAAsB;gBAArC,aAAa,EAAE,sBAAsB;IAI7D,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBvF,OAAO,CAAC,mBAAmB;IAW3B,OAAO,CAAC,oBAAoB;IAInB,YAAY,CAAC,YAAY,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,iBAAiB;CA+D/E"}
package/dist/llm/llm.js CHANGED
@@ -7,8 +7,9 @@ import { AiModelTypeEnum } from '@metad/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';
10
- import { shouldEnableResponseFormat, shouldEnableSamplingParameters, toCredentialKwargs } from '../types.js';
10
+ import { getSupportedOpenAIReasoningEfforts, normalizeOpenAIReasoningEffort, shouldEnableResponseFormat, shouldEnableSamplingParameters, toCredentialKwargs } from '../types.js';
11
11
  import { OpenAIProviderStrategy } from '../provider.strategy.js';
12
+ import { OpenAIReasoningResponsesModel } from './reasoning.js';
12
13
  let OpenAILargeLanguageModel = OpenAILargeLanguageModel_1 = class OpenAILargeLanguageModel extends LargeLanguageModel {
13
14
  #logger = new Logger(OpenAILargeLanguageModel_1.name);
14
15
  constructor(modelProvider) {
@@ -31,6 +32,18 @@ let OpenAILargeLanguageModel = OpenAILargeLanguageModel_1 = class OpenAILargeLan
31
32
  throw new CredentialsValidateFailedError(getErrorMessage(err));
32
33
  }
33
34
  }
35
+ getReasoningOptions(model, reasoningEffort) {
36
+ if (!getSupportedOpenAIReasoningEfforts(model)) {
37
+ return undefined;
38
+ }
39
+ return {
40
+ ...(reasoningEffort ? { effort: reasoningEffort } : {}),
41
+ summary: 'auto'
42
+ };
43
+ }
44
+ toLangChainReasoning(reasoning) {
45
+ return reasoning;
46
+ }
34
47
  getChatModel(copilotModel, options) {
35
48
  const { handleLLMTokens } = options ?? {};
36
49
  const { copilot } = copilotModel;
@@ -42,6 +55,9 @@ let OpenAILargeLanguageModel = OpenAILargeLanguageModel_1 = class OpenAILargeLan
42
55
  const hasCustomEndpoint = !!credentials?.endpoint_url?.trim();
43
56
  const streaming = modelOptions?.streaming ?? !hasCustomEndpoint;
44
57
  const supportsSamplingParams = shouldEnableSamplingParameters(credentials?.sampling_parameters, params.configuration?.baseURL, model);
58
+ const reasoningEffort = normalizeOpenAIReasoningEffort(model, modelOptions?.reasoning_effort);
59
+ const reasoning = this.getReasoningOptions(model, reasoningEffort);
60
+ const langChainReasoning = this.toLangChainReasoning(reasoning);
45
61
  const supportsResponseFormat = shouldEnableResponseFormat(params.configuration?.baseURL, model);
46
62
  const responseFormat = supportsResponseFormat && modelOptions?.response_format
47
63
  ? { type: modelOptions.response_format }
@@ -57,9 +73,12 @@ let OpenAILargeLanguageModel = OpenAILargeLanguageModel_1 = class OpenAILargeLan
57
73
  presencePenalty: modelOptions?.presence_penalty,
58
74
  maxRetries: modelOptions?.maxRetries,
59
75
  useResponsesApi: true,
60
- reasoning: modelOptions?.reasoning_effort
61
- ? { effort: modelOptions.reasoning_effort }
62
- : undefined,
76
+ reasoning: langChainReasoning,
77
+ responses: new OpenAIReasoningResponsesModel({
78
+ ...params,
79
+ model,
80
+ reasoning: langChainReasoning
81
+ }),
63
82
  streamUsage: streaming,
64
83
  }, isNil);
65
84
  const chatModel = new ChatOpenAI({
@@ -0,0 +1,8 @@
1
+ import { AIMessage } from '@langchain/core/messages';
2
+ import { ChatGenerationChunk } from '@langchain/core/outputs';
3
+ import { ChatOpenAIResponses, OpenAIClient } from '@langchain/openai';
4
+ export declare class OpenAIReasoningResponsesModel extends ChatOpenAIResponses {
5
+ protected _convertResponsesMessageToBaseMessage(response: OpenAIClient.Responses.Response): AIMessage;
6
+ protected _convertResponsesDeltaToBaseMessageChunk(chunk: OpenAIClient.Responses.ResponseStreamEvent): ChatGenerationChunk | null;
7
+ }
8
+ //# sourceMappingURL=reasoning.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,54 @@
1
+ import { ChatOpenAIResponses } from '@langchain/openai';
2
+ function extractReasoningSummaryText(reasoning) {
3
+ if (!reasoning || typeof reasoning !== 'object') {
4
+ return undefined;
5
+ }
6
+ const summary = reasoning.summary;
7
+ if (!Array.isArray(summary)) {
8
+ return undefined;
9
+ }
10
+ const text = summary
11
+ .map((item) => (typeof item?.text === 'string' ? item.text : ''))
12
+ .join('')
13
+ .trim();
14
+ return text || undefined;
15
+ }
16
+ function extractReasoningDeltaText(chunk) {
17
+ if (chunk.type === 'response.reasoning_summary_text.delta') {
18
+ return chunk.delta || undefined;
19
+ }
20
+ if (chunk.type === 'response.reasoning_summary_part.added' && typeof chunk.part?.text === 'string') {
21
+ return chunk.part.text || undefined;
22
+ }
23
+ return undefined;
24
+ }
25
+ export class OpenAIReasoningResponsesModel extends ChatOpenAIResponses {
26
+ _convertResponsesMessageToBaseMessage(response) {
27
+ const message = super._convertResponsesMessageToBaseMessage(response);
28
+ const reasoningContent = extractReasoningSummaryText(message.additional_kwargs?.reasoning);
29
+ if (reasoningContent) {
30
+ message.additional_kwargs = {
31
+ ...message.additional_kwargs,
32
+ reasoning_content: reasoningContent
33
+ };
34
+ }
35
+ return message;
36
+ }
37
+ _convertResponsesDeltaToBaseMessageChunk(chunk) {
38
+ const generationChunk = super._convertResponsesDeltaToBaseMessageChunk(chunk);
39
+ if (!generationChunk) {
40
+ return null;
41
+ }
42
+ const message = generationChunk.message;
43
+ const reasoningContent = extractReasoningDeltaText(chunk) ?? extractReasoningSummaryText(message.additional_kwargs?.reasoning);
44
+ if (reasoningContent) {
45
+ message.additional_kwargs = {
46
+ ...message.additional_kwargs,
47
+ reasoning_content: reasoningContent
48
+ };
49
+ message.content = '';
50
+ generationChunk.text = '';
51
+ }
52
+ return generationChunk;
53
+ }
54
+ }
@@ -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;AAEnB,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;CAajF"}
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"}
@@ -4,6 +4,25 @@ import { Injectable, Logger } from '@nestjs/common';
4
4
  import { AIModelProviderStrategy, CredentialsValidateFailedError, ModelProvider, } from '@xpert-ai/plugin-sdk';
5
5
  import { AiModelTypeEnum } from '@metad/contracts';
6
6
  import { OpenAIProvider, toCredentialKwargs, } from './types.js';
7
+ const OpenAIValidationModels = ['gpt-5.4', 'gpt-5', 'gpt-5.2'];
8
+ const OpenAIValidationFallbackPatterns = [
9
+ 'model is not supported',
10
+ 'unsupported model',
11
+ 'does not exist',
12
+ 'unknown model',
13
+ 'invalid model',
14
+ 'unrecognized model',
15
+ 'no such model',
16
+ 'not found',
17
+ 'not available',
18
+ ];
19
+ function shouldRetryWithNextValidationModel(error) {
20
+ if (!(error instanceof CredentialsValidateFailedError)) {
21
+ return false;
22
+ }
23
+ const message = error.message.toLowerCase();
24
+ return OpenAIValidationFallbackPatterns.some((pattern) => message.includes(pattern));
25
+ }
7
26
  let OpenAIProviderStrategy = OpenAIProviderStrategy_1 = class OpenAIProviderStrategy extends ModelProvider {
8
27
  constructor() {
9
28
  super(...arguments);
@@ -17,19 +36,34 @@ let OpenAIProviderStrategy = OpenAIProviderStrategy_1 = class OpenAIProviderStra
17
36
  return `Bearer ${credentials.api_key}`;
18
37
  }
19
38
  async validateProviderCredentials(credentials) {
20
- try {
21
- const modelInstance = this.getModelManager(AiModelTypeEnum.LLM);
22
- await modelInstance.validateCredentials('gpt-5', credentials);
23
- }
24
- catch (ex) {
25
- if (ex instanceof CredentialsValidateFailedError) {
26
- throw ex;
39
+ const modelInstance = this.getModelManager(AiModelTypeEnum.LLM);
40
+ let lastError;
41
+ for (const model of OpenAIValidationModels) {
42
+ try {
43
+ await modelInstance.validateCredentials(model, credentials);
44
+ return;
27
45
  }
28
- else {
29
- this.logger.error(`${this.getProviderSchema().provider}: credentials verification failed`, ex.stack);
30
- throw ex;
46
+ catch (ex) {
47
+ lastError = ex;
48
+ if (!shouldRetryWithNextValidationModel(ex)) {
49
+ if (ex instanceof CredentialsValidateFailedError) {
50
+ throw ex;
51
+ }
52
+ else {
53
+ this.logger.error(`${this.getProviderSchema().provider}: credentials verification failed`, ex?.stack);
54
+ throw ex;
55
+ }
56
+ }
57
+ this.logger.warn(`${this.getProviderSchema().provider}: validation model '${model}' unavailable, trying next candidate`);
31
58
  }
32
59
  }
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
+ }
33
67
  }
34
68
  };
35
69
  OpenAIProviderStrategy = OpenAIProviderStrategy_1 = __decorate([
package/dist/types.d.ts CHANGED
@@ -8,7 +8,7 @@ export interface OpenAICredentials {
8
8
  endpoint_url?: string;
9
9
  sampling_parameters?: 'auto' | 'enabled' | 'disabled';
10
10
  }
11
- export type OpenAIReasoningEffort = 'minimal' | 'low' | 'medium' | 'high';
11
+ export type OpenAIReasoningEffort = 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
12
12
  export interface OpenAIModelOptions extends CommonChatModelParameters {
13
13
  streaming?: boolean;
14
14
  top_p?: number;
@@ -21,6 +21,8 @@ export interface OpenAIModelOptions extends CommonChatModelParameters {
21
21
  export declare function normalizeOpenAIBaseUrl(endpointUrl?: string): string;
22
22
  export declare function isOpenAIOfficialBaseUrl(baseURL?: string): boolean;
23
23
  export declare function isOpenAIGPT5ProModel(model?: string): boolean;
24
+ export declare function getSupportedOpenAIReasoningEfforts(model?: string): readonly OpenAIReasoningEffort[] | undefined;
25
+ export declare function normalizeOpenAIReasoningEffort(model?: string, effort?: OpenAIReasoningEffort): OpenAIReasoningEffort | undefined;
24
26
  export declare function shouldEnableSamplingParameters(mode: OpenAICredentials['sampling_parameters'], baseURL?: string, model?: string): boolean;
25
27
  export declare function shouldEnableResponseFormat(baseURL?: string, model?: string): boolean;
26
28
  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;AAI/D,eAAO,MAAM,OAAO,QAAiE,CAAA;AAErF,MAAM,WAAW,iBAAiB;IACjC,OAAO,EAAE,MAAM,CAAA;IACf,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,mBAAmB,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,CAAA;CACrD;AAED,MAAM,MAAM,qBAAqB,GAAG,SAAS,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAA;AAEzE,MAAM,WAAW,kBAAmB,SAAQ,yBAAyB;IACpE,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,gBAAgB,CAAC,EAAE,qBAAqB,CAAA;IACxC,eAAe,CAAC,EAAE,MAAM,GAAG,aAAa,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,8BAA8B,CAC7C,IAAI,EAAE,iBAAiB,CAAC,qBAAqB,CAAC,EAC9C,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,GACZ,OAAO,CAcT;AAED,wBAAgB,0BAA0B,CACzC,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,GACZ,OAAO,CAMT;AAED,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,iBAAiB;;;;;;;;;;;;;;;;;;;;;;EAYhE"}
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;AAI/D,eAAO,MAAM,OAAO,QAAiE,CAAA;AAErF,MAAM,WAAW,iBAAiB;IACjC,OAAO,EAAE,MAAM,CAAA;IACf,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,mBAAmB,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,CAAA;CACrD;AAED,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,SAAS,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;AA8B5F,MAAM,WAAW,kBAAmB,SAAQ,yBAAyB;IACpE,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,gBAAgB,CAAC,EAAE,qBAAqB,CAAA;IACxC,eAAe,CAAC,EAAE,MAAM,GAAG,aAAa,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,CAM9C;AAED,wBAAgB,8BAA8B,CAC7C,KAAK,CAAC,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,qBAAqB,GAC5B,qBAAqB,GAAG,SAAS,CA2BnC;AAED,wBAAgB,8BAA8B,CAC7C,IAAI,EAAE,iBAAiB,CAAC,qBAAqB,CAAC,EAC9C,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,GACZ,OAAO,CAcT;AAED,wBAAgB,0BAA0B,CACzC,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,GACZ,OAAO,CAMT;AAED,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,iBAAiB;;;;;;;;;;;;;;;;;;;;;;EAYhE"}
package/dist/types.js CHANGED
@@ -7,6 +7,32 @@ export const OpenAIDefaultBaseUrl = 'https://api.openai.com/v1';
7
7
  const OpenAIApiVersionPath = '/v1';
8
8
  const OpenAIOfficialHost = 'api.openai.com';
9
9
  export const SvgIcon = readFileSync(join(moduleDir, '_assets/icon_s_en.svg'), 'utf8');
10
+ const OpenAIReasoningEffortScale = [
11
+ 'none',
12
+ 'minimal',
13
+ 'low',
14
+ 'medium',
15
+ 'high',
16
+ 'xhigh',
17
+ ];
18
+ const OpenAIReasoningEffortProfiles = [
19
+ {
20
+ pattern: /^gpt-5$/,
21
+ supported: ['minimal', 'low', 'medium', 'high'],
22
+ },
23
+ {
24
+ pattern: /^gpt-5\.(2|4)$/,
25
+ supported: ['none', 'low', 'medium', 'high', 'xhigh'],
26
+ },
27
+ {
28
+ pattern: /^gpt-5\.[23]-codex$/,
29
+ supported: ['low', 'medium', 'high', 'xhigh'],
30
+ },
31
+ {
32
+ pattern: /^gpt-5\.(2|4)-pro$/,
33
+ supported: ['medium', 'high', 'xhigh'],
34
+ },
35
+ ];
10
36
  const OpenAIGPT5ProModelPattern = /^gpt-5(?:\.\d+)?-pro$/;
11
37
  export function normalizeOpenAIBaseUrl(endpointUrl) {
12
38
  if (!endpointUrl?.trim()) {
@@ -45,6 +71,35 @@ export function isOpenAIOfficialBaseUrl(baseURL) {
45
71
  export function isOpenAIGPT5ProModel(model) {
46
72
  return !!model?.trim() && OpenAIGPT5ProModelPattern.test(model.trim());
47
73
  }
74
+ export function getSupportedOpenAIReasoningEfforts(model) {
75
+ if (!model?.trim()) {
76
+ return undefined;
77
+ }
78
+ return OpenAIReasoningEffortProfiles.find(({ pattern }) => pattern.test(model.trim()))?.supported;
79
+ }
80
+ export function normalizeOpenAIReasoningEffort(model, effort) {
81
+ if (!effort) {
82
+ return undefined;
83
+ }
84
+ const supported = getSupportedOpenAIReasoningEfforts(model);
85
+ if (!supported?.length) {
86
+ return undefined;
87
+ }
88
+ if (supported.includes(effort)) {
89
+ return effort;
90
+ }
91
+ const requestedIndex = OpenAIReasoningEffortScale.indexOf(effort);
92
+ if (requestedIndex === -1) {
93
+ return supported[0];
94
+ }
95
+ return supported.reduce((closest, candidate) => {
96
+ const candidateIndex = OpenAIReasoningEffortScale.indexOf(candidate);
97
+ const closestIndex = OpenAIReasoningEffortScale.indexOf(closest);
98
+ const candidateDistance = Math.abs(candidateIndex - requestedIndex);
99
+ const closestDistance = Math.abs(closestIndex - requestedIndex);
100
+ return candidateDistance < closestDistance ? candidate : closest;
101
+ });
102
+ }
48
103
  export function shouldEnableSamplingParameters(mode, baseURL, model) {
49
104
  if (mode === 'enabled') {
50
105
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xpert-ai/plugin-openai",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "OpenAI GPT-5 model plugin for XpertAI platform using Responses API",
5
5
  "author": {
6
6
  "name": "XpertAI",
@@ -46,6 +46,7 @@
46
46
  "lodash-es": "4.17.21"
47
47
  },
48
48
  "scripts": {
49
+ "build": "tsc --build tsconfig.lib.json && node ./scripts/copy-assets.mjs",
49
50
  "test": "jest"
50
51
  }
51
52
  }