@bubblelab/bubble-core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +202 -0
- package/dist/bubble-bundle.d.ts +2021 -0
- package/dist/bubble-factory.d.ts +161 -0
- package/dist/bubble-factory.d.ts.map +1 -0
- package/dist/bubble-factory.js +426 -0
- package/dist/bubble-factory.js.map +1 -0
- package/dist/bubble-flow/bubble-flow-class.d.ts +19 -0
- package/dist/bubble-flow/bubble-flow-class.d.ts.map +1 -0
- package/dist/bubble-flow/bubble-flow-class.js +23 -0
- package/dist/bubble-flow/bubble-flow-class.js.map +1 -0
- package/dist/bubble-flow/sample/data-analyst-flow.d.ts +15 -0
- package/dist/bubble-flow/sample/data-analyst-flow.d.ts.map +1 -0
- package/dist/bubble-flow/sample/data-analyst-flow.js +63 -0
- package/dist/bubble-flow/sample/data-analyst-flow.js.map +1 -0
- package/dist/bubble-flow/sample/error-ts.d.ts +23 -0
- package/dist/bubble-flow/sample/error-ts.d.ts.map +1 -0
- package/dist/bubble-flow/sample/error-ts.js +31 -0
- package/dist/bubble-flow/sample/error-ts.js.map +1 -0
- package/dist/bubble-flow/sample/sanitytest.d.ts +10 -0
- package/dist/bubble-flow/sample/sanitytest.d.ts.map +1 -0
- package/dist/bubble-flow/sample/sanitytest.js +13 -0
- package/dist/bubble-flow/sample/sanitytest.js.map +1 -0
- package/dist/bubble-flow/sample/simple-webhook-2.d.ts +19 -0
- package/dist/bubble-flow/sample/simple-webhook-2.d.ts.map +1 -0
- package/dist/bubble-flow/sample/simple-webhook-2.js +23 -0
- package/dist/bubble-flow/sample/simple-webhook-2.js.map +1 -0
- package/dist/bubble-flow/sample/simple-webhook.d.ts +10 -0
- package/dist/bubble-flow/sample/simple-webhook.d.ts.map +1 -0
- package/dist/bubble-flow/sample/simple-webhook.js +18 -0
- package/dist/bubble-flow/sample/simple-webhook.js.map +1 -0
- package/dist/bubble-flow/sample/simplified-data-analysis.flow.d.ts +29 -0
- package/dist/bubble-flow/sample/simplified-data-analysis.flow.d.ts.map +1 -0
- package/dist/bubble-flow/sample/simplified-data-analysis.flow.js +150 -0
- package/dist/bubble-flow/sample/simplified-data-analysis.flow.js.map +1 -0
- package/dist/bubble-flow/sample/slack-v0.1.d.ts +10 -0
- package/dist/bubble-flow/sample/slack-v0.1.d.ts.map +1 -0
- package/dist/bubble-flow/sample/slack-v0.1.js +59 -0
- package/dist/bubble-flow/sample/slack-v0.1.js.map +1 -0
- package/dist/bubble-flow/sample/slackagenttest.d.ts +10 -0
- package/dist/bubble-flow/sample/slackagenttest.d.ts.map +1 -0
- package/dist/bubble-flow/sample/slackagenttest.js +59 -0
- package/dist/bubble-flow/sample/slackagenttest.js.map +1 -0
- package/dist/bubble-trigger/index.d.ts +2 -0
- package/dist/bubble-trigger/index.d.ts.map +1 -0
- package/dist/bubble-trigger/index.js +2 -0
- package/dist/bubble-trigger/index.js.map +1 -0
- package/dist/bubble-trigger/types.d.ts +87 -0
- package/dist/bubble-trigger/types.d.ts.map +1 -0
- package/dist/bubble-trigger/types.js +14 -0
- package/dist/bubble-trigger/types.js.map +1 -0
- package/dist/bubbles/service-bubble/ai-agent.d.ts +428 -0
- package/dist/bubbles/service-bubble/ai-agent.d.ts.map +1 -0
- package/dist/bubbles/service-bubble/ai-agent.js +881 -0
- package/dist/bubbles/service-bubble/ai-agent.js.map +1 -0
- package/dist/bubbles/service-bubble/gmail.d.ts +3073 -0
- package/dist/bubbles/service-bubble/gmail.d.ts.map +1 -0
- package/dist/bubbles/service-bubble/gmail.js +908 -0
- package/dist/bubbles/service-bubble/gmail.js.map +1 -0
- package/dist/bubbles/service-bubble/google-calendar.d.ts +3377 -0
- package/dist/bubbles/service-bubble/google-calendar.d.ts.map +1 -0
- package/dist/bubbles/service-bubble/google-calendar.js +527 -0
- package/dist/bubbles/service-bubble/google-calendar.js.map +1 -0
- package/dist/bubbles/service-bubble/google-drive.d.ts +1152 -0
- package/dist/bubbles/service-bubble/google-drive.d.ts.map +1 -0
- package/dist/bubbles/service-bubble/google-drive.js +943 -0
- package/dist/bubbles/service-bubble/google-drive.js.map +1 -0
- package/dist/bubbles/service-bubble/google-sheets.d.ts +1811 -0
- package/dist/bubbles/service-bubble/google-sheets.d.ts.map +1 -0
- package/dist/bubbles/service-bubble/google-sheets.js +904 -0
- package/dist/bubbles/service-bubble/google-sheets.js.map +1 -0
- package/dist/bubbles/service-bubble/hello-world.d.ts +74 -0
- package/dist/bubbles/service-bubble/hello-world.d.ts.map +1 -0
- package/dist/bubbles/service-bubble/hello-world.js +67 -0
- package/dist/bubbles/service-bubble/hello-world.js.map +1 -0
- package/dist/bubbles/service-bubble/http.d.ts +134 -0
- package/dist/bubbles/service-bubble/http.d.ts.map +1 -0
- package/dist/bubbles/service-bubble/http.js +184 -0
- package/dist/bubbles/service-bubble/http.js.map +1 -0
- package/dist/bubbles/service-bubble/postgresql.d.ts +180 -0
- package/dist/bubbles/service-bubble/postgresql.d.ts.map +1 -0
- package/dist/bubbles/service-bubble/postgresql.js +448 -0
- package/dist/bubbles/service-bubble/postgresql.js.map +1 -0
- package/dist/bubbles/service-bubble/resend.d.ts +301 -0
- package/dist/bubbles/service-bubble/resend.d.ts.map +1 -0
- package/dist/bubbles/service-bubble/resend.js +253 -0
- package/dist/bubbles/service-bubble/resend.js.map +1 -0
- package/dist/bubbles/service-bubble/slack.d.ts +5869 -0
- package/dist/bubbles/service-bubble/slack.d.ts.map +1 -0
- package/dist/bubbles/service-bubble/slack.js +1536 -0
- package/dist/bubbles/service-bubble/slack.js.map +1 -0
- package/dist/bubbles/service-bubble/storage.d.ts +571 -0
- package/dist/bubbles/service-bubble/storage.d.ts.map +1 -0
- package/dist/bubbles/service-bubble/storage.js +504 -0
- package/dist/bubbles/service-bubble/storage.js.map +1 -0
- package/dist/bubbles/tool-bubble/bubbleflow-validation-tool.d.ts +308 -0
- package/dist/bubbles/tool-bubble/bubbleflow-validation-tool.d.ts.map +1 -0
- package/dist/bubbles/tool-bubble/bubbleflow-validation-tool.js +285 -0
- package/dist/bubbles/tool-bubble/bubbleflow-validation-tool.js.map +1 -0
- package/dist/bubbles/tool-bubble/chart-js-tool.d.ts +416 -0
- package/dist/bubbles/tool-bubble/chart-js-tool.d.ts.map +1 -0
- package/dist/bubbles/tool-bubble/chart-js-tool.js +570 -0
- package/dist/bubbles/tool-bubble/chart-js-tool.js.map +1 -0
- package/dist/bubbles/tool-bubble/get-bubble-details-tool.d.ts +99 -0
- package/dist/bubbles/tool-bubble/get-bubble-details-tool.d.ts.map +1 -0
- package/dist/bubbles/tool-bubble/get-bubble-details-tool.js +645 -0
- package/dist/bubbles/tool-bubble/get-bubble-details-tool.js.map +1 -0
- package/dist/bubbles/tool-bubble/list-bubbles-tool.d.ts +112 -0
- package/dist/bubbles/tool-bubble/list-bubbles-tool.d.ts.map +1 -0
- package/dist/bubbles/tool-bubble/list-bubbles-tool.js +82 -0
- package/dist/bubbles/tool-bubble/list-bubbles-tool.js.map +1 -0
- package/dist/bubbles/tool-bubble/reddit-scrape-tool.d.ts +413 -0
- package/dist/bubbles/tool-bubble/reddit-scrape-tool.d.ts.map +1 -0
- package/dist/bubbles/tool-bubble/reddit-scrape-tool.js +327 -0
- package/dist/bubbles/tool-bubble/reddit-scrape-tool.js.map +1 -0
- package/dist/bubbles/tool-bubble/research-agent-tool.d.ts +122 -0
- package/dist/bubbles/tool-bubble/research-agent-tool.d.ts.map +1 -0
- package/dist/bubbles/tool-bubble/research-agent-tool.js +343 -0
- package/dist/bubbles/tool-bubble/research-agent-tool.js.map +1 -0
- package/dist/bubbles/tool-bubble/sql-query-tool.d.ts +131 -0
- package/dist/bubbles/tool-bubble/sql-query-tool.d.ts.map +1 -0
- package/dist/bubbles/tool-bubble/sql-query-tool.js +147 -0
- package/dist/bubbles/tool-bubble/sql-query-tool.js.map +1 -0
- package/dist/bubbles/tool-bubble/tool-template.d.ts +257 -0
- package/dist/bubbles/tool-bubble/tool-template.d.ts.map +1 -0
- package/dist/bubbles/tool-bubble/tool-template.js +238 -0
- package/dist/bubbles/tool-bubble/tool-template.js.map +1 -0
- package/dist/bubbles/tool-bubble/virtual-file-editor-example.d.ts +8 -0
- package/dist/bubbles/tool-bubble/virtual-file-editor-example.d.ts.map +1 -0
- package/dist/bubbles/tool-bubble/virtual-file-editor-example.js +65 -0
- package/dist/bubbles/tool-bubble/virtual-file-editor-example.js.map +1 -0
- package/dist/bubbles/tool-bubble/virtual-file-editor.tool.d.ts +125 -0
- package/dist/bubbles/tool-bubble/virtual-file-editor.tool.d.ts.map +1 -0
- package/dist/bubbles/tool-bubble/virtual-file-editor.tool.js +169 -0
- package/dist/bubbles/tool-bubble/virtual-file-editor.tool.js.map +1 -0
- package/dist/bubbles/tool-bubble/web-crawl-tool.d.ts +218 -0
- package/dist/bubbles/tool-bubble/web-crawl-tool.d.ts.map +1 -0
- package/dist/bubbles/tool-bubble/web-crawl-tool.js +255 -0
- package/dist/bubbles/tool-bubble/web-crawl-tool.js.map +1 -0
- package/dist/bubbles/tool-bubble/web-extract-tool.d.ts +134 -0
- package/dist/bubbles/tool-bubble/web-extract-tool.d.ts.map +1 -0
- package/dist/bubbles/tool-bubble/web-extract-tool.js +175 -0
- package/dist/bubbles/tool-bubble/web-extract-tool.js.map +1 -0
- package/dist/bubbles/tool-bubble/web-scrape-tool.d.ts +228 -0
- package/dist/bubbles/tool-bubble/web-scrape-tool.d.ts.map +1 -0
- package/dist/bubbles/tool-bubble/web-scrape-tool.js +214 -0
- package/dist/bubbles/tool-bubble/web-scrape-tool.js.map +1 -0
- package/dist/bubbles/tool-bubble/web-search-tool.d.ts +134 -0
- package/dist/bubbles/tool-bubble/web-search-tool.d.ts.map +1 -0
- package/dist/bubbles/tool-bubble/web-search-tool.js +155 -0
- package/dist/bubbles/tool-bubble/web-search-tool.js.map +1 -0
- package/dist/bubbles/workflow-bubble/bubbleflow-generator.workflow.d.ts +114 -0
- package/dist/bubbles/workflow-bubble/bubbleflow-generator.workflow.d.ts.map +1 -0
- package/dist/bubbles/workflow-bubble/bubbleflow-generator.workflow.js +777 -0
- package/dist/bubbles/workflow-bubble/bubbleflow-generator.workflow.js.map +1 -0
- package/dist/bubbles/workflow-bubble/bubblscript-generateor.workflow.d.ts +97 -0
- package/dist/bubbles/workflow-bubble/bubblscript-generateor.workflow.d.ts.map +1 -0
- package/dist/bubbles/workflow-bubble/bubblscript-generateor.workflow.js +327 -0
- package/dist/bubbles/workflow-bubble/bubblscript-generateor.workflow.js.map +1 -0
- package/dist/bubbles/workflow-bubble/database-analyzer.workflow.d.ts +303 -0
- package/dist/bubbles/workflow-bubble/database-analyzer.workflow.d.ts.map +1 -0
- package/dist/bubbles/workflow-bubble/database-analyzer.workflow.js +297 -0
- package/dist/bubbles/workflow-bubble/database-analyzer.workflow.js.map +1 -0
- package/dist/bubbles/workflow-bubble/file-editor-agent.workflow.d.ts +157 -0
- package/dist/bubbles/workflow-bubble/file-editor-agent.workflow.d.ts.map +1 -0
- package/dist/bubbles/workflow-bubble/file-editor-agent.workflow.js +310 -0
- package/dist/bubbles/workflow-bubble/file-editor-agent.workflow.js.map +1 -0
- package/dist/bubbles/workflow-bubble/generate-document.workflow.d.ts +543 -0
- package/dist/bubbles/workflow-bubble/generate-document.workflow.d.ts.map +1 -0
- package/dist/bubbles/workflow-bubble/generate-document.workflow.js +628 -0
- package/dist/bubbles/workflow-bubble/generate-document.workflow.js.map +1 -0
- package/dist/bubbles/workflow-bubble/parse-document.workflow.d.ts +679 -0
- package/dist/bubbles/workflow-bubble/parse-document.workflow.d.ts.map +1 -0
- package/dist/bubbles/workflow-bubble/parse-document.workflow.js +604 -0
- package/dist/bubbles/workflow-bubble/parse-document.workflow.js.map +1 -0
- package/dist/bubbles/workflow-bubble/pdf-form-operations.workflow.d.ts +1011 -0
- package/dist/bubbles/workflow-bubble/pdf-form-operations.workflow.d.ts.map +1 -0
- package/dist/bubbles/workflow-bubble/pdf-form-operations.workflow.js +841 -0
- package/dist/bubbles/workflow-bubble/pdf-form-operations.workflow.js.map +1 -0
- package/dist/bubbles/workflow-bubble/pdf-ocr.workflow.d.ts +883 -0
- package/dist/bubbles/workflow-bubble/pdf-ocr.workflow.d.ts.map +1 -0
- package/dist/bubbles/workflow-bubble/pdf-ocr.workflow.js +781 -0
- package/dist/bubbles/workflow-bubble/pdf-ocr.workflow.js.map +1 -0
- package/dist/bubbles/workflow-bubble/slack-data-assistant.workflow.d.ts +300 -0
- package/dist/bubbles/workflow-bubble/slack-data-assistant.workflow.d.ts.map +1 -0
- package/dist/bubbles/workflow-bubble/slack-data-assistant.workflow.js +508 -0
- package/dist/bubbles/workflow-bubble/slack-data-assistant.workflow.js.map +1 -0
- package/dist/bubbles/workflow-bubble/slack-formatter-agent.d.ts +731 -0
- package/dist/bubbles/workflow-bubble/slack-formatter-agent.d.ts.map +1 -0
- package/dist/bubbles/workflow-bubble/slack-formatter-agent.js +690 -0
- package/dist/bubbles/workflow-bubble/slack-formatter-agent.js.map +1 -0
- package/dist/bubbles/workflow-bubble/slack-notifier.workflow.d.ts +401 -0
- package/dist/bubbles/workflow-bubble/slack-notifier.workflow.d.ts.map +1 -0
- package/dist/bubbles/workflow-bubble/slack-notifier.workflow.js +382 -0
- package/dist/bubbles/workflow-bubble/slack-notifier.workflow.js.map +1 -0
- package/dist/bubbles/workflow-bubble/workflow-template.d.ts +144 -0
- package/dist/bubbles/workflow-bubble/workflow-template.d.ts.map +1 -0
- package/dist/bubbles/workflow-bubble/workflow-template.js +124 -0
- package/dist/bubbles/workflow-bubble/workflow-template.js.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/logging/BubbleLogger.d.ts +146 -0
- package/dist/logging/BubbleLogger.d.ts.map +1 -0
- package/dist/logging/BubbleLogger.js +472 -0
- package/dist/logging/BubbleLogger.js.map +1 -0
- package/dist/logging/StreamingBubbleLogger.d.ts +85 -0
- package/dist/logging/StreamingBubbleLogger.d.ts.map +1 -0
- package/dist/logging/StreamingBubbleLogger.js +340 -0
- package/dist/logging/StreamingBubbleLogger.js.map +1 -0
- package/dist/types/ai-models.d.ts +4 -0
- package/dist/types/ai-models.d.ts.map +1 -0
- package/dist/types/ai-models.js +14 -0
- package/dist/types/ai-models.js.map +1 -0
- package/dist/types/available-tools.d.ts +4 -0
- package/dist/types/available-tools.d.ts.map +1 -0
- package/dist/types/available-tools.js +19 -0
- package/dist/types/available-tools.js.map +1 -0
- package/dist/types/base-bubble-class.d.ts +47 -0
- package/dist/types/base-bubble-class.d.ts.map +1 -0
- package/dist/types/base-bubble-class.js +212 -0
- package/dist/types/base-bubble-class.js.map +1 -0
- package/dist/types/bubble-errors.d.ts +44 -0
- package/dist/types/bubble-errors.d.ts.map +1 -0
- package/dist/types/bubble-errors.js +51 -0
- package/dist/types/bubble-errors.js.map +1 -0
- package/dist/types/bubble.d.ts +73 -0
- package/dist/types/bubble.d.ts.map +1 -0
- package/dist/types/bubble.js +2 -0
- package/dist/types/bubble.js.map +1 -0
- package/dist/types/credentials.d.ts +6 -0
- package/dist/types/credentials.d.ts.map +1 -0
- package/dist/types/credentials.js +6 -0
- package/dist/types/credentials.js.map +1 -0
- package/dist/types/service-bubble-class.d.ts +31 -0
- package/dist/types/service-bubble-class.d.ts.map +1 -0
- package/dist/types/service-bubble-class.js +36 -0
- package/dist/types/service-bubble-class.js.map +1 -0
- package/dist/types/streaming-events.d.ts +18 -0
- package/dist/types/streaming-events.d.ts.map +1 -0
- package/dist/types/streaming-events.js +5 -0
- package/dist/types/streaming-events.js.map +1 -0
- package/dist/types/tool-bubble-class.d.ts +19 -0
- package/dist/types/tool-bubble-class.d.ts.map +1 -0
- package/dist/types/tool-bubble-class.js +48 -0
- package/dist/types/tool-bubble-class.js.map +1 -0
- package/dist/types/workflow-bubble-class.d.ts +25 -0
- package/dist/types/workflow-bubble-class.d.ts.map +1 -0
- package/dist/types/workflow-bubble-class.js +30 -0
- package/dist/types/workflow-bubble-class.js.map +1 -0
- package/dist/utils/bubbleflow-parser.d.ts +32 -0
- package/dist/utils/bubbleflow-parser.d.ts.map +1 -0
- package/dist/utils/bubbleflow-parser.js +332 -0
- package/dist/utils/bubbleflow-parser.js.map +1 -0
- package/dist/utils/bubbleflow-validation.d.ts +9 -0
- package/dist/utils/bubbleflow-validation.d.ts.map +1 -0
- package/dist/utils/bubbleflow-validation.js +116 -0
- package/dist/utils/bubbleflow-validation.js.map +1 -0
- package/dist/utils/json-parsing.d.ts +20 -0
- package/dist/utils/json-parsing.d.ts.map +1 -0
- package/dist/utils/json-parsing.js +394 -0
- package/dist/utils/json-parsing.js.map +1 -0
- package/dist/utils/mock-data-generator.d.ts +43 -0
- package/dist/utils/mock-data-generator.d.ts.map +1 -0
- package/dist/utils/mock-data-generator.js +312 -0
- package/dist/utils/mock-data-generator.js.map +1 -0
- package/dist/utils/param-helper.d.ts +2 -0
- package/dist/utils/param-helper.d.ts.map +1 -0
- package/dist/utils/param-helper.js +5 -0
- package/dist/utils/param-helper.js.map +1 -0
- package/dist/utils/source-bubble-parser.d.ts +31 -0
- package/dist/utils/source-bubble-parser.d.ts.map +1 -0
- package/dist/utils/source-bubble-parser.js +231 -0
- package/dist/utils/source-bubble-parser.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,645 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ToolBubble } from '../../types/tool-bubble-class.js';
|
|
3
|
+
import { CredentialType } from '@bubblelab/shared-schemas';
|
|
4
|
+
import { BubbleFactory } from '../../bubble-factory.js';
|
|
5
|
+
// Define the parameters schema
|
|
6
|
+
const GetBubbleDetailsToolParamsSchema = z.object({
|
|
7
|
+
bubbleName: z
|
|
8
|
+
.string()
|
|
9
|
+
.min(1, 'Bubble name is required')
|
|
10
|
+
.describe('The name of the bubble to get details about'),
|
|
11
|
+
credentials: z
|
|
12
|
+
.record(z.nativeEnum(CredentialType), z.string())
|
|
13
|
+
.optional()
|
|
14
|
+
.describe('Object mapping credential types to values (injected at runtime)'),
|
|
15
|
+
});
|
|
16
|
+
// Result schema for validation
|
|
17
|
+
const GetBubbleDetailsToolResultSchema = z.object({
|
|
18
|
+
name: z.string().describe('Name of the bubble'),
|
|
19
|
+
alias: z.string().optional().describe('Short alias for the bubble'),
|
|
20
|
+
outputSchema: z
|
|
21
|
+
.string()
|
|
22
|
+
.describe('String representation of the output schema types'),
|
|
23
|
+
usageExample: z
|
|
24
|
+
.string()
|
|
25
|
+
.describe('Code example showing how to use the bubble'),
|
|
26
|
+
success: z.boolean().describe('Whether the operation was successful'),
|
|
27
|
+
error: z.string().describe('Error message if operation failed'),
|
|
28
|
+
});
|
|
29
|
+
export class GetBubbleDetailsTool extends ToolBubble {
|
|
30
|
+
static type = 'tool';
|
|
31
|
+
static bubbleName = 'get-bubble-details-tool';
|
|
32
|
+
static schema = GetBubbleDetailsToolParamsSchema;
|
|
33
|
+
static resultSchema = GetBubbleDetailsToolResultSchema;
|
|
34
|
+
static shortDescription = 'Provides detailed information about a specific bubble, including schema, parameters, and documentation';
|
|
35
|
+
static longDescription = `
|
|
36
|
+
A tool bubble that retrieves comprehensive information about any registered bubble in the system.
|
|
37
|
+
|
|
38
|
+
Returns detailed information including:
|
|
39
|
+
- Complete schema with parameter types and descriptions
|
|
40
|
+
- Result schema for expected outputs
|
|
41
|
+
- Credential requirements
|
|
42
|
+
- AI-formatted documentation
|
|
43
|
+
- Usage examples
|
|
44
|
+
|
|
45
|
+
Use cases:
|
|
46
|
+
- AI agent understanding of specific bubble capabilities
|
|
47
|
+
- Parameter validation before bubble instantiation
|
|
48
|
+
- Documentation generation and help systems
|
|
49
|
+
- Dynamic form generation for bubble configuration
|
|
50
|
+
`;
|
|
51
|
+
static alias = 'details';
|
|
52
|
+
factory;
|
|
53
|
+
constructor(params, context) {
|
|
54
|
+
super(params, context);
|
|
55
|
+
this.factory = new BubbleFactory();
|
|
56
|
+
}
|
|
57
|
+
async performAction(context) {
|
|
58
|
+
void context; // Context available but not currently used
|
|
59
|
+
await this.factory.registerDefaults();
|
|
60
|
+
const metadata = this.factory.getMetadata(this.params.bubbleName);
|
|
61
|
+
if (!metadata) {
|
|
62
|
+
throw new Error(`Bubble '${this.params.bubbleName}' not found in registry`);
|
|
63
|
+
}
|
|
64
|
+
// Format schema for AI consumption
|
|
65
|
+
// const schemaProperties = JSON.stringify(zodToJsonSchema(metadata.schema));
|
|
66
|
+
// const resultSchemaProperties = JSON.stringify(
|
|
67
|
+
// zodToJsonSchema(metadata.resultSchema!)
|
|
68
|
+
// );
|
|
69
|
+
// Create formatted description for AI agents
|
|
70
|
+
const usageExample = this.generateUsageExample({
|
|
71
|
+
name: metadata.name,
|
|
72
|
+
schema: metadata.schema,
|
|
73
|
+
resultSchema: metadata.resultSchema,
|
|
74
|
+
});
|
|
75
|
+
// Generate string representation of output schema
|
|
76
|
+
const outputSchemaString = this.generateOutputSchemaString(metadata.resultSchema);
|
|
77
|
+
return {
|
|
78
|
+
name: metadata.name,
|
|
79
|
+
alias: metadata.alias,
|
|
80
|
+
outputSchema: outputSchemaString,
|
|
81
|
+
usageExample,
|
|
82
|
+
success: true,
|
|
83
|
+
error: '',
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
generateOutputSchemaString(resultSchema) {
|
|
87
|
+
if (!resultSchema) {
|
|
88
|
+
return 'No output schema defined';
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
if (resultSchema &&
|
|
92
|
+
typeof resultSchema === 'object' &&
|
|
93
|
+
'shape' in resultSchema) {
|
|
94
|
+
const shape = resultSchema.shape;
|
|
95
|
+
const outputFields = [];
|
|
96
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
97
|
+
if (value && typeof value === 'object' && '_def' in value) {
|
|
98
|
+
const zodType = value;
|
|
99
|
+
const typeInfo = this.generateTypeInfo(zodType);
|
|
100
|
+
const description = this.getParameterDescription(zodType);
|
|
101
|
+
if (typeInfo) {
|
|
102
|
+
let fieldLine = `${key}: ${typeInfo}`;
|
|
103
|
+
if (description) {
|
|
104
|
+
fieldLine += ` // ${description}`;
|
|
105
|
+
}
|
|
106
|
+
outputFields.push(fieldLine);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (outputFields.length > 0) {
|
|
111
|
+
return `{\n ${outputFields.join(',\n ')}\n}`;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return 'Complex schema - see usage example for structure';
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return 'Unable to parse output schema';
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
generateTypeInfo(zodType) {
|
|
121
|
+
const def = zodType._def;
|
|
122
|
+
if (def.typeName === 'ZodString') {
|
|
123
|
+
return 'string';
|
|
124
|
+
}
|
|
125
|
+
else if (def.typeName === 'ZodNumber') {
|
|
126
|
+
return 'number';
|
|
127
|
+
}
|
|
128
|
+
else if (def.typeName === 'ZodBoolean') {
|
|
129
|
+
return 'boolean';
|
|
130
|
+
}
|
|
131
|
+
else if (def.typeName === 'ZodArray') {
|
|
132
|
+
const elementType = def.type;
|
|
133
|
+
if (elementType) {
|
|
134
|
+
const elementTypeInfo = this.generateTypeInfo(elementType);
|
|
135
|
+
if (elementTypeInfo) {
|
|
136
|
+
return `${elementTypeInfo}[]`;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return 'unknown[]';
|
|
140
|
+
}
|
|
141
|
+
else if (def.typeName === 'ZodObject') {
|
|
142
|
+
if ('shape' in zodType) {
|
|
143
|
+
const shape = zodType.shape;
|
|
144
|
+
const properties = [];
|
|
145
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
146
|
+
if (value && typeof value === 'object' && '_def' in value) {
|
|
147
|
+
const zodValue = value;
|
|
148
|
+
const typeInfo = this.generateTypeInfo(zodValue);
|
|
149
|
+
if (typeInfo) {
|
|
150
|
+
properties.push(`${key}: ${typeInfo}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (properties.length > 0) {
|
|
155
|
+
return `{ ${properties.join(', ')} }`;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return 'object';
|
|
159
|
+
}
|
|
160
|
+
else if (def.typeName === 'ZodOptional') {
|
|
161
|
+
const innerType = this.generateTypeInfo(def.innerType);
|
|
162
|
+
return innerType ? `${innerType} | undefined` : 'unknown | undefined';
|
|
163
|
+
}
|
|
164
|
+
else if (def.typeName === 'ZodDefault') {
|
|
165
|
+
return this.generateTypeInfo(def.innerType);
|
|
166
|
+
}
|
|
167
|
+
else if (def.typeName === 'ZodEnum') {
|
|
168
|
+
const enumValues = def.values;
|
|
169
|
+
return enumValues.map((v) => `"${v}"`).join(' | ');
|
|
170
|
+
}
|
|
171
|
+
else if (def.typeName === 'ZodLiteral') {
|
|
172
|
+
return typeof def.value === 'string'
|
|
173
|
+
? `"${def.value}"`
|
|
174
|
+
: String(def.value);
|
|
175
|
+
}
|
|
176
|
+
else if (def.typeName === 'ZodRecord') {
|
|
177
|
+
const valueType = def.valueType;
|
|
178
|
+
if (valueType) {
|
|
179
|
+
const valueTypeInfo = this.generateTypeInfo(valueType);
|
|
180
|
+
if (valueTypeInfo) {
|
|
181
|
+
return `Record<string, ${valueTypeInfo}>`;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return 'Record<string, unknown>';
|
|
185
|
+
}
|
|
186
|
+
else if (def.typeName === 'ZodDiscriminatedUnion') {
|
|
187
|
+
return 'DiscriminatedUnion'; // Simplified for complex unions
|
|
188
|
+
}
|
|
189
|
+
return 'unknown';
|
|
190
|
+
}
|
|
191
|
+
generateUsageExample(metadata) {
|
|
192
|
+
const lines = [];
|
|
193
|
+
// Check if this is a discriminated union (multiple operations)
|
|
194
|
+
const isDiscriminatedUnion = this.isDiscriminatedUnion(metadata.schema);
|
|
195
|
+
if (isDiscriminatedUnion) {
|
|
196
|
+
// Generate separate examples for each operation
|
|
197
|
+
const operationExamples = this.generateOperationExamples(metadata);
|
|
198
|
+
if (operationExamples.length > 0) {
|
|
199
|
+
lines.push(...operationExamples);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
// Fallback to original format if operation parsing fails
|
|
203
|
+
lines.push(...this.generateSingleExample(metadata));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
// Generate single example for non-discriminated schemas
|
|
208
|
+
lines.push(...this.generateSingleExample(metadata));
|
|
209
|
+
}
|
|
210
|
+
return lines.join('\n');
|
|
211
|
+
}
|
|
212
|
+
isDiscriminatedUnion(schema) {
|
|
213
|
+
if (schema && typeof schema === 'object' && '_def' in schema) {
|
|
214
|
+
const zodSchema = schema;
|
|
215
|
+
return zodSchema._def.typeName === 'ZodDiscriminatedUnion';
|
|
216
|
+
}
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
generateOperationExamples(metadata) {
|
|
220
|
+
const lines = [];
|
|
221
|
+
if (metadata.schema &&
|
|
222
|
+
typeof metadata.schema === 'object' &&
|
|
223
|
+
'_def' in metadata.schema) {
|
|
224
|
+
const zodSchema = metadata.schema;
|
|
225
|
+
const def = zodSchema._def;
|
|
226
|
+
if (def.typeName === 'ZodDiscriminatedUnion') {
|
|
227
|
+
const options = def.options;
|
|
228
|
+
const discriminatorKey = def.discriminator;
|
|
229
|
+
// Limit to first 4 operations to avoid overwhelming output
|
|
230
|
+
const maxOperations = 4;
|
|
231
|
+
const operationsToShow = options.slice(0, maxOperations);
|
|
232
|
+
operationsToShow.forEach((option, index) => {
|
|
233
|
+
if (option && typeof option === 'object' && 'shape' in option) {
|
|
234
|
+
const shape = option.shape;
|
|
235
|
+
// Get the operation name from discriminator
|
|
236
|
+
const discriminatorValue = shape[discriminatorKey];
|
|
237
|
+
if (discriminatorValue &&
|
|
238
|
+
typeof discriminatorValue === 'object' &&
|
|
239
|
+
'_def' in discriminatorValue) {
|
|
240
|
+
const literalDef = discriminatorValue._def;
|
|
241
|
+
if (literalDef.typeName === 'ZodLiteral') {
|
|
242
|
+
const operationName = literalDef.value;
|
|
243
|
+
// Add spacing between operations
|
|
244
|
+
if (index > 0) {
|
|
245
|
+
lines.push('');
|
|
246
|
+
}
|
|
247
|
+
// Add operation-specific comment
|
|
248
|
+
const operationComment = this.formatOperationComment(operationName);
|
|
249
|
+
lines.push(`// ${operationComment}`);
|
|
250
|
+
// Create variable name with operation suffix
|
|
251
|
+
const variableName = `${this.toCamelCase(metadata.name)}_${operationName.replace(/[^a-zA-Z0-9]/g, '_')}`;
|
|
252
|
+
lines.push(`const ${variableName} = new ${this.toPascalCase(metadata.name)}Bubble({`);
|
|
253
|
+
// Generate parameters for this specific operation
|
|
254
|
+
const operationParams = [];
|
|
255
|
+
Object.entries(shape).forEach(([key, value]) => {
|
|
256
|
+
if (key === 'credentials')
|
|
257
|
+
return; // Skip credentials
|
|
258
|
+
if (value && typeof value === 'object' && '_def' in value) {
|
|
259
|
+
const zodType = value;
|
|
260
|
+
const example = this.generateExampleValue(zodType);
|
|
261
|
+
const description = this.getParameterDescription(zodType);
|
|
262
|
+
if (example !== null) {
|
|
263
|
+
const paramLine = ` ${key}: ${example}`;
|
|
264
|
+
if (description) {
|
|
265
|
+
operationParams.push(`${paramLine}, // ${description}`);
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
operationParams.push(`${paramLine},`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
if (operationParams.length > 0) {
|
|
274
|
+
lines.push(...operationParams);
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
lines.push(' // Add required parameters here');
|
|
278
|
+
}
|
|
279
|
+
lines.push('});');
|
|
280
|
+
lines.push('');
|
|
281
|
+
lines.push(`const result = await ${variableName}.action();`);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
// Add common result handling code once at the end
|
|
287
|
+
if (operationsToShow.length > 0) {
|
|
288
|
+
lines.push('');
|
|
289
|
+
lines.push('// Always check success status before using data');
|
|
290
|
+
lines.push('if (!result.success) {');
|
|
291
|
+
lines.push(` throw new Error(\`${metadata.name} failed: \${result.error}\`);`);
|
|
292
|
+
lines.push('}');
|
|
293
|
+
lines.push('');
|
|
294
|
+
// Add output schema information
|
|
295
|
+
if (metadata.resultSchema) {
|
|
296
|
+
const outputExample = this.generateOutputExample(metadata.resultSchema);
|
|
297
|
+
if (outputExample) {
|
|
298
|
+
lines.push('// Expected output structure in result.data:');
|
|
299
|
+
lines.push(`// ${outputExample}`);
|
|
300
|
+
lines.push('');
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
lines.push('// Access the actual data');
|
|
304
|
+
lines.push('const actualData = result.data;');
|
|
305
|
+
lines.push('console.log(actualData);');
|
|
306
|
+
// Add note if there are more operations
|
|
307
|
+
if (options.length > maxOperations) {
|
|
308
|
+
lines.push('');
|
|
309
|
+
lines.push(`// ... and ${options.length - maxOperations} more operations available`);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return lines;
|
|
315
|
+
}
|
|
316
|
+
generateSingleExample(metadata) {
|
|
317
|
+
const lines = [];
|
|
318
|
+
lines.push(`// Example usage of ${metadata.name} bubble`);
|
|
319
|
+
// Try to extract example parameters from schema
|
|
320
|
+
const exampleParams = this.generateExampleParams(metadata.schema);
|
|
321
|
+
lines.push(`const ${this.toCamelCase(metadata.name)} = new ${this.toPascalCase(metadata.name)}Bubble({`);
|
|
322
|
+
if (exampleParams.length > 0) {
|
|
323
|
+
lines.push(...exampleParams.map((param) => ` ${param},`));
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
lines.push(' // Add required parameters here');
|
|
327
|
+
}
|
|
328
|
+
lines.push('});');
|
|
329
|
+
lines.push('');
|
|
330
|
+
lines.push(`const result = await ${this.toCamelCase(metadata.name)}.action();`);
|
|
331
|
+
lines.push('');
|
|
332
|
+
lines.push('// Always check success status before using data');
|
|
333
|
+
lines.push('if (!result.success) {');
|
|
334
|
+
lines.push(' throw new Error(`${metadata.name} failed: ${result.error}`);');
|
|
335
|
+
lines.push('}');
|
|
336
|
+
lines.push('');
|
|
337
|
+
// Add output schema information
|
|
338
|
+
if (metadata.resultSchema) {
|
|
339
|
+
const outputExample = this.generateOutputExample(metadata.resultSchema);
|
|
340
|
+
if (outputExample) {
|
|
341
|
+
lines.push('// Expected output structure in result.data:');
|
|
342
|
+
lines.push(`// ${outputExample}`);
|
|
343
|
+
lines.push('');
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
lines.push('// Access the actual data');
|
|
347
|
+
lines.push('const actualData = result.data;');
|
|
348
|
+
lines.push('console.log(actualData);');
|
|
349
|
+
return lines;
|
|
350
|
+
}
|
|
351
|
+
formatOperationComment(operationName) {
|
|
352
|
+
// Convert operation name to readable format
|
|
353
|
+
return (operationName
|
|
354
|
+
.split('_')
|
|
355
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
356
|
+
.join(' ') + ' example');
|
|
357
|
+
}
|
|
358
|
+
generateOutputExample(resultSchema) {
|
|
359
|
+
try {
|
|
360
|
+
// Try to generate a meaningful example of the output structure
|
|
361
|
+
if (resultSchema &&
|
|
362
|
+
typeof resultSchema === 'object' &&
|
|
363
|
+
'shape' in resultSchema) {
|
|
364
|
+
const shape = resultSchema.shape;
|
|
365
|
+
const outputFields = [];
|
|
366
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
367
|
+
if (value && typeof value === 'object' && '_def' in value) {
|
|
368
|
+
const zodType = value;
|
|
369
|
+
const example = this.generateExampleValue(zodType);
|
|
370
|
+
const description = this.getParameterDescription(zodType);
|
|
371
|
+
if (example !== null) {
|
|
372
|
+
let fieldLine = `${key}: ${example}`;
|
|
373
|
+
if (description) {
|
|
374
|
+
fieldLine += ` // ${description}`;
|
|
375
|
+
}
|
|
376
|
+
outputFields.push(fieldLine);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (outputFields.length > 0) {
|
|
381
|
+
return `{ ${outputFields.join(', ')} }`;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return null;
|
|
385
|
+
}
|
|
386
|
+
catch {
|
|
387
|
+
return null;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Extracts the description from a Zod schema type
|
|
392
|
+
*/
|
|
393
|
+
getParameterDescription(zodType) {
|
|
394
|
+
try {
|
|
395
|
+
const def = zodType._def;
|
|
396
|
+
// Check if the schema has a description
|
|
397
|
+
if (def.description) {
|
|
398
|
+
return def.description;
|
|
399
|
+
}
|
|
400
|
+
// For optional types, check the inner type
|
|
401
|
+
if (def.typeName === 'ZodOptional' && def.innerType) {
|
|
402
|
+
return this.getParameterDescription(def.innerType);
|
|
403
|
+
}
|
|
404
|
+
// For default types, check the inner type
|
|
405
|
+
if (def.typeName === 'ZodDefault' && def.innerType) {
|
|
406
|
+
return this.getParameterDescription(def.innerType);
|
|
407
|
+
}
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
catch {
|
|
411
|
+
return null;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
generateExampleParams(schema) {
|
|
415
|
+
const params = [];
|
|
416
|
+
if (schema && typeof schema === 'object' && '_def' in schema) {
|
|
417
|
+
const zodSchema = schema;
|
|
418
|
+
const def = zodSchema._def;
|
|
419
|
+
// Handle discriminated unions
|
|
420
|
+
if (def.typeName === 'ZodDiscriminatedUnion') {
|
|
421
|
+
// For discriminated unions, show examples for all operations
|
|
422
|
+
const options = def.options;
|
|
423
|
+
const discriminatorKey = def.discriminator;
|
|
424
|
+
options.forEach((option, index) => {
|
|
425
|
+
if (option && typeof option === 'object' && 'shape' in option) {
|
|
426
|
+
const shape = option.shape;
|
|
427
|
+
// Get the discriminator value for this option
|
|
428
|
+
const discriminatorValue = shape[discriminatorKey];
|
|
429
|
+
if (discriminatorValue &&
|
|
430
|
+
typeof discriminatorValue === 'object' &&
|
|
431
|
+
'_def' in discriminatorValue) {
|
|
432
|
+
const literalDef = discriminatorValue._def;
|
|
433
|
+
if (literalDef.typeName === 'ZodLiteral') {
|
|
434
|
+
const operationName = literalDef.value;
|
|
435
|
+
// Add operation header
|
|
436
|
+
if (index > 0)
|
|
437
|
+
params.push(''); // Add spacing between operations
|
|
438
|
+
params.push(`// Operation: ${operationName}`);
|
|
439
|
+
// Add parameters for this operation
|
|
440
|
+
Object.entries(shape).forEach(([key, value]) => {
|
|
441
|
+
if (key === 'credentials' || key === discriminatorKey)
|
|
442
|
+
return; // Skip credentials and discriminator
|
|
443
|
+
if (value && typeof value === 'object' && '_def' in value) {
|
|
444
|
+
const zodType = value;
|
|
445
|
+
const example = this.generateExampleValue(zodType);
|
|
446
|
+
const description = this.getParameterDescription(zodType);
|
|
447
|
+
if (example !== null) {
|
|
448
|
+
const paramLine = ` ${key}: ${example}`;
|
|
449
|
+
if (description) {
|
|
450
|
+
params.push(`${paramLine}, // ${description}`);
|
|
451
|
+
}
|
|
452
|
+
else {
|
|
453
|
+
params.push(`${paramLine},`);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
// Handle regular objects
|
|
464
|
+
else if ('shape' in schema) {
|
|
465
|
+
const zodSchema = schema;
|
|
466
|
+
const shape = zodSchema.shape;
|
|
467
|
+
Object.entries(shape).forEach(([key, value]) => {
|
|
468
|
+
if (key === 'credentials')
|
|
469
|
+
return; // Skip credentials in examples
|
|
470
|
+
if (value && typeof value === 'object' && '_def' in value) {
|
|
471
|
+
const zodType = value;
|
|
472
|
+
const example = this.generateExampleValue(zodType);
|
|
473
|
+
const description = this.getParameterDescription(zodType);
|
|
474
|
+
if (example !== null) {
|
|
475
|
+
const paramLine = `${key}: ${example}`;
|
|
476
|
+
if (description) {
|
|
477
|
+
params.push(`${paramLine}, // ${description}`);
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
params.push(`${paramLine},`);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
return params;
|
|
488
|
+
}
|
|
489
|
+
generateExampleValue(zodType) {
|
|
490
|
+
const def = zodType._def;
|
|
491
|
+
if (def.typeName === 'ZodString') {
|
|
492
|
+
return '"example string"';
|
|
493
|
+
}
|
|
494
|
+
else if (def.typeName === 'ZodNumber') {
|
|
495
|
+
return '42';
|
|
496
|
+
}
|
|
497
|
+
else if (def.typeName === 'ZodBoolean') {
|
|
498
|
+
return 'true';
|
|
499
|
+
}
|
|
500
|
+
else if (def.typeName === 'ZodArray') {
|
|
501
|
+
// Generate example for array element type
|
|
502
|
+
const elementType = def.type;
|
|
503
|
+
if (elementType) {
|
|
504
|
+
const elementExample = this.generateExampleValue(elementType);
|
|
505
|
+
if (elementExample) {
|
|
506
|
+
return `[${elementExample}]`;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
return '[]';
|
|
510
|
+
}
|
|
511
|
+
else if (def.typeName === 'ZodObject') {
|
|
512
|
+
// Generate example object with its properties
|
|
513
|
+
if ('shape' in zodType) {
|
|
514
|
+
const shape = zodType.shape;
|
|
515
|
+
const properties = [];
|
|
516
|
+
// Limit properties to avoid too verbose examples
|
|
517
|
+
let count = 0;
|
|
518
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
519
|
+
if (value && typeof value === 'object' && '_def' in value) {
|
|
520
|
+
const zodValue = value;
|
|
521
|
+
const exampleValue = this.generateExampleValue(zodValue);
|
|
522
|
+
const description = this.getParameterDescription(zodValue);
|
|
523
|
+
if (exampleValue !== null) {
|
|
524
|
+
let propertyLine = `${key}: ${exampleValue}`;
|
|
525
|
+
if (description) {
|
|
526
|
+
propertyLine += ` // ${description}`;
|
|
527
|
+
}
|
|
528
|
+
properties.push(propertyLine);
|
|
529
|
+
count++;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
if (properties.length > 0) {
|
|
534
|
+
return `{ ${properties.join(', ')} }`;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
return '{}';
|
|
538
|
+
}
|
|
539
|
+
else if (def.typeName === 'ZodOptional') {
|
|
540
|
+
return this.generateExampleValue(def.innerType);
|
|
541
|
+
}
|
|
542
|
+
else if (def.typeName === 'ZodDefault') {
|
|
543
|
+
// For defaults, show the example structure of the inner type if it's complex, otherwise show default
|
|
544
|
+
const innerExample = this.generateExampleValue(def.innerType);
|
|
545
|
+
const defaultValue = def.defaultValue();
|
|
546
|
+
// If the default is an empty array but the inner type is complex, show example
|
|
547
|
+
if (Array.isArray(defaultValue) &&
|
|
548
|
+
defaultValue.length === 0 &&
|
|
549
|
+
innerExample &&
|
|
550
|
+
innerExample !== '[]') {
|
|
551
|
+
return `${innerExample} // example for array`;
|
|
552
|
+
}
|
|
553
|
+
// If the default is a complex object and we have a meaningful inner example, show structure
|
|
554
|
+
if (typeof defaultValue === 'object' &&
|
|
555
|
+
defaultValue !== null &&
|
|
556
|
+
!Array.isArray(defaultValue) &&
|
|
557
|
+
innerExample &&
|
|
558
|
+
innerExample !== '{}' &&
|
|
559
|
+
innerExample.includes(':') // Has properties
|
|
560
|
+
) {
|
|
561
|
+
return `${innerExample} // structure`;
|
|
562
|
+
}
|
|
563
|
+
// If the inner type is an enum with multiple options, show the enum options instead of just default
|
|
564
|
+
if (def.innerType &&
|
|
565
|
+
def.innerType._def &&
|
|
566
|
+
def.innerType._def.typeName === 'ZodEnum') {
|
|
567
|
+
return innerExample; // This will include the enum options
|
|
568
|
+
}
|
|
569
|
+
// If the inner type is ZodOptional containing an enum, drill down further
|
|
570
|
+
if (def.innerType &&
|
|
571
|
+
def.innerType._def &&
|
|
572
|
+
def.innerType._def.typeName === 'ZodOptional') {
|
|
573
|
+
const optionalInner = def.innerType._def.innerType;
|
|
574
|
+
if (optionalInner &&
|
|
575
|
+
optionalInner._def &&
|
|
576
|
+
optionalInner._def.typeName === 'ZodEnum') {
|
|
577
|
+
return this.generateExampleValue(optionalInner); // Generate example for the enum
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
return `${JSON.stringify(defaultValue)} // default`;
|
|
581
|
+
}
|
|
582
|
+
else if (def.typeName === 'ZodEnum') {
|
|
583
|
+
// Show all enum options, not just the first one
|
|
584
|
+
const enumValues = def.values;
|
|
585
|
+
if (enumValues.length > 1) {
|
|
586
|
+
// Show first value as primary with all options listed
|
|
587
|
+
return `"${enumValues[0]}" // options: ${enumValues.map((v) => `"${v}"`).join(', ')}`;
|
|
588
|
+
}
|
|
589
|
+
return `"${enumValues[0]}"`;
|
|
590
|
+
}
|
|
591
|
+
else if (def.typeName === 'ZodDiscriminatedUnion') {
|
|
592
|
+
// For discriminated unions, generate a proper example object from the first option
|
|
593
|
+
const options = def.options;
|
|
594
|
+
if (options.length > 0) {
|
|
595
|
+
const firstOption = options[0];
|
|
596
|
+
if (firstOption &&
|
|
597
|
+
typeof firstOption === 'object' &&
|
|
598
|
+
'_def' in firstOption &&
|
|
599
|
+
'shape' in firstOption) {
|
|
600
|
+
const firstOptionDef = firstOption._def;
|
|
601
|
+
if (firstOptionDef.typeName === 'ZodObject') {
|
|
602
|
+
const shape = firstOption.shape;
|
|
603
|
+
const properties = [];
|
|
604
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
605
|
+
if (value && typeof value === 'object' && '_def' in value) {
|
|
606
|
+
const zodValue = value;
|
|
607
|
+
const exampleValue = this.generateExampleValue(zodValue);
|
|
608
|
+
if (exampleValue !== null) {
|
|
609
|
+
properties.push(`${key}: ${exampleValue}`);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
if (properties.length > 0) {
|
|
614
|
+
return `{ ${properties.join(', ')} }`;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
return '"first_option" // discriminated union';
|
|
620
|
+
}
|
|
621
|
+
else if (def.typeName === 'ZodLiteral') {
|
|
622
|
+
return JSON.stringify(def.value);
|
|
623
|
+
}
|
|
624
|
+
else if (def.typeName === 'ZodRecord') {
|
|
625
|
+
// For records, show an example with a key-value pair
|
|
626
|
+
const valueType = def.valueType;
|
|
627
|
+
if (valueType) {
|
|
628
|
+
const valueExample = this.generateExampleValue(valueType);
|
|
629
|
+
if (valueExample) {
|
|
630
|
+
return `{ "example_key": ${valueExample} } // record/object with string keys`;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
return '{} // record/object with string keys';
|
|
634
|
+
}
|
|
635
|
+
return null;
|
|
636
|
+
}
|
|
637
|
+
toCamelCase(str) {
|
|
638
|
+
return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
639
|
+
}
|
|
640
|
+
toPascalCase(str) {
|
|
641
|
+
const camelCase = this.toCamelCase(str);
|
|
642
|
+
return camelCase.charAt(0).toUpperCase() + camelCase.slice(1);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
//# sourceMappingURL=get-bubble-details-tool.js.map
|