@effect-uai/ui 0.0.0-stage → 0.17.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.
Files changed (76) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +64 -2
  3. package/dist/Atoms.d.mts +141 -0
  4. package/dist/Atoms.d.mts.map +1 -0
  5. package/dist/Atoms.mjs +132 -0
  6. package/dist/Atoms.mjs.map +1 -0
  7. package/dist/Client-C9UYN_VK.d.mts +219 -0
  8. package/dist/Client-C9UYN_VK.d.mts.map +1 -0
  9. package/dist/Client.d.mts +2 -0
  10. package/dist/Client.mjs +55 -0
  11. package/dist/Client.mjs.map +1 -0
  12. package/dist/Input-Cz-Kxusm.d.mts +277 -0
  13. package/dist/Input-Cz-Kxusm.d.mts.map +1 -0
  14. package/dist/Input.d.mts +2 -0
  15. package/dist/Input.mjs +127 -0
  16. package/dist/Input.mjs.map +1 -0
  17. package/dist/Projection.d.mts +44 -0
  18. package/dist/Projection.d.mts.map +1 -0
  19. package/dist/Projection.mjs +133 -0
  20. package/dist/Projection.mjs.map +1 -0
  21. package/dist/Run.d.mts +44 -0
  22. package/dist/Run.d.mts.map +1 -0
  23. package/dist/Run.mjs +117 -0
  24. package/dist/Run.mjs.map +1 -0
  25. package/dist/RunEvent.d.mts +1225 -0
  26. package/dist/RunEvent.d.mts.map +1 -0
  27. package/dist/RunEvent.mjs +264 -0
  28. package/dist/RunEvent.mjs.map +1 -0
  29. package/dist/RunView-nHfJwN8t.d.mts +380 -0
  30. package/dist/RunView-nHfJwN8t.d.mts.map +1 -0
  31. package/dist/RunView.d.mts +2 -0
  32. package/dist/RunView.mjs +452 -0
  33. package/dist/RunView.mjs.map +1 -0
  34. package/dist/SseEncoding.d.mts +437 -0
  35. package/dist/SseEncoding.d.mts.map +1 -0
  36. package/dist/SseEncoding.mjs +64 -0
  37. package/dist/SseEncoding.mjs.map +1 -0
  38. package/dist/Thread-CAXsjhpX.d.mts +474 -0
  39. package/dist/Thread-CAXsjhpX.d.mts.map +1 -0
  40. package/dist/Thread.d.mts +2 -0
  41. package/dist/Thread.mjs +225 -0
  42. package/dist/Thread.mjs.map +1 -0
  43. package/dist/Transport.d.mts +96 -0
  44. package/dist/Transport.d.mts.map +1 -0
  45. package/dist/Transport.mjs +82 -0
  46. package/dist/Transport.mjs.map +1 -0
  47. package/dist/UiContract.d.mts +114 -0
  48. package/dist/UiContract.d.mts.map +1 -0
  49. package/dist/UiContract.mjs +229 -0
  50. package/dist/UiContract.mjs.map +1 -0
  51. package/dist/index.d.mts +12 -0
  52. package/dist/index.mjs +12 -0
  53. package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
  54. package/package.json +99 -3
  55. package/src/Atoms.test.ts +163 -0
  56. package/src/Atoms.ts +355 -0
  57. package/src/Client.test.ts +53 -0
  58. package/src/Client.ts +92 -0
  59. package/src/Input.test.ts +68 -0
  60. package/src/Input.ts +165 -0
  61. package/src/Projection.test.ts +198 -0
  62. package/src/Projection.ts +142 -0
  63. package/src/Run.test.ts +119 -0
  64. package/src/Run.ts +166 -0
  65. package/src/RunEvent.test.ts +84 -0
  66. package/src/RunEvent.ts +374 -0
  67. package/src/RunView.test.ts +98 -0
  68. package/src/RunView.ts +583 -0
  69. package/src/SseEncoding.test.ts +46 -0
  70. package/src/SseEncoding.ts +77 -0
  71. package/src/Thread.test.ts +304 -0
  72. package/src/Thread.ts +286 -0
  73. package/src/Transport.ts +182 -0
  74. package/src/UiContract.test.ts +342 -0
  75. package/src/UiContract.ts +402 -0
  76. package/src/index.ts +11 -0
