-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathapi.ts
More file actions
118 lines (102 loc) · 3.42 KB
/
Copy pathapi.ts
File metadata and controls
118 lines (102 loc) · 3.42 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
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
import { HttpApiEndpoint, HttpApiGroup } from "effect/unstable/httpapi";
import { Schema } from "effect";
import { InternalError } from "@executor-js/sdk/shared";
// ---------------------------------------------------------------------------
// Schemas
// ---------------------------------------------------------------------------
const ExecuteRequest = Schema.Struct({
code: Schema.String,
});
const StartCellRequest = Schema.Struct({
code: Schema.String,
yieldAfterMs: Schema.optional(Schema.Number),
});
const CompletedResult = Schema.Struct({
status: Schema.Literal("completed"),
text: Schema.String,
structured: Schema.Unknown,
isError: Schema.Boolean,
});
const PausedResult = Schema.Struct({
status: Schema.Literal("paused"),
text: Schema.String,
structured: Schema.Unknown,
});
const ExecuteResponse = Schema.Union([CompletedResult, PausedResult]);
const CellObservation = Schema.Struct({
status: Schema.Literals(["running", "completed", "failed", "terminated"]),
cellId: Schema.String,
cursor: Schema.Number,
events: Schema.Array(Schema.Unknown),
result: Schema.optional(Schema.Unknown),
error: Schema.optional(Schema.String),
});
const ResumeRequest = Schema.Struct({
action: Schema.Literals(["accept", "decline", "cancel"]),
content: Schema.optional(Schema.Unknown),
});
const ResumeResponse = Schema.Union([CompletedResult, PausedResult]);
const PausedExecutionInfo = Schema.Struct({
text: Schema.String,
structured: Schema.Unknown,
});
const ExecutionNotFoundError = Schema.TaggedStruct("ExecutionNotFoundError", {
executionId: Schema.String,
}).annotate({ httpApiStatus: 404 });
// ---------------------------------------------------------------------------
// Params
// ---------------------------------------------------------------------------
const ExecutionParams = { executionId: Schema.String };
const CellParams = { cellId: Schema.String };
const CellWaitQuery = Schema.Struct({
after: Schema.optional(Schema.String),
timeoutMs: Schema.optional(Schema.String),
});
// ---------------------------------------------------------------------------
// Group
// ---------------------------------------------------------------------------
export const ExecutionsApi = HttpApiGroup.make("executions")
.add(
HttpApiEndpoint.post("execute", "/executions", {
payload: ExecuteRequest,
success: ExecuteResponse,
error: InternalError,
}),
)
.add(
HttpApiEndpoint.post("startCell", "/execution-cells", {
payload: StartCellRequest,
success: CellObservation,
error: InternalError,
}),
)
.add(
HttpApiEndpoint.get("waitCell", "/execution-cells/:cellId", {
params: CellParams,
query: CellWaitQuery,
success: CellObservation,
error: [InternalError, ExecutionNotFoundError],
}),
)
.add(
HttpApiEndpoint.post("terminateCell", "/execution-cells/:cellId/terminate", {
params: CellParams,
success: CellObservation,
error: [InternalError, ExecutionNotFoundError],
}),
)
.add(
HttpApiEndpoint.get("getPaused", "/executions/:executionId", {
params: ExecutionParams,
success: PausedExecutionInfo,
error: [InternalError, ExecutionNotFoundError],
}),
)
.add(
HttpApiEndpoint.post("resume", "/executions/:executionId/resume", {
params: ExecutionParams,
payload: ResumeRequest,
success: ResumeResponse,
error: [InternalError, ExecutionNotFoundError],
}),
);