Skip to content
This repository was archived by the owner on Oct 23, 2025. It is now read-only.

Commit 36df1a8

Browse files
authored
Merge pull request #43 from picahq/feat/filter-by-connector-keys
feat: query connectors by keys to optimize api response
2 parents 3d715e2 + d3c2c48 commit 36df1a8

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@picahq/ai",
3-
"version": "2.8.0",
3+
"version": "2.8.1",
44
"description": "Pica AI SDK for Vercel AI SDK integration",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/pica.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,7 @@ export class Pica {
8787
.then(() => {
8888
let filteredConnections = this.connections.filter((conn: any) => conn.active);
8989

90-
if (options?.connectors?.length) {
91-
if (!options.connectors.includes("*")) {
92-
filteredConnections = filteredConnections.filter(conn =>
93-
options.connectors!.includes(conn.key)
94-
);
95-
}
96-
} else {
90+
if (!options?.connectors?.length) {
9791
filteredConnections = [];
9892
}
9993

@@ -147,7 +141,7 @@ ${this.system.trim()}
147141

148142
private async initialize() {
149143
await Promise.all([
150-
this.initializeConnections(),
144+
this.initializeConnections(undefined, this.options?.connectors),
151145
this.initializeConnectionDefinitions(),
152146
]);
153147
}
@@ -157,8 +151,13 @@ ${this.system.trim()}
157151
return this.system;
158152
}
159153

160-
private async initializeConnections(platform?: string) {
154+
private async initializeConnections(platform?: string, connectionKeys?: string[]) {
161155
try {
156+
if (!connectionKeys || connectionKeys.length === 0) {
157+
this.connections = [];
158+
return;
159+
}
160+
162161
const headers = this.generateHeaders();
163162

164163
let baseUrl = this.getConnectionUrl;
@@ -169,6 +168,11 @@ ${this.system.trim()}
169168
hasQueryParam = true;
170169
}
171170

171+
if (!connectionKeys.includes("*")) {
172+
baseUrl += hasQueryParam ? `&key=${connectionKeys.join(',')}` : `?key=${connectionKeys.join(',')}`;
173+
hasQueryParam = true;
174+
}
175+
172176
if (this.identity) {
173177
baseUrl += hasQueryParam ? `&identity=${encodeURIComponent(this.identity)}` : `?identity=${encodeURIComponent(this.identity)}`;
174178
hasQueryParam = true;
@@ -301,7 +305,7 @@ ${this.system.trim()}
301305
}
302306

303307
public async getAvailableConnectors(platform?: string) {
304-
await this.initializeConnections(platform);
308+
await this.initializeConnections(platform, this.options?.connectors);
305309
return this.connections;
306310
}
307311

0 commit comments

Comments
 (0)