Repository navigation
feat(server): t3_thread_launch takes clientRequestId #16654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,10 @@ | ||
| import { MessageId, ThreadId, OrchestratorMcpFailure, ProjectId } from "@t3tools/contracts"; | ||
| import { | ||
| CommandId, | ||
| MessageId, | ||
| ThreadId, | ||
| OrchestratorMcpFailure, | ||
| ProjectId, | ||
| } from "@t3tools/contracts"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as FileSystem from "effect/FileSystem"; | ||
| import * as Option from "effect/Option"; | ||
|
|
@@ -58,8 +64,16 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, { | |
| (input, { runtimeMode, interactionMode }) => | ||
| Effect.gen(function* () { | ||
| const context = yield* readCaller(); | ||
| const { caller } = context; | ||
| const commandId = yield* newCommandId(); | ||
| const { caller, scope } = context; | ||
| // A retry with the same key replays the first launch: the ids derive | ||
| // from the caller and the key, and the launch service replays a | ||
| // command it already accepted. | ||
| const commandId = | ||
|
macroscopeapp[bot] marked this conversation as resolved.
|
||
| input.clientRequestId === undefined | ||
| ? yield* newCommandId() | ||
| : CommandId.make( | ||
| `mcp:launch:${encodeURIComponent(scope.requestNamespace)}:${encodeURIComponent(input.clientRequestId)}`, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High With 🚀 Reply "fix it for me" or copy this AI Prompt for your agent: |
||
| ); | ||
| const threadId = ThreadId.make(commandId); | ||
| const messageId = MessageId.make(commandId); | ||
| const attachments = input.attachments ?? []; | ||
|
|
@@ -95,7 +109,17 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, { | |
| Effect.mapError(unavailable), | ||
| Effect.map(Option.getOrUndefined), | ||
| ); | ||
| if (input.workspaceStrategy?.type === "existing_worktree") { | ||
| // A retry of an accepted launch replays it: it keeps the model it started | ||
| // with and skips the checks only a new launch needs, which the project | ||
| // may no longer pass, such as a base branch deleted since. | ||
| const launched = | ||
| input.clientRequestId === undefined | ||
| ? null | ||
| : yield* context.threads.getThreadShell(threadId).pipe(Effect.mapError(unavailable)); | ||
| const launchedModel = | ||
| launched === null || launched.deletedAt !== null ? undefined : launched.modelSelection; | ||
| const replaying = launchedModel !== undefined; | ||
| if (!replaying && input.workspaceStrategy?.type === "existing_worktree") { | ||
| const project = yield* readProject; | ||
| if (project === undefined) | ||
| return yield* new OrchestratorMcpFailure({ | ||
|
|
@@ -106,7 +130,7 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, { | |
| } | ||
| // Reject unresolved base refs before accepting a launch; worktree provisioning happens later. | ||
| const strategy = input.workspaceStrategy; | ||
| if (strategy?.type === "worktree") | ||
| if (!replaying && strategy?.type === "worktree") | ||
| yield* ThreadLaunch.ThreadLaunchService.pipe( | ||
| Effect.flatMap((launches) => | ||
| launches.checkWorktreeBase({ projectId, workspaceStrategy: strategy }), | ||
|
|
@@ -127,7 +151,7 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, { | |
| // project's effective defaults, as the composer does. Its mode stays | ||
| // within the ceiling it was approved with. | ||
| const projectDefaults = | ||
| caller === undefined | ||
| caller === undefined && !replaying | ||
| ? yield* ServerSettings.ServerSettingsService.pipe( | ||
| Effect.flatMap((settings) => settings.getSettings), | ||
| Effect.mapError(unavailable), | ||
|
|
@@ -141,6 +165,7 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, { | |
| : undefined; | ||
| const modelSelection = | ||
| input.modelSelection ?? | ||
| launchedModel ?? | ||
| caller?.modelSelection ?? | ||
| projectDefaults?.defaultModelSelection ?? | ||
| undefined; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.