doukui 0.8.0 → 0.9.0
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/README.en.md +85 -18
- package/README.md +8 -8
- package/bin/commands/help.js +2 -0
- package/bin/commands/plan-lint.js +105 -0
- package/bin/commands/verify.js +263 -0
- package/bin/doukui.js +2 -0
- package/package.json +1 -1
- package/plugins/core/hook-session-start/index.js +1 -1
- package/plugins/core/hook-skill-gate/index.js +64 -15
- package/plugins/core/hook-skill-gate/plugin.json +1 -1
- package/plugins/core/skill-agent-dispatcher/cleanup-reference.md +7 -28
- package/plugins/core/skill-agent-dispatcher/monitoring-reference.md +5 -177
- package/plugins/core/skill-agent-dispatcher/plugin.json +1 -1
- package/plugins/core/skill-agent-dispatcher/recovery-reference.md +99 -58
- package/plugins/core/skill-agent-dispatcher/roles-reference.md +9 -22
- package/plugins/core/skill-agent-dispatcher/skill.md +112 -524
- package/plugins/core/skill-agentic-loop/mirror-rules.md +15 -3
- package/plugins/core/skill-agentic-loop/plugin.json +1 -1
- package/plugins/core/skill-agentic-loop/skill.md +123 -324
- package/plugins/core/skill-batch-task-creator/plugin.json +1 -1
- package/plugins/core/skill-checklist/skill.md +15 -141
- package/plugins/core/skill-completion-report/plugin.json +1 -1
- package/plugins/core/skill-doukui-plan/plugin.json +1 -1
- package/plugins/core/skill-doukui-plan/skill.md +22 -22
- package/plugins/core/skill-experience-logger/plugin.json +1 -1
- package/plugins/core/skill-human-checkpoint/skill.md +1 -0
- package/plugins/core/skill-split-work-package/plugin.json +1 -1
- package/plugins/core/skill-task-creator/plugin.json +1 -1
- package/plugins/core/skill-task-creator/skill.md +1 -139
- package/plugins/core/skill-workflow-orchestrator/plugin.json +1 -1
- package/plugins/plugin-registry.json +0 -36
- package/plugins/runtime/harness-build.js +5 -5
- package/plugins/runtime/plan-reader.js +21 -3
- package/plugins/runtime/resolve-plugin-path.js +2 -2
- package/plugins/contracts/capabilities.js +0 -268
- package/plugins/core/provider-memory-store/index.js +0 -510
- package/plugins/core/provider-memory-store/plugin.json +0 -9
- package/plugins/core/provider-state-store/index.js +0 -244
- package/plugins/core/provider-state-store/plugin.json +0 -9
- package/plugins/core/provider-watchdog/assets/daemon-config.template.json +0 -32
- package/plugins/core/provider-watchdog/assets/lib/watchdog-multi-window.js +0 -676
- package/plugins/core/provider-watchdog/assets/watchdog.js +0 -754
- package/plugins/core/provider-watchdog/index.js +0 -151
- package/plugins/core/provider-watchdog/plugin.json +0 -13
- package/plugins/core/skill-agent-dispatcher/daemon-helpers-reference.md +0 -249
- package/plugins/core/skill-watchdog-manager/plugin.json +0 -10
- package/plugins/core/skill-watchdog-manager/skill.md +0 -143
- package/plugins/core/validator-doc-sync/index.js +0 -248
- package/plugins/core/validator-doc-sync/plugin.json +0 -12
- package/plugins/core/validator-work-package/index.js +0 -300
- package/plugins/core/validator-work-package/plugin.json +0 -12
- package/plugins/runtime/audit-logger.js +0 -311
- package/plugins/runtime/build-cli.js +0 -89
- package/plugins/runtime/event-bus.js +0 -207
- package/plugins/runtime/hook-dispatcher.js +0 -315
- package/plugins/runtime/plugin-loader.js +0 -798
- package/plugins/runtime/plugin-trust.js +0 -182
- package/plugins/runtime/sandbox-context.js +0 -235
- package/plugins/runtime/sandbox-manager.js +0 -609
- package/plugins/runtime/sandbox-worker.js +0 -215
- package/plugins/runtime/text-tokenize.js +0 -24
- package/plugins/runtime/validator-pipeline.js +0 -475
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// ---------------------------------------------------------------------------
|
|
4
|
-
// Plugin Trust(WP-D8 sandbox 轻量强制化)
|
|
5
|
-
// ---------------------------------------------------------------------------
|
|
6
|
-
// 背景见 docs/design/sandbox-threat-model.md:真隔离不存在(main-process
|
|
7
|
-
// require 全权限),capabilities 声明此前是纯装饰。本模块把「声明」升级为
|
|
8
|
-
// 「可检查声明」+「知情记录」,不提供假隔离:
|
|
9
|
-
//
|
|
10
|
-
// 1. capabilities 扫描:加载前 grep 插件 index.js 的危险 require
|
|
11
|
-
// (child_process / fs / net / http / worker_threads),与 plugin.json
|
|
12
|
-
// capabilities 声明比对——声明 forbidden 却出现对应 require → violation
|
|
13
|
-
// (高亮警告;无法真正阻止 require,但把「声明与行为不符」显式化)
|
|
14
|
-
// 2. 信任记录:首次加载的第三方插件记入 {stateDir}/trusted-plugins.json
|
|
15
|
-
// (name + sha1(index.js)),重复加载降为一行提示(不刷屏)
|
|
16
|
-
// 3. 严格模式:DOUKUI_STRICT_PLUGINS=1 时,未在信任记录中的第三方插件
|
|
17
|
-
// 直接拒绝加载(显式 opt-in 的强约束,供安全敏感环境使用)
|
|
18
|
-
//
|
|
19
|
-
// 边界(诚实声明):源码扫描可被动态 require / 混淆绕过——它是「知情辅助」
|
|
20
|
-
// 而非安全边界。真正的隔离仍不可行(见 threat model)。
|
|
21
|
-
// ---------------------------------------------------------------------------
|
|
22
|
-
|
|
23
|
-
var fs = require('fs');
|
|
24
|
-
var path = require('path');
|
|
25
|
-
var crypto = require('crypto');
|
|
26
|
-
|
|
27
|
-
// 危险模块 → capabilities 键映射(声明 forbidden/deny 却 require → violation)
|
|
28
|
-
var DANGEROUS_REQUIRES = [
|
|
29
|
-
{ re: /require\s*\(\s*['"]child_process['"]\s*\)/g, cap: 'child_process', label: 'child_process' },
|
|
30
|
-
{ re: /require\s*\(\s*['"]fs['"]\s*\)/g, cap: 'filesystem', label: 'fs' },
|
|
31
|
-
{ re: /require\s*\(\s*['"](net|dgram|tls)['"]\s*\)/g, cap: 'network', label: 'net/tls/dgram' },
|
|
32
|
-
{ re: /require\s*\(\s*['"](http|https|http2)['"]\s*\)/g, cap: 'network', label: 'http/https' },
|
|
33
|
-
{ re: /require\s*\(\s*['"]worker_threads['"]\s*\)/g, cap: 'worker_threads', label: 'worker_threads' },
|
|
34
|
-
{ re: /require\s*\(\s*['"]process['"]\s*\)|global\.process(?!\w)/g, cap: 'process_env', label: 'process' },
|
|
35
|
-
];
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* 扫描插件入口源码的危险 require,与 capabilities 声明比对。
|
|
39
|
-
* @param {string} indexJsPath 插件 index.js 绝对路径
|
|
40
|
-
* @param {object|null} pluginJson 插件清单(capabilities 段可省略)
|
|
41
|
-
* @returns {{ violations: Array<{module:string,cap:string,declared:string}>, hash: string }}
|
|
42
|
-
* violations 空 = 声明与行为一致(或无声明,只报 hash)
|
|
43
|
-
*/
|
|
44
|
-
function scanCapabilities(indexJsPath, pluginJson) {
|
|
45
|
-
var src = '';
|
|
46
|
-
try {
|
|
47
|
-
src = fs.readFileSync(indexJsPath, 'utf8');
|
|
48
|
-
} catch (_e) {
|
|
49
|
-
return { violations: [], hash: '' };
|
|
50
|
-
}
|
|
51
|
-
var hash = crypto.createHash('sha1').update(src, 'utf8').digest('hex');
|
|
52
|
-
var caps = (pluginJson && pluginJson.capabilities) || {};
|
|
53
|
-
var violations = [];
|
|
54
|
-
for (var i = 0; i < DANGEROUS_REQUIRES.length; i++) {
|
|
55
|
-
var d = DANGEROUS_REQUIRES[i];
|
|
56
|
-
var re = new RegExp(d.re.source, 'g'); // 重置 lastIndex
|
|
57
|
-
var hits = 0;
|
|
58
|
-
var m;
|
|
59
|
-
while ((m = re.exec(src)) !== null) { hits++; if (hits > 0) break; }
|
|
60
|
-
if (hits === 0) continue;
|
|
61
|
-
var declared = caps[d.cap];
|
|
62
|
-
var declaredStr = (declared === undefined || declared === null) ? '(未声明)' : String(declared);
|
|
63
|
-
// declared 为 forbidden/deny/never/false 之一 → 声明与行为不符
|
|
64
|
-
var forbiddenLike = ['forbidden', 'deny', 'denied', 'never', 'false'].indexOf(
|
|
65
|
-
String(declared).toLowerCase()) !== -1;
|
|
66
|
-
if (forbiddenLike) {
|
|
67
|
-
violations.push({ module: d.label, cap: d.cap, declared: declaredStr });
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return { violations: violations, hash: hash };
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function trustFilePath(stateDir) {
|
|
74
|
-
return path.join(stateDir, 'trusted-plugins.json');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* 读取信任记录。
|
|
79
|
-
* @param {string} stateDir 项目 state 目录(.doukui-state 或 .doukui)
|
|
80
|
-
* @returns {Object<string, { hash: string, trustedAt: string }>}
|
|
81
|
-
*/
|
|
82
|
-
function readTrust(stateDir) {
|
|
83
|
-
try {
|
|
84
|
-
var raw = JSON.parse(fs.readFileSync(trustFilePath(stateDir), 'utf8'));
|
|
85
|
-
return (raw && typeof raw.plugins === 'object' && raw.plugins) || {};
|
|
86
|
-
} catch (_e) {
|
|
87
|
-
return {};
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* 记录信任(首次知情加载后写入;幂等)。
|
|
93
|
-
* @param {string} stateDir
|
|
94
|
-
* @param {string} pluginName
|
|
95
|
-
* @param {string} indexHash scanCapabilities 的 hash
|
|
96
|
-
* @returns {boolean} 是否实际写入
|
|
97
|
-
*/
|
|
98
|
-
function recordTrust(stateDir, pluginName, indexHash) {
|
|
99
|
-
var file = trustFilePath(stateDir);
|
|
100
|
-
var data;
|
|
101
|
-
try {
|
|
102
|
-
data = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
103
|
-
if (!data || typeof data.plugins !== 'object') data = { plugins: {} };
|
|
104
|
-
} catch (_e) {
|
|
105
|
-
data = { plugins: {} };
|
|
106
|
-
}
|
|
107
|
-
if (data.plugins[pluginName] && data.plugins[pluginName].hash === indexHash) {
|
|
108
|
-
return false; // 已记录且内容未变
|
|
109
|
-
}
|
|
110
|
-
data.plugins[pluginName] = { hash: indexHash, trustedAt: new Date().toISOString() };
|
|
111
|
-
try {
|
|
112
|
-
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
113
|
-
fs.writeFileSync(file, JSON.stringify(data, null, 2), 'utf8');
|
|
114
|
-
return true;
|
|
115
|
-
} catch (_e) {
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* 加载门禁综合评估。
|
|
122
|
-
*
|
|
123
|
-
* 语义(WP-D8 双跑验证后的裁决):**信任记录只服务两件事——strict 模式的
|
|
124
|
-
* 放行/拒绝判定 + 审计痕迹**。非 strict(常规)模式下,第三方插件每次加载
|
|
125
|
-
* 都必须发 warn(S3 精神:外部代码跑在主进程,这一事实本身就该始终可见,
|
|
126
|
-
* 不能被「曾经信任过」静默掉——信任记录降噪会让披露吞没)。
|
|
127
|
-
*
|
|
128
|
-
* @param {object} opts
|
|
129
|
-
* @param {string} opts.pluginName
|
|
130
|
-
* @param {{violations:Array,hash:string}} opts.scan scanCapabilities 产物
|
|
131
|
-
* @param {string} opts.stateDir
|
|
132
|
-
* @param {boolean} [opts.strict] DOUKUI_STRICT_PLUGINS=1
|
|
133
|
-
* @returns {{ allowed: boolean, firstTime: boolean, messages: string[] }}
|
|
134
|
-
*/
|
|
135
|
-
function evaluateLoad(opts) {
|
|
136
|
-
opts = opts || {};
|
|
137
|
-
var messages = [];
|
|
138
|
-
var trust = readTrust(opts.stateDir);
|
|
139
|
-
var known = trust[opts.pluginName];
|
|
140
|
-
var hashUnchanged = !!(known && known.hash === opts.scan.hash);
|
|
141
|
-
var firstTime = !known;
|
|
142
|
-
|
|
143
|
-
if (opts.scan.violations.length > 0) {
|
|
144
|
-
for (var i = 0; i < opts.scan.violations.length; i++) {
|
|
145
|
-
var v = opts.scan.violations[i];
|
|
146
|
-
messages.push('⚠ CAPABILITY VIOLATION: plugin "' + opts.pluginName +
|
|
147
|
-
'" declares ' + v.cap + '=' + v.declared + ' but requires ' + v.module);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
if (!hashUnchanged) {
|
|
151
|
-
// 首次加载 或 代码较上次信任记录已变化 → 完整披露
|
|
152
|
-
messages.push('Loading third-party plugin "' + opts.pluginName +
|
|
153
|
-
'" — the sandbox is decorative and is NOT enforced; this plugin runs with full ' +
|
|
154
|
-
'main-process privileges.' + (firstTime
|
|
155
|
-
? ' Recorded to ' + trustFilePath(opts.stateDir) + '.'
|
|
156
|
-
: ' Code changed since last trust record.') +
|
|
157
|
-
' (see docs/design/sandbox-threat-model.md)');
|
|
158
|
-
} else {
|
|
159
|
-
// 已信任且未变:常规模式保持一行披露(不静默——S3 精神)
|
|
160
|
-
messages.push('Loading trusted third-party plugin "' + opts.pluginName +
|
|
161
|
-
'" (hash unchanged) — the sandbox is decorative and is NOT enforced; full main-process privileges');
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
var strict = opts.strict === true;
|
|
165
|
-
var allowed = true;
|
|
166
|
-
if (strict && (firstTime || !hashUnchanged)) {
|
|
167
|
-
allowed = false;
|
|
168
|
-
messages.push('STRICT MODE: plugin "' + opts.pluginName +
|
|
169
|
-
'" is not (or no longer) in the trust record. Load it once with strict mode off ' +
|
|
170
|
-
'(or remove DOUKUI_STRICT_PLUGINS=1) to record trust.');
|
|
171
|
-
}
|
|
172
|
-
return { allowed: allowed, firstTime: firstTime, messages: messages };
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
module.exports = {
|
|
176
|
-
scanCapabilities: scanCapabilities,
|
|
177
|
-
readTrust: readTrust,
|
|
178
|
-
recordTrust: recordTrust,
|
|
179
|
-
evaluateLoad: evaluateLoad,
|
|
180
|
-
trustFilePath: trustFilePath,
|
|
181
|
-
_DANGEROUS_REQUIRES: DANGEROUS_REQUIRES,
|
|
182
|
-
};
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SandboxContext - Standalone RPC proxy context factory
|
|
3
|
-
*
|
|
4
|
-
* Provides two utilities:
|
|
5
|
-
* 1. createSandboxProxy() - creates a PluginContext-like proxy object that
|
|
6
|
-
* forwards method calls through a message port (used inside Worker Threads)
|
|
7
|
-
* 2. createMainThreadBridge() - creates a message handler for the main thread
|
|
8
|
-
* side that dispatches RPC calls to real services
|
|
9
|
-
*
|
|
10
|
-
* This module complements the inline SandboxContext in sandbox-worker.js by
|
|
11
|
-
* providing a testable factory that can be used outside of Worker Threads.
|
|
12
|
-
*
|
|
13
|
-
* @module sandbox-context
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
'use strict';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Create a sandbox proxy object that mimics PluginContext interface.
|
|
20
|
-
* All method calls are forwarded as RPC messages through the given port.
|
|
21
|
-
*
|
|
22
|
-
* This is the main-thread side factory for creating proxy objects
|
|
23
|
-
* that can be tested without Worker Threads.
|
|
24
|
-
*
|
|
25
|
-
* @experimental
|
|
26
|
-
* @param {string} pluginName - plugin name
|
|
27
|
-
* @param {object} port - message port with postMessage/on/off methods
|
|
28
|
-
* @returns {object} proxy context object
|
|
29
|
-
*/
|
|
30
|
-
function createSandboxProxy(pluginName, port) {
|
|
31
|
-
var rpcId = 0;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Send an RPC call and wait for the response.
|
|
35
|
-
* @param {string} method
|
|
36
|
-
* @param {Array} args
|
|
37
|
-
* @returns {Promise<any>}
|
|
38
|
-
*/
|
|
39
|
-
function rpc(method, args) {
|
|
40
|
-
var id = ++rpcId;
|
|
41
|
-
|
|
42
|
-
return new Promise(function (resolve, reject) {
|
|
43
|
-
var handler = function (msg) {
|
|
44
|
-
if (msg.type === 'rpc-response' && msg.id === id) {
|
|
45
|
-
port.off('message', handler);
|
|
46
|
-
if (msg.error) {
|
|
47
|
-
reject(new Error(msg.error));
|
|
48
|
-
} else {
|
|
49
|
-
resolve(msg.result);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
port.on('message', handler);
|
|
55
|
-
port.postMessage({
|
|
56
|
-
type: 'rpc-request',
|
|
57
|
-
id: id,
|
|
58
|
-
method: method,
|
|
59
|
-
args: args,
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
pluginName: pluginName,
|
|
66
|
-
_rpc: rpc,
|
|
67
|
-
|
|
68
|
-
eventBus: {
|
|
69
|
-
emit: function (event, data) {
|
|
70
|
-
return rpc('eventBus.emit', [event, data]);
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
stateStore: {
|
|
75
|
-
get: function (key) {
|
|
76
|
-
return rpc('stateStore.get', [key]);
|
|
77
|
-
},
|
|
78
|
-
set: function (key, value) {
|
|
79
|
-
return rpc('stateStore.set', [key, value]);
|
|
80
|
-
},
|
|
81
|
-
delete: function (key) {
|
|
82
|
-
return rpc('stateStore.delete', [key]);
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
|
|
86
|
-
logger: {
|
|
87
|
-
info: function (msg) {
|
|
88
|
-
return rpc('logger.info', [msg]);
|
|
89
|
-
},
|
|
90
|
-
warn: function (msg) {
|
|
91
|
-
return rpc('logger.warn', [msg]);
|
|
92
|
-
},
|
|
93
|
-
error: function (msg) {
|
|
94
|
-
return rpc('logger.error', [msg]);
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
|
|
98
|
-
config: {
|
|
99
|
-
get: function (key) {
|
|
100
|
-
return rpc('config.get', [key]);
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
getProvider: function (name) {
|
|
105
|
-
return rpc('getProvider', [name]);
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
getPlugin: function () {
|
|
109
|
-
return undefined; // Not supported in sandbox
|
|
110
|
-
},
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Create a main-thread RPC handler that dispatches calls to real services.
|
|
116
|
-
*
|
|
117
|
-
* @experimental
|
|
118
|
-
* @param {object} services - { eventBus, stateStore, logger, configManager, getProvider }
|
|
119
|
-
* @param {object} options
|
|
120
|
-
* @param {Function} [options.onRpc] - callback for each RPC call (for testing/auditing)
|
|
121
|
-
* @returns {Function} message handler function (to attach to worker/port 'message' event)
|
|
122
|
-
*/
|
|
123
|
-
function createMainThreadBridge(services, options) {
|
|
124
|
-
options = options || {};
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Message handler for RPC dispatch.
|
|
128
|
-
*
|
|
129
|
-
* @param {object} msg - RPC request message
|
|
130
|
-
* @param {object} [respondTo] - object with postMessage method (e.g. Worker or test port)
|
|
131
|
-
*/
|
|
132
|
-
return function handleRpcMessage(msg, respondTo) {
|
|
133
|
-
if (!msg || msg.type !== 'rpc-request') return;
|
|
134
|
-
|
|
135
|
-
var id = msg.id;
|
|
136
|
-
var method = msg.method;
|
|
137
|
-
var args = msg.args || [];
|
|
138
|
-
|
|
139
|
-
// Notify callback
|
|
140
|
-
if (options.onRpc) {
|
|
141
|
-
options.onRpc(method, args);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// Execute the method
|
|
145
|
-
try {
|
|
146
|
-
var result = callService(services, method, args);
|
|
147
|
-
|
|
148
|
-
if (result && typeof result.then === 'function') {
|
|
149
|
-
result.then(function (resolved) {
|
|
150
|
-
sendResponse(respondTo, id, resolved, null);
|
|
151
|
-
}).catch(function (err) {
|
|
152
|
-
sendResponse(respondTo, id, null, err.message);
|
|
153
|
-
});
|
|
154
|
-
} else {
|
|
155
|
-
sendResponse(respondTo, id, result, null);
|
|
156
|
-
}
|
|
157
|
-
} catch (err) {
|
|
158
|
-
sendResponse(respondTo, id, null, err.message);
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Call a service method by name.
|
|
165
|
-
*
|
|
166
|
-
* @internal
|
|
167
|
-
* @param {object} services
|
|
168
|
-
* @param {string} method
|
|
169
|
-
* @param {Array} args
|
|
170
|
-
* @returns {*}
|
|
171
|
-
*/
|
|
172
|
-
function callService(services, method, args) {
|
|
173
|
-
// Known methods: if service is available, call it; if not, return undefined
|
|
174
|
-
if (method === 'eventBus.emit') {
|
|
175
|
-
return services.eventBus ? services.eventBus.emit(args[0], args[1]) : undefined;
|
|
176
|
-
}
|
|
177
|
-
if (method === 'stateStore.get') {
|
|
178
|
-
return services.stateStore ? services.stateStore.get(args[0]) : undefined;
|
|
179
|
-
}
|
|
180
|
-
if (method === 'stateStore.set') {
|
|
181
|
-
return services.stateStore ? services.stateStore.set(args[0], args[1]) : undefined;
|
|
182
|
-
}
|
|
183
|
-
if (method === 'stateStore.delete') {
|
|
184
|
-
return services.stateStore ? services.stateStore.delete(args[0]) : undefined;
|
|
185
|
-
}
|
|
186
|
-
if (method === 'logger.info') {
|
|
187
|
-
return services.logger ? services.logger.info(args[0]) : undefined;
|
|
188
|
-
}
|
|
189
|
-
if (method === 'logger.warn') {
|
|
190
|
-
return services.logger ? services.logger.warn(args[0]) : undefined;
|
|
191
|
-
}
|
|
192
|
-
if (method === 'logger.error') {
|
|
193
|
-
return services.logger ? services.logger.error(args[0]) : undefined;
|
|
194
|
-
}
|
|
195
|
-
if (method === 'config.get') {
|
|
196
|
-
return services.configManager ? services.configManager.get(args[0]) : undefined;
|
|
197
|
-
}
|
|
198
|
-
if (method === 'getProvider') {
|
|
199
|
-
return services.getProvider ? services.getProvider(args[0]) : undefined;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
throw new Error('Unknown RPC method: ' + method);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Send an RPC response.
|
|
207
|
-
*
|
|
208
|
-
* @internal
|
|
209
|
-
* @param {object|null} respondTo - object with postMessage method
|
|
210
|
-
* @param {number} id - RPC call ID
|
|
211
|
-
* @param {*} result - result value
|
|
212
|
-
* @param {string|null} error - error message
|
|
213
|
-
*/
|
|
214
|
-
function sendResponse(respondTo, id, result, error) {
|
|
215
|
-
if (!respondTo) return;
|
|
216
|
-
|
|
217
|
-
var response = {
|
|
218
|
-
type: 'rpc-response',
|
|
219
|
-
id: id,
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
if (error) {
|
|
223
|
-
response.error = error;
|
|
224
|
-
} else {
|
|
225
|
-
response.result = result;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
respondTo.postMessage(response);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
module.exports = {
|
|
232
|
-
createSandboxProxy: createSandboxProxy,
|
|
233
|
-
createMainThreadBridge: createMainThreadBridge,
|
|
234
|
-
callService: callService,
|
|
235
|
-
};
|