@acedatacloud/koishi-plugin-veo 0.0.0-stage → 0.1.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 +21 -0
- package/README.md +14 -2
- package/index.js +85 -0
- package/package.json +47 -4
- package/product.json +11 -0
- package/request.js +13 -0
- package/services.js +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ace Data Cloud
|
|
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,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Veo for Koishi
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
Generate a Veo video from text and retrieve the original task in a private Koishi chat.
|
|
6
|
+
|
|
7
|
+
In Koishi Console, search for `@acedatacloud/koishi-plugin-veo` in the Plugin Market and enable it. In the plugin settings, set `token` to your Ace Data Cloud application token for Veo.
|
|
8
|
+
|
|
9
|
+
Use these commands in a private chat with operator authority (3 or higher).
|
|
10
|
+
|
|
11
|
+
- `ace-veo.make --confirm A slow camera pan across a moonlit garden` submits one paid generation. Check your application task history before retrying an unconfirmed submission.
|
|
12
|
+
- `ace-veo.task <task-id>` queries that same task and lists the available terminal results.
|
|
13
|
+
- `ace-veo.task <task-id> 1` sends the first result.
|
|
14
|
+
|
|
15
|
+
[Veo OpenAPI specification](https://docs.acedata.cloud/openapi/veo.json)
|
package/index.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const { h, Schema } = require('koishi')
|
|
2
|
+
const { services, makeRequest, readTask } = require('./services')
|
|
3
|
+
const request = require('./request')
|
|
4
|
+
const product = require('./product.json')
|
|
5
|
+
|
|
6
|
+
if (product.service) services.set(product.key, product.service)
|
|
7
|
+
const service = services.get(product.key)
|
|
8
|
+
const command = 'ace-' + product.key
|
|
9
|
+
const success = new Set(['complete', 'completed', 'success', 'succeeded', 'succeed', 'partial_failed'])
|
|
10
|
+
const credentialHelp = '请在此插件的设置里填写应用令牌。'
|
|
11
|
+
|
|
12
|
+
exports.name = 'acedatacloud-' + product.key
|
|
13
|
+
exports.inject = ['database']
|
|
14
|
+
exports.usage = `<img src="${product.icon}" alt="${product.title}" width="48" height="48">\n\n为 ${product.title} 创建 [Ace 应用令牌](https://platform.acedata.cloud/console/applications?utm_source=koishi&utm_medium=referral&utm_campaign=evergreen),再将令牌填入下方的密钥字段。`
|
|
15
|
+
exports.Config = Schema.object({
|
|
16
|
+
token: Schema.string().role('secret').required().description(`Ace Data Cloud application token for ${product.title}.`),
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
function isProductModel(model) {
|
|
20
|
+
return product.key !== 'gpt-image' || typeof model === 'string' && model.startsWith('gpt-image-')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
exports.apply = (ctx, config) => {
|
|
24
|
+
const chat = ctx.private()
|
|
25
|
+
const token = () => config.token?.trim()
|
|
26
|
+
const generation = `${command}.make --confirm ${product.example}`
|
|
27
|
+
const retrieval = `${command}.task`
|
|
28
|
+
|
|
29
|
+
chat.command(command, product.title, { authority: 3 })
|
|
30
|
+
.action(() => `生成(计费):${generation}\n查询:${retrieval} <任务 ID> [编号]`)
|
|
31
|
+
|
|
32
|
+
chat.command(`${command}.make <prompt:text>`, '提交一次媒体生成任务(计费)', { authority: 3 })
|
|
33
|
+
.option('confirmed', '-y, --confirm 确认提交一次计费请求')
|
|
34
|
+
.option('model', '-m <model:string> 指定产品支持的公开模型')
|
|
35
|
+
.example(generation)
|
|
36
|
+
.action(async ({ options }, prompt) => {
|
|
37
|
+
if (!token()) return credentialHelp
|
|
38
|
+
if (!prompt?.trim()) return `用法:${generation}`
|
|
39
|
+
if (!options.confirmed) return `生成会计费。确认提交请使用:${generation}`
|
|
40
|
+
const model = options.model || service.defaults.model
|
|
41
|
+
if (!isProductModel(model)) return '请选择 GPT Image 系列模型。'
|
|
42
|
+
|
|
43
|
+
let result
|
|
44
|
+
try {
|
|
45
|
+
result = await request(service.submit, makeRequest(product.key, prompt, options.model), token())
|
|
46
|
+
} catch (error) {
|
|
47
|
+
const status = /^HTTP \d{3}$/.test(error.message) ? `(${error.message})` : ''
|
|
48
|
+
return `提交未确认${status}。请先核对应用里的任务记录,以免重复计费。`
|
|
49
|
+
}
|
|
50
|
+
if (result?.success === false || typeof result?.task_id !== 'string' || !result.task_id.trim()) {
|
|
51
|
+
return '服务没有返回可查询的任务 ID。请先核对应用里的任务记录。'
|
|
52
|
+
}
|
|
53
|
+
return h.text(`${product.title} 已接收。查询:${retrieval} ${result.task_id}`)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
chat.command(`${retrieval} <taskId:string> [index:posint]`, '查询一次现有任务,或发送选中的媒体', { authority: 3 })
|
|
57
|
+
.example(`${retrieval} YOUR_TASK_ID 1`)
|
|
58
|
+
.action(async (_, taskId, index) => {
|
|
59
|
+
if (!token()) return credentialHelp
|
|
60
|
+
if (!taskId) return `用法:${retrieval} <任务 ID> [编号]`
|
|
61
|
+
let task
|
|
62
|
+
try {
|
|
63
|
+
task = await request(service.tasks || `/${product.key}/tasks`, { action: 'retrieve', id: taskId }, token())
|
|
64
|
+
} catch (error) {
|
|
65
|
+
const status = /^HTTP \d{3}$/.test(error.message) ? `(${error.message})` : ''
|
|
66
|
+
return `查询失败${status}。请检查应用权限后使用相同 ID 再查。`
|
|
67
|
+
}
|
|
68
|
+
if (!task || !Object.keys(task).length) return '没有找到该任务。'
|
|
69
|
+
if (task.id !== taskId || (task.response?.task_id != null && task.response.task_id !== taskId)) {
|
|
70
|
+
return '响应中的任务 ID 与查询不符。'
|
|
71
|
+
}
|
|
72
|
+
if (!isProductModel(task.request?.model)) return '该任务没有可验证的 GPT Image 模型。'
|
|
73
|
+
|
|
74
|
+
const { state, assets } = readTask(product.key, task, { requireTerminalState: true })
|
|
75
|
+
if (!success.has(state) || !assets.length) return h.text(`状态:${state}。暂无可发送的媒体。`)
|
|
76
|
+
if (index === undefined) {
|
|
77
|
+
const items = assets.map((asset, i) => `${i + 1}. ${asset.label}`)
|
|
78
|
+
return h.text(`状态:${state}\n${items.join('\n')}\n发送:${retrieval} ${taskId} <编号>`)
|
|
79
|
+
}
|
|
80
|
+
if (!Number.isInteger(index) || index < 1 || index > assets.length) return `请选择 1 至 ${assets.length} 的编号。`
|
|
81
|
+
const asset = assets[index - 1]
|
|
82
|
+
const media = asset.buffer ? h.image(asset.buffer, asset.mime) : h[asset.kind](asset.url)
|
|
83
|
+
return [h.text(asset.label), media]
|
|
84
|
+
})
|
|
85
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acedatacloud/koishi-plugin-veo",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Generate a Veo video from text and retrieve the original task in a private Koishi chat.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"index.js",
|
|
8
|
+
"product.json",
|
|
9
|
+
"services.js",
|
|
10
|
+
"request.js",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": "Ace Data Cloud",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/AceDataCloud/KoishiPluginAceMusic.git",
|
|
19
|
+
"directory": "products"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/AceDataCloud/KoishiPluginAceMusic/tree/main/products",
|
|
22
|
+
"keywords": [
|
|
23
|
+
"koishi",
|
|
24
|
+
"plugin",
|
|
25
|
+
"veo",
|
|
26
|
+
"video"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=18"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"koishi": "^4.18.0"
|
|
33
|
+
},
|
|
34
|
+
"koishi": {
|
|
35
|
+
"description": {
|
|
36
|
+
"en": "Generate a Veo video from text and retrieve the original task in a private Koishi chat.",
|
|
37
|
+
"zh": "在 Koishi 私聊中用文本生成 Veo 视频,查询原任务并发送完成的视频。"
|
|
38
|
+
},
|
|
39
|
+
"service": {
|
|
40
|
+
"required": [
|
|
41
|
+
"database"
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public",
|
|
47
|
+
"registry": "https://registry.npmjs.org"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/product.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"key": "veo",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"title": "Veo",
|
|
5
|
+
"description": "Generate a Veo video from text and retrieve the original task in a private Koishi chat.",
|
|
6
|
+
"descriptionZh": "在 Koishi 私聊中用文本生成 Veo 视频,查询原任务并发送完成的视频。",
|
|
7
|
+
"kind": "video",
|
|
8
|
+
"icon": "https://cdn.acedata.cloud/8nxyy9.jpg",
|
|
9
|
+
"docs": "https://docs.acedata.cloud/openapi/veo.json",
|
|
10
|
+
"example": "A slow camera pan across a moonlit garden"
|
|
11
|
+
}
|
package/request.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
async function request(path, body, token) {
|
|
2
|
+
const reply = await fetch('https://api.acedata.cloud' + path, {
|
|
3
|
+
method: 'POST',
|
|
4
|
+
redirect: 'error',
|
|
5
|
+
signal: AbortSignal.timeout(30000),
|
|
6
|
+
headers: { Authorization: 'Bearer ' + token, 'Content-Type': 'application/json' },
|
|
7
|
+
body: JSON.stringify(body),
|
|
8
|
+
})
|
|
9
|
+
if (!reply.ok) throw new Error('HTTP ' + reply.status)
|
|
10
|
+
return reply.json()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = request
|
package/services.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const services = new Map([
|
|
2
|
+
['suno', { label: 'Suno', submit: '/suno/audios', defaults: { action: 'generate' }, kind: 'audio', url: 'audio_url' }],
|
|
3
|
+
['acemusic', { label: 'ACE Music', submit: '/acemusic/audios', defaults: { action: 'generate' }, kind: 'audio', url: 'audio_url' }],
|
|
4
|
+
['nano-banana', { label: 'Nano Banana', submit: '/nano-banana/images', defaults: { action: 'generate' }, kind: 'image', url: 'image_url' }],
|
|
5
|
+
['gpt-image', { label: 'GPT Image', submit: '/openai/images/generations', tasks: '/openai/tasks', defaults: { model: 'gpt-image-2', response_format: 'url' }, kind: 'image', url: 'url' }],
|
|
6
|
+
['seedream', { label: 'Seedream', submit: '/seedream/images', defaults: { model: 'doubao-seedream-5-0-lite-260128', response_format: 'url' }, kind: 'image', url: 'image_url' }],
|
|
7
|
+
['flux', { label: 'FLUX', submit: '/flux/images', defaults: { action: 'generate', size: '1024x1024' }, kind: 'image', url: 'image_url' }],
|
|
8
|
+
['seedance', { label: 'Seedance', submit: '/seedance/videos', defaults: { model: 'doubao-seedance-1-5-pro-251215' }, kind: 'video', url: 'video_url' }],
|
|
9
|
+
['kling', { label: 'Kling', submit: '/kling/videos', defaults: { action: 'text2video' }, kind: 'video', url: 'video_url' }],
|
|
10
|
+
['veo', { label: 'Veo', submit: '/veo/videos', defaults: { action: 'text2video' }, kind: 'video', url: 'video_url' }],
|
|
11
|
+
['hailuo', { label: 'Hailuo', submit: '/hailuo/videos', defaults: { action: 'generate', model: 'minimax-t2v' }, kind: 'video', url: 'video_url' }],
|
|
12
|
+
])
|
|
13
|
+
|
|
14
|
+
function makeRequest(service, prompt, model) {
|
|
15
|
+
const request = { ...services.get(service).defaults, async: true }
|
|
16
|
+
if (model) request.model = model
|
|
17
|
+
if (service === 'seedance') request.content = [{ type: 'text', text: prompt }]
|
|
18
|
+
else request.prompt = prompt
|
|
19
|
+
return request
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function decodeImage(encoded) {
|
|
23
|
+
if (typeof encoded !== 'string' || !encoded.length) return
|
|
24
|
+
const buffer = Buffer.from(encoded, 'base64')
|
|
25
|
+
let mime
|
|
26
|
+
if (buffer.subarray(0, 8).equals(Buffer.from('89504e470d0a1a0a', 'hex'))) mime = 'image/png'
|
|
27
|
+
else if (buffer.subarray(0, 3).equals(Buffer.from('ffd8ff', 'hex'))) mime = 'image/jpeg'
|
|
28
|
+
else if (buffer.toString('ascii', 0, 4) === 'RIFF' && buffer.toString('ascii', 8, 12) === 'WEBP') mime = 'image/webp'
|
|
29
|
+
if (mime) return { buffer, mime }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function readTask(service, task, { requireTerminalState = false } = {}) {
|
|
33
|
+
const spec = services.get(service)
|
|
34
|
+
const result = task.response
|
|
35
|
+
if (requireTerminalState && (task.success === false || task.error || result?.success === false || result?.error)) {
|
|
36
|
+
return { state: 'failed', assets: [] }
|
|
37
|
+
}
|
|
38
|
+
let rows = Array.isArray(result?.data) ? result.data : []
|
|
39
|
+
if (service === 'kling' || spec.flatResult) rows = [result]
|
|
40
|
+
if (service === 'seedance') rows = [result?.data?.content]
|
|
41
|
+
const assets = []
|
|
42
|
+
const states = new Set()
|
|
43
|
+
for (const row of rows) {
|
|
44
|
+
if (!row) continue
|
|
45
|
+
const state = row.state || row.status
|
|
46
|
+
if (state) states.add(state)
|
|
47
|
+
let url
|
|
48
|
+
if (typeof row[spec.url] === 'string') {
|
|
49
|
+
try { url = new URL(row[spec.url]) } catch {}
|
|
50
|
+
}
|
|
51
|
+
const label = String(row.title || spec.label)
|
|
52
|
+
if (url?.protocol === 'https:' && !url.username && !url.password) {
|
|
53
|
+
assets.push({ kind: spec.kind, label, url: url.href })
|
|
54
|
+
} else if (service === 'gpt-image' || service === 'seedream') {
|
|
55
|
+
const image = decodeImage(row.b64_json)
|
|
56
|
+
if (image) assets.push({ kind: 'image', label, ...image })
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
let state = result?.status || result?.state || result?.data?.status || task.status || task.state
|
|
60
|
+
if (!state && (result?.success === false || result?.error)) state = 'failed'
|
|
61
|
+
if (!state && states.size) state = states.size === 1 ? [...states][0] : 'mixed'
|
|
62
|
+
if (!state) {
|
|
63
|
+
const finished = task.finished_at || result?.finished_at || (!requireTerminalState && result?.success === true)
|
|
64
|
+
state = finished ? 'completed' : 'pending'
|
|
65
|
+
}
|
|
66
|
+
return { state, assets }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
module.exports = { services, makeRequest, readTask }
|