@effect-uai/responses 0.9.0 → 0.11.0
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/OpenAIDeepResearch.d.mts +54 -0
- package/dist/OpenAIDeepResearch.d.mts.map +1 -0
- package/dist/OpenAIDeepResearch.mjs +121 -0
- package/dist/OpenAIDeepResearch.mjs.map +1 -0
- package/dist/OpenAIEmbedding.mjs +1 -1
- package/dist/OpenAIEmbedding.mjs.map +1 -1
- package/dist/Responses.d.mts +13 -3
- package/dist/Responses.d.mts.map +1 -1
- package/dist/Responses.mjs +68 -33
- package/dist/Responses.mjs.map +1 -1
- package/dist/ResponsesTools.d.mts +85 -0
- package/dist/ResponsesTools.d.mts.map +1 -0
- package/dist/ResponsesTools.mjs +126 -0
- package/dist/ResponsesTools.mjs.map +1 -0
- package/dist/codec.d.mts +42 -3
- package/dist/codec.d.mts.map +1 -1
- package/dist/codec.mjs +28 -9
- package/dist/codec.mjs.map +1 -1
- package/dist/index.d.mts +5 -3
- package/dist/index.mjs +5 -3
- package/dist/{magic-string.es-PAZgLX4h.mjs → magic-string.es-CaWgF-3p.mjs} +1 -1
- package/dist/{magic-string.es-PAZgLX4h.mjs.map → magic-string.es-CaWgF-3p.mjs.map} +1 -1
- package/dist/models.d.mts +10 -1
- package/dist/models.d.mts.map +1 -1
- package/dist/region.test.mjs +1 -13630
- package/dist/region.test.mjs.map +1 -1
- package/dist/responsesTools.test.d.mts +1 -0
- package/dist/responsesTools.test.mjs +138 -0
- package/dist/responsesTools.test.mjs.map +1 -0
- package/dist/streamEvents.d.mts +142 -0
- package/dist/streamEvents.d.mts.map +1 -1
- package/dist/streamEvents.mjs +27 -2
- package/dist/streamEvents.mjs.map +1 -1
- package/dist/test.DNmyFkvJ-CPKukVWS.mjs +13633 -0
- package/dist/test.DNmyFkvJ-CPKukVWS.mjs.map +1 -0
- package/package.json +8 -4
- package/src/OpenAIDeepResearch.ts +266 -0
- package/src/OpenAIEmbedding.ts +1 -1
- package/src/Responses.ts +94 -36
- package/src/ResponsesTools.ts +158 -0
- package/src/codec.ts +62 -26
- package/src/index.ts +2 -0
- package/src/models.ts +14 -0
- package/src/responsesTools.test.ts +146 -0
- package/src/streamEvents.ts +58 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { codeInterpreterTool, fileSearchTool, renderProviderTools, webSearchTool } from "./ResponsesTools.mjs";
|
|
2
|
+
import { KnownProviderEvent, eventToDeltas, makeCallIdLookup } from "./streamEvents.mjs";
|
|
3
|
+
import { n as describe, r as it, t as globalExpect } from "./test.DNmyFkvJ-CPKukVWS.mjs";
|
|
4
|
+
import { Result, Schema } from "effect";
|
|
5
|
+
import * as Tool from "@effect-uai/core/Tool";
|
|
6
|
+
import { providerToolsOf } from "@effect-uai/core/Tool";
|
|
7
|
+
//#region src/responsesTools.test.ts
|
|
8
|
+
const wireFor = (toolkit) => Result.getOrThrow(renderProviderTools(providerToolsOf(toolkit)));
|
|
9
|
+
describe("Responses provider tool rendering", () => {
|
|
10
|
+
it("maps web_search options onto the native wire fields", () => {
|
|
11
|
+
globalExpect(wireFor({ web_search: webSearchTool({
|
|
12
|
+
searchContextSize: "high",
|
|
13
|
+
filters: {
|
|
14
|
+
allowedDomains: ["example.com"],
|
|
15
|
+
blockedDomains: ["spam.com"]
|
|
16
|
+
},
|
|
17
|
+
userLocation: {
|
|
18
|
+
city: "Berlin",
|
|
19
|
+
country: "DE"
|
|
20
|
+
}
|
|
21
|
+
}) })).toEqual([{
|
|
22
|
+
type: "web_search",
|
|
23
|
+
filters: {
|
|
24
|
+
allowed_domains: ["example.com"],
|
|
25
|
+
blocked_domains: ["spam.com"]
|
|
26
|
+
},
|
|
27
|
+
user_location: {
|
|
28
|
+
type: "approximate",
|
|
29
|
+
city: "Berlin",
|
|
30
|
+
country: "DE"
|
|
31
|
+
},
|
|
32
|
+
search_context_size: "high"
|
|
33
|
+
}]);
|
|
34
|
+
});
|
|
35
|
+
it("maps code_interpreter to an auto container (with file ids when given)", () => {
|
|
36
|
+
globalExpect(wireFor({ ci: codeInterpreterTool() })).toEqual([{
|
|
37
|
+
type: "code_interpreter",
|
|
38
|
+
container: { type: "auto" }
|
|
39
|
+
}]);
|
|
40
|
+
globalExpect(wireFor({ ci: codeInterpreterTool({ fileIds: ["file_1"] }) })).toEqual([{
|
|
41
|
+
type: "code_interpreter",
|
|
42
|
+
container: {
|
|
43
|
+
type: "auto",
|
|
44
|
+
file_ids: ["file_1"]
|
|
45
|
+
}
|
|
46
|
+
}]);
|
|
47
|
+
});
|
|
48
|
+
it("maps file_search to its vector store ids", () => {
|
|
49
|
+
globalExpect(wireFor({ fs: fileSearchTool({ vectorStoreIds: ["vs_1", "vs_2"] }) })).toEqual([{
|
|
50
|
+
type: "file_search",
|
|
51
|
+
vector_store_ids: ["vs_1", "vs_2"]
|
|
52
|
+
}]);
|
|
53
|
+
});
|
|
54
|
+
it("fails on a tool hosted by a different provider", () => {
|
|
55
|
+
const foreign = Tool.provider({
|
|
56
|
+
name: "google_search",
|
|
57
|
+
description: "Gemini grounding.",
|
|
58
|
+
inputSchema: Tool.noInput,
|
|
59
|
+
provider: "gemini",
|
|
60
|
+
config: { kind: "google_search" }
|
|
61
|
+
});
|
|
62
|
+
globalExpect(Result.isFailure(renderProviderTools(providerToolsOf({ foreign })))).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
it("fails on an unrecognized config", () => {
|
|
65
|
+
const bogus = Tool.provider({
|
|
66
|
+
name: "mystery",
|
|
67
|
+
description: "Unknown Responses tool.",
|
|
68
|
+
inputSchema: Tool.noInput,
|
|
69
|
+
provider: "openai",
|
|
70
|
+
config: { kind: "telepathy" }
|
|
71
|
+
});
|
|
72
|
+
globalExpect(Result.isFailure(renderProviderTools(providerToolsOf({ bogus })))).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
describe("Responses hosted-tool response tolerance", () => {
|
|
76
|
+
const decodeEvent = Schema.decodeUnknownSync(KnownProviderEvent);
|
|
77
|
+
it("emits TurnComplete with just the text answer for a grounded completion", () => {
|
|
78
|
+
const complete = eventToDeltas(decodeEvent({
|
|
79
|
+
type: "response.completed",
|
|
80
|
+
response: {
|
|
81
|
+
status: "completed",
|
|
82
|
+
output: [{
|
|
83
|
+
type: "web_search_call",
|
|
84
|
+
id: "ws_1",
|
|
85
|
+
status: "completed"
|
|
86
|
+
}, {
|
|
87
|
+
type: "message",
|
|
88
|
+
role: "assistant",
|
|
89
|
+
content: [{
|
|
90
|
+
type: "output_text",
|
|
91
|
+
text: "Grounded answer."
|
|
92
|
+
}]
|
|
93
|
+
}]
|
|
94
|
+
}
|
|
95
|
+
}), makeCallIdLookup()).find((d) => d._tag === "TurnComplete");
|
|
96
|
+
globalExpect(complete).toBeDefined();
|
|
97
|
+
const turn = complete?._tag === "TurnComplete" ? complete.turn : void 0;
|
|
98
|
+
globalExpect(turn?.stop_reason).toBe("stop");
|
|
99
|
+
globalExpect(turn?.items).toEqual([{
|
|
100
|
+
type: "message",
|
|
101
|
+
role: "assistant",
|
|
102
|
+
content: [{
|
|
103
|
+
type: "output_text",
|
|
104
|
+
text: "Grounded answer."
|
|
105
|
+
}],
|
|
106
|
+
providerData: globalExpect.anything()
|
|
107
|
+
}]);
|
|
108
|
+
});
|
|
109
|
+
it("projects a streamed url_citation to CitationAdded", () => {
|
|
110
|
+
globalExpect(eventToDeltas(decodeEvent({
|
|
111
|
+
type: "response.output_text.annotation.added",
|
|
112
|
+
item_id: "msg_1",
|
|
113
|
+
output_index: 0,
|
|
114
|
+
content_index: 0,
|
|
115
|
+
annotation_index: 0,
|
|
116
|
+
annotation: {
|
|
117
|
+
type: "url_citation",
|
|
118
|
+
url: "https://example.com/a",
|
|
119
|
+
title: "A",
|
|
120
|
+
start_index: 10,
|
|
121
|
+
end_index: 20
|
|
122
|
+
}
|
|
123
|
+
}), makeCallIdLookup())).toEqual([{
|
|
124
|
+
_tag: "CitationAdded",
|
|
125
|
+
annotation: {
|
|
126
|
+
type: "url_citation",
|
|
127
|
+
url: "https://example.com/a",
|
|
128
|
+
title: "A",
|
|
129
|
+
start_index: 10,
|
|
130
|
+
end_index: 20
|
|
131
|
+
}
|
|
132
|
+
}]);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
//#endregion
|
|
136
|
+
export {};
|
|
137
|
+
|
|
138
|
+
//# sourceMappingURL=responsesTools.test.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responsesTools.test.mjs","names":["expect"],"sources":["../src/responsesTools.test.ts"],"sourcesContent":["import { Result, Schema } from \"effect\"\nimport * as Tool from \"@effect-uai/core/Tool\"\nimport { providerToolsOf } from \"@effect-uai/core/Tool\"\nimport { describe, expect, it } from \"vitest\"\nimport { KnownProviderEvent, eventToDeltas, makeCallIdLookup } from \"./streamEvents.js\"\nimport {\n codeInterpreterTool,\n fileSearchTool,\n renderProviderTools,\n webSearchTool,\n} from \"./ResponsesTools.js\"\n\nconst wireFor = (toolkit: Record<string, Tool.AnyTool>) =>\n Result.getOrThrow(renderProviderTools(providerToolsOf(toolkit)))\n\ndescribe(\"Responses provider tool rendering\", () => {\n it(\"maps web_search options onto the native wire fields\", () => {\n expect(\n wireFor({\n web_search: webSearchTool({\n searchContextSize: \"high\",\n filters: { allowedDomains: [\"example.com\"], blockedDomains: [\"spam.com\"] },\n userLocation: { city: \"Berlin\", country: \"DE\" },\n }),\n }),\n ).toEqual([\n {\n type: \"web_search\",\n filters: { allowed_domains: [\"example.com\"], blocked_domains: [\"spam.com\"] },\n user_location: { type: \"approximate\", city: \"Berlin\", country: \"DE\" },\n search_context_size: \"high\",\n },\n ])\n })\n\n it(\"maps code_interpreter to an auto container (with file ids when given)\", () => {\n expect(wireFor({ ci: codeInterpreterTool() })).toEqual([\n { type: \"code_interpreter\", container: { type: \"auto\" } },\n ])\n expect(wireFor({ ci: codeInterpreterTool({ fileIds: [\"file_1\"] }) })).toEqual([\n { type: \"code_interpreter\", container: { type: \"auto\", file_ids: [\"file_1\"] } },\n ])\n })\n\n it(\"maps file_search to its vector store ids\", () => {\n expect(wireFor({ fs: fileSearchTool({ vectorStoreIds: [\"vs_1\", \"vs_2\"] }) })).toEqual([\n { type: \"file_search\", vector_store_ids: [\"vs_1\", \"vs_2\"] },\n ])\n })\n\n it(\"fails on a tool hosted by a different provider\", () => {\n const foreign = Tool.provider({\n name: \"google_search\",\n description: \"Gemini grounding.\",\n inputSchema: Tool.noInput,\n provider: \"gemini\",\n config: { kind: \"google_search\" },\n })\n expect(Result.isFailure(renderProviderTools(providerToolsOf({ foreign })))).toBe(true)\n })\n\n it(\"fails on an unrecognized config\", () => {\n const bogus = Tool.provider({\n name: \"mystery\",\n description: \"Unknown Responses tool.\",\n inputSchema: Tool.noInput,\n provider: \"openai\",\n config: { kind: \"telepathy\" },\n })\n expect(Result.isFailure(renderProviderTools(providerToolsOf({ bogus })))).toBe(true)\n })\n})\n\ndescribe(\"Responses hosted-tool response tolerance\", () => {\n // The real regression: a hosted-tool output item in `response.completed` must\n // not break the event decode, or `TurnComplete` would never fire. Decoding\n // through the actual event schema (throws on failure) and projecting to\n // TurnEvents proves the grounded text still assembles into a turn.\n const decodeEvent = Schema.decodeUnknownSync(KnownProviderEvent)\n\n it(\"emits TurnComplete with just the text answer for a grounded completion\", () => {\n const event = decodeEvent({\n type: \"response.completed\",\n response: {\n status: \"completed\",\n output: [\n { type: \"web_search_call\", id: \"ws_1\", status: \"completed\" },\n {\n type: \"message\",\n role: \"assistant\",\n content: [{ type: \"output_text\", text: \"Grounded answer.\" }],\n },\n ],\n },\n })\n const deltas = eventToDeltas(event, makeCallIdLookup())\n const complete = deltas.find((d) => d._tag === \"TurnComplete\")\n expect(complete).toBeDefined()\n const turn = complete?._tag === \"TurnComplete\" ? complete.turn : undefined\n expect(turn?.stop_reason).toBe(\"stop\")\n expect(turn?.items).toEqual([\n {\n type: \"message\",\n role: \"assistant\",\n content: [{ type: \"output_text\", text: \"Grounded answer.\" }],\n providerData: expect.anything(),\n },\n ])\n })\n\n // The new streamed-citation path: a real `annotation.added` payload (with the\n // wire's positional fields) must decode and project to a `CitationAdded`\n // carrying a domain `Annotation`. This is what makes native-grounding\n // citations stream instead of only landing on the final turn.\n it(\"projects a streamed url_citation to CitationAdded\", () => {\n const deltas = eventToDeltas(\n decodeEvent({\n type: \"response.output_text.annotation.added\",\n item_id: \"msg_1\",\n output_index: 0,\n content_index: 0,\n annotation_index: 0,\n annotation: {\n type: \"url_citation\",\n url: \"https://example.com/a\",\n title: \"A\",\n start_index: 10,\n end_index: 20,\n },\n }),\n makeCallIdLookup(),\n )\n expect(deltas).toEqual([\n {\n _tag: \"CitationAdded\",\n annotation: {\n type: \"url_citation\",\n url: \"https://example.com/a\",\n title: \"A\",\n start_index: 10,\n end_index: 20,\n },\n },\n ])\n })\n})\n"],"mappings":";;;;;;;AAYA,MAAM,WAAW,YACf,OAAO,WAAW,oBAAoB,gBAAgB,QAAQ,CAAC,CAAC;AAElE,SAAS,2CAA2C;AAClD,IAAG,6DAA6D;AAC9D,eACE,QAAQ,EACN,YAAY,cAAc;GACxB,mBAAmB;GACnB,SAAS;IAAE,gBAAgB,CAAC,cAAc;IAAE,gBAAgB,CAAC,WAAW;IAAE;GAC1E,cAAc;IAAE,MAAM;IAAU,SAAS;IAAM;GAChD,CAAC,EACH,CAAC,CACH,CAAC,QAAQ,CACR;GACE,MAAM;GACN,SAAS;IAAE,iBAAiB,CAAC,cAAc;IAAE,iBAAiB,CAAC,WAAW;IAAE;GAC5E,eAAe;IAAE,MAAM;IAAe,MAAM;IAAU,SAAS;IAAM;GACrE,qBAAqB;GACtB,CACF,CAAC;GACF;AAEF,IAAG,+EAA+E;AAChF,eAAO,QAAQ,EAAE,IAAI,qBAAqB,EAAE,CAAC,CAAC,CAAC,QAAQ,CACrD;GAAE,MAAM;GAAoB,WAAW,EAAE,MAAM,QAAQ;GAAE,CAC1D,CAA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GACF,CACiC,EAAE,kBAAkB,CAC/B,CAAC,MAAM,MAAM,EAAE,SAAS,eAAe;AAC9D,eAAO,SAAS,CAAC,aAAa;EAC9B,MAAM,OAAO,UAAU,SAAS,iBAAiB,SAAS,OAAO,KAAA;AACjE,eAAO,MAAM,YAAY,CAAC,KAAK,OAAO;AACtC,eAAO,MAAM,MAAM,CAAC,QAAQ,CAC1B;GACE,MAAM;GACN,MAAM;GACN,SAAS,CAAC;IAAE,MAAM;IAAe,MAAM;IAAoB,CAAC;GAC5D,cAAcA,aAAO,UAAU;GAChC,CACF,CAAC;GACF;AAMF,IAAG,2DAA2D;AAkB5D,eAjBe,cACb,YAAY;GACV,MAAM;GACN,SAAS;GACT,cAAc;GACd,eAAe;GACf,kBAAkB;GAClB,YAAY;IACV,MAAM;IACN,KAAK;IACL,OAAO;IACP,aAAa;IACb,WAAW;IACZ;GACF,CAAC,EACF,kBAAkB,CAEP,CAAC,CAAC,QAAQ,CACrB;GACE,MAAM;GACN,YAAY;IACV,MAAM;IACN,KAAK;IACL,OAAO;IACP,aAAa;IACb,WAAW;IACZ;GACF,CACF,CAAC;GACF;EACF"}
|
package/dist/streamEvents.d.mts
CHANGED
|
@@ -57,6 +57,15 @@ declare const KnownProviderEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
57
57
|
readonly text: Schema.String;
|
|
58
58
|
}>>>;
|
|
59
59
|
readonly encrypted_content: Schema.optional<Schema.String>;
|
|
60
|
+
}>, Schema.Struct<{
|
|
61
|
+
readonly type: Schema.Literal<"web_search_call">;
|
|
62
|
+
readonly id: Schema.optional<Schema.String>;
|
|
63
|
+
}>, Schema.Struct<{
|
|
64
|
+
readonly type: Schema.Literal<"code_interpreter_call">;
|
|
65
|
+
readonly id: Schema.optional<Schema.String>;
|
|
66
|
+
}>, Schema.Struct<{
|
|
67
|
+
readonly type: Schema.Literal<"file_search_call">;
|
|
68
|
+
readonly id: Schema.optional<Schema.String>;
|
|
60
69
|
}>]>;
|
|
61
70
|
}>, Schema.Struct<{
|
|
62
71
|
readonly type: Schema.Literal<"response.output_text.delta">;
|
|
@@ -77,6 +86,35 @@ declare const KnownProviderEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
77
86
|
}>, Schema.Struct<{
|
|
78
87
|
readonly type: Schema.Literal<"response.refusal.done">;
|
|
79
88
|
readonly refusal: Schema.optional<Schema.String>;
|
|
89
|
+
}>, Schema.Struct<{
|
|
90
|
+
readonly type: Schema.Literal<"response.web_search_call.in_progress">;
|
|
91
|
+
}>, Schema.Struct<{
|
|
92
|
+
readonly type: Schema.Literal<"response.web_search_call.searching">;
|
|
93
|
+
}>, Schema.Struct<{
|
|
94
|
+
readonly type: Schema.Literal<"response.web_search_call.completed">;
|
|
95
|
+
}>, Schema.Struct<{
|
|
96
|
+
readonly type: Schema.Literal<"response.output_text.annotation.added">;
|
|
97
|
+
readonly annotation: Schema.Union<readonly [Schema.Struct<{
|
|
98
|
+
readonly type: Schema.Literal<"url_citation">;
|
|
99
|
+
readonly url: Schema.String;
|
|
100
|
+
readonly start_index: Schema.Number;
|
|
101
|
+
readonly end_index: Schema.Number;
|
|
102
|
+
readonly title: Schema.String;
|
|
103
|
+
}>, Schema.Struct<{
|
|
104
|
+
readonly type: Schema.Literal<"file_citation">;
|
|
105
|
+
readonly file_id: Schema.String;
|
|
106
|
+
readonly index: Schema.Number;
|
|
107
|
+
}>, Schema.Struct<{
|
|
108
|
+
readonly type: Schema.Literal<"container_file_citation">;
|
|
109
|
+
readonly container_id: Schema.String;
|
|
110
|
+
readonly file_id: Schema.String;
|
|
111
|
+
readonly start_index: Schema.Number;
|
|
112
|
+
readonly end_index: Schema.Number;
|
|
113
|
+
}>, Schema.Struct<{
|
|
114
|
+
readonly type: Schema.Literal<"file_path">;
|
|
115
|
+
readonly file_id: Schema.String;
|
|
116
|
+
readonly index: Schema.Number;
|
|
117
|
+
}>]>;
|
|
80
118
|
}>, Schema.Struct<{
|
|
81
119
|
readonly type: Schema.Literal<"response.completed">;
|
|
82
120
|
readonly response: Schema.Struct<{
|
|
@@ -128,6 +166,15 @@ declare const KnownProviderEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
128
166
|
readonly text: Schema.String;
|
|
129
167
|
}>>>;
|
|
130
168
|
readonly encrypted_content: Schema.optional<Schema.String>;
|
|
169
|
+
}>, Schema.Struct<{
|
|
170
|
+
readonly type: Schema.Literal<"web_search_call">;
|
|
171
|
+
readonly id: Schema.optional<Schema.String>;
|
|
172
|
+
}>, Schema.Struct<{
|
|
173
|
+
readonly type: Schema.Literal<"code_interpreter_call">;
|
|
174
|
+
readonly id: Schema.optional<Schema.String>;
|
|
175
|
+
}>, Schema.Struct<{
|
|
176
|
+
readonly type: Schema.Literal<"file_search_call">;
|
|
177
|
+
readonly id: Schema.optional<Schema.String>;
|
|
131
178
|
}>]>>>>;
|
|
132
179
|
readonly usage: Schema.optional<Schema.NullOr<Schema.Struct<{
|
|
133
180
|
readonly input_tokens: Schema.optional<Schema.Number>;
|
|
@@ -199,6 +246,15 @@ declare const KnownProviderEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
199
246
|
readonly text: Schema.String;
|
|
200
247
|
}>>>;
|
|
201
248
|
readonly encrypted_content: Schema.optional<Schema.String>;
|
|
249
|
+
}>, Schema.Struct<{
|
|
250
|
+
readonly type: Schema.Literal<"web_search_call">;
|
|
251
|
+
readonly id: Schema.optional<Schema.String>;
|
|
252
|
+
}>, Schema.Struct<{
|
|
253
|
+
readonly type: Schema.Literal<"code_interpreter_call">;
|
|
254
|
+
readonly id: Schema.optional<Schema.String>;
|
|
255
|
+
}>, Schema.Struct<{
|
|
256
|
+
readonly type: Schema.Literal<"file_search_call">;
|
|
257
|
+
readonly id: Schema.optional<Schema.String>;
|
|
202
258
|
}>]>>>>;
|
|
203
259
|
readonly usage: Schema.optional<Schema.NullOr<Schema.Struct<{
|
|
204
260
|
readonly input_tokens: Schema.optional<Schema.Number>;
|
|
@@ -270,6 +326,15 @@ declare const KnownProviderEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
270
326
|
readonly text: Schema.String;
|
|
271
327
|
}>>>;
|
|
272
328
|
readonly encrypted_content: Schema.optional<Schema.String>;
|
|
329
|
+
}>, Schema.Struct<{
|
|
330
|
+
readonly type: Schema.Literal<"web_search_call">;
|
|
331
|
+
readonly id: Schema.optional<Schema.String>;
|
|
332
|
+
}>, Schema.Struct<{
|
|
333
|
+
readonly type: Schema.Literal<"code_interpreter_call">;
|
|
334
|
+
readonly id: Schema.optional<Schema.String>;
|
|
335
|
+
}>, Schema.Struct<{
|
|
336
|
+
readonly type: Schema.Literal<"file_search_call">;
|
|
337
|
+
readonly id: Schema.optional<Schema.String>;
|
|
273
338
|
}>]>>>>;
|
|
274
339
|
readonly usage: Schema.optional<Schema.NullOr<Schema.Struct<{
|
|
275
340
|
readonly input_tokens: Schema.optional<Schema.Number>;
|
|
@@ -294,6 +359,12 @@ declare const KnownProviderEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
294
359
|
readonly type: Schema.Literal<"error">;
|
|
295
360
|
readonly message: Schema.optional<Schema.String>;
|
|
296
361
|
readonly code: Schema.optional<Schema.String>;
|
|
362
|
+
readonly error: Schema.optional<Schema.Struct<{
|
|
363
|
+
readonly message: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
364
|
+
readonly code: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
365
|
+
readonly type: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
366
|
+
readonly param: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
367
|
+
}>>;
|
|
297
368
|
}>]>;
|
|
298
369
|
/**
|
|
299
370
|
* Public: every event the native stream can emit. Discriminated on `type`.
|
|
@@ -348,6 +419,15 @@ declare const ProviderEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
348
419
|
readonly text: Schema.String;
|
|
349
420
|
}>>>;
|
|
350
421
|
readonly encrypted_content: Schema.optional<Schema.String>;
|
|
422
|
+
}>, Schema.Struct<{
|
|
423
|
+
readonly type: Schema.Literal<"web_search_call">;
|
|
424
|
+
readonly id: Schema.optional<Schema.String>;
|
|
425
|
+
}>, Schema.Struct<{
|
|
426
|
+
readonly type: Schema.Literal<"code_interpreter_call">;
|
|
427
|
+
readonly id: Schema.optional<Schema.String>;
|
|
428
|
+
}>, Schema.Struct<{
|
|
429
|
+
readonly type: Schema.Literal<"file_search_call">;
|
|
430
|
+
readonly id: Schema.optional<Schema.String>;
|
|
351
431
|
}>]>;
|
|
352
432
|
}>, Schema.Struct<{
|
|
353
433
|
readonly type: Schema.Literal<"response.output_text.delta">;
|
|
@@ -368,6 +448,35 @@ declare const ProviderEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
368
448
|
}>, Schema.Struct<{
|
|
369
449
|
readonly type: Schema.Literal<"response.refusal.done">;
|
|
370
450
|
readonly refusal: Schema.optional<Schema.String>;
|
|
451
|
+
}>, Schema.Struct<{
|
|
452
|
+
readonly type: Schema.Literal<"response.web_search_call.in_progress">;
|
|
453
|
+
}>, Schema.Struct<{
|
|
454
|
+
readonly type: Schema.Literal<"response.web_search_call.searching">;
|
|
455
|
+
}>, Schema.Struct<{
|
|
456
|
+
readonly type: Schema.Literal<"response.web_search_call.completed">;
|
|
457
|
+
}>, Schema.Struct<{
|
|
458
|
+
readonly type: Schema.Literal<"response.output_text.annotation.added">;
|
|
459
|
+
readonly annotation: Schema.Union<readonly [Schema.Struct<{
|
|
460
|
+
readonly type: Schema.Literal<"url_citation">;
|
|
461
|
+
readonly url: Schema.String;
|
|
462
|
+
readonly start_index: Schema.Number;
|
|
463
|
+
readonly end_index: Schema.Number;
|
|
464
|
+
readonly title: Schema.String;
|
|
465
|
+
}>, Schema.Struct<{
|
|
466
|
+
readonly type: Schema.Literal<"file_citation">;
|
|
467
|
+
readonly file_id: Schema.String;
|
|
468
|
+
readonly index: Schema.Number;
|
|
469
|
+
}>, Schema.Struct<{
|
|
470
|
+
readonly type: Schema.Literal<"container_file_citation">;
|
|
471
|
+
readonly container_id: Schema.String;
|
|
472
|
+
readonly file_id: Schema.String;
|
|
473
|
+
readonly start_index: Schema.Number;
|
|
474
|
+
readonly end_index: Schema.Number;
|
|
475
|
+
}>, Schema.Struct<{
|
|
476
|
+
readonly type: Schema.Literal<"file_path">;
|
|
477
|
+
readonly file_id: Schema.String;
|
|
478
|
+
readonly index: Schema.Number;
|
|
479
|
+
}>]>;
|
|
371
480
|
}>, Schema.Struct<{
|
|
372
481
|
readonly type: Schema.Literal<"response.completed">;
|
|
373
482
|
readonly response: Schema.Struct<{
|
|
@@ -419,6 +528,15 @@ declare const ProviderEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
419
528
|
readonly text: Schema.String;
|
|
420
529
|
}>>>;
|
|
421
530
|
readonly encrypted_content: Schema.optional<Schema.String>;
|
|
531
|
+
}>, Schema.Struct<{
|
|
532
|
+
readonly type: Schema.Literal<"web_search_call">;
|
|
533
|
+
readonly id: Schema.optional<Schema.String>;
|
|
534
|
+
}>, Schema.Struct<{
|
|
535
|
+
readonly type: Schema.Literal<"code_interpreter_call">;
|
|
536
|
+
readonly id: Schema.optional<Schema.String>;
|
|
537
|
+
}>, Schema.Struct<{
|
|
538
|
+
readonly type: Schema.Literal<"file_search_call">;
|
|
539
|
+
readonly id: Schema.optional<Schema.String>;
|
|
422
540
|
}>]>>>>;
|
|
423
541
|
readonly usage: Schema.optional<Schema.NullOr<Schema.Struct<{
|
|
424
542
|
readonly input_tokens: Schema.optional<Schema.Number>;
|
|
@@ -490,6 +608,15 @@ declare const ProviderEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
490
608
|
readonly text: Schema.String;
|
|
491
609
|
}>>>;
|
|
492
610
|
readonly encrypted_content: Schema.optional<Schema.String>;
|
|
611
|
+
}>, Schema.Struct<{
|
|
612
|
+
readonly type: Schema.Literal<"web_search_call">;
|
|
613
|
+
readonly id: Schema.optional<Schema.String>;
|
|
614
|
+
}>, Schema.Struct<{
|
|
615
|
+
readonly type: Schema.Literal<"code_interpreter_call">;
|
|
616
|
+
readonly id: Schema.optional<Schema.String>;
|
|
617
|
+
}>, Schema.Struct<{
|
|
618
|
+
readonly type: Schema.Literal<"file_search_call">;
|
|
619
|
+
readonly id: Schema.optional<Schema.String>;
|
|
493
620
|
}>]>>>>;
|
|
494
621
|
readonly usage: Schema.optional<Schema.NullOr<Schema.Struct<{
|
|
495
622
|
readonly input_tokens: Schema.optional<Schema.Number>;
|
|
@@ -561,6 +688,15 @@ declare const ProviderEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
561
688
|
readonly text: Schema.String;
|
|
562
689
|
}>>>;
|
|
563
690
|
readonly encrypted_content: Schema.optional<Schema.String>;
|
|
691
|
+
}>, Schema.Struct<{
|
|
692
|
+
readonly type: Schema.Literal<"web_search_call">;
|
|
693
|
+
readonly id: Schema.optional<Schema.String>;
|
|
694
|
+
}>, Schema.Struct<{
|
|
695
|
+
readonly type: Schema.Literal<"code_interpreter_call">;
|
|
696
|
+
readonly id: Schema.optional<Schema.String>;
|
|
697
|
+
}>, Schema.Struct<{
|
|
698
|
+
readonly type: Schema.Literal<"file_search_call">;
|
|
699
|
+
readonly id: Schema.optional<Schema.String>;
|
|
564
700
|
}>]>>>>;
|
|
565
701
|
readonly usage: Schema.optional<Schema.NullOr<Schema.Struct<{
|
|
566
702
|
readonly input_tokens: Schema.optional<Schema.Number>;
|
|
@@ -585,6 +721,12 @@ declare const ProviderEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
585
721
|
readonly type: Schema.Literal<"error">;
|
|
586
722
|
readonly message: Schema.optional<Schema.String>;
|
|
587
723
|
readonly code: Schema.optional<Schema.String>;
|
|
724
|
+
readonly error: Schema.optional<Schema.Struct<{
|
|
725
|
+
readonly message: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
726
|
+
readonly code: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
727
|
+
readonly type: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
728
|
+
readonly param: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
729
|
+
}>>;
|
|
588
730
|
}>, Schema.Struct<{
|
|
589
731
|
readonly type: Schema.Literal<"_unknown">;
|
|
590
732
|
readonly raw: Schema.Unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streamEvents.d.mts","names":[],"sources":["../src/streamEvents.ts"],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"streamEvents.d.mts","names":[],"sources":["../src/streamEvents.ts"],"mappings":";;;;;;;;;;;cAuHa,kBAAA,EAAkB,MAAA,CAAA,KAAA,WAAA,MAAA,CAAA,MAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAuBlB,aAAA,EAAa,MAAA,CAAA,KAAA,WAAA,MAAA,CAAA,MAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAkBd,aAAA,UAAuB,aAAA,CAAc,IAAA;AAAA,KAKrC,YAAA;EAAA,SACD,OAAA,GAAU,MAAA;EAAA,SACV,QAAA,GAAW,MAAA,UAAgB,MAAA;AAAA;AAAA,cAGzB,gBAAA,QAAuB,YAAA;;;;;;;cAgBvB,aAAA,GACX,KAAA,EAAO,aAAA,EACP,MAAA,EAAQ,YAAA,KACP,aAAA,CAAc,SAAA"}
|
package/dist/streamEvents.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-CfYAbeIz.mjs";
|
|
2
|
-
import { WireOutputItem, WireResponseCompleted, turnFromCompleted } from "./codec.mjs";
|
|
2
|
+
import { WireAnnotation, WireOutputItem, WireResponseCompleted, turnFromCompleted } from "./codec.mjs";
|
|
3
3
|
import { Match, Schema } from "effect";
|
|
4
4
|
import { TurnEvent } from "@effect-uai/core/Turn";
|
|
5
5
|
//#region src/streamEvents.ts
|
|
@@ -38,6 +38,13 @@ const RefusalDone = Schema.Struct({
|
|
|
38
38
|
type: Schema.Literal("response.refusal.done"),
|
|
39
39
|
refusal: Schema.optional(Schema.String)
|
|
40
40
|
});
|
|
41
|
+
const WebSearchInProgress = Schema.Struct({ type: Schema.Literal("response.web_search_call.in_progress") });
|
|
42
|
+
const WebSearchSearching = Schema.Struct({ type: Schema.Literal("response.web_search_call.searching") });
|
|
43
|
+
const WebSearchCompleted = Schema.Struct({ type: Schema.Literal("response.web_search_call.completed") });
|
|
44
|
+
const AnnotationAdded = Schema.Struct({
|
|
45
|
+
type: Schema.Literal("response.output_text.annotation.added"),
|
|
46
|
+
annotation: WireAnnotation
|
|
47
|
+
});
|
|
41
48
|
const Completed = Schema.Struct({
|
|
42
49
|
type: Schema.Literal("response.completed"),
|
|
43
50
|
response: WireResponseCompleted
|
|
@@ -53,7 +60,13 @@ const Failed = Schema.Struct({
|
|
|
53
60
|
const ErrorEvent = Schema.Struct({
|
|
54
61
|
type: Schema.Literal("error"),
|
|
55
62
|
message: Schema.optional(Schema.String),
|
|
56
|
-
code: Schema.optional(Schema.String)
|
|
63
|
+
code: Schema.optional(Schema.String),
|
|
64
|
+
error: Schema.optional(Schema.Struct({
|
|
65
|
+
message: Schema.optional(Schema.NullOr(Schema.String)),
|
|
66
|
+
code: Schema.optional(Schema.NullOr(Schema.String)),
|
|
67
|
+
type: Schema.optional(Schema.NullOr(Schema.String)),
|
|
68
|
+
param: Schema.optional(Schema.NullOr(Schema.String))
|
|
69
|
+
}))
|
|
57
70
|
});
|
|
58
71
|
/**
|
|
59
72
|
* Catch-all variant for wire events that fail to decode against any known
|
|
@@ -77,6 +90,10 @@ const KnownProviderEvent = Schema.Union([
|
|
|
77
90
|
ReasoningSummaryDelta,
|
|
78
91
|
RefusalDelta,
|
|
79
92
|
RefusalDone,
|
|
93
|
+
WebSearchInProgress,
|
|
94
|
+
WebSearchSearching,
|
|
95
|
+
WebSearchCompleted,
|
|
96
|
+
AnnotationAdded,
|
|
80
97
|
Completed,
|
|
81
98
|
Incomplete,
|
|
82
99
|
Failed,
|
|
@@ -95,6 +112,10 @@ const ProviderEvent = Schema.Union([
|
|
|
95
112
|
ReasoningSummaryDelta,
|
|
96
113
|
RefusalDelta,
|
|
97
114
|
RefusalDone,
|
|
115
|
+
WebSearchInProgress,
|
|
116
|
+
WebSearchSearching,
|
|
117
|
+
WebSearchCompleted,
|
|
118
|
+
AnnotationAdded,
|
|
98
119
|
Completed,
|
|
99
120
|
Incomplete,
|
|
100
121
|
Failed,
|
|
@@ -143,6 +164,10 @@ const eventToDeltas = (event, lookup) => Match.value(event).pipe(Match.discrimin
|
|
|
143
164
|
})],
|
|
144
165
|
"response.refusal.delta": ({ delta }) => [TurnEvent.RefusalDelta({ text: delta })],
|
|
145
166
|
"response.refusal.done": () => [],
|
|
167
|
+
"response.web_search_call.in_progress": () => [TurnEvent.WebSearchCall({ status: "started" })],
|
|
168
|
+
"response.web_search_call.searching": () => [TurnEvent.WebSearchCall({ status: "searching" })],
|
|
169
|
+
"response.web_search_call.completed": () => [TurnEvent.WebSearchCall({ status: "completed" })],
|
|
170
|
+
"response.output_text.annotation.added": ({ annotation }) => [TurnEvent.CitationAdded({ annotation })],
|
|
146
171
|
"response.completed": ({ response }) => [TurnEvent.TurnComplete({ turn: turnFromCompleted(response) })],
|
|
147
172
|
"response.incomplete": ({ response }) => [TurnEvent.TurnComplete({ turn: turnFromCompleted(response) })],
|
|
148
173
|
"response.failed": () => [],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streamEvents.mjs","names":[],"sources":["../src/streamEvents.ts"],"sourcesContent":["import { Match, Schema } from \"effect\"\nimport { TurnEvent } from \"@effect-uai/core/Turn\"\nimport { WireOutputItem, WireResponseCompleted, turnFromCompleted } from \"./codec.js\"\n\n// ---------------------------------------------------------------------------\n// Schemas for the SSE event payloads we care about. The Responses API ships\n// many event types; we model only the ones that map to a `TurnEvent`. All\n// others are silently ignored at the dispatch site.\n// ---------------------------------------------------------------------------\n\nconst OutputItemAdded = Schema.Struct({\n type: Schema.Literal(\"response.output_item.added\"),\n item: WireOutputItem,\n})\n\nconst OutputTextDelta = Schema.Struct({\n type: Schema.Literal(\"response.output_text.delta\"),\n delta: Schema.String,\n})\n\nconst FunctionArgsDelta = Schema.Struct({\n type: Schema.Literal(\"response.function_call_arguments.delta\"),\n item_id: Schema.String,\n delta: Schema.String,\n})\n\nconst ReasoningTextDelta = Schema.Struct({\n type: Schema.Literal(\"response.reasoning_text.delta\"),\n delta: Schema.String,\n})\n\nconst ReasoningSummaryDelta = Schema.Struct({\n type: Schema.Literal(\"response.reasoning_summary_text.delta\"),\n delta: Schema.String,\n})\n\nconst RefusalDelta = Schema.Struct({\n type: Schema.Literal(\"response.refusal.delta\"),\n delta: Schema.String,\n})\n\nconst RefusalDone = Schema.Struct({\n type: Schema.Literal(\"response.refusal.done\"),\n refusal: Schema.optional(Schema.String),\n})\n\nconst Completed = Schema.Struct({\n type: Schema.Literal(\"response.completed\"),\n response: WireResponseCompleted,\n})\n\nconst Incomplete = Schema.Struct({\n type: Schema.Literal(\"response.incomplete\"),\n response: WireResponseCompleted,\n})\n\nconst Failed = Schema.Struct({\n type: Schema.Literal(\"response.failed\"),\n response: WireResponseCompleted,\n})\n\nconst ErrorEvent = Schema.Struct({\n type: Schema.Literal(\"error\"),\n message: Schema.optional(Schema.String),\n code: Schema.optional(Schema.String),\n})\n\n/**\n * Catch-all variant for wire events that fail to decode against any known\n * schema, plus events that fail to JSON-parse. The decoder never produces\n * this directly - it's synthesized by `sseEventToProviderEvent` when\n * `decodeKnown` fails.\n */\nconst Unknown = Schema.Struct({\n type: Schema.Literal(\"_unknown\"),\n raw: Schema.Unknown,\n})\n\n/**\n * Internal: union of variants we actually know how to decode from the wire.\n * Used as the decode target; failures are caught and re-emitted as `Unknown`.\n */\nexport const KnownProviderEvent = Schema.Union([\n OutputItemAdded,\n OutputTextDelta,\n FunctionArgsDelta,\n ReasoningTextDelta,\n ReasoningSummaryDelta,\n RefusalDelta,\n RefusalDone,\n Completed,\n Incomplete,\n Failed,\n ErrorEvent,\n])\n\n/**\n * Public: every event the native stream can emit. Discriminated on `type`.\n * The `_unknown` branch closes the cardinality so downstream `Match.exhaustive`\n * cannot silently miss a wire event we didn't model.\n */\nexport const ProviderEvent = Schema.Union([\n OutputItemAdded,\n OutputTextDelta,\n FunctionArgsDelta,\n ReasoningTextDelta,\n ReasoningSummaryDelta,\n RefusalDelta,\n RefusalDone,\n Completed,\n Incomplete,\n Failed,\n ErrorEvent,\n Unknown,\n])\nexport type ProviderEvent = typeof ProviderEvent.Type\n\n// `call_id` lookup for `function_call_arguments.delta`. The SSE event\n// references the *item id*, not the call id; we keep a small map populated\n// from the `output_item.added` events.\nexport type CallIdLookup = {\n readonly resolve: (itemId: string) => string | undefined\n readonly remember: (itemId: string, callId: string) => void\n}\n\nexport const makeCallIdLookup = (): CallIdLookup => {\n const map = new Map<string, string>()\n return {\n resolve: (id) => map.get(id),\n remember: (id, callId) => {\n map.set(id, callId)\n },\n }\n}\n\n/**\n * Translate a decoded provider event into zero-or-more `TurnEvent`s.\n * Mutates `lookup` to record `(item_id → call_id)` from `output_item.added`\n * so subsequent `function_call_arguments.delta` events can be tagged with\n * the right call id.\n */\nexport const eventToDeltas = (\n event: ProviderEvent,\n lookup: CallIdLookup,\n): ReadonlyArray<TurnEvent> =>\n Match.value(event).pipe(\n Match.discriminatorsExhaustive(\"type\")({\n \"response.output_item.added\": ({ item }) => {\n if (item.type !== \"function_call\") return []\n if (item.id !== undefined) lookup.remember(item.id, item.call_id)\n return [TurnEvent.ToolCallStart({ call_id: item.call_id, name: item.name })]\n },\n \"response.output_text.delta\": ({ delta }) => [TurnEvent.TextDelta({ text: delta })],\n \"response.function_call_arguments.delta\": ({ item_id, delta }) => {\n const call_id = lookup.resolve(item_id)\n return call_id === undefined ? [] : [TurnEvent.ToolCallArgsDelta({ call_id, delta })]\n },\n \"response.reasoning_text.delta\": ({ delta }) => [\n TurnEvent.ReasoningDelta({ text: delta, kind: \"trace\" }),\n ],\n \"response.reasoning_summary_text.delta\": ({ delta }) => [\n TurnEvent.ReasoningDelta({ text: delta, kind: \"summary\" }),\n ],\n \"response.refusal.delta\": ({ delta }) => [TurnEvent.RefusalDelta({ text: delta })],\n // Terminal marker for the refusal stream; the deltas already covered\n // the text, so no canonical event is emitted here.\n \"response.refusal.done\": () => [],\n \"response.completed\": ({ response }) => [\n TurnEvent.TurnComplete({ turn: turnFromCompleted(response) }),\n ],\n // Incomplete = the model stopped early but produced a usable partial\n // turn (max_tokens, content_filter, max_tool_calls, refusal). Same\n // payload shape as `response.completed`; the stop_reason carries the\n // reason.\n \"response.incomplete\": ({ response }) => [\n TurnEvent.TurnComplete({ turn: turnFromCompleted(response) }),\n ],\n // Failed and error are surfaced separately as `AiError` by the stream\n // pipeline, not as canonical events.\n \"response.failed\": () => [],\n error: () => [],\n // No silent drops: unknown wire events flow through `streamNative` but\n // produce no canonical delta. Step 3 (canonical `other` event) replaces\n // this with a forwarded `other` delta on `TurnEvent`.\n _unknown: () => [],\n }),\n )\n"],"mappings":";;;;;;;;;;;AAUA,MAAM,kBAAkB,OAAO,OAAO;CACpC,MAAM,OAAO,QAAQ,6BAA6B;CAClD,MAAM;CACP,CAAC;AAEF,MAAM,kBAAkB,OAAO,OAAO;CACpC,MAAM,OAAO,QAAQ,6BAA6B;CAClD,OAAO,OAAO;CACf,CAAC;AAEF,MAAM,oBAAoB,OAAO,OAAO;CACtC,MAAM,OAAO,QAAQ,yCAAyC;CAC9D,SAAS,OAAO;CAChB,OAAO,OAAO;CACf,CAAC;AAEF,MAAM,qBAAqB,OAAO,OAAO;CACvC,MAAM,OAAO,QAAQ,gCAAgC;CACrD,OAAO,OAAO;CACf,CAAC;AAEF,MAAM,wBAAwB,OAAO,OAAO;CAC1C,MAAM,OAAO,QAAQ,wCAAwC;CAC7D,OAAO,OAAO;CACf,CAAC;AAEF,MAAM,eAAe,OAAO,OAAO;CACjC,MAAM,OAAO,QAAQ,yBAAyB;CAC9C,OAAO,OAAO;CACf,CAAC;AAEF,MAAM,cAAc,OAAO,OAAO;CAChC,MAAM,OAAO,QAAQ,wBAAwB;CAC7C,SAAS,OAAO,SAAS,OAAO,OAAO;CACxC,CAAC;AAEF,MAAM,YAAY,OAAO,OAAO;CAC9B,MAAM,OAAO,QAAQ,qBAAqB;CAC1C,UAAU;CACX,CAAC;AAEF,MAAM,aAAa,OAAO,OAAO;CAC/B,MAAM,OAAO,QAAQ,sBAAsB;CAC3C,UAAU;CACX,CAAC;AAEF,MAAM,SAAS,OAAO,OAAO;CAC3B,MAAM,OAAO,QAAQ,kBAAkB;CACvC,UAAU;CACX,CAAC;AAEF,MAAM,aAAa,OAAO,OAAO;CAC/B,MAAM,OAAO,QAAQ,QAAQ;CAC7B,SAAS,OAAO,SAAS,OAAO,OAAO;CACvC,MAAM,O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AAW,CAAC,CAC3D;CACD,2BAA2B,EAAE,YAAY,CAAC,UAAU,aAAa,EAAE,MAAM,OAAO,CAAC,CAAC;CAGlF,+BAA+B,EAAE;CACjC,uBAAuB,EAAE,eAAe,CACtC,UAAU,aAAa,EAAE,MAAM,kBAAkB,SAAS,EAAE,CAAC,CAC9D;CAKD,wBAAwB,EAAE,eAAe,CACvC,UAAU,aAAa,EAAE,MAAM,kBAAkB,SAAS,EAAE,CAAC,CAC9D;CAGD,yBAAyB,EAAE;CAC3B,aAAa,EAAE;CAIf,gBAAgB,EAAE;CACnB,CAAC,CACH"}
|
|
1
|
+
{"version":3,"file":"streamEvents.mjs","names":[],"sources":["../src/streamEvents.ts"],"sourcesContent":["import { Match, Schema } from \"effect\"\nimport { TurnEvent } from \"@effect-uai/core/Turn\"\nimport {\n WireAnnotation,\n WireOutputItem,\n WireResponseCompleted,\n turnFromCompleted,\n} from \"./codec.js\"\n\n// ---------------------------------------------------------------------------\n// Schemas for the SSE event payloads we care about. The Responses API ships\n// many event types; we model only the ones that map to a `TurnEvent`. All\n// others are silently ignored at the dispatch site.\n// ---------------------------------------------------------------------------\n\nconst OutputItemAdded = Schema.Struct({\n type: Schema.Literal(\"response.output_item.added\"),\n item: WireOutputItem,\n})\n\nconst OutputTextDelta = Schema.Struct({\n type: Schema.Literal(\"response.output_text.delta\"),\n delta: Schema.String,\n})\n\nconst FunctionArgsDelta = Schema.Struct({\n type: Schema.Literal(\"response.function_call_arguments.delta\"),\n item_id: Schema.String,\n delta: Schema.String,\n})\n\nconst ReasoningTextDelta = Schema.Struct({\n type: Schema.Literal(\"response.reasoning_text.delta\"),\n delta: Schema.String,\n})\n\nconst ReasoningSummaryDelta = Schema.Struct({\n type: Schema.Literal(\"response.reasoning_summary_text.delta\"),\n delta: Schema.String,\n})\n\nconst RefusalDelta = Schema.Struct({\n type: Schema.Literal(\"response.refusal.delta\"),\n delta: Schema.String,\n})\n\nconst RefusalDone = Schema.Struct({\n type: Schema.Literal(\"response.refusal.done\"),\n refusal: Schema.optional(Schema.String),\n})\n\n// Web-search lifecycle. The three phases carry `item_id` / `output_index` /\n// `sequence_number`; we map each to a `WebSearchCall` status. `query` / `action`\n// ride on the `web_search_call` output item, not these lifecycle events.\nconst WebSearchInProgress = Schema.Struct({\n type: Schema.Literal(\"response.web_search_call.in_progress\"),\n})\n\nconst WebSearchSearching = Schema.Struct({\n type: Schema.Literal(\"response.web_search_call.searching\"),\n})\n\nconst WebSearchCompleted = Schema.Struct({\n type: Schema.Literal(\"response.web_search_call.completed\"),\n})\n\n// A citation attached to the answer as it is written. `annotation` is the\n// same shape as the ones bundled on the final `output_text` block.\nconst AnnotationAdded = Schema.Struct({\n type: Schema.Literal(\"response.output_text.annotation.added\"),\n annotation: WireAnnotation,\n})\n\nconst Completed = Schema.Struct({\n type: Schema.Literal(\"response.completed\"),\n response: WireResponseCompleted,\n})\n\nconst Incomplete = Schema.Struct({\n type: Schema.Literal(\"response.incomplete\"),\n response: WireResponseCompleted,\n})\n\nconst Failed = Schema.Struct({\n type: Schema.Literal(\"response.failed\"),\n response: WireResponseCompleted,\n})\n\nconst ErrorEvent = Schema.Struct({\n type: Schema.Literal(\"error\"),\n // Flat form (top-level `message`/`code`) and the nested form the Responses API\n // uses for request rejections: `error: { message, code, type, param }`.\n message: Schema.optional(Schema.String),\n code: Schema.optional(Schema.String),\n error: Schema.optional(\n Schema.Struct({\n message: Schema.optional(Schema.NullOr(Schema.String)),\n code: Schema.optional(Schema.NullOr(Schema.String)),\n type: Schema.optional(Schema.NullOr(Schema.String)),\n param: Schema.optional(Schema.NullOr(Schema.String)),\n }),\n ),\n})\n\n/**\n * Catch-all variant for wire events that fail to decode against any known\n * schema, plus events that fail to JSON-parse. The decoder never produces\n * this directly - it's synthesized by `sseEventToProviderEvent` when\n * `decodeKnown` fails.\n */\nconst Unknown = Schema.Struct({\n type: Schema.Literal(\"_unknown\"),\n raw: Schema.Unknown,\n})\n\n/**\n * Internal: union of variants we actually know how to decode from the wire.\n * Used as the decode target; failures are caught and re-emitted as `Unknown`.\n */\nexport const KnownProviderEvent = Schema.Union([\n OutputItemAdded,\n OutputTextDelta,\n FunctionArgsDelta,\n ReasoningTextDelta,\n ReasoningSummaryDelta,\n RefusalDelta,\n RefusalDone,\n WebSearchInProgress,\n WebSearchSearching,\n WebSearchCompleted,\n AnnotationAdded,\n Completed,\n Incomplete,\n Failed,\n ErrorEvent,\n])\n\n/**\n * Public: every event the native stream can emit. Discriminated on `type`.\n * The `_unknown` branch closes the cardinality so downstream `Match.exhaustive`\n * cannot silently miss a wire event we didn't model.\n */\nexport const ProviderEvent = Schema.Union([\n OutputItemAdded,\n OutputTextDelta,\n FunctionArgsDelta,\n ReasoningTextDelta,\n ReasoningSummaryDelta,\n RefusalDelta,\n RefusalDone,\n WebSearchInProgress,\n WebSearchSearching,\n WebSearchCompleted,\n AnnotationAdded,\n Completed,\n Incomplete,\n Failed,\n ErrorEvent,\n Unknown,\n])\nexport type ProviderEvent = typeof ProviderEvent.Type\n\n// `call_id` lookup for `function_call_arguments.delta`. The SSE event\n// references the *item id*, not the call id; we keep a small map populated\n// from the `output_item.added` events.\nexport type CallIdLookup = {\n readonly resolve: (itemId: string) => string | undefined\n readonly remember: (itemId: string, callId: string) => void\n}\n\nexport const makeCallIdLookup = (): CallIdLookup => {\n const map = new Map<string, string>()\n return {\n resolve: (id) => map.get(id),\n remember: (id, callId) => {\n map.set(id, callId)\n },\n }\n}\n\n/**\n * Translate a decoded provider event into zero-or-more `TurnEvent`s.\n * Mutates `lookup` to record `(item_id → call_id)` from `output_item.added`\n * so subsequent `function_call_arguments.delta` events can be tagged with\n * the right call id.\n */\nexport const eventToDeltas = (\n event: ProviderEvent,\n lookup: CallIdLookup,\n): ReadonlyArray<TurnEvent> =>\n Match.value(event).pipe(\n Match.discriminatorsExhaustive(\"type\")({\n \"response.output_item.added\": ({ item }) => {\n if (item.type !== \"function_call\") return []\n if (item.id !== undefined) lookup.remember(item.id, item.call_id)\n return [TurnEvent.ToolCallStart({ call_id: item.call_id, name: item.name })]\n },\n \"response.output_text.delta\": ({ delta }) => [TurnEvent.TextDelta({ text: delta })],\n \"response.function_call_arguments.delta\": ({ item_id, delta }) => {\n const call_id = lookup.resolve(item_id)\n return call_id === undefined ? [] : [TurnEvent.ToolCallArgsDelta({ call_id, delta })]\n },\n \"response.reasoning_text.delta\": ({ delta }) => [\n TurnEvent.ReasoningDelta({ text: delta, kind: \"trace\" }),\n ],\n \"response.reasoning_summary_text.delta\": ({ delta }) => [\n TurnEvent.ReasoningDelta({ text: delta, kind: \"summary\" }),\n ],\n \"response.refusal.delta\": ({ delta }) => [TurnEvent.RefusalDelta({ text: delta })],\n // Terminal marker for the refusal stream; the deltas already covered\n // the text, so no canonical event is emitted here.\n \"response.refusal.done\": () => [],\n \"response.web_search_call.in_progress\": () => [\n TurnEvent.WebSearchCall({ status: \"started\" }),\n ],\n \"response.web_search_call.searching\": () => [\n TurnEvent.WebSearchCall({ status: \"searching\" }),\n ],\n \"response.web_search_call.completed\": () => [\n TurnEvent.WebSearchCall({ status: \"completed\" }),\n ],\n \"response.output_text.annotation.added\": ({ annotation }) => [\n TurnEvent.CitationAdded({ annotation }),\n ],\n \"response.completed\": ({ response }) => [\n TurnEvent.TurnComplete({ turn: turnFromCompleted(response) }),\n ],\n // Incomplete = the model stopped early but produced a usable partial\n // turn (max_tokens, content_filter, max_tool_calls, refusal). Same\n // payload shape as `response.completed`; the stop_reason carries the\n // reason.\n \"response.incomplete\": ({ response }) => [\n TurnEvent.TurnComplete({ turn: turnFromCompleted(response) }),\n ],\n // Failed and error are surfaced separately as `AiError` by the stream\n // pipeline, not as canonical events.\n \"response.failed\": () => [],\n error: () => [],\n // No silent drops: unknown wire events flow through `streamNative` but\n // produce no canonical delta. Step 3 (canonical `other` event) replaces\n // this with a forwarded `other` delta on `TurnEvent`.\n _unknown: () => [],\n }),\n )\n"],"mappings":";;;;;;;;;;;AAeA,MAAM,kBAAkB,OAAO,OAAO;CACp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