@aiti-ai/aiti-msg-share 0.0.0-stage → 0.1.8
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.md +115 -2
- package/client/src/index.js +806 -0
- package/dist/aiti-msg-share-client.mjs +3346 -0
- package/docs/README.zh-CN.md +83 -0
- package/icon.svg +1 -0
- package/icons/share-2.svg +1 -0
- package/index.ts +602 -0
- package/lib/share-core.mjs +144 -0
- package/package.json +29 -4
- package/skills/configure-target/SKILL.md +56 -0
- package/skills/import-sxcu/SKILL.md +30 -0
- package/skills/index.json +1 -0
- package/skills/troubleshoot/SKILL.md +35 -0
- package/test/share-core.test.mjs +61 -0
- package/tools/build-client.mjs +10 -0
- package/tools/deploy.mjs +32 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* aiti-msg-share · server-side core (pure JS, unit-testable without the host).
|
|
3
|
+
*
|
|
4
|
+
* Owns: persisted targets (0600), share history (state layer), redaction via
|
|
5
|
+
* @aiti-ai/secret-mask-core, provider dispatch via @aiti-ai/content-share.
|
|
6
|
+
* No UI / DOM / host API in here.
|
|
7
|
+
*/
|
|
8
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, chmodSync } from "node:fs";
|
|
9
|
+
import { join, dirname } from "node:path";
|
|
10
|
+
|
|
11
|
+
const HISTORY_MAX = 200;
|
|
12
|
+
|
|
13
|
+
/** Files above this size are rejected before reading (provider limits are checked later). */
|
|
14
|
+
export const MAX_SHARE_FILE_BYTES = 200 * 1024 * 1024;
|
|
15
|
+
|
|
16
|
+
const IMAGE_MIME = {
|
|
17
|
+
png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", gif: "image/gif",
|
|
18
|
+
webp: "image/webp", bmp: "image/bmp", svg: "image/svg+xml", ico: "image/x-icon", avif: "image/avif",
|
|
19
|
+
};
|
|
20
|
+
const TEXT_EXT = new Set([
|
|
21
|
+
"txt", "md", "markdown", "json", "js", "mjs", "cjs", "ts", "tsx", "jsx", "py", "rb", "go", "rs", "java",
|
|
22
|
+
"c", "h", "cpp", "hpp", "cs", "php", "sh", "bash", "zsh", "yml", "yaml", "toml", "ini", "cfg", "conf",
|
|
23
|
+
"csv", "tsv", "log", "html", "htm", "css", "scss", "xml", "sql", "env", "properties", "gradle", "vim",
|
|
24
|
+
"dockerfile", "makefile", "gitignore", "license",
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Classify a shared file: image (binary, image/* mime), text (decoded as utf8),
|
|
29
|
+
* or binary (byte-exact buffer, application/octet-stream). Mirrors the client's
|
|
30
|
+
* kind filter so both ends agree on what the content is.
|
|
31
|
+
*/
|
|
32
|
+
export function classifyFile(filename) {
|
|
33
|
+
const ext = String(filename || "").split(".").pop()?.toLowerCase() || "";
|
|
34
|
+
if (IMAGE_MIME[ext]) return { kind: "image", mime: IMAGE_MIME[ext] };
|
|
35
|
+
if (TEXT_EXT.has(ext)) return { kind: "text", mime: "text/plain" };
|
|
36
|
+
// Executables/scripts without extension sometimes carry a shebang — still treat
|
|
37
|
+
// unknown types as binary: byte-exact upload never corrupts, utf8 decode can.
|
|
38
|
+
return { kind: "binary", mime: "application/octet-stream" };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Mask a secret for display: keep first 2 / last 4 chars only. */
|
|
42
|
+
export function maskSecret(value) {
|
|
43
|
+
if (!value || typeof value !== "string") return "";
|
|
44
|
+
if (value.length <= 6) return "****";
|
|
45
|
+
return value.slice(0, 2) + "*".repeat(Math.min(18, value.length - 6)) + value.slice(-4);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Sanitize a target for API responses (never echo raw secrets). */
|
|
49
|
+
export function publicTarget(target, provider) {
|
|
50
|
+
const secretKeys = new Set((provider?.metaFields || [])
|
|
51
|
+
.filter((f) => f.type === "password" || /key|token|secret|password|hash/i.test(f.key))
|
|
52
|
+
.map((f) => f.key));
|
|
53
|
+
return {
|
|
54
|
+
...target,
|
|
55
|
+
values: Object.fromEntries(Object.entries(target.values || {}).map(([k, v]) =>
|
|
56
|
+
[k, secretKeys.has(k) && v ? maskSecret(v) : v])),
|
|
57
|
+
secretKeys: [...secretKeys],
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Redact secrets in text using secret-mask-core's deterministic rules. */
|
|
62
|
+
export function makeRedactor(engine) {
|
|
63
|
+
const { scan, fnv1a } = engine;
|
|
64
|
+
return (text) => {
|
|
65
|
+
const hits = scan(text, { maxBytes: 4 * 1024 * 1024 });
|
|
66
|
+
if (!hits.length) return { text, hits: [] };
|
|
67
|
+
let out = "";
|
|
68
|
+
let cursor = 0;
|
|
69
|
+
const counts = new Map();
|
|
70
|
+
for (const hit of hits) {
|
|
71
|
+
out += text.slice(cursor, hit.start);
|
|
72
|
+
const label = String(hit.label || hit.id).replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 40);
|
|
73
|
+
const token = `[REDACTED:${label}#${fnv1a(hit.value).slice(0, 8)}]`;
|
|
74
|
+
out += token;
|
|
75
|
+
cursor = hit.end;
|
|
76
|
+
counts.set(label, (counts.get(label) || 0) + 1);
|
|
77
|
+
}
|
|
78
|
+
out += text.slice(cursor);
|
|
79
|
+
return { text: out, hits: [...counts].map(([rule, count]) => ({ rule, count })) };
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export class ShareStore {
|
|
84
|
+
constructor(configDir, stateDir) {
|
|
85
|
+
this.targetsFile = join(configDir, "targets.json");
|
|
86
|
+
this.historyFile = join(stateDir, "shares.json");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
readTargets() {
|
|
90
|
+
try { return JSON.parse(readFileSync(this.targetsFile, "utf8")); }
|
|
91
|
+
catch { return []; }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
writeTargets(targets) {
|
|
95
|
+
mkdirSync(dirname(this.targetsFile), { recursive: true });
|
|
96
|
+
writeFileSync(this.targetsFile, JSON.stringify(targets, null, 2));
|
|
97
|
+
chmodSync(this.targetsFile, 0o600);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
upsertTarget(target) {
|
|
101
|
+
const all = this.readTargets();
|
|
102
|
+
const i = all.findIndex((t) => t.id === target.id);
|
|
103
|
+
if (i < 0) all.push(target); else all[i] = target;
|
|
104
|
+
this.writeTargets(all);
|
|
105
|
+
return target;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
deleteTarget(id) {
|
|
109
|
+
this.writeTargets(this.readTargets().filter((t) => t.id !== id));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
readHistory() {
|
|
113
|
+
try { return JSON.parse(readFileSync(this.historyFile, "utf8")); }
|
|
114
|
+
catch { return []; }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
appendHistory(record) {
|
|
118
|
+
const all = this.readHistory();
|
|
119
|
+
all.unshift(record);
|
|
120
|
+
mkdirSync(dirname(this.historyFile), { recursive: true });
|
|
121
|
+
writeFileSync(this.historyFile, JSON.stringify(all.slice(0, HISTORY_MAX), null, 2));
|
|
122
|
+
return record;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Export a session's messages to markdown (tool output folded by default). */
|
|
127
|
+
export function exportSessionMarkdown(session, opts = {}) {
|
|
128
|
+
const { full = false, title = "", tags = [] } = opts;
|
|
129
|
+
const lines = [];
|
|
130
|
+
if (title || tags.length) {
|
|
131
|
+
lines.push("---", ...(title ? [`title: ${title}`] : []), ...(tags.length ? [`tags: [${tags.join(", ")}]`] : []), "---", "");
|
|
132
|
+
}
|
|
133
|
+
for (const m of session?.messages || []) {
|
|
134
|
+
const role = m.role === "user" ? "User" : m.role === "assistant" ? "Assistant" : m.role;
|
|
135
|
+
lines.push(`## ${role}`, "");
|
|
136
|
+
const content = typeof m.content === "string" ? m.content
|
|
137
|
+
: Array.isArray(m.content) ? m.content.map((b) => b?.text || b?.content || "").join("\n") : String(m.content ?? "");
|
|
138
|
+
if (!full && content.length > 2000) lines.push(content.slice(0, 1000), `\n_… ${content.length - 2000} chars folded (full export available)_`, content.slice(-1000));
|
|
139
|
+
else lines.push(content);
|
|
140
|
+
lines.push("");
|
|
141
|
+
}
|
|
142
|
+
return lines.join("\n");
|
|
143
|
+
}
|
|
144
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiti-ai/aiti-msg-share",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.8",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Share sessions, messages, selections, files and images through pluggable targets with secret redaction and QR codes",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"aitiExtProtocol": "1.0",
|
|
8
|
+
"soul": "分享出去,是为了让对话继续。",
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@aiti-ai/content-share": "^0.1.11",
|
|
11
|
+
"@aiti-ai/secret-mask-core": "^0.1.0",
|
|
12
|
+
"qrcode": "^1.5.4"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"esbuild": "^0.24.2"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build:client": "node tools/build-client.mjs",
|
|
19
|
+
"test": "node --test test/*.test.mjs"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/aiti-ai/aiti-ai.git",
|
|
24
|
+
"directory": "extensions/aiti-msg-share"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/aiti-ai/aiti-ai#readme",
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/aiti-ai/aiti-ai/issues"
|
|
29
|
+
},
|
|
30
|
+
"contentHash": "603e2fa84e7f66a0"
|
|
31
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: configure-target
|
|
3
|
+
title: AI 帮我配置分享目标
|
|
4
|
+
title.en: "AI: set up a share target"
|
|
5
|
+
summary: 一步步拿到并填入 Gitee / ImgBB / 兰空 / OSS / Joplin / memos 等平台的 token 或密钥,再测活保存
|
|
6
|
+
summary.en: Walk through obtaining and storing an access token/key for Gitee, ImgBB, Lsky, OSS, Joplin, memos, then verify it.
|
|
7
|
+
placeholder: 说你要配哪个平台,或直接把 token 贴给我(如:配 Gitee 分享 / 这是我的兰空 token xxx)…
|
|
8
|
+
placeholder.en: Name the platform you want to configure, or paste the token (e.g. set up Gitee sharing / here is my Lsky token)…
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Configure a share target
|
|
12
|
+
|
|
13
|
+
You are helping the user set up a **aiti-msg-share** target. The user may say
|
|
14
|
+
"help me configure Gitee sharing" or paste a token. Follow these steps:
|
|
15
|
+
|
|
16
|
+
## 1. Identify the provider
|
|
17
|
+
|
|
18
|
+
Check the target list (the share dialog → "Add more…" → target manager). If no
|
|
19
|
+
provider is named, ask which one: Gitee Snippet (text, China), Lsky Pro (images),
|
|
20
|
+
Alibaba OSS (any file), ImgBB (images), Joplin (local notes), memos (self-hosted).
|
|
21
|
+
|
|
22
|
+
## 2. Guide credential creation — exact paths
|
|
23
|
+
|
|
24
|
+
- **Gitee Snippet**: open https://gitee.com/profile/personal_access_tokens →
|
|
25
|
+
generate a personal access token with the `gists` scope → paste into the
|
|
26
|
+
"token" field. Target config: `access_token`.
|
|
27
|
+
- **ImgBB**: open https://api.imgbb.com/ → request a free API key (no card) →
|
|
28
|
+
paste into `key`.
|
|
29
|
+
- **Lsky Pro**: log in to your Lsky instance → 个人设置 → 图片 Token → copy the
|
|
30
|
+
Bearer token. Also set your instance endpoint in `RequestURL`.
|
|
31
|
+
- **Alibaba OSS**: RAM console → AccessKey management → create an AccessKey pair
|
|
32
|
+
(`accessKeyId`/`accessKeySecret`) → fill `endpoint` (e.g.
|
|
33
|
+
`oss-cn-hangzhou.aliyuncs.com`), `bucket`, and a `publicBaseUrl`.
|
|
34
|
+
- **Joplin**: Tools → Options → Web Clipper → enable the clipper service and copy
|
|
35
|
+
the authorization token. API runs at `http://localhost:41184`.
|
|
36
|
+
- **memos**: Settings → Access Tokens → create; API at `http://localhost:5230`.
|
|
37
|
+
- **Obsidian Local REST**: install the Local REST API plugin → copy its API key;
|
|
38
|
+
API at `http://localhost:27123`.
|
|
39
|
+
|
|
40
|
+
## 3. Store and verify
|
|
41
|
+
|
|
42
|
+
Open the target manager, pick the provider, fill the fields, then click
|
|
43
|
+
**Save & test**. Confirm the status turns green (✓ Configured) before using it.
|
|
44
|
+
Or via API: `POST /api/extensions/aiti-msg-share/targets` then
|
|
45
|
+
`POST .../targets/test`.
|
|
46
|
+
|
|
47
|
+
## Rules
|
|
48
|
+
|
|
49
|
+
- **Never echo a full token back** into chat, logs, commits or files. Masks like
|
|
50
|
+
`gh3e****d21c` are fine.
|
|
51
|
+
- Credentials are stored only in `configDir/targets.json` with mode 0600; uploads
|
|
52
|
+
go through the extension server proxy (browser never sees the token).
|
|
53
|
+
- If the test fails, report the HTTP status and reason; do not guess secrets.
|
|
54
|
+
- If the service is unreachable from this machine (e.g. `catbox.moe` returns
|
|
55
|
+
"fetch failed"), suggest a China-friendly target (Gitee / Lsky / OSS) or
|
|
56
|
+
`local-link`.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: import-sxcu
|
|
3
|
+
title: AI 帮我导入 ShareX .sxcu 配置
|
|
4
|
+
title.en: "AI: import a ShareX .sxcu config"
|
|
5
|
+
summary: 校验 .sxcu 配置的兼容性并注册为新的分享目标(ShareX 官方仓 148 份配置可直接用)
|
|
6
|
+
summary.en: Validate a .sxcu config's compatibility and register it as a new share target.
|
|
7
|
+
placeholder: 粘贴 .sxcu JSON,或给出配置来源(如 ShareX CustomUploaders 里的某个服务名)…
|
|
8
|
+
placeholder.en: Paste the .sxcu JSON, or name the service from the ShareX CustomUploaders catalog.
|
|
9
|
+
description: Import a ShareX .sxcu custom-uploader config as a new aiti-msg-share target, with compatibility report.
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Import a ShareX .sxcu config
|
|
13
|
+
|
|
14
|
+
The user provides a `.sxcu` JSON config (file, pasted JSON, or a URL from the
|
|
15
|
+
[ShareX CustomUploaders catalog](https://github.com/ShareX/CustomUploaders)).
|
|
16
|
+
|
|
17
|
+
1. Parse and validate: required `RequestURL`; check `Body` is one of
|
|
18
|
+
`MultipartFormData` / `JSON` / `FormURLEncoded` / `Binary` / `XML`;
|
|
19
|
+
`DestinationType` maps to text/image/file kinds.
|
|
20
|
+
2. Report compatibility before import:
|
|
21
|
+
- Full support: `$json:path$`, `$regex:N$`, `$base64:`, `$header:`,
|
|
22
|
+
`{{content}}/{{title}}/{{tags}}` variables.
|
|
23
|
+
- Partial: other ShareX functions degrade to empty strings; note them.
|
|
24
|
+
- Placeholders like `<API KEY HERE>` become required fields in the target form.
|
|
25
|
+
3. Import via `POST /api/extensions/aiti-msg-share/import-sxcu` with the config.
|
|
26
|
+
4. Tell the user to open the target manager, fill any required credential
|
|
27
|
+
fields, and click **Test connection**.
|
|
28
|
+
|
|
29
|
+
Never invent credentials. If the config contains a hard-coded token, warn the
|
|
30
|
+
user to remove it before saving (configs are stored in plain text).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
["configure-target", "troubleshoot", "import-sxcu"]
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: troubleshoot
|
|
3
|
+
title: AI 帮我排查分享失败
|
|
4
|
+
title.en: "AI: troubleshoot a failed share"
|
|
5
|
+
summary: 读分享历史定位失败原因(网络不可达 / token 失效 / 内容超限 / 服务已关停),给出换目标或修配置的建议
|
|
6
|
+
summary.en: Read share history, classify the failure (network / token / size / dead service) and recommend a fix.
|
|
7
|
+
placeholder: 描述现象或直接说“分享失败了”(我会读最近历史诊断)…
|
|
8
|
+
placeholder.en: Describe the symptom, or just say "the share failed" and I will read the latest history.
|
|
9
|
+
description: Diagnose aiti-msg-share failures — read recent share history, classify the error (network/auth/size/dead service), and recommend a fix or alternative target.
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Troubleshoot a failed share
|
|
13
|
+
|
|
14
|
+
1. Read recent history via `GET /api/extensions/aiti-msg-share/history` (or the
|
|
15
|
+
share dialog → history). Look at the newest failing record: targetId, kind,
|
|
16
|
+
bytes, hits.
|
|
17
|
+
2. Classify the failure:
|
|
18
|
+
- **401/403 / "invalid token"** → target credential expired; re-run
|
|
19
|
+
`configure-target` for that provider.
|
|
20
|
+
- **413 / "Content too large"** → use the compact export (folded tool output)
|
|
21
|
+
or switch to OSS/Gofile (larger `maxBytes`).
|
|
22
|
+
- **timeout / fetch failed** → network reachability. For a local service
|
|
23
|
+
(Joplin :41184 / Obsidian :27123 / memos :5230), confirm the app is running
|
|
24
|
+
and its API is enabled. For overseas hosts, suggest a China-friendly target
|
|
25
|
+
(Gitee, Lsky, OSS).
|
|
26
|
+
- **HTTP 5xx from provider** → service-side outage; `metadata.json` marks
|
|
27
|
+
known dead/legacy services (`anonfiles`, `transfer.sh`, `0x0.st`, `uguu`).
|
|
28
|
+
Recommend another target via "Add more…".
|
|
29
|
+
- **"no URL in response"** → provider changed its response shape; an `.sxcu`
|
|
30
|
+
config update via the remote overlay or a manual URL-extraction fix is needed.
|
|
31
|
+
3. If the error is redaction-related, check the preview banner: the
|
|
32
|
+
`[REDACTED:*]` placeholders are intentional — disable "Share redaction" only
|
|
33
|
+
after the user explicitly accepts the risk.
|
|
34
|
+
|
|
35
|
+
Report the diagnosis in plain language with one concrete next action.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { mkdtempSync, readFileSync, statSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { ShareStore, makeRedactor, publicTarget, maskSecret, exportSessionMarkdown } from "../lib/share-core.mjs";
|
|
7
|
+
|
|
8
|
+
test("maskSecret keeps prefix/suffix only", () => {
|
|
9
|
+
assert.equal(maskSecret("sk-ant-api03-abcdefgh"), "sk***************efgh");
|
|
10
|
+
assert.equal(maskSecret("short"), "****");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("publicTarget masks password fields but keeps normal ones", () => {
|
|
14
|
+
const provider = { metaFields: [{ key: "token", type: "password" }, { key: "title", type: "text" }] };
|
|
15
|
+
const out = publicTarget({ id: "x", values: { token: "supersecretvalue", title: "Hello" } }, provider);
|
|
16
|
+
assert.notEqual(out.values.token, "supersecretvalue");
|
|
17
|
+
assert.equal(out.values.title, "Hello");
|
|
18
|
+
assert.ok(out.secretKeys.includes("token"));
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("makeRedactor: replaces detected secrets with stable placeholders", async () => {
|
|
22
|
+
const engine = await import("@aiti-ai/secret-mask-core");
|
|
23
|
+
const redactor = makeRedactor(engine);
|
|
24
|
+
const input = "export ANTHROPIC_API_KEY=sk-ant-api03-" + "A1b2C3d4E5f6G7h8I9j0K1l2";
|
|
25
|
+
const out = redactor(input);
|
|
26
|
+
assert.match(out.text, /\[REDACTED:[A-Za-z0-9_-]+#[0-9a-f]{8}\]/);
|
|
27
|
+
assert.equal(out.hits.length, 1);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("ShareStore targets file is 0600 and history wraps", () => {
|
|
31
|
+
const dir = mkdtempSync(join(tmpdir(), "share-store-"));
|
|
32
|
+
const store = new ShareStore(join(dir, "config"), join(dir, "state"));
|
|
33
|
+
store.upsertTarget({ id: "gitee", provider: "gitee-gist", values: { token: "secret" } });
|
|
34
|
+
assert.equal(statSync(store.targetsFile).mode & 0o777, 0o600);
|
|
35
|
+
assert.deepEqual(JSON.parse(readFileSync(store.targetsFile, "utf8"))[0].id, "gitee");
|
|
36
|
+
for (let i = 0; i < 205; i++) store.appendHistory({ url: `u${i}` });
|
|
37
|
+
const h = store.readHistory();
|
|
38
|
+
assert.equal(h.length, 200);
|
|
39
|
+
assert.equal(h[0].url, "u204");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("exportSessionMarkdown: role headers + folded tool output", () => {
|
|
43
|
+
const md = exportSessionMarkdown({ messages: [
|
|
44
|
+
{ role: "user", content: "hello" },
|
|
45
|
+
{ role: "assistant", content: "x".repeat(3000) },
|
|
46
|
+
] }, { title: "T", tags: ["a", "b"] });
|
|
47
|
+
assert.ok(md.startsWith("---\ntitle: T\ntags: [a, b]"));
|
|
48
|
+
assert.ok(md.includes("## User\n\nhello"));
|
|
49
|
+
assert.ok(md.includes("folded"));
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("classifyFile: image / text / binary by extension", async () => {
|
|
53
|
+
const { classifyFile } = await import("../lib/share-core.mjs");
|
|
54
|
+
assert.deepEqual(classifyFile("shot.png"), { kind: "image", mime: "image/png" });
|
|
55
|
+
assert.deepEqual(classifyFile("photo.JPG"), { kind: "image", mime: "image/jpeg" });
|
|
56
|
+
assert.deepEqual(classifyFile("notes.md"), { kind: "text", mime: "text/plain" });
|
|
57
|
+
assert.deepEqual(classifyFile("data.json"), { kind: "text", mime: "text/plain" });
|
|
58
|
+
assert.deepEqual(classifyFile("report.pdf"), { kind: "binary", mime: "application/octet-stream" });
|
|
59
|
+
assert.deepEqual(classifyFile("archive.tar.gz"), { kind: "binary", mime: "application/octet-stream" });
|
|
60
|
+
assert.deepEqual(classifyFile("noext"), { kind: "binary", mime: "application/octet-stream" });
|
|
61
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
const { build } = require("esbuild");
|
|
5
|
+
await build({
|
|
6
|
+
entryPoints: ["client/src/index.js"], bundle: true, format: "esm", platform: "browser",
|
|
7
|
+
target: ["es2020"], outfile: "dist/aiti-msg-share-client.mjs", logLevel: "warning",
|
|
8
|
+
banner: { js: "// aiti-msg-share client bundle — built by tools/build-client.mjs. Do not edit." },
|
|
9
|
+
});
|
|
10
|
+
console.log("[aiti-msg-share] client bundle → dist/aiti-msg-share-client.mjs");
|
package/tools/deploy.mjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/** aiti-msg-share · build + deploy to ~/.pi/web{,-dev}/extensions/. */
|
|
3
|
+
import { cpSync, rmSync, mkdirSync, existsSync } from "node:fs";
|
|
4
|
+
import { resolve } from "node:path";
|
|
5
|
+
import { homedir } from "node:os";
|
|
6
|
+
import { execSync } from "node:child_process";
|
|
7
|
+
import { deployCommit } from "../../_shared/deploy-commit.mjs";
|
|
8
|
+
|
|
9
|
+
const root = resolve(import.meta.dirname, "..");
|
|
10
|
+
console.log("[deploy] build client…");
|
|
11
|
+
execSync("node tools/build-client.mjs", { cwd: root, stdio: "inherit" });
|
|
12
|
+
const bundle = resolve(root, "dist/aiti-msg-share-client.mjs");
|
|
13
|
+
if (!existsSync(bundle)) { console.error("[deploy] bundle missing"); process.exit(1); }
|
|
14
|
+
|
|
15
|
+
for (const dir of [
|
|
16
|
+
resolve(homedir(), ".pi/web/extensions/aiti-msg-share"),
|
|
17
|
+
resolve(homedir(), ".pi/web-dev/extensions/aiti-msg-share"),
|
|
18
|
+
]) {
|
|
19
|
+
mkdirSync(resolve(dir, "dist"), { recursive: true });
|
|
20
|
+
cpSync(resolve(root, "index.ts"), resolve(dir, "index.ts"));
|
|
21
|
+
cpSync(resolve(root, "package.json"), resolve(dir, "package.json"));
|
|
22
|
+
cpSync(bundle, resolve(dir, "dist/aiti-msg-share-client.mjs"));
|
|
23
|
+
cpSync(resolve(root, "lib"), resolve(dir, "lib"), { recursive: true });
|
|
24
|
+
cpSync(resolve(root, "skills"), resolve(dir, "skills"), { recursive: true });
|
|
25
|
+
cpSync(resolve(root, "icon.svg"), resolve(dir, "icon.svg"));
|
|
26
|
+
mkdirSync(resolve(dir, "icons"), { recursive: true });
|
|
27
|
+
cpSync(resolve(root, "icon.svg"), resolve(dir, "icons/share-2.svg"));
|
|
28
|
+
console.log(`[deploy] → ${dir}`);
|
|
29
|
+
}
|
|
30
|
+
deployCommit({ repo: resolve(homedir(), ".pi/web/extensions"), name: "aiti-msg-share",
|
|
31
|
+
paths: ["aiti-msg-share"], log: (m) => console.log("[deploy] " + m) });
|
|
32
|
+
console.log("[deploy] done. Reload via POST /api/extensions/reload");
|