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

effect@4.0.1.patch

139 lines7.5 KB

1diff --git a/dist/ai/McpServer.js b/dist/ai/McpServer.js
2index 2da594107273980144e84ab9b53636ef34043f6b..9fada51944f58fd0d988ae8f6b18f83e79583a25 100644
3--- a/dist/ai/McpServer.js
4+++ b/dist/ai/McpServer.js
5@@ -1093,7 +1093,7 @@ export const layerHttp = options => {
6 const methodNotAllowed = request => isAllowedMcpOrigin(request, options.allowedOrigins) ? Effect.succeed(methodNotAllowedResponse) : Effect.succeed(HttpServerResponse.empty({
7 status: 403
8 }));
9- const routes = Layer.mergeAll(HttpRouter.add("GET", options.path, methodNotAllowed), HttpRouter.add("PUT", options.path, methodNotAllowed), HttpRouter.add("PATCH", options.path, methodNotAllowed), HttpRouter.add("DELETE", options.path, methodNotAllowed), HttpRouter.add("OPTIONS", options.path, methodNotAllowed));
10+ const routes = Layer.mergeAll(HttpRouter.add("GET", options.path, methodNotAllowed), HttpRouter.add("PUT", options.path, methodNotAllowed), HttpRouter.add("PATCH", options.path, methodNotAllowed), HttpRouter.add("OPTIONS", options.path, methodNotAllowed));
11 return Layer.merge(layerWithRuntime(options, "http"), routes).pipe(Layer.provide(layerMcpProtocolHttp(options)), Layer.provide(runtime), Layer.provide(RpcSerialization.layerJsonRpc()));
12 };
13 const layerMcpProtocolHttp = options => Layer.effect(RpcServer.Protocol)(Effect.gen(function* () {
14@@ -1136,6 +1136,17 @@ const layerMcpProtocolHttp = options => Layer.effect(RpcServer.Protocol)(Effect.
15 }))) : response;
16 });
17 });
18+ yield* router.add("DELETE", options.path, request => {
19+ if (!isAllowedMcpOrigin(request, options.allowedOrigins)) {
20+ return Effect.succeed(HttpServerResponse.empty({
21+ status: 403
22+ }));
23+ }
24+ const sessionId = request.headers[MCP_SESSION_ID_HEADER];
25+ return Effect.succeed(HttpServerResponse.empty({
26+ status: sessionId === undefined ? 400 : runtime.terminateSession(sessionId) ? 204 : 404
27+ }));
28+ });
29 return protocol;
30 }));
31 const mcpHttpSerialization = /*#__PURE__*/(() => {
32diff --git a/dist/ai/internal/mcpRuntime.js b/dist/ai/internal/mcpRuntime.js
33index 06370fd1341ae7a6b681c513a3a3c2866a414b7b..baa945b8b4763b5472c4a900b90b817209caa4bf 100644
34--- a/dist/ai/internal/mcpRuntime.js
35+++ b/dist/ai/internal/mcpRuntime.js
36@@ -336,6 +336,7 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (protocols) {
37 },
38 effectLogLevel: (clientId, headers, fallback) => stateful?.effectLogLevel(clientId, headers, fallback) ?? fallback,
39 disconnect: clientId => stateful?.disconnect(clientId),
40+ terminateSession: sessionId => stateful?.terminateSession(sessionId) ?? false,
41 deliveryClientIds: () => stateful?.initializedClientIds() ?? [],
42 canDeliver: (clientId, headers, notification, fallback) => stateful?.canDeliver(clientId, headers, notification, fallback) ?? true,
43 installHandlers: Effect.fnUntraced(function* (options) {
44diff --git a/dist/ai/internal/mcpStatefulRuntime.js b/dist/ai/internal/mcpStatefulRuntime.js
45index 9471bdfbcff0643b44df3a08c3701f743a299638..455860316ddfccaf98ff95f9f05da500c331869c 100644
46--- a/dist/ai/internal/mcpStatefulRuntime.js
47+++ b/dist/ai/internal/mcpStatefulRuntime.js
48@@ -46,6 +46,7 @@ export const make = () => {
49 },
50 resolve: resolveSession,
51 resolveSessionId: sessionId => bySessionId.get(sessionId),
52+ terminateSession: sessionId => bySessionId.delete(sessionId),
53 setLogLevel: (level, clientId, headers) => Effect.sync(() => {
54 const session = resolveSession(clientId, headers);
55 if (session !== undefined) {
56diff --git a/dist/http/HttpClientResponse.js b/dist/http/HttpClientResponse.js
57index 42fba673de3b6bdc089c305f2e87ad56c3bfc374..2b4981b8a88606fb93d62a29f21f9556803307c4 100644
58--- a/dist/http/HttpClientResponse.js
59+++ b/dist/http/HttpClientResponse.js
60@@ -195,7 +195,7 @@ class WebHttpClientResponse extends Inspectable.Class {
61 if (this.cachedCookies) {
62 return this.cachedCookies;
63 }
64- return this.cachedCookies = Cookies.fromSetCookie(this.source.headers.getSetCookie());
65+ return this.cachedCookies = Cookies.fromSetCookie(this.source.headers.getSetCookie?.() ?? []);
66 }
67 get remoteAddress() {
68 return Option.none();
69diff --git a/dist/rpc/RpcClient.d.ts b/dist/rpc/RpcClient.d.ts
70index c498ff74510b784dcba791dbf6b8f23dac40a71d..8be9c910a8112a5289159251846128cd27cf32aa 100644
71--- a/dist/rpc/RpcClient.d.ts
72+++ b/dist/rpc/RpcClient.d.ts
73@@ -302,6 +302,8 @@ export declare const layerProtocolWorker: (options: {
74 declare const ConnectionHooks_base: Context.ServiceClass<ConnectionHooks, "effect/rpc/RpcClient/ConnectionHooks", {
75 readonly onConnect: Effect.Effect<void>;
76 readonly onDisconnect: Effect.Effect<void>;
77+ /** Runs when the socket is dropped because pongs stopped, before `onDisconnect`. */
78+ readonly onPingTimeout?: Effect.Effect<void> | undefined;
79 }>;
80 /**
81 * Represents optional client protocol hooks that run when a transport connects
82diff --git a/dist/rpc/RpcClient.js b/dist/rpc/RpcClient.js
83index 8af2e2efa9311d582add61fef131fd39fd459ab4..723649f05baa61ac33c9bc3634d106caa9641164 100644
84--- a/dist/rpc/RpcClient.js
85+++ b/dist/rpc/RpcClient.js
86@@ -679,11 +679,11 @@ export const makeProtocolSocket = options => Protocol.make(Effect.fnUntraced(fun
87 yield* processData(frames[i]);
88 }
89 }
90- }).pipe(Effect.scoped, Effect.raceFirst(Effect.flatMap(pinger.timeout, () => Effect.fail(new Socket.SocketError({
91+ }).pipe(Effect.scoped, Effect.raceFirst(Effect.flatMap(pinger.timeout, () => (Option.isSome(hooks) && hooks.value.onPingTimeout ? hooks.value.onPingTimeout : Effect.void).pipe(Effect.andThen(Effect.fail(new Socket.SocketError({
92 reason: new Socket.SocketReadError({
93 cause: new Error("ping timeout")
94 })
95- })))));
96+ })))))));
97 }).pipe(Option.isSome(hooks) ? Effect.ensuring(hooks.value.onDisconnect) : identity, Effect.tapCause(cause => {
98 const error = Cause.findError(cause);
99 const hasError = Result.isSuccess(error);
100@@ -726,17 +726,25 @@ export const makeProtocolSocket = options => Protocol.make(Effect.fnUntraced(fun
101 const defaultRetryPolicy = /*#__PURE__*/Schedule.min([/*#__PURE__*/Schedule.exponential(500, 1.5), /*#__PURE__*/Schedule.spaced(5000)]);
102 const makePinger = /*#__PURE__*/Effect.fnUntraced(function* (writePing) {
103 let recievedPong = true;
104+ let missedPongs = 0;
105 const latch = Latch.makeUnsafe();
106 const reset = () => {
107 recievedPong = true;
108+ missedPongs = 0;
109 latch.closeUnsafe();
110 };
111 const onPong = () => {
112 recievedPong = true;
113+ missedPongs = 0;
114 };
115 yield* Effect.suspend(() => {
116- if (!recievedPong) return latch.open;
117+ if (!recievedPong) {
118+ missedPongs += 1;
119+ if (missedPongs >= 3) return latch.open;
120+ return writePing;
121+ }
122 recievedPong = false;
123+ missedPongs = 0;
124 return writePing;
125 }).pipe(Effect.delay("5 seconds"), Effect.ignore, Effect.forever, Effect.interruptible, Effect.forkScoped);
126 return {
127diff --git a/src/http/HttpClientResponse.ts b/src/http/HttpClientResponse.ts
128index c037015185da1e0c664653b5a496832a9449f3c1..a8b0d8be28bbbd3a0d0d3f1a222c2f074d2d3ad5 100644
129--- a/src/http/HttpClientResponse.ts
130+++ b/src/http/HttpClientResponse.ts
131@@ -341,7 +341,7 @@ class WebHttpClientResponse extends Inspectable.Class implements HttpClientRespo
132 if (this.cachedCookies) {
133 return this.cachedCookies
134 }
135- return this.cachedCookies = Cookies.fromSetCookie(this.source.headers.getSetCookie())
136+ return this.cachedCookies = Cookies.fromSetCookie(this.source.headers.getSetCookie?.() ?? [])
137 }
139 get remoteAddress(): Option.Option<string> {