t3code-cli 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.js +2 -2
- package/dist/index.js +1 -1
- package/dist/{runtime-DU_hs0MM.js → runtime-0wuYCEoH.js} +9952 -2871
- package/package.json +5 -3
- package/src/application/model-selection.ts +13 -15
- package/src/application/models.ts +1 -1
- package/src/application/project-commands.ts +6 -4
- package/src/application/service.ts +26 -22
- package/src/application/shell-sequence.ts +1 -1
- package/src/application/thread-commands.ts +32 -22
- package/src/application/thread-wait.ts +4 -4
- package/src/cli/model-format.ts +1 -1
- package/src/cli/project-format.ts +3 -3
- package/src/cli/thread-format.ts +6 -6
- package/src/domain/helpers.ts +11 -3
- package/src/domain/model-config.ts +1 -1
- package/src/domain/thread-lifecycle.ts +24 -30
- package/src/index.ts +6 -6
- package/src/orchestration/layer.ts +41 -48
- package/src/orchestration/service.ts +20 -11
- package/src/rpc/error.ts +12 -0
- package/src/rpc/layer.ts +2 -2
- package/src/rpc/service.ts +2 -3
- package/src/rpc/ws-group.ts +43 -0
- package/src/domain/command-schema.ts +0 -82
- package/src/domain/schema.ts +0 -162
- package/src/protocol/schema.ts +0 -105
|
@@ -4,34 +4,35 @@ import * as Option from "effect/Option";
|
|
|
4
4
|
import * as Schedule from "effect/Schedule";
|
|
5
5
|
import * as Sink from "effect/Sink";
|
|
6
6
|
import * as Stream from "effect/Stream";
|
|
7
|
-
import { RpcClientError } from "effect/unstable/rpc";
|
|
8
|
-
|
|
9
|
-
import { type ClientOrchestrationCommand } from "../domain/command-schema.ts";
|
|
10
7
|
import {
|
|
11
8
|
ORCHESTRATION_WS_METHODS,
|
|
12
|
-
|
|
13
|
-
type ThreadStreamItem,
|
|
9
|
+
ThreadId,
|
|
14
10
|
WS_METHODS,
|
|
15
|
-
|
|
11
|
+
type ClientOrchestrationCommand,
|
|
12
|
+
type OrchestrationShellStreamItem,
|
|
13
|
+
type OrchestrationThreadStreamItem,
|
|
14
|
+
} from "@t3tools/contracts";
|
|
15
|
+
import { RpcClientError } from "effect/unstable/rpc";
|
|
16
|
+
|
|
16
17
|
import { RpcError } from "../rpc/error.ts";
|
|
17
18
|
import { T3Rpc, type WsClient } from "../rpc/service.ts";
|
|
19
|
+
import type { CliRpcRequestError } from "../rpc/ws-group.ts";
|
|
18
20
|
import { T3Orchestration, type OpenThread } from "./service.ts";
|
|
19
21
|
|
|
20
|
-
type
|
|
22
|
+
type RpcRequestError = RpcClientError.RpcClientError | CliRpcRequestError;
|
|
21
23
|
|
|
22
24
|
const rpcRetrySchedule = Schedule.exponential("100 millis").pipe(
|
|
23
25
|
Schedule.take(4),
|
|
24
26
|
Schedule.collectWhile(
|
|
25
|
-
(metadata: Schedule.Metadata
|
|
26
|
-
metadata.input instanceof RpcClientError.RpcClientError,
|
|
27
|
+
(metadata: Schedule.Metadata) => metadata.input instanceof RpcClientError.RpcClientError,
|
|
27
28
|
),
|
|
28
29
|
);
|
|
29
30
|
|
|
30
31
|
function runRpc<A>(
|
|
31
32
|
rpc: T3Rpc["Service"],
|
|
32
33
|
method: string,
|
|
33
|
-
f: (client: WsClient) => Effect.Effect<A,
|
|
34
|
-
) {
|
|
34
|
+
f: (client: WsClient) => Effect.Effect<A, RpcRequestError>,
|
|
35
|
+
): Effect.Effect<A, RpcError> {
|
|
35
36
|
return Effect.gen(function* () {
|
|
36
37
|
const client = yield* rpc.getClient;
|
|
37
38
|
return yield* f(client);
|
|
@@ -41,15 +42,13 @@ function runRpc<A>(
|
|
|
41
42
|
),
|
|
42
43
|
Effect.retry(rpcRetrySchedule),
|
|
43
44
|
Effect.catchTags({
|
|
44
|
-
RpcClientError: (error) =>
|
|
45
|
-
Effect.fail(
|
|
46
|
-
new RpcError({
|
|
47
|
-
message: error.message,
|
|
48
|
-
method,
|
|
49
|
-
cause: error,
|
|
50
|
-
}),
|
|
51
|
-
),
|
|
52
45
|
RpcError: (error) => Effect.fail(error),
|
|
46
|
+
EnvironmentAuthorizationError: (error) => Effect.fail(toRpcRequestError(error, method)),
|
|
47
|
+
RpcClientError: (error) => Effect.fail(toRpcRequestError(error, method)),
|
|
48
|
+
KeybindingsConfigParseError: (error) => Effect.fail(toRpcRequestError(error, method)),
|
|
49
|
+
OrchestrationDispatchCommandError: (error) => Effect.fail(toRpcRequestError(error, method)),
|
|
50
|
+
OrchestrationGetSnapshotError: (error) => Effect.fail(toRpcRequestError(error, method)),
|
|
51
|
+
ServerSettingsError: (error) => Effect.fail(toRpcRequestError(error, method)),
|
|
53
52
|
}),
|
|
54
53
|
);
|
|
55
54
|
}
|
|
@@ -57,23 +56,21 @@ function runRpc<A>(
|
|
|
57
56
|
function subscribeRpc<A>(
|
|
58
57
|
rpc: T3Rpc["Service"],
|
|
59
58
|
method: string,
|
|
60
|
-
f: (client: WsClient) => Stream.Stream<A,
|
|
61
|
-
) {
|
|
59
|
+
f: (client: WsClient) => Stream.Stream<A, RpcRequestError>,
|
|
60
|
+
): Stream.Stream<A, RpcError> {
|
|
62
61
|
return Stream.unwrap(Effect.map(rpc.getClient, f)).pipe(
|
|
63
62
|
Stream.tapError((error) =>
|
|
64
63
|
error instanceof RpcClientError.RpcClientError ? rpc.disconnect : Effect.void,
|
|
65
64
|
),
|
|
66
65
|
Stream.retry(rpcRetrySchedule),
|
|
67
66
|
Stream.catchTags({
|
|
68
|
-
RpcClientError: (error) =>
|
|
69
|
-
Stream.fail(
|
|
70
|
-
new RpcError({
|
|
71
|
-
message: error.message,
|
|
72
|
-
method,
|
|
73
|
-
cause: error,
|
|
74
|
-
}),
|
|
75
|
-
),
|
|
76
67
|
RpcError: (error) => Stream.fail(error),
|
|
68
|
+
EnvironmentAuthorizationError: (error) => Stream.fail(toRpcRequestError(error, method)),
|
|
69
|
+
RpcClientError: (error) => Stream.fail(toRpcRequestError(error, method)),
|
|
70
|
+
KeybindingsConfigParseError: (error) => Stream.fail(toRpcRequestError(error, method)),
|
|
71
|
+
OrchestrationDispatchCommandError: (error) => Stream.fail(toRpcRequestError(error, method)),
|
|
72
|
+
OrchestrationGetSnapshotError: (error) => Stream.fail(toRpcRequestError(error, method)),
|
|
73
|
+
ServerSettingsError: (error) => Stream.fail(toRpcRequestError(error, method)),
|
|
77
74
|
}),
|
|
78
75
|
);
|
|
79
76
|
}
|
|
@@ -83,20 +80,8 @@ export const makeT3Orchestration = Effect.fn("makeT3Orchestration")(function* ()
|
|
|
83
80
|
const dispatch = Effect.fn("T3OrchestrationLive.dispatch")(function* (
|
|
84
81
|
command: ClientOrchestrationCommand,
|
|
85
82
|
) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
Effect.tapErrorTag("RpcClientError", () => rpc.disconnect),
|
|
89
|
-
Effect.catchTags({
|
|
90
|
-
RpcClientError: (error) =>
|
|
91
|
-
Effect.fail(
|
|
92
|
-
new RpcError({
|
|
93
|
-
message: error.message,
|
|
94
|
-
method: ORCHESTRATION_WS_METHODS.dispatchCommand,
|
|
95
|
-
cause: error,
|
|
96
|
-
}),
|
|
97
|
-
),
|
|
98
|
-
RpcError: (error) => Effect.fail(error),
|
|
99
|
-
}),
|
|
83
|
+
return yield* runRpc(rpc, ORCHESTRATION_WS_METHODS.dispatchCommand, (client) =>
|
|
84
|
+
client[ORCHESTRATION_WS_METHODS.dispatchCommand](command),
|
|
100
85
|
);
|
|
101
86
|
});
|
|
102
87
|
const getServerConfig = Effect.fn("T3OrchestrationLive.getServerConfig")(function* () {
|
|
@@ -126,7 +111,7 @@ export const makeT3Orchestration = Effect.fn("makeT3Orchestration")(function* ()
|
|
|
126
111
|
) {
|
|
127
112
|
const item = yield* Stream.runHead(
|
|
128
113
|
subscribeRpc(rpc, ORCHESTRATION_WS_METHODS.subscribeThread, (client) =>
|
|
129
|
-
client[ORCHESTRATION_WS_METHODS.subscribeThread]({ threadId }),
|
|
114
|
+
client[ORCHESTRATION_WS_METHODS.subscribeThread]({ threadId: ThreadId.make(threadId) }),
|
|
130
115
|
),
|
|
131
116
|
);
|
|
132
117
|
const value = Option.getOrUndefined(item);
|
|
@@ -144,17 +129,17 @@ export const makeT3Orchestration = Effect.fn("makeT3Orchestration")(function* ()
|
|
|
144
129
|
subscribeRpc(rpc, ORCHESTRATION_WS_METHODS.subscribeShell, (client) =>
|
|
145
130
|
client[ORCHESTRATION_WS_METHODS.subscribeShell]({}),
|
|
146
131
|
).pipe(
|
|
147
|
-
Stream.map((item:
|
|
132
|
+
Stream.map((item: OrchestrationShellStreamItem) =>
|
|
148
133
|
item.kind === "snapshot" ? item.snapshot.snapshotSequence : item.sequence,
|
|
149
134
|
),
|
|
150
135
|
);
|
|
151
136
|
const watchThreadItems = (threadId: string) =>
|
|
152
137
|
subscribeRpc(rpc, ORCHESTRATION_WS_METHODS.subscribeThread, (client) =>
|
|
153
|
-
client[ORCHESTRATION_WS_METHODS.subscribeThread]({ threadId }),
|
|
138
|
+
client[ORCHESTRATION_WS_METHODS.subscribeThread]({ threadId: ThreadId.make(threadId) }),
|
|
154
139
|
);
|
|
155
140
|
const openThread = Effect.fn("T3OrchestrationLive.openThread")(function* (threadId: string) {
|
|
156
141
|
return yield* watchThreadItems(threadId).pipe(
|
|
157
|
-
Stream.peel(Sink.head<
|
|
142
|
+
Stream.peel(Sink.head<OrchestrationThreadStreamItem>()),
|
|
158
143
|
Effect.flatMap(([item, rest]) => {
|
|
159
144
|
const value = Option.getOrUndefined(item);
|
|
160
145
|
if (value === undefined || value.kind !== "snapshot") {
|
|
@@ -169,7 +154,7 @@ export const makeT3Orchestration = Effect.fn("makeT3Orchestration")(function* ()
|
|
|
169
154
|
snapshot: value.snapshot.thread,
|
|
170
155
|
events: rest.pipe(
|
|
171
156
|
Stream.filter(
|
|
172
|
-
(next): next is Extract<
|
|
157
|
+
(next): next is Extract<OrchestrationThreadStreamItem, { readonly kind: "event" }> =>
|
|
173
158
|
next.kind === "event",
|
|
174
159
|
),
|
|
175
160
|
Stream.map((next) => next.event),
|
|
@@ -191,3 +176,11 @@ export const makeT3Orchestration = Effect.fn("makeT3Orchestration")(function* ()
|
|
|
191
176
|
});
|
|
192
177
|
|
|
193
178
|
export const T3OrchestrationLive = Layer.effect(T3Orchestration, makeT3Orchestration());
|
|
179
|
+
|
|
180
|
+
function toRpcRequestError(error: RpcRequestError, method: string) {
|
|
181
|
+
return new RpcError({
|
|
182
|
+
message: error.message,
|
|
183
|
+
method,
|
|
184
|
+
cause: error,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
@@ -2,33 +2,42 @@ import * as Context from "effect/Context";
|
|
|
2
2
|
import type * as Effect from "effect/Effect";
|
|
3
3
|
import type * as Scope from "effect/Scope";
|
|
4
4
|
import type * as Stream from "effect/Stream";
|
|
5
|
+
import type {
|
|
6
|
+
ClientOrchestrationCommand,
|
|
7
|
+
DispatchResult,
|
|
8
|
+
OrchestrationEvent,
|
|
9
|
+
OrchestrationShellSnapshot,
|
|
10
|
+
OrchestrationThread,
|
|
11
|
+
OrchestrationThreadStreamItem,
|
|
12
|
+
ServerProviders,
|
|
13
|
+
} from "@t3tools/contracts";
|
|
5
14
|
|
|
6
|
-
import type { ClientOrchestrationCommand, DispatchResult } from "../domain/command-schema.ts";
|
|
7
|
-
import type { ServerConfig, ShellSnapshot, ThreadDetail, ThreadEvent } from "../domain/schema.ts";
|
|
8
15
|
import type { RpcError } from "../rpc/error.ts";
|
|
9
16
|
|
|
10
17
|
export type OrchestrationError = RpcError;
|
|
11
18
|
|
|
12
19
|
export type OpenThread = {
|
|
13
|
-
readonly snapshot:
|
|
14
|
-
readonly events: Stream.Stream<
|
|
20
|
+
readonly snapshot: OrchestrationThread;
|
|
21
|
+
readonly events: Stream.Stream<OrchestrationEvent, OrchestrationError>;
|
|
15
22
|
};
|
|
16
23
|
|
|
17
|
-
export type
|
|
18
|
-
|
|
19
|
-
|
|
24
|
+
export type ServerConfigForCli = {
|
|
25
|
+
readonly providers: ServerProviders;
|
|
26
|
+
};
|
|
20
27
|
|
|
21
28
|
export type Orchestration = {
|
|
22
29
|
readonly dispatch: (
|
|
23
30
|
command: ClientOrchestrationCommand,
|
|
24
31
|
) => Effect.Effect<DispatchResult, OrchestrationError>;
|
|
25
|
-
readonly getServerConfig: () => Effect.Effect<
|
|
26
|
-
readonly getShellSnapshot: () => Effect.Effect<
|
|
27
|
-
readonly getThreadSnapshot: (
|
|
32
|
+
readonly getServerConfig: () => Effect.Effect<ServerConfigForCli, OrchestrationError>;
|
|
33
|
+
readonly getShellSnapshot: () => Effect.Effect<OrchestrationShellSnapshot, OrchestrationError>;
|
|
34
|
+
readonly getThreadSnapshot: (
|
|
35
|
+
threadId: string,
|
|
36
|
+
) => Effect.Effect<OrchestrationThread, OrchestrationError>;
|
|
28
37
|
readonly watchShellSequence: () => Stream.Stream<number, OrchestrationError, Scope.Scope>;
|
|
29
38
|
readonly watchThreadItems: (
|
|
30
39
|
threadId: string,
|
|
31
|
-
) => Stream.Stream<
|
|
40
|
+
) => Stream.Stream<OrchestrationThreadStreamItem, OrchestrationError, Scope.Scope>;
|
|
32
41
|
readonly openThread: (
|
|
33
42
|
threadId: string,
|
|
34
43
|
) => Effect.Effect<OpenThread, OrchestrationError, Scope.Scope>;
|
package/src/rpc/error.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import * as Schema from "effect/Schema";
|
|
2
|
+
import {
|
|
3
|
+
EnvironmentAuthorizationError,
|
|
4
|
+
KeybindingsConfigError,
|
|
5
|
+
OrchestrationDispatchCommandError,
|
|
6
|
+
OrchestrationGetSnapshotError,
|
|
7
|
+
ServerSettingsError,
|
|
8
|
+
} from "@t3tools/contracts";
|
|
2
9
|
import { HttpClientError } from "effect/unstable/http";
|
|
3
10
|
import { RpcClientError } from "effect/unstable/rpc";
|
|
4
11
|
|
|
@@ -12,6 +19,11 @@ import { ConfigError, UrlError } from "../config/error.ts";
|
|
|
12
19
|
|
|
13
20
|
const RpcErrorCauseSchema = Schema.Union([
|
|
14
21
|
RpcClientError.RpcClientError,
|
|
22
|
+
EnvironmentAuthorizationError,
|
|
23
|
+
KeybindingsConfigError,
|
|
24
|
+
OrchestrationDispatchCommandError,
|
|
25
|
+
OrchestrationGetSnapshotError,
|
|
26
|
+
ServerSettingsError,
|
|
15
27
|
AuthConfigError,
|
|
16
28
|
AuthLocalError,
|
|
17
29
|
AuthPairingUrlError,
|
package/src/rpc/layer.ts
CHANGED
|
@@ -14,11 +14,11 @@ import * as Socket from "effect/unstable/socket/Socket";
|
|
|
14
14
|
import { T3Auth } from "../auth/service.ts";
|
|
15
15
|
import { T3Config } from "../config/service.ts";
|
|
16
16
|
import { toWebSocketBaseUrl } from "../config/url.ts";
|
|
17
|
-
import {
|
|
17
|
+
import { CliWsRpcGroup } from "./ws-group.ts";
|
|
18
18
|
import { RpcError } from "./error.ts";
|
|
19
19
|
import { T3Rpc, type WsClient } from "./service.ts";
|
|
20
20
|
|
|
21
|
-
const makeClient = RpcClient.make(
|
|
21
|
+
const makeClient = RpcClient.make(CliWsRpcGroup);
|
|
22
22
|
const connectionRetrySchedule = Schedule.exponential("100 millis").pipe(Schedule.take(4));
|
|
23
23
|
|
|
24
24
|
type Connection = {
|
package/src/rpc/service.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import * as Context from "effect/Context";
|
|
2
2
|
import type * as Effect from "effect/Effect";
|
|
3
3
|
import type { RpcClient, RpcClientError } from "effect/unstable/rpc";
|
|
4
|
-
|
|
5
|
-
import type { WsRpcGroup } from "../protocol/schema.ts";
|
|
4
|
+
import type { CliWsRpcGroup } from "./ws-group.ts";
|
|
6
5
|
import type { RpcError } from "./error.ts";
|
|
7
6
|
|
|
8
|
-
export type WsClient = RpcClient.FromGroup<typeof
|
|
7
|
+
export type WsClient = RpcClient.FromGroup<typeof CliWsRpcGroup, RpcClientError.RpcClientError>;
|
|
9
8
|
|
|
10
9
|
export type T3RpcService = {
|
|
11
10
|
readonly getClient: Effect.Effect<WsClient, RpcError>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EnvironmentAuthorizationError,
|
|
3
|
+
KeybindingsConfigError,
|
|
4
|
+
OrchestrationDispatchCommandError,
|
|
5
|
+
OrchestrationGetSnapshotError,
|
|
6
|
+
ServerConfig,
|
|
7
|
+
ServerProviders,
|
|
8
|
+
ServerSettingsError,
|
|
9
|
+
WS_METHODS,
|
|
10
|
+
WsOrchestrationDispatchCommandRpc,
|
|
11
|
+
WsOrchestrationSubscribeShellRpc,
|
|
12
|
+
WsOrchestrationSubscribeThreadRpc,
|
|
13
|
+
} from "@t3tools/contracts";
|
|
14
|
+
import * as Schema from "effect/Schema";
|
|
15
|
+
import { Rpc, RpcGroup } from "effect/unstable/rpc";
|
|
16
|
+
|
|
17
|
+
export const FallbackServerConfig = Schema.Struct({
|
|
18
|
+
providers: ServerProviders,
|
|
19
|
+
});
|
|
20
|
+
export type FallbackServerConfig = typeof FallbackServerConfig.Type;
|
|
21
|
+
|
|
22
|
+
export const CliServerConfig = Schema.Union([ServerConfig, FallbackServerConfig]);
|
|
23
|
+
export type CliServerConfig = typeof CliServerConfig.Type;
|
|
24
|
+
|
|
25
|
+
export const WsServerGetConfigRpc = Rpc.make(WS_METHODS.serverGetConfig, {
|
|
26
|
+
payload: Schema.Struct({}),
|
|
27
|
+
success: CliServerConfig,
|
|
28
|
+
error: Schema.Union([KeybindingsConfigError, ServerSettingsError, EnvironmentAuthorizationError]),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const CliWsRpcGroup = RpcGroup.make(
|
|
32
|
+
WsOrchestrationDispatchCommandRpc,
|
|
33
|
+
WsOrchestrationSubscribeShellRpc,
|
|
34
|
+
WsOrchestrationSubscribeThreadRpc,
|
|
35
|
+
WsServerGetConfigRpc,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
export type CliRpcRequestError =
|
|
39
|
+
| EnvironmentAuthorizationError
|
|
40
|
+
| KeybindingsConfigError
|
|
41
|
+
| OrchestrationDispatchCommandError
|
|
42
|
+
| OrchestrationGetSnapshotError
|
|
43
|
+
| ServerSettingsError;
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import * as Schema from "effect/Schema";
|
|
2
|
-
|
|
3
|
-
import { ModelSelectionSchema } from "./schema.ts";
|
|
4
|
-
|
|
5
|
-
export const DispatchResultSchema = Schema.Struct({
|
|
6
|
-
sequence: Schema.Number,
|
|
7
|
-
});
|
|
8
|
-
export type DispatchResult = typeof DispatchResultSchema.Type;
|
|
9
|
-
|
|
10
|
-
export const ProjectCreateCommandSchema = Schema.Struct({
|
|
11
|
-
type: Schema.Literal("project.create"),
|
|
12
|
-
commandId: Schema.String,
|
|
13
|
-
projectId: Schema.String,
|
|
14
|
-
title: Schema.String,
|
|
15
|
-
workspaceRoot: Schema.String,
|
|
16
|
-
createdAt: Schema.String,
|
|
17
|
-
});
|
|
18
|
-
export type ProjectCreateCommand = typeof ProjectCreateCommandSchema.Type;
|
|
19
|
-
|
|
20
|
-
export const ThreadCreateCommandSchema = Schema.Struct({
|
|
21
|
-
type: Schema.Literal("thread.create"),
|
|
22
|
-
commandId: Schema.String,
|
|
23
|
-
threadId: Schema.String,
|
|
24
|
-
projectId: Schema.String,
|
|
25
|
-
title: Schema.String,
|
|
26
|
-
modelSelection: ModelSelectionSchema,
|
|
27
|
-
runtimeMode: Schema.Literal("full-access"),
|
|
28
|
-
interactionMode: Schema.Literal("default"),
|
|
29
|
-
branch: Schema.Null,
|
|
30
|
-
worktreePath: Schema.NullOr(Schema.String),
|
|
31
|
-
createdAt: Schema.String,
|
|
32
|
-
});
|
|
33
|
-
export type ThreadCreateCommand = typeof ThreadCreateCommandSchema.Type;
|
|
34
|
-
|
|
35
|
-
export const ThreadTurnStartCommandSchema = Schema.Struct({
|
|
36
|
-
type: Schema.Literal("thread.turn.start"),
|
|
37
|
-
commandId: Schema.String,
|
|
38
|
-
threadId: Schema.String,
|
|
39
|
-
message: Schema.Struct({
|
|
40
|
-
messageId: Schema.String,
|
|
41
|
-
role: Schema.Literal("user"),
|
|
42
|
-
text: Schema.String,
|
|
43
|
-
attachments: Schema.Array(Schema.Never),
|
|
44
|
-
}),
|
|
45
|
-
modelSelection: Schema.optionalKey(ModelSelectionSchema),
|
|
46
|
-
titleSeed: Schema.optionalKey(Schema.String),
|
|
47
|
-
runtimeMode: Schema.Literal("full-access"),
|
|
48
|
-
interactionMode: Schema.Literal("default"),
|
|
49
|
-
bootstrap: Schema.optionalKey(
|
|
50
|
-
Schema.Struct({
|
|
51
|
-
createThread: Schema.optionalKey(
|
|
52
|
-
Schema.Struct({
|
|
53
|
-
projectId: Schema.String,
|
|
54
|
-
title: Schema.String,
|
|
55
|
-
modelSelection: ModelSelectionSchema,
|
|
56
|
-
runtimeMode: Schema.Literal("full-access"),
|
|
57
|
-
interactionMode: Schema.Literal("default"),
|
|
58
|
-
branch: Schema.Null,
|
|
59
|
-
worktreePath: Schema.NullOr(Schema.String),
|
|
60
|
-
createdAt: Schema.String,
|
|
61
|
-
}),
|
|
62
|
-
),
|
|
63
|
-
}),
|
|
64
|
-
),
|
|
65
|
-
createdAt: Schema.String,
|
|
66
|
-
});
|
|
67
|
-
export type ThreadTurnStartCommand = typeof ThreadTurnStartCommandSchema.Type;
|
|
68
|
-
|
|
69
|
-
export const ThreadArchiveCommandSchema = Schema.Struct({
|
|
70
|
-
type: Schema.Literal("thread.archive"),
|
|
71
|
-
commandId: Schema.String,
|
|
72
|
-
threadId: Schema.String,
|
|
73
|
-
});
|
|
74
|
-
export type ThreadArchiveCommand = typeof ThreadArchiveCommandSchema.Type;
|
|
75
|
-
|
|
76
|
-
export const ClientOrchestrationCommandSchema = Schema.Union([
|
|
77
|
-
ProjectCreateCommandSchema,
|
|
78
|
-
ThreadArchiveCommandSchema,
|
|
79
|
-
ThreadCreateCommandSchema,
|
|
80
|
-
ThreadTurnStartCommandSchema,
|
|
81
|
-
]);
|
|
82
|
-
export type ClientOrchestrationCommand = typeof ClientOrchestrationCommandSchema.Type;
|
package/src/domain/schema.ts
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import * as Schema from "effect/Schema";
|
|
2
|
-
|
|
3
|
-
export type Format = "human" | "json" | "ndjson";
|
|
4
|
-
|
|
5
|
-
export const FormatSchema = Schema.Literals(["human", "json", "ndjson"]);
|
|
6
|
-
|
|
7
|
-
export const ModelSelectionSchema = Schema.Struct({
|
|
8
|
-
instanceId: Schema.String,
|
|
9
|
-
model: Schema.String,
|
|
10
|
-
options: Schema.optionalKey(
|
|
11
|
-
Schema.Array(
|
|
12
|
-
Schema.Struct({
|
|
13
|
-
id: Schema.String,
|
|
14
|
-
value: Schema.Unknown,
|
|
15
|
-
}),
|
|
16
|
-
),
|
|
17
|
-
),
|
|
18
|
-
});
|
|
19
|
-
export type ModelSelection = typeof ModelSelectionSchema.Type;
|
|
20
|
-
|
|
21
|
-
export const ProjectShellSchema = Schema.Struct({
|
|
22
|
-
id: Schema.String,
|
|
23
|
-
title: Schema.String,
|
|
24
|
-
workspaceRoot: Schema.String,
|
|
25
|
-
defaultModelSelection: Schema.NullOr(ModelSelectionSchema),
|
|
26
|
-
createdAt: Schema.String,
|
|
27
|
-
updatedAt: Schema.String,
|
|
28
|
-
});
|
|
29
|
-
export type ProjectShell = typeof ProjectShellSchema.Type;
|
|
30
|
-
|
|
31
|
-
export const ThreadMessageSchema = Schema.Struct({
|
|
32
|
-
id: Schema.optionalKey(Schema.String),
|
|
33
|
-
messageId: Schema.optionalKey(Schema.String),
|
|
34
|
-
role: Schema.Literals(["user", "assistant", "system"]),
|
|
35
|
-
text: Schema.String,
|
|
36
|
-
streaming: Schema.optionalKey(Schema.Boolean),
|
|
37
|
-
turnId: Schema.optionalKey(Schema.NullOr(Schema.String)),
|
|
38
|
-
createdAt: Schema.String,
|
|
39
|
-
updatedAt: Schema.String,
|
|
40
|
-
});
|
|
41
|
-
export type ThreadMessage = typeof ThreadMessageSchema.Type;
|
|
42
|
-
|
|
43
|
-
export const ThreadSessionSchema = Schema.Struct({
|
|
44
|
-
threadId: Schema.String,
|
|
45
|
-
status: Schema.Literals([
|
|
46
|
-
"idle",
|
|
47
|
-
"starting",
|
|
48
|
-
"running",
|
|
49
|
-
"ready",
|
|
50
|
-
"interrupted",
|
|
51
|
-
"stopped",
|
|
52
|
-
"error",
|
|
53
|
-
]),
|
|
54
|
-
lastError: Schema.NullOr(Schema.String),
|
|
55
|
-
updatedAt: Schema.String,
|
|
56
|
-
});
|
|
57
|
-
export type ThreadSession = typeof ThreadSessionSchema.Type;
|
|
58
|
-
|
|
59
|
-
export const ThreadShellSchema = Schema.Struct({
|
|
60
|
-
id: Schema.String,
|
|
61
|
-
projectId: Schema.String,
|
|
62
|
-
title: Schema.String,
|
|
63
|
-
modelSelection: ModelSelectionSchema,
|
|
64
|
-
runtimeMode: Schema.String,
|
|
65
|
-
interactionMode: Schema.String,
|
|
66
|
-
branch: Schema.NullOr(Schema.String),
|
|
67
|
-
worktreePath: Schema.NullOr(Schema.String),
|
|
68
|
-
latestTurn: Schema.NullOr(Schema.Struct({ state: Schema.String })),
|
|
69
|
-
createdAt: Schema.String,
|
|
70
|
-
updatedAt: Schema.String,
|
|
71
|
-
session: Schema.NullOr(ThreadSessionSchema),
|
|
72
|
-
latestUserMessageAt: Schema.optionalKey(Schema.NullOr(Schema.String)),
|
|
73
|
-
});
|
|
74
|
-
export type ThreadShell = typeof ThreadShellSchema.Type;
|
|
75
|
-
|
|
76
|
-
export const ThreadDetailSchema = Schema.Struct({
|
|
77
|
-
id: Schema.String,
|
|
78
|
-
projectId: Schema.String,
|
|
79
|
-
title: Schema.String,
|
|
80
|
-
modelSelection: ModelSelectionSchema,
|
|
81
|
-
runtimeMode: Schema.String,
|
|
82
|
-
interactionMode: Schema.String,
|
|
83
|
-
branch: Schema.NullOr(Schema.String),
|
|
84
|
-
worktreePath: Schema.NullOr(Schema.String),
|
|
85
|
-
latestTurn: Schema.NullOr(Schema.Struct({ state: Schema.String })),
|
|
86
|
-
createdAt: Schema.String,
|
|
87
|
-
updatedAt: Schema.String,
|
|
88
|
-
session: Schema.NullOr(ThreadSessionSchema),
|
|
89
|
-
latestUserMessageAt: Schema.optionalKey(Schema.NullOr(Schema.String)),
|
|
90
|
-
messages: Schema.Array(ThreadMessageSchema),
|
|
91
|
-
activities: Schema.optionalKey(Schema.Array(Schema.Unknown)),
|
|
92
|
-
});
|
|
93
|
-
export type ThreadDetail = typeof ThreadDetailSchema.Type;
|
|
94
|
-
|
|
95
|
-
export const ShellSnapshotSchema = Schema.Struct({
|
|
96
|
-
snapshotSequence: Schema.Number,
|
|
97
|
-
projects: Schema.Array(ProjectShellSchema),
|
|
98
|
-
threads: Schema.Array(ThreadShellSchema),
|
|
99
|
-
updatedAt: Schema.String,
|
|
100
|
-
});
|
|
101
|
-
export type ShellSnapshot = typeof ShellSnapshotSchema.Type;
|
|
102
|
-
|
|
103
|
-
export const ServerProviderSchema = Schema.Struct({
|
|
104
|
-
instanceId: Schema.String,
|
|
105
|
-
displayName: Schema.optionalKey(Schema.String),
|
|
106
|
-
enabled: Schema.Boolean,
|
|
107
|
-
installed: Schema.Boolean,
|
|
108
|
-
status: Schema.Literals(["ready", "warning", "error", "disabled"]),
|
|
109
|
-
auth: Schema.Struct({
|
|
110
|
-
status: Schema.Literals(["authenticated", "unauthenticated", "unknown"]),
|
|
111
|
-
}),
|
|
112
|
-
models: Schema.Array(
|
|
113
|
-
Schema.Struct({
|
|
114
|
-
slug: Schema.String,
|
|
115
|
-
name: Schema.String,
|
|
116
|
-
}),
|
|
117
|
-
),
|
|
118
|
-
});
|
|
119
|
-
export type ServerProvider = typeof ServerProviderSchema.Type;
|
|
120
|
-
export type ServerProviderModel = NonNullable<ServerProvider["models"]>[number];
|
|
121
|
-
|
|
122
|
-
export const ServerConfigSchema = Schema.Struct({
|
|
123
|
-
providers: Schema.optionalKey(Schema.Array(ServerProviderSchema)),
|
|
124
|
-
});
|
|
125
|
-
export type ServerConfig = typeof ServerConfigSchema.Type;
|
|
126
|
-
|
|
127
|
-
export const ThreadMessageSentEventSchema = Schema.Struct({
|
|
128
|
-
type: Schema.Literal("thread.message-sent"),
|
|
129
|
-
payload: Schema.Struct({
|
|
130
|
-
messageId: Schema.String,
|
|
131
|
-
role: Schema.Literals(["user", "assistant", "system"]),
|
|
132
|
-
text: Schema.String,
|
|
133
|
-
turnId: Schema.NullOr(Schema.String),
|
|
134
|
-
streaming: Schema.optionalKey(Schema.Boolean),
|
|
135
|
-
createdAt: Schema.String,
|
|
136
|
-
updatedAt: Schema.String,
|
|
137
|
-
}),
|
|
138
|
-
});
|
|
139
|
-
export type ThreadMessageSentEvent = typeof ThreadMessageSentEventSchema.Type;
|
|
140
|
-
|
|
141
|
-
export const ThreadSessionSetEventSchema = Schema.Struct({
|
|
142
|
-
type: Schema.Literal("thread.session-set"),
|
|
143
|
-
payload: Schema.Struct({
|
|
144
|
-
session: Schema.NullOr(ThreadSessionSchema),
|
|
145
|
-
}),
|
|
146
|
-
});
|
|
147
|
-
export type ThreadSessionSetEvent = typeof ThreadSessionSetEventSchema.Type;
|
|
148
|
-
|
|
149
|
-
export const UnknownThreadEventSchema = Schema.Struct({
|
|
150
|
-
type: Schema.String,
|
|
151
|
-
payload: Schema.Record(Schema.String, Schema.Unknown),
|
|
152
|
-
});
|
|
153
|
-
export type UnknownThreadEvent = typeof UnknownThreadEventSchema.Type;
|
|
154
|
-
|
|
155
|
-
export const ThreadEventSchema = Schema.Union([
|
|
156
|
-
ThreadMessageSentEventSchema,
|
|
157
|
-
ThreadSessionSetEventSchema,
|
|
158
|
-
UnknownThreadEventSchema,
|
|
159
|
-
]);
|
|
160
|
-
export type ThreadEvent = typeof ThreadEventSchema.Type;
|
|
161
|
-
|
|
162
|
-
export const decodeModelSelection = Schema.decodeUnknownSync(ModelSelectionSchema);
|
package/src/protocol/schema.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import * as Schema from "effect/Schema";
|
|
2
|
-
import { Rpc, RpcGroup } from "effect/unstable/rpc";
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
ClientOrchestrationCommandSchema,
|
|
6
|
-
DispatchResultSchema,
|
|
7
|
-
} from "../domain/command-schema.ts";
|
|
8
|
-
import {
|
|
9
|
-
ProjectShellSchema,
|
|
10
|
-
ServerConfigSchema,
|
|
11
|
-
ShellSnapshotSchema,
|
|
12
|
-
ThreadDetailSchema,
|
|
13
|
-
ThreadEventSchema,
|
|
14
|
-
ThreadShellSchema,
|
|
15
|
-
} from "../domain/schema.ts";
|
|
16
|
-
import { RpcError } from "../rpc/error.ts";
|
|
17
|
-
|
|
18
|
-
export const ORCHESTRATION_WS_METHODS = {
|
|
19
|
-
dispatchCommand: "orchestration.dispatchCommand",
|
|
20
|
-
subscribeShell: "orchestration.subscribeShell",
|
|
21
|
-
subscribeThread: "orchestration.subscribeThread",
|
|
22
|
-
} as const;
|
|
23
|
-
|
|
24
|
-
export const WS_METHODS = {
|
|
25
|
-
serverGetConfig: "server.getConfig",
|
|
26
|
-
} as const;
|
|
27
|
-
|
|
28
|
-
export const ThreadStreamItemSchema = Schema.Union([
|
|
29
|
-
Schema.Struct({
|
|
30
|
-
kind: Schema.Literal("snapshot"),
|
|
31
|
-
snapshot: Schema.Struct({ thread: ThreadDetailSchema }),
|
|
32
|
-
}),
|
|
33
|
-
Schema.Struct({
|
|
34
|
-
kind: Schema.Literal("event"),
|
|
35
|
-
event: ThreadEventSchema,
|
|
36
|
-
}),
|
|
37
|
-
]);
|
|
38
|
-
export type ThreadStreamItem = typeof ThreadStreamItemSchema.Type;
|
|
39
|
-
|
|
40
|
-
export const ShellStreamItemSchema = Schema.Union([
|
|
41
|
-
Schema.Struct({
|
|
42
|
-
kind: Schema.Literal("snapshot"),
|
|
43
|
-
snapshot: ShellSnapshotSchema,
|
|
44
|
-
}),
|
|
45
|
-
Schema.Struct({
|
|
46
|
-
kind: Schema.Literal("project-upserted"),
|
|
47
|
-
sequence: Schema.Number,
|
|
48
|
-
project: ProjectShellSchema,
|
|
49
|
-
}),
|
|
50
|
-
Schema.Struct({
|
|
51
|
-
kind: Schema.Literal("project-removed"),
|
|
52
|
-
sequence: Schema.Number,
|
|
53
|
-
projectId: Schema.String,
|
|
54
|
-
}),
|
|
55
|
-
Schema.Struct({
|
|
56
|
-
kind: Schema.Literal("thread-upserted"),
|
|
57
|
-
sequence: Schema.Number,
|
|
58
|
-
thread: ThreadShellSchema,
|
|
59
|
-
}),
|
|
60
|
-
Schema.Struct({
|
|
61
|
-
kind: Schema.Literal("thread-removed"),
|
|
62
|
-
sequence: Schema.Number,
|
|
63
|
-
threadId: Schema.String,
|
|
64
|
-
}),
|
|
65
|
-
]);
|
|
66
|
-
export type ShellStreamItem = typeof ShellStreamItemSchema.Type;
|
|
67
|
-
|
|
68
|
-
export const WsOrchestrationDispatchCommandRpc = Rpc.make(
|
|
69
|
-
ORCHESTRATION_WS_METHODS.dispatchCommand,
|
|
70
|
-
{
|
|
71
|
-
payload: ClientOrchestrationCommandSchema,
|
|
72
|
-
success: DispatchResultSchema,
|
|
73
|
-
error: RpcError,
|
|
74
|
-
},
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
export const WsOrchestrationSubscribeShellRpc = Rpc.make(ORCHESTRATION_WS_METHODS.subscribeShell, {
|
|
78
|
-
payload: Schema.Struct({}),
|
|
79
|
-
success: ShellStreamItemSchema,
|
|
80
|
-
error: RpcError,
|
|
81
|
-
stream: true,
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
export const WsOrchestrationSubscribeThreadRpc = Rpc.make(
|
|
85
|
-
ORCHESTRATION_WS_METHODS.subscribeThread,
|
|
86
|
-
{
|
|
87
|
-
payload: Schema.Struct({ threadId: Schema.String }),
|
|
88
|
-
success: ThreadStreamItemSchema,
|
|
89
|
-
error: RpcError,
|
|
90
|
-
stream: true,
|
|
91
|
-
},
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
export const WsServerGetConfigRpc = Rpc.make(WS_METHODS.serverGetConfig, {
|
|
95
|
-
payload: Schema.Struct({}),
|
|
96
|
-
success: ServerConfigSchema,
|
|
97
|
-
error: RpcError,
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
export const WsRpcGroup = RpcGroup.make(
|
|
101
|
-
WsOrchestrationDispatchCommandRpc,
|
|
102
|
-
WsOrchestrationSubscribeShellRpc,
|
|
103
|
-
WsOrchestrationSubscribeThreadRpc,
|
|
104
|
-
WsServerGetConfigRpc,
|
|
105
|
-
);
|