@nextclaw/ncp-toolkit 0.5.14 → 0.5.16
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 +1 -0
- package/dist/index.js +13 -5
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -176,6 +176,7 @@ declare class DefaultNcpAgentBackend implements NcpAgentServerEndpoint, NcpSessi
|
|
|
176
176
|
signal: AbortSignal;
|
|
177
177
|
}, opts?: NcpAgentRunStreamOptions) => AsyncIterable<NcpEndpointEvent>;
|
|
178
178
|
listSessions: () => Promise<NcpSessionSummary[]>;
|
|
179
|
+
isLiveSessionRunning: (sessionId: string) => boolean;
|
|
179
180
|
listSessionMessages: (sessionId: string) => Promise<NcpMessage[]>;
|
|
180
181
|
getSession: (sessionId: string) => Promise<NcpSessionSummary | null>;
|
|
181
182
|
appendMessage: (sessionId: string, message: NcpMessage) => Promise<NcpSessionSummary | null>;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NcpEventType, isHiddenNcpMessage, sanitizeAssistantReplyTags } from "@nextclaw/ncp";
|
|
1
|
+
import { NcpEventType, consumeNcpRunHandle, createNcpRunHandle, isHiddenNcpMessage, sanitizeAssistantReplyTags } from "@nextclaw/ncp";
|
|
2
2
|
//#region src/agent/agent-conversation-message-normalizer.ts
|
|
3
3
|
function cloneConversationMessage(message) {
|
|
4
4
|
return {
|
|
@@ -522,6 +522,7 @@ var DefaultNcpAgentConversationStateManager = class {
|
|
|
522
522
|
};
|
|
523
523
|
upsertMessage = (message) => {
|
|
524
524
|
const normalizedMessage = normalizeConversationMessage(message);
|
|
525
|
+
if (this.streamingMessage?.id === normalizedMessage.id) this.streamingMessage = null;
|
|
525
526
|
const messageIndex = this.messages.findIndex((item) => item.id === normalizedMessage.id);
|
|
526
527
|
if (messageIndex < 0) {
|
|
527
528
|
this.messages = [...this.messages, normalizedMessage];
|
|
@@ -596,7 +597,7 @@ function createAgentClientFromServer(server) {
|
|
|
596
597
|
switch (event.type) {
|
|
597
598
|
case NcpEventType.MessageRequest:
|
|
598
599
|
assertMaterializedEnvelope(event.payload);
|
|
599
|
-
await
|
|
600
|
+
await consumeNcpRunHandle(server.send(event.payload), createNcpRunHandle(event.payload));
|
|
600
601
|
return;
|
|
601
602
|
case NcpEventType.MessageStreamRequest:
|
|
602
603
|
await consume(server.stream(event.payload));
|
|
@@ -612,7 +613,7 @@ function createAgentClientFromServer(server) {
|
|
|
612
613
|
},
|
|
613
614
|
async send(envelope) {
|
|
614
615
|
assertMaterializedEnvelope(envelope);
|
|
615
|
-
await
|
|
616
|
+
return await consumeNcpRunHandle(server.send(envelope), createNcpRunHandle(envelope));
|
|
616
617
|
},
|
|
617
618
|
async stream(payload) {
|
|
618
619
|
await consume(server.stream(payload));
|
|
@@ -900,9 +901,9 @@ var AgentBackendSessionRealtime = class {
|
|
|
900
901
|
}
|
|
901
902
|
publishSessionEvent = async (session, event, options = {}) => {
|
|
902
903
|
if (options.dispatchToStateManager) await session.stateManager.dispatch(event);
|
|
904
|
+
if (options.persistSession !== false) await this.params.persistSessionEvent(session, event);
|
|
903
905
|
this.params.publishEndpointEvent(event);
|
|
904
906
|
session.publisher.publish(event);
|
|
905
|
-
if (options.persistSession !== false) await this.params.persistSessionEvent(session, event);
|
|
906
907
|
};
|
|
907
908
|
streamSessionEvents = (payloadOrParams, opts) => {
|
|
908
909
|
return (async function* (self) {
|
|
@@ -981,7 +982,7 @@ function readOptionalAgentId$1(value) {
|
|
|
981
982
|
}
|
|
982
983
|
function readMessages(snapshot) {
|
|
983
984
|
const messages = snapshot.messages.map((message) => structuredClone(message));
|
|
984
|
-
if (snapshot.streamingMessage) messages.push(structuredClone(snapshot.streamingMessage));
|
|
985
|
+
if (snapshot.streamingMessage && !messages.some((message) => message.id === snapshot.streamingMessage?.id)) messages.push(structuredClone(snapshot.streamingMessage));
|
|
985
986
|
return messages;
|
|
986
987
|
}
|
|
987
988
|
function readSessionActivityAt(summary) {
|
|
@@ -1260,6 +1261,9 @@ const DEFAULT_SUPPORTED_PART_TYPES = [
|
|
|
1260
1261
|
"action",
|
|
1261
1262
|
"extension"
|
|
1262
1263
|
];
|
|
1264
|
+
const disposeRuntime = async (runtime) => {
|
|
1265
|
+
await runtime.dispose?.();
|
|
1266
|
+
};
|
|
1263
1267
|
var DefaultNcpAgentBackend = class {
|
|
1264
1268
|
manifest;
|
|
1265
1269
|
sessionStore;
|
|
@@ -1321,12 +1325,14 @@ var DefaultNcpAgentBackend = class {
|
|
|
1321
1325
|
const execution = session.activeExecution;
|
|
1322
1326
|
if (!execution) {
|
|
1323
1327
|
session.publisher.close();
|
|
1328
|
+
await disposeRuntime(session.runtime);
|
|
1324
1329
|
continue;
|
|
1325
1330
|
}
|
|
1326
1331
|
execution.abortHandled = true;
|
|
1327
1332
|
execution.controller.abort();
|
|
1328
1333
|
this.finishSessionExecution(session, execution);
|
|
1329
1334
|
session.publisher.close();
|
|
1335
|
+
await disposeRuntime(session.runtime);
|
|
1330
1336
|
}
|
|
1331
1337
|
this.sessionRegistry.clear();
|
|
1332
1338
|
};
|
|
@@ -1401,6 +1407,7 @@ var DefaultNcpAgentBackend = class {
|
|
|
1401
1407
|
liveSessions: this.sessionRegistry.listSessions()
|
|
1402
1408
|
});
|
|
1403
1409
|
};
|
|
1410
|
+
isLiveSessionRunning = (sessionId) => Boolean(this.sessionRegistry.getSession(sessionId)?.activeExecution);
|
|
1404
1411
|
listSessionMessages = async (sessionId) => {
|
|
1405
1412
|
return listBackendSessionMessages({
|
|
1406
1413
|
sessionStore: this.sessionStore,
|
|
@@ -1446,6 +1453,7 @@ var DefaultNcpAgentBackend = class {
|
|
|
1446
1453
|
execution.closed = true;
|
|
1447
1454
|
}
|
|
1448
1455
|
liveSession?.publisher.close();
|
|
1456
|
+
if (liveSession) await disposeRuntime(liveSession.runtime);
|
|
1449
1457
|
await this.sessionStore.deleteSession(sessionId);
|
|
1450
1458
|
};
|
|
1451
1459
|
ensureStarted = async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nextclaw/ncp-toolkit",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.16",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Toolkit implementations built on top of the NextClaw Communication Protocol.",
|
|
6
6
|
"type": "module",
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@nextclaw/ncp": "0.5.
|
|
18
|
+
"@nextclaw/ncp": "0.5.11"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/node": "^20.17.6",
|
|
22
22
|
"prettier": "^3.3.3",
|
|
23
23
|
"typescript": "^5.6.3",
|
|
24
24
|
"vitest": "^4.1.2",
|
|
25
|
-
"@nextclaw/ncp-agent-runtime": "0.3.
|
|
25
|
+
"@nextclaw/ncp-agent-runtime": "0.3.21"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
28
|
"build": "tsdown src/index.ts --dts --clean --target es2022 --no-fixedExtension",
|