|
1 | 1 | import { |
2 | 2 | NodeConnectionTypes, |
| 3 | + type ICredentialDataDecryptedObject, |
| 4 | + type ICredentialTestFunctions, |
| 5 | + type ICredentialsDecrypted, |
3 | 6 | type IExecuteFunctions, |
| 7 | + type INodeCredentialTestResult, |
4 | 8 | type INodeExecutionData, |
5 | 9 | type INodeType, |
6 | 10 | type INodeTypeDescription, |
@@ -30,6 +34,7 @@ export class Browserbase implements INodeType { |
30 | 34 | { |
31 | 35 | name: 'browserbaseApi', |
32 | 36 | required: true, |
| 37 | + testedBy: 'browserbaseApiTest', |
33 | 38 | }, |
34 | 39 | ], |
35 | 40 | properties: [ |
@@ -613,6 +618,79 @@ export class Browserbase implements INodeType { |
613 | 618 | ], |
614 | 619 | }; |
615 | 620 |
|
| 621 | + methods = { |
| 622 | + credentialTest: { |
| 623 | + async browserbaseApiTest( |
| 624 | + this: ICredentialTestFunctions, |
| 625 | + credential: ICredentialsDecrypted<ICredentialDataDecryptedObject>, |
| 626 | + ): Promise<INodeCredentialTestResult> { |
| 627 | + const { browserbaseApiKey, browserbaseProjectId, modelApiKey } = |
| 628 | + credential.data!; |
| 629 | + |
| 630 | + const headers: Record<string, string> = { |
| 631 | + Accept: 'application/json', |
| 632 | + 'Content-Type': 'application/json', |
| 633 | + 'x-bb-api-key': browserbaseApiKey as string, |
| 634 | + 'x-model-api-key': modelApiKey as string, |
| 635 | + }; |
| 636 | + if (browserbaseProjectId) { |
| 637 | + headers['x-bb-project-id'] = browserbaseProjectId as string; |
| 638 | + } |
| 639 | + |
| 640 | + let sessionId: string | undefined; |
| 641 | + |
| 642 | + const httpRequest = this.helpers[ |
| 643 | + 'request' as keyof typeof this.helpers |
| 644 | + ] as (opts: object) => Promise<Record<string, unknown>>; |
| 645 | + |
| 646 | + try { |
| 647 | + const startResponse = await httpRequest({ |
| 648 | + method: 'POST', |
| 649 | + uri: `${BASE_URL}/v1/sessions/start`, |
| 650 | + headers, |
| 651 | + body: { modelName: 'openai/gpt-4o' }, |
| 652 | + json: true, |
| 653 | + }); |
| 654 | + |
| 655 | + const data = startResponse.data as Record<string, unknown> | undefined; |
| 656 | + sessionId = (data?.sessionId ?? |
| 657 | + startResponse.sessionId ?? |
| 658 | + startResponse.id) as string | undefined; |
| 659 | + |
| 660 | + if (sessionId) { |
| 661 | + await httpRequest({ |
| 662 | + method: 'POST', |
| 663 | + uri: `${BASE_URL}/v1/sessions/${sessionId}/end`, |
| 664 | + headers, |
| 665 | + body: {}, |
| 666 | + json: true, |
| 667 | + }); |
| 668 | + } |
| 669 | + |
| 670 | + return { status: 'OK', message: 'Connection successful' }; |
| 671 | + } catch (error) { |
| 672 | + if (sessionId) { |
| 673 | + try { |
| 674 | + await httpRequest({ |
| 675 | + method: 'POST', |
| 676 | + uri: `${BASE_URL}/v1/sessions/${sessionId}/end`, |
| 677 | + headers, |
| 678 | + body: {}, |
| 679 | + json: true, |
| 680 | + }); |
| 681 | + } catch { |
| 682 | + // Ignore cleanup errors |
| 683 | + } |
| 684 | + } |
| 685 | + |
| 686 | + const msg = |
| 687 | + error instanceof Error ? error.message : String(error); |
| 688 | + return { status: 'Error', message: msg }; |
| 689 | + } |
| 690 | + }, |
| 691 | + }, |
| 692 | + }; |
| 693 | + |
616 | 694 | async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> { |
617 | 695 | const items = this.getInputData(); |
618 | 696 | const returnData: INodeExecutionData[] = []; |
@@ -674,13 +752,16 @@ export class Browserbase implements INodeType { |
674 | 752 |
|
675 | 753 | // Get credentials |
676 | 754 | const credentials = await this.getCredentials('browserbaseApi'); |
677 | | - const headers = { |
| 755 | + const headers: Record<string, string> = { |
678 | 756 | Accept: 'application/json', |
679 | 757 | 'Content-Type': 'application/json', |
680 | 758 | 'x-bb-api-key': credentials.browserbaseApiKey as string, |
681 | | - 'x-bb-project-id': credentials.browserbaseProjectId as string, |
682 | 759 | 'x-model-api-key': credentials.modelApiKey as string, |
683 | 760 | }; |
| 761 | + // We no longer need to set the Project ID, but keeping this here for backwards compatibility |
| 762 | + if (credentials.browserbaseProjectId) { |
| 763 | + headers['x-bb-project-id'] = credentials.browserbaseProjectId as string; |
| 764 | + } |
684 | 765 |
|
685 | 766 | // Helper function to make API calls |
686 | 767 | const apiCall = async ( |
|
0 commit comments