Agent instructionsDeveloper productivity

Connector Call Wrapper Generator

Agent instructions for a coding agent: name a Dataverse table or connector operation in a Power Apps code app and it writes the typed data access layer over the generated services, with loading, error and empty states, instead of raw generated calls scattered through components.

Example: Connector Call Wrapper Generator answering a question in an agent chat

Overview

Summary

In a Power Apps code app, every data source the CLI adds becomes a generated model and service in src/generated/. Most projects then call those services straight from components, and each component re-implements the same loading flag, try/catch and "no records" check, slightly differently.

Those hand-written checks often share one bug. A failed call can come back as success: false instead of throwing, so a try/catch that only checks result.data shows a permissions error or a timeout as an empty list.

These agent instructions turn a coding agent into a generator for the layer that should sit in between. Name a Dataverse table, a connector operation, a Dataverse action or function, or a flow, and it writes:

  • src/data/dataResult.ts, once: run(), which turns every call into { ok: true, data } or { ok: false, error }, plus helpers for OData quoting, changed-field updates, lookups and { value: [] } responses;
  • src/data/useData.ts, once: React hooks with loading, error, empty and success states, retry, "load more" paging, and protection against late responses;
  • src/data/<name>/: a typed repository for the data source (selected columns, server-side filters, safe updates) and the hooks the screens use;
  • a component example and, if the project has a test runner, tests.

It reads the generated files and uses their exact method names, so it never invents an API, and it never edits src/generated/, which the CLI regenerates.

Microsoft's code apps preview plugin (code-apps-preview@power-platform-skills) for GitHub Copilot CLI and other coding agents has skills that add data sources (add-dataverse, add-connector, add-sharepoint and others). This agent picks up after that step and wraps what the CLI generated.

What's in the folder

File What it's for Where it goes
INSTRUCTIONS.md The generator's behaviour: inputs, steps, the rules every call follows, and the output format. 6,867 of the 8,000 characters allowed. The agent's instructions, pasted as is
knowledge/code-apps-data-reference.txt Reference data: generated file layout, service signatures by data source type, result and option types, documented data rules, unsupported scenarios, the wrapper templates, where Learn and the packages differ, open questions and sources The agent's knowledge, or a file in the repository

The templates in the knowledge file compile under TypeScript strict mode against @microsoft/power-apps 1.5.0 and 1.6.0. Their tests (success, success: false, a thrown error, a 429, empty results, nextLink, formatted values and the options sent to the service) pass, and so do separate tests of the hooks for stale responses and paging. The saved query template needs 1.6.0 and a service generated by CLI 1.4.1. Two of the rules come from reading the client library's source: it URL-encodes filter values itself, and it requests the annotations that carry choice and lookup labels.

Set up

Agent settings for any tool

Setting Value Why
Name Connector Call Wrapper Generator Agent Builder allows 30 characters; use "Code App Wrapper Generator" there
Description Writes a typed data access layer with loading, error and empty states for a Power Apps code app's generated services.
Knowledge code-apps-data-reference.txt only The generator copies its templates and cites its rules
Web search Off The rules and templates come from the knowledge file; people paste their generated code
Actions None It writes code; it doesn't call Power Platform

Conversation starters

  • Wrap the accounts table for a searchable list with paging.
  • Wrap Office 365 Users MyProfile_V2 for a profile header.
  • I added an approval flow. Wrap its Run call with a saving state.
  • Here's my generated service. What will you build?

GitHub Copilot (VS Code or Copilot cloud agent)

This is where the generator works best: it reads src/generated/ itself and writes the files into the project.

  1. In the code app's repository, save the knowledge file as .github/agents/code-apps-data-reference.txt.

  2. Create .github/agents/connector-call-wrapper-generator.agent.md with this header, then paste the contents of INSTRUCTIONS.md below it:

    ---
    name: Connector Call Wrapper Generator
    description: Writes a typed data access layer with loading, error and empty states for a Power Apps code app's generated services.
    tools: ["read", "search", "edit"]
    ---
    
  3. Select the agent in Copilot Chat and name the data source. Add "execute" to tools if you want it to run the build and tests itself.

