# Learn detailed information about the fields of an extension.yaml file in the docs:
# https://firebase.google.com/docs/extensions/alpha/ref-extension-yaml

name: palm-secure-backend # Identifier for your extension
version: 0.1.5 # Follow semver versioning
specVersion: v1beta # Version of the Firebase Extensions specification

# Friendly display name for your extension (~3-5 words)
displayName: Call PaLM API Securely

# Brief description of the task your extension performs (~1 sentence)
description: >-
  Protects your API key and prevents resource abuse by deploying a backend to
  call the PaLM API, secured by App Check.

license: Apache-2.0 # https://spdx.org/licenses/

icon: icon.png

tags:
  [
    ai,
    palm,
    generative-ai,
    text-ai,
    language-ai,
    large-language-models,
    llm,
    nlp,
    google-ai,
  ]

author:
  authorName: Google Cloud
  url: https://cloud.google.com/

contributors:
  - authorName: Invertase
    email: oss@invertase.io
    url: https://github.com/invertase

# Public URL for the source code of your extension
sourceUrl: https://github.com/GoogleCloudPlatform/firebase-extensions/tree/main/palm-secure-backend
releaseNotesUrl: https://github.com/GoogleCloudPlatform/firebase-extensions/tree/main/palm-secure-backend/CHANGELOG.md

# Specify whether a paid-tier billing plan is required to use your extension.
# Learn more in the docs: https://firebase.google.com/docs/extensions/alpha/ref-extension-yaml#billing-required-field
billingRequired: true

# In an `apis` field, list any Google APIs (like Cloud Translation, BigQuery, etc.)
# required for your extension to operate.
# Learn more in the docs: https://firebase.google.com/docs/extensions/alpha/ref-extension-yaml#apis-field

# In a `roles` field, list any IAM access roles required for your extension to operate.
# Learn more in the docs: https://firebase.google.com/docs/extensions/alpha/ref-extension-yaml#roles-field

# In the `resources` field, list each of your extension's functions, including the trigger for each function.
# Learn more in the docs: https://firebase.google.com/docs/extensions/alpha/ref-extension-yaml#resources-field
resources:
  - name: post
    type: firebaseextensions.v1beta.function
    description: >-
      https endpoint wrapping the PaLM API
    properties:
      # LOCATION is a user-configured parameter value specified by the user during installation.
      location: ${LOCATION}
      # httpsTrigger is used for an HTTP triggered function.
      httpsTrigger: {}
      runtime: nodejs18
  - name: getModels
    type: firebaseextensions.v1beta.function
    description: >-
      https endpoint wrapping the PaLM API
    properties:
      # LOCATION is a user-configured parameter value specified by the user during installation.
      location: ${LOCATION}
      # httpsTrigger is used for an HTTP triggered function.
      httpsTrigger: {}
      runtime: nodejs18
  - name: getModel
    type: firebaseextensions.v1beta.function
    description: >-
      https endpoint wrapping the PaLM API
    properties:
      # LOCATION is a user-configured parameter value specified by the user during installation.
      location: ${LOCATION}
      # httpsTrigger is used for an HTTP triggered function.
      httpsTrigger: {}
      runtime: nodejs18

# In the `params` field, set up your extension's user-configured parameters.
# Learn more in the docs: https://firebase.google.com/docs/extensions/alpha/ref-extension-yaml#params-field
params:
  - param: LOCATION
    label: Cloud Functions location
    description: >-
      Where do you want to deploy the functions created for this extension? For
      help selecting a location, refer to the [location selection
      guide](https://firebase.google.com/docs/functions/locations).
    type: select
    options:
      - label: Iowa (us-central1)
        value: us-central1
      - label: South Carolina (us-east1)
        value: us-east1
      - label: Northern Virginia (us-east4)
        value: us-east4
      - label: Los Angeles (us-west2)
        value: us-west2
      - label: Salt Lake City (us-west3)
        value: us-west3
      - label: Las Vegas (us-west4)
        value: us-west4
      - label: Warsaw (europe-central2)
        value: europe-central2
      - label: Belgium (europe-west1)
        value: europe-west1
      - label: London (europe-west2)
        value: europe-west2
      - label: Frankfurt (europe-west3)
        value: europe-west3
      - label: Zurich (europe-west6)
        value: europe-west6
      - label: Hong Kong (asia-east2)
        value: asia-east2
      - label: Tokyo (asia-northeast1)
        value: asia-northeast1
      - label: Osaka (asia-northeast2)
        value: asia-northeast2
      - label: Seoul (asia-northeast3)
        value: asia-northeast3
      - label: Mumbai (asia-south1)
        value: asia-south1
      - label: Jakarta (asia-southeast2)
        value: asia-southeast2
      - label: Montreal (northamerica-northeast1)
        value: northamerica-northeast1
      - label: Sao Paulo (southamerica-east1)
        value: southamerica-east1
      - label: Sydney (australia-southeast1)
        value: australia-southeast1
    required: true
    immutable: true

  - param: API_KEY
    label: API Key
    description: >-
      Google Cloud API Key with PaLM API access enabled.
    type: secret
    required: true

  - param: ENFORCE_APP_CHECK
    label: Enforce App Check
    description: >-
      If enabled, App check will be enforced for function calls.
    type: select
    options:
      - label: Yes
        value: yes
      - label: No
        value: no
    default: no
    required: true

  - param: CUSTOM_HOOK_URL
    label: Custom hook function url
    description: >
      An HTTPS callable function that will be called with the request and
      response body of the PaLM API call, as well as user context.
    type: string
    example: https://us-west1-my-project-id.cloudfunctions.net/customHook
    required: false

events:
  - type: firebase.extensions.palm-secure-backend.v1.onStart
    description: Occurs when any of the extensions functions receive a request.

  - type: firebase.extensions.palm-secure-backend.v1.onRequest
    description:
      Occurs when the extension attempts to fetch a response from the PaLM API.

  - type: firebase.extensions.palm-secure-backend.v1.onResponse
    description:
      Occurs when the extension successfully receives a reponse from the PaLM
      API.

  - type: firebase.extensions.palm-secure-backend.v1.onError
    description: Occurs when the extension fails to complete execution.
