langchain 0.2.19 → 0.3.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.
- package/README.md +9 -9
- package/dist/agents/chat/index.cjs +1 -1
- package/dist/agents/chat/index.d.ts +1 -1
- package/dist/agents/chat/index.js +1 -1
- package/dist/agents/chat_convo/index.cjs +1 -1
- package/dist/agents/chat_convo/index.d.ts +1 -1
- package/dist/agents/chat_convo/index.js +1 -1
- package/dist/agents/mrkl/index.cjs +1 -1
- package/dist/agents/mrkl/index.d.ts +1 -1
- package/dist/agents/mrkl/index.js +1 -1
- package/dist/agents/openai_functions/index.cjs +3 -3
- package/dist/agents/openai_functions/index.d.ts +1 -1
- package/dist/agents/openai_functions/index.js +3 -3
- package/dist/agents/structured_chat/index.cjs +1 -1
- package/dist/agents/structured_chat/index.d.ts +1 -1
- package/dist/agents/structured_chat/index.js +1 -1
- package/dist/agents/xml/index.cjs +1 -1
- package/dist/agents/xml/index.d.ts +1 -1
- package/dist/agents/xml/index.js +1 -1
- package/dist/chains/combine_documents/stuff.cjs +2 -2
- package/dist/chains/combine_documents/stuff.js +2 -2
- package/dist/chains/load.cjs +1 -1
- package/dist/chains/load.d.ts +1 -1
- package/dist/chains/load.js +1 -1
- package/dist/chains/openai_functions/structured_output.cjs +2 -2
- package/dist/chains/openai_functions/structured_output.d.ts +2 -2
- package/dist/chains/openai_functions/structured_output.js +2 -2
- package/dist/chains/serde.d.ts +12 -12
- package/dist/experimental/plan_and_execute/agent_executor.cjs +1 -1
- package/dist/experimental/plan_and_execute/agent_executor.js +1 -1
- package/dist/load/import_constants.cjs +2 -39
- package/dist/load/import_constants.js +2 -39
- package/dist/load/import_map.cjs +2 -3
- package/dist/load/import_map.d.ts +0 -1
- package/dist/load/import_map.js +0 -1
- package/dist/output_parsers/openai_tools.cjs +2 -4
- package/dist/output_parsers/openai_tools.d.ts +8 -3
- package/dist/output_parsers/openai_tools.js +2 -4
- package/dist/retrievers/multi_query.d.ts +1 -0
- package/dist/smith/config.d.ts +1 -5
- package/package.json +31 -854
- package/dist/document_loaders/fs/chatgpt.cjs +0 -90
- package/dist/document_loaders/fs/chatgpt.d.ts +0 -8
- package/dist/document_loaders/fs/chatgpt.js +0 -86
- package/dist/document_loaders/fs/csv.cjs +0 -73
- package/dist/document_loaders/fs/csv.d.ts +0 -65
- package/dist/document_loaders/fs/csv.js +0 -69
- package/dist/document_loaders/fs/docx.cjs +0 -58
- package/dist/document_loaders/fs/docx.d.ts +0 -25
- package/dist/document_loaders/fs/docx.js +0 -54
- package/dist/document_loaders/fs/epub.cjs +0 -103
- package/dist/document_loaders/fs/epub.d.ts +0 -33
- package/dist/document_loaders/fs/epub.js +0 -99
- package/dist/document_loaders/fs/notion.cjs +0 -26
- package/dist/document_loaders/fs/notion.d.ts +0 -12
- package/dist/document_loaders/fs/notion.js +0 -22
- package/dist/document_loaders/fs/obsidian.cjs +0 -247
- package/dist/document_loaders/fs/obsidian.d.ts +0 -28
- package/dist/document_loaders/fs/obsidian.js +0 -240
- package/dist/document_loaders/fs/openai_whisper_audio.cjs +0 -49
- package/dist/document_loaders/fs/openai_whisper_audio.d.ts +0 -23
- package/dist/document_loaders/fs/openai_whisper_audio.js +0 -45
- package/dist/document_loaders/fs/pdf.cjs +0 -148
- package/dist/document_loaders/fs/pdf.d.ts +0 -49
- package/dist/document_loaders/fs/pdf.js +0 -144
- package/dist/document_loaders/fs/pptx.cjs +0 -46
- package/dist/document_loaders/fs/pptx.d.ts +0 -25
- package/dist/document_loaders/fs/pptx.js +0 -42
- package/dist/document_loaders/fs/srt.cjs +0 -57
- package/dist/document_loaders/fs/srt.d.ts +0 -32
- package/dist/document_loaders/fs/srt.js +0 -50
- package/dist/document_loaders/fs/unstructured.cjs +0 -338
- package/dist/document_loaders/fs/unstructured.d.ts +0 -125
- package/dist/document_loaders/fs/unstructured.js +0 -333
- package/dist/document_loaders/web/apify_dataset.cjs +0 -130
- package/dist/document_loaders/web/apify_dataset.d.ts +0 -85
- package/dist/document_loaders/web/apify_dataset.js +0 -126
- package/dist/document_loaders/web/assemblyai.cjs +0 -200
- package/dist/document_loaders/web/assemblyai.d.ts +0 -95
- package/dist/document_loaders/web/assemblyai.js +0 -193
- package/dist/document_loaders/web/azure_blob_storage_container.cjs +0 -73
- package/dist/document_loaders/web/azure_blob_storage_container.d.ts +0 -46
- package/dist/document_loaders/web/azure_blob_storage_container.js +0 -69
- package/dist/document_loaders/web/azure_blob_storage_file.cjs +0 -124
- package/dist/document_loaders/web/azure_blob_storage_file.d.ts +0 -53
- package/dist/document_loaders/web/azure_blob_storage_file.js +0 -97
- package/dist/document_loaders/web/browserbase.cjs +0 -93
- package/dist/document_loaders/web/browserbase.d.ts +0 -48
- package/dist/document_loaders/web/browserbase.js +0 -86
- package/dist/document_loaders/web/cheerio.cjs +0 -118
- package/dist/document_loaders/web/cheerio.d.ts +0 -77
- package/dist/document_loaders/web/cheerio.js +0 -114
- package/dist/document_loaders/web/college_confidential.cjs +0 -41
- package/dist/document_loaders/web/college_confidential.d.ts +0 -25
- package/dist/document_loaders/web/college_confidential.js +0 -37
- package/dist/document_loaders/web/confluence.cjs +0 -190
- package/dist/document_loaders/web/confluence.d.ts +0 -114
- package/dist/document_loaders/web/confluence.js +0 -186
- package/dist/document_loaders/web/couchbase.cjs +0 -95
- package/dist/document_loaders/web/couchbase.d.ts +0 -32
- package/dist/document_loaders/web/couchbase.js +0 -91
- package/dist/document_loaders/web/figma.cjs +0 -102
- package/dist/document_loaders/web/figma.d.ts +0 -82
- package/dist/document_loaders/web/figma.js +0 -98
- package/dist/document_loaders/web/firecrawl.cjs +0 -95
- package/dist/document_loaders/web/firecrawl.d.ts +0 -50
- package/dist/document_loaders/web/firecrawl.js +0 -88
- package/dist/document_loaders/web/gitbook.cjs +0 -110
- package/dist/document_loaders/web/gitbook.d.ts +0 -55
- package/dist/document_loaders/web/gitbook.js +0 -106
- package/dist/document_loaders/web/github.cjs +0 -615
- package/dist/document_loaders/web/github.d.ts +0 -203
- package/dist/document_loaders/web/github.js +0 -608
- package/dist/document_loaders/web/hn.cjs +0 -90
- package/dist/document_loaders/web/hn.d.ts +0 -42
- package/dist/document_loaders/web/hn.js +0 -86
- package/dist/document_loaders/web/imsdb.cjs +0 -44
- package/dist/document_loaders/web/imsdb.d.ts +0 -23
- package/dist/document_loaders/web/imsdb.js +0 -40
- package/dist/document_loaders/web/notionapi.cjs +0 -404
- package/dist/document_loaders/web/notionapi.d.ts +0 -133
- package/dist/document_loaders/web/notionapi.js +0 -392
- package/dist/document_loaders/web/notiondb.cjs +0 -199
- package/dist/document_loaders/web/notiondb.d.ts +0 -56
- package/dist/document_loaders/web/notiondb.js +0 -195
- package/dist/document_loaders/web/pdf.cjs +0 -140
- package/dist/document_loaders/web/pdf.d.ts +0 -35
- package/dist/document_loaders/web/pdf.js +0 -136
- package/dist/document_loaders/web/playwright.cjs +0 -89
- package/dist/document_loaders/web/playwright.d.ts +0 -58
- package/dist/document_loaders/web/playwright.js +0 -85
- package/dist/document_loaders/web/puppeteer.cjs +0 -139
- package/dist/document_loaders/web/puppeteer.d.ts +0 -82
- package/dist/document_loaders/web/puppeteer.js +0 -135
- package/dist/document_loaders/web/recursive_url.cjs +0 -198
- package/dist/document_loaders/web/recursive_url.d.ts +0 -33
- package/dist/document_loaders/web/recursive_url.js +0 -194
- package/dist/document_loaders/web/s3.cjs +0 -164
- package/dist/document_loaders/web/s3.d.ts +0 -78
- package/dist/document_loaders/web/s3.js +0 -137
- package/dist/document_loaders/web/searchapi.cjs +0 -150
- package/dist/document_loaders/web/searchapi.d.ts +0 -76
- package/dist/document_loaders/web/searchapi.js +0 -146
- package/dist/document_loaders/web/serpapi.cjs +0 -127
- package/dist/document_loaders/web/serpapi.d.ts +0 -62
- package/dist/document_loaders/web/serpapi.js +0 -123
- package/dist/document_loaders/web/sitemap.cjs +0 -118
- package/dist/document_loaders/web/sitemap.d.ts +0 -41
- package/dist/document_loaders/web/sitemap.js +0 -114
- package/dist/document_loaders/web/sonix_audio.cjs +0 -68
- package/dist/document_loaders/web/sonix_audio.d.ts +0 -36
- package/dist/document_loaders/web/sonix_audio.js +0 -64
- package/dist/document_loaders/web/sort_xyz_blockchain.cjs +0 -157
- package/dist/document_loaders/web/sort_xyz_blockchain.d.ts +0 -78
- package/dist/document_loaders/web/sort_xyz_blockchain.js +0 -153
- package/dist/document_loaders/web/youtube.cjs +0 -116
- package/dist/document_loaders/web/youtube.d.ts +0 -55
- package/dist/document_loaders/web/youtube.js +0 -112
- package/dist/experimental/tools/pyinterpreter.cjs +0 -248
- package/dist/experimental/tools/pyinterpreter.d.ts +0 -18
- package/dist/experimental/tools/pyinterpreter.js +0 -244
- package/dist/retrievers/self_query/chroma.cjs +0 -48
- package/dist/retrievers/self_query/chroma.d.ts +0 -26
- package/dist/retrievers/self_query/chroma.js +0 -44
- package/dist/retrievers/self_query/pinecone.cjs +0 -47
- package/dist/retrievers/self_query/pinecone.d.ts +0 -26
- package/dist/retrievers/self_query/pinecone.js +0 -43
- package/dist/retrievers/self_query/supabase.cjs +0 -278
- package/dist/retrievers/self_query/supabase.d.ts +0 -109
- package/dist/retrievers/self_query/supabase.js +0 -274
- package/dist/retrievers/self_query/supabase_utils.cjs +0 -264
- package/dist/retrievers/self_query/supabase_utils.d.ts +0 -101
- package/dist/retrievers/self_query/supabase_utils.js +0 -259
- package/dist/retrievers/self_query/vectara.cjs +0 -143
- package/dist/retrievers/self_query/vectara.d.ts +0 -42
- package/dist/retrievers/self_query/vectara.js +0 -139
- package/dist/retrievers/self_query/weaviate.cjs +0 -201
- package/dist/retrievers/self_query/weaviate.d.ts +0 -99
- package/dist/retrievers/self_query/weaviate.js +0 -197
- package/dist/types/assemblyai-types.cjs +0 -2
- package/dist/types/assemblyai-types.d.ts +0 -4
- package/dist/types/assemblyai-types.js +0 -1
- package/document_loaders/fs/chatgpt.cjs +0 -1
- package/document_loaders/fs/chatgpt.d.cts +0 -1
- package/document_loaders/fs/chatgpt.d.ts +0 -1
- package/document_loaders/fs/chatgpt.js +0 -1
- package/document_loaders/fs/csv.cjs +0 -1
- package/document_loaders/fs/csv.d.cts +0 -1
- package/document_loaders/fs/csv.d.ts +0 -1
- package/document_loaders/fs/csv.js +0 -1
- package/document_loaders/fs/docx.cjs +0 -1
- package/document_loaders/fs/docx.d.cts +0 -1
- package/document_loaders/fs/docx.d.ts +0 -1
- package/document_loaders/fs/docx.js +0 -1
- package/document_loaders/fs/epub.cjs +0 -1
- package/document_loaders/fs/epub.d.cts +0 -1
- package/document_loaders/fs/epub.d.ts +0 -1
- package/document_loaders/fs/epub.js +0 -1
- package/document_loaders/fs/notion.cjs +0 -1
- package/document_loaders/fs/notion.d.cts +0 -1
- package/document_loaders/fs/notion.d.ts +0 -1
- package/document_loaders/fs/notion.js +0 -1
- package/document_loaders/fs/obsidian.cjs +0 -1
- package/document_loaders/fs/obsidian.d.cts +0 -1
- package/document_loaders/fs/obsidian.d.ts +0 -1
- package/document_loaders/fs/obsidian.js +0 -1
- package/document_loaders/fs/openai_whisper_audio.cjs +0 -1
- package/document_loaders/fs/openai_whisper_audio.d.cts +0 -1
- package/document_loaders/fs/openai_whisper_audio.d.ts +0 -1
- package/document_loaders/fs/openai_whisper_audio.js +0 -1
- package/document_loaders/fs/pdf.cjs +0 -1
- package/document_loaders/fs/pdf.d.cts +0 -1
- package/document_loaders/fs/pdf.d.ts +0 -1
- package/document_loaders/fs/pdf.js +0 -1
- package/document_loaders/fs/pptx.cjs +0 -1
- package/document_loaders/fs/pptx.d.cts +0 -1
- package/document_loaders/fs/pptx.d.ts +0 -1
- package/document_loaders/fs/pptx.js +0 -1
- package/document_loaders/fs/srt.cjs +0 -1
- package/document_loaders/fs/srt.d.cts +0 -1
- package/document_loaders/fs/srt.d.ts +0 -1
- package/document_loaders/fs/srt.js +0 -1
- package/document_loaders/fs/unstructured.cjs +0 -1
- package/document_loaders/fs/unstructured.d.cts +0 -1
- package/document_loaders/fs/unstructured.d.ts +0 -1
- package/document_loaders/fs/unstructured.js +0 -1
- package/document_loaders/web/apify_dataset.cjs +0 -1
- package/document_loaders/web/apify_dataset.d.cts +0 -1
- package/document_loaders/web/apify_dataset.d.ts +0 -1
- package/document_loaders/web/apify_dataset.js +0 -1
- package/document_loaders/web/assemblyai.cjs +0 -1
- package/document_loaders/web/assemblyai.d.cts +0 -1
- package/document_loaders/web/assemblyai.d.ts +0 -1
- package/document_loaders/web/assemblyai.js +0 -1
- package/document_loaders/web/azure_blob_storage_container.cjs +0 -1
- package/document_loaders/web/azure_blob_storage_container.d.cts +0 -1
- package/document_loaders/web/azure_blob_storage_container.d.ts +0 -1
- package/document_loaders/web/azure_blob_storage_container.js +0 -1
- package/document_loaders/web/azure_blob_storage_file.cjs +0 -1
- package/document_loaders/web/azure_blob_storage_file.d.cts +0 -1
- package/document_loaders/web/azure_blob_storage_file.d.ts +0 -1
- package/document_loaders/web/azure_blob_storage_file.js +0 -1
- package/document_loaders/web/browserbase.cjs +0 -1
- package/document_loaders/web/browserbase.d.cts +0 -1
- package/document_loaders/web/browserbase.d.ts +0 -1
- package/document_loaders/web/browserbase.js +0 -1
- package/document_loaders/web/cheerio.cjs +0 -1
- package/document_loaders/web/cheerio.d.cts +0 -1
- package/document_loaders/web/cheerio.d.ts +0 -1
- package/document_loaders/web/cheerio.js +0 -1
- package/document_loaders/web/college_confidential.cjs +0 -1
- package/document_loaders/web/college_confidential.d.cts +0 -1
- package/document_loaders/web/college_confidential.d.ts +0 -1
- package/document_loaders/web/college_confidential.js +0 -1
- package/document_loaders/web/confluence.cjs +0 -1
- package/document_loaders/web/confluence.d.cts +0 -1
- package/document_loaders/web/confluence.d.ts +0 -1
- package/document_loaders/web/confluence.js +0 -1
- package/document_loaders/web/couchbase.cjs +0 -1
- package/document_loaders/web/couchbase.d.cts +0 -1
- package/document_loaders/web/couchbase.d.ts +0 -1
- package/document_loaders/web/couchbase.js +0 -1
- package/document_loaders/web/figma.cjs +0 -1
- package/document_loaders/web/figma.d.cts +0 -1
- package/document_loaders/web/figma.d.ts +0 -1
- package/document_loaders/web/figma.js +0 -1
- package/document_loaders/web/firecrawl.cjs +0 -1
- package/document_loaders/web/firecrawl.d.cts +0 -1
- package/document_loaders/web/firecrawl.d.ts +0 -1
- package/document_loaders/web/firecrawl.js +0 -1
- package/document_loaders/web/gitbook.cjs +0 -1
- package/document_loaders/web/gitbook.d.cts +0 -1
- package/document_loaders/web/gitbook.d.ts +0 -1
- package/document_loaders/web/gitbook.js +0 -1
- package/document_loaders/web/github.cjs +0 -1
- package/document_loaders/web/github.d.cts +0 -1
- package/document_loaders/web/github.d.ts +0 -1
- package/document_loaders/web/github.js +0 -1
- package/document_loaders/web/hn.cjs +0 -1
- package/document_loaders/web/hn.d.cts +0 -1
- package/document_loaders/web/hn.d.ts +0 -1
- package/document_loaders/web/hn.js +0 -1
- package/document_loaders/web/imsdb.cjs +0 -1
- package/document_loaders/web/imsdb.d.cts +0 -1
- package/document_loaders/web/imsdb.d.ts +0 -1
- package/document_loaders/web/imsdb.js +0 -1
- package/document_loaders/web/notionapi.cjs +0 -1
- package/document_loaders/web/notionapi.d.cts +0 -1
- package/document_loaders/web/notionapi.d.ts +0 -1
- package/document_loaders/web/notionapi.js +0 -1
- package/document_loaders/web/notiondb.cjs +0 -1
- package/document_loaders/web/notiondb.d.cts +0 -1
- package/document_loaders/web/notiondb.d.ts +0 -1
- package/document_loaders/web/notiondb.js +0 -1
- package/document_loaders/web/pdf.cjs +0 -1
- package/document_loaders/web/pdf.d.cts +0 -1
- package/document_loaders/web/pdf.d.ts +0 -1
- package/document_loaders/web/pdf.js +0 -1
- package/document_loaders/web/playwright.cjs +0 -1
- package/document_loaders/web/playwright.d.cts +0 -1
- package/document_loaders/web/playwright.d.ts +0 -1
- package/document_loaders/web/playwright.js +0 -1
- package/document_loaders/web/puppeteer.cjs +0 -1
- package/document_loaders/web/puppeteer.d.cts +0 -1
- package/document_loaders/web/puppeteer.d.ts +0 -1
- package/document_loaders/web/puppeteer.js +0 -1
- package/document_loaders/web/recursive_url.cjs +0 -1
- package/document_loaders/web/recursive_url.d.cts +0 -1
- package/document_loaders/web/recursive_url.d.ts +0 -1
- package/document_loaders/web/recursive_url.js +0 -1
- package/document_loaders/web/s3.cjs +0 -1
- package/document_loaders/web/s3.d.cts +0 -1
- package/document_loaders/web/s3.d.ts +0 -1
- package/document_loaders/web/s3.js +0 -1
- package/document_loaders/web/searchapi.cjs +0 -1
- package/document_loaders/web/searchapi.d.cts +0 -1
- package/document_loaders/web/searchapi.d.ts +0 -1
- package/document_loaders/web/searchapi.js +0 -1
- package/document_loaders/web/serpapi.cjs +0 -1
- package/document_loaders/web/serpapi.d.cts +0 -1
- package/document_loaders/web/serpapi.d.ts +0 -1
- package/document_loaders/web/serpapi.js +0 -1
- package/document_loaders/web/sitemap.cjs +0 -1
- package/document_loaders/web/sitemap.d.cts +0 -1
- package/document_loaders/web/sitemap.d.ts +0 -1
- package/document_loaders/web/sitemap.js +0 -1
- package/document_loaders/web/sonix_audio.cjs +0 -1
- package/document_loaders/web/sonix_audio.d.cts +0 -1
- package/document_loaders/web/sonix_audio.d.ts +0 -1
- package/document_loaders/web/sonix_audio.js +0 -1
- package/document_loaders/web/sort_xyz_blockchain.cjs +0 -1
- package/document_loaders/web/sort_xyz_blockchain.d.cts +0 -1
- package/document_loaders/web/sort_xyz_blockchain.d.ts +0 -1
- package/document_loaders/web/sort_xyz_blockchain.js +0 -1
- package/document_loaders/web/youtube.cjs +0 -1
- package/document_loaders/web/youtube.d.cts +0 -1
- package/document_loaders/web/youtube.d.ts +0 -1
- package/document_loaders/web/youtube.js +0 -1
- package/experimental/tools/pyinterpreter.cjs +0 -1
- package/experimental/tools/pyinterpreter.d.cts +0 -1
- package/experimental/tools/pyinterpreter.d.ts +0 -1
- package/experimental/tools/pyinterpreter.js +0 -1
- package/memory/index.cjs +0 -1
- package/memory/index.d.cts +0 -1
- package/memory/index.d.ts +0 -1
- package/memory/index.js +0 -1
- package/retrievers/self_query/chroma.cjs +0 -1
- package/retrievers/self_query/chroma.d.cts +0 -1
- package/retrievers/self_query/chroma.d.ts +0 -1
- package/retrievers/self_query/chroma.js +0 -1
- package/retrievers/self_query/pinecone.cjs +0 -1
- package/retrievers/self_query/pinecone.d.cts +0 -1
- package/retrievers/self_query/pinecone.d.ts +0 -1
- package/retrievers/self_query/pinecone.js +0 -1
- package/retrievers/self_query/supabase.cjs +0 -1
- package/retrievers/self_query/supabase.d.cts +0 -1
- package/retrievers/self_query/supabase.d.ts +0 -1
- package/retrievers/self_query/supabase.js +0 -1
- package/retrievers/self_query/vectara.cjs +0 -1
- package/retrievers/self_query/vectara.d.cts +0 -1
- package/retrievers/self_query/vectara.d.ts +0 -1
- package/retrievers/self_query/vectara.js +0 -1
- package/retrievers/self_query/weaviate.cjs +0 -1
- package/retrievers/self_query/weaviate.d.cts +0 -1
- package/retrievers/self_query/weaviate.d.ts +0 -1
- package/retrievers/self_query/weaviate.js +0 -1
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { APIResponseError, Client, isFullBlock, isFullPage, isFullDatabase } from "@notionhq/client";
|
|
2
|
-
import { Document } from "@langchain/core/documents";
|
|
3
|
-
import { AsyncCaller } from "@langchain/core/utils/async_caller";
|
|
4
|
-
import { BaseDocumentLoader } from "../base.js";
|
|
5
|
-
type GuardType<T> = T extends (x: any, ...rest: any) => x is infer U ? U : never;
|
|
6
|
-
export type GetBlockResponse = Parameters<typeof isFullBlock>[0];
|
|
7
|
-
export type GetPageResponse = Parameters<typeof isFullPage>[0];
|
|
8
|
-
export type GetDatabaseResponse = Parameters<typeof isFullDatabase>[0];
|
|
9
|
-
export type BlockObjectResponse = GuardType<typeof isFullBlock>;
|
|
10
|
-
export type PageObjectResponse = GuardType<typeof isFullPage>;
|
|
11
|
-
export type DatabaseObjectResponse = GuardType<typeof isFullDatabase>;
|
|
12
|
-
export type GetResponse = GetBlockResponse | GetPageResponse | GetDatabaseResponse | APIResponseError;
|
|
13
|
-
export type PagePropertiesType = PageObjectResponse["properties"];
|
|
14
|
-
export type PagePropertiesValue = PagePropertiesType[keyof PagePropertiesType];
|
|
15
|
-
export declare const isPageResponse: (res: GetResponse) => res is import("@notionhq/client/build/src/api-endpoints.js").PageObjectResponse | import("@notionhq/client/build/src/api-endpoints.js").PartialPageObjectResponse;
|
|
16
|
-
export declare const isDatabaseResponse: (res: GetResponse) => res is import("@notionhq/client/build/src/api-endpoints.js").DatabaseObjectResponse | import("@notionhq/client/build/src/api-endpoints.js").PartialDatabaseObjectResponse;
|
|
17
|
-
export declare const isErrorResponse: (res: GetResponse) => res is APIResponseError;
|
|
18
|
-
export declare const isPage: (res: GetResponse) => res is import("@notionhq/client/build/src/api-endpoints.js").PageObjectResponse;
|
|
19
|
-
export declare const isDatabase: (res: GetResponse) => res is import("@notionhq/client/build/src/api-endpoints.js").DatabaseObjectResponse;
|
|
20
|
-
/**
|
|
21
|
-
* Represents the type of Notion API to load documents from. The options
|
|
22
|
-
* are "database" or "page".
|
|
23
|
-
*/
|
|
24
|
-
export type NotionAPIType = "database" | "page";
|
|
25
|
-
export type OnDocumentLoadedCallback = (current: number, total: number, currentTitle?: string, rootTitle?: string) => void;
|
|
26
|
-
/**
|
|
27
|
-
* @deprecated - Import from "@langchain/community/document_loaders/web/notionapi" instead. This entrypoint will be removed in 0.3.0.
|
|
28
|
-
*/
|
|
29
|
-
export type NotionAPILoaderOptions = {
|
|
30
|
-
clientOptions: ConstructorParameters<typeof Client>[0];
|
|
31
|
-
id: string;
|
|
32
|
-
type?: NotionAPIType;
|
|
33
|
-
callerOptions?: ConstructorParameters<typeof AsyncCaller>[0];
|
|
34
|
-
onDocumentLoaded?: OnDocumentLoadedCallback;
|
|
35
|
-
propertiesAsHeader?: boolean;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* @deprecated - Import from "@langchain/community/document_loaders/web/notionapi" instead. This entrypoint will be removed in 0.3.0.
|
|
39
|
-
*
|
|
40
|
-
* A class that extends the BaseDocumentLoader class. It represents a
|
|
41
|
-
* document loader for loading documents from Notion using the Notion API.
|
|
42
|
-
* @example
|
|
43
|
-
* ```typescript
|
|
44
|
-
* import { RecursiveCharacterTextSplitter } from "@langchain/textsplitters";
|
|
45
|
-
*
|
|
46
|
-
* const pageLoader = new NotionAPILoader({
|
|
47
|
-
* clientOptions: { auth: "<NOTION_INTEGRATION_TOKEN>" },
|
|
48
|
-
* id: "<PAGE_ID>",
|
|
49
|
-
* type: "page",
|
|
50
|
-
* });
|
|
51
|
-
* const splitter = new RecursiveCharacterTextSplitter();
|
|
52
|
-
* const pageDocs = await pageLoader.loadAndSplit(splitter);
|
|
53
|
-
* const dbLoader = new NotionAPILoader({
|
|
54
|
-
* clientOptions: { auth: "<NOTION_INTEGRATION_TOKEN>" },
|
|
55
|
-
* id: "<DATABASE_ID>",
|
|
56
|
-
* type: "database",
|
|
57
|
-
* propertiesAsHeader: true,
|
|
58
|
-
* });
|
|
59
|
-
* const dbDocs = await dbLoader.load();
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
export declare class NotionAPILoader extends BaseDocumentLoader {
|
|
63
|
-
private caller;
|
|
64
|
-
private notionClient;
|
|
65
|
-
private n2mClient;
|
|
66
|
-
private id;
|
|
67
|
-
private pageQueue;
|
|
68
|
-
private pageCompleted;
|
|
69
|
-
pageQueueTotal: number;
|
|
70
|
-
private documents;
|
|
71
|
-
private rootTitle;
|
|
72
|
-
private onDocumentLoaded;
|
|
73
|
-
private propertiesAsHeader;
|
|
74
|
-
constructor(options: NotionAPILoaderOptions);
|
|
75
|
-
/**
|
|
76
|
-
* Adds a selection of page ids to the pageQueue and removes duplicates.
|
|
77
|
-
* @param items An array of string ids
|
|
78
|
-
*/
|
|
79
|
-
private addToQueue;
|
|
80
|
-
/**
|
|
81
|
-
* Parses a Notion GetResponse object (page or database) and returns a string of the title.
|
|
82
|
-
* @param obj The Notion GetResponse object to parse.
|
|
83
|
-
* @returns The string of the title.
|
|
84
|
-
*/
|
|
85
|
-
private getTitle;
|
|
86
|
-
/**
|
|
87
|
-
* Parses the property type and returns a string
|
|
88
|
-
* @param page The Notion page property to parse.
|
|
89
|
-
* @returns A string of parsed property.
|
|
90
|
-
*/
|
|
91
|
-
private getPropValue;
|
|
92
|
-
/**
|
|
93
|
-
* Parses the properties of a Notion page and returns them as key-value
|
|
94
|
-
* pairs.
|
|
95
|
-
* @param page The Notion page to parse.
|
|
96
|
-
* @returns An object containing the parsed properties as key-value pairs.
|
|
97
|
-
*/
|
|
98
|
-
private parsePageProperties;
|
|
99
|
-
/**
|
|
100
|
-
* Parses the details of a Notion page and returns them as an object.
|
|
101
|
-
* @param page The Notion page to parse.
|
|
102
|
-
* @returns An object containing the parsed details of the page.
|
|
103
|
-
*/
|
|
104
|
-
private parsePageDetails;
|
|
105
|
-
/**
|
|
106
|
-
* Loads a Notion block and returns it as an MdBlock object.
|
|
107
|
-
* @param block The Notion block to load.
|
|
108
|
-
* @returns A Promise that resolves to an MdBlock object.
|
|
109
|
-
*/
|
|
110
|
-
private loadBlock;
|
|
111
|
-
/**
|
|
112
|
-
* Loads Notion blocks and their children recursively.
|
|
113
|
-
* @param blocksResponse The response from the Notion API containing the blocks to load.
|
|
114
|
-
* @returns A Promise that resolves to an array containing the loaded MdBlocks.
|
|
115
|
-
*/
|
|
116
|
-
private loadBlocks;
|
|
117
|
-
/**
|
|
118
|
-
* Loads a Notion page and its child documents, then adds it to the completed documents array.
|
|
119
|
-
* @param page The Notion page or page ID to load.
|
|
120
|
-
*/
|
|
121
|
-
private loadPage;
|
|
122
|
-
/**
|
|
123
|
-
* Loads a Notion database and adds it's pages to the queue.
|
|
124
|
-
* @param id The ID of the Notion database to load.
|
|
125
|
-
*/
|
|
126
|
-
private loadDatabase;
|
|
127
|
-
/**
|
|
128
|
-
* Loads the documents from Notion based on the specified options.
|
|
129
|
-
* @returns A Promise that resolves to an array of Documents.
|
|
130
|
-
*/
|
|
131
|
-
load(): Promise<Document[]>;
|
|
132
|
-
}
|
|
133
|
-
export {};
|
|
@@ -1,392 +0,0 @@
|
|
|
1
|
-
import { Client, isFullBlock, isFullPage, iteratePaginatedAPI, APIErrorCode, isNotionClientError, isFullDatabase, } from "@notionhq/client";
|
|
2
|
-
import { NotionToMarkdown } from "notion-to-md";
|
|
3
|
-
import { getBlockChildren } from "notion-to-md/build/utils/notion.js";
|
|
4
|
-
import yaml from "js-yaml";
|
|
5
|
-
import { Document } from "@langchain/core/documents";
|
|
6
|
-
import { AsyncCaller } from "@langchain/core/utils/async_caller";
|
|
7
|
-
import { BaseDocumentLoader } from "../base.js";
|
|
8
|
-
import { logVersion020MigrationWarning } from "../../util/entrypoint_deprecation.js";
|
|
9
|
-
/* #__PURE__ */ logVersion020MigrationWarning({
|
|
10
|
-
oldEntrypointName: "document_loaders/web/notionapi",
|
|
11
|
-
newPackageName: "@langchain/community",
|
|
12
|
-
});
|
|
13
|
-
export const isPageResponse = (res) => !isNotionClientError(res) && res.object === "page";
|
|
14
|
-
export const isDatabaseResponse = (res) => !isNotionClientError(res) && res.object === "database";
|
|
15
|
-
export const isErrorResponse = (res) => isNotionClientError(res);
|
|
16
|
-
export const isPage = (res) => isPageResponse(res) && isFullPage(res);
|
|
17
|
-
export const isDatabase = (res) => isDatabaseResponse(res) && isFullDatabase(res);
|
|
18
|
-
/**
|
|
19
|
-
* @deprecated - Import from "@langchain/community/document_loaders/web/notionapi" instead. This entrypoint will be removed in 0.3.0.
|
|
20
|
-
*
|
|
21
|
-
* A class that extends the BaseDocumentLoader class. It represents a
|
|
22
|
-
* document loader for loading documents from Notion using the Notion API.
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* import { RecursiveCharacterTextSplitter } from "@langchain/textsplitters";
|
|
26
|
-
*
|
|
27
|
-
* const pageLoader = new NotionAPILoader({
|
|
28
|
-
* clientOptions: { auth: "<NOTION_INTEGRATION_TOKEN>" },
|
|
29
|
-
* id: "<PAGE_ID>",
|
|
30
|
-
* type: "page",
|
|
31
|
-
* });
|
|
32
|
-
* const splitter = new RecursiveCharacterTextSplitter();
|
|
33
|
-
* const pageDocs = await pageLoader.loadAndSplit(splitter);
|
|
34
|
-
* const dbLoader = new NotionAPILoader({
|
|
35
|
-
* clientOptions: { auth: "<NOTION_INTEGRATION_TOKEN>" },
|
|
36
|
-
* id: "<DATABASE_ID>",
|
|
37
|
-
* type: "database",
|
|
38
|
-
* propertiesAsHeader: true,
|
|
39
|
-
* });
|
|
40
|
-
* const dbDocs = await dbLoader.load();
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export class NotionAPILoader extends BaseDocumentLoader {
|
|
44
|
-
constructor(options) {
|
|
45
|
-
super();
|
|
46
|
-
Object.defineProperty(this, "caller", {
|
|
47
|
-
enumerable: true,
|
|
48
|
-
configurable: true,
|
|
49
|
-
writable: true,
|
|
50
|
-
value: void 0
|
|
51
|
-
});
|
|
52
|
-
Object.defineProperty(this, "notionClient", {
|
|
53
|
-
enumerable: true,
|
|
54
|
-
configurable: true,
|
|
55
|
-
writable: true,
|
|
56
|
-
value: void 0
|
|
57
|
-
});
|
|
58
|
-
Object.defineProperty(this, "n2mClient", {
|
|
59
|
-
enumerable: true,
|
|
60
|
-
configurable: true,
|
|
61
|
-
writable: true,
|
|
62
|
-
value: void 0
|
|
63
|
-
});
|
|
64
|
-
Object.defineProperty(this, "id", {
|
|
65
|
-
enumerable: true,
|
|
66
|
-
configurable: true,
|
|
67
|
-
writable: true,
|
|
68
|
-
value: void 0
|
|
69
|
-
});
|
|
70
|
-
Object.defineProperty(this, "pageQueue", {
|
|
71
|
-
enumerable: true,
|
|
72
|
-
configurable: true,
|
|
73
|
-
writable: true,
|
|
74
|
-
value: void 0
|
|
75
|
-
});
|
|
76
|
-
Object.defineProperty(this, "pageCompleted", {
|
|
77
|
-
enumerable: true,
|
|
78
|
-
configurable: true,
|
|
79
|
-
writable: true,
|
|
80
|
-
value: void 0
|
|
81
|
-
});
|
|
82
|
-
Object.defineProperty(this, "pageQueueTotal", {
|
|
83
|
-
enumerable: true,
|
|
84
|
-
configurable: true,
|
|
85
|
-
writable: true,
|
|
86
|
-
value: void 0
|
|
87
|
-
});
|
|
88
|
-
Object.defineProperty(this, "documents", {
|
|
89
|
-
enumerable: true,
|
|
90
|
-
configurable: true,
|
|
91
|
-
writable: true,
|
|
92
|
-
value: void 0
|
|
93
|
-
});
|
|
94
|
-
Object.defineProperty(this, "rootTitle", {
|
|
95
|
-
enumerable: true,
|
|
96
|
-
configurable: true,
|
|
97
|
-
writable: true,
|
|
98
|
-
value: void 0
|
|
99
|
-
});
|
|
100
|
-
Object.defineProperty(this, "onDocumentLoaded", {
|
|
101
|
-
enumerable: true,
|
|
102
|
-
configurable: true,
|
|
103
|
-
writable: true,
|
|
104
|
-
value: void 0
|
|
105
|
-
});
|
|
106
|
-
Object.defineProperty(this, "propertiesAsHeader", {
|
|
107
|
-
enumerable: true,
|
|
108
|
-
configurable: true,
|
|
109
|
-
writable: true,
|
|
110
|
-
value: void 0
|
|
111
|
-
});
|
|
112
|
-
this.caller = new AsyncCaller({
|
|
113
|
-
maxConcurrency: 64,
|
|
114
|
-
...options.callerOptions,
|
|
115
|
-
});
|
|
116
|
-
this.notionClient = new Client({
|
|
117
|
-
logger: () => { },
|
|
118
|
-
...options.clientOptions,
|
|
119
|
-
});
|
|
120
|
-
this.n2mClient = new NotionToMarkdown({
|
|
121
|
-
notionClient: this.notionClient,
|
|
122
|
-
config: { parseChildPages: false, convertImagesToBase64: false },
|
|
123
|
-
});
|
|
124
|
-
this.id = options.id;
|
|
125
|
-
this.pageQueue = [];
|
|
126
|
-
this.pageCompleted = [];
|
|
127
|
-
this.pageQueueTotal = 0;
|
|
128
|
-
this.documents = [];
|
|
129
|
-
this.rootTitle = "";
|
|
130
|
-
this.onDocumentLoaded = options.onDocumentLoaded ?? ((_ti, _cu) => { });
|
|
131
|
-
this.propertiesAsHeader = options.propertiesAsHeader || false;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Adds a selection of page ids to the pageQueue and removes duplicates.
|
|
135
|
-
* @param items An array of string ids
|
|
136
|
-
*/
|
|
137
|
-
addToQueue(...items) {
|
|
138
|
-
const deDuped = items.filter((item) => !this.pageCompleted.concat(this.pageQueue).includes(item));
|
|
139
|
-
this.pageQueue.push(...deDuped);
|
|
140
|
-
this.pageQueueTotal += deDuped.length;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Parses a Notion GetResponse object (page or database) and returns a string of the title.
|
|
144
|
-
* @param obj The Notion GetResponse object to parse.
|
|
145
|
-
* @returns The string of the title.
|
|
146
|
-
*/
|
|
147
|
-
getTitle(obj) {
|
|
148
|
-
if (isPage(obj)) {
|
|
149
|
-
const titleProp = Object.values(obj.properties).find((prop) => prop.type === "title");
|
|
150
|
-
if (titleProp)
|
|
151
|
-
return this.getPropValue(titleProp);
|
|
152
|
-
}
|
|
153
|
-
if (isDatabase(obj))
|
|
154
|
-
return obj.title
|
|
155
|
-
.map((v) => this.n2mClient.annotatePlainText(v.plain_text, v.annotations))
|
|
156
|
-
.join("");
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Parses the property type and returns a string
|
|
161
|
-
* @param page The Notion page property to parse.
|
|
162
|
-
* @returns A string of parsed property.
|
|
163
|
-
*/
|
|
164
|
-
getPropValue(prop) {
|
|
165
|
-
switch (prop.type) {
|
|
166
|
-
case "number": {
|
|
167
|
-
const propNumber = prop[prop.type];
|
|
168
|
-
return propNumber !== null ? propNumber.toString() : "";
|
|
169
|
-
}
|
|
170
|
-
case "url":
|
|
171
|
-
return prop[prop.type] || "";
|
|
172
|
-
case "select":
|
|
173
|
-
return prop[prop.type]?.name ?? "";
|
|
174
|
-
case "multi_select":
|
|
175
|
-
return `[${prop[prop.type].map((v) => `"${v.name}"`).join(", ")}]`;
|
|
176
|
-
case "status":
|
|
177
|
-
return prop[prop.type]?.name ?? "";
|
|
178
|
-
case "date":
|
|
179
|
-
return `${prop[prop.type]?.start ?? ""}${prop[prop.type]?.end ? ` - ${prop[prop.type]?.end}` : ""}`;
|
|
180
|
-
case "email":
|
|
181
|
-
return prop[prop.type] || "";
|
|
182
|
-
case "phone_number":
|
|
183
|
-
return prop[prop.type] || "";
|
|
184
|
-
case "checkbox":
|
|
185
|
-
return prop[prop.type].toString();
|
|
186
|
-
case "files":
|
|
187
|
-
return `[${prop[prop.type].map((v) => `"${v.name}"`).join(", ")}]`;
|
|
188
|
-
case "created_by":
|
|
189
|
-
return `["${prop[prop.type].object}", "${prop[prop.type].id}"]`;
|
|
190
|
-
case "created_time":
|
|
191
|
-
return prop[prop.type];
|
|
192
|
-
case "last_edited_by":
|
|
193
|
-
return `["${prop[prop.type].object}", "${prop[prop.type].id}"]`;
|
|
194
|
-
case "last_edited_time":
|
|
195
|
-
return prop[prop.type];
|
|
196
|
-
case "title":
|
|
197
|
-
return prop[prop.type]
|
|
198
|
-
.map((v) => this.n2mClient.annotatePlainText(v.plain_text, v.annotations))
|
|
199
|
-
.join("");
|
|
200
|
-
case "rich_text":
|
|
201
|
-
return prop[prop.type]
|
|
202
|
-
.map((v) => this.n2mClient.annotatePlainText(v.plain_text, v.annotations))
|
|
203
|
-
.join("");
|
|
204
|
-
case "people":
|
|
205
|
-
return `[${prop[prop.type]
|
|
206
|
-
.map((v) => `["${v.object}", "${v.id}"]`)
|
|
207
|
-
.join(", ")}]`;
|
|
208
|
-
case "unique_id":
|
|
209
|
-
return `${prop[prop.type].prefix || ""}${prop[prop.type].number}`;
|
|
210
|
-
case "relation":
|
|
211
|
-
return `[${prop[prop.type].map((v) => `"${v.id}"`).join(", ")}]`;
|
|
212
|
-
default:
|
|
213
|
-
return `Unsupported type: ${prop.type}`;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Parses the properties of a Notion page and returns them as key-value
|
|
218
|
-
* pairs.
|
|
219
|
-
* @param page The Notion page to parse.
|
|
220
|
-
* @returns An object containing the parsed properties as key-value pairs.
|
|
221
|
-
*/
|
|
222
|
-
parsePageProperties(page) {
|
|
223
|
-
return Object.entries(page.properties).reduce((accum, [propName, prop]) => {
|
|
224
|
-
const value = this.getPropValue(prop);
|
|
225
|
-
const props = { ...accum, [propName]: value };
|
|
226
|
-
return prop.type === "title" ? { ...props, _title: value } : props;
|
|
227
|
-
}, {});
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Parses the details of a Notion page and returns them as an object.
|
|
231
|
-
* @param page The Notion page to parse.
|
|
232
|
-
* @returns An object containing the parsed details of the page.
|
|
233
|
-
*/
|
|
234
|
-
parsePageDetails(page) {
|
|
235
|
-
const { id, ...rest } = page;
|
|
236
|
-
return {
|
|
237
|
-
...rest,
|
|
238
|
-
notionId: id,
|
|
239
|
-
properties: this.parsePageProperties(page),
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Loads a Notion block and returns it as an MdBlock object.
|
|
244
|
-
* @param block The Notion block to load.
|
|
245
|
-
* @returns A Promise that resolves to an MdBlock object.
|
|
246
|
-
*/
|
|
247
|
-
async loadBlock(block) {
|
|
248
|
-
const mdBlock = {
|
|
249
|
-
type: block.type,
|
|
250
|
-
blockId: block.id,
|
|
251
|
-
parent: await this.caller.call(() => this.n2mClient.blockToMarkdown(block)),
|
|
252
|
-
children: [],
|
|
253
|
-
};
|
|
254
|
-
if (block.has_children) {
|
|
255
|
-
const block_id = block.type === "synced_block" &&
|
|
256
|
-
block.synced_block?.synced_from?.block_id
|
|
257
|
-
? block.synced_block.synced_from.block_id
|
|
258
|
-
: block.id;
|
|
259
|
-
const childBlocks = await this.loadBlocks(await this.caller.call(() => getBlockChildren(this.notionClient, block_id, null)));
|
|
260
|
-
mdBlock.children = childBlocks;
|
|
261
|
-
}
|
|
262
|
-
return mdBlock;
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Loads Notion blocks and their children recursively.
|
|
266
|
-
* @param blocksResponse The response from the Notion API containing the blocks to load.
|
|
267
|
-
* @returns A Promise that resolves to an array containing the loaded MdBlocks.
|
|
268
|
-
*/
|
|
269
|
-
async loadBlocks(blocksResponse) {
|
|
270
|
-
const blocks = blocksResponse.filter(isFullBlock);
|
|
271
|
-
// Add child pages to queue
|
|
272
|
-
const childPages = blocks
|
|
273
|
-
.filter((block) => block.type.includes("child_page"))
|
|
274
|
-
.map((block) => block.id);
|
|
275
|
-
if (childPages.length > 0)
|
|
276
|
-
this.addToQueue(...childPages);
|
|
277
|
-
// Add child database pages to queue
|
|
278
|
-
const childDatabases = blocks
|
|
279
|
-
.filter((block) => block.type.includes("child_database"))
|
|
280
|
-
.map((block) => this.caller.call(() => this.loadDatabase(block.id)));
|
|
281
|
-
// Load this block and child blocks
|
|
282
|
-
const loadingMdBlocks = blocks
|
|
283
|
-
.filter((block) => !["child_page", "child_database"].includes(block.type))
|
|
284
|
-
.map((block) => this.loadBlock(block));
|
|
285
|
-
const [mdBlocks] = await Promise.all([
|
|
286
|
-
Promise.all(loadingMdBlocks),
|
|
287
|
-
Promise.all(childDatabases),
|
|
288
|
-
]);
|
|
289
|
-
return mdBlocks;
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Loads a Notion page and its child documents, then adds it to the completed documents array.
|
|
293
|
-
* @param page The Notion page or page ID to load.
|
|
294
|
-
*/
|
|
295
|
-
async loadPage(page) {
|
|
296
|
-
// Check page is a page ID or a PageObjectResponse
|
|
297
|
-
const [pageData, pageId] = typeof page === "string"
|
|
298
|
-
? [
|
|
299
|
-
this.caller.call(() => this.notionClient.pages.retrieve({ page_id: page })),
|
|
300
|
-
page,
|
|
301
|
-
]
|
|
302
|
-
: [page, page.id];
|
|
303
|
-
const [pageDetails, pageBlocks] = await Promise.all([
|
|
304
|
-
pageData,
|
|
305
|
-
this.caller.call(() => getBlockChildren(this.notionClient, pageId, null)),
|
|
306
|
-
]);
|
|
307
|
-
if (!isFullPage(pageDetails)) {
|
|
308
|
-
this.pageCompleted.push(pageId);
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
const mdBlocks = await this.loadBlocks(pageBlocks);
|
|
312
|
-
const mdStringObject = this.n2mClient.toMarkdownString(mdBlocks);
|
|
313
|
-
let pageContent = mdStringObject.parent;
|
|
314
|
-
const metadata = this.parsePageDetails(pageDetails);
|
|
315
|
-
if (this.propertiesAsHeader) {
|
|
316
|
-
pageContent =
|
|
317
|
-
`---\n` +
|
|
318
|
-
`${yaml.dump(metadata.properties)}` +
|
|
319
|
-
`---\n\n` +
|
|
320
|
-
`${pageContent ?? ""}`;
|
|
321
|
-
}
|
|
322
|
-
if (!pageContent) {
|
|
323
|
-
this.pageCompleted.push(pageId);
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
const pageDocument = new Document({ pageContent, metadata });
|
|
327
|
-
this.documents.push(pageDocument);
|
|
328
|
-
this.pageCompleted.push(pageId);
|
|
329
|
-
this.onDocumentLoaded(this.documents.length, this.pageQueueTotal, this.getTitle(pageDetails) || undefined, this.rootTitle);
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* Loads a Notion database and adds it's pages to the queue.
|
|
333
|
-
* @param id The ID of the Notion database to load.
|
|
334
|
-
*/
|
|
335
|
-
async loadDatabase(id) {
|
|
336
|
-
try {
|
|
337
|
-
for await (const page of iteratePaginatedAPI(this.notionClient.databases.query, {
|
|
338
|
-
database_id: id,
|
|
339
|
-
page_size: 50,
|
|
340
|
-
})) {
|
|
341
|
-
this.addToQueue(page.id);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
catch (e) {
|
|
345
|
-
console.log(e);
|
|
346
|
-
// TODO: Catch and report api request errors
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* Loads the documents from Notion based on the specified options.
|
|
351
|
-
* @returns A Promise that resolves to an array of Documents.
|
|
352
|
-
*/
|
|
353
|
-
async load() {
|
|
354
|
-
const resPagePromise = this.notionClient.pages
|
|
355
|
-
.retrieve({ page_id: this.id })
|
|
356
|
-
.then((res) => {
|
|
357
|
-
this.addToQueue(this.id);
|
|
358
|
-
return res;
|
|
359
|
-
})
|
|
360
|
-
.catch((error) => error);
|
|
361
|
-
const resDatabasePromise = this.notionClient.databases
|
|
362
|
-
.retrieve({ database_id: this.id })
|
|
363
|
-
.then(async (res) => {
|
|
364
|
-
await this.loadDatabase(this.id);
|
|
365
|
-
return res;
|
|
366
|
-
})
|
|
367
|
-
.catch((error) => error);
|
|
368
|
-
const [resPage, resDatabase] = await Promise.all([
|
|
369
|
-
resPagePromise,
|
|
370
|
-
resDatabasePromise,
|
|
371
|
-
]);
|
|
372
|
-
// Check if both resPage and resDatabase resulted in error responses
|
|
373
|
-
const errors = [resPage, resDatabase].filter(isErrorResponse);
|
|
374
|
-
if (errors.length === 2) {
|
|
375
|
-
if (errors.every((e) => e.code === APIErrorCode.ObjectNotFound)) {
|
|
376
|
-
throw new AggregateError([
|
|
377
|
-
Error(`Could not find object with ID: ${this.id}. Make sure the relevant pages and databases are shared with your integration.`),
|
|
378
|
-
...errors,
|
|
379
|
-
]);
|
|
380
|
-
}
|
|
381
|
-
throw new AggregateError(errors);
|
|
382
|
-
}
|
|
383
|
-
this.rootTitle =
|
|
384
|
-
this.getTitle(resPage) || this.getTitle(resDatabase) || this.id;
|
|
385
|
-
let pageId = this.pageQueue.shift();
|
|
386
|
-
while (pageId) {
|
|
387
|
-
await this.loadPage(pageId);
|
|
388
|
-
pageId = this.pageQueue.shift();
|
|
389
|
-
}
|
|
390
|
-
return this.documents;
|
|
391
|
-
}
|
|
392
|
-
}
|