@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,30 @@
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 marketplaceBuyTool: {
16
+ name: string;
17
+ description: string;
18
+ inputSchema: {
19
+ type: "object";
20
+ properties: {
21
+ slug: {
22
+ type: string;
23
+ description: string;
24
+ };
25
+ };
26
+ required: string[];
27
+ };
28
+ handler(args: unknown): Promise<BuyResult>;
29
+ };
30
+ export {};
@@ -0,0 +1,97 @@
1
+ // ============================================================================
2
+ // Marketplace Buy Tool
3
+ // Purchase or claim books from the Telvok marketplace
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 marketplaceBuyTool = {
11
+ name: 'marketplace_buy',
12
+ description: `Purchase or claim a book from the Telvok marketplace.
13
+
14
+ For free (open) books: Instantly adds the book to your library.
15
+ For paid books: Returns a checkout URL to complete payment.
16
+
17
+ Requires authentication. Run auth({ action: "login" }) first if not connected.
18
+
19
+ Examples:
20
+ - marketplace_buy({ slug: "react-best-practices" })
21
+ - marketplace_buy({ slug: "premium-patterns" })`,
22
+ inputSchema: {
23
+ type: 'object',
24
+ properties: {
25
+ slug: {
26
+ type: 'string',
27
+ description: 'Book slug from marketplace_search results',
28
+ },
29
+ },
30
+ required: ['slug'],
31
+ },
32
+ async handler(args) {
33
+ const { slug } = args;
34
+ if (!slug || typeof slug !== 'string') {
35
+ throw new Error('Book slug is required');
36
+ }
37
+ // Check authentication
38
+ const apiKey = await loadApiKey();
39
+ if (!apiKey) {
40
+ return {
41
+ success: false,
42
+ message: 'Not authenticated. Run auth({ action: "login" }) to connect your Telvok account first.',
43
+ };
44
+ }
45
+ try {
46
+ const response = await fetch(`${TELVOK_API_URL}/api/purchase`, {
47
+ method: 'POST',
48
+ headers: {
49
+ 'Authorization': `Bearer ${apiKey}`,
50
+ 'Content-Type': 'application/json',
51
+ },
52
+ body: JSON.stringify({ slug }),
53
+ });
54
+ const data = await response.json();
55
+ if (!response.ok) {
56
+ return {
57
+ success: false,
58
+ message: data.error || `Purchase failed: HTTP ${response.status}`,
59
+ };
60
+ }
61
+ // Handle different response types
62
+ if (data.already_owned) {
63
+ return {
64
+ success: true,
65
+ already_owned: true,
66
+ message: data.message || `You already own '${data.book?.name || slug}'`,
67
+ book: data.book,
68
+ };
69
+ }
70
+ if (data.free_access) {
71
+ return {
72
+ success: true,
73
+ free_access: true,
74
+ message: data.message || `'${data.book?.name || slug}' added to your library (${data.book?.entries || 0} entries)`,
75
+ book: data.book,
76
+ };
77
+ }
78
+ if (data.checkout_url) {
79
+ return {
80
+ success: true,
81
+ checkout_url: data.checkout_url,
82
+ message: `Complete your purchase:\n\n${data.checkout_url}\n\nBook: ${data.book?.name || slug} (${data.book?.price || 'paid'})`,
83
+ book: data.book,
84
+ };
85
+ }
86
+ // Unexpected response
87
+ return {
88
+ success: false,
89
+ message: 'Unexpected response from purchase API',
90
+ };
91
+ }
92
+ catch (error) {
93
+ const message = error instanceof Error ? error.message : String(error);
94
+ throw new Error(`Purchase failed: ${message}`);
95
+ }
96
+ },
97
+ };
@@ -0,0 +1,26 @@
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 marketplaceDownloadTool: {
12
+ name: string;
13
+ description: string;
14
+ inputSchema: {
15
+ type: "object";
16
+ properties: {
17
+ slug: {
18
+ type: string;
19
+ description: string;
20
+ };
21
+ };
22
+ required: string[];
23
+ };
24
+ handler(args: unknown): Promise<DownloadResult>;
25
+ };
26
+ export {};
@@ -0,0 +1,160 @@
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 marketplaceDownloadTool = {
14
+ name: 'marketplace_download',
15
+ description: `Download a FREE (open) book to your local library.
16
+
17
+ Downloads content from free/open books to .librarian/packages/{slug}/ for offline access.
18
+
19
+ NOTE: Paid books (one-time or subscription) cannot be downloaded - they are cloud-only
20
+ for IP protection. Use brief({ query: "...", include_marketplace: true }) to access
21
+ content from paid books you own.
22
+
23
+ Requires authentication and ownership (purchased or free).
24
+
25
+ Examples:
26
+ - marketplace_download({ slug: "react-best-practices" })`,
27
+ inputSchema: {
28
+ type: 'object',
29
+ properties: {
30
+ slug: {
31
+ type: 'string',
32
+ description: 'Book slug to download',
33
+ },
34
+ },
35
+ required: ['slug'],
36
+ },
37
+ async handler(args) {
38
+ const { slug } = args;
39
+ if (!slug || typeof slug !== 'string') {
40
+ throw new Error('Book slug is required');
41
+ }
42
+ // Check authentication
43
+ const apiKey = await loadApiKey();
44
+ if (!apiKey) {
45
+ return {
46
+ success: false,
47
+ message: 'Not authenticated. Run auth({ action: "login" }) to connect your Telvok account first.',
48
+ };
49
+ }
50
+ try {
51
+ // Fetch content from API
52
+ const response = await fetch(`${TELVOK_API_URL}/api/content/${slug}`, {
53
+ method: 'GET',
54
+ headers: {
55
+ 'Authorization': `Bearer ${apiKey}`,
56
+ },
57
+ });
58
+ const data = await response.json();
59
+ if (!response.ok) {
60
+ return {
61
+ success: false,
62
+ message: data.error || `Download failed: HTTP ${response.status}`,
63
+ };
64
+ }
65
+ // Check if book is paid - reject download for paid content
66
+ const pricingType = data.book?.pricing_type;
67
+ if (pricingType && pricingType !== 'open') {
68
+ return {
69
+ success: false,
70
+ 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_marketplace: true })`,
71
+ };
72
+ }
73
+ // Save entries to packages directory
74
+ const libraryPath = getLibraryPath();
75
+ const packagesPath = getPackagesPath(libraryPath);
76
+ const bookPath = path.join(packagesPath, slug);
77
+ // Create directory
78
+ await fs.mkdir(bookPath, { recursive: true });
79
+ // Write each entry as a markdown file
80
+ const entries = data.entries || [];
81
+ for (const entry of entries) {
82
+ const filename = slugify(entry.title) + '.md';
83
+ const content = formatEntry(entry);
84
+ await fs.writeFile(path.join(bookPath, filename), content, 'utf-8');
85
+ }
86
+ // Write metadata file
87
+ const metadata = {
88
+ slug: data.book.slug,
89
+ name: data.book.name,
90
+ description: data.book.description,
91
+ version: data.book.version,
92
+ downloaded_at: new Date().toISOString(),
93
+ entry_count: entries.length,
94
+ };
95
+ await fs.writeFile(path.join(bookPath, '_metadata.json'), JSON.stringify(metadata, null, 2), 'utf-8');
96
+ return {
97
+ success: true,
98
+ message: `Downloaded '${data.book.name}' (${entries.length} entries) to ${bookPath}`,
99
+ book: {
100
+ slug: data.book.slug,
101
+ name: data.book.name,
102
+ entries: entries.length,
103
+ },
104
+ path: bookPath,
105
+ };
106
+ }
107
+ catch (error) {
108
+ const message = error instanceof Error ? error.message : String(error);
109
+ throw new Error(`Download failed: ${message}`);
110
+ }
111
+ },
112
+ };
113
+ // ============================================================================
114
+ // Helpers
115
+ // ============================================================================
116
+ function slugify(text) {
117
+ return text
118
+ .toLowerCase()
119
+ .replace(/[^a-z0-9]+/g, '-')
120
+ .replace(/^-|-$/g, '')
121
+ .substring(0, 50);
122
+ }
123
+ function formatEntry(entry) {
124
+ const lines = [];
125
+ // Frontmatter
126
+ lines.push('---');
127
+ if (entry.intent)
128
+ lines.push(`intent: "${entry.intent.replace(/"/g, '\\"')}"`);
129
+ if (entry.context)
130
+ lines.push(`context: "${entry.context.replace(/"/g, '\\"')}"`);
131
+ lines.push(`created: "${new Date().toISOString()}"`);
132
+ lines.push('source: "marketplace"');
133
+ lines.push('hits: 0');
134
+ lines.push('last_hit: null');
135
+ lines.push('---');
136
+ lines.push('');
137
+ // Title
138
+ lines.push(`# ${entry.title}`);
139
+ lines.push('');
140
+ // Insight/content
141
+ if (entry.insight) {
142
+ lines.push(entry.insight);
143
+ lines.push('');
144
+ }
145
+ // Reasoning
146
+ if (entry.reasoning) {
147
+ lines.push('## Reasoning');
148
+ lines.push('');
149
+ lines.push(entry.reasoning);
150
+ lines.push('');
151
+ }
152
+ // Example
153
+ if (entry.example) {
154
+ lines.push('## Example');
155
+ lines.push('');
156
+ lines.push(entry.example);
157
+ lines.push('');
158
+ }
159
+ return lines.join('\n');
160
+ }
@@ -0,0 +1,111 @@
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 marketplacePublishTool: {
30
+ name: string;
31
+ description: string;
32
+ inputSchema: {
33
+ type: "object";
34
+ properties: {
35
+ name: {
36
+ type: string;
37
+ description: string;
38
+ };
39
+ description: {
40
+ type: string;
41
+ description: string;
42
+ };
43
+ pricing: {
44
+ type: string;
45
+ properties: {
46
+ type: {
47
+ type: string;
48
+ enum: string[];
49
+ description: string;
50
+ };
51
+ price_cents: {
52
+ type: string;
53
+ description: string;
54
+ };
55
+ };
56
+ required: string[];
57
+ description: string;
58
+ };
59
+ consumption: {
60
+ type: string;
61
+ enum: string[];
62
+ description: string;
63
+ };
64
+ attestation: {
65
+ type: string;
66
+ properties: {
67
+ original_work: {
68
+ type: string;
69
+ description: string;
70
+ };
71
+ no_secrets: {
72
+ type: string;
73
+ description: string;
74
+ };
75
+ terms_accepted: {
76
+ type: string;
77
+ description: string;
78
+ };
79
+ };
80
+ required: string[];
81
+ description: string;
82
+ };
83
+ preview: {
84
+ type: string;
85
+ description: string;
86
+ };
87
+ entries: {
88
+ type: string;
89
+ items: {
90
+ type: string;
91
+ };
92
+ description: string;
93
+ };
94
+ tags: {
95
+ type: string;
96
+ items: {
97
+ type: string;
98
+ };
99
+ description: string;
100
+ };
101
+ license: {
102
+ type: string;
103
+ enum: string[];
104
+ description: string;
105
+ };
106
+ };
107
+ required: string[];
108
+ };
109
+ handler(args: unknown): Promise<PublishResult>;
110
+ };
111
+ export default marketplacePublishTool;