@sanoma-ai/connector-exa 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,105 @@
1
+ # Functional Source License, Version 1.1, ALv2 Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-ALv2
6
+
7
+ ## Notice
8
+
9
+ Copyright 2026 Sanoma-AI
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,129 @@
1
- # Temporary Holding Version
1
+ # @sanoma-ai/connector-exa
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [Exa](https://exa.ai) web search operations for [`@sanoma-ai/workflows`](https://www.npmjs.com/package/@sanoma-ai/workflows): a search, pages read by URL, the pages like one, and an answer with its sources.
4
+
5
+ ## Usage
6
+
7
+ ```sh
8
+ npm install @sanoma-ai/connector-exa
9
+ ```
10
+
11
+ | Operation | Effect | What it does |
12
+ | --------------------- | ------ | -------------------------------------------------------------------------------------------- |
13
+ | `exa.web.search` | `read` | Search the web, and return the pages found, with their text, highlights or summary if asked. |
14
+ | `exa.web.getContents` | `read` | Read pages by URL: their text, highlights or summary. |
15
+ | `exa.web.findSimilar` | `read` | Find pages like the one at a URL. |
16
+ | `exa.web.answer` | `read` | Answer a question from a web search, with the pages the answer cites. |
17
+
18
+ ```ts
19
+ import { exa } from "@sanoma-ai/connector-exa";
20
+ import { defineWorkflow } from "@sanoma-ai/workflows";
21
+
22
+ defineWorkflow({
23
+ // ...
24
+ uses: [exa.web.search, exa.web.answer],
25
+ run: async (ctx, input) => {
26
+ const { results } = await ctx.exa.web.search({
27
+ query: `${input.company} pricing page`,
28
+ numResults: 5,
29
+ contents: { highlights: { query: "price per month" } },
30
+ });
31
+ const { answer, citations } = await ctx.exa.web.answer({ query: `What does ${input.company} charge?` });
32
+ return { pages: results.map((r) => r.url), answer, sources: citations.map((c) => c.url) };
33
+ },
34
+ });
35
+ ```
36
+
37
+ The inputs are Exa's own fields ([API reference](https://exa.ai/docs/reference/search)), cut to these:
38
+
39
+ - `search`: `query`, `type` (`auto` by default, `neural`, or `lite`, the cheapest, in beta), `category` (`company`, `publication`, `news`, `personal site`, `financial report`, `people`), and the filters below.
40
+ - `findSimilar`: `url`, `excludeSourceDomain`, and the filters below. `exa-js` marks it deprecated, with no other way to find pages like one; Exa's endpoint still answers.
41
+ - The filters: `numResults` (1 to 100, 10 by default), `includeDomains`, `excludeDomains`, `startPublishedDate` and `endPublishedDate` (ISO 8601), and `contents`, what of each page to return.
42
+ - `getContents`: `urls`, and what `contents` takes, at the top level: `text` (`true`, or `{ maxCharacters }`), `highlights` (`true`, or `{ maxCharacters, query }`), `summary` (`{ query? }`) and `maxAgeHours` (the oldest cached copy to use; 0 fetches the page again, -1 never does).
43
+ - `answer`: `query`, and `text` to return each cited page's text.
44
+
45
+ Each page comes back as `{ id, url, title, author, publishedDate, score, image?, favicon? }` plus the `text`, `highlights` and `summary` asked for. `getContents` returns `statuses` too, one per URL: a page Exa could not read is not in `results` but in `statuses` with `status: "error"` and an `error.tag` such as `CRAWL_NOT_FOUND`, and the call itself succeeds.
46
+
47
+ The logo the app shows beside these operations is Exa's mark from its [brand page](https://exa.ai/brand), blue or white. It is there only to identify the service an operation calls. Exa Labs, which makes Exa, does not endorse this package.
48
+
49
+ ## Driver
50
+
51
+ `@sanoma-ai/connector-exa/driver` calls Exa. The `exa` connector the package root exports carries it, made once per resolved config, and its fake (`withSetup` from `@sanoma-ai/workflows`), so a config names the connector alone and workflows never import the driver (the lint refuses that):
52
+
53
+ ```ts
54
+ import { exa } from "@sanoma-ai/connector-exa";
55
+
56
+ export default defineConfig({ workflows, connectors: [exa], policy });
57
+ ```
58
+
59
+ `./driver` (`exaDriver`; `exaDriver({ timeoutMs })`, 30 s by default, since an answer takes several seconds) and `./fake` (`fakeExa`) are internal entries, for tests.
60
+
61
+ It calls Exa through [`exa-js`](https://www.npmjs.com/package/exa-js), Exa's own SDK, loaded at the first call (it brings the OpenAI SDK and zod 3 with it). A search with no `contents` asks for none, where the SDK would ask for each page's text.
62
+
63
+ ### Environment
64
+
65
+ It reads this on every call, never when the config loads:
66
+
67
+ | Variable | What it is |
68
+ | ------------- | -------------------------------------------------------------------------------------- |
69
+ | `EXA_API_KEY` | An Exa API key, from the API Keys page of [Exa's dashboard](https://dashboard.exa.ai). |
70
+
71
+ When it is unset, a call fails, not retryable, naming it. The driver declares it in its `env` ([Credentials](https://www.npmjs.com/package/@sanoma-ai/workflows#credentials)): the worker starts without it, warning, and the app's connector page shows its status and lets you set it.
72
+
73
+ ### Errors and retries
74
+
75
+ Every operation only reads, so a retried call changes nothing, though each call costs Exa credits. A 408, a 429 (rate limit), a 5xx (Exa overloaded, `SERVICE_OVERLOADED`, or a request past its deadline), a timeout (30 s; `timeoutMs` changes it) or no reply is retryable; any other 4xx is not, such as 401 `INVALID_API_KEY` and 402 `NO_MORE_CREDITS` or a budget spent. `status` is kept, and Exa's message ([error codes](https://exa.ai/docs/reference/error-codes)); `exa-js` drops the error's `tag`, so `vendorCode` is set only when its error carries a `code`. A reply with no body, or an answer that is not text, fails for good.
76
+
77
+ ### Testing the driver
78
+
79
+ `test/driver.test.ts` replays Exa's replies (`test/fixtures`) with [`@sanoma-ai/testing/replay`](https://github.com/Sanoma-AI/sanoma/blob/main/packages/testing/README.md#replaying-a-vendors-api), which says what `SANOMA_LIVE` and `SANOMA_RECORD` do: `pnpm vitest run connectors/exa` needs no account. The fixtures were written from Exa's API reference and error docs, not recorded from its API; live, the tests search Exa and spend a few cents of credits, and recording replaces them with Exa's own replies:
80
+
81
+ ```sh
82
+ SANOMA_LIVE=1 SANOMA_RECORD=1 EXA_API_KEY=... pnpm vitest run connectors/exa
83
+ ```
84
+
85
+ A recording loses request ids. The error cases only replay.
86
+
87
+ ## Steps and features
88
+
89
+ The connector carries steps for [scenarios](https://github.com/Sanoma-AI/sanoma/blob/main/packages/workflows/README.md#steps-a-connector-ships) (`exaSteps`, attached with `withSetup`), which a company's scenario can use beside the generic steps and other connectors' ones:
90
+
91
+ | Keyword | Step | What it does |
92
+ | ------- | ------------------------------- | -------------------------------------------------------------- |
93
+ | Given | `Exa fails to search once` | The next `exa.web.search` fails (`failNext`) |
94
+ | Then | `Exa was searched for {string}` | The run searched Exa with a query that holds that text |
95
+ | Then | `Exa was asked {string}` | The run asked `exa.web.answer` a question that holds that text |
96
+
97
+ `features/search.feature`, `features/contents.feature` and `features/answer.feature` test each operation with these steps and the generic ones for an operation's own test, on the fake and on Exa's replies: `test/features.test.ts` runs them with [`describeFeatures`](https://github.com/Sanoma-AI/sanoma/blob/main/packages/testing/README.md#a-connectors-own-features). A scenario tagged `@fake-only` has no recording. The package ships `features/`.
98
+
99
+ ## Testing
100
+
101
+ `@sanoma-ai/connector-exa/fake` is an in-memory Exa that searches nothing, the fake the connector carries: each sandbox run makes one of its own. It makes up to three pages for a query or a URL, from them alone, so one call always finds the same pages (on the first of `includeDomains`, else `example.com`, or for `findSimilar` the URL's own host, and never on a domain excluded), with the `text`, `highlights` and `summary` asked for. The pages it served stay in `state.pages`, by URL, which `getContents` reads; put a page there to give it a text of your own. `getContents` returns each page's text when the call asks for none of text, highlights or summary, as Exa does. A URL on a `.invalid` host cannot be read: `getContents` returns it in `statuses` as `CRAWL_NOT_FOUND`.
102
+
103
+ ```ts
104
+ import { withSetup } from "@sanoma-ai/workflows";
105
+ import { exa } from "@sanoma-ai/connector-exa";
106
+ import { fakeExa } from "@sanoma-ai/connector-exa/fake";
107
+
108
+ const fake = fakeExa();
109
+ fake.update((state) => {
110
+ state.pages["https://acme.example/pricing"] = {
111
+ url: "https://acme.example/pricing",
112
+ title: "Pricing",
113
+ text: "$20 a month.",
114
+ };
115
+ });
116
+ const worker = await startWorker({
117
+ connectors: [withSetup(exa, { driver: () => fake.driver, fake: () => fake })],
118
+ /* ... */
119
+ });
120
+
121
+ // ...run a workflow, then:
122
+ fake.calls.map((c) => c.op); // ["exa.web.search", "exa.web.getContents"]
123
+ ```
124
+
125
+ To test what a workflow does when Exa misbehaves, set up the next call to an operation before the run makes it: `fake.failNext("exa.web.search", err?)`, `fake.rateLimit("exa.web.search")` (a `DriverError` with status 429), `fake.loseReply(…)` and `fake.hold(…)`. `fake.reset()` empties it between tests.
126
+
127
+ [`@sanoma-ai/testing`](https://github.com/Sanoma-AI/sanoma/blob/main/packages/testing/README.md) (in the sanoma repository, not published) has `startTestWorker` and `testDatabaseUrl` to run a test's worker with the fake on a database of its own.
128
+
129
+ License: FSL-1.1-ALv2.
@@ -0,0 +1,172 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Exa, the web search API (https://exa.ai/docs/reference): a search, a page's contents, the pages
4
+ * like one, and an answer with its sources. Every operation reads; each call costs Exa credits.
5
+ */
6
+ export declare const exaOps: import("@sanoma-ai/workflows").Connector<"exa", {
7
+ readonly web: {
8
+ readonly search: {
9
+ readonly effect: "read";
10
+ readonly idempotent: true;
11
+ readonly description: "Search the web, and return the pages found, with their text, highlights or summary if asked.";
12
+ readonly input: z.ZodObject<{
13
+ numResults: z.ZodOptional<z.ZodInt>;
14
+ includeDomains: z.ZodOptional<z.ZodArray<z.ZodString>>;
15
+ excludeDomains: z.ZodOptional<z.ZodArray<z.ZodString>>;
16
+ startPublishedDate: z.ZodOptional<z.ZodString>;
17
+ endPublishedDate: z.ZodOptional<z.ZodString>;
18
+ contents: z.ZodOptional<z.ZodObject<{
19
+ text: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodObject<{
20
+ maxCharacters: z.ZodOptional<z.ZodInt>;
21
+ }, z.core.$strip>]>>;
22
+ highlights: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodObject<{
23
+ maxCharacters: z.ZodOptional<z.ZodInt>;
24
+ query: z.ZodOptional<z.ZodString>;
25
+ }, z.core.$strip>]>>;
26
+ summary: z.ZodOptional<z.ZodObject<{
27
+ query: z.ZodOptional<z.ZodString>;
28
+ }, z.core.$strip>>;
29
+ maxAgeHours: z.ZodOptional<z.ZodInt>;
30
+ }, z.core.$strip>>;
31
+ query: z.ZodString;
32
+ type: z.ZodOptional<z.ZodEnum<{
33
+ auto: "auto";
34
+ lite: "lite";
35
+ neural: "neural";
36
+ }>>;
37
+ category: z.ZodOptional<z.ZodEnum<{
38
+ company: "company";
39
+ "financial report": "financial report";
40
+ news: "news";
41
+ people: "people";
42
+ "personal site": "personal site";
43
+ publication: "publication";
44
+ }>>;
45
+ }, z.core.$strip>;
46
+ readonly output: z.ZodObject<{
47
+ results: z.ZodArray<z.ZodObject<{
48
+ id: z.ZodString;
49
+ url: z.ZodString;
50
+ title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
51
+ author: z.ZodOptional<z.ZodNullable<z.ZodString>>;
52
+ publishedDate: z.ZodOptional<z.ZodNullable<z.ZodString>>;
53
+ score: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
54
+ image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
55
+ favicon: z.ZodOptional<z.ZodNullable<z.ZodString>>;
56
+ text: z.ZodOptional<z.ZodString>;
57
+ highlights: z.ZodOptional<z.ZodArray<z.ZodString>>;
58
+ summary: z.ZodOptional<z.ZodString>;
59
+ }, z.core.$strip>>;
60
+ }, z.core.$strip>;
61
+ };
62
+ readonly getContents: {
63
+ readonly effect: "read";
64
+ readonly idempotent: true;
65
+ readonly description: "Read pages by URL: their text, highlights or summary.";
66
+ readonly input: z.ZodObject<{
67
+ text: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodObject<{
68
+ maxCharacters: z.ZodOptional<z.ZodInt>;
69
+ }, z.core.$strip>]>>;
70
+ highlights: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodObject<{
71
+ maxCharacters: z.ZodOptional<z.ZodInt>;
72
+ query: z.ZodOptional<z.ZodString>;
73
+ }, z.core.$strip>]>>;
74
+ summary: z.ZodOptional<z.ZodObject<{
75
+ query: z.ZodOptional<z.ZodString>;
76
+ }, z.core.$strip>>;
77
+ maxAgeHours: z.ZodOptional<z.ZodInt>;
78
+ urls: z.ZodArray<z.ZodURL>;
79
+ }, z.core.$strip>;
80
+ readonly output: z.ZodObject<{
81
+ results: z.ZodArray<z.ZodObject<{
82
+ id: z.ZodString;
83
+ url: z.ZodString;
84
+ title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
85
+ author: z.ZodOptional<z.ZodNullable<z.ZodString>>;
86
+ publishedDate: z.ZodOptional<z.ZodNullable<z.ZodString>>;
87
+ score: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
88
+ image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
89
+ favicon: z.ZodOptional<z.ZodNullable<z.ZodString>>;
90
+ text: z.ZodOptional<z.ZodString>;
91
+ highlights: z.ZodOptional<z.ZodArray<z.ZodString>>;
92
+ summary: z.ZodOptional<z.ZodString>;
93
+ }, z.core.$strip>>;
94
+ statuses: z.ZodArray<z.ZodObject<{
95
+ id: z.ZodString;
96
+ status: z.ZodString;
97
+ error: z.ZodOptional<z.ZodNullable<z.ZodObject<{
98
+ tag: z.ZodOptional<z.ZodString>;
99
+ httpStatusCode: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
100
+ }, z.core.$strip>>>;
101
+ }, z.core.$strip>>;
102
+ }, z.core.$strip>;
103
+ };
104
+ readonly findSimilar: {
105
+ readonly effect: "read";
106
+ readonly idempotent: true;
107
+ readonly description: "Find pages like the one at a URL.";
108
+ readonly input: z.ZodObject<{
109
+ numResults: z.ZodOptional<z.ZodInt>;
110
+ includeDomains: z.ZodOptional<z.ZodArray<z.ZodString>>;
111
+ excludeDomains: z.ZodOptional<z.ZodArray<z.ZodString>>;
112
+ startPublishedDate: z.ZodOptional<z.ZodString>;
113
+ endPublishedDate: z.ZodOptional<z.ZodString>;
114
+ contents: z.ZodOptional<z.ZodObject<{
115
+ text: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodObject<{
116
+ maxCharacters: z.ZodOptional<z.ZodInt>;
117
+ }, z.core.$strip>]>>;
118
+ highlights: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodObject<{
119
+ maxCharacters: z.ZodOptional<z.ZodInt>;
120
+ query: z.ZodOptional<z.ZodString>;
121
+ }, z.core.$strip>]>>;
122
+ summary: z.ZodOptional<z.ZodObject<{
123
+ query: z.ZodOptional<z.ZodString>;
124
+ }, z.core.$strip>>;
125
+ maxAgeHours: z.ZodOptional<z.ZodInt>;
126
+ }, z.core.$strip>>;
127
+ url: z.ZodURL;
128
+ excludeSourceDomain: z.ZodOptional<z.ZodBoolean>;
129
+ }, z.core.$strip>;
130
+ readonly output: z.ZodObject<{
131
+ results: z.ZodArray<z.ZodObject<{
132
+ id: z.ZodString;
133
+ url: z.ZodString;
134
+ title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
135
+ author: z.ZodOptional<z.ZodNullable<z.ZodString>>;
136
+ publishedDate: z.ZodOptional<z.ZodNullable<z.ZodString>>;
137
+ score: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
138
+ image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
139
+ favicon: z.ZodOptional<z.ZodNullable<z.ZodString>>;
140
+ text: z.ZodOptional<z.ZodString>;
141
+ highlights: z.ZodOptional<z.ZodArray<z.ZodString>>;
142
+ summary: z.ZodOptional<z.ZodString>;
143
+ }, z.core.$strip>>;
144
+ }, z.core.$strip>;
145
+ };
146
+ readonly answer: {
147
+ readonly effect: "read";
148
+ readonly idempotent: true;
149
+ readonly description: "Answer a question from a web search, with the pages the answer cites.";
150
+ readonly input: z.ZodObject<{
151
+ query: z.ZodString;
152
+ text: z.ZodOptional<z.ZodBoolean>;
153
+ }, z.core.$strip>;
154
+ readonly output: z.ZodObject<{
155
+ answer: z.ZodString;
156
+ citations: z.ZodArray<z.ZodObject<{
157
+ id: z.ZodString;
158
+ url: z.ZodString;
159
+ title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
160
+ author: z.ZodOptional<z.ZodNullable<z.ZodString>>;
161
+ publishedDate: z.ZodOptional<z.ZodNullable<z.ZodString>>;
162
+ score: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
163
+ image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
164
+ favicon: z.ZodOptional<z.ZodNullable<z.ZodString>>;
165
+ text: z.ZodOptional<z.ZodString>;
166
+ highlights: z.ZodOptional<z.ZodArray<z.ZodString>>;
167
+ summary: z.ZodOptional<z.ZodString>;
168
+ }, z.core.$strip>>;
169
+ }, z.core.$strip>;
170
+ };
171
+ };
172
+ }>;
@@ -0,0 +1,113 @@
1
+ import { defineConnector, vendorInfo } from "@sanoma-ai/workflows";
2
+ import { z } from "zod";
3
+ /** What of each page to return with it; none of them by default. Exa's `ContentsRequest`, cut. */
4
+ const contents = {
5
+ text: z
6
+ .union([z.literal(true), z.object({ maxCharacters: z.int().positive().optional() })])
7
+ .optional()
8
+ .describe("The page's text, all of it or up to `maxCharacters`"),
9
+ highlights: z
10
+ .union([
11
+ z.literal(true),
12
+ z.object({ maxCharacters: z.int().positive().optional(), query: z.string().min(1).optional() }),
13
+ ])
14
+ .optional()
15
+ .describe("The passages of the page most relevant to the query, or to `query`"),
16
+ summary: z
17
+ .object({ query: z.string().min(1).optional() })
18
+ .optional()
19
+ .describe("A summary of the page, written for `query` when given"),
20
+ maxAgeHours: z
21
+ .int()
22
+ .min(-1)
23
+ .optional()
24
+ .describe("The oldest cached copy to use, in hours, else Exa fetches the page again: 0 always, -1 never"),
25
+ };
26
+ /** The filters a search and a similar-page search share. Dates are ISO 8601, such as `2025-01-31`. */
27
+ const filters = {
28
+ numResults: z.int().min(1).max(100).optional().describe("How many results, 10 by default"),
29
+ includeDomains: z.array(z.string().min(1)).optional().describe("Only results from these domains"),
30
+ excludeDomains: z.array(z.string().min(1)).optional().describe("No results from these domains"),
31
+ startPublishedDate: z.string().min(1).optional().describe("Only pages published after this date"),
32
+ endPublishedDate: z.string().min(1).optional().describe("Only pages published before this date"),
33
+ contents: z.object(contents).optional().describe("What of each page to return with it"),
34
+ };
35
+ /** A page Exa found, with what of it the call asked for. */
36
+ const result = z.object({
37
+ id: z.string(),
38
+ url: z.string(),
39
+ title: z.string().nullish(),
40
+ author: z.string().nullish(),
41
+ publishedDate: z.string().nullish(),
42
+ /** How close the page is to the query or URL, from 0 to 1. */
43
+ score: z.number().nullish(),
44
+ image: z.string().nullish(),
45
+ favicon: z.string().nullish(),
46
+ text: z.string().optional(),
47
+ highlights: z.array(z.string()).optional(),
48
+ summary: z.string().optional(),
49
+ });
50
+ const results = z.object({ results: z.array(result) });
51
+ /**
52
+ * Exa, the web search API (https://exa.ai/docs/reference): a search, a page's contents, the pages
53
+ * like one, and an answer with its sources. Every operation reads; each call costs Exa credits.
54
+ */
55
+ export const exaOps = defineConnector("exa", {
56
+ web: {
57
+ search: {
58
+ effect: "read",
59
+ idempotent: true,
60
+ description: "Search the web, and return the pages found, with their text, highlights or summary if asked.",
61
+ input: z.object({
62
+ query: z.string().min(1),
63
+ type: z
64
+ .enum(["auto", "neural", "lite"])
65
+ .optional()
66
+ .describe("How Exa searches: `auto` by default, `lite` the cheapest (beta)"),
67
+ category: z
68
+ .enum(["company", "publication", "news", "personal site", "financial report", "people"])
69
+ .optional()
70
+ .describe("The kind of page to look for"),
71
+ ...filters,
72
+ }),
73
+ output: results,
74
+ },
75
+ getContents: {
76
+ effect: "read",
77
+ idempotent: true,
78
+ description: "Read pages by URL: their text, highlights or summary.",
79
+ input: z.object({ urls: z.array(z.url()).min(1), ...contents }),
80
+ output: results.extend({
81
+ /** Each URL's fetch: a page that could not be read is in here with an `error`, not in `results`. */
82
+ statuses: z.array(z.object({
83
+ id: z.string(),
84
+ /** `success`, or `error` with Exa's `tag`, such as `CRAWL_NOT_FOUND`. */
85
+ status: z.string(),
86
+ error: z.object({ tag: z.string().optional(), httpStatusCode: z.number().nullish() }).nullish(),
87
+ })),
88
+ }),
89
+ },
90
+ findSimilar: {
91
+ effect: "read",
92
+ idempotent: true,
93
+ description: "Find pages like the one at a URL.",
94
+ input: z.object({
95
+ url: z.url(),
96
+ excludeSourceDomain: z.boolean().optional().describe("No results from the URL's own domain"),
97
+ ...filters,
98
+ }),
99
+ output: results,
100
+ },
101
+ answer: {
102
+ effect: "read",
103
+ idempotent: true,
104
+ description: "Answer a question from a web search, with the pages the answer cites.",
105
+ input: z.object({
106
+ query: z.string().min(1),
107
+ text: z.boolean().optional().describe("Return each cited page's text too"),
108
+ }),
109
+ output: z.object({ answer: z.string(), citations: z.array(result) }),
110
+ },
111
+ },
112
+ }, vendorInfo(import.meta.url));
113
+ //# sourceMappingURL=connector.js.map
@@ -0,0 +1 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O,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,mCAAmC,CAAC;aAC3E,CAAC;YACF,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;SACrE;KACF;CACF,EACD,UAAU,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAC5B,CAAC"}
@@ -0,0 +1,10 @@
1
+ export interface ExaDriverOptions {
2
+ /** How long one request may take before it fails, retryable. Default 30 seconds: an answer takes several. */
3
+ timeoutMs?: number;
4
+ }
5
+ /**
6
+ * Calls Exa's search, contents, find-similar and answer endpoints through `exa-js`, Exa's own SDK,
7
+ * with the key in `EXA_API_KEY`, read on every call. Each operation only reads, so a retried call
8
+ * costs credits again and changes nothing.
9
+ */
10
+ export declare function exaDriver(options?: ExaDriverOptions): import("@sanoma-ai/workflows").Driver;
package/dist/driver.js ADDED
@@ -0,0 +1,105 @@
1
+ import { defineDriver, DriverError, retryableStatus } from "@sanoma-ai/workflows";
2
+ import { z } from "zod";
3
+ import { exaOps } from "./connector.js";
4
+ /** The environment variable the driver reads, on every call. */
5
+ const env = z.object({
6
+ EXA_API_KEY: z.string().describe("an API key, from the API Keys page of Exa's dashboard"),
7
+ });
8
+ /**
9
+ * `exa-js`, loaded at the first call: it brings the OpenAI SDK and zod 3, which a worker that
10
+ * never calls Exa (or the app listing the connector) need not load. It also takes `fetch` as it
11
+ * loads, so a test's replay, listening by then, sees its requests.
12
+ */
13
+ const sdk = () => import("exa-js");
14
+ /**
15
+ * The DriverError for a request that failed. `exa-js` throws an `ExaError` with Exa's status for a
16
+ * reply, an `ExaTimeoutError` (status 408) past the timeout, and `fetch`'s own error for no reply.
17
+ */
18
+ function failure(op, { ExaError, ExaTimeoutError }, error) {
19
+ if (error instanceof ExaTimeoutError) {
20
+ return new DriverError(`exa: ${op} timed out after ${error.timeout} ms`, {
21
+ retryable: true,
22
+ status: error.statusCode,
23
+ cause: error,
24
+ });
25
+ }
26
+ if (error instanceof ExaError) {
27
+ const { statusCode: status, message, code } = error;
28
+ // A 429 (rate limit) and a 5xx (overloaded, past its deadline) pass; a 402 (credits or budget spent) does not in a retry's wait.
29
+ // Exa's `tag` is not kept: `exa-js` reads a `code` only from an error object, which these endpoints do not send.
30
+ return new DriverError(`exa: ${op} failed (${status}): ${message}`, {
31
+ retryable: retryableStatus(status),
32
+ status,
33
+ cause: error,
34
+ ...(code === undefined ? {} : { vendorCode: code }),
35
+ });
36
+ }
37
+ return new DriverError(`exa: ${op} got no reply`, { retryable: true, cause: error });
38
+ }
39
+ /**
40
+ * Calls Exa's search, contents, find-similar and answer endpoints through `exa-js`, Exa's own SDK,
41
+ * with the key in `EXA_API_KEY`, read on every call. Each operation only reads, so a retried call
42
+ * costs credits again and changes nothing.
43
+ */
44
+ export function exaDriver(options = {}) {
45
+ const timeoutMs = options.timeoutMs ?? 30_000;
46
+ // Checked here, as `exa-js` checks it, so a bad option fails when the driver is made, not as each call's request.
47
+ if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 2_147_483_647) {
48
+ throw new RangeError(`exaDriver: timeoutMs must be a whole number of ms from 1 to 2147483647, not ${timeoutMs}`);
49
+ }
50
+ /** The client for the last key read, made again only when `EXA_API_KEY` changes. */
51
+ let client;
52
+ /** Sends `request` on a client with the key in `EXA_API_KEY`, and maps what fails. */
53
+ async function calling(op, request) {
54
+ const key = process.env.EXA_API_KEY;
55
+ if (!key)
56
+ throw new DriverError("exa: EXA_API_KEY is not set", { retryable: false });
57
+ const exaJs = await sdk();
58
+ if (client?.key !== key) {
59
+ try {
60
+ // Warnings Exa returns about a request are not the worker's to print.
61
+ client = { key, exa: new exaJs.Exa(key, undefined, { timeout: timeoutMs, warnings: "silent" }) };
62
+ }
63
+ catch {
64
+ // A key no header can carry, such as one with a newline: a retry would fail alike. No
65
+ // `cause`: the platform's message for it holds the header's value, the key.
66
+ throw new DriverError(`exa: ${op} could not build its request`, { retryable: false });
67
+ }
68
+ }
69
+ let reply;
70
+ try {
71
+ reply = await request(client.exa);
72
+ }
73
+ catch (error) {
74
+ throw failure(op, exaJs, error);
75
+ }
76
+ // A 200 with an empty body: Exa answered, so a retry would only spend credits again.
77
+ if (typeof reply !== "object" || reply === null) {
78
+ throw new DriverError(`exa: ${op} replied with no body`, { retryable: false });
79
+ }
80
+ return reply;
81
+ }
82
+ return defineDriver(exaOps, {
83
+ web: {
84
+ // `contents: false` when none is asked for, as the SDK would otherwise ask for each page's
85
+ // text. Two calls, not `contents ?? false`: the SDK's overloads take each but not the union.
86
+ // The runtime's parse of the output keeps `results` and drops the rest of the reply.
87
+ search: ({ query, contents, ...rest }) => calling("web.search", (exa) => contents ? exa.search(query, { ...rest, contents }) : exa.search(query, { ...rest, contents: false })),
88
+ getContents: async ({ urls, ...contents }) => {
89
+ const { results, statuses = [] } = await calling("web.getContents", (exa) => exa.getContents(urls, contents));
90
+ return { results, statuses };
91
+ },
92
+ // Deprecated in the SDK, which has no other way to find pages like one; the endpoint stands.
93
+ findSimilar: ({ url, contents, ...rest }) => calling("web.findSimilar", (exa) => contents ? exa.findSimilar(url, { ...rest, contents }) : exa.findSimilar(url, { ...rest, contents: false })),
94
+ answer: async ({ query, text }) => {
95
+ const { answer, citations } = await calling("web.answer", (exa) => exa.answer(query, { text }));
96
+ // Text, unless the request sends an `outputSchema`, which this one never does.
97
+ if (typeof answer !== "string") {
98
+ throw new DriverError("exa: web.answer replied without an answer in text", { retryable: false });
99
+ }
100
+ return { answer, citations };
101
+ },
102
+ },
103
+ }, { env });
104
+ }
105
+ //# sourceMappingURL=driver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"driver.js","sourceRoot":"","sources":["../src/driver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAElF,OAAO,EAA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E,CAC1C,OAAO,CAAC,iBAAiB,EAAE,CAAC,GAAG,EAAE,EAAE,CACjC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,EAAE,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,EAAE,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAC5G;YACH,MAAM,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE;gBAChC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,OAAO,CAAC,YAAY,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;gBAChG,+EAA+E;gBAC/E,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;oBAC/B,MAAM,IAAI,WAAW,CAAC,mDAAmD,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;gBACnG,CAAC;gBACD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;YAC/B,CAAC;SACF;KACF,EACD,EAAE,GAAG,EAAE,CACR,CAAC;AACJ,CAAC"}
package/dist/fake.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { type FakeOptions } from "@sanoma-ai/workflows/fake";
2
+ /** A page of the fake web. */
3
+ export interface FakeExaPage {
4
+ url: string;
5
+ title: string;
6
+ text: string;
7
+ }
8
+ export interface FakeExaState extends Record<string, unknown> {
9
+ /** The pages the fake has served, by URL; a test may put its own here for `getContents` to read. */
10
+ pages: Record<string, FakeExaPage>;
11
+ }
12
+ /**
13
+ * An in-memory Exa for tests: it searches nothing, and makes up up to three pages for a query or
14
+ * a URL, from them alone, so the same call always finds the same pages. A page it served stays in
15
+ * `state.pages`, which `getContents` reads; a URL on a `.invalid` host cannot be read
16
+ * (`CRAWL_NOT_FOUND`), as on the web.
17
+ */
18
+ export declare function fakeExa(options?: FakeOptions): import("@sanoma-ai/workflows/fake").Fake<FakeExaState, "exa.web.answer" | "exa.web.findSimilar" | "exa.web.getContents" | "exa.web.search">;
package/dist/fake.js ADDED
@@ -0,0 +1,86 @@
1
+ import { defineFake } from "@sanoma-ai/workflows/fake";
2
+ import { exaOps } from "./connector.js";
3
+ /** How many results the fake returns at most, whatever `numResults` asks. */
4
+ const MAX_RESULTS = 3;
5
+ const slug = (s) => s
6
+ .toLowerCase()
7
+ .replaceAll(/[^a-z0-9]+/g, "-")
8
+ .replaceAll(/^-|-$/g, "") || "page";
9
+ /** Where the fake's pages are: the first domain the filters include and do not exclude, else `usual`, else one made up. */
10
+ function hostFor(usual, { includeDomains, excludeDomains = [] }) {
11
+ const allowed = (host) => !excludeDomains.includes(host);
12
+ if (includeDomains?.length)
13
+ return includeDomains.find(allowed) ?? `other.${includeDomains[0]}.example`;
14
+ return allowed(usual) ? usual : `other.${usual}.example`;
15
+ }
16
+ /** A page as Exa returns it, with what of it `contents` asks for. */
17
+ function shown(page, contents = {}, score) {
18
+ const { text, highlights, summary } = contents;
19
+ const max = (option) => typeof option === "object" ? option.maxCharacters : undefined;
20
+ return {
21
+ id: page.url,
22
+ url: page.url,
23
+ title: page.title,
24
+ author: null,
25
+ publishedDate: null,
26
+ ...(score === undefined ? {} : { score }),
27
+ ...(text ? { text: page.text.slice(0, max(text)) } : {}),
28
+ ...(highlights ? { highlights: [page.text.split(". ")[0].slice(0, max(highlights))] } : {}),
29
+ ...(summary ? { summary: `A summary of ${page.title}${summary.query ? `, for "${summary.query}"` : ""}.` } : {}),
30
+ };
31
+ }
32
+ /**
33
+ * An in-memory Exa for tests: it searches nothing, and makes up up to three pages for a query or
34
+ * a URL, from them alone, so the same call always finds the same pages. A page it served stays in
35
+ * `state.pages`, which `getContents` reads; a URL on a `.invalid` host cannot be read
36
+ * (`CRAWL_NOT_FOUND`), as on the web.
37
+ */
38
+ export function fakeExa(options = {}) {
39
+ return defineFake(exaOps, {
40
+ initial: () => ({ pages: {} }),
41
+ ops: (state) => {
42
+ /** The page at a URL: one the fake served or was given, else one made up from the URL. */
43
+ const page = (url, title = url) => (state.pages[url] ??= { url, title, text: `${title}. A page of the fake web, at ${url}.` });
44
+ /** Up to `n` pages under `base`, the first the closest. */
45
+ const found = (base, title, n = 10, contents) => Array.from({ length: Math.min(n, MAX_RESULTS) }, (_, i) => shown(page(`${base}-${i + 1}`, title(i + 1)), contents, 1 - i / 10));
46
+ return {
47
+ web: {
48
+ search: async ({ query, numResults, contents, ...filters }) => ({
49
+ results: found(`https://${hostFor("example.com", filters)}/${slug(query)}`, (i) => `${query} (${i})`, numResults, contents),
50
+ }),
51
+ findSimilar: async ({ url, numResults, excludeSourceDomain, contents, ...filters }) => {
52
+ const { hostname, pathname } = new URL(url);
53
+ const excluded = excludeSourceDomain ? [hostname] : [];
54
+ const host = hostFor(hostname, {
55
+ ...filters,
56
+ excludeDomains: [...excluded, ...(filters.excludeDomains ?? [])],
57
+ });
58
+ return {
59
+ results: found(`https://${host}/like-${slug(pathname)}`, (i) => `Like ${url} (${i})`, numResults, contents),
60
+ };
61
+ },
62
+ getContents: async ({ urls, ...contents }) => {
63
+ const read = urls.map((url) => ({ url, ok: !URL.parse(url)?.hostname.endsWith(".invalid") }));
64
+ return {
65
+ // Like Exa, a page's text when the call asks for none of it.
66
+ results: read
67
+ .filter((r) => r.ok)
68
+ .map((r) => shown(page(r.url), contents.text || contents.highlights || contents.summary ? contents : { text: true })),
69
+ statuses: read.map(({ url: id, ok }) => ok
70
+ ? { id, status: "success" }
71
+ : { id, status: "error", error: { tag: "CRAWL_NOT_FOUND", httpStatusCode: 404 } }),
72
+ };
73
+ },
74
+ answer: async ({ query, text }) => {
75
+ const source = page(`https://example.com/${slug(query)}-1`, `${query} (1)`);
76
+ return {
77
+ answer: `A made-up answer to "${query}", from ${source.url}.`,
78
+ citations: [shown(source, { text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E,EAAE,EAAE,CACrC,EAAE;gCACA,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE;gCAC3B,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,iBAAiB,EAAE,cAAc,EAAE,GAAG,EAAE,EAAE,CACpF;yBACF,CAAC;oBACJ,CAAC;oBACD,MAAM,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE;wBAChC,MAAM,MAAM,GAAG,IAAI,CAAC,uBAAuB,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,KAAK,MAAM,CAAC,CAAC;wBAC5E,OAAO;4BACL,MAAM,EAAE,wBAAwB,KAAK,WAAW,MAAM,CAAC,GAAG,GAAG;4BAC7D,SAAS,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;yBACrC,CAAC;oBACJ,CAAC;iBACF;aACF,CAAC;QACJ,CAAC;KACF,EACD,OAAO,CACR,CAAC;AACJ,CAAC"}
@@ -0,0 +1,172 @@
1
+ /**
2
+ * Exa web search: `web.search`, `web.getContents`, `web.findSimilar` and `web.answer`. It carries
3
+ * its live driver (`exaDriver`), which reads its key when called, its fake (`fakeExa`), of which
4
+ * each sandbox run makes its own, and its steps for Gherkin tests (`exaSteps`).
5
+ */
6
+ export declare const exa: import("@sanoma-ai/workflows").Connector<"exa", {
7
+ readonly web: {
8
+ readonly search: {
9
+ readonly effect: "read";
10
+ readonly idempotent: true;
11
+ readonly description: "Search the web, and return the pages found, with their text, highlights or summary if asked.";
12
+ readonly input: import("zod").ZodObject<{
13
+ numResults: import("zod").ZodOptional<import("zod").ZodInt>;
14
+ includeDomains: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
15
+ excludeDomains: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
16
+ startPublishedDate: import("zod").ZodOptional<import("zod").ZodString>;
17
+ endPublishedDate: import("zod").ZodOptional<import("zod").ZodString>;
18
+ contents: import("zod").ZodOptional<import("zod").ZodObject<{
19
+ text: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodLiteral<true>, import("zod").ZodObject<{
20
+ maxCharacters: import("zod").ZodOptional<import("zod").ZodInt>;
21
+ }, import("zod/v4/core").$strip>]>>;
22
+ highlights: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodLiteral<true>, import("zod").ZodObject<{
23
+ maxCharacters: import("zod").ZodOptional<import("zod").ZodInt>;
24
+ query: import("zod").ZodOptional<import("zod").ZodString>;
25
+ }, import("zod/v4/core").$strip>]>>;
26
+ summary: import("zod").ZodOptional<import("zod").ZodObject<{
27
+ query: import("zod").ZodOptional<import("zod").ZodString>;
28
+ }, import("zod/v4/core").$strip>>;
29
+ maxAgeHours: import("zod").ZodOptional<import("zod").ZodInt>;
30
+ }, import("zod/v4/core").$strip>>;
31
+ query: import("zod").ZodString;
32
+ type: import("zod").ZodOptional<import("zod").ZodEnum<{
33
+ auto: "auto";
34
+ lite: "lite";
35
+ neural: "neural";
36
+ }>>;
37
+ category: import("zod").ZodOptional<import("zod").ZodEnum<{
38
+ company: "company";
39
+ "financial report": "financial report";
40
+ news: "news";
41
+ people: "people";
42
+ "personal site": "personal site";
43
+ publication: "publication";
44
+ }>>;
45
+ }, import("zod/v4/core").$strip>;
46
+ readonly output: import("zod").ZodObject<{
47
+ results: import("zod").ZodArray<import("zod").ZodObject<{
48
+ id: import("zod").ZodString;
49
+ url: import("zod").ZodString;
50
+ title: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
51
+ author: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
52
+ publishedDate: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
53
+ score: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodNumber>>;
54
+ image: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
55
+ favicon: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
56
+ text: import("zod").ZodOptional<import("zod").ZodString>;
57
+ highlights: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
58
+ summary: import("zod").ZodOptional<import("zod").ZodString>;
59
+ }, import("zod/v4/core").$strip>>;
60
+ }, import("zod/v4/core").$strip>;
61
+ };
62
+ readonly getContents: {
63
+ readonly effect: "read";
64
+ readonly idempotent: true;
65
+ readonly description: "Read pages by URL: their text, highlights or summary.";
66
+ readonly input: import("zod").ZodObject<{
67
+ text: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodLiteral<true>, import("zod").ZodObject<{
68
+ maxCharacters: import("zod").ZodOptional<import("zod").ZodInt>;
69
+ }, import("zod/v4/core").$strip>]>>;
70
+ highlights: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodLiteral<true>, import("zod").ZodObject<{
71
+ maxCharacters: import("zod").ZodOptional<import("zod").ZodInt>;
72
+ query: import("zod").ZodOptional<import("zod").ZodString>;
73
+ }, import("zod/v4/core").$strip>]>>;
74
+ summary: import("zod").ZodOptional<import("zod").ZodObject<{
75
+ query: import("zod").ZodOptional<import("zod").ZodString>;
76
+ }, import("zod/v4/core").$strip>>;
77
+ maxAgeHours: import("zod").ZodOptional<import("zod").ZodInt>;
78
+ urls: import("zod").ZodArray<import("zod").ZodURL>;
79
+ }, import("zod/v4/core").$strip>;
80
+ readonly output: import("zod").ZodObject<{
81
+ results: import("zod").ZodArray<import("zod").ZodObject<{
82
+ id: import("zod").ZodString;
83
+ url: import("zod").ZodString;
84
+ title: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
85
+ author: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
86
+ publishedDate: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
87
+ score: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodNumber>>;
88
+ image: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
89
+ favicon: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
90
+ text: import("zod").ZodOptional<import("zod").ZodString>;
91
+ highlights: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
92
+ summary: import("zod").ZodOptional<import("zod").ZodString>;
93
+ }, import("zod/v4/core").$strip>>;
94
+ statuses: import("zod").ZodArray<import("zod").ZodObject<{
95
+ id: import("zod").ZodString;
96
+ status: import("zod").ZodString;
97
+ error: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodObject<{
98
+ tag: import("zod").ZodOptional<import("zod").ZodString>;
99
+ httpStatusCode: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodNumber>>;
100
+ }, import("zod/v4/core").$strip>>>;
101
+ }, import("zod/v4/core").$strip>>;
102
+ }, import("zod/v4/core").$strip>;
103
+ };
104
+ readonly findSimilar: {
105
+ readonly effect: "read";
106
+ readonly idempotent: true;
107
+ readonly description: "Find pages like the one at a URL.";
108
+ readonly input: import("zod").ZodObject<{
109
+ numResults: import("zod").ZodOptional<import("zod").ZodInt>;
110
+ includeDomains: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
111
+ excludeDomains: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
112
+ startPublishedDate: import("zod").ZodOptional<import("zod").ZodString>;
113
+ endPublishedDate: import("zod").ZodOptional<import("zod").ZodString>;
114
+ contents: import("zod").ZodOptional<import("zod").ZodObject<{
115
+ text: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodLiteral<true>, import("zod").ZodObject<{
116
+ maxCharacters: import("zod").ZodOptional<import("zod").ZodInt>;
117
+ }, import("zod/v4/core").$strip>]>>;
118
+ highlights: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodLiteral<true>, import("zod").ZodObject<{
119
+ maxCharacters: import("zod").ZodOptional<import("zod").ZodInt>;
120
+ query: import("zod").ZodOptional<import("zod").ZodString>;
121
+ }, import("zod/v4/core").$strip>]>>;
122
+ summary: import("zod").ZodOptional<import("zod").ZodObject<{
123
+ query: import("zod").ZodOptional<import("zod").ZodString>;
124
+ }, import("zod/v4/core").$strip>>;
125
+ maxAgeHours: import("zod").ZodOptional<import("zod").ZodInt>;
126
+ }, import("zod/v4/core").$strip>>;
127
+ url: import("zod").ZodURL;
128
+ excludeSourceDomain: import("zod").ZodOptional<import("zod").ZodBoolean>;
129
+ }, import("zod/v4/core").$strip>;
130
+ readonly output: import("zod").ZodObject<{
131
+ results: import("zod").ZodArray<import("zod").ZodObject<{
132
+ id: import("zod").ZodString;
133
+ url: import("zod").ZodString;
134
+ title: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
135
+ author: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
136
+ publishedDate: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
137
+ score: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodNumber>>;
138
+ image: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
139
+ favicon: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
140
+ text: import("zod").ZodOptional<import("zod").ZodString>;
141
+ highlights: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
142
+ summary: import("zod").ZodOptional<import("zod").ZodString>;
143
+ }, import("zod/v4/core").$strip>>;
144
+ }, import("zod/v4/core").$strip>;
145
+ };
146
+ readonly answer: {
147
+ readonly effect: "read";
148
+ readonly idempotent: true;
149
+ readonly description: "Answer a question from a web search, with the pages the answer cites.";
150
+ readonly input: import("zod").ZodObject<{
151
+ query: import("zod").ZodString;
152
+ text: import("zod").ZodOptional<import("zod").ZodBoolean>;
153
+ }, import("zod/v4/core").$strip>;
154
+ readonly output: import("zod").ZodObject<{
155
+ answer: import("zod").ZodString;
156
+ citations: import("zod").ZodArray<import("zod").ZodObject<{
157
+ id: import("zod").ZodString;
158
+ url: import("zod").ZodString;
159
+ title: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
160
+ author: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
161
+ publishedDate: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
162
+ score: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodNumber>>;
163
+ image: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
164
+ favicon: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
165
+ text: import("zod").ZodOptional<import("zod").ZodString>;
166
+ highlights: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
167
+ summary: import("zod").ZodOptional<import("zod").ZodString>;
168
+ }, import("zod/v4/core").$strip>>;
169
+ }, import("zod/v4/core").$strip>;
170
+ };
171
+ };
172
+ }>;
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ import { withSetup } from "@sanoma-ai/workflows";
2
+ import { exaOps } from "./connector.js";
3
+ import { exaDriver } from "./driver.js";
4
+ import { fakeExa } from "./fake.js";
5
+ import { exaSteps } from "./steps.js";
6
+ /**
7
+ * Exa web search: `web.search`, `web.getContents`, `web.findSimilar` and `web.answer`. It carries
8
+ * its live driver (`exaDriver`), which reads its key when called, its fake (`fakeExa`), of which
9
+ * each sandbox run makes its own, and its steps for Gherkin tests (`exaSteps`).
10
+ */
11
+ export const exa = withSetup(exaOps, { driver: exaDriver, fake: fakeExa, steps: exaSteps });
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC;;;;GAIG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Exa's steps for Gherkin tests: Exa failing the next search, and a search or a question the run
3
+ * made, by some of its query.
4
+ */
5
+ export declare const exaSteps: import("@sanoma-ai/workflows").Steps;
package/dist/steps.js ADDED
@@ -0,0 +1,24 @@
1
+ import { defineSteps } from "@sanoma-ai/workflows";
2
+ import { exaOps } from "./connector.js";
3
+ const { search, answer } = exaOps.web;
4
+ /** A `then` that the run called `op` with a query holding `text`, and what it says when not. */
5
+ const queried = (op, text, miss, none) => ({
6
+ op,
7
+ called: true,
8
+ check: (run) => {
9
+ const queries = run.calls(op).map((c) => c.input.query);
10
+ if (queries.some((q) => q.includes(text)))
11
+ return undefined;
12
+ return queries.length ? `${miss}; the queries were ${JSON.stringify(queries)}` : none;
13
+ },
14
+ });
15
+ /**
16
+ * Exa's steps for Gherkin tests: Exa failing the next search, and a search or a question the run
17
+ * made, by some of its query.
18
+ */
19
+ export const exaSteps = defineSteps("exa", ({ given, then }) => {
20
+ given("Exa fails to search once", () => ({ op: search, fault: "failNext" }));
21
+ then("Exa was searched for {string}", (text) => queried(search, text, `no Exa search was for "${text}"`, "Exa was not searched"));
22
+ then("Exa was asked {string}", (text) => queried(answer, text, `Exa was not asked "${text}"`, "Exa was asked nothing"));
23
+ });
24
+ //# sourceMappingURL=steps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"steps.js","sourceRoot":"","sources":["../src/steps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAwB,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,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M,EAAE,IAAI,EAAE,sBAAsB,IAAI,GAAG,EAAE,uBAAuB,CAAC,CAC9E,CAAC;AACJ,CAAC,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ Feature: Exa answers
2
+ A question answered from a search, with its sources. Each scenario runs on the fake and on
3
+ Exa's replies (test/fixtures/, named after the scenario), unless tagged @fake-only.
4
+
5
+ Scenario: Answer a question
6
+ When exa.web.answer is called with
7
+ | query | What does Exa do? |
8
+ Then Exa was asked "What does Exa do"
@@ -0,0 +1,19 @@
1
+ Feature: Exa contents
2
+ Pages read by URL. Each scenario runs on the fake and on Exa's replies (test/fixtures/, named
3
+ after the scenario), unless tagged @fake-only.
4
+
5
+ Scenario: Read a page
6
+ When exa.web.getContents is called with
7
+ """
8
+ { "urls": ["https://exa.ai/"], "text": true }
9
+ """
10
+ Then it returns
11
+ | statuses | [{ "id": "https://exa.ai/", "status": "success" }] |
12
+
13
+ Scenario: A page that cannot be read
14
+ When exa.web.getContents is called with
15
+ """
16
+ { "urls": ["https://gone.invalid/page"] }
17
+ """
18
+ Then it returns
19
+ | statuses | [{ "id": "https://gone.invalid/page", "status": "error", "error": { "tag": "CRAWL_NOT_FOUND", "httpStatusCode": 404 } }] |
@@ -0,0 +1,24 @@
1
+ Feature: Exa search
2
+ A search of the web, and the pages like a page. Each scenario runs on the fake and on Exa's
3
+ replies (test/fixtures/, named after the scenario), unless tagged @fake-only.
4
+
5
+ Scenario: Search the web
6
+ When exa.web.search is called with
7
+ """
8
+ { "query": "workflow automation for small businesses", "numResults": 2, "contents": { "text": { "maxCharacters": 200 } } }
9
+ """
10
+ Then Exa was searched for "workflow automation"
11
+
12
+ Scenario: Find similar pages
13
+ When exa.web.findSimilar is called with
14
+ """
15
+ { "url": "https://exa.ai/", "numResults": 2, "excludeSourceDomain": true }
16
+ """
17
+ Then exa.web.findSimilar was called
18
+
19
+ @fake-only
20
+ Scenario: Search while rate limited
21
+ Given exa.web.search is rate limited once
22
+ When exa.web.search is called with
23
+ | query | anything |
24
+ Then it fails with status 429
package/logo-dark.svg ADDED
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="-11.29 0 129 129"><path fill="white" fill-rule="evenodd" d="M106.417 9.30741C106.417 9.57392 106.324 9.83227 106.155 10.0388L61.5395 64.5L106.155 118.96C106.324 119.166 106.417 119.425 106.417 119.691V127.843C106.417 128.482 105.897 129 105.255 129H1.16175C0.520132 129 0 128.482 0 127.843V1.15695C0 0.517982 0.520131 0 1.16174 0H105.255C105.897 0 106.417 0.517984 106.417 1.15695V9.30741ZM19.0364 116.382H87.6921L53.363 74.4795L19.0364 116.382ZM12.6699 104.192L40.1426 70.6585H12.6699V104.192ZM12.6699 58.0409H39.8964L12.6699 24.8064V58.0409ZM53.363 54.5193L87.6921 12.6176H19.0364L53.363 54.5193Z"/></svg>
package/logo.svg ADDED
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="-11.29 0 129 129"><path fill="#0143D9" fill-rule="evenodd" d="M106.417 9.30741C106.417 9.57392 106.324 9.83227 106.155 10.0388L61.5395 64.5L106.155 118.96C106.324 119.166 106.417 119.425 106.417 119.691V127.843C106.417 128.482 105.897 129 105.255 129H1.16175C0.520132 129 0 128.482 0 127.843V1.15695C0 0.517982 0.520131 0 1.16174 0H105.255C105.897 0 106.417 0.517984 106.417 1.15695V9.30741ZM19.0364 116.382H87.6921L53.363 74.4795L19.0364 116.382ZM12.6699 104.192L40.1426 70.6585H12.6699V104.192ZM12.6699 58.0409H39.8964L12.6699 24.8064V58.0409ZM53.363 54.5193L87.6921 12.6176H19.0364L53.363 54.5193Z"/></svg>
package/package.json CHANGED
@@ -1,6 +1,75 @@
1
1
  {
2
2
  "name": "@sanoma-ai/connector-exa",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "Exa web search, page contents, similar pages and cited answers for Sanoma workflows",
5
+ "keywords": [
6
+ "connector",
7
+ "exa",
8
+ "sanoma",
9
+ "sanoma-connector",
10
+ "search",
11
+ "web-search"
12
+ ],
13
+ "homepage": "https://github.com/Sanoma-AI/sanoma/tree/main/connectors/exa#readme",
14
+ "bugs": "https://github.com/Sanoma-AI/sanoma/issues",
15
+ "license": "FSL-1.1-ALv2",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/Sanoma-AI/sanoma.git",
19
+ "directory": "connectors/exa"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "features",
24
+ "logo.svg",
25
+ "logo-dark.svg",
26
+ "README.md",
27
+ "LICENSE"
28
+ ],
29
+ "type": "module",
30
+ "sideEffects": false,
31
+ "main": "./dist/index.js",
32
+ "types": "./dist/index.d.ts",
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist/index.d.ts",
36
+ "default": "./dist/index.js"
37
+ },
38
+ "./fake": {
39
+ "types": "./dist/fake.d.ts",
40
+ "default": "./dist/fake.js"
41
+ },
42
+ "./driver": {
43
+ "types": "./dist/driver.d.ts",
44
+ "default": "./dist/driver.js"
45
+ }
46
+ },
47
+ "publishConfig": {
48
+ "access": "public"
49
+ },
50
+ "dependencies": {
51
+ "exa-js": "^2.26.0"
52
+ },
53
+ "devDependencies": {
54
+ "@sanoma-ai/workflows": "0.6.0",
55
+ "msw": "^3.0.2",
56
+ "zod": "^4.6.5"
57
+ },
58
+ "peerDependencies": {
59
+ "@sanoma-ai/workflows": "^0.6.0",
60
+ "zod": "^4"
61
+ },
62
+ "engines": {
63
+ "node": ">=24"
64
+ },
65
+ "sanoma": {
66
+ "title": "Exa",
67
+ "logo": "logo.svg",
68
+ "logoDark": "logo-dark.svg"
69
+ },
70
+ "scripts": {
71
+ "build": "tsc -p tsconfig.build.json",
72
+ "clean": "rm -rf dist",
73
+ "watch": "tsc -p tsconfig.build.json --watch --preserveWatchOutput"
74
+ }
6
75
  }