Unified · Split
| @@ -135,38 +135,6 @@ export declare const api: { · 134 unmodified lines | ||
| 135 | 135 | any |
| 136 | 136 | >; |
| 137 | 137 | }; |
| 138 | − database: { | |
| 139 | − createAgentTask: FunctionReference< | |
| 140 | − "mutation", | |
| 141 | − "public", | |
| 142 | − { | |
| 143 | − actorId: string; | |
| 144 | − id: string; | |
| 145 | − prompt: string; | |
| 146 | − requesterId: string; | |
| 147 | − workspaceId: Id<"workspaces">; | |
| 148 | − }, | |
| 149 | − any | |
| 150 | − >; | |
| 151 | − getAgentTask: FunctionReference< | |
| 152 | − "query", | |
| 153 | − "public", | |
| 154 | − { agentTaskId: string }, | |
| 155 | − any | |
| 156 | − >; | |
| 157 | − updateAgentTask: FunctionReference< | |
| 158 | − "mutation", | |
| 159 | − "public", | |
| 160 | − { | |
| 161 | − agentTaskId: string; | |
| 162 | − codeRuns?: number; | |
| 163 | − error?: string; | |
| 164 | − resultText?: string; | |
| 165 | − status?: "running" | "completed" | "failed"; | |
| 166 | − }, | |
| 167 | − any | |
| 168 | − >; | |
| 169 | − }; | |
| 170 | 138 | executor: { |
| 171 | 139 | createTask: FunctionReference< |
| 172 | 140 | "mutation", |
| @@ -198,17 +166,6 @@ export declare const api: { · 25 unmodified lines | ||
| 198 | 166 | >; |
| 199 | 167 | }; |
| 200 | 168 | executorNode: { |
| 201 | − listTools: FunctionReference< | |
| 202 | − "action", | |
| 203 | − "public", | |
| 204 | − { | |
| 205 | − actorId?: string; | |
| 206 | − clientId?: string; | |
| 207 | − sessionId?: string; | |
| 208 | − workspaceId: Id<"workspaces">; | |
| 209 | − }, | |
| 210 | − any | |
| 211 | − >; | |
| 212 | 169 | listToolsWithWarnings: FunctionReference< |
| 213 | 170 | "action", |
| 214 | 171 | "public", |
| @@ -332,18 +289,6 @@ export declare const api: { · 117 unmodified lines | ||
| 332 | 289 | { sessionId?: string; sourceId: string; workspaceId: Id<"workspaces"> }, |
| 333 | 290 | any |
| 334 | 291 | >; |
| 335 | − getRequestContext: FunctionReference< | |
| 336 | − "query", | |
| 337 | − "public", | |
| 338 | − { sessionId?: string; workspaceId: Id<"workspaces"> }, | |
| 339 | − any | |
| 340 | − >; | |
| 341 | − getTask: FunctionReference< | |
| 342 | − "query", | |
| 343 | − "public", | |
| 344 | − { sessionId?: string; taskId: string; workspaceId: Id<"workspaces"> }, | |
| 345 | − any | |
| 346 | − >; | |
| 347 | 292 | getTaskInWorkspace: FunctionReference< |
| 348 | 293 | "query", |
| 349 | 294 | "public", |
| @@ -356,16 +301,6 @@ export declare const api: { · 6 unmodified lines | ||
| 356 | 301 | { sessionId?: string; workspaceId: Id<"workspaces"> }, |
| 357 | 302 | any |
| 358 | 303 | >; |
| 359 | − listApprovals: FunctionReference< | |
| 360 | − "query", | |
| 361 | − "public", | |
| 362 | − { | |
| 363 | − sessionId?: string; | |
| 364 | − status?: "pending" | "approved" | "denied"; | |
| 365 | − workspaceId: Id<"workspaces">; | |
| 366 | − }, | |
| 367 | − any | |
| 368 | − >; | |
| 369 | 304 | listCredentialProviders: FunctionReference<"query", "public", {}, any>; |
| 370 | 305 | listCredentials: FunctionReference< |
| 371 | 306 | "query", |
| @@ -58,14 +58,6 @@ async function deleteWorkspaceData( · 57 unmodified lines | ||
| 58 | 58 | await ctx.db.delete(source._id); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | − const agentTasks = await ctx.db | |
| 62 | − .query("agentTasks") | |
| 63 | − .withIndex("by_workspace_created", (q) => q.eq("workspaceId", workspaceId)) | |
| 64 | − .collect(); | |
| 65 | − for (const agentTask of agentTasks) { | |
| 66 | − await ctx.db.delete(agentTask._id); | |
| 67 | − } | |
| 68 | − | |
| 69 | 61 | const cachedToolsets = await ctx.db |
| 70 | 62 | .query("workspaceToolCache") |
| 71 | 63 | .withIndex("by_workspace", (q) => q.eq("workspaceId", workspaceId)) |
| @@ -1,8 +1,6 @@ | ||
| 1 | 1 | import { v } from "convex/values"; |
| 2 | 2 | import type { Doc } from "./_generated/dataModel"; |
| 3 | −import { mutation, | |
| 4 | −query, | |
| 5 | −type MutationCtx, type QueryCtx } from "./_generated/server"; | |
| 3 | +import { type MutationCtx, type QueryCtx } from "./_generated/server"; | |
| 6 | 4 | import { internalMutation, internalQuery } from "./_generated/server"; |
| 7 | 5 | import { ensureUniqueSlug } from "../lib/slug"; |
| 8 | 6 | import type { TaskStatus } from "../lib/types"; |
| @@ -25,7 +23,6 @@ const credentialProviderValidator = v.union( · 16 unmodified lines | ||
| 25 | 23 | v.literal("workos-vault"), |
| 26 | 24 | ); |
| 27 | 25 | const toolSourceTypeValidator = v.union(v.literal("mcp"), v.literal("openapi"), v.literal("graphql")); |
| 28 | −const agentTaskStatusValidator = v.union(v.literal("running"), v.literal("completed"), v.literal("failed")); | |
| 29 | 26 | |
| 30 | 27 | function slugify(input: string): string { |
| 31 | 28 | const slug = input |
| @@ -610,96 +607,6 @@ export const getApprovalInWorkspace = internalQuery({ · 578 unmodified lines | ||
| 610 | 607 | }, |
| 611 | 608 | }); |
| 612 | 609 | |
| 613 | −// ── Agent Tasks ── | |
| 614 | − | |
| 615 | −function mapAgentTask(doc: Doc<"agentTasks">) { | |
| 616 | − return { | |
| 617 | − id: doc.agentTaskId, | |
| 618 | − prompt: doc.prompt, | |
| 619 | − requesterId: doc.requesterId, | |
| 620 | − workspaceId: doc.workspaceId, | |
| 621 | − actorId: doc.actorId, | |
| 622 | − status: doc.status, | |
| 623 | − resultText: doc.resultText, | |
| 624 | − error: doc.error, | |
| 625 | − codeRuns: doc.codeRuns ?? 0, | |
| 626 | − createdAt: doc.createdAt, | |
| 627 | − updatedAt: doc.updatedAt, | |
| 628 | − }; | |
| 629 | −} | |
| 630 | − | |
| 631 | −async function getAgentTaskDoc(ctx: { db: QueryCtx["db"] }, agentTaskId: string) { | |
| 632 | − return await ctx.db | |
| 633 | − .query("agentTasks") | |
| 634 | − .withIndex("by_agent_task_id", (q) => q.eq("agentTaskId", agentTaskId)) | |
| 635 | − .unique(); | |
| 636 | −} | |
| 637 | − | |
| 638 | −export const createAgentTask = mutation({ | |
| 639 | − args: { | |
| 640 | − id: v.string(), | |
| 641 | − prompt: v.string(), | |
| 642 | − requesterId: v.string(), | |
| 643 | − workspaceId: v.id("workspaces"), | |
| 644 | − actorId: v.string(), | |
| 645 | − }, | |
| 646 | − handler: async (ctx, args) => { | |
| 647 | − const existing = await getAgentTaskDoc(ctx, args.id); | |
| 648 | − if (existing) { | |
| 649 | − throw new Error(`Agent task already exists: ${args.id}`); | |
| 650 | − } | |
| 651 | − | |
| 652 | − const now = Date.now(); | |
| 653 | − await ctx.db.insert("agentTasks", { | |
| 654 | − agentTaskId: args.id, | |
| 655 | − prompt: args.prompt, | |
| 656 | − requesterId: args.requesterId, | |
| 657 | − workspaceId: args.workspaceId, | |
| 658 | − actorId: args.actorId, | |
| 659 | − status: "running", | |
| 660 | − codeRuns: 0, | |
| 661 | − createdAt: now, | |
| 662 | − updatedAt: now, | |
| 663 | − }); | |
| 664 | − | |
| 665 | − const created = await getAgentTaskDoc(ctx, args.id); | |
| 666 | − if (!created) throw new Error(`Failed to fetch created agent task ${args.id}`); | |
| 667 | − return mapAgentTask(created); | |
| 668 | − }, | |
| 669 | −}); | |
| 670 | − | |
| 671 | −export const getAgentTask = query({ | |
| 672 | − args: { agentTaskId: v.string() }, | |
| 673 | − handler: async (ctx, args) => { | |
| 674 | − const doc = await getAgentTaskDoc(ctx, args.agentTaskId); | |
| 675 | − return doc ? mapAgentTask(doc) : null; | |
| 676 | − }, | |
| 677 | −}); | |
| 678 | − | |
| 679 | −export const updateAgentTask = mutation({ | |
| 680 | − args: { | |
| 681 | − agentTaskId: v.string(), | |
| 682 | − status: v.optional(agentTaskStatusValidator), | |
| 683 | − resultText: v.optional(v.string()), | |
| 684 | − error: v.optional(v.string()), | |
| 685 | − codeRuns: v.optional(v.number()), | |
| 686 | − }, | |
| 687 | − handler: async (ctx, args) => { | |
| 688 | − const doc = await getAgentTaskDoc(ctx, args.agentTaskId); | |
| 689 | − if (!doc) return null; | |
| 690 | − | |
| 691 | − const patch: Record<string, unknown> = { updatedAt: Date.now() }; | |
| 692 | − if (args.status !== undefined) patch.status = args.status; | |
| 693 | − if (args.resultText !== undefined) patch.resultText = args.resultText; | |
| 694 | − if (args.error !== undefined) patch.error = args.error; | |
| 695 | − if (args.codeRuns !== undefined) patch.codeRuns = args.codeRuns; | |
| 696 | − | |
| 697 | − await ctx.db.patch(doc._id, patch); | |
| 698 | − const updated = await getAgentTaskDoc(ctx, args.agentTaskId); | |
| 699 | − return updated ? mapAgentTask(updated) : null; | |
| 700 | − }, | |
| 701 | −}); | |
| 702 | − | |
| 703 | 610 | export const bootstrapAnonymousSession = internalMutation({ |
| 704 | 611 | args: { sessionId: v.optional(v.string()) }, |
| 705 | 612 | handler: async (ctx, args) => { |
| @@ -934,35 +934,6 @@ async function invokeTool(ctx: ActionCtx, task: TaskRecord, call: ToolCallReques · 933 unmodified lines | ||
| 934 | 934 | } |
| 935 | 935 | } |
| 936 | 936 | |
| 937 | −export const listTools = action({ | |
| 938 | − args: { | |
| 939 | − workspaceId: v.id("workspaces"), | |
| 940 | − actorId: v.optional(v.string()), | |
| 941 | − clientId: v.optional(v.string()), | |
| 942 | − sessionId: v.optional(v.string()), | |
| 943 | − }, | |
| 944 | − handler: async (ctx, args): Promise<ToolDescriptor[]> => { | |
| 945 | − const access = await ctx.runQuery(internal.workspaceAuthInternal.getWorkspaceAccessForRequest, { | |
| 946 | − workspaceId: args.workspaceId, | |
| 947 | − sessionId: args.sessionId, | |
| 948 | − }); | |
| 949 | − const canonicalActorId = actorIdForAccount({ | |
| 950 | − _id: access.accountId, | |
| 951 | − provider: access.provider, | |
| 952 | − providerAccountId: access.providerAccountId, | |
| 953 | − }); | |
| 954 | − if (args.actorId && args.actorId !== canonicalActorId) { | |
| 955 | − throw new Error("actorId must match the authenticated workspace actor"); | |
| 956 | − } | |
| 957 | − | |
| 958 | − return await listToolsForContext(ctx, { | |
| 959 | − workspaceId: args.workspaceId, | |
| 960 | − actorId: canonicalActorId, | |
| 961 | − clientId: args.clientId, | |
| 962 | − }); | |
| 963 | − }, | |
| 964 | −}); | |
| 965 | − | |
| 966 | 937 | export const listToolsWithWarnings = action({ |
| 967 | 938 | args: { |
| 968 | 939 | workspaceId: v.id("workspaces"), |
| @@ -41,7 +41,6 @@ const credentialProvider = v.union( · 40 unmodified lines | ||
| 41 | 41 | v.literal("workos-vault"), |
| 42 | 42 | ); |
| 43 | 43 | const toolSourceType = v.union(v.literal("mcp"), v.literal("openapi"), v.literal("graphql")); |
| 44 | −const agentTaskStatus = v.union(v.literal("running"), v.literal("completed"), v.literal("failed")); | |
| 45 | 44 | |
| 46 | 45 | export default defineSchema({ |
| 47 | 46 | accounts: defineTable({ |
| @@ -260,22 +259,6 @@ export default defineSchema({ · 212 unmodified lines | ||
| 260 | 259 | .index("by_workspace_updated", ["workspaceId", "updatedAt"]) |
| 261 | 260 | .index("by_workspace_name", ["workspaceId", "name"]), |
| 262 | 261 | |
| 263 | − agentTasks: defineTable({ | |
| 264 | − agentTaskId: v.string(), // domain ID: atask_<timestamp>_<counter> | |
| 265 | − prompt: v.string(), | |
| 266 | − requesterId: v.string(), // external ID (e.g. Discord user snowflake) | |
| 267 | − workspaceId: v.id("workspaces"), | |
| 268 | − actorId: v.string(), // account._id or anon_<uuid> | |
| 269 | − status: agentTaskStatus, | |
| 270 | − resultText: v.optional(v.string()), | |
| 271 | − error: v.optional(v.string()), | |
| 272 | − codeRuns: v.number(), | |
| 273 | − createdAt: v.number(), | |
| 274 | − updatedAt: v.number(), | |
| 275 | − }) | |
| 276 | − .index("by_agent_task_id", ["agentTaskId"]) | |
| 277 | − .index("by_workspace_created", ["workspaceId", "createdAt"]), | |
| 278 | − | |
| 279 | 262 | openApiSpecCache: defineTable({ |
| 280 | 263 | specUrl: v.string(), |
| 281 | 264 | storageId: v.id("_storage"), |
| @@ -2,9 +2,7 @@ import { v } from "convex/values"; · 1 unmodified line | ||
| 2 | 2 | import { internal } from "./_generated/api"; |
| 3 | 3 | import { mutation, query } from "./_generated/server"; |
| 4 | 4 | import { workspaceMutation, workspaceQuery } from "../lib/functionBuilders"; |
| 5 | −import { actorIdForAccount } from "../lib/identity"; | |
| 6 | 5 | |
| 7 | −const approvalStatusValidator = v.union(v.literal("pending"), v.literal("approved"), v.literal("denied")); | |
| 8 | 6 | const policyDecisionValidator = v.union(v.literal("allow"), v.literal("require_approval"), v.literal("deny")); |
| 9 | 7 | const credentialScopeValidator = v.union(v.literal("workspace"), v.literal("actor")); |
| 10 | 8 | const credentialProviderValidator = v.union(v.literal("managed"), v.literal("workos-vault")); |
| @@ -31,26 +29,6 @@ export const listRuntimeTargets = query({ · 20 unmodified lines | ||
| 31 | 29 | }, |
| 32 | 30 | }); |
| 33 | 31 | |
| 34 | −export const getRequestContext = workspaceQuery({ | |
| 35 | − args: {}, | |
| 36 | − handler: async (ctx) => { | |
| 37 | − return { | |
| 38 | − workspaceId: ctx.workspaceId, | |
| 39 | − actorId: actorIdForAccount(ctx.account as { _id: string; provider: string; providerAccountId: string }), | |
| 40 | − }; | |
| 41 | − }, | |
| 42 | −}); | |
| 43 | − | |
| 44 | −export const getTask = workspaceQuery({ | |
| 45 | − args: { taskId: v.string() }, | |
| 46 | − handler: async (ctx, args) => { | |
| 47 | − return await ctx.runQuery(internal.database.getTaskInWorkspace, { | |
| 48 | − taskId: args.taskId, | |
| 49 | − workspaceId: ctx.workspaceId, | |
| 50 | − }); | |
| 51 | − }, | |
| 52 | −}); | |
| 53 | − | |
| 54 | 32 | export const getTaskInWorkspace = workspaceQuery({ |
| 55 | 33 | args: { taskId: v.string() }, |
| 56 | 34 | handler: async (ctx, args) => { |
| @@ -70,18 +48,6 @@ export const listTasks = workspaceQuery({ · 13 unmodified lines | ||
| 70 | 48 | }, |
| 71 | 49 | }); |
| 72 | 50 | |
| 73 | −export const listApprovals = workspaceQuery({ | |
| 74 | − args: { | |
| 75 | − status: v.optional(approvalStatusValidator), | |
| 76 | − }, | |
| 77 | − handler: async (ctx, args) => { | |
| 78 | − return await ctx.runQuery(internal.database.listApprovals, { | |
| 79 | − workspaceId: ctx.workspaceId, | |
| 80 | − status: args.status, | |
| 81 | − }); | |
| 82 | − }, | |
| 83 | −}); | |
| 84 | − | |
| 85 | 51 | export const listPendingApprovals = workspaceQuery({ |
| 86 | 52 | args: {}, |
| 87 | 53 | handler: async (ctx) => { |
| @@ -26,7 +26,6 @@ async function workspaceHasActivity( · 25 unmodified lines | ||
| 26 | 26 | policy, |
| 27 | 27 | credential, |
| 28 | 28 | toolSource, |
| 29 | − agentTask, | |
| 30 | 29 | member, |
| 31 | 30 | ] = await Promise.all([ |
| 32 | 31 | ctx.db.query("tasks").withIndex("by_workspace_created", (q) => q.eq("workspaceId", workspaceId)).first(), |
| @@ -37,11 +36,10 @@ async function workspaceHasActivity( · 4 unmodified lines | ||
| 37 | 36 | .withIndex("by_workspace_created", (q) => q.eq("workspaceId", workspaceId)) |
| 38 | 37 | .first(), |
| 39 | 38 | ctx.db.query("toolSources").withIndex("by_workspace_updated", (q) => q.eq("workspaceId", workspaceId)).first(), |
| 40 | − ctx.db.query("agentTasks").withIndex("by_workspace_created", (q) => q.eq("workspaceId", workspaceId)).first(), | |
| 41 | 39 | ctx.db.query("workspaceMembers").withIndex("by_workspace", (q) => q.eq("workspaceId", workspaceId)).first(), |
| 42 | 40 | ]); |
| 43 | 41 | |
| 44 | − return Boolean(task || approval || policy || credential || toolSource || agentTask || member); | |
| 42 | + return Boolean(task || approval || policy || credential || toolSource || member); | |
| 45 | 43 | } |
| 46 | 44 | |
| 47 | 45 | async function filterDisplayWorkspaces( |
| @@ -3,7 +3,6 @@ import { $ } from "bun"; · 2 unmodified lines | ||
| 3 | 3 | const tables = [ |
| 4 | 4 | "accessPolicies", |
| 5 | 5 | "accounts", |
| 6 | − "agentTasks", | |
| 7 | 6 | "anonymousSessions", |
| 8 | 7 | "approvals", |
| 9 | 8 | "billingCustomers", |