From 9928917899fe69d4f49cde1ec1b4338fc29dfaf3 Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Tue, 28 Apr 2026 17:12:13 -0400 Subject: [PATCH] simplify(llm): remove dead ProviderShared.sse and withQuery helpers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After migration to Adapter.fromProtocol, the sse() convenience wrapper and withQuery() URL builder are no longer called anywhere — Framing.sse and Endpoint.baseURL handle their responsibilities directly. Also inlines two exported-but-unused test constants (helloPrompt, weatherPrompt) per style guide. --- packages/llm/src/provider/shared.ts | 43 ++++++------------------- packages/llm/test/recorded-scenarios.ts | 6 ++-- 2 files changed, 11 insertions(+), 38 deletions(-) diff --git a/packages/llm/src/provider/shared.ts b/packages/llm/src/provider/shared.ts index b51102175d..8f37acb41e 100644 --- a/packages/llm/src/provider/shared.ts +++ b/packages/llm/src/provider/shared.ts @@ -34,8 +34,8 @@ export interface ToolAccumulator { * - `encodeTarget(target)` produces the JSON string body for `jsonPost`. * - `decodeTarget(draft)` runs the Schema-driven `Draft → Target` decode * inside an Effect, mapping parse errors to `InvalidRequestError` via - * `validateWith` so the result drops directly into `Adapter.define`'s - * `validate` field. + * `validateWith` so the result drops directly into a protocol's `validate` + * field. * - `decodeChunk(input)` decodes one streaming JSON chunk against the chunk * schema. The default expects a `string` (the SSE data field); pass a * custom decoder shape via `decodeChunkInput` for adapters whose framing @@ -128,13 +128,6 @@ export const queryParams = (request: { readonly model: { readonly native?: Recor return value } -export const withQuery = (url: string, params: Record | undefined) => { - if (!params) return url - const result = new URL(url) - for (const [key, value] of Object.entries(params)) result.searchParams.set(key, value) - return result.toString() -} - export const toolResultText = (part: ToolResultPart) => { if (part.result.type === "text" || part.result.type === "error") return String(part.result.value) return encodeJson(part.result.value) @@ -156,16 +149,16 @@ const streamError = (adapter: string, message: string, cause: Cause.Cause(input: { readonly adapter: string @@ -211,24 +204,6 @@ export const sseFraming = ( Stream.map((event) => event.data), ) -/** - * SSE-specific convenience over `framed`. Identical surface as the original - * `sse` helper; preserves the `decodeChunk: (data: string) => …` signature - * so existing adapters don't need to know about `Frame`. - */ -export const sse = (input: { - readonly adapter: string - readonly response: HttpClientResponse.HttpClientResponse - readonly readError: string - readonly decodeChunk: (data: string) => Effect.Effect - readonly initial: () => State - readonly process: ( - state: State, - chunk: Chunk, - ) => Effect.Effect], ProviderChunkError> - readonly onHalt?: (state: State) => ReadonlyArray -}): Stream.Stream => framed({ ...input, framing: sseFraming }) - /** * Canonical `InvalidRequestError` constructor. Lift one-line `const invalid = * (message) => new InvalidRequestError({ message })` aliases out of every diff --git a/packages/llm/test/recorded-scenarios.ts b/packages/llm/test/recorded-scenarios.ts index 6d4f282d65..d8f3cc6e02 100644 --- a/packages/llm/test/recorded-scenarios.ts +++ b/packages/llm/test/recorded-scenarios.ts @@ -3,8 +3,6 @@ import { Effect, Schema } from "effect" import { LLM, type LLMEvent, type LLMResponse, type ModelRef } from "../src" import { tool } from "../src/tool" -export const helloPrompt = "Reply with exactly: Hello!" -export const weatherPrompt = "Call get_weather with city exactly Paris." export const weatherToolName = "get_weather" export const weatherTool = LLM.toolDefinition({ @@ -40,7 +38,7 @@ export const textRequest = (input: { id: input.id, model: input.model, system: "You are concise.", - prompt: input.prompt ?? helloPrompt, + prompt: input.prompt ?? "Reply with exactly: Hello!", generation: { maxTokens: input.maxTokens ?? 20, temperature: 0 }, }) @@ -53,7 +51,7 @@ export const weatherToolRequest = (input: { id: input.id, model: input.model, system: "Call tools exactly as requested.", - prompt: weatherPrompt, + prompt: "Call get_weather with city exactly Paris.", tools: [weatherTool], toolChoice: LLM.toolChoice(weatherTool), generation: { maxTokens: input.maxTokens ?? 80, temperature: 0 },