@nextclaw/nextclaw-ncp-runtime-plugin-codex-sdk 0.1.3 → 0.1.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextclaw/nextclaw-ncp-runtime-plugin-codex-sdk",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
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/core": "0.9.1",
24
+ "@nextclaw/core": "0.9.3",
25
25
  "@nextclaw/ncp": "0.3.1",
26
- "@nextclaw/ncp-toolkit": "0.4.1",
27
- "@nextclaw/nextclaw-ncp-runtime-codex-sdk": "0.1.1"
26
+ "@nextclaw/nextclaw-ncp-runtime-codex-sdk": "0.1.1",
27
+ "@nextclaw/ncp-toolkit": "0.4.1"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/node": "^20.17.6",
package/dist/index.d.ts DELETED
@@ -1,23 +0,0 @@
1
- import { Config } from '@nextclaw/core';
2
- import { NcpAgentRuntime } from '@nextclaw/ncp';
3
- import { RuntimeFactoryParams } from '@nextclaw/ncp-toolkit';
4
-
5
- type PluginApi = {
6
- config: Config;
7
- pluginConfig?: Record<string, unknown>;
8
- registerNcpAgentRuntime: (registration: {
9
- kind: string;
10
- label?: string;
11
- createRuntime: (params: RuntimeFactoryParams) => NcpAgentRuntime;
12
- }) => void;
13
- };
14
- type PluginDefinition = {
15
- id: string;
16
- name: string;
17
- description: string;
18
- configSchema: Record<string, unknown>;
19
- register: (api: PluginApi) => void;
20
- };
21
- declare const plugin: PluginDefinition;
22
-
23
- export { plugin as default };
package/dist/index.js DELETED
@@ -1,223 +0,0 @@
1
- import {
2
- getApiBase,
3
- getProvider,
4
- getProviderName,
5
- getWorkspacePath,
6
- SkillsLoader
7
- } from "@nextclaw/core";
8
- import {
9
- CodexSdkNcpAgentRuntime
10
- } from "@nextclaw/nextclaw-ncp-runtime-codex-sdk";
11
- const PLUGIN_ID = "nextclaw-ncp-runtime-plugin-codex-sdk";
12
- const CODEX_RUNTIME_KIND = "codex";
13
- function readString(value) {
14
- if (typeof value !== "string") {
15
- return void 0;
16
- }
17
- const trimmed = value.trim();
18
- return trimmed || void 0;
19
- }
20
- function readBoolean(value) {
21
- return typeof value === "boolean" ? value : void 0;
22
- }
23
- function readRecord(value) {
24
- if (!value || typeof value !== "object" || Array.isArray(value)) {
25
- return void 0;
26
- }
27
- return value;
28
- }
29
- function readStringArray(value) {
30
- if (!Array.isArray(value)) {
31
- return void 0;
32
- }
33
- const values = value.map((entry) => readString(entry)).filter((entry) => Boolean(entry));
34
- return values.length > 0 ? values : void 0;
35
- }
36
- function readStringRecord(value) {
37
- if (!value || typeof value !== "object" || Array.isArray(value)) {
38
- return void 0;
39
- }
40
- const out = {};
41
- for (const [entryKey, entryValue] of Object.entries(value)) {
42
- if (typeof entryValue !== "string") {
43
- continue;
44
- }
45
- const normalized = entryValue.trim();
46
- if (!normalized) {
47
- continue;
48
- }
49
- out[entryKey] = normalized;
50
- }
51
- return Object.keys(out).length > 0 ? out : void 0;
52
- }
53
- function readThinkingLevel(value) {
54
- if (typeof value !== "string") {
55
- return void 0;
56
- }
57
- const normalized = value.trim().toLowerCase();
58
- if (normalized === "minimal" || normalized === "low" || normalized === "medium" || normalized === "high" || normalized === "xhigh") {
59
- return normalized;
60
- }
61
- return void 0;
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
- }
109
- function readRequestedSkills(metadata) {
110
- const raw = metadata.requested_skills ?? metadata.requestedSkills;
111
- if (!Array.isArray(raw)) {
112
- return [];
113
- }
114
- return raw.map((entry) => readString(entry)).filter((entry) => Boolean(entry)).slice(0, 8);
115
- }
116
- function readUserText(input) {
117
- for (let index = input.messages.length - 1; index >= 0; index -= 1) {
118
- const message = input.messages[index];
119
- if (message?.role !== "user") {
120
- continue;
121
- }
122
- const text = message.parts.filter((part) => part.type === "text").map((part) => part.text).join("").trim();
123
- if (text) {
124
- return text;
125
- }
126
- }
127
- return "";
128
- }
129
- function buildCodexInputBuilder(workspace) {
130
- const skillsLoader = new SkillsLoader(workspace);
131
- return async (input) => {
132
- const userText = readUserText(input);
133
- const metadata = input.metadata && typeof input.metadata === "object" && !Array.isArray(input.metadata) ? input.metadata : {};
134
- const requestedSkills = readRequestedSkills(metadata);
135
- const requestedSkillsContent = skillsLoader.loadSkillsForContext(requestedSkills);
136
- if (requestedSkillsContent.trim().length === 0) {
137
- return userText;
138
- }
139
- return [
140
- "## Requested Skills",
141
- `Selected skill names: ${requestedSkills.join(", ")}`,
142
- requestedSkillsContent,
143
- "## User Message",
144
- userText
145
- ].join("\n\n");
146
- };
147
- }
148
- function resolveCodexModel(params) {
149
- return readString(params.sessionMetadata.preferred_model) ?? readString(params.sessionMetadata.model) ?? readString(params.pluginConfig.model) ?? params.config.agents.defaults.model;
150
- }
151
- const plugin = {
152
- id: PLUGIN_ID,
153
- name: "NextClaw Codex NCP Runtime",
154
- description: "Registers NCP session type `codex` backed by OpenAI Codex SDK.",
155
- configSchema: {
156
- type: "object",
157
- additionalProperties: true,
158
- properties: {}
159
- },
160
- register(api) {
161
- const pluginConfig = readRecord(api.pluginConfig) ?? {};
162
- api.registerNcpAgentRuntime({
163
- kind: CODEX_RUNTIME_KIND,
164
- label: "Codex",
165
- createRuntime: (runtimeParams) => {
166
- const nextConfig = api.config;
167
- const model = resolveCodexModel({
168
- config: nextConfig,
169
- pluginConfig,
170
- sessionMetadata: runtimeParams.sessionMetadata
171
- });
172
- const provider = getProvider(nextConfig, model);
173
- const providerName = getProviderName(nextConfig, model);
174
- const apiBase = readString(pluginConfig.apiBase) ?? getApiBase(nextConfig, model) ?? void 0;
175
- const apiKey = readString(pluginConfig.apiKey) ?? provider?.apiKey ?? void 0;
176
- if (!apiKey) {
177
- throw new Error(
178
- `[codex] missing apiKey. Set plugins.entries.${PLUGIN_ID}.config.apiKey or providers.*.apiKey for model "${model}".`
179
- );
180
- }
181
- const executionOptions = resolveCodexExecutionOptions({
182
- config: nextConfig,
183
- pluginConfig
184
- });
185
- const thinkingLevel = readThinkingLevel(runtimeParams.sessionMetadata.preferred_thinking) ?? readThinkingLevel(runtimeParams.sessionMetadata.thinking) ?? void 0;
186
- return new CodexSdkNcpAgentRuntime({
187
- sessionId: runtimeParams.sessionId,
188
- apiKey,
189
- apiBase,
190
- model: stripProviderPrefix(model, providerName),
191
- threadId: readString(runtimeParams.sessionMetadata.codex_thread_id) ?? null,
192
- codexPathOverride: readString(pluginConfig.codexPathOverride),
193
- env: readStringRecord(pluginConfig.env),
194
- cliConfig: resolveCodexCliConfig({
195
- pluginConfig,
196
- providerName,
197
- apiBase
198
- }),
199
- stateManager: runtimeParams.stateManager,
200
- sessionMetadata: runtimeParams.sessionMetadata,
201
- setSessionMetadata: runtimeParams.setSessionMetadata,
202
- inputBuilder: buildCodexInputBuilder(executionOptions.workingDirectory),
203
- threadOptions: {
204
- model,
205
- sandboxMode: readString(pluginConfig.sandboxMode),
206
- workingDirectory: executionOptions.workingDirectory,
207
- skipGitRepoCheck: executionOptions.skipGitRepoCheck,
208
- modelReasoningEffort: thinkingLevel,
209
- networkAccessEnabled: readBoolean(pluginConfig.networkAccessEnabled),
210
- webSearchMode: readString(pluginConfig.webSearchMode),
211
- webSearchEnabled: readBoolean(pluginConfig.webSearchEnabled),
212
- approvalPolicy: readString(pluginConfig.approvalPolicy),
213
- additionalDirectories: readStringArray(pluginConfig.additionalDirectories)
214
- }
215
- });
216
- }
217
- });
218
- }
219
- };
220
- var index_default = plugin;
221
- export {
222
- index_default as default
223
- };