@telvok/librarian-mcp 1.5.4 → 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 (119) hide show
  1. package/dist/library/errors.d.ts +48 -0
  2. package/dist/library/errors.js +80 -0
  3. package/dist/library/schemas.d.ts +6 -6
  4. package/dist/library/storage.d.ts +2 -2
  5. package/dist/library/storage.js +2 -2
  6. package/dist/library 2/embeddings.d.ts +21 -0
  7. package/dist/library 2/embeddings.js +86 -0
  8. package/dist/library 2/manager.d.ts +42 -0
  9. package/dist/library 2/manager.js +218 -0
  10. package/dist/library 2/parsers/cursor.d.ts +15 -0
  11. package/dist/library 2/parsers/cursor.js +168 -0
  12. package/dist/library 2/parsers/index.d.ts +6 -0
  13. package/dist/library 2/parsers/index.js +5 -0
  14. package/dist/library 2/parsers/json.d.ts +11 -0
  15. package/dist/library 2/parsers/json.js +95 -0
  16. package/dist/library 2/parsers/jsonl.d.ts +14 -0
  17. package/dist/library 2/parsers/jsonl.js +85 -0
  18. package/dist/library 2/parsers/markdown.d.ts +15 -0
  19. package/dist/library 2/parsers/markdown.js +77 -0
  20. package/dist/library 2/parsers/sqlite.d.ts +8 -0
  21. package/dist/library 2/parsers/sqlite.js +123 -0
  22. package/dist/library 2/parsers/types.d.ts +21 -0
  23. package/dist/library 2/parsers/types.js +4 -0
  24. package/dist/library 2/query.d.ts +26 -0
  25. package/dist/library 2/query.js +104 -0
  26. package/dist/library 2/schemas.d.ts +324 -0
  27. package/dist/library 2/schemas.js +79 -0
  28. package/dist/library 2/storage.d.ts +22 -0
  29. package/dist/library 2/storage.js +36 -0
  30. package/dist/library 2/vector-index.d.ts +55 -0
  31. package/dist/library 2/vector-index.js +160 -0
  32. package/dist/server 2.js +199 -0
  33. package/dist/server.d 2.ts +2 -0
  34. package/dist/server.js +102 -54
  35. package/dist/tools/adopt.d.ts +1 -0
  36. package/dist/tools/adopt.js +37 -10
  37. package/dist/tools/auth.d.ts +69 -0
  38. package/dist/tools/auth.js +379 -0
  39. package/dist/tools/bounty-claim.d.ts +28 -0
  40. package/dist/tools/bounty-claim.js +92 -0
  41. package/dist/tools/bounty-create.d.ts +47 -0
  42. package/dist/tools/bounty-create.js +118 -0
  43. package/dist/tools/bounty-list.d.ts +50 -0
  44. package/dist/tools/bounty-list.js +116 -0
  45. package/dist/tools/bounty-submit.d.ts +34 -0
  46. package/dist/tools/bounty-submit.js +94 -0
  47. package/dist/tools/brief.d.ts +94 -0
  48. package/dist/tools/brief.js +234 -15
  49. package/dist/tools/delete.d.ts +87 -0
  50. package/dist/tools/delete.js +266 -0
  51. package/dist/tools/feedback.d.ts +27 -0
  52. package/dist/tools/feedback.js +98 -0
  53. package/dist/tools/help.d.ts +22 -0
  54. package/dist/tools/help.js +482 -0
  55. package/dist/tools/import-memories.d.ts +1 -0
  56. package/dist/tools/import-memories.js +18 -13
  57. package/dist/tools/index.d.ts +11 -0
  58. package/dist/tools/index.js +12 -0
  59. package/dist/tools/library-buy.d.ts +31 -0
  60. package/dist/tools/library-buy.js +104 -0
  61. package/dist/tools/library-download.d.ts +27 -0
  62. package/dist/tools/library-download.js +177 -0
  63. package/dist/tools/library-publish.d.ts +112 -0
  64. package/dist/tools/library-publish.js +387 -0
  65. package/dist/tools/library-search.d.ts +110 -0
  66. package/dist/tools/library-search.js +132 -0
  67. package/dist/tools/mark-hit.d.ts +1 -0
  68. package/dist/tools/mark-hit.js +83 -5
  69. package/dist/tools/my-books.d.ts +51 -0
  70. package/dist/tools/my-books.js +115 -0
  71. package/dist/tools/my-bounties.d.ts +43 -0
  72. package/dist/tools/my-bounties.js +126 -0
  73. package/dist/tools/rate-book.d.ts +40 -0
  74. package/dist/tools/rate-book.js +147 -0
  75. package/dist/tools/rebuild-index.d.ts +1 -0
  76. package/dist/tools/rebuild-index.js +40 -8
  77. package/dist/tools/record.d.ts +18 -0
  78. package/dist/tools/record.js +30 -26
  79. package/dist/tools/seller-analytics.d.ts +53 -0
  80. package/dist/tools/seller-analytics.js +180 -0
  81. package/dist/tools/sync.d.ts +55 -0
  82. package/dist/tools/sync.js +304 -0
  83. package/dist/tools/unsubscribe.d.ts +48 -0
  84. package/dist/tools/unsubscribe.js +120 -0
  85. package/dist/tools 2/adopt.d.ts +24 -0
  86. package/dist/tools 2/adopt.js +154 -0
  87. package/dist/tools 2/auth.d.ts +35 -0
  88. package/dist/tools 2/auth.js +229 -0
  89. package/dist/tools 2/brief.d.ts +56 -0
  90. package/dist/tools 2/brief.js +414 -0
  91. package/dist/tools 2/help.d.ts +21 -0
  92. package/dist/tools 2/help.js +267 -0
  93. package/dist/tools 2/import-memories.d.ts +32 -0
  94. package/dist/tools 2/import-memories.js +231 -0
  95. package/dist/tools 2/index.d.ts +12 -0
  96. package/dist/tools 2/index.js +12 -0
  97. package/dist/tools 2/mark-hit.d.ts +20 -0
  98. package/dist/tools 2/mark-hit.js +71 -0
  99. package/dist/tools 2/marketplace-buy.d.ts +30 -0
  100. package/dist/tools 2/marketplace-buy.js +97 -0
  101. package/dist/tools 2/marketplace-download.d.ts +26 -0
  102. package/dist/tools 2/marketplace-download.js +160 -0
  103. package/dist/tools 2/marketplace-publish.d.ts +111 -0
  104. package/dist/tools 2/marketplace-publish.js +377 -0
  105. package/dist/tools 2/marketplace-search.d.ts +57 -0
  106. package/dist/tools 2/marketplace-search.js +96 -0
  107. package/dist/tools 2/my-books.d.ts +50 -0
  108. package/dist/tools 2/my-books.js +107 -0
  109. package/dist/tools 2/rate-book.d.ts +39 -0
  110. package/dist/tools 2/rate-book.js +139 -0
  111. package/dist/tools 2/rebuild-index.d.ts +23 -0
  112. package/dist/tools 2/rebuild-index.js +107 -0
  113. package/dist/tools 2/record.d.ts +40 -0
  114. package/dist/tools 2/record.js +205 -0
  115. package/dist/tools 2/seller-analytics.d.ts +35 -0
  116. package/dist/tools 2/seller-analytics.js +102 -0
  117. package/dist/tools 2/sync.d.ts +54 -0
  118. package/dist/tools 2/sync.js +298 -0
  119. package/package.json +1 -1
