notebooklm-sdk 0.3.0 → 0.3.2
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.
- package/dist/index.cjs +138 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -1
- package/dist/index.d.ts +45 -1
- package/dist/index.js +139 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -21,7 +21,10 @@ __export(enums_exports, {
|
|
|
21
21
|
ArtifactTypeCode: () => exports.ArtifactTypeCode,
|
|
22
22
|
AudioFormat: () => exports.AudioFormat,
|
|
23
23
|
AudioLength: () => exports.AudioLength,
|
|
24
|
+
ChatGoal: () => exports.ChatGoal,
|
|
24
25
|
ChatMode: () => exports.ChatMode,
|
|
26
|
+
ChatResponseLength: () => exports.ChatResponseLength,
|
|
27
|
+
DriveMimeType: () => exports.DriveMimeType,
|
|
25
28
|
ExportType: () => exports.ExportType,
|
|
26
29
|
InfographicDetail: () => exports.InfographicDetail,
|
|
27
30
|
InfographicOrientation: () => exports.InfographicOrientation,
|
|
@@ -64,7 +67,7 @@ function sourceStatusFromCode(code) {
|
|
|
64
67
|
function chatModeToParams(mode) {
|
|
65
68
|
return CHAT_MODE_PARAMS[mode];
|
|
66
69
|
}
|
|
67
|
-
exports.RPCMethod = void 0; exports.ArtifactTypeCode = void 0; var ArtifactStatusCode, SourceStatusCode; exports.AudioFormat = void 0; exports.AudioLength = void 0; exports.VideoFormat = void 0; exports.VideoStyle = void 0; exports.QuizQuantity = void 0; exports.QuizDifficulty = void 0; exports.InfographicOrientation = void 0; exports.InfographicDetail = void 0; exports.InfographicStyle = void 0; exports.SlideDeckFormat = void 0; exports.SlideDeckLength = void 0; exports.ExportType = void 0; var SOURCE_TYPE_MAP, ARTIFACT_TYPE_MAP, ARTIFACT_STATUS_MAP, SOURCE_STATUS_MAP; exports.ChatMode = void 0; var CHAT_MODE_PARAMS; exports.ShareAccess = void 0; exports.ShareViewLevel = void 0; exports.SharePermission = void 0;
|
|
70
|
+
exports.RPCMethod = void 0; exports.ArtifactTypeCode = void 0; var ArtifactStatusCode, SourceStatusCode; exports.AudioFormat = void 0; exports.AudioLength = void 0; exports.VideoFormat = void 0; exports.VideoStyle = void 0; exports.QuizQuantity = void 0; exports.QuizDifficulty = void 0; exports.InfographicOrientation = void 0; exports.InfographicDetail = void 0; exports.InfographicStyle = void 0; exports.SlideDeckFormat = void 0; exports.SlideDeckLength = void 0; exports.ExportType = void 0; exports.DriveMimeType = void 0; var SOURCE_TYPE_MAP, ARTIFACT_TYPE_MAP, ARTIFACT_STATUS_MAP, SOURCE_STATUS_MAP; exports.ChatMode = void 0; var CHAT_MODE_PARAMS; exports.ChatGoal = void 0; exports.ChatResponseLength = void 0; exports.ShareAccess = void 0; exports.ShareViewLevel = void 0; exports.SharePermission = void 0;
|
|
68
71
|
var init_enums = __esm({
|
|
69
72
|
"src/types/enums.ts"() {
|
|
70
73
|
exports.RPCMethod = {
|
|
@@ -213,6 +216,12 @@ var init_enums = __esm({
|
|
|
213
216
|
DOCS: 1,
|
|
214
217
|
SHEETS: 2
|
|
215
218
|
};
|
|
219
|
+
exports.DriveMimeType = {
|
|
220
|
+
GOOGLE_DOC: "application/vnd.google-apps.document",
|
|
221
|
+
GOOGLE_SLIDES: "application/vnd.google-apps.presentation",
|
|
222
|
+
GOOGLE_SHEETS: "application/vnd.google-apps.spreadsheet",
|
|
223
|
+
PDF: "application/pdf"
|
|
224
|
+
};
|
|
216
225
|
SOURCE_TYPE_MAP = {
|
|
217
226
|
1: "google_docs",
|
|
218
227
|
2: "google_slides",
|
|
@@ -264,6 +273,22 @@ var init_enums = __esm({
|
|
|
264
273
|
concise: [1, 5],
|
|
265
274
|
detailed: [1, 4]
|
|
266
275
|
};
|
|
276
|
+
exports.ChatGoal = {
|
|
277
|
+
/** General purpose research and brainstorming. */
|
|
278
|
+
DEFAULT: 1,
|
|
279
|
+
/** Custom instructions (up to 10,000 characters). */
|
|
280
|
+
CUSTOM: 2,
|
|
281
|
+
/** Educational focus with learning-oriented responses. */
|
|
282
|
+
LEARNING_GUIDE: 3
|
|
283
|
+
};
|
|
284
|
+
exports.ChatResponseLength = {
|
|
285
|
+
/** Standard response length. */
|
|
286
|
+
DEFAULT: 1,
|
|
287
|
+
/** Verbose, detailed responses. */
|
|
288
|
+
LONGER: 4,
|
|
289
|
+
/** Concise, brief responses. */
|
|
290
|
+
SHORTER: 5
|
|
291
|
+
};
|
|
267
292
|
exports.ShareAccess = {
|
|
268
293
|
/** Only explicitly shared users can access */
|
|
269
294
|
RESTRICTED: 0,
|
|
@@ -786,6 +811,30 @@ var ArtifactsAPI = class {
|
|
|
786
811
|
const artifacts = await this.list(notebookId);
|
|
787
812
|
return artifacts.find((a) => a.id === artifactId) ?? null;
|
|
788
813
|
}
|
|
814
|
+
async listAudio(notebookId) {
|
|
815
|
+
return (await this.list(notebookId)).filter((a) => a.kind === "audio");
|
|
816
|
+
}
|
|
817
|
+
async listVideo(notebookId) {
|
|
818
|
+
return (await this.list(notebookId)).filter((a) => a.kind === "video");
|
|
819
|
+
}
|
|
820
|
+
async listReports(notebookId) {
|
|
821
|
+
return (await this.list(notebookId)).filter((a) => a.kind === "report");
|
|
822
|
+
}
|
|
823
|
+
async listQuizzes(notebookId) {
|
|
824
|
+
return (await this.list(notebookId)).filter((a) => a.kind === "quiz");
|
|
825
|
+
}
|
|
826
|
+
async listFlashcards(notebookId) {
|
|
827
|
+
return (await this.list(notebookId)).filter((a) => a.kind === "flashcards");
|
|
828
|
+
}
|
|
829
|
+
async listInfographics(notebookId) {
|
|
830
|
+
return (await this.list(notebookId)).filter((a) => a.kind === "infographic");
|
|
831
|
+
}
|
|
832
|
+
async listSlideDecks(notebookId) {
|
|
833
|
+
return (await this.list(notebookId)).filter((a) => a.kind === "slide_deck");
|
|
834
|
+
}
|
|
835
|
+
async listDataTables(notebookId) {
|
|
836
|
+
return (await this.list(notebookId)).filter((a) => a.kind === "data_table");
|
|
837
|
+
}
|
|
789
838
|
async delete(notebookId, artifactId) {
|
|
790
839
|
const params = [[2], notebookId, artifactId];
|
|
791
840
|
await this.rpc.call(exports.RPCMethod.DELETE_ARTIFACT, params, {
|
|
@@ -1198,6 +1247,24 @@ ${opts.extraInstructions}` : cfg.prompt;
|
|
|
1198
1247
|
}
|
|
1199
1248
|
// ---------------------------------------------------------------------------
|
|
1200
1249
|
// Internal
|
|
1250
|
+
/** Export a completed report artifact to Google Docs. Returns the created document URL. */
|
|
1251
|
+
async exportReport(notebookId, artifactId, title) {
|
|
1252
|
+
const params = [null, artifactId, null, title, exports.ExportType.DOCS];
|
|
1253
|
+
const result = await this.rpc.call(exports.RPCMethod.EXPORT_ARTIFACT, params, {
|
|
1254
|
+
sourcePath: `/notebook/${notebookId}`,
|
|
1255
|
+
allowNull: true
|
|
1256
|
+
});
|
|
1257
|
+
return extractExportUrl(result);
|
|
1258
|
+
}
|
|
1259
|
+
/** Export a completed data table artifact to Google Sheets. Returns the created spreadsheet URL. */
|
|
1260
|
+
async exportDataTable(notebookId, artifactId, title) {
|
|
1261
|
+
const params = [null, artifactId, null, title, exports.ExportType.SHEETS];
|
|
1262
|
+
const result = await this.rpc.call(exports.RPCMethod.EXPORT_ARTIFACT, params, {
|
|
1263
|
+
sourcePath: `/notebook/${notebookId}`,
|
|
1264
|
+
allowNull: true
|
|
1265
|
+
});
|
|
1266
|
+
return extractExportUrl(result);
|
|
1267
|
+
}
|
|
1201
1268
|
// ---------------------------------------------------------------------------
|
|
1202
1269
|
/**
|
|
1203
1270
|
* Fetch a Google-hosted media URL, manually following redirects to ensure
|
|
@@ -1280,6 +1347,21 @@ function parseDataTable(rawData) {
|
|
|
1280
1347
|
throw new Error(`Failed to parse data table: ${e}`);
|
|
1281
1348
|
}
|
|
1282
1349
|
}
|
|
1350
|
+
function extractExportUrl(result) {
|
|
1351
|
+
if (!Array.isArray(result)) return null;
|
|
1352
|
+
function findUrl(data, depth = 5) {
|
|
1353
|
+
if (depth <= 0 || data == null) return null;
|
|
1354
|
+
if (typeof data === "string" && data.startsWith("https://")) return data;
|
|
1355
|
+
if (Array.isArray(data)) {
|
|
1356
|
+
for (const item of data) {
|
|
1357
|
+
const found = findUrl(item, depth - 1);
|
|
1358
|
+
if (found) return found;
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
return null;
|
|
1362
|
+
}
|
|
1363
|
+
return findUrl(result);
|
|
1364
|
+
}
|
|
1283
1365
|
function sleep(ms) {
|
|
1284
1366
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1285
1367
|
}
|
|
@@ -1410,6 +1492,23 @@ var ChatAPI = class {
|
|
|
1410
1492
|
}
|
|
1411
1493
|
return null;
|
|
1412
1494
|
}
|
|
1495
|
+
/**
|
|
1496
|
+
* Low-level chat configuration. Set goal, response length, and optional
|
|
1497
|
+
* custom instructions directly. Persists on the server per notebook.
|
|
1498
|
+
* Use `setMode()` for preset combinations instead.
|
|
1499
|
+
*/
|
|
1500
|
+
async configure(notebookId, goal, length, customPrompt) {
|
|
1501
|
+
if (goal === exports.ChatGoal.CUSTOM && !customPrompt) {
|
|
1502
|
+
throw new Error("customPrompt is required when goal is ChatGoal.CUSTOM");
|
|
1503
|
+
}
|
|
1504
|
+
const goalArray = goal === exports.ChatGoal.CUSTOM ? [goal, customPrompt] : [goal];
|
|
1505
|
+
const chatSettings = [goalArray, [length]];
|
|
1506
|
+
const params = [notebookId, [[null, null, null, null, null, null, null, chatSettings]]];
|
|
1507
|
+
await this.rpc.call(exports.RPCMethod.RENAME_NOTEBOOK, params, {
|
|
1508
|
+
sourcePath: `/notebook/${notebookId}`,
|
|
1509
|
+
allowNull: true
|
|
1510
|
+
});
|
|
1511
|
+
}
|
|
1413
1512
|
/**
|
|
1414
1513
|
* Set the chat mode for a notebook. Persists on the server — affects all
|
|
1415
1514
|
* subsequent `ask()` calls until changed.
|
|
@@ -2121,6 +2220,44 @@ var SourcesAPI = class {
|
|
|
2121
2220
|
_typeCode: null
|
|
2122
2221
|
};
|
|
2123
2222
|
}
|
|
2223
|
+
async addDrive(notebookId, fileId, title, mimeType = exports.DriveMimeType.GOOGLE_DOC, opts = {}) {
|
|
2224
|
+
const sourceData = [
|
|
2225
|
+
[fileId, mimeType, 1, title],
|
|
2226
|
+
null,
|
|
2227
|
+
null,
|
|
2228
|
+
null,
|
|
2229
|
+
null,
|
|
2230
|
+
null,
|
|
2231
|
+
null,
|
|
2232
|
+
null,
|
|
2233
|
+
null,
|
|
2234
|
+
null,
|
|
2235
|
+
1
|
|
2236
|
+
];
|
|
2237
|
+
const params = [
|
|
2238
|
+
[sourceData],
|
|
2239
|
+
notebookId,
|
|
2240
|
+
[2],
|
|
2241
|
+
[1, null, null, null, null, null, null, null, null, null, [1]]
|
|
2242
|
+
];
|
|
2243
|
+
const result = await this.rpc.call(exports.RPCMethod.ADD_SOURCE, params, {
|
|
2244
|
+
sourcePath: `/notebook/${notebookId}`,
|
|
2245
|
+
allowNull: true
|
|
2246
|
+
});
|
|
2247
|
+
const sourceId = extractSourceId(result);
|
|
2248
|
+
if (opts.waitUntilReady) {
|
|
2249
|
+
return this.waitUntilReady(notebookId, sourceId, opts.waitTimeout);
|
|
2250
|
+
}
|
|
2251
|
+
return {
|
|
2252
|
+
id: sourceId,
|
|
2253
|
+
title,
|
|
2254
|
+
url: null,
|
|
2255
|
+
kind: "unknown",
|
|
2256
|
+
createdAt: null,
|
|
2257
|
+
status: "processing",
|
|
2258
|
+
_typeCode: null
|
|
2259
|
+
};
|
|
2260
|
+
}
|
|
2124
2261
|
async addFile(notebookId, filePath, mimeType, opts = {}) {
|
|
2125
2262
|
const fileData = fs.readFileSync(filePath);
|
|
2126
2263
|
const fileName = filePath.split("/").pop() ?? "file";
|