@picahq/toolkit
Advanced tools
@@ -39,2 +39,3 @@ /** | ||
| systemIds: string[]; | ||
| passthroughUrl: string; | ||
| options?: PicaOptions; | ||
@@ -47,6 +48,7 @@ } | ||
| * @param systemIds - The system IDs to get knowledge for | ||
| * @param passthroughUrl - The passthrough URL to replace baseUrl with in knowledge | ||
| * @param options - The options for the Pica client | ||
| * @returns The knowledge for the system IDs | ||
| */ | ||
| export declare function getActionsKnowledge({ baseUrl, secret, systemIds, options, }: GetActionsKnowledgeParams): Promise<ActionsKnowledgeResponse>; | ||
| export declare function getActionsKnowledge({ baseUrl, secret, systemIds, passthroughUrl, options, }: GetActionsKnowledgeParams): Promise<ActionsKnowledgeResponse>; | ||
| /** | ||
@@ -53,0 +55,0 @@ * Fetch action references for multiple action IDs using Promise.all |
@@ -11,3 +11,3 @@ /** | ||
| import axios from "axios"; | ||
| import { isInitializingWithAllActions, parseSystemId, normalizeActionId } from "../utils"; | ||
| import { isInitializingWithAllActions, parseSystemId, normalizeActionId, replaceBaseUrlInKnowledge } from "../utils"; | ||
| const SEARCH_ACTIONS_URL = "/v1/available-actions/search"; | ||
@@ -110,6 +110,7 @@ const KNOWLEDGE_URL = "/v1/knowledge"; | ||
| * @param systemIds - The system IDs to get knowledge for | ||
| * @param passthroughUrl - The passthrough URL to replace baseUrl with in knowledge | ||
| * @param options - The options for the Pica client | ||
| * @returns The knowledge for the system IDs | ||
| */ | ||
| export async function getActionsKnowledge({ baseUrl, secret, systemIds, options, }) { | ||
| export async function getActionsKnowledge({ baseUrl, secret, systemIds, passthroughUrl, options, }) { | ||
| const knowledgeMap = {}; | ||
@@ -129,3 +130,7 @@ const promises = systemIds.map(async (systemId) => { | ||
| const actionKnowledge = response.data.rows[0]; | ||
| knowledgeMap[systemId] = actionKnowledge.knowledge; | ||
| let updatedKnowledge = actionKnowledge.knowledge; | ||
| if (actionKnowledge.baseUrl && updatedKnowledge) { | ||
| updatedKnowledge = replaceBaseUrlInKnowledge(updatedKnowledge, actionKnowledge.baseUrl, passthroughUrl); | ||
| } | ||
| knowledgeMap[systemId] = updatedKnowledge; | ||
| } | ||
@@ -132,0 +137,0 @@ } |
+2
-4
@@ -16,9 +16,7 @@ /** | ||
| constructor(secret: string, options?: PicaOptions); | ||
| get passthroughUrl(): string; | ||
| get systemPrompt(): string; | ||
| private logConnectorInitialization; | ||
| private logActionInitialization; | ||
| /** | ||
| * @returns The system prompt for the Pica ToolKit | ||
| */ | ||
| getSystemPrompt(): Promise<string>; | ||
| /** | ||
| * @returns List of connected integrations | ||
@@ -25,0 +23,0 @@ */ |
+10
-9
@@ -49,2 +49,11 @@ /** | ||
| } | ||
| get passthroughUrl() { | ||
| return `${this.baseUrl}/v1/passthrough`; | ||
| } | ||
| get systemPrompt() { | ||
| if (this.options?.knowledgeAgent) { | ||
| return generateKnowledgeAgentSystemPrompt(); | ||
| } | ||
| return generateDefaultSystemPrompt(this.options?.connectors, this.options?.actions); | ||
| } | ||
| logConnectorInitialization() { | ||
@@ -71,11 +80,2 @@ if (isInitializingWithAllConnectors(this.options?.connectors)) { | ||
| /** | ||
| * @returns The system prompt for the Pica ToolKit | ||
| */ | ||
| async getSystemPrompt() { | ||
| if (this.options?.knowledgeAgent) { | ||
| return generateKnowledgeAgentSystemPrompt(); | ||
| } | ||
| return generateDefaultSystemPrompt(this.options?.connectors, this.options?.actions); | ||
| } | ||
| /** | ||
| * @returns List of connected integrations | ||
@@ -160,2 +160,3 @@ */ | ||
| systemIds, | ||
| passthroughUrl: this.passthroughUrl, | ||
| options: this.options?.knowledgeAgent ? { ...this.options, actions: ["*"] } : this.options | ||
@@ -162,0 +163,0 @@ }); |
@@ -93,1 +93,10 @@ /** | ||
| export declare function pluralize(count: number, singular: string, plural?: string): string; | ||
| /** | ||
| * Replace all instances of the original baseUrl with the passthrough URL in the knowledge string | ||
| * Handles both HTTP and HTTPS versions, with and without trailing slashes | ||
| * @param knowledge - The knowledge string to update | ||
| * @param originalBaseUrl - The original baseUrl to replace | ||
| * @param passthroughUrl - The passthrough URL to replace with | ||
| * @returns The updated knowledge string | ||
| */ | ||
| export declare function replaceBaseUrlInKnowledge(knowledge: string, originalBaseUrl: string, passthroughUrl: string): string; |
@@ -207,1 +207,33 @@ /** | ||
| } | ||
| /** | ||
| * Replace all instances of the original baseUrl with the passthrough URL in the knowledge string | ||
| * Handles both HTTP and HTTPS versions, with and without trailing slashes | ||
| * @param knowledge - The knowledge string to update | ||
| * @param originalBaseUrl - The original baseUrl to replace | ||
| * @param passthroughUrl - The passthrough URL to replace with | ||
| * @returns The updated knowledge string | ||
| */ | ||
| export function replaceBaseUrlInKnowledge(knowledge, originalBaseUrl, passthroughUrl) { | ||
| if (!knowledge || !originalBaseUrl) { | ||
| return knowledge; | ||
| } | ||
| let updatedKnowledge = knowledge; | ||
| const normalizedOriginal = originalBaseUrl.replace(/\/$/, ''); | ||
| const patterns = [ | ||
| normalizedOriginal, | ||
| normalizedOriginal + '/', | ||
| normalizedOriginal.replace(/^https?:\/\//, 'http://'), | ||
| normalizedOriginal.replace(/^https?:\/\//, 'http://') + '/', | ||
| normalizedOriginal.replace(/^https?:\/\//, 'https://'), | ||
| normalizedOriginal.replace(/^https?:\/\//, 'https://') + '/' | ||
| ]; | ||
| const uniquePatterns = [...new Set(patterns)]; | ||
| uniquePatterns.forEach(pattern => { | ||
| if (pattern) { | ||
| const escapedPattern = pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); | ||
| const regex = new RegExp(escapedPattern, 'g'); | ||
| updatedKnowledge = updatedKnowledge.replace(regex, passthroughUrl); | ||
| } | ||
| }); | ||
| return updatedKnowledge; | ||
| } |
+1
-1
| { | ||
| "name": "@picahq/toolkit", | ||
| "version": "0.1.0", | ||
| "version": "0.2.0", | ||
| "description": "Pica tools for the Vercel AI SDK", | ||
@@ -5,0 +5,0 @@ "type": "module", |
+1
-1
@@ -44,3 +44,3 @@ # Pica ToolKit | ||
| const systemPrompt = await pica.getSystemPrompt(); | ||
| const systemPrompt = pica.systemPrompt; | ||
@@ -47,0 +47,0 @@ const result = streamText({ |
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
196367
1.27%2342
2.05%