@@ -0,0 +1,31 @@
1
+ interface BuyResult {
2
+ success: boolean;
3
+ message: string;
4
+ checkout_url?: string;
5
+ already_owned?: boolean;
6
+ free_access?: boolean;
7
+ book?: {
8
+ slug: string;
9
+ name: string;
10
+ entries?: number;
11
+ price?: string;
12
+ pricing_type?: string;
13
+ };
14
+ }
15
+ export declare const libraryBuyTool: {
16
+ name: string;
17
+ title: string;
18
+ description: string;
19
+ inputSchema: {
20
+ type: "object";
21
+ properties: {
22
+ slug: {
23
+ type: string;
24
+ description: string;
25
+ };
26
+ };
27
+ required: string[];
28
+ };
29
+ handler(args: unknown): Promise<BuyResult>;
30
+ };
31
+ export {};
@@ -0,0 +1,104 @@
1
+ // ============================================================================
2
+ // Marketplace Buy Tool
3
+ // Purchase or claim books from the Telvok library
4
+ // ============================================================================
5
+ import { loadApiKey } from './auth.js';
6
+ const TELVOK_API_URL = process.env.TELVOK_API_URL || 'https://telvok.com';
7
+ // ============================================================================
8
+ // Tool Definition
9
+ // ============================================================================
10
+ export const libraryBuyTool = {
11
+ name: 'library_buy',
12
+ title: 'Purchase Book',
13
+ description: `Purchase or claim a book from Telvok marketplace.
14
+
15
+ USE THIS TOOL WHEN:
16
+ - User wants to buy a book from library_search() results
17
+ - Claiming a free (open) book
18
+ - User says "get", "buy", "purchase", or "claim" a book
19
+
20
+ Free books: Instantly added to library. Paid: Returns checkout URL.
21
+
22
+ TRIGGER PATTERNS:
23
+ - "Buy that book" → library_buy({ slug: "<slug from search>" })
24
+ - "Get the free one" → library_buy({ slug: "..." })
25
+ - User selects from library_search results → library_buy({ slug: "..." })
26
+
27
+ Example:
28
+ - library_buy({ slug: "react-best-practices" })`,
29
+ inputSchema: {
30
+ type: 'object',
31
+ properties: {
32
+ slug: {
33
+ type: 'string',
34
+ description: 'Book slug from library_search results',
35
+ },
36
+ },
37
+ required: ['slug'],
38
+ },
39
+ async handler(args) {
40
+ const { slug } = args;
41
+ if (!slug || typeof slug !== 'string') {
42
+ throw new Error('Book slug is required');
43
+ }
44
+ // Check authentication
45
+ const apiKey = await loadApiKey();
46
+ if (!apiKey) {
47
+ return {
48
+ success: false,
49
+ message: 'Not authenticated. Run auth({ action: "login" }) to connect your Telvok account first.',
50
+ };
51
+ }
52
+ try {
53
+ const response = await fetch(`${TELVOK_API_URL}/api/purchase`, {
54
+ method: 'POST',
55
+ headers: {
56
+ 'Authorization': `Bearer ${apiKey}`,
57
+ 'Content-Type': 'application/json',
58
+ },
59
+ body: JSON.stringify({ slug }),
60
+ });
61
+ const data = await response.json();
62
+ if (!response.ok) {
63
+ return {
64
+ success: false,
65
+ message: data.error || `Purchase failed: HTTP ${response.status}`,
66
+ };
67
+ }
68
+ // Handle different response types
69
+ if (data.already_owned) {
70
+ return {
71
+ success: true,
72
+ already_owned: true,
73
+ message: data.message || `You already own '${data.book?.name || slug}'`,
74
+ book: data.book,
75
+ };
76
+ }
77
+ if (data.free_access) {
78
+ return {
79
+ success: true,
80
+ free_access: true,
81
+ message: data.message || `'${data.book?.name || slug}' added to your library (${data.book?.entries || 0} entries)`,
82
+ book: data.book,
83
+ };
84
+ }
85
+ if (data.checkout_url) {
86
+ return {
87
+ success: true,
88
+ checkout_url: data.checkout_url,
89
+ message: `Complete your purchase:\n\n${data.checkout_url}\n\nBook: ${data.book?.name || slug} (${data.book?.price || 'paid'})`,
90
+ book: data.book,
91
+ };
92
+ }
93
+ // Unexpected response
94
+ return {
95
+ success: false,
96
+ message: 'Unexpected response from purchase API',
97
+ };
98
+ }
99
+ catch (error) {
100
+ const message = error instanceof Error ? error.message : String(error);
101
+ throw new Error(`Purchase failed: ${message}`);
102
+ }
103
+ },
104
+ };
@@ -0,0 +1,27 @@
1
+ interface DownloadResult {
2
+ success: boolean;
3
+ message: string;
4
+ book?: {
5
+ slug: string;
6
+ name: string;
7
+ entries: number;
8
+ };
9
+ path?: string;
10
+ }
11
+ export declare const libraryDownloadTool: {
12
+ name: string;
13
+ title: string;
14
+ description: string;
15
+ inputSchema: {
16
+ type: "object";
17
+ properties: {
18
+ slug: {
19
+ type: string;
20
+ description: string;
21
+ };
22
+ };
23
+ required: string[];
24
+ };
25
+ handler(args: unknown): Promise<DownloadResult>;
26
+ };
27
+ export {};
@@ -0,0 +1,177 @@
1
+ // ============================================================================
2
+ // Marketplace Download Tool
3
+ // Download purchased books to local library
4
+ // ============================================================================
5
+ import * as fs from 'fs/promises';
6
+ import * as path from 'path';
7
+ import { loadApiKey } from './auth.js';
8
+ import { getLibraryPath, getPackagesPath } from '../library/storage.js';
9
+ const TELVOK_API_URL = process.env.TELVOK_API_URL || 'https://telvok.com';
10
+ // ============================================================================
11
+ // Tool Definition
12
+ // ============================================================================
13
+ export const libraryDownloadTool = {
14
+ name: 'library_download',
15
+ title: 'Download Free Book',
16
+ description: `Download a FREE (open) book for offline access.
17
+
18
+ USE THIS TOOL WHEN:
19
+ - User wants to download a free book they own
20
+ - Need offline access to open-source book content
21
+ - User says "download that book"
22
+
23
+ Downloads to .librarian/packages/{slug}/. Only works for FREE books.
24
+ Paid books are cloud-only - use brief({ include_library: true }) instead.
25
+
26
+ TRIGGER PATTERNS:
27
+ - "Download that free book" → library_download({ slug: "..." })
28
+ - After library_buy() on free book → library_download({ slug: "..." })
29
+
30
+ Example:
31
+ - library_download({ slug: "react-best-practices" })`,
32
+ inputSchema: {
33
+ type: 'object',
34
+ properties: {
35
+ slug: {
36
+ type: 'string',
37
+ description: 'Book slug to download',
38
+ },
39
+ },
40
+ required: ['slug'],
41
+ },
42
+ async handler(args) {
43
+ const { slug } = args;
44
+ if (!slug || typeof slug !== 'string') {
45
+ throw new Error('Book slug is required');
46
+ }
47
+ // Check authentication
48
+ const apiKey = await loadApiKey();
49
+ if (!apiKey) {
50
+ return {
51
+ success: false,
52
+ message: 'Not authenticated. Run auth({ action: "login" }) to connect your Telvok account first.',
53
+ };
54
+ }
55
+ try {
56
+ // Fetch content from API
57
+ const response = await fetch(`${TELVOK_API_URL}/api/content/${slug}`, {
58
+ method: 'GET',
59
+ headers: {
60
+ 'Authorization': `Bearer ${apiKey}`,
61
+ },
62
+ });
63
+ const data = await response.json();
64
+ if (!response.ok) {
65
+ return {
66
+ success: false,
67
+ message: data.error || `Download failed: HTTP ${response.status}`,
68
+ };
69
+ }
70
+ // Check if book is paid - reject download for paid content
71
+ const pricingType = data.book?.pricing_type;
72
+ if (pricingType && pricingType !== 'open') {
73
+ return {
74
+ success: false,
75
+ message: `Paid content cannot be downloaded locally. '${data.book.name}' is a ${pricingType === 'subscription' ? 'subscription' : 'paid'} book.\n\nTo access content from paid books, use:\n brief({ query: "your search", include_library: true })`,
76
+ };
77
+ }
78
+ // Save entries to packages directory
79
+ const libraryPath = getLibraryPath();
80
+ const packagesPath = getPackagesPath(libraryPath);
81
+ const bookPath = path.join(packagesPath, slug);
82
+ // Create directory
83
+ await fs.mkdir(bookPath, { recursive: true });
84
+ // Clean up existing .md files to remove orphaned entries from deleted content
85
+ try {
86
+ const existingFiles = await fs.readdir(bookPath);
87
+ for (const file of existingFiles) {
88
+ if (file.endsWith('.md')) {
89
+ await fs.unlink(path.join(bookPath, file));
90
+ }
91
+ }
92
+ }
93
+ catch {
94
+ // Directory might be new or empty, ignore errors
95
+ }
96
+ // Write each entry as a markdown file
97
+ const entries = data.entries || [];
98
+ for (const entry of entries) {
99
+ const filename = slugify(entry.title) + '.md';
100
+ const content = formatEntry(entry);
101
+ await fs.writeFile(path.join(bookPath, filename), content, 'utf-8');
102
+ }
103
+ // Write metadata file
104
+ const metadata = {
105
+ slug: data.book.slug,
106
+ name: data.book.name,
107
+ description: data.book.description,
108
+ version: data.book.version,
109
+ downloaded_at: new Date().toISOString(),
110
+ entry_count: entries.length,
111
+ };
112
+ await fs.writeFile(path.join(bookPath, '_metadata.json'), JSON.stringify(metadata, null, 2), 'utf-8');
113
+ return {
114
+ success: true,
115
+ message: `Downloaded '${data.book.name}' (${entries.length} entries) to ${bookPath}`,
116
+ book: {
117
+ slug: data.book.slug,
118
+ name: data.book.name,
119
+ entries: entries.length,
120
+ },
121
+ path: bookPath,
122
+ };
123
+ }
124
+ catch (error) {
125
+ const message = error instanceof Error ? error.message : String(error);
126
+ throw new Error(`Download failed: ${message}`);
127
+ }
128
+ },
129
+ };
130
+ // ============================================================================
131
+ // Helpers
132
+ // ============================================================================
133
+ function slugify(text) {
134
+ return text
135
+ .toLowerCase()
136
+ .replace(/[^a-z0-9]+/g, '-')
137
+ .replace(/^-|-$/g, '')
138
+ .substring(0, 50);
139
+ }
140
+ function formatEntry(entry) {
141
+ const lines = [];
142
+ // Frontmatter
143
+ lines.push('---');
144
+ if (entry.intent)
145
+ lines.push(`intent: "${entry.intent.replace(/"/g, '\\"')}"`);
146
+ if (entry.context)
147
+ lines.push(`context: "${entry.context.replace(/"/g, '\\"')}"`);
148
+ lines.push(`created: "${new Date().toISOString()}"`);
149
+ lines.push('source: "library"');
150
+ lines.push('hits: 0');
151
+ lines.push('last_hit: null');
152
+ lines.push('---');
153
+ lines.push('');
154
+ // Title
155
+ lines.push(`# ${entry.title}`);
156
+ lines.push('');
157
+ // Insight/content
158
+ if (entry.insight) {
159
+ lines.push(entry.insight);
160
+ lines.push('');
161
+ }
162
+ // Reasoning
163
+ if (entry.reasoning) {
164
+ lines.push('## Reasoning');
165
+ lines.push('');
166
+ lines.push(entry.reasoning);
167
+ lines.push('');
168
+ }
169
+ // Example
170
+ if (entry.example) {
171
+ lines.push('## Example');
172
+ lines.push('');
173
+ lines.push(entry.example);
174
+ lines.push('');
175
+ }
176
+ return lines.join('\n');
177
+ }
@@ -0,0 +1,112 @@
1
+ interface PublishResult {
2
+ success: boolean;
3
+ message: string;
4
+ book?: {
5
+ id?: string;
6
+ slug: string;
7
+ name: string;
8
+ url: string;
9
+ };
10
+ entries_count?: number;
11
+ setup_url?: string;
12
+ preview?: boolean;
13
+ summary?: {
14
+ name: string;
15
+ pricing: {
16
+ type: string;
17
+ display: string;
18
+ };
19
+ entries_count: number;
20
+ entries: Array<{
21
+ title: string;
22
+ file: string;
23
+ }>;
24
+ };
25
+ next_steps?: string;
26
+ options?: Record<string, string>;
27
+ required?: Record<string, string>;
28
+ }
29
+ export declare const libraryPublishTool: {
30
+ name: string;
31
+ title: string;
32
+ description: string;
33
+ inputSchema: {
34
+ type: "object";
35
+ properties: {
36
+ name: {
37
+ type: string;
38
+ description: string;
39
+ };
40
+ description: {
41
+ type: string;
42
+ description: string;
43
+ };
44
+ pricing: {
45
+ type: string;
46
+ properties: {
47
+ type: {
48
+ type: string;
49
+ enum: string[];
50
+ description: string;
51
+ };
52
+ price_cents: {
53
+ type: string;
54
+ description: string;
55
+ };
56
+ };
57
+ required: string[];
58
+ description: string;
59
+ };
60
+ consumption: {
61
+ type: string;
62
+ enum: string[];
63
+ description: string;
64
+ };
65
+ attestation: {
66
+ type: string;
67
+ properties: {
68
+ original_work: {
69
+ type: string;
70
+ description: string;
71
+ };
72
+ no_secrets: {
73
+ type: string;
74
+ description: string;
75
+ };
76
+ terms_accepted: {
77
+ type: string;
78
+ description: string;
79
+ };
80
+ };
81
+ required: string[];
82
+ description: string;
83
+ };
84
+ preview: {
85
+ type: string;
86
+ description: string;
87
+ };
88
+ entries: {
89
+ type: string;
90
+ items: {
91
+ type: string;
92
+ };
93
+ description: string;
94
+ };
95
+ tags: {
96
+ type: string;
97
+ items: {
98
+ type: string;
99
+ };
100
+ description: string;
101
+ };
102
+ license: {
103
+ type: string;
104
+ enum: string[];
105
+ description: string;
106
+ };
107
+ };
108
+ required: string[];
109
+ };
110
+ handler(args: unknown): Promise<PublishResult>;
111
+ };
112
+ export default libraryPublishTool;