@surfaceapi/langchain 0.0.0-stage → 0.1.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/LICENSE +9 -0
- package/README.md +9 -2
- package/index.js +45 -0
- package/package.json +13 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Canada Site Ops
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
|
package/README.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @surfaceapi/langchain
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Surface is the link-safety layer between an AI agent and the open web. One tool, `surface_preflight`: give it a URL, get back `fetch` or `skip` plus where the link really goes (unwraps t.co, bit.ly, redirects). Free up to 1M requests/month; no key needed to start.
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
import { surface_preflight } from "@surfaceapi/langchain";
|
|
7
|
+
const agent = createReactAgent({ llm, tools: [surface_preflight] });
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Optional env: SURFACE_API_KEY, SURFACE_BASE_URL. API: https://nova-otter-delta-cloud.grok.me (MCP at /mcp). On any error the tool answers skip.
|
package/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Surface for langchain: the link-safety layer between an AI agent and the open web.
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
export const DEFAULT_BASE_URL = "https://nova-otter-delta-cloud.grok.me";
|
|
5
|
+
export const TOOL_DESCRIPTION =
|
|
6
|
+
"Check a link before you open it. Surface unwraps short links (t.co, bit.ly, lnkd.in, youtu.be), " +
|
|
7
|
+
"follows redirects, and tells you whether the destination is worth fetching ('fetch') or should be " +
|
|
8
|
+
"skipped ('skip'), plus where the link really goes. It never returns the page itself.";
|
|
9
|
+
|
|
10
|
+
const env = (k) => (typeof process !== "undefined" && process.env ? process.env[k] : undefined);
|
|
11
|
+
|
|
12
|
+
export async function preflight(url, { apiKey, baseUrl, headers, timeoutMs = 15000 } = {}) {
|
|
13
|
+
const base = (baseUrl || env("SURFACE_BASE_URL") || DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
14
|
+
const key = apiKey || env("SURFACE_API_KEY");
|
|
15
|
+
const res = await fetch(base + "/v1/preflight", {
|
|
16
|
+
method: "POST",
|
|
17
|
+
headers: {
|
|
18
|
+
"content-type": "application/json",
|
|
19
|
+
accept: "application/json",
|
|
20
|
+
"user-agent": "@surfaceapi/langchain/0.1.0",
|
|
21
|
+
...(key ? { authorization: "Bearer " + key } : {}),
|
|
22
|
+
...(headers || {}),
|
|
23
|
+
},
|
|
24
|
+
body: JSON.stringify({ url }),
|
|
25
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
26
|
+
});
|
|
27
|
+
if (!res.ok) throw new Error("Surface preflight HTTP " + res.status);
|
|
28
|
+
const d = await res.json();
|
|
29
|
+
const next = d.next || d.verdict;
|
|
30
|
+
return {
|
|
31
|
+
next, fetch: next === "fetch", url: d.url || url, final_url: d.final_url, final_host: d.final_host,
|
|
32
|
+
status: d.status, redirects: d.redirects, shortener: d.shortener, reason: d.reason,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
import { tool } from "@langchain/core/tools";
|
|
37
|
+
export function surfacePreflightTool(opts = {}) {
|
|
38
|
+
return tool(async ({ url }) => {
|
|
39
|
+
try { return JSON.stringify(await preflight(url, opts)); }
|
|
40
|
+
catch (e) { return JSON.stringify({ next: "skip", fetch: false, url, error: String(e && e.message || e) }); }
|
|
41
|
+
}, { name: "surface_preflight", description: TOOL_DESCRIPTION,
|
|
42
|
+
schema: z.object({ url: z.string().describe("The link to check before fetching it") }) });
|
|
43
|
+
}
|
|
44
|
+
export const surface_preflight = surfacePreflightTool();
|
|
45
|
+
export default surface_preflight;
|
package/package.json
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@surfaceapi/langchain",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Surface for langchain: the link-safety layer between an AI agent and the open web. One tool, surface_preflight, that answers fetch or skip without returning the page.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./index.js",
|
|
7
|
+
"files": ["index.js", "README.md", "LICENSE"],
|
|
8
|
+
"keywords": ["langchain", "ai-agents", "tools", "link-safety", "url", "preflight", "mcp", "surface"],
|
|
9
|
+
"author": "Canada Site Ops <canada.site.ops@gmail.com>",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"homepage": "https://otter-sand-wolf-spring.grok.me",
|
|
12
|
+
"peerDependencies": { "@langchain/core": ">=0.3.0", "zod": ">=3.22.0" },
|
|
13
|
+
"engines": { "node": ">=18" },
|
|
14
|
+
"publishConfig": { "access": "public" }
|
|
15
|
+
}
|