{"version":3,"file":"commands.mjs","names":[],"sources":["../../../src/web/lib/commands.ts"],"sourcesContent":["import { t } from '@agimon-ai/po-core/web';\n\ntype Frame = Record<string, unknown>;\n\nexport interface RpcImage {\n  type: 'image';\n  data: string;\n  mimeType: string;\n}\n\nexport function promptCommand(message: string, images: RpcImage[] = []): Frame {\n  return { type: 'prompt', message, ...(images.length > 0 ? { images } : {}) };\n}\n\nexport function steerCommand(message: string, images: RpcImage[] = []): Frame {\n  return { type: 'steer', message, ...(images.length > 0 ? { images } : {}) };\n}\n\nexport function followUpCommand(message: string, images: RpcImage[] = []): Frame {\n  return { type: 'follow_up', message, ...(images.length > 0 ? { images } : {}) };\n}\n\nexport function enqueueAutomaticCommand(message: string, images: RpcImage[] = []): Frame {\n  return { type: 'enqueue_automatic', message, ...(images.length > 0 ? { images } : {}) };\n}\n\nexport function removeQueuedCommand(id: string): Frame {\n  return { type: 'remove_queued', id };\n}\n\nexport function promoteQueuedCommand(id: string, operationId?: string): Frame {\n  return { type: 'promote_queued', id, ...(operationId === undefined ? {} : { operationId }) };\n}\n\nexport function resumeQueueCommand(): Frame {\n  return { type: 'resume_queue' };\n}\n\n/** Requests in-place Pi session-tree navigation after the hub resolves the visible transcript id. */\nexport function rewindCommand(itemId: string): Frame {\n  return { type: 'rewind', itemId };\n}\n\nexport function abortCommand(operationId?: string): Frame {\n  return operationId === undefined ? { type: 'abort' } : { type: 'abort', operationId };\n}\n\nexport function clearQueueCommand(): Frame {\n  return { type: 'clear_queue' };\n}\n\nexport function getStateCommand(): Frame {\n  return { type: 'get_state' };\n}\n\nexport function getSessionStatsCommand(): Frame {\n  return { type: 'get_session_stats' };\n}\n\nexport function getCommandsCommand(): Frame {\n  return { type: 'get_commands' };\n}\n\nexport function compactCommand(customInstructions?: string): Frame {\n  return { type: 'compact', ...(customInstructions === undefined ? {} : { customInstructions }) };\n}\n\n/** Drops the model's context without a summary. The transcript stays, with a notice where the memory restarts. */\nexport function clearCommand(): Frame {\n  return { type: 'compact', clear: true };\n}\n\nconst COMPACT = 'compact';\nconst CLEAR = 'clear';\n\n/**\n * Pi's built-in slash commands that the cockpit can actually run.\n *\n * `get_commands` reports extension commands, prompt templates and skills, and\n * nothing else, so the built-ins never reach the palette on their own. Nor can\n * they be sent as prompts: `session.prompt` has no branch for them, and the\n * TUI runs them by matching the raw typed text, so a prompt-shaped `/compact`\n * arrives at the model as literal text. Each entry here therefore needs its\n * own RPC frame, which is why the list holds only what is wired below rather\n * than everything the TUI offers.\n */\n// Descriptions are getters so they translate when the palette reads them, not when this module loads.\nexport const BUILTIN_COMMANDS: ReadonlyArray<{ readonly name: string; readonly description: string }> = [\n  {\n    name: COMPACT,\n    get description() {\n      return t('webDashboard.commands.compactDescription', 'Manually compact the session context');\n    },\n  },\n  {\n    name: CLEAR,\n    get description() {\n      return t(\n        'webDashboard.commands.clearDescription',\n        'Start fresh: Po forgets the conversation so far, the transcript stays',\n      );\n    },\n  },\n];\n\n/**\n * The frame a typed built-in maps to, or undefined when the text is an\n * ordinary prompt. The argument is passed through, so `/compact keep the API\n * decisions` reaches Pi as its custom instruction.\n */\nexport function builtinCommandFrame(text: string): Frame | undefined {\n  // Split on any whitespace, not a space: the composer folds text attachments\n  // into the draft with newlines, so a space-only split reads the newline as\n  // part of the command name and silently sends the whole thing to the model.\n  const matched = /^\\/(\\S+)(?:\\s+([\\s\\S]*))?$/u.exec(text.trim());\n  // A clear takes no argument: text after it is dropped rather than sent to the model.\n  if (matched?.[1] === CLEAR) return clearCommand();\n  if (matched?.[1] !== COMPACT) return undefined;\n  const argument = (matched[2] ?? '').trim();\n  return compactCommand(argument.length > 0 ? argument : undefined);\n}\nexport function getAvailableModelsCommand(): Frame {\n  return { type: 'get_available_models' };\n}\n\nexport function getAvailableThinkingLevelsCommand(): Frame {\n  return { type: 'get_available_thinking_levels' };\n}\n\nexport function setModelCommand(provider: string, modelId: string): Frame {\n  return { type: 'set_model', provider, modelId };\n}\n\nexport function setThinkingLevelCommand(level: string): Frame {\n  return { type: 'set_thinking_level', level };\n}\n\nexport function setSessionNameCommand(name: string): Frame {\n  return { type: 'set_session_name', name };\n}\n\nexport function dialogValue(id: string, value: string): Frame {\n  return { type: 'extension_ui_response', id, value };\n}\n\nexport function dialogConfirmed(id: string, confirmed: boolean): Frame {\n  return { type: 'extension_ui_response', id, confirmed };\n}\n\nexport function dialogCancelled(id: string): Frame {\n  return { type: 'extension_ui_response', id, cancelled: true };\n}\n"],"mappings":";;AAUA,SAAgB,cAAc,SAAiB,SAAqB,CAAC,GAAU;CAC7E,OAAO;EAAE,MAAM;EAAU;EAAS,GAAI,OAAO,SAAS,IAAI,EAAE,OAAO,IAAI,CAAC;CAAG;AAC7E;AAEA,SAAgB,aAAa,SAAiB,SAAqB,CAAC,GAAU;CAC5E,OAAO;EAAE,MAAM;EAAS;EAAS,GAAI,OAAO,SAAS,IAAI,EAAE,OAAO,IAAI,CAAC;CAAG;AAC5E;AAEA,SAAgB,gBAAgB,SAAiB,SAAqB,CAAC,GAAU;CAC/E,OAAO;EAAE,MAAM;EAAa;EAAS,GAAI,OAAO,SAAS,IAAI,EAAE,OAAO,IAAI,CAAC;CAAG;AAChF;AAEA,SAAgB,wBAAwB,SAAiB,SAAqB,CAAC,GAAU;CACvF,OAAO;EAAE,MAAM;EAAqB;EAAS,GAAI,OAAO,SAAS,IAAI,EAAE,OAAO,IAAI,CAAC;CAAG;AACxF;AAEA,SAAgB,oBAAoB,IAAmB;CACrD,OAAO;EAAE,MAAM;EAAiB;CAAG;AACrC;AAEA,SAAgB,qBAAqB,IAAY,aAA6B;CAC5E,OAAO;EAAE,MAAM;EAAkB;EAAI,GAAI,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,YAAY;CAAG;AAC7F;AAEA,SAAgB,qBAA4B;CAC1C,OAAO,EAAE,MAAM,eAAe;AAChC;;AAGA,SAAgB,cAAc,QAAuB;CACnD,OAAO;EAAE,MAAM;EAAU;CAAO;AAClC;AAEA,SAAgB,aAAa,aAA6B;C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