UNPKG

firebase-tools

Version:
71 lines (62 loc) 3.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.schema = void 0; const prompt_1 = require("../../prompt"); const load_1 = require("../../../dataconnect/load"); const types_1 = require("../../../dataconnect/types"); const content_1 = require("../../util/dataconnect/content"); const compile_1 = require("../../util/dataconnect/compile"); function renderServices(fdcServices) { var _a; if (!fdcServices.length) return "Data Connect Status: <UNCONFIGURED>"; return `\n\n## Data Connect Schema The following is the up-to-date content of existing schema files (their paths are relative to the Data Connect source directory). ${(_a = (0, types_1.mainSchema)(fdcServices[0].schemas) .source.files) === null || _a === void 0 ? void 0 : _a.map((f) => `\`\`\`graphql ${f.path}\n${f.content}\n\`\`\``).join("\n\n")}`; } function renderErrors(errors) { return `\n\n## Current Schema Build Errors\n\n${errors || "<NO ERRORS>"}`; } exports.schema = (0, prompt_1.prompt)("core", { name: "schema", description: "Generate or update your Firebase Data Connect schema.", arguments: [ { name: "prompt", description: "describe the schema you want generated or the edits you want to make to your existing schema", required: true, }, ], annotations: { title: "Generate Data Connect Schema", }, }, async ({ prompt }, { config, projectId, accountEmail }) => { const fdcServices = await (0, load_1.loadAll)(projectId, config); const buildErrors = fdcServices.length ? await (0, compile_1.compileErrors)(fdcServices[0].sourceDirectory) : ""; return [ { role: "user", content: { type: "text", text: ` ${content_1.MAIN_INSTRUCTIONS}\n\n${content_1.BUILTIN_SDL} ==== CURRENT ENVIRONMENT INFO ==== User Email: ${accountEmail || "<NONE>"} Project ID: ${projectId || "<NONE>"} ${renderServices(fdcServices)}${renderErrors(buildErrors)} ==== USER PROMPT ==== ${prompt} ==== TASK INSTRUCTIONS ==== 1. If Data Connect is marked as \`<UNCONFIGURED>\`, first run the \`firebase_init\` tool with \`{dataconnect: {}}\` arguments to initialize it. 2. If there is not an existing schema to work with (or the existing schema is the commented-out default schema about a movie app), follow the user's prompt to generate a robust schema meeting the specified requirements. 3. If there is already a schema, perform edits to the existing schema file(s) based on the user's instructions. If schema build errors are present and seem relevant to your changes, attempt to fix them. 4. After you have performed edits on the schema, run the \`dataconnect_compile\` tool to build the schema and see if there are any errors. Fix errors that are related to the user's prompt or your changes. 5. If there are errors, attempt to fix them. If you have attempted to fix them 3 times without success, ask the user for help. 6. If there are no errors, write a brief paragraph summarizing your changes.`, }, }, ]; });