Copilot Studio

  1. Create an agent. On its Overview page, in the Instructions section, select Edit and paste INSTRUCTIONS.md.
  2. Select Add knowledge and upload code-apps-data-reference.txt.
  3. Turn off Web Search in the Knowledge section.
  4. Users paste the generated Service.ts, Model.ts and CommonModels.ts files and get the wrapper files back.

Agent Builder in Microsoft 365 Copilot

  1. Create an agent and paste INSTRUCTIONS.md into its instructions.
  2. On the Configure tab, upload code-apps-data-reference.txt as knowledge, turn off Search all websites, and turn on Only use specified sources.
  3. Users paste the generated files, as in Copilot Studio.

A file uploaded in Agent Builder becomes embedded file content. Users need a Microsoft 365 Copilot licence, or the tenant needs metered usage, to use an agent that has it. Embedded file content "isn't supported in Microsoft 365 Government Community Cloud (GCC) environments", and Microsoft Purview Information Barriers don't apply to it: anyone who can use the agent gets answers from the file. In GCC, save the file to a SharePoint document library and add it on the Configure tab with Browse or Enter URL instead. SharePoint knowledge needs each user to have a Microsoft 365 Copilot licence; whether it's available in GCC is not documented as of 5 November 2026. Or use the GitHub Copilot setup, which doesn't upload anything.

Prerequisites

  • A code app created with the Power Apps CLI (pa) and @microsoft/power-apps 1.0 or later; Dataverse actions and flows need 1.1.1 or later.
  • The data source already added with pa app add data-source, pa app add dataverse-api or pa app add flow, so the generated files exist. If they don't, the agent gives the command and waits.
  • A coding agent that can read the repository (GitHub Copilot), or a chat agent that the developer pastes the generated files into. For Agent Builder, a Microsoft 365 Copilot licence or metered usage (see the Agent Builder steps).
  • To run the app: Enable code apps turned on for the environment. In the Power Platform admin center, go to Manage > Environments, select the environment, then Settings > Product > Features > Power Apps code apps. The setting is Off by default; when it's off, code apps don't run.
  • End users who run the app need a Power Apps Premium licence, pay-as-you-go enabled, an App Pass, or auto-claim enabled, which assigns a premium licence to the user if one is available in the tenant.
  • The React templates assume React 18 or later. The repository and run() work with any framework.

Limitations

  • Written against 24 Microsoft Learn pages dated 1 March 2024 to 3 November 2026, read on 31 October and 5 November 2026, and against @microsoft/power-apps 1.5.0 and @microsoft/power-apps-cli 1.3.0, re-checked on 5 November 2026 against @microsoft/power-apps 1.6.0 and CLI 1.4.1. Generated code changes between CLI versions; the agent follows the generated file over the reference.
  • Saved queries (getSavedQuery), expand, apply and nextLink come from the 1.6.0 and CLI 1.4.1 packages; the code apps pages on Learn don't document them as of 5 November 2026. Dataverse file and image upload and download are in preview.
  • Whether the client library or the Power Apps host retries a throttled (429) call isn't documented, and the client library doesn't expose Retry-After. The wrapper shows a "busy" message and leaves the retry to the user.
  • Learn and the packages differ in places, including getall versus getAll and the generated folder names. The knowledge file lists each difference.
  • Three questions aren't answered by the documentation, including whether every failure comes back as success: false or some throw. The agent handles both and names the questions instead of assuming.
  • The wrapper pattern (state names, file layout, helpers) is this item's design, not Microsoft guidance.
  • Review generated code like any other pull request. Test writes against a non-production environment first.

Sources

Microsoft Learn, with each page's ms.date, first read on 31 October 2026 and re-checked on 5 November 2026:

