@nextclaw/server 0.12.21 → 0.12.23
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 +2 -1
- package/dist/index.js +24 -33
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -1091,6 +1091,7 @@ type UiNcpSessionMessagesView = {
|
|
|
1091
1091
|
sessionId: string;
|
|
1092
1092
|
status: NcpSessionStatus;
|
|
1093
1093
|
messages: NcpMessage[];
|
|
1094
|
+
contextWindow?: NcpSessionSummary["contextWindow"];
|
|
1094
1095
|
total: number;
|
|
1095
1096
|
};
|
|
1096
1097
|
type SessionTypeDescribeParams = {
|
|
@@ -1481,7 +1482,7 @@ type UiPluginHost = {
|
|
|
1481
1482
|
getChannelBindings: () => PluginChannelBinding[];
|
|
1482
1483
|
getUiMetadata: () => PluginUiMetadata[];
|
|
1483
1484
|
};
|
|
1484
|
-
type UiKernelHost = Pick<NextclawKernel, "agentRuntimeManager" | "assetStore" | "ingress" | "llmProviders" | "
|
|
1485
|
+
type UiKernelHost = Pick<NextclawKernel, "agentRuntimeManager" | "assetStore" | "ingress" | "llmProviders" | "ncpSessionManager" | "sessionRunManager">;
|
|
1485
1486
|
type UiCronHost = {
|
|
1486
1487
|
listJobs: (includeDisabled?: boolean) => CronJobEntry[];
|
|
1487
1488
|
addJob: (params: {
|
package/dist/index.js
CHANGED
|
@@ -456,6 +456,7 @@ const eventKeys = {
|
|
|
456
456
|
channelConfigApplyStatus: createAppEventKey("channel.config.apply-status"),
|
|
457
457
|
sessionUpdated: createAppEventKey("session.updated"),
|
|
458
458
|
sessionRunStatus: createAppEventKey("session.run-status"),
|
|
459
|
+
sessionMetadataChanged: createAppEventKey("session.metadata.changed"),
|
|
459
460
|
ncpEvent: createAppEventKey("ncp.event"),
|
|
460
461
|
sessionSummaryUpsert: createAppEventKey("session.summary.upsert"),
|
|
461
462
|
sessionSummaryDelete: createAppEventKey("session.summary.delete"),
|
|
@@ -4163,9 +4164,8 @@ function applyUiReadAtPatch(metadata, patch) {
|
|
|
4163
4164
|
const { ui_last_read_at: _removed, ...nextMetadata } = metadata;
|
|
4164
4165
|
return nextMetadata;
|
|
4165
4166
|
}
|
|
4166
|
-
|
|
4167
|
-
if (
|
|
4168
|
-
const projectRoot = await normalizeSessionProjectRoot(patch.projectRoot);
|
|
4167
|
+
function applyProjectRootPatch(metadata, projectRoot) {
|
|
4168
|
+
if (projectRoot === void 0) return metadata;
|
|
4169
4169
|
if (projectRoot) {
|
|
4170
4170
|
const { projectRoot: _removed, ...nextMetadata } = metadata;
|
|
4171
4171
|
return {
|
|
@@ -4176,13 +4176,12 @@ async function applyProjectRootPatch(metadata, patch) {
|
|
|
4176
4176
|
const { project_root: _projectRoot, projectRoot: _camelProjectRoot, ...nextMetadata } = metadata;
|
|
4177
4177
|
return nextMetadata;
|
|
4178
4178
|
}
|
|
4179
|
-
|
|
4180
|
-
const { metadata, patch } = params;
|
|
4179
|
+
function buildPatchedSessionMetadata(metadata, patch, projectRootPatch) {
|
|
4181
4180
|
return applyProjectRootPatch(applyUiReadAtPatch(applySessionTypePatch(applySessionPreferencePatch({
|
|
4182
4181
|
metadata: structuredClone(metadata),
|
|
4183
4182
|
patch,
|
|
4184
4183
|
createInvalidThinkingError: () => /* @__PURE__ */ new Error("PREFERRED_THINKING_INVALID")
|
|
4185
|
-
}), patch), patch),
|
|
4184
|
+
}), patch), patch), projectRootPatch);
|
|
4186
4185
|
}
|
|
4187
4186
|
var NcpSessionRoutesController = class {
|
|
4188
4187
|
sessionSkillsViewBuilder;
|
|
@@ -4190,15 +4189,12 @@ var NcpSessionRoutesController = class {
|
|
|
4190
4189
|
this.options = options;
|
|
4191
4190
|
this.sessionSkillsViewBuilder = new SessionSkillsViewBuilder(options);
|
|
4192
4191
|
}
|
|
4193
|
-
getSessionApi = () => this.options.kernel.ncpSessionApi;
|
|
4194
4192
|
getSessionTypes = async (c) => {
|
|
4195
4193
|
const payload = await this.options.kernel.agentRuntimeManager.listSessionTypes({ describeMode: "observation" });
|
|
4196
4194
|
return c.json(ok(payload));
|
|
4197
4195
|
};
|
|
4198
4196
|
listSessions = async (c) => {
|
|
4199
|
-
const
|
|
4200
|
-
if (!sessionApi) return c.json(err("NOT_AVAILABLE", "ncp session api unavailable"), 503);
|
|
4201
|
-
const sessions = await sessionApi.listSessions({ limit: readPositiveInt(c.req.query("limit")) });
|
|
4197
|
+
const sessions = await this.options.kernel.ncpSessionManager.listSessions({ limit: readPositiveInt(c.req.query("limit")) });
|
|
4202
4198
|
const payload = {
|
|
4203
4199
|
sessions,
|
|
4204
4200
|
total: sessions.length
|
|
@@ -4206,20 +4202,18 @@ var NcpSessionRoutesController = class {
|
|
|
4206
4202
|
return c.json(ok(payload));
|
|
4207
4203
|
};
|
|
4208
4204
|
getSession = async (c) => {
|
|
4209
|
-
const
|
|
4210
|
-
if (!sessionApi) return c.json(err("NOT_AVAILABLE", "ncp session api unavailable"), 503);
|
|
4205
|
+
const sessionManager = this.options.kernel.ncpSessionManager;
|
|
4211
4206
|
const sessionId = decodeURIComponent(c.req.param("sessionId"));
|
|
4212
|
-
const session = await
|
|
4207
|
+
const session = await sessionManager.getSession(sessionId);
|
|
4213
4208
|
if (!session) return c.json(err("NOT_FOUND", `ncp session not found: ${sessionId}`), 404);
|
|
4214
4209
|
return c.json(ok(session));
|
|
4215
4210
|
};
|
|
4216
4211
|
listSessionMessages = async (c) => {
|
|
4217
|
-
const
|
|
4218
|
-
if (!sessionApi) return c.json(err("NOT_AVAILABLE", "ncp session api unavailable"), 503);
|
|
4212
|
+
const sessionManager = this.options.kernel.ncpSessionManager;
|
|
4219
4213
|
const sessionId = decodeURIComponent(c.req.param("sessionId"));
|
|
4220
|
-
const session = await
|
|
4214
|
+
const session = await sessionManager.getSession(sessionId);
|
|
4221
4215
|
if (!session) return c.json(err("NOT_FOUND", `ncp session not found: ${sessionId}`), 404);
|
|
4222
|
-
const messages = await
|
|
4216
|
+
const messages = await sessionManager.listSessionMessages(sessionId, { limit: readPositiveInt(c.req.query("limit")) });
|
|
4223
4217
|
const payload = {
|
|
4224
4218
|
sessionId,
|
|
4225
4219
|
status: session.status ?? "idle",
|
|
@@ -4230,12 +4224,11 @@ var NcpSessionRoutesController = class {
|
|
|
4230
4224
|
return c.json(ok(payload));
|
|
4231
4225
|
};
|
|
4232
4226
|
getSessionSkills = async (c) => {
|
|
4233
|
-
const
|
|
4234
|
-
if (!sessionApi) return c.json(err("NOT_AVAILABLE", "ncp session api unavailable"), 503);
|
|
4227
|
+
const sessionManager = this.options.kernel.ncpSessionManager;
|
|
4235
4228
|
const sessionId = decodeURIComponent(c.req.param("sessionId"));
|
|
4236
4229
|
const query = c.req.query();
|
|
4237
4230
|
const hasProjectRootOverride = Object.prototype.hasOwnProperty.call(query, "projectRoot");
|
|
4238
|
-
const metadata = readSessionMetadata((await
|
|
4231
|
+
const metadata = readSessionMetadata((await sessionManager.getSession(sessionId))?.metadata);
|
|
4239
4232
|
if (hasProjectRootOverride) try {
|
|
4240
4233
|
const projectRoot = await normalizeSessionProjectRoot(query.projectRoot);
|
|
4241
4234
|
if (projectRoot) metadata.project_root = projectRoot;
|
|
@@ -4253,35 +4246,33 @@ var NcpSessionRoutesController = class {
|
|
|
4253
4246
|
})));
|
|
4254
4247
|
};
|
|
4255
4248
|
patchSession = async (c) => {
|
|
4256
|
-
const
|
|
4257
|
-
if (!sessionApi) return c.json(err("NOT_AVAILABLE", "ncp session api unavailable"), 503);
|
|
4249
|
+
const sessionManager = this.options.kernel.ncpSessionManager;
|
|
4258
4250
|
const sessionId = decodeURIComponent(c.req.param("sessionId"));
|
|
4259
4251
|
const body = await readJson(c.req.raw);
|
|
4260
4252
|
if (!body.ok || !body.data || typeof body.data !== "object") return c.json(err("INVALID_BODY", "invalid json body"), 400);
|
|
4261
4253
|
const patch = body.data;
|
|
4262
4254
|
if (patch.clearHistory) return c.json(err("UNSUPPORTED_PATCH", "clearHistory is not supported for ncp sessions"), 400);
|
|
4263
|
-
|
|
4264
|
-
let updated;
|
|
4255
|
+
let patched;
|
|
4265
4256
|
try {
|
|
4266
|
-
const
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
});
|
|
4270
|
-
updated = await sessionApi.updateSession(sessionId, { metadata: nextMetadata });
|
|
4257
|
+
const projectRootPatch = Object.prototype.hasOwnProperty.call(patch, "projectRoot") ? await normalizeSessionProjectRoot(patch.projectRoot) : void 0;
|
|
4258
|
+
const existing = await sessionManager.getSessionRecord(sessionId);
|
|
4259
|
+
const metadata = buildPatchedSessionMetadata(readSessionMetadata(existing?.metadata), patch, projectRootPatch);
|
|
4260
|
+
patched = existing ? await sessionManager.setSessionMetadata(sessionId, metadata) : Boolean(await sessionManager.updateSession(sessionId, { metadata }));
|
|
4271
4261
|
} catch (error) {
|
|
4272
4262
|
if (error instanceof Error && error.message === "PREFERRED_THINKING_INVALID") return c.json(err("PREFERRED_THINKING_INVALID", "preferredThinking must be a supported thinking level"), 400);
|
|
4273
4263
|
if (isSessionProjectRootValidationError(error)) return c.json(err(error.code, error.message), 400);
|
|
4274
4264
|
throw error;
|
|
4275
4265
|
}
|
|
4266
|
+
if (!patched) return c.json(err("NOT_FOUND", `ncp session not found: ${sessionId}`), 404);
|
|
4267
|
+
const updated = await sessionManager.getSession(sessionId);
|
|
4276
4268
|
if (!updated) return c.json(err("NOT_FOUND", `ncp session not found: ${sessionId}`), 404);
|
|
4277
4269
|
return c.json(ok(updated));
|
|
4278
4270
|
};
|
|
4279
4271
|
deleteSession = async (c) => {
|
|
4280
|
-
const
|
|
4281
|
-
if (!sessionApi) return c.json(err("NOT_AVAILABLE", "ncp session api unavailable"), 503);
|
|
4272
|
+
const sessionManager = this.options.kernel.ncpSessionManager;
|
|
4282
4273
|
const sessionId = decodeURIComponent(c.req.param("sessionId"));
|
|
4283
|
-
if (!await
|
|
4284
|
-
await
|
|
4274
|
+
if (!await sessionManager.getSession(sessionId)) return c.json(err("NOT_FOUND", `ncp session not found: ${sessionId}`), 404);
|
|
4275
|
+
await sessionManager.deleteSession(sessionId);
|
|
4285
4276
|
return c.json(ok({
|
|
4286
4277
|
deleted: true,
|
|
4287
4278
|
sessionId
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nextclaw/server",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.23",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Nextclaw UI/API server.",
|
|
6
6
|
"type": "module",
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
"@hono/node-server": "^1.13.3",
|
|
19
19
|
"hono": "^4.6.2",
|
|
20
20
|
"ws": "^8.18.0",
|
|
21
|
-
"@nextclaw/core": "0.12.
|
|
22
|
-
"@nextclaw/
|
|
23
|
-
"@nextclaw/
|
|
24
|
-
"@nextclaw/
|
|
25
|
-
"@nextclaw/openclaw-compat": "1.0.
|
|
26
|
-
"@nextclaw/runtime": "0.2.
|
|
21
|
+
"@nextclaw/core": "0.12.22",
|
|
22
|
+
"@nextclaw/mcp": "0.1.87",
|
|
23
|
+
"@nextclaw/ncp": "0.5.15",
|
|
24
|
+
"@nextclaw/kernel": "0.1.12",
|
|
25
|
+
"@nextclaw/openclaw-compat": "1.0.22",
|
|
26
|
+
"@nextclaw/runtime": "0.2.54"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "^20.17.6",
|