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