polite-crawler 0.1.2 → 0.1.4

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 (46) hide show
  1. package/README.md +555 -8
  2. package/build/cli-daemon-ZYRdy6EW.mjs +38 -0
  3. package/build/cli-daemon-ZYRdy6EW.mjs.map +1 -0
  4. package/build/cli-recipes-Bci6HREA.mjs +59 -0
  5. package/build/cli-recipes-Bci6HREA.mjs.map +1 -0
  6. package/build/cli.mjs +673 -26
  7. package/build/cli.mjs.map +1 -1
  8. package/build/daemon-DK6U51_v.mjs +515 -0
  9. package/build/daemon-DK6U51_v.mjs.map +1 -0
  10. package/build/{open-Ca1lcWR3.d.mts → daemon-wwIWsUmU.d.mts} +919 -17
  11. package/build/{diff-Dk2eSvi-.mjs → diff-BUM91Rev.mjs} +2 -2
  12. package/build/{diff-Dk2eSvi-.mjs.map → diff-BUM91Rev.mjs.map} +1 -1
  13. package/build/{extract-DcwNrTK7.mjs → extract-CefB5Vfn.mjs} +2 -2
  14. package/build/{extract-DcwNrTK7.mjs.map → extract-CefB5Vfn.mjs.map} +1 -1
  15. package/build/hours.d.mts +26 -0
  16. package/build/hours.mjs +48 -1
  17. package/build/hours.mjs.map +1 -1
  18. package/build/index.d.mts +491 -11
  19. package/build/index.mjs +14 -9
  20. package/build/loopback-C_QYowSf.mjs +22 -0
  21. package/build/loopback-C_QYowSf.mjs.map +1 -0
  22. package/build/mcp.d.mts +158 -2
  23. package/build/mcp.mjs +567 -18
  24. package/build/mcp.mjs.map +1 -1
  25. package/build/ollama-BJxkjny4.mjs +160 -0
  26. package/build/ollama-BJxkjny4.mjs.map +1 -0
  27. package/build/{open-DnrWgkC0.mjs → open-CbpSCEZc.mjs} +1127 -16
  28. package/build/open-CbpSCEZc.mjs.map +1 -0
  29. package/build/recipe-GiFQojmo.mjs +279 -0
  30. package/build/recipe-GiFQojmo.mjs.map +1 -0
  31. package/build/recipe-product-Dellqudu.mjs +892 -0
  32. package/build/recipe-product-Dellqudu.mjs.map +1 -0
  33. package/build/{runtime-k8mo1_7U.mjs → runtime-D_r2SYge.mjs} +3 -3
  34. package/build/{runtime-k8mo1_7U.mjs.map → runtime-D_r2SYge.mjs.map} +1 -1
  35. package/build/transformers-BQMlaGj4.mjs +133 -0
  36. package/build/transformers-BQMlaGj4.mjs.map +1 -0
  37. package/build/{duration-iIuMMofi.mjs → version-BPem-XZd.mjs} +10 -10
  38. package/build/version-BPem-XZd.mjs.map +1 -0
  39. package/build/{wacz-sfOLT8e9.mjs → wacz-QyzLp4mC.mjs} +3 -3
  40. package/build/{wacz-sfOLT8e9.mjs.map → wacz-QyzLp4mC.mjs.map} +1 -1
  41. package/build/{warc-VIPscWxY.mjs → warc-BHcaRKHw.mjs} +2 -2
  42. package/build/{warc-VIPscWxY.mjs.map → warc-BHcaRKHw.mjs.map} +1 -1
  43. package/build/webbotauth-CjJdTAfE.mjs.map +1 -1
  44. package/package.json +10 -2
  45. package/build/duration-iIuMMofi.mjs.map +0 -1
  46. package/build/open-DnrWgkC0.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loopback-C_QYowSf.mjs","names":[],"sources":["../src/loopback.ts"],"sourcesContent":["import { isIP } from \"node:net\";\n\n/**\n * This function tells if a host name or an address is a loopback host: `localhost`, an address in\n * `127.0.0.0/8`, or `::1`. The MCP server over HTTP binds to a loopback host unless the operator\n * permits a different host. The function imports only Node.js, so the command line uses it before\n * the store opens.\n */\nexport const isLoopbackHost = (host: string): boolean => {\n const name = host\n .trim()\n .toLowerCase()\n .replace(/^\\[(.*)\\]$/, \"$1\");\n if (name === \"localhost\" || name.endsWith(\".localhost\")) return true;\n const mapped = name.startsWith(\"::ffff:\") ? name.slice(7) : name;\n if (isIP(mapped) === 4) return mapped.startsWith(\"127.\");\n if (isIP(name) === 6) return /^(?:0{0,4}:){7}0{0,3}1$|^::1$/.test(name);\n return false;\n};\n\n/** This function gives a host for a URL: an IPv6 address goes in brackets. */\nexport const urlHost = (host: string): string => (isIP(host) === 6 ? `[${host}]` : host);\n"],"mappings":";;;;;;;;AAQA,MAAa,kBAAkB,SAA0B;CACvD,MAAM,OAAO,KACV,KAAK,CAAC,CACN,YAAY,CAAC,CACb,QAAQ,cAAc,IAAI;CAC7B,IAAI,SAAS,eAAe,KAAK,SAAS,YAAY,GAAG,OAAO;CAChE,MAAM,SAAS,KAAK,WAAW,SAAS,IAAI,KAAK,MAAM,CAAC,IAAI;CAC5D,IAAI,KAAK,MAAM,MAAM,GAAG,OAAO,OAAO,WAAW,MAAM;CACvD,IAAI,KAAK,IAAI,MAAM,GAAG,OAAO,gCAAgC,KAAK,IAAI;CACtE,OAAO;AACT;;AAGA,MAAa,WAAW,SAA0B,KAAK,IAAI,MAAM,IAAI,IAAI,KAAK,KAAK"}
