Skip to content

Fix import paths and add error handling in agents documentation#10

Merged
JosunLP merged 6 commits intodevelopmentfrom
copilot/fix-import-path-inconsistencies
Jan 24, 2026
Merged

Fix import paths and add error handling in agents documentation#10
JosunLP merged 6 commits intodevelopmentfrom
copilot/fix-import-path-inconsistencies

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 24, 2026

Plan: Fix Import Paths and Error Handling in Documentation

  • Fix import path inconsistency on line 81 (change 'bquery/reactive' to '@bquery/bquery/reactive')
  • Fix import path inconsistency on line 112 (change 'bquery/component' to '@bquery/bquery/component')
  • Add error handling for JSON parsing and network response (lines 64-74)
  • Replace type assertion with proper type guard on line 56
  • Verify changes don't break any documentation build
  • Clean up build artifacts from repository
  • Address PR review feedback: include statusText in error message
  • Address PR review feedback: validate reply is a string before using it

All changes have been successfully applied and verified. Documentation builds without errors.

Original prompt
Please apply the following diffs and create a pull request.
Once the PR is ready, give it a title based on the messages of the fixes being applied.

[{"message":"Import path inconsistency: This uses 'bquery/reactive' while earlier examples use '@bquery/bquery/reactive'. The import path should be consistent throughout the documentation.","fixFiles":[{"filePath":"docs/guide/agents.md","diff":"diff --git a/docs/guide/agents.md b/docs/guide/agents.md\n--- a/docs/guide/agents.md\n+++ b/docs/guide/agents.md\n@@ -78,7 +78,7 @@\n ### Streaming responses (token updates)\n \n ```ts\n-import { signal, effect } from 'bquery/reactive';\n+import { signal, effect } from '@bquery/bquery/reactive';\n \n const reply = signal('');\n \n"}]},{"message":"Import path inconsistency: This uses 'bquery/component' while other examples use '@bquery/bquery/...' format. The import path should be consistent with the established pattern.","fixFiles":[{"filePath":"docs/guide/agents.md","diff":"diff --git a/docs/guide/agents.md b/docs/guide/agents.md\n--- a/docs/guide/agents.md\n+++ b/docs/guide/agents.md\n@@ -109,7 +109,7 @@\n ### 3) Components for reusable UI parts\n \n ```ts\n-import { component, html } from 'bquery/component';\n+import { component, html } from '@bquery/bquery/component';\n \n component('tool-pill', {\n   props: { name: { type: String, required: true } },\n"}]},{"message":"Missing error handling for the JSON parsing and network response. If the response is not valid JSON or the request fails, this will throw an unhandled error without providing helpful feedback to users.","fixFiles":[{"filePath":"docs/guide/agents.md","diff":"diff --git a/docs/guide/agents.md b/docs/guide/agents.md\n--- a/docs/guide/agents.md\n+++ b/docs/guide/agents.md\n@@ -62,16 +62,39 @@\n   });\n \n   // Backend call (agent logic server-side)\n-  const res = await fetch('/api/agent', {\n-    method: 'POST',\n-    headers: { 'Content-Type': 'application/json' },\n-    body: JSON.stringify({ prompt }),\n-  });\n+  try {\n+    const res = await fetch('/api/agent', {\n+      method: 'POST',\n+      headers: { 'Content-Type': 'application/json' },\n+      body: JSON.stringify({ prompt }),\n+    });\n \n-  const { reply } = await res.json();\n+    if (!res.ok) {\n+      // Try to read error details, but fall back to status text\n+      let errorMessage = `Request failed with status ${res.status}`;\n+      try {\n+        const errorBody = await res.text();\n+        if (errorBody) {\n+          errorMessage += `: ${errorBody}`;\n+        }\n+      } catch {\n+        // ignore secondary errors from reading the body\n+      }\n+      throw new Error(errorMessage);\n+    }\n \n-  // replace the last \"Agent: …\"\n-  messages.value = messages.value.slice(0, -1).concat(`Agent: ${reply}`);\n+    const data = await res.json();\n+    const reply = (data as { reply?: string }).reply ?? '';\n+\n+    // replace the last \"Agent: …\"\n+    messages.value = messages.value.slice(0, -1).concat(`Agent: ${reply}`);\n+  } catch (err) {\n+    console.error('Agent request failed:', err);\n+    // replace the last \"Agent: …\" with an error message\n+    messages.value = messages.value\n+      .slice(0, -1)\n+      .concat('Agent: (error getting response, please try again)');\n+  }\n });\n ```\n \n"}]},{"message":"[nitpick] The type assertion 'as string | undefined' suggests uncertainty about the return type. Consider using proper type guards or ensuring the input element exists and has the expected type instead of casting.","fixFiles":[{"filePath":"docs/guide/agents.md","diff":"diff --git a/docs/guide/agents.md b/docs/guide/agents.md\n--- a/docs/guide/agents.md\n+++ b/docs/guide/agents.md\n@@ -53,7 +53,8 @@\n });\n \n $('#send').on('click', async () => {\n-  const prompt = (input.val() as string | undefined)?.trim();\n+  const raw = input.val();\n+  const prompt = typeof raw === 'string' ? raw.trim() : undefined;\n   if (!prompt) return;\n \n   batch(() => {\n"}]}]

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

