notebooklm-kit 0.0.1 → 2.1.1

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 (100) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +4102 -0
  3. package/dist/src/auth/auth.d.ts +46 -0
  4. package/dist/src/auth/auth.d.ts.map +1 -0
  5. package/dist/src/auth/auth.js +323 -0
  6. package/dist/src/auth/auth.js.map +1 -0
  7. package/dist/src/auth/refresh.d.ts +150 -0
  8. package/dist/src/auth/refresh.d.ts.map +1 -0
  9. package/dist/src/auth/refresh.js +433 -0
  10. package/dist/src/auth/refresh.js.map +1 -0
  11. package/dist/src/client/notebooklm-client.d.ts +372 -0
  12. package/dist/src/client/notebooklm-client.d.ts.map +1 -0
  13. package/dist/src/client/notebooklm-client.js +550 -0
  14. package/dist/src/client/notebooklm-client.js.map +1 -0
  15. package/dist/src/index.d.ts +50 -0
  16. package/dist/src/index.d.ts.map +1 -0
  17. package/dist/src/index.js +45 -0
  18. package/dist/src/index.js.map +1 -0
  19. package/dist/src/rpc/rpc-client.d.ts +48 -0
  20. package/dist/src/rpc/rpc-client.d.ts.map +1 -0
  21. package/dist/src/rpc/rpc-client.js +94 -0
  22. package/dist/src/rpc/rpc-client.js.map +1 -0
  23. package/dist/src/rpc/rpc-methods.d.ts +127 -0
  24. package/dist/src/rpc/rpc-methods.d.ts.map +1 -0
  25. package/dist/src/rpc/rpc-methods.js +169 -0
  26. package/dist/src/rpc/rpc-methods.js.map +1 -0
  27. package/dist/src/services/artifacts.d.ts +1017 -0
  28. package/dist/src/services/artifacts.d.ts.map +1 -0
  29. package/dist/src/services/artifacts.js +5413 -0
  30. package/dist/src/services/artifacts.js.map +1 -0
  31. package/dist/src/services/generation.d.ts +147 -0
  32. package/dist/src/services/generation.d.ts.map +1 -0
  33. package/dist/src/services/generation.js +479 -0
  34. package/dist/src/services/generation.js.map +1 -0
  35. package/dist/src/services/notebook-language.d.ts +109 -0
  36. package/dist/src/services/notebook-language.d.ts.map +1 -0
  37. package/dist/src/services/notebook-language.js +204 -0
  38. package/dist/src/services/notebook-language.js.map +1 -0
  39. package/dist/src/services/notebooks.d.ts +26 -0
  40. package/dist/src/services/notebooks.d.ts.map +1 -0
  41. package/dist/src/services/notebooks.js +539 -0
  42. package/dist/src/services/notebooks.js.map +1 -0
  43. package/dist/src/services/notes.d.ts +72 -0
  44. package/dist/src/services/notes.d.ts.map +1 -0
  45. package/dist/src/services/notes.js +340 -0
  46. package/dist/src/services/notes.js.map +1 -0
  47. package/dist/src/services/sources.d.ts +1085 -0
  48. package/dist/src/services/sources.d.ts.map +1 -0
  49. package/dist/src/services/sources.js +2675 -0
  50. package/dist/src/services/sources.js.map +1 -0
  51. package/dist/src/types/artifact.d.ts +258 -0
  52. package/dist/src/types/artifact.d.ts.map +1 -0
  53. package/dist/src/types/artifact.js +42 -0
  54. package/dist/src/types/artifact.js.map +1 -0
  55. package/dist/src/types/common.d.ts +226 -0
  56. package/dist/src/types/common.d.ts.map +1 -0
  57. package/dist/src/types/common.js +80 -0
  58. package/dist/src/types/common.js.map +1 -0
  59. package/dist/src/types/languages.d.ts +179 -0
  60. package/dist/src/types/languages.d.ts.map +1 -0
  61. package/dist/src/types/languages.js +254 -0
  62. package/dist/src/types/languages.js.map +1 -0
  63. package/dist/src/types/note.d.ts +41 -0
  64. package/dist/src/types/note.d.ts.map +1 -0
  65. package/dist/src/types/note.js +12 -0
  66. package/dist/src/types/note.js.map +1 -0
  67. package/dist/src/types/notebook.d.ts +81 -0
  68. package/dist/src/types/notebook.d.ts.map +1 -0
  69. package/dist/src/types/notebook.js +5 -0
  70. package/dist/src/types/notebook.js.map +1 -0
  71. package/dist/src/types/source.d.ts +241 -0
  72. package/dist/src/types/source.d.ts.map +1 -0
  73. package/dist/src/types/source.js +60 -0
  74. package/dist/src/types/source.js.map +1 -0
  75. package/dist/src/utils/batch-execute.d.ts +58 -0
  76. package/dist/src/utils/batch-execute.d.ts.map +1 -0
  77. package/dist/src/utils/batch-execute.js +398 -0
  78. package/dist/src/utils/batch-execute.js.map +1 -0
  79. package/dist/src/utils/chunked-decoder.d.ts +11 -0
  80. package/dist/src/utils/chunked-decoder.d.ts.map +1 -0
  81. package/dist/src/utils/chunked-decoder.js +326 -0
  82. package/dist/src/utils/chunked-decoder.js.map +1 -0
  83. package/dist/src/utils/chunked-parser.d.ts +61 -0
  84. package/dist/src/utils/chunked-parser.d.ts.map +1 -0
  85. package/dist/src/utils/chunked-parser.js +609 -0
  86. package/dist/src/utils/chunked-parser.js.map +1 -0
  87. package/dist/src/utils/errors.d.ts +58 -0
  88. package/dist/src/utils/errors.d.ts.map +1 -0
  89. package/dist/src/utils/errors.js +357 -0
  90. package/dist/src/utils/errors.js.map +1 -0
  91. package/dist/src/utils/quota.d.ts +213 -0
  92. package/dist/src/utils/quota.d.ts.map +1 -0
  93. package/dist/src/utils/quota.js +518 -0
  94. package/dist/src/utils/quota.js.map +1 -0
  95. package/dist/src/utils/streaming-client.d.ts +129 -0
  96. package/dist/src/utils/streaming-client.d.ts.map +1 -0
  97. package/dist/src/utils/streaming-client.js +559 -0
  98. package/dist/src/utils/streaming-client.js.map +1 -0
  99. package/package.json +85 -7
  100. package/index.js +0 -2
