| 140 | } |
| 141 | |
| 142 | function firstEvent(open: (signal: AbortSignal) => Promise<{ stream: AsyncIterator<unknown> }>) { |
| 143 | return Effect.acquireRelease( |
| 144 | Effect.sync(() => new AbortController()), |
| 145 | (controller) => Effect.sync(() => controller.abort()), |
| 146 | ).pipe( |
| 147 | Effect.flatMap((controller) => |
| 148 | Effect.acquireRelease( |
| 149 | call(() => open(controller.signal)), |
| 150 | (events) => call(async () => void (await events.stream.return?.(undefined))).pipe(Effect.ignore), |
| 151 | ).pipe( |
| 152 | Effect.flatMap((events) => |
| 153 | call(() => events.stream.next()).pipe( |
| 154 | Effect.timeoutOrElse({ |
| 155 | duration: "1 second", |
| 156 | orElse: () => Effect.fail(new Error("timed out waiting for SDK event")), |
| 157 | }), |
| 158 | ), |
| 159 | ), |
| 160 | Effect.map((result) => result.value), |
| 161 | ), |
| 162 | ), |
| 163 | ) |
| 164 | } |
| 165 | |
| 166 | function record(value: unknown) { |
| 167 | return value && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.entries(value)) : {} |