@skillful-ai/piece-web 0.0.1

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.
@@ -0,0 +1,251 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.webSearch = exports.WebSearchCategories = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
6
+ const common_1 = require("../common");
7
+ // Web search categories enum matching the Python implementation
8
+ var WebSearchCategories;
9
+ (function (WebSearchCategories) {
10
+ WebSearchCategories["AI_OVERVIEW"] = "ai_overview";
11
+ WebSearchCategories["ADS"] = "ads";
12
+ WebSearchCategories["ANSWER_BOX"] = "answer_box";
13
+ WebSearchCategories["AVAILABLE_ON"] = "available_on";
14
+ WebSearchCategories["BROADEN_SEARCHES"] = "broaden_searches";
15
+ WebSearchCategories["BUYING_GUIDE"] = "buying_guide";
16
+ WebSearchCategories["COMPLEMENTARY_RESULTS"] = "complementary_results";
17
+ WebSearchCategories["DMCA_MESSAGES"] = "dmca_messages";
18
+ WebSearchCategories["DISCOVER_MORE_PLACES"] = "discover_more_places";
19
+ WebSearchCategories["DISCUSSIONS_AND_FORUMS"] = "discussions_and_forums";
20
+ WebSearchCategories["EPISODE_GUIDE"] = "episode_guide";
21
+ WebSearchCategories["EVENTS_RESULTS"] = "events_results";
22
+ WebSearchCategories["FIND_RESULTS_ON"] = "find_results_on";
23
+ WebSearchCategories["GRAMMAR_CHECK"] = "grammar_check";
24
+ WebSearchCategories["IMMERSIVE_PRODUCTS"] = "immersive_products";
25
+ WebSearchCategories["INLINE_IMAGES"] = "inline_images";
26
+ WebSearchCategories["SHOPPING_RESULTS"] = "shopping_results";
27
+ WebSearchCategories["INLINE_VIDEOS"] = "inline_videos";
28
+ WebSearchCategories["JOBS_RESULTS"] = "jobs_results";
29
+ WebSearchCategories["KNOWLEDGE_GRAPH"] = "knowledge_graph";
30
+ WebSearchCategories["LATEST_POSTS"] = "latest_posts";
31
+ WebSearchCategories["LOCAL_ADS"] = "local_ads";
32
+ WebSearchCategories["LOCAL_NEWS"] = "local_news";
33
+ WebSearchCategories["LOCAL_MAP"] = "local_map";
34
+ WebSearchCategories["MENU_HIGHLIGHTS"] = "menu_highlights";
35
+ WebSearchCategories["NEWS_RESULTS"] = "news_results";
36
+ WebSearchCategories["NUTRITION_INFORMATION"] = "nutrition_information";
37
+ WebSearchCategories["ORGANIC_RESULTS"] = "organic_results";
38
+ WebSearchCategories["PERSPECTIVES"] = "perspectives";
39
+ WebSearchCategories["PLACES_SITES"] = "places_sites";
40
+ WebSearchCategories["POPULAR_DESTINATIONS"] = "popular_destinations";
41
+ WebSearchCategories["PRODUCT_RESULT"] = "product_result";
42
+ WebSearchCategories["PRODUCT_SITES"] = "product_sites";
43
+ WebSearchCategories["QUESTIONS_AND_ANSWERS"] = "questions_and_answers";
44
+ WebSearchCategories["RECIPES_RESULTS"] = "recipes_results";
45
+ WebSearchCategories["RELATED_BRANDS"] = "related_brands";
46
+ WebSearchCategories["RELATED_CATEGORIES"] = "related_categories";
47
+ WebSearchCategories["RELATED_QUESTIONS"] = "related_questions";
48
+ WebSearchCategories["RELATED_SEARCHES"] = "related_searches";
49
+ WebSearchCategories["SCHOLARLY_ARTICLES"] = "scholarly_articles";
50
+ WebSearchCategories["SHORT_VIDEOS"] = "short_videos";
51
+ WebSearchCategories["SHOWTIMES"] = "showtimes";
52
+ WebSearchCategories["SEARCH_INFORMATION"] = "search_information";
53
+ WebSearchCategories["SPORTS_RESULTS"] = "sports_results";
54
+ WebSearchCategories["THINGS_TO_KNOW"] = "things_to_know";
55
+ WebSearchCategories["TOP_INSIGHTS"] = "top_insights";
56
+ WebSearchCategories["TOP_SIGHTS"] = "top_sights";
57
+ WebSearchCategories["TOP_STORIES"] = "top_stories";
58
+ WebSearchCategories["TWITTER_RESULTS"] = "twitter_results";
59
+ WebSearchCategories["VISUAL_STORIES"] = "visual_stories";
60
+ })(WebSearchCategories || (exports.WebSearchCategories = WebSearchCategories = {}));
61
+ // Configuration constants
62
+ const MAX_LIMIT = 20;
63
+ const DEFAULT_LIMIT = 10;
64
+ exports.webSearch = (0, pieces_framework_1.createAction)({
65
+ name: 'web_search',
66
+ displayName: 'Web Search',
67
+ description: 'Search the web for information using Google with category-specific results.',
68
+ props: {
69
+ query: pieces_framework_1.Property.ShortText({
70
+ displayName: 'Search Query',
71
+ description: 'The query to search for',
72
+ required: true,
73
+ }),
74
+ category: pieces_framework_1.Property.StaticDropdown({
75
+ displayName: 'Search Category',
76
+ description: 'Category to search the web for (e.g., ads, local_results, broaden_searches, twitter_results, top_stories, etc.)',
77
+ required: true,
78
+ defaultValue: WebSearchCategories.ORGANIC_RESULTS,
79
+ options: {
80
+ options: [
81
+ { label: 'AI Overview', value: WebSearchCategories.AI_OVERVIEW },
82
+ { label: 'Ads', value: WebSearchCategories.ADS },
83
+ { label: 'Answer Box', value: WebSearchCategories.ANSWER_BOX },
84
+ { label: 'Available On', value: WebSearchCategories.AVAILABLE_ON },
85
+ { label: 'Broaden Searches', value: WebSearchCategories.BROADEN_SEARCHES },
86
+ { label: 'Buying Guide', value: WebSearchCategories.BUYING_GUIDE },
87
+ { label: 'Complementary Results', value: WebSearchCategories.COMPLEMENTARY_RESULTS },
88
+ { label: 'DMCA Messages', value: WebSearchCategories.DMCA_MESSAGES },
89
+ { label: 'Discover More Places', value: WebSearchCategories.DISCOVER_MORE_PLACES },
90
+ { label: 'Discussions and Forums', value: WebSearchCategories.DISCUSSIONS_AND_FORUMS },
91
+ { label: 'Episode Guide', value: WebSearchCategories.EPISODE_GUIDE },
92
+ { label: 'Events Results', value: WebSearchCategories.EVENTS_RESULTS },
93
+ { label: 'Find Results On', value: WebSearchCategories.FIND_RESULTS_ON },
94
+ { label: 'Grammar Check', value: WebSearchCategories.GRAMMAR_CHECK },
95
+ { label: 'Immersive Products', value: WebSearchCategories.IMMERSIVE_PRODUCTS },
96
+ { label: 'Inline Images', value: WebSearchCategories.INLINE_IMAGES },
97
+ { label: 'Shopping Results', value: WebSearchCategories.SHOPPING_RESULTS },
98
+ { label: 'Inline Videos', value: WebSearchCategories.INLINE_VIDEOS },
99
+ { label: 'Jobs Results', value: WebSearchCategories.JOBS_RESULTS },
100
+ { label: 'Knowledge Graph', value: WebSearchCategories.KNOWLEDGE_GRAPH },
101
+ { label: 'Latest Posts', value: WebSearchCategories.LATEST_POSTS },
102
+ { label: 'Local Ads', value: WebSearchCategories.LOCAL_ADS },
103
+ { label: 'Local News', value: WebSearchCategories.LOCAL_NEWS },
104
+ { label: 'Local Map', value: WebSearchCategories.LOCAL_MAP },
105
+ { label: 'Menu Highlights', value: WebSearchCategories.MENU_HIGHLIGHTS },
106
+ { label: 'News Results', value: WebSearchCategories.NEWS_RESULTS },
107
+ { label: 'Nutrition Information', value: WebSearchCategories.NUTRITION_INFORMATION },
108
+ { label: 'Organic Results', value: WebSearchCategories.ORGANIC_RESULTS },
109
+ { label: 'Perspectives', value: WebSearchCategories.PERSPECTIVES },
110
+ { label: 'Places Sites', value: WebSearchCategories.PLACES_SITES },
111
+ { label: 'Popular Destinations', value: WebSearchCategories.POPULAR_DESTINATIONS },
112
+ { label: 'Product Result', value: WebSearchCategories.PRODUCT_RESULT },
113
+ { label: 'Product Sites', value: WebSearchCategories.PRODUCT_SITES },
114
+ { label: 'Questions and Answers', value: WebSearchCategories.QUESTIONS_AND_ANSWERS },
115
+ { label: 'Recipes Results', value: WebSearchCategories.RECIPES_RESULTS },
116
+ { label: 'Related Brands', value: WebSearchCategories.RELATED_BRANDS },
117
+ { label: 'Related Categories', value: WebSearchCategories.RELATED_CATEGORIES },
118
+ { label: 'Related Questions', value: WebSearchCategories.RELATED_QUESTIONS },
119
+ { label: 'Related Searches', value: WebSearchCategories.RELATED_SEARCHES },
120
+ { label: 'Scholarly Articles', value: WebSearchCategories.SCHOLARLY_ARTICLES },
121
+ { label: 'Short Videos', value: WebSearchCategories.SHORT_VIDEOS },
122
+ { label: 'Showtimes', value: WebSearchCategories.SHOWTIMES },
123
+ { label: 'Search Information', value: WebSearchCategories.SEARCH_INFORMATION },
124
+ { label: 'Sports Results', value: WebSearchCategories.SPORTS_RESULTS },
125
+ { label: 'Things to Know', value: WebSearchCategories.THINGS_TO_KNOW },
126
+ { label: 'Top Insights', value: WebSearchCategories.TOP_INSIGHTS },
127
+ { label: 'Top Sights', value: WebSearchCategories.TOP_SIGHTS },
128
+ { label: 'Top Stories', value: WebSearchCategories.TOP_STORIES },
129
+ { label: 'Twitter Results', value: WebSearchCategories.TWITTER_RESULTS },
130
+ { label: 'Visual Stories', value: WebSearchCategories.VISUAL_STORIES },
131
+ ],
132
+ },
133
+ }),
134
+ location: pieces_framework_1.Property.ShortText({
135
+ displayName: 'Location',
136
+ description: 'Location for the search to originate from (optional)',
137
+ required: false,
138
+ }),
139
+ start: pieces_framework_1.Property.Number({
140
+ displayName: 'Start Index',
141
+ description: 'Start index for paginated results (optional)',
142
+ required: false,
143
+ defaultValue: 0,
144
+ }),
145
+ num: pieces_framework_1.Property.Number({
146
+ displayName: 'Number of Results',
147
+ description: `Limit the number of results (max ${MAX_LIMIT}, default ${DEFAULT_LIMIT})`,
148
+ required: false,
149
+ defaultValue: DEFAULT_LIMIT,
150
+ }),
151
+ },
152
+ run(context) {
153
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
154
+ const { query, category, location, start, num } = context.propsValue;
155
+ // Validate category
156
+ if (!Object.values(WebSearchCategories).includes(category)) {
157
+ return {
158
+ success: false,
159
+ error: `Invalid category: ${category}`,
160
+ validCategories: Object.values(WebSearchCategories),
161
+ };
162
+ }
163
+ // Validate and set number of results
164
+ let resultLimit = num || DEFAULT_LIMIT;
165
+ if (resultLimit > MAX_LIMIT) {
166
+ resultLimit = MAX_LIMIT;
167
+ }
168
+ else if (resultLimit < 0) {
169
+ resultLimit = DEFAULT_LIMIT;
170
+ }
171
+ // Get API key
172
+ const apiKey = yield (0, common_1.getSerpApiKey)(context);
173
+ if (!apiKey) {
174
+ return {
175
+ success: false,
176
+ error: 'No SerpAPI key available. Please configure a connection or contact support.',
177
+ };
178
+ }
179
+ try {
180
+ // Build search parameters
181
+ const params = {
182
+ q: query,
183
+ engine: 'google',
184
+ start: start || 0,
185
+ num: resultLimit,
186
+ api_key: apiKey,
187
+ };
188
+ // Add category-specific parameters
189
+ if (category === WebSearchCategories.NEWS_RESULTS) {
190
+ params['tbm'] = 'nws';
191
+ }
192
+ else if (category === WebSearchCategories.LOCAL_NEWS) {
193
+ params['tbm'] = 'lcl';
194
+ }
195
+ // Add location if provided
196
+ if (location) {
197
+ params['location'] = location;
198
+ }
199
+ // Build URL with query parameters
200
+ const url = new URL('https://serpapi.com/search');
201
+ Object.entries(params).forEach(([key, value]) => {
202
+ if (value !== undefined && value !== null) {
203
+ url.searchParams.append(key, String(value));
204
+ }
205
+ });
206
+ const response = yield fetch(url.toString(), {
207
+ method: 'GET',
208
+ headers: {
209
+ 'Content-Type': 'application/json',
210
+ },
211
+ });
212
+ if (!response.ok) {
213
+ throw new Error(`SerpAPI request failed: ${response.status} ${response.statusText}`);
214
+ }
215
+ const results = yield response.json();
216
+ // Extract category-specific results
217
+ const categoryResults = results[category] || [];
218
+ // If no results for specific category, fallback to organic results
219
+ const finalResults = categoryResults.length > 0
220
+ ? categoryResults
221
+ : results[WebSearchCategories.ORGANIC_RESULTS] || [];
222
+ return {
223
+ success: true,
224
+ category,
225
+ results: finalResults,
226
+ totalResults: finalResults.length,
227
+ searchMetadata: results.search_metadata,
228
+ searchInformation: results.search_information,
229
+ query,
230
+ location,
231
+ start: start || 0,
232
+ num: resultLimit,
233
+ };
234
+ }
235
+ catch (error) {
236
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
237
+ return {
238
+ success: false,
239
+ error: errorMessage,
240
+ errorType: error instanceof Error ? error.constructor.name : 'UnknownError',
241
+ category,
242
+ query,
243
+ location,
244
+ start: start || 0,
245
+ num: resultLimit,
246
+ };
247
+ }
248
+ });
249
+ },
250
+ });
251
+ //# sourceMappingURL=web-search.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-search.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/custom/web/src/lib/actions/web-search.ts"],"names":[],"mappings":";;;;AAAA,qEAAuE;AACvE,sCAAyC;AAEzC,gEAAgE;AAChE,IAAY,mBAmDX;AAnDD,WAAY,mBAAmB;IAC7B,kDAA2B,CAAA;IAC3B,kCAAW,CAAA;IACX,gDAAyB,CAAA;IACzB,oDAA6B,CAAA;IAC7B,4DAAqC,CAAA;IACrC,oDAA6B,CAAA;IAC7B,sEAA+C,CAAA;IAC/C,sDAA+B,CAAA;IAC/B,oEAA6C,CAAA;IAC7C,wEAAiD,CAAA;IACjD,sDAA+B,CAAA;IAC/B,wDAAiC,CAAA;IACjC,0DAAmC,CAAA;IACnC,sDAA+B,CAAA;IAC/B,gEAAyC,CAAA;IACzC,sDAA+B,CAAA;IAC/B,4DAAqC,CAAA;IACrC,sDAA+B,CAAA;IAC/B,oDAA6B,CAAA;IAC7B,0DAAmC,CAAA;IACnC,oDAA6B,CAAA;IAC7B,8CAAuB,CAAA;IACvB,gDAAyB,CAAA;IACzB,8CAAuB,CAAA;IACvB,0DAAmC,CAAA;IACnC,oDAA6B,CAAA;IAC7B,sEAA+C,CAAA;IAC/C,0DAAmC,CAAA;IACnC,oDAA6B,CAAA;IAC7B,oDAA6B,CAAA;IAC7B,oEAA6C,CAAA;IAC7C,wDAAiC,CAAA;IACjC,sDAA+B,CAAA;IAC/B,sEAA+C,CAAA;IAC/C,0DAAmC,CAAA;IACnC,wDAAiC,CAAA;IACjC,gEAAyC,CAAA;IACzC,8DAAuC,CAAA;IACvC,4DAAqC,CAAA;IACrC,gEAAyC,CAAA;IACzC,oDAA6B,CAAA;IAC7B,8CAAuB,CAAA;IACvB,gEAAyC,CAAA;IACzC,wDAAiC,CAAA;IACjC,wDAAiC,CAAA;IACjC,oDAA6B,CAAA;IAC7B,gDAAyB,CAAA;IACzB,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,YAAY,GAAG,eAAe,CAAC,MAAM,GAAG,CAAC;oBAC7C,CAAC,CAAC,eAAe;oBACjB,CAAC,CAAC,OAAO,CAAC,mBAAmB,CAAC,eAAe,CAAC,IAAI,EAAE,CAAA;gBAEtD,OAAO;oBACL,OAAO,EAAE,IAAI;oBACb,QAAQ;oBACR,OAAO,EAAE,YAAY;oBACrB,YAAY,EAAE,YAAY,CAAC,MAAM;oBACjC,cAAc,EAAE,OAAO,CAAC,eAAe;oBACvC,iBAAiB,EAAE,OAAO,CAAC,kBAAkB;oBAC7C,KAAK;oBACL,QAAQ;oBACR,KAAK,EAAE,KAAK,IAAI,CAAC;oBACjB,GAAG,EAAE,WAAW;iBACjB,CAAA;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,wBAAwB,CAAA;gBAEtF,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,YAAY;oBACnB,SAAS,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc;oBAC3E,QAAQ;oBACR,KAAK;oBACL,QAAQ;oBACR,KAAK,EAAE,KAAK,IAAI,CAAC;oBACjB,GAAG,EAAE,WAAW;iBACjB,CAAA;YACH,CAAC;QACH,CAAC;KAAA;CACF,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ export declare const youtubeProcessor: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").PieceAuthProperty, {
2
+ youtubeUrl: import("@activepieces/pieces-framework").ShortTextProperty<true>;
3
+ prompt: import("@activepieces/pieces-framework").LongTextProperty<true>;
4
+ geminiModel: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
5
+ }>;
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.youtubeProcessor = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
6
+ const common_1 = require("../common");
7
+ exports.youtubeProcessor = (0, pieces_framework_1.createAction)({
8
+ name: 'youtube_processor',
9
+ displayName: 'YouTube Video Processor',
10
+ description: 'Process YouTube videos using Google Gemini AI model to analyze content.',
11
+ props: {
12
+ youtubeUrl: pieces_framework_1.Property.ShortText({
13
+ displayName: 'YouTube URL',
14
+ description: 'YouTube video URL to process',
15
+ required: true,
16
+ }),
17
+ prompt: pieces_framework_1.Property.LongText({
18
+ displayName: 'Prompt',
19
+ description: 'The prompt, question, or instruction to be applied to the video',
20
+ required: true,
21
+ }),
22
+ geminiModel: pieces_framework_1.Property.StaticDropdown({
23
+ displayName: 'Gemini Model',
24
+ description: 'The Gemini model to use for processing',
25
+ required: true,
26
+ defaultValue: 'gemini-2.0-flash',
27
+ options: {
28
+ options: [
29
+ { label: 'Gemini 2.0 Flash', value: 'gemini-2.0-flash' },
30
+ { label: 'Gemini 2.0 Flash Lite', value: 'gemini-2.0-flash-lite' },
31
+ { label: 'Gemini 1.5 Flash', value: 'gemini-1.5-flash' },
32
+ { label: 'Gemini 1.5 Pro', value: 'gemini-1.5-pro' },
33
+ ],
34
+ },
35
+ }),
36
+ },
37
+ run(context) {
38
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
39
+ const { youtubeUrl, prompt, geminiModel } = context.propsValue;
40
+ // Validate YouTube URL
41
+ if (!isValidYouTubeUrl(youtubeUrl)) {
42
+ return {
43
+ success: false,
44
+ errorType: 'InvalidUrl',
45
+ error: `Invalid YouTube URL: ${youtubeUrl}`,
46
+ };
47
+ }
48
+ if (!(prompt === null || prompt === void 0 ? void 0 : prompt.trim())) {
49
+ return {
50
+ success: false,
51
+ errorType: 'InvalidPrompt',
52
+ error: 'Prompt cannot be empty',
53
+ };
54
+ }
55
+ // Get API key with automatic fallback to Skillful defaults
56
+ const apiKey = yield (0, common_1.getGoogleApiKey)(context);
57
+ if (!apiKey) {
58
+ return {
59
+ success: false,
60
+ errorType: 'MissingApiKey',
61
+ error: 'No Google AI API key available. Please configure a connection or contact support.',
62
+ };
63
+ }
64
+ try {
65
+ // Process video using Gemini
66
+ const result = yield processVideoWithGemini(apiKey, geminiModel, prompt, youtubeUrl);
67
+ return {
68
+ success: true,
69
+ status: 'success',
70
+ result: result.text,
71
+ youtubeUrl,
72
+ prompt,
73
+ raw: result.raw,
74
+ };
75
+ }
76
+ catch (error) {
77
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
78
+ return {
79
+ success: false,
80
+ status: 'error',
81
+ errorType: error instanceof Error ? error.constructor.name : 'UnknownError',
82
+ error: errorMessage,
83
+ youtubeUrl,
84
+ prompt,
85
+ };
86
+ }
87
+ });
88
+ },
89
+ });
90
+ // Helper function to validate YouTube URL
91
+ function isValidYouTubeUrl(url) {
92
+ try {
93
+ const urlObj = new URL(url);
94
+ const hostname = urlObj.hostname.toLowerCase();
95
+ // Check if it's a YouTube domain
96
+ if (!hostname.includes('youtube.com') && !hostname.includes('youtu.be')) {
97
+ return false;
98
+ }
99
+ // Basic URL structure validation
100
+ if (!urlObj.protocol || !['http:', 'https:'].includes(urlObj.protocol)) {
101
+ return false;
102
+ }
103
+ return true;
104
+ }
105
+ catch (_a) {
106
+ return false;
107
+ }
108
+ }
109
+ // Helper function to process video with Gemini
110
+ function processVideoWithGemini(apiKey, model, prompt, youtubeUrl) {
111
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
112
+ var _a, _b, _c, _d;
113
+ const requestBody = {
114
+ contents: [{
115
+ parts: [
116
+ { text: prompt },
117
+ {
118
+ fileData: {
119
+ fileUri: youtubeUrl,
120
+ mimeType: 'video/mp4', // YouTube videos are typically MP4
121
+ }
122
+ }
123
+ ]
124
+ }],
125
+ generationConfig: {
126
+ temperature: 0.7,
127
+ topK: 32,
128
+ topP: 1,
129
+ maxOutputTokens: 4096,
130
+ }
131
+ };
132
+ const response = yield fetch(`https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent?key=${apiKey}`, {
133
+ method: 'POST',
134
+ headers: {
135
+ 'Content-Type': 'application/json',
136
+ },
137
+ body: JSON.stringify(requestBody),
138
+ });
139
+ if (!response.ok) {
140
+ let errorText = `${response.status} ${response.statusText}`;
141
+ try {
142
+ const errorBody = yield response.text();
143
+ if (errorBody) {
144
+ errorText += ` - ${errorBody}`;
145
+ }
146
+ }
147
+ catch (_e) {
148
+ // Ignore error reading response body
149
+ }
150
+ throw new Error(`Failed to generate content: ${errorText}`);
151
+ }
152
+ const result = yield response.json();
153
+ // Handle safety ratings or blocked content
154
+ if ((_a = result.promptFeedback) === null || _a === void 0 ? void 0 : _a.blockReason) {
155
+ throw new Error(`Content blocked: ${result.promptFeedback.blockReason}`);
156
+ }
157
+ if (!result.candidates || result.candidates.length === 0) {
158
+ throw new Error('No content generated by the model');
159
+ }
160
+ const candidate = result.candidates[0];
161
+ // Check if content was blocked
162
+ if (candidate.finishReason === 'SAFETY') {
163
+ throw new Error('Content generation blocked due to safety concerns');
164
+ }
165
+ if (!((_d = (_c = (_b = candidate.content) === null || _b === void 0 ? void 0 : _b.parts) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.text)) {
166
+ throw new Error('Empty or invalid response from the model');
167
+ }
168
+ return {
169
+ text: candidate.content.parts[0].text,
170
+ raw: result
171
+ };
172
+ });
173
+ }
174
+ //# sourceMappingURL=youtube-processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"youtube-processor.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/custom/web/src/lib/actions/youtube-processor.ts"],"names":[],"mappings":";;;;AAAA,qEAAuE;AACvE,sCAA2C;AAE9B,QAAA,gBAAgB,GAAG,IAAA,+BAAY,EAAC;IAC3C,IAAI,EAAE,mBAAmB;IACzB,WAAW,EAAE,yBAAyB;IACtC,WAAW,EAAE,yEAAyE;IACtF,KAAK,EAAE;QAC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youtubeSearch: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").PieceAuthProperty, {
2
+ query: import("@activepieces/pieces-framework").ShortTextProperty<true>;
3
+ start: import("@activepieces/pieces-framework").NumberProperty<false>;
4
+ limit: import("@activepieces/pieces-framework").NumberProperty<false>;
5
+ }>;
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.youtubeSearch = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
6
+ const common_1 = require("../common");
7
+ // Configuration constants
8
+ const MAX_LIMIT = 20;
9
+ const DEFAULT_LIMIT = 10;
10
+ exports.youtubeSearch = (0, pieces_framework_1.createAction)({
11
+ name: 'youtube_search',
12
+ displayName: 'YouTube Search',
13
+ description: 'Search for videos on YouTube and return structured results.',
14
+ props: {
15
+ query: pieces_framework_1.Property.ShortText({
16
+ displayName: 'Search Query',
17
+ description: 'The query to search for on YouTube',
18
+ required: true,
19
+ }),
20
+ start: pieces_framework_1.Property.Number({
21
+ displayName: 'Start Index',
22
+ description: 'Start index for paginated results (optional)',
23
+ required: false,
24
+ defaultValue: 0,
25
+ }),
26
+ limit: pieces_framework_1.Property.Number({
27
+ displayName: 'Number of Results',
28
+ description: `Limit the number of results (max ${MAX_LIMIT}, default ${DEFAULT_LIMIT})`,
29
+ required: false,
30
+ defaultValue: DEFAULT_LIMIT,
31
+ }),
32
+ },
33
+ run(context) {
34
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
35
+ var _a;
36
+ const { query, start, limit } = context.propsValue;
37
+ // Validate and set number of results
38
+ let resultLimit = limit || DEFAULT_LIMIT;
39
+ if (resultLimit > MAX_LIMIT) {
40
+ resultLimit = MAX_LIMIT;
41
+ }
42
+ else if (resultLimit < 0) {
43
+ resultLimit = DEFAULT_LIMIT;
44
+ }
45
+ // Get API key with automatic fallback
46
+ const apiKey = yield (0, common_1.getSerpApiKey)(context);
47
+ if (!apiKey) {
48
+ return {
49
+ success: false,
50
+ error: 'No SerpAPI key available. Please configure a connection or contact support.',
51
+ };
52
+ }
53
+ try {
54
+ const allVideoResults = [];
55
+ let nextPageToken = null;
56
+ const startIndex = start || 0;
57
+ // Fetch results with pagination
58
+ while (true) {
59
+ const params = {
60
+ search_query: query,
61
+ engine: 'youtube',
62
+ api_key: apiKey,
63
+ };
64
+ if (nextPageToken) {
65
+ params['sp'] = nextPageToken;
66
+ }
67
+ // Build URL with query parameters
68
+ const url = new URL('https://serpapi.com/search');
69
+ Object.entries(params).forEach(([key, value]) => {
70
+ if (value !== undefined && value !== null) {
71
+ url.searchParams.append(key, String(value));
72
+ }
73
+ });
74
+ const response = yield fetch(url.toString(), {
75
+ method: 'GET',
76
+ headers: {
77
+ 'Content-Type': 'application/json',
78
+ },
79
+ });
80
+ if (!response.ok) {
81
+ throw new Error(`SerpAPI request failed: ${response.status} ${response.statusText}`);
82
+ }
83
+ const results = yield response.json();
84
+ // Get next page token for pagination
85
+ nextPageToken = ((_a = results.pagination) === null || _a === void 0 ? void 0 : _a.next_page_token) || null;
86
+ // Add video results to our collection
87
+ const videoResults = results.video_results || [];
88
+ allVideoResults.push(...videoResults);
89
+ // Break if no more results or we have enough
90
+ if (!videoResults.length || allVideoResults.length >= startIndex + resultLimit) {
91
+ break;
92
+ }
93
+ }
94
+ // Apply start index and limit
95
+ let finalResults = [];
96
+ if (allVideoResults.length >= startIndex) {
97
+ const endIndex = Math.min(startIndex + resultLimit, allVideoResults.length);
98
+ finalResults = allVideoResults.slice(startIndex, endIndex);
99
+ }
100
+ // Extract and format fields
101
+ const extractedResults = yield extractVideoFields(finalResults);
102
+ return {
103
+ success: true,
104
+ video_results: extractedResults,
105
+ totalResults: extractedResults.length,
106
+ query,
107
+ start: startIndex,
108
+ limit: resultLimit,
109
+ hasMoreResults: nextPageToken !== null,
110
+ };
111
+ }
112
+ catch (error) {
113
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
114
+ return {
115
+ success: false,
116
+ error: errorMessage,
117
+ errorType: error instanceof Error ? error.constructor.name : 'UnknownError',
118
+ query,
119
+ start: start || 0,
120
+ limit: resultLimit,
121
+ };
122
+ }
123
+ });
124
+ },
125
+ });
126
+ // Helper function to extract video fields
127
+ function extractVideoFields(items) {
128
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
129
+ return items.map(item => {
130
+ var _a;
131
+ return ({
132
+ title: item.title || '',
133
+ link: item.link || '',
134
+ description: item.description || '',
135
+ length: item.length || '',
136
+ channel_name: ((_a = item.channel) === null || _a === void 0 ? void 0 : _a.name) || '',
137
+ thumbnail: item.thumbnail || {},
138
+ });
139
+ });
140
+ });
141
+ }
142
+ //# sourceMappingURL=youtube-search.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"youtube-search.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/custom/web/src/lib/actions/youtube-search.ts"],"names":[],"mappings":";;;;AAAA,qEAAuE;AACvE,sCAAyC;AAEzC,0BAA0B;AAC1B,MAAM,SAAS,GAAG,EAAE,CAAA;AACpB,MAAM,aAAa,GAAG,EAAE,CAAA;AAEX,QAAA,aAAa,GAAG,IAAA,+BAAY,EAAC;IACxC,IAAI,EAAE,gBAAgB;IACtB,WAAW,EAAE,gBAAgB;IAC7B,WAAW,EAAE,6DAA6D;IAC1E,KAAK,EAAE;QACL,KAAK,EAAE,2BAAQ,CAAC,SAAS,CAAC;YACxB,WAAW,EAAE,cAAc;YAC3B,WAAW,EAAE,oCAAoC;YACjD,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,KAAK,EAAE,2BAAQ,CAAC,MAAM,CAAC;YACrB,WAAW,EAAE,aAAa;YAC1B,WAAW,EAAE,8CAA8C;YAC3D,QAAQ,EAAE,KAAK;YACf,YAAY,EAAE,CAAC;SAChB,CAAC;QACF,KAAK,EAAE,2BAAQ,CAAC,MAAM,CAAC;YACrB,WAAW,EAAE,mBAAmB;YAChC,WAAW,EAAE,oCAAoC,SAAS,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AS,IAAI,EAAE;aAChC,CAAC,CAAA;SAAA,CAAC,CAAA;IACL,CAAC;CAAA"}
@@ -0,0 +1,4 @@
1
+ export declare const webAuth: import("@activepieces/pieces-framework").CustomAuthProperty<{
2
+ googleApiKey: import("@activepieces/pieces-framework").SecretTextProperty<false>;
3
+ serpApiKey: import("@activepieces/pieces-framework").SecretTextProperty<false>;
4
+ }>;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.webAuth = void 0;
4
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
5
+ exports.webAuth = pieces_framework_1.PieceAuth.CustomAuth({
6
+ description: 'Configure API keys for web actions',
7
+ required: true,
8
+ props: {
9
+ googleApiKey: pieces_framework_1.PieceAuth.SecretText({
10
+ displayName: 'Google AI API Key',
11
+ description: 'For Gemini AI models (media processing)',
12
+ required: false,
13
+ }),
14
+ serpApiKey: pieces_framework_1.PieceAuth.SecretText({
15
+ displayName: 'SerpAPI API Key',
16
+ description: 'For SerpAPI (web search and youtube search)',
17
+ required: false,
18
+ })
19
+ },
20
+ });
21
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../../../../../packages/pieces/custom/web/src/lib/auth.ts"],"names":[],"mappings":";;;AAAA,qEAA2D;AAE9C,QAAA,OAAO,GAAG,4BAAS,CAAC,UAAU,CAAC;IACxC,WAAW,EAAE,oCAAoC;IACjD,QAAQ,EAAE,IAAI;IACd,KAAK,EAAE;QACL,YAAY,EAAE,4BAAS,CAAC,UAAU,CAAC;YACjC,WAAW,EAAE,mBAAmB;YAChC,WAAW,EAAE,yCAAyC;YACtD,QAAQ,EAAE,KAAK;SAChB,CAAC;QACF,UAAU,EAAE,4BAAS,CAAC,UAAU,CAAC;YAC/B,WAAW,EAAE,iBAAiB;YAC9B,WAAW,EAAE,6CAA6C;YAC1D,QAAQ,EAAE,KAAK;SAChB,CAAC;KACH;CACJ,CAAC,CAAC"}