package/build/mcp.d.mts CHANGED
@@ -1,5 +1,141 @@
1
- import { a as PoliteCrawler, r as OpenOptions } from "./open-Ca1lcWR3.mjs";
1
+ import { E as OpenOptions, O as PoliteCrawler, s as DaemonMcpHost } from "./daemon-wwIWsUmU.mjs";
2
2
  import { McpServer, McpServer as McpServer$1 } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+ import { Request, RequestId, Result, Task } from "@modelcontextprotocol/sdk/types.js";
4
+ import { CreateTaskOptions, TaskStore } from "@modelcontextprotocol/sdk/experimental/tasks/interfaces.js";
5
+ import "@modelcontextprotocol/sdk/shared/protocol.js";
6
+ //#region src/mcp-tasks.d.ts
7
+ /** These are the limits of the tasks of one MCP server. */
8
+ export declare const TASK_LIMITS: {
9
+ /** A task and its result stay for this time after the task starts or ends: 1 hour by default. */
10
+ readonly ttlMs: 3_600_000;
11
+ /** The longest time that a client can ask for: 1 day. */
12
+ readonly maxTtlMs: 86_400_000;
13
+ /** The time that the server proposes between two polls of the status: 1 second. */
14
+ readonly pollMs: 1_000;
15
+ /** The most tasks that run at one time. A new task above the limit is an error. */
16
+ readonly maxRunning: 8;
17
+ };
18
+ /** This is a task of the server, as the status of the daemon shows it. */
19
+ interface TaskInfo {
20
+ /** This id is the task id that the client got. */
21
+ readonly id: string;
22
+ /** This value is the name of the tool, for example `crawl_site`. */
23
+ readonly tool: string;
24
+ /** This value is `working`, `input_required`, `completed`, `failed` or `cancelled`. */
25
+ readonly status: string;
26
+ /** This text tells the progress, for example `3 of 10 done`, or null. */
27
+ readonly message: string | null;
28
+ readonly created_at: string;
29
+ readonly updated_at: string;
30
+ }
31
+ /** These options make a task store. */
32
+ interface CrawlTaskStoreOptions {
33
+ /** This value is the most tasks that run at one time. The default is 8. */
34
+ readonly maxRunning?: number | undefined;
35
+ /** This function operates when a task starts, changes its status or ends. */
36
+ readonly onChange?: (() => void) | undefined;
37
+ }
38
+ /**
39
+ * This store keeps the tasks of the long tools in memory. It wraps the `InMemoryTaskStore` of the
40
+ * SDK, which binds each task to its session. It also keeps an abort signal for each task: the
41
+ * cancel of a task (`tasks/cancel`) aborts the work of its tool. One store serves each session of
42
+ * one server.
43
+ */
44
+ export declare class CrawlTaskStore implements TaskStore {
45
+ private readonly options;
46
+ private readonly store;
47
+ private readonly jobs;
48
+ private readonly maxRunning;
49
+ private closed;
50
+ constructor(options?: CrawlTaskStoreOptions);
51
+ private changed;
52
+ /** This method removes the jobs whose tasks the SDK store removed at the end of their time. */
53
+ private prune;
54
+ createTask(params: CreateTaskOptions, requestId: RequestId, request: Request, sessionId?: string): Promise<Task>;
55
+ getTask(taskId: string, sessionId?: string): Promise<Task | null>;
56
+ storeTaskResult(taskId: string, status: "completed" | "failed", result: Result, sessionId?: string): Promise<void>;
57
+ getTaskResult(taskId: string, sessionId?: string): Promise<Result>;
58
+ updateTaskStatus(taskId: string, status: Task["status"], statusMessage?: string, sessionId?: string): Promise<void>;
59
+ listTasks(cursor?: string, sessionId?: string): Promise<{
60
+ tasks: Task[];
61
+ nextCursor?: string;
62
+ }>;
63
+ /** This method gives the abort signal of a task. A cancel of the task aborts it. */
64
+ signal(taskId: string): AbortSignal;
65
+ /** This method gives the reason that a task did not start, or undefined for a task that started. */
66
+ refusal(taskId: string): string | undefined;
67
+ /** This method tells if the client asked for the task. False is the call of a client with no tasks. */
68
+ augmented(taskId: string): boolean;
69
+ /** This method gives the tasks that did not end, the oldest first. */
70
+ running(): TaskInfo[];
71
+ /** This method gives the sessions that have a task in progress. */
72
+ busySessions(): Set<string>;
73
+ /** This method cancels the tasks of a session that closed. Their work stops. */
74
+ cancelSession(sessionId: string, message?: string): Promise<void>;
75
+ /** This method cancels each task that runs, and removes all the tasks. A second close does nothing. */
76
+ close(): Promise<void>;
77
+ }
78
+ //#endregion
79
+ //#region src/mcp-http.d.ts
80
+ /** These are the defaults of the MCP server over HTTP. */
81
+ export declare const MCP_HTTP_DEFAULTS: {
82
+ /** The port of the server. */
83
+ readonly port: 9307;
84
+ /** The host of the server: the IPv4 loopback address. */
85
+ readonly host: "127.0.0.1";
86
+ /** The path of the MCP endpoint. */
87
+ readonly path: "/mcp";
88
+ /** The path of the status of the daemon. */
89
+ readonly statusPath: "/status";
90
+ /** The most sessions at one time. A new session above the limit closes the session that was idle longest. */
91
+ readonly maxSessions: 32;
92
+ /** The largest body of a request that starts a session: 4 MiB. */
93
+ readonly maxBodyBytes: 4_194_304;
94
+ /** The shortest token: 16 characters. */
95
+ readonly minTokenLength: 16;
96
+ };
97
+ /** These options serve MCP over HTTP. */
98
+ interface McpHttpOptions {
99
+ /** This value is the port. The default is 9307. The value 0 takes a free port. */
100
+ readonly port?: number | undefined;
101
+ /** This value is the host to bind. The default is `127.0.0.1`. A host that is not loopback needs `allowRemote`. */
102
+ readonly host?: string | undefined;
103
+ /** The value true permits a host that is not loopback. Then other computers can try the token. */
104
+ readonly allowRemote?: boolean | undefined;
105
+ /** This value is the bearer token. The default reads `tokenFile`, or makes a random token. */
106
+ readonly token?: string | undefined;
107
+ /** This file holds the bearer token, when `token` is not given. */
108
+ readonly tokenFile?: string | undefined;
109
+ /** This function gives the JSON of `GET /status`. Without it, the path gives 404. */
110
+ readonly status?: (() => unknown) | undefined;
111
+ /** This store keeps the tasks of each session. The default is a new `CrawlTaskStore`. */
112
+ readonly tasks?: CrawlTaskStore | undefined;
113
+ /** This function writes the messages of the server. The default writes nothing. */
114
+ readonly log?: ((line: string) => void) | undefined;
115
+ }
116
+ /** This is a server that serves MCP over HTTP. */
117
+ interface McpHttpServer {
118
+ /** This URL is the MCP endpoint, for example `http://127.0.0.1:9307/mcp`. */
119
+ readonly url: string;
120
+ readonly host: string;
121
+ readonly port: number;
122
+ /** This value is the bearer token. Give it to the client, and keep it secret. */
123
+ readonly token: string;
124
+ /** This store keeps the tasks of the long tools. */
125
+ readonly tasks: CrawlTaskStore;
126
+ /** This method counts the open sessions. */
127
+ sessions(): number;
128
+ /** This method closes each session, cancels each task and stops the server. A second close does nothing. */
129
+ close(): Promise<void>;
130
+ }
131
+ /**
132
+ * This function compares a token with the token of the server in constant time. It compares the
133
+ * SHA-256 digests, so the time does not depend on the length or the text of either token.
134
+ */
135
+ export declare const sameToken: (given: string, token: string) => boolean;
136
+ /** This function makes a random token: 32 bytes in base64url, 43 characters. */
137
+ export declare const makeToken: () => string;
138
+ //#endregion
3
139
  //#region src/mcp.d.ts
