ima2-gen 1.1.20 → 1.1.22

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.
Files changed (239) hide show
  1. package/README.md +42 -26
  2. package/bin/commands/capabilities.js +2 -2
  3. package/bin/commands/defaults.js +2 -2
  4. package/bin/commands/doctor.js +3 -3
  5. package/bin/commands/edit.js +1 -1
  6. package/bin/commands/gen.js +1 -1
  7. package/bin/commands/grok.js +16 -11
  8. package/bin/commands/multimode.js +1 -1
  9. package/bin/commands/observability.js +2 -2
  10. package/bin/commands/video.js +335 -13
  11. package/bin/ima2.js +23 -13
  12. package/bin/lib/error-hints.js +2 -2
  13. package/bin/lib/platform.js +34 -5
  14. package/docs/API.md +112 -3
  15. package/docs/CLI.md +61 -7
  16. package/docs/FAQ.ko.md +15 -20
  17. package/docs/FAQ.md +14 -19
  18. package/docs/NPX_QUICKSTART.md +40 -0
  19. package/docs/PROMPT_STUDIO.ko.md +1 -1
  20. package/docs/PROMPT_STUDIO.md +1 -1
  21. package/docs/README.ja.md +6 -16
  22. package/docs/README.ko.md +35 -14
  23. package/docs/README.zh-CN.md +7 -17
  24. package/docs/migration/runtime-test-inventory.md +8 -1
  25. package/lib/agentQueueWorker.js +6 -0
  26. package/lib/agentRuntime.js +20 -5
  27. package/lib/atomicWrite.js +14 -0
  28. package/lib/capabilities.js +1 -1
  29. package/lib/generationErrors.js +1 -1
  30. package/lib/grokProxyLauncher.js +31 -6
  31. package/lib/grokVideoAdapter.js +18 -89
  32. package/lib/grokVideoCanvas.js +25 -0
  33. package/lib/grokVideoDownload.js +58 -0
  34. package/lib/grokVideoPlannerPrompt.js +64 -0
  35. package/lib/historyList.js +7 -1
  36. package/lib/inflight.js +1 -1
  37. package/lib/oauthLauncher.js +26 -6
  38. package/lib/videoContinuity.js +149 -0
  39. package/lib/videoFrameExtract.js +80 -0
  40. package/node_modules/progrok/dist/index.js +187 -88
  41. package/node_modules/progrok/dist/index.js.map +1 -1
  42. package/node_modules/progrok/package.json +1 -1
  43. package/node_modules/progrok/skills/progrok/SKILL.md +33 -4
  44. package/package.json +6 -8
  45. package/routes/edit.js +2 -1
  46. package/routes/generate.js +4 -3
  47. package/routes/health.js +4 -3
  48. package/routes/index.js +4 -0
  49. package/routes/multimode.js +2 -1
  50. package/routes/quota.js +66 -0
  51. package/routes/video.js +80 -16
  52. package/routes/videoExtended.js +293 -0
  53. package/server.js +35 -4
  54. package/skills/ima2/SKILL.md +320 -7
  55. package/ui/dist/.vite/manifest.json +12 -12
  56. package/ui/dist/assets/{AgentWorkspace-DS8uvoLI.js → AgentWorkspace-COxQ5TjU.js} +2 -2
  57. package/ui/dist/assets/{CardNewsWorkspace-CYxMsE67.js → CardNewsWorkspace-B0OkcuVz.js} +1 -1
  58. package/ui/dist/assets/{NodeCanvas-DccIc347.js → NodeCanvas-BSsclEBh.js} +1 -1
  59. package/ui/dist/assets/{PromptBuilderPanel-BvxxwSJp.js → PromptBuilderPanel-DpC9A5Rz.js} +1 -1
  60. package/ui/dist/assets/{PromptImportDialog-u1_BFDRd.js → PromptImportDialog-CVwT0rLd.js} +2 -2
  61. package/ui/dist/assets/{PromptImportDiscoverySection-C5uvkVSz.js → PromptImportDiscoverySection-BDCkRCRs.js} +1 -1
  62. package/ui/dist/assets/{PromptImportFolderSection-D3E_O1SD.js → PromptImportFolderSection-QoKbZD83.js} +1 -1
  63. package/ui/dist/assets/{PromptLibraryPanel-4gyf9CB9.js → PromptLibraryPanel-BhFgeKnY.js} +2 -2
  64. package/ui/dist/assets/SettingsWorkspace-CfjrlH5R.js +1 -0
  65. package/ui/dist/assets/index-C-mur7pa.css +1 -0
  66. package/ui/dist/assets/index-CCP5nUOj.js +42 -0
  67. package/ui/dist/assets/{index-DoKtXbod.js → index-Cxhzi3bs.js} +1 -1
  68. package/ui/dist/index.html +2 -2
  69. package/vendor/progrok-0.2.0.tgz +0 -0
  70. package/bin/commands/annotate.ts +0 -119
  71. package/bin/commands/cancel.ts +0 -48
  72. package/bin/commands/canvas-versions.ts +0 -80
  73. package/bin/commands/capabilities.ts +0 -110
  74. package/bin/commands/cardnews.ts +0 -249
  75. package/bin/commands/comfy.ts +0 -54
  76. package/bin/commands/config.ts +0 -186
  77. package/bin/commands/defaults.ts +0 -192
  78. package/bin/commands/doctor.ts +0 -202
  79. package/bin/commands/edit.ts +0 -150
  80. package/bin/commands/gen.ts +0 -214
  81. package/bin/commands/grok.ts +0 -85
  82. package/bin/commands/history.ts +0 -146
  83. package/bin/commands/ls.ts +0 -64
  84. package/bin/commands/metadata.ts +0 -39
  85. package/bin/commands/multimode.ts +0 -196
  86. package/bin/commands/node.ts +0 -166
  87. package/bin/commands/observability.ts +0 -176
  88. package/bin/commands/ping.ts +0 -31
  89. package/bin/commands/prompt-sub/build.ts +0 -101
  90. package/bin/commands/prompt.ts +0 -492
  91. package/bin/commands/ps.ts +0 -81
  92. package/bin/commands/session.ts +0 -266
  93. package/bin/commands/show.ts +0 -72
  94. package/bin/commands/skill.ts +0 -70
  95. package/bin/commands/video.ts +0 -205
  96. package/bin/ima2.ts +0 -430
  97. package/bin/lib/args.ts +0 -92
  98. package/bin/lib/browser-id.ts +0 -16
  99. package/bin/lib/client.ts +0 -122
  100. package/bin/lib/config-store.ts +0 -120
  101. package/bin/lib/destructive-confirm.ts +0 -19
  102. package/bin/lib/doctor-checks.ts +0 -91
  103. package/bin/lib/error-hints.ts +0 -23
  104. package/bin/lib/files.ts +0 -39
  105. package/bin/lib/output.ts +0 -73
  106. package/bin/lib/platform.ts +0 -99
  107. package/bin/lib/recover-output.ts +0 -139
  108. package/bin/lib/sse.ts +0 -73
  109. package/bin/lib/star-prompt.ts +0 -97
  110. package/bin/lib/storage-doctor.ts +0 -39
  111. package/bin/lib/ui-build.ts +0 -85
  112. package/config.ts +0 -354
  113. package/lib/agentCommandParser.ts +0 -69
  114. package/lib/agentGenerationPlanner.ts +0 -273
  115. package/lib/agentQuestionResponder.ts +0 -266
  116. package/lib/agentQueueStore.ts +0 -270
  117. package/lib/agentQueueWorker.ts +0 -89
  118. package/lib/agentRuntime.ts +0 -592
  119. package/lib/agentSettings.ts +0 -72
  120. package/lib/agentStore.ts +0 -422
  121. package/lib/agentStoreRows.ts +0 -136
  122. package/lib/agentTypes.ts +0 -154
  123. package/lib/apiCachePolicy.ts +0 -11
  124. package/lib/assetLifecycle.ts +0 -146
  125. package/lib/canvasVersionStore.ts +0 -223
  126. package/lib/capabilities.ts +0 -126
  127. package/lib/cardNewsGenerator.ts +0 -271
  128. package/lib/cardNewsJobStore.ts +0 -142
  129. package/lib/cardNewsManifestStore.ts +0 -154
  130. package/lib/cardNewsPlanner.ts +0 -236
  131. package/lib/cardNewsPlannerClient.ts +0 -155
  132. package/lib/cardNewsPlannerPrompt.ts +0 -62
  133. package/lib/cardNewsPlannerSchema.ts +0 -321
  134. package/lib/cardNewsRoleTemplateStore.ts +0 -47
  135. package/lib/cardNewsTemplateStore.ts +0 -252
  136. package/lib/codexDetect.ts +0 -71
  137. package/lib/comfyBridge.ts +0 -235
  138. package/lib/composerSnapshot.ts +0 -33
  139. package/lib/configKeys.ts +0 -62
  140. package/lib/db.ts +0 -295
  141. package/lib/errInfo.ts +0 -43
  142. package/lib/errorClassify.ts +0 -100
  143. package/lib/generationCancel.ts +0 -28
  144. package/lib/generationErrors.ts +0 -238
  145. package/lib/grokImageAdapter.ts +0 -513
  146. package/lib/grokMultimodeAdapter.ts +0 -84
  147. package/lib/grokProxyLauncher.ts +0 -129
  148. package/lib/grokRuntime.ts +0 -23
  149. package/lib/grokSizeMapper.ts +0 -71
  150. package/lib/grokVideoAdapter.ts +0 -519
  151. package/lib/historyIndex.ts +0 -51
  152. package/lib/historyList.ts +0 -177
  153. package/lib/imageMetadata.ts +0 -113
  154. package/lib/imageMetadataStore.ts +0 -67
  155. package/lib/imageModels.ts +0 -165
  156. package/lib/inflight.ts +0 -281
  157. package/lib/localImportStore.ts +0 -114
  158. package/lib/logger.ts +0 -161
  159. package/lib/nodeStore.ts +0 -91
  160. package/lib/oauthLauncher.ts +0 -78
  161. package/lib/oauthNormalize.ts +0 -30
  162. package/lib/oauthProxy/errors.ts +0 -128
  163. package/lib/oauthProxy/generators.ts +0 -494
  164. package/lib/oauthProxy/index.ts +0 -28
  165. package/lib/oauthProxy/prompts.ts +0 -123
  166. package/lib/oauthProxy/references.ts +0 -45
  167. package/lib/oauthProxy/runtime.ts +0 -115
  168. package/lib/oauthProxy/streams.ts +0 -232
  169. package/lib/oauthProxy/types.ts +0 -9
  170. package/lib/oauthProxy.ts +0 -3
  171. package/lib/openDirectory.ts +0 -47
  172. package/lib/pngInfo.ts +0 -26
  173. package/lib/promptBuilder/attachments.ts +0 -74
  174. package/lib/promptBuilder/client.ts +0 -130
  175. package/lib/promptBuilder/constants.ts +0 -9
  176. package/lib/promptBuilder/context.ts +0 -36
  177. package/lib/promptBuilder/errors.ts +0 -12
  178. package/lib/promptBuilder/requestSchema.ts +0 -56
  179. package/lib/promptBuilder/responseParser.ts +0 -219
  180. package/lib/promptBuilder/systemPrompt.ts +0 -135
  181. package/lib/promptBuilder/transport.ts +0 -94
  182. package/lib/promptBuilder/types.ts +0 -109
  183. package/lib/promptImport/curatedSources.ts +0 -141
  184. package/lib/promptImport/discoveryRegistry.ts +0 -329
  185. package/lib/promptImport/errors.ts +0 -18
  186. package/lib/promptImport/githubDiscovery.ts +0 -309
  187. package/lib/promptImport/githubFolder.ts +0 -397
  188. package/lib/promptImport/githubSource.ts +0 -257
  189. package/lib/promptImport/gptImageHints.ts +0 -70
  190. package/lib/promptImport/parsePromptCandidates.ts +0 -179
  191. package/lib/promptImport/promptIndex.ts +0 -326
  192. package/lib/promptImport/rankPromptCandidates.ts +0 -65
  193. package/lib/promptImport/types.ts +0 -103
  194. package/lib/promptSafetyPolicy.ts +0 -5
  195. package/lib/providerOptions.ts +0 -56
  196. package/lib/referenceImageCompress.ts +0 -84
  197. package/lib/refs.ts +0 -133
  198. package/lib/requestLogger.ts +0 -49
  199. package/lib/responsesDoctor.ts +0 -456
  200. package/lib/responsesErrors.ts +0 -83
  201. package/lib/responsesFallback.ts +0 -114
  202. package/lib/responsesImageAdapter.ts +0 -466
  203. package/lib/responsesParse.ts +0 -452
  204. package/lib/responsesTools.ts +0 -28
  205. package/lib/runtimeContext.ts +0 -146
  206. package/lib/runtimePorts.ts +0 -105
  207. package/lib/sessionStore.ts +0 -308
  208. package/lib/storageMigration.ts +0 -310
  209. package/lib/styleSheet.ts +0 -139
  210. package/lib/systemTrash.ts +0 -20
  211. package/lib/videoSeriesChain.ts +0 -29
  212. package/lib/visibleTextLanguagePolicy.ts +0 -7
  213. package/routes/agent.ts +0 -308
  214. package/routes/annotations.ts +0 -118
  215. package/routes/canvasVersions.ts +0 -69
  216. package/routes/capabilities.ts +0 -18
  217. package/routes/cardNews.ts +0 -211
  218. package/routes/comfy.ts +0 -43
  219. package/routes/edit.ts +0 -352
  220. package/routes/generate.ts +0 -492
  221. package/routes/grok.ts +0 -24
  222. package/routes/health.ts +0 -123
  223. package/routes/history.ts +0 -221
  224. package/routes/imageImport.ts +0 -37
  225. package/routes/index.ts +0 -48
  226. package/routes/metadata.ts +0 -77
  227. package/routes/multimode.ts +0 -499
  228. package/routes/nodes.ts +0 -578
  229. package/routes/promptBuilder.ts +0 -37
  230. package/routes/promptImport.ts +0 -379
  231. package/routes/prompts.ts +0 -428
  232. package/routes/sessions.ts +0 -317
  233. package/routes/storage.ts +0 -47
  234. package/routes/video.ts +0 -232
  235. package/server.ts +0 -290
  236. package/ui/dist/assets/SettingsWorkspace-F3eNu3mJ.js +0 -1
  237. package/ui/dist/assets/index-B6tcw_UF.css +0 -1
  238. package/ui/dist/assets/index-DYOh6gQD.js +0 -32
  239. package/vendor/progrok-0.1.1.tgz +0 -0
