Unified · Split
| @@ -1,4 +1,4 @@ | ||
| 1 | −import { Deferred, Effect, Fiber, Ref } from "effect"; | |
| 1 | +import { Deferred, Effect, Fiber, Predicate, Ref } from "effect"; | |
| 2 | 2 | import type * as Cause from "effect/Cause"; |
| 3 | 3 | |
| 4 | 4 | import type { |
| @@ -24,9 +24,7 @@ import { buildExecuteDescription } from "./description"; · 19 unmodified lines | ||
| 24 | 24 | // Types |
| 25 | 25 | // --------------------------------------------------------------------------- |
| 26 | 26 | |
| 27 | −export type ExecutionEngineConfig< | |
| 28 | − E extends Cause.YieldableError = CodeExecutionError, | |
| 29 | −> = { | |
| 27 | +export type ExecutionEngineConfig<E extends Cause.YieldableError = CodeExecutionError> = { | |
| 30 | 28 | readonly executor: Executor; |
| 31 | 29 | readonly codeExecutor: CodeExecutor<E>; |
| 32 | 30 | }; |
| @@ -107,8 +105,10 @@ export const formatPausedExecution = ( · 74 unmodified lines | ||
| 107 | 105 | } => { |
| 108 | 106 | const req = paused.elicitationContext.request; |
| 109 | 107 | const lines: string[] = [`Execution paused: ${req.message}`]; |
| 108 | + const isUrlElicitation = Predicate.isTagged(req, "UrlElicitation"); | |
| 109 | + const isFormElicitation = Predicate.isTagged(req, "FormElicitation"); | |
| 110 | 110 | |
| 111 | − if (req._tag === "UrlElicitation") { | |
| 111 | + if (isUrlElicitation) { | |
| 112 | 112 | lines.push(`\nOpen this URL in a browser:\n${req.url}`); |
| 113 | 113 | lines.push("\nAfter the browser flow, resume with the executionId below:"); |
| 114 | 114 | } else { |
| @@ -127,10 +127,10 @@ export const formatPausedExecution = ( · 12 unmodified lines | ||
| 127 | 127 | status: "waiting_for_interaction", |
| 128 | 128 | executionId: paused.id, |
| 129 | 129 | interaction: { |
| 130 | − kind: req._tag === "UrlElicitation" ? "url" : "form", | |
| 130 | + kind: isUrlElicitation ? "url" : "form", | |
| 131 | 131 | message: req.message, |
| 132 | − ...(req._tag === "UrlElicitation" ? { url: req.url } : {}), | |
| 133 | − ...(req._tag === "FormElicitation" ? { requestedSchema: req.requestedSchema } : {}), | |
| 132 | + ...(isUrlElicitation ? { url: req.url } : {}), | |
| 133 | + ...(isFormElicitation ? { requestedSchema: req.requestedSchema } : {}), | |
| 134 | 134 | }, |
| 135 | 135 | }, |
| 136 | 136 | }; |
| @@ -202,12 +202,12 @@ const makeFullInvoker = (executor: Executor, invokeOptions: InvokeOptions): Sand · 65 unmodified lines | ||
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | const limit = readOptionalLimit(args.limit, "tools.search"); |
| 205 | − if (limit instanceof ExecutionToolError) { | |
| 205 | + if (Predicate.isTagged(limit, "ExecutionToolError")) { | |
| 206 | 206 | return Effect.fail(limit); |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | const offset = readOptionalOffset(args.offset, "tools.search"); |
| 210 | − if (offset instanceof ExecutionToolError) { | |
| 210 | + if (Predicate.isTagged(offset, "ExecutionToolError")) { | |
| 211 | 211 | return Effect.fail(offset); |
| 212 | 212 | } |
| 213 | 213 | |
| @@ -242,7 +242,7 @@ const makeFullInvoker = (executor: Executor, invokeOptions: InvokeOptions): Sand · 28 unmodified lines | ||
| 242 | 242 | isRecord(args) ? args.limit : undefined, |
| 243 | 243 | "tools.executor.sources.list", |
| 244 | 244 | ); |
| 245 | − if (limit instanceof ExecutionToolError) { | |
| 245 | + if (Predicate.isTagged(limit, "ExecutionToolError")) { | |
| 246 | 246 | return Effect.fail(limit); |
| 247 | 247 | } |
| 248 | 248 | |
| @@ -250,7 +250,7 @@ const makeFullInvoker = (executor: Executor, invokeOptions: InvokeOptions): Sand · 1 unmodified line | ||
| 250 | 250 | isRecord(args) ? args.offset : undefined, |
| 251 | 251 | "tools.executor.sources.list", |
| 252 | 252 | ); |
| 253 | − if (offset instanceof ExecutionToolError) { | |
| 253 | + if (Predicate.isTagged(offset, "ExecutionToolError")) { | |
| 254 | 254 | return Effect.fail(offset); |
| 255 | 255 | } |
| 256 | 256 | |
| @@ -340,9 +340,7 @@ export type ExecutionEngine<E extends Cause.YieldableError = CodeExecutionError> · 83 unmodified lines | ||
| 340 | 340 | readonly getDescription: Effect.Effect<string>; |
| 341 | 341 | }; |
| 342 | 342 | |
| 343 | −export const createExecutionEngine = < | |
| 344 | − E extends Cause.YieldableError = CodeExecutionError, | |
| 345 | −>( | |
| 343 | +export const createExecutionEngine = <E extends Cause.YieldableError = CodeExecutionError>( | |
| 346 | 344 | config: ExecutionEngineConfig<E>, |
| 347 | 345 | ): ExecutionEngine<E> => { |
| 348 | 346 | const { executor, codeExecutor } = config; |
| @@ -470,9 +468,7 @@ export const createExecutionEngine = < · 121 unmodified lines | ||
| 470 | 468 | const invoker = makeFullInvoker(executor, { |
| 471 | 469 | onElicitation: options.onElicitation, |
| 472 | 470 | }); |
| 473 | − return yield* codeExecutor | |
| 474 | − .execute(code, invoker) | |
| 475 | − .pipe(Effect.withSpan("executor.code.exec")); | |
| 471 | + return yield* codeExecutor.execute(code, invoker).pipe(Effect.withSpan("executor.code.exec")); | |
| 476 | 472 | }); |
| 477 | 473 | |
| 478 | 474 | return { |