@memberjunction/core-actions 6.1.4 → 6.2.0-edge.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.
- package/dist/config.d.ts +74 -10
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +48 -9
- package/dist/config.js.map +1 -1
- package/dist/custom/ai/base-find-actions.action.js +6 -6
- package/dist/custom/ai/base-find-agents.action.js +6 -6
- package/dist/custom/ai/find-candidate-agents.action.js +2 -2
- package/dist/custom/ai/generate-image.action.d.ts +13 -1
- package/dist/custom/ai/generate-image.action.d.ts.map +1 -1
- package/dist/custom/ai/generate-image.action.js +25 -13
- package/dist/custom/ai/generate-image.action.js.map +1 -1
- package/dist/custom/ai/semantic-entity-search.helper.d.ts +6 -0
- package/dist/custom/ai/semantic-entity-search.helper.d.ts.map +1 -1
- package/dist/custom/ai/semantic-entity-search.helper.js +16 -4
- package/dist/custom/ai/semantic-entity-search.helper.js.map +1 -1
- package/dist/custom/data/search-query-catalog.action.js +2 -2
- package/dist/custom/integration/api-rate-limiter.action.d.ts +4 -0
- package/dist/custom/integration/api-rate-limiter.action.d.ts.map +1 -1
- package/dist/custom/integration/api-rate-limiter.action.js +10 -2
- package/dist/custom/integration/api-rate-limiter.action.js.map +1 -1
- package/dist/custom/integration/gamma-generate-presentation.action.js +2 -2
- package/dist/custom/integration/integration-action-executor.d.ts +22 -22
- package/dist/custom/integration/integration-action-executor.js +83 -83
- package/dist/custom/interactive-forms/_shared.d.ts +69 -0
- package/dist/custom/interactive-forms/_shared.d.ts.map +1 -1
- package/dist/custom/interactive-forms/_shared.js +118 -38
- package/dist/custom/interactive-forms/_shared.js.map +1 -1
- package/dist/custom/interactive-forms/activate-interactive-form-version.action.js +25 -25
- package/dist/custom/interactive-forms/create-interactive-form.action.js +22 -22
- package/dist/custom/interactive-forms/modify-interactive-form.action.js +35 -35
- package/dist/custom/interactive-forms/revert-interactive-form.action.js +32 -32
- package/dist/custom/lists/_action-helpers.d.ts +10 -0
- package/dist/custom/lists/_action-helpers.d.ts.map +1 -1
- package/dist/custom/lists/_action-helpers.js +26 -6
- package/dist/custom/lists/_action-helpers.js.map +1 -1
- package/dist/custom/lists/add-view-results-to-list.action.js +8 -8
- package/dist/custom/lists/bulk-update-list-item-status.action.js +8 -8
- package/dist/custom/lists/compose-lists.action.js +14 -14
- package/dist/custom/lists/invite-to-list.action.js +10 -10
- package/dist/custom/lists/materialize-list-from-view.action.js +13 -13
- package/dist/custom/lists/move-list-members.action.js +12 -12
- package/dist/custom/lists/refresh-list-from-source.action.js +8 -8
- package/dist/custom/lists/resolve-audience.action.js +7 -7
- package/dist/custom/lists/revoke-list-invitation.action.js +3 -3
- package/dist/custom/lists/share-list.action.js +8 -8
- package/dist/custom/lists/unshare-list.action.js +3 -3
- package/dist/custom/utilities/address-services.action.js +2 -2
- package/dist/custom/utilities/artifact-builder-service.d.ts +16 -16
- package/dist/custom/utilities/artifact-builder-service.js +39 -39
- package/dist/custom/utilities/artifact-builder-service.js.map +1 -1
- package/dist/custom/utilities/base-file-handler.d.ts.map +1 -1
- package/dist/custom/utilities/base-file-handler.js +4 -2
- package/dist/custom/utilities/base-file-handler.js.map +1 -1
- package/dist/custom/utilities/docx-renderer.d.ts +17 -11
- package/dist/custom/utilities/docx-renderer.d.ts.map +1 -1
- package/dist/custom/utilities/docx-renderer.js +60 -48
- package/dist/custom/utilities/docx-renderer.js.map +1 -1
- package/dist/custom/utilities/json-param-helper.d.ts +6 -0
- package/dist/custom/utilities/json-param-helper.d.ts.map +1 -1
- package/dist/custom/utilities/json-param-helper.js +16 -4
- package/dist/custom/utilities/json-param-helper.js.map +1 -1
- package/dist/custom/utilities/pdf-renderer.d.ts +13 -7
- package/dist/custom/utilities/pdf-renderer.d.ts.map +1 -1
- package/dist/custom/utilities/pdf-renderer.js +27 -15
- package/dist/custom/utilities/pdf-renderer.js.map +1 -1
- package/dist/custom/utilities/xlsx-renderer.d.ts +19 -11
- package/dist/custom/utilities/xlsx-renderer.d.ts.map +1 -1
- package/dist/custom/utilities/xlsx-renderer.js +55 -39
- package/dist/custom/utilities/xlsx-renderer.js.map +1 -1
- package/dist/custom/visualization/create-svg-chart.action.js +23 -23
- package/dist/custom/visualization/create-svg-diagram.action.js +10 -10
- package/dist/custom/visualization/create-svg-infographic.action.js +4 -4
- package/dist/custom/visualization/create-svg-network.action.js +12 -12
- package/dist/custom/visualization/create-svg-sketch-diagram.action.js +10 -10
- package/dist/custom/visualization/create-svg-word-cloud.action.js +11 -11
- package/dist/custom/visualization/shared/svg-theming.d.ts +17 -0
- package/dist/custom/visualization/shared/svg-theming.d.ts.map +1 -1
- package/dist/custom/visualization/shared/svg-theming.js +34 -10
- package/dist/custom/visualization/shared/svg-theming.js.map +1 -1
- package/dist/custom/visualization/shared/svg-utils.d.ts +39 -0
- package/dist/custom/visualization/shared/svg-utils.d.ts.map +1 -1
- package/dist/custom/visualization/shared/svg-utils.js +81 -17
- package/dist/custom/visualization/shared/svg-utils.js.map +1 -1
- package/dist/custom/web/brave-search.action.d.ts +108 -0
- package/dist/custom/web/brave-search.action.d.ts.map +1 -0
- package/dist/custom/web/brave-search.action.js +285 -0
- package/dist/custom/web/brave-search.action.js.map +1 -0
- package/dist/custom/web/duckduckgo-rate-limiter.d.ts +17 -1
- package/dist/custom/web/duckduckgo-rate-limiter.d.ts.map +1 -1
- package/dist/custom/web/duckduckgo-rate-limiter.js +26 -6
- package/dist/custom/web/duckduckgo-rate-limiter.js.map +1 -1
- package/dist/custom/web/google-custom-search.action.js +2 -2
- package/dist/custom/web/perplexity-search.action.d.ts +76 -44
- package/dist/custom/web/perplexity-search.action.d.ts.map +1 -1
- package/dist/custom/web/perplexity-search.action.js +228 -157
- package/dist/custom/web/perplexity-search.action.js.map +1 -1
- package/dist/custom/web/rss-feed-parsing.d.ts +19 -0
- package/dist/custom/web/rss-feed-parsing.d.ts.map +1 -1
- package/dist/custom/web/rss-feed-parsing.js +45 -13
- package/dist/custom/web/rss-feed-parsing.js.map +1 -1
- package/dist/custom/web/rss-feed-read.action.d.ts.map +1 -1
- package/dist/custom/web/rss-feed-read.action.js +9 -6
- package/dist/custom/web/rss-feed-read.action.js.map +1 -1
- package/dist/custom/web/tavily-search.action.js +2 -2
- package/dist/custom/web/web-search.action.d.ts +56 -40
- package/dist/custom/web/web-search.action.d.ts.map +1 -1
- package/dist/custom/web/web-search.action.js +141 -413
- package/dist/custom/web/web-search.action.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +40 -39
|
@@ -1,80 +1,112 @@
|
|
|
1
1
|
import { ActionResultSimple, RunActionParams } from "@memberjunction/actions-base";
|
|
2
2
|
import { BaseAction } from "@memberjunction/actions";
|
|
3
|
+
/** One result from Perplexity's `/search` endpoint, normalised to this package's naming. */
|
|
4
|
+
export interface PerplexitySearchResultItem {
|
|
5
|
+
title: string;
|
|
6
|
+
url: string;
|
|
7
|
+
snippet: string;
|
|
8
|
+
/** Publication date when Perplexity resolved one. */
|
|
9
|
+
date?: string;
|
|
10
|
+
/** When Perplexity last saw the page change. */
|
|
11
|
+
lastUpdated?: string;
|
|
12
|
+
}
|
|
13
|
+
/** Which Perplexity product a call routes to. */
|
|
14
|
+
export type PerplexitySearchMode = 'search' | 'answer';
|
|
3
15
|
/**
|
|
4
|
-
* Action that
|
|
5
|
-
*
|
|
16
|
+
* Action that queries Perplexity. It fronts **two different products**, selected
|
|
17
|
+
* by `Mode`, because they answer different questions and cost different money.
|
|
18
|
+
*
|
|
19
|
+
* - **`search` (default)** calls `POST /search`, Perplexity's raw search endpoint.
|
|
20
|
+
* It returns ranked `title` / `url` / `snippet` results with no model in the
|
|
21
|
+
* loop: sub-second, flat-priced per query, and deterministic enough to cache.
|
|
22
|
+
* This is the mode to use when something wants *sources*.
|
|
23
|
+
* - **`answer`** calls `POST /chat/completions` against the Sonar models. It
|
|
24
|
+
* returns synthesised prose plus a flat citation list, takes seconds rather
|
|
25
|
+
* than milliseconds, and bills per token. Use it when a caller genuinely wants
|
|
26
|
+
* a written answer rather than results to read.
|
|
27
|
+
*
|
|
28
|
+
* `search` is the default deliberately. Every caller that omitted `Mode` before
|
|
29
|
+
* this parameter existed was paying Sonar generation prices, and waiting for
|
|
30
|
+
* generation latency, to obtain what was usually just a list of links — and
|
|
31
|
+
* `Citations` is still populated in `search` mode, so callers that only read the
|
|
32
|
+
* URL list keep working unchanged.
|
|
6
33
|
*
|
|
7
34
|
* @example
|
|
8
35
|
* ```typescript
|
|
9
|
-
* //
|
|
36
|
+
* // Structured results — fast, flat-priced (default)
|
|
10
37
|
* await runAction({
|
|
11
38
|
* ActionName: 'Perplexity Search',
|
|
12
|
-
* Params: [{
|
|
13
|
-
* Name: 'Query',
|
|
14
|
-
* Value: 'latest developments in quantum computing'
|
|
15
|
-
* }]
|
|
39
|
+
* Params: [{ Name: 'Query', Value: 'latest developments in quantum computing' }]
|
|
16
40
|
* });
|
|
17
41
|
*
|
|
18
|
-
* //
|
|
42
|
+
* // Structured results, recent only, restricted to two domains
|
|
19
43
|
* await runAction({
|
|
20
44
|
* ActionName: 'Perplexity Search',
|
|
21
|
-
* Params: [
|
|
22
|
-
* Name: 'Query',
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* Name: '
|
|
26
|
-
*
|
|
27
|
-
* }, {
|
|
28
|
-
* Name: 'ReturnRelatedQuestions',
|
|
29
|
-
* Value: true
|
|
30
|
-
* }, {
|
|
31
|
-
* Name: 'ReturnImages',
|
|
32
|
-
* Value: true
|
|
33
|
-
* }]
|
|
45
|
+
* Params: [
|
|
46
|
+
* { Name: 'Query', Value: 'IRS Form 990 filing changes' },
|
|
47
|
+
* { Name: 'MaxResults', Value: 15 },
|
|
48
|
+
* { Name: 'SearchRecencyFilter', Value: 'month' },
|
|
49
|
+
* { Name: 'SearchDomainFilter', Value: ['irs.gov', 'councilofnonprofits.org'] }
|
|
50
|
+
* ]
|
|
34
51
|
* });
|
|
35
52
|
*
|
|
36
|
-
* //
|
|
53
|
+
* // A written answer with citations — slower, token-billed
|
|
37
54
|
* await runAction({
|
|
38
55
|
* ActionName: 'Perplexity Search',
|
|
39
|
-
* Params: [
|
|
40
|
-
* Name: 'Query',
|
|
41
|
-
* Value: '
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* Value: ['github.com', 'arxiv.org', 'medium.com']
|
|
45
|
-
* }]
|
|
56
|
+
* Params: [
|
|
57
|
+
* { Name: 'Query', Value: 'summarise the 2026 nonprofit reporting changes' },
|
|
58
|
+
* { Name: 'Mode', Value: 'answer' },
|
|
59
|
+
* { Name: 'Model', Value: 'sonar-pro' }
|
|
60
|
+
* ]
|
|
46
61
|
* });
|
|
47
62
|
* ```
|
|
48
63
|
*/
|
|
49
64
|
export declare class PerplexitySearchAction extends BaseAction {
|
|
65
|
+
private static readonly SEARCH_ENDPOINT;
|
|
66
|
+
private static readonly CHAT_ENDPOINT;
|
|
67
|
+
/** Perplexity's cap on results per web-search request. */
|
|
68
|
+
private static readonly MAX_RESULTS;
|
|
69
|
+
private static readonly DEFAULT_MAX_RESULTS;
|
|
70
|
+
/** Perplexity's cap on the domain allow/deny list. */
|
|
71
|
+
private static readonly MAX_DOMAIN_FILTERS;
|
|
72
|
+
private static readonly RECENCY_VALUES;
|
|
50
73
|
/**
|
|
51
|
-
* Executes the Perplexity
|
|
74
|
+
* Executes the Perplexity call.
|
|
52
75
|
*
|
|
53
76
|
* @param params - The action parameters containing:
|
|
54
77
|
* - Query: Search query text (required)
|
|
55
|
-
* -
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* -
|
|
61
|
-
* -
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* -
|
|
65
|
-
*
|
|
78
|
+
* - Mode: 'search' (default) for structured results, or 'answer' for Sonar prose
|
|
79
|
+
* - SearchDomainFilter: Restrict to these domains (max 20) — both modes
|
|
80
|
+
* - SearchRecencyFilter: 'hour' | 'day' | 'week' | 'month' | 'year' — both modes
|
|
81
|
+
*
|
|
82
|
+
* `search` mode only:
|
|
83
|
+
* - MaxResults: 1-20 (default 10)
|
|
84
|
+
* - Country: 2-letter country code for localisation
|
|
85
|
+
*
|
|
86
|
+
* `answer` mode only:
|
|
87
|
+
* - Model: 'sonar' (default), 'sonar-pro', 'sonar-reasoning-pro', 'sonar-deep-research'.
|
|
88
|
+
* Note the legacy `llama-3.1-sonar-*` identifiers were retired by Perplexity in
|
|
89
|
+
* February 2025 and now fail with an invalid-model error
|
|
90
|
+
* - MaxTokens, Temperature, TopP
|
|
91
|
+
* - ReturnImages, ReturnRelatedQuestions
|
|
66
92
|
*
|
|
67
|
-
* @returns
|
|
93
|
+
* @returns Structured results in `search` mode; prose plus citations in `answer` mode
|
|
68
94
|
*/
|
|
69
95
|
protected InternalRunAction(params: RunActionParams): Promise<ActionResultSimple>;
|
|
96
|
+
/** `POST /search` — structured results, no model in the loop. */
|
|
97
|
+
private runSearchMode;
|
|
98
|
+
/** `POST /chat/completions` — Sonar prose plus citations. */
|
|
99
|
+
private runAnswerMode;
|
|
100
|
+
private mapHttpError;
|
|
70
101
|
/**
|
|
71
102
|
* Get string parameter value
|
|
72
103
|
*/
|
|
73
104
|
private getStringParam;
|
|
74
105
|
/**
|
|
75
|
-
*
|
|
106
|
+
* A list param, accepted as a real array or as a comma-separated string — both
|
|
107
|
+
* forms arrive in practice, from agent input mappings and from humans respectively.
|
|
76
108
|
*/
|
|
77
|
-
private
|
|
109
|
+
private getStringArrayParam;
|
|
78
110
|
/**
|
|
79
111
|
* Get boolean parameter value with default
|
|
80
112
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perplexity-search.action.d.ts","sourceRoot":"","sources":["../../../src/custom/web/perplexity-search.action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAiBrD
|
|
1
|
+
{"version":3,"file":"perplexity-search.action.d.ts","sourceRoot":"","sources":["../../../src/custom/web/perplexity-search.action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAiBrD,4FAA4F;AAC5F,MAAM,WAAW,0BAA0B;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAgBD,iDAAiD;AACjD,MAAM,MAAM,oBAAoB,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,qBACa,sBAAuB,SAAQ,UAAU;IAClD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAsC;IAC7E,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAgD;IACrF,0DAA0D;IAC1D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAM;IACzC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAM;IACjD,sDAAsD;IACtD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAM;IAChD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAqD;IAE3F;;;;;;;;;;;;;;;;;;;;;OAqBG;cACa,iBAAiB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAoDvF,iEAAiE;YACnD,aAAa;IA4E3B,6DAA6D;YAC/C,aAAa;IA2E3B,OAAO,CAAC,YAAY;IAoBpB;;OAEG;IACH,OAAO,CAAC,cAAc;IAMtB;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAQ3B;;OAEG;IACH,OAAO,CAAC,eAAe;IAMvB;;OAEG;IACH,OAAO,CAAC,eAAe;IAOvB;;OAEG;IACH,OAAO,CAAC,cAAc;IAQtB;;OAEG;IACH,OAAO,CAAC,iBAAiB;CAO5B"}
|
|
@@ -4,195 +4,261 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
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;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
+
var PerplexitySearchAction_1;
|
|
7
8
|
import { BaseAction } from "@memberjunction/actions";
|
|
8
9
|
import { RegisterClass } from "@memberjunction/global";
|
|
9
10
|
import { HttpPost, IsHttpError } from "@memberjunction/network-utils";
|
|
10
11
|
import { getApiIntegrationsConfig } from "../../config.js";
|
|
11
12
|
/**
|
|
12
|
-
* Action that
|
|
13
|
-
*
|
|
13
|
+
* Action that queries Perplexity. It fronts **two different products**, selected
|
|
14
|
+
* by `Mode`, because they answer different questions and cost different money.
|
|
15
|
+
*
|
|
16
|
+
* - **`search` (default)** calls `POST /search`, Perplexity's raw search endpoint.
|
|
17
|
+
* It returns ranked `title` / `url` / `snippet` results with no model in the
|
|
18
|
+
* loop: sub-second, flat-priced per query, and deterministic enough to cache.
|
|
19
|
+
* This is the mode to use when something wants *sources*.
|
|
20
|
+
* - **`answer`** calls `POST /chat/completions` against the Sonar models. It
|
|
21
|
+
* returns synthesised prose plus a flat citation list, takes seconds rather
|
|
22
|
+
* than milliseconds, and bills per token. Use it when a caller genuinely wants
|
|
23
|
+
* a written answer rather than results to read.
|
|
24
|
+
*
|
|
25
|
+
* `search` is the default deliberately. Every caller that omitted `Mode` before
|
|
26
|
+
* this parameter existed was paying Sonar generation prices, and waiting for
|
|
27
|
+
* generation latency, to obtain what was usually just a list of links — and
|
|
28
|
+
* `Citations` is still populated in `search` mode, so callers that only read the
|
|
29
|
+
* URL list keep working unchanged.
|
|
14
30
|
*
|
|
15
31
|
* @example
|
|
16
32
|
* ```typescript
|
|
17
|
-
* //
|
|
33
|
+
* // Structured results — fast, flat-priced (default)
|
|
18
34
|
* await runAction({
|
|
19
35
|
* ActionName: 'Perplexity Search',
|
|
20
|
-
* Params: [{
|
|
21
|
-
* Name: 'Query',
|
|
22
|
-
* Value: 'latest developments in quantum computing'
|
|
23
|
-
* }]
|
|
36
|
+
* Params: [{ Name: 'Query', Value: 'latest developments in quantum computing' }]
|
|
24
37
|
* });
|
|
25
38
|
*
|
|
26
|
-
* //
|
|
39
|
+
* // Structured results, recent only, restricted to two domains
|
|
27
40
|
* await runAction({
|
|
28
41
|
* ActionName: 'Perplexity Search',
|
|
29
|
-
* Params: [
|
|
30
|
-
* Name: 'Query',
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* Name: '
|
|
34
|
-
*
|
|
35
|
-
* }, {
|
|
36
|
-
* Name: 'ReturnRelatedQuestions',
|
|
37
|
-
* Value: true
|
|
38
|
-
* }, {
|
|
39
|
-
* Name: 'ReturnImages',
|
|
40
|
-
* Value: true
|
|
41
|
-
* }]
|
|
42
|
+
* Params: [
|
|
43
|
+
* { Name: 'Query', Value: 'IRS Form 990 filing changes' },
|
|
44
|
+
* { Name: 'MaxResults', Value: 15 },
|
|
45
|
+
* { Name: 'SearchRecencyFilter', Value: 'month' },
|
|
46
|
+
* { Name: 'SearchDomainFilter', Value: ['irs.gov', 'councilofnonprofits.org'] }
|
|
47
|
+
* ]
|
|
42
48
|
* });
|
|
43
49
|
*
|
|
44
|
-
* //
|
|
50
|
+
* // A written answer with citations — slower, token-billed
|
|
45
51
|
* await runAction({
|
|
46
52
|
* ActionName: 'Perplexity Search',
|
|
47
|
-
* Params: [
|
|
48
|
-
* Name: 'Query',
|
|
49
|
-
* Value: '
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* Value: ['github.com', 'arxiv.org', 'medium.com']
|
|
53
|
-
* }]
|
|
53
|
+
* Params: [
|
|
54
|
+
* { Name: 'Query', Value: 'summarise the 2026 nonprofit reporting changes' },
|
|
55
|
+
* { Name: 'Mode', Value: 'answer' },
|
|
56
|
+
* { Name: 'Model', Value: 'sonar-pro' }
|
|
57
|
+
* ]
|
|
54
58
|
* });
|
|
55
59
|
* ```
|
|
56
60
|
*/
|
|
57
61
|
let PerplexitySearchAction = class PerplexitySearchAction extends BaseAction {
|
|
62
|
+
static { PerplexitySearchAction_1 = this; }
|
|
63
|
+
static { this.SEARCH_ENDPOINT = 'https://api.perplexity.ai/search'; }
|
|
64
|
+
static { this.CHAT_ENDPOINT = 'https://api.perplexity.ai/chat/completions'; }
|
|
65
|
+
/** Perplexity's cap on results per web-search request. */
|
|
66
|
+
static { this.MAX_RESULTS = 20; }
|
|
67
|
+
static { this.DEFAULT_MAX_RESULTS = 10; }
|
|
68
|
+
/** Perplexity's cap on the domain allow/deny list. */
|
|
69
|
+
static { this.MAX_DOMAIN_FILTERS = 20; }
|
|
70
|
+
static { this.RECENCY_VALUES = ['hour', 'day', 'week', 'month', 'year']; }
|
|
58
71
|
/**
|
|
59
|
-
* Executes the Perplexity
|
|
72
|
+
* Executes the Perplexity call.
|
|
60
73
|
*
|
|
61
74
|
* @param params - The action parameters containing:
|
|
62
75
|
* - Query: Search query text (required)
|
|
63
|
-
* -
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* -
|
|
69
|
-
* -
|
|
70
|
-
* - ReturnImages: Include images in results (default: false)
|
|
71
|
-
* - ReturnRelatedQuestions: Include related questions (default: false)
|
|
72
|
-
* - SearchDomainFilter: Array of domains to limit/exclude search (use '-' prefix to exclude)
|
|
73
|
-
* - SearchRecencyFilter: Filter by recency - 'day', 'week', 'month', 'year' (optional)
|
|
76
|
+
* - Mode: 'search' (default) for structured results, or 'answer' for Sonar prose
|
|
77
|
+
* - SearchDomainFilter: Restrict to these domains (max 20) — both modes
|
|
78
|
+
* - SearchRecencyFilter: 'hour' | 'day' | 'week' | 'month' | 'year' — both modes
|
|
79
|
+
*
|
|
80
|
+
* `search` mode only:
|
|
81
|
+
* - MaxResults: 1-20 (default 10)
|
|
82
|
+
* - Country: 2-letter country code for localisation
|
|
74
83
|
*
|
|
75
|
-
*
|
|
84
|
+
* `answer` mode only:
|
|
85
|
+
* - Model: 'sonar' (default), 'sonar-pro', 'sonar-reasoning-pro', 'sonar-deep-research'.
|
|
86
|
+
* Note the legacy `llama-3.1-sonar-*` identifiers were retired by Perplexity in
|
|
87
|
+
* February 2025 and now fail with an invalid-model error
|
|
88
|
+
* - MaxTokens, Temperature, TopP
|
|
89
|
+
* - ReturnImages, ReturnRelatedQuestions
|
|
90
|
+
*
|
|
91
|
+
* @returns Structured results in `search` mode; prose plus citations in `answer` mode
|
|
76
92
|
*/
|
|
77
93
|
async InternalRunAction(params) {
|
|
94
|
+
const query = this.getStringParam(params, 'query');
|
|
95
|
+
if (!query) {
|
|
96
|
+
return this.createErrorResult("Query parameter is required", "MISSING_QUERY");
|
|
97
|
+
}
|
|
98
|
+
const mode = (this.getStringParam(params, 'mode') || 'search').trim().toLowerCase();
|
|
99
|
+
if (mode !== 'search' && mode !== 'answer') {
|
|
100
|
+
return this.createErrorResult(`Mode must be 'search' or 'answer' (got '${mode}')`, "INVALID_MODE");
|
|
101
|
+
}
|
|
102
|
+
const apiKey = getApiIntegrationsConfig().perplexityApiKey;
|
|
103
|
+
if (!apiKey) {
|
|
104
|
+
return this.createErrorResult("Perplexity API key not found. Set perplexityApiKey in mj.config.cjs or PERPLEXITY_API_KEY environment variable", "MISSING_API_KEY");
|
|
105
|
+
}
|
|
106
|
+
const recency = this.getStringParam(params, 'searchrecencyfilter')?.trim().toLowerCase();
|
|
107
|
+
if (recency && !PerplexitySearchAction_1.RECENCY_VALUES.includes(recency)) {
|
|
108
|
+
return this.createErrorResult(`SearchRecencyFilter must be one of ${PerplexitySearchAction_1.RECENCY_VALUES.join(', ')} (got '${recency}')`, "INVALID_RECENCY_FILTER");
|
|
109
|
+
}
|
|
110
|
+
// Truncated rather than rejected: Perplexity 400s on an over-long list, and the
|
|
111
|
+
// first 20 domains still express what the caller was narrowing to.
|
|
112
|
+
const domainFilter = this.getStringArrayParam(params, 'searchdomainfilter')
|
|
113
|
+
.slice(0, PerplexitySearchAction_1.MAX_DOMAIN_FILTERS);
|
|
78
114
|
try {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return this.createErrorResult("Perplexity API key not found. Set perplexityApiKey in mj.config.cjs or PERPLEXITY_API_KEY environment variable", "MISSING_API_KEY");
|
|
89
|
-
}
|
|
90
|
-
// Get optional parameters
|
|
91
|
-
const model = this.getStringParam(params, 'model') || 'sonar';
|
|
92
|
-
const maxTokens = this.getNumericParam(params, 'maxtokens', 1000);
|
|
93
|
-
const temperature = this.getNumericParam(params, 'temperature', 0.2);
|
|
94
|
-
const topP = this.getNumericParam(params, 'topp', 0.9);
|
|
95
|
-
const returnImages = this.getBooleanParam(params, 'returnimages', false);
|
|
96
|
-
const returnRelatedQuestions = this.getBooleanParam(params, 'returnrelatedquestions', false);
|
|
97
|
-
const searchRecencyFilter = this.getStringParam(params, 'searchrecencyfilter');
|
|
98
|
-
// Get domain filter (can be array or comma-separated string)
|
|
99
|
-
const domainFilterParam = this.getParamValue(params, 'searchdomainfilter');
|
|
100
|
-
let searchDomainFilter;
|
|
101
|
-
if (domainFilterParam) {
|
|
102
|
-
if (Array.isArray(domainFilterParam)) {
|
|
103
|
-
searchDomainFilter = domainFilterParam;
|
|
104
|
-
}
|
|
105
|
-
else if (typeof domainFilterParam === 'string') {
|
|
106
|
-
searchDomainFilter = domainFilterParam.split(',').map(d => d.trim());
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
// Build request body
|
|
110
|
-
const requestBody = {
|
|
111
|
-
model,
|
|
112
|
-
messages: [
|
|
113
|
-
{
|
|
114
|
-
role: 'user',
|
|
115
|
-
content: query
|
|
116
|
-
}
|
|
117
|
-
],
|
|
118
|
-
max_tokens: maxTokens,
|
|
119
|
-
temperature,
|
|
120
|
-
top_p: topP,
|
|
121
|
-
return_images: returnImages,
|
|
122
|
-
return_related_questions: returnRelatedQuestions,
|
|
123
|
-
stream: false
|
|
124
|
-
};
|
|
125
|
-
// Add optional parameters
|
|
126
|
-
if (searchDomainFilter && searchDomainFilter.length > 0) {
|
|
127
|
-
requestBody.search_domain_filter = searchDomainFilter;
|
|
128
|
-
}
|
|
129
|
-
if (searchRecencyFilter) {
|
|
130
|
-
requestBody.search_recency_filter = searchRecencyFilter;
|
|
131
|
-
}
|
|
132
|
-
// Make API request
|
|
133
|
-
const response = await HttpPost('https://api.perplexity.ai/chat/completions', requestBody, {
|
|
134
|
-
Headers: {
|
|
135
|
-
'Authorization': `Bearer ${apiKey}`,
|
|
136
|
-
'Content-Type': 'application/json'
|
|
137
|
-
},
|
|
138
|
-
Timeout: 60000 // 60 second timeout
|
|
139
|
-
});
|
|
140
|
-
if (!response.Data) {
|
|
141
|
-
return this.createErrorResult("Empty response from Perplexity API", "EMPTY_RESPONSE");
|
|
115
|
+
return mode === 'search'
|
|
116
|
+
? await this.runSearchMode(params, { query, apiKey, recency, domainFilter })
|
|
117
|
+
: await this.runAnswerMode(params, { query, apiKey, recency, domainFilter });
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
// Status 0 is HttpError's "the request never produced a response" — a timeout or a
|
|
121
|
+
// network failure. That is not an API answer, so it falls through to SEARCH_FAILED.
|
|
122
|
+
if (IsHttpError(error) && error.Status > 0) {
|
|
123
|
+
return this.mapHttpError(error);
|
|
142
124
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
125
|
+
return this.createErrorResult(`Failed to perform Perplexity search: ${error instanceof Error ? error.message : String(error)}`, "SEARCH_FAILED");
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/** `POST /search` — structured results, no model in the loop. */
|
|
129
|
+
async runSearchMode(params, ctx) {
|
|
130
|
+
// Clamped rather than rejected, matching Tavily and Brave: a caller asking for
|
|
131
|
+
// 50 wants as many as possible, and Perplexity rejects the whole request above its cap.
|
|
132
|
+
const maxResults = Math.min(Math.max(Math.floor(this.getNumericParam(params, 'maxresults', PerplexitySearchAction_1.DEFAULT_MAX_RESULTS)), 1), PerplexitySearchAction_1.MAX_RESULTS);
|
|
133
|
+
const requestBody = { query: ctx.query, max_results: maxResults };
|
|
134
|
+
if (ctx.domainFilter.length > 0) {
|
|
135
|
+
requestBody.search_domain_filter = ctx.domainFilter;
|
|
136
|
+
}
|
|
137
|
+
if (ctx.recency) {
|
|
138
|
+
requestBody.search_recency_filter = ctx.recency;
|
|
139
|
+
}
|
|
140
|
+
const country = this.getStringParam(params, 'country');
|
|
141
|
+
if (country) {
|
|
142
|
+
requestBody.country = country.trim().toUpperCase();
|
|
143
|
+
}
|
|
144
|
+
const response = await HttpPost(PerplexitySearchAction_1.SEARCH_ENDPOINT, requestBody, { Headers: { 'Authorization': `Bearer ${ctx.apiKey}` }, Timeout: 30000 });
|
|
145
|
+
if (!response.Data) {
|
|
146
|
+
return this.createErrorResult("Empty response from Perplexity Search API", "EMPTY_RESPONSE");
|
|
147
|
+
}
|
|
148
|
+
const results = (response.Data.results ?? []).map((item) => {
|
|
149
|
+
const mapped = {
|
|
150
|
+
title: item.title ?? '',
|
|
151
|
+
url: item.url ?? '',
|
|
152
|
+
snippet: item.snippet ?? '',
|
|
161
153
|
};
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
this.addOutputParam(params, 'Citations', citations);
|
|
165
|
-
this.addOutputParam(params, 'CitationCount', citations.length);
|
|
166
|
-
if (returnImages && images.length > 0) {
|
|
167
|
-
this.addOutputParam(params, 'Images', images);
|
|
168
|
-
this.addOutputParam(params, 'ImageCount', images.length);
|
|
154
|
+
if (item.date) {
|
|
155
|
+
mapped.date = item.date;
|
|
169
156
|
}
|
|
170
|
-
if (
|
|
171
|
-
|
|
172
|
-
this.addOutputParam(params, 'RelatedQuestionCount', relatedQuestions.length);
|
|
157
|
+
if (item.last_updated) {
|
|
158
|
+
mapped.lastUpdated = item.last_updated;
|
|
173
159
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
160
|
+
return mapped;
|
|
161
|
+
});
|
|
162
|
+
// `Citations` is emitted here too, holding the result URLs. Callers written against
|
|
163
|
+
// the old answer-only behaviour read that param, and this keeps them working when
|
|
164
|
+
// the default mode changed underneath them.
|
|
165
|
+
const citations = results.map(r => r.url).filter(u => u.length > 0);
|
|
166
|
+
this.addOutputParam(params, 'Results', results);
|
|
167
|
+
this.addOutputParam(params, 'ResultCount', results.length);
|
|
168
|
+
this.addOutputParam(params, 'Citations', citations);
|
|
169
|
+
this.addOutputParam(params, 'CitationCount', citations.length);
|
|
170
|
+
this.addOutputParam(params, 'SearchResultDetails', {
|
|
171
|
+
query: ctx.query,
|
|
172
|
+
mode: 'search',
|
|
173
|
+
maxResults,
|
|
174
|
+
results,
|
|
175
|
+
citations,
|
|
176
|
+
serverTime: response.Data.server_time,
|
|
177
|
+
});
|
|
178
|
+
// Zero results is a real answer to a narrow query, not a failure.
|
|
179
|
+
return {
|
|
180
|
+
Success: true,
|
|
181
|
+
ResultCode: "SUCCESS",
|
|
182
|
+
Message: results.length === 0
|
|
183
|
+
? `Perplexity returned no results for '${ctx.query}'.`
|
|
184
|
+
: `Perplexity returned ${results.length} result(s) for '${ctx.query}'.`
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/** `POST /chat/completions` — Sonar prose plus citations. */
|
|
188
|
+
async runAnswerMode(params, ctx) {
|
|
189
|
+
const model = this.getStringParam(params, 'model') || 'sonar';
|
|
190
|
+
const returnImages = this.getBooleanParam(params, 'returnimages', false);
|
|
191
|
+
const returnRelatedQuestions = this.getBooleanParam(params, 'returnrelatedquestions', false);
|
|
192
|
+
const requestBody = {
|
|
193
|
+
model,
|
|
194
|
+
messages: [{ role: 'user', content: ctx.query }],
|
|
195
|
+
max_tokens: this.getNumericParam(params, 'maxtokens', 1000),
|
|
196
|
+
temperature: this.getNumericParam(params, 'temperature', 0.2),
|
|
197
|
+
top_p: this.getNumericParam(params, 'topp', 0.9),
|
|
198
|
+
return_images: returnImages,
|
|
199
|
+
return_related_questions: returnRelatedQuestions,
|
|
200
|
+
stream: false
|
|
201
|
+
};
|
|
202
|
+
if (ctx.domainFilter.length > 0) {
|
|
203
|
+
requestBody.search_domain_filter = ctx.domainFilter;
|
|
181
204
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
205
|
+
if (ctx.recency) {
|
|
206
|
+
requestBody.search_recency_filter = ctx.recency;
|
|
207
|
+
}
|
|
208
|
+
const response = await HttpPost(PerplexitySearchAction_1.CHAT_ENDPOINT, requestBody, { Headers: { 'Authorization': `Bearer ${ctx.apiKey}` }, Timeout: 60000 });
|
|
209
|
+
if (!response.Data) {
|
|
210
|
+
return this.createErrorResult("Empty response from Perplexity API", "EMPTY_RESPONSE");
|
|
211
|
+
}
|
|
212
|
+
const result = response.Data;
|
|
213
|
+
const choice = result.choices?.[0];
|
|
214
|
+
const content = choice?.message?.content || '';
|
|
215
|
+
const citations = result.citations || [];
|
|
216
|
+
const images = result.images || [];
|
|
217
|
+
const relatedQuestions = result.related_questions || [];
|
|
218
|
+
const outputData = {
|
|
219
|
+
query: ctx.query,
|
|
220
|
+
mode: 'answer',
|
|
221
|
+
model,
|
|
222
|
+
content,
|
|
223
|
+
citations,
|
|
224
|
+
images,
|
|
225
|
+
relatedQuestions,
|
|
226
|
+
usage: result.usage || {},
|
|
227
|
+
finishReason: choice?.finish_reason
|
|
228
|
+
};
|
|
229
|
+
this.addOutputParam(params, 'Content', content);
|
|
230
|
+
this.addOutputParam(params, 'Citations', citations);
|
|
231
|
+
this.addOutputParam(params, 'CitationCount', citations.length);
|
|
232
|
+
if (returnImages && images.length > 0) {
|
|
233
|
+
this.addOutputParam(params, 'Images', images);
|
|
234
|
+
this.addOutputParam(params, 'ImageCount', images.length);
|
|
235
|
+
}
|
|
236
|
+
if (returnRelatedQuestions && relatedQuestions.length > 0) {
|
|
237
|
+
this.addOutputParam(params, 'RelatedQuestions', relatedQuestions);
|
|
238
|
+
this.addOutputParam(params, 'RelatedQuestionCount', relatedQuestions.length);
|
|
239
|
+
}
|
|
240
|
+
this.addOutputParam(params, 'Usage', result.usage);
|
|
241
|
+
this.addOutputParam(params, 'SearchResultDetails', outputData);
|
|
242
|
+
return {
|
|
243
|
+
Success: true,
|
|
244
|
+
ResultCode: "SUCCESS",
|
|
245
|
+
Message: JSON.stringify(outputData, null, 2)
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
mapHttpError(error) {
|
|
249
|
+
const status = error.Status;
|
|
250
|
+
const errorData = error.Data;
|
|
251
|
+
const detail = errorData?.error?.message || error.message;
|
|
252
|
+
if (status === 401 || status === 403) {
|
|
253
|
+
return this.createErrorResult(`Invalid Perplexity API key (HTTP ${status})`, "INVALID_API_KEY");
|
|
254
|
+
}
|
|
255
|
+
if (status === 429) {
|
|
256
|
+
return this.createErrorResult("Perplexity API rate limit exceeded", "RATE_LIMITED");
|
|
257
|
+
}
|
|
258
|
+
if (status === 400 || status === 422) {
|
|
259
|
+
return this.createErrorResult(`Perplexity rejected the request (HTTP ${status}): ${detail}`, "INVALID_REQUEST");
|
|
195
260
|
}
|
|
261
|
+
return this.createErrorResult(`Perplexity API error: ${detail}`, "API_ERROR");
|
|
196
262
|
}
|
|
197
263
|
/**
|
|
198
264
|
* Get string parameter value
|
|
@@ -204,11 +270,16 @@ let PerplexitySearchAction = class PerplexitySearchAction extends BaseAction {
|
|
|
204
270
|
return String(param.Value);
|
|
205
271
|
}
|
|
206
272
|
/**
|
|
207
|
-
*
|
|
273
|
+
* A list param, accepted as a real array or as a comma-separated string — both
|
|
274
|
+
* forms arrive in practice, from agent input mappings and from humans respectively.
|
|
208
275
|
*/
|
|
209
|
-
|
|
276
|
+
getStringArrayParam(params, paramName) {
|
|
210
277
|
const param = params.Params.find(p => p.Name.trim().toLowerCase() === paramName.toLowerCase());
|
|
211
|
-
|
|
278
|
+
const value = param?.Value;
|
|
279
|
+
if (value === undefined || value === null)
|
|
280
|
+
return [];
|
|
281
|
+
const raw = Array.isArray(value) ? value.map(v => String(v)) : String(value).split(',');
|
|
282
|
+
return raw.map(v => v.trim()).filter(v => v.length > 0);
|
|
212
283
|
}
|
|
213
284
|
/**
|
|
214
285
|
* Get boolean parameter value with default
|
|
@@ -250,7 +321,7 @@ let PerplexitySearchAction = class PerplexitySearchAction extends BaseAction {
|
|
|
250
321
|
};
|
|
251
322
|
}
|
|
252
323
|
};
|
|
253
|
-
PerplexitySearchAction = __decorate([
|
|
324
|
+
PerplexitySearchAction = PerplexitySearchAction_1 = __decorate([
|
|
254
325
|
RegisterClass(BaseAction, "Perplexity Search")
|
|
255
326
|
], PerplexitySearchAction);
|
|
256
327
|
export { PerplexitySearchAction };
|