@nextclaw/ncp 0.5.9 → 0.5.11
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 +15 -3
- package/dist/index.js +38 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -671,6 +671,14 @@ type NcpRunContext = {
|
|
|
671
671
|
sessionId?: string;
|
|
672
672
|
abortDisabledReason?: string | null;
|
|
673
673
|
};
|
|
674
|
+
/** Command acknowledgement returned after a user message has been accepted. */
|
|
675
|
+
type NcpRunHandle = {
|
|
676
|
+
sessionId: string;
|
|
677
|
+
userMessageId: string;
|
|
678
|
+
assistantMessageId: string | null;
|
|
679
|
+
runId: string | null;
|
|
680
|
+
correlationId?: string;
|
|
681
|
+
};
|
|
674
682
|
/** Schema for run.metadata.metadata when kind is "ready" (run started, backend ready). */
|
|
675
683
|
type NcpRunReadyMetadata = {
|
|
676
684
|
kind: "ready";
|
|
@@ -742,8 +750,8 @@ interface NcpEndpoint {
|
|
|
742
750
|
* (e.g. frontend, CLI) that sends user messages and receives agent responses.
|
|
743
751
|
*/
|
|
744
752
|
interface NcpAgentClientEndpoint extends NcpEndpoint {
|
|
745
|
-
/** Sends a
|
|
746
|
-
send(envelope: NcpAgentSendEnvelope): Promise<
|
|
753
|
+
/** Sends a command-only message request to the agent and returns the run handle. */
|
|
754
|
+
send(envelope: NcpAgentSendEnvelope): Promise<NcpRunHandle>;
|
|
747
755
|
/** Attaches to the live event stream of a session. Emits `message.stream-request`. */
|
|
748
756
|
stream(payload: NcpStreamRequestPayload): Promise<void>;
|
|
749
757
|
/** Aborts the active execution of a session. Emits `message.abort`. */
|
|
@@ -1014,4 +1022,8 @@ declare function normalizeAssistantText(text: string, mode: NcpAssistantReasonin
|
|
|
1014
1022
|
parts: NcpAssistantReasoningSegment[];
|
|
1015
1023
|
};
|
|
1016
1024
|
//#endregion
|
|
1017
|
-
|
|
1025
|
+
//#region src/toolkit/run-handle.d.ts
|
|
1026
|
+
declare function createNcpRunHandle(envelope: NcpRequestEnvelope): NcpRunHandle;
|
|
1027
|
+
declare function consumeNcpRunHandle(events: AsyncIterable<NcpEndpointEvent>, fallback: NcpRunHandle): Promise<NcpRunHandle>;
|
|
1028
|
+
//#endregion
|
|
1029
|
+
export { ListMessagesOptions, ListSessionsOptions, NCP_INTERNAL_VISIBILITY_METADATA_KEY, NcpActionPart, NcpAgentClientEndpoint, NcpAgentConversationHydrationParams, NcpAgentConversationSnapshot, NcpAgentConversationStateManager, NcpAgentRunApi, NcpAgentRunInput, NcpAgentRunOptions, NcpAgentRunSendOptions, NcpAgentRunStreamOptions, NcpAgentRuntime, NcpAgentSendEnvelope, NcpAgentServerEndpoint, NcpAgentStreamProvider, NcpAssistantReasoningNormalizationMode, NcpAssistantReasoningSegment, NcpAssistantTextStreamNormalizer, NcpCardPart, NcpCompletedEnvelope, NcpContextBuilder, NcpContextPrepareOptions, NcpContextWindowUpdatedPayload, NcpConversationSnapshot, NcpConversationStateManager, NcpEncodeContext, NcpEndpoint, NcpEndpointEvent, NcpEndpointKind, NcpEndpointLatency, NcpEndpointManifest, NcpEndpointSubscriber, NcpError, NcpErrorCode, NcpEventType, NcpExtensionPart, NcpFailedEnvelope, NcpFilePart, NcpInvalidToolArgumentsResult, NcpLLMApi, NcpLLMApiInput, NcpLLMApiOptions, NcpMessage, NcpMessageAbortPayload, NcpMessageAcceptedPayload, NcpMessageDeliveredPayload, NcpMessagePart, NcpMessageReactionPayload, NcpMessageReadPayload, NcpMessageRecalledPayload, NcpMessageRole, NcpMessageSentPayload, NcpMessageStatus, NcpOutboundMessageDraft, NcpPendingToolCall, NcpPresenceUpdatedPayload, NcpProviderRuntimeRoute, NcpReasoningDeltaPayload, NcpReasoningEndPayload, NcpReasoningPart, NcpReasoningStartPayload, NcpReplyTagParseResult, NcpRequestEnvelope, NcpResponseEnvelope, NcpRichTextPart, NcpRoundBuffer, NcpRunContext, NcpRunErrorPayload, NcpRunFinalMetadata, NcpRunFinishedPayload, NcpRunHandle, NcpRunMetadataPayload, NcpRunReadyMetadata, NcpRunStartedPayload, NcpSessionApi, NcpSessionPatch, NcpSessionStatus, NcpSessionSummary, NcpSourcePart, NcpStepStartPart, NcpStreamEncoder, NcpStreamRequestPayload, NcpTextDeltaPayload, NcpTextEndPayload, NcpTextPart, NcpTextStartPayload, NcpTool, NcpToolCallArgsDeltaPayload, NcpToolCallArgsPayload, NcpToolCallEndPayload, NcpToolCallResult, NcpToolCallResultPayload, NcpToolCallStartPayload, NcpToolDefinition, NcpToolInvocationPart, NcpToolOutputContentItem, NcpToolOutputImageItem, NcpToolOutputTextItem, NcpToolRegistry, NcpTypingEndPayload, NcpTypingStartPayload, OpenAIChatChunk, OpenAIChatMessage, OpenAIContentPart, OpenAITool, OpenAIToolCall, OpenAIToolCallDelta, consumeNcpRunHandle, createNcpRunHandle, isHiddenNcpMessage, normalizeAssistantText, readAssistantReasoningNormalizationMode, readAssistantReasoningNormalizationModeFromMetadata, sanitizeAssistantReplyTags, stripReplyTagsFromText, writeAssistantReasoningNormalizationModeToMetadata };
|
package/dist/index.js
CHANGED
|
@@ -282,4 +282,41 @@ function normalizeAssistantText(text, mode) {
|
|
|
282
282
|
};
|
|
283
283
|
}
|
|
284
284
|
//#endregion
|
|
285
|
-
|
|
285
|
+
//#region src/toolkit/run-handle.ts
|
|
286
|
+
function createNcpRunHandle(envelope) {
|
|
287
|
+
return {
|
|
288
|
+
sessionId: envelope.sessionId,
|
|
289
|
+
userMessageId: envelope.message.id,
|
|
290
|
+
assistantMessageId: null,
|
|
291
|
+
runId: null,
|
|
292
|
+
...envelope.correlationId ? { correlationId: envelope.correlationId } : {}
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
function consumeNcpRunHandle(events, fallback) {
|
|
296
|
+
let resolved = false;
|
|
297
|
+
let handle = fallback;
|
|
298
|
+
return new Promise((resolve, reject) => {
|
|
299
|
+
const resolveOnce = () => {
|
|
300
|
+
if (resolved) return;
|
|
301
|
+
resolved = true;
|
|
302
|
+
resolve(handle);
|
|
303
|
+
};
|
|
304
|
+
(async () => {
|
|
305
|
+
try {
|
|
306
|
+
for await (const event of events) if (event.type === NcpEventType.RunStarted) {
|
|
307
|
+
handle = {
|
|
308
|
+
...handle,
|
|
309
|
+
assistantMessageId: event.payload.messageId ?? null,
|
|
310
|
+
runId: event.payload.runId ?? null
|
|
311
|
+
};
|
|
312
|
+
resolveOnce();
|
|
313
|
+
}
|
|
314
|
+
resolveOnce();
|
|
315
|
+
} catch (error) {
|
|
316
|
+
if (!resolved) reject(error);
|
|
317
|
+
}
|
|
318
|
+
})();
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
//#endregion
|
|
322
|
+
export { NCP_INTERNAL_VISIBILITY_METADATA_KEY, NcpAssistantTextStreamNormalizer, NcpEventType, consumeNcpRunHandle, createNcpRunHandle, isHiddenNcpMessage, normalizeAssistantText, readAssistantReasoningNormalizationMode, readAssistantReasoningNormalizationModeFromMetadata, sanitizeAssistantReplyTags, stripReplyTagsFromText, writeAssistantReasoningNormalizationModeToMetadata };
|