@downcity/plugins 1.0.60 → 1.0.64
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/bin/BuiltinPlugins.d.ts +15 -0
- package/bin/BuiltinPlugins.d.ts.map +1 -1
- package/bin/BuiltinPlugins.js +7 -1
- package/bin/BuiltinPlugins.js.map +1 -1
- package/bin/index.d.ts +6 -0
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +3 -0
- package/bin/index.js.map +1 -1
- package/bin/memory/Action.d.ts +15 -10
- package/bin/memory/Action.d.ts.map +1 -1
- package/bin/memory/Action.js +233 -16
- package/bin/memory/Action.js.map +1 -1
- package/bin/memory/MemoryPlugin.d.ts +10 -4
- package/bin/memory/MemoryPlugin.d.ts.map +1 -1
- package/bin/memory/MemoryPlugin.js +79 -37
- package/bin/memory/MemoryPlugin.js.map +1 -1
- package/bin/memory/runtime/Search.d.ts +1 -1
- package/bin/memory/runtime/Search.d.ts.map +1 -1
- package/bin/memory/runtime/Search.js +11 -7
- package/bin/memory/runtime/Search.js.map +1 -1
- package/bin/memory/runtime/Store.d.ts +8 -23
- package/bin/memory/runtime/Store.d.ts.map +1 -1
- package/bin/memory/runtime/Store.js +28 -43
- package/bin/memory/runtime/Store.js.map +1 -1
- package/bin/memory/runtime/SystemProvider.d.ts +4 -8
- package/bin/memory/runtime/SystemProvider.d.ts.map +1 -1
- package/bin/memory/runtime/SystemProvider.js +55 -62
- package/bin/memory/runtime/SystemProvider.js.map +1 -1
- package/bin/memory/runtime/Writer.d.ts +48 -10
- package/bin/memory/runtime/Writer.d.ts.map +1 -1
- package/bin/memory/runtime/Writer.js +197 -60
- package/bin/memory/runtime/Writer.js.map +1 -1
- package/bin/memory/types/Memory.d.ts +222 -33
- package/bin/memory/types/Memory.d.ts.map +1 -1
- package/bin/memory/types/Memory.js +4 -3
- package/bin/memory/types/Memory.js.map +1 -1
- package/bin/shell/ShellPlugin.d.ts +2 -1
- package/bin/shell/ShellPlugin.d.ts.map +1 -1
- package/bin/shell/ShellPlugin.js +41 -4
- package/bin/shell/ShellPlugin.js.map +1 -1
- package/bin/shell/ShellRuntimeTypes.d.ts +57 -3
- package/bin/shell/ShellRuntimeTypes.d.ts.map +1 -1
- package/bin/shell/runtime/ShellActionRuntime.d.ts +21 -0
- package/bin/shell/runtime/ShellActionRuntime.d.ts.map +1 -1
- package/bin/shell/runtime/ShellActionRuntime.js +142 -6
- package/bin/shell/runtime/ShellActionRuntime.js.map +1 -1
- package/bin/shell/runtime/ShellActionRuntimeSupport.d.ts +14 -5
- package/bin/shell/runtime/ShellActionRuntimeSupport.d.ts.map +1 -1
- package/bin/shell/runtime/ShellActionRuntimeSupport.js +61 -22
- package/bin/shell/runtime/ShellActionRuntimeSupport.js.map +1 -1
- package/bin/shell/runtime/ShellApprovalRuntime.d.ts +57 -0
- package/bin/shell/runtime/ShellApprovalRuntime.d.ts.map +1 -0
- package/bin/shell/runtime/ShellApprovalRuntime.js +182 -0
- package/bin/shell/runtime/ShellApprovalRuntime.js.map +1 -0
- package/bin/shell/runtime/ShellProcessEvents.js +3 -3
- package/bin/shell/runtime/ShellProcessEvents.js.map +1 -1
- package/bin/shell/types/ShellPluginOptions.d.ts +103 -0
- package/bin/shell/types/ShellPluginOptions.d.ts.map +1 -0
- package/bin/shell/types/ShellPluginOptions.js +10 -0
- package/bin/shell/types/ShellPluginOptions.js.map +1 -0
- package/bin/task/Scheduler.d.ts +8 -0
- package/bin/task/Scheduler.d.ts.map +1 -1
- package/bin/task/Scheduler.js +7 -9
- package/bin/task/Scheduler.js.map +1 -1
- package/bin/task/TaskPlugin.d.ts +18 -1
- package/bin/task/TaskPlugin.d.ts.map +1 -1
- package/bin/task/TaskPlugin.js +23 -1
- package/bin/task/TaskPlugin.js.map +1 -1
- package/bin/task/types/TaskPluginOptions.d.ts +22 -0
- package/bin/task/types/TaskPluginOptions.d.ts.map +1 -0
- package/bin/task/types/TaskPluginOptions.js +9 -0
- package/bin/task/types/TaskPluginOptions.js.map +1 -0
- package/package.json +2 -2
- package/scripts/unrestricted-sandbox-approval.test.mjs +156 -0
- package/src/BuiltinPlugins.ts +27 -1
- package/src/index.ts +35 -0
- package/src/memory/Action.ts +292 -25
- package/src/memory/MemoryPlugin.ts +82 -40
- package/src/memory/runtime/Search.ts +16 -9
- package/src/memory/runtime/Store.ts +52 -49
- package/src/memory/runtime/SystemProvider.ts +55 -69
- package/src/memory/runtime/Writer.ts +262 -81
- package/src/memory/types/Memory.ts +296 -35
- package/src/shell/ShellPlugin.ts +44 -3
- package/src/shell/ShellRuntimeTypes.ts +61 -3
- package/src/shell/runtime/ShellActionRuntime.ts +182 -9
- package/src/shell/runtime/ShellActionRuntimeSupport.ts +112 -21
- package/src/shell/runtime/ShellApprovalRuntime.ts +236 -0
- package/src/shell/runtime/ShellProcessEvents.ts +3 -3
- package/src/shell/types/ShellPluginOptions.ts +122 -0
- package/src/task/Scheduler.ts +15 -9
- package/src/task/TaskPlugin.ts +27 -1
- package/src/task/types/TaskPluginOptions.ts +22 -0
- package/bin/memory/runtime/Flush.d.ts +0 -15
- package/bin/memory/runtime/Flush.d.ts.map +0 -1
- package/bin/memory/runtime/Flush.js +0 -63
- package/bin/memory/runtime/Flush.js.map +0 -1
- package/src/memory/runtime/Flush.ts +0 -83
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TaskPlugin.js","sourceRoot":"","sources":["../../src/task/TaskPlugin.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,oDAAoD,CAAC;
|
|
1
|
+
{"version":3,"file":"TaskPlugin.js","sourceRoot":"","sources":["../../src/task/TaskPlugin.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,oDAAoD,CAAC;AAQhF,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAA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runtime,不提供 enabled 开关。
|
|
6
|
+
* - 只暴露用户能直接理解的时区配置,内部调度实现细节不进入 constructor。
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* TaskPlugin 构造参数。
|
|
10
|
+
*/
|
|
11
|
+
export interface TaskPluginOptions {
|
|
12
|
+
/**
|
|
13
|
+
* cron task 使用的 IANA 时区。
|
|
14
|
+
*
|
|
15
|
+
* 说明(中文)
|
|
16
|
+
* - 例如 `Asia/Shanghai`、`America/Los_Angeles`。
|
|
17
|
+
* - 省略时使用当前运行机器的本机时区。
|
|
18
|
+
* - `time:<ISO8601-with-timezone>` 一次性任务以 ISO 字符串自身的 offset 为准,这里的时区主要影响 cron 表达式。
|
|
19
|
+
*/
|
|
20
|
+
timezone?: string;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=TaskPluginOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TaskPluginOptions.d.ts","sourceRoot":"","sources":["../../../src/task/types/TaskPluginOptions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TaskPluginOptions.js","sourceRoot":"","sources":["../../../src/task/types/TaskPluginOptions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@downcity/plugins",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.64",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Downcity 内建 plugin 集合包",
|
|
6
6
|
"main": "./bin/index.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"node-cron": "^4.2.1",
|
|
23
23
|
"ws": "^8.21.0",
|
|
24
24
|
"zod": "^4.4.3",
|
|
25
|
-
"@downcity/agent": "^1.1.
|
|
25
|
+
"@downcity/agent": "^1.1.111"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/better-sqlite3": "^7.6.13",
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file 验证 shell unrestricted sandbox 审批运行时。
|
|
3
|
+
*
|
|
4
|
+
* 关键点(中文)
|
|
5
|
+
* - 测试编译后的 bin 输出,避免测试文件进入 package 源码导出面。
|
|
6
|
+
* - 直接驱动 shell runtime state,模拟 UI/Console 收到 approval_id 后批准或拒绝。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import test from "node:test";
|
|
10
|
+
import assert from "node:assert/strict";
|
|
11
|
+
import fs from "node:fs/promises";
|
|
12
|
+
import os from "node:os";
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
approveShellApproval,
|
|
17
|
+
closeAllShellSessions,
|
|
18
|
+
createShellPluginState,
|
|
19
|
+
denyShellApproval,
|
|
20
|
+
execShellCommand,
|
|
21
|
+
startShellSession,
|
|
22
|
+
} from "../bin/shell/runtime/ShellActionRuntime.js";
|
|
23
|
+
|
|
24
|
+
async function create_fixture() {
|
|
25
|
+
const root_path = await fs.mkdtemp(path.join(os.tmpdir(), "downcity-unrestricted-"));
|
|
26
|
+
const events = [];
|
|
27
|
+
const context = {
|
|
28
|
+
rootPath: root_path,
|
|
29
|
+
env: {},
|
|
30
|
+
config: { id: "test-agent" },
|
|
31
|
+
paths: {
|
|
32
|
+
getDowncityChannelMetaPath: () => path.join(root_path, ".downcity", "channel", "meta.json"),
|
|
33
|
+
},
|
|
34
|
+
session: {
|
|
35
|
+
get: () => ({
|
|
36
|
+
publishEvent: (event) => {
|
|
37
|
+
events.push(event);
|
|
38
|
+
},
|
|
39
|
+
}),
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
root_path,
|
|
44
|
+
events,
|
|
45
|
+
context,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function wait_for_approval(state) {
|
|
50
|
+
const started_at = Date.now();
|
|
51
|
+
while (Date.now() - started_at < 2000) {
|
|
52
|
+
const approval = Array.from(state.approvals.values())[0];
|
|
53
|
+
if (approval) return approval;
|
|
54
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
55
|
+
}
|
|
56
|
+
throw new Error("approval request was not created");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
test("shell_start unrestricted requires reason", async () => {
|
|
60
|
+
const fixture = await create_fixture();
|
|
61
|
+
const state = createShellPluginState({ defaultApprovalTimeoutMs: 500 });
|
|
62
|
+
try {
|
|
63
|
+
await assert.rejects(
|
|
64
|
+
startShellSession(state, fixture.context, {
|
|
65
|
+
cmd: "printf should-not-run",
|
|
66
|
+
cwd: fixture.root_path,
|
|
67
|
+
shell: "/bin/sh",
|
|
68
|
+
login: false,
|
|
69
|
+
sandbox: "unrestricted",
|
|
70
|
+
}),
|
|
71
|
+
/requires a non-empty reason/,
|
|
72
|
+
);
|
|
73
|
+
} finally {
|
|
74
|
+
await closeAllShellSessions(state, true);
|
|
75
|
+
await fs.rm(fixture.root_path, { recursive: true, force: true });
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("shell_start unrestricted denied returns denied tool result without execution", async () => {
|
|
80
|
+
const fixture = await create_fixture();
|
|
81
|
+
const state = createShellPluginState({
|
|
82
|
+
defaultApprovalTimeoutMs: 2000,
|
|
83
|
+
defaultInlineWaitMs: 20,
|
|
84
|
+
});
|
|
85
|
+
try {
|
|
86
|
+
const marker_path = path.join(fixture.root_path, "should-not-exist.txt");
|
|
87
|
+
const pending_result = startShellSession(state, fixture.context, {
|
|
88
|
+
cmd: `printf denied > ${JSON.stringify(marker_path)}`,
|
|
89
|
+
cwd: fixture.root_path,
|
|
90
|
+
shell: "/bin/sh",
|
|
91
|
+
login: false,
|
|
92
|
+
sandbox: "unrestricted",
|
|
93
|
+
reason: "测试拒绝 unrestricted sandbox 不会执行命令。",
|
|
94
|
+
ownerContextId: "session_test",
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const approval = await wait_for_approval(state);
|
|
98
|
+
assert.equal(approval.toolName, "shell_start");
|
|
99
|
+
assert.equal(fixture.events[0]?.type, "tool-approval-request");
|
|
100
|
+
assert.equal(fixture.events[0]?.approvalId, approval.approvalId);
|
|
101
|
+
|
|
102
|
+
assert.equal(
|
|
103
|
+
await denyShellApproval(state, fixture.context, approval.approvalId),
|
|
104
|
+
true,
|
|
105
|
+
);
|
|
106
|
+
const result = await pending_result;
|
|
107
|
+
|
|
108
|
+
assert.equal(result.shell.sandboxMode, "unrestricted");
|
|
109
|
+
assert.equal(result.shell.approvalStatus, "denied");
|
|
110
|
+
assert.equal(result.shell.status, "failed");
|
|
111
|
+
assert.match(result.chunk.output, /User denied unrestricted sandbox execution/);
|
|
112
|
+
await assert.rejects(fs.stat(marker_path), /ENOENT/);
|
|
113
|
+
assert.equal(fixture.events.at(-1)?.type, "tool-approval-result");
|
|
114
|
+
assert.equal(fixture.events.at(-1)?.decision, "denied");
|
|
115
|
+
} finally {
|
|
116
|
+
await closeAllShellSessions(state, true);
|
|
117
|
+
await fs.rm(fixture.root_path, { recursive: true, force: true });
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("shell_exec unrestricted approved executes in unrestricted sandbox", async () => {
|
|
122
|
+
const fixture = await create_fixture();
|
|
123
|
+
const state = createShellPluginState({
|
|
124
|
+
defaultApprovalTimeoutMs: 2000,
|
|
125
|
+
defaultInlineWaitMs: 20,
|
|
126
|
+
defaultExecTimeoutMs: 2000,
|
|
127
|
+
});
|
|
128
|
+
try {
|
|
129
|
+
const pending_result = execShellCommand(state, fixture.context, {
|
|
130
|
+
cmd: "printf unrestricted-ok",
|
|
131
|
+
cwd: fixture.root_path,
|
|
132
|
+
shell: "/bin/sh",
|
|
133
|
+
login: false,
|
|
134
|
+
sandbox: "unrestricted",
|
|
135
|
+
reason: "测试批准后执行 unrestricted sandbox 命令。",
|
|
136
|
+
timeoutMs: 2000,
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const approval = await wait_for_approval(state);
|
|
140
|
+
assert.equal(approval.toolName, "shell_exec");
|
|
141
|
+
assert.equal(
|
|
142
|
+
await approveShellApproval(state, fixture.context, approval.approvalId),
|
|
143
|
+
true,
|
|
144
|
+
);
|
|
145
|
+
const result = await pending_result;
|
|
146
|
+
|
|
147
|
+
assert.equal(result.shell.sandboxed, false);
|
|
148
|
+
assert.equal(result.shell.sandboxMode, "unrestricted");
|
|
149
|
+
assert.equal(result.shell.approvalStatus, "approved");
|
|
150
|
+
assert.equal(result.shell.exitCode, 0);
|
|
151
|
+
assert.equal(result.chunk.output, "unrestricted-ok");
|
|
152
|
+
} finally {
|
|
153
|
+
await closeAllShellSessions(state, true);
|
|
154
|
+
await fs.rm(fixture.root_path, { recursive: true, force: true });
|
|
155
|
+
}
|
|
156
|
+
});
|
package/src/BuiltinPlugins.ts
CHANGED
|
@@ -22,6 +22,9 @@ import { TtsPlugin } from "@/tts/Plugin.js";
|
|
|
22
22
|
import type { ImagePluginOptions } from "@/image/types/ImagePlugin.js";
|
|
23
23
|
import type { AsrPluginOptions } from "@/asr/types/AsrPlugin.js";
|
|
24
24
|
import type { TtsPluginOptions } from "@/tts/types/TtsPlugin.js";
|
|
25
|
+
import type { TaskPluginOptions } from "@/task/types/TaskPluginOptions.js";
|
|
26
|
+
import type { MemoryPluginOptions } from "@/memory/types/Memory.js";
|
|
27
|
+
import type { ShellPluginOptions } from "@/shell/types/ShellPluginOptions.js";
|
|
25
28
|
|
|
26
29
|
/**
|
|
27
30
|
* 内建 plugin class 构造器。
|
|
@@ -62,13 +65,36 @@ export interface BuiltinPluginOptions {
|
|
|
62
65
|
* 文本转语音 plugin 的 City AI 能力注入。
|
|
63
66
|
*/
|
|
64
67
|
tts?: TtsPluginOptions;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* task plugin 的定时任务运行参数。
|
|
71
|
+
*/
|
|
72
|
+
task?: TaskPluginOptions;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* memory plugin 的 LLM Wiki 能力注入。
|
|
76
|
+
*/
|
|
77
|
+
memory?: MemoryPluginOptions;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* shell plugin 的可选 runtime 参数。
|
|
81
|
+
*/
|
|
82
|
+
shell?: ShellPluginOptions;
|
|
65
83
|
}
|
|
66
84
|
|
|
67
85
|
/**
|
|
68
86
|
* 创建完整内建 plugin 实例集合。
|
|
69
87
|
*/
|
|
70
88
|
export function createBuiltinPlugins(options: BuiltinPluginOptions = {}): BasePlugin[] {
|
|
71
|
-
const plugins = BUILTIN_PLUGIN_CLASSES.map((PluginClass) =>
|
|
89
|
+
const plugins = BUILTIN_PLUGIN_CLASSES.map((PluginClass) =>
|
|
90
|
+
PluginClass === TaskPlugin
|
|
91
|
+
? new TaskPlugin(options.task)
|
|
92
|
+
: PluginClass === MemoryPlugin
|
|
93
|
+
? new MemoryPlugin(options.memory)
|
|
94
|
+
: PluginClass === ShellPlugin
|
|
95
|
+
? new ShellPlugin(options.shell)
|
|
96
|
+
: new PluginClass(),
|
|
97
|
+
);
|
|
72
98
|
if (options.image?.image_create && options.image?.image_result) {
|
|
73
99
|
plugins.push(new ImagePlugin(options.image));
|
|
74
100
|
}
|
package/src/index.ts
CHANGED
|
@@ -29,6 +29,9 @@ export { WebPlugin } from "./web/Plugin.js";
|
|
|
29
29
|
export { AsrPlugin } from "./asr/Plugin.js";
|
|
30
30
|
export { TtsPlugin } from "./tts/Plugin.js";
|
|
31
31
|
export { WorkboardPlugin } from "./workboard/Plugin.js";
|
|
32
|
+
export { TaskPlugin } from "./task/TaskPlugin.js";
|
|
33
|
+
export { MemoryPlugin } from "./memory/MemoryPlugin.js";
|
|
34
|
+
export { ShellPlugin } from "./shell/ShellPlugin.js";
|
|
32
35
|
export {
|
|
33
36
|
listChatAuthorizationRoles,
|
|
34
37
|
readChatAuthorizationConfigSync,
|
|
@@ -59,6 +62,38 @@ export type {
|
|
|
59
62
|
ChatPluginOptions,
|
|
60
63
|
} from "./chat/types/ChatPluginOptions.js";
|
|
61
64
|
export type { ContactPluginOptions } from "./contact/types/ContactPluginOptions.js";
|
|
65
|
+
export type { TaskPluginOptions } from "./task/types/TaskPluginOptions.js";
|
|
66
|
+
export type {
|
|
67
|
+
ResolvedShellPluginOptions,
|
|
68
|
+
ShellPluginOptions,
|
|
69
|
+
} from "./shell/types/ShellPluginOptions.js";
|
|
70
|
+
export type {
|
|
71
|
+
MemoryActionPayload,
|
|
72
|
+
MemoryDefaults,
|
|
73
|
+
MemoryDigestHandler,
|
|
74
|
+
MemoryDigestHandlerInput,
|
|
75
|
+
MemoryDigestHandlerOutput,
|
|
76
|
+
MemoryDigestPayload,
|
|
77
|
+
MemoryDigestResponse,
|
|
78
|
+
MemoryPluginOptions,
|
|
79
|
+
MemoryReadPayload,
|
|
80
|
+
MemoryReadResponse,
|
|
81
|
+
MemoryRememberPayload,
|
|
82
|
+
MemoryRememberResponse,
|
|
83
|
+
MemoryReviseHandler,
|
|
84
|
+
MemoryReviseHandlerInput,
|
|
85
|
+
MemoryReviseHandlerOutput,
|
|
86
|
+
MemoryRevisePayload,
|
|
87
|
+
MemoryReviseResponse,
|
|
88
|
+
MemorySearchMode,
|
|
89
|
+
MemorySearchPayload,
|
|
90
|
+
MemorySearchResponse,
|
|
91
|
+
MemorySearchResultItem,
|
|
92
|
+
MemorySourceStat,
|
|
93
|
+
MemorySourceType,
|
|
94
|
+
MemoryStatusResponse,
|
|
95
|
+
MemoryWikiPageDraft,
|
|
96
|
+
} from "./memory/types/Memory.js";
|
|
62
97
|
export type {
|
|
63
98
|
AsrPluginInput,
|
|
64
99
|
AsrPluginOptions,
|