File size: 7,916 Bytes
5710dd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/**
 * Service panel descriptors — the handwritten *override* layer of the right
 * sidebar. The sidebar's baseline is the dynamic channel list served by
 * `GET /api/v1/debug/channels` (every wire-exposed Service with its methods);
 * a descriptor here replaces the generic card for its Service with a curated
 * one: a `fetch` that reads its inspectable state and optional `actions`
 * that trigger its methods. The generic `ServiceCard` renders them; adding a
 * curated panel is one entry here, no component code.
 *
 * Panels refresh manually (Load / Refresh buttons): the live event streams
 * that used to drive `refreshOn` refetches went away with the v2 socket
 * (`/api/v2/ws`).
 *
 * The proxies are typed by the real `agent-core-v2` contracts at the call
 * site, but panels treat them as `AnyService` so one descriptor shape covers
 * every Service.
 */

import { IAgentLoopService } from '@moonshot-ai/agent-core-v2/agent/loop/loop';
import { IAgentMcpService } from '@moonshot-ai/agent-core-v2/agent/mcp/mcp';
import { IAgentPermissionModeService } from '@moonshot-ai/agent-core-v2/agent/permissionMode/permissionMode';
import { IAgentPermissionRulesService } from '@moonshot-ai/agent-core-v2/agent/permissionRules/permissionRules';
import { IAgentPlanService } from '@moonshot-ai/agent-core-v2/features/plan/plan';
import { IAgentProfileService } from '@moonshot-ai/agent-core-v2/agent/profile/profile';
import { IAgentSwarmService } from '@moonshot-ai/agent-core-v2/features/swarm/agent/swarm';
import { IAgentTaskService } from '@moonshot-ai/agent-core-v2/agent/task/task';
import { IAgentToolRegistryService } from '@moonshot-ai/agent-core-v2/agent/toolRegistry/toolRegistry';
import { IAuthSummaryService } from '@moonshot-ai/agent-core-v2/app/auth/auth';
import { IConfigService } from '@moonshot-ai/agent-core-v2/app/config/config';
import { IFlagService } from '@moonshot-ai/agent-core-v2/app/flag/flag';
import { IProviderService } from '@moonshot-ai/agent-core-v2/llm-adapter/provider/provider';
import { ISessionInitService } from '@moonshot-ai/agent-core-v2/features/sessionInit/sessionInit';
import { ISessionMetadata } from '@moonshot-ai/agent-core-v2/session/sessionMetadata/sessionMetadata';
import { ISessionWorkspaceContext } from '@moonshot-ai/agent-core-v2/session/workspaceContext/workspaceContext';

/** Loosely-typed view of a scoped service proxy (every member is a remote call). */
export type AnyService = Record<string, (...args: unknown[]) => Promise<unknown>>;

/** Invoke a method on a loose proxy; the proxy materializes every member. */
export function call(svc: AnyService, method: string, ...args: unknown[]): Promise<unknown> {
  const fn = svc[method];
  if (fn === undefined) {
    return Promise.reject(new Error(`no such method on proxy: ${method}`));
  }
  return fn(...args);
}

export interface PanelAction {
  readonly label: string;
  /** Prompt for one string input before running (raw string passed to `run`). */
  readonly input?: string;
  readonly danger?: boolean;
  readonly run: (svc: AnyService, input?: string) => unknown;
}

export interface ServicePanelDef {
  /** Decorator id / wire channel name, e.g. `sessionMetadata`. */
  readonly id: string;
  readonly label: string;
  /** Wire scope the Service is called on (`app` maps to the `core` route). */
  readonly scope: 'app' | 'workspace' | 'session' | 'agent';
  readonly fetch?: (svc: AnyService) => Promise<unknown>;
  readonly actions?: readonly PanelAction[];
}

const setModeModes = ['manual', 'auto', 'yolo'];

export const CORE_PANELS: readonly ServicePanelDef[] = [
  {
    id: String(IConfigService),
    label: 'ConfigService',
    scope: 'app',
    fetch: async (svc) => ({
      config: await call(svc, 'getAll'),
      diagnostics: await call(svc, 'diagnostics'),
    }),
    actions: [{ label: 'reload', run: (svc) => call(svc, 'reload') }],
  },
  {
    id: String(IProviderService),
    label: 'ProviderService',
    scope: 'app',
    fetch: (svc) => call(svc, 'list'),
  },
  {
    id: String(IAuthSummaryService),
    label: 'AuthSummaryService',
    scope: 'app',
    fetch: (svc) => call(svc, 'summarize'),
  },
  {
    id: String(IFlagService),
    label: 'FlagService',
    scope: 'app',
    fetch: (svc) => call(svc, 'explainAll'),
  },
];

