@nextclaw/ncp-toolkit 0.4.8 → 0.4.9

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 CHANGED
@@ -129,6 +129,7 @@ declare class DefaultNcpAgentBackend implements NcpAgentServerEndpoint, NcpSessi
129
129
  listSessionMessages(sessionId: string): Promise<NcpMessage[]>;
130
130
  getSession(sessionId: string): Promise<NcpSessionSummary | null>;
131
131
  appendMessage: (sessionId: string, message: NcpMessage) => Promise<NcpSessionSummary | null>;
132
+ updateToolCallResult: (sessionId: string, toolCallId: string, content: unknown) => Promise<NcpSessionSummary | null>;
132
133
  updateSession(sessionId: string, patch: NcpSessionPatch): Promise<NcpSessionSummary | null>;
133
134
  deleteSession(sessionId: string): Promise<void>;
134
135
  private ensureStarted;
package/dist/index.js CHANGED
@@ -692,7 +692,7 @@ async function consume(events) {
692
692
 
693
693
  // src/agent/agent-backend/agent-backend.ts
694
694
  import {
695
- NcpEventType as NcpEventType6
695
+ NcpEventType as NcpEventType8
696
696
  } from "@nextclaw/ncp";
697
697
 
698
698
  // src/errors/ncp-error-exception.ts
@@ -777,23 +777,28 @@ function cloneMessages(messages) {
777
777
  }
778
778
 
779
779
  // src/agent/agent-backend/agent-run-executor.ts
780
+ import {
781
+ isHiddenNcpMessage
782
+ } from "@nextclaw/ncp";
780
783
  import { NcpEventType as NcpEventType3 } from "@nextclaw/ncp";
781
784
  var AgentRunExecutor = class {
782
785
  constructor(persistSession) {
783
786
  this.persistSession = persistSession;
784
787
  }
785
788
  async *executeRun(session, envelope, controller) {
786
- const messageSent = {
787
- type: NcpEventType3.MessageSent,
788
- payload: {
789
- sessionId: envelope.sessionId,
790
- message: structuredClone(envelope.message),
791
- metadata: envelope.metadata
792
- }
793
- };
794
- await session.stateManager.dispatch(messageSent);
795
- await this.persistSession(envelope.sessionId);
796
- yield structuredClone(messageSent);
789
+ if (!isHiddenNcpMessage(envelope.message)) {
790
+ const messageSent = {
791
+ type: NcpEventType3.MessageSent,
792
+ payload: {
793
+ sessionId: envelope.sessionId,
794
+ message: structuredClone(envelope.message),
795
+ metadata: envelope.metadata
796
+ }
797
+ };
798
+ await session.stateManager.dispatch(messageSent);
799
+ await this.persistSession(envelope.sessionId);
800
+ yield structuredClone(messageSent);
801
+ }
797
802
  try {
798
803
  for await (const event of session.runtime.run(
799
804
  {
@@ -903,8 +908,34 @@ function buildPersistedLiveSessionRecord(params) {
903
908
  };
904
909
  }
905
910
 
906
- // src/agent/agent-backend/agent-backend-append-message.ts
911
+ // src/agent/agent-backend/agent-backend-update-tool-call-result.ts
907
912
  import { NcpEventType as NcpEventType5 } from "@nextclaw/ncp";
913
+ async function updateAgentBackendToolCallResult(params) {
914
+ const normalizedSessionId = params.sessionId.trim();
915
+ const normalizedToolCallId = params.toolCallId.trim();
916
+ if (!normalizedSessionId || !normalizedToolCallId) {
917
+ return null;
918
+ }
919
+ const liveSession = await params.sessionRegistry.ensureSession(normalizedSessionId);
920
+ const event = {
921
+ type: NcpEventType5.MessageToolCallResult,
922
+ payload: {
923
+ sessionId: normalizedSessionId,
924
+ toolCallId: normalizedToolCallId,
925
+ content: params.content
926
+ }
927
+ };
928
+ await liveSession.stateManager.dispatch(event);
929
+ params.publisher.publish(event);
930
+ if (liveSession.activeExecution && !liveSession.activeExecution.closed) {
931
+ liveSession.activeExecution.publisher.publish(event);
932
+ }
933
+ await params.persistSession(normalizedSessionId);
934
+ return params.getSession(normalizedSessionId);
935
+ }
936
+
937
+ // src/agent/agent-backend/agent-backend-append-message.ts
938
+ import { NcpEventType as NcpEventType6 } from "@nextclaw/ncp";
908
939
  async function appendAgentBackendMessage(params) {
909
940
  const normalizedSessionId = params.sessionId.trim();
910
941
  if (!normalizedSessionId) {
@@ -923,7 +954,7 @@ async function appendAgentBackendMessage(params) {
923
954
  sessionId: normalizedSessionId
924
955
  };
925
956
  const event = {
926
- type: NcpEventType5.MessageSent,
957
+ type: NcpEventType6.MessageSent,
927
958
  payload: {
928
959
  sessionId: normalizedSessionId,
929
960
  message: nextMessage
@@ -938,6 +969,9 @@ async function appendAgentBackendMessage(params) {
938
969
  return params.getSession(normalizedSessionId);
939
970
  }
940
971
 
972
+ // src/agent/agent-backend/agent-backend-stream.ts
973
+ import { NcpEventType as NcpEventType7 } from "@nextclaw/ncp";
974
+
941
975
  // src/agent/agent-backend/async-queue.ts
942
976
  function createAsyncQueue() {
943
977
  const items = [];
@@ -1004,6 +1038,14 @@ async function* streamAgentBackendExecution(params) {
1004
1038
  const session = params.sessionRegistry.getSession(payload.sessionId);
1005
1039
  const execution = session?.activeExecution;
1006
1040
  if (!session || !execution || execution.closed) {
1041
+ if (session) {
1042
+ yield {
1043
+ type: NcpEventType7.RunFinished,
1044
+ payload: {
1045
+ sessionId: payload.sessionId
1046
+ }
1047
+ };
1048
+ }
1007
1049
  return;
1008
1050
  }
1009
1051
  const queue = createAsyncQueue();
@@ -1081,18 +1123,7 @@ var EventPublisher = class {
1081
1123
  };
1082
1124
 
1083
1125
  // src/agent/agent-backend/agent-backend.ts
1084
- var DEFAULT_SUPPORTED_PART_TYPES = [
1085
- "text",
1086
- "file",
1087
- "source",
1088
- "step-start",
1089
- "reasoning",
1090
- "tool-invocation",
1091
- "card",
1092
- "rich-text",
1093
- "action",
1094
- "extension"
1095
- ];
1126
+ var DEFAULT_SUPPORTED_PART_TYPES = ["text", "file", "source", "step-start", "reasoning", "tool-invocation", "card", "rich-text", "action", "extension"];
1096
1127
  var DefaultNcpAgentBackend = class {
1097
1128
  manifest;
1098
1129
  sessionStore;
@@ -1126,7 +1157,7 @@ var DefaultNcpAgentBackend = class {
1126
1157
  return;
1127
1158
  }
1128
1159
  this.started = true;
1129
- this.publisher.publish({ type: NcpEventType6.EndpointReady });
1160
+ this.publisher.publish({ type: NcpEventType8.EndpointReady });
1130
1161
  }
1131
1162
  async stop() {
1132
1163
  if (!this.started) {
@@ -1147,13 +1178,13 @@ var DefaultNcpAgentBackend = class {
1147
1178
  async emit(event) {
1148
1179
  await this.ensureStarted();
1149
1180
  switch (event.type) {
1150
- case NcpEventType6.MessageRequest:
1181
+ case NcpEventType8.MessageRequest:
1151
1182
  await this.handleRequest(event.payload);
1152
1183
  return;
1153
- case NcpEventType6.MessageStreamRequest:
1184
+ case NcpEventType8.MessageStreamRequest:
1154
1185
  await this.streamToSubscribers(event.payload);
1155
1186
  return;
1156
- case NcpEventType6.MessageAbort:
1187
+ case NcpEventType8.MessageAbort:
1157
1188
  await this.handleAbort(event.payload);
1158
1189
  return;
1159
1190
  default:
@@ -1229,6 +1260,18 @@ var DefaultNcpAgentBackend = class {
1229
1260
  getSession: async (nextSessionId) => this.getSession(nextSessionId)
1230
1261
  });
1231
1262
  };
1263
+ updateToolCallResult = async (sessionId, toolCallId, content) => {
1264
+ await this.ensureStarted();
1265
+ return updateAgentBackendToolCallResult({
1266
+ sessionId,
1267
+ toolCallId,
1268
+ content,
1269
+ sessionRegistry: this.sessionRegistry,
1270
+ publisher: this.publisher,
1271
+ persistSession: async (nextSessionId) => this.persistSession(nextSessionId),
1272
+ getSession: async (nextSessionId) => this.getSession(nextSessionId)
1273
+ });
1274
+ };
1232
1275
  async updateSession(sessionId, patch) {
1233
1276
  const liveSession = this.sessionRegistry.getSession(sessionId);
1234
1277
  const storedSession = await this.sessionStore.getSession(sessionId);
@@ -1325,7 +1368,7 @@ var DefaultNcpAgentBackend = class {
1325
1368
  }
1326
1369
  async createAbortEvent(sessionId, messageId) {
1327
1370
  const abortEvent = {
1328
- type: NcpEventType6.MessageAbort,
1371
+ type: NcpEventType8.MessageAbort,
1329
1372
  payload: {
1330
1373
  sessionId,
1331
1374
  ...messageId ? { messageId } : {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextclaw/ncp-toolkit",
3
- "version": "0.4.8",
3
+ "version": "0.4.9",
4
4
  "private": false,
5
5
  "description": "Toolkit implementations built on top of the NextClaw Communication Protocol.",
6
6
  "type": "module",
@@ -15,7 +15,7 @@
15
15
  "dist"
16
16
  ],
17
17
  "dependencies": {
18
- "@nextclaw/ncp": "0.4.1"
18
+ "@nextclaw/ncp": "0.4.2"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/node": "^20.17.6",
@@ -23,7 +23,7 @@
23
23
  "tsup": "^8.3.5",
24
24
  "typescript": "^5.6.3",
25
25
  "vitest": "^2.1.2",
26
- "@nextclaw/ncp-agent-runtime": "0.3.1"
26
+ "@nextclaw/ncp-agent-runtime": "0.3.2"
27
27
  },
28
28
  "scripts": {
29
29
  "build": "tsup src/index.ts --format esm --dts --out-dir dist",