Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
Fix ConnectionRequest serialization to handle cyclic references (#13)
devin-ai-integration[bot]6efc5c5a2b5c
diff --git a/packages/core/src/models/ConnectionRequest.ts b/packages/core/src/models/ConnectionRequest.tsindex 92eaf5e1a..beb6ed51b 100644--- a/packages/core/src/models/ConnectionRequest.ts+++ b/packages/core/src/models/ConnectionRequest.ts@@ -169,6 +169,25 @@ export class ConnectionRequest {throw new ConnectionRequestTimeoutError(`Connection request timed out for ${this.id}`);}++ /**+ * Returns a JSON-serializable representation of the connection request+ * Excludes the private client property to avoid cyclic reference issues+ */+ toJSON(): Record<string, unknown> {+ return {+ id: this.id,+ status: this.status,+ redirectUrl: this.redirectUrl,+ };+ }++ /**+ * Returns a string representation of the connection request+ */+ toString(): string {+ return JSON.stringify(this.toJSON(), null, 2);+ }}export const connectionRequest = (client: ComposioClient) => {diff --git a/packages/core/test/connectedAccounts/connectionRequest.test.ts b/packages/core/test/connectedAccounts/connectionRequest.test.tsindex 503a7b8ed..583cd8e7a 100644--- a/packages/core/test/connectedAccounts/connectionRequest.test.ts+++ b/packages/core/test/connectedAccounts/connectionRequest.test.ts@@ -217,4 +217,65 @@ describe('ConnectionRequest', () => {await expect(connectionPromise).rejects.toBe(apiError);});});++ describe('serialization methods', () => {+ it('should return a JSON-serializable object with toJSON()', () => {+ // Create a connection request instance+ connectionRequest = new ConnectionRequest(+ mockClient as unknown as ComposioClient,+ connectedAccountId,+ ConnectedAccountStatuses.INITIATED,+ redirectUrl+ );++ const jsonObj = connectionRequest.toJSON();++ expect(jsonObj).toHaveProperty('id', connectedAccountId);+ expect(jsonObj).toHaveProperty('status', ConnectedAccountStatuses.INITIATED);+ expect(jsonObj).toHaveProperty('redirectUrl', redirectUrl);++ expect(jsonObj).not.toHaveProperty('client');+ });++ it('should return a formatted JSON string with toString()', () => {+ // Create a connection request instance+ connectionRequest = new ConnectionRequest(+ mockClient as unknown as ComposioClient,+ connectedAccountId,+ ConnectedAccountStatuses.INITIATED,+ redirectUrl+ );++ const jsonString = connectionRequest.toString();++ expect(() => JSON.parse(jsonString)).not.toThrow();++ const parsedObj = JSON.parse(jsonString);+ expect(parsedObj).toHaveProperty('id', connectedAccountId);+ expect(parsedObj).toHaveProperty('status', ConnectedAccountStatuses.INITIATED);+ expect(parsedObj).toHaveProperty('redirectUrl', redirectUrl);++ expect(jsonString).toContain('\n');+ expect(jsonString).toContain(' ');+ });++ it('should be serializable with JSON.stringify without cyclic reference errors', () => {+ // Create a connection request instance+ connectionRequest = new ConnectionRequest(+ mockClient as unknown as ComposioClient,+ connectedAccountId,+ ConnectedAccountStatuses.INITIATED,+ redirectUrl+ );++ expect(() => JSON.stringify(connectionRequest)).not.toThrow();++ const stringified = JSON.stringify(connectionRequest);+ const parsed = JSON.parse(stringified);++ expect(parsed).toHaveProperty('id', connectedAccountId);+ expect(parsed).toHaveProperty('status', ConnectedAccountStatuses.INITIATED);+ expect(parsed).toHaveProperty('redirectUrl', redirectUrl);+ });+ });});