Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add types #842

Merged
merged 14 commits into from
Nov 14, 2024
2 changes: 1 addition & 1 deletion .github/workflows/run_js_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: pnpm build
run: cd js && pnpm build
- name: run test
run: cd js && pnpm test:coverage
run: cd js && pnpm test:coverage --max-workers 16


- name: Upload `coverage` folder to R2
Expand Down

This file was deleted.

3 changes: 0 additions & 3 deletions docs/api-reference/actions-controller-v-1/execute-action.mdx

This file was deleted.

3 changes: 0 additions & 3 deletions docs/api-reference/actions-controller-v-1/get-action.mdx

This file was deleted.

3 changes: 0 additions & 3 deletions docs/api-reference/actions-controller-v-1/list-actions.mdx

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions docs/api-reference/actions-controller-v-2/execute-action.mdx

This file was deleted.

3 changes: 3 additions & 0 deletions docs/api-reference/admin/clear-cache.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new API documentation files are missing descriptions and details about the endpoints. Consider adding information such as parameters, request body, responses, and examples to improve clarity and usability. This applies to clear-cache.mdx, get-user-info.mdx, and update-connection-data.mdx.

openapi: post /api/v1/clear-cache
---
3 changes: 3 additions & 0 deletions docs/api-reference/auth/get-user-info.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: get /api/v1/client/auth/client_info
---
3 changes: 3 additions & 0 deletions docs/api-reference/connections/update-connection-data.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: patch /api/v1/connectedAccounts/{connectedAccountId}/data
---
2 changes: 1 addition & 1 deletion docs/composio_openapi.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "composio-core",
"version": "0.2.9-3",
"version": "0.2.9-7",
"description": "",
"main": "lib/src/index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions js/src/frameworks/cloudflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class CloudflareToolSet extends BaseComposioToolSet {
apps?: Sequence<string>;
tags?: Optional<Array<string>>;
useCase?: Optional<string>;
usecaseLimit?: Optional<number>;
filterByAvailableApps?: Optional<boolean>;
}): Promise<Sequence<AiTextGenerationToolInput>> {
const actions = await this.getToolsSchema(filters);
Expand Down
1 change: 1 addition & 0 deletions js/src/frameworks/langchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class LangchainToolSet extends BaseComposioToolSet {
apps?: Sequence<string>;
tags?: Optional<Array<string>>;
useCase?: Optional<string>;
usecaseLimit?: Optional<number>;
filterByAvailableApps?: Optional<boolean>;
},
entityId: Optional<string> = null
Expand Down
10 changes: 10 additions & 0 deletions js/src/frameworks/openai.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ describe("Apps class tests", () => {
expect(Object.keys(tools).length).toBe(1);
});

it("should get tools with usecase limit", async () => {
const tools = await openAIToolset.getTools({
useCase: "follow user",
apps: ["github"],
useCaseLimit: 1
});

expect(tools.length).toBe(1);
});

it("check if getTools -> actions are coming", async () => {
const tools = await openAIToolset.getTools({
actions: ['GITHUB_GITHUB_API_ROOT']
Expand Down
1 change: 1 addition & 0 deletions js/src/frameworks/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class OpenAIToolSet extends BaseComposioToolSet {
apps?: Sequence<string>;
tags?: Optional<Array<string>>;
useCase?: Optional<string>;
useCaseLimit?: Optional<number>;
filterByAvailableApps?: Optional<boolean>;
},
entityId?: Optional<string>
Expand Down
3 changes: 2 additions & 1 deletion js/src/frameworks/vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class VercelAIToolSet extends BaseComposioToolSet {
apps?: Array<string>;
tags?: Optional<Array<string>>;
useCase?: Optional<string>;
usecaseLimit?: Optional<number>;
filterByAvailableApps?: Optional<boolean>;
}): Promise<{ [key: string]: any }> {

Expand All @@ -59,7 +60,7 @@ export class VercelAIToolSet extends BaseComposioToolSet {
...(filters?.tags && { tags: filters?.tags?.join(",") }),
...(filters?.useCase && { useCase: filters?.useCase }),
...(filters?.actions && { actions: filters?.actions?.join(",") }),
...(filters?.actions && { actions: filters?.actions?.join(",") }),
...(filters?.usecaseLimit && { usecaseLimit: filters?.usecaseLimit }),
filterByAvailableApps: filters?.filterByAvailableApps ?? undefined
});

Expand Down
10 changes: 10 additions & 0 deletions js/src/sdk/base.toolset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,14 @@ describe("ComposioToolSet class tests", () => {

});

it("should get tools with usecase limit", async () => {
const tools = await toolset.getToolsSchema({
useCase: "follow user",
apps: ["github"],
useCaseLimit: 1
});

expect(tools.length).toBe(1);
});

});
2 changes: 2 additions & 0 deletions js/src/sdk/base.toolset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export class ComposioToolSet {
apps?: Array<string>;
tags?: Optional<Array<string>>;
useCase?: Optional<string>;
useCaseLimit?: Optional<number>;
filterByAvailableApps?: Optional<boolean>;
},
entityId?: Optional<string>
Expand All @@ -140,6 +141,7 @@ export class ComposioToolSet {
...(filters?.tags && { tags: filters?.tags?.join(",") }),
...(filters?.useCase && { useCase: filters?.useCase }),
...(filters?.actions && { actions: filters?.actions?.join(",") }),
...(filters?.useCaseLimit && { usecaseLimit: filters?.useCaseLimit }),
filterByAvailableApps: filters?.filterByAvailableApps ?? undefined
});
const localActions = new Map<string, NonNullable<GetListActionsResponse["items"]>[0]>();
Expand Down
20 changes: 16 additions & 4 deletions js/src/sdk/client/schemas.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ export const $ExpectedInputFieldsDTO = {
type: 'string',
description: 'Description of the field'
},
displayName: {
display_name: {
type: 'string',
description: 'Display name of the field'
},
Expand All @@ -809,17 +809,17 @@ export const $ExpectedInputFieldsDTO = {
type: 'boolean',
description: 'Whether the field is required'
},
expectedFromCustomer: {
expected_from_customer: {
type: 'boolean',
description: 'Whether the field is expected from customer'
},
isSecret: {
is_secret: {
type: 'boolean',
description: 'Whether the field is a secret'
}
},
type: 'object',
required: ['name', 'type', 'description', 'displayName', 'default', 'required', 'expectedFromCustomer', 'isSecret']
required: ['name', 'type', 'description', 'display_name', 'default', 'required', 'expected_from_customer', 'is_secret']
} as const;

export const $GetConnectorInfoResDTO = {
Expand Down Expand Up @@ -1161,6 +1161,12 @@ export const $ConnectionWithAppData = {
'$ref': '#/components/schemas/MemberInfoResDTO'
},
type: 'object'
},
labels: {
items: {
type: 'string'
},
type: 'array'
}
},
type: 'object',
Expand Down Expand Up @@ -1316,6 +1322,12 @@ export const $ConnectionParams = {
'$ref': '#/components/schemas/MemberInfoResDTO'
},
type: 'object'
},
labels: {
items: {
type: 'string'
},
type: 'array'
}
},
type: 'object',
Expand Down
13 changes: 7 additions & 6 deletions js/src/sdk/client/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ export type AppQueryDTO = {
*/
additionalFields?: string;
/**
* Whether to include local tools or not
* Enter 'true' or 'false'
*/
includeLocal?: string;
};
Expand Down Expand Up @@ -571,7 +571,7 @@ export type ExpectedInputFieldsDTO = {
/**
* Display name of the field
*/
displayName: string;
display_name: string;
/**
* Default value of the field
*/
Expand All @@ -585,11 +585,11 @@ export type ExpectedInputFieldsDTO = {
/**
* Whether the field is expected from customer
*/
expectedFromCustomer: boolean;
expected_from_customer: boolean;
/**
* Whether the field is a secret
*/
isSecret: boolean;
is_secret: boolean;
};

export type GetConnectorInfoResDTO = {
Expand Down Expand Up @@ -810,6 +810,7 @@ export type ConnectionWithAppData = {
member: {
[key: string]: unknown;
};
labels?: Array<(string)>;
};

export type GetConnectionsResult = {
Expand Down Expand Up @@ -853,7 +854,6 @@ export type ActionExecutionResDto = {

export type ConnectionParams = {
integrationId: string;
labels?: Array<(string)>;
connectionParams?: {
[key: string]: unknown;
};
Expand All @@ -878,6 +878,7 @@ export type ConnectionParams = {
member: {
[key: string]: unknown;
};
labels?: Array<(string)>;
};

export type ToggleConnectedAccountResponseDTO = {
Expand Down Expand Up @@ -2598,7 +2599,7 @@ export type ListActionsV2Data = {
showEnabledOnly?: boolean;
tags?: string;
useCase?: string;
usecaseLimit?: number;
useCaseLimit?: number;
};
};

Expand Down
16 changes: 16 additions & 0 deletions js/src/sdk/models/Entity.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
import { describe, it, expect } from "@jest/globals";
import { getBackendClient } from "../testUtils/getBackendClient";
import { Entity } from "./Entity";
import { ConnectedAccounts } from "./connectedAccounts";

describe("Entity class tests", () => {
let backendClient = getBackendClient();
let entity: Entity;
let triggerId: string;
let connectedAccounts: ConnectedAccounts;

beforeAll(() => {
entity = new Entity(backendClient, "default");
connectedAccounts = new ConnectedAccounts(backendClient);

});

it("should create an Entity instance with 'default' id", () => {
expect(entity).toBeInstanceOf(Entity);
expect(entity.id).toBe("default");
});


it("should create for different entities", async () => {
const entityId = "test-entity";
const entity2 = new Entity(backendClient, entityId);
const connection = await entity2.initiateConnection("github");
expect(connection.connectionStatus).toBe("INITIATED");

const connection2 = await connectedAccounts.get({connectedAccountId: connection.connectedAccountId});
if(!connection2) throw new Error("Connection not found");
expect(connection2.entityId).toBe(entityId);
});

it("get connection for github", async () => {
const app = "github";
Expand Down
2 changes: 1 addition & 1 deletion js/src/sdk/models/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export class Entity {
// Initiate the connection process
return this.connectedAccounts.initiate({
integrationId: integration!.id!,
userUuid: this.id,
entityId: this.id,
redirectUri: redirectUrl,
//@ts-ignore
data: connectionData,
Expand Down
3 changes: 2 additions & 1 deletion js/src/sdk/models/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type GetListActionsData = {
/**
* Limit of use-cases based search
*/
usecaseLimit?: string;
usecaseLimit?: number;
/**
* Show all actions - i.e disable pagination
*/
Expand Down Expand Up @@ -207,6 +207,7 @@ export class Actions {
useCase: data.useCase as string,
filterImportantActions: data.filterImportantActions,
showEnabledOnly: data.showEnabledOnly,
usecaseLimit: data.usecaseLimit || undefined
}
});
return response.data!;
Expand Down
5 changes: 3 additions & 2 deletions js/src/sdk/models/connectedAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ type ConnectedAccountsListData = GetConnectionsData['query'] & {appNames?: strin

type InitiateConnectionDataReq = InitiateConnectionPayloadDto & {
data?: Record<string, unknown> | unknown;
userUuid?: string;
entityId?: string;
labels?: string[];
integrationId: string;
redirectUri?: string;
}

export class ConnectedAccounts {
Expand Down Expand Up @@ -70,12 +70,13 @@ export class ConnectedAccounts {

async initiate(payload: InitiateConnectionDataReq): Promise<ConnectionRequest> {
try {
const {integrationId, entityId = 'default', labels,data={}} = payload;
const {integrationId, entityId = 'default', labels,data={}, redirectUri} = payload;

const res = await client.connections.initiateConnection({ body: {
integrationId,
entityId,
labels,
redirectUri,
data,
} }).then(res => res.data);

Expand Down
10 changes: 8 additions & 2 deletions js/src/sdk/utils/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ export class CEG {

let axiosDataMessage = axiosError.response?.data?.message || axiosError.message;
const status = axiosError.response?.status || axiosError.status || axiosError.code || 'unknown';
const urlAndStatus = axiosError.config?.url ? `in (URL: ${axiosError.config.url}, Status: ${status})` : '';
axiosDataMessage = `${axiosDataMessage || errorDetails.description || "No additional information available."} ${urlAndStatus}`;
const request_id = axiosError.response?.headers?.["x-request-id"];
const urlAndStatus = axiosError.config?.url ? ` got 📊 ${status} response from URL🔗: ${axiosError.config.url}, request_id: ${request_id}` : '';

axiosDataMessage = `❌ ${ifObjectStringify(axiosDataMessage) || errorDetails.description || "No additional information available."} ${urlAndStatus}`;
throw new ComposioError(
errorKey as string,
errorDetails.message,
Expand Down Expand Up @@ -151,4 +153,8 @@ export class CEG {

throw new ComposioError(messageCode, message || errorDetails.message, description || errorDetails.description, possibleFix || errorDetails.possibleFix);
}
}

export const ifObjectStringify = (obj: any) => {
return typeof obj === 'object' ? JSON.stringify(obj) : obj;
}
Loading