@mindstudio-ai/agent 0.1.7 → 0.1.10
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/README.md +43 -2
- package/dist/cli.js +1518 -28
- package/dist/index.d.ts +944 -78
- package/dist/index.js +1506 -24
- package/dist/index.js.map +1 -1
- package/dist/postinstall.js +1518 -28
- package/llms.txt +53 -23
- package/package.json +1 -1
package/dist/postinstall.js
CHANGED
|
@@ -37,7 +37,7 @@ var init_metadata = __esm({
|
|
|
37
37
|
stepType: "addSubtitlesToVideo",
|
|
38
38
|
description: "Automatically add subtitles to a video",
|
|
39
39
|
usageNotes: "- Can control style of text and animation",
|
|
40
|
-
inputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the source video" }, "language": { "type": "string", "description": "ISO language code for subtitle transcription" }, "fontName": { "type": "string", "description": "Google Font name for subtitle text" }, "fontSize": { "type": "number", "description": "Font size in pixels. Default: 100." }, "fontWeight": { "enum": ["normal", "bold", "black"], "type": "string", "description": "Font weight for subtitle text" }, "fontColor": { "enum": ["white", "black", "red", "green", "blue", "yellow", "orange", "purple", "pink", "brown", "gray", "cyan", "magenta"], "type": "string", "description": "Color of the subtitle text" }, "highlightColor": { "enum": ["white", "black", "red", "green", "blue", "yellow", "orange", "purple", "pink", "brown", "gray", "cyan", "magenta"], "type": "string", "description": "Color used to highlight the currently spoken word" }, "strokeWidth": { "type": "number", "description": "Width of the text stroke outline in pixels" }, "strokeColor": { "enum": ["black", "white", "red", "green", "blue", "yellow", "orange", "purple", "pink", "brown", "gray", "cyan", "magenta"], "type": "string", "description": "Color of the text stroke outline" }, "backgroundColor": { "enum": ["black", "white", "red", "green", "blue", "yellow", "orange", "purple", "pink", "brown", "gray", "cyan", "magenta", "none"], "type": "string", "description": "Background color behind subtitle text. Use 'none' for transparent." }, "backgroundOpacity": { "type": "number", "description": "Opacity of the subtitle background. 0.0 = fully transparent, 1.0 = fully opaque." }, "position": { "enum": ["top", "center", "bottom"], "type": "string", "description": "Vertical position of subtitle text on screen" }, "yOffset": { "type": "number", "description": "Vertical offset in pixels from the position. Positive moves down, negative moves up. Default: 75." }, "wordsPerSubtitle": { "type": "number", "description": "Maximum number of words per subtitle segment. Use 1 for single-word display, 2-3 for short phrases, or 8-12 for full sentences. Default: 3." }, "enableAnimation": { "type": "boolean", "description": "When true, enables bounce-style entrance animation for subtitles. Default: true." }, "
|
|
40
|
+
inputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the source video" }, "language": { "type": "string", "description": "ISO language code for subtitle transcription" }, "fontName": { "type": "string", "description": "Google Font name for subtitle text" }, "fontSize": { "type": "number", "description": "Font size in pixels. Default: 100." }, "fontWeight": { "enum": ["normal", "bold", "black"], "type": "string", "description": "Font weight for subtitle text" }, "fontColor": { "enum": ["white", "black", "red", "green", "blue", "yellow", "orange", "purple", "pink", "brown", "gray", "cyan", "magenta"], "type": "string", "description": "Color of the subtitle text" }, "highlightColor": { "enum": ["white", "black", "red", "green", "blue", "yellow", "orange", "purple", "pink", "brown", "gray", "cyan", "magenta"], "type": "string", "description": "Color used to highlight the currently spoken word" }, "strokeWidth": { "type": "number", "description": "Width of the text stroke outline in pixels" }, "strokeColor": { "enum": ["black", "white", "red", "green", "blue", "yellow", "orange", "purple", "pink", "brown", "gray", "cyan", "magenta"], "type": "string", "description": "Color of the text stroke outline" }, "backgroundColor": { "enum": ["black", "white", "red", "green", "blue", "yellow", "orange", "purple", "pink", "brown", "gray", "cyan", "magenta", "none"], "type": "string", "description": "Background color behind subtitle text. Use 'none' for transparent." }, "backgroundOpacity": { "type": "number", "description": "Opacity of the subtitle background. 0.0 = fully transparent, 1.0 = fully opaque." }, "position": { "enum": ["top", "center", "bottom"], "type": "string", "description": "Vertical position of subtitle text on screen" }, "yOffset": { "type": "number", "description": "Vertical offset in pixels from the position. Positive moves down, negative moves up. Default: 75." }, "wordsPerSubtitle": { "type": "number", "description": "Maximum number of words per subtitle segment. Use 1 for single-word display, 2-3 for short phrases, or 8-12 for full sentences. Default: 3." }, "enableAnimation": { "type": "boolean", "description": "When true, enables bounce-style entrance animation for subtitles. Default: true." }, "intermediateAsset": { "type": "boolean", "description": "When true, the asset is created but hidden from the user's gallery (tagged as intermediate)" } }, "required": ["videoUrl", "language", "fontName", "fontSize", "fontWeight", "fontColor", "highlightColor", "strokeWidth", "strokeColor", "backgroundColor", "backgroundOpacity", "position", "yOffset", "wordsPerSubtitle", "enableAnimation"] },
|
|
41
41
|
outputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the video with subtitles added" } }, "required": ["videoUrl"] }
|
|
42
42
|
},
|
|
43
43
|
"airtableCreateUpdateRecord": {
|
|
@@ -89,6 +89,13 @@ var init_metadata = __esm({
|
|
|
89
89
|
inputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the source video to capture a frame from" }, "at": { "anyOf": [{ "type": "number" }, { "type": "string" }] } }, "required": ["videoUrl", "at"] },
|
|
90
90
|
outputSchema: { "type": "object", "properties": { "thumbnailUrl": { "type": "string", "description": "URL of the captured thumbnail image" } }, "required": ["thumbnailUrl"] }
|
|
91
91
|
},
|
|
92
|
+
"checkAppRole": {
|
|
93
|
+
stepType: "checkAppRole",
|
|
94
|
+
description: "Check whether the current user has a specific app role and branch accordingly.",
|
|
95
|
+
usageNotes: '- Checks if the current user has been assigned a specific role in this app.\n- If the user has the role, transitions to the "has role" path.\n- If the user does not have the role, transitions to the "no role" path, or errors if no path is configured.\n- Role names are defined by the app creator and assigned to users via the app roles system.\n- The roleName field supports {{variables}} for dynamic role checks.',
|
|
96
|
+
inputSchema: { "type": "object", "properties": { "roleName": { "type": "string", "description": "The role name to check (supports {{variables}})" }, "hasRoleStepId": { "type": "string", "description": "Step to transition to if the user has the role (same workflow)" }, "hasRoleWorkflowId": { "type": "string", "description": "Workflow to jump to if the user has the role (cross workflow)" }, "noRoleStepId": { "type": "string", "description": "Step to transition to if the user does not have the role (same workflow)" }, "noRoleWorkflowId": { "type": "string", "description": "Workflow to jump to if the user does not have the role (cross workflow)" } }, "required": ["roleName"], "description": "Configuration for the check app role step" },
|
|
97
|
+
outputSchema: { "type": "object", "properties": { "hasRole": { "type": "boolean", "description": "Whether the current user has the checked role" }, "userRoles": { "type": "array", "items": { "type": "string" }, "description": "All roles assigned to the current user for this app" } }, "required": ["hasRole", "userRoles"] }
|
|
98
|
+
},
|
|
92
99
|
"codaCreateUpdatePage": {
|
|
93
100
|
stepType: "codaCreateUpdatePage",
|
|
94
101
|
description: "Create a new page or update an existing page in a Coda document.",
|
|
@@ -340,7 +347,7 @@ var init_metadata = __esm({
|
|
|
340
347
|
stepType: "generatePdf",
|
|
341
348
|
description: "Generate an HTML asset and export it as a webpage, PDF, or image",
|
|
342
349
|
usageNotes: '- Agents can generate HTML documents and export as webpage, PDFs, images, or videos. They do this by using the "generatePdf" block, which defines an HTML page with variables, and then the generation process renders the page to create the output and save its URL at the specified variable.\n- The template for the HTML page is generated by a separate process, and it can only use variables that have already been defined in the workflow at the time of its execution. It has full access to handlebars to render the HTML template, including a handlebars helper to render a markdown variable string as HTML (which can be useful for creating templates that render long strings). The template can also create its own simple JavaScript to do things like format dates and strings.\n- If PDF or composited image generation are part of the workflow, assistant adds the block and leaves the "source" empty. In a separate step, assistant generates a detailed request for the developer who will write the HTML.\n- Can also auto-generate HTML from a prompt (like a generate text block to generate HTML). In these cases, create a prompt with variables in the dynamicPrompt variable describing, in detail, the document to generate\n- Can either display output directly to user (foreground mode) or save the URL of the asset to a variable (background mode)',
|
|
343
|
-
inputSchema: { "type": "object", "properties": { "source": { "type": "string", "description": "The HTML or Markdown source template for the asset" }, "sourceType": { "enum": ["html", "markdown", "spa", "raw", "dynamic", "customInterface"], "type": "string", "description": "Source type: html, markdown (auto-formatted), spa (single page app), raw (pre-generated HTML in a variable), dynamic (AI-generated from prompt), or customInterface" }, "outputFormat": { "enum": ["pdf", "png", "html", "mp4", "openGraph"], "type": "string", "description": "The output format for the generated asset" }, "pageSize": { "enum": ["full", "letter", "A4", "custom"], "type": "string", "description": "Page size for PDF, PNG, or MP4 output" }, "testData": { "type": "object", "description": "Test data used for previewing the template with sample variable values" }, "options": { "type": "object", "properties": { "pageWidthPx": { "type": "number", "description": "Custom page width in pixels (for custom pageSize)" }, "pageHeightPx": { "type": "number", "description": "Custom page height in pixels (for custom pageSize)" }, "pageOrientation": { "enum": ["portrait", "landscape"], "type": "string", "description": "Page orientation for the rendered output" }, "rehostMedia": { "type": "boolean", "description": "Whether to re-host third-party images on the MindStudio CDN" }, "videoDurationSeconds": { "type": "number", "description": "Duration in seconds for MP4 video output" } }, "description": "Additional rendering options" }, "spaSource": { "type": "object", "properties": { "source": { "type": "string", "description": "Source code of the SPA (legacy, use files instead)" }, "lastCompiledSource": { "type": "string", "description": "Last compiled source (cached)" }, "files": { "type": "object", "description": "Multi-file SPA source" }, "paths": { "type": "array", "items": { "type": "string" }, "description": "Available route paths in the SPA" }, "root": { "type": "string", "description": "Root URL of the SPA bundle" }, "zipUrl": { "type": "string", "description": "URL of the zipped SPA bundle" } }, "required": ["paths", "root", "zipUrl"], "description": "Single page app source configuration (advanced)" }, "rawSource": { "type": "string", "description": "Raw HTML source stored in a variable, using handlebars syntax (e.g. {{myHtmlVariable}})" }, "dynamicPrompt": { "type": "string", "description": 'Prompt to generate the HTML dynamically when sourceType is "dynamic"' }, "dynamicSourceModelOverride": { "type": "object", "properties": { "model": { "type": "string", "description": 'Model identifier (e.g. "gpt-4", "claude-3-opus")' }, "temperature": { "type": "number", "description": "Sampling temperature for the model (0-2)" }, "maxResponseTokens": { "type": "number", "description": "Maximum number of tokens in the model's response" }, "ignorePreamble": { "type": "boolean", "description": "Whether to skip the system preamble/instructions" }, "userMessagePreprocessor": { "type": "object", "properties": { "dataSource": { "type": "string", "description": "Data source identifier for the preprocessor" }, "messageTemplate": { "type": "string", "description": "Template string applied to user messages before sending to the model" }, "maxResults": { "type": "number", "description": "Maximum number of results to include from the data source" }, "enabled": { "type": "boolean", "description": "Whether the preprocessor is active" }, "shouldInherit": { "type": "boolean", "description": "Whether child steps should inherit this preprocessor configuration" } }, "description": "Preprocessor applied to user messages before sending to the model" }, "preamble": { "type": "string", "description": "System preamble/instructions for the model" }, "multiModelEnabled": { "type": "boolean", "description": "Whether multi-model candidate generation is enabled" }, "editResponseEnabled": { "type": "boolean", "description": "Whether the user can edit the model's response" }, "config": { "type": "object", "description": "Additional model-specific configuration" } }, "required": ["model", "temperature", "maxResponseTokens"], "description": "Model override for dynamic HTML generation. Leave undefined to use the default model" }, "transitionControl": { "enum": ["default", "native"], "type": "string", "description": "Controls how the step transitions after displaying in foreground mode" }, "shareControl": { "enum": ["default", "hidden"], "type": "string", "description": "Controls visibility of the share button on displayed assets" }, "shareImageUrl": { "type": "string", "description": "URL of a custom Open Graph share image" }, "
|
|
350
|
+
inputSchema: { "type": "object", "properties": { "source": { "type": "string", "description": "The HTML or Markdown source template for the asset" }, "sourceType": { "enum": ["html", "markdown", "spa", "raw", "dynamic", "customInterface"], "type": "string", "description": "Source type: html, markdown (auto-formatted), spa (single page app), raw (pre-generated HTML in a variable), dynamic (AI-generated from prompt), or customInterface" }, "outputFormat": { "enum": ["pdf", "png", "html", "mp4", "openGraph"], "type": "string", "description": "The output format for the generated asset" }, "pageSize": { "enum": ["full", "letter", "A4", "custom"], "type": "string", "description": "Page size for PDF, PNG, or MP4 output" }, "testData": { "type": "object", "description": "Test data used for previewing the template with sample variable values" }, "options": { "type": "object", "properties": { "pageWidthPx": { "type": "number", "description": "Custom page width in pixels (for custom pageSize)" }, "pageHeightPx": { "type": "number", "description": "Custom page height in pixels (for custom pageSize)" }, "pageOrientation": { "enum": ["portrait", "landscape"], "type": "string", "description": "Page orientation for the rendered output" }, "rehostMedia": { "type": "boolean", "description": "Whether to re-host third-party images on the MindStudio CDN" }, "videoDurationSeconds": { "type": "number", "description": "Duration in seconds for MP4 video output" } }, "description": "Additional rendering options" }, "spaSource": { "type": "object", "properties": { "source": { "type": "string", "description": "Source code of the SPA (legacy, use files instead)" }, "lastCompiledSource": { "type": "string", "description": "Last compiled source (cached)" }, "files": { "type": "object", "description": "Multi-file SPA source" }, "paths": { "type": "array", "items": { "type": "string" }, "description": "Available route paths in the SPA" }, "root": { "type": "string", "description": "Root URL of the SPA bundle" }, "zipUrl": { "type": "string", "description": "URL of the zipped SPA bundle" } }, "required": ["paths", "root", "zipUrl"], "description": "Single page app source configuration (advanced)" }, "rawSource": { "type": "string", "description": "Raw HTML source stored in a variable, using handlebars syntax (e.g. {{myHtmlVariable}})" }, "dynamicPrompt": { "type": "string", "description": 'Prompt to generate the HTML dynamically when sourceType is "dynamic"' }, "dynamicSourceModelOverride": { "type": "object", "properties": { "model": { "type": "string", "description": 'Model identifier (e.g. "gpt-4", "claude-3-opus")' }, "temperature": { "type": "number", "description": "Sampling temperature for the model (0-2)" }, "maxResponseTokens": { "type": "number", "description": "Maximum number of tokens in the model's response" }, "ignorePreamble": { "type": "boolean", "description": "Whether to skip the system preamble/instructions" }, "userMessagePreprocessor": { "type": "object", "properties": { "dataSource": { "type": "string", "description": "Data source identifier for the preprocessor" }, "messageTemplate": { "type": "string", "description": "Template string applied to user messages before sending to the model" }, "maxResults": { "type": "number", "description": "Maximum number of results to include from the data source" }, "enabled": { "type": "boolean", "description": "Whether the preprocessor is active" }, "shouldInherit": { "type": "boolean", "description": "Whether child steps should inherit this preprocessor configuration" } }, "description": "Preprocessor applied to user messages before sending to the model" }, "preamble": { "type": "string", "description": "System preamble/instructions for the model" }, "multiModelEnabled": { "type": "boolean", "description": "Whether multi-model candidate generation is enabled" }, "editResponseEnabled": { "type": "boolean", "description": "Whether the user can edit the model's response" }, "config": { "type": "object", "description": "Additional model-specific configuration" } }, "required": ["model", "temperature", "maxResponseTokens"], "description": "Model override for dynamic HTML generation. Leave undefined to use the default model" }, "transitionControl": { "enum": ["default", "native"], "type": "string", "description": "Controls how the step transitions after displaying in foreground mode" }, "shareControl": { "enum": ["default", "hidden"], "type": "string", "description": "Controls visibility of the share button on displayed assets" }, "shareImageUrl": { "type": "string", "description": "URL of a custom Open Graph share image" }, "intermediateAsset": { "type": "boolean", "description": "When true, the asset is created but hidden from the user's gallery (tagged as intermediate)" } }, "required": ["source", "sourceType", "outputFormat", "pageSize", "testData"] },
|
|
344
351
|
outputSchema: { "type": "object", "properties": { "url": { "type": "string", "description": "CDN URL of the generated asset (PDF, PNG, HTML, or MP4 depending on outputFormat)" } }, "required": ["url"] }
|
|
345
352
|
},
|
|
346
353
|
"generateChart": {
|
|
@@ -354,28 +361,28 @@ var init_metadata = __esm({
|
|
|
354
361
|
stepType: "generateImage",
|
|
355
362
|
description: "Generate an image from a text prompt using an AI model.",
|
|
356
363
|
usageNotes: "- Prompts should be descriptive but concise (roughly 3\u20136 sentences).\n- Images are automatically hosted on a CDN.\n- In foreground mode, the image is displayed to the user. In background mode, the URL is saved to a variable.\n- When generateVariants is true with numVariants > 1, multiple images are generated in parallel.\n- In direct execution, foreground mode behaves as background, and userSelect variant behavior behaves as saveAll.",
|
|
357
|
-
inputSchema: { "type": "object", "properties": { "prompt": { "type": "string", "description": "Text prompt describing the image to generate" }, "
|
|
364
|
+
inputSchema: { "type": "object", "properties": { "prompt": { "type": "string", "description": "Text prompt describing the image to generate" }, "intermediateAsset": { "type": "boolean", "description": "When true, the asset is created but hidden from the user's gallery (tagged as intermediate)" }, "imageModelOverride": { "type": "object", "properties": { "model": { "type": "string", "description": "Image generation model identifier" }, "config": { "type": "object", "description": "Additional model-specific configuration" } }, "required": ["model"], "description": "Optional model configuration override. Uses the workflow's default image model if not specified" }, "generateVariants": { "type": "boolean", "description": "Whether to generate multiple image variants in parallel" }, "numVariants": { "type": "number", "description": "Number of variants to generate (max 10)" }, "addWatermark": { "type": "boolean", "description": "Whether to add a MindStudio watermark to the generated image" } }, "required": ["prompt"] },
|
|
358
365
|
outputSchema: { "type": "object", "properties": { "imageUrl": { "anyOf": [{ "type": "string" }, { "type": "array", "items": { "type": "string" } }] } }, "required": ["imageUrl"] }
|
|
359
366
|
},
|
|
360
367
|
"generateLipsync": {
|
|
361
368
|
stepType: "generateLipsync",
|
|
362
369
|
description: "Generate a lip sync video from provided audio and image.",
|
|
363
370
|
usageNotes: "- In foreground mode, the video is displayed to the user. In background mode, the URL is saved to a variable.",
|
|
364
|
-
inputSchema: { "type": "object", "properties": { "
|
|
371
|
+
inputSchema: { "type": "object", "properties": { "intermediateAsset": { "type": "boolean", "description": "When true, the asset is created but hidden from the user's gallery (tagged as intermediate)" }, "addWatermark": { "type": "boolean", "description": "Whether to add a MindStudio watermark to the generated video" }, "lipsyncModelOverride": { "type": "object", "properties": { "model": { "type": "string" }, "config": { "type": "object" } }, "required": ["model"], "description": "Optional model configuration override. Uses the workflow's default lipsync model if not specified" } } },
|
|
365
372
|
outputSchema: { "description": "This step does not produce output data." }
|
|
366
373
|
},
|
|
367
374
|
"generateMusic": {
|
|
368
375
|
stepType: "generateMusic",
|
|
369
376
|
description: "Generate an audio file from provided instructions (text) using a music model.",
|
|
370
377
|
usageNotes: "- The text field contains the instructions (prompt) for the music generation.\n- In foreground mode, the audio is displayed to the user. In background mode, the URL is saved to a variable.",
|
|
371
|
-
inputSchema: { "type": "object", "properties": { "text": { "type": "string", "description": "The instructions (prompt) for the music generation" }, "
|
|
378
|
+
inputSchema: { "type": "object", "properties": { "text": { "type": "string", "description": "The instructions (prompt) for the music generation" }, "intermediateAsset": { "type": "boolean", "description": "When true, the asset is created but hidden from the user's gallery (tagged as intermediate)" }, "musicModelOverride": { "type": "object", "properties": { "model": { "type": "string" }, "config": { "type": "object" } }, "required": ["model"], "description": "Optional model configuration override. Uses the workflow's default music model if not specified" } }, "required": ["text"] },
|
|
372
379
|
outputSchema: { "description": "This step does not produce output data." }
|
|
373
380
|
},
|
|
374
381
|
"generatePdf": {
|
|
375
382
|
stepType: "generatePdf",
|
|
376
383
|
description: "Generate an HTML asset and export it as a webpage, PDF, or image",
|
|
377
384
|
usageNotes: '- Agents can generate HTML documents and export as webpage, PDFs, images, or videos. They do this by using the "generatePdf" block, which defines an HTML page with variables, and then the generation process renders the page to create the output and save its URL at the specified variable.\n- The template for the HTML page is generated by a separate process, and it can only use variables that have already been defined in the workflow at the time of its execution. It has full access to handlebars to render the HTML template, including a handlebars helper to render a markdown variable string as HTML (which can be useful for creating templates that render long strings). The template can also create its own simple JavaScript to do things like format dates and strings.\n- If PDF or composited image generation are part of the workflow, assistant adds the block and leaves the "source" empty. In a separate step, assistant generates a detailed request for the developer who will write the HTML.\n- Can also auto-generate HTML from a prompt (like a generate text block to generate HTML). In these cases, create a prompt with variables in the dynamicPrompt variable describing, in detail, the document to generate\n- Can either display output directly to user (foreground mode) or save the URL of the asset to a variable (background mode)',
|
|
378
|
-
inputSchema: { "type": "object", "properties": { "source": { "type": "string", "description": "The HTML or Markdown source template for the asset" }, "sourceType": { "enum": ["html", "markdown", "spa", "raw", "dynamic", "customInterface"], "type": "string", "description": "Source type: html, markdown (auto-formatted), spa (single page app), raw (pre-generated HTML in a variable), dynamic (AI-generated from prompt), or customInterface" }, "outputFormat": { "enum": ["pdf", "png", "html", "mp4", "openGraph"], "type": "string", "description": "The output format for the generated asset" }, "pageSize": { "enum": ["full", "letter", "A4", "custom"], "type": "string", "description": "Page size for PDF, PNG, or MP4 output" }, "testData": { "type": "object", "description": "Test data used for previewing the template with sample variable values" }, "options": { "type": "object", "properties": { "pageWidthPx": { "type": "number", "description": "Custom page width in pixels (for custom pageSize)" }, "pageHeightPx": { "type": "number", "description": "Custom page height in pixels (for custom pageSize)" }, "pageOrientation": { "enum": ["portrait", "landscape"], "type": "string", "description": "Page orientation for the rendered output" }, "rehostMedia": { "type": "boolean", "description": "Whether to re-host third-party images on the MindStudio CDN" }, "videoDurationSeconds": { "type": "number", "description": "Duration in seconds for MP4 video output" } }, "description": "Additional rendering options" }, "spaSource": { "type": "object", "properties": { "source": { "type": "string", "description": "Source code of the SPA (legacy, use files instead)" }, "lastCompiledSource": { "type": "string", "description": "Last compiled source (cached)" }, "files": { "type": "object", "description": "Multi-file SPA source" }, "paths": { "type": "array", "items": { "type": "string" }, "description": "Available route paths in the SPA" }, "root": { "type": "string", "description": "Root URL of the SPA bundle" }, "zipUrl": { "type": "string", "description": "URL of the zipped SPA bundle" } }, "required": ["paths", "root", "zipUrl"], "description": "Single page app source configuration (advanced)" }, "rawSource": { "type": "string", "description": "Raw HTML source stored in a variable, using handlebars syntax (e.g. {{myHtmlVariable}})" }, "dynamicPrompt": { "type": "string", "description": 'Prompt to generate the HTML dynamically when sourceType is "dynamic"' }, "dynamicSourceModelOverride": { "type": "object", "properties": { "model": { "type": "string", "description": 'Model identifier (e.g. "gpt-4", "claude-3-opus")' }, "temperature": { "type": "number", "description": "Sampling temperature for the model (0-2)" }, "maxResponseTokens": { "type": "number", "description": "Maximum number of tokens in the model's response" }, "ignorePreamble": { "type": "boolean", "description": "Whether to skip the system preamble/instructions" }, "userMessagePreprocessor": { "type": "object", "properties": { "dataSource": { "type": "string", "description": "Data source identifier for the preprocessor" }, "messageTemplate": { "type": "string", "description": "Template string applied to user messages before sending to the model" }, "maxResults": { "type": "number", "description": "Maximum number of results to include from the data source" }, "enabled": { "type": "boolean", "description": "Whether the preprocessor is active" }, "shouldInherit": { "type": "boolean", "description": "Whether child steps should inherit this preprocessor configuration" } }, "description": "Preprocessor applied to user messages before sending to the model" }, "preamble": { "type": "string", "description": "System preamble/instructions for the model" }, "multiModelEnabled": { "type": "boolean", "description": "Whether multi-model candidate generation is enabled" }, "editResponseEnabled": { "type": "boolean", "description": "Whether the user can edit the model's response" }, "config": { "type": "object", "description": "Additional model-specific configuration" } }, "required": ["model", "temperature", "maxResponseTokens"], "description": "Model override for dynamic HTML generation. Leave undefined to use the default model" }, "transitionControl": { "enum": ["default", "native"], "type": "string", "description": "Controls how the step transitions after displaying in foreground mode" }, "shareControl": { "enum": ["default", "hidden"], "type": "string", "description": "Controls visibility of the share button on displayed assets" }, "shareImageUrl": { "type": "string", "description": "URL of a custom Open Graph share image" }, "
|
|
385
|
+
inputSchema: { "type": "object", "properties": { "source": { "type": "string", "description": "The HTML or Markdown source template for the asset" }, "sourceType": { "enum": ["html", "markdown", "spa", "raw", "dynamic", "customInterface"], "type": "string", "description": "Source type: html, markdown (auto-formatted), spa (single page app), raw (pre-generated HTML in a variable), dynamic (AI-generated from prompt), or customInterface" }, "outputFormat": { "enum": ["pdf", "png", "html", "mp4", "openGraph"], "type": "string", "description": "The output format for the generated asset" }, "pageSize": { "enum": ["full", "letter", "A4", "custom"], "type": "string", "description": "Page size for PDF, PNG, or MP4 output" }, "testData": { "type": "object", "description": "Test data used for previewing the template with sample variable values" }, "options": { "type": "object", "properties": { "pageWidthPx": { "type": "number", "description": "Custom page width in pixels (for custom pageSize)" }, "pageHeightPx": { "type": "number", "description": "Custom page height in pixels (for custom pageSize)" }, "pageOrientation": { "enum": ["portrait", "landscape"], "type": "string", "description": "Page orientation for the rendered output" }, "rehostMedia": { "type": "boolean", "description": "Whether to re-host third-party images on the MindStudio CDN" }, "videoDurationSeconds": { "type": "number", "description": "Duration in seconds for MP4 video output" } }, "description": "Additional rendering options" }, "spaSource": { "type": "object", "properties": { "source": { "type": "string", "description": "Source code of the SPA (legacy, use files instead)" }, "lastCompiledSource": { "type": "string", "description": "Last compiled source (cached)" }, "files": { "type": "object", "description": "Multi-file SPA source" }, "paths": { "type": "array", "items": { "type": "string" }, "description": "Available route paths in the SPA" }, "root": { "type": "string", "description": "Root URL of the SPA bundle" }, "zipUrl": { "type": "string", "description": "URL of the zipped SPA bundle" } }, "required": ["paths", "root", "zipUrl"], "description": "Single page app source configuration (advanced)" }, "rawSource": { "type": "string", "description": "Raw HTML source stored in a variable, using handlebars syntax (e.g. {{myHtmlVariable}})" }, "dynamicPrompt": { "type": "string", "description": 'Prompt to generate the HTML dynamically when sourceType is "dynamic"' }, "dynamicSourceModelOverride": { "type": "object", "properties": { "model": { "type": "string", "description": 'Model identifier (e.g. "gpt-4", "claude-3-opus")' }, "temperature": { "type": "number", "description": "Sampling temperature for the model (0-2)" }, "maxResponseTokens": { "type": "number", "description": "Maximum number of tokens in the model's response" }, "ignorePreamble": { "type": "boolean", "description": "Whether to skip the system preamble/instructions" }, "userMessagePreprocessor": { "type": "object", "properties": { "dataSource": { "type": "string", "description": "Data source identifier for the preprocessor" }, "messageTemplate": { "type": "string", "description": "Template string applied to user messages before sending to the model" }, "maxResults": { "type": "number", "description": "Maximum number of results to include from the data source" }, "enabled": { "type": "boolean", "description": "Whether the preprocessor is active" }, "shouldInherit": { "type": "boolean", "description": "Whether child steps should inherit this preprocessor configuration" } }, "description": "Preprocessor applied to user messages before sending to the model" }, "preamble": { "type": "string", "description": "System preamble/instructions for the model" }, "multiModelEnabled": { "type": "boolean", "description": "Whether multi-model candidate generation is enabled" }, "editResponseEnabled": { "type": "boolean", "description": "Whether the user can edit the model's response" }, "config": { "type": "object", "description": "Additional model-specific configuration" } }, "required": ["model", "temperature", "maxResponseTokens"], "description": "Model override for dynamic HTML generation. Leave undefined to use the default model" }, "transitionControl": { "enum": ["default", "native"], "type": "string", "description": "Controls how the step transitions after displaying in foreground mode" }, "shareControl": { "enum": ["default", "hidden"], "type": "string", "description": "Controls visibility of the share button on displayed assets" }, "shareImageUrl": { "type": "string", "description": "URL of a custom Open Graph share image" }, "intermediateAsset": { "type": "boolean", "description": "When true, the asset is created but hidden from the user's gallery (tagged as intermediate)" } }, "required": ["source", "sourceType", "outputFormat", "pageSize", "testData"] },
|
|
379
386
|
outputSchema: { "type": "object", "properties": { "url": { "type": "string", "description": "CDN URL of the generated asset (PDF, PNG, HTML, or MP4 depending on outputFormat)" } }, "required": ["url"] }
|
|
380
387
|
},
|
|
381
388
|
"generateStaticVideoFromImage": {
|
|
@@ -399,7 +406,7 @@ var init_metadata = __esm({
|
|
|
399
406
|
stepType: "generateVideo",
|
|
400
407
|
description: "Generate a video from a text prompt using an AI model.",
|
|
401
408
|
usageNotes: "- Prompts should be descriptive but concise (roughly 3\u20136 sentences).\n- Videos are automatically hosted on a CDN.\n- In foreground mode, the video is displayed to the user. In background mode, the URL is saved to a variable.\n- When generateVariants is true with numVariants > 1, multiple videos are generated in parallel.\n- In direct execution, foreground mode behaves as background, and userSelect variant behavior behaves as saveAll.",
|
|
402
|
-
inputSchema: { "type": "object", "properties": { "prompt": { "type": "string", "description": "Text prompt describing the video to generate" }, "
|
|
409
|
+
inputSchema: { "type": "object", "properties": { "prompt": { "type": "string", "description": "Text prompt describing the video to generate" }, "intermediateAsset": { "type": "boolean", "description": "When true, the asset is created but hidden from the user's gallery (tagged as intermediate)" }, "videoModelOverride": { "type": "object", "properties": { "model": { "type": "string", "description": "Video generation model identifier" }, "config": { "type": "object", "description": "Additional model-specific configuration" } }, "required": ["model"], "description": "Optional model configuration override. Uses the workflow's default video model if not specified" }, "generateVariants": { "type": "boolean", "description": "Whether to generate multiple video variants in parallel" }, "numVariants": { "type": "number", "description": "Number of variants to generate (max 10)" }, "addWatermark": { "type": "boolean", "description": "Whether to add a MindStudio watermark to the generated video" } }, "required": ["prompt"] },
|
|
403
410
|
outputSchema: { "type": "object", "properties": { "videoUrl": { "anyOf": [{ "type": "string" }, { "type": "array", "items": { "type": "string" } }] } }, "required": ["videoUrl"] }
|
|
404
411
|
},
|
|
405
412
|
"getGmailAttachments": {
|
|
@@ -539,14 +546,14 @@ var init_metadata = __esm({
|
|
|
539
546
|
stepType: "imageRemoveWatermark",
|
|
540
547
|
description: "Remove watermarks from an image using AI.",
|
|
541
548
|
usageNotes: "- Output is re-hosted on the CDN as a PNG.",
|
|
542
|
-
inputSchema: { "type": "object", "properties": { "imageUrl": { "type": "string", "description": "URL of the image to remove the watermark from" }, "engine": { "type": "string", "description": "Watermark removal engine to use" }, "
|
|
549
|
+
inputSchema: { "type": "object", "properties": { "imageUrl": { "type": "string", "description": "URL of the image to remove the watermark from" }, "engine": { "type": "string", "description": "Watermark removal engine to use" }, "intermediateAsset": { "type": "boolean", "description": "When true, the asset is created but hidden from the user's gallery (tagged as intermediate)" } }, "required": ["imageUrl", "engine"] },
|
|
543
550
|
outputSchema: { "type": "object", "properties": { "imageUrl": { "type": "string", "description": "CDN URL of the processed image with watermark removed (PNG)" } }, "required": ["imageUrl"] }
|
|
544
551
|
},
|
|
545
552
|
"insertVideoClips": {
|
|
546
553
|
stepType: "insertVideoClips",
|
|
547
554
|
description: "Insert b-roll clips into a base video at a timecode, optionally with an xfade transition.",
|
|
548
555
|
usageNotes: "",
|
|
549
|
-
inputSchema: { "type": "object", "properties": { "baseVideoUrl": { "type": "string", "description": "URL of the base video to insert clips into" }, "overlayVideos": { "type": "array", "items": { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the overlay video clip" }, "startTimeSec": { "type": "number", "description": "Timecode in seconds at which to insert this clip" } }, "required": ["videoUrl", "startTimeSec"] }, "description": "Array of overlay clips to insert at specified timecodes" }, "transition": { "type": "string", "description": "Optional xfade transition effect name between clips" }, "transitionDuration": { "type": "number", "description": "Duration of the transition in seconds" }, "useOverlayAudio": { "type": "boolean", "description": "When true, uses audio from the overlay clips instead of the base video audio during inserts" }, "
|
|
556
|
+
inputSchema: { "type": "object", "properties": { "baseVideoUrl": { "type": "string", "description": "URL of the base video to insert clips into" }, "overlayVideos": { "type": "array", "items": { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the overlay video clip" }, "startTimeSec": { "type": "number", "description": "Timecode in seconds at which to insert this clip" } }, "required": ["videoUrl", "startTimeSec"] }, "description": "Array of overlay clips to insert at specified timecodes" }, "transition": { "type": "string", "description": "Optional xfade transition effect name between clips" }, "transitionDuration": { "type": "number", "description": "Duration of the transition in seconds" }, "useOverlayAudio": { "type": "boolean", "description": "When true, uses audio from the overlay clips instead of the base video audio during inserts" }, "intermediateAsset": { "type": "boolean", "description": "When true, the asset is created but hidden from the user's gallery (tagged as intermediate)" } }, "required": ["baseVideoUrl", "overlayVideos"] },
|
|
550
557
|
outputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the video with clips inserted" } }, "required": ["videoUrl"] }
|
|
551
558
|
},
|
|
552
559
|
"listDataSources": {
|
|
@@ -613,28 +620,28 @@ var init_metadata = __esm({
|
|
|
613
620
|
stepType: "mergeAudio",
|
|
614
621
|
description: "Merge one or more clips into a single audio file.",
|
|
615
622
|
usageNotes: "",
|
|
616
|
-
inputSchema: { "type": "object", "properties": { "mp3Urls": { "type": "array", "items": { "type": "string" }, "description": "URLs of the MP3 audio clips to merge in order" }, "fileMetadata": { "type": "object", "description": "FFmpeg MP3 metadata key-value pairs to embed in the output file" }, "albumArtUrl": { "type": "string", "description": "URL of an image to embed as album art in the output file" }, "
|
|
623
|
+
inputSchema: { "type": "object", "properties": { "mp3Urls": { "type": "array", "items": { "type": "string" }, "description": "URLs of the MP3 audio clips to merge in order" }, "fileMetadata": { "type": "object", "description": "FFmpeg MP3 metadata key-value pairs to embed in the output file" }, "albumArtUrl": { "type": "string", "description": "URL of an image to embed as album art in the output file" }, "intermediateAsset": { "type": "boolean", "description": "When true, the asset is created but hidden from the user's gallery (tagged as intermediate)" } }, "required": ["mp3Urls"] },
|
|
617
624
|
outputSchema: { "type": "object", "properties": { "audioUrl": { "type": "string", "description": "URL of the merged audio file" } }, "required": ["audioUrl"] }
|
|
618
625
|
},
|
|
619
626
|
"mergeVideos": {
|
|
620
627
|
stepType: "mergeVideos",
|
|
621
628
|
description: "Merge one or more clips into a single video.",
|
|
622
629
|
usageNotes: "",
|
|
623
|
-
inputSchema: { "type": "object", "properties": { "videoUrls": { "type": "array", "items": { "type": "string" }, "description": "URLs of the video clips to merge in order" }, "transition": { "type": "string", "description": "Optional xfade transition effect name" }, "transitionDuration": { "type": "number", "description": "Duration of the transition in seconds" }, "
|
|
630
|
+
inputSchema: { "type": "object", "properties": { "videoUrls": { "type": "array", "items": { "type": "string" }, "description": "URLs of the video clips to merge in order" }, "transition": { "type": "string", "description": "Optional xfade transition effect name" }, "transitionDuration": { "type": "number", "description": "Duration of the transition in seconds" }, "intermediateAsset": { "type": "boolean", "description": "When true, the asset is created but hidden from the user's gallery (tagged as intermediate)" } }, "required": ["videoUrls"] },
|
|
624
631
|
outputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the merged video" } }, "required": ["videoUrl"] }
|
|
625
632
|
},
|
|
626
633
|
"mixAudioIntoVideo": {
|
|
627
634
|
stepType: "mixAudioIntoVideo",
|
|
628
635
|
description: "Mix an audio track into a video",
|
|
629
636
|
usageNotes: "",
|
|
630
|
-
inputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the source video" }, "audioUrl": { "type": "string", "description": "URL of the audio track to mix into the video" }, "options": { "type": "object", "properties": { "keepVideoAudio": { "type": "boolean", "description": "When true, preserves the original video audio alongside the new track. Defaults to false." }, "audioGainDb": { "type": "number", "description": "Volume adjustment for the new audio track in decibels. Defaults to 0." }, "videoGainDb": { "type": "number", "description": "Volume adjustment for the existing video audio in decibels. Defaults to 0." }, "loopAudio": { "type": "boolean", "description": "When true, loops the audio track to match the video duration. Defaults to false." } }, "description": "Audio mixing options" }, "
|
|
637
|
+
inputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the source video" }, "audioUrl": { "type": "string", "description": "URL of the audio track to mix into the video" }, "options": { "type": "object", "properties": { "keepVideoAudio": { "type": "boolean", "description": "When true, preserves the original video audio alongside the new track. Defaults to false." }, "audioGainDb": { "type": "number", "description": "Volume adjustment for the new audio track in decibels. Defaults to 0." }, "videoGainDb": { "type": "number", "description": "Volume adjustment for the existing video audio in decibels. Defaults to 0." }, "loopAudio": { "type": "boolean", "description": "When true, loops the audio track to match the video duration. Defaults to false." } }, "description": "Audio mixing options" }, "intermediateAsset": { "type": "boolean", "description": "When true, the asset is created but hidden from the user's gallery (tagged as intermediate)" } }, "required": ["videoUrl", "audioUrl", "options"] },
|
|
631
638
|
outputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the video with the mixed audio track" } }, "required": ["videoUrl"] }
|
|
632
639
|
},
|
|
633
640
|
"muteVideo": {
|
|
634
641
|
stepType: "muteVideo",
|
|
635
642
|
description: "Mute a video file",
|
|
636
643
|
usageNotes: "",
|
|
637
|
-
inputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the source video to mute" }, "
|
|
644
|
+
inputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the source video to mute" }, "intermediateAsset": { "type": "boolean", "description": "When true, the asset is created but hidden from the user's gallery (tagged as intermediate)" } }, "required": ["videoUrl"] },
|
|
638
645
|
outputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the muted video" } }, "required": ["videoUrl"] }
|
|
639
646
|
},
|
|
640
647
|
"n8nRunNode": {
|
|
@@ -668,8 +675,8 @@ var init_metadata = __esm({
|
|
|
668
675
|
"postToLinkedIn": {
|
|
669
676
|
stepType: "postToLinkedIn",
|
|
670
677
|
description: "Create a post on LinkedIn from the connected account.",
|
|
671
|
-
usageNotes: "- Requires a LinkedIn OAuth connection (connectionId).\n- Supports text posts, image posts, and
|
|
672
|
-
inputSchema: { "type": "object", "properties": { "message": { "type": "string", "description": "The text content of the LinkedIn post" }, "visibility": { "enum": ["PUBLIC", "CONNECTIONS"], "type": "string", "description": 'Who can see the post: "PUBLIC" or "CONNECTIONS"' }, "videoUrl": { "type": "string", "description": "URL of a video to attach to the post" }, "
|
|
678
|
+
usageNotes: "- Requires a LinkedIn OAuth connection (connectionId).\n- Supports text posts, image posts, video posts, document posts, and article posts.\n- Attach one media type per post: image, video, document, or article.\n- Documents support PDF, PPT, PPTX, DOC, DOCX (max 100MB, 300 pages). Displays as a slideshow carousel.\n- Articles create a link preview with optional custom title, description, and thumbnail.\n- Visibility controls who can see the post.",
|
|
679
|
+
inputSchema: { "type": "object", "properties": { "message": { "type": "string", "description": "The text content of the LinkedIn post" }, "visibility": { "enum": ["PUBLIC", "CONNECTIONS"], "type": "string", "description": 'Who can see the post: "PUBLIC" or "CONNECTIONS"' }, "imageUrl": { "type": "string", "description": "URL of an image to attach to the post" }, "videoUrl": { "type": "string", "description": "URL of a video to attach to the post" }, "documentUrl": { "type": "string", "description": "URL of a document (PDF, PPT, DOC) to attach to the post" }, "articleUrl": { "type": "string", "description": "URL to share as an article link preview" }, "titleText": { "type": "string", "description": "Title text for media or article attachments" }, "descriptionText": { "type": "string", "description": "Description text for article attachments" }, "connectionId": { "type": "string", "description": "LinkedIn OAuth connection ID" } }, "required": ["message", "visibility"] },
|
|
673
680
|
outputSchema: { "description": "This step does not produce output data." }
|
|
674
681
|
},
|
|
675
682
|
"postToSlackChannel": {
|
|
@@ -693,6 +700,13 @@ var init_metadata = __esm({
|
|
|
693
700
|
inputSchema: { "type": "object", "properties": { "webhookUrl": { "type": "string", "description": "Zapier webhook URL to send data to" }, "input": { "type": "object", "description": "Key-value pairs to send as the JSON POST body" } }, "required": ["webhookUrl", "input"] },
|
|
694
701
|
outputSchema: { "type": "object", "properties": { "data": { "description": "Parsed webhook response from Zapier (JSON object, array, or string)" } }, "required": ["data"] }
|
|
695
702
|
},
|
|
703
|
+
"queryAppDatabase": {
|
|
704
|
+
stepType: "queryAppDatabase",
|
|
705
|
+
description: "Execute a SQL query against the app managed database.",
|
|
706
|
+
usageNotes: '- Executes raw SQL against a SQLite database managed by the app.\n- For SELECT queries, returns rows as JSON.\n- For INSERT/UPDATE/DELETE, returns the number of affected rows.\n- Use {{variables}} directly in your SQL. By default they are automatically extracted\n and passed as safe parameterized values (preventing SQL injection).\n Example: INSERT INTO contacts (name, comment) VALUES ({{name}}, {{comment}})\n- Full MindStudio handlebars syntax is supported, including helpers like {{json myVar}},\n {{get myVar "$.path"}}, {{global.orgName}}, etc.\n- Set parameterize to false for raw/dynamic SQL where variables are interpolated directly\n into the query string. Use this when another step generates full or partial SQL, e.g.\n a bulk INSERT with a precomputed VALUES list. The user is responsible for sanitization\n when parameterize is false.',
|
|
707
|
+
inputSchema: { "type": "object", "properties": { "databaseId": { "type": "string", "description": "Name or ID of the app data database to query" }, "sql": { "type": "string", "description": "SQL query to execute. Use {{variables}} directly in the SQL \u2014 they are handled according to the `parameterize` setting.\n\nWhen parameterize is true (default): {{variables}} are extracted from the SQL, replaced with ? placeholders, resolved via the full MindStudio handlebars pipeline, and passed as safe parameterized values to SQLite. This prevents SQL injection. Example: INSERT INTO contacts (name, email) VALUES ({{name}}, {{email}})\n\nWhen parameterize is false: The entire SQL string is resolved via compileString (standard handlebars interpolation) and executed as-is. Use this for dynamic/generated SQL where another step builds the query. The user is responsible for safety. Example: {{generatedInsertQuery}}\n\nAsk the user for the database schema if they have not already provided it." }, "parameterize": { "type": "boolean", "description": "Whether to treat {{variables}} as parameterized query values (default: true).\n\n- true: {{vars}} are extracted, replaced with ?, and passed as bind params. Safe from SQL injection. Use for standard CRUD operations.\n- false: {{vars}} are interpolated directly into the SQL string via handlebars. Use when another step generates full or partial SQL (e.g. bulk inserts with precomputed VALUES). The user is responsible for sanitization." } }, "required": ["databaseId", "sql"] },
|
|
708
|
+
outputSchema: { "type": "object", "properties": { "rows": { "type": "array", "items": {}, "description": "Result rows for SELECT queries (empty array for write queries)" }, "changes": { "type": "number", "description": "Number of rows affected by INSERT, UPDATE, or DELETE queries (0 for SELECT)" } }, "required": ["rows", "changes"] }
|
|
709
|
+
},
|
|
696
710
|
"queryDataSource": {
|
|
697
711
|
stepType: "queryDataSource",
|
|
698
712
|
description: "Search a vector data source (RAG) and return relevant document chunks.",
|
|
@@ -732,7 +746,7 @@ var init_metadata = __esm({
|
|
|
732
746
|
stepType: "resizeVideo",
|
|
733
747
|
description: "Resize a video file",
|
|
734
748
|
usageNotes: "",
|
|
735
|
-
inputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the source video to resize" }, "mode": { "enum": ["fit", "exact"], "type": "string", "description": "Resize mode: 'fit' scales within max dimensions, 'exact' forces exact dimensions" }, "maxWidth": { "type": "number", "description": "Maximum width in pixels (used with 'fit' mode)" }, "maxHeight": { "type": "number", "description": "Maximum height in pixels (used with 'fit' mode)" }, "width": { "type": "number", "description": "Exact width in pixels (used with 'exact' mode)" }, "height": { "type": "number", "description": "Exact height in pixels (used with 'exact' mode)" }, "strategy": { "enum": ["pad", "crop"], "type": "string", "description": "Strategy for handling aspect ratio mismatch in 'exact' mode" }, "
|
|
749
|
+
inputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the source video to resize" }, "mode": { "enum": ["fit", "exact"], "type": "string", "description": "Resize mode: 'fit' scales within max dimensions, 'exact' forces exact dimensions" }, "maxWidth": { "type": "number", "description": "Maximum width in pixels (used with 'fit' mode)" }, "maxHeight": { "type": "number", "description": "Maximum height in pixels (used with 'fit' mode)" }, "width": { "type": "number", "description": "Exact width in pixels (used with 'exact' mode)" }, "height": { "type": "number", "description": "Exact height in pixels (used with 'exact' mode)" }, "strategy": { "enum": ["pad", "crop"], "type": "string", "description": "Strategy for handling aspect ratio mismatch in 'exact' mode" }, "intermediateAsset": { "type": "boolean", "description": "When true, the asset is created but hidden from the user's gallery (tagged as intermediate)" } }, "required": ["videoUrl", "mode"] },
|
|
736
750
|
outputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the resized video" } }, "required": ["videoUrl"] }
|
|
737
751
|
},
|
|
738
752
|
"runFromConnectorRegistry": {
|
|
@@ -1028,7 +1042,7 @@ var init_metadata = __esm({
|
|
|
1028
1042
|
stepType: "textToSpeech",
|
|
1029
1043
|
description: "Generate an audio file from provided text using a speech model.",
|
|
1030
1044
|
usageNotes: "- The text field contains the exact words to be spoken (not instructions).\n- In foreground mode, the audio is displayed to the user. In background mode, the URL is saved to a variable.",
|
|
1031
|
-
inputSchema: { "type": "object", "properties": { "text": { "type": "string", "description": "The text to convert to speech" }, "
|
|
1045
|
+
inputSchema: { "type": "object", "properties": { "text": { "type": "string", "description": "The text to convert to speech" }, "intermediateAsset": { "type": "boolean" }, "speechModelOverride": { "type": "object", "properties": { "model": { "type": "string", "description": "Speech synthesis model identifier" }, "config": { "type": "object", "description": "Additional model-specific configuration" } }, "required": ["model"], "description": "Optional model configuration override. Uses the workflow's default speech model if not specified" } }, "required": ["text"] },
|
|
1032
1046
|
outputSchema: { "type": "object", "properties": { "audioUrl": { "type": "string", "description": "URL of the generated audio file" } }, "required": ["audioUrl"] }
|
|
1033
1047
|
},
|
|
1034
1048
|
"transcribeAudio": {
|
|
@@ -1042,7 +1056,7 @@ var init_metadata = __esm({
|
|
|
1042
1056
|
stepType: "trimMedia",
|
|
1043
1057
|
description: "Trim an audio or video clip",
|
|
1044
1058
|
usageNotes: "",
|
|
1045
|
-
inputSchema: { "type": "object", "properties": { "inputUrl": { "type": "string", "description": "URL of the source audio or video file to trim" }, "start": { "type": ["number", "string"] }, "duration": { "type": ["string", "number"] }, "
|
|
1059
|
+
inputSchema: { "type": "object", "properties": { "inputUrl": { "type": "string", "description": "URL of the source audio or video file to trim" }, "start": { "type": ["number", "string"] }, "duration": { "type": ["string", "number"] }, "intermediateAsset": { "type": "boolean", "description": "When true, the asset is created but hidden from the user's gallery (tagged as intermediate)" } }, "required": ["inputUrl"] },
|
|
1046
1060
|
outputSchema: { "type": "object", "properties": { "mediaUrl": { "type": "string", "description": "URL of the trimmed media file" } }, "required": ["mediaUrl"] }
|
|
1047
1061
|
},
|
|
1048
1062
|
"updateGmailLabels": {
|
|
@@ -1091,7 +1105,7 @@ var init_metadata = __esm({
|
|
|
1091
1105
|
stepType: "upscaleVideo",
|
|
1092
1106
|
description: "Upscale a video file",
|
|
1093
1107
|
usageNotes: "",
|
|
1094
|
-
inputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the source video to upscale" }, "targetResolution": { "enum": ["720p", "1080p", "2K", "4K"], "type": "string", "description": "Target output resolution for the upscaled video" }, "engine": { "enum": ["standard", "pro", "ultimate", "flashvsr", "seedance", "seedvr2", "runwayml/upscale-v1"], "type": "string", "description": "Upscaling engine to use. Higher tiers produce better quality at higher cost." }, "
|
|
1108
|
+
inputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the source video to upscale" }, "targetResolution": { "enum": ["720p", "1080p", "2K", "4K"], "type": "string", "description": "Target output resolution for the upscaled video" }, "engine": { "enum": ["standard", "pro", "ultimate", "flashvsr", "seedance", "seedvr2", "runwayml/upscale-v1"], "type": "string", "description": "Upscaling engine to use. Higher tiers produce better quality at higher cost." }, "intermediateAsset": { "type": "boolean", "description": "When true, the asset is created but hidden from the user's gallery (tagged as intermediate)" } }, "required": ["videoUrl", "targetResolution", "engine"] },
|
|
1095
1109
|
outputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the upscaled video" } }, "required": ["videoUrl"] }
|
|
1096
1110
|
},
|
|
1097
1111
|
"userMessage": {
|
|
@@ -1108,35 +1122,35 @@ var init_metadata = __esm({
|
|
|
1108
1122
|
stepType: "videoFaceSwap",
|
|
1109
1123
|
description: "Swap faces in a video file",
|
|
1110
1124
|
usageNotes: "",
|
|
1111
|
-
inputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the source video containing faces to swap" }, "faceImageUrl": { "type": "string", "description": "URL of the image containing the replacement face" }, "targetIndex": { "type": "number", "description": "Zero-based index of the face to replace in the video" }, "engine": { "type": "string", "description": "Face swap engine to use" }, "
|
|
1125
|
+
inputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the source video containing faces to swap" }, "faceImageUrl": { "type": "string", "description": "URL of the image containing the replacement face" }, "targetIndex": { "type": "number", "description": "Zero-based index of the face to replace in the video" }, "engine": { "type": "string", "description": "Face swap engine to use" }, "intermediateAsset": { "type": "boolean", "description": "When true, the asset is created but hidden from the user's gallery (tagged as intermediate)" } }, "required": ["videoUrl", "faceImageUrl", "targetIndex", "engine"] },
|
|
1112
1126
|
outputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the face-swapped video" } }, "required": ["videoUrl"] }
|
|
1113
1127
|
},
|
|
1114
1128
|
"videoRemoveBackground": {
|
|
1115
1129
|
stepType: "videoRemoveBackground",
|
|
1116
1130
|
description: "Remove or replace background from a video",
|
|
1117
1131
|
usageNotes: "",
|
|
1118
|
-
inputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the source video" }, "newBackground": { "enum": ["transparent", "image"], "type": "string", "description": "Whether to make the background transparent or replace it with an image" }, "newBackgroundImageUrl": { "type": "string", "description": "URL of a replacement background image. Required when newBackground is 'image'." }, "engine": { "type": "string", "description": "Background removal engine to use" }, "
|
|
1132
|
+
inputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the source video" }, "newBackground": { "enum": ["transparent", "image"], "type": "string", "description": "Whether to make the background transparent or replace it with an image" }, "newBackgroundImageUrl": { "type": "string", "description": "URL of a replacement background image. Required when newBackground is 'image'." }, "engine": { "type": "string", "description": "Background removal engine to use" }, "intermediateAsset": { "type": "boolean", "description": "When true, the asset is created but hidden from the user's gallery (tagged as intermediate)" } }, "required": ["videoUrl", "newBackground", "engine"] },
|
|
1119
1133
|
outputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the video with background removed or replaced" } }, "required": ["videoUrl"] }
|
|
1120
1134
|
},
|
|
1121
1135
|
"videoRemoveWatermark": {
|
|
1122
1136
|
stepType: "videoRemoveWatermark",
|
|
1123
1137
|
description: "Remove a watermark from a video",
|
|
1124
1138
|
usageNotes: "",
|
|
1125
|
-
inputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the source video containing a watermark" }, "engine": { "type": "string", "description": "Watermark removal engine to use" }, "
|
|
1139
|
+
inputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the source video containing a watermark" }, "engine": { "type": "string", "description": "Watermark removal engine to use" }, "intermediateAsset": { "type": "boolean", "description": "When true, the asset is created but hidden from the user's gallery (tagged as intermediate)" } }, "required": ["videoUrl", "engine"] },
|
|
1126
1140
|
outputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the video with watermark removed" } }, "required": ["videoUrl"] }
|
|
1127
1141
|
},
|
|
1128
1142
|
"watermarkImage": {
|
|
1129
1143
|
stepType: "watermarkImage",
|
|
1130
1144
|
description: "Overlay a watermark image onto another image.",
|
|
1131
1145
|
usageNotes: "- The watermark is placed at the specified corner with configurable padding and width.",
|
|
1132
|
-
inputSchema: { "type": "object", "properties": { "imageUrl": { "type": "string", "description": "URL of the base image" }, "watermarkImageUrl": { "type": "string", "description": "URL of the watermark image to overlay" }, "corner": { "enum": ["top-left", "top-right", "bottom-left", "bottom-right"], "type": "string", "description": "Corner position for the watermark placement" }, "paddingPx": { "type": "number", "description": "Padding from the corner in pixels" }, "widthPx": { "type": "number", "description": "Width of the watermark overlay in pixels" }, "
|
|
1146
|
+
inputSchema: { "type": "object", "properties": { "imageUrl": { "type": "string", "description": "URL of the base image" }, "watermarkImageUrl": { "type": "string", "description": "URL of the watermark image to overlay" }, "corner": { "enum": ["top-left", "top-right", "bottom-left", "bottom-right"], "type": "string", "description": "Corner position for the watermark placement" }, "paddingPx": { "type": "number", "description": "Padding from the corner in pixels" }, "widthPx": { "type": "number", "description": "Width of the watermark overlay in pixels" }, "intermediateAsset": { "type": "boolean", "description": "When true, the asset is created but hidden from the user's gallery (tagged as intermediate)" } }, "required": ["imageUrl", "watermarkImageUrl", "corner", "paddingPx", "widthPx"] },
|
|
1133
1147
|
outputSchema: { "type": "object", "properties": { "imageUrl": { "type": "string", "description": "CDN URL of the watermarked image" } }, "required": ["imageUrl"] }
|
|
1134
1148
|
},
|
|
1135
1149
|
"watermarkVideo": {
|
|
1136
1150
|
stepType: "watermarkVideo",
|
|
1137
1151
|
description: "Add an image watermark to a video",
|
|
1138
1152
|
usageNotes: "",
|
|
1139
|
-
inputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the source video" }, "imageUrl": { "type": "string", "description": "URL of the watermark image to overlay" }, "corner": { "enum": ["top-left", "top-right", "bottom-left", "bottom-right"], "type": "string", "description": "Corner position for the watermark placement" }, "paddingPx": { "type": "number", "description": "Padding from the corner in pixels" }, "widthPx": { "type": "number", "description": "Width of the watermark overlay in pixels" }, "
|
|
1153
|
+
inputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the source video" }, "imageUrl": { "type": "string", "description": "URL of the watermark image to overlay" }, "corner": { "enum": ["top-left", "top-right", "bottom-left", "bottom-right"], "type": "string", "description": "Corner position for the watermark placement" }, "paddingPx": { "type": "number", "description": "Padding from the corner in pixels" }, "widthPx": { "type": "number", "description": "Width of the watermark overlay in pixels" }, "intermediateAsset": { "type": "boolean", "description": "When true, the asset is created but hidden from the user's gallery (tagged as intermediate)" } }, "required": ["videoUrl", "imageUrl", "corner", "paddingPx", "widthPx"] },
|
|
1140
1154
|
outputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the watermarked video" } }, "required": ["videoUrl"] }
|
|
1141
1155
|
}
|
|
1142
1156
|
};
|
|
@@ -1324,6 +1338,1145 @@ var init_config = __esm({
|
|
|
1324
1338
|
}
|
|
1325
1339
|
});
|
|
1326
1340
|
|
|
1341
|
+
// src/auth/index.ts
|
|
1342
|
+
var AuthContext, Roles;
|
|
1343
|
+
var init_auth = __esm({
|
|
1344
|
+
"src/auth/index.ts"() {
|
|
1345
|
+
"use strict";
|
|
1346
|
+
init_errors();
|
|
1347
|
+
AuthContext = class {
|
|
1348
|
+
/** The current user's ID. */
|
|
1349
|
+
userId;
|
|
1350
|
+
/** The current user's roles in this app. */
|
|
1351
|
+
roles;
|
|
1352
|
+
/** All role assignments for this app (all users, all roles). */
|
|
1353
|
+
_roleAssignments;
|
|
1354
|
+
constructor(ctx) {
|
|
1355
|
+
this.userId = ctx.userId;
|
|
1356
|
+
this._roleAssignments = ctx.roleAssignments;
|
|
1357
|
+
this.roles = ctx.roleAssignments.filter((a) => a.userId === ctx.userId).map((a) => a.roleName);
|
|
1358
|
+
}
|
|
1359
|
+
/**
|
|
1360
|
+
* Check if the current user has **any** of the given roles.
|
|
1361
|
+
* Returns true if at least one matches.
|
|
1362
|
+
*
|
|
1363
|
+
* @example
|
|
1364
|
+
* ```ts
|
|
1365
|
+
* if (auth.hasRole(Roles.admin, Roles.approver)) {
|
|
1366
|
+
* // user is an admin OR an approver
|
|
1367
|
+
* }
|
|
1368
|
+
* ```
|
|
1369
|
+
*/
|
|
1370
|
+
hasRole(...roles) {
|
|
1371
|
+
return roles.some((r) => this.roles.includes(r));
|
|
1372
|
+
}
|
|
1373
|
+
/**
|
|
1374
|
+
* Require the current user to have at least one of the given roles.
|
|
1375
|
+
* Throws a `MindStudioError` with code `'forbidden'` and status 403
|
|
1376
|
+
* if the user lacks all of the specified roles.
|
|
1377
|
+
*
|
|
1378
|
+
* Use this at the top of route handlers to gate access.
|
|
1379
|
+
*
|
|
1380
|
+
* @example
|
|
1381
|
+
* ```ts
|
|
1382
|
+
* auth.requireRole(Roles.admin);
|
|
1383
|
+
* // code below only runs if user is an admin
|
|
1384
|
+
* ```
|
|
1385
|
+
*/
|
|
1386
|
+
requireRole(...roles) {
|
|
1387
|
+
if (!this.hasRole(...roles)) {
|
|
1388
|
+
throw new MindStudioError(
|
|
1389
|
+
`User does not have required role: ${roles.join(", ")}`,
|
|
1390
|
+
"forbidden",
|
|
1391
|
+
403
|
|
1392
|
+
);
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
/**
|
|
1396
|
+
* Get all user IDs that have the given role in this app.
|
|
1397
|
+
* Synchronous — scans the preloaded role assignments.
|
|
1398
|
+
*
|
|
1399
|
+
* @example
|
|
1400
|
+
* ```ts
|
|
1401
|
+
* const reviewers = auth.getUsersByRole(Roles.reviewer);
|
|
1402
|
+
* // ['user-id-1', 'user-id-2', ...]
|
|
1403
|
+
* ```
|
|
1404
|
+
*/
|
|
1405
|
+
getUsersByRole(role) {
|
|
1406
|
+
return this._roleAssignments.filter((a) => a.roleName === role).map((a) => a.userId);
|
|
1407
|
+
}
|
|
1408
|
+
};
|
|
1409
|
+
Roles = new Proxy(
|
|
1410
|
+
{},
|
|
1411
|
+
{
|
|
1412
|
+
get(_, prop) {
|
|
1413
|
+
if (typeof prop === "string") return prop;
|
|
1414
|
+
return void 0;
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
);
|
|
1418
|
+
}
|
|
1419
|
+
});
|
|
1420
|
+
|
|
1421
|
+
// src/db/sql.ts
|
|
1422
|
+
function serializeParam(val) {
|
|
1423
|
+
if (val === null || val === void 0) return null;
|
|
1424
|
+
if (typeof val === "boolean") return val ? 1 : 0;
|
|
1425
|
+
if (typeof val === "number" || typeof val === "string") return val;
|
|
1426
|
+
return JSON.stringify(val);
|
|
1427
|
+
}
|
|
1428
|
+
function serializeColumnParam(val, columnName, columns) {
|
|
1429
|
+
const col = columns.find((c) => c.name === columnName);
|
|
1430
|
+
if (col?.type === "user" && typeof val === "string") {
|
|
1431
|
+
return `@@user@@${val}`;
|
|
1432
|
+
}
|
|
1433
|
+
return serializeParam(val);
|
|
1434
|
+
}
|
|
1435
|
+
function escapeValue(val) {
|
|
1436
|
+
if (val === null || val === void 0) return "NULL";
|
|
1437
|
+
if (typeof val === "boolean") return val ? "1" : "0";
|
|
1438
|
+
if (typeof val === "number") return String(val);
|
|
1439
|
+
if (typeof val === "string") return `'${val.replace(/'/g, "''")}'`;
|
|
1440
|
+
const json = JSON.stringify(val);
|
|
1441
|
+
return `'${json.replace(/'/g, "''")}'`;
|
|
1442
|
+
}
|
|
1443
|
+
function deserializeRow(row, columns) {
|
|
1444
|
+
const result = {};
|
|
1445
|
+
for (const [key, value] of Object.entries(row)) {
|
|
1446
|
+
const col = columns.find((c) => c.name === key);
|
|
1447
|
+
if (col?.type === "user" && typeof value === "string" && value.startsWith(USER_PREFIX)) {
|
|
1448
|
+
result[key] = value.slice(USER_PREFIX.length);
|
|
1449
|
+
} else if (col?.type === "json" && typeof value === "string") {
|
|
1450
|
+
try {
|
|
1451
|
+
result[key] = JSON.parse(value);
|
|
1452
|
+
} catch {
|
|
1453
|
+
result[key] = value;
|
|
1454
|
+
}
|
|
1455
|
+
} else {
|
|
1456
|
+
result[key] = value;
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
return result;
|
|
1460
|
+
}
|
|
1461
|
+
function buildSelect(table, options = {}) {
|
|
1462
|
+
let sql = `SELECT * FROM ${table}`;
|
|
1463
|
+
const params = [];
|
|
1464
|
+
if (options.where) {
|
|
1465
|
+
sql += ` WHERE ${options.where}`;
|
|
1466
|
+
if (options.whereParams) params.push(...options.whereParams);
|
|
1467
|
+
}
|
|
1468
|
+
if (options.orderBy) sql += ` ORDER BY ${options.orderBy}${options.desc ? " DESC" : " ASC"}`;
|
|
1469
|
+
if (options.limit != null) sql += ` LIMIT ${options.limit}`;
|
|
1470
|
+
if (options.offset != null) sql += ` OFFSET ${options.offset}`;
|
|
1471
|
+
return { sql, params: params.length > 0 ? params : void 0 };
|
|
1472
|
+
}
|
|
1473
|
+
function buildCount(table, where, whereParams) {
|
|
1474
|
+
let sql = `SELECT COUNT(*) as count FROM ${table}`;
|
|
1475
|
+
if (where) sql += ` WHERE ${where}`;
|
|
1476
|
+
return { sql, params: whereParams?.length ? whereParams : void 0 };
|
|
1477
|
+
}
|
|
1478
|
+
function buildExists(table, where, whereParams, negate) {
|
|
1479
|
+
const inner = where ? `SELECT 1 FROM ${table} WHERE ${where}` : `SELECT 1 FROM ${table}`;
|
|
1480
|
+
const fn = negate ? "NOT EXISTS" : "EXISTS";
|
|
1481
|
+
return { sql: `SELECT ${fn}(${inner}) as result`, params: whereParams?.length ? whereParams : void 0 };
|
|
1482
|
+
}
|
|
1483
|
+
function buildInsert(table, data, columns) {
|
|
1484
|
+
const filtered = stripSystemColumns(data);
|
|
1485
|
+
const keys = Object.keys(filtered);
|
|
1486
|
+
const placeholders = keys.map(() => "?").join(", ");
|
|
1487
|
+
const params = keys.map((k) => serializeColumnParam(filtered[k], k, columns));
|
|
1488
|
+
return {
|
|
1489
|
+
sql: `INSERT INTO ${table} (${keys.join(", ")}) VALUES (${placeholders}) RETURNING *`,
|
|
1490
|
+
params
|
|
1491
|
+
};
|
|
1492
|
+
}
|
|
1493
|
+
function buildUpdate(table, id, data, columns) {
|
|
1494
|
+
const filtered = stripSystemColumns(data);
|
|
1495
|
+
const keys = Object.keys(filtered);
|
|
1496
|
+
const assignments = keys.map((k) => `${k} = ?`).join(", ");
|
|
1497
|
+
const params = [
|
|
1498
|
+
...keys.map((k) => serializeColumnParam(filtered[k], k, columns)),
|
|
1499
|
+
id
|
|
1500
|
+
// for WHERE id = ?
|
|
1501
|
+
];
|
|
1502
|
+
return {
|
|
1503
|
+
sql: `UPDATE ${table} SET ${assignments} WHERE id = ? RETURNING *`,
|
|
1504
|
+
params
|
|
1505
|
+
};
|
|
1506
|
+
}
|
|
1507
|
+
function buildDelete(table, where, whereParams) {
|
|
1508
|
+
let sql = `DELETE FROM ${table}`;
|
|
1509
|
+
if (where) sql += ` WHERE ${where}`;
|
|
1510
|
+
return { sql, params: whereParams?.length ? whereParams : void 0 };
|
|
1511
|
+
}
|
|
1512
|
+
function stripSystemColumns(data) {
|
|
1513
|
+
const result = {};
|
|
1514
|
+
for (const [key, value] of Object.entries(data)) {
|
|
1515
|
+
if (!SYSTEM_COLUMNS.has(key)) {
|
|
1516
|
+
result[key] = value;
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
return result;
|
|
1520
|
+
}
|
|
1521
|
+
var USER_PREFIX, SYSTEM_COLUMNS;
|
|
1522
|
+
var init_sql = __esm({
|
|
1523
|
+
"src/db/sql.ts"() {
|
|
1524
|
+
"use strict";
|
|
1525
|
+
USER_PREFIX = "@@user@@";
|
|
1526
|
+
SYSTEM_COLUMNS = /* @__PURE__ */ new Set(["id", "createdAt", "updatedAt", "lastUpdatedBy"]);
|
|
1527
|
+
}
|
|
1528
|
+
});
|
|
1529
|
+
|
|
1530
|
+
// src/db/predicate.ts
|
|
1531
|
+
function compilePredicate(fn) {
|
|
1532
|
+
try {
|
|
1533
|
+
const source = fn.toString();
|
|
1534
|
+
const paramName = extractParamName(source);
|
|
1535
|
+
if (!paramName) return { type: "js", fn };
|
|
1536
|
+
const body = extractBody(source);
|
|
1537
|
+
if (!body) return { type: "js", fn };
|
|
1538
|
+
const tokens = tokenize(body);
|
|
1539
|
+
if (tokens.length === 0) return { type: "js", fn };
|
|
1540
|
+
const parser = new Parser(tokens, paramName, fn);
|
|
1541
|
+
const ast = parser.parseExpression();
|
|
1542
|
+
if (!ast) return { type: "js", fn };
|
|
1543
|
+
if (parser.pos < tokens.length) return { type: "js", fn };
|
|
1544
|
+
const where = compileNode(ast);
|
|
1545
|
+
if (!where) return { type: "js", fn };
|
|
1546
|
+
return { type: "sql", where };
|
|
1547
|
+
} catch {
|
|
1548
|
+
return { type: "js", fn };
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
function extractParamName(source) {
|
|
1552
|
+
const match = source.match(
|
|
1553
|
+
/^\s*(?:\(?\s*([a-zA-Z_$][a-zA-Z0-9_$]*)\s*(?::[^)]*?)?\)?\s*=>)/
|
|
1554
|
+
);
|
|
1555
|
+
return match?.[1] ?? null;
|
|
1556
|
+
}
|
|
1557
|
+
function extractBody(source) {
|
|
1558
|
+
const arrowIdx = source.indexOf("=>");
|
|
1559
|
+
if (arrowIdx === -1) return null;
|
|
1560
|
+
let body = source.slice(arrowIdx + 2).trim();
|
|
1561
|
+
if (body.startsWith("{")) {
|
|
1562
|
+
const match = body.match(/^\{\s*return\s+([\s\S]+?)\s*;?\s*\}$/);
|
|
1563
|
+
if (!match) return null;
|
|
1564
|
+
body = match[1];
|
|
1565
|
+
}
|
|
1566
|
+
return body.trim() || null;
|
|
1567
|
+
}
|
|
1568
|
+
function tokenize(expr) {
|
|
1569
|
+
const tokens = [];
|
|
1570
|
+
let i = 0;
|
|
1571
|
+
while (i < expr.length) {
|
|
1572
|
+
const ch = expr[i];
|
|
1573
|
+
if (/\s/.test(ch)) {
|
|
1574
|
+
i++;
|
|
1575
|
+
continue;
|
|
1576
|
+
}
|
|
1577
|
+
if (ch === "'" || ch === '"') {
|
|
1578
|
+
const quote = ch;
|
|
1579
|
+
let str = "";
|
|
1580
|
+
i++;
|
|
1581
|
+
while (i < expr.length && expr[i] !== quote) {
|
|
1582
|
+
if (expr[i] === "\\") {
|
|
1583
|
+
i++;
|
|
1584
|
+
if (i < expr.length) str += expr[i];
|
|
1585
|
+
} else {
|
|
1586
|
+
str += expr[i];
|
|
1587
|
+
}
|
|
1588
|
+
i++;
|
|
1589
|
+
}
|
|
1590
|
+
if (i >= expr.length) return [];
|
|
1591
|
+
i++;
|
|
1592
|
+
tokens.push({ type: "string", value: str });
|
|
1593
|
+
continue;
|
|
1594
|
+
}
|
|
1595
|
+
if (ch === "`") return [];
|
|
1596
|
+
if (/[0-9]/.test(ch) || ch === "-" && i + 1 < expr.length && /[0-9]/.test(expr[i + 1])) {
|
|
1597
|
+
let num = ch;
|
|
1598
|
+
i++;
|
|
1599
|
+
while (i < expr.length && /[0-9.]/.test(expr[i])) {
|
|
1600
|
+
num += expr[i];
|
|
1601
|
+
i++;
|
|
1602
|
+
}
|
|
1603
|
+
tokens.push({ type: "number", value: num });
|
|
1604
|
+
continue;
|
|
1605
|
+
}
|
|
1606
|
+
if (expr.slice(i, i + 3) === "===" || expr.slice(i, i + 3) === "!==") {
|
|
1607
|
+
tokens.push({ type: "operator", value: expr.slice(i, i + 3) });
|
|
1608
|
+
i += 3;
|
|
1609
|
+
continue;
|
|
1610
|
+
}
|
|
1611
|
+
if (expr.slice(i, i + 2) === "==" || expr.slice(i, i + 2) === "!=" || expr.slice(i, i + 2) === "<=" || expr.slice(i, i + 2) === ">=" || expr.slice(i, i + 2) === "&&" || expr.slice(i, i + 2) === "||") {
|
|
1612
|
+
tokens.push({ type: "operator", value: expr.slice(i, i + 2) });
|
|
1613
|
+
i += 2;
|
|
1614
|
+
continue;
|
|
1615
|
+
}
|
|
1616
|
+
if (ch === "!" || ch === "<" || ch === ">") {
|
|
1617
|
+
tokens.push({ type: "operator", value: ch });
|
|
1618
|
+
i++;
|
|
1619
|
+
continue;
|
|
1620
|
+
}
|
|
1621
|
+
if (ch === ".") {
|
|
1622
|
+
tokens.push({ type: "dot", value: "." });
|
|
1623
|
+
i++;
|
|
1624
|
+
continue;
|
|
1625
|
+
}
|
|
1626
|
+
if (ch === "(") {
|
|
1627
|
+
tokens.push({ type: "lparen", value: "(" });
|
|
1628
|
+
i++;
|
|
1629
|
+
continue;
|
|
1630
|
+
}
|
|
1631
|
+
if (ch === ")") {
|
|
1632
|
+
tokens.push({ type: "rparen", value: ")" });
|
|
1633
|
+
i++;
|
|
1634
|
+
continue;
|
|
1635
|
+
}
|
|
1636
|
+
if (ch === "[") {
|
|
1637
|
+
tokens.push({ type: "lbracket", value: "[" });
|
|
1638
|
+
i++;
|
|
1639
|
+
continue;
|
|
1640
|
+
}
|
|
1641
|
+
if (ch === "]") {
|
|
1642
|
+
tokens.push({ type: "rbracket", value: "]" });
|
|
1643
|
+
i++;
|
|
1644
|
+
continue;
|
|
1645
|
+
}
|
|
1646
|
+
if (ch === ",") {
|
|
1647
|
+
tokens.push({ type: "comma", value: "," });
|
|
1648
|
+
i++;
|
|
1649
|
+
continue;
|
|
1650
|
+
}
|
|
1651
|
+
if (/[a-zA-Z_$]/.test(ch)) {
|
|
1652
|
+
let ident = ch;
|
|
1653
|
+
i++;
|
|
1654
|
+
while (i < expr.length && /[a-zA-Z0-9_$]/.test(expr[i])) {
|
|
1655
|
+
ident += expr[i];
|
|
1656
|
+
i++;
|
|
1657
|
+
}
|
|
1658
|
+
tokens.push({ type: "identifier", value: ident });
|
|
1659
|
+
continue;
|
|
1660
|
+
}
|
|
1661
|
+
return [];
|
|
1662
|
+
}
|
|
1663
|
+
return tokens;
|
|
1664
|
+
}
|
|
1665
|
+
function compileNode(node) {
|
|
1666
|
+
switch (node.kind) {
|
|
1667
|
+
case "comparison":
|
|
1668
|
+
return `${node.field} ${node.operator} ${escapeValue(node.value)}`;
|
|
1669
|
+
case "nullCheck":
|
|
1670
|
+
return `${node.field} ${node.isNull ? "IS NULL" : "IS NOT NULL"}`;
|
|
1671
|
+
case "in": {
|
|
1672
|
+
if (node.values.length === 0) return "0";
|
|
1673
|
+
const vals = node.values.map(escapeValue).join(", ");
|
|
1674
|
+
return `${node.field} IN (${vals})`;
|
|
1675
|
+
}
|
|
1676
|
+
case "like":
|
|
1677
|
+
return `${node.field} LIKE ${escapeValue(node.pattern)}`;
|
|
1678
|
+
case "booleanField":
|
|
1679
|
+
return node.negated ? `${node.field} = 0` : `${node.field} = 1`;
|
|
1680
|
+
case "logical": {
|
|
1681
|
+
const left = compileNode(node.left);
|
|
1682
|
+
const right = compileNode(node.right);
|
|
1683
|
+
if (!left || !right) return null;
|
|
1684
|
+
return `(${left} ${node.operator} ${right})`;
|
|
1685
|
+
}
|
|
1686
|
+
case "not": {
|
|
1687
|
+
const inner = compileNode(node.operand);
|
|
1688
|
+
if (!inner) return null;
|
|
1689
|
+
return `NOT (${inner})`;
|
|
1690
|
+
}
|
|
1691
|
+
default:
|
|
1692
|
+
return null;
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
function isComparisonOp(value) {
|
|
1696
|
+
return value in JS_TO_SQL_OP;
|
|
1697
|
+
}
|
|
1698
|
+
var Parser, JS_TO_SQL_OP, PARSE_FAILED;
|
|
1699
|
+
var init_predicate = __esm({
|
|
1700
|
+
"src/db/predicate.ts"() {
|
|
1701
|
+
"use strict";
|
|
1702
|
+
init_sql();
|
|
1703
|
+
Parser = class {
|
|
1704
|
+
constructor(tokens, paramName, originalFn) {
|
|
1705
|
+
this.tokens = tokens;
|
|
1706
|
+
this.paramName = paramName;
|
|
1707
|
+
this.originalFn = originalFn;
|
|
1708
|
+
}
|
|
1709
|
+
pos = 0;
|
|
1710
|
+
/** Peek at the current token without consuming it. */
|
|
1711
|
+
peek() {
|
|
1712
|
+
return this.tokens[this.pos];
|
|
1713
|
+
}
|
|
1714
|
+
/** Consume the current token and advance. */
|
|
1715
|
+
advance() {
|
|
1716
|
+
return this.tokens[this.pos++];
|
|
1717
|
+
}
|
|
1718
|
+
/** Check if the current token matches an expected type and value. */
|
|
1719
|
+
match(type, value) {
|
|
1720
|
+
const t = this.peek();
|
|
1721
|
+
if (!t) return false;
|
|
1722
|
+
if (t.type !== type) return false;
|
|
1723
|
+
if (value !== void 0 && t.value !== value) return false;
|
|
1724
|
+
return true;
|
|
1725
|
+
}
|
|
1726
|
+
/** Consume a token if it matches, otherwise return false. */
|
|
1727
|
+
eat(type, value) {
|
|
1728
|
+
if (this.match(type, value)) {
|
|
1729
|
+
this.advance();
|
|
1730
|
+
return true;
|
|
1731
|
+
}
|
|
1732
|
+
return false;
|
|
1733
|
+
}
|
|
1734
|
+
// --- Grammar rules ---
|
|
1735
|
+
/** Entry point: parse a full expression. */
|
|
1736
|
+
parseExpression() {
|
|
1737
|
+
return this.parseOr();
|
|
1738
|
+
}
|
|
1739
|
+
/** or_expr → and_expr ( '||' and_expr )* */
|
|
1740
|
+
parseOr() {
|
|
1741
|
+
let left = this.parseAnd();
|
|
1742
|
+
if (!left) return null;
|
|
1743
|
+
while (this.match("operator", "||")) {
|
|
1744
|
+
this.advance();
|
|
1745
|
+
const right = this.parseAnd();
|
|
1746
|
+
if (!right) return null;
|
|
1747
|
+
left = { kind: "logical", operator: "OR", left, right };
|
|
1748
|
+
}
|
|
1749
|
+
return left;
|
|
1750
|
+
}
|
|
1751
|
+
/** and_expr → not_expr ( '&&' not_expr )* */
|
|
1752
|
+
parseAnd() {
|
|
1753
|
+
let left = this.parseNot();
|
|
1754
|
+
if (!left) return null;
|
|
1755
|
+
while (this.match("operator", "&&")) {
|
|
1756
|
+
this.advance();
|
|
1757
|
+
const right = this.parseNot();
|
|
1758
|
+
if (!right) return null;
|
|
1759
|
+
left = { kind: "logical", operator: "AND", left, right };
|
|
1760
|
+
}
|
|
1761
|
+
return left;
|
|
1762
|
+
}
|
|
1763
|
+
/** not_expr → '!' not_expr | primary */
|
|
1764
|
+
parseNot() {
|
|
1765
|
+
if (this.match("operator", "!")) {
|
|
1766
|
+
this.advance();
|
|
1767
|
+
if (this.match("lparen")) {
|
|
1768
|
+
this.advance();
|
|
1769
|
+
const inner2 = this.parseExpression();
|
|
1770
|
+
if (!inner2) return null;
|
|
1771
|
+
if (!this.eat("rparen")) return null;
|
|
1772
|
+
return { kind: "not", operand: inner2 };
|
|
1773
|
+
}
|
|
1774
|
+
const inner = this.parsePrimary();
|
|
1775
|
+
if (!inner) return null;
|
|
1776
|
+
if (inner.kind === "booleanField") {
|
|
1777
|
+
return { ...inner, negated: !inner.negated };
|
|
1778
|
+
}
|
|
1779
|
+
return { kind: "not", operand: inner };
|
|
1780
|
+
}
|
|
1781
|
+
return this.parsePrimary();
|
|
1782
|
+
}
|
|
1783
|
+
/**
|
|
1784
|
+
* primary → field_comparison | null_check | includes_expr | paren_expr | boolean_field
|
|
1785
|
+
*
|
|
1786
|
+
* This is the workhorse — handles the different patterns that can appear
|
|
1787
|
+
* as atomic expressions within a larger &&/|| combination.
|
|
1788
|
+
*/
|
|
1789
|
+
parsePrimary() {
|
|
1790
|
+
if (this.match("lparen")) {
|
|
1791
|
+
this.advance();
|
|
1792
|
+
const inner = this.parseExpression();
|
|
1793
|
+
if (!inner) return null;
|
|
1794
|
+
if (!this.eat("rparen")) return null;
|
|
1795
|
+
return inner;
|
|
1796
|
+
}
|
|
1797
|
+
if (this.match("lbracket")) {
|
|
1798
|
+
return this.parseArrayIncludes();
|
|
1799
|
+
}
|
|
1800
|
+
if (this.match("identifier", this.paramName)) {
|
|
1801
|
+
return this.parseFieldExpression();
|
|
1802
|
+
}
|
|
1803
|
+
if (this.match("identifier")) {
|
|
1804
|
+
return this.parseNonParamExpression();
|
|
1805
|
+
}
|
|
1806
|
+
return null;
|
|
1807
|
+
}
|
|
1808
|
+
/**
|
|
1809
|
+
* Parse an expression that starts with the parameter name (e.g. `o.field`).
|
|
1810
|
+
*
|
|
1811
|
+
* Could be:
|
|
1812
|
+
* - `o.field === value` (comparison)
|
|
1813
|
+
* - `o.field != null` (null check)
|
|
1814
|
+
* - `o.field.includes('text')` (LIKE)
|
|
1815
|
+
* - `o.field` alone (boolean field check)
|
|
1816
|
+
*/
|
|
1817
|
+
parseFieldExpression() {
|
|
1818
|
+
this.advance();
|
|
1819
|
+
const field = this.parseFieldPath();
|
|
1820
|
+
if (!field) return null;
|
|
1821
|
+
const next = this.peek();
|
|
1822
|
+
if (next?.type === "dot" && this.lookAheadForIncludes()) {
|
|
1823
|
+
return this.parseFieldIncludes(field);
|
|
1824
|
+
}
|
|
1825
|
+
if (next?.type === "operator" && isComparisonOp(next.value)) {
|
|
1826
|
+
return this.parseComparison(field);
|
|
1827
|
+
}
|
|
1828
|
+
return { kind: "booleanField", field, negated: false };
|
|
1829
|
+
}
|
|
1830
|
+
/**
|
|
1831
|
+
* Parse a dot-separated field path after the parameter name.
|
|
1832
|
+
* `o.status` → `"status"`, `o.address.city` → `"json_extract(address, '$.city')"`.
|
|
1833
|
+
*/
|
|
1834
|
+
parseFieldPath() {
|
|
1835
|
+
if (!this.eat("dot")) return null;
|
|
1836
|
+
if (!this.match("identifier")) return null;
|
|
1837
|
+
const parts = [this.advance().value];
|
|
1838
|
+
while (this.match("dot") && this.tokens[this.pos + 1]?.type === "identifier") {
|
|
1839
|
+
this.advance();
|
|
1840
|
+
parts.push(this.advance().value);
|
|
1841
|
+
}
|
|
1842
|
+
if (parts.length === 1) {
|
|
1843
|
+
return parts[0];
|
|
1844
|
+
}
|
|
1845
|
+
const root = parts[0];
|
|
1846
|
+
const jsonPath = "$." + parts.slice(1).join(".");
|
|
1847
|
+
return `json_extract(${root}, '${jsonPath}')`;
|
|
1848
|
+
}
|
|
1849
|
+
/**
|
|
1850
|
+
* Parse a comparison: `field OP value`.
|
|
1851
|
+
* The field has already been parsed; we need the operator and right-hand value.
|
|
1852
|
+
*/
|
|
1853
|
+
parseComparison(field) {
|
|
1854
|
+
const opToken = this.advance();
|
|
1855
|
+
const jsOp = opToken.value;
|
|
1856
|
+
const value = this.parseValue();
|
|
1857
|
+
if (value === PARSE_FAILED) return null;
|
|
1858
|
+
if (value === null || value === void 0) {
|
|
1859
|
+
if (jsOp === "===" || jsOp === "==") {
|
|
1860
|
+
return { kind: "nullCheck", field, isNull: true };
|
|
1861
|
+
}
|
|
1862
|
+
if (jsOp === "!==" || jsOp === "!=") {
|
|
1863
|
+
return { kind: "nullCheck", field, isNull: false };
|
|
1864
|
+
}
|
|
1865
|
+
return null;
|
|
1866
|
+
}
|
|
1867
|
+
const sqlOp = JS_TO_SQL_OP[jsOp];
|
|
1868
|
+
if (!sqlOp) return null;
|
|
1869
|
+
return { kind: "comparison", field, operator: sqlOp, value };
|
|
1870
|
+
}
|
|
1871
|
+
/**
|
|
1872
|
+
* Parse `o.field.includes('text')` → LIKE expression.
|
|
1873
|
+
* The field name has already been parsed.
|
|
1874
|
+
*/
|
|
1875
|
+
parseFieldIncludes(field) {
|
|
1876
|
+
this.advance();
|
|
1877
|
+
this.advance();
|
|
1878
|
+
if (!this.eat("lparen")) return null;
|
|
1879
|
+
const value = this.parseValue();
|
|
1880
|
+
if (value === PARSE_FAILED || typeof value !== "string") return null;
|
|
1881
|
+
if (!this.eat("rparen")) return null;
|
|
1882
|
+
const escaped = value.replace(/%/g, "\\%").replace(/_/g, "\\_");
|
|
1883
|
+
return { kind: "like", field, pattern: `%${escaped}%` };
|
|
1884
|
+
}
|
|
1885
|
+
/**
|
|
1886
|
+
* Parse `['a', 'b', 'c'].includes(o.field)` → IN expression.
|
|
1887
|
+
* The opening bracket has been peeked but not consumed.
|
|
1888
|
+
*/
|
|
1889
|
+
parseArrayIncludes() {
|
|
1890
|
+
this.advance();
|
|
1891
|
+
const values = [];
|
|
1892
|
+
while (!this.match("rbracket")) {
|
|
1893
|
+
if (values.length > 0) {
|
|
1894
|
+
if (!this.eat("comma")) return null;
|
|
1895
|
+
}
|
|
1896
|
+
const val = this.parseValue();
|
|
1897
|
+
if (val === PARSE_FAILED) return null;
|
|
1898
|
+
values.push(val);
|
|
1899
|
+
}
|
|
1900
|
+
this.advance();
|
|
1901
|
+
if (!this.eat("dot")) return null;
|
|
1902
|
+
if (!this.match("identifier", "includes")) return null;
|
|
1903
|
+
this.advance();
|
|
1904
|
+
if (!this.eat("lparen")) return null;
|
|
1905
|
+
if (!this.match("identifier", this.paramName)) return null;
|
|
1906
|
+
this.advance();
|
|
1907
|
+
const field = this.parseFieldPath();
|
|
1908
|
+
if (!field) return null;
|
|
1909
|
+
if (!this.eat("rparen")) return null;
|
|
1910
|
+
return { kind: "in", field, values };
|
|
1911
|
+
}
|
|
1912
|
+
/**
|
|
1913
|
+
* Parse an expression that starts with an identifier that is NOT the
|
|
1914
|
+
* parameter name. This could be:
|
|
1915
|
+
* - A keyword literal: `true`, `false`, `null`, `undefined`
|
|
1916
|
+
* - A closure variable used in a comparison (handled by backtracking)
|
|
1917
|
+
*/
|
|
1918
|
+
parseNonParamExpression() {
|
|
1919
|
+
const ident = this.peek().value;
|
|
1920
|
+
if (ident === "true" || ident === "false") return null;
|
|
1921
|
+
return null;
|
|
1922
|
+
}
|
|
1923
|
+
/**
|
|
1924
|
+
* Parse a literal value or closure variable reference.
|
|
1925
|
+
*
|
|
1926
|
+
* Returns the parsed value, or PARSE_FAILED if parsing fails.
|
|
1927
|
+
* Returns `null` or `undefined` for those keyword literals.
|
|
1928
|
+
*/
|
|
1929
|
+
parseValue() {
|
|
1930
|
+
const t = this.peek();
|
|
1931
|
+
if (!t) return PARSE_FAILED;
|
|
1932
|
+
if (t.type === "string") {
|
|
1933
|
+
this.advance();
|
|
1934
|
+
return t.value;
|
|
1935
|
+
}
|
|
1936
|
+
if (t.type === "number") {
|
|
1937
|
+
this.advance();
|
|
1938
|
+
return Number(t.value);
|
|
1939
|
+
}
|
|
1940
|
+
if (t.type === "identifier") {
|
|
1941
|
+
if (t.value === "true") {
|
|
1942
|
+
this.advance();
|
|
1943
|
+
return true;
|
|
1944
|
+
}
|
|
1945
|
+
if (t.value === "false") {
|
|
1946
|
+
this.advance();
|
|
1947
|
+
return false;
|
|
1948
|
+
}
|
|
1949
|
+
if (t.value === "null") {
|
|
1950
|
+
this.advance();
|
|
1951
|
+
return null;
|
|
1952
|
+
}
|
|
1953
|
+
if (t.value === "undefined") {
|
|
1954
|
+
this.advance();
|
|
1955
|
+
return void 0;
|
|
1956
|
+
}
|
|
1957
|
+
return this.resolveClosureVariable();
|
|
1958
|
+
}
|
|
1959
|
+
if (t.type === "operator" && t.value === "-") {
|
|
1960
|
+
this.advance();
|
|
1961
|
+
const next = this.peek();
|
|
1962
|
+
if (next?.type === "number") {
|
|
1963
|
+
this.advance();
|
|
1964
|
+
return -Number(next.value);
|
|
1965
|
+
}
|
|
1966
|
+
return PARSE_FAILED;
|
|
1967
|
+
}
|
|
1968
|
+
return PARSE_FAILED;
|
|
1969
|
+
}
|
|
1970
|
+
/**
|
|
1971
|
+
* Attempt to resolve a closure variable by invoking the original function
|
|
1972
|
+
* with a recording Proxy and inspecting what values it compares against.
|
|
1973
|
+
*
|
|
1974
|
+
* This handles the common pattern:
|
|
1975
|
+
* ```ts
|
|
1976
|
+
* const userId = auth.userId;
|
|
1977
|
+
* orders.filter(o => o.requestedBy === userId)
|
|
1978
|
+
* ```
|
|
1979
|
+
*
|
|
1980
|
+
* The Proxy captures property accesses on the parameter and we can then
|
|
1981
|
+
* extract the comparison value from the function's behavior. However,
|
|
1982
|
+
* this approach has limitations — if the function throws, has side effects,
|
|
1983
|
+
* or uses the variable in a non-comparison context, we fall back to JS.
|
|
1984
|
+
*/
|
|
1985
|
+
resolveClosureVariable() {
|
|
1986
|
+
const identToken = this.advance();
|
|
1987
|
+
let closureExpr = identToken.value;
|
|
1988
|
+
while (this.match("dot") && this.tokens[this.pos + 1]?.type === "identifier") {
|
|
1989
|
+
this.advance();
|
|
1990
|
+
closureExpr += "." + this.advance().value;
|
|
1991
|
+
}
|
|
1992
|
+
try {
|
|
1993
|
+
const MARKER = /* @__PURE__ */ Symbol("field_access_marker");
|
|
1994
|
+
const accessed = [];
|
|
1995
|
+
const proxy = new Proxy(
|
|
1996
|
+
{},
|
|
1997
|
+
{
|
|
1998
|
+
get(_, prop) {
|
|
1999
|
+
accessed.push(prop);
|
|
2000
|
+
return new Proxy(() => MARKER, {
|
|
2001
|
+
get(_2, nestedProp) {
|
|
2002
|
+
accessed.push(nestedProp);
|
|
2003
|
+
return MARKER;
|
|
2004
|
+
}
|
|
2005
|
+
});
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
);
|
|
2009
|
+
void proxy;
|
|
2010
|
+
return PARSE_FAILED;
|
|
2011
|
+
} catch {
|
|
2012
|
+
return PARSE_FAILED;
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
/**
|
|
2016
|
+
* Look ahead to check if the next tokens form `.includes(`.
|
|
2017
|
+
* Used to disambiguate `o.field.includes(...)` from `o.field.nested`.
|
|
2018
|
+
*/
|
|
2019
|
+
lookAheadForIncludes() {
|
|
2020
|
+
return this.tokens[this.pos]?.type === "dot" && this.tokens[this.pos + 1]?.type === "identifier" && this.tokens[this.pos + 1]?.value === "includes" && this.tokens[this.pos + 2]?.type === "lparen";
|
|
2021
|
+
}
|
|
2022
|
+
};
|
|
2023
|
+
JS_TO_SQL_OP = {
|
|
2024
|
+
"===": "=",
|
|
2025
|
+
"==": "=",
|
|
2026
|
+
"!==": "!=",
|
|
2027
|
+
"!=": "!=",
|
|
2028
|
+
"<": "<",
|
|
2029
|
+
">": ">",
|
|
2030
|
+
"<=": "<=",
|
|
2031
|
+
">=": ">="
|
|
2032
|
+
};
|
|
2033
|
+
PARSE_FAILED = /* @__PURE__ */ Symbol("PARSE_FAILED");
|
|
2034
|
+
}
|
|
2035
|
+
});
|
|
2036
|
+
|
|
2037
|
+
// src/db/query.ts
|
|
2038
|
+
function extractFieldName(accessor) {
|
|
2039
|
+
const source = accessor.toString();
|
|
2040
|
+
const match = source.match(
|
|
2041
|
+
/^\s*\(?([a-zA-Z_$][a-zA-Z0-9_$]*)\)?\s*=>\s*\1\.([a-zA-Z_$][a-zA-Z0-9_$]*)\s*$/
|
|
2042
|
+
);
|
|
2043
|
+
return match?.[2] ?? null;
|
|
2044
|
+
}
|
|
2045
|
+
var Query;
|
|
2046
|
+
var init_query = __esm({
|
|
2047
|
+
"src/db/query.ts"() {
|
|
2048
|
+
"use strict";
|
|
2049
|
+
init_predicate();
|
|
2050
|
+
init_sql();
|
|
2051
|
+
Query = class _Query {
|
|
2052
|
+
_predicates;
|
|
2053
|
+
_sortAccessor;
|
|
2054
|
+
_reversed;
|
|
2055
|
+
_limit;
|
|
2056
|
+
_offset;
|
|
2057
|
+
_config;
|
|
2058
|
+
constructor(config, options) {
|
|
2059
|
+
this._config = config;
|
|
2060
|
+
this._predicates = options?.predicates ?? [];
|
|
2061
|
+
this._sortAccessor = options?.sortAccessor;
|
|
2062
|
+
this._reversed = options?.reversed ?? false;
|
|
2063
|
+
this._limit = options?.limit;
|
|
2064
|
+
this._offset = options?.offset;
|
|
2065
|
+
}
|
|
2066
|
+
_clone(overrides) {
|
|
2067
|
+
return new _Query(this._config, {
|
|
2068
|
+
predicates: overrides.predicates ?? this._predicates,
|
|
2069
|
+
sortAccessor: overrides.sortAccessor ?? this._sortAccessor,
|
|
2070
|
+
reversed: overrides.reversed ?? this._reversed,
|
|
2071
|
+
limit: overrides.limit ?? this._limit,
|
|
2072
|
+
offset: overrides.offset ?? this._offset
|
|
2073
|
+
});
|
|
2074
|
+
}
|
|
2075
|
+
// -------------------------------------------------------------------------
|
|
2076
|
+
// Chain methods
|
|
2077
|
+
// -------------------------------------------------------------------------
|
|
2078
|
+
filter(predicate) {
|
|
2079
|
+
return this._clone({ predicates: [...this._predicates, predicate] });
|
|
2080
|
+
}
|
|
2081
|
+
sortBy(accessor) {
|
|
2082
|
+
return this._clone({ sortAccessor: accessor });
|
|
2083
|
+
}
|
|
2084
|
+
reverse() {
|
|
2085
|
+
return this._clone({ reversed: !this._reversed });
|
|
2086
|
+
}
|
|
2087
|
+
take(n) {
|
|
2088
|
+
return this._clone({ limit: n });
|
|
2089
|
+
}
|
|
2090
|
+
skip(n) {
|
|
2091
|
+
return this._clone({ offset: n });
|
|
2092
|
+
}
|
|
2093
|
+
// -------------------------------------------------------------------------
|
|
2094
|
+
// Terminal methods
|
|
2095
|
+
// -------------------------------------------------------------------------
|
|
2096
|
+
async first() {
|
|
2097
|
+
const rows = await this._clone({ limit: 1 })._execute();
|
|
2098
|
+
return rows[0] ?? null;
|
|
2099
|
+
}
|
|
2100
|
+
async last() {
|
|
2101
|
+
const rows = await this._clone({ limit: 1, reversed: !this._reversed })._execute();
|
|
2102
|
+
return rows[0] ?? null;
|
|
2103
|
+
}
|
|
2104
|
+
async count() {
|
|
2105
|
+
const compiled = this._compilePredicates();
|
|
2106
|
+
if (compiled.allSql) {
|
|
2107
|
+
const query = buildCount(
|
|
2108
|
+
this._config.tableName,
|
|
2109
|
+
compiled.sqlWhere || void 0
|
|
2110
|
+
);
|
|
2111
|
+
const results = await this._config.executeBatch([query]);
|
|
2112
|
+
const row = results[0]?.rows[0];
|
|
2113
|
+
return row?.count ?? 0;
|
|
2114
|
+
}
|
|
2115
|
+
const rows = await this._fetchAndFilterInJs(compiled);
|
|
2116
|
+
return rows.length;
|
|
2117
|
+
}
|
|
2118
|
+
async some() {
|
|
2119
|
+
const compiled = this._compilePredicates();
|
|
2120
|
+
if (compiled.allSql) {
|
|
2121
|
+
const query = buildExists(
|
|
2122
|
+
this._config.tableName,
|
|
2123
|
+
compiled.sqlWhere || void 0
|
|
2124
|
+
);
|
|
2125
|
+
const results = await this._config.executeBatch([query]);
|
|
2126
|
+
const row = results[0]?.rows[0];
|
|
2127
|
+
return row?.result === 1;
|
|
2128
|
+
}
|
|
2129
|
+
const rows = await this._fetchAndFilterInJs(compiled);
|
|
2130
|
+
return rows.length > 0;
|
|
2131
|
+
}
|
|
2132
|
+
async every() {
|
|
2133
|
+
const compiled = this._compilePredicates();
|
|
2134
|
+
if (compiled.allSql && compiled.sqlWhere) {
|
|
2135
|
+
const query = buildExists(
|
|
2136
|
+
this._config.tableName,
|
|
2137
|
+
`NOT (${compiled.sqlWhere})`,
|
|
2138
|
+
void 0,
|
|
2139
|
+
true
|
|
2140
|
+
);
|
|
2141
|
+
const results = await this._config.executeBatch([query]);
|
|
2142
|
+
const row = results[0]?.rows[0];
|
|
2143
|
+
return row?.result === 1;
|
|
2144
|
+
}
|
|
2145
|
+
if (this._predicates.length === 0) return true;
|
|
2146
|
+
const allRows = await this._fetchAllRows();
|
|
2147
|
+
return allRows.every(
|
|
2148
|
+
(row) => this._predicates.every((pred) => pred(row))
|
|
2149
|
+
);
|
|
2150
|
+
}
|
|
2151
|
+
async min(accessor) {
|
|
2152
|
+
return this.sortBy(accessor).first();
|
|
2153
|
+
}
|
|
2154
|
+
async max(accessor) {
|
|
2155
|
+
return this.sortBy(accessor).reverse().first();
|
|
2156
|
+
}
|
|
2157
|
+
async groupBy(accessor) {
|
|
2158
|
+
const rows = await this._execute();
|
|
2159
|
+
const map = /* @__PURE__ */ new Map();
|
|
2160
|
+
for (const row of rows) {
|
|
2161
|
+
const key = accessor(row);
|
|
2162
|
+
const group = map.get(key);
|
|
2163
|
+
if (group) {
|
|
2164
|
+
group.push(row);
|
|
2165
|
+
} else {
|
|
2166
|
+
map.set(key, [row]);
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
return map;
|
|
2170
|
+
}
|
|
2171
|
+
// -------------------------------------------------------------------------
|
|
2172
|
+
// PromiseLike
|
|
2173
|
+
// -------------------------------------------------------------------------
|
|
2174
|
+
then(onfulfilled, onrejected) {
|
|
2175
|
+
return this._execute().then(onfulfilled, onrejected);
|
|
2176
|
+
}
|
|
2177
|
+
// -------------------------------------------------------------------------
|
|
2178
|
+
// Execution internals
|
|
2179
|
+
// -------------------------------------------------------------------------
|
|
2180
|
+
async _execute() {
|
|
2181
|
+
const compiled = this._compilePredicates();
|
|
2182
|
+
if (compiled.allSql) {
|
|
2183
|
+
const sortField = this._sortAccessor ? extractFieldName(this._sortAccessor) : void 0;
|
|
2184
|
+
const query = buildSelect(this._config.tableName, {
|
|
2185
|
+
where: compiled.sqlWhere || void 0,
|
|
2186
|
+
orderBy: sortField ?? void 0,
|
|
2187
|
+
desc: this._reversed,
|
|
2188
|
+
limit: this._limit,
|
|
2189
|
+
offset: this._offset
|
|
2190
|
+
});
|
|
2191
|
+
const results = await this._config.executeBatch([query]);
|
|
2192
|
+
return results[0].rows.map(
|
|
2193
|
+
(row) => deserializeRow(
|
|
2194
|
+
row,
|
|
2195
|
+
this._config.columns
|
|
2196
|
+
)
|
|
2197
|
+
);
|
|
2198
|
+
}
|
|
2199
|
+
let rows = await this._fetchAndFilterInJs(compiled);
|
|
2200
|
+
if (this._sortAccessor) {
|
|
2201
|
+
const accessor = this._sortAccessor;
|
|
2202
|
+
rows.sort((a, b) => {
|
|
2203
|
+
const aVal = accessor(a);
|
|
2204
|
+
const bVal = accessor(b);
|
|
2205
|
+
if (aVal < bVal) return this._reversed ? 1 : -1;
|
|
2206
|
+
if (aVal > bVal) return this._reversed ? -1 : 1;
|
|
2207
|
+
return 0;
|
|
2208
|
+
});
|
|
2209
|
+
}
|
|
2210
|
+
if (this._offset != null || this._limit != null) {
|
|
2211
|
+
const start = this._offset ?? 0;
|
|
2212
|
+
const end = this._limit != null ? start + this._limit : void 0;
|
|
2213
|
+
rows = rows.slice(start, end);
|
|
2214
|
+
}
|
|
2215
|
+
return rows;
|
|
2216
|
+
}
|
|
2217
|
+
_compilePredicates() {
|
|
2218
|
+
if (this._predicates.length === 0) {
|
|
2219
|
+
return { allSql: true, sqlWhere: "", compiled: [] };
|
|
2220
|
+
}
|
|
2221
|
+
const compiled = this._predicates.map((pred) => compilePredicate(pred));
|
|
2222
|
+
const allSql = compiled.every((c) => c.type === "sql");
|
|
2223
|
+
let sqlWhere = "";
|
|
2224
|
+
if (allSql) {
|
|
2225
|
+
sqlWhere = compiled.map((c) => c.where).join(" AND ");
|
|
2226
|
+
}
|
|
2227
|
+
return { allSql, sqlWhere, compiled };
|
|
2228
|
+
}
|
|
2229
|
+
async _fetchAndFilterInJs(compiled) {
|
|
2230
|
+
const allRows = await this._fetchAllRows();
|
|
2231
|
+
if (compiled.compiled.some((c) => c.type === "js")) {
|
|
2232
|
+
console.warn(
|
|
2233
|
+
`[mindstudio] Filter on ${this._config.tableName} could not be compiled to SQL \u2014 scanning ${allRows.length} rows in JS`
|
|
2234
|
+
);
|
|
2235
|
+
}
|
|
2236
|
+
return allRows.filter(
|
|
2237
|
+
(row) => this._predicates.every((pred) => pred(row))
|
|
2238
|
+
);
|
|
2239
|
+
}
|
|
2240
|
+
async _fetchAllRows() {
|
|
2241
|
+
const query = buildSelect(this._config.tableName);
|
|
2242
|
+
const results = await this._config.executeBatch([query]);
|
|
2243
|
+
return results[0].rows.map(
|
|
2244
|
+
(row) => deserializeRow(row, this._config.columns)
|
|
2245
|
+
);
|
|
2246
|
+
}
|
|
2247
|
+
};
|
|
2248
|
+
}
|
|
2249
|
+
});
|
|
2250
|
+
|
|
2251
|
+
// src/db/table.ts
|
|
2252
|
+
var Table;
|
|
2253
|
+
var init_table = __esm({
|
|
2254
|
+
"src/db/table.ts"() {
|
|
2255
|
+
"use strict";
|
|
2256
|
+
init_query();
|
|
2257
|
+
init_predicate();
|
|
2258
|
+
init_sql();
|
|
2259
|
+
Table = class {
|
|
2260
|
+
/** @internal */
|
|
2261
|
+
_config;
|
|
2262
|
+
constructor(config) {
|
|
2263
|
+
this._config = config;
|
|
2264
|
+
}
|
|
2265
|
+
// -------------------------------------------------------------------------
|
|
2266
|
+
// Reads — direct
|
|
2267
|
+
// -------------------------------------------------------------------------
|
|
2268
|
+
async get(id) {
|
|
2269
|
+
const query = buildSelect(this._config.tableName, {
|
|
2270
|
+
where: `id = ?`,
|
|
2271
|
+
whereParams: [id],
|
|
2272
|
+
limit: 1
|
|
2273
|
+
});
|
|
2274
|
+
const results = await this._config.executeBatch([query]);
|
|
2275
|
+
if (results[0].rows.length === 0) return null;
|
|
2276
|
+
return deserializeRow(
|
|
2277
|
+
results[0].rows[0],
|
|
2278
|
+
this._config.columns
|
|
2279
|
+
);
|
|
2280
|
+
}
|
|
2281
|
+
async findOne(predicate) {
|
|
2282
|
+
return this.filter(predicate).first();
|
|
2283
|
+
}
|
|
2284
|
+
async count(predicate) {
|
|
2285
|
+
if (predicate) return this.filter(predicate).count();
|
|
2286
|
+
const query = buildCount(this._config.tableName);
|
|
2287
|
+
const results = await this._config.executeBatch([query]);
|
|
2288
|
+
const row = results[0]?.rows[0];
|
|
2289
|
+
return row?.count ?? 0;
|
|
2290
|
+
}
|
|
2291
|
+
async some(predicate) {
|
|
2292
|
+
return this.filter(predicate).some();
|
|
2293
|
+
}
|
|
2294
|
+
async every(predicate) {
|
|
2295
|
+
return this.filter(predicate).every();
|
|
2296
|
+
}
|
|
2297
|
+
async isEmpty() {
|
|
2298
|
+
const query = buildExists(this._config.tableName, void 0, void 0, true);
|
|
2299
|
+
const results = await this._config.executeBatch([query]);
|
|
2300
|
+
const row = results[0]?.rows[0];
|
|
2301
|
+
return row?.result === 1;
|
|
2302
|
+
}
|
|
2303
|
+
async min(accessor) {
|
|
2304
|
+
return this.sortBy(accessor).first();
|
|
2305
|
+
}
|
|
2306
|
+
async max(accessor) {
|
|
2307
|
+
return this.sortBy(accessor).reverse().first();
|
|
2308
|
+
}
|
|
2309
|
+
async groupBy(accessor) {
|
|
2310
|
+
return new Query(this._config).groupBy(accessor);
|
|
2311
|
+
}
|
|
2312
|
+
// -------------------------------------------------------------------------
|
|
2313
|
+
// Reads — chainable
|
|
2314
|
+
// -------------------------------------------------------------------------
|
|
2315
|
+
filter(predicate) {
|
|
2316
|
+
return new Query(this._config).filter(predicate);
|
|
2317
|
+
}
|
|
2318
|
+
sortBy(accessor) {
|
|
2319
|
+
return new Query(this._config).sortBy(accessor);
|
|
2320
|
+
}
|
|
2321
|
+
async push(data) {
|
|
2322
|
+
const isArray = Array.isArray(data);
|
|
2323
|
+
const items = isArray ? data : [data];
|
|
2324
|
+
const queries = items.map(
|
|
2325
|
+
(item) => buildInsert(
|
|
2326
|
+
this._config.tableName,
|
|
2327
|
+
item,
|
|
2328
|
+
this._config.columns
|
|
2329
|
+
)
|
|
2330
|
+
);
|
|
2331
|
+
const results = await this._config.executeBatch(queries);
|
|
2332
|
+
const rows = results.map((r) => {
|
|
2333
|
+
if (r.rows.length > 0) {
|
|
2334
|
+
return deserializeRow(
|
|
2335
|
+
r.rows[0],
|
|
2336
|
+
this._config.columns
|
|
2337
|
+
);
|
|
2338
|
+
}
|
|
2339
|
+
return void 0;
|
|
2340
|
+
});
|
|
2341
|
+
return isArray ? rows : rows[0];
|
|
2342
|
+
}
|
|
2343
|
+
/**
|
|
2344
|
+
* Update a row by ID. Only the provided fields are changed.
|
|
2345
|
+
* Returns the updated row via `UPDATE ... RETURNING *`.
|
|
2346
|
+
*/
|
|
2347
|
+
async update(id, data) {
|
|
2348
|
+
const query = buildUpdate(
|
|
2349
|
+
this._config.tableName,
|
|
2350
|
+
id,
|
|
2351
|
+
data,
|
|
2352
|
+
this._config.columns
|
|
2353
|
+
);
|
|
2354
|
+
const results = await this._config.executeBatch([query]);
|
|
2355
|
+
return deserializeRow(
|
|
2356
|
+
results[0].rows[0],
|
|
2357
|
+
this._config.columns
|
|
2358
|
+
);
|
|
2359
|
+
}
|
|
2360
|
+
async remove(id) {
|
|
2361
|
+
const query = buildDelete(this._config.tableName, `id = ?`, [id]);
|
|
2362
|
+
await this._config.executeBatch([query]);
|
|
2363
|
+
}
|
|
2364
|
+
/**
|
|
2365
|
+
* Remove all rows matching a predicate. Returns the count removed.
|
|
2366
|
+
*/
|
|
2367
|
+
async removeAll(predicate) {
|
|
2368
|
+
const compiled = compilePredicate(predicate);
|
|
2369
|
+
if (compiled.type === "sql") {
|
|
2370
|
+
const query = buildDelete(this._config.tableName, compiled.where);
|
|
2371
|
+
const results = await this._config.executeBatch([query]);
|
|
2372
|
+
return results[0].changes;
|
|
2373
|
+
}
|
|
2374
|
+
console.warn(
|
|
2375
|
+
`[mindstudio] removeAll predicate on ${this._config.tableName} could not be compiled to SQL \u2014 fetching all rows first`
|
|
2376
|
+
);
|
|
2377
|
+
const allQuery = buildSelect(this._config.tableName);
|
|
2378
|
+
const allResults = await this._config.executeBatch([allQuery]);
|
|
2379
|
+
const allRows = allResults[0].rows.map(
|
|
2380
|
+
(r) => deserializeRow(
|
|
2381
|
+
r,
|
|
2382
|
+
this._config.columns
|
|
2383
|
+
)
|
|
2384
|
+
);
|
|
2385
|
+
const matching = allRows.filter((row) => predicate(row));
|
|
2386
|
+
if (matching.length === 0) return 0;
|
|
2387
|
+
const deleteQueries = matching.filter((row) => row.id).map((row) => buildDelete(this._config.tableName, `id = ?`, [row.id]));
|
|
2388
|
+
if (deleteQueries.length > 0) {
|
|
2389
|
+
await this._config.executeBatch(deleteQueries);
|
|
2390
|
+
}
|
|
2391
|
+
return matching.length;
|
|
2392
|
+
}
|
|
2393
|
+
async clear() {
|
|
2394
|
+
const query = buildDelete(this._config.tableName);
|
|
2395
|
+
await this._config.executeBatch([query]);
|
|
2396
|
+
}
|
|
2397
|
+
};
|
|
2398
|
+
}
|
|
2399
|
+
});
|
|
2400
|
+
|
|
2401
|
+
// src/db/index.ts
|
|
2402
|
+
function createDb(databases, executeBatch) {
|
|
2403
|
+
return {
|
|
2404
|
+
defineTable(name, options) {
|
|
2405
|
+
const resolved = resolveTable(databases, name, options?.database);
|
|
2406
|
+
const config = {
|
|
2407
|
+
databaseId: resolved.databaseId,
|
|
2408
|
+
tableName: name,
|
|
2409
|
+
columns: resolved.columns,
|
|
2410
|
+
executeBatch: (queries) => executeBatch(resolved.databaseId, queries)
|
|
2411
|
+
};
|
|
2412
|
+
return new Table(config);
|
|
2413
|
+
},
|
|
2414
|
+
// --- Time helpers ---
|
|
2415
|
+
// Pure JS, no platform dependency. All timestamps are unix ms.
|
|
2416
|
+
now: () => Date.now(),
|
|
2417
|
+
days: (n) => n * 864e5,
|
|
2418
|
+
hours: (n) => n * 36e5,
|
|
2419
|
+
minutes: (n) => n * 6e4,
|
|
2420
|
+
ago: (ms) => Date.now() - ms,
|
|
2421
|
+
fromNow: (ms) => Date.now() + ms
|
|
2422
|
+
};
|
|
2423
|
+
}
|
|
2424
|
+
function resolveTable(databases, tableName, databaseHint) {
|
|
2425
|
+
if (databases.length === 0) {
|
|
2426
|
+
throw new MindStudioError(
|
|
2427
|
+
`No databases found in app context. Make sure the app has at least one database configured.`,
|
|
2428
|
+
"no_databases",
|
|
2429
|
+
400
|
|
2430
|
+
);
|
|
2431
|
+
}
|
|
2432
|
+
if (databaseHint) {
|
|
2433
|
+
const targetDb = databases.find(
|
|
2434
|
+
(db) => db.id === databaseHint || db.name === databaseHint
|
|
2435
|
+
);
|
|
2436
|
+
if (!targetDb) {
|
|
2437
|
+
const available = databases.map((db) => db.name || db.id).join(", ");
|
|
2438
|
+
throw new MindStudioError(
|
|
2439
|
+
`Database "${databaseHint}" not found. Available databases: ${available}`,
|
|
2440
|
+
"database_not_found",
|
|
2441
|
+
400
|
|
2442
|
+
);
|
|
2443
|
+
}
|
|
2444
|
+
const table = targetDb.tables.find((t) => t.name === tableName);
|
|
2445
|
+
if (!table) {
|
|
2446
|
+
const available = targetDb.tables.map((t) => t.name).join(", ");
|
|
2447
|
+
throw new MindStudioError(
|
|
2448
|
+
`Table "${tableName}" not found in database "${databaseHint}". Available tables: ${available || "(none)"}`,
|
|
2449
|
+
"table_not_found",
|
|
2450
|
+
400
|
|
2451
|
+
);
|
|
2452
|
+
}
|
|
2453
|
+
return { databaseId: targetDb.id, columns: table.schema };
|
|
2454
|
+
}
|
|
2455
|
+
for (const db of databases) {
|
|
2456
|
+
const table = db.tables.find((t) => t.name === tableName);
|
|
2457
|
+
if (table) {
|
|
2458
|
+
return {
|
|
2459
|
+
databaseId: db.id,
|
|
2460
|
+
columns: table.schema
|
|
2461
|
+
};
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
const availableTables = databases.flatMap((db) => db.tables.map((t) => t.name)).join(", ");
|
|
2465
|
+
throw new MindStudioError(
|
|
2466
|
+
`Table "${tableName}" not found in app databases. Available tables: ${availableTables || "(none)"}`,
|
|
2467
|
+
"table_not_found",
|
|
2468
|
+
400
|
|
2469
|
+
);
|
|
2470
|
+
}
|
|
2471
|
+
var init_db = __esm({
|
|
2472
|
+
"src/db/index.ts"() {
|
|
2473
|
+
"use strict";
|
|
2474
|
+
init_errors();
|
|
2475
|
+
init_table();
|
|
2476
|
+
init_table();
|
|
2477
|
+
}
|
|
2478
|
+
});
|
|
2479
|
+
|
|
1327
2480
|
// src/generated/steps.ts
|
|
1328
2481
|
var steps_exports = {};
|
|
1329
2482
|
__export(steps_exports, {
|
|
@@ -1361,6 +2514,9 @@ function applyStepMethods(AgentClass) {
|
|
|
1361
2514
|
proto.captureThumbnail = function(step, options) {
|
|
1362
2515
|
return this.executeStep("captureThumbnail", step, options);
|
|
1363
2516
|
};
|
|
2517
|
+
proto.checkAppRole = function(step, options) {
|
|
2518
|
+
return this.executeStep("checkAppRole", step, options);
|
|
2519
|
+
};
|
|
1364
2520
|
proto.codaCreateUpdatePage = function(step, options) {
|
|
1365
2521
|
return this.executeStep("codaCreateUpdatePage", step, options);
|
|
1366
2522
|
};
|
|
@@ -1610,6 +2766,9 @@ function applyStepMethods(AgentClass) {
|
|
|
1610
2766
|
proto.postToZapier = function(step, options) {
|
|
1611
2767
|
return this.executeStep("postToZapier", step, options);
|
|
1612
2768
|
};
|
|
2769
|
+
proto.queryAppDatabase = function(step, options) {
|
|
2770
|
+
return this.executeStep("queryAppDatabase", step, options);
|
|
2771
|
+
};
|
|
1613
2772
|
proto.queryDataSource = function(step, options) {
|
|
1614
2773
|
return this.executeStep("queryDataSource", step, options);
|
|
1615
2774
|
};
|
|
@@ -1836,6 +2995,8 @@ var init_client = __esm({
|
|
|
1836
2995
|
init_errors();
|
|
1837
2996
|
init_rate_limit();
|
|
1838
2997
|
init_config();
|
|
2998
|
+
init_auth();
|
|
2999
|
+
init_db();
|
|
1839
3000
|
init_steps();
|
|
1840
3001
|
DEFAULT_BASE_URL = "https://v1.mindstudio-api.com";
|
|
1841
3002
|
DEFAULT_MAX_RETRIES = 3;
|
|
@@ -1846,17 +3007,46 @@ var init_client = __esm({
|
|
|
1846
3007
|
_reuseThreadId;
|
|
1847
3008
|
/** @internal */
|
|
1848
3009
|
_threadId;
|
|
3010
|
+
// ---- App context (db + auth) ----
|
|
3011
|
+
/**
|
|
3012
|
+
* @internal App ID for context resolution. Resolved from:
|
|
3013
|
+
* constructor appId → MINDSTUDIO_APP_ID env → sandbox globals →
|
|
3014
|
+
* auto-detected from first executeStep response header.
|
|
3015
|
+
*/
|
|
3016
|
+
_appId;
|
|
3017
|
+
/**
|
|
3018
|
+
* @internal Cached app context (auth + databases). Populated by
|
|
3019
|
+
* ensureContext() and cached for the lifetime of the instance.
|
|
3020
|
+
*/
|
|
3021
|
+
_context;
|
|
3022
|
+
/**
|
|
3023
|
+
* @internal Deduplication promise for ensureContext(). Ensures only one
|
|
3024
|
+
* context fetch is in-flight at a time, even if multiple db/auth
|
|
3025
|
+
* operations trigger it concurrently.
|
|
3026
|
+
*/
|
|
3027
|
+
_contextPromise;
|
|
3028
|
+
/** @internal Cached AuthContext instance, created during context hydration. */
|
|
3029
|
+
_auth;
|
|
3030
|
+
/** @internal Cached Db namespace instance, created during context hydration. */
|
|
3031
|
+
_db;
|
|
3032
|
+
/** @internal Auth type — 'internal' for CALLBACK_TOKEN (managed mode), 'apiKey' otherwise. */
|
|
3033
|
+
_authType;
|
|
1849
3034
|
constructor(options = {}) {
|
|
1850
3035
|
const config = loadConfig();
|
|
1851
3036
|
const { token, authType } = resolveToken(options.apiKey, config);
|
|
1852
3037
|
const baseUrl = options.baseUrl ?? process.env.MINDSTUDIO_BASE_URL ?? process.env.REMOTE_HOSTNAME ?? config.baseUrl ?? DEFAULT_BASE_URL;
|
|
1853
3038
|
this._reuseThreadId = options.reuseThreadId ?? /^(true|1)$/i.test(process.env.MINDSTUDIO_REUSE_THREAD_ID ?? "");
|
|
3039
|
+
this._appId = options.appId ?? process.env.MINDSTUDIO_APP_ID ?? void 0;
|
|
3040
|
+
this._authType = authType;
|
|
1854
3041
|
this._httpConfig = {
|
|
1855
3042
|
baseUrl,
|
|
1856
3043
|
token,
|
|
1857
3044
|
rateLimiter: new RateLimiter(authType),
|
|
1858
3045
|
maxRetries: options.maxRetries ?? DEFAULT_MAX_RETRIES
|
|
1859
3046
|
};
|
|
3047
|
+
if (authType === "internal") {
|
|
3048
|
+
this._trySandboxHydration();
|
|
3049
|
+
}
|
|
1860
3050
|
}
|
|
1861
3051
|
/**
|
|
1862
3052
|
* Execute any step by its type name. This is the low-level method that all
|
|
@@ -1895,6 +3085,10 @@ var init_client = __esm({
|
|
|
1895
3085
|
if (this._reuseThreadId && returnedThreadId) {
|
|
1896
3086
|
this._threadId = returnedThreadId;
|
|
1897
3087
|
}
|
|
3088
|
+
const returnedAppId = headers.get("x-mindstudio-app-id");
|
|
3089
|
+
if (!this._appId && returnedAppId) {
|
|
3090
|
+
this._appId = returnedAppId;
|
|
3091
|
+
}
|
|
1898
3092
|
const remaining = headers.get("x-ratelimit-remaining");
|
|
1899
3093
|
const billingCost = headers.get("x-mindstudio-billing-cost");
|
|
1900
3094
|
const billingEvents = headers.get("x-mindstudio-billing-events");
|
|
@@ -2161,6 +3355,299 @@ var init_client = __esm({
|
|
|
2161
3355
|
return data;
|
|
2162
3356
|
}
|
|
2163
3357
|
// -------------------------------------------------------------------------
|
|
3358
|
+
// db + auth namespaces
|
|
3359
|
+
// -------------------------------------------------------------------------
|
|
3360
|
+
/**
|
|
3361
|
+
* The `auth` namespace — synchronous role-based access control.
|
|
3362
|
+
*
|
|
3363
|
+
* Provides the current user's identity and roles. All methods are
|
|
3364
|
+
* synchronous since the role map is preloaded during context hydration.
|
|
3365
|
+
*
|
|
3366
|
+
* **Important**: Context must be hydrated before accessing `auth`.
|
|
3367
|
+
* - Inside the MindStudio sandbox: automatic (populated from globals)
|
|
3368
|
+
* - Outside the sandbox: call `await agent.ensureContext()` first,
|
|
3369
|
+
* or access `auth` after any `db` operation (which auto-hydrates)
|
|
3370
|
+
*
|
|
3371
|
+
* @throws {MindStudioError} if context has not been hydrated yet
|
|
3372
|
+
*
|
|
3373
|
+
* @example
|
|
3374
|
+
* ```ts
|
|
3375
|
+
* await agent.ensureContext();
|
|
3376
|
+
* agent.auth.requireRole(Roles.admin);
|
|
3377
|
+
* const admins = agent.auth.getUsersByRole(Roles.admin);
|
|
3378
|
+
* ```
|
|
3379
|
+
*/
|
|
3380
|
+
get auth() {
|
|
3381
|
+
if (!this._auth) {
|
|
3382
|
+
this._trySandboxHydration();
|
|
3383
|
+
}
|
|
3384
|
+
if (!this._auth) {
|
|
3385
|
+
throw new MindStudioError(
|
|
3386
|
+
"Auth context not yet loaded. Call `await agent.ensureContext()` or perform any db operation first (which auto-hydrates context). Inside the MindStudio sandbox, context is loaded automatically.",
|
|
3387
|
+
"context_not_loaded",
|
|
3388
|
+
400
|
|
3389
|
+
);
|
|
3390
|
+
}
|
|
3391
|
+
return this._auth;
|
|
3392
|
+
}
|
|
3393
|
+
/**
|
|
3394
|
+
* The `db` namespace — chainable collection API over managed databases.
|
|
3395
|
+
*
|
|
3396
|
+
* Use `db.defineTable<T>(name)` to get a typed Table<T>, then call
|
|
3397
|
+
* collection methods (filter, sortBy, push, update, etc.) on it.
|
|
3398
|
+
*
|
|
3399
|
+
* Context is auto-hydrated on first query execution — you can safely
|
|
3400
|
+
* call `defineTable()` at module scope without triggering any HTTP.
|
|
3401
|
+
*
|
|
3402
|
+
* @example
|
|
3403
|
+
* ```ts
|
|
3404
|
+
* const Orders = agent.db.defineTable<Order>('orders');
|
|
3405
|
+
* const active = await Orders.filter(o => o.status === 'active').take(10);
|
|
3406
|
+
* ```
|
|
3407
|
+
*/
|
|
3408
|
+
get db() {
|
|
3409
|
+
if (!this._db) {
|
|
3410
|
+
this._trySandboxHydration();
|
|
3411
|
+
}
|
|
3412
|
+
if (this._db) return this._db;
|
|
3413
|
+
return this._createLazyDb();
|
|
3414
|
+
}
|
|
3415
|
+
/**
|
|
3416
|
+
* Hydrate the app context (auth + database metadata). This must be
|
|
3417
|
+
* called before using `auth` synchronously. For `db`, hydration happens
|
|
3418
|
+
* automatically on first query.
|
|
3419
|
+
*
|
|
3420
|
+
* Context is fetched once and cached for the instance's lifetime.
|
|
3421
|
+
* Calling `ensureContext()` multiple times is safe (no-op after first).
|
|
3422
|
+
*
|
|
3423
|
+
* Context sources (checked in order):
|
|
3424
|
+
* 1. Sandbox globals (`globalThis.ai.auth`, `globalThis.ai.databases`)
|
|
3425
|
+
* 2. HTTP: `GET /developer/v2/helpers/app-context?appId={appId}`
|
|
3426
|
+
*
|
|
3427
|
+
* @throws {MindStudioError} if no `appId` is available
|
|
3428
|
+
*
|
|
3429
|
+
* @example
|
|
3430
|
+
* ```ts
|
|
3431
|
+
* await agent.ensureContext();
|
|
3432
|
+
* // auth is now available synchronously
|
|
3433
|
+
* agent.auth.requireRole(Roles.admin);
|
|
3434
|
+
* ```
|
|
3435
|
+
*/
|
|
3436
|
+
async ensureContext() {
|
|
3437
|
+
if (this._context) return;
|
|
3438
|
+
if (!this._contextPromise) {
|
|
3439
|
+
this._contextPromise = this._hydrateContext();
|
|
3440
|
+
}
|
|
3441
|
+
await this._contextPromise;
|
|
3442
|
+
}
|
|
3443
|
+
/**
|
|
3444
|
+
* @internal Fetch and cache app context, then create auth + db instances.
|
|
3445
|
+
*
|
|
3446
|
+
* In managed mode (CALLBACK_TOKEN), the platform resolves the app from
|
|
3447
|
+
* the token — no appId needed. With an API key, appId is required.
|
|
3448
|
+
*/
|
|
3449
|
+
async _hydrateContext() {
|
|
3450
|
+
if (!this._appId && this._authType !== "internal") {
|
|
3451
|
+
throw new MindStudioError(
|
|
3452
|
+
"No app ID available for context resolution. Pass `appId` to the constructor, set the MINDSTUDIO_APP_ID environment variable, or make a step execution call first (which auto-detects the app ID).",
|
|
3453
|
+
"missing_app_id",
|
|
3454
|
+
400
|
|
3455
|
+
);
|
|
3456
|
+
}
|
|
3457
|
+
const context = await this.getAppContext(this._appId);
|
|
3458
|
+
this._applyContext(context);
|
|
3459
|
+
}
|
|
3460
|
+
/**
|
|
3461
|
+
* @internal Apply a resolved context object — creates AuthContext and Db.
|
|
3462
|
+
* Used by both the HTTP path and sandbox hydration.
|
|
3463
|
+
*/
|
|
3464
|
+
_applyContext(context) {
|
|
3465
|
+
this._context = context;
|
|
3466
|
+
this._auth = new AuthContext(context.auth);
|
|
3467
|
+
this._db = createDb(
|
|
3468
|
+
context.databases,
|
|
3469
|
+
this._executeDbBatch.bind(this)
|
|
3470
|
+
);
|
|
3471
|
+
}
|
|
3472
|
+
/**
|
|
3473
|
+
* @internal Try to hydrate context synchronously from sandbox globals.
|
|
3474
|
+
* Called in the constructor when CALLBACK_TOKEN auth is detected.
|
|
3475
|
+
*
|
|
3476
|
+
* The MindStudio sandbox pre-populates `globalThis.ai` with:
|
|
3477
|
+
* - `ai.auth`: { userId, roleAssignments[] }
|
|
3478
|
+
* - `ai.databases`: [{ id, name, tables[] }]
|
|
3479
|
+
*/
|
|
3480
|
+
_trySandboxHydration() {
|
|
3481
|
+
const ai = globalThis.ai;
|
|
3482
|
+
if (ai?.auth && ai?.databases) {
|
|
3483
|
+
this._applyContext({
|
|
3484
|
+
auth: ai.auth,
|
|
3485
|
+
databases: ai.databases
|
|
3486
|
+
});
|
|
3487
|
+
}
|
|
3488
|
+
}
|
|
3489
|
+
/**
|
|
3490
|
+
* @internal Execute a batch of SQL queries against a managed database.
|
|
3491
|
+
* Used as the `executeBatch` callback for Table/Query instances.
|
|
3492
|
+
*
|
|
3493
|
+
* Calls `POST /_internal/v2/db/query` directly with the hook token
|
|
3494
|
+
* (raw, no Bearer prefix). All queries run on a single SQLite connection,
|
|
3495
|
+
* enabling RETURNING clauses and multi-statement batches.
|
|
3496
|
+
*/
|
|
3497
|
+
async _executeDbBatch(databaseId, queries) {
|
|
3498
|
+
const url = `${this._httpConfig.baseUrl}/_internal/v2/db/query`;
|
|
3499
|
+
const res = await fetch(url, {
|
|
3500
|
+
method: "POST",
|
|
3501
|
+
headers: {
|
|
3502
|
+
"Content-Type": "application/json",
|
|
3503
|
+
Authorization: this._httpConfig.token
|
|
3504
|
+
},
|
|
3505
|
+
body: JSON.stringify({ databaseId, queries })
|
|
3506
|
+
});
|
|
3507
|
+
if (!res.ok) {
|
|
3508
|
+
let message = `Database query failed: ${res.status} ${res.statusText}`;
|
|
3509
|
+
try {
|
|
3510
|
+
const body = await res.json();
|
|
3511
|
+
if (body.error) message = body.error;
|
|
3512
|
+
} catch {
|
|
3513
|
+
}
|
|
3514
|
+
throw new MindStudioError(message, "db_query_error", res.status);
|
|
3515
|
+
}
|
|
3516
|
+
const data = await res.json();
|
|
3517
|
+
return data.results;
|
|
3518
|
+
}
|
|
3519
|
+
/**
|
|
3520
|
+
* @internal Create a lazy Db proxy that auto-hydrates context.
|
|
3521
|
+
*
|
|
3522
|
+
* defineTable() returns Table instances immediately (no async needed).
|
|
3523
|
+
* But the Table's executeBatch callback is wrapped to call ensureContext()
|
|
3524
|
+
* before the first query, so context is fetched lazily.
|
|
3525
|
+
*/
|
|
3526
|
+
_createLazyDb() {
|
|
3527
|
+
const agent = this;
|
|
3528
|
+
return {
|
|
3529
|
+
defineTable(name, options) {
|
|
3530
|
+
const databaseHint = options?.database;
|
|
3531
|
+
return new Table({
|
|
3532
|
+
databaseId: "",
|
|
3533
|
+
tableName: name,
|
|
3534
|
+
columns: [],
|
|
3535
|
+
executeBatch: async (queries) => {
|
|
3536
|
+
await agent.ensureContext();
|
|
3537
|
+
const databases = agent._context.databases;
|
|
3538
|
+
let targetDb;
|
|
3539
|
+
if (databaseHint) {
|
|
3540
|
+
targetDb = databases.find(
|
|
3541
|
+
(d) => d.id === databaseHint || d.name === databaseHint
|
|
3542
|
+
);
|
|
3543
|
+
} else {
|
|
3544
|
+
targetDb = databases.find(
|
|
3545
|
+
(d) => d.tables.some((t) => t.name === name)
|
|
3546
|
+
);
|
|
3547
|
+
}
|
|
3548
|
+
const databaseId = targetDb?.id ?? databases[0]?.id ?? "";
|
|
3549
|
+
return agent._executeDbBatch(databaseId, queries);
|
|
3550
|
+
}
|
|
3551
|
+
});
|
|
3552
|
+
},
|
|
3553
|
+
// Time helpers work without context
|
|
3554
|
+
now: () => Date.now(),
|
|
3555
|
+
days: (n) => n * 864e5,
|
|
3556
|
+
hours: (n) => n * 36e5,
|
|
3557
|
+
minutes: (n) => n * 6e4,
|
|
3558
|
+
ago: (ms) => Date.now() - ms,
|
|
3559
|
+
fromNow: (ms) => Date.now() + ms
|
|
3560
|
+
};
|
|
3561
|
+
}
|
|
3562
|
+
// -------------------------------------------------------------------------
|
|
3563
|
+
// Helper methods — user resolution
|
|
3564
|
+
// -------------------------------------------------------------------------
|
|
3565
|
+
/**
|
|
3566
|
+
* Resolve a single user ID to display info (name, email, profile picture).
|
|
3567
|
+
*
|
|
3568
|
+
* Use this when you have a `User`-typed field value and need the person's
|
|
3569
|
+
* display name, email, or avatar. Returns null if the user ID is not found.
|
|
3570
|
+
*
|
|
3571
|
+
* Also available as a top-level import:
|
|
3572
|
+
* ```ts
|
|
3573
|
+
* import { resolveUser } from '@mindstudio-ai/agent';
|
|
3574
|
+
* ```
|
|
3575
|
+
*
|
|
3576
|
+
* @param userId - The user ID to resolve (a `User` branded string or plain UUID)
|
|
3577
|
+
* @returns Resolved user info, or null if not found
|
|
3578
|
+
*
|
|
3579
|
+
* @example
|
|
3580
|
+
* ```ts
|
|
3581
|
+
* const user = await agent.resolveUser(order.requestedBy);
|
|
3582
|
+
* if (user) {
|
|
3583
|
+
* console.log(user.name); // "Jane Smith"
|
|
3584
|
+
* console.log(user.email); // "jane@example.com"
|
|
3585
|
+
* console.log(user.profilePictureUrl); // "https://..." or null
|
|
3586
|
+
* }
|
|
3587
|
+
* ```
|
|
3588
|
+
*/
|
|
3589
|
+
async resolveUser(userId) {
|
|
3590
|
+
const { users } = await this.resolveUsers([userId]);
|
|
3591
|
+
return users[0] ?? null;
|
|
3592
|
+
}
|
|
3593
|
+
/**
|
|
3594
|
+
* Resolve multiple user IDs to display info in a single request.
|
|
3595
|
+
* Maximum 100 user IDs per request.
|
|
3596
|
+
*
|
|
3597
|
+
* Use this for batch resolution when you have multiple user references
|
|
3598
|
+
* to display (e.g. all approvers on a purchase order, all team members).
|
|
3599
|
+
*
|
|
3600
|
+
* @param userIds - Array of user IDs to resolve (max 100)
|
|
3601
|
+
* @returns Object with `users` array of resolved user info
|
|
3602
|
+
*
|
|
3603
|
+
* @example
|
|
3604
|
+
* ```ts
|
|
3605
|
+
* // Resolve all approvers at once
|
|
3606
|
+
* const approverIds = approvals.map(a => a.assignedTo);
|
|
3607
|
+
* const { users } = await agent.resolveUsers(approverIds);
|
|
3608
|
+
*
|
|
3609
|
+
* for (const u of users) {
|
|
3610
|
+
* console.log(`${u.name} (${u.email})`);
|
|
3611
|
+
* }
|
|
3612
|
+
* ```
|
|
3613
|
+
*/
|
|
3614
|
+
async resolveUsers(userIds) {
|
|
3615
|
+
const { data } = await request(
|
|
3616
|
+
this._httpConfig,
|
|
3617
|
+
"POST",
|
|
3618
|
+
"/helpers/resolve-users",
|
|
3619
|
+
{ userIds }
|
|
3620
|
+
);
|
|
3621
|
+
return data;
|
|
3622
|
+
}
|
|
3623
|
+
// -------------------------------------------------------------------------
|
|
3624
|
+
// App context
|
|
3625
|
+
// -------------------------------------------------------------------------
|
|
3626
|
+
/**
|
|
3627
|
+
* Get auth and database context for an app.
|
|
3628
|
+
*
|
|
3629
|
+
* Returns role assignments and managed database schemas. Useful for
|
|
3630
|
+
* hydrating `auth` and `db` namespaces when running outside the sandbox.
|
|
3631
|
+
*
|
|
3632
|
+
* When called with a CALLBACK_TOKEN (managed mode), `appId` is optional —
|
|
3633
|
+
* the platform resolves the app from the token. With an API key, `appId`
|
|
3634
|
+
* is required.
|
|
3635
|
+
*
|
|
3636
|
+
* ```ts
|
|
3637
|
+
* const ctx = await agent.getAppContext('your-app-id');
|
|
3638
|
+
* console.log(ctx.auth.roleAssignments, ctx.databases);
|
|
3639
|
+
* ```
|
|
3640
|
+
*/
|
|
3641
|
+
async getAppContext(appId) {
|
|
3642
|
+
const query = appId ? `?appId=${encodeURIComponent(appId)}` : "";
|
|
3643
|
+
const { data } = await request(
|
|
3644
|
+
this._httpConfig,
|
|
3645
|
+
"GET",
|
|
3646
|
+
`/helpers/app-context${query}`
|
|
3647
|
+
);
|
|
3648
|
+
return data;
|
|
3649
|
+
}
|
|
3650
|
+
// -------------------------------------------------------------------------
|
|
2164
3651
|
// Account methods
|
|
2165
3652
|
// -------------------------------------------------------------------------
|
|
2166
3653
|
/** Update the display name of the authenticated user/agent. */
|
|
@@ -2274,7 +3761,7 @@ async function startMcpServer(options) {
|
|
|
2274
3761
|
capabilities: { tools: {} },
|
|
2275
3762
|
serverInfo: {
|
|
2276
3763
|
name: "mindstudio-agent",
|
|
2277
|
-
version: "0.1.
|
|
3764
|
+
version: "0.1.10"
|
|
2278
3765
|
},
|
|
2279
3766
|
instructions: "Welcome to MindStudio \u2014 a platform with 200+ AI models, 850+ third-party integrations, and pre-built agents.\n\nGetting started:\n1. Call `listAgents` to verify your connection and see available agents.\n2. Call `changeName` to set your display name \u2014 use your name or whatever your user calls you. This is how you'll appear in MindStudio request logs.\n3. If you have a profile picture or icon, call `uploadFile` to upload it, then `changeProfilePicture` with the returned URL. This helps users identify your requests in their logs.\n4. Call `listActions` to discover all available actions.\n\nThen use the tools to generate text, images, video, audio, search the web, work with data sources, run agents, and more.\n\nImportant:\n- AI-powered actions (text generation, image generation, video, audio, etc.) cost money. Before running these, call `estimateActionCost` and confirm with the user before proceeding \u2014 unless they've explicitly told you to go ahead.\n- Not all agents from `listAgents` are configured for API use. Do not try to run an agent just because it appears in the list \u2014 it will likely fail. Only run agents the user specifically asks you to run."
|
|
2280
3767
|
});
|
|
@@ -3094,7 +4581,7 @@ function isNewerVersion(current, latest) {
|
|
|
3094
4581
|
return false;
|
|
3095
4582
|
}
|
|
3096
4583
|
async function checkForUpdate() {
|
|
3097
|
-
const currentVersion = "0.1.
|
|
4584
|
+
const currentVersion = "0.1.10";
|
|
3098
4585
|
if (!currentVersion) return null;
|
|
3099
4586
|
try {
|
|
3100
4587
|
const { loadConfig: loadConfig2, saveConfig: saveConfig2 } = await Promise.resolve().then(() => (init_config(), config_exports));
|
|
@@ -3123,7 +4610,7 @@ async function checkForUpdate() {
|
|
|
3123
4610
|
}
|
|
3124
4611
|
}
|
|
3125
4612
|
function printUpdateNotice(latestVersion) {
|
|
3126
|
-
const currentVersion = "0.1.
|
|
4613
|
+
const currentVersion = "0.1.10";
|
|
3127
4614
|
process.stderr.write(
|
|
3128
4615
|
`
|
|
3129
4616
|
${ansi.cyanBright("Update available")} ${ansi.gray(currentVersion + " \u2192")} ${ansi.cyanBold(latestVersion)}
|
|
@@ -3178,7 +4665,7 @@ async function cmdLogin(options) {
|
|
|
3178
4665
|
process.stderr.write("\n");
|
|
3179
4666
|
printLogo();
|
|
3180
4667
|
process.stderr.write("\n");
|
|
3181
|
-
const ver = "0.1.
|
|
4668
|
+
const ver = "0.1.10";
|
|
3182
4669
|
process.stderr.write(
|
|
3183
4670
|
` ${ansi.bold("MindStudio Agent")} ${ver ? " " + ansi.gray("v" + ver) : ""}
|
|
3184
4671
|
`
|
|
@@ -3261,6 +4748,9 @@ async function cmdLogin(options) {
|
|
|
3261
4748
|
` ${ansi.greenBold("\u2714")} Authenticated successfully!
|
|
3262
4749
|
${ansi.gray("Credentials saved to")} ${getConfigPath2()}
|
|
3263
4750
|
|
|
4751
|
+
${ansi.bold("Using with Claude Code?")} Run once to enable the MCP server:
|
|
4752
|
+
${ansi.cyan("claude mcp add mindstudio -- mindstudio mcp")}
|
|
4753
|
+
|
|
3264
4754
|
`
|
|
3265
4755
|
);
|
|
3266
4756
|
return;
|