retry-job.ts•1.63 kB
/**
* This file was generated. Do NOT edit this file.
*/
import fetch from 'node-fetch'
import { type ZodRawShape, z } from 'zod'
import { commons_JobIdSchema } from '../schemas.js'
import type { Tool } from './index.js'
const params = {
jobId: commons_JobIdSchema.describe('ID of job to return'),
} as ZodRawShape
export const retryJob: Tool<typeof params> = {
name: 'retryJob',
description: 'Retry a failed job: Retry a failt job and return the job',
params,
cb: async ({ jobId }) => {
try {
const searchParams = {}
const searchParamsString = new URLSearchParams(JSON.parse(JSON.stringify(searchParams))).toString()
const baseUrl = process.env.FLATFILE_API_URL || 'https://platform.flatfile.com/api/v1'
const url = `${baseUrl}/jobs/${jobId}/retry${searchParamsString ? `?${searchParamsString}` : ''}`
const response = await fetch(url, {
method: 'POST',
headers: {
'X-Disable-Hooks': 'true',
Authorization: `Bearer ${process.env.FLATFILE_BEARER_TOKEN}`,
'Content-Type': 'application/json',
},
})
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status} - ${response.statusText}`)
}
const data = (await response.json()) as { data: unknown }
return {
content: [
{
type: 'text',
text: JSON.stringify(data.data, null, 2),
},
],
status: 'success',
}
} catch (error) {
return {
content: [{ type: 'text', text: `Error: ${error}` }],
status: 'failed',
}
}
},
}