export const SESSION_PANELS: readonly ServicePanelDef[] = [
  {
    id: String(ISessionMetadata),
    label: 'SessionMetadata',
    scope: 'session',
    fetch: (svc) => call(svc, 'read'),
    actions: [
      { label: 'Set title', input: 'New title', run: (svc, title) => call(svc, 'setTitle', title) },
      { label: 'Archive', danger: true, run: (svc) => call(svc, 'setArchived', true) },
      { label: 'Unarchive', run: (svc) => call(svc, 'setArchived', false) },
    ],
  },
  {
    id: String(ISessionWorkspaceContext),
    label: 'SessionWorkspaceContext',
    scope: 'session',
    fetch: async (svc) => ({
      workDir: await call(svc, 'workDir'),
      additionalDirs: await call(svc, 'additionalDirs'),
    }),
  },
  {
    id: String(ISessionInitService),
    label: 'SessionInitService',
    scope: 'session',
    actions: [{ label: 'generateAgentsMd (/init)', run: (svc) => call(svc, 'generateAgentsMd') }],
  },
];

export const AGENT_PANELS: readonly ServicePanelDef[] = [
  {
    id: String(IAgentLoopService),
    label: 'AgentLoopService',
    scope: 'agent',
    fetch: (svc) => call(svc, 'activitySnapshot'),
  },
  {
    id: String(IAgentProfileService),
    label: 'AgentProfileService',
    scope: 'agent',
    fetch: async (svc) => ({
      model: await call(svc, 'getModel'),
      hasModel: await call(svc, 'hasModel'),
      isRunnable: await call(svc, 'isRunnable'),
      data: await call(svc, 'data'),
    }),
    actions: [
      { label: 'Set model', input: 'Model id', run: (svc, model) => call(svc, 'setModel', model) },
    ],
  },
  {
    id: String(IAgentPermissionModeService),
    label: 'AgentPermissionModeService',
    scope: 'agent',
    fetch: (svc) => call(svc, 'mode'),
    actions: setModeModes.map((mode) => ({
      label: `setMode('${mode}')`,
      run: (svc) => call(svc, 'setMode', mode),
    })),
  },
  {
    id: String(IAgentPermissionRulesService),
    label: 'AgentPermissionRulesService',
    scope: 'agent',
    fetch: (svc) => call(svc, 'rules'),
  },
  {
    id: String(IAgentPlanService),
    label: 'AgentPlanService',
    scope: 'agent',
    fetch: (svc) => call(svc, 'status'),
    actions: [
      { label: 'enter', run: (svc) => call(svc, 'enter') },
      { label: 'cancel', run: (svc) => call(svc, 'cancel') },
      { label: 'clear', run: (svc) => call(svc, 'clear') },
    ],
  },
  {
    id: String(IAgentTaskService),
    label: 'AgentTaskService',
    scope: 'agent',
    fetch: (svc) => call(svc, 'list'),
    actions: [
      {
        label: 'Stop task',
        input: 'Task id',
        danger: true,
        run: (svc, id) => call(svc, 'stop', id),
      },
      { label: 'stopAll', danger: true, run: (svc) => call(svc, 'stopAll') },
    ],
  },
  {
    id: String(IAgentToolRegistryService),
    label: 'AgentToolRegistryService',
    scope: 'agent',
    fetch: async (svc) => {
      const tools = (await call(svc, 'list')) as readonly { name?: string }[];
      return { count: tools.length, names: tools.map((t) => t.name) };
    },
  },
  {
    id: String(IAgentMcpService),
    label: 'AgentMcpService',
    scope: 'agent',
    fetch: (svc) => call(svc, 'list'),
    actions: [
      {
        label: 'Reconnect server',
        input: 'Server name',
        run: (svc, name) => call(svc, 'reconnect', name),
      },
    ],
  },
  {
    id: String(IAgentSwarmService),
    label: 'AgentSwarmService',
    scope: 'agent',
    fetch: (svc) => call(svc, 'isActive'),
    actions: [
      { label: 'enter (manual)', run: (svc) => call(svc, 'enter', 'manual') },
      { label: 'exit', run: (svc) => call(svc, 'exit') },
    ],
  },
];