@picahq/toolkit 0.1.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.
Files changed (40) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +97 -0
  3. package/dist/apis/action.d.ts +69 -0
  4. package/dist/apis/action.js +201 -0
  5. package/dist/apis/available-actions.d.ts +26 -0
  6. package/dist/apis/available-actions.js +41 -0
  7. package/dist/apis/available-connectors.d.ts +24 -0
  8. package/dist/apis/available-connectors.js +40 -0
  9. package/dist/apis/connections.d.ts +29 -0
  10. package/dist/apis/connections.js +74 -0
  11. package/dist/apis/execute.d.ts +42 -0
  12. package/dist/apis/execute.js +185 -0
  13. package/dist/index.d.ts +36 -0
  14. package/dist/index.js +228 -0
  15. package/dist/prompts/default.d.ts +16 -0
  16. package/dist/prompts/default.js +114 -0
  17. package/dist/prompts/knowledge.d.ts +15 -0
  18. package/dist/prompts/knowledge.js +109 -0
  19. package/dist/schemas/actions.d.ts +69 -0
  20. package/dist/schemas/actions.js +43 -0
  21. package/dist/schemas/connections.d.ts +69 -0
  22. package/dist/schemas/connections.js +42 -0
  23. package/dist/schemas/execute.d.ts +128 -0
  24. package/dist/schemas/execute.js +69 -0
  25. package/dist/schemas/index.d.ts +3 -0
  26. package/dist/schemas/index.js +3 -0
  27. package/dist/tsconfig.tsbuildinfo +1 -0
  28. package/dist/types/client.d.ts +144 -0
  29. package/dist/types/client.js +9 -0
  30. package/dist/types/index.d.ts +2 -0
  31. package/dist/types/index.js +2 -0
  32. package/dist/types/pica.d.ts +133 -0
  33. package/dist/types/pica.js +9 -0
  34. package/dist/utils/helpers.d.ts +92 -0
  35. package/dist/utils/helpers.js +206 -0
  36. package/dist/utils/index.d.ts +2 -0
  37. package/dist/utils/index.js +2 -0
  38. package/dist/utils/log-messages.d.ts +21 -0
  39. package/dist/utils/log-messages.js +26 -0
  40. package/package.json +73 -0
