@memberjunction/core-actions 2.103.0 → 2.105.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config.d.ts +82 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +83 -0
- package/dist/config.js.map +1 -0
- package/dist/custom/files/base-file-storage.action.d.ts +70 -0
- package/dist/custom/files/base-file-storage.action.d.ts.map +1 -0
- package/dist/custom/files/base-file-storage.action.js +140 -0
- package/dist/custom/files/base-file-storage.action.js.map +1 -0
- package/dist/custom/files/copy-object.action.d.ts +38 -0
- package/dist/custom/files/copy-object.action.d.ts.map +1 -0
- package/dist/custom/files/copy-object.action.js +84 -0
- package/dist/custom/files/copy-object.action.js.map +1 -0
- package/dist/custom/files/create-directory.action.d.ts +34 -0
- package/dist/custom/files/create-directory.action.d.ts.map +1 -0
- package/dist/custom/files/create-directory.action.js +75 -0
- package/dist/custom/files/create-directory.action.js.map +1 -0
- package/dist/custom/files/delete-directory.action.d.ts +38 -0
- package/dist/custom/files/delete-directory.action.d.ts.map +1 -0
- package/dist/custom/files/delete-directory.action.js +82 -0
- package/dist/custom/files/delete-directory.action.js.map +1 -0
- package/dist/custom/files/delete-object.action.d.ts +34 -0
- package/dist/custom/files/delete-object.action.d.ts.map +1 -0
- package/dist/custom/files/delete-object.action.js +75 -0
- package/dist/custom/files/delete-object.action.js.map +1 -0
- package/dist/custom/files/directory-exists.action.d.ts +34 -0
- package/dist/custom/files/directory-exists.action.d.ts.map +1 -0
- package/dist/custom/files/directory-exists.action.js +75 -0
- package/dist/custom/files/directory-exists.action.js.map +1 -0
- package/dist/custom/files/get-download-url.action.d.ts +34 -0
- package/dist/custom/files/get-download-url.action.d.ts.map +1 -0
- package/dist/custom/files/get-download-url.action.js +75 -0
- package/dist/custom/files/get-download-url.action.js.map +1 -0
- package/dist/custom/files/get-metadata.action.d.ts +42 -0
- package/dist/custom/files/get-metadata.action.d.ts.map +1 -0
- package/dist/custom/files/get-metadata.action.js +95 -0
- package/dist/custom/files/get-metadata.action.js.map +1 -0
- package/dist/custom/files/get-object.action.d.ts +35 -0
- package/dist/custom/files/get-object.action.d.ts.map +1 -0
- package/dist/custom/files/get-object.action.js +80 -0
- package/dist/custom/files/get-object.action.js.map +1 -0
- package/dist/custom/files/get-upload-url.action.d.ts +35 -0
- package/dist/custom/files/get-upload-url.action.d.ts.map +1 -0
- package/dist/custom/files/get-upload-url.action.js +80 -0
- package/dist/custom/files/get-upload-url.action.js.map +1 -0
- package/dist/custom/files/index.d.ts +23 -0
- package/dist/custom/files/index.d.ts.map +1 -0
- package/dist/custom/files/index.js +39 -0
- package/dist/custom/files/index.js.map +1 -0
- package/dist/custom/files/list-objects.action.d.ts +50 -0
- package/dist/custom/files/list-objects.action.d.ts.map +1 -0
- package/dist/custom/files/list-objects.action.js +95 -0
- package/dist/custom/files/list-objects.action.js.map +1 -0
- package/dist/custom/files/move-object.action.d.ts +38 -0
- package/dist/custom/files/move-object.action.d.ts.map +1 -0
- package/dist/custom/files/move-object.action.js +84 -0
- package/dist/custom/files/move-object.action.js.map +1 -0
- package/dist/custom/files/object-exists.action.d.ts +34 -0
- package/dist/custom/files/object-exists.action.d.ts.map +1 -0
- package/dist/custom/files/object-exists.action.js +75 -0
- package/dist/custom/files/object-exists.action.js.map +1 -0
- package/dist/custom/integration/gamma-generate-presentation.action.d.ts +108 -0
- package/dist/custom/integration/gamma-generate-presentation.action.d.ts.map +1 -0
- package/dist/custom/integration/gamma-generate-presentation.action.js +315 -0
- package/dist/custom/integration/gamma-generate-presentation.action.js.map +1 -0
- package/dist/custom/web/perplexity-search.action.d.ts +98 -0
- package/dist/custom/web/perplexity-search.action.d.ts.map +1 -0
- package/dist/custom/web/perplexity-search.action.js +269 -0
- package/dist/custom/web/perplexity-search.action.js.map +1 -0
- package/dist/custom/web/web-page-content.action.d.ts +74 -27
- package/dist/custom/web/web-page-content.action.d.ts.map +1 -1
- package/dist/custom/web/web-page-content.action.js +458 -226
- package/dist/custom/web/web-page-content.action.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -1
- package/package.json +16 -10
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LoadPerplexitySearchAction = exports.PerplexitySearchAction = void 0;
|
|
13
|
+
const actions_1 = require("@memberjunction/actions");
|
|
14
|
+
const global_1 = require("@memberjunction/global");
|
|
15
|
+
const axios_1 = __importDefault(require("axios"));
|
|
16
|
+
const config_1 = require("../../config");
|
|
17
|
+
/**
|
|
18
|
+
* Action that performs AI-powered web search using Perplexity's Search API
|
|
19
|
+
* Returns comprehensive search results with citations and related questions
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // Basic search with Perplexity
|
|
24
|
+
* await runAction({
|
|
25
|
+
* ActionName: 'Perplexity Search',
|
|
26
|
+
* Params: [{
|
|
27
|
+
* Name: 'Query',
|
|
28
|
+
* Value: 'latest developments in quantum computing'
|
|
29
|
+
* }]
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // Search with specific model and parameters
|
|
33
|
+
* await runAction({
|
|
34
|
+
* ActionName: 'Perplexity Search',
|
|
35
|
+
* Params: [{
|
|
36
|
+
* Name: 'Query',
|
|
37
|
+
* Value: 'climate change research papers 2024'
|
|
38
|
+
* }, {
|
|
39
|
+
* Name: 'Model',
|
|
40
|
+
* Value: 'llama-3.1-sonar-large-128k-online'
|
|
41
|
+
* }, {
|
|
42
|
+
* Name: 'ReturnRelatedQuestions',
|
|
43
|
+
* Value: true
|
|
44
|
+
* }, {
|
|
45
|
+
* Name: 'ReturnImages',
|
|
46
|
+
* Value: true
|
|
47
|
+
* }]
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* // Search with domain filtering
|
|
51
|
+
* await runAction({
|
|
52
|
+
* ActionName: 'Perplexity Search',
|
|
53
|
+
* Params: [{
|
|
54
|
+
* Name: 'Query',
|
|
55
|
+
* Value: 'machine learning tutorials'
|
|
56
|
+
* }, {
|
|
57
|
+
* Name: 'SearchDomainFilter',
|
|
58
|
+
* Value: ['github.com', 'arxiv.org', 'medium.com']
|
|
59
|
+
* }]
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
let PerplexitySearchAction = class PerplexitySearchAction extends actions_1.BaseAction {
|
|
64
|
+
/**
|
|
65
|
+
* Executes the Perplexity AI search
|
|
66
|
+
*
|
|
67
|
+
* @param params - The action parameters containing:
|
|
68
|
+
* - Query: Search query text (required)
|
|
69
|
+
* - Model: Perplexity model to use (default: 'llama-3.1-sonar-small-128k-online')
|
|
70
|
+
* Options: llama-3.1-sonar-small-128k-online, llama-3.1-sonar-large-128k-online,
|
|
71
|
+
* llama-3.1-sonar-huge-128k-online
|
|
72
|
+
* - MaxTokens: Maximum tokens in response (default: 1000)
|
|
73
|
+
* - Temperature: Sampling temperature 0-2 (default: 0.2)
|
|
74
|
+
* - TopP: Nucleus sampling threshold (default: 0.9)
|
|
75
|
+
* - ReturnImages: Include images in results (default: false)
|
|
76
|
+
* - ReturnRelatedQuestions: Include related questions (default: false)
|
|
77
|
+
* - SearchDomainFilter: Array of domains to limit/exclude search (use '-' prefix to exclude)
|
|
78
|
+
* - SearchRecencyFilter: Filter by recency - 'day', 'week', 'month', 'year' (optional)
|
|
79
|
+
*
|
|
80
|
+
* @returns Search results with content, citations, and related questions
|
|
81
|
+
*/
|
|
82
|
+
async InternalRunAction(params) {
|
|
83
|
+
try {
|
|
84
|
+
// Get required parameters
|
|
85
|
+
const query = this.getStringParam(params, 'query');
|
|
86
|
+
if (!query) {
|
|
87
|
+
return this.createErrorResult("Query parameter is required", "MISSING_QUERY");
|
|
88
|
+
}
|
|
89
|
+
// Get API key from config (which checks mj.config.cjs then falls back to environment variable)
|
|
90
|
+
const apiConfig = (0, config_1.getApiIntegrationsConfig)();
|
|
91
|
+
const apiKey = apiConfig.perplexityApiKey;
|
|
92
|
+
if (!apiKey) {
|
|
93
|
+
return this.createErrorResult("Perplexity API key not found. Set perplexityApiKey in mj.config.cjs or PERPLEXITY_API_KEY environment variable", "MISSING_API_KEY");
|
|
94
|
+
}
|
|
95
|
+
// Get optional parameters
|
|
96
|
+
const model = this.getStringParam(params, 'model') || 'llama-3.1-sonar-small-128k-online';
|
|
97
|
+
const maxTokens = this.getNumericParam(params, 'maxtokens', 1000);
|
|
98
|
+
const temperature = this.getNumericParam(params, 'temperature', 0.2);
|
|
99
|
+
const topP = this.getNumericParam(params, 'topp', 0.9);
|
|
100
|
+
const returnImages = this.getBooleanParam(params, 'returnimages', false);
|
|
101
|
+
const returnRelatedQuestions = this.getBooleanParam(params, 'returnrelatedquestions', false);
|
|
102
|
+
const searchRecencyFilter = this.getStringParam(params, 'searchrecencyfilter');
|
|
103
|
+
// Get domain filter (can be array or comma-separated string)
|
|
104
|
+
const domainFilterParam = this.getParamValue(params, 'searchdomainfilter');
|
|
105
|
+
let searchDomainFilter;
|
|
106
|
+
if (domainFilterParam) {
|
|
107
|
+
if (Array.isArray(domainFilterParam)) {
|
|
108
|
+
searchDomainFilter = domainFilterParam;
|
|
109
|
+
}
|
|
110
|
+
else if (typeof domainFilterParam === 'string') {
|
|
111
|
+
searchDomainFilter = domainFilterParam.split(',').map(d => d.trim());
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Build request body
|
|
115
|
+
const requestBody = {
|
|
116
|
+
model,
|
|
117
|
+
messages: [
|
|
118
|
+
{
|
|
119
|
+
role: 'user',
|
|
120
|
+
content: query
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
max_tokens: maxTokens,
|
|
124
|
+
temperature,
|
|
125
|
+
top_p: topP,
|
|
126
|
+
return_images: returnImages,
|
|
127
|
+
return_related_questions: returnRelatedQuestions,
|
|
128
|
+
stream: false
|
|
129
|
+
};
|
|
130
|
+
// Add optional parameters
|
|
131
|
+
if (searchDomainFilter && searchDomainFilter.length > 0) {
|
|
132
|
+
requestBody.search_domain_filter = searchDomainFilter;
|
|
133
|
+
}
|
|
134
|
+
if (searchRecencyFilter) {
|
|
135
|
+
requestBody.search_recency_filter = searchRecencyFilter;
|
|
136
|
+
}
|
|
137
|
+
// Make API request
|
|
138
|
+
const response = await axios_1.default.post('https://api.perplexity.ai/chat/completions', requestBody, {
|
|
139
|
+
headers: {
|
|
140
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
141
|
+
'Content-Type': 'application/json'
|
|
142
|
+
},
|
|
143
|
+
timeout: 60000 // 60 second timeout
|
|
144
|
+
});
|
|
145
|
+
if (!response.data) {
|
|
146
|
+
return this.createErrorResult("Empty response from Perplexity API", "EMPTY_RESPONSE");
|
|
147
|
+
}
|
|
148
|
+
// Extract response data
|
|
149
|
+
const result = response.data;
|
|
150
|
+
const choice = result.choices?.[0];
|
|
151
|
+
const message = choice?.message;
|
|
152
|
+
const content = message?.content || '';
|
|
153
|
+
const citations = result.citations || [];
|
|
154
|
+
const images = result.images || [];
|
|
155
|
+
const relatedQuestions = result.related_questions || [];
|
|
156
|
+
// Build output data
|
|
157
|
+
const outputData = {
|
|
158
|
+
query,
|
|
159
|
+
model,
|
|
160
|
+
content,
|
|
161
|
+
citations,
|
|
162
|
+
images,
|
|
163
|
+
relatedQuestions,
|
|
164
|
+
usage: result.usage || {},
|
|
165
|
+
finishReason: choice?.finish_reason
|
|
166
|
+
};
|
|
167
|
+
// Add output parameters
|
|
168
|
+
this.addOutputParam(params, 'Content', content);
|
|
169
|
+
this.addOutputParam(params, 'Citations', citations);
|
|
170
|
+
this.addOutputParam(params, 'CitationCount', citations.length);
|
|
171
|
+
if (returnImages && images.length > 0) {
|
|
172
|
+
this.addOutputParam(params, 'Images', images);
|
|
173
|
+
this.addOutputParam(params, 'ImageCount', images.length);
|
|
174
|
+
}
|
|
175
|
+
if (returnRelatedQuestions && relatedQuestions.length > 0) {
|
|
176
|
+
this.addOutputParam(params, 'RelatedQuestions', relatedQuestions);
|
|
177
|
+
this.addOutputParam(params, 'RelatedQuestionCount', relatedQuestions.length);
|
|
178
|
+
}
|
|
179
|
+
this.addOutputParam(params, 'Usage', result.usage);
|
|
180
|
+
this.addOutputParam(params, 'SearchResultDetails', outputData);
|
|
181
|
+
return {
|
|
182
|
+
Success: true,
|
|
183
|
+
ResultCode: "SUCCESS",
|
|
184
|
+
Message: JSON.stringify(outputData, null, 2)
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
189
|
+
const status = error.response?.status;
|
|
190
|
+
const errorData = error.response?.data;
|
|
191
|
+
if (status === 401) {
|
|
192
|
+
return this.createErrorResult("Invalid Perplexity API key", "INVALID_API_KEY");
|
|
193
|
+
}
|
|
194
|
+
if (status === 429) {
|
|
195
|
+
return this.createErrorResult("Perplexity API rate limit exceeded", "RATE_LIMITED");
|
|
196
|
+
}
|
|
197
|
+
return this.createErrorResult(`Perplexity API error: ${errorData?.error?.message || error.message}`, "API_ERROR");
|
|
198
|
+
}
|
|
199
|
+
return this.createErrorResult(`Failed to perform Perplexity search: ${error instanceof Error ? error.message : String(error)}`, "SEARCH_FAILED");
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Get string parameter value
|
|
204
|
+
*/
|
|
205
|
+
getStringParam(params, paramName) {
|
|
206
|
+
const param = params.Params.find(p => p.Name.trim().toLowerCase() === paramName.toLowerCase());
|
|
207
|
+
if (param?.Value === undefined || param?.Value === null)
|
|
208
|
+
return undefined;
|
|
209
|
+
return String(param.Value);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Get parameter value (any type)
|
|
213
|
+
*/
|
|
214
|
+
getParamValue(params, paramName) {
|
|
215
|
+
const param = params.Params.find(p => p.Name.trim().toLowerCase() === paramName.toLowerCase());
|
|
216
|
+
return param?.Value;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Get boolean parameter value with default
|
|
220
|
+
*/
|
|
221
|
+
getBooleanParam(params, paramName, defaultValue = false) {
|
|
222
|
+
const param = params.Params.find(p => p.Name.trim().toLowerCase() === paramName.toLowerCase());
|
|
223
|
+
if (param?.Value === undefined || param?.Value === null)
|
|
224
|
+
return defaultValue;
|
|
225
|
+
return String(param.Value).toLowerCase() === 'true';
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Get numeric parameter value with default
|
|
229
|
+
*/
|
|
230
|
+
getNumericParam(params, paramName, defaultValue = 0) {
|
|
231
|
+
const param = params.Params.find(p => p.Name.trim().toLowerCase() === paramName.toLowerCase());
|
|
232
|
+
if (param?.Value === undefined || param?.Value === null)
|
|
233
|
+
return defaultValue;
|
|
234
|
+
const num = Number(param.Value);
|
|
235
|
+
return isNaN(num) ? defaultValue : num;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Add output parameter
|
|
239
|
+
*/
|
|
240
|
+
addOutputParam(params, name, value) {
|
|
241
|
+
params.Params.push({
|
|
242
|
+
Name: name,
|
|
243
|
+
Type: 'Output',
|
|
244
|
+
Value: value
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Create error result
|
|
249
|
+
*/
|
|
250
|
+
createErrorResult(message, code) {
|
|
251
|
+
return {
|
|
252
|
+
Success: false,
|
|
253
|
+
Message: message,
|
|
254
|
+
ResultCode: code
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
exports.PerplexitySearchAction = PerplexitySearchAction;
|
|
259
|
+
exports.PerplexitySearchAction = PerplexitySearchAction = __decorate([
|
|
260
|
+
(0, global_1.RegisterClass)(actions_1.BaseAction, "Perplexity Search")
|
|
261
|
+
], PerplexitySearchAction);
|
|
262
|
+
/**
|
|
263
|
+
* Loader function to ensure the PerplexitySearchAction class is included in the bundle.
|
|
264
|
+
*/
|
|
265
|
+
function LoadPerplexitySearchAction() {
|
|
266
|
+
// this function is a stub that is used to force the bundler to include the above class in the final bundle and not tree shake them out
|
|
267
|
+
}
|
|
268
|
+
exports.LoadPerplexitySearchAction = LoadPerplexitySearchAction;
|
|
269
|
+
//# sourceMappingURL=perplexity-search.action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"perplexity-search.action.js","sourceRoot":"","sources":["../../../src/custom/web/perplexity-search.action.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qDAAqD;AACrD,mDAAuD;AACvD,kDAA0B;AAC1B,yCAAwD;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAEI,IAAM,sBAAsB,GAA5B,MAAM,sBAAuB,SAAQ,oBAAU;IAElD;;;;;;;;;;;;;;;;;OAiBG;IACO,KAAK,CAAC,iBAAiB,CAAC,MAAuB;QACrD,IAAI,CAAC;YACD,0BAA0B;YAC1B,MAAM,KAAK,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACnD,IAAI,CAAC,KAAK,EAAE,CAAC;gBACT,OAAO,IAAI,CAAC,iBAAiB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AAC,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,SAAS,CAAC,WAAW,EAAE,CAAC,CAAC;QAC/F,IAAI,KAAK,EAAE,KAAK,KAAK,SAAS,IAAI,KAAK,EAAE,KAAK,KAAK,IAAI;YAAE,OAAO,YAAY,CAAC;QAC7E,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAChC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC;IAC3C,CAAC;IAED;;OAEG;IACK,cAAc,CAAC,MAAuB,EAAE,IAAY,EAAE,KAAc;QACxE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;YACf,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,KAAK;SACf,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACK,iBAAiB,CAAC,OAAe,EAAE,IAAY;QACnD,OAAO;YACH,OAAO,EAAE,KAAK;YACd,OAAO,EAAE,OAAO;YAChB,UAAU,EAAE,IAAI;SACnB,CAAC;IACN,CAAC;CACJ,CAAA;AA1OY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,sBAAa,EAAC,oBAAU,EAAE,mBAAmB,CAAC;GAClC,sBAAsB,CA0OlC;AAED;;GAEG;AACH,SAAgB,0BAA0B;IACtC,uIAAuI;AAC3I,CAAC;AAFD,gEAEC"}
|
|
@@ -1,35 +1,44 @@
|
|
|
1
1
|
import { ActionResultSimple, RunActionParams } from "@memberjunction/actions-base";
|
|
2
2
|
import { BaseAction } from "@memberjunction/actions";
|
|
3
3
|
/**
|
|
4
|
-
* Action that retrieves and processes web
|
|
5
|
-
* Supports
|
|
4
|
+
* Action that retrieves and processes web content in various formats
|
|
5
|
+
* Supports JSON, PDF, DOCX, XML, CSV, HTML and more - similar to Claude's web reading capabilities
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```typescript
|
|
9
|
-
* // Get
|
|
9
|
+
* // Get JSON API response
|
|
10
10
|
* await runAction({
|
|
11
11
|
* ActionName: 'Web Page Content',
|
|
12
12
|
* Params: [{
|
|
13
13
|
* Name: 'URL',
|
|
14
|
-
* Value: 'https://example.com'
|
|
14
|
+
* Value: 'https://api.example.com/data'
|
|
15
|
+
* }, {
|
|
16
|
+
* Name: 'ContentType',
|
|
17
|
+
* Value: 'json'
|
|
18
|
+
* }]
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // Get PDF content as text
|
|
22
|
+
* await runAction({
|
|
23
|
+
* ActionName: 'Web Page Content',
|
|
24
|
+
* Params: [{
|
|
25
|
+
* Name: 'URL',
|
|
26
|
+
* Value: 'https://example.com/document.pdf'
|
|
15
27
|
* }, {
|
|
16
28
|
* Name: 'ContentType',
|
|
17
29
|
* Value: 'text'
|
|
18
30
|
* }]
|
|
19
31
|
* });
|
|
20
32
|
*
|
|
21
|
-
* // Get
|
|
33
|
+
* // Get DOCX content as markdown
|
|
22
34
|
* await runAction({
|
|
23
35
|
* ActionName: 'Web Page Content',
|
|
24
36
|
* Params: [{
|
|
25
37
|
* Name: 'URL',
|
|
26
|
-
* Value: 'https://
|
|
38
|
+
* Value: 'https://example.com/document.docx'
|
|
27
39
|
* }, {
|
|
28
40
|
* Name: 'ContentType',
|
|
29
41
|
* Value: 'markdown'
|
|
30
|
-
* }, {
|
|
31
|
-
* Name: 'ExtractMainContent',
|
|
32
|
-
* Value: true
|
|
33
42
|
* }]
|
|
34
43
|
* });
|
|
35
44
|
* ```
|
|
@@ -37,29 +46,71 @@ import { BaseAction } from "@memberjunction/actions";
|
|
|
37
46
|
export declare class WebPageContentAction extends BaseAction {
|
|
38
47
|
private readonly MAX_CONTENT_SIZE;
|
|
39
48
|
private readonly MAX_IMAGE_SIZE;
|
|
49
|
+
private turndown;
|
|
50
|
+
constructor();
|
|
40
51
|
/**
|
|
41
|
-
* Executes
|
|
52
|
+
* Executes web content retrieval and processing
|
|
42
53
|
*
|
|
43
54
|
* @param params - The action parameters containing:
|
|
44
|
-
* - URL: Web
|
|
45
|
-
* - ContentType: Output format - 'text', 'html', 'markdown', 'json' (default: '
|
|
55
|
+
* - URL: Web resource URL to fetch (required)
|
|
56
|
+
* - ContentType: Output format - 'auto', 'text', 'html', 'markdown', 'json' (default: 'auto')
|
|
46
57
|
* - ExtractMainContent: Extract only main content vs full page (default: false)
|
|
47
|
-
* - IncludeMetadata: Include
|
|
48
|
-
* - MaxContentLength: Maximum content length to return (default:
|
|
58
|
+
* - IncludeMetadata: Include resource metadata in response (default: true)
|
|
59
|
+
* - MaxContentLength: Maximum content length to return (default: 100000 chars)
|
|
49
60
|
*
|
|
50
|
-
* @returns Processed
|
|
61
|
+
* @returns Processed content in the specified format
|
|
51
62
|
*/
|
|
52
63
|
protected InternalRunAction(params: RunActionParams): Promise<ActionResultSimple>;
|
|
53
64
|
/**
|
|
54
|
-
*
|
|
65
|
+
* Detects content type from response headers and URL
|
|
66
|
+
*/
|
|
67
|
+
private detectContentType;
|
|
68
|
+
/**
|
|
69
|
+
* Processes response based on detected content type
|
|
70
|
+
*/
|
|
71
|
+
private processResponse;
|
|
72
|
+
/**
|
|
73
|
+
* Infers best output type based on detected content type
|
|
74
|
+
*/
|
|
75
|
+
private inferOutputType;
|
|
76
|
+
/**
|
|
77
|
+
* Process JSON content
|
|
55
78
|
*/
|
|
56
|
-
private
|
|
79
|
+
private processJson;
|
|
57
80
|
/**
|
|
58
|
-
*
|
|
81
|
+
* Process PDF content
|
|
59
82
|
*/
|
|
60
|
-
private
|
|
83
|
+
private processPdf;
|
|
61
84
|
/**
|
|
62
|
-
*
|
|
85
|
+
* Process DOCX content
|
|
86
|
+
*/
|
|
87
|
+
private processDocx;
|
|
88
|
+
/**
|
|
89
|
+
* Process CSV content
|
|
90
|
+
*/
|
|
91
|
+
private processCsv;
|
|
92
|
+
/**
|
|
93
|
+
* Process XML content
|
|
94
|
+
*/
|
|
95
|
+
private processXml;
|
|
96
|
+
/**
|
|
97
|
+
* Process HTML content
|
|
98
|
+
*/
|
|
99
|
+
private processHtml;
|
|
100
|
+
/**
|
|
101
|
+
* Process image content
|
|
102
|
+
*/
|
|
103
|
+
private processImage;
|
|
104
|
+
/**
|
|
105
|
+
* Process plain text content
|
|
106
|
+
*/
|
|
107
|
+
private processText;
|
|
108
|
+
/**
|
|
109
|
+
* Extracts HTML metadata
|
|
110
|
+
*/
|
|
111
|
+
private extractHtmlMetadata;
|
|
112
|
+
/**
|
|
113
|
+
* Attempts to extract main content from HTML
|
|
63
114
|
*/
|
|
64
115
|
private extractMainContent;
|
|
65
116
|
/**
|
|
@@ -67,17 +118,13 @@ export declare class WebPageContentAction extends BaseAction {
|
|
|
67
118
|
*/
|
|
68
119
|
private htmlToText;
|
|
69
120
|
/**
|
|
70
|
-
*
|
|
71
|
-
*/
|
|
72
|
-
private htmlToMarkdown;
|
|
73
|
-
/**
|
|
74
|
-
* Extracts basic document structure
|
|
121
|
+
* Extracts document structure from HTML
|
|
75
122
|
*/
|
|
76
123
|
private extractStructure;
|
|
77
124
|
/**
|
|
78
|
-
*
|
|
125
|
+
* Converts CSV data to markdown table
|
|
79
126
|
*/
|
|
80
|
-
private
|
|
127
|
+
private csvToMarkdownTable;
|
|
81
128
|
/**
|
|
82
129
|
* Truncates content to specified length
|
|
83
130
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-page-content.action.d.ts","sourceRoot":"","sources":["../../../src/custom/web/web-page-content.action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"web-page-content.action.d.ts","sourceRoot":"","sources":["../../../src/custom/web/web-page-content.action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAUrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,qBACa,oBAAqB,SAAQ,UAAU;IAEhD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAoB;IACrD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAmB;IAClD,OAAO,CAAC,QAAQ,CAAkB;;IAWlC;;;;;;;;;;;OAWG;cACa,iBAAiB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA2GvF;;OAEG;IACH,OAAO,CAAC,iBAAiB;IA6BzB;;OAEG;YACW,eAAe;IAuC7B;;OAEG;IACH,OAAO,CAAC,eAAe;IAgBvB;;OAEG;YACW,WAAW;IA6BzB;;OAEG;YACW,UAAU;IAgCxB;;OAEG;YACW,WAAW;IAsCzB;;OAEG;YACW,UAAU;IAgCxB;;OAEG;YACW,UAAU;IAiCxB;;OAEG;YACW,WAAW;IA8CzB;;OAEG;YACW,YAAY;IA8B1B;;OAEG;YACW,WAAW;IAoBzB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IA8B3B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAsB1B;;OAEG;IACH,OAAO,CAAC,UAAU;IAUlB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IA+BxB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAwB1B;;OAEG;IACH,OAAO,CAAC,eAAe;CAM1B;AAED;;GAEG;AACH,wBAAgB,wBAAwB,SAEvC"}
|