diff --git a/.github/workflows/canary-deploy.yml b/.github/workflows/canary-deploy.yml index 73ce0044c1a..9c4d7de448b 100644 --- a/.github/workflows/canary-deploy.yml +++ b/.github/workflows/canary-deploy.yml @@ -73,6 +73,7 @@ jobs: NPM_TOKEN_STORAGE_TYPES: ${{secrets.NPM_TOKEN_STORAGE_TYPES}} NPM_TOKEN_TESTING: ${{secrets.NPM_TOKEN_TESTING}} NPM_TOKEN_UTIL: ${{secrets.NPM_TOKEN_UTIL}} + NPM_TOKEN_VERTEX: ${{secrets.NPM_TOKEN_VERTEX}} NPM_TOKEN_WEBCHANNEL_WRAPPER: ${{secrets.NPM_TOKEN_WEBCHANNEL_WRAPPER}} NPM_TOKEN_FIREBASE: ${{secrets.NPM_TOKEN_FIREBASE}} NPM_TOKEN_APP_COMPAT: ${{ secrets.NPM_TOKEN_APP_COMPAT }} diff --git a/.github/workflows/prerelease-manual-deploy.yml b/.github/workflows/prerelease-manual-deploy.yml index 54f75383f95..13168c0cee7 100644 --- a/.github/workflows/prerelease-manual-deploy.yml +++ b/.github/workflows/prerelease-manual-deploy.yml @@ -76,6 +76,7 @@ jobs: NPM_TOKEN_STORAGE_TYPES: ${{secrets.NPM_TOKEN_STORAGE_TYPES}} NPM_TOKEN_TESTING: ${{secrets.NPM_TOKEN_TESTING}} NPM_TOKEN_UTIL: ${{secrets.NPM_TOKEN_UTIL}} + NPM_TOKEN_VERTEX: ${{secrets.NPM_TOKEN_VERTEX}} NPM_TOKEN_WEBCHANNEL_WRAPPER: ${{secrets.NPM_TOKEN_WEBCHANNEL_WRAPPER}} NPM_TOKEN_FIREBASE: ${{secrets.NPM_TOKEN_FIREBASE}} NPM_TOKEN_APP_COMPAT: ${{ secrets.NPM_TOKEN_APP_COMPAT }} diff --git a/.github/workflows/release-prod.yml b/.github/workflows/release-prod.yml index 09d1797ec4c..12f5766d66e 100644 --- a/.github/workflows/release-prod.yml +++ b/.github/workflows/release-prod.yml @@ -86,6 +86,7 @@ jobs: NPM_TOKEN_STORAGE_TYPES: ${{secrets.NPM_TOKEN_STORAGE_TYPES}} NPM_TOKEN_TESTING: ${{secrets.NPM_TOKEN_TESTING}} NPM_TOKEN_UTIL: ${{secrets.NPM_TOKEN_UTIL}} + NPM_TOKEN_VERTEX: ${{secrets.NPM_TOKEN_VERTEX}} NPM_TOKEN_WEBCHANNEL_WRAPPER: ${{secrets.NPM_TOKEN_WEBCHANNEL_WRAPPER}} NPM_TOKEN_FIREBASE: ${{secrets.NPM_TOKEN_FIREBASE}} NPM_TOKEN_APP_COMPAT: ${{ secrets.NPM_TOKEN_APP_COMPAT }} diff --git a/.github/workflows/release-staging.yml b/.github/workflows/release-staging.yml index 6a687ed5ee2..057f0944dd3 100644 --- a/.github/workflows/release-staging.yml +++ b/.github/workflows/release-staging.yml @@ -112,6 +112,7 @@ jobs: NPM_TOKEN_STORAGE_TYPES: ${{secrets.NPM_TOKEN_STORAGE_TYPES}} NPM_TOKEN_TESTING: ${{secrets.NPM_TOKEN_TESTING}} NPM_TOKEN_UTIL: ${{secrets.NPM_TOKEN_UTIL}} + NPM_TOKEN_VERTEX: ${{secrets.NPM_TOKEN_VERTEX}} NPM_TOKEN_WEBCHANNEL_WRAPPER: ${{secrets.NPM_TOKEN_WEBCHANNEL_WRAPPER}} NPM_TOKEN_FIREBASE: ${{secrets.NPM_TOKEN_FIREBASE}} NPM_TOKEN_APP_COMPAT: ${{ secrets.NPM_TOKEN_APP_COMPAT }} diff --git a/packages/vertexai/src/api.test.ts b/packages/vertexai/src/api.test.ts index efc2705921a..5c25cce7ef9 100644 --- a/packages/vertexai/src/api.test.ts +++ b/packages/vertexai/src/api.test.ts @@ -17,11 +17,11 @@ import { ModelParams } from './types'; import { getGenerativeModel } from './api'; import { expect } from 'chai'; -import { Vertex } from './public-types'; +import { VertexAI } from './public-types'; import { GenerativeModel } from './models/generative-model'; import { VertexError } from './errors'; -const fakeVertex: Vertex = { +const fakeVertexAI: VertexAI = { app: { name: 'DEFAULT', automaticDataCollectionEnabled: true, @@ -35,30 +35,30 @@ const fakeVertex: Vertex = { describe('Top level API', () => { it('getGenerativeModel throws if no model is provided', () => { - expect(() => getGenerativeModel(fakeVertex, {} as ModelParams)).to.throw( + expect(() => getGenerativeModel(fakeVertexAI, {} as ModelParams)).to.throw( VertexError.NO_MODEL ); }); it('getGenerativeModel throws if no apiKey is provided', () => { const fakeVertexNoApiKey = { - ...fakeVertex, + ...fakeVertexAI, app: { options: { projectId: 'my-project' } } - } as Vertex; + } as VertexAI; expect(() => getGenerativeModel(fakeVertexNoApiKey, { model: 'my-model' }) ).to.throw(VertexError.NO_API_KEY); }); it('getGenerativeModel throws if no projectId is provided', () => { const fakeVertexNoProject = { - ...fakeVertex, + ...fakeVertexAI, app: { options: { apiKey: 'my-key' } } - } as Vertex; + } as VertexAI; expect(() => getGenerativeModel(fakeVertexNoProject, { model: 'my-model' }) ).to.throw(VertexError.NO_PROJECT_ID); }); it('getGenerativeModel gets a GenerativeModel', () => { - const genModel = getGenerativeModel(fakeVertex, { model: 'my-model' }); + const genModel = getGenerativeModel(fakeVertexAI, { model: 'my-model' }); expect(genModel).to.be.an.instanceOf(GenerativeModel); expect(genModel.model).to.equal('publishers/google/models/my-model'); }); diff --git a/packages/vertexai/src/api.ts b/packages/vertexai/src/api.ts index 02caa7ee599..3702a5ff17f 100644 --- a/packages/vertexai/src/api.ts +++ b/packages/vertexai/src/api.ts @@ -19,8 +19,8 @@ import { FirebaseApp, getApp, _getProvider } from '@firebase/app'; import { Provider } from '@firebase/component'; import { getModularInstance } from '@firebase/util'; import { DEFAULT_LOCATION, VERTEX_TYPE } from './constants'; -import { VertexService } from './service'; -import { Vertex, VertexOptions } from './public-types'; +import { VertexAIService } from './service'; +import { VertexAI, VertexAIOptions } from './public-types'; import { ERROR_FACTORY, VertexError } from './errors'; import { ModelParams, RequestOptions } from './types'; import { GenerativeModel } from './models/generative-model'; @@ -31,21 +31,21 @@ export { GenerativeModel }; declare module '@firebase/component' { interface NameServiceMapping { - [VERTEX_TYPE]: VertexService; + [VERTEX_TYPE]: VertexAIService; } } /** - * Returns an {@link Vertex} instance for the given app. + * Returns an {@link VertexAI} instance for the given app. * * @public * * @param app - The {@link @firebase/app#FirebaseApp} to use. */ -export function getVertex( +export function getVertexAI( app: FirebaseApp = getApp(), - options?: VertexOptions -): Vertex { + options?: VertexAIOptions +): VertexAI { app = getModularInstance(app); // Dependencies const vertexProvider: Provider<'vertex'> = _getProvider(app, VERTEX_TYPE); @@ -56,7 +56,7 @@ export function getVertex( } export function getGenerativeModel( - vertex: Vertex, + vertex: VertexAI, modelParams: ModelParams, requestOptions?: RequestOptions ): GenerativeModel { diff --git a/packages/vertexai/src/index.ts b/packages/vertexai/src/index.ts index dafbd87ba82..9a0c717b9ee 100644 --- a/packages/vertexai/src/index.ts +++ b/packages/vertexai/src/index.ts @@ -22,7 +22,7 @@ */ import { registerVersion, _registerComponent } from '@firebase/app'; -import { VertexService } from './service'; +import { VertexAIService } from './service'; import { VERTEX_TYPE } from './constants'; import { Component, ComponentType } from '@firebase/component'; import { name, version } from '../package.json'; @@ -41,7 +41,7 @@ function registerVertex(): void { // getImmediate for FirebaseApp will always succeed const app = container.getProvider('app').getImmediate(); const appCheckProvider = container.getProvider('app-check-internal'); - return new VertexService(app, appCheckProvider, { location }); + return new VertexAIService(app, appCheckProvider, { location }); }, ComponentType.PUBLIC ).setMultipleInstances(true) diff --git a/packages/vertexai/src/models/generative-model.test.ts b/packages/vertexai/src/models/generative-model.test.ts index f3623960872..5c930f36fc7 100644 --- a/packages/vertexai/src/models/generative-model.test.ts +++ b/packages/vertexai/src/models/generative-model.test.ts @@ -16,9 +16,9 @@ */ import { expect } from 'chai'; import { GenerativeModel } from './generative-model'; -import { Vertex } from '../public-types'; +import { VertexAI } from '../public-types'; -const fakeVertex: Vertex = { +const fakeVertexAI: VertexAI = { app: { name: 'DEFAULT', automaticDataCollectionEnabled: true, @@ -32,23 +32,23 @@ const fakeVertex: Vertex = { describe('GenerativeModel', () => { it('handles plain model name', () => { - const genModel = new GenerativeModel(fakeVertex, { model: 'my-model' }); + const genModel = new GenerativeModel(fakeVertexAI, { model: 'my-model' }); expect(genModel.model).to.equal('publishers/google/models/my-model'); }); it('handles models/ prefixed model name', () => { - const genModel = new GenerativeModel(fakeVertex, { + const genModel = new GenerativeModel(fakeVertexAI, { model: 'models/my-model' }); expect(genModel.model).to.equal('publishers/google/models/my-model'); }); it('handles full model name', () => { - const genModel = new GenerativeModel(fakeVertex, { + const genModel = new GenerativeModel(fakeVertexAI, { model: 'publishers/google/models/my-model' }); expect(genModel.model).to.equal('publishers/google/models/my-model'); }); it('handles prefixed tuned model name', () => { - const genModel = new GenerativeModel(fakeVertex, { + const genModel = new GenerativeModel(fakeVertexAI, { model: 'tunedModels/my-model' }); expect(genModel.model).to.equal('tunedModels/my-model'); diff --git a/packages/vertexai/src/models/generative-model.ts b/packages/vertexai/src/models/generative-model.ts index 94bc87255ff..04f30036365 100644 --- a/packages/vertexai/src/models/generative-model.ts +++ b/packages/vertexai/src/models/generative-model.ts @@ -36,10 +36,10 @@ import { import { ChatSession } from '../methods/chat-session'; import { countTokens } from '../methods/count-tokens'; import { formatGenerateContentInput } from '../requests/request-helpers'; -import { Vertex } from '../public-types'; +import { VertexAI } from '../public-types'; import { ERROR_FACTORY, VertexError } from '../errors'; import { ApiSettings } from '../types/internal'; -import { VertexService } from '../service'; +import { VertexAIService } from '../service'; /** * Class for generative model APIs. @@ -54,23 +54,23 @@ export class GenerativeModel { tools?: Tool[]; constructor( - vertex: Vertex, + vertexAI: VertexAI, modelParams: ModelParams, requestOptions?: RequestOptions ) { - if (!vertex.app?.options?.apiKey) { + if (!vertexAI.app?.options?.apiKey) { throw ERROR_FACTORY.create(VertexError.NO_API_KEY); - } else if (!vertex.app?.options?.projectId) { + } else if (!vertexAI.app?.options?.projectId) { throw ERROR_FACTORY.create(VertexError.NO_PROJECT_ID); } else { this._apiSettings = { - apiKey: vertex.app.options.apiKey, - project: vertex.app.options.projectId, - location: vertex.location + apiKey: vertexAI.app.options.apiKey, + project: vertexAI.app.options.projectId, + location: vertexAI.location }; - if ((vertex as VertexService).appCheck) { + if ((vertexAI as VertexAIService).appCheck) { this._apiSettings.getAppCheckToken = () => - (vertex as VertexService).appCheck!.getToken(); + (vertexAI as VertexAIService).appCheck!.getToken(); } } if (modelParams.model.includes('/')) { diff --git a/packages/vertexai/src/public-types.ts b/packages/vertexai/src/public-types.ts index 8724759e00a..73d9fb6d376 100644 --- a/packages/vertexai/src/public-types.ts +++ b/packages/vertexai/src/public-types.ts @@ -20,17 +20,17 @@ import { FirebaseApp } from '@firebase/app'; export * from './types'; /** - * An instance of Firebase Vertex. + * An instance of Firebase Vertex AI. * @public */ -export interface Vertex { +export interface VertexAI { /** - * The {@link @firebase/app#FirebaseApp} this {@link Vertex} instance is associated with. + * The {@link @firebase/app#FirebaseApp} this {@link VertexAI} instance is associated with. */ app: FirebaseApp; location: string; } -export interface VertexOptions { +export interface VertexAIOptions { location?: string; } diff --git a/packages/vertexai/src/service.ts b/packages/vertexai/src/service.ts index 2f54784f5c6..a061fc4ad65 100644 --- a/packages/vertexai/src/service.ts +++ b/packages/vertexai/src/service.ts @@ -16,7 +16,7 @@ */ import { FirebaseApp, _FirebaseService } from '@firebase/app'; -import { Vertex, VertexOptions } from './public-types'; +import { VertexAI, VertexAIOptions } from './public-types'; import { AppCheckInternalComponentName, FirebaseAppCheckInternal @@ -24,14 +24,14 @@ import { import { Provider } from '@firebase/component'; import { DEFAULT_LOCATION } from './constants'; -export class VertexService implements Vertex, _FirebaseService { +export class VertexAIService implements VertexAI, _FirebaseService { appCheck: FirebaseAppCheckInternal | null; location: string; constructor( public app: FirebaseApp, appCheckProvider?: Provider, - public options?: VertexOptions + public options?: VertexAIOptions ) { const appCheck = appCheckProvider?.getImmediate({ optional: true }); this.appCheck = appCheck || null; diff --git a/scripts/release/utils/publish.ts b/scripts/release/utils/publish.ts index 55d641cc510..c3f40f0d888 100644 --- a/scripts/release/utils/publish.ts +++ b/scripts/release/utils/publish.ts @@ -75,9 +75,13 @@ export async function publishInCI( continue; } } catch (e) { - // 404 from NPM indicates the package doesn't exist there. - console.log(`Skipping pkg: ${pkg} - it has never been published to NPM.`); - continue; + if (version !== '0.0.1') { + // 404 from NPM indicates the package doesn't exist there. + console.log( + `Skipping pkg: ${pkg} - it has never been published to NPM.` + ); + continue; + } } const tag = `${pkg}@${version}`;