dsh-plugin-image-workbench 0.0.0-stage → 1.1.5
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 +256 -0
- package/README.md +256 -2
- package/client.js +241 -0
- package/cordis.patch.yml +14 -0
- package/host.js +641 -0
- package/install.mjs +387 -0
- package/package.json +57 -4
- 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,9 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { EditableFilePanel } from "./editable-file-panel";
|
|
4
|
+
|
|
5
|
+
const defaultPrompt = "需要制作一份《2026年Q2 电商运营工作汇报》PPT,用于公司管理层季度会议汇报,整体页数控制在 8 页以内,风格偏商务科技感。重点体现销售增长、用户增长、广告投放效果以及618活动成果,并通过折线图、柱状图、环形图、漏斗图呈现。";
|
|
6
|
+
|
|
7
|
+
export function PptPanel() {
|
|
8
|
+
return <EditableFilePanel title="PPT生成" kind="ppt" endpoint="/v1/ppt/generations" defaultPrompt={defaultPrompt} />;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { EditableFilePanel } from "./editable-file-panel";
|
|
4
|
+
|
|
5
|
+
const defaultPrompt = "按原图位置拆分海报元素并合成可编辑 PSD,保留背景和每个元素图层位置,同时输出每个图层素材 zip。";
|
|
6
|
+
|
|
7
|
+
export function PsdPanel() {
|
|
8
|
+
return <EditableFilePanel title="PSD生成" kind="psd" endpoint="/v1/psd/generations" defaultPrompt={defaultPrompt} imageRequired />;
|
|
9
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { ExternalLink, Globe2, LoaderCircle, Search } from "lucide-react";
|
|
5
|
+
import ReactMarkdown from "react-markdown";
|
|
6
|
+
import remarkGfm from "remark-gfm";
|
|
7
|
+
|
|
8
|
+
import { httpRequest } from "@/lib/request";
|
|
9
|
+
import { cn } from "@/lib/utils";
|
|
10
|
+
|
|
11
|
+
import type { SearchResult } from "./types";
|
|
12
|
+
|
|
13
|
+
const normalizeMarkdown = (text: string) =>
|
|
14
|
+
text
|
|
15
|
+
.replace(/\ue200url\ue202([^\ue202\ue201]*)\ue202([^\ue201]*)\ue201/g, "[$1]($2)")
|
|
16
|
+
.replace(/\ue200cite\ue202[^\ue201]*\ue201/g, "")
|
|
17
|
+
.replace(/\ue200[^\ue201]*\ue201/g, "")
|
|
18
|
+
.replace(/\ue200[^\ue201]*$/g, "")
|
|
19
|
+
.replace(/\n{3,}/g, "\n\n")
|
|
20
|
+
.trim();
|
|
21
|
+
|
|
22
|
+
const cleanUrl = (url: string) => url.replace(/[\ue200-\ue202].*$/g, "").trim();
|
|
23
|
+
|
|
24
|
+
const sourceKind = (url: string) => {
|
|
25
|
+
const host = (() => {
|
|
26
|
+
try {
|
|
27
|
+
return new URL(url).hostname;
|
|
28
|
+
} catch {
|
|
29
|
+
return "";
|
|
30
|
+
}
|
|
31
|
+
})();
|
|
32
|
+
return host.includes("github.com") ? "github" : "web";
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function MarkdownResult({ content }: { content: string }) {
|
|
36
|
+
return (
|
|
37
|
+
<ReactMarkdown
|
|
38
|
+
remarkPlugins={[remarkGfm]}
|
|
39
|
+
components={{
|
|
40
|
+
a: ({ className, ...props }) => <a className={cn("font-medium text-blue-700 underline decoration-blue-300 underline-offset-4 hover:text-blue-900 dark:text-blue-300 dark:decoration-blue-700", className)} target="_blank" rel="noreferrer" {...props} />,
|
|
41
|
+
h1: ({ className, ...props }) => <h1 className={cn("mt-8 mb-4 text-2xl font-semibold tracking-tight text-stone-950 first:mt-0 dark:text-stone-50", className)} {...props} />,
|
|
42
|
+
h2: ({ className, ...props }) => <h2 className={cn("mt-8 mb-4 border-b border-stone-200 pb-2 text-xl font-semibold tracking-tight text-stone-950 first:mt-0 dark:border-white/10 dark:text-stone-50", className)} {...props} />,
|
|
43
|
+
h3: ({ className, ...props }) => <h3 className={cn("mt-6 mb-3 text-lg font-semibold text-stone-900 dark:text-stone-100", className)} {...props} />,
|
|
44
|
+
p: ({ className, ...props }) => <p className={cn("my-4 leading-8 text-stone-800 dark:text-stone-200", className)} {...props} />,
|
|
45
|
+
ul: ({ className, ...props }) => <ul className={cn("my-4 list-disc space-y-2 pl-6 leading-7 text-stone-800 dark:text-stone-200", className)} {...props} />,
|
|
46
|
+
ol: ({ className, ...props }) => <ol className={cn("my-4 list-decimal space-y-2 pl-6 leading-7 text-stone-800 dark:text-stone-200", className)} {...props} />,
|
|
47
|
+
blockquote: ({ className, ...props }) => <blockquote className={cn("my-5 border-l-4 border-stone-300 bg-white/70 py-3 pr-4 pl-5 text-stone-700 dark:border-white/20 dark:bg-white/[0.04] dark:text-stone-300", className)} {...props} />,
|
|
48
|
+
code: ({ className, ...props }) => <code className={cn("rounded bg-stone-100 px-1.5 py-0.5 font-mono text-[0.9em] text-stone-800 dark:bg-white/10 dark:text-stone-100", className)} {...props} />,
|
|
49
|
+
pre: ({ className, ...props }) => <pre className={cn("my-5 overflow-x-auto rounded-xl border border-stone-200 bg-stone-950 p-4 text-sm text-stone-50 dark:border-white/10", className)} {...props} />,
|
|
50
|
+
table: ({ className, ...props }) => <div className="my-5 overflow-x-auto rounded-xl border border-stone-200 dark:border-white/10"><table className={cn("w-full border-collapse text-sm", className)} {...props} /></div>,
|
|
51
|
+
th: ({ className, ...props }) => <th className={cn("border-b border-stone-200 bg-stone-100 px-3 py-2 text-left font-semibold dark:border-white/10 dark:bg-white/10", className)} {...props} />,
|
|
52
|
+
td: ({ className, ...props }) => <td className={cn("border-b border-stone-100 px-3 py-2 align-top dark:border-white/10", className)} {...props} />,
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
{content}
|
|
56
|
+
</ReactMarkdown>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function SearchPanel() {
|
|
61
|
+
const [prompt, setPrompt] = useState("帮我搜索 chatgpt2api 相关项目");
|
|
62
|
+
const [result, setResult] = useState<SearchResult | null>(null);
|
|
63
|
+
const [loading, setLoading] = useState(false);
|
|
64
|
+
const [error, setError] = useState("");
|
|
65
|
+
const [elapsedMs, setElapsedMs] = useState(0);
|
|
66
|
+
const [startedAt, setStartedAt] = useState(0);
|
|
67
|
+
const searched = loading || !!result || !!error;
|
|
68
|
+
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (!loading || !startedAt) return;
|
|
71
|
+
const timer = window.setInterval(() => setElapsedMs(Date.now() - startedAt), 100);
|
|
72
|
+
return () => window.clearInterval(timer);
|
|
73
|
+
}, [loading, startedAt]);
|
|
74
|
+
|
|
75
|
+
const runSearch = async () => {
|
|
76
|
+
const value = prompt.trim();
|
|
77
|
+
if (!value || loading) return;
|
|
78
|
+
const start = Date.now();
|
|
79
|
+
setStartedAt(start);
|
|
80
|
+
setElapsedMs(0);
|
|
81
|
+
setLoading(true);
|
|
82
|
+
setError("");
|
|
83
|
+
setResult(null);
|
|
84
|
+
try {
|
|
85
|
+
setResult(await httpRequest<SearchResult>("/v1/search", { method: "POST", body: { prompt: value } }));
|
|
86
|
+
} catch (err) {
|
|
87
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
88
|
+
} finally {
|
|
89
|
+
setElapsedMs(Date.now() - start);
|
|
90
|
+
setLoading(false);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<section className={cn("mx-auto flex min-h-[calc(100vh-142px)] w-full max-w-6xl flex-col px-4 transition-all", searched ? "py-5" : "justify-center")}>
|
|
96
|
+
<div className={cn("mx-auto w-full max-w-3xl", searched && "sticky top-3 z-10")}>
|
|
97
|
+
{!searched ? (
|
|
98
|
+
<p className="mb-5 text-center text-sm text-stone-500 dark:text-stone-400">利用ChatGPT先进的网页搜索功能进行搜索</p>
|
|
99
|
+
) : null}
|
|
100
|
+
<form
|
|
101
|
+
className={cn("mx-auto flex w-full items-center gap-3 rounded-full border border-stone-200 bg-white/95 backdrop-blur transition-all dark:border-white/10 dark:bg-stone-950/90", searched ? "px-4 py-2" : "px-5 py-3")}
|
|
102
|
+
onSubmit={(event) => {
|
|
103
|
+
event.preventDefault();
|
|
104
|
+
void runSearch();
|
|
105
|
+
}}
|
|
106
|
+
>
|
|
107
|
+
<img src="/openai.svg" alt="" aria-hidden="true" className="size-5 shrink-0 opacity-80 dark:invert" />
|
|
108
|
+
<input
|
|
109
|
+
value={prompt}
|
|
110
|
+
onChange={(event) => setPrompt(event.target.value)}
|
|
111
|
+
placeholder="搜索网页"
|
|
112
|
+
className={cn("min-w-0 flex-1 bg-transparent text-[15px] text-stone-900 outline-none placeholder:text-stone-400 dark:text-stone-100 dark:placeholder:text-stone-500", searched ? "h-8" : "h-10")}
|
|
113
|
+
/>
|
|
114
|
+
<button type="submit" disabled={loading || !prompt.trim()} className="inline-flex size-8 shrink-0 items-center justify-center rounded-full text-stone-800 transition hover:bg-stone-100 disabled:cursor-not-allowed disabled:text-stone-300 dark:text-stone-100 dark:hover:bg-white/10 dark:disabled:text-stone-600">
|
|
115
|
+
{loading ? <LoaderCircle className="size-4 animate-spin" /> : <Search className="size-4" />}
|
|
116
|
+
</button>
|
|
117
|
+
</form>
|
|
118
|
+
</div>
|
|
119
|
+
|
|
120
|
+
{searched ? <div className="mx-auto w-full max-w-6xl flex-1 pt-6">
|
|
121
|
+
{loading ? (
|
|
122
|
+
<div className="mx-auto flex max-w-3xl items-center gap-3 rounded-2xl border border-stone-200 bg-white/75 px-4 py-3 text-sm text-stone-600 dark:border-white/10 dark:bg-white/[0.03] dark:text-stone-300">
|
|
123
|
+
<LoaderCircle className="size-4 animate-spin" />
|
|
124
|
+
搜索中... {(elapsedMs / 1000).toFixed(1)}s
|
|
125
|
+
</div>
|
|
126
|
+
) : null}
|
|
127
|
+
|
|
128
|
+
{error ? <div className="rounded-2xl border border-rose-200 bg-rose-50 px-4 py-3 text-sm text-rose-700 dark:border-rose-900/60 dark:bg-rose-950/25 dark:text-rose-300">{error}</div> : null}
|
|
129
|
+
|
|
130
|
+
{result ? (
|
|
131
|
+
<article className="grid gap-8 pb-12 lg:grid-cols-[minmax(0,1fr)_320px]">
|
|
132
|
+
<div className="min-w-0">
|
|
133
|
+
<div className="mb-5 flex flex-wrap items-center gap-2 text-xs text-stone-500 dark:text-stone-400">
|
|
134
|
+
<span className="rounded-full border border-stone-200 bg-white px-3 py-1 dark:border-white/10 dark:bg-white/[0.03]">{result.status || "done"}</span>
|
|
135
|
+
<span className="rounded-full border border-stone-200 bg-white px-3 py-1 dark:border-white/10 dark:bg-white/[0.03]">{(elapsedMs / 1000).toFixed(2)}s</span>
|
|
136
|
+
<span className="rounded-full border border-stone-200 bg-white px-3 py-1 dark:border-white/10 dark:bg-white/[0.03]">{result.sources?.length || 0} sources</span>
|
|
137
|
+
</div>
|
|
138
|
+
<div className="text-[15px]">
|
|
139
|
+
<MarkdownResult content={normalizeMarkdown(result.answer || "")} />
|
|
140
|
+
</div>
|
|
141
|
+
</div>
|
|
142
|
+
{result.sources?.length ? (
|
|
143
|
+
<aside className="lg:sticky lg:top-24 lg:self-start">
|
|
144
|
+
<div className="mb-3 text-sm font-semibold text-stone-900 dark:text-stone-100">来源</div>
|
|
145
|
+
<div className="divide-y divide-stone-200 dark:divide-white/10">
|
|
146
|
+
{result.sources.map((source, index) => {
|
|
147
|
+
const url = cleanUrl(source.url || "");
|
|
148
|
+
const kind = sourceKind(url);
|
|
149
|
+
return (
|
|
150
|
+
<a key={`${url || index}`} href={url} target="_blank" rel="noreferrer" className="flex gap-3 py-3 text-xs transition hover:text-stone-950 dark:hover:text-stone-50">
|
|
151
|
+
<span className="mt-0.5 flex size-5 shrink-0 items-center justify-center text-stone-600 dark:text-stone-300">
|
|
152
|
+
{kind === "github" ? <img src="/github.svg" alt="" aria-hidden="true" className="size-3.5 dark:invert" /> : <Globe2 className="size-3.5" />}
|
|
153
|
+
</span>
|
|
154
|
+
<span className="min-w-0">
|
|
155
|
+
<span className="line-clamp-2 font-medium leading-5 text-stone-800 dark:text-stone-200">{source.title || url || "source"}</span>
|
|
156
|
+
<span className="mt-1 flex items-center gap-1 truncate text-stone-500 dark:text-stone-400">
|
|
157
|
+
<ExternalLink className="size-3 shrink-0" />
|
|
158
|
+
{url}
|
|
159
|
+
</span>
|
|
160
|
+
</span>
|
|
161
|
+
</a>
|
|
162
|
+
);
|
|
163
|
+
})}
|
|
164
|
+
</div>
|
|
165
|
+
</aside>
|
|
166
|
+
) : null}
|
|
167
|
+
</article>
|
|
168
|
+
) : null}
|
|
169
|
+
</div> : null}
|
|
170
|
+
</section>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useMemo, useState } from "react";
|
|
4
|
+
import { Copy, Download } from "lucide-react";
|
|
5
|
+
import { toast } from "sonner";
|
|
6
|
+
|
|
7
|
+
import { Button } from "@/components/ui/button";
|
|
8
|
+
import webConfig from "@/constants/common-env";
|
|
9
|
+
import { fetchSettingsConfig } from "@/lib/api";
|
|
10
|
+
import { getStoredAuthSession } from "@/store/auth";
|
|
11
|
+
|
|
12
|
+
export function SkillPanel() {
|
|
13
|
+
const [browserBaseUrl, setBrowserBaseUrl] = useState("");
|
|
14
|
+
const [configuredBaseUrl, setConfiguredBaseUrl] = useState("");
|
|
15
|
+
const [authKey, setAuthKey] = useState("");
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
setBrowserBaseUrl(window.location.origin);
|
|
19
|
+
void fetchSettingsConfig().then((data) => setConfiguredBaseUrl(String(data.config.base_url || "").replace(/\/$/, ""))).catch(() => undefined);
|
|
20
|
+
void getStoredAuthSession().then((session) => setAuthKey(session?.key || ""));
|
|
21
|
+
}, []);
|
|
22
|
+
|
|
23
|
+
const apiBaseUrl = configuredBaseUrl || webConfig.apiUrl.replace(/\/$/, "") || browserBaseUrl;
|
|
24
|
+
const skillZh = useMemo(() => `---
|
|
25
|
+
name: chatgpt2api-search
|
|
26
|
+
description: 当用户需要联网搜索、查询最新信息、核实事实或需要来源链接时,调用本地 chatgpt2api 搜索接口。
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
# ChatGPT2API 搜索
|
|
30
|
+
|
|
31
|
+
当用户要求联网搜索、查询最新信息、核实资料、查新闻、查价格、查文档更新或需要来源链接时,使用这个 skill。
|
|
32
|
+
|
|
33
|
+
## 接口
|
|
34
|
+
|
|
35
|
+
POST ${apiBaseUrl}/v1/search
|
|
36
|
+
|
|
37
|
+
Headers:
|
|
38
|
+
|
|
39
|
+
Authorization: Bearer ${authKey}
|
|
40
|
+
Content-Type: application/json
|
|
41
|
+
|
|
42
|
+
Body:
|
|
43
|
+
|
|
44
|
+
{
|
|
45
|
+
"prompt": "<用户要搜索的问题>"
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
## 返回处理
|
|
49
|
+
|
|
50
|
+
- 使用接口返回的 \`answer\` 作为主要回答。
|
|
51
|
+
- 如果有 \`sources\`,在回答里附上来源链接。
|
|
52
|
+
- 如果接口报错,简要说明错误并询问是否重试。`, [apiBaseUrl, authKey]);
|
|
53
|
+
|
|
54
|
+
const skillEn = useMemo(() => `---
|
|
55
|
+
name: chatgpt2api-search
|
|
56
|
+
description: Use when current web search is needed through this chatgpt2api server. Call the configured HTTP search endpoint with a prompt and return the answer with source URLs.
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
# ChatGPT2API Search
|
|
60
|
+
|
|
61
|
+
Use this skill when the user asks for current web search, online lookup, recent information, or source-backed answers. It calls the local chatgpt2api search endpoint and returns an answer with source links.
|
|
62
|
+
|
|
63
|
+
## When to use
|
|
64
|
+
|
|
65
|
+
- The user asks to search the web, look something up, verify current information, or find the latest status.
|
|
66
|
+
- The answer needs source URLs, recent details, prices, releases, docs, laws, schedules, or news.
|
|
67
|
+
- Do not use it for purely local codebase questions unless the user explicitly asks for web search.
|
|
68
|
+
|
|
69
|
+
## Request
|
|
70
|
+
|
|
71
|
+
POST ${apiBaseUrl}/v1/search
|
|
72
|
+
|
|
73
|
+
Headers:
|
|
74
|
+
|
|
75
|
+
Authorization: Bearer ${authKey}
|
|
76
|
+
Content-Type: application/json
|
|
77
|
+
|
|
78
|
+
JSON body:
|
|
79
|
+
|
|
80
|
+
{
|
|
81
|
+
"prompt": "<search question>"
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
## Response handling
|
|
85
|
+
|
|
86
|
+
- Use \`answer\` as the main response.
|
|
87
|
+
- Include source URLs from \`sources\` when available.
|
|
88
|
+
- If the endpoint returns an error, summarize the error and ask the user whether to retry.
|
|
89
|
+
- Keep the final answer concise unless the user asks for detail.`, [apiBaseUrl, authKey]);
|
|
90
|
+
|
|
91
|
+
const zhPrompt = useMemo(() => `请帮我在本机安装一个用于联网搜索的 skill。
|
|
92
|
+
|
|
93
|
+
要求:
|
|
94
|
+
1. 请按你当前环境的 skill 安装规范,把它安装成本地 skill。
|
|
95
|
+
2. skill 名称为:chatgpt2api-search
|
|
96
|
+
3. 文件名为:SKILL.md
|
|
97
|
+
4. 如果你无法确定本地 skills 目录在哪里,先告诉我需要放到哪个目录,不要猜路径。
|
|
98
|
+
5. 只创建或更新这个 skill 文件,不要修改其他无关文件。
|
|
99
|
+
6. SKILL.md 请写入下面的完整内容。
|
|
100
|
+
|
|
101
|
+
SKILL.md 内容:
|
|
102
|
+
|
|
103
|
+
\`\`\`markdown
|
|
104
|
+
${skillZh}
|
|
105
|
+
\`\`\``, [skillZh]);
|
|
106
|
+
|
|
107
|
+
const enPrompt = useMemo(() => `Please install a local web-search skill on this machine.
|
|
108
|
+
|
|
109
|
+
Requirements:
|
|
110
|
+
1. Install this as a local skill according to the skill installation rules of your current environment.
|
|
111
|
+
2. Skill name: chatgpt2api-search
|
|
112
|
+
3. File name: SKILL.md
|
|
113
|
+
4. If you cannot determine the local skills directory, tell me which directory is required before writing files.
|
|
114
|
+
5. Only create or update this skill file. Do not modify unrelated files.
|
|
115
|
+
6. Write the full content below into SKILL.md.
|
|
116
|
+
|
|
117
|
+
SKILL.md content:
|
|
118
|
+
|
|
119
|
+
\`\`\`markdown
|
|
120
|
+
${skillEn}
|
|
121
|
+
\`\`\``, [skillEn]);
|
|
122
|
+
|
|
123
|
+
const copyText = async (text: string) => {
|
|
124
|
+
await navigator.clipboard.writeText(text);
|
|
125
|
+
toast.success("已复制");
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const downloadSkill = (text: string) => {
|
|
129
|
+
const url = URL.createObjectURL(new Blob([text], { type: "text/markdown;charset=utf-8" }));
|
|
130
|
+
const link = document.createElement("a");
|
|
131
|
+
link.href = url;
|
|
132
|
+
link.download = "SKILL.md";
|
|
133
|
+
link.click();
|
|
134
|
+
URL.revokeObjectURL(url);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const versions = [
|
|
138
|
+
{ title: "中文安装指令", desc: "复制后直接发给 Codex 或 Claude,让它安装到本地。", prompt: zhPrompt, skill: skillZh },
|
|
139
|
+
{ title: "English install prompt", desc: "Copy and send this to Codex or Claude to install locally.", prompt: enPrompt, skill: skillEn },
|
|
140
|
+
];
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<section className="grid items-stretch gap-4 lg:grid-cols-2">
|
|
144
|
+
{versions.map((item) => (
|
|
145
|
+
<div key={item.title} className="flex flex-col overflow-hidden rounded-lg border border-slate-200 bg-white shadow-sm dark:border-white/10 dark:bg-white/[0.04]">
|
|
146
|
+
<div className="flex items-center justify-between gap-3 border-b border-slate-200/70 bg-slate-50/80 p-4 dark:border-white/10 dark:bg-white/[0.03]">
|
|
147
|
+
<div>
|
|
148
|
+
<h2 className="font-medium text-slate-900 dark:text-slate-100">{item.title}</h2>
|
|
149
|
+
<p className="mt-1 text-sm text-slate-500 dark:text-slate-400">{item.desc}</p>
|
|
150
|
+
</div>
|
|
151
|
+
<div className="flex gap-2">
|
|
152
|
+
<Button size="sm" variant="outline" className="cursor-pointer" onClick={() => downloadSkill(item.skill)}>
|
|
153
|
+
<Download />
|
|
154
|
+
下载
|
|
155
|
+
</Button>
|
|
156
|
+
<Button size="sm" className="cursor-pointer" onClick={() => void copyText(item.prompt)}>
|
|
157
|
+
<Copy />
|
|
158
|
+
复制
|
|
159
|
+
</Button>
|
|
160
|
+
</div>
|
|
161
|
+
</div>
|
|
162
|
+
<pre className="flex-1 whitespace-pre-wrap p-4 font-mono text-sm leading-6">
|
|
163
|
+
{item.prompt}
|
|
164
|
+
</pre>
|
|
165
|
+
</div>
|
|
166
|
+
))}
|
|
167
|
+
</section>
|
|
168
|
+
);
|
|
169
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export type SearchResult = {
|
|
2
|
+
conversation_id: string;
|
|
3
|
+
status: string;
|
|
4
|
+
answer: string;
|
|
5
|
+
sources: Array<{ title?: string; url?: string; snippet?: string; source_type?: string }>;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type ChatMessage = {
|
|
9
|
+
role: "system" | "user" | "assistant";
|
|
10
|
+
content: string | ChatContentPart[];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type ChatContentPart =
|
|
14
|
+
| { type: "text"; text: string }
|
|
15
|
+
| { type: "image_url"; image_url: { url: string } };
|
|
16
|
+
|
|
17
|
+
export type ChatCompletionResponse = {
|
|
18
|
+
choices?: Array<{ message?: { role?: string; content?: string } }>;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type EditableFileTask = {
|
|
22
|
+
id: string;
|
|
23
|
+
taskId?: string;
|
|
24
|
+
status: "queued" | "running" | "success" | "error" | string;
|
|
25
|
+
kind: "ppt" | "psd" | string;
|
|
26
|
+
created_at?: string;
|
|
27
|
+
updated_at?: string;
|
|
28
|
+
elapsed_seconds?: number;
|
|
29
|
+
polled_at?: number;
|
|
30
|
+
prompt_preview?: string;
|
|
31
|
+
error?: string;
|
|
32
|
+
result?: {
|
|
33
|
+
conversation_id?: string;
|
|
34
|
+
primary_url?: string;
|
|
35
|
+
zip_url?: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const pretty = (value: unknown) => JSON.stringify(value, null, 2);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { LoaderCircle } from "lucide-react";
|
|
4
|
+
|
|
5
|
+
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
|
6
|
+
import { useAuthGuard } from "@/lib/use-auth-guard";
|
|
7
|
+
|
|
8
|
+
import { ChatPanel } from "./components/chat-panel";
|
|
9
|
+
import { PptPanel } from "./components/ppt-panel";
|
|
10
|
+
import { PsdPanel } from "./components/psd-panel";
|
|
11
|
+
import { SearchPanel } from "./components/search-panel";
|
|
12
|
+
import { SkillPanel } from "./components/skill-panel";
|
|
13
|
+
|
|
14
|
+
const tabs = [
|
|
15
|
+
{ value: "skills", title: "搜索Skills" },
|
|
16
|
+
{ value: "search", title: "搜索" },
|
|
17
|
+
{ value: "ppt", title: "PPT生成" },
|
|
18
|
+
{ value: "psd", title: "PSD生成" },
|
|
19
|
+
{ value: "chat", title: "对话" },
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
export default function DebugPage() {
|
|
23
|
+
const { isCheckingAuth, session } = useAuthGuard(["admin"]);
|
|
24
|
+
|
|
25
|
+
if (isCheckingAuth || !session || session.role !== "admin") {
|
|
26
|
+
return (
|
|
27
|
+
<div className="flex min-h-[calc(100vh-49px)] items-center justify-center">
|
|
28
|
+
<LoaderCircle className="size-5 animate-spin text-muted-foreground" />
|
|
29
|
+
</div>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<Tabs defaultValue="skills" className="mx-auto flex min-h-[calc(100vh-49px)] w-full max-w-[1600px] flex-col gap-4 px-4 pt-3 pb-6 md:px-8">
|
|
35
|
+
<TabsList variant="line" className="w-full">
|
|
36
|
+
{tabs.map(({ value, title }) => (
|
|
37
|
+
<TabsTrigger key={value} value={value}>
|
|
38
|
+
{title}
|
|
39
|
+
</TabsTrigger>
|
|
40
|
+
))}
|
|
41
|
+
</TabsList>
|
|
42
|
+
<TabsContent value="skills">
|
|
43
|
+
<SkillPanel />
|
|
44
|
+
</TabsContent>
|
|
45
|
+
<TabsContent value="search" className="min-h-0">
|
|
46
|
+
<SearchPanel />
|
|
47
|
+
</TabsContent>
|
|
48
|
+
<TabsContent value="ppt" className="min-h-0">
|
|
49
|
+
<PptPanel />
|
|
50
|
+
</TabsContent>
|
|
51
|
+
<TabsContent value="psd" className="min-h-0">
|
|
52
|
+
<PsdPanel />
|
|
53
|
+
</TabsContent>
|
|
54
|
+
<TabsContent value="chat" className="min-h-0">
|
|
55
|
+
<ChatPanel />
|
|
56
|
+
</TabsContent>
|
|
57
|
+
</Tabs>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
Binary file
|