@@ -0,0 +1,206 @@
1
+ /**
2
+ * Pica ToolKit - Utils
3
+ *
4
+ * These are util helper functions for the Pica ToolKit.
5
+ *
6
+ * @fileoverview Utils for the Pica ToolKit
7
+ * @author Pica
8
+ */
9
+ /**
10
+ * Paginate results from a fetch function
11
+ * @param fetchFn - The function to fetch the results
12
+ * @param limit - The number of results to fetch per page
13
+ * @returns An array of all results
14
+ */
15
+ export async function paginateResults(fetchFn, limit = 100) {
16
+ let page = 1;
17
+ let allResults = [];
18
+ let totalPages = 0;
19
+ try {
20
+ do {
21
+ const response = await fetchFn(page, limit);
22
+ const { rows, pages } = response;
23
+ totalPages = pages;
24
+ allResults = [...allResults, ...rows];
25
+ page++;
26
+ } while (page <= totalPages);
27
+ return allResults;
28
+ }
29
+ catch (error) {
30
+ console.error("Error in pagination:", error);
31
+ throw error;
32
+ }
33
+ }
34
+ /**
35
+ * Normalize an action ID
36
+ * @param raw - The raw action ID
37
+ * @returns The normalized action ID
38
+ */
39
+ export function normalizeActionId(raw) {
40
+ if (raw.includes("::")) {
41
+ if (!raw.startsWith("conn_mod_def::")) {
42
+ return `conn_mod_def::${raw}`;
43
+ }
44
+ return raw;
45
+ }
46
+ return raw;
47
+ }
48
+ /**
49
+ * Replace path variables in a path
50
+ * @param path - The path to replace variables in
51
+ * @param variables - The variables to replace in the path
52
+ * @returns The path with the variables replaced
53
+ */
54
+ export function replacePathVariables(path, variables) {
55
+ return path.replace(/\{\{([^}]+)\}\}/g, (_match, variable) => {
56
+ const value = variables[variable];
57
+ if (!value) {
58
+ throw new Error(`Missing value for path variable: ${variable}`);
59
+ }
60
+ return value.toString();
61
+ });
62
+ }
63
+ /**
64
+ * Parse a connection key into its component parts
65
+ * Format: environment::platform::namespace::id[|identity]
66
+ * @param key - The connection key to parse
67
+ * @returns The parsed connection key
68
+ * @throws Error if the key format is invalid or environment is not 'live' or 'test'
69
+ */
70
+ export function parseConnectionKey(key) {
71
+ if (!key || typeof key !== 'string') {
72
+ throw new Error('Connection key must be a non-empty string');
73
+ }
74
+ const parts = key.split("::");
75
+ if (parts.length < 4) {
76
+ throw new Error('Invalid connection key format. Expected: environment::platform::namespace::id[|identity]');
77
+ }
78
+ const [environment, platform, namespace, last] = parts;
79
+ if (environment !== "live" && environment !== "test") {
80
+ throw new Error(`Invalid environment '${environment}'. Must be 'live' or 'test'`);
81
+ }
82
+ if (!platform) {
83
+ throw new Error('Platform cannot be empty in connection key');
84
+ }
85
+ if (!namespace) {
86
+ throw new Error('Namespace cannot be empty in connection key');
87
+ }
88
+ if (!last) {
89
+ throw new Error('ID cannot be empty in connection key');
90
+ }
91
+ let id = last;
92
+ let identity;
93
+ if (id.includes("|")) {
94
+ const idParts = id.split("|");
95
+ id = idParts[0] ?? "";
96
+ identity = idParts[1];
97
+ if (!id) {
98
+ throw new Error('ID cannot be empty in connection key');
99
+ }
100
+ }
101
+ return {
102
+ environment,
103
+ platform,
104
+ namespace,
105
+ id,
106
+ identity
107
+ };
108
+ }
109
+ /**
110
+ * Parse a system ID into its component parts
111
+ * Format: prefix::metadata::suffix
112
+ * @param systemId - The system ID to parse
113
+ * @returns The parsed system ID
114
+ * @throws Error if the system ID format is invalid or any part is empty
115
+ */
116
+ export function parseSystemId(systemId) {
117
+ if (!systemId || typeof systemId !== 'string') {
118
+ throw new Error('System ID must be a non-empty string');
119
+ }
120
+ const parts = systemId.split("::");
121
+ if (parts.length !== 3) {
122
+ throw new Error('Invalid system ID format. Expected: prefix::metadata::suffix');
123
+ }
124
+ const [prefix, metadata, suffix] = parts;
125
+ if (!prefix) {
126
+ throw new Error('Prefix cannot be empty in system ID');
127
+ }
128
+ if (!metadata) {
129
+ throw new Error('Metadata cannot be empty in system ID');
130
+ }
131
+ if (!suffix) {
132
+ throw new Error('Suffix cannot be empty in system ID');
133
+ }
134
+ return {
135
+ prefix,
136
+ metadata,
137
+ suffix
138
+ };
139
+ }
140
+ /**
141
+ * Resolve template variables in a path and prepare data for execution
142
+ * @param actionPath - The path to resolve template variables in
143
+ * @param data - The data to resolve template variables in
144
+ * @param pathVariables - The path variables to resolve template variables in
145
+ * @returns The resolved path, cleaned data, and resolved path variables
146
+ */
147
+ export function resolveTemplateVariables(actionPath, data, pathVariables) {
148
+ const templateVariables = actionPath.match(/\{\{([^}]+)\}\}/g);
149
+ let resolvedPath = actionPath;
150
+ let cleanedData = data;
151
+ let resolvedPathVariables = { ...pathVariables };
152
+ if (templateVariables) {
153
+ const requiredVariables = templateVariables.map(v => v.replace(/\{\{|\}\}/g, ''));
154
+ const combinedVariables = {
155
+ ...(Array.isArray(data) ? {} : (data || {})),
156
+ ...(pathVariables || {})
157
+ };
158
+ const missingVariables = requiredVariables.filter(v => !combinedVariables[v]);
159
+ if (missingVariables.length > 0) {
160
+ throw new Error(`Missing required path variables: ${missingVariables.join(', ')}. ` +
161
+ `Please provide values for these variables.`);
162
+ }
163
+ // Clean up data object and prepare path variables
164
+ if (!Array.isArray(data) && data) {
165
+ cleanedData = { ...data };
166
+ requiredVariables.forEach(v => {
167
+ if (cleanedData[v] && (!pathVariables || !pathVariables[v])) {
168
+ resolvedPathVariables[v] = cleanedData[v];
169
+ delete cleanedData[v];
170
+ }
171
+ });
172
+ }
173
+ resolvedPath = replacePathVariables(actionPath, resolvedPathVariables);
174
+ }
175
+ return {
176
+ resolvedPath,
177
+ cleanedData,
178
+ resolvedPathVariables
179
+ };
180
+ }
181
+ /**
182
+ * Check if initializing with all connectors
183
+ * @param connectors - The connectors to check
184
+ * @returns True if '*' is in the connectors array
185
+ */
186
+ export function isInitializingWithAllConnectors(connectors = []) {
187
+ return connectors?.includes("*");
188
+ }
189
+ /**
190
+ * Check if initializing with all actions
191
+ * @param actions - The actions to check
192
+ * @returns True if '*' is in the actions array
193
+ */
194
+ export function isInitializingWithAllActions(actions = []) {
195
+ return actions?.includes("*");
196
+ }
197
+ /**
198
+ * Get the plural form of a word based on count
199
+ * @param count - The count to check
200
+ * @param singular - The singular form of the word
201
+ * @param plural - The plural form of the word (defaults to singular + 's')
202
+ * @returns The appropriate form based on count
203
+ */
204
+ export function pluralize(count, singular, plural) {
205
+ return count === 1 ? singular : (plural || `${singular}s`);
206
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./helpers";
2
+ export * from "./log-messages";
@@ -0,0 +1,2 @@
1
+ export * from "./helpers";
2
+ export * from "./log-messages";
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Pica ToolKit - Log Messages
3
+ *
4
+ * Centralized log messages for consistent logging across the application.
5
+ *
6
+ * @fileoverview Log messages for the Pica ToolKit
7
+ * @author Pica
8
+ */
9
+ export declare const LOG_MESSAGES: {
10
+ readonly KNOWLEDGE_AGENT_INITIALIZED: "[Pica] 🧠 Knowledge Agent Mode Initialized";
11
+ readonly KNOWLEDGE_AGENT_ACTIONS_ACCESS: "[Pica] Agent has access to all actions for knowledge discovery";
12
+ readonly KNOWLEDGE_AGENT_EXECUTE_CONFIG: "[Pica] Execute tool returns request configurations without execution";
13
+ readonly KNOWLEDGE_AGENT_CONNECTIONS_DISABLED: "[Pica] Connection management tools are disabled in knowledge mode";
14
+ readonly ALL_CONNECTORS_ACCESS: "[Pica] Initialized client with access to all connectors";
15
+ readonly LIST_CONNECTIONS_ENABLED: "[Pica] The `listPicaConnections` tool is enabled";
16
+ readonly LIST_CONNECTIONS_DISABLED: "[Pica] The `listPicaConnections` tool is disabled";
17
+ readonly ALL_ACTIONS_ACCESS: "[Pica] Initialized client with access to all actions";
18
+ readonly AUTHKIT_ENABLED: "[Pica] 🔗 AuthKit enabled - The `promptToConnectIntegration` tool is available";
19
+ readonly connectorCount: (count: number, pluralizedWord: string) => string;
20
+ readonly actionCount: (count: number, pluralizedWord: string) => string;
21
+ };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Pica ToolKit - Log Messages
3
+ *
4
+ * Centralized log messages for consistent logging across the application.
5
+ *
6
+ * @fileoverview Log messages for the Pica ToolKit
7
+ * @author Pica
8
+ */
9
+ export const LOG_MESSAGES = {
10
+ // Knowledge Agent Mode
11
+ KNOWLEDGE_AGENT_INITIALIZED: "[Pica] 🧠 Knowledge Agent Mode Initialized",
12
+ KNOWLEDGE_AGENT_ACTIONS_ACCESS: "[Pica] Agent has access to all actions for knowledge discovery",
13
+ KNOWLEDGE_AGENT_EXECUTE_CONFIG: "[Pica] Execute tool returns request configurations without execution",
14
+ KNOWLEDGE_AGENT_CONNECTIONS_DISABLED: "[Pica] Connection management tools are disabled in knowledge mode",
15
+ // Standard Mode - Connectors
16
+ ALL_CONNECTORS_ACCESS: "[Pica] Initialized client with access to all connectors",
17
+ LIST_CONNECTIONS_ENABLED: "[Pica] The `listPicaConnections` tool is enabled",
18
+ LIST_CONNECTIONS_DISABLED: "[Pica] The `listPicaConnections` tool is disabled",
19
+ // Standard Mode - Actions
20
+ ALL_ACTIONS_ACCESS: "[Pica] Initialized client with access to all actions",
21
+ // AuthKit
22
+ AUTHKIT_ENABLED: "[Pica] 🔗 AuthKit enabled - The `promptToConnectIntegration` tool is available",
23
+ // Dynamic messages (functions)
24
+ connectorCount: (count, pluralizedWord) => `[Pica] Initialized client with access to ${count} ${pluralizedWord}`,
25
+ actionCount: (count, pluralizedWord) => `[Pica] Initialized client with access to ${count} ${pluralizedWord}`,
26
+ };
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@picahq/toolkit",
3
+ "version": "0.1.0",
4
+ "description": "Pica tools for the Vercel AI SDK",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "engines": {
15
+ "node": ">=18.0.0"
16
+ },
17
+ "files": [
18
+ "dist/**",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "scripts": {
23
+ "build": "tsc",
24
+ "build:clean": "rm -rf dist && npm run build",
25
+ "dev": "tsc --watch",
26
+ "test": "jest",
27
+ "test:watch": "jest --watch",
28
+ "test:coverage": "jest --coverage",
29
+ "example:basic": "tsx examples/basic-agent.ts",
30
+ "example:knowledge": "tsx examples/knowledge-agent.ts",
31
+ "typecheck": "tsc --noEmit",
32
+ "prepublishOnly": "npm run build:clean"
33
+ },
34
+ "keywords": [
35
+ "pica",
36
+ "ai",
37
+ "vercel",
38
+ "tool",
39
+ "integration"
40
+ ],
41
+ "homepage": "https://picaos.com",
42
+ "bugs": {
43
+ "url": "https://github.com/picahq/toolkit/issues"
44
+ },
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "git+https://github.com/picahq/toolkit.git"
48
+ },
49
+ "license": "GPL-3.0",
50
+ "author": "@picahq",
51
+ "dependencies": {
52
+ "axios": "^1.12.1",
53
+ "chalk": "^4.1.2",
54
+ "form-data": "^4.0.4"
55
+ },
56
+ "peerDependencies": {
57
+ "@ai-sdk/openai": "^2.0.30",
58
+ "ai": "^5.0.0",
59
+ "zod": "^4.0.0"
60
+ },
61
+ "devDependencies": {
62
+ "@ai-sdk/openai": "^2.0.30",
63
+ "@types/jest": "^29.5.14",
64
+ "@types/node": "^24.3.3",
65
+ "ai": "^5.0.44",
66
+ "jest": "^29.7.0",
67
+ "ts-jest": "^29.2.5",
68
+ "ts-node": "^10.9.2",
69
+ "tsx": "^4.7.1",
70
+ "typescript": "^5.6.0",
71
+ "zod": "^4.1.8"
72
+ }
73
+ }