feat(server): let agents coordinate persistent peer threads #11303
Closedsamdickson22(GitHub profile, opens in a new tab)wants to merge 4 commits into
main fromrefs/pull/11303/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/mcp/toolkits/threads/handlers.ts lines 69 to 69OutdatedResolvedby samdickson22(GitHub profile, opens in a new tab)@@ -0,0 +49,21 @@49+ ((thread.latestUserMessageAt === null ||50+ [51+ thread.latestTurn?.requestedAt,52+ thread.latestTurn?.startedAt,53+ thread.latestTurn?.completedAt,54+ ].some((at) => at != null && at >= thread.latestUserMessageAt!)) &&55+ thread.session?.status !== "starting" &&56+ thread.session?.status !== "running" &&57+ thread.backgroundLiveness !== "working" &&58+ thread.latestTurn !== null &&59+ thread.latestTurn.state !== "running");60+61+const make = Effect.gen(function* () {62+ const engine = yield* OrchestrationEngine.OrchestrationEngineService;63+ const snapshots = yield* ProjectionSnapshotQuery.ProjectionSnapshotQuery;64+ const crypto = yield* Crypto.Crypto;65+ const uuid = crypto.randomUUIDv4.pipe(Effect.orDie);66+ const commandId = (caller: OrchestrationThreadShell, id?: CommandId) =>67+ id === undefined68+ ? uuid.pipe(Effect.map(CommandId.make))69+ : Effect.succeed(CommandId.make(`mcp:${caller.id}:${id}`));
- apps/server/src/mcp/toolkits/threads/handlers.ts line 166OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +146,21 @@146+ )147+ .sort((a, b) => (a.id < b.id ? 1 : a.id > b.id ? -1 : 0));148+ const page = threads.slice(0, input.limit ?? 20);149+ return {150+ threads: yield* Effect.forEach(page, summarize),151+ nextBeforeThreadId: threads.length > page.length ? page.at(-1)!.id : null,152+ };153+ }),154+ read_thread: (input) =>155+ Effect.gen(function* () {156+ const caller = yield* source();157+ const thread = yield* target(input.threadId, caller);158+ const detail = yield* snapshots159+ .getThreadDetailSnapshot(thread.id, {160+ turnLimit: input.turnLimit ?? 10,161+ ...(input.beforeCursor === undefined ? {} : { beforeCursor: input.beforeCursor }),162+ })163+ .pipe(Effect.mapError(failed));164+ if (Option.isNone(detail)) return yield* failed();165+ return {166+ thread: yield* summarize(thread),apps/server/src/mcp/toolkits/threads/tools.ts line 73OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +53,21 @@53+ "settledOverride",54+ "session",55+ "latestTurn",56+ "latestUserMessageAt",57+ "hasPendingApprovals",58+ "hasPendingUserInput",59+ "backgroundLiveness",60+ ]),61+ cursor: Schema.String,62+});63+64+const makeTool = <const N extends string, P extends Schema.Top, S extends Schema.Top>(65+ name: N,66+ description: string,67+ parameters: P,68+ success: S,69+ readonly: boolean,70+) =>71+ Tool.make(name, { description, parameters, success, failure, dependencies })72+ .annotate(Tool.Readonly, readonly)73+ .annotate(Tool.Destructive, false)
- apps/server/src/mcp/toolkits/threads/handlers.ts line 171OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +151,21 @@151+ return {152+ threads: yield* Effect.forEach(page, summarize),153+ nextBeforeThreadId: threads.length > page.length ? page.at(-1)!.id : null,154+ };155+ }),156+ read_thread: (input) =>157+ Effect.gen(function* () {158+ const caller = yield* source();159+ for (let attempt = 0; attempt < 3; attempt++) {160+ const before = yield* snapshots.getSnapshotSequence().pipe(Effect.mapError(failed));161+ const thread = yield* target(input.threadId, caller);162+ const detail = yield* snapshots163+ .getThreadDetailSnapshot(thread.id, {164+ turnLimit: input.turnLimit ?? 10,165+ ...(input.beforeCursor === undefined ? {} : { beforeCursor: input.beforeCursor }),166+ })167+ .pipe(Effect.mapError(failed));168+ if (Option.isNone(detail)) return yield* failed();169+ // Detail pages omit shell-only attention/liveness fields. A matching sequence170+ // keeps those fields and the paginated history on the same projection version.171+ if (before.snapshotSequence !== detail.value.snapshotSequence) continue;
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed