forked from getsentry/XcodeBuildMCP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession_set_defaults.ts
More file actions
61 lines (54 loc) · 2.63 KB
/
session_set_defaults.ts
File metadata and controls
61 lines (54 loc) · 2.63 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
import { z } from 'zod';
import { sessionStore, type SessionDefaults } from '../../../utils/session-store.ts';
import { createTypedTool } from '../../../utils/typed-tool-factory.ts';
import { getDefaultCommandExecutor } from '../../../utils/execution/index.ts';
import type { ToolResponse } from '../../../types/common.ts';
const baseSchema = z.object({
projectPath: z.string().optional(),
workspacePath: z.string().optional(),
scheme: z.string().optional(),
configuration: z.string().optional(),
simulatorName: z.string().optional(),
simulatorId: z.string().optional(),
deviceId: z.string().optional(),
useLatestOS: z.boolean().optional(),
arch: z.enum(['arm64', 'x86_64']).optional(),
suppressWarnings: z
.boolean()
.optional()
.describe('When true, warning messages are filtered from build output to conserve context'),
});
const schemaObj = baseSchema
.refine((v) => !(v.projectPath && v.workspacePath), {
message: 'projectPath and workspacePath are mutually exclusive',
path: ['projectPath'],
})
.refine((v) => !(v.simulatorId && v.simulatorName), {
message: 'simulatorId and simulatorName are mutually exclusive',
path: ['simulatorId'],
});
type Params = z.infer<typeof schemaObj>;
export async function sessionSetDefaultsLogic(params: Params): Promise<ToolResponse> {
// Clear mutually exclusive counterparts before merging new defaults
const toClear = new Set<keyof SessionDefaults>();
if (Object.prototype.hasOwnProperty.call(params, 'projectPath')) toClear.add('workspacePath');
if (Object.prototype.hasOwnProperty.call(params, 'workspacePath')) toClear.add('projectPath');
if (Object.prototype.hasOwnProperty.call(params, 'simulatorId')) toClear.add('simulatorName');
if (Object.prototype.hasOwnProperty.call(params, 'simulatorName')) toClear.add('simulatorId');
if (toClear.size > 0) {
sessionStore.clear(Array.from(toClear));
}
sessionStore.setDefaults(params as Partial<SessionDefaults>);
const current = sessionStore.getAll();
return {
content: [{ type: 'text', text: `Defaults updated:\n${JSON.stringify(current, null, 2)}` }],
isError: false,
};
}
export default {
name: 'session-set-defaults',
description:
'Set the session defaults needed by many tools. Most tools require one or more session defaults to be set before they can be used. Agents should set all relevant defaults up front in a single call (e.g., project/workspace, scheme, simulator or device ID, useLatestOS) to avoid iterative prompts; only set the keys your workflow needs.',
schema: baseSchema.shape,
handler: createTypedTool(schemaObj, sessionSetDefaultsLogic, getDefaultCommandExecutor),
};