@nextclaw/nextclaw-ncp-runtime-codex-sdk 0.1.27 → 0.1.29
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.
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { NcpEventType } from "@nextclaw/ncp";
|
|
2
2
|
//#region src/utils/codex-sdk-ncp-event-mapper.utils.ts
|
|
3
3
|
const TEXT_DELTA_CHUNK_SIZE = 32;
|
|
4
|
+
const TOOL_LIKE_ITEM_TYPES = new Set([
|
|
5
|
+
"mcp_tool_call",
|
|
6
|
+
"command_execution",
|
|
7
|
+
"web_search",
|
|
8
|
+
"file_change",
|
|
9
|
+
"todo_list"
|
|
10
|
+
]);
|
|
4
11
|
function buildToolDescriptor(item) {
|
|
5
12
|
switch (item.type) {
|
|
6
13
|
case "mcp_tool_call": return {
|
|
@@ -63,13 +70,10 @@ function stringifyToolArgs(args) {
|
|
|
63
70
|
}
|
|
64
71
|
}
|
|
65
72
|
function isToolLikeItem(item) {
|
|
66
|
-
return
|
|
73
|
+
return TOOL_LIKE_ITEM_TYPES.has(item.type);
|
|
67
74
|
}
|
|
68
75
|
function splitTextDelta(delta) {
|
|
69
|
-
|
|
70
|
-
const chunks = [];
|
|
71
|
-
for (let index = 0; index < delta.length; index += TEXT_DELTA_CHUNK_SIZE) chunks.push(delta.slice(index, index + TEXT_DELTA_CHUNK_SIZE));
|
|
72
|
-
return chunks;
|
|
76
|
+
return Array.from({ length: Math.ceil(delta.length / TEXT_DELTA_CHUNK_SIZE) }, (_, index) => delta.slice(index * TEXT_DELTA_CHUNK_SIZE, (index + 1) * TEXT_DELTA_CHUNK_SIZE));
|
|
73
77
|
}
|
|
74
78
|
function* mapTextSnapshotDelta(params) {
|
|
75
79
|
const { currentText, itemId, itemTextById, messageId, sessionId } = params;
|
|
@@ -110,31 +114,18 @@ function* mapTextSnapshotDelta(params) {
|
|
|
110
114
|
async function* mapCodexItemEvent(params) {
|
|
111
115
|
const { sessionId, messageId, event, itemTextById, toolStateById } = params;
|
|
112
116
|
const { item } = event;
|
|
113
|
-
if (item.type === "agent_message") {
|
|
117
|
+
if (item.type === "agent_message" || item.type === "reasoning") {
|
|
118
|
+
const isReasoning = item.type === "reasoning";
|
|
114
119
|
yield* mapTextSnapshotDelta({
|
|
115
120
|
currentText: item.text ?? "",
|
|
116
|
-
deltaType: NcpEventType.MessageTextDelta,
|
|
117
|
-
endType: NcpEventType.MessageTextEnd,
|
|
121
|
+
deltaType: isReasoning ? NcpEventType.MessageReasoningDelta : NcpEventType.MessageTextDelta,
|
|
122
|
+
endType: isReasoning ? NcpEventType.MessageReasoningEnd : NcpEventType.MessageTextEnd,
|
|
118
123
|
eventType: event.type,
|
|
119
124
|
itemId: item.id,
|
|
120
125
|
itemTextById,
|
|
121
126
|
messageId,
|
|
122
127
|
sessionId,
|
|
123
|
-
startType: NcpEventType.MessageTextStart
|
|
124
|
-
});
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
if (item.type === "reasoning") {
|
|
128
|
-
yield* mapTextSnapshotDelta({
|
|
129
|
-
currentText: item.text ?? "",
|
|
130
|
-
deltaType: NcpEventType.MessageReasoningDelta,
|
|
131
|
-
endType: NcpEventType.MessageReasoningEnd,
|
|
132
|
-
eventType: event.type,
|
|
133
|
-
itemId: item.id,
|
|
134
|
-
itemTextById,
|
|
135
|
-
messageId,
|
|
136
|
-
sessionId,
|
|
137
|
-
startType: NcpEventType.MessageReasoningStart
|
|
128
|
+
startType: isReasoning ? NcpEventType.MessageReasoningStart : NcpEventType.MessageTextStart
|
|
138
129
|
});
|
|
139
130
|
return;
|
|
140
131
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nextclaw/nextclaw-ncp-runtime-codex-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Optional NCP runtime adapter backed by OpenAI Codex SDK.",
|
|
6
6
|
"type": "module",
|
|
@@ -21,11 +21,13 @@
|
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/node": "^20.17.6",
|
|
24
|
-
"typescript": "^5.6.3"
|
|
24
|
+
"typescript": "^5.6.3",
|
|
25
|
+
"vitest": "^4.1.2"
|
|
25
26
|
},
|
|
26
27
|
"scripts": {
|
|
27
28
|
"build": "tsdown src/index.ts --dts --clean --target es2022 --no-fixedExtension --unbundle",
|
|
28
29
|
"lint": "eslint .",
|
|
30
|
+
"test": "vitest run src/utils/codex-sdk-ncp-event-mapper.utils.test.ts",
|
|
29
31
|
"tsc": "tsc -p tsconfig.json"
|
|
30
32
|
}
|
|
31
33
|
}
|