Skip to content

Commit a1ba3a6

Browse files
authored
Merge pull request #47 from necyberteam/hyperlinks-in-response
Support hyperlinks in bot responses, improve publishing workflow
2 parents 62931b8 + f940588 commit a1ba3a6

File tree

3 files changed

+91
-106
lines changed

3 files changed

+91
-106
lines changed

publishing.md

Lines changed: 50 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @snf/access-qa-bot Publishing Guide
22

3-
This document outlines the process for publishing the ACCESS Q&A Bot package to npm.
3+
This document outlines the simplified process for publishing the ACCESS Q&A Bot package to npm.
44

55
## Version Management
66

@@ -39,31 +39,28 @@ git tag -l "v0.3.0"
3939
npm login
4040
```
4141

42-
## Release Process
42+
## Standard Release Process
4343

44-
Our release process is designed to work with our existing CDN infrastructure and includes release candidate testing for integration with dependent repositories (like access-ci-ui). The process allows for testing integration BEFORE opening a PR to ensure end-to-end functionality.
44+
This is the main workflow for releasing new versions of the package.
4545

46-
### 1. Feature Development (Including Release Candidate Version)
47-
48-
During feature development:
46+
### 1. Feature Development
4947

5048
```bash
5149
# Create feature branch from main
5250
git checkout -b feature/my-feature main
5351

54-
# Make changes, commit them
52+
# Make your changes, commit them
5553
# ...
5654

5755
# Check existing versions before updating
5856
git tag -l "v*"
5957

60-
# Update version in package.json with rc suffix (manually edit)
61-
# Example: "1.1.0-rc.1"
58+
# Update version in package.json (manually edit)
59+
# Example: "1.1.0"
6260
# IMPORTANT: Choose a NEW version that doesn't have an existing git tag
6361
# This is necessary for our CDN links to work correctly
6462

6563
# Sync package-lock.json with new version
66-
# NOTE: This ensures package-lock.json matches package.json version
6764
npm install
6865

6966
# Build the library and app for both npm and CDN delivery
@@ -72,123 +69,85 @@ npm run build
7269

7370
# Commit the version change and builds
7471
git add .
75-
git commit -am "Bump version to X.Y.Z-rc.1"
72+
git commit -am "Bump version to X.Y.Z"
7673
```
7774

78-
### 2. Publish Release Candidate from Feature Branch (Before PR)
79-
80-
Publish the release candidate version for integration testing BEFORE opening the PR:
75+
### 2. Test the Package (Optional)
8176

8277
```bash
83-
# From your feature branch (not main yet)
84-
git checkout npm-release
85-
git merge feature/my-feature # Merge your feature branch to npm-release
86-
# Resolve any conflicts if needed
87-
88-
# Test the package
78+
# Test the package locally
8979
npm pack
9080
tar -tf @snf-access-qa-bot-*.tgz
9181

92-
# Publish release candidate to npm with rc tag
93-
npm publish --tag rc --access public
94-
95-
# Push changes to npm-release branch
96-
git push upstream npm-release
97-
98-
# Return to your feature branch
99-
git checkout feature/my-feature
100-
```
101-
102-
### 3. Integration Testing
103-
104-
Test the release candidate version with dependent repositories:
105-
106-
```bash
107-
# In access-ci-ui or other consuming repos
108-
npm install @snf/access-qa-bot@rc
109-
110-
# Test integration thoroughly
111-
# Document any issues or successful tests
82+
# Clean up the test file
83+
rm @snf-access-qa-bot-*.tgz
11284
```
11385

114-
### 4. Open Pull Request
115-
116-
Now that integration testing is complete, open the PR:
86+
### 3. Open Pull Request
11787

11888
- Create PR from `feature/my-feature` to `main`
119-
- Include integration test results in PR description
120-
- Note that RC version has been published and tested
121-
- Reviewers can be confident the changes work end-to-end
122-
123-
### 5. Merge to Main
89+
- Include description of changes
90+
- Get code review and approval
12491

125-
Once PR is approved and merged to main, the feature branch changes are now in main.
92+
### 4. Merge to Main
12693

127-
### 6. Promote to Stable Release
94+
Once PR is approved and merged to main, proceed with the release.
12895

129-
After successful PR merge, promote the release candidate to a stable release:
96+
### 5. Create Release
13097

13198
```bash
13299
# Switch to main and pull latest
133100
git checkout main
134101
git pull upstream main
135102

