@mindstudio-ai/agent 0.1.44 → 0.1.46

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/index.js CHANGED
@@ -1693,491 +1693,6 @@ function resolveTable(databases, tableName, databaseHint) {
1693
1693
  );
1694
1694
  }
1695
1695
 
1696
- // src/generated/steps.ts
1697
- function applyStepMethods(AgentClass) {
1698
- const proto = AgentClass.prototype;
1699
- proto.activeCampaignAddNote = function(step, options) {
1700
- return this.executeStep("activeCampaignAddNote", step, options);
1701
- };
1702
- proto.activeCampaignCreateContact = function(step, options) {
1703
- return this.executeStep("activeCampaignCreateContact", step, options);
1704
- };
1705
- proto.addSubtitlesToVideo = function(step, options) {
1706
- return this.executeStep("addSubtitlesToVideo", step, options);
1707
- };
1708
- proto.airtableCreateUpdateRecord = function(step, options) {
1709
- return this.executeStep("airtableCreateUpdateRecord", step, options);
1710
- };
1711
- proto.airtableDeleteRecord = function(step, options) {
1712
- return this.executeStep("airtableDeleteRecord", step, options);
1713
- };
1714
- proto.airtableGetRecord = function(step, options) {
1715
- return this.executeStep("airtableGetRecord", step, options);
1716
- };
1717
- proto.airtableGetTableRecords = function(step, options) {
1718
- return this.executeStep("airtableGetTableRecords", step, options);
1719
- };
1720
- proto.analyzeImage = function(step, options) {
1721
- return this.executeStep("analyzeImage", step, options);
1722
- };
1723
- proto.analyzeVideo = function(step, options) {
1724
- return this.executeStep("analyzeVideo", step, options);
1725
- };
1726
- proto.captureThumbnail = function(step, options) {
1727
- return this.executeStep("captureThumbnail", step, options);
1728
- };
1729
- proto.checkAppRole = function(step, options) {
1730
- return this.executeStep("checkAppRole", step, options);
1731
- };
1732
- proto.codaCreateUpdatePage = function(step, options) {
1733
- return this.executeStep("codaCreateUpdatePage", step, options);
1734
- };
1735
- proto.codaCreateUpdateRow = function(step, options) {
1736
- return this.executeStep("codaCreateUpdateRow", step, options);
1737
- };
1738
- proto.codaFindRow = function(step, options) {
1739
- return this.executeStep("codaFindRow", step, options);
1740
- };
1741
- proto.codaGetPage = function(step, options) {
1742
- return this.executeStep("codaGetPage", step, options);
1743
- };
1744
- proto.codaGetTableRows = function(step, options) {
1745
- return this.executeStep("codaGetTableRows", step, options);
1746
- };
1747
- proto.convertPdfToImages = function(step, options) {
1748
- return this.executeStep("convertPdfToImages", step, options);
1749
- };
1750
- proto.createDataSource = function(step, options) {
1751
- return this.executeStep("createDataSource", step, options);
1752
- };
1753
- proto.createGmailDraft = function(step, options) {
1754
- return this.executeStep("createGmailDraft", step, options);
1755
- };
1756
- proto.createGoogleCalendarEvent = function(step, options) {
1757
- return this.executeStep("createGoogleCalendarEvent", step, options);
1758
- };
1759
- proto.createGoogleDoc = function(step, options) {
1760
- return this.executeStep("createGoogleDoc", step, options);
1761
- };
1762
- proto.createGoogleSheet = function(step, options) {
1763
- return this.executeStep("createGoogleSheet", step, options);
1764
- };
1765
- proto.deleteDataSource = function(step, options) {
1766
- return this.executeStep("deleteDataSource", step, options);
1767
- };
1768
- proto.deleteDataSourceDocument = function(step, options) {
1769
- return this.executeStep("deleteDataSourceDocument", step, options);
1770
- };
1771
- proto.deleteGmailEmail = function(step, options) {
1772
- return this.executeStep("deleteGmailEmail", step, options);
1773
- };
1774
- proto.deleteGoogleCalendarEvent = function(step, options) {
1775
- return this.executeStep("deleteGoogleCalendarEvent", step, options);
1776
- };
1777
- proto.deleteGoogleSheetRows = function(step, options) {
1778
- return this.executeStep("deleteGoogleSheetRows", step, options);
1779
- };
1780
- proto.detectChanges = function(step, options) {
1781
- return this.executeStep("detectChanges", step, options);
1782
- };
1783
- proto.detectPII = function(step, options) {
1784
- return this.executeStep("detectPII", step, options);
1785
- };
1786
- proto.discordEditMessage = function(step, options) {
1787
- return this.executeStep("discordEditMessage", step, options);
1788
- };
1789
- proto.discordSendFollowUp = function(step, options) {
1790
- return this.executeStep("discordSendFollowUp", step, options);
1791
- };
1792
- proto.discordSendMessage = function(step, options) {
1793
- return this.executeStep("discordSendMessage", step, options);
1794
- };
1795
- proto.downloadVideo = function(step, options) {
1796
- return this.executeStep("downloadVideo", step, options);
1797
- };
1798
- proto.enhanceImageGenerationPrompt = function(step, options) {
1799
- return this.executeStep("enhanceImageGenerationPrompt", step, options);
1800
- };
1801
- proto.enhanceVideoGenerationPrompt = function(step, options) {
1802
- return this.executeStep("enhanceVideoGenerationPrompt", step, options);
1803
- };
1804
- proto.enrichPerson = function(step, options) {
1805
- return this.executeStep("enrichPerson", step, options);
1806
- };
1807
- proto.extractAudioFromVideo = function(step, options) {
1808
- return this.executeStep("extractAudioFromVideo", step, options);
1809
- };
1810
- proto.extractText = function(step, options) {
1811
- return this.executeStep("extractText", step, options);
1812
- };
1813
- proto.fetchDataSourceDocument = function(step, options) {
1814
- return this.executeStep("fetchDataSourceDocument", step, options);
1815
- };
1816
- proto.fetchGoogleDoc = function(step, options) {
1817
- return this.executeStep("fetchGoogleDoc", step, options);
1818
- };
1819
- proto.fetchGoogleSheet = function(step, options) {
1820
- return this.executeStep("fetchGoogleSheet", step, options);
1821
- };
1822
- proto.fetchSlackChannelHistory = function(step, options) {
1823
- return this.executeStep("fetchSlackChannelHistory", step, options);
1824
- };
1825
- proto.fetchYoutubeCaptions = function(step, options) {
1826
- return this.executeStep("fetchYoutubeCaptions", step, options);
1827
- };
1828
- proto.fetchYoutubeChannel = function(step, options) {
1829
- return this.executeStep("fetchYoutubeChannel", step, options);
1830
- };
1831
- proto.fetchYoutubeComments = function(step, options) {
1832
- return this.executeStep("fetchYoutubeComments", step, options);
1833
- };
1834
- proto.fetchYoutubeVideo = function(step, options) {
1835
- return this.executeStep("fetchYoutubeVideo", step, options);
1836
- };
1837
- proto.generateChart = function(step, options) {
1838
- return this.executeStep("generateChart", step, options);
1839
- };
1840
- proto.generateImage = function(step, options) {
1841
- return this.executeStep("generateImage", step, options);
1842
- };
1843
- proto.generateLipsync = function(step, options) {
1844
- return this.executeStep("generateLipsync", step, options);
1845
- };
1846
- proto.generateMusic = function(step, options) {
1847
- return this.executeStep("generateMusic", step, options);
1848
- };
1849
- proto.generateAsset = function(step, options) {
1850
- return this.executeStep("generatePdf", step, options);
1851
- };
1852
- proto.generateStaticVideoFromImage = function(step, options) {
1853
- return this.executeStep("generateStaticVideoFromImage", step, options);
1854
- };
1855
- proto.generateVideo = function(step, options) {
1856
- return this.executeStep("generateVideo", step, options);
1857
- };
1858
- proto.getGmailAttachments = function(step, options) {
1859
- return this.executeStep("getGmailAttachments", step, options);
1860
- };
1861
- proto.getGmailDraft = function(step, options) {
1862
- return this.executeStep("getGmailDraft", step, options);
1863
- };
1864
- proto.getGmailEmail = function(step, options) {
1865
- return this.executeStep("getGmailEmail", step, options);
1866
- };
1867
- proto.getGmailUnreadCount = function(step, options) {
1868
- return this.executeStep("getGmailUnreadCount", step, options);
1869
- };
1870
- proto.getGoogleCalendarEvent = function(step, options) {
1871
- return this.executeStep("getGoogleCalendarEvent", step, options);
1872
- };
1873
- proto.getGoogleDriveFile = function(step, options) {
1874
- return this.executeStep("getGoogleDriveFile", step, options);
1875
- };
1876
- proto.getGoogleSheetInfo = function(step, options) {
1877
- return this.executeStep("getGoogleSheetInfo", step, options);
1878
- };
1879
- proto.getMediaMetadata = function(step, options) {
1880
- return this.executeStep("getMediaMetadata", step, options);
1881
- };
1882
- proto.httpRequest = function(step, options) {
1883
- return this.executeStep("httpRequest", step, options);
1884
- };
1885
- proto.hubspotCreateCompany = function(step, options) {
1886
- return this.executeStep("hubspotCreateCompany", step, options);
1887
- };
1888
- proto.hubspotCreateContact = function(step, options) {
1889
- return this.executeStep("hubspotCreateContact", step, options);
1890
- };
1891
- proto.hubspotGetCompany = function(step, options) {
1892
- return this.executeStep("hubspotGetCompany", step, options);
1893
- };
1894
- proto.hubspotGetContact = function(step, options) {
1895
- return this.executeStep("hubspotGetContact", step, options);
1896
- };
1897
- proto.hunterApiCompanyEnrichment = function(step, options) {
1898
- return this.executeStep("hunterApiCompanyEnrichment", step, options);
1899
- };
1900
- proto.hunterApiDomainSearch = function(step, options) {
1901
- return this.executeStep("hunterApiDomainSearch", step, options);
1902
- };
1903
- proto.hunterApiEmailFinder = function(step, options) {
1904
- return this.executeStep("hunterApiEmailFinder", step, options);
1905
- };
1906
- proto.hunterApiEmailVerification = function(step, options) {
1907
- return this.executeStep("hunterApiEmailVerification", step, options);
1908
- };
1909
- proto.hunterApiPersonEnrichment = function(step, options) {
1910
- return this.executeStep("hunterApiPersonEnrichment", step, options);
1911
- };
1912
- proto.imageFaceSwap = function(step, options) {
1913
- return this.executeStep("imageFaceSwap", step, options);
1914
- };
1915
- proto.imageRemoveWatermark = function(step, options) {
1916
- return this.executeStep("imageRemoveWatermark", step, options);
1917
- };
1918
- proto.insertVideoClips = function(step, options) {
1919
- return this.executeStep("insertVideoClips", step, options);
1920
- };
1921
- proto.listDataSources = function(step, options) {
1922
- return this.executeStep("listDataSources", step, options);
1923
- };
1924
- proto.listGmailDrafts = function(step, options) {
1925
- return this.executeStep("listGmailDrafts", step, options);
1926
- };
1927
- proto.listGmailLabels = function(step, options) {
1928
- return this.executeStep("listGmailLabels", step, options);
1929
- };
1930
- proto.listGoogleCalendarEvents = function(step, options) {
1931
- return this.executeStep("listGoogleCalendarEvents", step, options);
1932
- };
1933
- proto.listGoogleDriveFiles = function(step, options) {
1934
- return this.executeStep("listGoogleDriveFiles", step, options);
1935
- };
1936
- proto.listRecentGmailEmails = function(step, options) {
1937
- return this.executeStep("listRecentGmailEmails", step, options);
1938
- };
1939
- proto.logic = function(step, options) {
1940
- return this.executeStep("logic", step, options);
1941
- };
1942
- proto.makeDotComRunScenario = function(step, options) {
1943
- return this.executeStep("makeDotComRunScenario", step, options);
1944
- };
1945
- proto.mergeAudio = function(step, options) {
1946
- return this.executeStep("mergeAudio", step, options);
1947
- };
1948
- proto.mergeVideos = function(step, options) {
1949
- return this.executeStep("mergeVideos", step, options);
1950
- };
1951
- proto.mixAudioIntoVideo = function(step, options) {
1952
- return this.executeStep("mixAudioIntoVideo", step, options);
1953
- };
1954
- proto.muteVideo = function(step, options) {
1955
- return this.executeStep("muteVideo", step, options);
1956
- };
1957
- proto.n8nRunNode = function(step, options) {
1958
- return this.executeStep("n8nRunNode", step, options);
1959
- };
1960
- proto.notionCreatePage = function(step, options) {
1961
- return this.executeStep("notionCreatePage", step, options);
1962
- };
1963
- proto.notionUpdatePage = function(step, options) {
1964
- return this.executeStep("notionUpdatePage", step, options);
1965
- };
1966
- proto.peopleSearch = function(step, options) {
1967
- return this.executeStep("peopleSearch", step, options);
1968
- };
1969
- proto.postToLinkedIn = function(step, options) {
1970
- return this.executeStep("postToLinkedIn", step, options);
1971
- };
1972
- proto.postToSlackChannel = function(step, options) {
1973
- return this.executeStep("postToSlackChannel", step, options);
1974
- };
1975
- proto.postToX = function(step, options) {
1976
- return this.executeStep("postToX", step, options);
1977
- };
1978
- proto.postToZapier = function(step, options) {
1979
- return this.executeStep("postToZapier", step, options);
1980
- };
1981
- proto.queryAppDatabase = function(step, options) {
1982
- return this.executeStep("queryAppDatabase", step, options);
1983
- };
1984
- proto.queryDataSource = function(step, options) {
1985
- return this.executeStep("queryDataSource", step, options);
1986
- };
1987
- proto.queryExternalDatabase = function(step, options) {
1988
- return this.executeStep("queryExternalDatabase", step, options);
1989
- };
1990
- proto.redactPII = function(step, options) {
1991
- return this.executeStep("redactPII", step, options);
1992
- };
1993
- proto.removeBackgroundFromImage = function(step, options) {
1994
- return this.executeStep("removeBackgroundFromImage", step, options);
1995
- };
1996
- proto.replyToGmailEmail = function(step, options) {
1997
- return this.executeStep("replyToGmailEmail", step, options);
1998
- };
1999
- proto.resizeVideo = function(step, options) {
2000
- return this.executeStep("resizeVideo", step, options);
2001
- };
2002
- proto.runFromConnectorRegistry = function(step, options) {
2003
- return this.executeStep("runFromConnectorRegistry", step, options);
2004
- };
2005
- proto.runPackagedWorkflow = function(step, options) {
2006
- return this.executeStep("runPackagedWorkflow", step, options);
2007
- };
2008
- proto.scrapeFacebookPage = function(step, options) {
2009
- return this.executeStep("scrapeFacebookPage", step, options);
2010
- };
2011
- proto.scrapeFacebookPosts = function(step, options) {
2012
- return this.executeStep("scrapeFacebookPosts", step, options);
2013
- };
2014
- proto.scrapeInstagramComments = function(step, options) {
2015
- return this.executeStep("scrapeInstagramComments", step, options);
2016
- };
2017
- proto.scrapeInstagramMentions = function(step, options) {
2018
- return this.executeStep("scrapeInstagramMentions", step, options);
2019
- };
2020
- proto.scrapeInstagramPosts = function(step, options) {
2021
- return this.executeStep("scrapeInstagramPosts", step, options);
2022
- };
2023
- proto.scrapeInstagramProfile = function(step, options) {
2024
- return this.executeStep("scrapeInstagramProfile", step, options);
2025
- };
2026
- proto.scrapeInstagramReels = function(step, options) {
2027
- return this.executeStep("scrapeInstagramReels", step, options);
2028
- };
2029
- proto.scrapeLinkedInCompany = function(step, options) {
2030
- return this.executeStep("scrapeLinkedInCompany", step, options);
2031
- };
2032
- proto.scrapeLinkedInProfile = function(step, options) {
2033
- return this.executeStep("scrapeLinkedInProfile", step, options);
2034
- };
2035
- proto.scrapeMetaThreadsProfile = function(step, options) {
2036
- return this.executeStep("scrapeMetaThreadsProfile", step, options);
2037
- };
2038
- proto.scrapeUrl = function(step, options) {
2039
- return this.executeStep("scrapeUrl", step, options);
2040
- };
2041
- proto.scrapeXPost = function(step, options) {
2042
- return this.executeStep("scrapeXPost", step, options);
2043
- };
2044
- proto.scrapeXProfile = function(step, options) {
2045
- return this.executeStep("scrapeXProfile", step, options);
2046
- };
2047
- proto.screenshotUrl = function(step, options) {
2048
- return this.executeStep("screenshotUrl", step, options);
2049
- };
2050
- proto.searchGmailEmails = function(step, options) {
2051
- return this.executeStep("searchGmailEmails", step, options);
2052
- };
2053
- proto.searchGoogle = function(step, options) {
2054
- return this.executeStep("searchGoogle", step, options);
2055
- };
2056
- proto.searchGoogleCalendarEvents = function(step, options) {
2057
- return this.executeStep("searchGoogleCalendarEvents", step, options);
2058
- };
2059
- proto.searchGoogleDrive = function(step, options) {
2060
- return this.executeStep("searchGoogleDrive", step, options);
2061
- };
2062
- proto.searchGoogleImages = function(step, options) {
2063
- return this.executeStep("searchGoogleImages", step, options);
2064
- };
2065
- proto.searchGoogleNews = function(step, options) {
2066
- return this.executeStep("searchGoogleNews", step, options);
2067
- };
2068
- proto.searchGoogleTrends = function(step, options) {
2069
- return this.executeStep("searchGoogleTrends", step, options);
2070
- };
2071
- proto.searchPerplexity = function(step, options) {
2072
- return this.executeStep("searchPerplexity", step, options);
2073
- };
2074
- proto.searchXPosts = function(step, options) {
2075
- return this.executeStep("searchXPosts", step, options);
2076
- };
2077
- proto.searchYoutube = function(step, options) {
2078
- return this.executeStep("searchYoutube", step, options);
2079
- };
2080
- proto.searchYoutubeTrends = function(step, options) {
2081
- return this.executeStep("searchYoutubeTrends", step, options);
2082
- };
2083
- proto.sendEmail = function(step, options) {
2084
- return this.executeStep("sendEmail", step, options);
2085
- };
2086
- proto.sendGmailDraft = function(step, options) {
2087
- return this.executeStep("sendGmailDraft", step, options);
2088
- };
2089
- proto.sendGmailMessage = function(step, options) {
2090
- return this.executeStep("sendGmailMessage", step, options);
2091
- };
2092
- proto.sendSlackDirectMessage = function(step, options) {
2093
- return this.executeStep("sendSlackDirectMessage", step, options);
2094
- };
2095
- proto.sendSMS = function(step, options) {
2096
- return this.executeStep("sendSMS", step, options);
2097
- };
2098
- proto.setGmailReadStatus = function(step, options) {
2099
- return this.executeStep("setGmailReadStatus", step, options);
2100
- };
2101
- proto.setRunTitle = function(step, options) {
2102
- return this.executeStep("setRunTitle", step, options);
2103
- };
2104
- proto.setVariable = function(step, options) {
2105
- return this.executeStep("setVariable", step, options);
2106
- };
2107
- proto.telegramEditMessage = function(step, options) {
2108
- return this.executeStep("telegramEditMessage", step, options);
2109
- };
2110
- proto.telegramReplyToMessage = function(step, options) {
2111
- return this.executeStep("telegramReplyToMessage", step, options);
2112
- };
2113
- proto.telegramSendAudio = function(step, options) {
2114
- return this.executeStep("telegramSendAudio", step, options);
2115
- };
2116
- proto.telegramSendFile = function(step, options) {
2117
- return this.executeStep("telegramSendFile", step, options);
2118
- };
2119
- proto.telegramSendImage = function(step, options) {
2120
- return this.executeStep("telegramSendImage", step, options);
2121
- };
2122
- proto.telegramSendMessage = function(step, options) {
2123
- return this.executeStep("telegramSendMessage", step, options);
2124
- };
2125
- proto.telegramSendVideo = function(step, options) {
2126
- return this.executeStep("telegramSendVideo", step, options);
2127
- };
2128
- proto.telegramSetTyping = function(step, options) {
2129
- return this.executeStep("telegramSetTyping", step, options);
2130
- };
2131
- proto.textToSpeech = function(step, options) {
2132
- return this.executeStep("textToSpeech", step, options);
2133
- };
2134
- proto.transcribeAudio = function(step, options) {
2135
- return this.executeStep("transcribeAudio", step, options);
2136
- };
2137
- proto.trimMedia = function(step, options) {
2138
- return this.executeStep("trimMedia", step, options);
2139
- };
2140
- proto.updateGmailLabels = function(step, options) {
2141
- return this.executeStep("updateGmailLabels", step, options);
2142
- };
2143
- proto.updateGoogleCalendarEvent = function(step, options) {
2144
- return this.executeStep("updateGoogleCalendarEvent", step, options);
2145
- };
2146
- proto.updateGoogleDoc = function(step, options) {
2147
- return this.executeStep("updateGoogleDoc", step, options);
2148
- };
2149
- proto.updateGoogleSheet = function(step, options) {
2150
- return this.executeStep("updateGoogleSheet", step, options);
2151
- };
2152
- proto.uploadDataSourceDocument = function(step, options) {
2153
- return this.executeStep("uploadDataSourceDocument", step, options);
2154
- };
2155
- proto.upscaleImage = function(step, options) {
2156
- return this.executeStep("upscaleImage", step, options);
2157
- };
2158
- proto.upscaleVideo = function(step, options) {
2159
- return this.executeStep("upscaleVideo", step, options);
2160
- };
2161
- proto.generateText = function(step, options) {
2162
- return this.executeStep("userMessage", step, options);
2163
- };
2164
- proto.videoFaceSwap = function(step, options) {
2165
- return this.executeStep("videoFaceSwap", step, options);
2166
- };
2167
- proto.videoRemoveBackground = function(step, options) {
2168
- return this.executeStep("videoRemoveBackground", step, options);
2169
- };
2170
- proto.videoRemoveWatermark = function(step, options) {
2171
- return this.executeStep("videoRemoveWatermark", step, options);
2172
- };
2173
- proto.watermarkImage = function(step, options) {
2174
- return this.executeStep("watermarkImage", step, options);
2175
- };
2176
- proto.watermarkVideo = function(step, options) {
2177
- return this.executeStep("watermarkVideo", step, options);
2178
- };
2179
- }
2180
-
2181
1696
  // src/generated/metadata.ts
