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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
"supabase:dev": "supabase start --ignore-health-check"
},
"dependencies": {
"@assembly-js/node-sdk": "^3.19.1",
"@sentry/nextjs": "^10",
"@trigger.dev/sdk": "4.0.6",
"bottleneck": "^2.19.5",
"camelcase-keys": "^10.0.1",
"clsx": "^2.1.1",
"copilot-design-system": "^2.2.6",
"copilot-node-sdk": "^3.16.0",
"dayjs": "^1.11.19",
"dotenv": "^17.2.1",
"drizzle-orm": "^0.44.5",
Expand Down
47 changes: 21 additions & 26 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/features/sync/lib/MapFiles.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { and, asc, eq, isNotNull, isNull, or, sql } from 'drizzle-orm'
import httpStatus from 'http-status'
import { ApiError } from 'node_modules/copilot-node-sdk/dist/codegen/api'
import z from 'zod'
import db from '@/db'
import { ObjectType } from '@/db/constants'
Expand Down Expand Up @@ -30,6 +29,7 @@ import {
} from '@/lib/copilot/types'
import AuthenticatedDropboxService from '@/lib/dropbox/AuthenticatedDropbox.service'
import logger from '@/lib/logger'
import { isAssemblyApiError } from '@/utils/assemblyError'

export class MapFilesService extends AuthenticatedDropboxService {
async getSingleFileMap(where: WhereClause): Promise<FileSyncSelectType | undefined> {
Expand Down Expand Up @@ -489,7 +489,7 @@ export class MapFilesService extends AuthenticatedDropboxService {

return formattedChannelInfo
} catch (error: unknown) {
if (error instanceof ApiError && error.status === httpStatus.BAD_REQUEST) {
if (isAssemblyApiError(error) && error.status === httpStatus.BAD_REQUEST) {
console.info('Soft delete channel map and make it inactive')
await this.deleteChannelMapById(channelMap.id)
}
Expand Down
6 changes: 3 additions & 3 deletions src/features/sync/lib/Sync.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { and, eq } from 'drizzle-orm'
import { DropboxResponseError } from 'dropbox'
import httpStatus from 'http-status'
import { ApiError as CopilotApiError } from 'node_modules/copilot-node-sdk/dist/codegen/api'
import fetch from 'node-fetch'
import z from 'zod'
import { ObjectType, type ObjectTypeValue } from '@/db/constants'
Expand All @@ -23,6 +22,7 @@ import type { CopilotFileRetrieve } from '@/lib/copilot/types'
import AuthenticatedDropboxService from '@/lib/dropbox/AuthenticatedDropbox.service'
import logger from '@/lib/logger'
import { bidirectionalMasterSync } from '@/trigger/processFileSync'
import { isAssemblyApiError } from '@/utils/assemblyError'
import { appendDateTimeToFilePath, buildPathArray, getPathFromRoot } from '@/utils/filePath'

export class SyncService extends AuthenticatedDropboxService {
Expand Down Expand Up @@ -187,8 +187,8 @@ export class SyncService extends AuthenticatedDropboxService {
await this.mapFilesService.updateChannelMapSyncedFilesCount(channelSyncId)
} catch (error: unknown) {
if (
error instanceof CopilotApiError &&
error.status === 400 &&
isAssemblyApiError(error) &&
error.status === httpStatus.BAD_REQUEST &&
error.body.message === 'Folder already exists'
) {
console.info({ message: error.body.message, path: itemPath })
Expand Down
5 changes: 2 additions & 3 deletions src/lib/copilot/CopilotAPI.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'server-only'

import type { CopilotAPI as SDK } from 'copilot-node-sdk'
import { copilotApi } from 'copilot-node-sdk'
import { assemblyApi, type AssemblyAPI as SDK } from '@assembly-js/node-sdk'
import fetch from 'node-fetch'
import z from 'zod'
import env from '@/config/server.env'
Expand Down Expand Up @@ -52,7 +51,7 @@ export class CopilotAPI {
private readonly token: string,
readonly customApiKey?: string,
) {
this.copilot = copilotApi({
this.copilot = assemblyApi({
apiKey: customApiKey ?? env.COPILOT_API_KEY,
token,
})
Expand Down
20 changes: 20 additions & 0 deletions src/utils/assemblyError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export interface AssemblyApiError extends Error {
status: number
body: {
message: string
}
}

export function isAssemblyApiError(err: unknown): err is AssemblyApiError {
if (!(err instanceof Error)) return false

// @ts-expect-error
const error = err as Record<string, unknown>

if (typeof error.status !== 'number') return false
if (!error.body || typeof error.body !== 'object') return false

const body = error.body as Record<string, unknown>

return typeof body.message === 'string'
}