list-jobs.ts•3.13 kB
/**
* This file was generated. Do NOT edit this file.
*/
import fetch from 'node-fetch'
import { type ZodRawShape, z } from 'zod'
import {
commons_EnvironmentIdSchema,
commons_FileIdSchema,
commons_JobIdSchema,
commons_SortDirectionSchema,
commons_SpaceIdSchema,
commons_WorkbookIdSchema,
} from '../schemas.js'
import type { Tool } from './index.js'
const params = {
environmentId: commons_EnvironmentIdSchema
.optional()
.describe('When provided, only jobs for the given environment will be returned'),
spaceId: commons_SpaceIdSchema.optional().describe('When provided, only jobs for the given space will be returned'),
workbookId: commons_WorkbookIdSchema
.optional()
.describe('When provided, only jobs for the given workbook will be returned'),
fileId: commons_FileIdSchema.optional().describe('When provided, only jobs for the given file will be returned'),
parentId: commons_JobIdSchema
.optional()
.describe('When provided, only jobs that are parts of the given job will be returned'),
pageSize: z.number().int().optional().describe('Number of jobs to return in a page (default 20)'),
pageNumber: z.number().int().optional().describe('Based on pageSize, which page of jobs to return'),
sortDirection: commons_SortDirectionSchema
.optional()
.describe('Sort direction - asc (ascending) or desc (descending)'),
excludeChildJobs: z
.boolean()
.optional()
.describe('When true, only top-level jobs will be returned unless a parentId is specified'),
} as ZodRawShape
export const listJobs: Tool<typeof params> = {
name: 'listJobs',
description: 'List jobs: List jobs',
params,
cb: async ({
environmentId,
spaceId,
workbookId,
fileId,
parentId,
pageSize,
pageNumber,
sortDirection,
excludeChildJobs,
}) => {
try {
const searchParams = {
environmentId,
spaceId,
workbookId,
fileId,
parentId,
pageSize,
pageNumber,
sortDirection,
excludeChildJobs,
}
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${searchParamsString ? `?${searchParamsString}` : ''}`
const response = await fetch(url, {
method: 'GET',
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',
}
}
},
}