@udondan/duolingo 1.0.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +215 -12
  2. package/dist/cli/config-file.d.ts +22 -0
  3. package/dist/cli/config-file.d.ts.map +1 -0
  4. package/dist/cli/config-file.js +68 -0
  5. package/dist/cli/config-file.js.map +1 -0
  6. package/dist/cli/program.d.ts +25 -0
  7. package/dist/cli/program.d.ts.map +1 -0
  8. package/dist/cli/program.js +187 -0
  9. package/dist/cli/program.js.map +1 -0
  10. package/dist/cli.d.ts +7 -0
  11. package/dist/cli.d.ts.map +1 -0
  12. package/dist/cli.js +8 -0
  13. package/dist/cli.js.map +1 -0
  14. package/dist/index.d.ts +2 -2
  15. package/dist/index.js +2 -2
  16. package/dist/mcp.d.ts +14 -0
  17. package/dist/mcp.d.ts.map +1 -0
  18. package/dist/mcp.js +38 -0
  19. package/dist/mcp.js.map +1 -0
  20. package/dist/tools/account.d.ts.map +1 -1
  21. package/dist/tools/account.js +28 -621
  22. package/dist/tools/account.js.map +1 -1
  23. package/dist/tools/helpers.d.ts +11 -7
  24. package/dist/tools/helpers.d.ts.map +1 -1
  25. package/dist/tools/helpers.js +19 -50
  26. package/dist/tools/helpers.js.map +1 -1
  27. package/dist/tools/language.d.ts.map +1 -1
  28. package/dist/tools/language.js +63 -552
  29. package/dist/tools/language.js.map +1 -1
  30. package/dist/tools/shop.d.ts.map +1 -1
  31. package/dist/tools/shop.js +6 -93
  32. package/dist/tools/shop.js.map +1 -1
  33. package/dist/version.d.ts +3 -0
  34. package/dist/version.d.ts.map +1 -0
  35. package/dist/version.js +4 -0
  36. package/dist/version.js.map +1 -0
  37. package/dist/views/account.d.ts +32 -0
  38. package/dist/views/account.d.ts.map +1 -0
  39. package/dist/views/account.js +393 -0
  40. package/dist/views/account.js.map +1 -0
  41. package/dist/views/language.d.ts +38 -0
  42. package/dist/views/language.d.ts.map +1 -0
  43. package/dist/views/language.js +269 -0
  44. package/dist/views/language.js.map +1 -0
  45. package/dist/views/utils.d.ts +13 -0
  46. package/dist/views/utils.d.ts.map +1 -0
  47. package/dist/views/utils.js +30 -0
  48. package/dist/views/utils.js.map +1 -0
  49. package/dist/views/view.d.ts +34 -0
  50. package/dist/views/view.d.ts.map +1 -0
  51. package/dist/views/view.js +34 -0
  52. package/dist/views/view.js.map +1 -0
  53. package/package.json +20 -19
  54. package/dist/server.d.ts +0 -19
  55. package/dist/server.d.ts.map +0 -1
  56. package/dist/server.js +0 -40
  57. package/dist/server.js.map +0 -1
@@ -7,8 +7,8 @@
7
7
  * get_language_voices, get_audio_url
8
8
  */
9
9
  import { z } from 'zod';
10
- import { getClient } from '../client/duolingo.js';
11
- import { handleError, ResponseFormatSchema, UsernameFieldSchema, computeDependencyOrder, } from './helpers.js';
10
+ import { audioUrlView, goldenTopicsView, knownTopicsView, knownWordsView, languageDetailsView, languageProgressView, languageVoicesView, learnedSkillsView, reviewableTopicsView, unknownTopicsView, } from '../views/language.js';
11
+ import { READ_ONLY, reply, ResponseFormatSchema, UsernameFieldSchema, } from './helpers.js';
12
12
  const LanguageAbbrSchema = z
13
13
  .string()
14
14
  .min(2)
@@ -20,10 +20,49 @@ const OptionalLanguageAbbrSchema = z
20
20
  .max(5)
