feat(server): port agent thread metadata tools to main #12018
ClosedStiensWout(GitHub profile, opens in a new tab)wants to merge 7 commits into
main fromrefs/pull/12018/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/server/src/mcp/toolkits/threads/tools.ts lines 10 to 12OutdatedResolvedby StiensWout(GitHub profile, opens in a new tab)@@ -0,0 +1,12 @@1+import { McpCapabilityUnavailableError, ThreadId, TrimmedNonEmptyString } from "@t3tools/contracts";2+import * as Schema from "effect/Schema";3+import * as Tool from "effect/unstable/ai/Tool";4+import * as Toolkit from "effect/unstable/ai/Toolkit";5+6+import * as OrchestrationEngine from "../../../orchestration/Services/OrchestrationEngine.ts";7+import * as McpInvocationContext from "../../McpInvocationContext.ts";8+9+export class ThreadRenameFailedError extends Schema.TaggedError<ThreadRenameFailedError>()(10+ "ThreadRenameFailedError",11+ { cause: Schema.Defect() },12+) {
- apps/server/src/mcp/toolkits/threads/tools.ts line 37OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +17,21 @@17+18+const RenameThreadTool = Tool.make("rename_thread", {19+ description:20+ "Rename the current T3 Code thread when the user or a skill asks for a specific name. Pass the desired title, including any task ID or naming convention. This saves a manual title that automatic title generation will not overwrite. Only the calling thread can be renamed.",21+ parameters: Schema.Struct({22+ title: TrimmedNonEmptyString.annotate({23+ description:24+ "The new thread title. Leading and trailing whitespace is removed; it must not be empty.",25+ }),26+ }),27+ success: Schema.Struct({ threadId: ThreadId, title: TrimmedNonEmptyString }),28+ failure: Schema.Union([McpCapabilityUnavailableError, ThreadRenameFailedError]),29+ dependencies: [30+ McpInvocationContext.McpInvocationContext,31+ OrchestrationEngine.OrchestrationEngineService,32+ ],33+})34+ .annotate(Tool.Title, "Rename current thread")35+ .annotate(Tool.Readonly, false)36+ .annotate(Tool.Destructive, false)37+ .annotate(Tool.Idempotent, true)
- apps/server/src/mcp/toolkits/threads/handlers.ts lines 7 to 7OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +1,7 @@1+import { CommandId } from "@t3tools/contracts";2+import * as Crypto from "effect/Crypto";3+import * as Effect from "effect/Effect";4+5+import * as OrchestrationEngine from "../../../orchestration/Services/OrchestrationEngine.ts";6+import * as McpInvocationContext from "../../McpInvocationContext.ts";7+import { ThreadRenameFailedError, ThreadsToolkit } from "./tools.ts";apps/server/src/mcp/McpHttpServer.ts lines 34 to 35OutdatedResolvedby StiensWout(GitHub profile, opens in a new tab)@@ -31,3 +31,5 @@3131 } from "./toolkits/preview/tools.ts";3232 import { PullRequestsToolkitHandlersLive } from "./toolkits/pullRequests/handlers.ts";3333 import { PullRequestsToolkit } from "./toolkits/pullRequests/tools.ts";34+import { ThreadsToolkitHandlersLive } from "./toolkits/threads/handlers.ts";35+import { ThreadsToolkit } from "./toolkits/threads/tools.ts";
StiensWout(GitHub profile, opens in a new tab) changed the title
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- packages/contracts/src/threadMetadataMcp.ts lines 38 to 38OutdatedResolvedby StiensWout(GitHub profile, opens in a new tab)@@ -0,0 +18,21 @@18+ if (index + 1 >= value.length || nextCodeUnit < 0xdc00 || nextCodeUnit > 0xdfff) {19+ return false;20+ }21+ index += 1;22+ } else if (codeUnit >= 0xdc00 && codeUnit <= 0xdfff) {23+ return false;24+ }25+ }26+ return true;27+}28+29+function isHttpUrl(value: string): boolean {30+ try {31+ const url = new URL(value);32+ return url.protocol === "http:" || url.protocol === "https:";33+ } catch {34+ return false;35+ }36+}37+38+const ThreadMetadataTitle = TrimmedNonEmptyString.check(Schema.isMaxLength(512)).annotate({apps/server/src/mcp/ThreadMetadataMcpService.ts line 83OutdatedResolvedby StiensWout(GitHub profile, opens in a new tab)@@ -0,0 +63,21 @@63+ input: ThreadMetadataMcpUpdateInput,64+): OrchestrationCommand {65+ const base = { commandId, threadId: target.id };66+ switch (input.action) {67+ case "rename":68+ return { ...base, type: "thread.meta.update", title: input.title! };69+ case "regenerate_title":70+ return { ...base, type: "thread.meta.update", regenerateTitle: true };71+ case "link_pull_request":72+ return {73+ ...base,74+ type: "thread.pull-request.link",75+ ...legacyThreadPullRequestKey(input.pullRequest!),76+ url: input.pullRequest!.url,77+ source: "agent",78+ };79+ case "unlink_pull_request": {80+ const current = resolveThreadCurrentPullRequestLink(target.pullRequests);81+ return current === null82+ ? // Record a receipt even for an empty unlink so a retry cannot remove a later link.83+ { ...base, type: "thread.meta.update", linkedPullRequest: null }apps/server/src/provider/Layers/ProviderService.ts line 909Resolvedby StiensWout(GitHub profile, opens in a new tab)@@ -906,4 +906,4 @@906906 const agentAccessCapabilities = Effect.fn("ProviderService.agentAccessCapabilities")(function* (907907 threadId: ThreadId,908908 ) {909- const capabilities = new Set<McpInvocationContext.McpCapability>(["pull-requests"]);909+ const capabilities = new Set<McpInvocationContext.McpCapability>([packages/contracts/src/threadMetadataMcp.ts line 97Resolvedby StiensWout(GitHub profile, opens in a new tab)@@ -0,0 +77,21 @@77+});78+export type ThreadMetadataMcpPullRequest = typeof ThreadMetadataMcpPullRequest.Type;79+80+export const ThreadMetadataMcpUpdateInput = Schema.Struct({81+ threadId: Schema.optional(ThreadId).annotate({82+ description: "Thread in the calling project. Omit to update the calling thread.",83+ }),84+ action: ThreadMetadataMcpAction,85+ title: Schema.optional(ThreadMetadataTitle),86+ pullRequest: Schema.optional(ThreadMetadataMcpPullRequest).annotate({87+ description: "Pull request to link. Required only when action is link_pull_request.",88+ }),89+ clientRequestId: Schema.optional(ThreadMetadataClientRequestId),90+}).check(91+ Schema.makeFilter((input) => {92+ switch (input.action) {93+ case "rename":94+ return input.title !== undefined && input.pullRequest === undefined95+ ? true96+ : "rename requires title and does not accept pullRequest.";97+ case "link_pull_request":
- apps/server/src/mcp/ThreadMetadataMcpService.ts line 95OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +75,21 @@75+ ...legacyThreadPullRequestKey(input.pullRequest!),76+ url: input.pullRequest!.url,77+ source: "agent",78+ };79+ case "unlink_pull_request": {80+ const current = resolveThreadCurrentPullRequestLink(target.pullRequests);81+ return current === null82+ ? // Record a receipt even for an empty unlink so a retry cannot remove a later link.83+ { ...base, type: "thread.meta.update", linkedPullRequest: null }84+ : {85+ ...base,86+ type: "thread.pull-request.unlink",87+ host: current.host,88+ repository: current.repository,89+ number: current.number,90+ };91+ }92+ }93+}94+95+export const make = Effect.gen(function* () {
- apps/server/src/mcp/ThreadMetadataMcpService.ts line 106OutdatedResolvedby StiensWout(GitHub profile, opens in a new tab)@@ -0,0 +86,21 @@86+ ...legacyThreadPullRequestKey(input.pullRequest!),87+ url: input.pullRequest!.url,88+ source: "agent",89+ };90+ case "unlink_pull_request": {91+ const current = resolveThreadCurrentPullRequestLink(target.pullRequests);92+ return current === null93+ ? // Record a receipt even for an empty unlink so a retry cannot remove a later link.94+ { ...base, type: "thread.meta.update" }95+ : {96+ ...base,97+ type: "thread.pull-request.unlink",98+ host: current.host,99+ repository: current.repository,100+ number: current.number,101+ };102+ }103+ }104+}105+106+const make = Effect.gen(function* () {
juliusmarminge closed this
Sign in to join this conversation.



macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed