@nextclaw/ncp-toolkit 0.4.14 → 0.4.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 CHANGED
@@ -17,6 +17,8 @@ declare class DefaultNcpAgentConversationStateManager implements NcpAgentConvers
17
17
  reset: () => void;
18
18
  hydrate: (payload: NcpAgentConversationHydrationParams) => void;
19
19
  dispatch: (event: NcpEndpointEvent) => Promise<void>;
20
+ dispatchBatch: (events: readonly NcpEndpointEvent[]) => Promise<void>;
21
+ private applyEvent;
20
22
  handleMessageSent: (payload: NcpMessageSentPayload) => void;
21
23
  handleMessageAbort: (payload: NcpMessageAbortPayload) => void;
22
24
  handleMessageTextStart: (payload: NcpTextStartPayload) => void;
@@ -96,6 +98,7 @@ interface AgentSessionStore {
96
98
  getSession(sessionId: string): Promise<AgentSessionRecord | null>;
97
99
  listSessions(): Promise<AgentSessionRecord[]>;
98
100
  saveSession(session: AgentSessionRecord): Promise<void>;
101
+ replaceSession(session: AgentSessionRecord): Promise<void>;
99
102
  deleteSession(sessionId: string): Promise<AgentSessionRecord | null>;
100
103
  }
101
104
 
@@ -161,10 +164,11 @@ declare class AgentRunExecutor {
161
164
 
162
165
  declare class InMemoryAgentSessionStore implements AgentSessionStore {
163
166
  private readonly sessions;
164
- getSession(sessionId: string): Promise<AgentSessionRecord | null>;
165
- listSessions(): Promise<AgentSessionRecord[]>;
166
- saveSession(session: AgentSessionRecord): Promise<void>;
167
- deleteSession(sessionId: string): Promise<AgentSessionRecord | null>;
167
+ getSession: (sessionId: string) => Promise<AgentSessionRecord | null>;
168
+ listSessions: () => Promise<AgentSessionRecord[]>;
169
+ saveSession: (session: AgentSessionRecord) => Promise<void>;
170
+ replaceSession: (session: AgentSessionRecord) => Promise<void>;
171
+ deleteSession: (sessionId: string) => Promise<AgentSessionRecord | null>;
168
172
  }
169
173
 
170
174
  /**
package/dist/index.js CHANGED
@@ -151,8 +151,14 @@ var DefaultNcpAgentConversationStateManager = class {
151
151
  this.stateVersion += 1;
152
152
  this.notifyListeners();
153
153
  };
154
- dispatch = async (event) => {
154
+ dispatch = (event) => this.dispatchBatch([event]);
155
+ dispatchBatch = async (events) => {
156
+ if (!events.length) return;
155
157
  const versionBeforeDispatch = this.stateVersion;
158
+ events.forEach(this.applyEvent);
159
+ if (this.stateVersion !== versionBeforeDispatch) this.notifyListeners();
160
+ };
161
+ applyEvent = (event) => {
156
162
  switch (event.type) {
157
163
  case NcpEventType.MessageSent:
158
164
  this.handleMessageSent(event.payload);
@@ -211,9 +217,6 @@ var DefaultNcpAgentConversationStateManager = class {
211
217
  default:
212
218
  break;
213
219
  }
214
- if (this.stateVersion !== versionBeforeDispatch) {
215
- this.notifyListeners();
216
- }
217
220
  };
218
221
  handleMessageSent = (payload) => {
219
222
  this.upsertMessage(payload.message);
@@ -1350,7 +1353,7 @@ var DefaultNcpAgentBackend = class {
1350
1353
  const liveSession = this.sessionRegistry.getSession(sessionId);
1351
1354
  const storedSession = await this.sessionStore.getSession(sessionId);
1352
1355
  if (!liveSession && !storedSession) return null;
1353
- await this.sessionStore.saveSession(buildUpdatedSessionRecord({
1356
+ await this.sessionStore.replaceSession(buildUpdatedSessionRecord({
1354
1357
  sessionId,
1355
1358
  patch,
1356
1359
  liveSession,
@@ -1471,24 +1474,27 @@ var DefaultNcpAgentBackend = class {
1471
1474
  // src/agent/agent-backend/in-memory-agent-session-store.ts
1472
1475
  var InMemoryAgentSessionStore = class {
1473
1476
  sessions = /* @__PURE__ */ new Map();
1474
- async getSession(sessionId) {
1477
+ getSession = async (sessionId) => {
1475
1478
  const session = this.sessions.get(sessionId);
1476
1479
  return session ? structuredClone(session) : null;
1477
- }
1478
- async listSessions() {
1480
+ };
1481
+ listSessions = async () => {
1479
1482
  return [...this.sessions.values()].map((session) => structuredClone(session));
1480
- }
1481
- async saveSession(session) {
1483
+ };
1484
+ saveSession = async (session) => {
1482
1485
  this.sessions.set(session.sessionId, structuredClone(session));
1483
- }
1484
- async deleteSession(sessionId) {
1486
+ };
1487
+ replaceSession = async (session) => {
1488
+ this.sessions.set(session.sessionId, structuredClone(session));
1489
+ };
1490
+ deleteSession = async (sessionId) => {
1485
1491
  const session = this.sessions.get(sessionId);
1486
1492
  if (!session) {
1487
1493
  return null;
1488
1494
  }
1489
1495
  this.sessions.delete(sessionId);
1490
1496
  return structuredClone(session);
1491
- }
1497
+ };
1492
1498
  };
1493
1499
  export {
1494
1500
  AgentRunExecutor,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextclaw/ncp-toolkit",
3
- "version": "0.4.14",
3
+ "version": "0.4.16",
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.5"
18
+ "@nextclaw/ncp": "0.4.6"
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": "^4.1.2",
26
- "@nextclaw/ncp-agent-runtime": "0.3.5"
26
+ "@nextclaw/ncp-agent-runtime": "0.3.6"
27
27
  },
28
28
  "scripts": {
29
29
  "build": "tsup src/index.ts --format esm --dts --out-dir dist",