4
140
  /** These options change the tools of the MCP server. */
5
141
  export interface CrawlServerOptions {
@@ -16,6 +152,12 @@ export interface CrawlServerOptions {
16
152
  readonly allowUserProvided?: boolean | undefined;
17
153
  /** This text tells why the server renders no page. The result of a page that needs JavaScript shows it. */
18
154
  readonly renderOff?: string | undefined;
155
+ /**
156
+ * This store makes the long tools (`crawl_site` and `crawl_discover`) MCP tasks. A client that
157
+ * asks for a task gets a task id at once. A client with no tasks gets the result in the call. The
158
+ * server over HTTP gives the store. Without it, the long tools are normal tools.
159
+ */
160
+ readonly tasks?: CrawlTaskStore | undefined;
19
161
  }
20
162
  /** These options start the MCP server on the standard input and output. */
21
163
  export interface StartMcpOptions extends OpenOptions, CrawlServerOptions {
@@ -38,6 +180,20 @@ export declare const createMcpServer: (crawler: PoliteCrawler, options?: CrawlSe
38
180
  * The server stops when its standard input closes, or at `SIGINT` or `SIGTERM`.
39
181
  */
40
182
  export declare const startMcpServer: (options: StartMcpOptions) => Promise<void>;
183
+ /** These options serve the tools over HTTP: the options of the tools, and of the HTTP server. */
184
+ export interface StartMcpHttpOptions extends McpHttpOptions, Omit<CrawlServerOptions, "tasks"> {}
185
+ /**
186
+ * This function serves the tools of a crawler over the Streamable HTTP transport of MCP. Each
187
+ * session gets an MCP server with the nine tools of the server on the standard input and output.
188
+ * The envelope, the elicitation and the opt-ins are the same. `crawl_site` and `crawl_discover` are MCP tasks.
189
+ * Each request needs the bearer token. The function does not close the crawler.
190
+ */
191
+ export declare const startMcpHttpServer: (crawler: PoliteCrawler, options?: StartMcpHttpOptions) => Promise<McpHttpServer>;
192
+ /**
193
+ * This host serves the tools of the daemon over HTTP. It is the seam between the daemon and its MCP
194
+ * transport: a different MCP host can replace it with `DaemonOptions.mcpHost`.
195
+ */
196
+ export declare const mcpHttpHost: DaemonMcpHost;
41
197
  //#endregion
42
- export type { McpServer };
198
+ export type { CrawlTaskStoreOptions, McpHttpOptions, McpHttpServer, McpServer, TaskInfo };
43
199
  //# sourceMappingURL=mcp.d.mts.map