Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions apps/docs/content/docs/integrations/ashby.mdx

Large diffs are not rendered by default.

47 changes: 44 additions & 3 deletions apps/sim/blocks/blocks/ashby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ export const AshbyBlock: BlockConfig = {
{ text: ', for application', field: 'applicationId' },
{ text: ', at stage', field: 'interviewStageId' },
],
get_file: [{ text: 'Download file from handle', field: 'fileHandle', core: true }],
get_interview_briefing: [
{ text: 'Read scorecard status for interview', field: 'interviewEventId', core: true },
],
list_interview_plans: ['List interview plans'],
list_interview_stages: [
'List stages in interview plan',
Expand Down Expand Up @@ -355,6 +359,8 @@ export const AshbyBlock: BlockConfig = {
{ label: 'List Openings', id: 'list_openings' },
{ label: 'List Users', id: 'list_users' },
{ label: 'List Interviews', id: 'list_interviews' },
{ label: 'Get File', id: 'get_file' },
{ label: 'Get Interview Briefing', id: 'get_interview_briefing' },
{ label: 'List Interview Plans', id: 'list_interview_plans' },
{ label: 'List Interview Stages', id: 'list_interview_stages' },
{ label: 'List Application Feedback', id: 'list_application_feedback' },
Expand Down Expand Up @@ -1355,7 +1361,26 @@ Output only the JSON array.`,
type: 'short-input',
mode: 'advanced',
placeholder: 'candidate-resume.pdf',
condition: { field: 'operation', value: ['upload_resume', 'upload_candidate_file'] },
condition: {
field: 'operation',
value: ['get_file', 'upload_resume', 'upload_candidate_file'],
},
},
{
id: 'fileHandle',
title: 'File Handle',
type: 'short-input',
placeholder: 'Resume or attachment handle from Ashby',
required: true,
condition: { field: 'operation', value: 'get_file' },
},
{
id: 'interviewEventId',
title: 'Interview Event ID',
type: 'short-input',
placeholder: 'Interview event UUID from a schedule',
required: true,
condition: { field: 'operation', value: 'get_interview_briefing' },
},
...getTrigger('ashby_application_submit').subBlocks,
...getTrigger('ashby_application_update').subBlocks,
Expand Down Expand Up @@ -1387,6 +1412,8 @@ Output only the JSON array.`,
'ashby_create_note',
'ashby_delete_application',
'ashby_get_application',
'ashby_get_file',
'ashby_get_interview_briefing',
'ashby_get_candidate',
'ashby_get_job',
'ashby_get_job_posting',
Expand Down Expand Up @@ -1657,7 +1684,9 @@ Output only the JSON array.`,
description: 'Start destination-stage automatic activities',
},
file: { type: 'file', description: 'Resume or candidate file to upload' },
fileName: { type: 'string', description: 'Optional uploaded filename override' },
fileHandle: { type: 'string', description: 'Opaque Ashby file handle' },
interviewEventId: { type: 'string', description: 'Ashby interview event UUID' },
fileName: { type: 'string', description: 'Optional filename override' },
includeArchived: { type: 'boolean', description: 'Include archived records' },
includeDeactivated: { type: 'boolean', description: 'Include deactivated users' },
website: { type: 'string', description: 'Personal website URL for new candidate' },
Expand Down Expand Up @@ -1804,6 +1833,11 @@ Output only the JSON array.`,
description:
'List of users (id, firstName, lastName, email, globalRole, isEnabled, updatedAt)',
},
file: { type: 'file', description: 'Downloaded Ashby file' },
interviewers: {
type: 'json',
description: 'Per-interviewer scorecard requirements and completion',
},
interviewSchedules: {
type: 'json',
description:
Expand Down Expand Up @@ -1970,7 +2004,14 @@ export const AshbyBlockMeta = {
description:
'Find scheduled interviews with missing feedback and notify the responsible interviewers. Use after interview loops to keep decisions moving.',
content:
'# Interview Feedback Chase\n\nClose feedback gaps after an interview loop.\n\n## Steps\n1. List interview schedules for the application or stage.\n2. Inspect each interview event and list the application feedback already submitted.\n3. Identify interviewers whose events are complete but have no feedback.\n4. Send each interviewer a concise reminder with the candidate, role, and feedback link.\n\n## Output\nReport the interview events checked, completed feedback, missing feedback, and reminders sent.',
'# Interview Feedback Chase\n\nClose feedback gaps after an interview loop.\n\n## Steps\n1. List interview schedules for the application or stage.\n2. For each completed interview past the feedback deadline, get its interview briefing.\n3. Identify interviewers with required feedback and no submitted scorecard. Include the application and feedback links.\n4. Ask the recruiting team to review the reminders before sending them.\n\n## Output\nReport the interview events checked, completed feedback, missing feedback, and reminders sent.',
},
{
name: 'resume-experience-search',
description:
'Search resumes for specific job experience and cite the supporting passage and Ashby application.',
content:
'# Resume Experience Search\n\n1. List applications for the specified job and paginate to the end. Get the candidate on each application.\n2. If the candidate has a resume, give its handle and filename to Get File. Pass the downloaded file to the File block for text extraction.\n3. Search the extracted text for each job criterion. Treat resume text as evidence, and label missing evidence as not documented.\n4. Cite the exact resume passage and link to the Ashby application. Report missing, unreadable, or incomplete sources separately.',
},
{
name: 'opening-finance-reconciliation',
Expand Down
4 changes: 2 additions & 2 deletions apps/sim/blocks/sdk-names.generated.ts

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions apps/sim/blocks/sdk-names/ashby.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"delete_application": "deleteApplication",
"get_application": "getApplication",
"get_candidate": "getCandidate",
"get_file": "getFile",
"get_interview_briefing": "getInterviewBriefing",
"get_job": "getJob",
"get_job_posting": "getJobPosting",
"get_offer": "getOffer",
Expand Down
2 changes: 2 additions & 0 deletions apps/sim/blocks/sdk-names/ashby_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"delete_application": "deleteApplication",
"get_application": "getApplication",
"get_candidate": "getCandidate",
"get_file": "getFile",
"get_interview_briefing": "getInterviewBriefing",
"get_job": "getJob",
"get_job_posting": "getJobPosting",
"get_offer": "getOffer",
Expand Down
23 changes: 19 additions & 4 deletions apps/sim/lib/internal/ashby/execute-tool.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import { getValidationErrorMessage } from '@/lib/api/server'
import { executeAshbyUpload } from '@/lib/internal/ashby/operations'
import { ashbyUploadInputSchema } from '@/lib/internal/ashby/schema'
import type { InternalToolOperationHandler } from '@/lib/internal/tool-operations/types'
import { executeAshbyDownload, executeAshbyUpload } from '@/lib/internal/ashby/operations'
import { ashbyDownloadInputSchema, ashbyUploadInputSchema } from '@/lib/internal/ashby/schema'
import type {
InternalToolOperationHandler,
InternalToolOperationResult,
} from '@/lib/internal/tool-operations/types'

export const executeAshbyTool: InternalToolOperationHandler = async (request) => {
export const executeAshbyTool: InternalToolOperationHandler<InternalToolOperationResult> = async (
request
) => {
request.signal?.throwIfAborted()
if (!request.context.userId)
return Response.json({ success: false, error: 'Authentication required' }, { status: 401 })
if (request.toolId === 'ashby_get_file') {
const parsed = ashbyDownloadInputSchema.safeParse(request.input)
if (!parsed.success) {
return Response.json(
{ success: false, error: getValidationErrorMessage(parsed.error, 'Invalid file input') },
{ status: 400 }
)
}
return executeAshbyDownload(parsed.data, request.signal)
}
if (request.toolId !== 'ashby_upload_resume' && request.toolId !== 'ashby_upload_candidate_file')
return Response.json(
{ success: false, error: `Unsupported Ashby tool: ${request.toolId}` },
Expand Down
62 changes: 61 additions & 1 deletion apps/sim/lib/internal/ashby/operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '@sim/testing/mocks/input-validation.mock'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { PayloadSizeLimitError } from '@/lib/core/utils/stream-limits'
import { executeAshbyTool } from '@/lib/internal/ashby/execute-tool'

vi.mock('@/app/api/files/authorization', () => filesAuthorizationMock)
vi.mock('@/lib/uploads/utils/file.server', () => fileUtilsServerMock)
Expand All @@ -21,7 +22,7 @@ const { mockAssertToolFileAccess } = filesAuthorizationMockFns
const { mockDownloadServableFileFromStorage } = fileUtilsServerMockFns
const { mockSecureFetchWithPinnedIP, mockValidateUrlWithDNS } = inputValidationMockFns

import { executeAshbyUpload } from '@/lib/internal/ashby/operations'
import { executeAshbyDownload, executeAshbyUpload } from '@/lib/internal/ashby/operations'

const FILE = {
id: 'file-1',
Expand All @@ -32,6 +33,65 @@ const FILE = {
url: '/api/files/serve?key=resume.pdf',
}

describe('Ashby file download', () => {
const signedUrl = 'https://files.example.com/resume.pdf?signature=private-download-token'
const input = { apiKey: 'test-key', fileHandle: 'file-handle', fileName: 'resume.pdf' }

it('downloads with the default filename when the optional override is blank', async () => {
vi.stubGlobal(
'fetch',
vi.fn().mockResolvedValueOnce(Response.json({ success: true, results: { url: signedUrl } }))
)
mockValidateUrlWithDNS.mockResolvedValueOnce({ isValid: true, resolvedIP: '203.0.113.10' })
mockSecureFetchWithPinnedIP.mockResolvedValueOnce(
new Response('Candidate worked on embedded Linux', {
headers: { 'content-type': 'application/pdf' },
})
)

const result = await executeAshbyTool({
toolId: 'ashby_get_file',
input: { ...input, fileName: ' ' },
context: { workflowId: 'workflow-1', userId: 'sim-user' },
headers: new Headers(),
requestId: 'request-1',
})
if (result instanceof Response) throw new Error('Expected a private file output')
expect(result.files[0]?.name).toBe('resume.pdf')
expect(result.files[0]?.buffer.toString()).toContain('embedded Linux')
expect(JSON.stringify(result.present([FILE]))).not.toContain('private-download-token')
expect(mockSecureFetchWithPinnedIP.mock.calls[0]?.[2].headers).toBeUndefined()
})

it('rejects an unsafe download URL without a second request or leaking the provider URL', async () => {
vi.stubGlobal(
'fetch',
vi.fn().mockResolvedValueOnce(
Response.json({
success: true,
results: { url: 'http://127.0.0.1/?signature=private-download-token' },
})
)
)
const result = await executeAshbyDownload(input)
if (!(result instanceof Response)) throw new Error('Expected the unsafe URL to be rejected')
expect(result.status).toBe(502)
expect(await result.text()).not.toContain('private-download-token')
expect(mockSecureFetchWithPinnedIP).not.toHaveBeenCalled()
})

it('preserves Ashby throttling without treating it as a file transfer failure', async () => {
vi.stubGlobal(
'fetch',
vi.fn().mockResolvedValueOnce(new Response('Rate limited', { status: 429 }))
)
const result = await executeAshbyDownload(input)
if (!(result instanceof Response)) throw new Error('Expected a throttled response')
expect(result.status).toBe(429)
expect(await result.text()).toContain('rate-limited')
})
})

describe('executeAshbyUpload', () => {
beforeEach(() => {
mockAssertToolFileAccess.mockResolvedValue(null)
Expand Down
88 changes: 85 additions & 3 deletions apps/sim/lib/internal/ashby/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ import {
readResponseJsonWithLimit,
readResponseTextWithLimit,
} from '@/lib/core/utils/stream-limits'
import type { AshbyUploadInput } from '@/lib/internal/ashby/schema'
import type { AshbyDownloadInput, AshbyUploadInput } from '@/lib/internal/ashby/schema'
import {
createInternalToolFileResult,
type InternalToolFileResult,
} from '@/lib/internal/tool-operations/file-result'
import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types'
import { processFilesToUserFiles } from '@/lib/uploads/utils/file'
import { fetchExternalUrl } from '@/lib/uploads/utils/fetch-external-url.server'
import { ensureFileNameExtension, processFilesToUserFiles } from '@/lib/uploads/utils/file'
import { downloadServableFileFromStorage } from '@/lib/uploads/utils/file.server'
import { docNotReadyResponse } from '@/lib/uploads/utils/servable-file-response'
import { assertToolFileAccess } from '@/app/api/files/authorization'
Expand All @@ -23,6 +28,7 @@ import { ashbyAuthHeaders, ashbyErrorMessage, mapCandidate } from '@/tools/ashby
const logger = createLogger('AshbyFileUpload')
const MAX_ASHBY_JSON_BYTES = 2 * 1024 * 1024
const MAX_ASHBY_UPLOAD_BYTES = Math.min(MAX_BUFFERED_TRANSFER_BYTES, 25 * 1024 * 1024)
const MAX_ASHBY_DOWNLOAD_BYTES = Math.min(MAX_BUFFERED_TRANSFER_BYTES, 10 * 1024 * 1024)

interface Context {
userId: string
Expand All @@ -34,6 +40,15 @@ function failure(error: string, status: number): Response {
return Response.json({ success: false, error }, { status })
}

class AshbyRequestError extends Error {
constructor(
message: string,
readonly status: number
) {
super(message)
}
}

async function ashbyPost(
apiKey: string,
path: string,
Expand All @@ -47,17 +62,84 @@ async function ashbyPost(
body: JSON.stringify(body),
signal,
})
const fallback = `Ashby ${path} failed (HTTP ${response.status})`
const data = await readResponseJsonWithLimit<unknown>(response, {
maxBytes: MAX_ASHBY_JSON_BYTES,
label: `Ashby ${path} response`,
signal,
}).catch((error: unknown) => {
signal?.throwIfAborted()
if (!response.ok && !isPayloadSizeLimitError(error)) {
throw new AshbyRequestError(fallback, response.status)
}
throw error
})
if (!response.ok || !isRecordLike(data) || data.success !== true) {
throw new Error(ashbyErrorMessage(data, `Ashby ${path} failed (HTTP ${response.status})`))
throw new AshbyRequestError(ashbyErrorMessage(data, fallback), response.status)
}
return data.results
}

/** Resolve Ashby's temporary link within the tool boundary and hand the bytes to managed storage. */
export async function executeAshbyDownload(
input: AshbyDownloadInput,
signal?: AbortSignal
): Promise<InternalToolFileResult | Response> {
let result: unknown
try {
result = await ashbyPost(
input.apiKey,
'file.info',
{ fileHandle: input.fileHandle },
undefined,
signal
)
} catch (error) {
signal?.throwIfAborted()
if (error instanceof AshbyRequestError) {
if (error.status === 429)
return failure('Ashby rate-limited the file lookup. Try again shortly.', 429)
if (error.status === 401 || error.status === 403) {
return failure('The Ashby credential cannot read this file.', error.status)
}
if (error.status === 400) return failure('Ashby rejected this file handle.', 400)
if (error.status === 404 || error.status === 200) {
return failure(
'Ashby could not resolve this file handle. Check that the file is still available.',
404
)
}
}
return failure('Could not look up the file in Ashby.', 502)
}
if (!isRecordLike(result) || typeof result.url !== 'string') {
return failure('Ashby did not return a file download URL', 502)
}
try {
const url = new URL(result.url)
if (url.protocol !== 'https:' || url.username || url.password) {
return failure('Ashby returned an invalid file download URL', 502)
}
const { buffer, filename, mimeType } = await fetchExternalUrl({
url: result.url,
maxDownloadBytes: MAX_ASHBY_DOWNLOAD_BYTES,
signal,
})
signal?.throwIfAborted()
if (buffer.length === 0) return failure('Ashby returned an empty file', 502)
const name = input.fileName ? ensureFileNameExtension(input.fileName, mimeType) : filename
return createInternalToolFileResult({ buffer, name, mimeType }, (file) => ({
success: true,
output: { file },
}))
} catch (error) {
signal?.throwIfAborted()
if (isPayloadSizeLimitError(error)) return failure('Ashby file exceeds the download limit', 413)
// Storage errors may contain the signed URL.
return failure('Could not transfer the file from Ashby storage.', 502)
}
}

export async function executeAshbyUpload(
input: AshbyUploadInput,
kind: 'resume' | 'file',
Expand Down
8 changes: 8 additions & 0 deletions apps/sim/lib/internal/ashby/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ export const ashbyUploadInputSchema = z.object({
})

export type AshbyUploadInput = z.output<typeof ashbyUploadInputSchema>

export const ashbyDownloadInputSchema = z.object({
apiKey: z.string().min(1, 'Ashby API key is required'),
fileHandle: z.string().trim().min(1, 'File handle is required').max(8192),
fileName: z.string().trim().max(255).nullish(),
})

export type AshbyDownloadInput = z.output<typeof ashbyDownloadInputSchema>
6 changes: 5 additions & 1 deletion apps/sim/lib/internal/tool-operations/registry.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,11 @@ const DISCORD_TOOL_IDS = ['discord_send_message'] as const

const LINQ_TOOL_IDS = ['linq_create_attachment'] as const

const ASHBY_TOOL_IDS = ['ashby_upload_candidate_file', 'ashby_upload_resume'] as const
const ASHBY_TOOL_IDS = [
'ashby_get_file',
'ashby_upload_candidate_file',
'ashby_upload_resume',
] as const

const MICROSOFT_DATAVERSE_TOOL_IDS = ['microsoft_dataverse_upload_file'] as const

Expand Down
Loading
Loading