Skip to content

Commit 09cccd5

Browse files
authored
feat(helm): added cert-postgresql template to helm (#1620)
* feat(helm): added cert-postgresql template to helm * use js-tiktoken (pure js) in favor of tiktoken (wasm)
1 parent 1773530 commit 09cccd5

File tree

8 files changed

+89
-15
lines changed

8 files changed

+89
-15
lines changed

apps/sim/lib/tokenization/estimators.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Token estimation and accurate counting functions for different providers
33
*/
44

5-
import { encoding_for_model, type Tiktoken } from 'tiktoken'
5+
import { encodingForModel, type Tiktoken } from 'js-tiktoken'
66
import { createLogger } from '@/lib/logs/console/logger'
77
import { MIN_TEXT_LENGTH_FOR_ESTIMATION, TOKENIZATION_CONFIG } from '@/lib/tokenization/constants'
88
import type { TokenEstimate } from '@/lib/tokenization/types'
@@ -21,12 +21,12 @@ function getEncoding(modelName: string): Tiktoken {
2121
}
2222

2323
try {
24-
const encoding = encoding_for_model(modelName as Parameters<typeof encoding_for_model>[0])
24+
const encoding = encodingForModel(modelName as Parameters<typeof encodingForModel>[0])
2525
encodingCache.set(modelName, encoding)
2626
return encoding
2727
} catch (error) {
2828
logger.warn(`Failed to get encoding for model ${modelName}, falling back to cl100k_base`)
29-
const encoding = encoding_for_model('gpt-4')
29+
const encoding = encodingForModel('gpt-4')
3030
encodingCache.set(modelName, encoding)
3131
return encoding
3232
}
@@ -79,7 +79,7 @@ export function truncateToTokenLimit(
7979
}
8080

8181
const truncatedTokens = tokens.slice(0, maxTokens)
82-
const truncatedText = new TextDecoder().decode(encoding.decode(truncatedTokens))
82+
const truncatedText = encoding.decode(truncatedTokens)
8383

8484
logger.warn(
8585
`Truncated text from ${tokens.length} to ${maxTokens} tokens (${text.length} to ${truncatedText.length} chars)`
@@ -160,9 +160,6 @@ export function batchByTokenLimit(
160160
* Clean up cached encodings (call when shutting down)
161161
*/
162162
export function clearEncodingCache(): void {
163-
for (const encoding of encodingCache.values()) {
164-
encoding.free()
165-
}
166163
encodingCache.clear()
167164
logger.info('Cleared tiktoken encoding cache')
168165
}

apps/sim/next.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const nextConfig: NextConfig = {
7575
turbopack: {
7676
resolveExtensions: ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.json'],
7777
},
78-
serverExternalPackages: ['pdf-parse', 'tiktoken'],
78+
serverExternalPackages: ['pdf-parse'],
7979
experimental: {
8080
optimizeCss: true,
8181
turbopackSourceMaps: false,

apps/sim/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"input-otp": "^1.4.2",
8383
"ioredis": "^5.6.0",
8484
"jose": "6.0.11",
85+
"js-tiktoken": "1.0.21",
8586
"js-yaml": "4.1.0",
8687
"jwt-decode": "^4.0.0",
8788
"lucide-react": "^0.479.0",
@@ -119,6 +120,7 @@
119120
},
120121
"devDependencies": {
121122
"@testing-library/jest-dom": "^6.6.3",
123+
"@trigger.dev/build": "4.0.4",
122124
"@types/html-to-text": "9.0.4",
123125
"@types/js-yaml": "4.0.9",
124126
"@types/jsdom": "21.1.7",

apps/sim/trigger.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { additionalPackages } from '@trigger.dev/build/extensions/core'
12
import { defineConfig } from '@trigger.dev/sdk'
23
import { env } from './lib/env'
34

@@ -13,4 +14,12 @@ export default defineConfig({
1314
},
1415
},
1516
dirs: ['./background'],
17+
build: {
18+
extensions: [
19+
// pdf-parse has native bindings, keep as external package
20+
additionalPackages({
21+
packages: ['pdf-parse'],
22+
}),
23+
],
24+
},
1625
})

bun.lock

Lines changed: 19 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{{- if and .Values.postgresql.enabled .Values.postgresql.tls.enabled }}
2+
apiVersion: cert-manager.io/v1
3+
kind: Certificate
4+
metadata:
5+
name: {{ include "sim.fullname" . }}-postgresql-tls-certificate
6+
namespace: {{ .Release.Namespace }}
7+
labels:
8+
{{- include "sim.postgresql.labels" . | nindent 4 }}
9+
spec:
10+
secretName: {{ .Values.postgresql.tls.certificatesSecret }}
11+
duration: {{ .Values.postgresql.tls.duration | default "87600h" }} # Default: 10 years
12+
renewBefore: {{ .Values.postgresql.tls.renewBefore | default "2160h" }} # Default: 90 days before expiry
13+
isCA: false
14+
{{- if .Values.postgresql.tls.rotationPolicy }}
15+
rotationPolicy: {{ .Values.postgresql.tls.rotationPolicy }}
16+
{{- end }}
17+
privateKey:
18+
algorithm: {{ .Values.postgresql.tls.privateKey.algorithm | default "RSA" }}
19+
size: {{ .Values.postgresql.tls.privateKey.size | default 4096 }}
20+
usages:
21+
- server auth
22+
- client auth
23+
dnsNames:
24+
- {{ include "sim.fullname" . }}-postgresql
25+
- {{ include "sim.fullname" . }}-postgresql.{{ .Release.Namespace }}.svc.cluster.local
26+
{{- with .Values.postgresql.tls.additionalDnsNames }}
27+
{{- toYaml . | nindent 2 }}
28+
{{- end }}
29+
issuerRef:
30+
name: {{ .Values.postgresql.tls.issuerRef.name }}
31+
kind: {{ .Values.postgresql.tls.issuerRef.kind | default "ClusterIssuer" }}
32+
{{- if .Values.postgresql.tls.issuerRef.group }}
33+
group: {{ .Values.postgresql.tls.issuerRef.group }}
34+
{{- end }}
35+
{{- end }}

helm/sim/values.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,28 @@ postgresql:
290290
- ReadWriteOnce
291291

292292
# SSL/TLS configuration (enable for production deployments with certificates)
293+
# Requires cert-manager to be installed in the cluster
293294
tls:
294295
enabled: false
295296
certificatesSecret: postgres-tls-secret
297+
# Certificate configuration (only used if enabled)
298+
duration: "87600h" # 10 years (default)
299+
renewBefore: "2160h" # Renew 90 days before expiry (default)
300+
rotationPolicy: "" # Set to "Always" to rotate private key on renewal (recommended for security)
301+
privateKey:
302+
algorithm: RSA # RSA or ECDSA
303+
size: 4096 # Key size in bits
304+
# Issuer reference (REQUIRED if tls.enabled is true)
305+
issuerRef:
306+
name: selfsigned-cluster-issuer # Name of your cert-manager Issuer/ClusterIssuer
307+
kind: ClusterIssuer # ClusterIssuer or Issuer
308+
group: "" # Optional: cert-manager.io (leave empty for default)
309+
# Additional DNS names (optional)
310+
additionalDnsNames: []
311+
# Example:
312+
# additionalDnsNames:
313+
# - postgres.example.com
314+
# - db.example.com
296315

297316
# PostgreSQL configuration
298317
config:

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"postgres": "^3.4.5",
4343
"remark-gfm": "4.0.1",
4444
"socket.io-client": "4.8.1",
45-
"tiktoken": "1.0.22",
4645
"twilio": "5.9.0"
4746
},
4847
"devDependencies": {

0 commit comments

Comments
 (0)