@sisu-ai/tool-extract-urls 2.0.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 ADDED
@@ -0,0 +1,34 @@
1
+ # @sisu-ai/tool-extract-urls
2
+
3
+ Extract unique `http`/`https` URLs from text snippets. Small, deterministic, and zero I/O — great as a first pass before fetching, classifying, or summarizing pages.
4
+
5
+ ## Install
6
+ ```bash
7
+ npm i @sisu-ai/tool-extract-urls
8
+ ```
9
+
10
+ ## Why it’s useful
11
+ - Simple guardrail: avoids asking the model to spot links.
12
+ - Deterministic: same inputs → same outputs.
13
+ - Lightweight: no network calls, safe to run early in a pipeline.
14
+
15
+ ## Usage
16
+ ```ts
17
+ import { Agent, SimpleTools } from '@sisu-ai/core';
18
+ import { registerTools } from '@sisu-ai/mw-register-tools';
19
+ import { toolCalling } from '@sisu-ai/mw-tool-calling';
20
+ import { extractUrlsTool } from '@sisu-ai/tool-extract-urls';
21
+
22
+ const app = new Agent()
23
+ .use(registerTools([extractUrlsTool]))
24
+ .use(toolCalling);
25
+
26
+ // Prompt example: "Find links in: https://example.com and http://sisu.ai"
27
+ ```
28
+
29
+ ## What it returns
30
+ - Array of unique URLs, e.g. `["https://example.com", "http://sisu.ai"]`.
31
+
32
+ ## Notes
33
+ - The regex targets `http`/`https` URLs and ignores surrounding punctuation where possible.
34
+ - Prefer pairing with a fetch tool (e.g., `@sisu-ai/tool-web-fetch`) for subsequent content analysis.
@@ -0,0 +1,18 @@
1
+ import type { Tool } from '@sisu-ai/core';
2
+ /**
3
+ * Extract all unique URLs from an array of strings.
4
+ *
5
+ * @param contents - Array of strings to scan for URLs.
6
+ * @returns Array of unique URLs found in the contents.
7
+ */
8
+ export declare function extractUrls(contents: string[]): string[];
9
+ /**
10
+ * Tool definition wrapping {@link extractUrls} for use with agents.
11
+ */
12
+ export declare const extractUrlsTool: Tool<{
13
+ contents: string[];
14
+ }>;
15
+ declare const _default: Tool<{
16
+ contents: string[];
17
+ }, unknown>[];
18
+ export default _default;
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Extract all unique URLs from an array of strings.
4
+ *
5
+ * @param contents - Array of strings to scan for URLs.
6
+ * @returns Array of unique URLs found in the contents.
7
+ */
8
+ export function extractUrls(contents) {
9
+ const urlRe = /https?:\/\/[\S)\]"'>]+/gi;
10
+ const out = new Set();
11
+ for (const c of contents)
12
+ for (const m of c.matchAll(urlRe))
13
+ out.add(m[0]);
14
+ return Array.from(out);
15
+ }
16
+ /**
17
+ * Tool definition wrapping {@link extractUrls} for use with agents.
18
+ */
19
+ export const extractUrlsTool = {
20
+ name: 'extractUrls',
21
+ description: 'Extract unique HTTP/HTTPS URLs from provided text snippets.',
22
+ schema: z.object({ contents: z.array(z.string()) }),
23
+ handler: async ({ contents }) => extractUrls(contents),
24
+ };
25
+ export default [extractUrlsTool];
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@sisu-ai/tool-extract-urls",
3
+ "version": "2.0.0",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc -b"
12
+ },
13
+ "dependencies": {
14
+ "zod": "^3.23.8"
15
+ },
16
+ "peerDependencies": {
17
+ "@sisu-ai/core": "0.3.0"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/finger-gun/sisu",
22
+ "directory": "packages/tools/extract-urls"
23
+ },
24
+ "homepage": "https://github.com/finger-gun/sisu#readme",
25
+ "bugs": {
26
+ "url": "https://github.com/finger-gun/sisu/issues"
27
+ }
28
+ }