chore: initial commit
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import type {Json} from '../../../../types/bot/workflow/workflow.ts';
|
||||
import type {WorkflowQueryTemplate} from '../../../../types/bot/workflow/metadata.ts';
|
||||
import {assert_json} from '../../runtime/value.ts';
|
||||
import {describe, output} from '../../metadata.ts';
|
||||
|
||||
export const config_template: WorkflowQueryTemplate = {
|
||||
name: 'info', version: '1.0.0', provider: 'info',
|
||||
i18n: describe('信息查询', '从 InfoManager 读取指定名称的信息快照,仅返回快照的 value。'),
|
||||
config: [{name: 'name', type: 'string', required: true, provider: 'info', min_length: 1,
|
||||
i18n: describe('信息名称', '选择或填写 InfoManager 中的信息名称;名称必须是非空字符串。')}],
|
||||
output: output('json', '信息值', 'InfoManager.get_info(name).value 的实际 JSON 值,类型和结构取决于所选信息;不包含快照名称或翻译元数据。'),
|
||||
};
|
||||
|
||||
export function query_info(context: {
|
||||
info_manager: {get_info(name: string): {value: unknown} | undefined} | null;
|
||||
}, args: Record<string, Json>): Json {
|
||||
if (typeof args.name !== 'string' || args.name.length === 0) {
|
||||
throw Object.assign(new Error('Info query requires a name'), {code: 'INVALID_QUERY_ARGUMENTS'});
|
||||
}
|
||||
if (!context.info_manager) {
|
||||
throw Object.assign(new Error('Info manager is unavailable'), {code: 'INFO_UNAVAILABLE'});
|
||||
}
|
||||
const snapshot = context.info_manager.get_info(args.name);
|
||||
if (!snapshot) {
|
||||
throw Object.assign(new Error(`Info was not found: ${args.name}`), {code: 'INFO_NOT_FOUND'});
|
||||
}
|
||||
assert_json(snapshot.value);
|
||||
return snapshot.value;
|
||||
}
|
||||
Reference in New Issue
Block a user