21
21
  .optional()
22
22
  .describe("Language abbreviation (e.g. 'fr'). Defaults to current language.");
23
+ /** Tools that take a language and an optional username. */
24
+ const LANGUAGE_QUERY_TOOLS = [
25
+ [
26
+ 'duolingo_get_known_topics',
27
+ 'Get Duolingo Known Topics',
28
+ 'Get the list of learned topic/skill names for a language.',
29
+ knownTopicsView,
30
+ ],
31
+ [
32
+ 'duolingo_get_unknown_topics',
33
+ 'Get Duolingo Unknown Topics',
34
+ 'Get the list of not-yet-learned topics/skills for a language.',
35
+ unknownTopicsView,
36
+ ],
37
+ [
38
+ 'duolingo_get_golden_topics',
39
+ 'Get Duolingo Golden (Mastered) Topics',
40
+ 'Get the list of fully mastered ("golden") topics for a language. ' +
41
+ 'A golden topic has a strength of 1.0 (fully reviewed).',
42
+ goldenTopicsView,
43
+ ],
44
+ [
45
+ 'duolingo_get_reviewable_topics',
46
+ 'Get Duolingo Reviewable Topics',
47
+ 'Get the list of learned but not fully mastered topics for a language. ' +
48
+ 'These are topics that have been started but whose strength is below 1.0, meaning they need review.',
49
+ reviewableTopicsView,
50
+ ],
51
+ [
52
+ 'duolingo_get_known_words',
53
+ 'Get Duolingo Known Words',
54
+ 'Get the set of words a user has learned in a language.',
55
+ knownWordsView,
56
+ ],
57
+ [
58
+ 'duolingo_get_learned_skills',
59
+ 'Get Duolingo Learned Skills',
60
+ 'Get full skill objects for all learned skills, sorted by learning order. ' +
61
+ 'Returns detailed skill data including title, strength, progress, words, and more.',
62
+ learnedSkillsView,
63
+ ],
64
+ ];
23
65
  export function registerLanguageTools(server) {
24
- // -------------------------------------------------------------------------
25
- // Get Language Details
26
- // -------------------------------------------------------------------------
27
66
  server.registerTool('duolingo_get_language_details', {
28
67
  title: 'Get Duolingo Language Details',
29
68
  description: "Get a user's status and details for a specific language. " +
@@ -36,66 +75,8 @@ export function registerLanguageTools(server) {
36
75
  username: UsernameFieldSchema,
37
76
  response_format: ResponseFormatSchema,
38
77
  },
39
- annotations: {
40
- readOnlyHint: true,
41
- destructiveHint: false,
42
- idempotentHint: true,
43
- openWorldHint: true,
44
- },
45
- }, async ({ language_name, username, response_format }) => {
46
- try {
47
- const userData = await getClient().getUserData(username);
48
- // The API omits `languages` while the current course is not a
49
- // language course (e.g. Math, Music, Chess).
50
- if (!userData.languages) {
51
- return {
52
- content: [
53
- {
54
- type: 'text',
55
- text: 'Language details are not available while the current course is not a language course.',
56
- },
57
- ],
58
- };
59
- }
60
- const lang = userData.languages.find((l) => l.language_string === language_name);
61
- if (!lang) {
62
- return {
63
- content: [
64
- {
65
- type: 'text',
66
- text: `No details found for language '${language_name}'. Check the language name.`,
67
- },
68
- ],
69
- };
70
- }
71
- const details = {
72
- language: lang.language,
73
- language_string: lang.language_string,
74
- level: lang.level,
75
- points: lang.points,
76
- streak: lang.streak,
77
- current_learning: lang.current_learning,
78
- learning: lang.learning,
79
- };
80
- if (response_format === 'json') {
81
- return {
82
- content: [{ type: 'text', text: JSON.stringify(details, null, 2) }],
83
- };
84
- }
85
- const lines = [`# ${language_name} Details`, ''];
86
- lines.push(`- **Level**: ${details.level}`);
87
- lines.push(`- **Points**: ${details.points}`);
88
- lines.push(`- **Streak**: ${details.streak} days`);
89
- lines.push(`- **Currently Learning**: ${details.current_learning}`);
90
- return { content: [{ type: 'text', text: lines.join('\n') }] };
91
- }
92
- catch (err) {
93
- return { content: [{ type: 'text', text: handleError(err) }] };
94
- }
95
- });
96
- // -------------------------------------------------------------------------
97
- // Get Language Progress
98
- // -------------------------------------------------------------------------
78
+ annotations: READ_ONLY,
79
+ }, ({ language_name, username, response_format }) => reply(() => languageDetailsView({ language_name, username }), response_format));
99
80
  server.registerTool('duolingo_get_language_progress', {
100
81
  title: 'Get Duolingo Language Progress',
101
82
  description: 'Get detailed progress metrics for a specific language. ' +
@@ -104,387 +85,20 @@ export function registerLanguageTools(server) {
104
85
  language_abbr: LanguageAbbrSchema,
105
86
  response_format: ResponseFormatSchema,
106
87
  },
107
- annotations: {
108
- readOnlyHint: true,
109
- destructiveHint: false,
110
- idempotentHint: true,
111
- openWorldHint: true,
112
- },
113
- }, async ({ language_abbr, response_format }) => {
114
- try {
115
- const userData = await getClient().getUserData();
116
- const langData = userData.language_data?.[language_abbr];
117
- if (!langData) {
118
- return {
119
- content: [
120
- {
121
- type: 'text',
122
- text: `Language '${language_abbr}' not found. Make sure you are learning this language.`,
123
- },
124
- ],
125
- };
126
- }
127
- const progress = {
128
- language: langData.language,
129
- language_string: langData.language_string,
130
- level: langData.level,
131
- level_percent: langData.level_percent,
132
- level_points: langData.level_points,
133
- level_progress: langData.level_progress,
134
- level_left: langData.level_left,
135
- next_level: langData.next_level,
136
- points: langData.points,
137
- // points_rank is absent in the current API response
138
- points_rank: langData.points_rank,
139
- streak: langData.streak,
140
- num_skills_learned: langData.num_skills_learned,
141
- fluency_score: langData.fluency_score,
142
- };
143
- if (response_format === 'json') {
144
- return {
145
- content: [
146
- { type: 'text', text: JSON.stringify(progress, null, 2) },
147
- ],
148
- };
149
- }
150
- const lang = progress.language_string || language_abbr;
151
- const lines = [`# ${lang} Progress`, ''];
152
- lines.push(`- **Level**: ${progress.level}`);
153
- lines.push(`- **Level Progress**: ${progress.level_percent}%`);
154
- lines.push(`- **Points to Next Level**: ${progress.level_left}`);
155
- lines.push(`- **Total Points**: ${progress.points}`);
156
- if (typeof progress.points_rank === 'number')
157
- lines.push(`- **Points Rank**: #${progress.points_rank}`);
158
- lines.push(`- **Streak**: ${progress.streak} days`);
159
- lines.push(`- **Skills Learned**: ${progress.num_skills_learned}`);
160
- if (progress.fluency_score !== null) {
161
- lines.push(`- **Fluency Score**: ${progress.fluency_score}`);
162
- }
163
- return { content: [{ type: 'text', text: lines.join('\n') }] };
164
- }
165
- catch (err) {
166
- return { content: [{ type: 'text', text: handleError(err) }] };
167
- }
168
- });
169
- // -------------------------------------------------------------------------
170
- // Shared topic/word tool schema
171
- // -------------------------------------------------------------------------
172
- const topicInputSchema = {
173
- language_abbr: LanguageAbbrSchema,
174
- username: UsernameFieldSchema,
175
- response_format: ResponseFormatSchema,
176
- };
177
- function formatTopicList(title, topics, fmt) {
178
- if (fmt === 'json')
179
- return JSON.stringify([...topics].sort(), null, 2);
180
- if (topics.length === 0)
181
- return `No ${title.toLowerCase()} found.`;
182
- const lines = [`# ${title}`, ''];
183
- for (const topic of [...topics].sort()) {
184
- lines.push(`- ${topic}`);
185
- }
186
- return lines.join('\n');
88
+ annotations: READ_ONLY,
89
+ }, ({ language_abbr, response_format }) => reply(() => languageProgressView({ language_abbr }), response_format));
90
+ for (const [name, title, description, view] of LANGUAGE_QUERY_TOOLS) {
91
+ server.registerTool(name, {
92
+ title,
93
+ description,
94
+ inputSchema: {
95
+ language_abbr: LanguageAbbrSchema,
96
+ username: UsernameFieldSchema,
97
+ response_format: ResponseFormatSchema,
98
+ },
99
+ annotations: READ_ONLY,
100
+ }, ({ language_abbr, username, response_format }) => reply(() => view({ language_abbr, username }), response_format));
187
101
  }
