{"askUser.function_call.ts":"import type {FunctionCallFn} from \"npm:@jixo/dev/google-aistudio\";\nimport z from \"npm:zod\";\n\nexport const name = \"askUser\";\n\nexport const description = \"当遇到歧义、需要决策或缺少关键信息时，向用户提问并等待响应。\";\n\nexport const paramsSchema = z.object({\n  question: z.string().describe(\"需要向用户提出的、清晰具体的问题。\"),\n  options: z.array(z.string()).optional().describe(\"如果提供，则向用户呈现一个选项列表，用户必须从中选择一个。\"),\n});\n\n/**\n * Uses the injected render function from the context to display a UI prompt.\n * @param args - The question and options to ask the user.\n * @param context - The context containing the `render` function.\n * @returns A promise that resolves with the user's response.\n */\nexport const functionCall: FunctionCallFn<z.infer<typeof paramsSchema>> = async (args, context) => {\n  console.log(`Asking user via UI: \"${args.question}\"`);\n\n  try {\n    const response = await context.render({\n      component: \"AskUserDialog\", // The name for the UI component\n      props: {\n        question: args.question,\n        options: args.options,\n      },\n    });\n\n    console.log(`Received user response:`, response);\n    return response;\n  } catch (error) {\n    console.error(\"Failed to get user response:\", error);\n    // Rethrow the error to let the caller know the FC failed.\n    throw error;\n  }\n};\n","logThought.function_call.ts":"import type {FunctionCallFn} from \"npm:@jixo/dev/google-aistudio\";\nimport z from \"npm:zod\";\n\nexport const name = \"logThought\";\n\nexport const description = \"用于外部化和记录AI的思考过程，并将这个过程展示给用户。\";\n\nexport const paramsSchema = z.object({\n  thought: z.string().describe(\"当前这一步的思考内容。可以是对问题的分析、一个假设、对风险的评估或一个初步想法。\"),\n  step: z.number().int().min(1).describe(\"当前思考是第几步。\"),\n  total_steps: z.number().int().min(1).describe(\"预估总共需要几步思考。\"),\n  is_conclusive: z.boolean().describe(\"设置为true表示思考过程已结束。\"),\n});\n\n/**\n * Renders the AI's thought process into the UI.\n * This is a \"fire-and-forget\" operation from the AI's perspective,\n * but we still await the render call to ensure the UI command is sent.\n * @param args - The thought content and step information.\n * @param context - The context containing the `render` function.\n * @returns A simple status object.\n */\nexport const functionCall: FunctionCallFn<z.infer<typeof paramsSchema>> = async (args, context) => {\n  console.log(`Logging thought #${args.step}/${args.total_steps} to UI:`, args.thought);\n\n  // We await the render call to ensure the message is sent before the tool returns.\n  // The UI won't send a USER_RESPONSE, so the promise will resolve once the command is sent,\n  // or reject if the connection fails.\n  await context.render({\n    component: \"LogThoughtPanel\",\n    props: args,\n  });\n\n  const result = {\n    status: \"THOUGHT_LOGGED_TO_UI\",\n    step: args.step,\n  };\n\n  return result;\n};\n","proposePlan.function_call.ts":"import type {FunctionCallFn} from \"npm:@jixo/dev/google-aistudio\";\nimport z from \"npm:zod\";\n\nexport const name = \"proposePlan\";\n\nexport const description = \"向用户提出一个高层级的行动计划以供审批。\";\n\nexport const paramsSchema = z.object({\n  plan_summary: z.string().describe(\"对整个计划的一句话总结。\"),\n  steps: z.array(z.string()).describe(\"一个有序列表，描述了计划执行的每一个具体步骤。\"),\n  estimated_tool_calls: z.array(z.string()).optional().describe(\"预估在计划批准后将会调用的主要工具列表。\"),\n});\n\n/**\n * Renders a plan to the user and awaits their approval or rejection.\n * @param args - The plan details.\n * @param context - The context containing the `render` function.\n * @returns A promise resolving with an approval status.\n */\nexport const functionCall: FunctionCallFn<z.infer<typeof paramsSchema>> = async (args, context) => {\n  console.log(\"Proposing plan to user via UI:\", args.plan_summary);\n\n  try {\n    const response = await context.render({\n      component: \"ProposePlanDialog\",\n      props: args,\n    });\n\n    if (response === true) {\n      console.log(\"Plan was approved by the user.\");\n      return {status: \"PLAN_APPROVED\"};\n    } else {\n      // This handles both explicit rejection (response === false) and other falsy values.\n      throw new Error(\"Plan was rejected by the user.\");\n    }\n  } catch (error) {\n    console.error(\"Failed to get plan approval:\", error);\n    // Re-throw the error to ensure the AI knows the tool failed.\n    throw error;\n  }\n};\n","shellCat.function_call.ts":"import {junCatLogic} from \"jsr:@jixo/jun\";\nimport z from \"npm:zod\";\n\nexport const name = \"shellCat\";\n\nexport const description = \"获取一个或多个指定pid任务的详细信息和完整的stdio日志。\";\n\nexport const paramsSchema = z.object({\n  pids: z.array(z.number().int().positive()).min(1).describe(\"要获取日志的任务PID列表。\"),\n});\n\n/**\n * 调用 @jixo/jun 的 junCatLogic 来获取任务日志。\n * @param args - 符合paramsSchema的参数\n * @returns 一个包含任务详细日志的对象\n */\nexport const functionCall = async (args: z.infer<typeof paramsSchema>) => {\n  console.log(`Executing jun cat logic for pids: ${args.pids.join(\", \")}`);\n\n  const {success, failed} = await junCatLogic(args.pids);\n\n  return {\n    status: \"SUCCESS\",\n    tasks: success,\n    failed_pids: failed,\n  };\n};\n","shellHistory.function_call.ts":"import {junHistoryLogic} from \"jsr:@jixo/jun\";\nimport z from \"npm:zod\";\n\nexport const name = \"shellHistory\";\n\nexport const description = \"列出所有由jun执行过的任务历史记录，包括已完成和正在运行的。\";\n\nexport const paramsSchema = z.object({}).describe(\"此工具没有参数。\");\n\n/**\n * 调用 @jixo/jun 的 junHistoryLogic 来获取所有任务历史。\n * @returns 一个包含所有任务历史的对象\n */\nexport const functionCall = async (_args: z.infer<typeof paramsSchema>) => {\n  console.log(`Executing jun history logic`);\n\n  const history = await junHistoryLogic();\n\n  return {\n    status: \"SUCCESS\",\n    history,\n  };\n};\n\n// JIXO_CODER_EOF\n","shellKill.function_call.ts":"import {junKillLogic} from \"jsr:@jixo/jun\";\nimport z from \"npm:zod\";\n\nexport const name = \"shellKill\";\n\nexport const description = \"停止一个或多个正在运行的后台任务。\";\n\nexport const paramsSchema = z.object({\n  pids: z.array(z.number().int().positive()).min(1).describe(\"要停止的后台任务PID列表。\"),\n});\n\n/**\n * 调用 @jixo/jun 的 junKillLogic 来停止任务。\n * @param args - 符合paramsSchema的参数\n * @returns 一个报告操作结果的对象\n */\nexport const functionCall = async (args: z.infer<typeof paramsSchema>) => {\n  console.log(`Executing jun kill logic for pids: ${args.pids.join(\", \")}`);\n\n  const {killedCount, failedPids} = await junKillLogic({pids: args.pids});\n\n  return {\n    status: \"SUCCESS\",\n    killed_count: killedCount,\n    failed_pids: failedPids,\n  };\n};\n\n// JIXO_CODER_EOF\n","shellList.function_call.ts":"import {junLsLogic} from \"jsr:@jixo/jun\";\nimport z from \"npm:zod\";\n\nexport const name = \"shellList\";\n\nexport const description = \"列出当前所有由jun管理的正在运行的后台任务。\";\n\nexport const paramsSchema = z.object({}).describe(\"此工具没有参数。\");\n\n/**\n * 调用 @jixo/jun 的 junLsLogic 来列出正在运行的任务。\n * @returns 一个包含正在运行任务列表的对象\n */\nexport const functionCall = async (_args: z.infer<typeof paramsSchema>) => {\n  console.log(`Executing jun ls logic`);\n\n  const runningTasks = await junLsLogic();\n\n  return {\n    status: \"SUCCESS\",\n    running_tasks: runningTasks,\n  };\n};\n\n// JIXO_CODER_EOF\n","shellRemove.function_call.ts":"import {junRmLogic} from \"jsr:@jixo/jun\";\nimport z from \"npm:zod\";\n\nexport const name = \"shellRemove\";\n\nexport const description = \"清理jun的历史记录。可以指定pid，也可以进行批量清理。\";\n\nexport const paramsSchema = z\n  .object({\n    pids: z.array(z.number().int().positive()).optional().describe(\"要移除的具体任务PID列表。\"),\n    all: z.boolean().optional().describe(\"如果为true，则移除所有已结束的任务。\"),\n    auto: z.boolean().optional().describe(\"如果为true，则自动清理，仅保留最近10条和所有正在运行的任务。\"),\n  })\n  .refine((data) => data.pids || data.all || data.auto, {\n    message: \"At least one of pids, all, or auto must be specified.\",\n  });\n\n/**\n * 调用 @jixo/jun 的 junRmLogic 来清理历史记录。\n * @param args - 符合paramsSchema的参数\n * @returns 一个报告操作结果的对象\n */\nexport const functionCall = async (args: z.infer<typeof paramsSchema>) => {\n  console.log(`Executing jun rm logic with args:`, args);\n\n  const {removed, skipped} = await junRmLogic({\n    pids: args.pids,\n    all: args.all,\n    auto: args.auto,\n  });\n\n  return {\n    status: \"SUCCESS\",\n    removed_pids: removed,\n    skipped_pids: skipped,\n  };\n};\n\n// JIXO_CODER_EOF\n","shellRun.function_call.ts":"import {junRunLogic} from \"jsr:@jixo/jun\";\nimport type {FunctionCallFn} from \"npm:@jixo/dev/google-aistudio\";\nimport z from \"npm:zod\";\n\nexport const name = \"shellRun\";\n\nexport const description = \"使用jun代理执行一个shell命令。这会将命令的执行和stdio持久化，并允许后台运行和后续查询。\";\n\nexport const paramsSchema = z.object({\n  command: z.string().describe(\"要执行的主命令。\"),\n  args: z.array(z.string()).optional().default([]).describe(\"命令的参数列表。\"),\n  background: z.boolean().optional().default(false).describe(\"是否在后台运行命令。如果为true，工具会立即返回pid而不会等待命令完成。\"),\n});\n\n/**\n * 调用 @jixo/jun 的 junRunLogic 来执行命令。\n * @param args - 符合paramsSchema的参数\n * @returns 一个包含jun任务信息的对象\n */\nexport const functionCall: FunctionCallFn<z.infer<typeof paramsSchema>> = async (args) => {\n  if (args.background) {\n    // For background tasks, we capture the JSON output to get the PID.\n    let pid = -1;\n    let osPid = -1;\n    const originalConsoleLog = console.log;\n    let jsonOutput = \"\";\n    console.log = (data) => {\n      jsonOutput = data;\n    }; // Hijack console.log\n\n    try {\n      await junRunLogic({\n        command: args.command,\n        commandArgs: args.args,\n        background: true,\n        json: true,\n      });\n      const parsed = JSON.parse(jsonOutput);\n      pid = parsed.pid;\n      osPid = parsed.osPid;\n    } finally {\n      console.log = originalConsoleLog; // Restore console.log\n    }\n\n    return {\n      status: \"STARTED_IN_BACKGROUND\",\n      pid: pid,\n      osPid: osPid,\n      command: args.command,\n      args: args.args,\n    };\n  }\n\n  // For foreground tasks, we wait for the result as before.\n  const exitCode = await junRunLogic({\n    command: args.command,\n    commandArgs: args.args,\n    background: false,\n    json: false,\n  });\n\n  return {\n    status: exitCode === 0 ? \"COMPLETED\" : \"ERROR\",\n    exit_code: exitCode,\n    command: args.command,\n    args: args.args,\n  };\n};\n","submitChangeSet.function_call.ts":"import type {FunctionCallFn} from \"npm:@jixo/dev/google-aistudio\";\nimport z from \"npm:zod\";\n\nexport const name = \"submitChangeSet\";\n\nexport const description = \"向用户展示一个文件变更集以供最终审批，并在批准后应用这些变更。\";\n\nconst operationSchema = z.object({\n  type: z.enum([\"writeFile\", \"deleteFile\", \"renameFile\"]),\n  path: z.string().describe(\"被操作文件的完整路径。\"),\n  content: z.string().optional().describe(\"当type为'writeFile'时，提供文件的完整、最终内容。\"),\n  new_path: z.string().optional().describe(\"当type为'renameFile'时，提供文件的新路径。\"),\n});\n\nexport const paramsSchema = z.object({\n  change_log: z.string().describe(\"严格符合Git Commit Message规范的变更日志。\"),\n  operations: z.array(operationSchema).describe(\"一个包含所有文件系统操作的原子列表。\"),\n  final_statement: z.string().describe(\"当这个变更集被成功应用后，你希望对用户说的总结性话语。\"),\n});\n\n/**\n * Renders a change set to the user for final approval, then returns the operations if approved.\n * In a real scenario, the host environment (jixo-node) would execute the operations.\n * For now, this function simulates that by returning the operations upon approval.\n * @param args - The changeset details.\n * @param context - The context containing the `render` function.\n * @returns The original operations if approved, so the host can execute them.\n */\nexport const functionCall: FunctionCallFn<z.infer<typeof paramsSchema>> = async (args, context) => {\n  console.log(\"Proposing changeset to user via UI for final approval.\");\n\n  try {\n    const isApproved = await context.render({\n      component: \"SubmitChangeSetPanel\",\n      props: {\n        change_log: args.change_log,\n        operations: args.operations,\n      },\n    });\n\n    if (isApproved === true) {\n      console.log(\"Changeset was approved by the user.\");\n      // The tool's job is done. It returns the validated operations.\n      // The host environment is now responsible for executing them.\n      return {\n        status: \"CHANGESET_APPROVED\",\n        operations: args.operations,\n        final_statement: args.final_statement,\n      };\n    } else {\n      throw new Error(\"Changeset was rejected by the user.\");\n    }\n  } catch (error) {\n    console.error(\"Failed to get changeset approval:\", error);\n    throw error;\n  }\n};\n"}