Reproducing a Chat Web Page with AI Coding Agents: Engineering Methods and Acceptance Practices

    This article explains how to treat a chat web page built with an AI coding agent as an engineering task rather than a front-end exercise. It covers turning observed behavior into verifiable requirements, splitting delivery into a product analysis, a baseline version, and an optimized version, and managing conversation state, service integration, security boundaries, and testing. It also describes the evidence needed to judge whether the result is reliable.

    1. From “Copy the Page” to a Verifiable Engineering Task

    Building a chat web page with an AI coding system looks like a front-end task. In practice, it involves product analysis, interaction design, server-side integration, data management, and testing.

    If the request is only “match the interface, complete the features, and add some optimizations,” the system has to fill in many implicit conditions on its own. For example: Is the session kept after a page refresh? Can the user switch sessions while a response is still generating? Does the Stop button actually cancel the upstream request? Does the input area stay visible when the mobile keyboard opens? If these conditions are not defined in advance, the final delivery tends to stop at a demo that only displays content.

    A more sound approach is to split the task into three separate deliverables:

    1. Product analysis document and feature structure diagram: Record what was observed, what was inferred, and which behaviors still need verification.
    2. Baseline reproduction: Within authorized scope, build an implementation that meets the confirmed features and interactions, and can be checked against acceptance criteria.
    3. Independent optimized version: Keep the core usage path, make improvements to specific problems, and explain the benefits and costs.

    “Reproduction” should target a page you own, a page you are authorized to use, or a general interaction pattern. Being able to access a page does not mean you may copy its branding, assets, or original design. Technical analysis also cannot replace the necessary authorization.

    2. Product Analysis Comes Before Code Generation

    2.1 Turn observations into requirement evidence

    A product document should do more than list feature names. For each feature, record the entry point, the steps to use it, the preconditions, the state changes, and the abnormal behavior.

    For example, “chat history” raises at least these questions:

    • How does a user create, select, and delete a session?
    • When is the session name generated, and can the user change it?
    • After the current session is deleted, where does the page navigate?
    • Is history stored only on the current device, or synced through an account?
    • If the session list fails to load, can the user still start a new conversation?

    Answers that can be confirmed through page operations should be recorded as observations. Answers that cannot be confirmed should be listed as items to verify. Do not present a guess as an established fact.

    It is especially important to distinguish between “the interface has an entry point” and “the backend capability is available.” An attachment button does not prove that the system supports every file type, and it does not prove that files are stored long term.

    2.2 Use a structure diagram to define the implementation boundary

    A general chat application can be broken down as follows:

    1. Chat Application
    2. ├─ Session Management
    3. │ ├─ Create and switch
    4. │ ├─ Rename and delete
    5. │ └─ Restore history
    6. ├─ Message Interaction
    7. │ ├─ Input and send
    8. │ ├─ Incremental content display
    9. │ ├─ Stop generation
    10. │ ├─ Copy content
    11. │ └─ Retry on failure
    12. ├─ Content Rendering
    13. │ ├─ Paragraphs, lists, and quotes
    14. │ ├─ Code blocks
    15. │ └─ Links and other supported content
    16. ├─ Preferences
    17. │ ├─ Appearance settings
    18. │ └─ Input behavior settings
    19. └─ Foundations
    20. ├─ Identity and permissions
    21. ├─ Data storage
    22. ├─ Error feedback
    23. └─ Logging and monitoring

    The diagram is not a checklist of features that must all be built. Each node should be marked as in scope for this release, planned for later, or explicitly unsupported. Without these labels, a coding agent can easily make unimplemented features look like working buttons that do nothing.

    2.3 Verify visual consistency and behavioral consistency separately

    Visual consistency covers layout, spacing, font hierarchy, colors, corner radius, and responsive behavior. Behavioral consistency covers send conditions, focus movement, scrolling logic, data restoration, and error handling.

    Record the two separately. An interface that looks close to the original does not prove that switching sessions avoids mixing up messages. A working back button does not prove that the mobile layout is acceptable.

    3. Use Staged Prompts Instead of One Large Goal

    A complex task is better handled in stages, where each stage has defined inputs, outputs, and checkpoints.

    Stage 1: Analysis and modeling

    Ask the system to produce a list of page regions, a feature structure diagram, a state table, open questions, and an implementation plan. Do not ask it to build the full application yet. This makes it possible to find gaps before coding, which reduces rework later.

    Stage 2: Baseline implementation with mock data

    Use a mock service to cover normal responses, slow responses, empty content, request failures, and user cancellation. The value of a mock environment is not only lower API cost. It also makes boundary conditions reproducible.

    Mock implementations must be clearly labeled. A fixed text response must not pass as a real service integration.

    Stage 3: Connect to real services

    The integration stage should change only the data path, authentication, and protocol adapter. Avoid restructuring the interface at the same time. Otherwise, when something breaks, it is hard to tell whether the cause is a layout change, a state logic change, or the service call.

    Stage 4: Independent optimization

    Build the optimized version only after the baseline passes acceptance. Do not add many new features before the basic behavior is confirmed. Otherwise, you cannot judge the quality of the reproduction, and you cannot measure whether the optimizations actually help.

    4. The Core of a Chat App Is State, Not the Input Box

    4.1 Define the message lifecycle

    A single chat request usually moves through these states:

    1. Pending → Requesting → Receiving → Completed
    2. ├→ Cancelled
    3. └→ Failed

    These states determine when buttons are enabled, how the interface communicates progress, and when data is persisted.

    For example, when the user clicks Stop, the partial output can be kept, but it must be clearly marked as incomplete. A network interruption should also not look like a normal finish. If the two cases look the same, users cannot tell whether a response is complete.

    4.2 Use stable identifiers for asynchronous events

    Sessions, messages, and requests should each have their own stable identifiers. Asynchronous callbacks must not depend only on “the session that is currently open.”

    Suppose the user starts generating a response in Session A, then switches to Session B. A late response should still be written to Session A, not to the page the user is currently viewing. Similarly, if a session is deleted, a late response from an old request must not recreate the deleted content.

    Request mapping, cancellation signals, and state checks can handle these race conditions. Unmounting a UI component does not automatically end the network request, so cancellation and cleanup must be designed explicitly.

    4.3 Separate displayed history from request context

    Not all messages shown on the page should be sent to the generation service as they are. The actual request must account for length limits, role order, failed records, and duplicated content.

    When the history becomes too long, you can truncate it, summarize it, or let the user choose which context to include. In each case, the user should understand that the information may no longer be complete. A summary loses information, so it should not be treated as equivalent to the original record by default.

    5. Service Integration Needs a Trust Boundary

    5.1 Keep keys on the server side

    Real credentials must not appear in page code, browser storage, build output, or shared task records. The recommended data path is:

    1. Browser
    2. ↓ authenticated business request
    3. Application server
    4. ↓ reads credentials from controlled configuration
    5. Model service

    The browser sends a user’s business request. It does not hold the server-side key and call the upstream service directly.

    The server must also verify user identity, input size, session ownership, and call rate. Hiding the key alone does not prevent the endpoint from being abused.

    5.2 Verify the protocol before connecting the interface

    Before integration, confirm the request fields, content format, streaming response conventions, termination signals, and error structure. Do not assume that every service behaves the same way based on past experience.

    Start with a minimal call test that confirms:

    • A normal request completes successfully.
    • Streamed content is parsed correctly.
    • Authentication failures and permission failures can be told apart.
    • Timeouts, rate limits, and upstream errors map to messages a user can understand.
    • Logs do not record keys or unnecessary sensitive content.

    5.3 Handle streamed responses correctly

    A network chunk in a stream does not necessarily correspond to a complete character, a complete message, or a complete structured object. The client must keep a buffer according to the protocol and update the application state only when the data can be parsed.

    The client should also distinguish between a closed connection and a completed generation. If the connection drops unexpectedly, the client must not report success just because no more data arrives.

    Cancellation should also propagate through the call chain. Stopping rendering in the front end does not mean the server has stopped processing. Even when a cancellation signal is sent, the upstream service may not stop immediately, and some resources may still be consumed.

    6. Make Testing Cover Real Usage

    6.1 Test visuals across multiple states

    Checking only an empty home page is not enough. Cover at least an empty session, long text, multi-turn conversations, code content, expanded history lists, error messages, and the generating state.

    Mobile testing needs special attention. Check the visible area when the soft keyboard opens, the bottom safe area, orientation changes, and the input box growing as the user types. Fixed-height layouts often work on desktop but cover the send button on a phone.

    6.2 Test the full functional path

    A basic acceptance path can look like this:

    1. Create a session and send a message.
    2. Confirm that content appears progressively.
    3. Switch sessions while a response is generating.
    4. Return to the original session and check that the content belongs to it.
    5. Click Stop and check the resulting state.
    6. Refresh the page and verify the restore behavior.
    7. Simulate a network failure and retry.
    8. Delete the session and confirm that a late response does not restore it.

    This is much closer to real use than checking only that the send button can be clicked.

    6.3 Verify permission boundaries in an independent environment

    For sharing, login state, or access control, test with a logged-out window or a different identity. A developer who can access content in their own session may have permissions that others do not have. That does not prove the sharing flow is correct.

    If the application includes sharing, check the sharing scope, the effect of revoking access, and what unauthorized users can see. Entry points that handle user data need negative tests, not only positive ones.

    6.4 Base the delivery conclusion on evidence

    A test report should record the environment, the steps, the expected result, the actual result, and any remaining issues. Each item can be marked as passed, partially passed, failed, or not verified.

    A test that was not run must not be reported as passed. Without a sufficient sample, do not claim a stability or performance ranking. Generated code is only part of the delivery process. Verification evidence is the basis for any quality conclusion.

    7. Optimize Problems Instead of Adding Entry Points

    An optimized version should be organized around problem, solution, and verification method.

    For example, long answers can be hard to read. Paragraph navigation and easy copying may help, but you must verify that they do not add visual clutter. Session history can be hard to search. A search feature helps, but you must explain what it covers and how the index is updated. Users who often retype the same instructions could benefit from editable templates, but templates should not include sensitive information by default.

    Controls over the generation process usually add more value than decorative features. A clear generation status, reliable stop behavior, preserved content after a failure, and a retry scope that users can understand all reduce uncertainty.

    Accessibility should also be part of the design. The input area should have a clear label, key actions should work with the keyboard, focus states should be visible, and error messages should not rely on color alone. Assistive announcements for streamed content should not fire so often that they interrupt reading.

    8. Final Delivery Should Be Reproducible, Maintainable, and Accountable

    A complete delivery includes at least the product document, the structure diagram, the source code, startup instructions, configuration notes, test records, and known limitations. Configuration examples should use placeholders only and must not contain real credentials.

    Evaluate the engineering process by reliability, not by how fast the code is generated:

    • Were the requirements clarified before coding?
    • Were observed facts separated from inferences?
    • Was the real service integration actually verified?
    • Were errors and permission boundaries tested proactively?
    • Are incomplete items disclosed honestly?
    • Can a future developer understand and maintain the code?

    The hard part of reproducing a chat web page is not making the first screen look similar. The hard part is keeping its behavior consistent and trustworthy through refreshes, session switches, interruptions, retries, and cross-device use. When requirements, state, security, and acceptance testing are part of one engineering process, an AI-generated build can become software that can be maintained and extended over time.