Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

tools.ts

69 lines2.6 KB

1import {
2 DefaultThemePreference,
3 EnvironmentThemeFile,
4 EnvironmentThemeId,
5 OrchestratorMcpFailure,
6} from "@t3tools/contracts";
7import * as Schema from "effect/Schema";
8import { Tool, Toolkit } from "effect/ai";
9import * as EnvironmentTheme from "../../../environmentTheme.ts";
10import * as McpInvocationContext from "../../McpInvocationContext.ts";
11import * as ThreadCommandExecutor from "../../../orchestration-v2/ThreadCommandExecutor.ts";
12import * as ThreadManagementService from "../../../orchestration-v2/ThreadManagementService.ts";
13​
14const Appearance = Schema.Literals(["light", "dark", "system"]);
15​
16const shared = {
17 failure: OrchestratorMcpFailure,
18 failureMode: "return" as const,
19 dependencies: [
20 McpInvocationContext.McpInvocationContext,
21 ThreadManagementService.ThreadManagementService,
22 EnvironmentTheme.EnvironmentThemeService,
23 ThreadCommandExecutor.ThreadCommandExecutor,
24 ],
25};
26​
27const ThemeReadTool = Tool.make("t3_theme_read", {
28 ...shared,
29 description:
30 "Read T3 Code's own themes and the guide to restyle it: color roles and CSS selectors. Call before `t3_theme_set`.",
31 parameters: Schema.Struct({
32 themeId: Schema.optionalKey(
33 EnvironmentThemeId.annotate({ description: "Also return this published theme's file." }),
34 ),
35 }),
36 success: Schema.Struct({
37 current: DefaultThemePreference,
38 builtIn: Schema.Array(Schema.String),
39 published: Schema.Array(
40 Schema.Struct({
41 id: EnvironmentThemeId,
42 name: Schema.String,
43 hasCss: Schema.Boolean,
44 }),
45 ),
46 theme: Schema.optionalKey(EnvironmentThemeFile),
47 guide: Schema.String,
48 }),
49})
50 .annotate(Tool.Readonly, true)
51 .annotate(Tool.Destructive, false);
52​
53const ThemeSetTool = Tool.make("t3_theme_set", {
54 ...shared,
55 description:
56 "Restyle T3 Code itself, only when the user asks. With `theme`, publish it as `themeId` (the same id updates it) and switch this machine's web and desktop clients to it. Without `theme`, switch to a built-in or published `themeId`. `appearance` switches them to light, dark, or system mode, with or without a theme. Live full-access or default caller thread only.",
57 parameters: Schema.Struct({
58 themeId: Schema.optionalKey(EnvironmentThemeId),
59 theme: Schema.optionalKey(EnvironmentThemeFile),
60 appearance: Schema.optionalKey(Appearance),
61 }),
62 success: Schema.Struct({
63 themeId: Schema.optionalKey(EnvironmentThemeId),
64 appearance: Schema.optionalKey(Appearance),
65 published: Schema.Boolean,
66 }),
67}).annotate(Tool.Destructive, true);
68​
69export const ThemeToolkit = Toolkit.make(ThemeReadTool, ThemeSetTool);