@mulmoclaude/mulmoscript-plugin 0.2.3 → 1.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/dist/core/paths.d.ts +2 -5
- package/dist/core/paths.d.ts.map +1 -1
- package/dist/core/plugin.d.ts.map +1 -1
- package/dist/core/validate.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/lang/index.d.ts +1 -2
- package/dist/lang/index.d.ts.map +1 -1
- package/dist/{plugin-Bi986Wga.cjs → plugin-BLp8tSYt.cjs} +86 -46
- package/dist/plugin-BLp8tSYt.cjs.map +1 -0
- package/dist/{plugin-BQyzxkui.js → plugin-CXhOP_xU.js} +81 -47
- package/dist/plugin-CXhOP_xU.js.map +1 -0
- package/dist/server/mulmoErrorCapture.d.ts.map +1 -1
- package/dist/server/ops.d.ts.map +1 -1
- package/dist/server/support.d.ts +0 -5
- package/dist/server/support.d.ts.map +1 -1
- package/dist/server/types.d.ts +3 -7
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server.cjs +34 -58
- package/dist/server.cjs.map +1 -1
- package/dist/server.js +33 -57
- package/dist/server.js.map +1 -1
- package/dist/style.css +36 -18
- package/dist/vue/View.vue.d.ts.map +1 -1
- package/dist/vue/components/BeatLightbox.vue.d.ts +25 -0
- package/dist/vue/components/BeatLightbox.vue.d.ts.map +1 -0
- package/dist/vue/components/CharacterStrip.vue.d.ts +29 -0
- package/dist/vue/components/CharacterStrip.vue.d.ts.map +1 -0
- package/dist/vue/components/MulmoScriptToolbar.vue.d.ts +26 -0
- package/dist/vue/components/MulmoScriptToolbar.vue.d.ts.map +1 -0
- package/dist/vue/composables/useBeatMovie.d.ts +20 -0
- package/dist/vue/composables/useBeatMovie.d.ts.map +1 -0
- package/dist/vue/composables/useCharacterImages.d.ts +31 -0
- package/dist/vue/composables/useCharacterImages.d.ts.map +1 -0
- package/dist/vue/composables/useDeckEditor.d.ts +18 -0
- package/dist/vue/composables/useDeckEditor.d.ts.map +1 -0
- package/dist/vue/composables/useMediaExport.d.ts +26 -0
- package/dist/vue/composables/useMediaExport.d.ts.map +1 -0
- package/dist/vue/helpers.d.ts +78 -0
- package/dist/vue/helpers.d.ts.map +1 -1
- package/dist/vue/index.d.ts +1 -1
- package/dist/vue/support.d.ts +6 -4
- package/dist/vue/support.d.ts.map +1 -1
- package/dist/vue/transport.d.ts.map +1 -1
- package/dist/vue/viewTypes.d.ts +49 -0
- package/dist/vue/viewTypes.d.ts.map +1 -0
- package/dist/vue.cjs +1021 -729
- package/dist/vue.cjs.map +1 -1
- package/dist/vue.js +1019 -727
- package/dist/vue.js.map +1 -1
- package/package.json +11 -7
- package/dist/plugin-BQyzxkui.js.map +0 -1
- package/dist/plugin-Bi986Wga.cjs.map +0 -1
package/dist/core/paths.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
/** Lowercase-hyphen slug, capped
|
|
2
|
-
*
|
|
3
|
-
* input. Mirrors html-plugin's in-package slugify — deliberately simpler
|
|
4
|
-
* than the host's hash-fallback variant; the timestamp suffix appended by
|
|
5
|
-
* `storyFilePath` keeps these throwaway filenames collision-free. */
|
|
1
|
+
/** Lowercase-hyphen slug, capped, leading/trailing hyphens stripped; falls back
|
|
2
|
+
* to `fallback` for empty/undefined/non-ASCII input. */
|
|
6
3
|
export declare function slugify(title: string | undefined, fallback?: string): string;
|
|
7
4
|
/** Build a fresh, collision-safe story path for a new script —
|
|
8
5
|
* `stories/<slug>-<epoch-ms>.json`, valid as both the FileOps-relative
|
package/dist/core/paths.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/core/paths.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/core/paths.ts"],"names":[],"mappings":"AAgBA;yDACyD;AACzD,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,SAAsB,GAAG,MAAM,CAEzF;AAED;;0CAE0C;AAC1C,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,GAAE,IAAiB,GAAG,MAAM,CAEhF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAUlE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/core/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/core/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAMpE,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE/F;;mCAEmC;AACnC,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,KAAK,CAAC;IACV,IAAI,EAAE,aAAa,GAAG,WAAW,CAAC;IAClC,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,sBAAsB,GAAG,CAAC;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,eAAe,CAAC,GAAG,kBAAkB,CAAC;AAE5G,MAAM,MAAM,wBAAwB,GAAG;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG,kBAAkB,CAAC;AA4DzE;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,yBAAyB,EAClC,IAAI,EAAE,mBAAmB,EACzB,GAAG,GAAE,IAAiB,GACrB,OAAO,CAAC,sBAAsB,CAAC,CAYjC;AAYD;;kEAEkE;AAClE,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,yBAAyB,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAoB5H;AAED;;mDAEmD;AACnD,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,yBAAyB,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAU9H;AAED;;;wDAGwD;AACxD,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,EAAE,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAmB5I;AAED;;0CAE0C;AAC1C,eAAO,MAAM,UAAU,EAAE,cAAc,CAAC,eAAe,EAAE,eAAe,EAAE,mBAAmB,CAK5F,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/core/validate.ts"],"names":[],"mappings":"AAUA,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/core/validate.ts"],"names":[],"mappings":"AAUA,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAoCxF;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,OAAO,GAAG,gBAAgB,CAAC;IACxE,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC,CAkBD;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,OAAO,GAAG,gBAAgB,CAAC;IACtE,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;CACf,CAAC,CA0BD"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_plugin = require("./plugin-
|
|
2
|
+
const require_plugin = require("./plugin-BLp8tSYt.cjs");
|
|
3
3
|
exports.TOOL_DEFINITION = require_plugin.TOOL_DEFINITION;
|
|
4
4
|
exports.TOOL_NAME = require_plugin.TOOL_NAME;
|
|
5
5
|
exports.executeMulmoScript = require_plugin.executeMulmoScript;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as pluginCore, c as normalizeStoryPath,
|
|
1
|
+
import { a as pluginCore, c as normalizeStoryPath, f as TOOL_DEFINITION, i as executeUpdateScript, l as slugify, n as executeMulmoScriptSave, o as validateUpdateBeatBody, p as TOOL_NAME, r as executeUpdateBeat, s as validateUpdateScriptBody, t as executeMulmoScript, u as storyFilePath } from "./plugin-CXhOP_xU.js";
|
|
2
2
|
export { TOOL_DEFINITION, TOOL_NAME, executeMulmoScript, executeMulmoScriptSave, executeUpdateBeat, executeUpdateScript, normalizeStoryPath, pluginCore, slugify, storyFilePath, validateUpdateBeatBody, validateUpdateScriptBody };
|
package/dist/lang/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { type ComputedRef } from "vue";
|
|
2
1
|
import type { Messages } from "./messages";
|
|
3
2
|
/** Reactive message bundle for the active host locale. The plugin carries its
|
|
4
3
|
* own translations (no host i18n dependency); it reads the locale off the
|
|
5
4
|
* injected `BrowserPluginRuntime.locale` ref and falls back to English.
|
|
6
5
|
* Same pattern as @mulmoclaude/html-plugin. */
|
|
7
|
-
export declare
|
|
6
|
+
export declare const useT: () => import("vue").ComputedRef<Messages>;
|
|
8
7
|
export type { Messages };
|
|
9
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/lang/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lang/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lang/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAY3C;;;gDAGgD;AAChD,eAAO,MAAM,IAAI,2CAAuB,CAAC;AAEzC,YAAY,EAAE,QAAQ,EAAE,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
let _mulmocast_types = require("@mulmocast/types");
|
|
2
|
+
let _mulmoclaude_core_artifacts = require("@mulmoclaude/core/artifacts");
|
|
2
3
|
//#region src/core/definition.ts
|
|
3
4
|
var TOOL_NAME = "presentMulmoScript";
|
|
4
5
|
var TOOL_DEFINITION = {
|
|
@@ -111,29 +112,54 @@ IMPORTANT: "imagePrompt" and "moviePrompt" are plain string fields on the beat,
|
|
|
111
112
|
}
|
|
112
113
|
};
|
|
113
114
|
//#endregion
|
|
115
|
+
//#region ../../common/dist/index.js
|
|
116
|
+
/** Narrow `unknown` to a plain object (not null, not array). */
|
|
117
|
+
function isRecord$1(value) {
|
|
118
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
119
|
+
}
|
|
120
|
+
/** Check that a record has a specific key with a string value. */
|
|
121
|
+
function hasStringProp(value, key) {
|
|
122
|
+
return isRecord$1(value) && typeof value[key] === "string";
|
|
123
|
+
}
|
|
124
|
+
/** Normalise an unknown thrown value into a human-readable string. Isomorphic
|
|
125
|
+
* (host, bridges, plugins, Vue) — this is the single home for the helper that
|
|
126
|
+
* #2217 could only consolidate for server code, since `@mulmoclaude/core/utils`
|
|
127
|
+
* is server-only.
|
|
128
|
+
*
|
|
129
|
+
* A non-Error object with a non-empty string `details` (gRPC convention) or
|
|
130
|
+
* `message` field surfaces that field — `details` wins — instead of the
|
|
131
|
+
* `[object Object]` a bare `String(err)` would print; an empty-string field
|
|
132
|
+
* falls through. `fallback` covers the error-boundary idiom where a thrown
|
|
133
|
+
* non-Error should read as a descriptive message rather than `String(err)`
|
|
134
|
+
* noise; omit it in logging contexts where `String(err)` is fine. */
|
|
135
|
+
function errorMessage(err, fallback) {
|
|
136
|
+
if (err instanceof Error) return err.message;
|
|
137
|
+
if (hasStringProp(err, "details") && err.details) return err.details;
|
|
138
|
+
if (hasStringProp(err, "message") && err.message) return err.message;
|
|
139
|
+
if (fallback !== void 0) return fallback;
|
|
140
|
+
return String(err);
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
114
143
|
//#region src/core/paths.ts
|
|
115
144
|
var STORIES_DIR = "stories";
|
|
116
|
-
var
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
* than the host's hash-fallback variant; the timestamp suffix appended by
|
|
122
|
-
* `storyFilePath` keeps these throwaway filenames collision-free. */
|
|
123
|
-
function slugify(title, fallback = "story") {
|
|
124
|
-
if (!title) return fallback;
|
|
125
|
-
const collapsed = title.toLowerCase().replace(/[^a-z0-9]+/g, "-").slice(0, MAX_SLUG_LEN);
|
|
126
|
-
let start = 0;
|
|
127
|
-
let end = collapsed.length;
|
|
128
|
-
while (start < end && collapsed[start] === "-") start += 1;
|
|
129
|
-
while (end > start && collapsed[end - 1] === "-") end -= 1;
|
|
130
|
-
return collapsed.slice(start, end) || fallback;
|
|
145
|
+
var STORY_FALLBACK_SLUG = "story";
|
|
146
|
+
/** Lowercase-hyphen slug, capped, leading/trailing hyphens stripped; falls back
|
|
147
|
+
* to `fallback` for empty/undefined/non-ASCII input. */
|
|
148
|
+
function slugify(title, fallback = STORY_FALLBACK_SLUG) {
|
|
149
|
+
return (0, _mulmoclaude_core_artifacts.slugifyArtifact)(title, fallback);
|
|
131
150
|
}
|
|
132
151
|
/** Build a fresh, collision-safe story path for a new script —
|
|
133
152
|
* `stories/<slug>-<epoch-ms>.json`, valid as both the FileOps-relative
|
|
134
153
|
* write path and the wire `filePath`. */
|
|
135
154
|
function storyFilePath(slugSource, now = /* @__PURE__ */ new Date()) {
|
|
136
|
-
return
|
|
155
|
+
return (0, _mulmoclaude_core_artifacts.buildArtifactRelPath)({
|
|
156
|
+
dir: STORIES_DIR,
|
|
157
|
+
title: slugSource,
|
|
158
|
+
ext: ".json",
|
|
159
|
+
fallback: STORY_FALLBACK_SLUG,
|
|
160
|
+
now,
|
|
161
|
+
partitioned: false
|
|
162
|
+
});
|
|
137
163
|
}
|
|
138
164
|
/**
|
|
139
165
|
* Normalize a caller-supplied wire path to the canonical
|
|
@@ -152,9 +178,9 @@ function storyFilePath(slugSource, now = /* @__PURE__ */ new Date()) {
|
|
|
152
178
|
function normalizeStoryPath(filePath) {
|
|
153
179
|
if (filePath.length === 0 || filePath.includes("\\")) return null;
|
|
154
180
|
if (filePath.startsWith("/") || /^[A-Za-z]:/.test(filePath)) return null;
|
|
181
|
+
if ((0, _mulmoclaude_core_artifacts.hasUnsafePathSegment)(filePath)) return null;
|
|
155
182
|
const segments = filePath.split("/");
|
|
156
|
-
|
|
157
|
-
const trimmed = segments[0] === ARTIFACTS_DIR && segments[1] === STORIES_DIR ? segments.slice(1) : segments;
|
|
183
|
+
const trimmed = segments[0] === _mulmoclaude_core_artifacts.ARTIFACTS_ROOT && segments[1] === STORIES_DIR ? segments.slice(1) : segments;
|
|
158
184
|
const rest = trimmed[0] === STORIES_DIR ? trimmed.slice(1) : trimmed;
|
|
159
185
|
if (rest.length === 0) return null;
|
|
160
186
|
return [STORIES_DIR, ...rest].join("/");
|
|
@@ -171,12 +197,10 @@ function formatZodIssues(issues) {
|
|
|
171
197
|
}).join("; ");
|
|
172
198
|
return issues.length > 3 ? `${head} (+${issues.length - 3} more)` : head;
|
|
173
199
|
}
|
|
174
|
-
/**
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
|
|
178
|
-
*/
|
|
179
|
-
function validateUpdateScriptBody(body) {
|
|
200
|
+
/** Shared prelude: require an object body carrying a non-empty
|
|
201
|
+
* `filePath`. On success returns the narrowed record + filePath so the
|
|
202
|
+
* caller reads the remaining fields without re-narrowing. */
|
|
203
|
+
function validateFilePathBody(body) {
|
|
180
204
|
if (!isRecord(body)) return {
|
|
181
205
|
ok: false,
|
|
182
206
|
error: "body must be an object"
|
|
@@ -185,11 +209,28 @@ function validateUpdateScriptBody(body) {
|
|
|
185
209
|
ok: false,
|
|
186
210
|
error: "filePath must be a non-empty string"
|
|
187
211
|
};
|
|
188
|
-
|
|
212
|
+
return {
|
|
213
|
+
ok: true,
|
|
214
|
+
value: {
|
|
215
|
+
record: body,
|
|
216
|
+
filePath: body.filePath
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Validate the `update-script` request body. Returns the parsed,
|
|
222
|
+
* schema-conformant script on success, or a human-readable error
|
|
223
|
+
* suitable for sending back as a 400 response.
|
|
224
|
+
*/
|
|
225
|
+
function validateUpdateScriptBody(body) {
|
|
226
|
+
const base = validateFilePathBody(body);
|
|
227
|
+
if (!base.ok) return base;
|
|
228
|
+
const { record, filePath } = base.value;
|
|
229
|
+
if (record.script === void 0) return {
|
|
189
230
|
ok: false,
|
|
190
231
|
error: "script is required"
|
|
191
232
|
};
|
|
192
|
-
const parsed = _mulmocast_types.mulmoScriptSchema.safeParse(
|
|
233
|
+
const parsed = _mulmocast_types.mulmoScriptSchema.safeParse(record.script);
|
|
193
234
|
if (!parsed.success) return {
|
|
194
235
|
ok: false,
|
|
195
236
|
error: `invalid script: ${formatZodIssues(parsed.error.issues)}`
|
|
@@ -197,7 +238,7 @@ function validateUpdateScriptBody(body) {
|
|
|
197
238
|
return {
|
|
198
239
|
ok: true,
|
|
199
240
|
value: {
|
|
200
|
-
filePath
|
|
241
|
+
filePath,
|
|
201
242
|
script: parsed.data
|
|
202
243
|
}
|
|
203
244
|
};
|
|
@@ -208,23 +249,19 @@ function validateUpdateScriptBody(body) {
|
|
|
208
249
|
* against the actual script length after reading the file.
|
|
209
250
|
*/
|
|
210
251
|
function validateUpdateBeatBody(body) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (typeof
|
|
216
|
-
ok: false,
|
|
217
|
-
error: "filePath must be a non-empty string"
|
|
218
|
-
};
|
|
219
|
-
if (typeof body.beatIndex !== "number" || !Number.isInteger(body.beatIndex) || body.beatIndex < 0) return {
|
|
252
|
+
const base = validateFilePathBody(body);
|
|
253
|
+
if (!base.ok) return base;
|
|
254
|
+
const { record, filePath } = base.value;
|
|
255
|
+
const beatIndex = record.beatIndex;
|
|
256
|
+
if (typeof beatIndex !== "number" || !Number.isInteger(beatIndex) || beatIndex < 0) return {
|
|
220
257
|
ok: false,
|
|
221
258
|
error: "beatIndex must be a non-negative integer"
|
|
222
259
|
};
|
|
223
|
-
if (
|
|
260
|
+
if (record.beat === void 0) return {
|
|
224
261
|
ok: false,
|
|
225
262
|
error: "beat is required"
|
|
226
263
|
};
|
|
227
|
-
const parsed = _mulmocast_types.mulmoBeatSchema.safeParse(
|
|
264
|
+
const parsed = _mulmocast_types.mulmoBeatSchema.safeParse(record.beat);
|
|
228
265
|
if (!parsed.success) return {
|
|
229
266
|
ok: false,
|
|
230
267
|
error: `invalid beat: ${formatZodIssues(parsed.error.issues)}`
|
|
@@ -232,8 +269,8 @@ function validateUpdateBeatBody(body) {
|
|
|
232
269
|
return {
|
|
233
270
|
ok: true,
|
|
234
271
|
value: {
|
|
235
|
-
filePath
|
|
236
|
-
beatIndex
|
|
272
|
+
filePath,
|
|
273
|
+
beatIndex,
|
|
237
274
|
beat: parsed.data
|
|
238
275
|
}
|
|
239
276
|
};
|
|
@@ -254,9 +291,6 @@ function notFound(error) {
|
|
|
254
291
|
error
|
|
255
292
|
};
|
|
256
293
|
}
|
|
257
|
-
function errorText(err) {
|
|
258
|
-
return err instanceof Error ? err.message : String(err);
|
|
259
|
-
}
|
|
260
294
|
function stringifyScript(script) {
|
|
261
295
|
return JSON.stringify(script, null, 2);
|
|
262
296
|
}
|
|
@@ -287,7 +321,7 @@ async function loadExistingScript(context, filePath) {
|
|
|
287
321
|
try {
|
|
288
322
|
parsed = JSON.parse(raw);
|
|
289
323
|
} catch (err) {
|
|
290
|
-
return badRequest(`Invalid JSON: ${
|
|
324
|
+
return badRequest(`Invalid JSON: ${errorMessage(err)}`);
|
|
291
325
|
}
|
|
292
326
|
const validation = _mulmocast_types.mulmoScriptSchema.safeParse(parsed);
|
|
293
327
|
if (!validation.success) return badRequest("File is not a valid MulmoScript");
|
|
@@ -333,7 +367,7 @@ async function executeUpdateBeat(context, body) {
|
|
|
333
367
|
try {
|
|
334
368
|
script = JSON.parse(await context.files.artifacts.read(resolved.storyPath));
|
|
335
369
|
} catch (err) {
|
|
336
|
-
return badRequest(`Invalid JSON: ${
|
|
370
|
+
return badRequest(`Invalid JSON: ${errorMessage(err)}`);
|
|
337
371
|
}
|
|
338
372
|
if (!Array.isArray(script.beats) || beatIndex >= script.beats.length) return badRequest("Invalid beatIndex");
|
|
339
373
|
script.beats[beatIndex] = beat;
|
|
@@ -394,6 +428,12 @@ Object.defineProperty(exports, "TOOL_NAME", {
|
|
|
394
428
|
return TOOL_NAME;
|
|
395
429
|
}
|
|
396
430
|
});
|
|
431
|
+
Object.defineProperty(exports, "errorMessage", {
|
|
432
|
+
enumerable: true,
|
|
433
|
+
get: function() {
|
|
434
|
+
return errorMessage;
|
|
435
|
+
}
|
|
436
|
+
});
|
|
397
437
|
Object.defineProperty(exports, "executeMulmoScript", {
|
|
398
438
|
enumerable: true,
|
|
399
439
|
get: function() {
|
|
@@ -455,4 +495,4 @@ Object.defineProperty(exports, "validateUpdateScriptBody", {
|
|
|
455
495
|
}
|
|
456
496
|
});
|
|
457
497
|
|
|
458
|
-
//# sourceMappingURL=plugin-
|
|
498
|
+
//# sourceMappingURL=plugin-BLp8tSYt.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-BLp8tSYt.cjs","names":["isRecord"],"sources":["../src/core/definition.ts","../../../common/dist/index.js","../src/core/paths.ts","../src/core/validate.ts","../src/core/plugin.ts"],"sourcesContent":["import type { ToolDefinition } from \"gui-chat-protocol\";\n\nexport const TOOL_NAME = \"presentMulmoScript\";\n\n// Single source of truth for the presentMulmoScript tool schema, shared by\n// MulmoClaude (host built-in shim re-exports this) and MulmoTerminal.\n// (Extracted byte-identical from the host definition; evolves here with the\n// package version.)\nexport const TOOL_DEFINITION: ToolDefinition = {\n type: \"function\",\n name: TOOL_NAME,\n description: `Save and present a MulmoScript story or presentation as a visual storyboard in the canvas.\n\nTwo modes — provide EXACTLY ONE of \\`script\\` or \\`filePath\\`:\n\n1. **Create new** — pass \\`script\\` (full MulmoScript JSON). Server saves it to disk and presents it.\n2. **Re-display existing** — pass \\`filePath\\` (the \\`filePath\\` returned by a previous call, e.g. \"stories/my-story-1700000000000.json\"; it is resolved against the workspace's \\`artifacts/\\` directory, NOT the workspace root). Much cheaper than re-sending the full script. Use whenever the user wants to revisit a presentation that was already created in this workspace.\n\nOptional \\`autoGenerateMovie: true\\` kicks off movie generation in the background, so the final video is ready by the time the user opens the canvas. Movie generation is expensive (multiple image + audio API calls + video encoding) — only set this when the user has explicitly asked for the movie. Default \\`false\\`.\n\nProvider rules for new scripts:\n- \\`speechParams.speakers.<name>.provider\\`: \\`\"gemini\"\\` — pairs with Gemini voices like \\`\"Kore\"\\`, \\`\"Aoede\"\\`, \\`\"Puck\"\\`. Do NOT use \\`\"google\"\\` here — that routes to Google Cloud TTS, where Gemini-class voices fail with \"This voice requires a model name to be specified.\" unless an explicit \\`model\\` is set.\n- \\`imageParams.provider\\`: \\`\"google\"\\`\n- \\`movieParams.provider\\`: \\`\"google\"\\`\n- Do NOT add a top-level \\`provider\\` field to \\`speechParams\\` — provider belongs per-speaker only.\n\nRequired structure:\n\n{\n \"$mulmocast\": { \"version\": \"1.1\" },\n \"title\": \"The Life of a Star\",\n \"description\": \"A short educational explainer about stellar evolution\",\n \"lang\": \"en\",\n \"speechParams\": {\n \"speakers\": {\n \"Presenter\": {\n \"provider\": \"gemini\",\n \"voiceId\": \"Kore\",\n \"displayName\": { \"en\": \"Presenter\" }\n }\n }\n },\n \"imageParams\": { \"provider\": \"google\", \"model\": \"gemini-3.1-flash-image-preview\" },\n \"movieParams\": { \"provider\": \"google\", \"model\": \"veo-3.1-generate\" },\n \"beats\": [\n {\n \"speaker\": \"Presenter\",\n \"text\": \"Narration spoken aloud for this beat.\",\n \"imagePrompt\": \"Detailed description — AI generates the image\"\n },\n {\n \"speaker\": \"Presenter\",\n \"text\": \"Bullet point beat.\",\n \"image\": { \"type\": \"textSlide\", \"slide\": { \"title\": \"Slide Title\", \"bullets\": [\"Point one\", \"Point two\"] } }\n },\n {\n \"speaker\": \"Presenter\",\n \"text\": \"Markdown beat.\",\n \"image\": { \"type\": \"markdown\", \"markdown\": \"## Heading\\\\n\\\\nBody text here.\" }\n },\n {\n \"speaker\": \"Presenter\",\n \"text\": \"Chart beat — use for data, comparisons, trends.\",\n \"image\": { \"type\": \"chart\", \"title\": \"Chart Title\", \"chartData\": { \"type\": \"bar\", \"data\": { \"labels\": [\"A\", \"B\", \"C\"], \"datasets\": [{ \"label\": \"Series\", \"data\": [10, 20, 30] }] } } }\n },\n {\n \"speaker\": \"Presenter\",\n \"text\": \"Diagram beat — use for flows, architectures, relationships.\",\n \"image\": { \"type\": \"mermaid\", \"title\": \"Diagram Title\", \"code\": { \"kind\": \"text\", \"text\": \"graph TD\\\\n A[Start] --> B[Process] --> C[End]\" } }\n },\n {\n \"speaker\": \"Presenter\",\n \"text\": \"Rich interactive beat — use for custom layouts, animations, or anything that benefits from HTML/CSS.\",\n \"image\": { \"type\": \"html_tailwind\", \"html\": \"<div class=\\\\\"flex items-center justify-center h-full text-4xl font-bold text-blue-600\\\\\">Hello World</div>\" }\n },\n {\n \"speaker\": \"Presenter\",\n \"text\": \"AI video beat.\",\n \"moviePrompt\": \"Detailed description — AI generates the video clip\"\n }\n ]\n}\n\nBeat visual options (choose one per beat):\n- \"imagePrompt\": \"...\" → top-level string field — AI generates an image from the prompt\n- \"moviePrompt\": \"...\" → top-level string field — AI generates a video clip from the prompt\n- \"image\": { \"type\": \"textSlide\", \"slide\": { \"title\", \"subtitle\"?, \"bullets\"? } }\n- \"image\": { \"type\": \"markdown\", \"markdown\": \"...\" }\n- \"image\": { \"type\": \"chart\", \"title\": \"...\", \"chartData\": { \"type\": \"bar\"|\"line\"|\"pie\"|..., \"data\": { \"labels\": [...], \"datasets\": [...] } } } ← PREFER for data/numbers/comparisons. chartData is a full Chart.js config: labels/datasets go under \"data\", not at the top level.\n- \"image\": { \"type\": \"mermaid\", \"title\": \"...\", \"code\": { \"kind\": \"text\", \"text\": \"...\" } } ← PREFER for flows/diagrams/relationships\n- \"image\": { \"type\": \"html_tailwind\", \"html\": \"...\", \"script\"?: \"...\" } ← PREFER for rich layouts, animations, custom visuals\n\nIMPORTANT: \"imagePrompt\" and \"moviePrompt\" are plain string fields on the beat, NOT nested under \"image\".`,\n parameters: {\n type: \"object\",\n properties: {\n script: {\n type: \"object\",\n description:\n \"Complete MulmoScript JSON for a NEW presentation. Must include $mulmocast, speechParams, imageParams, movieParams, and beats array. Always populate the top-level 'description' field with a concise 1–2 sentence summary of the presentation. Do NOT pass alongside `filePath`.\",\n additionalProperties: true,\n },\n filename: {\n type: \"string\",\n description:\n \"Optional filename without extension. Defaults to a slug of the script title. Only meaningful with `script`; ignored when `filePath` is given.\",\n },\n filePath: {\n type: \"string\",\n description:\n \"Path of an EXISTING MulmoScript JSON file, as returned by a previous call (e.g. 'stories/my-story-1700000000000.json'). Resolved against the workspace's `artifacts/` directory, not the workspace root ('artifacts/stories/…' is also accepted). Use this to re-display a script previously saved in this workspace, instead of resending the full JSON. Do NOT pass alongside `script`.\",\n },\n autoGenerateMovie: {\n type: \"boolean\",\n description:\n \"When true, the server starts movie generation in the background after save/load. The user does NOT need to open the canvas — progress streams via the existing session channel. Default false. Only set true when the user has explicitly asked for the movie; generation is expensive.\",\n },\n },\n required: [],\n },\n};\n","// General-purpose runtime type guards, shared across the MulmoClaude host,\n// bridges, and plugins. This is a leaf package — pure and dependency-free — so\n// any tier can import it without creating an uphill edge.\n//\n// These originated as `server/utils/types.ts` (#504), which centralised 40+\n// hand-written inline `typeof x === \"object\"` checks. They are promoted here so\n// the same guards stop being re-hand-written in every bridge and plugin too.\n/** Narrow `unknown` to a plain object (not null, not array). */\nexport function isRecord(value) {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n/** Narrow `unknown` to any object (not null, arrays allowed).\n * Use `isRecord` when you need to access string keys. */\nexport function isObj(value) {\n return typeof value === \"object\" && value !== null;\n}\n/** Non-empty string after trimming whitespace. */\nexport function isNonEmptyString(value) {\n return typeof value === \"string\" && value.trim().length > 0;\n}\n/** Record whose values are all strings. */\nexport function isStringRecord(value) {\n if (!isRecord(value))\n return false;\n return Object.values(value).every((val) => typeof val === \"string\");\n}\n/** String array (every element is a string). */\nexport function isStringArray(value) {\n return Array.isArray(value) && value.every((val) => typeof val === \"string\");\n}\n/** An array of unknowns. Prefer this over a bare `Array.isArray` in typed code:\n * `Array.isArray(x: unknown)` narrows to `any[]`, silently reintroducing\n * `any`, whereas this keeps the element type `unknown`. */\nexport function isUnknownArray(value) {\n return Array.isArray(value);\n}\n/** Error-like object with a `code` property (e.g. Node.js fs errors). */\nexport function isErrorWithCode(value) {\n return isRecord(value) && typeof value.code === \"string\";\n}\n/** Check that a record has a specific key with a string value. */\nexport function hasStringProp(value, key) {\n return isRecord(value) && typeof value[key] === \"string\";\n}\n/** Check that a record has a specific key with a number value. */\nexport function hasNumberProp(value, key) {\n return isRecord(value) && typeof value[key] === \"number\";\n}\n/** Split a comma-separated env value into trimmed, non-empty entries.\n * `lowercase` folds case for identifiers compared case-insensitively\n * (JIDs, email addresses, hex pubkeys). Absent/empty input → empty list. */\nexport function parseCsvList(raw, opts) {\n return (raw ?? \"\")\n .split(\",\")\n .map((entry) => (opts?.lowercase ? entry.trim().toLowerCase() : entry.trim()))\n .filter(Boolean);\n}\n/** A comma-separated env value as a Set — the canonical allowlist shape,\n * where an empty set is the \"allow all\" sentinel (`set.size === 0`). */\nexport function parseCsvSet(raw, opts) {\n return new Set(parseCsvList(raw, opts));\n}\n/** Normalise an unknown thrown value into a human-readable string. Isomorphic\n * (host, bridges, plugins, Vue) — this is the single home for the helper that\n * #2217 could only consolidate for server code, since `@mulmoclaude/core/utils`\n * is server-only.\n *\n * A non-Error object with a non-empty string `details` (gRPC convention) or\n * `message` field surfaces that field — `details` wins — instead of the\n * `[object Object]` a bare `String(err)` would print; an empty-string field\n * falls through. `fallback` covers the error-boundary idiom where a thrown\n * non-Error should read as a descriptive message rather than `String(err)`\n * noise; omit it in logging contexts where `String(err)` is fine. */\nexport function errorMessage(err, fallback) {\n if (err instanceof Error)\n return err.message;\n if (hasStringProp(err, \"details\") && err.details)\n return err.details;\n if (hasStringProp(err, \"message\") && err.message)\n return err.message;\n if (fallback !== undefined)\n return fallback;\n return String(err);\n}\n/** `Date` → `YYYY-MM-DD` in UTC — for dates that must not shift with the\n * host's local timezone (tool-trace search dirs, API date keys). Isomorphic\n * single source (#2480): the host re-exports it from `server/utils/date.ts`,\n * x-plugin imports it directly. The `@receptron/task-scheduler` copy stays\n * local on purpose — that leaf package is published independently and kept\n * dependency-free. Wall-clock questions use the host's `toLocalIsoDate`. */\nexport function toUtcIsoDate(timestamp) {\n const year = timestamp.getUTCFullYear();\n const month = String(timestamp.getUTCMonth() + 1).padStart(2, \"0\");\n const day = String(timestamp.getUTCDate()).padStart(2, \"0\");\n return `${year}-${month}-${day}`;\n}\n// A Map, not an object literal: `{}[char]` reads through the prototype chain,\n// so a future caller widening the regex would silently get `[object Object]`\n// for keys like `constructor`.\nconst HTML_ESCAPES = new Map([\n [\"&\", \"&\"],\n [\"<\", \"<\"],\n [\">\", \">\"],\n ['\"', \""\"],\n [\"'\", \"'\"],\n]);\n/** HTML-escape text destined for markup or an attribute value — the fixed\n * five-character map, nothing more. Lives here rather than in\n * `@mulmoclaude/core/wiki` (#2483) because `@mulmoclaude/markdown-utils` is a\n * leaf that core depends on and so cannot import back up; core/wiki\n * re-exports this, keeping its consumers' import path unchanged.\n *\n * Escaping `&` first is what makes a single pass safe — the entities this\n * introduces contain none of the other four characters, so nothing is\n * double-escaped. Not a sanitiser: it neither strips tags nor validates URLs. */\nexport function escapeHtml(value) {\n return value.replace(/[&<>\"']/g, (char) => HTML_ESCAPES.get(char) ?? char);\n}\nexport { scanEnvOptions, snakeToLowerCamel } from \"./envScan.js\";\n","// Path helpers for MulmoScript story artifacts. The generic build primitives\n// (slug + the `\"\"`/`.`/`..` traversal guard) live in the shared, browser-safe\n// `@mulmoclaude/core/artifacts` (#2405); only the story-specific wire-path\n// rules stay here.\n//\n// Path model: the stories directory lives at `<workspace>/artifacts/stories`\n// and the FileOps scope root is `<workspace>/artifacts`, so the\n// FileOps-relative path and the historical `stories/<name>.json` wire form\n// (which every mulmoScript endpoint keys on) are the SAME string. Stories are\n// NOT `YYYY/MM`-partitioned, so `storyFilePath` opts out of partitioning.\n\nimport { ARTIFACTS_ROOT, buildArtifactRelPath, hasUnsafePathSegment, slugifyArtifact } from \"@mulmoclaude/core/artifacts\";\n\nconst STORIES_DIR = \"stories\";\nconst STORY_FALLBACK_SLUG = \"story\";\n\n/** Lowercase-hyphen slug, capped, leading/trailing hyphens stripped; falls back\n * to `fallback` for empty/undefined/non-ASCII input. */\nexport function slugify(title: string | undefined, fallback = STORY_FALLBACK_SLUG): string {\n return slugifyArtifact(title, fallback);\n}\n\n/** Build a fresh, collision-safe story path for a new script —\n * `stories/<slug>-<epoch-ms>.json`, valid as both the FileOps-relative\n * write path and the wire `filePath`. */\nexport function storyFilePath(slugSource: string, now: Date = new Date()): string {\n return buildArtifactRelPath({ dir: STORIES_DIR, title: slugSource, ext: \".json\", fallback: STORY_FALLBACK_SLUG, now, partitioned: false });\n}\n\n/**\n * Normalize a caller-supplied wire path to the canonical\n * `stories/<rel>` form, or null when it can't be trusted. Accepts the\n * canonical `stories/foo.json` convention, bare `foo.json` (the host route\n * historically allowed either), and the workspace-relative spelling\n * `artifacts/stories/foo.json` — the tool description called `filePath`\n * \"workspace-relative\" for a long time, so agents legitimately send it.\n * A leading `artifacts` segment is dropped only when `stories` follows;\n * a bare `artifacts/foo.json` keeps its historical meaning (a file named\n * `artifacts/foo.json` under the stories dir). Rejects absolute paths,\n * backslashes, and any empty / `.` / `..` segment — the lexical guard\n * before every `files.artifacts` read/write (FileOps re-checks\n * containment as defence-in-depth).\n */\nexport function normalizeStoryPath(filePath: string): string | null {\n if (filePath.length === 0 || filePath.includes(\"\\\\\")) return null;\n // Absolute POSIX path or Windows drive prefix.\n if (filePath.startsWith(\"/\") || /^[A-Za-z]:/.test(filePath)) return null;\n if (hasUnsafePathSegment(filePath)) return null;\n const segments = filePath.split(\"/\");\n const trimmed = segments[0] === ARTIFACTS_ROOT && segments[1] === STORIES_DIR ? segments.slice(1) : segments;\n const rest = trimmed[0] === STORIES_DIR ? trimmed.slice(1) : trimmed;\n if (rest.length === 0) return null;\n return [STORIES_DIR, ...rest].join(\"/\");\n}\n","// Body validators for the mulmoScript update endpoints, moved verbatim from\n// the host's `server/api/routes/mulmoScriptValidate.ts` so MulmoClaude and\n// MulmoTerminal share one definition of a \"valid script\" / \"valid beat\".\n//\n// The `@mulmocast/types` package exports zod schemas that mirror the\n// canonical MulmoScript / MulmoBeat shapes. The same schemas back client-side\n// edit-time validation in the presentMulmoScript View.\n\nimport { mulmoBeatSchema, mulmoScriptSchema } from \"@mulmocast/types\";\n\nexport type ValidationResult<T> = { ok: true; value: T } | { ok: false; error: string };\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction formatZodIssues(\n // Zod's `$ZodIssue.path` is `PropertyKey[]` (includes `symbol`).\n // Accept the wider type so callers can pass `safeParse().error.issues`\n // directly; stringify any non-string/number segments at format time.\n issues: readonly { message: string; path: readonly PropertyKey[] }[],\n): string {\n if (issues.length === 0) return \"invalid shape\";\n const head = issues\n .slice(0, 3)\n .map((i) => {\n const pathStr = i.path.length > 0 ? i.path.map((seg) => String(seg)).join(\".\") : \"<root>\";\n return `${pathStr}: ${i.message}`;\n })\n .join(\"; \");\n return issues.length > 3 ? `${head} (+${issues.length - 3} more)` : head;\n}\n\n/** Shared prelude: require an object body carrying a non-empty\n * `filePath`. On success returns the narrowed record + filePath so the\n * caller reads the remaining fields without re-narrowing. */\nfunction validateFilePathBody(body: unknown): ValidationResult<{ record: Record<string, unknown>; filePath: string }> {\n if (!isRecord(body)) {\n return { ok: false, error: \"body must be an object\" };\n }\n if (typeof body.filePath !== \"string\" || body.filePath === \"\") {\n return { ok: false, error: \"filePath must be a non-empty string\" };\n }\n return { ok: true, value: { record: body, filePath: body.filePath } };\n}\n\n/**\n * Validate the `update-script` request body. Returns the parsed,\n * schema-conformant script on success, or a human-readable error\n * suitable for sending back as a 400 response.\n */\nexport function validateUpdateScriptBody(body: unknown): ValidationResult<{\n filePath: string;\n script: unknown;\n}> {\n const base = validateFilePathBody(body);\n if (!base.ok) return base;\n const { record, filePath } = base.value;\n if (record.script === undefined) {\n return { ok: false, error: \"script is required\" };\n }\n const parsed = mulmoScriptSchema.safeParse(record.script);\n if (!parsed.success) {\n return {\n ok: false,\n error: `invalid script: ${formatZodIssues(parsed.error.issues)}`,\n };\n }\n return {\n ok: true,\n value: { filePath, script: parsed.data },\n };\n}\n\n/**\n * Validate the `update-beat` request body. `beatIndex` is allowed\n * to be any non-negative integer; the handler still bounds-checks\n * against the actual script length after reading the file.\n */\nexport function validateUpdateBeatBody(body: unknown): ValidationResult<{\n filePath: string;\n beatIndex: number;\n beat: unknown;\n}> {\n const base = validateFilePathBody(body);\n if (!base.ok) return base;\n const { record, filePath } = base.value;\n const beatIndex = record.beatIndex;\n if (typeof beatIndex !== \"number\" || !Number.isInteger(beatIndex) || beatIndex < 0) {\n return { ok: false, error: \"beatIndex must be a non-negative integer\" };\n }\n if (record.beat === undefined) {\n return { ok: false, error: \"beat is required\" };\n }\n const parsed = mulmoBeatSchema.safeParse(record.beat);\n if (!parsed.success) {\n return {\n ok: false,\n error: `invalid beat: ${formatZodIssues(parsed.error.issues)}`,\n };\n }\n return {\n ok: true,\n value: {\n filePath,\n beatIndex,\n beat: parsed.data,\n },\n };\n}\n","import type { ToolPluginCore, ToolResult } from \"gui-chat-protocol\";\nimport { mulmoScriptSchema } from \"@mulmocast/types\";\nimport { errorMessage } from \"@mulmoclaude/common\";\nimport { TOOL_DEFINITION } from \"./definition\";\nimport { normalizeStoryPath, storyFilePath } from \"./paths\";\nimport { validateUpdateBeatBody, validateUpdateScriptBody } from \"./validate\";\nimport type { MulmoScriptData, MulmoScriptExecuteContext, SaveMulmoScriptArgs } from \"./types\";\n\n/** Failure half of every outcome below. `code` preserves the hosts'\n * HTTP contract (bad_request → 400, not_found → 404) without the package\n * knowing anything about HTTP. */\nexport interface MulmoScriptFailure {\n ok: false;\n code: \"bad_request\" | \"not_found\";\n error: string;\n}\n\nexport type SaveMulmoScriptOutcome = ({ ok: true; message: string } & MulmoScriptData) | MulmoScriptFailure;\n\nexport type UpdateMulmoScriptOutcome = { ok: true } | MulmoScriptFailure;\n\nfunction badRequest(error: string): MulmoScriptFailure {\n return { ok: false, code: \"bad_request\", error };\n}\n\nfunction notFound(error: string): MulmoScriptFailure {\n return { ok: false, code: \"not_found\", error };\n}\n\nfunction stringifyScript(script: unknown): string {\n // 2-space indent matches the hosts' writeJsonAtomic convention so a\n // package-written script diffs cleanly against host-written ones.\n return JSON.stringify(script, null, 2);\n}\n\n/** Persist a new, schema-validated script under a fresh `stories/…` path. */\nasync function saveNewScript(context: MulmoScriptExecuteContext, script: unknown, filename: string | undefined, now: Date): Promise<SaveMulmoScriptOutcome> {\n const validation = mulmoScriptSchema.safeParse(script);\n if (!validation.success) {\n return badRequest(\"script is not a valid MulmoScript\");\n }\n const validatedScript = validation.data;\n // slugify drops `/`, `\\`, and `..`, so a hostile `filename` like\n // \"../../etc/passwd\" can never escape the stories dir — defense in\n // depth on top of FileOps' own containment check.\n const slugSource = filename ? filename.replace(/\\.json$/i, \"\") : validatedScript.title || \"untitled\";\n const filePath = storyFilePath(slugSource, now);\n await context.files.artifacts.write(filePath, stringifyScript(validatedScript));\n return { ok: true, script: validatedScript, filePath, message: `Saved MulmoScript to ${filePath}` };\n}\n\n/** Re-open an existing script: containment guard, existence, JSON parse,\n * schema validation — same acceptance rules as the save path so a script\n * this package saved can never be one it later refuses to load. */\nasync function loadExistingScript(context: MulmoScriptExecuteContext, filePath: string): Promise<SaveMulmoScriptOutcome> {\n if (!filePath.toLowerCase().endsWith(\".json\")) {\n return badRequest(\"filePath must point to a .json file\");\n }\n const storyPath = normalizeStoryPath(filePath);\n if (!storyPath) {\n return badRequest(\"Invalid filePath\");\n }\n if (!(await context.files.artifacts.exists(storyPath))) {\n return notFound(`File not found: ${filePath}`);\n }\n const raw = await context.files.artifacts.read(storyPath);\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch (err) {\n return badRequest(`Invalid JSON: ${errorMessage(err)}`);\n }\n const validation = mulmoScriptSchema.safeParse(parsed);\n if (!validation.success) {\n return badRequest(\"File is not a valid MulmoScript\");\n }\n return { ok: true, script: validation.data, filePath: storyPath, message: `Loaded MulmoScript from ${storyPath}` };\n}\n\n/**\n * Unified save-or-reopen for the presentMulmoScript tool call. `script`\n * (create new) and `filePath` (existing) are mutually exclusive. Never\n * throws on bad input — validation failures come back as discriminated\n * failures so host routes stay thin adapters. `autoGenerateMovie` is NOT\n * handled here: movie generation needs host backends (mulmocast/ffmpeg),\n * so hosts that support it trigger it from the returned `filePath`.\n */\nexport async function executeMulmoScriptSave(\n context: MulmoScriptExecuteContext,\n args: SaveMulmoScriptArgs,\n now: Date = new Date(),\n): Promise<SaveMulmoScriptOutcome> {\n const { script, filename, filePath } = args ?? {};\n const hasScript = script !== undefined && script !== null;\n const hasFilePath = typeof filePath === \"string\" && filePath !== \"\";\n if (hasScript === hasFilePath) {\n return badRequest(\n hasScript ? \"Provide either `script` or `filePath`, not both.\" : \"Provide either `script` (new presentation) or `filePath` (existing presentation).\",\n );\n }\n return hasFilePath\n ? loadExistingScript(context, filePath as string)\n : saveNewScript(context, script, typeof filename === \"string\" ? filename : undefined, now);\n}\n\n/** Resolve + guard a wire path for the update endpoints. */\nasync function resolveExistingStory(context: MulmoScriptExecuteContext, filePath: string): Promise<{ storyPath: string } | MulmoScriptFailure> {\n const storyPath = normalizeStoryPath(filePath);\n if (!storyPath) return badRequest(\"Invalid filePath\");\n if (!(await context.files.artifacts.exists(storyPath))) {\n return notFound(`File not found: ${filePath}`);\n }\n return { storyPath };\n}\n\n/** Overwrite one beat of an existing script (the View's per-beat source\n * editor). Validates the body shape + beat schema, bounds-checks the index\n * against the script on disk, and writes the whole file back. */\nexport async function executeUpdateBeat(context: MulmoScriptExecuteContext, body: unknown): Promise<UpdateMulmoScriptOutcome> {\n const validation = validateUpdateBeatBody(body);\n if (!validation.ok) return badRequest(validation.error);\n const { filePath, beatIndex, beat } = validation.value;\n\n const resolved = await resolveExistingStory(context, filePath);\n if (\"ok\" in resolved) return resolved;\n\n let script: { beats?: unknown[] };\n try {\n script = JSON.parse(await context.files.artifacts.read(resolved.storyPath));\n } catch (err) {\n return badRequest(`Invalid JSON: ${errorMessage(err)}`);\n }\n if (!Array.isArray(script.beats) || beatIndex >= script.beats.length) {\n return badRequest(\"Invalid beatIndex\");\n }\n script.beats[beatIndex] = beat;\n await context.files.artifacts.write(resolved.storyPath, stringifyScript(script));\n return { ok: true };\n}\n\n/** Overwrite the whole script (the View's full-source editor / deck-editor\n * auto-save). The body's `script` is schema-validated by\n * `validateUpdateScriptBody` before the write. */\nexport async function executeUpdateScript(context: MulmoScriptExecuteContext, body: unknown): Promise<UpdateMulmoScriptOutcome> {\n const validation = validateUpdateScriptBody(body);\n if (!validation.ok) return badRequest(validation.error);\n const { filePath, script } = validation.value;\n\n const resolved = await resolveExistingStory(context, filePath);\n if (\"ok\" in resolved) return resolved;\n\n await context.files.artifacts.write(resolved.storyPath, stringifyScript(script));\n return { ok: true };\n}\n\n/** ToolResult-shaped wrapper over `executeMulmoScriptSave` for runtime hosts\n * (e.g. MulmoTerminal's package loader), where the tool call resolves to a\n * ToolResult rather than an HTTP response. Failures are narrate-only\n * (message, no data) so the agent can self-correct. */\nexport async function executeMulmoScript(context: MulmoScriptExecuteContext, args: SaveMulmoScriptArgs): Promise<ToolResult<MulmoScriptData>> {\n const outcome = await executeMulmoScriptSave(context, args);\n if (!outcome.ok) {\n return {\n message: outcome.error,\n instructions: \"Acknowledge the error and retry with a valid `script` (new) or an existing `filePath`.\",\n };\n }\n // The tool schema advertises `autoGenerateMovie`, but movie generation\n // needs host backends (mulmocast/ffmpeg) this generic execute path\n // doesn't have — MulmoClaude honours the flag in its own save route.\n // Say so in the result rather than silently dropping the option, so the\n // agent doesn't tell the user a movie is on its way.\n const ignoredMovieNote = args.autoGenerateMovie === true ? \" (autoGenerateMovie is not supported by this host and was ignored)\" : \"\";\n return {\n message: `${outcome.message}${ignoredMovieNote}`,\n data: { script: outcome.script, filePath: outcome.filePath },\n instructions: \"Display the storyboard to the user.\",\n };\n}\n\n/** Non-Vue plugin core for runtime hosts that register the package directly.\n * MulmoClaude consumes only TOOL_DEFINITION + the execute functions in its\n * own routes, so it doesn't use this. */\nexport const pluginCore: ToolPluginCore<MulmoScriptData, MulmoScriptData, SaveMulmoScriptArgs> = {\n toolDefinition: TOOL_DEFINITION,\n execute: executeMulmoScript as unknown as ToolPluginCore<MulmoScriptData, MulmoScriptData, SaveMulmoScriptArgs>[\"execute\"],\n generatingMessage: \"Generating MulmoScript storyboard…\",\n isEnabled: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,IAAI,OAAO,WAAW,WAAW,KAAK;CACtD,MAAM,EAAE,UAAU,WAAW,WAAW;CAExC,MAAM,WAAW,MAAM,qBAAqB,SAAS,QAAQ;CAC7D,IAAI,QAAQ,UAAU,OAAO;CAE7B,MAAM,QAAQ,MAAM,UAAU,MAAM,SAAS,WAAW,gBAAgB,MAAM,CAAC;CAC/E,OAAO,EAAE,IAAI,KAAK;AACpB;;;;;AAMA,eAAsB,mBAAmB,SAAoC,MAAiE;CAC5I,MAAM,UAAU,MAAM,uBAAuB,SAAS,IAAI;CAC1D,IAAI,CAAC,QAAQ,IACX,OAAO;EACL,SAAS,QAAQ;EACjB,cAAc;CAChB;CAOF,MAAM,mBAAmB,KAAK,sBAAsB,OAAO,uEAAuE;CAClI,OAAO;EACL,SAAS,GAAG,QAAQ,UAAU;EAC9B,MAAM;GAAE,QAAQ,QAAQ;GAAQ,UAAU,QAAQ;EAAS;EAC3D,cAAc;CAChB;AACF;;;;AAKA,IAAa,aAAoF;CAC/F,gBAAgB;CAChB,SAAS;CACT,mBAAmB;CACnB,iBAAiB;AACnB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { mulmoBeatSchema, mulmoScriptSchema } from "@mulmocast/types";
|
|
2
|
+
import { ARTIFACTS_ROOT, buildArtifactRelPath, hasUnsafePathSegment, slugifyArtifact } from "@mulmoclaude/core/artifacts";
|
|
2
3
|
//#region src/core/definition.ts
|
|
3
4
|
var TOOL_NAME = "presentMulmoScript";
|
|
4
5
|
var TOOL_DEFINITION = {
|
|
@@ -111,29 +112,54 @@ IMPORTANT: "imagePrompt" and "moviePrompt" are plain string fields on the beat,
|
|
|
111
112
|
}
|
|
112
113
|
};
|
|
113
114
|
//#endregion
|
|
115
|
+
//#region ../../common/dist/index.js
|
|
116
|
+
/** Narrow `unknown` to a plain object (not null, not array). */
|
|
117
|
+
function isRecord$1(value) {
|
|
118
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
119
|
+
}
|
|
120
|
+
/** Check that a record has a specific key with a string value. */
|
|
121
|
+
function hasStringProp(value, key) {
|
|
122
|
+
return isRecord$1(value) && typeof value[key] === "string";
|
|
123
|
+
}
|
|
124
|
+
/** Normalise an unknown thrown value into a human-readable string. Isomorphic
|
|
125
|
+
* (host, bridges, plugins, Vue) — this is the single home for the helper that
|
|
126
|
+
* #2217 could only consolidate for server code, since `@mulmoclaude/core/utils`
|
|
127
|
+
* is server-only.
|
|
128
|
+
*
|
|
129
|
+
* A non-Error object with a non-empty string `details` (gRPC convention) or
|
|
130
|
+
* `message` field surfaces that field — `details` wins — instead of the
|
|
131
|
+
* `[object Object]` a bare `String(err)` would print; an empty-string field
|
|
132
|
+
* falls through. `fallback` covers the error-boundary idiom where a thrown
|
|
133
|
+
* non-Error should read as a descriptive message rather than `String(err)`
|
|
134
|
+
* noise; omit it in logging contexts where `String(err)` is fine. */
|
|
135
|
+
function errorMessage(err, fallback) {
|
|
136
|
+
if (err instanceof Error) return err.message;
|
|
137
|
+
if (hasStringProp(err, "details") && err.details) return err.details;
|
|
138
|
+
if (hasStringProp(err, "message") && err.message) return err.message;
|
|
139
|
+
if (fallback !== void 0) return fallback;
|
|
140
|
+
return String(err);
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
114
143
|
//#region src/core/paths.ts
|
|
115
144
|
var STORIES_DIR = "stories";
|
|
116
|
-
var
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
* than the host's hash-fallback variant; the timestamp suffix appended by
|
|
122
|
-
* `storyFilePath` keeps these throwaway filenames collision-free. */
|
|
123
|
-
function slugify(title, fallback = "story") {
|
|
124
|
-
if (!title) return fallback;
|
|
125
|
-
const collapsed = title.toLowerCase().replace(/[^a-z0-9]+/g, "-").slice(0, MAX_SLUG_LEN);
|
|
126
|
-
let start = 0;
|
|
127
|
-
let end = collapsed.length;
|
|
128
|
-
while (start < end && collapsed[start] === "-") start += 1;
|
|
129
|
-
while (end > start && collapsed[end - 1] === "-") end -= 1;
|
|
130
|
-
return collapsed.slice(start, end) || fallback;
|
|
145
|
+
var STORY_FALLBACK_SLUG = "story";
|
|
146
|
+
/** Lowercase-hyphen slug, capped, leading/trailing hyphens stripped; falls back
|
|
147
|
+
* to `fallback` for empty/undefined/non-ASCII input. */
|
|
148
|
+
function slugify(title, fallback = STORY_FALLBACK_SLUG) {
|
|
149
|
+
return slugifyArtifact(title, fallback);
|
|
131
150
|
}
|
|
132
151
|
/** Build a fresh, collision-safe story path for a new script —
|
|
133
152
|
* `stories/<slug>-<epoch-ms>.json`, valid as both the FileOps-relative
|
|
134
153
|
* write path and the wire `filePath`. */
|
|
135
154
|
function storyFilePath(slugSource, now = /* @__PURE__ */ new Date()) {
|
|
136
|
-
return
|
|
155
|
+
return buildArtifactRelPath({
|
|
156
|
+
dir: STORIES_DIR,
|
|
157
|
+
title: slugSource,
|
|
158
|
+
ext: ".json",
|
|
159
|
+
fallback: STORY_FALLBACK_SLUG,
|
|
160
|
+
now,
|
|
161
|
+
partitioned: false
|
|
162
|
+
});
|
|
137
163
|
}
|
|
138
164
|
/**
|
|
139
165
|
* Normalize a caller-supplied wire path to the canonical
|
|
@@ -152,9 +178,9 @@ function storyFilePath(slugSource, now = /* @__PURE__ */ new Date()) {
|
|
|
152
178
|
function normalizeStoryPath(filePath) {
|
|
153
179
|
if (filePath.length === 0 || filePath.includes("\\")) return null;
|
|
154
180
|
if (filePath.startsWith("/") || /^[A-Za-z]:/.test(filePath)) return null;
|
|
181
|
+
if (hasUnsafePathSegment(filePath)) return null;
|
|
155
182
|
const segments = filePath.split("/");
|
|
156
|
-
|
|
157
|
-
const trimmed = segments[0] === ARTIFACTS_DIR && segments[1] === STORIES_DIR ? segments.slice(1) : segments;
|
|
183
|
+
const trimmed = segments[0] === ARTIFACTS_ROOT && segments[1] === STORIES_DIR ? segments.slice(1) : segments;
|
|
158
184
|
const rest = trimmed[0] === STORIES_DIR ? trimmed.slice(1) : trimmed;
|
|
159
185
|
if (rest.length === 0) return null;
|
|
160
186
|
return [STORIES_DIR, ...rest].join("/");
|
|
@@ -171,12 +197,10 @@ function formatZodIssues(issues) {
|
|
|
171
197
|
}).join("; ");
|
|
172
198
|
return issues.length > 3 ? `${head} (+${issues.length - 3} more)` : head;
|
|
173
199
|
}
|
|
174
|
-
/**
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
|
|
178
|
-
*/
|
|
179
|
-
function validateUpdateScriptBody(body) {
|
|
200
|
+
/** Shared prelude: require an object body carrying a non-empty
|
|
201
|
+
* `filePath`. On success returns the narrowed record + filePath so the
|
|
202
|
+
* caller reads the remaining fields without re-narrowing. */
|
|
203
|
+
function validateFilePathBody(body) {
|
|
180
204
|
if (!isRecord(body)) return {
|
|
181
205
|
ok: false,
|
|
182
206
|
error: "body must be an object"
|
|
@@ -185,11 +209,28 @@ function validateUpdateScriptBody(body) {
|
|
|
185
209
|
ok: false,
|
|
186
210
|
error: "filePath must be a non-empty string"
|
|
187
211
|
};
|
|
188
|
-
|
|
212
|
+
return {
|
|
213
|
+
ok: true,
|
|
214
|
+
value: {
|
|
215
|
+
record: body,
|
|
216
|
+
filePath: body.filePath
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Validate the `update-script` request body. Returns the parsed,
|
|
222
|
+
* schema-conformant script on success, or a human-readable error
|
|
223
|
+
* suitable for sending back as a 400 response.
|
|
224
|
+
*/
|
|
225
|
+
function validateUpdateScriptBody(body) {
|
|
226
|
+
const base = validateFilePathBody(body);
|
|
227
|
+
if (!base.ok) return base;
|
|
228
|
+
const { record, filePath } = base.value;
|
|
229
|
+
if (record.script === void 0) return {
|
|
189
230
|
ok: false,
|
|
190
231
|
error: "script is required"
|
|
191
232
|
};
|
|
192
|
-
const parsed = mulmoScriptSchema.safeParse(
|
|
233
|
+
const parsed = mulmoScriptSchema.safeParse(record.script);
|
|
193
234
|
if (!parsed.success) return {
|
|
194
235
|
ok: false,
|
|
195
236
|
error: `invalid script: ${formatZodIssues(parsed.error.issues)}`
|
|
@@ -197,7 +238,7 @@ function validateUpdateScriptBody(body) {
|
|
|
197
238
|
return {
|
|
198
239
|
ok: true,
|
|
199
240
|
value: {
|
|
200
|
-
filePath
|
|
241
|
+
filePath,
|
|
201
242
|
script: parsed.data
|
|
202
243
|
}
|
|
203
244
|
};
|
|
@@ -208,23 +249,19 @@ function validateUpdateScriptBody(body) {
|
|
|
208
249
|
* against the actual script length after reading the file.
|
|
209
250
|
*/
|
|
210
251
|
function validateUpdateBeatBody(body) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (typeof
|
|
216
|
-
ok: false,
|
|
217
|
-
error: "filePath must be a non-empty string"
|
|
218
|
-
};
|
|
219
|
-
if (typeof body.beatIndex !== "number" || !Number.isInteger(body.beatIndex) || body.beatIndex < 0) return {
|
|
252
|
+
const base = validateFilePathBody(body);
|
|
253
|
+
if (!base.ok) return base;
|
|
254
|
+
const { record, filePath } = base.value;
|
|
255
|
+
const beatIndex = record.beatIndex;
|
|
256
|
+
if (typeof beatIndex !== "number" || !Number.isInteger(beatIndex) || beatIndex < 0) return {
|
|
220
257
|
ok: false,
|
|
221
258
|
error: "beatIndex must be a non-negative integer"
|
|
222
259
|
};
|
|
223
|
-
if (
|
|
260
|
+
if (record.beat === void 0) return {
|
|
224
261
|
ok: false,
|
|
225
262
|
error: "beat is required"
|
|
226
263
|
};
|
|
227
|
-
const parsed = mulmoBeatSchema.safeParse(
|
|
264
|
+
const parsed = mulmoBeatSchema.safeParse(record.beat);
|
|
228
265
|
if (!parsed.success) return {
|
|
229
266
|
ok: false,
|
|
230
267
|
error: `invalid beat: ${formatZodIssues(parsed.error.issues)}`
|
|
@@ -232,8 +269,8 @@ function validateUpdateBeatBody(body) {
|
|
|
232
269
|
return {
|
|
233
270
|
ok: true,
|
|
234
271
|
value: {
|
|
235
|
-
filePath
|
|
236
|
-
beatIndex
|
|
272
|
+
filePath,
|
|
273
|
+
beatIndex,
|
|
237
274
|
beat: parsed.data
|
|
238
275
|
}
|
|
239
276
|
};
|
|
@@ -254,9 +291,6 @@ function notFound(error) {
|
|
|
254
291
|
error
|
|
255
292
|
};
|
|
256
293
|
}
|
|
257
|
-
function errorText(err) {
|
|
258
|
-
return err instanceof Error ? err.message : String(err);
|
|
259
|
-
}
|
|
260
294
|
function stringifyScript(script) {
|
|
261
295
|
return JSON.stringify(script, null, 2);
|
|
262
296
|
}
|
|
@@ -287,7 +321,7 @@ async function loadExistingScript(context, filePath) {
|
|
|
287
321
|
try {
|
|
288
322
|
parsed = JSON.parse(raw);
|
|
289
323
|
} catch (err) {
|
|
290
|
-
return badRequest(`Invalid JSON: ${
|
|
324
|
+
return badRequest(`Invalid JSON: ${errorMessage(err)}`);
|
|
291
325
|
}
|
|
292
326
|
const validation = mulmoScriptSchema.safeParse(parsed);
|
|
293
327
|
if (!validation.success) return badRequest("File is not a valid MulmoScript");
|
|
@@ -333,7 +367,7 @@ async function executeUpdateBeat(context, body) {
|
|
|
333
367
|
try {
|
|
334
368
|
script = JSON.parse(await context.files.artifacts.read(resolved.storyPath));
|
|
335
369
|
} catch (err) {
|
|
336
|
-
return badRequest(`Invalid JSON: ${
|
|
370
|
+
return badRequest(`Invalid JSON: ${errorMessage(err)}`);
|
|
337
371
|
}
|
|
338
372
|
if (!Array.isArray(script.beats) || beatIndex >= script.beats.length) return badRequest("Invalid beatIndex");
|
|
339
373
|
script.beats[beatIndex] = beat;
|
|
@@ -382,6 +416,6 @@ var pluginCore = {
|
|
|
382
416
|
isEnabled: () => true
|
|
383
417
|
};
|
|
384
418
|
//#endregion
|
|
385
|
-
export { pluginCore as a, normalizeStoryPath as c,
|
|
419
|
+
export { pluginCore as a, normalizeStoryPath as c, errorMessage as d, TOOL_DEFINITION as f, executeUpdateScript as i, slugify as l, executeMulmoScriptSave as n, validateUpdateBeatBody as o, TOOL_NAME as p, executeUpdateBeat as r, validateUpdateScriptBody as s, executeMulmoScript as t, storyFilePath as u };
|
|
386
420
|
|
|
387
|
-
//# sourceMappingURL=plugin-
|
|
421
|
+
//# sourceMappingURL=plugin-CXhOP_xU.js.map
|