@effect-uai/responses 0.19.0-dev-20261110065930 → 0.20.0-dev-20261110202152
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/Responses.d.mts +8 -3
- package/dist/Responses.d.mts.map +1 -1
- package/dist/Responses.mjs.map +1 -1
- package/package.json +4 -4
- package/src/Responses.ts +7 -1
package/dist/Responses.d.mts
CHANGED
|
@@ -8,16 +8,21 @@ import * as AiError from "@effect-uai/core/AiError";
|
|
|
8
8
|
import { CommonRequest, LanguageModel } from "@effect-uai/core/LanguageModel";
|
|
9
9
|
import { Turn, TurnEvent } from "@effect-uai/core/Turn";
|
|
10
10
|
declare namespace Responses_d_exports {
|
|
11
|
-
export { Config, Responses, ResponsesRequest, ResponsesService, UserLocation, WebSearchFilters, WebSearchOptions, codeInterpreterTool, fileSearchTool, httpStatusError, layer, make, providerEventsOfResponse, toCanonical, webSearchTool };
|
|
11
|
+
export { Config, ReasoningEffort, Responses, ResponsesRequest, ResponsesService, UserLocation, WebSearchFilters, WebSearchOptions, codeInterpreterTool, fileSearchTool, httpStatusError, layer, make, providerEventsOfResponse, toCanonical, webSearchTool };
|
|
12
12
|
}
|
|
13
|
+
type ReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
13
14
|
type ResponsesRequest = Omit<CommonRequest, "model"> & {
|
|
14
15
|
/**
|
|
15
16
|
* Narrows `CommonRequest.model` (`string`) to the typed `OpenAIModel`
|
|
16
17
|
* literal union for autocomplete.
|
|
17
18
|
*/
|
|
18
19
|
readonly model: OpenAIModel;
|
|
20
|
+
/**
|
|
21
|
+
* Reasoning effort. Which values a model accepts varies: `none` (GPT-5.1+),
|
|
22
|
+
* `minimal` (GPT-5), `xhigh` (GPT-5.2+); `low` / `medium` / `high` everywhere.
|
|
23
|
+
*/
|
|
19
24
|
readonly reasoning?: {
|
|
20
|
-
readonly effort:
|
|
25
|
+
readonly effort: ReasoningEffort;
|
|
21
26
|
};
|
|
22
27
|
readonly store?: boolean;
|
|
23
28
|
readonly previousResponseId?: string;
|
|
@@ -128,5 +133,5 @@ declare const make: (cfg: Config) => Effect.Effect<ResponsesService, never, Http
|
|
|
128
133
|
*/
|
|
129
134
|
declare const layer: (cfg: Config) => Layer.Layer<Responses | LanguageModel, never, HttpClient.HttpClient>;
|
|
130
135
|
//#endregion
|
|
131
|
-
export { Config, Responses, ResponsesRequest, ResponsesService, type UserLocation, type WebSearchFilters, type WebSearchOptions, codeInterpreterTool, fileSearchTool, httpStatusError, layer, make, providerEventsOfResponse, Responses_d_exports as t, toCanonical, webSearchTool };
|
|
136
|
+
export { Config, ReasoningEffort, Responses, ResponsesRequest, ResponsesService, type UserLocation, type WebSearchFilters, type WebSearchOptions, codeInterpreterTool, fileSearchTool, httpStatusError, layer, make, providerEventsOfResponse, Responses_d_exports as t, toCanonical, webSearchTool };
|
|
132
137
|
//# sourceMappingURL=Responses.d.mts.map
|
package/dist/Responses.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Responses.d.mts","names":[],"sources":["../src/Responses.ts"],"mappings":";;;;;;;;;;;;KAsCY,mBAAmB,KAAK;;;;;WAKzB,OAAO;
|
|
1
|
+
{"version":3,"file":"Responses.d.mts","names":[],"sources":["../src/Responses.ts"],"mappings":";;;;;;;;;;;;KAsCY;KAEA,mBAAmB,KAAK;;;;;WAKzB,OAAO;;;;;WAKP;aAAuB,QAAQ;;WAC/B;WACA;WACA;WACA;WACA,WAAW,SAAS;WACpB;WACA;WACA;WACA;;;;;;;;;;;;;;WAcA,YAAY,SAAS;;;;;;WAMrB;aAA4B;;;;;;WAK5B;;KAGC;;;;;;WAMD,eACP,SAAS,qBACN,OAAO,OAAO,eAAe,QAAQ;;;;;WAKjC,aAAa,SAAS,qBAAqB,OAAO,OAAO,WAAW,QAAQ;;;;;;WAM5E,OAAO,SAAS,qBAAqB,OAAO,OAAO,MAAM,QAAQ;;;;;;WAMjE,cAAc,GAAG,GACxB,GAAG,OAAO,OAAO,eAAe,GAAG,OAChC,OAAO,OAAO,WAAW,GAAG;;;;;;;;;cAStB,kBAAkB;KAInB;WACD,QAAQ,SAAS;WACjB;WACA,SAAS;;;;;;WAMT,YAAY,SAAS;;cA0InB,kBAAe,gBAAkB,iBAAiB,QAAQ;;;;;;;;cAoB1D,2BAAwB,UACzB,mBAAmB,uBAC5B,OAAO,OAAO,eAAe,QAAQ;;;;;;cAuE3B,cAAe,GAAG,GAAC,GAC3B,OAAO,OAAO,eAAe,GAAG,OAClC,OAAO,OAAO,WAAW,GAAG;;;;cAelB,OAAI,KAAS,WAAS,OAAO,OAAO,yBAAyB,WAAW;;;;;;;;cAqBxE,QAAK,KACX,WACJ,MAAM,MAAM,YAAY,sBAAsB,WAAW"}
|
package/dist/Responses.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Responses.mjs","names":[],"sources":["../src/Responses.ts"],"sourcesContent":["import { Context, Effect, Layer, Match, Option, Redacted, Result, Schema, Stream } from \"effect\"\nimport { HttpClient, HttpClientRequest, HttpClientResponse } from \"effect/http\"\nimport * as AiError from \"@effect-uai/core/AiError\"\nimport * as Capabilities from \"@effect-uai/core/Capabilities\"\nimport * as StructuredFormat from \"@effect-uai/core/StructuredFormat\"\nimport {\n type CommonRequest,\n LanguageModel,\n type LanguageModelService,\n turnFromStream,\n} from \"@effect-uai/core/LanguageModel\"\nimport * as SSE from \"@effect-uai/core/SSE\"\nimport { descriptorsOf, providerToolsOf } from \"@effect-uai/core/Tool\"\nimport type { Turn, TurnEvent } from \"@effect-uai/core/Turn\"\nimport { itemsToInput } from \"./codec.js\"\nimport { renderProviderTools } from \"./ResponsesTools.js\"\n\nexport {\n codeInterpreterTool,\n fileSearchTool,\n webSearchTool,\n type WebSearchOptions,\n type WebSearchFilters,\n type UserLocation,\n} from \"./ResponsesTools.js\"\nimport type { OpenAIModel } from \"./models.js\"\nimport { type OpenAiRegion, resolveHost } from \"./region.js\"\nimport {\n KnownProviderEvent,\n ProviderEvent,\n eventToDeltas,\n makeCallIdLookup,\n} from \"./streamEvents.js\"\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\nexport type ResponsesRequest = Omit<CommonRequest, \"model\"> & {\n /**\n * Narrows `CommonRequest.model` (`string`) to the typed `OpenAIModel`\n * literal union for autocomplete.\n */\n readonly model: OpenAIModel\n readonly reasoning?: { readonly effort: \"low\" | \"medium\" | \"high\" }\n readonly store?: boolean\n readonly previousResponseId?: string\n readonly instructions?: string\n readonly parallelToolCalls?: boolean\n readonly metadata?: Readonly<Record<string, string>>\n readonly user?: string\n readonly safetyIdentifier?: string\n readonly promptCacheKey?: string\n readonly truncation?: \"auto\" | \"disabled\"\n /**\n * Vendor-specific body fields merged into the request as-is.\n *\n * The Responses dialect is spoken by gateways as well as by OpenAI, and a\n * gateway carries its own parameters — Requesty's `{ requesty: { auto_cache:\n * true } }`, for example. Modelling each one would tie this provider to a\n * catalogue of gateways it cannot see; passing them through keeps the typed\n * surface OpenAI's and the untyped surface open.\n *\n * Merged over the built body, so a field named here wins over the one this\n * provider would have sent. Per-request keys win over the layer's\n * {@link Config.extraBody}.\n */\n readonly extraBody?: Readonly<Record<string, unknown>>\n /**\n * Free-form JSON output: model emits valid JSON without schema\n * constraints. Mutually exclusive with `structured` (schema wins if\n * both are set).\n */\n readonly responseFormat?: { readonly type: \"json_object\" }\n /**\n * Answer length / level-of-detail hint. GPT-5+ models honour it;\n * earlier models ignore.\n */\n readonly verbosity?: \"low\" | \"medium\" | \"high\"\n}\n\nexport type ResponsesService = {\n /**\n * Stream the provider's native event vocabulary (post-SSE-decode).\n * Use this when you need full vendor fidelity. For provider-portable\n * code, use `streamTurn` instead.\n */\n readonly streamNative: (\n request: ResponsesRequest,\n ) => Stream.Stream<ProviderEvent, AiError.AiError>\n /**\n * Stream canonical `TurnEvent`s. Implemented as\n * `streamNative |> toCanonical`.\n */\n readonly streamTurn: (request: ResponsesRequest) => Stream.Stream<TurnEvent, AiError.AiError>\n /**\n * Drain a single turn and return the assembled `Turn`. Derived from\n * `streamTurn` — Responses doesn't expose a native non-streaming\n * complete endpoint we'd want to take advantage of.\n */\n readonly turn: (request: ResponsesRequest) => Effect.Effect<Turn, AiError.AiError>\n /**\n * Project a stream of native `ProviderEvent`s into canonical `TurnEvent`s.\n * Exposed for cases where consumers want to compose with `streamNative`\n * directly (e.g. tap into natives + still get canonical downstream).\n */\n readonly toCanonical: <E, R>(\n s: Stream.Stream<ProviderEvent, E, R>,\n ) => Stream.Stream<TurnEvent, E, R>\n}\n\n/**\n * Provider-typed service tag. Yield this when you want Responses-specific\n * options (`reasoning.effort`, `store`, `previousResponseId`) at the call\n * site. Yield the generic `LanguageModel` tag for provider-portable code -\n * both are registered by `layer`.\n */\nexport class Responses extends Context.Service<Responses, ResponsesService>()(\n \"@betalyra/effect-uai/providers/responses/Responses\",\n) {}\n\nexport type Config = {\n readonly apiKey: Redacted.Redacted\n readonly baseUrl?: string\n readonly region?: OpenAiRegion\n /**\n * Vendor-specific body fields sent on every request from this layer — the\n * place for a gateway's standing configuration, so call sites do not repeat\n * it. Overridden per request by {@link ResponsesRequest.extraBody}.\n */\n readonly extraBody?: Readonly<Record<string, unknown>>\n}\n\n// ---------------------------------------------------------------------------\n// Request body\n// ---------------------------------------------------------------------------\n\nconst jsonSchemaFormat = (\n format: StructuredFormat.StructuredFormat<unknown>,\n): Record<string, unknown> => ({\n type: \"json_schema\",\n name: format.name,\n schema: format.schema[\"~standard\"].jsonSchema.input({ target: \"draft-2020-12\" }),\n ...(format.description !== undefined && { description: format.description }),\n ...(format.strict !== undefined && { strict: format.strict }),\n})\n\nconst buildText = (request: ResponsesRequest): Record<string, unknown> | undefined => {\n const format =\n request.structured !== undefined ? jsonSchemaFormat(request.structured) : request.responseFormat\n const text: Record<string, unknown> = {}\n if (format !== undefined) text.format = format\n if (request.verbosity !== undefined) text.verbosity = request.verbosity\n return Object.keys(text).length === 0 ? undefined : text\n}\n\nconst buildBody = (\n request: ResponsesRequest,\n providerToolWire: ReadonlyArray<Record<string, unknown>>,\n cfg: Config,\n): Record<string, unknown> => {\n const text = buildText(request)\n const functionTools = descriptorsOf(request.tools).map((t) => ({\n type: \"function\",\n name: t.name,\n description: t.description,\n parameters: t.inputSchema,\n ...(t.strict !== undefined && { strict: t.strict }),\n }))\n const tools = [...functionTools, ...providerToolWire]\n return {\n model: request.model,\n input: itemsToInput(request.history),\n stream: true,\n ...(tools.length > 0 && { tools }),\n ...(request.toolChoice !== undefined && { tool_choice: request.toolChoice }),\n ...(request.temperature !== undefined && { temperature: request.temperature }),\n ...(request.maxOutputTokens !== undefined && {\n max_output_tokens: request.maxOutputTokens,\n }),\n ...(request.reasoning !== undefined && { reasoning: request.reasoning }),\n ...(request.store !== undefined && { store: request.store }),\n ...(request.previousResponseId !== undefined && {\n previous_response_id: request.previousResponseId,\n }),\n ...(request.instructions !== undefined && { instructions: request.instructions }),\n ...(request.topP !== undefined && { top_p: request.topP }),\n ...(request.parallelToolCalls !== undefined && {\n parallel_tool_calls: request.parallelToolCalls,\n }),\n ...(request.metadata !== undefined && { metadata: request.metadata }),\n ...(request.user !== undefined && { user: request.user }),\n ...(request.safetyIdentifier !== undefined && {\n safety_identifier: request.safetyIdentifier,\n }),\n ...(request.promptCacheKey !== undefined && {\n prompt_cache_key: request.promptCacheKey,\n }),\n ...(request.truncation !== undefined && { truncation: request.truncation }),\n ...(text !== undefined && { text }),\n ...cfg.extraBody,\n ...request.extraBody,\n }\n}\n\n// ---------------------------------------------------------------------------\n// SSE event → provider event\n// ---------------------------------------------------------------------------\n\nconst decodeKnown = Schema.decodeUnknownEffect(KnownProviderEvent)\n\nconst makeUnknown = (raw: unknown): ProviderEvent => ({ type: \"_unknown\", raw })\n\n/**\n * Lift events that carry a terminal failure signal (`error`,\n * `response.failed`) to a typed `AiError`. Other events are not failures\n * and produce `Option.none`.\n */\nconst eventToError = Match.type<ProviderEvent>().pipe(\n Match.discriminators(\"type\")({\n error: (e): AiError.AiError => {\n const detail = e.error\n const message = detail?.message ?? e.message\n const code = detail?.code ?? e.code\n const param = detail?.param\n // A top-level SSE `error` is usually a request rejection (bad model,\n // missing access, malformed body): non-retryable, so `InvalidRequest`.\n return detail?.type === \"invalid_request_error\"\n ? new AiError.InvalidRequest({\n provider: \"responses\",\n ...(param != null && { param }),\n raw: e,\n })\n : new AiError.GenerationFailed({\n provider: \"responses\",\n ...(code != null && { code }),\n ...(message != null && { message }),\n raw: e,\n })\n },\n \"response.failed\": (e): AiError.AiError => {\n const code = e.response.error?.code\n const message = e.response.error?.message\n return new AiError.GenerationFailed({\n provider: \"responses\",\n ...(code !== undefined && code !== null && { code }),\n ...(message !== undefined && message !== null && { message }),\n raw: e,\n })\n },\n }),\n Match.option,\n)\n\nconst parseJsonUnknown = Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Unknown))\n\nconst sseEventToProviderEvent = (ev: SSE.Event): Effect.Effect<ProviderEvent> =>\n parseJsonUnknown(ev.data).pipe(\n Effect.flatMap((parsed) =>\n decodeKnown(parsed).pipe(Effect.orElseSucceed(() => makeUnknown(parsed))),\n ),\n Effect.orElseSucceed(() => makeUnknown(ev.data)),\n )\n\n// ---------------------------------------------------------------------------\n// Service implementation\n// ---------------------------------------------------------------------------\n\nexport const httpStatusError = (status: number, body: string): AiError.AiError => {\n const provider = \"responses\"\n const raw = body\n if (status === 429) return new AiError.RateLimited({ provider, raw })\n if (status === 408 || status === 504) return new AiError.Timeout({ provider, raw })\n if (status === 401) return new AiError.AuthFailed({ provider, subtype: \"auth\", raw })\n if (status === 403) return new AiError.AuthFailed({ provider, subtype: \"permission\", raw })\n if (status === 402) return new AiError.AuthFailed({ provider, subtype: \"billing\", raw })\n if (status === 413) return new AiError.ContextLengthExceeded({ provider, raw })\n if (status >= 500) return new AiError.Unavailable({ provider, status, raw })\n return new AiError.InvalidRequest({ provider, raw })\n}\n\n/**\n * Decode an already-executed `/responses` HTTP response into the native\n * `ProviderEvent` stream: fail on a >=400 status, else SSE-decode the body and\n * lift terminal `error` / `response.failed` events to a typed `AiError`. Shared\n * by the streaming turn path (POST) and the deep-research resume stream (GET\n * `?stream=true`).\n */\nexport const providerEventsOfResponse = (\n response: HttpClientResponse.HttpClientResponse,\n): Stream.Stream<ProviderEvent, AiError.AiError> =>\n Stream.unwrap(\n Effect.gen(function* () {\n if (response.status >= 400) {\n const body = yield* response.text.pipe(Effect.orElseSucceed(() => \"\"))\n return Stream.fail(httpStatusError(response.status, body))\n }\n return response.stream.pipe(\n Stream.mapError((cause) => new AiError.Unavailable({ provider: \"responses\", raw: cause })),\n SSE.fromBytes,\n Stream.mapEffect(sseEventToProviderEvent),\n Stream.flatMap((event) =>\n Option.match(eventToError(event), {\n onNone: () => Stream.succeed(event),\n onSome: Stream.fail,\n }),\n ),\n )\n }),\n )\n\nconst buildNativeStream = (cfg: Config) => {\n const url = `${resolveHost(cfg)}/responses`\n return (\n request: ResponsesRequest,\n ): Stream.Stream<ProviderEvent, AiError.AiError, HttpClient.HttpClient> =>\n Stream.unwrap(\n Effect.gen(function* () {\n const client = yield* HttpClient.HttpClient\n const providerToolWire = yield* Result.match(\n renderProviderTools(providerToolsOf(request.tools)),\n {\n onFailure: (e) =>\n Effect.fail(\n new AiError.Unsupported({\n provider: \"responses\",\n capability: e.capability,\n reason: e.reason,\n }),\n ),\n onSuccess: (wire) => Effect.succeed(wire),\n },\n )\n yield* Capabilities.warnDroppedBlocks(request.history, \"output_image\", {\n provider: \"responses\",\n capability: \"output_image\",\n reason:\n \"Assistant messages carry no image on this wire; images here come from the `image_generation` tool. Use `Turn.imagesAsInput` to resend one as user content.\",\n })\n const httpRequest = HttpClientRequest.post(url).pipe(\n HttpClientRequest.bearerToken(cfg.apiKey),\n HttpClientRequest.bodyJsonUnsafe(buildBody(request, providerToolWire, cfg)),\n HttpClientRequest.accept(\"text/event-stream\"),\n )\n const response = yield* client\n .execute(httpRequest)\n .pipe(\n Effect.mapError(\n (cause) => new AiError.Unavailable({ provider: \"responses\", raw: cause }),\n ),\n )\n return providerEventsOfResponse(response)\n }),\n )\n}\n\n/**\n * Project a stream of native `ProviderEvent`s into canonical `TurnEvent`s.\n * Threads a fresh `CallIdLookup` per stream so `function_call_arguments.delta`\n * can be tagged with the right `call_id`.\n */\nexport const toCanonical = <E, R>(\n s: Stream.Stream<ProviderEvent, E, R>,\n): Stream.Stream<TurnEvent, E, R> =>\n Stream.unwrap(\n Effect.sync(() => {\n const lookup = makeCallIdLookup()\n return s.pipe(Stream.flatMap((event) => Stream.fromIterable(eventToDeltas(event, lookup))))\n }),\n )\n\n// ---------------------------------------------------------------------------\n// Constructors\n// ---------------------------------------------------------------------------\n\n/**\n * Build a `ResponsesService` value. For Layer-based setup, prefer `layer`.\n */\nexport const make = (cfg: Config): Effect.Effect<ResponsesService, never, HttpClient.HttpClient> =>\n Effect.map(HttpClient.HttpClient, (client) => {\n const streamNative: ResponsesService[\"streamNative\"] = (request) =>\n buildNativeStream(cfg)(request).pipe(Stream.provideService(HttpClient.HttpClient, client))\n const streamTurn: ResponsesService[\"streamTurn\"] = (request) =>\n toCanonical(streamNative(request))\n return {\n streamNative,\n streamTurn,\n turn: turnFromStream(streamTurn),\n toCanonical,\n }\n })\n\n/**\n * Layer that registers both the provider-specific `Responses` tag and the\n * generic `LanguageModel` tag, sharing one underlying implementation.\n *\n * The generic tag accepts `CommonRequest`; the typed tag accepts the full\n * `ResponsesRequest` surface.\n */\nexport const layer = (\n cfg: Config,\n): Layer.Layer<Responses | LanguageModel, never, HttpClient.HttpClient> => {\n const typed = Layer.effect(Responses, make(cfg))\n const generic = Layer.effect(\n LanguageModel,\n Effect.map(make(cfg), (s): LanguageModelService => ({\n streamTurn: (request) => s.streamTurn(request as ResponsesRequest),\n turn: (request) => s.turn(request as ResponsesRequest),\n })),\n )\n return Layer.merge(typed, generic)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqHA,IAAa,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CAAC;EACD,MAAM,cAAc,kBAAkB,KAAK,GAAG,CAAC,CAAC,KAC9C,kBAAkB,YAAY,IAAI,MAAM,GACxC,kBAAkB,eAAe,UAAU,SAAS,kBAAkB,GAAG,CAAC,GAC1E,kBAAkB,OAAO,mBAAmB,CAC9C;EACA,MAAM,WAAW,OAAO,OACrB,QAAQ,WAAW,CAAC,CACpB,KACC,OAAO,UACJ,UAAU,IAAI,QAAQ,YAAY;GAAE,UAAU;GAAa,KAAK;EAAM,CAAC,CAC1E,CACF;EACF,OAAO,yBAAyB,QAAQ;CAC1C,CAAC,CACH;AACJ;;;;;;AAOA,MAAa,eACX,MAEA,OAAO,OACL,OAAO,WAAW;CAChB,MAAM,SAAS,iBAAiB;CAChC,OAAO,EAAE,KAAK,OAAO,SAAS,UAAU,OAAO,aAAa,cAAc,OAAO,MAAM,CAAC,CAAC,CAAC;AAC5F,CAAC,CACH;;;;AASF,MAAa,QAAQ,QACnB,OAAO,IAAI,WAAW,aAAa,WAAW;CAC5C,MAAM,gBAAkD,YACtD,kBAAkB,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,OAAO,eAAe,WAAW,YAAY,MAAM,CAAC;CAC3F,MAAM,cAA8C,YAClD,YAAY,aAAa,OAAO,CAAC;CACnC,OAAO;EACL;EACA;EACA,MAAM,eAAe,UAAU;EAC/B;CACF;AACF,CAAC;;;;;;;;AASH,MAAa,SACX,QACyE;CACzE,MAAM,QAAQ,MAAM,OAAO,WAAW,KAAK,GAAG,CAAC;CAC/C,MAAM,UAAU,MAAM,OACpB,eACA,OAAO,IAAI,KAAK,GAAG,IAAI,OAA6B;EAClD,aAAa,YAAY,EAAE,WAAW,OAA2B;EACjE,OAAO,YAAY,EAAE,KAAK,OAA2B;CACvD,EAAE,CACJ;CACA,OAAO,MAAM,MAAM,OAAO,OAAO;AACnC"}
|
|
1
|
+
{"version":3,"file":"Responses.mjs","names":[],"sources":["../src/Responses.ts"],"sourcesContent":["import { Context, Effect, Layer, Match, Option, Redacted, Result, Schema, Stream } from \"effect\"\nimport { HttpClient, HttpClientRequest, HttpClientResponse } from \"effect/http\"\nimport * as AiError from \"@effect-uai/core/AiError\"\nimport * as Capabilities from \"@effect-uai/core/Capabilities\"\nimport * as StructuredFormat from \"@effect-uai/core/StructuredFormat\"\nimport {\n type CommonRequest,\n LanguageModel,\n type LanguageModelService,\n turnFromStream,\n} from \"@effect-uai/core/LanguageModel\"\nimport * as SSE from \"@effect-uai/core/SSE\"\nimport { descriptorsOf, providerToolsOf } from \"@effect-uai/core/Tool\"\nimport type { Turn, TurnEvent } from \"@effect-uai/core/Turn\"\nimport { itemsToInput } from \"./codec.js\"\nimport { renderProviderTools } from \"./ResponsesTools.js\"\n\nexport {\n codeInterpreterTool,\n fileSearchTool,\n webSearchTool,\n type WebSearchOptions,\n type WebSearchFilters,\n type UserLocation,\n} from \"./ResponsesTools.js\"\nimport type { OpenAIModel } from \"./models.js\"\nimport { type OpenAiRegion, resolveHost } from \"./region.js\"\nimport {\n KnownProviderEvent,\n ProviderEvent,\n eventToDeltas,\n makeCallIdLookup,\n} from \"./streamEvents.js\"\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\nexport type ReasoningEffort = \"none\" | \"minimal\" | \"low\" | \"medium\" | \"high\" | \"xhigh\"\n\nexport type ResponsesRequest = Omit<CommonRequest, \"model\"> & {\n /**\n * Narrows `CommonRequest.model` (`string`) to the typed `OpenAIModel`\n * literal union for autocomplete.\n */\n readonly model: OpenAIModel\n /**\n * Reasoning effort. Which values a model accepts varies: `none` (GPT-5.1+),\n * `minimal` (GPT-5), `xhigh` (GPT-5.2+); `low` / `medium` / `high` everywhere.\n */\n readonly reasoning?: { readonly effort: ReasoningEffort }\n readonly store?: boolean\n readonly previousResponseId?: string\n readonly instructions?: string\n readonly parallelToolCalls?: boolean\n readonly metadata?: Readonly<Record<string, string>>\n readonly user?: string\n readonly safetyIdentifier?: string\n readonly promptCacheKey?: string\n readonly truncation?: \"auto\" | \"disabled\"\n /**\n * Vendor-specific body fields merged into the request as-is.\n *\n * The Responses dialect is spoken by gateways as well as by OpenAI, and a\n * gateway carries its own parameters — Requesty's `{ requesty: { auto_cache:\n * true } }`, for example. Modelling each one would tie this provider to a\n * catalogue of gateways it cannot see; passing them through keeps the typed\n * surface OpenAI's and the untyped surface open.\n *\n * Merged over the built body, so a field named here wins over the one this\n * provider would have sent. Per-request keys win over the layer's\n * {@link Config.extraBody}.\n */\n readonly extraBody?: Readonly<Record<string, unknown>>\n /**\n * Free-form JSON output: model emits valid JSON without schema\n * constraints. Mutually exclusive with `structured` (schema wins if\n * both are set).\n */\n readonly responseFormat?: { readonly type: \"json_object\" }\n /**\n * Answer length / level-of-detail hint. GPT-5+ models honour it;\n * earlier models ignore.\n */\n readonly verbosity?: \"low\" | \"medium\" | \"high\"\n}\n\nexport type ResponsesService = {\n /**\n * Stream the provider's native event vocabulary (post-SSE-decode).\n * Use this when you need full vendor fidelity. For provider-portable\n * code, use `streamTurn` instead.\n */\n readonly streamNative: (\n request: ResponsesRequest,\n ) => Stream.Stream<ProviderEvent, AiError.AiError>\n /**\n * Stream canonical `TurnEvent`s. Implemented as\n * `streamNative |> toCanonical`.\n */\n readonly streamTurn: (request: ResponsesRequest) => Stream.Stream<TurnEvent, AiError.AiError>\n /**\n * Drain a single turn and return the assembled `Turn`. Derived from\n * `streamTurn` — Responses doesn't expose a native non-streaming\n * complete endpoint we'd want to take advantage of.\n */\n readonly turn: (request: ResponsesRequest) => Effect.Effect<Turn, AiError.AiError>\n /**\n * Project a stream of native `ProviderEvent`s into canonical `TurnEvent`s.\n * Exposed for cases where consumers want to compose with `streamNative`\n * directly (e.g. tap into natives + still get canonical downstream).\n */\n readonly toCanonical: <E, R>(\n s: Stream.Stream<ProviderEvent, E, R>,\n ) => Stream.Stream<TurnEvent, E, R>\n}\n\n/**\n * Provider-typed service tag. Yield this when you want Responses-specific\n * options (`reasoning.effort`, `store`, `previousResponseId`) at the call\n * site. Yield the generic `LanguageModel` tag for provider-portable code -\n * both are registered by `layer`.\n */\nexport class Responses extends Context.Service<Responses, ResponsesService>()(\n \"@betalyra/effect-uai/providers/responses/Responses\",\n) {}\n\nexport type Config = {\n readonly apiKey: Redacted.Redacted\n readonly baseUrl?: string\n readonly region?: OpenAiRegion\n /**\n * Vendor-specific body fields sent on every request from this layer — the\n * place for a gateway's standing configuration, so call sites do not repeat\n * it. Overridden per request by {@link ResponsesRequest.extraBody}.\n */\n readonly extraBody?: Readonly<Record<string, unknown>>\n}\n\n// ---------------------------------------------------------------------------\n// Request body\n// ---------------------------------------------------------------------------\n\nconst jsonSchemaFormat = (\n format: StructuredFormat.StructuredFormat<unknown>,\n): Record<string, unknown> => ({\n type: \"json_schema\",\n name: format.name,\n schema: format.schema[\"~standard\"].jsonSchema.input({ target: \"draft-2020-12\" }),\n ...(format.description !== undefined && { description: format.description }),\n ...(format.strict !== undefined && { strict: format.strict }),\n})\n\nconst buildText = (request: ResponsesRequest): Record<string, unknown> | undefined => {\n const format =\n request.structured !== undefined ? jsonSchemaFormat(request.structured) : request.responseFormat\n const text: Record<string, unknown> = {}\n if (format !== undefined) text.format = format\n if (request.verbosity !== undefined) text.verbosity = request.verbosity\n return Object.keys(text).length === 0 ? undefined : text\n}\n\nconst buildBody = (\n request: ResponsesRequest,\n providerToolWire: ReadonlyArray<Record<string, unknown>>,\n cfg: Config,\n): Record<string, unknown> => {\n const text = buildText(request)\n const functionTools = descriptorsOf(request.tools).map((t) => ({\n type: \"function\",\n name: t.name,\n description: t.description,\n parameters: t.inputSchema,\n ...(t.strict !== undefined && { strict: t.strict }),\n }))\n const tools = [...functionTools, ...providerToolWire]\n return {\n model: request.model,\n input: itemsToInput(request.history),\n stream: true,\n ...(tools.length > 0 && { tools }),\n ...(request.toolChoice !== undefined && { tool_choice: request.toolChoice }),\n ...(request.temperature !== undefined && { temperature: request.temperature }),\n ...(request.maxOutputTokens !== undefined && {\n max_output_tokens: request.maxOutputTokens,\n }),\n ...(request.reasoning !== undefined && { reasoning: request.reasoning }),\n ...(request.store !== undefined && { store: request.store }),\n ...(request.previousResponseId !== undefined && {\n previous_response_id: request.previousResponseId,\n }),\n ...(request.instructions !== undefined && { instructions: request.instructions }),\n ...(request.topP !== undefined && { top_p: request.topP }),\n ...(request.parallelToolCalls !== undefined && {\n parallel_tool_calls: request.parallelToolCalls,\n }),\n ...(request.metadata !== undefined && { metadata: request.metadata }),\n ...(request.user !== undefined && { user: request.user }),\n ...(request.safetyIdentifier !== undefined && {\n safety_identifier: request.safetyIdentifier,\n }),\n ...(request.promptCacheKey !== undefined && {\n prompt_cache_key: request.promptCacheKey,\n }),\n ...(request.truncation !== undefined && { truncation: request.truncation }),\n ...(text !== undefined && { text }),\n ...cfg.extraBody,\n ...request.extraBody,\n }\n}\n\n// ---------------------------------------------------------------------------\n// SSE event → provider event\n// ---------------------------------------------------------------------------\n\nconst decodeKnown = Schema.decodeUnknownEffect(KnownProviderEvent)\n\nconst makeUnknown = (raw: unknown): ProviderEvent => ({ type: \"_unknown\", raw })\n\n/**\n * Lift events that carry a terminal failure signal (`error`,\n * `response.failed`) to a typed `AiError`. Other events are not failures\n * and produce `Option.none`.\n */\nconst eventToError = Match.type<ProviderEvent>().pipe(\n Match.discriminators(\"type\")({\n error: (e): AiError.AiError => {\n const detail = e.error\n const message = detail?.message ?? e.message\n const code = detail?.code ?? e.code\n const param = detail?.param\n // A top-level SSE `error` is usually a request rejection (bad model,\n // missing access, malformed body): non-retryable, so `InvalidRequest`.\n return detail?.type === \"invalid_request_error\"\n ? new AiError.InvalidRequest({\n provider: \"responses\",\n ...(param != null && { param }),\n raw: e,\n })\n : new AiError.GenerationFailed({\n provider: \"responses\",\n ...(code != null && { code }),\n ...(message != null && { message }),\n raw: e,\n })\n },\n \"response.failed\": (e): AiError.AiError => {\n const code = e.response.error?.code\n const message = e.response.error?.message\n return new AiError.GenerationFailed({\n provider: \"responses\",\n ...(code !== undefined && code !== null && { code }),\n ...(message !== undefined && message !== null && { message }),\n raw: e,\n })\n },\n }),\n Match.option,\n)\n\nconst parseJsonUnknown = Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Unknown))\n\nconst sseEventToProviderEvent = (ev: SSE.Event): Effect.Effect<ProviderEvent> =>\n parseJsonUnknown(ev.data).pipe(\n Effect.flatMap((parsed) =>\n decodeKnown(parsed).pipe(Effect.orElseSucceed(() => makeUnknown(parsed))),\n ),\n Effect.orElseSucceed(() => makeUnknown(ev.data)),\n )\n\n// ---------------------------------------------------------------------------\n// Service implementation\n// ---------------------------------------------------------------------------\n\nexport const httpStatusError = (status: number, body: string): AiError.AiError => {\n const provider = \"responses\"\n const raw = body\n if (status === 429) return new AiError.RateLimited({ provider, raw })\n if (status === 408 || status === 504) return new AiError.Timeout({ provider, raw })\n if (status === 401) return new AiError.AuthFailed({ provider, subtype: \"auth\", raw })\n if (status === 403) return new AiError.AuthFailed({ provider, subtype: \"permission\", raw })\n if (status === 402) return new AiError.AuthFailed({ provider, subtype: \"billing\", raw })\n if (status === 413) return new AiError.ContextLengthExceeded({ provider, raw })\n if (status >= 500) return new AiError.Unavailable({ provider, status, raw })\n return new AiError.InvalidRequest({ provider, raw })\n}\n\n/**\n * Decode an already-executed `/responses` HTTP response into the native\n * `ProviderEvent` stream: fail on a >=400 status, else SSE-decode the body and\n * lift terminal `error` / `response.failed` events to a typed `AiError`. Shared\n * by the streaming turn path (POST) and the deep-research resume stream (GET\n * `?stream=true`).\n */\nexport const providerEventsOfResponse = (\n response: HttpClientResponse.HttpClientResponse,\n): Stream.Stream<ProviderEvent, AiError.AiError> =>\n Stream.unwrap(\n Effect.gen(function* () {\n if (response.status >= 400) {\n const body = yield* response.text.pipe(Effect.orElseSucceed(() => \"\"))\n return Stream.fail(httpStatusError(response.status, body))\n }\n return response.stream.pipe(\n Stream.mapError((cause) => new AiError.Unavailable({ provider: \"responses\", raw: cause })),\n SSE.fromBytes,\n Stream.mapEffect(sseEventToProviderEvent),\n Stream.flatMap((event) =>\n Option.match(eventToError(event), {\n onNone: () => Stream.succeed(event),\n onSome: Stream.fail,\n }),\n ),\n )\n }),\n )\n\nconst buildNativeStream = (cfg: Config) => {\n const url = `${resolveHost(cfg)}/responses`\n return (\n request: ResponsesRequest,\n ): Stream.Stream<ProviderEvent, AiError.AiError, HttpClient.HttpClient> =>\n Stream.unwrap(\n Effect.gen(function* () {\n const client = yield* HttpClient.HttpClient\n const providerToolWire = yield* Result.match(\n renderProviderTools(providerToolsOf(request.tools)),\n {\n onFailure: (e) =>\n Effect.fail(\n new AiError.Unsupported({\n provider: \"responses\",\n capability: e.capability,\n reason: e.reason,\n }),\n ),\n onSuccess: (wire) => Effect.succeed(wire),\n },\n )\n yield* Capabilities.warnDroppedBlocks(request.history, \"output_image\", {\n provider: \"responses\",\n capability: \"output_image\",\n reason:\n \"Assistant messages carry no image on this wire; images here come from the `image_generation` tool. Use `Turn.imagesAsInput` to resend one as user content.\",\n })\n const httpRequest = HttpClientRequest.post(url).pipe(\n HttpClientRequest.bearerToken(cfg.apiKey),\n HttpClientRequest.bodyJsonUnsafe(buildBody(request, providerToolWire, cfg)),\n HttpClientRequest.accept(\"text/event-stream\"),\n )\n const response = yield* client\n .execute(httpRequest)\n .pipe(\n Effect.mapError(\n (cause) => new AiError.Unavailable({ provider: \"responses\", raw: cause }),\n ),\n )\n return providerEventsOfResponse(response)\n }),\n )\n}\n\n/**\n * Project a stream of native `ProviderEvent`s into canonical `TurnEvent`s.\n * Threads a fresh `CallIdLookup` per stream so `function_call_arguments.delta`\n * can be tagged with the right `call_id`.\n */\nexport const toCanonical = <E, R>(\n s: Stream.Stream<ProviderEvent, E, R>,\n): Stream.Stream<TurnEvent, E, R> =>\n Stream.unwrap(\n Effect.sync(() => {\n const lookup = makeCallIdLookup()\n return s.pipe(Stream.flatMap((event) => Stream.fromIterable(eventToDeltas(event, lookup))))\n }),\n )\n\n// ---------------------------------------------------------------------------\n// Constructors\n// ---------------------------------------------------------------------------\n\n/**\n * Build a `ResponsesService` value. For Layer-based setup, prefer `layer`.\n */\nexport const make = (cfg: Config): Effect.Effect<ResponsesService, never, HttpClient.HttpClient> =>\n Effect.map(HttpClient.HttpClient, (client) => {\n const streamNative: ResponsesService[\"streamNative\"] = (request) =>\n buildNativeStream(cfg)(request).pipe(Stream.provideService(HttpClient.HttpClient, client))\n const streamTurn: ResponsesService[\"streamTurn\"] = (request) =>\n toCanonical(streamNative(request))\n return {\n streamNative,\n streamTurn,\n turn: turnFromStream(streamTurn),\n toCanonical,\n }\n })\n\n/**\n * Layer that registers both the provider-specific `Responses` tag and the\n * generic `LanguageModel` tag, sharing one underlying implementation.\n *\n * The generic tag accepts `CommonRequest`; the typed tag accepts the full\n * `ResponsesRequest` surface.\n */\nexport const layer = (\n cfg: Config,\n): Layer.Layer<Responses | LanguageModel, never, HttpClient.HttpClient> => {\n const typed = Layer.effect(Responses, make(cfg))\n const generic = Layer.effect(\n LanguageModel,\n Effect.map(make(cfg), (s): LanguageModelService => ({\n streamTurn: (request) => s.streamTurn(request as ResponsesRequest),\n turn: (request) => s.turn(request as ResponsesRequest),\n })),\n )\n return Layer.merge(typed, generic)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2HA,IAAa,YAAb,cAA+B,QAAQ,QAAqC,CAAC,CAC3E,oDACF,CAAC,CAAC,CAAC;AAkBH,MAAM,oBACJ,YAC6B;CAC7B,MAAM;CACN,MAAM,OAAO;CACb,QAAQ,OAAO,OAAO,YAAY,CAAC,WAAW,MAAM,EAAE,QAAQ,gBAAgB,CAAC;CAC/E,GAAI,OAAO,gBAAgB,KAAA,KAAa,EAAE,aAAa,OAAO,YAAY;CAC1E,GAAI,OAAO,WAAW,KAAA,KAAa,EAAE,QAAQ,OAAO,OAAO;AAC7D;AAEA,MAAM,aAAa,YAAmE;CACpF,MAAM,SACJ,QAAQ,eAAe,KAAA,IAAY,iBAAiB,QAAQ,UAAU,IAAI,QAAQ;CACpF,MAAM,OAAgC,CAAC;CACv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EAAE,KAAK,OAAO,SAAS,UAAU,OAAO,aAAa,cAAc,OAAO,MAAM,CAAC,CAAC,CAAC;AAC5F,CAAC,CACH;;;;AASF,MAAa,QAAQ,QACnB,OAAO,IAAI,WAAW,aAAa,WAAW;CAC5C,MAAM,gBAAkD,YACtD,kBAAkB,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,OAAO,eAAe,WAAW,YAAY,MAAM,CAAC;CAC3F,MAAM,cAA8C,YAClD,YAAY,aAAa,OAAO,CAAC;CACnC,OAAO;EACL;EACA;EACA,MAAM,eAAe,UAAU;EAC/B;CACF;AACF,CAAC;;;;;;;;AASH,MAAa,SACX,QACyE;CACzE,MAAM,QAAQ,MAAM,OAAO,WAAW,KAAK,GAAG,CAAC;CAC/C,MAAM,UAAU,MAAM,OACpB,eACA,OAAO,IAAI,KAAK,GAAG,IAAI,OAA6B;EAClD,aAAa,YAAY,EAAE,WAAW,OAA2B;EACjE,OAAO,YAAY,EAAE,KAAK,OAA2B;CACvD,EAAE,CACJ;CACA,OAAO,MAAM,MAAM,OAAO,OAAO;AACnC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect-uai/responses",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0-dev-20261110202152",
|
|
4
4
|
"description": "OpenAI Responses API provider for @effect-uai/core.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -57,11 +57,11 @@
|
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"effect": "4.1.2",
|
|
59
59
|
"typescript": "^7.0.2",
|
|
60
|
-
"@effect-uai/core": "0.
|
|
60
|
+
"@effect-uai/core": "0.20.0-dev-20261110202152"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"@effect-uai/core": "0.
|
|
64
|
-
"effect": ">=4.0
|
|
63
|
+
"@effect-uai/core": "0.20.0-dev-20261110202152",
|
|
64
|
+
"effect": ">=4.1.0 <5.0.0"
|
|
65
65
|
},
|
|
66
66
|
"scripts": {
|
|
67
67
|
"build": "tsdown",
|
package/src/Responses.ts
CHANGED
|
@@ -36,13 +36,19 @@ import {
|
|
|
36
36
|
// Public types
|
|
37
37
|
// ---------------------------------------------------------------------------
|
|
38
38
|
|
|
39
|
+
export type ReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh"
|
|
40
|
+
|
|
39
41
|
export type ResponsesRequest = Omit<CommonRequest, "model"> & {
|
|
40
42
|
/**
|
|
41
43
|
* Narrows `CommonRequest.model` (`string`) to the typed `OpenAIModel`
|
|
42
44
|
* literal union for autocomplete.
|
|
43
45
|
*/
|
|
44
46
|
readonly model: OpenAIModel
|
|
45
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Reasoning effort. Which values a model accepts varies: `none` (GPT-5.1+),
|
|
49
|
+
* `minimal` (GPT-5), `xhigh` (GPT-5.2+); `low` / `medium` / `high` everywhere.
|
|
50
|
+
*/
|
|
51
|
+
readonly reasoning?: { readonly effort: ReasoningEffort }
|
|
46
52
|
readonly store?: boolean
|
|
47
53
|
readonly previousResponseId?: string
|
|
48
54
|
readonly instructions?: string
|