@aiti-ai/aiti-feedback 0.0.0-stage → 0.1.1
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/AGENTS.md +17 -0
- package/LICENSE +21 -0
- package/README.md +15 -2
- package/README.zh-CN.md +13 -0
- package/client/src/entry.tsx +25 -0
- package/client/src/feedback-app.tsx +161 -0
- package/client/src/feedback-build.ts +134 -0
- package/client/src/host-shim.ts +104 -0
- package/client/src/jsx-runtime.ts +2 -0
- package/client/tests/feedback-build.test.mjs +86 -0
- package/dist/aiti-feedback-client.mjs +295 -0
- package/icons/discussion.svg +1 -0
- package/icons/message-circle.svg +1 -0
- package/icons/message-square-text.svg +1 -0
- package/index.ts +110 -0
- package/package.json +30 -4
- package/tools/build-client.mjs +36 -0
- package/tools/deploy.mjs +63 -0
- package/vite.config.ts +41 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# aiti-feedback 扩展(部署目录直改指南)
|
|
2
|
+
|
|
3
|
+
## 形态
|
|
4
|
+
- 纯客户端扩展:toolbar「报告问题」按钮 → 弹窗(表单 + 脱敏预览)→ GitHub 预填 issue
|
|
5
|
+
- 无服务端 API、无数据目录、零 token——用户自己登录 GitHub 提交
|
|
6
|
+
- 方案:pi-work `docs/aiti-feedback-plan.md`
|
|
7
|
+
|
|
8
|
+
## 小改现场流程
|
|
9
|
+
1. 改 `src/`(client/src)
|
|
10
|
+
2. `node tools/build-client.mjs`(client 有构建产物)
|
|
11
|
+
3. `curl -X POST http://127.0.0.1:3001/api/extensions/reload`(dev 3001 / prod 3002;外部经 nginx 带 basePath)
|
|
12
|
+
4. 刷新页面验证
|
|
13
|
+
|
|
14
|
+
## 红线
|
|
15
|
+
- 禁手改 dist/(构建产物)
|
|
16
|
+
- 脱敏规则表在 `client/src/feedback-build.ts`(REDACT_RULES),改前跑 `client/tests/feedback-build.test.mjs`
|
|
17
|
+
- **图标必须是 24×24 lucide 线条风**(stroke=currentColor):宿主 `embedUiSvgIcons` 只取 svg 内部 path、用自己的 svg 根(16px、fill=none)重渲染——fill 实心型(如 GitHub octicon)的根属性被丢弃,16px 下必然糊
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 aiti-ai contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
#
|
|
1
|
+
# aiti-feedback
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Report an issue / send feedback from the pi-web UI: compose a sanitized report
|
|
4
|
+
in a dialog, preview the final markdown, then open a **prefilled GitHub issue** —
|
|
5
|
+
you log into GitHub yourself and just hit Submit. Zero tokens, zero server.
|
|
6
|
+
|
|
7
|
+
## Privacy model
|
|
8
|
+
|
|
9
|
+
- The dialog preview IS the final content (best-effort redaction applied:
|
|
10
|
+
internal domains/IPs/repo names/paths and common token shapes → placeholders).
|
|
11
|
+
- Environment info (UA/platform/language/page path, query stripped) is opt-in.
|
|
12
|
+
- Session content is never auto-read; there is an opt-in paste box.
|
|
13
|
+
- The full text always lands in your clipboard as a fallback when GitHub
|
|
14
|
+
truncates the prefilled body.
|
|
15
|
+
|
|
16
|
+
Plan: internal `aiti-feedback-plan.md` (pi-work docs).
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# aiti-feedback — 用户反馈扩展
|
|
2
|
+
|
|
3
|
+
从 pi-web 界面直接报告问题:弹窗里填写表单、实时预览(已脱敏)的最终内容,
|
|
4
|
+
一键打开**预填好的 GitHub issue**——用户自己登录 GitHub 点提交即可。
|
|
5
|
+
零 token、零服务端。
|
|
6
|
+
|
|
7
|
+
## 隐私模型
|
|
8
|
+
- 弹窗预览 = 最终提交内容(best-effort 脱敏:内部域名/内网 IP/内部仓名/路径/常见 token 形态 → 占位符)
|
|
9
|
+
- 环境信息(UA/平台/语言/页面路径,query 剥离)默认勾选、可关闭
|
|
10
|
+
- 会话内容**永不自动读取**;提供自愿粘贴框(同样脱敏)
|
|
11
|
+
- GitHub 预填超长时自动截断,全文始终写入剪贴板兜底
|
|
12
|
+
|
|
13
|
+
方案:内部 `aiti-feedback-plan.md`(pi-work docs)。
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* aiti-feedback · client entry.
|
|
3
|
+
*
|
|
4
|
+
* register(ctx) wires:
|
|
5
|
+
* - toolbar button ("Report an issue") → opens the compose dialog
|
|
6
|
+
* - dialogs slot: the compose dialog (module-level state controls visibility)
|
|
7
|
+
*
|
|
8
|
+
* Build: node tools/build-client.mjs Deploy: node tools/deploy.mjs
|
|
9
|
+
*/
|
|
10
|
+
import { __setCtx } from "./host-shim";
|
|
11
|
+
import { FeedbackDialog, openFeedback } from "./feedback-app";
|
|
12
|
+
|
|
13
|
+
export default function register(ctx: Record<string, any>) {
|
|
14
|
+
__setCtx(ctx);
|
|
15
|
+
ctx.registerItems("toolbar", [{
|
|
16
|
+
id: "aiti-feedback-open",
|
|
17
|
+
meta: {
|
|
18
|
+
label: "i18n:fb.open.label",
|
|
19
|
+
title: "i18n:fb.open.title",
|
|
20
|
+
icon: "icons/message-circle.svg",
|
|
21
|
+
onClick: () => openFeedback(),
|
|
22
|
+
},
|
|
23
|
+
}]);
|
|
24
|
+
ctx.registerItems("dialogs", [{ id: "aiti-feedback-dialog", render: FeedbackDialog }]);
|
|
25
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* aiti-feedback client — compose → preview → open prefilled GitHub issue.
|
|
3
|
+
*
|
|
4
|
+
* The dialog preview IS the final content (redaction applied, user-confirmed
|
|
5
|
+
* before redirect). Full text always goes to the clipboard as the fallback when
|
|
6
|
+
* GitHub truncates the prefilled body. Zero tokens, zero server round-trips.
|
|
7
|
+
*
|
|
8
|
+
* i18n: abstract keys (fb.*) resolved via ctx.t against the per-locale tables
|
|
9
|
+
* in index.ts (host locales are exactly "zh-CN" / "en").
|
|
10
|
+
*/
|
|
11
|
+
import { useState, useEffect } from "react";
|
|
12
|
+
import { t } from "./host-shim";
|
|
13
|
+
import { envInfo, buildMarkdown, buildIssueUrl, BODY_SAFE, type FeedbackForm, type FeedbackKind } from "./feedback-build";
|
|
14
|
+
|
|
15
|
+
// ---- module-level state (host re-renders via listener subscription) ----
|
|
16
|
+
interface FbState extends FeedbackForm { open: boolean; copied: boolean; hint: string }
|
|
17
|
+
let state: FbState = { open: false, kind: "bug", title: "", desc: "", steps: "", contact: "", context: "", includeEnv: true, copied: false, hint: "" };
|
|
18
|
+
const listeners = new Set<() => void>();
|
|
19
|
+
function fbSet(patch: Partial<FbState>): void {
|
|
20
|
+
state = { ...state, ...patch };
|
|
21
|
+
for (const l of listeners) l();
|
|
22
|
+
}
|
|
23
|
+
function useStateOf(): FbState {
|
|
24
|
+
const [, force] = useState(0);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const l = () => force((x) => x + 1);
|
|
27
|
+
listeners.add(l);
|
|
28
|
+
return () => { listeners.delete(l); };
|
|
29
|
+
}, []);
|
|
30
|
+
return state;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Toolbar / ⋮ menu entry point. */
|
|
34
|
+
export function openFeedback(): void {
|
|
35
|
+
fbSet({ open: true, copied: false, hint: "" });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// ---- icons (lucide paths) ----
|
|
39
|
+
const ICONS: Record<string, string[]> = {
|
|
40
|
+
x: ["M18 6 6 18", "m6 6 12 12"],
|
|
41
|
+
chat: ["M7.9 20A9 9 0 1 0 4 16.1L2 22Z"],
|
|
42
|
+
copy: ["M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7", "M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z"],
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
function Ic(props: { size?: number; paths: string[] }) {
|
|
46
|
+
return (
|
|
47
|
+
<svg width={props.size ?? 13} height={props.size ?? 13} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" style={{ flexShrink: 0 }}>
|
|
48
|
+
{props.paths.map((d, i) => <path key={i} d={d} />)}
|
|
49
|
+
</svg>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ---- styles ----
|
|
54
|
+
const btn = { display: "inline-flex", alignItems: "center", justifyContent: "center", gap: 5, padding: "6px 12px", borderRadius: 8, border: "1px solid var(--border)", background: "transparent", color: "var(--text)", fontSize: 12.5, cursor: "pointer" } as Record<string, string | number>;
|
|
55
|
+
const btnPrimary = { ...btn, background: "var(--accent)", borderColor: "var(--accent)", color: "#fff" } as Record<string, string | number>;
|
|
56
|
+
const input = { width: "100%", boxSizing: "border-box", padding: "6px 9px", borderRadius: 7, border: "1px solid var(--border)", background: "var(--bg-input, transparent)", color: "var(--text)", fontSize: 12.5, fontFamily: "inherit" } as Record<string, string | number>;
|
|
57
|
+
const fieldLabel = { display: "block", fontSize: 11, color: "var(--text-muted)", marginBottom: 4, fontWeight: 500 } as Record<string, string | number>;
|
|
58
|
+
|
|
59
|
+
const KINDS: Array<{ v: FeedbackKind; label: string }> = [
|
|
60
|
+
{ v: "bug", label: "fb.kind.bug" },
|
|
61
|
+
{ v: "suggestion", label: "fb.kind.suggestion" },
|
|
62
|
+
{ v: "other", label: "fb.kind.other" },
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
async function copyText(text: string): Promise<boolean> {
|
|
66
|
+
try {
|
|
67
|
+
await navigator.clipboard.writeText(text);
|
|
68
|
+
return true;
|
|
69
|
+
} catch {
|
|
70
|
+
try {
|
|
71
|
+
const ta = document.createElement("textarea");
|
|
72
|
+
ta.value = text;
|
|
73
|
+
ta.style.position = "fixed";
|
|
74
|
+
ta.style.opacity = "0";
|
|
75
|
+
document.body.appendChild(ta);
|
|
76
|
+
ta.select();
|
|
77
|
+
const ok = document.execCommand("copy");
|
|
78
|
+
document.body.removeChild(ta);
|
|
79
|
+
return ok;
|
|
80
|
+
} catch { return false; }
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function FeedbackDialog() {
|
|
85
|
+
const s = useStateOf();
|
|
86
|
+
if (!s.open) return null;
|
|
87
|
+
const env = s.includeEnv ? envInfo() : {};
|
|
88
|
+
const md = buildMarkdown(s, env);
|
|
89
|
+
const issue = buildIssueUrl(s.title || (s.desc ? s.desc.slice(0, 40) : ""), md);
|
|
90
|
+
const missing = !s.desc.trim();
|
|
91
|
+
|
|
92
|
+
const submit = () => {
|
|
93
|
+
if (missing) { fbSet({ hint: t("fb.err.descRequired") }); return; }
|
|
94
|
+
void copyText(issue.fullBody).then(() => {
|
|
95
|
+
fbSet({ copied: true, hint: issue.truncated ? t("fb.err.tooLong") : "" });
|
|
96
|
+
try { window.open(issue.url, "_blank", "noopener"); } catch { location.href = issue.url; }
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<div style={{ position: "fixed", inset: 0, zIndex: 335, background: "rgba(0,0,0,0.4)", display: "flex", alignItems: "center", justifyContent: "center" }} onClick={() => fbSet({ open: false })}>
|
|
102
|
+
<div
|
|
103
|
+
data-ext-float="1" data-ext-float-w="560" data-ext-float-autoh="1" data-ext-float-full="1"
|
|
104
|
+
style={{ width: "min(560px, 94vw)", maxHeight: "86vh", overflow: "auto", padding: 16, borderRadius: 10, background: "var(--bg-panel)", border: "1px solid var(--border)", color: "var(--text)", fontFamily: "inherit" }}
|
|
105
|
+
onClick={(e) => e.stopPropagation()}
|
|
106
|
+
>
|
|
107
|
+
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 6 }}>
|
|
108
|
+
<b style={{ fontSize: 14, display: "inline-flex", alignItems: "center", gap: 6 }}><Ic size={15} paths={ICONS.chat} />{t("fb.open.label")}</b>
|
|
109
|
+
<button onClick={() => fbSet({ open: false })} style={{ ...btn, padding: "2px 8px" }} aria-label={t("fb.close")}><Ic size={12} paths={ICONS.x} /></button>
|
|
110
|
+
</div>
|
|
111
|
+
<div style={{ fontSize: 11, color: "var(--text-muted)", marginBottom: 12 }}>{t("fb.hint.disclaimer")}</div>
|
|
112
|
+
|
|
113
|
+
<label style={fieldLabel}>{t("fb.kind")}</label>
|
|
114
|
+
<div style={{ display: "flex", gap: 6, marginBottom: 10 }}>
|
|
115
|
+
{KINDS.map((k) => (
|
|
116
|
+
<button
|
|
117
|
+
key={k.v} type="button"
|
|
118
|
+
onClick={() => fbSet({ kind: k.v })}
|
|
119
|
+
style={{ ...btn, ...(s.kind === k.v ? { background: "color-mix(in srgb, var(--accent) 14%, transparent)", borderColor: "var(--accent)", color: "var(--accent)" } : {}) }}
|
|
120
|
+
>{t(k.label)}</button>
|
|
121
|
+
))}
|
|
122
|
+
</div>
|
|
123
|
+
|
|
124
|
+
<label style={fieldLabel}>{t("fb.field.title")}</label>
|
|
125
|
+
<input style={{ ...input, marginBottom: 10 }} value={s.title} placeholder={t("fb.field.title.ph")} onChange={(e) => fbSet({ title: e.target.value })} />
|
|
126
|
+
|
|
127
|
+
<label style={fieldLabel}>{t("fb.field.desc")}</label>
|
|
128
|
+
<textarea style={{ ...input, height: 72, minHeight: 72, resize: "vertical", marginBottom: 10 }} value={s.desc} placeholder={t("fb.field.desc.ph")} onChange={(e) => fbSet({ desc: e.target.value })} />
|
|
129
|
+
|
|
130
|
+
<label style={fieldLabel}>{t("fb.field.steps")}</label>
|
|
131
|
+
<textarea style={{ ...input, height: 56, minHeight: 56, resize: "vertical", marginBottom: 10 }} value={s.steps} placeholder={t("fb.field.steps.ph")} onChange={(e) => fbSet({ steps: e.target.value })} />
|
|
132
|
+
|
|
133
|
+
<details style={{ marginBottom: 10 }}>
|
|
134
|
+
<summary style={{ fontSize: 11, color: "var(--text-muted)", cursor: "pointer", userSelect: "none" }}>{t("fb.field.context")}</summary>
|
|
135
|
+
<textarea style={{ ...input, height: 64, minHeight: 64, resize: "vertical", marginTop: 6 }} value={s.context} placeholder={t("fb.field.context.ph")} onChange={(e) => fbSet({ context: e.target.value })} />
|
|
136
|
+
</details>
|
|
137
|
+
|
|
138
|
+
<div style={{ display: "flex", alignItems: "center", gap: 8, marginBottom: 10 }}>
|
|
139
|
+
<input style={{ width: "100%", boxSizing: "border-box", padding: "6px 9px", borderRadius: 7, border: "1px solid var(--border)", background: "var(--bg-input, transparent)", color: "var(--text)", fontSize: 12.5 }} value={s.contact} placeholder={t("fb.field.contact")} onChange={(e) => fbSet({ contact: e.target.value })} />
|
|
140
|
+
</div>
|
|
141
|
+
<label style={{ display: "flex", alignItems: "center", gap: 6, fontSize: 12, color: "var(--text-muted)", marginBottom: 10, cursor: "pointer" }}>
|
|
142
|
+
<input type="checkbox" checked={s.includeEnv} onChange={(e) => fbSet({ includeEnv: e.target.checked })} />
|
|
143
|
+
{t("fb.opt.env")}
|
|
144
|
+
</label>
|
|
145
|
+
|
|
146
|
+
<label style={fieldLabel}>{t("fb.preview")}</label>
|
|
147
|
+
<pre style={{ margin: "0 0 10px", padding: 10, borderRadius: 8, border: "1px solid var(--border)", background: "color-mix(in srgb, var(--text) 4%, transparent)", fontSize: 11, fontFamily: "var(--font-mono)", maxHeight: 160, overflow: "auto", whiteSpace: "pre-wrap", wordBreak: "break-word", color: "var(--text-muted)" }}>{md}</pre>
|
|
148
|
+
|
|
149
|
+
<div style={{ display: "flex", alignItems: "center", gap: 8, flexWrap: "wrap" }}>
|
|
150
|
+
<button
|
|
151
|
+
type="button" style={btn}
|
|
152
|
+
onClick={() => { void copyText(issue.fullBody).then((ok) => fbSet({ copied: ok, hint: ok ? "" : t("fb.err.copyFailed") })); }}
|
|
153
|
+
><Ic size={12} paths={ICONS.copy} />{s.copied ? t("fb.copied") : t("fb.copy")}</button>
|
|
154
|
+
<button type="button" style={{ ...btnPrimary, opacity: missing ? 0.5 : 1 }} onClick={submit} title={missing ? t("fb.err.descRequired") : undefined}>{t("fb.submit")}</button>
|
|
155
|
+
<span style={{ fontSize: 11, color: issue.truncated ? "var(--danger, #ef4444)" : "var(--text-dim)" }}>{issue.truncated ? t("fb.err.tooLong") : `${md.length} / ${BODY_SAFE}`}</span>
|
|
156
|
+
</div>
|
|
157
|
+
{s.hint && <div style={{ marginTop: 8, fontSize: 11.5, color: "var(--danger, #ef4444)" }}>{s.hint}</div>}
|
|
158
|
+
</div>
|
|
159
|
+
</div>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* feedback-build — pure functions for composing the feedback report.
|
|
3
|
+
*
|
|
4
|
+
* Pipeline: form + env info → sanitize (best-effort redact) → markdown body →
|
|
5
|
+
* prefilled GitHub issue URL (query params). No tokens, no server: the user logs
|
|
6
|
+
* into GitHub themselves and the content is already in the input boxes.
|
|
7
|
+
*
|
|
8
|
+
* Safety model: the preview in the dialog IS the final content (user-confirmed
|
|
9
|
+
* before the redirect), so redaction here is best-effort — the rules below catch
|
|
10
|
+
* internal domains/IPs/repo names/paths and common token shapes.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** GitHub truncates oversized query payloads; stay comfortably under (~8KB). */
|
|
14
|
+
export const BODY_SAFE = 6000;
|
|
15
|
+
export const REPO_NEW_ISSUE = "https://github.com/aiti-ai/aiti-ai/issues/new";
|
|
16
|
+
|
|
17
|
+
export type FeedbackKind = "bug" | "suggestion" | "other";
|
|
18
|
+
|
|
19
|
+
export interface FeedbackForm {
|
|
20
|
+
kind: FeedbackKind;
|
|
21
|
+
title: string;
|
|
22
|
+
desc: string;
|
|
23
|
+
steps: string;
|
|
24
|
+
contact: string;
|
|
25
|
+
/** Optional pasted session context (never auto-read from the session). */
|
|
26
|
+
context: string;
|
|
27
|
+
includeEnv: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Environment section lines (URL query is stripped — session ids stay local). */
|
|
31
|
+
export function envInfo(nav?: { userAgent?: string; platform?: string; language?: string }, href?: string): Record<string, string> {
|
|
32
|
+
const n = nav ?? (typeof navigator !== "undefined" ? navigator : ({} as { userAgent?: string; platform?: string; language?: string }));
|
|
33
|
+
let page = "";
|
|
34
|
+
if (href ?? (typeof location !== "undefined" ? location.href : "")) {
|
|
35
|
+
try { const u = new URL((href ?? (typeof location !== "undefined" ? location.href : "")) as string); page = u.origin + u.pathname; } catch { page = ""; }
|
|
36
|
+
}
|
|
37
|
+
const out: Record<string, string> = {};
|
|
38
|
+
if (n.userAgent) out["UA"] = n.userAgent;
|
|
39
|
+
if (n.platform) out["Platform"] = n.platform;
|
|
40
|
+
if (n.language) out["Language"] = n.language;
|
|
41
|
+
if (page) out["pi-web path"] = page;
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Site-specific internal hostnames are injected, never hardcoded here:
|
|
46
|
+
// build time — VITE_FEEDBACK_INTERNAL_HOSTS="host1,host2"
|
|
47
|
+
// runtime — <html data-aiti-feedback-internal-hosts="host1,host2">
|
|
48
|
+
function injectedHosts(): string[] {
|
|
49
|
+
const env = (import.meta as unknown as { env?: Record<string, string> })?.env ?? {};
|
|
50
|
+
const doc = (globalThis as { document?: { documentElement?: { getAttribute?(n: string): string | null } } }).document;
|
|
51
|
+
const fromDom = doc?.documentElement?.getAttribute?.("data-aiti-feedback-internal-hosts") ?? "";
|
|
52
|
+
const raw = [env.VITE_FEEDBACK_INTERNAL_HOSTS, fromDom];
|
|
53
|
+
const hosts = raw
|
|
54
|
+
.flatMap((v) => String(v ?? "").split(","))
|
|
55
|
+
.map((s) => s.trim())
|
|
56
|
+
.filter(Boolean);
|
|
57
|
+
return [...new Set(hosts)];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const escapeRe = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
61
|
+
|
|
62
|
+
// Order matters: specific shapes first, generic long-secrets last.
|
|
63
|
+
const REDACT_RULES: Array<[RegExp, string]> = [
|
|
64
|
+
// Self-hosted / private-network DNS suffixes (RFC 8375 .home.arpa included).
|
|
65
|
+
[/\b(?:[a-z0-9-]+\.)+(?:internal|intranet|lan|local|corp|home\.arpa)(?::\d+)?/gi, "<redacted-domain>"],
|
|
66
|
+
[/\b192\.168\.\d{1,3}\.\d{1,3}\b/g, "<redacted-ip>"],
|
|
67
|
+
[/\b10\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/g, "<redacted-ip>"],
|
|
68
|
+
[/\b172\.(?:1[6-9]|2\d|3[01])\.\d{1,3}\.\d{1,3}\b/g, "<redacted-ip>"],
|
|
69
|
+
// Home directories: drop the user segment, keep the rest readable.
|
|
70
|
+
[/\/home\/[^/\s]+/g, "/home/<redacted>"],
|
|
71
|
+
[/\/Users\/[^/\s]+/g, "/Users/<redacted>"],
|
|
72
|
+
[/\b[A-Za-z]:\\Users\\[^\\\s]+/g, "<redacted-path>"],
|
|
73
|
+
[/\bsk-[A-Za-z0-9_-]{8,}/g, "<redacted-key>"],
|
|
74
|
+
[/\bgh[pousr]_[A-Za-z0-9]{20,}/g, "<redacted-token>"],
|
|
75
|
+
[/\bgithub_pat_[A-Za-z0-9_]{20,}/g, "<redacted-token>"],
|
|
76
|
+
[/\bAKIA[0-9A-Z]{16}\b/g, "<redacted-aws-key>"],
|
|
77
|
+
[/\bxox[baprs]-[A-Za-z0-9-]{10,}/g, "<redacted-token>"],
|
|
78
|
+
[/\b[0-9a-f]{32,}\b/gi, "<redacted-hex>"],
|
|
79
|
+
[/\b[A-Za-z0-9+/]{40,}={0,2}(?![A-Za-z0-9+/])/g, "<redacted-b64>"],
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
/** Best-effort sanitize: internal names/addresses and common secret shapes → placeholders. */
|
|
83
|
+
export function redact(text: string): string {
|
|
84
|
+
const rules: Array<[RegExp, string]> = [
|
|
85
|
+
...injectedHosts().map((host): [RegExp, string] => [
|
|
86
|
+
new RegExp(`[\\w.-]*${escapeRe(host)}(?::\\d+)?`, "gi"),
|
|
87
|
+
"<redacted-domain>",
|
|
88
|
+
]),
|
|
89
|
+
...REDACT_RULES,
|
|
90
|
+
];
|
|
91
|
+
return rules.reduce((s, [re, sub]) => s.replace(re, sub), text);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const KIND_LABEL: Record<FeedbackKind, string> = { bug: "bug", suggestion: "suggestion", other: "other" };
|
|
95
|
+
|
|
96
|
+
function section(title: string, content: string): string {
|
|
97
|
+
const c = content.trim();
|
|
98
|
+
return c ? `### ${title}\n${c}\n` : "";
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Compose the issue body (each section emitted only when non-empty; redacted). */
|
|
102
|
+
export function buildMarkdown(f: FeedbackForm, env?: Record<string, string>): string {
|
|
103
|
+
const lines: string[] = [];
|
|
104
|
+
lines.push(`### Type\n${KIND_LABEL[f.kind] || f.kind}\n`);
|
|
105
|
+
const desc = redact(f.desc).trim();
|
|
106
|
+
lines.push(`### Description\n${desc || "(empty)"}\n`);
|
|
107
|
+
lines.push(section("Steps to reproduce", redact(f.steps)));
|
|
108
|
+
if (f.includeEnv && env && Object.keys(env).length) {
|
|
109
|
+
lines.push(`### Environment\n${Object.entries(env).map(([k, v]) => `- ${k}: ${redact(String(v))}`).join("\n")}\n`);
|
|
110
|
+
}
|
|
111
|
+
lines.push(section("Session context (pasted by the reporter)", redact(f.context)));
|
|
112
|
+
lines.push(section("Contact", redact(f.contact)));
|
|
113
|
+
return lines.join("\n").trim() + "\n";
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface IssueUrlResult {
|
|
117
|
+
url: string;
|
|
118
|
+
/** true when body exceeded BODY_SAFE and was cut (full text goes to clipboard). */
|
|
119
|
+
truncated: boolean;
|
|
120
|
+
fullBody: string;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Prefilled new-issue URL; body over the safe budget is cut with a pointer note. */
|
|
124
|
+
export function buildIssueUrl(title: string, fullBody: string): IssueUrlResult {
|
|
125
|
+
const t = (title || "feedback").trim().slice(0, 160) || "feedback";
|
|
126
|
+
let body = fullBody;
|
|
127
|
+
let truncated = false;
|
|
128
|
+
if (body.length > BODY_SAFE) {
|
|
129
|
+
truncated = true;
|
|
130
|
+
body = body.slice(0, BODY_SAFE).replace(/\n[\s\S]*$/, "") + "\n\n(truncated — full text in clipboard, paste as a follow-up comment)";
|
|
131
|
+
}
|
|
132
|
+
const url = `${REPO_NEW_ISSUE}?title=${encodeURIComponent(t)}&body=${encodeURIComponent(body)}`;
|
|
133
|
+
return { url, truncated, fullBody };
|
|
134
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* host-shim — host bridge for JSX client bundles (shared template file).
|
|
3
|
+
*
|
|
4
|
+
* Why it exists: browsers don't understand JSX, so an extension client must be
|
|
5
|
+
* precompiled by esbuild (vite lib mode). esbuild's automatic JSX runtime
|
|
6
|
+
* (jsx: "automatic") generates `jsx(type, props)` calls that point at React by
|
|
7
|
+
* default — but pi-web extension clients are NOT React: the host passes its own
|
|
8
|
+
* rendering primitives (h / useState / useEffect / apiUrl…) via register(ctx).
|
|
9
|
+
*
|
|
10
|
+
* So vite resolve.alias redirects react / react/jsx-runtime to this shim:
|
|
11
|
+
* hooks imported from "react" in components → this shim's createElement /
|
|
12
|
+
* useState / … → delegated to ctx. The bundle references zero React; the host
|
|
13
|
+
* keeps a single renderer instance, and npm components written with standard
|
|
14
|
+
* react hooks can be bundled in directly.
|
|
15
|
+
*
|
|
16
|
+
* Usage: register(ctx) in entry.tsx must call `__setCtx(ctx)` first (before any
|
|
17
|
+
* JSX renders). Add fields as needed (apiUrl/t/useRef/useMemo…) as one-line
|
|
18
|
+
* delegations below.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
// Module-level ctx (set in entry.tsx register; read at render time)
|
|
22
|
+
let _ctx: Record<string, unknown> | null = null;
|
|
23
|
+
export function __setCtx(ctx: Record<string, unknown>): void { _ctx = ctx; }
|
|
24
|
+
|
|
25
|
+
/** DI P2: read a cross-extension client service (lazy provider / absent → undefined; consumers must degrade) */
|
|
26
|
+
export function extSvc<T = unknown>(key: string): T | undefined {
|
|
27
|
+
return (_ctx as any)?.getExtService?.(key) as T | undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** DI P2: register a cross-extension client service (returns disposer; null on old hosts) */
|
|
31
|
+
export function regSvc(key: string, impl: unknown): (() => void) | null {
|
|
32
|
+
const c = _ctx as any;
|
|
33
|
+
return typeof c?.registerExtService === "function" ? c.registerExtService(key, impl) : null;
|
|
34
|
+
}
|
|
35
|
+
function c<T = (...args: never[]) => unknown>(name: string): T {
|
|
36
|
+
return (_ctx?.[name] as T) ?? (() => undefined as never);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// ---------- react-compatible exports (esbuild alias react → this shim) ----------
|
|
40
|
+
// React's Fragment type is Symbol.for("react.fragment") — passing it to host h()
|
|
41
|
+
// produces a real Fragment.
|
|
42
|
+
export const Fragment = (typeof Symbol !== "undefined" && Symbol.for) ? Symbol.for("react.fragment") : 0xacb;
|
|
43
|
+
export function createElement(...args: unknown[]): unknown {
|
|
44
|
+
return c("h").call(null, ...args);
|
|
45
|
+
}
|
|
46
|
+
// Automatic runtime jsx(type, props, key) — key is a separate third argument;
|
|
47
|
+
// host h() = React.createElement whose third argument is **children**. Passing
|
|
48
|
+
// key through would treat it as a child (lost element key + key value clobbering
|
|
49
|
+
// props.children as real content). So merge key back into props.
|
|
50
|
+
function mergeKey(args: unknown[]): unknown[] {
|
|
51
|
+
const [type, props, key, ...rest] = args;
|
|
52
|
+
if (props && typeof props === "object") {
|
|
53
|
+
// Key always merges into props; createElement always receives (type, config):
|
|
54
|
+
// with key → config.key is read as the element key; undefined/null keys must
|
|
55
|
+
// also strip the third argument — otherwise createElement(type, config,
|
|
56
|
+
// undefined) follows legacy semantics (third arg = children) and undefined
|
|
57
|
+
// clobbers props.children, wiping the whole element content (proven in the
|
|
58
|
+
// field: aiti-editor ⋯ menu items with key=undefined all rendered blank).
|
|
59
|
+
const merged: Record<string, unknown> = { ...(props as Record<string, unknown>) };
|
|
60
|
+
if (key !== undefined && key !== null) merged.key = key;
|
|
61
|
+
return [type, merged, ...rest];
|
|
62
|
+
}
|
|
63
|
+
return args;
|
|
64
|
+
}
|
|
65
|
+
export const jsx = (...args: unknown[]) => createElement(...mergeKey(args));
|
|
66
|
+
export const jsxs = (...args: unknown[]) => {
|
|
67
|
+
// React automatic-runtime semantics: jsxs (static multi-children) calls
|
|
68
|
+
// validateChildKeys on each child → marks _store.validated = 1 ("validated,
|
|
69
|
+
// don't warn again"). Host h() = React.createElement only creates elements and
|
|
70
|
+
// does not mark them — without this, static sibling children like
|
|
71
|
+
// `<div><A/><B/></div>` (no key needed in JSX; the automatic runtime would
|
|
72
|
+
// normally suppress the warning) trigger React's "Each child in a list should
|
|
73
|
+
// have a unique key" (dev-only, deduped per owner). The value must be 1
|
|
74
|
+
// (2 is a different marker and still warns).
|
|
75
|
+
const props = (args as [unknown, { children?: unknown } | undefined, ...unknown[]])[1];
|
|
76
|
+
const children = props?.children;
|
|
77
|
+
if (Array.isArray(children)) {
|
|
78
|
+
for (const c of children) {
|
|
79
|
+
if (c && typeof c === "object" && (c as { _store?: { validated?: number } })._store) {
|
|
80
|
+
(c as { _store: { validated: number } })._store.validated = 1;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return createElement(...mergeKey(args));
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// ---------- React hooks delegation (add/remove as needed) ----------
|
|
88
|
+
export const useState = <T>(init: T | (() => T)) => c<(...a: unknown[]) => [T, (v: T | ((prev: T) => T)) => void]>("useState")(init);
|
|
89
|
+
export const useEffect = (fn: () => unknown, deps?: unknown[]) => c("useEffect")(fn, deps);
|
|
90
|
+
export const useRef = <T>(v: T) => c<(...a: unknown[]) => { current: T }>("useRef")(v);
|
|
91
|
+
export const useCallback = <T extends (...args: never[]) => unknown>(fn: T, deps?: unknown[]) => c<(...a: unknown[]) => T>("useCallback")(fn, deps);
|
|
92
|
+
export const useMemo = <T>(fn: () => T, deps?: unknown[]) => c<(...a: unknown[]) => T>("useMemo")(fn, deps);
|
|
93
|
+
|
|
94
|
+
// ---------- host utility delegation (add/remove as needed) ----------
|
|
95
|
+
/** apiUrl(p): resolve a relative path to the full API URL under the current basePath (multi-instance /dev prefix safe). */
|
|
96
|
+
export function apiUrl(p: string): string {
|
|
97
|
+
const fn = _ctx?.apiUrl as ((p: string) => string) | undefined;
|
|
98
|
+
return typeof fn === "function" ? fn(p) : p;
|
|
99
|
+
}
|
|
100
|
+
/** t(key, params?): extension i18n translation (entries from ui.i18n in index.ts). */
|
|
101
|
+
export function t(key: string, params?: Record<string, unknown>): string {
|
|
102
|
+
const fn = _ctx?.t as ((key: string, params?: Record<string, unknown>) => string) | undefined;
|
|
103
|
+
return typeof fn === "function" ? fn(key, params) : key;
|
|
104
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { redact, buildMarkdown, buildIssueUrl, envInfo, BODY_SAFE } from "../src/feedback-build.ts";
|
|
4
|
+
|
|
5
|
+
test("redact: private-network domains, hosts and ports", () => {
|
|
6
|
+
const out = redact("open https://dev.internal:57442/app/ and https://docs.home.arpa/x");
|
|
7
|
+
assert.equal(out, "open https://<redacted-domain>/app/ and https://<redacted-domain>/x");
|
|
8
|
+
assert.equal(redact("open https://corp.example/x"), "open https://corp.example/x");
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test("redact: injected internal hosts", () => {
|
|
12
|
+
const attrs = { "data-aiti-feedback-internal-hosts": "corp.example, ops.example" };
|
|
13
|
+
globalThis.document = { documentElement: { getAttribute: (n) => attrs[n] ?? null } };
|
|
14
|
+
try {
|
|
15
|
+
assert.equal(redact("open https://corp.example:8443/x"), "open https://<redacted-domain>/x");
|
|
16
|
+
assert.equal(redact("see ops.example/y"), "see <redacted-domain>/y");
|
|
17
|
+
} finally {
|
|
18
|
+
delete globalThis.document;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("redact: private IPv4 ranges only", () => {
|
|
23
|
+
assert.equal(redact("a 192.168.1.24 b"), "a <redacted-ip> b");
|
|
24
|
+
assert.equal(redact("a 10.7.0.23 b"), "a <redacted-ip> b");
|
|
25
|
+
assert.equal(redact("a 172.20.1.5 b"), "a <redacted-ip> b");
|
|
26
|
+
// public IP stays
|
|
27
|
+
assert.equal(redact("a 8.8.8.8 b"), "a 8.8.8.8 b");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("redact: home paths drop the user segment", () => {
|
|
31
|
+
assert.equal(redact("/home/alice/.pi/web"), "/home/<redacted>/.pi/web");
|
|
32
|
+
assert.equal(redact("/Users/alice/.pi/web"), "/Users/<redacted>/.pi/web");
|
|
33
|
+
assert.equal(redact(String.raw`C:\Users\alice\app`), String.raw`<redacted-path>\app`);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("redact: token shapes", () => {
|
|
37
|
+
assert.ok(redact("key sk-abc123def456677").includes("<redacted-key>"));
|
|
38
|
+
assert.ok(redact("ghp_ABCDEFGHIJKLMNOPQRSTUVWX").includes("<redacted-token>"));
|
|
39
|
+
assert.ok(redact("AKIAIOSFODNN7EXAMPLE").includes("<redacted-aws-key>"));
|
|
40
|
+
assert.ok(redact("hex deadbeefdeadbeefdeadbeefdeadbeef").includes("<redacted-hex>"));
|
|
41
|
+
assert.ok(redact("b64 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrst").includes("<redacted-b64>"));
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("redact: normal text untouched", () => {
|
|
45
|
+
const s = "The build fails on step 2 with exit code 1.";
|
|
46
|
+
assert.equal(redact(s), s);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("buildMarkdown: sections and redaction", () => {
|
|
50
|
+
const md = buildMarkdown({
|
|
51
|
+
kind: "bug", title: "t", desc: "crash at dev.internal", steps: "1. open\n2. click",
|
|
52
|
+
contact: "", context: "", includeEnv: false,
|
|
53
|
+
});
|
|
54
|
+
assert.ok(md.includes("### Type\nbug"));
|
|
55
|
+
assert.ok(md.includes("<redacted-domain>"));
|
|
56
|
+
assert.ok(md.includes("### Steps to reproduce"));
|
|
57
|
+
assert.ok(!md.includes("### Environment"));
|
|
58
|
+
// empty optional sections are omitted entirely
|
|
59
|
+
const md2 = buildMarkdown({ kind: "bug", title: "t", desc: "d", steps: "", contact: "", context: "", includeEnv: false });
|
|
60
|
+
assert.ok(!md2.includes("### Steps"));
|
|
61
|
+
assert.ok(!md2.includes("### Contact"));
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("buildMarkdown: env section only when enabled", () => {
|
|
65
|
+
const env = envInfo({ userAgent: "UA/1", platform: "Linux", language: "zh" }, "https://x.test/?session=abc");
|
|
66
|
+
const md = buildMarkdown({ kind: "bug", title: "t", desc: "d", steps: "", contact: "", context: "", includeEnv: true }, env);
|
|
67
|
+
assert.ok(md.includes("- UA: UA/1"));
|
|
68
|
+
assert.ok(md.includes("https://x.test/")); // query stripped
|
|
69
|
+
assert.ok(!md.includes("session=abc"));
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("buildIssueUrl: encodes and stays under budget", () => {
|
|
73
|
+
const r = buildIssueUrl("标题 bug", "body line\nwith spaces");
|
|
74
|
+
assert.ok(r.url.startsWith("https://github.com/aiti-ai/aiti-ai/issues/new?title="));
|
|
75
|
+
assert.ok(r.url.includes(encodeURIComponent("标题 bug")));
|
|
76
|
+
assert.ok(!r.truncated);
|
|
77
|
+
assert.ok(r.url.length < 8000);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("buildIssueUrl: truncation with clipboard fallback note", () => {
|
|
81
|
+
const r = buildIssueUrl("big", "x".repeat(BODY_SAFE + 500));
|
|
82
|
+
assert.ok(r.truncated);
|
|
83
|
+
assert.ok(r.fullBody.length === BODY_SAFE + 500); // caller copies full text
|
|
84
|
+
assert.ok(r.url.length < 12000);
|
|
85
|
+
assert.ok(r.url.includes(encodeURIComponent("(truncated — full text in clipboard")));
|
|
86
|
+
});
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
let _ctx = null;
|
|
2
|
+
function __setCtx(ctx) {
|
|
3
|
+
_ctx = ctx;
|
|
4
|
+
}
|
|
5
|
+
function c(name) {
|
|
6
|
+
return _ctx?.[name] ?? (() => void 0);
|
|
7
|
+
}
|
|
8
|
+
function createElement(...args) {
|
|
9
|
+
return c("h").call(null, ...args);
|
|
10
|
+
}
|
|
11
|
+
function mergeKey(args) {
|
|
12
|
+
const [type, props, key, ...rest] = args;
|
|
13
|
+
if (props && typeof props === "object") {
|
|
14
|
+
const merged = { ...props };
|
|
15
|
+
if (key !== void 0 && key !== null) merged.key = key;
|
|
16
|
+
return [type, merged, ...rest];
|
|
17
|
+
}
|
|
18
|
+
return args;
|
|
19
|
+
}
|
|
20
|
+
const jsx = (...args) => createElement(...mergeKey(args));
|
|
21
|
+
const jsxs = (...args) => {
|
|
22
|
+
const props = args[1];
|
|
23
|
+
const children = props?.children;
|
|
24
|
+
if (Array.isArray(children)) {
|
|
25
|
+
for (const c2 of children) {
|
|
26
|
+
if (c2 && typeof c2 === "object" && c2._store) {
|
|
27
|
+
c2._store.validated = 1;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return createElement(...mergeKey(args));
|
|
32
|
+
};
|
|
33
|
+
const useState = (init) => c("useState")(init);
|
|
34
|
+
const useEffect = (fn, deps) => c("useEffect")(fn, deps);
|
|
35
|
+
function t(key, params) {
|
|
36
|
+
const fn = _ctx?.t;
|
|
37
|
+
return typeof fn === "function" ? fn(key, params) : key;
|
|
38
|
+
}
|
|
39
|
+
const BODY_SAFE = 6e3;
|
|
40
|
+
const REPO_NEW_ISSUE = "https://github.com/aiti-ai/aiti-ai/issues/new";
|
|
41
|
+
function envInfo(nav, href) {
|
|
42
|
+
const n = typeof navigator !== "undefined" ? navigator : {};
|
|
43
|
+
let page = "";
|
|
44
|
+
if (typeof location !== "undefined" ? location.href : "") {
|
|
45
|
+
try {
|
|
46
|
+
const u = new URL(href ?? (typeof location !== "undefined" ? location.href : ""));
|
|
47
|
+
page = u.origin + u.pathname;
|
|
48
|
+
} catch {
|
|
49
|
+
page = "";
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const out = {};
|
|
53
|
+
if (n.userAgent) out["UA"] = n.userAgent;
|
|
54
|
+
if (n.platform) out["Platform"] = n.platform;
|
|
55
|
+
if (n.language) out["Language"] = n.language;
|
|
56
|
+
if (page) out["pi-web path"] = page;
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
function injectedHosts() {
|
|
60
|
+
const env = import.meta?.env ?? {};
|
|
61
|
+
const doc = globalThis.document;
|
|
62
|
+
const fromDom = doc?.documentElement?.getAttribute?.("data-aiti-feedback-internal-hosts") ?? "";
|
|
63
|
+
const raw = [env.VITE_FEEDBACK_INTERNAL_HOSTS, fromDom];
|
|
64
|
+
const hosts = raw.flatMap((v) => String(v ?? "").split(",")).map((s) => s.trim()).filter(Boolean);
|
|
65
|
+
return [...new Set(hosts)];
|
|
66
|
+
}
|
|
67
|
+
const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
68
|
+
const REDACT_RULES = [
|
|
69
|
+
// Self-hosted / private-network DNS suffixes (RFC 8375 .home.arpa included).
|
|
70
|
+
[/\b(?:[a-z0-9-]+\.)+(?:internal|intranet|lan|local|corp|home\.arpa)(?::\d+)?/gi, "<redacted-domain>"],
|
|
71
|
+
[/\b192\.168\.\d{1,3}\.\d{1,3}\b/g, "<redacted-ip>"],
|
|
72
|
+
[/\b10\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/g, "<redacted-ip>"],
|
|
73
|
+
[/\b172\.(?:1[6-9]|2\d|3[01])\.\d{1,3}\.\d{1,3}\b/g, "<redacted-ip>"],
|
|
74
|
+
// Home directories: drop the user segment, keep the rest readable.
|
|
75
|
+
[/\/home\/[^/\s]+/g, "/home/<redacted>"],
|
|
76
|
+
[/\/Users\/[^/\s]+/g, "/Users/<redacted>"],
|
|
77
|
+
[/\b[A-Za-z]:\\Users\\[^\\\s]+/g, "<redacted-path>"],
|
|
78
|
+
[/\bsk-[A-Za-z0-9_-]{8,}/g, "<redacted-key>"],
|
|
79
|
+
[/\bgh[pousr]_[A-Za-z0-9]{20,}/g, "<redacted-token>"],
|
|
80
|
+
[/\bgithub_pat_[A-Za-z0-9_]{20,}/g, "<redacted-token>"],
|
|
81
|
+
[/\bAKIA[0-9A-Z]{16}\b/g, "<redacted-aws-key>"],
|
|
82
|
+
[/\bxox[baprs]-[A-Za-z0-9-]{10,}/g, "<redacted-token>"],
|
|
83
|
+
[/\b[0-9a-f]{32,}\b/gi, "<redacted-hex>"],
|
|
84
|
+
[/\b[A-Za-z0-9+/]{40,}={0,2}(?![A-Za-z0-9+/])/g, "<redacted-b64>"]
|
|
85
|
+
];
|
|
86
|
+
function redact(text) {
|
|
87
|
+
const rules = [
|
|
88
|
+
...injectedHosts().map((host) => [
|
|
89
|
+
new RegExp(`[\\w.-]*${escapeRe(host)}(?::\\d+)?`, "gi"),
|
|
90
|
+
"<redacted-domain>"
|
|
91
|
+
]),
|
|
92
|
+
...REDACT_RULES
|
|
93
|
+
];
|
|
94
|
+
return rules.reduce((s, [re, sub]) => s.replace(re, sub), text);
|
|
95
|
+
}
|
|
96
|
+
const KIND_LABEL = { bug: "bug", suggestion: "suggestion", other: "other" };
|
|
97
|
+
function section(title, content) {
|
|
98
|
+
const c2 = content.trim();
|
|
99
|
+
return c2 ? `### ${title}
|
|
100
|
+
${c2}
|
|
101
|
+
` : "";
|
|
102
|
+
}
|
|
103
|
+
function buildMarkdown(f, env) {
|
|
104
|
+
const lines = [];
|
|
105
|
+
lines.push(`### Type
|
|
106
|
+
${KIND_LABEL[f.kind] || f.kind}
|
|
107
|
+
`);
|
|
108
|
+
const desc = redact(f.desc).trim();
|
|
109
|
+
lines.push(`### Description
|
|
110
|
+
${desc || "(empty)"}
|
|
111
|
+
`);
|
|
112
|
+
lines.push(section("Steps to reproduce", redact(f.steps)));
|
|
113
|
+
if (f.includeEnv && env && Object.keys(env).length) {
|
|
114
|
+
lines.push(`### Environment
|
|
115
|
+
${Object.entries(env).map(([k, v]) => `- ${k}: ${redact(String(v))}`).join("\n")}
|
|
116
|
+
`);
|
|
117
|
+
}
|
|
118
|
+
lines.push(section("Session context (pasted by the reporter)", redact(f.context)));
|
|
119
|
+
lines.push(section("Contact", redact(f.contact)));
|
|
120
|
+
return lines.join("\n").trim() + "\n";
|
|
121
|
+
}
|
|
122
|
+
function buildIssueUrl(title, fullBody) {
|
|
123
|
+
const t2 = (title || "feedback").trim().slice(0, 160) || "feedback";
|
|
124
|
+
let body = fullBody;
|
|
125
|
+
let truncated = false;
|
|
126
|
+
if (body.length > BODY_SAFE) {
|
|
127
|
+
truncated = true;
|
|
128
|
+
body = body.slice(0, BODY_SAFE).replace(/\n[\s\S]*$/, "") + "\n\n(truncated — full text in clipboard, paste as a follow-up comment)";
|
|
129
|
+
}
|
|
130
|
+
const url = `${REPO_NEW_ISSUE}?title=${encodeURIComponent(t2)}&body=${encodeURIComponent(body)}`;
|
|
131
|
+
return { url, truncated, fullBody };
|
|
132
|
+
}
|
|
133
|
+
let state = { open: false, kind: "bug", title: "", desc: "", steps: "", contact: "", context: "", includeEnv: true, copied: false, hint: "" };
|
|
134
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
135
|
+
function fbSet(patch) {
|
|
136
|
+
state = { ...state, ...patch };
|
|
137
|
+
for (const l of listeners) l();
|
|
138
|
+
}
|
|
139
|
+
function useStateOf() {
|
|
140
|
+
const [, force] = useState(0);
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
const l = () => force((x) => x + 1);
|
|
143
|
+
listeners.add(l);
|
|
144
|
+
return () => {
|
|
145
|
+
listeners.delete(l);
|
|
146
|
+
};
|
|
147
|
+
}, []);
|
|
148
|
+
return state;
|
|
149
|
+
}
|
|
150
|
+
function openFeedback() {
|
|
151
|
+
fbSet({ open: true, copied: false, hint: "" });
|
|
152
|
+
}
|
|
153
|
+
const ICONS = {
|
|
154
|
+
x: ["M18 6 6 18", "m6 6 12 12"],
|
|
155
|
+
chat: ["M7.9 20A9 9 0 1 0 4 16.1L2 22Z"],
|
|
156
|
+
copy: ["M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7", "M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z"]
|
|
157
|
+
};
|
|
158
|
+
function Ic(props) {
|
|
159
|
+
return /* @__PURE__ */ jsx("svg", { width: props.size ?? 13, height: props.size ?? 13, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", style: { flexShrink: 0 }, children: props.paths.map((d, i) => /* @__PURE__ */ jsx("path", { d }, i)) });
|
|
160
|
+
}
|
|
161
|
+
const btn = { display: "inline-flex", alignItems: "center", justifyContent: "center", gap: 5, padding: "6px 12px", borderRadius: 8, border: "1px solid var(--border)", background: "transparent", color: "var(--text)", fontSize: 12.5, cursor: "pointer" };
|
|
162
|
+
const btnPrimary = { ...btn, background: "var(--accent)", borderColor: "var(--accent)", color: "#fff" };
|
|
163
|
+
const input = { width: "100%", boxSizing: "border-box", padding: "6px 9px", borderRadius: 7, border: "1px solid var(--border)", background: "var(--bg-input, transparent)", color: "var(--text)", fontSize: 12.5, fontFamily: "inherit" };
|
|
164
|
+
const fieldLabel = { display: "block", fontSize: 11, color: "var(--text-muted)", marginBottom: 4, fontWeight: 500 };
|
|
165
|
+
const KINDS = [
|
|
166
|
+
{ v: "bug", label: "fb.kind.bug" },
|
|
167
|
+
{ v: "suggestion", label: "fb.kind.suggestion" },
|
|
168
|
+
{ v: "other", label: "fb.kind.other" }
|
|
169
|
+
];
|
|
170
|
+
async function copyText(text) {
|
|
171
|
+
try {
|
|
172
|
+
await navigator.clipboard.writeText(text);
|
|
173
|
+
return true;
|
|
174
|
+
} catch {
|
|
175
|
+
try {
|
|
176
|
+
const ta = document.createElement("textarea");
|
|
177
|
+
ta.value = text;
|
|
178
|
+
ta.style.position = "fixed";
|
|
179
|
+
ta.style.opacity = "0";
|
|
180
|
+
document.body.appendChild(ta);
|
|
181
|
+
ta.select();
|
|
182
|
+
const ok = document.execCommand("copy");
|
|
183
|
+
document.body.removeChild(ta);
|
|
184
|
+
return ok;
|
|
185
|
+
} catch {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function FeedbackDialog() {
|
|
191
|
+
const s = useStateOf();
|
|
192
|
+
if (!s.open) return null;
|
|
193
|
+
const env = s.includeEnv ? envInfo() : {};
|
|
194
|
+
const md = buildMarkdown(s, env);
|
|
195
|
+
const issue = buildIssueUrl(s.title || (s.desc ? s.desc.slice(0, 40) : ""), md);
|
|
196
|
+
const missing = !s.desc.trim();
|
|
197
|
+
const submit = () => {
|
|
198
|
+
if (missing) {
|
|
199
|
+
fbSet({ hint: t("fb.err.descRequired") });
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
void copyText(issue.fullBody).then(() => {
|
|
203
|
+
fbSet({ copied: true, hint: issue.truncated ? t("fb.err.tooLong") : "" });
|
|
204
|
+
try {
|
|
205
|
+
window.open(issue.url, "_blank", "noopener");
|
|
206
|
+
} catch {
|
|
207
|
+
location.href = issue.url;
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
return /* @__PURE__ */ jsx("div", { style: { position: "fixed", inset: 0, zIndex: 335, background: "rgba(0,0,0,0.4)", display: "flex", alignItems: "center", justifyContent: "center" }, onClick: () => fbSet({ open: false }), children: /* @__PURE__ */ jsxs(
|
|
212
|
+
"div",
|
|
213
|
+
{
|
|
214
|
+
"data-ext-float": "1",
|
|
215
|
+
"data-ext-float-w": "560",
|
|
216
|
+
"data-ext-float-autoh": "1",
|
|
217
|
+
"data-ext-float-full": "1",
|
|
218
|
+
style: { width: "min(560px, 94vw)", maxHeight: "86vh", overflow: "auto", padding: 16, borderRadius: 10, background: "var(--bg-panel)", border: "1px solid var(--border)", color: "var(--text)", fontFamily: "inherit" },
|
|
219
|
+
onClick: (e) => e.stopPropagation(),
|
|
220
|
+
children: [
|
|
221
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 6 }, children: [
|
|
222
|
+
/* @__PURE__ */ jsxs("b", { style: { fontSize: 14, display: "inline-flex", alignItems: "center", gap: 6 }, children: [
|
|
223
|
+
/* @__PURE__ */ jsx(Ic, { size: 15, paths: ICONS.chat }),
|
|
224
|
+
t("fb.open.label")
|
|
225
|
+
] }),
|
|
226
|
+
/* @__PURE__ */ jsx("button", { onClick: () => fbSet({ open: false }), style: { ...btn, padding: "2px 8px" }, "aria-label": t("fb.close"), children: /* @__PURE__ */ jsx(Ic, { size: 12, paths: ICONS.x }) })
|
|
227
|
+
] }),
|
|
228
|
+
/* @__PURE__ */ jsx("div", { style: { fontSize: 11, color: "var(--text-muted)", marginBottom: 12 }, children: t("fb.hint.disclaimer") }),
|
|
229
|
+
/* @__PURE__ */ jsx("label", { style: fieldLabel, children: t("fb.kind") }),
|
|
230
|
+
/* @__PURE__ */ jsx("div", { style: { display: "flex", gap: 6, marginBottom: 10 }, children: KINDS.map((k) => /* @__PURE__ */ jsx(
|
|
231
|
+
"button",
|
|
232
|
+
{
|
|
233
|
+
type: "button",
|
|
234
|
+
onClick: () => fbSet({ kind: k.v }),
|
|
235
|
+
style: { ...btn, ...s.kind === k.v ? { background: "color-mix(in srgb, var(--accent) 14%, transparent)", borderColor: "var(--accent)", color: "var(--accent)" } : {} },
|
|
236
|
+
children: t(k.label)
|
|
237
|
+
},
|
|
238
|
+
k.v
|
|
239
|
+
)) }),
|
|
240
|
+
/* @__PURE__ */ jsx("label", { style: fieldLabel, children: t("fb.field.title") }),
|
|
241
|
+
/* @__PURE__ */ jsx("input", { style: { ...input, marginBottom: 10 }, value: s.title, placeholder: t("fb.field.title.ph"), onChange: (e) => fbSet({ title: e.target.value }) }),
|
|
242
|
+
/* @__PURE__ */ jsx("label", { style: fieldLabel, children: t("fb.field.desc") }),
|
|
243
|
+
/* @__PURE__ */ jsx("textarea", { style: { ...input, height: 72, minHeight: 72, resize: "vertical", marginBottom: 10 }, value: s.desc, placeholder: t("fb.field.desc.ph"), onChange: (e) => fbSet({ desc: e.target.value }) }),
|
|
244
|
+
/* @__PURE__ */ jsx("label", { style: fieldLabel, children: t("fb.field.steps") }),
|
|
245
|
+
/* @__PURE__ */ jsx("textarea", { style: { ...input, height: 56, minHeight: 56, resize: "vertical", marginBottom: 10 }, value: s.steps, placeholder: t("fb.field.steps.ph"), onChange: (e) => fbSet({ steps: e.target.value }) }),
|
|
246
|
+
/* @__PURE__ */ jsxs("details", { style: { marginBottom: 10 }, children: [
|
|
247
|
+
/* @__PURE__ */ jsx("summary", { style: { fontSize: 11, color: "var(--text-muted)", cursor: "pointer", userSelect: "none" }, children: t("fb.field.context") }),
|
|
248
|
+
/* @__PURE__ */ jsx("textarea", { style: { ...input, height: 64, minHeight: 64, resize: "vertical", marginTop: 6 }, value: s.context, placeholder: t("fb.field.context.ph"), onChange: (e) => fbSet({ context: e.target.value }) })
|
|
249
|
+
] }),
|
|
250
|
+
/* @__PURE__ */ jsx("div", { style: { display: "flex", alignItems: "center", gap: 8, marginBottom: 10 }, children: /* @__PURE__ */ jsx("input", { style: { width: "100%", boxSizing: "border-box", padding: "6px 9px", borderRadius: 7, border: "1px solid var(--border)", background: "var(--bg-input, transparent)", color: "var(--text)", fontSize: 12.5 }, value: s.contact, placeholder: t("fb.field.contact"), onChange: (e) => fbSet({ contact: e.target.value }) }) }),
|
|
251
|
+
/* @__PURE__ */ jsxs("label", { style: { display: "flex", alignItems: "center", gap: 6, fontSize: 12, color: "var(--text-muted)", marginBottom: 10, cursor: "pointer" }, children: [
|
|
252
|
+
/* @__PURE__ */ jsx("input", { type: "checkbox", checked: s.includeEnv, onChange: (e) => fbSet({ includeEnv: e.target.checked }) }),
|
|
253
|
+
t("fb.opt.env")
|
|
254
|
+
] }),
|
|
255
|
+
/* @__PURE__ */ jsx("label", { style: fieldLabel, children: t("fb.preview") }),
|
|
256
|
+
/* @__PURE__ */ jsx("pre", { style: { margin: "0 0 10px", padding: 10, borderRadius: 8, border: "1px solid var(--border)", background: "color-mix(in srgb, var(--text) 4%, transparent)", fontSize: 11, fontFamily: "var(--font-mono)", maxHeight: 160, overflow: "auto", whiteSpace: "pre-wrap", wordBreak: "break-word", color: "var(--text-muted)" }, children: md }),
|
|
257
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: 8, flexWrap: "wrap" }, children: [
|
|
258
|
+
/* @__PURE__ */ jsxs(
|
|
259
|
+
"button",
|
|
260
|
+
{
|
|
261
|
+
type: "button",
|
|
262
|
+
style: btn,
|
|
263
|
+
onClick: () => {
|
|
264
|
+
void copyText(issue.fullBody).then((ok) => fbSet({ copied: ok, hint: ok ? "" : t("fb.err.copyFailed") }));
|
|
265
|
+
},
|
|
266
|
+
children: [
|
|
267
|
+
/* @__PURE__ */ jsx(Ic, { size: 12, paths: ICONS.copy }),
|
|
268
|
+
s.copied ? t("fb.copied") : t("fb.copy")
|
|
269
|
+
]
|
|
270
|
+
}
|
|
271
|
+
),
|
|
272
|
+
/* @__PURE__ */ jsx("button", { type: "button", style: { ...btnPrimary, opacity: missing ? 0.5 : 1 }, onClick: submit, title: missing ? t("fb.err.descRequired") : void 0, children: t("fb.submit") }),
|
|
273
|
+
/* @__PURE__ */ jsx("span", { style: { fontSize: 11, color: issue.truncated ? "var(--danger, #ef4444)" : "var(--text-dim)" }, children: issue.truncated ? t("fb.err.tooLong") : `${md.length} / ${BODY_SAFE}` })
|
|
274
|
+
] }),
|
|
275
|
+
s.hint && /* @__PURE__ */ jsx("div", { style: { marginTop: 8, fontSize: 11.5, color: "var(--danger, #ef4444)" }, children: s.hint })
|
|
276
|
+
]
|
|
277
|
+
}
|
|
278
|
+
) });
|
|
279
|
+
}
|
|
280
|
+
function register(ctx) {
|
|
281
|
+
__setCtx(ctx);
|
|
282
|
+
ctx.registerItems("toolbar", [{
|
|
283
|
+
id: "aiti-feedback-open",
|
|
284
|
+
meta: {
|
|
285
|
+
label: "i18n:fb.open.label",
|
|
286
|
+
title: "i18n:fb.open.title",
|
|
287
|
+
icon: "icons/message-circle.svg",
|
|
288
|
+
onClick: () => openFeedback()
|
|
289
|
+
}
|
|
290
|
+
}]);
|
|
291
|
+
ctx.registerItems("dialogs", [{ id: "aiti-feedback-dialog", render: FeedbackDialog }]);
|
|
292
|
+
}
|
|
293
|
+
export {
|
|
294
|
+
register as default
|
|
295
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 9a2 2 0 0 1-2 2H6l-4 4V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2z"/><path d="M18 9h2a2 2 0 0 1 2 2v11l-4-4h-6a2 2 0 0 1-2-2v-1"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M7.9 20A9 9 0 1 0 4 16.1L2 22Z"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/><path d="M13 8H7"/><path d="M17 12H7"/></svg>
|
package/index.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* aiti-feedback · user feedback extension (pure client: compose a sanitized
|
|
3
|
+
* report → open a prefilled GitHub issue).
|
|
4
|
+
*
|
|
5
|
+
* No server API; zero tokens — the user logs into GitHub themselves and
|
|
6
|
+
* submits; the dialog preview IS the final content (sanitized, user-confirmed
|
|
7
|
+
* before redirect). Plan: pi-work docs/aiti-feedback-plan.md.
|
|
8
|
+
*/
|
|
9
|
+
export default {
|
|
10
|
+
id: "aiti-feedback",
|
|
11
|
+
name: "报告问题",
|
|
12
|
+
icon: "icons/message-square-text.svg",
|
|
13
|
+
client: "dist/aiti-feedback-client.mjs",
|
|
14
|
+
|
|
15
|
+
ui: {
|
|
16
|
+
clientImmediately: false,
|
|
17
|
+
toolbar: [{ id: "aiti-feedback-open", label: "i18n:fb.open.label", title: "i18n:fb.open.title", icon: "icons/discussion.svg" }],
|
|
18
|
+
dialogs: [{ id: "aiti-feedback-dialog", label: "i18n:fb.open.label" }],
|
|
19
|
+
// Full tables per locale (host locales are exactly "zh-CN" / "en"; zh-TW kept
|
|
20
|
+
// for parity with other extensions). Keys are abstract ids — no fallback to
|
|
21
|
+
// bare source strings, so every locale must be complete.
|
|
22
|
+
i18n: {
|
|
23
|
+
"zh-CN": {
|
|
24
|
+
"fb.open.label": "报告问题",
|
|
25
|
+
"fb.open.title": "报告问题 / 提供反馈",
|
|
26
|
+
"fb.close": "关闭",
|
|
27
|
+
"fb.hint.disclaimer": "将以 GitHub issue 打开(预填内容);提交前请确认不含敏感信息。",
|
|
28
|
+
"fb.kind": "类型",
|
|
29
|
+
"fb.kind.bug": "问题",
|
|
30
|
+
"fb.kind.suggestion": "建议",
|
|
31
|
+
"fb.kind.other": "其他",
|
|
32
|
+
"fb.field.title": "标题",
|
|
33
|
+
"fb.field.title.ph": "一句话摘要",
|
|
34
|
+
"fb.field.desc": "描述(必填)",
|
|
35
|
+
"fb.field.desc.ph": "发生了什么?期望是什么?",
|
|
36
|
+
"fb.field.steps": "复现步骤(可选)",
|
|
37
|
+
"fb.field.steps.ph": "1. 打开…\n2. 点击…",
|
|
38
|
+
"fb.field.context": "+ 会话上下文(可选,自行粘贴)",
|
|
39
|
+
"fb.field.context.ph": "粘贴相关日志/输出(将做脱敏处理,预览里请再确认)",
|
|
40
|
+
"fb.field.contact": "联系方式(可选:邮箱等,公开可见)",
|
|
41
|
+
"fb.opt.env": "附带环境信息(浏览器/平台,不含会话内容)",
|
|
42
|
+
"fb.preview": "预览(将提交的内容,已脱敏)",
|
|
43
|
+
"fb.copy": "复制全文",
|
|
44
|
+
"fb.copied": "已复制全文",
|
|
45
|
+
"fb.copyFailed": "复制失败",
|
|
46
|
+
"fb.submit": "前往 GitHub 提交",
|
|
47
|
+
"fb.err.descRequired": "描述是必填项",
|
|
48
|
+
"fb.err.copyFailed": "复制失败",
|
|
49
|
+
"fb.err.tooLong": "内容超长已截断,完整内容已复制到剪贴板",
|
|
50
|
+
},
|
|
51
|
+
en: {
|
|
52
|
+
"ext.displayName": "Report a Problem",
|
|
53
|
+
"fb.open.label": "Report an issue",
|
|
54
|
+
"fb.open.title": "Report an issue / send feedback",
|
|
55
|
+
"fb.close": "Close",
|
|
56
|
+
"fb.hint.disclaimer": "Opens a prefilled GitHub issue; review the preview and make sure it carries nothing sensitive before submitting.",
|
|
57
|
+
"fb.kind": "Type",
|
|
58
|
+
"fb.kind.bug": "Bug",
|
|
59
|
+
"fb.kind.suggestion": "Suggestion",
|
|
60
|
+
"fb.kind.other": "Other",
|
|
61
|
+
"fb.field.title": "Title",
|
|
62
|
+
"fb.field.title.ph": "one-line summary",
|
|
63
|
+
"fb.field.desc": "Description (required)",
|
|
64
|
+
"fb.field.desc.ph": "What happened? What did you expect?",
|
|
65
|
+
"fb.field.steps": "Steps to reproduce (optional)",
|
|
66
|
+
"fb.field.steps.ph": "1. Open…\n2. Click…",
|
|
67
|
+
"fb.field.context": "+ Session context (optional, paste yourself)",
|
|
68
|
+
"fb.field.context.ph": "Paste relevant logs/output (sanitized; double-check in the preview)",
|
|
69
|
+
"fb.field.contact": "Contact (optional: email etc., publicly visible)",
|
|
70
|
+
"fb.opt.env": "Include environment info (browser/platform; no session content)",
|
|
71
|
+
"fb.preview": "Preview (what will be submitted, sanitized)",
|
|
72
|
+
"fb.copy": "Copy full text",
|
|
73
|
+
"fb.copied": "Full text copied",
|
|
74
|
+
"fb.copyFailed": "Copy failed",
|
|
75
|
+
"fb.submit": "Open GitHub to submit",
|
|
76
|
+
"fb.err.descRequired": "Description is required",
|
|
77
|
+
"fb.err.copyFailed": "Copy failed",
|
|
78
|
+
"fb.err.tooLong": "Too long for GitHub prefill — truncated; full text copied to clipboard",
|
|
79
|
+
},
|
|
80
|
+
"zh-TW": {
|
|
81
|
+
"fb.open.label": "回報問題",
|
|
82
|
+
"fb.open.title": "回報問題 / 提供建議",
|
|
83
|
+
"fb.close": "關閉",
|
|
84
|
+
"fb.hint.disclaimer": "將以 GitHub issue 打開(預填內容);提交前請確認不含敏感資訊。",
|
|
85
|
+
"fb.kind": "類型",
|
|
86
|
+
"fb.kind.bug": "問題",
|
|
87
|
+
"fb.kind.suggestion": "建議",
|
|
88
|
+
"fb.kind.other": "其他",
|
|
89
|
+
"fb.field.title": "標題",
|
|
90
|
+
"fb.field.title.ph": "一句話摘要",
|
|
91
|
+
"fb.field.desc": "描述(必填)",
|
|
92
|
+
"fb.field.desc.ph": "發生了什麼?期望是什麼?",
|
|
93
|
+
"fb.field.steps": "重現步驟(可選)",
|
|
94
|
+
"fb.field.steps.ph": "1. 打開…\n2. 點擊…",
|
|
95
|
+
"fb.field.context": "+ 會話上下文(可選,自行貼上)",
|
|
96
|
+
"fb.field.context.ph": "貼上相關日誌/輸出(將做脫敏處理,預覽裡請再確認)",
|
|
97
|
+
"fb.field.contact": "聯繫方式(可選:信箱等,公開可見)",
|
|
98
|
+
"fb.opt.env": "附帶環境資訊(瀏覽器/平台,不含會話內容)",
|
|
99
|
+
"fb.preview": "預覽(將提交的內容,已脫敏)",
|
|
100
|
+
"fb.copy": "複製全文",
|
|
101
|
+
"fb.copied": "已複製全文",
|
|
102
|
+
"fb.copyFailed": "複製失敗",
|
|
103
|
+
"fb.submit": "前往 GitHub 提交",
|
|
104
|
+
"fb.err.descRequired": "描述為必填項",
|
|
105
|
+
"fb.err.copyFailed": "複製失敗",
|
|
106
|
+
"fb.err.tooLong": "內容超長已截斷,完整內容已複製到剪貼簿",
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiti-ai/aiti-feedback",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "User feedback — compose a sanitized report and open a prefilled GitHub issue",
|
|
6
|
+
"displayNameI18n": {
|
|
7
|
+
"en": "Report a Problem"
|
|
8
|
+
},
|
|
9
|
+
"descriptionI18n": {
|
|
10
|
+
"zh-CN": "用户反馈 —— 撰写脱敏报告并打开预填好的 GitHub issue"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build:client": "vite build --config vite.config.ts",
|
|
14
|
+
"watch": "vite build --watch --config vite.config.ts",
|
|
15
|
+
"deploy": "node tools/deploy.mjs"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"vite": "^6.4.3"
|
|
19
|
+
},
|
|
20
|
+
"aitiExtProtocol": "1.0",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/aiti-ai/aiti-ai.git",
|
|
25
|
+
"directory": "extensions/aiti-feedback"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/aiti-ai/aiti-ai#readme",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/aiti-ai/aiti-ai/issues"
|
|
30
|
+
},
|
|
31
|
+
"contentHash": "ed6f3fd0cf2e515f"
|
|
32
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Build the JSX client bundle (Vite lib mode → dist/<your-ext>-client.mjs)
|
|
4
|
+
*
|
|
5
|
+
* Wraps `vite build`, making sure vite resolves from this extension's own
|
|
6
|
+
* node_modules (the extension does not depend on the host install).
|
|
7
|
+
* Sources: client/src/*.tsx; config: vite.config.ts.
|
|
8
|
+
*
|
|
9
|
+
* Usage: node tools/build-client.mjs
|
|
10
|
+
* npm run watch (vite build --watch, rebuild on change → HMR with the
|
|
11
|
+
* frontend rev poller)
|
|
12
|
+
*/
|
|
13
|
+
import { spawnSync } from "node:child_process";
|
|
14
|
+
import { createRequire } from "node:module";
|
|
15
|
+
import { resolve } from "node:path";
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
17
|
+
import { existsSync } from "node:fs";
|
|
18
|
+
|
|
19
|
+
const root = resolve(fileURLToPath(new URL("..", import.meta.url)));
|
|
20
|
+
|
|
21
|
+
// On Windows, spawning .bin/vite (an sh script without extension) fails
|
|
22
|
+
// silently with status=null; run vite.js directly via node on every platform
|
|
23
|
+
// (the real target behind the .bin shim — what npm scripts do internally).
|
|
24
|
+
const viteJs = resolve(root, "node_modules", "vite", "bin", "vite.js");
|
|
25
|
+
const viteBin = existsSync(viteJs) ? viteJs : resolve(createRequire(import.meta.url).resolve("vite/package.json"), "..", "bin", "vite.js");
|
|
26
|
+
|
|
27
|
+
const r = spawnSync(process.execPath, [viteBin, "build", "--config", resolve(root, "vite.config.ts")], {
|
|
28
|
+
cwd: root,
|
|
29
|
+
stdio: "inherit",
|
|
30
|
+
shell: false,
|
|
31
|
+
});
|
|
32
|
+
if (r.status !== 0) {
|
|
33
|
+
console.error("[ext-jsx] vite build failed (exit " + r.status + "). If vite is missing: cd <ext-dir> && npm install");
|
|
34
|
+
process.exit(r.status ?? 1);
|
|
35
|
+
}
|
|
36
|
+
console.log("[ext-jsx] JSX client bundle built → dist/ (see vite.config.ts fileName)");
|
package/tools/deploy.mjs
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* aiti-feedback · deploy to ~/.pi/web/extensions/ and ~/.pi/web-dev/extensions/
|
|
4
|
+
*
|
|
5
|
+
* 0) build the JSX client bundle (client/src → dist/aiti-feedback-client.mjs)
|
|
6
|
+
* 1) copy server files (index.ts / package.json) to both instances
|
|
7
|
+
* 2) copy the client bundle to dist/
|
|
8
|
+
* 3) icons from _shared/icons (discussion / message-square-text / message-circle)
|
|
9
|
+
* 4) deploy commit + dual-instance hot reload (env ports per machine)
|
|
10
|
+
*/
|
|
11
|
+
import { copyFileSync, mkdirSync, existsSync } from "node:fs";
|
|
12
|
+
import { resolve } from "node:path";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
import { homedir } from "node:os";
|
|
15
|
+
import { execSync } from "node:child_process";
|
|
16
|
+
import { deployCommit } from "../../_shared/deploy-commit.mjs";
|
|
17
|
+
import { copyIcons } from "../../_shared/ext-icons-deploy.mjs";
|
|
18
|
+
|
|
19
|
+
// client TS residue check (.mjs hides bad TS syntax from syntax checks; it explodes at runtime)
|
|
20
|
+
{
|
|
21
|
+
const { checkClientDir } = await import("../../_shared/check-client.mjs");
|
|
22
|
+
checkClientDir(fileURLToPath(new URL("../client", import.meta.url)), { log: (m) => console.log("[deploy] " + m) });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const root = resolve(import.meta.dirname, "..");
|
|
26
|
+
const targets = [
|
|
27
|
+
resolve(homedir(), ".pi", "web", "extensions", "aiti-feedback"),
|
|
28
|
+
resolve(homedir(), ".pi", "web-dev", "extensions", "aiti-feedback"),
|
|
29
|
+
];
|
|
30
|
+
const extRepo = resolve(homedir(), ".pi", "web", "extensions");
|
|
31
|
+
|
|
32
|
+
console.log("[deploy] build JSX client bundle…");
|
|
33
|
+
try {
|
|
34
|
+
execSync("node tools/build-client.mjs", { cwd: root, stdio: "inherit" });
|
|
35
|
+
} catch (e) {
|
|
36
|
+
console.error("[deploy] build failed, abort:", e.message);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
for (const extDir of targets) {
|
|
41
|
+
mkdirSync(extDir, { recursive: true });
|
|
42
|
+
for (const f of ["package.json", "index.ts"]) {
|
|
43
|
+
copyFileSync(resolve(root, f), resolve(extDir, f));
|
|
44
|
+
console.log("[deploy] src → " + resolve(extDir, f));
|
|
45
|
+
}
|
|
46
|
+
const clientDir = resolve(extDir, "dist");
|
|
47
|
+
mkdirSync(clientDir, { recursive: true });
|
|
48
|
+
copyFileSync(resolve(root, "dist/aiti-feedback-client.mjs"), resolve(clientDir, "aiti-feedback-client.mjs"));
|
|
49
|
+
console.log("[deploy] client → " + resolve(clientDir, "aiti-feedback-client.mjs"));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
for (const t of targets) copyIcons(resolve(t, "icons"), ["discussion", "message-square-text", "message-circle"], { log: (m) => console.log(m) });
|
|
53
|
+
|
|
54
|
+
deployCommit({ repo: extRepo, name: "aiti-feedback", paths: ["aiti-feedback"], ident: true, log: (m) => console.log("[deploy] " + m) });
|
|
55
|
+
|
|
56
|
+
console.log("[deploy] done. Reload via POST /api/extensions/reload; client refreshes on page reload");
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const { reloadInstances } = await import("../../_shared/reload-instances.mjs");
|
|
60
|
+
await reloadInstances();
|
|
61
|
+
} catch (e) {
|
|
62
|
+
console.log("[deploy] auto reload skipped (" + String((e && e.message) || e) + ")");
|
|
63
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* aiti-feedback client build (Vite lib mode) — JSX template instance.
|
|
3
|
+
*
|
|
4
|
+
* client/src/entry.tsx (JSX + TS) → single ESM bundle: dist/aiti-feedback-client.mjs
|
|
5
|
+
* (matches the client field in index.ts).
|
|
6
|
+
*
|
|
7
|
+
* Template & notes: extensions/templates/ext-jsx-client/ — three known pitfalls
|
|
8
|
+
* (jsx automatic / regex alias / external []) are already handled; do not regress.
|
|
9
|
+
*/
|
|
10
|
+
import { defineConfig } from "vite";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
12
|
+
|
|
13
|
+
export default defineConfig({
|
|
14
|
+
esbuild: {
|
|
15
|
+
jsx: "automatic",
|
|
16
|
+
jsxImportSource: "react",
|
|
17
|
+
},
|
|
18
|
+
resolve: {
|
|
19
|
+
alias: [
|
|
20
|
+
// Regex-exact matches (string alias is prefix matching; 'react' would swallow 'react/jsx-runtime')
|
|
21
|
+
{ find: /^react\/jsx-dev-runtime$/, replacement: fileURLToPath(new URL("client/src/jsx-runtime.ts", import.meta.url)) },
|
|
22
|
+
{ find: /^react\/jsx-runtime$/, replacement: fileURLToPath(new URL("client/src/jsx-runtime.ts", import.meta.url)) },
|
|
23
|
+
{ find: /^react$/, replacement: fileURLToPath(new URL("client/src/host-shim.ts", import.meta.url)) },
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
build: {
|
|
27
|
+
lib: {
|
|
28
|
+
entry: fileURLToPath(new URL("client/src/entry.tsx", import.meta.url)),
|
|
29
|
+
formats: ["es"],
|
|
30
|
+
fileName: () => "aiti-feedback-client.mjs",
|
|
31
|
+
},
|
|
32
|
+
outDir: "dist",
|
|
33
|
+
emptyOutDir: true,
|
|
34
|
+
target: "es2020",
|
|
35
|
+
minify: false,
|
|
36
|
+
sourcemap: false,
|
|
37
|
+
rollupOptions: {
|
|
38
|
+
external: [], // everything inlines into a single .mjs
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
});
|