ima2-gen 1.1.21 → 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.
- package/README.md +30 -4
- package/bin/ima2.js +14 -4
- package/bin/lib/platform.js +34 -5
- package/docs/README.ko.md +31 -0
- package/lib/agentQueueWorker.js +6 -0
- package/lib/agentRuntime.js +3 -2
- package/lib/atomicWrite.js +14 -0
- package/lib/grokProxyLauncher.js +5 -3
- package/lib/inflight.js +1 -1
- package/lib/oauthLauncher.js +5 -0
- package/lib/videoFrameExtract.js +3 -3
- package/package.json +5 -7
- package/routes/edit.js +2 -1
- package/routes/generate.js +4 -3
- package/routes/health.js +4 -3
- package/routes/multimode.js +2 -1
- package/routes/video.js +4 -2
- package/server.js +29 -2
- package/ui/dist/.vite/manifest.json +12 -12
- package/ui/dist/assets/{AgentWorkspace-B_hq9CLg.js → AgentWorkspace-COxQ5TjU.js} +1 -1
- package/ui/dist/assets/{CardNewsWorkspace-wD12J7qk.js → CardNewsWorkspace-B0OkcuVz.js} +1 -1
- package/ui/dist/assets/{NodeCanvas-CI_wuPMf.js → NodeCanvas-BSsclEBh.js} +1 -1
- package/ui/dist/assets/{PromptBuilderPanel-CUTujJUV.js → PromptBuilderPanel-DpC9A5Rz.js} +1 -1
- package/ui/dist/assets/{PromptImportDialog-CUi66jPK.js → PromptImportDialog-CVwT0rLd.js} +2 -2
- package/ui/dist/assets/{PromptImportDiscoverySection-Cm3vrjY4.js → PromptImportDiscoverySection-BDCkRCRs.js} +1 -1
- package/ui/dist/assets/{PromptImportFolderSection-DOtWTD9n.js → PromptImportFolderSection-QoKbZD83.js} +1 -1
- package/ui/dist/assets/{PromptLibraryPanel-BMjQegRa.js → PromptLibraryPanel-BhFgeKnY.js} +2 -2
- package/ui/dist/assets/SettingsWorkspace-CfjrlH5R.js +1 -0
- package/ui/dist/assets/index-C-mur7pa.css +1 -0
- package/ui/dist/assets/index-CCP5nUOj.js +42 -0
- package/ui/dist/assets/{index-31uVIdt4.js → index-Cxhzi3bs.js} +1 -1
- package/ui/dist/index.html +2 -2
- package/bin/commands/annotate.ts +0 -119
- package/bin/commands/cancel.ts +0 -48
- package/bin/commands/canvas-versions.ts +0 -80
- package/bin/commands/capabilities.ts +0 -110
- package/bin/commands/cardnews.ts +0 -249
- package/bin/commands/comfy.ts +0 -54
- package/bin/commands/config.ts +0 -186
- package/bin/commands/defaults.ts +0 -192
- package/bin/commands/doctor.ts +0 -202
- package/bin/commands/edit.ts +0 -150
- package/bin/commands/gen.ts +0 -214
- package/bin/commands/grok.ts +0 -90
- package/bin/commands/history.ts +0 -146
- package/bin/commands/ls.ts +0 -64
- package/bin/commands/metadata.ts +0 -39
- package/bin/commands/multimode.ts +0 -196
- package/bin/commands/node.ts +0 -166
- package/bin/commands/observability.ts +0 -176
- package/bin/commands/ping.ts +0 -31
- package/bin/commands/prompt-sub/build.ts +0 -101
- package/bin/commands/prompt.ts +0 -492
- package/bin/commands/ps.ts +0 -81
- package/bin/commands/session.ts +0 -266
- package/bin/commands/show.ts +0 -72
- package/bin/commands/skill.ts +0 -70
- package/bin/commands/video.ts +0 -442
- package/bin/ima2.ts +0 -430
- package/bin/lib/args.ts +0 -92
- package/bin/lib/browser-id.ts +0 -16
- package/bin/lib/client.ts +0 -122
- package/bin/lib/config-store.ts +0 -120
- package/bin/lib/destructive-confirm.ts +0 -19
- package/bin/lib/doctor-checks.ts +0 -91
- package/bin/lib/error-hints.ts +0 -23
- package/bin/lib/files.ts +0 -39
- package/bin/lib/output.ts +0 -73
- package/bin/lib/platform.ts +0 -99
- package/bin/lib/recover-output.ts +0 -139
- package/bin/lib/sse.ts +0 -73
- package/bin/lib/star-prompt.ts +0 -97
- package/bin/lib/storage-doctor.ts +0 -39
- package/bin/lib/ui-build.ts +0 -85
- package/config.ts +0 -354
- package/lib/agentCommandParser.ts +0 -69
- package/lib/agentGenerationPlanner.ts +0 -273
- package/lib/agentQuestionResponder.ts +0 -266
- package/lib/agentQueueStore.ts +0 -270
- package/lib/agentQueueWorker.ts +0 -89
- package/lib/agentRuntime.ts +0 -604
- package/lib/agentSettings.ts +0 -72
- package/lib/agentStore.ts +0 -422
- package/lib/agentStoreRows.ts +0 -136
- package/lib/agentTypes.ts +0 -154
- package/lib/apiCachePolicy.ts +0 -11
- package/lib/assetLifecycle.ts +0 -146
- package/lib/canvasVersionStore.ts +0 -223
- package/lib/capabilities.ts +0 -126
- package/lib/cardNewsGenerator.ts +0 -271
- package/lib/cardNewsJobStore.ts +0 -142
- package/lib/cardNewsManifestStore.ts +0 -154
- package/lib/cardNewsPlanner.ts +0 -236
- package/lib/cardNewsPlannerClient.ts +0 -155
- package/lib/cardNewsPlannerPrompt.ts +0 -62
- package/lib/cardNewsPlannerSchema.ts +0 -321
- package/lib/cardNewsRoleTemplateStore.ts +0 -47
- package/lib/cardNewsTemplateStore.ts +0 -252
- package/lib/codexDetect.ts +0 -71
- package/lib/comfyBridge.ts +0 -235
- package/lib/composerSnapshot.ts +0 -33
- package/lib/configKeys.ts +0 -62
- package/lib/db.ts +0 -295
- package/lib/errInfo.ts +0 -43
- package/lib/errorClassify.ts +0 -100
- package/lib/generationCancel.ts +0 -28
- package/lib/generationErrors.ts +0 -238
- package/lib/grokImageAdapter.ts +0 -513
- package/lib/grokMultimodeAdapter.ts +0 -84
- package/lib/grokProxyLauncher.ts +0 -153
- package/lib/grokRuntime.ts +0 -23
- package/lib/grokSizeMapper.ts +0 -71
- package/lib/grokVideoAdapter.ts +0 -458
- package/lib/grokVideoCanvas.ts +0 -26
- package/lib/grokVideoDownload.ts +0 -59
- package/lib/grokVideoPlannerPrompt.ts +0 -67
- package/lib/historyIndex.ts +0 -51
- package/lib/historyList.ts +0 -181
- package/lib/imageMetadata.ts +0 -113
- package/lib/imageMetadataStore.ts +0 -67
- package/lib/imageModels.ts +0 -165
- package/lib/inflight.ts +0 -281
- package/lib/localImportStore.ts +0 -114
- package/lib/logger.ts +0 -161
- package/lib/nodeStore.ts +0 -91
- package/lib/oauthLauncher.ts +0 -94
- package/lib/oauthNormalize.ts +0 -30
- package/lib/oauthProxy/errors.ts +0 -128
- package/lib/oauthProxy/generators.ts +0 -494
- package/lib/oauthProxy/index.ts +0 -28
- package/lib/oauthProxy/prompts.ts +0 -123
- package/lib/oauthProxy/references.ts +0 -45
- package/lib/oauthProxy/runtime.ts +0 -115
- package/lib/oauthProxy/streams.ts +0 -232
- package/lib/oauthProxy/types.ts +0 -9
- package/lib/oauthProxy.ts +0 -3
- package/lib/openDirectory.ts +0 -47
- package/lib/pngInfo.ts +0 -26
- package/lib/promptBuilder/attachments.ts +0 -74
- package/lib/promptBuilder/client.ts +0 -130
- package/lib/promptBuilder/constants.ts +0 -9
- package/lib/promptBuilder/context.ts +0 -36
- package/lib/promptBuilder/errors.ts +0 -12
- package/lib/promptBuilder/requestSchema.ts +0 -56
- package/lib/promptBuilder/responseParser.ts +0 -219
- package/lib/promptBuilder/systemPrompt.ts +0 -135
- package/lib/promptBuilder/transport.ts +0 -94
- package/lib/promptBuilder/types.ts +0 -109
- package/lib/promptImport/curatedSources.ts +0 -141
- package/lib/promptImport/discoveryRegistry.ts +0 -329
- package/lib/promptImport/errors.ts +0 -18
- package/lib/promptImport/githubDiscovery.ts +0 -309
- package/lib/promptImport/githubFolder.ts +0 -397
- package/lib/promptImport/githubSource.ts +0 -257
- package/lib/promptImport/gptImageHints.ts +0 -70
- package/lib/promptImport/parsePromptCandidates.ts +0 -179
- package/lib/promptImport/promptIndex.ts +0 -326
- package/lib/promptImport/rankPromptCandidates.ts +0 -65
- package/lib/promptImport/types.ts +0 -103
- package/lib/promptSafetyPolicy.ts +0 -5
- package/lib/providerOptions.ts +0 -56
- package/lib/referenceImageCompress.ts +0 -84
- package/lib/refs.ts +0 -133
- package/lib/requestLogger.ts +0 -49
- package/lib/responsesDoctor.ts +0 -456
- package/lib/responsesErrors.ts +0 -83
- package/lib/responsesFallback.ts +0 -114
- package/lib/responsesImageAdapter.ts +0 -466
- package/lib/responsesParse.ts +0 -452
- package/lib/responsesTools.ts +0 -28
- package/lib/runtimeContext.ts +0 -146
- package/lib/runtimePorts.ts +0 -105
- package/lib/sessionStore.ts +0 -308
- package/lib/storageMigration.ts +0 -310
- package/lib/styleSheet.ts +0 -139
- package/lib/systemTrash.ts +0 -20
- package/lib/videoContinuity.ts +0 -180
- package/lib/videoFrameExtract.ts +0 -78
- package/lib/videoSeriesChain.ts +0 -29
- package/lib/visibleTextLanguagePolicy.ts +0 -7
- package/routes/agent.ts +0 -308
- package/routes/annotations.ts +0 -118
- package/routes/canvasVersions.ts +0 -69
- package/routes/capabilities.ts +0 -18
- package/routes/cardNews.ts +0 -211
- package/routes/comfy.ts +0 -43
- package/routes/edit.ts +0 -352
- package/routes/generate.ts +0 -492
- package/routes/grok.ts +0 -24
- package/routes/health.ts +0 -123
- package/routes/history.ts +0 -221
- package/routes/imageImport.ts +0 -37
- package/routes/index.ts +0 -52
- package/routes/metadata.ts +0 -77
- package/routes/multimode.ts +0 -499
- package/routes/nodes.ts +0 -578
- package/routes/promptBuilder.ts +0 -37
- package/routes/promptImport.ts +0 -379
- package/routes/prompts.ts +0 -428
- package/routes/quota.ts +0 -89
- package/routes/sessions.ts +0 -317
- package/routes/storage.ts +0 -47
- package/routes/video.ts +0 -300
- package/routes/videoExtended.ts +0 -284
- package/server.ts +0 -293
- package/ui/dist/assets/SettingsWorkspace-PiaVnsdA.js +0 -1
- package/ui/dist/assets/index-CjgnNtgt.css +0 -1
- 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
|
-
}
|