@@ -5,21 +5,15 @@ import { executeJxa } from "../applescript/execute.js";
55import { escapeStringForJXA, isJXASafeString } from "../utils/escapeString.js";
66import { getRecordLookupHelpers, getDatabaseHelper } from "../utils/jxaHelpers.js";
77import { lookupZoteroMetadataByPath } from "../utils/zoteroMetadata.js";
8- import type {
9- ZoteroMatchType,
10- ZoteroMetadataDescriptor,
11- } from "../utils/zoteroMetadata.js";
8+ import type { ZoteroMatchType, ZoteroMetadataDescriptor } from "../utils/zoteroMetadata.js";
129
1310const ToolInputSchema = ToolSchema.shape.inputSchema;
1411type ToolInput = z.infer<typeof ToolInputSchema>;
1512
1613const GetZoteroMetadataSchema = z
1714 .object({
1815 uuid: z.string().optional().describe("UUID of the DEVONthink record"),
19- id: z
20- .number()
21- .optional()
22- .describe("DEVONthink record ID (requires databaseName)"),
16+ id: z.number().optional().describe("DEVONthink record ID (requires databaseName)"),
2317 databaseName: z
2418 .string()
2519 .optional()
@@ -141,19 +135,15 @@ const buildRecordLookupScript = (input: {
141135 parts.push(` let resolvedDatabase = null;`);
142136
143137 if (input.uuid) {
144- parts.push(
145- ` lookupOptions["uuid"] = "${escapeStringForJXA(input.uuid)}";`,
146- );
138+ parts.push(` lookupOptions["uuid"] = "${escapeStringForJXA(input.uuid)}";`);
147139 }
148140
149141 if (input.id !== undefined) {
150142 parts.push(` lookupOptions["id"] = ${input.id};`);
151143 }
152144
153145 if (input.recordPath) {
154- parts.push(
155- ` lookupOptions["path"] = "${escapeStringForJXA(input.recordPath)}";`,
156- );
146+ parts.push(` lookupOptions["path"] = "${escapeStringForJXA(input.recordPath)}";`);
157147 }
158148
159149 if (input.databaseName) {
@@ -175,8 +165,8 @@ const buildRecordLookupScript = (input: {
175165 parts.push(` const response = {};`);
176166 parts.push(` response["success"] = false;`);
177167 parts.push(
178- ` const lookupError = lookupResult && lookupResult.error ? lookupResult.error : "Record not found";`,
179- );
168+ ` const lookupError = lookupResult && lookupResult.error ? lookupResult.error : "Record not found";`,
169+ );
180170 parts.push(` response["error"] = lookupError;`);
181171 parts.push(` return JSON.stringify(response);`);
182172 parts.push(` }`);
@@ -192,17 +182,21 @@ const buildRecordLookupScript = (input: {
192182 parts.push(` const response = {};`);
193183 parts.push(` response["success"] = true;`);
194184 parts.push(` response["finderPath"] = finderPath;`);
195- parts.push(
196- ` response["lookupMethod"] = lookupResult.method ? lookupResult.method : null;`,
197- );
185+ parts.push(` response["lookupMethod"] = lookupResult.method ? lookupResult.method : null;`);
198186
199187 parts.push(` const recordInfo = {};`);
200- parts.push(` try { recordInfo["uuid"] = record.uuid(); } catch (e) { recordInfo["uuid"] = null; }`);
201- parts.push(` try { recordInfo["id"] = record.id(); } catch (e) { recordInfo["id"] = null; }`);
202- parts.push(` try { recordInfo["name"] = record.name(); } catch (e) { recordInfo["name"] = null; }`);
203188 parts.push(
204- ` try { recordInfo["location"] = record.location(); } catch (e) { recordInfo["location"] = null; }`,
205- );
189+ ` try { recordInfo["uuid"] = record.uuid(); } catch (e) { recordInfo["uuid"] = null; }`,
190+ );
191+ parts.push(
192+ ` try { recordInfo["id"] = record.id(); } catch (e) { recordInfo["id"] = null; }`,
193+ );
194+ parts.push(
195+ ` try { recordInfo["name"] = record.name(); } catch (e) { recordInfo["name"] = null; }`,
196+ );
197+ parts.push(
198+ ` try { recordInfo["location"] = record.location(); } catch (e) { recordInfo["location"] = null; }`,
199+ );
206200 parts.push(` recordInfo["path"] = finderPath;`);
207201 parts.push(` try {`);
208202 parts.push(` const db = record.database();`);
@@ -234,9 +228,7 @@ const buildRecordLookupScript = (input: {
234228 return parts.join("\n");
235229};
236230
237- const getRecordFinderPath = async (
238- input: GetZoteroMetadataInput,
239- ): Promise<RecordLookupResult> => {
231+ const getRecordFinderPath = async (input: GetZoteroMetadataInput): Promise<RecordLookupResult> => {
240232 try {
241233 const script = buildRecordLookupScript(input);
242234 return await executeJxa<RecordLookupResult>(script);
@@ -251,15 +243,7 @@ const getRecordFinderPath = async (
251243const getZoteroMetadata = async (
252244 input: GetZoteroMetadataInput,
253245): Promise<ZoteroMetadataToolSuccess | ZoteroMetadataToolFailure> => {
254- const {
255- uuid,
256- id,
257- databaseName,
258- recordPath,
259- finderPath,
260- zoteroJsonPath,
261- zoteroBibPath,
262- } = input;
246+ const { uuid, id, databaseName, recordPath, finderPath, zoteroJsonPath, zoteroBibPath } = input;
263247
264248 const metadataJsonPath = zoteroJsonPath ?? process.env.ZOTERO_BIBLIOGRAPHY_JSON ?? null;
265249 const metadataBibPath = zoteroBibPath ?? process.env.ZOTERO_BIBLIOGRAPHY_BIB ?? null;
0 commit comments