@@ -1,141 +0,0 @@
1
- const CURATED_SOURCES = [
2
- {
3
- id: "picotrex-nano-banana",
4
- repo: "PicoTrex/Awesome-Nano-Banana-images",
5
- owner: "PicoTrex",
6
- name: "Awesome-Nano-Banana-images",
7
- displayName: "Awesome Nano Banana Images",
8
- defaultRef: "main",
9
- allowedPaths: ["README_en.md", "README.md"],
10
- extensions: ["md"],
11
- sourceType: "nano-banana-gallery",
12
- licenseSpdx: "Apache-2.0",
13
- requiresAttribution: true,
14
- trustTier: "curated",
15
- lastVerifiedAt: "2026-04-28",
16
- notes: "High-signal Nano Banana image prompt and example collection.",
17
- searchSeeds: ["nano banana", "image generation", "reference image", "style transfer", "prompt"],
18
- defaultSearch: true,
19
- },
20
- {
21
- id: "aimikoda-nano-banana-pro",
22
- repo: "aimikoda/nano-banana-pro-prompts",
23
- owner: "aimikoda",
24
- name: "nano-banana-pro-prompts",
25
- displayName: "Nano Banana Pro Prompts",
26
- defaultRef: "main",
27
- allowedPaths: ["README.md"],
28
- extensions: ["md"],
29
- sourceType: "nano-banana-prompts",
30
- licenseSpdx: "NOASSERTION",
31
- requiresAttribution: true,
32
- trustTier: "curated",
33
- lastVerifiedAt: "2026-04-28",
34
- notes: "Nano Banana Pro / Nano Banana 2 prompt source.",
35
- searchSeeds: ["nano banana pro", "gpt-image-2", "prompt", "2k", "4k"],
36
- defaultSearch: true,
37
- },
38
- {
39
- id: "stable-diffusion-awesome-manual",
40
- repo: "yuyan124/awesome-stable-diffusion-prompts",
41
- displayName: "Awesome Stable Diffusion Prompts",
42
- defaultRef: "main",
43
- allowedPaths: [],
44
- extensions: ["md", "txt"],
45
- sourceType: "manual-review",
46
- licenseSpdx: "NOASSERTION",
47
- requiresAttribution: true,
48
- trustTier: "manual-review",
49
- lastVerifiedAt: null,
50
- notes: "Manual-review candidate for a later registry promotion.",
51
- searchSeeds: ["stable diffusion", "prompt"],
52
- defaultSearch: false,
53
- },
54
- {
55
- id: "stable-diffusion-templates-manual",
56
- repo: "Dalabad/stable-diffusion-prompt-templates",
57
- displayName: "Stable Diffusion Prompt Templates",
58
- defaultRef: "main",
59
- allowedPaths: [],
60
- extensions: ["md", "txt"],
61
- sourceType: "manual-review",
62
- licenseSpdx: "NOASSERTION",
63
- requiresAttribution: true,
64
- trustTier: "manual-review",
65
- lastVerifiedAt: null,
66
- notes: "Manual-review candidate for structured Stable Diffusion prompt templates.",
67
- searchSeeds: ["stable diffusion", "template", "prompt"],
68
- defaultSearch: false,
69
- },
70
- {
71
- id: "midjourney-awesome-manual",
72
- repo: "Ezagor-dev/awesome-midjourney-prompts",
73
- displayName: "Awesome Midjourney Prompts",
74
- defaultRef: "main",
75
- allowedPaths: [],
76
- extensions: ["md", "txt"],
77
- sourceType: "manual-review",
78
- licenseSpdx: "NOASSERTION",
79
- requiresAttribution: true,
80
- trustTier: "manual-review",
81
- lastVerifiedAt: null,
82
- notes: "Manual-review candidate for broader model-aware search.",
83
- searchSeeds: ["midjourney", "prompt"],
84
- defaultSearch: false,
85
- },
86
- {
87
- id: "diagram-image-prompts-manual",
88
- repo: "danielrosehill/Tech-Diagram-Image-Gen-Prompts",
89
- displayName: "Tech Diagram Image Gen Prompts",
90
- defaultRef: "main",
91
- allowedPaths: [],
92
- extensions: ["md", "txt"],
93
- sourceType: "manual-review",
94
- licenseSpdx: "NOASSERTION",
95
- requiresAttribution: true,
96
- trustTier: "manual-review",
97
- lastVerifiedAt: null,
98
- notes: "Manual-review candidate for technical diagram image-generation prompts.",
99
- searchSeeds: ["diagram", "technical", "image generation", "prompt"],
100
- defaultSearch: false,
101
- },
102
- ];
103
-
104
- type CuratedSource = (typeof CURATED_SOURCES)[number];
105
-
106
- function publicSource(source: CuratedSource) {
107
- return {
108
- id: source.id,
109
- repo: source.repo,
110
- owner: source.owner,
111
- name: source.name,
112
- displayName: source.displayName,
113
- defaultRef: source.defaultRef,
114
- allowedPaths: [...source.allowedPaths],
115
- extensions: [...source.extensions],
116
- sourceType: source.sourceType,
117
- licenseSpdx: source.licenseSpdx,
118
- requiresAttribution: source.requiresAttribution,
119
- trustTier: source.trustTier,
120
- lastVerifiedAt: source.lastVerifiedAt,
121
- notes: source.notes,
122
- searchSeeds: [...source.searchSeeds],
123
- defaultSearch: source.defaultSearch,
124
- };
125
- }
126
-
127
- export function listCuratedSources({ includeManualReview = true, defaultSearchOnly = false } = {}) {
128
- return CURATED_SOURCES
129
- .filter((source) => includeManualReview || source.trustTier !== "manual-review")
130
- .filter((source) => !defaultSearchOnly || source.defaultSearch)
131
- .map(publicSource);
132
- }
133
-
134
- export function getCuratedSource(sourceId: string) {
135
- const source = CURATED_SOURCES.find((item) => item.id === sourceId);
136
- return source ? publicSource(source) : null;
137
- }
138
-
139
- export function getDefaultSearchSources() {
140
- return listCuratedSources({ includeManualReview: false, defaultSearchOnly: true });
141
- }
@@ -1,329 +0,0 @@
1
- import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
2
- import { dirname } from "node:path";
3
- import { promptImportError } from "./errors.js";
4
- import { requireRuntimeContext } from "../runtimeContext.js";
5
- import type { CuratedSourceLike, PromptImportCtx } from "./types.js";
6
-
7
- const REGISTRY_VERSION = 1;
8
- const OWNER_REPO_RE = /^[A-Za-z0-9_.-]+$/;
9
- const SUPPORTED_EXTENSIONS = new Set(["md", "markdown", "txt"]);
10
-
11
- interface DiscoveryCandidateRecord {
12
- id: string;
13
- repo: string;
14
- owner?: string;
15
- name?: string;
16
- fullName: string;
17
- htmlUrl?: string | null;
18
- description?: string;
19
- defaultBranch?: string;
20
- stars?: number;
21
- forks?: number;
22
- openIssues?: number;
23
- updatedAt?: string | null;
24
- pushedAt?: string | null;
25
- licenseSpdx?: string;
26
- topics?: string[];
27
- language?: string | null;
28
- score?: number;
29
- scoreReasons?: string[];
30
- warnings?: string[];
31
- status?: string;
32
- query?: string;
33
- discoveredAt?: string;
34
- allowedPaths?: string[];
35
- reviewedAt?: string | null;
36
- reviewNotes?: string;
37
- approvedSource?: CuratedSourceLike | null;
38
- defaultSearch?: boolean;
39
- }
40
-
41
- interface DiscoveryRegistry {
42
- version: number;
43
- updatedAt: string | null;
44
- candidates: Record<string, DiscoveryCandidateRecord>;
45
- }
46
-
47
- interface ReviewLimits {
48
- maxRepoIndexFiles: number;
49
- }
50
-
51
- interface ReviewPayload {
52
- repo?: unknown;
53
- status?: unknown;
54
- allowedPaths?: unknown;
55
- defaultSearch?: unknown;
56
- reviewNotes?: unknown;
57
- }
58
-
59
- function registryFile(ctx: PromptImportCtx): string {
60
- const storage = (ctx.config as { storage?: { promptImportDiscoveryRegistryFile?: string } } | undefined)?.storage;
61
- return storage?.promptImportDiscoveryRegistryFile ?? "";
62
- }
63
-
64
- function emptyRegistry(): DiscoveryRegistry {
65
- return { version: REGISTRY_VERSION, updatedAt: null, candidates: {} };
66
- }
67
-
68
- function normalizeRepoFullName(repo: unknown): string {
69
- const value = String(repo || "").trim();
70
- const parts = value.split("/");
71
- if (parts.length !== 2 || !OWNER_REPO_RE.test(parts[0]) || !OWNER_REPO_RE.test(parts[1])) {
72
- throw promptImportError("GITHUB_DISCOVERY_REVIEW_INVALID", "Review repo must be owner/repo");
73
- }
74
- return `${parts[0]}/${parts[1]}`;
75
- }
76
-
77
- function extensionForPath(path: string): string {
78
- const match = /\.([A-Za-z0-9]+)$/.exec(path);
79
- return match?.[1]?.toLowerCase() ?? "";
80
- }
81
-
82
- function assertAllowedPath(path: unknown): string {
83
- const value = String(path || "").trim();
84
- if (!value) {
85
- throw promptImportError("GITHUB_DISCOVERY_REVIEW_INVALID", "Allowed path is required");
86
- }
87
- if (/^https?:\/\//i.test(value)) {
88
- throw promptImportError("GITHUB_DISCOVERY_REVIEW_INVALID", "Allowed path must be repo-relative");
89
- }
90
- if (value.includes("\0") || /%00/i.test(value)) {
91
- throw promptImportError("GITHUB_DISCOVERY_REVIEW_INVALID", "Allowed path contains a null byte");
92
- }
93
- if (/%2f|%5c/i.test(value)) {
94
- throw promptImportError("GITHUB_DISCOVERY_REVIEW_INVALID", "Allowed path contains an encoded slash");
95
- }
96
- if (value.includes("\\") || value.split("/").includes("..")) {
97
- throw promptImportError("GITHUB_DISCOVERY_REVIEW_INVALID", "Allowed path traversal is not allowed");
98
- }
99
- const clean = value.replace(/^\/+/, "");
100
- const extension = extensionForPath(clean);
101
- if (!SUPPORTED_EXTENSIONS.has(extension)) {
102
- throw promptImportError("GITHUB_DISCOVERY_REVIEW_INVALID", "Allowed paths must be .md, .markdown, or .txt");
103
- }
104
- return clean;
105
- }
106
-
107
- function normalizeAllowedPaths(paths: unknown, limits: ReviewLimits): string[] {
108
- if (paths === undefined) return [];
109
- if (!Array.isArray(paths)) {
110
- throw promptImportError("GITHUB_DISCOVERY_REVIEW_INVALID", "allowedPaths must be an array");
111
- }
112
- if (paths.length > limits.maxRepoIndexFiles) {
113
- throw promptImportError("GITHUB_DISCOVERY_REVIEW_INVALID", "Too many allowed paths", 413);
114
- }
115
- return [...new Set(paths.map(assertAllowedPath))];
116
- }
117
-
118
- interface PublicCandidate {
119
- id: string;
120
- repo: string;
121
- owner: string | undefined;
122
- name: string | undefined;
123
- fullName: string;
124
- htmlUrl: string | null | undefined;
125
- description: string | undefined;
126
- defaultBranch: string | undefined;
127
- stars: number | undefined;
128
- forks: number | undefined;
129
- openIssues: number | undefined;
130
- updatedAt: string | null | undefined;
131
- pushedAt: string | null | undefined;
132
- licenseSpdx: string | undefined;
133
- topics: string[];
134
- language: string | null | undefined;
135
- score: number | undefined;
136
- scoreReasons: string[];
137
- warnings: string[];
138
- status: string;
139
- query: string | undefined;
140
- discoveredAt: string | undefined;
141
- reviewedAt: string | null;
142
- reviewNotes: string;
143
- approvedSource: CuratedSourceLike | null;
144
- }
145
-
146
- function publicCandidate(candidate: DiscoveryCandidateRecord): PublicCandidate {
147
- return {
148
- id: candidate.id,
149
- repo: candidate.repo,
150
- owner: candidate.owner,
151
- name: candidate.name,
152
- fullName: candidate.fullName,
153
- htmlUrl: candidate.htmlUrl,
154
- description: candidate.description,
155
- defaultBranch: candidate.defaultBranch,
156
- stars: candidate.stars,
157
- forks: candidate.forks,
158
- openIssues: candidate.openIssues,
159
- updatedAt: candidate.updatedAt,
160
- pushedAt: candidate.pushedAt,
161
- licenseSpdx: candidate.licenseSpdx,
162
- topics: Array.isArray(candidate.topics) ? [...candidate.topics] : [],
163
- language: candidate.language,
164
- score: candidate.score,
165
- scoreReasons: Array.isArray(candidate.scoreReasons) ? [...candidate.scoreReasons] : [],
166
- warnings: Array.isArray(candidate.warnings) ? [...candidate.warnings] : [],
167
- status: candidate.status || "candidate",
168
- query: candidate.query,
169
- discoveredAt: candidate.discoveredAt,
170
- reviewedAt: candidate.reviewedAt || null,
171
- reviewNotes: candidate.reviewNotes || "",
172
- approvedSource: candidate.approvedSource || null,
173
- };
174
- }
175
-
176
- function reviewedSourceId(candidate: DiscoveryCandidateRecord): string {
177
- return `discovered-${candidate.fullName.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "")}`;
178
- }
179
-
180
- export async function readDiscoveryRegistry(ctxIn: PromptImportCtx): Promise<DiscoveryRegistry> {
181
- const ctx = requireRuntimeContext(ctxIn);
182
- try {
183
- const parsed = JSON.parse(await readFile(registryFile(ctx), "utf8")) as DiscoveryRegistry;
184
- if (parsed.version !== REGISTRY_VERSION) return emptyRegistry();
185
- return {
186
- version: REGISTRY_VERSION,
187
- updatedAt: parsed.updatedAt || null,
188
- candidates: parsed.candidates || {},
189
- };
190
- } catch {
191
- return emptyRegistry();
192
- }
193
- }
194
-
195
- export async function writeDiscoveryRegistry(ctxIn: PromptImportCtx, registry: DiscoveryRegistry): Promise<void> {
196
- const ctx = requireRuntimeContext(ctxIn);
197
- const file = registryFile(ctx);
198
- await mkdir(dirname(file), { recursive: true });
199
- const tmp = `${file}.${process.pid}.${Date.now()}.tmp`;
200
- await writeFile(tmp, JSON.stringify(registry, null, 2));
201
- await rename(tmp, file);
202
- }
203
-
204
- interface ListFilters {
205
- status?: string;
206
- }
207
-
208
- export async function listDiscoveryCandidates(ctxIn: PromptImportCtx, filters: ListFilters = {}): Promise<PublicCandidate[]> {
209
- const ctx = requireRuntimeContext(ctxIn);
210
- const registry = await readDiscoveryRegistry(ctx);
211
- const status = typeof filters.status === "string" ? filters.status : null;
212
- return Object.values(registry.candidates)
213
- .filter((candidate) => !status || candidate.status === status)
214
- .map(publicCandidate)
215
- .sort((a, b) => (b.score ?? 0) - (a.score ?? 0) || a.fullName.localeCompare(b.fullName));
216
- }
217
-
218
- export async function upsertDiscoveryCandidates(ctxIn: PromptImportCtx, candidates: DiscoveryCandidateRecord[]): Promise<PublicCandidate[]> {
219
- const ctx = requireRuntimeContext(ctxIn);
220
- const registry = await readDiscoveryRegistry(ctx);
221
- const now = new Date().toISOString();
222
- for (const candidate of candidates) {
223
- const fullName = normalizeRepoFullName(candidate.fullName || candidate.repo);
224
- const existing = registry.candidates[fullName];
225
- registry.candidates[fullName] = {
226
- ...existing,
227
- ...candidate,
228
- fullName,
229
- repo: fullName,
230
- status: existing?.status || candidate.status || "candidate",
231
- discoveredAt: existing?.discoveredAt || candidate.discoveredAt || now,
232
- };
233
- }
234
- registry.updatedAt = now;
235
- await writeDiscoveryRegistry(ctx, registry);
236
- return Object.values(registry.candidates).map(publicCandidate);
237
- }
238
-
239
- export function reviewedSourceFromCandidate(candidate: DiscoveryCandidateRecord): CuratedSourceLike {
240
- const [owner, name] = String(candidate.fullName || candidate.repo).split("/");
241
- const allowedPaths = Array.isArray(candidate.allowedPaths) ? candidate.allowedPaths : [];
242
- return {
243
- id: reviewedSourceId(candidate),
244
- repo: `${owner}/${name}`,
245
- owner,
246
- name,
247
- displayName: candidate.name || name,
248
- defaultRef: candidate.defaultBranch || "main",
249
- allowedPaths,
250
- extensions: ["md", "markdown", "txt"],
251
- sourceType: "discovered",
252
- licenseSpdx: candidate.licenseSpdx || "NOASSERTION",
253
- requiresAttribution: true,
254
- trustTier: "reviewed",
255
- lastVerifiedAt: candidate.reviewedAt || null,
256
- notes: candidate.reviewNotes || candidate.description || "Reviewed GitHub discovery source.",
257
- searchSeeds: [candidate.name, candidate.description, ...(candidate.topics || [])].filter(Boolean).slice(0, 8) as string[],
258
- defaultSearch: Boolean(candidate.defaultSearch && allowedPaths.length > 0 && !String(candidate.defaultBranch || "").includes("/")),
259
- };
260
- }
261
-
262
- export async function reviewDiscoveryCandidate(ctxIn: PromptImportCtx, payload: ReviewPayload) {
263
- const ctx = requireRuntimeContext(ctxIn);
264
- const configLimits = (ctx.config?.limits ?? {}) as Record<string, number>;
265
- const limits: ReviewLimits = {
266
- maxRepoIndexFiles: configLimits.promptImportMaxRepoIndexFiles ?? 0,
267
- };
268
- const repo = normalizeRepoFullName(payload?.repo);
269
- const status = String(payload?.status || "");
270
- if (!["approved", "rejected"].includes(status)) {
271
- throw promptImportError("GITHUB_DISCOVERY_REVIEW_INVALID", "Review status must be approved or rejected");
272
- }
273
-
274
- const registry = await readDiscoveryRegistry(ctx);
275
- const candidate = registry.candidates[repo];
276
- if (!candidate) {
277
- throw promptImportError("GITHUB_DISCOVERY_SOURCE_NOT_FOUND", "Discovery candidate was not found", 404);
278
- }
279
-
280
- const allowedPaths = normalizeAllowedPaths(payload?.allowedPaths, limits);
281
- const warnings = [...(candidate.warnings || [])];
282
- const defaultBranch = String(candidate.defaultBranch || "");
283
- let defaultSearch = Boolean(payload?.defaultSearch);
284
-
285
- if (status !== "approved" || allowedPaths.length === 0) defaultSearch = false;
286
- if (defaultBranch.includes("/")) {
287
- defaultSearch = false;
288
- warnings.push("discovery-default-branch-unsupported");
289
- }
290
- if (status === "approved" && allowedPaths.length === 0) {
291
- warnings.push("discovery-requires-paths");
292
- }
293
-
294
- const reviewed: DiscoveryCandidateRecord = {
295
- ...candidate,
296
- allowedPaths,
297
- status,
298
- warnings: [...new Set(warnings)],
299
- defaultSearch,
300
- reviewedAt: new Date().toISOString(),
301
- reviewNotes: typeof payload?.reviewNotes === "string" ? payload.reviewNotes.slice(0, 500) : "",
302
- };
303
- reviewed.approvedSource = status === "approved" ? reviewedSourceFromCandidate(reviewed) : null;
304
- registry.candidates[repo] = reviewed;
305
- registry.updatedAt = reviewed.reviewedAt ?? null;
306
- await writeDiscoveryRegistry(ctx, registry);
307
- return { candidate: publicCandidate(reviewed), source: reviewed.approvedSource, warnings: reviewed.warnings };
308
- }
309
-
310
- interface ListReviewedOptions {
311
- defaultSearchOnly?: boolean;
312
- }
313
-
314
- export async function listReviewedDiscoverySources(ctx: PromptImportCtx, { defaultSearchOnly = false }: ListReviewedOptions = {}): Promise<CuratedSourceLike[]> {
315
- const registry = await readDiscoveryRegistry(ctx);
316
- return Object.values(registry.candidates)
317
- .filter((candidate) => candidate.status === "approved" && candidate.approvedSource)
318
- .map((candidate) => candidate.approvedSource as CuratedSourceLike)
319
- .filter((source) => !defaultSearchOnly || source.defaultSearch);
320
- }
321
-
322
- export async function getReviewedDiscoverySource(ctx: PromptImportCtx, sourceId: string): Promise<CuratedSourceLike | null> {
323
- const sources = await listReviewedDiscoverySources(ctx);
324
- return sources.find((source) => source.id === sourceId) || null;
325
- }
326
-
327
- export async function getDefaultReviewedDiscoverySources(ctx: PromptImportCtx): Promise<CuratedSourceLike[]> {
328
- return listReviewedDiscoverySources(ctx, { defaultSearchOnly: true });
329
- }
@@ -1,18 +0,0 @@
1
- export class PromptImportError extends Error {
2
- code: string;
3
- status: number;
4
- constructor(code: string, message: string, status = 400) {
5
- super(message);
6
- this.name = "PromptImportError";
7
- this.code = code;
8
- this.status = status;
9
- }
10
- }
11
-
12
- export function promptImportError(code: string, message: string, status = 400) {
13
- return new PromptImportError(code, message, status);
14
- }
15
-
16
- export function isPromptImportError(error: unknown) {
17
- return error instanceof PromptImportError || Boolean((error as { code?: unknown; status?: unknown })?.code && (error as { status?: unknown })?.status);
18
- }