From 93accb9472abc5cd32ebc2d15b7d9dbdc573d540 Mon Sep 17 00:00:00 2001 From: Atharva Deosthale Date: Tue, 18 Nov 2025 17:12:27 +0530 Subject: [PATCH] final tweaks to prompt to perfect the agent behaviour --- .../overview/platforms/createAndroid.svelte | 54 ++++++++++++------ .../overview/platforms/createApple.svelte | 2 +- .../overview/platforms/createFlutter.svelte | 28 ++++----- .../platforms/createReactNative.svelte | 28 ++++----- .../overview/platforms/createWeb.svelte | 57 ++++++++++--------- .../overview/platforms/store.ts | 22 ++++--- 6 files changed, 109 insertions(+), 82 deletions(-) diff --git a/src/routes/(console)/project-[region]-[project]/overview/platforms/createAndroid.svelte b/src/routes/(console)/project-[region]-[project]/overview/platforms/createAndroid.svelte index 1758e9a8f..aa9023ebc 100644 --- a/src/routes/(console)/project-[region]-[project]/overview/platforms/createAndroid.svelte +++ b/src/routes/(console)/project-[region]-[project]/overview/platforms/createAndroid.svelte @@ -38,28 +38,48 @@ const projectId = page.params.project; const alreadyExistsInstructions = ` - Install the Appwrite Android SDK by adding the following dependency to app-level build.gradle.kts file under dependencies block: +Confirm you're working inside the correct Android project before editing anything: +- Navigate into the directory that contains the real Android app module (look for gradlew, settings.gradle, and the app-level build.gradle(.kts)). +- If Cursor opens in a parent folder (like your home directory) or you see multiple Android projects, ask which one to modify before making changes. +- Update the app-level build.gradle.kts by default, but be ready to edit a Groovy build.gradle if the project hasn't migrated to Kotlin DSL yet. - \`\`\` - implementation("io.appwrite:sdk-for-android:8.1.0") - \`\`\` +Prefer Version Catalogs when adding the Appwrite SDK: +1. If ./gradle/libs.versions.toml exists, add or reuse an Appwrite entry: +\`\`\`toml +[libraries] +appwrite = { module = "io.appwrite:sdk-for-android", version = "11.3.0" } +\`\`\` +2. Reference it inside the module's dependencies block: +\`\`\`kotlin +dependencies { + implementation(libs.appwrite) +} +\`\`\` +Only when the project lacks ./gradle/libs.versions.toml should you hardcode the dependency: +\`\`\`kotlin +implementation("io.appwrite:sdk-for-android:11.3.0") +\`\`\` +Legacy Groovy scripts should use: +\`\`\`groovy +implementation "io.appwrite:sdk-for-android:11.3.0" +\`\`\` - From a suitable lib directory, export the Appwrite client as a global variable: +Before introducing any new files, search the project (app/src, libs/, shared modules, etc.) for existing Appwrite client helpers (look for \`Client(\`, \`AppwriteClient\`, or \`.setEndpoint\`). If a client already exists, update its configuration instead of creating a duplicate. - \`\`\` - val client = Client() - .setEndpoint("${sdk.forProject(page.params.region, page.params.project).client.config.endpoint}") - .setProject("${projectId}") +Ensure the Appwrite client is initialized with the application context and current project info: +\`\`\`kotlin +val client = Client(applicationContext) + .setEndpoint("${sdk.forProject(page.params.region, page.params.project).client.config.endpoint}") + .setProject("${projectId}") - val account = Account(client) - \`\`\` +val account = Account(client) +\`\`\` - On the homepage of the app, create a button that says "Send a ping" and when clicked, it should call the following function: - - \`\`\` - client.ping() - \`\`\` - `; +From the app's entry point (e.g., Application class or the first launched Activity), automatically invoke a helper that pings Appwrite so the user can verify connectivity and will be reflected on the Appwrite console: +\`\`\`kotlin +client.ping() +\`\`\` +`; const gitCloneCode = '\ngit clone https://github.com/appwrite/starter-for-android\ncd starter-for-android\n'; diff --git a/src/routes/(console)/project-[region]-[project]/overview/platforms/createApple.svelte b/src/routes/(console)/project-[region]-[project]/overview/platforms/createApple.svelte index 1b9a37f40..0f428a78e 100644 --- a/src/routes/(console)/project-[region]-[project]/overview/platforms/createApple.svelte +++ b/src/routes/(console)/project-[region]-[project]/overview/platforms/createApple.svelte @@ -59,7 +59,7 @@ On the homepage of the app, create a button that says "Send a ping" and when clicked, it should call the following function: \`\`\` - appwrite.ping() + client.ping() \`\`\` `; diff --git a/src/routes/(console)/project-[region]-[project]/overview/platforms/createFlutter.svelte b/src/routes/(console)/project-[region]-[project]/overview/platforms/createFlutter.svelte index c06185847..e0e662602 100644 --- a/src/routes/(console)/project-[region]-[project]/overview/platforms/createFlutter.svelte +++ b/src/routes/(console)/project-[region]-[project]/overview/platforms/createFlutter.svelte @@ -40,25 +40,25 @@ const projectId = page.params.project; const alreadyExistsInstructions = ` - Install the Appwrite Flutter SDK using the following command: +Install the Appwrite Flutter SDK using the following command: - \`\`\` - flutter pub add appwrite:17.0.0 - \`\`\` +\`\`\` +flutter pub add appwrite:20.3.0 +\`\`\` - From a suitable lib directory, export the Appwrite client as a global variable, hardcode the project details too: +From a suitable lib directory, export the Appwrite client as a global variable, hardcode the project details too: - \`\`\` - final Client client = Client() - .setProject("${projectId}") - .setEndpoint("${sdk.forProject(page.params.region, page.params.project).client.config.endpoint}"); - \`\`\` +\`\`\` +final Client client = Client() + .setProject("${projectId}") + .setEndpoint("${sdk.forProject(page.params.region, page.params.project).client.config.endpoint}"); +\`\`\` - On the homepage of the app, create a button that says "Send a ping" and when clicked, it should call the following function: +On the homepage of the app, create a button that says "Send a ping" and when clicked, it should call the following function: - \`\`\` - client.ping(); - \`\`\` +\`\`\` +client.ping(); +\`\`\` `; const gitCloneCode = diff --git a/src/routes/(console)/project-[region]-[project]/overview/platforms/createReactNative.svelte b/src/routes/(console)/project-[region]-[project]/overview/platforms/createReactNative.svelte index d76c674f3..af345372e 100644 --- a/src/routes/(console)/project-[region]-[project]/overview/platforms/createReactNative.svelte +++ b/src/routes/(console)/project-[region]-[project]/overview/platforms/createReactNative.svelte @@ -40,25 +40,25 @@ const projectId = page.params.project; const alreadyExistsInstructions = ` - Install the Appwrite React Native SDK using the following command, respect user's package manager of choice and use the one being used in the codebase: +Install the Appwrite React Native SDK using the following command, respect user's package manager of choice and use the one being used in the codebase: - \`\`\` - npx expo install react-native-appwrite react-native-url-polyfill - \`\`\` +\`\`\` +npx expo install react-native-appwrite react-native-url-polyfill +\`\`\` - From a suitable lib directory, export the Appwrite client as a global variable, hardcode the project details too: +From a suitable lib directory, export the Appwrite client as a global variable, hardcode the project details too: - \`\`\` - const client = new Client() - .setProject("${projectId}") - .setEndpoint("${sdk.forProject(page.params.region, page.params.project).client.config.endpoint}"); - \`\`\` +\`\`\` +const client = new Client() + .setProject("${projectId}") + .setEndpoint("${sdk.forProject(page.params.region, page.params.project).client.config.endpoint}"); +\`\`\` - On the homepage of the app, create a button that says "Send a ping" and when clicked, it should call the following function: +From the entrypoint of the app, make it so that the following function is automatically called which will ping the Appwrite backend server to verify the setup. Let the user know about this function being added - \`\`\` - client.ping(); - \`\`\` +\`\`\` +client.ping(); +\`\`\` `; const gitCloneCode = diff --git a/src/routes/(console)/project-[region]-[project]/overview/platforms/createWeb.svelte b/src/routes/(console)/project-[region]-[project]/overview/platforms/createWeb.svelte index 6b259468e..debaff0fc 100644 --- a/src/routes/(console)/project-[region]-[project]/overview/platforms/createWeb.svelte +++ b/src/routes/(console)/project-[region]-[project]/overview/platforms/createWeb.svelte @@ -165,33 +165,33 @@ ${prefix}APPWRITE_ENDPOINT = "${sdk.forProject(page.params.region, page.params.p const llmConfig: LLMPromptConfig = $derived({ alreadyExistsInstructions: ` - Install the Appwrite web SDK using the following command. Respect the user's package manager of choice. Do not use NPM if the user uses Bun for example. +Install the Appwrite web SDK using the following command. Respect the user's package manager of choice. Do not use NPM if the user uses Bun for example. - \`\`\`bash - npm install appwrite - \`\`\` +\`\`\`bash +npm install appwrite +\`\`\` - Create a new \`appwrite.js\` (or equivalent, respecting the framework and language, don't create a JS file if TS is being used in the project) file in a suitable lib directory and have the following code: +Create a new \`appwrite.js\` (or equivalent, respecting the framework and language, don't create a JS file if TS is being used in the project) file in a suitable lib directory and have the following code: - \`\`\`js - import { Client, Account, Databases } from "appwrite"; +\`\`\`js +import { Client, Account, Databases } from "appwrite"; - const client = new Client() - .setEndpoint("${sdk.forProject(page.params.region, page.params.project).client.config.endpoint}") - .setProject("${projectId}"); +const client = new Client() + .setEndpoint("${sdk.forProject(page.params.region, page.params.project).client.config.endpoint}") + .setProject("${projectId}"); - const account = new Account(client); - const databases = new Databases(client); +const account = new Account(client); +const databases = new Databases(client); - export { client, account, databases }; - \`\`\` +export { client, account, databases }; +\`\`\` - On the homepage of the app, create a button that says "Send a ping" and when clicked, it should call the following function: +When the app is opened, make it so that the following function is automatically called which will ping the Appwrite backend server to verify the setup. Let the user know about this function being added - \`\`\`js - client.ping(); - \`\`\` - `, +\`\`\`js +client.ping(); +\`\`\` +`, title: `Copy prompt: starter kit for Appwrite in ${selectedFramework?.label || 'Web'}`, cloneCommand: `git clone https://github.com/appwrite/starter-for-${selectedFramework?.key}\ncd starter-for-${selectedFramework?.key}`, configFile: @@ -199,15 +199,18 @@ ${prefix}APPWRITE_ENDPOINT = "${sdk.forProject(page.params.region, page.params.p ? 'src/environments/environment.ts' : 'appwrite.js', configCode: - selectedFramework?.key === 'angular' - ? `APPWRITE_PROJECT_ID=${projectId}\nAPPWRITE_PROJECT_NAME=${$project.name}\nAPPWRITE_ENDPOINT=${sdk.forProject(page.params.region, page.params.project).client.config.endpoint}` - : ` - const client = new Client() - .setEndpoint("${sdk.forProject(page.params.region, page.params.project).client.config.endpoint}") - .setProject("${projectId}"); - `, + // selectedFramework?.key === 'angular' + // ? `APPWRITE_PROJECT_ID=${projectId}\nAPPWRITE_PROJECT_NAME=${$project.name}\nAPPWRITE_ENDPOINT=${sdk.forProject(page.params.region, page.params.project).client.config.endpoint}` + // : ` + // const client = new Client() + // .setEndpoint("${sdk.forProject(page.params.region, page.params.project).client.config.endpoint}") + // .setProject("${projectId}"); + // `, + `APPWRITE_PROJECT_ID = "${projectId}" +APPWRITE_PROJECT_NAME = "${$project.name}" +APPWRITE_ENDPOINT = "${sdk.forProject(page.params.region, page.params.project).client.config.endpoint}"`, configLanguage: selectedFramework?.key === 'angular' ? 'ts' : 'dotenv', - runInstructions: `${selectedFramework?.key === 'angular' && 'Replace the file with the configuration above'}. Install project dependencies using \`npm install\`, then run the app using \`${selectedFramework?.runCommand}\`. Demo app runs on http://localhost:${selectedFramework?.portNumber}. Click the \`Send a ping\` button to verify the setup.`, + runInstructions: `Install project dependencies using \`npm install\`, then run the app using \`${selectedFramework?.runCommand}\`. Demo app runs on http://localhost:${selectedFramework?.portNumber}. Click the \`Send a ping\` button to verify the setup.`, using: 'the terminal or VSCode' }); diff --git a/src/routes/(console)/project-[region]-[project]/overview/platforms/store.ts b/src/routes/(console)/project-[region]-[project]/overview/platforms/store.ts index ea5296d4f..8111af1f3 100644 --- a/src/routes/(console)/project-[region]-[project]/overview/platforms/store.ts +++ b/src/routes/(console)/project-[region]-[project]/overview/platforms/store.ts @@ -34,6 +34,14 @@ export function getCorrectTitle(isConnectPlatform: boolean, platform: string) { export function generatePromptFromConfig(config: LLMPromptConfig): string { return ` +Goal: Setting up Appwrite SDK in the project depending on if a project already exists or not. + +Following are the project details: + +\`\`\` +${config.configCode} +\`\`\` + Follow the steps depending on if a project already exists on user's working directory or not: ## If a project already exists: @@ -41,17 +49,13 @@ ${config.alreadyExistsInstructions} ## If a project does not exist: -1. If you're starting a new project, you can clone our starter kit from GitHub using ${config.using || 'the terminal'}. Make sure to clone in the current working directory root so that the files are directly available in the working directory. +1. Clone the starter kit using ${config.using || 'the terminal'}. Make sure to clone in the current working directory so that the cloned files are directly available in the working directory. \`\`\`bash -${config.cloneCommand} +${config.cloneCommand} . \`\`\` -2. Open the file \`${config.configFile}\`, find the code block, replace and hardcode the project details as mentioned below. - -\`\`\` -${config.configCode} -\`\`\` +2. Replace all the occurences of environment variables with the keys mentioned in the project details section with the values mentioned in the project details section. That'd mean we are hardcoding the project details wherever project details environment variables are used. Use grep to find all the occurences of the environment variables and replace them with the values mentioned in the project details section. 3. ${config.runInstructions}`; } @@ -94,7 +98,7 @@ const platformConfigs: Record = { configFile: 'lib/config/environment.dart', configLanguage: 'dart', runInstructions: - 'Run the app on a connected device or simulator using `flutter run -d [device_name]`, then click the `Send a ping` button to verify the setup.', + 'Run the app on a connected device or simulator using `flutter run -d [device_name]`, then click the `Send a ping` button to verify the setup. Ask the user if the AI agent should run the command to run the app for them. Provide the full command while you ask for permission.', using: 'the terminal' }, reactnative: { @@ -104,7 +108,7 @@ const platformConfigs: Record = { configFile: 'index.ts', configLanguage: 'typescript', runInstructions: - 'After replacing and hardcoding project details, run the app on a connected device or simulator using `npm install` followed by `npm run ios` or `npm run android`, then click the `Send a ping` button to verify the setup.', + 'After replacing and hardcoding project details, run the app on a connected device or simulator using `npm install` followed by `npm run ios` or `npm run android`, then click the `Send a ping` button to verify the setup. Ask the user if the AI agent should run the command to run the app for them. Provide the full command while you ask for permission.', using: 'the terminal or VSCode' } };