49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
const fields = {
|
|
prompt: ["message", "images", "streamingBehavior"],
|
|
steer: ["message", "images"],
|
|
follow_up: ["message", "images"],
|
|
abort: [],
|
|
new_session: ["parentSession"],
|
|
get_state: [],
|
|
get_messages: [],
|
|
set_model: ["provider", "modelId"],
|
|
cycle_model: [],
|
|
get_available_models: [],
|
|
set_thinking_level: ["level"],
|
|
cycle_thinking_level: [],
|
|
set_steering_mode: ["mode"],
|
|
set_follow_up_mode: ["mode"],
|
|
compact: ["customInstructions"],
|
|
set_auto_compaction: ["enabled"],
|
|
set_auto_retry: ["enabled"],
|
|
abort_retry: [],
|
|
bash: ["command"],
|
|
abort_bash: [],
|
|
get_session_stats: [],
|
|
export_html: ["outputPath"],
|
|
switch_session: ["sessionPath"],
|
|
fork: ["entryId"],
|
|
clone: [],
|
|
get_fork_messages: [],
|
|
get_entries: ["since"],
|
|
get_tree: [],
|
|
get_last_assistant_text: [],
|
|
set_session_name: ["name"],
|
|
get_commands: [],
|
|
};
|
|
|
|
export const PI_RPC_COMMANDS = Object.freeze(Object.keys(fields));
|
|
|
|
export function validatePiRpcCommand(command, input) {
|
|
if (!Object.hasOwn(fields, command))
|
|
throw new TypeError(`unsupported Pi RPC command: ${command}`);
|
|
if (input === undefined) return {};
|
|
if (input === null || typeof input !== "object" || Array.isArray(input))
|
|
throw new TypeError("Pi RPC command input must be an object");
|
|
for (const key of Object.keys(input)) {
|
|
if (!fields[command].includes(key))
|
|
throw new TypeError(`unsupported Pi RPC field: ${command}.${key}`);
|
|
}
|
|
return input;
|
|
}
|