Skip to content
38 changes: 5 additions & 33 deletions apps/sim/app/api/tools/jira/update/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type NextRequest, NextResponse } from 'next/server'
import { z } from 'zod'
import { checkSessionOrInternalAuth } from '@/lib/auth/hybrid'
import { validateJiraCloudId, validateJiraIssueKey } from '@/lib/core/security/input-validation'
import { getJiraCloudId, parseAtlassianErrorMessage } from '@/tools/jira/utils'
import { getJiraCloudId, parseAtlassianErrorMessage, toAdf } from '@/tools/jira/utils'

export const dynamic = 'force-dynamic'

Expand All @@ -15,14 +15,14 @@ const jiraUpdateSchema = z.object({
issueKey: z.string().min(1, 'Issue key is required'),
summary: z.string().optional(),
title: z.string().optional(),
description: z.string().optional(),
description: z.union([z.string(), z.record(z.unknown())]).optional(),
priority: z.string().optional(),
assignee: z.string().optional(),
labels: z.array(z.string()).optional(),
components: z.array(z.string()).optional(),
duedate: z.string().optional(),
fixVersions: z.array(z.string()).optional(),
environment: z.string().optional(),
environment: z.union([z.string(), z.record(z.unknown())]).optional(),
customFieldId: z.string().optional(),
customFieldValue: z.string().optional(),
notifyUsers: z.boolean().optional(),
Expand Down Expand Up @@ -91,21 +91,7 @@ export async function PUT(request: NextRequest) {
}

if (description !== undefined && description !== null && description !== '') {
fields.description = {
type: 'doc',
version: 1,
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: description,
},
],
},
],
}
fields.description = toAdf(description)
}

if (priority !== undefined && priority !== null && priority !== '') {
Expand Down Expand Up @@ -136,21 +122,7 @@ export async function PUT(request: NextRequest) {
}

if (environment !== undefined && environment !== null && environment !== '') {
fields.environment = {
type: 'doc',
version: 1,
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: environment,
},
],
},
],
}
fields.environment = toAdf(environment)
}

if (
Expand Down
34 changes: 3 additions & 31 deletions apps/sim/app/api/tools/jira/write/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createLogger } from '@sim/logger'
import { type NextRequest, NextResponse } from 'next/server'
import { checkSessionOrInternalAuth } from '@/lib/auth/hybrid'
import { validateAlphanumericId, validateJiraCloudId } from '@/lib/core/security/input-validation'
import { getJiraCloudId, parseAtlassianErrorMessage } from '@/tools/jira/utils'
import { getJiraCloudId, parseAtlassianErrorMessage, toAdf } from '@/tools/jira/utils'

export const dynamic = 'force-dynamic'

Expand Down Expand Up @@ -85,21 +85,7 @@ export async function POST(request: NextRequest) {
}

if (description !== undefined && description !== null && description !== '') {
fields.description = {
type: 'doc',
version: 1,
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: description,
},
],
},
],
}
fields.description = toAdf(description)
}

if (parent !== undefined && parent !== null && parent !== '') {
Expand Down Expand Up @@ -144,21 +130,7 @@ export async function POST(request: NextRequest) {
}

if (environment !== undefined && environment !== null && environment !== '') {
fields.environment = {
type: 'doc',
version: 1,
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: environment,
},
],
},
],
}
fields.environment = toAdf(environment)
}

if (
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/tools/jira/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export const jiraUpdateTool: ToolConfig<JiraUpdateParams, JiraUpdateResponse> =
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'New description for the issue',
description:
'New description for the issue. Accepts plain text (auto-wrapped in ADF) or a raw ADF document object',
},
priority: {
type: 'string',
Expand Down
45 changes: 45 additions & 0 deletions apps/sim/tools/jira/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,51 @@ const logger = createLogger('JiraUtils')

const MAX_ATTACHMENT_SIZE = 50 * 1024 * 1024

/**
* Converts a value to ADF format. If the value is already an ADF document object,
* it is returned as-is. If it is a plain string, it is wrapped in a single-paragraph ADF doc.
*/
export function toAdf(value: string | Record<string, unknown>): Record<string, unknown> {
if (typeof value === 'object') {
if (value.type === 'doc') {
return value
}
if (value.type && Array.isArray(value.content)) {
return { type: 'doc', version: 1, content: [value] }
}
}
if (typeof value === 'string') {
try {
const parsed = JSON.parse(value)
if (typeof parsed === 'object' && parsed !== null && parsed.type === 'doc') {
return parsed
}
if (
typeof parsed === 'object' &&
parsed !== null &&
parsed.type &&
Array.isArray(parsed.content)
) {
return { type: 'doc', version: 1, content: [parsed] }
}
} catch {
// Not JSON — treat as plain text below
}
}
return {
type: 'doc',
version: 1,
content: [
{
type: 'paragraph',
content: [
{ type: 'text', text: typeof value === 'string' ? value : JSON.stringify(value) },
],
},
],
}
}

/**
* Extracts plain text from Atlassian Document Format (ADF) content.
* Returns null if content is falsy.
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/tools/jira/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export const jiraWriteTool: ToolConfig<JiraWriteParams, JiraWriteResponse> = {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Description for the issue',
description:
'Description for the issue. Accepts plain text (auto-wrapped in ADF) or a raw ADF document object',
},
priority: {
type: 'string',
Expand Down
Loading