-
-
Notifications
You must be signed in to change notification settings - Fork 268
Expand file tree
/
Copy pathsession_set_defaults.ts
More file actions
47 lines (41 loc) · 2.01 KB
/
session_set_defaults.ts
File metadata and controls
47 lines (41 loc) · 2.01 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
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 schemaObj = 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(),
});
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 the relevant defaults at the beginning of a session.',
schema: schemaObj.shape,
handler: createTypedTool(schemaObj, sessionSetDefaultsLogic, getDefaultCommandExecutor),
};