@nextclaw/ncp-toolkit 0.5.16 → 0.5.17
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 +10 -2
- package/dist/index.js +27 -29
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -125,8 +125,12 @@ interface AgentSessionStore {
|
|
|
125
125
|
event: NcpEndpointEvent;
|
|
126
126
|
updatedAt: string;
|
|
127
127
|
}): Promise<void>;
|
|
128
|
+
updateSessionMetadata(params: {
|
|
129
|
+
sessionId: string;
|
|
130
|
+
metadata: Record<string, unknown>;
|
|
131
|
+
updatedAt: string;
|
|
132
|
+
}): Promise<boolean>;
|
|
128
133
|
saveSession(session: AgentSessionRecord): Promise<void>;
|
|
129
|
-
replaceSession(session: AgentSessionRecord): Promise<void>;
|
|
130
134
|
deleteSession(sessionId: string): Promise<AgentSessionRecord | null>;
|
|
131
135
|
}
|
|
132
136
|
//#endregion
|
|
@@ -201,7 +205,11 @@ declare class InMemoryAgentSessionStore implements AgentSessionStore {
|
|
|
201
205
|
getSession: (sessionId: string) => Promise<AgentSessionRecord | null>;
|
|
202
206
|
listSessions: () => Promise<AgentSessionRecord[]>;
|
|
203
207
|
saveSession: (session: AgentSessionRecord) => Promise<void>;
|
|
204
|
-
|
|
208
|
+
updateSessionMetadata: (params: {
|
|
209
|
+
sessionId: string;
|
|
210
|
+
metadata: Record<string, unknown>;
|
|
211
|
+
updatedAt: string;
|
|
212
|
+
}) => Promise<boolean>;
|
|
205
213
|
deleteSession: (sessionId: string) => Promise<AgentSessionRecord | null>;
|
|
206
214
|
}
|
|
207
215
|
//#endregion
|
package/dist/index.js
CHANGED
|
@@ -1160,27 +1160,6 @@ function readOptionalAgentId(value) {
|
|
|
1160
1160
|
function readAgentIdFromMetadata(metadata) {
|
|
1161
1161
|
return readOptionalAgentId(metadata?.agent_id) ?? readOptionalAgentId(metadata?.agentId);
|
|
1162
1162
|
}
|
|
1163
|
-
function resolvePersistedAgentId(params) {
|
|
1164
|
-
const { liveSession, storedSession } = params;
|
|
1165
|
-
return readOptionalAgentId(liveSession?.agentId) ?? readOptionalAgentId(storedSession?.agentId) ?? readAgentIdFromMetadata(liveSession?.metadata) ?? readAgentIdFromMetadata(storedSession?.metadata);
|
|
1166
|
-
}
|
|
1167
|
-
function buildUpdatedSessionRecord(params) {
|
|
1168
|
-
const { liveSession, patch, sessionId, storedSession, updatedAt } = params;
|
|
1169
|
-
const nextMetadata = patch.metadata === null ? {} : patch.metadata ? structuredClone(patch.metadata) : structuredClone(liveSession?.metadata ?? storedSession?.metadata ?? {});
|
|
1170
|
-
if (liveSession) liveSession.metadata = structuredClone(nextMetadata);
|
|
1171
|
-
const agentId = resolvePersistedAgentId({
|
|
1172
|
-
liveSession,
|
|
1173
|
-
storedSession
|
|
1174
|
-
});
|
|
1175
|
-
return {
|
|
1176
|
-
sessionId,
|
|
1177
|
-
...agentId ? { agentId } : {},
|
|
1178
|
-
messages: liveSession ? readMessages(liveSession.stateManager.getSnapshot()) : storedSession?.messages.map((message) => structuredClone(message)) ?? [],
|
|
1179
|
-
createdAt: storedSession?.createdAt ?? liveSession?.createdAt ?? updatedAt,
|
|
1180
|
-
updatedAt,
|
|
1181
|
-
metadata: nextMetadata
|
|
1182
|
-
};
|
|
1183
|
-
}
|
|
1184
1163
|
function buildPersistedLiveSessionRecord(params) {
|
|
1185
1164
|
const { session, sessionId, updatedAt } = params;
|
|
1186
1165
|
const messages = readMessages(session.stateManager.getSnapshot());
|
|
@@ -1264,6 +1243,12 @@ const DEFAULT_SUPPORTED_PART_TYPES = [
|
|
|
1264
1243
|
const disposeRuntime = async (runtime) => {
|
|
1265
1244
|
await runtime.dispose?.();
|
|
1266
1245
|
};
|
|
1246
|
+
function buildUpdatedMetadata(params) {
|
|
1247
|
+
const { liveSession, patch, storedSession } = params;
|
|
1248
|
+
if (patch.metadata === null) return {};
|
|
1249
|
+
if (patch.metadata) return structuredClone(patch.metadata);
|
|
1250
|
+
return structuredClone(liveSession?.metadata ?? storedSession?.metadata ?? {});
|
|
1251
|
+
}
|
|
1267
1252
|
var DefaultNcpAgentBackend = class {
|
|
1268
1253
|
manifest;
|
|
1269
1254
|
sessionStore;
|
|
@@ -1435,13 +1420,18 @@ var DefaultNcpAgentBackend = class {
|
|
|
1435
1420
|
const liveSession = this.sessionRegistry.getSession(sessionId);
|
|
1436
1421
|
const storedSession = await this.sessionStore.getSession(sessionId);
|
|
1437
1422
|
if (!liveSession && !storedSession) return null;
|
|
1438
|
-
|
|
1439
|
-
sessionId,
|
|
1440
|
-
patch,
|
|
1423
|
+
const metadata = buildUpdatedMetadata({
|
|
1441
1424
|
liveSession,
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
})
|
|
1425
|
+
patch,
|
|
1426
|
+
storedSession
|
|
1427
|
+
});
|
|
1428
|
+
const updatedAt = now();
|
|
1429
|
+
if (liveSession) liveSession.metadata = structuredClone(metadata);
|
|
1430
|
+
await this.sessionStore.updateSessionMetadata({
|
|
1431
|
+
sessionId,
|
|
1432
|
+
metadata,
|
|
1433
|
+
updatedAt
|
|
1434
|
+
});
|
|
1445
1435
|
return this.getSession(sessionId);
|
|
1446
1436
|
};
|
|
1447
1437
|
deleteSession = async (sessionId) => {
|
|
@@ -1501,8 +1491,16 @@ var InMemoryAgentSessionStore = class {
|
|
|
1501
1491
|
saveSession = async (session) => {
|
|
1502
1492
|
this.sessions.set(session.sessionId, structuredClone(session));
|
|
1503
1493
|
};
|
|
1504
|
-
|
|
1505
|
-
|
|
1494
|
+
updateSessionMetadata = async (params) => {
|
|
1495
|
+
const { metadata, sessionId, updatedAt } = params;
|
|
1496
|
+
const session = this.sessions.get(sessionId);
|
|
1497
|
+
if (!session) return false;
|
|
1498
|
+
this.sessions.set(sessionId, {
|
|
1499
|
+
...session,
|
|
1500
|
+
metadata: structuredClone(metadata),
|
|
1501
|
+
updatedAt
|
|
1502
|
+
});
|
|
1503
|
+
return true;
|
|
1506
1504
|
};
|
|
1507
1505
|
deleteSession = async (sessionId) => {
|
|
1508
1506
|
const session = this.sessions.get(sessionId);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nextclaw/ncp-toolkit",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.17",
|
|
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.12"
|
|
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.22"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
28
|
"build": "tsdown src/index.ts --dts --clean --target es2022 --no-fixedExtension",
|