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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 101 additions & 49 deletions src/tools/wiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,26 @@ function configureWikiTools(
project: z.string().optional().describe("The project name or ID where the wiki is located. If not provided, the default project will be used."),
},
async ({ wikiIdentifier, project }) => {
const connection = await connectionProvider();
const wikiApi = await connection.getWikiApi();
const wiki = await wikiApi.getWiki(wikiIdentifier, project);

return {
content: [{ type: "text", text: JSON.stringify(wiki, null, 2) }],
};
try {
const connection = await connectionProvider();
const wikiApi = await connection.getWikiApi();
const wiki = await wikiApi.getWiki(wikiIdentifier, project);

if (!wiki) {
return { content: [{ type: "text", text: "No wiki found" }], isError: true };
}

return {
content: [{ type: "text", text: JSON.stringify(wiki, null, 2) }],
};
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';

return {
content: [{ type: "text", text: `Error fetching wiki: ${errorMessage}` }],
isError: true
};
}
}
);

Expand All @@ -44,13 +57,26 @@ function configureWikiTools(
project: z.string().optional().describe("The project name or ID to filter wikis. If not provided, all wikis in the organization will be returned."),
},
async ({ project }) => {
const connection = await connectionProvider();
const wikiApi = await connection.getWikiApi();
const wikis = await wikiApi.getAllWikis(project);

return {
content: [{ type: "text", text: JSON.stringify(wikis, null, 2) }],
};
try {
const connection = await connectionProvider();
const wikiApi = await connection.getWikiApi();
const wikis = await wikiApi.getAllWikis(project);

if (!wikis) {
return { content: [{ type: "text", text: "No wikis found" }], isError: true };
}

return {
content: [{ type: "text", text: JSON.stringify(wikis, null, 2) }],
};
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';

return {
content: [{ type: "text", text: `Error fetching wikis: ${errorMessage}` }],
isError: true
};
}
}
);

Expand All @@ -71,24 +97,37 @@ function configureWikiTools(
continuationToken,
pageViewsForDays,
}) => {
const connection = await connectionProvider();
const wikiApi = await connection.getWikiApi();

const pagesBatchRequest: WikiPagesBatchRequest = {
top,
continuationToken,
pageViewsForDays,
};

const pages = await wikiApi.getPagesBatch(
pagesBatchRequest,
project,
wikiIdentifier
);

return {
content: [{ type: "text", text: JSON.stringify(pages, null, 2) }],
};
try {
const connection = await connectionProvider();
const wikiApi = await connection.getWikiApi();

const pagesBatchRequest: WikiPagesBatchRequest = {
top,
continuationToken,
pageViewsForDays,
};

const pages = await wikiApi.getPagesBatch(
pagesBatchRequest,
project,
wikiIdentifier
);

if (!pages) {
return { content: [{ type: "text", text: "No wiki pages found" }], isError: true };
}

return {
content: [{ type: "text", text: JSON.stringify(pages, null, 2) }],
};
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';

return {
content: [{ type: "text", text: `Error fetching wiki pages: ${errorMessage}` }],
isError: true
};
}
}
);

Expand All @@ -101,23 +140,36 @@ function configureWikiTools(
path: z.string().describe("The path of the wiki page to retrieve content for."),
},
async ({ wikiIdentifier, project, path }) => {
const connection = await connectionProvider();
const wikiApi = await connection.getWikiApi();

const stream = await wikiApi.getPageText(
project,
wikiIdentifier,
path,
undefined,
undefined,
true
);

const content = await streamToString(stream);

return {
content: [{ type: "text", text: JSON.stringify(content, null, 2) }],
};
try {
const connection = await connectionProvider();
const wikiApi = await connection.getWikiApi();

const stream = await wikiApi.getPageText(
project,
wikiIdentifier,
path,
undefined,
undefined,
true
);

if (!stream) {
return { content: [{ type: "text", text: "No wiki page content found" }], isError: true };
}

const content = await streamToString(stream);

return {
content: [{ type: "text", text: JSON.stringify(content, null, 2) }],
};
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';

return {
content: [{ type: "text", text: `Error fetching wiki page content: ${errorMessage}` }],
isError: true
};
}
}
);
}
Expand Down
Loading