newo 1.4.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +17 -6
- package/CHANGELOG.md +102 -0
- package/README.md +96 -1
- package/dist/akb.d.ts +10 -0
- package/dist/akb.js +88 -0
- package/dist/api.d.ts +14 -0
- package/dist/api.js +103 -0
- package/dist/auth.d.ts +6 -0
- package/dist/auth.js +361 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +307 -0
- package/dist/customer.d.ts +23 -0
- package/dist/customer.js +87 -0
- package/dist/customerAsync.d.ts +22 -0
- package/dist/customerAsync.js +67 -0
- package/dist/customerInit.d.ts +10 -0
- package/dist/customerInit.js +78 -0
- package/dist/env.d.ts +33 -0
- package/dist/env.js +82 -0
- package/dist/fsutil.d.ts +20 -0
- package/dist/fsutil.js +51 -0
- package/dist/hash.d.ts +5 -0
- package/dist/hash.js +40 -0
- package/dist/sync.d.ts +7 -0
- package/dist/sync.js +376 -0
- package/dist/types.d.ts +229 -0
- package/dist/types.js +5 -0
- package/package.json +35 -14
- package/src/{akb.js → akb.ts} +35 -39
- package/src/api.ts +130 -0
- package/src/auth.ts +415 -0
- package/src/cli.ts +316 -0
- package/src/customer.ts +102 -0
- package/src/customerAsync.ts +78 -0
- package/src/customerInit.ts +97 -0
- package/src/env.ts +118 -0
- package/src/fsutil.ts +73 -0
- package/src/hash.ts +41 -0
- package/src/{sync.js → sync.ts} +179 -81
- package/src/types.ts +276 -0
- package/src/api.js +0 -103
- package/src/auth.js +0 -92
- package/src/cli.js +0 -108
- package/src/fsutil.js +0 -34
- package/src/hash.js +0 -17
package/.env.example
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
# NEWO endpoints
|
|
2
2
|
NEWO_BASE_URL=https://app.newo.ai
|
|
3
3
|
|
|
4
|
-
#
|
|
5
|
-
#
|
|
4
|
+
# Multi-customer configuration - Array format
|
|
5
|
+
# Define API keys as JSON array - customer IDN will be auto-detected from API response
|
|
6
|
+
NEWO_API_KEYS=["api_key_1", "api_key_2", "api_key_3"]
|
|
7
|
+
|
|
8
|
+
# Or with optional project IDs per API key
|
|
9
|
+
# NEWO_API_KEYS=[{"key":"api_key_1","project_id":"project_uuid_1"}, {"key":"api_key_2","project_id":"project_uuid_2"}]
|
|
10
|
+
|
|
11
|
+
# Optional: specify default customer IDN after keys are loaded
|
|
12
|
+
# NEWO_DEFAULT_CUSTOMER=NEWO_ESd2BC95
|
|
6
13
|
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
|
|
14
|
+
# Legacy format (still supported)
|
|
15
|
+
# NEWO_CUSTOMER_[IDN]_API_KEY=api_key
|
|
16
|
+
# NEWO_CUSTOMER_acme_API_KEY=put_acme_api_key_here
|
|
17
|
+
|
|
18
|
+
# Legacy single-customer mode (still supported)
|
|
19
|
+
# NEWO_API_KEY=put_api_key_here
|
|
20
|
+
# NEWO_PROJECT_ID=b78188ba-0df0-46a8-8713-f0d7cff0a06e
|
|
10
21
|
|
|
11
|
-
#
|
|
22
|
+
# Optional bootstrap tokens (for legacy mode or manual setup)
|
|
12
23
|
NEWO_ACCESS_TOKEN=
|
|
13
24
|
NEWO_REFRESH_TOKEN=
|
|
14
25
|
|
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,108 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.5.1] - 2025-01-14
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **Comprehensive Test Coverage**: Added extensive test suites for all major modules
|
|
12
|
+
- `test/auth.test.js`: 500+ lines covering authentication, token management, multi-customer support
|
|
13
|
+
- `test/hash.test.js`: 400+ lines covering SHA256 hashing, hash storage, and cross-platform compatibility
|
|
14
|
+
- `test/fsutil.test.js`: 400+ lines covering file system utilities and path handling
|
|
15
|
+
- `test/akb.test.js`: 600+ lines covering AKB article parsing and import workflows
|
|
16
|
+
- Added missing test dependencies: `chai`, `sinon`, `c8` for coverage reporting
|
|
17
|
+
- **Enhanced Authentication Validation**:
|
|
18
|
+
- `validateApiKey()`: Comprehensive API key format and length validation
|
|
19
|
+
- `validateTokens()`: Token format and structure validation with detailed error messages
|
|
20
|
+
- `validateUrl()`: URL format validation for API endpoints
|
|
21
|
+
- Sensitive data sanitization in logs (API keys and tokens masked)
|
|
22
|
+
- **Structured Logging System**:
|
|
23
|
+
- `logAuthEvent()`: Structured authentication event logging with metadata
|
|
24
|
+
- Automatic sensitive data sanitization (keys/tokens/secrets masked in logs)
|
|
25
|
+
- JSON-formatted logs with timestamp, level, module, and context information
|
|
26
|
+
- **Enhanced Error Handling**:
|
|
27
|
+
- User-friendly CLI error messages with troubleshooting tips
|
|
28
|
+
- Specific error handling for authentication, network, environment, and file system errors
|
|
29
|
+
- Verbose mode support for detailed debugging information
|
|
30
|
+
- Context-aware error messages with suggested solutions
|
|
31
|
+
|
|
32
|
+
### Enhanced
|
|
33
|
+
- **Authentication Robustness** (`src/auth.ts`):
|
|
34
|
+
- Added comprehensive input validation with detailed error messages
|
|
35
|
+
- Enhanced network error handling with specific status code interpretation
|
|
36
|
+
- Added request timeouts (30 seconds) and retry logic for reliability
|
|
37
|
+
- Improved token expiry handling with 60-second buffer for refresh
|
|
38
|
+
- Better handling of connection errors, timeouts, and server errors
|
|
39
|
+
- **CLI Error Experience** (`src/cli.ts`):
|
|
40
|
+
- Added `handleCliError()` function with categorized error types
|
|
41
|
+
- User-friendly error messages with emoji indicators and troubleshooting tips
|
|
42
|
+
- Verbose mode toggle for detailed technical information vs. clean user messages
|
|
43
|
+
- Specific guidance for common issues (API key, network, configuration)
|
|
44
|
+
- **Testing Infrastructure**:
|
|
45
|
+
- Fixed ES module/CommonJS compatibility issues in test files
|
|
46
|
+
- Enhanced `TestEnvironment` class with comprehensive cleanup and mocking
|
|
47
|
+
- Added MockHttpClient, MockFileSystem, and MockLogger utilities
|
|
48
|
+
- Comprehensive assertion helpers and test data generators
|
|
49
|
+
|
|
50
|
+
### Fixed
|
|
51
|
+
- **Module System Compatibility**: Resolved ES module/CommonJS conflicts in test environment
|
|
52
|
+
- **Test Dependencies**: Added missing testing dependencies that were imported but not declared
|
|
53
|
+
- **Integration Test Paths**: Fixed paths from `src/cli.js` to `dist/cli.js` for proper compiled code testing
|
|
54
|
+
- **Error Message Consistency**: Standardized error messages across authentication and CLI modules
|
|
55
|
+
|
|
56
|
+
### Technical Details
|
|
57
|
+
- **Validation Constants**: Added security-focused validation thresholds (API_KEY_MIN_LENGTH, TOKEN_MIN_LENGTH)
|
|
58
|
+
- **Request Configuration**: Added proper timeout handling (30s) and user-agent headers
|
|
59
|
+
- **Error Recovery**: Comprehensive fallback strategies for different failure scenarios
|
|
60
|
+
- **Logging Standards**: JSON-structured logs with automatic PII/sensitive data protection
|
|
61
|
+
- **Test Coverage**: Achieved comprehensive test coverage across all core modules with realistic scenarios
|
|
62
|
+
|
|
63
|
+
### Developer Experience
|
|
64
|
+
- **Enhanced Debugging**: Verbose mode provides detailed technical information for troubleshooting
|
|
65
|
+
- **Better Error Messages**: Clear, actionable error messages instead of generic API errors
|
|
66
|
+
- **Comprehensive Testing**: Full test suite covering authentication, file operations, hashing, and AKB import
|
|
67
|
+
- **Type Safety**: All improvements maintain strict TypeScript compliance with proper error types
|
|
68
|
+
|
|
69
|
+
## [1.5.0] - 2025-09-03
|
|
70
|
+
|
|
71
|
+
### Changed
|
|
72
|
+
- **Complete TypeScript Refactoring**: Major codebase conversion from JavaScript to TypeScript
|
|
73
|
+
- All source files converted to TypeScript with `.ts` extensions
|
|
74
|
+
- Added comprehensive type definitions in `src/types.ts`
|
|
75
|
+
- Strict TypeScript configuration with `exactOptionalPropertyTypes` and `noUncheckedIndexedAccess`
|
|
76
|
+
- Modern ES2022 target with ESNext modules for optimal performance
|
|
77
|
+
- Enhanced IntelliSense support and developer experience
|
|
78
|
+
|
|
79
|
+
### Added
|
|
80
|
+
- **TypeScript Build System**:
|
|
81
|
+
- `tsconfig.json` with strict type checking and modern ES features
|
|
82
|
+
- New build scripts: `npm run build`, `npm run build:watch`, `npm run typecheck`
|
|
83
|
+
- Development scripts: `npm run dev`, `npm run pull`, `npm run push`, `npm run status`
|
|
84
|
+
- Source map generation for debugging compiled JavaScript
|
|
85
|
+
- **Enhanced Type Safety**:
|
|
86
|
+
- Complete type definitions for all NEWO API responses and data structures
|
|
87
|
+
- Strict error handling with proper TypeScript error types
|
|
88
|
+
- Optional property handling with explicit `| undefined` types
|
|
89
|
+
- Enhanced Axios integration with proper TypeScript interceptor types
|
|
90
|
+
|
|
91
|
+
### Technical Details
|
|
92
|
+
- **Type Definitions**: Comprehensive interfaces for `ProjectMeta`, `Agent`, `Flow`, `Skill`, `FlowEvent`, `FlowState`, and all API responses
|
|
93
|
+
- **Build Output**: TypeScript compiles to `dist/` directory with JavaScript and declaration files
|
|
94
|
+
- **Import Strategy**: Uses runtime `.js` extensions in TypeScript source (required for ESModules)
|
|
95
|
+
- **Dependency Updates**: Added TypeScript and @types packages for full type support
|
|
96
|
+
- **Package.json**: Updated with TypeScript build pipeline and development scripts
|
|
97
|
+
|
|
98
|
+
### Migration for Developers
|
|
99
|
+
- **New Development Workflow**: `npm run build` required before running CLI commands
|
|
100
|
+
- **Source Files**: All development now in `src/*.ts` files instead of `src/*.js`
|
|
101
|
+
- **Build Artifacts**: Generated JavaScript in `dist/` directory (automatically created)
|
|
102
|
+
- **IDE Support**: Enhanced autocomplete, error detection, and refactoring capabilities
|
|
103
|
+
|
|
104
|
+
### Backward Compatibility
|
|
105
|
+
- **Runtime Behavior**: No changes to CLI command interface or functionality
|
|
106
|
+
- **Environment Variables**: All existing `.env` configurations continue to work
|
|
107
|
+
- **File Formats**: Same `.guidance` and `.jinja` file support as before
|
|
108
|
+
- **API Compatibility**: No changes to NEWO API integration or endpoints
|
|
109
|
+
|
|
8
110
|
## [1.4.0] - 2025-08-20
|
|
9
111
|
|
|
10
112
|
### Added
|
package/README.md
CHANGED
|
@@ -33,6 +33,7 @@ npx newo status
|
|
|
33
33
|
git clone https://github.com/sabbah13/newo-cli.git
|
|
34
34
|
cd newo-cli
|
|
35
35
|
npm install
|
|
36
|
+
npm run build # Build TypeScript to JavaScript
|
|
36
37
|
```
|
|
37
38
|
|
|
38
39
|
## Configure
|
|
@@ -92,8 +93,40 @@ Hashes are tracked in `.newo/hashes.json` so only changed files are pushed.
|
|
|
92
93
|
- **AKB import**: Import knowledge base articles from structured text files
|
|
93
94
|
- **Project structure export**: Generates `flows.yaml` with complete project metadata
|
|
94
95
|
- **Robust authentication**: API key exchange with automatic token refresh
|
|
96
|
+
- **Enhanced error handling**: User-friendly error messages with troubleshooting guidance
|
|
97
|
+
- **Comprehensive testing**: Full test suite covering all major functionality
|
|
95
98
|
- **CI/CD ready**: GitHub Actions workflow included
|
|
96
99
|
|
|
100
|
+
## Robustness & Error Handling
|
|
101
|
+
|
|
102
|
+
NEWO CLI v1.5.1+ includes comprehensive error handling and validation:
|
|
103
|
+
|
|
104
|
+
### User-Friendly Error Messages
|
|
105
|
+
- **Authentication Errors**: Clear guidance when API keys are invalid or missing
|
|
106
|
+
- **Network Issues**: Helpful tips for connection problems and timeouts
|
|
107
|
+
- **Configuration Errors**: Step-by-step setup instructions for common issues
|
|
108
|
+
- **File System Errors**: Actionable guidance for permission and path problems
|
|
109
|
+
|
|
110
|
+
### Verbose Debugging
|
|
111
|
+
Use the `--verbose` or `-v` flag with any command for detailed technical information:
|
|
112
|
+
```bash
|
|
113
|
+
npx newo pull --verbose # Detailed pull operation logs
|
|
114
|
+
npx newo push -v # Verbose push with full error context
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Enhanced Validation
|
|
118
|
+
- **API Key Validation**: Format and length validation with specific error messages
|
|
119
|
+
- **Token Security**: Automatic sanitization of sensitive data in logs
|
|
120
|
+
- **Network Timeouts**: 30-second request timeouts with proper error handling
|
|
121
|
+
- **Input Validation**: Comprehensive validation for all user inputs and configuration
|
|
122
|
+
|
|
123
|
+
### Troubleshooting Tips
|
|
124
|
+
When errors occur, NEWO CLI provides:
|
|
125
|
+
- 🔍 **Problem diagnosis** with specific error categories
|
|
126
|
+
- 💡 **Solution suggestions** for common configuration issues
|
|
127
|
+
- 📋 **Step-by-step guidance** for resolving authentication and network problems
|
|
128
|
+
- 🔧 **Configuration validation** to ensure proper setup
|
|
129
|
+
|
|
97
130
|
## CI/CD (GitHub Actions)
|
|
98
131
|
Create `.github/workflows/deploy.yml`:
|
|
99
132
|
```yaml
|
|
@@ -113,7 +146,7 @@ jobs:
|
|
|
113
146
|
with:
|
|
114
147
|
node-version: 20
|
|
115
148
|
- run: npm ci
|
|
116
|
-
- run: node ./
|
|
149
|
+
- run: npm run build && node ./dist/cli.js push
|
|
117
150
|
env:
|
|
118
151
|
NEWO_BASE_URL: https://app.newo.ai
|
|
119
152
|
NEWO_PROJECT_ID: ${{ secrets.NEWO_PROJECT_ID }}
|
|
@@ -155,6 +188,68 @@ Each article will be imported with:
|
|
|
155
188
|
|
|
156
189
|
Use `--verbose` flag to see detailed import progress.
|
|
157
190
|
|
|
191
|
+
## Development
|
|
192
|
+
|
|
193
|
+
This project is built with TypeScript for enhanced type safety and developer experience.
|
|
194
|
+
|
|
195
|
+
### Development Commands
|
|
196
|
+
```bash
|
|
197
|
+
# Build TypeScript to JavaScript
|
|
198
|
+
npm run build
|
|
199
|
+
|
|
200
|
+
# Build and watch for changes
|
|
201
|
+
npm run build:watch
|
|
202
|
+
|
|
203
|
+
# Run CLI commands (after building)
|
|
204
|
+
npm run dev pull # Build and run pull command
|
|
205
|
+
npm run pull # Build and run pull command
|
|
206
|
+
npm run push # Build and run push command
|
|
207
|
+
npm run status # Build and run status command
|
|
208
|
+
|
|
209
|
+
# Type checking without emitting files
|
|
210
|
+
npm run typecheck
|
|
211
|
+
|
|
212
|
+
# Run tests
|
|
213
|
+
npm test
|
|
214
|
+
|
|
215
|
+
# Run tests with coverage reporting
|
|
216
|
+
npm run test:coverage
|
|
217
|
+
|
|
218
|
+
# Run specific test suites
|
|
219
|
+
npm run test:unit # Core module tests (api, sync, auth, hash, fsutil, akb)
|
|
220
|
+
npm run test:integration # End-to-end integration tests
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Test Coverage
|
|
224
|
+
NEWO CLI includes comprehensive test suites:
|
|
225
|
+
- **Authentication Tests** (`test/auth.test.js`): Token management, API key validation, multi-customer support
|
|
226
|
+
- **Hashing Tests** (`test/hash.test.js`): SHA256 operations, hash storage, change detection
|
|
227
|
+
- **File System Tests** (`test/fsutil.test.js`): Path utilities, directory management, atomic operations
|
|
228
|
+
- **AKB Import Tests** (`test/akb.test.js`): Article parsing, Unicode handling, import workflows
|
|
229
|
+
- **API Tests** (`test/api.test.js`): HTTP client functionality, NEWO API integration
|
|
230
|
+
- **Sync Tests** (`test/sync.test.js`): Pull/push operations, project synchronization
|
|
231
|
+
- **Integration Tests** (`test/integration.test.js`): End-to-end CLI functionality
|
|
232
|
+
|
|
233
|
+
Test infrastructure includes:
|
|
234
|
+
- **MockHttpClient**: HTTP request/response simulation
|
|
235
|
+
- **MockFileSystem**: File system operation mocking
|
|
236
|
+
- **TestEnvironment**: Isolated test environments with automatic cleanup
|
|
237
|
+
- **Coverage Reporting**: HTML and text coverage reports via c8
|
|
238
|
+
|
|
239
|
+
### Project Structure
|
|
240
|
+
- `src/` - TypeScript source files
|
|
241
|
+
- `dist/` - Compiled JavaScript output (generated by `npm run build`)
|
|
242
|
+
- `test/` - Test files
|
|
243
|
+
- `projects/` - Downloaded NEWO projects (generated by pull command)
|
|
244
|
+
- `.newo/` - CLI state directory (tokens, hashes, mappings)
|
|
245
|
+
|
|
246
|
+
### TypeScript Features
|
|
247
|
+
- Full type safety with strict TypeScript configuration
|
|
248
|
+
- Modern ES2022 target with ESNext modules
|
|
249
|
+
- Comprehensive type definitions for all NEWO API responses
|
|
250
|
+
- Enhanced error handling and validation
|
|
251
|
+
- IntelliSense support in compatible IDEs
|
|
252
|
+
|
|
158
253
|
## API Endpoints
|
|
159
254
|
- `GET /api/v1/designer/projects` - List all accessible projects
|
|
160
255
|
- `GET /api/v1/designer/projects/by-id/{projectId}` - Get specific project metadata
|
package/dist/akb.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ParsedArticle, AkbImportArticle } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parse AKB file and extract articles
|
|
4
|
+
*/
|
|
5
|
+
export declare function parseAkbFile(filePath: string): Promise<ParsedArticle[]>;
|
|
6
|
+
/**
|
|
7
|
+
* Convert parsed articles to API format for bulk import
|
|
8
|
+
*/
|
|
9
|
+
export declare function prepareArticlesForImport(articles: ParsedArticle[], personaId: string): AkbImportArticle[];
|
|
10
|
+
//# sourceMappingURL=akb.d.ts.map
|
package/dist/akb.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
/**
|
|
3
|
+
* Parse AKB file and extract articles
|
|
4
|
+
*/
|
|
5
|
+
export async function parseAkbFile(filePath) {
|
|
6
|
+
const content = await fs.readFile(filePath, 'utf8');
|
|
7
|
+
const articles = [];
|
|
8
|
+
// Split by article separators (---)
|
|
9
|
+
const sections = content.split(/^---\s*$/gm).filter(section => section.trim());
|
|
10
|
+
for (const section of sections) {
|
|
11
|
+
const lines = section.split('\n').filter(line => line.trim());
|
|
12
|
+
if (lines.length === 0)
|
|
13
|
+
continue;
|
|
14
|
+
const article = parseArticleSection(lines);
|
|
15
|
+
if (article) {
|
|
16
|
+
articles.push(article);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return articles;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Parse individual article section
|
|
23
|
+
*/
|
|
24
|
+
function parseArticleSection(lines) {
|
|
25
|
+
const state = {
|
|
26
|
+
topicName: '',
|
|
27
|
+
category: '',
|
|
28
|
+
summary: '',
|
|
29
|
+
keywords: '',
|
|
30
|
+
topicSummary: ''
|
|
31
|
+
};
|
|
32
|
+
// Find topic name (# r001)
|
|
33
|
+
const topicLine = lines.find(line => line.match(/^#\s+r\d+/));
|
|
34
|
+
if (!topicLine) {
|
|
35
|
+
console.warn('No topic line found in section');
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
state.topicName = topicLine.replace(/^#\s+/, '').trim();
|
|
39
|
+
// Extract category/subcategory/description (first ## line)
|
|
40
|
+
const categoryLine = lines.find(line => line.startsWith('## ') && line.includes(' / '));
|
|
41
|
+
if (categoryLine) {
|
|
42
|
+
state.category = categoryLine.replace(/^##\s+/, '').trim();
|
|
43
|
+
}
|
|
44
|
+
// Extract summary (second ## line)
|
|
45
|
+
const summaryLineIndex = lines.findIndex(line => line.startsWith('## ') && line.includes(' / '));
|
|
46
|
+
if (summaryLineIndex >= 0 && summaryLineIndex + 1 < lines.length) {
|
|
47
|
+
const nextLine = lines[summaryLineIndex + 1];
|
|
48
|
+
if (nextLine && nextLine.startsWith('## ') && !nextLine.includes(' / ')) {
|
|
49
|
+
state.summary = nextLine.replace(/^##\s+/, '').trim();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// Extract keywords (third ## line)
|
|
53
|
+
const keywordsLineIndex = lines.findIndex((line, index) => index > summaryLineIndex + 1 && line.startsWith('## ') && !line.includes(' / '));
|
|
54
|
+
if (keywordsLineIndex >= 0) {
|
|
55
|
+
const keywordsLine = lines[keywordsLineIndex];
|
|
56
|
+
if (keywordsLine) {
|
|
57
|
+
state.keywords = keywordsLine.replace(/^##\s+/, '').trim();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Extract category content
|
|
61
|
+
const categoryStartIndex = lines.findIndex(line => line.includes('<Category type='));
|
|
62
|
+
const categoryEndIndex = lines.findIndex(line => line.includes('</Category>'));
|
|
63
|
+
if (categoryStartIndex >= 0 && categoryEndIndex >= 0) {
|
|
64
|
+
const categoryLines = lines.slice(categoryStartIndex, categoryEndIndex + 1);
|
|
65
|
+
state.topicSummary = categoryLines.join('\n');
|
|
66
|
+
}
|
|
67
|
+
// Create topic_facts array
|
|
68
|
+
const topicFacts = [state.category, state.summary, state.keywords].filter(fact => fact.trim() !== '');
|
|
69
|
+
return {
|
|
70
|
+
topic_name: state.category, // Use the descriptive title as topic_name
|
|
71
|
+
persona_id: null, // Will be set when importing
|
|
72
|
+
topic_summary: state.topicSummary,
|
|
73
|
+
topic_facts: topicFacts,
|
|
74
|
+
confidence: 100,
|
|
75
|
+
source: state.topicName, // Use the ID (r001) as source
|
|
76
|
+
labels: ['rag_context']
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Convert parsed articles to API format for bulk import
|
|
81
|
+
*/
|
|
82
|
+
export function prepareArticlesForImport(articles, personaId) {
|
|
83
|
+
return articles.map(article => ({
|
|
84
|
+
...article,
|
|
85
|
+
persona_id: personaId
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=akb.js.map
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type AxiosInstance } from 'axios';
|
|
2
|
+
import type { ProjectMeta, Agent, Skill, FlowEvent, FlowState, AkbImportArticle, CustomerProfile } from './types.js';
|
|
3
|
+
export declare function makeClient(verbose?: boolean, token?: string): Promise<AxiosInstance>;
|
|
4
|
+
export declare function listProjects(client: AxiosInstance): Promise<ProjectMeta[]>;
|
|
5
|
+
export declare function listAgents(client: AxiosInstance, projectId: string): Promise<Agent[]>;
|
|
6
|
+
export declare function getProjectMeta(client: AxiosInstance, projectId: string): Promise<ProjectMeta>;
|
|
7
|
+
export declare function listFlowSkills(client: AxiosInstance, flowId: string): Promise<Skill[]>;
|
|
8
|
+
export declare function getSkill(client: AxiosInstance, skillId: string): Promise<Skill>;
|
|
9
|
+
export declare function updateSkill(client: AxiosInstance, skillObject: Skill): Promise<void>;
|
|
10
|
+
export declare function listFlowEvents(client: AxiosInstance, flowId: string): Promise<FlowEvent[]>;
|
|
11
|
+
export declare function listFlowStates(client: AxiosInstance, flowId: string): Promise<FlowState[]>;
|
|
12
|
+
export declare function importAkbArticle(client: AxiosInstance, articleData: AkbImportArticle): Promise<unknown>;
|
|
13
|
+
export declare function getCustomerProfile(client: AxiosInstance): Promise<CustomerProfile>;
|
|
14
|
+
//# sourceMappingURL=api.d.ts.map
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import axios, {} from 'axios';
|
|
2
|
+
import { getValidAccessToken, forceReauth } from './auth.js';
|
|
3
|
+
import { ENV } from './env.js';
|
|
4
|
+
// Per-request retry tracking to avoid shared state issues
|
|
5
|
+
const RETRY_SYMBOL = Symbol('retried');
|
|
6
|
+
export async function makeClient(verbose = false, token) {
|
|
7
|
+
let accessToken = token || await getValidAccessToken();
|
|
8
|
+
if (verbose)
|
|
9
|
+
console.log('✓ Access token obtained');
|
|
10
|
+
const client = axios.create({
|
|
11
|
+
baseURL: ENV.NEWO_BASE_URL,
|
|
12
|
+
headers: { accept: 'application/json' }
|
|
13
|
+
});
|
|
14
|
+
client.interceptors.request.use(async (config) => {
|
|
15
|
+
config.headers = config.headers || {};
|
|
16
|
+
config.headers.Authorization = `Bearer ${accessToken}`;
|
|
17
|
+
if (verbose) {
|
|
18
|
+
console.log(`→ ${config.method?.toUpperCase()} ${config.url}`);
|
|
19
|
+
if (config.data)
|
|
20
|
+
console.log(' Data:', JSON.stringify(config.data, null, 2));
|
|
21
|
+
if (config.params)
|
|
22
|
+
console.log(' Params:', config.params);
|
|
23
|
+
}
|
|
24
|
+
return config;
|
|
25
|
+
});
|
|
26
|
+
client.interceptors.response.use((response) => {
|
|
27
|
+
if (verbose) {
|
|
28
|
+
console.log(`← ${response.status} ${response.config.method?.toUpperCase()} ${response.config.url}`);
|
|
29
|
+
if (response.data && Object.keys(response.data).length < 20) {
|
|
30
|
+
console.log(' Response:', JSON.stringify(response.data, null, 2));
|
|
31
|
+
}
|
|
32
|
+
else if (response.data) {
|
|
33
|
+
const itemCount = Array.isArray(response.data) ? response.data.length : Object.keys(response.data).length;
|
|
34
|
+
console.log(` Response: [${typeof response.data}] ${Array.isArray(response.data) ? itemCount + ' items' : 'large object'}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return response;
|
|
38
|
+
}, async (error) => {
|
|
39
|
+
const status = error?.response?.status;
|
|
40
|
+
if (verbose) {
|
|
41
|
+
console.log(`← ${status} ${error.config?.method?.toUpperCase()} ${error.config?.url} - ${error.message}`);
|
|
42
|
+
if (error.response?.data)
|
|
43
|
+
console.log(' Error data:', error.response.data);
|
|
44
|
+
}
|
|
45
|
+
// Use per-request retry tracking to avoid shared state issues
|
|
46
|
+
const config = error.config;
|
|
47
|
+
if (status === 401 && !config?.[RETRY_SYMBOL]) {
|
|
48
|
+
if (config) {
|
|
49
|
+
config[RETRY_SYMBOL] = true;
|
|
50
|
+
if (verbose)
|
|
51
|
+
console.log('🔄 Retrying with fresh token...');
|
|
52
|
+
accessToken = await forceReauth();
|
|
53
|
+
config.headers = config.headers || {};
|
|
54
|
+
config.headers.Authorization = `Bearer ${accessToken}`;
|
|
55
|
+
return client.request(config);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
throw error;
|
|
59
|
+
});
|
|
60
|
+
return client;
|
|
61
|
+
}
|
|
62
|
+
export async function listProjects(client) {
|
|
63
|
+
const response = await client.get('/api/v1/designer/projects');
|
|
64
|
+
return response.data;
|
|
65
|
+
}
|
|
66
|
+
export async function listAgents(client, projectId) {
|
|
67
|
+
const response = await client.get('/api/v1/bff/agents/list', {
|
|
68
|
+
params: { project_id: projectId }
|
|
69
|
+
});
|
|
70
|
+
return response.data;
|
|
71
|
+
}
|
|
72
|
+
export async function getProjectMeta(client, projectId) {
|
|
73
|
+
const response = await client.get(`/api/v1/designer/projects/by-id/${projectId}`);
|
|
74
|
+
return response.data;
|
|
75
|
+
}
|
|
76
|
+
export async function listFlowSkills(client, flowId) {
|
|
77
|
+
const response = await client.get(`/api/v1/designer/flows/${flowId}/skills`);
|
|
78
|
+
return response.data;
|
|
79
|
+
}
|
|
80
|
+
export async function getSkill(client, skillId) {
|
|
81
|
+
const response = await client.get(`/api/v1/designer/skills/${skillId}`);
|
|
82
|
+
return response.data;
|
|
83
|
+
}
|
|
84
|
+
export async function updateSkill(client, skillObject) {
|
|
85
|
+
await client.put(`/api/v1/designer/flows/skills/${skillObject.id}`, skillObject);
|
|
86
|
+
}
|
|
87
|
+
export async function listFlowEvents(client, flowId) {
|
|
88
|
+
const response = await client.get(`/api/v1/designer/flows/${flowId}/events`);
|
|
89
|
+
return response.data;
|
|
90
|
+
}
|
|
91
|
+
export async function listFlowStates(client, flowId) {
|
|
92
|
+
const response = await client.get(`/api/v1/designer/flows/${flowId}/states`);
|
|
93
|
+
return response.data;
|
|
94
|
+
}
|
|
95
|
+
export async function importAkbArticle(client, articleData) {
|
|
96
|
+
const response = await client.post('/api/v1/akb/append-manual', articleData);
|
|
97
|
+
return response.data;
|
|
98
|
+
}
|
|
99
|
+
export async function getCustomerProfile(client) {
|
|
100
|
+
const response = await client.get('/api/v1/customer/profile');
|
|
101
|
+
return response.data;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=api.js.map
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { StoredTokens, CustomerConfig } from './types.js';
|
|
2
|
+
export declare function exchangeApiKeyForToken(customer?: CustomerConfig): Promise<StoredTokens>;
|
|
3
|
+
export declare function refreshWithEndpoint(refreshToken: string, customer?: CustomerConfig): Promise<StoredTokens>;
|
|
4
|
+
export declare function getValidAccessToken(customer?: CustomerConfig): Promise<string>;
|
|
5
|
+
export declare function forceReauth(customer?: CustomerConfig): Promise<string>;
|
|
6
|
+
//# sourceMappingURL=auth.d.ts.map
|