@superblocksteam/vite-plugin-file-sync 2.0.42-next.9 → 2.0.43-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai-service/agent/prompts/build-base-system-prompt.d.ts +2 -1
- package/dist/ai-service/agent/prompts/build-base-system-prompt.d.ts.map +1 -1
- package/dist/ai-service/agent/prompts/build-base-system-prompt.js +31 -2
- package/dist/ai-service/agent/prompts/build-base-system-prompt.js.map +1 -1
- package/dist/ai-service/agent/subagents/apis/example-selector.d.ts +24 -0
- package/dist/ai-service/agent/subagents/apis/example-selector.d.ts.map +1 -0
- package/dist/ai-service/agent/subagents/apis/example-selector.js +104 -0
- package/dist/ai-service/agent/subagents/apis/example-selector.js.map +1 -0
- package/dist/ai-service/agent/subagents/apis/examples.d.ts +55 -0
- package/dist/ai-service/agent/subagents/apis/examples.d.ts.map +1 -0
- package/dist/ai-service/agent/subagents/apis/examples.js +1229 -0
- package/dist/ai-service/agent/subagents/apis/examples.js.map +1 -0
- package/dist/ai-service/agent/subagents/apis/generate-api-source.d.ts +83 -0
- package/dist/ai-service/agent/subagents/apis/generate-api-source.d.ts.map +1 -0
- package/dist/ai-service/agent/{apis.js → subagents/apis/generate-api-source.js} +130 -98
- package/dist/ai-service/agent/subagents/apis/generate-api-source.js.map +1 -0
- package/dist/ai-service/agent/subagents/apis/prompt-builder.d.ts +39 -0
- package/dist/ai-service/agent/subagents/apis/prompt-builder.d.ts.map +1 -0
- package/dist/ai-service/agent/subagents/apis/prompt-builder.js +115 -0
- package/dist/ai-service/agent/subagents/apis/prompt-builder.js.map +1 -0
- package/dist/ai-service/agent/{apis-static-analysis.d.ts → subagents/apis/static-analysis.d.ts} +1 -1
- package/dist/ai-service/agent/subagents/apis/static-analysis.d.ts.map +1 -0
- package/dist/ai-service/agent/{apis-static-analysis.js → subagents/apis/static-analysis.js} +3 -2
- package/dist/ai-service/agent/subagents/apis/static-analysis.js.map +1 -0
- package/dist/ai-service/agent/subagents/apis/system-prompt.d.ts +3 -0
- package/dist/ai-service/agent/subagents/apis/system-prompt.d.ts.map +1 -0
- package/dist/ai-service/agent/{apis-system-prompt.js → subagents/apis/system-prompt.js} +67 -31
- package/dist/ai-service/agent/{apis-system-prompt.js.map → subagents/apis/system-prompt.js.map} +1 -1
- package/dist/ai-service/agent/tool-message-utils.d.ts +6 -15
- package/dist/ai-service/agent/tool-message-utils.d.ts.map +1 -1
- package/dist/ai-service/agent/tool-message-utils.js +75 -248
- package/dist/ai-service/agent/tool-message-utils.js.map +1 -1
- package/dist/ai-service/agent/tools/build-add-event.d.ts +2 -4
- package/dist/ai-service/agent/tools/build-add-event.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-add-event.js +9 -8
- package/dist/ai-service/agent/tools/build-add-event.js.map +1 -1
- package/dist/ai-service/agent/tools/build-add-state-var.d.ts +2 -4
- package/dist/ai-service/agent/tools/build-add-state-var.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-add-state-var.js +6 -5
- package/dist/ai-service/agent/tools/build-add-state-var.js.map +1 -1
- package/dist/ai-service/agent/tools/build-add-timer.d.ts +2 -4
- package/dist/ai-service/agent/tools/build-add-timer.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-add-timer.js +7 -6
- package/dist/ai-service/agent/tools/build-add-timer.js.map +1 -1
- package/dist/ai-service/agent/tools/build-create-page.d.ts +2 -3
- package/dist/ai-service/agent/tools/build-create-page.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-create-page.js +11 -10
- package/dist/ai-service/agent/tools/build-create-page.js.map +1 -1
- package/dist/ai-service/agent/tools/build-debug.d.ts +1 -3
- package/dist/ai-service/agent/tools/build-debug.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-debug.js +7 -5
- package/dist/ai-service/agent/tools/build-debug.js.map +1 -1
- package/dist/ai-service/agent/tools/build-edit-file.d.ts +2 -4
- package/dist/ai-service/agent/tools/build-edit-file.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-edit-file.js +10 -7
- package/dist/ai-service/agent/tools/build-edit-file.js.map +1 -1
- package/dist/ai-service/agent/tools/build-finalize.d.ts +2 -4
- package/dist/ai-service/agent/tools/build-finalize.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-finalize.js +7 -6
- package/dist/ai-service/agent/tools/build-finalize.js.map +1 -1
- package/dist/ai-service/agent/tools/build-install-packages.d.ts +2 -4
- package/dist/ai-service/agent/tools/build-install-packages.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-install-packages.js +7 -6
- package/dist/ai-service/agent/tools/build-install-packages.js.map +1 -1
- package/dist/ai-service/agent/tools/build-list-available-components.d.ts +3 -8
- package/dist/ai-service/agent/tools/build-list-available-components.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-list-available-components.js +30 -9
- package/dist/ai-service/agent/tools/build-list-available-components.js.map +1 -1
- package/dist/ai-service/agent/tools/build-list-files.d.ts +2 -3
- package/dist/ai-service/agent/tools/build-list-files.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-list-files.js +10 -8
- package/dist/ai-service/agent/tools/build-list-files.js.map +1 -1
- package/dist/ai-service/agent/tools/build-manage-checklist.d.ts +3 -3
- package/dist/ai-service/agent/tools/build-manage-checklist.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-manage-checklist.js +9 -8
- package/dist/ai-service/agent/tools/build-manage-checklist.js.map +1 -1
- package/dist/ai-service/agent/tools/build-multi-edit-file.d.ts +2 -4
- package/dist/ai-service/agent/tools/build-multi-edit-file.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-multi-edit-file.js +9 -6
- package/dist/ai-service/agent/tools/build-multi-edit-file.js.map +1 -1
- package/dist/ai-service/agent/tools/build-read-files.d.ts +2 -4
- package/dist/ai-service/agent/tools/build-read-files.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-read-files.js +10 -8
- package/dist/ai-service/agent/tools/build-read-files.js.map +1 -1
- package/dist/ai-service/agent/tools/build-register-component-name.d.ts +2 -4
- package/dist/ai-service/agent/tools/build-register-component-name.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-register-component-name.js +9 -8
- package/dist/ai-service/agent/tools/build-register-component-name.js.map +1 -1
- package/dist/ai-service/agent/tools/build-rename-page.d.ts +2 -3
- package/dist/ai-service/agent/tools/build-rename-page.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-rename-page.js +6 -5
- package/dist/ai-service/agent/tools/build-rename-page.js.map +1 -1
- package/dist/ai-service/agent/tools/build-set-api-triggers.d.ts +2 -4
- package/dist/ai-service/agent/tools/build-set-api-triggers.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-set-api-triggers.js +6 -5
- package/dist/ai-service/agent/tools/build-set-api-triggers.js.map +1 -1
- package/dist/ai-service/agent/tools/build-update-state-var.d.ts +2 -3
- package/dist/ai-service/agent/tools/build-update-state-var.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-update-state-var.js +6 -5
- package/dist/ai-service/agent/tools/build-update-state-var.js.map +1 -1
- package/dist/ai-service/agent/tools/build-validate-icons.d.ts +2 -3
- package/dist/ai-service/agent/tools/build-validate-icons.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-validate-icons.js +8 -6
- package/dist/ai-service/agent/tools/build-validate-icons.js.map +1 -1
- package/dist/ai-service/agent/tools/build-write-file.d.ts +2 -4
- package/dist/ai-service/agent/tools/build-write-file.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-write-file.js +6 -5
- package/dist/ai-service/agent/tools/build-write-file.js.map +1 -1
- package/dist/ai-service/agent/tools/debug-cache.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/debug-cache.js +4 -1
- package/dist/ai-service/agent/tools/debug-cache.js.map +1 -1
- package/dist/ai-service/agent/tools/index.d.ts +23 -20
- package/dist/ai-service/agent/tools/index.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/index.js +23 -20
- package/dist/ai-service/agent/tools/index.js.map +1 -1
- package/dist/ai-service/agent/tools/integrations/execute-request.d.ts +25 -0
- package/dist/ai-service/agent/tools/integrations/execute-request.d.ts.map +1 -0
- package/dist/ai-service/agent/tools/integrations/execute-request.js +213 -0
- package/dist/ai-service/agent/tools/integrations/execute-request.js.map +1 -0
- package/dist/ai-service/agent/tools/integrations/index.d.ts +4 -0
- package/dist/ai-service/agent/tools/integrations/index.d.ts.map +1 -0
- package/dist/ai-service/agent/tools/integrations/index.js +4 -0
- package/dist/ai-service/agent/tools/integrations/index.js.map +1 -0
- package/dist/ai-service/agent/tools/integrations/internal.d.ts +3 -0
- package/dist/ai-service/agent/tools/integrations/internal.d.ts.map +1 -0
- package/dist/ai-service/agent/tools/integrations/internal.js +11 -0
- package/dist/ai-service/agent/tools/integrations/internal.js.map +1 -0
- package/dist/ai-service/agent/tools/integrations/metadata.d.ts +10 -0
- package/dist/ai-service/agent/tools/integrations/metadata.d.ts.map +1 -0
- package/dist/ai-service/agent/tools/integrations/metadata.js +80 -0
- package/dist/ai-service/agent/tools/integrations/metadata.js.map +1 -0
- package/dist/ai-service/agent/tools/integrations/run-code.d.ts +5 -0
- package/dist/ai-service/agent/tools/integrations/run-code.d.ts.map +1 -0
- package/dist/ai-service/agent/tools/integrations/run-code.js +32 -0
- package/dist/ai-service/agent/tools/integrations/run-code.js.map +1 -0
- package/dist/ai-service/agent/tools/study-current-app-state.d.ts +2 -4
- package/dist/ai-service/agent/tools/study-current-app-state.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/study-current-app-state.js +10 -8
- package/dist/ai-service/agent/tools/study-current-app-state.js.map +1 -1
- package/dist/ai-service/agent/tools.d.ts +3 -280
- package/dist/ai-service/agent/tools.d.ts.map +1 -1
- package/dist/ai-service/agent/tools.js +68 -55
- package/dist/ai-service/agent/tools.js.map +1 -1
- package/dist/ai-service/agent/tools2/access-control.d.ts +119 -0
- package/dist/ai-service/agent/tools2/access-control.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/access-control.js +216 -0
- package/dist/ai-service/agent/tools2/access-control.js.map +1 -0
- package/dist/ai-service/agent/tools2/example.d.ts +13 -0
- package/dist/ai-service/agent/tools2/example.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/example.js +143 -0
- package/dist/ai-service/agent/tools2/example.js.map +1 -0
- package/dist/ai-service/agent/tools2/index.d.ts +16 -0
- package/dist/ai-service/agent/tools2/index.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/index.js +18 -0
- package/dist/ai-service/agent/tools2/index.js.map +1 -0
- package/dist/ai-service/agent/tools2/registry.d.ts +167 -0
- package/dist/ai-service/agent/tools2/registry.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/registry.js +305 -0
- package/dist/ai-service/agent/tools2/registry.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/ask-multi-choice.d.ts +12 -0
- package/dist/ai-service/agent/tools2/tools/ask-multi-choice.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/ask-multi-choice.js +73 -0
- package/dist/ai-service/agent/tools2/tools/ask-multi-choice.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/bash.d.ts +34 -0
- package/dist/ai-service/agent/tools2/tools/bash.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/bash.js +76 -0
- package/dist/ai-service/agent/tools2/tools/bash.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/edit.d.ts +14 -0
- package/dist/ai-service/agent/tools2/tools/edit.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/edit.js +60 -0
- package/dist/ai-service/agent/tools2/tools/edit.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/exit-plan-mode.d.ts +10 -0
- package/dist/ai-service/agent/tools2/tools/exit-plan-mode.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/exit-plan-mode.js +66 -0
- package/dist/ai-service/agent/tools2/tools/exit-plan-mode.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/glob.d.ts +11 -0
- package/dist/ai-service/agent/tools2/tools/glob.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/glob.js +44 -0
- package/dist/ai-service/agent/tools2/tools/glob.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/grep.d.ts +21 -0
- package/dist/ai-service/agent/tools2/tools/grep.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/grep.js +100 -0
- package/dist/ai-service/agent/tools2/tools/grep.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/index.d.ts +13 -0
- package/dist/ai-service/agent/tools2/tools/index.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/index.js +13 -0
- package/dist/ai-service/agent/tools2/tools/index.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/read.d.ts +9 -0
- package/dist/ai-service/agent/tools2/tools/read.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/read.js +43 -0
- package/dist/ai-service/agent/tools2/tools/read.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/write.d.ts +11 -0
- package/dist/ai-service/agent/tools2/tools/write.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/write.js +28 -0
- package/dist/ai-service/agent/tools2/tools/write.js.map +1 -0
- package/dist/ai-service/agent/tools2/types.d.ts +148 -0
- package/dist/ai-service/agent/tools2/types.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/types.js +55 -0
- package/dist/ai-service/agent/tools2/types.js.map +1 -0
- package/dist/ai-service/agent/utils.d.ts +2 -3
- package/dist/ai-service/agent/utils.d.ts.map +1 -1
- package/dist/ai-service/agent/utils.js +14 -13
- package/dist/ai-service/agent/utils.js.map +1 -1
- package/dist/ai-service/chat/chat-session-store.d.ts +5 -0
- package/dist/ai-service/chat/chat-session-store.d.ts.map +1 -1
- package/dist/ai-service/chat/chat-session-store.js +484 -345
- package/dist/ai-service/chat/chat-session-store.js.map +1 -1
- package/dist/ai-service/chat/extract-history.d.ts +1 -0
- package/dist/ai-service/chat/extract-history.d.ts.map +1 -1
- package/dist/ai-service/chat/extract-history.js +12 -1
- package/dist/ai-service/chat/extract-history.js.map +1 -1
- package/dist/ai-service/const.d.ts +2 -1
- package/dist/ai-service/const.d.ts.map +1 -1
- package/dist/ai-service/const.js +7 -1
- package/dist/ai-service/const.js.map +1 -1
- package/dist/ai-service/index.d.ts +9 -8
- package/dist/ai-service/index.d.ts.map +1 -1
- package/dist/ai-service/index.js +7 -0
- package/dist/ai-service/index.js.map +1 -1
- package/dist/ai-service/integrations/metadata/database.d.ts.map +1 -1
- package/dist/ai-service/integrations/metadata/database.js +3 -29
- package/dist/ai-service/integrations/metadata/database.js.map +1 -1
- package/dist/ai-service/integrations/metadata/databricks.d.ts +25 -0
- package/dist/ai-service/integrations/metadata/databricks.d.ts.map +1 -0
- package/dist/ai-service/integrations/metadata/databricks.js +174 -0
- package/dist/ai-service/integrations/metadata/databricks.js.map +1 -0
- package/dist/ai-service/integrations/store.d.ts +34 -4
- package/dist/ai-service/integrations/store.d.ts.map +1 -1
- package/dist/ai-service/integrations/store.js +125 -5
- package/dist/ai-service/integrations/store.js.map +1 -1
- package/dist/ai-service/llm/context/caching/constants.d.ts +27 -0
- package/dist/ai-service/llm/context/caching/constants.d.ts.map +1 -0
- package/dist/ai-service/llm/context/caching/constants.js +20 -0
- package/dist/ai-service/llm/context/caching/constants.js.map +1 -0
- package/dist/ai-service/llm/context/caching/factory.d.ts +12 -0
- package/dist/ai-service/llm/context/caching/factory.d.ts.map +1 -0
- package/dist/ai-service/llm/context/caching/factory.js +28 -0
- package/dist/ai-service/llm/context/caching/factory.js.map +1 -0
- package/dist/ai-service/llm/context/caching/index.d.ts +10 -0
- package/dist/ai-service/llm/context/caching/index.d.ts.map +1 -0
- package/dist/ai-service/llm/context/caching/index.js +9 -0
- package/dist/ai-service/llm/context/caching/index.js.map +1 -0
- package/dist/ai-service/llm/context/caching/quantized-strategy.d.ts +22 -0
- package/dist/ai-service/llm/context/caching/quantized-strategy.d.ts.map +1 -0
- package/dist/ai-service/llm/context/caching/quantized-strategy.js +48 -0
- package/dist/ai-service/llm/context/caching/quantized-strategy.js.map +1 -0
- package/dist/ai-service/llm/context/caching/strategy.d.ts +20 -0
- package/dist/ai-service/llm/context/caching/strategy.d.ts.map +1 -0
- package/dist/ai-service/llm/context/caching/strategy.js +5 -0
- package/dist/ai-service/llm/context/caching/strategy.js.map +1 -0
- package/dist/ai-service/llm/context/caching/types.d.ts +34 -0
- package/dist/ai-service/llm/context/caching/types.d.ts.map +1 -0
- package/dist/ai-service/llm/context/caching/types.js +8 -0
- package/dist/ai-service/llm/context/caching/types.js.map +1 -0
- package/dist/ai-service/llm/context/config.d.ts +51 -0
- package/dist/ai-service/llm/context/config.d.ts.map +1 -0
- package/dist/ai-service/llm/context/config.js +58 -0
- package/dist/ai-service/llm/context/config.js.map +1 -0
- package/dist/ai-service/llm/context/constants.d.ts +106 -0
- package/dist/ai-service/llm/context/constants.d.ts.map +1 -0
- package/dist/ai-service/llm/context/constants.js +106 -0
- package/dist/ai-service/llm/context/constants.js.map +1 -0
- package/dist/ai-service/llm/context/context.d.ts +207 -0
- package/dist/ai-service/llm/context/context.d.ts.map +1 -0
- package/dist/ai-service/llm/context/context.js +742 -0
- package/dist/ai-service/llm/context/context.js.map +1 -0
- package/dist/ai-service/llm/context/errors.d.ts +45 -0
- package/dist/ai-service/llm/context/errors.d.ts.map +1 -0
- package/dist/ai-service/llm/context/errors.js +56 -0
- package/dist/ai-service/llm/context/errors.js.map +1 -0
- package/dist/ai-service/llm/context/index.d.ts +13 -0
- package/dist/ai-service/llm/context/index.d.ts.map +1 -0
- package/dist/ai-service/llm/context/index.js +17 -0
- package/dist/ai-service/llm/context/index.js.map +1 -0
- package/dist/ai-service/llm/context/internal-types.d.ts +52 -0
- package/dist/ai-service/llm/context/internal-types.d.ts.map +1 -0
- package/dist/ai-service/llm/context/internal-types.js +28 -0
- package/dist/ai-service/llm/context/internal-types.js.map +1 -0
- package/dist/ai-service/llm/context/levels/index.d.ts +12 -0
- package/dist/ai-service/llm/context/levels/index.d.ts.map +1 -0
- package/dist/ai-service/llm/context/levels/index.js +12 -0
- package/dist/ai-service/llm/context/levels/index.js.map +1 -0
- package/dist/ai-service/llm/context/levels/l1.d.ts +83 -0
- package/dist/ai-service/llm/context/levels/l1.d.ts.map +1 -0
- package/dist/ai-service/llm/context/levels/l1.js +143 -0
- package/dist/ai-service/llm/context/levels/l1.js.map +1 -0
- package/dist/ai-service/llm/context/levels/l2.d.ts +60 -0
- package/dist/ai-service/llm/context/levels/l2.d.ts.map +1 -0
- package/dist/ai-service/llm/context/levels/l2.js +96 -0
- package/dist/ai-service/llm/context/levels/l2.js.map +1 -0
- package/dist/ai-service/llm/context/levels/l3.d.ts +46 -0
- package/dist/ai-service/llm/context/levels/l3.d.ts.map +1 -0
- package/dist/ai-service/llm/context/levels/l3.js +70 -0
- package/dist/ai-service/llm/context/levels/l3.js.map +1 -0
- package/dist/ai-service/llm/context/logger.d.ts +17 -0
- package/dist/ai-service/llm/context/logger.d.ts.map +1 -0
- package/dist/ai-service/llm/context/logger.js +26 -0
- package/dist/ai-service/llm/context/logger.js.map +1 -0
- package/dist/ai-service/llm/context/manager.d.ts +79 -0
- package/dist/ai-service/llm/context/manager.d.ts.map +1 -0
- package/dist/ai-service/llm/context/manager.js +136 -0
- package/dist/ai-service/llm/context/manager.js.map +1 -0
- package/dist/ai-service/llm/context/options.d.ts +43 -0
- package/dist/ai-service/llm/context/options.d.ts.map +1 -0
- package/dist/ai-service/llm/context/options.js +81 -0
- package/dist/ai-service/llm/context/options.js.map +1 -0
- package/dist/ai-service/llm/context/serialization.d.ts +56 -0
- package/dist/ai-service/llm/context/serialization.d.ts.map +1 -0
- package/dist/ai-service/llm/context/serialization.js +9 -0
- package/dist/ai-service/llm/context/serialization.js.map +1 -0
- package/dist/ai-service/llm/context/storage/index.d.ts +10 -0
- package/dist/ai-service/llm/context/storage/index.d.ts.map +1 -0
- package/dist/ai-service/llm/context/storage/index.js +2 -0
- package/dist/ai-service/llm/context/storage/index.js.map +1 -0
- package/dist/ai-service/llm/context/storage/local.d.ts +22 -0
- package/dist/ai-service/llm/context/storage/local.d.ts.map +1 -0
- package/dist/ai-service/llm/context/storage/local.js +42 -0
- package/dist/ai-service/llm/context/storage/local.js.map +1 -0
- package/dist/ai-service/llm/context/types.d.ts +125 -0
- package/dist/ai-service/llm/context/types.d.ts.map +1 -0
- package/dist/ai-service/llm/context/types.js +5 -0
- package/dist/ai-service/llm/context/types.js.map +1 -0
- package/dist/ai-service/llm/context/utils/content-compaction.d.ts +26 -0
- package/dist/ai-service/llm/context/utils/content-compaction.d.ts.map +1 -0
- package/dist/ai-service/llm/context/utils/content-compaction.js +52 -0
- package/dist/ai-service/llm/context/utils/content-compaction.js.map +1 -0
- package/dist/ai-service/llm/context/utils/index.d.ts +10 -0
- package/dist/ai-service/llm/context/utils/index.d.ts.map +1 -0
- package/dist/ai-service/llm/context/utils/index.js +10 -0
- package/dist/ai-service/llm/context/utils/index.js.map +1 -0
- package/dist/ai-service/llm/context/utils/message-utils.d.ts +34 -0
- package/dist/ai-service/llm/context/utils/message-utils.d.ts.map +1 -0
- package/dist/ai-service/llm/context/utils/message-utils.js +73 -0
- package/dist/ai-service/llm/context/utils/message-utils.js.map +1 -0
- package/dist/ai-service/llm/context/utils/token-estimation.d.ts +31 -0
- package/dist/ai-service/llm/context/utils/token-estimation.d.ts.map +1 -0
- package/dist/ai-service/llm/context/utils/token-estimation.js +52 -0
- package/dist/ai-service/llm/context/utils/token-estimation.js.map +1 -0
- package/dist/ai-service/llm/context/utils/visualization.d.ts +40 -0
- package/dist/ai-service/llm/context/utils/visualization.d.ts.map +1 -0
- package/dist/ai-service/llm/context/utils/visualization.js +516 -0
- package/dist/ai-service/llm/context/utils/visualization.js.map +1 -0
- package/dist/ai-service/llm/impl/anthropic.js +2 -2
- package/dist/ai-service/llm/impl/anthropic.js.map +1 -1
- package/dist/ai-service/llmobs/helpers.d.ts.map +1 -1
- package/dist/ai-service/llmobs/helpers.js +10 -19
- package/dist/ai-service/llmobs/helpers.js.map +1 -1
- package/dist/ai-service/llmobs/middleware/stream-text.d.ts.map +1 -1
- package/dist/ai-service/llmobs/middleware/stream-text.js +16 -11
- package/dist/ai-service/llmobs/middleware/stream-text.js.map +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/ButtonPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/CheckboxPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/ColumnPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/ContainerPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/DatePickerPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/DropdownPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/IconPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/ImagePropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/InputPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/ModalPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/PagePropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/SectionPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/SlideoutPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/SwitchPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/TablePropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/TextPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-typedefs/Dim.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-typedefs/EventFlow.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-typedefs/TextStyleWithVariant.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/full-examples.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-api.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-components-rules.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-custom-components.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-data-filtering.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-event-flow.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-forms.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-layouts.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-page.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-rbac.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-routes.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-state.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-theming-chakra-new.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/system-base.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/system-incremental.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/system-specific-edit.js +1 -1
- package/dist/ai-service/state-machine/clark-fsm.d.ts +9 -5
- package/dist/ai-service/state-machine/clark-fsm.d.ts.map +1 -1
- package/dist/ai-service/state-machine/clark-fsm.js.map +1 -1
- package/dist/ai-service/state-machine/handlers/agent-planning.d.ts.map +1 -1
- package/dist/ai-service/state-machine/handlers/agent-planning.js +36 -9
- package/dist/ai-service/state-machine/handlers/agent-planning.js.map +1 -1
- package/dist/ai-service/state-machine/handlers/llm-generating.d.ts.map +1 -1
- package/dist/ai-service/state-machine/handlers/llm-generating.js +161 -104
- package/dist/ai-service/state-machine/handlers/llm-generating.js.map +1 -1
- package/dist/ai-service/state-machine/helpers/context-id.d.ts +4 -0
- package/dist/ai-service/state-machine/helpers/context-id.d.ts.map +1 -0
- package/dist/ai-service/state-machine/helpers/context-id.js +16 -0
- package/dist/ai-service/state-machine/helpers/context-id.js.map +1 -0
- package/dist/ai-service/state-machine/helpers/peer.d.ts.map +1 -1
- package/dist/ai-service/state-machine/helpers/peer.js +7 -4
- package/dist/ai-service/state-machine/helpers/peer.js.map +1 -1
- package/dist/ai-service/state-machine/mocks.d.ts +2 -3
- package/dist/ai-service/state-machine/mocks.d.ts.map +1 -1
- package/dist/ai-service/state-machine/mocks.js.map +1 -1
- package/dist/ai-service/types.d.ts +3 -0
- package/dist/ai-service/types.d.ts.map +1 -1
- package/dist/ai-service/types.js.map +1 -1
- package/dist/ai-service/util/parse-jwt.d.ts +12 -0
- package/dist/ai-service/util/parse-jwt.d.ts.map +1 -0
- package/dist/ai-service/util/parse-jwt.js +30 -0
- package/dist/ai-service/util/parse-jwt.js.map +1 -0
- package/dist/ai-service/util/safe-stringify.d.ts +1 -1
- package/dist/ai-service/util/safe-stringify.d.ts.map +1 -1
- package/dist/ai-service/util/safe-stringify.js +3 -3
- package/dist/ai-service/util/safe-stringify.js.map +1 -1
- package/dist/binding-extraction/extract-js-identifiers.d.ts.map +1 -1
- package/dist/binding-extraction/extract-js-identifiers.js +1 -1
- package/dist/binding-extraction/extract-js-identifiers.js.map +1 -1
- package/dist/build-errors.d.ts +10 -0
- package/dist/build-errors.d.ts.map +1 -0
- package/dist/build-errors.js +14 -0
- package/dist/build-errors.js.map +1 -0
- package/dist/client-error-overlay.d.ts +7 -0
- package/dist/client-error-overlay.d.ts.map +1 -0
- package/dist/client-error-overlay.js +124 -0
- package/dist/client-error-overlay.js.map +1 -0
- package/dist/component-docs-service/index.d.ts.map +1 -1
- package/dist/component-docs-service/index.js +0 -2
- package/dist/component-docs-service/index.js.map +1 -1
- package/dist/file-sync-vite-plugin.d.ts.map +1 -1
- package/dist/file-sync-vite-plugin.js +37 -26
- package/dist/file-sync-vite-plugin.js.map +1 -1
- package/dist/injected-index.d.ts.map +1 -1
- package/dist/injected-index.js +6 -1
- package/dist/injected-index.js.map +1 -1
- package/dist/routing.d.ts.map +1 -1
- package/dist/routing.js +0 -18
- package/dist/routing.js.map +1 -1
- package/package.json +8 -8
- package/dist/ai-service/agent/apis-static-analysis.d.ts.map +0 -1
- package/dist/ai-service/agent/apis-static-analysis.js.map +0 -1
- package/dist/ai-service/agent/apis-system-prompt.d.ts +0 -3
- package/dist/ai-service/agent/apis-system-prompt.d.ts.map +0 -1
- package/dist/ai-service/agent/apis.d.ts +0 -55
- package/dist/ai-service/agent/apis.d.ts.map +0 -1
- package/dist/ai-service/agent/apis.js.map +0 -1
|
@@ -0,0 +1,1229 @@
|
|
|
1
|
+
import { buildApiPrompt, } from "./prompt-builder.js";
|
|
2
|
+
export const VALID_TAGS = [
|
|
3
|
+
// Control flow
|
|
4
|
+
"loop",
|
|
5
|
+
"conditional",
|
|
6
|
+
"trycatch",
|
|
7
|
+
"nested-control-flow",
|
|
8
|
+
// Integrations w/ special guidance
|
|
9
|
+
"snowflake",
|
|
10
|
+
"databricks",
|
|
11
|
+
// Patterns
|
|
12
|
+
"scope-access",
|
|
13
|
+
"variable-access",
|
|
14
|
+
"error-handling",
|
|
15
|
+
"validation",
|
|
16
|
+
"data-transformation",
|
|
17
|
+
"batch-processing",
|
|
18
|
+
"global-context",
|
|
19
|
+
"multi-integration",
|
|
20
|
+
"data-science",
|
|
21
|
+
"sql-query",
|
|
22
|
+
"aggregation",
|
|
23
|
+
// Error types (for negative examples)
|
|
24
|
+
"error-scope-violation",
|
|
25
|
+
"error-execution-order",
|
|
26
|
+
];
|
|
27
|
+
export const POSITIVE_EXAMPLES = [
|
|
28
|
+
{
|
|
29
|
+
id: "getUsersByStatusApi",
|
|
30
|
+
metadata: {
|
|
31
|
+
tags: ["conditional", "validation", "sql-query"],
|
|
32
|
+
complexity: "simple",
|
|
33
|
+
category: "positive",
|
|
34
|
+
estimatedTokens: 450,
|
|
35
|
+
},
|
|
36
|
+
inputContext: {
|
|
37
|
+
pageEntities: [{ name: "statusFilter", type: "Variable" }],
|
|
38
|
+
availableIntegrations: [
|
|
39
|
+
{
|
|
40
|
+
name: "PostgresDB",
|
|
41
|
+
id: "<postgres-integration-id>",
|
|
42
|
+
type: "PostgreSQL",
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
integrationMetadata: [
|
|
46
|
+
{
|
|
47
|
+
integrationId: "<postgres-integration-id>",
|
|
48
|
+
metadata: {
|
|
49
|
+
databaseSchemaMetadata: {
|
|
50
|
+
tables: [
|
|
51
|
+
{
|
|
52
|
+
type: "TABLE",
|
|
53
|
+
name: "users",
|
|
54
|
+
schema: "public",
|
|
55
|
+
columns: [
|
|
56
|
+
{ name: "id", type: "int4" },
|
|
57
|
+
{ name: "email", type: "varchar" },
|
|
58
|
+
{ name: "full_name", type: "varchar" },
|
|
59
|
+
{ name: "status", type: "varchar" },
|
|
60
|
+
{ name: "created_at", type: "timestamp" },
|
|
61
|
+
{ name: "last_login", type: "timestamp" },
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
userPrompt: "Create an API that fetches users filtered by their account status. The API should accept a status filter from the statusFilter variable and validate it against allowed values (active, inactive, pending). If an invalid status is provided, throw an error. Query the PostgreSQL database to fetch user details including id, email, full_name, status, created_at, and last_login. Sort results by creation date (newest first). Return a formatted response with the user list, count, applied filter, and timestamp.",
|
|
71
|
+
code: `import {
|
|
72
|
+
Api,
|
|
73
|
+
PostgreSQL,
|
|
74
|
+
Conditional,
|
|
75
|
+
Throw,
|
|
76
|
+
JavaScript,
|
|
77
|
+
} from "@superblocksteam/library";
|
|
78
|
+
|
|
79
|
+
export default new Api("getUsersByStatusApi", [
|
|
80
|
+
new Conditional("validate_status_input", {
|
|
81
|
+
if: {
|
|
82
|
+
when: ({ statusFilter }) => {
|
|
83
|
+
const validStatuses = ['active', 'inactive', 'pending'];
|
|
84
|
+
return statusFilter.value && !validStatuses.includes(statusFilter.value);
|
|
85
|
+
},
|
|
86
|
+
then: [
|
|
87
|
+
new Throw("invalid_status", {
|
|
88
|
+
error: "Status must be one of: active, inactive, pending"
|
|
89
|
+
})
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
}),
|
|
93
|
+
new JavaScript("get_validated_status", {
|
|
94
|
+
fn: ({ statusFilter }) => {
|
|
95
|
+
const validStatuses = ['active', 'inactive', 'pending'];
|
|
96
|
+
return validStatuses.includes(statusFilter.value) ? statusFilter.value : 'active';
|
|
97
|
+
}
|
|
98
|
+
}),
|
|
99
|
+
new PostgreSQL("fetch_users", "<postgres-integration-id>", {
|
|
100
|
+
statement: ({ get_validated_status }) => \`
|
|
101
|
+
SELECT
|
|
102
|
+
id,
|
|
103
|
+
email,
|
|
104
|
+
full_name,
|
|
105
|
+
status,
|
|
106
|
+
created_at,
|
|
107
|
+
last_login
|
|
108
|
+
FROM users
|
|
109
|
+
WHERE status = '\${get_validated_status.output}'
|
|
110
|
+
ORDER BY created_at DESC
|
|
111
|
+
LIMIT 500
|
|
112
|
+
\`
|
|
113
|
+
}),
|
|
114
|
+
new JavaScript("format_response", {
|
|
115
|
+
fn: ({ fetch_users, get_validated_status }) => ({
|
|
116
|
+
users: fetch_users.output || [],
|
|
117
|
+
count: (fetch_users.output || []).length,
|
|
118
|
+
filterApplied: get_validated_status.output,
|
|
119
|
+
timestamp: new Date().toISOString()
|
|
120
|
+
})
|
|
121
|
+
})
|
|
122
|
+
]);`,
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
id: "getOrderSummaryApi",
|
|
126
|
+
metadata: {
|
|
127
|
+
tags: ["data-transformation", "sql-query", "aggregation"],
|
|
128
|
+
complexity: "intermediate",
|
|
129
|
+
category: "positive",
|
|
130
|
+
estimatedTokens: 520,
|
|
131
|
+
},
|
|
132
|
+
userPrompt: "Create an API that generates comprehensive order analytics. The API should: 1) Fetch the most recent orders from the orders table including id, customer_id, total_amount, status, item_count, and created_at. 2) Calculate aggregate statistics including total orders, total revenue, average order value, total items sold, and a breakdown by order status. 3) Identify the top 10 customers by total spending, showing their customer ID, order count, and total amount spent. 4) Return a formatted response with the statistics, top customers list, and a sample of the 5 most recent orders along with a generation timestamp.",
|
|
133
|
+
code: `import {
|
|
134
|
+
Api,
|
|
135
|
+
PostgreSQL,
|
|
136
|
+
JavaScript,
|
|
137
|
+
} from "@superblocksteam/library";
|
|
138
|
+
|
|
139
|
+
export default new Api("getOrderSummaryApi", [
|
|
140
|
+
new PostgreSQL("fetch_recent_orders", "<postgres-integration-id>", {
|
|
141
|
+
statement: () => \`
|
|
142
|
+
SELECT
|
|
143
|
+
id,
|
|
144
|
+
customer_id,
|
|
145
|
+
total_amount,
|
|
146
|
+
status,
|
|
147
|
+
item_count,
|
|
148
|
+
created_at
|
|
149
|
+
FROM orders
|
|
150
|
+
ORDER BY created_at DESC
|
|
151
|
+
LIMIT 500
|
|
152
|
+
\`
|
|
153
|
+
}),
|
|
154
|
+
new JavaScript("calculate_statistics", {
|
|
155
|
+
fn: ({ fetch_recent_orders }) => {
|
|
156
|
+
const orders = fetch_recent_orders.output || [];
|
|
157
|
+
|
|
158
|
+
const stats = {
|
|
159
|
+
totalOrders: orders.length,
|
|
160
|
+
totalRevenue: 0,
|
|
161
|
+
averageOrderValue: 0,
|
|
162
|
+
totalItems: 0,
|
|
163
|
+
statusBreakdown: {}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
orders.forEach(order => {
|
|
167
|
+
stats.totalRevenue += order.total_amount || 0;
|
|
168
|
+
stats.totalItems += order.item_count || 0;
|
|
169
|
+
|
|
170
|
+
const status = order.status || 'unknown';
|
|
171
|
+
stats.statusBreakdown[status] = (stats.statusBreakdown[status] || 0) + 1;
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
if (stats.totalOrders > 0) {
|
|
175
|
+
stats.averageOrderValue = stats.totalRevenue / stats.totalOrders;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return stats;
|
|
179
|
+
}
|
|
180
|
+
}),
|
|
181
|
+
new JavaScript("identify_top_customers", {
|
|
182
|
+
fn: ({ fetch_recent_orders }) => {
|
|
183
|
+
const orders = fetch_recent_orders.output || [];
|
|
184
|
+
const customerTotals: Record<string, { customerId: string; orderCount: number; totalSpent: number }> = {};
|
|
185
|
+
|
|
186
|
+
orders.forEach(order => {
|
|
187
|
+
const customerId = order.customer_id;
|
|
188
|
+
if (!customerTotals[customerId]) {
|
|
189
|
+
customerTotals[customerId] = { customerId, orderCount: 0, totalSpent: 0 };
|
|
190
|
+
}
|
|
191
|
+
customerTotals[customerId].orderCount += 1;
|
|
192
|
+
customerTotals[customerId].totalSpent += order.total_amount || 0;
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
return Object.values(customerTotals)
|
|
196
|
+
.sort((a, b) => b.totalSpent - a.totalSpent)
|
|
197
|
+
.slice(0, 10);
|
|
198
|
+
}
|
|
199
|
+
}),
|
|
200
|
+
new JavaScript("format_final_response", {
|
|
201
|
+
fn: ({ calculate_statistics, identify_top_customers, fetch_recent_orders }) => ({
|
|
202
|
+
statistics: calculate_statistics.output,
|
|
203
|
+
topCustomers: identify_top_customers.output,
|
|
204
|
+
sampleOrders: (fetch_recent_orders.output || []).slice(0, 5),
|
|
205
|
+
generatedAt: new Date().toISOString()
|
|
206
|
+
})
|
|
207
|
+
})
|
|
208
|
+
]);`,
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
id: "processOrderBatchApi",
|
|
212
|
+
metadata: {
|
|
213
|
+
tags: ["loop", "conditional", "batch-processing", "nested-control-flow"],
|
|
214
|
+
complexity: "intermediate",
|
|
215
|
+
category: "positive",
|
|
216
|
+
estimatedTokens: 680,
|
|
217
|
+
},
|
|
218
|
+
userPrompt: "Create an API that processes pending orders in batch. The API should: 1) Fetch up to 100 pending orders from the orders table, sorted by creation date (oldest first). 2) Loop through each order and determine the processing type based on order amount - orders over $1000 get premium processing with 1% fee and priority 1, others get standard processing with 2% fee and priority 2. 3) For each order, update the database to set status to 'processing', save the processing type, fee, and priority, and update the timestamp. 4) Return a summary showing total orders processed, successful updates, and processing timestamp. This will be used by the order fulfillment team to automatically triage and process incoming orders.",
|
|
219
|
+
code: `import {
|
|
220
|
+
Api,
|
|
221
|
+
PostgreSQL,
|
|
222
|
+
Loop,
|
|
223
|
+
Conditional,
|
|
224
|
+
JavaScript,
|
|
225
|
+
} from "@superblocksteam/library";
|
|
226
|
+
|
|
227
|
+
export default new Api("processOrderBatchApi", [
|
|
228
|
+
new PostgreSQL("fetch_pending_orders", "<postgres-integration-id>", {
|
|
229
|
+
statement: () => \`
|
|
230
|
+
SELECT
|
|
231
|
+
id,
|
|
232
|
+
customer_id,
|
|
233
|
+
total_amount,
|
|
234
|
+
items_count,
|
|
235
|
+
created_at
|
|
236
|
+
FROM orders
|
|
237
|
+
WHERE status = 'pending'
|
|
238
|
+
ORDER BY created_at ASC
|
|
239
|
+
LIMIT 100
|
|
240
|
+
\`
|
|
241
|
+
}),
|
|
242
|
+
new Loop("process_each_order", {
|
|
243
|
+
over: ({ fetch_pending_orders }) => fetch_pending_orders.output,
|
|
244
|
+
variables: { item: "order", index: "idx" },
|
|
245
|
+
blocks: [
|
|
246
|
+
new Conditional("determine_processing_type", {
|
|
247
|
+
if: {
|
|
248
|
+
when: ({ order }) => order.value.total_amount > 1000,
|
|
249
|
+
then: [
|
|
250
|
+
new JavaScript("calculate_premium_fee", {
|
|
251
|
+
fn: ({ order }) => ({
|
|
252
|
+
processing_type: 'premium',
|
|
253
|
+
priority: 1,
|
|
254
|
+
fee: order.value.total_amount * 0.01
|
|
255
|
+
})
|
|
256
|
+
})
|
|
257
|
+
]
|
|
258
|
+
},
|
|
259
|
+
else: [
|
|
260
|
+
new JavaScript("calculate_standard_fee", {
|
|
261
|
+
fn: ({ order }) => ({
|
|
262
|
+
processing_type: 'standard',
|
|
263
|
+
priority: 2,
|
|
264
|
+
fee: order.value.total_amount * 0.02
|
|
265
|
+
})
|
|
266
|
+
})
|
|
267
|
+
]
|
|
268
|
+
}),
|
|
269
|
+
new PostgreSQL("update_order", "<postgres-integration-id>", {
|
|
270
|
+
statement: ({ order, determine_processing_type }) => \`
|
|
271
|
+
UPDATE orders
|
|
272
|
+
SET
|
|
273
|
+
status = 'processing',
|
|
274
|
+
processing_type = '\${determine_processing_type.output.processing_type}',
|
|
275
|
+
processing_fee = \${determine_processing_type.output.fee},
|
|
276
|
+
priority = \${determine_processing_type.output.priority},
|
|
277
|
+
updated_at = NOW()
|
|
278
|
+
WHERE id = \${order.value.id}
|
|
279
|
+
\`
|
|
280
|
+
})
|
|
281
|
+
]
|
|
282
|
+
}),
|
|
283
|
+
new JavaScript("summarize_results", {
|
|
284
|
+
fn: ({ process_each_order, fetch_pending_orders }) => {
|
|
285
|
+
const updateResults = process_each_order.output || [];
|
|
286
|
+
const originalOrders = fetch_pending_orders.output || [];
|
|
287
|
+
|
|
288
|
+
return {
|
|
289
|
+
totalProcessed: originalOrders.length,
|
|
290
|
+
successfulUpdates: updateResults.rowCount || 0,
|
|
291
|
+
processedAt: new Date().toISOString()
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
})
|
|
295
|
+
]);`,
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
id: "getEnrichedCustomerDataApi",
|
|
299
|
+
metadata: {
|
|
300
|
+
tags: [
|
|
301
|
+
"trycatch",
|
|
302
|
+
"error-handling",
|
|
303
|
+
"conditional",
|
|
304
|
+
"validation",
|
|
305
|
+
"multi-integration",
|
|
306
|
+
],
|
|
307
|
+
complexity: "intermediate",
|
|
308
|
+
category: "positive",
|
|
309
|
+
estimatedTokens: 720,
|
|
310
|
+
},
|
|
311
|
+
inputContext: {
|
|
312
|
+
pageEntities: [{ name: "customerIdVar", type: "Variable" }],
|
|
313
|
+
availableIntegrations: [
|
|
314
|
+
{
|
|
315
|
+
name: "PostgresDB",
|
|
316
|
+
id: "<postgres-integration-id>",
|
|
317
|
+
type: "PostgreSQL",
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
name: "ProfileEnrichmentAPI",
|
|
321
|
+
id: "<openapi-integration-id>",
|
|
322
|
+
type: "OpenApi",
|
|
323
|
+
},
|
|
324
|
+
],
|
|
325
|
+
integrationMetadata: [
|
|
326
|
+
{
|
|
327
|
+
integrationId: "<postgres-integration-id>",
|
|
328
|
+
metadata: {
|
|
329
|
+
databaseSchemaMetadata: {
|
|
330
|
+
tables: [
|
|
331
|
+
{
|
|
332
|
+
type: "TABLE",
|
|
333
|
+
name: "customers",
|
|
334
|
+
schema: "public",
|
|
335
|
+
columns: [
|
|
336
|
+
{ name: "id", type: "int4" },
|
|
337
|
+
{ name: "email", type: "varchar" },
|
|
338
|
+
{ name: "full_name", type: "varchar" },
|
|
339
|
+
{ name: "account_type", type: "varchar" },
|
|
340
|
+
{ name: "created_at", type: "timestamp" },
|
|
341
|
+
],
|
|
342
|
+
},
|
|
343
|
+
],
|
|
344
|
+
},
|
|
345
|
+
},
|
|
346
|
+
},
|
|
347
|
+
],
|
|
348
|
+
},
|
|
349
|
+
userPrompt: "Create an API that enriches customer data from an external service. The API should: 1) Validate that the customerIdVar contains a valid positive number, throwing an error if invalid. 2) Fetch basic customer information (id, email, full_name, account_type, created_at) from the PostgreSQL customers table. 3) Attempt to enrich the customer data by calling an external profile enrichment API using the OpenAPI integration - this should fetch social score, verification status, and risk level. 4) If the external API fails, gracefully fall back to default enrichment data with social_score: 0, verified: false, and risk_level: 'unknown', and include the error message. 5) Merge the basic customer data with the enrichment data and return a combined profile including the enrichment source and success status. This will be used to display enhanced customer profiles in the CRM dashboard.",
|
|
350
|
+
code: `import {
|
|
351
|
+
Api,
|
|
352
|
+
PostgreSQL,
|
|
353
|
+
OpenApi,
|
|
354
|
+
TryCatch,
|
|
355
|
+
Conditional,
|
|
356
|
+
Throw,
|
|
357
|
+
JavaScript,
|
|
358
|
+
} from "@superblocksteam/library";
|
|
359
|
+
|
|
360
|
+
export default new Api("getEnrichedCustomerDataApi", [
|
|
361
|
+
new Conditional("validate_customer_id", {
|
|
362
|
+
if: {
|
|
363
|
+
when: ({ customerIdVar }) => {
|
|
364
|
+
const id = parseInt(customerIdVar.value);
|
|
365
|
+
return isNaN(id) || id <= 0;
|
|
366
|
+
},
|
|
367
|
+
then: [
|
|
368
|
+
new Throw("invalid_customer_id", {
|
|
369
|
+
error: "Customer ID must be a positive number"
|
|
370
|
+
})
|
|
371
|
+
]
|
|
372
|
+
}
|
|
373
|
+
}),
|
|
374
|
+
new PostgreSQL("fetch_customer_basic", "<postgres-integration-id>", {
|
|
375
|
+
statement: ({ customerIdVar }) => \`
|
|
376
|
+
SELECT
|
|
377
|
+
id,
|
|
378
|
+
email,
|
|
379
|
+
full_name,
|
|
380
|
+
account_type,
|
|
381
|
+
created_at
|
|
382
|
+
FROM customers
|
|
383
|
+
WHERE id = \${parseInt(customerIdVar.value)}
|
|
384
|
+
LIMIT 1
|
|
385
|
+
\`
|
|
386
|
+
}),
|
|
387
|
+
new TryCatch("fetch_external_enrichment", {
|
|
388
|
+
variables: { error: "enrichmentError" },
|
|
389
|
+
try: [
|
|
390
|
+
new OpenApi("call_enrichment_api", "<openapi-integration-id>", {
|
|
391
|
+
method: "GET",
|
|
392
|
+
url: ({ fetch_customer_basic }) => {
|
|
393
|
+
const customer = (fetch_customer_basic.output || [])[0];
|
|
394
|
+
return \`/profile/\${customer?.id || 0}\`;
|
|
395
|
+
},
|
|
396
|
+
headers: [
|
|
397
|
+
{ key: "Authorization", value: "Bearer sk_live_abc123xyz" }
|
|
398
|
+
]
|
|
399
|
+
}, {
|
|
400
|
+
path: "/profile/{id}"
|
|
401
|
+
}),
|
|
402
|
+
new JavaScript("format_enriched_data", {
|
|
403
|
+
fn: ({ call_enrichment_api }) => ({
|
|
404
|
+
success: true,
|
|
405
|
+
data: call_enrichment_api.output || {},
|
|
406
|
+
source: 'external_api'
|
|
407
|
+
})
|
|
408
|
+
})
|
|
409
|
+
],
|
|
410
|
+
catch: [
|
|
411
|
+
new JavaScript("provide_fallback_enrichment", {
|
|
412
|
+
fn: ({ enrichmentError }) => ({
|
|
413
|
+
success: false,
|
|
414
|
+
data: {
|
|
415
|
+
social_score: 0,
|
|
416
|
+
verified: false,
|
|
417
|
+
risk_level: 'unknown'
|
|
418
|
+
},
|
|
419
|
+
source: 'fallback',
|
|
420
|
+
error: enrichmentError.value?.message || 'External API unavailable'
|
|
421
|
+
})
|
|
422
|
+
})
|
|
423
|
+
]
|
|
424
|
+
}),
|
|
425
|
+
new JavaScript("merge_customer_data", {
|
|
426
|
+
fn: ({ fetch_customer_basic, fetch_external_enrichment }) => {
|
|
427
|
+
const customer = (fetch_customer_basic.output || [])[0] || {};
|
|
428
|
+
const enrichment = fetch_external_enrichment.output || {};
|
|
429
|
+
|
|
430
|
+
return {
|
|
431
|
+
id: customer.id,
|
|
432
|
+
email: customer.email,
|
|
433
|
+
fullName: customer.full_name,
|
|
434
|
+
accountType: customer.account_type,
|
|
435
|
+
enrichmentData: enrichment.data || {},
|
|
436
|
+
enrichmentSource: enrichment.source,
|
|
437
|
+
enrichmentSuccess: enrichment.success || false
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
})
|
|
441
|
+
]);`,
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
id: "getCrossPlatformAnalyticsApi",
|
|
445
|
+
metadata: {
|
|
446
|
+
tags: [
|
|
447
|
+
"snowflake",
|
|
448
|
+
"global-context",
|
|
449
|
+
"data-transformation",
|
|
450
|
+
"multi-integration",
|
|
451
|
+
],
|
|
452
|
+
complexity: "intermediate",
|
|
453
|
+
category: "positive",
|
|
454
|
+
estimatedTokens: 650,
|
|
455
|
+
},
|
|
456
|
+
inputContext: {
|
|
457
|
+
availableIntegrations: [
|
|
458
|
+
{
|
|
459
|
+
name: "PostgresDB",
|
|
460
|
+
id: "<postgres-integration-id>",
|
|
461
|
+
type: "PostgreSQL",
|
|
462
|
+
},
|
|
463
|
+
{
|
|
464
|
+
name: "SnowflakeWarehouse",
|
|
465
|
+
id: "<snowflake-integration-id>",
|
|
466
|
+
type: "Snowflake",
|
|
467
|
+
},
|
|
468
|
+
],
|
|
469
|
+
integrationMetadata: [
|
|
470
|
+
{
|
|
471
|
+
integrationId: "<postgres-integration-id>",
|
|
472
|
+
metadata: {
|
|
473
|
+
databaseSchemaMetadata: {
|
|
474
|
+
tables: [
|
|
475
|
+
{
|
|
476
|
+
type: "TABLE",
|
|
477
|
+
name: "transactions",
|
|
478
|
+
schema: "public",
|
|
479
|
+
columns: [
|
|
480
|
+
{ name: "transaction_id", type: "int4" },
|
|
481
|
+
{ name: "user_id", type: "int4" },
|
|
482
|
+
{ name: "amount", type: "numeric" },
|
|
483
|
+
{ name: "category", type: "varchar" },
|
|
484
|
+
{ name: "created_at", type: "timestamp" },
|
|
485
|
+
],
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
type: "TABLE",
|
|
489
|
+
name: "users",
|
|
490
|
+
schema: "public",
|
|
491
|
+
columns: [
|
|
492
|
+
{ name: "id", type: "int4" },
|
|
493
|
+
{ name: "email", type: "varchar" },
|
|
494
|
+
],
|
|
495
|
+
},
|
|
496
|
+
],
|
|
497
|
+
},
|
|
498
|
+
},
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
integrationId: "<snowflake-integration-id>",
|
|
502
|
+
metadata: {
|
|
503
|
+
databaseSchemaMetadata: {
|
|
504
|
+
tables: [
|
|
505
|
+
{
|
|
506
|
+
type: "TABLE",
|
|
507
|
+
name: "USER_METRICS",
|
|
508
|
+
schema: "PUBLIC",
|
|
509
|
+
columns: [
|
|
510
|
+
{ name: "USER_ID", type: "NUMBER" },
|
|
511
|
+
{ name: "USER_EMAIL", type: "VARCHAR" },
|
|
512
|
+
{ name: "PAGE_VIEWS", type: "NUMBER" },
|
|
513
|
+
{ name: "SESSION_COUNT", type: "NUMBER" },
|
|
514
|
+
{ name: "LAST_ACTIVE_DATE", type: "TIMESTAMP_NTZ" },
|
|
515
|
+
{ name: "ENGAGEMENT_SCORE", type: "FLOAT" },
|
|
516
|
+
],
|
|
517
|
+
},
|
|
518
|
+
],
|
|
519
|
+
},
|
|
520
|
+
},
|
|
521
|
+
},
|
|
522
|
+
],
|
|
523
|
+
},
|
|
524
|
+
userPrompt: "Create an API that generates cross-platform analytics for the current logged-in user. The API should: 1) Fetch the user's transaction history from the PostgreSQL transactions table using Global.user.email to identify the user - include transaction_id, amount, category, and created_at, limited to the most recent transactions sorted by date descending. 2) Fetch the user's engagement metrics from the Snowflake analytics warehouse USER_METRICS table (also using Global.user.email) - get USER_ID, PAGE_VIEWS, SESSION_COUNT, LAST_ACTIVE_DATE, and ENGAGEMENT_SCORE, taking only the most recent record. 3) Calculate spending breakdown by category, showing category name, total amount, and transaction count, sorted by total amount descending. 4) Merge all the data into a comprehensive response showing user info from Global, transaction summary (total transactions, total spent, breakdown by category), and engagement metrics (page views, sessions, last active date, engagement score), along with a generation timestamp. This will power the unified user analytics dashboard.",
|
|
525
|
+
code: `import {
|
|
526
|
+
Api,
|
|
527
|
+
PostgreSQL,
|
|
528
|
+
Snowflake,
|
|
529
|
+
JavaScript,
|
|
530
|
+
Global,
|
|
531
|
+
} from "@superblocksteam/library";
|
|
532
|
+
|
|
533
|
+
export default new Api("getCrossPlatformAnalyticsApi", [
|
|
534
|
+
new PostgreSQL("fetch_user_transactions", "<postgres-integration-id>", {
|
|
535
|
+
statement: () => \`
|
|
536
|
+
SELECT
|
|
537
|
+
transaction_id,
|
|
538
|
+
amount,
|
|
539
|
+
category,
|
|
540
|
+
created_at
|
|
541
|
+
FROM transactions
|
|
542
|
+
WHERE user_id = (
|
|
543
|
+
SELECT id FROM users WHERE email = '\${Global.user.email}' LIMIT 1
|
|
544
|
+
)
|
|
545
|
+
ORDER BY created_at DESC
|
|
546
|
+
LIMIT 500
|
|
547
|
+
\`
|
|
548
|
+
}),
|
|
549
|
+
new Snowflake("fetch_user_analytics", "<snowflake-integration-id>", {
|
|
550
|
+
statement: () => \`
|
|
551
|
+
SELECT
|
|
552
|
+
USER_ID,
|
|
553
|
+
PAGE_VIEWS,
|
|
554
|
+
SESSION_COUNT,
|
|
555
|
+
LAST_ACTIVE_DATE,
|
|
556
|
+
ENGAGEMENT_SCORE
|
|
557
|
+
FROM ANALYTICS.PUBLIC.USER_METRICS
|
|
558
|
+
WHERE USER_EMAIL = '\${Global.user.email}'
|
|
559
|
+
ORDER BY LAST_ACTIVE_DATE DESC
|
|
560
|
+
LIMIT 1
|
|
561
|
+
\`
|
|
562
|
+
}),
|
|
563
|
+
new JavaScript("calculate_spending_by_category", {
|
|
564
|
+
fn: ({ fetch_user_transactions }) => {
|
|
565
|
+
const transactions = fetch_user_transactions.output || [];
|
|
566
|
+
const categoryTotals: Record<string, number> = {};
|
|
567
|
+
|
|
568
|
+
transactions.forEach(txn => {
|
|
569
|
+
const category = txn.category || 'uncategorized';
|
|
570
|
+
categoryTotals[category] = (categoryTotals[category] || 0) + (txn.amount || 0);
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
return Object.entries(categoryTotals).map(([category, total]) => ({
|
|
574
|
+
category,
|
|
575
|
+
total,
|
|
576
|
+
transactionCount: transactions.filter(t => t.category === category).length
|
|
577
|
+
})).sort((a, b) => b.total - a.total);
|
|
578
|
+
}
|
|
579
|
+
}),
|
|
580
|
+
new JavaScript("merge_all_data", {
|
|
581
|
+
fn: ({ fetch_user_transactions, fetch_user_analytics, calculate_spending_by_category }) => {
|
|
582
|
+
const analytics = (fetch_user_analytics.output || [])[0] || {};
|
|
583
|
+
const transactions = fetch_user_transactions.output || [];
|
|
584
|
+
|
|
585
|
+
return {
|
|
586
|
+
user: {
|
|
587
|
+
email: Global.user.email,
|
|
588
|
+
name: Global.user.name
|
|
589
|
+
},
|
|
590
|
+
transactionSummary: {
|
|
591
|
+
totalTransactions: transactions.length,
|
|
592
|
+
totalSpent: transactions.reduce((sum, t) => sum + (t.amount || 0), 0),
|
|
593
|
+
byCategory: calculate_spending_by_category.output
|
|
594
|
+
},
|
|
595
|
+
engagementMetrics: {
|
|
596
|
+
pageViews: analytics.PAGE_VIEWS || 0,
|
|
597
|
+
sessions: analytics.SESSION_COUNT || 0,
|
|
598
|
+
lastActive: analytics.LAST_ACTIVE_DATE || null,
|
|
599
|
+
engagementScore: analytics.ENGAGEMENT_SCORE || 0
|
|
600
|
+
},
|
|
601
|
+
generatedAt: new Date().toISOString()
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
})
|
|
605
|
+
]);`,
|
|
606
|
+
},
|
|
607
|
+
{
|
|
608
|
+
id: "analyzeCustomerSegmentsApi",
|
|
609
|
+
metadata: {
|
|
610
|
+
tags: ["data-transformation", "data-science"],
|
|
611
|
+
complexity: "intermediate",
|
|
612
|
+
category: "positive",
|
|
613
|
+
estimatedTokens: 600,
|
|
614
|
+
},
|
|
615
|
+
userPrompt: "Create an API that performs RFM (Recency, Frequency, Monetary) customer segmentation analysis. The API should: 1) Fetch customer metrics from the customer_metrics table including customer_id, total_purchases, average_order_value, days_since_last_purchase, and total_spent, limited to the top customers by total spending. 2) Use Python with pandas and numpy to perform RFM analysis - calculate recency, frequency, and monetary scores using quartile-based scoring (1-4), combine the scores, and assign customers to segments: 'Champions' (score >= 10), 'Loyal Customers' (score >= 8), 'Potential Loyalists' (score >= 6), 'At Risk' (score >= 4), or 'Lost' (score < 4). 3) Summarize the results by segment showing count of customers, total revenue, and average order value for each segment. Return the segment summary, total customers analyzed, and analysis timestamp. This will be used by the marketing team to target customer segments with appropriate campaigns.",
|
|
616
|
+
code: `import {
|
|
617
|
+
Api,
|
|
618
|
+
PostgreSQL,
|
|
619
|
+
Python,
|
|
620
|
+
JavaScript,
|
|
621
|
+
} from "@superblocksteam/library";
|
|
622
|
+
|
|
623
|
+
export default new Api("analyzeCustomerSegmentsApi", [
|
|
624
|
+
new PostgreSQL("fetch_customer_metrics", "<postgres-integration-id>", {
|
|
625
|
+
statement: () => \`
|
|
626
|
+
SELECT
|
|
627
|
+
customer_id,
|
|
628
|
+
total_purchases,
|
|
629
|
+
average_order_value,
|
|
630
|
+
days_since_last_purchase,
|
|
631
|
+
total_spent
|
|
632
|
+
FROM customer_metrics
|
|
633
|
+
ORDER BY total_spent DESC
|
|
634
|
+
LIMIT 500
|
|
635
|
+
\`
|
|
636
|
+
}),
|
|
637
|
+
new Python("calculate_segments", {
|
|
638
|
+
fn: \`
|
|
639
|
+
import pandas as pd
|
|
640
|
+
import numpy as np
|
|
641
|
+
|
|
642
|
+
# Access block output via Global
|
|
643
|
+
customers = Global['fetch_customer_metrics']['output']
|
|
644
|
+
|
|
645
|
+
# Convert to DataFrame
|
|
646
|
+
df = pd.DataFrame(customers)
|
|
647
|
+
|
|
648
|
+
# Calculate customer segments using RFM analysis
|
|
649
|
+
df['recency_score'] = pd.qcut(df['days_since_last_purchase'], q=4, labels=[4,3,2,1], duplicates='drop')
|
|
650
|
+
df['frequency_score'] = pd.qcut(df['total_purchases'], q=4, labels=[1,2,3,4], duplicates='drop')
|
|
651
|
+
df['monetary_score'] = pd.qcut(df['total_spent'], q=4, labels=[1,2,3,4], duplicates='drop')
|
|
652
|
+
|
|
653
|
+
# Combine scores
|
|
654
|
+
df['rfm_score'] = (df['recency_score'].astype(int) +
|
|
655
|
+
df['frequency_score'].astype(int) +
|
|
656
|
+
df['monetary_score'].astype(int))
|
|
657
|
+
|
|
658
|
+
# Assign segments
|
|
659
|
+
def assign_segment(score):
|
|
660
|
+
if score >= 10:
|
|
661
|
+
return 'Champions'
|
|
662
|
+
elif score >= 8:
|
|
663
|
+
return 'Loyal Customers'
|
|
664
|
+
elif score >= 6:
|
|
665
|
+
return 'Potential Loyalists'
|
|
666
|
+
elif score >= 4:
|
|
667
|
+
return 'At Risk'
|
|
668
|
+
else:
|
|
669
|
+
return 'Lost'
|
|
670
|
+
|
|
671
|
+
df['segment'] = df['rfm_score'].apply(assign_segment)
|
|
672
|
+
|
|
673
|
+
# Return as list of dicts
|
|
674
|
+
df.to_dict('records')
|
|
675
|
+
\`
|
|
676
|
+
}),
|
|
677
|
+
new JavaScript("summarize_segments", {
|
|
678
|
+
fn: ({ calculate_segments }) => {
|
|
679
|
+
const segmented = calculate_segments.output || [];
|
|
680
|
+
const summary = {};
|
|
681
|
+
|
|
682
|
+
segmented.forEach(customer => {
|
|
683
|
+
const segment = customer.segment || 'Unknown';
|
|
684
|
+
if (!summary[segment]) {
|
|
685
|
+
summary[segment] = {
|
|
686
|
+
count: 0,
|
|
687
|
+
totalRevenue: 0,
|
|
688
|
+
avgOrderValue: 0
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
summary[segment].count += 1;
|
|
692
|
+
summary[segment].totalRevenue += customer.total_spent || 0;
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
// Calculate averages
|
|
696
|
+
Object.keys(summary).forEach(segment => {
|
|
697
|
+
if (summary[segment].count > 0) {
|
|
698
|
+
summary[segment].avgOrderValue = summary[segment].totalRevenue / summary[segment].count;
|
|
699
|
+
}
|
|
700
|
+
});
|
|
701
|
+
|
|
702
|
+
return {
|
|
703
|
+
segmentSummary: summary,
|
|
704
|
+
totalCustomers: segmented.length,
|
|
705
|
+
analyzedAt: new Date().toISOString()
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
})
|
|
709
|
+
]);`,
|
|
710
|
+
},
|
|
711
|
+
{
|
|
712
|
+
id: "processInventoryUpdatesApi",
|
|
713
|
+
metadata: {
|
|
714
|
+
tags: [
|
|
715
|
+
"loop",
|
|
716
|
+
"conditional",
|
|
717
|
+
"nested-control-flow",
|
|
718
|
+
"scope-access",
|
|
719
|
+
"batch-processing",
|
|
720
|
+
],
|
|
721
|
+
complexity: "complex",
|
|
722
|
+
category: "positive",
|
|
723
|
+
estimatedTokens: 850,
|
|
724
|
+
},
|
|
725
|
+
userPrompt: "Create an API that processes inventory updates with complex validation and batch operations. The API should: 1) Fetch pending inventory updates from the inventory_queue table. 2) Loop through each inventory update, and within each iteration: validate if the product exists by checking a product_status flag, and if valid: (a) check if it's a bulk operation (quantity > 100), if so calculate a bulk discount of 5%, otherwise use standard pricing, (b) update the inventory table with the new quantity and price. 3) After all updates, summarize the results by operation type (bulk vs standard), showing count, total quantity, and average price for each type. This demonstrates proper scope access across double-nested control flow (Loop > Conditional > Conditional).",
|
|
726
|
+
code: `import {
|
|
727
|
+
Api,
|
|
728
|
+
PostgreSQL,
|
|
729
|
+
Loop,
|
|
730
|
+
Conditional,
|
|
731
|
+
JavaScript,
|
|
732
|
+
} from "@superblocksteam/library";
|
|
733
|
+
|
|
734
|
+
export default new Api("processInventoryUpdatesApi", [
|
|
735
|
+
new PostgreSQL("fetch_pending_updates", "<postgres-integration-id>", {
|
|
736
|
+
statement: () => \`
|
|
737
|
+
SELECT
|
|
738
|
+
id,
|
|
739
|
+
product_id,
|
|
740
|
+
quantity_change,
|
|
741
|
+
unit_price,
|
|
742
|
+
product_status,
|
|
743
|
+
operation_type
|
|
744
|
+
FROM inventory_queue
|
|
745
|
+
WHERE status = 'pending'
|
|
746
|
+
ORDER BY created_at ASC
|
|
747
|
+
LIMIT 100
|
|
748
|
+
\`
|
|
749
|
+
}),
|
|
750
|
+
new Loop("process_each_update", {
|
|
751
|
+
over: ({ fetch_pending_updates }) => fetch_pending_updates.output,
|
|
752
|
+
variables: { item: "update", index: "updateIdx" },
|
|
753
|
+
blocks: [
|
|
754
|
+
// First level: Validate product status
|
|
755
|
+
new Conditional("validate_product", {
|
|
756
|
+
if: {
|
|
757
|
+
when: ({ update }) => update.value.product_status === 'active',
|
|
758
|
+
then: [
|
|
759
|
+
// Second level (nested inside first Conditional): Check for bulk operation
|
|
760
|
+
new Conditional("determine_pricing", {
|
|
761
|
+
if: {
|
|
762
|
+
when: ({ update }) => update.value.quantity_change > 100,
|
|
763
|
+
then: [
|
|
764
|
+
new JavaScript("calculate_bulk_pricing", {
|
|
765
|
+
fn: ({ update, updateIdx }) => ({
|
|
766
|
+
operation_type: 'bulk',
|
|
767
|
+
quantity: update.value.quantity_change,
|
|
768
|
+
unit_price: update.value.unit_price,
|
|
769
|
+
final_price: update.value.unit_price * 0.95, // 5% bulk discount
|
|
770
|
+
index: updateIdx.value
|
|
771
|
+
})
|
|
772
|
+
})
|
|
773
|
+
]
|
|
774
|
+
},
|
|
775
|
+
else: [
|
|
776
|
+
new JavaScript("calculate_standard_pricing", {
|
|
777
|
+
fn: ({ update, updateIdx }) => ({
|
|
778
|
+
operation_type: 'standard',
|
|
779
|
+
quantity: update.value.quantity_change,
|
|
780
|
+
unit_price: update.value.unit_price,
|
|
781
|
+
final_price: update.value.unit_price,
|
|
782
|
+
index: updateIdx.value
|
|
783
|
+
})
|
|
784
|
+
})
|
|
785
|
+
]
|
|
786
|
+
}),
|
|
787
|
+
// This block can access:
|
|
788
|
+
// ✅ determine_pricing.output (parent Conditional output)
|
|
789
|
+
// ✅ update, updateIdx (Loop variables from ancestor)
|
|
790
|
+
// ✅ fetch_pending_updates (top-level sibling)
|
|
791
|
+
// ❌ CANNOT access calculate_bulk_pricing or calculate_standard_pricing directly
|
|
792
|
+
new PostgreSQL("update_inventory", "<postgres-integration-id>", {
|
|
793
|
+
statement: ({ update, determine_pricing }) => \`
|
|
794
|
+
UPDATE inventory
|
|
795
|
+
SET
|
|
796
|
+
quantity = quantity + \${update.value.quantity_change},
|
|
797
|
+
unit_price = \${determine_pricing.output.final_price},
|
|
798
|
+
last_updated = NOW()
|
|
799
|
+
WHERE product_id = \${update.value.product_id}
|
|
800
|
+
\`
|
|
801
|
+
})
|
|
802
|
+
]
|
|
803
|
+
}
|
|
804
|
+
})
|
|
805
|
+
]
|
|
806
|
+
}),
|
|
807
|
+
// This block can access:
|
|
808
|
+
// ✅ process_each_update.output (previous sibling)
|
|
809
|
+
// ✅ fetch_pending_updates (previous sibling)
|
|
810
|
+
// ❌ CANNOT access validate_product, determine_pricing, calculate_bulk_pricing, etc. (inside Loop scope)
|
|
811
|
+
new JavaScript("summarize_by_operation_type", {
|
|
812
|
+
fn: ({ process_each_update, fetch_pending_updates }) => {
|
|
813
|
+
const updates = fetch_pending_updates.output || [];
|
|
814
|
+
const results = process_each_update.output || [];
|
|
815
|
+
|
|
816
|
+
const summary = {
|
|
817
|
+
bulk: { count: 0, totalQuantity: 0, avgPrice: 0, prices: [] },
|
|
818
|
+
standard: { count: 0, totalQuantity: 0, avgPrice: 0, prices: [] }
|
|
819
|
+
};
|
|
820
|
+
|
|
821
|
+
// Note: In a real scenario, you'd need to reconstruct operation type from results
|
|
822
|
+
// This is simplified for demonstration
|
|
823
|
+
updates.forEach(update => {
|
|
824
|
+
const isBulk = update.quantity_change > 100;
|
|
825
|
+
const type = isBulk ? 'bulk' : 'standard';
|
|
826
|
+
const finalPrice = isBulk ? update.unit_price * 0.95 : update.unit_price;
|
|
827
|
+
|
|
828
|
+
summary[type].count += 1;
|
|
829
|
+
summary[type].totalQuantity += update.quantity_change;
|
|
830
|
+
summary[type].prices.push(finalPrice);
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
// Calculate averages
|
|
834
|
+
['bulk', 'standard'].forEach(type => {
|
|
835
|
+
if (summary[type].prices.length > 0) {
|
|
836
|
+
summary[type].avgPrice = summary[type].prices.reduce((a, b) => a + b, 0) / summary[type].prices.length;
|
|
837
|
+
}
|
|
838
|
+
delete summary[type].prices; // Remove helper array
|
|
839
|
+
});
|
|
840
|
+
|
|
841
|
+
return {
|
|
842
|
+
summary,
|
|
843
|
+
totalProcessed: updates.length,
|
|
844
|
+
processedAt: new Date().toISOString()
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
})
|
|
848
|
+
]);`,
|
|
849
|
+
},
|
|
850
|
+
];
|
|
851
|
+
export const NEGATIVE_EXAMPLES = [
|
|
852
|
+
{
|
|
853
|
+
id: "negative-scope-violation-sibling",
|
|
854
|
+
metadata: {
|
|
855
|
+
tags: ["error-scope-violation", "loop"],
|
|
856
|
+
complexity: "simple",
|
|
857
|
+
category: "negative",
|
|
858
|
+
estimatedTokens: 300,
|
|
859
|
+
},
|
|
860
|
+
scenario: "Attempting to access blocks inside control flow from outside (sibling scope violation)",
|
|
861
|
+
incorrectCode: `import { Api, Loop, JavaScript } from "@superblocksteam/library";
|
|
862
|
+
|
|
863
|
+
export default new Api("badScopeApi", [
|
|
864
|
+
new JavaScript("fetch_data", {
|
|
865
|
+
fn: () => [{ id: 1, value: 100 }, { id: 2, value: 200 }]
|
|
866
|
+
}),
|
|
867
|
+
new Loop("process_items", {
|
|
868
|
+
over: ({ fetch_data }) => fetch_data.output,
|
|
869
|
+
variables: { item: "current", index: "i" },
|
|
870
|
+
blocks: [
|
|
871
|
+
new JavaScript("transform_item", {
|
|
872
|
+
fn: ({ current }) => ({ transformed: current.value.value * 2 })
|
|
873
|
+
}),
|
|
874
|
+
new JavaScript("validate_item", {
|
|
875
|
+
fn: ({ transform_item }) => ({ valid: transform_item.output.transformed > 0 })
|
|
876
|
+
})
|
|
877
|
+
]
|
|
878
|
+
}),
|
|
879
|
+
// ❌ ERROR: Cannot access blocks inside Loop from outside
|
|
880
|
+
new JavaScript("bad_summary", {
|
|
881
|
+
fn: ({ transform_item, validate_item }) => {
|
|
882
|
+
// ❌ transform_item and validate_item are NOT in scope here!
|
|
883
|
+
// They are nested inside process_items Loop
|
|
884
|
+
return {
|
|
885
|
+
transformed: transform_item.output, // ❌ WILL FAIL
|
|
886
|
+
valid: validate_item.output // ❌ WILL FAIL
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
})
|
|
890
|
+
]);`,
|
|
891
|
+
correctAlternative: `// ✅ CORRECT: Access the Loop's output, not its internal blocks
|
|
892
|
+
new JavaScript("correct_summary", {
|
|
893
|
+
fn: ({ process_items, fetch_data }) => {
|
|
894
|
+
// ✅ Can access process_items.output (equals last block's output in Loop)
|
|
895
|
+
// ✅ Can access fetch_data (previous sibling)
|
|
896
|
+
return {
|
|
897
|
+
loopResults: process_items.output,
|
|
898
|
+
itemCount: fetch_data.output.length
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
})`,
|
|
902
|
+
},
|
|
903
|
+
{
|
|
904
|
+
id: "negative-error-scope-violation-branches",
|
|
905
|
+
metadata: {
|
|
906
|
+
tags: ["error-scope-violation", "conditional"],
|
|
907
|
+
complexity: "simple",
|
|
908
|
+
category: "negative",
|
|
909
|
+
estimatedTokens: 280,
|
|
910
|
+
},
|
|
911
|
+
scenario: "Attempting to access blocks from different Conditional branches",
|
|
912
|
+
incorrectCode: `import { Api, Conditional, JavaScript } from "@superblocksteam/library";
|
|
913
|
+
|
|
914
|
+
export default new Api("badConditionalScopeApi", [
|
|
915
|
+
new JavaScript("get_user_role", {
|
|
916
|
+
fn: ({ userRoleVar }) => userRoleVar.value
|
|
917
|
+
}),
|
|
918
|
+
new Conditional("process_by_role", {
|
|
919
|
+
if: {
|
|
920
|
+
when: ({ get_user_role }) => get_user_role.output === "admin",
|
|
921
|
+
then: [
|
|
922
|
+
new JavaScript("admin_processing", {
|
|
923
|
+
fn: () => ({ type: "admin", permissions: ["read", "write", "delete"] })
|
|
924
|
+
})
|
|
925
|
+
]
|
|
926
|
+
},
|
|
927
|
+
elif: [{
|
|
928
|
+
when: ({ get_user_role }) => get_user_role.output === "user",
|
|
929
|
+
then: [
|
|
930
|
+
new JavaScript("user_processing", {
|
|
931
|
+
fn: () => ({ type: "user", permissions: ["read"] })
|
|
932
|
+
})
|
|
933
|
+
]
|
|
934
|
+
}],
|
|
935
|
+
else: [
|
|
936
|
+
new JavaScript("guest_processing", {
|
|
937
|
+
fn: () => ({ type: "guest", permissions: [] })
|
|
938
|
+
})
|
|
939
|
+
]
|
|
940
|
+
}),
|
|
941
|
+
// ❌ ERROR: Cannot access blocks from specific branches
|
|
942
|
+
new JavaScript("bad_merge", {
|
|
943
|
+
fn: ({ admin_processing, user_processing, guest_processing }) => {
|
|
944
|
+
// ❌ Only ONE of these branches executed, so 2 of these 3 will be undefined/not in scope
|
|
945
|
+
// You cannot access blocks from branches that didn't execute
|
|
946
|
+
return {
|
|
947
|
+
adminData: admin_processing.output, // ❌ Only exists if admin branch ran
|
|
948
|
+
userData: user_processing.output, // ❌ Only exists if user branch ran
|
|
949
|
+
guestData: guest_processing.output // ❌ Only exists if else branch ran
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
})
|
|
953
|
+
]);`,
|
|
954
|
+
correctAlternative: `// ✅ CORRECT: Access the Conditional's output (from whichever branch executed)
|
|
955
|
+
new JavaScript("correct_merge", {
|
|
956
|
+
fn: ({ process_by_role, get_user_role }) => {
|
|
957
|
+
// ✅ Can access process_by_role.output (output from the executed branch)
|
|
958
|
+
// ✅ Can access get_user_role (previous sibling)
|
|
959
|
+
return {
|
|
960
|
+
role: get_user_role.output,
|
|
961
|
+
processedData: process_by_role.output
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
})`,
|
|
965
|
+
},
|
|
966
|
+
{
|
|
967
|
+
id: "negative-variable-access",
|
|
968
|
+
metadata: {
|
|
969
|
+
tags: ["error-scope-violation", "variable-access", "loop"],
|
|
970
|
+
complexity: "simple",
|
|
971
|
+
category: "negative",
|
|
972
|
+
estimatedTokens: 320,
|
|
973
|
+
},
|
|
974
|
+
scenario: "Incorrect variable access patterns (missing .value or .output)",
|
|
975
|
+
incorrectCode: `import { Api, Loop, JavaScript, PostgreSQL } from "@superblocksteam/library";
|
|
976
|
+
|
|
977
|
+
export default new Api("badVariableAccessApi", [
|
|
978
|
+
new JavaScript("get_orders", {
|
|
979
|
+
fn: () => [{ id: 1, total: 100 }, { id: 2, total: 200 }]
|
|
980
|
+
}),
|
|
981
|
+
new Loop("process_orders", {
|
|
982
|
+
over: ({ get_orders }) => get_orders.output,
|
|
983
|
+
variables: { item: "order", index: "idx" },
|
|
984
|
+
blocks: [
|
|
985
|
+
new JavaScript("bad_access", {
|
|
986
|
+
fn: ({ order, idx, get_orders }) => ({
|
|
987
|
+
// ❌ Loop variables need .value
|
|
988
|
+
orderId: order.id, // ❌ Should be order.value.id
|
|
989
|
+
index: idx, // ❌ Should be idx.value
|
|
990
|
+
|
|
991
|
+
// ❌ Block outputs need .output
|
|
992
|
+
totalOrders: get_orders.length // ❌ Should be get_orders.output.length
|
|
993
|
+
})
|
|
994
|
+
}),
|
|
995
|
+
new PostgreSQL("bad_query", "<postgres-integration-id>", {
|
|
996
|
+
statement: ({ order }) => \`
|
|
997
|
+
-- ❌ Missing .value for Loop variable
|
|
998
|
+
SELECT * FROM order_items WHERE order_id = \${order.id}
|
|
999
|
+
-- ✅ Should be: WHERE order_id = \${order.value.id}
|
|
1000
|
+
\`
|
|
1001
|
+
})
|
|
1002
|
+
]
|
|
1003
|
+
}),
|
|
1004
|
+
new JavaScript("another_bad_access", {
|
|
1005
|
+
fn: ({ get_orders, process_orders }) => ({
|
|
1006
|
+
// ❌ Missing .output for block outputs
|
|
1007
|
+
orders: get_orders, // ❌ Should be get_orders.output
|
|
1008
|
+
results: process_orders // ❌ Should be process_orders.output
|
|
1009
|
+
})
|
|
1010
|
+
})
|
|
1011
|
+
]);`,
|
|
1012
|
+
correctAlternative: `// ✅ CORRECT: Proper use of .value and .output
|
|
1013
|
+
new Loop("process_orders", {
|
|
1014
|
+
over: ({ get_orders }) => get_orders.output,
|
|
1015
|
+
variables: { item: "order", index: "idx" },
|
|
1016
|
+
blocks: [
|
|
1017
|
+
new JavaScript("correct_access", {
|
|
1018
|
+
fn: ({ order, idx, get_orders }) => ({
|
|
1019
|
+
// ✅ Loop variables use .value
|
|
1020
|
+
orderId: order.value.id,
|
|
1021
|
+
index: idx.value,
|
|
1022
|
+
|
|
1023
|
+
// ✅ Block outputs use .output
|
|
1024
|
+
totalOrders: get_orders.output.length
|
|
1025
|
+
})
|
|
1026
|
+
})
|
|
1027
|
+
]
|
|
1028
|
+
}),
|
|
1029
|
+
new JavaScript("correct_summary", {
|
|
1030
|
+
fn: ({ get_orders, process_orders }) => ({
|
|
1031
|
+
// ✅ Block outputs use .output
|
|
1032
|
+
orders: get_orders.output,
|
|
1033
|
+
results: process_orders.output
|
|
1034
|
+
})
|
|
1035
|
+
})`,
|
|
1036
|
+
},
|
|
1037
|
+
{
|
|
1038
|
+
id: "negative-forward-reference",
|
|
1039
|
+
metadata: {
|
|
1040
|
+
tags: ["error-scope-violation", "error-execution-order"],
|
|
1041
|
+
complexity: "simple",
|
|
1042
|
+
category: "negative",
|
|
1043
|
+
estimatedTokens: 250,
|
|
1044
|
+
},
|
|
1045
|
+
scenario: "Attempting to access blocks that execute later (forward reference)",
|
|
1046
|
+
incorrectCode: `import { Api, JavaScript, PostgreSQL } from "@superblocksteam/library";
|
|
1047
|
+
|
|
1048
|
+
export default new Api("badOrderingApi", [
|
|
1049
|
+
new JavaScript("bad_early_access", {
|
|
1050
|
+
fn: ({ fetch_users }) => {
|
|
1051
|
+
// ❌ fetch_users hasn't executed yet - it comes AFTER this block
|
|
1052
|
+
return fetch_users.output.map(u => u.id); // ❌ WILL FAIL
|
|
1053
|
+
}
|
|
1054
|
+
}),
|
|
1055
|
+
new PostgreSQL("fetch_users", "<postgres-integration-id>", {
|
|
1056
|
+
statement: () => \`SELECT id, name FROM users LIMIT 100\`
|
|
1057
|
+
}),
|
|
1058
|
+
new JavaScript("correct_late_access", {
|
|
1059
|
+
fn: ({ fetch_users }) => {
|
|
1060
|
+
// ✅ This works - fetch_users executed before this block
|
|
1061
|
+
return fetch_users.output.map(u => u.id);
|
|
1062
|
+
}
|
|
1063
|
+
})
|
|
1064
|
+
]);`,
|
|
1065
|
+
explanation: "Blocks can ONLY access outputs from blocks that have already executed (previous siblings, ancestors). They cannot access blocks that come after them in the execution order.",
|
|
1066
|
+
},
|
|
1067
|
+
{
|
|
1068
|
+
id: "negative-deep-nesting",
|
|
1069
|
+
metadata: {
|
|
1070
|
+
tags: [
|
|
1071
|
+
"error-scope-violation",
|
|
1072
|
+
"nested-control-flow",
|
|
1073
|
+
"loop",
|
|
1074
|
+
"conditional",
|
|
1075
|
+
],
|
|
1076
|
+
complexity: "simple",
|
|
1077
|
+
category: "negative",
|
|
1078
|
+
estimatedTokens: 280,
|
|
1079
|
+
},
|
|
1080
|
+
scenario: "Deeply nested scope violation (trying to access grandchild blocks)",
|
|
1081
|
+
incorrectCode: `import { Api, Loop, Conditional, JavaScript } from "@superblocksteam/library";
|
|
1082
|
+
|
|
1083
|
+
export default new Api("badDeepNestingApi", [
|
|
1084
|
+
new JavaScript("fetch_data", {
|
|
1085
|
+
fn: () => [{ id: 1, status: 'active' }, { id: 2, status: 'inactive' }]
|
|
1086
|
+
}),
|
|
1087
|
+
new Loop("process_items", {
|
|
1088
|
+
over: ({ fetch_data }) => fetch_data.output,
|
|
1089
|
+
variables: { item: "item", index: "i" },
|
|
1090
|
+
blocks: [
|
|
1091
|
+
new Conditional("check_status", {
|
|
1092
|
+
if: {
|
|
1093
|
+
when: ({ item }) => item.value.status === 'active',
|
|
1094
|
+
then: [
|
|
1095
|
+
new JavaScript("process_active", {
|
|
1096
|
+
fn: ({ item }) => ({ processed: true, id: item.value.id })
|
|
1097
|
+
})
|
|
1098
|
+
]
|
|
1099
|
+
}
|
|
1100
|
+
})
|
|
1101
|
+
]
|
|
1102
|
+
}),
|
|
1103
|
+
// ❌ ERROR: Cannot access blocks nested inside Loop > Conditional
|
|
1104
|
+
new JavaScript("bad_access_grandchild", {
|
|
1105
|
+
fn: ({ process_active }) => {
|
|
1106
|
+
// ❌ process_active is nested TWO levels deep (inside Loop, then inside Conditional)
|
|
1107
|
+
// It is NOT accessible from here
|
|
1108
|
+
return process_active.output; // ❌ WILL FAIL
|
|
1109
|
+
}
|
|
1110
|
+
})
|
|
1111
|
+
]);`,
|
|
1112
|
+
correctAlternative: `// ✅ CORRECT: Access only the Loop's output
|
|
1113
|
+
new JavaScript("correct_access", {
|
|
1114
|
+
fn: ({ process_items }) => {
|
|
1115
|
+
// ✅ process_items.output contains results from the last block of each iteration
|
|
1116
|
+
return {
|
|
1117
|
+
results: process_items.output,
|
|
1118
|
+
count: (process_items.output || []).length
|
|
1119
|
+
};
|
|
1120
|
+
}
|
|
1121
|
+
})`,
|
|
1122
|
+
},
|
|
1123
|
+
];
|
|
1124
|
+
/**
|
|
1125
|
+
* Format a positive example as XML for LLM consumption
|
|
1126
|
+
*/
|
|
1127
|
+
export function formatPositiveExample(example) {
|
|
1128
|
+
// Build the input using the same helper that builds runtime prompts
|
|
1129
|
+
const input = buildApiPrompt({
|
|
1130
|
+
apiName: example.id,
|
|
1131
|
+
userPrompt: example.userPrompt,
|
|
1132
|
+
pageEntities: example.inputContext?.pageEntities,
|
|
1133
|
+
availableIntegrations: example.inputContext?.availableIntegrations,
|
|
1134
|
+
integrationMetadata: example.inputContext?.integrationMetadata,
|
|
1135
|
+
isEdit: false,
|
|
1136
|
+
});
|
|
1137
|
+
return `<example>
|
|
1138
|
+
<input>
|
|
1139
|
+
${input}
|
|
1140
|
+
</input>
|
|
1141
|
+
<output>
|
|
1142
|
+
${example.code}
|
|
1143
|
+
</output>
|
|
1144
|
+
</example>`;
|
|
1145
|
+
}
|
|
1146
|
+
/**
|
|
1147
|
+
* Format a negative example as XML for LLM consumption
|
|
1148
|
+
*/
|
|
1149
|
+
export function formatNegativeExample(example) {
|
|
1150
|
+
let formatted = `<negative_example>
|
|
1151
|
+
<scenario>${example.scenario}</scenario>
|
|
1152
|
+
<incorrect_code>
|
|
1153
|
+
${example.incorrectCode}
|
|
1154
|
+
</incorrect_code>`;
|
|
1155
|
+
if (example.correctAlternative) {
|
|
1156
|
+
formatted += `
|
|
1157
|
+
<correct_alternative>
|
|
1158
|
+
${example.correctAlternative}
|
|
1159
|
+
</correct_alternative>`;
|
|
1160
|
+
}
|
|
1161
|
+
if (example.explanation) {
|
|
1162
|
+
formatted += `
|
|
1163
|
+
<explanation>
|
|
1164
|
+
${example.explanation}
|
|
1165
|
+
</explanation>`;
|
|
1166
|
+
}
|
|
1167
|
+
formatted += `
|
|
1168
|
+
</negative_example>`;
|
|
1169
|
+
return formatted;
|
|
1170
|
+
}
|
|
1171
|
+
/**
|
|
1172
|
+
* Get all example metadata for selection purposes
|
|
1173
|
+
*/
|
|
1174
|
+
export function getAllExampleMetadata() {
|
|
1175
|
+
const positive = POSITIVE_EXAMPLES.map((ex) => ({
|
|
1176
|
+
id: ex.id,
|
|
1177
|
+
...ex.metadata,
|
|
1178
|
+
}));
|
|
1179
|
+
const negative = NEGATIVE_EXAMPLES.map((ex) => ({
|
|
1180
|
+
id: ex.id,
|
|
1181
|
+
...ex.metadata,
|
|
1182
|
+
}));
|
|
1183
|
+
return [...positive, ...negative];
|
|
1184
|
+
}
|
|
1185
|
+
/**
|
|
1186
|
+
* Get examples by IDs and format as XML
|
|
1187
|
+
*/
|
|
1188
|
+
export function formatExamplesByIds(ids) {
|
|
1189
|
+
if (ids.length === 0) {
|
|
1190
|
+
return "";
|
|
1191
|
+
}
|
|
1192
|
+
const idSet = new Set(ids);
|
|
1193
|
+
const examples = [];
|
|
1194
|
+
// Add positive examples
|
|
1195
|
+
for (const example of POSITIVE_EXAMPLES) {
|
|
1196
|
+
if (idSet.has(example.id)) {
|
|
1197
|
+
examples.push(formatPositiveExample(example));
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
// Add negative examples
|
|
1201
|
+
for (const example of NEGATIVE_EXAMPLES) {
|
|
1202
|
+
if (idSet.has(example.id)) {
|
|
1203
|
+
examples.push(formatNegativeExample(example));
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
if (examples.length === 0) {
|
|
1207
|
+
return "";
|
|
1208
|
+
}
|
|
1209
|
+
// Separate positive and negative
|
|
1210
|
+
const hasPositive = POSITIVE_EXAMPLES.some((ex) => idSet.has(ex.id));
|
|
1211
|
+
const hasNegative = NEGATIVE_EXAMPLES.some((ex) => idSet.has(ex.id));
|
|
1212
|
+
if (hasPositive && !hasNegative) {
|
|
1213
|
+
return `<examples>\n${examples.join("\n\n")}\n</examples>`;
|
|
1214
|
+
}
|
|
1215
|
+
else if (hasNegative && !hasPositive) {
|
|
1216
|
+
return `<negative_examples>\nThese examples demonstrate INCORRECT scope access patterns that will cause API failures. Do NOT follow these patterns.\n\n${examples.join("\n\n")}\n</negative_examples>`;
|
|
1217
|
+
}
|
|
1218
|
+
else {
|
|
1219
|
+
// Both positive and negative
|
|
1220
|
+
const positiveFormatted = POSITIVE_EXAMPLES.filter((ex) => idSet.has(ex.id))
|
|
1221
|
+
.map(formatPositiveExample)
|
|
1222
|
+
.join("\n\n");
|
|
1223
|
+
const negativeFormatted = NEGATIVE_EXAMPLES.filter((ex) => idSet.has(ex.id))
|
|
1224
|
+
.map(formatNegativeExample)
|
|
1225
|
+
.join("\n\n");
|
|
1226
|
+
return `<examples>\n${positiveFormatted}\n</examples>\n\n<negative_examples>\nThese examples demonstrate INCORRECT scope access patterns that will cause API failures. Do NOT follow these patterns.\n\n${negativeFormatted}\n</negative_examples>`;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
//# sourceMappingURL=examples.js.map
|