meshy-dsh 0.3.6 → 0.4.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/lib/uploads.js ADDED
@@ -0,0 +1,79 @@
1
+ // The composer handoff's host route: an image the user picks from a Meshy entry (the Studio's New
2
+ // menu, the /meshy command, the Meshy page) is saved as picked under `meshy_input/` in the chat's
3
+ // workspace, so the message the composer gets can name it and the agent can hand that path to the
4
+ // Meshy CLI. Nothing is generated or sent anywhere here.
5
+ import { access, mkdir, writeFile } from 'node:fs/promises'
6
+ import { join } from 'node:path'
7
+
8
+ /** Where picked images are kept in the workspace. */
9
+ export const UPLOAD_DIR = 'meshy_input'
10
+ /** The largest image saved. */
11
+ export const MAX_INPUT = 20 << 20
12
+
13
+ const json = (body, status = 200) => Response.json(body, { status, headers: { 'cache-control': 'no-store' } })
14
+
15
+ /** The image type the bytes call for: `png`, `jpg` or `webp`, else null. */
16
+ export function sniffImage(bytes) {
17
+ if (bytes.length > 8 && bytes[0] === 0x89 && bytes[1] === 0x50 && bytes[2] === 0x4e && bytes[3] === 0x47) return 'png'
18
+ if (bytes.length > 3 && bytes[0] === 0xff && bytes[1] === 0xd8 && bytes[2] === 0xff) return 'jpg'
19
+ if (bytes.length > 12 && bytes.subarray(0, 4).toString('latin1') === 'RIFF' && bytes.subarray(8, 12).toString('latin1') === 'WEBP') return 'webp'
20
+ return null
21
+ }
22
+
23
+ /** A file name stem from the picked file's name: ASCII letters, digits, `-` and `_`, else `image`. */
24
+ export function uploadStem(name) {
25
+ const stem = String(name ?? '').split(/[\\/]/).pop().replace(/\.[^.]*$/, '').normalize('NFKD').replace(/[^A-Za-z0-9_-]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 40)
26
+ return stem || 'image'
27
+ }
28
+
29
+ const exists = (path) => access(path).then(() => true, () => false)
30
+
31
+ /** Save one image under `meshy_input/`, never over an existing file; resolves to its workspace path. */
32
+ export async function saveInput(workspace, bytes, name) {
33
+ const ext = sniffImage(bytes)
34
+ if (!ext) throw Object.assign(new Error('the file is not a PNG, JPEG or WebP image'), { statusCode: 400 })
35
+ const dir = join(workspace, UPLOAD_DIR)
36
+ await mkdir(dir, { recursive: true })
37
+ const stem = uploadStem(name)
38
+ for (let i = 1; i < 1000; i++) {
39
+ const file = `${i === 1 ? stem : `${stem}-${i}`}.${ext}`
40
+ if (await exists(join(dir, file))) continue
41
+ try {
42
+ await writeFile(join(dir, file), bytes, { flag: 'wx', mode: 0o644 })
43
+ } catch (err) {
44
+ if (err?.code === 'EEXIST') continue
45
+ throw err
46
+ }
47
+ return `${UPLOAD_DIR}/${file}`
48
+ }
49
+ throw new Error('too many images with this name')
50
+ }
51
+
52
+ /**
53
+ * `POST /api/meshy.input?session=<id>&name=<file name>` with the image's bytes as the body.
54
+ * `workspaceOf` resolves a session id to its workspace (null when unknown).
55
+ */
56
+ export function createInputRoute({ workspaceOf }) {
57
+ return async function handleInput(request) {
58
+ const url = new URL(request.url)
59
+ const sessionId = url.searchParams.get('session') ?? ''
60
+ if (!sessionId) return json({ error: 'session is required' }, 400)
61
+ const declared = Number(request.headers.get('content-length') ?? 0)
62
+ if (declared > MAX_INPUT) return json({ error: `the image is over ${MAX_INPUT >> 20} MB` }, 413)
63
+ const workspace = await workspaceOf(sessionId)
64
+ if (!workspace) return json({ error: 'session workspace not found' }, 404)
65
+ let bytes
66
+ try {
67
+ bytes = Buffer.from(await request.arrayBuffer())
68
+ } catch {
69
+ return json({ error: 'could not read the image' }, 400)
70
+ }
71
+ if (bytes.length === 0) return json({ error: 'an image is required' }, 400)
72
+ if (bytes.length > MAX_INPUT) return json({ error: `the image is over ${MAX_INPUT >> 20} MB` }, 413)
73
+ try {
74
+ return json({ file: await saveInput(workspace, bytes, url.searchParams.get('name')) })
75
+ } catch (err) {
76
+ return json({ error: String(err?.message ?? err) }, err?.statusCode ?? 500)
77
+ }
78
+ }
79
+ }
package/locale/en.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Meshy",
4
- "description": "Generate textured, rigged and animated 3D models, or print-ready files, from text or images with Meshy. The agent drives meshy-cli and saves the files into your project."
4
+ "description": "Text or image to 3D with native tools, live 3D Studio preview, model library and printing skills."
5
5
  }
6
6
  }
package/locale/zh.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Meshy",
4
- "description": "用 Meshy 从文字或图片生成带贴图、绑骨和动画的 3D 模型,或可直接打印的文件。agent 通过 meshy-cli 完成,文件直接保存到你的项目里。"
4
+ "description": "原生 3D 生成工具、实时 3D Studio 预览、模型库,以及绑骨动画与 3D 打印"
5
5
  }
6
6
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "meshy-dsh",
3
- "version": "0.3.6",
4
- "description": "Meshy skills for DeepSeek Harness: textured, rigged and animated 3D models or print-ready files from text or images, through meshy-cli, with a Meshy settings page and a 3D preview for GLB files.",
3
+ "version": "0.4.0",
4
+ "description": "Meshy for DeepSeek Harness: native 3D generation tools with inline chat cards and credit approval, a live right-sidebar 3D Studio and model library, GLB preview, Cordis services, and CLI skills for rigging, animation and 3D printing.",
5
5
  "keywords": [
6
6
  "dsh-plugin",
7
7
  "dsh",
@@ -39,6 +39,7 @@
39
39
  "cordis.patch.yml",
40
40
  "locale/*.json",
41
41
  "icon.svg",
42
+ "assets/viewer-env.hdr",
42
43
  "lib",
43
44
  "skills"
44
45
  ],