dsh-plugin-image-workbench 0.0.0-stage → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.en.md +258 -0
- package/README.md +260 -2
- package/client.js +241 -0
- package/cordis.patch.yml +14 -0
- package/host.js +692 -0
- package/install.mjs +333 -0
- package/package.json +58 -4
- package/scripts/fetch-style-images.mjs +104 -0
- package/scripts/vendor-snapshot.py +154 -0
- package/server/access.py +26 -0
- package/server/app.py +1329 -0
- package/server/catalog.json +1 -0
- package/server/catalog.py +147 -0
- package/server/composer.py +391 -0
- package/server/drafts.py +158 -0
- package/server/history.py +575 -0
- package/server/imaging.py +172 -0
- package/server/pool.py +1335 -0
- package/server/pool_admin.py +921 -0
- package/server/pool_service.py +1073 -0
- package/server/requirements.txt +6 -0
- package/server/smoke_check.py +402 -0
- package/server/static/access.html +202 -0
- package/server/static/index.html +4725 -0
- package/vendor/chatgpt2api/README.md +13 -0
- package/vendor/chatgpt2api/SOURCE.json +11 -0
- package/vendor/chatgpt2api/runtime/uv.exe +0 -0
- package/vendor/chatgpt2api/source/.env.example +82 -0
- package/vendor/chatgpt2api/source/.python-version +1 -0
- package/vendor/chatgpt2api/source/LICENSE +21 -0
- package/vendor/chatgpt2api/source/README.md +391 -0
- package/vendor/chatgpt2api/source/VERSION +1 -0
- package/vendor/chatgpt2api/source/api/__init__.py +2 -0
- package/vendor/chatgpt2api/source/api/accounts.py +537 -0
- package/vendor/chatgpt2api/source/api/ai.py +217 -0
- package/vendor/chatgpt2api/source/api/app.py +62 -0
- package/vendor/chatgpt2api/source/api/errors.py +46 -0
- package/vendor/chatgpt2api/source/api/image_inputs.py +309 -0
- package/vendor/chatgpt2api/source/api/image_tasks.py +120 -0
- package/vendor/chatgpt2api/source/api/support.py +134 -0
- package/vendor/chatgpt2api/source/api/system.py +365 -0
- package/vendor/chatgpt2api/source/assets/atlascloud.svg +1 -0
- package/vendor/chatgpt2api/source/assets/ipwo.png +0 -0
- package/vendor/chatgpt2api/source/assets/kunrouai.svg +50 -0
- package/vendor/chatgpt2api/source/config.default.json +108 -0
- package/vendor/chatgpt2api/source/main.py +9 -0
- package/vendor/chatgpt2api/source/pyproject.toml +27 -0
- package/vendor/chatgpt2api/source/scripts/init_proxy_config.py +186 -0
- package/vendor/chatgpt2api/source/scripts/migrate_storage.py +163 -0
- package/vendor/chatgpt2api/source/scripts/privoxy-warp.conf +13 -0
- package/vendor/chatgpt2api/source/scripts/test_outlook_token_mailbox.py +385 -0
- package/vendor/chatgpt2api/source/scripts/test_storage.py +129 -0
- package/vendor/chatgpt2api/source/scripts/verify_oauth_refresh.py +92 -0
- package/vendor/chatgpt2api/source/services/__init__.py +0 -0
- package/vendor/chatgpt2api/source/services/account_service.py +1757 -0
- package/vendor/chatgpt2api/source/services/auth_service.py +253 -0
- package/vendor/chatgpt2api/source/services/backup_service.py +671 -0
- package/vendor/chatgpt2api/source/services/config.py +667 -0
- package/vendor/chatgpt2api/source/services/content_filter.py +242 -0
- package/vendor/chatgpt2api/source/services/cpa_service.py +315 -0
- package/vendor/chatgpt2api/source/services/editable_file_task_service.py +260 -0
- package/vendor/chatgpt2api/source/services/image_service.py +376 -0
- package/vendor/chatgpt2api/source/services/image_storage_service.py +405 -0
- package/vendor/chatgpt2api/source/services/image_tags_service.py +76 -0
- package/vendor/chatgpt2api/source/services/image_task_service.py +550 -0
- package/vendor/chatgpt2api/source/services/log_service.py +337 -0
- package/vendor/chatgpt2api/source/services/model_service.py +182 -0
- package/vendor/chatgpt2api/source/services/oauth_login_service.py +267 -0
- package/vendor/chatgpt2api/source/services/openai_backend_api.py +2763 -0
- package/vendor/chatgpt2api/source/services/openai_oauth.py +32 -0
- package/vendor/chatgpt2api/source/services/protocol/__init__.py +2 -0
- package/vendor/chatgpt2api/source/services/protocol/anthropic_v1_messages.py +307 -0
- package/vendor/chatgpt2api/source/services/protocol/chat_completion_cache.py +238 -0
- package/vendor/chatgpt2api/source/services/protocol/conversation.py +1644 -0
- package/vendor/chatgpt2api/source/services/protocol/error_response.py +124 -0
- package/vendor/chatgpt2api/source/services/protocol/openai_search.py +19 -0
- package/vendor/chatgpt2api/source/services/protocol/openai_v1_chat_complete.py +316 -0
- package/vendor/chatgpt2api/source/services/protocol/openai_v1_image_edit.py +86 -0
- package/vendor/chatgpt2api/source/services/protocol/openai_v1_image_generations.py +42 -0
- package/vendor/chatgpt2api/source/services/protocol/openai_v1_models.py +53 -0
- package/vendor/chatgpt2api/source/services/protocol/openai_v1_response.py +453 -0
- package/vendor/chatgpt2api/source/services/protocol/web_search_tool.py +160 -0
- package/vendor/chatgpt2api/source/services/proxy_service.py +648 -0
- package/vendor/chatgpt2api/source/services/storage/__init__.py +5 -0
- package/vendor/chatgpt2api/source/services/storage/base.py +38 -0
- package/vendor/chatgpt2api/source/services/storage/database_storage.py +194 -0
- package/vendor/chatgpt2api/source/services/storage/factory.py +104 -0
- package/vendor/chatgpt2api/source/services/storage/git_storage.py +183 -0
- package/vendor/chatgpt2api/source/services/storage/json_storage.py +95 -0
- package/vendor/chatgpt2api/source/services/sub2api_service.py +531 -0
- package/vendor/chatgpt2api/source/utils/__init__.py +0 -0
- package/vendor/chatgpt2api/source/utils/helper.py +469 -0
- package/vendor/chatgpt2api/source/utils/image_tokens.py +346 -0
- package/vendor/chatgpt2api/source/utils/log.py +110 -0
- package/vendor/chatgpt2api/source/utils/pkce.py +19 -0
- package/vendor/chatgpt2api/source/utils/pow.py +207 -0
- package/vendor/chatgpt2api/source/utils/sentinel.py +159 -0
- package/vendor/chatgpt2api/source/utils/turnstile.py +184 -0
- package/vendor/chatgpt2api/source/uv.lock +904 -0
- package/vendor/chatgpt2api/source/web/bun.lock +1501 -0
- package/vendor/chatgpt2api/source/web/components.json +24 -0
- package/vendor/chatgpt2api/source/web/eslint.config.mjs +17 -0
- package/vendor/chatgpt2api/source/web/next.config.ts +40 -0
- package/vendor/chatgpt2api/source/web/package.json +58 -0
- package/vendor/chatgpt2api/source/web/postcss.config.mjs +5 -0
- package/vendor/chatgpt2api/source/web/public/github.svg +1 -0
- package/vendor/chatgpt2api/source/web/public/next.svg +1 -0
- package/vendor/chatgpt2api/source/web/public/openai.svg +1 -0
- package/vendor/chatgpt2api/source/web/public/vercel.svg +1 -0
- package/vendor/chatgpt2api/source/web/src/app/accounts/components/account-import-dialog.tsx +925 -0
- package/vendor/chatgpt2api/source/web/src/app/accounts/page.tsx +1307 -0
- package/vendor/chatgpt2api/source/web/src/app/debug/components/chat-panel.tsx +224 -0
- package/vendor/chatgpt2api/source/web/src/app/debug/components/editable-file-panel.tsx +444 -0
- package/vendor/chatgpt2api/source/web/src/app/debug/components/ppt-panel.tsx +9 -0
- package/vendor/chatgpt2api/source/web/src/app/debug/components/psd-panel.tsx +9 -0
- package/vendor/chatgpt2api/source/web/src/app/debug/components/search-panel.tsx +172 -0
- package/vendor/chatgpt2api/source/web/src/app/debug/components/skill-panel.tsx +169 -0
- package/vendor/chatgpt2api/source/web/src/app/debug/components/types.ts +39 -0
- package/vendor/chatgpt2api/source/web/src/app/debug/page.tsx +59 -0
- package/vendor/chatgpt2api/source/web/src/app/favicon.ico +0 -0
- package/vendor/chatgpt2api/source/web/src/app/globals.css +231 -0
- package/vendor/chatgpt2api/source/web/src/app/image/components/image-composer.tsx +542 -0
- package/vendor/chatgpt2api/source/web/src/app/image/components/image-results.tsx +554 -0
- package/vendor/chatgpt2api/source/web/src/app/image/components/image-sidebar.tsx +176 -0
- package/vendor/chatgpt2api/source/web/src/app/image/page.tsx +1799 -0
- package/vendor/chatgpt2api/source/web/src/app/image-manager/page.tsx +732 -0
- package/vendor/chatgpt2api/source/web/src/app/layout.tsx +50 -0
- package/vendor/chatgpt2api/source/web/src/app/login/page.tsx +101 -0
- package/vendor/chatgpt2api/source/web/src/app/logs/page.tsx +356 -0
- package/vendor/chatgpt2api/source/web/src/app/page.tsx +30 -0
- package/vendor/chatgpt2api/source/web/src/app/settings/components/api-docs-card.tsx +341 -0
- package/vendor/chatgpt2api/source/web/src/app/settings/components/backup-settings-card.tsx +447 -0
- package/vendor/chatgpt2api/source/web/src/app/settings/components/base-url-card.tsx +71 -0
- package/vendor/chatgpt2api/source/web/src/app/settings/components/config-card.tsx +491 -0
- package/vendor/chatgpt2api/source/web/src/app/settings/components/cpa-pool-dialog.tsx +108 -0
- package/vendor/chatgpt2api/source/web/src/app/settings/components/cpa-pools-card.tsx +169 -0
- package/vendor/chatgpt2api/source/web/src/app/settings/components/import-browser-dialog.tsx +185 -0
- package/vendor/chatgpt2api/source/web/src/app/settings/components/proxy-runtime-card.tsx +379 -0
- package/vendor/chatgpt2api/source/web/src/app/settings/components/proxy-settings-card.tsx +127 -0
- package/vendor/chatgpt2api/source/web/src/app/settings/components/proxy-settings.tsx +200 -0
- package/vendor/chatgpt2api/source/web/src/app/settings/components/settings-header.tsx +12 -0
- package/vendor/chatgpt2api/source/web/src/app/settings/components/sub2api-connections.tsx +886 -0
- package/vendor/chatgpt2api/source/web/src/app/settings/components/third-party-apps-card.tsx +81 -0
- package/vendor/chatgpt2api/source/web/src/app/settings/components/user-keys-card.tsx +422 -0
- package/vendor/chatgpt2api/source/web/src/app/settings/page.tsx +135 -0
- package/vendor/chatgpt2api/source/web/src/app/settings/store.ts +1069 -0
- package/vendor/chatgpt2api/source/web/src/components/date-range-filter.tsx +49 -0
- package/vendor/chatgpt2api/source/web/src/components/header-actions.tsx +24 -0
- package/vendor/chatgpt2api/source/web/src/components/image-lightbox.tsx +434 -0
- package/vendor/chatgpt2api/source/web/src/components/image-thumbnail.tsx +46 -0
- package/vendor/chatgpt2api/source/web/src/components/theme-script.tsx +18 -0
- package/vendor/chatgpt2api/source/web/src/components/theme-toggle.tsx +14 -0
- package/vendor/chatgpt2api/source/web/src/components/top-nav.tsx +263 -0
- package/vendor/chatgpt2api/source/web/src/components/ui/animated-theme-toggler.tsx +256 -0
- package/vendor/chatgpt2api/source/web/src/components/ui/badge.tsx +41 -0
- package/vendor/chatgpt2api/source/web/src/components/ui/button.tsx +59 -0
- package/vendor/chatgpt2api/source/web/src/components/ui/calendar.tsx +46 -0
- package/vendor/chatgpt2api/source/web/src/components/ui/card.tsx +61 -0
- package/vendor/chatgpt2api/source/web/src/components/ui/checkbox.tsx +27 -0
- package/vendor/chatgpt2api/source/web/src/components/ui/dia-text-reveal.tsx +267 -0
- package/vendor/chatgpt2api/source/web/src/components/ui/dialog.tsx +132 -0
- package/vendor/chatgpt2api/source/web/src/components/ui/field.tsx +13 -0
- package/vendor/chatgpt2api/source/web/src/components/ui/input.tsx +19 -0
- package/vendor/chatgpt2api/source/web/src/components/ui/label.tsx +24 -0
- package/vendor/chatgpt2api/source/web/src/components/ui/morphing-text.tsx +149 -0
- package/vendor/chatgpt2api/source/web/src/components/ui/popover.tsx +38 -0
- package/vendor/chatgpt2api/source/web/src/components/ui/select.tsx +175 -0
- package/vendor/chatgpt2api/source/web/src/components/ui/sheet.tsx +143 -0
- package/vendor/chatgpt2api/source/web/src/components/ui/table.tsx +29 -0
- package/vendor/chatgpt2api/source/web/src/components/ui/tabs.tsx +91 -0
- package/vendor/chatgpt2api/source/web/src/components/ui/text-3d-flip.tsx +269 -0
- package/vendor/chatgpt2api/source/web/src/components/ui/textarea.tsx +18 -0
- package/vendor/chatgpt2api/source/web/src/components/version-release-dialog.tsx +127 -0
- package/vendor/chatgpt2api/source/web/src/constants/common-env.ts +6 -0
- package/vendor/chatgpt2api/source/web/src/hooks/use-version-check.ts +85 -0
- package/vendor/chatgpt2api/source/web/src/lib/api.ts +926 -0
- package/vendor/chatgpt2api/source/web/src/lib/auth-session.ts +26 -0
- package/vendor/chatgpt2api/source/web/src/lib/release.ts +25 -0
- package/vendor/chatgpt2api/source/web/src/lib/request.ts +93 -0
- package/vendor/chatgpt2api/source/web/src/lib/use-auth-guard.ts +89 -0
- package/vendor/chatgpt2api/source/web/src/lib/utils.ts +6 -0
- package/vendor/chatgpt2api/source/web/src/store/auth.ts +112 -0
- package/vendor/chatgpt2api/source/web/src/store/editable-file-history.ts +33 -0
- package/vendor/chatgpt2api/source/web/src/store/image-conversations.ts +318 -0
- package/vendor/chatgpt2api/source/web/tsconfig.json +42 -0
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import localforage from "localforage";
|
|
4
|
+
|
|
5
|
+
import type { ImageModel } from "@/lib/api";
|
|
6
|
+
|
|
7
|
+
export type ImageConversationMode = "generate" | "edit";
|
|
8
|
+
|
|
9
|
+
export type StoredReferenceImage = {
|
|
10
|
+
name: string;
|
|
11
|
+
type: string;
|
|
12
|
+
dataUrl: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type StoredImage = {
|
|
16
|
+
id: string;
|
|
17
|
+
taskId?: string;
|
|
18
|
+
status?: "loading" | "success" | "error";
|
|
19
|
+
taskStatus?: "queued" | "running";
|
|
20
|
+
progress?: string;
|
|
21
|
+
b64_json?: string;
|
|
22
|
+
url?: string;
|
|
23
|
+
revised_prompt?: string;
|
|
24
|
+
error?: string;
|
|
25
|
+
startTime?: number;
|
|
26
|
+
elapsedSecs?: number;
|
|
27
|
+
elapsedUpdatedAt?: number;
|
|
28
|
+
durationMs?: number;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type ImageTurnStatus = "queued" | "generating" | "success" | "error";
|
|
32
|
+
|
|
33
|
+
export type ImageTurn = {
|
|
34
|
+
id: string;
|
|
35
|
+
prompt: string;
|
|
36
|
+
model: ImageModel;
|
|
37
|
+
mode: ImageConversationMode;
|
|
38
|
+
referenceImages: StoredReferenceImage[];
|
|
39
|
+
count: number;
|
|
40
|
+
size: string;
|
|
41
|
+
ratio: string;
|
|
42
|
+
tier: string;
|
|
43
|
+
quality: string;
|
|
44
|
+
images: StoredImage[];
|
|
45
|
+
createdAt: string;
|
|
46
|
+
status: ImageTurnStatus;
|
|
47
|
+
error?: string;
|
|
48
|
+
promptDeleted?: boolean;
|
|
49
|
+
resultsDeleted?: boolean;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type ImageConversation = {
|
|
53
|
+
id: string;
|
|
54
|
+
title: string;
|
|
55
|
+
createdAt: string;
|
|
56
|
+
updatedAt: string;
|
|
57
|
+
turns: ImageTurn[];
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type ImageConversationStats = {
|
|
61
|
+
queued: number;
|
|
62
|
+
running: number;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const imageConversationStorage = localforage.createInstance({
|
|
66
|
+
name: "chatgpt2api",
|
|
67
|
+
storeName: "image_conversations",
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const IMAGE_CONVERSATIONS_KEY = "items";
|
|
71
|
+
let imageConversationWriteQueue: Promise<void> = Promise.resolve();
|
|
72
|
+
|
|
73
|
+
function normalizeStoredImage(image: StoredImage): StoredImage {
|
|
74
|
+
const normalized = {
|
|
75
|
+
...image,
|
|
76
|
+
taskId: typeof image.taskId === "string" && image.taskId ? image.taskId : undefined,
|
|
77
|
+
taskStatus: image.taskStatus === "queued" || image.taskStatus === "running" ? image.taskStatus : undefined,
|
|
78
|
+
url: typeof image.url === "string" && image.url ? image.url : undefined,
|
|
79
|
+
revised_prompt: typeof image.revised_prompt === "string" ? image.revised_prompt : undefined,
|
|
80
|
+
startTime: typeof image.startTime === "number" ? image.startTime : undefined,
|
|
81
|
+
elapsedSecs: typeof image.elapsedSecs === "number" ? image.elapsedSecs : undefined,
|
|
82
|
+
elapsedUpdatedAt: typeof image.elapsedUpdatedAt === "number" ? image.elapsedUpdatedAt : undefined,
|
|
83
|
+
durationMs: typeof image.durationMs === "number" ? image.durationMs : undefined,
|
|
84
|
+
};
|
|
85
|
+
if (image.status === "loading" || image.status === "error" || image.status === "success") {
|
|
86
|
+
return normalized;
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
...normalized,
|
|
90
|
+
status: image.b64_json || image.url ? "success" : "loading",
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function normalizeReferenceImage(image: StoredReferenceImage): StoredReferenceImage {
|
|
95
|
+
return {
|
|
96
|
+
name: image.name || "reference.png",
|
|
97
|
+
type: image.type || "image/png",
|
|
98
|
+
dataUrl: image.dataUrl,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function dataUrlMimeType(dataUrl: string) {
|
|
103
|
+
const match = dataUrl.match(/^data:(.*?);base64,/);
|
|
104
|
+
return match?.[1] || "image/png";
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function getLegacyReferenceImages(source: Record<string, unknown>): StoredReferenceImage[] {
|
|
108
|
+
if (Array.isArray(source.referenceImages)) {
|
|
109
|
+
return source.referenceImages
|
|
110
|
+
.filter((image): image is StoredReferenceImage => {
|
|
111
|
+
if (!image || typeof image !== "object") {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
const candidate = image as StoredReferenceImage;
|
|
115
|
+
return typeof candidate.dataUrl === "string" && candidate.dataUrl.length > 0;
|
|
116
|
+
})
|
|
117
|
+
.map(normalizeReferenceImage);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (source.sourceImage && typeof source.sourceImage === "object") {
|
|
121
|
+
const image = source.sourceImage as { dataUrl?: unknown; fileName?: unknown };
|
|
122
|
+
if (typeof image.dataUrl === "string" && image.dataUrl) {
|
|
123
|
+
return [
|
|
124
|
+
{
|
|
125
|
+
name: typeof image.fileName === "string" && image.fileName ? image.fileName : "reference.png",
|
|
126
|
+
type: dataUrlMimeType(image.dataUrl),
|
|
127
|
+
dataUrl: image.dataUrl,
|
|
128
|
+
},
|
|
129
|
+
];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return [];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function normalizeTurn(turn: ImageTurn & Record<string, unknown>): ImageTurn {
|
|
137
|
+
const normalizedImages = Array.isArray(turn.images) ? turn.images.map(normalizeStoredImage) : [];
|
|
138
|
+
const derivedStatus: ImageTurnStatus =
|
|
139
|
+
normalizedImages.some((image) => image.status === "loading")
|
|
140
|
+
? "generating"
|
|
141
|
+
: normalizedImages.some((image) => image.status === "error")
|
|
142
|
+
? "error"
|
|
143
|
+
: "success";
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
id: String(turn.id || `${Date.now()}`),
|
|
147
|
+
prompt: String(turn.prompt || ""),
|
|
148
|
+
model: (turn.model as ImageModel) || "gpt-image-2",
|
|
149
|
+
mode: turn.mode === "edit" ? "edit" : "generate",
|
|
150
|
+
referenceImages: getLegacyReferenceImages(turn),
|
|
151
|
+
count: Math.max(1, Number(turn.count || normalizedImages.length || 1)),
|
|
152
|
+
size: typeof turn.size === "string" ? turn.size : "",
|
|
153
|
+
ratio: typeof turn.ratio === "string" && turn.ratio ? turn.ratio : "1:1",
|
|
154
|
+
tier: typeof turn.tier === "string" && turn.tier ? turn.tier : "1k",
|
|
155
|
+
quality: typeof turn.quality === "string" && turn.quality ? turn.quality : "auto",
|
|
156
|
+
images: normalizedImages,
|
|
157
|
+
createdAt: String(turn.createdAt || new Date().toISOString()),
|
|
158
|
+
status:
|
|
159
|
+
turn.status === "queued" ||
|
|
160
|
+
turn.status === "generating" ||
|
|
161
|
+
turn.status === "success" ||
|
|
162
|
+
turn.status === "error"
|
|
163
|
+
? turn.status
|
|
164
|
+
: derivedStatus,
|
|
165
|
+
error: typeof turn.error === "string" ? turn.error : undefined,
|
|
166
|
+
promptDeleted: turn.promptDeleted === true,
|
|
167
|
+
resultsDeleted: turn.resultsDeleted === true,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function normalizeConversation(conversation: ImageConversation & Record<string, unknown>): ImageConversation {
|
|
172
|
+
const turns = Array.isArray(conversation.turns)
|
|
173
|
+
? conversation.turns.map((turn) => normalizeTurn(turn as ImageTurn & Record<string, unknown>))
|
|
174
|
+
: [
|
|
175
|
+
normalizeTurn({
|
|
176
|
+
id: String(conversation.id || `${Date.now()}`),
|
|
177
|
+
prompt: String(conversation.prompt || ""),
|
|
178
|
+
model: (conversation.model as ImageModel) || "gpt-image-2",
|
|
179
|
+
mode: conversation.mode === "edit" ? "edit" : "generate",
|
|
180
|
+
referenceImages: getLegacyReferenceImages(conversation),
|
|
181
|
+
count: Number(conversation.count || 1),
|
|
182
|
+
size: typeof conversation.size === "string" ? conversation.size : "",
|
|
183
|
+
ratio: typeof conversation.ratio === "string" && conversation.ratio ? conversation.ratio : "1:1",
|
|
184
|
+
tier: typeof conversation.tier === "string" && conversation.tier ? conversation.tier : "1k",
|
|
185
|
+
quality: typeof conversation.quality === "string" && conversation.quality ? conversation.quality : "auto",
|
|
186
|
+
images: Array.isArray(conversation.images) ? (conversation.images as StoredImage[]) : [],
|
|
187
|
+
createdAt: String(conversation.createdAt || new Date().toISOString()),
|
|
188
|
+
status:
|
|
189
|
+
conversation.status === "generating" || conversation.status === "success" || conversation.status === "error"
|
|
190
|
+
? conversation.status
|
|
191
|
+
: "success",
|
|
192
|
+
error: typeof conversation.error === "string" ? conversation.error : undefined,
|
|
193
|
+
}),
|
|
194
|
+
];
|
|
195
|
+
const lastTurn = turns.length > 0 ? turns[turns.length - 1] : null;
|
|
196
|
+
|
|
197
|
+
return {
|
|
198
|
+
id: String(conversation.id || `${Date.now()}`),
|
|
199
|
+
title: String(conversation.title || ""),
|
|
200
|
+
createdAt: String(conversation.createdAt || lastTurn?.createdAt || new Date().toISOString()),
|
|
201
|
+
updatedAt: String(conversation.updatedAt || lastTurn?.createdAt || new Date().toISOString()),
|
|
202
|
+
turns,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function sortImageConversations(conversations: ImageConversation[]): ImageConversation[] {
|
|
207
|
+
return [...conversations].sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function getTimestamp(value: string) {
|
|
211
|
+
const time = new Date(value).getTime();
|
|
212
|
+
return Number.isFinite(time) ? time : 0;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function pickLatestConversation(current: ImageConversation, next: ImageConversation) {
|
|
216
|
+
return getTimestamp(next.updatedAt) >= getTimestamp(current.updatedAt) ? next : current;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function queueImageConversationWrite<T>(operation: () => Promise<T>): Promise<T> {
|
|
220
|
+
const result = imageConversationWriteQueue.then(operation);
|
|
221
|
+
imageConversationWriteQueue = result.then(
|
|
222
|
+
() => undefined,
|
|
223
|
+
() => undefined,
|
|
224
|
+
);
|
|
225
|
+
return result;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async function readStoredImageConversations(): Promise<ImageConversation[]> {
|
|
229
|
+
const items =
|
|
230
|
+
(await imageConversationStorage.getItem<Array<ImageConversation & Record<string, unknown>>>(
|
|
231
|
+
IMAGE_CONVERSATIONS_KEY,
|
|
232
|
+
)) || [];
|
|
233
|
+
return items.map(normalizeConversation);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export async function listImageConversations(): Promise<ImageConversation[]> {
|
|
237
|
+
return sortImageConversations(await readStoredImageConversations());
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export async function saveImageConversations(conversations: ImageConversation[]): Promise<void> {
|
|
241
|
+
await queueImageConversationWrite(async () => {
|
|
242
|
+
const items = await readStoredImageConversations();
|
|
243
|
+
const conversationMap = new Map(items.map((item) => [item.id, item]));
|
|
244
|
+
for (const conversation of conversations.map(normalizeConversation)) {
|
|
245
|
+
const current = conversationMap.get(conversation.id);
|
|
246
|
+
conversationMap.set(conversation.id, current ? pickLatestConversation(current, conversation) : conversation);
|
|
247
|
+
}
|
|
248
|
+
await imageConversationStorage.setItem(
|
|
249
|
+
IMAGE_CONVERSATIONS_KEY,
|
|
250
|
+
sortImageConversations([...conversationMap.values()]),
|
|
251
|
+
);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export async function saveImageConversation(conversation: ImageConversation): Promise<void> {
|
|
256
|
+
await queueImageConversationWrite(async () => {
|
|
257
|
+
const items = await readStoredImageConversations();
|
|
258
|
+
const nextConversation = normalizeConversation(conversation);
|
|
259
|
+
const current = items.find((item) => item.id === nextConversation.id);
|
|
260
|
+
const persistedConversation = current ? pickLatestConversation(current, nextConversation) : nextConversation;
|
|
261
|
+
const nextItems = sortImageConversations([
|
|
262
|
+
persistedConversation,
|
|
263
|
+
...items.filter((item) => item.id !== persistedConversation.id),
|
|
264
|
+
]);
|
|
265
|
+
await imageConversationStorage.setItem(IMAGE_CONVERSATIONS_KEY, nextItems);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export async function renameImageConversation(id: string, title: string): Promise<void> {
|
|
270
|
+
await queueImageConversationWrite(async () => {
|
|
271
|
+
const items = await readStoredImageConversations();
|
|
272
|
+
const target = items.find((item) => item.id === id);
|
|
273
|
+
if (!target) return;
|
|
274
|
+
const updated = { ...target, title, updatedAt: new Date().toISOString() };
|
|
275
|
+
const nextItems = sortImageConversations([
|
|
276
|
+
updated,
|
|
277
|
+
...items.filter((item) => item.id !== id),
|
|
278
|
+
]);
|
|
279
|
+
await imageConversationStorage.setItem(IMAGE_CONVERSATIONS_KEY, nextItems);
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export async function deleteImageConversation(id: string): Promise<void> {
|
|
284
|
+
await queueImageConversationWrite(async () => {
|
|
285
|
+
const items = await readStoredImageConversations();
|
|
286
|
+
await imageConversationStorage.setItem(
|
|
287
|
+
IMAGE_CONVERSATIONS_KEY,
|
|
288
|
+
items.filter((item) => item.id !== id),
|
|
289
|
+
);
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export async function clearImageConversations(): Promise<void> {
|
|
294
|
+
await queueImageConversationWrite(async () => {
|
|
295
|
+
await imageConversationStorage.removeItem(IMAGE_CONVERSATIONS_KEY);
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export function getImageConversationStats(conversation: ImageConversation | null): ImageConversationStats {
|
|
300
|
+
if (!conversation) {
|
|
301
|
+
return { queued: 0, running: 0 };
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return conversation.turns.reduce(
|
|
305
|
+
(acc, turn) => {
|
|
306
|
+
if (turn.resultsDeleted) {
|
|
307
|
+
return acc;
|
|
308
|
+
}
|
|
309
|
+
if (turn.status === "queued") {
|
|
310
|
+
acc.queued += 1;
|
|
311
|
+
} else if (turn.status === "generating") {
|
|
312
|
+
acc.running += 1;
|
|
313
|
+
}
|
|
314
|
+
return acc;
|
|
315
|
+
},
|
|
316
|
+
{ queued: 0, running: 0 },
|
|
317
|
+
);
|
|
318
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2017",
|
|
4
|
+
"lib": [
|
|
5
|
+
"dom",
|
|
6
|
+
"dom.iterable",
|
|
7
|
+
"esnext"
|
|
8
|
+
],
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"strict": true,
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
"esModuleInterop": true,
|
|
14
|
+
"module": "esnext",
|
|
15
|
+
"moduleResolution": "bundler",
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"isolatedModules": true,
|
|
18
|
+
"jsx": "react-jsx",
|
|
19
|
+
"incremental": true,
|
|
20
|
+
"plugins": [
|
|
21
|
+
{
|
|
22
|
+
"name": "next"
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"paths": {
|
|
26
|
+
"@/*": [
|
|
27
|
+
"./src/*"
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"include": [
|
|
32
|
+
"next-env.d.ts",
|
|
33
|
+
"next.config.ts",
|
|
34
|
+
"src/**/*.ts",
|
|
35
|
+
"src/**/*.tsx",
|
|
36
|
+
".next/types/**/*.ts",
|
|
37
|
+
".next/dev/types/**/*.ts"
|
|
38
|
+
],
|
|
39
|
+
"exclude": [
|
|
40
|
+
"node_modules"
|
|
41
|
+
]
|
|
42
|
+
}
|