@nextclaw/server 0.7.0 → 0.8.0
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 +20 -1
- package/dist/index.js +94 -1
- package/package.json +6 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as NextclawCore from '@nextclaw/core';
|
|
2
2
|
import { ThinkingLevel, CronService, Config, ConfigActionExecuteRequest as ConfigActionExecuteRequest$1, ConfigActionExecuteResult as ConfigActionExecuteResult$1 } from '@nextclaw/core';
|
|
3
|
+
import { NcpAgentClientEndpoint, NcpSessionApi, NcpSessionSummary, NcpMessage } from '@nextclaw/ncp';
|
|
4
|
+
import { NcpHttpAgentStreamProvider } from '@nextclaw/ncp-http-agent-server';
|
|
3
5
|
import { Hono } from 'hono';
|
|
4
6
|
import { IncomingMessage } from 'node:http';
|
|
5
7
|
|
|
@@ -450,6 +452,21 @@ type UiChatRuntime = {
|
|
|
450
452
|
listSessionTypes?: () => Promise<ChatSessionTypesView> | ChatSessionTypesView;
|
|
451
453
|
stopTurn?: (params: ChatTurnStopRequest) => Promise<ChatTurnStopResult> | ChatTurnStopResult;
|
|
452
454
|
};
|
|
455
|
+
type UiNcpSessionListView = {
|
|
456
|
+
sessions: NcpSessionSummary[];
|
|
457
|
+
total: number;
|
|
458
|
+
};
|
|
459
|
+
type UiNcpSessionMessagesView = {
|
|
460
|
+
sessionId: string;
|
|
461
|
+
messages: NcpMessage[];
|
|
462
|
+
total: number;
|
|
463
|
+
};
|
|
464
|
+
type UiNcpAgent = {
|
|
465
|
+
agentClientEndpoint: NcpAgentClientEndpoint;
|
|
466
|
+
streamProvider?: NcpHttpAgentStreamProvider;
|
|
467
|
+
sessionApi?: NcpSessionApi;
|
|
468
|
+
basePath?: string;
|
|
469
|
+
};
|
|
453
470
|
type ConfigView = {
|
|
454
471
|
agents: {
|
|
455
472
|
defaults: {
|
|
@@ -831,6 +848,7 @@ type UiServerOptions = {
|
|
|
831
848
|
marketplace?: MarketplaceApiConfig;
|
|
832
849
|
cronService?: CronService;
|
|
833
850
|
chatRuntime?: UiChatRuntime;
|
|
851
|
+
ncpAgent?: UiNcpAgent;
|
|
834
852
|
};
|
|
835
853
|
type UiServerHandle = {
|
|
836
854
|
host: string;
|
|
@@ -886,6 +904,7 @@ type UiRouterOptions = {
|
|
|
886
904
|
marketplace?: MarketplaceApiConfig;
|
|
887
905
|
cronService?: InstanceType<typeof NextclawCore.CronService>;
|
|
888
906
|
chatRuntime?: UiChatRuntime;
|
|
907
|
+
ncpAgent?: UiNcpAgent;
|
|
889
908
|
authService?: UiAuthService;
|
|
890
909
|
};
|
|
891
910
|
|
|
@@ -935,4 +954,4 @@ declare function deleteSession(configPath: string, key: string): boolean;
|
|
|
935
954
|
declare function updateRuntime(configPath: string, patch: RuntimeConfigUpdate): Pick<ConfigView, "agents" | "bindings" | "session">;
|
|
936
955
|
declare function updateSecrets(configPath: string, patch: SecretsConfigUpdate): SecretsView;
|
|
937
956
|
|
|
938
|
-
export { type AgentBindingView, type AgentProfileView, type ApiError, type ApiResponse, type AppMetaView, type AuthEnabledUpdateRequest, type AuthLoginRequest, type AuthPasswordUpdateRequest, type AuthSetupRequest, type AuthStatusView, type BindingPeerView, type BochaFreshnessValue, type ChannelSpecView, type ChatCapabilitiesView, type ChatCommandOptionView, type ChatCommandView, type ChatCommandsView, type ChatRunListView, type ChatRunState, type ChatRunView, type ChatSessionTypeOptionView, type ChatSessionTypesView, type ChatTurnRequest, type ChatTurnResult, type ChatTurnStopRequest, type ChatTurnStopResult, type ChatTurnStreamEvent, type ChatTurnView, type ConfigActionExecuteRequest, type ConfigActionExecuteResult, type ConfigActionManifest, type ConfigActionType, type ConfigMetaView, type ConfigSchemaResponse, type ConfigUiHint, type ConfigUiHints, type ConfigView, type CronActionResult, type CronEnableRequest, type CronJobStateView, type CronJobView, type CronListView, type CronPayloadView, type CronRunRequest, type CronScheduleView, DEFAULT_SESSION_TYPE, type MarketplaceApiConfig, type MarketplaceInstallKind, type MarketplaceInstallSkillParams, type MarketplaceInstallSpec, type MarketplaceInstalledRecord, type MarketplaceInstalledView, type MarketplaceInstaller, type MarketplaceItemSummary, type MarketplaceItemType, type MarketplaceItemView, type MarketplaceListView, type MarketplaceLocalizedTextMap, type MarketplacePluginContentView, type MarketplacePluginInstallKind, type MarketplacePluginInstallRequest, type MarketplacePluginInstallResult, type MarketplacePluginManageAction, type MarketplacePluginManageRequest, type MarketplacePluginManageResult, type MarketplaceRecommendationView, type MarketplaceSkillContentView, type MarketplaceSkillInstallKind, type MarketplaceSkillInstallRequest, type MarketplaceSkillInstallResult, type MarketplaceSkillManageAction, type MarketplaceSkillManageRequest, type MarketplaceSkillManageResult, type MarketplaceSort, type ProviderAuthImportResult, type ProviderAuthPollRequest, type ProviderAuthPollResult, type ProviderAuthStartRequest, type ProviderAuthStartResult, type ProviderConfigUpdate, type ProviderConfigView, type ProviderConnectionTestRequest, type ProviderConnectionTestResult, type ProviderCreateRequest, type ProviderCreateResult, type ProviderDeleteResult, type ProviderSpecView, type RuntimeConfigUpdate, type SearchConfigUpdate, type SearchConfigView, type SearchProviderConfigView, type SearchProviderName, type SearchProviderSpecView, type SecretProviderEnvView, type SecretProviderExecView, type SecretProviderFileView, type SecretProviderView, type SecretRefView, type SecretSourceView, type SecretsConfigUpdate, type SecretsView, type SessionConfigView, type SessionEntryView, type SessionEventView, type SessionHistoryView, type SessionMessageView, type SessionPatchUpdate, SessionPatchValidationError, type SessionsListView, type UiChatRuntime, type UiServerEvent, type UiServerHandle, type UiServerOptions, buildConfigMeta, buildConfigSchemaView, buildConfigView, createCustomProvider, createUiRouter, deleteCustomProvider, deleteSession, executeConfigAction, getSessionHistory, listSessions, loadConfigOrDefault, patchSession, startUiServer, testProviderConnection, updateChannel, updateModel, updateProvider, updateRuntime, updateSearch, updateSecrets };
|
|
957
|
+
export { type AgentBindingView, type AgentProfileView, type ApiError, type ApiResponse, type AppMetaView, type AuthEnabledUpdateRequest, type AuthLoginRequest, type AuthPasswordUpdateRequest, type AuthSetupRequest, type AuthStatusView, type BindingPeerView, type BochaFreshnessValue, type ChannelSpecView, type ChatCapabilitiesView, type ChatCommandOptionView, type ChatCommandView, type ChatCommandsView, type ChatRunListView, type ChatRunState, type ChatRunView, type ChatSessionTypeOptionView, type ChatSessionTypesView, type ChatTurnRequest, type ChatTurnResult, type ChatTurnStopRequest, type ChatTurnStopResult, type ChatTurnStreamEvent, type ChatTurnView, type ConfigActionExecuteRequest, type ConfigActionExecuteResult, type ConfigActionManifest, type ConfigActionType, type ConfigMetaView, type ConfigSchemaResponse, type ConfigUiHint, type ConfigUiHints, type ConfigView, type CronActionResult, type CronEnableRequest, type CronJobStateView, type CronJobView, type CronListView, type CronPayloadView, type CronRunRequest, type CronScheduleView, DEFAULT_SESSION_TYPE, type MarketplaceApiConfig, type MarketplaceInstallKind, type MarketplaceInstallSkillParams, type MarketplaceInstallSpec, type MarketplaceInstalledRecord, type MarketplaceInstalledView, type MarketplaceInstaller, type MarketplaceItemSummary, type MarketplaceItemType, type MarketplaceItemView, type MarketplaceListView, type MarketplaceLocalizedTextMap, type MarketplacePluginContentView, type MarketplacePluginInstallKind, type MarketplacePluginInstallRequest, type MarketplacePluginInstallResult, type MarketplacePluginManageAction, type MarketplacePluginManageRequest, type MarketplacePluginManageResult, type MarketplaceRecommendationView, type MarketplaceSkillContentView, type MarketplaceSkillInstallKind, type MarketplaceSkillInstallRequest, type MarketplaceSkillInstallResult, type MarketplaceSkillManageAction, type MarketplaceSkillManageRequest, type MarketplaceSkillManageResult, type MarketplaceSort, type ProviderAuthImportResult, type ProviderAuthPollRequest, type ProviderAuthPollResult, type ProviderAuthStartRequest, type ProviderAuthStartResult, type ProviderConfigUpdate, type ProviderConfigView, type ProviderConnectionTestRequest, type ProviderConnectionTestResult, type ProviderCreateRequest, type ProviderCreateResult, type ProviderDeleteResult, type ProviderSpecView, type RuntimeConfigUpdate, type SearchConfigUpdate, type SearchConfigView, type SearchProviderConfigView, type SearchProviderName, type SearchProviderSpecView, type SecretProviderEnvView, type SecretProviderExecView, type SecretProviderFileView, type SecretProviderView, type SecretRefView, type SecretSourceView, type SecretsConfigUpdate, type SecretsView, type SessionConfigView, type SessionEntryView, type SessionEventView, type SessionHistoryView, type SessionMessageView, type SessionPatchUpdate, SessionPatchValidationError, type SessionsListView, type UiChatRuntime, type UiNcpAgent, type UiNcpSessionListView, type UiNcpSessionMessagesView, type UiServerEvent, type UiServerHandle, type UiServerOptions, buildConfigMeta, buildConfigSchemaView, buildConfigView, createCustomProvider, createUiRouter, deleteCustomProvider, deleteSession, executeConfigAction, getSessionHistory, listSessions, loadConfigOrDefault, patchSession, startUiServer, testProviderConnection, updateChannel, updateModel, updateProvider, updateRuntime, updateSearch, updateSecrets };
|
package/dist/index.js
CHANGED
|
@@ -320,6 +320,7 @@ var UiAuthService = class {
|
|
|
320
320
|
|
|
321
321
|
// src/ui/router.ts
|
|
322
322
|
import { Hono } from "hono";
|
|
323
|
+
import { mountNcpHttpAgentRoutes } from "@nextclaw/ncp-http-agent-server";
|
|
323
324
|
|
|
324
325
|
// src/ui/router/response.ts
|
|
325
326
|
function ok(data) {
|
|
@@ -3267,6 +3268,83 @@ var CronRoutesController = class {
|
|
|
3267
3268
|
};
|
|
3268
3269
|
};
|
|
3269
3270
|
|
|
3271
|
+
// src/ui/router/ncp-session.controller.ts
|
|
3272
|
+
function readPositiveInt(value) {
|
|
3273
|
+
if (typeof value !== "string") {
|
|
3274
|
+
return void 0;
|
|
3275
|
+
}
|
|
3276
|
+
const parsed = Number.parseInt(value, 10);
|
|
3277
|
+
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
3278
|
+
return void 0;
|
|
3279
|
+
}
|
|
3280
|
+
return parsed;
|
|
3281
|
+
}
|
|
3282
|
+
var NcpSessionRoutesController = class {
|
|
3283
|
+
constructor(options) {
|
|
3284
|
+
this.options = options;
|
|
3285
|
+
}
|
|
3286
|
+
listSessions = async (c) => {
|
|
3287
|
+
const sessionApi = this.options.ncpAgent?.sessionApi;
|
|
3288
|
+
if (!sessionApi) {
|
|
3289
|
+
return c.json(err("NOT_AVAILABLE", "ncp session api unavailable"), 503);
|
|
3290
|
+
}
|
|
3291
|
+
const sessions = await sessionApi.listSessions({
|
|
3292
|
+
limit: readPositiveInt(c.req.query("limit"))
|
|
3293
|
+
});
|
|
3294
|
+
const payload = {
|
|
3295
|
+
sessions,
|
|
3296
|
+
total: sessions.length
|
|
3297
|
+
};
|
|
3298
|
+
return c.json(ok(payload));
|
|
3299
|
+
};
|
|
3300
|
+
getSession = async (c) => {
|
|
3301
|
+
const sessionApi = this.options.ncpAgent?.sessionApi;
|
|
3302
|
+
if (!sessionApi) {
|
|
3303
|
+
return c.json(err("NOT_AVAILABLE", "ncp session api unavailable"), 503);
|
|
3304
|
+
}
|
|
3305
|
+
const sessionId = decodeURIComponent(c.req.param("sessionId"));
|
|
3306
|
+
const session = await sessionApi.getSession(sessionId);
|
|
3307
|
+
if (!session) {
|
|
3308
|
+
return c.json(err("NOT_FOUND", `ncp session not found: ${sessionId}`), 404);
|
|
3309
|
+
}
|
|
3310
|
+
return c.json(ok(session));
|
|
3311
|
+
};
|
|
3312
|
+
listSessionMessages = async (c) => {
|
|
3313
|
+
const sessionApi = this.options.ncpAgent?.sessionApi;
|
|
3314
|
+
if (!sessionApi) {
|
|
3315
|
+
return c.json(err("NOT_AVAILABLE", "ncp session api unavailable"), 503);
|
|
3316
|
+
}
|
|
3317
|
+
const sessionId = decodeURIComponent(c.req.param("sessionId"));
|
|
3318
|
+
const session = await sessionApi.getSession(sessionId);
|
|
3319
|
+
if (!session) {
|
|
3320
|
+
return c.json(err("NOT_FOUND", `ncp session not found: ${sessionId}`), 404);
|
|
3321
|
+
}
|
|
3322
|
+
const messages = await sessionApi.listSessionMessages(sessionId, {
|
|
3323
|
+
limit: readPositiveInt(c.req.query("limit"))
|
|
3324
|
+
});
|
|
3325
|
+
const payload = {
|
|
3326
|
+
sessionId,
|
|
3327
|
+
messages,
|
|
3328
|
+
total: messages.length
|
|
3329
|
+
};
|
|
3330
|
+
return c.json(ok(payload));
|
|
3331
|
+
};
|
|
3332
|
+
deleteSession = async (c) => {
|
|
3333
|
+
const sessionApi = this.options.ncpAgent?.sessionApi;
|
|
3334
|
+
if (!sessionApi) {
|
|
3335
|
+
return c.json(err("NOT_AVAILABLE", "ncp session api unavailable"), 503);
|
|
3336
|
+
}
|
|
3337
|
+
const sessionId = decodeURIComponent(c.req.param("sessionId"));
|
|
3338
|
+
const existing = await sessionApi.getSession(sessionId);
|
|
3339
|
+
if (!existing) {
|
|
3340
|
+
return c.json(err("NOT_FOUND", `ncp session not found: ${sessionId}`), 404);
|
|
3341
|
+
}
|
|
3342
|
+
await sessionApi.deleteSession(sessionId);
|
|
3343
|
+
this.options.publish({ type: "config.updated", payload: { path: "session" } });
|
|
3344
|
+
return c.json(ok({ deleted: true, sessionId }));
|
|
3345
|
+
};
|
|
3346
|
+
};
|
|
3347
|
+
|
|
3270
3348
|
// src/ui/router/marketplace/constants.ts
|
|
3271
3349
|
var DEFAULT_MARKETPLACE_API_BASE = "https://marketplace-api.nextclaw.io";
|
|
3272
3350
|
var NEXTCLAW_PLUGIN_NPM_PREFIX = "@nextclaw/channel-plugin-";
|
|
@@ -4464,6 +4542,7 @@ function createUiRouter(options) {
|
|
|
4464
4542
|
const chatController = new ChatRoutesController(options);
|
|
4465
4543
|
const sessionController = new SessionRoutesController(options);
|
|
4466
4544
|
const cronController = new CronRoutesController(options);
|
|
4545
|
+
const ncpSessionController = new NcpSessionRoutesController(options);
|
|
4467
4546
|
const pluginMarketplaceController = new PluginMarketplaceController(options, marketplaceBaseUrl);
|
|
4468
4547
|
const skillMarketplaceController = new SkillMarketplaceController(options, marketplaceBaseUrl);
|
|
4469
4548
|
app.notFound((c) => c.json(err("NOT_FOUND", "endpoint not found"), 404));
|
|
@@ -4517,6 +4596,17 @@ function createUiRouter(options) {
|
|
|
4517
4596
|
app.get("/api/sessions/:key/history", sessionController.getSessionHistory);
|
|
4518
4597
|
app.put("/api/sessions/:key", sessionController.patchSession);
|
|
4519
4598
|
app.delete("/api/sessions/:key", sessionController.deleteSession);
|
|
4599
|
+
if (options.ncpAgent) {
|
|
4600
|
+
mountNcpHttpAgentRoutes(app, {
|
|
4601
|
+
basePath: options.ncpAgent.basePath ?? "/api/ncp/agent",
|
|
4602
|
+
agentClientEndpoint: options.ncpAgent.agentClientEndpoint,
|
|
4603
|
+
streamProvider: options.ncpAgent.streamProvider
|
|
4604
|
+
});
|
|
4605
|
+
app.get("/api/ncp/sessions", ncpSessionController.listSessions);
|
|
4606
|
+
app.get("/api/ncp/sessions/:sessionId", ncpSessionController.getSession);
|
|
4607
|
+
app.get("/api/ncp/sessions/:sessionId/messages", ncpSessionController.listSessionMessages);
|
|
4608
|
+
app.delete("/api/ncp/sessions/:sessionId", ncpSessionController.deleteSession);
|
|
4609
|
+
}
|
|
4520
4610
|
app.get("/api/cron", cronController.listJobs);
|
|
4521
4611
|
app.delete("/api/cron/:id", cronController.deleteJob);
|
|
4522
4612
|
app.put("/api/cron/:id/enable", cronController.enableJob);
|
|
@@ -4573,6 +4663,7 @@ function startUiServer(options) {
|
|
|
4573
4663
|
marketplace: options.marketplace,
|
|
4574
4664
|
cronService: options.cronService,
|
|
4575
4665
|
chatRuntime: options.chatRuntime,
|
|
4666
|
+
ncpAgent: options.ncpAgent,
|
|
4576
4667
|
authService
|
|
4577
4668
|
})
|
|
4578
4669
|
);
|
|
@@ -4641,7 +4732,9 @@ function startUiServer(options) {
|
|
|
4641
4732
|
publish,
|
|
4642
4733
|
close: () => new Promise((resolve2) => {
|
|
4643
4734
|
wss.close(() => {
|
|
4644
|
-
server.close(() =>
|
|
4735
|
+
server.close(() => {
|
|
4736
|
+
Promise.resolve(options.ncpAgent?.agentClientEndpoint.stop()).catch(() => void 0).finally(() => resolve2());
|
|
4737
|
+
});
|
|
4645
4738
|
});
|
|
4646
4739
|
})
|
|
4647
4740
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nextclaw/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Nextclaw UI/API server.",
|
|
6
6
|
"type": "module",
|
|
@@ -18,9 +18,11 @@
|
|
|
18
18
|
"@hono/node-server": "^1.13.3",
|
|
19
19
|
"hono": "^4.6.2",
|
|
20
20
|
"ws": "^8.18.0",
|
|
21
|
-
"@nextclaw/
|
|
22
|
-
"@nextclaw/
|
|
23
|
-
"@nextclaw/
|
|
21
|
+
"@nextclaw/ncp-http-agent-server": "0.3.0",
|
|
22
|
+
"@nextclaw/openclaw-compat": "0.3.0",
|
|
23
|
+
"@nextclaw/ncp": "0.3.0",
|
|
24
|
+
"@nextclaw/runtime": "0.2.0",
|
|
25
|
+
"@nextclaw/core": "0.9.0"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
26
28
|
"@types/node": "^20.17.6",
|