-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Expand file tree
/
Copy pathEntryView.tsx
More file actions
468 lines (444 loc) · 17.3 KB
/
Copy pathEntryView.tsx
File metadata and controls
468 lines (444 loc) · 17.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
import {
useCallback,
useEffect,
useState,
type Dispatch,
type ReactNode,
type SetStateAction,
} from 'react';
import type { ChatSessionMode, ConnectorDetail } from '@open-design/contracts';
import type { OpenDesignHostProjectImportSuccess } from '@open-design/host';
import {
DEFAULT_AUDIO_MODEL,
DEFAULT_IMAGE_MODEL,
DEFAULT_VIDEO_MODEL,
} from '../media/models';
import type {
AgentInfo,
ApiProtocol,
AppConfig,
DesignSystemSummary,
ExecMode,
Project,
ProjectKind,
ProjectMetadata,
ProjectTemplate,
PromptTemplateSummary,
ProviderModelOption,
SkillSummary,
} from '../types';
// `EntryShell` owns the redesigned home layout (left rail + centered
// hero + recent projects + plugins). Keeping the redesign in a sibling
// component lets future rebases against upstream `EntryView` (props,
// connector lifecycle, exported helpers) stay close to a no-op here.
import { EntryShell, type ProjectTitleHint } from './EntryShell';
import type { IntegrationTab } from './IntegrationsView';
import type { CreateInput, ImportClaudeDesignOutcome } from './NewProjectPanel';
import {
CONNECTOR_CALLBACK_MESSAGE_TYPE,
listenForConnectorsChanged,
} from './connectors-events';
import { fetchConnectorCatalogSnapshot } from './connectors-state';
import type {
PluginShareAction,
PluginShareProjectOutcome,
} from '../state/projects';
type EntryCreateProjectInput = Omit<CreateInput, 'metadata'> & {
metadata?: CreateInput['metadata'];
pendingPrompt?: string;
pluginId?: string;
pluginType?: string;
appliedPluginSnapshotId?: string;
pluginInputs?: Record<string, unknown>;
conversationMode?: ChatSessionMode;
autoSendFirstMessage?: boolean;
requestId?: string;
pendingFiles?: File[];
userWorkingDirToken?: string;
};
interface Props {
// Union of functional skills + design templates — used for id-based
// lookups (DesignsTab project chips, NewProjectPanel skill picker).
// The Templates gallery itself reads `designTemplates` instead so it
// doesn't accidentally show functional skills as renderable cards.
skills: SkillSummary[];
// Design templates only. Sourced from /api/design-templates. See
// specs/current/skills-and-design-templates.md.
designTemplates: SkillSummary[];
designSystems: DesignSystemSummary[];
projects: Project[];
templates: ProjectTemplate[];
onDeleteTemplate: (id: string) => Promise<boolean>;
promptTemplates: PromptTemplateSummary[];
defaultDesignSystemId: string | null;
agents: AgentInfo[];
// Forwarded to EntryShell → OnboardingView so the AMR cloud card can show a
// detecting/skeleton state while the cold-start agent stream is in flight.
agentsLoading?: boolean;
amrLoggedIn?: boolean | null;
// Execution / model-switching context forwarded to the EntryShell so the
// sticky top-bar can expose the active CLI/BYOK + model and persist
// changes through the same channels as the project view.
config: AppConfig;
providerModelsCache?: Record<string, ProviderModelOption[]>;
onProviderModelsCacheChange?: Dispatch<SetStateAction<Record<string, ProviderModelOption[]>>>;
integrationInitialTab?: IntegrationTab;
composioConfigLoading?: boolean;
daemonLive: boolean;
onModeChange: (mode: ExecMode) => void;
onAgentChange: (id: string) => void;
onAgentModelChange: (
id: string,
choice: { model?: string; reasoning?: string; serviceTier?: string },
) => void;
onApiProtocolChange: (protocol: ApiProtocol) => void;
onApiModelChange: (model: string) => void;
onConfigPersist: (cfg: AppConfig) => Promise<void> | void;
onSkillsRefresh?: () => Promise<void> | void;
onSkillsChanged?: (affectedSkillId?: string) => void;
onRefreshAgents: () => Promise<AgentInfo[]> | AgentInfo[];
// Per-resource loading flags. Each tab gates its own content on whichever
// flag matches the data it renders, so a slow `/api/agents` probe does
// not block tabs that don't need agents. Templates are not gated here —
// the New project modal renders an empty state until they arrive (fast
// fetch), which keeps the prop surface narrower.
skillsLoading?: boolean;
designSystemsLoading?: boolean;
projectsLoading?: boolean;
promptTemplatesLoading?: boolean;
onCreateProject: (input: EntryCreateProjectInput) => Promise<boolean> | boolean | void;
onCreatePluginShareProject: (
pluginId: string,
action: PluginShareAction,
locale?: string,
) => Promise<PluginShareProjectOutcome>;
onImportClaudeDesign: (
file: File,
) => Promise<ImportClaudeDesignOutcome | void> | ImportClaudeDesignOutcome | void;
onImportFolder?: (baseDir: string) => Promise<void> | void;
onImportFolderResponse?: (response: OpenDesignHostProjectImportSuccess) => Promise<void> | void;
onOpenProject: (
id: string,
fileName?: string,
projectTitleHint?: ProjectTitleHint,
) => Promise<boolean> | boolean | void;
onOpenLiveArtifact: (projectId: string, artifactId: string) => void;
onDeleteProject: (id: string) => void;
onDuplicateProject?: (id: string) => Promise<void> | void;
onRenameProject: (id: string, name: string) => void;
onProjectsRefresh?: () => Promise<void> | void;
onTeamProjectContentReady?: (
projectId: string,
workspaceId: string,
workspaceMemberId: string,
) => Promise<boolean> | boolean;
onChangeDefaultDesignSystem: (id: string) => void;
onCreateDesignSystem?: () => void;
onOpenDesignSystem?: (id: string) => void;
onDesignSystemsRefresh?: () => Promise<void> | void;
onPersistComposioKey: (composio: AppConfig['composio']) => Promise<void> | void;
onOpenSettings: (section?: 'execution' | 'media' | 'composio' | 'orbit' | 'integrations' | 'mcpClient' | 'language' | 'appearance' | 'notifications' | 'pet' | 'projectLocations' | 'library' | 'about' | 'memory' | 'designSystems') => void;
onCompleteOnboarding: () => void;
artifactUpgradeSlot?: ReactNode;
}
export function isTrustedConnectorCallbackOrigin(origin: string, currentOrigin?: string): boolean {
const expectedOrigin = currentOrigin ?? (typeof window === 'undefined' ? '' : window.location.origin);
if (origin === expectedOrigin) return true;
try {
const url = new URL(origin);
if (url.protocol !== 'http:' && url.protocol !== 'https:') return false;
return url.hostname === 'localhost' || url.hostname === '127.0.0.1' || url.hostname === '[::1]' || url.hostname === '::1';
} catch {
return false;
}
}
export function sortConnectorsForDisplay(connectors: ConnectorDetail[]): ConnectorDetail[] {
return [...connectors].sort((a, b) => {
const aConnected = a.status === 'connected';
const bConnected = b.status === 'connected';
if (aConnected !== bConnected) return aConnected ? -1 : 1;
return a.name.localeCompare(b.name, undefined, { sensitivity: 'base' }) || a.id.localeCompare(b.id);
});
}
function normalizedSearchValue(value: string | undefined): string {
return typeof value === 'string' ? value.trim().toLowerCase() : '';
}
function scoreConnectorText(value: string | undefined, query: string, baseScore: number): number | null {
const normalized = normalizedSearchValue(value);
if (!normalized) return null;
if (normalized === query) return baseScore;
if (normalized.startsWith(query)) return baseScore + 1;
if (normalized.includes(query)) return baseScore + 2;
return null;
}
export function getConnectorSearchScore(connector: ConnectorDetail, query: string): number | null {
const normalizedQuery = query.trim().toLowerCase();
if (!normalizedQuery) return 0;
const scores: number[] = [];
const collect = (value: string | undefined, baseScore: number) => {
const score = scoreConnectorText(value, normalizedQuery, baseScore);
if (score !== null) scores.push(score);
};
// Connector identity fields carry the most intent: exact and prefix
// name/provider matches should beat incidental mentions elsewhere.
collect(connector.name, 0);
collect(connector.provider, 0);
// Secondary connector metadata is still searchable, but lower priority.
collect(connector.category, 3);
collect(connector.accountLabel, 3);
// Tool names/titles are more relevant than prose descriptions, but below
// connector-level identity matches.
for (const tool of connector.tools) {
collect(tool.title, 5);
collect(tool.name, 5);
}
// Prose descriptions are broad and often mention other products, so they
// are intentionally down-ranked rather than excluded.
collect(connector.description, 8);
for (const tool of connector.tools) {
collect(tool.description, 8);
}
return scores.length ? Math.min(...scores) : null;
}
export function sortConnectorsForSearch(
connectors: ConnectorDetail[],
query: string,
): ConnectorDetail[] {
const normalizedQuery = query.trim().toLowerCase();
if (!normalizedQuery) return sortConnectorsForDisplay(connectors);
return [...connectors]
.map((connector) => ({ connector, score: getConnectorSearchScore(connector, normalizedQuery) }))
.filter((entry): entry is { connector: ConnectorDetail; score: number } => entry.score !== null)
.sort((a, b) => {
if (a.score !== b.score) return a.score - b.score;
const aConnected = a.connector.status === 'connected';
const bConnected = b.connector.status === 'connected';
if (aConnected !== bConnected) return aConnected ? -1 : 1;
return (
a.connector.name.localeCompare(b.connector.name, undefined, { sensitivity: 'base' }) ||
a.connector.id.localeCompare(b.connector.id)
);
})
.map((entry) => entry.connector);
}
export function EntryView({
skills,
designTemplates,
designSystems,
projects,
templates,
onDeleteTemplate,
promptTemplates,
defaultDesignSystemId,
agents,
agentsLoading,
amrLoggedIn,
config,
providerModelsCache,
onProviderModelsCacheChange,
integrationInitialTab,
composioConfigLoading = false,
daemonLive,
onModeChange,
onAgentChange,
onAgentModelChange,
onApiProtocolChange,
onApiModelChange,
onConfigPersist,
onSkillsRefresh,
onSkillsChanged,
onRefreshAgents,
skillsLoading = false,
designSystemsLoading = false,
projectsLoading = false,
promptTemplatesLoading: _promptTemplatesLoading = false,
onCreateProject,
onCreatePluginShareProject,
onImportClaudeDesign,
onImportFolder,
onImportFolderResponse,
onOpenProject,
onOpenLiveArtifact,
onDeleteProject,
onDuplicateProject,
onRenameProject,
onProjectsRefresh,
onTeamProjectContentReady,
onChangeDefaultDesignSystem,
onCreateDesignSystem,
onOpenDesignSystem,
onDesignSystemsRefresh,
onPersistComposioKey,
onOpenSettings,
onCompleteOnboarding,
artifactUpgradeSlot,
}: Props) {
const [connectors, setConnectors] = useState<ConnectorDetail[]>([]);
const [connectorsLoading, setConnectorsLoading] = useState(false);
const reloadConnectorCatalog = useCallback(async (options: { refreshDiscovery?: boolean } = {}) => {
setConnectors(await fetchConnectorCatalogSnapshot(options));
}, []);
useEffect(() => {
let cancelled = false;
// Fetch connectors on mount so the New project modal can show
// already-configured connectors without waiting for the user to
// open the Settings → Connectors surface.
setConnectorsLoading(true);
(async () => {
const next = await fetchConnectorCatalogSnapshot();
if (cancelled) return;
setConnectors(next);
setConnectorsLoading(false);
})();
return () => {
cancelled = true;
};
}, []);
useEffect(() => {
function onMessage(event: MessageEvent) {
const data = event.data;
if (!data || typeof data !== 'object' || (data as { type?: unknown }).type !== CONNECTOR_CALLBACK_MESSAGE_TYPE) return;
if (!isTrustedConnectorCallbackOrigin(event.origin)) return;
void reloadConnectorCatalog({ refreshDiscovery: true });
}
window.addEventListener('message', onMessage);
return () => window.removeEventListener('message', onMessage);
}, [reloadConnectorCatalog]);
useEffect(() => {
function onConnectorsChanged() {
void reloadConnectorCatalog({ refreshDiscovery: true });
}
return listenForConnectorsChanged(onConnectorsChanged);
}, [reloadConnectorCatalog]);
// When the OAuth flow is handed off to the user's system browser (desktop
// shell opens connector auth URLs externally rather than in an Electron
// popup), the callback page has no `window.opener` to postMessage back to.
// Refresh connector statuses whenever the window regains focus so the UI
// picks up a just-completed connection without manual intervention.
useEffect(() => {
function refreshAfterReturn() {
void reloadConnectorCatalog({ refreshDiscovery: true });
}
function onVisibilityChange() {
if (document.visibilityState !== 'visible') return;
refreshAfterReturn();
}
window.addEventListener('focus', refreshAfterReturn);
window.addEventListener('pageshow', refreshAfterReturn);
document.addEventListener('visibilitychange', onVisibilityChange);
return () => {
window.removeEventListener('focus', refreshAfterReturn);
window.removeEventListener('pageshow', refreshAfterReturn);
document.removeEventListener('visibilitychange', onVisibilityChange);
};
}, [reloadConnectorCatalog]);
return (
<EntryShell
skills={skills}
designTemplates={designTemplates}
designSystems={designSystems}
projects={projects}
templates={templates}
onDeleteTemplate={onDeleteTemplate}
promptTemplates={promptTemplates}
defaultDesignSystemId={defaultDesignSystemId}
connectors={connectors}
connectorsLoading={connectorsLoading}
{...(integrationInitialTab ? { integrationInitialTab } : {})}
composioConfigLoading={composioConfigLoading}
skillsLoading={skillsLoading}
designSystemsLoading={designSystemsLoading}
projectsLoading={projectsLoading}
config={config}
providerModelsCache={providerModelsCache}
onProviderModelsCacheChange={onProviderModelsCacheChange}
agents={agents}
{...(agentsLoading !== undefined ? { agentsLoading } : {})}
{...(amrLoggedIn !== undefined ? { amrLoggedIn } : {})}
daemonLive={daemonLive}
onModeChange={onModeChange}
onAgentChange={onAgentChange}
onAgentModelChange={onAgentModelChange}
onApiProtocolChange={onApiProtocolChange}
onApiModelChange={onApiModelChange}
onConfigPersist={onConfigPersist}
onSkillsRefresh={onSkillsRefresh}
onSkillsChanged={onSkillsChanged}
onRefreshAgents={onRefreshAgents}
onCreateProject={onCreateProject}
onCreatePluginShareProject={onCreatePluginShareProject}
onImportClaudeDesign={onImportClaudeDesign}
{...(onImportFolder ? { onImportFolder } : {})}
{...(onImportFolderResponse ? { onImportFolderResponse } : {})}
onOpenProject={onOpenProject}
onOpenLiveArtifact={onOpenLiveArtifact}
onDeleteProject={onDeleteProject}
onDuplicateProject={onDuplicateProject}
onRenameProject={onRenameProject}
onProjectsRefresh={onProjectsRefresh}
onTeamProjectContentReady={onTeamProjectContentReady}
onChangeDefaultDesignSystem={onChangeDefaultDesignSystem}
onCreateDesignSystem={onCreateDesignSystem}
onOpenDesignSystem={onOpenDesignSystem}
onDesignSystemsRefresh={onDesignSystemsRefresh}
onPersistComposioKey={onPersistComposioKey}
onOpenSettings={onOpenSettings}
onCompleteOnboarding={onCompleteOnboarding}
artifactUpgradeSlot={artifactUpgradeSlot}
/>
);
}
// Map a skill's declared mode to project metadata. Falls back to the same
// defaults the new-project form would apply (high-fidelity prototype, no
// speaker notes on decks, no template animations) so 'Use this prompt'
// produces a project indistinguishable from one created via the form. Per-
// skill hints in SKILL.md frontmatter (od.fidelity, od.speaker_notes,
// od.animations) override the defaults so each example reproduces the
// shipped example.html — e.g. wireframe-sketch declares fidelity:wireframe.
//
// Kept exported (and the kindForSkill helper too) so the New project modal
// and any future skill-driven creation surface can share the mapping.
export function metadataForSkill(skill: SkillSummary): ProjectMetadata {
const kind = kindForSkill(skill);
if (kind === 'prototype') {
return { kind, fidelity: skill.fidelity ?? 'high-fidelity' };
}
if (kind === 'deck') {
return {
kind,
speakerNotes:
typeof skill.speakerNotes === 'boolean' ? skill.speakerNotes : false,
};
}
if (kind === 'template') {
return {
kind,
animations:
typeof skill.animations === 'boolean' ? skill.animations : false,
};
}
if (kind === 'image') {
return { kind, imageModel: DEFAULT_IMAGE_MODEL, imageAspect: '1:1' };
}
if (kind === 'video') {
return { kind, videoModel: DEFAULT_VIDEO_MODEL, videoAspect: '16:9', videoLength: 5 };
}
if (kind === 'audio') {
return {
kind,
audioKind: 'speech',
audioModel: DEFAULT_AUDIO_MODEL.speech,
audioDuration: 10,
};
}
return { kind: 'other' };
}
export function kindForSkill(skill: SkillSummary): ProjectKind {
if (skill.mode === 'deck') return 'deck';
if (skill.mode === 'prototype') return 'prototype';
if (skill.mode === 'template') return 'template';
if (skill.mode === 'image' || skill.surface === 'image') return 'image';
if (skill.mode === 'video' || skill.surface === 'video') return 'video';
if (skill.mode === 'audio' || skill.surface === 'audio') return 'audio';
return 'other';
}