@truto/langchain-toolset 0.0.2 → 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.
package/dist/types.d.ts CHANGED
@@ -1,10 +1,7 @@
1
1
  import { DynamicStructuredTool } from "@langchain/core/tools";
2
- export const isCustomMethod: (method: string) => boolean;
3
- export const isIndividualMethod: (method: string) => boolean;
4
- export const getRequiredProperties: (schema: Record<string, any>) => (string | null)[];
5
2
  export const getPropertiesBySchema: (body: Record<string, any>, schema: Record<string, any>) => Pick<Record<string, any>, string>;
6
- export const getToolName: (integrationLabel: string, resourceName: string, methodName: string) => string;
7
3
  export default function getTools(integratedAccountId: string, config: {
4
+ methods?: string[];
8
5
  truto: {
9
6
  baseUrl?: string;
10
7
  token: string;
@@ -1 +1 @@
1
- {"mappings":";AAcA,OAAO,MAAM,yBAA0B,MAAM,YAE5C,CAAA;AAED,OAAO,MAAM,6BAA8B,MAAM,YAEhD,CAAA;AAED,OAAO,MAAM,gCAAiC,OAAO,MAAM,EAAE,GAAG,CAAC,sBAKhE,CAAA;AAED,OAAO,MAAM,8BACL,OAAO,MAAM,EAAE,GAAG,CAAC,UACjB,OAAO,MAAM,EAAE,GAAG,CAAC,sCAI5B,CAAA;AAED,OAAO,MAAM,gCACO,MAAM,gBACV,MAAM,cACR,MAAM,WA0BnB,CAAA;AAED,wBAAsB,QAAQ,CAC5B,mBAAmB,EAAE,MAAM,EAC3B,MAAM,EAAE;IACN,KAAK,EAAE;QACL,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,KAAK,EAAE,MAAM,CAAA;KACd,CAAA;CACF,GACA,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,sBAAsB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAsLrE;AAED,eAAe,QAAQ,CAAA","sources":["src/src/index.ts","src/index.ts"],"sourcesContent":[null,"import { DynamicStructuredTool, tool } from '@langchain/core/tools'\nimport TrutoApi from '@truto/truto-ts-sdk'\nimport {\n compact,\n each,\n filter,\n get,\n keys,\n map,\n pick,\n snakeCase,\n} from 'lodash-es'\nimport pluralize from 'pluralize'\n\nexport const isCustomMethod = (method: string) => {\n return ['get', 'list', 'create', 'update', 'delete'].indexOf(method) === -1\n}\n\nexport const isIndividualMethod = (method: string) => {\n return ['get', 'update', 'delete'].indexOf(method) !== -1\n}\n\nexport const getRequiredProperties = (schema: Record<string, any>) => {\n return filter(\n map(schema, (value, key) => (value.required ? key : null)),\n value => value !== null\n )\n}\n\nexport const getPropertiesBySchema = (\n body: Record<string, any>,\n schema: Record<string, any>\n) => {\n const keysToPick = keys(schema)\n return pick(body, keysToPick)\n}\n\nexport const getToolName = (\n integrationLabel: string,\n resourceName: string,\n methodName: string\n) => {\n if (methodName === 'list') {\n return snakeCase(`list all ${integrationLabel} ${resourceName}`)\n }\n if (methodName === 'get') {\n return snakeCase(\n `get single ${integrationLabel} ${pluralize.singular(resourceName)} by id`\n )\n }\n if (methodName === 'create') {\n return snakeCase(\n `create a ${integrationLabel} ${pluralize.singular(resourceName)}`\n )\n }\n if (methodName === 'update') {\n return snakeCase(\n `update a ${integrationLabel} ${pluralize.singular(resourceName)} by id`\n )\n }\n if (methodName === 'delete') {\n return snakeCase(\n `delete a ${integrationLabel} ${pluralize.singular(resourceName)} by id`\n )\n }\n return snakeCase(`${integrationLabel} ${resourceName} ${methodName}`)\n}\n\nexport async function getTools(\n integratedAccountId: string,\n config: {\n truto: {\n baseUrl?: string\n token: string\n }\n }\n): Promise<Record<string, DynamicStructuredTool<Record<string, any>>>> {\n const tools: Record<string, DynamicStructuredTool<Record<string, any>>> = {}\n\n const trutoApi = new TrutoApi({\n baseUrl: config.truto.baseUrl,\n token: config.truto.token,\n })\n\n const integratedAccount = await trutoApi.integratedAccount.get(\n integratedAccountId\n )\n\n const installedIntegration = await trutoApi.environmentIntegration.get(\n integratedAccount.environment_integration_id\n )\n\n const integration = get(installedIntegration, 'integration') || {}\n\n const resources = get(integration, 'config.resources', []) as Record<\n string,\n any\n >\n\n each(resources, (resource: any, resourceName: string) => {\n each(resource, (method, methodName: string) => {\n const description = get(method, 'description') || ''\n if (!description) {\n return\n }\n const toolName = getToolName(\n integration.name || '',\n resourceName,\n methodName\n )\n const querySchema = get(method, 'query_schema') || {}\n if (methodName === 'list') {\n querySchema.limit = {\n type: 'string',\n description: 'The number of records to fetch',\n }\n querySchema.next_cursor = {\n type: 'string',\n description:\n 'The cursor to fetch the next set of records. This can be found in the response of the previous call as nextCursor.',\n }\n }\n const queryRequiredProperties = getRequiredProperties(querySchema)\n const bodySchema = get(method, 'body_schema') || {}\n const bodyRequiredProperties = getRequiredProperties(bodySchema)\n tools[toolName] = tool<Record<string, any>>(\n async config => {\n const methodToCall = isCustomMethod(methodName)\n ? 'customMethod'\n : methodName\n const query = getPropertiesBySchema(config, querySchema) || {}\n const body = getPropertiesBySchema(config, bodySchema) || {}\n switch (methodToCall) {\n case 'list':\n return JSON.stringify(\n await trutoApi.proxyApi\n .list({\n integrated_account_id: integratedAccountId,\n resource: resourceName,\n ...query,\n })\n .next(),\n null,\n 2\n )\n case 'get':\n return JSON.stringify(\n await trutoApi.proxyApi.get(config?.id, {\n integrated_account_id: integratedAccountId,\n resource: resourceName,\n ...query,\n }),\n null,\n 2\n )\n case 'create':\n return JSON.stringify(\n await trutoApi.proxyApi.create(body, {\n integrated_account_id: integratedAccountId,\n resource: resourceName,\n ...query,\n }),\n null,\n 2\n )\n case 'update':\n return JSON.stringify(\n await trutoApi.proxyApi.update(config?.id, body, {\n integrated_account_id: integratedAccountId,\n resource: resourceName,\n ...query,\n }),\n null,\n 2\n )\n case 'delete':\n return JSON.stringify(\n await trutoApi.proxyApi.delete(config?.id, {\n integrated_account_id: integratedAccountId,\n resource: resourceName,\n ...query,\n }),\n null,\n 2\n )\n case 'customMethod':\n return JSON.stringify(\n await trutoApi.proxyApi.customMethod(methodName, body, {\n integrated_account_id: integratedAccountId,\n resource: resourceName,\n ...query,\n }),\n null,\n 2\n )\n }\n return []\n },\n {\n name: toolName,\n description: get(method, 'description') || '',\n schema: {\n type: 'object',\n properties: {\n ...querySchema,\n ...bodySchema,\n ...(isIndividualMethod(methodName)\n ? {\n id: {\n type: 'string',\n description: `The id of the ${resourceName} to ${methodName}. Required.`,\n },\n }\n : {}),\n },\n required: compact([\n isIndividualMethod(methodName) ? 'id' : null,\n ...queryRequiredProperties,\n ...bodyRequiredProperties,\n ]),\n },\n }\n )\n console.log(\n 'Registering tool',\n JSON.stringify(\n {\n name: toolName,\n description: get(method, 'description') || '',\n schema: {\n type: 'object',\n properties: {\n ...querySchema,\n ...bodySchema,\n ...(isIndividualMethod(methodName)\n ? {\n id: {\n type: 'string',\n description: `The id of the ${resourceName} to ${methodName}. Required.`,\n },\n }\n : {}),\n },\n required: compact([\n isIndividualMethod(methodName) ? 'id' : null,\n ...queryRequiredProperties,\n ...bodyRequiredProperties,\n ]),\n },\n },\n null,\n 2\n )\n )\n })\n })\n\n return tools\n}\n\nexport default getTools\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";AAIA,OAAO,MAAM,8BACL,OAAO,MAAM,EAAE,GAAG,CAAC,UACjB,OAAO,MAAM,EAAE,GAAG,CAAC,sCAI5B,CAAA;AAED,wBAAsB,QAAQ,CAC5B,mBAAmB,EAAE,MAAM,EAC3B,MAAM,EAAE;IACN,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,KAAK,EAAE;QACL,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,KAAK,EAAE,MAAM,CAAA;KACd,CAAA;CACF,GACA,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,sBAAsB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAwGrE;AAED,eAAe,QAAQ,CAAA","sources":["src/src/index.ts","src/index.ts"],"sourcesContent":[null,"import { DynamicStructuredTool, tool } from '@langchain/core/tools'\nimport TrutoApi from '@truto/truto-ts-sdk'\nimport { each, keys, pick } from 'lodash-es'\n\nexport const getPropertiesBySchema = (\n body: Record<string, any>,\n schema: Record<string, any>\n) => {\n const keysToPick = keys(schema?.properties || {})\n return pick(body, keysToPick)\n}\n\nexport async function getTools(\n integratedAccountId: string,\n config: {\n methods?: string[]\n truto: {\n baseUrl?: string\n token: string\n }\n }\n): Promise<Record<string, DynamicStructuredTool<Record<string, any>>>> {\n const tools: Record<string, DynamicStructuredTool<Record<string, any>>> = {}\n\n const trutoApi = new TrutoApi({\n baseUrl: config.truto.baseUrl,\n token: config.truto.token,\n })\n\n const availableTools = await trutoApi.integratedAccount.tools(\n integratedAccountId,\n config?.methods\n )\n\n each(availableTools, availableTool => {\n const toolName = availableTool.name\n tools[toolName] = tool<Record<string, any>>(\n async config => {\n const resourceName = availableTool.resource\n const methodToCall = availableTool.method\n const query =\n getPropertiesBySchema(config, availableTool.query_schema) || {}\n const body =\n getPropertiesBySchema(config, availableTool.body_schema) || {}\n switch (methodToCall) {\n case 'list':\n return JSON.stringify(\n await trutoApi.proxyApi\n .list({\n integrated_account_id: integratedAccountId,\n resource: resourceName,\n ...query,\n })\n .next(),\n null,\n 2\n )\n case 'get':\n return JSON.stringify(\n await trutoApi.proxyApi.get(config?.id, {\n integrated_account_id: integratedAccountId,\n resource: resourceName,\n ...query,\n }),\n null,\n 2\n )\n case 'create':\n return JSON.stringify(\n await trutoApi.proxyApi.create(body, {\n integrated_account_id: integratedAccountId,\n resource: resourceName,\n ...query,\n }),\n null,\n 2\n )\n case 'update':\n return JSON.stringify(\n await trutoApi.proxyApi.update(config?.id, body, {\n integrated_account_id: integratedAccountId,\n resource: resourceName,\n ...query,\n }),\n null,\n 2\n )\n case 'delete':\n return JSON.stringify(\n await trutoApi.proxyApi.delete(config?.id, {\n integrated_account_id: integratedAccountId,\n resource: resourceName,\n ...query,\n }),\n null,\n 2\n )\n default:\n return JSON.stringify(\n await trutoApi.proxyApi.customMethod(methodToCall, body, {\n integrated_account_id: integratedAccountId,\n resource: resourceName,\n ...query,\n }),\n null,\n 2\n )\n }\n },\n {\n name: toolName,\n description: availableTool.description || '',\n schema: {\n type: 'object',\n properties: {\n ...(availableTool.query_schema?.properties || {}),\n ...(availableTool.body_schema?.properties || {}),\n },\n required: availableTool.required || [],\n },\n }\n )\n })\n\n return tools\n}\n\nexport default getTools\n"],"names":[],"version":3,"file":"types.d.ts.map"}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.0.2",
7
+ "version": "0.1.0",
8
8
  "description": "SuperAI toolset for TypeScript. Works in Langchain.js.",
9
9
  "repository": "https://github.com/trutohq/truto-langchainjs-toolset.git",
10
10
  "source": "src/index.ts",
@@ -46,7 +46,6 @@
46
46
  "@types/jest": "29.4.0",
47
47
  "@types/lodash-es": "4.17.7",
48
48
  "@types/node": "18.14.6",
49
- "@types/pluralize": "0.0.33",
50
49
  "@typescript-eslint/eslint-plugin": "5.46.1",
51
50
  "@typescript-eslint/parser": "5.46.1",
52
51
  "@langchain/openai": "0.4.4",
@@ -59,10 +58,9 @@
59
58
  "typescript": "4.9.5"
60
59
  },
61
60
  "dependencies": {
62
- "@truto/truto-ts-sdk": "1.0.21",
61
+ "@truto/truto-ts-sdk": "2.0.2",
63
62
  "@langchain/core": "0.3.42",
64
- "lodash-es": "4.17.21",
65
- "pluralize": "8.0.0"
63
+ "lodash-es": "4.17.21"
66
64
  },
67
65
  "scripts": {
68
66
  "dev": "parcel watch",