@nextclaw/server 0.5.15 → 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 +34 -2
- package/dist/index.js +65 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -70,10 +70,12 @@ type SessionsListView = {
|
|
|
70
70
|
};
|
|
71
71
|
type SessionMessageView = {
|
|
72
72
|
role: string;
|
|
73
|
-
content:
|
|
73
|
+
content: unknown;
|
|
74
74
|
timestamp: string;
|
|
75
75
|
name?: string;
|
|
76
76
|
tool_call_id?: string;
|
|
77
|
+
tool_calls?: Array<Record<string, unknown>>;
|
|
78
|
+
reasoning_content?: string;
|
|
77
79
|
};
|
|
78
80
|
type SessionHistoryView = {
|
|
79
81
|
key: string;
|
|
@@ -145,6 +147,34 @@ type RuntimeConfigUpdate = {
|
|
|
145
147
|
bindings?: AgentBindingView[];
|
|
146
148
|
session?: SessionConfigView;
|
|
147
149
|
};
|
|
150
|
+
type ChatTurnRequest = {
|
|
151
|
+
message: string;
|
|
152
|
+
sessionKey?: string;
|
|
153
|
+
agentId?: string;
|
|
154
|
+
channel?: string;
|
|
155
|
+
chatId?: string;
|
|
156
|
+
model?: string;
|
|
157
|
+
metadata?: Record<string, unknown>;
|
|
158
|
+
};
|
|
159
|
+
type ChatTurnResult = {
|
|
160
|
+
reply: string;
|
|
161
|
+
sessionKey: string;
|
|
162
|
+
agentId?: string;
|
|
163
|
+
model?: string;
|
|
164
|
+
metadata?: Record<string, unknown>;
|
|
165
|
+
};
|
|
166
|
+
type ChatTurnView = {
|
|
167
|
+
reply: string;
|
|
168
|
+
sessionKey: string;
|
|
169
|
+
agentId?: string;
|
|
170
|
+
model?: string;
|
|
171
|
+
requestedAt: string;
|
|
172
|
+
completedAt: string;
|
|
173
|
+
durationMs: number;
|
|
174
|
+
};
|
|
175
|
+
type UiChatRuntime = {
|
|
176
|
+
processTurn: (params: ChatTurnRequest) => Promise<ChatTurnResult>;
|
|
177
|
+
};
|
|
148
178
|
type ConfigView = {
|
|
149
179
|
agents: {
|
|
150
180
|
defaults: {
|
|
@@ -443,6 +473,7 @@ type UiServerOptions = {
|
|
|
443
473
|
staticDir?: string;
|
|
444
474
|
marketplace?: MarketplaceApiConfig;
|
|
445
475
|
cronService?: CronService;
|
|
476
|
+
chatRuntime?: UiChatRuntime;
|
|
446
477
|
};
|
|
447
478
|
type UiServerHandle = {
|
|
448
479
|
host: string;
|
|
@@ -458,6 +489,7 @@ type UiRouterOptions = {
|
|
|
458
489
|
publish: (event: UiServerEvent) => void;
|
|
459
490
|
marketplace?: MarketplaceApiConfig;
|
|
460
491
|
cronService?: InstanceType<typeof NextclawCore.CronService>;
|
|
492
|
+
chatRuntime?: UiChatRuntime;
|
|
461
493
|
};
|
|
462
494
|
declare function createUiRouter(options: UiRouterOptions): Hono;
|
|
463
495
|
|
|
@@ -491,4 +523,4 @@ declare function patchSession(configPath: string, key: string, patch: SessionPat
|
|
|
491
523
|
declare function deleteSession(configPath: string, key: string): boolean;
|
|
492
524
|
declare function updateRuntime(configPath: string, patch: RuntimeConfigUpdate): Pick<ConfigView, "agents" | "bindings" | "session">;
|
|
493
525
|
|
|
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 };
|
|
526
|
+
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
|
@@ -485,6 +485,12 @@ function getSessionHistory(configPath, key, limit) {
|
|
|
485
485
|
if (typeof message.tool_call_id === "string") {
|
|
486
486
|
entry.tool_call_id = message.tool_call_id;
|
|
487
487
|
}
|
|
488
|
+
if (Array.isArray(message.tool_calls)) {
|
|
489
|
+
entry.tool_calls = message.tool_calls;
|
|
490
|
+
}
|
|
491
|
+
if (typeof message.reasoning_content === "string") {
|
|
492
|
+
entry.reasoning_content = message.reasoning_content;
|
|
493
|
+
}
|
|
488
494
|
return entry;
|
|
489
495
|
})
|
|
490
496
|
};
|
|
@@ -745,6 +751,18 @@ function readErrorMessage(value, fallback) {
|
|
|
745
751
|
}
|
|
746
752
|
return typeof maybeError.message === "string" && maybeError.message.trim().length > 0 ? maybeError.message : fallback;
|
|
747
753
|
}
|
|
754
|
+
function readNonEmptyString(value) {
|
|
755
|
+
if (typeof value !== "string") {
|
|
756
|
+
return void 0;
|
|
757
|
+
}
|
|
758
|
+
const trimmed = value.trim();
|
|
759
|
+
return trimmed || void 0;
|
|
760
|
+
}
|
|
761
|
+
function resolveAgentIdFromSessionKey(sessionKey) {
|
|
762
|
+
const parsed = NextclawCore.parseAgentScopedSessionKey(sessionKey);
|
|
763
|
+
const agentId = readNonEmptyString(parsed?.agentId);
|
|
764
|
+
return agentId;
|
|
765
|
+
}
|
|
748
766
|
function normalizeMarketplaceBaseUrl(options) {
|
|
749
767
|
const fromOptions = options.marketplace?.apiBaseUrl?.trim();
|
|
750
768
|
const fromEnv = process.env.NEXTCLAW_MARKETPLACE_API_BASE?.trim();
|
|
@@ -1488,6 +1506,51 @@ function createUiRouter(options) {
|
|
|
1488
1506
|
options.publish({ type: "config.updated", payload: { path: `channels.${channel}` } });
|
|
1489
1507
|
return c.json(ok(result));
|
|
1490
1508
|
});
|
|
1509
|
+
app.post("/api/chat/turn", async (c) => {
|
|
1510
|
+
if (!options.chatRuntime) {
|
|
1511
|
+
return c.json(err("NOT_AVAILABLE", "chat runtime unavailable"), 503);
|
|
1512
|
+
}
|
|
1513
|
+
const body = await readJson(c.req.raw);
|
|
1514
|
+
if (!body.ok) {
|
|
1515
|
+
return c.json(err("INVALID_BODY", "invalid json body"), 400);
|
|
1516
|
+
}
|
|
1517
|
+
const message = readNonEmptyString(body.data.message);
|
|
1518
|
+
if (!message) {
|
|
1519
|
+
return c.json(err("INVALID_BODY", "message is required"), 400);
|
|
1520
|
+
}
|
|
1521
|
+
const sessionKey = readNonEmptyString(body.data.sessionKey) ?? `ui:${Date.now().toString(36)}:${Math.random().toString(36).slice(2, 8)}`;
|
|
1522
|
+
const requestedAt = /* @__PURE__ */ new Date();
|
|
1523
|
+
const startedAtMs = requestedAt.getTime();
|
|
1524
|
+
const metadata = isRecord(body.data.metadata) ? body.data.metadata : void 0;
|
|
1525
|
+
const requestedAgentId = readNonEmptyString(body.data.agentId) ?? resolveAgentIdFromSessionKey(sessionKey);
|
|
1526
|
+
const requestedModel = readNonEmptyString(body.data.model);
|
|
1527
|
+
const request = {
|
|
1528
|
+
message,
|
|
1529
|
+
sessionKey,
|
|
1530
|
+
channel: readNonEmptyString(body.data.channel) ?? "ui",
|
|
1531
|
+
chatId: readNonEmptyString(body.data.chatId) ?? "web-ui",
|
|
1532
|
+
...requestedAgentId ? { agentId: requestedAgentId } : {},
|
|
1533
|
+
...requestedModel ? { model: requestedModel } : {},
|
|
1534
|
+
...metadata ? { metadata } : {}
|
|
1535
|
+
};
|
|
1536
|
+
try {
|
|
1537
|
+
const result = await options.chatRuntime.processTurn(request);
|
|
1538
|
+
const completedAt = /* @__PURE__ */ new Date();
|
|
1539
|
+
const response = {
|
|
1540
|
+
reply: String(result.reply ?? ""),
|
|
1541
|
+
sessionKey: readNonEmptyString(result.sessionKey) ?? sessionKey,
|
|
1542
|
+
...readNonEmptyString(result.agentId) || requestedAgentId ? { agentId: readNonEmptyString(result.agentId) ?? requestedAgentId } : {},
|
|
1543
|
+
...readNonEmptyString(result.model) || requestedModel ? { model: readNonEmptyString(result.model) ?? requestedModel } : {},
|
|
1544
|
+
requestedAt: requestedAt.toISOString(),
|
|
1545
|
+
completedAt: completedAt.toISOString(),
|
|
1546
|
+
durationMs: Math.max(0, completedAt.getTime() - startedAtMs)
|
|
1547
|
+
};
|
|
1548
|
+
options.publish({ type: "config.updated", payload: { path: "session" } });
|
|
1549
|
+
return c.json(ok(response));
|
|
1550
|
+
} catch (error) {
|
|
1551
|
+
return c.json(err("CHAT_TURN_FAILED", String(error)), 500);
|
|
1552
|
+
}
|
|
1553
|
+
});
|
|
1491
1554
|
app.get("/api/sessions", (c) => {
|
|
1492
1555
|
const query = c.req.query();
|
|
1493
1556
|
const q = typeof query.q === "string" ? query.q : void 0;
|
|
@@ -1653,7 +1716,8 @@ function startUiServer(options) {
|
|
|
1653
1716
|
configPath: options.configPath,
|
|
1654
1717
|
publish,
|
|
1655
1718
|
marketplace: options.marketplace,
|
|
1656
|
-
cronService: options.cronService
|
|
1719
|
+
cronService: options.cronService,
|
|
1720
|
+
chatRuntime: options.chatRuntime
|
|
1657
1721
|
})
|
|
1658
1722
|
);
|
|
1659
1723
|
const staticDir = options.staticDir;
|