vidspotai-shared 1.0.82 → 1.0.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/globals/aiModels/enums.d.ts +11 -1
- package/lib/globals/aiModels/enums.d.ts.map +1 -1
- package/lib/globals/aiModels/enums.js +24 -1
- package/lib/globals/aiModels/index.d.ts.map +1 -1
- package/lib/globals/aiModels/index.js +2 -0
- package/lib/globals/aiModels/providers/anthropic.d.ts +12 -0
- package/lib/globals/aiModels/providers/anthropic.d.ts.map +1 -0
- package/lib/globals/aiModels/providers/anthropic.js +88 -0
- package/lib/globals/aiModels/providers/google.d.ts.map +1 -1
- package/lib/globals/aiModels/providers/google.js +82 -0
- package/lib/globals/aiModels/providers/openai.d.ts.map +1 -1
- package/lib/globals/aiModels/providers/openai.js +63 -4
- package/lib/globals/aiModels/tierHelpers.d.ts +12 -0
- package/lib/globals/aiModels/tierHelpers.d.ts.map +1 -1
- package/lib/globals/aiModels/tierHelpers.js +83 -0
- package/lib/globals/aiModels/types.d.ts +19 -0
- package/lib/globals/aiModels/types.d.ts.map +1 -1
- package/lib/globals/types.d.ts +120 -1
- package/lib/globals/types.d.ts.map +1 -1
- package/lib/globals/types.js +135 -1
- package/lib/models/agent.model.d.ts +41 -1
- package/lib/models/agent.model.d.ts.map +1 -1
- package/lib/models/index.d.ts +1 -0
- package/lib/models/index.d.ts.map +1 -1
- package/lib/models/index.js +1 -0
- package/lib/models/social.model.d.ts +180 -0
- package/lib/models/social.model.d.ts.map +1 -0
- package/lib/models/social.model.js +2 -0
- package/lib/models/user.model.d.ts +10 -0
- package/lib/models/user.model.d.ts.map +1 -1
- package/lib/models/video.model.d.ts +6 -0
- package/lib/models/video.model.d.ts.map +1 -1
- package/lib/schemas/brief.schema.d.ts +46 -0
- package/lib/schemas/brief.schema.d.ts.map +1 -1
- package/lib/schemas/brief.schema.js +72 -1
- package/lib/schemas/index.d.ts +1 -0
- package/lib/schemas/index.d.ts.map +1 -1
- package/lib/schemas/index.js +1 -0
- package/lib/schemas/project.schema.d.ts +67 -0
- package/lib/schemas/project.schema.d.ts.map +1 -1
- package/lib/schemas/project.schema.js +12 -0
- package/lib/schemas/social.schema.d.ts +91 -0
- package/lib/schemas/social.schema.d.ts.map +1 -0
- package/lib/schemas/social.schema.js +114 -0
- package/lib/schemas/videoPlan.schema.d.ts +114 -0
- package/lib/schemas/videoPlan.schema.d.ts.map +1 -1
- package/lib/schemas/videoPlan.schema.js +141 -1
- package/lib/services/agent/chatAgent.d.ts +25 -1
- package/lib/services/agent/chatAgent.d.ts.map +1 -1
- package/lib/services/agent/chatAgent.js +145 -9
- package/lib/services/agent/costPreflight.d.ts +11 -1
- package/lib/services/agent/costPreflight.d.ts.map +1 -1
- package/lib/services/agent/costPreflight.js +18 -1
- package/lib/services/agent/covers/coverPlanner.d.ts +41 -0
- package/lib/services/agent/covers/coverPlanner.d.ts.map +1 -0
- package/lib/services/agent/covers/coverPlanner.js +278 -0
- package/lib/services/agent/covers/covers.schema.d.ts +158 -0
- package/lib/services/agent/covers/covers.schema.d.ts.map +1 -0
- package/lib/services/agent/covers/covers.schema.js +166 -0
- package/lib/services/agent/covers/index.d.ts +3 -0
- package/lib/services/agent/covers/index.d.ts.map +1 -0
- package/lib/services/agent/covers/index.js +18 -0
- package/lib/services/agent/critic.d.ts +10 -0
- package/lib/services/agent/critic.d.ts.map +1 -1
- package/lib/services/agent/critic.js +37 -1
- package/lib/services/agent/editClassifier.d.ts +2 -2
- package/lib/services/agent/editClassifier.js +2 -2
- package/lib/services/agent/editExisting/editAssembler.d.ts +78 -0
- package/lib/services/agent/editExisting/editAssembler.d.ts.map +1 -0
- package/lib/services/agent/editExisting/editAssembler.js +172 -0
- package/lib/services/agent/editExisting/editExisting.schema.d.ts +119 -0
- package/lib/services/agent/editExisting/editExisting.schema.d.ts.map +1 -0
- package/lib/services/agent/editExisting/editExisting.schema.js +157 -0
- package/lib/services/agent/editExisting/highlightPicker.d.ts +48 -0
- package/lib/services/agent/editExisting/highlightPicker.d.ts.map +1 -0
- package/lib/services/agent/editExisting/highlightPicker.js +199 -0
- package/lib/services/agent/editExisting/index.d.ts +4 -0
- package/lib/services/agent/editExisting/index.d.ts.map +1 -0
- package/lib/services/agent/editExisting/index.js +19 -0
- package/lib/services/agent/eval/seedBriefs.d.ts +4 -3
- package/lib/services/agent/eval/seedBriefs.d.ts.map +1 -1
- package/lib/services/agent/eval/seedBriefs.js +283 -3
- package/lib/services/agent/eval/types.d.ts +10 -0
- package/lib/services/agent/eval/types.d.ts.map +1 -1
- package/lib/services/agent/executor/core.d.ts +70 -0
- package/lib/services/agent/executor/core.d.ts.map +1 -0
- package/lib/services/agent/executor/core.js +250 -0
- package/lib/services/agent/executor/duration.d.ts +20 -0
- package/lib/services/agent/executor/duration.d.ts.map +1 -0
- package/lib/services/agent/executor/duration.js +46 -0
- package/lib/services/agent/executor/index.d.ts +15 -0
- package/lib/services/agent/executor/index.d.ts.map +1 -0
- package/lib/services/agent/executor/index.js +32 -0
- package/lib/services/agent/executor/types.d.ts +183 -0
- package/lib/services/agent/executor/types.d.ts.map +1 -0
- package/lib/services/agent/executor/types.js +29 -0
- package/lib/services/agent/executor/visual.d.ts +32 -0
- package/lib/services/agent/executor/visual.d.ts.map +1 -0
- package/lib/services/agent/executor/visual.js +400 -0
- package/lib/services/agent/executor/voice.d.ts +17 -0
- package/lib/services/agent/executor/voice.d.ts.map +1 -0
- package/lib/services/agent/executor/voice.js +119 -0
- package/lib/services/agent/extendChain.d.ts +101 -0
- package/lib/services/agent/extendChain.d.ts.map +1 -0
- package/lib/services/agent/extendChain.js +177 -0
- package/lib/services/agent/index.d.ts +11 -1
- package/lib/services/agent/index.d.ts.map +1 -1
- package/lib/services/agent/index.js +11 -1
- package/lib/services/agent/llmCaller.d.ts +7 -8
- package/lib/services/agent/llmCaller.d.ts.map +1 -1
- package/lib/services/agent/llmCallerAnthropic.d.ts +44 -31
- package/lib/services/agent/llmCallerAnthropic.d.ts.map +1 -1
- package/lib/services/agent/llmCallerAnthropic.js +135 -60
- package/lib/services/agent/llmCallerFactory.d.ts +34 -0
- package/lib/services/agent/llmCallerFactory.d.ts.map +1 -0
- package/lib/services/agent/llmCallerFactory.js +31 -0
- package/lib/services/agent/llmCallerGemini.d.ts +62 -0
- package/lib/services/agent/llmCallerGemini.d.ts.map +1 -0
- package/lib/services/agent/llmCallerGemini.js +235 -0
- package/lib/services/agent/llmCallerOpenai.d.ts +56 -0
- package/lib/services/agent/llmCallerOpenai.d.ts.map +1 -0
- package/lib/services/agent/llmCallerOpenai.js +230 -0
- package/lib/services/agent/llmCallerRegistry.d.ts.map +1 -1
- package/lib/services/agent/llmCallerRegistry.js +7 -7
- package/lib/services/agent/llmCallerRouting.d.ts +63 -0
- package/lib/services/agent/llmCallerRouting.d.ts.map +1 -0
- package/lib/services/agent/llmCallerRouting.js +124 -0
- package/lib/services/agent/llmModelRegistry.d.ts +59 -0
- package/lib/services/agent/llmModelRegistry.d.ts.map +1 -0
- package/lib/services/agent/llmModelRegistry.js +168 -0
- package/lib/services/agent/llmRetry.d.ts +57 -0
- package/lib/services/agent/llmRetry.d.ts.map +1 -0
- package/lib/services/agent/llmRetry.js +102 -0
- package/lib/services/agent/modelRouter.d.ts +3 -3
- package/lib/services/agent/modelRouter.d.ts.map +1 -1
- package/lib/services/agent/modelRouter.js +27 -13
- package/lib/services/agent/planMutations.d.ts +54 -1
- package/lib/services/agent/planMutations.d.ts.map +1 -1
- package/lib/services/agent/planMutations.js +78 -0
- package/lib/services/agent/planner/Planner.d.ts +0 -17
- package/lib/services/agent/planner/Planner.d.ts.map +1 -1
- package/lib/services/agent/planner/Planner.js +67 -303
- package/lib/services/agent/planner/overlayRegen.d.ts +38 -0
- package/lib/services/agent/planner/overlayRegen.d.ts.map +1 -0
- package/lib/services/agent/planner/overlayRegen.js +145 -0
- package/lib/services/agent/planner/plannerMessages.d.ts +34 -0
- package/lib/services/agent/planner/plannerMessages.d.ts.map +1 -0
- package/lib/services/agent/planner/plannerMessages.js +185 -0
- package/lib/services/agent/planner/promptSections.d.ts +12 -0
- package/lib/services/agent/planner/promptSections.d.ts.map +1 -1
- package/lib/services/agent/planner/promptSections.js +57 -0
- package/lib/services/agent/planner/scriptFirstPlanner.d.ts +35 -0
- package/lib/services/agent/planner/scriptFirstPlanner.d.ts.map +1 -0
- package/lib/services/agent/planner/scriptFirstPlanner.js +140 -0
- package/lib/services/agent/planner/structuralRules.d.ts +10 -0
- package/lib/services/agent/planner/structuralRules.d.ts.map +1 -1
- package/lib/services/agent/planner/structuralRules.js +92 -9
- package/lib/services/agent/planner/validators.d.ts +18 -0
- package/lib/services/agent/planner/validators.d.ts.map +1 -1
- package/lib/services/agent/planner/validators.js +97 -0
- package/lib/services/agent/planner.d.ts +2 -1
- package/lib/services/agent/planner.d.ts.map +1 -1
- package/lib/services/agent/planner.js +5 -1
- package/lib/services/agent/priorProject.d.ts +26 -0
- package/lib/services/agent/priorProject.d.ts.map +1 -0
- package/lib/services/agent/priorProject.js +51 -0
- package/lib/services/agent/providerFallback/chains.d.ts.map +1 -1
- package/lib/services/agent/providerFallback/chains.js +27 -15
- package/lib/services/agent/repurpose/index.d.ts +3 -0
- package/lib/services/agent/repurpose/index.d.ts.map +1 -0
- package/lib/services/agent/repurpose/index.js +18 -0
- package/lib/services/agent/repurpose/repurpose.schema.d.ts +132 -0
- package/lib/services/agent/repurpose/repurpose.schema.d.ts.map +1 -0
- package/lib/services/agent/repurpose/repurpose.schema.js +144 -0
- package/lib/services/agent/repurpose/shortsPicker.d.ts +25 -0
- package/lib/services/agent/repurpose/shortsPicker.d.ts.map +1 -0
- package/lib/services/agent/repurpose/shortsPicker.js +218 -0
- package/lib/services/agent/runHelpers.d.ts +21 -2
- package/lib/services/agent/runHelpers.d.ts.map +1 -1
- package/lib/services/agent/runHelpers.js +71 -2
- package/lib/services/agent/tools/animateImage.tool.d.ts +1 -0
- package/lib/services/agent/tools/animateImage.tool.d.ts.map +1 -1
- package/lib/services/agent/tools/animateImage.tool.js +12 -0
- package/lib/services/agent/tools/chapterOutline.tool.d.ts +42 -0
- package/lib/services/agent/tools/chapterOutline.tool.d.ts.map +1 -0
- package/lib/services/agent/tools/chapterOutline.tool.js +115 -0
- package/lib/services/agent/tools/composeScene.tool.d.ts +63 -0
- package/lib/services/agent/tools/composeScene.tool.d.ts.map +1 -1
- package/lib/services/agent/tools/estimateCost.tool.d.ts +27 -0
- package/lib/services/agent/tools/estimateCost.tool.d.ts.map +1 -1
- package/lib/services/agent/tools/estimateCost.tool.js +55 -7
- package/lib/services/agent/tools/extendVideo.tool.d.ts +26 -0
- package/lib/services/agent/tools/extendVideo.tool.d.ts.map +1 -0
- package/lib/services/agent/tools/extendVideo.tool.js +149 -0
- package/lib/services/agent/tools/generateScript.tool.d.ts +184 -0
- package/lib/services/agent/tools/generateScript.tool.d.ts.map +1 -0
- package/lib/services/agent/tools/generateScript.tool.js +123 -0
- package/lib/services/agent/tools/generateVideo.tool.d.ts +1 -0
- package/lib/services/agent/tools/generateVideo.tool.d.ts.map +1 -1
- package/lib/services/agent/tools/generateVideo.tool.js +20 -1
- package/lib/services/agent/tools/index.d.ts +4 -0
- package/lib/services/agent/tools/index.d.ts.map +1 -1
- package/lib/services/agent/tools/index.js +4 -0
- package/lib/services/agent/tools/matchBrollToScript.tool.d.ts +50 -0
- package/lib/services/agent/tools/matchBrollToScript.tool.d.ts.map +1 -0
- package/lib/services/agent/tools/matchBrollToScript.tool.js +139 -0
- package/lib/services/agent/tools/planVideo.tool.d.ts +56 -0
- package/lib/services/agent/tools/planVideo.tool.d.ts.map +1 -1
- package/lib/services/agent/tools/planVideo.tool.js +3 -3
- package/lib/services/agent/tools/render.tool.d.ts +21 -0
- package/lib/services/agent/tools/render.tool.d.ts.map +1 -1
- package/lib/services/aiGen/aiGenFactory.service.d.ts.map +1 -1
- package/lib/services/aiGen/aiGenFactory.service.js +18 -3
- package/lib/services/aiGen/providers/anthropic/anthropic.service.d.ts +26 -0
- package/lib/services/aiGen/providers/anthropic/anthropic.service.d.ts.map +1 -0
- package/lib/services/aiGen/providers/anthropic/anthropic.service.js +95 -0
- package/lib/services/aiGen/providers/google/google.service.d.ts +24 -1
- package/lib/services/aiGen/providers/google/google.service.d.ts.map +1 -1
- package/lib/services/aiGen/providers/google/google.service.js +96 -244
- package/lib/services/aiGen/providers/google/googleErrors.d.ts +13 -0
- package/lib/services/aiGen/providers/google/googleErrors.d.ts.map +1 -0
- package/lib/services/aiGen/providers/google/googleErrors.js +102 -0
- package/lib/services/aiGen/providers/google/googleFetch.d.ts +8 -0
- package/lib/services/aiGen/providers/google/googleFetch.d.ts.map +1 -0
- package/lib/services/aiGen/providers/google/googleFetch.js +96 -0
- package/lib/services/aiGen/providers/google/googleMusic.d.ts +15 -0
- package/lib/services/aiGen/providers/google/googleMusic.d.ts.map +1 -0
- package/lib/services/aiGen/providers/google/googleMusic.js +77 -0
- package/lib/services/aiGen/providers/kling/kling.service.d.ts +7 -3
- package/lib/services/aiGen/providers/kling/kling.service.d.ts.map +1 -1
- package/lib/services/aiGen/providers/kling/kling.service.js +23 -367
- package/lib/services/aiGen/providers/kling/klingCredits.d.ts +9 -0
- package/lib/services/aiGen/providers/kling/klingCredits.d.ts.map +1 -0
- package/lib/services/aiGen/providers/kling/klingCredits.js +63 -0
- package/lib/services/aiGen/providers/kling/klingRequests.d.ts +32 -0
- package/lib/services/aiGen/providers/kling/klingRequests.d.ts.map +1 -0
- package/lib/services/aiGen/providers/kling/klingRequests.js +194 -0
- package/lib/services/aiGen/providers/kling/klingStatus.d.ts +16 -0
- package/lib/services/aiGen/providers/kling/klingStatus.d.ts.map +1 -0
- package/lib/services/aiGen/providers/kling/klingStatus.js +173 -0
- package/lib/services/bullmq.service.d.ts +61 -0
- package/lib/services/bullmq.service.d.ts.map +1 -1
- package/lib/services/bullmq.service.js +101 -1
- package/lib/services/crypto/index.d.ts +2 -0
- package/lib/services/crypto/index.d.ts.map +1 -0
- package/lib/services/crypto/index.js +17 -0
- package/lib/services/crypto/tokenVault.d.ts +47 -0
- package/lib/services/crypto/tokenVault.d.ts.map +1 -0
- package/lib/services/crypto/tokenVault.js +179 -0
- package/lib/services/editor/captionStyleHint.d.ts +3 -0
- package/lib/services/editor/captionStyleHint.d.ts.map +1 -0
- package/lib/services/editor/captionStyleHint.js +112 -0
- package/lib/services/editor/planToProject.d.ts +7 -66
- package/lib/services/editor/planToProject.d.ts.map +1 -1
- package/lib/services/editor/planToProject.helpers.d.ts +40 -0
- package/lib/services/editor/planToProject.helpers.d.ts.map +1 -0
- package/lib/services/editor/planToProject.helpers.js +177 -0
- package/lib/services/editor/planToProject.js +197 -180
- package/lib/services/editor/planToProject.types.d.ts +94 -0
- package/lib/services/editor/planToProject.types.d.ts.map +1 -0
- package/lib/services/editor/planToProject.types.js +2 -0
- package/lib/services/firestore.service.d.ts +5 -0
- package/lib/services/firestore.service.d.ts.map +1 -1
- package/lib/services/firestore.service.js +13 -0
- package/lib/services/index.d.ts +12 -0
- package/lib/services/index.d.ts.map +1 -1
- package/lib/services/index.js +12 -0
- package/lib/services/promptEnhancer/index.d.ts +18 -0
- package/lib/services/promptEnhancer/index.d.ts.map +1 -0
- package/lib/services/promptEnhancer/index.js +33 -0
- package/lib/services/promptEnhancer/models.d.ts +54 -0
- package/lib/services/promptEnhancer/models.d.ts.map +1 -0
- package/lib/services/promptEnhancer/models.js +37 -0
- package/lib/services/promptEnhancer/profiles/agent.profile.d.ts +14 -0
- package/lib/services/promptEnhancer/profiles/agent.profile.d.ts.map +1 -0
- package/lib/services/promptEnhancer/profiles/agent.profile.js +40 -0
- package/lib/services/promptEnhancer/profiles/avatar.profile.d.ts +13 -0
- package/lib/services/promptEnhancer/profiles/avatar.profile.d.ts.map +1 -0
- package/lib/services/promptEnhancer/profiles/avatar.profile.js +40 -0
- package/lib/services/promptEnhancer/profiles/base.d.ts +28 -0
- package/lib/services/promptEnhancer/profiles/base.d.ts.map +1 -0
- package/lib/services/promptEnhancer/profiles/base.js +35 -0
- package/lib/services/promptEnhancer/profiles/image.profile.d.ts +11 -0
- package/lib/services/promptEnhancer/profiles/image.profile.d.ts.map +1 -0
- package/lib/services/promptEnhancer/profiles/image.profile.js +42 -0
- package/lib/services/promptEnhancer/profiles/index.d.ts +12 -0
- package/lib/services/promptEnhancer/profiles/index.d.ts.map +1 -0
- package/lib/services/promptEnhancer/profiles/index.js +33 -0
- package/lib/services/promptEnhancer/profiles/video.profile.d.ts +15 -0
- package/lib/services/promptEnhancer/profiles/video.profile.d.ts.map +1 -0
- package/lib/services/promptEnhancer/profiles/video.profile.js +81 -0
- package/lib/services/promptEnhancer/promptEnhancer.service.d.ts +45 -0
- package/lib/services/promptEnhancer/promptEnhancer.service.d.ts.map +1 -0
- package/lib/services/promptEnhancer/promptEnhancer.service.js +157 -0
- package/lib/services/promptEnhancer/schema.d.ts +19 -0
- package/lib/services/promptEnhancer/schema.d.ts.map +1 -0
- package/lib/services/promptEnhancer/schema.js +43 -0
- package/lib/services/promptEnhancer/types.d.ts +112 -0
- package/lib/services/promptEnhancer/types.d.ts.map +1 -0
- package/lib/services/promptEnhancer/types.js +2 -0
- package/lib/services/socialAI/captionGen.d.ts +81 -0
- package/lib/services/socialAI/captionGen.d.ts.map +1 -0
- package/lib/services/socialAI/captionGen.js +206 -0
- package/lib/services/socialAI/hookScore.d.ts +85 -0
- package/lib/services/socialAI/hookScore.d.ts.map +1 -0
- package/lib/services/socialAI/hookScore.js +170 -0
- package/lib/services/socialAI/index.d.ts +3 -0
- package/lib/services/socialAI/index.d.ts.map +1 -0
- package/lib/services/socialAI/index.js +18 -0
- package/lib/services/socialAccounts/index.d.ts +2 -0
- package/lib/services/socialAccounts/index.d.ts.map +1 -0
- package/lib/services/socialAccounts/index.js +17 -0
- package/lib/services/socialAccounts/socialAccountService.d.ts +25 -0
- package/lib/services/socialAccounts/socialAccountService.d.ts.map +1 -0
- package/lib/services/socialAccounts/socialAccountService.js +105 -0
- package/lib/services/socialEngage/factory.d.ts +7 -0
- package/lib/services/socialEngage/factory.d.ts.map +1 -0
- package/lib/services/socialEngage/factory.js +25 -0
- package/lib/services/socialEngage/index.d.ts +6 -0
- package/lib/services/socialEngage/index.d.ts.map +1 -0
- package/lib/services/socialEngage/index.js +21 -0
- package/lib/services/socialEngage/meta.engage.d.ts +17 -0
- package/lib/services/socialEngage/meta.engage.d.ts.map +1 -0
- package/lib/services/socialEngage/meta.engage.js +128 -0
- package/lib/services/socialEngage/metaWebhook.d.ts +50 -0
- package/lib/services/socialEngage/metaWebhook.d.ts.map +1 -0
- package/lib/services/socialEngage/metaWebhook.js +93 -0
- package/lib/services/socialEngage/types.d.ts +72 -0
- package/lib/services/socialEngage/types.d.ts.map +1 -0
- package/lib/services/socialEngage/types.js +10 -0
- package/lib/services/socialEngage/youtube.engage.d.ts +9 -0
- package/lib/services/socialEngage/youtube.engage.d.ts.map +1 -0
- package/lib/services/socialEngage/youtube.engage.js +87 -0
- package/lib/services/socialFormat/aspectGeometry.d.ts +74 -0
- package/lib/services/socialFormat/aspectGeometry.d.ts.map +1 -0
- package/lib/services/socialFormat/aspectGeometry.js +135 -0
- package/lib/services/socialFormat/index.d.ts +2 -0
- package/lib/services/socialFormat/index.d.ts.map +1 -0
- package/lib/services/socialFormat/index.js +19 -0
- package/lib/services/socialInsights/index.d.ts +3 -0
- package/lib/services/socialInsights/index.d.ts.map +1 -0
- package/lib/services/socialInsights/index.js +18 -0
- package/lib/services/socialInsights/recommendations.d.ts +131 -0
- package/lib/services/socialInsights/recommendations.d.ts.map +1 -0
- package/lib/services/socialInsights/recommendations.js +277 -0
- package/lib/services/socialInsights/timeBuckets.d.ts +35 -0
- package/lib/services/socialInsights/timeBuckets.d.ts.map +1 -0
- package/lib/services/socialInsights/timeBuckets.js +78 -0
- package/lib/services/socialMetrics/factory.d.ts +5 -0
- package/lib/services/socialMetrics/factory.d.ts.map +1 -0
- package/lib/services/socialMetrics/factory.js +24 -0
- package/lib/services/socialMetrics/index.d.ts +6 -0
- package/lib/services/socialMetrics/index.d.ts.map +1 -0
- package/lib/services/socialMetrics/index.js +21 -0
- package/lib/services/socialMetrics/meta.metrics.d.ts +22 -0
- package/lib/services/socialMetrics/meta.metrics.d.ts.map +1 -0
- package/lib/services/socialMetrics/meta.metrics.js +137 -0
- package/lib/services/socialMetrics/tiktok.metrics.d.ts +8 -0
- package/lib/services/socialMetrics/tiktok.metrics.d.ts.map +1 -0
- package/lib/services/socialMetrics/tiktok.metrics.js +43 -0
- package/lib/services/socialMetrics/types.d.ts +54 -0
- package/lib/services/socialMetrics/types.d.ts.map +1 -0
- package/lib/services/socialMetrics/types.js +2 -0
- package/lib/services/socialMetrics/youtube.metrics.d.ts +8 -0
- package/lib/services/socialMetrics/youtube.metrics.d.ts.map +1 -0
- package/lib/services/socialMetrics/youtube.metrics.js +43 -0
- package/lib/services/socialOAuth/factory.d.ts +7 -0
- package/lib/services/socialOAuth/factory.d.ts.map +1 -0
- package/lib/services/socialOAuth/factory.js +42 -0
- package/lib/services/socialOAuth/index.d.ts +11 -0
- package/lib/services/socialOAuth/index.d.ts.map +1 -0
- package/lib/services/socialOAuth/index.js +26 -0
- package/lib/services/socialOAuth/linkedin.oauth.d.ts +14 -0
- package/lib/services/socialOAuth/linkedin.oauth.d.ts.map +1 -0
- package/lib/services/socialOAuth/linkedin.oauth.js +127 -0
- package/lib/services/socialOAuth/meta.oauth.d.ts +31 -0
- package/lib/services/socialOAuth/meta.oauth.d.ts.map +1 -0
- package/lib/services/socialOAuth/meta.oauth.js +214 -0
- package/lib/services/socialOAuth/oauthState.d.ts +14 -0
- package/lib/services/socialOAuth/oauthState.d.ts.map +1 -0
- package/lib/services/socialOAuth/oauthState.js +66 -0
- package/lib/services/socialOAuth/pinterest.oauth.d.ts +15 -0
- package/lib/services/socialOAuth/pinterest.oauth.d.ts.map +1 -0
- package/lib/services/socialOAuth/pinterest.oauth.js +126 -0
- package/lib/services/socialOAuth/threads.oauth.d.ts +14 -0
- package/lib/services/socialOAuth/threads.oauth.d.ts.map +1 -0
- package/lib/services/socialOAuth/threads.oauth.js +129 -0
- package/lib/services/socialOAuth/tiktok.oauth.d.ts +15 -0
- package/lib/services/socialOAuth/tiktok.oauth.d.ts.map +1 -0
- package/lib/services/socialOAuth/tiktok.oauth.js +151 -0
- package/lib/services/socialOAuth/types.d.ts +67 -0
- package/lib/services/socialOAuth/types.d.ts.map +1 -0
- package/lib/services/socialOAuth/types.js +2 -0
- package/lib/services/socialOAuth/x.oauth.d.ts +17 -0
- package/lib/services/socialOAuth/x.oauth.d.ts.map +1 -0
- package/lib/services/socialOAuth/x.oauth.js +134 -0
- package/lib/services/socialOAuth/youtube.oauth.d.ts +15 -0
- package/lib/services/socialOAuth/youtube.oauth.d.ts.map +1 -0
- package/lib/services/socialOAuth/youtube.oauth.js +156 -0
- package/lib/services/socialPublish/factory.d.ts +5 -0
- package/lib/services/socialPublish/factory.d.ts.map +1 -0
- package/lib/services/socialPublish/factory.js +32 -0
- package/lib/services/socialPublish/index.d.ts +10 -0
- package/lib/services/socialPublish/index.d.ts.map +1 -0
- package/lib/services/socialPublish/index.js +25 -0
- package/lib/services/socialPublish/linkedin.publish.d.ts +9 -0
- package/lib/services/socialPublish/linkedin.publish.d.ts.map +1 -0
- package/lib/services/socialPublish/linkedin.publish.js +143 -0
- package/lib/services/socialPublish/meta.publish.d.ts +28 -0
- package/lib/services/socialPublish/meta.publish.d.ts.map +1 -0
- package/lib/services/socialPublish/meta.publish.js +149 -0
- package/lib/services/socialPublish/pinterest.publish.d.ts +13 -0
- package/lib/services/socialPublish/pinterest.publish.d.ts.map +1 -0
- package/lib/services/socialPublish/pinterest.publish.js +130 -0
- package/lib/services/socialPublish/threads.publish.d.ts +12 -0
- package/lib/services/socialPublish/threads.publish.d.ts.map +1 -0
- package/lib/services/socialPublish/threads.publish.js +96 -0
- package/lib/services/socialPublish/tiktok.publish.d.ts +13 -0
- package/lib/services/socialPublish/tiktok.publish.d.ts.map +1 -0
- package/lib/services/socialPublish/tiktok.publish.js +118 -0
- package/lib/services/socialPublish/types.d.ts +47 -0
- package/lib/services/socialPublish/types.d.ts.map +1 -0
- package/lib/services/socialPublish/types.js +2 -0
- package/lib/services/socialPublish/x.publish.d.ts +12 -0
- package/lib/services/socialPublish/x.publish.d.ts.map +1 -0
- package/lib/services/socialPublish/x.publish.js +147 -0
- package/lib/services/socialPublish/youtube.publish.d.ts +9 -0
- package/lib/services/socialPublish/youtube.publish.d.ts.map +1 -0
- package/lib/services/socialPublish/youtube.publish.js +107 -0
- package/lib/services/stock/index.d.ts +2 -0
- package/lib/services/stock/index.d.ts.map +1 -0
- package/lib/services/stock/index.js +17 -0
- package/lib/services/stock/realPersonSafety.d.ts +99 -0
- package/lib/services/stock/realPersonSafety.d.ts.map +1 -0
- package/lib/services/stock/realPersonSafety.js +248 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +1 -0
- package/lib/utils/renderTier.d.ts +26 -0
- package/lib/utils/renderTier.d.ts.map +1 -0
- package/lib/utils/renderTier.js +34 -0
- package/package.json +1 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { LlmCaller } from "./llmCaller";
|
|
2
|
+
import { ProviderRoutingLlmCaller } from "./llmCallerRouting";
|
|
3
|
+
/**
|
|
4
|
+
* Build the native provider-dispatching LlmCaller from per-provider API keys
|
|
5
|
+
* (LLM_NATIVE_MIGRATION_PLAN). This is the single place the "construct three
|
|
6
|
+
* native callers + wrap in a dispatcher" wiring lives — both app bootstraps
|
|
7
|
+
* (firebase-functions, node-express-server) and the dev/eval scripts call it
|
|
8
|
+
* instead of copy-pasting the construction. Replaced the old per-call-site
|
|
9
|
+
* `new GatewayLlmCaller(...)`.
|
|
10
|
+
*
|
|
11
|
+
* Hosts own env reading (keys are passed in, not read here) so this stays a
|
|
12
|
+
* pure function. A provider with no key is left unwired — calls routed to it
|
|
13
|
+
* throw at dispatch, and its name is returned in `missing` so the caller can
|
|
14
|
+
* log/alert at boot rather than at first use.
|
|
15
|
+
*/
|
|
16
|
+
export interface NativeLlmCallerResult {
|
|
17
|
+
/** The dispatcher to hand to setLlmCaller(). */
|
|
18
|
+
caller: ProviderRoutingLlmCaller;
|
|
19
|
+
/**
|
|
20
|
+
* The Anthropic caller instance (or undefined if no key). Exposed so the
|
|
21
|
+
* functions host can also setAnthropicCaller() for the planner's web-search
|
|
22
|
+
* grounding, sharing the one client the dispatcher uses.
|
|
23
|
+
*/
|
|
24
|
+
anthropic?: LlmCaller;
|
|
25
|
+
/** Provider env-var names with no key supplied, for boot-time logging. */
|
|
26
|
+
missing: string[];
|
|
27
|
+
}
|
|
28
|
+
export declare function createNativeLlmCaller(opts: {
|
|
29
|
+
openaiKey?: string;
|
|
30
|
+
anthropicKey?: string;
|
|
31
|
+
geminiKey?: string;
|
|
32
|
+
timeoutMs?: number;
|
|
33
|
+
}): NativeLlmCallerResult;
|
|
34
|
+
//# sourceMappingURL=llmCallerFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llmCallerFactory.d.ts","sourceRoot":"","sources":["../../../src/services/agent/llmCallerFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAIxC,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAE9D;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,qBAAqB;IACpC,gDAAgD;IAChD,MAAM,EAAE,wBAAwB,CAAC;IACjC;;;;OAIG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,0EAA0E;IAC1E,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,qBAAqB,CAuBxB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createNativeLlmCaller = createNativeLlmCaller;
|
|
4
|
+
const llmCallerAnthropic_1 = require("./llmCallerAnthropic");
|
|
5
|
+
const llmCallerOpenai_1 = require("./llmCallerOpenai");
|
|
6
|
+
const llmCallerGemini_1 = require("./llmCallerGemini");
|
|
7
|
+
const llmCallerRouting_1 = require("./llmCallerRouting");
|
|
8
|
+
function createNativeLlmCaller(opts) {
|
|
9
|
+
const { openaiKey, anthropicKey, geminiKey, timeoutMs } = opts;
|
|
10
|
+
const anthropic = anthropicKey
|
|
11
|
+
? new llmCallerAnthropic_1.AnthropicLlmCaller({ apiKey: anthropicKey, timeoutMs })
|
|
12
|
+
: undefined;
|
|
13
|
+
const openai = openaiKey
|
|
14
|
+
? new llmCallerOpenai_1.OpenAiLlmCaller({ apiKey: openaiKey, timeoutMs })
|
|
15
|
+
: undefined;
|
|
16
|
+
const google = geminiKey
|
|
17
|
+
? new llmCallerGemini_1.GeminiLlmCaller({ apiKey: geminiKey, timeoutMs })
|
|
18
|
+
: undefined;
|
|
19
|
+
const missing = [];
|
|
20
|
+
if (!openaiKey)
|
|
21
|
+
missing.push("OPENAI_API_KEY");
|
|
22
|
+
if (!anthropicKey)
|
|
23
|
+
missing.push("ANTHROPIC_API_KEY");
|
|
24
|
+
if (!geminiKey)
|
|
25
|
+
missing.push("GOOGLE_API_KEY");
|
|
26
|
+
return {
|
|
27
|
+
caller: new llmCallerRouting_1.ProviderRoutingLlmCaller({ anthropic, openai, google }),
|
|
28
|
+
anthropic,
|
|
29
|
+
missing,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ChatRequest, ChatResponse, LlmCaller, StructuredRequest, StructuredResponse } from "./llmCaller";
|
|
3
|
+
/**
|
|
4
|
+
* Direct Google Gemini SDK LlmCaller (`@google/genai`) — native replacement for
|
|
5
|
+
* the Google slice of the Vercel AI Gateway (LLM_NATIVE_MIGRATION_PLAN Phase 4).
|
|
6
|
+
*
|
|
7
|
+
* Required to not regress the critic (gemini-2.5-flash, vision) and reference
|
|
8
|
+
* (gemini-2.5-pro, vision) roles, which route to `google` today. Single-provider:
|
|
9
|
+
* only serves `provider === "google"` ModelChoices; transport retry only (the
|
|
10
|
+
* dispatcher owns cross-provider fallback).
|
|
11
|
+
*
|
|
12
|
+
* Structured output uses Gemini's native `responseSchema` + JSON mime type; the
|
|
13
|
+
* client-side `JSON.parse` + Zod `safeParse` stay the source of truth (same
|
|
14
|
+
* contract as the OpenAI/gateway callers).
|
|
15
|
+
*
|
|
16
|
+
* Mapping notes:
|
|
17
|
+
* - system messages → `config.systemInstruction` (Gemini has no system role).
|
|
18
|
+
* - assistant role → Gemini's "model" role.
|
|
19
|
+
* - maxTokens → `config.maxOutputTokens`.
|
|
20
|
+
* - vision: imageUrls are fetched + base64-inlined (`inlineData`); Gemini does
|
|
21
|
+
* not accept arbitrary https URLs in `generateContent`.
|
|
22
|
+
*/
|
|
23
|
+
export interface GeminiCallerConfig {
|
|
24
|
+
apiKey: string;
|
|
25
|
+
/** Default request timeout in ms. Default 180s. */
|
|
26
|
+
timeoutMs?: number;
|
|
27
|
+
/** Max retries on transient errors per call. Default 3. */
|
|
28
|
+
maxRetries?: number;
|
|
29
|
+
/** Optional fetch override (tests). */
|
|
30
|
+
fetchImpl?: typeof fetch;
|
|
31
|
+
}
|
|
32
|
+
export declare class GeminiLlmCaller implements LlmCaller {
|
|
33
|
+
private readonly ai;
|
|
34
|
+
private readonly maxRetries;
|
|
35
|
+
private readonly fetchImpl;
|
|
36
|
+
constructor(cfg: GeminiCallerConfig);
|
|
37
|
+
chat(req: ChatRequest): Promise<ChatResponse>;
|
|
38
|
+
structured<T extends z.ZodTypeAny>(req: StructuredRequest<T>): Promise<StructuredResponse<T>>;
|
|
39
|
+
structuredStream<T extends z.ZodTypeAny>(req: StructuredRequest<T>): {
|
|
40
|
+
tokens: AsyncIterable<string>;
|
|
41
|
+
result: Promise<StructuredResponse<T>>;
|
|
42
|
+
};
|
|
43
|
+
private streamIterator;
|
|
44
|
+
private buildConfig;
|
|
45
|
+
/**
|
|
46
|
+
* Split system messages into a merged `systemInstruction` and map the rest to
|
|
47
|
+
* Gemini `Content` (user/model roles). Vision images are fetched + inlined.
|
|
48
|
+
*/
|
|
49
|
+
private encode;
|
|
50
|
+
/** Fetch an image URL and inline it as base64 (Gemini rejects raw https URLs). */
|
|
51
|
+
private toInlinePart;
|
|
52
|
+
private parseStructured;
|
|
53
|
+
private resolveModelId;
|
|
54
|
+
private usage;
|
|
55
|
+
/**
|
|
56
|
+
* Transport retry mapping the genai SDK's error shape (carries a numeric
|
|
57
|
+
* `status`) into the shared transient policy. Non-transient statuses
|
|
58
|
+
* (400/401/403/404) propagate immediately.
|
|
59
|
+
*/
|
|
60
|
+
private withRetry;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=llmCallerGemini.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llmCallerGemini.d.ts","sourceRoot":"","sources":["../../../src/services/agent/llmCallerGemini.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAEL,WAAW,EACX,YAAY,EACZ,SAAS,EACT,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAKrB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,mDAAmD;IACnD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uCAAuC;IACvC,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B;AAID,qBAAa,eAAgB,YAAW,SAAS;IAC/C,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAc;IACjC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAe;gBAE7B,GAAG,EAAE,kBAAkB;IAM7B,IAAI,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAuB7C,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EACrC,GAAG,EAAE,iBAAiB,CAAC,CAAC,CAAC,GACxB,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;IAwBjC,gBAAgB,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EACrC,GAAG,EAAE,iBAAiB,CAAC,CAAC,CAAC,GACxB;QACD,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;QAC9B,MAAM,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;KACxC;YAgBc,cAAc;IAyD7B,OAAO,CAAC,WAAW;IAmBnB;;;OAGG;YACW,MAAM;IAyBpB,kFAAkF;YACpE,YAAY;IAkB1B,OAAO,CAAC,eAAe;IA0BvB,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,KAAK;IAcb;;;;OAIG;IACH,OAAO,CAAC,SAAS;CAmBlB"}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GeminiLlmCaller = void 0;
|
|
4
|
+
const genai_1 = require("@google/genai");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const llmModelRegistry_1 = require("./llmModelRegistry");
|
|
7
|
+
const llmRetry_1 = require("./llmRetry");
|
|
8
|
+
const TRANSIENT_HTTP = new Set([408, 425, 429, 500, 502, 503, 504]);
|
|
9
|
+
class GeminiLlmCaller {
|
|
10
|
+
constructor(cfg) {
|
|
11
|
+
this.ai = new genai_1.GoogleGenAI({ apiKey: cfg.apiKey });
|
|
12
|
+
this.maxRetries = cfg.maxRetries ?? 3;
|
|
13
|
+
this.fetchImpl = cfg.fetchImpl ?? fetch;
|
|
14
|
+
}
|
|
15
|
+
async chat(req) {
|
|
16
|
+
const { systemInstruction, contents } = await this.encode(req.messages);
|
|
17
|
+
const resp = await this.withRetry(() => this.ai.models.generateContent({
|
|
18
|
+
model: this.resolveModelId(req.model),
|
|
19
|
+
contents,
|
|
20
|
+
config: this.buildConfig({
|
|
21
|
+
systemInstruction,
|
|
22
|
+
temperature: req.temperature,
|
|
23
|
+
maxTokens: req.maxTokens,
|
|
24
|
+
stop: req.stop,
|
|
25
|
+
}),
|
|
26
|
+
}));
|
|
27
|
+
return {
|
|
28
|
+
text: resp.text ?? "",
|
|
29
|
+
usage: this.usage(resp),
|
|
30
|
+
requestId: resp.responseId,
|
|
31
|
+
attemptedModels: [req.model],
|
|
32
|
+
usedFallback: false,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async structured(req) {
|
|
36
|
+
const { systemInstruction, contents } = await this.encode(req.messages);
|
|
37
|
+
const jsonSchema = zod_1.z.toJSONSchema(req.schema, { target: "draft-7" });
|
|
38
|
+
const resp = await this.withRetry(() => this.ai.models.generateContent({
|
|
39
|
+
model: this.resolveModelId(req.model),
|
|
40
|
+
contents,
|
|
41
|
+
config: this.buildConfig({
|
|
42
|
+
systemInstruction,
|
|
43
|
+
temperature: req.temperature,
|
|
44
|
+
maxTokens: req.maxTokens,
|
|
45
|
+
responseSchema: jsonSchema,
|
|
46
|
+
}),
|
|
47
|
+
}));
|
|
48
|
+
return {
|
|
49
|
+
...this.parseStructured(req, resp.text ?? ""),
|
|
50
|
+
usage: this.usage(resp),
|
|
51
|
+
requestId: resp.responseId,
|
|
52
|
+
attemptedModels: [req.model],
|
|
53
|
+
usedFallback: false,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
structuredStream(req) {
|
|
57
|
+
let resolveResult;
|
|
58
|
+
let rejectResult;
|
|
59
|
+
const result = new Promise((resolve, reject) => {
|
|
60
|
+
resolveResult = resolve;
|
|
61
|
+
rejectResult = reject;
|
|
62
|
+
});
|
|
63
|
+
const self = this;
|
|
64
|
+
const tokens = {
|
|
65
|
+
[Symbol.asyncIterator]() {
|
|
66
|
+
return self.streamIterator(req, resolveResult, rejectResult);
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
return { tokens, result };
|
|
70
|
+
}
|
|
71
|
+
async *streamIterator(req, resolveResult, rejectResult) {
|
|
72
|
+
let accumulated = "";
|
|
73
|
+
let requestId;
|
|
74
|
+
let usage;
|
|
75
|
+
try {
|
|
76
|
+
const { systemInstruction, contents } = await this.encode(req.messages);
|
|
77
|
+
const jsonSchema = zod_1.z.toJSONSchema(req.schema, { target: "draft-7" });
|
|
78
|
+
const stream = await this.withRetry(() => this.ai.models.generateContentStream({
|
|
79
|
+
model: this.resolveModelId(req.model),
|
|
80
|
+
contents,
|
|
81
|
+
config: this.buildConfig({
|
|
82
|
+
systemInstruction,
|
|
83
|
+
temperature: req.temperature,
|
|
84
|
+
maxTokens: req.maxTokens,
|
|
85
|
+
responseSchema: jsonSchema,
|
|
86
|
+
}),
|
|
87
|
+
}));
|
|
88
|
+
for await (const chunk of stream) {
|
|
89
|
+
if (chunk.responseId)
|
|
90
|
+
requestId = chunk.responseId;
|
|
91
|
+
const u = this.usage(chunk);
|
|
92
|
+
if (u)
|
|
93
|
+
usage = u;
|
|
94
|
+
const delta = chunk.text ?? "";
|
|
95
|
+
if (delta) {
|
|
96
|
+
accumulated += delta;
|
|
97
|
+
yield delta;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// Post-stream parse/validate failures reject the RESULT promise but must
|
|
101
|
+
// NOT throw out of the generator (same contract as the other callers —
|
|
102
|
+
// the planner's retry fallback awaits `result`).
|
|
103
|
+
try {
|
|
104
|
+
const parsed = this.parseStructured(req, accumulated);
|
|
105
|
+
resolveResult({
|
|
106
|
+
data: parsed.data,
|
|
107
|
+
usage,
|
|
108
|
+
requestId,
|
|
109
|
+
attemptedModels: [req.model],
|
|
110
|
+
usedFallback: false,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
rejectResult(e);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch (e) {
|
|
119
|
+
rejectResult(e);
|
|
120
|
+
throw e;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// ---------- helpers ----------
|
|
124
|
+
buildConfig(opts) {
|
|
125
|
+
const config = {};
|
|
126
|
+
if (opts.systemInstruction)
|
|
127
|
+
config.systemInstruction = opts.systemInstruction;
|
|
128
|
+
if (opts.temperature !== undefined)
|
|
129
|
+
config.temperature = opts.temperature;
|
|
130
|
+
if (opts.maxTokens !== undefined)
|
|
131
|
+
config.maxOutputTokens = opts.maxTokens;
|
|
132
|
+
if (opts.stop?.length)
|
|
133
|
+
config.stopSequences = opts.stop;
|
|
134
|
+
if (opts.responseSchema) {
|
|
135
|
+
config.responseMimeType = "application/json";
|
|
136
|
+
config.responseSchema = opts.responseSchema;
|
|
137
|
+
}
|
|
138
|
+
return config;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Split system messages into a merged `systemInstruction` and map the rest to
|
|
142
|
+
* Gemini `Content` (user/model roles). Vision images are fetched + inlined.
|
|
143
|
+
*/
|
|
144
|
+
async encode(messages) {
|
|
145
|
+
let systemInstruction;
|
|
146
|
+
const contents = [];
|
|
147
|
+
for (const m of messages) {
|
|
148
|
+
if (m.role === "system") {
|
|
149
|
+
systemInstruction = systemInstruction
|
|
150
|
+
? `${systemInstruction}\n\n${m.content}`
|
|
151
|
+
: m.content;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const role = m.role === "assistant" ? "model" : "user";
|
|
155
|
+
const parts = [{ text: m.content }];
|
|
156
|
+
if (m.imageUrls?.length) {
|
|
157
|
+
for (const url of m.imageUrls) {
|
|
158
|
+
parts.push(await this.toInlinePart(url));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
contents.push({ role, parts });
|
|
162
|
+
}
|
|
163
|
+
return { systemInstruction, contents };
|
|
164
|
+
}
|
|
165
|
+
/** Fetch an image URL and inline it as base64 (Gemini rejects raw https URLs). */
|
|
166
|
+
async toInlinePart(url) {
|
|
167
|
+
if (url.startsWith("data:")) {
|
|
168
|
+
const [meta, data] = url.split(",", 2);
|
|
169
|
+
const mimeType = meta?.slice(5).split(";")[0] || "image/jpeg";
|
|
170
|
+
return { inlineData: { mimeType, data: data ?? "" } };
|
|
171
|
+
}
|
|
172
|
+
const res = await this.fetchImpl(url);
|
|
173
|
+
if (!res.ok) {
|
|
174
|
+
throw new Error(`GeminiLlmCaller.toInlinePart: ${res.status} ${res.statusText} fetching ${url}`);
|
|
175
|
+
}
|
|
176
|
+
const mimeType = res.headers.get("content-type")?.split(";")[0]?.trim() || "image/jpeg";
|
|
177
|
+
const buf = Buffer.from(await res.arrayBuffer());
|
|
178
|
+
return { inlineData: { mimeType, data: buf.toString("base64") } };
|
|
179
|
+
}
|
|
180
|
+
parseStructured(req, txt) {
|
|
181
|
+
if (!txt) {
|
|
182
|
+
throw new Error(`GeminiLlmCaller.structured: empty response for schema ${req.schemaName}`);
|
|
183
|
+
}
|
|
184
|
+
let parsed;
|
|
185
|
+
try {
|
|
186
|
+
parsed = JSON.parse(txt);
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
throw new Error(`GeminiLlmCaller.structured: model returned non-JSON for ${req.schemaName}: ${txt.slice(0, 200)}`);
|
|
190
|
+
}
|
|
191
|
+
const result = req.schema.safeParse(parsed);
|
|
192
|
+
if (!result.success) {
|
|
193
|
+
throw new Error(`GeminiLlmCaller.structured: schema validation failed for ${req.schemaName}: ${result.error.message}`);
|
|
194
|
+
}
|
|
195
|
+
return { data: result.data };
|
|
196
|
+
}
|
|
197
|
+
resolveModelId(m) {
|
|
198
|
+
if ((0, llmModelRegistry_1.normalizeProvider)(m.provider) !== "google") {
|
|
199
|
+
throw new Error(`GeminiLlmCaller cannot serve provider=${m.provider}; route via the dispatcher.`);
|
|
200
|
+
}
|
|
201
|
+
return (0, llmModelRegistry_1.nativeModelId)(m);
|
|
202
|
+
}
|
|
203
|
+
usage(resp) {
|
|
204
|
+
const u = resp.usageMetadata;
|
|
205
|
+
if (!u)
|
|
206
|
+
return undefined;
|
|
207
|
+
return {
|
|
208
|
+
promptTokens: u.promptTokenCount,
|
|
209
|
+
completionTokens: u.candidatesTokenCount,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Transport retry mapping the genai SDK's error shape (carries a numeric
|
|
214
|
+
* `status`) into the shared transient policy. Non-transient statuses
|
|
215
|
+
* (400/401/403/404) propagate immediately.
|
|
216
|
+
*/
|
|
217
|
+
withRetry(fn) {
|
|
218
|
+
return (0, llmRetry_1.withRetry)(async () => {
|
|
219
|
+
try {
|
|
220
|
+
return await fn();
|
|
221
|
+
}
|
|
222
|
+
catch (err) {
|
|
223
|
+
const status = err?.status;
|
|
224
|
+
if (typeof status === "number" && !TRANSIENT_HTTP.has(status)) {
|
|
225
|
+
throw err;
|
|
226
|
+
}
|
|
227
|
+
if (typeof status === "number" && TRANSIENT_HTTP.has(status)) {
|
|
228
|
+
throw new llmRetry_1.TransientLlmError(`Gemini ${status} error`, err);
|
|
229
|
+
}
|
|
230
|
+
throw err;
|
|
231
|
+
}
|
|
232
|
+
}, { maxRetries: this.maxRetries });
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
exports.GeminiLlmCaller = GeminiLlmCaller;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ChatRequest, ChatResponse, LlmCaller, StructuredRequest, StructuredResponse } from "./llmCaller";
|
|
3
|
+
/**
|
|
4
|
+
* Direct OpenAI SDK LlmCaller — native replacement for the OpenAI slice of the
|
|
5
|
+
* Vercel AI Gateway (LLM_NATIVE_MIGRATION_PLAN Phase 2).
|
|
6
|
+
*
|
|
7
|
+
* Single-provider: only serves `provider === "openai"` ModelChoices (the
|
|
8
|
+
* dispatcher routes by provider). Does NOT implement cross-provider model
|
|
9
|
+
* fallback — that's the ProviderRoutingLlmCaller's job; this caller only does
|
|
10
|
+
* transport retry via the shared `withRetry`.
|
|
11
|
+
*
|
|
12
|
+
* Structured output uses the native strict `json_schema` response_format —
|
|
13
|
+
* identical semantics to what the gateway sent to OpenAI, with the client-side
|
|
14
|
+
* `JSON.parse` + Zod `safeParse` kept as the source of truth so a strict-mode
|
|
15
|
+
* miss still surfaces as a deterministic (non-transient) error.
|
|
16
|
+
*
|
|
17
|
+
* Native wins over the gateway shape: automatic prompt caching on long stable
|
|
18
|
+
* prefixes (OpenAI caches ≥1024-token prompts server-side, billed at a
|
|
19
|
+
* discount, no flag needed) and direct provider billing.
|
|
20
|
+
*/
|
|
21
|
+
export interface OpenAiCallerConfig {
|
|
22
|
+
apiKey: string;
|
|
23
|
+
/** Optional base URL override (e.g. an OpenAI-compatible endpoint). */
|
|
24
|
+
baseURL?: string;
|
|
25
|
+
/** Default request timeout in ms. Default 180s (matches planner budget). */
|
|
26
|
+
timeoutMs?: number;
|
|
27
|
+
/** Max retries on transient errors per call. Default 3. */
|
|
28
|
+
maxRetries?: number;
|
|
29
|
+
}
|
|
30
|
+
export declare class OpenAiLlmCaller implements LlmCaller {
|
|
31
|
+
private readonly client;
|
|
32
|
+
private readonly timeoutMs;
|
|
33
|
+
private readonly maxRetries;
|
|
34
|
+
constructor(cfg: OpenAiCallerConfig);
|
|
35
|
+
chat(req: ChatRequest): Promise<ChatResponse>;
|
|
36
|
+
structured<T extends z.ZodTypeAny>(req: StructuredRequest<T>): Promise<StructuredResponse<T>>;
|
|
37
|
+
structuredStream<T extends z.ZodTypeAny>(req: StructuredRequest<T>): {
|
|
38
|
+
tokens: AsyncIterable<string>;
|
|
39
|
+
result: Promise<StructuredResponse<T>>;
|
|
40
|
+
};
|
|
41
|
+
private streamIterator;
|
|
42
|
+
/** Shared non-streaming params: model id, encoded messages, sampling knobs. */
|
|
43
|
+
private baseParams;
|
|
44
|
+
private encodeMessage;
|
|
45
|
+
/** Parse + Zod-validate the model's text. Throws plain (non-transient) Error. */
|
|
46
|
+
private parseStructured;
|
|
47
|
+
private resolveModelId;
|
|
48
|
+
private usage;
|
|
49
|
+
/**
|
|
50
|
+
* Transport retry that re-classifies the OpenAI SDK's APIError shape (it
|
|
51
|
+
* carries a numeric `status`) into the shared transient policy. Non-transient
|
|
52
|
+
* statuses (400/401/403/404/422) propagate immediately.
|
|
53
|
+
*/
|
|
54
|
+
private withRetry;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=llmCallerOpenai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llmCallerOpenai.d.ts","sourceRoot":"","sources":["../../../src/services/agent/llmCallerOpenai.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAEL,WAAW,EACX,YAAY,EACZ,SAAS,EACT,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAKrB;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4EAA4E;IAC5E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAID,qBAAa,eAAgB,YAAW,SAAS;IAC/C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAExB,GAAG,EAAE,kBAAkB;IAU7B,IAAI,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAoB7C,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EACrC,GAAG,EAAE,iBAAiB,CAAC,CAAC,CAAC,GACxB,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;IA4BjC,gBAAgB,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EACrC,GAAG,EAAE,iBAAiB,CAAC,CAAC,CAAC,GACxB;QACD,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;QAC9B,MAAM,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;KACxC;YAgBc,cAAc;IAqE7B,+EAA+E;IAC/E,OAAO,CAAC,UAAU;IAoBlB,OAAO,CAAC,aAAa;IAkBrB,iFAAiF;IACjF,OAAO,CAAC,eAAe;IA0BvB,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,KAAK;IAUb;;;;OAIG;IACH,OAAO,CAAC,SAAS;CAyBlB"}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.OpenAiLlmCaller = void 0;
|
|
7
|
+
const openai_1 = __importDefault(require("openai"));
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
const llmModelRegistry_1 = require("./llmModelRegistry");
|
|
10
|
+
const llmRetry_1 = require("./llmRetry");
|
|
11
|
+
const TRANSIENT_HTTP = new Set([408, 425, 429, 500, 502, 503, 504]);
|
|
12
|
+
class OpenAiLlmCaller {
|
|
13
|
+
constructor(cfg) {
|
|
14
|
+
this.client = new openai_1.default({
|
|
15
|
+
apiKey: cfg.apiKey,
|
|
16
|
+
...(cfg.baseURL ? { baseURL: cfg.baseURL } : {}),
|
|
17
|
+
timeout: cfg.timeoutMs ?? 180000,
|
|
18
|
+
});
|
|
19
|
+
this.timeoutMs = cfg.timeoutMs ?? 180000;
|
|
20
|
+
this.maxRetries = cfg.maxRetries ?? 3;
|
|
21
|
+
}
|
|
22
|
+
async chat(req) {
|
|
23
|
+
const completion = await this.withRetry(() => this.client.chat.completions.create(this.baseParams(req.model, req.messages, {
|
|
24
|
+
temperature: req.temperature,
|
|
25
|
+
maxTokens: req.maxTokens,
|
|
26
|
+
stop: req.stop,
|
|
27
|
+
})));
|
|
28
|
+
const text = completion.choices?.[0]?.message?.content ?? "";
|
|
29
|
+
return {
|
|
30
|
+
text: typeof text === "string" ? text : JSON.stringify(text),
|
|
31
|
+
usage: this.usage(completion.usage),
|
|
32
|
+
requestId: completion.id,
|
|
33
|
+
attemptedModels: [req.model],
|
|
34
|
+
usedFallback: false,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
async structured(req) {
|
|
38
|
+
const jsonSchema = zod_1.z.toJSONSchema(req.schema, { target: "draft-7" });
|
|
39
|
+
const completion = await this.withRetry(() => this.client.chat.completions.create({
|
|
40
|
+
...this.baseParams(req.model, req.messages, {
|
|
41
|
+
temperature: req.temperature,
|
|
42
|
+
maxTokens: req.maxTokens,
|
|
43
|
+
}),
|
|
44
|
+
response_format: {
|
|
45
|
+
type: "json_schema",
|
|
46
|
+
json_schema: {
|
|
47
|
+
name: req.schemaName,
|
|
48
|
+
schema: jsonSchema,
|
|
49
|
+
strict: true,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
}));
|
|
53
|
+
const txt = completion.choices?.[0]?.message?.content ?? "";
|
|
54
|
+
return {
|
|
55
|
+
...this.parseStructured(req, txt),
|
|
56
|
+
usage: this.usage(completion.usage),
|
|
57
|
+
requestId: completion.id,
|
|
58
|
+
attemptedModels: [req.model],
|
|
59
|
+
usedFallback: false,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
structuredStream(req) {
|
|
63
|
+
let resolveResult;
|
|
64
|
+
let rejectResult;
|
|
65
|
+
const result = new Promise((resolve, reject) => {
|
|
66
|
+
resolveResult = resolve;
|
|
67
|
+
rejectResult = reject;
|
|
68
|
+
});
|
|
69
|
+
const self = this;
|
|
70
|
+
const tokens = {
|
|
71
|
+
[Symbol.asyncIterator]() {
|
|
72
|
+
return self.streamIterator(req, resolveResult, rejectResult);
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
return { tokens, result };
|
|
76
|
+
}
|
|
77
|
+
async *streamIterator(req, resolveResult, rejectResult) {
|
|
78
|
+
const jsonSchema = zod_1.z.toJSONSchema(req.schema, { target: "draft-7" });
|
|
79
|
+
let accumulated = "";
|
|
80
|
+
let requestId;
|
|
81
|
+
let usage;
|
|
82
|
+
try {
|
|
83
|
+
// Connect with transient retry; once bytes flow a mid-stream drop
|
|
84
|
+
// propagates and the planner's own retry loop handles it (mirrors the
|
|
85
|
+
// gateway's streaming contract).
|
|
86
|
+
const stream = await this.withRetry(() => this.client.chat.completions.create({
|
|
87
|
+
...this.baseParams(req.model, req.messages, {
|
|
88
|
+
temperature: req.temperature,
|
|
89
|
+
maxTokens: req.maxTokens,
|
|
90
|
+
}),
|
|
91
|
+
response_format: {
|
|
92
|
+
type: "json_schema",
|
|
93
|
+
json_schema: {
|
|
94
|
+
name: req.schemaName,
|
|
95
|
+
schema: jsonSchema,
|
|
96
|
+
strict: true,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
stream: true,
|
|
100
|
+
stream_options: { include_usage: true },
|
|
101
|
+
}));
|
|
102
|
+
for await (const chunk of stream) {
|
|
103
|
+
if (chunk.id)
|
|
104
|
+
requestId = chunk.id;
|
|
105
|
+
if (chunk.usage) {
|
|
106
|
+
usage = {
|
|
107
|
+
promptTokens: chunk.usage.prompt_tokens,
|
|
108
|
+
completionTokens: chunk.usage.completion_tokens,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const delta = chunk.choices?.[0]?.delta?.content ?? "";
|
|
112
|
+
if (delta) {
|
|
113
|
+
accumulated += delta;
|
|
114
|
+
yield delta;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// Post-stream parse/validate failures reject the RESULT promise but must
|
|
118
|
+
// NOT throw out of the generator — the planner awaits `result` for its
|
|
119
|
+
// non-streaming retry fallback. (Same rationale as GatewayLlmCaller.)
|
|
120
|
+
try {
|
|
121
|
+
const parsed = this.parseStructured(req, accumulated);
|
|
122
|
+
resolveResult({
|
|
123
|
+
data: parsed.data,
|
|
124
|
+
usage,
|
|
125
|
+
requestId,
|
|
126
|
+
attemptedModels: [req.model],
|
|
127
|
+
usedFallback: false,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
catch (e) {
|
|
131
|
+
rejectResult(e);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch (e) {
|
|
136
|
+
rejectResult(e);
|
|
137
|
+
throw e;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// ---------- helpers ----------
|
|
141
|
+
/** Shared non-streaming params: model id, encoded messages, sampling knobs. */
|
|
142
|
+
baseParams(model, messages, opts) {
|
|
143
|
+
return {
|
|
144
|
+
model: this.resolveModelId(model),
|
|
145
|
+
messages: messages.map((m) => this.encodeMessage(m)),
|
|
146
|
+
// Only send temperature when explicitly set — gpt-5 reasoning models
|
|
147
|
+
// reject non-default temperatures, and most agent calls leave it unset.
|
|
148
|
+
...(opts.temperature !== undefined ? { temperature: opts.temperature } : {}),
|
|
149
|
+
// gpt-5 family requires max_completion_tokens (max_tokens is rejected on
|
|
150
|
+
// reasoning models); it's also accepted by non-reasoning models.
|
|
151
|
+
...(opts.maxTokens !== undefined
|
|
152
|
+
? { max_completion_tokens: opts.maxTokens }
|
|
153
|
+
: {}),
|
|
154
|
+
...(opts.stop?.length ? { stop: opts.stop } : {}),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
encodeMessage(m) {
|
|
158
|
+
if (!m.imageUrls?.length) {
|
|
159
|
+
return { role: m.role, content: m.content };
|
|
160
|
+
}
|
|
161
|
+
// OpenAI accepts https image URLs directly (no base64 round-trip needed).
|
|
162
|
+
// Only user messages carry image parts.
|
|
163
|
+
const parts = [
|
|
164
|
+
{ type: "text", text: m.content },
|
|
165
|
+
...m.imageUrls.map((url) => ({
|
|
166
|
+
type: "image_url",
|
|
167
|
+
image_url: { url },
|
|
168
|
+
})),
|
|
169
|
+
];
|
|
170
|
+
return { role: "user", content: parts };
|
|
171
|
+
}
|
|
172
|
+
/** Parse + Zod-validate the model's text. Throws plain (non-transient) Error. */
|
|
173
|
+
parseStructured(req, txt) {
|
|
174
|
+
if (!txt || typeof txt !== "string") {
|
|
175
|
+
throw new Error(`OpenAiLlmCaller.structured: empty response for schema ${req.schemaName}`);
|
|
176
|
+
}
|
|
177
|
+
let parsed;
|
|
178
|
+
try {
|
|
179
|
+
parsed = JSON.parse(txt);
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
throw new Error(`OpenAiLlmCaller.structured: model returned non-JSON for ${req.schemaName}: ${txt.slice(0, 200)}`);
|
|
183
|
+
}
|
|
184
|
+
const result = req.schema.safeParse(parsed);
|
|
185
|
+
if (!result.success) {
|
|
186
|
+
throw new Error(`OpenAiLlmCaller.structured: schema validation failed for ${req.schemaName}: ${result.error.message}`);
|
|
187
|
+
}
|
|
188
|
+
return { data: result.data };
|
|
189
|
+
}
|
|
190
|
+
resolveModelId(m) {
|
|
191
|
+
if ((0, llmModelRegistry_1.normalizeProvider)(m.provider) !== "openai") {
|
|
192
|
+
throw new Error(`OpenAiLlmCaller cannot serve provider=${m.provider}; route via the dispatcher.`);
|
|
193
|
+
}
|
|
194
|
+
return (0, llmModelRegistry_1.nativeModelId)(m);
|
|
195
|
+
}
|
|
196
|
+
usage(u) {
|
|
197
|
+
if (!u)
|
|
198
|
+
return undefined;
|
|
199
|
+
return {
|
|
200
|
+
promptTokens: u.prompt_tokens,
|
|
201
|
+
completionTokens: u.completion_tokens,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Transport retry that re-classifies the OpenAI SDK's APIError shape (it
|
|
206
|
+
* carries a numeric `status`) into the shared transient policy. Non-transient
|
|
207
|
+
* statuses (400/401/403/404/422) propagate immediately.
|
|
208
|
+
*/
|
|
209
|
+
withRetry(fn) {
|
|
210
|
+
return (0, llmRetry_1.withRetry)(async () => {
|
|
211
|
+
try {
|
|
212
|
+
return await fn();
|
|
213
|
+
}
|
|
214
|
+
catch (err) {
|
|
215
|
+
// OpenAI APIError exposes `status`; map 5xx/429/408 → transient so the
|
|
216
|
+
// shared loop retries, everything else short-circuits.
|
|
217
|
+
const status = err?.status;
|
|
218
|
+
if (typeof status === "number" && !TRANSIENT_HTTP.has(status)) {
|
|
219
|
+
// Deterministic API error — wrap nothing, rethrow as-is.
|
|
220
|
+
throw err;
|
|
221
|
+
}
|
|
222
|
+
if (typeof status === "number" && TRANSIENT_HTTP.has(status)) {
|
|
223
|
+
throw new llmRetry_1.TransientLlmError(`OpenAI ${status} error`, err);
|
|
224
|
+
}
|
|
225
|
+
throw err;
|
|
226
|
+
}
|
|
227
|
+
}, { maxRetries: this.maxRetries });
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
exports.OpenAiLlmCaller = OpenAiLlmCaller;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llmCallerRegistry.d.ts","sourceRoot":"","sources":["../../../src/services/agent/llmCallerRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAyB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"llmCallerRegistry.d.ts","sourceRoot":"","sources":["../../../src/services/agent/llmCallerRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAyB,MAAM,aAAa,CAAC;AAa/D,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAEpD;AAED,wBAAgB,YAAY,IAAI,SAAS,CAExC;AAcD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI,CAEjE;AAED,wBAAgB,kBAAkB,IAAI,SAAS,GAAG,IAAI,CAErD"}
|