pilothub 0.0.1 → 0.0.2
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/LICENSE +1 -0
- package/README.md +36 -129
- package/dist/browserAuth.d.ts +20 -0
- package/dist/browserAuth.js +156 -0
- package/dist/browserAuth.js.map +1 -0
- package/dist/browserAuth.test.d.ts +1 -0
- package/dist/browserAuth.test.js +83 -0
- package/dist/browserAuth.test.js.map +1 -0
- package/dist/cli/buildInfo.d.ts +3 -0
- package/dist/cli/buildInfo.js +103 -0
- package/dist/cli/buildInfo.js.map +1 -0
- package/dist/cli/commands/auth.d.ts +9 -0
- package/dist/cli/commands/auth.js +75 -0
- package/dist/cli/commands/auth.js.map +1 -0
- package/dist/cli/commands/delete.d.ts +11 -0
- package/dist/cli/commands/delete.js +67 -0
- package/dist/cli/commands/delete.js.map +1 -0
- package/dist/cli/commands/delete.test.d.ts +1 -0
- package/dist/cli/commands/delete.test.js +52 -0
- package/dist/cli/commands/delete.test.js.map +1 -0
- package/dist/cli/commands/publish.d.ts +9 -0
- package/dist/cli/commands/publish.js +87 -0
- package/dist/cli/commands/publish.js.map +1 -0
- package/dist/cli/commands/publish.test.d.ts +1 -0
- package/dist/cli/commands/publish.test.js +104 -0
- package/dist/cli/commands/publish.test.js.map +1 -0
- package/dist/cli/commands/skills.d.ts +23 -0
- package/dist/cli/commands/skills.js +298 -0
- package/dist/cli/commands/skills.js.map +1 -0
- package/dist/cli/commands/skills.test.d.ts +1 -0
- package/dist/cli/commands/skills.test.js +156 -0
- package/dist/cli/commands/skills.test.js.map +1 -0
- package/dist/cli/commands/star.d.ts +8 -0
- package/dist/cli/commands/star.js +38 -0
- package/dist/cli/commands/star.js.map +1 -0
- package/dist/cli/commands/sync.d.ts +3 -0
- package/dist/cli/commands/sync.js +160 -0
- package/dist/cli/commands/sync.js.map +1 -0
- package/dist/cli/commands/sync.test.d.ts +1 -0
- package/dist/cli/commands/sync.test.js +277 -0
- package/dist/cli/commands/sync.test.js.map +1 -0
- package/dist/cli/commands/syncHelpers.d.ts +76 -0
- package/dist/cli/commands/syncHelpers.js +349 -0
- package/dist/cli/commands/syncHelpers.js.map +1 -0
- package/dist/cli/commands/syncHelpers.test.d.ts +1 -0
- package/dist/cli/commands/syncHelpers.test.js +22 -0
- package/dist/cli/commands/syncHelpers.test.js.map +1 -0
- package/dist/cli/commands/syncTypes.d.ts +24 -0
- package/dist/cli/commands/syncTypes.js +2 -0
- package/dist/cli/commands/syncTypes.js.map +1 -0
- package/dist/cli/commands/unstar.d.ts +8 -0
- package/dist/cli/commands/unstar.js +38 -0
- package/dist/cli/commands/unstar.js.map +1 -0
- package/dist/cli/helpStyle.d.ts +13 -0
- package/dist/cli/helpStyle.js +38 -0
- package/dist/cli/helpStyle.js.map +1 -0
- package/dist/cli/pilotbotConfig.d.ts +6 -0
- package/dist/cli/pilotbotConfig.js +110 -0
- package/dist/cli/pilotbotConfig.js.map +1 -0
- package/dist/cli/pilotbotConfig.test.d.ts +1 -0
- package/dist/cli/pilotbotConfig.test.js +133 -0
- package/dist/cli/pilotbotConfig.test.js.map +1 -0
- package/dist/cli/registry.d.ts +7 -0
- package/dist/cli/registry.js +42 -0
- package/dist/cli/registry.js.map +1 -0
- package/dist/cli/registry.test.d.ts +1 -0
- package/dist/cli/registry.test.js +48 -0
- package/dist/cli/registry.test.js.map +1 -0
- package/dist/cli/scanSkills.d.ts +7 -0
- package/dist/cli/scanSkills.js +75 -0
- package/dist/cli/scanSkills.js.map +1 -0
- package/dist/cli/scanSkills.test.d.ts +1 -0
- package/dist/cli/scanSkills.test.js +60 -0
- package/dist/cli/scanSkills.test.js.map +1 -0
- package/dist/cli/slug.d.ts +2 -0
- package/dist/cli/slug.js +16 -0
- package/dist/cli/slug.js.map +1 -0
- package/dist/cli/types.d.ts +15 -0
- package/dist/cli/types.js +2 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli/ui.d.ts +7 -0
- package/dist/cli/ui.js +72 -0
- package/dist/cli/ui.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +268 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +4 -0
- package/dist/config.js +38 -0
- package/dist/config.js.map +1 -0
- package/dist/discovery.d.ts +5 -0
- package/dist/discovery.js +21 -0
- package/dist/discovery.js.map +1 -0
- package/dist/discovery.test.d.ts +1 -0
- package/dist/discovery.test.js +46 -0
- package/dist/discovery.test.js.map +1 -0
- package/dist/http.d.ts +32 -0
- package/dist/http.js +261 -0
- package/dist/http.js.map +1 -0
- package/dist/http.test.d.ts +1 -0
- package/dist/http.test.js +135 -0
- package/dist/http.test.js.map +1 -0
- package/dist/schema/ark.js.map +1 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/routes.js.map +1 -0
- package/{packages/schema/dist → dist/schema}/schemas.d.ts +0 -39
- package/{packages/schema/dist → dist/schema}/schemas.js +0 -22
- package/dist/schema/schemas.js.map +1 -0
- package/dist/schema/textFiles.js.map +1 -0
- package/dist/schema/textFiles.test.d.ts +1 -0
- package/dist/schema/textFiles.test.js +20 -0
- package/dist/schema/textFiles.test.js.map +1 -0
- package/dist/skills.d.ts +43 -0
- package/dist/skills.js +163 -0
- package/dist/skills.js.map +1 -0
- package/dist/skills.test.d.ts +1 -0
- package/dist/skills.test.js +144 -0
- package/dist/skills.test.js.map +1 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +27 -70
- package/.env.local.example +0 -19
- package/.github/workflows/ci.yml +0 -40
- package/.oxlintrc.json +0 -3
- package/AGENTS.md +0 -45
- package/CHANGELOG.md +0 -138
- package/DEPRECATIONS.md +0 -7
- package/biome.json +0 -41
- package/convex/_generated/api.d.ts +0 -153
- package/convex/_generated/api.js +0 -23
- package/convex/_generated/dataModel.d.ts +0 -60
- package/convex/_generated/server.d.ts +0 -143
- package/convex/_generated/server.js +0 -93
- package/convex/auth.config.ts +0 -8
- package/convex/auth.ts +0 -19
- package/convex/comments.ts +0 -88
- package/convex/crons.ts +0 -34
- package/convex/devSeed.ts +0 -459
- package/convex/devSeedExtra.ts +0 -541
- package/convex/downloads.ts +0 -78
- package/convex/githubBackups.ts +0 -170
- package/convex/githubBackupsNode.ts +0 -183
- package/convex/githubImport.ts +0 -317
- package/convex/githubSoulBackups.ts +0 -170
- package/convex/githubSoulBackupsNode.ts +0 -186
- package/convex/http.ts +0 -194
- package/convex/httpApi.handlers.test.ts +0 -488
- package/convex/httpApi.test.ts +0 -70
- package/convex/httpApi.ts +0 -305
- package/convex/httpApiV1.handlers.test.ts +0 -584
- package/convex/httpApiV1.ts +0 -1172
- package/convex/leaderboards.ts +0 -39
- package/convex/lib/access.ts +0 -36
- package/convex/lib/apiTokenAuth.ts +0 -36
- package/convex/lib/badges.ts +0 -50
- package/convex/lib/changelog.test.ts +0 -34
- package/convex/lib/changelog.ts +0 -278
- package/convex/lib/embeddings.ts +0 -38
- package/convex/lib/githubBackup.ts +0 -443
- package/convex/lib/githubImport.test.ts +0 -247
- package/convex/lib/githubImport.ts +0 -425
- package/convex/lib/githubSoulBackup.ts +0 -443
- package/convex/lib/leaderboards.ts +0 -103
- package/convex/lib/moderation.ts +0 -42
- package/convex/lib/public.ts +0 -89
- package/convex/lib/searchText.test.ts +0 -46
- package/convex/lib/searchText.ts +0 -27
- package/convex/lib/skillBackfill.test.ts +0 -34
- package/convex/lib/skillBackfill.ts +0 -67
- package/convex/lib/skillPublish.test.ts +0 -28
- package/convex/lib/skillPublish.ts +0 -284
- package/convex/lib/skillStats.ts +0 -80
- package/convex/lib/skills.test.ts +0 -197
- package/convex/lib/skills.ts +0 -273
- package/convex/lib/soulChangelog.ts +0 -273
- package/convex/lib/soulPublish.ts +0 -236
- package/convex/lib/tokens.test.ts +0 -33
- package/convex/lib/tokens.ts +0 -51
- package/convex/lib/webhooks.test.ts +0 -91
- package/convex/lib/webhooks.ts +0 -112
- package/convex/maintenance.test.ts +0 -270
- package/convex/maintenance.ts +0 -840
- package/convex/rateLimits.ts +0 -50
- package/convex/schema.ts +0 -472
- package/convex/search.test.ts +0 -12
- package/convex/search.ts +0 -254
- package/convex/seed.test.ts +0 -37
- package/convex/seed.ts +0 -254
- package/convex/seedSouls.ts +0 -111
- package/convex/skillStatEvents.ts +0 -568
- package/convex/skills.ts +0 -1606
- package/convex/soulComments.ts +0 -88
- package/convex/soulDownloads.ts +0 -14
- package/convex/soulStars.ts +0 -71
- package/convex/souls.ts +0 -570
- package/convex/stars.ts +0 -108
- package/convex/statsMaintenance.ts +0 -205
- package/convex/telemetry.ts +0 -434
- package/convex/tokens.ts +0 -88
- package/convex/tsconfig.json +0 -7
- package/convex/uploads.ts +0 -20
- package/convex/users.ts +0 -122
- package/convex/webhooks.ts +0 -50
- package/convex.json +0 -3
- package/docs/README.md +0 -32
- package/docs/api.md +0 -51
- package/docs/architecture.md +0 -61
- package/docs/auth.md +0 -54
- package/docs/cli.md +0 -117
- package/docs/deploy.md +0 -78
- package/docs/diffing.md +0 -84
- package/docs/github-import.md +0 -171
- package/docs/http-api.md +0 -187
- package/docs/manual-testing.md +0 -64
- package/docs/mintlify.md +0 -43
- package/docs/quickstart.md +0 -120
- package/docs/skill-format.md +0 -58
- package/docs/soul-format.md +0 -37
- package/docs/spec.md +0 -177
- package/docs/telemetry.md +0 -91
- package/docs/troubleshooting.md +0 -49
- package/docs/webhook.md +0 -51
- package/e2e/menu-smoke.pw.test.ts +0 -49
- package/e2e/pilothub.e2e.test.ts +0 -494
- package/e2e/search-exact.pw.test.ts +0 -97
- package/packages/pilothub/LICENSE +0 -22
- package/packages/pilothub/README.md +0 -57
- package/packages/pilothub/package.json +0 -41
- package/packages/pilothub/src/browserAuth.test.ts +0 -96
- package/packages/pilothub/src/browserAuth.ts +0 -174
- package/packages/pilothub/src/cli/buildInfo.ts +0 -94
- package/packages/pilothub/src/cli/commands/auth.ts +0 -97
- package/packages/pilothub/src/cli/commands/delete.test.ts +0 -73
- package/packages/pilothub/src/cli/commands/delete.ts +0 -83
- package/packages/pilothub/src/cli/commands/publish.test.ts +0 -122
- package/packages/pilothub/src/cli/commands/publish.ts +0 -108
- package/packages/pilothub/src/cli/commands/skills.test.ts +0 -191
- package/packages/pilothub/src/cli/commands/skills.ts +0 -380
- package/packages/pilothub/src/cli/commands/star.ts +0 -46
- package/packages/pilothub/src/cli/commands/sync.test.ts +0 -310
- package/packages/pilothub/src/cli/commands/sync.ts +0 -200
- package/packages/pilothub/src/cli/commands/syncHelpers.test.ts +0 -26
- package/packages/pilothub/src/cli/commands/syncHelpers.ts +0 -427
- package/packages/pilothub/src/cli/commands/syncTypes.ts +0 -27
- package/packages/pilothub/src/cli/commands/unstar.ts +0 -48
- package/packages/pilothub/src/cli/helpStyle.ts +0 -45
- package/packages/pilothub/src/cli/pilotbotConfig.test.ts +0 -159
- package/packages/pilothub/src/cli/pilotbotConfig.ts +0 -147
- package/packages/pilothub/src/cli/registry.test.ts +0 -63
- package/packages/pilothub/src/cli/registry.ts +0 -43
- package/packages/pilothub/src/cli/scanSkills.test.ts +0 -64
- package/packages/pilothub/src/cli/scanSkills.ts +0 -84
- package/packages/pilothub/src/cli/slug.ts +0 -16
- package/packages/pilothub/src/cli/types.ts +0 -12
- package/packages/pilothub/src/cli/ui.ts +0 -75
- package/packages/pilothub/src/cli.ts +0 -311
- package/packages/pilothub/src/config.ts +0 -36
- package/packages/pilothub/src/discovery.test.ts +0 -75
- package/packages/pilothub/src/discovery.ts +0 -19
- package/packages/pilothub/src/http.test.ts +0 -156
- package/packages/pilothub/src/http.ts +0 -301
- package/packages/pilothub/src/schema/ark.ts +0 -29
- package/packages/pilothub/src/schema/index.ts +0 -5
- package/packages/pilothub/src/schema/routes.ts +0 -22
- package/packages/pilothub/src/schema/schemas.ts +0 -260
- package/packages/pilothub/src/schema/textFiles.test.ts +0 -23
- package/packages/pilothub/src/schema/textFiles.ts +0 -66
- package/packages/pilothub/src/skills.test.ts +0 -191
- package/packages/pilothub/src/skills.ts +0 -172
- package/packages/pilothub/src/types.ts +0 -10
- package/packages/pilothub/tsconfig.json +0 -14
- package/packages/schema/README.md +0 -3
- package/packages/schema/dist/ark.js.map +0 -1
- package/packages/schema/dist/index.js.map +0 -1
- package/packages/schema/dist/routes.js.map +0 -1
- package/packages/schema/dist/schemas.js.map +0 -1
- package/packages/schema/dist/textFiles.js.map +0 -1
- package/packages/schema/package.json +0 -26
- package/packages/schema/src/ark.ts +0 -29
- package/packages/schema/src/index.ts +0 -5
- package/packages/schema/src/routes.ts +0 -22
- package/packages/schema/src/schemas.test.ts +0 -123
- package/packages/schema/src/schemas.ts +0 -287
- package/packages/schema/src/textFiles.test.ts +0 -23
- package/packages/schema/src/textFiles.ts +0 -66
- package/packages/schema/tsconfig.json +0 -15
- package/pilothub +0 -46
- package/playwright.config.ts +0 -33
- package/public/.well-known/pilothub.json +0 -6
- package/public/api/v1/openapi.json +0 -379
- package/public/favicon.ico +0 -0
- package/public/logo192.png +0 -0
- package/public/logo512.png +0 -0
- package/public/manifest.json +0 -25
- package/public/og.png +0 -0
- package/public/og.svg +0 -98
- package/public/pilot-logo.png +0 -0
- package/public/pilot-mark.png +0 -0
- package/public/robots.txt +0 -3
- package/public/tanstack-circle-logo.png +0 -0
- package/public/tanstack-word-logo-white.svg +0 -1
- package/scripts/check-peer-deps.ts +0 -56
- package/scripts/docs-list.ts +0 -148
- package/scripts/run-playwright-local.sh +0 -14
- package/server/og/fetchSkillOgMeta.ts +0 -27
- package/server/og/fetchSoulOgMeta.ts +0 -27
- package/server/og/ogAssets.ts +0 -80
- package/server/og/skillOgSvg.test.ts +0 -59
- package/server/og/skillOgSvg.ts +0 -258
- package/server/og/soulOgSvg.ts +0 -209
- package/server/routes/og/skill.png.ts +0 -103
- package/server/routes/og/soul.png.ts +0 -111
- package/src/__tests__/skill-detail-page.test.tsx +0 -86
- package/src/__tests__/skills-index.test.tsx +0 -145
- package/src/__tests__/upload.route.test.tsx +0 -228
- package/src/components/AppProviders.tsx +0 -19
- package/src/components/ClientOnly.tsx +0 -18
- package/src/components/Footer.tsx +0 -29
- package/src/components/Header.tsx +0 -295
- package/src/components/InstallSwitcher.tsx +0 -53
- package/src/components/SkillCard.tsx +0 -36
- package/src/components/SkillDetailPage.tsx +0 -817
- package/src/components/SkillDiffCard.tsx +0 -485
- package/src/components/SoulCard.tsx +0 -19
- package/src/components/SoulDetailPage.tsx +0 -263
- package/src/components/UserBootstrap.tsx +0 -18
- package/src/components/ui/dropdown-menu.tsx +0 -67
- package/src/components/ui/toggle-group.tsx +0 -35
- package/src/convex/client.ts +0 -3
- package/src/lib/badges.ts +0 -29
- package/src/lib/diffing.test.ts +0 -163
- package/src/lib/diffing.ts +0 -106
- package/src/lib/gravatar.test.ts +0 -9
- package/src/lib/gravatar.ts +0 -158
- package/src/lib/og.test.ts +0 -142
- package/src/lib/og.ts +0 -156
- package/src/lib/publicUser.ts +0 -39
- package/src/lib/roles.ts +0 -19
- package/src/lib/site.test.ts +0 -130
- package/src/lib/site.ts +0 -84
- package/src/lib/theme-transition.test.ts +0 -134
- package/src/lib/theme-transition.ts +0 -134
- package/src/lib/theme.test.tsx +0 -88
- package/src/lib/theme.ts +0 -43
- package/src/lib/uploadFiles.jsdom.test.ts +0 -33
- package/src/lib/uploadFiles.test.ts +0 -123
- package/src/lib/uploadFiles.ts +0 -245
- package/src/lib/uploadUtils.test.ts +0 -78
- package/src/lib/uploadUtils.ts +0 -93
- package/src/lib/useAuthStatus.ts +0 -12
- package/src/lib/utils.test.ts +0 -9
- package/src/lib/utils.ts +0 -6
- package/src/logo.svg +0 -12
- package/src/routeTree.gen.ts +0 -345
- package/src/router.tsx +0 -17
- package/src/routes/$owner/$slug.tsx +0 -55
- package/src/routes/__root.tsx +0 -136
- package/src/routes/admin.tsx +0 -11
- package/src/routes/cli/auth.tsx +0 -168
- package/src/routes/dashboard.tsx +0 -97
- package/src/routes/import.tsx +0 -415
- package/src/routes/index.tsx +0 -252
- package/src/routes/management.tsx +0 -529
- package/src/routes/settings.tsx +0 -203
- package/src/routes/skills/index.tsx +0 -422
- package/src/routes/souls/$slug.tsx +0 -55
- package/src/routes/souls/index.tsx +0 -243
- package/src/routes/stars.tsx +0 -68
- package/src/routes/u/$handle.tsx +0 -307
- package/src/routes/upload/utils.ts +0 -81
- package/src/routes/upload.tsx +0 -499
- package/src/styles.css +0 -2718
- package/tsconfig.json +0 -24
- package/tsconfig.oxlint.json +0 -16
- package/vercel.json +0 -8
- package/vite.config.ts +0 -48
- package/vitest.config.ts +0 -47
- package/vitest.e2e.config.ts +0 -11
- package/vitest.setup.ts +0 -1
- /package/{packages/pilothub/bin → bin}/pilothub.js +0 -0
- /package/{packages/schema/dist → dist/schema}/ark.d.ts +0 -0
- /package/{packages/schema/dist → dist/schema}/ark.js +0 -0
- /package/{packages/schema/dist → dist/schema}/index.d.ts +0 -0
- /package/{packages/schema/dist → dist/schema}/index.js +0 -0
- /package/{packages/schema/dist → dist/schema}/routes.d.ts +0 -0
- /package/{packages/schema/dist → dist/schema}/routes.js +0 -0
- /package/{packages/schema/dist → dist/schema}/textFiles.d.ts +0 -0
- /package/{packages/schema/dist → dist/schema}/textFiles.js +0 -0
package/convex/souls.ts
DELETED
|
@@ -1,570 +0,0 @@
|
|
|
1
|
-
import { ConvexError, v } from 'convex/values'
|
|
2
|
-
import { internal } from './_generated/api'
|
|
3
|
-
import type { Doc, Id } from './_generated/dataModel'
|
|
4
|
-
import { action, internalMutation, internalQuery, mutation, query } from './_generated/server'
|
|
5
|
-
import { assertModerator, requireUser, requireUserFromAction } from './lib/access'
|
|
6
|
-
import { toPublicSoul, toPublicUser } from './lib/public'
|
|
7
|
-
import { getFrontmatterValue, hashSkillFiles } from './lib/skills'
|
|
8
|
-
import { generateSoulChangelogPreview } from './lib/soulChangelog'
|
|
9
|
-
import { fetchText, type PublishResult, publishSoulVersionForUser } from './lib/soulPublish'
|
|
10
|
-
|
|
11
|
-
export { publishSoulVersionForUser } from './lib/soulPublish'
|
|
12
|
-
|
|
13
|
-
type ReadmeResult = { path: string; text: string }
|
|
14
|
-
|
|
15
|
-
type FileTextResult = { path: string; text: string; size: number; sha256: string }
|
|
16
|
-
|
|
17
|
-
const MAX_DIFF_FILE_BYTES = 200 * 1024
|
|
18
|
-
const MAX_LIST_LIMIT = 50
|
|
19
|
-
|
|
20
|
-
export const getBySlug = query({
|
|
21
|
-
args: { slug: v.string() },
|
|
22
|
-
handler: async (ctx, args) => {
|
|
23
|
-
const matches = await ctx.db
|
|
24
|
-
.query('souls')
|
|
25
|
-
.withIndex('by_slug', (q) => q.eq('slug', args.slug))
|
|
26
|
-
.order('desc')
|
|
27
|
-
.take(2)
|
|
28
|
-
const soul = matches[0] ?? null
|
|
29
|
-
if (!soul || soul.softDeletedAt) return null
|
|
30
|
-
const latestVersion = soul.latestVersionId ? await ctx.db.get(soul.latestVersionId) : null
|
|
31
|
-
const owner = toPublicUser(await ctx.db.get(soul.ownerUserId))
|
|
32
|
-
const publicSoul = toPublicSoul(soul)
|
|
33
|
-
if (!publicSoul) return null
|
|
34
|
-
|
|
35
|
-
return { soul: publicSoul, latestVersion, owner }
|
|
36
|
-
},
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
export const getSoulBySlugInternal = internalQuery({
|
|
40
|
-
args: { slug: v.string() },
|
|
41
|
-
handler: async (ctx, args) => {
|
|
42
|
-
const matches = await ctx.db
|
|
43
|
-
.query('souls')
|
|
44
|
-
.withIndex('by_slug', (q) => q.eq('slug', args.slug))
|
|
45
|
-
.order('desc')
|
|
46
|
-
.take(2)
|
|
47
|
-
return matches[0] ?? null
|
|
48
|
-
},
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
export const list = query({
|
|
52
|
-
args: {
|
|
53
|
-
ownerUserId: v.optional(v.id('users')),
|
|
54
|
-
limit: v.optional(v.number()),
|
|
55
|
-
},
|
|
56
|
-
handler: async (ctx, args) => {
|
|
57
|
-
const limit = args.limit ?? 24
|
|
58
|
-
const ownerUserId = args.ownerUserId
|
|
59
|
-
if (ownerUserId) {
|
|
60
|
-
const entries = await ctx.db
|
|
61
|
-
.query('souls')
|
|
62
|
-
.withIndex('by_owner', (q) => q.eq('ownerUserId', ownerUserId))
|
|
63
|
-
.order('desc')
|
|
64
|
-
.take(limit * 5)
|
|
65
|
-
return entries
|
|
66
|
-
.filter((soul) => !soul.softDeletedAt)
|
|
67
|
-
.slice(0, limit)
|
|
68
|
-
.map((soul) => toPublicSoul(soul))
|
|
69
|
-
.filter((soul): soul is NonNullable<typeof soul> => Boolean(soul))
|
|
70
|
-
}
|
|
71
|
-
const entries = await ctx.db
|
|
72
|
-
.query('souls')
|
|
73
|
-
.order('desc')
|
|
74
|
-
.take(limit * 5)
|
|
75
|
-
return entries
|
|
76
|
-
.filter((soul) => !soul.softDeletedAt)
|
|
77
|
-
.slice(0, limit)
|
|
78
|
-
.map((soul) => toPublicSoul(soul))
|
|
79
|
-
.filter((soul): soul is NonNullable<typeof soul> => Boolean(soul))
|
|
80
|
-
},
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
export const listPublicPage = query({
|
|
84
|
-
args: {
|
|
85
|
-
cursor: v.optional(v.string()),
|
|
86
|
-
limit: v.optional(v.number()),
|
|
87
|
-
},
|
|
88
|
-
handler: async (ctx, args) => {
|
|
89
|
-
const limit = clampInt(args.limit ?? 24, 1, MAX_LIST_LIMIT)
|
|
90
|
-
const { page, isDone, continueCursor } = await ctx.db
|
|
91
|
-
.query('souls')
|
|
92
|
-
.withIndex('by_updated', (q) => q)
|
|
93
|
-
.order('desc')
|
|
94
|
-
.paginate({ cursor: args.cursor ?? null, numItems: limit })
|
|
95
|
-
|
|
96
|
-
const items: Array<{
|
|
97
|
-
soul: NonNullable<ReturnType<typeof toPublicSoul>>
|
|
98
|
-
latestVersion: Doc<'soulVersions'> | null
|
|
99
|
-
}> = []
|
|
100
|
-
|
|
101
|
-
for (const soul of page) {
|
|
102
|
-
if (soul.softDeletedAt) continue
|
|
103
|
-
const latestVersion = soul.latestVersionId ? await ctx.db.get(soul.latestVersionId) : null
|
|
104
|
-
const publicSoul = toPublicSoul(soul)
|
|
105
|
-
if (!publicSoul) continue
|
|
106
|
-
items.push({ soul: publicSoul, latestVersion })
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return { items, nextCursor: isDone ? null : continueCursor }
|
|
110
|
-
},
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
export const listVersions = query({
|
|
114
|
-
args: { soulId: v.id('souls'), limit: v.optional(v.number()) },
|
|
115
|
-
handler: async (ctx, args) => {
|
|
116
|
-
const limit = args.limit ?? 20
|
|
117
|
-
return ctx.db
|
|
118
|
-
.query('soulVersions')
|
|
119
|
-
.withIndex('by_soul', (q) => q.eq('soulId', args.soulId))
|
|
120
|
-
.order('desc')
|
|
121
|
-
.take(limit)
|
|
122
|
-
},
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
export const listVersionsPage = query({
|
|
126
|
-
args: {
|
|
127
|
-
soulId: v.id('souls'),
|
|
128
|
-
cursor: v.optional(v.string()),
|
|
129
|
-
limit: v.optional(v.number()),
|
|
130
|
-
},
|
|
131
|
-
handler: async (ctx, args) => {
|
|
132
|
-
const limit = clampInt(args.limit ?? 20, 1, MAX_LIST_LIMIT)
|
|
133
|
-
const { page, isDone, continueCursor } = await ctx.db
|
|
134
|
-
.query('soulVersions')
|
|
135
|
-
.withIndex('by_soul', (q) => q.eq('soulId', args.soulId))
|
|
136
|
-
.order('desc')
|
|
137
|
-
.paginate({ cursor: args.cursor ?? null, numItems: limit })
|
|
138
|
-
const items = page.filter((version) => !version.softDeletedAt)
|
|
139
|
-
return { items, nextCursor: isDone ? null : continueCursor }
|
|
140
|
-
},
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
export const getVersionById = query({
|
|
144
|
-
args: { versionId: v.id('soulVersions') },
|
|
145
|
-
handler: async (ctx, args) => ctx.db.get(args.versionId),
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
export const getVersionByIdInternal = internalQuery({
|
|
149
|
-
args: { versionId: v.id('soulVersions') },
|
|
150
|
-
handler: async (ctx, args) => ctx.db.get(args.versionId),
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
export const getVersionBySoulAndVersion = query({
|
|
154
|
-
args: { soulId: v.id('souls'), version: v.string() },
|
|
155
|
-
handler: async (ctx, args) => {
|
|
156
|
-
return ctx.db
|
|
157
|
-
.query('soulVersions')
|
|
158
|
-
.withIndex('by_soul_version', (q) => q.eq('soulId', args.soulId).eq('version', args.version))
|
|
159
|
-
.unique()
|
|
160
|
-
},
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
export const publishVersion: ReturnType<typeof action> = action({
|
|
164
|
-
args: {
|
|
165
|
-
slug: v.string(),
|
|
166
|
-
displayName: v.string(),
|
|
167
|
-
version: v.string(),
|
|
168
|
-
changelog: v.string(),
|
|
169
|
-
tags: v.optional(v.array(v.string())),
|
|
170
|
-
source: v.optional(
|
|
171
|
-
v.object({
|
|
172
|
-
kind: v.literal('github'),
|
|
173
|
-
url: v.string(),
|
|
174
|
-
repo: v.string(),
|
|
175
|
-
ref: v.string(),
|
|
176
|
-
commit: v.string(),
|
|
177
|
-
path: v.string(),
|
|
178
|
-
importedAt: v.number(),
|
|
179
|
-
}),
|
|
180
|
-
),
|
|
181
|
-
files: v.array(
|
|
182
|
-
v.object({
|
|
183
|
-
path: v.string(),
|
|
184
|
-
size: v.number(),
|
|
185
|
-
storageId: v.id('_storage'),
|
|
186
|
-
sha256: v.string(),
|
|
187
|
-
contentType: v.optional(v.string()),
|
|
188
|
-
}),
|
|
189
|
-
),
|
|
190
|
-
},
|
|
191
|
-
handler: async (ctx, args): Promise<PublishResult> => {
|
|
192
|
-
const { userId } = await requireUserFromAction(ctx)
|
|
193
|
-
return publishSoulVersionForUser(ctx, userId, args)
|
|
194
|
-
},
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
export const generateChangelogPreview = action({
|
|
198
|
-
args: {
|
|
199
|
-
slug: v.string(),
|
|
200
|
-
version: v.string(),
|
|
201
|
-
readmeText: v.string(),
|
|
202
|
-
filePaths: v.optional(v.array(v.string())),
|
|
203
|
-
},
|
|
204
|
-
handler: async (ctx, args) => {
|
|
205
|
-
await requireUserFromAction(ctx)
|
|
206
|
-
const changelog = await generateSoulChangelogPreview(ctx, {
|
|
207
|
-
slug: args.slug.trim().toLowerCase(),
|
|
208
|
-
version: args.version.trim(),
|
|
209
|
-
readmeText: args.readmeText,
|
|
210
|
-
filePaths: args.filePaths?.map((value) => value.trim()).filter(Boolean),
|
|
211
|
-
})
|
|
212
|
-
return { changelog, source: 'auto' as const }
|
|
213
|
-
},
|
|
214
|
-
})
|
|
215
|
-
|
|
216
|
-
export const getReadme: ReturnType<typeof action> = action({
|
|
217
|
-
args: { versionId: v.id('soulVersions') },
|
|
218
|
-
handler: async (ctx, args): Promise<ReadmeResult> => {
|
|
219
|
-
const version = (await ctx.runQuery(internal.souls.getVersionByIdInternal, {
|
|
220
|
-
versionId: args.versionId,
|
|
221
|
-
})) as Doc<'soulVersions'> | null
|
|
222
|
-
if (!version) throw new ConvexError('Version not found')
|
|
223
|
-
const readmeFile = version.files.find((file) => file.path.toLowerCase() === 'soul.md')
|
|
224
|
-
if (!readmeFile) throw new ConvexError('SOUL.md not found')
|
|
225
|
-
const text = await fetchText(ctx, readmeFile.storageId)
|
|
226
|
-
return { path: readmeFile.path, text }
|
|
227
|
-
},
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
export const getFileText: ReturnType<typeof action> = action({
|
|
231
|
-
args: { versionId: v.id('soulVersions'), path: v.string() },
|
|
232
|
-
handler: async (ctx, args): Promise<FileTextResult> => {
|
|
233
|
-
const version = (await ctx.runQuery(internal.souls.getVersionByIdInternal, {
|
|
234
|
-
versionId: args.versionId,
|
|
235
|
-
})) as Doc<'soulVersions'> | null
|
|
236
|
-
if (!version) throw new ConvexError('Version not found')
|
|
237
|
-
|
|
238
|
-
const normalizedPath = args.path.trim()
|
|
239
|
-
const normalizedLower = normalizedPath.toLowerCase()
|
|
240
|
-
const file =
|
|
241
|
-
version.files.find((entry) => entry.path === normalizedPath) ??
|
|
242
|
-
version.files.find((entry) => entry.path.toLowerCase() === normalizedLower)
|
|
243
|
-
if (!file) throw new ConvexError('File not found')
|
|
244
|
-
if (file.size > MAX_DIFF_FILE_BYTES) {
|
|
245
|
-
throw new ConvexError('File exceeds 200KB limit')
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const text = await fetchText(ctx, file.storageId)
|
|
249
|
-
return { path: file.path, text, size: file.size, sha256: file.sha256 }
|
|
250
|
-
},
|
|
251
|
-
})
|
|
252
|
-
|
|
253
|
-
export const resolveVersionByHash = query({
|
|
254
|
-
args: { slug: v.string(), hash: v.string() },
|
|
255
|
-
handler: async (ctx, args) => {
|
|
256
|
-
const slug = args.slug.trim().toLowerCase()
|
|
257
|
-
const hash = args.hash.trim().toLowerCase()
|
|
258
|
-
if (!slug || !/^[a-f0-9]{64}$/.test(hash)) return null
|
|
259
|
-
|
|
260
|
-
const soulMatches = await ctx.db
|
|
261
|
-
.query('souls')
|
|
262
|
-
.withIndex('by_slug', (q) => q.eq('slug', slug))
|
|
263
|
-
.order('desc')
|
|
264
|
-
.take(2)
|
|
265
|
-
const soul = soulMatches[0] ?? null
|
|
266
|
-
if (!soul || soul.softDeletedAt) return null
|
|
267
|
-
|
|
268
|
-
const latestVersion = soul.latestVersionId ? await ctx.db.get(soul.latestVersionId) : null
|
|
269
|
-
|
|
270
|
-
const fingerprintMatches = await ctx.db
|
|
271
|
-
.query('soulVersionFingerprints')
|
|
272
|
-
.withIndex('by_soul_fingerprint', (q) => q.eq('soulId', soul._id).eq('fingerprint', hash))
|
|
273
|
-
.take(25)
|
|
274
|
-
|
|
275
|
-
let match: { version: string } | null = null
|
|
276
|
-
if (fingerprintMatches.length > 0) {
|
|
277
|
-
const newest = fingerprintMatches.reduce(
|
|
278
|
-
(best, entry) => (entry.createdAt > best.createdAt ? entry : best),
|
|
279
|
-
fingerprintMatches[0] as (typeof fingerprintMatches)[number],
|
|
280
|
-
)
|
|
281
|
-
const version = await ctx.db.get(newest.versionId)
|
|
282
|
-
if (version && !version.softDeletedAt) {
|
|
283
|
-
match = { version: version.version }
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
if (!match) {
|
|
288
|
-
const versions = await ctx.db
|
|
289
|
-
.query('soulVersions')
|
|
290
|
-
.withIndex('by_soul', (q) => q.eq('soulId', soul._id))
|
|
291
|
-
.order('desc')
|
|
292
|
-
.take(200)
|
|
293
|
-
|
|
294
|
-
for (const version of versions) {
|
|
295
|
-
if (version.softDeletedAt) continue
|
|
296
|
-
if (typeof version.fingerprint === 'string' && version.fingerprint === hash) {
|
|
297
|
-
match = { version: version.version }
|
|
298
|
-
break
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
const fingerprint = await hashSkillFiles(
|
|
302
|
-
version.files.map((file) => ({ path: file.path, sha256: file.sha256 })),
|
|
303
|
-
)
|
|
304
|
-
if (fingerprint === hash) {
|
|
305
|
-
match = { version: version.version }
|
|
306
|
-
break
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
return {
|
|
312
|
-
match,
|
|
313
|
-
latestVersion: latestVersion ? { version: latestVersion.version } : null,
|
|
314
|
-
}
|
|
315
|
-
},
|
|
316
|
-
})
|
|
317
|
-
|
|
318
|
-
export const updateTags = mutation({
|
|
319
|
-
args: {
|
|
320
|
-
soulId: v.id('souls'),
|
|
321
|
-
tags: v.array(v.object({ tag: v.string(), versionId: v.id('soulVersions') })),
|
|
322
|
-
},
|
|
323
|
-
handler: async (ctx, args) => {
|
|
324
|
-
const { user } = await requireUser(ctx)
|
|
325
|
-
const soul = await ctx.db.get(args.soulId)
|
|
326
|
-
if (!soul) throw new Error('Soul not found')
|
|
327
|
-
if (soul.ownerUserId !== user._id) {
|
|
328
|
-
assertModerator(user)
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
const nextTags = { ...soul.tags }
|
|
332
|
-
for (const entry of args.tags) {
|
|
333
|
-
nextTags[entry.tag] = entry.versionId
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
const latestEntry = args.tags.find((entry) => entry.tag === 'latest')
|
|
337
|
-
await ctx.db.patch(soul._id, {
|
|
338
|
-
tags: nextTags,
|
|
339
|
-
latestVersionId: latestEntry ? latestEntry.versionId : soul.latestVersionId,
|
|
340
|
-
updatedAt: Date.now(),
|
|
341
|
-
})
|
|
342
|
-
|
|
343
|
-
if (latestEntry) {
|
|
344
|
-
const embeddings = await ctx.db
|
|
345
|
-
.query('soulEmbeddings')
|
|
346
|
-
.withIndex('by_soul', (q) => q.eq('soulId', soul._id))
|
|
347
|
-
.collect()
|
|
348
|
-
for (const embedding of embeddings) {
|
|
349
|
-
const isLatest = embedding.versionId === latestEntry.versionId
|
|
350
|
-
await ctx.db.patch(embedding._id, {
|
|
351
|
-
isLatest,
|
|
352
|
-
visibility: visibilityFor(isLatest, embedding.isApproved),
|
|
353
|
-
updatedAt: Date.now(),
|
|
354
|
-
})
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
},
|
|
358
|
-
})
|
|
359
|
-
|
|
360
|
-
export const insertVersion = internalMutation({
|
|
361
|
-
args: {
|
|
362
|
-
userId: v.id('users'),
|
|
363
|
-
slug: v.string(),
|
|
364
|
-
displayName: v.string(),
|
|
365
|
-
version: v.string(),
|
|
366
|
-
changelog: v.string(),
|
|
367
|
-
changelogSource: v.optional(v.union(v.literal('auto'), v.literal('user'))),
|
|
368
|
-
tags: v.optional(v.array(v.string())),
|
|
369
|
-
fingerprint: v.string(),
|
|
370
|
-
summary: v.optional(v.string()),
|
|
371
|
-
files: v.array(
|
|
372
|
-
v.object({
|
|
373
|
-
path: v.string(),
|
|
374
|
-
size: v.number(),
|
|
375
|
-
storageId: v.id('_storage'),
|
|
376
|
-
sha256: v.string(),
|
|
377
|
-
contentType: v.optional(v.string()),
|
|
378
|
-
}),
|
|
379
|
-
),
|
|
380
|
-
parsed: v.object({
|
|
381
|
-
frontmatter: v.record(v.string(), v.any()),
|
|
382
|
-
metadata: v.optional(v.any()),
|
|
383
|
-
}),
|
|
384
|
-
embedding: v.array(v.number()),
|
|
385
|
-
},
|
|
386
|
-
handler: async (ctx, args) => {
|
|
387
|
-
const userId = args.userId
|
|
388
|
-
const user = await ctx.db.get(userId)
|
|
389
|
-
if (!user || user.deletedAt) throw new Error('User not found')
|
|
390
|
-
|
|
391
|
-
const soulMatches = await ctx.db
|
|
392
|
-
.query('souls')
|
|
393
|
-
.withIndex('by_slug', (q) => q.eq('slug', args.slug))
|
|
394
|
-
.order('desc')
|
|
395
|
-
.take(2)
|
|
396
|
-
let soul: Doc<'souls'> | null = soulMatches[0] ?? null
|
|
397
|
-
|
|
398
|
-
if (soul && soul.ownerUserId !== userId) {
|
|
399
|
-
throw new Error('Only the owner can publish updates')
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
const now = Date.now()
|
|
403
|
-
if (!soul) {
|
|
404
|
-
const summary = args.summary ?? getFrontmatterValue(args.parsed.frontmatter, 'description')
|
|
405
|
-
const soulId = await ctx.db.insert('souls', {
|
|
406
|
-
slug: args.slug,
|
|
407
|
-
displayName: args.displayName,
|
|
408
|
-
summary: summary ?? undefined,
|
|
409
|
-
ownerUserId: userId,
|
|
410
|
-
latestVersionId: undefined,
|
|
411
|
-
tags: {},
|
|
412
|
-
softDeletedAt: undefined,
|
|
413
|
-
stats: {
|
|
414
|
-
downloads: 0,
|
|
415
|
-
stars: 0,
|
|
416
|
-
versions: 0,
|
|
417
|
-
comments: 0,
|
|
418
|
-
},
|
|
419
|
-
createdAt: now,
|
|
420
|
-
updatedAt: now,
|
|
421
|
-
})
|
|
422
|
-
soul = await ctx.db.get(soulId)
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
if (!soul) throw new Error('Soul creation failed')
|
|
426
|
-
|
|
427
|
-
const existingVersion = await ctx.db
|
|
428
|
-
.query('soulVersions')
|
|
429
|
-
.withIndex('by_soul_version', (q) => q.eq('soulId', soul._id).eq('version', args.version))
|
|
430
|
-
.unique()
|
|
431
|
-
if (existingVersion) {
|
|
432
|
-
throw new Error('Version already exists')
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
const versionId = await ctx.db.insert('soulVersions', {
|
|
436
|
-
soulId: soul._id,
|
|
437
|
-
version: args.version,
|
|
438
|
-
fingerprint: args.fingerprint,
|
|
439
|
-
changelog: args.changelog,
|
|
440
|
-
changelogSource: args.changelogSource,
|
|
441
|
-
files: args.files,
|
|
442
|
-
parsed: args.parsed,
|
|
443
|
-
createdBy: userId,
|
|
444
|
-
createdAt: now,
|
|
445
|
-
softDeletedAt: undefined,
|
|
446
|
-
})
|
|
447
|
-
|
|
448
|
-
const nextTags: Record<string, Id<'soulVersions'>> = { ...soul.tags }
|
|
449
|
-
nextTags.latest = versionId
|
|
450
|
-
for (const tag of args.tags ?? []) {
|
|
451
|
-
nextTags[tag] = versionId
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
const latestBefore = soul.latestVersionId
|
|
455
|
-
|
|
456
|
-
await ctx.db.patch(soul._id, {
|
|
457
|
-
displayName: args.displayName,
|
|
458
|
-
summary:
|
|
459
|
-
args.summary ?? getFrontmatterValue(args.parsed.frontmatter, 'description') ?? soul.summary,
|
|
460
|
-
latestVersionId: versionId,
|
|
461
|
-
tags: nextTags,
|
|
462
|
-
stats: { ...soul.stats, versions: soul.stats.versions + 1 },
|
|
463
|
-
softDeletedAt: undefined,
|
|
464
|
-
updatedAt: now,
|
|
465
|
-
})
|
|
466
|
-
|
|
467
|
-
const embeddingId = await ctx.db.insert('soulEmbeddings', {
|
|
468
|
-
soulId: soul._id,
|
|
469
|
-
versionId,
|
|
470
|
-
ownerId: userId,
|
|
471
|
-
embedding: args.embedding,
|
|
472
|
-
isLatest: true,
|
|
473
|
-
isApproved: true,
|
|
474
|
-
visibility: visibilityFor(true, true),
|
|
475
|
-
updatedAt: now,
|
|
476
|
-
})
|
|
477
|
-
|
|
478
|
-
if (latestBefore) {
|
|
479
|
-
const previousEmbedding = await ctx.db
|
|
480
|
-
.query('soulEmbeddings')
|
|
481
|
-
.withIndex('by_version', (q) => q.eq('versionId', latestBefore))
|
|
482
|
-
.unique()
|
|
483
|
-
if (previousEmbedding) {
|
|
484
|
-
await ctx.db.patch(previousEmbedding._id, {
|
|
485
|
-
isLatest: false,
|
|
486
|
-
visibility: visibilityFor(false, previousEmbedding.isApproved),
|
|
487
|
-
updatedAt: now,
|
|
488
|
-
})
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
await ctx.db.insert('soulVersionFingerprints', {
|
|
493
|
-
soulId: soul._id,
|
|
494
|
-
versionId,
|
|
495
|
-
fingerprint: args.fingerprint,
|
|
496
|
-
createdAt: now,
|
|
497
|
-
})
|
|
498
|
-
|
|
499
|
-
return { soulId: soul._id, versionId, embeddingId }
|
|
500
|
-
},
|
|
501
|
-
})
|
|
502
|
-
|
|
503
|
-
export const setSoulSoftDeletedInternal = internalMutation({
|
|
504
|
-
args: {
|
|
505
|
-
userId: v.id('users'),
|
|
506
|
-
slug: v.string(),
|
|
507
|
-
deleted: v.boolean(),
|
|
508
|
-
},
|
|
509
|
-
handler: async (ctx, args) => {
|
|
510
|
-
const user = await ctx.db.get(args.userId)
|
|
511
|
-
if (!user || user.deletedAt) throw new Error('User not found')
|
|
512
|
-
|
|
513
|
-
const slug = args.slug.trim().toLowerCase()
|
|
514
|
-
if (!slug) throw new Error('Slug required')
|
|
515
|
-
|
|
516
|
-
const soulMatches = await ctx.db
|
|
517
|
-
.query('souls')
|
|
518
|
-
.withIndex('by_slug', (q) => q.eq('slug', slug))
|
|
519
|
-
.order('desc')
|
|
520
|
-
.take(2)
|
|
521
|
-
const soul = soulMatches[0] ?? null
|
|
522
|
-
if (!soul) throw new Error('Soul not found')
|
|
523
|
-
|
|
524
|
-
if (soul.ownerUserId !== args.userId) {
|
|
525
|
-
assertModerator(user)
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
const now = Date.now()
|
|
529
|
-
await ctx.db.patch(soul._id, {
|
|
530
|
-
softDeletedAt: args.deleted ? now : undefined,
|
|
531
|
-
updatedAt: now,
|
|
532
|
-
})
|
|
533
|
-
|
|
534
|
-
const embeddings = await ctx.db
|
|
535
|
-
.query('soulEmbeddings')
|
|
536
|
-
.withIndex('by_soul', (q) => q.eq('soulId', soul._id))
|
|
537
|
-
.collect()
|
|
538
|
-
for (const embedding of embeddings) {
|
|
539
|
-
await ctx.db.patch(embedding._id, {
|
|
540
|
-
visibility: args.deleted
|
|
541
|
-
? 'deleted'
|
|
542
|
-
: visibilityFor(embedding.isLatest, embedding.isApproved),
|
|
543
|
-
updatedAt: now,
|
|
544
|
-
})
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
await ctx.db.insert('auditLogs', {
|
|
548
|
-
actorUserId: args.userId,
|
|
549
|
-
action: args.deleted ? 'soul.delete' : 'soul.undelete',
|
|
550
|
-
targetType: 'soul',
|
|
551
|
-
targetId: soul._id,
|
|
552
|
-
metadata: { slug, softDeletedAt: args.deleted ? now : null },
|
|
553
|
-
createdAt: now,
|
|
554
|
-
})
|
|
555
|
-
|
|
556
|
-
return { ok: true as const }
|
|
557
|
-
},
|
|
558
|
-
})
|
|
559
|
-
|
|
560
|
-
function visibilityFor(isLatest: boolean, isApproved: boolean) {
|
|
561
|
-
if (isLatest && isApproved) return 'latest-approved'
|
|
562
|
-
if (isLatest) return 'latest'
|
|
563
|
-
if (isApproved) return 'archived-approved'
|
|
564
|
-
return 'archived'
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
function clampInt(value: number, min: number, max: number) {
|
|
568
|
-
const rounded = Number.isFinite(value) ? Math.round(value) : min
|
|
569
|
-
return Math.min(max, Math.max(min, rounded))
|
|
570
|
-
}
|
package/convex/stars.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { v } from 'convex/values'
|
|
2
|
-
import { internalMutation, mutation, query } from './_generated/server'
|
|
3
|
-
import { requireUser } from './lib/access'
|
|
4
|
-
import { toPublicSkill } from './lib/public'
|
|
5
|
-
import { insertStatEvent } from './skillStatEvents'
|
|
6
|
-
|
|
7
|
-
export const isStarred = query({
|
|
8
|
-
args: { skillId: v.id('skills') },
|
|
9
|
-
handler: async (ctx, args) => {
|
|
10
|
-
const { userId } = await requireUser(ctx)
|
|
11
|
-
const existing = await ctx.db
|
|
12
|
-
.query('stars')
|
|
13
|
-
.withIndex('by_skill_user', (q) => q.eq('skillId', args.skillId).eq('userId', userId))
|
|
14
|
-
.unique()
|
|
15
|
-
return Boolean(existing)
|
|
16
|
-
},
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
export const toggle = mutation({
|
|
20
|
-
args: { skillId: v.id('skills') },
|
|
21
|
-
handler: async (ctx, args) => {
|
|
22
|
-
const { userId } = await requireUser(ctx)
|
|
23
|
-
const skill = await ctx.db.get(args.skillId)
|
|
24
|
-
if (!skill) throw new Error('Skill not found')
|
|
25
|
-
|
|
26
|
-
const existing = await ctx.db
|
|
27
|
-
.query('stars')
|
|
28
|
-
.withIndex('by_skill_user', (q) => q.eq('skillId', args.skillId).eq('userId', userId))
|
|
29
|
-
.unique()
|
|
30
|
-
|
|
31
|
-
if (existing) {
|
|
32
|
-
await ctx.db.delete(existing._id)
|
|
33
|
-
await insertStatEvent(ctx, { skillId: skill._id, kind: 'unstar' })
|
|
34
|
-
return { starred: false }
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
await ctx.db.insert('stars', {
|
|
38
|
-
skillId: args.skillId,
|
|
39
|
-
userId,
|
|
40
|
-
createdAt: Date.now(),
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
await insertStatEvent(ctx, { skillId: skill._id, kind: 'star' })
|
|
44
|
-
|
|
45
|
-
return { starred: true }
|
|
46
|
-
},
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
export const listByUser = query({
|
|
50
|
-
args: { userId: v.id('users'), limit: v.optional(v.number()) },
|
|
51
|
-
handler: async (ctx, args) => {
|
|
52
|
-
const limit = args.limit ?? 50
|
|
53
|
-
const stars = await ctx.db
|
|
54
|
-
.query('stars')
|
|
55
|
-
.withIndex('by_user', (q) => q.eq('userId', args.userId))
|
|
56
|
-
.order('desc')
|
|
57
|
-
.take(limit)
|
|
58
|
-
const skills: NonNullable<ReturnType<typeof toPublicSkill>>[] = []
|
|
59
|
-
for (const star of stars) {
|
|
60
|
-
const skill = await ctx.db.get(star.skillId)
|
|
61
|
-
const publicSkill = toPublicSkill(skill)
|
|
62
|
-
if (!publicSkill) continue
|
|
63
|
-
skills.push(publicSkill)
|
|
64
|
-
}
|
|
65
|
-
return skills
|
|
66
|
-
},
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
export const addStarInternal = internalMutation({
|
|
70
|
-
args: { userId: v.id('users'), skillId: v.id('skills') },
|
|
71
|
-
handler: async (ctx, args) => {
|
|
72
|
-
const skill = await ctx.db.get(args.skillId)
|
|
73
|
-
if (!skill) throw new Error('Skill not found')
|
|
74
|
-
const existing = await ctx.db
|
|
75
|
-
.query('stars')
|
|
76
|
-
.withIndex('by_skill_user', (q) => q.eq('skillId', args.skillId).eq('userId', args.userId))
|
|
77
|
-
.unique()
|
|
78
|
-
if (existing) return { ok: true as const, starred: true, alreadyStarred: true }
|
|
79
|
-
|
|
80
|
-
await ctx.db.insert('stars', {
|
|
81
|
-
skillId: args.skillId,
|
|
82
|
-
userId: args.userId,
|
|
83
|
-
createdAt: Date.now(),
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
await insertStatEvent(ctx, { skillId: skill._id, kind: 'star' })
|
|
87
|
-
|
|
88
|
-
return { ok: true as const, starred: true, alreadyStarred: false }
|
|
89
|
-
},
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
export const removeStarInternal = internalMutation({
|
|
93
|
-
args: { userId: v.id('users'), skillId: v.id('skills') },
|
|
94
|
-
handler: async (ctx, args) => {
|
|
95
|
-
const skill = await ctx.db.get(args.skillId)
|
|
96
|
-
if (!skill) throw new Error('Skill not found')
|
|
97
|
-
const existing = await ctx.db
|
|
98
|
-
.query('stars')
|
|
99
|
-
.withIndex('by_skill_user', (q) => q.eq('skillId', args.skillId).eq('userId', args.userId))
|
|
100
|
-
.unique()
|
|
101
|
-
if (!existing) return { ok: true as const, unstarred: false, alreadyUnstarred: true }
|
|
102
|
-
|
|
103
|
-
await ctx.db.delete(existing._id)
|
|
104
|
-
await insertStatEvent(ctx, { skillId: skill._id, kind: 'unstar' })
|
|
105
|
-
|
|
106
|
-
return { ok: true as const, unstarred: true, alreadyUnstarred: false }
|
|
107
|
-
},
|
|
108
|
-
})
|