rol-websocket-channel 1.6.2 → 1.6.4
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.js +56 -1
- package/dist/message-handler.js +13 -1
- package/dist/src/admin/methods/admin.js +2 -4
- package/dist/src/admin/methods/admin.test.js +5 -8
- package/dist/src/admin/methods/mem9.js +30 -9
- package/dist/src/admin/methods/models-extended.js +10 -4
- package/index.ts +69 -1
- package/message-handler.ts +16 -0
- package/package.json +1 -1
- package/src/admin/methods/admin.test.ts +7 -19
- package/src/admin/methods/admin.ts +2 -4
- package/src/admin/methods/mem9.ts +32 -9
- package/src/admin/methods/models-extended.ts +20 -5
- package/test/admin/methods/models-extended.test.ts +49 -0
- package/test/custom-message-update-ack.test.ts +77 -0
- package/test/message-handler-artifacts.test.ts +11 -0
- package/MQTT-API System.md +0 -2195
- package/MQTT-API/347/211/210/346/234/254/346/237/245/347/234/213.md +0 -2191
- package/SDK-CHANNEL-TODO.md +0 -6
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import test from 'node:test';
|
|
6
|
+
|
|
7
|
+
import { updateModels } from '../../../src/admin/methods/models-extended.js';
|
|
8
|
+
import { JsonRpcException, JSON_RPC_ERRORS } from '../../../src/admin/jsonrpc.js';
|
|
9
|
+
import type { MethodContext } from '../../../src/admin/types.js';
|
|
10
|
+
|
|
11
|
+
test('updateModels rejects primaryModel values outside the allowed catalog', async () => {
|
|
12
|
+
const context = await createMethodContext();
|
|
13
|
+
await fs.writeFile(path.join(context.openclawRoot, 'openclaw.json'), JSON.stringify({
|
|
14
|
+
agents: {
|
|
15
|
+
defaults: {
|
|
16
|
+
model: {
|
|
17
|
+
primary: 'openai/gpt-5.4-mini'
|
|
18
|
+
},
|
|
19
|
+
models: {
|
|
20
|
+
'openai/gpt-5.4-mini': {
|
|
21
|
+
label: 'GPT-5.4 Mini'
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}, null, 2));
|
|
27
|
+
|
|
28
|
+
await assert.rejects(
|
|
29
|
+
updateModels({ primaryModel: 'openai/not-allowed' }, context),
|
|
30
|
+
(error: unknown) => {
|
|
31
|
+
assert.ok(error instanceof JsonRpcException);
|
|
32
|
+
assert.equal(error.code, JSON_RPC_ERRORS.invalidParams);
|
|
33
|
+
assert.equal(error.message, 'model is not in allowed model options');
|
|
34
|
+
assert.deepEqual(error.data, { code: 'MODEL_NOT_ALLOWED' });
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
async function createMethodContext(): Promise<MethodContext> {
|
|
41
|
+
const projectRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'models-extended-test-'));
|
|
42
|
+
const openclawRoot = path.join(projectRoot, '.openclaw');
|
|
43
|
+
await fs.mkdir(openclawRoot, { recursive: true });
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
projectRoot,
|
|
47
|
+
openclawRoot
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
|
|
4
|
+
import { handleCustomMessageType } from '../index.js';
|
|
5
|
+
import { messageHandler } from '../message-handler.js';
|
|
6
|
+
import {
|
|
7
|
+
_setMqttConnectFn,
|
|
8
|
+
closeGlobalConnection,
|
|
9
|
+
createGlobalMqttConnection
|
|
10
|
+
} from '../src/mqtt/connection-manager.js';
|
|
11
|
+
|
|
12
|
+
test('openclawUpdate publishes an immediate running response before the command finishes', async () => {
|
|
13
|
+
const published: Array<{ topic: string; message: string }> = [];
|
|
14
|
+
const originalOpenclawUpdate = (messageHandler as any).openclawUpdate;
|
|
15
|
+
let finish!: () => void;
|
|
16
|
+
const commandFinished = new Promise<void>((resolve) => {
|
|
17
|
+
finish = resolve;
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const fakeClient = {
|
|
21
|
+
connected: true,
|
|
22
|
+
on() {},
|
|
23
|
+
subscribe() {},
|
|
24
|
+
end() {},
|
|
25
|
+
publish(topic: string, message: string) {
|
|
26
|
+
published.push({ topic, message });
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
_setMqttConnectFn(() => fakeClient as any);
|
|
31
|
+
await createGlobalMqttConnection('mqtt://test', 'announcement/user/agent/#', {});
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
(messageHandler as any).openclawUpdate = async () => {
|
|
35
|
+
await commandFinished;
|
|
36
|
+
return { ok: true, result: { ok: true, action: 'openclawUpdate' } };
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const task = handleCustomMessageType(
|
|
40
|
+
'openclawUpdate',
|
|
41
|
+
{ source_type: 'device' },
|
|
42
|
+
'trace-update-001',
|
|
43
|
+
'default',
|
|
44
|
+
'announcement/user/agent/#'
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
48
|
+
|
|
49
|
+
assert.equal(published.length, 1);
|
|
50
|
+
const first = JSON.parse(published[0]!.message);
|
|
51
|
+
assert.equal(published[0]!.topic, 'announcement/user/agent/device');
|
|
52
|
+
assert.equal(first.trace_id, 'trace-update-001');
|
|
53
|
+
assert.equal(first.success, true);
|
|
54
|
+
assert.equal(first.data.status, 'running');
|
|
55
|
+
|
|
56
|
+
await task;
|
|
57
|
+
finish();
|
|
58
|
+
await waitFor(() => published.length === 2);
|
|
59
|
+
|
|
60
|
+
assert.equal(published.length, 2);
|
|
61
|
+
const final = JSON.parse(published[1]!.message);
|
|
62
|
+
assert.equal(final.trace_id, 'trace-update-001');
|
|
63
|
+
assert.equal(final.success, true);
|
|
64
|
+
assert.deepEqual(final.data, { ok: true, action: 'openclawUpdate' });
|
|
65
|
+
} finally {
|
|
66
|
+
(messageHandler as any).openclawUpdate = originalOpenclawUpdate;
|
|
67
|
+
closeGlobalConnection();
|
|
68
|
+
_setMqttConnectFn(null);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
async function waitFor(predicate: () => boolean): Promise<void> {
|
|
73
|
+
for (let i = 0; i < 20; i += 1) {
|
|
74
|
+
if (predicate()) return;
|
|
75
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
|
|
4
|
+
import { MessageHandler } from '../message-handler.js';
|
|
5
|
+
|
|
6
|
+
test('message handler exposes artifact convenience MQTT methods', () => {
|
|
7
|
+
const handler = new MessageHandler() as any;
|
|
8
|
+
|
|
9
|
+
assert.equal(typeof handler.artifactsFindLatest, 'function');
|
|
10
|
+
assert.equal(typeof handler.artifactsPublish, 'function');
|
|
11
|
+
});
|