Skip to content

Commit cad60e9

Browse files
committed
refactor(plugins/anthropic): improve list func readability
1 parent 21c9b9b commit cad60e9

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

plugins/anthropic/src/index.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,19 @@ async function list(client: Anthropic): Promise<ActionMetadata[]> {
5454

5555
return clientModels
5656
.map((modelInfo) => {
57-
// Remove the final part if it's a date (8 digits)
58-
const idParts = modelInfo.id.split('-');
59-
const normalizedId = idParts[idParts.length - 1].match(/^\d{8}$/)
60-
? idParts.slice(0, -1).join('-')
61-
: modelInfo.id;
57+
// Remove the date suffix from the model id
58+
const normalizedId = modelInfo.id.replace(/-\d{8}$/, '');
59+
// Get the model reference from the supported models
6260
const ref = SUPPORTED_CLAUDE_MODELS[normalizedId];
63-
return ref
64-
? modelActionMetadata({
65-
name: ref.name,
66-
info: ref.info,
67-
configSchema: ref.configSchema,
68-
})
69-
: null;
61+
// Return the model action metadata if the model is supported
62+
return ref ? modelActionMetadata({
63+
name: ref.name,
64+
info: ref.info,
65+
configSchema: ref.configSchema,
66+
}) : undefined;
7067
})
71-
.filter(Boolean) as ActionMetadata[];
68+
// Filter out undefined values
69+
.filter((metadata) => metadata !== undefined);
7270
}
7371

7472
/**

0 commit comments

Comments
 (0)