(push: (event: TheaterEvent) => Effect.Effect<void>)
| 73 | }; |
| 74 | |
| 75 | const makeTheater = (push: (event: TheaterEvent) => Effect.Effect<void>): ChatTheater => ({ |
| 76 | user: (text) => push({ type: "user", text }), |
| 77 | assistant: (text) => push({ type: "assistant", text }), |
| 78 | status: (text) => push({ type: "status", text }), |
| 79 | tool: (call, work) => |
| 80 | Effect.gen(function* () { |
| 81 | yield* push({ type: "tool-start", name: call.name, input: inputPreview(call.input) }); |
| 82 | const startedAt = Date.now(); |
| 83 | const exit = yield* Effect.exit(work); |
| 84 | const seconds = (Date.now() - startedAt) / 1000; |
| 85 | if (Exit.isSuccess(exit)) { |
| 86 | const line = call.result ? call.result(exit.value) : JSON.stringify(exit.value); |
| 87 | yield* push({ type: "tool-end", ok: true, result: line, seconds }); |
| 88 | return exit.value; |
| 89 | } |
| 90 | yield* push({ type: "tool-end", ok: false, result: "failed", seconds }); |
| 91 | return yield* exit; |
| 92 | }), |
| 93 | }); |
| 94 | |
| 95 | export interface TheaterOptions { |
| 96 | readonly title: string; |
no test coverage detected