unity-agent-tools 0.7.2 → 0.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/server.mjs +37 -14
  2. package/package.json +1 -1
package/dist/server.mjs CHANGED
@@ -31178,24 +31178,29 @@ Please install manually: dotnet tool install --global shader-ls`);
31178
31178
  // build/ai-handler.js
31179
31179
  import { query } from "@anthropic-ai/claude-agent-sdk";
31180
31180
  import { tmpdir } from "os";
31181
- import { existsSync } from "fs";
31181
+ import { existsSync, writeFileSync, unlinkSync } from "fs";
31182
31182
  import { fileURLToPath } from "url";
31183
31183
  import { dirname, join } from "path";
31184
31184
  async function handleAIQuery(request) {
31185
- const fullPrompt = buildFullPrompt(request.prompt, request.context, request.language, request.projectPath);
31185
+ const fullPrompt = buildFullPrompt(request.prompt, request.context, request.language, request.projectPath, !!request.referenceImage);
31186
31186
  const cwd = request.projectPath && existsSync(request.projectPath) ? request.projectPath : tmpdir();
31187
+ if (request.geminiApiKey)
31188
+ process.env.GEMINI_API_KEY = request.geminiApiKey;
31189
+ if (request.geminiModel)
31190
+ process.env.GEMINI_MODEL = request.geminiModel;
31191
+ let refImageTempPath;
31192
+ if (request.referenceImage) {
31193
+ refImageTempPath = join(tmpdir(), `unity-agent-ref-${Date.now()}.b64`);
31194
+ writeFileSync(refImageTempPath, request.referenceImage, "utf-8");
31195
+ process.env.GEMINI_REFERENCE_IMAGE_PATH = refImageTempPath;
31196
+ } else {
31197
+ delete process.env.GEMINI_REFERENCE_IMAGE_PATH;
31198
+ }
31199
+ delete process.env.GEMINI_REFERENCE_IMAGE;
31187
31200
  try {
31188
31201
  let resultText = "";
31189
31202
  request.onStatus?.("\u23F3 Claude Code \uC791\uC5C5 \uC2DC\uC791...");
31190
31203
  const serverPath = join(dirname(fileURLToPath(import.meta.url)), "server.mjs");
31191
- if (request.geminiApiKey)
31192
- process.env.GEMINI_API_KEY = request.geminiApiKey;
31193
- if (request.geminiModel)
31194
- process.env.GEMINI_MODEL = request.geminiModel;
31195
- if (request.referenceImage)
31196
- process.env.GEMINI_REFERENCE_IMAGE = request.referenceImage;
31197
- else
31198
- delete process.env.GEMINI_REFERENCE_IMAGE;
31199
31204
  for await (const msg of query({
31200
31205
  prompt: fullPrompt,
31201
31206
  options: {
@@ -31242,10 +31247,20 @@ async function handleAIQuery(request) {
31242
31247
  } catch (err) {
31243
31248
  const msg = err instanceof Error ? err.message : String(err);
31244
31249
  return { success: false, error: msg };
31250
+ } finally {
31251
+ if (refImageTempPath) {
31252
+ try {
31253
+ unlinkSync(refImageTempPath);
31254
+ } catch {
31255
+ }
31256
+ }
31245
31257
  }
31246
31258
  }
31247
- function buildFullPrompt(userPrompt, context, language, projectPath) {
31259
+ function buildFullPrompt(userPrompt, context, language, projectPath, hasReferenceImage) {
31248
31260
  let prompt = "You are a Unity development expert assistant embedded in a Unity Editor plugin. You can read, create, modify, and delete files in the Unity project. You have expertise in shaders (HLSL/ShaderLab), C# scripts, materials, textures, and all Unity workflows. You can also diagnose and fix Unity errors that prevent the project from compiling or running. You can generate images using the generate_image tool (powered by Google Nano Banana / Gemini Image). When the user asks to create a texture, sprite, icon, or any visual asset, use the generate_image tool with a detailed prompt. The generated image will appear in the Unity Editor where the user can save it to their project. Do NOT ask the user for file paths or project paths \u2014 the working directory is already set to the Unity project root. When fixing errors: read the relevant source files, understand the root cause, apply the fix, and explain what you changed. Answer clearly and concisely. When the user asks you to modify or create files, do it directly.\n";
31261
+ if (hasReferenceImage) {
31262
+ prompt += "IMPORTANT: The user has attached a reference image in the UI. When generating images, set useReferenceImage to true so the reference image is sent to Gemini. The reference image can be used for style transfer, color changes, edits, or as inspiration.\n";
31263
+ }
31249
31264
  if (projectPath) {
31250
31265
  prompt += `Unity project path: ${projectPath}
31251
31266
  `;
@@ -31888,6 +31903,7 @@ async function generateImage(request) {
31888
31903
  }
31889
31904
 
31890
31905
  // build/tools/generate-image.js
31906
+ import { readFileSync as readFileSync2, existsSync as existsSync2 } from "fs";
31891
31907
  var geminiConfig = {
31892
31908
  get apiKey() {
31893
31909
  return process.env.GEMINI_API_KEY || this._apiKey;
@@ -31902,9 +31918,16 @@ var geminiConfig = {
31902
31918
  set model(v) {
31903
31919
  this._model = v;
31904
31920
  },
31905
- _model: "gemini-2.5-flash-preview-image-generation",
31921
+ _model: "gemini-2.5-flash-image",
31906
31922
  get referenceImage() {
31907
- return process.env.GEMINI_REFERENCE_IMAGE || this._referenceImage;
31923
+ const filePath = process.env.GEMINI_REFERENCE_IMAGE_PATH;
31924
+ if (filePath && existsSync2(filePath)) {
31925
+ try {
31926
+ return readFileSync2(filePath, "utf-8");
31927
+ } catch {
31928
+ }
31929
+ }
31930
+ return this._referenceImage;
31908
31931
  },
31909
31932
  set referenceImage(v) {
31910
31933
  this._referenceImage = v;
@@ -32107,7 +32130,7 @@ function registerEditorPlatformResource(server, bridge) {
32107
32130
  async function main() {
32108
32131
  const server = new McpServer({
32109
32132
  name: "unity-agent-tools",
32110
- version: "0.7.2"
32133
+ version: "0.7.4"
32111
32134
  });
32112
32135
  const bridge = new UnityBridge("ws://localhost:8090");
32113
32136
  const lspClient = new ShaderLspClient();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unity-agent-tools",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "description": "Unity Agent - AI-powered Unity Editor tools for shader analysis and error auto-fix via Claude Code",
5
5
  "type": "module",
6
6
  "main": "dist/server.mjs",