@nextclaw/ncp 0.2.0 → 0.3.0
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.d.ts +25 -2
- package/dist/index.js +81 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -222,6 +222,7 @@ type NcpSessionSummary = {
|
|
|
222
222
|
messageCount: number;
|
|
223
223
|
updatedAt: string;
|
|
224
224
|
status?: NcpSessionStatus;
|
|
225
|
+
metadata?: Record<string, unknown>;
|
|
225
226
|
};
|
|
226
227
|
type ListSessionsOptions = {
|
|
227
228
|
limit?: number;
|
|
@@ -668,6 +669,7 @@ type NcpAgentRunInput = {
|
|
|
668
669
|
sessionId: string;
|
|
669
670
|
messages: ReadonlyArray<NcpMessage>;
|
|
670
671
|
correlationId?: string;
|
|
672
|
+
metadata?: Record<string, unknown>;
|
|
671
673
|
};
|
|
672
674
|
type NcpAgentRunOptions = {
|
|
673
675
|
signal?: AbortSignal;
|
|
@@ -703,6 +705,7 @@ type OpenAIChatMessage = {
|
|
|
703
705
|
} | {
|
|
704
706
|
role: "assistant";
|
|
705
707
|
content?: string | null;
|
|
708
|
+
reasoning_content?: string;
|
|
706
709
|
tool_calls?: OpenAIToolCall[];
|
|
707
710
|
} | {
|
|
708
711
|
role: "tool";
|
|
@@ -748,6 +751,7 @@ type NcpLLMApiInput = {
|
|
|
748
751
|
messages: OpenAIChatMessage[];
|
|
749
752
|
tools?: OpenAITool[];
|
|
750
753
|
model?: string;
|
|
754
|
+
thinkingLevel?: string | null;
|
|
751
755
|
max_tokens?: number;
|
|
752
756
|
};
|
|
753
757
|
type NcpLLMApiOptions = {
|
|
@@ -781,9 +785,21 @@ interface NcpTool {
|
|
|
781
785
|
type NcpToolCallResult = {
|
|
782
786
|
toolCallId: string;
|
|
783
787
|
toolName: string;
|
|
784
|
-
args: unknown;
|
|
788
|
+
args: Record<string, unknown> | null;
|
|
789
|
+
rawArgsText: string;
|
|
785
790
|
result: unknown;
|
|
786
791
|
};
|
|
792
|
+
type NcpInvalidToolArgumentsResult = {
|
|
793
|
+
ok: false;
|
|
794
|
+
error: {
|
|
795
|
+
code: "invalid_tool_arguments";
|
|
796
|
+
message: string;
|
|
797
|
+
toolCallId: string;
|
|
798
|
+
toolName: string;
|
|
799
|
+
rawArgumentsText: string;
|
|
800
|
+
issues: string[];
|
|
801
|
+
};
|
|
802
|
+
};
|
|
787
803
|
interface NcpToolRegistry {
|
|
788
804
|
listTools(): ReadonlyArray<NcpTool>;
|
|
789
805
|
getTool(name: string): NcpTool | undefined;
|
|
@@ -916,4 +932,11 @@ interface NcpAgentConversationStateManager extends NcpConversationStateManager {
|
|
|
916
932
|
handleEndpointError(payload: NcpError): void;
|
|
917
933
|
}
|
|
918
934
|
|
|
919
|
-
|
|
935
|
+
type NcpReplyTagParseResult = {
|
|
936
|
+
content: string;
|
|
937
|
+
replyTo?: string;
|
|
938
|
+
};
|
|
939
|
+
declare function stripReplyTagsFromText(content: string, currentMessageId?: string): NcpReplyTagParseResult;
|
|
940
|
+
declare function sanitizeAssistantReplyTags(message: NcpMessage, currentMessageId?: string): NcpMessage;
|
|
941
|
+
|
|
942
|
+
export { type ListMessagesOptions, type ListSessionsOptions, type NcpActionPart, type NcpAgentClientEndpoint, type NcpAgentConversationHydrationParams, type NcpAgentConversationSnapshot, type NcpAgentConversationStateManager, type NcpAgentRunApi, type NcpAgentRunInput, type NcpAgentRunOptions, type NcpAgentRunSendOptions, type NcpAgentRunStreamOptions, type NcpAgentRuntime, type NcpAgentServerEndpoint, type NcpAgentStreamProvider, type NcpCardPart, type NcpCompletedEnvelope, type NcpContextBuilder, type NcpContextPrepareOptions, type NcpConversationSnapshot, type NcpConversationStateManager, type NcpEncodeContext, type NcpEndpoint, type NcpEndpointEvent, type NcpEndpointKind, type NcpEndpointLatency, type NcpEndpointManifest, type NcpEndpointSubscriber, type NcpError, type NcpErrorCode, NcpEventType, type NcpExtensionPart, type NcpFailedEnvelope, type NcpFilePart, type NcpInvalidToolArgumentsResult, type NcpLLMApi, type NcpLLMApiInput, type NcpLLMApiOptions, type NcpMessage, type NcpMessageAbortPayload, type NcpMessageAcceptedPayload, type NcpMessageDeliveredPayload, type NcpMessagePart, type NcpMessageReactionPayload, type NcpMessageReadPayload, type NcpMessageRecalledPayload, type NcpMessageRole, type NcpMessageSentPayload, type NcpMessageStatus, type NcpPendingToolCall, type NcpPresenceUpdatedPayload, type NcpReasoningDeltaPayload, type NcpReasoningEndPayload, type NcpReasoningPart, type NcpReasoningStartPayload, type NcpReplyTagParseResult, type NcpRequestEnvelope, type NcpResponseEnvelope, type NcpRichTextPart, type NcpRoundBuffer, type NcpRunContext, type NcpRunErrorPayload, type NcpRunFinalMetadata, type NcpRunFinishedPayload, type NcpRunMetadataPayload, type NcpRunReadyMetadata, type NcpRunStartedPayload, type NcpSessionApi, type NcpSessionStatus, type NcpSessionSummary, type NcpSourcePart, type NcpStepStartPart, type NcpStreamEncoder, type NcpStreamRequestPayload, type NcpTextDeltaPayload, type NcpTextEndPayload, type NcpTextPart, type NcpTextStartPayload, type NcpTool, type NcpToolCallArgsDeltaPayload, type NcpToolCallArgsPayload, type NcpToolCallEndPayload, type NcpToolCallResult, type NcpToolCallResultPayload, type NcpToolCallStartPayload, type NcpToolDefinition, type NcpToolInvocationPart, type NcpToolRegistry, type NcpTypingEndPayload, type NcpTypingStartPayload, type OpenAIChatChunk, type OpenAIChatMessage, type OpenAIContentPart, type OpenAITool, type OpenAIToolCall, type OpenAIToolCallDelta, sanitizeAssistantReplyTags, stripReplyTagsFromText };
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,86 @@ var NcpEventType = /* @__PURE__ */ ((NcpEventType2) => {
|
|
|
34
34
|
NcpEventType2["PresenceUpdated"] = "presence.updated";
|
|
35
35
|
return NcpEventType2;
|
|
36
36
|
})(NcpEventType || {});
|
|
37
|
+
|
|
38
|
+
// src/toolkit/reply-tags.ts
|
|
39
|
+
var REPLY_TO_CURRENT_PATTERN = /\[\[\s*reply_to_current\s*\]\]/gi;
|
|
40
|
+
var REPLY_TO_ID_PATTERN = /\[\[\s*reply_to\s*:\s*([^\]]+?)\s*\]\]/i;
|
|
41
|
+
function normalizeReplyTarget(value) {
|
|
42
|
+
if (typeof value !== "string") {
|
|
43
|
+
return void 0;
|
|
44
|
+
}
|
|
45
|
+
const trimmed = value.trim();
|
|
46
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
47
|
+
}
|
|
48
|
+
function stripReplyTagsFromText(content, currentMessageId) {
|
|
49
|
+
let nextContent = content;
|
|
50
|
+
let replyTo;
|
|
51
|
+
if (REPLY_TO_CURRENT_PATTERN.test(nextContent)) {
|
|
52
|
+
replyTo = normalizeReplyTarget(currentMessageId);
|
|
53
|
+
nextContent = nextContent.replace(REPLY_TO_CURRENT_PATTERN, "").trim();
|
|
54
|
+
}
|
|
55
|
+
const explicitReplyTarget = nextContent.match(REPLY_TO_ID_PATTERN)?.[1];
|
|
56
|
+
if (explicitReplyTarget) {
|
|
57
|
+
replyTo = normalizeReplyTarget(explicitReplyTarget);
|
|
58
|
+
nextContent = nextContent.replace(REPLY_TO_ID_PATTERN, "").trim();
|
|
59
|
+
}
|
|
60
|
+
return replyTo ? { content: nextContent, replyTo } : { content: nextContent };
|
|
61
|
+
}
|
|
62
|
+
function sanitizeAssistantReplyTags(message, currentMessageId = message.id) {
|
|
63
|
+
if (message.role !== "assistant") {
|
|
64
|
+
return {
|
|
65
|
+
...message,
|
|
66
|
+
parts: [...message.parts],
|
|
67
|
+
metadata: message.metadata ? { ...message.metadata } : void 0
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const firstTextIndex = message.parts.findIndex((part) => part.type === "text");
|
|
71
|
+
const nextMetadata = message.metadata ? { ...message.metadata } : void 0;
|
|
72
|
+
const existingReplyTo = normalizeReplyTarget(nextMetadata?.reply_to);
|
|
73
|
+
if (firstTextIndex < 0) {
|
|
74
|
+
return {
|
|
75
|
+
...message,
|
|
76
|
+
parts: [...message.parts],
|
|
77
|
+
metadata: nextMetadata
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const firstTextPart = message.parts[firstTextIndex];
|
|
81
|
+
if (!firstTextPart || firstTextPart.type !== "text") {
|
|
82
|
+
return {
|
|
83
|
+
...message,
|
|
84
|
+
parts: [...message.parts],
|
|
85
|
+
metadata: nextMetadata
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const { content, replyTo } = stripReplyTagsFromText(firstTextPart.text, currentMessageId);
|
|
89
|
+
const effectiveReplyTo = replyTo ?? existingReplyTo;
|
|
90
|
+
const nextParts = message.parts.flatMap((part, index) => {
|
|
91
|
+
if (index !== firstTextIndex || part.type !== "text") {
|
|
92
|
+
return [part];
|
|
93
|
+
}
|
|
94
|
+
if (content.length === 0) {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
return [{ ...part, text: content }];
|
|
98
|
+
});
|
|
99
|
+
if (effectiveReplyTo) {
|
|
100
|
+
return {
|
|
101
|
+
...message,
|
|
102
|
+
parts: nextParts,
|
|
103
|
+
metadata: {
|
|
104
|
+
...nextMetadata,
|
|
105
|
+
reply_to: effectiveReplyTo
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
...message,
|
|
111
|
+
parts: nextParts,
|
|
112
|
+
metadata: nextMetadata
|
|
113
|
+
};
|
|
114
|
+
}
|
|
37
115
|
export {
|
|
38
|
-
NcpEventType
|
|
116
|
+
NcpEventType,
|
|
117
|
+
sanitizeAssistantReplyTags,
|
|
118
|
+
stripReplyTagsFromText
|
|
39
119
|
};
|