chore: import upstream snapshot with attribution
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
import type { JiraAddAttachmentParams, JiraAddAttachmentResponse } from '@/tools/jira/types'
|
||||
import { TIMESTAMP_OUTPUT } from '@/tools/jira/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const jiraAddAttachmentTool: ToolConfig<JiraAddAttachmentParams, JiraAddAttachmentResponse> =
|
||||
{
|
||||
id: 'jira_add_attachment',
|
||||
name: 'Jira Add Attachment',
|
||||
description: 'Add attachments to a Jira issue',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
issueKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Jira issue key to add attachments to (e.g., PROJ-123)',
|
||||
},
|
||||
files: {
|
||||
type: 'file[]',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Files to attach to the Jira issue',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: '/api/tools/jira/add-attachment',
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params: JiraAddAttachmentParams) => ({
|
||||
accessToken: params.accessToken,
|
||||
domain: params.domain,
|
||||
issueKey: params.issueKey,
|
||||
files: params.files,
|
||||
cloudId: params.cloudId,
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
if (!response.ok || !data.success) {
|
||||
throw new Error(data.error || 'Failed to add Jira attachment')
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: data.output,
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
issueKey: { type: 'string', description: 'Issue key' },
|
||||
attachments: {
|
||||
type: 'array',
|
||||
description: 'Uploaded attachments',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: { type: 'string', description: 'Attachment ID' },
|
||||
filename: { type: 'string', description: 'Attachment file name' },
|
||||
mimeType: { type: 'string', description: 'MIME type' },
|
||||
size: { type: 'number', description: 'File size in bytes' },
|
||||
content: { type: 'string', description: 'URL to download the attachment' },
|
||||
},
|
||||
},
|
||||
},
|
||||
attachmentIds: {
|
||||
type: 'array',
|
||||
description: 'Array of attachment IDs',
|
||||
items: { type: 'string' },
|
||||
optional: true,
|
||||
},
|
||||
files: { type: 'file[]', description: 'Uploaded attachment files' },
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
import type { JiraAddCommentParams, JiraAddCommentResponse } from '@/tools/jira/types'
|
||||
import { SUCCESS_OUTPUT, TIMESTAMP_OUTPUT, USER_OUTPUT_PROPERTIES } from '@/tools/jira/types'
|
||||
import { extractAdfText, getJiraCloudId, toAdf, transformUser } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
/**
|
||||
* Transforms an add comment API response into typed output.
|
||||
*/
|
||||
function transformCommentResponse(data: any, params: JiraAddCommentParams) {
|
||||
return {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: params.issueKey ?? 'unknown',
|
||||
commentId: data?.id ?? 'unknown',
|
||||
body: data?.body ? (extractAdfText(data.body) ?? params.body ?? '') : (params.body ?? ''),
|
||||
author: transformUser(data?.author) ?? { accountId: '', displayName: '' },
|
||||
created: data?.created ?? '',
|
||||
updated: data?.updated ?? '',
|
||||
success: true,
|
||||
}
|
||||
}
|
||||
|
||||
export const jiraAddCommentTool: ToolConfig<JiraAddCommentParams, JiraAddCommentResponse> = {
|
||||
id: 'jira_add_comment',
|
||||
name: 'Jira Add Comment',
|
||||
description: 'Add a comment to a Jira issue',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
issueKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Jira issue key to add comment to (e.g., PROJ-123)',
|
||||
},
|
||||
body: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Comment body text',
|
||||
},
|
||||
visibility: {
|
||||
type: 'json',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'Restrict comment visibility. Object with "type" ("role" or "group") and "value" (role/group name).',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraAddCommentParams) => {
|
||||
if (params.cloudId) {
|
||||
return `https://api.atlassian.com/ex/jira/${params.cloudId}/rest/api/3/issue/${params.issueKey?.trim() ?? ''}/comment`
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: (params: JiraAddCommentParams) => (params.cloudId ? 'POST' : 'GET'),
|
||||
headers: (params: JiraAddCommentParams) => {
|
||||
return {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}
|
||||
},
|
||||
body: (params: JiraAddCommentParams) => {
|
||||
if (!params.cloudId) return undefined as any
|
||||
const payload: Record<string, any> = { body: toAdf(params.body ?? '') }
|
||||
if (params.visibility) payload.visibility = params.visibility
|
||||
return payload
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraAddCommentParams) => {
|
||||
const payload: Record<string, any> = { body: toAdf(params?.body ?? '') }
|
||||
if (params?.visibility) payload.visibility = params.visibility
|
||||
|
||||
const makeRequest = async (cloudId: string) => {
|
||||
const commentUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issue/${params!.issueKey?.trim() ?? ''}/comment`
|
||||
const commentResponse = await fetch(commentUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
})
|
||||
|
||||
if (!commentResponse.ok) {
|
||||
let message = `Failed to add comment to Jira issue (${commentResponse.status})`
|
||||
try {
|
||||
const err = await commentResponse.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return commentResponse.json()
|
||||
}
|
||||
|
||||
let data: any
|
||||
|
||||
if (!params?.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params!.domain, params!.accessToken)
|
||||
data = await makeRequest(cloudId)
|
||||
} else {
|
||||
if (!response.ok) {
|
||||
let message = `Failed to add comment to Jira issue (${response.status})`
|
||||
try {
|
||||
const err = await response.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
data = await response.json()
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: transformCommentResponse(data, params!),
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
success: SUCCESS_OUTPUT,
|
||||
issueKey: { type: 'string', description: 'Issue key the comment was added to' },
|
||||
commentId: { type: 'string', description: 'Created comment ID' },
|
||||
body: { type: 'string', description: 'Comment text content' },
|
||||
author: {
|
||||
type: 'object',
|
||||
description: 'Comment author',
|
||||
properties: USER_OUTPUT_PROPERTIES,
|
||||
},
|
||||
created: { type: 'string', description: 'ISO 8601 timestamp when the comment was created' },
|
||||
updated: {
|
||||
type: 'string',
|
||||
description: 'ISO 8601 timestamp when the comment was last updated',
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
import type { JiraAddWatcherParams, JiraAddWatcherResponse } from '@/tools/jira/types'
|
||||
import { SUCCESS_OUTPUT, TIMESTAMP_OUTPUT } from '@/tools/jira/types'
|
||||
import { getJiraCloudId } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const jiraAddWatcherTool: ToolConfig<JiraAddWatcherParams, JiraAddWatcherResponse> = {
|
||||
id: 'jira_add_watcher',
|
||||
name: 'Jira Add Watcher',
|
||||
description: 'Add a watcher to a Jira issue to receive notifications about updates',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
issueKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Jira issue key to add watcher to (e.g., PROJ-123)',
|
||||
},
|
||||
accountId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Account ID of the user to add as watcher',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraAddWatcherParams) => {
|
||||
if (params.cloudId) {
|
||||
return `https://api.atlassian.com/ex/jira/${params.cloudId}/rest/api/3/issue/${params.issueKey?.trim() ?? ''}/watchers`
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: (params: JiraAddWatcherParams) => (params.cloudId ? 'POST' : 'GET'),
|
||||
headers: (params: JiraAddWatcherParams) => {
|
||||
return {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}
|
||||
},
|
||||
body: (params: JiraAddWatcherParams) => {
|
||||
if (!params.cloudId) return undefined as any
|
||||
if (!params.accountId) {
|
||||
throw new Error('accountId is required to add a Jira watcher')
|
||||
}
|
||||
return params.accountId as any
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraAddWatcherParams) => {
|
||||
if (!params?.accountId) {
|
||||
throw new Error('accountId is required to add a Jira watcher')
|
||||
}
|
||||
if (!params?.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params!.domain, params!.accessToken)
|
||||
const watcherUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issue/${params!.issueKey?.trim() ?? ''}/watchers`
|
||||
const watcherResponse = await fetch(watcherUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
body: JSON.stringify(params!.accountId),
|
||||
})
|
||||
|
||||
if (!watcherResponse.ok) {
|
||||
let message = `Failed to add watcher to Jira issue (${watcherResponse.status})`
|
||||
try {
|
||||
const err = await watcherResponse.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: params!.issueKey || 'unknown',
|
||||
watcherAccountId: params!.accountId || 'unknown',
|
||||
success: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
let message = `Failed to add watcher to Jira issue (${response.status})`
|
||||
try {
|
||||
const err = await response.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: params!.issueKey || 'unknown',
|
||||
watcherAccountId: params!.accountId || 'unknown',
|
||||
success: true,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
success: SUCCESS_OUTPUT,
|
||||
issueKey: { type: 'string', description: 'Issue key' },
|
||||
watcherAccountId: { type: 'string', description: 'Added watcher account ID' },
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
import type { JiraAddWorklogParams, JiraAddWorklogResponse } from '@/tools/jira/types'
|
||||
import { SUCCESS_OUTPUT, TIMESTAMP_OUTPUT, USER_OUTPUT_PROPERTIES } from '@/tools/jira/types'
|
||||
import {
|
||||
getJiraCloudId,
|
||||
normalizeJiraWorklogTimestamp,
|
||||
toAdf,
|
||||
transformUser,
|
||||
} from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
/**
|
||||
* Builds the worklog request body per Jira API v3.
|
||||
*/
|
||||
function buildWorklogBody(params: JiraAddWorklogParams) {
|
||||
const t = Number(params.timeSpentSeconds)
|
||||
if (!Number.isFinite(t) || t <= 0) {
|
||||
throw new Error('timeSpentSeconds must be a positive finite number')
|
||||
}
|
||||
const body: Record<string, any> = {
|
||||
timeSpentSeconds: t,
|
||||
comment: params.comment ? toAdf(params.comment) : undefined,
|
||||
started: normalizeJiraWorklogTimestamp(params.started || new Date().toISOString()),
|
||||
}
|
||||
if (params.visibility) body.visibility = params.visibility
|
||||
return body
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a worklog API response into typed output.
|
||||
*/
|
||||
function transformWorklogResponse(data: any, params: JiraAddWorklogParams) {
|
||||
return {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: params.issueKey ?? 'unknown',
|
||||
worklogId: data?.id ?? 'unknown',
|
||||
timeSpent: data?.timeSpent ?? '',
|
||||
timeSpentSeconds: data?.timeSpentSeconds ?? Number(params.timeSpentSeconds) ?? 0,
|
||||
author: transformUser(data?.author) ?? { accountId: '', displayName: '' },
|
||||
started: data?.started ?? '',
|
||||
created: data?.created ?? '',
|
||||
success: true,
|
||||
}
|
||||
}
|
||||
|
||||
export const jiraAddWorklogTool: ToolConfig<JiraAddWorklogParams, JiraAddWorklogResponse> = {
|
||||
id: 'jira_add_worklog',
|
||||
name: 'Jira Add Worklog',
|
||||
description: 'Add a time tracking worklog entry to a Jira issue',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
issueKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Jira issue key to add worklog to (e.g., PROJ-123)',
|
||||
},
|
||||
timeSpentSeconds: {
|
||||
type: 'number',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Time spent in seconds',
|
||||
},
|
||||
comment: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Optional comment for the worklog entry',
|
||||
},
|
||||
started: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Optional start time in ISO format (defaults to current time)',
|
||||
},
|
||||
visibility: {
|
||||
type: 'json',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'Restrict worklog visibility. Object with "type" ("role" or "group") and "value" (role/group name).',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraAddWorklogParams) => {
|
||||
if (params.cloudId) {
|
||||
return `https://api.atlassian.com/ex/jira/${params.cloudId}/rest/api/3/issue/${params.issueKey?.trim() ?? ''}/worklog`
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: (params: JiraAddWorklogParams) => (params.cloudId ? 'POST' : 'GET'),
|
||||
headers: (params: JiraAddWorklogParams) => {
|
||||
return {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}
|
||||
},
|
||||
body: (params: JiraAddWorklogParams) => {
|
||||
if (!params.cloudId) return undefined as any
|
||||
return buildWorklogBody(params)
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraAddWorklogParams) => {
|
||||
const t = Number(params?.timeSpentSeconds)
|
||||
if (!params?.timeSpentSeconds || !Number.isFinite(t) || t <= 0) {
|
||||
throw new Error('timeSpentSeconds is required and must be a positive finite number')
|
||||
}
|
||||
|
||||
const makeRequest = async (cloudId: string) => {
|
||||
const worklogUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issue/${params!.issueKey?.trim() ?? ''}/worklog`
|
||||
const worklogResponse = await fetch(worklogUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
body: JSON.stringify(buildWorklogBody(params!)),
|
||||
})
|
||||
|
||||
if (!worklogResponse.ok) {
|
||||
let message = `Failed to add worklog to Jira issue (${worklogResponse.status})`
|
||||
try {
|
||||
const err = await worklogResponse.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return worklogResponse.json()
|
||||
}
|
||||
|
||||
let data: any
|
||||
|
||||
if (!params.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params.domain, params.accessToken)
|
||||
data = await makeRequest(cloudId)
|
||||
} else {
|
||||
if (!response.ok) {
|
||||
let message = `Failed to add worklog to Jira issue (${response.status})`
|
||||
try {
|
||||
const err = await response.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
data = await response.json()
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: transformWorklogResponse(data, params),
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
success: SUCCESS_OUTPUT,
|
||||
issueKey: { type: 'string', description: 'Issue key the worklog was added to' },
|
||||
worklogId: { type: 'string', description: 'Created worklog ID' },
|
||||
timeSpent: {
|
||||
type: 'string',
|
||||
description: 'Time spent in human-readable format (e.g., 3h 20m)',
|
||||
},
|
||||
timeSpentSeconds: { type: 'number', description: 'Time spent in seconds' },
|
||||
author: {
|
||||
type: 'object',
|
||||
description: 'Worklog author',
|
||||
properties: USER_OUTPUT_PROPERTIES,
|
||||
},
|
||||
started: { type: 'string', description: 'ISO 8601 timestamp when the work started' },
|
||||
created: { type: 'string', description: 'ISO 8601 timestamp when the worklog was created' },
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
import type { JiraAssignIssueParams, JiraAssignIssueResponse } from '@/tools/jira/types'
|
||||
import { SUCCESS_OUTPUT, TIMESTAMP_OUTPUT } from '@/tools/jira/types'
|
||||
import { getJiraCloudId } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
/**
|
||||
* Maps user-provided accountId to the Jira API value.
|
||||
* Empty string, "null", "none", or "unassigned" → null (unassign).
|
||||
* "-1" → "-1" (auto-assign). Otherwise the trimmed accountId.
|
||||
*/
|
||||
function resolveAssigneeAccountId(value: string | null | undefined): string | null {
|
||||
if (value === null || value === undefined) return null
|
||||
const trimmed = String(value).trim()
|
||||
if (trimmed === '') return null
|
||||
const lower = trimmed.toLowerCase()
|
||||
if (lower === 'null' || lower === 'none' || lower === 'unassigned') return null
|
||||
return trimmed
|
||||
}
|
||||
|
||||
export const jiraAssignIssueTool: ToolConfig<JiraAssignIssueParams, JiraAssignIssueResponse> = {
|
||||
id: 'jira_assign_issue',
|
||||
name: 'Jira Assign Issue',
|
||||
description: 'Assign a Jira issue to a user',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
issueKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Jira issue key to assign (e.g., PROJ-123)',
|
||||
},
|
||||
accountId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'Account ID of the user to assign the issue to. Use "-1" for automatic assignment, or leave empty / pass "null" to unassign.',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraAssignIssueParams) => {
|
||||
if (params.cloudId) {
|
||||
return `https://api.atlassian.com/ex/jira/${params.cloudId}/rest/api/3/issue/${params.issueKey?.trim() ?? ''}/assignee`
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: (params: JiraAssignIssueParams) => (params.cloudId ? 'PUT' : 'GET'),
|
||||
headers: (params: JiraAssignIssueParams) => {
|
||||
return {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}
|
||||
},
|
||||
body: (params: JiraAssignIssueParams) => {
|
||||
if (!params.cloudId) return undefined as any
|
||||
return { accountId: resolveAssigneeAccountId(params.accountId) }
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraAssignIssueParams) => {
|
||||
if (!params?.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params!.domain, params!.accessToken)
|
||||
const assignUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issue/${params!.issueKey?.trim() ?? ''}/assignee`
|
||||
const assignResponse = await fetch(assignUrl, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
body: JSON.stringify({ accountId: resolveAssigneeAccountId(params!.accountId) }),
|
||||
})
|
||||
|
||||
if (!assignResponse.ok) {
|
||||
let message = `Failed to assign Jira issue (${assignResponse.status})`
|
||||
try {
|
||||
const err = await assignResponse.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: params?.issueKey || 'unknown',
|
||||
assigneeId: params?.accountId || 'unknown',
|
||||
success: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
let message = `Failed to assign Jira issue (${response.status})`
|
||||
try {
|
||||
const err = await response.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: params?.issueKey || 'unknown',
|
||||
assigneeId: params?.accountId || 'unknown',
|
||||
success: true,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
success: SUCCESS_OUTPUT,
|
||||
issueKey: { type: 'string', description: 'Issue key that was assigned' },
|
||||
assigneeId: {
|
||||
type: 'string',
|
||||
description: 'Account ID of the assignee (use "-1" for auto-assign, null to unassign)',
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
import type { JiraRetrieveBulkParams, JiraRetrieveResponseBulk } from '@/tools/jira/types'
|
||||
import { TIMESTAMP_OUTPUT } from '@/tools/jira/types'
|
||||
import { extractAdfText, normalizeDomain } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const jiraBulkRetrieveTool: ToolConfig<JiraRetrieveBulkParams, JiraRetrieveResponseBulk> = {
|
||||
id: 'jira_bulk_read',
|
||||
name: 'Jira Bulk Read',
|
||||
description: 'Retrieve multiple Jira issues from a project in bulk',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
projectId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Jira project key (e.g., PROJ)',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: () => 'https://api.atlassian.com/oauth/token/accessible-resources',
|
||||
method: 'GET',
|
||||
headers: (params: JiraRetrieveBulkParams) => ({
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
Accept: 'application/json',
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraRetrieveBulkParams) => {
|
||||
const MAX_TOTAL = 1000
|
||||
const PAGE_SIZE = 100
|
||||
|
||||
const resolveProjectKey = async (cloudId: string, accessToken: string, ref: string) => {
|
||||
const refTrimmed = (ref || '').trim()
|
||||
if (!refTrimmed) return refTrimmed
|
||||
const url = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/project/${encodeURIComponent(refTrimmed)}`
|
||||
const resp = await fetch(url, {
|
||||
method: 'GET',
|
||||
headers: { Authorization: `Bearer ${accessToken}`, Accept: 'application/json' },
|
||||
})
|
||||
if (!resp.ok) return refTrimmed
|
||||
const project = await resp.json()
|
||||
return project?.key || refTrimmed
|
||||
}
|
||||
|
||||
const resolveCloudId = async () => {
|
||||
if (params?.cloudId) return params.cloudId
|
||||
const accessibleResources = await response.json()
|
||||
if (!Array.isArray(accessibleResources) || accessibleResources.length === 0) {
|
||||
throw new Error('No Jira resources found')
|
||||
}
|
||||
const normalizedInput = normalizeDomain(params?.domain ?? '')
|
||||
const matchedResource = accessibleResources.find(
|
||||
(r: { url: string }) => r.url.toLowerCase().replace(/\/+$/, '') === normalizedInput
|
||||
)
|
||||
if (matchedResource) return matchedResource.id
|
||||
if (accessibleResources.length === 1) return accessibleResources[0].id
|
||||
throw new Error(
|
||||
`Could not match Jira domain "${params?.domain}" to any accessible resource. ` +
|
||||
`Available sites: ${accessibleResources.map((r: { url: string }) => r.url).join(', ')}`
|
||||
)
|
||||
}
|
||||
|
||||
const cloudId = await resolveCloudId()
|
||||
const projectKey = await resolveProjectKey(cloudId, params!.accessToken, params!.projectId)
|
||||
if (!/^[A-Za-z][A-Za-z0-9_]*$/.test(projectKey)) {
|
||||
throw new Error(
|
||||
`Invalid Jira project key "${projectKey}". Expected an alphanumeric project key (e.g., PROJ).`
|
||||
)
|
||||
}
|
||||
const jql = `project = "${projectKey}" ORDER BY updated DESC`
|
||||
|
||||
let collected: any[] = []
|
||||
let nextPageToken: string | undefined
|
||||
let total: number | null = null
|
||||
|
||||
while (collected.length < MAX_TOTAL) {
|
||||
const queryParams = new URLSearchParams({
|
||||
jql,
|
||||
fields: 'summary,description,status,issuetype,priority,assignee,created,updated',
|
||||
maxResults: String(PAGE_SIZE),
|
||||
})
|
||||
if (nextPageToken) queryParams.set('nextPageToken', nextPageToken)
|
||||
|
||||
const url = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/search/jql?${queryParams.toString()}`
|
||||
const pageResponse = await fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
Accept: 'application/json',
|
||||
},
|
||||
})
|
||||
|
||||
if (!pageResponse.ok) {
|
||||
let message = `Failed to bulk read Jira issues (${pageResponse.status})`
|
||||
try {
|
||||
const err = await pageResponse.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
const pageData = await pageResponse.json()
|
||||
const issues = pageData.issues || []
|
||||
if (pageData.total != null) total = pageData.total
|
||||
collected = collected.concat(issues)
|
||||
|
||||
if (pageData.isLast || !pageData.nextPageToken || issues.length === 0) break
|
||||
nextPageToken = pageData.nextPageToken
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
total,
|
||||
issues: collected.slice(0, MAX_TOTAL).map((issue: any) => ({
|
||||
id: issue.id ?? '',
|
||||
key: issue.key ?? '',
|
||||
self: issue.self ?? '',
|
||||
summary: issue.fields?.summary ?? '',
|
||||
description: extractAdfText(issue.fields?.description),
|
||||
status: {
|
||||
id: issue.fields?.status?.id ?? '',
|
||||
name: issue.fields?.status?.name ?? '',
|
||||
},
|
||||
issuetype: {
|
||||
id: issue.fields?.issuetype?.id ?? '',
|
||||
name: issue.fields?.issuetype?.name ?? '',
|
||||
},
|
||||
priority: issue.fields?.priority
|
||||
? { id: issue.fields.priority.id ?? '', name: issue.fields.priority.name ?? '' }
|
||||
: null,
|
||||
assignee: issue.fields?.assignee
|
||||
? {
|
||||
accountId: issue.fields.assignee.accountId ?? '',
|
||||
displayName: issue.fields.assignee.displayName ?? '',
|
||||
}
|
||||
: null,
|
||||
created: issue.fields?.created ?? '',
|
||||
updated: issue.fields?.updated ?? '',
|
||||
})),
|
||||
nextPageToken: nextPageToken ?? null,
|
||||
isLast: !nextPageToken || collected.length >= MAX_TOTAL,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
total: {
|
||||
type: 'number',
|
||||
description: 'Total number of issues in the project (may not always be available)',
|
||||
optional: true,
|
||||
},
|
||||
issues: {
|
||||
type: 'array',
|
||||
description: 'Array of Jira issues',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: { type: 'string', description: 'Issue ID' },
|
||||
key: { type: 'string', description: 'Issue key (e.g., PROJ-123)' },
|
||||
self: { type: 'string', description: 'REST API URL for this issue' },
|
||||
summary: { type: 'string', description: 'Issue summary' },
|
||||
description: { type: 'string', description: 'Issue description text', optional: true },
|
||||
status: {
|
||||
type: 'object',
|
||||
description: 'Issue status',
|
||||
properties: {
|
||||
id: { type: 'string', description: 'Status ID' },
|
||||
name: { type: 'string', description: 'Status name' },
|
||||
},
|
||||
},
|
||||
issuetype: {
|
||||
type: 'object',
|
||||
description: 'Issue type',
|
||||
properties: {
|
||||
id: { type: 'string', description: 'Issue type ID' },
|
||||
name: { type: 'string', description: 'Issue type name' },
|
||||
},
|
||||
},
|
||||
priority: {
|
||||
type: 'object',
|
||||
description: 'Issue priority',
|
||||
properties: {
|
||||
id: { type: 'string', description: 'Priority ID' },
|
||||
name: { type: 'string', description: 'Priority name' },
|
||||
},
|
||||
optional: true,
|
||||
},
|
||||
assignee: {
|
||||
type: 'object',
|
||||
description: 'Assigned user',
|
||||
properties: {
|
||||
accountId: { type: 'string', description: 'Atlassian account ID' },
|
||||
displayName: { type: 'string', description: 'Display name' },
|
||||
},
|
||||
optional: true,
|
||||
},
|
||||
created: { type: 'string', description: 'ISO 8601 creation timestamp' },
|
||||
updated: { type: 'string', description: 'ISO 8601 last updated timestamp' },
|
||||
},
|
||||
},
|
||||
},
|
||||
nextPageToken: {
|
||||
type: 'string',
|
||||
description: 'Cursor token for the next page. Null when no more results.',
|
||||
optional: true,
|
||||
},
|
||||
isLast: { type: 'boolean', description: 'Whether this is the last page of results' },
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
import type { JiraCreateIssueLinkParams, JiraCreateIssueLinkResponse } from '@/tools/jira/types'
|
||||
import { SUCCESS_OUTPUT, TIMESTAMP_OUTPUT } from '@/tools/jira/types'
|
||||
import { getJiraCloudId, toAdf } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const jiraCreateIssueLinkTool: ToolConfig<
|
||||
JiraCreateIssueLinkParams,
|
||||
JiraCreateIssueLinkResponse
|
||||
> = {
|
||||
id: 'jira_create_issue_link',
|
||||
name: 'Jira Create Issue Link',
|
||||
description: 'Create a link relationship between two Jira issues',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
inwardIssueKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Jira issue key for the inward issue (e.g., PROJ-123)',
|
||||
},
|
||||
outwardIssueKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Jira issue key for the outward issue (e.g., PROJ-456)',
|
||||
},
|
||||
linkType: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'The type of link relationship (e.g., "Blocks", "Relates to", "Duplicates")',
|
||||
},
|
||||
comment: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Optional comment to add to the issue link',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (_params: JiraCreateIssueLinkParams) => {
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: () => 'GET',
|
||||
headers: (params: JiraCreateIssueLinkParams) => {
|
||||
return {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}
|
||||
},
|
||||
body: () => undefined as any,
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraCreateIssueLinkParams) => {
|
||||
const cloudId = params?.cloudId || (await getJiraCloudId(params!.domain, params!.accessToken))
|
||||
|
||||
const typesResp = await fetch(
|
||||
`https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issueLinkType`,
|
||||
{
|
||||
method: 'GET',
|
||||
headers: { Accept: 'application/json', Authorization: `Bearer ${params!.accessToken}` },
|
||||
}
|
||||
)
|
||||
if (!typesResp.ok) {
|
||||
throw new Error(`Failed to fetch issue link types (${typesResp.status})`)
|
||||
}
|
||||
const typesData = await typesResp.json()
|
||||
const provided = (params!.linkType || '').trim().toLowerCase()
|
||||
let resolvedType: { id?: string; name?: string } | undefined
|
||||
const allTypes = Array.isArray(typesData?.issueLinkTypes) ? typesData.issueLinkTypes : []
|
||||
for (const t of allTypes) {
|
||||
const name = String(t?.name || '').toLowerCase()
|
||||
const inward = String(t?.inward || '').toLowerCase()
|
||||
const outward = String(t?.outward || '').toLowerCase()
|
||||
if (provided && (provided === name || provided === inward || provided === outward)) {
|
||||
resolvedType = t?.id ? { id: String(t.id) } : { name: t?.name }
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!resolvedType && /^\d+$/.test(provided)) {
|
||||
resolvedType = { id: provided }
|
||||
}
|
||||
if (!resolvedType) {
|
||||
const available = allTypes
|
||||
.map((t: any) => `${t?.name} (inward: ${t?.inward}, outward: ${t?.outward})`)
|
||||
.join('; ')
|
||||
throw new Error(`Unknown issue link type "${params!.linkType}". Available: ${available}`)
|
||||
}
|
||||
|
||||
const linkUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issueLink`
|
||||
const linkResponse = await fetch(linkUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
type: resolvedType,
|
||||
inwardIssue: { key: params!.inwardIssueKey?.trim() ?? '' },
|
||||
outwardIssue: { key: params!.outwardIssueKey?.trim() ?? '' },
|
||||
comment: params?.comment ? { body: toAdf(params.comment) } : undefined,
|
||||
}),
|
||||
})
|
||||
if (!linkResponse.ok) {
|
||||
let message = `Failed to create issue link (${linkResponse.status})`
|
||||
try {
|
||||
const err = await linkResponse.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
let linkId: string | null = null
|
||||
|
||||
try {
|
||||
const linkData = await linkResponse.json()
|
||||
if (linkData?.id) linkId = String(linkData.id)
|
||||
} catch {
|
||||
const location = linkResponse.headers.get('location') || linkResponse.headers.get('Location')
|
||||
if (location) {
|
||||
const match = location.match(/\/issueLink\/(\d+)/)
|
||||
if (match) linkId = match[1]
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
inwardIssue: params!.inwardIssueKey || 'unknown',
|
||||
outwardIssue: params!.outwardIssueKey || 'unknown',
|
||||
linkType: params!.linkType || 'unknown',
|
||||
linkId,
|
||||
success: true,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
success: SUCCESS_OUTPUT,
|
||||
inwardIssue: { type: 'string', description: 'Inward issue key' },
|
||||
outwardIssue: { type: 'string', description: 'Outward issue key' },
|
||||
linkType: { type: 'string', description: 'Type of issue link' },
|
||||
linkId: { type: 'string', description: 'Created link ID', optional: true },
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
import type { JiraDeleteAttachmentParams, JiraDeleteAttachmentResponse } from '@/tools/jira/types'
|
||||
import { SUCCESS_OUTPUT, TIMESTAMP_OUTPUT } from '@/tools/jira/types'
|
||||
import { getJiraCloudId } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const jiraDeleteAttachmentTool: ToolConfig<
|
||||
JiraDeleteAttachmentParams,
|
||||
JiraDeleteAttachmentResponse
|
||||
> = {
|
||||
id: 'jira_delete_attachment',
|
||||
name: 'Jira Delete Attachment',
|
||||
description: 'Delete an attachment from a Jira issue',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
attachmentId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'ID of the attachment to delete',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraDeleteAttachmentParams) => {
|
||||
if (params.cloudId) {
|
||||
return `https://api.atlassian.com/ex/jira/${params.cloudId}/rest/api/3/attachment/${params.attachmentId?.trim() ?? ''}`
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: (params: JiraDeleteAttachmentParams) => (params.cloudId ? 'DELETE' : 'GET'),
|
||||
headers: (params: JiraDeleteAttachmentParams) => {
|
||||
return {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraDeleteAttachmentParams) => {
|
||||
if (!params?.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params!.domain, params!.accessToken)
|
||||
// Make the actual request with the resolved cloudId
|
||||
const attachmentUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/attachment/${params?.attachmentId?.trim() ?? ''}`
|
||||
const attachmentResponse = await fetch(attachmentUrl, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params?.accessToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
if (!attachmentResponse.ok) {
|
||||
let message = `Failed to delete attachment from Jira issue (${attachmentResponse.status})`
|
||||
try {
|
||||
const err = await attachmentResponse.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
attachmentId: params?.attachmentId || 'unknown',
|
||||
success: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// If cloudId was provided, process the response
|
||||
if (!response.ok) {
|
||||
let message = `Failed to delete attachment from Jira issue (${response.status})`
|
||||
try {
|
||||
const err = await response.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
attachmentId: params?.attachmentId || 'unknown',
|
||||
success: true,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
success: SUCCESS_OUTPUT,
|
||||
attachmentId: { type: 'string', description: 'Deleted attachment ID' },
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
import type { JiraDeleteCommentParams, JiraDeleteCommentResponse } from '@/tools/jira/types'
|
||||
import { SUCCESS_OUTPUT, TIMESTAMP_OUTPUT } from '@/tools/jira/types'
|
||||
import { getJiraCloudId } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const jiraDeleteCommentTool: ToolConfig<JiraDeleteCommentParams, JiraDeleteCommentResponse> =
|
||||
{
|
||||
id: 'jira_delete_comment',
|
||||
name: 'Jira Delete Comment',
|
||||
description: 'Delete a comment from a Jira issue',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
issueKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Jira issue key containing the comment (e.g., PROJ-123)',
|
||||
},
|
||||
commentId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'ID of the comment to delete',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraDeleteCommentParams) => {
|
||||
if (params.cloudId) {
|
||||
return `https://api.atlassian.com/ex/jira/${params.cloudId}/rest/api/3/issue/${params.issueKey?.trim() ?? ''}/comment/${params.commentId?.trim() ?? ''}`
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: (params: JiraDeleteCommentParams) => (params.cloudId ? 'DELETE' : 'GET'),
|
||||
headers: (params: JiraDeleteCommentParams) => {
|
||||
return {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraDeleteCommentParams) => {
|
||||
if (!params?.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params!.domain, params!.accessToken)
|
||||
// Make the actual request with the resolved cloudId
|
||||
const commentUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issue/${params?.issueKey?.trim() ?? ''}/comment/${params?.commentId?.trim() ?? ''}`
|
||||
const commentResponse = await fetch(commentUrl, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params?.accessToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
if (!commentResponse.ok) {
|
||||
let message = `Failed to delete comment from Jira issue (${commentResponse.status})`
|
||||
try {
|
||||
const err = await commentResponse.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: params?.issueKey || 'unknown',
|
||||
commentId: params?.commentId || 'unknown',
|
||||
success: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// If cloudId was provided, process the response
|
||||
if (!response.ok) {
|
||||
let message = `Failed to delete comment from Jira issue (${response.status})`
|
||||
try {
|
||||
const err = await response.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: params?.issueKey || 'unknown',
|
||||
commentId: params?.commentId || 'unknown',
|
||||
success: true,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
success: SUCCESS_OUTPUT,
|
||||
issueKey: { type: 'string', description: 'Issue key' },
|
||||
commentId: { type: 'string', description: 'Deleted comment ID' },
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
import type { JiraDeleteIssueParams, JiraDeleteIssueResponse } from '@/tools/jira/types'
|
||||
import { SUCCESS_OUTPUT, TIMESTAMP_OUTPUT } from '@/tools/jira/types'
|
||||
import { getJiraCloudId } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const jiraDeleteIssueTool: ToolConfig<JiraDeleteIssueParams, JiraDeleteIssueResponse> = {
|
||||
id: 'jira_delete_issue',
|
||||
name: 'Jira Delete Issue',
|
||||
description: 'Delete a Jira issue',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
issueKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Jira issue key to delete (e.g., PROJ-123)',
|
||||
},
|
||||
deleteSubtasks: {
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'Whether to delete subtasks. If false, parent issues with subtasks cannot be deleted.',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraDeleteIssueParams) => {
|
||||
if (params.cloudId) {
|
||||
const deleteSubtasksParam = params.deleteSubtasks ? '?deleteSubtasks=true' : ''
|
||||
return `https://api.atlassian.com/ex/jira/${params.cloudId}/rest/api/3/issue/${params.issueKey?.trim() ?? ''}${deleteSubtasksParam}`
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: (params: JiraDeleteIssueParams) => (params.cloudId ? 'DELETE' : 'GET'),
|
||||
headers: (params: JiraDeleteIssueParams) => {
|
||||
return {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraDeleteIssueParams) => {
|
||||
if (!params?.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params!.domain, params!.accessToken)
|
||||
const deleteSubtasksParam = params!.deleteSubtasks ? '?deleteSubtasks=true' : ''
|
||||
const deleteUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issue/${params!.issueKey?.trim() ?? ''}${deleteSubtasksParam}`
|
||||
const deleteResponse = await fetch(deleteUrl, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
if (deleteResponse.status === 204) {
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: params?.issueKey || 'unknown',
|
||||
success: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if (!deleteResponse.ok) {
|
||||
let message = `Failed to delete Jira issue (${deleteResponse.status})`
|
||||
try {
|
||||
const contentType = deleteResponse.headers.get('content-type') || ''
|
||||
if (contentType.includes('application/json')) {
|
||||
const err = await deleteResponse.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} else {
|
||||
const text = await deleteResponse.text()
|
||||
message = `${message} - Received HTML/text response. Check authentication and permissions. Response: ${text.substring(0, 200)}`
|
||||
}
|
||||
} catch (_e) {
|
||||
// If parsing fails, keep default message
|
||||
}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: params?.issueKey || 'unknown',
|
||||
success: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if (response.status === 204) {
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: params?.issueKey || 'unknown',
|
||||
success: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
let message = `Failed to delete Jira issue (${response.status})`
|
||||
try {
|
||||
const contentType = response.headers.get('content-type') || ''
|
||||
if (contentType.includes('application/json')) {
|
||||
const err = await response.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} else {
|
||||
const text = await response.text()
|
||||
message = `${message} - Received HTML/text response. Check authentication and permissions. Response: ${text.substring(0, 200)}`
|
||||
}
|
||||
} catch (_e) {
|
||||
// If parsing fails, keep default message
|
||||
}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: params?.issueKey || 'unknown',
|
||||
success: true,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
success: SUCCESS_OUTPUT,
|
||||
issueKey: { type: 'string', description: 'Deleted issue key' },
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
import type { JiraDeleteIssueLinkParams, JiraDeleteIssueLinkResponse } from '@/tools/jira/types'
|
||||
import { SUCCESS_OUTPUT, TIMESTAMP_OUTPUT } from '@/tools/jira/types'
|
||||
import { getJiraCloudId } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const jiraDeleteIssueLinkTool: ToolConfig<
|
||||
JiraDeleteIssueLinkParams,
|
||||
JiraDeleteIssueLinkResponse
|
||||
> = {
|
||||
id: 'jira_delete_issue_link',
|
||||
name: 'Jira Delete Issue Link',
|
||||
description: 'Delete a link between two Jira issues',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
linkId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'ID of the issue link to delete',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraDeleteIssueLinkParams) => {
|
||||
if (params.cloudId) {
|
||||
return `https://api.atlassian.com/ex/jira/${params.cloudId}/rest/api/3/issueLink/${params.linkId?.trim() ?? ''}`
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: (params: JiraDeleteIssueLinkParams) => (params.cloudId ? 'DELETE' : 'GET'),
|
||||
headers: (params: JiraDeleteIssueLinkParams) => {
|
||||
return {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraDeleteIssueLinkParams) => {
|
||||
if (!params?.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params!.domain, params!.accessToken)
|
||||
const issueLinkUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issueLink/${params!.linkId?.trim() ?? ''}`
|
||||
const issueLinkResponse = await fetch(issueLinkUrl, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
if (!issueLinkResponse.ok) {
|
||||
let message = `Failed to delete issue link (${issueLinkResponse.status})`
|
||||
try {
|
||||
const err = await issueLinkResponse.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
linkId: params!.linkId || 'unknown',
|
||||
success: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
let message = `Failed to delete issue link (${response.status})`
|
||||
try {
|
||||
const err = await response.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
linkId: params!.linkId || 'unknown',
|
||||
success: true,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
success: SUCCESS_OUTPUT,
|
||||
linkId: { type: 'string', description: 'Deleted link ID' },
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
import type { JiraDeleteWorklogParams, JiraDeleteWorklogResponse } from '@/tools/jira/types'
|
||||
import { SUCCESS_OUTPUT, TIMESTAMP_OUTPUT } from '@/tools/jira/types'
|
||||
import { getJiraCloudId } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const jiraDeleteWorklogTool: ToolConfig<JiraDeleteWorklogParams, JiraDeleteWorklogResponse> =
|
||||
{
|
||||
id: 'jira_delete_worklog',
|
||||
name: 'Jira Delete Worklog',
|
||||
description: 'Delete a worklog entry from a Jira issue',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
issueKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Jira issue key containing the worklog (e.g., PROJ-123)',
|
||||
},
|
||||
worklogId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'ID of the worklog entry to delete',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraDeleteWorklogParams) => {
|
||||
if (params.cloudId) {
|
||||
return `https://api.atlassian.com/ex/jira/${params.cloudId}/rest/api/3/issue/${params.issueKey?.trim() ?? ''}/worklog/${params.worklogId?.trim() ?? ''}`
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: (params: JiraDeleteWorklogParams) => (params.cloudId ? 'DELETE' : 'GET'),
|
||||
headers: (params: JiraDeleteWorklogParams) => {
|
||||
return {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraDeleteWorklogParams) => {
|
||||
if (!params?.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params!.domain, params!.accessToken)
|
||||
const worklogUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issue/${params!.issueKey?.trim() ?? ''}/worklog/${params!.worklogId?.trim() ?? ''}`
|
||||
const worklogResponse = await fetch(worklogUrl, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
if (!worklogResponse.ok) {
|
||||
let message = `Failed to delete worklog from Jira issue (${worklogResponse.status})`
|
||||
try {
|
||||
const err = await worklogResponse.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: params!.issueKey || 'unknown',
|
||||
worklogId: params!.worklogId || 'unknown',
|
||||
success: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
let message = `Failed to delete worklog from Jira issue (${response.status})`
|
||||
try {
|
||||
const err = await response.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: params!.issueKey || 'unknown',
|
||||
worklogId: params!.worklogId || 'unknown',
|
||||
success: true,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
success: SUCCESS_OUTPUT,
|
||||
issueKey: { type: 'string', description: 'Issue key' },
|
||||
worklogId: { type: 'string', description: 'Deleted worklog ID' },
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
import type { JiraGetAttachmentsParams, JiraGetAttachmentsResponse } from '@/tools/jira/types'
|
||||
import { ATTACHMENT_ITEM_PROPERTIES, TIMESTAMP_OUTPUT } from '@/tools/jira/types'
|
||||
import { downloadJiraAttachments, getJiraCloudId, transformUser } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
/**
|
||||
* Transforms a raw Jira attachment object into typed output.
|
||||
*/
|
||||
function transformAttachment(att: any) {
|
||||
return {
|
||||
id: att.id ?? '',
|
||||
filename: att.filename ?? '',
|
||||
mimeType: att.mimeType ?? '',
|
||||
size: att.size ?? 0,
|
||||
content: att.content ?? '',
|
||||
thumbnail: att.thumbnail ?? null,
|
||||
author: transformUser(att.author),
|
||||
authorName: att.author?.displayName ?? att.author?.accountId ?? 'Unknown',
|
||||
created:
|
||||
typeof att.created === 'number' ? new Date(att.created).toISOString() : (att.created ?? ''),
|
||||
}
|
||||
}
|
||||
|
||||
export const jiraGetAttachmentsTool: ToolConfig<
|
||||
JiraGetAttachmentsParams,
|
||||
JiraGetAttachmentsResponse
|
||||
> = {
|
||||
id: 'jira_get_attachments',
|
||||
name: 'Jira Get Attachments',
|
||||
description: 'Get all attachments from a Jira issue',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
issueKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Jira issue key to get attachments from (e.g., PROJ-123)',
|
||||
},
|
||||
includeAttachments: {
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Download attachment file contents and include them as files in the output',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraGetAttachmentsParams) => {
|
||||
if (params.cloudId) {
|
||||
return `https://api.atlassian.com/ex/jira/${params.cloudId}/rest/api/3/issue/${params.issueKey?.trim() ?? ''}?fields=attachment`
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: 'GET',
|
||||
headers: (params: JiraGetAttachmentsParams) => {
|
||||
return {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraGetAttachmentsParams) => {
|
||||
const fetchAttachments = async (cloudId: string) => {
|
||||
const attachmentsUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issue/${params!.issueKey?.trim() ?? ''}?fields=attachment`
|
||||
const attachmentsResponse = await fetch(attachmentsUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
if (!attachmentsResponse.ok) {
|
||||
let message = `Failed to get attachments from Jira issue (${attachmentsResponse.status})`
|
||||
try {
|
||||
const err = await attachmentsResponse.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return attachmentsResponse.json()
|
||||
}
|
||||
|
||||
let data: any
|
||||
|
||||
if (!params?.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params!.domain, params!.accessToken)
|
||||
data = await fetchAttachments(cloudId)
|
||||
} else {
|
||||
if (!response.ok) {
|
||||
let message = `Failed to get attachments from Jira issue (${response.status})`
|
||||
try {
|
||||
const err = await response.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
data = await response.json()
|
||||
}
|
||||
|
||||
const attachments = (data?.fields?.attachment ?? []).map(transformAttachment)
|
||||
|
||||
let files: Array<{ name: string; mimeType: string; data: string; size: number }> | undefined
|
||||
if (params?.includeAttachments && attachments.length > 0) {
|
||||
files = await downloadJiraAttachments(attachments, params.accessToken)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: params?.issueKey ?? 'unknown',
|
||||
attachments,
|
||||
...(files && files.length > 0 ? { files } : {}),
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
issueKey: { type: 'string', description: 'Issue key' },
|
||||
attachments: {
|
||||
type: 'array',
|
||||
description: 'Array of attachments',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: ATTACHMENT_ITEM_PROPERTIES,
|
||||
},
|
||||
},
|
||||
files: {
|
||||
type: 'file[]',
|
||||
description: 'Downloaded attachment files (only when includeAttachments is true)',
|
||||
optional: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
import type { JiraGetCommentsParams, JiraGetCommentsResponse } from '@/tools/jira/types'
|
||||
import { COMMENT_ITEM_PROPERTIES, TIMESTAMP_OUTPUT } from '@/tools/jira/types'
|
||||
import { extractAdfText, getJiraCloudId, transformUser } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
/**
|
||||
* Transforms a raw Jira comment object into typed output.
|
||||
*/
|
||||
function transformComment(comment: any) {
|
||||
return {
|
||||
id: comment.id ?? '',
|
||||
body: extractAdfText(comment.body) ?? '',
|
||||
author: transformUser(comment.author) ?? { accountId: '', displayName: '' },
|
||||
authorName: comment.author?.displayName ?? comment.author?.accountId ?? 'Unknown',
|
||||
updateAuthor: transformUser(comment.updateAuthor),
|
||||
created: comment.created ?? '',
|
||||
updated: comment.updated ?? '',
|
||||
visibility: comment.visibility
|
||||
? { type: comment.visibility.type ?? '', value: comment.visibility.value ?? '' }
|
||||
: null,
|
||||
}
|
||||
}
|
||||
|
||||
export const jiraGetCommentsTool: ToolConfig<JiraGetCommentsParams, JiraGetCommentsResponse> = {
|
||||
id: 'jira_get_comments',
|
||||
name: 'Jira Get Comments',
|
||||
description: 'Get all comments from a Jira issue',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
issueKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Jira issue key to get comments from (e.g., PROJ-123)',
|
||||
},
|
||||
startAt: {
|
||||
type: 'number',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Index of the first comment to return (default: 0)',
|
||||
},
|
||||
maxResults: {
|
||||
type: 'number',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Maximum number of comments to return (default: 50)',
|
||||
},
|
||||
orderBy: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'Sort order for comments: "-created" for newest first, "created" for oldest first',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraGetCommentsParams) => {
|
||||
if (params.cloudId) {
|
||||
const startAt = params.startAt ?? 0
|
||||
const maxResults = params.maxResults ?? 50
|
||||
const orderBy = params.orderBy ?? '-created'
|
||||
return `https://api.atlassian.com/ex/jira/${params.cloudId}/rest/api/3/issue/${params.issueKey?.trim() ?? ''}/comment?startAt=${startAt}&maxResults=${maxResults}&orderBy=${orderBy}`
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: 'GET',
|
||||
headers: (params: JiraGetCommentsParams) => {
|
||||
return {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraGetCommentsParams) => {
|
||||
const fetchComments = async (cloudId: string) => {
|
||||
const startAt = params?.startAt ?? 0
|
||||
const maxResults = params?.maxResults ?? 50
|
||||
const orderBy = params?.orderBy ?? '-created'
|
||||
const commentsUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issue/${params!.issueKey?.trim() ?? ''}/comment?startAt=${startAt}&maxResults=${maxResults}&orderBy=${orderBy}`
|
||||
const commentsResponse = await fetch(commentsUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
if (!commentsResponse.ok) {
|
||||
let message = `Failed to get comments from Jira issue (${commentsResponse.status})`
|
||||
try {
|
||||
const err = await commentsResponse.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return commentsResponse.json()
|
||||
}
|
||||
|
||||
let data: any
|
||||
|
||||
if (!params?.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params!.domain, params!.accessToken)
|
||||
data = await fetchComments(cloudId)
|
||||
} else {
|
||||
if (!response.ok) {
|
||||
let message = `Failed to get comments from Jira issue (${response.status})`
|
||||
try {
|
||||
const err = await response.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
data = await response.json()
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: params?.issueKey ?? 'unknown',
|
||||
total: data.total ?? 0,
|
||||
startAt: data.startAt ?? 0,
|
||||
maxResults: data.maxResults ?? 0,
|
||||
comments: (data.comments ?? []).map(transformComment),
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
issueKey: { type: 'string', description: 'Issue key' },
|
||||
total: { type: 'number', description: 'Total number of comments' },
|
||||
startAt: { type: 'number', description: 'Pagination start index' },
|
||||
maxResults: { type: 'number', description: 'Maximum results per page' },
|
||||
comments: {
|
||||
type: 'array',
|
||||
description: 'Array of comments',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: COMMENT_ITEM_PROPERTIES,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
import type { JiraGetFieldsParams, JiraGetFieldsResponse } from '@/tools/jira/types'
|
||||
import { TIMESTAMP_OUTPUT } from '@/tools/jira/types'
|
||||
import { getJiraCloudId, parseAtlassianErrorMessage } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
function buildFieldsUrl(cloudId: string): string {
|
||||
return `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/field`
|
||||
}
|
||||
|
||||
export const jiraGetFieldsTool: ToolConfig<JiraGetFieldsParams, JiraGetFieldsResponse> = {
|
||||
id: 'jira_get_fields',
|
||||
name: 'Jira Get Fields',
|
||||
description:
|
||||
'Get all system and custom fields defined in the Jira instance. Useful for discovering custom field IDs (e.g., customfield_10001) to use when writing or updating issues.',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraGetFieldsParams) => {
|
||||
if (params.cloudId) {
|
||||
return buildFieldsUrl(params.cloudId)
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: 'GET',
|
||||
headers: (params: JiraGetFieldsParams) => ({
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraGetFieldsParams) => {
|
||||
const fetchFields = async (cloudId: string) => {
|
||||
const fieldsResponse = await fetch(buildFieldsUrl(cloudId), {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
if (!fieldsResponse.ok) {
|
||||
const errorText = await fieldsResponse.text()
|
||||
throw new Error(
|
||||
parseAtlassianErrorMessage(fieldsResponse.status, fieldsResponse.statusText, errorText)
|
||||
)
|
||||
}
|
||||
|
||||
return fieldsResponse.json()
|
||||
}
|
||||
|
||||
let data: any
|
||||
|
||||
if (!params?.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params!.domain, params!.accessToken)
|
||||
data = await fetchFields(cloudId)
|
||||
} else {
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
throw new Error(parseAtlassianErrorMessage(response.status, response.statusText, errorText))
|
||||
}
|
||||
data = await response.json()
|
||||
}
|
||||
|
||||
const fields = Array.isArray(data) ? data : []
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
fields: fields.map((f: any) => ({
|
||||
id: f?.id ?? '',
|
||||
key: f?.key ?? null,
|
||||
name: f?.name ?? '',
|
||||
custom: f?.custom ?? null,
|
||||
navigable: f?.navigable ?? null,
|
||||
searchable: f?.searchable ?? null,
|
||||
schemaType: f?.schema?.type ?? null,
|
||||
customType: f?.schema?.custom ?? null,
|
||||
})),
|
||||
total: fields.length,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
fields: {
|
||||
type: 'array',
|
||||
description: 'Array of Jira fields (system and custom)',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: { type: 'string', description: 'Field ID (e.g., summary, customfield_10001)' },
|
||||
key: { type: 'string', description: 'Field key', optional: true },
|
||||
name: { type: 'string', description: 'Human-readable field name' },
|
||||
custom: {
|
||||
type: 'boolean',
|
||||
description: 'Whether this is a custom field',
|
||||
optional: true,
|
||||
},
|
||||
navigable: {
|
||||
type: 'boolean',
|
||||
description: 'Whether the field is navigable in issue views',
|
||||
optional: true,
|
||||
},
|
||||
searchable: {
|
||||
type: 'boolean',
|
||||
description: 'Whether the field can be used in JQL searches',
|
||||
optional: true,
|
||||
},
|
||||
schemaType: {
|
||||
type: 'string',
|
||||
description: 'Field value type (e.g., string, number, array, user)',
|
||||
optional: true,
|
||||
},
|
||||
customType: {
|
||||
type: 'string',
|
||||
description: 'Custom field type identifier (only for custom fields)',
|
||||
optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
total: { type: 'number', description: 'Number of fields returned' },
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
import type { JiraGetProjectParams, JiraGetProjectResponse } from '@/tools/jira/types'
|
||||
import { TIMESTAMP_OUTPUT } from '@/tools/jira/types'
|
||||
import { getJiraCloudId, parseAtlassianErrorMessage } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
function buildProjectUrl(cloudId: string, projectIdOrKey: string): string {
|
||||
return `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/project/${encodeURIComponent(projectIdOrKey)}`
|
||||
}
|
||||
|
||||
export const jiraGetProjectTool: ToolConfig<JiraGetProjectParams, JiraGetProjectResponse> = {
|
||||
id: 'jira_get_project',
|
||||
name: 'Jira Get Project',
|
||||
description:
|
||||
'Get the details of a single Jira project by its ID or key, including its type, lead, components, issue types, and versions.',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
projectId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'The project ID or key (e.g., "PROJ" or "10000")',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraGetProjectParams) => {
|
||||
if (params.cloudId) {
|
||||
return buildProjectUrl(params.cloudId, params.projectId)
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: 'GET',
|
||||
headers: (params: JiraGetProjectParams) => ({
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraGetProjectParams) => {
|
||||
const fetchProject = async (cloudId: string) => {
|
||||
const projectResponse = await fetch(buildProjectUrl(cloudId, params!.projectId), {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
if (!projectResponse.ok) {
|
||||
const errorText = await projectResponse.text()
|
||||
throw new Error(
|
||||
parseAtlassianErrorMessage(projectResponse.status, projectResponse.statusText, errorText)
|
||||
)
|
||||
}
|
||||
|
||||
return projectResponse.json()
|
||||
}
|
||||
|
||||
let data: any
|
||||
|
||||
if (!params?.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params!.domain, params!.accessToken)
|
||||
data = await fetchProject(cloudId)
|
||||
} else {
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
throw new Error(parseAtlassianErrorMessage(response.status, response.statusText, errorText))
|
||||
}
|
||||
data = await response.json()
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
id: data?.id ?? '',
|
||||
key: data?.key ?? '',
|
||||
name: data?.name ?? '',
|
||||
description: data?.description ?? null,
|
||||
projectTypeKey: data?.projectTypeKey ?? null,
|
||||
simplified: data?.simplified ?? null,
|
||||
style: data?.style ?? null,
|
||||
isPrivate: data?.isPrivate ?? null,
|
||||
url: data?.self ?? null,
|
||||
leadDisplayName: data?.lead?.displayName ?? null,
|
||||
leadAccountId: data?.lead?.accountId ?? null,
|
||||
issueTypes: Array.isArray(data?.issueTypes)
|
||||
? data.issueTypes.map((t: any) => ({
|
||||
id: t?.id ?? '',
|
||||
name: t?.name ?? '',
|
||||
subtask: t?.subtask ?? null,
|
||||
}))
|
||||
: [],
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
id: { type: 'string', description: 'Project ID' },
|
||||
key: { type: 'string', description: 'Project key (e.g., PROJ)' },
|
||||
name: { type: 'string', description: 'Project name' },
|
||||
description: { type: 'string', description: 'Project description', optional: true },
|
||||
projectTypeKey: {
|
||||
type: 'string',
|
||||
description: 'Project type key (e.g., software, service_desk, business)',
|
||||
optional: true,
|
||||
},
|
||||
simplified: {
|
||||
type: 'boolean',
|
||||
description: 'Whether the project is a simplified (team-managed) project',
|
||||
optional: true,
|
||||
},
|
||||
style: {
|
||||
type: 'string',
|
||||
description: 'Project style (e.g., classic, next-gen)',
|
||||
optional: true,
|
||||
},
|
||||
isPrivate: { type: 'boolean', description: 'Whether the project is private', optional: true },
|
||||
url: { type: 'string', description: 'REST API URL for this project', optional: true },
|
||||
leadDisplayName: {
|
||||
type: 'string',
|
||||
description: 'Display name of the project lead',
|
||||
optional: true,
|
||||
},
|
||||
leadAccountId: {
|
||||
type: 'string',
|
||||
description: 'Account ID of the project lead',
|
||||
optional: true,
|
||||
},
|
||||
issueTypes: {
|
||||
type: 'array',
|
||||
description: 'Issue types available in this project',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: { type: 'string', description: 'Issue type ID' },
|
||||
name: { type: 'string', description: 'Issue type name (e.g., Task, Bug, Story)' },
|
||||
subtask: {
|
||||
type: 'boolean',
|
||||
description: 'Whether this issue type is a subtask',
|
||||
optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
import type { JiraGetTransitionsParams, JiraGetTransitionsResponse } from '@/tools/jira/types'
|
||||
import { TIMESTAMP_OUTPUT } from '@/tools/jira/types'
|
||||
import { getJiraCloudId, parseAtlassianErrorMessage } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
function buildTransitionsUrl(cloudId: string, issueKey: string): string {
|
||||
return `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issue/${encodeURIComponent(issueKey)}/transitions`
|
||||
}
|
||||
|
||||
export const jiraGetTransitionsTool: ToolConfig<
|
||||
JiraGetTransitionsParams,
|
||||
JiraGetTransitionsResponse
|
||||
> = {
|
||||
id: 'jira_get_transitions',
|
||||
name: 'Jira Get Transitions',
|
||||
description:
|
||||
'Get the workflow transitions available for an issue in its current status. Use the returned transition IDs with the Transition Issue operation.',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
issueKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'The issue key or ID (e.g., PROJ-123)',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraGetTransitionsParams) => {
|
||||
if (params.cloudId) {
|
||||
return buildTransitionsUrl(params.cloudId, params.issueKey)
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: 'GET',
|
||||
headers: (params: JiraGetTransitionsParams) => ({
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraGetTransitionsParams) => {
|
||||
const fetchTransitions = async (cloudId: string) => {
|
||||
const transitionsResponse = await fetch(buildTransitionsUrl(cloudId, params!.issueKey), {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
if (!transitionsResponse.ok) {
|
||||
const errorText = await transitionsResponse.text()
|
||||
throw new Error(
|
||||
parseAtlassianErrorMessage(
|
||||
transitionsResponse.status,
|
||||
transitionsResponse.statusText,
|
||||
errorText
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
return transitionsResponse.json()
|
||||
}
|
||||
|
||||
let data: any
|
||||
|
||||
if (!params?.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params!.domain, params!.accessToken)
|
||||
data = await fetchTransitions(cloudId)
|
||||
} else {
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
throw new Error(parseAtlassianErrorMessage(response.status, response.statusText, errorText))
|
||||
}
|
||||
data = await response.json()
|
||||
}
|
||||
|
||||
const transitions = Array.isArray(data?.transitions) ? data.transitions : []
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: params?.issueKey ?? '',
|
||||
transitions: transitions.map((t: any) => ({
|
||||
id: t?.id ?? '',
|
||||
name: t?.name ?? '',
|
||||
toStatusId: t?.to?.id ?? null,
|
||||
toStatusName: t?.to?.name ?? null,
|
||||
toStatusCategory: t?.to?.statusCategory?.key ?? null,
|
||||
isAvailable: t?.isAvailable ?? null,
|
||||
hasScreen: t?.hasScreen ?? null,
|
||||
})),
|
||||
total: transitions.length,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
issueKey: { type: 'string', description: 'Issue key the transitions belong to' },
|
||||
transitions: {
|
||||
type: 'array',
|
||||
description: 'Available workflow transitions for the issue',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: { type: 'string', description: 'Transition ID (use with Transition Issue)' },
|
||||
name: { type: 'string', description: 'Transition name (e.g., "Start Progress")' },
|
||||
toStatusId: {
|
||||
type: 'string',
|
||||
description: 'ID of the status the issue moves to',
|
||||
optional: true,
|
||||
},
|
||||
toStatusName: {
|
||||
type: 'string',
|
||||
description: 'Name of the status the issue moves to',
|
||||
optional: true,
|
||||
},
|
||||
toStatusCategory: {
|
||||
type: 'string',
|
||||
description: 'Status category key of the target status (new, indeterminate, done)',
|
||||
optional: true,
|
||||
},
|
||||
isAvailable: {
|
||||
type: 'boolean',
|
||||
description: 'Whether the transition can currently be performed',
|
||||
optional: true,
|
||||
},
|
||||
hasScreen: {
|
||||
type: 'boolean',
|
||||
description: 'Whether the transition requires a screen with fields',
|
||||
optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
total: { type: 'number', description: 'Number of available transitions' },
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
import type { JiraGetUsersParams, JiraGetUsersResponse } from '@/tools/jira/types'
|
||||
import { TIMESTAMP_OUTPUT, USER_OUTPUT_PROPERTIES } from '@/tools/jira/types'
|
||||
import { getJiraCloudId } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
/**
|
||||
* Transforms a raw Jira user API object into typed output.
|
||||
*/
|
||||
function transformUserOutput(user: any) {
|
||||
return {
|
||||
accountId: user.accountId ?? '',
|
||||
accountType: user.accountType ?? null,
|
||||
active: user.active ?? false,
|
||||
displayName: user.displayName ?? '',
|
||||
emailAddress: user.emailAddress ?? null,
|
||||
avatarUrl: user.avatarUrls?.['48x48'] ?? null,
|
||||
avatarUrls: user.avatarUrls ?? null,
|
||||
timeZone: user.timeZone ?? null,
|
||||
self: user.self ?? null,
|
||||
}
|
||||
}
|
||||
|
||||
export const jiraGetUsersTool: ToolConfig<JiraGetUsersParams, JiraGetUsersResponse> = {
|
||||
id: 'jira_get_users',
|
||||
name: 'Jira Get Users',
|
||||
description:
|
||||
'Get Jira users. If an account ID is provided, returns a single user. Otherwise, returns a list of all users.',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
accountId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'Optional account ID to get a specific user. If not provided, returns all users.',
|
||||
},
|
||||
startAt: {
|
||||
type: 'number',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'The index of the first user to return (for pagination, default: 0)',
|
||||
},
|
||||
maxResults: {
|
||||
type: 'number',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Maximum number of users to return (default: 50)',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraGetUsersParams) => {
|
||||
if (params.cloudId) {
|
||||
if (params.accountId) {
|
||||
return `https://api.atlassian.com/ex/jira/${params.cloudId}/rest/api/3/user?accountId=${encodeURIComponent(params.accountId)}`
|
||||
}
|
||||
const queryParams = new URLSearchParams()
|
||||
if (params.startAt !== undefined) queryParams.append('startAt', String(params.startAt))
|
||||
if (params.maxResults !== undefined)
|
||||
queryParams.append('maxResults', String(params.maxResults))
|
||||
const queryString = queryParams.toString()
|
||||
return `https://api.atlassian.com/ex/jira/${params.cloudId}/rest/api/3/users/search${queryString ? `?${queryString}` : ''}`
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: 'GET',
|
||||
headers: (params: JiraGetUsersParams) => ({
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraGetUsersParams) => {
|
||||
const fetchUsers = async (cloudId: string) => {
|
||||
let usersUrl: string
|
||||
if (params!.accountId) {
|
||||
usersUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/user?accountId=${encodeURIComponent(params!.accountId)}`
|
||||
} else {
|
||||
const queryParams = new URLSearchParams()
|
||||
if (params!.startAt !== undefined) queryParams.append('startAt', String(params!.startAt))
|
||||
if (params!.maxResults !== undefined)
|
||||
queryParams.append('maxResults', String(params!.maxResults))
|
||||
const queryString = queryParams.toString()
|
||||
usersUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/users/search${queryString ? `?${queryString}` : ''}`
|
||||
}
|
||||
|
||||
const usersResponse = await fetch(usersUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
if (!usersResponse.ok) {
|
||||
let message = `Failed to get Jira users (${usersResponse.status})`
|
||||
try {
|
||||
const err = await usersResponse.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return usersResponse.json()
|
||||
}
|
||||
|
||||
let data: any
|
||||
|
||||
if (!params?.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params!.domain, params!.accessToken)
|
||||
data = await fetchUsers(cloudId)
|
||||
} else {
|
||||
if (!response.ok) {
|
||||
let message = `Failed to get Jira users (${response.status})`
|
||||
try {
|
||||
const err = await response.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
data = await response.json()
|
||||
}
|
||||
|
||||
const users = params?.accountId ? [data] : data
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
users: users.map(transformUserOutput),
|
||||
total: params?.accountId ? 1 : users.length,
|
||||
startAt: params?.startAt ?? 0,
|
||||
maxResults: params?.maxResults ?? 50,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
users: {
|
||||
type: 'array',
|
||||
description: 'Array of Jira users',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
...USER_OUTPUT_PROPERTIES,
|
||||
avatarUrls: {
|
||||
type: 'json',
|
||||
description: 'User avatar URLs in multiple sizes (16x16, 24x24, 32x32, 48x48)',
|
||||
optional: true,
|
||||
},
|
||||
self: {
|
||||
type: 'string',
|
||||
description: 'REST API URL for this user',
|
||||
optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
total: { type: 'number', description: 'Total number of users returned' },
|
||||
startAt: { type: 'number', description: 'Pagination start index' },
|
||||
maxResults: { type: 'number', description: 'Maximum results per page' },
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
import type { JiraGetWorklogsParams, JiraGetWorklogsResponse } from '@/tools/jira/types'
|
||||
import { TIMESTAMP_OUTPUT, WORKLOG_ITEM_PROPERTIES } from '@/tools/jira/types'
|
||||
import { extractAdfText, getJiraCloudId, transformUser } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
/**
|
||||
* Transforms a raw Jira worklog object into typed output.
|
||||
*/
|
||||
function transformWorklog(worklog: any) {
|
||||
return {
|
||||
id: worklog.id ?? '',
|
||||
author: transformUser(worklog.author) ?? { accountId: '', displayName: '' },
|
||||
authorName: worklog.author?.displayName ?? worklog.author?.accountId ?? 'Unknown',
|
||||
updateAuthor: transformUser(worklog.updateAuthor),
|
||||
comment: worklog.comment ? (extractAdfText(worklog.comment) ?? null) : null,
|
||||
started: worklog.started ?? '',
|
||||
timeSpent: worklog.timeSpent ?? '',
|
||||
timeSpentSeconds: worklog.timeSpentSeconds ?? 0,
|
||||
created: worklog.created ?? '',
|
||||
updated: worklog.updated ?? '',
|
||||
}
|
||||
}
|
||||
|
||||
export const jiraGetWorklogsTool: ToolConfig<JiraGetWorklogsParams, JiraGetWorklogsResponse> = {
|
||||
id: 'jira_get_worklogs',
|
||||
name: 'Jira Get Worklogs',
|
||||
description: 'Get all worklog entries from a Jira issue',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
issueKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Jira issue key to get worklogs from (e.g., PROJ-123)',
|
||||
},
|
||||
startAt: {
|
||||
type: 'number',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Index of the first worklog to return (default: 0)',
|
||||
},
|
||||
maxResults: {
|
||||
type: 'number',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Maximum number of worklogs to return (default: 50)',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraGetWorklogsParams) => {
|
||||
if (params.cloudId) {
|
||||
const startAt = params.startAt ?? 0
|
||||
const maxResults = params.maxResults ?? 50
|
||||
return `https://api.atlassian.com/ex/jira/${params.cloudId}/rest/api/3/issue/${params.issueKey?.trim() ?? ''}/worklog?startAt=${startAt}&maxResults=${maxResults}`
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: 'GET',
|
||||
headers: (params: JiraGetWorklogsParams) => {
|
||||
return {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraGetWorklogsParams) => {
|
||||
const fetchWorklogs = async (cloudId: string) => {
|
||||
const startAt = params?.startAt ?? 0
|
||||
const maxResults = params?.maxResults ?? 50
|
||||
const worklogsUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issue/${params!.issueKey?.trim() ?? ''}/worklog?startAt=${startAt}&maxResults=${maxResults}`
|
||||
const worklogsResponse = await fetch(worklogsUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
if (!worklogsResponse.ok) {
|
||||
let message = `Failed to get worklogs from Jira issue (${worklogsResponse.status})`
|
||||
try {
|
||||
const err = await worklogsResponse.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return worklogsResponse.json()
|
||||
}
|
||||
|
||||
let data: any
|
||||
|
||||
if (!params?.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params!.domain, params!.accessToken)
|
||||
data = await fetchWorklogs(cloudId)
|
||||
} else {
|
||||
if (!response.ok) {
|
||||
let message = `Failed to get worklogs from Jira issue (${response.status})`
|
||||
try {
|
||||
const err = await response.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
data = await response.json()
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: params?.issueKey ?? 'unknown',
|
||||
total: data.total ?? 0,
|
||||
startAt: data.startAt ?? 0,
|
||||
maxResults: data.maxResults ?? 0,
|
||||
worklogs: (data.worklogs ?? []).map(transformWorklog),
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
issueKey: { type: 'string', description: 'Issue key' },
|
||||
total: { type: 'number', description: 'Total number of worklogs' },
|
||||
startAt: { type: 'number', description: 'Pagination start index' },
|
||||
maxResults: { type: 'number', description: 'Maximum results per page' },
|
||||
worklogs: {
|
||||
type: 'array',
|
||||
description: 'Array of worklogs',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: WORKLOG_ITEM_PROPERTIES,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import { jiraAddAttachmentTool } from '@/tools/jira/add_attachment'
|
||||
import { jiraAddCommentTool } from '@/tools/jira/add_comment'
|
||||
import { jiraAddWatcherTool } from '@/tools/jira/add_watcher'
|
||||
import { jiraAddWorklogTool } from '@/tools/jira/add_worklog'
|
||||
import { jiraAssignIssueTool } from '@/tools/jira/assign_issue'
|
||||
import { jiraBulkRetrieveTool } from '@/tools/jira/bulk_read'
|
||||
import { jiraCreateIssueLinkTool } from '@/tools/jira/create_issue_link'
|
||||
import { jiraDeleteAttachmentTool } from '@/tools/jira/delete_attachment'
|
||||
import { jiraDeleteCommentTool } from '@/tools/jira/delete_comment'
|
||||
import { jiraDeleteIssueTool } from '@/tools/jira/delete_issue'
|
||||
import { jiraDeleteIssueLinkTool } from '@/tools/jira/delete_issue_link'
|
||||
import { jiraDeleteWorklogTool } from '@/tools/jira/delete_worklog'
|
||||
import { jiraGetAttachmentsTool } from '@/tools/jira/get_attachments'
|
||||
import { jiraGetCommentsTool } from '@/tools/jira/get_comments'
|
||||
import { jiraGetFieldsTool } from '@/tools/jira/get_fields'
|
||||
import { jiraGetProjectTool } from '@/tools/jira/get_project'
|
||||
import { jiraGetTransitionsTool } from '@/tools/jira/get_transitions'
|
||||
import { jiraGetUsersTool } from '@/tools/jira/get_users'
|
||||
import { jiraGetWorklogsTool } from '@/tools/jira/get_worklogs'
|
||||
import { jiraListIssueTypesTool } from '@/tools/jira/list_issue_types'
|
||||
import { jiraListProjectsTool } from '@/tools/jira/list_projects'
|
||||
import { jiraRemoveWatcherTool } from '@/tools/jira/remove_watcher'
|
||||
import { jiraRetrieveTool } from '@/tools/jira/retrieve'
|
||||
import { jiraSearchIssuesTool } from '@/tools/jira/search_issues'
|
||||
import { jiraSearchUsersTool } from '@/tools/jira/search_users'
|
||||
import { jiraTransitionIssueTool } from '@/tools/jira/transition_issue'
|
||||
import { jiraUpdateTool } from '@/tools/jira/update'
|
||||
import { jiraUpdateCommentTool } from '@/tools/jira/update_comment'
|
||||
import { jiraUpdateWorklogTool } from '@/tools/jira/update_worklog'
|
||||
import { jiraWriteTool } from '@/tools/jira/write'
|
||||
|
||||
export {
|
||||
jiraRetrieveTool,
|
||||
jiraUpdateTool,
|
||||
jiraWriteTool,
|
||||
jiraBulkRetrieveTool,
|
||||
jiraDeleteIssueTool,
|
||||
jiraAssignIssueTool,
|
||||
jiraTransitionIssueTool,
|
||||
jiraSearchIssuesTool,
|
||||
jiraAddCommentTool,
|
||||
jiraAddAttachmentTool,
|
||||
jiraGetCommentsTool,
|
||||
jiraUpdateCommentTool,
|
||||
jiraDeleteCommentTool,
|
||||
jiraGetAttachmentsTool,
|
||||
jiraDeleteAttachmentTool,
|
||||
jiraAddWorklogTool,
|
||||
jiraGetWorklogsTool,
|
||||
jiraUpdateWorklogTool,
|
||||
jiraDeleteWorklogTool,
|
||||
jiraCreateIssueLinkTool,
|
||||
jiraDeleteIssueLinkTool,
|
||||
jiraAddWatcherTool,
|
||||
jiraRemoveWatcherTool,
|
||||
jiraGetUsersTool,
|
||||
jiraSearchUsersTool,
|
||||
jiraListProjectsTool,
|
||||
jiraGetProjectTool,
|
||||
jiraGetTransitionsTool,
|
||||
jiraListIssueTypesTool,
|
||||
jiraGetFieldsTool,
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
import type { JiraListIssueTypesParams, JiraListIssueTypesResponse } from '@/tools/jira/types'
|
||||
import { TIMESTAMP_OUTPUT } from '@/tools/jira/types'
|
||||
import { getJiraCloudId, parseAtlassianErrorMessage } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
function buildIssueTypesUrl(cloudId: string): string {
|
||||
return `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issuetype`
|
||||
}
|
||||
|
||||
export const jiraListIssueTypesTool: ToolConfig<
|
||||
JiraListIssueTypesParams,
|
||||
JiraListIssueTypesResponse
|
||||
> = {
|
||||
id: 'jira_list_issue_types',
|
||||
name: 'Jira List Issue Types',
|
||||
description:
|
||||
'List all issue types visible to the user across projects (e.g., Task, Bug, Story, Epic, Subtask). Useful for discovering valid issue types before creating an issue.',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraListIssueTypesParams) => {
|
||||
if (params.cloudId) {
|
||||
return buildIssueTypesUrl(params.cloudId)
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: 'GET',
|
||||
headers: (params: JiraListIssueTypesParams) => ({
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraListIssueTypesParams) => {
|
||||
const fetchIssueTypes = async (cloudId: string) => {
|
||||
const issueTypesResponse = await fetch(buildIssueTypesUrl(cloudId), {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
if (!issueTypesResponse.ok) {
|
||||
const errorText = await issueTypesResponse.text()
|
||||
throw new Error(
|
||||
parseAtlassianErrorMessage(
|
||||
issueTypesResponse.status,
|
||||
issueTypesResponse.statusText,
|
||||
errorText
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
return issueTypesResponse.json()
|
||||
}
|
||||
|
||||
let data: any
|
||||
|
||||
if (!params?.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params!.domain, params!.accessToken)
|
||||
data = await fetchIssueTypes(cloudId)
|
||||
} else {
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
throw new Error(parseAtlassianErrorMessage(response.status, response.statusText, errorText))
|
||||
}
|
||||
data = await response.json()
|
||||
}
|
||||
|
||||
const issueTypes = Array.isArray(data) ? data : []
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
issueTypes: issueTypes.map((t: any) => ({
|
||||
id: t?.id ?? '',
|
||||
name: t?.name ?? '',
|
||||
description: t?.description ?? null,
|
||||
subtask: t?.subtask ?? null,
|
||||
hierarchyLevel: typeof t?.hierarchyLevel === 'number' ? t.hierarchyLevel : null,
|
||||
iconUrl: t?.iconUrl ?? null,
|
||||
scope: t?.scope?.project?.id ?? null,
|
||||
})),
|
||||
total: issueTypes.length,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
issueTypes: {
|
||||
type: 'array',
|
||||
description: 'Array of issue types',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: { type: 'string', description: 'Issue type ID' },
|
||||
name: { type: 'string', description: 'Issue type name (e.g., Task, Bug, Story)' },
|
||||
description: { type: 'string', description: 'Issue type description', optional: true },
|
||||
subtask: {
|
||||
type: 'boolean',
|
||||
description: 'Whether this issue type is a subtask',
|
||||
optional: true,
|
||||
},
|
||||
hierarchyLevel: {
|
||||
type: 'number',
|
||||
description: 'Hierarchy level (0 = standard, 1 = epic, -1 = subtask)',
|
||||
optional: true,
|
||||
},
|
||||
iconUrl: { type: 'string', description: 'URL of the issue type icon', optional: true },
|
||||
scope: {
|
||||
type: 'string',
|
||||
description: 'Project ID if this issue type is scoped to a team-managed project',
|
||||
optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
total: { type: 'number', description: 'Number of issue types returned' },
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
import type { JiraListProjectsParams, JiraListProjectsResponse } from '@/tools/jira/types'
|
||||
import { TIMESTAMP_OUTPUT } from '@/tools/jira/types'
|
||||
import { getJiraCloudId, parseAtlassianErrorMessage } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
/**
|
||||
* Transforms a raw Jira project object into typed output.
|
||||
*/
|
||||
function transformProject(project: any) {
|
||||
return {
|
||||
id: project.id ?? '',
|
||||
key: project.key ?? '',
|
||||
name: project.name ?? '',
|
||||
projectTypeKey: project.projectTypeKey ?? null,
|
||||
simplified: project.simplified ?? null,
|
||||
style: project.style ?? null,
|
||||
isPrivate: project.isPrivate ?? null,
|
||||
url: project.self ?? null,
|
||||
leadDisplayName: project.lead?.displayName ?? null,
|
||||
leadAccountId: project.lead?.accountId ?? null,
|
||||
}
|
||||
}
|
||||
|
||||
function buildSearchUrl(cloudId: string, params: JiraListProjectsParams): string {
|
||||
const queryParams = new URLSearchParams()
|
||||
// `lead` is not returned by default on project/search — expand it so the lead outputs populate.
|
||||
queryParams.append('expand', 'lead')
|
||||
if (params.query) queryParams.append('query', params.query)
|
||||
if (params.startAt !== undefined) queryParams.append('startAt', String(params.startAt))
|
||||
if (params.maxResults !== undefined) queryParams.append('maxResults', String(params.maxResults))
|
||||
const queryString = queryParams.toString()
|
||||
return `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/project/search${queryString ? `?${queryString}` : ''}`
|
||||
}
|
||||
|
||||
export const jiraListProjectsTool: ToolConfig<JiraListProjectsParams, JiraListProjectsResponse> = {
|
||||
id: 'jira_list_projects',
|
||||
name: 'Jira List Projects',
|
||||
description:
|
||||
'List Jira projects visible to the user, with optional name/key filtering and pagination. Returns each project with id, key, name, and type.',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
query: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Filter projects by partial name or key match',
|
||||
},
|
||||
startAt: {
|
||||
type: 'number',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'The index of the first project to return (for pagination, default: 0)',
|
||||
},
|
||||
maxResults: {
|
||||
type: 'number',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Maximum number of projects to return (default: 50, max: 100)',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraListProjectsParams) => {
|
||||
if (params.cloudId) {
|
||||
return buildSearchUrl(params.cloudId, params)
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: 'GET',
|
||||
headers: (params: JiraListProjectsParams) => ({
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraListProjectsParams) => {
|
||||
const fetchProjects = async (cloudId: string) => {
|
||||
const projectsResponse = await fetch(buildSearchUrl(cloudId, params!), {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
if (!projectsResponse.ok) {
|
||||
const errorText = await projectsResponse.text()
|
||||
throw new Error(
|
||||
parseAtlassianErrorMessage(
|
||||
projectsResponse.status,
|
||||
projectsResponse.statusText,
|
||||
errorText
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
return projectsResponse.json()
|
||||
}
|
||||
|
||||
let data: any
|
||||
|
||||
if (!params?.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params!.domain, params!.accessToken)
|
||||
data = await fetchProjects(cloudId)
|
||||
} else {
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
throw new Error(parseAtlassianErrorMessage(response.status, response.statusText, errorText))
|
||||
}
|
||||
data = await response.json()
|
||||
}
|
||||
|
||||
const values = Array.isArray(data?.values) ? data.values : []
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
projects: values.map(transformProject),
|
||||
total: typeof data?.total === 'number' ? data.total : values.length,
|
||||
startAt: typeof data?.startAt === 'number' ? data.startAt : (params?.startAt ?? 0),
|
||||
maxResults:
|
||||
typeof data?.maxResults === 'number' ? data.maxResults : (params?.maxResults ?? 50),
|
||||
isLast: data?.isLast ?? null,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
projects: {
|
||||
type: 'array',
|
||||
description: 'Array of Jira projects',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: { type: 'string', description: 'Project ID' },
|
||||
key: { type: 'string', description: 'Project key (e.g., PROJ)' },
|
||||
name: { type: 'string', description: 'Project name' },
|
||||
projectTypeKey: {
|
||||
type: 'string',
|
||||
description: 'Project type key (e.g., software, service_desk, business)',
|
||||
optional: true,
|
||||
},
|
||||
simplified: {
|
||||
type: 'boolean',
|
||||
description: 'Whether the project is a simplified (team-managed) project',
|
||||
optional: true,
|
||||
},
|
||||
style: {
|
||||
type: 'string',
|
||||
description: 'Project style (e.g., classic, next-gen)',
|
||||
optional: true,
|
||||
},
|
||||
isPrivate: {
|
||||
type: 'boolean',
|
||||
description: 'Whether the project is private',
|
||||
optional: true,
|
||||
},
|
||||
url: { type: 'string', description: 'REST API URL for this project', optional: true },
|
||||
leadDisplayName: {
|
||||
type: 'string',
|
||||
description: 'Display name of the project lead',
|
||||
optional: true,
|
||||
},
|
||||
leadAccountId: {
|
||||
type: 'string',
|
||||
description: 'Account ID of the project lead',
|
||||
optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
total: { type: 'number', description: 'Total number of matching projects' },
|
||||
startAt: { type: 'number', description: 'Pagination start index' },
|
||||
maxResults: { type: 'number', description: 'Maximum results per page' },
|
||||
isLast: {
|
||||
type: 'boolean',
|
||||
description: 'Whether this is the last page of results',
|
||||
optional: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
import type { JiraRemoveWatcherParams, JiraRemoveWatcherResponse } from '@/tools/jira/types'
|
||||
import { SUCCESS_OUTPUT, TIMESTAMP_OUTPUT } from '@/tools/jira/types'
|
||||
import { getJiraCloudId } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const jiraRemoveWatcherTool: ToolConfig<JiraRemoveWatcherParams, JiraRemoveWatcherResponse> =
|
||||
{
|
||||
id: 'jira_remove_watcher',
|
||||
name: 'Jira Remove Watcher',
|
||||
description: 'Remove a watcher from a Jira issue',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
issueKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Jira issue key to remove watcher from (e.g., PROJ-123)',
|
||||
},
|
||||
accountId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Account ID of the user to remove as watcher',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraRemoveWatcherParams) => {
|
||||
if (params.cloudId) {
|
||||
return `https://api.atlassian.com/ex/jira/${params.cloudId}/rest/api/3/issue/${params.issueKey?.trim() ?? ''}/watchers?accountId=${encodeURIComponent(params.accountId?.trim() ?? '')}`
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: (params: JiraRemoveWatcherParams) => (params.cloudId ? 'DELETE' : 'GET'),
|
||||
headers: (params: JiraRemoveWatcherParams) => {
|
||||
return {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraRemoveWatcherParams) => {
|
||||
if (!params?.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params!.domain, params!.accessToken)
|
||||
const watcherUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issue/${params!.issueKey?.trim() ?? ''}/watchers?accountId=${encodeURIComponent(params!.accountId?.trim() ?? '')}`
|
||||
const watcherResponse = await fetch(watcherUrl, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
if (!watcherResponse.ok) {
|
||||
let message = `Failed to remove watcher from Jira issue (${watcherResponse.status})`
|
||||
try {
|
||||
const err = await watcherResponse.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: params!.issueKey || 'unknown',
|
||||
watcherAccountId: params!.accountId || 'unknown',
|
||||
success: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
let message = `Failed to remove watcher from Jira issue (${response.status})`
|
||||
try {
|
||||
const err = await response.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: params!.issueKey || 'unknown',
|
||||
watcherAccountId: params!.accountId || 'unknown',
|
||||
success: true,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
success: SUCCESS_OUTPUT,
|
||||
issueKey: { type: 'string', description: 'Issue key' },
|
||||
watcherAccountId: { type: 'string', description: 'Removed watcher account ID' },
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,370 @@
|
||||
import { createLogger } from '@sim/logger'
|
||||
import type { JiraRetrieveParams, JiraRetrieveResponse } from '@/tools/jira/types'
|
||||
import { ISSUE_ITEM_PROPERTIES, TIMESTAMP_OUTPUT } from '@/tools/jira/types'
|
||||
import {
|
||||
downloadJiraAttachments,
|
||||
extractAdfText,
|
||||
getJiraCloudId,
|
||||
transformUser,
|
||||
} from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
const logger = createLogger('JiraRetrieveTool')
|
||||
|
||||
/**
|
||||
* Transforms a raw Jira API issue response into a fully typed output.
|
||||
*/
|
||||
function transformIssueData(data: any) {
|
||||
const fields = data?.fields ?? {}
|
||||
return {
|
||||
id: data?.id ?? '',
|
||||
issueKey: data?.key ?? '',
|
||||
key: data?.key ?? '',
|
||||
self: data?.self ?? '',
|
||||
summary: fields.summary ?? '',
|
||||
description: extractAdfText(fields.description),
|
||||
status: {
|
||||
id: fields.status?.id ?? '',
|
||||
name: fields.status?.name ?? '',
|
||||
description: fields.status?.description ?? null,
|
||||
statusCategory: fields.status?.statusCategory
|
||||
? {
|
||||
id: fields.status.statusCategory.id,
|
||||
key: fields.status.statusCategory.key ?? '',
|
||||
name: fields.status.statusCategory.name ?? '',
|
||||
colorName: fields.status.statusCategory.colorName ?? '',
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
issuetype: {
|
||||
id: fields.issuetype?.id ?? '',
|
||||
name: fields.issuetype?.name ?? '',
|
||||
description: fields.issuetype?.description ?? null,
|
||||
subtask: fields.issuetype?.subtask ?? false,
|
||||
iconUrl: fields.issuetype?.iconUrl ?? null,
|
||||
},
|
||||
project: {
|
||||
id: fields.project?.id ?? '',
|
||||
key: fields.project?.key ?? '',
|
||||
name: fields.project?.name ?? '',
|
||||
projectTypeKey: fields.project?.projectTypeKey ?? null,
|
||||
},
|
||||
priority: fields.priority
|
||||
? {
|
||||
id: fields.priority.id ?? '',
|
||||
name: fields.priority.name ?? '',
|
||||
iconUrl: fields.priority.iconUrl ?? null,
|
||||
}
|
||||
: null,
|
||||
statusName: fields.status?.name ?? '',
|
||||
assignee: transformUser(fields.assignee),
|
||||
assigneeName: fields.assignee?.displayName ?? fields.assignee?.accountId ?? null,
|
||||
reporter: transformUser(fields.reporter),
|
||||
creator: transformUser(fields.creator),
|
||||
labels: fields.labels ?? [],
|
||||
components: (fields.components ?? []).map((c: any) => ({
|
||||
id: c.id ?? '',
|
||||
name: c.name ?? '',
|
||||
description: c.description ?? null,
|
||||
})),
|
||||
fixVersions: (fields.fixVersions ?? []).map((v: any) => ({
|
||||
id: v.id ?? '',
|
||||
name: v.name ?? '',
|
||||
released: v.released ?? null,
|
||||
releaseDate: v.releaseDate ?? null,
|
||||
})),
|
||||
resolution: fields.resolution
|
||||
? {
|
||||
id: fields.resolution.id ?? '',
|
||||
name: fields.resolution.name ?? '',
|
||||
description: fields.resolution.description ?? null,
|
||||
}
|
||||
: null,
|
||||
duedate: fields.duedate ?? null,
|
||||
created: fields.created ?? '',
|
||||
updated: fields.updated ?? '',
|
||||
resolutiondate: fields.resolutiondate ?? null,
|
||||
timetracking: fields.timetracking
|
||||
? {
|
||||
originalEstimate: fields.timetracking.originalEstimate ?? null,
|
||||
remainingEstimate: fields.timetracking.remainingEstimate ?? null,
|
||||
timeSpent: fields.timetracking.timeSpent ?? null,
|
||||
originalEstimateSeconds: fields.timetracking.originalEstimateSeconds ?? null,
|
||||
remainingEstimateSeconds: fields.timetracking.remainingEstimateSeconds ?? null,
|
||||
timeSpentSeconds: fields.timetracking.timeSpentSeconds ?? null,
|
||||
}
|
||||
: null,
|
||||
parent: fields.parent
|
||||
? {
|
||||
id: fields.parent.id ?? '',
|
||||
key: fields.parent.key ?? '',
|
||||
summary: fields.parent.fields?.summary ?? null,
|
||||
}
|
||||
: null,
|
||||
issuelinks: (fields.issuelinks ?? []).map((link: any) => ({
|
||||
id: link.id ?? '',
|
||||
type: {
|
||||
id: link.type?.id ?? '',
|
||||
name: link.type?.name ?? '',
|
||||
inward: link.type?.inward ?? '',
|
||||
outward: link.type?.outward ?? '',
|
||||
},
|
||||
inwardIssue: link.inwardIssue
|
||||
? {
|
||||
id: link.inwardIssue.id ?? '',
|
||||
key: link.inwardIssue.key ?? '',
|
||||
statusName: link.inwardIssue.fields?.status?.name ?? null,
|
||||
summary: link.inwardIssue.fields?.summary ?? null,
|
||||
}
|
||||
: null,
|
||||
outwardIssue: link.outwardIssue
|
||||
? {
|
||||
id: link.outwardIssue.id ?? '',
|
||||
key: link.outwardIssue.key ?? '',
|
||||
statusName: link.outwardIssue.fields?.status?.name ?? null,
|
||||
summary: link.outwardIssue.fields?.summary ?? null,
|
||||
}
|
||||
: null,
|
||||
})),
|
||||
subtasks: (fields.subtasks ?? []).map((sub: any) => ({
|
||||
id: sub.id ?? '',
|
||||
key: sub.key ?? '',
|
||||
summary: sub.fields?.summary ?? '',
|
||||
statusName: sub.fields?.status?.name ?? '',
|
||||
issueTypeName: sub.fields?.issuetype?.name ?? null,
|
||||
})),
|
||||
votes: fields.votes
|
||||
? {
|
||||
votes: fields.votes.votes ?? 0,
|
||||
hasVoted: fields.votes.hasVoted ?? false,
|
||||
}
|
||||
: null,
|
||||
watches:
|
||||
(fields.watches ?? fields.watcher)
|
||||
? {
|
||||
watchCount: (fields.watches ?? fields.watcher)?.watchCount ?? 0,
|
||||
isWatching: (fields.watches ?? fields.watcher)?.isWatching ?? false,
|
||||
}
|
||||
: null,
|
||||
comments: ((fields.comment?.comments ?? fields.comment) || []).map((c: any) => ({
|
||||
id: c.id ?? '',
|
||||
body: extractAdfText(c.body) ?? '',
|
||||
author: transformUser(c.author),
|
||||
authorName: c.author?.displayName ?? c.author?.accountId ?? 'Unknown',
|
||||
updateAuthor: transformUser(c.updateAuthor),
|
||||
created: c.created ?? '',
|
||||
updated: c.updated ?? '',
|
||||
visibility: c.visibility
|
||||
? { type: c.visibility.type ?? '', value: c.visibility.value ?? '' }
|
||||
: null,
|
||||
})),
|
||||
worklogs: ((fields.worklog?.worklogs ?? fields.worklog) || []).map((w: any) => ({
|
||||
id: w.id ?? '',
|
||||
author: transformUser(w.author),
|
||||
authorName: w.author?.displayName ?? w.author?.accountId ?? 'Unknown',
|
||||
updateAuthor: transformUser(w.updateAuthor),
|
||||
comment: w.comment ? (extractAdfText(w.comment) ?? null) : null,
|
||||
started: w.started ?? '',
|
||||
timeSpent: w.timeSpent ?? '',
|
||||
timeSpentSeconds: w.timeSpentSeconds ?? 0,
|
||||
created: w.created ?? '',
|
||||
updated: w.updated ?? '',
|
||||
})),
|
||||
attachments: (fields.attachment ?? []).map((att: any) => ({
|
||||
id: att.id ?? '',
|
||||
filename: att.filename ?? '',
|
||||
mimeType: att.mimeType ?? '',
|
||||
size: att.size ?? 0,
|
||||
content: att.content ?? '',
|
||||
thumbnail: att.thumbnail ?? null,
|
||||
author: transformUser(att.author),
|
||||
authorName: att.author?.displayName ?? att.author?.accountId ?? 'Unknown',
|
||||
created: att.created ?? '',
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
export const jiraRetrieveTool: ToolConfig<JiraRetrieveParams, JiraRetrieveResponse> = {
|
||||
id: 'jira_retrieve',
|
||||
name: 'Jira Retrieve',
|
||||
description: 'Retrieve detailed information about a specific Jira issue',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
issueKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Jira issue key to retrieve (e.g., PROJ-123)',
|
||||
},
|
||||
includeAttachments: {
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Download attachment file contents and include them as files in the output',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraRetrieveParams) => {
|
||||
if (params.cloudId) {
|
||||
return `https://api.atlassian.com/ex/jira/${params.cloudId}/rest/api/3/issue/${params.issueKey?.trim() ?? ''}?expand=renderedFields,names,schema,transitions,operations,editmeta,changelog,versionedRepresentations`
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: 'GET',
|
||||
headers: (params: JiraRetrieveParams) => {
|
||||
return {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraRetrieveParams) => {
|
||||
if (!params?.issueKey) {
|
||||
throw new Error('Provide an issue key to retrieve a single issue.')
|
||||
}
|
||||
|
||||
const fetchIssue = async (cloudId: string) => {
|
||||
const issueUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issue/${params.issueKey?.trim() ?? ''}?expand=renderedFields,names,schema,transitions,operations,editmeta,changelog,versionedRepresentations`
|
||||
const issueResponse = await fetch(issueUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
if (!issueResponse.ok) {
|
||||
let message = `Failed to fetch Jira issue (${issueResponse.status})`
|
||||
try {
|
||||
const err = await issueResponse.json()
|
||||
message = err?.message || err?.errorMessages?.[0] || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return issueResponse.json()
|
||||
}
|
||||
|
||||
const fetchSupplementary = async (cloudId: string, data: any) => {
|
||||
const base = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issue/${params.issueKey?.trim() ?? ''}`
|
||||
const [commentsResp, worklogResp, watchersResp] = await Promise.all([
|
||||
fetch(`${base}/comment?maxResults=100&orderBy=-created`, {
|
||||
headers: { Accept: 'application/json', Authorization: `Bearer ${params.accessToken}` },
|
||||
}),
|
||||
fetch(`${base}/worklog?maxResults=100`, {
|
||||
headers: { Accept: 'application/json', Authorization: `Bearer ${params.accessToken}` },
|
||||
}),
|
||||
fetch(`${base}/watchers`, {
|
||||
headers: { Accept: 'application/json', Authorization: `Bearer ${params.accessToken}` },
|
||||
}),
|
||||
])
|
||||
|
||||
try {
|
||||
if (commentsResp.ok) {
|
||||
const commentsData = await commentsResp.json()
|
||||
if (data?.fields) data.fields.comment = commentsData?.comments || data.fields.comment
|
||||
}
|
||||
} catch {
|
||||
logger.debug?.('Failed to fetch comments')
|
||||
}
|
||||
|
||||
try {
|
||||
if (worklogResp.ok) {
|
||||
const worklogData = await worklogResp.json()
|
||||
if (data?.fields) data.fields.worklog = worklogData || data.fields.worklog
|
||||
}
|
||||
} catch {
|
||||
logger.debug?.('Failed to fetch worklog')
|
||||
}
|
||||
|
||||
try {
|
||||
if (watchersResp.ok) {
|
||||
const watchersData = await watchersResp.json()
|
||||
if (data?.fields) {
|
||||
data.fields.watches = watchersData
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
logger.debug?.('Failed to fetch watchers')
|
||||
}
|
||||
}
|
||||
|
||||
let data: any
|
||||
|
||||
if (!params.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params.domain, params.accessToken)
|
||||
data = await fetchIssue(cloudId)
|
||||
await fetchSupplementary(cloudId, data)
|
||||
} else {
|
||||
if (!response.ok) {
|
||||
let message = `Failed to fetch Jira issue (${response.status})`
|
||||
try {
|
||||
const err = await response.json()
|
||||
message = err?.message || err?.errorMessages?.[0] || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
data = await response.json()
|
||||
await fetchSupplementary(params.cloudId, data)
|
||||
}
|
||||
|
||||
const issueData = transformIssueData(data)
|
||||
|
||||
let files: Array<{ name: string; mimeType: string; data: string; size: number }> | undefined
|
||||
if (params?.includeAttachments && issueData.attachments.length > 0) {
|
||||
files = await downloadJiraAttachments(issueData.attachments, params.accessToken)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
...issueData,
|
||||
issue: data,
|
||||
...(files && files.length > 0 ? { files } : {}),
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
...ISSUE_ITEM_PROPERTIES,
|
||||
issue: {
|
||||
type: 'json',
|
||||
description: 'Complete raw Jira issue object from the API',
|
||||
optional: true,
|
||||
},
|
||||
files: {
|
||||
type: 'file[]',
|
||||
description: 'Downloaded attachment files (only when includeAttachments is true)',
|
||||
optional: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
import type { JiraSearchIssuesParams, JiraSearchIssuesResponse } from '@/tools/jira/types'
|
||||
import { SEARCH_ISSUE_ITEM_PROPERTIES, TIMESTAMP_OUTPUT } from '@/tools/jira/types'
|
||||
import { extractAdfText, getJiraCloudId, transformUser } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
/**
|
||||
* Transforms a raw Jira search result issue into typed output.
|
||||
*/
|
||||
function transformSearchIssue(issue: any) {
|
||||
const fields = issue?.fields ?? {}
|
||||
return {
|
||||
id: issue.id ?? '',
|
||||
key: issue.key ?? '',
|
||||
self: issue.self ?? '',
|
||||
summary: fields.summary ?? '',
|
||||
description: extractAdfText(fields.description),
|
||||
status: {
|
||||
id: fields.status?.id ?? '',
|
||||
name: fields.status?.name ?? '',
|
||||
description: fields.status?.description ?? null,
|
||||
statusCategory: fields.status?.statusCategory
|
||||
? {
|
||||
id: fields.status.statusCategory.id,
|
||||
key: fields.status.statusCategory.key ?? '',
|
||||
name: fields.status.statusCategory.name ?? '',
|
||||
colorName: fields.status.statusCategory.colorName ?? '',
|
||||
}
|
||||
: null,
|
||||
},
|
||||
issuetype: {
|
||||
id: fields.issuetype?.id ?? '',
|
||||
name: fields.issuetype?.name ?? '',
|
||||
description: fields.issuetype?.description ?? null,
|
||||
subtask: fields.issuetype?.subtask ?? false,
|
||||
iconUrl: fields.issuetype?.iconUrl ?? null,
|
||||
},
|
||||
project: {
|
||||
id: fields.project?.id ?? '',
|
||||
key: fields.project?.key ?? '',
|
||||
name: fields.project?.name ?? '',
|
||||
projectTypeKey: fields.project?.projectTypeKey ?? null,
|
||||
},
|
||||
priority: fields.priority
|
||||
? {
|
||||
id: fields.priority.id ?? '',
|
||||
name: fields.priority.name ?? '',
|
||||
iconUrl: fields.priority.iconUrl ?? null,
|
||||
}
|
||||
: null,
|
||||
statusName: fields.status?.name ?? '',
|
||||
assignee: transformUser(fields.assignee),
|
||||
assigneeName: fields.assignee?.displayName ?? fields.assignee?.accountId ?? null,
|
||||
reporter: transformUser(fields.reporter),
|
||||
labels: fields.labels ?? [],
|
||||
components: (fields.components ?? []).map((c: any) => ({
|
||||
id: c.id ?? '',
|
||||
name: c.name ?? '',
|
||||
description: c.description ?? null,
|
||||
})),
|
||||
resolution: fields.resolution
|
||||
? {
|
||||
id: fields.resolution.id ?? '',
|
||||
name: fields.resolution.name ?? '',
|
||||
description: fields.resolution.description ?? null,
|
||||
}
|
||||
: null,
|
||||
duedate: fields.duedate ?? null,
|
||||
created: fields.created ?? '',
|
||||
updated: fields.updated ?? '',
|
||||
}
|
||||
}
|
||||
|
||||
export const jiraSearchIssuesTool: ToolConfig<JiraSearchIssuesParams, JiraSearchIssuesResponse> = {
|
||||
id: 'jira_search_issues',
|
||||
name: 'Jira Search Issues',
|
||||
description: 'Search for Jira issues using JQL (Jira Query Language)',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
jql: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'JQL query string to search for issues (e.g., "project = PROJ AND status = Open")',
|
||||
},
|
||||
nextPageToken: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Cursor token for the next page of results. Omit for the first page.',
|
||||
},
|
||||
maxResults: {
|
||||
type: 'number',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Maximum number of results to return per page (default: 50)',
|
||||
},
|
||||
fields: {
|
||||
type: 'array',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Array of field names to return (default: all fields).',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraSearchIssuesParams) => {
|
||||
if (params.cloudId) {
|
||||
const query = new URLSearchParams()
|
||||
if (params.jql) query.set('jql', params.jql)
|
||||
if (params.nextPageToken) query.set('nextPageToken', params.nextPageToken)
|
||||
if (typeof params.maxResults === 'number')
|
||||
query.set('maxResults', String(params.maxResults))
|
||||
if (Array.isArray(params.fields) && params.fields.length > 0) {
|
||||
query.set('fields', params.fields.join(','))
|
||||
} else {
|
||||
query.set('fields', '*all')
|
||||
}
|
||||
const qs = query.toString()
|
||||
return `https://api.atlassian.com/ex/jira/${params.cloudId}/rest/api/3/search/jql${qs ? `?${qs}` : ''}`
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: () => 'GET',
|
||||
headers: (params: JiraSearchIssuesParams) => ({
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}),
|
||||
body: () => undefined as any,
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraSearchIssuesParams) => {
|
||||
const performSearch = async (cloudId: string) => {
|
||||
const query = new URLSearchParams()
|
||||
if (params?.jql) query.set('jql', params.jql)
|
||||
if (params?.nextPageToken) query.set('nextPageToken', params.nextPageToken)
|
||||
if (typeof params?.maxResults === 'number') query.set('maxResults', String(params.maxResults))
|
||||
if (Array.isArray(params?.fields) && params.fields.length > 0) {
|
||||
query.set('fields', params.fields.join(','))
|
||||
} else {
|
||||
query.set('fields', '*all')
|
||||
}
|
||||
const searchUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/search/jql?${query.toString()}`
|
||||
const searchResponse = await fetch(searchUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
if (!searchResponse.ok) {
|
||||
let message = `Failed to search Jira issues (${searchResponse.status})`
|
||||
try {
|
||||
const err = await searchResponse.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return searchResponse.json()
|
||||
}
|
||||
|
||||
let data: any
|
||||
|
||||
if (!params?.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params!.domain, params!.accessToken)
|
||||
data = await performSearch(cloudId)
|
||||
} else {
|
||||
if (!response.ok) {
|
||||
let message = `Failed to search Jira issues (${response.status})`
|
||||
try {
|
||||
const err = await response.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
data = await response.json()
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
issues: (data?.issues ?? []).map(transformSearchIssue),
|
||||
nextPageToken: data?.nextPageToken ?? null,
|
||||
isLast: data?.isLast ?? !data?.nextPageToken,
|
||||
total: null,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
issues: {
|
||||
type: 'array',
|
||||
description: 'Array of matching issues',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: SEARCH_ISSUE_ITEM_PROPERTIES,
|
||||
},
|
||||
},
|
||||
nextPageToken: {
|
||||
type: 'string',
|
||||
description: 'Cursor token for the next page. Null when no more results.',
|
||||
optional: true,
|
||||
},
|
||||
isLast: { type: 'boolean', description: 'Whether this is the last page of results' },
|
||||
total: {
|
||||
type: 'number',
|
||||
description:
|
||||
'Always null. The Jira /search/jql endpoint does not return a total count; use isLast and nextPageToken for pagination.',
|
||||
optional: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
import type { JiraSearchUsersParams, JiraSearchUsersResponse } from '@/tools/jira/types'
|
||||
import { TIMESTAMP_OUTPUT, USER_OUTPUT_PROPERTIES } from '@/tools/jira/types'
|
||||
import { getJiraCloudId, transformUser } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const jiraSearchUsersTool: ToolConfig<JiraSearchUsersParams, JiraSearchUsersResponse> = {
|
||||
id: 'jira_search_users',
|
||||
name: 'Jira Search Users',
|
||||
description:
|
||||
'Search for Jira users by email address or display name. Returns matching users with their accountId, displayName, and emailAddress.',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
query: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'A query string to search for users. Can be an email address, display name, or partial match.',
|
||||
},
|
||||
maxResults: {
|
||||
type: 'number',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Maximum number of users to return (default: 50, max: 1000)',
|
||||
},
|
||||
startAt: {
|
||||
type: 'number',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'The index of the first user to return (for pagination, default: 0)',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraSearchUsersParams) => {
|
||||
if (params.cloudId) {
|
||||
const queryParams = new URLSearchParams()
|
||||
queryParams.append('query', params.query)
|
||||
if (params.maxResults !== undefined)
|
||||
queryParams.append('maxResults', String(params.maxResults))
|
||||
if (params.startAt !== undefined) queryParams.append('startAt', String(params.startAt))
|
||||
return `https://api.atlassian.com/ex/jira/${params.cloudId}/rest/api/3/user/search?${queryParams.toString()}`
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: 'GET',
|
||||
headers: (params: JiraSearchUsersParams) => ({
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraSearchUsersParams) => {
|
||||
const fetchUsers = async (cloudId: string) => {
|
||||
const queryParams = new URLSearchParams()
|
||||
queryParams.append('query', params!.query)
|
||||
if (params!.maxResults !== undefined)
|
||||
queryParams.append('maxResults', String(params!.maxResults))
|
||||
if (params!.startAt !== undefined) queryParams.append('startAt', String(params!.startAt))
|
||||
|
||||
const usersUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/user/search?${queryParams.toString()}`
|
||||
|
||||
const usersResponse = await fetch(usersUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
if (!usersResponse.ok) {
|
||||
let message = `Failed to search Jira users (${usersResponse.status})`
|
||||
try {
|
||||
const err = await usersResponse.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return usersResponse.json()
|
||||
}
|
||||
|
||||
let data: any
|
||||
|
||||
if (!params?.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params!.domain, params!.accessToken)
|
||||
data = await fetchUsers(cloudId)
|
||||
} else {
|
||||
if (!response.ok) {
|
||||
let message = `Failed to search Jira users (${response.status})`
|
||||
try {
|
||||
const err = await response.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
data = await response.json()
|
||||
}
|
||||
|
||||
const users = Array.isArray(data) ? data.filter(Boolean) : []
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
users: users.map((user: any) => ({
|
||||
...(transformUser(user) ?? { accountId: '', displayName: '' }),
|
||||
self: user.self ?? null,
|
||||
})),
|
||||
total: users.length,
|
||||
startAt: params?.startAt ?? 0,
|
||||
maxResults: params?.maxResults ?? 50,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
users: {
|
||||
type: 'array',
|
||||
description: 'Array of matching Jira users',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
...USER_OUTPUT_PROPERTIES,
|
||||
self: {
|
||||
type: 'string',
|
||||
description: 'REST API URL for this user',
|
||||
optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
total: {
|
||||
type: 'number',
|
||||
description: 'Number of users returned in this page (may be less than total matches)',
|
||||
},
|
||||
startAt: { type: 'number', description: 'Pagination start index' },
|
||||
maxResults: { type: 'number', description: 'Maximum results per page' },
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
import type { JiraTransitionIssueParams, JiraTransitionIssueResponse } from '@/tools/jira/types'
|
||||
import { SUCCESS_OUTPUT, TIMESTAMP_OUTPUT } from '@/tools/jira/types'
|
||||
import { getJiraCloudId, toAdf } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const jiraTransitionIssueTool: ToolConfig<
|
||||
JiraTransitionIssueParams,
|
||||
JiraTransitionIssueResponse
|
||||
> = {
|
||||
id: 'jira_transition_issue',
|
||||
name: 'Jira Transition Issue',
|
||||
description: 'Move a Jira issue between workflow statuses (e.g., To Do -> In Progress)',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
issueKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Jira issue key to transition (e.g., PROJ-123)',
|
||||
},
|
||||
transitionId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'ID of the transition to execute (e.g., "11" for "To Do", "21" for "In Progress")',
|
||||
},
|
||||
comment: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Optional comment to add when transitioning the issue',
|
||||
},
|
||||
resolution: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Resolution name to set during transition (e.g., "Fixed", "Won\'t Fix")',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraTransitionIssueParams) => {
|
||||
if (params.cloudId) {
|
||||
return `https://api.atlassian.com/ex/jira/${params.cloudId}/rest/api/3/issue/${params.issueKey?.trim() ?? ''}/transitions`
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: (params: JiraTransitionIssueParams) => (params.cloudId ? 'POST' : 'GET'),
|
||||
headers: (params: JiraTransitionIssueParams) => {
|
||||
return {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}
|
||||
},
|
||||
body: (params: JiraTransitionIssueParams) => {
|
||||
if (!params.cloudId) return undefined as any
|
||||
return buildTransitionBody(params)
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraTransitionIssueParams) => {
|
||||
const performTransition = async (cloudId: string) => {
|
||||
// First, fetch available transitions to get the name and target status
|
||||
const transitionsUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issue/${params!.issueKey?.trim() ?? ''}/transitions`
|
||||
const transitionsResp = await fetch(transitionsUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
let transitionName: string | null = null
|
||||
let toStatus: { id: string; name: string } | null = null
|
||||
|
||||
if (transitionsResp.ok) {
|
||||
const transitionsData = await transitionsResp.json()
|
||||
const transition = (transitionsData?.transitions ?? []).find(
|
||||
(t: any) => String(t.id) === String(params!.transitionId)
|
||||
)
|
||||
if (transition) {
|
||||
transitionName = transition.name ?? null
|
||||
toStatus = transition.to
|
||||
? { id: transition.to.id ?? '', name: transition.to.name ?? '' }
|
||||
: null
|
||||
}
|
||||
}
|
||||
|
||||
// Perform the transition
|
||||
const transitionResponse = await fetch(transitionsUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
body: JSON.stringify(buildTransitionBody(params!)),
|
||||
})
|
||||
|
||||
if (!transitionResponse.ok) {
|
||||
let message = `Failed to transition Jira issue (${transitionResponse.status})`
|
||||
try {
|
||||
const err = await transitionResponse.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return { transitionName, toStatus }
|
||||
}
|
||||
|
||||
let transitionName: string | null = null
|
||||
let toStatus: { id: string; name: string } | null = null
|
||||
|
||||
if (!params?.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params!.domain, params!.accessToken)
|
||||
const result = await performTransition(cloudId)
|
||||
transitionName = result.transitionName
|
||||
toStatus = result.toStatus
|
||||
} else {
|
||||
// When cloudId was provided, the initial request was the POST transition.
|
||||
// We need to fetch transition metadata separately.
|
||||
if (!response.ok) {
|
||||
let message = `Failed to transition Jira issue (${response.status})`
|
||||
try {
|
||||
const err = await response.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
// Fetch transition metadata for the response
|
||||
try {
|
||||
const transitionsUrl = `https://api.atlassian.com/ex/jira/${params.cloudId}/rest/api/3/issue/${params.issueKey?.trim() ?? ''}/transitions`
|
||||
const transitionsResp = await fetch(transitionsUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
},
|
||||
})
|
||||
if (transitionsResp.ok) {
|
||||
const transitionsData = await transitionsResp.json()
|
||||
const transition = (transitionsData?.transitions ?? []).find(
|
||||
(t: any) => String(t.id) === String(params.transitionId)
|
||||
)
|
||||
if (transition) {
|
||||
transitionName = transition.name ?? null
|
||||
toStatus = transition.to
|
||||
? { id: transition.to.id ?? '', name: transition.to.name ?? '' }
|
||||
: null
|
||||
}
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: params?.issueKey ?? 'unknown',
|
||||
transitionId: params?.transitionId ?? 'unknown',
|
||||
transitionName,
|
||||
toStatus,
|
||||
success: true,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
success: SUCCESS_OUTPUT,
|
||||
issueKey: { type: 'string', description: 'Issue key that was transitioned' },
|
||||
transitionId: { type: 'string', description: 'Applied transition ID' },
|
||||
transitionName: { type: 'string', description: 'Applied transition name', optional: true },
|
||||
toStatus: {
|
||||
type: 'object',
|
||||
description: 'Target status after transition',
|
||||
properties: {
|
||||
id: { type: 'string', description: 'Status ID' },
|
||||
name: { type: 'string', description: 'Status name' },
|
||||
},
|
||||
optional: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the transition request body per Jira API v3.
|
||||
*/
|
||||
function buildTransitionBody(params: JiraTransitionIssueParams) {
|
||||
const body: any = {
|
||||
transition: { id: params.transitionId },
|
||||
}
|
||||
|
||||
if (params.resolution) {
|
||||
body.fields = {
|
||||
...body.fields,
|
||||
resolution: { name: params.resolution },
|
||||
}
|
||||
}
|
||||
|
||||
if (params.comment) {
|
||||
body.update = {
|
||||
comment: [{ add: { body: toAdf(params.comment) } }],
|
||||
}
|
||||
}
|
||||
|
||||
return body
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,191 @@
|
||||
import type { JiraUpdateParams, JiraUpdateResponse } from '@/tools/jira/types'
|
||||
import { SUCCESS_OUTPUT, TIMESTAMP_OUTPUT } from '@/tools/jira/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const jiraUpdateTool: ToolConfig<JiraUpdateParams, JiraUpdateResponse> = {
|
||||
id: 'jira_update',
|
||||
name: 'Jira Update',
|
||||
description: 'Update a Jira issue',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
issueKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Jira issue key to update (e.g., PROJ-123)',
|
||||
},
|
||||
summary: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'New summary for the issue',
|
||||
},
|
||||
description: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'New description for the issue. Accepts plain text (auto-wrapped in ADF) or a raw ADF document object',
|
||||
},
|
||||
priority: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'New priority ID or name for the issue (e.g., "High")',
|
||||
},
|
||||
assignee: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'New assignee account ID for the issue',
|
||||
},
|
||||
labels: {
|
||||
type: 'json',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Labels to set on the issue (array of label name strings)',
|
||||
},
|
||||
components: {
|
||||
type: 'json',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Components to set on the issue (array of component name strings)',
|
||||
},
|
||||
duedate: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Due date for the issue (format: YYYY-MM-DD)',
|
||||
},
|
||||
fixVersions: {
|
||||
type: 'json',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Fix versions to set (array of version name strings)',
|
||||
},
|
||||
environment: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Environment information for the issue',
|
||||
},
|
||||
customFieldId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Custom field ID to update (e.g., customfield_10001)',
|
||||
},
|
||||
customFieldValue: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Value for the custom field',
|
||||
},
|
||||
notifyUsers: {
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Whether to send email notifications about this update (default: true)',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: '/api/tools/jira/update',
|
||||
method: 'PUT',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params) => {
|
||||
return {
|
||||
domain: params.domain,
|
||||
accessToken: params.accessToken,
|
||||
issueKey: params.issueKey,
|
||||
summary: params.summary,
|
||||
description: params.description,
|
||||
priority: params.priority,
|
||||
assignee: params.assignee,
|
||||
labels: params.labels,
|
||||
components: params.components,
|
||||
duedate: params.duedate,
|
||||
fixVersions: params.fixVersions,
|
||||
environment: params.environment,
|
||||
customFieldId: params.customFieldId,
|
||||
customFieldValue: params.customFieldValue,
|
||||
notifyUsers: params.notifyUsers,
|
||||
cloudId: params.cloudId,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const responseText = await response.text()
|
||||
|
||||
if (!responseText) {
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: 'unknown',
|
||||
summary: 'Issue updated successfully',
|
||||
success: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
let data: any
|
||||
try {
|
||||
data = JSON.parse(responseText)
|
||||
} catch {
|
||||
throw new Error(
|
||||
`Jira update failed (${response.status} ${response.statusText}): non-JSON response from /api/tools/jira/update`
|
||||
)
|
||||
}
|
||||
|
||||
if (data.success && data.output) {
|
||||
return data
|
||||
}
|
||||
|
||||
return {
|
||||
success: data.success || false,
|
||||
output: data.output || {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: 'unknown',
|
||||
summary: 'Issue updated',
|
||||
success: false,
|
||||
},
|
||||
error: data.error,
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
success: SUCCESS_OUTPUT,
|
||||
issueKey: { type: 'string', description: 'Updated issue key (e.g., PROJ-123)' },
|
||||
summary: { type: 'string', description: 'Issue summary after update' },
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
import type { JiraUpdateCommentParams, JiraUpdateCommentResponse } from '@/tools/jira/types'
|
||||
import { SUCCESS_OUTPUT, TIMESTAMP_OUTPUT, USER_OUTPUT_PROPERTIES } from '@/tools/jira/types'
|
||||
import { extractAdfText, getJiraCloudId, toAdf, transformUser } from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
/**
|
||||
* Transforms an update comment API response into typed output.
|
||||
*/
|
||||
function transformUpdateCommentResponse(data: any, params: JiraUpdateCommentParams) {
|
||||
return {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: params.issueKey ?? 'unknown',
|
||||
commentId: data?.id ?? params.commentId ?? 'unknown',
|
||||
body: data?.body ? (extractAdfText(data.body) ?? params.body ?? '') : (params.body ?? ''),
|
||||
author: transformUser(data?.author) ?? { accountId: '', displayName: '' },
|
||||
created: data?.created ?? '',
|
||||
updated: data?.updated ?? '',
|
||||
success: true,
|
||||
}
|
||||
}
|
||||
|
||||
export const jiraUpdateCommentTool: ToolConfig<JiraUpdateCommentParams, JiraUpdateCommentResponse> =
|
||||
{
|
||||
id: 'jira_update_comment',
|
||||
name: 'Jira Update Comment',
|
||||
description: 'Update an existing comment on a Jira issue',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
issueKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Jira issue key containing the comment (e.g., PROJ-123)',
|
||||
},
|
||||
commentId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'ID of the comment to update',
|
||||
},
|
||||
body: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Updated comment text',
|
||||
},
|
||||
visibility: {
|
||||
type: 'json',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'Restrict comment visibility. Object with "type" ("role" or "group") and "value" (role/group name).',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraUpdateCommentParams) => {
|
||||
if (params.cloudId) {
|
||||
return `https://api.atlassian.com/ex/jira/${params.cloudId}/rest/api/3/issue/${params.issueKey?.trim() ?? ''}/comment/${params.commentId?.trim() ?? ''}`
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: (params: JiraUpdateCommentParams) => (params.cloudId ? 'PUT' : 'GET'),
|
||||
headers: (params: JiraUpdateCommentParams) => {
|
||||
return {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}
|
||||
},
|
||||
body: (params: JiraUpdateCommentParams) => {
|
||||
if (!params.cloudId) return undefined as any
|
||||
const payload: Record<string, any> = { body: toAdf(params.body ?? '') }
|
||||
if (params.visibility) payload.visibility = params.visibility
|
||||
return payload
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraUpdateCommentParams) => {
|
||||
const payload: Record<string, any> = { body: toAdf(params?.body ?? '') }
|
||||
if (params?.visibility) payload.visibility = params.visibility
|
||||
|
||||
const makeRequest = async (cloudId: string) => {
|
||||
const commentUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issue/${params!.issueKey?.trim() ?? ''}/comment/${params!.commentId?.trim() ?? ''}`
|
||||
const commentResponse = await fetch(commentUrl, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
})
|
||||
|
||||
if (!commentResponse.ok) {
|
||||
let message = `Failed to update comment on Jira issue (${commentResponse.status})`
|
||||
try {
|
||||
const err = await commentResponse.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return commentResponse.json()
|
||||
}
|
||||
|
||||
let data: any
|
||||
|
||||
if (!params?.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params!.domain, params!.accessToken)
|
||||
data = await makeRequest(cloudId)
|
||||
} else {
|
||||
if (!response.ok) {
|
||||
let message = `Failed to update comment on Jira issue (${response.status})`
|
||||
try {
|
||||
const err = await response.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
data = await response.json()
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: transformUpdateCommentResponse(data, params!),
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
success: SUCCESS_OUTPUT,
|
||||
issueKey: { type: 'string', description: 'Issue key' },
|
||||
commentId: { type: 'string', description: 'Updated comment ID' },
|
||||
body: { type: 'string', description: 'Updated comment text' },
|
||||
author: {
|
||||
type: 'object',
|
||||
description: 'Comment author',
|
||||
properties: USER_OUTPUT_PROPERTIES,
|
||||
},
|
||||
created: { type: 'string', description: 'ISO 8601 timestamp when the comment was created' },
|
||||
updated: {
|
||||
type: 'string',
|
||||
description: 'ISO 8601 timestamp when the comment was last updated',
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
import type { JiraUpdateWorklogParams, JiraUpdateWorklogResponse } from '@/tools/jira/types'
|
||||
import { SUCCESS_OUTPUT, TIMESTAMP_OUTPUT, USER_OUTPUT_PROPERTIES } from '@/tools/jira/types'
|
||||
import {
|
||||
extractAdfText,
|
||||
getJiraCloudId,
|
||||
normalizeJiraWorklogTimestamp,
|
||||
toAdf,
|
||||
transformUser,
|
||||
} from '@/tools/jira/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
function buildWorklogBody(params: JiraUpdateWorklogParams) {
|
||||
let timeSpentSeconds: number | undefined
|
||||
if (
|
||||
params.timeSpentSeconds !== undefined &&
|
||||
params.timeSpentSeconds !== null &&
|
||||
String(params.timeSpentSeconds).trim() !== ''
|
||||
) {
|
||||
const n = Number(params.timeSpentSeconds)
|
||||
if (!Number.isFinite(n) || n <= 0) {
|
||||
throw new Error('timeSpentSeconds must be a positive finite number')
|
||||
}
|
||||
timeSpentSeconds = n
|
||||
}
|
||||
const body: Record<string, any> = {
|
||||
timeSpentSeconds,
|
||||
comment: params.comment ? toAdf(params.comment) : undefined,
|
||||
started: params.started ? normalizeJiraWorklogTimestamp(params.started) : undefined,
|
||||
}
|
||||
if (params.visibility) body.visibility = params.visibility
|
||||
return body
|
||||
}
|
||||
|
||||
function transformWorklogResponse(data: any, params: JiraUpdateWorklogParams) {
|
||||
return {
|
||||
ts: new Date().toISOString(),
|
||||
issueKey: params.issueKey || 'unknown',
|
||||
worklogId: data?.id || params.worklogId || 'unknown',
|
||||
timeSpent: data?.timeSpent ?? null,
|
||||
timeSpentSeconds: data?.timeSpentSeconds ?? null,
|
||||
comment: data?.comment ? extractAdfText(data.comment) : null,
|
||||
author: data?.author ? transformUser(data.author) : null,
|
||||
updateAuthor: data?.updateAuthor ? transformUser(data.updateAuthor) : null,
|
||||
started: data?.started || null,
|
||||
created: data?.created || null,
|
||||
updated: data?.updated || null,
|
||||
success: true,
|
||||
}
|
||||
}
|
||||
|
||||
export const jiraUpdateWorklogTool: ToolConfig<JiraUpdateWorklogParams, JiraUpdateWorklogResponse> =
|
||||
{
|
||||
id: 'jira_update_worklog',
|
||||
name: 'Jira Update Worklog',
|
||||
description: 'Update an existing worklog entry on a Jira issue',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
issueKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Jira issue key containing the worklog (e.g., PROJ-123)',
|
||||
},
|
||||
worklogId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'ID of the worklog entry to update',
|
||||
},
|
||||
timeSpentSeconds: {
|
||||
type: 'number',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Time spent in seconds',
|
||||
},
|
||||
comment: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Optional comment for the worklog entry',
|
||||
},
|
||||
started: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Optional start time in ISO format',
|
||||
},
|
||||
visibility: {
|
||||
type: 'json',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'Restrict worklog visibility. Object with "type" ("role" or "group") and "value" (role/group name).',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: JiraUpdateWorklogParams) => {
|
||||
if (params.cloudId) {
|
||||
return `https://api.atlassian.com/ex/jira/${params.cloudId}/rest/api/3/issue/${params.issueKey?.trim() ?? ''}/worklog/${params.worklogId?.trim() ?? ''}`
|
||||
}
|
||||
return 'https://api.atlassian.com/oauth/token/accessible-resources'
|
||||
},
|
||||
method: (params: JiraUpdateWorklogParams) => (params.cloudId ? 'PUT' : 'GET'),
|
||||
headers: (params: JiraUpdateWorklogParams) => {
|
||||
return {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
}
|
||||
},
|
||||
body: (params: JiraUpdateWorklogParams) => {
|
||||
if (!params.cloudId) return undefined as any
|
||||
return buildWorklogBody(params)
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params?: JiraUpdateWorklogParams) => {
|
||||
if (!params?.cloudId) {
|
||||
const cloudId = await getJiraCloudId(params!.domain, params!.accessToken)
|
||||
const worklogUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issue/${params!.issueKey?.trim() ?? ''}/worklog/${params!.worklogId?.trim() ?? ''}`
|
||||
const worklogResponse = await fetch(worklogUrl, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${params!.accessToken}`,
|
||||
},
|
||||
body: JSON.stringify(buildWorklogBody(params!)),
|
||||
})
|
||||
|
||||
if (!worklogResponse.ok) {
|
||||
let message = `Failed to update worklog on Jira issue (${worklogResponse.status})`
|
||||
try {
|
||||
const err = await worklogResponse.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
const data = await worklogResponse.json()
|
||||
return {
|
||||
success: true,
|
||||
output: transformWorklogResponse(data, params!),
|
||||
}
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
let message = `Failed to update worklog on Jira issue (${response.status})`
|
||||
try {
|
||||
const err = await response.json()
|
||||
message = err?.errorMessages?.join(', ') || err?.message || message
|
||||
} catch (_e) {}
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
return {
|
||||
success: true,
|
||||
output: transformWorklogResponse(data, params!),
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
success: SUCCESS_OUTPUT,
|
||||
issueKey: { type: 'string', description: 'Issue key' },
|
||||
worklogId: { type: 'string', description: 'Updated worklog ID' },
|
||||
timeSpent: { type: 'string', description: 'Human-readable time spent (e.g., "3h 20m")' },
|
||||
timeSpentSeconds: { type: 'number', description: 'Time spent in seconds' },
|
||||
comment: { type: 'string', description: 'Worklog comment text' },
|
||||
author: {
|
||||
type: 'object',
|
||||
description: 'Worklog author',
|
||||
properties: USER_OUTPUT_PROPERTIES,
|
||||
},
|
||||
updateAuthor: {
|
||||
type: 'object',
|
||||
description: 'User who last updated the worklog',
|
||||
properties: USER_OUTPUT_PROPERTIES,
|
||||
},
|
||||
started: { type: 'string', description: 'Worklog start time in ISO format' },
|
||||
created: { type: 'string', description: 'Worklog creation time' },
|
||||
updated: { type: 'string', description: 'Worklog last update time' },
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
import { createLogger } from '@sim/logger'
|
||||
import type { RetryOptions } from '@/lib/knowledge/documents/utils'
|
||||
import { fetchWithRetry } from '@/lib/knowledge/documents/utils'
|
||||
|
||||
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.
|
||||
*/
|
||||
export function extractAdfText(content: any): string | null {
|
||||
if (!content) return null
|
||||
if (typeof content === 'string') return content
|
||||
if (Array.isArray(content)) {
|
||||
return content.map(extractAdfText).filter(Boolean).join(' ')
|
||||
}
|
||||
if (content.type === 'text') return content.text || ''
|
||||
if (content.type === 'hardBreak') return '\n'
|
||||
if (content.type === 'mention') return content.attrs?.text || ''
|
||||
if (content.type === 'emoji') return content.attrs?.shortName || content.attrs?.text || ''
|
||||
if (content.content) return extractAdfText(content.content)
|
||||
return ''
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a raw Jira API user object into a typed user output.
|
||||
* Returns null if user data is falsy.
|
||||
*/
|
||||
export function transformUser(user: any): {
|
||||
accountId: string
|
||||
displayName: string
|
||||
active: boolean | null
|
||||
emailAddress: string | null
|
||||
avatarUrl: string | null
|
||||
accountType: string | null
|
||||
timeZone: string | null
|
||||
} | null {
|
||||
if (!user) return null
|
||||
return {
|
||||
accountId: user.accountId ?? '',
|
||||
displayName: user.displayName ?? '',
|
||||
active: user.active ?? null,
|
||||
emailAddress: user.emailAddress ?? null,
|
||||
avatarUrl: user.avatarUrls?.['48x48'] ?? null,
|
||||
accountType: user.accountType ?? null,
|
||||
timeZone: user.timeZone ?? null,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads Jira attachment file content given attachment metadata and an access token.
|
||||
* Returns an array of downloaded files with base64-encoded data.
|
||||
*/
|
||||
export async function downloadJiraAttachments(
|
||||
attachments: Array<{
|
||||
content: string
|
||||
filename: string
|
||||
mimeType: string
|
||||
size: number
|
||||
id: string
|
||||
}>,
|
||||
accessToken: string
|
||||
): Promise<Array<{ name: string; mimeType: string; data: string; size: number }>> {
|
||||
const downloaded: Array<{ name: string; mimeType: string; data: string; size: number }> = []
|
||||
|
||||
for (const att of attachments) {
|
||||
if (!att.content) continue
|
||||
if (att.size > MAX_ATTACHMENT_SIZE) {
|
||||
logger.warn(`Skipping attachment ${att.filename} (${att.size} bytes): exceeds size limit`)
|
||||
continue
|
||||
}
|
||||
try {
|
||||
const response = await fetchWithRetry(att.content, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
Accept: '*/*',
|
||||
},
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
logger.warn(`Failed to download attachment ${att.filename}: HTTP ${response.status}`)
|
||||
continue
|
||||
}
|
||||
|
||||
const arrayBuffer = await response.arrayBuffer()
|
||||
const buffer = Buffer.from(arrayBuffer)
|
||||
|
||||
downloaded.push({
|
||||
name: att.filename || `attachment-${att.id}`,
|
||||
mimeType: att.mimeType || 'application/octet-stream',
|
||||
data: buffer.toString('base64'),
|
||||
size: buffer.length,
|
||||
})
|
||||
} catch (error) {
|
||||
logger.warn(`Failed to download attachment ${att.filename}:`, error)
|
||||
}
|
||||
}
|
||||
|
||||
return downloaded
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes an ISO timestamp into the format Jira's worklog API requires:
|
||||
* `YYYY-MM-DDTHH:mm:ss.sss±HHMM` (offset without colon). Accepts trailing `Z`
|
||||
* and `±HH:MM` offsets and rewrites them to `±HHMM`. If milliseconds are
|
||||
* missing, `.000` is inserted before the offset.
|
||||
*/
|
||||
export function normalizeJiraWorklogTimestamp(value: string): string {
|
||||
let s = value.trim()
|
||||
s = s.replace(/Z$/i, '+0000')
|
||||
s = s.replace(/([+-]\d{2}):(\d{2})$/, '$1$2')
|
||||
s = s.replace(/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})([+-]\d{4})$/, '$1.000$2')
|
||||
return s
|
||||
}
|
||||
|
||||
export function normalizeDomain(domain: string): string {
|
||||
return `https://${domain
|
||||
.trim()
|
||||
.replace(/^https?:\/\//i, '')
|
||||
.replace(/\/+$/, '')}`.toLowerCase()
|
||||
}
|
||||
|
||||
export async function getJiraCloudId(
|
||||
domain: string,
|
||||
accessToken: string,
|
||||
retryOptions?: RetryOptions
|
||||
): Promise<string> {
|
||||
const response = await fetchWithRetry(
|
||||
'https://api.atlassian.com/oauth/token/accessible-resources',
|
||||
{
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
Accept: 'application/json',
|
||||
},
|
||||
},
|
||||
retryOptions
|
||||
)
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
throw new Error(`Failed to fetch Jira accessible resources: ${response.status} - ${errorText}`)
|
||||
}
|
||||
|
||||
const resources = await response.json()
|
||||
|
||||
if (!Array.isArray(resources) || resources.length === 0) {
|
||||
throw new Error('No Jira resources found')
|
||||
}
|
||||
|
||||
const normalized = normalizeDomain(domain)
|
||||
const match = resources.find(
|
||||
(r: { url: string }) => r.url.toLowerCase().replace(/\/+$/, '') === normalized
|
||||
)
|
||||
|
||||
if (match) {
|
||||
return match.id
|
||||
}
|
||||
|
||||
if (resources.length === 1) {
|
||||
return resources[0].id
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`Could not match Jira domain "${domain}" to any accessible resource. ` +
|
||||
`Available sites: ${resources.map((r: { url: string }) => r.url).join(', ')}`
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse error messages from Atlassian API responses (Jira, JSM, Confluence).
|
||||
* Handles all known error formats: errorMessage, errorMessages[], errors[].title/detail,
|
||||
* field-level errors object, and generic message fallback.
|
||||
*/
|
||||
export function parseAtlassianErrorMessage(
|
||||
status: number,
|
||||
statusText: string,
|
||||
errorText: string
|
||||
): string {
|
||||
try {
|
||||
const errorData = JSON.parse(errorText)
|
||||
if (errorData.errorMessage) {
|
||||
return errorData.errorMessage
|
||||
}
|
||||
if (Array.isArray(errorData.errorMessages) && errorData.errorMessages.length > 0) {
|
||||
return errorData.errorMessages.join(', ')
|
||||
}
|
||||
if (Array.isArray(errorData.errors) && errorData.errors.length > 0) {
|
||||
const err = errorData.errors[0]
|
||||
if (err?.title) {
|
||||
return err.detail ? `${err.title}: ${err.detail}` : err.title
|
||||
}
|
||||
}
|
||||
if (errorData.errors && !Array.isArray(errorData.errors)) {
|
||||
const fieldErrors = Object.entries(errorData.errors)
|
||||
.map(([field, msg]) => `${field}: ${msg}`)
|
||||
.join(', ')
|
||||
if (fieldErrors) return fieldErrors
|
||||
}
|
||||
if (errorData.message) {
|
||||
return errorData.message
|
||||
}
|
||||
} catch {
|
||||
if (errorText) {
|
||||
return errorText
|
||||
}
|
||||
}
|
||||
return `${status} ${statusText}`
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
import type { JiraWriteParams, JiraWriteResponse } from '@/tools/jira/types'
|
||||
import { TIMESTAMP_OUTPUT } from '@/tools/jira/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const jiraWriteTool: ToolConfig<JiraWriteParams, JiraWriteResponse> = {
|
||||
id: 'jira_write',
|
||||
name: 'Jira Write',
|
||||
description: 'Create a new Jira issue',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'jira',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for Jira',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Jira domain (e.g., yourcompany.atlassian.net)',
|
||||
},
|
||||
projectId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Jira project key (e.g., PROJ)',
|
||||
},
|
||||
summary: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Summary for the issue',
|
||||
},
|
||||
description: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'Description for the issue. Accepts plain text (auto-wrapped in ADF) or a raw ADF document object',
|
||||
},
|
||||
priority: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Priority ID or name for the issue (e.g., "10000" or "High")',
|
||||
},
|
||||
assignee: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Assignee account ID for the issue',
|
||||
},
|
||||
cloudId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description:
|
||||
'Jira Cloud ID for the instance. If not provided, it will be fetched using the domain.',
|
||||
},
|
||||
issueType: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Type of issue to create (e.g., Task, Story, Bug, Epic, Sub-task)',
|
||||
},
|
||||
parent: {
|
||||
type: 'json',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Parent issue key for creating subtasks (e.g., { "key": "PROJ-123" })',
|
||||
},
|
||||
labels: {
|
||||
type: 'array',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Labels for the issue (array of label names)',
|
||||
},
|
||||
components: {
|
||||
type: 'array',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Components for the issue (array of component names)',
|
||||
},
|
||||
duedate: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Due date for the issue (format: YYYY-MM-DD)',
|
||||
},
|
||||
fixVersions: {
|
||||
type: 'array',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Fix versions for the issue (array of version names)',
|
||||
},
|
||||
reporter: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Reporter account ID for the issue',
|
||||
},
|
||||
environment: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Environment information for the issue',
|
||||
},
|
||||
customFieldId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Custom field ID (e.g., customfield_10001)',
|
||||
},
|
||||
customFieldValue: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Value for the custom field',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: '/api/tools/jira/write',
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params) => {
|
||||
return {
|
||||
domain: params.domain,
|
||||
accessToken: params.accessToken,
|
||||
projectId: params.projectId,
|
||||
summary: params.summary,
|
||||
description: params.description,
|
||||
priority: params.priority,
|
||||
assignee: params.assignee,
|
||||
cloudId: params.cloudId,
|
||||
issueType: params.issueType,
|
||||
parent: params.parent,
|
||||
labels: params.labels,
|
||||
components: params.components,
|
||||
duedate: params.duedate,
|
||||
fixVersions: params.fixVersions,
|
||||
reporter: params.reporter,
|
||||
environment: params.environment,
|
||||
customFieldId: params.customFieldId,
|
||||
customFieldValue: params.customFieldValue,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const responseText = await response.text()
|
||||
|
||||
if (!responseText) {
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
id: '',
|
||||
issueKey: 'unknown',
|
||||
self: '',
|
||||
summary: 'Issue created successfully',
|
||||
success: true,
|
||||
url: '',
|
||||
assigneeId: null,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
let data: any
|
||||
try {
|
||||
data = JSON.parse(responseText)
|
||||
} catch {
|
||||
throw new Error(
|
||||
`Jira write failed (${response.status} ${response.statusText}): non-JSON response from /api/tools/jira/write`
|
||||
)
|
||||
}
|
||||
|
||||
if (data.success && data.output) {
|
||||
return {
|
||||
success: data.success,
|
||||
output: {
|
||||
ts: data.output.ts ?? new Date().toISOString(),
|
||||
id: data.output.id ?? '',
|
||||
issueKey: data.output.issueKey ?? 'unknown',
|
||||
self: data.output.self ?? '',
|
||||
summary: data.output.summary ?? '',
|
||||
success: data.output.success ?? true,
|
||||
url: data.output.url ?? '',
|
||||
assigneeId: data.output.assigneeId ?? null,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
success: data.success || false,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
id: data.output?.id ?? '',
|
||||
issueKey: data.output?.issueKey ?? 'unknown',
|
||||
self: data.output?.self ?? '',
|
||||
summary: data.output?.summary ?? 'Issue created',
|
||||
success: false,
|
||||
url: data.output?.url ?? '',
|
||||
assigneeId: data.output?.assigneeId ?? null,
|
||||
},
|
||||
error: data.error,
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ts: TIMESTAMP_OUTPUT,
|
||||
id: { type: 'string', description: 'Created issue ID' },
|
||||
issueKey: { type: 'string', description: 'Created issue key (e.g., PROJ-123)' },
|
||||
self: { type: 'string', description: 'REST API URL for the created issue' },
|
||||
summary: { type: 'string', description: 'Issue summary' },
|
||||
success: { type: 'boolean', description: 'Whether the issue was created successfully' },
|
||||
url: { type: 'string', description: 'URL to the created issue in Jira' },
|
||||
assigneeId: {
|
||||
type: 'string',
|
||||
description: 'Account ID of the assigned user (null if no assignee was set)',
|
||||
optional: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user