Skip to content

Commit 72c5b4b

Browse files
authored
refactor: project structure change (#3)
* chore: structural refactoring * chore: docs updated
1 parent b9b0e5e commit 72c5b4b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+758
-433
lines changed

.gitignore

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ logs
1515
_.log
1616
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
1717

18-
# dotenv environment variable files
19-
.env
20-
.env.development.local
21-
.env.test.local
22-
.env.production.local
23-
.env.local
24-
2518
# caches
2619
.eslintcache
2720
.cache
@@ -34,4 +27,5 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
3427
.DS_Store
3528

3629
# Wrangler
37-
.wrangler
30+
.wrangler
31+
*.vars

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,22 @@ flowchart TD
4949
LAB --> API
5050
ML --> AI
5151
```
52+
53+
## TODO
54+
55+
- [x] Webhook security
56+
- [x] Github
57+
- [x] Gitlab
58+
- [x] JIRA
59+
- [x] Unit testing
60+
- [x] AI
61+
- [x] Config
62+
- [x] Service
63+
- [x] Types
64+
- [x] Utils
65+
- [x] Webhook
66+
- [x] Worker
67+
- [x] Integrations
68+
- [x] Github
69+
- [x] Gitlab
70+
- [x] JIRA

bun.lock

Lines changed: 186 additions & 114 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "labelit.ai",
3-
"version": "0.0.0",
3+
"version": "0.0.1",
44
"workspaces": [
55
"packages/*",
66
"integrations/*"
@@ -10,12 +10,10 @@
1010
"build": "bun run --filter './packages/*' build",
1111
"lint": "bun run --filter './packages/*' lint",
1212
"test": "bun run --filter './packages/*' test",
13-
"typecheck": "bun run --filter './packages/*' typecheck"
13+
"typecheck": "bun run --filter './packages/*' typecheck",
14+
"update": "bun run --filter './packages/*' update --ignore-scripts --no-progress --no-summary"
1415
},
1516
"devDependencies": {
1617
"husky": "^9.1.7"
17-
},
18-
"peerDependencies": {
19-
"typescript": "^5.7.3"
2018
}
2119
}

packages/ai/package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,26 @@
77
},
88
"./processor": {
99
"default": "./src/processor.ts"
10+
},
11+
"./prompts": {
12+
"default": "./src/prompts.ts"
1013
}
1114
},
1215
"main": "./src/index.ts",
1316
"scripts": {
1417
"lint": "eslint . --fix",
15-
"typecheck": "tsc --noEmit"
18+
"typecheck": "tsc --noEmit",
19+
"update": "bun update"
1620
},
1721
"dependencies": {
1822
"@labelit/config": "workspace:*",
19-
"ai": "^4.1.46",
20-
"workers-ai-provider": "^0.1.1"
23+
"ai": "^4.2.2",
24+
"workers-ai-provider": "^0.1.3"
2125
},
2226
"devDependencies": {
23-
"@antfu/eslint-config": "^4.3.0",
27+
"@antfu/eslint-config": "^4.11.0",
2428
"@labelit/types": "workspace:*",
25-
"eslint": "^9.21.0",
26-
"typescript": "^5.7.3"
29+
"eslint": "^9.23.0",
30+
"typescript": "^5.8.2"
2731
}
2832
}

packages/ai/src/processor.ts

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,44 @@
1-
import type { Bindings } from '@labelit/types/basic'
2-
import type { ProcessedTicket, TicketData } from '@labelit/types/ticket'
1+
import type { Env } from '@labelit/types'
2+
import type { ClassificationType, PromptResponse } from '@labelit/types/basic'
33
import type { LanguageModelV1 } from 'ai'
4-
import { ENV } from '@labelit/config/environment'
54
import { generateText } from 'ai'
65
import { createWorkersAI } from 'workers-ai-provider'
76

8-
export class AIProcessor {
7+
export abstract class AIProcessor<T> {
98
private model: LanguageModelV1
10-
private systemPrompt: string
119

12-
constructor(env: Bindings) {
10+
constructor(env: Env) {
1311
const workersai = createWorkersAI({ binding: env.AI })
14-
this.model = workersai(ENV.MODEL_NAME, {
12+
this.model = workersai(env.MODEL_NAME, {
1513
safePrompt: true,
1614
})
17-
this.systemPrompt = `
18-
You are a ticket classification system. Classify tickets as either Bug, Story, Task, or Spike.
19-
20-
- Bugs: Issues or unexpected behavior
21-
- Stories: User-facing features
22-
- Tasks: Technical work items
23-
- Spikes: Research or exploration items
24-
25-
Respond only with the classification label.
26-
`
2715
}
2816

29-
public async classifyTicket(ticket: TicketData): Promise<ProcessedTicket | Error> {
17+
public async classify<TContent>(content: TContent, prompt: PromptResponse): Promise<ClassificationType> {
3018
const startTime = Date.now()
31-
const userContent = `Title: ${ticket.title}\nDescription: ${ticket.description}`
3219

3320
const { text } = await generateText({
3421
model: this.model,
3522
messages: [{
3623
role: 'system',
37-
content: this.systemPrompt,
24+
content: prompt.system,
3825
}, {
3926
role: 'user',
40-
content: userContent,
27+
content: prompt.user,
28+
}, {
29+
role: 'data',
30+
content: typeof content === 'string' ? content : JSON.stringify(content),
4131
}],
4232
})
4333

44-
const result: ProcessedTicket = {
45-
...ticket,
46-
predictedLabel: this.parseResponse(text),
34+
const result: ClassificationType = {
35+
text,
4736
processingTime: Date.now() - startTime,
4837
}
4938

5039
return result
5140
}
5241

53-
private parseResponse(response: string): ProcessedTicket['predictedLabel'] {
54-
const normalized = response.trim().toLowerCase()
55-
if (normalized.includes('bug'))
56-
return 'Bug'
57-
if (normalized.includes('story'))
58-
return 'Story'
59-
if (normalized.includes('spike'))
60-
return 'Spike'
61-
return 'Task'
62-
}
42+
public abstract preparePrompt<P>(payload: P): PromptResponse
43+
public abstract parseResponse(result: ClassificationType): T
6344
}

packages/ai/src/prompts.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
export const issuePrompt = `
2+
You are an advanced AI issue classification system. Your goal is to provide comprehensive and accurate ticket classification.
3+
4+
Classification Categories:
5+
6+
1. Primary Types:
7+
- Bug: Unexpected behavior, system malfunction, or error
8+
* Severity levels: Critical, High, Medium, Low
9+
* Impact: System-wide, Feature-specific, Minor
10+
11+
- Story: User-facing feature or enhancement
12+
* Types:
13+
* New Feature
14+
* Feature Enhancement
15+
* User Experience Improvement
16+
* Complexity: Simple, Medium, Complex
17+
18+
- Task: Technical work item
19+
* Categories:
20+
* Refactoring
21+
* Technical Debt
22+
* Infrastructure
23+
* DevOps
24+
* Configuration
25+
* Priority: High, Medium, Low
26+
27+
- Spike: Research or exploration
28+
* Purpose:
29+
* Technical Investigation
30+
* Proof of Concept
31+
* Architecture Exploration
32+
* Technology Evaluation
33+
* Duration: Short-term, Medium-term, Long-term
34+
35+
2. Additional Classification Dimensions:
36+
- Impact Area:
37+
* Frontend
38+
* Backend
39+
* Database
40+
* Infrastructure
41+
* Security
42+
* Performance
43+
44+
- Origin:
45+
* Customer Reported
46+
* Internal Discovery
47+
* Proactive Improvement
48+
* Regression
49+
50+
Evaluation Criteria:
51+
- Analyze title and description comprehensively
52+
- Consider implied complexity and effort
53+
- Assess potential system-wide implications
54+
`
55+
export const prPrompt = `
56+
You are an advanced AI pull request classifier. Your task is to provide a comprehensive analysis of pull requests.
57+
58+
Classification Labels:
59+
1. Risk Categories:
60+
- Low Risk: Minor changes, no critical system impact
61+
- Medium Risk: Moderate changes, potential minor system effects
62+
- High Risk: Significant changes, potential major system impacts
63+
64+
2. Change Types:
65+
- Refactoring: Code restructuring without changing external behavior
66+
- Testing: Adds or improves test coverage
67+
- Feature: New functionality
68+
- Bugfix: Resolves existing issues
69+
- Performance: Optimization of existing code
70+
- Security: Addresses security vulnerabilities
71+
72+
3. Complexity Indicators:
73+
- Cyclomatic Complexity
74+
- Number of changed files
75+
- Lines of code added/removed
76+
- Test coverage impact
77+
78+
Evaluation Criteria:
79+
- Assess potential system-wide implications
80+
- Consider code quality and maintainability
81+
- Evaluate potential regression risks
82+
- Analyze test coverage and impact
83+
`

packages/config/package.json

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,19 @@
44
"exports": {
55
".": {
66
"default": "./src/index.ts"
7-
},
8-
"./environment": {
9-
"default": "./src/environment.ts"
107
}
118
},
129
"main": "./src/index.ts",
1310
"scripts": {
1411
"lint": "eslint . --fix",
15-
"typecheck": "tsc --noEmit"
16-
},
17-
"dependencies": {
18-
"std-env": "^3.8.0"
12+
"typecheck": "tsc --noEmit",
13+
"update": "bun update"
1914
},
2015
"devDependencies": {
21-
"@antfu/eslint-config": "^4.3.0",
22-
"eslint": "^9.21.0",
23-
"typescript": "^5.7.3"
16+
"@antfu/eslint-config": "^4.11.0",
17+
"@labelit/types": "workspace:*",
18+
"eslint": "^9.23.0",
19+
"hono": "^4.7.5",
20+
"typescript": "^5.8.2"
2421
}
2522
}

packages/config/src/constant.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const defaultSecretValue = 'labelit-ai'

packages/config/src/environment.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)