Skip to content

Commit 3bba438

Browse files
chore(deps): upgrade Effect to beta.103
- Migrate schema and HTTP APIs to the new Effect release - Enable built-in HTTP and WebSocket compression - Update MCP transport to protocol 2025-06-18
1 parent 966cc05 commit 3bba438

44 files changed

Lines changed: 383 additions & 597 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/desktop/src/preview/Manager.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const DIAGNOSTIC_BUFFER_LIMIT = 200;
109109
const MAX_ARTIFACT_SITE_SLUG_LENGTH = 80;
110110
const AGENT_CURSOR_MOVE_MS = 160;
111111
const AGENT_CURSOR_CLICK_LEAD_MS = 40;
112-
const encodeUnknownJson = Schema.encodeUnknownEffect(Schema.UnknownFromJsonString);
112+
const encodeUnknownJson = Schema.encodeUnknownEffect(Schema.fromJsonString(Schema.Unknown));
113113
const DEFAULT_ANNOTATION_THEME: DesktopPreviewAnnotationTheme = {
114114
colorScheme: "light",
115115
radius: "0.625rem",

‎apps/desktop/src/preview/PlaywrightInjectedRuntime.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as Effect from "effect/Effect";
88
import * as Schema from "effect/Schema";
99

1010
const require = NodeModule.createRequire(import.meta.url);
11-
const encodeUnknownJson = Schema.encodeUnknownEffect(Schema.UnknownFromJsonString);
11+
const encodeUnknownJson = Schema.encodeUnknownEffect(Schema.fromJsonString(Schema.Unknown));
1212
const PLAYWRIGHT_PACKAGE_SPECIFIER = "playwright-core/package.json";
1313
const PLAYWRIGHT_SOURCE_MARKER = "source3 = ";
1414
const PLAYWRIGHT_SOURCE_TERMINATOR = ";\n }\n});";

‎apps/server/src/cli/config.test.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @effect-diagnostics nodeBuiltinImport:off
2+
import * as NodeFS from "node:fs";
13
import * as NodeOS from "node:os";
24

35
import { assert, expect, it } from "@effect/vitest";
@@ -56,8 +58,10 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
5658
const filePath = yield* fs.makeTempFileScoped({ prefix: "t3-bootstrap-", suffix: ".ndjson" });
5759
const encoded = yield* encodeDesktopBootstrap(payload);
5860
yield* fs.writeFileString(filePath, `${encoded}\n`);
59-
const { fd } = yield* fs.open(filePath, { flag: "r" });
60-
return fd;
61+
return yield* Effect.acquireRelease(
62+
Effect.sync(() => NodeFS.openSync(filePath, "r")),
63+
(fd) => Effect.sync(() => NodeFS.closeSync(fd)),
64+
);
6165
});
6266

