@surfaceapi/ai-sdk 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 +49 -2
- package/index.d.ts +8 -0
- package/index.js +51 -0
- package/package.json +15 -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,50 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @surfaceapi/ai-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Surface is the link-safety layer between an AI agent and the open web.** Before your agent opens a link someone pasted, Surface checks it: it unwraps short links (t.co, bit.ly, lnkd.in, youtu.be), follows the redirects, and answers **fetch** or **skip**, along with where the link really goes. It never downloads the page for you, so it's fast and cheap.
|
|
4
|
+
|
|
5
|
+
This package gives Vercel AI SDK agents that check as one ready-made tool: `surface_preflight`.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @surfaceapi/ai-sdk ai zod
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import { generateText } from "ai";
|
|
13
|
+
import { surface_preflight } from "@surfaceapi/ai-sdk";
|
|
14
|
+
|
|
15
|
+
const { text } = await generateText({
|
|
16
|
+
model,
|
|
17
|
+
tools: { surface_preflight },
|
|
18
|
+
prompt: "Summarize https://bit.ly/... if it's safe to open",
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The tool returns:
|
|
23
|
+
|
|
24
|
+
```json
|
|
25
|
+
{"next": "fetch", "fetch": true, "url": "https://youtu.be/jNQXAC9IVRw",
|
|
26
|
+
"final_url": "https://www.youtube.com/watch?v=jNQXAC9IVRw&feature=youtu.be",
|
|
27
|
+
"final_host": "youtube.com", "status": 200, "redirects": 1, "shortener": true,
|
|
28
|
+
"reason": "unwrapped youtu.be → youtube.com · alive, worth a fetch"}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Free to start
|
|
32
|
+
|
|
33
|
+
The first 1M requests a month are free. It works with no key at all (shared demo limit), or grab your own free key in one call, with no email and no card:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
curl -s -X POST https://nova-otter-delta-cloud.grok.me/v1/keys
|
|
37
|
+
export SURFACE_API_KEY=...
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
After the free tier: $0.25 USD per 1,000 preflights.
|
|
41
|
+
|
|
42
|
+
## Prefer MCP?
|
|
43
|
+
|
|
44
|
+
Point any MCP client at `https://nova-otter-delta-cloud.grok.me/mcp` (tool `preflight_url`).
|
|
45
|
+
|
|
46
|
+
- Website: https://otter-sand-wolf-spring.grok.me
|
|
47
|
+
- Docs: https://nova-otter-delta-cloud.grok.me/docs
|
|
48
|
+
- LLM reference: https://nova-otter-delta-cloud.grok.me/llms.txt
|
|
49
|
+
|
|
50
|
+
Made by Canada Site Ops. MIT licensed.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface PreflightOptions { apiKey?: string; baseUrl?: string; headers?: Record<string, string>; timeoutMs?: number; }
|
|
2
|
+
export interface PreflightResult { next: "fetch" | "skip"; fetch: boolean; url: string; final_url?: string; final_host?: string; status?: number; redirects?: number; shortener?: boolean; reason?: string; error?: string; }
|
|
3
|
+
export declare const DEFAULT_BASE_URL: string;
|
|
4
|
+
export declare const TOOL_DESCRIPTION: string;
|
|
5
|
+
export declare function preflight(url: string, opts?: PreflightOptions): Promise<PreflightResult>;
|
|
6
|
+
export declare function surfacePreflightTool(opts?: PreflightOptions): any;
|
|
7
|
+
export declare const surface_preflight: any;
|
|
8
|
+
export default surface_preflight;
|
package/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Surface for the Vercel AI SDK: the link-safety layer between an AI agent and the open web.
|
|
2
|
+
import { tool } from "ai";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
|
|
5
|
+
export const DEFAULT_BASE_URL = "https://nova-otter-delta-cloud.grok.me";
|
|
6
|
+
export const TOOL_DESCRIPTION =
|
|
7
|
+
"Check a link before you open it. Surface unwraps short links (t.co, bit.ly, lnkd.in, youtu.be), " +
|
|
8
|
+
"follows redirects, and tells you whether the destination is worth fetching ('fetch') or should be " +
|
|
9
|
+
"skipped ('skip'), plus where the link really goes. It never returns the page itself.";
|
|
10
|
+
|
|
11
|
+
const env = (k) => (typeof process !== "undefined" && process.env ? process.env[k] : undefined);
|
|
12
|
+
|
|
13
|
+
export async function preflight(url, { apiKey, baseUrl, headers, timeoutMs = 15000 } = {}) {
|
|
14
|
+
const base = (baseUrl || env("SURFACE_BASE_URL") || DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
15
|
+
const key = apiKey || env("SURFACE_API_KEY");
|
|
16
|
+
const res = await fetch(base + "/v1/preflight", {
|
|
17
|
+
method: "POST",
|
|
18
|
+
headers: {
|
|
19
|
+
"content-type": "application/json",
|
|
20
|
+
accept: "application/json",
|
|
21
|
+
"user-agent": "@surfaceapi/ai-sdk/0.1.0",
|
|
22
|
+
...(key ? { authorization: "Bearer " + key } : {}),
|
|
23
|
+
...(headers || {}),
|
|
24
|
+
},
|
|
25
|
+
body: JSON.stringify({ url }),
|
|
26
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
27
|
+
});
|
|
28
|
+
if (!res.ok) throw new Error("Surface preflight HTTP " + res.status);
|
|
29
|
+
const d = await res.json();
|
|
30
|
+
const next = d.next || d.verdict;
|
|
31
|
+
return {
|
|
32
|
+
next, fetch: next === "fetch", url: d.url || url, final_url: d.final_url, final_host: d.final_host,
|
|
33
|
+
status: d.status, redirects: d.redirects, shortener: d.shortener, reason: d.reason,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function surfacePreflightTool(opts = {}) {
|
|
38
|
+
return tool({
|
|
39
|
+
description: TOOL_DESCRIPTION,
|
|
40
|
+
parameters: z.object({ url: z.string().describe("The link to check before fetching it") }),
|
|
41
|
+
inputSchema: z.object({ url: z.string().describe("The link to check before fetching it") }),
|
|
42
|
+
execute: async ({ url }) => {
|
|
43
|
+
try { return await preflight(url, opts); }
|
|
44
|
+
catch (e) { return { next: "skip", fetch: false, url, error: String(e && e.message || e) }; }
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Ready-made tool. Use as: tools: { surface_preflight } */
|
|
50
|
+
export const surface_preflight = surfacePreflightTool();
|
|
51
|
+
export default surface_preflight;
|
package/package.json
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@surfaceapi/ai-sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Surface for the Vercel AI SDK: the link-safety layer between an AI agent and the open web. One tool, surfacePreflight, that tells your agent whether a link is worth fetching.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./index.js",
|
|
7
|
+
"types": "./index.d.ts",
|
|
8
|
+
"exports": { ".": { "types": "./index.d.ts", "import": "./index.js" } },
|
|
9
|
+
"files": ["index.js", "index.d.ts", "README.md", "LICENSE"],
|
|
10
|
+
"keywords": ["ai", "ai-sdk", "vercel", "ai-agents", "tools", "link-safety", "url", "preflight", "mcp", "surface"],
|
|
11
|
+
"author": "Canada Site Ops <canada.site.ops@gmail.com>",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"homepage": "https://otter-sand-wolf-spring.grok.me",
|
|
14
|
+
"peerDependencies": { "ai": ">=4.0.0", "zod": ">=3.22.0" },
|
|
15
|
+
"engines": { "node": ">=18" },
|
|
16
|
+
"publishConfig": { "access": "public" }
|
|
17
|
+
}
|