@nextclaw/nextclaw-ncp-runtime-plugin-codex-sdk 0.1.0 → 0.1.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.
- package/dist/index.js +64 -9
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getApiBase,
|
|
3
3
|
getProvider,
|
|
4
|
+
getProviderName,
|
|
4
5
|
getWorkspacePath,
|
|
5
6
|
SkillsLoader
|
|
6
7
|
} from "@nextclaw/core";
|
|
@@ -59,6 +60,52 @@ function readThinkingLevel(value) {
|
|
|
59
60
|
}
|
|
60
61
|
return void 0;
|
|
61
62
|
}
|
|
63
|
+
function resolveCodexExecutionOptions(params) {
|
|
64
|
+
const configuredWorkingDirectory = readString(params.pluginConfig.workingDirectory);
|
|
65
|
+
const workspace = getWorkspacePath(
|
|
66
|
+
configuredWorkingDirectory ?? params.config.agents.defaults.workspace
|
|
67
|
+
);
|
|
68
|
+
return {
|
|
69
|
+
workingDirectory: workspace,
|
|
70
|
+
skipGitRepoCheck: readBoolean(params.pluginConfig.skipGitRepoCheck) ?? true
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function resolveCodexCliConfig(params) {
|
|
74
|
+
const explicitConfig = readRecord(params.pluginConfig.config);
|
|
75
|
+
const modelProvider = readString(params.pluginConfig.modelProvider) ?? readString(params.providerName) ?? "openai";
|
|
76
|
+
const preferredAuthMethod = readString(params.pluginConfig.preferredAuthMethod) ?? "apikey";
|
|
77
|
+
const apiBase = readString(params.pluginConfig.apiBase) ?? readString(params.apiBase);
|
|
78
|
+
const config = {
|
|
79
|
+
model_provider: modelProvider,
|
|
80
|
+
preferred_auth_method: preferredAuthMethod
|
|
81
|
+
};
|
|
82
|
+
if (modelProvider && apiBase) {
|
|
83
|
+
config.model_providers = {
|
|
84
|
+
[modelProvider]: {
|
|
85
|
+
name: modelProvider,
|
|
86
|
+
base_url: apiBase,
|
|
87
|
+
wire_api: "responses",
|
|
88
|
+
requires_openai_auth: true
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
...config,
|
|
94
|
+
...explicitConfig ?? {}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function stripProviderPrefix(model, providerName) {
|
|
98
|
+
const normalizedModel = model.trim();
|
|
99
|
+
const normalizedProvider = providerName?.trim().toLowerCase();
|
|
100
|
+
if (!normalizedModel || !normalizedProvider) {
|
|
101
|
+
return normalizedModel;
|
|
102
|
+
}
|
|
103
|
+
const prefix = `${normalizedProvider}/`;
|
|
104
|
+
if (!normalizedModel.toLowerCase().startsWith(prefix)) {
|
|
105
|
+
return normalizedModel;
|
|
106
|
+
}
|
|
107
|
+
return normalizedModel.slice(prefix.length);
|
|
108
|
+
}
|
|
62
109
|
function readRequestedSkills(metadata) {
|
|
63
110
|
const raw = metadata.requested_skills ?? metadata.requestedSkills;
|
|
64
111
|
if (!Array.isArray(raw)) {
|
|
@@ -123,33 +170,41 @@ const plugin = {
|
|
|
123
170
|
sessionMetadata: runtimeParams.sessionMetadata
|
|
124
171
|
});
|
|
125
172
|
const provider = getProvider(nextConfig, model);
|
|
173
|
+
const providerName = getProviderName(nextConfig, model);
|
|
174
|
+
const apiBase = readString(pluginConfig.apiBase) ?? getApiBase(nextConfig, model) ?? void 0;
|
|
126
175
|
const apiKey = readString(pluginConfig.apiKey) ?? provider?.apiKey ?? void 0;
|
|
127
176
|
if (!apiKey) {
|
|
128
177
|
throw new Error(
|
|
129
178
|
`[codex] missing apiKey. Set plugins.entries.${PLUGIN_ID}.config.apiKey or providers.*.apiKey for model "${model}".`
|
|
130
179
|
);
|
|
131
180
|
}
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
181
|
+
const executionOptions = resolveCodexExecutionOptions({
|
|
182
|
+
config: nextConfig,
|
|
183
|
+
pluginConfig
|
|
184
|
+
});
|
|
135
185
|
const thinkingLevel = readThinkingLevel(runtimeParams.sessionMetadata.preferred_thinking) ?? readThinkingLevel(runtimeParams.sessionMetadata.thinking) ?? void 0;
|
|
136
186
|
return new CodexSdkNcpAgentRuntime({
|
|
137
187
|
sessionId: runtimeParams.sessionId,
|
|
138
188
|
apiKey,
|
|
139
|
-
apiBase
|
|
140
|
-
model,
|
|
189
|
+
apiBase,
|
|
190
|
+
model: stripProviderPrefix(model, providerName),
|
|
141
191
|
threadId: readString(runtimeParams.sessionMetadata.codex_thread_id) ?? null,
|
|
142
192
|
codexPathOverride: readString(pluginConfig.codexPathOverride),
|
|
143
193
|
env: readStringRecord(pluginConfig.env),
|
|
144
|
-
cliConfig:
|
|
194
|
+
cliConfig: resolveCodexCliConfig({
|
|
195
|
+
pluginConfig,
|
|
196
|
+
providerName,
|
|
197
|
+
apiBase
|
|
198
|
+
}),
|
|
199
|
+
stateManager: runtimeParams.stateManager,
|
|
145
200
|
sessionMetadata: runtimeParams.sessionMetadata,
|
|
146
201
|
setSessionMetadata: runtimeParams.setSessionMetadata,
|
|
147
|
-
inputBuilder: buildCodexInputBuilder(
|
|
202
|
+
inputBuilder: buildCodexInputBuilder(executionOptions.workingDirectory),
|
|
148
203
|
threadOptions: {
|
|
149
204
|
model,
|
|
150
205
|
sandboxMode: readString(pluginConfig.sandboxMode),
|
|
151
|
-
workingDirectory:
|
|
152
|
-
skipGitRepoCheck:
|
|
206
|
+
workingDirectory: executionOptions.workingDirectory,
|
|
207
|
+
skipGitRepoCheck: executionOptions.skipGitRepoCheck,
|
|
153
208
|
modelReasoningEffort: thinkingLevel,
|
|
154
209
|
networkAccessEnabled: readBoolean(pluginConfig.networkAccessEnabled),
|
|
155
210
|
webSearchMode: readString(pluginConfig.webSearchMode),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nextclaw/nextclaw-ncp-runtime-plugin-codex-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "NextClaw plugin that registers Codex SDK as an optional NCP runtime.",
|
|
6
6
|
"type": "module",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
]
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@nextclaw/
|
|
24
|
+
"@nextclaw/ncp-toolkit": "0.4.0",
|
|
25
25
|
"@nextclaw/ncp": "0.3.0",
|
|
26
|
-
"@nextclaw/
|
|
27
|
-
"@nextclaw/
|
|
26
|
+
"@nextclaw/core": "0.9.0",
|
|
27
|
+
"@nextclaw/nextclaw-ncp-runtime-codex-sdk": "0.1.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "^20.17.6",
|