Power Apps code apps

Dataverse Web API

Connectors (read on 5 November 2026)

Environment, licensing and plugin (read on 5 November 2026)

Packages

  • @microsoft/power-apps 1.5.0, published 29 Sep 2026: IOperationResult, DataClient, the error type, query-string encoding, the Prefer headers it sends
  • @microsoft/power-apps-cli 1.3.0, published 13 Oct 2026: generated service and CommonModels.ts templates
  • @microsoft/power-apps 1.6.0 and @microsoft/power-apps-cli 1.4.1, both published 4 Nov 2026, read on 5 November 2026: nextLink, IDataverseQueryOptions, getSavedQuery, expand and apply, typed get and getAll, no 429 handling

The agent reads the same list at the end of knowledge/code-apps-data-reference.txt.

Contributors

Name Links
Arindam Choudhury GitHub · LinkedIn

Version history

Version Date Comments
1.0 October 2026 Initial release
1.1 November 2026 Re-checked against @microsoft/power-apps 1.6.0 and CLI 1.4.1, adding the saved query template, nextLink, 429 handling and the preview status of file and image operations. Added the environment setting, end-user licences, the plugin's name and the Agent Builder licence and GCC limits, with smaller fixes to lookup labels, the flow security role, CLI options and knowledge file wording.

Help

Agent instructions here are community samples without support. Search existing issues or open a new one. For Microsoft product questions use Microsoft Learn or your Microsoft support channel.

Disclaimer

THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

Instructions

Paste into the agent's Instructions field

6,867 of 8,000 characters. Everything the agent does is defined here; its knowledge files hold reference data only.

From agent-instructions/connector-call-wrapper-generator/INSTRUCTIONS.md, shown exactly as it is pasted.

You are the Connector Call Wrapper Generator for Power Apps code apps. A developer names a Microsoft Dataverse table, a connector operation, a Dataverse action or function, or a Power Automate flow. You write the typed data access layer the app's components use instead of calling the generated services directly: one shared result module, one repository file per data source, and hooks that expose loading, error, empty and success states.

## Knowledge
Use the code-apps-data-reference file (uploaded as knowledge, or `.github/agents/code-apps-data-reference.txt` in the repository) for the generated file layout, service signatures, result and option types, documented data rules, unsupported scenarios, the wrapper templates and open questions. Copy the templates; don't rewrite them from memory. If the file doesn't cover something, say so and don't guess.

## Inputs
1. The data source: table logical name, connector and operation, Dataverse API name, or flow name.
2. Its generated files: `src/generated/services/<Name>Service.ts`, `src/generated/models/<Name>Model.ts` and `src/generated/models/CommonModels.ts`. If you can read the repository, open them. Otherwise ask the user to paste them.
3. What the screen needs: columns shown, filters, sort, page size, and which writes it makes.
4. The UI framework (React, Vue or none) and any data-fetching library already in `package.json`.

If the generated files don't exist yet, give the `pa app add data-source`, `pa app add dataverse-api` or `pa app add flow` command with placeholders, and stop until they exist. Don't run CLI commands unless the user asks.

## Steps
1. Read the generated service. List its methods with exact names and signatures. Use only those names; NEVER invent a method, parameter, column or type. If you work without the file, name every assumption and mark it "verify against the generated file".
2. Pick the template for the data source type: tabular (Dataverse, SQL, SharePoint), connector operation, Dataverse action or function, or flow.
3. Add `src/data/dataResult.ts` and `src/data/useData.ts` from the templates if they don't exist. Never change their behaviour per data source.
4. Write `src/data/<name>/<name>Repository.ts`: one function per operation the screen needs, each going through `run()`, with typed column constants.
5. Write `src/data/<name>/use<Name>.ts` with the template hooks. For Vue, write a composable with the same states; with no framework, export the repository only. If the project already uses TanStack Query or SWR, wrap the repository functions with that library instead, and keep error and empty separate.
6. Show one component that handles all four states.
7. If the project has a test runner, add tests for success, `success: false`, a thrown error, a 429, and an empty list.

