@ossy/consultancy 3.22.0 → 3.24.0
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 +5 -3
- package/src/ConsultancyNav.jsx +4 -0
- package/src/ConsultancyRecordList.jsx +11 -2
- package/src/CreateConsultancyButton.jsx +3 -2
- package/src/Forecast.jsx +3 -53
- package/src/MonthDayGrid.jsx +68 -0
- package/src/RequestMatches.jsx +52 -0
- package/src/current-month.component.jsx +10 -6
- package/src/en.translations.json +41 -0
- package/src/extract-request.task.js +21 -4
- package/src/extract-request.task.spec.js +44 -2
- 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/resume-inbound-screening.task.js +77 -0
- package/src/resume-inbound-screening.task.spec.js +68 -0
- package/src/resumes.page.jsx +121 -0
- package/src/schema-ids.js +1 -0
- package/src/screen-inbound.task.js +63 -14
- package/src/screen-inbound.task.spec.js +59 -2
- package/src/sv.translations.json +41 -0
- package/src/utilization-hours.js +21 -3
- package/src/utilization-hours.spec.js +23 -0
|
@@ -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,77 @@
|
|
|
1
|
+
import { run as screenInbound } from './screen-inbound.task.js'
|
|
2
|
+
import { acceptsRequestCategory } from './intake-categories.js'
|
|
3
|
+
|
|
4
|
+
const ListResources = { id: '@ossy/resources/actions/list' }
|
|
5
|
+
const INBOUND_MESSAGE = '@ossy/email/schema/inbound-message'
|
|
6
|
+
const INBOUND_LOCATION = '/@ossy/email/inbound/'
|
|
7
|
+
const MAX_AGE_MS = 14 * 24 * 60 * 60 * 1000
|
|
8
|
+
const MAX_PER_PASS = 20
|
|
9
|
+
|
|
10
|
+
export const metadata = {
|
|
11
|
+
id: '@ossy/consultancy/tasks/resume-inbound-screening',
|
|
12
|
+
schedule: '*/5 * * * *',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function asResourceList (result) {
|
|
16
|
+
if (Array.isArray(result)) return result
|
|
17
|
+
if (Array.isArray(result?.items)) return result.items
|
|
18
|
+
return []
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A message still needs screening when it has no request and no finished
|
|
23
|
+
* intake label. A confident request label with no request means extraction
|
|
24
|
+
* died and should be run again.
|
|
25
|
+
*
|
|
26
|
+
* @param {object | null | undefined} resource
|
|
27
|
+
* @param {number} [now]
|
|
28
|
+
*/
|
|
29
|
+
export function needsInboundScreening (resource, now = Date.now()) {
|
|
30
|
+
if (resource?.type !== INBOUND_MESSAGE) return false
|
|
31
|
+
const content = resource.content && typeof resource.content === 'object' ? resource.content : {}
|
|
32
|
+
if (content.requestId) return false
|
|
33
|
+
const received = Date.parse(content.receivedAt || '')
|
|
34
|
+
if (!Number.isNaN(received) && now - received > MAX_AGE_MS) return false
|
|
35
|
+
if (!Object.hasOwn(content, 'intakeCategory')) return true
|
|
36
|
+
return acceptsRequestCategory({
|
|
37
|
+
category: content.intakeCategory,
|
|
38
|
+
confidence: content.intakeConfidence,
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Finish inbound mail whose screening was interrupted. One pass per workspace.
|
|
44
|
+
*/
|
|
45
|
+
export async function run ({ payload, req, sdk, log }) {
|
|
46
|
+
if (!sdk?.invoke) throw Object.assign(new Error('sdk is required'), { status: 500 })
|
|
47
|
+
|
|
48
|
+
const workspaceId = payload?.workspaceId || req?.workspaceId
|
|
49
|
+
if (!workspaceId) throw Object.assign(new Error('workspaceId is required'), { status: 400 })
|
|
50
|
+
|
|
51
|
+
const listed = await sdk.invoke(ListResources, {
|
|
52
|
+
location: INBOUND_LOCATION,
|
|
53
|
+
workspaceId,
|
|
54
|
+
})
|
|
55
|
+
const pending = asResourceList(listed)
|
|
56
|
+
.filter((resource) => needsInboundScreening(resource))
|
|
57
|
+
.slice(0, MAX_PER_PASS)
|
|
58
|
+
|
|
59
|
+
let screened = 0
|
|
60
|
+
let failed = 0
|
|
61
|
+
for (const message of pending) {
|
|
62
|
+
try {
|
|
63
|
+
await screenInbound({
|
|
64
|
+
event: { resourceId: message.id, payload: { belongsTo: workspaceId } },
|
|
65
|
+
payload: { resourceId: message.id, workspaceId },
|
|
66
|
+
req,
|
|
67
|
+
sdk,
|
|
68
|
+
})
|
|
69
|
+
screened += 1
|
|
70
|
+
} catch (error) {
|
|
71
|
+
failed += 1
|
|
72
|
+
log?.error('[consultancy/tasks/resume-inbound-screening] message failed', { resourceId: message.id }, error)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return { screened, failed }
|
|
77
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { metadata, needsInboundScreening, run } from './resume-inbound-screening.task.js'
|
|
2
|
+
import { REQUEST_CATEGORY } from './intake-categories.js'
|
|
3
|
+
|
|
4
|
+
const message = {
|
|
5
|
+
id: 'msg-1',
|
|
6
|
+
type: '@ossy/email/schema/inbound-message',
|
|
7
|
+
content: {
|
|
8
|
+
from: 'client@studio.se',
|
|
9
|
+
subject: 'SDK',
|
|
10
|
+
text: 'Vi behöver en specialist.',
|
|
11
|
+
receivedAt: '2026-10-17T17:56:46.000Z',
|
|
12
|
+
},
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe('resume-inbound-screening', () => {
|
|
16
|
+
it('runs every five minutes', () => {
|
|
17
|
+
expect(metadata.schedule).toBe('*/5 * * * *')
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('selects mail that never finished screening', () => {
|
|
21
|
+
const now = Date.parse('2026-10-17T19:00:00.000Z')
|
|
22
|
+
expect(needsInboundScreening(message, now)).toBe(true)
|
|
23
|
+
expect(needsInboundScreening({
|
|
24
|
+
...message,
|
|
25
|
+
content: { ...message.content, intakeCategory: 'contact', intakeConfidence: 0.9 },
|
|
26
|
+
}, now)).toBe(false)
|
|
27
|
+
expect(needsInboundScreening({
|
|
28
|
+
...message,
|
|
29
|
+
content: { ...message.content, intakeCategory: REQUEST_CATEGORY, intakeConfidence: 1 },
|
|
30
|
+
}, now)).toBe(true)
|
|
31
|
+
expect(needsInboundScreening({
|
|
32
|
+
...message,
|
|
33
|
+
content: { ...message.content, requestId: 'request-1' },
|
|
34
|
+
}, now)).toBe(false)
|
|
35
|
+
expect(needsInboundScreening({
|
|
36
|
+
...message,
|
|
37
|
+
content: { ...message.content, receivedAt: '2026-01-01T00:00:00.000Z' },
|
|
38
|
+
}, now)).toBe(false)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('screens only the unfinished message', async () => {
|
|
42
|
+
const calls = []
|
|
43
|
+
const settled = {
|
|
44
|
+
...message,
|
|
45
|
+
id: 'msg-settled',
|
|
46
|
+
content: { ...message.content, intakeCategory: 'contact', intakeConfidence: 1 },
|
|
47
|
+
}
|
|
48
|
+
const sdk = {
|
|
49
|
+
async invoke (action, payload) {
|
|
50
|
+
calls.push({ id: action.id, payload })
|
|
51
|
+
if (action.id === '@ossy/resources/actions/list') return [settled, message]
|
|
52
|
+
if (action.id === '@ossy/resources/actions/get') return message
|
|
53
|
+
if (action.id === '@ossy/media-tasks/actions/categorize') return { category: 'contact', confidence: 0.95 }
|
|
54
|
+
if (action.id === '@ossy/resources/actions/update-content') return { ...message, content: payload.content }
|
|
55
|
+
throw new Error(`unexpected ${action.id}`)
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const result = await run({
|
|
60
|
+
payload: { workspaceId: 'ws-1' },
|
|
61
|
+
sdk,
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
expect(result).toEqual({ screened: 1, failed: 0 })
|
|
65
|
+
const gets = calls.filter((call) => call.id === '@ossy/resources/actions/get')
|
|
66
|
+
expect(gets.map((call) => call.payload.resourceId)).toEqual(['msg-1'])
|
|
67
|
+
})
|
|
68
|
+
})
|
|
@@ -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
|
})
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { forwardedOriginalFromMessage } from '@ossy/email/forwarded-original'
|
|
1
2
|
import { location } from './locations.js'
|
|
2
3
|
import { ConsultancySchema } from './schema-ids.js'
|
|
3
4
|
import { requestSourceText } from './extract-request.task.js'
|
|
@@ -7,6 +8,7 @@ import {
|
|
|
7
8
|
} from './intake-categories.js'
|
|
8
9
|
|
|
9
10
|
const GetResource = { id: '@ossy/resources/actions/get' }
|
|
11
|
+
const UpdateContent = { id: '@ossy/resources/actions/update-content' }
|
|
10
12
|
const Categorize = { id: '@ossy/media-tasks/actions/categorize' }
|
|
11
13
|
const ExtractRequest = { id: '@ossy/consultancy/actions/extract-request' }
|
|
12
14
|
const INBOUND_MESSAGE = '@ossy/email/schema/inbound-message'
|
|
@@ -41,9 +43,37 @@ function workspaceIdFrom ({ event, payload, req }) {
|
|
|
41
43
|
?? null
|
|
42
44
|
}
|
|
43
45
|
|
|
46
|
+
async function saveContent (sdk, resource, workspaceId, patch) {
|
|
47
|
+
const content = { ...resource.content, ...patch }
|
|
48
|
+
const updated = await sdk.invoke(UpdateContent, {
|
|
49
|
+
resourceId: resource.id,
|
|
50
|
+
workspaceId,
|
|
51
|
+
content,
|
|
52
|
+
})
|
|
53
|
+
return updated?.content ? updated : { ...resource, content }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A forward stores the person who clicked forward as From. Replace that with
|
|
58
|
+
* the sender inside the forwarded block, and remember who forwarded it.
|
|
59
|
+
*/
|
|
60
|
+
async function withOriginalSender (sdk, resource, workspaceId) {
|
|
61
|
+
const content = resource?.content && typeof resource.content === 'object' ? resource.content : {}
|
|
62
|
+
if (content.forwardedBy) return resource
|
|
63
|
+
const forward = forwardedOriginalFromMessage(content)
|
|
64
|
+
if (!forward?.from) return resource
|
|
65
|
+
return saveContent(sdk, resource, workspaceId, {
|
|
66
|
+
from: forward.from,
|
|
67
|
+
forwardedBy: content.from || '',
|
|
68
|
+
...(forward.subject ? { subject: forward.subject } : {}),
|
|
69
|
+
...(forward.receivedAt ? { receivedAt: forward.receivedAt } : {}),
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
44
73
|
/**
|
|
45
74
|
* New inbound mail is categorized first. A consultancy request is extracted.
|
|
46
|
-
*
|
|
75
|
+
* The outcome is stored on the message so a later pass can finish a run that
|
|
76
|
+
* died before the request was saved. Anything else stays in the inbox.
|
|
47
77
|
*/
|
|
48
78
|
export async function run ({ event, payload, req, sdk }) {
|
|
49
79
|
if (!sdk?.invoke) fail('sdk is required', 500)
|
|
@@ -54,31 +84,50 @@ export async function run ({ event, payload, req, sdk }) {
|
|
|
54
84
|
const workspaceId = workspaceIdFrom({ event, payload, req })
|
|
55
85
|
if (!workspaceId) fail('workspaceId is required', 400)
|
|
56
86
|
|
|
57
|
-
|
|
87
|
+
let resource = await sdk.invoke(GetResource, { resourceId })
|
|
58
88
|
if (resource?.type !== INBOUND_MESSAGE) fail('inbound message is required', 400)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (!text) {
|
|
62
|
-
return { skipped: true, reason: 'empty', category: null, confidence: null }
|
|
89
|
+
if (resource.content?.requestId) {
|
|
90
|
+
return { skipped: false, requestId: resource.content.requestId, category: resource.content.intakeCategory ?? null }
|
|
63
91
|
}
|
|
64
92
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
93
|
+
resource = await withOriginalSender(sdk, resource, workspaceId)
|
|
94
|
+
|
|
95
|
+
const alreadyScreened = Object.hasOwn(resource.content ?? {}, 'intakeCategory')
|
|
96
|
+
let category = typeof resource.content?.intakeCategory === 'string' ? resource.content.intakeCategory : null
|
|
97
|
+
let confidence = typeof resource.content?.intakeConfidence === 'number' ? resource.content.intakeConfidence : null
|
|
98
|
+
|
|
99
|
+
if (!alreadyScreened) {
|
|
100
|
+
const text = requestSourceText(resource)
|
|
101
|
+
if (!text) {
|
|
102
|
+
return { skipped: true, reason: 'empty', category: null, confidence: null }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const categorized = await sdk.invoke(Categorize, {
|
|
106
|
+
workspaceId,
|
|
107
|
+
text,
|
|
108
|
+
categories: INTAKE_CATEGORIES,
|
|
109
|
+
})
|
|
110
|
+
category = typeof categorized?.category === 'string' ? categorized.category : null
|
|
111
|
+
confidence = typeof categorized?.confidence === 'number' ? categorized.confidence : null
|
|
112
|
+
resource = await saveContent(sdk, resource, workspaceId, {
|
|
113
|
+
intakeCategory: category,
|
|
114
|
+
intakeConfidence: confidence,
|
|
115
|
+
})
|
|
116
|
+
}
|
|
70
117
|
|
|
71
|
-
const category = typeof categorized?.category === 'string' ? categorized.category : null
|
|
72
|
-
const confidence = typeof categorized?.confidence === 'number' ? categorized.confidence : null
|
|
73
118
|
if (!acceptsRequestCategory({ category, confidence })) {
|
|
74
119
|
return { skipped: true, reason: 'category', category, confidence }
|
|
75
120
|
}
|
|
76
121
|
|
|
77
122
|
const request = await sdk.invoke(ExtractRequest, { resourceId, workspaceId })
|
|
123
|
+
const requestId = request?.id ?? null
|
|
124
|
+
if (requestId) {
|
|
125
|
+
await saveContent(sdk, resource, workspaceId, { requestId })
|
|
126
|
+
}
|
|
78
127
|
return {
|
|
79
128
|
skipped: false,
|
|
80
129
|
category,
|
|
81
130
|
confidence,
|
|
82
|
-
requestId
|
|
131
|
+
requestId,
|
|
83
132
|
}
|
|
84
133
|
}
|
|
@@ -3,6 +3,7 @@ import { INTAKE_CATEGORIES, REQUEST_CATEGORY } from './intake-categories.js'
|
|
|
3
3
|
import { requestSourceText } from './extract-request.task.js'
|
|
4
4
|
|
|
5
5
|
const GetResource = { id: '@ossy/resources/actions/get' }
|
|
6
|
+
const UpdateContent = { id: '@ossy/resources/actions/update-content' }
|
|
6
7
|
const Categorize = { id: '@ossy/media-tasks/actions/categorize' }
|
|
7
8
|
const ExtractRequest = { id: '@ossy/consultancy/actions/extract-request' }
|
|
8
9
|
|
|
@@ -17,12 +18,17 @@ const inbound = {
|
|
|
17
18
|
},
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
function sdkFor (categorized) {
|
|
21
|
+
function sdkFor (categorized, source = inbound) {
|
|
22
|
+
let current = { ...source, content: { ...source.content } }
|
|
21
23
|
const calls = []
|
|
22
24
|
const sdk = {
|
|
23
25
|
async invoke (action, payload) {
|
|
24
26
|
calls.push({ id: action.id, payload })
|
|
25
|
-
if (action.id === GetResource.id) return
|
|
27
|
+
if (action.id === GetResource.id) return current
|
|
28
|
+
if (action.id === UpdateContent.id) {
|
|
29
|
+
current = { ...current, content: payload.content }
|
|
30
|
+
return current
|
|
31
|
+
}
|
|
26
32
|
if (action.id === Categorize.id) return categorized
|
|
27
33
|
if (action.id === ExtractRequest.id) return { id: 'request-1' }
|
|
28
34
|
throw new Error(`unexpected ${action.id}`)
|
|
@@ -54,12 +60,15 @@ describe('screen-inbound task', () => {
|
|
|
54
60
|
expect(calls.map((call) => call.id)).toEqual([
|
|
55
61
|
GetResource.id,
|
|
56
62
|
Categorize.id,
|
|
63
|
+
UpdateContent.id,
|
|
57
64
|
ExtractRequest.id,
|
|
65
|
+
UpdateContent.id,
|
|
58
66
|
])
|
|
59
67
|
expect(calls.find((call) => call.id === ExtractRequest.id).payload).toEqual({
|
|
60
68
|
resourceId: inbound.id,
|
|
61
69
|
workspaceId: 'ws-1',
|
|
62
70
|
})
|
|
71
|
+
expect(calls.filter((call) => call.id === UpdateContent.id).at(-1).payload.content.requestId).toBe('request-1')
|
|
63
72
|
expect(result).toEqual({
|
|
64
73
|
skipped: false,
|
|
65
74
|
category: REQUEST_CATEGORY,
|
|
@@ -76,6 +85,7 @@ describe('screen-inbound task', () => {
|
|
|
76
85
|
})
|
|
77
86
|
|
|
78
87
|
expect(calls.map((call) => call.id)).not.toContain(ExtractRequest.id)
|
|
88
|
+
expect(calls.find((call) => call.id === UpdateContent.id).payload.content.intakeCategory).toBe('contact')
|
|
79
89
|
expect(result).toEqual({
|
|
80
90
|
skipped: true,
|
|
81
91
|
reason: 'category',
|
|
@@ -94,4 +104,51 @@ describe('screen-inbound task', () => {
|
|
|
94
104
|
expect(calls.map((call) => call.id)).not.toContain(ExtractRequest.id)
|
|
95
105
|
expect(result).toMatchObject({ skipped: true, reason: 'category', confidence: 0.4 })
|
|
96
106
|
})
|
|
107
|
+
|
|
108
|
+
it('extracts again when a confident label was saved and the request was not', async () => {
|
|
109
|
+
const { calls, sdk } = sdkFor(null, {
|
|
110
|
+
...inbound,
|
|
111
|
+
content: {
|
|
112
|
+
...inbound.content,
|
|
113
|
+
intakeCategory: REQUEST_CATEGORY,
|
|
114
|
+
intakeConfidence: 1,
|
|
115
|
+
},
|
|
116
|
+
})
|
|
117
|
+
const result = await run({
|
|
118
|
+
event: { resourceId: inbound.id, payload: { belongsTo: 'ws-1' } },
|
|
119
|
+
sdk,
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
expect(calls.map((call) => call.id)).not.toContain(Categorize.id)
|
|
123
|
+
expect(calls.map((call) => call.id)).toContain(ExtractRequest.id)
|
|
124
|
+
expect(result.requestId).toBe('request-1')
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it('stores the original sender before screening a forward', async () => {
|
|
128
|
+
const { calls, sdk } = sdkFor({ category: 'contact', confidence: 0.99 }, {
|
|
129
|
+
...inbound,
|
|
130
|
+
content: {
|
|
131
|
+
...inbound.content,
|
|
132
|
+
from: 'oskars.sylwan@ossy.se',
|
|
133
|
+
subject: 'Fwd: Senior React',
|
|
134
|
+
text: [
|
|
135
|
+
'---------- Forwarded message ---------',
|
|
136
|
+
'From: Recruiter <recruiter@client.se>',
|
|
137
|
+
'Subject: Senior React',
|
|
138
|
+
'',
|
|
139
|
+
'Vi soker en senior React-utvecklare i Stockholm.',
|
|
140
|
+
].join('\n'),
|
|
141
|
+
},
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
await run({
|
|
145
|
+
event: { resourceId: inbound.id, payload: { belongsTo: 'ws-1' } },
|
|
146
|
+
sdk,
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
const firstSave = calls.find((call) => call.id === UpdateContent.id)
|
|
150
|
+
expect(firstSave.payload.content.from).toBe('recruiter@client.se')
|
|
151
|
+
expect(firstSave.payload.content.forwardedBy).toBe('oskars.sylwan@ossy.se')
|
|
152
|
+
expect(firstSave.payload.content.subject).toBe('Senior React')
|
|
153
|
+
})
|
|
97
154
|
})
|