@@ -0,0 +1,479 @@
1
+ /**
2
+ * Generation service
3
+ * Handles generation operations (guides, chat)
4
+ *
5
+ * CRITICAL FIXES VERIFIED:
6
+ * ========================
7
+ * 1. ✅ notebookId passed to streamingClient.streamChat() (line ~376)
8
+ * 2. ✅ Source IDs extracted from notebook before chat (line ~214-250)
9
+ * 3. ✅ Request structure correct: [contextItems, prompt, null, [2,null,[1]], notebookId]
10
+ *
11
+ * This service correctly calls the streaming client with all required parameters.
12
+ * The streaming client handles the URL building (with source-path) and request
13
+ * body formatting (with notebookId as last parameter).
14
+ *
15
+ * All three critical bugs are fixed:
16
+ * - ❌ Bug #1: Missing source-path → ✅ Fixed in streaming-client.ts line ~230
17
+ * - ❌ Bug #2: Double URL encoding → ✅ Fixed in streaming-client.ts line ~219
18
+ * - ❌ Bug #3: Wrong ID in body → ✅ Fixed in streaming-client.ts line ~298
19
+ */
20
+ import * as RPC from '../rpc/rpc-methods.js';
21
+ import { NotebookLMError, ChatGoalType, ChatResponseLength } from '../types/common.js';
22
+ import { StreamingClient } from '../utils/streaming-client.js';
23
+ /**
24
+ * Service for generation operations
25
+ */
26
+ export class GenerationService {
27
+ rpc;
28
+ quota;
29
+ streamingClient;
30
+ constructor(rpc, quota) {
31
+ this.rpc = rpc;
32
+ this.quota = quota;
33
+ // Initialize streaming client with RPC config
34
+ const rpcConfig = this.rpc.getConfig();
35
+ // Add batch client reference for f.sid access
36
+ rpcConfig.batchClient = this.rpc.getBatchClient();
37
+ this.streamingClient = new StreamingClient(rpcConfig);
38
+ }
39
+ /**
40
+ * Set chat configuration
41
+ *
42
+ * @param notebookId - The notebook ID
43
+ * @param config - Chat configuration options
44
+ * @param config.type - Configuration type: 'default' | 'custom' | 'learning-guide'
45
+ * @param config.customText - Custom prompt text (required if type is 'custom')
46
+ * @param config.responseLength - Response length: 'default' | 'shorter' | 'longer'
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * // Set default configuration
51
+ * await client.generation.setChatConfig('notebook-id', { type: 'default', responseLength: 'default' });
52
+ *
53
+ * // Set custom configuration
54
+ * await client.generation.setChatConfig('notebook-id', {
55
+ * type: 'custom',
56
+ * customText: 'respond as phd student',
57
+ * responseLength: 'default'
58
+ * });
59
+ *
60
+ * // Set learning guide configuration
61
+ * await client.generation.setChatConfig('notebook-id', { type: 'learning-guide', responseLength: 'default' });
62
+ * ```
63
+ */
64
+ async setChatConfig(notebookId, config) {
65
+ // Validate config
66
+ if (config.type === 'custom' && !config.customText) {
67
+ throw new NotebookLMError('customText is required when type is "custom"');
68
+ }
69
+ // Map config type to numeric value using enum
70
+ let configType;
71
+ if (config.type === 'default') {
72
+ configType = ChatGoalType.DEFAULT;
73
+ }
74
+ else if (config.type === 'custom') {
75
+ configType = ChatGoalType.CUSTOM;
76
+ }
77
+ else if (config.type === 'learning-guide') {
78
+ configType = ChatGoalType.LEARNING_GUIDE;
79
+ }
80
+ else {
81
+ throw new NotebookLMError(`Invalid config type: ${config.type}`);
82
+ }
83
+ // Map response length to numeric value using enum
84
+ let responseLength;
85
+ if (config.responseLength === 'default') {
86
+ responseLength = ChatResponseLength.DEFAULT;
87
+ }
88
+ else if (config.responseLength === 'shorter') {
89
+ // Shorter is 5 for custom, but we use 2 for others (API quirk)
90
+ responseLength = config.type === 'custom' ? ChatResponseLength.SHORTER : 2;
91
+ }
92
+ else if (config.responseLength === 'longer') {
93
+ responseLength = ChatResponseLength.LONGER;
94
+ }
95
+ else {
96
+ throw new NotebookLMError(`Invalid response length: ${config.responseLength}`);
97
+ }
98
+ // Build config array
99
+ // Format: [[goal, custom_text?], [length?]]
100
+ // Length is only included if it's not default (1)
101
+ const configArray = [];
102
+ if (config.type === 'custom' && config.customText) {
103
+ configArray.push([configType, config.customText]);
104
+ }
105
+ else {
106
+ configArray.push([configType]);
107
+ }
108
+ // Only include length if it's not default
109
+ if (responseLength !== ChatResponseLength.DEFAULT) {
110
+ configArray.push([responseLength]);
111
+ }
112
+ // Build full request: [notebookId, [[null,null,null,null,null,null,null, configArray]]]
113
+ const request = [
114
+ notebookId,
115
+ [[null, null, null, null, null, null, null, configArray]]
116
+ ];
117
+ const response = await this.rpc.call(RPC.RPC_SET_CHAT_CONFIG, request, notebookId);
118
+ return response;
119
+ }
120
+ /**
121
+ * Chat with notebook (non-streaming - returns full response data)
122
+ * For streaming, use chatStream() method instead
123
+ *
124
+ * Returns a ChatResponseData object containing:
125
+ * - chunks: All StreamChunk objects received
126
+ * - rawData: Raw data from the last chunk (contains full response structure)
127
+ * - text: Processed text (for convenience, but examples should parse rawData)
128
+ * - conversationId, messageIds, citations: Metadata
129
+ *
130
+ * Examples should decode the rawData to extract the full response.
131
+ *
132
+ * Note: For continuing conversations, extract messageIds from previous responses
133
+ * and pass them via the conversationId parameter context. The conversationHistory
134
+ * parameter is for reference only - message IDs must be extracted from responses.
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * // Non-streaming: Get complete response
139
+ * const response = await client.generation.chat('notebook-id', 'What are the key findings?');
140
+ * console.log(response.text);
141
+ *
142
+ * // Chat with specific sources
143
+ * const response = await client.generation.chat('notebook-id', 'Summarize these sources', {
144
+ * sourceIds: ['source-id-1', 'source-id-2']
145
+ * });
146
+ * ```
147
+ */
148
+ async chat(notebookId, prompt, options) {
149
+ // Check quota before chat
150
+ this.quota?.checkQuota('chat');
151
+ // Generate conversation ID if not provided
152
+ const convId = options?.conversationId || this.generateConversationId();
153
+ // If no source IDs provided, fetch all sources from the notebook
154
+ let sourceIds = options?.sourceIds;
155
+ if (!sourceIds || sourceIds.length === 0) {
156
+ try {
157
+ // Fetch notebook data to get all sources
158
+ const projectResponse = await this.rpc.call(RPC.RPC_GET_PROJECT, [notebookId, null, [2], null, 0], notebookId);
159
+ // Parse sources from response (similar to SourcesService.parseSourcesFromResponse)
160
+ sourceIds = this.extractSourceIdsFromResponse(projectResponse);
161
+ }
162
+ catch (error) {
163
+ // If fetching sources fails, continue with empty array
164
+ sourceIds = [];
165
+ }
166
+ }
167
+ // Ensure we have at least one source (API requires sources for chat)
168
+ if (!sourceIds || sourceIds.length === 0) {
169
+ throw new NotebookLMError('No sources found in notebook. Please add at least one source before chatting.');
170
+ }
171
+ // Build context items based on reference implementation
172
+ // Format for new conversation: [[[["conversation_id"]]], "prompt", null, [2, null, [1]], "notebook_id"]
173
+ // Format for continuing conversation: [[[["conversation_id"]], [["msg_id_1"]], [["msg_id_2"]]]], "prompt", null, [2, null, [1]], "notebook_id"]
174
+ // Format for sources: [[["source_id_1"]], [["source_id_2"]]], "prompt", null, [2, null, [1]], "notebook_id"]
175
+ const contextItems = [];
176
+ if (sourceIds && sourceIds.length > 0) {
177
+ // When using sources, each source ID becomes an element: [[["source_id"]]]
178
+ for (const sourceId of sourceIds) {
179
+ contextItems.push([[sourceId]]);
180
+ }
181
+ }
182
+ else {
183
+ // For conversation, add conversation ID: [[["conversation_id"]]]
184
+ contextItems.push([[convId]]);
185
+ // Add message history (message IDs) if provided: [["msg_id_1"]], [["msg_id_2"]], ...
186
+ // Message IDs should be extracted from previous chat responses' metadata (messageIds field)
187
+ // The conversationHistory parameter contains message objects for reference, but the API
188
+ // requires message IDs. Extract messageIds from previous ChatResponseData and add to contextItems.
189
+ // Example: After first chat, use responseData.messageIds and add to contextItems in next request
190
+ }
191
+ // Build the inner request array
192
+ // Format: [contextItems, prompt, null, [2, null, [1]], notebookId]
193
+ // The third parameter is always null (not used for message content)
194
+ const innerRequest = [
195
+ contextItems,
196
+ prompt,
197
+ null, // Always null - message IDs go in contextItems, not here
198
+ [2, null, [1]],
199
+ notebookId
200
+ ];
201
+ // Build the full request: [null, JSON.stringify(innerRequest)]
202
+ const request = [null, JSON.stringify(innerRequest)];
203
+ try {
204
+ // For non-streaming, collect all chunks and raw data
205
+ const chunks = [];
206
+ let conversationId;
207
+ let messageIds;
208
+ const citations = new Set();
209
+ let lastRawData = undefined;
210
+ // Use streaming client to get all chunks
211
+ if (!this.streamingClient) {
212
+ throw new NotebookLMError('Streaming client not initialized');
213
+ }
214
+ const streamOptions = {
215
+ onChunk: (chunk) => {
216
+ chunks.push(chunk);
217
+ // Track metadata from first chunk
218
+ if (chunk.metadata && !conversationId) {
219
+ conversationId = chunk.metadata[0];
220
+ messageIds = chunk.metadata.slice(0, 2);
221
+ }
222
+ // Collect citations
223
+ if (chunk.citations) {
224
+ chunk.citations.forEach(citation => citations.add(citation));
225
+ }
226
+ // Keep track of last rawData (contains full response structure)
227
+ if (chunk.rawData) {
228
+ lastRawData = chunk.rawData;
229
+ }
230
+ },
231
+ showThinking: false,
232
+ };
233
+ // Stream all chunks
234
+ let chunkReceived = false;
235
+ for await (const chunk of this.streamingClient.streamChat(notebookId, prompt, sourceIds, convId, null, // Always null - message IDs go in contextItems
236
+ streamOptions)) {
237
+ chunkReceived = true;
238
+ // Chunks are already processed in onChunk callback
239
+ }
240
+ // Record usage after successful chat
241
+ this.quota?.recordUsage('chat');
242
+ // Extract text from chunks - prioritize rawData (most complete), then longest chunk text
243
+ // CRITICAL: rawData contains the full response structure and is most reliable
244
+ let processedText = '';
245
+ // Method 1: Try rawData first (most reliable - contains complete response structure)
246
+ if (lastRawData) {
247
+ try {
248
+ if (Array.isArray(lastRawData) && lastRawData.length > 0) {
249
+ const firstElement = lastRawData[0];
250
+ if (Array.isArray(firstElement) && firstElement.length > 0) {
251
+ const rawText = firstElement[0];
252
+ if (typeof rawText === 'string' && rawText.length > 0) {
253
+ processedText = rawText.replace(/\*\*[^*]+\*\*\n\n/g, '');
254
+ }
255
+ }
256
+ else if (typeof firstElement === 'string' && firstElement.length > 0) {
257
+ processedText = firstElement.replace(/\*\*[^*]+\*\*\n\n/g, '');
258
+ }
259
+ }
260
+ }
261
+ catch (error) {
262
+ // Ignore errors in rawData extraction, fall back to chunk text
263
+ }
264
+ }
265
+ // Method 2: Fallback to longest chunk text if rawData extraction failed or is shorter
266
+ if (chunks.length > 0) {
267
+ // Find the chunk with the longest text (should be the last one, but be safe)
268
+ let longestChunk = chunks[0];
269
+ for (const chunk of chunks) {
270
+ if (chunk.text && chunk.text.length > (longestChunk.text?.length || 0)) {
271
+ longestChunk = chunk;
272
+ }
273
+ }
274
+ // Use the longest chunk's full text if it's longer than rawData text
275
+ const longestChunkText = longestChunk.text
276
+ ? longestChunk.text.replace(/\*\*[^*]+\*\*\n\n/g, '')
277
+ : (longestChunk.response || '');
278
+ // Use chunk text if it's longer (might have more complete data)
279
+ if (longestChunkText.length > processedText.length) {
280
+ processedText = longestChunkText;
281
+ }
282
+ }
283
+ // Return full response data for examples to decode
284
+ return {
285
+ chunks,
286
+ rawData: lastRawData,
287
+ text: processedText,
288
+ conversationId,
289
+ messageIds,
290
+ citations: Array.from(citations),
291
+ };
292
+ }
293
+ catch (error) {
294
+ throw error;
295
+ }
296
+ }
297
+ /**
298
+ * Stream chat with notebook (returns async generator for streaming chunks)
299
+ *
300
+ * @param notebookId - The notebook ID
301
+ * @param prompt - The chat prompt/question
302
+ * @param options - Optional chat options
303
+ * @param options.sourceIds - Optional specific source IDs to query (if not provided, uses all sources)
304
+ * @param options.conversationHistory - Optional conversation history array for reference (message IDs should be extracted from previous responses)
305
+ * @param options.conversationId - Optional conversation ID for continuing a conversation (auto-generated if not provided)
306
+ * @param options.onChunk - Optional callback for each chunk
307
+ * @param options.showThinking - Whether to include thinking process in output
308
+ *
309
+ * Note: For continuing conversations, extract messageIds from previous responses' metadata
310
+ * and pass them via the conversationId context. The conversationHistory parameter is for
311
+ * reference only - the API requires message IDs in contextItems, not message objects.
312
+ *
313
+ * @example
314
+ * ```typescript
315
+ * // Stream chat response
316
+ * for await (const chunk of client.generation.chatStream('notebook-id', 'What is this about?')) {
317
+ * if (chunk.response) {
318
+ * process.stdout.write(chunk.response);
319
+ * }
320
+ * }
321
+ *
322
+ * // With callback
323
+ * await client.generation.chatStream('notebook-id', 'Explain this', {
324
+ * onChunk: (chunk) => {
325
+ * console.log('Chunk:', chunk.text);
326
+ * }
327
+ * });
328
+ * ```
329
+ */
330
+ async *chatStream(notebookId, prompt, options) {
331
+ // Check quota before chat
332
+ this.quota?.checkQuota('chat');
333
+ // Generate conversation ID if not provided
334
+ const convId = options?.conversationId || this.generateConversationId();
335
+ // If no source IDs provided, fetch all sources from the notebook
336
+ let sourceIds = options?.sourceIds;
337
+ if (!sourceIds || sourceIds.length === 0) {
338
+ try {
339
+ // Fetch notebook data to get all sources
340
+ const projectResponse = await this.rpc.call(RPC.RPC_GET_PROJECT, [notebookId, null, [2], null, 0], notebookId);
341
+ // Parse sources from response
342
+ sourceIds = this.extractSourceIdsFromResponse(projectResponse);
343
+ }
344
+ catch (error) {
345
+ console.error('\n❌ Failed to fetch sources from notebook:', error);
346
+ sourceIds = [];
347
+ }
348
+ }
349
+ // Ensure we have at least one source
350
+ if (!sourceIds || sourceIds.length === 0) {
351
+ throw new NotebookLMError('No sources found in notebook. Please add at least one source before chatting.');
352
+ }
353
+ // Build context items based on reference implementation
354
+ const contextItems = [];
355
+ if (sourceIds && sourceIds.length > 0) {
356
+ // When using sources, each source ID becomes an element: [[["source_id"]]]
357
+ for (const sourceId of sourceIds) {
358
+ contextItems.push([[sourceId]]);
359
+ }
360
+ }
361
+ else {
362
+ // For conversation, add conversation ID: [[["conversation_id"]]]
363
+ contextItems.push([[convId]]);
364
+ // Add message history (message IDs) if available
365
+ // Message IDs should be extracted from previous chat responses' metadata
366
+ // The conversationHistory parameter contains message objects, but we need message IDs
367
+ // For proper message ID tracking, users should extract messageIds from previous responses
368
+ // and pass them explicitly (this is a limitation of the current API design)
369
+ }
370
+ // Stream using streaming client
371
+ // Note: The third parameter in the request body is always null
372
+ // Message IDs go in contextItems, not as a separate parameter
373
+ if (!this.streamingClient) {
374
+ throw new NotebookLMError('Streaming client not initialized');
375
+ }
376
+ const streamOptions = {
377
+ onChunk: options?.onChunk,
378
+ showThinking: options?.showThinking,
379
+ };
380
+ for await (const chunk of this.streamingClient.streamChat(notebookId, prompt, sourceIds, convId, null, // Always null - message IDs go in contextItems
381
+ streamOptions)) {
382
+ yield chunk;
383
+ }
384
+ // Record usage after streaming completes
385
+ this.quota?.recordUsage('chat');
386
+ }
387
+ /**
388
+ * Generate a conversation ID (UUID v4)
389
+ */
390
+ generateConversationId() {
391
+ // Generate a UUID v4
392
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
393
+ const r = Math.random() * 16 | 0;
394
+ const v = c === 'x' ? r : (r & 0x3 | 0x8);
395
+ return v.toString(16);
396
+ });
397
+ }
398
+ /**
399
+ * Extract source IDs from notebook response
400
+ * Uses the same logic as SourcesService.parseSourcesFromResponse
401
+ */
402
+ extractSourceIdsFromResponse(response) {
403
+ try {
404
+ let parsedResponse = response;
405
+ if (typeof response === 'string') {
406
+ parsedResponse = JSON.parse(response);
407
+ }
408
+ if (!Array.isArray(parsedResponse) || parsedResponse.length === 0) {
409
+ return [];
410
+ }
411
+ let data = parsedResponse;
412
+ // Handle nested array structure - same as SourcesService
413
+ if (Array.isArray(parsedResponse[0])) {
414
+ data = parsedResponse[0];
415
+ }
416
+ // Sources are in data[1] - same as SourcesService
417
+ if (!Array.isArray(data[1])) {
418
+ return [];
419
+ }
420
+ const sourceIds = [];
421
+ for (const sourceData of data[1]) {
422
+ if (!Array.isArray(sourceData) || sourceData.length === 0) {
423
+ continue;
424
+ }
425
+ // Extract source ID from [0][0] - same as SourcesService
426
+ let sourceId;
427
+ if (Array.isArray(sourceData[0]) && sourceData[0].length > 0) {
428
+ sourceId = sourceData[0][0];
429
+ }
430
+ else if (typeof sourceData[0] === 'string') {
431
+ sourceId = sourceData[0];
432
+ }
433
+ if (sourceId && typeof sourceId === 'string') {
434
+ sourceIds.push(sourceId);
435
+ }
436
+ }
437
+ return sourceIds;
438
+ }
439
+ catch (error) {
440
+ // Return empty array if parsing fails
441
+ return [];
442
+ }
443
+ }
444
+ // ========================================================================
445
+ // Response parsers
446
+ // ========================================================================
447
+ parseChatResponse(response) {
448
+ try {
449
+ // Response format varies - extract text content
450
+ if (typeof response === 'string') {
451
+ return response;
452
+ }
453
+ if (Array.isArray(response) && response.length > 0) {
454
+ // Try to find text content in array
455
+ const findText = (data) => {
456
+ if (typeof data === 'string' && data.length > 10) {
457
+ return data;
458
+ }
459
+ if (Array.isArray(data)) {
460
+ for (const item of data) {
461
+ const text = findText(item);
462
+ if (text)
463
+ return text;
464
+ }
465
+ }
466
+ return null;
467
+ };
468
+ const text = findText(response);
469
+ if (text)
470
+ return text;
471
+ }
472
+ return '';
473
+ }
474
+ catch (error) {
475
+ throw new NotebookLMError(`Failed to parse chat response: ${error.message}`);
476
+ }
477
+ }
478
+ }
479
+ //# sourceMappingURL=generation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generation.js","sourceRoot":"","sources":["../../../src/services/generation.ts"],"names":[],"mappings":"A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AAO,IAAI,CAAC;oBACd,CAAC;oBACD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;wBACxB,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;4BACxB,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;4BAC5B,IAAI,IAAI;gCAAE,OAAO,IAAI,CAAC;wBACxB,CAAC;oBACH,CAAC;oBACD,OAAO,IAAI,CAAC;gBACd,CAAC,CAAC;gBAEF,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;gBAChC,IAAI,IAAI;oBAAE,OAAO,IAAI,CAAC;YACxB,CAAC;YAED,OAAO,EAAE,CAAC;QACZ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,eAAe,CAAC,kCAAmC,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;QAC1F,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Notebook Language Service
3
+ * Handles getting and setting the notebook's default output language
4
+ *
5
+ * The notebook's default output language is used as the default for:
6
+ * - Artifact creation (audio, video, report, infographics, slide decks)
7
+ * - Chat responses
8
+ * - All other notebook operations
9
+ *
10
+ * If a specific language is provided in artifact creation, it overrides the default.
11
+ */
12
+ import { RPCClient } from '../rpc/rpc-client.js';
13
+ export interface NotebookLanguageInfo {
14
+ /** Current default output language code (e.g., 'en', 'de', 'ja') */
15
+ language: string;
16
+ /** Language display name */
17
+ name?: string;
18
+ /** Native language name */
19
+ nativeName?: string;
20
+ }
21
+ /**
22
+ * Service for managing notebook output language
23
+ */
24
+ export declare class NotebookLanguageService {
25
+ private rpc;
26
+ private languageCache;
27
+ constructor(rpc: RPCClient);
28
+ /**
29
+ * Get the default output language for a notebook
30
+ *
31
+ * **What it does:** Retrieves the notebook's default output language setting.
32
+ * This language is used as the default for all artifact creation, chat responses,
33
+ * and other notebook operations unless overridden.
34
+ *
35
+ * **Input:**
36
+ * - `notebookId` (string, required): The ID of the notebook
37
+ *
38
+ * **Output:** Returns the language code (e.g., 'en', 'de', 'ja')
39
+ *
40
+ * **Note:**
41
+ * - Returns cached language if available (set via `set()` method)
42
+ * - If not cached, defaults to 'en' (English)
43
+ * - The language is cached when set via `set()` method
44
+ *
45
+ * @param notebookId - The notebook ID
46
+ * @returns The default language code
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const language = await sdk.notebookLanguage.get('notebook-id');
51
+ * console.log(`Default language: ${language}`); // 'en', 'de', 'ja', etc.
52
+ * ```
53
+ */
54
+ get(notebookId: string): Promise<string>;
55
+ /**
56
+ * Set the default output language for a notebook
57
+ *
58
+ * **What it does:** Sets the notebook's default output language.
59
+ * This language will be used as the default for all artifact creation,
60
+ * chat responses, and other notebook operations.
61
+ *
62
+ * **Input:**
63
+ * - `notebookId` (string, required): The ID of the notebook
64
+ * - `language` (string, required): Language code (e.g., 'en', 'de', 'ja')
65
+ * - Use `NotebookLMLanguage` enum for type safety
66
+ * - Supports 80+ languages
67
+ *
68
+ * **Output:** Returns the updated language code
69
+ *
70
+ * **Note:**
71
+ * - The language setting is persistent and affects all future operations
72
+ * - Cache is updated after successful setting
73
+ * - Uses RPC `hT54vc` (MutateAccount) to update the language
74
+ *
75
+ * @param notebookId - The notebook ID
76
+ * @param language - Language code to set
77
+ * @returns The updated language code
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * import { NotebookLMLanguage } from 'notebooklm-kit';
82
+ *
83
+ * // Set to German
84
+ * await sdk.notebookLanguage.set('notebook-id', NotebookLMLanguage.GERMAN);
85
+ *
86
+ * // Set to Japanese
87
+ * await sdk.notebookLanguage.set('notebook-id', NotebookLMLanguage.JAPANESE);
88
+ *
89
+ * // Set using language code directly
90
+ * await sdk.notebookLanguage.set('notebook-id', 'de');
91
+ * ```
92
+ */
93
+ set(notebookId: string, language: string): Promise<string>;
94
+ /**
95
+ * Clear the language cache for a notebook
96
+ * Useful if you want to force a fresh fetch
97
+ *
98
+ * @param notebookId - The notebook ID (optional, clears all if not provided)
99
+ */
100
+ clearCache(notebookId?: string): void;
101
+ /**
102
+ * Get language information with metadata
103
+ *
104
+ * @param notebookId - The notebook ID
105
+ * @returns Language information object
106
+ */
107
+ getInfo(notebookId: string): Promise<NotebookLanguageInfo>;
108
+ }
109
+ //# sourceMappingURL=notebook-language.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notebook-language.d.ts","sourceRoot":"","sources":["../../../src/services/notebook-language.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAKjD,MAAM,WAAW,oBAAoB;IACnC,oEAAoE;IACpE,QAAQ,EAAE,MAAM,CAAC;IAEjB,4BAA4B;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,2BAA2B;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,qBAAa,uBAAuB;IAKhC,OAAO,CAAC,GAAG;IAHb,OAAO,CAAC,aAAa,CAAkC;gBAG7C,GAAG,EAAE,SAAS;IAGxB;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACG,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAa9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACG,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAwFhE;;;;;OAKG;IACH,UAAU,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI;IAQrC;;;;;OAKG;IACG,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;CAajE"}