@nextclaw/nextclaw-ncp-runtime-codex-sdk 0.1.28 → 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,24 +114,21 @@ 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
|
|
128
|
+
startType: isReasoning ? NcpEventType.MessageReasoningStart : NcpEventType.MessageTextStart
|
|
124
129
|
});
|
|
125
130
|
return;
|
|
126
131
|
}
|
|
127
|
-
if (item.type === "reasoning") {
|
|
128
|
-
itemTextById.delete(item.id);
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
132
|
if (!isToolLikeItem(item)) return;
|
|
132
133
|
const previous = toolStateById.get(item.id) ?? {
|
|
133
134
|
started: false,
|