6367
it.effect("falls back to effect/config values when flags are omitted", () =>

‎apps/server/src/cli/config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ export const DurationFromString = Schema.String.pipe(
466466
return Effect.succeed(duration);
467467
}
468468
return Effect.fail(
469-
new SchemaIssue.InvalidValue(Option.some(value), {
469+
new SchemaIssue.InvalidValue({
470470
message: "Invalid duration. Use values like 5m, 1h, 30d, or 15 minutes.",
471471
}),
472472
);

‎apps/server/src/cloud/publicConfig.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { normalizeSecureRelayUrl } from "@t3tools/shared/relayUrl";
44
import * as Config from "effect/Config";
55
import * as ConfigProvider from "effect/ConfigProvider";
66
import * as Effect from "effect/Effect";
7-
import * as Option from "effect/Option";
87
import * as Schema from "effect/Schema";
98
import * as SchemaIssue from "effect/SchemaIssue";
109

@@ -24,7 +23,7 @@ function validateRelayUrl(value: string) {
2423
? Effect.fail(
2524
new Config.ConfigError(
2625
new Schema.SchemaError(
27-
new SchemaIssue.InvalidValue(Option.some(value), {
26+
new SchemaIssue.InvalidValue({
2827
message: "Relay URL must be a secure absolute HTTPS origin.",
2928
}),
3029
),
@@ -130,7 +129,7 @@ function validateHostedAppUrl(value: string) {
130129
return Effect.fail(
131130
new Config.ConfigError(
132131
new Schema.SchemaError(
133-
new SchemaIssue.InvalidValue(Option.some(value), {
132+
new SchemaIssue.InvalidValue({
134133
message: "Hosted app URL must be an absolute HTTPS origin (or HTTP loopback origin).",
135134
}),
136135
),

‎apps/server/src/http.ts‎

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import * as Option from "effect/Option";
1414
import * as Path from "effect/Path";
1515
import { cast } from "effect/Function";
1616
import {
17-
Headers,
1817
HttpBody,
1918
HttpClient,
2019
HttpClientResponse,
20+
HttpMiddleware,
2121
HttpRouter,
2222
HttpServerResponse,
2323
HttpServerRequest,
@@ -30,7 +30,6 @@ import * as ServerConfig from "./config.ts";
3030
import { ASSET_ROUTE_PREFIX, resolveAsset } from "./assets/AssetAccess.ts";
3131
import * as BrowserTraceCollector from "./observability/BrowserTraceCollector.ts";
3232
import * as EnvironmentAuth from "./auth/EnvironmentAuth.ts";
33-
import * as HttpResponseCompression from "./httpCompression/HttpResponseCompression.ts";
3433
import { traceRelayRequest } from "./cloud/traceRelayRequest.ts";
3534
import {
3635
annotateEnvironmentRequest,
@@ -44,74 +43,10 @@ import { browserApiCorsAllowedHeaders, browserApiCorsAllowedMethods } from "./ht
4443
const OTLP_TRACES_PROXY_PATH = "/api/observability/v1/traces";
4544
const LOOPBACK_HOSTNAMES = new Set(["127.0.0.1", "::1", "localhost"]);
4645
const DESKTOP_RENDERER_ORIGINS = ["t3code://app", "t3code-dev://app"];
47-
const GZIP_MIN_BYTES = 1024;
48-
49-
function acceptsGzip(value: string | undefined): boolean {
50-
if (!value) return false;
51-
52-
const accepted = new Map(
53-
value.split(",").map((entry) => {
54-
const [coding = "", ...parameters] = entry.trim().toLowerCase().split(";");
55-
const quality = parameters
56-
.map((parameter) => parameter.trim().match(/^q=(.+)$/)?.[1])
57-
.find((parameter) => parameter !== undefined);
58-
return [coding, quality === undefined ? 1 : Number(quality)] as const;
59-
}),
60-
);
61-
return (accepted.get("gzip") ?? accepted.get("*") ?? 0) > 0;
62-
}
63-
64-
function varyByAcceptEncoding(value: string | undefined): string {
65-
if (!value) return "Accept-Encoding";
66-
const values = new Set(value.split(",").map((entry) => entry.trim().toLowerCase()));
67-
return values.has("*") || values.has("accept-encoding") ? value : `${value}, Accept-Encoding`;
68-
}
69-
70-
const compressHttpResponse = Effect.fnUntraced(function* (
71-
response: HttpServerResponse.HttpServerResponse,
72-
acceptEncoding: string | undefined,
73-
) {
74-
const body = response.body;
75-
if (
76-
body._tag !== "Uint8Array" ||
77-
body.contentLength < GZIP_MIN_BYTES ||
78-
!body.contentType.startsWith("application/json") ||
79-
response.headers["content-encoding"]
80-
) {
81-
return response;
82-
}
83-
84-
const variedResponse = HttpServerResponse.setHeader(
85-
response,
86-
"vary",
87-
varyByAcceptEncoding(response.headers.vary),
88-
);
89-
if (!acceptsGzip(acceptEncoding)) return variedResponse;
90-
91-
const compression = yield* HttpResponseCompression.HttpResponseCompression;
92-
const headers = Headers.set(
93-
Headers.remove(variedResponse.headers, "content-length"),
94-
"content-encoding",
95-
"gzip",
96-
);
97-
return compression.gzip(body.body, {
98-
status: response.status,
99-
statusText: response.statusText,
100-
headers,
101-
cookies: response.cookies,
102-
contentType: body.contentType,
103-
});
46+
export const httpCompressionLayer = HttpRouter.middleware(HttpMiddleware.compression(), {
47+
global: true,
10448
});
10549

106-
export const httpCompressionLayer = HttpRouter.middleware(
107-
(httpEffect) =>
108-
Effect.flatMap(
109-
Effect.all([httpEffect, HttpServerRequest.HttpServerRequest]),
110-
([response, request]) => compressHttpResponse(response, request.headers["accept-encoding"]),
111-
),
112-
{ global: true },
113-
);
114-
11550
export const browserApiCorsLayer = Layer.unwrap(
11651
Effect.gen(function* () {
11752
const config = yield* ServerConfig.ServerConfig;

‎apps/server/src/httpCompression/HttpResponseCompression.test.ts‎

Lines changed: 0 additions & 29 deletions
This file was deleted.

‎apps/server/src/httpCompression/HttpResponseCompression.ts‎

Lines changed: 0 additions & 36 deletions
This file was deleted.

‎apps/server/src/keybindings.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import * as Exit from "effect/Exit";
2929
import * as FileSystem from "effect/FileSystem";
3030
import * as Path from "effect/Path";
3131
import * as Layer from "effect/Layer";
32-
import * as Option from "effect/Option";
3332
import * as Predicate from "effect/Predicate";
3433
import * as PubSub from "effect/PubSub";
3534
import * as Result from "effect/Result";
@@ -68,7 +67,7 @@ export const ResolvedKeybindingFromConfig = KeybindingRule.pipe(
6867
Effect.filterOrFail(
6968
Predicate.isNotNull,
7069
() =>
71-
new SchemaIssue.InvalidValue(Option.some(rule), {
70+
new SchemaIssue.InvalidValue({
7271
message: "Invalid keybinding rule",
7372
}),
7473
),
@@ -80,7 +79,7 @@ export const ResolvedKeybindingFromConfig = KeybindingRule.pipe(
8079
const key = encodeShortcut(resolved.shortcut);
8180
if (!key) {
8281
return yield* Effect.fail(
83-
new SchemaIssue.InvalidValue(Option.some(resolved), {
82+
new SchemaIssue.InvalidValue({
8483
message: "Resolved shortcut cannot be encoded to key string",
8584
}),
8685
);

‎apps/server/src/mcp/McpHttpServer.test.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { EnvironmentId, PreviewTabId, ProviderInstanceId, ThreadId } from "@t3to
55
import * as Effect from "effect/Effect";
66
import * as Layer from "effect/Layer";
77
import * as Stream from "effect/Stream";
8-
import { McpSchema, McpServer } from "effect/unstable/ai";
8+
import { McpProtocol, McpSchema, McpServer } from "effect/unstable/ai";
99
import { HttpBody, HttpClient, HttpRouter, HttpServerResponse } from "effect/unstable/http";
1010

1111
import * as McpHttpServer from "./McpHttpServer.ts";
@@ -26,8 +26,9 @@ const invocation = {
2626
};
2727
const client = McpSchema.McpServerClient.of({
2828
clientId: 1,
29+
protocolVersion: "2025-06-18",
2930
initializePayload: {
30-
protocolVersion: "2025-03-26",
31+
protocolVersion: "2025-06-18",
3132
capabilities: {},
3233
clientInfo: { name: "mcp-test", version: "1.0.0" },
3334
},
@@ -103,6 +104,7 @@ it.effect("terminates HTTP MCP sessions with DELETE", () =>
103104
name: "MCP termination test",
104105
version: "1.0.0",
105106
path: "/mcp",
107+
protocols: [McpProtocol.v2025_06_18],
106108
});
107109
yield* HttpRouter.serve(serverLayer, {
108110
disableListenLog: true,
@@ -239,8 +241,9 @@ it.effect("registers annotated tools and preserves authenticated request context
239241
.pipe(
240242
Effect.provideService(McpInvocationContext.McpInvocationContext, invocation),
241243
Effect.provideService(McpSchema.McpServerClient, client),
244+
Effect.flip,
242245
);
243-
expect(malformed.isError).toBe(true);
246+
expect(malformed._tag).toBe("InvalidParams");
244247

245248
const snapshot = yield* server
246249
.callTool({ name: "preview_snapshot", arguments: { tabId: alternateTabId } })

0 commit comments

Comments
 (0)