ima2-gen 1.1.21 → 1.1.23

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 (214) hide show
  1. package/README.md +44 -7
  2. package/bin/commands/video.js +14 -0
  3. package/bin/ima2.js +14 -4
  4. package/bin/lib/platform.js +34 -5
  5. package/docs/README.ko.md +43 -2
  6. package/lib/agentQueueWorker.js +6 -0
  7. package/lib/agentRuntime.js +3 -2
  8. package/lib/atomicWrite.js +14 -0
  9. package/lib/grokImageAdapter.js +6 -0
  10. package/lib/grokProxyLauncher.js +5 -3
  11. package/lib/grokVideoAdapter.js +1 -1
  12. package/lib/grokVideoPlannerPrompt.js +10 -0
  13. package/lib/inflight.js +1 -1
  14. package/lib/oauthLauncher.js +5 -0
  15. package/lib/videoFrameExtract.js +3 -3
  16. package/package.json +5 -7
  17. package/routes/capabilities.js +13 -0
  18. package/routes/edit.js +2 -1
  19. package/routes/generate.js +32 -6
  20. package/routes/health.js +4 -3
  21. package/routes/multimode.js +2 -1
  22. package/routes/video.js +35 -3
  23. package/server.js +29 -2
  24. package/skills/ima2/SKILL.md +48 -6
  25. package/ui/dist/.vite/manifest.json +12 -12
  26. package/ui/dist/assets/{AgentWorkspace-B_hq9CLg.js → AgentWorkspace-C21zqdTZ.js} +1 -1
  27. package/ui/dist/assets/{CardNewsWorkspace-wD12J7qk.js → CardNewsWorkspace-BN-ga1lG.js} +1 -1
  28. package/ui/dist/assets/{NodeCanvas-CI_wuPMf.js → NodeCanvas-BbMa4IhI.js} +1 -1
  29. package/ui/dist/assets/{PromptBuilderPanel-CUTujJUV.js → PromptBuilderPanel-DRwBJRDQ.js} +1 -1
  30. package/ui/dist/assets/{PromptImportDialog-CUi66jPK.js → PromptImportDialog-Dp85kHCq.js} +2 -2
  31. package/ui/dist/assets/{PromptImportDiscoverySection-Cm3vrjY4.js → PromptImportDiscoverySection-BE8Q8MLD.js} +1 -1
  32. package/ui/dist/assets/{PromptImportFolderSection-DOtWTD9n.js → PromptImportFolderSection-PtH5x0sc.js} +1 -1
  33. package/ui/dist/assets/{PromptLibraryPanel-BMjQegRa.js → PromptLibraryPanel-FnM9tHI9.js} +2 -2
  34. package/ui/dist/assets/SettingsWorkspace-MARPGyBL.js +1 -0
  35. package/ui/dist/assets/index-BAFI6htx.js +42 -0
  36. package/ui/dist/assets/{index-31uVIdt4.js → index-BSXxr_Bt.js} +1 -1
  37. package/ui/dist/assets/index-DS-ADE7U.css +1 -0
  38. package/ui/dist/index.html +2 -2
  39. package/bin/commands/annotate.ts +0 -119
  40. package/bin/commands/cancel.ts +0 -48
  41. package/bin/commands/canvas-versions.ts +0 -80
  42. package/bin/commands/capabilities.ts +0 -110
  43. package/bin/commands/cardnews.ts +0 -249
  44. package/bin/commands/comfy.ts +0 -54
  45. package/bin/commands/config.ts +0 -186
  46. package/bin/commands/defaults.ts +0 -192
  47. package/bin/commands/doctor.ts +0 -202
  48. package/bin/commands/edit.ts +0 -150
  49. package/bin/commands/gen.ts +0 -214
  50. package/bin/commands/grok.ts +0 -90
  51. package/bin/commands/history.ts +0 -146
  52. package/bin/commands/ls.ts +0 -64
  53. package/bin/commands/metadata.ts +0 -39
  54. package/bin/commands/multimode.ts +0 -196
  55. package/bin/commands/node.ts +0 -166
  56. package/bin/commands/observability.ts +0 -176
  57. package/bin/commands/ping.ts +0 -31
  58. package/bin/commands/prompt-sub/build.ts +0 -101
  59. package/bin/commands/prompt.ts +0 -492
  60. package/bin/commands/ps.ts +0 -81
  61. package/bin/commands/session.ts +0 -266
  62. package/bin/commands/show.ts +0 -72
  63. package/bin/commands/skill.ts +0 -70
  64. package/bin/commands/video.ts +0 -442
  65. package/bin/ima2.ts +0 -430
  66. package/bin/lib/args.ts +0 -92
  67. package/bin/lib/browser-id.ts +0 -16
  68. package/bin/lib/client.ts +0 -122
  69. package/bin/lib/config-store.ts +0 -120
  70. package/bin/lib/destructive-confirm.ts +0 -19
  71. package/bin/lib/doctor-checks.ts +0 -91
  72. package/bin/lib/error-hints.ts +0 -23
  73. package/bin/lib/files.ts +0 -39
  74. package/bin/lib/output.ts +0 -73
  75. package/bin/lib/platform.ts +0 -99
  76. package/bin/lib/recover-output.ts +0 -139
  77. package/bin/lib/sse.ts +0 -73
  78. package/bin/lib/star-prompt.ts +0 -97
  79. package/bin/lib/storage-doctor.ts +0 -39
  80. package/bin/lib/ui-build.ts +0 -85
  81. package/config.ts +0 -354
  82. package/lib/agentCommandParser.ts +0 -69
  83. package/lib/agentGenerationPlanner.ts +0 -273
  84. package/lib/agentQuestionResponder.ts +0 -266
  85. package/lib/agentQueueStore.ts +0 -270
  86. package/lib/agentQueueWorker.ts +0 -89
  87. package/lib/agentRuntime.ts +0 -604
  88. package/lib/agentSettings.ts +0 -72
  89. package/lib/agentStore.ts +0 -422
  90. package/lib/agentStoreRows.ts +0 -136
  91. package/lib/agentTypes.ts +0 -154
  92. package/lib/apiCachePolicy.ts +0 -11
  93. package/lib/assetLifecycle.ts +0 -146
  94. package/lib/canvasVersionStore.ts +0 -223
  95. package/lib/capabilities.ts +0 -126
  96. package/lib/cardNewsGenerator.ts +0 -271
  97. package/lib/cardNewsJobStore.ts +0 -142
  98. package/lib/cardNewsManifestStore.ts +0 -154
  99. package/lib/cardNewsPlanner.ts +0 -236
  100. package/lib/cardNewsPlannerClient.ts +0 -155
  101. package/lib/cardNewsPlannerPrompt.ts +0 -62
  102. package/lib/cardNewsPlannerSchema.ts +0 -321
  103. package/lib/cardNewsRoleTemplateStore.ts +0 -47
  104. package/lib/cardNewsTemplateStore.ts +0 -252
  105. package/lib/codexDetect.ts +0 -71
  106. package/lib/comfyBridge.ts +0 -235
  107. package/lib/composerSnapshot.ts +0 -33
  108. package/lib/configKeys.ts +0 -62
  109. package/lib/db.ts +0 -295
  110. package/lib/errInfo.ts +0 -43
  111. package/lib/errorClassify.ts +0 -100
  112. package/lib/generationCancel.ts +0 -28
  113. package/lib/generationErrors.ts +0 -238
  114. package/lib/grokImageAdapter.ts +0 -513
  115. package/lib/grokMultimodeAdapter.ts +0 -84
  116. package/lib/grokProxyLauncher.ts +0 -153
  117. package/lib/grokRuntime.ts +0 -23
  118. package/lib/grokSizeMapper.ts +0 -71
  119. package/lib/grokVideoAdapter.ts +0 -458
  120. package/lib/grokVideoCanvas.ts +0 -26
  121. package/lib/grokVideoDownload.ts +0 -59
  122. package/lib/grokVideoPlannerPrompt.ts +0 -67
  123. package/lib/historyIndex.ts +0 -51
  124. package/lib/historyList.ts +0 -181
  125. package/lib/imageMetadata.ts +0 -113
  126. package/lib/imageMetadataStore.ts +0 -67
  127. package/lib/imageModels.ts +0 -165
  128. package/lib/inflight.ts +0 -281
  129. package/lib/localImportStore.ts +0 -114
  130. package/lib/logger.ts +0 -161
  131. package/lib/nodeStore.ts +0 -91
  132. package/lib/oauthLauncher.ts +0 -94
  133. package/lib/oauthNormalize.ts +0 -30
  134. package/lib/oauthProxy/errors.ts +0 -128
  135. package/lib/oauthProxy/generators.ts +0 -494
  136. package/lib/oauthProxy/index.ts +0 -28
  137. package/lib/oauthProxy/prompts.ts +0 -123
  138. package/lib/oauthProxy/references.ts +0 -45
  139. package/lib/oauthProxy/runtime.ts +0 -115
  140. package/lib/oauthProxy/streams.ts +0 -232
  141. package/lib/oauthProxy/types.ts +0 -9
  142. package/lib/oauthProxy.ts +0 -3
  143. package/lib/openDirectory.ts +0 -47
  144. package/lib/pngInfo.ts +0 -26
  145. package/lib/promptBuilder/attachments.ts +0 -74
  146. package/lib/promptBuilder/client.ts +0 -130
  147. package/lib/promptBuilder/constants.ts +0 -9
  148. package/lib/promptBuilder/context.ts +0 -36
  149. package/lib/promptBuilder/errors.ts +0 -12
  150. package/lib/promptBuilder/requestSchema.ts +0 -56
  151. package/lib/promptBuilder/responseParser.ts +0 -219
  152. package/lib/promptBuilder/systemPrompt.ts +0 -135
  153. package/lib/promptBuilder/transport.ts +0 -94
  154. package/lib/promptBuilder/types.ts +0 -109
  155. package/lib/promptImport/curatedSources.ts +0 -141
  156. package/lib/promptImport/discoveryRegistry.ts +0 -329
  157. package/lib/promptImport/errors.ts +0 -18
  158. package/lib/promptImport/githubDiscovery.ts +0 -309
  159. package/lib/promptImport/githubFolder.ts +0 -397
  160. package/lib/promptImport/githubSource.ts +0 -257
  161. package/lib/promptImport/gptImageHints.ts +0 -70
  162. package/lib/promptImport/parsePromptCandidates.ts +0 -179
  163. package/lib/promptImport/promptIndex.ts +0 -326
  164. package/lib/promptImport/rankPromptCandidates.ts +0 -65
  165. package/lib/promptImport/types.ts +0 -103
  166. package/lib/promptSafetyPolicy.ts +0 -5
  167. package/lib/providerOptions.ts +0 -56
  168. package/lib/referenceImageCompress.ts +0 -84
  169. package/lib/refs.ts +0 -133
  170. package/lib/requestLogger.ts +0 -49
  171. package/lib/responsesDoctor.ts +0 -456
  172. package/lib/responsesErrors.ts +0 -83
  173. package/lib/responsesFallback.ts +0 -114
  174. package/lib/responsesImageAdapter.ts +0 -466
  175. package/lib/responsesParse.ts +0 -452
  176. package/lib/responsesTools.ts +0 -28
  177. package/lib/runtimeContext.ts +0 -146
  178. package/lib/runtimePorts.ts +0 -105
  179. package/lib/sessionStore.ts +0 -308
  180. package/lib/storageMigration.ts +0 -310
  181. package/lib/styleSheet.ts +0 -139
  182. package/lib/systemTrash.ts +0 -20
  183. package/lib/videoContinuity.ts +0 -180
  184. package/lib/videoFrameExtract.ts +0 -78
  185. package/lib/videoSeriesChain.ts +0 -29
  186. package/lib/visibleTextLanguagePolicy.ts +0 -7
  187. package/routes/agent.ts +0 -308
  188. package/routes/annotations.ts +0 -118
  189. package/routes/canvasVersions.ts +0 -69
  190. package/routes/capabilities.ts +0 -18
  191. package/routes/cardNews.ts +0 -211
  192. package/routes/comfy.ts +0 -43
  193. package/routes/edit.ts +0 -352
  194. package/routes/generate.ts +0 -492
  195. package/routes/grok.ts +0 -24
  196. package/routes/health.ts +0 -123
  197. package/routes/history.ts +0 -221
  198. package/routes/imageImport.ts +0 -37
  199. package/routes/index.ts +0 -52
  200. package/routes/metadata.ts +0 -77
  201. package/routes/multimode.ts +0 -499
  202. package/routes/nodes.ts +0 -578
  203. package/routes/promptBuilder.ts +0 -37
  204. package/routes/promptImport.ts +0 -379
  205. package/routes/prompts.ts +0 -428
  206. package/routes/quota.ts +0 -89
  207. package/routes/sessions.ts +0 -317
  208. package/routes/storage.ts +0 -47
  209. package/routes/video.ts +0 -300
  210. package/routes/videoExtended.ts +0 -284
  211. package/server.ts +0 -293
  212. package/ui/dist/assets/SettingsWorkspace-PiaVnsdA.js +0 -1
  213. package/ui/dist/assets/index-CjgnNtgt.css +0 -1
  214. package/ui/dist/assets/index-Da2s4_-5.js +0 -36
@@ -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
- }