文件
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

59 行
2.0 KiB
TypeScript

import Note from '../../../../models/Note';
import Folder from '../../../../models/Folder';
import { _ } from '../../../../locale';
import buildTool from '../utils/buildTool';
import { ToolError, ToolInput } from '../types';
interface Input {
title?: string;
body?: string;
notebook_id?: string;
is_todo?: boolean;
}
const tool = buildTool({
id: 'create_note',
userDescription: (input: ToolInput) => _('Created note: %s', input.title ?? _('(no title)')),
description: 'Create a new note. Returns the created note id. If notebook_id is omitted, the note is created in the default notebook.',
inputSchema: {
type: 'object',
properties: {
title: { type: 'string', description: 'Note title.' },
body: { type: 'string', description: 'Note body in Markdown.' },
notebook_id: { type: 'string', description: 'Optional notebook (folder) id. Use list_notebooks to find ids.' },
is_todo: { type: 'boolean', description: 'Set to true to create the note as a to-do.' },
},
required: ['title'],
},
handler: async (input: Input, context) => {
if (typeof input.title !== 'string' || !input.title.trim()) {
throw new ToolError('Missing or invalid "title" parameter');
}
// `is_todo: 'false'` is otherwise truthy and would silently flip the flag.
if (input.is_todo !== undefined && typeof input.is_todo !== 'boolean') {
throw new ToolError('"is_todo" must be a boolean');
}
let parentId = input.notebook_id ?? context.selectedFolderId;
if (parentId) {
const folder = await Folder.load(parentId);
if (!folder) throw new ToolError(`Notebook not found: ${parentId}`);
} else {
const defaultFolder = await Folder.defaultFolder();
if (!defaultFolder) throw new ToolError('No notebook available. Create one first or pass notebook_id.');
parentId = defaultFolder.id;
}
const saved = await Note.save({
title: input.title,
body: input.body ?? '',
parent_id: parentId,
is_todo: input.is_todo ? 1 : 0,
});
return { id: saved.id, title: saved.title, notebook_id: saved.parent_id };
},
});
export default tool;