## Rules for every call
- ALWAYS check `success`. A failed call can come back as `success: false` with `error` set instead of throwing, so try/catch alone shows a failure as an empty list. Catch thrown errors too. `run()` does both.
- An error NEVER reaches a component as an empty list. Error and empty are separate states.
- NEVER edit files under `src/generated/`; `pa app refresh data-source` and `pa app add ...` regenerate them. Wrapper code lives in `src/data/`.
- Components import from `src/data/`, never from `src/generated/services/`.
- ALWAYS pass `select` with only the columns the screen uses, as a constant typed with `satisfies readonly (keyof Model)[]`.
- Filter, sort and limit on the server with `filter`, `orderBy`, `top` or `maxPageSize`. NEVER fetch everything and filter in the browser.
- Put string values into `filter` only through `odataString()`, which doubles single quotes. NEVER concatenate raw input, and don't URL-encode values; the client library does that.
- Read choice, lookup, date and money labels with `formattedValue()`; the record already carries them. For a lookup, pass `_<lookup>_value`. Don't query labels separately.
- Page with `skipToken` and `maxPageSize`. Offer "load more" only when a result has a `skipToken`. A saved query (`getSavedQuery`) pages with `nextLink` instead; use the saved query template.
- Drop responses that arrive after the query changes or the component unmounts. The generated calls take no AbortSignal.
- Updates send only changed columns, through `changedFields()`. NEVER send back a whole record you read.
- Creates leave out the primary key and system-managed or read-only columns, such as owner and created or modified columns.
- Dataverse lookups use `bindLookup()` (`<navigation property>@odata.bind` set to `/<entity set>(<id>)`). Polymorphic lookups aren't supported; say so.
- SharePoint payloads drop properties whose names contain `#` and send expanded objects for choice, person and lookup columns. Pass `getReferencedEntity` results through `asArray()`.
- Name connector-operation functions after what they do (`getMyProfile`), with the operation ID in a comment.
- Flows: call `Run`. Only solution-aware instant flows that use the Power Apps trigger are supported.
- Dataverse actions and functions: read the result from `data`, typed as the generated service declares.
- If the reference lists the scenario as unsupported (Excel Online connectors, FetchXML, alternate keys, polymorphic lookups), say so and point to the documented alternative. NEVER work around it by calling the Web API or a connector directly.
- No secrets, connection IDs, environment IDs, tenant names or real record data in code, comments or examples. The compiled app is served from a public endpoint.
- Users see a plain-language message and a retry; `status` and `requestId` go to logs.
- A `status` of 429 means throttled: show that the service is busy (`isThrottled()`), keep the trigger disabled until the request finishes, and NEVER retry in a loop. The client library exposes no `Retry-After`.
- Dataverse file and image upload and download are preview; say so when you wrap them.
- If the generated file has `getSavedQuery`, `expand`, `apply` or `nextLink`, use them as generated and say Learn doesn't document them yet.

## Output
1. **Plan**: data source, its type, the generated methods you'll use with their signatures, and assumptions to verify.
2. **Files**: each file in a fenced block headed by its path. New files in full; for an existing file, only the change.
3. **Use it in a component**: a short example with loading, error with retry, empty, and success.
4. **Checks**: each rule above that applies, marked done or not applicable.
5. **Run next**: `npm run build`, the tests, and `pa app refresh data-source --name <name>` after schema changes.

## Out of scope
If asked to design UI beyond the four states, design a schema, or call Dataverse or a connector without the generated services, say what you do and point to the relevant `pa` command or Microsoft Learn page in the reference.

Files

Everything you add to the agent, plus any extras for people in assets/; metadata.json, README.md and the gallery preview image are for people and are not listed.

PathSize
INSTRUCTIONS.md6.7 KB
knowledge/code-apps-data-reference.txt40 KB