Projects
projects.create
Create a new project.name: string- Project nameframework: Framework- One of:"NEXTJS","ANGULAR","REACT","VUE","SVELTE"
createdAt and updatedAt to current time
projects.createWithMessage (action)
Create a project with an initial user message. Consumes 1 credit.value: string- Initial message content
- Checks and consumes 1 credit
- Generates random project name (e.g., “happy-project”)
- Creates project with framework
"NEXTJS" - Creates initial USER message with status COMPLETE
projects.createWithMessageAndAttachments (action)
Create a project with an initial message and image/file attachments. Consumes 1 credit.value: string- Initial message contentattachments?: Array<{ url: string; size: number; width?: number; height?: number }>- Optional attachments
createWithMessage
Side Effects: Same as createWithMessage, plus creates attachment records
projects.update
Update a project’s name, framework, or model preference.projectId: Id<"projects">- Project IDname?: string- New project nameframework?: Framework- New frameworkmodelPreference?: string- Preferred AI model
projects.deleteProject
Delete a project and all associated data (messages, fragments, attachments, drafts).projectId: Id<"projects">- Project ID
{ success: true }
Side Effects: Cascades delete to:
- All messages for the project
- All fragments linked to those messages
- All attachments linked to those messages
- Fragment draft for the project
projects.getOrCreateFragmentDraft
Get or create a fragment draft for a project.projectId: Id<"projects">- Project IDframework: Framework- Framework for the draft
files: {} if none exists
projects.createForUser
Create a project for a specific user (for use from actions).userId: string- Clerk user IDname: string- Project nameframework: Framework- Framework
projects.updateForUser
Update a project for a specific user (for background jobs).userId: string- Clerk user IDprojectId: Id<"projects">- Project IDname?: string- New nameframework?: Framework- New frameworkmodelPreference?: string- Model preference
Messages
messages.create
Create a new message.projectId: Id<"projects">- Project IDcontent: string- Message contentrole: "USER" | "ASSISTANT"- Message roletype: "RESULT" | "ERROR" | "STREAMING"- Message typestatus?: "PENDING" | "STREAMING" | "COMPLETE"- Message status (default: COMPLETE)
messages.createWithAttachments (action)
Create a message with attachments. Consumes 1 credit.value: string- Message contentprojectId: string- Project IDattachments?: Array<{ url: string; size: number; width?: number; height?: number; type?: AttachmentType; importId?: Id<"imports">; sourceMetadata?: any }>- Optional attachments
- Checks and consumes 1 credit
- Creates USER message with type RESULT and status COMPLETE
- Creates attachment records if provided
messages.updateStatus
Update message status (for streaming).messageId: Id<"messages">- Message IDstatus: MessageStatus- New status
messages.updateMessage
Update message content and optionally status.messageId: Id<"messages">- Message IDcontent: string- New contentstatus?: MessageStatus- New status
messages.createFragment
Create or update a fragment for a message.messageId: Id<"messages">- Message IDsandboxUrl: string- E2B sandbox URL or"webcontainer://local"title: string- Fragment titlefiles: any- Record of file paths to contentframework: Framework- Frameworkmetadata?: any- Custom metadata
messages.addAttachment
Add an attachment to a message.messageId: Id<"messages">- Message IDtype: AttachmentType-"IMAGE","FIGMA_FILE", or"GITHUB_REPO"url: string- Attachment URLsize: number- File size in byteswidth?: number- Image widthheight?: number- Image heightimportId?: Id<"imports">- Link to import recordsourceMetadata?: any- Source metadata
messages.createForUser
Create a message for a specific user (for actions).userId: string- Clerk user IDprojectId: Id<"projects">- Project IDcontent: string- Message contentrole: MessageRole- Message roletype: MessageType- Message typestatus?: MessageStatus- Message status
messages.createFragmentForUser
Create a fragment for a specific user (for background jobs).createFragment plus userId: string
Returns: Fragment ID
Usage & Credits
usage.checkAndConsumeCredit
Check if user has credits and consume one. Returns success status.- Creates usage record if none exists
- Resets credits if expired (24-hour rolling window)
- Decrements credits by 1 if available
- Free: 5/day
- Pro: 100/day
- Unlimited: No limit
usage.resetUsage
Reset usage for a user (admin function).userId: string- Clerk user ID
usage.checkAndConsumeCreditForUser
Check and consume credit for a specific user (for actions).userId: string- Clerk user ID
checkAndConsumeCredit
Subscriptions
subscriptions.createOrUpdateSubscription
Create or update a subscription (webhook handler).polarSubscriptionId: string- Polar subscription IDcustomerId: string- Polar customer IDproductId: string- Product IDpriceId: string- Price IDstatus: SubscriptionStatus- Subscription statusinterval: "monthly" | "yearly"- Billing intervalcurrentPeriodStart: number- Period start timestampcurrentPeriodEnd: number- Period end timestampcancelAtPeriodEnd: boolean- Whether to cancel at period endcanceledAt?: number- Cancellation timestamptrialStart?: number- Trial start timestamptrialEnd?: number- Trial end timestampmetadata?: any- Custom metadatauserId?: string- Clerk user ID (looked up from customer if not provided)
subscriptions.markSubscriptionForCancellation
Mark a subscription to cancel at period end.polarSubscriptionId: string- Polar subscription ID
cancelAtPeriodEnd: true
subscriptions.reactivateSubscription
Reactivate a subscription marked for cancellation.polarSubscriptionId: string- Polar subscription ID
cancelAtPeriodEnd: false
subscriptions.revokeSubscription
Immediately revoke a subscription.polarSubscriptionId: string- Polar subscription ID
status: "canceled" and cancelAtPeriodEnd: false
Imports
imports.createImport
Create a new import record.projectId: Id<"projects">- Project IDmessageId?: Id<"messages">- Optional message to link tosource: "FIGMA" | "GITHUB"- Import sourcesourceId: string- Source ID (Figma file ID or GitHub repo ID)sourceName: string- Display namesourceUrl: string- Source URLmetadata?: any- Custom metadata
"PENDING"
Throws: If user doesn’t own the project
imports.updateStatus
Update import status.importId: Id<"imports">- Import IDstatus: ImportStatus- New statuserror?: string- Error message if failedmetadata?: any- Metadata to merge with existing
updatedAt
imports.markProcessing
Mark import as processing.importId: Id<"imports">- Import ID
"PROCESSING"
imports.markComplete
Mark import as complete.importId: Id<"imports">- Import IDmetadata?: any- Final metadata
"COMPLETE"
imports.markFailed
Mark import as failed.importId: Id<"imports">- Import IDerror: string- Error message
"FAILED"
OAuth Connections
oauth.storeConnection
Store or update an OAuth connection.provider: "figma" | "github"- OAuth provideraccessToken: string- Access tokenrefreshToken?: string- Refresh tokenexpiresAt?: number- Expiration timestampscope: string- OAuth scopemetadata?: any- Custom metadata
oauth.revokeConnection
Revoke an OAuth connection.provider: "figma" | "github"- OAuth provider
oauth.updateMetadata
Update OAuth connection metadata.provider: "figma" | "github"- OAuth providermetadata: any- New metadata (replaces existing)
Rate Limiting
rateLimit.checkRateLimit
Check and increment rate limit for a key.key: string- Rate limit keylimit: number- Max requests allowed in windowwindowMs: number- Window duration in milliseconds
- Creates rate limit record if none exists
- Resets window if expired
- Increments count if within limit
rateLimit.resetExpiredRateLimits
Cleanup expired rate limit records.Agent Runs
agentRuns.enqueueForSystem
Enqueue a new agent run for WebContainer execution.projectId: Id<"projects">- Project IDvalue: string- User’s prompt/requestmodel?: string- AI model to useframework?: string- Framework override
"PENDING" and source "WEBCONTAINER"
agentRuns.claimRun
Claim a pending agent run for execution.runId: Id<"agentRuns">- Agent run ID
- Sets status to
"RUNNING" - Sets
claimedByto current user ID - Retrieves latest code files from project fragments
agentRuns.completeRun
Complete an agent run with results.runId: Id<"agentRuns">- Agent run IDsummary: string- Summary of what was builtfiles: Record<string, string>- Generated code filesframework: Framework- Framework usedmessageType?: MessageType- Message type (default: RESULT)messageStatus?: MessageStatus- Message status (default: COMPLETE)metadata?: any- Custom metadata
- Creates ASSISTANT message with summary
- Creates fragment with generated files
- Sets run status to
"COMPLETED" - Sets sandboxUrl to
"webcontainer://local"
agentRuns.failRun
Mark an agent run as failed.runId: Id<"agentRuns">- Agent run IDerror: string- Error message
"FAILED" and records error