@@ -0,0 +1,55 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
+ import { EnvelopeJson, isTerminal } from "./RunEvent.mjs";
3
+ import { decode } from "./SseEncoding.mjs";
4
+ import { Data, Effect, Ref, Stream } from "effect";
5
+ import { Ndjson } from "effect/encoding";
6
+ import { HttpClient } from "effect/http";
7
+ //#region src/Client.ts
8
+ /**
9
+ * Browser-safe sources of envelopes. Every source yields
10
+ * `Stream<Envelope>`; `resumable` adds reconnect-from-last-seq on top of
11
+ * any of them. HTTP goes through `effect/http`'s `HttpClient`, so a browser
12
+ * provides `FetchHttpClient.layer` and tests provide a fake client.
13
+ */
14
+ var Client_exports = /* @__PURE__ */ __exportAll({
15
+ Disconnected: () => Disconnected,
16
+ execute: () => execute,
17
+ ndjson: () => ndjson,
18
+ resumable: () => resumable,
19
+ sse: () => sse
20
+ });
21
+ /** The connection ended before the run's terminal event arrived. */
22
+ var Disconnected = class extends Data.TaggedError("Disconnected") {};
23
+ /** Run a request, failing on a non-2xx status. */
24
+ const execute = (request) => HttpClient.HttpClient.pipe(Effect.flatMap((client) => HttpClient.filterStatusOk(client).execute(request)));
25
+ const body = (request) => Stream.unwrap(Effect.map(execute(request), (response) => response.stream));
26
+ /** An SSE response (`text/event-stream`) as envelopes. */
27
+ const sse = (request) => body(request).pipe(decode);
28
+ /** An NDJSON response (one envelope per line) as envelopes. */
29
+ const ndjson = (request) => body(request).pipe(Stream.pipeThroughChannelOrFail(Ndjson.decodeSchema(EnvelopeJson)()));
30
+ /**
31
+ * Keep events flowing across dropped connections: `connect(after)` is
32
+ * re-invoked with the last seen `seq` on failure, per `schedule`; duplicates
33
+ * are dropped. A connection that ends cleanly before the end counts as a
34
+ * failure (`Disconnected`), so it is retried too.
35
+ *
36
+ * `until: "terminal"` (default) follows one run and completes after its
37
+ * terminal. `until: "never"` follows a session stream that carries many runs
38
+ * (a durable chat) and never completes on its own.
39
+ */
40
+ const resumable = (connect, options) => Stream.unwrap(Effect.gen(function* () {
41
+ const untilTerminal = options.until !== "never";
42
+ const ends = (envelope) => untilTerminal && isTerminal(envelope.event);
43
+ const position = yield* Ref.make({
44
+ seq: options.from ?? 0,
45
+ done: false
46
+ });
47
+ return Stream.unwrap(Ref.get(position).pipe(Effect.map(({ seq: after }) => connect(after).pipe(Stream.filterEffect((envelope) => Ref.modify(position, (p) => envelope.seq > p.seq ? [true, {
48
+ seq: envelope.seq,
49
+ done: ends(envelope)
50
+ }] : [false, p])), Stream.takeUntil(ends), Stream.concat(Stream.unwrap(Ref.get(position).pipe(Effect.map((p) => p.done ? Stream.empty : Stream.fail(new Disconnected({ lastSeq: p.seq })))))))))).pipe(Stream.retry(options.schedule));
51
+ }));
52
+ //#endregion
53
+ export { Disconnected, execute, ndjson, resumable, sse, Client_exports as t };
54
+
55
+ //# sourceMappingURL=Client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Client.mjs","names":["SseEncoding.decode"],"sources":["../src/Client.ts"],"sourcesContent":["/**\n * Browser-safe sources of envelopes. Every source yields\n * `Stream<Envelope>`; `resumable` adds reconnect-from-last-seq on top of\n * any of them. HTTP goes through `effect/http`'s `HttpClient`, so a browser\n * provides `FetchHttpClient.layer` and tests provide a fake client.\n */\nimport { Data, Effect, Ref, type Schedule, type Schema, Stream } from \"effect\"\nimport { Ndjson, type Sse } from \"effect/encoding\"\nimport { HttpClient, type HttpClientError, type HttpClientRequest } from \"effect/http\"\nimport { type Envelope, EnvelopeJson, isTerminal } from \"./RunEvent.js\"\nimport * as SseEncoding from \"./SseEncoding.js\"\n\n/** The connection ended before the run's terminal event arrived. */\nexport class Disconnected extends Data.TaggedError(\"Disconnected\")<{ readonly lastSeq: number }> {}\n\n/** What an HTTP source can fail with: transport, a malformed SSE frame, or a malformed NDJSON line. */\nexport type ClientError =\n | HttpClientError.HttpClientError\n | Schema.SchemaError\n | Sse.Retry\n | Sse.SseError\n | Ndjson.NdjsonError\n\n/** Run a request, failing on a non-2xx status. */\nexport const execute = (request: HttpClientRequest.HttpClientRequest) =>\n HttpClient.HttpClient.pipe(\n Effect.flatMap((client) => HttpClient.filterStatusOk(client).execute(request)),\n )\n\nconst body = (request: HttpClientRequest.HttpClientRequest) =>\n Stream.unwrap(Effect.map(execute(request), (response) => response.stream))\n\n/** An SSE response (`text/event-stream`) as envelopes. */\nexport const sse = (request: HttpClientRequest.HttpClientRequest) =>\n body(request).pipe(SseEncoding.decode)\n\n/** An NDJSON response (one envelope per line) as envelopes. */\nexport const ndjson = (request: HttpClientRequest.HttpClientRequest) =>\n body(request).pipe(Stream.pipeThroughChannelOrFail(Ndjson.decodeSchema(EnvelopeJson)()))\n\n/**\n * Keep events flowing across dropped connections: `connect(after)` is\n * re-invoked with the last seen `seq` on failure, per `schedule`; duplicates\n * are dropped. A connection that ends cleanly before the end counts as a\n * failure (`Disconnected`), so it is retried too.\n *\n * `until: \"terminal\"` (default) follows one run and completes after its\n * terminal. `until: \"never\"` follows a session stream that carries many runs\n * (a durable chat) and never completes on its own.\n */\nexport const resumable = <E, R, X>(\n connect: (after: number) => Stream.Stream<Envelope, E, R>,\n options: {\n readonly from?: number\n readonly until?: \"terminal\" | \"never\"\n readonly schedule: Schedule.Schedule<X, E | Disconnected>\n },\n): Stream.Stream<Envelope, E | Disconnected, R> =>\n Stream.unwrap(\n Effect.gen(function* () {\n const untilTerminal = options.until !== \"never\"\n const ends = (envelope: Envelope) => untilTerminal && isTerminal(envelope.event)\n // The last seen seq, and whether the run's terminal arrived.\n const position = yield* Ref.make({ seq: options.from ?? 0, done: false })\n const attempt = Stream.unwrap(\n Ref.get(position).pipe(\n Effect.map(({ seq: after }) =>\n connect(after).pipe(\n Stream.filterEffect((envelope) =>\n Ref.modify(position, (p) =>\n envelope.seq > p.seq\n ? [true, { seq: envelope.seq, done: ends(envelope) }]\n : [false, p],\n ),\n ),\n Stream.takeUntil(ends),\n Stream.concat(\n Stream.unwrap(\n Ref.get(position).pipe(\n Effect.map((p) =>\n p.done ? Stream.empty : Stream.fail(new Disconnected({ lastSeq: p.seq })),\n ),\n ),\n ),\n ),\n ),\n ),\n ),\n )\n return attempt.pipe(Stream.retry(options.schedule))\n }),\n )\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAaA,IAAa,eAAb,cAAkC,KAAK,YAAY,cAAc,CAAC,CAA+B,CAAC;;AAWlG,MAAa,WAAW,YACtB,WAAW,WAAW,KACpB,OAAO,SAAS,WAAW,WAAW,eAAe,MAAM,CAAC,CAAC,QAAQ,OAAO,CAAC,CAC/E;AAEF,MAAM,QAAQ,YACZ,OAAO,OAAO,OAAO,IAAI,QAAQ,OAAO,IAAI,aAAa,SAAS,MAAM,CAAC;;AAG3E,MAAa,OAAO,YAClB,KAAK,OAAO,CAAC,CAAC,KAAKA,MAAkB;;AAGvC,MAAa,UAAU,YACrB,KAAK,OAAO,CAAC,CAAC,KAAK,OAAO,yBAAyB,OAAO,aAAa,YAAY,CAAC,CAAC,CAAC,CAAC;;;;;;;;;;;AAYzF,MAAa,aACX,SACA,YAMA,OAAO,OACL,OAAO,IAAI,aAAa;CACtB,MAAM,gBAAgB,QAAQ,UAAU;CACxC,MAAM,QAAQ,aAAuB,iBAAiB,WAAW,SAAS,KAAK;CAE/E,MAAM,WAAW,OAAO,IAAI,KAAK;EAAE,KAAK,QAAQ,QAAQ;EAAG,MAAM;CAAM,CAAC;CA0BxE,OAzBgB,OAAO,OACrB,IAAI,IAAI,QAAQ,CAAC,CAAC,KAChB,OAAO,KAAK,EAAE,KAAK,YACjB,QAAQ,KAAK,CAAC,CAAC,KACb,OAAO,cAAc,aACnB,IAAI,OAAO,WAAW,MACpB,SAAS,MAAM,EAAE,MACb,CAAC,MAAM;EAAE,KAAK,SAAS;EAAK,MAAM,KAAK,QAAQ;CAAE,CAAC,IAClD,CAAC,OAAO,CAAC,CACf,CACF,GACA,OAAO,UAAU,IAAI,GACrB,OAAO,OACL,OAAO,OACL,IAAI,IAAI,QAAQ,CAAC,CAAC,KAChB,OAAO,KAAK,MACV,EAAE,OAAO,OAAO,QAAQ,OAAO,KAAK,IAAI,aAAa,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC,CAC1E,CACF,CACF,CACF,CACF,CACF,CACF,CAEW,CAAC,CAAC,KAAK,OAAO,MAAM,QAAQ,QAAQ,CAAC;AACpD,CAAC,CACH"}
@@ -0,0 +1,277 @@
1
+ import { InputId } from "./RunEvent.mjs";
2
+ import { Effect, Schema } from "effect";
3
+ import * as ToolDecision from "@effect-uai/core/ToolDecision";
4
+ import { SecureRandom } from "effect/crypto";
5
+ declare namespace Input_d_exports {
6
+ export { Content, Decision, Draft, Identified, Input, InputJson, Resolve, ResolveDraft, Sent, Submit, SubmitJson, UserMessage, answer, make, resolve, submit, text, user, withId };
7
+ }
8
+ /** A user message: core's `message` item with role `user` and input blocks only. */
9
+ declare const UserMessage: Schema.Struct<{
10
+ readonly type: Schema.Literal<"message">;
11
+ readonly role: Schema.Literal<"user">;
12
+ readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
13
+ readonly type: Schema.Literal<"input_text">;
14
+ readonly text: Schema.String;
15
+ }>, Schema.Struct<{
16
+ readonly type: Schema.Literal<"input_image">;
17
+ readonly source: Schema.Codec<import("@effect-uai/core/Image").ImageSource, import("@effect-uai/core/Image").ImageSource, never, never>;
18
+ }>]>>;
19
+ }>;
20
+ type UserMessage = typeof UserMessage.Type;
21
+ type Content = UserMessage["content"][number];
22
+ /** The answer to one waiting call, with a decision of the app's `ToolDecision.make`. */
23
+ declare const answer: <D extends Schema.Top>(decision: D) => Schema.Struct<{
24
+ readonly callId: Schema.String;
25
+ readonly decision: D;
26
+ }>;
27
+ /** The default answer: `ToolDecision.Default` (approve, or deny with an optional reason). */
28
+ declare const Decision: Schema.Struct<{
29
+ readonly callId: Schema.String;
30
+ readonly decision: Schema.Codec<ToolDecision.DecisionOf<{
31
+ readonly Approve: {};
32
+ readonly Deny: ToolDecision.Closing<{
33
+ readonly reason: Schema.optionalKey<Schema.String>;
34
+ }, ToolDecision.Denied>;
35
+ }>, unknown, never, never>;
36
+ }>;
37
+ type Decision = typeof Decision.Type;
38
+ declare const Submit: Schema.Struct<{
39
+ id: Schema.brand<Schema.String, "InputId">;
40
+ kind: Schema.Literal<"submit">;
41
+ messages: Schema.$Array<Schema.Struct<{
42
+ readonly type: Schema.Literal<"message">;
43
+ readonly role: Schema.Literal<"user">;
44
+ readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
45
+ readonly type: Schema.Literal<"input_text">;
46
+ readonly text: Schema.String;
47
+ }>, Schema.Struct<{
48
+ readonly type: Schema.Literal<"input_image">;
49
+ readonly source: Schema.Codec<import("@effect-uai/core/Image").ImageSource, import("@effect-uai/core/Image").ImageSource, never, never>;
50
+ }>]>>;
51
+ }>>;
52
+ }>;
53
+ type Submit = typeof Submit.Type;
54
+ declare const Resolve: Schema.Struct<{
55
+ id: Schema.brand<Schema.String, "InputId">;
56
+ kind: Schema.Literal<"resolve">;
57
+ decisions: Schema.$Array<Schema.Struct<{
58
+ readonly callId: Schema.String;
59
+ readonly decision: Schema.Codec<ToolDecision.DecisionOf<{
60
+ readonly Approve: {};
61
+ readonly Deny: ToolDecision.Closing<{
62
+ readonly reason: Schema.optionalKey<Schema.String>;
63
+ }, ToolDecision.Denied>;
64
+ }>, unknown, never, never>;
65
+ }>>;
66
+ }>;
67
+ type Resolve = typeof Resolve.Type;
68
+ declare const Input: Schema.Union<readonly [Schema.Struct<{
69
+ id: Schema.brand<Schema.String, "InputId">;
70
+ kind: Schema.Literal<"submit">;
71
+ messages: Schema.$Array<Schema.Struct<{
72
+ readonly type: Schema.Literal<"message">;
73
+ readonly role: Schema.Literal<"user">;
74
+ readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
75
+ readonly type: Schema.Literal<"input_text">;
76
+ readonly text: Schema.String;
77
+ }>, Schema.Struct<{
78
+ readonly type: Schema.Literal<"input_image">;
79
+ readonly source: Schema.Codec<import("@effect-uai/core/Image").ImageSource, import("@effect-uai/core/Image").ImageSource, never, never>;
80
+ }>]>>;
81
+ }>>;
82
+ }>, Schema.Struct<{
83
+ id: Schema.brand<Schema.String, "InputId">;
84
+ kind: Schema.Literal<"resolve">;
85
+ decisions: Schema.$Array<Schema.Struct<{
86
+ readonly callId: Schema.String;
87
+ readonly decision: Schema.Codec<ToolDecision.DecisionOf<{
88
+ readonly Approve: {};
89
+ readonly Deny: ToolDecision.Closing<{
90
+ readonly reason: Schema.optionalKey<Schema.String>;
91
+ }, ToolDecision.Denied>;
92
+ }>, unknown, never, never>;
93
+ }>>;
94
+ }>]>;
95
+ type Input = typeof Input.Type;
96
+ declare const SubmitJson: Schema.toCodecJson<Schema.Struct<{
97
+ id: Schema.brand<Schema.String, "InputId">;
98
+ kind: Schema.Literal<"submit">;
99
+ messages: Schema.$Array<Schema.Struct<{
100
+ readonly type: Schema.Literal<"message">;
101
+ readonly role: Schema.Literal<"user">;
102
+ readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
103
+ readonly type: Schema.Literal<"input_text">;
104
+ readonly text: Schema.String;
105
+ }>, Schema.Struct<{
106
+ readonly type: Schema.Literal<"input_image">;
107
+ readonly source: Schema.Codec<import("@effect-uai/core/Image").ImageSource, import("@effect-uai/core/Image").ImageSource, never, never>;
108
+ }>]>>;
109
+ }>>;
110
+ }>>;
111
+ declare const InputJson: Schema.toCodecJson<Schema.Union<readonly [Schema.Struct<{
112
+ id: Schema.brand<Schema.String, "InputId">;
113
+ kind: Schema.Literal<"submit">;
114
+ messages: Schema.$Array<Schema.Struct<{
115
+ readonly type: Schema.Literal<"message">;
116
+ readonly role: Schema.Literal<"user">;
117
+ readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
118
+ readonly type: Schema.Literal<"input_text">;
119
+ readonly text: Schema.String;
120
+ }>, Schema.Struct<{
121
+ readonly type: Schema.Literal<"input_image">;
122
+ readonly source: Schema.Codec<import("@effect-uai/core/Image").ImageSource, import("@effect-uai/core/Image").ImageSource, never, never>;
123
+ }>]>>;
124
+ }>>;
125
+ }>, Schema.Struct<{
126
+ id: Schema.brand<Schema.String, "InputId">;
127
+ kind: Schema.Literal<"resolve">;
128
+ decisions: Schema.$Array<Schema.Struct<{
129
+ readonly callId: Schema.String;
130
+ readonly decision: Schema.Codec<ToolDecision.DecisionOf<{
131
+ readonly Approve: {};
132
+ readonly Deny: ToolDecision.Closing<{
133
+ readonly reason: Schema.optionalKey<Schema.String>;
134
+ }, ToolDecision.Denied>;
135
+ }>, unknown, never, never>;
136
+ }>>;
137
+ }>]>>;
138
+ /**
139
+ * The preset with typed app `data` (required on `submit`, optional on
140
+ * `resolve`) and, optionally, the app's decisions (`ToolDecision.make(...).schema`).
141
+ */
142
+ declare function make<D extends Schema.Top>(data: D): Preset<D, typeof ToolDecision.Default.schema>;
143
+ declare function make<D extends Schema.Top, A extends Schema.Top>(data: D, decisions: A): Preset<D, A>;
144
+ type Preset<D extends Schema.Top, A extends Schema.Top> = ReturnType<typeof preset<D, A>>;
145
+ declare const preset: <D extends Schema.Top, A extends Schema.Top>(data: D, decisions: A) => {
146
+ Submit: Schema.Struct<{
147
+ readonly id: Schema.brand<Schema.String, "InputId">;
148
+ readonly kind: Schema.Literal<"submit">;
149
+ readonly messages: Schema.$Array<Schema.Struct<{
150
+ readonly type: Schema.Literal<"message">;
151
+ readonly role: Schema.Literal<"user">;
152
+ readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
153
+ readonly type: Schema.Literal<"input_text">;
154
+ readonly text: Schema.String;
155
+ }>, Schema.Struct<{
156
+ readonly type: Schema.Literal<"input_image">;
157
+ readonly source: Schema.Codec<import("@effect-uai/core/Image").ImageSource, import("@effect-uai/core/Image").ImageSource, never, never>;
158
+ }>]>>;
159
+ }>>;
160
+ readonly data: D;
161
+ }>;
162
+ Resolve: Schema.Struct<{
163
+ readonly id: Schema.brand<Schema.String, "InputId">;
164
+ readonly kind: Schema.Literal<"resolve">;
165
+ readonly decisions: Schema.$Array<Schema.Struct<{
166
+ readonly callId: Schema.String;
167
+ readonly decision: A;
168
+ }>>;
169
+ readonly data: Schema.optionalKey<D>;
170
+ }>;
171
+ Input: Schema.Union<readonly [Schema.Struct<{
172
+ readonly id: Schema.brand<Schema.String, "InputId">;
173
+ readonly kind: Schema.Literal<"submit">;
174
+ readonly messages: Schema.$Array<Schema.Struct<{
175
+ readonly type: Schema.Literal<"message">;
176
+ readonly role: Schema.Literal<"user">;
177
+ readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
178
+ readonly type: Schema.Literal<"input_text">;
179
+ readonly text: Schema.String;
180
+ }>, Schema.Struct<{
181
+ readonly type: Schema.Literal<"input_image">;
182
+ readonly source: Schema.Codec<import("@effect-uai/core/Image").ImageSource, import("@effect-uai/core/Image").ImageSource, never, never>;
183
+ }>]>>;
184
+ }>>;
185
+ readonly data: D;
186
+ }>, Schema.Struct<{
187
+ readonly id: Schema.brand<Schema.String, "InputId">;
188
+ readonly kind: Schema.Literal<"resolve">;
189
+ readonly decisions: Schema.$Array<Schema.Struct<{
190
+ readonly callId: Schema.String;
191
+ readonly decision: A;
192
+ }>>;
193
+ readonly data: Schema.optionalKey<D>;
194
+ }>]>;
195
+ SubmitJson: Schema.toCodecJson<Schema.Struct<{
196
+ readonly id: Schema.brand<Schema.String, "InputId">;
197
+ readonly kind: Schema.Literal<"submit">;
198
+ readonly messages: Schema.$Array<Schema.Struct<{
199
+ readonly type: Schema.Literal<"message">;
200
+ readonly role: Schema.Literal<"user">;
201
+ readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
202
+ readonly type: Schema.Literal<"input_text">;
203
+ readonly text: Schema.String;
204
+ }>, Schema.Struct<{
205
+ readonly type: Schema.Literal<"input_image">;
206
+ readonly source: Schema.Codec<import("@effect-uai/core/Image").ImageSource, import("@effect-uai/core/Image").ImageSource, never, never>;
207
+ }>]>>;
208
+ }>>;
209
+ readonly data: D;
210
+ }>>;
211
+ InputJson: Schema.toCodecJson<Schema.Union<readonly [Schema.Struct<{
212
+ readonly id: Schema.brand<Schema.String, "InputId">;
213
+ readonly kind: Schema.Literal<"submit">;
214
+ readonly messages: Schema.$Array<Schema.Struct<{
215
+ readonly type: Schema.Literal<"message">;
216
+ readonly role: Schema.Literal<"user">;
217
+ readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
218
+ readonly type: Schema.Literal<"input_text">;
219
+ readonly text: Schema.String;
220
+ }>, Schema.Struct<{
221
+ readonly type: Schema.Literal<"input_image">;
222
+ readonly source: Schema.Codec<import("@effect-uai/core/Image").ImageSource, import("@effect-uai/core/Image").ImageSource, never, never>;
223
+ }>]>>;
224
+ }>>;
225
+ readonly data: D;
226
+ }>, Schema.Struct<{
227
+ readonly id: Schema.brand<Schema.String, "InputId">;
228
+ readonly kind: Schema.Literal<"resolve">;
229
+ readonly decisions: Schema.$Array<Schema.Struct<{
230
+ readonly callId: Schema.String;
231
+ readonly decision: A;
232
+ }>>;
233
+ readonly data: Schema.optionalKey<D>;
234
+ }>]>>;
235
+ };
236
+ /** An input whose `id` is not assigned yet (per union member). */
237
+ type Draft<I> = I extends unknown ? Omit<I, "id"> & {
238
+ readonly id?: InputId;
239
+ } : never;
240
+ /** A draft with its `id` assigned. */
241
+ type Identified<D> = D & {
242
+ readonly id: InputId;
243
+ };
244
+ /** What a transport receives for inputs of type `I`: the draft `submit` took, with its id. */
245
+ type Sent<I = Input> = Identified<Draft<I>>;
246
+ /** Assign a UUIDv7 id unless the draft already has one. */
247
+ declare const withId: <D extends {
248
+ readonly id?: InputId;
249
+ }>(draft: D) => Effect.Effect<Identified<D>, never, SecureRandom.SecureRandom>;
250
+ /** A user message: `text` first, then any attachments (images). */
251
+ declare const user: (text: string, attachments?: ReadonlyArray<Content>) => UserMessage;
252
+ type Id = {
253
+ readonly id?: InputId;
254
+ };
255
+ declare function submit(messages: string | ReadonlyArray<UserMessage>, options?: Id): Draft<Submit>;
256
+ declare function submit<D>(messages: string | ReadonlyArray<UserMessage>, options: Id & {
257
+ readonly data: D;
258
+ }): Draft<Submit> & {
259
+ readonly data: D;
260
+ };
261
+ /** A resolve draft; the decision type defaults to `ToolDecision.Default`'s. */
262
+ type ResolveDraft<A = Decision["decision"]> = {
263
+ readonly id?: InputId;
264
+ readonly kind: "resolve";
265
+ readonly decisions: ReadonlyArray<ToolDecision.Answer<A>>;
266
+ };
267
+ declare function resolve<A = Decision["decision"]>(decisions: ReadonlyArray<ToolDecision.Answer<A>>, options?: Id): ResolveDraft<A>;
268
+ declare function resolve<A, D>(decisions: ReadonlyArray<ToolDecision.Answer<A>>, options: Id & {
269
+ readonly data: D;
270
+ }): ResolveDraft<A> & {
271
+ readonly data: D;
272
+ };
273
+ /** All text of the submit's messages, joined by blank lines. */
274
+ declare const text: (input: Pick<Submit, "messages">) => string;
275
+ //#endregion
276
+ export { submit as _, Input as a, withId as b, Resolve as c, Submit as d, SubmitJson as f, resolve as g, make as h, Identified as i, ResolveDraft as l, answer as m, Decision as n, InputJson as o, UserMessage as p, Draft as r, Input_d_exports as s, Content as t, Sent as u, text as v, user as y };
277
+ //# sourceMappingURL=Input-Cz-Kxusm.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Input-Cz-Kxusm.d.mts","names":[],"sources":["../src/Input.ts"],"mappings":";;;;;;;;cAqBa,aAAW,OAAA;;;;;;;;;;;KAKZ,qBAAqB,YAAY;KACjC,UAAU;;cAGT,SAAU,UAAU,OAAO,KAAG,UAAY,MAAC,OAAA;;;;;cAI3C,UAAQ,OAAA;;;;;;;;;KACT,kBAAkB,SAAS;cAc1B,QAAM,OAAA;;;;;;;;;;;;;;;KACP,gBAAgB,OAAO;cAEtB,SAAO,OAAA;;;;;;;;;;;;;KACR,iBAAiB,QAAQ;cAExB,OAAK,OAAA,gBAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;KACN,eAAe,MAAM;cAEpB,YAAU,OAAA,YAAA,OAAA;;;;;;;;;;;;;;;cACV,WAAS,OAAA,YAAA,OAAA,gBAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAMN,KAAK,UAAU,OAAO,KAAK,MAAM,IAAI,OAAO,UAAU,aAAa,QAAQ;iBAC3E,KAAK,UAAU,OAAO,KAAK,UAAU,OAAO,KAC1D,MAAM,GACN,WAAW,IACV,OAAO,GAAG;KAKR,OAAO,UAAU,OAAO,KAAK,UAAU,OAAO,OAAO,kBAAkB,OAAO,GAAG;cAEhF,SAAU,UAAU,OAAO,KAAK,UAAU,OAAO,KAAG,MAAQ,GAAC,WAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAcpE,MAAM,KAAK,oBAAoB,KAAK;WAAsB,KAAK;;;KAG/D,WAAW,KAAK;WAAe,IAAI;;;KAGnC,KAAK,IAAI,SAAS,WAAW,MAAM;;cAGlC,SAAU;WAAqB,KAAK;GAAS,OACjD,MACN,OAAO,OAAO,WAAW,WAAW,aAAa;;cAUvC,OAAI,cAAgB,cAAe,cAAc,aAAgB;KAMzE;WAAgB,KAAK;;iBAKV,OAAO,mBAAmB,cAAc,cAAc,UAAU,KAAK,MAAM;iBAC3E,OAAO,GACrB,mBAAmB,cAAc,cACjC,SAAS;WAAgB,MAAM;IAC9B,MAAM;WAAqB,MAAM;;;KAaxB,aAAa,IAAI;WAClB,KAAK;WACL;WACA,WAAW,cAAc,aAAa,OAAO;;iBAGxC,QAAQ,IAAI,sBAC1B,WAAW,cAAc,aAAa,OAAO,KAC7C,UAAU,KACT,aAAa;iBACA,QAAQ,GAAG,GACzB,WAAW,cAAc,aAAa,OAAO,KAC7C,SAAS;WAAgB,MAAM;IAC9B,aAAa;WAAgB,MAAM;;;cASzB,OAAI,OAAW,KAAK"}
@@ -0,0 +1,2 @@
1
+ import { _ as submit, a as Input, b as withId, c as Resolve, d as Submit, f as SubmitJson, g as resolve, h as make, i as Identified, l as ResolveDraft, m as answer, n as Decision, o as InputJson, p as UserMessage, r as Draft, t as Content, u as Sent, v as text, y as user } from "./Input-Cz-Kxusm.mjs";
2
+ export { Content, Decision, Draft, Identified, Input, InputJson, Resolve, ResolveDraft, Sent, Submit, SubmitJson, UserMessage, answer, make, resolve, submit, text, user, withId };
package/dist/Input.mjs ADDED
@@ -0,0 +1,127 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
+ import { InputId } from "./RunEvent.mjs";
3
+ import { Effect, Schema } from "effect";
4
+ import * as ToolDecision from "@effect-uai/core/ToolDecision";
5
+ import * as Items from "@effect-uai/core/Items";
6
+ import { SecureRandom } from "effect/crypto";
7
+ //#region src/Input.ts
8
+ /**
9
+ * What a client sends to start or continue a run. The library only needs an
10
+ * `id` on an input (generated on the client, so optimistic UI can match it
11
+ * to `run-started { inputs }`); this module is a preset, and an app with a
12
+ * different shape passes its own schema.
13
+ *
14
+ * A `submit` carries user `messages` (core message items: the server appends
15
+ * them to its history as they are) and, with `make(DataSchema)`, typed `data` the server
16
+ * interprets (template id, model choice). Decode request bodies with the
17
+ * `*Json` codecs: they carry image bytes over JSON.
18
+ *
19
+ * Constructors build drafts without randomness; the id is assigned where an
20
+ * input is sent (`Atoms.submit`, or `withId`).
21
+ */
22
+ var Input_exports = /* @__PURE__ */ __exportAll({
23
+ Decision: () => Decision,
24
+ Input: () => Input,
25
+ InputJson: () => InputJson,
26
+ Resolve: () => Resolve,
27
+ Submit: () => Submit,
28
+ SubmitJson: () => SubmitJson,
29
+ UserMessage: () => UserMessage,
30
+ answer: () => answer,
31
+ make: () => make,
32
+ resolve: () => resolve,
33
+ submit: () => submit,
34
+ text: () => text,
35
+ user: () => user,
36
+ withId: () => withId
37
+ });
38
+ /** A user message: core's `message` item with role `user` and input blocks only. */
39
+ const UserMessage = Schema.Struct({
40
+ type: Schema.Literal("message"),
41
+ role: Schema.Literal("user"),
42
+ content: Schema.Array(Schema.Union([Items.InputText, Items.InputImage]))
43
+ });
44
+ /** The answer to one waiting call, with a decision of the app's `ToolDecision.make`. */
45
+ const answer = (decision) => Schema.Struct({
46
+ callId: Schema.String,
47
+ decision
48
+ });
49
+ /** The default answer: `ToolDecision.Default` (approve, or deny with an optional reason). */
50
+ const Decision = answer(ToolDecision.Default.schema);
51
+ const submitFields = {
52
+ id: InputId,
53
+ kind: Schema.Literal("submit"),
54
+ messages: Schema.Array(UserMessage)
55
+ };
56
+ const resolveFields = (decision) => ({
57
+ id: InputId,
58
+ kind: Schema.Literal("resolve"),
59
+ decisions: Schema.Array(answer(decision))
60
+ });
61
+ const Submit = Schema.Struct(submitFields);
62
+ const Resolve = Schema.Struct(resolveFields(ToolDecision.Default.schema));
63
+ const Input = Schema.Union([Submit, Resolve]);
64
+ const SubmitJson = Schema.toCodecJson(Submit);
65
+ const InputJson = Schema.toCodecJson(Input);
66
+ function make(data, decisions = ToolDecision.Default.schema) {
67
+ return preset(data, decisions);
68
+ }
69
+ const preset = (data, decisions) => {
70
+ const Submit = Schema.Struct({
71
+ ...submitFields,
72
+ data
73
+ });
74
+ const Resolve = Schema.Struct({
75
+ ...resolveFields(decisions),
76
+ data: Schema.optionalKey(data)
77
+ });
78
+ const Input = Schema.Union([Submit, Resolve]);
79
+ return {
80
+ Submit,
81
+ Resolve,
82
+ Input,
83
+ SubmitJson: Schema.toCodecJson(Submit),
84
+ InputJson: Schema.toCodecJson(Input)
85
+ };
86
+ };
87
+ /** Assign a UUIDv7 id unless the draft already has one. */
88
+ const withId = (draft) => {
89
+ const { id } = draft;
90
+ return id !== void 0 ? Effect.succeed({
91
+ ...draft,
92
+ id
93
+ }) : SecureRandom.SecureRandom.use((random) => random.uuidV7()).pipe(Effect.map((uuid) => ({
94
+ ...draft,
95
+ id: InputId.make(uuid)
96
+ })));
97
+ };
98
+ /** A user message: `text` first, then any attachments (images). */
99
+ const user = (text, attachments = []) => ({
100
+ type: "message",
101
+ role: "user",
102
+ content: [{
103
+ type: "input_text",
104
+ text
105
+ }, ...attachments]
106
+ });
107
+ const toMessages = (messages) => typeof messages === "string" ? [user(messages)] : messages;
108
+ function submit(messages, options) {
109
+ return {
110
+ ...options,
111
+ kind: "submit",
112
+ messages: toMessages(messages)
113
+ };
114
+ }
115
+ function resolve(decisions, options) {
116
+ return {
117
+ ...options,
118
+ kind: "resolve",
119
+ decisions
120
+ };
121
+ }
122
+ /** All text of the submit's messages, joined by blank lines. */
123
+ const text = (input) => input.messages.flatMap((m) => m.content.flatMap((block) => block.type === "input_text" ? [block.text] : [])).join("\n\n");
124
+ //#endregion
125
+ export { Decision, Input, InputJson, Resolve, Submit, SubmitJson, UserMessage, answer, make, resolve, submit, Input_exports as t, text, user, withId };
126
+
127
+ //# sourceMappingURL=Input.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Input.mjs","names":[],"sources":["../src/Input.ts"],"sourcesContent":["/**\n * What a client sends to start or continue a run. The library only needs an\n * `id` on an input (generated on the client, so optimistic UI can match it\n * to `run-started { inputs }`); this module is a preset, and an app with a\n * different shape passes its own schema.\n *\n * A `submit` carries user `messages` (core message items: the server appends\n * them to its history as they are) and, with `make(DataSchema)`, typed `data` the server\n * interprets (template id, model choice). Decode request bodies with the\n * `*Json` codecs: they carry image bytes over JSON.\n *\n * Constructors build drafts without randomness; the id is assigned where an\n * input is sent (`Atoms.submit`, or `withId`).\n */\nimport * as ToolDecision from \"@effect-uai/core/ToolDecision\"\nimport * as Items from \"@effect-uai/core/Items\"\nimport { Effect, Schema } from \"effect\"\nimport { SecureRandom } from \"effect/crypto\"\nimport { InputId } from \"./RunEvent.js\"\n\n/** A user message: core's `message` item with role `user` and input blocks only. */\nexport const UserMessage = Schema.Struct({\n type: Schema.Literal(\"message\"),\n role: Schema.Literal(\"user\"),\n content: Schema.Array(Schema.Union([Items.InputText, Items.InputImage])),\n})\nexport type UserMessage = typeof UserMessage.Type\nexport type Content = UserMessage[\"content\"][number]\n\n/** The answer to one waiting call, with a decision of the app's `ToolDecision.make`. */\nexport const answer = <D extends Schema.Top>(decision: D) =>\n Schema.Struct({ callId: Schema.String, decision })\n\n/** The default answer: `ToolDecision.Default` (approve, or deny with an optional reason). */\nexport const Decision = answer(ToolDecision.Default.schema)\nexport type Decision = typeof Decision.Type\n\nconst submitFields = {\n id: InputId,\n kind: Schema.Literal(\"submit\"),\n messages: Schema.Array(UserMessage),\n}\n\nconst resolveFields = <D extends Schema.Top>(decision: D) => ({\n id: InputId,\n kind: Schema.Literal(\"resolve\"),\n decisions: Schema.Array(answer(decision)),\n})\n\nexport const Submit = Schema.Struct(submitFields)\nexport type Submit = typeof Submit.Type\n\nexport const Resolve = Schema.Struct(resolveFields(ToolDecision.Default.schema))\nexport type Resolve = typeof Resolve.Type\n\nexport const Input = Schema.Union([Submit, Resolve])\nexport type Input = typeof Input.Type\n\nexport const SubmitJson = Schema.toCodecJson(Submit)\nexport const InputJson = Schema.toCodecJson(Input)\n\n/**\n * The preset with typed app `data` (required on `submit`, optional on\n * `resolve`) and, optionally, the app's decisions (`ToolDecision.make(...).schema`).\n */\nexport function make<D extends Schema.Top>(data: D): Preset<D, typeof ToolDecision.Default.schema>\nexport function make<D extends Schema.Top, A extends Schema.Top>(\n data: D,\n decisions: A,\n): Preset<D, A>\nexport function make(data: Schema.Top, decisions: Schema.Top = ToolDecision.Default.schema) {\n return preset(data, decisions)\n}\n\ntype Preset<D extends Schema.Top, A extends Schema.Top> = ReturnType<typeof preset<D, A>>\n\nconst preset = <D extends Schema.Top, A extends Schema.Top>(data: D, decisions: A) => {\n const Submit = Schema.Struct({ ...submitFields, data })\n const Resolve = Schema.Struct({ ...resolveFields(decisions), data: Schema.optionalKey(data) })\n const Input = Schema.Union([Submit, Resolve])\n return {\n Submit,\n Resolve,\n Input,\n SubmitJson: Schema.toCodecJson(Submit),\n InputJson: Schema.toCodecJson(Input),\n }\n}\n\n/** An input whose `id` is not assigned yet (per union member). */\nexport type Draft<I> = I extends unknown ? Omit<I, \"id\"> & { readonly id?: InputId } : never\n\n/** A draft with its `id` assigned. */\nexport type Identified<D> = D & { readonly id: InputId }\n\n/** What a transport receives for inputs of type `I`: the draft `submit` took, with its id. */\nexport type Sent<I = Input> = Identified<Draft<I>>\n\n/** Assign a UUIDv7 id unless the draft already has one. */\nexport const withId = <D extends { readonly id?: InputId }>(\n draft: D,\n): Effect.Effect<Identified<D>, never, SecureRandom.SecureRandom> => {\n const { id } = draft\n return id !== undefined\n ? Effect.succeed({ ...draft, id })\n : SecureRandom.SecureRandom.use((random) => random.uuidV7()).pipe(\n Effect.map((uuid) => ({ ...draft, id: InputId.make(uuid) })),\n )\n}\n\n/** A user message: `text` first, then any attachments (images). */\nexport const user = (text: string, attachments: ReadonlyArray<Content> = []): UserMessage => ({\n type: \"message\",\n role: \"user\",\n content: [{ type: \"input_text\", text }, ...attachments],\n})\n\ntype Id = { readonly id?: InputId }\n\nconst toMessages = (messages: string | ReadonlyArray<UserMessage>): ReadonlyArray<UserMessage> =>\n typeof messages === \"string\" ? [user(messages)] : messages\n\nexport function submit(messages: string | ReadonlyArray<UserMessage>, options?: Id): Draft<Submit>\nexport function submit<D>(\n messages: string | ReadonlyArray<UserMessage>,\n options: Id & { readonly data: D },\n): Draft<Submit> & { readonly data: D }\nexport function submit(\n messages: string | ReadonlyArray<UserMessage>,\n options?: Id & { readonly data?: unknown },\n): Draft<Submit> & { readonly data?: unknown } {\n return {\n ...options,\n kind: \"submit\",\n messages: toMessages(messages),\n }\n}\n\n/** A resolve draft; the decision type defaults to `ToolDecision.Default`'s. */\nexport type ResolveDraft<A = Decision[\"decision\"]> = {\n readonly id?: InputId\n readonly kind: \"resolve\"\n readonly decisions: ReadonlyArray<ToolDecision.Answer<A>>\n}\n\nexport function resolve<A = Decision[\"decision\"]>(\n decisions: ReadonlyArray<ToolDecision.Answer<A>>,\n options?: Id,\n): ResolveDraft<A>\nexport function resolve<A, D>(\n decisions: ReadonlyArray<ToolDecision.Answer<A>>,\n options: Id & { readonly data: D },\n): ResolveDraft<A> & { readonly data: D }\nexport function resolve(\n decisions: ReadonlyArray<ToolDecision.Answer<unknown>>,\n options?: Id & { readonly data?: unknown },\n): ResolveDraft<unknown> & { readonly data?: unknown } {\n return { ...options, kind: \"resolve\", decisions }\n}\n\n/** All text of the submit's messages, joined by blank lines. */\nexport const text = (input: Pick<Submit, \"messages\">): string =>\n input.messages\n .flatMap((m) => m.content.flatMap((block) => (block.type === \"input_text\" ? [block.text] : [])))\n .join(\"\\n\\n\")\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,cAAc,OAAO,OAAO;CACvC,MAAM,OAAO,QAAQ,SAAS;CAC9B,MAAM,OAAO,QAAQ,MAAM;CAC3B,SAAS,OAAO,MAAM,OAAO,MAAM,CAAC,MAAM,WAAW,MAAM,UAAU,CAAC,CAAC;AACzE,CAAC;;AAKD,MAAa,UAAgC,aAC3C,OAAO,OAAO;CAAE,QAAQ,OAAO;CAAQ;AAAS,CAAC;;AAGnD,MAAa,WAAW,OAAO,aAAa,QAAQ,MAAM;AAG1D,MAAM,eAAe;CACnB,IAAI;CACJ,MAAM,OAAO,QAAQ,QAAQ;CAC7B,UAAU,OAAO,MAAM,WAAW;AACpC;AAEA,MAAM,iBAAuC,cAAiB;CAC5D,IAAI;CACJ,MAAM,OAAO,QAAQ,SAAS;CAC9B,WAAW,OAAO,MAAM,OAAO,QAAQ,CAAC;AAC1C;AAEA,MAAa,SAAS,OAAO,OAAO,YAAY;AAGhD,MAAa,UAAU,OAAO,OAAO,cAAc,aAAa,QAAQ,MAAM,CAAC;AAG/E,MAAa,QAAQ,OAAO,MAAM,CAAC,QAAQ,OAAO,CAAC;AAGnD,MAAa,aAAa,OAAO,YAAY,MAAM;AACnD,MAAa,YAAY,OAAO,YAAY,KAAK;AAWjD,SAAgB,KAAK,MAAkB,YAAwB,aAAa,QAAQ,QAAQ;CAC1F,OAAO,OAAO,MAAM,SAAS;AAC/B;AAIA,MAAM,UAAsD,MAAS,cAAiB;CACpF,MAAM,SAAS,OAAO,OAAO;EAAE,GAAG;EAAc;CAAK,CAAC;CACtD,MAAM,UAAU,OAAO,OAAO;EAAE,GAAG,cAAc,SAAS;EAAG,MAAM,OAAO,YAAY,IAAI;CAAE,CAAC;CAC7F,MAAM,QAAQ,OAAO,MAAM,CAAC,QAAQ,OAAO,CAAC;CAC5C,OAAO;EACL;EACA;EACA;EACA,YAAY,OAAO,YAAY,MAAM;EACrC,WAAW,OAAO,YAAY,KAAK;CACrC;AACF;;AAYA,MAAa,UACX,UACmE;CACnE,MAAM,EAAE,OAAO;CACf,OAAO,OAAO,KAAA,IACV,OAAO,QAAQ;EAAE,GAAG;EAAO;CAAG,CAAC,IAC/B,aAAa,aAAa,KAAK,WAAW,OAAO,OAAO,CAAC,CAAC,CAAC,KACzD,OAAO,KAAK,UAAU;EAAE,GAAG;EAAO,IAAI,QAAQ,KAAK,IAAI;CAAE,EAAE,CAC7D;AACN;;AAGA,MAAa,QAAQ,MAAc,cAAsC,CAAC,OAAoB;CAC5F,MAAM;CACN,MAAM;CACN,SAAS,CAAC;EAAE,MAAM;EAAc;CAAK,GAAG,GAAG,WAAW;AACxD;AAIA,MAAM,cAAc,aAClB,OAAO,aAAa,WAAW,CAAC,KAAK,QAAQ,CAAC,IAAI;AAOpD,SAAgB,OACd,UACA,SAC6C;CAC7C,OAAO;EACL,GAAG;EACH,MAAM;EACN,UAAU,WAAW,QAAQ;CAC/B;AACF;AAiBA,SAAgB,QACd,WACA,SACqD;CACrD,OAAO;EAAE,GAAG;EAAS,MAAM;EAAW;CAAU;AAClD;;AAGA,MAAa,QAAQ,UACnB,MAAM,SACH,SAAS,MAAM,EAAE,QAAQ,SAAS,UAAW,MAAM,SAAS,eAAe,CAAC,MAAM,IAAI,IAAI,CAAC,CAAE,CAAC,CAAC,CAC/F,KAAK,MAAM"}
@@ -0,0 +1,44 @@
1
+ import { RunEvent } from "./RunEvent.mjs";
2
+ import { UiContract } from "./UiContract.mjs";
3
+ import { Effect, Schema, Stream } from "effect";
4
+ import * as Items from "@effect-uai/core/Items";
5
+ import * as Turn from "@effect-uai/core/Turn";
6
+ import * as ToolEvent from "@effect-uai/core/ToolEvent";
7
+ declare namespace Projection_d_exports {
8
+ export { Config, Options, Source, State, initial, step, toRunEvents };
9
+ }
10
+ /** What an effect-uai loop emits: turn events, tool events, and plain tool outputs. */
11
+ type Source = Turn.TurnEvent | ToolEvent.ToolEvent | Items.ToolCallOutput;
12
+ declare const Options: Schema.Struct<{
13
+ /**
14
+ * `"signal"` (default): only `reasoning-started`. `"summary"`: also
15
+ * forward summary deltas. `"full"`: also forward raw reasoning traces.
16
+ */
17
+ readonly reasoning: Schema.optionalKey<Schema.Literals<readonly ["signal", "summary", "full"]>>;
18
+ /** Forward raw tool-argument deltas (`tool-call-args-delta`). Default false. */
19
+ readonly toolArgs: Schema.optionalKey<Schema.Boolean>;
20
+ }>;
21
+ type Options = typeof Options.Type;
22
+ /** `Options` plus the contract whose tool schemas encode tool values and errors. */
23
+ type Config = Options & {
24
+ readonly contract: Pick<UiContract<any>, "toolEvent" | "toolOutput">;
25
+ };
26
+ declare const State: Schema.Struct<{
27
+ readonly inStep: Schema.Boolean;
28
+ readonly reasoningShown: Schema.Boolean;
29
+ /** Tool names by call id, for outputs that arrive as plain `function_call_output` items. */
30
+ readonly tools: Schema.$Record<Schema.String, Schema.String>;
31
+ }>;
32
+ type State = typeof State.Type;
33
+ declare const initial: State;
34
+ type Step = readonly [State, ReadonlyArray<RunEvent>];
35
+ /** Map one loop event onto zero or more `RunEvent`s; tool values are encoded by the contract. */
36
+ declare const step: (config: Config) => (s: State, event: Source) => Effect.Effect<Step, Schema.SchemaError>;
37
+ /**
38
+ * Stream operator: project a loop's events onto `RunEvent`s. A tool value the
39
+ * contract can't encode fails the stream: a contract violation, not data to show.
40
+ */
41
+ declare const toRunEvents: (config: Config) => <E, R>(self: Stream.Stream<Source, E, R>) => Stream.Stream<RunEvent, E | Schema.SchemaError, R>;
42
+ //#endregion
43
+ export { Config, Options, Source, State, initial, step, Projection_d_exports as t, toRunEvents };
44
+ //# sourceMappingURL=Projection.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Projection.d.mts","names":[],"sources":["../src/Projection.ts"],"mappings":";;;;;;;;;;KAiBY,SAAS,KAAK,YAAY,UAAU,YAAY,MAAM;cAErD,SAAO,OAAA;;;;;;;;;KASR,iBAAiB,QAAQ;;KAGzB,SAAS;WACV,UAAU,KAAK;;cAGb,OAAK,OAAA;;;;;;KAMN,eAAe,MAAM;cAEpB,SAAS;KAEjB,iBAAiB,OAAO,cAAc;;cA8C9B,OAAI,QACN,YAAM,GACX,OAAK,OAAS,WAAS,OAAO,OAAO,MAAM,OAAO;;;;;cA6C3C,cAAW,QACb,YACR,GAAG,GAAC,MAAQ,OAAO,OAAO,QAAQ,GAAG,OAAK,OAAO,OAAO,UAAU,IAAI,OAAO,aAAa"}