-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Testing new agent skills #1256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Testing new agent skills #1256
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,6 +16,8 @@ | |||||
|
|
||||||
| // [START presence_sync_function] | ||||||
| const functions = require('firebase-functions/v1'); | ||||||
| const { onValueUpdated } = require("firebase-functions/v2/database"); | ||||||
|
|
||||||
| const admin = require('firebase-admin'); | ||||||
| admin.initializeApp(); | ||||||
|
|
||||||
|
|
@@ -26,8 +28,8 @@ const firestore = admin.firestore(); | |||||
|
|
||||||
| // Create a new function which is triggered on changes to /status/{uid} | ||||||
| // Note: This is a Realtime Database trigger, *not* Firestore. | ||||||
| exports.onUserStatusChanged = functions.database.ref('/status/{uid}').onUpdate( | ||||||
| async (change, context) => { | ||||||
| exports.onUserStatusChanged = onValueUpdated('/status/{uid}', async ({ change, context }) => { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Cloud Functions v2, the trigger handler receives a single
Suggested change
|
||||||
|
|
||||||
| // Get the data written to Realtime Database | ||||||
| const eventStatus = change.after.val(); | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,8 @@ | |
| */ | ||
|
|
||
| const {functions} = require("firebase-functions/v1"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and elsewhere, isn't functions no longer needed? |
||
| const { beforeUserCreated, beforeUserSignedIn } = require("firebase-functions/v2/identity"); | ||
|
|
||
| const {admin} = require("firebase-admin"); | ||
|
|
||
| admin.initializeApp(); | ||
|
|
@@ -23,9 +25,8 @@ const db = admin.firestore(); | |
| // [START v1ValidateNewUser] | ||
| // [START v1beforeCreateFunctionTrigger] | ||
| // Block account creation with any non-acme email address. | ||
| exports.validateNewUser = functions.auth | ||
| .user() | ||
| .beforeCreate((user, context) => { | ||
| exports.validateNewUser = beforeUserCreated(({ data: user }) => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should just be {user} right? |
||
|
|
||
| // [END v1beforeCreateFunctionTrigger] | ||
| // [START v1readEmailData] | ||
| // Email passed from the User object. | ||
|
|
@@ -48,9 +49,8 @@ exports.validateNewUser = functions.auth | |
| // [START v1CheckForBan] | ||
| // [START v1beforeSignInFunctionTrigger] | ||
| // Block account sign in with any banned account. | ||
| exports.checkForBan = functions.auth | ||
| .user() | ||
| .beforeSignIn(async (user, context) => { | ||
| exports.checkForBan = beforeUserSignedIn(async ({ data: user }) => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again {user} |
||
|
|
||
| // [END v1beforeSignInFunctionTrigger] | ||
| // [START v1readEmailData] | ||
| // Email passed from the User object. | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,8 @@ | |||||
|
|
||||||
| // [START import] | ||||||
| const functions = require('firebase-functions/v1'); | ||||||
| const { onMessagePublished } = require("firebase-functions/v2/pubsub"); | ||||||
|
|
||||||
| // [END import] | ||||||
|
|
||||||
| // [START helloWorld] | ||||||
|
|
@@ -25,7 +27,8 @@ const functions = require('firebase-functions/v1'); | |||||
| * topic. | ||||||
| */ | ||||||
| // [START trigger] | ||||||
| exports.helloPubSub = functions.pubsub.topic('topic-name').onPublish((message) => { | ||||||
| exports.helloPubSub = onMessagePublished('topic-name', ({ message, context }) => { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Cloud Functions v2, the Pub/Sub handler receives a single
Suggested change
|
||||||
|
|
||||||
| // [END trigger] | ||||||
| // [START readBase64] | ||||||
| // Decode the PubSub Message body. | ||||||
|
|
@@ -41,7 +44,8 @@ exports.helloPubSub = functions.pubsub.topic('topic-name').onPublish((message) = | |||||
| * Cloud Function to be triggered by Pub/Sub that logs a message using the data published to the | ||||||
| * topic as JSON. | ||||||
| */ | ||||||
| exports.helloPubSubJson = functions.pubsub.topic('another-topic-name').onPublish((message) => { | ||||||
| exports.helloPubSubJson = onMessagePublished('another-topic-name', ({ message, context }) => { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Cloud Functions v2, the Pub/Sub handler receives a single
Suggested change
|
||||||
|
|
||||||
| // [START readJson] | ||||||
| // Get the `name` attribute of the PubSub message JSON body. | ||||||
| let name = null; | ||||||
|
|
@@ -60,7 +64,8 @@ exports.helloPubSubJson = functions.pubsub.topic('another-topic-name').onPublish | |||||
| * Cloud Function to be triggered by Pub/Sub that logs a message using the data attributes | ||||||
| * published to the topic. | ||||||
| */ | ||||||
| exports.helloPubSubAttributes = functions.pubsub.topic('yet-another-topic-name').onPublish((message) => { | ||||||
| exports.helloPubSubAttributes = onMessagePublished('yet-another-topic-name', ({ message, context }) => { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Cloud Functions v2, the Pub/Sub handler receives a single
Suggested change
|
||||||
|
|
||||||
| // [START readAttributes] | ||||||
| // Get the `name` attribute of the message. | ||||||
| const name = message.attributes.name; | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,8 @@ | |||||
|
|
||||||
| // [START import] | ||||||
| const functions = require('firebase-functions/v1'); | ||||||
| const { onObjectFinalized } = require("firebase-functions/v2/storage"); | ||||||
|
|
||||||
| const admin = require('firebase-admin'); | ||||||
| admin.initializeApp() | ||||||
| const path = require('path'); | ||||||
|
|
@@ -31,7 +33,8 @@ const sharp = require('sharp'); | |||||
| * generate a thumbnail automatically using sharp. | ||||||
| */ | ||||||
| // [START generateThumbnailTrigger] | ||||||
| exports.firstGenGenerateThumbnail = functions.storage.object().onFinalize(async (object) => { | ||||||
| exports.firstGenGenerateThumbnail = onObjectFinalized(async ({ object, context }) => { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Cloud Functions v2, the Storage handler receives a single
Suggested change
|
||||||
|
|
||||||
| // [END generateThumbnailTrigger] | ||||||
| // [START eventAttributes] | ||||||
| const fileBucket = object.bucket; // The Storage bucket that contains the file. | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,9 @@ | |||||
| // [START import] | ||||||
| // The Cloud Functions for Firebase SDK to create Cloud Functions and set up triggers. | ||||||
| const functions = require('firebase-functions/v1'); | ||||||
| const { onRequest } = require("firebase-functions/v2/https"); | ||||||
| const { onDocumentCreated } = require("firebase-functions/v2/firestore"); | ||||||
|
|
||||||
|
|
||||||
| // The Firebase Admin SDK to access Firestore. | ||||||
| const admin = require("firebase-admin"); | ||||||
|
|
@@ -29,7 +32,8 @@ admin.initializeApp(); | |||||
| // Take the text parameter passed to this HTTP endpoint and insert it into | ||||||
| // Firestore under the path /messages/:documentId/original | ||||||
| // [START addMessageTrigger] | ||||||
| exports.addMessage = functions.https.onRequest(async (req, res) => { | ||||||
| exports.addMessage = onRequest(async (req, res) => { | ||||||
|
|
||||||
| // [END addMessageTrigger] | ||||||
| // Grab the text parameter. | ||||||
| const original = req.query.text; | ||||||
|
|
@@ -49,9 +53,8 @@ exports.addMessage = functions.https.onRequest(async (req, res) => { | |||||
| // Listens for new messages added to /messages/:documentId/original and creates an | ||||||
| // uppercase version of the message to /messages/:documentId/uppercase | ||||||
| // [START makeUppercaseTrigger] | ||||||
| exports.makeUppercase = functions.firestore | ||||||
| .document("/messages/{documentId}") | ||||||
| .onCreate((snap, context) => { | ||||||
| exports.makeUppercase = onDocumentCreated("/messages/{documentId}", ({ snapshot: snap, context }) => { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Cloud Functions v2, the Firestore handler receives a single
Suggested change
|
||||||
|
|
||||||
| // [END makeUppercaseTrigger] | ||||||
| // [START makeUppercaseBody] | ||||||
| // Grab the current value of what was written to Firestore. | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,9 @@ | |||||
| // [START import] | ||||||
| // The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers. | ||||||
| const functions = require('firebase-functions/v1'); | ||||||
| const { onRequest } = require("firebase-functions/v2/https"); | ||||||
| const { onValueCreated } = require("firebase-functions/v2/database"); | ||||||
|
|
||||||
|
|
||||||
| // The Firebase Admin SDK to access the Firebase Realtime Database. | ||||||
| const admin = require('firebase-admin'); | ||||||
|
|
@@ -29,7 +32,8 @@ admin.initializeApp(); | |||||
| // Take the text parameter passed to this HTTP endpoint and insert it into the | ||||||
| // Realtime Database under the path /messages/:pushId/original | ||||||
| // [START addMessageTrigger] | ||||||
| exports.addMessage = functions.https.onRequest(async (req, res) => { | ||||||
| exports.addMessage = onRequest(async (req, res) => { | ||||||
|
|
||||||
| // [END addMessageTrigger] | ||||||
| // Grab the text parameter. | ||||||
| const original = req.query.text; | ||||||
|
|
@@ -45,8 +49,8 @@ exports.addMessage = functions.https.onRequest(async (req, res) => { | |||||
| // [START makeUppercase] | ||||||
| // Listens for new messages added to /messages/:pushId/original and creates an | ||||||
| // uppercase version of the message to /messages/:pushId/uppercase | ||||||
| exports.makeUppercase = functions.database.ref('/messages/{pushId}/original') | ||||||
| .onCreate((snapshot, context) => { | ||||||
| exports.makeUppercase = onValueCreated('/messages/{pushId}/original', ({ snapshot, context }) => { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Cloud Functions v2, the Realtime Database handler receives a single
Suggested change
|
||||||
|
|
||||||
| // Grab the current value of what was written to the Realtime Database. | ||||||
| const original = snapshot.val(); | ||||||
| functions.logger.log('Uppercasing', context.params.pushId, original); | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -15,13 +15,16 @@ | |||||
| */ | ||||||
|
|
||||||
| const functions = require('firebase-functions/v1'); | ||||||
| const { onConfigUpdated } = require("firebase-functions/v2/remoteConfig"); | ||||||
|
|
||||||
| const admin = require('firebase-admin'); | ||||||
| const jsonDiff = require('json-diff'); | ||||||
|
|
||||||
| admin.initializeApp(); | ||||||
|
|
||||||
| // [START remote_config_function] | ||||||
| exports.showConfigDiff = functions.remoteConfig.onUpdate(versionMetadata => { | ||||||
| exports.showConfigDiff = onConfigUpdated(({ version: versionMetadata, context }) => { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Cloud Functions v2, the Remote Config handler receives a single
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually correct I assume (renaming the parameter) and is the kind of neat thing using a skill gives us |
||||||
|
|
||||||
| return admin.credential.applicationDefault().getAccessToken() | ||||||
| .then(accessTokenObj => { | ||||||
| return accessTokenObj.access_token; | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this work with {context}?