136-
# Update version in package.json to remove rc suffix
137-
# Example: "1.1.0-rc.1" becomes "1.1.0"
138-
139-
# Sync package-lock.json with new version
140-
# NOTE: This ensures package-lock.json matches package.json version
141-
npm install
142-
143-
# Build the library and app for both npm and CDN delivery
144-
npm run build:lib
145-
npm run build
146-
147-
# Commit the stable version and builds
148-
git add .
149-
git commit -am "Release version X.Y.Z"
150-
151-
# Create git tag and GitHub release
103+
# Create git tag and push it
152104
git tag -a vX.Y.Z -m "Release version X.Y.Z" # Match your actual version
153105
git push upstream vX.Y.Z
154106

155107
# Create GitHub release
156108
```
157-
- Click on the "Releases" tab in the GitHub repository
158-
- Click "Draft a new release"
159-
- Select the tag you just created
109+
110+
#### GitHub Release Steps:
111+
- Go to: https://github.com/necyberteam/qa-bot/releases/new
112+
- Select the tag you just created (vX.Y.Z)
160113
- Add a title and description
161114
- Click "Publish release"
162115

116+
### 6. Publish to npm
117+
163118
```bash
164-
# Update npm-release branch with stable version
119+
# Update npm-release branch with latest main
165120
git checkout npm-release
166121
git merge main
122+
# Resolve any conflicts if needed
167123

168-
# Publish stable version to npm
124+
# Publish to npm
169125
npm publish --access public
170126

171-
# Push final changes
127+
# Push npm-release branch
172128
git push upstream npm-release
173129
```
174130

175-
### 7. Cleanup (Optional)
131+
## Debug Release Workflow
176132

177-
If desired, you can remove the RC tag from npm after stable release:
133+
For quick debug releases during development (publishes to npm only, no git tags or GitHub releases):
178134

179135
```bash
180-
# Remove the rc tag (optional)
181-
npm dist-tag rm @snf/access-qa-bot rc
182-
```
136+
# From any local branch
137+
# Update version (e.g., 2.6.0-debug.0 to 2.6.0-debug.1)
138+
npm version 2.6.0-debug.1
183139

184-
### Alternative: Direct Release (Skip Release Candidate)
140+
# Build the library
141+
npm run build:lib
185142

186-
For smaller changes or when integration testing isn't needed:
143+
# Publish with debug tag
144+
npm publish --tag debug --access public
145+
```
187146

188-
1. Use stable version number (no rc suffix) from the start
189-
2. Build the library and app: `npm run build:lib && npm run build`
190-
3. Follow steps 1-2 above (including the build and commit steps)
191-
4. Skip to step 5 (Create tag, GitHub release, and publish to npm)
147+
This workflow is useful for:
148+
- Quick iterations during development
149+
- Testing specific versions in integration environments
150+
- Publishing debug versions without affecting the main release process
192151

193152
## Maintaining the Release Branch
194153

@@ -247,22 +206,12 @@ npm install @snf/access-qa-bot
247206

248207
For more detailed usage instructions and examples, refer to the README.md file.
249208

250-
## Simple Debug Releases Workflow
209+
## AI Assistant Notes
251210

252-
For quick debug releases during development:
211+
This workflow is designed to be clear and actionable for AI assistants. Key points:
253212

