@ossy/consultancy 3.23.0 → 3.24.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/package.json +6 -5
- package/src/ConsultancyNav.jsx +4 -0
- package/src/ConsultancyRecordList.jsx +11 -2
- package/src/CreateConsultancyButton.jsx +3 -2
- package/src/RequestMatches.jsx +52 -0
- package/src/en.translations.json +17 -2
- package/src/extract-request.task.spec.js +1 -1
- package/src/locations.js +3 -0
- package/src/match-resumes.action.js +5 -0
- package/src/match-resumes.js +125 -0
- package/src/match-resumes.spec.js +58 -0
- package/src/match-resumes.task.js +67 -0
- package/src/match-resumes.task.spec.js +68 -0
- package/src/refresh-matches.action.js +5 -0
- package/src/refresh-matches.js +42 -0
- package/src/refresh-matches.spec.js +26 -0
- package/src/refresh-matches.task.js +196 -0
- package/src/refresh-matches.task.spec.js +123 -0
- package/src/request-matches.schema.js +13 -0
- package/src/request.schema.js +1 -1
- package/src/requests.page.jsx +21 -11
- package/src/resumes.page.jsx +121 -0
- package/src/schema-ids.js +1 -0
- package/src/sv.translations.json +17 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/consultancy",
|
|
3
3
|
"description": "Consultancy feature package — schemas, forecasts UI, and assignment margins",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.24.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
7
|
"module": "./src/index.js",
|
|
@@ -25,15 +25,16 @@
|
|
|
25
25
|
"README.md"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@ossy/email": "^3.
|
|
29
|
-
"@ossy/event-store": "^3.
|
|
30
|
-
"@ossy/schema": "^3.
|
|
28
|
+
"@ossy/email": "^3.24.1",
|
|
29
|
+
"@ossy/event-store": "^3.24.1",
|
|
30
|
+
"@ossy/schema": "^3.24.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@ossy/calendar": "*",
|
|
34
34
|
"@ossy/dashboard": "*",
|
|
35
35
|
"@ossy/design-system": "*",
|
|
36
36
|
"@ossy/resources": "*",
|
|
37
|
+
"@ossy/resumes": "*",
|
|
37
38
|
"@ossy/router-react": "*",
|
|
38
39
|
"@ossy/sdk-react": "*",
|
|
39
40
|
"react": "*"
|
|
@@ -41,5 +42,5 @@
|
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"jest": "^30.2.0"
|
|
43
44
|
},
|
|
44
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "d0e7eda0397239d5e8a8cd5115d9c91959b4103f"
|
|
45
46
|
}
|
package/src/ConsultancyNav.jsx
CHANGED
|
@@ -68,7 +68,7 @@ function recordMeta (resource, byId, language) {
|
|
|
68
68
|
/**
|
|
69
69
|
* Storage-style list of one consultancy schema, with the resource panel beside it.
|
|
70
70
|
*/
|
|
71
|
-
export function ConsultancyRecordList ({ schemaId, icon, listHeader, emptyText }) {
|
|
71
|
+
export function ConsultancyRecordList ({ schemaId, icon, listHeader, emptyText, extraPanels }) {
|
|
72
72
|
const sdk = useSdk()
|
|
73
73
|
const { language } = useLocale()
|
|
74
74
|
const { selectedResourceId, setSelectedResourceId, clearSelectedResourceId } = useSelectedResourceId()
|
|
@@ -131,7 +131,14 @@ export function ConsultancyRecordList ({ schemaId, icon, listHeader, emptyText }
|
|
|
131
131
|
</List>
|
|
132
132
|
)}
|
|
133
133
|
panel={selectedResourceId
|
|
134
|
-
?
|
|
134
|
+
? (
|
|
135
|
+
<ResourcePanel
|
|
136
|
+
width="100%"
|
|
137
|
+
resourceId={selectedResourceId}
|
|
138
|
+
onClose={clearSelectedResourceId}
|
|
139
|
+
extraPanels={extraPanels}
|
|
140
|
+
/>
|
|
141
|
+
)
|
|
135
142
|
: null}
|
|
136
143
|
/>
|
|
137
144
|
)
|
|
@@ -145,6 +152,7 @@ export function ConsultancyRecordPage ({
|
|
|
145
152
|
icon,
|
|
146
153
|
listHeader,
|
|
147
154
|
emptyText,
|
|
155
|
+
extraPanels,
|
|
148
156
|
}) {
|
|
149
157
|
const statusTags = (Definition.status ?? [])
|
|
150
158
|
.map((status) => ({ beta: 'Beta', 'coming-soon': 'Coming Soon' }[status]))
|
|
@@ -165,6 +173,7 @@ export function ConsultancyRecordPage ({
|
|
|
165
173
|
icon={icon}
|
|
166
174
|
listHeader={listHeader}
|
|
167
175
|
emptyText={emptyText}
|
|
176
|
+
extraPanels={extraPanels}
|
|
168
177
|
/>
|
|
169
178
|
</View>
|
|
170
179
|
</Page>
|
|
@@ -48,9 +48,9 @@ function createHref (router, schemaId) {
|
|
|
48
48
|
* Add CTA for consultancy schemas.
|
|
49
49
|
* Without `schemaId`, opens a dropdown of document types instead of the type-picker page.
|
|
50
50
|
* With `schemaId`, links straight to that type's create form.
|
|
51
|
-
* @param {{ schemaId?: string }} [props]
|
|
51
|
+
* @param {{ schemaId?: string, before?: import('react').ReactNode }} [props]
|
|
52
52
|
*/
|
|
53
|
-
export function CreateConsultancyButton ({ schemaId, ...props }) {
|
|
53
|
+
export function CreateConsultancyButton ({ schemaId, before, ...props }) {
|
|
54
54
|
const { t } = useLocale()
|
|
55
55
|
const router = useRouter()
|
|
56
56
|
|
|
@@ -77,6 +77,7 @@ export function CreateConsultancyButton ({ schemaId, ...props }) {
|
|
|
77
77
|
>
|
|
78
78
|
<View inset="xs" surface="primary" roundness="s">
|
|
79
79
|
<ContextMenu roundness="s" surface="primary">
|
|
80
|
+
{before}
|
|
80
81
|
{ADD_TYPES.map(({ schema, label }) => (
|
|
81
82
|
<ContextMenu.Item
|
|
82
83
|
key={schema.id}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { List, Text, View } from '@ossy/design-system'
|
|
3
|
+
import { useRouter } from '@ossy/router-react'
|
|
4
|
+
import { AsyncStatus, useSdk } from '@ossy/sdk-react'
|
|
5
|
+
import { ListResources } from '@ossy/resources'
|
|
6
|
+
import { referenceId } from '@ossy/resumes/resume-links'
|
|
7
|
+
import { ConsultancySchema } from './schema-ids.js'
|
|
8
|
+
import { matchesLocation } from './locations.js'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Saved matches for one request. Embedding and ranking happen when the
|
|
12
|
+
* request or a resume changes, not when this panel opens.
|
|
13
|
+
*/
|
|
14
|
+
export function RequestMatches ({ requestId, resourceId }) {
|
|
15
|
+
const id = requestId || resourceId
|
|
16
|
+
const sdk = useSdk()
|
|
17
|
+
const router = useRouter()
|
|
18
|
+
const { data: resources = [], status } = sdk.read(ListResources, { location: matchesLocation })
|
|
19
|
+
const loading = status === AsyncStatus.Loading || status === AsyncStatus.NotInitialized
|
|
20
|
+
const match = (Array.isArray(resources) ? resources : []).find((resource) => (
|
|
21
|
+
resource?.type === ConsultancySchema.requestMatches
|
|
22
|
+
&& referenceId(resource?.content?.request) === id
|
|
23
|
+
))
|
|
24
|
+
const matches = Array.isArray(match?.content?.matches) ? match.content.matches : []
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<View gap="s" inset="m" data-request-matches={loading ? 'loading' : match ? 'ready' : 'pending'}>
|
|
28
|
+
{loading ? <Text color="secondary" text="consultancy.matches.loading" /> : null}
|
|
29
|
+
{!loading && !match ? <Text color="secondary" text="consultancy.matches.pending" /> : null}
|
|
30
|
+
{!loading && match && matches.length === 0 ? (
|
|
31
|
+
<Text color="secondary" text="consultancy.matches.empty" />
|
|
32
|
+
) : null}
|
|
33
|
+
{!loading && matches.length > 0 ? (
|
|
34
|
+
<List>
|
|
35
|
+
{matches.map((item) => (
|
|
36
|
+
<List.Item
|
|
37
|
+
key={item.resourceId}
|
|
38
|
+
href={router.getHref({
|
|
39
|
+
id: '@resume',
|
|
40
|
+
params: { resumeId: item.resourceId, workspaceId: router.params.workspaceId },
|
|
41
|
+
})}
|
|
42
|
+
data-resource-name={item.name || undefined}
|
|
43
|
+
meta={item.shared?.length ? <Text variant="small">{item.shared.join(', ')}</Text> : null}
|
|
44
|
+
>
|
|
45
|
+
{item.name || item.resourceId}
|
|
46
|
+
</List.Item>
|
|
47
|
+
))}
|
|
48
|
+
</List>
|
|
49
|
+
) : null}
|
|
50
|
+
</View>
|
|
51
|
+
)
|
|
52
|
+
}
|
package/src/en.translations.json
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
"consultancy/contracts.documentTitle": "Contracts",
|
|
8
8
|
"consultancy/opportunities.documentTitle": "Opportunities",
|
|
9
9
|
"consultancy/requests.documentTitle": "Requests",
|
|
10
|
+
"consultancy/resumes.documentTitle": "Resumes",
|
|
10
11
|
"consultancy/proposals.documentTitle": "Proposals",
|
|
11
12
|
"consultancy/reports.documentTitle": "Reports",
|
|
12
13
|
"consultancy.home.title": "Overview",
|
|
@@ -20,6 +21,7 @@
|
|
|
20
21
|
"consultancy.nav.vacations": "Vacations",
|
|
21
22
|
"consultancy.nav.contracts": "Contracts",
|
|
22
23
|
"consultancy.nav.requests": "Requests",
|
|
24
|
+
"consultancy.nav.resumes": "Resumes",
|
|
23
25
|
"consultancy.nav.opportunities": "Opportunities",
|
|
24
26
|
"consultancy.nav.proposals": "Proposals",
|
|
25
27
|
"consultancy.nav.reports": "Reports",
|
|
@@ -75,6 +77,19 @@
|
|
|
75
77
|
"consultancy.requests.title": "Requests",
|
|
76
78
|
"consultancy.requests.description": "Assignments parsed from inbound email",
|
|
77
79
|
"consultancy.requests.empty": "No requests yet.",
|
|
80
|
+
"consultancy.matches.title": "Matching resumes",
|
|
81
|
+
"consultancy.matches.loading": "Matching resumes…",
|
|
82
|
+
"consultancy.matches.empty": "No resumes to match.",
|
|
83
|
+
"consultancy.matches.error": "Could not match resumes.",
|
|
84
|
+
"consultancy.matches.embeddingsUnavailable": "Showing tag overlap. Similarity is unavailable.",
|
|
85
|
+
"consultancy.matches.pending": "Matches are prepared when a request or resume changes.",
|
|
86
|
+
"@ossy/consultancy/actions/refresh-matches.label": "Refresh matches",
|
|
87
|
+
"@ossy/consultancy/actions/refresh-matches.description": "Embed changed requests and resumes, then save their matches",
|
|
88
|
+
"@ossy/consultancy/actions/match-resumes.label": "Match resumes",
|
|
89
|
+
"@ossy/consultancy/actions/match-resumes.description": "Rank resumes in this workspace against a request by shared tags and similarity",
|
|
90
|
+
"consultancy.resumes.title": "Resumes",
|
|
91
|
+
"consultancy.resumes.description": "Resumes in this workspace, linked to a profile and experiences",
|
|
92
|
+
"consultancy.resumes.empty": "No resumes yet.",
|
|
78
93
|
"consultancy.requests.statsTitle": "Incoming requests",
|
|
79
94
|
"consultancy.requests.statsSeries": "Requests",
|
|
80
95
|
"consultancy.requests.statsUnit": "requests",
|
|
@@ -171,8 +186,8 @@
|
|
|
171
186
|
"@ossy/consultancy/schema/request.summary.description": "What the client is asking for.",
|
|
172
187
|
"@ossy/consultancy/schema/request.role.label": "Role",
|
|
173
188
|
"@ossy/consultancy/schema/request.role.description": "The profile they are looking for.",
|
|
174
|
-
"@ossy/consultancy/schema/request.
|
|
175
|
-
"@ossy/consultancy/schema/request.
|
|
189
|
+
"@ossy/consultancy/schema/request.tags.label": "Skills",
|
|
190
|
+
"@ossy/consultancy/schema/request.tags.description": "Skills or technologies named in the request.",
|
|
176
191
|
"@ossy/consultancy/schema/request.location.label": "Location",
|
|
177
192
|
"@ossy/consultancy/schema/request.location.description": "Where the work happens.",
|
|
178
193
|
"@ossy/consultancy/schema/request.duration.label": "Duration",
|
|
@@ -25,7 +25,7 @@ const extracted = {
|
|
|
25
25
|
title: 'Senior React, 6 manader',
|
|
26
26
|
summary: 'Senior React developer in Stockholm for 6 months, starting in January.',
|
|
27
27
|
role: 'Senior React developer',
|
|
28
|
-
|
|
28
|
+
tags: ['React'],
|
|
29
29
|
location: 'Stockholm',
|
|
30
30
|
duration: '6 months',
|
|
31
31
|
start: 'January',
|
package/src/locations.js
CHANGED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rank resume documents against a consultancy request.
|
|
3
|
+
* Tag overlap is the share of the request's tags that the resume also has.
|
|
4
|
+
* Similarity is the cosine score from the existing embedding store, when present.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export function tagsOf (value) {
|
|
8
|
+
const items = Array.isArray(value)
|
|
9
|
+
? value
|
|
10
|
+
: (typeof value === 'string' ? value.split(',') : [])
|
|
11
|
+
const seen = new Set()
|
|
12
|
+
const tags = []
|
|
13
|
+
for (const item of items) {
|
|
14
|
+
if (typeof item !== 'string') continue
|
|
15
|
+
const trimmed = item.trim()
|
|
16
|
+
const key = trimmed.toLowerCase()
|
|
17
|
+
if (!key || seen.has(key)) continue
|
|
18
|
+
seen.add(key)
|
|
19
|
+
tags.push(trimmed)
|
|
20
|
+
}
|
|
21
|
+
return tags
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function tagOverlap (requestTags, resumeTags) {
|
|
25
|
+
const resumeByKey = new Map(resumeTags.map((tag) => [tag.toLowerCase(), tag]))
|
|
26
|
+
const shared = []
|
|
27
|
+
for (const tag of requestTags) {
|
|
28
|
+
const hit = resumeByKey.get(tag.toLowerCase())
|
|
29
|
+
if (hit) shared.push(hit)
|
|
30
|
+
}
|
|
31
|
+
const score = requestTags.length === 0 ? 0 : shared.length / requestTags.length
|
|
32
|
+
return { shared, score }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function line (label, value) {
|
|
36
|
+
if (typeof value !== 'string') return ''
|
|
37
|
+
const trimmed = value.trim()
|
|
38
|
+
if (!trimmed) return ''
|
|
39
|
+
return `${label}: ${trimmed}`
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function textField (content, next, previous) {
|
|
43
|
+
const value = content?.[next] ?? content?.[previous]
|
|
44
|
+
return typeof value === 'string' ? value.trim() : ''
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function requestMatchText (resource) {
|
|
48
|
+
const content = resource?.content && typeof resource.content === 'object' ? resource.content : {}
|
|
49
|
+
return [
|
|
50
|
+
line('Title', content.title || resource?.name),
|
|
51
|
+
line('Summary', content.summary),
|
|
52
|
+
line('Role', content.role),
|
|
53
|
+
line('Tags', tagsOf(content.tags).join(', ')),
|
|
54
|
+
line('Location', content.location),
|
|
55
|
+
line('Duration', content.duration),
|
|
56
|
+
line('Start', content.start),
|
|
57
|
+
].filter(Boolean).join('\n')
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function resumeMatchText (resume, { profile, experiences } = {}) {
|
|
61
|
+
const content = resume?.content && typeof resume.content === 'object' ? resume.content : {}
|
|
62
|
+
const lines = [
|
|
63
|
+
line('Resume', resume?.name),
|
|
64
|
+
line('Tags', tagsOf(content.tags).join(', ')),
|
|
65
|
+
]
|
|
66
|
+
const profileContent = profile?.content && typeof profile.content === 'object' ? profile.content : null
|
|
67
|
+
if (profileContent) {
|
|
68
|
+
lines.push(
|
|
69
|
+
line('Name', profileContent.name),
|
|
70
|
+
line('Role', profileContent.role),
|
|
71
|
+
line('Summary', profileContent.summary),
|
|
72
|
+
line('Profile tags', tagsOf(profileContent.tags).join(', ')),
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
for (const experience of experiences || []) {
|
|
76
|
+
const experienceContent = experience?.content && typeof experience.content === 'object'
|
|
77
|
+
? experience.content
|
|
78
|
+
: {}
|
|
79
|
+
lines.push(
|
|
80
|
+
line('Experience', textField(experienceContent, 'title', 'Title')),
|
|
81
|
+
line('Subtitle', textField(experienceContent, 'subtitle', 'Sub Title')),
|
|
82
|
+
line('Kind', textField(experienceContent, 'kind', 'Type of experience')),
|
|
83
|
+
line('Description', textField(experienceContent, 'description', 'Description')),
|
|
84
|
+
line('Experience tags', tagsOf(experienceContent.tags ?? experienceContent.Tags).join(', ')),
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
return lines.filter(Boolean).join('\n')
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @param {{
|
|
92
|
+
* request: object,
|
|
93
|
+
* resumes: object[],
|
|
94
|
+
* similarities?: Array<{ resourceId: string, score: number }>,
|
|
95
|
+
* }} input
|
|
96
|
+
*/
|
|
97
|
+
export function rankMatches ({ request, resumes, similarities = [] } = {}) {
|
|
98
|
+
const requestTags = tagsOf(request?.content?.tags)
|
|
99
|
+
const similarityById = new Map()
|
|
100
|
+
for (const item of similarities || []) {
|
|
101
|
+
if (!item?.resourceId || !Number.isFinite(item.score)) continue
|
|
102
|
+
similarityById.set(item.resourceId, item.score)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return (resumes || [])
|
|
106
|
+
.filter((resume) => resume?.id && resume.id !== request?.id)
|
|
107
|
+
.map((resume) => {
|
|
108
|
+
const overlap = tagOverlap(requestTags, tagsOf(resume?.content?.tags))
|
|
109
|
+
const similarity = similarityById.has(resume.id) ? similarityById.get(resume.id) : null
|
|
110
|
+
return {
|
|
111
|
+
resourceId: resume.id,
|
|
112
|
+
name: typeof resume.name === 'string' ? resume.name : '',
|
|
113
|
+
tags: tagsOf(resume?.content?.tags),
|
|
114
|
+
shared: overlap.shared,
|
|
115
|
+
tagScore: overlap.score,
|
|
116
|
+
similarity,
|
|
117
|
+
score: overlap.score + (similarity ?? 0),
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
.sort((a, b) => (
|
|
121
|
+
b.score - a.score
|
|
122
|
+
|| b.shared.length - a.shared.length
|
|
123
|
+
|| a.name.localeCompare(b.name)
|
|
124
|
+
))
|
|
125
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { rankMatches, requestMatchText, resumeMatchText, tagOverlap, tagsOf } from './match-resumes.js'
|
|
2
|
+
|
|
3
|
+
const request = {
|
|
4
|
+
id: 'request-1',
|
|
5
|
+
name: 'Senior React consultant',
|
|
6
|
+
content: {
|
|
7
|
+
title: 'Senior React consultant',
|
|
8
|
+
summary: 'A product team wants a React and Node.js consultant.',
|
|
9
|
+
role: 'Senior frontend',
|
|
10
|
+
tags: ['React', 'Node.js'],
|
|
11
|
+
location: 'Stockholm',
|
|
12
|
+
},
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe('match resumes', () => {
|
|
16
|
+
it('reads tags from a list or a comma string', () => {
|
|
17
|
+
expect(tagsOf([' React ', 'react', 'Node.js'])).toEqual(['React', 'Node.js'])
|
|
18
|
+
expect(tagsOf('React, Node.js')).toEqual(['React', 'Node.js'])
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('scores tag overlap as the share of the request tags that the resume has', () => {
|
|
22
|
+
expect(tagOverlap(['React', 'Node.js'], ['react', 'TypeScript'])).toEqual({
|
|
23
|
+
shared: ['react'],
|
|
24
|
+
score: 0.5,
|
|
25
|
+
})
|
|
26
|
+
expect(tagOverlap([], ['React']).score).toBe(0)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('writes the request and the linked resume as text an embedding can read', () => {
|
|
30
|
+
expect(requestMatchText(request)).toContain('Tags: React, Node.js')
|
|
31
|
+
expect(resumeMatchText({
|
|
32
|
+
name: 'React consultant',
|
|
33
|
+
content: { tags: ['React', 'Node.js'] },
|
|
34
|
+
}, {
|
|
35
|
+
profile: { content: { name: 'Ada Consultant', role: 'Senior React consultant' } },
|
|
36
|
+
experiences: [{ content: { Title: 'Platform engineer', Tags: 'React, Node.js' } }],
|
|
37
|
+
})).toContain('Experience: Platform engineer')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('orders resumes by tag overlap plus similarity', () => {
|
|
41
|
+
const resumes = [
|
|
42
|
+
{ id: 'low', name: 'Design', content: { tags: ['Figma'] } },
|
|
43
|
+
{ id: 'tags-only', name: 'React', content: { tags: ['React', 'Node.js'] } },
|
|
44
|
+
{ id: 'both', name: 'Full stack', content: { tags: ['React'] } },
|
|
45
|
+
]
|
|
46
|
+
const ranked = rankMatches({
|
|
47
|
+
request,
|
|
48
|
+
resumes,
|
|
49
|
+
similarities: [
|
|
50
|
+
{ resourceId: 'both', score: 0.9 },
|
|
51
|
+
{ resourceId: 'low', score: 0.1 },
|
|
52
|
+
],
|
|
53
|
+
})
|
|
54
|
+
expect(ranked.map((item) => item.resourceId)).toEqual(['both', 'tags-only', 'low'])
|
|
55
|
+
expect(ranked[0]).toMatchObject({ shared: ['React'], tagScore: 0.5, similarity: 0.9, score: 1.4 })
|
|
56
|
+
expect(ranked[1].similarity).toBeNull()
|
|
57
|
+
})
|
|
58
|
+
})
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { scoreRequests } from './refresh-matches.task.js'
|
|
2
|
+
import { location as resumeLocation } from '@ossy/resumes/locations'
|
|
3
|
+
import { ResumesSchema } from '@ossy/resumes/schema-ids'
|
|
4
|
+
import { ConsultancySchema } from './schema-ids.js'
|
|
5
|
+
import { location, matchesLocation } from './locations.js'
|
|
6
|
+
import { referenceId } from '@ossy/resumes/resume-links'
|
|
7
|
+
|
|
8
|
+
const GetResource = { id: '@ossy/resources/actions/get' }
|
|
9
|
+
const ListResources = { id: '@ossy/resources/actions/list' }
|
|
10
|
+
|
|
11
|
+
export const metadata = {
|
|
12
|
+
id: '@ossy/consultancy/tasks/match-resumes',
|
|
13
|
+
triggers: [
|
|
14
|
+
{
|
|
15
|
+
kind: 'on_action',
|
|
16
|
+
action: '@ossy/consultancy/actions/match-resumes',
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function fail (message, status) {
|
|
22
|
+
throw Object.assign(new Error(message), { status })
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function asResourceList (result) {
|
|
26
|
+
if (Array.isArray(result)) return result
|
|
27
|
+
if (Array.isArray(result?.items)) return result.items
|
|
28
|
+
return []
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Re-rank one request from embeddings that already exist. Does not embed.
|
|
33
|
+
* New and changed documents are embedded by the refresh-matches task.
|
|
34
|
+
*/
|
|
35
|
+
export async function run ({ payload, req, sdk }) {
|
|
36
|
+
if (!sdk?.invoke) fail('sdk is required', 500)
|
|
37
|
+
|
|
38
|
+
const requestId = payload?.requestId ?? payload?.resourceId
|
|
39
|
+
if (!requestId) fail('requestId is required', 400)
|
|
40
|
+
const workspaceId = payload?.workspaceId ?? req?.workspaceId
|
|
41
|
+
if (!workspaceId) fail('workspaceId is required', 400)
|
|
42
|
+
|
|
43
|
+
const request = await sdk.invoke(GetResource, { resourceId: requestId })
|
|
44
|
+
if (request?.type !== ConsultancySchema.request) fail('request is required', 400)
|
|
45
|
+
if (request.belongsTo && request.belongsTo !== workspaceId) fail('request is required', 404)
|
|
46
|
+
|
|
47
|
+
const listed = async (listLocation) => asResourceList(await sdk.invoke(ListResources, {
|
|
48
|
+
location: listLocation,
|
|
49
|
+
workspaceId,
|
|
50
|
+
}))
|
|
51
|
+
const resumes = (await listed(resumeLocation)).filter((item) => item?.type === ResumesSchema.resume)
|
|
52
|
+
const existing = (await listed(matchesLocation)).filter((item) => (
|
|
53
|
+
item?.type === ConsultancySchema.requestMatches && referenceId(item?.content?.request) === request.id
|
|
54
|
+
))
|
|
55
|
+
|
|
56
|
+
const saved = await scoreRequests(sdk, {
|
|
57
|
+
workspaceId,
|
|
58
|
+
requests: [request],
|
|
59
|
+
resumes,
|
|
60
|
+
existing,
|
|
61
|
+
})
|
|
62
|
+
const match = saved[0]
|
|
63
|
+
return {
|
|
64
|
+
requestId: request.id,
|
|
65
|
+
matches: match?.content?.matches || [],
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, jest } from '@jest/globals'
|
|
2
|
+
|
|
3
|
+
const loadWorkspaceEmbeddings = jest.fn()
|
|
4
|
+
|
|
5
|
+
jest.unstable_mockModule('@ossy/platform/vector/vector-store', () => ({
|
|
6
|
+
getEmbedding: jest.fn(),
|
|
7
|
+
loadWorkspaceEmbeddings,
|
|
8
|
+
cosineSimilarity: () => 0.8,
|
|
9
|
+
}))
|
|
10
|
+
|
|
11
|
+
const { run } = await import('./match-resumes.task.js')
|
|
12
|
+
|
|
13
|
+
const GetResource = { id: '@ossy/resources/actions/get' }
|
|
14
|
+
const ListResources = { id: '@ossy/resources/actions/list' }
|
|
15
|
+
const CreateResource = { id: '@ossy/resources/actions/create' }
|
|
16
|
+
const EmbedResource = { id: '@ossy/media-tasks/actions/embed-resource' }
|
|
17
|
+
|
|
18
|
+
const request = {
|
|
19
|
+
id: 'request-1',
|
|
20
|
+
type: '@ossy/consultancy/schema/request',
|
|
21
|
+
belongsTo: 'ws-1',
|
|
22
|
+
name: 'Senior React consultant',
|
|
23
|
+
content: { title: 'Senior React consultant', tags: ['React'] },
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const resume = {
|
|
27
|
+
id: 'resume-1',
|
|
28
|
+
type: '@ossy/resumes/schema/resume',
|
|
29
|
+
name: 'React consultant',
|
|
30
|
+
content: { tags: ['React'] },
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe('match-resumes task', () => {
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
loadWorkspaceEmbeddings.mockReset()
|
|
36
|
+
loadWorkspaceEmbeddings.mockResolvedValue([
|
|
37
|
+
{ resourceId: 'request-1', vector: [1] },
|
|
38
|
+
{ resourceId: 'resume-1', vector: [1] },
|
|
39
|
+
])
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('ranks from stored embeddings and does not embed', async () => {
|
|
43
|
+
const created = []
|
|
44
|
+
const sdk = {
|
|
45
|
+
invoke: jest.fn(async (action, payload) => {
|
|
46
|
+
if (action.id === GetResource.id) return request
|
|
47
|
+
if (action.id === ListResources.id) {
|
|
48
|
+
if (payload.location === '/@ossy/resumes/') return [resume]
|
|
49
|
+
return []
|
|
50
|
+
}
|
|
51
|
+
if (action.id === CreateResource.id) {
|
|
52
|
+
created.push(payload)
|
|
53
|
+
return { id: 'match-1', content: payload.content }
|
|
54
|
+
}
|
|
55
|
+
if (action.id === EmbedResource.id) throw new Error('should not embed')
|
|
56
|
+
throw new Error(action.id)
|
|
57
|
+
}),
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const result = await run({
|
|
61
|
+
payload: { requestId: 'request-1', workspaceId: 'ws-1' },
|
|
62
|
+
sdk,
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
expect(created[0].content.matches[0].resourceId).toBe('resume-1')
|
|
66
|
+
expect(result.matches[0]).toMatchObject({ resourceId: 'resume-1', similarity: 0.8 })
|
|
67
|
+
})
|
|
68
|
+
})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { referenceId, referenceIds } from '@ossy/resumes/resume-links'
|
|
3
|
+
|
|
4
|
+
export const PROFILE_SCHEMA = '@ossy/profile/schema/profile'
|
|
5
|
+
|
|
6
|
+
export function textHash (text) {
|
|
7
|
+
return createHash('sha256').update(text).digest('hex')
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** An embedding is current when it was built from this exact text. */
|
|
11
|
+
export function embeddingIsCurrent (stored, hash) {
|
|
12
|
+
return Boolean(hash) && stored?.textHash === hash
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Resumes whose profile or experience links point at this resource. */
|
|
16
|
+
export function resumesLinking (resumes, resourceId) {
|
|
17
|
+
if (!resourceId) return []
|
|
18
|
+
return (resumes || []).filter((resume) => {
|
|
19
|
+
if (referenceId(resume?.content?.profile) === resourceId) return true
|
|
20
|
+
return referenceIds(resume?.content?.experiences).includes(resourceId)
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function round (value) {
|
|
25
|
+
return Math.round((Number(value) || 0) * 1000) / 1000
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function normalized (matches) {
|
|
29
|
+
return (matches || []).map((match) => ({
|
|
30
|
+
resourceId: match.resourceId,
|
|
31
|
+
name: match.name || '',
|
|
32
|
+
shared: match.shared || [],
|
|
33
|
+
tagScore: round(match.tagScore),
|
|
34
|
+
similarity: match.similarity == null ? null : round(match.similarity),
|
|
35
|
+
score: round(match.score),
|
|
36
|
+
}))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** True when a saved match list would not change a later reader. */
|
|
40
|
+
export function matchesEqual (left, right) {
|
|
41
|
+
return JSON.stringify(normalized(left)) === JSON.stringify(normalized(right))
|
|
42
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { embeddingIsCurrent, matchesEqual, resumesLinking, textHash } from './refresh-matches.js'
|
|
2
|
+
|
|
3
|
+
describe('refresh matches', () => {
|
|
4
|
+
it('treats an embedding as current only when the text hash matches', () => {
|
|
5
|
+
const hash = textHash('Title: React')
|
|
6
|
+
expect(embeddingIsCurrent({ textHash: hash }, hash)).toBe(true)
|
|
7
|
+
expect(embeddingIsCurrent({ textHash: 'other' }, hash)).toBe(false)
|
|
8
|
+
expect(embeddingIsCurrent(null, hash)).toBe(false)
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('finds resumes that link a profile or an experience', () => {
|
|
12
|
+
const resumes = [
|
|
13
|
+
{ id: 'a', content: { profile: { resourceId: 'profile-1' }, experiences: [] } },
|
|
14
|
+
{ id: 'b', content: { experiences: [{ resourceId: 'experience-1' }] } },
|
|
15
|
+
{ id: 'c', content: { profile: { resourceId: 'other' } } },
|
|
16
|
+
]
|
|
17
|
+
expect(resumesLinking(resumes, 'profile-1').map((item) => item.id)).toEqual(['a'])
|
|
18
|
+
expect(resumesLinking(resumes, 'experience-1').map((item) => item.id)).toEqual(['b'])
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('treats the same ranking as unchanged', () => {
|
|
22
|
+
const matches = [{ resourceId: 'resume-1', name: 'React', shared: ['React'], tagScore: 1, similarity: 0.8, score: 1.8 }]
|
|
23
|
+
expect(matchesEqual(matches, [{ ...matches[0], score: 1.8004 }])).toBe(true)
|
|
24
|
+
expect(matchesEqual(matches, [{ ...matches[0], resourceId: 'resume-2' }])).toBe(false)
|
|
25
|
+
})
|
|
26
|
+
})
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { location as resumeLocation } from '@ossy/resumes/locations'
|
|
2
|
+
import { referenceId, referenceIds } from '@ossy/resumes/resume-links'
|
|
3
|
+
import { ResumesSchema } from '@ossy/resumes/schema-ids'
|
|
4
|
+
import { cosineSimilarity, getEmbedding, loadWorkspaceEmbeddings } from '@ossy/platform/vector/vector-store'
|
|
5
|
+
import { ConsultancySchema } from './schema-ids.js'
|
|
6
|
+
import { location, matchesLocation } from './locations.js'
|
|
7
|
+
import { rankMatches, requestMatchText, resumeMatchText } from './match-resumes.js'
|
|
8
|
+
import {
|
|
9
|
+
PROFILE_SCHEMA,
|
|
10
|
+
embeddingIsCurrent,
|
|
11
|
+
matchesEqual,
|
|
12
|
+
resumesLinking,
|
|
13
|
+
textHash,
|
|
14
|
+
} from './refresh-matches.js'
|
|
15
|
+
|
|
16
|
+
const GetResource = { id: '@ossy/resources/actions/get' }
|
|
17
|
+
const ListResources = { id: '@ossy/resources/actions/list' }
|
|
18
|
+
const CreateResource = { id: '@ossy/resources/actions/create' }
|
|
19
|
+
const UpdateContent = { id: '@ossy/resources/actions/update-content' }
|
|
20
|
+
const EmbedResource = { id: '@ossy/media-tasks/actions/embed-resource' }
|
|
21
|
+
|
|
22
|
+
export const metadata = {
|
|
23
|
+
id: '@ossy/consultancy/tasks/refresh-matches',
|
|
24
|
+
schedule: '*/5 * * * *',
|
|
25
|
+
triggers: [
|
|
26
|
+
{ type: ConsultancySchema.request, event: 'Created' },
|
|
27
|
+
{ type: ConsultancySchema.request, event: 'Updated' },
|
|
28
|
+
{ type: ResumesSchema.resume, event: 'Created' },
|
|
29
|
+
{ type: ResumesSchema.resume, event: 'Updated' },
|
|
30
|
+
{ type: PROFILE_SCHEMA, event: 'Created' },
|
|
31
|
+
{ type: PROFILE_SCHEMA, event: 'Updated' },
|
|
32
|
+
{ type: ResumesSchema.resumeExperience, event: 'Created' },
|
|
33
|
+
{ type: ResumesSchema.resumeExperience, event: 'Updated' },
|
|
34
|
+
],
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function fail (message, status) {
|
|
38
|
+
throw Object.assign(new Error(message), { status })
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function asResourceList (result) {
|
|
42
|
+
if (Array.isArray(result)) return result
|
|
43
|
+
if (Array.isArray(result?.items)) return result.items
|
|
44
|
+
return []
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function workspaceIdFrom ({ event, payload, req }) {
|
|
48
|
+
return event?.payload?.belongsTo
|
|
49
|
+
?? payload?.workspaceId
|
|
50
|
+
?? req?.workspaceId
|
|
51
|
+
?? null
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function readLinked (sdk, resourceId) {
|
|
55
|
+
if (!resourceId) return null
|
|
56
|
+
try {
|
|
57
|
+
return await sdk.invoke(GetResource, { resourceId })
|
|
58
|
+
} catch (err) {
|
|
59
|
+
if (err?.status === 404) return null
|
|
60
|
+
throw err
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function listAt (sdk, listLocation, workspaceId) {
|
|
65
|
+
return asResourceList(await sdk.invoke(ListResources, { location: listLocation, workspaceId }))
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Embed a request or resume when its text changed. Returns true when a new vector was written.
|
|
70
|
+
*/
|
|
71
|
+
export async function ensureEmbedded (sdk, resource, workspaceId) {
|
|
72
|
+
const text = resource?.type === ConsultancySchema.request
|
|
73
|
+
? requestMatchText(resource)
|
|
74
|
+
: await resumeText(sdk, resource)
|
|
75
|
+
if (!text) return false
|
|
76
|
+
const hash = textHash(text)
|
|
77
|
+
const stored = await getEmbedding(resource.id)
|
|
78
|
+
if (embeddingIsCurrent(stored, hash)) return false
|
|
79
|
+
await sdk.invoke(EmbedResource, {
|
|
80
|
+
resourceId: resource.id,
|
|
81
|
+
text,
|
|
82
|
+
textHash: hash,
|
|
83
|
+
workspaceId,
|
|
84
|
+
})
|
|
85
|
+
return true
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function resumeText (sdk, resume) {
|
|
89
|
+
const profile = await readLinked(sdk, referenceId(resume?.content?.profile))
|
|
90
|
+
const experiences = (await Promise.all(
|
|
91
|
+
referenceIds(resume?.content?.experiences).map((id) => readLinked(sdk, id)),
|
|
92
|
+
)).filter(Boolean)
|
|
93
|
+
return resumeMatchText(resume, { profile, experiences })
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function similaritiesFor (queryVector, resumes, vectorById) {
|
|
97
|
+
if (!Array.isArray(queryVector) || !queryVector.length) return []
|
|
98
|
+
const scores = []
|
|
99
|
+
for (const resume of resumes) {
|
|
100
|
+
const vector = vectorById.get(resume.id)
|
|
101
|
+
if (!vector) continue
|
|
102
|
+
scores.push({ resourceId: resume.id, score: cosineSimilarity(queryVector, vector) })
|
|
103
|
+
}
|
|
104
|
+
return scores
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function saveMatches (sdk, { workspaceId, request, matches, existing }) {
|
|
108
|
+
const content = {
|
|
109
|
+
request: { resourceId: request.id },
|
|
110
|
+
matches,
|
|
111
|
+
}
|
|
112
|
+
const current = existing.find((item) => referenceId(item?.content?.request) === request.id)
|
|
113
|
+
if (current && matchesEqual(current.content?.matches, matches)) return current
|
|
114
|
+
if (current) {
|
|
115
|
+
return sdk.invoke(UpdateContent, { resourceId: current.id, workspaceId, content })
|
|
116
|
+
}
|
|
117
|
+
return sdk.invoke(CreateResource, {
|
|
118
|
+
type: ConsultancySchema.requestMatches,
|
|
119
|
+
location: matchesLocation,
|
|
120
|
+
name: request.name || request.id,
|
|
121
|
+
workspaceId,
|
|
122
|
+
content,
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Rank the given requests against stored resume vectors and save a match document each.
|
|
128
|
+
*/
|
|
129
|
+
export async function scoreRequests (sdk, { workspaceId, requests, resumes, existing }) {
|
|
130
|
+
const stored = await loadWorkspaceEmbeddings(workspaceId)
|
|
131
|
+
const vectorById = new Map((stored || []).map((item) => [item.resourceId, item.vector]))
|
|
132
|
+
const saved = []
|
|
133
|
+
for (const request of requests) {
|
|
134
|
+
const matches = rankMatches({
|
|
135
|
+
request,
|
|
136
|
+
resumes,
|
|
137
|
+
similarities: similaritiesFor(vectorById.get(request.id), resumes, vectorById),
|
|
138
|
+
})
|
|
139
|
+
saved.push(await saveMatches(sdk, { workspaceId, request, matches, existing }))
|
|
140
|
+
}
|
|
141
|
+
return saved
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Keep embeddings and saved matches current.
|
|
146
|
+
*
|
|
147
|
+
* A request or resume change embeds that document. A profile or experience
|
|
148
|
+
* change embeds the resumes that link it. A schedule pass embeds anything
|
|
149
|
+
* that has no current vector, then re-scores. Unchanged text is not embedded again.
|
|
150
|
+
*/
|
|
151
|
+
export async function run ({ event, payload, req, sdk }) {
|
|
152
|
+
if (!sdk?.invoke) fail('sdk is required', 500)
|
|
153
|
+
const workspaceId = workspaceIdFrom({ event, payload, req })
|
|
154
|
+
if (!workspaceId) fail('workspaceId is required', 400)
|
|
155
|
+
|
|
156
|
+
const requests = (await listAt(sdk, location, workspaceId))
|
|
157
|
+
.filter((item) => item?.type === ConsultancySchema.request)
|
|
158
|
+
const resumes = (await listAt(sdk, resumeLocation, workspaceId))
|
|
159
|
+
.filter((item) => item?.type === ResumesSchema.resume)
|
|
160
|
+
const existing = (await listAt(sdk, matchesLocation, workspaceId))
|
|
161
|
+
.filter((item) => item?.type === ConsultancySchema.requestMatches)
|
|
162
|
+
|
|
163
|
+
const resourceId = event?.resourceId || null
|
|
164
|
+
const type = event?.type
|
|
165
|
+
const scheduled = !resourceId || type === 'scheduled'
|
|
166
|
+
|
|
167
|
+
let toEmbed = []
|
|
168
|
+
let toScore = requests
|
|
169
|
+
if (scheduled) {
|
|
170
|
+
toEmbed = [...requests, ...resumes]
|
|
171
|
+
} else if (type === ConsultancySchema.request) {
|
|
172
|
+
toEmbed = requests.filter((item) => item.id === resourceId)
|
|
173
|
+
if (!toEmbed.length) {
|
|
174
|
+
const request = await readLinked(sdk, resourceId)
|
|
175
|
+
if (request?.type === ConsultancySchema.request) toEmbed = [request]
|
|
176
|
+
}
|
|
177
|
+
toScore = toEmbed
|
|
178
|
+
} else if (type === ResumesSchema.resume) {
|
|
179
|
+
toEmbed = resumes.filter((item) => item.id === resourceId)
|
|
180
|
+
if (!toEmbed.length) {
|
|
181
|
+
const resume = await readLinked(sdk, resourceId)
|
|
182
|
+
if (resume?.type === ResumesSchema.resume) toEmbed = [resume]
|
|
183
|
+
}
|
|
184
|
+
} else if (type === PROFILE_SCHEMA || type === ResumesSchema.resumeExperience) {
|
|
185
|
+
toEmbed = resumesLinking(resumes, resourceId)
|
|
186
|
+
if (!toEmbed.length) toScore = []
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
let embedded = 0
|
|
190
|
+
for (const resource of toEmbed) {
|
|
191
|
+
if (await ensureEmbedded(sdk, resource, workspaceId)) embedded += 1
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const saved = await scoreRequests(sdk, { workspaceId, requests: toScore, resumes, existing })
|
|
195
|
+
return { embedded, requests: saved.length }
|
|
196
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, jest } from '@jest/globals'
|
|
2
|
+
|
|
3
|
+
const getEmbedding = jest.fn()
|
|
4
|
+
const loadWorkspaceEmbeddings = jest.fn()
|
|
5
|
+
|
|
6
|
+
jest.unstable_mockModule('@ossy/platform/vector/vector-store', () => ({
|
|
7
|
+
getEmbedding,
|
|
8
|
+
loadWorkspaceEmbeddings,
|
|
9
|
+
cosineSimilarity: (a, b) => (a[0] === b[0] ? 0.8 : 0.1),
|
|
10
|
+
}))
|
|
11
|
+
|
|
12
|
+
const { run } = await import('./refresh-matches.task.js')
|
|
13
|
+
|
|
14
|
+
const GetResource = { id: '@ossy/resources/actions/get' }
|
|
15
|
+
const ListResources = { id: '@ossy/resources/actions/list' }
|
|
16
|
+
const CreateResource = { id: '@ossy/resources/actions/create' }
|
|
17
|
+
const EmbedResource = { id: '@ossy/media-tasks/actions/embed-resource' }
|
|
18
|
+
|
|
19
|
+
const request = {
|
|
20
|
+
id: 'request-1',
|
|
21
|
+
type: '@ossy/consultancy/schema/request',
|
|
22
|
+
name: 'Senior React consultant',
|
|
23
|
+
content: { title: 'Senior React consultant', tags: ['React', 'Node.js'] },
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const resume = {
|
|
27
|
+
id: 'resume-1',
|
|
28
|
+
type: '@ossy/resumes/schema/resume',
|
|
29
|
+
name: 'React consultant',
|
|
30
|
+
content: {
|
|
31
|
+
tags: ['React', 'Node.js'],
|
|
32
|
+
profile: { resourceId: 'profile-1' },
|
|
33
|
+
experiences: [],
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const profile = {
|
|
38
|
+
id: 'profile-1',
|
|
39
|
+
type: '@ossy/profile/schema/profile',
|
|
40
|
+
content: { name: 'Ada Consultant', role: 'Senior React consultant' },
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function sdkFor () {
|
|
44
|
+
const embedded = []
|
|
45
|
+
const created = []
|
|
46
|
+
return {
|
|
47
|
+
embedded,
|
|
48
|
+
created,
|
|
49
|
+
invoke: jest.fn(async (action, payload) => {
|
|
50
|
+
if (action.id === ListResources.id) {
|
|
51
|
+
if (payload.location === '/@ossy/consultancy/') return [request]
|
|
52
|
+
if (payload.location === '/@ossy/resumes/') return [resume]
|
|
53
|
+
return []
|
|
54
|
+
}
|
|
55
|
+
if (action.id === GetResource.id) return profile
|
|
56
|
+
if (action.id === EmbedResource.id) {
|
|
57
|
+
embedded.push(payload)
|
|
58
|
+
return { ok: true }
|
|
59
|
+
}
|
|
60
|
+
if (action.id === CreateResource.id) {
|
|
61
|
+
created.push(payload)
|
|
62
|
+
return { id: 'match-1', content: payload.content }
|
|
63
|
+
}
|
|
64
|
+
throw new Error(action.id)
|
|
65
|
+
}),
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
describe('refresh-matches task', () => {
|
|
70
|
+
beforeEach(() => {
|
|
71
|
+
getEmbedding.mockReset()
|
|
72
|
+
loadWorkspaceEmbeddings.mockReset()
|
|
73
|
+
getEmbedding.mockResolvedValue(null)
|
|
74
|
+
loadWorkspaceEmbeddings.mockResolvedValue([
|
|
75
|
+
{ resourceId: 'request-1', vector: [1] },
|
|
76
|
+
{ resourceId: 'resume-1', vector: [1] },
|
|
77
|
+
])
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('embeds a new request and saves its matches without embedding resumes', async () => {
|
|
81
|
+
const sdk = sdkFor()
|
|
82
|
+
const result = await run({
|
|
83
|
+
event: {
|
|
84
|
+
resourceId: 'request-1',
|
|
85
|
+
type: '@ossy/consultancy/schema/request',
|
|
86
|
+
event: 'Created',
|
|
87
|
+
payload: { belongsTo: 'ws-1' },
|
|
88
|
+
},
|
|
89
|
+
sdk,
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
expect(sdk.embedded.map((item) => item.resourceId)).toEqual(['request-1'])
|
|
93
|
+
expect(sdk.embedded[0].textHash).toEqual(expect.any(String))
|
|
94
|
+
expect(sdk.created[0].type).toBe('@ossy/consultancy/schema/request-matches')
|
|
95
|
+
expect(sdk.created[0].content.matches[0]).toMatchObject({
|
|
96
|
+
resourceId: 'resume-1',
|
|
97
|
+
shared: ['React', 'Node.js'],
|
|
98
|
+
})
|
|
99
|
+
expect(result.embedded).toBe(1)
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('skips embed when the stored hash is still current', async () => {
|
|
103
|
+
const sdk = sdkFor()
|
|
104
|
+
getEmbedding.mockImplementation(async (resourceId) => {
|
|
105
|
+
const { textHash } = await import('./refresh-matches.js')
|
|
106
|
+
const { requestMatchText, resumeMatchText } = await import('./match-resumes.js')
|
|
107
|
+
const text = resourceId === 'request-1'
|
|
108
|
+
? requestMatchText(request)
|
|
109
|
+
: resumeMatchText(resume, { profile, experiences: [] })
|
|
110
|
+
return { textHash: textHash(text) }
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
const result = await run({
|
|
114
|
+
event: { type: 'scheduled' },
|
|
115
|
+
payload: { workspaceId: 'ws-1' },
|
|
116
|
+
sdk,
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
expect(sdk.embedded).toEqual([])
|
|
120
|
+
expect(result.embedded).toBe(0)
|
|
121
|
+
expect(sdk.created).toHaveLength(1)
|
|
122
|
+
})
|
|
123
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ConsultancySchema } from './schema-ids.js'
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
id: ConsultancySchema.requestMatches,
|
|
5
|
+
name: 'Request matches',
|
|
6
|
+
description: 'Resumes ranked against one consultancy request',
|
|
7
|
+
categoryName: 'Consultancy',
|
|
8
|
+
icon: 'document',
|
|
9
|
+
fields: [
|
|
10
|
+
{ name: 'request', type: 'reference', of: ConsultancySchema.request, required: true },
|
|
11
|
+
{ name: 'matches', type: 'json', description: 'Ranked resumes: resourceId, name, tags, shared, tagScore, similarity, score' },
|
|
12
|
+
],
|
|
13
|
+
}
|
package/src/request.schema.js
CHANGED
|
@@ -15,7 +15,7 @@ export default {
|
|
|
15
15
|
{ name: 'title', type: 'text', required: true, description: 'Assignment title' },
|
|
16
16
|
{ name: 'summary', type: 'textarea', description: 'What the client is asking for' },
|
|
17
17
|
{ name: 'role', type: 'text', description: 'Profile they are looking for' },
|
|
18
|
-
{ name: '
|
|
18
|
+
{ name: 'tags', type: 'tags', description: 'JSON array of skills or technologies named in the request. One string per item. Omit when the message names none.' },
|
|
19
19
|
{ name: 'location', type: 'text', description: 'Where the work happens' },
|
|
20
20
|
{ name: 'duration', type: 'text', description: 'How long the assignment lasts, in the message\'s own words' },
|
|
21
21
|
{ name: 'start', type: 'text', description: 'When the assignment starts, in the message\'s own words' },
|
package/src/requests.page.jsx
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
+
import { useLocale } from '@ossy/design-system'
|
|
2
3
|
import { ConsultancyRecordPage } from './ConsultancyRecordList.jsx'
|
|
4
|
+
import { RequestMatches } from './RequestMatches.jsx'
|
|
3
5
|
import { ConsultancySchema } from './schema-ids.js'
|
|
4
6
|
import requestSchema from './request.schema.js'
|
|
5
7
|
|
|
@@ -11,16 +13,24 @@ export const metadata = {
|
|
|
11
13
|
},
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
export const RequestsPage = () =>
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
export const RequestsPage = () => {
|
|
17
|
+
const { t } = useLocale()
|
|
18
|
+
return (
|
|
19
|
+
<ConsultancyRecordPage
|
|
20
|
+
active="consultancy/requests"
|
|
21
|
+
title="consultancy.requests.title"
|
|
22
|
+
description="consultancy.requests.description"
|
|
23
|
+
schemaId={ConsultancySchema.request}
|
|
24
|
+
icon={requestSchema.icon}
|
|
25
|
+
listHeader="consultancy.nav.requests"
|
|
26
|
+
emptyText="consultancy.requests.empty"
|
|
27
|
+
extraPanels={[{
|
|
28
|
+
id: 'panel-request-matches',
|
|
29
|
+
label: t('consultancy.matches.title'),
|
|
30
|
+
content: RequestMatches,
|
|
31
|
+
}]}
|
|
32
|
+
/>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
25
35
|
|
|
26
36
|
export default RequestsPage
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import React, { useMemo, useRef } from 'react'
|
|
2
|
+
import { DropZone, Icon, List, Page, Tags, Text, View } from '@ossy/design-system'
|
|
3
|
+
import { AsyncStatus } from '@ossy/sdk-react'
|
|
4
|
+
import { useRouter } from '@ossy/router-react'
|
|
5
|
+
import { ListPanelLayout, listPanelPageProps } from '@ossy/resources'
|
|
6
|
+
import {
|
|
7
|
+
ResumeFileInput,
|
|
8
|
+
ResumeImportMenuItem,
|
|
9
|
+
ResumeImportStatus,
|
|
10
|
+
useImportResumes,
|
|
11
|
+
useResumes,
|
|
12
|
+
} from '@ossy/resumes'
|
|
13
|
+
import { ConsultancyNav } from './ConsultancyNav.jsx'
|
|
14
|
+
import { CreateConsultancyButton } from './CreateConsultancyButton.jsx'
|
|
15
|
+
import { Definition } from './Definition.js'
|
|
16
|
+
|
|
17
|
+
export const metadata = {
|
|
18
|
+
id: 'consultancy/resumes',
|
|
19
|
+
path: {
|
|
20
|
+
sv: '/konsultverksamhet/cv',
|
|
21
|
+
en: '/consultancy/resumes',
|
|
22
|
+
},
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function resumeLabel (resource) {
|
|
26
|
+
const name = resource?.name || resource?.content?.name
|
|
27
|
+
if (typeof name === 'string' && name.trim()) return name.trim()
|
|
28
|
+
return resource?.id || ''
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function resumeTags (resource) {
|
|
32
|
+
const value = resource?.content?.tags
|
|
33
|
+
if (!Array.isArray(value)) return ''
|
|
34
|
+
return value
|
|
35
|
+
.filter((item) => typeof item === 'string' && item.trim())
|
|
36
|
+
.join(', ')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const ConsultancyResumesPage = () => {
|
|
40
|
+
const router = useRouter()
|
|
41
|
+
const fileRef = useRef(null)
|
|
42
|
+
const { jobs, importFiles, busy } = useImportResumes()
|
|
43
|
+
const { resumes, status } = useResumes()
|
|
44
|
+
const statusTags = (Definition.status ?? [])
|
|
45
|
+
.map((item) => ({ beta: 'Beta', 'coming-soon': 'Coming Soon' }[item]))
|
|
46
|
+
.filter(Boolean)
|
|
47
|
+
|
|
48
|
+
const rows = useMemo(() => (
|
|
49
|
+
[...resumes].sort((a, b) => resumeLabel(a).localeCompare(resumeLabel(b)))
|
|
50
|
+
), [resumes])
|
|
51
|
+
|
|
52
|
+
const loading = status === AsyncStatus.Loading || status === AsyncStatus.NotInitialized
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<Page
|
|
56
|
+
{...listPanelPageProps}
|
|
57
|
+
title="consultancy.resumes.title"
|
|
58
|
+
near={statusTags.length > 0 ? <Tags tags={statusTags} size="s" /> : undefined}
|
|
59
|
+
description="consultancy.resumes.description"
|
|
60
|
+
far={(
|
|
61
|
+
<>
|
|
62
|
+
<ResumeFileInput inputRef={fileRef} onFiles={importFiles} />
|
|
63
|
+
<CreateConsultancyButton
|
|
64
|
+
before={(
|
|
65
|
+
<ResumeImportMenuItem busy={busy} onOpen={() => fileRef.current?.click()} />
|
|
66
|
+
)}
|
|
67
|
+
/>
|
|
68
|
+
</>
|
|
69
|
+
)}
|
|
70
|
+
>
|
|
71
|
+
<DropZone onFilesDrop={importFiles}>
|
|
72
|
+
<View gap="m" style={{ flex: '1 1 auto', height: '100%', minHeight: 0, display: 'flex', flexDirection: 'column' }}>
|
|
73
|
+
<ConsultancyNav active="consultancy/resumes" />
|
|
74
|
+
<ListPanelLayout
|
|
75
|
+
data-consultancy-resumes
|
|
76
|
+
listHeader="consultancy.nav.resumes"
|
|
77
|
+
style={{ flex: '1 1 auto', minHeight: 0 }}
|
|
78
|
+
list={loading ? (
|
|
79
|
+
<View inset="m">
|
|
80
|
+
<ResumeImportStatus jobs={jobs} />
|
|
81
|
+
<Text color="secondary" text="consultancy.records.loading" />
|
|
82
|
+
</View>
|
|
83
|
+
) : rows.length === 0 && jobs.length === 0 ? (
|
|
84
|
+
<View inset="m">
|
|
85
|
+
<Text color="secondary" text="consultancy.resumes.empty" />
|
|
86
|
+
</View>
|
|
87
|
+
) : (
|
|
88
|
+
<View>
|
|
89
|
+
<ResumeImportStatus jobs={jobs} />
|
|
90
|
+
<List>
|
|
91
|
+
{rows.map((resource) => {
|
|
92
|
+
const label = resumeLabel(resource)
|
|
93
|
+
const tags = resumeTags(resource)
|
|
94
|
+
return (
|
|
95
|
+
<List.Item
|
|
96
|
+
key={resource.id}
|
|
97
|
+
href={router.getHref({
|
|
98
|
+
id: '@resume',
|
|
99
|
+
params: { resumeId: resource.id, workspaceId: router.params.workspaceId },
|
|
100
|
+
})}
|
|
101
|
+
data-resource-name={label || undefined}
|
|
102
|
+
leading={(
|
|
103
|
+
<Icon size="s" name="document" style={{ fill: 'hsl(0, 0%, 80%)' }} />
|
|
104
|
+
)}
|
|
105
|
+
meta={tags ? <Text variant="small">{tags}</Text> : null}
|
|
106
|
+
>
|
|
107
|
+
{label}
|
|
108
|
+
</List.Item>
|
|
109
|
+
)
|
|
110
|
+
})}
|
|
111
|
+
</List>
|
|
112
|
+
</View>
|
|
113
|
+
)}
|
|
114
|
+
/>
|
|
115
|
+
</View>
|
|
116
|
+
</DropZone>
|
|
117
|
+
</Page>
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export default ConsultancyResumesPage
|
package/src/schema-ids.js
CHANGED
|
@@ -6,5 +6,6 @@ export const ConsultancySchema = Object.freeze({
|
|
|
6
6
|
vacation: '@ossy/consultancy/schema/vacation',
|
|
7
7
|
opportunity: '@ossy/consultancy/schema/opportunity',
|
|
8
8
|
request: '@ossy/consultancy/schema/request',
|
|
9
|
+
requestMatches: '@ossy/consultancy/schema/request-matches',
|
|
9
10
|
proposal: '@ossy/consultancy/schema/proposal',
|
|
10
11
|
})
|
package/src/sv.translations.json
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
"consultancy/contracts.documentTitle": "Avtal",
|
|
8
8
|
"consultancy/opportunities.documentTitle": "Möjligheter",
|
|
9
9
|
"consultancy/requests.documentTitle": "Förfrågningar",
|
|
10
|
+
"consultancy/resumes.documentTitle": "CV",
|
|
10
11
|
"consultancy/reports.documentTitle": "Rapporter",
|
|
11
12
|
"consultancy/proposals.documentTitle": "Offerter",
|
|
12
13
|
"consultancy.home.title": "Översikt",
|
|
@@ -20,6 +21,7 @@
|
|
|
20
21
|
"consultancy.nav.vacations": "Semester",
|
|
21
22
|
"consultancy.nav.contracts": "Avtal",
|
|
22
23
|
"consultancy.nav.requests": "Förfrågningar",
|
|
24
|
+
"consultancy.nav.resumes": "CV",
|
|
23
25
|
"consultancy.nav.opportunities": "Möjligheter",
|
|
24
26
|
"consultancy.nav.proposals": "Offerter",
|
|
25
27
|
"consultancy.nav.reports": "Rapporter",
|
|
@@ -75,6 +77,19 @@
|
|
|
75
77
|
"consultancy.requests.title": "Förfrågningar",
|
|
76
78
|
"consultancy.requests.description": "Uppdrag tolkade från inkommande e-post",
|
|
77
79
|
"consultancy.requests.empty": "Inga förfrågningar ännu.",
|
|
80
|
+
"consultancy.matches.title": "Matchande CV",
|
|
81
|
+
"consultancy.matches.loading": "Matchar CV…",
|
|
82
|
+
"consultancy.matches.empty": "Inga CV att matcha.",
|
|
83
|
+
"consultancy.matches.error": "Kunde inte matcha CV.",
|
|
84
|
+
"consultancy.matches.embeddingsUnavailable": "Visar överlappande taggar. Likhet är inte tillgänglig.",
|
|
85
|
+
"consultancy.matches.pending": "Matchningar tas fram när en förfrågan eller ett CV ändras.",
|
|
86
|
+
"@ossy/consultancy/actions/refresh-matches.label": "Uppdatera matchningar",
|
|
87
|
+
"@ossy/consultancy/actions/refresh-matches.description": "Bädda in ändrade förfrågningar och CV och spara deras matchningar",
|
|
88
|
+
"@ossy/consultancy/actions/match-resumes.label": "Matcha CV",
|
|
89
|
+
"@ossy/consultancy/actions/match-resumes.description": "Rangordna CV i den här workspacen mot en förfrågan efter delade taggar och likhet",
|
|
90
|
+
"consultancy.resumes.title": "CV",
|
|
91
|
+
"consultancy.resumes.description": "CV i den här workspacen, länkade till en profil och erfarenheter",
|
|
92
|
+
"consultancy.resumes.empty": "Inga CV ännu.",
|
|
78
93
|
"consultancy.requests.statsTitle": "Inkommande förfrågningar",
|
|
79
94
|
"consultancy.requests.statsSeries": "Förfrågningar",
|
|
80
95
|
"consultancy.requests.statsUnit": "förfrågningar",
|
|
@@ -171,8 +186,8 @@
|
|
|
171
186
|
"@ossy/consultancy/schema/request.summary.description": "Vad kunden frågar efter.",
|
|
172
187
|
"@ossy/consultancy/schema/request.role.label": "Roll",
|
|
173
188
|
"@ossy/consultancy/schema/request.role.description": "Profilen de söker.",
|
|
174
|
-
"@ossy/consultancy/schema/request.
|
|
175
|
-
"@ossy/consultancy/schema/request.
|
|
189
|
+
"@ossy/consultancy/schema/request.tags.label": "Kompetenser",
|
|
190
|
+
"@ossy/consultancy/schema/request.tags.description": "Kompetenser eller tekniker som nämns.",
|
|
176
191
|
"@ossy/consultancy/schema/request.location.label": "Plats",
|
|
177
192
|
"@ossy/consultancy/schema/request.location.description": "Var arbetet sker.",
|
|
178
193
|
"@ossy/consultancy/schema/request.duration.label": "Längd",
|