← Files Dwite - AI Store ManagerARCHIVED FILE

README.md

8.84 KB · Nov 27, 2026 · 19:55 UTC

↓ Download file

See the change to this file →

# Dwite Store Operator

Source for the existing public draft `asdk_app_6ac7d933a55c8191b94537d98e441be6`. The plugin identity remains `dwite-store-operator-v2`; package version 2.1.0 retains shared Dwite agent tasks and adds optional task events. The existing MCP endpoint remains `https://app.dwiteai.com/api/mcp`. Do not create another OpenAI app or OAuth client for this update.

## What runs where

ChatGPT submits the merchant's request. Dwite's existing worker runs its agent, skills and connected tools. Its normal events are appended to `tasks` / `task_blocks`. The ChatGPT task card and Dwite website read that same task. Answers to `ask_user` or follow-up requests append ordinary user-message blocks and resume the existing worker.

The task APIs create no new tables. A migration adds `allow_tasks` to the existing permissions table, a service-only atomic command function, and idempotent event append support. The previous grouped-product-review tables are not used in task mode. Historical migrations are retained; this release does not drop tables or data.

## Permissions and OAuth

Keep the current OAuth issuer, audience, registered callback and client allowlist. This package includes no credentials. Merchants must enable View and edit and explicitly opt into **Run Dwite tasks from ChatGPT** in [Dwite Settings](https://app.dwiteai.com/app?settings=dwite-store-operator). Existing product-edit permission does not automatically grant general agent access or task history.

The broader opt-in covers task messages and results and the account's existing agent tools, including tools beyond product copy. The normal agent approval flow applies. This is not a new universal cryptographic gate around every commerce write: the existing Dwite agent and its tools enforce their existing behavior. ChatGPT cannot call the app-only reply tools, and private action tokens bind replies to the owner, task and current event sequence.

Disabling task access blocks new submissions, status reads and replies. Already-running tasks continue unless stopped in Dwite. Stop is best effort and cannot undo completed store actions. Reads are scoped to the authenticated owner before any service-role history query.

## Rollout order — PR only until reviewed

1. Review and apply `supabase/migrations/20261011011557_dwite_mcp_shared_tasks.sql` using the normal migration process. Existing task functions and permissions table must already exist. No #68 review-table migration is needed for this mode.
2. Deploy the worker and backend through `scripts/deploy-server-beta.sh`. Include the new `scripts/task-event-journal.mjs` helper. **Migration must precede worker deployment:** the worker retries event appends with stable event IDs.
3. Ensure the existing `DWITE_MCP_EDIT_SECRET` is at least 32 characters; it signs private task-action tokens with a separate purpose. Keep it server-only. Set `DWITE_MCP_TASKS=on` for the backend only after the migration and worker are ready. No new API key or OAuth login is needed. Leave `DWITE_MCP_GROUPED_REVIEWS` off for this release.
4. Enable the new task opt-in for a test merchant. Refresh MCP discovery and start a fresh chat. In task mode MCP version is 0.5.0 and exposes profile, store connections, submit/get/list/reply/cancel task tools. Legacy cached reads and product-edit tools are not offered or callable in task mode.
5. Run a real read-only task, then a question/reply task. Inspect `task_blocks` on the host and the website: same task id, one initial user message pair, ordered worker events, one answer pair, and no completed status before the journal drains. Verify an approved disposable store edit against the live store. Test denied permission, stale replies, cancellation, connection-required state and mobile/dark card rendering.
6. Record this flow. Add its reviewer-accessible URL to `extensions.com.openai.review.demo_recording_url`. Build the existing public draft's ZIP from this directory and upload it only after the live behavior matches the 2.0.0 manifest. Exclude `.app.json` and development app bindings. Retain the current public app identity.

This PR does not deploy, change live permissions, upload, or submit for review. The old uploaded package is not changed by merging source. Old product cards must be replaced with a fresh task after task mode is enabled.

## Verification

- `node --test scripts/task-event-journal.test.mjs`
- In `rebuild`, run the focused task/server/permission/settings and existing ask-user/follow-up Vitest tests and `npx tsc --noEmit`.
- `python3 scripts/test-shared-task-sql.py <local-postgres-port>` uses **127.0.0.1 only** and creates a disposable test database. It checks ownership, current opt-in, plan limits, concurrent submission/event retries, atomic answer rollback, stale replies, cancellation and revocation against real Postgres.

Live worker execution and the real ChatGPT bridge remain deployment gates. The local card fixture tests cannot prove those live paths.

## Limits

Task history is paged in 100-event chunks; `nextAfterSeq` retrieves older/more progress. `current` projects the latest 100 saved events, so it is a recent snapshot, not an exhaustive audit. Full history and files remain available in the same task on Dwite. The card renders messages, tool activity, existing ask-user forms and suggestions. Connection setup and file previews open Dwite. Task completion is an agent-reported status, not independent proof that every external side effect succeeded.

The plugin's existing default prompts are preserved. In task mode, forward those requests to the Dwite agent instead of using removed cache/product tools.


## Optional completion notifications (2.1.0 test rollout)

The existing task tools cover submission, progress/steps and saved results.
`task.finished` (done/error/cancelled) and `task.needs_input` add **subscribed**
notifications through MCP Events. Events contain task identity/status/link, not
credentials, tool results or the merchant's message history. ChatGPT fetches
saved specifics using `get_task`. No notification is promised without an active
subscription and a compatible host.

1. Apply `20261021183450_dwite_mcp_task_events.sql` **after** shared-task SQL.
   This optional extension adds three private, service-only tables for durable
   subscriptions, short-lived callback verification jobs and delivery retries. It does not alter merchant opt-ins.
2. Deploy backend and worker from the same revision. The worker deploy script
   includes `mcp-event-dispatcher.mjs` and the shared `mcp-events/` modules.
3. Configure `DWITE_MCP_TASKS=on` and `DWITE_MCP_EVENTS=on` in the backend and
   `DWITE_MCP_EVENTS=on` in the existing worker environment. Both must use the
   same `DWITE_MCP_EDIT_SECRET` (used to encrypt callback signing keys). The
   production deployment helper now validates and carries both flags to runtime.
   Callback verification and delivery run on the Node worker with pinned HTTPS;
   the Cloudflare API waits for verification before creating the subscription.
   A real callback check remains a deployment gate.
4. Refresh tools/events on the existing development connection. In a supported
   **Work chat with Cloud selected**, submit a read-only task, then ask ChatGPT
   to monitor `task.finished` for its returned `taskId` and fetch/summarise the
   saved result. Subscribe to `task.needs_input` to surface merchant questions.
   OpenAI supplies and verifies the callback; do not paste a made-up callback.
5. Test completion before subscription (initial status is queued for delivery),
   normal completion, errors, a merchant question, server restart, permission
   revocation and unsubscribe. A revoked/expired subscription cannot send; the
   dispatcher rechecks permission before outbound delivery. In-flight network
   requests may finish during revocation. Replies remain merchant-only.

The legacy MCP tool/card connection stays supported. MCP 2026-07-28 requests use
an explicit adapter around the installed legacy SDK and return complete results;
no MRTR or streaming capability is advertised. Events support HTTPS webhooks,
not polling/streaming/replay. Default expiry is one day, maximum seven days.
Refresh uses the same deterministic subscription ID and signs with old/new
secrets for a five-minute rotation window. Retries retain their event ID and
stop after eight attempts. Delivery is at least once; consumers must deduplicate.

Local verification: `scripts/test-mcp-task-flow.sh`. To also verify real SQL,
start a disposable Postgres cluster and run
`scripts/test-mcp-task-flow.sh --postgres-port PORT`. This only connects to
127.0.0.1 and creates disposable test databases. Unit fixtures do not certify a
live merchant task or a real ChatGPT callback.

Rollback: set `DWITE_MCP_EVENTS=off` on the API and worker. Existing task tools
continue when `DWITE_MCP_TASKS=on`. Keep the tables and migrations; no data
removal is needed. Unsubscribe or revoke access before disabling the dispatcher
if queued events must not resume on a later re-enable.

SHA-256: afdbf739f76165ea5d00eefdd1ef7d046a5b79aa9f45d361ce9dcbe5610a0a76