@nextclaw/server 0.5.14 → 0.5.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
@@ -145,6 +145,34 @@ type RuntimeConfigUpdate = {
145
145
  bindings?: AgentBindingView[];
146
146
  session?: SessionConfigView;
147
147
  };
148
+ type ChatTurnRequest = {
149
+ message: string;
150
+ sessionKey?: string;
151
+ agentId?: string;
152
+ channel?: string;
153
+ chatId?: string;
154
+ model?: string;
155
+ metadata?: Record<string, unknown>;
156
+ };
157
+ type ChatTurnResult = {
158
+ reply: string;
159
+ sessionKey: string;
160
+ agentId?: string;
161
+ model?: string;
162
+ metadata?: Record<string, unknown>;
163
+ };
164
+ type ChatTurnView = {
165
+ reply: string;
166
+ sessionKey: string;
167
+ agentId?: string;
168
+ model?: string;
169
+ requestedAt: string;
170
+ completedAt: string;
171
+ durationMs: number;
172
+ };
173
+ type UiChatRuntime = {
174
+ processTurn: (params: ChatTurnRequest) => Promise<ChatTurnResult>;
175
+ };
148
176
  type ConfigView = {
149
177
  agents: {
150
178
  defaults: {
@@ -443,6 +471,7 @@ type UiServerOptions = {
443
471
  staticDir?: string;
444
472
  marketplace?: MarketplaceApiConfig;
445
473
  cronService?: CronService;
474
+ chatRuntime?: UiChatRuntime;
446
475
  };
447
476
  type UiServerHandle = {
448
477
  host: string;
@@ -458,6 +487,7 @@ type UiRouterOptions = {
458
487
  publish: (event: UiServerEvent) => void;
459
488
  marketplace?: MarketplaceApiConfig;
460
489
  cronService?: InstanceType<typeof NextclawCore.CronService>;
490
+ chatRuntime?: UiChatRuntime;
461
491
  };
462
492
  declare function createUiRouter(options: UiRouterOptions): Hono;
463
493
 
@@ -491,4 +521,4 @@ declare function patchSession(configPath: string, key: string, patch: SessionPat
491
521
  declare function deleteSession(configPath: string, key: string): boolean;
492
522
  declare function updateRuntime(configPath: string, patch: RuntimeConfigUpdate): Pick<ConfigView, "agents" | "bindings" | "session">;
493
523
 
494
- export { type AgentBindingView, type AgentProfileView, type ApiError, type ApiResponse, type BindingPeerView, type ChannelSpecView, 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, type MarketplaceApiConfig, type MarketplaceInstallKind, type MarketplaceInstallSkillParams, type MarketplaceInstallSpec, type MarketplaceInstalledRecord, type MarketplaceInstalledView, type MarketplaceInstaller, type MarketplaceItemSummary, type MarketplaceItemType, type MarketplaceItemView, type MarketplaceListView, type MarketplacePluginInstallRequest, type MarketplacePluginInstallResult, type MarketplacePluginManageAction, type MarketplacePluginManageRequest, type MarketplacePluginManageResult, type MarketplaceRecommendationView, type MarketplaceSkillInstallRequest, type MarketplaceSkillInstallResult, type MarketplaceSkillManageAction, type MarketplaceSkillManageRequest, type MarketplaceSkillManageResult, type MarketplaceSort, type ProviderConfigUpdate, type ProviderConfigView, type ProviderSpecView, type RuntimeConfigUpdate, type SessionConfigView, type SessionEntryView, type SessionHistoryView, type SessionMessageView, type SessionPatchUpdate, type SessionsListView, type UiServerEvent, type UiServerHandle, type UiServerOptions, buildConfigMeta, buildConfigSchemaView, buildConfigView, createUiRouter, deleteSession, executeConfigAction, getSessionHistory, listSessions, loadConfigOrDefault, patchSession, startUiServer, updateChannel, updateModel, updateProvider, updateRuntime };
524
+ export { type AgentBindingView, type AgentProfileView, type ApiError, type ApiResponse, type BindingPeerView, type ChannelSpecView, type ChatTurnRequest, type ChatTurnResult, 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, type MarketplaceApiConfig, type MarketplaceInstallKind, type MarketplaceInstallSkillParams, type MarketplaceInstallSpec, type MarketplaceInstalledRecord, type MarketplaceInstalledView, type MarketplaceInstaller, type MarketplaceItemSummary, type MarketplaceItemType, type MarketplaceItemView, type MarketplaceListView, type MarketplacePluginInstallRequest, type MarketplacePluginInstallResult, type MarketplacePluginManageAction, type MarketplacePluginManageRequest, type MarketplacePluginManageResult, type MarketplaceRecommendationView, type MarketplaceSkillInstallRequest, type MarketplaceSkillInstallResult, type MarketplaceSkillManageAction, type MarketplaceSkillManageRequest, type MarketplaceSkillManageResult, type MarketplaceSort, type ProviderConfigUpdate, type ProviderConfigView, type ProviderSpecView, type RuntimeConfigUpdate, type SessionConfigView, type SessionEntryView, type SessionHistoryView, type SessionMessageView, type SessionPatchUpdate, type SessionsListView, type UiChatRuntime, type UiServerEvent, type UiServerHandle, type UiServerOptions, buildConfigMeta, buildConfigSchemaView, buildConfigView, createUiRouter, deleteSession, executeConfigAction, getSessionHistory, listSessions, loadConfigOrDefault, patchSession, startUiServer, updateChannel, updateModel, updateProvider, updateRuntime };
package/dist/index.js CHANGED
@@ -745,6 +745,18 @@ function readErrorMessage(value, fallback) {
745
745
  }
746
746
  return typeof maybeError.message === "string" && maybeError.message.trim().length > 0 ? maybeError.message : fallback;
747
747
  }
748
+ function readNonEmptyString(value) {
749
+ if (typeof value !== "string") {
750
+ return void 0;
751
+ }
752
+ const trimmed = value.trim();
753
+ return trimmed || void 0;
754
+ }
755
+ function resolveAgentIdFromSessionKey(sessionKey) {
756
+ const parsed = NextclawCore.parseAgentScopedSessionKey(sessionKey);
757
+ const agentId = readNonEmptyString(parsed?.agentId);
758
+ return agentId;
759
+ }
748
760
  function normalizeMarketplaceBaseUrl(options) {
749
761
  const fromOptions = options.marketplace?.apiBaseUrl?.trim();
750
762
  const fromEnv = process.env.NEXTCLAW_MARKETPLACE_API_BASE?.trim();
@@ -1488,6 +1500,51 @@ function createUiRouter(options) {
1488
1500
  options.publish({ type: "config.updated", payload: { path: `channels.${channel}` } });
1489
1501
  return c.json(ok(result));
1490
1502
  });
1503
+ app.post("/api/chat/turn", async (c) => {
1504
+ if (!options.chatRuntime) {
1505
+ return c.json(err("NOT_AVAILABLE", "chat runtime unavailable"), 503);
1506
+ }
1507
+ const body = await readJson(c.req.raw);
1508
+ if (!body.ok) {
1509
+ return c.json(err("INVALID_BODY", "invalid json body"), 400);
1510
+ }
1511
+ const message = readNonEmptyString(body.data.message);
1512
+ if (!message) {
1513
+ return c.json(err("INVALID_BODY", "message is required"), 400);
1514
+ }
1515
+ const sessionKey = readNonEmptyString(body.data.sessionKey) ?? `ui:${Date.now().toString(36)}:${Math.random().toString(36).slice(2, 8)}`;
1516
+ const requestedAt = /* @__PURE__ */ new Date();
1517
+ const startedAtMs = requestedAt.getTime();
1518
+ const metadata = isRecord(body.data.metadata) ? body.data.metadata : void 0;
1519
+ const requestedAgentId = readNonEmptyString(body.data.agentId) ?? resolveAgentIdFromSessionKey(sessionKey);
1520
+ const requestedModel = readNonEmptyString(body.data.model);
1521
+ const request = {
1522
+ message,
1523
+ sessionKey,
1524
+ channel: readNonEmptyString(body.data.channel) ?? "ui",
1525
+ chatId: readNonEmptyString(body.data.chatId) ?? "web-ui",
1526
+ ...requestedAgentId ? { agentId: requestedAgentId } : {},
1527
+ ...requestedModel ? { model: requestedModel } : {},
1528
+ ...metadata ? { metadata } : {}
1529
+ };
1530
+ try {
1531
+ const result = await options.chatRuntime.processTurn(request);
1532
+ const completedAt = /* @__PURE__ */ new Date();
1533
+ const response = {
1534
+ reply: String(result.reply ?? ""),
1535
+ sessionKey: readNonEmptyString(result.sessionKey) ?? sessionKey,
1536
+ ...readNonEmptyString(result.agentId) || requestedAgentId ? { agentId: readNonEmptyString(result.agentId) ?? requestedAgentId } : {},
1537
+ ...readNonEmptyString(result.model) || requestedModel ? { model: readNonEmptyString(result.model) ?? requestedModel } : {},
1538
+ requestedAt: requestedAt.toISOString(),
1539
+ completedAt: completedAt.toISOString(),
1540
+ durationMs: Math.max(0, completedAt.getTime() - startedAtMs)
1541
+ };
1542
+ options.publish({ type: "config.updated", payload: { path: "session" } });
1543
+ return c.json(ok(response));
1544
+ } catch (error) {
1545
+ return c.json(err("CHAT_TURN_FAILED", String(error)), 500);
1546
+ }
1547
+ });
1491
1548
  app.get("/api/sessions", (c) => {
1492
1549
  const query = c.req.query();
1493
1550
  const q = typeof query.q === "string" ? query.q : void 0;
@@ -1653,7 +1710,8 @@ function startUiServer(options) {
1653
1710
  configPath: options.configPath,
1654
1711
  publish,
1655
1712
  marketplace: options.marketplace,
1656
- cronService: options.cronService
1713
+ cronService: options.cronService,
1714
+ chatRuntime: options.chatRuntime
1657
1715
  })
1658
1716
  );
1659
1717
  const staticDir = options.staticDir;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextclaw/server",
3
- "version": "0.5.14",
3
+ "version": "0.5.16",
4
4
  "private": false,
5
5
  "description": "Nextclaw UI/API server.",
6
6
  "type": "module",
@@ -15,10 +15,10 @@
15
15
  ],
16
16
  "dependencies": {
17
17
  "@hono/node-server": "^1.13.3",
18
- "@nextclaw/openclaw-compat": "^0.1.27",
18
+ "@nextclaw/openclaw-compat": "^0.1.28",
19
19
  "hono": "^4.6.2",
20
20
  "ws": "^8.18.0",
21
- "@nextclaw/core": "^0.6.33"
21
+ "@nextclaw/core": "^0.6.34"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/node": "^20.17.6",