Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions multimodal/omni-tars/omni-agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ export default class OmniTARSAgent extends ComposableAgent {
welcomTitle: 'Let’s work it out',
welcomePrompts: [],
welcomeCards: [
{
title: 'Play Game',
category: 'Game',
prompt: `1. Open this game: https://cpstest.click/en/aim-trainer#google_vignette
2. Select total sec to 50
3. Play and pass this game`,
image:
'https://images.unsplash.com/photo-1551288049-bebda4e38f71?w=400&h=300&fit=crop&crop=center',
agentOptions: {
agentMode: {
id: 'game',
link: 'https://cpstest.click/en/aim-trainer#google_vignette',
browserMode: 'hybrid',
},
},
},
{
title: 'GUI Agent Research',
category: 'Research',
Expand Down Expand Up @@ -141,6 +157,8 @@ export default class OmniTARSAgent extends ComposableAgent {
};

constructor(option: OmniTarsOption) {
console.log('[option]', option);

super(getComposableOption(option));
}
}
104 changes: 0 additions & 104 deletions multimodal/tarko/agent-server-next/src/controllers/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,110 +9,6 @@ import { SessionInfo } from '@tarko/interface';
import { ShareService } from '../services';
import { filterSessionModel } from '../utils';

/**
* Get runtime settings schema and current values
*/
export async function getRuntimeSettings(c: HonoContext) {
const sessionId = c.req.query('sessionId');

if (!sessionId) {
return c.json({ error: 'Session ID is required' }, 400);
}

try {
const server = c.get('server');

// Get runtime settings configuration from server config
const runtimeSettingsConfig = server.appConfig?.server?.runtimeSettings;

if (!runtimeSettingsConfig) {
return c.json({
schema: { type: 'object', properties: {} },
currentValues: {}
}, 200);
}

// Get current session info to retrieve stored runtime settings
let currentValues = {};

const sessionInfo = await server.daoFactory.getSessionInfo(sessionId);
currentValues = sessionInfo?.metadata?.runtimeSettings || {};

// Merge with default values from schema
const schema = runtimeSettingsConfig.schema;
const mergedValues: Record<string, any> = { ...currentValues };

if (schema && schema.properties) {
Object.entries(schema.properties).forEach(([key, propSchema]: [string, any]) => {
if (mergedValues[key] === undefined && propSchema.default !== undefined) {
mergedValues[key] = propSchema.default;
}
});
}

return c.json({
schema: runtimeSettingsConfig.schema,
currentValues: mergedValues
}, 200);
} catch (error) {
console.error(`Error getting runtime settings for session ${sessionId}:`, error);
return c.json({ error: 'Failed to get runtime settings' }, 500);
}
}

/**
* Update runtime settings for a session
*/
export async function updateRuntimeSettings(c: HonoContext) {
const body = await c.req.json();
const server = c.get('server');
const activeSession = c.get('session');

if (!activeSession) {
return c.json({ error: 'Session not found' }, 404);
}

const { runtimeSettings } = body as {
sessionId: string;
runtimeSettings: Record<string, any>;
};
const sessionId = activeSession.id;


if (!runtimeSettings || typeof runtimeSettings !== 'object') {
return c.json({ error: 'Runtime settings object is required' }, 400);
}

try {
// Update session info with new runtime settings
const updated = {
metadata: {
...activeSession.sessionInfo?.metadata,
runtimeSettings,
},
}

const updatedSessionInfo = await server.daoFactory.updateSessionInfo(sessionId, updated);

try {
// Recreate agent with new runtime settings configuration
await activeSession!.updateSessionConfig(updatedSessionInfo);
console.log('Session agent recreated with new runtime settings', { sessionId });
} catch (error) {
console.error('Failed to update agent runtime settings for session', { sessionId, error });
// Continue execution - the runtime settings are saved, will apply on next session
}

return c.json({
session: updatedSessionInfo,
runtimeSettings
}, 200);
} catch (error) {
console.error(`Error updating runtime settings for session ${sessionId}:`, error);
return c.json({ error: 'Failed to update runtime settings' }, 500);
}
}

/**
* Get all sessions (with multi-tenant support)
*/
Expand Down
125 changes: 121 additions & 4 deletions multimodal/tarko/agent-server-next/src/controllers/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,127 @@ export async function getVersion(c: HonoContext) {
* Get agent options (sanitized for client)
*/
export async function getAgentOptions(c: HonoContext) {
const server = c.get('server')
return c.json({
options: sanitizeAgentOptions(server.appConfig),
}, 200);
const server = c.get('server')
return c.json({
options: sanitizeAgentOptions(server.appConfig),
}, 200);
}

/**
* Get runtime settings schema and current values
* - If no sessionId provided: returns only schema for home page
* - If sessionId provided: returns schema + current values for that session
*/
export async function getRuntimeSettings(c: HonoContext) {
const sessionId = c.req.query('sessionId');
const server = c.get('server');

try {
// Get runtime settings configuration from server config
const runtimeSettingsConfig = server.appConfig?.server?.runtimeSettings;

if (!runtimeSettingsConfig) {
return c.json({
schema: { type: 'object', properties: {} },
currentValues: {}
}, 200);
}

const schema = runtimeSettingsConfig.schema;
let currentValues = {};

// If sessionId is provided, get current session values
if (sessionId) {
try {
const sessionInfo = await server.daoFactory.getSessionInfo(sessionId);
currentValues = sessionInfo?.metadata?.runtimeSettings || {};
} catch (error) {
// Session doesn't exist or no stored values, use defaults from schema
}
}

// Merge with default values from schema
const mergedValues: Record<string, any> = { ...currentValues };

if (schema && schema.properties) {
Object.entries(schema.properties).forEach(([key, propSchema]: [string, any]) => {
if (mergedValues[key] === undefined && propSchema.default !== undefined) {
mergedValues[key] = propSchema.default;
}
});
}

return c.json({
schema: schema,
currentValues: sessionId ? mergedValues : {} // Only return current values if sessionId provided
}, 200);
} catch (error) {
console.error(`Error getting runtime settings:`, error);
return c.json({ error: 'Failed to get runtime settings' }, 500);
}
}

/**
* Update runtime settings for a session
* Requires sessionId parameter
*/
export async function updateRuntimeSettings(c: HonoContext) {
const body = await c.req.json();
const { sessionId, runtimeSettings } = body as {
sessionId: string;
runtimeSettings: Record<string, any>;
};

if (!sessionId) {
return c.json({ error: 'Session ID is required' }, 400);
}

if (!runtimeSettings || typeof runtimeSettings !== 'object') {
return c.json({ error: 'Runtime settings object is required' }, 400);
}

try {
const server = c.get('server');

const sessionInfo = await server.daoFactory.getSessionInfo(sessionId);
if (!sessionInfo) {
return c.json({ error: 'Session not found' }, 404);
}

// Update session info with new runtime settings
const updatedSessionInfo = await server.daoFactory.updateSessionInfo(sessionId, {
metadata: {
...sessionInfo.metadata,
runtimeSettings,
},
});

// If session is currently active, recreate the agent with new runtime settings
const activeSession = server.getSessionPool().get(sessionId);
if (activeSession) {
console.log('Runtime settings updated', {
sessionId,
runtimeSettings,
});

try {
// Recreate agent with new runtime settings configuration
await activeSession.updateSessionConfig(updatedSessionInfo);
console.log('Session agent recreated with new runtime settings', { sessionId });
} catch (error) {
console.error('Failed to update agent runtime settings for session', { sessionId, error });
// Continue execution - the runtime settings are saved, will apply on next session
}
}

return c.json({
session: updatedSessionInfo,
runtimeSettings
}, 200);
} catch (error) {
console.error(`Error updating runtime settings:`, error);
return c.json({ error: 'Failed to update runtime settings' }, 500);
}
}

export function getAvailableModels(c: HonoContext) {
Expand Down
4 changes: 4 additions & 0 deletions multimodal/tarko/agent-server-next/src/routes/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export function createSystemRoutes(): Hono<{ Variables: ContextVariables }> {
// Agent options endpoint (sanitized)
router.get('/api/v1/agent/options', systemController.getAgentOptions);

// Runtime settings endpoints
router.get('/api/v1/runtime-settings', systemController.getRuntimeSettings);
router.post('/api/v1/runtime-settings', systemController.updateRuntimeSettings);

// Model management endpoints
router.get('/api/v1/models', systemController.getAvailableModels);
router.post('/api/v1/sessions/model', systemController.updateSessionModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,11 @@ export class AgentSession {
}
}

// Merge base options with transformed runtime settings
// Merge base options with transformed runtime settings and one-time agent options
const agentOptions = {
...baseAgentOptions,
...transformedOptions,
...(this.agentOptions || {}), // Apply one-time agent initialization options
};

// Create base agent
Expand Down Expand Up @@ -269,6 +270,7 @@ export class AgentSession {
sessionId: string,
agioProviderImpl?: AgioProviderConstructor,
sessionInfo?: SessionInfo,
private agentOptions?: Record<string, any>, // One-time agent initialization options
) {
this.id = sessionId;
this.eventBridge = new EventStreamBridge();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ export class AgentSessionFactory {
const sessionId = nanoid();
const user = getCurrentUser(c);
const server = c.get('server');

// Get runtimeSettings and agentOptions from request body
const body = await c.req.json().catch(() => ({}));
const { runtimeSettings, agentOptions } = body as {
runtimeSettings?: Record<string, any>;
agentOptions?: Record<string, any>;
};

// Allocate sandbox if scheduler is available
let sandboxUrl: string | undefined;
Expand Down Expand Up @@ -88,19 +95,39 @@ export class AgentSessionFactory {
modelConfig: defaultModel,
}),
sandboxUrl,
// Include runtime settings if provided (persistent session settings)
...(runtimeSettings && {
runtimeSettings,
}),
// Include agent options if provided (one-time initialization options)
...(agentOptions && {
agentOptions,
}),
},
};

const savedSessionInfo = await this.sessionDao.createSession(newSessionInfo);

// Create AgentSession instance with sandbox URL
// Create AgentSession instance with sandbox URL and agent options
const session = this.createAgentSessionWithSandbox({
sessionInfo: savedSessionInfo,
agioProvider: this.server.getCustomAgioProvider(),
agentOptions, // Pass one-time agent options
});

// Initialize the session
const { storageUnsubscribe } = await session.initialize();

// If runtime settings were provided and session is active, update the agent configuration
if (runtimeSettings && savedSessionInfo) {
try {
await session.updateSessionConfig(savedSessionInfo);
console.log('Session created with runtime settings', { sessionId, runtimeSettings });
} catch (error) {
console.error('Failed to apply runtime settings to new session', { sessionId, error });
// Continue execution - the runtime settings are saved, will apply on next session restart
}
}

return {
session,
Expand Down Expand Up @@ -163,6 +190,7 @@ export class AgentSessionFactory {
const session = this.createAgentSessionWithSandbox({
sessionInfo,
agioProvider: this.server.getCustomAgioProvider(),
// No agentOptions for restored sessions - they are one-time initialization only
});

const { storageUnsubscribe } = await session.initialize();
Expand All @@ -180,10 +208,11 @@ export class AgentSessionFactory {
private createAgentSessionWithSandbox(options: {
sessionInfo: SessionInfo;
agioProvider?: AgioProviderConstructor;
agentOptions?: Record<string, any>; // One-time agent initialization options
}): AgentSession {
const { sessionInfo, agioProvider } = options;
const { sessionInfo, agioProvider, agentOptions } = options;

const session = new AgentSession(this.server, sessionInfo.id, agioProvider, sessionInfo);
const session = new AgentSession(this.server, sessionInfo.id, agioProvider, sessionInfo, agentOptions);

return session;
}
Expand Down
Loading
Loading