254-
```bash
255-
# Update version (e.g., 2.6.0-debug.0 to 2.6.0-debug.1)
256-
npm version 2.6.0-debug.1
257-
258-
# Build the library
259-
npm run build:lib
260-
261-
# Publish with debug tag
262-
npm publish --tag debug --access public
263-
```
264-
265-
This workflow is useful for:
266-
- Quick iterations during development
267-
- Testing specific versions in integration environments
268-
- Publishing debug versions without affecting the main release process
213+
- Always check existing git tags before choosing a version number
214+
- Build commands are: `npm run build:lib && npm run build`
215+
- The process maintains both npm packages and CDN links
216+
- Debug releases use the `--tag debug` flag and don't create git tags
217+
- Clean up temporary files (like .tgz from npm pack) after testing

src/utils/flows/qa-flow.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { handleBotError } from '../error-handler';
22
import { getApiEndpoint, getRatingEndpoint } from '../../config/constants';
33
import { v4 as uuidv4 } from 'uuid';
4+
import { getProcessedText } from '../getProcessedText';
45

56
/**
67
* Creates the Q&A conversation flow
@@ -25,7 +26,7 @@ export const createQAFlow = ({ sessionId, apiKey }) => {
2526

2627
// Handle feedback first if it's feedback
2728
if (userInput === "👍 Helpful" || userInput === "👎 Not helpful") {
28-
29+
2930
// Send feedback using the captured query ID
3031
if (apiKey && sessionId && feedbackQueryId) {
3132
const isPositive = userInput === "👍 Helpful";
@@ -56,7 +57,7 @@ export const createQAFlow = ({ sessionId, apiKey }) => {
5657
// Generate our own query ID since we're bypassing useHandleAIQuery
5758
const queryId = uuidv4();
5859
feedbackQueryId = queryId;
59-
60+
6061
const headers = {
6162
'Content-Type': 'application/json',
6263
'X-Origin': 'access',
@@ -72,12 +73,14 @@ export const createQAFlow = ({ sessionId, apiKey }) => {
7273
query: userInput
7374
})
7475
});
75-
76+
7677
const body = await response.json();
7778
const text = body.response;
78-
79+
const processedText = getProcessedText(text);
80+
81+
7982
// Inject the response
80-
await chatState.injectMessage(text);
83+
await chatState.injectMessage(processedText);
8184
return null;
8285
} catch (error) {
8386
console.error('Error in bot flow:', error);

src/utils/getProcessedText.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Processes text to convert bare URLs into markdown hyperlinks while preserving existing links
3+
* @param {string} text - The raw text from the API response
4+
* @returns {string} - Processed text with bare URLs converted to markdown links
5+
*/
6+
export const getProcessedText = (text) => {
7+
if (!text || typeof text !== 'string') {
8+
return text;
9+
}
10+
11+
// Regex to match URLs that are NOT already in markdown or HTML link format
12+
// This looks for URLs that are not preceded by ]( or href=" or [ and not followed by ) or ]
13+
const urlRegex = /(?<!\]\(|href=["']|\[)https?:\/\/[^\s[\]()]+(?![)\]])/gi;
14+
15+
// Replace bare URLs with markdown links
16+
const processedText = text.replace(urlRegex, (url) => {
17+
// Clean up common punctuation that shouldn't be part of the URL
18+
let cleanUrl = url;
19+
let trailingPunctuation = '';
20+
21+
// Check for trailing punctuation and remove it from the URL
22+
const trailingPunctuationMatch = cleanUrl.match(/([.,;:!?]+)$/);
23+
if (trailingPunctuationMatch) {
24+
trailingPunctuation = trailingPunctuationMatch[1];
25+
cleanUrl = cleanUrl.slice(0, -trailingPunctuation.length);
26+
}
27+
28+
// Create markdown link with the URL as both the link text and href
29+
return `[${cleanUrl}](${cleanUrl})${trailingPunctuation}`;
30+
});
31+
32+
return processedText;
33+
};

0 commit comments

Comments
 (0)