@cachly-dev/mcp-server 0.10.64 → 0.10.66
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/handlers/brain.js +1 -1
- package/dist/src/index.js +1 -1
- package/package.json +7 -1
- package/server.json +2 -2
- package/.env.test.example +0 -23
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -50
- package/.github/ISSUE_TEMPLATE/config.yml +0 -8
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -25
- package/.github/workflows/eas-build-android.yml +0 -58
- package/.github/workflows/eas-update.yml +0 -55
- package/.github/workflows/publish.yml +0 -72
- package/BENCH.md +0 -91
- package/CHANGELOG.md +0 -604
- package/CHANGELOG.md.tmp +0 -0
- package/Dockerfile +0 -16
- package/LAUNCH_TEXTS.md +0 -182
- package/PROGRESS.md +0 -137
- package/STRATEGY.md +0 -228
- package/VISION_10X.md +0 -133
- package/apps/travel-chaos-organizer/.env.example +0 -49
- package/apps/travel-chaos-organizer/DEPLOY.md +0 -328
- package/apps/travel-chaos-organizer/Makefile +0 -57
- package/apps/travel-chaos-organizer/README.md +0 -159
- package/apps/travel-chaos-organizer/backend/.env.example +0 -10
- package/apps/travel-chaos-organizer/backend/Dockerfile +0 -25
- package/apps/travel-chaos-organizer/backend/alembic/env.py +0 -56
- package/apps/travel-chaos-organizer/backend/alembic/script.py.mako +0 -24
- package/apps/travel-chaos-organizer/backend/alembic/versions/.gitkeep +0 -0
- package/apps/travel-chaos-organizer/backend/alembic/versions/0001_stripe_customer_id.py +0 -24
- package/apps/travel-chaos-organizer/backend/alembic/versions/0002_telegram_chat_id.py +0 -24
- package/apps/travel-chaos-organizer/backend/alembic.ini +0 -39
- package/apps/travel-chaos-organizer/backend/app/__init__.py +0 -0
- package/apps/travel-chaos-organizer/backend/app/auth/__init__.py +0 -0
- package/apps/travel-chaos-organizer/backend/app/auth/keycloak.py +0 -81
- package/apps/travel-chaos-organizer/backend/app/config.py +0 -66
- package/apps/travel-chaos-organizer/backend/app/db/__init__.py +0 -0
- package/apps/travel-chaos-organizer/backend/app/db/database.py +0 -20
- package/apps/travel-chaos-organizer/backend/app/db/migrations/001_init.sql +0 -71
- package/apps/travel-chaos-organizer/backend/app/db/migrations/002_telemetry_freemium.sql +0 -31
- package/apps/travel-chaos-organizer/backend/app/db/migrations/003_telegram_chat_id.sql +0 -4
- package/apps/travel-chaos-organizer/backend/app/db/migrations/004_stripe_and_email.sql +0 -5
- package/apps/travel-chaos-organizer/backend/app/limiter.py +0 -4
- package/apps/travel-chaos-organizer/backend/app/logging_config.py +0 -25
- package/apps/travel-chaos-organizer/backend/app/main.py +0 -77
- package/apps/travel-chaos-organizer/backend/app/models/__init__.py +0 -0
- package/apps/travel-chaos-organizer/backend/app/models/schemas.py +0 -142
- package/apps/travel-chaos-organizer/backend/app/routers/__init__.py +0 -0
- package/apps/travel-chaos-organizer/backend/app/routers/admin.py +0 -237
- package/apps/travel-chaos-organizer/backend/app/routers/cache.py +0 -13
- package/apps/travel-chaos-organizer/backend/app/routers/events.py +0 -29
- package/apps/travel-chaos-organizer/backend/app/routers/export.py +0 -122
- package/apps/travel-chaos-organizer/backend/app/routers/inbox.py +0 -122
- package/apps/travel-chaos-organizer/backend/app/routers/items.py +0 -130
- package/apps/travel-chaos-organizer/backend/app/routers/mail.py +0 -108
- package/apps/travel-chaos-organizer/backend/app/routers/parse.py +0 -303
- package/apps/travel-chaos-organizer/backend/app/routers/payments.py +0 -179
- package/apps/travel-chaos-organizer/backend/app/routers/trips.py +0 -134
- package/apps/travel-chaos-organizer/backend/app/routers/users.py +0 -169
- package/apps/travel-chaos-organizer/backend/app/routers/waitlist.py +0 -37
- package/apps/travel-chaos-organizer/backend/app/services/__init__.py +0 -0
- package/apps/travel-chaos-organizer/backend/app/services/cache.py +0 -131
- package/apps/travel-chaos-organizer/backend/app/services/drip.py +0 -128
- package/apps/travel-chaos-organizer/backend/app/services/email.py +0 -61
- package/apps/travel-chaos-organizer/backend/app/services/errors.py +0 -44
- package/apps/travel-chaos-organizer/backend/app/services/notifier.py +0 -10
- package/apps/travel-chaos-organizer/backend/app/services/ollama.py +0 -101
- package/apps/travel-chaos-organizer/backend/app/services/parser.py +0 -22
- package/apps/travel-chaos-organizer/backend/app/services/quota.py +0 -85
- package/apps/travel-chaos-organizer/backend/app/services/sentry.py +0 -11
- package/apps/travel-chaos-organizer/backend/app/services/telemetry.py +0 -35
- package/apps/travel-chaos-organizer/backend/pytest.ini +0 -4
- package/apps/travel-chaos-organizer/backend/requirements-dev.txt +0 -6
- package/apps/travel-chaos-organizer/backend/requirements.txt +0 -25
- package/apps/travel-chaos-organizer/backend/tests/__init__.py +0 -0
- package/apps/travel-chaos-organizer/backend/tests/conftest.py +0 -223
- package/apps/travel-chaos-organizer/backend/tests/test_admin.py +0 -99
- package/apps/travel-chaos-organizer/backend/tests/test_cache.py +0 -142
- package/apps/travel-chaos-organizer/backend/tests/test_drip.py +0 -32
- package/apps/travel-chaos-organizer/backend/tests/test_e2e_chain.py +0 -121
- package/apps/travel-chaos-organizer/backend/tests/test_export.py +0 -48
- package/apps/travel-chaos-organizer/backend/tests/test_inbox.py +0 -107
- package/apps/travel-chaos-organizer/backend/tests/test_items.py +0 -138
- package/apps/travel-chaos-organizer/backend/tests/test_mail.py +0 -113
- package/apps/travel-chaos-organizer/backend/tests/test_ollama.py +0 -145
- package/apps/travel-chaos-organizer/backend/tests/test_parse_url.py +0 -98
- package/apps/travel-chaos-organizer/backend/tests/test_parser.py +0 -72
- package/apps/travel-chaos-organizer/backend/tests/test_payments.py +0 -163
- package/apps/travel-chaos-organizer/backend/tests/test_quota.py +0 -46
- package/apps/travel-chaos-organizer/backend/tests/test_search.py +0 -67
- package/apps/travel-chaos-organizer/backend/tests/test_trips.py +0 -123
- package/apps/travel-chaos-organizer/backend/tests/test_users.py +0 -52
- package/apps/travel-chaos-organizer/backups/.gitkeep +0 -0
- package/apps/travel-chaos-organizer/caddy/Caddyfile +0 -27
- package/apps/travel-chaos-organizer/docker-compose.node1.yml +0 -31
- package/apps/travel-chaos-organizer/docker-compose.override.yml +0 -14
- package/apps/travel-chaos-organizer/docker-compose.yml +0 -128
- package/apps/travel-chaos-organizer/frontend/.env.example +0 -13
- package/apps/travel-chaos-organizer/frontend/app/(app)/_layout.tsx +0 -80
- package/apps/travel-chaos-organizer/frontend/app/(app)/inbox.tsx +0 -166
- package/apps/travel-chaos-organizer/frontend/app/(app)/search.tsx +0 -130
- package/apps/travel-chaos-organizer/frontend/app/(app)/settings.tsx +0 -381
- package/apps/travel-chaos-organizer/frontend/app/(app)/trips/[id].tsx +0 -346
- package/apps/travel-chaos-organizer/frontend/app/(app)/trips.tsx +0 -363
- package/apps/travel-chaos-organizer/frontend/app/(app)/upgrade/cancel.tsx +0 -34
- package/apps/travel-chaos-organizer/frontend/app/(app)/upgrade/success.tsx +0 -35
- package/apps/travel-chaos-organizer/frontend/app/(auth)/login.tsx +0 -91
- package/apps/travel-chaos-organizer/frontend/app/_layout.tsx +0 -71
- package/apps/travel-chaos-organizer/frontend/app/auth.tsx +0 -29
- package/apps/travel-chaos-organizer/frontend/app/index.tsx +0 -16
- package/apps/travel-chaos-organizer/frontend/app/onboarding.tsx +0 -119
- package/apps/travel-chaos-organizer/frontend/app.config.ts +0 -54
- package/apps/travel-chaos-organizer/frontend/assets/adaptive-icon.svg +0 -66
- package/apps/travel-chaos-organizer/frontend/assets/icon.svg +0 -79
- package/apps/travel-chaos-organizer/frontend/assets/splash.svg +0 -15
- package/apps/travel-chaos-organizer/frontend/components/BottomSheet.tsx +0 -102
- package/apps/travel-chaos-organizer/frontend/components/ConfettiCannon.tsx +0 -107
- package/apps/travel-chaos-organizer/frontend/components/ConfirmDialog.tsx +0 -109
- package/apps/travel-chaos-organizer/frontend/components/ErrorBoundary.tsx +0 -45
- package/apps/travel-chaos-organizer/frontend/components/FileUploadButton.tsx +0 -19
- package/apps/travel-chaos-organizer/frontend/components/ImportSheet.tsx +0 -155
- package/apps/travel-chaos-organizer/frontend/components/OfflineBadge.tsx +0 -55
- package/apps/travel-chaos-organizer/frontend/components/QRCodeViewer.tsx +0 -80
- package/apps/travel-chaos-organizer/frontend/components/ScoreRing.tsx +0 -39
- package/apps/travel-chaos-organizer/frontend/components/Screen.tsx +0 -39
- package/apps/travel-chaos-organizer/frontend/components/Skeleton.tsx +0 -70
- package/apps/travel-chaos-organizer/frontend/components/SwipeableInboxItem.tsx +0 -121
- package/apps/travel-chaos-organizer/frontend/components/SwipeableTimelineItem.tsx +0 -70
- package/apps/travel-chaos-organizer/frontend/components/TimelineItem.tsx +0 -73
- package/apps/travel-chaos-organizer/frontend/components/TimelineItemDetail.tsx +0 -130
- package/apps/travel-chaos-organizer/frontend/components/Toast.tsx +0 -60
- package/apps/travel-chaos-organizer/frontend/components/ToastContext.tsx +0 -42
- package/apps/travel-chaos-organizer/frontend/components/TripCard.tsx +0 -146
- package/apps/travel-chaos-organizer/frontend/components/TripQRModal.tsx +0 -70
- package/apps/travel-chaos-organizer/frontend/components/UpgradeBanner.tsx +0 -44
- package/apps/travel-chaos-organizer/frontend/eas.json +0 -22
- package/apps/travel-chaos-organizer/frontend/hooks/useInbox.ts +0 -24
- package/apps/travel-chaos-organizer/frontend/hooks/useNetworkSync.ts +0 -60
- package/apps/travel-chaos-organizer/frontend/hooks/useTrips.ts +0 -112
- package/apps/travel-chaos-organizer/frontend/lib/api.ts +0 -223
- package/apps/travel-chaos-organizer/frontend/lib/auth.ts +0 -93
- package/apps/travel-chaos-organizer/frontend/lib/db.ts +0 -86
- package/apps/travel-chaos-organizer/frontend/lib/fileCache.ts +0 -54
- package/apps/travel-chaos-organizer/frontend/lib/haptics.ts +0 -13
- package/apps/travel-chaos-organizer/frontend/lib/notifications.ts +0 -112
- package/apps/travel-chaos-organizer/frontend/lib/offlineQueue.ts +0 -145
- package/apps/travel-chaos-organizer/frontend/lib/quota.tsx +0 -43
- package/apps/travel-chaos-organizer/frontend/lib/sentry.ts +0 -28
- package/apps/travel-chaos-organizer/frontend/lib/shareIntent.ts +0 -44
- package/apps/travel-chaos-organizer/frontend/package-lock.json +0 -13221
- package/apps/travel-chaos-organizer/frontend/package.json +0 -44
- package/apps/travel-chaos-organizer/frontend/tsconfig.json +0 -23
- package/apps/travel-chaos-organizer/keycloak/realm-export.json +0 -59
- package/apps/travel-chaos-organizer/landing/index.html +0 -773
- package/apps/travel-chaos-organizer/scripts/backup.sh +0 -14
- package/apps/travel-chaos-organizer/scripts/configure-env.sh +0 -82
- package/apps/travel-chaos-organizer/scripts/deploy.sh +0 -54
- package/apps/travel-chaos-organizer/scripts/health-check.sh +0 -36
- package/apps/travel-chaos-organizer/scripts/migrate.sh +0 -7
- package/apps/travel-chaos-organizer/scripts/server-setup.sh +0 -85
- package/apps/travel-chaos-organizer/scripts/smoke-test.sh +0 -29
- package/apps/travel-chaos-organizer/scripts/verify-tracking.sh +0 -71
- package/apps/travel-chaos-organizer/telegram-bot/.env.example +0 -3
- package/apps/travel-chaos-organizer/telegram-bot/Dockerfile +0 -6
- package/apps/travel-chaos-organizer/telegram-bot/bot.py +0 -504
- package/apps/travel-chaos-organizer/telegram-bot/requirements.txt +0 -3
- package/dist/src/__tests__/auth.test.d.ts +0 -1
- package/dist/src/__tests__/auth.test.js +0 -107
- package/dist/src/__tests__/auth.test.js.map +0 -1
- package/dist/src/__tests__/brain-flow.test.d.ts +0 -12
- package/dist/src/__tests__/brain-flow.test.js +0 -1241
- package/dist/src/__tests__/brain-flow.test.js.map +0 -1
- package/dist/src/__tests__/confidence.test.d.ts +0 -13
- package/dist/src/__tests__/confidence.test.js +0 -233
- package/dist/src/__tests__/confidence.test.js.map +0 -1
- package/dist/src/__tests__/e2e/api-auth.test.d.ts +0 -7
- package/dist/src/__tests__/e2e/api-auth.test.js +0 -162
- package/dist/src/__tests__/e2e/api-auth.test.js.map +0 -1
- package/dist/src/__tests__/e2e/api-health.test.d.ts +0 -7
- package/dist/src/__tests__/e2e/api-health.test.js +0 -95
- package/dist/src/__tests__/e2e/api-health.test.js.map +0 -1
- package/dist/src/__tests__/e2e/cli.test.d.ts +0 -10
- package/dist/src/__tests__/e2e/cli.test.js +0 -204
- package/dist/src/__tests__/e2e/cli.test.js.map +0 -1
- package/dist/src/__tests__/e2e/config.d.ts +0 -35
- package/dist/src/__tests__/e2e/config.js +0 -53
- package/dist/src/__tests__/e2e/config.js.map +0 -1
- package/dist/src/__tests__/e2e/funnel.test.d.ts +0 -13
- package/dist/src/__tests__/e2e/funnel.test.js +0 -90
- package/dist/src/__tests__/e2e/funnel.test.js.map +0 -1
- package/dist/src/__tests__/e2e/mcp-tools.test.d.ts +0 -7
- package/dist/src/__tests__/e2e/mcp-tools.test.js +0 -129
- package/dist/src/__tests__/e2e/mcp-tools.test.js.map +0 -1
- package/dist/src/__tests__/e2e/provisioning.test.d.ts +0 -15
- package/dist/src/__tests__/e2e/provisioning.test.js +0 -123
- package/dist/src/__tests__/e2e/provisioning.test.js.map +0 -1
- package/dist/src/__tests__/handlers-unit.test.d.ts +0 -12
- package/dist/src/__tests__/handlers-unit.test.js +0 -505
- package/dist/src/__tests__/handlers-unit.test.js.map +0 -1
- package/dist/src/__tests__/namespace.test.d.ts +0 -1
- package/dist/src/__tests__/namespace.test.js +0 -114
- package/dist/src/__tests__/namespace.test.js.map +0 -1
- package/dist/src/__tests__/rerank.test.d.ts +0 -1
- package/dist/src/__tests__/rerank.test.js +0 -115
- package/dist/src/__tests__/rerank.test.js.map +0 -1
- package/dist/src/__tests__/utils.test.d.ts +0 -1
- package/dist/src/__tests__/utils.test.js +0 -83
- package/dist/src/__tests__/utils.test.js.map +0 -1
- package/dist/src/bench/cachly-bench.d.ts +0 -35
- package/dist/src/bench/cachly-bench.js +0 -182
- package/dist/src/bench/cachly-bench.js.map +0 -1
- package/dist/src/bench/fixtures.d.ts +0 -37
- package/dist/src/bench/fixtures.js +0 -225
- package/dist/src/bench/fixtures.js.map +0 -1
- package/dist/src/search.test.d.ts +0 -1
- package/dist/src/search.test.js +0 -713
- package/dist/src/search.test.js.map +0 -1
- package/eslint.config.js +0 -16
- package/glama.json +0 -36
- package/llms.txt +0 -155
- package/packages/telegram-notify/SPLIT_PLAN.md +0 -106
- package/packages/telegram-notify/client.ts +0 -88
- package/packages/telegram-notify/emojis.json +0 -22
- package/packages/telegram-notify/pyproject.toml +0 -17
- package/packages/telegram-notify/telegram_notify/__init__.py +0 -3
- package/packages/telegram-notify/telegram_notify/client.py +0 -87
- package/packages/telegram-notify/telegram_notify/emojis.json +0 -22
- package/scripts/e2e-run.sh +0 -160
- package/scripts/generate-icons.js +0 -28
- package/smithery.yaml +0 -45
- package/src/__tests__/auth.test.ts +0 -147
- package/src/__tests__/brain-flow.test.ts +0 -1472
- package/src/__tests__/confidence.test.ts +0 -285
- package/src/__tests__/e2e/api-auth.test.ts +0 -182
- package/src/__tests__/e2e/api-health.test.ts +0 -103
- package/src/__tests__/e2e/cli.test.ts +0 -228
- package/src/__tests__/e2e/config.ts +0 -53
- package/src/__tests__/e2e/funnel.test.ts +0 -99
- package/src/__tests__/e2e/mcp-tools.test.ts +0 -191
- package/src/__tests__/e2e/provisioning.test.ts +0 -128
- package/src/__tests__/handlers-unit.test.ts +0 -677
- package/src/__tests__/namespace.test.ts +0 -126
- package/src/__tests__/rerank.test.ts +0 -130
- package/src/__tests__/utils.test.ts +0 -81
- package/src/auth.ts +0 -46
- package/src/bench/cachly-bench.ts +0 -217
- package/src/bench/fixtures.ts +0 -256
- package/src/ckg.ts +0 -103
- package/src/confidence.ts +0 -38
- package/src/embeddings.ts +0 -217
- package/src/handlers/advanced.ts +0 -647
- package/src/handlers/brain.ts +0 -2622
- package/src/handlers/cache.ts +0 -633
- package/src/handlers/context.ts +0 -222
- package/src/handlers/fedbrain.ts +0 -1232
- package/src/handlers/instances.ts +0 -180
- package/src/handlers/roadmap.ts +0 -201
- package/src/handlers/syndicate.ts +0 -460
- package/src/handlers/tco.ts +0 -345
- package/src/handlers/team.ts +0 -1249
- package/src/index.ts +0 -2815
- package/src/namespace.ts +0 -128
- package/src/notifier.ts +0 -5
- package/src/rerank.ts +0 -148
- package/src/search.test.ts +0 -848
- package/src/search.ts +0 -1781
- package/src/tools.ts +0 -2056
- package/src/utils.ts +0 -90
- package/test-features.cjs +0 -23
- package/tsconfig.json +0 -16
- package/vitest.config.ts +0 -14
package/src/bench/fixtures.ts
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cachly-Bench fixture corpus.
|
|
3
|
-
*
|
|
4
|
-
* A small but realistic corpus of engineering "lessons" plus a set of labeled
|
|
5
|
-
* natural-language queries. Each query declares which lesson topics are *truly*
|
|
6
|
-
* relevant — the answer an agent actually wants.
|
|
7
|
-
*
|
|
8
|
-
* The corpus is deliberately adversarial in a fair way: for several queries there
|
|
9
|
-
* is a text-similar but LOW-QUALITY distractor (a failed attempt, an unverified
|
|
10
|
-
* note) competing with the proven success lesson. This is exactly the situation
|
|
11
|
-
* where raw text ranking (and a flat-file memory) goes wrong, and where Cachly's
|
|
12
|
-
* quality-aware reranking should win. The labels reward the lesson that solves the
|
|
13
|
-
* problem, not the one that merely shares vocabulary.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
export interface BenchLesson {
|
|
17
|
-
/** Stored under cachly:lesson:best:{topic} */
|
|
18
|
-
topic: string;
|
|
19
|
-
outcome: 'success' | 'partial' | 'failure';
|
|
20
|
-
what_worked: string;
|
|
21
|
-
what_failed?: string;
|
|
22
|
-
context?: string;
|
|
23
|
-
severity?: 'critical' | 'major' | 'minor';
|
|
24
|
-
confidence?: number;
|
|
25
|
-
recall_count?: number;
|
|
26
|
-
reviewed_by?: string;
|
|
27
|
-
review_level?: 'senior' | 'peer';
|
|
28
|
-
endorsements?: number;
|
|
29
|
-
tags?: string[];
|
|
30
|
-
ts?: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface BenchQuery {
|
|
34
|
-
query: string;
|
|
35
|
-
/** Topics that genuinely answer the query (the gold set). */
|
|
36
|
-
relevant: string[];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const NOW = Date.now();
|
|
40
|
-
const daysAgo = (d: number) => new Date(NOW - d * 86400_000).toISOString();
|
|
41
|
-
|
|
42
|
-
export const BENCH_LESSONS: BenchLesson[] = [
|
|
43
|
-
// ── Deploy domain ──────────────────────────────────────────────────────────
|
|
44
|
-
{
|
|
45
|
-
topic: 'deploy:k8s:rollout-stuck',
|
|
46
|
-
outcome: 'success',
|
|
47
|
-
what_worked: 'Set a readinessProbe with a longer initialDelaySeconds and a higher failureThreshold so the liveness probe stopped terminating the container before startup completed. The pod then reached ready and traffic flowed.',
|
|
48
|
-
context: 'Production release never became healthy.',
|
|
49
|
-
severity: 'critical', confidence: 0.95, recall_count: 12,
|
|
50
|
-
tags: ['kubernetes', 'deploy', 'probe'], ts: daysAgo(8),
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
topic: 'deploy:k8s:rollout-attempt-restart',
|
|
54
|
-
outcome: 'failure',
|
|
55
|
-
what_worked: '',
|
|
56
|
-
what_failed: 'The kubernetes deploy was stuck, the rollout was not finishing, so I restarted the deploy. The kubernetes deploy stayed stuck and the rollout still was not finishing. Restarted the stuck rollout again, deploy still stuck.',
|
|
57
|
-
context: 'Kubernetes deploy stuck, rollout not finishing.',
|
|
58
|
-
severity: 'major', confidence: 0.3, recall_count: 0,
|
|
59
|
-
tags: ['kubernetes', 'deploy'], ts: daysAgo(9),
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
topic: 'deploy:docker:image-too-large',
|
|
63
|
-
outcome: 'success',
|
|
64
|
-
what_worked: 'Reduced Docker image size dramatically with a multi-stage build and a slim base image, moving build-only deps out of the final layer.',
|
|
65
|
-
context: 'CI pushes were slow due to a 1.8GB image.',
|
|
66
|
-
severity: 'minor', confidence: 0.9, recall_count: 6,
|
|
67
|
-
tags: ['docker', 'deploy', 'optimization'], ts: daysAgo(20),
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
// ── Database domain ────────────────────────────────────────────────────────
|
|
71
|
-
{
|
|
72
|
-
topic: 'db:postgres:connection-pool-exhausted',
|
|
73
|
-
outcome: 'success',
|
|
74
|
-
what_worked: 'Added PgBouncer in transaction pooling mode and lowered the per-service max pool size so backends were shared. Peak traffic stopped exhausting backends.',
|
|
75
|
-
context: 'API returned 500s at peak traffic.',
|
|
76
|
-
severity: 'critical', confidence: 0.92, recall_count: 9,
|
|
77
|
-
tags: ['postgres', 'database', 'pool'], ts: daysAgo(15),
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
topic: 'db:postgres:slow-query-missing-index',
|
|
81
|
-
outcome: 'success',
|
|
82
|
-
what_worked: 'A slow Postgres query was fixed by adding a composite index on (tenant_id, created_at); query dropped from 4s to 12ms.',
|
|
83
|
-
context: 'Dashboard timed out loading recent events.',
|
|
84
|
-
severity: 'major', confidence: 0.88, recall_count: 4,
|
|
85
|
-
tags: ['postgres', 'database', 'index', 'performance'], ts: daysAgo(30),
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
topic: 'db:postgres:pool-raise-limit-attempt',
|
|
89
|
-
outcome: 'failure',
|
|
90
|
-
what_worked: '',
|
|
91
|
-
what_failed: 'Postgres had too many connections under load, so I raised max_connections. Postgres still had too many connections under load and the load made it worse — too many connections again under load.',
|
|
92
|
-
context: 'Postgres too many connections under load.',
|
|
93
|
-
severity: 'major', confidence: 0.25, recall_count: 0,
|
|
94
|
-
tags: ['postgres', 'database', 'pool'], ts: daysAgo(16),
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
// ── Auth domain ────────────────────────────────────────────────────────────
|
|
98
|
-
{
|
|
99
|
-
topic: 'auth:jwt:expired-on-restart',
|
|
100
|
-
outcome: 'success',
|
|
101
|
-
what_worked: 'JWT was lost on server restart because it was only kept in memory; persisting the token to disk after the device flow fixed recall counts staying at zero.',
|
|
102
|
-
context: 'Telemetry showed zero authenticated calls after restarts.',
|
|
103
|
-
severity: 'critical', confidence: 0.93, recall_count: 7,
|
|
104
|
-
tags: ['jwt', 'auth', 'persistence'], ts: daysAgo(3),
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
topic: 'auth:pkce:keycloak-rejects-exchange',
|
|
108
|
-
outcome: 'success',
|
|
109
|
-
what_worked: 'Keycloak rejected the PKCE code exchange because the verifier used non-URL-safe Base64; switching to RFC 7636 Base64URL random bytes fixed the login.',
|
|
110
|
-
context: 'Mobile login failed at the token exchange step.',
|
|
111
|
-
severity: 'major', confidence: 0.9, recall_count: 3,
|
|
112
|
-
tags: ['pkce', 'auth', 'keycloak', 'oauth'], ts: daysAgo(2),
|
|
113
|
-
},
|
|
114
|
-
|
|
115
|
-
// ── Redis / cache domain ───────────────────────────────────────────────────
|
|
116
|
-
{
|
|
117
|
-
topic: 'redis:noauth-on-every-call',
|
|
118
|
-
outcome: 'success',
|
|
119
|
-
what_worked: 'The connection endpoint omitted the password field, so the client connected unauthenticated; returning the credential explicitly in the response let the client authenticate and the calls succeeded.',
|
|
120
|
-
context: 'Hosted Valkey requires a credential.',
|
|
121
|
-
severity: 'critical', confidence: 0.94, recall_count: 11,
|
|
122
|
-
tags: ['redis', 'valkey', 'auth'], ts: daysAgo(4),
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
topic: 'redis:noauth-disable-auth-attempt',
|
|
126
|
-
outcome: 'failure',
|
|
127
|
-
what_worked: '',
|
|
128
|
-
what_failed: 'Redis threw NOAUTH on every call, so I tried disabling auth on Redis. Redis still threw NOAUTH on every call. Tried again to stop the NOAUTH error on every Redis call — no luck.',
|
|
129
|
-
context: 'Redis NOAUTH error on every call.',
|
|
130
|
-
severity: 'major', confidence: 0.2, recall_count: 0,
|
|
131
|
-
tags: ['redis', 'auth'], ts: daysAgo(5),
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
topic: 'redis:keys-no-ttl-memory-leak',
|
|
135
|
-
outcome: 'success',
|
|
136
|
-
what_worked: 'Redis memory grew unbounded because dependency-index and history keys had no TTL; adding a 90-day expire and an ltrim bounded the memory.',
|
|
137
|
-
context: 'Instance memory crept up over weeks of use.',
|
|
138
|
-
severity: 'major', confidence: 0.85, recall_count: 2,
|
|
139
|
-
tags: ['redis', 'ttl', 'memory'], ts: daysAgo(1),
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
// ── CI / build domain ──────────────────────────────────────────────────────
|
|
143
|
-
{
|
|
144
|
-
topic: 'ci:npm-ci-lockfile-mismatch',
|
|
145
|
-
outcome: 'success',
|
|
146
|
-
what_worked: 'CI "npm ci" failed because a dependency was added to package.json but the lockfile was never regenerated; running npm install to update package-lock.json fixed the build.',
|
|
147
|
-
context: 'GitHub Actions install step failed after adding a dep.',
|
|
148
|
-
severity: 'major', confidence: 0.91, recall_count: 5,
|
|
149
|
-
tags: ['ci', 'npm', 'lockfile'], ts: daysAgo(0),
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
topic: 'ci:golangci-lint-errcheck',
|
|
153
|
-
outcome: 'success',
|
|
154
|
-
what_worked: 'golangci-lint failed on an unchecked recover() return value; assigning it to _ satisfied errcheck.',
|
|
155
|
-
context: 'Go lint job blocked the deploy pipeline.',
|
|
156
|
-
severity: 'minor', confidence: 0.8, recall_count: 1,
|
|
157
|
-
tags: ['ci', 'go', 'lint'], ts: daysAgo(1),
|
|
158
|
-
},
|
|
159
|
-
|
|
160
|
-
// ── Frontend domain ────────────────────────────────────────────────────────
|
|
161
|
-
{
|
|
162
|
-
topic: 'frontend:cors-preflight-blocked',
|
|
163
|
-
outcome: 'success',
|
|
164
|
-
what_worked: 'Dashboard mutations failed because the CORS middleware did not allow PUT/PATCH; adding them to AllowMethods fixed the preflight.',
|
|
165
|
-
context: 'BYOK and webhook settings could not be saved from the browser.',
|
|
166
|
-
severity: 'major', confidence: 0.87, recall_count: 4,
|
|
167
|
-
tags: ['cors', 'frontend', 'api'], ts: daysAgo(6),
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
topic: 'frontend:hydration-mismatch',
|
|
171
|
-
outcome: 'partial',
|
|
172
|
-
what_worked: 'A Next.js hydration mismatch was reduced by guarding a date render with a client-only effect, though the root cause (locale formatting) still needs work.',
|
|
173
|
-
context: 'Console hydration warnings on the landing page.',
|
|
174
|
-
severity: 'minor', confidence: 0.6, recall_count: 1,
|
|
175
|
-
tags: ['nextjs', 'frontend', 'hydration'], ts: daysAgo(25),
|
|
176
|
-
},
|
|
177
|
-
|
|
178
|
-
// ── Governance adversarial pair: two similar-text success lessons ──────────
|
|
179
|
-
// Only the reviewed one should win; baseline cannot distinguish them by text.
|
|
180
|
-
{
|
|
181
|
-
topic: 'auth:csrf:double-submit-cookie',
|
|
182
|
-
outcome: 'success',
|
|
183
|
-
what_worked: 'CSRF protection was added via the double-submit cookie pattern: the server sets a random CSRF token cookie; the client echoes it as a request header. Requests with a mismatched or absent header are rejected.',
|
|
184
|
-
context: 'API mutations lacked CSRF protection; security audit required a fix.',
|
|
185
|
-
severity: 'critical', confidence: 0.91, recall_count: 2,
|
|
186
|
-
reviewed_by: 'senior-alice', review_level: 'senior', endorsements: 2,
|
|
187
|
-
tags: ['csrf', 'auth', 'security', 'cookie'], ts: daysAgo(12),
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
topic: 'auth:csrf:origin-header-check',
|
|
191
|
-
outcome: 'success',
|
|
192
|
-
what_worked: 'CSRF mitigation attempted by checking the Origin header on API requests, but this was bypassed in a penetration test because same-site requests from subdomains also sent the header.',
|
|
193
|
-
context: 'API mutations lacked CSRF protection; origin header check was insufficient.',
|
|
194
|
-
severity: 'major', confidence: 0.55, recall_count: 1,
|
|
195
|
-
tags: ['csrf', 'auth', 'security'], ts: daysAgo(14),
|
|
196
|
-
},
|
|
197
|
-
];
|
|
198
|
-
|
|
199
|
-
export const BENCH_QUERIES: BenchQuery[] = [
|
|
200
|
-
{
|
|
201
|
-
query: 'kubernetes deploy stuck rollout not finishing',
|
|
202
|
-
relevant: ['deploy:k8s:rollout-stuck'],
|
|
203
|
-
},
|
|
204
|
-
{
|
|
205
|
-
query: 'postgres too many connections under load',
|
|
206
|
-
relevant: ['db:postgres:connection-pool-exhausted'],
|
|
207
|
-
},
|
|
208
|
-
{
|
|
209
|
-
query: 'dashboard query is slow and times out',
|
|
210
|
-
relevant: ['db:postgres:slow-query-missing-index'],
|
|
211
|
-
},
|
|
212
|
-
{
|
|
213
|
-
query: 'jwt lost after restart recall count zero',
|
|
214
|
-
relevant: ['auth:jwt:expired-on-restart'],
|
|
215
|
-
},
|
|
216
|
-
{
|
|
217
|
-
query: 'keycloak rejects pkce token exchange on login',
|
|
218
|
-
relevant: ['auth:pkce:keycloak-rejects-exchange'],
|
|
219
|
-
},
|
|
220
|
-
{
|
|
221
|
-
query: 'redis noauth error on every call',
|
|
222
|
-
relevant: ['redis:noauth-on-every-call'],
|
|
223
|
-
},
|
|
224
|
-
{
|
|
225
|
-
query: 'redis memory keeps growing unbounded',
|
|
226
|
-
relevant: ['redis:keys-no-ttl-memory-leak'],
|
|
227
|
-
},
|
|
228
|
-
{
|
|
229
|
-
query: 'npm ci fails in github actions after adding dependency',
|
|
230
|
-
relevant: ['ci:npm-ci-lockfile-mismatch'],
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
query: 'cannot save settings cors preflight blocked',
|
|
234
|
-
relevant: ['frontend:cors-preflight-blocked'],
|
|
235
|
-
},
|
|
236
|
-
{
|
|
237
|
-
query: 'docker image too big slow ci push',
|
|
238
|
-
relevant: ['deploy:docker:image-too-large'],
|
|
239
|
-
},
|
|
240
|
-
{
|
|
241
|
-
query: 'go lint failing on unchecked return value',
|
|
242
|
-
relevant: ['ci:golangci-lint-errcheck'],
|
|
243
|
-
},
|
|
244
|
-
// Multi-relevant: both postgres performance lessons are reasonable answers.
|
|
245
|
-
{
|
|
246
|
-
query: 'postgres performance problem in production',
|
|
247
|
-
relevant: ['db:postgres:connection-pool-exhausted', 'db:postgres:slow-query-missing-index'],
|
|
248
|
-
},
|
|
249
|
-
// Governance adversarial: two CSRF lessons have almost identical text, but only
|
|
250
|
-
// the senior-reviewed canonical one is a proven complete solution. Quality
|
|
251
|
-
// reranking must prefer the reviewed+endorsed lesson over the unreviewed partial.
|
|
252
|
-
{
|
|
253
|
-
query: 'CSRF protection missing on API mutations security',
|
|
254
|
-
relevant: ['auth:csrf:double-submit-cookie'],
|
|
255
|
-
},
|
|
256
|
-
];
|
package/src/ckg.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { Redis } from 'ioredis';
|
|
2
|
-
|
|
3
|
-
// ── Layer 1: Causal Knowledge Graph (CKG) helpers ────────────────────────────
|
|
4
|
-
// Nodes: cachly:ckg:node:{id} → CKGNode | PersonNode | FileNode
|
|
5
|
-
// Edges: cachly:ckg:edge:{from}:{edgeType}:{to} → CKGEdge
|
|
6
|
-
|
|
7
|
-
export type CKGEdge = {
|
|
8
|
-
from: string; to: string; edgeType: string;
|
|
9
|
-
successes: number; trials: number; confidence: number; last_updated: string;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export type CKGNode = { id: string; domain: string; type: string; count: number; ts: string };
|
|
13
|
-
|
|
14
|
-
// Phase 3A: People nodes — auto-built from learn_from_attempts(author=...)
|
|
15
|
-
export type PersonNode = {
|
|
16
|
-
id: string; // "person:{slug}"
|
|
17
|
-
handle: string; // original author string as provided
|
|
18
|
-
domain: string; // first/primary problem domain seen
|
|
19
|
-
type: 'person';
|
|
20
|
-
count: number; // number of lessons authored
|
|
21
|
-
last_active: string; // ISO timestamp of most recent contribution
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// Phase 3A: File nodes — auto-built from learn_from_attempts(file_paths=[...])
|
|
25
|
-
export type FileNode = {
|
|
26
|
-
id: string; // "file:{slug}"
|
|
27
|
-
path: string; // original file path
|
|
28
|
-
domain: string;
|
|
29
|
-
type: 'file';
|
|
30
|
-
count: number; // number of times referenced in lessons
|
|
31
|
-
ts: string;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const STOPWORDS_CKG = new Set(['that','this','with','from','when','then','also','have','been','will','were','they','them','than','more','some','into','over','only','just','where','while','which','there','their','would','could','should','after','before','about']);
|
|
35
|
-
|
|
36
|
-
export function ckgSlug(text: string): string {
|
|
37
|
-
return text.toLowerCase().replace(/[^a-z0-9\-:]/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '').slice(0, 80);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** Extract 1-3 significant keywords from free text for a problem concept */
|
|
41
|
-
export function extractProblemConcept(text: string): string | null {
|
|
42
|
-
const words = text.toLowerCase()
|
|
43
|
-
.replace(/[^a-z0-9\s\-_]/g, ' ').split(/\s+/)
|
|
44
|
-
.filter(w => w.length > 3 && !STOPWORDS_CKG.has(w))
|
|
45
|
-
.slice(0, 5);
|
|
46
|
-
if (words.length === 0) return null;
|
|
47
|
-
return words.slice(0, 2).join('-');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export async function ckgUpsertNode(redis: Redis, id: string, domain: string, type: string): Promise<void> {
|
|
51
|
-
const key = `cachly:ckg:node:${id}`;
|
|
52
|
-
const raw = await redis.get(key);
|
|
53
|
-
const node: CKGNode = raw ? JSON.parse(raw) : { id, domain, type, count: 0, ts: new Date().toISOString() };
|
|
54
|
-
node.count = (node.count || 0) + 1;
|
|
55
|
-
node.ts = new Date().toISOString();
|
|
56
|
-
await redis.set(key, JSON.stringify(node));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** Upsert a Person node; returns the node id ("person:{slug}"). */
|
|
60
|
-
export async function ckgUpsertPersonNode(redis: Redis, handle: string, domain: string): Promise<string> {
|
|
61
|
-
const id = `person:${ckgSlug(handle)}`;
|
|
62
|
-
const key = `cachly:ckg:node:${id}`;
|
|
63
|
-
const raw = await redis.get(key);
|
|
64
|
-
const node: PersonNode = raw
|
|
65
|
-
? JSON.parse(raw)
|
|
66
|
-
: { id, handle, domain, type: 'person', count: 0, last_active: new Date().toISOString() };
|
|
67
|
-
node.count = (node.count || 0) + 1;
|
|
68
|
-
node.last_active = new Date().toISOString();
|
|
69
|
-
if (!node.domain) node.domain = domain;
|
|
70
|
-
await redis.set(key, JSON.stringify(node));
|
|
71
|
-
return id;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** Upsert a File node; returns the node id ("file:{slug}"). */
|
|
75
|
-
export async function ckgUpsertFileNode(redis: Redis, filePath: string): Promise<string> {
|
|
76
|
-
const dir = filePath.split('/')[0] ?? 'root';
|
|
77
|
-
const id = `file:${ckgSlug(filePath)}`;
|
|
78
|
-
const key = `cachly:ckg:node:${id}`;
|
|
79
|
-
const raw = await redis.get(key);
|
|
80
|
-
const node: FileNode = raw
|
|
81
|
-
? JSON.parse(raw)
|
|
82
|
-
: { id, path: filePath, domain: dir, type: 'file', count: 0, ts: new Date().toISOString() };
|
|
83
|
-
node.count = (node.count || 0) + 1;
|
|
84
|
-
node.ts = new Date().toISOString();
|
|
85
|
-
await redis.set(key, JSON.stringify(node));
|
|
86
|
-
return id;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export async function ckgUpdateEdge(redis: Redis, from: string, edgeType: string, to: string, success: boolean, partial = false): Promise<void> {
|
|
90
|
-
const key = `cachly:ckg:edge:${from}:${edgeType}:${to}`;
|
|
91
|
-
const raw = await redis.get(key);
|
|
92
|
-
const edge: CKGEdge = raw ? JSON.parse(raw) : { from, to, edgeType, successes: 0, trials: 0, confidence: 0, last_updated: '' };
|
|
93
|
-
edge.trials = (edge.trials || 0) + 1;
|
|
94
|
-
if (success) edge.successes = (edge.successes || 0) + 1;
|
|
95
|
-
else if (partial) edge.successes = (edge.successes || 0) + 0.5;
|
|
96
|
-
// Beta distribution smoothed confidence: (successes+1) / (trials+2)
|
|
97
|
-
edge.confidence = (edge.successes + 1) / (edge.trials + 2);
|
|
98
|
-
edge.last_updated = new Date().toISOString();
|
|
99
|
-
await redis.set(key, JSON.stringify(edge));
|
|
100
|
-
// Index: set of edge keys per source node (for fast traversal)
|
|
101
|
-
await redis.sadd(`cachly:ckg:idx:from:${from}`, key);
|
|
102
|
-
await redis.sadd(`cachly:ckg:idx:to:${to}`, key);
|
|
103
|
-
}
|
package/src/confidence.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
|
-
|
|
3
|
-
// ── Confidence Decay Config ───────────────────────────────────────────────────
|
|
4
|
-
export const CONFIDENCE_WARN_DAYS = Number(process.env.CACHLY_CONFIDENCE_WARN_DAYS ?? 5);
|
|
5
|
-
export const CONFIDENCE_STALE_DAYS = Number(process.env.CACHLY_CONFIDENCE_STALE_DAYS ?? 10);
|
|
6
|
-
export const CONFIDENCE_WARN_VALUE = 0.7;
|
|
7
|
-
export const CONFIDENCE_STALE_VALUE = 0.5;
|
|
8
|
-
|
|
9
|
-
/** Calculate current confidence for a lesson based on how long since last verified. */
|
|
10
|
-
export function calculateConfidence(lesson: { verified_at?: string; ts: string; recall_count?: number }): number {
|
|
11
|
-
const ref = lesson.verified_at ?? lesson.ts;
|
|
12
|
-
const ageMs = Date.now() - new Date(ref).getTime();
|
|
13
|
-
const ageDays = ageMs / 86400000;
|
|
14
|
-
if (ageDays >= CONFIDENCE_STALE_DAYS) return CONFIDENCE_STALE_VALUE;
|
|
15
|
-
if (ageDays >= CONFIDENCE_WARN_DAYS) return CONFIDENCE_WARN_VALUE;
|
|
16
|
-
return 1.0 - (ageDays / CONFIDENCE_WARN_DAYS) * (1.0 - CONFIDENCE_WARN_VALUE);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** Render a confidence badge string. */
|
|
20
|
-
export function confidenceBadge(confidence: number, ageDays: number): string {
|
|
21
|
-
if (confidence >= 0.9) return '✅';
|
|
22
|
-
if (confidence >= 0.7) return `⚠️ (${Math.round(ageDays)}d old, confidence ${(confidence * 100).toFixed(0)}% — verify before applying)`;
|
|
23
|
-
return `🔴 STALE (${Math.round(ageDays)}d old, confidence ${(confidence * 100).toFixed(0)}% — likely outdated!)`;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Category-specific required fields for structured lessons. */
|
|
27
|
-
export const STRUCTURED_TEMPLATES: Record<string, { required: string[]; hint: string }> = {
|
|
28
|
-
'deploy': { required: ['commands'], hint: 'deploy:* needs commands[]' },
|
|
29
|
-
'bash': { required: ['commands'], hint: 'bash:* needs commands[]' },
|
|
30
|
-
'infra': { required: ['commands'], hint: 'infra:* needs commands[] + verified on real system' },
|
|
31
|
-
'pricing': { required: [], hint: 'pricing:* — add context with source (e.g. "Stripe Dashboard Apr 2026")' },
|
|
32
|
-
'stripe': { required: [], hint: 'stripe:* — add context with Stripe API version' },
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/** Fast content hash for index invalidation (not cryptographic, just change detection) */
|
|
36
|
-
export function simpleHash(text: string): string {
|
|
37
|
-
return createHash('md5').update(text).digest('hex').slice(0, 12);
|
|
38
|
-
}
|
package/src/embeddings.ts
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ┌──────────────────────────────────────────────────────────────────────┐
|
|
3
|
-
* │ EMBEDDING PROVIDER — pluggable, client-side first │
|
|
4
|
-
* │ │
|
|
5
|
-
* │ Auto-detects from env vars. To force a provider, set: │
|
|
6
|
-
* │ CACHLY_EMBED_PROVIDER=openai (+ OPENAI_API_KEY) │
|
|
7
|
-
* │ CACHLY_EMBED_PROVIDER=gemini (+ GEMINI_API_KEY) │
|
|
8
|
-
* │ CACHLY_EMBED_PROVIDER=mistral (+ MISTRAL_API_KEY) │
|
|
9
|
-
* │ CACHLY_EMBED_PROVIDER=cohere (+ COHERE_API_KEY) │
|
|
10
|
-
* │ CACHLY_EMBED_PROVIDER=ollama (+ OLLAMA_BASE_URL, local) │
|
|
11
|
-
* │ CACHLY_EMBED_PROVIDER=cachly (server-side fallback, no key) │
|
|
12
|
-
* │ │
|
|
13
|
-
* │ Priority: openai > gemini > mistral > cohere > ollama > cachly │
|
|
14
|
-
* │ Brain works WITHOUT embedding (keyword search + exact key lookup). │
|
|
15
|
-
* │ Embedding is an optional boost for semantic_search/index_project. │
|
|
16
|
-
* └──────────────────────────────────────────────────────────────────────┘
|
|
17
|
-
*
|
|
18
|
-
* Mutable config — call setEmbedJwt() when the JWT changes (device flow).
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
// ── Mutable config (synced with index.ts JWT on device-flow auth) ────────────
|
|
22
|
-
export const embedConfig = {
|
|
23
|
-
apiUrl: process.env.CACHLY_API_URL ?? 'https://api.cachly.dev',
|
|
24
|
-
jwt: process.env.CACHLY_JWT ?? '',
|
|
25
|
-
model: process.env.CACHLY_EMBED_MODEL ?? '',
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/** Call this when JWT is refreshed (e.g. after device flow). */
|
|
29
|
-
export function setEmbedJwt(jwt: string): void {
|
|
30
|
-
embedConfig.jwt = jwt;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// ── Provider auto-detection ───────────────────────────────────────────────────
|
|
34
|
-
|
|
35
|
-
function detectEmbedProvider(): string {
|
|
36
|
-
// Client-side keys first (direct, fast, no server roundtrip)
|
|
37
|
-
if (process.env.OPENAI_API_KEY) return 'openai';
|
|
38
|
-
if (process.env.GEMINI_API_KEY) return 'gemini';
|
|
39
|
-
if (process.env.MISTRAL_API_KEY) return 'mistral';
|
|
40
|
-
if (process.env.COHERE_API_KEY) return 'cohere';
|
|
41
|
-
if (process.env.OLLAMA_BASE_URL) return 'ollama';
|
|
42
|
-
// Server-side fallback — no API key needed, but adds latency
|
|
43
|
-
if (process.env.CACHLY_JWT) return 'cachly';
|
|
44
|
-
return 'none'; // no provider → embedding disabled, brain still works via exact keys
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export const EMBED_PROVIDER = (process.env.CACHLY_EMBED_PROVIDER ?? detectEmbedProvider()).toLowerCase();
|
|
48
|
-
|
|
49
|
-
// ── Multi-provider embedding ─────────────────────────────────────────────────
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Compute an embedding vector for `text` using the configured provider.
|
|
53
|
-
*
|
|
54
|
-
* Client-side (recommended — set one API key in your .env):
|
|
55
|
-
* openai – OPENAI_API_KEY · text-embedding-3-small
|
|
56
|
-
* gemini – GEMINI_API_KEY · text-embedding-004
|
|
57
|
-
* mistral – MISTRAL_API_KEY · mistral-embed
|
|
58
|
-
* cohere – COHERE_API_KEY · embed-english-v3.0
|
|
59
|
-
* ollama – OLLAMA_BASE_URL · nomic-embed-text (local, free)
|
|
60
|
-
*
|
|
61
|
-
* Server-side fallback (no key needed on client):
|
|
62
|
-
* cachly – POST /api/v1/embed (requires CACHLY_JWT)
|
|
63
|
-
*
|
|
64
|
-
* Note: Brain works fully WITHOUT embedding (keyword search + exact keys).
|
|
65
|
-
* Embedding is an OPTIONAL boost for semantic_search and index_project.
|
|
66
|
-
*/
|
|
67
|
-
export async function computeEmbedding(text: string): Promise<number[]> {
|
|
68
|
-
switch (EMBED_PROVIDER) {
|
|
69
|
-
case 'cachly': {
|
|
70
|
-
// Server-side embedding — the Cachly API computes the embedding
|
|
71
|
-
// using whatever provider is configured on the server. No client-side API key needed.
|
|
72
|
-
if (!embedConfig.jwt) throw new Error(
|
|
73
|
-
'CACHLY_JWT not set.\n\n' +
|
|
74
|
-
'The "cachly" provider uses server-side embeddings via the Cachly API.\n' +
|
|
75
|
-
'Set CACHLY_JWT, or use another provider via CACHLY_EMBED_PROVIDER:\n' +
|
|
76
|
-
' openai → OPENAI_API_KEY\n' +
|
|
77
|
-
' gemini → GEMINI_API_KEY\n' +
|
|
78
|
-
' ollama → OLLAMA_BASE_URL (local, no key needed)'
|
|
79
|
-
);
|
|
80
|
-
const url = `${embedConfig.apiUrl}/api/v1/embed`;
|
|
81
|
-
const body: Record<string, string> = { text };
|
|
82
|
-
if (embedConfig.model) body.model = embedConfig.model;
|
|
83
|
-
const res = await fetch(url, {
|
|
84
|
-
method: 'POST',
|
|
85
|
-
headers: {
|
|
86
|
-
'Content-Type': 'application/json',
|
|
87
|
-
'Authorization': `Bearer ${embedConfig.jwt}`,
|
|
88
|
-
},
|
|
89
|
-
body: JSON.stringify(body),
|
|
90
|
-
});
|
|
91
|
-
if (!res.ok) {
|
|
92
|
-
const errBody = await res.text();
|
|
93
|
-
throw new Error(`Cachly embed API error ${res.status}: ${errBody}`);
|
|
94
|
-
}
|
|
95
|
-
const json = (await res.json()) as { embedding: number[]; dimensions: number };
|
|
96
|
-
return json.embedding;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
case 'mistral': {
|
|
100
|
-
const key = process.env.MISTRAL_API_KEY;
|
|
101
|
-
if (!key) throw new Error('MISTRAL_API_KEY not set');
|
|
102
|
-
const model = embedConfig.model !== 'text-embedding-3-small' ? embedConfig.model : 'mistral-embed';
|
|
103
|
-
const res = await fetch('https://api.mistral.ai/v1/embeddings', {
|
|
104
|
-
method: 'POST',
|
|
105
|
-
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` },
|
|
106
|
-
body: JSON.stringify({ model, input: [text] }),
|
|
107
|
-
});
|
|
108
|
-
if (!res.ok) throw new Error(`Mistral embedding error: ${res.statusText}`);
|
|
109
|
-
const json = (await res.json()) as { data: { embedding: number[] }[] };
|
|
110
|
-
if (!json.data?.[0]?.embedding) throw new Error('Mistral returned empty embedding response');
|
|
111
|
-
return json.data[0].embedding;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
case 'cohere': {
|
|
115
|
-
const key = process.env.COHERE_API_KEY;
|
|
116
|
-
if (!key) throw new Error('COHERE_API_KEY not set');
|
|
117
|
-
const model = embedConfig.model !== 'text-embedding-3-small' ? embedConfig.model : 'embed-english-v3.0';
|
|
118
|
-
const res = await fetch('https://api.cohere.com/v2/embed', {
|
|
119
|
-
method: 'POST',
|
|
120
|
-
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` },
|
|
121
|
-
body: JSON.stringify({ model, texts: [text], input_type: 'search_query', embedding_types: ['float'] }),
|
|
122
|
-
});
|
|
123
|
-
if (!res.ok) throw new Error(`Cohere embedding error: ${res.statusText}`);
|
|
124
|
-
const json = (await res.json()) as { embeddings: { float: number[][] } };
|
|
125
|
-
return json.embeddings.float[0];
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
case 'ollama': {
|
|
129
|
-
const base = process.env.OLLAMA_BASE_URL ?? 'http://localhost:11434';
|
|
130
|
-
const model = embedConfig.model !== 'text-embedding-3-small' ? embedConfig.model : 'nomic-embed-text';
|
|
131
|
-
const res = await fetch(`${base}/api/embeddings`, {
|
|
132
|
-
method: 'POST',
|
|
133
|
-
headers: { 'Content-Type': 'application/json' },
|
|
134
|
-
body: JSON.stringify({ model, prompt: text }),
|
|
135
|
-
});
|
|
136
|
-
if (!res.ok) throw new Error(`Ollama embedding error: ${res.statusText}`);
|
|
137
|
-
const json = (await res.json()) as { embedding: number[] };
|
|
138
|
-
return json.embedding;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
case 'gemini': {
|
|
142
|
-
const key = process.env.GEMINI_API_KEY;
|
|
143
|
-
if (!key) throw new Error('GEMINI_API_KEY not set');
|
|
144
|
-
const model = embedConfig.model !== 'text-embedding-3-small' ? embedConfig.model : 'text-embedding-004';
|
|
145
|
-
const res = await fetch(
|
|
146
|
-
`https://generativelanguage.googleapis.com/v1beta/models/${model}:embedContent?key=${key}`,
|
|
147
|
-
{
|
|
148
|
-
method: 'POST',
|
|
149
|
-
headers: { 'Content-Type': 'application/json' },
|
|
150
|
-
body: JSON.stringify({ model: `models/${model}`, content: { parts: [{ text }] } }),
|
|
151
|
-
},
|
|
152
|
-
);
|
|
153
|
-
if (!res.ok) throw new Error(`Gemini embedding error: ${res.statusText}`);
|
|
154
|
-
const json = (await res.json()) as { embedding: { values: number[] } };
|
|
155
|
-
return json.embedding.values;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
case 'openai': {
|
|
159
|
-
const key = process.env.OPENAI_API_KEY;
|
|
160
|
-
if (!key) throw new Error(
|
|
161
|
-
'OPENAI_API_KEY not set.\n\n' +
|
|
162
|
-
'Set OPENAI_API_KEY in your .env, or switch provider:\n' +
|
|
163
|
-
' CACHLY_EMBED_PROVIDER=gemini (+ GEMINI_API_KEY)\n' +
|
|
164
|
-
' CACHLY_EMBED_PROVIDER=ollama (local, free)\n' +
|
|
165
|
-
' CACHLY_EMBED_PROVIDER=cachly (server-side, no key needed)'
|
|
166
|
-
);
|
|
167
|
-
const model = embedConfig.model || 'text-embedding-3-small';
|
|
168
|
-
const res = await fetch('https://api.openai.com/v1/embeddings', {
|
|
169
|
-
method: 'POST',
|
|
170
|
-
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` },
|
|
171
|
-
body: JSON.stringify({ model, input: text }),
|
|
172
|
-
});
|
|
173
|
-
if (!res.ok) throw new Error(`OpenAI embedding error: ${res.statusText}`);
|
|
174
|
-
const json = (await res.json()) as { data: { embedding: number[] }[] };
|
|
175
|
-
if (!json.data?.[0]?.embedding) throw new Error('OpenAI returned empty embedding response');
|
|
176
|
-
return json.data[0].embedding;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
default: {
|
|
180
|
-
throw new Error(
|
|
181
|
-
`Unknown CACHLY_EMBED_PROVIDER="${EMBED_PROVIDER}".\n` +
|
|
182
|
-
'Supported: cachly (default), openai, mistral, cohere, ollama, gemini'
|
|
183
|
-
);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/** Returns true if the configured embedding provider has its required key/URL set. */
|
|
189
|
-
export function hasEmbedProvider(): boolean {
|
|
190
|
-
switch (EMBED_PROVIDER) {
|
|
191
|
-
case 'cachly': return !!embedConfig.jwt;
|
|
192
|
-
case 'mistral': return !!process.env.MISTRAL_API_KEY;
|
|
193
|
-
case 'cohere': return !!process.env.COHERE_API_KEY;
|
|
194
|
-
case 'ollama': return true; // OLLAMA_BASE_URL is optional (defaults to localhost)
|
|
195
|
-
case 'gemini': return !!process.env.GEMINI_API_KEY;
|
|
196
|
-
case 'openai': return !!process.env.OPENAI_API_KEY;
|
|
197
|
-
case 'none': return false;
|
|
198
|
-
default: return false;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/** Returns a human-readable description of the current embed provider/model for error messages. */
|
|
203
|
-
export function embedProviderHint(): string {
|
|
204
|
-
const providerKeys: Record<string, string> = {
|
|
205
|
-
cachly: 'CACHLY_JWT (server-side, no extra key needed)',
|
|
206
|
-
openai: 'OPENAI_API_KEY',
|
|
207
|
-
mistral: 'MISTRAL_API_KEY',
|
|
208
|
-
cohere: 'COHERE_API_KEY',
|
|
209
|
-
ollama: 'OLLAMA_BASE_URL (optional, default: http://localhost:11434)',
|
|
210
|
-
gemini: 'GEMINI_API_KEY',
|
|
211
|
-
};
|
|
212
|
-
if (EMBED_PROVIDER === 'none') {
|
|
213
|
-
return 'No embedding provider configured. Set OPENAI_API_KEY, GEMINI_API_KEY, or another provider key in .env. Brain works without embedding.';
|
|
214
|
-
}
|
|
215
|
-
const key = providerKeys[EMBED_PROVIDER] ?? 'CACHLY_JWT';
|
|
216
|
-
return `CACHLY_EMBED_PROVIDER=${EMBED_PROVIDER} → requires ${key}`;
|
|
217
|
-
}
|