Skip to content

Commit 77bc312

Browse files
committed
fix ts and add warning if using app tools on official web
1 parent a31a00f commit 77bc312

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

app/src/components/AgentCard/AgentCard.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ interface AgentCardProps {
5353
onSave: (agent: CompleteAgent, code: string) => Promise<void>;
5454
isProUser?: boolean;
5555
onAIEdit?: (agentId: string) => void;
56+
hostingContext?: 'official-web' | 'self-hosted' | 'tauri';
5657
}
5758

5859

5960
const AgentCard: React.FC<AgentCardProps> = ({
6061
agent, code, isRunning, isStarting, isMemoryFlashing, onEdit, onDelete, onToggle,
61-
onMemory, onActivity, onShowJupyterModal, hasQuotaError, onUpgradeClick, onSave, isProUser = false, onAIEdit
62+
onMemory, onActivity, onShowJupyterModal, hasQuotaError, onUpgradeClick, onSave, isProUser = false, onAIEdit, hostingContext
6263
}) => {
6364
const [isPythonAgent, setIsPythonAgent] = useState(false);
6465
const [startWarning, setStartWarning] = useState<string | null>(null);
@@ -246,6 +247,7 @@ const AgentCard: React.FC<AgentCardProps> = ({
246247
onModelChange={setCurrentModel}
247248
startWarning={startWarning}
248249
isProUser={isProUser}
250+
hostingContext={hostingContext}
249251
// REMOVED: communicationWarnings prop is gone
250252
/>
251253
)}

app/src/components/AgentCard/StaticAgentView.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import { detectAgentCapabilities } from './agentCapabilities';
1212

1313
// --- GENERIC HELPER COMPONENTS ---
1414

15-
const InfoTag: React.FC<{ icon: React.ElementType; label: string; warning?: string }> = ({ icon: Icon, label, warning }) => (
15+
const InfoTag: React.FC<{ icon: React.ElementType; label: string; warning?: string; isBlocking?: boolean }> = ({ icon: Icon, label, warning, isBlocking }) => (
1616
<div className="relative group">
1717
<div className="inline-flex items-center gap-1.5 bg-gray-100 text-gray-700 px-2 py-1 rounded-md text-xs font-medium cursor-default">
1818
<Icon className="w-3.5 h-3.5" />
1919
<span>{label}</span>
20-
{warning && <AlertTriangle className="w-3.5 h-3.5 ml-1 text-orange-500" />}
20+
{warning && <AlertTriangle className={`w-3.5 h-3.5 ml-1 ${isBlocking ? 'text-red-500' : 'text-orange-500'}`} />}
2121
</div>
2222
{warning && (
2323
<div className="absolute bottom-full left-1/2 -translate-x-1/2 mb-2 w-max max-w-xs p-2 bg-gray-800 text-white text-xs rounded-md shadow-lg opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none">
@@ -151,6 +151,7 @@ interface StaticAgentViewProps {
151151
onModelChange: (modelName: string) => void;
152152
startWarning: string | null;
153153
isProUser?: boolean;
154+
hostingContext?: 'official-web' | 'self-hosted' | 'tauri';
154155
}
155156

156157

@@ -162,14 +163,15 @@ const StaticAgentView: React.FC<StaticAgentViewProps> = ({
162163
onModelChange,
163164
startWarning,
164165
isProUser = false,
166+
hostingContext,
165167
}) => {
166168
const [detectedSensors, setDetectedSensors] = useState<any[]>([]);
167169
const [detectedTools, setDetectedTools] = useState<any[]>([]);
168170

169171
useEffect(() => {
170172
const loadCapabilities = async () => {
171173
try {
172-
const capabilities = await detectAgentCapabilities(agent.system_prompt || '', code || '');
174+
const capabilities = await detectAgentCapabilities(agent.system_prompt || '', code || '', hostingContext);
173175
setDetectedSensors(capabilities.sensors);
174176
setDetectedTools(capabilities.tools);
175177
} catch (error) {
@@ -180,7 +182,7 @@ const StaticAgentView: React.FC<StaticAgentViewProps> = ({
180182
};
181183

182184
loadCapabilities();
183-
}, [agent.system_prompt, code]);
185+
}, [agent.system_prompt, code, hostingContext]);
184186

185187
return (
186188
<div className="space-y-4 animate-fade-in">
@@ -220,6 +222,7 @@ const StaticAgentView: React.FC<StaticAgentViewProps> = ({
220222
icon={tool.icon}
221223
label={tool.label}
222224
warning={tool.warning}
225+
isBlocking={tool.isBlocking}
223226
/>
224227
))}
225228
</div>

app/src/components/AgentCard/agentCapabilities.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface DetectedTool {
1414
label: string;
1515
icon: React.ElementType;
1616
warning?: string;
17+
isBlocking?: boolean;
1718
}
1819

1920
export interface AgentCapabilities {
@@ -133,17 +134,30 @@ export async function detectAgentSensors(systemPrompt: string): Promise<Detected
133134
/**
134135
* Detects which tools an agent uses based on its code
135136
*/
136-
export async function detectAgentTools(code: string): Promise<DetectedTool[]> {
137+
export async function detectAgentTools(code: string, hostingContext?: 'official-web' | 'self-hosted' | 'tauri'): Promise<DetectedTool[]> {
137138
const foundTools: DetectedTool[] = [];
138139

140+
// Tools that don't work in official web environment
141+
const webIncompatibleTools = ['overlay', 'message', 'ask', 'system_notify'];
142+
139143
for (const [key, tool] of Object.entries(TOOL_CONFIG)) {
140144
if (code.match(tool.regex)) {
141145
const icon = await loadToolIcon(key);
146+
let warning = tool.warning;
147+
148+
// Add web incompatibility warning if in official web context
149+
let isBlocking = false;
150+
if (hostingContext === 'official-web' && webIncompatibleTools.includes(key)) {
151+
warning = 'These tools are only available when using the Observer App';
152+
isBlocking = true;
153+
}
154+
142155
foundTools.push({
143156
key,
144157
label: tool.label,
145158
icon,
146-
warning: tool.warning
159+
warning,
160+
isBlocking
147161
});
148162
}
149163
}
@@ -154,10 +168,10 @@ export async function detectAgentTools(code: string): Promise<DetectedTool[]> {
154168
/**
155169
* Detects all capabilities of an agent (sensors + tools)
156170
*/
157-
export async function detectAgentCapabilities(systemPrompt: string, code: string): Promise<AgentCapabilities> {
171+
export async function detectAgentCapabilities(systemPrompt: string, code: string, hostingContext?: 'official-web' | 'self-hosted' | 'tauri'): Promise<AgentCapabilities> {
158172
const [sensors, tools] = await Promise.all([
159173
detectAgentSensors(systemPrompt),
160-
detectAgentTools(code)
174+
detectAgentTools(code, hostingContext)
161175
]);
162176

163177
return {

app/src/web/App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState, useEffect, useCallback, useMemo } from 'react';
2-
import { Terminal, Server } from 'lucide-react';
2+
import { Terminal } from 'lucide-react';
33
import { Auth0Provider, useAuth0 } from '@auth0/auth0-react';
44
import { BrowserRouter, Routes, Route } from 'react-router-dom';
55
import {
@@ -629,6 +629,7 @@ function AppContent() {
629629
onSave={handleSaveAgent}
630630
isProUser={isProUser}
631631
onAIEdit={handleAIEditClick}
632+
hostingContext={hostingContext}
632633
/>
633634
</div>
634635
);

0 commit comments

Comments
 (0)