Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/cli/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ const executeCode = (input: {
payload: {
code: input.code,
},
headers: { "x-executor-trigger": "cli" },
});

if (response.status === "paused") {
Expand Down
11 changes: 11 additions & 0 deletions packages/core/api/src/executions/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ const ExecuteRequest = Schema.Struct({
code: Schema.String,
});

/**
* Optional header naming the surface that triggered this execution —
* `"cli"`, `"http"`, `"mcp"`, etc. Persisted on the execution row so
* the runs UI can facet by trigger kind. Defaults to `"http"` when
* absent.
*/
const ExecuteHeaders = Schema.Struct({
"x-executor-trigger": Schema.optional(Schema.String),
});

const CompletedResult = Schema.Struct({
status: Schema.Literal("completed"),
text: Schema.String,
Expand Down Expand Up @@ -55,6 +65,7 @@ export class ExecutionsApi extends HttpApiGroup.make("executions")
.add(
HttpApiEndpoint.post("execute")`/executions`
.setPayload(ExecuteRequest)
.setHeaders(ExecuteHeaders)
.addSuccess(ExecuteResponse),
)
.add(
Expand Down
9 changes: 7 additions & 2 deletions packages/core/api/src/handlers/executions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ import { capture, captureEngineError } from "@executor/api";

export const ExecutionsHandlers = HttpApiBuilder.group(ExecutorApi, "executions", (handlers) =>
handlers
.handle("execute", ({ payload }) =>
.handle("execute", ({ payload, headers }) =>
capture(Effect.gen(function* () {
const engine = yield* ExecutionEngineService;
const outcome = yield* captureEngineError(engine.executeWithPause(payload.code));
const triggerKind = headers["x-executor-trigger"] ?? "http";
const outcome = yield* captureEngineError(
engine.executeWithPause(payload.code, {
trigger: { kind: triggerKind },
}),
);

if (outcome.status === "completed") {
const formatted = formatExecuteResult(outcome.result);
Expand Down
5 changes: 4 additions & 1 deletion packages/hosts/mcp/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,13 @@ export const createExecutorMcpServer = <E extends Cause.YieldableError>(
if (supportsManagedElicitation(server)) {
const result = yield* engine.execute(code, {
onElicitation: makeMcpElicitationHandler(server, debugLog),
trigger: { kind: "mcp" },
});
return toMcpResult(formatExecuteResult(result));
}
const outcome = yield* engine.executeWithPause(code);
const outcome = yield* engine.executeWithPause(code, {
trigger: { kind: "mcp" },
});
debugLog("execute.paused_flow_result", {
status: outcome.status,
executionId: outcome.status === "paused" ? outcome.execution.id : undefined,
Expand Down
Loading