-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathapi.ts
More file actions
85 lines (76 loc) · 2.29 KB
/
api.ts
File metadata and controls
85 lines (76 loc) · 2.29 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* Tasks API - Type-safe message definitions for the Tasks webview.
*
* Usage:
* ```tsx
* const ipc = useIpc();
* const tasks = await ipc.request(TasksApi.getTasks); // Returns Task[]
* ipc.command(TasksApi.viewInCoder, { taskId: "..." }); // Fire-and-forget
* ```
*/
import {
defineCommand,
defineNotification,
defineRequest,
} from "../ipc/protocol";
import type { Task, TaskDetails, TaskTemplate } from "./types";
export interface TaskIdParams {
taskId: string;
}
const getTasks = defineRequest<void, readonly Task[] | null>("getTasks");
const getTemplates = defineRequest<void, readonly TaskTemplate[] | null>(
"getTemplates",
);
const getTask = defineRequest<TaskIdParams, Task>("getTask");
const getTaskDetails = defineRequest<TaskIdParams, TaskDetails>(
"getTaskDetails",
);
export interface CreateTaskParams {
templateVersionId: string;
prompt: string;
presetId?: string;
}
const createTask = defineRequest<CreateTaskParams, Task>("createTask");
export interface TaskActionParams extends TaskIdParams {
taskName: string;
}
const deleteTask = defineRequest<TaskActionParams, void>("deleteTask");
const pauseTask = defineRequest<TaskActionParams, void>("pauseTask");
const resumeTask = defineRequest<TaskActionParams, void>("resumeTask");
const downloadLogs = defineRequest<TaskIdParams, void>("downloadLogs");
const sendTaskMessage = defineRequest<TaskIdParams & { message: string }, void>(
"sendTaskMessage",
);
const viewInCoder = defineCommand<TaskIdParams>("viewInCoder");
const viewLogs = defineCommand<TaskIdParams>("viewLogs");
const stopStreamingWorkspaceLogs = defineCommand<void>(
"stopStreamingWorkspaceLogs",
);
const taskUpdated = defineNotification<Task>("taskUpdated");
const tasksUpdated = defineNotification<Task[]>("tasksUpdated");
const workspaceLogsAppend = defineNotification<string[]>("workspaceLogsAppend");
const refresh = defineNotification<void>("refresh");
const showCreateForm = defineNotification<void>("showCreateForm");
export const TasksApi = {
// Requests
getTasks,
getTemplates,
getTask,
getTaskDetails,
createTask,
deleteTask,
pauseTask,
resumeTask,
downloadLogs,
sendTaskMessage,
// Commands
viewInCoder,
viewLogs,
stopStreamingWorkspaceLogs,
// Notifications
taskUpdated,
tasksUpdated,
workspaceLogsAppend,
refresh,
showCreateForm,
} as const;