2182
1697
  var stepMetadata = {
2183
1698
  "activeCampaignAddNote": {
@@ -3351,6 +2866,672 @@ var stepMetadata = {
3351
2866
  }
3352
2867
  };
3353
2868
 
2869
+ // src/task/index.ts
2870
+ function resolveStepType(name) {
2871
+ const meta = stepMetadata[name];
2872
+ return meta ? meta.stepType : name;
2873
+ }
2874
+ function mapTools(tools) {
2875
+ return tools.map((t) => {
2876
+ const method = typeof t === "string" ? t : t.method;
2877
+ const stepType = resolveStepType(method);
2878
+ const defaults = typeof t === "object" ? t.defaults : void 0;
2879
+ return defaults ? { stepType, defaults } : { stepType };
2880
+ });
2881
+ }
2882
+ function buildTaskRequestBody(options) {
2883
+ return {
2884
+ prompt: options.prompt,
2885
+ input: options.input,
2886
+ tools: mapTools(options.tools),
2887
+ structuredOutputExample: options.structuredOutputExample,
2888
+ model: options.model,
2889
+ ...options.maxTurns != null && { maxTurns: options.maxTurns },
2890
+ ...options.appId != null && { appId: options.appId },
2891
+ ...options.threadId != null && { threadId: options.threadId }
2892
+ };
2893
+ }
2894
+ function sleep2(ms) {
2895
+ return new Promise((resolve) => setTimeout(resolve, ms));
2896
+ }
2897
+ async function runTaskPoll(httpConfig, body) {
2898
+ const { data } = await request(
2899
+ httpConfig,
2900
+ "POST",
2901
+ "/task",
2902
+ body
2903
+ );
2904
+ const pollUrl = `${httpConfig.baseUrl}/developer/v2/task/poll/${data.taskToken}`;
2905
+ let pollDelay = 300;
2906
+ while (true) {
2907
+ await sleep2(pollDelay);
2908
+ pollDelay = Math.min(pollDelay * 1.5, 3e3);
2909
+ const res = await fetch(pollUrl, {
2910
+ headers: { "User-Agent": "@mindstudio-ai/agent" }
2911
+ });
2912
+ if (res.status === 404) {
2913
+ throw new MindStudioError(
2914
+ "Task poll token not found or expired.",
2915
+ "poll_token_expired",
2916
+ 404
2917
+ );
2918
+ }
2919
+ if (!res.ok) {
2920
+ const errorBody = await res.json().catch(() => ({}));
2921
+ throw new MindStudioError(
2922
+ errorBody.message ?? errorBody.error ?? `Task poll failed: ${res.status} ${res.statusText}`,
2923
+ errorBody.code ?? "poll_error",
2924
+ res.status,
2925
+ errorBody
2926
+ );
2927
+ }
2928
+ const poll = await res.json();
2929
+ if (poll.status === "pending") continue;
2930
+ if (poll.status === "error") {
2931
+ throw new MindStudioError(
2932
+ poll.error ?? "Task execution failed.",
2933
+ "task_execution_error",
2934
+ 500
2935
+ );
2936
+ }
2937
+ return {
2938
+ output: poll.output,
2939
+ turns: poll.turns ?? 0,
2940
+ usage: poll.usage ?? { inputTokens: 0, outputTokens: 0, totalBillingCost: 0 }
2941
+ };
2942
+ }
2943
+ }
2944
+ async function runTaskStream(httpConfig, body, onEvent) {
2945
+ const url = `${httpConfig.baseUrl}/developer/v2/task`;
2946
+ const res = await fetch(url, {
2947
+ method: "POST",
2948
+ headers: {
2949
+ Authorization: `Bearer ${httpConfig.token}`,
2950
+ "Content-Type": "application/json",
2951
+ "User-Agent": "@mindstudio-ai/agent",
2952
+ Accept: "text/event-stream"
2953
+ },
2954
+ body: JSON.stringify(body)
2955
+ });
2956
+ if (!res.ok) {
2957
+ let message = `${res.status} ${res.statusText}`;
2958
+ let code = "api_error";
2959
+ let details;
2960
+ try {
2961
+ const text = await res.text();
2962
+ try {
2963
+ const errBody = JSON.parse(text);
2964
+ details = errBody;
2965
+ const errMsg = (typeof errBody.error === "string" ? errBody.error : void 0) ?? (typeof errBody.message === "string" ? errBody.message : void 0);
2966
+ if (errMsg) message = errMsg;
2967
+ if (errBody.code) code = errBody.code;
2968
+ } catch {
2969
+ const stripped = text.replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
2970
+ if (stripped) message = stripped.slice(0, 200);
2971
+ }
2972
+ } catch {
2973
+ }
2974
+ throw new MindStudioError(`[task] ${message}`, code, res.status, details);
2975
+ }
2976
+ const reader = res.body.getReader();
2977
+ const decoder = new TextDecoder();
2978
+ let buffer = "";
2979
+ let result = null;
2980
+ while (true) {
2981
+ const { done, value } = await reader.read();
2982
+ if (done) break;
2983
+ buffer += decoder.decode(value, { stream: true });
2984
+ const lines = buffer.split("\n");
2985
+ buffer = lines.pop() ?? "";
2986
+ for (const line of lines) {
2987
+ if (!line.startsWith("data: ")) continue;
2988
+ try {
2989
+ const event = JSON.parse(line.slice(6));
2990
+ onEvent(event);
2991
+ if (event.type === "error") {
2992
+ throw new MindStudioError(
2993
+ event.error ?? "Task execution failed.",
2994
+ "task_execution_error",
2995
+ 500
2996
+ );
2997
+ }
2998
+ if (event.type === "done") {
2999
+ result = {
3000
+ output: event.output,
3001
+ turns: event.turns ?? 0,
3002
+ usage: event.usage ?? {
3003
+ inputTokens: 0,
3004
+ outputTokens: 0,
3005
+ totalBillingCost: 0
3006
+ }
3007
+ };
3008
+ }
3009
+ } catch (err) {
3010
+ if (err instanceof MindStudioError) throw err;
3011
+ }
3012
+ }
3013
+ }
3014
+ if (buffer.startsWith("data: ")) {
3015
+ try {
3016
+ const event = JSON.parse(buffer.slice(6));
3017
+ onEvent(event);
3018
+ if (event.type === "error") {
3019
+ throw new MindStudioError(
3020
+ event.error ?? "Task execution failed.",
3021
+ "task_execution_error",
3022
+ 500
3023
+ );
3024
+ }
3025
+ if (event.type === "done") {
3026
+ result = {
3027
+ output: event.output,
3028
+ turns: event.turns ?? 0,
3029
+ usage: event.usage ?? {
3030
+ inputTokens: 0,
3031
+ outputTokens: 0,
3032
+ totalBillingCost: 0
3033
+ }
3034
+ };
3035
+ }
3036
+ } catch (err) {
3037
+ if (err instanceof MindStudioError) throw err;
3038
+ }
3039
+ }
3040
+ if (!result) {
3041
+ throw new MindStudioError(
3042
+ "[task] Stream ended without a done event. The task execution may have been interrupted.",
3043
+ "stream_error",
3044
+ 500
3045
+ );
3046
+ }
3047
+ return result;
3048
+ }
3049
+
3050
+ // src/generated/steps.ts
3051
+ function applyStepMethods(AgentClass) {
3052
+ const proto = AgentClass.prototype;
3053
+ proto.activeCampaignAddNote = function(step, options) {
3054
+ return this.executeStep("activeCampaignAddNote", step, options);
3055
+ };
3056
+ proto.activeCampaignCreateContact = function(step, options) {
3057
+ return this.executeStep("activeCampaignCreateContact", step, options);
3058
+ };
3059
+ proto.addSubtitlesToVideo = function(step, options) {
3060
+ return this.executeStep("addSubtitlesToVideo", step, options);
3061
+ };
3062
+ proto.airtableCreateUpdateRecord = function(step, options) {
3063
+ return this.executeStep("airtableCreateUpdateRecord", step, options);
3064
+ };
3065
+ proto.airtableDeleteRecord = function(step, options) {
3066
+ return this.executeStep("airtableDeleteRecord", step, options);
3067
+ };
3068
+ proto.airtableGetRecord = function(step, options) {
3069
+ return this.executeStep("airtableGetRecord", step, options);
3070
+ };
3071
+ proto.airtableGetTableRecords = function(step, options) {
3072
+ return this.executeStep("airtableGetTableRecords", step, options);
3073
+ };
3074
+ proto.analyzeImage = function(step, options) {
3075
+ return this.executeStep("analyzeImage", step, options);
3076
+ };
3077
+ proto.analyzeVideo = function(step, options) {
3078
+ return this.executeStep("analyzeVideo", step, options);
3079
+ };
3080
+ proto.captureThumbnail = function(step, options) {
3081
+ return this.executeStep("captureThumbnail", step, options);
3082
+ };
3083
+ proto.checkAppRole = function(step, options) {
3084
+ return this.executeStep("checkAppRole", step, options);
3085
+ };
3086
+ proto.codaCreateUpdatePage = function(step, options) {
3087
+ return this.executeStep("codaCreateUpdatePage", step, options);
3088
+ };
3089
+ proto.codaCreateUpdateRow = function(step, options) {
3090
+ return this.executeStep("codaCreateUpdateRow", step, options);
3091
+ };
3092
+ proto.codaFindRow = function(step, options) {
3093
+ return this.executeStep("codaFindRow", step, options);
3094
+ };
3095
+ proto.codaGetPage = function(step, options) {
3096
+ return this.executeStep("codaGetPage", step, options);
3097
+ };
3098
+ proto.codaGetTableRows = function(step, options) {
3099
+ return this.executeStep("codaGetTableRows", step, options);
3100
+ };
3101
+ proto.convertPdfToImages = function(step, options) {
3102
+ return this.executeStep("convertPdfToImages", step, options);
3103
+ };
3104
+ proto.createDataSource = function(step, options) {
3105
+ return this.executeStep("createDataSource", step, options);
3106
+ };
3107
+ proto.createGmailDraft = function(step, options) {
3108
+ return this.executeStep("createGmailDraft", step, options);
3109
+ };
3110
+ proto.createGoogleCalendarEvent = function(step, options) {
3111
+ return this.executeStep("createGoogleCalendarEvent", step, options);
3112
+ };
3113
+ proto.createGoogleDoc = function(step, options) {
3114
+ return this.executeStep("createGoogleDoc", step, options);
3115
+ };
3116
+ proto.createGoogleSheet = function(step, options) {
3117
+ return this.executeStep("createGoogleSheet", step, options);
3118
+ };
3119
+ proto.deleteDataSource = function(step, options) {
3120
+ return this.executeStep("deleteDataSource", step, options);
3121
+ };
3122
+ proto.deleteDataSourceDocument = function(step, options) {
3123
+ return this.executeStep("deleteDataSourceDocument", step, options);
3124
+ };
3125
+ proto.deleteGmailEmail = function(step, options) {
3126
+ return this.executeStep("deleteGmailEmail", step, options);
3127
+ };
3128
+ proto.deleteGoogleCalendarEvent = function(step, options) {
3129
+ return this.executeStep("deleteGoogleCalendarEvent", step, options);
3130
+ };
3131
+ proto.deleteGoogleSheetRows = function(step, options) {
3132
+ return this.executeStep("deleteGoogleSheetRows", step, options);
3133
+ };
3134
+ proto.detectChanges = function(step, options) {
3135
+ return this.executeStep("detectChanges", step, options);
3136
+ };
3137
+ proto.detectPII = function(step, options) {
3138
+ return this.executeStep("detectPII", step, options);
3139
+ };
3140
+ proto.discordEditMessage = function(step, options) {
3141
+ return this.executeStep("discordEditMessage", step, options);
3142
+ };
3143
+ proto.discordSendFollowUp = function(step, options) {
3144
+ return this.executeStep("discordSendFollowUp", step, options);
3145
+ };
3146
+ proto.discordSendMessage = function(step, options) {
3147
+ return this.executeStep("discordSendMessage", step, options);
3148
+ };
3149
+ proto.downloadVideo = function(step, options) {
3150
+ return this.executeStep("downloadVideo", step, options);
3151
+ };
3152
+ proto.enhanceImageGenerationPrompt = function(step, options) {
3153
+ return this.executeStep("enhanceImageGenerationPrompt", step, options);
3154
+ };
3155
+ proto.enhanceVideoGenerationPrompt = function(step, options) {
3156
+ return this.executeStep("enhanceVideoGenerationPrompt", step, options);
3157
+ };
3158
+ proto.enrichPerson = function(step, options) {
3159
+ return this.executeStep("enrichPerson", step, options);
3160
+ };
3161
+ proto.extractAudioFromVideo = function(step, options) {
3162
+ return this.executeStep("extractAudioFromVideo", step, options);
3163
+ };
3164
+ proto.extractText = function(step, options) {
3165
+ return this.executeStep("extractText", step, options);
3166
+ };
3167
+ proto.fetchDataSourceDocument = function(step, options) {
3168
+ return this.executeStep("fetchDataSourceDocument", step, options);
3169
+ };
3170
+ proto.fetchGoogleDoc = function(step, options) {
3171
+ return this.executeStep("fetchGoogleDoc", step, options);
3172
+ };
3173
+ proto.fetchGoogleSheet = function(step, options) {
3174
+ return this.executeStep("fetchGoogleSheet", step, options);
3175
+ };
3176
+ proto.fetchSlackChannelHistory = function(step, options) {
3177
+ return this.executeStep("fetchSlackChannelHistory", step, options);
3178
+ };
3179
+ proto.fetchYoutubeCaptions = function(step, options) {
3180
+ return this.executeStep("fetchYoutubeCaptions", step, options);
3181
+ };
3182
+ proto.fetchYoutubeChannel = function(step, options) {
3183
+ return this.executeStep("fetchYoutubeChannel", step, options);
3184
+ };
3185
+ proto.fetchYoutubeComments = function(step, options) {
3186
+ return this.executeStep("fetchYoutubeComments", step, options);
3187
+ };
3188
+ proto.fetchYoutubeVideo = function(step, options) {
3189
+ return this.executeStep("fetchYoutubeVideo", step, options);
3190
+ };
3191
+ proto.generateChart = function(step, options) {
3192
+ return this.executeStep("generateChart", step, options);
3193
+ };
3194
+ proto.generateImage = function(step, options) {
3195
+ return this.executeStep("generateImage", step, options);
3196
+ };
3197
+ proto.generateLipsync = function(step, options) {
3198
+ return this.executeStep("generateLipsync", step, options);
3199
+ };
3200
+ proto.generateMusic = function(step, options) {
3201
+ return this.executeStep("generateMusic", step, options);
3202
+ };
3203
+ proto.generateAsset = function(step, options) {
3204
+ return this.executeStep("generatePdf", step, options);
3205
+ };
3206
+ proto.generateStaticVideoFromImage = function(step, options) {
3207
+ return this.executeStep("generateStaticVideoFromImage", step, options);
3208
+ };
3209
+ proto.generateVideo = function(step, options) {
3210
+ return this.executeStep("generateVideo", step, options);
3211
+ };
3212
+ proto.getGmailAttachments = function(step, options) {
3213
+ return this.executeStep("getGmailAttachments", step, options);
3214
+ };
3215
+ proto.getGmailDraft = function(step, options) {
3216
+ return this.executeStep("getGmailDraft", step, options);
3217
+ };
3218
+ proto.getGmailEmail = function(step, options) {
3219
+ return this.executeStep("getGmailEmail", step, options);
3220
+ };
3221
+ proto.getGmailUnreadCount = function(step, options) {
3222
+ return this.executeStep("getGmailUnreadCount", step, options);
3223
+ };
3224
+ proto.getGoogleCalendarEvent = function(step, options) {
3225
+ return this.executeStep("getGoogleCalendarEvent", step, options);
3226
+ };
3227
+ proto.getGoogleDriveFile = function(step, options) {
3228
+ return this.executeStep("getGoogleDriveFile", step, options);
3229
+ };
3230
+ proto.getGoogleSheetInfo = function(step, options) {
3231
+ return this.executeStep("getGoogleSheetInfo", step, options);
3232
+ };
3233
+ proto.getMediaMetadata = function(step, options) {
3234
+ return this.executeStep("getMediaMetadata", step, options);
3235
+ };
3236
+ proto.httpRequest = function(step, options) {
3237
+ return this.executeStep("httpRequest", step, options);
3238
+ };
3239
+ proto.hubspotCreateCompany = function(step, options) {
3240
+ return this.executeStep("hubspotCreateCompany", step, options);
3241
+ };
3242
+ proto.hubspotCreateContact = function(step, options) {
3243
+ return this.executeStep("hubspotCreateContact", step, options);
3244
+ };
3245
+ proto.hubspotGetCompany = function(step, options) {
3246
+ return this.executeStep("hubspotGetCompany", step, options);
3247
+ };
3248
+ proto.hubspotGetContact = function(step, options) {
3249
+ return this.executeStep("hubspotGetContact", step, options);
3250
+ };
3251
+ proto.hunterApiCompanyEnrichment = function(step, options) {
3252
+ return this.executeStep("hunterApiCompanyEnrichment", step, options);
3253
+ };
3254
+ proto.hunterApiDomainSearch = function(step, options) {
3255
+ return this.executeStep("hunterApiDomainSearch", step, options);
3256
+ };
3257
+ proto.hunterApiEmailFinder = function(step, options) {
3258
+ return this.executeStep("hunterApiEmailFinder", step, options);
3259
+ };
3260
+ proto.hunterApiEmailVerification = function(step, options) {
3261
+ return this.executeStep("hunterApiEmailVerification", step, options);
3262
+ };
3263
+ proto.hunterApiPersonEnrichment = function(step, options) {
3264
+ return this.executeStep("hunterApiPersonEnrichment", step, options);
3265
+ };
3266
+ proto.imageFaceSwap = function(step, options) {
3267
+ return this.executeStep("imageFaceSwap", step, options);
3268
+ };
3269
+ proto.imageRemoveWatermark = function(step, options) {
3270
+ return this.executeStep("imageRemoveWatermark", step, options);
3271
+ };
3272
+ proto.insertVideoClips = function(step, options) {
3273
+ return this.executeStep("insertVideoClips", step, options);
3274
+ };
3275
+ proto.listDataSources = function(step, options) {
3276
+ return this.executeStep("listDataSources", step, options);
3277
+ };
3278
+ proto.listGmailDrafts = function(step, options) {
3279
+ return this.executeStep("listGmailDrafts", step, options);
3280
+ };
3281
+ proto.listGmailLabels = function(step, options) {
3282
+ return this.executeStep("listGmailLabels", step, options);
3283
+ };
3284
+ proto.listGoogleCalendarEvents = function(step, options) {
3285
+ return this.executeStep("listGoogleCalendarEvents", step, options);
3286
+ };
3287
+ proto.listGoogleDriveFiles = function(step, options) {
3288
+ return this.executeStep("listGoogleDriveFiles", step, options);
3289
+ };
3290
+ proto.listRecentGmailEmails = function(step, options) {
3291
+ return this.executeStep("listRecentGmailEmails", step, options);
3292
+ };
3293
+ proto.logic = function(step, options) {
3294
+ return this.executeStep("logic", step, options);
3295
+ };
3296
+ proto.makeDotComRunScenario = function(step, options) {
3297
+ return this.executeStep("makeDotComRunScenario", step, options);
3298
+ };
3299
+ proto.mergeAudio = function(step, options) {
3300
+ return this.executeStep("mergeAudio", step, options);
3301
+ };
3302
+ proto.mergeVideos = function(step, options) {
3303
+ return this.executeStep("mergeVideos", step, options);
3304
+ };
3305
+ proto.mixAudioIntoVideo = function(step, options) {
3306
+ return this.executeStep("mixAudioIntoVideo", step, options);
3307
+ };
3308
+ proto.muteVideo = function(step, options) {
3309
+ return this.executeStep("muteVideo", step, options);
3310
+ };
3311
+ proto.n8nRunNode = function(step, options) {
3312
+ return this.executeStep("n8nRunNode", step, options);
3313
+ };
3314
+ proto.notionCreatePage = function(step, options) {
3315
+ return this.executeStep("notionCreatePage", step, options);
3316
+ };
3317
+ proto.notionUpdatePage = function(step, options) {
3318
+ return this.executeStep("notionUpdatePage", step, options);
3319
+ };
3320
+ proto.peopleSearch = function(step, options) {
3321
+ return this.executeStep("peopleSearch", step, options);
3322
+ };
3323
+ proto.postToLinkedIn = function(step, options) {
3324
+ return this.executeStep("postToLinkedIn", step, options);
3325
+ };
3326
+ proto.postToSlackChannel = function(step, options) {
3327
+ return this.executeStep("postToSlackChannel", step, options);
3328
+ };
3329
+ proto.postToX = function(step, options) {
3330
+ return this.executeStep("postToX", step, options);
3331
+ };
3332
+ proto.postToZapier = function(step, options) {
3333
+ return this.executeStep("postToZapier", step, options);
3334
+ };
3335
+ proto.queryAppDatabase = function(step, options) {
3336
+ return this.executeStep("queryAppDatabase", step, options);
3337
+ };
3338
+ proto.queryDataSource = function(step, options) {
3339
+ return this.executeStep("queryDataSource", step, options);
3340
+ };
3341
+ proto.queryExternalDatabase = function(step, options) {
3342
+ return this.executeStep("queryExternalDatabase", step, options);
3343
+ };
3344
+ proto.redactPII = function(step, options) {
3345
+ return this.executeStep("redactPII", step, options);
3346
+ };
3347
+ proto.removeBackgroundFromImage = function(step, options) {
3348
+ return this.executeStep("removeBackgroundFromImage", step, options);
3349
+ };
3350
+ proto.replyToGmailEmail = function(step, options) {
3351
+ return this.executeStep("replyToGmailEmail", step, options);
3352
+ };
3353
+ proto.resizeVideo = function(step, options) {
3354
+ return this.executeStep("resizeVideo", step, options);
3355
+ };
3356
+ proto.runFromConnectorRegistry = function(step, options) {
3357
+ return this.executeStep("runFromConnectorRegistry", step, options);
3358
+ };
3359
+ proto.runPackagedWorkflow = function(step, options) {
3360
+ return this.executeStep("runPackagedWorkflow", step, options);
3361
+ };
3362
+ proto.scrapeFacebookPage = function(step, options) {
3363
+ return this.executeStep("scrapeFacebookPage", step, options);
3364
+ };
3365
+ proto.scrapeFacebookPosts = function(step, options) {
3366
+ return this.executeStep("scrapeFacebookPosts", step, options);
3367
+ };
3368
+ proto.scrapeInstagramComments = function(step, options) {
3369
+ return this.executeStep("scrapeInstagramComments", step, options);
3370
+ };
3371
+ proto.scrapeInstagramMentions = function(step, options) {
3372
+ return this.executeStep("scrapeInstagramMentions", step, options);
3373
+ };
3374
+ proto.scrapeInstagramPosts = function(step, options) {
3375
+ return this.executeStep("scrapeInstagramPosts", step, options);
3376
+ };
3377
+ proto.scrapeInstagramProfile = function(step, options) {
3378
+ return this.executeStep("scrapeInstagramProfile", step, options);
3379
+ };
3380
+ proto.scrapeInstagramReels = function(step, options) {
3381
+ return this.executeStep("scrapeInstagramReels", step, options);
3382
+ };
3383
+ proto.scrapeLinkedInCompany = function(step, options) {
3384
+ return this.executeStep("scrapeLinkedInCompany", step, options);
3385
+ };
3386
+ proto.scrapeLinkedInProfile = function(step, options) {
3387
+ return this.executeStep("scrapeLinkedInProfile", step, options);
3388
+ };
3389
+ proto.scrapeMetaThreadsProfile = function(step, options) {
3390
+ return this.executeStep("scrapeMetaThreadsProfile", step, options);
3391
+ };
3392
+ proto.scrapeUrl = function(step, options) {
3393
+ return this.executeStep("scrapeUrl", step, options);
3394
+ };
3395
+ proto.scrapeXPost = function(step, options) {
3396
+ return this.executeStep("scrapeXPost", step, options);
3397
+ };
3398
+ proto.scrapeXProfile = function(step, options) {
3399
+ return this.executeStep("scrapeXProfile", step, options);
3400
+ };
3401
+ proto.screenshotUrl = function(step, options) {
3402
+ return this.executeStep("screenshotUrl", step, options);
3403
+ };
3404
+ proto.searchGmailEmails = function(step, options) {
3405
+ return this.executeStep("searchGmailEmails", step, options);
3406
+ };
3407
+ proto.searchGoogle = function(step, options) {
3408
+ return this.executeStep("searchGoogle", step, options);
3409
+ };
3410
+ proto.searchGoogleCalendarEvents = function(step, options) {
3411
+ return this.executeStep("searchGoogleCalendarEvents", step, options);
3412
+ };
3413
+ proto.searchGoogleDrive = function(step, options) {
3414
+ return this.executeStep("searchGoogleDrive", step, options);
3415
+ };
3416
+ proto.searchGoogleImages = function(step, options) {
3417
+ return this.executeStep("searchGoogleImages", step, options);
3418
+ };
3419
+ proto.searchGoogleNews = function(step, options) {
3420
+ return this.executeStep("searchGoogleNews", step, options);
3421
+ };
3422
+ proto.searchGoogleTrends = function(step, options) {
3423
+ return this.executeStep("searchGoogleTrends", step, options);
3424
+ };
3425
+ proto.searchPerplexity = function(step, options) {
3426
+ return this.executeStep("searchPerplexity", step, options);
3427
+ };
3428
+ proto.searchXPosts = function(step, options) {
3429
+ return this.executeStep("searchXPosts", step, options);
3430
+ };
3431
+ proto.searchYoutube = function(step, options) {
3432
+ return this.executeStep("searchYoutube", step, options);
3433
+ };
3434
+ proto.searchYoutubeTrends = function(step, options) {
3435
+ return this.executeStep("searchYoutubeTrends", step, options);
3436
+ };
3437
+ proto.sendEmail = function(step, options) {
3438
+ return this.executeStep("sendEmail", step, options);
3439
+ };
3440
+ proto.sendGmailDraft = function(step, options) {
3441
+ return this.executeStep("sendGmailDraft", step, options);
3442
+ };
3443
+ proto.sendGmailMessage = function(step, options) {
3444
+ return this.executeStep("sendGmailMessage", step, options);
3445
+ };
3446
+ proto.sendSlackDirectMessage = function(step, options) {
3447
+ return this.executeStep("sendSlackDirectMessage", step, options);
3448
+ };
3449
+ proto.sendSMS = function(step, options) {
3450
+ return this.executeStep("sendSMS", step, options);
3451
+ };
3452
+ proto.setGmailReadStatus = function(step, options) {
3453
+ return this.executeStep("setGmailReadStatus", step, options);
3454
+ };
3455
+ proto.setRunTitle = function(step, options) {
3456
+ return this.executeStep("setRunTitle", step, options);
3457
+ };
3458
+ proto.setVariable = function(step, options) {
3459
+ return this.executeStep("setVariable", step, options);
3460
+ };
3461
+ proto.telegramEditMessage = function(step, options) {
3462
+ return this.executeStep("telegramEditMessage", step, options);
3463
+ };
3464
+ proto.telegramReplyToMessage = function(step, options) {
3465
+ return this.executeStep("telegramReplyToMessage", step, options);
3466
+ };
3467
+ proto.telegramSendAudio = function(step, options) {
3468
+ return this.executeStep("telegramSendAudio", step, options);
3469
+ };
3470
+ proto.telegramSendFile = function(step, options) {
3471
+ return this.executeStep("telegramSendFile", step, options);
3472
+ };
3473
+ proto.telegramSendImage = function(step, options) {
3474
+ return this.executeStep("telegramSendImage", step, options);
3475
+ };
3476
+ proto.telegramSendMessage = function(step, options) {
3477
+ return this.executeStep("telegramSendMessage", step, options);
3478
+ };
3479
+ proto.telegramSendVideo = function(step, options) {
3480
+ return this.executeStep("telegramSendVideo", step, options);
3481
+ };
3482
+ proto.telegramSetTyping = function(step, options) {
3483
+ return this.executeStep("telegramSetTyping", step, options);
3484
+ };
3485
+ proto.textToSpeech = function(step, options) {
3486
+ return this.executeStep("textToSpeech", step, options);
3487
+ };
3488
+ proto.transcribeAudio = function(step, options) {
3489
+ return this.executeStep("transcribeAudio", step, options);
3490
+ };
3491
+ proto.trimMedia = function(step, options) {
3492
+ return this.executeStep("trimMedia", step, options);
3493
+ };
3494
+ proto.updateGmailLabels = function(step, options) {
3495
+ return this.executeStep("updateGmailLabels", step, options);
3496
+ };
3497
+ proto.updateGoogleCalendarEvent = function(step, options) {
3498
+ return this.executeStep("updateGoogleCalendarEvent", step, options);
3499
+ };
3500
+ proto.updateGoogleDoc = function(step, options) {
3501
+ return this.executeStep("updateGoogleDoc", step, options);
3502
+ };
3503
+ proto.updateGoogleSheet = function(step, options) {
3504
+ return this.executeStep("updateGoogleSheet", step, options);
3505
+ };
3506
+ proto.uploadDataSourceDocument = function(step, options) {
3507
+ return this.executeStep("uploadDataSourceDocument", step, options);
3508
+ };
3509
+ proto.upscaleImage = function(step, options) {
3510
+ return this.executeStep("upscaleImage", step, options);
3511
+ };
3512
+ proto.upscaleVideo = function(step, options) {
3513
+ return this.executeStep("upscaleVideo", step, options);
3514
+ };
3515
+ proto.generateText = function(step, options) {
3516
+ return this.executeStep("userMessage", step, options);
3517
+ };
3518
+ proto.videoFaceSwap = function(step, options) {
3519
+ return this.executeStep("videoFaceSwap", step, options);
3520
+ };
3521
+ proto.videoRemoveBackground = function(step, options) {
3522
+ return this.executeStep("videoRemoveBackground", step, options);
3523
+ };
3524
+ proto.videoRemoveWatermark = function(step, options) {
3525
+ return this.executeStep("videoRemoveWatermark", step, options);
3526
+ };
3527
+ proto.watermarkImage = function(step, options) {
3528
+ return this.executeStep("watermarkImage", step, options);
3529
+ };
3530
+ proto.watermarkVideo = function(step, options) {
3531
+ return this.executeStep("watermarkVideo", step, options);
3532
+ };
3533
+ }
3534
+
3354
3535
  // src/client.ts
3355
3536
  var DEFAULT_BASE_URL = "https://v1.mindstudio-api.com";
3356
3537
  var DEFAULT_MAX_RETRIES = 3;
@@ -3690,52 +3871,115 @@ var MindStudioAgent = class {
3690
3871
  */
3691
3872
  async executeStepBatch(steps, options) {
3692
3873
  const threadId = options?.threadId ?? (this._reuseThreadId && !getRequestContext() ? this._threadId : void 0);
3693
- const { data } = await request(this._httpConfig, "POST", "/steps/execute-batch", {
3694
- steps: steps.map((s) => ({ ...s, stepType: resolveStepType(s.stepType) })),
3874
+ const { data: asyncData } = await request(this._currentHttpConfig, "POST", "/steps/execute-batch-async", {
3875
+ steps: steps.map((s) => ({ ...s, stepType: resolveStepType2(s.stepType) })),
3695
3876
  ...options?.appId != null && { appId: options.appId },
3696
3877
  ...threadId != null && { threadId }
3697
3878
  });
3698
- const results = await Promise.all(
3699
- data.results.map(async (r) => {
3700
- if (r.output != null) {
3701
- return {
3702
- stepType: r.stepType,
3703
- output: r.output,
3704
- billingCost: r.billingCost,
3705
- error: r.error
3706
- };
3879
+ const pollUrl = `${this._currentHttpConfig.baseUrl}/developer/v2/steps/execute-batch-async/poll/${asyncData.batchToken}`;
3880
+ let pollDelay = 300;
3881
+ while (true) {
3882
+ await sleep3(pollDelay);
3883
+ pollDelay = Math.min(pollDelay * 1.5, 3e3);
3884
+ const res = await fetch(pollUrl, {
3885
+ headers: { "User-Agent": "@mindstudio-ai/agent" }
3886
+ });
3887
+ if (res.status === 404) {
3888
+ throw new MindStudioError(
3889
+ "Batch poll token not found or expired.",
3890
+ "poll_token_expired",
3891
+ 404
3892
+ );
3893
+ }
3894
+ if (!res.ok) {
3895
+ const errorBody = await res.json().catch(() => ({}));
3896
+ throw new MindStudioError(
3897
+ errorBody.message ?? errorBody.error ?? `Batch poll failed: ${res.status} ${res.statusText}`,
3898
+ errorBody.code ?? "poll_error",
3899
+ res.status,
3900
+ errorBody
3901
+ );
3902
+ }
3903
+ const poll = await res.json();
3904
+ if (poll.status === "pending") {
3905
+ if (options?.onProgress && poll.totalSteps != null && poll.completedSteps != null) {
3906
+ options.onProgress(poll.completedSteps, poll.totalSteps);
3707
3907
  }
3708
- if (r.outputUrl) {
3709
- const res = await fetch(r.outputUrl);
3710
- if (!res.ok) {
3908
+ continue;
3909
+ }
3910
+ if (poll.status === "error") {
3911
+ throw new MindStudioError(
3912
+ poll.error ?? "Batch execution failed.",
3913
+ "batch_execution_error",
3914
+ 500
3915
+ );
3916
+ }
3917
+ const results = await Promise.all(
3918
+ poll.results.map(async (r) => {
3919
+ if (r.output != null) {
3920
+ return {
3921
+ stepType: r.stepType,
3922
+ output: r.output,
3923
+ billingCost: r.billingCost,
3924
+ error: r.error
3925
+ };
3926
+ }
3927
+ if (r.outputUrl) {
3928
+ const s3Res = await fetch(r.outputUrl);
3929
+ if (!s3Res.ok) {
3930
+ return {
3931
+ stepType: r.stepType,
3932
+ error: `Failed to fetch output from S3: ${s3Res.status} ${s3Res.statusText}`
3933
+ };
3934
+ }
3935
+ const envelope = await s3Res.json();
3711
3936
  return {
3712
3937
  stepType: r.stepType,
3713
- error: `Failed to fetch output from S3: ${res.status} ${res.statusText}`
3938
+ output: envelope.value,
3939
+ billingCost: r.billingCost
3714
3940
  };
3715
3941
  }
3716
- const envelope = await res.json();
3717
3942
  return {
3718
3943
  stepType: r.stepType,
3719
- output: envelope.value,
3720
- billingCost: r.billingCost
3944
+ billingCost: r.billingCost,
3945
+ error: r.error
3721
3946
  };
3722
- }
3723
- return {
3724
- stepType: r.stepType,
3725
- billingCost: r.billingCost,
3726
- error: r.error
3727
- };
3728
- })
3729
- );
3730
- if (this._reuseThreadId && data.threadId && !getRequestContext()) {
3731
- this._threadId = data.threadId;
3947
+ })
3948
+ );
3949
+ const resultThreadId = poll.threadId ?? asyncData.threadId;
3950
+ if (this._reuseThreadId && resultThreadId && !getRequestContext()) {
3951
+ this._threadId = resultThreadId;
3952
+ }
3953
+ return {
3954
+ results,
3955
+ totalBillingCost: poll.totalBillingCost,
3956
+ appId: poll.appId,
3957
+ threadId: resultThreadId
3958
+ };
3732
3959
  }
3733
- return {
3734
- results,
3735
- totalBillingCost: data.totalBillingCost,
3736
- appId: data.appId,
3737
- threadId: data.threadId
3738
- };
3960
+ }
3961
+ /**
3962
+ * Run a task agent — a multi-step tool-use loop that composes SDK actions
3963
+ * to produce structured output. The model receives the prompt and tools,
3964
+ * calls actions as needed, and returns JSON matching the output example.
3965
+ *
3966
+ * ```ts
3967
+ * const result = await agent.runTask<{ name: string; url: string }>({
3968
+ * prompt: 'Find canonical info for this restaurant.',
3969
+ * input: { restaurantName: 'Tartine Bakery SF' },
3970
+ * tools: ['searchGoogle', 'fetchUrl'],
3971
+ * structuredOutputExample: JSON.stringify({ name: 'Tartine Bakery', url: 'https://tartinebakery.com' }),
3972
+ * model: 'claude-4-6-sonnet',
3973
+ * });
3974
+ * console.log(result.output.name); // 'Tartine Bakery'
3975
+ * ```
3976
+ */
3977
+ async runTask(options) {
3978
+ const body = buildTaskRequestBody(options);
3979
+ if (options.onEvent) {
3980
+ return runTaskStream(this._currentHttpConfig, body, options.onEvent);
3981
+ }
3982
+ return runTaskPoll(this._currentHttpConfig, body);
3739
3983
  }
3740
3984
  /**
3741
3985
  * Get the authenticated user's identity and organization info.
@@ -3799,7 +4043,7 @@ var MindStudioAgent = class {
3799
4043
  const token = data.callbackToken;
3800
4044
  const pollUrl = `${this._currentHttpConfig.baseUrl}/developer/v2/agents/run/poll/${token}`;
3801
4045
  while (true) {
3802
- await sleep2(pollInterval);
4046
+ await sleep3(pollInterval);
3803
4047
  const res = await fetch(pollUrl, {
3804
4048
  headers: { "User-Agent": "@mindstudio-ai/agent" }
3805
4049
  });
@@ -3924,7 +4168,7 @@ var MindStudioAgent = class {
3924
4168
  /** Estimate the cost of executing an action before running it. */
3925
4169
  async estimateStepCost(stepType, step, options) {
3926
4170
  const { data } = await request(this._httpConfig, "POST", "/helpers/step-cost-estimate", {
3927
- step: { type: resolveStepType(stepType), ...step },
4171
+ step: { type: resolveStepType2(stepType), ...step },
3928
4172
  ...options
3929
4173
  });
3930
4174
  return data;
@@ -4410,11 +4654,11 @@ var MindStudioAgent = class {
4410
4654
  return { url: data.url };
4411
4655
  }
4412
4656
  };
4413
- function sleep2(ms) {
4657
+ function sleep3(ms) {
4414
4658
  return new Promise((resolve) => setTimeout(resolve, ms));
4415
4659
  }
4416
4660
  applyStepMethods(MindStudioAgent);
4417
- function resolveStepType(name) {
4661
+ function resolveStepType2(name) {
4418
4662
  const meta = stepMetadata[name];
4419
4663
  return meta ? meta.stepType : name;
4420
4664
  }