@mastra/openai 1.0.0 → 1.0.1-alpha.1

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/src/index.ts CHANGED
@@ -1,67 +1,59 @@
1
- import { Integration, OpenAPI, IntegrationCredentialType, IntegrationAuth } from '@mastra/core';
2
- import { createClient, type OASClient, type NormalizeOAS } from 'fets';
3
- import { z } from 'zod';
1
+ import { Integration, ToolApi } from '@mastra/core';
4
2
 
5
3
  // @ts-ignore
6
4
  import OpenaiLogo from './assets/openai.png';
7
- import { openapi } from './openapi';
8
- import { components } from './openapi-components';
9
- import { paths } from './openapi-paths';
5
+ import { comments } from './client/service-comments';
6
+ import * as integrationClient from './client/services.gen';
7
+ import * as zodSchema from './client/zodSchema';
8
+
9
+ type OpenaiConfig = {
10
+ API_KEY: string;
11
+ [key: string]: any;
12
+ };
10
13
 
11
14
  export class OpenaiIntegration extends Integration {
12
- constructor() {
13
- super({
14
- authType: IntegrationCredentialType.API_KEY,
15
- name: 'OPENAI',
16
- logoUrl: OpenaiLogo,
17
- authConnectionOptions: z.object({
18
- API_KEY: z.string(),
19
- }),
20
- });
15
+ readonly name = 'OPENAI';
16
+ readonly logoUrl = OpenaiLogo;
17
+ config: OpenaiConfig;
18
+ readonly tools: Record<Exclude<keyof typeof integrationClient, 'client'>, ToolApi>;
19
+ categories = ['ai'];
20
+ description =
21
+ 'OpenAI is an artificial intelligence platform that provides a set of tools and APIs for building AI-powered applications.';
22
+
23
+ constructor({ config }: { config: OpenaiConfig }) {
24
+ super();
25
+
26
+ this.config = config;
27
+ this.tools = this._generateIntegrationTools<typeof this.tools>();
21
28
  }
22
29
 
23
- getOpenApiSpec() {
24
- return { paths, components } as unknown as OpenAPI;
30
+ protected get toolSchemas() {
31
+ return zodSchema;
25
32
  }
26
33
 
27
- getApiClient = async ({ connectionId }: { connectionId: string }): Promise<OASClient<NormalizeOAS<openapi>>> => {
28
- const connection = await this.dataLayer?.getConnection({ name: this.name, connectionId });
29
-
30
- if (!connection) {
31
- throw new Error(`Connection not found for connectionId: ${connectionId}`);
32
- }
33
-
34
- const credential = await this.dataLayer?.getCredentialsByConnection(connection.id);
35
- const value = credential?.value as Record<string, string>;
34
+ protected get toolDocumentations() {
35
+ return comments;
36
+ }
36
37
 
37
- const client = createClient<NormalizeOAS<openapi>>({
38
- endpoint: `https://api.openai.com/v1`,
39
- globalParams: {
40
- headers: {
41
- Authorization: `Bearer ${value?.['API_KEY']}`,
42
- },
43
- },
38
+ protected get baseClient() {
39
+ integrationClient.client.setConfig({
40
+ baseUrl: `https://api.openai.com/v1`,
44
41
  });
42
+ return integrationClient;
43
+ }
45
44
 
46
- return client as any;
47
- };
45
+ getApiClient = async () => {
46
+ const value = {
47
+ API_KEY: this.config?.['API_KEY'],
48
+ } as Record<string, any>;
48
49
 
49
- registerEvents() {
50
- this.events = {};
51
- return this.events;
52
- }
50
+ const baseClient = this.baseClient;
53
51
 
54
- getAuthenticator() {
55
- return new IntegrationAuth({
56
- dataAccess: this.dataLayer!,
57
- // @ts-ignore
58
- onConnectionCreated: () => {
59
- // TODO
60
- },
61
- config: {
62
- INTEGRATION_NAME: this.name,
63
- AUTH_TYPE: this.config.authType,
64
- },
52
+ baseClient.client.interceptors.request.use((request, options) => {
53
+ request.headers.set('Authorization', `Bearer ${value?.['API_KEY']}`);
54
+ return request;
65
55
  });
66
- }
56
+
57
+ return integrationClient;
58
+ };
67
59
  }
@@ -1,37 +0,0 @@
1
-
2
- <svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
3
- viewBox="0 0 297.5 297.5" xml:space="preserve">
4
- <g id="XMLID_40_">
5
- <g>
6
- <path style="fill:#ACBFC7;" d="M277.71,158.52v85.7H19.79v-85.7h6.53v40.54c0,16.98,13.81,30.78,30.78,30.78
7
- s30.78-13.8,30.78-30.78v-40.54h30.09v40.54c0,16.98,13.81,30.78,30.78,30.78c16.98,0,30.78-13.8,30.78-30.78v-40.54h30.1v40.54
8
- c0,16.98,13.8,30.78,30.78,30.78c16.97,0,30.78-13.8,30.78-30.78v-40.54H277.71z"/>
9
- <rect x="218.66" y="53.28" style="fill:#CDD9DD;" width="43.49" height="10.53"/>
10
- <rect x="229.17" y="83.35" style="fill:#CDD9DD;" width="22.48" height="23.92"/>
11
- <rect x="137.51" y="83.35" style="fill:#CDD9DD;" width="22.48" height="23.92"/>
12
- <rect x="127.01" y="53.28" style="fill:#CDD9DD;" width="43.49" height="10.53"/>
13
- <rect x="35.35" y="53.28" style="fill:#CDD9DD;" width="43.49" height="10.53"/>
14
- <rect x="45.86" y="83.35" style="fill:#CDD9DD;" width="22.48" height="23.92"/>
15
- <path style="fill:#FF4855;" d="M251.65,126.81v72.25c0,6.2-5.05,11.24-11.24,11.24c-6.2,0-11.24-5.04-11.24-11.24v-72.25H251.65z"
16
- />
17
- <path style="fill:#D61616;" d="M68.34,126.81v72.25c0,6.2-5.04,11.24-11.24,11.24s-11.24-5.04-11.24-11.24v-72.25H68.34z"/>
18
- <path style="fill:#FFD63F;" d="M159.99,126.81v72.25c0,6.2-5.04,11.24-11.24,11.24s-11.24-5.04-11.24-11.24v-72.25H159.99z"/>
19
- <path d="M297.25,148.75v105.24c0,5.4-4.37,9.77-9.77,9.77H10.02c-5.39,0-9.77-4.37-9.77-9.77V148.75c0-5.4,4.38-9.77,9.77-9.77
20
- h16.3V83.35h-0.74c-5.39,0-9.77-4.38-9.77-9.77V43.51c0-5.4,4.38-9.77,9.77-9.77h63.03c5.4,0,9.77,4.37,9.77,9.77v30.07
21
- c0,5.39-4.37,9.77-9.77,9.77h-0.73v55.63h30.09V83.35h-0.73c-5.4,0-9.77-4.38-9.77-9.77V43.51c0-5.4,4.37-9.77,9.77-9.77h63.03
22
- c5.39,0,9.77,4.37,9.77,9.77v30.07c0,5.39-4.38,9.77-9.77,9.77h-0.74v55.63h30.1V83.35h-0.74c-5.39,0-9.77-4.38-9.77-9.77V43.51
23
- c0-5.4,4.38-9.77,9.77-9.77h63.03c5.4,0,9.77,4.37,9.77,9.77v30.07c0,5.39-4.37,9.77-9.77,9.77h-0.73v55.63h16.29
24
- C292.88,138.98,297.25,143.35,297.25,148.75z M277.71,244.22v-85.7h-6.52v40.54c0,16.98-13.81,30.78-30.78,30.78
25
- c-16.98,0-30.78-13.8-30.78-30.78v-40.54h-30.1v40.54c0,16.98-13.8,30.78-30.78,30.78c-16.97,0-30.78-13.8-30.78-30.78v-40.54
26
- H87.88v40.54c0,16.98-13.81,30.78-30.78,30.78s-30.78-13.8-30.78-30.78v-40.54h-6.53v85.7H277.71z M262.15,63.81V53.28h-43.49
27
- v10.53H262.15z M251.65,199.06v-72.25h-22.48v72.25c0,6.2,5.04,11.24,11.24,11.24C246.6,210.3,251.65,205.26,251.65,199.06z
28
- M251.65,107.27V83.35h-22.48v23.92H251.65z M170.5,63.81V53.28h-43.49v10.53H170.5z M159.99,199.06v-72.25h-22.48v72.25
29
- c0,6.2,5.04,11.24,11.24,11.24S159.99,205.26,159.99,199.06z M159.99,107.27V83.35h-22.48v23.92H159.99z M78.84,63.81V53.28H35.35
30
- v10.53H78.84z M68.34,199.06v-72.25H45.86v72.25c0,6.2,5.04,11.24,11.24,11.24S68.34,205.26,68.34,199.06z M68.34,107.27V83.35
31
- H45.86v23.92H68.34z"/>
32
- </g>
33
- <g>
34
- </g>
35
- </g>
36
- </svg>
37
-