Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions apps/sim/lib/copilot/chat/persisted-message.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { generateId } from '@sim/utils/id'
import {
MothershipStreamV1CompletionStatus,
MothershipStreamV1EventType,
Expand Down Expand Up @@ -191,7 +192,7 @@ export function buildPersistedAssistantMessage(
requestId?: string
): PersistedMessage {
const message: PersistedMessage = {
id: crypto.randomUUID(),
id: generateId(),
role: 'assistant',
content: result.content,
timestamp: new Date().toISOString(),
Expand Down Expand Up @@ -488,7 +489,7 @@ function normalizeBlocks(rawBlocks: RawBlock[], messageContent: string): Persist

export function normalizeMessage(raw: Record<string, unknown>): PersistedMessage {
const msg: PersistedMessage = {
id: (raw.id as string) ?? crypto.randomUUID(),
id: (raw.id as string) ?? generateId(),
role: (raw.role as 'user' | 'assistant') ?? 'assistant',
content: (raw.content as string) ?? '',
timestamp: (raw.timestamp as string) ?? new Date().toISOString(),
Expand Down
7 changes: 4 additions & 3 deletions apps/sim/lib/copilot/chat/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type Context as OtelContext, context as otelContextApi } from '@opentel
import { db } from '@sim/db'
import { copilotChats } from '@sim/db/schema'
import { createLogger } from '@sim/logger'
import { generateId } from '@sim/utils/id'
import { eq, sql } from 'drizzle-orm'
import { type NextRequest, NextResponse } from 'next/server'
import { z } from 'zod'
Expand Down Expand Up @@ -615,8 +616,8 @@ export async function handleUnifiedChatPost(req: NextRequest) {
// trace ID) as soon as startCopilotOtelRoot runs. Empty only in the
// narrow pre-otelRoot window where errors don't correlate anyway.
let requestId = ''
const executionId = crypto.randomUUID()
const runId = crypto.randomUUID()
const executionId = generateId()
const runId = generateId()

try {
const session = await getSession()
Expand All @@ -628,7 +629,7 @@ export async function handleUnifiedChatPost(req: NextRequest) {

const body = ChatMessageSchema.parse(await req.json())
const normalizedContexts = normalizeContexts(body.contexts) ?? []
userMessageId = body.userMessageId || crypto.randomUUID()
userMessageId = body.userMessageId || generateId()

otelRoot = startCopilotOtelRoot({
streamId: userMessageId,
Expand Down
5 changes: 3 additions & 2 deletions apps/sim/lib/copilot/request/tools/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { db } from '@sim/db'
import { userTableRows } from '@sim/db/schema'
import { createLogger } from '@sim/logger'
import { toError } from '@sim/utils/errors'
import { generateId } from '@sim/utils/id'
import { parse as csvParse } from 'csv-parse/sync'
import { eq } from 'drizzle-orm'
import { FunctionExecute, Read as ReadTool } from '@/lib/copilot/generated/tool-catalog-v1'
Expand Down Expand Up @@ -107,7 +108,7 @@ export async function maybeWriteOutputToTable(
}
const chunk = rows.slice(i, i + BATCH_CHUNK_SIZE)
const values = chunk.map((rowData, j) => ({
id: `row_${crypto.randomUUID().replace(/-/g, '')}`,
id: `row_${generateId().replace(/-/g, '')}`,
tableId: outputTable,
workspaceId: context.workspaceId!,
data: rowData,
Expand Down Expand Up @@ -251,7 +252,7 @@ export async function maybeWriteReadCsvToTable(
}
const chunk = rows.slice(i, i + BATCH_CHUNK_SIZE)
const values = chunk.map((rowData, j) => ({
id: `row_${crypto.randomUUID().replace(/-/g, '')}`,
id: `row_${generateId().replace(/-/g, '')}`,
tableId: outputTable,
workspaceId: context.workspaceId!,
data: rowData,
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/lib/copilot/tools/handlers/oauth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { db } from '@sim/db'
import { pendingCredentialDraft, user } from '@sim/db/schema'
import { toError } from '@sim/utils/errors'
import { generateId } from '@sim/utils/id'
import { and, eq, lt } from 'drizzle-orm'
import type { ExecutionContext, ToolCallResult } from '@/lib/copilot/request/types'
import { getBaseUrl } from '@/lib/core/utils/urls'
Expand Down Expand Up @@ -140,7 +141,7 @@ export async function generateOAuthLink(
await db
.insert(pendingCredentialDraft)
.values({
id: crypto.randomUUID(),
id: generateId(),
userId,
workspaceId,
providerId,
Expand Down