|
| 1 | +import { parseOracleOutput, ParsedOracleResponse } from './parser'; |
| 2 | +// import { GoogleGenAI } from '@google/genai'; // Assuming this is installed |
| 3 | + |
| 4 | +const SYSTEM_PROMPT = ` |
| 5 | +You are the MANIFOLD Gemini Oracle. |
| 6 | +Your task is to generate valid WGSL shader code for a compute pass in a voxel/cellular automata simulation. |
| 7 | +
|
| 8 | +### The 6-Channel Material Tensor |
| 9 | +The terrain is defined by a 6-channel state tensor (Float32): |
| 10 | +- \`density\`: Physical mass. |
| 11 | +- \`cohesion\`: Structural integrity (rock=high, sand=low). |
| 12 | +- \`permeability\`: Ability for fluids to pass through. |
| 13 | +- \`water\`: Mobile fluid mass. |
| 14 | +- \`sediment\`: Mobile solid mass. |
| 15 | +- \`oxidation\`: Chemical state (age). |
| 16 | +
|
| 17 | +### Rules |
| 18 | +1. You must output exactly one \`\`\`wgsl block containing the shader. |
| 19 | +2. If you mutate \`water\` or \`sand\` using flux mechanics, you must mark \`flux_producer: true\`. |
| 20 | +3. You must output exactly one \`\`\`yaml block listing the channels you read from and write to. |
| 21 | +
|
| 22 | +Example YAML: |
| 23 | +\`\`\`yaml |
| 24 | +reads: [water, permeability] |
| 25 | +writes: [water, sand] |
| 26 | +flux_producer: true |
| 27 | +\`\`\` |
| 28 | +`; |
| 29 | + |
| 30 | +export class GeminiOracle { |
| 31 | + // private ai: GoogleGenAI; |
| 32 | + |
| 33 | + constructor(apiKey: string) { |
| 34 | + // this.ai = new GoogleGenAI({ apiKey }); |
| 35 | + console.log("Initialized Gemini Oracle with System Prompt constraints."); |
| 36 | + } |
| 37 | + |
| 38 | + public async generateModule(prompt: string): Promise<ParsedOracleResponse> { |
| 39 | + console.log(`[Oracle] Prompting Gemini: "${prompt}"`); |
| 40 | + |
| 41 | + // MOCK API CALL for now, simulating Gemini response |
| 42 | + // const response = await this.ai.models.generateContent({ |
| 43 | + // model: 'gemini-2.5-flash', |
| 44 | + // contents: prompt, |
| 45 | + // config: { systemInstruction: SYSTEM_PROMPT } |
| 46 | + // }); |
| 47 | + // const text = response.text; |
| 48 | + |
| 49 | + const mockResponseText = ` |
| 50 | +Here is your requested operator. |
| 51 | +\`\`\`wgsl |
| 52 | +@compute @workgroup_size(64) |
| 53 | +fn main(@builtin(global_invocation_id) id: vec3<u32>) { |
| 54 | + // Oracle generated code here |
| 55 | + let current_water = state.water[idx]; |
| 56 | + state.water[idx] = current_water * 0.99; // Evaporation |
| 57 | +} |
| 58 | +\`\`\` |
| 59 | +
|
| 60 | +\`\`\`yaml |
| 61 | +reads: [water] |
| 62 | +writes: [water] |
| 63 | +flux_producer: false |
| 64 | +\`\`\` |
| 65 | + `; |
| 66 | + |
| 67 | + return parseOracleOutput(mockResponseText); |
| 68 | + } |
| 69 | +} |
0 commit comments