polite-crawler 0.4.0 → 0.5.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.
- package/README.md +1 -0
- package/build/{browser-56dBBLec.mjs → browser-Cp5W-dmj.mjs} +5 -10
- package/build/{browser-56dBBLec.mjs.map → browser-Cp5W-dmj.mjs.map} +1 -1
- package/build/classify.d.mts +0 -2
- package/build/classify.mjs +1 -2
- package/build/{cli-daemon-Br17snPs.mjs → cli-daemon-oSJWogkA.mjs} +3 -4
- package/build/{cli-daemon-Br17snPs.mjs.map → cli-daemon-oSJWogkA.mjs.map} +1 -1
- package/build/{cli-recipes-Cjq6ohWH.mjs → cli-recipes-DVTMTQLx.mjs} +4 -5
- package/build/{cli-recipes-Cjq6ohWH.mjs.map → cli-recipes-DVTMTQLx.mjs.map} +1 -1
- package/build/cli.mjs +16 -19
- package/build/cli.mjs.map +1 -1
- package/build/{daemon-BPswUOgu.mjs → daemon-DNGSr4hR.mjs} +7 -13
- package/build/{daemon-BPswUOgu.mjs.map → daemon-DNGSr4hR.mjs.map} +1 -1
- package/build/{diff-DuD9pinS.mjs → diff-ChsL3yux.mjs} +5 -12
- package/build/{diff-DuD9pinS.mjs.map → diff-ChsL3yux.mjs.map} +1 -1
- package/build/{extract-BISJyKWN.mjs → extract-DO-NFOmF.mjs} +7 -12
- package/build/{extract-BISJyKWN.mjs.map → extract-DO-NFOmF.mjs.map} +1 -1
- package/build/hours.d.mts +0 -2
- package/build/hours.mjs +1 -2
- package/build/{html-Dir5QEi0.mjs → html-CawWTgMQ.mjs} +4 -6
- package/build/{html-Dir5QEi0.mjs.map → html-CawWTgMQ.mjs.map} +1 -1
- package/build/{html-o5bDHjNi.d.mts → html-oS_ueu9U.d.mts} +2 -20
- package/build/html.d.mts +2 -1
- package/build/html.mjs +2 -2
- package/build/index.d.mts +5 -72
- package/build/index.mjs +20 -19
- package/build/{log-CmBWcyQm.mjs → log-CB5bADmd.mjs} +3 -5
- package/build/{log-CmBWcyQm.mjs.map → log-CB5bADmd.mjs.map} +1 -1
- package/build/{mcp-package-Y0bREnOS.mjs → mcp-package-D9ACY0Ux.mjs} +2 -3
- package/build/{mcp-package-Y0bREnOS.mjs.map → mcp-package-D9ACY0Ux.mjs.map} +1 -1
- package/build/{ollama-D1xRh3hY.mjs → ollama-BDZjLDOK.mjs} +4 -10
- package/build/{ollama-D1xRh3hY.mjs.map → ollama-BDZjLDOK.mjs.map} +1 -1
- package/build/{open-CsFRWOjf.mjs → open-DOgE033K.mjs} +23 -40
- package/build/{open-CsFRWOjf.mjs.map → open-DOgE033K.mjs.map} +1 -1
- package/build/politeness.d.mts +0 -2
- package/build/politeness.mjs +1 -2
- package/build/{recipe-30dN3orz.mjs → recipe-BsGOZJyi.mjs} +5 -6
- package/build/{recipe-30dN3orz.mjs.map → recipe-BsGOZJyi.mjs.map} +1 -1
- package/build/{recipe-product-BuJ_gEwn.mjs → recipe-product-DEDPKMY5.mjs} +7 -9
- package/build/{recipe-product-BuJ_gEwn.mjs.map → recipe-product-DEDPKMY5.mjs.map} +1 -1
- package/build/{render-CKE2LILH.mjs → render-CZaqvjQh.mjs} +2 -3
- package/build/{render-CKE2LILH.mjs.map → render-CZaqvjQh.mjs.map} +1 -1
- package/build/robots.d.mts +0 -2
- package/build/robots.mjs +1 -2
- package/build/{rolldown-runtime-8H4AJuhK.mjs → rolldown-runtime-BJohB4LM.mjs} +1 -2
- package/build/{runtime-C2VRY89U.mjs → runtime-NyweI69B.mjs} +13 -20
- package/build/{runtime-C2VRY89U.mjs.map → runtime-NyweI69B.mjs.map} +1 -1
- package/build/signals.d.mts +0 -2
- package/build/signals.mjs +1 -2
- package/build/{transformers-BNiuiLxT.mjs → transformers-C_ziG8yf.mjs} +4 -9
- package/build/{transformers-BNiuiLxT.mjs.map → transformers-C_ziG8yf.mjs.map} +1 -1
- package/build/urls.d.mts +28 -0
- package/build/{urls-BHFeSyEK.mjs → urls.mjs} +3 -4
- package/build/urls.mjs.map +1 -0
- package/build/{version-B9CUZfx5.mjs → version-hVv3n9O6.mjs} +4 -6
- package/build/{version-B9CUZfx5.mjs.map → version-hVv3n9O6.mjs.map} +1 -1
- package/build/{wacz-D5bvxsiM.mjs → wacz-Blvh5qwS.mjs} +7 -9
- package/build/{wacz-D5bvxsiM.mjs.map → wacz-Blvh5qwS.mjs.map} +1 -1
- package/build/{warc-DsB3oP78.mjs → warc-DiE1M5le.mjs} +7 -17
- package/build/{warc-DsB3oP78.mjs.map → warc-DiE1M5le.mjs.map} +1 -1
- package/build/{webbotauth-Dq_dA_u3.mjs → webbotauth-W3GXY3dy.mjs} +4 -11
- package/build/{webbotauth-Dq_dA_u3.mjs.map → webbotauth-W3GXY3dy.mjs.map} +1 -1
- package/package.json +5 -1
- package/build/urls-BHFeSyEK.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ollama-D1xRh3hY.mjs","names":[],"sources":["../src/ollama.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { EmbedCallOptions, Embedder } from \"./embed.ts\";\n\n/**\n * The Ollama embedder sends texts to the local HTTP API of Ollama (`POST /api/embed`). The package\n * has no dependency for it: you install Ollama, start it (`ollama serve`) and pull a model\n * (`ollama pull nomic-embed-text`).\n *\n * The page text goes to the Ollama server. Thus the embedder accepts only a server on this\n * computer (a loopback address), unless `allowRemote` is true.\n */\n\n/** These are the facts of the embedding models that the Ollama library has. */\nexport interface EmbeddingModel {\n readonly dimensions: number;\n readonly maxInputTokens: number;\n /** This prefix goes before the text of a question. */\n readonly queryPrefix?: string | undefined;\n /** This prefix goes before each chunk of a stored text. */\n readonly documentPrefix?: string | undefined;\n}\n\n/** These are the facts of three embedding models of Ollama. The name has no tag (`nomic-embed-text`, not `nomic-embed-text:latest`). */\nexport const OLLAMA_MODELS: Readonly<Record<string, EmbeddingModel>> = {\n \"nomic-embed-text\": {\n dimensions: 768,\n maxInputTokens: 8192,\n queryPrefix: \"search_query: \",\n documentPrefix: \"search_document: \",\n },\n \"all-minilm\": { dimensions: 384, maxInputTokens: 256 },\n \"mxbai-embed-large\": {\n dimensions: 1024,\n maxInputTokens: 512,\n queryPrefix: \"Represent this sentence for searching relevant passages: \",\n },\n};\n\n/** These options make an Ollama embedder. */\nexport interface OllamaEmbedderOptions {\n /** This value is the model of Ollama, with a tag when you want one. The default is `nomic-embed-text`. */\n readonly model?: string | undefined;\n /** This URL is the Ollama server. The default is `http://127.0.0.1:11434`. */\n readonly baseUrl?: string | undefined;\n /** This value is the number of texts in one request. The default is 32. */\n readonly batch?: number | undefined;\n /**\n * The value true lets `baseUrl` be a server on a different computer. The default is false,\n * because the embedder sends the text of the stored pages to the server.\n */\n readonly allowRemote?: boolean | undefined;\n /** This value is the length of each vector. The default comes from `OLLAMA_MODELS`, or from the first answer. */\n readonly dimensions?: number | undefined;\n /** This value is the input limit of the model in tokens. The default comes from `OLLAMA_MODELS`, or it is 256. */\n readonly maxInputTokens?: number | undefined;\n /** This prefix goes before the text of a question. The default comes from `OLLAMA_MODELS`. */\n readonly queryPrefix?: string | undefined;\n /** This prefix goes before each chunk of a stored text. The default comes from `OLLAMA_MODELS`. */\n readonly documentPrefix?: string | undefined;\n /** This value is the longest time of one request in milliseconds. The default is 2 minutes, because the first request loads the model. */\n readonly timeoutMs?: number | undefined;\n}\n\n/** The text of the error when no Ollama server answers. */\nexport const NO_OLLAMA =\n \"Ollama does not answer: install it from https://ollama.com, then start it with ollama serve\";\n\n/**\n * This function tells if a host name is a loopback address: `localhost`, `127.0.0.0/8` or `::1`.\n *\n * @beta\n */\nexport const isLoopback = (host: string): boolean => {\n const name = host.replace(/^\\[|\\]$/g, \"\").toLowerCase();\n return (\n name === \"localhost\" ||\n name.endsWith(\".localhost\") ||\n name === \"::1\" ||\n /^127(?:\\.\\d{1,3}){3}$/.test(name) ||\n /^::ffff:127(?:\\.\\d{1,3}){3}$/.test(name)\n );\n};\n\n/** This function gives the name of a model with no tag, for `OLLAMA_MODELS`. */\nconst baseName = (model: string): string => {\n const slash = model.lastIndexOf(\"/\");\n const colon = model.indexOf(\":\", slash + 1);\n return colon === -1 ? model : model.slice(0, colon);\n};\n\nconst messageOf = (error: unknown): string =>\n error instanceof Error ? error.message : String(error);\n\n/** This function gives the code of a network error, also when it is the cause of the error of `fetch`. */\nconst codeOf = (error: unknown): string | undefined => {\n for (\n let at: unknown = error, depth = 0;\n at !== undefined && at !== null && depth < 4;\n depth += 1\n ) {\n const code = (at as { code?: unknown }).code;\n if (typeof code === \"string\") return code;\n at = (at as { cause?: unknown }).cause;\n }\n return undefined;\n};\n\nconst NETWORK = new Set([\n \"ECONNREFUSED\",\n \"ECONNRESET\",\n \"ENOTFOUND\",\n \"EHOSTUNREACH\",\n \"ENETUNREACH\",\n \"EAI_AGAIN\",\n \"UND_ERR_SOCKET\",\n \"UND_ERR_CONNECT_TIMEOUT\",\n]);\n\n/**\n * This function makes an embedder that sends texts to Ollama (`POST {baseUrl}/api/embed`). It\n * sends `batch` texts in each request, and it stops when the signal aborts. The errors tell what\n * to do: `ollama serve` when no server answers, and `ollama pull <model>` when the model is not\n * there. A `baseUrl` on a different computer throws a `RangeError`, unless `allowRemote` is true.\n */\nexport const ollamaEmbedder = (options: OllamaEmbedderOptions = {}): Embedder => {\n const model = options.model ?? \"nomic-embed-text\";\n if (model.trim() === \"\") throw new RangeError(\"the Ollama model must have a name\");\n const base = options.baseUrl ?? \"http://127.0.0.1:11434\";\n let url: URL;\n try {\n url = new URL(base);\n } catch (cause) {\n throw new RangeError(`the Ollama URL ${base} is not a URL`, { cause });\n }\n if (url.protocol !== \"http:\" && url.protocol !== \"https:\")\n throw new RangeError(`the Ollama URL ${base} must be an http or https URL`);\n if (url.username !== \"\" || url.password !== \"\")\n throw new RangeError(\"the Ollama URL must not hold a user name or a password\");\n if (!isLoopback(url.hostname) && options.allowRemote !== true) {\n throw new RangeError(\n `the Ollama URL ${url.origin} is not on this computer, and the embedder sends the text of the stored pages to it: give allowRemote: true (--allow-remote-ollama) to permit it`,\n );\n }\n const endpoint = new URL(\"api/embed\", url.href.endsWith(\"/\") ? url.href : `${url.href}/`).href;\n const known = OLLAMA_MODELS[baseName(model)];\n const batch = Math.max(1, Math.floor(options.batch ?? 32));\n const timeoutMs = Math.max(1, Math.floor(options.timeoutMs ?? 120_000));\n const queryPrefix = options.queryPrefix ?? known?.queryPrefix ?? \"\";\n const documentPrefix = options.documentPrefix ?? known?.documentPrefix ?? \"\";\n // a document prefix of your own changes each stored vector, so it changes the id\n const custom =\n options.documentPrefix !== undefined && options.documentPrefix !== (known?.documentPrefix ?? \"\")\n ? `#${createHash(\"sha256\").update(options.documentPrefix).digest(\"hex\").slice(0, 8)}`\n : \"\";\n let dimensions = options.dimensions ?? known?.dimensions ?? 0;\n const maxInputTokens = options.maxInputTokens ?? known?.maxInputTokens ?? 256;\n\n const request = async (\n input: readonly string[],\n signal: AbortSignal | undefined,\n ): Promise<number[][]> => {\n const timeout = AbortSignal.timeout(timeoutMs);\n const both = signal === undefined ? timeout : AbortSignal.any([signal, timeout]);\n let response: Response;\n try {\n response = await fetch(endpoint, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ model, input, truncate: true }),\n signal: both,\n });\n } catch (error) {\n if (signal?.aborted === true) throw signal.reason;\n if (timeout.aborted)\n throw new Error(`Ollama at ${url.origin} did not answer in ${String(timeoutMs)} ms`, {\n cause: error,\n });\n const code = codeOf(error);\n if (code !== undefined && NETWORK.has(code))\n throw new Error(`${NO_OLLAMA} (no answer at ${url.origin}: ${code})`, { cause: error });\n // fetch says only \"fetch failed\": the cause tells why\n const cause = (error as { cause?: unknown }).cause;\n throw new Error(\n `the request to Ollama at ${url.origin} failed: ${messageOf(error)}${cause === undefined ? \"\" : ` (${messageOf(cause)})`}`,\n { cause: error },\n );\n }\n let text: string;\n try {\n text = await response.text();\n } catch (error) {\n if (signal?.aborted === true) throw signal.reason;\n throw new Error(`the answer of Ollama at ${url.origin} stopped: ${messageOf(error)}`, {\n cause: error,\n });\n }\n let body: { embeddings?: unknown; error?: unknown } | undefined;\n try {\n body = JSON.parse(text) as { embeddings?: unknown; error?: unknown };\n } catch {\n body = undefined;\n }\n const said = typeof body?.error === \"string\" ? body.error : undefined;\n if (!response.ok) {\n if (said !== undefined && /not found|pull/i.test(said))\n throw new Error(\n `the model ${model} is not in Ollama: ollama pull ${model} (Ollama said: ${said})`,\n );\n if (response.status === 404)\n throw new Error(\n `the server at ${url.origin} has no /api/embed: update Ollama to version 0.3.0 or later`,\n );\n if (said !== undefined && /embed/i.test(said))\n throw new Error(\n `the model ${model} does not make embeddings: use an embedding model, such as nomic-embed-text (Ollama said: ${said})`,\n );\n throw new Error(\n `Ollama answered ${String(response.status)}${said === undefined ? \"\" : `: ${said}`}`,\n );\n }\n const embeddings = body?.embeddings;\n if (\n !Array.isArray(embeddings) ||\n embeddings.length !== input.length ||\n !embeddings.every((vector) => Array.isArray(vector))\n ) {\n throw new Error(\n `Ollama gave no embedding for each text (${String(input.length)} texts): its answer is not the answer of /api/embed`,\n );\n }\n return embeddings as number[][];\n };\n\n return {\n id: `ollama:${model}${custom}`,\n get dimensions() {\n return dimensions;\n },\n maxInputTokens,\n async embed(texts: readonly string[], call: EmbedCallOptions = {}): Promise<Float32Array[]> {\n const prefix = call.purpose === \"query\" ? queryPrefix : documentPrefix;\n const out: Float32Array[] = [];\n for (let at = 0; at < texts.length; at += batch) {\n call.signal?.throwIfAborted();\n const part = texts.slice(at, at + batch).map((text) => `${prefix}${text}`);\n for (const vector of await request(part, call.signal)) {\n if (dimensions === 0) dimensions = vector.length;\n if (vector.length !== dimensions) {\n throw new Error(\n `the model ${model} gave a vector of ${String(vector.length)} dimensions, not ${String(dimensions)}`,\n );\n }\n out.push(Float32Array.from(vector));\n }\n }\n return out;\n },\n };\n};\n"],"mappings":";;;;;;;;;;AAuBA,MAAa,gBAA0D;CACrE,oBAAoB;EAClB,YAAY;EACZ,gBAAgB;EAChB,aAAa;EACb,gBAAg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,4FAA4F,KAAK,EACtH;GACF,MAAM,IAAI,MACR,mBAAmB,OAAO,SAAS,MAAM,IAAI,SAAS,KAAA,IAAY,KAAK,KAAK,QAC9E;EACF;EACA,MAAM,aAAa,MAAM;EACzB,IACE,CAAC,MAAM,QAAQ,UAAU,KACzB,WAAW,WAAW,MAAM,UAC5B,CAAC,WAAW,OAAO,WAAW,MAAM,QAAQ,MAAM,CAAC,GAEnD,MAAM,IAAI,MACR,2CAA2C,OAAO,MAAM,MAAM,EAAE,oDAClE;EAEF,OAAO;CACT;CAEA,OAAO;EACL,IAAI,UAAU,QAAQ;EACtB,IAAI,aAAa;GACf,OAAO;EACT;EACA;EACA,MAAM,MAAM,OAA0B,OAAyB,CAAC,GAA4B;GAC1F,MAAM,SAAS,KAAK,YAAY,UAAU,cAAc;GACxD,MAAM,MAAsB,CAAC;GAC7B,KAAK,IAAI,KAAK,GAAG,KAAK,MAAM,QAAQ,MAAM,OAAO;IAC/C,KAAK,QAAQ,eAAe;IAC5B,MAAM,OAAO,MAAM,MAAM,IAAI,KAAK,KAAK,CAAC,CAAC,KAAK,SAAS,GAAG,SAAS,MAAM;IACzE,KAAK,MAAM,UAAU,MAAM,QAAQ,MAAM,KAAK,MAAM,GAAG;KACrD,IAAI,eAAe,GAAG,aAAa,OAAO;KAC1C,IAAI,OAAO,WAAW,YACpB,MAAM,IAAI,MACR,aAAa,MAAM,oBAAoB,OAAO,OAAO,MAAM,EAAE,mBAAmB,OAAO,UAAU,GACnG;KAEF,IAAI,KAAK,aAAa,KAAK,MAAM,CAAC;IACpC;GACF;GACA,OAAO;EACT;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"ollama-BDZjLDOK.mjs","names":[],"sources":["../src/ollama.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { EmbedCallOptions, Embedder } from \"./embed.ts\";\n\n/**\n * The Ollama embedder sends texts to the local HTTP API of Ollama (`POST /api/embed`). The package\n * has no dependency for it: you install Ollama, start it (`ollama serve`) and pull a model\n * (`ollama pull nomic-embed-text`).\n *\n * The page text goes to the Ollama server. Thus the embedder accepts only a server on this\n * computer (a loopback address), unless `allowRemote` is true.\n */\n\n/** These are the facts of the embedding models that the Ollama library has. */\nexport interface EmbeddingModel {\n readonly dimensions: number;\n readonly maxInputTokens: number;\n /** This prefix goes before the text of a question. */\n readonly queryPrefix?: string | undefined;\n /** This prefix goes before each chunk of a stored text. */\n readonly documentPrefix?: string | undefined;\n}\n\n/** These are the facts of three embedding models of Ollama. The name has no tag (`nomic-embed-text`, not `nomic-embed-text:latest`). */\nexport const OLLAMA_MODELS: Readonly<Record<string, EmbeddingModel>> = {\n \"nomic-embed-text\": {\n dimensions: 768,\n maxInputTokens: 8192,\n queryPrefix: \"search_query: \",\n documentPrefix: \"search_document: \",\n },\n \"all-minilm\": { dimensions: 384, maxInputTokens: 256 },\n \"mxbai-embed-large\": {\n dimensions: 1024,\n maxInputTokens: 512,\n queryPrefix: \"Represent this sentence for searching relevant passages: \",\n },\n};\n\n/** These options make an Ollama embedder. */\nexport interface OllamaEmbedderOptions {\n /** This value is the model of Ollama, with a tag when you want one. The default is `nomic-embed-text`. */\n readonly model?: string | undefined;\n /** This URL is the Ollama server. The default is `http://127.0.0.1:11434`. */\n readonly baseUrl?: string | undefined;\n /** This value is the number of texts in one request. The default is 32. */\n readonly batch?: number | undefined;\n /**\n * The value true lets `baseUrl` be a server on a different computer. The default is false,\n * because the embedder sends the text of the stored pages to the server.\n */\n readonly allowRemote?: boolean | undefined;\n /** This value is the length of each vector. The default comes from `OLLAMA_MODELS`, or from the first answer. */\n readonly dimensions?: number | undefined;\n /** This value is the input limit of the model in tokens. The default comes from `OLLAMA_MODELS`, or it is 256. */\n readonly maxInputTokens?: number | undefined;\n /** This prefix goes before the text of a question. The default comes from `OLLAMA_MODELS`. */\n readonly queryPrefix?: string | undefined;\n /** This prefix goes before each chunk of a stored text. The default comes from `OLLAMA_MODELS`. */\n readonly documentPrefix?: string | undefined;\n /** This value is the longest time of one request in milliseconds. The default is 2 minutes, because the first request loads the model. */\n readonly timeoutMs?: number | undefined;\n}\n\n/** The text of the error when no Ollama server answers. */\nexport const NO_OLLAMA =\n \"Ollama does not answer: install it from https://ollama.com, then start it with ollama serve\";\n\n/**\n * This function tells if a host name is a loopback address: `localhost`, `127.0.0.0/8` or `::1`.\n *\n * @beta\n */\nexport const isLoopback = (host: string): boolean => {\n const name = host.replace(/^\\[|\\]$/g, \"\").toLowerCase();\n return (\n name === \"localhost\" ||\n name.endsWith(\".localhost\") ||\n name === \"::1\" ||\n /^127(?:\\.\\d{1,3}){3}$/.test(name) ||\n /^::ffff:127(?:\\.\\d{1,3}){3}$/.test(name)\n );\n};\n\n/** This function gives the name of a model with no tag, for `OLLAMA_MODELS`. */\nconst baseName = (model: string): string => {\n const slash = model.lastIndexOf(\"/\");\n const colon = model.indexOf(\":\", slash + 1);\n return colon === -1 ? model : model.slice(0, colon);\n};\n\nconst messageOf = (error: unknown): string =>\n error instanceof Error ? error.message : String(error);\n\n/** This function gives the code of a network error, also when it is the cause of the error of `fetch`. */\nconst codeOf = (error: unknown): string | undefined => {\n for (\n let at: unknown = error, depth = 0;\n at !== undefined && at !== null && depth < 4;\n depth += 1\n ) {\n const code = (at as { code?: unknown }).code;\n if (typeof code === \"string\") return code;\n at = (at as { cause?: unknown }).cause;\n }\n return undefined;\n};\n\nconst NETWORK = new Set([\n \"ECONNREFUSED\",\n \"ECONNRESET\",\n \"ENOTFOUND\",\n \"EHOSTUNREACH\",\n \"ENETUNREACH\",\n \"EAI_AGAIN\",\n \"UND_ERR_SOCKET\",\n \"UND_ERR_CONNECT_TIMEOUT\",\n]);\n\n/**\n * This function makes an embedder that sends texts to Ollama (`POST {baseUrl}/api/embed`). It\n * sends `batch` texts in each request, and it stops when the signal aborts. The errors tell what\n * to do: `ollama serve` when no server answers, and `ollama pull <model>` when the model is not\n * there. A `baseUrl` on a different computer throws a `RangeError`, unless `allowRemote` is true.\n */\nexport const ollamaEmbedder = (options: OllamaEmbedderOptions = {}): Embedder => {\n const model = options.model ?? \"nomic-embed-text\";\n if (model.trim() === \"\") throw new RangeError(\"the Ollama model must have a name\");\n const base = options.baseUrl ?? \"http://127.0.0.1:11434\";\n let url: URL;\n try {\n url = new URL(base);\n } catch (cause) {\n throw new RangeError(`the Ollama URL ${base} is not a URL`, { cause });\n }\n if (url.protocol !== \"http:\" && url.protocol !== \"https:\")\n throw new RangeError(`the Ollama URL ${base} must be an http or https URL`);\n if (url.username !== \"\" || url.password !== \"\")\n throw new RangeError(\"the Ollama URL must not hold a user name or a password\");\n if (!isLoopback(url.hostname) && options.allowRemote !== true) {\n throw new RangeError(\n `the Ollama URL ${url.origin} is not on this computer, and the embedder sends the text of the stored pages to it: give allowRemote: true (--allow-remote-ollama) to permit it`,\n );\n }\n const endpoint = new URL(\"api/embed\", url.href.endsWith(\"/\") ? url.href : `${url.href}/`).href;\n const known = OLLAMA_MODELS[baseName(model)];\n const batch = Math.max(1, Math.floor(options.batch ?? 32));\n const timeoutMs = Math.max(1, Math.floor(options.timeoutMs ?? 120_000));\n const queryPrefix = options.queryPrefix ?? known?.queryPrefix ?? \"\";\n const documentPrefix = options.documentPrefix ?? known?.documentPrefix ?? \"\";\n // a document prefix of your own changes each stored vector, so it changes the id\n const custom =\n options.documentPrefix !== undefined && options.documentPrefix !== (known?.documentPrefix ?? \"\")\n ? `#${createHash(\"sha256\").update(options.documentPrefix).digest(\"hex\").slice(0, 8)}`\n : \"\";\n let dimensions = options.dimensions ?? known?.dimensions ?? 0;\n const maxInputTokens = options.maxInputTokens ?? known?.maxInputTokens ?? 256;\n\n const request = async (\n input: readonly string[],\n signal: AbortSignal | undefined,\n ): Promise<number[][]> => {\n const timeout = AbortSignal.timeout(timeoutMs);\n const both = signal === undefined ? timeout : AbortSignal.any([signal, timeout]);\n let response: Response;\n try {\n response = await fetch(endpoint, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ model, input, truncate: true }),\n signal: both,\n });\n } catch (error) {\n if (signal?.aborted === true) throw signal.reason;\n if (timeout.aborted)\n throw new Error(`Ollama at ${url.origin} did not answer in ${String(timeoutMs)} ms`, {\n cause: error,\n });\n const code = codeOf(error);\n if (code !== undefined && NETWORK.has(code))\n throw new Error(`${NO_OLLAMA} (no answer at ${url.origin}: ${code})`, { cause: error });\n // fetch says only \"fetch failed\": the cause tells why\n const cause = (error as { cause?: unknown }).cause;\n throw new Error(\n `the request to Ollama at ${url.origin} failed: ${messageOf(error)}${cause === undefined ? \"\" : ` (${messageOf(cause)})`}`,\n { cause: error },\n );\n }\n let text: string;\n try {\n text = await response.text();\n } catch (error) {\n if (signal?.aborted === true) throw signal.reason;\n throw new Error(`the answer of Ollama at ${url.origin} stopped: ${messageOf(error)}`, {\n cause: error,\n });\n }\n let body: { embeddings?: unknown; error?: unknown } | undefined;\n try {\n body = JSON.parse(text) as { embeddings?: unknown; error?: unknown };\n } catch {\n body = undefined;\n }\n const said = typeof body?.error === \"string\" ? body.error : undefined;\n if (!response.ok) {\n if (said !== undefined && /not found|pull/i.test(said))\n throw new Error(\n `the model ${model} is not in Ollama: ollama pull ${model} (Ollama said: ${said})`,\n );\n if (response.status === 404)\n throw new Error(\n `the server at ${url.origin} has no /api/embed: update Ollama to version 0.3.0 or later`,\n );\n if (said !== undefined && /embed/i.test(said))\n throw new Error(\n `the model ${model} does not make embeddings: use an embedding model, such as nomic-embed-text (Ollama said: ${said})`,\n );\n throw new Error(\n `Ollama answered ${String(response.status)}${said === undefined ? \"\" : `: ${said}`}`,\n );\n }\n const embeddings = body?.embeddings;\n if (\n !Array.isArray(embeddings) ||\n embeddings.length !== input.length ||\n !embeddings.every((vector) => Array.isArray(vector))\n ) {\n throw new Error(\n `Ollama gave no embedding for each text (${String(input.length)} texts): its answer is not the answer of /api/embed`,\n );\n }\n return embeddings as number[][];\n };\n\n return {\n id: `ollama:${model}${custom}`,\n get dimensions() {\n return dimensions;\n },\n maxInputTokens,\n async embed(texts: readonly string[], call: EmbedCallOptions = {}): Promise<Float32Array[]> {\n const prefix = call.purpose === \"query\" ? queryPrefix : documentPrefix;\n const out: Float32Array[] = [];\n for (let at = 0; at < texts.length; at += batch) {\n call.signal?.throwIfAborted();\n const part = texts.slice(at, at + batch).map((text) => `${prefix}${text}`);\n for (const vector of await request(part, call.signal)) {\n if (dimensions === 0) dimensions = vector.length;\n if (vector.length !== dimensions) {\n throw new Error(\n `the model ${model} gave a vector of ${String(vector.length)} dimensions, not ${String(dimensions)}`,\n );\n }\n out.push(Float32Array.from(vector));\n }\n }\n return out;\n },\n };\n};\n"],"mappings":";;;;;AAuBA,MAAa,gBAA0D;CACrE,oBAAoB;EAClB,YAAY;EACZ,gBAAgB;EAChB,aAAa;EACb,gBAAgB;CAClB;CACA,cAAc;EAAE,YAAY;EAAK,gBAAgB;CAAI;CACrD,qBAAqB;EACnB,YAAY;EACZ,gBAAgB;EAChB,aAAa;CACf;AACF;;AA4BA,MAAa,YACX;;;;;;AAOF,MAAa,cAAc,SAA0B;CACnD,MAAM,OAAO,KAAK,QAAQ,YAAY,EAAE,CAAC,CAAC,YAAY;CACtD,OACE,SAAS,eACT,KAAK,SAAS,YAAY,KAC1B,SAAS,SACT,wBAAwB,KAAK,IAAI,KACjC,+BAA+B,KAAK,IAAI;AAE5C;;AAGA,MAAM,YAAY,UAA0B;CAC1C,MAAM,QAAQ,MAAM,YAAY,GAAG;CACnC,MAAM,QAAQ,MAAM,QAAQ,KAAK,QAAQ,CAAC;CAC1C,OAAO,UAAU,KAAK,QAAQ,MAAM,MAAM,GAAG,KAAK;AACpD;AAEA,MAAM,aAAa,UACjB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;;AAGvD,MAAM,UAAU,UAAuC;CACrD,KACE,IAAI,KAAc,OAAO,QAAQ,GACjC,OAAO,KAAA,KAAa,OAAO,QAAQ,QAAQ,GAC3C,SAAS,GACT;EACA,MAAM,OAAQ,GAA0B;EACxC,IAAI,OAAO,SAAS,UAAU,OAA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;KACrD,IAAI,eAAe,GAAG,aAAa,OAAO;KAC1C,IAAI,OAAO,WAAW,YACpB,MAAM,IAAI,MACR,aAAa,MAAM,oBAAoB,OAAO,OAAO,MAAM,EAAE,mBAAmB,OAAO,UAAU,GACnG;KAEF,IAAI,KAAK,aAAa,KAAK,MAAM,CAAC;IACpC;GACF;GACA,OAAO;EACT;CACF;AACF"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime-
|
|
2
|
-
import {
|
|
3
|
-
import { r as
|
|
4
|
-
import {
|
|
5
|
-
import { i as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-BJohB4LM.mjs";
|
|
2
|
+
import { r as checkedRenderer } from "./browser-Cp5W-dmj.mjs";
|
|
3
|
+
import { i as durationMs, n as DEFAULT_TOKEN, r as VERSION, t as BOT_PAGE } from "./version-hVv3n9O6.mjs";
|
|
4
|
+
import { n as FileBlobStore, t as CaptureLog } from "./log-CB5bADmd.mjs";
|
|
5
|
+
import { A as DEADLINE_NOTE, C as fold, D as snippetOf, E as parseQuery, N as sha256$1, P as stableStringify, a as fetchPage, c as isHeldBack, f as reindex, i as fetchAndIndex, k as Crawler, l as isoTime, o as findDocuments, p as verifyQuote, r as catchUpIndex, t as Extractors, u as readDocument, y as archivedOf } from "./runtime-NyweI69B.mjs";
|
|
6
|
+
import { n as diffDocument, r as diffTexts } from "./diff-ChsL3yux.mjs";
|
|
7
|
+
import { o as decodeBody, t as extractPage } from "./html-CawWTgMQ.mjs";
|
|
8
|
+
import { cacheKeyOf, canonicalUrl, scopeTest } from "./urls.mjs";
|
|
9
|
+
import { r as extractDocument } from "./extract-DO-NFOmF.mjs";
|
|
8
10
|
import { matchesPattern } from "./robots.mjs";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { r as extractDocument } from "./extract-BISJyKWN.mjs";
|
|
13
|
-
import { o as registerRecipe } from "./recipe-30dN3orz.mjs";
|
|
11
|
+
import { MemoryHostStateStore, nextValidatorMemo, realClock } from "./politeness.mjs";
|
|
12
|
+
import { r as playwrightRenderer } from "./render-CZaqvjQh.mjs";
|
|
13
|
+
import { o as registerRecipe } from "./recipe-BsGOZJyi.mjs";
|
|
14
14
|
import { createHash, randomUUID } from "node:crypto";
|
|
15
15
|
import { dirname, join } from "node:path";
|
|
16
16
|
import { existsSync, lstatSync, mkdirSync, realpathSync, statSync } from "node:fs";
|
|
@@ -817,8 +817,7 @@ var DocIndex = class {
|
|
|
817
817
|
this.db.close();
|
|
818
818
|
}
|
|
819
819
|
};
|
|
820
|
-
|
|
821
|
-
//#region src/sitemaps.ts
|
|
820
|
+
// src/sitemaps.ts
|
|
822
821
|
/**
|
|
823
822
|
* These are the default limits of the reader, and the maximum length of one value.
|
|
824
823
|
*
|
|
@@ -1320,8 +1319,7 @@ const scanSitemap = (text, base, limits = {}, meter = { steps: 0 }) => {
|
|
|
1320
1319
|
* @beta
|
|
1321
1320
|
*/
|
|
1322
1321
|
const readSitemap = (text, base, limits) => scanSitemap(text, base, limits);
|
|
1323
|
-
|
|
1324
|
-
//#region src/discover.ts
|
|
1322
|
+
// src/discover.ts
|
|
1325
1323
|
/**
|
|
1326
1324
|
* Discovery finds the pages of a site from its sitemaps and its feeds. Each file is a fetch of the
|
|
1327
1325
|
* crawler, so each polite rule applies to it. These rules are robots.txt, one request at a time for
|
|
@@ -1728,8 +1726,7 @@ const discoverSite = async (runtime, site, options = {}) => {
|
|
|
1728
1726
|
if (stopped === void 0 && urls.size >= maxUrls) stopped = "max-urls";
|
|
1729
1727
|
return result();
|
|
1730
1728
|
};
|
|
1731
|
-
|
|
1732
|
-
//#region src/frontier.ts
|
|
1729
|
+
// src/frontier.ts
|
|
1733
1730
|
/**
|
|
1734
1731
|
* The frontier is a small crawl of a site. It starts at the seeds. It follows the links of each page
|
|
1735
1732
|
* that it fetched, to a maximum of pages, a maximum depth and a maximum time.
|
|
@@ -2162,8 +2159,7 @@ const crawlSite = (runtime, seeds, options = {}) => {
|
|
|
2162
2159
|
}
|
|
2163
2160
|
};
|
|
2164
2161
|
};
|
|
2165
|
-
|
|
2166
|
-
//#region src/hoststate.ts
|
|
2162
|
+
// src/hoststate.ts
|
|
2167
2163
|
/** A stop with no end goes into the table as this value, which is past each date that JavaScript can hold. */
|
|
2168
2164
|
const NO_END = 9e15;
|
|
2169
2165
|
/** A process that shares the store asks again after this wait, at most, during the lease of a different process. */
|
|
@@ -2376,8 +2372,7 @@ var SqliteHostStateStore = class {
|
|
|
2376
2372
|
this.db.close();
|
|
2377
2373
|
}
|
|
2378
2374
|
};
|
|
2379
|
-
|
|
2380
|
-
//#region src/embed.ts
|
|
2375
|
+
// src/embed.ts
|
|
2381
2376
|
/**
|
|
2382
2377
|
* These are the limits of the chunks of a text.
|
|
2383
2378
|
*
|
|
@@ -2663,8 +2658,7 @@ const fuseRanks = (lists, k = HYBRID_DEFAULTS.fusionK) => {
|
|
|
2663
2658
|
ranks: entry
|
|
2664
2659
|
}));
|
|
2665
2660
|
};
|
|
2666
|
-
|
|
2667
|
-
//#region src/hybrid.ts
|
|
2661
|
+
// src/hybrid.ts
|
|
2668
2662
|
/** The embedder gets this number of texts in one call at most. */
|
|
2669
2663
|
const BATCH = 32;
|
|
2670
2664
|
/** The search keeps the vectors of this number of questions. */
|
|
@@ -3067,8 +3061,7 @@ async function* pagesOf(runtime) {
|
|
|
3067
3061
|
}
|
|
3068
3062
|
if (page.length > 0) yield page;
|
|
3069
3063
|
}
|
|
3070
|
-
|
|
3071
|
-
//#region src/vectors.ts
|
|
3064
|
+
// src/vectors.ts
|
|
3072
3065
|
/**
|
|
3073
3066
|
* The vector store keeps the vectors of hybrid search in `vectors.sqlite`, beside the index. It is
|
|
3074
3067
|
* a projection, as the index is. Delete the file, and the next hybrid search or `embed` makes the
|
|
@@ -3450,8 +3443,7 @@ var VectorStore = class {
|
|
|
3450
3443
|
this.db.close();
|
|
3451
3444
|
}
|
|
3452
3445
|
};
|
|
3453
|
-
|
|
3454
|
-
//#region src/watch.ts
|
|
3446
|
+
// src/watch.ts
|
|
3455
3447
|
/**
|
|
3456
3448
|
* A watch list keeps the pages that the crawler checks again on a schedule. `watch.run` fetches the
|
|
3457
3449
|
* pages that are due through the normal fetch, so each polite rule applies. It gives an event for
|
|
@@ -4046,16 +4038,8 @@ const runWatch = (runtime, source, options = {}) => {
|
|
|
4046
4038
|
}
|
|
4047
4039
|
};
|
|
4048
4040
|
};
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
var open_exports = /* @__PURE__ */ __exportAll({
|
|
4052
|
-
BOT_PAGE: () => BOT_PAGE,
|
|
4053
|
-
DEFAULT_TOKEN: () => DEFAULT_TOKEN,
|
|
4054
|
-
createRuntime: () => createRuntime,
|
|
4055
|
-
defaultUserAgent: () => defaultUserAgent,
|
|
4056
|
-
isMailbox: () => isMailbox,
|
|
4057
|
-
openCrawler: () => openCrawler
|
|
4058
|
-
});
|
|
4041
|
+
// src/open.ts
|
|
4042
|
+
var open_exports = /* @__PURE__ */ __exportAll({ openCrawler: () => openCrawler });
|
|
4059
4043
|
/**
|
|
4060
4044
|
* This function gives the default `User-Agent` header. The header names the crawler, its version
|
|
4061
4045
|
* and the page about it, so a site owner can find out what made each request.
|
|
@@ -4353,7 +4337,6 @@ const openCrawler = (options) => {
|
|
|
4353
4337
|
}
|
|
4354
4338
|
};
|
|
4355
4339
|
};
|
|
4356
|
-
//#endregion
|
|
4357
4340
|
export { NO_EMBEDDER as A, DISCOVER_LIMITS as C, readSitemap as D, feedDate as E, DocIndex as O, crawlSite as S, SITEMAP_LIMITS as T, estimateTokens as _, open_exports as a, SqliteHostStateStore as b, WatchStore as c, VectorStore as d, createHybridSearch as f, chunkTokensOf as g, chunkText as h, openCrawler as i, FAST_RANK_SHARE as k, runWatch as l, HYBRID_DEFAULTS as m, defaultUserAgent as n, WATCH_LIMITS as o, CHUNK_LIMITS as p, isMailbox as r, WATCH_SCHEMA as s, createRuntime as t, VECTORS_SCHEMA as u, fuseRanks as v, discoverSite as w, CRAWL_LIMITS as x, unitVector as y };
|
|
4358
4341
|
|
|
4359
|
-
//# sourceMappingURL=open-
|
|
4342
|
+
//# sourceMappingURL=open-DOgE033K.mjs.map
|