File size: 7,313 Bytes
3201ca6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React from "react";
import {
  Bot,
  Home,
  Keyboard,
  KeyRound,
  ListTodo,
  PanelsTopLeft,
  Search,
  Settings,
  ShieldCheck,
  Sparkles,
  Wrench,
  Zap,
} from "lucide-react";
import { I18nKey } from "#/i18n/declaration";
import {
  automationListPath,
  getInterfaceCopy,
  hasAutomationInterface,
} from "#/manifests/automation-interface";
import { getLockedCloudHost } from "#/api/agent-server-config";
import { LOCKED_CLOUD_SETTINGS_NAV_PATH } from "#/constants/settings-nav";

const ICON_SIZE = 18;

export const COMMAND_MENU_ROUTE = {
  conversations: "/conversations",
  customize: "/customize",
  automations: automationListPath(),
  mcp: "/mcp",
  settings: "/settings",
  agentSettings: "/settings/agents",
  llmSettings: "/settings/llm",
  condenserSettings: "/settings/condenser",
  verificationSettings: "/settings/verification",
  appSettings: "/settings/app",
  secretsSettings: "/settings/secrets",
} as const;

export type CommandMenuGroupId = "navigation" | "settings" | "actions";
export type CommandMenuItemId =
  | "new-chat"
  | "customize"
  | "automations"
  | "mcp"
  | "settings"
  | "agent-settings"
  | "llm-settings"
  | "condenser-settings"
  | "verification-settings"
  | "app-settings"
  | "secrets-settings"
  | "toggle-sidebar";

export interface CommandMenuItemDefinition {
  id: CommandMenuItemId;
  group: CommandMenuGroupId;
  /** Absent on an item whose copy a manifest owns, which sets the literal. */
  titleKey?: I18nKey;
  descriptionKey?: I18nKey;
  keywordsKey?: I18nKey;
  /** Literal copy, for an item a manifest owns. */
  title?: string;
  description?: string;
  keywords?: string;
  icon: React.ReactElement;
  to?: string;
  perform?: () => void;
}

/**
 * An item's copy: its literal when a manifest owns the item, its translation
 * otherwise.
 */
export function commandMenuItemCopy(
  literal: string | undefined,
  key: I18nKey | undefined,
  translate: (key: I18nKey) => string,
): string {
  if (literal !== undefined) return literal;
  return key === undefined ? "" : translate(key);
}

export const COMMAND_MENU_GROUP_LABELS: Record<CommandMenuGroupId, I18nKey> = {
  navigation: I18nKey.COMMAND_MENU$GROUP_NAVIGATION,
  settings: I18nKey.COMMAND_MENU$GROUP_SETTINGS,
  actions: I18nKey.COMMAND_MENU$GROUP_ACTIONS,
};

export const COMMAND_MENU_GROUP_ORDER: CommandMenuGroupId[] = [
  "navigation",
  "settings",
  "actions",
];

