Skip to content

Commit 1130bef

Browse files
authored
fix(local): add missing deps, fix access patterns, update dockerfiles, updated turborepo (#1895)
* fix(local): add missing deps, fix access patterns, update dockerfiles * upgrade turborepo
1 parent b6139d6 commit 1130bef

File tree

8 files changed

+35
-52
lines changed

8 files changed

+35
-52
lines changed

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components-new/usage-indicator/usage-indicator.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,15 @@ interface UsageIndicatorProps {
2626
}
2727

2828
export function UsageIndicator({ onClick }: UsageIndicatorProps) {
29-
const { loadData, getUsage, getSubscriptionStatus, isLoading } = useSubscriptionStore()
29+
const { getUsage, getSubscriptionStatus, isLoading } = useSubscriptionStore()
3030

31-
// Load subscription data on mount
3231
useEffect(() => {
33-
loadData()
34-
}, [loadData])
32+
useSubscriptionStore.getState().loadData()
33+
}, [])
3534

3635
const usage = getUsage()
3736
const subscription = getSubscriptionStatus()
3837

39-
// Show skeleton while loading
4038
if (isLoading) {
4139
return (
4240
<div className={CONTAINER_STYLES} onClick={() => onClick?.()}>
@@ -54,10 +52,8 @@ export function UsageIndicator({ onClick }: UsageIndicatorProps) {
5452
)
5553
}
5654

57-
// Calculate progress percentage (capped at 100)
5855
const progressPercentage = Math.min(usage.percentUsed, 100)
5956

60-
// Determine plan type
6157
const planType = subscription.isEnterprise
6258
? 'enterprise'
6359
: subscription.isTeam
@@ -66,7 +62,6 @@ export function UsageIndicator({ onClick }: UsageIndicatorProps) {
6662
? 'pro'
6763
: 'free'
6864

69-
// Determine badge to show
7065
const billingStatus = useSubscriptionStore.getState().getBillingStatus()
7166
const isBlocked = billingStatus === 'blocked'
7267
const badgeText = isBlocked ? 'Payment Failed' : planType === 'free' ? 'Upgrade' : undefined

apps/sim/hooks/use-knowledge.ts

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -309,18 +309,11 @@ export function useDocumentChunks(
309309
hasMore: false,
310310
})
311311
const [initialLoadDone, setInitialLoadDone] = useState(false)
312-
const [isMounted, setIsMounted] = useState(false)
313312

314313
// Client-side search state
315314
const [searchQuery, setSearchQuery] = useState('')
316315
const [currentPage, setCurrentPage] = useState(urlPage)
317316

318-
// Handle mounting state
319-
useEffect(() => {
320-
setIsMounted(true)
321-
return () => setIsMounted(false)
322-
}, [])
323-
324317
// Sync with URL page changes
325318
useEffect(() => {
326319
setCurrentPage(urlPage)
@@ -331,7 +324,7 @@ export function useDocumentChunks(
331324

332325
if (enableClientSearch) {
333326
const loadAllChunks = useCallback(async () => {
334-
if (!knowledgeBaseId || !documentId || !isMounted) return
327+
if (!knowledgeBaseId || !documentId) return
335328

336329
try {
337330
setIsLoading(true)
@@ -342,7 +335,7 @@ export function useDocumentChunks(
342335
let offset = 0
343336
const limit = 50
344337

345-
while (hasMore && isMounted) {
338+
while (hasMore) {
346339
const response = await fetch(
347340
`/api/knowledge/${knowledgeBaseId}/documents/${documentId}/chunks?limit=${limit}&offset=${offset}`
348341
)
@@ -362,32 +355,24 @@ export function useDocumentChunks(
362355
}
363356
}
364357

365-
if (isMounted) {
366-
setAllChunks(allChunksData)
367-
setChunks(allChunksData) // For compatibility
368-
}
358+
setAllChunks(allChunksData)
359+
setChunks(allChunksData) // For compatibility
369360
} catch (err) {
370-
if (isMounted) {
371-
setError(err instanceof Error ? err.message : 'Failed to load chunks')
372-
logger.error(`Failed to load chunks for document ${documentId}:`, err)
373-
}
361+
setError(err instanceof Error ? err.message : 'Failed to load chunks')
362+
logger.error(`Failed to load chunks for document ${documentId}:`, err)
374363
} finally {
375-
if (isMounted) {
376-
setIsLoading(false)
377-
}
364+
setIsLoading(false)
378365
}
379-
}, [knowledgeBaseId, documentId, isMounted])
366+
}, [knowledgeBaseId, documentId])
380367

381-
// Load chunks on mount
368+
// Load chunks when knowledgeBaseId or documentId changes
382369
useEffect(() => {
383-
if (isMounted) {
384-
loadAllChunks()
385-
}
386-
}, [isMounted, loadAllChunks])
370+
loadAllChunks()
371+
}, [loadAllChunks])
387372

388373
// Client-side filtering with fuzzy search
389374
const filteredChunks = useMemo(() => {
390-
if (!isMounted || !searchQuery.trim()) return allChunks
375+
if (!searchQuery.trim()) return allChunks
391376

392377
const fuse = new Fuse(allChunks, {
393378
keys: ['content'],
@@ -400,7 +385,7 @@ export function useDocumentChunks(
400385

401386
const results = fuse.search(searchQuery)
402387
return results.map((result) => result.item)
403-
}, [allChunks, searchQuery, isMounted])
388+
}, [allChunks, searchQuery])
404389

405390
// Client-side pagination
406391
const CHUNKS_PER_PAGE = 50

apps/sim/lib/api-key/service.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { createCipheriv, createDecipheriv, randomBytes } from 'crypto'
22
import { db } from '@sim/db'
33
import { apiKey as apiKeyTable } from '@sim/db/schema'
44
import { and, eq } from 'drizzle-orm'
5-
import { nanoid } from 'nanoid'
65
import { authenticateApiKey } from '@/lib/api-key/auth'
76
import { env } from '@/lib/env'
87
import { createLogger } from '@/lib/logs/console/logger'
@@ -266,15 +265,15 @@ export async function decryptApiKey(encryptedValue: string): Promise<{ decrypted
266265
* @returns A new API key string
267266
*/
268267
export function generateApiKey(): string {
269-
return `sim_${nanoid(32)}`
268+
return `sim_${randomBytes(24).toString('base64url')}`
270269
}
271270

272271
/**
273272
* Generates a new encrypted API key with the 'sk-sim-' prefix
274273
* @returns A new encrypted API key string
275274
*/
276275
export function generateEncryptedApiKey(): string {
277-
return `sk-sim-${nanoid(32)}`
276+
return `sk-sim-${randomBytes(24).toString('base64url')}`
278277
}
279278

280279
/**

apps/sim/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"lucide-react": "^0.479.0",
8989
"mammoth": "^1.9.0",
9090
"mysql2": "3.14.3",
91+
"nanoid": "^3.3.7",
9192
"next": "^15.4.1",
9293
"next-mdx-remote": "^5.0.0",
9394
"next-runtime-env": "3.3.0",

bun.lock

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker/app.Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ WORKDIR /app
1313
# Install turbo globally
1414
RUN bun install -g turbo
1515

16-
COPY package.json bun.lock ./
17-
RUN mkdir -p apps
16+
COPY package.json bun.lock turbo.json ./
17+
RUN mkdir -p apps packages/db
1818
COPY apps/sim/package.json ./apps/sim/package.json
19+
COPY packages/db/package.json ./packages/db/package.json
1920

2021
RUN bun install --omit dev --ignore-scripts
2122

docker/realtime.Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ WORKDIR /app
1313
# Install turbo globally
1414
RUN bun install -g turbo
1515

16-
COPY package.json bun.lock ./
17-
RUN mkdir -p apps
16+
COPY package.json bun.lock turbo.json ./
17+
RUN mkdir -p apps packages/db
1818
COPY apps/sim/package.json ./apps/sim/package.json
19+
COPY packages/db/package.json ./packages/db/package.json
1920

2021
RUN bun install --omit dev --ignore-scripts
2122

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"drizzle-kit": "^0.31.4",
5353
"husky": "9.1.7",
5454
"lint-staged": "16.0.0",
55-
"turbo": "2.6.0"
55+
"turbo": "2.6.1"
5656
},
5757
"lint-staged": {
5858
"*.{js,jsx,ts,tsx,json,css,scss}": [

0 commit comments

Comments
 (0)