|
@@ -1,4 +1,3 @@
|
|
|
-import { GoogleGenAI } from '@google/genai';
|
|
|
|
|
import * as Commands from './commands/Commands.js';
|
|
import * as Commands from './commands/Commands.js';
|
|
|
import { Vector3, BoxGeometry, SphereGeometry, MeshStandardMaterial, Mesh, DirectionalLight, PointLight, AmbientLight, Color, CylinderGeometry } from 'three';
|
|
import { Vector3, BoxGeometry, SphereGeometry, MeshStandardMaterial, Mesh, DirectionalLight, PointLight, AmbientLight, Color, CylinderGeometry } from 'three';
|
|
|
|
|
|
|
@@ -397,29 +396,18 @@ class Agent {
|
|
|
|
|
|
|
|
Do not include any other text outside the JSON.`;
|
|
Do not include any other text outside the JSON.`;
|
|
|
|
|
|
|
|
- this.chat = await ai.chats.create({
|
|
|
|
|
- model: "gemini-2.0-flash",
|
|
|
|
|
- history: [
|
|
|
|
|
- {
|
|
|
|
|
- role: "user",
|
|
|
|
|
- parts: [{ text: systemPrompt }],
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- role: "model",
|
|
|
|
|
- parts: [
|
|
|
|
|
- {
|
|
|
|
|
- text: "I'm ready to help you create and modify your 3D scene.",
|
|
|
|
|
- },
|
|
|
|
|
- ],
|
|
|
|
|
- },
|
|
|
|
|
- ],
|
|
|
|
|
- config: {
|
|
|
|
|
- temperature: 0.2,
|
|
|
|
|
- maxOutputTokens: 2048
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ // const { available, defaultTemperature, defaultTopK, maxTopK } = await ai.languageModel.capabilities();
|
|
|
|
|
+ // console.log( 'Capabilities:', available, defaultTemperature, defaultTopK, maxTopK );
|
|
|
|
|
+
|
|
|
|
|
+ // if ( available !== 'readily' ) {
|
|
|
|
|
+
|
|
|
|
|
+ const session = await ai.languageModel.create({
|
|
|
|
|
+ systemPrompt: systemPrompt
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- console.log( 'CHAT:', this.chat );
|
|
|
|
|
|
|
+ console.log( 'SESSION:', session );
|
|
|
|
|
+
|
|
|
|
|
+ this.session = session;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -429,18 +417,16 @@ class Agent {
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
|
|
|
|
|
- this.signals.agentThinking.dispatch();
|
|
|
|
|
|
|
+ this.signals.agentThinking.dispatch();
|
|
|
|
|
|
|
|
- const response = await this.chat.sendMessage( { message: query } );
|
|
|
|
|
-
|
|
|
|
|
- console.log( 'RESPONSE:', response.text );
|
|
|
|
|
|
|
+ const response = await this.session.prompt( query );
|
|
|
|
|
|
|
|
let responseData;
|
|
let responseData;
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
|
|
|
|
|
// Strip markdown code block markers if present
|
|
// Strip markdown code block markers if present
|
|
|
- const cleanText = response.text.replace( /^```json\n|\n```$/g, '' )
|
|
|
|
|
|
|
+ const cleanText = response.replace( /^```json\n|\n```$/g, '' )
|
|
|
.replace( /^\s*```\s*|\s*```\s*$/g, '' ) // Remove any remaining code block markers
|
|
.replace( /^\s*```\s*|\s*```\s*$/g, '' ) // Remove any remaining code block markers
|
|
|
.trim();
|
|
.trim();
|
|
|
|
|
|
|
@@ -451,6 +437,8 @@ class Agent {
|
|
|
|
|
|
|
|
} catch ( e ) {
|
|
} catch ( e ) {
|
|
|
|
|
|
|
|
|
|
+ console.log( 'ERROR:', e );
|
|
|
|
|
+
|
|
|
// If that fails, try to fix common JSON issues
|
|
// If that fails, try to fix common JSON issues
|
|
|
const fixedText = cleanText
|
|
const fixedText = cleanText
|
|
|
.replace( /,\s*([}\]])/g, '$1' ) // Remove trailing commas
|
|
.replace( /,\s*([}\]])/g, '$1' ) // Remove trailing commas
|
|
@@ -464,9 +452,11 @@ class Agent {
|
|
|
|
|
|
|
|
} catch ( e ) {
|
|
} catch ( e ) {
|
|
|
|
|
|
|
|
|
|
+ console.log( 'ERROR:', e );
|
|
|
|
|
+
|
|
|
// console.error( 'AGENT: Failed to parse AI response as JSON:', e );
|
|
// console.error( 'AGENT: Failed to parse AI response as JSON:', e );
|
|
|
- // console.error( 'AGENT: Raw response:', response.text );
|
|
|
|
|
- this.showError( response.text );
|
|
|
|
|
|
|
+ // console.error( 'AGENT: Raw response:', response );
|
|
|
|
|
+ this.showError( response );
|
|
|
return;
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -500,6 +490,8 @@ class Agent {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ console.log( this.session.tokensSoFar, '/', this.session.tokensLeft );
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async executeCommand( commandData ) {
|
|
async executeCommand( commandData ) {
|