188
- // -------------------------------------------------------------------------
189
- // Get Known Topics
190
- // -------------------------------------------------------------------------
191
- server.registerTool('duolingo_get_known_topics', {
192
- title: 'Get Duolingo Known Topics',
193
- description: 'Get the list of learned topic/skill names for a language.',
194
- inputSchema: topicInputSchema,
195
- annotations: {
196
- readOnlyHint: true,
197
- destructiveHint: false,
198
- idempotentHint: true,
199
- openWorldHint: true,
200
- },
201
- }, async ({ language_abbr, username, response_format }) => {
202
- try {
203
- const userData = await getClient().getUserData(username);
204
- const langData = userData.language_data?.[language_abbr];
205
- if (!langData) {
206
- return {
207
- content: [
208
- {
209
- type: 'text',
210
- text: `Language '${language_abbr}' not found. Make sure the user is learning this language.`,
211
- },
212
- ],
213
- };
214
- }
215
- const topics = langData.skills
216
- .filter((s) => s.learned)
217
- .map((s) => s.title);
218
- return {
219
- content: [
220
- {
221
- type: 'text',
222
- text: formatTopicList('Known Topics', topics, response_format),
223
- },
224
- ],
225
- };
226
- }
227
- catch (err) {
228
- return { content: [{ type: 'text', text: handleError(err) }] };
229
- }
230
- });
231
- // -------------------------------------------------------------------------
232
- // Get Unknown Topics
233
- // -------------------------------------------------------------------------
234
- server.registerTool('duolingo_get_unknown_topics', {
235
- title: 'Get Duolingo Unknown Topics',
236
- description: 'Get the list of not-yet-learned topics/skills for a language.',
237
- inputSchema: topicInputSchema,
238
- annotations: {
239
- readOnlyHint: true,
240
- destructiveHint: false,
241
- idempotentHint: true,
242
- openWorldHint: true,
243
- },
244
- }, async ({ language_abbr, username, response_format }) => {
245
- try {
246
- const userData = await getClient().getUserData(username);
247
- const langData = userData.language_data?.[language_abbr];
248
- if (!langData) {
249
- return {
250
- content: [
251
- {
252
- type: 'text',
253
- text: `Language '${language_abbr}' not found. Make sure the user is learning this language.`,
254
- },
255
- ],
256
- };
257
- }
258
- const topics = langData.skills
259
- .filter((s) => !s.learned)
260
- .map((s) => s.title);
261
- return {
262
- content: [
263
- {
264
- type: 'text',
265
- text: formatTopicList('Unknown Topics', topics, response_format),
266
- },
267
- ],
268
- };
269
- }
270
- catch (err) {
271
- return { content: [{ type: 'text', text: handleError(err) }] };
272
- }
273
- });
274
- // -------------------------------------------------------------------------
275
- // Get Golden Topics
276
- // -------------------------------------------------------------------------
277
- server.registerTool('duolingo_get_golden_topics', {
278
- title: 'Get Duolingo Golden (Mastered) Topics',
279
- description: 'Get the list of fully mastered ("golden") topics for a language. ' +
280
- 'A golden topic has a strength of 1.0 (fully reviewed).',
281
- inputSchema: topicInputSchema,
282
- annotations: {
283
- readOnlyHint: true,
284
- destructiveHint: false,
285
- idempotentHint: true,
286
- openWorldHint: true,
287
- },
288
- }, async ({ language_abbr, username, response_format }) => {
289
- try {
290
- const userData = await getClient().getUserData(username);
291
- const langData = userData.language_data?.[language_abbr];
292
- if (!langData) {
293
- return {
294
- content: [
295
- {
296
- type: 'text',
297
- text: `Language '${language_abbr}' not found. Make sure the user is learning this language.`,
298
- },
299
- ],
300
- };
301
- }
302
- const topics = langData.skills
303
- .filter((s) => s.learned && s.strength === 1.0)
304
- .map((s) => s.title);
305
- return {
306
- content: [
307
- {
308
- type: 'text',
309
- text: formatTopicList('Golden (Mastered) Topics', topics, response_format),
310
- },
311
- ],
312
- };
313
- }
314
- catch (err) {
315
- return { content: [{ type: 'text', text: handleError(err) }] };
316
- }
317
- });
318
- // -------------------------------------------------------------------------
319
- // Get Reviewable Topics
320
- // -------------------------------------------------------------------------
321
- server.registerTool('duolingo_get_reviewable_topics', {
322
- title: 'Get Duolingo Reviewable Topics',
323
- description: 'Get the list of learned but not fully mastered topics for a language. ' +
324
- 'These are topics that have been started but whose strength is below 1.0, meaning they need review.',
325
- inputSchema: topicInputSchema,
326
- annotations: {
327
- readOnlyHint: true,
328
- destructiveHint: false,
329
- idempotentHint: true,
330
- openWorldHint: true,
331
- },
332
- }, async ({ language_abbr, username, response_format }) => {
333
- try {
334
- const userData = await getClient().getUserData(username);
335
- const langData = userData.language_data?.[language_abbr];
336
- if (!langData) {
337
- return {
338
- content: [
339
- {
340
- type: 'text',
341
- text: `Language '${language_abbr}' not found. Make sure the user is learning this language.`,
342
- },
343
- ],
344
- };
345
- }
346
- const topics = langData.skills
347
- .filter((s) => s.learned && s.strength < 1.0)
348
- .map((s) => s.title);
349
- return {
350
- content: [
351
- {
352
- type: 'text',
353
- text: formatTopicList('Reviewable Topics', topics, response_format),
354
- },
355
- ],
356
- };
357
- }
358
- catch (err) {
359
- return { content: [{ type: 'text', text: handleError(err) }] };
360
- }
361
- });
362
- // -------------------------------------------------------------------------
363
- // Get Known Words
364
- // -------------------------------------------------------------------------
365
- server.registerTool('duolingo_get_known_words', {
366
- title: 'Get Duolingo Known Words',
367
- description: 'Get the set of words a user has learned in a language.',
368
- inputSchema: topicInputSchema,
369
- annotations: {
370
- readOnlyHint: true,
371
- destructiveHint: false,
372
- idempotentHint: true,
373
- openWorldHint: true,
374
- },
375
- }, async ({ language_abbr, username, response_format }) => {
376
- try {
377
- const userData = await getClient().getUserData(username);
378
- const langData = userData.language_data?.[language_abbr];
379
- if (!langData) {
380
- return {
381
- content: [
382
- {
383
- type: 'text',
384
- text: `Language '${language_abbr}' not found. Make sure the user is learning this language.`,
385
- },
386
- ],
387
- };
388
- }
389
- const wordSet = new Set();
390
- for (const skill of langData.skills) {
391
- if (skill.learned) {
392
- for (const word of skill.words) {
393
- wordSet.add(word);
394
- }
395
- }
396
- }
397
- const words = [...wordSet].sort();
398
- if (response_format === 'json') {
399
- return {
400
- content: [{ type: 'text', text: JSON.stringify(words, null, 2) }],
401
- };
402
- }
403
- if (words.length === 0) {
404
- return {
405
- content: [
406
- {
407
- type: 'text',
408
- text: `No known words found for language '${language_abbr}'.`,
409
- },
410
- ],
411
- };
412
- }
413
- const lines = [
414
- `# Known Words (${language_abbr.toUpperCase()}) — ${words.length} words`,
415
- '',
416
- words.join(', '),
417
- ];
418
- return { content: [{ type: 'text', text: lines.join('\n') }] };
419
- }
420
- catch (err) {
421
- return { content: [{ type: 'text', text: handleError(err) }] };
422
- }
423
- });
424
- // -------------------------------------------------------------------------
425
- // Get Learned Skills
426
- // -------------------------------------------------------------------------
427
- server.registerTool('duolingo_get_learned_skills', {
428
- title: 'Get Duolingo Learned Skills',
429
- description: 'Get full skill objects for all learned skills, sorted by learning order. ' +
430
- 'Returns detailed skill data including title, strength, progress, words, and more.',
431
- inputSchema: topicInputSchema,
432
- annotations: {
433
- readOnlyHint: true,
434
- destructiveHint: false,
435
- idempotentHint: true,
436
- openWorldHint: true,
437
- },
438
- }, async ({ language_abbr, username, response_format }) => {
439
- try {
440
- const userData = await getClient().getUserData(username);
441
- const langData = userData.language_data?.[language_abbr];
442
- if (!langData) {
443
- return {
444
- content: [
445
- {
446
- type: 'text',
447
- text: `Language '${language_abbr}' not found. Make sure the user is learning this language.`,
448
- },
449
- ],
450
- };
451
- }
452
- const allSkills = [...langData.skills];
453
- computeDependencyOrder(allSkills);
454
- const learnedSkills = allSkills
455
- .filter((s) => s.learned)
456
- .sort((a, b) => (a.dependency_order ?? 0) - (b.dependency_order ?? 0));
457
- if (response_format === 'json') {
458
- return {
459
- content: [
460
- { type: 'text', text: JSON.stringify(learnedSkills, null, 2) },
461
- ],
462
- };
463
- }
464
- if (learnedSkills.length === 0) {
465
- return {
466
- content: [
467
- {
468
- type: 'text',
469
- text: `No learned skills found for language '${language_abbr}'.`,
470
- },
471
- ],
472
- };
473
- }
474
- const lines = [`# Learned Skills (${language_abbr.toUpperCase()})`, ''];
475
- for (const skill of learnedSkills) {
476
- const strengthPct = Math.round(skill.strength * 100);
477
- lines.push(`- **${skill.title}** — Strength: ${strengthPct}% | Progress: ${Math.round(skill.progress_percent)}%`);
478
- }
479
- return { content: [{ type: 'text', text: lines.join('\n') }] };
480
- }
481
- catch (err) {
482
- return { content: [{ type: 'text', text: handleError(err) }] };
483
- }
484
- });
485
- // -------------------------------------------------------------------------
486
- // Get Language Voices
487
- // -------------------------------------------------------------------------
488
102
  server.registerTool('duolingo_get_language_voices', {
489
103
  title: 'Get Duolingo Language TTS Voices',
490
104
  description: 'Get the available text-to-speech (TTS) voices for a language. ' +
@@ -493,64 +107,8 @@ export function registerLanguageTools(server) {
493
107
  language_abbr: OptionalLanguageAbbrSchema,
494
108
  response_format: ResponseFormatSchema,
495
109
  },
496
- annotations: {
497
- readOnlyHint: true,
498
- destructiveHint: false,
499
- idempotentHint: true,
500
- openWorldHint: true,
501
- },
502
- }, async ({ language_abbr, response_format }) => {
503
- try {
504
- const client = getClient();
505
- // Resolve language abbreviation
506
- let langAbbr = language_abbr;
507
- if (!langAbbr) {
508
- const userData = await client.getUserData();
509
- const langKeys = Object.keys(userData.language_data ?? {});
510
- langAbbr = langKeys[0];
511
- }
512
- if (!langAbbr) {
513
- return {
514
- content: [
515
- {
516
- type: 'text',
517
- text: 'No language found. Make sure you are learning a language.',
518
- },
519
- ],
520
- };
521
- }
522
- // Discover voices via the session API (duo.tts_multi_voices is no longer
523
- // embedded in the homepage — voices are now discovered from session TTS URLs)
524
- const voices = await client.getLanguageVoices(langAbbr);
525
- if (voices.length === 0) {
526
- return {
527
- content: [
528
- {
529
- type: 'text',
530
- text: `No voices found for language '${langAbbr}'.`,
531
- },
532
- ],
533
- };
534
- }
535
- if (response_format === 'json') {
536
- return {
537
- content: [{ type: 'text', text: JSON.stringify(voices, null, 2) }],
538
- };
539
- }
540
- const lines = [
541
- `# TTS Voices (${langAbbr})`,
542
- '',
543
- ...voices.map((v) => `- ${v}`),
544
- ];
545
- return { content: [{ type: 'text', text: lines.join('\n') }] };
546
- }
547
- catch (err) {
548
- return { content: [{ type: 'text', text: handleError(err) }] };
549
- }
550
- });
551
- // -------------------------------------------------------------------------
552
- // Get Audio URL
553
- // -------------------------------------------------------------------------
110
+ annotations: READ_ONLY,
111
+ }, ({ language_abbr, response_format }) => reply(() => languageVoicesView({ language_abbr }), response_format));
554
112
  server.registerTool('duolingo_get_audio_url', {
555
113
  title: 'Get Duolingo Word Audio URL',
556
114
  description: 'Get the URL of a pronunciation audio file for a word. ' +
@@ -570,54 +128,7 @@ export function registerLanguageTools(server) {
570
128
  .default(true)
571
129
  .describe("If true, select a random voice. Ignored if 'voice' is specified."),
572
130
  },
573
- annotations: {
574
- readOnlyHint: true,
575
- destructiveHint: false,
576
- idempotentHint: false,
577
- openWorldHint: true,
578
- },
579
- }, async ({ word, language_abbr, voice, random }) => {
580
- try {
581
- const client = getClient();
582
- // Resolve language abbreviation
583
- let langAbbr = language_abbr;
584
- if (!langAbbr) {
585
- const userData = await client.getUserData();
586
- const langKeys = Object.keys(userData.language_data ?? {});
587
- langAbbr = langKeys[0];
588
- }
589
- if (!langAbbr) {
590
- return {
591
- content: [
592
- {
593
- type: 'text',
594
- text: 'No language found. Make sure you are learning a language.',
595
- },
596
- ],
597
- };
598
- }
599
- // If a specific voice is requested, build the URL directly.
600
- // URL format: {ttsBaseUrl}tts/{lang}/{voice}/token/{word}
601
- if (voice) {
602
- const url = await client.buildAudioUrl(word, langAbbr, voice);
603
- return { content: [{ type: 'text', text: url }] };
604
- }
605
- // If random voice is requested, discover available voices first.
606
- if (random) {
607
- const voices = await client.getLanguageVoices(langAbbr);
608
- if (voices.length > 0) {
609
- const selectedVoice = voices[Math.floor(Math.random() * voices.length)] ?? voices[0];
610
- const url = await client.buildAudioUrl(word, langAbbr, selectedVoice);
611
- return { content: [{ type: 'text', text: url }] };
612
- }
613
- }
614
- // Fall back to the default (no-voice) URL
615
- const url = await client.buildAudioUrl(word, langAbbr);
616
- return { content: [{ type: 'text', text: url }] };
617
- }
618
- catch (err) {
619
- return { content: [{ type: 'text', text: handleError(err) }] };
620
- }
621
- });
131
+ annotations: { ...READ_ONLY, idempotentHint: false },
132
+ }, ({ word, language_abbr, voice, random }) => reply(() => audioUrlView({ word, language_abbr, voice, random })));
622
133
  }
623
134
  //# sourceMappingURL=language.js.map