@scavio/ai-sdk 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # @scavio/ai-sdk
2
+
3
+ Scavio search tools for the [Vercel AI SDK](https://sdk.vercel.ai). Give any AI SDK agent real-time
4
+ search across Google, YouTube, Reddit, Amazon, Walmart, TikTok, and Instagram via the
5
+ [Scavio](https://scavio.dev) API.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @scavio/ai-sdk ai
11
+ export SCAVIO_API_KEY=sk_live_your_key
12
+ ```
13
+
14
+ `ai` and `zod` are peer dependencies; `scavio` (the JS SDK) is bundled.
15
+
16
+ ## Usage
17
+
18
+ ```ts
19
+ import { generateText, stepCountIs } from "ai";
20
+ import { openai } from "@ai-sdk/openai";
21
+ import { scavioSearch, scavioTools } from "@scavio/ai-sdk";
22
+
23
+ // A single tool:
24
+ const res = await generateText({
25
+ model: openai("gpt-4o-mini"),
26
+ tools: { scavio_search: scavioSearch({ maxResults: 5 }) },
27
+ stopWhen: stepCountIs(3),
28
+ prompt: "Find the official GitHub repo of the Agno framework",
29
+ });
30
+
31
+ // Or all tools at once:
32
+ const res2 = await generateText({
33
+ model: openai("gpt-4o-mini"),
34
+ tools: scavioTools(),
35
+ stopWhen: stepCountIs(3),
36
+ prompt: "Compare prices for a mechanical keyboard on Amazon and Walmart",
37
+ });
38
+ ```
39
+
40
+ ## Tools
41
+
42
+ | Factory | Tool name | Provider |
43
+ | --- | --- | --- |
44
+ | `scavioSearch` | `scavio_search` | Google web search |
45
+ | `scavioYoutubeSearch` | `scavio_youtube_search` | YouTube video search |
46
+ | `scavioRedditSearch` | `scavio_reddit_search` | Reddit (2 credits) |
47
+ | `scavioAmazonSearch` | `scavio_amazon_search` | Amazon products |
48
+ | `scavioWalmartSearch` | `scavio_walmart_search` | Walmart products |
49
+ | `scavioTiktokSearch` | `scavio_tiktok_search` | TikTok videos |
50
+ | `scavioInstagramSearch` | `scavio_instagram_search` | Instagram users |
51
+ | `scavioTools` | all of the above | bundle for `tools:` |
52
+
53
+ Each factory accepts `{ apiKey?, maxResults?, ...ScavioConfig }`. The key falls back to `SCAVIO_API_KEY`.
54
+ Get a key at [dashboard.scavio.dev](https://dashboard.scavio.dev).
55
+
56
+ ## License
57
+
58
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ scavioAmazonSearch: () => scavioAmazonSearch,
24
+ scavioInstagramSearch: () => scavioInstagramSearch,
25
+ scavioRedditSearch: () => scavioRedditSearch,
26
+ scavioSearch: () => scavioSearch,
27
+ scavioTiktokSearch: () => scavioTiktokSearch,
28
+ scavioTools: () => scavioTools,
29
+ scavioWalmartSearch: () => scavioWalmartSearch,
30
+ scavioYoutubeSearch: () => scavioYoutubeSearch
31
+ });
32
+ module.exports = __toCommonJS(index_exports);
33
+ var import_ai = require("ai");
34
+ var import_zod = require("zod");
35
+ var import_scavio = require("scavio");
36
+ function client(config) {
37
+ return new import_scavio.Scavio({ apiKey: config?.apiKey });
38
+ }
39
+ function trim(res, max) {
40
+ const results = res.results;
41
+ if (Array.isArray(results) && results.length > max) {
42
+ return { ...res, results: results.slice(0, max) };
43
+ }
44
+ return res;
45
+ }
46
+ function scavioSearch(config) {
47
+ const c = client(config);
48
+ const max = config?.maxResults ?? 10;
49
+ return (0, import_ai.tool)({
50
+ description: "Search the web with Google via the Scavio API. Returns real-time organic search results.",
51
+ inputSchema: import_zod.z.object({
52
+ query: import_zod.z.string().describe("The search query."),
53
+ country_code: import_zod.z.string().optional().describe('Two-letter country code to localize results, e.g. "us".'),
54
+ language: import_zod.z.string().optional().describe('Two-letter language code, e.g. "en".')
55
+ }),
56
+ execute: async ({ query, country_code, language }) => trim(await c.google.search({ query, country_code, language }), max)
57
+ });
58
+ }
59
+ function scavioYoutubeSearch(config) {
60
+ const c = client(config);
61
+ const max = config?.maxResults ?? 10;
62
+ return (0, import_ai.tool)({
63
+ description: "Search YouTube for videos via the Scavio API.",
64
+ inputSchema: import_zod.z.object({
65
+ query: import_zod.z.string().describe("The search query.")
66
+ }),
67
+ execute: async ({ query }) => trim(await c.youtube.search({ query }), max)
68
+ });
69
+ }
70
+ function scavioRedditSearch(config) {
71
+ const c = client(config);
72
+ const max = config?.maxResults ?? 10;
73
+ return (0, import_ai.tool)({
74
+ description: "Search Reddit posts and communities via the Scavio API.",
75
+ inputSchema: import_zod.z.object({
76
+ query: import_zod.z.string().describe("The search query."),
77
+ sort: import_zod.z.string().optional().describe("Sort order for results.")
78
+ }),
79
+ execute: async ({ query, sort }) => trim(await c.reddit.search({ query, sort }), max)
80
+ });
81
+ }
82
+ function scavioAmazonSearch(config) {
83
+ const c = client(config);
84
+ const max = config?.maxResults ?? 10;
85
+ return (0, import_ai.tool)({
86
+ description: "Search Amazon for products via the Scavio API.",
87
+ inputSchema: import_zod.z.object({
88
+ query: import_zod.z.string().describe("The product search query."),
89
+ domain: import_zod.z.string().optional().describe('Amazon domain, e.g. "amazon.com".')
90
+ }),
91
+ execute: async ({ query, domain }) => trim(await c.amazon.search({ query, domain }), max)
92
+ });
93
+ }
94
+ function scavioWalmartSearch(config) {
95
+ const c = client(config);
96
+ const max = config?.maxResults ?? 10;
97
+ return (0, import_ai.tool)({
98
+ description: "Search Walmart for products via the Scavio API.",
99
+ inputSchema: import_zod.z.object({
100
+ query: import_zod.z.string().describe("The product search query.")
101
+ }),
102
+ execute: async ({ query }) => trim(await c.walmart.search({ query }), max)
103
+ });
104
+ }
105
+ function scavioTiktokSearch(config) {
106
+ const c = client(config);
107
+ const max = config?.maxResults ?? 10;
108
+ return (0, import_ai.tool)({
109
+ description: "Search TikTok for videos by keyword via the Scavio API.",
110
+ inputSchema: import_zod.z.object({
111
+ keyword: import_zod.z.string().describe("The search keyword."),
112
+ sort_type: import_zod.z.string().optional().describe("Sort order for results."),
113
+ publish_time: import_zod.z.string().optional().describe("Filter by publish time window.")
114
+ }),
115
+ execute: async ({ keyword, sort_type, publish_time }) => trim(await c.tiktok.searchVideos({ keyword, sort_type, publish_time }), max)
116
+ });
117
+ }
118
+ function scavioInstagramSearch(config) {
119
+ const c = client(config);
120
+ const max = config?.maxResults ?? 10;
121
+ return (0, import_ai.tool)({
122
+ description: "Search Instagram for users by keyword via the Scavio API.",
123
+ inputSchema: import_zod.z.object({
124
+ keyword: import_zod.z.string().describe("The search keyword.")
125
+ }),
126
+ execute: async ({ keyword }) => trim(await c.instagram.searchUsers({ keyword }), max)
127
+ });
128
+ }
129
+ function scavioTools(config) {
130
+ return {
131
+ scavio_search: scavioSearch(config),
132
+ scavio_youtube_search: scavioYoutubeSearch(config),
133
+ scavio_reddit_search: scavioRedditSearch(config),
134
+ scavio_amazon_search: scavioAmazonSearch(config),
135
+ scavio_walmart_search: scavioWalmartSearch(config),
136
+ scavio_tiktok_search: scavioTiktokSearch(config),
137
+ scavio_instagram_search: scavioInstagramSearch(config)
138
+ };
139
+ }
140
+ // Annotate the CommonJS export names for ESM import in node:
141
+ 0 && (module.exports = {
142
+ scavioAmazonSearch,
143
+ scavioInstagramSearch,
144
+ scavioRedditSearch,
145
+ scavioSearch,
146
+ scavioTiktokSearch,
147
+ scavioTools,
148
+ scavioWalmartSearch,
149
+ scavioYoutubeSearch
150
+ });
151
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport { Scavio, type ScavioConfig } from \"scavio\";\n\nexport interface ScavioToolConfig extends ScavioConfig {\n /** Max number of results to keep in `results`-style lists. Defaults to 10. */\n maxResults?: number;\n}\n\nfunction client(config?: ScavioToolConfig): Scavio {\n return new Scavio({ apiKey: config?.apiKey });\n}\n\nfunction trim(res: Record<string, unknown>, max: number): Record<string, unknown> {\n const results = res.results;\n if (Array.isArray(results) && results.length > max) {\n return { ...res, results: results.slice(0, max) };\n }\n return res;\n}\n\n/** Google web search. */\nexport function scavioSearch(config?: ScavioToolConfig) {\n const c = client(config);\n const max = config?.maxResults ?? 10;\n return tool({\n description:\n \"Search the web with Google via the Scavio API. Returns real-time organic search results.\",\n inputSchema: z.object({\n query: z.string().describe(\"The search query.\"),\n country_code: z.string().optional().describe('Two-letter country code to localize results, e.g. \"us\".'),\n language: z.string().optional().describe('Two-letter language code, e.g. \"en\".'),\n }),\n execute: async ({ query, country_code, language }) =>\n trim(await c.google.search({ query, country_code, language }), max),\n });\n}\n\n/** YouTube video search. */\nexport function scavioYoutubeSearch(config?: ScavioToolConfig) {\n const c = client(config);\n const max = config?.maxResults ?? 10;\n return tool({\n description: \"Search YouTube for videos via the Scavio API.\",\n inputSchema: z.object({\n query: z.string().describe(\"The search query.\"),\n }),\n execute: async ({ query }) => trim(await c.youtube.search({ query }), max),\n });\n}\n\n/** Reddit post/community search (costs 2 credits). */\nexport function scavioRedditSearch(config?: ScavioToolConfig) {\n const c = client(config);\n const max = config?.maxResults ?? 10;\n return tool({\n description: \"Search Reddit posts and communities via the Scavio API.\",\n inputSchema: z.object({\n query: z.string().describe(\"The search query.\"),\n sort: z.string().optional().describe(\"Sort order for results.\"),\n }),\n execute: async ({ query, sort }) => trim(await c.reddit.search({ query, sort }), max),\n });\n}\n\n/** Amazon product search. */\nexport function scavioAmazonSearch(config?: ScavioToolConfig) {\n const c = client(config);\n const max = config?.maxResults ?? 10;\n return tool({\n description: \"Search Amazon for products via the Scavio API.\",\n inputSchema: z.object({\n query: z.string().describe(\"The product search query.\"),\n domain: z.string().optional().describe('Amazon domain, e.g. \"amazon.com\".'),\n }),\n execute: async ({ query, domain }) => trim(await c.amazon.search({ query, domain }), max),\n });\n}\n\n/** Walmart product search. */\nexport function scavioWalmartSearch(config?: ScavioToolConfig) {\n const c = client(config);\n const max = config?.maxResults ?? 10;\n return tool({\n description: \"Search Walmart for products via the Scavio API.\",\n inputSchema: z.object({\n query: z.string().describe(\"The product search query.\"),\n }),\n execute: async ({ query }) => trim(await c.walmart.search({ query }), max),\n });\n}\n\n/** TikTok video search. */\nexport function scavioTiktokSearch(config?: ScavioToolConfig) {\n const c = client(config);\n const max = config?.maxResults ?? 10;\n return tool({\n description: \"Search TikTok for videos by keyword via the Scavio API.\",\n inputSchema: z.object({\n keyword: z.string().describe(\"The search keyword.\"),\n sort_type: z.string().optional().describe(\"Sort order for results.\"),\n publish_time: z.string().optional().describe(\"Filter by publish time window.\"),\n }),\n execute: async ({ keyword, sort_type, publish_time }) =>\n trim(await c.tiktok.searchVideos({ keyword, sort_type, publish_time }), max),\n });\n}\n\n/** Instagram user search. */\nexport function scavioInstagramSearch(config?: ScavioToolConfig) {\n const c = client(config);\n const max = config?.maxResults ?? 10;\n return tool({\n description: \"Search Instagram for users by keyword via the Scavio API.\",\n inputSchema: z.object({\n keyword: z.string().describe(\"The search keyword.\"),\n }),\n execute: async ({ keyword }) => trim(await c.instagram.searchUsers({ keyword }), max),\n });\n}\n\n/**\n * All Scavio tools as an object keyed by tool name, ready to spread into the\n * `tools` option of `generateText` / `streamText`.\n */\nexport function scavioTools(config?: ScavioToolConfig) {\n return {\n scavio_search: scavioSearch(config),\n scavio_youtube_search: scavioYoutubeSearch(config),\n scavio_reddit_search: scavioRedditSearch(config),\n scavio_amazon_search: scavioAmazonSearch(config),\n scavio_walmart_search: scavioWalmartSearch(config),\n scavio_tiktok_search: scavioTiktokSearch(config),\n scavio_instagram_search: scavioInstagramSearch(config),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAqB;AACrB,iBAAkB;AAClB,oBAA0C;AAO1C,SAAS,OAAO,QAAmC;AACjD,SAAO,IAAI,qBAAO,EAAE,QAAQ,QAAQ,OAAO,CAAC;AAC9C;AAEA,SAAS,KAAK,KAA8B,KAAsC;AAChF,QAAM,UAAU,IAAI;AACpB,MAAI,MAAM,QAAQ,OAAO,KAAK,QAAQ,SAAS,KAAK;AAClD,WAAO,EAAE,GAAG,KAAK,SAAS,QAAQ,MAAM,GAAG,GAAG,EAAE;AAAA,EAClD;AACA,SAAO;AACT;AAGO,SAAS,aAAa,QAA2B;AACtD,QAAM,IAAI,OAAO,MAAM;AACvB,QAAM,MAAM,QAAQ,cAAc;AAClC,aAAO,gBAAK;AAAA,IACV,aACE;AAAA,IACF,aAAa,aAAE,OAAO;AAAA,MACpB,OAAO,aAAE,OAAO,EAAE,SAAS,mBAAmB;AAAA,MAC9C,cAAc,aAAE,OAAO,EAAE,SAAS,EAAE,SAAS,yDAAyD;AAAA,MACtG,UAAU,aAAE,OAAO,EAAE,SAAS,EAAE,SAAS,sCAAsC;AAAA,IACjF,CAAC;AAAA,IACD,SAAS,OAAO,EAAE,OAAO,cAAc,SAAS,MAC9C,KAAK,MAAM,EAAE,OAAO,OAAO,EAAE,OAAO,cAAc,SAAS,CAAC,GAAG,GAAG;AAAA,EACtE,CAAC;AACH;AAGO,SAAS,oBAAoB,QAA2B;AAC7D,QAAM,IAAI,OAAO,MAAM;AACvB,QAAM,MAAM,QAA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/C,sBAAsB,mBAAmB,MAAM;AAAA,IAC/C,uBAAuB,oBAAoB,MAAM;AAAA,IACjD,sBAAsB,mBAAmB,MAAM;AAAA,IAC/C,yBAAyB,sBAAsB,MAAM;AAAA,EACvD;AACF;","names":[]}
@@ -0,0 +1,76 @@
1
+ import * as ai from 'ai';
2
+ import { ScavioConfig } from 'scavio';
3
+
4
+ interface ScavioToolConfig extends ScavioConfig {
5
+ /** Max number of results to keep in `results`-style lists. Defaults to 10. */
6
+ maxResults?: number;
7
+ }
8
+ /** Google web search. */
9
+ declare function scavioSearch(config?: ScavioToolConfig): ai.Tool<{
10
+ query: string;
11
+ country_code?: string | undefined;
12
+ language?: string | undefined;
13
+ }, Record<string, unknown>>;
14
+ /** YouTube video search. */
15
+ declare function scavioYoutubeSearch(config?: ScavioToolConfig): ai.Tool<{
16
+ query: string;
17
+ }, Record<string, unknown>>;
18
+ /** Reddit post/community search (costs 2 credits). */
19
+ declare function scavioRedditSearch(config?: ScavioToolConfig): ai.Tool<{
20
+ query: string;
21
+ sort?: string | undefined;
22
+ }, Record<string, unknown>>;
23
+ /** Amazon product search. */
24
+ declare function scavioAmazonSearch(config?: ScavioToolConfig): ai.Tool<{
25
+ query: string;
26
+ domain?: string | undefined;
27
+ }, Record<string, unknown>>;
28
+ /** Walmart product search. */
29
+ declare function scavioWalmartSearch(config?: ScavioToolConfig): ai.Tool<{
30
+ query: string;
31
+ }, Record<string, unknown>>;
32
+ /** TikTok video search. */
33
+ declare function scavioTiktokSearch(config?: ScavioToolConfig): ai.Tool<{
34
+ keyword: string;
35
+ sort_type?: string | undefined;
36
+ publish_time?: string | undefined;
37
+ }, Record<string, unknown>>;
38
+ /** Instagram user search. */
39
+ declare function scavioInstagramSearch(config?: ScavioToolConfig): ai.Tool<{
40
+ keyword: string;
41
+ }, Record<string, unknown>>;
42
+ /**
43
+ * All Scavio tools as an object keyed by tool name, ready to spread into the
44
+ * `tools` option of `generateText` / `streamText`.
45
+ */
46
+ declare function scavioTools(config?: ScavioToolConfig): {
47
+ scavio_search: ai.Tool<{
48
+ query: string;
49
+ country_code?: string | undefined;
50
+ language?: string | undefined;
51
+ }, Record<string, unknown>>;
52
+ scavio_youtube_search: ai.Tool<{
53
+ query: string;
54
+ }, Record<string, unknown>>;
55
+ scavio_reddit_search: ai.Tool<{
56
+ query: string;
57
+ sort?: string | undefined;
58
+ }, Record<string, unknown>>;
59
+ scavio_amazon_search: ai.Tool<{
60
+ query: string;
61
+ domain?: string | undefined;
62
+ }, Record<string, unknown>>;
63
+ scavio_walmart_search: ai.Tool<{
64
+ query: string;
65
+ }, Record<string, unknown>>;
66
+ scavio_tiktok_search: ai.Tool<{
67
+ keyword: string;
68
+ sort_type?: string | undefined;
69
+ publish_time?: string | undefined;
70
+ }, Record<string, unknown>>;
71
+ scavio_instagram_search: ai.Tool<{
72
+ keyword: string;
73
+ }, Record<string, unknown>>;
74
+ };
75
+
76
+ export { type ScavioToolConfig, scavioAmazonSearch, scavioInstagramSearch, scavioRedditSearch, scavioSearch, scavioTiktokSearch, scavioTools, scavioWalmartSearch, scavioYoutubeSearch };
@@ -0,0 +1,76 @@
1
+ import * as ai from 'ai';
2
+ import { ScavioConfig } from 'scavio';
3
+
4
+ interface ScavioToolConfig extends ScavioConfig {
5
+ /** Max number of results to keep in `results`-style lists. Defaults to 10. */
6
+ maxResults?: number;
7
+ }
8
+ /** Google web search. */
9
+ declare function scavioSearch(config?: ScavioToolConfig): ai.Tool<{
10
+ query: string;
11
+ country_code?: string | undefined;
12
+ language?: string | undefined;
13
+ }, Record<string, unknown>>;
14
+ /** YouTube video search. */
15
+ declare function scavioYoutubeSearch(config?: ScavioToolConfig): ai.Tool<{
16
+ query: string;
17
+ }, Record<string, unknown>>;
18
+ /** Reddit post/community search (costs 2 credits). */
19
+ declare function scavioRedditSearch(config?: ScavioToolConfig): ai.Tool<{
20
+ query: string;
21
+ sort?: string | undefined;
22
+ }, Record<string, unknown>>;
23
+ /** Amazon product search. */
24
+ declare function scavioAmazonSearch(config?: ScavioToolConfig): ai.Tool<{
25
+ query: string;
26
+ domain?: string | undefined;
27
+ }, Record<string, unknown>>;
28
+ /** Walmart product search. */
29
+ declare function scavioWalmartSearch(config?: ScavioToolConfig): ai.Tool<{
30
+ query: string;
31
+ }, Record<string, unknown>>;
32
+ /** TikTok video search. */
33
+ declare function scavioTiktokSearch(config?: ScavioToolConfig): ai.Tool<{
34
+ keyword: string;
35
+ sort_type?: string | undefined;
36
+ publish_time?: string | undefined;
37
+ }, Record<string, unknown>>;
38
+ /** Instagram user search. */
39
+ declare function scavioInstagramSearch(config?: ScavioToolConfig): ai.Tool<{
40
+ keyword: string;
41
+ }, Record<string, unknown>>;
42
+ /**
43
+ * All Scavio tools as an object keyed by tool name, ready to spread into the
44
+ * `tools` option of `generateText` / `streamText`.
45
+ */
46
+ declare function scavioTools(config?: ScavioToolConfig): {
47
+ scavio_search: ai.Tool<{
48
+ query: string;
49
+ country_code?: string | undefined;
50
+ language?: string | undefined;
51
+ }, Record<string, unknown>>;
52
+ scavio_youtube_search: ai.Tool<{
53
+ query: string;
54
+ }, Record<string, unknown>>;
55
+ scavio_reddit_search: ai.Tool<{
56
+ query: string;
57
+ sort?: string | undefined;
58
+ }, Record<string, unknown>>;
59
+ scavio_amazon_search: ai.Tool<{
60
+ query: string;
61
+ domain?: string | undefined;
62
+ }, Record<string, unknown>>;
63
+ scavio_walmart_search: ai.Tool<{
64
+ query: string;
65
+ }, Record<string, unknown>>;
66
+ scavio_tiktok_search: ai.Tool<{
67
+ keyword: string;
68
+ sort_type?: string | undefined;
69
+ publish_time?: string | undefined;
70
+ }, Record<string, unknown>>;
71
+ scavio_instagram_search: ai.Tool<{
72
+ keyword: string;
73
+ }, Record<string, unknown>>;
74
+ };
75
+
76
+ export { type ScavioToolConfig, scavioAmazonSearch, scavioInstagramSearch, scavioRedditSearch, scavioSearch, scavioTiktokSearch, scavioTools, scavioWalmartSearch, scavioYoutubeSearch };
package/dist/index.js ADDED
@@ -0,0 +1,119 @@
1
+ // src/index.ts
2
+ import { tool } from "ai";
3
+ import { z } from "zod";
4
+ import { Scavio } from "scavio";
5
+ function client(config) {
6
+ return new Scavio({ apiKey: config?.apiKey });
7
+ }
8
+ function trim(res, max) {
9
+ const results = res.results;
10
+ if (Array.isArray(results) && results.length > max) {
11
+ return { ...res, results: results.slice(0, max) };
12
+ }
13
+ return res;
14
+ }
15
+ function scavioSearch(config) {
16
+ const c = client(config);
17
+ const max = config?.maxResults ?? 10;
18
+ return tool({
19
+ description: "Search the web with Google via the Scavio API. Returns real-time organic search results.",
20
+ inputSchema: z.object({
21
+ query: z.string().describe("The search query."),
22
+ country_code: z.string().optional().describe('Two-letter country code to localize results, e.g. "us".'),
23
+ language: z.string().optional().describe('Two-letter language code, e.g. "en".')
24
+ }),
25
+ execute: async ({ query, country_code, language }) => trim(await c.google.search({ query, country_code, language }), max)
26
+ });
27
+ }
28
+ function scavioYoutubeSearch(config) {
29
+ const c = client(config);
30
+ const max = config?.maxResults ?? 10;
31
+ return tool({
32
+ description: "Search YouTube for videos via the Scavio API.",
33
+ inputSchema: z.object({
34
+ query: z.string().describe("The search query.")
35
+ }),
36
+ execute: async ({ query }) => trim(await c.youtube.search({ query }), max)
37
+ });
38
+ }
39
+ function scavioRedditSearch(config) {
40
+ const c = client(config);
41
+ const max = config?.maxResults ?? 10;
42
+ return tool({
43
+ description: "Search Reddit posts and communities via the Scavio API.",
44
+ inputSchema: z.object({
45
+ query: z.string().describe("The search query."),
46
+ sort: z.string().optional().describe("Sort order for results.")
47
+ }),
48
+ execute: async ({ query, sort }) => trim(await c.reddit.search({ query, sort }), max)
49
+ });
50
+ }
51
+ function scavioAmazonSearch(config) {
52
+ const c = client(config);
53
+ const max = config?.maxResults ?? 10;
54
+ return tool({
55
+ description: "Search Amazon for products via the Scavio API.",
56
+ inputSchema: z.object({
57
+ query: z.string().describe("The product search query."),
58
+ domain: z.string().optional().describe('Amazon domain, e.g. "amazon.com".')
59
+ }),
60
+ execute: async ({ query, domain }) => trim(await c.amazon.search({ query, domain }), max)
61
+ });
62
+ }
63
+ function scavioWalmartSearch(config) {
64
+ const c = client(config);
65
+ const max = config?.maxResults ?? 10;
66
+ return tool({
67
+ description: "Search Walmart for products via the Scavio API.",
68
+ inputSchema: z.object({
69
+ query: z.string().describe("The product search query.")
70
+ }),
71
+ execute: async ({ query }) => trim(await c.walmart.search({ query }), max)
72
+ });
73
+ }
74
+ function scavioTiktokSearch(config) {
75
+ const c = client(config);
76
+ const max = config?.maxResults ?? 10;
77
+ return tool({
78
+ description: "Search TikTok for videos by keyword via the Scavio API.",
79
+ inputSchema: z.object({
80
+ keyword: z.string().describe("The search keyword."),
81
+ sort_type: z.string().optional().describe("Sort order for results."),
82
+ publish_time: z.string().optional().describe("Filter by publish time window.")
83
+ }),
84
+ execute: async ({ keyword, sort_type, publish_time }) => trim(await c.tiktok.searchVideos({ keyword, sort_type, publish_time }), max)
85
+ });
86
+ }
87
+ function scavioInstagramSearch(config) {
88
+ const c = client(config);
89
+ const max = config?.maxResults ?? 10;
90
+ return tool({
91
+ description: "Search Instagram for users by keyword via the Scavio API.",
92
+ inputSchema: z.object({
93
+ keyword: z.string().describe("The search keyword.")
94
+ }),
95
+ execute: async ({ keyword }) => trim(await c.instagram.searchUsers({ keyword }), max)
96
+ });
97
+ }
98
+ function scavioTools(config) {
99
+ return {
100
+ scavio_search: scavioSearch(config),
101
+ scavio_youtube_search: scavioYoutubeSearch(config),
102
+ scavio_reddit_search: scavioRedditSearch(config),
103
+ scavio_amazon_search: scavioAmazonSearch(config),
104
+ scavio_walmart_search: scavioWalmartSearch(config),
105
+ scavio_tiktok_search: scavioTiktokSearch(config),
106
+ scavio_instagram_search: scavioInstagramSearch(config)
107
+ };
108
+ }
109
+ export {
110
+ scavioAmazonSearch,
111
+ scavioInstagramSearch,
112
+ scavioRedditSearch,
113
+ scavioSearch,
114
+ scavioTiktokSearch,
115
+ scavioTools,
116
+ scavioWalmartSearch,
117
+ scavioYoutubeSearch
118
+ };
119
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport { Scavio, type ScavioConfig } from \"scavio\";\n\nexport interface ScavioToolConfig extends ScavioConfig {\n /** Max number of results to keep in `results`-style lists. Defaults to 10. */\n maxResults?: number;\n}\n\nfunction client(config?: ScavioToolConfig): Scavio {\n return new Scavio({ apiKey: config?.apiKey });\n}\n\nfunction trim(res: Record<string, unknown>, max: number): Record<string, unknown> {\n const results = res.results;\n if (Array.isArray(results) && results.length > max) {\n return { ...res, results: results.slice(0, max) };\n }\n return res;\n}\n\n/** Google web search. */\nexport function scavioSearch(config?: ScavioToolConfig) {\n const c = client(config);\n const max = config?.maxResults ?? 10;\n return tool({\n description:\n \"Search the web with Google via the Scavio API. Returns real-time organic search results.\",\n inputSchema: z.object({\n query: z.string().describe(\"The search query.\"),\n country_code: z.string().optional().describe('Two-letter country code to localize results, e.g. \"us\".'),\n language: z.string().optional().describe('Two-letter language code, e.g. \"en\".'),\n }),\n execute: async ({ query, country_code, language }) =>\n trim(await c.google.search({ query, country_code, language }), max),\n });\n}\n\n/** YouTube video search. */\nexport function scavioYoutubeSearch(config?: ScavioToolConfig) {\n const c = client(config);\n const max = config?.maxResults ?? 10;\n return tool({\n description: \"Search YouTube for videos via the Scavio API.\",\n inputSchema: z.object({\n query: z.string().describe(\"The search query.\"),\n }),\n execute: async ({ query }) => trim(await c.youtube.search({ query }), max),\n });\n}\n\n/** Reddit post/community search (costs 2 credits). */\nexport function scavioRedditSearch(config?: ScavioToolConfig) {\n const c = client(config);\n const max = config?.maxResults ?? 10;\n return tool({\n description: \"Search Reddit posts and communities via the Scavio API.\",\n inputSchema: z.object({\n query: z.string().describe(\"The search query.\"),\n sort: z.string().optional().describe(\"Sort order for results.\"),\n }),\n execute: async ({ query, sort }) => trim(await c.reddit.search({ query, sort }), max),\n });\n}\n\n/** Amazon product search. */\nexport function scavioAmazonSearch(config?: ScavioToolConfig) {\n const c = client(config);\n const max = config?.maxResults ?? 10;\n return tool({\n description: \"Search Amazon for products via the Scavio API.\",\n inputSchema: z.object({\n query: z.string().describe(\"The product search query.\"),\n domain: z.string().optional().describe('Amazon domain, e.g. \"amazon.com\".'),\n }),\n execute: async ({ query, domain }) => trim(await c.amazon.search({ query, domain }), max),\n });\n}\n\n/** Walmart product search. */\nexport function scavioWalmartSearch(config?: ScavioToolConfig) {\n const c = client(config);\n const max = config?.maxResults ?? 10;\n return tool({\n description: \"Search Walmart for products via the Scavio API.\",\n inputSchema: z.object({\n query: z.string().describe(\"The product search query.\"),\n }),\n execute: async ({ query }) => trim(await c.walmart.search({ query }), max),\n });\n}\n\n/** TikTok video search. */\nexport function scavioTiktokSearch(config?: ScavioToolConfig) {\n const c = client(config);\n const max = config?.maxResults ?? 10;\n return tool({\n description: \"Search TikTok for videos by keyword via the Scavio API.\",\n inputSchema: z.object({\n keyword: z.string().describe(\"The search keyword.\"),\n sort_type: z.string().optional().describe(\"Sort order for results.\"),\n publish_time: z.string().optional().describe(\"Filter by publish time window.\"),\n }),\n execute: async ({ keyword, sort_type, publish_time }) =>\n trim(await c.tiktok.searchVideos({ keyword, sort_type, publish_time }), max),\n });\n}\n\n/** Instagram user search. */\nexport function scavioInstagramSearch(config?: ScavioToolConfig) {\n const c = client(config);\n const max = config?.maxResults ?? 10;\n return tool({\n description: \"Search Instagram for users by keyword via the Scavio API.\",\n inputSchema: z.object({\n keyword: z.string().describe(\"The search keyword.\"),\n }),\n execute: async ({ keyword }) => trim(await c.instagram.searchUsers({ keyword }), max),\n });\n}\n\n/**\n * All Scavio tools as an object keyed by tool name, ready to spread into the\n * `tools` option of `generateText` / `streamText`.\n */\nexport function scavioTools(config?: ScavioToolConfig) {\n return {\n scavio_search: scavioSearch(config),\n scavio_youtube_search: scavioYoutubeSearch(config),\n scavio_reddit_search: scavioRedditSearch(config),\n scavio_amazon_search: scavioAmazonSearch(config),\n scavio_walmart_search: scavioWalmartSearch(config),\n scavio_tiktok_search: scavioTiktokSearch(config),\n scavio_instagram_search: scavioInstagramSearch(config),\n };\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,SAAS,SAAS;AAClB,SAAS,cAAiC;AAO1C,SAAS,OAAO,QAAmC;AACjD,SAAO,IAAI,OAAO,EAAE,QAAQ,QAAQ,OAAO,CAAC;AAC9C;AAEA,SAAS,KAAK,KAA8B,KAAsC;AAChF,QAAM,UAAU,IAAI;AACpB,MAAI,MAAM,QAAQ,OAAO,KAAK,QAAQ,SAAS,KAAK;AAClD,WAAO,EAAE,GAAG,KAAK,SAAS,QAAQ,MAAM,GAAG,GAAG,EAAE;AAAA,EAClD;AACA,SAAO;AACT;AAGO,SAAS,aAAa,QAA2B;AACtD,QAAM,IAAI,OAAO,MAAM;AACvB,QAAM,MAAM,QAAQ,cAAc;AAClC,SAAO,KAAK;AAAA,IACV,aACE;AAAA,IACF,aAAa,EAAE,OAAO;AAAA,MACpB,OAAO,EAAE,OAAO,EAAE,SAAS,mBAAmB;AAAA,MAC9C,cAAc,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,yDAAyD;AAAA,MACtG,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,sCAAsC;AAAA,IACjF,CAAC;AAAA,IACD,SAAS,OAAO,EAAE,OAAO,cAAc,SAAS,MAC9C,KAAK,MAAM,EAAE,OAAO,OAAO,EAAE,OAAO,cAAc,SAAS,CAAC,GAAG,GAAG;AAAA,EACtE,CAAC;AACH;AAGO,SAAS,oBAAoB,QAA2B;AAC7D,QAAM,IAAI,OAAO,MAAM;AACvB,QAAM,MAAM,QAAQ,cAAc;AAClC,SAAO,KAAK;AAAA,IACV,aAAa;AAAA,IACb,aAAa,EAAE,OAAO;AAAA,MACpB,OAAO,EAAE,OAAO,EAAE,SAAS,mBAAmB;AAAA,IAChD,CAAC;AAAA,IACD,SAAS,OAAO,EAAE,MAAM,MAAM,KAAK,MAAM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 "name": "@scavio/ai-sdk",
3
+ "version": "0.2.0",
4
+ "description": "Scavio search tools for the Vercel AI SDK (Google, YouTube, Reddit, Amazon, Walmart, TikTok, Instagram).",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "scripts": {
25
+ "build": "tsup",
26
+ "test": "vitest run",
27
+ "typecheck": "tsc --noEmit"
28
+ },
29
+ "keywords": [
30
+ "scavio",
31
+ "ai",
32
+ "vercel-ai-sdk",
33
+ "tools",
34
+ "search",
35
+ "agents"
36
+ ],
37
+ "license": "MIT",
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/scavio-ai/scavio-ai.git"
44
+ },
45
+ "homepage": "https://scavio.dev",
46
+ "peerDependencies": {
47
+ "ai": ">=4",
48
+ "zod": ">=3"
49
+ },
50
+ "dependencies": {
51
+ "scavio": "^0.2.1"
52
+ },
53
+ "devDependencies": {
54
+ "@ai-sdk/openai": "^3.0.74",
55
+ "ai": "^6.0.208",
56
+ "scavio": "^0.2.1",
57
+ "tsup": "^8.0.0",
58
+ "typescript": "^5.4.0",
59
+ "vitest": "^2.0.0",
60
+ "zod": "^3.23.0"
61
+ }
62
+ }