@xpert-ai/plugin-openai 0.0.1

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.
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
2
+ <path d="M22.282 9.821a5.985 5.985 0 0 0-.516-4.91 6.046 6.046 0 0 0-6.51-2.9A6.065 6.065 0 0 0 4.981 4.18a5.998 5.998 0 0 0-3.998 2.9 6.042 6.042 0 0 0 .743 7.097 5.98 5.98 0 0 0 .51 4.911 6.051 6.051 0 0 0 6.515 2.9A5.985 5.985 0 0 0 13.26 24a6.056 6.056 0 0 0 5.772-4.206 5.99 5.99 0 0 0 3.997-2.9 6.056 6.056 0 0 0-.747-7.073zM13.26 22.43a4.476 4.476 0 0 1-2.876-1.04l.141-.081 4.779-2.758a.795.795 0 0 0 .392-.681v-6.737l2.02 1.168a.071.071 0 0 1 .038.052v5.583a4.504 4.504 0 0 1-4.494 4.494zM3.6 18.304a4.47 4.47 0 0 1-.535-3.014l.142.085 4.783 2.759a.771.771 0 0 0 .78 0l5.843-3.369v2.332a.08.08 0 0 1-.033.062L9.74 19.95a4.5 4.5 0 0 1-6.14-1.646zM2.34 7.896a4.485 4.485 0 0 1 2.366-1.973V11.6a.766.766 0 0 0 .388.676l5.815 3.355-2.02 1.168a.076.076 0 0 1-.071 0l-4.83-2.786A4.504 4.504 0 0 1 2.34 7.872zm16.597 3.855l-5.833-3.387L15.119 7.2a.076.076 0 0 1 .071 0l4.83 2.791a4.494 4.494 0 0 1-.676 8.105v-5.678a.79.79 0 0 0-.407-.667zm2.01-3.023l-.141-.085-4.774-2.782a.776.776 0 0 0-.785 0L9.409 9.23V6.897a.066.066 0 0 1 .028-.061l4.83-2.787a4.5 4.5 0 0 1 6.68 4.66zm-12.64 4.135l-2.02-1.164a.08.08 0 0 1-.038-.057V6.075a4.5 4.5 0 0 1 7.375-3.453l-.142.08L8.704 5.46a.795.795 0 0 0-.393.681zm1.097-2.365l2.602-1.5 2.607 1.5v2.999l-2.597 1.5-2.607-1.5z" fill="currentColor"/>
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
2
+ <path d="M22.282 9.821a5.985 5.985 0 0 0-.516-4.91 6.046 6.046 0 0 0-6.51-2.9A6.065 6.065 0 0 0 4.981 4.18a5.998 5.998 0 0 0-3.998 2.9 6.042 6.042 0 0 0 .743 7.097 5.98 5.98 0 0 0 .51 4.911 6.051 6.051 0 0 0 6.515 2.9A5.985 5.985 0 0 0 13.26 24a6.056 6.056 0 0 0 5.772-4.206 5.99 5.99 0 0 0 3.997-2.9 6.056 6.056 0 0 0-.747-7.073zM13.26 22.43a4.476 4.476 0 0 1-2.876-1.04l.141-.081 4.779-2.758a.795.795 0 0 0 .392-.681v-6.737l2.02 1.168a.071.071 0 0 1 .038.052v5.583a4.504 4.504 0 0 1-4.494 4.494zM3.6 18.304a4.47 4.47 0 0 1-.535-3.014l.142.085 4.783 2.759a.771.771 0 0 0 .78 0l5.843-3.369v2.332a.08.08 0 0 1-.033.062L9.74 19.95a4.5 4.5 0 0 1-6.14-1.646zM2.34 7.896a4.485 4.485 0 0 1 2.366-1.973V11.6a.766.766 0 0 0 .388.676l5.815 3.355-2.02 1.168a.076.076 0 0 1-.071 0l-4.83-2.786A4.504 4.504 0 0 1 2.34 7.872zm16.597 3.855l-5.833-3.387L15.119 7.2a.076.076 0 0 1 .071 0l4.83 2.791a4.494 4.494 0 0 1-.676 8.105v-5.678a.79.79 0 0 0-.407-.667zm2.01-3.023l-.141-.085-4.774-2.782a.776.776 0 0 0-.785 0L9.409 9.23V6.897a.066.066 0 0 1 .028-.061l4.83-2.787a4.5 4.5 0 0 1 6.68 4.66zm-12.64 4.135l-2.02-1.164a.08.08 0 0 1-.038-.057V6.075a4.5 4.5 0 0 1 7.375-3.453l-.142.08L8.704 5.46a.795.795 0 0 0-.393.681zm1.097-2.365l2.602-1.5 2.607 1.5v2.999l-2.597 1.5-2.607-1.5z" fill="currentColor"/>
3
+ </svg>
@@ -0,0 +1,4 @@
1
+ import type { XpertPlugin } from '@xpert-ai/plugin-sdk';
2
+ declare const plugin: XpertPlugin<any>;
3
+ export default plugin;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAkBvD,QAAA,MAAM,MAAM,EAAE,WAAW,CAAC,GAAG,CA2B5B,CAAA;AAED,eAAe,MAAM,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,38 @@
1
+ import { readFileSync } from 'fs';
2
+ import { fileURLToPath } from 'url';
3
+ import { dirname, join } from 'path';
4
+ import { z } from 'zod';
5
+ import { OpenAIModule } from './openai.module.js';
6
+ import { SvgIcon } from './types.js';
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = dirname(__filename);
9
+ const packageJson = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf8'));
10
+ const plugin = {
11
+ meta: {
12
+ name: packageJson.name,
13
+ version: packageJson.version,
14
+ category: 'model',
15
+ icon: {
16
+ type: 'svg',
17
+ value: SvgIcon,
18
+ },
19
+ displayName: 'OpenAI',
20
+ description: 'Provide OpenAI GPT-5 Models via Responses API',
21
+ keywords: ['OpenAI', 'GPT-5', 'model', 'llm', 'reasoning', 'Responses API'],
22
+ author: 'XpertAI Team',
23
+ },
24
+ config: {
25
+ schema: z.object({}),
26
+ },
27
+ register(ctx) {
28
+ ctx.logger.log('register OpenAI plugin');
29
+ return { module: OpenAIModule, global: true };
30
+ },
31
+ async onStart(ctx) {
32
+ ctx.logger.log('OpenAI plugin started');
33
+ },
34
+ async onStop(ctx) {
35
+ ctx.logger.log('OpenAI plugin stopped');
36
+ },
37
+ };
38
+ export default plugin;
@@ -0,0 +1,5 @@
1
+ - gpt-5.3-codex
2
+ - gpt-5.2
3
+ - gpt-5.2-chat
4
+ - gpt-5.2-pro
5
+ - gpt-5.2-codex
@@ -0,0 +1,77 @@
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: 1
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
@@ -0,0 +1,92 @@
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: 1
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.
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
@@ -0,0 +1,91 @@
1
+ model: gpt-5.2-pro
2
+ label:
3
+ en_US: GPT-5.2 Pro
4
+ zh_Hans: GPT-5.2 Pro
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: 1
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
+ - medium
51
+ - high
52
+ - xhigh
53
+ help:
54
+ zh_Hans: 控制模型推理的深度。xhigh 提供最深度的推理。
55
+ en_US: Controls how much reasoning effort the model uses. xhigh provides the deepest reasoning.
56
+ - name: frequency_penalty
57
+ use_template: frequency_penalty
58
+ default: 0
59
+ min: -2.0
60
+ max: 2.0
61
+ help:
62
+ zh_Hans: 降低重复内容的出现频率。
63
+ en_US: Reduces repetition in the output.
64
+ - name: presence_penalty
65
+ label:
66
+ zh_Hans: 存在惩罚
67
+ en_US: Presence Penalty
68
+ type: float
69
+ default: 0
70
+ min: -2.0
71
+ max: 2.0
72
+ help:
73
+ zh_Hans: 提高讨论新话题的可能性。
74
+ en_US: Increases the likelihood of discussing new topics.
75
+ - name: response_format
76
+ label:
77
+ zh_Hans: 回复格式
78
+ en_US: Response Format
79
+ type: string
80
+ help:
81
+ zh_Hans: 指定模型必须输出的格式。
82
+ en_US: Specifying the format that the model must output.
83
+ required: false
84
+ options:
85
+ - text
86
+ - json_object
87
+ pricing:
88
+ input: '21'
89
+ output: '168'
90
+ unit: '0.000001'
91
+ currency: USD
@@ -0,0 +1,92 @@
1
+ model: gpt-5.2
2
+ label:
3
+ en_US: GPT-5.2
4
+ zh_Hans: GPT-5.2
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: 1
30
+ max: 128000
31
+ help:
32
+ zh_Hans: 最大输出 token 数量。GPT-5.2 支持最大 128K 输出。
33
+ en_US: Maximum number of output tokens. GPT-5.2 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: 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.
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
@@ -0,0 +1,92 @@
1
+ model: gpt-5.3-codex
2
+ label:
3
+ en_US: GPT-5.3 Codex
4
+ zh_Hans: GPT-5.3 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: 16384
29
+ min: 1
30
+ max: 65536
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.
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: '2.5'
90
+ output: '10'
91
+ unit: '0.000001'
92
+ currency: USD
@@ -0,0 +1,13 @@
1
+ import { ChatOpenAI } from '@langchain/openai';
2
+ import { ICopilotModel } from '@metad/contracts';
3
+ import { LargeLanguageModel, TChatModelOptions } from '@xpert-ai/plugin-sdk';
4
+ import { OpenAICredentials } from '../types.js';
5
+ import { OpenAIProviderStrategy } from '../provider.strategy.js';
6
+ export declare class OpenAILargeLanguageModel extends LargeLanguageModel {
7
+ #private;
8
+ readonly modelProvider: OpenAIProviderStrategy;
9
+ constructor(modelProvider: OpenAIProviderStrategy);
10
+ validateCredentials(model: string, credentials: OpenAICredentials): Promise<void>;
11
+ getChatModel(copilotModel: ICopilotModel, options?: TChatModelOptions): ChatOpenAI<import("@langchain/openai").ChatOpenAICallOptions>;
12
+ }
13
+ //# sourceMappingURL=llm.d.ts.map
@@ -0,0 +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,EAIlB,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;CA+C/E"}
@@ -0,0 +1,78 @@
1
+ var _a;
2
+ var OpenAILargeLanguageModel_1;
3
+ import { __decorate, __metadata } from "tslib";
4
+ import { HumanMessage } from '@langchain/core/messages';
5
+ import { ChatOpenAI } from '@langchain/openai';
6
+ import { AiModelTypeEnum } from '@metad/contracts';
7
+ import { Injectable, Logger } from '@nestjs/common';
8
+ import { CredentialsValidateFailedError, getErrorMessage, LargeLanguageModel, } from '@xpert-ai/plugin-sdk';
9
+ import { isNil, omitBy } from 'lodash-es';
10
+ import { shouldEnableSamplingParameters, toCredentialKwargs } from '../types.js';
11
+ import { OpenAIProviderStrategy } from '../provider.strategy.js';
12
+ let OpenAILargeLanguageModel = OpenAILargeLanguageModel_1 = class OpenAILargeLanguageModel extends LargeLanguageModel {
13
+ #logger = new Logger(OpenAILargeLanguageModel_1.name);
14
+ constructor(modelProvider) {
15
+ super(modelProvider, AiModelTypeEnum.LLM);
16
+ this.modelProvider = modelProvider;
17
+ }
18
+ async validateCredentials(model, credentials) {
19
+ try {
20
+ const params = toCredentialKwargs(credentials);
21
+ const chatModel = new ChatOpenAI({
22
+ ...params,
23
+ model,
24
+ maxTokens: 5,
25
+ useResponsesApi: true,
26
+ });
27
+ const messages = [new HumanMessage('Hello')];
28
+ await chatModel.invoke(messages);
29
+ }
30
+ catch (err) {
31
+ throw new CredentialsValidateFailedError(getErrorMessage(err));
32
+ }
33
+ }
34
+ getChatModel(copilotModel, options) {
35
+ const { handleLLMTokens } = options ?? {};
36
+ const { copilot } = copilotModel;
37
+ const { modelProvider } = copilot;
38
+ const credentials = modelProvider.credentials;
39
+ const params = toCredentialKwargs(credentials);
40
+ const modelOptions = copilotModel.options;
41
+ const hasCustomEndpoint = !!credentials?.endpoint_url?.trim();
42
+ const streaming = modelOptions?.streaming ?? !hasCustomEndpoint;
43
+ const supportsSamplingParams = shouldEnableSamplingParameters(credentials?.sampling_parameters, params.configuration?.baseURL);
44
+ const model = copilotModel.model;
45
+ const fields = omitBy({
46
+ ...params,
47
+ model,
48
+ streaming,
49
+ temperature: supportsSamplingParams ? (modelOptions?.temperature ?? 1) : undefined,
50
+ maxTokens: modelOptions?.max_tokens,
51
+ topP: supportsSamplingParams ? modelOptions?.top_p : undefined,
52
+ frequencyPenalty: modelOptions?.frequency_penalty,
53
+ presencePenalty: modelOptions?.presence_penalty,
54
+ maxRetries: modelOptions?.maxRetries,
55
+ useResponsesApi: true,
56
+ reasoning: modelOptions?.reasoning_effort
57
+ ? { effort: modelOptions.reasoning_effort }
58
+ : undefined,
59
+ streamUsage: streaming,
60
+ }, isNil);
61
+ return new ChatOpenAI({
62
+ ...fields,
63
+ verbose: options?.verbose,
64
+ callbacks: [
65
+ ...this.createHandleUsageCallbacks(copilot, model, credentials, handleLLMTokens),
66
+ this.createHandleLLMErrorCallbacks(fields, this.#logger)
67
+ ],
68
+ metadata: {
69
+ profile: this.getModelProfile(model, credentials)
70
+ }
71
+ });
72
+ }
73
+ };
74
+ OpenAILargeLanguageModel = OpenAILargeLanguageModel_1 = __decorate([
75
+ Injectable(),
76
+ __metadata("design:paramtypes", [OpenAIProviderStrategy])
77
+ ], OpenAILargeLanguageModel);
78
+ export { OpenAILargeLanguageModel };
@@ -0,0 +1,7 @@
1
+ import { IOnPluginBootstrap, IOnPluginDestroy } from '@xpert-ai/plugin-sdk';
2
+ export declare class OpenAIModule implements IOnPluginBootstrap, IOnPluginDestroy {
3
+ private logEnabled;
4
+ onPluginBootstrap(): void | Promise<void>;
5
+ onPluginDestroy(): void | Promise<void>;
6
+ }
7
+ //# sourceMappingURL=openai.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.module.d.ts","sourceRoot":"","sources":["../src/openai.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,sBAAsB,CAAA;AAM7B,qBAIa,YAAa,YAAW,kBAAkB,EAAE,gBAAgB;IACvE,OAAO,CAAC,UAAU,CAAO;IAEzB,iBAAiB,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAMzC,eAAe,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;CAKxC"}
@@ -0,0 +1,29 @@
1
+ var OpenAIModule_1;
2
+ import { __decorate } from "tslib";
3
+ import { XpertServerPlugin, } from '@xpert-ai/plugin-sdk';
4
+ import { ConfigModule } from '@nestjs/config';
5
+ import chalk from 'chalk';
6
+ import { OpenAIProviderStrategy } from './provider.strategy.js';
7
+ import { OpenAILargeLanguageModel } from './llm/llm.js';
8
+ let OpenAIModule = OpenAIModule_1 = class OpenAIModule {
9
+ constructor() {
10
+ this.logEnabled = true;
11
+ }
12
+ onPluginBootstrap() {
13
+ if (this.logEnabled) {
14
+ console.log(chalk.green(`${OpenAIModule_1.name} is being bootstrapped...`));
15
+ }
16
+ }
17
+ onPluginDestroy() {
18
+ if (this.logEnabled) {
19
+ console.log(chalk.green(`${OpenAIModule_1.name} is being destroyed...`));
20
+ }
21
+ }
22
+ };
23
+ OpenAIModule = OpenAIModule_1 = __decorate([
24
+ XpertServerPlugin({
25
+ imports: [ConfigModule],
26
+ providers: [OpenAIProviderStrategy, OpenAILargeLanguageModel],
27
+ })
28
+ ], OpenAIModule);
29
+ export { OpenAIModule };
@@ -0,0 +1,65 @@
1
+ provider: openai
2
+ label:
3
+ en_US: OpenAI
4
+ zh_Hans: OpenAI
5
+ description:
6
+ en_US: OpenAI GPT-5 model service via Responses API.
7
+ zh_Hans: OpenAI GPT-5 模型服务,通过 Responses API 提供。
8
+ icon_small:
9
+ en_US: icon_s_en.svg
10
+ icon_large:
11
+ en_US: icon_l_en.svg
12
+ background: "#74AA9C"
13
+ help:
14
+ title:
15
+ en_US: Get your API key from OpenAI
16
+ zh_Hans: 从 OpenAI 获取 API Key
17
+ url:
18
+ en_US: https://platform.openai.com/api-keys
19
+ supported_model_types:
20
+ - llm
21
+ configurate_methods:
22
+ - predefined-model
23
+ provider_credential_schema:
24
+ credential_form_schemas:
25
+ - variable: api_key
26
+ label:
27
+ en_US: API Key
28
+ zh_Hans: API Key
29
+ type: secret-input
30
+ required: true
31
+ placeholder:
32
+ zh_Hans: 在此输入您的 API Key
33
+ en_US: Enter your API Key
34
+ - variable: endpoint_url
35
+ label:
36
+ en_US: API endpoint URL
37
+ zh_Hans: API endpoint URL
38
+ type: text-input
39
+ required: false
40
+ placeholder:
41
+ zh_Hans: "Base URL, e.g. https://api.openai.com/v1"
42
+ en_US: "Base URL, e.g. https://api.openai.com/v1"
43
+ - variable: sampling_parameters
44
+ label:
45
+ en_US: Sampling Params for Endpoint
46
+ zh_Hans: Endpoint 采样参数支持
47
+ type: select
48
+ required: false
49
+ default: auto
50
+ placeholder:
51
+ en_US: Auto detect sampling params support
52
+ zh_Hans: 自动检测 endpoint 是否支持采样参数
53
+ options:
54
+ - value: auto
55
+ label:
56
+ en_US: Auto
57
+ zh_Hans: 自动
58
+ - value: enabled
59
+ label:
60
+ en_US: Always enabled
61
+ zh_Hans: 强制开启
62
+ - value: disabled
63
+ label:
64
+ en_US: Always disabled
65
+ zh_Hans: 强制关闭
@@ -0,0 +1,10 @@
1
+ import { Logger } from '@nestjs/common';
2
+ import { ModelProvider } from '@xpert-ai/plugin-sdk';
3
+ import { OpenAICredentials } from './types.js';
4
+ export declare class OpenAIProviderStrategy extends ModelProvider {
5
+ logger: Logger;
6
+ getBaseUrl(credentials: OpenAICredentials): string;
7
+ getAuthorization(credentials: OpenAICredentials): string;
8
+ validateProviderCredentials(credentials: OpenAICredentials): Promise<void>;
9
+ }
10
+ //# sourceMappingURL=provider.strategy.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,39 @@
1
+ var OpenAIProviderStrategy_1;
2
+ import { __decorate } from "tslib";
3
+ import { Injectable, Logger } from '@nestjs/common';
4
+ import { AIModelProviderStrategy, CredentialsValidateFailedError, ModelProvider, } from '@xpert-ai/plugin-sdk';
5
+ import { AiModelTypeEnum } from '@metad/contracts';
6
+ import { OpenAIProvider, toCredentialKwargs, } from './types.js';
7
+ let OpenAIProviderStrategy = OpenAIProviderStrategy_1 = class OpenAIProviderStrategy extends ModelProvider {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.logger = new Logger(OpenAIProviderStrategy_1.name);
11
+ }
12
+ getBaseUrl(credentials) {
13
+ const params = toCredentialKwargs(credentials);
14
+ return params.configuration.baseURL;
15
+ }
16
+ getAuthorization(credentials) {
17
+ return `Bearer ${credentials.api_key}`;
18
+ }
19
+ async validateProviderCredentials(credentials) {
20
+ try {
21
+ const modelInstance = this.getModelManager(AiModelTypeEnum.LLM);
22
+ await modelInstance.validateCredentials('gpt-5.3-codex', credentials);
23
+ }
24
+ catch (ex) {
25
+ if (ex instanceof CredentialsValidateFailedError) {
26
+ throw ex;
27
+ }
28
+ else {
29
+ this.logger.error(`${this.getProviderSchema().provider}: credentials verification failed`, ex.stack);
30
+ throw ex;
31
+ }
32
+ }
33
+ }
34
+ };
35
+ OpenAIProviderStrategy = OpenAIProviderStrategy_1 = __decorate([
36
+ Injectable(),
37
+ AIModelProviderStrategy(OpenAIProvider)
38
+ ], OpenAIProviderStrategy);
39
+ export { OpenAIProviderStrategy };
@@ -0,0 +1,46 @@
1
+ import { ClientOptions } from '@langchain/openai';
2
+ import { CommonChatModelParameters } from '@xpert-ai/plugin-sdk';
3
+ export declare const OpenAIProvider = "openai";
4
+ export declare const OpenAIDefaultBaseUrl = "https://api.openai.com/v1";
5
+ export declare const SvgIcon: string;
6
+ export interface OpenAICredentials {
7
+ api_key: string;
8
+ endpoint_url?: string;
9
+ sampling_parameters?: 'auto' | 'enabled' | 'disabled';
10
+ }
11
+ export interface OpenAIModelOptions extends CommonChatModelParameters {
12
+ streaming?: boolean;
13
+ top_p?: number;
14
+ max_tokens?: number;
15
+ frequency_penalty?: number;
16
+ presence_penalty?: number;
17
+ reasoning_effort?: 'low' | 'medium' | 'high' | 'xhigh';
18
+ response_format?: 'text' | 'json_object';
19
+ }
20
+ export declare function normalizeOpenAIBaseUrl(endpointUrl?: string): string;
21
+ export declare function isOpenAIOfficialBaseUrl(baseURL?: string): boolean;
22
+ export declare function shouldEnableSamplingParameters(mode: OpenAICredentials['sampling_parameters'], baseURL?: string): boolean;
23
+ export declare function toCredentialKwargs(credentials: OpenAICredentials): {
24
+ configuration: ClientOptions;
25
+ temperature: number;
26
+ maxTokens?: number;
27
+ maxCompletionTokens?: number;
28
+ topP: number;
29
+ frequencyPenalty: number;
30
+ presencePenalty: number;
31
+ n: number;
32
+ logitBias?: Record<string, number>;
33
+ user?: string;
34
+ streaming: boolean;
35
+ streamUsage?: boolean;
36
+ modelName: string;
37
+ model: import("@langchain/openai").OpenAIChatModelId;
38
+ modelKwargs?: Record<string, any>;
39
+ stop?: string[];
40
+ stopSequences?: string[];
41
+ timeout?: number;
42
+ openAIApiKey?: string;
43
+ apiKey?: string;
44
+ verbosity?: import("@langchain/openai").OpenAIVerbosityParam;
45
+ };
46
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +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,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,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;IACtD,eAAe,CAAC,EAAE,MAAM,GAAG,aAAa,CAAA;CACxC;AAED,wBAAgB,sBAAsB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAuBnE;AAED,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAWjE;AAED,wBAAgB,8BAA8B,CAC7C,IAAI,EAAE,iBAAiB,CAAC,qBAAqB,CAAC,EAC9C,OAAO,CAAC,EAAE,MAAM,GACd,OAAO,CAUT;AAED,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,iBAAiB;;;;;;;;;;;;;;;;;;;;;;EAYhE"}
package/dist/types.js ADDED
@@ -0,0 +1,63 @@
1
+ import { readFileSync } from 'fs';
2
+ import { fileURLToPath } from 'url';
3
+ import { dirname, join } from 'path';
4
+ const moduleDir = dirname(fileURLToPath(import.meta.url));
5
+ export const OpenAIProvider = 'openai';
6
+ export const OpenAIDefaultBaseUrl = 'https://api.openai.com/v1';
7
+ const OpenAIApiVersionPath = '/v1';
8
+ const OpenAIOfficialHost = 'api.openai.com';
9
+ export const SvgIcon = readFileSync(join(moduleDir, '_assets/icon_s_en.svg'), 'utf8');
10
+ export function normalizeOpenAIBaseUrl(endpointUrl) {
11
+ if (!endpointUrl?.trim()) {
12
+ return OpenAIDefaultBaseUrl;
13
+ }
14
+ const trimmed = endpointUrl.trim().replace(/[。。.]+$/, '').replace(/\/+$/, '');
15
+ try {
16
+ const parsed = new URL(trimmed);
17
+ if (!parsed.pathname || parsed.pathname === '/') {
18
+ parsed.pathname = OpenAIApiVersionPath;
19
+ parsed.search = '';
20
+ parsed.hash = '';
21
+ return parsed.toString().replace(/\/$/, '');
22
+ }
23
+ return parsed.toString().replace(/\/$/, '');
24
+ }
25
+ catch {
26
+ if (trimmed.endsWith(OpenAIApiVersionPath) || trimmed.includes(`${OpenAIApiVersionPath}/`)) {
27
+ return trimmed;
28
+ }
29
+ return `${trimmed}${OpenAIApiVersionPath}`;
30
+ }
31
+ }
32
+ export function isOpenAIOfficialBaseUrl(baseURL) {
33
+ if (!baseURL?.trim()) {
34
+ return true;
35
+ }
36
+ try {
37
+ const parsed = new URL(baseURL);
38
+ return parsed.hostname.toLowerCase() === OpenAIOfficialHost;
39
+ }
40
+ catch {
41
+ return baseURL.includes(OpenAIOfficialHost);
42
+ }
43
+ }
44
+ export function shouldEnableSamplingParameters(mode, baseURL) {
45
+ if (mode === 'enabled') {
46
+ return true;
47
+ }
48
+ if (mode === 'disabled') {
49
+ return false;
50
+ }
51
+ return isOpenAIOfficialBaseUrl(baseURL);
52
+ }
53
+ export function toCredentialKwargs(credentials) {
54
+ const credentialsKwargs = {
55
+ apiKey: credentials.api_key,
56
+ };
57
+ const configuration = {};
58
+ configuration.baseURL = normalizeOpenAIBaseUrl(credentials.endpoint_url);
59
+ return {
60
+ ...credentialsKwargs,
61
+ configuration
62
+ };
63
+ }
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@xpert-ai/plugin-openai",
3
+ "version": "0.0.1",
4
+ "description": "OpenAI GPT-5 model plugin for XpertAI platform using Responses API",
5
+ "author": {
6
+ "name": "XpertAI",
7
+ "url": "https://xpertai.cn"
8
+ },
9
+ "license": "AGPL-3.0",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/xpert-ai/xpert-plugins.git"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/xpert-ai/xpert-plugins/issues"
16
+ },
17
+ "type": "module",
18
+ "main": "./dist/index.js",
19
+ "module": "./dist/index.js",
20
+ "types": "./dist/index.d.ts",
21
+ "exports": {
22
+ "./package.json": "./package.json",
23
+ ".": {
24
+ "@xpert-plugins-starter/source": "./src/index.ts",
25
+ "types": "./dist/index.d.ts",
26
+ "import": "./dist/index.js",
27
+ "default": "./dist/index.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "!**/*.tsbuildinfo"
33
+ ],
34
+ "dependencies": {
35
+ "tslib": "^2.3.0"
36
+ },
37
+ "peerDependencies": {
38
+ "@xpert-ai/plugin-sdk": "^3.7.2",
39
+ "@nestjs/config": "^4.0.2",
40
+ "chalk": "4.1.2",
41
+ "zod": "3.25.67",
42
+ "@metad/contracts": "^3.7.0",
43
+ "@nestjs/common": "^11.1.6",
44
+ "@langchain/core": "^0.3.72",
45
+ "@langchain/openai": "0.6.9",
46
+ "lodash-es": "4.17.21"
47
+ },
48
+ "scripts": {
49
+ "test": "jest"
50
+ }
51
+ }