meshy-dsh 0.3.7 → 0.4.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/lib/compose.js ADDED
@@ -0,0 +1,100 @@
1
+ // Adaptive system-prompt section (`meshy:compose`): run Meshy through the native `meshy` tool
2
+ // (the Meshy CLI's own arguments, which the Meshy skills teach), and take advantage of canvas or
3
+ // genui tools only when they are already installed in the current session.
4
+
5
+ const GENUI_PATTERNS = [/^genui/, /^dsh_genui/, /^render_ui$/, /^show_widget$/]
6
+
7
+ function getService(ctx, name) {
8
+ if (!ctx || typeof ctx !== 'object') return undefined
9
+ if (typeof ctx.get === 'function') return ctx.get(name)
10
+ return ctx[name]
11
+ }
12
+
13
+ function visibleToolNames(ctx, fallbackCtx, scope, toolSet) {
14
+ const tools = getService(ctx, 'tools') ?? getService(fallbackCtx, 'tools')
15
+ if (!tools) return null
16
+ if (typeof tools.definitions === 'function') {
17
+ try {
18
+ const defs = tools.definitions(scope, toolSet)
19
+ if (Array.isArray(defs)) return new Set(defs.map((d) => d?.name).filter(Boolean))
20
+ } catch {
21
+ // Fall through to schemas/get inspection.
22
+ }
23
+ }
24
+ if (typeof tools.schemas === 'function') {
25
+ try {
26
+ const schemas = tools.schemas(scope, toolSet)
27
+ if (Array.isArray(schemas)) return new Set(schemas.map((s) => s?.name).filter(Boolean))
28
+ } catch {
29
+ // Fall through to per-name lookup.
30
+ }
31
+ }
32
+ if (typeof tools.get === 'function') {
33
+ const probes = [
34
+ 'meshy',
35
+ 'meshy_sign_in',
36
+ 'canvas_write',
37
+ 'genui_render',
38
+ 'dsh_genui_render',
39
+ 'render_ui',
40
+ 'show_widget',
41
+ ]
42
+ const found = new Set()
43
+ for (const name of probes) {
44
+ try {
45
+ if (tools.get(name, scope, toolSet)) found.add(name)
46
+ } catch {
47
+ // Ignore unavailable probe.
48
+ }
49
+ }
50
+ return found
51
+ }
52
+ return null
53
+ }
54
+
55
+ /**
56
+ * Build the `meshy:compose` prompt section text for a given assembly scope.
57
+ */
58
+ export function buildComposeText(ctx, { scope, toolSet, fallbackCtx } = {}) {
59
+ const names = visibleToolNames(ctx, fallbackCtx, scope, toolSet)
60
+ if (names && toolSet && ![...names].some((n) => n === 'meshy' || n.startsWith('meshy_'))) {
61
+ return ''
62
+ }
63
+
64
+ const lines = [
65
+ '## Meshy 3D Creation',
66
+ '- Run Meshy through the native `meshy` tool: its `args` are the Meshy CLI arguments the Meshy skills document, without the leading `meshy`. It runs signed in as the user, in this workspace, and returns the CLI\'s JSON envelope. Use it rather than running meshy in the shell.',
67
+ '- Which AI model suits a job is in the Meshy skills; every model and option a command accepts, with its default, is in its `--help` (for example `["image-to-3d", "create", "--help"]`), which costs nothing. Check there rather than assuming, and tell the user which model you will use.',
68
+ '- A command that spends credits asks the user first. Pass `estimated_credits` and `estimate_source` only from `make --dry-run` or the published price list, never a guess.',
69
+ '- Commands that spend credits, and `wait`/`stream`, run as background jobs: a notice with the envelope arrives when they end. Meanwhile keep talking or do other work; do not poll, and never rerun a command whose task is still running. If the CLI\'s wait times out, resume with the `wait` command the envelope names.',
70
+ '- A command that submits a task already follows it to its result in that background job, so let the one call carry the task from submission to its files; submitting it and then waiting on it in a second call only adds a call. Give that call a `title` naming what it makes (for example "oak chest"), not the step.',
71
+ '- Images the user picks from a Meshy entry are saved under `meshy_input/` and named in the message; pass those paths to the CLI.',
72
+ '- Saved .glb and .3mf models and images open in the Meshy Studio on their own; call `meshy_preview_model` to show another workspace file or task there. The Studio is the 3D viewer here: skip `meshy view` from the skills, and do not suggest it to the user.',
73
+ '- If Meshy reports that nobody is signed in, call `meshy_sign_in`; never run `auth login`.',
74
+ ]
75
+
76
+ const hasCanvas = Boolean(names?.has('canvas_write'))
77
+ const hasGenUi = Boolean(names && [...names].some((n) => GENUI_PATTERNS.some((re) => re.test(n))))
78
+ if (hasCanvas) {
79
+ lines.push('- Because `canvas_write` is available in this session, you may also write companion asset sheets, material notes, or structured summaries to the canvas when helpful.')
80
+ }
81
+ if (hasGenUi) {
82
+ lines.push('- Because interactive UI rendering is available in this session, you may present structured comparisons or interactive previews alongside generated assets when helpful.')
83
+ }
84
+
85
+ return lines.join('\n')
86
+ }
87
+
88
+ /**
89
+ * Register the `meshy:compose` section on `ctx.systemPrompt`.
90
+ */
91
+ export function registerCompose(ctx, fallbackCtx) {
92
+ const systemPrompt = getService(ctx, 'systemPrompt')
93
+ if (!systemPrompt || typeof systemPrompt.section !== 'function') return undefined
94
+ return systemPrompt.section({
95
+ name: 'meshy:compose',
96
+ order: 500,
97
+ interpolate: false,
98
+ text: (assembleCtx) => buildComposeText(ctx, { ...assembleCtx, fallbackCtx }),
99
+ })
100
+ }
package/lib/events.js ADDED
@@ -0,0 +1,28 @@
1
+ // Host-local pub/sub event bus for live task updates, workspace model announcements, and
2
+ // right-sidebar focus requests. Listeners are isolated so one error never interrupts others.
3
+
4
+ /**
5
+ * Create a lightweight pub/sub bus scoped to one host instance (or test).
6
+ */
7
+ export function createEventBus() {
8
+ const listeners = new Set()
9
+
10
+ function emit(event) {
11
+ if (!event || typeof event !== 'object') return
12
+ for (const listener of [...listeners]) {
13
+ try {
14
+ listener(event)
15
+ } catch {
16
+ // One failing listener must not disrupt other subscribers or SSE streams.
17
+ }
18
+ }
19
+ }
20
+
21
+ function subscribe(listener) {
22
+ if (typeof listener !== 'function') return () => {}
23
+ listeners.add(listener)
24
+ return () => { listeners.delete(listener) }
25
+ }
26
+
27
+ return { emit, subscribe }
28
+ }