@mindstudio-ai/agent 0.1.45 → 0.1.47

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
@@ -42,9 +42,9 @@ async function requestWithRetry(config, method, url, body, attempt) {
42
42
  body: body != null ? JSON.stringify(body) : void 0
43
43
  });
44
44
  config.rateLimiter.updateFromHeaders(res.headers);
45
- if (res.status === 429 && attempt < config.maxRetries) {
45
+ if (attempt < config.maxRetries && (res.status === 429 || res.status === 502 || res.status === 503 || res.status === 504)) {
46
46
  const retryAfter = res.headers.get("retry-after");
47
- const waitMs = retryAfter ? parseFloat(retryAfter) * 1e3 : 1e3;
47
+ const waitMs = retryAfter ? parseFloat(retryAfter) * 1e3 : Math.min(1e3 * Math.pow(2, attempt), 1e4);
48
48
  await sleep(waitMs);
49
49
  return requestWithRetry(config, method, url, body, attempt + 1);
50
50
  }
@@ -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": {
@@ -3349,7 +2864,701 @@ var stepMetadata = {
3349
2864
  inputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the source video" }, "imageUrl": { "type": "string", "description": "URL of the watermark image to overlay" }, "corner": { "enum": ["top-left", "top-right", "bottom-left", "bottom-right"], "type": "string", "description": "Corner position for the watermark placement" }, "paddingPx": { "type": "number", "description": "Padding from the corner in pixels" }, "widthPx": { "type": "number", "description": "Width of the watermark overlay in pixels" }, "intermediateAsset": { "type": "boolean", "description": "When true, the asset is created but hidden from the user's gallery (tagged as intermediate)" } }, "required": ["videoUrl", "imageUrl", "corner", "paddingPx", "widthPx"] },
3350
2865
  outputSchema: { "type": "object", "properties": { "videoUrl": { "type": "string", "description": "URL of the watermarked video" } }, "required": ["videoUrl"] }
3351
2866
  }
3352
- };
2867
+ };
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: typeof options.structuredOutputExample === "string" ? options.structuredOutputExample : JSON.stringify(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
+ function isDevMode() {
2898
+ return !!(process.env.CALLBACK_TOKEN || getRequestContext()?.callbackToken);
2899
+ }
2900
+ function logTaskResult(result) {
2901
+ if (!isDevMode()) return;
2902
+ const toolSummary = result.toolCalls.map((tc) => `${tc.name} (${tc.durationMs}ms) ${tc.success ? "\u2713" : "\u2717"}`).join(", ");
2903
+ console.log(
2904
+ `[task] ${result.turns} turn${result.turns === 1 ? "" : "s"}` + (toolSummary ? `: ${toolSummary}` : "") + ` | ${result.parsedSuccessfully ? "output OK" : "\u26A0 output not valid JSON"} | cost: ${result.usage.totalBillingCost}`
2905
+ );
2906
+ }
2907
+ async function runTaskPoll(httpConfig, body) {
2908
+ const { data } = await request(
2909
+ httpConfig,
2910
+ "POST",
2911
+ "/task",
2912
+ body
2913
+ );
2914
+ const pollUrl = `${httpConfig.baseUrl}/developer/v2/task/poll/${data.taskToken}`;
2915
+ let pollDelay = 300;
2916
+ while (true) {
2917
+ await sleep2(pollDelay);
2918
+ pollDelay = Math.min(pollDelay * 1.5, 3e3);
2919
+ const res = await fetch(pollUrl, {
2920
+ headers: { "User-Agent": "@mindstudio-ai/agent" }
2921
+ });
2922
+ if (res.status === 502 || res.status === 503 || res.status === 504) continue;
2923
+ if (res.status === 404) {
2924
+ throw new MindStudioError(
2925
+ "Task poll token not found or expired.",
2926
+ "poll_token_expired",
2927
+ 404
2928
+ );
2929
+ }
2930
+ if (!res.ok) {
2931
+ const errorBody = await res.json().catch(() => ({}));
2932
+ throw new MindStudioError(
2933
+ errorBody.message ?? errorBody.error ?? `Task poll failed: ${res.status} ${res.statusText}`,
2934
+ errorBody.code ?? "poll_error",
2935
+ res.status,
2936
+ errorBody
2937
+ );
2938
+ }
2939
+ const poll = await res.json();
2940
+ if (poll.status === "pending") {
2941
+ if (isDevMode() && poll.currentTurn != null) {
2942
+ console.log(`[task] running... turn ${poll.currentTurn}/${poll.maxTurns ?? "?"}`);
2943
+ }
2944
+ continue;
2945
+ }
2946
+ if (poll.status === "error") {
2947
+ throw new MindStudioError(
2948
+ poll.error ?? "Task execution failed.",
2949
+ "task_execution_error",
2950
+ 500
2951
+ );
2952
+ }
2953
+ const result = {
2954
+ output: poll.output,
2955
+ outputRaw: poll.outputRaw ?? "",
2956
+ parsedSuccessfully: poll.parsedSuccessfully ?? true,
2957
+ turns: poll.turns ?? 0,
2958
+ usage: poll.usage ?? { inputTokens: 0, outputTokens: 0, totalBillingCost: 0 },
2959
+ toolCalls: poll.toolCalls ?? []
2960
+ };
2961
+ logTaskResult(result);
2962
+ return result;
2963
+ }
2964
+ }
2965
+ async function runTaskStream(httpConfig, body, onEvent) {
2966
+ const url = `${httpConfig.baseUrl}/developer/v2/task`;
2967
+ const res = await fetch(url, {
2968
+ method: "POST",
2969
+ headers: {
2970
+ Authorization: `Bearer ${httpConfig.token}`,
2971
+ "Content-Type": "application/json",
2972
+ "User-Agent": "@mindstudio-ai/agent",
2973
+ Accept: "text/event-stream"
2974
+ },
2975
+ body: JSON.stringify(body)
2976
+ });
2977
+ if (!res.ok) {
2978
+ let message = `${res.status} ${res.statusText}`;
2979
+ let code = "api_error";
2980
+ let details;
2981
+ try {
2982
+ const text = await res.text();
2983
+ try {
2984
+ const errBody = JSON.parse(text);
2985
+ details = errBody;
2986
+ const errMsg = (typeof errBody.error === "string" ? errBody.error : void 0) ?? (typeof errBody.message === "string" ? errBody.message : void 0);
2987
+ if (errMsg) message = errMsg;
2988
+ if (errBody.code) code = errBody.code;
2989
+ } catch {
2990
+ const stripped = text.replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
2991
+ if (stripped) message = stripped.slice(0, 200);
2992
+ }
2993
+ } catch {
2994
+ }
2995
+ throw new MindStudioError(`[task] ${message}`, code, res.status, details);
2996
+ }
2997
+ const reader = res.body.getReader();
2998
+ const decoder = new TextDecoder();
2999
+ let buffer = "";
3000
+ let result = null;
3001
+ while (true) {
3002
+ const { done, value } = await reader.read();
3003
+ if (done) break;
3004
+ buffer += decoder.decode(value, { stream: true });
3005
+ const lines = buffer.split("\n");
3006
+ buffer = lines.pop() ?? "";
3007
+ for (const line of lines) {
3008
+ if (!line.startsWith("data: ")) continue;
3009
+ try {
3010
+ const event = JSON.parse(line.slice(6));
3011
+ onEvent(event);
3012
+ if (event.type === "error") {
3013
+ throw new MindStudioError(
3014
+ event.error ?? "Task execution failed.",
3015
+ "task_execution_error",
3016
+ 500
3017
+ );
3018
+ }
3019
+ if (event.type === "done") {
3020
+ result = {
3021
+ output: event.output,
3022
+ outputRaw: event.outputRaw ?? "",
3023
+ parsedSuccessfully: event.parsedSuccessfully ?? true,
3024
+ turns: event.turns ?? 0,
3025
+ usage: event.usage ?? {
3026
+ inputTokens: 0,
3027
+ outputTokens: 0,
3028
+ totalBillingCost: 0
3029
+ },
3030
+ toolCalls: event.toolCalls ?? []
3031
+ };
3032
+ }
3033
+ } catch (err) {
3034
+ if (err instanceof MindStudioError) throw err;
3035
+ }
3036
+ }
3037
+ }
3038
+ if (buffer.startsWith("data: ")) {
3039
+ try {
3040
+ const event = JSON.parse(buffer.slice(6));
3041
+ onEvent(event);
3042
+ if (event.type === "error") {
3043
+ throw new MindStudioError(
3044
+ event.error ?? "Task execution failed.",
3045
+ "task_execution_error",
3046
+ 500
3047
+ );
3048
+ }
3049
+ if (event.type === "done") {
3050
+ result = {
3051
+ output: event.output,
3052
+ outputRaw: event.outputRaw ?? "",
3053
+ parsedSuccessfully: event.parsedSuccessfully ?? true,
3054
+ turns: event.turns ?? 0,
3055
+ usage: event.usage ?? {
3056
+ inputTokens: 0,
3057
+ outputTokens: 0,
3058
+ totalBillingCost: 0
3059
+ },
3060
+ toolCalls: event.toolCalls ?? []
3061
+ };
3062
+ }
3063
+ } catch (err) {
3064
+ if (err instanceof MindStudioError) throw err;
3065
+ }
3066
+ }
3067
+ if (!result) {
3068
+ throw new MindStudioError(
3069
+ "[task] Stream ended without a done event. The task execution may have been interrupted.",
3070
+ "stream_error",
3071
+ 500
3072
+ );
3073
+ }
3074
+ logTaskResult(result);
3075
+ return result;
3076
+ }
3077
+
3078
+ // src/generated/steps.ts
3079
+ function applyStepMethods(AgentClass) {
3080
+ const proto = AgentClass.prototype;
3081
+ proto.activeCampaignAddNote = function(step, options) {
3082
+ return this.executeStep("activeCampaignAddNote", step, options);
3083
+ };
3084
+ proto.activeCampaignCreateContact = function(step, options) {
3085
+ return this.executeStep("activeCampaignCreateContact", step, options);
3086
+ };
3087
+ proto.addSubtitlesToVideo = function(step, options) {
3088
+ return this.executeStep("addSubtitlesToVideo", step, options);
3089
+ };
3090
+ proto.airtableCreateUpdateRecord = function(step, options) {
3091
+ return this.executeStep("airtableCreateUpdateRecord", step, options);
3092
+ };
3093
+ proto.airtableDeleteRecord = function(step, options) {
3094
+ return this.executeStep("airtableDeleteRecord", step, options);
3095
+ };
3096
+ proto.airtableGetRecord = function(step, options) {
3097
+ return this.executeStep("airtableGetRecord", step, options);
3098
+ };
3099
+ proto.airtableGetTableRecords = function(step, options) {
3100
+ return this.executeStep("airtableGetTableRecords", step, options);
3101
+ };
3102
+ proto.analyzeImage = function(step, options) {
3103
+ return this.executeStep("analyzeImage", step, options);
3104
+ };
3105
+ proto.analyzeVideo = function(step, options) {
3106
+ return this.executeStep("analyzeVideo", step, options);
3107
+ };
3108
+ proto.captureThumbnail = function(step, options) {
3109
+ return this.executeStep("captureThumbnail", step, options);
3110
+ };
3111
+ proto.checkAppRole = function(step, options) {
3112
+ return this.executeStep("checkAppRole", step, options);
3113
+ };
3114
+ proto.codaCreateUpdatePage = function(step, options) {
3115
+ return this.executeStep("codaCreateUpdatePage", step, options);
3116
+ };
3117
+ proto.codaCreateUpdateRow = function(step, options) {
3118
+ return this.executeStep("codaCreateUpdateRow", step, options);
3119
+ };
3120
+ proto.codaFindRow = function(step, options) {
3121
+ return this.executeStep("codaFindRow", step, options);
3122
+ };
3123
+ proto.codaGetPage = function(step, options) {
3124
+ return this.executeStep("codaGetPage", step, options);
3125
+ };
3126
+ proto.codaGetTableRows = function(step, options) {
3127
+ return this.executeStep("codaGetTableRows", step, options);
3128
+ };
3129
+ proto.convertPdfToImages = function(step, options) {
3130
+ return this.executeStep("convertPdfToImages", step, options);
3131
+ };
3132
+ proto.createDataSource = function(step, options) {
3133
+ return this.executeStep("createDataSource", step, options);
3134
+ };
3135
+ proto.createGmailDraft = function(step, options) {
3136
+ return this.executeStep("createGmailDraft", step, options);
3137
+ };
3138
+ proto.createGoogleCalendarEvent = function(step, options) {
3139
+ return this.executeStep("createGoogleCalendarEvent", step, options);
3140
+ };
3141
+ proto.createGoogleDoc = function(step, options) {
3142
+ return this.executeStep("createGoogleDoc", step, options);
3143
+ };
3144
+ proto.createGoogleSheet = function(step, options) {
3145
+ return this.executeStep("createGoogleSheet", step, options);
3146
+ };
3147
+ proto.deleteDataSource = function(step, options) {
3148
+ return this.executeStep("deleteDataSource", step, options);
3149
+ };
3150
+ proto.deleteDataSourceDocument = function(step, options) {
3151
+ return this.executeStep("deleteDataSourceDocument", step, options);
3152
+ };
3153
+ proto.deleteGmailEmail = function(step, options) {
3154
+ return this.executeStep("deleteGmailEmail", step, options);
3155
+ };
3156
+ proto.deleteGoogleCalendarEvent = function(step, options) {
3157
+ return this.executeStep("deleteGoogleCalendarEvent", step, options);
3158
+ };
3159
+ proto.deleteGoogleSheetRows = function(step, options) {
3160
+ return this.executeStep("deleteGoogleSheetRows", step, options);
3161
+ };
3162
+ proto.detectChanges = function(step, options) {
3163
+ return this.executeStep("detectChanges", step, options);
3164
+ };
3165
+ proto.detectPII = function(step, options) {
3166
+ return this.executeStep("detectPII", step, options);
3167
+ };
3168
+ proto.discordEditMessage = function(step, options) {
3169
+ return this.executeStep("discordEditMessage", step, options);
3170
+ };
3171
+ proto.discordSendFollowUp = function(step, options) {
3172
+ return this.executeStep("discordSendFollowUp", step, options);
3173
+ };
3174
+ proto.discordSendMessage = function(step, options) {
3175
+ return this.executeStep("discordSendMessage", step, options);
3176
+ };
3177
+ proto.downloadVideo = function(step, options) {
3178
+ return this.executeStep("downloadVideo", step, options);
3179
+ };
3180
+ proto.enhanceImageGenerationPrompt = function(step, options) {
3181
+ return this.executeStep("enhanceImageGenerationPrompt", step, options);
3182
+ };
3183
+ proto.enhanceVideoGenerationPrompt = function(step, options) {
3184
+ return this.executeStep("enhanceVideoGenerationPrompt", step, options);
3185
+ };
3186
+ proto.enrichPerson = function(step, options) {
3187
+ return this.executeStep("enrichPerson", step, options);
3188
+ };
3189
+ proto.extractAudioFromVideo = function(step, options) {
3190
+ return this.executeStep("extractAudioFromVideo", step, options);
3191
+ };
3192
+ proto.extractText = function(step, options) {
3193
+ return this.executeStep("extractText", step, options);
3194
+ };
3195
+ proto.fetchDataSourceDocument = function(step, options) {
3196
+ return this.executeStep("fetchDataSourceDocument", step, options);
3197
+ };
3198
+ proto.fetchGoogleDoc = function(step, options) {
3199
+ return this.executeStep("fetchGoogleDoc", step, options);
3200
+ };
3201
+ proto.fetchGoogleSheet = function(step, options) {
3202
+ return this.executeStep("fetchGoogleSheet", step, options);
3203
+ };
3204
+ proto.fetchSlackChannelHistory = function(step, options) {
3205
+ return this.executeStep("fetchSlackChannelHistory", step, options);
3206
+ };
3207
+ proto.fetchYoutubeCaptions = function(step, options) {
3208
+ return this.executeStep("fetchYoutubeCaptions", step, options);
3209
+ };
3210
+ proto.fetchYoutubeChannel = function(step, options) {
3211
+ return this.executeStep("fetchYoutubeChannel", step, options);
3212
+ };
3213
+ proto.fetchYoutubeComments = function(step, options) {
3214
+ return this.executeStep("fetchYoutubeComments", step, options);
3215
+ };
3216
+ proto.fetchYoutubeVideo = function(step, options) {
3217
+ return this.executeStep("fetchYoutubeVideo", step, options);
3218
+ };
3219
+ proto.generateChart = function(step, options) {
3220
+ return this.executeStep("generateChart", step, options);
3221
+ };
3222
+ proto.generateImage = function(step, options) {
3223
+ return this.executeStep("generateImage", step, options);
3224
+ };
3225
+ proto.generateLipsync = function(step, options) {
3226
+ return this.executeStep("generateLipsync", step, options);
3227
+ };
3228
+ proto.generateMusic = function(step, options) {
3229
+ return this.executeStep("generateMusic", step, options);
3230
+ };
3231
+ proto.generateAsset = function(step, options) {
3232
+ return this.executeStep("generatePdf", step, options);
3233
+ };
3234
+ proto.generateStaticVideoFromImage = function(step, options) {
3235
+ return this.executeStep("generateStaticVideoFromImage", step, options);
3236
+ };
3237
+ proto.generateVideo = function(step, options) {
3238
+ return this.executeStep("generateVideo", step, options);
3239
+ };
3240
+ proto.getGmailAttachments = function(step, options) {
3241
+ return this.executeStep("getGmailAttachments", step, options);
3242
+ };
3243
+ proto.getGmailDraft = function(step, options) {
3244
+ return this.executeStep("getGmailDraft", step, options);
3245
+ };
3246
+ proto.getGmailEmail = function(step, options) {
3247
+ return this.executeStep("getGmailEmail", step, options);
3248
+ };
3249
+ proto.getGmailUnreadCount = function(step, options) {
3250
+ return this.executeStep("getGmailUnreadCount", step, options);
3251
+ };
3252
+ proto.getGoogleCalendarEvent = function(step, options) {
3253
+ return this.executeStep("getGoogleCalendarEvent", step, options);
3254
+ };
3255
+ proto.getGoogleDriveFile = function(step, options) {
3256
+ return this.executeStep("getGoogleDriveFile", step, options);
3257
+ };
3258
+ proto.getGoogleSheetInfo = function(step, options) {
3259
+ return this.executeStep("getGoogleSheetInfo", step, options);
3260
+ };
3261
+ proto.getMediaMetadata = function(step, options) {
3262
+ return this.executeStep("getMediaMetadata", step, options);
3263
+ };
3264
+ proto.httpRequest = function(step, options) {
3265
+ return this.executeStep("httpRequest", step, options);
3266
+ };
3267
+ proto.hubspotCreateCompany = function(step, options) {
3268
+ return this.executeStep("hubspotCreateCompany", step, options);
3269
+ };
3270
+ proto.hubspotCreateContact = function(step, options) {
3271
+ return this.executeStep("hubspotCreateContact", step, options);
3272
+ };
3273
+ proto.hubspotGetCompany = function(step, options) {
3274
+ return this.executeStep("hubspotGetCompany", step, options);
3275
+ };
3276
+ proto.hubspotGetContact = function(step, options) {
3277
+ return this.executeStep("hubspotGetContact", step, options);
3278
+ };
3279
+ proto.hunterApiCompanyEnrichment = function(step, options) {
3280
+ return this.executeStep("hunterApiCompanyEnrichment", step, options);
3281
+ };
3282
+ proto.hunterApiDomainSearch = function(step, options) {
3283
+ return this.executeStep("hunterApiDomainSearch", step, options);
3284
+ };
3285
+ proto.hunterApiEmailFinder = function(step, options) {
3286
+ return this.executeStep("hunterApiEmailFinder", step, options);
3287
+ };
3288
+ proto.hunterApiEmailVerification = function(step, options) {
3289
+ return this.executeStep("hunterApiEmailVerification", step, options);
3290
+ };
3291
+ proto.hunterApiPersonEnrichment = function(step, options) {
3292
+ return this.executeStep("hunterApiPersonEnrichment", step, options);
3293
+ };
3294
+ proto.imageFaceSwap = function(step, options) {
3295
+ return this.executeStep("imageFaceSwap", step, options);
3296
+ };
3297
+ proto.imageRemoveWatermark = function(step, options) {
3298
+ return this.executeStep("imageRemoveWatermark", step, options);
3299
+ };
3300
+ proto.insertVideoClips = function(step, options) {
3301
+ return this.executeStep("insertVideoClips", step, options);
3302
+ };
3303
+ proto.listDataSources = function(step, options) {
3304
+ return this.executeStep("listDataSources", step, options);
3305
+ };
3306
+ proto.listGmailDrafts = function(step, options) {
3307
+ return this.executeStep("listGmailDrafts", step, options);
3308
+ };
3309
+ proto.listGmailLabels = function(step, options) {
3310
+ return this.executeStep("listGmailLabels", step, options);
3311
+ };
3312
+ proto.listGoogleCalendarEvents = function(step, options) {
3313
+ return this.executeStep("listGoogleCalendarEvents", step, options);
3314
+ };
3315
+ proto.listGoogleDriveFiles = function(step, options) {
3316
+ return this.executeStep("listGoogleDriveFiles", step, options);
3317
+ };
3318
+ proto.listRecentGmailEmails = function(step, options) {
3319
+ return this.executeStep("listRecentGmailEmails", step, options);
3320
+ };
3321
+ proto.logic = function(step, options) {
3322
+ return this.executeStep("logic", step, options);
3323
+ };
3324
+ proto.makeDotComRunScenario = function(step, options) {
3325
+ return this.executeStep("makeDotComRunScenario", step, options);
3326
+ };
3327
+ proto.mergeAudio = function(step, options) {
3328
+ return this.executeStep("mergeAudio", step, options);
3329
+ };
3330
+ proto.mergeVideos = function(step, options) {
3331
+ return this.executeStep("mergeVideos", step, options);
3332
+ };
3333
+ proto.mixAudioIntoVideo = function(step, options) {
3334
+ return this.executeStep("mixAudioIntoVideo", step, options);
3335
+ };
3336
+ proto.muteVideo = function(step, options) {
3337
+ return this.executeStep("muteVideo", step, options);
3338
+ };
3339
+ proto.n8nRunNode = function(step, options) {
3340
+ return this.executeStep("n8nRunNode", step, options);
3341
+ };
3342
+ proto.notionCreatePage = function(step, options) {
3343
+ return this.executeStep("notionCreatePage", step, options);
3344
+ };
3345
+ proto.notionUpdatePage = function(step, options) {
3346
+ return this.executeStep("notionUpdatePage", step, options);
3347
+ };
3348
+ proto.peopleSearch = function(step, options) {
3349
+ return this.executeStep("peopleSearch", step, options);
3350
+ };
3351
+ proto.postToLinkedIn = function(step, options) {
3352
+ return this.executeStep("postToLinkedIn", step, options);
3353
+ };
3354
+ proto.postToSlackChannel = function(step, options) {
3355
+ return this.executeStep("postToSlackChannel", step, options);
3356
+ };
3357
+ proto.postToX = function(step, options) {
3358
+ return this.executeStep("postToX", step, options);
3359
+ };
3360
+ proto.postToZapier = function(step, options) {
3361
+ return this.executeStep("postToZapier", step, options);
3362
+ };
3363
+ proto.queryAppDatabase = function(step, options) {
3364
+ return this.executeStep("queryAppDatabase", step, options);
3365
+ };
3366
+ proto.queryDataSource = function(step, options) {
3367
+ return this.executeStep("queryDataSource", step, options);
3368
+ };
3369
+ proto.queryExternalDatabase = function(step, options) {
3370
+ return this.executeStep("queryExternalDatabase", step, options);
3371
+ };
3372
+ proto.redactPII = function(step, options) {
3373
+ return this.executeStep("redactPII", step, options);
3374
+ };
3375
+ proto.removeBackgroundFromImage = function(step, options) {
3376
+ return this.executeStep("removeBackgroundFromImage", step, options);
3377
+ };
3378
+ proto.replyToGmailEmail = function(step, options) {
3379
+ return this.executeStep("replyToGmailEmail", step, options);
3380
+ };
3381
+ proto.resizeVideo = function(step, options) {
3382
+ return this.executeStep("resizeVideo", step, options);
3383
+ };
3384
+ proto.runFromConnectorRegistry = function(step, options) {
3385
+ return this.executeStep("runFromConnectorRegistry", step, options);
3386
+ };
3387
+ proto.runPackagedWorkflow = function(step, options) {
3388
+ return this.executeStep("runPackagedWorkflow", step, options);
3389
+ };
3390
+ proto.scrapeFacebookPage = function(step, options) {
3391
+ return this.executeStep("scrapeFacebookPage", step, options);
3392
+ };
3393
+ proto.scrapeFacebookPosts = function(step, options) {
3394
+ return this.executeStep("scrapeFacebookPosts", step, options);
3395
+ };
3396
+ proto.scrapeInstagramComments = function(step, options) {
3397
+ return this.executeStep("scrapeInstagramComments", step, options);
3398
+ };
3399
+ proto.scrapeInstagramMentions = function(step, options) {
3400
+ return this.executeStep("scrapeInstagramMentions", step, options);
3401
+ };
3402
+ proto.scrapeInstagramPosts = function(step, options) {
3403
+ return this.executeStep("scrapeInstagramPosts", step, options);
3404
+ };
3405
+ proto.scrapeInstagramProfile = function(step, options) {
3406
+ return this.executeStep("scrapeInstagramProfile", step, options);
3407
+ };
3408
+ proto.scrapeInstagramReels = function(step, options) {
3409
+ return this.executeStep("scrapeInstagramReels", step, options);
3410
+ };
3411
+ proto.scrapeLinkedInCompany = function(step, options) {
3412
+ return this.executeStep("scrapeLinkedInCompany", step, options);
3413
+ };
3414
+ proto.scrapeLinkedInProfile = function(step, options) {
3415
+ return this.executeStep("scrapeLinkedInProfile", step, options);
3416
+ };
3417
+ proto.scrapeMetaThreadsProfile = function(step, options) {
3418
+ return this.executeStep("scrapeMetaThreadsProfile", step, options);
3419
+ };
3420
+ proto.scrapeUrl = function(step, options) {
3421
+ return this.executeStep("scrapeUrl", step, options);
3422
+ };
3423
+ proto.scrapeXPost = function(step, options) {
3424
+ return this.executeStep("scrapeXPost", step, options);
3425
+ };
3426
+ proto.scrapeXProfile = function(step, options) {
3427
+ return this.executeStep("scrapeXProfile", step, options);
3428
+ };
3429
+ proto.screenshotUrl = function(step, options) {
3430
+ return this.executeStep("screenshotUrl", step, options);
3431
+ };
3432
+ proto.searchGmailEmails = function(step, options) {
3433
+ return this.executeStep("searchGmailEmails", step, options);
3434
+ };
3435
+ proto.searchGoogle = function(step, options) {
3436
+ return this.executeStep("searchGoogle", step, options);
3437
+ };
3438
+ proto.searchGoogleCalendarEvents = function(step, options) {
3439
+ return this.executeStep("searchGoogleCalendarEvents", step, options);
3440
+ };
3441
+ proto.searchGoogleDrive = function(step, options) {
3442
+ return this.executeStep("searchGoogleDrive", step, options);
3443
+ };
3444
+ proto.searchGoogleImages = function(step, options) {
3445
+ return this.executeStep("searchGoogleImages", step, options);
3446
+ };
3447
+ proto.searchGoogleNews = function(step, options) {
3448
+ return this.executeStep("searchGoogleNews", step, options);
3449
+ };
3450
+ proto.searchGoogleTrends = function(step, options) {
3451
+ return this.executeStep("searchGoogleTrends", step, options);
3452
+ };
3453
+ proto.searchPerplexity = function(step, options) {
3454
+ return this.executeStep("searchPerplexity", step, options);
3455
+ };
3456
+ proto.searchXPosts = function(step, options) {
3457
+ return this.executeStep("searchXPosts", step, options);
3458
+ };
3459
+ proto.searchYoutube = function(step, options) {
3460
+ return this.executeStep("searchYoutube", step, options);
3461
+ };
3462
+ proto.searchYoutubeTrends = function(step, options) {
3463
+ return this.executeStep("searchYoutubeTrends", step, options);
3464
+ };
3465
+ proto.sendEmail = function(step, options) {
3466
+ return this.executeStep("sendEmail", step, options);
3467
+ };
3468
+ proto.sendGmailDraft = function(step, options) {
3469
+ return this.executeStep("sendGmailDraft", step, options);
3470
+ };
3471
+ proto.sendGmailMessage = function(step, options) {
3472
+ return this.executeStep("sendGmailMessage", step, options);
3473
+ };
3474
+ proto.sendSlackDirectMessage = function(step, options) {
3475
+ return this.executeStep("sendSlackDirectMessage", step, options);
3476
+ };
3477
+ proto.sendSMS = function(step, options) {
3478
+ return this.executeStep("sendSMS", step, options);
3479
+ };
3480
+ proto.setGmailReadStatus = function(step, options) {
3481
+ return this.executeStep("setGmailReadStatus", step, options);
3482
+ };
3483
+ proto.setRunTitle = function(step, options) {
3484
+ return this.executeStep("setRunTitle", step, options);
3485
+ };
3486
+ proto.setVariable = function(step, options) {
3487
+ return this.executeStep("setVariable", step, options);
3488
+ };
3489
+ proto.telegramEditMessage = function(step, options) {
3490
+ return this.executeStep("telegramEditMessage", step, options);
3491
+ };
3492
+ proto.telegramReplyToMessage = function(step, options) {
3493
+ return this.executeStep("telegramReplyToMessage", step, options);
3494
+ };
3495
+ proto.telegramSendAudio = function(step, options) {
3496
+ return this.executeStep("telegramSendAudio", step, options);
3497
+ };
3498
+ proto.telegramSendFile = function(step, options) {
3499
+ return this.executeStep("telegramSendFile", step, options);
3500
+ };
3501
+ proto.telegramSendImage = function(step, options) {
3502
+ return this.executeStep("telegramSendImage", step, options);
3503
+ };
3504
+ proto.telegramSendMessage = function(step, options) {
3505
+ return this.executeStep("telegramSendMessage", step, options);
3506
+ };
3507
+ proto.telegramSendVideo = function(step, options) {
3508
+ return this.executeStep("telegramSendVideo", step, options);
3509
+ };
3510
+ proto.telegramSetTyping = function(step, options) {
3511
+ return this.executeStep("telegramSetTyping", step, options);
3512
+ };
3513
+ proto.textToSpeech = function(step, options) {
3514
+ return this.executeStep("textToSpeech", step, options);
3515
+ };
3516
+ proto.transcribeAudio = function(step, options) {
3517
+ return this.executeStep("transcribeAudio", step, options);
3518
+ };
3519
+ proto.trimMedia = function(step, options) {
3520
+ return this.executeStep("trimMedia", step, options);
3521
+ };
3522
+ proto.updateGmailLabels = function(step, options) {
3523
+ return this.executeStep("updateGmailLabels", step, options);
3524
+ };
3525
+ proto.updateGoogleCalendarEvent = function(step, options) {
3526
+ return this.executeStep("updateGoogleCalendarEvent", step, options);
3527
+ };
3528
+ proto.updateGoogleDoc = function(step, options) {
3529
+ return this.executeStep("updateGoogleDoc", step, options);
3530
+ };
3531
+ proto.updateGoogleSheet = function(step, options) {
3532
+ return this.executeStep("updateGoogleSheet", step, options);
3533
+ };
3534
+ proto.uploadDataSourceDocument = function(step, options) {
3535
+ return this.executeStep("uploadDataSourceDocument", step, options);
3536
+ };
3537
+ proto.upscaleImage = function(step, options) {
3538
+ return this.executeStep("upscaleImage", step, options);
3539
+ };
3540
+ proto.upscaleVideo = function(step, options) {
3541
+ return this.executeStep("upscaleVideo", step, options);
3542
+ };
3543
+ proto.generateText = function(step, options) {
3544
+ return this.executeStep("userMessage", step, options);
3545
+ };
3546
+ proto.videoFaceSwap = function(step, options) {
3547
+ return this.executeStep("videoFaceSwap", step, options);
3548
+ };
3549
+ proto.videoRemoveBackground = function(step, options) {
3550
+ return this.executeStep("videoRemoveBackground", step, options);
3551
+ };
3552
+ proto.videoRemoveWatermark = function(step, options) {
3553
+ return this.executeStep("videoRemoveWatermark", step, options);
3554
+ };
3555
+ proto.watermarkImage = function(step, options) {
3556
+ return this.executeStep("watermarkImage", step, options);
3557
+ };
3558
+ proto.watermarkVideo = function(step, options) {
3559
+ return this.executeStep("watermarkVideo", step, options);
3560
+ };
3561
+ }
3353
3562
 
3354
3563
  // src/client.ts
3355
3564
  var DEFAULT_BASE_URL = "https://v1.mindstudio-api.com";
@@ -3691,18 +3900,19 @@ var MindStudioAgent = class {
3691
3900
  async executeStepBatch(steps, options) {
3692
3901
  const threadId = options?.threadId ?? (this._reuseThreadId && !getRequestContext() ? this._threadId : void 0);
3693
3902
  const { data: asyncData } = await request(this._currentHttpConfig, "POST", "/steps/execute-batch-async", {
3694
- steps: steps.map((s) => ({ ...s, stepType: resolveStepType(s.stepType) })),
3903
+ steps: steps.map((s) => ({ ...s, stepType: resolveStepType2(s.stepType) })),
3695
3904
  ...options?.appId != null && { appId: options.appId },
3696
3905
  ...threadId != null && { threadId }
3697
3906
  });
3698
3907
  const pollUrl = `${this._currentHttpConfig.baseUrl}/developer/v2/steps/execute-batch-async/poll/${asyncData.batchToken}`;
3699
3908
  let pollDelay = 300;
3700
3909
  while (true) {
3701
- await sleep2(pollDelay);
3910
+ await sleep3(pollDelay);
3702
3911
  pollDelay = Math.min(pollDelay * 1.5, 3e3);
3703
3912
  const res = await fetch(pollUrl, {
3704
3913
  headers: { "User-Agent": "@mindstudio-ai/agent" }
3705
3914
  });
3915
+ if (res.status === 502 || res.status === 503 || res.status === 504) continue;
3706
3916
  if (res.status === 404) {
3707
3917
  throw new MindStudioError(
3708
3918
  "Batch poll token not found or expired.",
@@ -3777,6 +3987,29 @@ var MindStudioAgent = class {
3777
3987
  };
3778
3988
  }
3779
3989
  }
3990
+ /**
3991
+ * Run a task agent — a multi-step tool-use loop that composes SDK actions
3992
+ * to produce structured output. The model receives the prompt and tools,
3993
+ * calls actions as needed, and returns JSON matching the output example.
3994
+ *
3995
+ * ```ts
3996
+ * const result = await agent.runTask<{ name: string; url: string }>({
3997
+ * prompt: 'Find canonical info for this restaurant.',
3998
+ * input: { restaurantName: 'Tartine Bakery SF' },
3999
+ * tools: ['searchGoogle', 'fetchUrl'],
4000
+ * structuredOutputExample: JSON.stringify({ name: 'Tartine Bakery', url: 'https://tartinebakery.com' }),
4001
+ * model: 'claude-4-6-sonnet',
4002
+ * });
4003
+ * console.log(result.output.name); // 'Tartine Bakery'
4004
+ * ```
4005
+ */
4006
+ async runTask(options) {
4007
+ const body = buildTaskRequestBody(options);
4008
+ if (options.onEvent) {
4009
+ return runTaskStream(this._currentHttpConfig, body, options.onEvent);
4010
+ }
4011
+ return runTaskPoll(this._currentHttpConfig, body);
4012
+ }
3780
4013
  /**
3781
4014
  * Get the authenticated user's identity and organization info.
3782
4015
  *
@@ -3839,10 +4072,11 @@ var MindStudioAgent = class {
3839
4072
  const token = data.callbackToken;
3840
4073
  const pollUrl = `${this._currentHttpConfig.baseUrl}/developer/v2/agents/run/poll/${token}`;
3841
4074
  while (true) {
3842
- await sleep2(pollInterval);
4075
+ await sleep3(pollInterval);
3843
4076
  const res = await fetch(pollUrl, {
3844
4077
  headers: { "User-Agent": "@mindstudio-ai/agent" }
3845
4078
  });
4079
+ if (res.status === 502 || res.status === 503 || res.status === 504) continue;
3846
4080
  if (res.status === 404) {
3847
4081
  throw new MindStudioError(
3848
4082
  "Poll token not found or expired.",
@@ -3964,7 +4198,7 @@ var MindStudioAgent = class {
3964
4198
  /** Estimate the cost of executing an action before running it. */
3965
4199
  async estimateStepCost(stepType, step, options) {
3966
4200
  const { data } = await request(this._httpConfig, "POST", "/helpers/step-cost-estimate", {
3967
- step: { type: resolveStepType(stepType), ...step },
4201
+ step: { type: resolveStepType2(stepType), ...step },
3968
4202
  ...options
3969
4203
  });
3970
4204
  return data;
@@ -4450,11 +4684,11 @@ var MindStudioAgent = class {
4450
4684
  return { url: data.url };
4451
4685
  }
4452
4686
  };
4453
- function sleep2(ms) {
4687
+ function sleep3(ms) {
4454
4688
  return new Promise((resolve) => setTimeout(resolve, ms));
4455
4689
  }
4456
4690
  applyStepMethods(MindStudioAgent);
4457
- function resolveStepType(name) {
4691
+ function resolveStepType2(name) {
4458
4692
  const meta = stepMetadata[name];
4459
4693
  return meta ? meta.stepType : name;
4460
4694
  }