export const createCommandMenuItems = ({
  toggleSidebar,
}: {
  toggleSidebar: () => void;
}): CommandMenuItemDefinition[] => {
  const items: CommandMenuItemDefinition[] = [
    {
      id: "new-chat",
      group: "navigation",
      titleKey: I18nKey.COMMAND_MENU$NEW_CHAT_TITLE,
      descriptionKey: I18nKey.COMMAND_MENU$NEW_CHAT_DESCRIPTION,
      keywordsKey: I18nKey.COMMAND_MENU$NEW_CHAT_KEYWORDS,
      icon: <Home size={ICON_SIZE} />,
      to: COMMAND_MENU_ROUTE.conversations,
    },
    {
      id: "customize",
      group: "navigation",
      titleKey: I18nKey.COMMAND_MENU$CUSTOMIZE_TITLE,
      descriptionKey: I18nKey.COMMAND_MENU$CUSTOMIZE_DESCRIPTION,
      keywordsKey: I18nKey.COMMAND_MENU$CUSTOMIZE_KEYWORDS,
      icon: <Sparkles size={ICON_SIZE} />,
      to: COMMAND_MENU_ROUTE.customize,
    },
    // The automation interface owns this entry's copy, so an absent manifest
    // leaves the command menu without it rather than with host copy.
    ...(hasAutomationInterface()
      ? [
          {
            id: "automations" as const,
            group: "navigation" as const,
            title: getInterfaceCopy().commandMenuTitle,
            description: getInterfaceCopy().commandMenuDescription,
            keywords: getInterfaceCopy().commandMenuKeywords,
            icon: <Zap size={ICON_SIZE} />,
            to: COMMAND_MENU_ROUTE.automations,
          },
        ]
      : []),
    {
      id: "mcp",
      group: "navigation",
      titleKey: I18nKey.COMMAND_MENU$MCP_TITLE,
      descriptionKey: I18nKey.COMMAND_MENU$MCP_DESCRIPTION,
      keywordsKey: I18nKey.COMMAND_MENU$MCP_KEYWORDS,
      icon: <Wrench size={ICON_SIZE} />,
      to: COMMAND_MENU_ROUTE.mcp,
    },
    {
      id: "settings",
      group: "settings",
      titleKey: I18nKey.COMMAND_MENU$SETTINGS_TITLE,
      descriptionKey: I18nKey.COMMAND_MENU$SETTINGS_DESCRIPTION,
      keywordsKey: I18nKey.COMMAND_MENU$SETTINGS_KEYWORDS,
      icon: <Settings size={ICON_SIZE} />,
      to: COMMAND_MENU_ROUTE.settings,
    },
    {
      id: "agent-settings",
      group: "settings",
      titleKey: I18nKey.COMMAND_MENU$AGENT_SETTINGS_TITLE,
      descriptionKey: I18nKey.COMMAND_MENU$AGENT_SETTINGS_DESCRIPTION,
      keywordsKey: I18nKey.COMMAND_MENU$AGENT_SETTINGS_KEYWORDS,
      icon: <Bot size={ICON_SIZE} />,
      to: COMMAND_MENU_ROUTE.agentSettings,
    },
    {
      id: "llm-settings",
      group: "settings",
      titleKey: I18nKey.COMMAND_MENU$LLM_SETTINGS_TITLE,
      descriptionKey: I18nKey.COMMAND_MENU$LLM_SETTINGS_DESCRIPTION,
      keywordsKey: I18nKey.COMMAND_MENU$LLM_SETTINGS_KEYWORDS,
      icon: <Search size={ICON_SIZE} />,
      to: COMMAND_MENU_ROUTE.llmSettings,
    },
    {
      id: "condenser-settings",
      group: "settings",
      titleKey: I18nKey.COMMAND_MENU$CONDENSER_SETTINGS_TITLE,
      descriptionKey: I18nKey.COMMAND_MENU$CONDENSER_SETTINGS_DESCRIPTION,
      keywordsKey: I18nKey.COMMAND_MENU$CONDENSER_SETTINGS_KEYWORDS,
      icon: <ListTodo size={ICON_SIZE} />,
      to: COMMAND_MENU_ROUTE.condenserSettings,
    },
    {
      id: "verification-settings",
      group: "settings",
      titleKey: I18nKey.COMMAND_MENU$VERIFICATION_SETTINGS_TITLE,
      descriptionKey: I18nKey.COMMAND_MENU$VERIFICATION_SETTINGS_DESCRIPTION,
      keywordsKey: I18nKey.COMMAND_MENU$VERIFICATION_SETTINGS_KEYWORDS,
      icon: <ShieldCheck size={ICON_SIZE} />,
      to: COMMAND_MENU_ROUTE.verificationSettings,
    },
    {
      id: "app-settings",
      group: "settings",
      titleKey: I18nKey.COMMAND_MENU$APP_SETTINGS_TITLE,
      descriptionKey: I18nKey.COMMAND_MENU$APP_SETTINGS_DESCRIPTION,
      keywordsKey: I18nKey.COMMAND_MENU$APP_SETTINGS_KEYWORDS,
      icon: <PanelsTopLeft size={ICON_SIZE} />,
      to: COMMAND_MENU_ROUTE.appSettings,
    },
    {
      id: "secrets-settings",
      group: "settings",
      titleKey: I18nKey.COMMAND_MENU$SECRETS_SETTINGS_TITLE,
      descriptionKey: I18nKey.COMMAND_MENU$SECRETS_SETTINGS_DESCRIPTION,
      keywordsKey: I18nKey.COMMAND_MENU$SECRETS_SETTINGS_KEYWORDS,
      icon: <KeyRound size={ICON_SIZE} />,
      to: COMMAND_MENU_ROUTE.secretsSettings,
    },
    {
      id: "toggle-sidebar",
      group: "actions",
      titleKey: I18nKey.COMMAND_MENU$TOGGLE_SIDEBAR_TITLE,
      descriptionKey: I18nKey.COMMAND_MENU$TOGGLE_SIDEBAR_DESCRIPTION,
      keywordsKey: I18nKey.COMMAND_MENU$TOGGLE_SIDEBAR_KEYWORDS,
      icon: <Keyboard size={ICON_SIZE} />,
      perform: toggleSidebar,
    },
  ];

  // Locked-to-Cloud (SaaS / self-hosted OHE) lists only the Application page;
  // the OHE settings shell owns the rest (OHE-3168).
  const isLockedToCloud = getLockedCloudHost() !== null;

  return items.filter(
    (item) =>
      !isLockedToCloud ||
      item.group !== "settings" ||
      item.to === COMMAND_MENU_ROUTE.settings ||
      item.to === LOCKED_CLOUD_SETTINGS_NAV_PATH,
  );
};