rol-websocket-channel 1.4.2 → 1.4.8
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/{MQTT-API /346/226/260/345/242/236/346/226/207/344/273/266/345/212/237/350/203/275.md" → MQTT-API 5-6.md } +89 -1
- package/dist/index.js +617 -617
- package/dist/message-handler.js +515 -503
- package/dist/src/admin/cli.js +43 -43
- package/dist/src/admin/jsonrpc.js +60 -60
- package/dist/src/admin/lib/fs.js +30 -30
- package/dist/src/admin/lib/paths.js +80 -80
- package/dist/src/admin/methods/admin.js +60 -60
- package/dist/src/admin/methods/agents-extended.js +251 -251
- package/dist/src/admin/methods/artifacts.js +736 -642
- package/dist/src/admin/methods/artifacts.test.js +210 -191
- package/dist/src/admin/methods/cron.js +250 -250
- package/dist/src/admin/methods/index.js +104 -102
- package/dist/src/admin/methods/mem9.js +309 -270
- package/dist/src/admin/methods/mem9.test.js +34 -0
- package/dist/src/admin/methods/memory.js +363 -363
- package/dist/src/admin/methods/models-extended.js +190 -190
- package/dist/src/admin/methods/models.js +195 -195
- package/dist/src/admin/methods/pairing.js +268 -268
- package/dist/src/admin/methods/sessions-extended.js +215 -215
- package/dist/src/admin/methods/sessions.js +75 -75
- package/dist/src/admin/methods/skills-extended.js +157 -157
- package/dist/src/admin/methods/skills-toggle.js +183 -183
- package/dist/src/admin/methods/skills.js +528 -528
- package/dist/src/admin/methods/system.js +271 -180
- package/dist/src/admin/methods/usage.js +1170 -1170
- package/dist/src/admin/types.js +1 -1
- package/dist/src/mqtt/connection-manager.js +209 -209
- package/dist/src/mqtt/index.js +5 -5
- package/dist/src/mqtt/mqtt-client.js +110 -110
- package/dist/src/mqtt/mqtt.test.js +418 -418
- package/dist/src/mqtt/types.js +2 -2
- package/dist/src/shared/context.js +24 -24
- package/dist/src/shared/wrapper.js +23 -23
- package/message-handler.ts +15 -1
- package/openclaw.plugin.json +73 -0
- package/package.json +1 -1
- package/src/admin/methods/artifacts.test.ts +35 -0
- package/src/admin/methods/artifacts.ts +140 -2
- package/src/admin/methods/index.ts +3 -1
- package/src/admin/methods/mem9.test.ts +39 -0
- package/src/admin/methods/mem9.ts +48 -1
- package/src/admin/methods/system.ts +129 -1
|
@@ -1,195 +1,195 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { readJsonFile } from '../lib/fs.js';
|
|
3
|
-
export const getModels = async (_params, context) => {
|
|
4
|
-
const configPath = path.join(context.openclawRoot, 'openclaw.json');
|
|
5
|
-
const config = await readJsonFile(configPath);
|
|
6
|
-
const agents = normalizeAgentModels(config);
|
|
7
|
-
const providers = config.models?.providers ?? {};
|
|
8
|
-
return {
|
|
9
|
-
sourceConfigFile: configPath,
|
|
10
|
-
defaults: {
|
|
11
|
-
model: normalizeModelConfig(config.agents?.defaults?.model),
|
|
12
|
-
models: config.agents?.defaults?.models ?? {}
|
|
13
|
-
},
|
|
14
|
-
agents,
|
|
15
|
-
modelOptions: buildModelOptions(config, providers, agents),
|
|
16
|
-
modelConfigMode: config.models?.mode ?? null,
|
|
17
|
-
configuredProviders: redactSecrets(providers)
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
function normalizeAgentModels(config) {
|
|
21
|
-
const items = [
|
|
22
|
-
{
|
|
23
|
-
id: 'defaults',
|
|
24
|
-
name: 'defaults',
|
|
25
|
-
model: normalizeModelConfig(config.agents?.defaults?.model)
|
|
26
|
-
}
|
|
27
|
-
];
|
|
28
|
-
const agents = Array.isArray(config.agents?.list) ? config.agents.list : [];
|
|
29
|
-
for (const agent of agents) {
|
|
30
|
-
items.push({
|
|
31
|
-
id: agent.id ?? null,
|
|
32
|
-
name: agent.name ?? agent.id ?? null,
|
|
33
|
-
model: normalizeModelConfig(agent.model)
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
return items;
|
|
37
|
-
}
|
|
38
|
-
function normalizeModelConfig(modelConfig) {
|
|
39
|
-
if (!modelConfig || typeof modelConfig !== 'object' || Array.isArray(modelConfig)) {
|
|
40
|
-
return {};
|
|
41
|
-
}
|
|
42
|
-
const primary = pickString(modelConfig.primary);
|
|
43
|
-
const provider = pickString(modelConfig.provider);
|
|
44
|
-
const inferredProvider = primary && !provider ? inferProviderFromPrimaryModel(primary) : null;
|
|
45
|
-
return {
|
|
46
|
-
...modelConfig,
|
|
47
|
-
...(inferredProvider ? { provider: inferredProvider } : {})
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
function buildModelOptions(config, providers, agents) {
|
|
51
|
-
const options = new Map();
|
|
52
|
-
addCatalogModelOptions(options, providers, config.agents?.defaults?.models);
|
|
53
|
-
if (options.size === 0) {
|
|
54
|
-
addFallbackAgentModelOptions(options, providers, agents);
|
|
55
|
-
}
|
|
56
|
-
return Array.from(options.values());
|
|
57
|
-
}
|
|
58
|
-
function addCatalogModelOptions(options, providers, catalog) {
|
|
59
|
-
if (!catalog || typeof catalog !== 'object' || Array.isArray(catalog)) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
for (const [modelId, modelConfig] of Object.entries(catalog)) {
|
|
63
|
-
const provider = inferProviderFromPrimaryModel(modelId);
|
|
64
|
-
const model = extractModelName(modelId, provider);
|
|
65
|
-
const providerConfig = provider ? providers[provider] : null;
|
|
66
|
-
const providerLabel = provider
|
|
67
|
-
? (pickString(providerConfig?.label) ?? pickString(providerConfig?.name) ?? humanizeProviderId(provider))
|
|
68
|
-
: null;
|
|
69
|
-
const label = modelConfig && typeof modelConfig === 'object'
|
|
70
|
-
? (pickString(modelConfig.alias) ?? pickString(modelConfig.label) ?? pickString(modelConfig.name) ?? humanizeModelId(model))
|
|
71
|
-
: humanizeModelId(model);
|
|
72
|
-
addModelOption(options, {
|
|
73
|
-
provider,
|
|
74
|
-
providerLabel,
|
|
75
|
-
model,
|
|
76
|
-
value: modelId,
|
|
77
|
-
label
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function addFallbackAgentModelOptions(options, providers, agents) {
|
|
82
|
-
for (const agent of agents) {
|
|
83
|
-
if (!agent || typeof agent !== 'object' || Array.isArray(agent)) {
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
const modelConfig = agent.model;
|
|
87
|
-
if (!modelConfig || typeof modelConfig !== 'object' || Array.isArray(modelConfig)) {
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
const primary = pickString(modelConfig.primary);
|
|
91
|
-
if (!primary) {
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
const provider = pickString(modelConfig.provider) ?? inferProviderFromPrimaryModel(primary);
|
|
95
|
-
const model = extractModelName(primary, provider);
|
|
96
|
-
const providerConfig = provider ? providers[provider] : null;
|
|
97
|
-
const providerLabel = provider
|
|
98
|
-
? (pickString(providerConfig?.label) ?? pickString(providerConfig?.name) ?? humanizeProviderId(provider))
|
|
99
|
-
: null;
|
|
100
|
-
addModelOption(options, {
|
|
101
|
-
provider,
|
|
102
|
-
providerLabel,
|
|
103
|
-
model,
|
|
104
|
-
value: primary,
|
|
105
|
-
label: humanizeModelId(model)
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
function addModelOption(options, input) {
|
|
110
|
-
const value = input.value ?? (input.provider ? `${input.provider}/${input.model}` : input.model);
|
|
111
|
-
if (options.has(value)) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
options.set(value, {
|
|
115
|
-
label: input.label,
|
|
116
|
-
value,
|
|
117
|
-
provider: input.provider,
|
|
118
|
-
providerLabel: input.providerLabel,
|
|
119
|
-
model: input.model
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
function inferProviderFromPrimaryModel(primaryModel) {
|
|
123
|
-
const slashIndex = primaryModel.indexOf('/');
|
|
124
|
-
if (slashIndex <= 0) {
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
return primaryModel.slice(0, slashIndex);
|
|
128
|
-
}
|
|
129
|
-
function extractModelName(primaryModel, provider) {
|
|
130
|
-
if (provider && primaryModel.startsWith(`${provider}/`)) {
|
|
131
|
-
return primaryModel.slice(provider.length + 1);
|
|
132
|
-
}
|
|
133
|
-
const slashIndex = primaryModel.indexOf('/');
|
|
134
|
-
return slashIndex >= 0 ? primaryModel.slice(slashIndex + 1) : primaryModel;
|
|
135
|
-
}
|
|
136
|
-
function pickString(value) {
|
|
137
|
-
if (typeof value !== 'string') {
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
const trimmed = value.trim();
|
|
141
|
-
return trimmed.length > 0 ? trimmed : null;
|
|
142
|
-
}
|
|
143
|
-
function humanizeProviderId(value) {
|
|
144
|
-
const knownLabels = {
|
|
145
|
-
openai: 'OpenAI',
|
|
146
|
-
anthropic: 'Anthropic',
|
|
147
|
-
openrouter: 'OpenRouter'
|
|
148
|
-
};
|
|
149
|
-
if (knownLabels[value]) {
|
|
150
|
-
return knownLabels[value];
|
|
151
|
-
}
|
|
152
|
-
return value
|
|
153
|
-
.replace(/^custom[-_]/, '')
|
|
154
|
-
.split(/[-_.]+/)
|
|
155
|
-
.filter(Boolean)
|
|
156
|
-
.map(capitalizeWord)
|
|
157
|
-
.join(' ');
|
|
158
|
-
}
|
|
159
|
-
function humanizeModelId(value) {
|
|
160
|
-
return value
|
|
161
|
-
.split(/[-_]+/)
|
|
162
|
-
.filter(Boolean)
|
|
163
|
-
.map((part) => (/^\d+(\.\d+)?$/.test(part) ? part : capitalizeWord(part)))
|
|
164
|
-
.join(' ');
|
|
165
|
-
}
|
|
166
|
-
function capitalizeWord(value) {
|
|
167
|
-
return value.length > 0 ? `${value.charAt(0).toUpperCase()}${value.slice(1)}` : value;
|
|
168
|
-
}
|
|
169
|
-
function redactSecrets(value) {
|
|
170
|
-
if (Array.isArray(value)) {
|
|
171
|
-
return value.map(redactSecrets);
|
|
172
|
-
}
|
|
173
|
-
if (!value || typeof value !== 'object') {
|
|
174
|
-
return value;
|
|
175
|
-
}
|
|
176
|
-
const result = {};
|
|
177
|
-
for (const [key, nestedValue] of Object.entries(value)) {
|
|
178
|
-
if (isSecretKey(key) && typeof nestedValue === 'string') {
|
|
179
|
-
result[key] = redactString(nestedValue);
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
result[key] = redactSecrets(nestedValue);
|
|
183
|
-
}
|
|
184
|
-
return result;
|
|
185
|
-
}
|
|
186
|
-
function isSecretKey(key) {
|
|
187
|
-
const normalized = key.toLowerCase();
|
|
188
|
-
return normalized.includes('apikey') || normalized.includes('token') || normalized.includes('secret');
|
|
189
|
-
}
|
|
190
|
-
function redactString(value) {
|
|
191
|
-
if (value.length <= 8) {
|
|
192
|
-
return '********';
|
|
193
|
-
}
|
|
194
|
-
return `${value.slice(0, 4)}***${value.slice(-4)}`;
|
|
195
|
-
}
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { readJsonFile } from '../lib/fs.js';
|
|
3
|
+
export const getModels = async (_params, context) => {
|
|
4
|
+
const configPath = path.join(context.openclawRoot, 'openclaw.json');
|
|
5
|
+
const config = await readJsonFile(configPath);
|
|
6
|
+
const agents = normalizeAgentModels(config);
|
|
7
|
+
const providers = config.models?.providers ?? {};
|
|
8
|
+
return {
|
|
9
|
+
sourceConfigFile: configPath,
|
|
10
|
+
defaults: {
|
|
11
|
+
model: normalizeModelConfig(config.agents?.defaults?.model),
|
|
12
|
+
models: config.agents?.defaults?.models ?? {}
|
|
13
|
+
},
|
|
14
|
+
agents,
|
|
15
|
+
modelOptions: buildModelOptions(config, providers, agents),
|
|
16
|
+
modelConfigMode: config.models?.mode ?? null,
|
|
17
|
+
configuredProviders: redactSecrets(providers)
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
function normalizeAgentModels(config) {
|
|
21
|
+
const items = [
|
|
22
|
+
{
|
|
23
|
+
id: 'defaults',
|
|
24
|
+
name: 'defaults',
|
|
25
|
+
model: normalizeModelConfig(config.agents?.defaults?.model)
|
|
26
|
+
}
|
|
27
|
+
];
|
|
28
|
+
const agents = Array.isArray(config.agents?.list) ? config.agents.list : [];
|
|
29
|
+
for (const agent of agents) {
|
|
30
|
+
items.push({
|
|
31
|
+
id: agent.id ?? null,
|
|
32
|
+
name: agent.name ?? agent.id ?? null,
|
|
33
|
+
model: normalizeModelConfig(agent.model)
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return items;
|
|
37
|
+
}
|
|
38
|
+
function normalizeModelConfig(modelConfig) {
|
|
39
|
+
if (!modelConfig || typeof modelConfig !== 'object' || Array.isArray(modelConfig)) {
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
const primary = pickString(modelConfig.primary);
|
|
43
|
+
const provider = pickString(modelConfig.provider);
|
|
44
|
+
const inferredProvider = primary && !provider ? inferProviderFromPrimaryModel(primary) : null;
|
|
45
|
+
return {
|
|
46
|
+
...modelConfig,
|
|
47
|
+
...(inferredProvider ? { provider: inferredProvider } : {})
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function buildModelOptions(config, providers, agents) {
|
|
51
|
+
const options = new Map();
|
|
52
|
+
addCatalogModelOptions(options, providers, config.agents?.defaults?.models);
|
|
53
|
+
if (options.size === 0) {
|
|
54
|
+
addFallbackAgentModelOptions(options, providers, agents);
|
|
55
|
+
}
|
|
56
|
+
return Array.from(options.values());
|
|
57
|
+
}
|
|
58
|
+
function addCatalogModelOptions(options, providers, catalog) {
|
|
59
|
+
if (!catalog || typeof catalog !== 'object' || Array.isArray(catalog)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
for (const [modelId, modelConfig] of Object.entries(catalog)) {
|
|
63
|
+
const provider = inferProviderFromPrimaryModel(modelId);
|
|
64
|
+
const model = extractModelName(modelId, provider);
|
|
65
|
+
const providerConfig = provider ? providers[provider] : null;
|
|
66
|
+
const providerLabel = provider
|
|
67
|
+
? (pickString(providerConfig?.label) ?? pickString(providerConfig?.name) ?? humanizeProviderId(provider))
|
|
68
|
+
: null;
|
|
69
|
+
const label = modelConfig && typeof modelConfig === 'object'
|
|
70
|
+
? (pickString(modelConfig.alias) ?? pickString(modelConfig.label) ?? pickString(modelConfig.name) ?? humanizeModelId(model))
|
|
71
|
+
: humanizeModelId(model);
|
|
72
|
+
addModelOption(options, {
|
|
73
|
+
provider,
|
|
74
|
+
providerLabel,
|
|
75
|
+
model,
|
|
76
|
+
value: modelId,
|
|
77
|
+
label
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function addFallbackAgentModelOptions(options, providers, agents) {
|
|
82
|
+
for (const agent of agents) {
|
|
83
|
+
if (!agent || typeof agent !== 'object' || Array.isArray(agent)) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const modelConfig = agent.model;
|
|
87
|
+
if (!modelConfig || typeof modelConfig !== 'object' || Array.isArray(modelConfig)) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const primary = pickString(modelConfig.primary);
|
|
91
|
+
if (!primary) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const provider = pickString(modelConfig.provider) ?? inferProviderFromPrimaryModel(primary);
|
|
95
|
+
const model = extractModelName(primary, provider);
|
|
96
|
+
const providerConfig = provider ? providers[provider] : null;
|
|
97
|
+
const providerLabel = provider
|
|
98
|
+
? (pickString(providerConfig?.label) ?? pickString(providerConfig?.name) ?? humanizeProviderId(provider))
|
|
99
|
+
: null;
|
|
100
|
+
addModelOption(options, {
|
|
101
|
+
provider,
|
|
102
|
+
providerLabel,
|
|
103
|
+
model,
|
|
104
|
+
value: primary,
|
|
105
|
+
label: humanizeModelId(model)
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function addModelOption(options, input) {
|
|
110
|
+
const value = input.value ?? (input.provider ? `${input.provider}/${input.model}` : input.model);
|
|
111
|
+
if (options.has(value)) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
options.set(value, {
|
|
115
|
+
label: input.label,
|
|
116
|
+
value,
|
|
117
|
+
provider: input.provider,
|
|
118
|
+
providerLabel: input.providerLabel,
|
|
119
|
+
model: input.model
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function inferProviderFromPrimaryModel(primaryModel) {
|
|
123
|
+
const slashIndex = primaryModel.indexOf('/');
|
|
124
|
+
if (slashIndex <= 0) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
return primaryModel.slice(0, slashIndex);
|
|
128
|
+
}
|
|
129
|
+
function extractModelName(primaryModel, provider) {
|
|
130
|
+
if (provider && primaryModel.startsWith(`${provider}/`)) {
|
|
131
|
+
return primaryModel.slice(provider.length + 1);
|
|
132
|
+
}
|
|
133
|
+
const slashIndex = primaryModel.indexOf('/');
|
|
134
|
+
return slashIndex >= 0 ? primaryModel.slice(slashIndex + 1) : primaryModel;
|
|
135
|
+
}
|
|
136
|
+
function pickString(value) {
|
|
137
|
+
if (typeof value !== 'string') {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
const trimmed = value.trim();
|
|
141
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
142
|
+
}
|
|
143
|
+
function humanizeProviderId(value) {
|
|
144
|
+
const knownLabels = {
|
|
145
|
+
openai: 'OpenAI',
|
|
146
|
+
anthropic: 'Anthropic',
|
|
147
|
+
openrouter: 'OpenRouter'
|
|
148
|
+
};
|
|
149
|
+
if (knownLabels[value]) {
|
|
150
|
+
return knownLabels[value];
|
|
151
|
+
}
|
|
152
|
+
return value
|
|
153
|
+
.replace(/^custom[-_]/, '')
|
|
154
|
+
.split(/[-_.]+/)
|
|
155
|
+
.filter(Boolean)
|
|
156
|
+
.map(capitalizeWord)
|
|
157
|
+
.join(' ');
|
|
158
|
+
}
|
|
159
|
+
function humanizeModelId(value) {
|
|
160
|
+
return value
|
|
161
|
+
.split(/[-_]+/)
|
|
162
|
+
.filter(Boolean)
|
|
163
|
+
.map((part) => (/^\d+(\.\d+)?$/.test(part) ? part : capitalizeWord(part)))
|
|
164
|
+
.join(' ');
|
|
165
|
+
}
|
|
166
|
+
function capitalizeWord(value) {
|
|
167
|
+
return value.length > 0 ? `${value.charAt(0).toUpperCase()}${value.slice(1)}` : value;
|
|
168
|
+
}
|
|
169
|
+
function redactSecrets(value) {
|
|
170
|
+
if (Array.isArray(value)) {
|
|
171
|
+
return value.map(redactSecrets);
|
|
172
|
+
}
|
|
173
|
+
if (!value || typeof value !== 'object') {
|
|
174
|
+
return value;
|
|
175
|
+
}
|
|
176
|
+
const result = {};
|
|
177
|
+
for (const [key, nestedValue] of Object.entries(value)) {
|
|
178
|
+
if (isSecretKey(key) && typeof nestedValue === 'string') {
|
|
179
|
+
result[key] = redactString(nestedValue);
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
result[key] = redactSecrets(nestedValue);
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
function isSecretKey(key) {
|
|
187
|
+
const normalized = key.toLowerCase();
|
|
188
|
+
return normalized.includes('apikey') || normalized.includes('token') || normalized.includes('secret');
|
|
189
|
+
}
|
|
190
|
+
function redactString(value) {
|
|
191
|
+
if (value.length <= 8) {
|
|
192
|
+
return '********';
|
|
193
|
+
}
|
|
194
|
+
return `${value.slice(0, 4)}***${value.slice(-4)}`;
|
|
195
|
+
}
|