Open History to see the last commit
1import {
2 providerSlashCommandArgumentError,
3 type ProviderSessionCommandInput,
4} from "@t3tools/contracts";
5
6/** Recognized utilities never fall through to an agent prompt when arguments are invalid. */
7export function parsePiSessionCommand(
8 text: string,
9): Omit<ProviderSessionCommandInput, "threadId"> | { readonly error: string } | null {
10 const trimmed = text.trim();
11 const noArgs = /^\/(copy|share)(?:\s+([\s\S]*))?$/.exec(trimmed);
12 if (noArgs) {
13 const command = noArgs[1] === "copy" ? "copy" : "share";
14 const error = providerSlashCommandArgumentError(
15 { name: command, argumentMode: "none" },
16 noArgs[2] ?? "",
17 );
18 return error ? { error } : { command };
19 }
20 const match = /^\/export(?:\s+([\s\S]*))?$/.exec(trimmed);
21 if (!match) return null;
22 if (/[\r\n]/.test(trimmed)) return { error: "/export accepts a path on a single line." };
23 const outputPath = match[1]?.trim();
24 return { command: "export", ...(outputPath ? { outputPath } : {}) };
25}