JosunLP and others added 2 commits January 24, 2026 01:02
Security and Playground Fixes:
* Replaced direct assignment of HTML via `innerHTML` with safer DOM manipulation in the `logEvent` function within `playground/src/demos/core.ts` to prevent possible HTML injection vulnerabilities.
* Updated collection handling in the same file to use the raw DOM element when re-appending items, improving code clarity and safety.

Workflow and Versioning:
* Added explicit `contents: read` permissions to both `build` and `build-docs` jobs in `.github/workflows/npm-publish.yml` to comply with GitHub Actions best practices. [[1]](diffhunk://#diff-8a5ce8b612395836520d0655143f732d08e747af57f3cfe76b5e283600106240R16-R17) [[2]](diffhunk://#diff-8a5ce8b612395836520d0655143f732d08e747af57f3cfe76b5e283600106240R29-R30)
* Bumped package version to `1.1.1` in `package.json` to reflect the new release.
* Added a changelog entry for version `1.1.1` noting the HTML handling fix in `CHANGELOG.md`.
Copilot AI and others added 3 commits January 24, 2026 00:07
Co-authored-by: JosunLP <20913954+JosunLP@users.noreply.github.com>
Co-authored-by: JosunLP <20913954+JosunLP@users.noreply.github.com>
Co-authored-by: JosunLP <20913954+JosunLP@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix import path inconsistencies in documentation Fix import paths and add error handling in agents documentation Jan 24, 2026
Copilot AI requested a review from JosunLP January 24, 2026 00:10
@JosunLP JosunLP marked this pull request as ready for review January 24, 2026 00:14
Copilot AI review requested due to automatic review settings January 24, 2026 00:14
@JosunLP JosunLP changed the base branch from main to development January 24, 2026 00:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Agents guide documentation to use consistent module import paths and improves robustness of the agent chat example by adding basic runtime error handling and safer input parsing.

Changes:

  • Normalized documentation imports to @bquery/bquery/{module} for reactive/component examples.
  • Added try/catch around the agent fetch call with HTTP status handling and a UI fallback message.
  • Replaced a prompt type assertion with a runtime type guard before trimming.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 2 comments.

File Description
docs/guide/agents.md Aligns import paths and hardens the agent chat example with safer input parsing and request/response error handling.
.gitignore Ignores package-lock.json to prevent committing an npm lockfile.
Comments suppressed due to low confidence (1)

docs/guide/agents.md:140

  • In this component example, props.name is interpolated into html templates, but html does not escape values (it’s just string concatenation). To avoid demonstrating an XSS-prone pattern, use safeHtml (or escape/sanitize props.name) when rendering potentially untrusted prop values into innerHTML-backed templates.
import { component, html } from '@bquery/bquery/component';

component('tool-pill', {
  props: { name: { type: String, required: true } },
  render({ props }) {

@JosunLP
Copy link
Copy Markdown
Collaborator

JosunLP commented Jan 24, 2026

@copilot apply changes based on the comments in this thread

Co-authored-by: JosunLP <20913954+JosunLP@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 24, 2026

@copilot apply changes based on the comments in this thread

Changes applied in bb10eec. Both review comments have been addressed.

@JosunLP JosunLP merged commit 22a4606 into development Jan 24, 2026
4 checks passed
@JosunLP JosunLP deleted the copilot/fix-import-path-inconsistencies branch January 24, 2026 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants