@agnocon/piece-bocha-search 0.0.5
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.MIT-AP +24 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/actions/web-search.d.ts +9 -0
- package/dist/lib/actions/web-search.d.ts.map +1 -0
- package/dist/lib/actions/web-search.js +76 -0
- package/dist/lib/actions/web-search.js.map +1 -0
- package/dist/lib/common/auth.d.ts +2 -0
- package/dist/lib/common/auth.d.ts.map +1 -0
- package/dist/lib/common/auth.js +48 -0
- package/dist/lib/common/auth.js.map +1 -0
- package/dist/lib/common/client.d.ts +11 -0
- package/dist/lib/common/client.d.ts.map +1 -0
- package/dist/lib/common/client.js +27 -0
- package/dist/lib/common/client.js.map +1 -0
- package/dist/lib/common/props.d.ts +3 -0
- package/dist/lib/common/props.d.ts.map +1 -0
- package/dist/lib/common/props.js +28 -0
- package/dist/lib/common/props.js.map +1 -0
- package/package.json +46 -0
- package/src/index.ts +28 -0
- package/src/lib/actions/web-search.ts +99 -0
- package/src/lib/common/auth.ts +45 -0
- package/src/lib/common/client.ts +31 -0
- package/src/lib/common/props.ts +24 -0
package/LICENSE.MIT-AP
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Activepieces AB
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
Derived helpers in this folder are adapted from Activepieces (MIT) for use
|
|
24
|
+
inside CX without depending on @activepieces/* packages at runtime.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,KAAK,yGAoBhB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bocha = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
// Vendored from Activepieces packages/pieces/community/bocha-search/src/index.ts (MIT).
|
|
6
|
+
// Generated by packages/scripts/vendor-ap.mjs - do not edit by hand.
|
|
7
|
+
const pieces_framework_1 = require("@agnocon/pieces-framework");
|
|
8
|
+
const pieces_common_1 = require("@agnocon/pieces-common");
|
|
9
|
+
const pieces_framework_2 = require("@agnocon/pieces-framework");
|
|
10
|
+
const web_search_1 = require("./lib/actions/web-search");
|
|
11
|
+
const auth_1 = require("./lib/common/auth");
|
|
12
|
+
const client_1 = require("./lib/common/client");
|
|
13
|
+
exports.bocha = (0, pieces_framework_1.createPiece)({
|
|
14
|
+
displayName: 'Bocha',
|
|
15
|
+
description: 'Web search API for AI agents, providing real-time web pages, images, and news.',
|
|
16
|
+
minimumSupportedRelease: '0.36.1',
|
|
17
|
+
logoUrl: 'https://cdn.activepieces.com/pieces/bocha-search.png',
|
|
18
|
+
categories: [pieces_framework_2.PieceCategory.ARTIFICIAL_INTELLIGENCE],
|
|
19
|
+
authors: ['BochaLab'],
|
|
20
|
+
auth: auth_1.bochaAuth,
|
|
21
|
+
actions: [
|
|
22
|
+
web_search_1.webSearchAction,
|
|
23
|
+
(0, pieces_common_1.createCustomApiCallAction)({
|
|
24
|
+
baseUrl: () => client_1.BASE_URL,
|
|
25
|
+
auth: auth_1.bochaAuth,
|
|
26
|
+
authMapping: (auth) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
return ({
|
|
28
|
+
Authorization: `Bearer ${auth.secret_text}`,
|
|
29
|
+
});
|
|
30
|
+
}),
|
|
31
|
+
}),
|
|
32
|
+
],
|
|
33
|
+
triggers: [],
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,wFAAwF;AACxF,qEAAqE;AACrE,gEAAwD;AACxD,0DAAmE;AACnE,gEAA0D;AAC1D,yDAA2D;AAC3D,4CAA8C;AAC9C,gDAA+C;AAElC,QAAA,KAAK,GAAG,IAAA,8BAAW,EAAC;IAC/B,WAAW,EAAE,OAAO;IACpB,WAAW,EACT,gFAAgF;IAClF,uBAAuB,EAAE,QAAQ;IACjC,OAAO,EAAE,sDAAsD;IAC/D,UAAU,EAAE,CAAC,gCAAa,CAAC,uBAAuB,CAAC;IACnD,OAAO,EAAE,CAAC,UAAU,CAAC;IACrB,IAAI,EAAE,gBAAS;IACf,OAAO,EAAE;QACP,4BAAe;QACf,IAAA,yCAAyB,EAAC;YACxB,OAAO,EAAE,GAAG,EAAE,CAAC,iBAAQ;YACvB,IAAI,EAAE,gBAAS;YACf,WAAW,EAAE,CAAO,IAAI,EAAE,EAAE;gBAAC,OAAA,CAAC;oBAC5B,aAAa,EAAE,UAAU,IAAI,CAAC,WAAW,EAAE;iBAC5C,CAAC,CAAA;cAAA;SACH,CAAC;KACH;IACD,QAAQ,EAAE,EAAE;CACb,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const webSearchAction: import("@agnocon/pieces-framework").IAction<import("@agnocon/pieces-framework").SecretTextProperty<true>, {
|
|
2
|
+
query: import("@agnocon/pieces-framework").ShortTextProperty<true>;
|
|
3
|
+
freshness: import("@agnocon/pieces-framework").StaticDropdownProperty<string, false>;
|
|
4
|
+
summary: import("@agnocon/pieces-framework").CheckboxProperty<false>;
|
|
5
|
+
include: import("@agnocon/pieces-framework").ShortTextProperty<false>;
|
|
6
|
+
exclude: import("@agnocon/pieces-framework").ShortTextProperty<false>;
|
|
7
|
+
count: import("@agnocon/pieces-framework").NumberProperty<false>;
|
|
8
|
+
}>;
|
|
9
|
+
//# sourceMappingURL=web-search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-search.d.ts","sourceRoot":"","sources":["../../../src/lib/actions/web-search.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,eAAe;;;;;;;EA+D1B,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.webSearchAction = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
// Vendored from Activepieces packages/pieces/community/bocha-search/src/lib/actions/web-search.ts (MIT).
|
|
6
|
+
// Generated by packages/scripts/vendor-ap.mjs - do not edit by hand.
|
|
7
|
+
const pieces_framework_1 = require("@agnocon/pieces-framework");
|
|
8
|
+
const pieces_common_1 = require("@agnocon/pieces-common");
|
|
9
|
+
const auth_1 = require("../common/auth");
|
|
10
|
+
const client_1 = require("../common/client");
|
|
11
|
+
const props_1 = require("../common/props");
|
|
12
|
+
exports.webSearchAction = (0, pieces_framework_1.createAction)({
|
|
13
|
+
name: 'web_search',
|
|
14
|
+
displayName: 'Web Search',
|
|
15
|
+
description: 'Search the web using Bocha.',
|
|
16
|
+
audience: 'both',
|
|
17
|
+
aiMetadata: {
|
|
18
|
+
description: 'Runs a Bocha web search for a query and returns matching web pages, optionally with per-result text summaries. Pick this to look up current information on the public web; results can be narrowed by freshness window, capped result count, and include/exclude domain lists (up to 100 domains each, separated by | or ,). Read-only and idempotent — repeating the same query just fetches results again.',
|
|
19
|
+
idempotent: true,
|
|
20
|
+
},
|
|
21
|
+
auth: auth_1.bochaAuth,
|
|
22
|
+
props: {
|
|
23
|
+
query: pieces_framework_1.Property.ShortText({
|
|
24
|
+
displayName: 'Query',
|
|
25
|
+
description: 'The search query.',
|
|
26
|
+
required: true,
|
|
27
|
+
}),
|
|
28
|
+
freshness: props_1.freshnessDropdown,
|
|
29
|
+
summary: pieces_framework_1.Property.Checkbox({
|
|
30
|
+
displayName: 'Show Summary',
|
|
31
|
+
description: 'Include a text summary for each search result.',
|
|
32
|
+
required: false,
|
|
33
|
+
defaultValue: true,
|
|
34
|
+
}),
|
|
35
|
+
include: pieces_framework_1.Property.ShortText({
|
|
36
|
+
displayName: 'Include Domains',
|
|
37
|
+
description: 'Limit search to specific domains. Separate multiple domains with | or , (max 100).',
|
|
38
|
+
required: false,
|
|
39
|
+
}),
|
|
40
|
+
exclude: pieces_framework_1.Property.ShortText({
|
|
41
|
+
displayName: 'Exclude Domains',
|
|
42
|
+
description: 'Exclude specific domains from search results. Separate multiple domains with | or , (max 100).',
|
|
43
|
+
required: false,
|
|
44
|
+
}),
|
|
45
|
+
count: props_1.countProp,
|
|
46
|
+
},
|
|
47
|
+
run(_a) {
|
|
48
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* ({ auth, propsValue }) {
|
|
49
|
+
var _b;
|
|
50
|
+
const body = {
|
|
51
|
+
query: propsValue['query'],
|
|
52
|
+
count: propsValue['count'],
|
|
53
|
+
};
|
|
54
|
+
if (propsValue['freshness']) {
|
|
55
|
+
body['freshness'] = propsValue['freshness'];
|
|
56
|
+
}
|
|
57
|
+
if (propsValue['summary'] !== undefined && propsValue['summary'] !== null) {
|
|
58
|
+
body['summary'] = propsValue['summary'];
|
|
59
|
+
}
|
|
60
|
+
if (propsValue['include']) {
|
|
61
|
+
body['include'] = propsValue['include'];
|
|
62
|
+
}
|
|
63
|
+
if (propsValue['exclude']) {
|
|
64
|
+
body['exclude'] = propsValue['exclude'];
|
|
65
|
+
}
|
|
66
|
+
const response = yield (0, client_1.makeRequest)({
|
|
67
|
+
token: auth.secret_text,
|
|
68
|
+
method: pieces_common_1.HttpMethod.POST,
|
|
69
|
+
path: '/web-search',
|
|
70
|
+
body,
|
|
71
|
+
});
|
|
72
|
+
return (_b = response.data) !== null && _b !== void 0 ? _b : {};
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
//# sourceMappingURL=web-search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-search.js","sourceRoot":"","sources":["../../../src/lib/actions/web-search.ts"],"names":[],"mappings":";;;;AAAA,yGAAyG;AACzG,qEAAqE;AACrE,gEAAmE;AACnE,0DAAoD;AACpD,yCAA2C;AAC3C,6CAA+C;AAC/C,2CAA+D;AAElD,QAAA,eAAe,GAAG,IAAA,+BAAY,EAAC;IAC1C,IAAI,EAAE,YAAY;IAClB,WAAW,EAAE,YAAY;IACzB,WAAW,EAAE,6BAA6B;IAC1C,QAAQ,EAAE,MAAM;IAChB,UAAU,EAAE;QACV,WAAW,EACT,8YAA8Y;QAChZ,UAAU,EAAE,IAAI;KACjB;IACD,IAAI,EAAE,gBAAS;IACf,KAAK,EAAE;QACL,KAAK,EAAE,2BAAQ,CAAC,SAAS,CAAC;YACxB,WAAW,EAAE,OAAO;YACpB,WAAW,EAAE,mBAAmB;YAChC,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,SAAS,EAAE,yBAAiB;QAC5B,OAAO,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YACzB,WAAW,EAAE,cAAc;YAC3B,WAAW,EAAE,gDAAgD;YAC7D,QAAQ,EAAE,KAAK;YACf,YAAY,EAAE,IAAI;SACnB,CAAC;QACF,OAAO,EAAE,2BAAQ,CAAC,SAAS,CAAC;YAC1B,WAAW,EAAE,iBAAiB;YAC9B,WAAW,EAAE,oFAAoF;YACjG,QAAQ,EAAE,KAAK;SAChB,CAAC;QACF,OAAO,EAAE,2BAAQ,CAAC,SAAS,CAAC;YAC1B,WAAW,EAAE,iBAAiB;YAC9B,WAAW,EAAE,gGAAgG;YAC7G,QAAQ,EAAE,KAAK;SAChB,CAAC;QACF,KAAK,EAAE,iBAAS;KACjB;IACK,GAAG;qEAAC,EAAE,IAAI,EAAE,UAAU,EAAE;;YAC5B,MAAM,IAAI,GAA4B;gBACpC,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC;gBAC1B,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC;aAC3B,CAAC;YACF,IAAI,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;gBAC5B,IAAI,CAAC,WAAW,CAAC,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;YAC9C,CAAC;YACD,IAAI,UAAU,CAAC,SAAS,CAAC,KAAK,SAAS,IAAI,UAAU,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE,CAAC;gBAC1E,IAAI,CAAC,SAAS,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;YAC1C,CAAC;YACD,IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC1B,IAAI,CAAC,SAAS,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;YAC1C,CAAC;YACD,IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC1B,IAAI,CAAC,SAAS,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;YAC1C,CAAC;YAED,MAAM,QAAQ,GAAG,MAAM,IAAA,oBAAW,EAAyB;gBACzD,KAAK,EAAE,IAAI,CAAC,WAAW;gBACvB,MAAM,EAAE,0BAAU,CAAC,IAAI;gBACvB,IAAI,EAAE,aAAa;gBACnB,IAAI;aACL,CAAC,CAAC;YAEH,OAAO,MAAA,QAAQ,CAAC,IAAI,mCAAI,EAAE,CAAC;QAC7B,CAAC;KAAA;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/lib/common/auth.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,SAAS,8DA4BpB,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bochaAuth = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
// Vendored from Activepieces packages/pieces/community/bocha-search/src/lib/common/auth.ts (MIT).
|
|
6
|
+
// Generated by packages/scripts/vendor-ap.mjs - do not edit by hand.
|
|
7
|
+
const pieces_framework_1 = require("@agnocon/pieces-framework");
|
|
8
|
+
const pieces_common_1 = require("@agnocon/pieces-common");
|
|
9
|
+
const client_1 = require("./client");
|
|
10
|
+
const markdownDescription = `
|
|
11
|
+
Follow these steps to obtain your Bocha API Key:
|
|
12
|
+
|
|
13
|
+
1. Visit [Bocha AI Open Platform](https://open.bochaai.com) and create an account.
|
|
14
|
+
2. Navigate to **API KEY Management** in the dashboard.
|
|
15
|
+
3. Copy your API key.
|
|
16
|
+
`;
|
|
17
|
+
exports.bochaAuth = pieces_framework_1.PieceAuth.SecretText({
|
|
18
|
+
displayName: 'API Key',
|
|
19
|
+
description: markdownDescription,
|
|
20
|
+
required: true,
|
|
21
|
+
validate: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
|
|
22
|
+
try {
|
|
23
|
+
yield (0, client_1.makeRequest)({
|
|
24
|
+
token: auth,
|
|
25
|
+
method: pieces_common_1.HttpMethod.POST,
|
|
26
|
+
path: '/web-search',
|
|
27
|
+
body: { query: 'test', count: 1 },
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
valid: true,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
const response = isRecord(e) ? e['response'] : undefined;
|
|
35
|
+
const status = isRecord(response) && typeof response['status'] === 'number'
|
|
36
|
+
? response['status']
|
|
37
|
+
: undefined;
|
|
38
|
+
if (status === 401 || status === 403) {
|
|
39
|
+
return { valid: false, error: 'Invalid API Key' };
|
|
40
|
+
}
|
|
41
|
+
return { valid: false, error: 'Could not connect to Bocha API. Please try again.' };
|
|
42
|
+
}
|
|
43
|
+
}),
|
|
44
|
+
});
|
|
45
|
+
function isRecord(value) {
|
|
46
|
+
return typeof value === 'object' && value !== null;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/lib/common/auth.ts"],"names":[],"mappings":";;;;AAAA,kGAAkG;AAClG,qEAAqE;AACrE,gEAAsD;AACtD,0DAAoD;AACpD,qCAAuC;AAEvC,MAAM,mBAAmB,GAAG;;;;;;CAM3B,CAAC;AAEW,QAAA,SAAS,GAAG,4BAAS,CAAC,UAAU,CAAC;IAC5C,WAAW,EAAE,SAAS;IACtB,WAAW,EAAE,mBAAmB;IAChC,QAAQ,EAAE,IAAI;IACd,QAAQ,EAAE,KAAiB,EAAE,oDAAZ,EAAE,IAAI,EAAE;QACvB,IAAI,CAAC;YACH,MAAM,IAAA,oBAAW,EAAC;gBAChB,KAAK,EAAE,IAAI;gBACX,MAAM,EAAE,0BAAU,CAAC,IAAI;gBACvB,IAAI,EAAE,aAAa;gBACnB,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE;aAClC,CAAC,CAAC;YACH,OAAO;gBACL,KAAK,EAAE,IAAI;aACZ,CAAC;QACJ,CAAC;QACD,OAAO,CAAC,EAAE,CAAC;YACT,MAAM,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YACzD,MAAM,MAAM,GACV,QAAQ,CAAC,QAAQ,CAAC,IAAI,OAAO,QAAQ,CAAC,QAAQ,CAAC,KAAK,QAAQ;gBAC1D,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBACpB,CAAC,CAAC,SAAS,CAAC;YAChB,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;gBACrC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC;YACpD,CAAC;YACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,mDAAmD,EAAE,CAAC;QACtF,CAAC;IACH,CAAC,CAAA;CACF,CAAC,CAAC;AAEH,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HttpMethod } from '@agnocon/pieces-common';
|
|
2
|
+
export declare function makeRequest<T = unknown>({ token, method, path, body, }: MakeRequestParams): Promise<T>;
|
|
3
|
+
export declare const BASE_URL = "https://api.bochaai.com/v1";
|
|
4
|
+
type MakeRequestParams = {
|
|
5
|
+
token: string;
|
|
6
|
+
method: HttpMethod;
|
|
7
|
+
path: string;
|
|
8
|
+
body?: unknown;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/lib/common/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkC,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpF,wBAAsB,WAAW,CAAC,CAAC,GAAG,OAAO,EAAE,EAC7C,KAAK,EACL,MAAM,EACN,IAAI,EACJ,IAAI,GACL,EAAE,iBAAiB,GAAG,OAAO,CAAC,CAAC,CAAC,CAchC;AAED,eAAO,MAAM,QAAQ,+BAA+B,CAAC;AAErD,KAAK,iBAAiB,GAAG;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BASE_URL = void 0;
|
|
4
|
+
exports.makeRequest = makeRequest;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
// Vendored from Activepieces packages/pieces/community/bocha-search/src/lib/common/client.ts (MIT).
|
|
7
|
+
// Generated by packages/scripts/vendor-ap.mjs - do not edit by hand.
|
|
8
|
+
const pieces_common_1 = require("@agnocon/pieces-common");
|
|
9
|
+
function makeRequest(_a) {
|
|
10
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* ({ token, method, path, body, }) {
|
|
11
|
+
const response = yield pieces_common_1.httpClient.sendRequest({
|
|
12
|
+
method,
|
|
13
|
+
url: `${exports.BASE_URL}${path}`,
|
|
14
|
+
authentication: {
|
|
15
|
+
type: pieces_common_1.AuthenticationType.BEARER_TOKEN,
|
|
16
|
+
token,
|
|
17
|
+
},
|
|
18
|
+
headers: {
|
|
19
|
+
'Content-Type': 'application/json',
|
|
20
|
+
},
|
|
21
|
+
body,
|
|
22
|
+
});
|
|
23
|
+
return response.body;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
exports.BASE_URL = 'https://api.bochaai.com/v1';
|
|
27
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/lib/common/client.ts"],"names":[],"mappings":";;;AAIA,kCAmBC;;AAvBD,oGAAoG;AACpG,qEAAqE;AACrE,0DAAoF;AAEpF,SAAsB,WAAW;iEAAc,EAC7C,KAAK,EACL,MAAM,EACN,IAAI,EACJ,IAAI,GACc;QAClB,MAAM,QAAQ,GAAG,MAAM,0BAAU,CAAC,WAAW,CAAI;YAC/C,MAAM;YACN,GAAG,EAAE,GAAG,gBAAQ,GAAG,IAAI,EAAE;YACzB,cAAc,EAAE;gBACd,IAAI,EAAE,kCAAkB,CAAC,YAAY;gBACrC,KAAK;aACN;YACD,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI;SACL,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;CAAA;AAEY,QAAA,QAAQ,GAAG,4BAA4B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../../../src/lib/common/props.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,iBAAiB,2EAc5B,CAAC;AAEH,eAAO,MAAM,SAAS,2DAKpB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.countProp = exports.freshnessDropdown = void 0;
|
|
4
|
+
// Vendored from Activepieces packages/pieces/community/bocha-search/src/lib/common/props.ts (MIT).
|
|
5
|
+
// Generated by packages/scripts/vendor-ap.mjs - do not edit by hand.
|
|
6
|
+
const pieces_framework_1 = require("@agnocon/pieces-framework");
|
|
7
|
+
exports.freshnessDropdown = pieces_framework_1.Property.StaticDropdown({
|
|
8
|
+
displayName: 'Freshness',
|
|
9
|
+
description: 'Filter results by time range. Defaults to no limit.',
|
|
10
|
+
required: false,
|
|
11
|
+
defaultValue: 'noLimit',
|
|
12
|
+
options: {
|
|
13
|
+
options: [
|
|
14
|
+
{ label: 'No Limit', value: 'noLimit' },
|
|
15
|
+
{ label: 'One Day', value: 'oneDay' },
|
|
16
|
+
{ label: 'One Week', value: 'oneWeek' },
|
|
17
|
+
{ label: 'One Month', value: 'oneMonth' },
|
|
18
|
+
{ label: 'One Year', value: 'oneYear' },
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
exports.countProp = pieces_framework_1.Property.Number({
|
|
23
|
+
displayName: 'Count',
|
|
24
|
+
description: 'Number of results to return (1-50). Defaults to 10.',
|
|
25
|
+
required: false,
|
|
26
|
+
defaultValue: 10,
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=props.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"props.js","sourceRoot":"","sources":["../../../src/lib/common/props.ts"],"names":[],"mappings":";;;AAAA,mGAAmG;AACnG,qEAAqE;AACrE,gEAAqD;AAExC,QAAA,iBAAiB,GAAG,2BAAQ,CAAC,cAAc,CAAC;IACvD,WAAW,EAAE,WAAW;IACxB,WAAW,EAAE,qDAAqD;IAClE,QAAQ,EAAE,KAAK;IACf,YAAY,EAAE,SAAS;IACvB,OAAO,EAAE;QACP,OAAO,EAAE;YACP,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE;YACvC,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE;YACrC,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE;YACvC,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE;YACzC,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE;SACxC;KACF;CACF,CAAC,CAAC;AAEU,QAAA,SAAS,GAAG,2BAAQ,CAAC,MAAM,CAAC;IACvC,WAAW,EAAE,OAAO;IACpB,WAAW,EAAE,qDAAqD;IAClE,QAAQ,EAAE,KAAK;IACf,YAAY,EAAE,EAAE;CACjB,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agnocon/piece-bocha-search",
|
|
3
|
+
"version": "0.0.5",
|
|
4
|
+
"description": "AgnoCon bocha search connector",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"src",
|
|
17
|
+
"LICENSE.MIT-AP"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.json",
|
|
21
|
+
"vendor": "node ../scripts/vendor-ap.mjs piece-bocha-search"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@agnocon/core-utils": "0.2.0",
|
|
25
|
+
"@agnocon/piece-types": "0.3.1",
|
|
26
|
+
"@agnocon/pieces-common": "0.12.8",
|
|
27
|
+
"@agnocon/pieces-framework": "0.36.0",
|
|
28
|
+
"tslib": "2.6.2"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "20.17.6",
|
|
32
|
+
"typescript": "5.5.4"
|
|
33
|
+
},
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"agnocon": {
|
|
36
|
+
"originVersion": "0.0.5"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "restricted",
|
|
40
|
+
"tag": "latest"
|
|
41
|
+
},
|
|
42
|
+
"keywords": [
|
|
43
|
+
"agnocon",
|
|
44
|
+
"connector"
|
|
45
|
+
]
|
|
46
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createPiece } from '@agnocon/pieces-framework';
|
|
2
|
+
import { createCustomApiCallAction } from '@agnocon/pieces-common';
|
|
3
|
+
import { PieceCategory } from '@agnocon/pieces-framework';
|
|
4
|
+
import { webSearchAction } from './lib/actions/web-search';
|
|
5
|
+
import { bochaAuth } from './lib/common/auth';
|
|
6
|
+
import { BASE_URL } from './lib/common/client';
|
|
7
|
+
|
|
8
|
+
export const bocha = createPiece({
|
|
9
|
+
displayName: 'Bocha',
|
|
10
|
+
description:
|
|
11
|
+
'Web search API for AI agents, providing real-time web pages, images, and news.',
|
|
12
|
+
minimumSupportedRelease: '0.36.1',
|
|
13
|
+
logoUrl: 'https://cdn.activepieces.com/pieces/bocha-search.png',
|
|
14
|
+
categories: [PieceCategory.ARTIFICIAL_INTELLIGENCE],
|
|
15
|
+
authors: ['BochaLab'],
|
|
16
|
+
auth: bochaAuth,
|
|
17
|
+
actions: [
|
|
18
|
+
webSearchAction,
|
|
19
|
+
createCustomApiCallAction({
|
|
20
|
+
baseUrl: () => BASE_URL,
|
|
21
|
+
auth: bochaAuth,
|
|
22
|
+
authMapping: async (auth) => ({
|
|
23
|
+
Authorization: `Bearer ${auth.secret_text}`,
|
|
24
|
+
}),
|
|
25
|
+
}),
|
|
26
|
+
],
|
|
27
|
+
triggers: [],
|
|
28
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { createAction, Property } from '@agnocon/pieces-framework';
|
|
2
|
+
import { HttpMethod } from '@agnocon/pieces-common';
|
|
3
|
+
import { bochaAuth } from '../common/auth';
|
|
4
|
+
import { makeRequest } from '../common/client';
|
|
5
|
+
import { freshnessDropdown, countProp } from '../common/props';
|
|
6
|
+
|
|
7
|
+
export const webSearchAction = createAction({
|
|
8
|
+
name: 'web_search',
|
|
9
|
+
displayName: 'Web Search',
|
|
10
|
+
description: 'Search the web using Bocha.',
|
|
11
|
+
audience: 'both',
|
|
12
|
+
aiMetadata: {
|
|
13
|
+
description:
|
|
14
|
+
'Runs a Bocha web search for a query and returns matching web pages, optionally with per-result text summaries. Pick this to look up current information on the public web; results can be narrowed by freshness window, capped result count, and include/exclude domain lists (up to 100 domains each, separated by | or ,). Read-only and idempotent — repeating the same query just fetches results again.',
|
|
15
|
+
idempotent: true,
|
|
16
|
+
},
|
|
17
|
+
auth: bochaAuth,
|
|
18
|
+
props: {
|
|
19
|
+
query: Property.ShortText({
|
|
20
|
+
displayName: 'Query',
|
|
21
|
+
description: 'The search query.',
|
|
22
|
+
required: true,
|
|
23
|
+
}),
|
|
24
|
+
freshness: freshnessDropdown,
|
|
25
|
+
summary: Property.Checkbox({
|
|
26
|
+
displayName: 'Show Summary',
|
|
27
|
+
description: 'Include a text summary for each search result.',
|
|
28
|
+
required: false,
|
|
29
|
+
defaultValue: true,
|
|
30
|
+
}),
|
|
31
|
+
include: Property.ShortText({
|
|
32
|
+
displayName: 'Include Domains',
|
|
33
|
+
description: 'Limit search to specific domains. Separate multiple domains with | or , (max 100).',
|
|
34
|
+
required: false,
|
|
35
|
+
}),
|
|
36
|
+
exclude: Property.ShortText({
|
|
37
|
+
displayName: 'Exclude Domains',
|
|
38
|
+
description: 'Exclude specific domains from search results. Separate multiple domains with | or , (max 100).',
|
|
39
|
+
required: false,
|
|
40
|
+
}),
|
|
41
|
+
count: countProp,
|
|
42
|
+
},
|
|
43
|
+
async run({ auth, propsValue }) {
|
|
44
|
+
const body: Record<string, unknown> = {
|
|
45
|
+
query: propsValue['query'],
|
|
46
|
+
count: propsValue['count'],
|
|
47
|
+
};
|
|
48
|
+
if (propsValue['freshness']) {
|
|
49
|
+
body['freshness'] = propsValue['freshness'];
|
|
50
|
+
}
|
|
51
|
+
if (propsValue['summary'] !== undefined && propsValue['summary'] !== null) {
|
|
52
|
+
body['summary'] = propsValue['summary'];
|
|
53
|
+
}
|
|
54
|
+
if (propsValue['include']) {
|
|
55
|
+
body['include'] = propsValue['include'];
|
|
56
|
+
}
|
|
57
|
+
if (propsValue['exclude']) {
|
|
58
|
+
body['exclude'] = propsValue['exclude'];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const response = await makeRequest<BochaWebSearchResponse>({
|
|
62
|
+
token: auth.secret_text,
|
|
63
|
+
method: HttpMethod.POST,
|
|
64
|
+
path: '/web-search',
|
|
65
|
+
body,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return response.data ?? {};
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
type BochaWebPage = {
|
|
73
|
+
id?: string;
|
|
74
|
+
name?: string;
|
|
75
|
+
url?: string;
|
|
76
|
+
displayUrl?: string;
|
|
77
|
+
snippet?: string;
|
|
78
|
+
summary?: string;
|
|
79
|
+
siteName?: string;
|
|
80
|
+
siteIcon?: string;
|
|
81
|
+
datePublished?: string;
|
|
82
|
+
dateLastCrawled?: string;
|
|
83
|
+
cachedPageUrl?: string;
|
|
84
|
+
language?: string;
|
|
85
|
+
isFamilyFriendly?: boolean;
|
|
86
|
+
isNavigational?: boolean;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
type BochaWebSearchResponse = {
|
|
90
|
+
data?: {
|
|
91
|
+
_type?: string;
|
|
92
|
+
queryContext?: unknown;
|
|
93
|
+
webPages?: {
|
|
94
|
+
value?: BochaWebPage[];
|
|
95
|
+
};
|
|
96
|
+
images?: unknown;
|
|
97
|
+
videos?: unknown;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { PieceAuth } from '@agnocon/pieces-framework';
|
|
2
|
+
import { HttpMethod } from '@agnocon/pieces-common';
|
|
3
|
+
import { makeRequest } from './client';
|
|
4
|
+
|
|
5
|
+
const markdownDescription = `
|
|
6
|
+
Follow these steps to obtain your Bocha API Key:
|
|
7
|
+
|
|
8
|
+
1. Visit [Bocha AI Open Platform](https://open.bochaai.com) and create an account.
|
|
9
|
+
2. Navigate to **API KEY Management** in the dashboard.
|
|
10
|
+
3. Copy your API key.
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
export const bochaAuth = PieceAuth.SecretText({
|
|
14
|
+
displayName: 'API Key',
|
|
15
|
+
description: markdownDescription,
|
|
16
|
+
required: true,
|
|
17
|
+
validate: async ({ auth }) => {
|
|
18
|
+
try {
|
|
19
|
+
await makeRequest({
|
|
20
|
+
token: auth,
|
|
21
|
+
method: HttpMethod.POST,
|
|
22
|
+
path: '/web-search',
|
|
23
|
+
body: { query: 'test', count: 1 },
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
valid: true,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
const response = isRecord(e) ? e['response'] : undefined;
|
|
31
|
+
const status =
|
|
32
|
+
isRecord(response) && typeof response['status'] === 'number'
|
|
33
|
+
? response['status']
|
|
34
|
+
: undefined;
|
|
35
|
+
if (status === 401 || status === 403) {
|
|
36
|
+
return { valid: false, error: 'Invalid API Key' };
|
|
37
|
+
}
|
|
38
|
+
return { valid: false, error: 'Could not connect to Bocha API. Please try again.' };
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
44
|
+
return typeof value === 'object' && value !== null;
|
|
45
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AuthenticationType, httpClient, HttpMethod } from '@agnocon/pieces-common';
|
|
2
|
+
|
|
3
|
+
export async function makeRequest<T = unknown>({
|
|
4
|
+
token,
|
|
5
|
+
method,
|
|
6
|
+
path,
|
|
7
|
+
body,
|
|
8
|
+
}: MakeRequestParams): Promise<T> {
|
|
9
|
+
const response = await httpClient.sendRequest<T>({
|
|
10
|
+
method,
|
|
11
|
+
url: `${BASE_URL}${path}`,
|
|
12
|
+
authentication: {
|
|
13
|
+
type: AuthenticationType.BEARER_TOKEN,
|
|
14
|
+
token,
|
|
15
|
+
},
|
|
16
|
+
headers: {
|
|
17
|
+
'Content-Type': 'application/json',
|
|
18
|
+
},
|
|
19
|
+
body,
|
|
20
|
+
});
|
|
21
|
+
return response.body;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const BASE_URL = 'https://api.bochaai.com/v1';
|
|
25
|
+
|
|
26
|
+
type MakeRequestParams = {
|
|
27
|
+
token: string;
|
|
28
|
+
method: HttpMethod;
|
|
29
|
+
path: string;
|
|
30
|
+
body?: unknown;
|
|
31
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Property } from '@agnocon/pieces-framework';
|
|
2
|
+
|
|
3
|
+
export const freshnessDropdown = Property.StaticDropdown({
|
|
4
|
+
displayName: 'Freshness',
|
|
5
|
+
description: 'Filter results by time range. Defaults to no limit.',
|
|
6
|
+
required: false,
|
|
7
|
+
defaultValue: 'noLimit',
|
|
8
|
+
options: {
|
|
9
|
+
options: [
|
|
10
|
+
{ label: 'No Limit', value: 'noLimit' },
|
|
11
|
+
{ label: 'One Day', value: 'oneDay' },
|
|
12
|
+
{ label: 'One Week', value: 'oneWeek' },
|
|
13
|
+
{ label: 'One Month', value: 'oneMonth' },
|
|
14
|
+
{ label: 'One Year', value: 'oneYear' },
|
|
15
|
+
],
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const countProp = Property.Number({
|
|
20
|
+
displayName: 'Count',
|
|
21
|
+
description: 'Number of results to return (1-50). Defaults to 10.',
|
|
22
|
+
required: false,
|
|
23
|
+
defaultValue: 10,
|
|
24
|
+
});
|