History

Merge remote-tracking branch 'origin/codex/effect-lint-execution-engine' into codex/effect-lint-integration

Rhys Sullivan committed 6 months ago

Commit ed4a5d72 parents b9a25b4 253b0111 file · +14 −18Browse files

Unified · Split

packages/core/execution/src/engine.ts+14−18
@@ -1,4 +1,4 @@
1−import { Deferred, Effect, Fiber, Ref } from "effect";
1+import { Deferred, Effect, Fiber, Predicate, Ref } from "effect";
22 import type * as Cause from "effect/Cause";
33
44 import type {
@@ -24,9 +24,7 @@ import { buildExecuteDescription } from "./description"; · 19 unmodified lines
2424 // Types
2525 // ---------------------------------------------------------------------------
2626
27−export type ExecutionEngineConfig<
28− E extends Cause.YieldableError = CodeExecutionError,
29−> = {
27+export type ExecutionEngineConfig<E extends Cause.YieldableError = CodeExecutionError> = {
3028 readonly executor: Executor;
3129 readonly codeExecutor: CodeExecutor<E>;
3230 };
@@ -107,8 +105,10 @@ export const formatPausedExecution = ( · 74 unmodified lines
107105 } => {
108106 const req = paused.elicitationContext.request;
109107 const lines: string[] = [`Execution paused: ${req.message}`];
108+ const isUrlElicitation = Predicate.isTagged(req, "UrlElicitation");
109+ const isFormElicitation = Predicate.isTagged(req, "FormElicitation");
110110
111− if (req._tag === "UrlElicitation") {
111+ if (isUrlElicitation) {
112112 lines.push(`\nOpen this URL in a browser:\n${req.url}`);
113113 lines.push("\nAfter the browser flow, resume with the executionId below:");
114114 } else {
@@ -127,10 +127,10 @@ export const formatPausedExecution = ( · 12 unmodified lines
127127 status: "waiting_for_interaction",
128128 executionId: paused.id,
129129 interaction: {
130− kind: req._tag === "UrlElicitation" ? "url" : "form",
130+ kind: isUrlElicitation ? "url" : "form",
131131 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 } : {}),
134134 },
135135 },
136136 };
@@ -202,12 +202,12 @@ const makeFullInvoker = (executor: Executor, invokeOptions: InvokeOptions): Sand · 65 unmodified lines
202202 }
203203
204204 const limit = readOptionalLimit(args.limit, "tools.search");
205− if (limit instanceof ExecutionToolError) {
205+ if (Predicate.isTagged(limit, "ExecutionToolError")) {
206206 return Effect.fail(limit);
207207 }
208208
209209 const offset = readOptionalOffset(args.offset, "tools.search");
210− if (offset instanceof ExecutionToolError) {
210+ if (Predicate.isTagged(offset, "ExecutionToolError")) {
211211 return Effect.fail(offset);
212212 }
213213
@@ -242,7 +242,7 @@ const makeFullInvoker = (executor: Executor, invokeOptions: InvokeOptions): Sand · 28 unmodified lines
242242 isRecord(args) ? args.limit : undefined,
243243 "tools.executor.sources.list",
244244 );
245− if (limit instanceof ExecutionToolError) {
245+ if (Predicate.isTagged(limit, "ExecutionToolError")) {
246246 return Effect.fail(limit);
247247 }
248248
@@ -250,7 +250,7 @@ const makeFullInvoker = (executor: Executor, invokeOptions: InvokeOptions): Sand · 1 unmodified line
250250 isRecord(args) ? args.offset : undefined,
251251 "tools.executor.sources.list",
252252 );
253− if (offset instanceof ExecutionToolError) {
253+ if (Predicate.isTagged(offset, "ExecutionToolError")) {
254254 return Effect.fail(offset);
255255 }
256256
@@ -340,9 +340,7 @@ export type ExecutionEngine<E extends Cause.YieldableError = CodeExecutionError> · 83 unmodified lines
340340 readonly getDescription: Effect.Effect<string>;
341341 };
342342
343−export const createExecutionEngine = <
344− E extends Cause.YieldableError = CodeExecutionError,
345−>(
343+export const createExecutionEngine = <E extends Cause.YieldableError = CodeExecutionError>(
346344 config: ExecutionEngineConfig<E>,
347345 ): ExecutionEngine<E> => {
348346 const { executor, codeExecutor } = config;
@@ -470,9 +468,7 @@ export const createExecutionEngine = < · 121 unmodified lines
470468 const invoker = makeFullInvoker(executor, {
471469 onElicitation: options.onElicitation,
472470 });
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"));
476472 });
477473
478474 return {