@nextclaw/server 0.5.21 → 0.5.22
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 +12 -1
- package/dist/index.js +134 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -27,6 +27,16 @@ type ProviderConfigUpdate = {
|
|
|
27
27
|
extraHeaders?: Record<string, string> | null;
|
|
28
28
|
wireApi?: "auto" | "chat" | "responses" | null;
|
|
29
29
|
};
|
|
30
|
+
type ProviderConnectionTestRequest = ProviderConfigUpdate & {
|
|
31
|
+
model?: string | null;
|
|
32
|
+
};
|
|
33
|
+
type ProviderConnectionTestResult = {
|
|
34
|
+
success: boolean;
|
|
35
|
+
provider: string;
|
|
36
|
+
model?: string;
|
|
37
|
+
latencyMs: number;
|
|
38
|
+
message: string;
|
|
39
|
+
};
|
|
30
40
|
type AgentProfileView = {
|
|
31
41
|
id: string;
|
|
32
42
|
default?: boolean;
|
|
@@ -578,6 +588,7 @@ declare function updateModel(configPath: string, patch: {
|
|
|
578
588
|
maxTokens?: number;
|
|
579
589
|
}): ConfigView;
|
|
580
590
|
declare function updateProvider(configPath: string, providerName: string, patch: ProviderConfigUpdate): ProviderConfigView | null;
|
|
591
|
+
declare function testProviderConnection(configPath: string, providerName: string, patch: ProviderConnectionTestRequest): Promise<ProviderConnectionTestResult | null>;
|
|
581
592
|
declare function updateChannel(configPath: string, channelName: string, patch: Record<string, unknown>): Record<string, unknown> | null;
|
|
582
593
|
declare function listSessions(configPath: string, query?: {
|
|
583
594
|
q?: string;
|
|
@@ -590,4 +601,4 @@ declare function deleteSession(configPath: string, key: string): boolean;
|
|
|
590
601
|
declare function updateRuntime(configPath: string, patch: RuntimeConfigUpdate): Pick<ConfigView, "agents" | "bindings" | "session">;
|
|
591
602
|
declare function updateSecrets(configPath: string, patch: SecretsConfigUpdate): SecretsView;
|
|
592
603
|
|
|
593
|
-
export { type AgentBindingView, type AgentProfileView, type ApiError, type ApiResponse, type BindingPeerView, type ChannelSpecView, type ChatTurnRequest, type ChatTurnResult, 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, 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 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, 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, updateSecrets };
|
|
604
|
+
export { type AgentBindingView, type AgentProfileView, type ApiError, type ApiResponse, type BindingPeerView, type ChannelSpecView, type ChatTurnRequest, type ChatTurnResult, 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, 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 ProviderConnectionTestRequest, type ProviderConnectionTestResult, type ProviderSpecView, type RuntimeConfigUpdate, 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, type SessionsListView, type UiChatRuntime, type UiServerEvent, type UiServerHandle, type UiServerOptions, buildConfigMeta, buildConfigSchemaView, buildConfigView, createUiRouter, deleteSession, executeConfigAction, getSessionHistory, listSessions, loadConfigOrDefault, patchSession, startUiServer, testProviderConnection, updateChannel, updateModel, updateProvider, updateRuntime, updateSecrets };
|
package/dist/index.js
CHANGED
|
@@ -19,9 +19,11 @@ import {
|
|
|
19
19
|
saveConfig,
|
|
20
20
|
ConfigSchema,
|
|
21
21
|
probeFeishu,
|
|
22
|
+
LiteLLMProvider,
|
|
22
23
|
PROVIDERS,
|
|
23
24
|
buildConfigSchema,
|
|
24
25
|
findProviderByName,
|
|
26
|
+
getProviderName,
|
|
25
27
|
getPackageVersion,
|
|
26
28
|
hasSecretRef,
|
|
27
29
|
isSensitiveConfigPath,
|
|
@@ -30,6 +32,19 @@ import {
|
|
|
30
32
|
} from "@nextclaw/core";
|
|
31
33
|
var MASK_MIN_LENGTH = 8;
|
|
32
34
|
var EXTRA_SENSITIVE_PATH_PATTERNS = [/authorization/i, /cookie/i, /session/i, /bearer/i];
|
|
35
|
+
var PROVIDER_TEST_MODEL_FALLBACKS = {
|
|
36
|
+
openai: "gpt-4o-mini",
|
|
37
|
+
deepseek: "deepseek-chat",
|
|
38
|
+
gemini: "gemini-2.0-flash",
|
|
39
|
+
zhipu: "glm-4-flash",
|
|
40
|
+
dashscope: "qwen-plus",
|
|
41
|
+
moonshot: "moonshot-v1-8k",
|
|
42
|
+
minimax: "minimax-text-01",
|
|
43
|
+
groq: "llama-3.1-8b-instant",
|
|
44
|
+
openrouter: "openai/gpt-4o-mini",
|
|
45
|
+
aihubmix: "gpt-4o-mini",
|
|
46
|
+
anthropic: "claude-3-5-haiku-latest"
|
|
47
|
+
};
|
|
33
48
|
function matchesExtraSensitivePath(path) {
|
|
34
49
|
if (path === "session" || path.startsWith("session.")) {
|
|
35
50
|
return false;
|
|
@@ -400,6 +415,108 @@ function updateProvider(configPath, providerName, patch) {
|
|
|
400
415
|
const updated = next.providers[providerName];
|
|
401
416
|
return toProviderView(next, updated, providerName, uiHints, spec ?? void 0);
|
|
402
417
|
}
|
|
418
|
+
function normalizeOptionalString(value) {
|
|
419
|
+
if (typeof value !== "string") {
|
|
420
|
+
return null;
|
|
421
|
+
}
|
|
422
|
+
const trimmed = value.trim();
|
|
423
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
424
|
+
}
|
|
425
|
+
function normalizeHeaders(input) {
|
|
426
|
+
if (!input) {
|
|
427
|
+
return null;
|
|
428
|
+
}
|
|
429
|
+
const entries = Object.entries(input).map(([key, value]) => [key.trim(), String(value ?? "").trim()]).filter(([key, value]) => key.length > 0 && value.length > 0);
|
|
430
|
+
if (entries.length === 0) {
|
|
431
|
+
return null;
|
|
432
|
+
}
|
|
433
|
+
return Object.fromEntries(entries);
|
|
434
|
+
}
|
|
435
|
+
function resolveTestModel(config, providerName, requestedModel) {
|
|
436
|
+
if (requestedModel) {
|
|
437
|
+
return requestedModel;
|
|
438
|
+
}
|
|
439
|
+
const defaultModel = normalizeOptionalString(config.agents.defaults.model);
|
|
440
|
+
if (defaultModel) {
|
|
441
|
+
const routedProvider = getProviderName(config, defaultModel);
|
|
442
|
+
if (!routedProvider || routedProvider === providerName) {
|
|
443
|
+
return defaultModel;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return PROVIDER_TEST_MODEL_FALLBACKS[providerName] ?? defaultModel ?? null;
|
|
447
|
+
}
|
|
448
|
+
function stringifyError(error) {
|
|
449
|
+
const raw = error instanceof Error ? error.message : String(error);
|
|
450
|
+
return raw.replace(/\s+/g, " ").trim();
|
|
451
|
+
}
|
|
452
|
+
async function testProviderConnection(configPath, providerName, patch) {
|
|
453
|
+
const config = loadConfigOrDefault(configPath);
|
|
454
|
+
const provider = config.providers[providerName];
|
|
455
|
+
if (!provider) {
|
|
456
|
+
return null;
|
|
457
|
+
}
|
|
458
|
+
const spec = findProviderByName(providerName);
|
|
459
|
+
const hasApiKeyPatch = Object.prototype.hasOwnProperty.call(patch, "apiKey");
|
|
460
|
+
const providedApiKey = normalizeOptionalString(patch.apiKey);
|
|
461
|
+
const currentApiKey = normalizeOptionalString(provider.apiKey);
|
|
462
|
+
const apiKey = hasApiKeyPatch ? providedApiKey : currentApiKey;
|
|
463
|
+
const hasApiBasePatch = Object.prototype.hasOwnProperty.call(patch, "apiBase");
|
|
464
|
+
const patchedApiBase = normalizeOptionalString(patch.apiBase);
|
|
465
|
+
const currentApiBase = normalizeOptionalString(provider.apiBase);
|
|
466
|
+
const apiBase = hasApiBasePatch ? patchedApiBase ?? spec?.defaultApiBase ?? null : currentApiBase ?? spec?.defaultApiBase ?? null;
|
|
467
|
+
const hasHeadersPatch = Object.prototype.hasOwnProperty.call(patch, "extraHeaders");
|
|
468
|
+
const extraHeaders = hasHeadersPatch ? normalizeHeaders(patch.extraHeaders ?? null) : normalizeHeaders(provider.extraHeaders ?? null);
|
|
469
|
+
const wireApi = spec?.supportsWireApi ? patch.wireApi ?? provider.wireApi ?? spec.defaultWireApi ?? "auto" : null;
|
|
470
|
+
if (!apiKey && !spec?.isLocal) {
|
|
471
|
+
return {
|
|
472
|
+
success: false,
|
|
473
|
+
provider: providerName,
|
|
474
|
+
latencyMs: 0,
|
|
475
|
+
message: "API key is required before testing the connection."
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
const requestedModel = normalizeOptionalString(patch.model);
|
|
479
|
+
const model = resolveTestModel(config, providerName, requestedModel);
|
|
480
|
+
if (!model) {
|
|
481
|
+
return {
|
|
482
|
+
success: false,
|
|
483
|
+
provider: providerName,
|
|
484
|
+
latencyMs: 0,
|
|
485
|
+
message: "No test model found. Set a default model first, then try again."
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
const probe = new LiteLLMProvider({
|
|
489
|
+
apiKey,
|
|
490
|
+
apiBase,
|
|
491
|
+
defaultModel: model,
|
|
492
|
+
extraHeaders,
|
|
493
|
+
providerName,
|
|
494
|
+
wireApi
|
|
495
|
+
});
|
|
496
|
+
const startedAtMs = Date.now();
|
|
497
|
+
try {
|
|
498
|
+
await probe.chat({
|
|
499
|
+
model,
|
|
500
|
+
messages: [{ role: "user", content: "ping" }],
|
|
501
|
+
maxTokens: 8
|
|
502
|
+
});
|
|
503
|
+
return {
|
|
504
|
+
success: true,
|
|
505
|
+
provider: providerName,
|
|
506
|
+
model,
|
|
507
|
+
latencyMs: Date.now() - startedAtMs,
|
|
508
|
+
message: "Connection test passed."
|
|
509
|
+
};
|
|
510
|
+
} catch (error) {
|
|
511
|
+
return {
|
|
512
|
+
success: false,
|
|
513
|
+
provider: providerName,
|
|
514
|
+
model,
|
|
515
|
+
latencyMs: Date.now() - startedAtMs,
|
|
516
|
+
message: stringifyError(error) || "Connection test failed."
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
}
|
|
403
520
|
function updateChannel(configPath, channelName, patch) {
|
|
404
521
|
const config = loadConfigOrDefault(configPath);
|
|
405
522
|
const channel = config.channels[channelName];
|
|
@@ -1594,6 +1711,22 @@ function createUiRouter(options) {
|
|
|
1594
1711
|
options.publish({ type: "config.updated", payload: { path: `providers.${provider}` } });
|
|
1595
1712
|
return c.json(ok(result));
|
|
1596
1713
|
});
|
|
1714
|
+
app.post("/api/config/providers/:provider/test", async (c) => {
|
|
1715
|
+
const provider = c.req.param("provider");
|
|
1716
|
+
const body = await readJson(c.req.raw);
|
|
1717
|
+
if (!body.ok) {
|
|
1718
|
+
return c.json(err("INVALID_BODY", "invalid json body"), 400);
|
|
1719
|
+
}
|
|
1720
|
+
const result = await testProviderConnection(
|
|
1721
|
+
options.configPath,
|
|
1722
|
+
provider,
|
|
1723
|
+
body.data
|
|
1724
|
+
);
|
|
1725
|
+
if (!result) {
|
|
1726
|
+
return c.json(err("NOT_FOUND", `unknown provider: ${provider}`), 404);
|
|
1727
|
+
}
|
|
1728
|
+
return c.json(ok(result));
|
|
1729
|
+
});
|
|
1597
1730
|
app.put("/api/config/channels/:channel", async (c) => {
|
|
1598
1731
|
const channel = c.req.param("channel");
|
|
1599
1732
|
const body = await readJson(c.req.raw);
|
|
@@ -2014,6 +2147,7 @@ export {
|
|
|
2014
2147
|
loadConfigOrDefault,
|
|
2015
2148
|
patchSession,
|
|
2016
2149
|
startUiServer,
|
|
2150
|
+
testProviderConnection,
|
|
2017
2151
|
updateChannel,
|
|
2018
2152
|
updateModel,
|
|
2019
2153
|
updateProvider,
|