miaochuan-dsh-plugin 0.0.0-stage → 1.0.0
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 +27 -0
- package/README.md +61 -2
- package/cordis.patch.yml +5 -0
- package/index.js +208 -0
- package/package.json +39 -5
- package/skills/miaochuan/SKILL.md +77 -0
- package/src/index.ts +243 -0
- package/tsconfig.json +24 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
秒穿AI DeepSeek Harness 插件 — 专有许可证
|
|
2
|
+
|
|
3
|
+
版权所有 © 2026 秒穿AI(miaochuan.shop)。保留所有权利。
|
|
4
|
+
|
|
5
|
+
本仓库源代码仅供查看与审计。未经版权方书面许可,任何人不得复制、
|
|
6
|
+
修改、合并、发布、分发、再许可、出售本软件或其副本,也不得将其用于
|
|
7
|
+
商业用途,或用于搭建与秒穿AI 相同或类似的服务。
|
|
8
|
+
|
|
9
|
+
安装与使用本插件即表示你同意:本插件调用秒穿AI 在线服务,须遵守
|
|
10
|
+
秒穿AI 的服务条款与积分规则;换装按积分计费。
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
Proprietary License — Miaochuan AI DeepSeek Harness Plugin
|
|
15
|
+
|
|
16
|
+
Copyright © 2026 Miaochuan AI (miaochuan.shop). All rights reserved.
|
|
17
|
+
|
|
18
|
+
The source code in this repository is made visible for review and audit
|
|
19
|
+
only. Without prior written permission from the copyright holder, no one
|
|
20
|
+
may copy, modify, merge, publish, distribute, sublicense, sell, or
|
|
21
|
+
commercially exploit this software or its copies, or use it to build a
|
|
22
|
+
service identical or similar to Miaochuan AI.
|
|
23
|
+
|
|
24
|
+
Installing and using this plugin means you agree to Miaochuan AI's terms
|
|
25
|
+
of service and points rules; video try-on is billed in points.
|
|
26
|
+
|
|
27
|
+
THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
|
package/README.md
CHANGED
|
@@ -1,3 +1,62 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 秒穿AI 视频换装 · DeepSeek Harness 插件
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
在 DeepSeek Harness(DSH)里直接用秒穿AI 视频换装:给一段视频,选一件衣服换上,拿回成片。不用重拍,不用抠图。
|
|
4
|
+
|
|
5
|
+
> DSH 插件市场(设置 → 插件市场)由社区 DSH Plugin Hub(dsh-plugin.org)运营,与 DeepSeek AI 无隶属关系。本插件由秒穿AI 官方维护。
|
|
6
|
+
>
|
|
7
|
+
> 本项目授权 [DSH Plugin](https://dsh-plugin.org/) 收录本仓库,并在该站展示插件信息。
|
|
8
|
+
|
|
9
|
+
## 安装
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
dsh plugin --profile web add github:axezhangjh-tech/miaochuan-dsh-plugin
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
装完重启 DSH。
|
|
16
|
+
|
|
17
|
+
## 配置 API Key
|
|
18
|
+
|
|
19
|
+
插件用你的秒穿AI API Key 鉴权(`mk_` 开头)。获取方式:登录 [miaochuan.shop](https://miaochuan.shop) →「我的积分」页生成 API Key(只显示一次,请妥善保存)。
|
|
20
|
+
|
|
21
|
+
填入方式(二选一):
|
|
22
|
+
|
|
23
|
+
1. DSH 网页端打开插件设置,填写 `apiKey`;或
|
|
24
|
+
2. 在你的 profile 配置 `~/.dsh/profiles/web/cordis.patch.yml` 里覆盖这一行(重启 DSH 生效):
|
|
25
|
+
|
|
26
|
+
```yaml
|
|
27
|
+
- id: miaochuan
|
|
28
|
+
name: miaochuan-dsh-plugin
|
|
29
|
+
config:
|
|
30
|
+
apiKey: 'mk_你的密钥'
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
未填 Key 时工具会直接报错提示,未配置不会扣费。
|
|
34
|
+
|
|
35
|
+
## 四个工具
|
|
36
|
+
|
|
37
|
+
| 工具 | 说明 |
|
|
38
|
+
| ---- | ---- |
|
|
39
|
+
| `list_garments` | 列出 15 件内置服装(编号、名称、类目、价格、图片链接),可按类目过滤 |
|
|
40
|
+
| `video_tryon` | 提交视频换装,立即返回 `job_id`(异步,不等完成) |
|
|
41
|
+
| `get_tryon_status` | 按 `job_id` 查进度,完成后返回成片链接(24 小时内有效,无需登录) |
|
|
42
|
+
| `get_balance` | 查积分余额,以及戏服免费是否已用过 |
|
|
43
|
+
|
|
44
|
+
典型流程:`list_garments` 按名字找 `garment_id` → `video_tryon` 提交 → `get_tryon_status` 轮询到 completed → 把成片链接给用户。详细用法见 `skills/miaochuan/SKILL.md`。
|
|
45
|
+
|
|
46
|
+
## 计费与规则
|
|
47
|
+
|
|
48
|
+
- 视频换装 60 积分/秒(1 积分 = ¥0.01),按视频时长向上取整;15 秒视频 900 积分。
|
|
49
|
+
- 每个账号首次戏服换装免费(神奇女侠、女武神、女雷神、美少女战士、猫女 5 件)。
|
|
50
|
+
- 余额不足时提交会失败,提示先充值(秒穿AI「我的积分」页)。
|
|
51
|
+
- 视频要求:公开链接、MP4、≤15 秒、≤100MB。超过 15 秒的视频先截一段。
|
|
52
|
+
- 实时试衣(打开摄像头秒换上身)和换角色不在插件里,只能在秒穿AI 网页端用。插件只做异步视频换装。
|
|
53
|
+
- 带明显版权的形象(如钢铁侠战甲)会被模型方拦截,提交会被拒绝且不扣积分。
|
|
54
|
+
|
|
55
|
+
## 兼容性
|
|
56
|
+
|
|
57
|
+
- 需要 DeepSeek Harness `>= 0.2.3-alpha.3 < 0.3.0`。DSH 仍是开发者预览,插件 API 可能随版本变;本插件按 0.2.3-alpha.3 的插件 API(`defineTool` / `Config` / bundle 格式)编写,工具已对 miaochuan.shop 实测通过。
|
|
58
|
+
- Node.js 22.19+ 或 24+(DSH 的要求)。
|
|
59
|
+
|
|
60
|
+
## 许可证
|
|
61
|
+
|
|
62
|
+
专有许可证,见 [LICENSE](LICENSE):源代码仅供查看与审计,禁止复制、修改、分发与商用。本插件不是开源软件。
|
package/cordis.patch.yml
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
2
|
+
import Schema from '@deepseek-ai/schemastery';
|
|
3
|
+
export const name = 'miaochuan';
|
|
4
|
+
export const inject = ['tools'];
|
|
5
|
+
export const Config = Schema.object({
|
|
6
|
+
apiKey: Schema.string().required(),
|
|
7
|
+
baseUrl: Schema.string().default('https://miaochuan.shop'),
|
|
8
|
+
});
|
|
9
|
+
const MAX_VIDEO_BYTES = 100 * 1024 * 1024; // 100 MB, matches /api/jobs
|
|
10
|
+
function getGarments(base) {
|
|
11
|
+
return [
|
|
12
|
+
{ id: 'charcoal', name: '标准版型美利奴羊毛针织衫', name_en: 'Merino wool jumper (charcoal)', image: `${base}/demo/cos-charcoal.jpg`, prompt: 'Substitute the current top with a charcoal-black layered-collar merino wool jumper', price: 890, category: '上装' },
|
|
13
|
+
{ id: 'cobalt', name: '休闲版型半高领拉链针织衫', name_en: 'Funnel-neck zip-up knit sweater (cobalt)', image: `${base}/demo/cos-cobalt.jpg`, prompt: 'Substitute the current top with a cobalt-blue funnel-neck zip-up knit sweater', price: 1300, category: '上装' },
|
|
14
|
+
{ id: 'cardigan', name: '标准版型菱格拉绒羊绒V领开衫', name_en: 'Argyle brushed cashmere V-neck cardigan', image: `${base}/demo/cos-cardigan.jpg`, prompt: 'Substitute the current outfit with a blue argyle brushed cashmere V-neck cardigan', price: 2500, category: '上装' },
|
|
15
|
+
{ id: 'contrast-dress', name: '标准版型拼接连衣裙(棕色)', name_en: 'Contrast-panel midi dress (brown)', image: `${base}/demo/cos-contrast-dress.jpg`, prompt: 'Substitute the current outfit with a brown contrast-panel midi dress, keeping the face, hair and background unchanged', price: 990, category: '连衣裙' },
|
|
16
|
+
{ id: 'madlenne', name: 'Madlenne 01 黑色窄框猫眼墨镜', name_en: 'Madlenne 01 cat-eye sunglasses (black)', image: `${base}/demo/gm-madlenne01.jpg`, prompt: 'Put the black narrow cat-eye sunglasses from the reference image onto the person\'s face, keeping the face, hair, clothes and background unchanged', price: 1880, category: '配饰' },
|
|
17
|
+
{ id: 'thorn-face', name: '银色荆棘液态金属面饰', name_en: 'Silver liquid-metal thorn face jewelry', image: `${base}/demo/face-jewelry-thorn.jpg`, prompt: 'Put the silver liquid-metal thorn face jewelry from the reference image onto the person\'s face, across the forehead and above the eyebrows, keeping the face, hair, clothes and background unchanged', price: null, category: '配饰' },
|
|
18
|
+
{ id: 'ubras-bralette', name: '圆领无钢圈文胸(裸色)', name_en: 'Scoop-neck bralette (nude)', image: `${base}/demo/ubras-scoop-bralette.jpg`, prompt: 'Substitute the current top with a nude seamless scoop-neck bralette, keeping the face, hair and background unchanged', price: 210, category: '内衣' },
|
|
19
|
+
{ id: 'cos-boiled-wool-set', name: '水煮羊毛混纺开衫套装(米灰混色)', name_en: 'Boiled wool-blend cardigan set (beige mélange)', image: `${base}/demo/cos-boiled-wool-set.jpg`, prompt: 'Substitute the current outfit with a beige mélange boiled wool-blend shawl-collar cardigan and matching barrel-leg pants set, keeping the face, hair and background unchanged', price: 1943, category: '套装' },
|
|
20
|
+
{ id: 'cos-pleated-trousers', name: '压褶莫代尔阔腿裤(奶油色)', name_en: 'Pleated modal wide-leg trousers (cream)', image: `${base}/demo/cos-pleated-trousers.jpg`, prompt: 'Substitute the current bottoms with cream pleated modal wide-leg trousers, keeping the face, hair, top and background unchanged', price: 1008, category: '下装' },
|
|
21
|
+
{ id: 'cos-tbar-necklace', name: 'T 形链条项链(银色)', name_en: 'T-bar chain necklace (silver)', image: `${base}/demo/cos-tbar-necklace.jpg`, prompt: 'Put the silver T-bar chain necklace from the reference image around the person\'s neck, keeping the face, hair, clothes and background unchanged', price: 305, category: '配饰' },
|
|
22
|
+
{ id: 'costume-wonder-woman', name: '神奇女侠戏服', name_en: 'Wonder Woman costume', image: `${base}/demo/costume-wonder-woman.jpg`, prompt: 'Substitute the current outfit with a red and gold armored bustier costume with a gold tiara, gold belt, blue skirt and silver-gold arm guards, keeping the face, hair and background unchanged', price: null, category: '戏服' },
|
|
23
|
+
{ id: 'costume-valkyrie', name: '女武神戏服', name_en: 'Valkyrie costume', image: `${base}/demo/costume-valkyrie.jpg`, prompt: 'Substitute the current outfit with a silver-grey armored costume with gold ornaments and a blue cape, keeping the face, hair and background unchanged', price: null, category: '戏服' },
|
|
24
|
+
{ id: 'costume-thor-jane', name: '女雷神戏服', name_en: 'Mighty Thor costume', image: `${base}/demo/costume-thor-jane.jpg`, prompt: 'Substitute the current outfit with a red and silver armored costume with a silver winged helmet and a red cape, keeping the face, hair and background unchanged', price: null, category: '戏服' },
|
|
25
|
+
{ id: 'costume-sailor-moon', name: '美少女战士戏服', name_en: 'Sailor Moon costume', image: `${base}/demo/costume-sailor-moon.jpg`, prompt: 'Substitute the current outfit with a blue sailor-collar costume with a large red bow, blue pleated skirt, red boots and white gloves, keeping the face, hair and background unchanged', price: null, category: '戏服' },
|
|
26
|
+
{ id: 'costume-catwoman', name: '猫女戏服', name_en: 'Catwoman costume', image: `${base}/demo/costume-catwoman.jpg`, prompt: 'Substitute the current outfit with a black bodysuit costume with a cat-ear mask, keeping the face, hair and background unchanged', price: null, category: '戏服' },
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
// Read an MP4's duration from its mvhd box. Scans the whole buffer (the
|
|
30
|
+
// moov box is often at the END of the file, so a first-1MB scan misses it).
|
|
31
|
+
function mp4DurationSeconds(buf) {
|
|
32
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
33
|
+
for (let i = 0; i + 4 <= buf.length; i++) {
|
|
34
|
+
if (buf[i] === 0x6d && buf[i + 1] === 0x76 && buf[i + 2] === 0x68 && buf[i + 3] === 0x64) {
|
|
35
|
+
const boxStart = i;
|
|
36
|
+
if (boxStart + 8 + 4 > buf.length)
|
|
37
|
+
return null;
|
|
38
|
+
const version = buf[boxStart + 4];
|
|
39
|
+
try {
|
|
40
|
+
if (version === 1) {
|
|
41
|
+
const timescale = view.getUint32(boxStart + 4 + 4 + 8 + 8);
|
|
42
|
+
const duration = Number(view.getBigUint64(boxStart + 4 + 4 + 8 + 8 + 4));
|
|
43
|
+
if (timescale > 0 && duration >= 0)
|
|
44
|
+
return duration / timescale;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const timescale = view.getUint32(boxStart + 4 + 4 + 4 + 4);
|
|
48
|
+
const duration = view.getUint32(boxStart + 4 + 4 + 4 + 4 + 4);
|
|
49
|
+
if (timescale > 0 && duration >= 0)
|
|
50
|
+
return duration / timescale;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
async function fetchBytes(url, label, signal) {
|
|
62
|
+
const res = await fetch(url, { headers: { 'User-Agent': 'miaochuan-dsh-plugin/1.0' }, signal });
|
|
63
|
+
if (!res.ok)
|
|
64
|
+
throw new Error(`Cannot download ${label} (${url}): HTTP ${res.status}`);
|
|
65
|
+
const len = res.headers.get('content-length');
|
|
66
|
+
if (len && Number(len) > MAX_VIDEO_BYTES)
|
|
67
|
+
throw new Error(`${label} is larger than 100 MB`);
|
|
68
|
+
const buf = Buffer.from(await res.arrayBuffer());
|
|
69
|
+
if (buf.length > MAX_VIDEO_BYTES)
|
|
70
|
+
throw new Error(`${label} is larger than 100 MB`);
|
|
71
|
+
return { buf, contentType: res.headers.get('content-type') || 'application/octet-stream' };
|
|
72
|
+
}
|
|
73
|
+
export function apply(ctx, config) {
|
|
74
|
+
const base = config.baseUrl.replace(/\/$/, '');
|
|
75
|
+
const garments = getGarments(base);
|
|
76
|
+
const authHeaders = () => {
|
|
77
|
+
if (!config.apiKey) {
|
|
78
|
+
throw new Error('秒穿AI API Key 未配置:请在插件设置里填写在 miaochuan.shop「我的积分」页生成的 API Key(mk_ 开头)。');
|
|
79
|
+
}
|
|
80
|
+
return { Authorization: `Bearer ${config.apiKey}` };
|
|
81
|
+
};
|
|
82
|
+
async function getJobStatus(jobId, signal) {
|
|
83
|
+
const res = await fetch(`${base}/api/jobs?id=${encodeURIComponent(jobId)}`, {
|
|
84
|
+
headers: authHeaders(),
|
|
85
|
+
signal,
|
|
86
|
+
});
|
|
87
|
+
const j = await res.json().catch(() => ({}));
|
|
88
|
+
if (!res.ok)
|
|
89
|
+
throw new Error(j.error || `Job lookup failed (HTTP ${res.status})`);
|
|
90
|
+
return j;
|
|
91
|
+
}
|
|
92
|
+
ctx.tools.register(defineTool({
|
|
93
|
+
name: 'list_garments',
|
|
94
|
+
description: 'List the built-in garments you can try on with 秒穿AI video try-on. Returns id, Chinese/English name, category, price in CNY (null = no price / costume), and the garment image URL. Pick a garment_id from this list for video_tryon. Filter by category with the optional category argument (e.g. 戏服 for costumes).',
|
|
95
|
+
parameters: {
|
|
96
|
+
category: { type: 'string', description: 'Filter by category, e.g. 上装, 连衣裙, 戏服, 配饰' },
|
|
97
|
+
},
|
|
98
|
+
output: {
|
|
99
|
+
schema: { type: 'string' },
|
|
100
|
+
render: (_args, value) => [{ type: 'text', text: value }],
|
|
101
|
+
},
|
|
102
|
+
async execute(args) {
|
|
103
|
+
const list = args.category ? garments.filter((g) => g.category === args.category) : garments;
|
|
104
|
+
return JSON.stringify(list.map((g) => ({ id: g.id, name: g.name, name_en: g.name_en, category: g.category, price_cny: g.price, image_url: g.image })), null, 2);
|
|
105
|
+
},
|
|
106
|
+
}));
|
|
107
|
+
ctx.tools.register(defineTool({
|
|
108
|
+
name: 'video_tryon',
|
|
109
|
+
description: 'Try a garment on a person in a video with 秒穿AI. Give a publicly reachable video URL (<= 15 seconds, <= 100 MB, the person should be clearly visible) and either a garment_id from list_garments or your own garment_image_url. This tool submits the job and returns immediately with a job_id — it does NOT wait for the video to finish. Call get_tryon_status with the job_id to check progress (usually done in seconds); when completed it returns the finished video link. Cost: 60 points per second of video (a 3 s clip costs 180 points; 1 point = 0.01 CNY). The first costume (戏服) try-on per account is free. Real-time (live camera) try-on is not available through this tool; only async video try-on.',
|
|
110
|
+
parameters: {
|
|
111
|
+
video_url: { type: 'string', required: true, description: 'Publicly reachable URL of the source video (<= 15 s, <= 100 MB)' },
|
|
112
|
+
garment_id: { type: 'string', description: 'Built-in garment id from list_garments, e.g. costume-wonder-woman. Use this OR garment_image_url.' },
|
|
113
|
+
garment_image_url: { type: 'string', description: 'URL of a garment/costume image to try on (your own image). Use this OR garment_id.' },
|
|
114
|
+
prompt: { type: 'string', description: 'Optional custom prompt overriding the garment default. Normally omit it.' },
|
|
115
|
+
},
|
|
116
|
+
output: {
|
|
117
|
+
schema: { type: 'string' },
|
|
118
|
+
render: (_args, value) => [{ type: 'text', text: value }],
|
|
119
|
+
},
|
|
120
|
+
async execute(args, exec) {
|
|
121
|
+
if (!args.garment_id && !args.garment_image_url) {
|
|
122
|
+
throw new Error('Missing garment: pass garment_id (from list_garments) or garment_image_url.');
|
|
123
|
+
}
|
|
124
|
+
let refUrl = args.garment_image_url || '';
|
|
125
|
+
let refPrompt = args.prompt || '';
|
|
126
|
+
let category = '我的上传';
|
|
127
|
+
let garmentParam = 'upload';
|
|
128
|
+
if (args.garment_id) {
|
|
129
|
+
const garment = garments.find((g) => g.id === args.garment_id);
|
|
130
|
+
if (!garment) {
|
|
131
|
+
throw new Error(`Unknown garment_id "${args.garment_id}". Call list_garments to see the available ids.`);
|
|
132
|
+
}
|
|
133
|
+
refUrl = garment.image;
|
|
134
|
+
refPrompt = args.prompt || garment.prompt;
|
|
135
|
+
category = garment.category;
|
|
136
|
+
garmentParam = garment.id;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
refPrompt = args.prompt || 'Substitute the current outfit with the costume in this image, keeping the face, hair and background unchanged';
|
|
140
|
+
}
|
|
141
|
+
const video = await fetchBytes(args.video_url, 'video', exec.signal);
|
|
142
|
+
const ref = await fetchBytes(refUrl, 'garment image', exec.signal);
|
|
143
|
+
const durationSec = mp4DurationSeconds(video.buf);
|
|
144
|
+
if (durationSec === null || durationSec <= 0 || durationSec > 15) {
|
|
145
|
+
throw new Error(`Cannot read a usable duration from the video (${durationSec === null ? 'no mvhd found' : durationSec.toFixed(2) + ' s'}). The video must be an MP4 of at most 15 seconds.`);
|
|
146
|
+
}
|
|
147
|
+
const fd = new FormData();
|
|
148
|
+
fd.append('video', new Blob([video.buf], { type: video.contentType }), 'source.mp4');
|
|
149
|
+
fd.append('prompt', refPrompt);
|
|
150
|
+
fd.append('reference_image', new Blob([ref.buf], { type: ref.contentType }), 'garment.jpg');
|
|
151
|
+
fd.append('category', category);
|
|
152
|
+
fd.append('garment', garmentParam);
|
|
153
|
+
fd.append('duration', String(durationSec));
|
|
154
|
+
const res = await fetch(`${base}/api/jobs`, {
|
|
155
|
+
method: 'POST',
|
|
156
|
+
headers: authHeaders(),
|
|
157
|
+
body: fd,
|
|
158
|
+
signal: exec.signal,
|
|
159
|
+
});
|
|
160
|
+
const j = await res.json().catch(() => ({}));
|
|
161
|
+
if (!res.ok) {
|
|
162
|
+
throw new Error(`Try-on failed to start (HTTP ${res.status}): ${j.error || 'unknown error'}`);
|
|
163
|
+
}
|
|
164
|
+
return JSON.stringify({
|
|
165
|
+
job_id: j.job_id,
|
|
166
|
+
status: 'processing',
|
|
167
|
+
free: j.free === true,
|
|
168
|
+
note: 'Job submitted. Call get_tryon_status with this job_id to check progress; when completed it returns the finished video link.',
|
|
169
|
+
}, null, 2);
|
|
170
|
+
},
|
|
171
|
+
}));
|
|
172
|
+
ctx.tools.register(defineTool({
|
|
173
|
+
name: 'get_tryon_status',
|
|
174
|
+
description: 'Check the status of a video try-on job by its job_id. Returns status (pending/processing/completed/failed) and, when completed, a signed video_url to watch/download the finished video (valid 24 h, no login needed).',
|
|
175
|
+
parameters: {
|
|
176
|
+
job_id: { type: 'string', required: true, description: 'The job_id returned by video_tryon' },
|
|
177
|
+
},
|
|
178
|
+
output: {
|
|
179
|
+
schema: { type: 'string' },
|
|
180
|
+
render: (_args, value) => [{ type: 'text', text: value }],
|
|
181
|
+
},
|
|
182
|
+
async execute(args, exec) {
|
|
183
|
+
const st = await getJobStatus(args.job_id, exec.signal);
|
|
184
|
+
return JSON.stringify({
|
|
185
|
+
job_id: args.job_id,
|
|
186
|
+
status: st.status,
|
|
187
|
+
video_url: st.download_url || null,
|
|
188
|
+
}, null, 2);
|
|
189
|
+
},
|
|
190
|
+
}));
|
|
191
|
+
ctx.tools.register(defineTool({
|
|
192
|
+
name: 'get_balance',
|
|
193
|
+
description: 'Check the 秒穿AI points balance for the account this plugin is configured with. Returns the total points (1 point = 0.01 CNY) and whether the account already used its one free costume (戏服) try-on.',
|
|
194
|
+
parameters: {},
|
|
195
|
+
output: {
|
|
196
|
+
schema: { type: 'string' },
|
|
197
|
+
render: (_args, value) => [{ type: 'text', text: value }],
|
|
198
|
+
},
|
|
199
|
+
async execute(_args, exec) {
|
|
200
|
+
const res = await fetch(`${base}/api/points/balance`, { headers: authHeaders(), signal: exec.signal });
|
|
201
|
+
const j = await res.json().catch(() => ({}));
|
|
202
|
+
if (!res.ok) {
|
|
203
|
+
throw new Error(`Balance lookup failed (HTTP ${res.status}): ${j.error || 'unknown error'}`);
|
|
204
|
+
}
|
|
205
|
+
return JSON.stringify({ total_points: j.total, free_costume_used: j.freeCostumeUsed ?? false }, null, 2);
|
|
206
|
+
},
|
|
207
|
+
}));
|
|
208
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"description": "\u79d2\u7a7fAI \u89c6\u9891\u6362\u88c5 for DeepSeek Harness \u2014 swap the outfit in a video, list garments, check points",
|
|
3
|
+
"devDependencies": {
|
|
4
|
+
"@deepseek-ai/cordis": "4.2.0-alpha.2",
|
|
5
|
+
"@deepseek-ai/dsh-tools": "0.2.3-alpha.3",
|
|
6
|
+
"@deepseek-ai/schemastery": "3.20.0-alpha.2",
|
|
7
|
+
"@types/node": "^24.0.0",
|
|
8
|
+
"typescript": "^5.9.0"
|
|
9
|
+
},
|
|
10
|
+
"dsh": {
|
|
11
|
+
"bundle": {
|
|
12
|
+
"patch": "./cordis.patch.yml"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"dsh": ">=0.2.3-alpha.3 <0.3.0"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"index.js",
|
|
20
|
+
"cordis.patch.yml",
|
|
21
|
+
"src/",
|
|
22
|
+
"tsconfig.json",
|
|
23
|
+
"skills/",
|
|
24
|
+
"README.md",
|
|
25
|
+
"LICENSE"
|
|
26
|
+
],
|
|
27
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
28
|
+
"main": "index.js",
|
|
29
|
+
"name": "miaochuan-dsh-plugin",
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@deepseek-ai/cordis": ">=4.2.0-alpha.2 <5.0.0",
|
|
32
|
+
"@deepseek-ai/dsh-tools": ">=0.2.3-alpha.3 <0.3.0",
|
|
33
|
+
"@deepseek-ai/schemastery": ">=3.20.0-alpha.2 <4.0.0"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsc -p tsconfig.json"
|
|
37
|
+
},
|
|
38
|
+
"type": "module",
|
|
39
|
+
"version": "1.0.0"
|
|
40
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: miaochuan
|
|
3
|
+
description: 秒穿AI 视频换装技能 - 把视频里模特的衣服一键换成另一件,查服装、查积分、取成片
|
|
4
|
+
description_zh: 秒穿AI 视频换装技能 - 把视频里模特的衣服一键换成另一件,查服装、查积分、取成片
|
|
5
|
+
description_en: Miaochuan AI video try-on skill - swap the outfit in a video in one click, list garments, check points, fetch the finished video
|
|
6
|
+
version: 1.0.0
|
|
7
|
+
author: 秒穿AI
|
|
8
|
+
metadata:
|
|
9
|
+
display_name: 秒穿AI 视频换装
|
|
10
|
+
display_description: 把视频里模特的衣服一键换成另一件:选服装、提交视频换装、查看成片
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# 秒穿AI · 视频换装
|
|
14
|
+
|
|
15
|
+
秒穿AI 把视频里的衣服一键换掉:给一段模特走秀、商品展示或直播切片,选一件衣服换上,直接拿到可用的成片。不用重拍,不用抠图。
|
|
16
|
+
|
|
17
|
+
## 可用工具
|
|
18
|
+
|
|
19
|
+
### list_garments - 列出可换装的服装
|
|
20
|
+
|
|
21
|
+
列出内置服装(编号、名称、类目、价格、图片链接)。
|
|
22
|
+
|
|
23
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
24
|
+
| ---- | ---- | :--: | ---- |
|
|
25
|
+
| category | string | - | 按类目过滤,如 `戏服`、`上装`、`连衣裙`、`配饰` |
|
|
26
|
+
|
|
27
|
+
不传参数时列出全部 15 件。不知道换什么时,先调这个看看。
|
|
28
|
+
|
|
29
|
+
### video_tryon - 视频换装(异步提交)
|
|
30
|
+
|
|
31
|
+
提交一段视频换装任务,立即返回 job_id,不等待完成。再用 get_tryon_status 轮询进度,完成后返回成片链接。
|
|
32
|
+
|
|
33
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
34
|
+
| ---- | ---- | :--: | ---- |
|
|
35
|
+
| video_url | string | 是 | 视频的公开链接,MP4,≤15 秒,≤100MB |
|
|
36
|
+
| garment_id | string | 二选一 | 内置服装编号,如 `contrast-dress`、`costume-wonder-woman` |
|
|
37
|
+
| garment_image_url | string | 二选一 | 自定义服装图的公开链接(不用内置服装时传这个) |
|
|
38
|
+
| prompt | string | - | 补充描述,如面料、版型。留空时用服装的默认描述 |
|
|
39
|
+
|
|
40
|
+
`garment_id` 和 `garment_image_url` 二选一。内置服装优先用 `garment_id`。
|
|
41
|
+
|
|
42
|
+
### get_tryon_status - 查询换装进度
|
|
43
|
+
|
|
44
|
+
按 job_id 查进度。完成后返回成片链接。
|
|
45
|
+
|
|
46
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
47
|
+
| ---- | ---- | :--: | ---- |
|
|
48
|
+
| job_id | string | 是 | video_tryon 返回的 job_id |
|
|
49
|
+
|
|
50
|
+
换装通常几秒到几十秒完成;查一次还是 processing 时,等几秒再查。
|
|
51
|
+
|
|
52
|
+
### get_balance - 查积分余额
|
|
53
|
+
|
|
54
|
+
返回当前账号的积分余额,以及戏服免费是否已用过。
|
|
55
|
+
|
|
56
|
+
## 典型流程
|
|
57
|
+
|
|
58
|
+
1. 用户给一段视频 + 想换的衣服(说名字、发图,或说“随便挑一件好看的”)。
|
|
59
|
+
2. 不确定编号时先调 `list_garments`,按名字找到对应的 `garment_id`。
|
|
60
|
+
3. 提交前先向用户确认服装、视频和预计扣费(60 积分/秒,15 秒约 900 积分;首次戏服换装免费的先说明免费),得到确认后再调用。
|
|
61
|
+
4. 调 `video_tryon` 提交,拿到 job_id。视频链接必须是公开可访问的;用户发的本地视频要先确认已上传到可公开访问的地址。
|
|
62
|
+
5. 调 `get_tryon_status` 轮询,直到 completed,返回成片链接(`video_url`)给用户,说明可以直接打开看、下载。
|
|
63
|
+
|
|
64
|
+
## 计费与规则
|
|
65
|
+
|
|
66
|
+
- 视频换装 60 积分/秒(1 积分 = ¥0.01),按视频时长向上取整。15 秒视频 900 积分。
|
|
67
|
+
- 每个账号首次戏服换装免费(神奇女侠、女武神、女雷神、美少女战士、猫女 5 件)。免费那次 `free` 为 true,不扣积分。
|
|
68
|
+
- 余额不足时提交会失败,提示用户先充值(秒穿AI「我的积分」页可充值)。
|
|
69
|
+
- 视频要求:公开链接、MP4、≤15 秒、≤100MB。超过 15 秒的视频先请用户截一段。
|
|
70
|
+
|
|
71
|
+
## 注意事项
|
|
72
|
+
|
|
73
|
+
- 实时试衣(打开摄像头秒换上身)不在插件里,只能在秒穿AI 网页的工作室用。插件只做异步视频换装。
|
|
74
|
+
- 换装成片由 AI 模型生成,颜色、版型与实物可能有细微差异,仅供参考。
|
|
75
|
+
- 钢铁侠等带明显版权的战甲形象会被模型方拦截,提交会被拒绝且不扣积分;遇到时建议换一件风格相近的普通服装。
|
|
76
|
+
- 换角色(把视频里的人换成另一个人)也不在插件里,只在网页端提供。
|
|
77
|
+
- 认证:插件配置里填 API Key(`mk_` 开头,在秒穿AI「我的积分」页生成),无需 OAuth 授权。Key 失效或余额不足时,工具会返回可读的错误,按错误提示引导用户重新生成 Key 或充值。
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
// 秒穿AI 视频换装插件 for DeepSeek Harness.
|
|
2
|
+
// Registers four native tools (list_garments, video_tryon, get_tryon_status,
|
|
3
|
+
// get_balance) that call the 秒穿AI backend with the user's API key.
|
|
4
|
+
// Real-time (live camera) try-on is not exposed here: DSH tools are async
|
|
5
|
+
// calls, they cannot hold a live camera session.
|
|
6
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
7
|
+
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
8
|
+
import Schema from '@deepseek-ai/schemastery'
|
|
9
|
+
|
|
10
|
+
export const name = 'miaochuan'
|
|
11
|
+
export const inject = ['tools']
|
|
12
|
+
|
|
13
|
+
export interface Config {
|
|
14
|
+
/** 秒穿AI API Key (mk_...). Generate one on the 秒穿AI "我的积分" page while logged in. */
|
|
15
|
+
apiKey: string
|
|
16
|
+
/** Backend origin. Only change it to point at another deployment. */
|
|
17
|
+
baseUrl: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const Config: Schema<Config> = Schema.object({
|
|
21
|
+
apiKey: Schema.string().required(),
|
|
22
|
+
baseUrl: Schema.string().default('https://miaochuan.shop'),
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const MAX_VIDEO_BYTES = 100 * 1024 * 1024 // 100 MB, matches /api/jobs
|
|
26
|
+
|
|
27
|
+
// Built-in garments. Keep in sync with the video-tryon page, the WorkBuddy
|
|
28
|
+
// MCP server and the remote MCP server: same 15 items, same prompts.
|
|
29
|
+
interface Garment {
|
|
30
|
+
id: string
|
|
31
|
+
name: string
|
|
32
|
+
name_en: string
|
|
33
|
+
category: string
|
|
34
|
+
price: number | null
|
|
35
|
+
image: string
|
|
36
|
+
prompt: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getGarments(base: string): Garment[] {
|
|
40
|
+
return [
|
|
41
|
+
{ id: 'charcoal', name: '标准版型美利奴羊毛针织衫', name_en: 'Merino wool jumper (charcoal)', image: `${base}/demo/cos-charcoal.jpg`, prompt: 'Substitute the current top with a charcoal-black layered-collar merino wool jumper', price: 890, category: '上装' },
|
|
42
|
+
{ id: 'cobalt', name: '休闲版型半高领拉链针织衫', name_en: 'Funnel-neck zip-up knit sweater (cobalt)', image: `${base}/demo/cos-cobalt.jpg`, prompt: 'Substitute the current top with a cobalt-blue funnel-neck zip-up knit sweater', price: 1300, category: '上装' },
|
|
43
|
+
{ id: 'cardigan', name: '标准版型菱格拉绒羊绒V领开衫', name_en: 'Argyle brushed cashmere V-neck cardigan', image: `${base}/demo/cos-cardigan.jpg`, prompt: 'Substitute the current outfit with a blue argyle brushed cashmere V-neck cardigan', price: 2500, category: '上装' },
|
|
44
|
+
{ id: 'contrast-dress', name: '标准版型拼接连衣裙(棕色)', name_en: 'Contrast-panel midi dress (brown)', image: `${base}/demo/cos-contrast-dress.jpg`, prompt: 'Substitute the current outfit with a brown contrast-panel midi dress, keeping the face, hair and background unchanged', price: 990, category: '连衣裙' },
|
|
45
|
+
{ id: 'madlenne', name: 'Madlenne 01 黑色窄框猫眼墨镜', name_en: 'Madlenne 01 cat-eye sunglasses (black)', image: `${base}/demo/gm-madlenne01.jpg`, prompt: 'Put the black narrow cat-eye sunglasses from the reference image onto the person\'s face, keeping the face, hair, clothes and background unchanged', price: 1880, category: '配饰' },
|
|
46
|
+
{ id: 'thorn-face', name: '银色荆棘液态金属面饰', name_en: 'Silver liquid-metal thorn face jewelry', image: `${base}/demo/face-jewelry-thorn.jpg`, prompt: 'Put the silver liquid-metal thorn face jewelry from the reference image onto the person\'s face, across the forehead and above the eyebrows, keeping the face, hair, clothes and background unchanged', price: null, category: '配饰' },
|
|
47
|
+
{ id: 'ubras-bralette', name: '圆领无钢圈文胸(裸色)', name_en: 'Scoop-neck bralette (nude)', image: `${base}/demo/ubras-scoop-bralette.jpg`, prompt: 'Substitute the current top with a nude seamless scoop-neck bralette, keeping the face, hair and background unchanged', price: 210, category: '内衣' },
|
|
48
|
+
{ id: 'cos-boiled-wool-set', name: '水煮羊毛混纺开衫套装(米灰混色)', name_en: 'Boiled wool-blend cardigan set (beige mélange)', image: `${base}/demo/cos-boiled-wool-set.jpg`, prompt: 'Substitute the current outfit with a beige mélange boiled wool-blend shawl-collar cardigan and matching barrel-leg pants set, keeping the face, hair and background unchanged', price: 1943, category: '套装' },
|
|
49
|
+
{ id: 'cos-pleated-trousers', name: '压褶莫代尔阔腿裤(奶油色)', name_en: 'Pleated modal wide-leg trousers (cream)', image: `${base}/demo/cos-pleated-trousers.jpg`, prompt: 'Substitute the current bottoms with cream pleated modal wide-leg trousers, keeping the face, hair, top and background unchanged', price: 1008, category: '下装' },
|
|
50
|
+
{ id: 'cos-tbar-necklace', name: 'T 形链条项链(银色)', name_en: 'T-bar chain necklace (silver)', image: `${base}/demo/cos-tbar-necklace.jpg`, prompt: 'Put the silver T-bar chain necklace from the reference image around the person\'s neck, keeping the face, hair, clothes and background unchanged', price: 305, category: '配饰' },
|
|
51
|
+
{ id: 'costume-wonder-woman', name: '神奇女侠戏服', name_en: 'Wonder Woman costume', image: `${base}/demo/costume-wonder-woman.jpg`, prompt: 'Substitute the current outfit with a red and gold armored bustier costume with a gold tiara, gold belt, blue skirt and silver-gold arm guards, keeping the face, hair and background unchanged', price: null, category: '戏服' },
|
|
52
|
+
{ id: 'costume-valkyrie', name: '女武神戏服', name_en: 'Valkyrie costume', image: `${base}/demo/costume-valkyrie.jpg`, prompt: 'Substitute the current outfit with a silver-grey armored costume with gold ornaments and a blue cape, keeping the face, hair and background unchanged', price: null, category: '戏服' },
|
|
53
|
+
{ id: 'costume-thor-jane', name: '女雷神戏服', name_en: 'Mighty Thor costume', image: `${base}/demo/costume-thor-jane.jpg`, prompt: 'Substitute the current outfit with a red and silver armored costume with a silver winged helmet and a red cape, keeping the face, hair and background unchanged', price: null, category: '戏服' },
|
|
54
|
+
{ id: 'costume-sailor-moon', name: '美少女战士戏服', name_en: 'Sailor Moon costume', image: `${base}/demo/costume-sailor-moon.jpg`, prompt: 'Substitute the current outfit with a blue sailor-collar costume with a large red bow, blue pleated skirt, red boots and white gloves, keeping the face, hair and background unchanged', price: null, category: '戏服' },
|
|
55
|
+
{ id: 'costume-catwoman', name: '猫女戏服', name_en: 'Catwoman costume', image: `${base}/demo/costume-catwoman.jpg`, prompt: 'Substitute the current outfit with a black bodysuit costume with a cat-ear mask, keeping the face, hair and background unchanged', price: null, category: '戏服' },
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Read an MP4's duration from its mvhd box. Scans the whole buffer (the
|
|
60
|
+
// moov box is often at the END of the file, so a first-1MB scan misses it).
|
|
61
|
+
function mp4DurationSeconds(buf: Buffer): number | null {
|
|
62
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)
|
|
63
|
+
for (let i = 0; i + 4 <= buf.length; i++) {
|
|
64
|
+
if (buf[i] === 0x6d && buf[i + 1] === 0x76 && buf[i + 2] === 0x68 && buf[i + 3] === 0x64) {
|
|
65
|
+
const boxStart = i
|
|
66
|
+
if (boxStart + 8 + 4 > buf.length) return null
|
|
67
|
+
const version = buf[boxStart + 4]
|
|
68
|
+
try {
|
|
69
|
+
if (version === 1) {
|
|
70
|
+
const timescale = view.getUint32(boxStart + 4 + 4 + 8 + 8)
|
|
71
|
+
const duration = Number(view.getBigUint64(boxStart + 4 + 4 + 8 + 8 + 4))
|
|
72
|
+
if (timescale > 0 && duration >= 0) return duration / timescale
|
|
73
|
+
} else {
|
|
74
|
+
const timescale = view.getUint32(boxStart + 4 + 4 + 4 + 4)
|
|
75
|
+
const duration = view.getUint32(boxStart + 4 + 4 + 4 + 4 + 4)
|
|
76
|
+
if (timescale > 0 && duration >= 0) return duration / timescale
|
|
77
|
+
}
|
|
78
|
+
} catch {
|
|
79
|
+
return null
|
|
80
|
+
}
|
|
81
|
+
return null
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return null
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function fetchBytes(url: string, label: string, signal: AbortSignal): Promise<{ buf: Buffer; contentType: string }> {
|
|
88
|
+
const res = await fetch(url, { headers: { 'User-Agent': 'miaochuan-dsh-plugin/1.0' }, signal })
|
|
89
|
+
if (!res.ok) throw new Error(`Cannot download ${label} (${url}): HTTP ${res.status}`)
|
|
90
|
+
const len = res.headers.get('content-length')
|
|
91
|
+
if (len && Number(len) > MAX_VIDEO_BYTES) throw new Error(`${label} is larger than 100 MB`)
|
|
92
|
+
const buf = Buffer.from(await res.arrayBuffer())
|
|
93
|
+
if (buf.length > MAX_VIDEO_BYTES) throw new Error(`${label} is larger than 100 MB`)
|
|
94
|
+
return { buf, contentType: res.headers.get('content-type') || 'application/octet-stream' }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function apply(ctx: Context, config: Config) {
|
|
98
|
+
const base = config.baseUrl.replace(/\/$/, '')
|
|
99
|
+
const garments = getGarments(base)
|
|
100
|
+
|
|
101
|
+
const authHeaders = (): Record<string, string> => {
|
|
102
|
+
if (!config.apiKey) {
|
|
103
|
+
throw new Error('秒穿AI API Key 未配置:请在插件设置里填写在 miaochuan.shop「我的积分」页生成的 API Key(mk_ 开头)。')
|
|
104
|
+
}
|
|
105
|
+
return { Authorization: `Bearer ${config.apiKey}` }
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function getJobStatus(jobId: string, signal: AbortSignal): Promise<{ status?: string; download_url?: string }> {
|
|
109
|
+
const res = await fetch(`${base}/api/jobs?id=${encodeURIComponent(jobId)}`, {
|
|
110
|
+
headers: authHeaders(),
|
|
111
|
+
signal,
|
|
112
|
+
})
|
|
113
|
+
const j = await res.json().catch(() => ({})) as { error?: string; status?: string; download_url?: string }
|
|
114
|
+
if (!res.ok) throw new Error(j.error || `Job lookup failed (HTTP ${res.status})`)
|
|
115
|
+
return j
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
ctx.tools.register(defineTool({
|
|
119
|
+
name: 'list_garments',
|
|
120
|
+
description: 'List the built-in garments you can try on with 秒穿AI video try-on. Returns id, Chinese/English name, category, price in CNY (null = no price / costume), and the garment image URL. Pick a garment_id from this list for video_tryon. Filter by category with the optional category argument (e.g. 戏服 for costumes).',
|
|
121
|
+
parameters: {
|
|
122
|
+
category: { type: 'string', description: 'Filter by category, e.g. 上装, 连衣裙, 戏服, 配饰' },
|
|
123
|
+
},
|
|
124
|
+
output: {
|
|
125
|
+
schema: { type: 'string' },
|
|
126
|
+
render: (_args, value) => [{ type: 'text', text: value }],
|
|
127
|
+
},
|
|
128
|
+
async execute(args) {
|
|
129
|
+
const list = args.category ? garments.filter((g) => g.category === args.category) : garments
|
|
130
|
+
return JSON.stringify(
|
|
131
|
+
list.map((g) => ({ id: g.id, name: g.name, name_en: g.name_en, category: g.category, price_cny: g.price, image_url: g.image })),
|
|
132
|
+
null,
|
|
133
|
+
2,
|
|
134
|
+
)
|
|
135
|
+
},
|
|
136
|
+
}))
|
|
137
|
+
|
|
138
|
+
ctx.tools.register(defineTool({
|
|
139
|
+
name: 'video_tryon',
|
|
140
|
+
description: 'Try a garment on a person in a video with 秒穿AI. Give a publicly reachable video URL (<= 15 seconds, <= 100 MB, the person should be clearly visible) and either a garment_id from list_garments or your own garment_image_url. This tool submits the job and returns immediately with a job_id — it does NOT wait for the video to finish. Call get_tryon_status with the job_id to check progress (usually done in seconds); when completed it returns the finished video link. Cost: 60 points per second of video (a 3 s clip costs 180 points; 1 point = 0.01 CNY). The first costume (戏服) try-on per account is free. Real-time (live camera) try-on is not available through this tool; only async video try-on.',
|
|
141
|
+
parameters: {
|
|
142
|
+
video_url: { type: 'string', required: true, description: 'Publicly reachable URL of the source video (<= 15 s, <= 100 MB)' },
|
|
143
|
+
garment_id: { type: 'string', description: 'Built-in garment id from list_garments, e.g. costume-wonder-woman. Use this OR garment_image_url.' },
|
|
144
|
+
garment_image_url: { type: 'string', description: 'URL of a garment/costume image to try on (your own image). Use this OR garment_id.' },
|
|
145
|
+
prompt: { type: 'string', description: 'Optional custom prompt overriding the garment default. Normally omit it.' },
|
|
146
|
+
},
|
|
147
|
+
output: {
|
|
148
|
+
schema: { type: 'string' },
|
|
149
|
+
render: (_args, value) => [{ type: 'text', text: value }],
|
|
150
|
+
},
|
|
151
|
+
async execute(args, exec) {
|
|
152
|
+
if (!args.garment_id && !args.garment_image_url) {
|
|
153
|
+
throw new Error('Missing garment: pass garment_id (from list_garments) or garment_image_url.')
|
|
154
|
+
}
|
|
155
|
+
let refUrl = args.garment_image_url || ''
|
|
156
|
+
let refPrompt = args.prompt || ''
|
|
157
|
+
let category = '我的上传'
|
|
158
|
+
let garmentParam = 'upload'
|
|
159
|
+
if (args.garment_id) {
|
|
160
|
+
const garment = garments.find((g) => g.id === args.garment_id)
|
|
161
|
+
if (!garment) {
|
|
162
|
+
throw new Error(`Unknown garment_id "${args.garment_id}". Call list_garments to see the available ids.`)
|
|
163
|
+
}
|
|
164
|
+
refUrl = garment.image
|
|
165
|
+
refPrompt = args.prompt || garment.prompt
|
|
166
|
+
category = garment.category
|
|
167
|
+
garmentParam = garment.id
|
|
168
|
+
} else {
|
|
169
|
+
refPrompt = args.prompt || 'Substitute the current outfit with the costume in this image, keeping the face, hair and background unchanged'
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const video = await fetchBytes(args.video_url, 'video', exec.signal)
|
|
173
|
+
const ref = await fetchBytes(refUrl, 'garment image', exec.signal)
|
|
174
|
+
const durationSec = mp4DurationSeconds(video.buf)
|
|
175
|
+
if (durationSec === null || durationSec <= 0 || durationSec > 15) {
|
|
176
|
+
throw new Error(`Cannot read a usable duration from the video (${durationSec === null ? 'no mvhd found' : durationSec.toFixed(2) + ' s'}). The video must be an MP4 of at most 15 seconds.`)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const fd = new FormData()
|
|
180
|
+
fd.append('video', new Blob([video.buf], { type: video.contentType }), 'source.mp4')
|
|
181
|
+
fd.append('prompt', refPrompt)
|
|
182
|
+
fd.append('reference_image', new Blob([ref.buf], { type: ref.contentType }), 'garment.jpg')
|
|
183
|
+
fd.append('category', category)
|
|
184
|
+
fd.append('garment', garmentParam)
|
|
185
|
+
fd.append('duration', String(durationSec))
|
|
186
|
+
|
|
187
|
+
const res = await fetch(`${base}/api/jobs`, {
|
|
188
|
+
method: 'POST',
|
|
189
|
+
headers: authHeaders(),
|
|
190
|
+
body: fd,
|
|
191
|
+
signal: exec.signal,
|
|
192
|
+
})
|
|
193
|
+
const j = await res.json().catch(() => ({})) as { error?: string; job_id?: string; free?: boolean }
|
|
194
|
+
if (!res.ok) {
|
|
195
|
+
throw new Error(`Try-on failed to start (HTTP ${res.status}): ${j.error || 'unknown error'}`)
|
|
196
|
+
}
|
|
197
|
+
return JSON.stringify({
|
|
198
|
+
job_id: j.job_id,
|
|
199
|
+
status: 'processing',
|
|
200
|
+
free: j.free === true,
|
|
201
|
+
note: 'Job submitted. Call get_tryon_status with this job_id to check progress; when completed it returns the finished video link.',
|
|
202
|
+
}, null, 2)
|
|
203
|
+
},
|
|
204
|
+
}))
|
|
205
|
+
|
|
206
|
+
ctx.tools.register(defineTool({
|
|
207
|
+
name: 'get_tryon_status',
|
|
208
|
+
description: 'Check the status of a video try-on job by its job_id. Returns status (pending/processing/completed/failed) and, when completed, a signed video_url to watch/download the finished video (valid 24 h, no login needed).',
|
|
209
|
+
parameters: {
|
|
210
|
+
job_id: { type: 'string', required: true, description: 'The job_id returned by video_tryon' },
|
|
211
|
+
},
|
|
212
|
+
output: {
|
|
213
|
+
schema: { type: 'string' },
|
|
214
|
+
render: (_args, value) => [{ type: 'text', text: value }],
|
|
215
|
+
},
|
|
216
|
+
async execute(args, exec) {
|
|
217
|
+
const st = await getJobStatus(args.job_id, exec.signal)
|
|
218
|
+
return JSON.stringify({
|
|
219
|
+
job_id: args.job_id,
|
|
220
|
+
status: st.status,
|
|
221
|
+
video_url: st.download_url || null,
|
|
222
|
+
}, null, 2)
|
|
223
|
+
},
|
|
224
|
+
}))
|
|
225
|
+
|
|
226
|
+
ctx.tools.register(defineTool({
|
|
227
|
+
name: 'get_balance',
|
|
228
|
+
description: 'Check the 秒穿AI points balance for the account this plugin is configured with. Returns the total points (1 point = 0.01 CNY) and whether the account already used its one free costume (戏服) try-on.',
|
|
229
|
+
parameters: {},
|
|
230
|
+
output: {
|
|
231
|
+
schema: { type: 'string' },
|
|
232
|
+
render: (_args, value) => [{ type: 'text', text: value }],
|
|
233
|
+
},
|
|
234
|
+
async execute(_args, exec) {
|
|
235
|
+
const res = await fetch(`${base}/api/points/balance`, { headers: authHeaders(), signal: exec.signal })
|
|
236
|
+
const j = await res.json().catch(() => ({})) as { error?: string; total?: number; freeCostumeUsed?: boolean }
|
|
237
|
+
if (!res.ok) {
|
|
238
|
+
throw new Error(`Balance lookup failed (HTTP ${res.status}): ${j.error || 'unknown error'}`)
|
|
239
|
+
}
|
|
240
|
+
return JSON.stringify({ total_points: j.total, free_costume_used: j.freeCostumeUsed ?? false }, null, 2)
|
|
241
|
+
},
|
|
242
|
+
}))
|
|
243
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"declaration": false,
|
|
4
|
+
"forceConsistentCasingInFileNames": true,
|
|
5
|
+
"lib": [
|
|
6
|
+
"ES2022"
|
|
7
|
+
],
|
|
8
|
+
"module": "NodeNext",
|
|
9
|
+
"moduleResolution": "NodeNext",
|
|
10
|
+
"outDir": ".",
|
|
11
|
+
"rootDir": "src",
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"sourceMap": false,
|
|
14
|
+
"strict": true,
|
|
15
|
+
"target": "ES2022",
|
|
16
|
+
"types": [
|
|
17
|
+
"node"
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
"include": [
|
|
21
|
+
"src"
|
|
22
|
+
],
|
|
23
|
+
"exclude": []
|
|
24
|
+
}
|